Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 20 May 2010 17:33:06 +0000 (10:33 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 20 May 2010 17:33:06 +0000 (10:33 -0700)
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (40 commits)
  Input: psmouse - small formatting changes to better follow coding style
  Input: synaptics - set dimensions as reported by firmware
  Input: elantech - relax signature checks
  Input: elantech - enforce common prefix on messages
  Input: wistron_btns - switch to using kmemdup()
  Input: usbtouchscreen - switch to using kmemdup()
  Input: do not force selecting i8042 on Moorestown
  Input: Documentation/sysrq.txt - update KEY_SYSRQ info
  Input: 88pm860x_onkey - remove invalid irq number assignment
  Input: i8042 - add a PNP entry to the aux device list
  Input: i8042 - add some extra PNP keyboard types
  Input: wm9712 - fix wm97xx_set_gpio() logic
  Input: add keypad driver for keys interfaced to TCA6416
  Input: remove obsolete {corgi,spitz,tosa}kbd.c
  Input: kbtab - do not advertise unsupported events
  Input: kbtab - simplify kbtab_disconnect()
  Input: kbtab - fix incorrect size parameter in usb_buffer_free
  Input: acecad - don't advertise mouse events
  Input: acecad - fix some formatting issues
  Input: acecad - simplify usb_acecad_disconnect()
  ...

Trivial conflict in Documentation/feature-removal-schedule.txt

2652 files changed:
Documentation/ABI/testing/sysfs-devices-memory
Documentation/DMA-API-HOWTO.txt
Documentation/DocBook/libata.tmpl
Documentation/DocBook/media-entities.tmpl
Documentation/DocBook/sh.tmpl
Documentation/DocBook/v4l/compat.xml
Documentation/DocBook/v4l/controls.xml
Documentation/DocBook/v4l/dev-event.xml [new file with mode: 0644]
Documentation/DocBook/v4l/io.xml
Documentation/DocBook/v4l/pixfmt.xml
Documentation/DocBook/v4l/v4l2.xml
Documentation/DocBook/v4l/videodev2.h.xml
Documentation/DocBook/v4l/vidioc-dqevent.xml [new file with mode: 0644]
Documentation/DocBook/v4l/vidioc-enuminput.xml
Documentation/DocBook/v4l/vidioc-qbuf.xml
Documentation/DocBook/v4l/vidioc-queryctrl.xml
Documentation/DocBook/v4l/vidioc-reqbufs.xml
Documentation/DocBook/v4l/vidioc-subscribe-event.xml [new file with mode: 0644]
Documentation/DocBook/writing-an-alsa-driver.tmpl
Documentation/PCI/pci-error-recovery.txt
Documentation/RCU/stallwarn.txt
Documentation/RCU/torture.txt
Documentation/RCU/trace.txt
Documentation/Smack.txt
Documentation/arm/00-INDEX
Documentation/arm/SA1100/ADSBitsy
Documentation/arm/SPEAr/overview.txt [new file with mode: 0644]
Documentation/arm/Sharp-LH/ADC-LH7-Touchscreen
Documentation/atomic_ops.txt
Documentation/blackfin/bfin-gpio-notes.txt
Documentation/cachetlb.txt
Documentation/cgroups/cgroups.txt
Documentation/cgroups/cpusets.txt
Documentation/cgroups/memcg_test.txt
Documentation/cgroups/memory.txt
Documentation/connector/connector.txt
Documentation/credentials.txt
Documentation/dvb/ci.txt
Documentation/dvb/contributors.txt
Documentation/feature-removal-schedule.txt
Documentation/filesystems/Locking
Documentation/filesystems/autofs4-mount-control.txt
Documentation/filesystems/ceph.txt
Documentation/filesystems/dlmfs.txt
Documentation/filesystems/fiemap.txt
Documentation/filesystems/fuse.txt
Documentation/filesystems/hpfs.txt
Documentation/filesystems/logfs.txt
Documentation/filesystems/nfs/nfs41-server.txt
Documentation/filesystems/nfs/rpc-cache.txt
Documentation/filesystems/proc.txt
Documentation/filesystems/smbfs.txt
Documentation/filesystems/vfs.txt
Documentation/hwmon/lm85
Documentation/input/joystick.txt
Documentation/intel_txt.txt
Documentation/kbuild/kconfig-language.txt
Documentation/kbuild/kconfig.txt
Documentation/kernel-docs.txt
Documentation/kernel-parameters.txt
Documentation/kprobes.txt
Documentation/laptops/laptop-mode.txt
Documentation/lguest/lguest.c
Documentation/md.txt
Documentation/netlabel/lsm_interface.txt
Documentation/networking/ifenslave.c
Documentation/networking/packet_mmap.txt
Documentation/pcmcia/driver-changes.txt
Documentation/power/devices.txt
Documentation/power/pm_qos_interface.txt
Documentation/power/regulator/consumer.txt
Documentation/power/regulator/machine.txt
Documentation/power/regulator/overview.txt
Documentation/power/userland-swsusp.txt
Documentation/powerpc/booting-without-of.txt
Documentation/powerpc/dts-bindings/xilinx.txt
Documentation/powerpc/phyp-assisted-dump.txt
Documentation/rbtree.txt
Documentation/rt-mutex-design.txt
Documentation/scheduler/sched-design-CFS.txt
Documentation/scheduler/sched-rt-group.txt
Documentation/scsi/ChangeLog.lpfc
Documentation/scsi/FlashPoint.txt
Documentation/scsi/dtc3x80.txt
Documentation/scsi/ncr53c8xx.txt
Documentation/scsi/osst.txt
Documentation/scsi/scsi_fc_transport.txt
Documentation/scsi/sym53c8xx_2.txt
Documentation/sound/alsa/ALSA-Configuration.txt
Documentation/sound/alsa/HD-Audio.txt
Documentation/sound/alsa/soc/dapm.txt
Documentation/sound/alsa/soc/machine.txt
Documentation/sound/alsa/soc/overview.txt
Documentation/sparse.txt
Documentation/sysfs-rules.txt
Documentation/trace/events.txt
Documentation/trace/ftrace.txt
Documentation/trace/kprobetrace.txt
Documentation/usb/WUSB-Design-overview.txt
Documentation/video4linux/CARDLIST.bttv
Documentation/video4linux/CARDLIST.cx88
Documentation/video4linux/CARDLIST.em28xx
Documentation/video4linux/CARDLIST.saa7134
Documentation/video4linux/extract_xc3028.pl
Documentation/video4linux/gspca.txt
Documentation/video4linux/sh_mobile_ceu_camera.txt
Documentation/video4linux/v4l2-framework.txt
Documentation/vm/numa_memory_policy.txt
Documentation/w1/w1.generic
MAINTAINERS
arch/Kconfig
arch/alpha/Kconfig
arch/alpha/include/asm/atomic.h
arch/alpha/include/asm/bitops.h
arch/alpha/include/asm/thread_info.h
arch/alpha/kernel/time.c
arch/arm/Kconfig
arch/arm/Makefile
arch/arm/boot/compressed/Makefile
arch/arm/boot/compressed/decompress.c
arch/arm/boot/compressed/piggy.lzma.S [new file with mode: 0644]
arch/arm/common/Kconfig
arch/arm/common/Makefile
arch/arm/common/clkdev.c
arch/arm/common/icst.c [new file with mode: 0644]
arch/arm/common/icst307.c [deleted file]
arch/arm/common/icst525.c [deleted file]
arch/arm/common/pl330.c [new file with mode: 0644]
arch/arm/common/vic.c
arch/arm/configs/cns3420vb_defconfig [new file with mode: 0644]
arch/arm/configs/mmp2_defconfig
arch/arm/configs/spear300_defconfig [new file with mode: 0644]
arch/arm/configs/spear310_defconfig [new file with mode: 0644]
arch/arm/configs/spear320_defconfig [new file with mode: 0644]
arch/arm/configs/spear600_defconfig [new file with mode: 0644]
arch/arm/configs/stamp9g20_defconfig [new file with mode: 0644]
arch/arm/include/asm/atomic.h
arch/arm/include/asm/hardware/arm_timer.h
arch/arm/include/asm/hardware/cache-l2x0.h
arch/arm/include/asm/hardware/icst.h [new file with mode: 0644]
arch/arm/include/asm/hardware/icst307.h [deleted file]
arch/arm/include/asm/hardware/icst525.h [deleted file]
arch/arm/include/asm/hardware/pl330.h [new file with mode: 0644]
arch/arm/include/asm/hardware/sp810.h [new file with mode: 0644]
arch/arm/include/asm/ioctls.h
arch/arm/include/asm/mach/pci.h
arch/arm/include/asm/mach/time.h
arch/arm/include/asm/pci.h
arch/arm/include/asm/perf_event.h
arch/arm/include/asm/pgtable.h
arch/arm/include/asm/pmu.h
arch/arm/include/asm/scatterlist.h
arch/arm/include/asm/smp.h
arch/arm/include/asm/system.h
arch/arm/include/asm/thread_info.h
arch/arm/kernel/bios32.c
arch/arm/kernel/dma.c
arch/arm/kernel/perf_event.c
arch/arm/kernel/pmu.c
arch/arm/kernel/smp.c
arch/arm/kernel/time.c
arch/arm/mach-at91/Kconfig
arch/arm/mach-at91/Makefile
arch/arm/mach-at91/board-stamp9g20.c [new file with mode: 0644]
arch/arm/mach-at91/include/mach/board.h
arch/arm/mach-at91/include/mach/cpu.h
arch/arm/mach-at91/include/mach/system.h
arch/arm/mach-bcmring/arch.c
arch/arm/mach-clps711x/mm.c
arch/arm/mach-cns3xxx/Kconfig [new file with mode: 0644]
arch/arm/mach-cns3xxx/Makefile [new file with mode: 0644]
arch/arm/mach-cns3xxx/Makefile.boot [new file with mode: 0644]
arch/arm/mach-cns3xxx/cns3420vb.c [new file with mode: 0644]
arch/arm/mach-cns3xxx/core.c [new file with mode: 0644]
arch/arm/mach-cns3xxx/core.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/cns3xxx.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/debug-macro.S [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/entry-macro.S [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/hardware.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/io.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/irqs.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/memory.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/system.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/timex.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/uncompress.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/vmalloc.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/pm.c [new file with mode: 0644]
arch/arm/mach-davinci/Kconfig
arch/arm/mach-davinci/board-da830-evm.c
arch/arm/mach-davinci/board-da850-evm.c
arch/arm/mach-davinci/board-dm355-evm.c
arch/arm/mach-davinci/board-dm355-leopard.c
arch/arm/mach-davinci/board-dm365-evm.c
arch/arm/mach-davinci/board-dm644x-evm.c
arch/arm/mach-davinci/board-dm646x-evm.c
arch/arm/mach-davinci/board-neuros-osd2.c
arch/arm/mach-davinci/board-sffsdr.c
arch/arm/mach-davinci/cdce949.c
arch/arm/mach-davinci/clock.c
arch/arm/mach-davinci/clock.h
arch/arm/mach-davinci/common.c
arch/arm/mach-davinci/cp_intc.c
arch/arm/mach-davinci/da830.c
arch/arm/mach-davinci/da850.c
arch/arm/mach-davinci/devices-da8xx.c
arch/arm/mach-davinci/devices.c
arch/arm/mach-davinci/dm355.c
arch/arm/mach-davinci/dm365.c
arch/arm/mach-davinci/dm644x.c
arch/arm/mach-davinci/dm646x.c
arch/arm/mach-davinci/dma.c
arch/arm/mach-davinci/gpio.c
arch/arm/mach-davinci/include/mach/common.h
arch/arm/mach-davinci/include/mach/cp_intc.h
arch/arm/mach-davinci/include/mach/cputype.h
arch/arm/mach-davinci/include/mach/da8xx.h
arch/arm/mach-davinci/include/mach/dm355.h
arch/arm/mach-davinci/include/mach/dm365.h
arch/arm/mach-davinci/include/mach/dm644x.h
arch/arm/mach-davinci/include/mach/dm646x.h
arch/arm/mach-davinci/include/mach/gpio.h
arch/arm/mach-davinci/include/mach/irqs.h
arch/arm/mach-davinci/include/mach/mux.h
arch/arm/mach-davinci/include/mach/psc.h
arch/arm/mach-davinci/include/mach/serial.h
arch/arm/mach-davinci/include/mach/system.h
arch/arm/mach-davinci/io.c
arch/arm/mach-davinci/irq.c
arch/arm/mach-davinci/mux.c
arch/arm/mach-davinci/mux.h
arch/arm/mach-davinci/psc.c
arch/arm/mach-davinci/serial.c
arch/arm/mach-davinci/time.c
arch/arm/mach-ep93xx/adssphere.c
arch/arm/mach-ep93xx/clock.c
arch/arm/mach-ep93xx/core.c
arch/arm/mach-ep93xx/edb93xx.c
arch/arm/mach-ep93xx/gesbc9312.c
arch/arm/mach-ep93xx/include/mach/ep93xx-regs.h
arch/arm/mach-ep93xx/include/mach/platform.h
arch/arm/mach-ep93xx/micro9.c
arch/arm/mach-ep93xx/simone.c
arch/arm/mach-ep93xx/snappercl15.c
arch/arm/mach-ep93xx/ts72xx.c
arch/arm/mach-integrator/Kconfig
arch/arm/mach-integrator/Makefile
arch/arm/mach-integrator/common.h [deleted file]
arch/arm/mach-integrator/core.c
arch/arm/mach-integrator/cpu.c
arch/arm/mach-integrator/impd1.c
arch/arm/mach-integrator/include/mach/clkdev.h
arch/arm/mach-integrator/include/mach/entry-macro.S
arch/arm/mach-integrator/include/mach/hardware.h
arch/arm/mach-integrator/include/mach/platform.h
arch/arm/mach-integrator/integrator_ap.c
arch/arm/mach-integrator/integrator_cp.c
arch/arm/mach-integrator/leds.c
arch/arm/mach-integrator/pci_v3.c
arch/arm/mach-iop32x/n2100.c
arch/arm/mach-ixp4xx/common.c
arch/arm/mach-kirkwood/Kconfig
arch/arm/mach-kirkwood/Makefile
arch/arm/mach-kirkwood/guruplug-setup.c [new file with mode: 0644]
arch/arm/mach-kirkwood/netxbig_v2-setup.c [new file with mode: 0644]
arch/arm/mach-mmp/aspenite.c
arch/arm/mach-mmp/include/mach/gpio.h
arch/arm/mach-mmp/include/mach/irqs.h
arch/arm/mach-mmp/include/mach/mfp-mmp2.h
arch/arm/mach-mmp/include/mach/mmp2.h
arch/arm/mach-mmp/include/mach/pxa168.h
arch/arm/mach-mmp/include/mach/regs-apbc.h
arch/arm/mach-mmp/include/mach/regs-smc.h [new file with mode: 0644]
arch/arm/mach-mmp/include/mach/timex.h
arch/arm/mach-mmp/jasper.c
arch/arm/mach-mmp/mmp2.c
arch/arm/mach-mmp/pxa168.c
arch/arm/mach-msm/Kconfig
arch/arm/mach-msm/Makefile
arch/arm/mach-msm/acpuclock-arm11.c [new file with mode: 0644]
arch/arm/mach-msm/acpuclock.h [new file with mode: 0644]
arch/arm/mach-msm/board-halibut.c
arch/arm/mach-msm/board-mahimahi.c [new file with mode: 0644]
arch/arm/mach-msm/board-msm7x27.c [new file with mode: 0644]
arch/arm/mach-msm/board-msm7x30.c [new file with mode: 0644]
arch/arm/mach-msm/board-qsd8x50.c [new file with mode: 0644]
arch/arm/mach-msm/board-sapphire.c [new file with mode: 0644]
arch/arm/mach-msm/board-trout.c [moved from arch/arm/mach-msm/board-dream.c with 93% similarity]
arch/arm/mach-msm/board-trout.h [moved from arch/arm/mach-msm/board-dream.h with 100% similarity]
arch/arm/mach-msm/clock-7x01a.c [deleted file]
arch/arm/mach-msm/clock-7x30.h [new file with mode: 0644]
arch/arm/mach-msm/clock-pcom.c [new file with mode: 0644]
arch/arm/mach-msm/clock-pcom.h [new file with mode: 0644]
arch/arm/mach-msm/clock.c
arch/arm/mach-msm/clock.h
arch/arm/mach-msm/devices-msm7x00.c [moved from arch/arm/mach-msm/devices.c with 58% similarity]
arch/arm/mach-msm/devices-msm7x30.c [new file with mode: 0644]
arch/arm/mach-msm/devices-qsd8x50.c [new file with mode: 0644]
arch/arm/mach-msm/devices.h
arch/arm/mach-msm/dma.c
arch/arm/mach-msm/gpio.c [new file with mode: 0644]
arch/arm/mach-msm/include/mach/board.h
arch/arm/mach-msm/include/mach/clk.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/dma.h
arch/arm/mach-msm/include/mach/gpio.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/io.h
arch/arm/mach-msm/include/mach/irqs-7x00.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/irqs-7x30.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/irqs-8x50.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/irqs.h
arch/arm/mach-msm/include/mach/memory.h
arch/arm/mach-msm/include/mach/msm_fb.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/msm_iomap-7x00.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/msm_iomap-7x30.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/msm_iomap-8x50.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/msm_iomap.h
arch/arm/mach-msm/include/mach/msm_smd.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/sirc.h [new file with mode: 0644]
arch/arm/mach-msm/include/mach/system.h
arch/arm/mach-msm/include/mach/vreg.h
arch/arm/mach-msm/io.c
arch/arm/mach-msm/irq-vic.c [new file with mode: 0644]
arch/arm/mach-msm/irq.c
arch/arm/mach-msm/last_radio_log.c [new file with mode: 0644]
arch/arm/mach-msm/proc_comm.c
arch/arm/mach-msm/proc_comm.h
arch/arm/mach-msm/sirc.c [new file with mode: 0644]
arch/arm/mach-msm/smd.c [new file with mode: 0644]
arch/arm/mach-msm/smd_debug.c [new file with mode: 0644]
arch/arm/mach-msm/smd_private.h [new file with mode: 0644]
arch/arm/mach-msm/timer.c
arch/arm/mach-msm/vreg.c
arch/arm/mach-nomadik/Kconfig
arch/arm/mach-nomadik/Makefile
arch/arm/mach-nomadik/board-nhk8815.c
arch/arm/mach-nomadik/clock.c
arch/arm/mach-nomadik/clock.h
arch/arm/mach-nomadik/cpu-8815.c
arch/arm/mach-nomadik/include/mach/gpio.h
arch/arm/mach-omap1/board-htcherald.c
arch/arm/mach-omap2/devices.c
arch/arm/mach-omap2/mcbsp.c
arch/arm/mach-omap2/omap_hwmod.c
arch/arm/mach-orion5x/dns323-setup.c
arch/arm/mach-pxa/Kconfig
arch/arm/mach-pxa/Makefile
arch/arm/mach-pxa/cm-x300.c
arch/arm/mach-pxa/colibri-pxa3xx.c
arch/arm/mach-pxa/corgi.c
arch/arm/mach-pxa/corgi_lcd.c [deleted file]
arch/arm/mach-pxa/corgi_pm.c
arch/arm/mach-pxa/corgi_ssp.c [deleted file]
arch/arm/mach-pxa/csb726.c
arch/arm/mach-pxa/em-x270.c
arch/arm/mach-pxa/generic.c
arch/arm/mach-pxa/include/mach/corgi.h
arch/arm/mach-pxa/include/mach/mfp-pxa2xx.h
arch/arm/mach-pxa/include/mach/mmc.h
arch/arm/mach-pxa/include/mach/pxa2xx-gpio.h [deleted file]
arch/arm/mach-pxa/include/mach/ssp.h [deleted file]
arch/arm/mach-pxa/include/mach/tosa.h
arch/arm/mach-pxa/include/mach/vpac270.h [new file with mode: 0644]
arch/arm/mach-pxa/include/mach/z2.h [new file with mode: 0644]
arch/arm/mach-pxa/littleton.c
arch/arm/mach-pxa/lubbock.c
arch/arm/mach-pxa/mfp-pxa2xx.c
arch/arm/mach-pxa/mioa701.c
arch/arm/mach-pxa/mxm8x10.c
arch/arm/mach-pxa/palmld.c
arch/arm/mach-pxa/palmt5.c
arch/arm/mach-pxa/palmtc.c
arch/arm/mach-pxa/palmtx.c
arch/arm/mach-pxa/pcm990-baseboard.c
arch/arm/mach-pxa/poodle.c
arch/arm/mach-pxa/pxa3xx.c
arch/arm/mach-pxa/raumfeld.c
arch/arm/mach-pxa/sharpsl.h
arch/arm/mach-pxa/sharpsl_pm.c
arch/arm/mach-pxa/spitz.c
arch/arm/mach-pxa/spitz_pm.c
arch/arm/mach-pxa/ssp.c [deleted file]
arch/arm/mach-pxa/stargate2.c
arch/arm/mach-pxa/tosa.c
arch/arm/mach-pxa/trizeps4.c
arch/arm/mach-pxa/vpac270.c [new file with mode: 0644]
arch/arm/mach-pxa/z2.c [new file with mode: 0644]
arch/arm/mach-pxa/zeus.c
arch/arm/mach-pxa/zylonite.c
arch/arm/mach-realview/Makefile
arch/arm/mach-realview/clock.c [deleted file]
arch/arm/mach-realview/clock.h [deleted file]
arch/arm/mach-realview/core.c
arch/arm/mach-realview/hotplug.c
arch/arm/mach-realview/include/mach/clkdev.h
arch/arm/mach-realview/include/mach/irqs-pb1176.h
arch/arm/mach-realview/include/mach/irqs-pba8.h
arch/arm/mach-realview/include/mach/irqs-pbx.h
arch/arm/mach-realview/include/mach/platform.h
arch/arm/mach-realview/realview_eb.c
arch/arm/mach-realview/realview_pb1176.c
arch/arm/mach-realview/realview_pb11mp.c
arch/arm/mach-realview/realview_pba8.c
arch/arm/mach-realview/realview_pbx.c
arch/arm/mach-s3c2410/Kconfig
arch/arm/mach-s3c2410/Makefile.boot
arch/arm/mach-s3c2410/h1940-bluetooth.c
arch/arm/mach-s3c2410/include/mach/dma.h
arch/arm/mach-s3c2410/include/mach/gpio-fns.h
arch/arm/mach-s3c2410/include/mach/gpio-nrs.h
arch/arm/mach-s3c2410/include/mach/gpio-track.h
arch/arm/mach-s3c2410/include/mach/gpio.h
arch/arm/mach-s3c2410/include/mach/irqs.h
arch/arm/mach-s3c2410/include/mach/map.h
arch/arm/mach-s3c2410/include/mach/regs-clock.h
arch/arm/mach-s3c2410/include/mach/regs-dsc.h
arch/arm/mach-s3c2410/include/mach/regs-gpio.h
arch/arm/mach-s3c2410/include/mach/regs-gpioj.h
arch/arm/mach-s3c2410/include/mach/regs-irq.h
arch/arm/mach-s3c2410/include/mach/regs-s3c2416-mem.h [new file with mode: 0644]
arch/arm/mach-s3c2410/include/mach/regs-s3c2416.h [new file with mode: 0644]
arch/arm/mach-s3c2410/include/mach/regs-s3c2443-clock.h
arch/arm/mach-s3c2410/include/mach/uncompress.h
arch/arm/mach-s3c2410/mach-amlm5900.c
arch/arm/mach-s3c2410/mach-bast.c
arch/arm/mach-s3c2410/mach-h1940.c
arch/arm/mach-s3c2410/mach-n30.c
arch/arm/mach-s3c2410/mach-qt2410.c
arch/arm/mach-s3c2410/mach-vr1000.c
arch/arm/mach-s3c2410/pm.c
arch/arm/mach-s3c2410/s3c2410.c
arch/arm/mach-s3c2412/Kconfig
arch/arm/mach-s3c2412/dma.c
arch/arm/mach-s3c2412/gpio.c
arch/arm/mach-s3c2412/mach-jive.c
arch/arm/mach-s3c2412/mach-smdk2413.c
arch/arm/mach-s3c2416/Kconfig [new file with mode: 0644]
arch/arm/mach-s3c2416/Makefile [new file with mode: 0644]
arch/arm/mach-s3c2416/clock.c [new file with mode: 0644]
arch/arm/mach-s3c2416/irq.c [new file with mode: 0644]
arch/arm/mach-s3c2416/mach-smdk2416.c [new file with mode: 0644]
arch/arm/mach-s3c2416/s3c2416.c [new file with mode: 0644]
arch/arm/mach-s3c2440/Kconfig
arch/arm/mach-s3c2440/Makefile
arch/arm/mach-s3c2440/mach-mini2440.c
arch/arm/mach-s3c2440/mach-nexcoder.c
arch/arm/mach-s3c2440/mach-osiris.c
arch/arm/mach-s3c2440/mach-rx1950.c [new file with mode: 0644]
arch/arm/mach-s3c2440/mach-rx3715.c
arch/arm/mach-s3c2440/mach-smdk2440.c
arch/arm/mach-s3c2440/s3c2440.c
arch/arm/mach-s3c2443/Kconfig
arch/arm/mach-s3c2443/clock.c
arch/arm/mach-s3c2443/mach-smdk2443.c
arch/arm/mach-s3c64xx/Kconfig
arch/arm/mach-s3c64xx/Makefile
arch/arm/mach-s3c64xx/clock.c
arch/arm/mach-s3c64xx/dma.c
arch/arm/mach-s3c64xx/gpiolib.c
arch/arm/mach-s3c64xx/include/mach/map.h
arch/arm/mach-s3c64xx/include/mach/pll.h
arch/arm/mach-s3c64xx/include/mach/regs-clock.h
arch/arm/mach-s3c64xx/mach-smdk6400.c
arch/arm/mach-s3c64xx/mach-smdk6410.c
arch/arm/mach-s3c64xx/s3c6410.c
arch/arm/mach-s5p6440/Kconfig
arch/arm/mach-s5p6440/Makefile
arch/arm/mach-s5p6440/clock.c
arch/arm/mach-s5p6440/cpu.c
arch/arm/mach-s5p6440/dev-audio.c [new file with mode: 0644]
arch/arm/mach-s5p6440/dma.c [new file with mode: 0644]
arch/arm/mach-s5p6440/gpio.c
arch/arm/mach-s5p6440/include/mach/dma.h [new file with mode: 0644]
arch/arm/mach-s5p6440/include/mach/map.h
arch/arm/mach-s5p6440/include/mach/pwm-clock.h
arch/arm/mach-s5p6440/mach-smdk6440.c
arch/arm/mach-s5p6440/setup-i2c0.c [moved from arch/arm/plat-s5p/setup-i2c0.c with 92% similarity]
arch/arm/mach-s5p6442/Kconfig
arch/arm/mach-s5p6442/Makefile
arch/arm/mach-s5p6442/cpu.c
arch/arm/mach-s5p6442/dev-audio.c [new file with mode: 0644]
arch/arm/mach-s5p6442/dma.c [new file with mode: 0644]
arch/arm/mach-s5p6442/include/mach/dma.h [new file with mode: 0644]
arch/arm/mach-s5p6442/include/mach/map.h
arch/arm/mach-s5p6442/include/mach/pwm-clock.h
arch/arm/mach-s5p6442/mach-smdk6442.c
arch/arm/mach-s5p6442/setup-i2c0.c [new file with mode: 0644]
arch/arm/mach-s5pc100/Kconfig
arch/arm/mach-s5pc100/Makefile
arch/arm/mach-s5pc100/clock.c [new file with mode: 0644]
arch/arm/mach-s5pc100/gpiolib.c [moved from arch/arm/plat-s5pc1xx/gpiolib.c with 78% similarity]
arch/arm/mach-s5pc100/include/mach/gpio.h
arch/arm/mach-s5pc100/include/mach/regs-clock.h [new file with mode: 0644]
arch/arm/mach-s5pc100/include/mach/regs-gpio.h [moved from arch/arm/plat-s5pc1xx/include/plat/regs-gpio.h with 94% similarity]
arch/arm/mach-s5pc100/mach-smdkc100.c
arch/arm/mach-s5pc100/setup-fb-24bpp.c [moved from arch/arm/plat-s5pc1xx/setup-fb-24bpp.c with 89% similarity]
arch/arm/mach-s5pc100/setup-i2c0.c [moved from arch/arm/plat-s5pc1xx/setup-i2c0.c with 89% similarity]
arch/arm/mach-s5pc100/setup-i2c1.c [moved from arch/arm/plat-s5pc1xx/setup-i2c1.c with 89% similarity]
arch/arm/mach-s5pv210/Kconfig
arch/arm/mach-s5pv210/Makefile
arch/arm/mach-s5pv210/clock.c
arch/arm/mach-s5pv210/cpu.c
arch/arm/mach-s5pv210/dev-audio.c [new file with mode: 0644]
arch/arm/mach-s5pv210/dma.c [new file with mode: 0644]
arch/arm/mach-s5pv210/gpiolib.c [new file with mode: 0644]
arch/arm/mach-s5pv210/include/mach/dma.h [new file with mode: 0644]
arch/arm/mach-s5pv210/include/mach/gpio.h
arch/arm/mach-s5pv210/include/mach/map.h
arch/arm/mach-s5pv210/include/mach/pwm-clock.h
arch/arm/mach-s5pv210/mach-smdkc110.c
arch/arm/mach-s5pv210/mach-smdkv210.c
arch/arm/mach-s5pv210/setup-i2c0.c [new file with mode: 0644]
arch/arm/mach-shmobile/Kconfig
arch/arm/mach-spear3xx/Kconfig [new file with mode: 0644]
arch/arm/mach-spear3xx/Kconfig300 [new file with mode: 0644]
arch/arm/mach-spear3xx/Kconfig310 [new file with mode: 0644]
arch/arm/mach-spear3xx/Kconfig320 [new file with mode: 0644]
arch/arm/mach-spear3xx/Makefile [new file with mode: 0644]
arch/arm/mach-spear3xx/Makefile.boot [new file with mode: 0644]
arch/arm/mach-spear3xx/clock.c [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/clkdev.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/debug-macro.S [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/entry-macro.S [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/generic.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/gpio.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/hardware.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/io.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/irqs.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/memory.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/misc_regs.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/spear.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/spear300.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/spear310.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/spear320.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/system.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/timex.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/uncompress.h [new file with mode: 0644]
arch/arm/mach-spear3xx/include/mach/vmalloc.h [new file with mode: 0644]
arch/arm/mach-spear3xx/spear300.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear300_evb.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear310.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear310_evb.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear320.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear320_evb.c [new file with mode: 0644]
arch/arm/mach-spear3xx/spear3xx.c [new file with mode: 0644]
arch/arm/mach-spear6xx/Kconfig [new file with mode: 0644]
arch/arm/mach-spear6xx/Kconfig600 [new file with mode: 0644]
arch/arm/mach-spear6xx/Makefile [new file with mode: 0644]
arch/arm/mach-spear6xx/Makefile.boot [new file with mode: 0644]
arch/arm/mach-spear6xx/clock.c [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/clkdev.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/debug-macro.S [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/entry-macro.S [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/generic.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/gpio.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/hardware.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/io.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/irqs.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/memory.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/misc_regs.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/spear.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/spear600.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/system.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/timex.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/uncompress.h [new file with mode: 0644]
arch/arm/mach-spear6xx/include/mach/vmalloc.h [new file with mode: 0644]
arch/arm/mach-spear6xx/spear600.c [new file with mode: 0644]
arch/arm/mach-spear6xx/spear600_evb.c [new file with mode: 0644]
arch/arm/mach-spear6xx/spear6xx.c [new file with mode: 0644]
arch/arm/mach-u300/mmc.c
arch/arm/mach-ux500/Kconfig
arch/arm/mach-ux500/Makefile
arch/arm/mach-ux500/board-mop500.c
arch/arm/mach-ux500/board-u5500.c [new file with mode: 0644]
arch/arm/mach-ux500/clock.c
arch/arm/mach-ux500/clock.h [new file with mode: 0644]
arch/arm/mach-ux500/cpu-db5500.c [new file with mode: 0644]
arch/arm/mach-ux500/cpu-db8500.c [moved from arch/arm/mach-ux500/cpu-u8500.c with 53% similarity]
arch/arm/mach-ux500/cpu.c [new file with mode: 0644]
arch/arm/mach-ux500/devices-db5500.c [new file with mode: 0644]
arch/arm/mach-ux500/devices-db8500.c [new file with mode: 0644]
arch/arm/mach-ux500/devices.c [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/db5500-regs.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/db8500-regs.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/debug-macro.S
arch/arm/mach-ux500/include/mach/devices.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/entry-macro.S
arch/arm/mach-ux500/include/mach/gpio.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/hardware.h
arch/arm/mach-ux500/include/mach/irqs.h
arch/arm/mach-ux500/include/mach/setup.h
arch/arm/mach-ux500/platsmp.c
arch/arm/mach-versatile/Makefile
arch/arm/mach-versatile/clock.c [deleted file]
arch/arm/mach-versatile/clock.h [deleted file]
arch/arm/mach-versatile/core.c
arch/arm/mach-versatile/include/mach/clkdev.h
arch/arm/mach-versatile/include/mach/entry-macro.S
arch/arm/mach-versatile/include/mach/hardware.h
arch/arm/mach-versatile/include/mach/platform.h
arch/arm/mach-vexpress/Kconfig [new file with mode: 0644]
arch/arm/mach-vexpress/Makefile [new file with mode: 0644]
arch/arm/mach-vexpress/Makefile.boot [new file with mode: 0644]
arch/arm/mach-vexpress/core.h [new file with mode: 0644]
arch/arm/mach-vexpress/ct-ca9x4.c [new file with mode: 0644]
arch/arm/mach-vexpress/headsmp.S [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/clkdev.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/ct-ca9x4.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/debug-macro.S [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/entry-macro.S [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/hardware.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/io.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/irqs.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/memory.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/motherboard.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/smp.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/system.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/timex.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/uncompress.h [new file with mode: 0644]
arch/arm/mach-vexpress/include/mach/vmalloc.h [new file with mode: 0644]
arch/arm/mach-vexpress/localtimer.c [new file with mode: 0644]
arch/arm/mach-vexpress/platsmp.c [new file with mode: 0644]
arch/arm/mach-vexpress/v2m.c [new file with mode: 0644]
arch/arm/mm/Kconfig
arch/arm/mm/abort-ev7.S
arch/arm/mm/alignment.c
arch/arm/mm/cache-l2x0.c
arch/arm/mm/copypage-fa.c
arch/arm/mm/fault-armv.c
arch/arm/mm/fault.c
arch/arm/mm/init.c
arch/arm/mm/mm.h
arch/arm/mm/mmu.c
arch/arm/nwfpe/fpmodule.c
arch/arm/oprofile/Makefile
arch/arm/oprofile/backtrace.c [deleted file]
arch/arm/oprofile/common.c
arch/arm/oprofile/op_arm_model.h [deleted file]
arch/arm/oprofile/op_counter.h [deleted file]
arch/arm/oprofile/op_model_arm11_core.c [deleted file]
arch/arm/oprofile/op_model_arm11_core.h [deleted file]
arch/arm/oprofile/op_model_mpcore.c [deleted file]
arch/arm/oprofile/op_model_mpcore.h [deleted file]
arch/arm/oprofile/op_model_v6.c [deleted file]
arch/arm/oprofile/op_model_v7.c [deleted file]
arch/arm/oprofile/op_model_v7.h [deleted file]
arch/arm/oprofile/op_model_xscale.c [deleted file]
arch/arm/plat-iop/Makefile
arch/arm/plat-iop/pmu.c [new file with mode: 0644]
arch/arm/plat-nomadik/Kconfig
arch/arm/plat-nomadik/Makefile
arch/arm/plat-nomadik/gpio.c [moved from arch/arm/mach-nomadik/gpio.c with 74% similarity]
arch/arm/plat-nomadik/include/plat/gpio.h [new file with mode: 0644]
arch/arm/plat-nomadik/timer.c
arch/arm/plat-omap/i2c.c
arch/arm/plat-omap/include/plat/mcbsp.h
arch/arm/plat-omap/mcbsp.c
arch/arm/plat-pxa/Kconfig
arch/arm/plat-pxa/Makefile
arch/arm/plat-pxa/include/plat/mfp.h
arch/arm/plat-pxa/include/plat/ssp.h [moved from arch/arm/mach-pxa/include/mach/regs-ssp.h with 75% similarity]
arch/arm/plat-pxa/mfp.c
arch/arm/plat-pxa/pmu.c [new file with mode: 0644]
arch/arm/plat-pxa/ssp.c [new file with mode: 0644]
arch/arm/plat-s3c24xx/Kconfig
arch/arm/plat-s3c24xx/Makefile
arch/arm/plat-s3c24xx/common-smdk.c
arch/arm/plat-s3c24xx/cpu.c
arch/arm/plat-s3c24xx/devs.c
arch/arm/plat-s3c24xx/dma.c
arch/arm/plat-s3c24xx/gpio.c
arch/arm/plat-s3c24xx/gpiolib.c
arch/arm/plat-s3c24xx/include/plat/pll.h
arch/arm/plat-s3c24xx/include/plat/s3c2416.h [new file with mode: 0644]
arch/arm/plat-s3c24xx/include/plat/s3c2443.h
arch/arm/plat-s3c24xx/pm.c
arch/arm/plat-s3c24xx/s3c2410-clock.c
arch/arm/plat-s3c24xx/s3c2443-clock.c [new file with mode: 0644]
arch/arm/plat-s3c24xx/setup-i2c.c
arch/arm/plat-s3c24xx/setup-ts.c [new file with mode: 0644]
arch/arm/plat-s3c24xx/spi-bus0-gpe11_12_13.c
arch/arm/plat-s3c24xx/spi-bus1-gpd8_9_10.c
arch/arm/plat-s3c24xx/spi-bus1-gpg5_6_7.c
arch/arm/plat-s5p/Kconfig
arch/arm/plat-s5p/Makefile
arch/arm/plat-s5p/clock.c
arch/arm/plat-s5p/include/plat/irqs.h
arch/arm/plat-s5p/include/plat/pll.h
arch/arm/plat-s5p/include/plat/s5p-clock.h
arch/arm/plat-s5pc1xx/Kconfig
arch/arm/plat-s5pc1xx/Makefile
arch/arm/plat-s5pc1xx/gpio-config.c [deleted file]
arch/arm/plat-s5pc1xx/include/plat/gpio-cfg-s5pc1xx.h [deleted file]
arch/arm/plat-samsung/Kconfig
arch/arm/plat-samsung/Makefile
arch/arm/plat-samsung/clock.c
arch/arm/plat-samsung/dev-adc.c [moved from arch/arm/mach-s3c64xx/dev-adc.c with 86% similarity]
arch/arm/plat-samsung/dev-fb.c
arch/arm/plat-samsung/dev-hwmon.c [new file with mode: 0644]
arch/arm/plat-samsung/dev-rtc.c [moved from arch/arm/mach-s3c64xx/dev-rtc.c with 58% similarity]
arch/arm/plat-samsung/dev-ts.c [new file with mode: 0644]
arch/arm/plat-samsung/gpio-config.c
arch/arm/plat-samsung/gpio.c
arch/arm/plat-samsung/include/plat/clock.h
arch/arm/plat-samsung/include/plat/cpu.h
arch/arm/plat-samsung/include/plat/devs.h
arch/arm/plat-samsung/include/plat/dma.h
arch/arm/plat-samsung/include/plat/fb.h
arch/arm/plat-samsung/include/plat/gpio-cfg-helpers.h
arch/arm/plat-samsung/include/plat/gpio-cfg.h
arch/arm/plat-samsung/include/plat/gpio-core.h
arch/arm/plat-samsung/include/plat/hwmon.h
arch/arm/plat-samsung/include/plat/pll6553x.h [new file with mode: 0644]
arch/arm/plat-samsung/include/plat/s3c-dma-pl330.h [new file with mode: 0644]
arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h [new file with mode: 0644]
arch/arm/plat-samsung/include/plat/ts.h [moved from arch/arm/mach-s3c2410/include/mach/ts.h with 72% similarity]
arch/arm/plat-samsung/pm-gpio.c
arch/arm/plat-samsung/s3c-pl330.c [new file with mode: 0644]
arch/arm/plat-spear/Kconfig [new file with mode: 0644]
arch/arm/plat-spear/Makefile [new file with mode: 0644]
arch/arm/plat-spear/clock.c [new file with mode: 0644]
arch/arm/plat-spear/include/plat/clkdev.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/clock.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/debug-macro.S [new file with mode: 0644]
arch/arm/plat-spear/include/plat/gpio.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/io.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/memory.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/padmux.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/shirq.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/system.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/timex.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/uncompress.h [new file with mode: 0644]
arch/arm/plat-spear/include/plat/vmalloc.h [new file with mode: 0644]
arch/arm/plat-spear/padmux.c [new file with mode: 0644]
arch/arm/plat-spear/shirq.c [new file with mode: 0644]
arch/arm/plat-spear/time.c [new file with mode: 0644]
arch/arm/plat-versatile/Makefile [new file with mode: 0644]
arch/arm/plat-versatile/clock.c [moved from arch/arm/mach-integrator/clock.c with 59% similarity]
arch/arm/plat-versatile/include/plat/clock.h [new file with mode: 0644]
arch/arm/plat-versatile/include/plat/timer-sp.h [new file with mode: 0644]
arch/arm/plat-versatile/sched-clock.c [new file with mode: 0644]
arch/arm/plat-versatile/timer-sp.c [new file with mode: 0644]
arch/avr32/include/asm/atomic.h
arch/avr32/include/asm/thread_info.h
arch/avr32/kernel/time.c
arch/blackfin/include/asm/thread_info.h
arch/blackfin/kernel/time-ts.c
arch/blackfin/kernel/time.c
arch/cris/Kconfig
arch/cris/arch-v10/kernel/time.c
arch/cris/arch-v32/kernel/time.c
arch/cris/include/asm/atomic.h
arch/cris/include/asm/thread_info.h
arch/cris/kernel/time.c
arch/frv/include/asm/atomic.h
arch/frv/include/asm/thread_info.h
arch/frv/kernel/time.c
arch/h8300/include/asm/atomic.h
arch/h8300/include/asm/thread_info.h
arch/h8300/kernel/time.c
arch/ia64/Kconfig
arch/ia64/hp/common/sba_iommu.c
arch/ia64/include/asm/atomic.h
arch/ia64/include/asm/bitops.h
arch/ia64/include/asm/mmzone.h
arch/ia64/include/asm/percpu.h
arch/ia64/include/asm/thread_info.h
arch/ia64/kernel/acpi.c
arch/ia64/kernel/cpufreq/acpi-cpufreq.c
arch/ia64/kernel/irq_ia64.c
arch/ia64/kernel/salinfo.c
arch/ia64/kernel/time.c
arch/ia64/kernel/topology.c
arch/ia64/kernel/unaligned.c
arch/ia64/mm/fault.c
arch/ia64/sn/kernel/sn2/sn_hwperf.c
arch/m32r/include/asm/atomic.h
arch/m32r/include/asm/thread_info.h
arch/m32r/kernel/time.c
arch/m68k/amiga/Makefile
arch/m68k/amiga/platform.c [new file with mode: 0644]
arch/m68k/bvme6000/rtc.c
arch/m68k/hp300/time.h
arch/m68k/include/asm/atomic_mm.h
arch/m68k/include/asm/atomic_no.h
arch/m68k/include/asm/bitops_mm.h
arch/m68k/include/asm/param.h
arch/m68k/include/asm/thread_info_mm.h
arch/m68k/include/asm/thread_info_no.h
arch/m68k/kernel/time.c
arch/m68k/kernel/traps.c
arch/m68k/mac/config.c
arch/m68k/mm/fault.c
arch/m68k/mvme16x/rtc.c
arch/m68k/q40/config.c
arch/microblaze/include/asm/thread_info.h
arch/mips/include/asm/atomic.h
arch/mips/include/asm/i8253.h
arch/mips/include/asm/thread_info.h
arch/mips/kernel/i8253.c
arch/mips/sibyte/bcm1480/irq.c
arch/mips/sibyte/sb1250/irq.c
arch/mn10300/Kconfig
arch/mn10300/include/asm/atomic.h
arch/mn10300/include/asm/thread_info.h
arch/mn10300/kernel/rtc.c
arch/mn10300/kernel/time.c
arch/parisc/include/asm/atomic.h
arch/parisc/include/asm/thread_info.h
arch/powerpc/include/asm/thread_info.h
arch/powerpc/kernel/perf_event.c
arch/powerpc/platforms/embedded6xx/wii.c
arch/s390/Kconfig
arch/s390/Makefile
arch/s390/hypfs/hypfs.h
arch/s390/hypfs/hypfs_diag.c
arch/s390/hypfs/hypfs_vm.c
arch/s390/hypfs/inode.c
arch/s390/include/asm/cputime.h
arch/s390/include/asm/lowcore.h
arch/s390/include/asm/ptrace.h
arch/s390/include/asm/qdio.h
arch/s390/include/asm/setup.h
arch/s390/include/asm/system.h
arch/s390/include/asm/thread_info.h
arch/s390/include/asm/timex.h
arch/s390/include/asm/topology.h
arch/s390/kernel/asm-offsets.c
arch/s390/kernel/debug.c
arch/s390/kernel/early.c
arch/s390/kernel/entry.S
arch/s390/kernel/entry64.S
arch/s390/kernel/head.S
arch/s390/kernel/nmi.c
arch/s390/kernel/processor.c
arch/s390/kernel/ptrace.c
arch/s390/kernel/s390_ext.c
arch/s390/kernel/setup.c
arch/s390/kernel/signal.c
arch/s390/kernel/time.c
arch/s390/kernel/topology.c
arch/s390/kernel/traps.c
arch/s390/kernel/vdso.c
arch/s390/kernel/vtime.c
arch/s390/kvm/Kconfig
arch/s390/kvm/sie64a.S
arch/s390/mm/fault.c
arch/score/include/asm/thread_info.h
arch/sh/Kconfig
arch/sh/Makefile
arch/sh/boards/board-urquell.c
arch/sh/boards/mach-ecovec24/setup.c
arch/sh/boards/mach-highlander/setup.c
arch/sh/boards/mach-sdk7786/setup.c
arch/sh/boards/mach-se/7724/setup.c
arch/sh/boards/mach-x3proto/setup.c
arch/sh/boot/compressed/Makefile
arch/sh/boot/compressed/head_32.S
arch/sh/configs/ap325rxa_defconfig
arch/sh/configs/cayman_defconfig
arch/sh/configs/dreamcast_defconfig
arch/sh/configs/ecovec24-romimage_defconfig
arch/sh/configs/ecovec24_defconfig
arch/sh/configs/edosk7705_defconfig
arch/sh/configs/edosk7760_defconfig
arch/sh/configs/espt_defconfig
arch/sh/configs/hp6xx_defconfig
arch/sh/configs/kfr2r09-romimage_defconfig
arch/sh/configs/kfr2r09_defconfig
arch/sh/configs/landisk_defconfig
arch/sh/configs/lboxre2_defconfig
arch/sh/configs/magicpanelr2_defconfig
arch/sh/configs/microdev_defconfig
arch/sh/configs/migor_defconfig
arch/sh/configs/polaris_defconfig
arch/sh/configs/r7780mp_defconfig
arch/sh/configs/r7785rp_defconfig
arch/sh/configs/rsk7201_defconfig
arch/sh/configs/rsk7203_defconfig
arch/sh/configs/rts7751r2d1_defconfig
arch/sh/configs/rts7751r2dplus_defconfig
arch/sh/configs/sdk7780_defconfig
arch/sh/configs/sdk7786_defconfig
arch/sh/configs/se7206_defconfig
arch/sh/configs/se7343_defconfig
arch/sh/configs/se7619_defconfig
arch/sh/configs/se7705_defconfig
arch/sh/configs/se7712_defconfig
arch/sh/configs/se7721_defconfig
arch/sh/configs/se7722_defconfig
arch/sh/configs/se7724_defconfig
arch/sh/configs/se7750_defconfig
arch/sh/configs/se7751_defconfig
arch/sh/configs/se7780_defconfig
arch/sh/configs/sh03_defconfig
arch/sh/configs/sh7710voipgw_defconfig
arch/sh/configs/sh7724_generic_defconfig
arch/sh/configs/sh7763rdp_defconfig
arch/sh/configs/sh7770_generic_defconfig
arch/sh/configs/sh7785lcr_32bit_defconfig
arch/sh/configs/sh7785lcr_defconfig
arch/sh/configs/shmin_defconfig
arch/sh/configs/shx3_defconfig
arch/sh/configs/snapgear_defconfig
arch/sh/configs/systemh_defconfig
arch/sh/configs/titan_defconfig
arch/sh/configs/ul2_defconfig
arch/sh/configs/urquell_defconfig
arch/sh/include/asm/atomic.h
arch/sh/include/asm/cache.h
arch/sh/include/asm/clkdev.h [new file with mode: 0644]
arch/sh/include/asm/clock.h
arch/sh/include/asm/dmaengine.h
arch/sh/include/asm/hw_breakpoint.h
arch/sh/include/asm/hwblk.h
arch/sh/include/asm/io_generic.h
arch/sh/include/asm/irq.h
arch/sh/include/asm/kexec.h
arch/sh/include/asm/machvec.h
arch/sh/include/asm/mmzone.h
arch/sh/include/asm/page.h
arch/sh/include/asm/processor.h
arch/sh/include/asm/processor_32.h
arch/sh/include/asm/setup.h
arch/sh/include/asm/siu.h
arch/sh/include/asm/smp-ops.h [new file with mode: 0644]
arch/sh/include/asm/smp.h
arch/sh/include/asm/thread_info.h
arch/sh/include/cpu-sh4/cpu/dma-register.h
arch/sh/include/cpu-sh4/cpu/mmu_context.h
arch/sh/include/mach-sdk7786/mach/fpga.h
arch/sh/kernel/Makefile
arch/sh/kernel/clkdev.c [new file with mode: 0644]
arch/sh/kernel/cpu/Makefile
arch/sh/kernel/cpu/clock-cpg.c
arch/sh/kernel/cpu/clock.c
arch/sh/kernel/cpu/hwblk.c
arch/sh/kernel/cpu/init.c
arch/sh/kernel/cpu/sh2/probe.c
arch/sh/kernel/cpu/sh2/setup-sh7619.c
arch/sh/kernel/cpu/sh2a/probe.c
arch/sh/kernel/cpu/sh2a/setup-mxg.c
arch/sh/kernel/cpu/sh2a/setup-sh7201.c
arch/sh/kernel/cpu/sh2a/setup-sh7203.c
arch/sh/kernel/cpu/sh2a/setup-sh7206.c
arch/sh/kernel/cpu/sh3/probe.c
arch/sh/kernel/cpu/sh3/setup-sh7705.c
arch/sh/kernel/cpu/sh3/setup-sh770x.c
arch/sh/kernel/cpu/sh3/setup-sh7710.c
arch/sh/kernel/cpu/sh3/setup-sh7720.c
arch/sh/kernel/cpu/sh4/clock-sh4-202.c
arch/sh/kernel/cpu/sh4/probe.c
arch/sh/kernel/cpu/sh4/setup-sh4-202.c
arch/sh/kernel/cpu/sh4/setup-sh7750.c
arch/sh/kernel/cpu/sh4/setup-sh7760.c
arch/sh/kernel/cpu/sh4a/clock-sh7343.c
arch/sh/kernel/cpu/sh4a/clock-sh7366.c
arch/sh/kernel/cpu/sh4a/clock-sh7722.c
arch/sh/kernel/cpu/sh4a/clock-sh7723.c
arch/sh/kernel/cpu/sh4a/clock-sh7724.c
arch/sh/kernel/cpu/sh4a/clock-sh7757.c
arch/sh/kernel/cpu/sh4a/clock-sh7763.c
arch/sh/kernel/cpu/sh4a/clock-sh7780.c
arch/sh/kernel/cpu/sh4a/clock-sh7785.c
arch/sh/kernel/cpu/sh4a/clock-sh7786.c
arch/sh/kernel/cpu/sh4a/clock-shx3.c
arch/sh/kernel/cpu/sh4a/setup-sh7343.c
arch/sh/kernel/cpu/sh4a/setup-sh7366.c
arch/sh/kernel/cpu/sh4a/setup-sh7722.c
arch/sh/kernel/cpu/sh4a/setup-sh7723.c
arch/sh/kernel/cpu/sh4a/setup-sh7724.c
arch/sh/kernel/cpu/sh4a/setup-sh7757.c
arch/sh/kernel/cpu/sh4a/setup-sh7763.c
arch/sh/kernel/cpu/sh4a/setup-sh7770.c
arch/sh/kernel/cpu/sh4a/setup-sh7780.c
arch/sh/kernel/cpu/sh4a/setup-sh7785.c
arch/sh/kernel/cpu/sh4a/setup-sh7786.c
arch/sh/kernel/cpu/sh4a/setup-shx3.c
arch/sh/kernel/cpu/sh4a/smp-shx3.c
arch/sh/kernel/cpu/sh5/probe.c
arch/sh/kernel/cpu/sh5/setup-sh5.c
arch/sh/kernel/crash_dump.c
arch/sh/kernel/dwarf.c
arch/sh/kernel/head_32.S
arch/sh/kernel/hw_breakpoint.c
arch/sh/kernel/idle.c
arch/sh/kernel/irq.c
arch/sh/kernel/localtimer.c
arch/sh/kernel/machine_kexec.c
arch/sh/kernel/machvec.c
arch/sh/kernel/process.c
arch/sh/kernel/ptrace_32.c
arch/sh/kernel/setup.c
arch/sh/kernel/smp.c
arch/sh/kernel/topology.c
arch/sh/kernel/traps_64.c
arch/sh/mm/Makefile
arch/sh/mm/cache-shx3.c [new file with mode: 0644]
arch/sh/mm/cache.c
arch/sh/mm/fault_32.c
arch/sh/mm/init.c
arch/sh/mm/numa.c
arch/sh/mm/pmb.c
arch/sh/mm/tlb-debugfs.c [new file with mode: 0644]
arch/sh/mm/tlbflush_64.c
arch/sparc/Kconfig
arch/sparc/include/asm/atomic_32.h
arch/sparc/include/asm/atomic_64.h
arch/sparc/include/asm/bitops_64.h
arch/sparc/include/asm/cache.h
arch/sparc/include/asm/thread_info_32.h
arch/sparc/include/asm/thread_info_64.h
arch/sparc/kernel/perf_event.c
arch/sparc/kernel/process_64.c
arch/sparc/kernel/stacktrace.c
arch/sparc/kernel/time_32.c
arch/sparc/kernel/traps_64.c
arch/um/drivers/line.c
arch/um/include/asm/system.h
arch/um/include/asm/thread_info.h
arch/um/kernel/skas/syscall.c
arch/um/sys-i386/asm/elf.h
arch/um/sys-x86_64/asm/elf.h
arch/um/sys-x86_64/signal.c
arch/x86/Kconfig
arch/x86/Kconfig.cpu
arch/x86/Kconfig.debug
arch/x86/Makefile
arch/x86/include/asm/alternative-asm.h
arch/x86/include/asm/alternative.h
arch/x86/include/asm/amd_iommu_types.h
arch/x86/include/asm/apic.h
arch/x86/include/asm/arch_hweight.h [new file with mode: 0644]
arch/x86/include/asm/atomic.h
arch/x86/include/asm/atomic64_32.h
arch/x86/include/asm/atomic64_64.h
arch/x86/include/asm/bitops.h
arch/x86/include/asm/boot.h
arch/x86/include/asm/cacheflush.h
arch/x86/include/asm/cmpxchg_32.h
arch/x86/include/asm/cpufeature.h
arch/x86/include/asm/ds.h [deleted file]
arch/x86/include/asm/dwarf2.h
arch/x86/include/asm/e820.h
arch/x86/include/asm/hardirq.h
arch/x86/include/asm/hpet.h
arch/x86/include/asm/hw_breakpoint.h
arch/x86/include/asm/hyperv.h
arch/x86/include/asm/hypervisor.h
arch/x86/include/asm/i387.h
arch/x86/include/asm/i8253.h
arch/x86/include/asm/insn.h
arch/x86/include/asm/io_apic.h
arch/x86/include/asm/kprobes.h
arch/x86/include/asm/mpspec.h
arch/x86/include/asm/mshyperv.h [new file with mode: 0644]
arch/x86/include/asm/msr-index.h
arch/x86/include/asm/percpu.h
arch/x86/include/asm/perf_event.h
arch/x86/include/asm/perf_event_p4.h [new file with mode: 0644]
arch/x86/include/asm/processor.h
arch/x86/include/asm/ptrace-abi.h
arch/x86/include/asm/ptrace.h
arch/x86/include/asm/thread_info.h
arch/x86/include/asm/traps.h
arch/x86/include/asm/uv/uv_bau.h
arch/x86/include/asm/uv/uv_hub.h
arch/x86/include/asm/uv/uv_mmrs.h
arch/x86/include/asm/vmware.h [deleted file]
arch/x86/include/asm/xsave.h
arch/x86/kernel/Makefile
arch/x86/kernel/acpi/boot.c
arch/x86/kernel/alternative.c
arch/x86/kernel/amd_iommu.c
arch/x86/kernel/amd_iommu_init.c
arch/x86/kernel/apic/es7000_32.c
arch/x86/kernel/apic/io_apic.c
arch/x86/kernel/apic/x2apic_uv_x.c
arch/x86/kernel/apm_32.c
arch/x86/kernel/cpu/Makefile
arch/x86/kernel/cpu/addon_cpuid_features.c
arch/x86/kernel/cpu/bugs.c
arch/x86/kernel/cpu/common.c
arch/x86/kernel/cpu/cpufreq/Makefile
arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
arch/x86/kernel/cpu/cpufreq/mperf.c [new file with mode: 0644]
arch/x86/kernel/cpu/cpufreq/mperf.h [new file with mode: 0644]
arch/x86/kernel/cpu/cpufreq/powernow-k8.c
arch/x86/kernel/cpu/cpufreq/powernow-k8.h
arch/x86/kernel/cpu/hypervisor.c
arch/x86/kernel/cpu/intel.c
arch/x86/kernel/cpu/intel_cacheinfo.c
arch/x86/kernel/cpu/mcheck/mce.c
arch/x86/kernel/cpu/mshyperv.c [new file with mode: 0644]
arch/x86/kernel/cpu/perf_event.c
arch/x86/kernel/cpu/perf_event_amd.c
arch/x86/kernel/cpu/perf_event_intel.c
arch/x86/kernel/cpu/perf_event_intel_ds.c [new file with mode: 0644]
arch/x86/kernel/cpu/perf_event_intel_lbr.c [new file with mode: 0644]
arch/x86/kernel/cpu/perf_event_p4.c [new file with mode: 0644]
arch/x86/kernel/cpu/perf_event_p6.c
arch/x86/kernel/cpu/vmware.c
arch/x86/kernel/ds.c [deleted file]
arch/x86/kernel/ds_selftest.c [deleted file]
arch/x86/kernel/ds_selftest.h [deleted file]
arch/x86/kernel/dumpstack.c
arch/x86/kernel/entry_32.S
arch/x86/kernel/hpet.c
arch/x86/kernel/hw_breakpoint.c
arch/x86/kernel/i387.c
arch/x86/kernel/i8253.c
arch/x86/kernel/irqinit.c
arch/x86/kernel/kprobes.c
arch/x86/kernel/microcode_core.c
arch/x86/kernel/microcode_intel.c
arch/x86/kernel/mpparse.c
arch/x86/kernel/mrst.c
arch/x86/kernel/process.c
arch/x86/kernel/process_32.c
arch/x86/kernel/process_64.c
arch/x86/kernel/ptrace.c
arch/x86/kernel/quirks.c
arch/x86/kernel/sfi.c
arch/x86/kernel/step.c
arch/x86/kernel/tboot.c
arch/x86/kernel/tlb_uv.c
arch/x86/kernel/traps.c
arch/x86/kernel/uv_irq.c
arch/x86/kernel/x8664_ksyms_64.c
arch/x86/kernel/xsave.c
arch/x86/kvm/vmx.c
arch/x86/kvm/x86.c
arch/x86/kvm/x86.h
arch/x86/lib/Makefile
arch/x86/lib/atomic64_32.c
arch/x86/lib/atomic64_386_32.S [new file with mode: 0644]
arch/x86/lib/atomic64_cx8_32.S [new file with mode: 0644]
arch/x86/math-emu/fpu_aux.c
arch/x86/math-emu/fpu_entry.c
arch/x86/math-emu/fpu_system.h
arch/x86/mm/Makefile
arch/x86/mm/pat.c
arch/x86/mm/pat_internal.h [new file with mode: 0644]
arch/x86/mm/pat_rbtree.c [new file with mode: 0644]
arch/x86/mm/srat_64.c
arch/x86/oprofile/nmi_int.c
arch/x86/oprofile/op_model_amd.c
arch/x86/oprofile/op_model_p4.c
arch/x86/oprofile/op_model_ppro.c
arch/x86/oprofile/op_x86_model.h
arch/x86/pci/mrst.c
arch/x86/xen/time.c
arch/xtensa/include/asm/atomic.h
arch/xtensa/include/asm/thread_info.h
arch/xtensa/kernel/time.c
crypto/Kconfig
drivers/acpi/acpica/Makefile
drivers/acpi/acpica/acevents.h
drivers/acpi/acpica/acglobal.h
drivers/acpi/acpica/acinterp.h
drivers/acpi/acpica/aclocal.h
drivers/acpi/acpica/actables.h
drivers/acpi/acpica/dsfield.c
drivers/acpi/acpica/dsmethod.c
drivers/acpi/acpica/dsmthdat.c
drivers/acpi/acpica/dsobject.c
drivers/acpi/acpica/dsopcode.c
drivers/acpi/acpica/dswexec.c
drivers/acpi/acpica/dswstate.c
drivers/acpi/acpica/evevent.c
drivers/acpi/acpica/evgpe.c
drivers/acpi/acpica/evgpeblk.c
drivers/acpi/acpica/evgpeinit.c [new file with mode: 0644]
drivers/acpi/acpica/evgpeutil.c [new file with mode: 0644]
drivers/acpi/acpica/evmisc.c
drivers/acpi/acpica/evxface.c
drivers/acpi/acpica/evxfevnt.c
drivers/acpi/acpica/exconfig.c
drivers/acpi/acpica/exconvrt.c
drivers/acpi/acpica/excreate.c
drivers/acpi/acpica/exdebug.c [new file with mode: 0644]
drivers/acpi/acpica/exfield.c
drivers/acpi/acpica/exfldio.c
drivers/acpi/acpica/exmisc.c
drivers/acpi/acpica/exmutex.c
drivers/acpi/acpica/exnames.c
drivers/acpi/acpica/exoparg1.c
drivers/acpi/acpica/exoparg2.c
drivers/acpi/acpica/exoparg3.c
drivers/acpi/acpica/exoparg6.c
drivers/acpi/acpica/exprep.c
drivers/acpi/acpica/exregion.c
drivers/acpi/acpica/exresnte.c
drivers/acpi/acpica/exresolv.c
drivers/acpi/acpica/exresop.c
drivers/acpi/acpica/exstore.c
drivers/acpi/acpica/exsystem.c
drivers/acpi/acpica/hwregs.c
drivers/acpi/acpica/hwsleep.c
drivers/acpi/acpica/hwvalid.c
drivers/acpi/acpica/nsaccess.c
drivers/acpi/acpica/nsdump.c
drivers/acpi/acpica/nsnames.c
drivers/acpi/acpica/nssearch.c
drivers/acpi/acpica/nsutils.c
drivers/acpi/acpica/psargs.c
drivers/acpi/acpica/psloop.c
drivers/acpi/acpica/psxface.c
drivers/acpi/acpica/rscreate.c
drivers/acpi/acpica/rslist.c
drivers/acpi/acpica/rsmisc.c
drivers/acpi/acpica/tbfadt.c
drivers/acpi/acpica/tbfind.c
drivers/acpi/acpica/tbinstal.c
drivers/acpi/acpica/tbutils.c
drivers/acpi/acpica/tbxface.c
drivers/acpi/acpica/tbxfroot.c
drivers/acpi/acpica/utalloc.c
drivers/acpi/acpica/utcopy.c
drivers/acpi/acpica/utdelete.c
drivers/acpi/acpica/uteval.c
drivers/acpi/acpica/utglobal.c
drivers/acpi/acpica/utmisc.c
drivers/acpi/acpica/utmutex.c
drivers/acpi/acpica/utobject.c
drivers/acpi/bus.c
drivers/acpi/osl.c
drivers/acpi/pci_irq.c
drivers/acpi/power.c
drivers/acpi/processor_idle.c
drivers/acpi/scan.c
drivers/acpi/system.c
drivers/ata/Kconfig
drivers/ata/Makefile
drivers/ata/ahci.c
drivers/ata/ahci.h [new file with mode: 0644]
drivers/ata/ahci_platform.c [new file with mode: 0644]
drivers/ata/ata_piix.c
drivers/ata/libahci.c [new file with mode: 0644]
drivers/ata/libata-core.c
drivers/ata/libata-eh.c
drivers/ata/libata-pmp.c
drivers/ata/libata-scsi.c
drivers/ata/libata-sff.c
drivers/ata/libata.h
drivers/ata/pata_acpi.c
drivers/ata/pata_ali.c
drivers/ata/pata_at91.c
drivers/ata/pata_atiixp.c
drivers/ata/pata_bf54x.c
drivers/ata/pata_cmd640.c
drivers/ata/pata_cs5520.c
drivers/ata/pata_cs5530.c
drivers/ata/pata_hpt366.c
drivers/ata/pata_hpt37x.c
drivers/ata/pata_hpt3x2n.c
drivers/ata/pata_icside.c
drivers/ata/pata_it821x.c
drivers/ata/pata_macio.c
drivers/ata/pata_mpc52xx.c
drivers/ata/pata_ns87415.c
drivers/ata/pata_octeon_cf.c
drivers/ata/pata_oldpiix.c
drivers/ata/pata_pcmcia.c
drivers/ata/pata_pdc2027x.c
drivers/ata/pata_pdc202xx_old.c
drivers/ata/pata_platform.c
drivers/ata/pata_radisys.c
drivers/ata/pata_sc1200.c
drivers/ata/pata_scc.c
drivers/ata/pata_sch.c
drivers/ata/pata_serverworks.c
drivers/ata/pata_sil680.c
drivers/ata/pata_via.c
drivers/ata/pdc_adma.c
drivers/ata/sata_inic162x.c
drivers/ata/sata_mv.c
drivers/ata/sata_nv.c
drivers/ata/sata_promise.c
drivers/ata/sata_qstor.c
drivers/ata/sata_sil.c
drivers/ata/sata_sil24.c
drivers/ata/sata_svw.c
drivers/ata/sata_sx4.c
drivers/ata/sata_uli.c
drivers/ata/sata_vsc.c
drivers/base/iommu.c
drivers/base/platform.c
drivers/base/power/runtime.c
drivers/base/power/sysfs.c
drivers/block/amiflop.c
drivers/block/cciss.c
drivers/block/hd.c
drivers/bluetooth/bluecard_cs.c
drivers/bluetooth/bt3c_cs.c
drivers/bluetooth/btuart_cs.c
drivers/bluetooth/dtl1_cs.c
drivers/char/agp/generic.c
drivers/char/bsr.c
drivers/char/i8k.c
drivers/char/pcmcia/cm4000_cs.c
drivers/char/pcmcia/cm4040_cs.c
drivers/char/pcmcia/ipwireless/main.c
drivers/char/pcmcia/ipwireless/main.h
drivers/char/pcmcia/ipwireless/tty.c
drivers/char/pcmcia/ipwireless/tty.h
drivers/char/pcmcia/synclink_cs.c
drivers/char/serial167.c
drivers/char/sysrq.c
drivers/char/tpm/Kconfig
drivers/char/tpm/tpm.c
drivers/char/tpm/tpm_tis.c
drivers/clocksource/cs5535-clockevt.c
drivers/clocksource/sh_cmt.c
drivers/clocksource/sh_mtu2.c
drivers/clocksource/sh_tmu.c
drivers/cpufreq/cpufreq.c
drivers/cpufreq/cpufreq_conservative.c
drivers/cpufreq/cpufreq_ondemand.c
drivers/cpuidle/governors/ladder.c
drivers/cpuidle/governors/menu.c
drivers/dma/shdma.c
drivers/dma/shdma.h
drivers/firewire/ohci.c
drivers/gpio/wm8994-gpio.c
drivers/gpu/drm/drm_bufs.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/radeon/atombios.h
drivers/i2c/busses/Kconfig
drivers/i2c/busses/i2c-bfin-twi.c
drivers/i2c/busses/i2c-cpm.c
drivers/i2c/busses/i2c-highlander.c
drivers/i2c/busses/i2c-ibm_iic.c
drivers/i2c/busses/i2c-mpc.c
drivers/i2c/busses/i2c-nomadik.c
drivers/i2c/busses/i2c-omap.c
drivers/i2c/busses/i2c-pxa.c
drivers/i2c/busses/i2c-s3c2410.c
drivers/i2c/i2c-core.c
drivers/ide/ide-cs.c
drivers/infiniband/Kconfig
drivers/infiniband/Makefile
drivers/infiniband/core/cma.c
drivers/infiniband/core/mad.c
drivers/infiniband/core/ucm.c
drivers/infiniband/core/ucma.c
drivers/infiniband/core/user_mad.c
drivers/infiniband/core/uverbs_main.c
drivers/infiniband/hw/amso1100/c2.h
drivers/infiniband/hw/amso1100/c2_alloc.c
drivers/infiniband/hw/amso1100/c2_cq.c
drivers/infiniband/hw/amso1100/c2_mq.h
drivers/infiniband/hw/amso1100/c2_provider.h
drivers/infiniband/hw/amso1100/c2_rnic.c
drivers/infiniband/hw/cxgb3/cxio_hal.c
drivers/infiniband/hw/cxgb3/cxio_hal.h
drivers/infiniband/hw/cxgb3/cxio_wr.h
drivers/infiniband/hw/cxgb3/iwch.c
drivers/infiniband/hw/cxgb3/iwch_cm.c
drivers/infiniband/hw/cxgb4/Kconfig [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/Makefile [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/cm.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/cq.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/device.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/ev.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/iw_cxgb4.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/mem.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/provider.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/qp.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/resource.c [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/t4.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/t4fw_ri_api.h [new file with mode: 0644]
drivers/infiniband/hw/cxgb4/user.h [new file with mode: 0644]
drivers/infiniband/hw/ipath/ipath_iba6110.c
drivers/infiniband/hw/ipath/ipath_iba6120.c
drivers/infiniband/hw/ipath/ipath_iba7220.c
drivers/infiniband/hw/mlx4/cq.c
drivers/infiniband/hw/mlx4/main.c
drivers/infiniband/hw/mlx4/qp.c
drivers/infiniband/hw/mthca/mthca_allocator.c
drivers/infiniband/hw/mthca/mthca_eq.c
drivers/infiniband/hw/mthca/mthca_provider.h
drivers/infiniband/hw/nes/nes_hw.c
drivers/infiniband/hw/nes/nes_nic.c
drivers/infiniband/hw/nes/nes_utils.c
drivers/infiniband/hw/nes/nes_verbs.c
drivers/infiniband/ulp/ipoib/ipoib_ethtool.c
drivers/infiniband/ulp/iser/iscsi_iser.c
drivers/infiniband/ulp/iser/iscsi_iser.h
drivers/infiniband/ulp/iser/iser_verbs.c
drivers/input/gameport/gameport.c
drivers/input/joystick/analog.c
drivers/input/misc/pcspkr.c
drivers/input/touchscreen/Kconfig
drivers/input/touchscreen/s3c2410_ts.c
drivers/isdn/divert/divert_procfs.c
drivers/isdn/hardware/avm/avm_cs.c
drivers/isdn/hardware/mISDN/hfcmulti.c
drivers/isdn/hisax/avma1_cs.c
drivers/isdn/hisax/elsa_cs.c
drivers/isdn/hisax/hfc4s8s_l1.c
drivers/isdn/hisax/sedlbauer_cs.c
drivers/isdn/hisax/teles_cs.c
drivers/macintosh/windfarm_pm81.c
drivers/media/IR/Kconfig
drivers/media/IR/Makefile
drivers/media/IR/imon.c [new file with mode: 0644]
drivers/media/IR/ir-core-priv.h [new file with mode: 0644]
drivers/media/IR/ir-functions.c
drivers/media/IR/ir-jvc-decoder.c [new file with mode: 0644]
drivers/media/IR/ir-keymaps.c [deleted file]
drivers/media/IR/ir-keytable.c
drivers/media/IR/ir-nec-decoder.c [new file with mode: 0644]
drivers/media/IR/ir-raw-event.c [new file with mode: 0644]
drivers/media/IR/ir-rc5-decoder.c [new file with mode: 0644]
drivers/media/IR/ir-rc6-decoder.c [new file with mode: 0644]
drivers/media/IR/ir-sony-decoder.c [new file with mode: 0644]
drivers/media/IR/ir-sysfs.c
drivers/media/IR/keymaps/Kconfig [new file with mode: 0644]
drivers/media/IR/keymaps/Makefile [new file with mode: 0644]
drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-apac-viewcomp.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-asus-pc39.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avermedia-a16d.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avermedia-cardbus.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avermedia-dvbt.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avermedia-m135a-rm-jx.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avermedia.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-avertv-303.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-behold-columbus.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-behold.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-budget-ci-old.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-cinergy-1400.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-cinergy.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-dm1105-nec.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-em-terratec.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-empty.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-encore-enltv-fm53.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-encore-enltv.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-encore-enltv2.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-evga-indtube.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-eztv.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-flydvb.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-flyvideo.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-fusionhdtv-mce.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-gadmei-rm008z.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-gotview7135.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-hauppauge-new.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-imon-mce.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-imon-pad.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-iodata-bctv7e.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-kaiomy.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-kworld-315u.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-manli.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-msi-tvanywhere.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-nebula.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-norwood.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-npgtech.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pctv-sedna.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pinnacle-color.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pinnacle-grey.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pixelview-mk12.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pixelview-new.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pixelview.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-powercolor-real-angel.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-proteus-2309.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-purpletv.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-pv951.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-rc5-tv.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-tbs-nec.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-tevii-nec.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-tt-1500.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-videomate-s350.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-videomate-tv-pvr.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c [new file with mode: 0644]
drivers/media/IR/keymaps/rc-winfast.c [new file with mode: 0644]
drivers/media/IR/rc-map.c [new file with mode: 0644]
drivers/media/common/tuners/tuner-xc2028.c
drivers/media/common/tuners/tuner-xc2028.h
drivers/media/dvb/bt8xx/dst.c
drivers/media/dvb/dm1105/dm1105.c
drivers/media/dvb/dvb-core/dvb_demux.c
drivers/media/dvb/dvb-core/dvb_frontend.c
drivers/media/dvb/dvb-usb/a800.c
drivers/media/dvb/dvb-usb/af9005-remote.c
drivers/media/dvb/dvb-usb/af9005.c
drivers/media/dvb/dvb-usb/af9005.h
drivers/media/dvb/dvb-usb/af9015.c
drivers/media/dvb/dvb-usb/af9015.h
drivers/media/dvb/dvb-usb/anysee.c
drivers/media/dvb/dvb-usb/az6027.c
drivers/media/dvb/dvb-usb/cinergyT2-core.c
drivers/media/dvb/dvb-usb/cxusb.c
drivers/media/dvb/dvb-usb/dib0700_devices.c
drivers/media/dvb/dvb-usb/dibusb-common.c
drivers/media/dvb/dvb-usb/dibusb-mb.c
drivers/media/dvb/dvb-usb/dibusb-mc.c
drivers/media/dvb/dvb-usb/dibusb.h
drivers/media/dvb/dvb-usb/digitv.c
drivers/media/dvb/dvb-usb/dtt200u.c
drivers/media/dvb/dvb-usb/dvb-usb-ids.h
drivers/media/dvb/dvb-usb/dvb-usb-urb.c
drivers/media/dvb/dvb-usb/dvb-usb.h
drivers/media/dvb/dvb-usb/dw2102.c
drivers/media/dvb/dvb-usb/friio-fe.c
drivers/media/dvb/dvb-usb/gp8psk.c
drivers/media/dvb/dvb-usb/m920x.c
drivers/media/dvb/dvb-usb/nova-t-usb2.c
drivers/media/dvb/dvb-usb/opera1.c
drivers/media/dvb/dvb-usb/vp702x.c
drivers/media/dvb/dvb-usb/vp7045.c
drivers/media/dvb/firewire/firedtv-avc.c
drivers/media/dvb/frontends/atbm8830_priv.h
drivers/media/dvb/frontends/au8522_decoder.c
drivers/media/dvb/frontends/au8522_dig.c
drivers/media/dvb/frontends/au8522_priv.h
drivers/media/dvb/frontends/dib3000mc.c
drivers/media/dvb/frontends/dib7000p.c
drivers/media/dvb/frontends/dib8000.h
drivers/media/dvb/frontends/ds3000.c
drivers/media/dvb/frontends/stv0900_core.c
drivers/media/dvb/frontends/stv090x.c
drivers/media/dvb/frontends/stv090x.h
drivers/media/dvb/frontends/stv6110x.c
drivers/media/dvb/frontends/stv6110x.h
drivers/media/dvb/mantis/mantis_input.c
drivers/media/dvb/mantis/mantis_vp1041.c
drivers/media/dvb/ngene/Kconfig
drivers/media/dvb/ngene/Makefile
drivers/media/dvb/ngene/ngene-cards.c [new file with mode: 0644]
drivers/media/dvb/ngene/ngene-core.c
drivers/media/dvb/ngene/ngene-dvb.c [new file with mode: 0644]
drivers/media/dvb/ngene/ngene-i2c.c [new file with mode: 0644]
drivers/media/dvb/ngene/ngene.h
drivers/media/dvb/pt1/pt1.c
drivers/media/dvb/pt1/va1j5jf8007s.c
drivers/media/dvb/pt1/va1j5jf8007s.h
drivers/media/dvb/pt1/va1j5jf8007t.c
drivers/media/dvb/pt1/va1j5jf8007t.h
drivers/media/dvb/ttpci/budget-ci.c
drivers/media/dvb/ttpci/budget.c
drivers/media/radio/radio-mr800.c
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/ak881x.c [new file with mode: 0644]
drivers/media/video/arv.c
drivers/media/video/au0828/au0828-video.c
drivers/media/video/bt8xx/bttv-cards.c
drivers/media/video/bt8xx/bttv-driver.c
drivers/media/video/bt8xx/bttv-input.c
drivers/media/video/bw-qcam.c
drivers/media/video/c-qcam.c
drivers/media/video/cpia2/cpia2_v4l.c
drivers/media/video/cx18/cx18-av-core.c
drivers/media/video/cx18/cx18-av-core.h
drivers/media/video/cx18/cx18-av-vbi.c
drivers/media/video/cx18/cx18-cards.c
drivers/media/video/cx18/cx18-cards.h
drivers/media/video/cx18/cx18-controls.c
drivers/media/video/cx18/cx18-fileops.c
drivers/media/video/cx18/cx18-i2c.c
drivers/media/video/cx18/cx18-ioctl.c
drivers/media/video/cx18/cx18-streams.c
drivers/media/video/cx18/cx18-vbi.c
drivers/media/video/cx231xx/cx231xx-audio.c
drivers/media/video/cx231xx/cx231xx-core.c
drivers/media/video/cx231xx/cx231xx-input.c
drivers/media/video/cx231xx/cx231xx-video.c
drivers/media/video/cx231xx/cx231xx.h
drivers/media/video/cx2341x.c
drivers/media/video/cx23885/cimax2.c
drivers/media/video/cx23885/cx23885-417.c
drivers/media/video/cx23885/cx23885-dvb.c
drivers/media/video/cx23885/cx23885-input.c
drivers/media/video/cx23885/cx23885-video.c
drivers/media/video/cx25840/cx25840-core.c
drivers/media/video/cx25840/cx25840-core.h
drivers/media/video/cx25840/cx25840-vbi.c
drivers/media/video/cx88/cx88-core.c
drivers/media/video/cx88/cx88-dvb.c
drivers/media/video/cx88/cx88-input.c
drivers/media/video/cx88/cx88-mpeg.c
drivers/media/video/cx88/cx88-video.c
drivers/media/video/cx88/cx88.h
drivers/media/video/davinci/dm644x_ccdc.c
drivers/media/video/davinci/dm644x_ccdc_regs.h
drivers/media/video/davinci/isif_regs.h
drivers/media/video/davinci/vpfe_capture.c
drivers/media/video/davinci/vpif_capture.c
drivers/media/video/davinci/vpif_display.c
drivers/media/video/em28xx/em28xx-audio.c
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/em28xx/em28xx-core.c
drivers/media/video/em28xx/em28xx-dvb.c
drivers/media/video/em28xx/em28xx-input.c
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/em28xx/em28xx.h
drivers/media/video/et61x251/et61x251_core.c
drivers/media/video/font.h [deleted file]
drivers/media/video/gspca/Kconfig
drivers/media/video/gspca/cpia1.c
drivers/media/video/gspca/gspca.c
drivers/media/video/gspca/gspca.h
drivers/media/video/gspca/ov534.c
drivers/media/video/gspca/pac207.c
drivers/media/video/gspca/sn9c2028.c
drivers/media/video/gspca/sn9c20x.c
drivers/media/video/gspca/sonixj.c
drivers/media/video/gspca/spca561.c
drivers/media/video/gspca/t613.c
drivers/media/video/gspca/vc032x.c
drivers/media/video/gspca/zc3xx.c
drivers/media/video/hdpvr/hdpvr-core.c
drivers/media/video/hdpvr/hdpvr-video.c
drivers/media/video/hdpvr/hdpvr.h
drivers/media/video/ir-kbd-i2c.c
drivers/media/video/ivtv/ivtv-driver.c
drivers/media/video/ivtv/ivtv-driver.h
drivers/media/video/ivtv/ivtv-fileops.c
drivers/media/video/ivtv/ivtv-i2c.c
drivers/media/video/ivtv/ivtv-ioctl.c
drivers/media/video/ivtv/ivtv-irq.c
drivers/media/video/ivtv/ivtv-streams.c
drivers/media/video/ivtv/ivtv-vbi.c
drivers/media/video/ivtv/ivtvfb.c
drivers/media/video/mem2mem_testdev.c [new file with mode: 0644]
drivers/media/video/meye.c
drivers/media/video/meye.h
drivers/media/video/mt9t031.c
drivers/media/video/mt9v022.c
drivers/media/video/mx1_camera.c
drivers/media/video/mx3_camera.c
drivers/media/video/omap/Kconfig [new file with mode: 0644]
drivers/media/video/omap/Makefile [new file with mode: 0644]
drivers/media/video/omap/omap_vout.c [new file with mode: 0644]
drivers/media/video/omap/omap_voutdef.h [new file with mode: 0644]
drivers/media/video/omap/omap_voutlib.c [new file with mode: 0644]
drivers/media/video/omap/omap_voutlib.h [new file with mode: 0644]
drivers/media/video/omap24xxcam.c
drivers/media/video/ov511.c
drivers/media/video/ov7670.c
drivers/media/video/ov9640.c
drivers/media/video/pms.c
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-v4l2.c
drivers/media/video/pwc/Kconfig
drivers/media/video/pxa_camera.c
drivers/media/video/rj54n1cb0c.c
drivers/media/video/s2255drv.c
drivers/media/video/saa7115.c
drivers/media/video/saa7127.c
drivers/media/video/saa7134/saa7134-alsa.c
drivers/media/video/saa7134/saa7134-cards.c
drivers/media/video/saa7134/saa7134-core.c
drivers/media/video/saa7134/saa7134-dvb.c
drivers/media/video/saa7134/saa7134-input.c
drivers/media/video/saa7134/saa7134-reg.h
drivers/media/video/saa7134/saa7134-video.c
drivers/media/video/saa7134/saa7134.h
drivers/media/video/sh_mobile_ceu_camera.c
drivers/media/video/sh_vou.c [new file with mode: 0644]
drivers/media/video/sn9c102/sn9c102_core.c
drivers/media/video/sn9c102/sn9c102_devtable.h
drivers/media/video/sn9c102/sn9c102_hv7131d.c
drivers/media/video/soc_camera.c
drivers/media/video/tlg2300/pd-dvb.c
drivers/media/video/tlg2300/pd-main.c
drivers/media/video/tlg2300/pd-radio.c
drivers/media/video/tlg2300/pd-video.c
drivers/media/video/tvp514x.c
drivers/media/video/tvp5150.c
drivers/media/video/tvp7002.c
drivers/media/video/usbvideo/quickcam_messenger.c
drivers/media/video/usbvision/usbvision-i2c.c
drivers/media/video/usbvision/usbvision-video.c
drivers/media/video/usbvision/usbvision.h
drivers/media/video/uvc/uvc_ctrl.c
drivers/media/video/uvc/uvc_driver.c
drivers/media/video/uvc/uvc_queue.c
drivers/media/video/uvc/uvcvideo.h
drivers/media/video/v4l2-common.c
drivers/media/video/v4l2-compat-ioctl32.c
drivers/media/video/v4l2-dev.c
drivers/media/video/v4l2-device.c
drivers/media/video/v4l2-event.c [new file with mode: 0644]
drivers/media/video/v4l2-fh.c [new file with mode: 0644]
drivers/media/video/v4l2-ioctl.c
drivers/media/video/v4l2-mem2mem.c [new file with mode: 0644]
drivers/media/video/videobuf-core.c
drivers/media/video/videobuf-dma-contig.c
drivers/media/video/videobuf-dma-sg.c
drivers/media/video/videobuf-dvb.c
drivers/media/video/videobuf-vmalloc.c
drivers/media/video/vivi.c
drivers/media/video/w9966.c
drivers/media/video/zc0301/zc0301_core.c
drivers/media/video/zc0301/zc0301_sensor.h
drivers/media/video/zoran/zoran.h
drivers/media/video/zoran/zoran_driver.c
drivers/media/video/zr364xx.c
drivers/message/i2o/i2o_config.c
drivers/mfd/Kconfig
drivers/mfd/Makefile
drivers/mfd/davinci_voicecodec.c [new file with mode: 0644]
drivers/mfd/twl-core.c
drivers/mfd/wm831x-irq.c
drivers/mfd/wm8994-core.c
drivers/mfd/wm8994-irq.c [new file with mode: 0644]
drivers/misc/eeprom/eeprom.c
drivers/misc/eeprom/eeprom_93cx6.c
drivers/misc/eeprom/max6875.c
drivers/misc/vmware_balloon.c
drivers/mmc/host/mmci.c
drivers/mmc/host/mmci.h
drivers/mmc/host/pxamci.c
drivers/mtd/maps/pcmciamtd.c
drivers/net/a2065.c
drivers/net/ariadne.c
drivers/net/bnx2x_hsi.h
drivers/net/e1000e/netdev.c
drivers/net/hydra.c
drivers/net/igbvf/netdev.c
drivers/net/pcmcia/3c574_cs.c
drivers/net/pcmcia/3c589_cs.c
drivers/net/pcmcia/axnet_cs.c
drivers/net/pcmcia/com20020_cs.c
drivers/net/pcmcia/fmvj18x_cs.c
drivers/net/pcmcia/ibmtr_cs.c
drivers/net/pcmcia/nmclan_cs.c
drivers/net/pcmcia/pcnet_cs.c
drivers/net/pcmcia/smc91c92_cs.c
drivers/net/pcmcia/xirc2ps_cs.c
drivers/net/ps3_gelic_wireless.c
drivers/net/smsc911x.c
drivers/net/wireless/airo_cs.c
drivers/net/wireless/atmel_cs.c
drivers/net/wireless/b43/pcmcia.c
drivers/net/wireless/hostap/hostap_cs.c
drivers/net/wireless/ipw2x00/ipw2100.c
drivers/net/wireless/libertas/if_cs.c
drivers/net/wireless/orinoco/orinoco_cs.c
drivers/net/wireless/orinoco/spectrum_cs.c
drivers/net/wireless/ray_cs.c
drivers/net/wireless/ray_cs.h
drivers/net/wireless/wl3501.h
drivers/net/wireless/wl3501_cs.c
drivers/net/zorro8390.c
drivers/oprofile/cpu_buffer.c
drivers/oprofile/oprof.c
drivers/oprofile/oprof.h
drivers/oprofile/timer_int.c
drivers/parport/parport_cs.c
drivers/pci/hotplug/cpqphp_core.c
drivers/pci/intel-iommu.c
drivers/pci/pci.c
drivers/pci/pci.h
drivers/pcmcia/Kconfig
drivers/pcmcia/Makefile
drivers/pcmcia/bfin_cf_pcmcia.c
drivers/pcmcia/cardbus.c
drivers/pcmcia/cistpl.c
drivers/pcmcia/cs.c
drivers/pcmcia/cs_internal.h
drivers/pcmcia/ds.c
drivers/pcmcia/omap_cf.c
drivers/pcmcia/pcmcia_cis.c [new file with mode: 0644]
drivers/pcmcia/pcmcia_ioctl.c
drivers/pcmcia/pcmcia_resource.c
drivers/pcmcia/pxa2xx_vpac270.c [new file with mode: 0644]
drivers/pcmcia/rsrc_iodyn.c [new file with mode: 0644]
drivers/pcmcia/rsrc_mgr.c
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/yenta_socket.c
drivers/ps3/ps3-sys-manager.c
drivers/regulator/core.c
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-davinci.c [new file with mode: 0644]
drivers/rtc/rtc-rx8581.c
drivers/rtc/rtc-stk17ta8.c
drivers/s390/block/dasd.c
drivers/s390/block/dasd_3990_erp.c
drivers/s390/block/dasd_alias.c
drivers/s390/block/dasd_devmap.c
drivers/s390/block/dasd_eckd.c
drivers/s390/block/dasd_eckd.h
drivers/s390/block/dasd_int.h
drivers/s390/char/Kconfig
drivers/s390/char/fs3270.c
drivers/s390/char/keyboard.c
drivers/s390/char/sclp_cpi_sys.c
drivers/s390/char/vmcp.c
drivers/s390/char/zcore.c
drivers/s390/cio/chsc_sch.c
drivers/s390/cio/cio.c
drivers/s390/cio/css.c
drivers/s390/cio/qdio.h
drivers/s390/cio/qdio_main.c
drivers/s390/cio/qdio_setup.c
drivers/s390/cio/qdio_thinint.c
drivers/s390/crypto/zcrypt_api.c
drivers/s390/net/qeth_core_main.c
drivers/s390/scsi/zfcp_cfdc.c
drivers/sbus/char/flash.c
drivers/scsi/bfa/include/defs/bfa_defs_cee.h
drivers/scsi/bfa/include/defs/bfa_defs_status.h
drivers/scsi/ipr.c
drivers/scsi/libsas/sas_scsi_host.c
drivers/scsi/pcmcia/aha152x_stub.c
drivers/scsi/pcmcia/fdomain_stub.c
drivers/scsi/pcmcia/nsp_cs.c
drivers/scsi/pcmcia/nsp_cs.h
drivers/scsi/pcmcia/qlogic_stub.c
drivers/scsi/pcmcia/sym53c500_cs.c
drivers/scsi/zorro7xx.c
drivers/serial/Kconfig
drivers/serial/Makefile
drivers/serial/atmel_serial.c
drivers/serial/serial_cs.c
drivers/serial/sh-sci.c
drivers/sh/Kconfig [new file with mode: 0644]
drivers/sh/Makefile
drivers/sh/clk-cpg.c [new file with mode: 0644]
drivers/sh/clk.c [new file with mode: 0644]
drivers/sh/intc.c
drivers/spi/pxa2xx_spi.c
drivers/spi/spi_mpc8xxx.c
drivers/ssb/main.c
drivers/staging/Kconfig
drivers/staging/Makefile
drivers/staging/comedi/drivers/cb_das16_cs.c
drivers/staging/comedi/drivers/das08_cs.c
drivers/staging/comedi/drivers/ni_daq_700.c
drivers/staging/comedi/drivers/ni_daq_dio24.c
drivers/staging/comedi/drivers/ni_labpc_cs.c
drivers/staging/comedi/drivers/ni_mio_cs.c
drivers/staging/comedi/drivers/quatech_daqp_cs.c
drivers/staging/cx25821/cx25821-alsa.c
drivers/staging/cx25821/cx25821-audio-upstream.c
drivers/staging/cx25821/cx25821-audups11.c
drivers/staging/cx25821/cx25821-cards.c
drivers/staging/cx25821/cx25821-core.c
drivers/staging/cx25821/cx25821-gpio.c
drivers/staging/cx25821/cx25821-i2c.c
drivers/staging/cx25821/cx25821-medusa-video.c
drivers/staging/cx25821/cx25821-video-upstream.c
drivers/staging/cx25821/cx25821-video.c
drivers/staging/cx25821/cx25821-video.h
drivers/staging/cx25821/cx25821-video0.c
drivers/staging/cx25821/cx25821-video1.c
drivers/staging/cx25821/cx25821-video2.c
drivers/staging/cx25821/cx25821-video3.c
drivers/staging/cx25821/cx25821-video4.c
drivers/staging/cx25821/cx25821-video5.c
drivers/staging/cx25821/cx25821-video6.c
drivers/staging/cx25821/cx25821-video7.c
drivers/staging/cx25821/cx25821-videoioctl.c
drivers/staging/cx25821/cx25821-vidups10.c
drivers/staging/cx25821/cx25821-vidups9.c
drivers/staging/netwave/netwave_cs.c
drivers/staging/tm6000/Kconfig [new file with mode: 0644]
drivers/staging/tm6000/Makefile [new file with mode: 0644]
drivers/staging/tm6000/README [new file with mode: 0644]
drivers/staging/tm6000/tm6000-alsa.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-cards.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-core.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-dvb.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-i2c.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-regs.h [new file with mode: 0644]
drivers/staging/tm6000/tm6000-stds.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000-usb-isoc.h [new file with mode: 0644]
drivers/staging/tm6000/tm6000-video.c [new file with mode: 0644]
drivers/staging/tm6000/tm6000.h [new file with mode: 0644]
drivers/staging/vt6655/rxtx.c
drivers/staging/vt6656/rxtx.c
drivers/staging/wavelan/wavelan_cs.c
drivers/staging/wlags49_h2/wl_cs.c
drivers/telephony/ixj_pcmcia.c
drivers/usb/gadget/at91_udc.c
drivers/usb/host/ehci-omap.c
drivers/usb/host/sl811_cs.c
drivers/usb/wusbcore/wa-xfer.c
drivers/video/amifb.c
drivers/video/cirrusfb.c
drivers/video/cobalt_lcdfb.c
drivers/video/fm2fb.c
drivers/virtio/virtio_pci.c
drivers/vlynq/Kconfig
drivers/xen/manage.c
drivers/zorro/proc.c
drivers/zorro/zorro-driver.c
drivers/zorro/zorro-sysfs.c
drivers/zorro/zorro.c
fs/cifs/asn1.c
fs/cifs/cifs_debug.c
fs/cifs/cifs_debug.h
fs/cifs/cifs_dfs_ref.c
fs/cifs/cifs_spnego.c
fs/cifs/cifs_unicode.c
fs/cifs/cifsacl.c
fs/cifs/cifsencrypt.c
fs/cifs/cifsfs.c
fs/cifs/cifsfs.h
fs/cifs/cifsglob.h
fs/cifs/cifsproto.h
fs/cifs/cifssmb.c
fs/cifs/connect.c
fs/cifs/dir.c
fs/cifs/dns_resolve.c
fs/cifs/export.c
fs/cifs/file.c
fs/cifs/inode.c
fs/cifs/ioctl.c
fs/cifs/link.c
fs/cifs/misc.c
fs/cifs/netmisc.c
fs/cifs/readdir.c
fs/cifs/sess.c
fs/cifs/transport.c
fs/cifs/xattr.c
fs/eventpoll.c
fs/inode.c
fs/jbd2/journal.c
fs/jfs/jfs_dmap.c
fs/libfs.c
fs/logfs/dev_bdev.c
fs/logfs/dev_mtd.c
fs/logfs/dir.c
fs/logfs/file.c
fs/logfs/gc.c
fs/logfs/inode.c
fs/logfs/journal.c
fs/logfs/logfs.h
fs/logfs/logfs_abi.h
fs/logfs/readwrite.c
fs/logfs/segment.c
fs/logfs/super.c
fs/namespace.c
fs/nfs/client.c
fs/nfs/delegation.c
fs/nfs/dir.c
fs/nfs/file.c
fs/nfs/fscache.c
fs/nfs/getroot.c
fs/nfs/inode.c
fs/nfs/internal.h
fs/nfs/iostat.h
fs/nfs/namespace.c
fs/nfs/nfs3acl.c
fs/nfs/nfs3proc.c
fs/nfs/nfs3xdr.c
fs/nfs/nfs4_fs.h
fs/nfs/nfs4namespace.c
fs/nfs/nfs4proc.c
fs/nfs/nfs4state.c
fs/nfs/nfs4xdr.c
fs/nfs/nfsroot.c
fs/nfs/pagelist.c
fs/nfs/proc.c
fs/nfs/read.c
fs/nfs/super.c
fs/nfs/unlink.c
fs/nfsd/export.c
fs/nfsd/nfs4callback.c
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c
fs/nfsd/nfsctl.c
fs/nfsd/nfsd.h
fs/nfsd/nfssvc.c
fs/nfsd/state.h
fs/nfsd/vfs.c
fs/nfsd/vfs.h
fs/nfsd/xdr4.h
fs/omfs/inode.c
fs/proc/base.c
fs/proc/inode.c
fs/proc/kcore.c
fs/proc/kmsg.c
fs/proc/vmcore.c
include/acpi/acexcep.h
include/acpi/acoutput.h
include/acpi/acpiosxf.h
include/acpi/acpixf.h
include/acpi/actbl2.h
include/acpi/actypes.h
include/asm-generic/atomic.h
include/asm-generic/bitops/arch_hweight.h [new file with mode: 0644]
include/asm-generic/bitops/const_hweight.h [new file with mode: 0644]
include/asm-generic/bitops/hweight.h
include/linux/acpi.h
include/linux/ahci_platform.h [new file with mode: 0644]
include/linux/amba/mmci.h
include/linux/ata.h
include/linux/bitops.h
include/linux/clocksource.h
include/linux/cpufreq.h
include/linux/cpuset.h
include/linux/debugobjects.h
include/linux/device.h
include/linux/elf.h
include/linux/fs.h
include/linux/ftrace.h
include/linux/ftrace_event.h
include/linux/hrtimer.h
include/linux/hw_breakpoint.h
include/linux/i2c-omap.h [new file with mode: 0644]
include/linux/i2c/twl.h
include/linux/init_task.h
include/linux/interrupt.h
include/linux/iommu.h
include/linux/irq.h
include/linux/kernel.h
include/linux/kfifo.h
include/linux/kobj_map.h
include/linux/kref.h
include/linux/ktime.h
include/linux/libata.h
include/linux/lsm_audit.h
include/linux/meye.h
include/linux/mfd/davinci_voicecodec.h [new file with mode: 0644]
include/linux/mfd/wm8350/audio.h
include/linux/mfd/wm8994/core.h
include/linux/mfd/wm8994/pdata.h
include/linux/mlx4/device.h
include/linux/mlx4/qp.h
include/linux/mm.h
include/linux/mod_devicetable.h
include/linux/module.h
include/linux/netdevice.h
include/linux/nfs_fs.h
include/linux/nfs_fs_sb.h
include/linux/nfs_xdr.h
include/linux/nfsd/nfsfh.h
include/linux/perf_event.h
include/linux/platform_device.h
include/linux/pm_qos_params.h
include/linux/pm_runtime.h
include/linux/pm_wakeup.h
include/linux/ptrace.h
include/linux/rbtree.h
include/linux/rcupdate.h
include/linux/rcutiny.h
include/linux/rcutree.h
include/linux/ring_buffer.h
include/linux/rtc-v3020.h
include/linux/sched.h
include/linux/security.h
include/linux/serial_sci.h
include/linux/sh_clk.h [new file with mode: 0644]
include/linux/sh_dma.h [new file with mode: 0644]
include/linux/sh_intc.h
include/linux/srcu.h
include/linux/stop_machine.h
include/linux/sunrpc/auth.h
include/linux/sunrpc/auth_gss.h
include/linux/sunrpc/gss_api.h
include/linux/sunrpc/gss_krb5.h
include/linux/sunrpc/metrics.h
include/linux/sunrpc/sched.h
include/linux/sunrpc/xdr.h
include/linux/sunrpc/xprt.h
include/linux/tick.h
include/linux/time.h
include/linux/timer.h
include/linux/timex.h
include/linux/tracepoint.h
include/linux/types.h
include/linux/usb/audio-v2.h [new file with mode: 0644]
include/linux/usb/audio.h
include/linux/videodev2.h
include/linux/wait.h
include/linux/zorro.h
include/media/ak881x.h [new file with mode: 0644]
include/media/davinci/vpfe_capture.h
include/media/ir-common.h
include/media/ir-core.h
include/media/ir-kbd-i2c.h
include/media/rc-map.h [new file with mode: 0644]
include/media/sh_vou.h [new file with mode: 0644]
include/media/soc_camera.h
include/media/v4l2-chip-ident.h
include/media/v4l2-common.h
include/media/v4l2-dev.h
include/media/v4l2-event.h [new file with mode: 0644]
include/media/v4l2-fh.h [new file with mode: 0644]
include/media/v4l2-ioctl.h
include/media/v4l2-mem2mem.h [new file with mode: 0644]
include/media/v4l2-subdev.h
include/media/videobuf-core.h
include/media/videobuf-dma-sg.h
include/media/videobuf-vmalloc.h
include/pcmcia/cs.h
include/pcmcia/ds.h
include/pcmcia/mem_op.h [deleted file]
include/pcmcia/ss.h
include/rdma/ib_verbs.h
include/sound/asound.h
include/sound/es1688.h
include/sound/info.h
include/sound/jack.h
include/sound/pcm.h
include/sound/soc-dai.h
include/sound/soc-dapm.h
include/sound/soc.h
include/sound/tlv320aic3x.h [new file with mode: 0644]
include/sound/tlv320dac33-plat.h
include/sound/uda134x.h
include/sound/version.h
include/sound/wm8903.h [new file with mode: 0644]
include/sound/wm8904.h
include/sound/wm8960.h [new file with mode: 0644]
include/sound/wm9090.h [new file with mode: 0644]
include/trace/define_trace.h
include/trace/events/lock.h
include/trace/events/module.h
include/trace/events/napi.h
include/trace/events/sched.h
include/trace/events/signal.h
include/trace/ftrace.h
init/Kconfig
ipc/mqueue.c
kernel/Makefile
kernel/acct.c
kernel/capability.c
kernel/cgroup.c
kernel/cgroup_freezer.c
kernel/compat.c
kernel/cpu.c
kernel/cpuset.c
kernel/cred-internals.h [deleted file]
kernel/cred.c
kernel/exit.c
kernel/fork.c
kernel/groups.c
kernel/hrtimer.c
kernel/hw_breakpoint.c
kernel/irq/handle.c
kernel/irq/manage.c
kernel/irq/proc.c
kernel/kprobes.c
kernel/lockdep.c
kernel/lockdep_internals.h
kernel/lockdep_proc.c
kernel/module.c
kernel/perf_event.c
kernel/pm_qos_params.c
kernel/posix-cpu-timers.c
kernel/power/Makefile
kernel/power/block_io.c [new file with mode: 0644]
kernel/power/power.h
kernel/power/snapshot.c
kernel/power/swap.c
kernel/power/user.c
kernel/ptrace.c
kernel/rcupdate.c
kernel/rcutiny.c
kernel/rcutiny_plugin.h [new file with mode: 0644]
kernel/rcutorture.c
kernel/rcutree.c
kernel/rcutree.h
kernel/rcutree_plugin.h
kernel/rcutree_trace.c
kernel/sched.c
kernel/sched_debug.c
kernel/sched_fair.c
kernel/sched_features.h
kernel/sched_idletask.c
kernel/sched_rt.c
kernel/softirq.c
kernel/stop_machine.c
kernel/sys.c
kernel/sysctl.c
kernel/time.c
kernel/time/clocksource.c
kernel/time/ntp.c
kernel/time/tick-sched.c
kernel/time/timekeeping.c
kernel/time/timer_list.c
kernel/timer.c
kernel/trace/Kconfig
kernel/trace/Makefile
kernel/trace/ftrace.c
kernel/trace/ring_buffer.c
kernel/trace/ring_buffer_benchmark.c
kernel/trace/trace.c
kernel/trace/trace.h
kernel/trace/trace_entries.h
kernel/trace/trace_events_filter.c
kernel/trace/trace_functions_graph.c
kernel/trace/trace_hw_branches.c [deleted file]
kernel/trace/trace_irqsoff.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_ksym.c
kernel/trace/trace_output.c
kernel/trace/trace_sched_switch.c
kernel/trace/trace_sched_wakeup.c
kernel/trace/trace_selftest.c
kernel/user.c
kernel/workqueue.c
lib/Kconfig.debug
lib/Makefile
lib/atomic64.c
lib/atomic64_test.c [new file with mode: 0644]
lib/debugobjects.c
lib/hweight.c
lib/rbtree.c
mm/memcontrol.c
mm/mlock.c
mm/page_alloc.c
mm/percpu-km.c [new file with mode: 0644]
mm/percpu-vm.c [new file with mode: 0644]
mm/percpu.c
net/ipv4/ipmr.c
net/mac80211/mlme.c
net/sunrpc/auth.c
net/sunrpc/auth_gss/Makefile
net/sunrpc/auth_gss/auth_gss.c
net/sunrpc/auth_gss/gss_krb5_crypto.c
net/sunrpc/auth_gss/gss_krb5_keys.c [new file with mode: 0644]
net/sunrpc/auth_gss/gss_krb5_mech.c
net/sunrpc/auth_gss/gss_krb5_seal.c
net/sunrpc/auth_gss/gss_krb5_seqnum.c
net/sunrpc/auth_gss/gss_krb5_unseal.c
net/sunrpc/auth_gss/gss_krb5_wrap.c
net/sunrpc/auth_gss/gss_mech_switch.c
net/sunrpc/auth_gss/gss_spkm3_mech.c
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/cache.c
net/sunrpc/clnt.c
net/sunrpc/sched.c
net/sunrpc/stats.c
net/sunrpc/svc_xprt.c
net/sunrpc/svcsock.c
net/sunrpc/xdr.c
net/sunrpc/xprt.c
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
net/sunrpc/xprtrdma/transport.c
net/sunrpc/xprtsock.c
net/wimax/op-rfkill.c
scripts/Makefile.lib
scripts/kconfig/util.c
scripts/mod/file2alias.c
scripts/package/mkspec
scripts/selinux/genheaders/genheaders.c
security/capability.c
security/commoncap.c
security/device_cgroup.c
security/integrity/ima/Kconfig
security/integrity/ima/ima.h
security/integrity/ima/ima_audit.c
security/integrity/ima/ima_crypto.c
security/integrity/ima/ima_fs.c
security/integrity/ima/ima_iint.c
security/integrity/ima/ima_init.c
security/integrity/ima/ima_main.c
security/integrity/ima/ima_policy.c
security/integrity/ima/ima_queue.c
security/keys/internal.h
security/keys/key.c
security/keys/keyctl.c
security/keys/keyring.c
security/keys/permission.c
security/keys/proc.c
security/keys/process_keys.c
security/keys/request_key.c
security/lsm_audit.c
security/security.c
security/selinux/avc.c
security/selinux/hooks.c
security/selinux/include/initial_sid_to_string.h
security/selinux/include/netlabel.h
security/selinux/netlabel.c
security/selinux/netlink.c
security/selinux/nlmsgtab.c
security/selinux/selinuxfs.c
security/selinux/ss/mls.c
security/selinux/ss/policydb.c
security/selinux/ss/services.c
security/smack/smack_lsm.c
security/tomoyo/Makefile
security/tomoyo/common.c
security/tomoyo/common.h
security/tomoyo/domain.c
security/tomoyo/file.c
security/tomoyo/gc.c
security/tomoyo/path_group.c [new file with mode: 0644]
security/tomoyo/realpath.c
sound/atmel/Kconfig
sound/atmel/ac97c.c
sound/core/control.c
sound/core/info.c
sound/core/jack.c
sound/core/oss/mixer_oss.c
sound/core/oss/pcm_oss.c
sound/core/pcm.c
sound/core/pcm_native.c
sound/core/rawmidi.c
sound/core/seq/seq_clientmgr.c
sound/core/sound.c
sound/core/timer.c
sound/drivers/opl4/opl4_proc.c
sound/drivers/pcsp/pcsp.h
sound/drivers/pcsp/pcsp_input.c
sound/drivers/pcsp/pcsp_lib.c
sound/i2c/i2c.c
sound/isa/Kconfig
sound/isa/es1688/es1688.c
sound/isa/es1688/es1688_lib.c
sound/isa/gus/gus_mem_proc.c
sound/isa/gus/gusextreme.c
sound/isa/sb/Makefile
sound/isa/sb/es968.c [deleted file]
sound/oss/dmasound/dmasound_paula.c
sound/pci/Kconfig
sound/pci/Makefile
sound/pci/asihpi/Makefile [new file with mode: 0644]
sound/pci/asihpi/asihpi.c [new file with mode: 0644]
sound/pci/asihpi/hpi.h [new file with mode: 0644]
sound/pci/asihpi/hpi6000.c [new file with mode: 0644]
sound/pci/asihpi/hpi6000.h [new file with mode: 0644]
sound/pci/asihpi/hpi6205.c [new file with mode: 0644]
sound/pci/asihpi/hpi6205.h [new file with mode: 0644]
sound/pci/asihpi/hpi_internal.h [new file with mode: 0644]
sound/pci/asihpi/hpicmn.c [new file with mode: 0644]
sound/pci/asihpi/hpicmn.h [new file with mode: 0644]
sound/pci/asihpi/hpidebug.c [new file with mode: 0644]
sound/pci/asihpi/hpidebug.h [new file with mode: 0644]
sound/pci/asihpi/hpidspcd.c [new file with mode: 0644]
sound/pci/asihpi/hpidspcd.h [new file with mode: 0644]
sound/pci/asihpi/hpifunc.c [new file with mode: 0644]
sound/pci/asihpi/hpimsginit.c [new file with mode: 0644]
sound/pci/asihpi/hpimsginit.h [new file with mode: 0644]
sound/pci/asihpi/hpimsgx.c [new file with mode: 0644]
sound/pci/asihpi/hpimsgx.h [new file with mode: 0644]
sound/pci/asihpi/hpioctl.c [new file with mode: 0644]
sound/pci/asihpi/hpioctl.h [new file with mode: 0644]
sound/pci/asihpi/hpios.c [new file with mode: 0644]
sound/pci/asihpi/hpios.h [new file with mode: 0644]
sound/pci/asihpi/hpipcida.h [new file with mode: 0644]
sound/pci/cs4281.c
sound/pci/cs46xx/cs46xx_lib.c
sound/pci/emu10k1/emu10k1_main.c
sound/pci/emu10k1/emuproc.c
sound/pci/es1968.c
sound/pci/hda/Kconfig
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_codec.h
sound/pci/hda/hda_intel.c
sound/pci/hda/hda_local.h
sound/pci/hda/patch_analog.c
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_hdmi.c
sound/pci/hda/patch_intelhdmi.c
sound/pci/hda/patch_realtek.c
sound/pci/ice1712/aureon.c
sound/pci/maestro3.c
sound/pci/mixart/mixart.c
sound/pcmcia/pdaudiocf/pdaudiocf.c
sound/pcmcia/pdaudiocf/pdaudiocf.h
sound/pcmcia/vx/vxpocket.c
sound/pcmcia/vx/vxpocket.h
sound/ppc/tumbler.c
sound/soc/atmel/atmel-pcm.c
sound/soc/blackfin/Kconfig
sound/soc/blackfin/Makefile
sound/soc/blackfin/bf5xx-ad193x.c [moved from sound/soc/blackfin/bf5xx-ad1938.c with 65% similarity]
sound/soc/blackfin/bf5xx-sport.h
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/ad1836.c
sound/soc/codecs/ad1938.c [deleted file]
sound/soc/codecs/ad1938.h [deleted file]
sound/soc/codecs/ad193x.c [new file with mode: 0644]
sound/soc/codecs/ad193x.h [new file with mode: 0644]
sound/soc/codecs/ak4104.c
sound/soc/codecs/ak4535.c
sound/soc/codecs/ak4642.c
sound/soc/codecs/ak4671.c
sound/soc/codecs/cq93vc.c [new file with mode: 0644]
sound/soc/codecs/cq93vc.h [new file with mode: 0644]
sound/soc/codecs/cs4270.c
sound/soc/codecs/cx20442.c
sound/soc/codecs/da7210.c
sound/soc/codecs/ssm2602.c
sound/soc/codecs/stac9766.c
sound/soc/codecs/tlv320aic23.c
sound/soc/codecs/tlv320aic26.c
sound/soc/codecs/tlv320aic3x.c
sound/soc/codecs/tlv320dac33.c
sound/soc/codecs/tpa6130a2.c
sound/soc/codecs/twl4030.c
sound/soc/codecs/twl6040.c [new file with mode: 0644]
sound/soc/codecs/twl6040.h [new file with mode: 0644]
sound/soc/codecs/uda134x.c
sound/soc/codecs/uda1380.c
sound/soc/codecs/wm8350.c
sound/soc/codecs/wm8350.h
sound/soc/codecs/wm8400.c
sound/soc/codecs/wm8510.c
sound/soc/codecs/wm8523.c
sound/soc/codecs/wm8580.c
sound/soc/codecs/wm8711.c
sound/soc/codecs/wm8728.c
sound/soc/codecs/wm8731.c
sound/soc/codecs/wm8750.c
sound/soc/codecs/wm8753.c
sound/soc/codecs/wm8776.c
sound/soc/codecs/wm8900.c
sound/soc/codecs/wm8903.c
sound/soc/codecs/wm8903.h
sound/soc/codecs/wm8904.c
sound/soc/codecs/wm8904.h
sound/soc/codecs/wm8940.c
sound/soc/codecs/wm8955.c
sound/soc/codecs/wm8960.c
sound/soc/codecs/wm8960.h
sound/soc/codecs/wm8961.c
sound/soc/codecs/wm8971.c
sound/soc/codecs/wm8974.c
sound/soc/codecs/wm8978.c
sound/soc/codecs/wm8988.c
sound/soc/codecs/wm8990.c
sound/soc/codecs/wm8993.c
sound/soc/codecs/wm8994.c
sound/soc/codecs/wm8994.h
sound/soc/codecs/wm9081.c
sound/soc/codecs/wm9090.c [new file with mode: 0644]
sound/soc/codecs/wm9090.h [new file with mode: 0644]
sound/soc/codecs/wm9712.c
sound/soc/codecs/wm9713.c
sound/soc/codecs/wm_hubs.c
sound/soc/davinci/Kconfig
sound/soc/davinci/Makefile
sound/soc/davinci/davinci-evm.c
sound/soc/davinci/davinci-vcif.c [new file with mode: 0644]
sound/soc/davinci/davinci-vcif.h [new file with mode: 0644]
sound/soc/imx/Kconfig
sound/soc/imx/Makefile
sound/soc/imx/wm1133-ev1.c [new file with mode: 0644]
sound/soc/omap/Kconfig
sound/soc/omap/Makefile
sound/soc/omap/mcpdm.c
sound/soc/omap/omap-mcbsp.c
sound/soc/omap/omap3pandora.c
sound/soc/omap/rx51.c [new file with mode: 0644]
sound/soc/omap/sdp4430.c [new file with mode: 0644]
sound/soc/omap/zoom2.c
sound/soc/pxa/Kconfig
sound/soc/pxa/Makefile
sound/soc/pxa/pxa-ssp.c
sound/soc/pxa/spitz.c
sound/soc/pxa/z2.c [new file with mode: 0644]
sound/soc/s3c24xx/Kconfig
sound/soc/s3c24xx/Makefile
sound/soc/s3c24xx/jive_wm8750.c
sound/soc/s3c24xx/neo1973_gta02_wm8753.c
sound/soc/s3c24xx/regs-i2s-v2.h [moved from arch/arm/plat-samsung/include/plat/regs-s3c2412-iis.h with 60% similarity]
sound/soc/s3c24xx/s3c-i2s-v2.c
sound/soc/s3c24xx/s3c-i2s-v2.h
sound/soc/s3c24xx/s3c2412-i2s.c
sound/soc/s3c24xx/s3c2412-i2s.h
sound/soc/s3c24xx/s3c64xx-i2s-v4.c [new file with mode: 0644]
sound/soc/s3c24xx/s3c64xx-i2s.c
sound/soc/s3c24xx/s3c64xx-i2s.h
sound/soc/s3c24xx/smdk64xx_wm8580.c
sound/soc/sh/Kconfig
sound/soc/sh/fsi-ak4642.c
sound/soc/sh/fsi.c
sound/soc/soc-cache.c
sound/soc/soc-core.c
sound/soc/soc-dapm.c
sound/soc/soc-jack.c
sound/usb/Kconfig
sound/usb/Makefile
sound/usb/caiaq/control.c
sound/usb/caiaq/device.c
sound/usb/caiaq/device.h
sound/usb/caiaq/input.c
sound/usb/card.c [new file with mode: 0644]
sound/usb/card.h [new file with mode: 0644]
sound/usb/debug.h [new file with mode: 0644]
sound/usb/endpoint.c [new file with mode: 0644]
sound/usb/endpoint.h [new file with mode: 0644]
sound/usb/format.c [new file with mode: 0644]
sound/usb/format.h [new file with mode: 0644]
sound/usb/helper.c [new file with mode: 0644]
sound/usb/helper.h [new file with mode: 0644]
sound/usb/midi.c [moved from sound/usb/usbmidi.c with 99% similarity]
sound/usb/midi.h [new file with mode: 0644]
sound/usb/misc/Makefile [new file with mode: 0644]
sound/usb/misc/ua101.c [moved from sound/usb/ua101.c with 99% similarity]
sound/usb/mixer.c [moved from sound/usb/usbmixer.c with 72% similarity]
sound/usb/mixer.h [new file with mode: 0644]
sound/usb/mixer_maps.c [moved from sound/usb/usbmixer_maps.c with 98% similarity]
sound/usb/mixer_quirks.c [new file with mode: 0644]
sound/usb/mixer_quirks.h [new file with mode: 0644]
sound/usb/pcm.c [new file with mode: 0644]
sound/usb/pcm.h [new file with mode: 0644]
sound/usb/proc.c [new file with mode: 0644]
sound/usb/proc.h [new file with mode: 0644]
sound/usb/quirks-table.h [moved from sound/usb/usbquirks.h with 97% similarity]
sound/usb/quirks.c [new file with mode: 0644]
sound/usb/quirks.h [new file with mode: 0644]
sound/usb/urb.c [new file with mode: 0644]
sound/usb/urb.h [new file with mode: 0644]
sound/usb/usbaudio.c [deleted file]
sound/usb/usbaudio.h
sound/usb/usx2y/us122l.c
sound/usb/usx2y/usbusx2y.h
tools/perf/Documentation/perf-annotate.txt
tools/perf/Documentation/perf-bench.txt
tools/perf/Documentation/perf-buildid-cache.txt
tools/perf/Documentation/perf-diff.txt
tools/perf/Documentation/perf-inject.txt [new file with mode: 0644]
tools/perf/Documentation/perf-kmem.txt
tools/perf/Documentation/perf-kvm.txt [new file with mode: 0644]
tools/perf/Documentation/perf-list.txt
tools/perf/Documentation/perf-probe.txt
tools/perf/Documentation/perf-record.txt
tools/perf/Documentation/perf-sched.txt
tools/perf/Documentation/perf-stat.txt
tools/perf/Documentation/perf-test.txt [new file with mode: 0644]
tools/perf/Documentation/perf-trace-perl.txt
tools/perf/Documentation/perf-trace-python.txt
tools/perf/Documentation/perf-trace.txt
tools/perf/Makefile
tools/perf/arch/powerpc/Makefile [new file with mode: 0644]
tools/perf/arch/powerpc/util/dwarf-regs.c [new file with mode: 0644]
tools/perf/arch/x86/Makefile [new file with mode: 0644]
tools/perf/arch/x86/util/dwarf-regs.c [new file with mode: 0644]
tools/perf/bench/mem-memcpy.c
tools/perf/bench/sched-messaging.c
tools/perf/bench/sched-pipe.c
tools/perf/builtin-annotate.c
tools/perf/builtin-bench.c
tools/perf/builtin-buildid-cache.c
tools/perf/builtin-buildid-list.c
tools/perf/builtin-diff.c
tools/perf/builtin-help.c
tools/perf/builtin-inject.c [new file with mode: 0644]
tools/perf/builtin-kmem.c
tools/perf/builtin-kvm.c [new file with mode: 0644]
tools/perf/builtin-lock.c
tools/perf/builtin-probe.c
tools/perf/builtin-record.c
tools/perf/builtin-report.c
tools/perf/builtin-sched.c
tools/perf/builtin-stat.c
tools/perf/builtin-test.c [new file with mode: 0644]
tools/perf/builtin-timechart.c
tools/perf/builtin-top.c
tools/perf/builtin-trace.c
tools/perf/builtin.h
tools/perf/command-list.txt
tools/perf/perf-archive.sh
tools/perf/perf.c
tools/perf/perf.h
tools/perf/scripts/perl/Perf-Trace-Util/lib/Perf/Trace/Util.pm
tools/perf/scripts/perl/bin/check-perf-trace-record
tools/perf/scripts/perl/bin/failed-syscalls-record
tools/perf/scripts/perl/bin/failed-syscalls-report
tools/perf/scripts/perl/bin/rw-by-file-record
tools/perf/scripts/perl/bin/rw-by-file-report
tools/perf/scripts/perl/bin/rw-by-pid-record
tools/perf/scripts/perl/bin/rw-by-pid-report
tools/perf/scripts/perl/bin/rwtop-record [new file with mode: 0644]
tools/perf/scripts/perl/bin/rwtop-report [new file with mode: 0644]
tools/perf/scripts/perl/bin/wakeup-latency-record
tools/perf/scripts/perl/bin/wakeup-latency-report
tools/perf/scripts/perl/bin/workqueue-stats-record
tools/perf/scripts/perl/bin/workqueue-stats-report
tools/perf/scripts/perl/failed-syscalls.pl
tools/perf/scripts/perl/rw-by-pid.pl
tools/perf/scripts/perl/rwtop.pl [new file with mode: 0644]
tools/perf/scripts/perl/wakeup-latency.pl
tools/perf/scripts/perl/workqueue-stats.pl
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py
tools/perf/scripts/python/bin/failed-syscalls-by-pid-record
tools/perf/scripts/python/bin/failed-syscalls-by-pid-report
tools/perf/scripts/python/bin/sctop-record [new file with mode: 0644]
tools/perf/scripts/python/bin/sctop-report [new file with mode: 0644]
tools/perf/scripts/python/bin/syscall-counts-by-pid-record
tools/perf/scripts/python/bin/syscall-counts-by-pid-report
tools/perf/scripts/python/bin/syscall-counts-record
tools/perf/scripts/python/bin/syscall-counts-report
tools/perf/scripts/python/sctop.py [new file with mode: 0644]
tools/perf/util/PERF-VERSION-GEN
tools/perf/util/bitmap.c [new file with mode: 0644]
tools/perf/util/build-id.c
tools/perf/util/cache.h
tools/perf/util/callchain.c
tools/perf/util/callchain.h
tools/perf/util/color.c
tools/perf/util/color.h
tools/perf/util/debug.c
tools/perf/util/debug.h
tools/perf/util/event.c
tools/perf/util/event.h
tools/perf/util/header.c
tools/perf/util/header.h
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/hweight.c [new file with mode: 0644]
tools/perf/util/include/asm/bitops.h [deleted file]
tools/perf/util/include/asm/hweight.h [new file with mode: 0644]
tools/perf/util/include/dwarf-regs.h [new file with mode: 0644]
tools/perf/util/include/linux/bitmap.h
tools/perf/util/include/linux/bitops.h
tools/perf/util/include/linux/compiler.h
tools/perf/util/include/linux/kernel.h
tools/perf/util/map.c
tools/perf/util/map.h
tools/perf/util/newt.c [new file with mode: 0644]
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/parse-options.c
tools/perf/util/parse-options.h
tools/perf/util/probe-event.c
tools/perf/util/probe-event.h
tools/perf/util/probe-finder.c
tools/perf/util/probe-finder.h
tools/perf/util/pstack.c [new file with mode: 0644]
tools/perf/util/pstack.h [new file with mode: 0644]
tools/perf/util/scripting-engines/trace-event-perl.c
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/session.c
tools/perf/util/session.h
tools/perf/util/sort.c
tools/perf/util/sort.h
tools/perf/util/string.c
tools/perf/util/string.h [deleted file]
tools/perf/util/symbol.c
tools/perf/util/symbol.h
tools/perf/util/thread.c
tools/perf/util/thread.h
tools/perf/util/trace-event-info.c
tools/perf/util/trace-event-parse.c
tools/perf/util/trace-event-read.c
tools/perf/util/trace-event.h
tools/perf/util/util.c
tools/perf/util/util.h
virt/kvm/iommu.c

index bf1627b..aba7d98 100644 (file)
@@ -43,7 +43,7 @@ Date:         September 2008
 Contact:       Badari Pulavarty <pbadari@us.ibm.com>
 Description:
                The file /sys/devices/system/memory/memoryX/state
-               is read-write.  When read, it's contents show the
+               is read-write.  When read, its contents show the
                online/offline state of the memory section.  When written,
                root can toggle the the online/offline state of a removable
                memory section (see removable file description above)
index 52618ab..2e435ad 100644 (file)
@@ -742,7 +742,7 @@ failure can be determined by:
 
                           Closing
 
-This document, and the API itself, would not be in it's current
+This document, and the API itself, would not be in its current
 form without the feedback and suggestions from numerous individuals.
 We would like to specifically mention, in no particular order, the
 following people:
index ff3e5be..8c5411c 100644 (file)
@@ -81,16 +81,14 @@ void (*port_disable) (struct ata_port *);
        </programlisting>
 
        <para>
-       Called from ata_bus_probe() and ata_bus_reset() error paths,
-       as well as when unregistering from the SCSI module (rmmod, hot
-       unplug).
+       Called from ata_bus_probe() error path, as well as when
+       unregistering from the SCSI module (rmmod, hot unplug).
        This function should do whatever needs to be done to take the
        port out of use.  In most cases, ata_port_disable() can be used
        as this hook.
        </para>
        <para>
        Called from ata_bus_probe() on a failed probe.
-       Called from ata_bus_reset() on a failed bus reset.
        Called from ata_scsi_release().
        </para>
 
@@ -227,6 +225,18 @@ u8   (*sff_check_altstatus)(struct ata_port *ap);
 
        </sect2>
 
+       <sect2><title>Write specific ATA shadow register</title>
+       <programlisting>
+void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
+       </programlisting>
+
+       <para>
+       Write the device control ATA shadow register to the hardware.
+       Most drivers don't need to define this.
+       </para>
+
+       </sect2>
+
        <sect2><title>Select ATA device on bus</title>
        <programlisting>
 void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
@@ -477,7 +487,7 @@ void (*host_stop) (struct ata_host_set *host_set);
        allocates space for a legacy IDE PRD table and returns.
        </para>
        <para>
-       ->port_stop() is called after ->host_stop().  It's sole function
+       ->port_stop() is called after ->host_stop().  Its sole function
        is to release DMA/memory resources, now that they are no longer
        actively being used.  Many drivers also free driver-private
        data from port at this time.
index c725cb8..5d4d40f 100644 (file)
@@ -17,6 +17,7 @@
 <!ENTITY VIDIOC-DBG-G-REGISTER "<link linkend='vidioc-dbg-g-register'><constant>VIDIOC_DBG_G_REGISTER</constant></link>">
 <!ENTITY VIDIOC-DBG-S-REGISTER "<link linkend='vidioc-dbg-g-register'><constant>VIDIOC_DBG_S_REGISTER</constant></link>">
 <!ENTITY VIDIOC-DQBUF "<link linkend='vidioc-qbuf'><constant>VIDIOC_DQBUF</constant></link>">
+<!ENTITY VIDIOC-DQEVENT "<link linkend='vidioc-dqevent'><constant>VIDIOC_DQEVENT</constant></link>">
 <!ENTITY VIDIOC-ENCODER-CMD "<link linkend='vidioc-encoder-cmd'><constant>VIDIOC_ENCODER_CMD</constant></link>">
 <!ENTITY VIDIOC-ENUMAUDIO "<link linkend='vidioc-enumaudio'><constant>VIDIOC_ENUMAUDIO</constant></link>">
 <!ENTITY VIDIOC-ENUMAUDOUT "<link linkend='vidioc-enumaudioout'><constant>VIDIOC_ENUMAUDOUT</constant></link>">
@@ -60,6 +61,7 @@
 <!ENTITY VIDIOC-REQBUFS "<link linkend='vidioc-reqbufs'><constant>VIDIOC_REQBUFS</constant></link>">
 <!ENTITY VIDIOC-STREAMOFF "<link linkend='vidioc-streamon'><constant>VIDIOC_STREAMOFF</constant></link>">
 <!ENTITY VIDIOC-STREAMON "<link linkend='vidioc-streamon'><constant>VIDIOC_STREAMON</constant></link>">
+<!ENTITY VIDIOC-SUBSCRIBE-EVENT "<link linkend='vidioc-subscribe-event'><constant>VIDIOC_SUBSCRIBE_EVENT</constant></link>">
 <!ENTITY VIDIOC-S-AUDIO "<link linkend='vidioc-g-audio'><constant>VIDIOC_S_AUDIO</constant></link>">
 <!ENTITY VIDIOC-S-AUDOUT "<link linkend='vidioc-g-audioout'><constant>VIDIOC_S_AUDOUT</constant></link>">
 <!ENTITY VIDIOC-S-CROP "<link linkend='vidioc-g-crop'><constant>VIDIOC_S_CROP</constant></link>">
@@ -83,6 +85,7 @@
 <!ENTITY VIDIOC-TRY-ENCODER-CMD "<link linkend='vidioc-encoder-cmd'><constant>VIDIOC_TRY_ENCODER_CMD</constant></link>">
 <!ENTITY VIDIOC-TRY-EXT-CTRLS "<link linkend='vidioc-g-ext-ctrls'><constant>VIDIOC_TRY_EXT_CTRLS</constant></link>">
 <!ENTITY VIDIOC-TRY-FMT "<link linkend='vidioc-g-fmt'><constant>VIDIOC_TRY_FMT</constant></link>">
+<!ENTITY VIDIOC-UNSUBSCRIBE-EVENT "<link linkend='vidioc-subscribe-event'><constant>VIDIOC_UNSUBSCRIBE_EVENT</constant></link>">
 
 <!-- Types -->
 <!ENTITY v4l2-std-id "<link linkend='v4l2-std-id'>v4l2_std_id</link>">
 <!ENTITY v4l2-enc-idx "struct&nbsp;<link linkend='v4l2-enc-idx'>v4l2_enc_idx</link>">
 <!ENTITY v4l2-enc-idx-entry "struct&nbsp;<link linkend='v4l2-enc-idx-entry'>v4l2_enc_idx_entry</link>">
 <!ENTITY v4l2-encoder-cmd "struct&nbsp;<link linkend='v4l2-encoder-cmd'>v4l2_encoder_cmd</link>">
+<!ENTITY v4l2-event "struct&nbsp;<link linkend='v4l2-event'>v4l2_event</link>">
+<!ENTITY v4l2-event-subscription "struct&nbsp;<link linkend='v4l2-event-subscription'>v4l2_event_subscription</link>">
+<!ENTITY v4l2-event-vsync "struct&nbsp;<link linkend='v4l2-event-vsync'>v4l2_event_vsync</link>">
 <!ENTITY v4l2-ext-control "struct&nbsp;<link linkend='v4l2-ext-control'>v4l2_ext_control</link>">
 <!ENTITY v4l2-ext-controls "struct&nbsp;<link linkend='v4l2-ext-controls'>v4l2_ext_controls</link>">
 <!ENTITY v4l2-fmtdesc "struct&nbsp;<link linkend='v4l2-fmtdesc'>v4l2_fmtdesc</link>">
 <!ENTITY sub-controls SYSTEM "v4l/controls.xml">
 <!ENTITY sub-dev-capture SYSTEM "v4l/dev-capture.xml">
 <!ENTITY sub-dev-codec SYSTEM "v4l/dev-codec.xml">
+<!ENTITY sub-dev-event SYSTEM "v4l/dev-event.xml">
 <!ENTITY sub-dev-effect SYSTEM "v4l/dev-effect.xml">
 <!ENTITY sub-dev-osd SYSTEM "v4l/dev-osd.xml">
 <!ENTITY sub-dev-output SYSTEM "v4l/dev-output.xml">
 <!ENTITY sub-v4l2grab-c SYSTEM "v4l/v4l2grab.c.xml">
 <!ENTITY sub-videodev2-h SYSTEM "v4l/videodev2.h.xml">
 <!ENTITY sub-v4l2 SYSTEM "v4l/v4l2.xml">
+<!ENTITY sub-dqevent SYSTEM "v4l/vidioc-dqevent.xml">
+<!ENTITY sub-subscribe-event SYSTEM "v4l/vidioc-subscribe-event.xml">
 <!ENTITY sub-intro SYSTEM "dvb/intro.xml">
 <!ENTITY sub-frontend SYSTEM "dvb/frontend.xml">
 <!ENTITY sub-dvbproperty SYSTEM "dvb/dvbproperty.xml">
 <!ENTITY reqbufs SYSTEM "v4l/vidioc-reqbufs.xml">
 <!ENTITY s-hw-freq-seek SYSTEM "v4l/vidioc-s-hw-freq-seek.xml">
 <!ENTITY streamon SYSTEM "v4l/vidioc-streamon.xml">
+<!ENTITY dqevent SYSTEM "v4l/vidioc-dqevent.xml">
+<!ENTITY subscribe_event SYSTEM "v4l/vidioc-subscribe-event.xml">
index 0c3dc4c..d858d92 100644 (file)
   </authorgroup>
 
   <copyright>
-   <year>2008</year>
+   <year>2008-2010</year>
    <holder>Paul Mundt</holder>
   </copyright>
   <copyright>
-   <year>2008</year>
+   <year>2008-2010</year>
    <holder>Renesas Technology Corp.</holder>
   </copyright>
+  <copyright>
+   <year>2010</year>
+   <holder>Renesas Electronics Corp.</holder>
+  </copyright>
 
   <legalnotice>
    <para>
@@ -77,7 +81,7 @@
   </chapter>
   <chapter id="clk">
     <title>Clock Framework Extensions</title>
-!Iarch/sh/include/asm/clock.h
+!Iinclude/linux/sh_clk.h
   </chapter>
   <chapter id="mach">
     <title>Machine Specific Interfaces</title>
index b9dbdf9..b42b935 100644 (file)
@@ -2332,15 +2332,26 @@ more information.</para>
        </listitem>
       </orderedlist>
     </section>
-   </section>
+    <section>
+      <title>V4L2 in Linux 2.6.34</title>
+      <orderedlist>
+       <listitem>
+         <para>Added
+<constant>V4L2_CID_IRIS_ABSOLUTE</constant> and
+<constant>V4L2_CID_IRIS_RELATIVE</constant> controls to the
+           <link linkend="camera-controls">Camera controls class</link>.
+         </para>
+       </listitem>
+      </orderedlist>
+    </section>
 
-   <section id="other">
-     <title>Relation of V4L2 to other Linux multimedia APIs</title>
+    <section id="other">
+      <title>Relation of V4L2 to other Linux multimedia APIs</title>
 
-    <section id="xvideo">
-      <title>X Video Extension</title>
+      <section id="xvideo">
+        <title>X Video Extension</title>
 
-      <para>The X Video Extension (abbreviated XVideo or just Xv) is
+        <para>The X Video Extension (abbreviated XVideo or just Xv) is
 an extension of the X Window system, implemented for example by the
 XFree86 project. Its scope is similar to V4L2, an API to video capture
 and output devices for X clients. Xv allows applications to display
@@ -2351,7 +2362,7 @@ capture or output still images in XPixmaps<footnote>
 extension available across many operating systems and
 architectures.</para>
 
-      <para>Because the driver is embedded into the X server Xv has a
+        <para>Because the driver is embedded into the X server Xv has a
 number of advantages over the V4L2 <link linkend="overlay">video
 overlay interface</link>. The driver can easily determine the overlay
 target, &ie; visible graphics memory or off-screen buffers for a
@@ -2360,16 +2371,16 @@ overlay, scaling or color-keying, or the clipping functions of the
 video capture hardware, always in sync with drawing operations or
 windows moving or changing their stacking order.</para>
 
-      <para>To combine the advantages of Xv and V4L a special Xv
+        <para>To combine the advantages of Xv and V4L a special Xv
 driver exists in XFree86 and XOrg, just programming any overlay capable
 Video4Linux device it finds. To enable it
 <filename>/etc/X11/XF86Config</filename> must contain these lines:</para>
-      <para><screen>
+        <para><screen>
 Section "Module"
     Load "v4l"
 EndSection</screen></para>
 
-      <para>As of XFree86 4.2 this driver still supports only V4L
+        <para>As of XFree86 4.2 this driver still supports only V4L
 ioctls, however it should work just fine with all V4L2 devices through
 the V4L2 backward-compatibility layer. Since V4L2 permits multiple
 opens it is possible (if supported by the V4L2 driver) to capture
@@ -2377,83 +2388,84 @@ video while an X client requested video overlay. Restrictions of
 simultaneous capturing and overlay are discussed in <xref
          linkend="overlay" /> apply.</para>
 
-      <para>Only marginally related to V4L2, XFree86 extended Xv to
+        <para>Only marginally related to V4L2, XFree86 extended Xv to
 support hardware YUV to RGB conversion and scaling for faster video
 playback, and added an interface to MPEG-2 decoding hardware. This API
 is useful to display images captured with V4L2 devices.</para>
-    </section>
+      </section>
 
-    <section>
-      <title>Digital Video</title>
+      <section>
+        <title>Digital Video</title>
 
-      <para>V4L2 does not support digital terrestrial, cable or
+        <para>V4L2 does not support digital terrestrial, cable or
 satellite broadcast. A separate project aiming at digital receivers
 exists. You can find its homepage at <ulink
 url="http://linuxtv.org">http://linuxtv.org</ulink>. The Linux DVB API
 has no connection to the V4L2 API except that drivers for hybrid
 hardware may support both.</para>
-    </section>
+      </section>
 
-    <section>
-      <title>Audio Interfaces</title>
+      <section>
+        <title>Audio Interfaces</title>
 
-      <para>[to do - OSS/ALSA]</para>
+        <para>[to do - OSS/ALSA]</para>
+      </section>
     </section>
-  </section>
 
-  <section id="experimental">
-    <title>Experimental API Elements</title>
+    <section id="experimental">
+      <title>Experimental API Elements</title>
 
-    <para>The following V4L2 API elements are currently experimental
+      <para>The following V4L2 API elements are currently experimental
 and may change in the future.</para>
 
-    <itemizedlist>
-      <listitem>
-       <para>Video Output Overlay (OSD) Interface, <xref
+      <itemizedlist>
+        <listitem>
+         <para>Video Output Overlay (OSD) Interface, <xref
            linkend="osd" />.</para>
-      </listitem>
+        </listitem>
        <listitem>
-       <para><constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY</constant>,
+         <para><constant>V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY</constant>,
        &v4l2-buf-type;, <xref linkend="v4l2-buf-type" />.</para>
-      </listitem>
-      <listitem>
-       <para><constant>V4L2_CAP_VIDEO_OUTPUT_OVERLAY</constant>,
+        </listitem>
+        <listitem>
+         <para><constant>V4L2_CAP_VIDEO_OUTPUT_OVERLAY</constant>,
 &VIDIOC-QUERYCAP; ioctl, <xref linkend="device-capabilities" />.</para>
-      </listitem>
-      <listitem>
-       <para>&VIDIOC-ENUM-FRAMESIZES; and
+        </listitem>
+        <listitem>
+         <para>&VIDIOC-ENUM-FRAMESIZES; and
 &VIDIOC-ENUM-FRAMEINTERVALS; ioctls.</para>
-      </listitem>
-      <listitem>
-       <para>&VIDIOC-G-ENC-INDEX; ioctl.</para>
-      </listitem>
-      <listitem>
-       <para>&VIDIOC-ENCODER-CMD; and &VIDIOC-TRY-ENCODER-CMD;
+        </listitem>
+        <listitem>
+         <para>&VIDIOC-G-ENC-INDEX; ioctl.</para>
+        </listitem>
+        <listitem>
+         <para>&VIDIOC-ENCODER-CMD; and &VIDIOC-TRY-ENCODER-CMD;
 ioctls.</para>
-      </listitem>
-      <listitem>
-       <para>&VIDIOC-DBG-G-REGISTER; and &VIDIOC-DBG-S-REGISTER;
+        </listitem>
+        <listitem>
+         <para>&VIDIOC-DBG-G-REGISTER; and &VIDIOC-DBG-S-REGISTER;
 ioctls.</para>
-      </listitem>
-      <listitem>
-       <para>&VIDIOC-DBG-G-CHIP-IDENT; ioctl.</para>
-      </listitem>
-    </itemizedlist>
-  </section>
+        </listitem>
+        <listitem>
+         <para>&VIDIOC-DBG-G-CHIP-IDENT; ioctl.</para>
+        </listitem>
+      </itemizedlist>
+    </section>
 
-  <section id="obsolete">
-    <title>Obsolete API Elements</title>
+    <section id="obsolete">
+      <title>Obsolete API Elements</title>
 
-    <para>The following V4L2 API elements were superseded by new
+      <para>The following V4L2 API elements were superseded by new
 interfaces and should not be implemented in new drivers.</para>
 
-    <itemizedlist>
-      <listitem>
-       <para><constant>VIDIOC_G_MPEGCOMP</constant> and
+      <itemizedlist>
+        <listitem>
+         <para><constant>VIDIOC_G_MPEGCOMP</constant> and
 <constant>VIDIOC_S_MPEGCOMP</constant> ioctls. Use Extended Controls,
 <xref linkend="extended-controls" />.</para>
-      </listitem>
-    </itemizedlist>
+        </listitem>
+      </itemizedlist>
+    </section>
   </section>
 
   <!--
index f464506..8408caa 100644 (file)
@@ -266,6 +266,12 @@ minimum value disables backlight compensation.</entry>
            <entry>boolean</entry>
            <entry>Chroma automatic gain control.</entry>
          </row>
+         <row>
+           <entry><constant>V4L2_CID_CHROMA_GAIN</constant></entry>
+           <entry>integer</entry>
+           <entry>Adjusts the Chroma gain control (for use when chroma AGC
+           is disabled).</entry>
+         </row>
          <row>
            <entry><constant>V4L2_CID_COLOR_KILLER</constant></entry>
            <entry>boolean</entry>
@@ -277,8 +283,15 @@ minimum value disables backlight compensation.</entry>
            <entry>Selects a color effect. Possible values for
 <constant>enum v4l2_colorfx</constant> are:
 <constant>V4L2_COLORFX_NONE</constant> (0),
-<constant>V4L2_COLORFX_BW</constant> (1) and
-<constant>V4L2_COLORFX_SEPIA</constant> (2).</entry>
+<constant>V4L2_COLORFX_BW</constant> (1),
+<constant>V4L2_COLORFX_SEPIA</constant> (2),
+<constant>V4L2_COLORFX_NEGATIVE</constant> (3),
+<constant>V4L2_COLORFX_EMBOSS</constant> (4),
+<constant>V4L2_COLORFX_SKETCH</constant> (5),
+<constant>V4L2_COLORFX_SKY_BLUE</constant> (6),
+<constant>V4L2_COLORFX_GRASS_GREEN</constant> (7),
+<constant>V4L2_COLORFX_SKIN_WHITEN</constant> (8) and
+<constant>V4L2_COLORFX_VIVID</constant> (9).</entry>
          </row>
          <row>
            <entry><constant>V4L2_CID_ROTATE</constant></entry>
@@ -1824,6 +1837,25 @@ wide-angle direction. The zoom speed unit is driver-specific.</entry>
          </row>
          <row><entry></entry></row>
 
+         <row>
+           <entry spanname="id"><constant>V4L2_CID_IRIS_ABSOLUTE</constant>&nbsp;</entry>
+           <entry>integer</entry>
+         </row><row><entry spanname="descr">This control sets the
+camera's aperture to the specified value. The unit is undefined.
+Larger values open the iris wider, smaller values close it.</entry>
+         </row>
+         <row><entry></entry></row>
+
+         <row>
+           <entry spanname="id"><constant>V4L2_CID_IRIS_RELATIVE</constant>&nbsp;</entry>
+           <entry>integer</entry>
+         </row><row><entry spanname="descr">This control modifies the
+camera's aperture by the specified amount. The unit is undefined.
+Positive values open the iris one step further, negative values close
+it one step further. This is a write-only control.</entry>
+         </row>
+         <row><entry></entry></row>
+
          <row>
            <entry spanname="id"><constant>V4L2_CID_PRIVACY</constant>&nbsp;</entry>
            <entry>boolean</entry>
diff --git a/Documentation/DocBook/v4l/dev-event.xml b/Documentation/DocBook/v4l/dev-event.xml
new file mode 100644 (file)
index 0000000..be5a98f
--- /dev/null
@@ -0,0 +1,31 @@
+  <title>Event Interface</title>
+
+  <para>The V4L2 event interface provides means for user to get
+  immediately notified on certain conditions taking place on a device.
+  This might include start of frame or loss of signal events, for
+  example.
+  </para>
+
+  <para>To receive events, the events the user is interested in first must
+  be subscribed using the &VIDIOC-SUBSCRIBE-EVENT; ioctl. Once an event is
+  subscribed, the events of subscribed types are dequeueable using the
+  &VIDIOC-DQEVENT; ioctl. Events may be unsubscribed using
+  VIDIOC_UNSUBSCRIBE_EVENT ioctl. The special event type V4L2_EVENT_ALL may
+  be used to unsubscribe all the events the driver supports.</para>
+
+  <para>The event subscriptions and event queues are specific to file
+  handles. Subscribing an event on one file handle does not affect
+  other file handles.
+  </para>
+
+  <para>The information on dequeueable events is obtained by using select or
+  poll system calls on video devices. The V4L2 events use POLLPRI events on
+  poll system call and exceptions on select system call.  </para>
+
+  <!--
+Local Variables:
+mode: sgml
+sgml-parent-document: "v4l2.sgml"
+indent-tabs-mode: nil
+End:
+  -->
index e870330..d424886 100644 (file)
@@ -701,6 +701,16 @@ buffer cannot be on both queues at the same time, the
 They can be both cleared however, then the buffer is in "dequeued"
 state, in the application domain to say so.</entry>
          </row>
+         <row>
+           <entry><constant>V4L2_BUF_FLAG_ERROR</constant></entry>
+           <entry>0x0040</entry>
+           <entry>When this flag is set, the buffer has been dequeued
+           successfully, although the data might have been corrupted.
+           This is recoverable, streaming may continue as normal and
+           the buffer may be reused normally.
+           Drivers set this flag when the <constant>VIDIOC_DQBUF</constant>
+           ioctl is called.</entry>
+         </row>
          <row>
            <entry><constant>V4L2_BUF_FLAG_KEYFRAME</constant></entry>
            <entry>0x0008</entry>
@@ -918,8 +928,8 @@ order</emphasis>.</para>
 
     <para>When the driver provides or accepts images field by field
 rather than interleaved, it is also important applications understand
-how the fields combine to frames. We distinguish between top and
-bottom fields, the <emphasis>spatial order</emphasis>: The first line
+how the fields combine to frames. We distinguish between top (aka odd) and
+bottom (aka even) fields, the <emphasis>spatial order</emphasis>: The first line
 of the top field is the first line of an interlaced frame, the first
 line of the bottom field is the second line of that frame.</para>
 
@@ -972,12 +982,12 @@ between <constant>V4L2_FIELD_TOP</constant> and
          <row>
            <entry><constant>V4L2_FIELD_TOP</constant></entry>
            <entry>2</entry>
-           <entry>Images consist of the top field only.</entry>
+           <entry>Images consist of the top (aka odd) field only.</entry>
          </row>
          <row>
            <entry><constant>V4L2_FIELD_BOTTOM</constant></entry>
            <entry>3</entry>
-           <entry>Images consist of the bottom field only.
+           <entry>Images consist of the bottom (aka even) field only.
 Applications may wish to prevent a device from capturing interlaced
 images because they will have "comb" or "feathering" artefacts around
 moving objects.</entry>
index 885968d..c4ad0a8 100644 (file)
@@ -792,6 +792,18 @@ http://www.thedirks.org/winnov/</ulink></para></entry>
            <entry>'YYUV'</entry>
            <entry>unknown</entry>
          </row>
+         <row id="V4L2-PIX-FMT-Y4">
+           <entry><constant>V4L2_PIX_FMT_Y4</constant></entry>
+           <entry>'Y04 '</entry>
+           <entry>Old 4-bit greyscale format. Only the least significant 4 bits of each byte are used,
+the other bits are set to 0.</entry>
+         </row>
+         <row id="V4L2-PIX-FMT-Y6">
+           <entry><constant>V4L2_PIX_FMT_Y6</constant></entry>
+           <entry>'Y06 '</entry>
+           <entry>Old 6-bit greyscale format. Only the least significant 6 bits of each byte are used,
+the other bits are set to 0.</entry>
+         </row>
        </tbody>
       </tgroup>
     </table>
index 060105a..9737243 100644 (file)
@@ -401,6 +401,7 @@ and discussions on the V4L mailing list.</revremark>
     <section id="ttx"> &sub-dev-teletext; </section>
     <section id="radio"> &sub-dev-radio; </section>
     <section id="rds"> &sub-dev-rds; </section>
+    <section id="event"> &sub-dev-event; </section>
   </chapter>
 
   <chapter id="driver">
@@ -426,6 +427,7 @@ and discussions on the V4L mailing list.</revremark>
     &sub-cropcap;
     &sub-dbg-g-chip-ident;
     &sub-dbg-g-register;
+    &sub-dqevent;
     &sub-encoder-cmd;
     &sub-enumaudio;
     &sub-enumaudioout;
@@ -467,6 +469,7 @@ and discussions on the V4L mailing list.</revremark>
     &sub-reqbufs;
     &sub-s-hw-freq-seek;
     &sub-streamon;
+    &sub-subscribe-event;
     <!-- End of ioctls. -->
     &sub-mmap;
     &sub-munmap;
index 0683259..865b06d 100644 (file)
@@ -1018,6 +1018,13 @@ enum <link linkend="v4l2-colorfx">v4l2_colorfx</link> {
         V4L2_COLORFX_NONE       = 0,
         V4L2_COLORFX_BW         = 1,
         V4L2_COLORFX_SEPIA      = 2,
+        V4L2_COLORFX_NEGATIVE   = 3,
+        V4L2_COLORFX_EMBOSS     = 4,
+        V4L2_COLORFX_SKETCH     = 5,
+        V4L2_COLORFX_SKY_BLUE   = 6,
+        V4L2_COLORFX_GRASS_GREEN = 7,
+        V4L2_COLORFX_SKIN_WHITEN = 8,
+        V4L2_COLORFX_VIVID      = 9.
 };
 #define V4L2_CID_AUTOBRIGHTNESS                 (V4L2_CID_BASE+32)
 #define V4L2_CID_BAND_STOP_FILTER               (V4L2_CID_BASE+33)
@@ -1271,6 +1278,9 @@ enum  <link linkend="v4l2-exposure-auto-type">v4l2_exposure_auto_type</link> {
 
 #define V4L2_CID_PRIVACY                        (V4L2_CID_CAMERA_CLASS_BASE+16)
 
+#define V4L2_CID_IRIS_ABSOLUTE                  (V4L2_CID_CAMERA_CLASS_BASE+17)
+#define V4L2_CID_IRIS_RELATIVE                  (V4L2_CID_CAMERA_CLASS_BASE+18)
+
 /* FM Modulator class control IDs */
 #define V4L2_CID_FM_TX_CLASS_BASE               (V4L2_CTRL_CLASS_FM_TX | 0x900)
 #define V4L2_CID_FM_TX_CLASS                    (V4L2_CTRL_CLASS_FM_TX | 1)
diff --git a/Documentation/DocBook/v4l/vidioc-dqevent.xml b/Documentation/DocBook/v4l/vidioc-dqevent.xml
new file mode 100644 (file)
index 0000000..4e0a7cc
--- /dev/null
@@ -0,0 +1,131 @@
+<refentry id="vidioc-dqevent">
+  <refmeta>
+    <refentrytitle>ioctl VIDIOC_DQEVENT</refentrytitle>
+    &manvol;
+  </refmeta>
+
+  <refnamediv>
+    <refname>VIDIOC_DQEVENT</refname>
+    <refpurpose>Dequeue event</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcprototype>
+       <funcdef>int <function>ioctl</function></funcdef>
+       <paramdef>int <parameter>fd</parameter></paramdef>
+       <paramdef>int <parameter>request</parameter></paramdef>
+       <paramdef>struct v4l2_event
+*<parameter>argp</parameter></paramdef>
+      </funcprototype>
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+       <term><parameter>fd</parameter></term>
+       <listitem>
+         <para>&fd;</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><parameter>request</parameter></term>
+       <listitem>
+         <para>VIDIOC_DQEVENT</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><parameter>argp</parameter></term>
+       <listitem>
+         <para></para>
+       </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>Description</title>
+
+    <para>Dequeue an event from a video device. No input is required
+    for this ioctl. All the fields of the &v4l2-event; structure are
+    filled by the driver. The file handle will also receive exceptions
+    which the application may get by e.g. using the select system
+    call.</para>
+
+    <table frame="none" pgwide="1" id="v4l2-event">
+      <title>struct <structname>v4l2_event</structname></title>
+      <tgroup cols="4">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>type</structfield></entry>
+            <entry></entry>
+           <entry>Type of the event.</entry>
+         </row>
+         <row>
+           <entry>union</entry>
+           <entry><structfield>u</structfield></entry>
+            <entry></entry>
+           <entry></entry>
+         </row>
+         <row>
+           <entry></entry>
+           <entry>&v4l2-event-vsync;</entry>
+            <entry><structfield>vsync</structfield></entry>
+           <entry>Event data for event V4L2_EVENT_VSYNC.
+            </entry>
+         </row>
+         <row>
+           <entry></entry>
+           <entry>__u8</entry>
+            <entry><structfield>data</structfield>[64]</entry>
+           <entry>Event data. Defined by the event type. The union
+            should be used to define easily accessible type for
+            events.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>pending</structfield></entry>
+            <entry></entry>
+           <entry>Number of pending events excluding this one.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>sequence</structfield></entry>
+            <entry></entry>
+           <entry>Event sequence number. The sequence number is
+           incremented for every subscribed event that takes place.
+           If sequence numbers are not contiguous it means that
+           events have been lost.
+           </entry>
+         </row>
+         <row>
+           <entry>struct timespec</entry>
+           <entry><structfield>timestamp</structfield></entry>
+            <entry></entry>
+           <entry>Event timestamp.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>reserved</structfield>[9]</entry>
+            <entry></entry>
+           <entry>Reserved for future extensions. Drivers must set
+           the array to zero.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+  </refsect1>
+</refentry>
+<!--
+Local Variables:
+mode: sgml
+sgml-parent-document: "v4l2.sgml"
+indent-tabs-mode: nil
+End:
+-->
index 71b868e..476fe1d 100644 (file)
@@ -283,7 +283,7 @@ input/output interface to linux-media@vger.kernel.org on 19 Oct 2009.
            <entry>This input supports setting DV presets by using VIDIOC_S_DV_PRESET.</entry>
          </row>
          <row>
-           <entry><constant>V4L2_OUT_CAP_CUSTOM_TIMINGS</constant></entry>
+           <entry><constant>V4L2_IN_CAP_CUSTOM_TIMINGS</constant></entry>
            <entry>0x00000002</entry>
            <entry>This input supports setting custom video timings by using VIDIOC_S_DV_TIMINGS.</entry>
          </row>
index b843bd7..ab691eb 100644 (file)
@@ -111,7 +111,11 @@ from the driver's outgoing queue. They just set the
 and <structfield>reserved</structfield>
 fields of a &v4l2-buffer; as above, when <constant>VIDIOC_DQBUF</constant>
 is called with a pointer to this structure the driver fills the
-remaining fields or returns an error code.</para>
+remaining fields or returns an error code. The driver may also set
+<constant>V4L2_BUF_FLAG_ERROR</constant> in the <structfield>flags</structfield>
+field. It indicates a non-critical (recoverable) streaming error. In such case
+the application may continue as normal, but should be aware that data in the
+dequeued buffer might be corrupted.</para>
 
     <para>By default <constant>VIDIOC_DQBUF</constant> blocks when no
 buffer is in the outgoing queue. When the
@@ -158,7 +162,13 @@ enqueue a user pointer buffer.</para>
          <para><constant>VIDIOC_DQBUF</constant> failed due to an
 internal error. Can also indicate temporary problems like signal
 loss. Note the driver might dequeue an (empty) buffer despite
-returning an error, or even stop capturing.</para>
+returning an error, or even stop capturing. Reusing such buffer may be unsafe
+though and its details (e.g. <structfield>index</structfield>) may not be
+returned either. It is recommended that drivers indicate recoverable errors
+by setting the <constant>V4L2_BUF_FLAG_ERROR</constant> and returning 0 instead.
+In that case the application should be able to safely reuse the buffer and
+continue streaming.
+       </para>
        </listitem>
       </varlistentry>
     </variablelist>
index 4876ff1..8e0e055 100644 (file)
@@ -325,7 +325,7 @@ should be part of the control documentation.</entry>
            <entry>n/a</entry>
            <entry>This is not a control. When
 <constant>VIDIOC_QUERYCTRL</constant> is called with a control ID
-equal to a control class code (see <xref linkend="ctrl-class" />), the
+equal to a control class code (see <xref linkend="ctrl-class" />) + 1, the
 ioctl returns the name of the control class and this control type.
 Older drivers which do not support this feature return an
 &EINVAL;.</entry>
index 1c08163..69800ae 100644 (file)
@@ -61,7 +61,7 @@ fields of the <structname>v4l2_requestbuffers</structname> structure.
 They set the <structfield>type</structfield> field to the respective
 stream or buffer type, the <structfield>count</structfield> field to
 the desired number of buffers, <structfield>memory</structfield>
-must be set to the requested I/O method and the reserved array
+must be set to the requested I/O method and the <structfield>reserved</structfield> array
 must be zeroed. When the ioctl
 is called with a pointer to this structure the driver will attempt to allocate
 the requested number of buffers and it stores the actual number
diff --git a/Documentation/DocBook/v4l/vidioc-subscribe-event.xml b/Documentation/DocBook/v4l/vidioc-subscribe-event.xml
new file mode 100644 (file)
index 0000000..8b50179
--- /dev/null
@@ -0,0 +1,133 @@
+<refentry id="vidioc-subscribe-event">
+  <refmeta>
+    <refentrytitle>ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT</refentrytitle>
+    &manvol;
+  </refmeta>
+
+  <refnamediv>
+    <refname>VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT</refname>
+    <refpurpose>Subscribe or unsubscribe event</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <funcsynopsis>
+      <funcprototype>
+       <funcdef>int <function>ioctl</function></funcdef>
+       <paramdef>int <parameter>fd</parameter></paramdef>
+       <paramdef>int <parameter>request</parameter></paramdef>
+       <paramdef>struct v4l2_event_subscription
+*<parameter>argp</parameter></paramdef>
+      </funcprototype>
+    </funcsynopsis>
+  </refsynopsisdiv>
+
+  <refsect1>
+    <title>Arguments</title>
+
+    <variablelist>
+      <varlistentry>
+       <term><parameter>fd</parameter></term>
+       <listitem>
+         <para>&fd;</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><parameter>request</parameter></term>
+       <listitem>
+         <para>VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT</para>
+       </listitem>
+      </varlistentry>
+      <varlistentry>
+       <term><parameter>argp</parameter></term>
+       <listitem>
+         <para></para>
+       </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
+  <refsect1>
+    <title>Description</title>
+
+    <para>Subscribe or unsubscribe V4L2 event. Subscribed events are
+    dequeued by using the &VIDIOC-DQEVENT; ioctl.</para>
+
+    <table frame="none" pgwide="1" id="v4l2-event-subscription">
+      <title>struct <structname>v4l2_event_subscription</structname></title>
+      <tgroup cols="3">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>type</structfield></entry>
+           <entry>Type of the event.</entry>
+         </row>
+         <row>
+           <entry>__u32</entry>
+           <entry><structfield>reserved</structfield>[7]</entry>
+           <entry>Reserved for future extensions. Drivers and applications
+           must set the array to zero.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+    <table frame="none" pgwide="1" id="event-type">
+      <title>Event Types</title>
+      <tgroup cols="3">
+       &cs-def;
+       <tbody valign="top">
+         <row>
+           <entry><constant>V4L2_EVENT_ALL</constant></entry>
+           <entry>0</entry>
+           <entry>All events. V4L2_EVENT_ALL is valid only for
+           VIDIOC_UNSUBSCRIBE_EVENT for unsubscribing all events at once.
+           </entry>
+         </row>
+         <row>
+           <entry><constant>V4L2_EVENT_VSYNC</constant></entry>
+           <entry>1</entry>
+           <entry>This event is triggered on the vertical sync.
+           This event has &v4l2-event-vsync; associated with it.
+           </entry>
+         </row>
+         <row>
+           <entry><constant>V4L2_EVENT_EOS</constant></entry>
+           <entry>2</entry>
+           <entry>This event is triggered when the end of a stream is reached.
+           This is typically used with MPEG decoders to report to the application
+           when the last of the MPEG stream has been decoded.
+           </entry>
+         </row>
+         <row>
+           <entry><constant>V4L2_EVENT_PRIVATE_START</constant></entry>
+           <entry>0x08000000</entry>
+           <entry>Base event number for driver-private events.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+    <table frame="none" pgwide="1" id="v4l2-event-vsync">
+      <title>struct <structname>v4l2_event_vsync</structname></title>
+      <tgroup cols="3">
+       &cs-str;
+       <tbody valign="top">
+         <row>
+           <entry>__u8</entry>
+           <entry><structfield>field</structfield></entry>
+           <entry>The upcoming field. See &v4l2-field;.</entry>
+         </row>
+       </tbody>
+      </tgroup>
+    </table>
+
+  </refsect1>
+</refentry>
+<!--
+Local Variables:
+mode: sgml
+sgml-parent-document: "v4l2.sgml"
+indent-tabs-mode: nil
+End:
+-->
index 0d0f7b4..0ba149d 100644 (file)
@@ -5518,34 +5518,41 @@ struct _snd_pcm_runtime {
 ]]>
         </programlisting>
       </informalexample>
+
+      For the raw data, <structfield>size</structfield> field must be
+      set properly.  This specifies the maximum size of the proc file access.
     </para>
 
     <para>
-      The callback is much more complicated than the text-file
-      version. You need to use a low-level I/O functions such as
+      The read/write callbacks of raw mode are more direct than the text mode.
+      You need to use a low-level I/O functions such as
       <function>copy_from/to_user()</function> to transfer the
       data.
 
       <informalexample>
         <programlisting>
 <![CDATA[
-  static long my_file_io_read(struct snd_info_entry *entry,
+  static ssize_t my_file_io_read(struct snd_info_entry *entry,
                               void *file_private_data,
                               struct file *file,
                               char *buf,
-                              unsigned long count,
-                              unsigned long pos)
+                              size_t count,
+                              loff_t pos)
   {
-          long size = count;
-          if (pos + size > local_max_size)
-                  size = local_max_size - pos;
-          if (copy_to_user(buf, local_data + pos, size))
+          if (copy_to_user(buf, local_data + pos, count))
                   return -EFAULT;
-          return size;
+          return count;
   }
 ]]>
         </programlisting>
       </informalexample>
+
+      If the size of the info entry has been set up properly,
+      <structfield>count</structfield> and <structfield>pos</structfield> are
+      guaranteed to fit within 0 and the given size.
+      You don't have to check the range in the callbacks unless any
+      other condition is required.
+
     </para>
 
   </chapter>
index e83f2ea..898ded2 100644 (file)
@@ -216,7 +216,7 @@ The driver should return one of the following result codes:
 
                - PCI_ERS_RESULT_NEED_RESET
                  Driver returns this if it thinks the device is not
-                 recoverable in it's current state and it needs a slot
+                 recoverable in its current state and it needs a slot
                  reset to proceed.
 
                - PCI_ERS_RESULT_DISCONNECT
@@ -241,7 +241,7 @@ in working condition.
 
 The driver is not supposed to restart normal driver I/O operations
 at this point.  It should limit itself to "probing" the device to
-check it's recoverability status. If all is right, then the platform
+check its recoverability status. If all is right, then the platform
 will call resume() once all drivers have ack'd link_reset().
 
        Result codes:
index 1423d25..44c6dcc 100644 (file)
@@ -3,35 +3,79 @@ Using RCU's CPU Stall Detector
 The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables
 RCU's CPU stall detector, which detects conditions that unduly delay
 RCU grace periods.  The stall detector's idea of what constitutes
-"unduly delayed" is controlled by a pair of C preprocessor macros:
+"unduly delayed" is controlled by a set of C preprocessor macros:
 
 RCU_SECONDS_TILL_STALL_CHECK
 
        This macro defines the period of time that RCU will wait from
        the beginning of a grace period until it issues an RCU CPU
-       stall warning.  It is normally ten seconds.
+       stall warning.  This time period is normally ten seconds.
 
 RCU_SECONDS_TILL_STALL_RECHECK
 
        This macro defines the period of time that RCU will wait after
-       issuing a stall warning until it issues another stall warning.
-       It is normally set to thirty seconds.
+       issuing a stall warning until it issues another stall warning
+       for the same stall.  This time period is normally set to thirty
+       seconds.
 
 RCU_STALL_RAT_DELAY
 
-       The CPU stall detector tries to make the offending CPU rat on itself,
-       as this often gives better-quality stack traces.  However, if
-       the offending CPU does not detect its own stall in the number
-       of jiffies specified by RCU_STALL_RAT_DELAY, then other CPUs will
-       complain.  This is normally set to two jiffies.
+       The CPU stall detector tries to make the offending CPU print its
+       own warnings, as this often gives better-quality stack traces.
+       However, if the offending CPU does not detect its own stall in
+       the number of jiffies specified by RCU_STALL_RAT_DELAY, then
+       some other CPU will complain.  This delay is normally set to
+       two jiffies.
 
-The following problems can result in an RCU CPU stall warning:
+When a CPU detects that it is stalling, it will print a message similar
+to the following:
+
+INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies)
+
+This message indicates that CPU 5 detected that it was causing a stall,
+and that the stall was affecting RCU-sched.  This message will normally be
+followed by a stack dump of the offending CPU.  On TREE_RCU kernel builds,
+RCU and RCU-sched are implemented by the same underlying mechanism,
+while on TREE_PREEMPT_RCU kernel builds, RCU is instead implemented
+by rcu_preempt_state.
+
+On the other hand, if the offending CPU fails to print out a stall-warning
+message quickly enough, some other CPU will print a message similar to
+the following:
+
+INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies)
+
+This message indicates that CPU 2 detected that CPUs 3 and 5 were both
+causing stalls, and that the stall was affecting RCU-bh.  This message
+will normally be followed by stack dumps for each CPU.  Please note that
+TREE_PREEMPT_RCU builds can be stalled by tasks as well as by CPUs,
+and that the tasks will be indicated by PID, for example, "P3421".
+It is even possible for a rcu_preempt_state stall to be caused by both
+CPUs -and- tasks, in which case the offending CPUs and tasks will all
+be called out in the list.
+
+Finally, if the grace period ends just as the stall warning starts
+printing, there will be a spurious stall-warning message:
+
+INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies)
+
+This is rare, but does happen from time to time in real life.
+
+So your kernel printed an RCU CPU stall warning.  The next question is
+"What caused it?"  The following problems can result in RCU CPU stall
+warnings:
 
 o      A CPU looping in an RCU read-side critical section.
        
-o      A CPU looping with interrupts disabled.
+o      A CPU looping with interrupts disabled.  This condition can
+       result in RCU-sched and RCU-bh stalls.
 
-o      A CPU looping with preemption disabled.
+o      A CPU looping with preemption disabled.  This condition can
+       result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh
+       stalls.
+
+o      A CPU looping with bottom halves disabled.  This condition can
+       result in RCU-sched and RCU-bh stalls.
 
 o      For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
        without invoking schedule().
@@ -39,20 +83,24 @@ o   For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
 o      A bug in the RCU implementation.
 
 o      A hardware failure.  This is quite unlikely, but has occurred
-       at least once in a former life.  A CPU failed in a running system,
+       at least once in real life.  A CPU failed in a running system,
        becoming unresponsive, but not causing an immediate crash.
        This resulted in a series of RCU CPU stall warnings, eventually
        leading the realization that the CPU had failed.
 
-The RCU, RCU-sched, and RCU-bh implementations have CPU stall warning.
-SRCU does not do so directly, but its calls to synchronize_sched() will
-result in RCU-sched detecting any CPU stalls that might be occurring.
-
-To diagnose the cause of the stall, inspect the stack traces.  The offending
-function will usually be near the top of the stack.  If you have a series
-of stall warnings from a single extended stall, comparing the stack traces
-can often help determine where the stall is occurring, which will usually
-be in the function nearest the top of the stack that stays the same from
-trace to trace.
+The RCU, RCU-sched, and RCU-bh implementations have CPU stall
+warning.  SRCU does not have its own CPU stall warnings, but its
+calls to synchronize_sched() will result in RCU-sched detecting
+RCU-sched-related CPU stalls.  Please note that RCU only detects
+CPU stalls when there is a grace period in progress.  No grace period,
+no CPU stall warnings.
+
+To diagnose the cause of the stall, inspect the stack traces.
+The offending function will usually be near the top of the stack.
+If you have a series of stall warnings from a single extended stall,
+comparing the stack traces can often help determine where the stall
+is occurring, which will usually be in the function nearest the top of
+that portion of the stack which remains the same from trace to trace.
+If you can reliably trigger the stall, ftrace can be quite helpful.
 
 RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE.
index 0e50bc2..5d90167 100644 (file)
@@ -182,16 +182,6 @@ Similarly, sched_expedited RCU provides the following:
        sched_expedited-torture: Reader Pipe:  12660320201 95875 0 0 0 0 0 0 0 0 0
        sched_expedited-torture: Reader Batch:  12660424885 0 0 0 0 0 0 0 0 0 0
        sched_expedited-torture: Free-Block Circulation:  1090795 1090795 1090794 1090793 1090792 1090791 1090790 1090789 1090788 1090787 0
-       state: -1 / 0:0 3:0 4:0
-
-As before, the first four lines are similar to those for RCU.
-The last line shows the task-migration state.  The first number is
--1 if synchronize_sched_expedited() is idle, -2 if in the process of
-posting wakeups to the migration kthreads, and N when waiting on CPU N.
-Each of the colon-separated fields following the "/" is a CPU:state pair.
-Valid states are "0" for idle, "1" for waiting for quiescent state,
-"2" for passed through quiescent state, and "3" when a race with a
-CPU-hotplug event forces use of the synchronize_sched() primitive.
 
 
 USAGE
index 8608fd8..efd8cc9 100644 (file)
@@ -256,23 +256,23 @@ o Each element of the form "1/1 0:127 ^0" represents one struct
 The output of "cat rcu/rcu_pending" looks as follows:
 
 rcu_sched:
-  0 np=255892 qsp=53936 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741
-  1 np=261224 qsp=54638 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792
-  2 np=237496 qsp=49664 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629
-  3 np=236249 qsp=48766 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723
-  4 np=221310 qsp=46850 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110
-  5 np=237332 qsp=48449 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456
-  6 np=219995 qsp=46718 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834
-  7 np=249893 qsp=49390 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888
+  0 np=255892 qsp=53936 rpq=85 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741
+  1 np=261224 qsp=54638 rpq=33 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792
+  2 np=237496 qsp=49664 rpq=23 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629
+  3 np=236249 qsp=48766 rpq=98 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723
+  4 np=221310 qsp=46850 rpq=7 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110
+  5 np=237332 qsp=48449 rpq=9 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456
+  6 np=219995 qsp=46718 rpq=12 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834
+  7 np=249893 qsp=49390 rpq=42 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888
 rcu_bh:
-  0 np=146741 qsp=1419 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314
-  1 np=155792 qsp=12597 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180
-  2 np=136629 qsp=18680 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936
-  3 np=137723 qsp=2843 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863
-  4 np=123110 qsp=12433 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671
-  5 np=137456 qsp=4210 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235
-  6 np=120834 qsp=9902 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921
-  7 np=144888 qsp=26336 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542
+  0 np=146741 qsp=1419 rpq=6 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314
+  1 np=155792 qsp=12597 rpq=3 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180
+  2 np=136629 qsp=18680 rpq=1 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936
+  3 np=137723 qsp=2843 rpq=0 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863
+  4 np=123110 qsp=12433 rpq=0 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671
+  5 np=137456 qsp=4210 rpq=1 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235
+  6 np=120834 qsp=9902 rpq=2 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921
+  7 np=144888 qsp=26336 rpq=0 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542
 
 As always, this is once again split into "rcu_sched" and "rcu_bh"
 portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional
@@ -284,6 +284,9 @@ o   "np" is the number of times that __rcu_pending() has been invoked
 o      "qsp" is the number of times that the RCU was waiting for a
        quiescent state from this CPU.
 
+o      "rpq" is the number of times that the CPU had passed through
+       a quiescent state, but not yet reported it to RCU.
+
 o      "cbr" is the number of times that this CPU had RCU callbacks
        that had passed through a grace period, and were thus ready
        to be invoked.
index 34614b4..e9dab41 100644 (file)
@@ -73,7 +73,7 @@ NOTE: Smack labels are limited to 23 characters. The attr command
 If you don't do anything special all users will get the floor ("_")
 label when they log in. If you do want to log in via the hacked ssh
 at other labels use the attr command to set the smack value on the
-home directory and it's contents.
+home directory and its contents.
 
 You can add access rules in /etc/smack/accesses. They take the form:
 
index 82e418d..7f5fc3b 100644 (file)
@@ -20,6 +20,8 @@ Samsung-S3C24XX
        - S3C24XX ARM Linux Overview
 Sharp-LH
        - Linux on Sharp LH79524 and LH7A40X System On a Chip (SOC)
+SPEAr
+       - ST SPEAr platform Linux Overview
 VFP/
        - Release notes for Linux Kernel Vector Floating Point support code
 empeg/
index 7197a9e..f9f62e8 100644 (file)
@@ -32,7 +32,7 @@ Notes:
 
 - The flash on board is divided into 3 partitions.
   You should be careful to use flash on board.
-  It's partition is different from GraphicsClient Plus and GraphicsMaster
+  Its partition is different from GraphicsClient Plus and GraphicsMaster
 
 - 16bpp mode requires a different cable than what ships with the board.
   Contact ADS or look through the manual to wire your own. Currently,
diff --git a/Documentation/arm/SPEAr/overview.txt b/Documentation/arm/SPEAr/overview.txt
new file mode 100644 (file)
index 0000000..253a35c
--- /dev/null
@@ -0,0 +1,60 @@
+                       SPEAr ARM Linux Overview
+                       ==========================
+
+Introduction
+------------
+
+  SPEAr (Structured Processor Enhanced Architecture).
+  weblink : http://www.st.com/spear
+
+  The ST Microelectronics SPEAr range of ARM9/CortexA9 System-on-Chip CPUs are
+  supported by the 'spear' platform of ARM Linux. Currently SPEAr300,
+  SPEAr310, SPEAr320 and SPEAr600 SOCs are supported. Support for the SPEAr13XX
+  series is in progress.
+
+  Hierarchy in SPEAr is as follows:
+
+  SPEAr (Platform)
+       - SPEAr3XX (3XX SOC series, based on ARM9)
+               - SPEAr300 (SOC)
+                       - SPEAr300_EVB (Evaluation Board)
+               - SPEAr310 (SOC)
+                       - SPEAr310_EVB (Evaluation Board)
+               - SPEAr320 (SOC)
+                       - SPEAr320_EVB (Evaluation Board)
+       - SPEAr6XX (6XX SOC series, based on ARM9)
+               - SPEAr600 (SOC)
+                       - SPEAr600_EVB (Evaluation Board)
+       - SPEAr13XX (13XX SOC series, based on ARM CORTEXA9)
+               - SPEAr1300 (SOC)
+
+  Configuration
+  -------------
+
+  A generic configuration is provided for each machine, and can be used as the
+  default by
+       make spear600_defconfig
+       make spear300_defconfig
+       make spear310_defconfig
+       make spear320_defconfig
+
+  Layout
+  ------
+
+  The common files for multiple machine families (SPEAr3XX, SPEAr6XX and
+  SPEAr13XX) are located in the platform code contained in arch/arm/plat-spear
+  with headers in plat/.
+
+  Each machine series have a directory with name arch/arm/mach-spear followed by
+  series name. Like mach-spear3xx, mach-spear6xx and mach-spear13xx.
+
+  Common file for machines of spear3xx family is mach-spear3xx/spear3xx.c and for
+  spear6xx is mach-spear6xx/spear6xx.c. mach-spear* also contain soc/machine
+  specific files, like spear300.c, spear310.c, spear320.c and spear600.c.
+  mach-spear* also contains board specific files for each machine type.
+
+
+  Document Author
+  ---------------
+
+  Viresh Kumar, (c) 2010 ST Microelectronics
index 1e6a23f..dc460f0 100644 (file)
@@ -7,7 +7,7 @@ The driver only implements a four-wire touch panel protocol.
 
 The touchscreen driver is maintenance free except for the pen-down or
 touch threshold.  Some resistive displays and board combinations may
-require tuning of this threshold.  The driver exposes some of it's
+require tuning of this threshold.  The driver exposes some of its
 internal state in the sys filesystem.  If the kernel is configured
 with it, CONFIG_SYSFS, and sysfs is mounted at /sys, there will be a
 directory
index 396bec3..ac4d471 100644 (file)
@@ -320,7 +320,7 @@ counter decrement would not become globally visible until the
 obj->active update does.
 
 As a historical note, 32-bit Sparc used to only allow usage of
-24-bits of it's atomic_t type.  This was because it used 8 bits
+24-bits of its atomic_t type.  This was because it used 8 bits
 as a spinlock for SMP safety.  Sparc32 lacked a "compare and swap"
 type instruction.  However, 32-bit Sparc has since been moved over
 to a "hash table of spinlocks" scheme, that allows the full 32-bit
index 9898c7d..f731c1e 100644 (file)
@@ -43,7 +43,7 @@
        void bfin_gpio_irq_free(unsigned gpio);
 
     The request functions will record the function state for a certain pin,
-    the free functions will clear it's function state.
+    the free functions will clear its function state.
     Once a pin is requested, it can't be requested again before it is freed by
     previous caller, otherwise kernel will dump stacks, and the request
     function fail.
index 2b5f823..9164ae3 100644 (file)
@@ -5,7 +5,7 @@
 
 This document describes the cache/tlb flushing interfaces called
 by the Linux VM subsystem.  It enumerates over each interface,
-describes it's intended purpose, and what side effect is expected
+describes its intended purpose, and what side effect is expected
 after the interface is invoked.
 
 The side effects described below are stated for a uniprocessor
@@ -231,7 +231,7 @@ require a whole different set of interfaces to handle properly.
 The biggest problem is that of virtual aliasing in the data cache
 of a processor.
 
-Is your port susceptible to virtual aliasing in it's D-cache?
+Is your port susceptible to virtual aliasing in its D-cache?
 Well, if your D-cache is virtually indexed, is larger in size than
 PAGE_SIZE, and does not prevent multiple cache lines for the same
 physical address from existing at once, you have this problem.
@@ -249,7 +249,7 @@ one way to solve this (in particular SPARC_FLAG_MMAPSHARED).
 Next, you have to solve the D-cache aliasing issue for all
 other cases.  Please keep in mind that fact that, for a given page
 mapped into some user address space, there is always at least one more
-mapping, that of the kernel in it's linear mapping starting at
+mapping, that of the kernel in its linear mapping starting at
 PAGE_OFFSET.  So immediately, once the first user maps a given
 physical page into its address space, by implication the D-cache
 aliasing problem has the potential to exist since the kernel already
index a1ca592..57444c2 100644 (file)
@@ -572,7 +572,7 @@ void cancel_attach(struct cgroup_subsys *ss, struct cgroup *cgrp,
 
 Called when a task attach operation has failed after can_attach() has succeeded.
 A subsystem whose can_attach() has some side-effects should provide this
-function, so that the subsytem can implement a rollback. If not, not necessary.
+function, so that the subsystem can implement a rollback. If not, not necessary.
 This will be called only about subsystems whose can_attach() operation have
 succeeded.
 
index 4160df8..51682ab 100644 (file)
@@ -42,7 +42,7 @@ Nodes to a set of tasks.   In this document "Memory Node" refers to
 an on-line node that contains memory.
 
 Cpusets constrain the CPU and Memory placement of tasks to only
-the resources within a tasks current cpuset.  They form a nested
+the resources within a task's current cpuset.  They form a nested
 hierarchy visible in a virtual file system.  These are the essential
 hooks, beyond what is already present, required to manage dynamic
 job placement on large systems.
@@ -53,11 +53,11 @@ Documentation/cgroups/cgroups.txt.
 Requests by a task, using the sched_setaffinity(2) system call to
 include CPUs in its CPU affinity mask, and using the mbind(2) and
 set_mempolicy(2) system calls to include Memory Nodes in its memory
-policy, are both filtered through that tasks cpuset, filtering out any
+policy, are both filtered through that task's cpuset, filtering out any
 CPUs or Memory Nodes not in that cpuset.  The scheduler will not
 schedule a task on a CPU that is not allowed in its cpus_allowed
 vector, and the kernel page allocator will not allocate a page on a
-node that is not allowed in the requesting tasks mems_allowed vector.
+node that is not allowed in the requesting task's mems_allowed vector.
 
 User level code may create and destroy cpusets by name in the cgroup
 virtual file system, manage the attributes and permissions of these
@@ -121,9 +121,9 @@ Cpusets extends these two mechanisms as follows:
  - Each task in the system is attached to a cpuset, via a pointer
    in the task structure to a reference counted cgroup structure.
  - Calls to sched_setaffinity are filtered to just those CPUs
-   allowed in that tasks cpuset.
+   allowed in that task's cpuset.
  - Calls to mbind and set_mempolicy are filtered to just
-   those Memory Nodes allowed in that tasks cpuset.
+   those Memory Nodes allowed in that task's cpuset.
  - The root cpuset contains all the systems CPUs and Memory
    Nodes.
  - For any cpuset, one can define child cpusets containing a subset
@@ -141,11 +141,11 @@ into the rest of the kernel, none in performance critical paths:
  - in init/main.c, to initialize the root cpuset at system boot.
  - in fork and exit, to attach and detach a task from its cpuset.
  - in sched_setaffinity, to mask the requested CPUs by what's
-   allowed in that tasks cpuset.
+   allowed in that task's cpuset.
  - in sched.c migrate_live_tasks(), to keep migrating tasks within
    the CPUs allowed by their cpuset, if possible.
  - in the mbind and set_mempolicy system calls, to mask the requested
-   Memory Nodes by what's allowed in that tasks cpuset.
+   Memory Nodes by what's allowed in that task's cpuset.
  - in page_alloc.c, to restrict memory to allowed nodes.
  - in vmscan.c, to restrict page recovery to the current cpuset.
 
@@ -155,7 +155,7 @@ new system calls are added for cpusets - all support for querying and
 modifying cpusets is via this cpuset file system.
 
 The /proc/<pid>/status file for each task has four added lines,
-displaying the tasks cpus_allowed (on which CPUs it may be scheduled)
+displaying the task's cpus_allowed (on which CPUs it may be scheduled)
 and mems_allowed (on which Memory Nodes it may obtain memory),
 in the two formats seen in the following example:
 
@@ -323,17 +323,17 @@ stack segment pages of a task.
 
 By default, both kinds of memory spreading are off, and memory
 pages are allocated on the node local to where the task is running,
-except perhaps as modified by the tasks NUMA mempolicy or cpuset
+except perhaps as modified by the task's NUMA mempolicy or cpuset
 configuration, so long as sufficient free memory pages are available.
 
 When new cpusets are created, they inherit the memory spread settings
 of their parent.
 
 Setting memory spreading causes allocations for the affected page
-or slab caches to ignore the tasks NUMA mempolicy and be spread
+or slab caches to ignore the task's NUMA mempolicy and be spread
 instead.    Tasks using mbind() or set_mempolicy() calls to set NUMA
 mempolicies will not notice any change in these calls as a result of
-their containing tasks memory spread settings.  If memory spreading
+their containing task's memory spread settings.  If memory spreading
 is turned off, then the currently specified NUMA mempolicy once again
 applies to memory page allocations.
 
@@ -357,7 +357,7 @@ pages from the node returned by cpuset_mem_spread_node().
 
 The cpuset_mem_spread_node() routine is also simple.  It uses the
 value of a per-task rotor cpuset_mem_spread_rotor to select the next
-node in the current tasks mems_allowed to prefer for the allocation.
+node in the current task's mems_allowed to prefer for the allocation.
 
 This memory placement policy is also known (in other contexts) as
 round-robin or interleave.
@@ -594,7 +594,7 @@ is attached, is subtle.
 If a cpuset has its Memory Nodes modified, then for each task attached
 to that cpuset, the next time that the kernel attempts to allocate
 a page of memory for that task, the kernel will notice the change
-in the tasks cpuset, and update its per-task memory placement to
+in the task's cpuset, and update its per-task memory placement to
 remain within the new cpusets memory placement.  If the task was using
 mempolicy MPOL_BIND, and the nodes to which it was bound overlap with
 its new cpuset, then the task will continue to use whatever subset
@@ -603,13 +603,13 @@ was using MPOL_BIND and now none of its MPOL_BIND nodes are allowed
 in the new cpuset, then the task will be essentially treated as if it
 was MPOL_BIND bound to the new cpuset (even though its NUMA placement,
 as queried by get_mempolicy(), doesn't change).  If a task is moved
-from one cpuset to another, then the kernel will adjust the tasks
+from one cpuset to another, then the kernel will adjust the task's
 memory placement, as above, the next time that the kernel attempts
 to allocate a page of memory for that task.
 
 If a cpuset has its 'cpuset.cpus' modified, then each task in that cpuset
 will have its allowed CPU placement changed immediately.  Similarly,
-if a tasks pid is written to another cpusets 'cpuset.tasks' file, then its
+if a task's pid is written to another cpusets 'cpuset.tasks' file, then its
 allowed CPU placement is changed immediately.  If such a task had been
 bound to some subset of its cpuset using the sched_setaffinity() call,
 the task will be allowed to run on any CPU allowed in its new cpuset,
@@ -626,16 +626,16 @@ cpusets memory placement policy 'cpuset.mems' subsequently changes.
 If the cpuset flag file 'cpuset.memory_migrate' is set true, then when
 tasks are attached to that cpuset, any pages that task had
 allocated to it on nodes in its previous cpuset are migrated
-to the tasks new cpuset. The relative placement of the page within
+to the task's new cpuset. The relative placement of the page within
 the cpuset is preserved during these migration operations if possible.
 For example if the page was on the second valid node of the prior cpuset
 then the page will be placed on the second valid node of the new cpuset.
 
-Also if 'cpuset.memory_migrate' is set true, then if that cpusets
+Also if 'cpuset.memory_migrate' is set true, then if that cpuset's
 'cpuset.mems' file is modified, pages allocated to tasks in that
 cpuset, that were on nodes in the previous setting of 'cpuset.mems',
 will be moved to nodes in the new setting of 'mems.'
-Pages that were not in the tasks prior cpuset, or in the cpusets
+Pages that were not in the task's prior cpuset, or in the cpuset's
 prior 'cpuset.mems' setting, will not be moved.
 
 There is an exception to the above.  If hotplug functionality is used
@@ -655,7 +655,7 @@ There is a second exception to the above.  GFP_ATOMIC requests are
 kernel internal allocations that must be satisfied, immediately.
 The kernel may drop some request, in rare cases even panic, if a
 GFP_ATOMIC alloc fails.  If the request cannot be satisfied within
-the current tasks cpuset, then we relax the cpuset, and look for
+the current task's cpuset, then we relax the cpuset, and look for
 memory anywhere we can find it.  It's better to violate the cpuset
 than stress the kernel.
 
index f7f68b2..b7eecec 100644 (file)
@@ -244,7 +244,7 @@ Under below explanation, we assume CONFIG_MEM_RES_CTRL_SWAP=y.
          we have to check if OLDPAGE/NEWPAGE is a valid page after commit().
 
 8. LRU
-        Each memcg has its own private LRU. Now, it's handling is under global
+        Each memcg has its own private LRU. Now, its handling is under global
        VM's control (means that it's handled under global zone->lru_lock).
        Almost all routines around memcg's LRU is called by global LRU's
        list management functions under zone->lru_lock().
index 3a6aecd..6cab1f2 100644 (file)
@@ -263,7 +263,7 @@ some of the pages cached in the cgroup (page cache pages).
 
 4.2 Task migration
 
-When a task migrates from one cgroup to another, it's charge is not
+When a task migrates from one cgroup to another, its charge is not
 carried forward by default. The pages allocated from the original cgroup still
 remain charged to it, the charge is dropped when the page is freed or
 reclaimed.
index 78c9466..e5c5f5e 100644 (file)
@@ -88,7 +88,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 __groups, int gfp_mask);
  int gfp_mask                  - GFP mask.
 
  Note: When registering new callback user, connector core assigns
- netlink group to the user which is equal to it's id.idx.
+ netlink group to the user which is equal to its id.idx.
 
 /*****************************************/
 Protocol description.
index df03169..a2db352 100644 (file)
@@ -408,9 +408,6 @@ This should be used inside the RCU read lock, as in the following example:
                ...
        }
 
-A function need not get RCU read lock to use __task_cred() if it is holding a
-spinlock at the time as this implicitly holds the RCU read lock.
-
 Should it be necessary to hold another task's credentials for a long period of
 time, and possibly to sleep whilst doing so, then the caller should get a
 reference on them using:
@@ -426,17 +423,16 @@ credentials, hiding the RCU magic from the caller:
        uid_t task_uid(task)            Task's real UID
        uid_t task_euid(task)           Task's effective UID
 
-If the caller is holding a spinlock or the RCU read lock at the time anyway,
-then:
+If the caller is holding the RCU read lock at the time anyway, then:
 
        __task_cred(task)->uid
        __task_cred(task)->euid
 
 should be used instead.  Similarly, if multiple aspects of a task's credentials
-need to be accessed, RCU read lock or a spinlock should be used, __task_cred()
-called, the result stored in a temporary pointer and then the credential
-aspects called from that before dropping the lock.  This prevents the
-potentially expensive RCU magic from being invoked multiple times.
+need to be accessed, RCU read lock should be used, __task_cred() called, the
+result stored in a temporary pointer and then the credential aspects called
+from that before dropping the lock.  This prevents the potentially expensive
+RCU magic from being invoked multiple times.
 
 Should some other single aspect of another task's credentials need to be
 accessed, then this can be used:
index 2ecd834..4a0c2b5 100644 (file)
@@ -41,7 +41,7 @@ This application requires the following to function properly as of now.
 
 * Cards that fall in this category
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-At present the cards that fall in this category are the Twinhan and it's
+At present the cards that fall in this category are the Twinhan and its
 clones, these cards are available as VVMER, Tomato, Hercules, Orange and
 so on.
 
index 4865add..47c3009 100644 (file)
@@ -1,7 +1,7 @@
 Thanks go to the following people for patches and contributions:
 
 Michael Hunold <m.hunold@gmx.de>
-  for the initial saa7146 driver and it's recent overhaul
+  for the initial saa7146 driver and its recent overhaul
 
 Christian Theiss
   for his work on the initial Linux DVB driver
index 4759af3..e7965f4 100644 (file)
@@ -520,18 +520,6 @@ Who:       Hans de Goede <hdegoede@redhat.com>
 
 ----------------------------
 
-What:  corgi_ssp and corgi_ts driver
-When:  2.6.35
-Files: arch/arm/mach-pxa/corgi_ssp.c, drivers/input/touchscreen/corgi_ts.c
-Why:   The corgi touchscreen is now deprecated in favour of the generic
-       ads7846.c driver. The noise reduction technique used in corgi_ts.c,
-       that's to wait till vsync before ADC sampling, is also integrated into
-       ads7846 driver now. Provided that the original driver is not generic
-       and is difficult to maintain, it will be removed later.
-Who:   Eric Miao <eric.y.miao@gmail.com>
-
-----------------------------
-
 What:  capifs
 When:  February 2011
 Files: drivers/isdn/capi/capifs.*
@@ -553,6 +541,16 @@ Who:       Avi Kivity <avi@redhat.com>
 
 ----------------------------
 
+What:  xtime, wall_to_monotonic
+When:  2.6.36+
+Files: kernel/time/timekeeping.c include/linux/time.h
+Why:   Cleaning up timekeeping internal values. Please use
+       existing timekeeping accessor functions to access
+       the equivalent functionality.
+Who:   John Stultz <johnstul@us.ibm.com>
+
+----------------------------
+
 What:  KVM kernel-allocated memory slots
 When:  July 2010
 Why:   Since 2.6.25, kvm supports user-allocated memory slots, which are
@@ -601,3 +599,13 @@ Why:       The vtx device nodes have been superseded by vbi device nodes
        provided by the vtx API, then that functionality should be build
        around the sliced VBI API instead.
 Who:   Hans Verkuil <hverkuil@xs4all.nl>
+
+----------------------------
+
+What:  IRQF_DISABLED
+When:  2.6.36
+Why:   The flag is a NOOP as we run interrupt handlers with interrupts disabled
+Who:   Thomas Gleixner <tglx@linutronix.de>
+
+----------------------------
+
index 06bbbed..af16080 100644 (file)
@@ -178,7 +178,7 @@ prototypes:
 locking rules:
        All except set_page_dirty may block
 
-                       BKL     PageLocked(page)        i_sem
+                       BKL     PageLocked(page)        i_mutex
 writepage:             no      yes, unlocks (see below)
 readpage:              no      yes, unlocks
 sync_page:             no      maybe
@@ -429,7 +429,7 @@ check_flags:                no
 implementations.  If your fs is not using generic_file_llseek, you
 need to acquire and release the appropriate locks in your ->llseek().
 For many filesystems, it is probably safe to acquire the inode
-semaphore.  Note some filesystems (i.e. remote ones) provide no
+mutex.  Note some filesystems (i.e. remote ones) provide no
 protection for i_size so you will need to use the BKL.
 
 Note: ext2_release() was *the* source of contention on fs-intensive
index 8f78ded..51986bf 100644 (file)
@@ -146,7 +146,7 @@ found to be inadequate, in this case. The Generic Netlink system was
 used for this as raw Netlink would lead to a significant increase in
 complexity. There's no question that the Generic Netlink system is an
 elegant solution for common case ioctl functions but it's not a complete
-replacement probably because it's primary purpose in life is to be a
+replacement probably because its primary purpose in life is to be a
 message bus implementation rather than specifically an ioctl replacement.
 While it would be possible to work around this there is one concern
 that lead to the decision to not use it. This is that the autofs
index 0660c9f..763d8eb 100644 (file)
@@ -90,7 +90,7 @@ Mount Options
        Specify the IP and/or port the client should bind to locally.
        There is normally not much reason to do this.  If the IP is not
        specified, the client's IP address is determined by looking at the
-       address it's connection to the monitor originates from.
+       address its connection to the monitor originates from.
 
   wsize=X
        Specify the maximum write size in bytes.  By default there is no
index c50bbb2..1b528b2 100644 (file)
@@ -47,7 +47,7 @@ You'll want to start heartbeating on a volume which all the nodes in
 your lockspace can access. The easiest way to do this is via
 ocfs2_hb_ctl (distributed with ocfs2-tools). Right now it requires
 that an OCFS2 file system be in place so that it can automatically
-find it's heartbeat area, though it will eventually support heartbeat
+find its heartbeat area, though it will eventually support heartbeat
 against raw disks.
 
 Please see the ocfs2_hb_ctl and mkfs.ocfs2 manual pages distributed
index 606233c..1b805a0 100644 (file)
@@ -38,7 +38,7 @@ flags, it will return EBADR and the contents of fm_flags will contain
 the set of flags which caused the error. If the kernel is compatible
 with all flags passed, the contents of fm_flags will be unmodified.
 It is up to userspace to determine whether rejection of a particular
-flag is fatal to it's operation. This scheme is intended to allow the
+flag is fatal to its operation. This scheme is intended to allow the
 fiemap interface to grow in the future but without losing
 compatibility with old software.
 
@@ -56,7 +56,7 @@ If this flag is set, the kernel will sync the file before mapping extents.
 
 * FIEMAP_FLAG_XATTR
 If this flag is set, the extents returned will describe the inodes
-extended attribute lookup tree, instead of it's data tree.
+extended attribute lookup tree, instead of its data tree.
 
 
 Extent Mapping
@@ -89,7 +89,7 @@ struct fiemap_extent {
 };
 
 All offsets and lengths are in bytes and mirror those on disk.  It is valid
-for an extents logical offset to start before the request or it's logical
+for an extents logical offset to start before the request or its logical
 length to extend past the request.  Unless FIEMAP_EXTENT_NOT_ALIGNED is
 returned, fe_logical, fe_physical, and fe_length will be aligned to the
 block size of the file system.  With the exception of extents flagged as
@@ -125,7 +125,7 @@ been allocated for the file yet.
 
 * FIEMAP_EXTENT_DELALLOC
   - This will also set FIEMAP_EXTENT_UNKNOWN.
-Delayed allocation - while there is data for this extent, it's
+Delayed allocation - while there is data for this extent, its
 physical location has not been allocated yet.
 
 * FIEMAP_EXTENT_ENCODED
@@ -159,7 +159,7 @@ Data is located within a meta data block.
 Data is packed into a block with data from other files.
 
 * FIEMAP_EXTENT_UNWRITTEN
-Unwritten extent - the extent is allocated but it's data has not been
+Unwritten extent - the extent is allocated but its data has not been
 initialized.  This indicates the extent's data will be all zero if read
 through the filesystem but the contents are undefined if read directly from
 the device.
@@ -176,7 +176,7 @@ VFS -> File System Implementation
 
 File systems wishing to support fiemap must implement a ->fiemap callback on
 their inode_operations structure. The fs ->fiemap call is responsible for
-defining it's set of supported fiemap flags, and calling a helper function on
+defining its set of supported fiemap flags, and calling a helper function on
 each discovered extent:
 
 struct inode_operations {
index 397a41a..13af4a4 100644 (file)
@@ -91,7 +91,7 @@ Mount options
 'default_permissions'
 
   By default FUSE doesn't check file access permissions, the
-  filesystem is free to implement it's access policy or leave it to
+  filesystem is free to implement its access policy or leave it to
   the underlying file access mechanism (e.g. in case of network
   filesystems).  This option enables permission checking, restricting
   access based on file mode.  It is usually useful together with the
@@ -171,7 +171,7 @@ or may honor them by sending a reply to the _original_ request, with
 the error set to EINTR.
 
 It is also possible that there's a race between processing the
-original request and it's INTERRUPT request.  There are two possibilities:
+original request and its INTERRUPT request.  There are two possibilities:
 
   1) The INTERRUPT request is processed before the original request is
      processed
index fa45c3b..74630bd 100644 (file)
@@ -103,7 +103,7 @@ to analyze or change OS2SYS.INI.
 Codepages
 
 HPFS can contain several uppercasing tables for several codepages and each
-file has a pointer to codepage it's name is in. However OS/2 was created in
+file has a pointer to codepage its name is in. However OS/2 was created in
 America where people don't care much about codepages and so multiple codepages
 support is quite buggy. I have Czech OS/2 working in codepage 852 on my disk.
 Once I booted English OS/2 working in cp 850 and I created a file on my 852
index e64c94b..bca42c2 100644 (file)
@@ -59,7 +59,7 @@ Levels
 ------
 
 Garbage collection (GC) may fail if all data is written
-indiscriminately.  One requirement of GC is that data is seperated
+indiscriminately.  One requirement of GC is that data is separated
 roughly according to the distance between the tree root and the data.
 Effectively that means all file data is on level 0, indirect blocks
 are on levels 1, 2, 3 4 or 5 for 1x, 2x, 3x, 4x or 5x indirect blocks,
@@ -67,7 +67,7 @@ respectively.  Inode file data is on level 6 for the inodes and 7-11
 for indirect blocks.
 
 Each segment contains objects of a single level only.  As a result,
-each level requires its own seperate segment to be open for writing.
+each level requires its own separate segment to be open for writing.
 
 Inode File
 ----------
@@ -106,9 +106,9 @@ Vim
 ---
 
 By cleverly predicting the life time of data, it is possible to
-seperate long-living data from short-living data and thereby reduce
+separate long-living data from short-living data and thereby reduce
 the GC overhead later.  Each type of distinc life expectency (vim) can
-have a seperate segment open for writing.  Each (level, vim) tupel can
+have a separate segment open for writing.  Each (level, vim) tupel can
 be open just once.  If an open segment with unknown vim is encountered
 at mount time, it is closed and ignored henceforth.
 
index 6a53a84..0488491 100644 (file)
@@ -137,7 +137,7 @@ NS*| OPENATTR             | OPT        |              | Section 18.17  |
    | READ                 | REQ        |              | Section 18.22  |
    | READDIR              | REQ        |              | Section 18.23  |
    | READLINK             | OPT        |              | Section 18.24  |
-NS | RECLAIM_COMPLETE     | REQ        |              | Section 18.51  |
+   | RECLAIM_COMPLETE     | REQ        |              | Section 18.51  |
    | RELEASE_LOCKOWNER    | MNI        |              | N/A            |
    | REMOVE               | REQ        |              | Section 18.25  |
    | RENAME               | REQ        |              | Section 18.26  |
index 8a382be..ebcaaee 100644 (file)
@@ -185,7 +185,7 @@ failed lookup meant a definite 'no'.
 request/response format
 -----------------------
 
-While each cache is free to use it's own format for requests
+While each cache is free to use its own format for requests
 and responses over channel, the following is recommended as
 appropriate and support routines are available to help:
 Each request or response record should be printable ASCII
index 1e359b6..9fb6cbe 100644 (file)
@@ -305,7 +305,7 @@ Table 1-4: Contents of the stat files (as of 2.6.30-rc7)
   cgtime        guest time of the task children in jiffies
 ..............................................................................
 
-The /proc/PID/map file containing the currently mapped memory regions and
+The /proc/PID/maps file containing the currently mapped memory regions and
 their access permissions.
 
 The format is:
@@ -565,6 +565,10 @@ The default_smp_affinity mask applies to all non-active IRQs, which are the
 IRQs which have not yet been allocated/activated, and hence which lack a
 /proc/irq/[0-9]* directory.
 
+The node file on an SMP system shows the node to which the device using the IRQ
+reports itself as being attached. This hardware locality information does not
+include information about any possible driver locality preference.
+
 prof_cpu_mask specifies which CPUs are to be profiled by the system wide
 profiler. Default value is ffffffff (all cpus).
 
@@ -964,7 +968,7 @@ your system and how much traffic was routed over those devices:
   ...] 1375103    17405    0    0    0     0       0          0 
   ...] 1703981     5535    0    0    0     3       0          0 
 
-In addition, each Channel Bond interface has it's own directory.  For
+In addition, each Channel Bond interface has its own directory.  For
 example, the bond0 device will have a directory called /proc/net/bond0/.
 It will contain information that is specific to that bond, such as the
 current slaves of the bond, the link status of the slaves, and how
@@ -1361,7 +1365,7 @@ been accounted as having caused 1MB of write.
 In other words: The number of bytes which this process caused to not happen,
 by truncating pagecache. A task can cause "negative" IO too. If this task
 truncates some dirty pagecache, some IO which another task has been accounted
-for (in it's write_bytes) will not be happening. We _could_ just subtract that
+for (in its write_bytes) will not be happening. We _could_ just subtract that
 from the truncating task's write_bytes, but there is information loss in doing
 that.
 
index f673ef0..194fb0d 100644 (file)
@@ -3,6 +3,6 @@ protocol used by Windows for Workgroups, Windows 95 and Windows NT.
 Smbfs was inspired by Samba, the program written by Andrew Tridgell
 that turns any Unix host into a file server for DOS or Windows clients.
 
-Smbfs is a SMB client, but uses parts of samba for it's operation. For
+Smbfs is a SMB client, but uses parts of samba for its operation. For
 more info on samba, including documentation, please go to
 http://www.samba.org/ and then on to your nearest mirror.
index 3de2f32..b668585 100644 (file)
@@ -72,7 +72,7 @@ structure (this is the kernel-side implementation of file
 descriptors). The freshly allocated file structure is initialized with
 a pointer to the dentry and a set of file operation member functions.
 These are taken from the inode data. The open() file method is then
-called so the specific filesystem implementation can do it's work. You
+called so the specific filesystem implementation can do its work. You
 can see that this is another switch performed by the VFS. The file
 structure is placed into the file descriptor table for the process.
 
index a136808..a76aefe 100644 (file)
@@ -157,7 +157,7 @@ temperature configuration points:
 
 There are three PWM outputs. The LM85 datasheet suggests that the
 pwm3 output control both fan3 and fan4. Each PWM can be individually
-configured and assigned to a zone for it's control value. Each PWM can be
+configured and assigned to a zone for its control value. Each PWM can be
 configured individually according to the following options.
 
 * pwm#_auto_pwm_min - this specifies the PWM value for temp#_auto_temp_off
index 154d767..8007b7c 100644 (file)
@@ -402,7 +402,7 @@ for the port of the SoundFusion is supported by the cs461x.c module.
 ~~~~~~~~~~~~~~~~~~~~~~~~
   The Live! has a special PCI gameport, which, although it doesn't provide
 any "Enhanced" stuff like 4DWave and friends, is quite a bit faster than
-it's ISA counterparts. It also requires special support, hence the
+its ISA counterparts. It also requires special support, hence the
 emu10k1-gp.c module for it instead of the normal ns558.c one.
 
 3.15 SoundBlaster 64 and 128 - ES1370 and ES1371, ESS Solo1 and S3 SonicVibes
index f40a1f0..5dc59b0 100644 (file)
@@ -126,7 +126,7 @@ o  Tboot then applies an (optional) user-defined launch policy to
 o  Tboot adjusts the e820 table provided by the bootloader to reserve
    its own location in memory as well as to reserve certain other
    TXT-related regions.
-o  As part of it's launch, tboot DMA protects all of RAM (using the
+o  As part of its launch, tboot DMA protects all of RAM (using the
    VT-d PMRs).  Thus, the kernel must be booted with 'intel_iommu=on'
    in order to remove this blanket protection and use VT-d's
    page-level protection.
@@ -161,13 +161,15 @@ o  In order to put a system into any of the sleep states after a TXT
       has been restored, it will restore the TPM PCRs and then
       transfer control back to the kernel's S3 resume vector.
       In order to preserve system integrity across S3, the kernel
-      provides tboot with a set of memory ranges (kernel
-      code/data/bss, S3 resume code, and AP trampoline) that tboot
-      will calculate a MAC (message authentication code) over and then
-      seal with the TPM.  On resume and once the measured environment
-      has been re-established, tboot will re-calculate the MAC and
-      verify it against the sealed value.  Tboot's policy determines
-      what happens if the verification fails.
+      provides tboot with a set of memory ranges (RAM and RESERVED_KERN
+      in the e820 table, but not any memory that BIOS might alter over
+      the S3 transition) that tboot will calculate a MAC (message
+      authentication code) over and then seal with the TPM. On resume
+      and once the measured environment has been re-established, tboot
+      will re-calculate the MAC and verify it against the sealed value.
+      Tboot's policy determines what happens if the verification fails.
+      Note that the c/s 194 of tboot which has the new MAC code supports
+      this.
 
 That's pretty much it for TXT support.
 
index c412c24..b472e4e 100644 (file)
@@ -181,7 +181,7 @@ Expressions are listed in decreasing order of precedence.
 (7) Returns the result of max(/expr/, /expr/).
 
 An expression can have a value of 'n', 'm' or 'y' (or 0, 1, 2
-respectively for calculations). A menu entry becomes visible when it's
+respectively for calculations). A menu entry becomes visible when its
 expression evaluates to 'm' or 'y'.
 
 There are two types of symbols: constant and non-constant symbols.
index 49efae7..b2cb16e 100644 (file)
@@ -96,7 +96,7 @@ Environment variables for 'silentoldconfig'
 KCONFIG_NOSILENTUPDATE
 --------------------------------------------------
 If this variable has a non-blank value, it prevents silent kernel
-config udpates (requires explicit updates).
+config updates (requires explicit updates).
 
 KCONFIG_AUTOCONFIG
 --------------------------------------------------
index 28cdc2a..ec8d31e 100644 (file)
        Author: Ingo Molnar, Gadi Oxman and Miguel de Icaza.
        URL: http://www.linuxjournal.com/article.php?sid=2391
        Keywords: RAID, MD driver.
-       Description: Linux Journal Kernel Korner article. Here is it's
+       Description: Linux Journal Kernel Korner article. Here is its
        abstract: "A description of the implementation of the RAID-1,
        RAID-4 and RAID-5 personalities of the MD device driver in the
        Linux kernel, providing users with high performance and reliable,
        URL: http://www.linuxjournal.com/article.php?sid=1219
        Keywords: device driver, module, loading/unloading modules,
        allocating resources.
-       Description: Linux Journal Kernel Korner article. Here is it's
+       Description: Linux Journal Kernel Korner article. Here is its
        abstract: "This is the first of a series of four articles
        co-authored by Alessandro Rubini and Georg Zezchwitz which present
        a practical approach to writing Linux device drivers as kernel
        Keywords: character driver, init_module, clean_up module,
        autodetection, mayor number, minor number, file operations,
        open(), close().
-       Description: Linux Journal Kernel Korner article. Here is it's
+       Description: Linux Journal Kernel Korner article. Here is its
        abstract: "This article, the second of four, introduces part of
        the actual code to create custom module implementing a character
        device driver. It describes the code for module initialization and
        URL: http://www.linuxjournal.com/article.php?sid=1221
        Keywords: read(), write(), select(), ioctl(), blocking/non
        blocking mode, interrupt handler.
-       Description: Linux Journal Kernel Korner article. Here is it's
+       Description: Linux Journal Kernel Korner article. Here is its
        abstract: "This article, the third of four on writing character
        device drivers, introduces concepts of reading, writing, and using
        ioctl-calls".
        Author: Alessandro Rubini and Georg v. Zezschwitz.
        URL: http://www.linuxjournal.com/article.php?sid=1222
        Keywords: interrupts, irqs, DMA, bottom halves, task queues.
-       Description: Linux Journal Kernel Korner article. Here is it's
+       Description: Linux Journal Kernel Korner article. Here is its
        abstract: "This is the fourth in a series of articles about
        writing character device drivers as loadable kernel modules. This
        month, we further investigate the field of interrupt handling.
index 839b21b..b12bacd 100644 (file)
@@ -99,6 +99,7 @@ parameter is applicable:
        SWSUSP  Software suspend (hibernation) is enabled.
        SUSPEND System suspend states are enabled.
        FTRACE  Function tracing enabled.
+       TPM     TPM drivers are enabled.
        TS      Appropriate touchscreen support is enabled.
        UMS     USB Mass Storage support is enabled.
        USB     USB support is enabled.
@@ -151,6 +152,7 @@ and is between 256 and 4096 characters. It is defined in the file
                        strict -- Be less tolerant of platforms that are not
                                strictly ACPI specification compliant.
                        rsdt -- prefer RSDT over (default) XSDT
+                       copy_dsdt -- copy DSDT to memory
 
                        See also Documentation/power/pm.txt, pci=noacpi
 
@@ -324,6 +326,8 @@ and is between 256 and 4096 characters. It is defined in the file
                                    they are unmapped. Otherwise they are
                                    flushed before they will be reused, which
                                    is a lot of faster
+                       off       - do not initialize any AMD IOMMU found in
+                                   the system
 
        amijoy.map=     [HW,JOY] Amiga joystick support
                        Map of devices attached to JOY0DAT and JOY1DAT
@@ -784,8 +788,12 @@ and is between 256 and 4096 characters. It is defined in the file
                        as early as possible in order to facilitate early
                        boot debugging.
 
-       ftrace_dump_on_oops
+       ftrace_dump_on_oops[=orig_cpu]
                        [FTRACE] will dump the trace buffers on oops.
+                       If no parameter is passed, ftrace will dump
+                       buffers of all CPUs, but if you pass orig_cpu, it will
+                       dump only the buffer of the CPU that triggered the
+                       oops.
 
        ftrace_filter=[function-list]
                        [FTRACE] Limit the functions traced by the function
@@ -2610,6 +2618,15 @@ and is between 256 and 4096 characters. It is defined in the file
 
        tp720=          [HW,PS2]
 
+       tpm_suspend_pcr=[HW,TPM]
+                       Format: integer pcr id
+                       Specify that at suspend time, the tpm driver
+                       should extend the specified pcr with zeros,
+                       as a workaround for some chips which fail to
+                       flush the last written pcr on TPM_SaveState.
+                       This will guarantee that all the other pcrs
+                       are saved.
+
        trace_buf_size=nn[KMG]
                        [FTRACE] will set tracing buffer size.
 
index 2f9115c..6653017 100644 (file)
@@ -165,8 +165,8 @@ the user entry_handler invocation is also skipped.
 
 1.4 How Does Jump Optimization Work?
 
-If you configured your kernel with CONFIG_OPTPROBES=y (currently
-this option is supported on x86/x86-64, non-preemptive kernel) and
+If your kernel is built with CONFIG_OPTPROBES=y (currently this flag
+is automatically set 'y' on x86/x86-64, non-preemptive kernel) and
 the "debug.kprobes_optimization" kernel parameter is set to 1 (see
 sysctl(8)), Kprobes tries to reduce probe-hit overhead by using a jump
 instruction instead of a breakpoint instruction at each probepoint.
@@ -271,8 +271,6 @@ tweak the kernel's execution path, you need to suppress optimization,
 using one of the following techniques:
 - Specify an empty function for the kprobe's post_handler or break_handler.
  or
-- Config CONFIG_OPTPROBES=n.
- or
 - Execute 'sysctl -w debug.kprobes_optimization=n'
 
 2. Architectures Supported
@@ -307,10 +305,6 @@ it useful to "Compile the kernel with debug info" (CONFIG_DEBUG_INFO),
 so you can use "objdump -d -l vmlinux" to see the source-to-object
 code mapping.
 
-If you want to reduce probing overhead, set "Kprobes jump optimization
-support" (CONFIG_OPTPROBES) to "y". You can find this option under the
-"Kprobes" line.
-
 4. API Reference
 
 The Kprobes API includes a "register" function and an "unregister"
@@ -332,7 +326,7 @@ occurs during execution of kp->pre_handler or kp->post_handler,
 or during single-stepping of the probed instruction, Kprobes calls
 kp->fault_handler.  Any or all handlers can be NULL. If kp->flags
 is set KPROBE_FLAG_DISABLED, that kp will be registered but disabled,
-so, it's handlers aren't hit until calling enable_kprobe(kp).
+so, its handlers aren't hit until calling enable_kprobe(kp).
 
 NOTE:
 1. With the introduction of the "symbol_name" field to struct kprobe,
index 2c3c350..0bf25ee 100644 (file)
@@ -207,7 +207,7 @@ Tips & Tricks
 * Drew Scott Daniels observed: "I don't know why, but when I decrease the number
   of colours that my display uses it consumes less battery power. I've seen
   this on powerbooks too. I hope that this is a piece of information that
-  might be useful to the Laptop Mode patch or it's users."
+  might be useful to the Laptop Mode patch or its users."
 
 * In syslog.conf, you can prefix entries with a dash ``-'' to omit syncing the
   file after every logging. When you're using laptop-mode and your disk doesn't
index 3119f5d..e9ce3c5 100644 (file)
@@ -263,7 +263,7 @@ static u8 *get_feature_bits(struct device *dev)
  * Launcher virtual with an offset.
  *
  * This can be tough to get your head around, but usually it just means that we
- * use these trivial conversion functions when the Guest gives us it's
+ * use these trivial conversion functions when the Guest gives us its
  * "physical" addresses:
  */
 static void *from_guest_phys(unsigned long addr)
index 188f476..e4e893e 100644 (file)
@@ -136,7 +136,7 @@ raid_disks != 0.
 
 Then uninitialized devices can be added with ADD_NEW_DISK.  The
 structure passed to ADD_NEW_DISK must specify the state of the device
-and it's role in the array.
+and its role in the array.
 
 Once started with RUN_ARRAY, uninitialized spares can be added with
 HOT_ADD_DISK.
index 98dd9f7..638c74f 100644 (file)
@@ -38,7 +38,7 @@ Depending on the exact configuration, translation between the network packet
 label and the internal LSM security identifier can be time consuming.  The
 NetLabel label mapping cache is a caching mechanism which can be used to
 sidestep much of this overhead once a mapping has been established.  Once the
-LSM has received a packet, used NetLabel to decode it's security attributes,
+LSM has received a packet, used NetLabel to decode its security attributes,
 and translated the security attributes into a LSM internal identifier the LSM
 can use the NetLabel caching functions to associate the LSM internal
 identifier with the network packet's label.  This means that in the future
index 1b96ccd..2bac961 100644 (file)
@@ -756,7 +756,7 @@ static int enslave(char *master_ifname, char *slave_ifname)
                 */
                if (abi_ver < 1) {
                        /* For old ABI, the master needs to be
-                        * down before setting it's hwaddr
+                        * down before setting its hwaddr
                         */
                        res = set_if_down(master_ifname, master_flags.ifr_flags);
                        if (res) {
index 09ab0d2..98f71a5 100644 (file)
@@ -100,7 +100,7 @@ by the kernel.
 The destruction of the socket and all associated resources
 is done by a simple call to close(fd).
 
-Next I will describe PACKET_MMAP settings and it's constraints,
+Next I will describe PACKET_MMAP settings and its constraints,
 also the mapping of the circular buffer in the user process and 
 the use of this buffer.
 
@@ -432,7 +432,7 @@ TP_STATUS_LOSING      : indicates there were packet drops from last time
                         the PACKET_STATISTICS option.
 
 TP_STATUS_CSUMNOTREADY: currently it's used for outgoing IP packets which 
-                        it's checksum will be done in hardware. So while 
+                        its checksum will be done in hardware. So while
                         reading the packet we should not try to check the 
                         checksum. 
 
index 446f43b..61bc4e9 100644 (file)
@@ -1,4 +1,17 @@
 This file details changes in 2.6 which affect PCMCIA card driver authors:
+* No dev_node_t (as of 2.6.35)
+   There is no more need to fill out a "dev_node_t" structure.
+
+* New IRQ request rules (as of 2.6.35)
+   Instead of the old pcmcia_request_irq() interface, drivers may now
+   choose between:
+   - calling request_irq/free_irq directly. Use the IRQ from *p_dev->irq.
+   - use pcmcia_request_irq(p_dev, handler_t); the PCMCIA core will
+     clean up automatically on calls to pcmcia_disable_device() or
+     device ejection.
+   - drivers still not capable of IRQF_SHARED (or not telling us so) may
+     use the deprecated pcmcia_request_exclusive_irq() for the time
+     being; they might receive a shared IRQ nonetheless.
 
 * no cs_error / CS_CHECK / CONFIG_PCMCIA_DEBUG (as of 2.6.33)
    Instead of the cs_error() callback or the CS_CHECK() macro, please use
index c9abbd8..57080cd 100644 (file)
@@ -1,7 +1,13 @@
+Device Power Management
+
+Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
+Copyright (c) 2010 Alan Stern <stern@rowland.harvard.edu>
+
+
 Most of the code in Linux is device drivers, so most of the Linux power
-management code is also driver-specific.  Most drivers will do very little;
-others, especially for platforms with small batteries (like cell phones),
-will do a lot.
+management (PM) code is also driver-specific.  Most drivers will do very
+little; others, especially for platforms with small batteries (like cell
+phones), will do a lot.
 
 This writeup gives an overview of how drivers interact with system-wide
 power management goals, emphasizing the models and interfaces that are
@@ -15,9 +21,10 @@ Drivers will use one or both of these models to put devices into low-power
 states:
 
     System Sleep model:
-       Drivers can enter low power states as part of entering system-wide
-       low-power states like "suspend-to-ram", or (mostly for systems with
-       disks) "hibernate" (suspend-to-disk).
+       Drivers can enter low-power states as part of entering system-wide
+       low-power states like "suspend" (also known as "suspend-to-RAM"), or
+       (mostly for systems with disks) "hibernation" (also known as
+       "suspend-to-disk").
 
        This is something that device, bus, and class drivers collaborate on
        by implementing various role-specific suspend and resume methods to
@@ -25,33 +32,41 @@ states:
        them without loss of data.
 
        Some drivers can manage hardware wakeup events, which make the system
-       leave that low-power state.  This feature may be disabled using the
-       relevant /sys/devices/.../power/wakeup file; enabling it may cost some
-       power usage, but let the whole system enter low power states more often.
+       leave the low-power state.  This feature may be enabled or disabled
+       using the relevant /sys/devices/.../power/wakeup file (for Ethernet
+       drivers the ioctl interface used by ethtool may also be used for this
+       purpose); enabling it may cost some power usage, but let the whole
+       system enter low-power states more often.
 
     Runtime Power Management model:
-       Drivers may also enter low power states while the system is running,
-       independently of other power management activity.  Upstream drivers
-       will normally not know (or care) if the device is in some low power
-       state when issuing requests; the driver will auto-resume anything
-       that's needed when it gets a request.
-
-       This doesn't have, or need much infrastructure; it's just something you
-       should do when writing your drivers.  For example, clk_disable() unused
-       clocks as part of minimizing power drain for currently-unused hardware.
-       Of course, sometimes clusters of drivers will collaborate with each
-       other, which could involve task-specific power management.
-
-There's not a lot to be said about those low power states except that they
-are very system-specific, and often device-specific.  Also, that if enough
-drivers put themselves into low power states (at "runtime"), the effect may be
-the same as entering some system-wide low-power state (system sleep) ... and
-that synergies exist, so that several drivers using runtime pm might put the
-system into a state where even deeper power saving options are available.
-
-Most suspended devices will have quiesced all I/O:  no more DMA or irqs, no
-more data read or written, and requests from upstream drivers are no longer
-accepted.  A given bus or platform may have different requirements though.
+       Devices may also be put into low-power states while the system is
+       running, independently of other power management activity in principle.
+       However, devices are not generally independent of each other (for
+       example, a parent device cannot be suspended unless all of its child
+       devices have been suspended).  Moreover, depending on the bus type the
+       device is on, it may be necessary to carry out some bus-specific
+       operations on the device for this purpose.  Devices put into low power
+       states at run time may require special handling during system-wide power
+       transitions (suspend or hibernation).
+
+       For these reasons not only the device driver itself, but also the
+       appropriate subsystem (bus type, device type or device class) driver and
+       the PM core are involved in runtime power management.  As in the system
+       sleep power management case, they need to collaborate by implementing
+       various role-specific suspend and resume methods, so that the hardware
+       is cleanly powered down and reactivated without data or service loss.
+
+There's not a lot to be said about those low-power states except that they are
+very system-specific, and often device-specific.  Also, that if enough devices
+have been put into low-power states (at runtime), the effect may be very similar
+to entering some system-wide low-power state (system sleep) ... and that
+synergies exist, so that several drivers using runtime PM might put the system
+into a state where even deeper power saving options are available.
+
+Most suspended devices will have quiesced all I/O: no more DMA or IRQs (except
+for wakeup events), no more data read or written, and requests from upstream
+drivers are no longer accepted.  A given bus or platform may have different
+requirements though.
 
 Examples of hardware wakeup events include an alarm from a real time clock,
 network wake-on-LAN packets, keyboard or mouse activity, and media insertion
@@ -60,129 +75,152 @@ or removal (for PCMCIA, MMC/SD, USB, and so on).
 
 Interfaces for Entering System Sleep States
 ===========================================
-Most of the programming interfaces a device driver needs to know about
-relate to that first model:  entering a system-wide low power state,
-rather than just minimizing power consumption by one device.
-
-
-Bus Driver Methods
-------------------
-The core methods to suspend and resume devices reside in struct bus_type.
-These are mostly of interest to people writing infrastructure for busses
-like PCI or USB, or because they define the primitives that device drivers
-may need to apply in domain-specific ways to their devices:
-
-struct bus_type {
-       ...
-       int  (*suspend)(struct device *dev, pm_message_t state);
-       int  (*resume)(struct device *dev);
+There are programming interfaces provided for subsystems (bus type, device type,
+device class) and device drivers to allow them to participate in the power
+management of devices they are concerned with.  These interfaces cover both
+system sleep and runtime power management.
+
+
+Device Power Management Operations
+----------------------------------
+Device power management operations, at the subsystem level as well as at the
+device driver level, are implemented by defining and populating objects of type
+struct dev_pm_ops:
+
+struct dev_pm_ops {
+       int (*prepare)(struct device *dev);
+       void (*complete)(struct device *dev);
+       int (*suspend)(struct device *dev);
+       int (*resume)(struct device *dev);
+       int (*freeze)(struct device *dev);
+       int (*thaw)(struct device *dev);
+       int (*poweroff)(struct device *dev);
+       int (*restore)(struct device *dev);
+       int (*suspend_noirq)(struct device *dev);
+       int (*resume_noirq)(struct device *dev);
+       int (*freeze_noirq)(struct device *dev);
+       int (*thaw_noirq)(struct device *dev);
+       int (*poweroff_noirq)(struct device *dev);
+       int (*restore_noirq)(struct device *dev);
+       int (*runtime_suspend)(struct device *dev);
+       int (*runtime_resume)(struct device *dev);
+       int (*runtime_idle)(struct device *dev);
 };
 
-Bus drivers implement those methods as appropriate for the hardware and
-the drivers using it; PCI works differently from USB, and so on.  Not many
-people write bus drivers; most driver code is a "device driver" that
-builds on top of bus-specific framework code.
+This structure is defined in include/linux/pm.h and the methods included in it
+are also described in that file.  Their roles will be explained in what follows.
+For now, it should be sufficient to remember that the last three methods are
+specific to runtime power management while the remaining ones are used during
+system-wide power transitions.
 
-For more information on these driver calls, see the description later;
-they are called in phases for every device, respecting the parent-child
-sequencing in the driver model tree.  Note that as this is being written,
-only the suspend() and resume() are widely available; not many bus drivers
-leverage all of those phases, or pass them down to lower driver levels.
+There also is a deprecated "old" or "legacy" interface for power management
+operations available at least for some subsystems.  This approach does not use
+struct dev_pm_ops objects and it is suitable only for implementing system sleep
+power management methods.  Therefore it is not described in this document, so
+please refer directly to the source code for more information about it.
 
 
-/sys/devices/.../power/wakeup files
------------------------------------
-All devices in the driver model have two flags to control handling of
-wakeup events, which are hardware signals that can force the device and/or
-system out of a low power state.  These are initialized by bus or device
-driver code using device_init_wakeup(dev,can_wakeup).
+Subsystem-Level Methods
+-----------------------
+The core methods to suspend and resume devices reside in struct dev_pm_ops
+pointed to by the pm member of struct bus_type, struct device_type and
+struct class.  They are mostly of interest to the people writing infrastructure
+for buses, like PCI or USB, or device type and device class drivers.
 
-The "can_wakeup" flag just records whether the device (and its driver) can
-physically support wakeup events.  When that flag is clear, the sysfs
-"wakeup" file is empty, and device_may_wakeup() returns false.
+Bus drivers implement these methods as appropriate for the hardware and the
+drivers using it; PCI works differently from USB, and so on.  Not many people
+write subsystem-level drivers; most driver code is a "device driver" that builds
+on top of bus-specific framework code.
 
-For devices that can issue wakeup events, a separate flag controls whether
-that device should try to use its wakeup mechanism.  The initial value of
-device_may_wakeup() will be true, so that the device's "wakeup" file holds
-the value "enabled".  Userspace can change that to "disabled" so that
-device_may_wakeup() returns false; or change it back to "enabled" (so that
-it returns true again).
+For more information on these driver calls, see the description later;
+they are called in phases for every device, respecting the parent-child
+sequencing in the driver model tree.
 
 
-EXAMPLE:  PCI Device Driver Methods
+/sys/devices/.../power/wakeup files
 -----------------------------------
-PCI framework software calls these methods when the PCI device driver bound
-to a device device has provided them:
-
-struct pci_driver {
-       ...
-       int  (*suspend)(struct pci_device *pdev, pm_message_t state);
-       int  (*suspend_late)(struct pci_device *pdev, pm_message_t state);
+All devices in the driver model have two flags to control handling of wakeup
+events (hardware signals that can force the device and/or system out of a low
+power state).  These flags are initialized by bus or device driver code using
+device_set_wakeup_capable() and device_set_wakeup_enable(), defined in
+include/linux/pm_wakeup.h.
 
-       int  (*resume_early)(struct pci_device *pdev);
-       int  (*resume)(struct pci_device *pdev);
-};
-
-Drivers will implement those methods, and call PCI-specific procedures
-like pci_set_power_state(), pci_enable_wake(), pci_save_state(), and
-pci_restore_state() to manage PCI-specific mechanisms.  (PCI config space
-could be saved during driver probe, if it weren't for the fact that some
-systems rely on userspace tweaking using setpci.)  Devices are suspended
-before their bridges enter low power states, and likewise bridges resume
-before their devices.
-
-
-Upper Layers of Driver Stacks
------------------------------
-Device drivers generally have at least two interfaces, and the methods
-sketched above are the ones which apply to the lower level (nearer PCI, USB,
-or other bus hardware).  The network and block layers are examples of upper
-level interfaces, as is a character device talking to userspace.
-
-Power management requests normally need to flow through those upper levels,
-which often use domain-oriented requests like "blank that screen".  In
-some cases those upper levels will have power management intelligence that
-relates to end-user activity, or other devices that work in cooperation.
-
-When those interfaces are structured using class interfaces, there is a
-standard way to have the upper layer stop issuing requests to a given
-class device (and restart later):
-
-struct class {
-       ...
-       int  (*suspend)(struct device *dev, pm_message_t state);
-       int  (*resume)(struct device *dev);
-};
-
-Those calls are issued in specific phases of the process by which the
-system enters a low power "suspend" state, or resumes from it.
-
-
-Calling Drivers to Enter System Sleep States
-============================================
-When the system enters a low power state, each device's driver is asked
-to suspend the device by putting it into state compatible with the target
+The "can_wakeup" flag just records whether the device (and its driver) can
+physically support wakeup events.  The device_set_wakeup_capable() routine
+affects this flag.  The "should_wakeup" flag controls whether the device should
+try to use its wakeup mechanism.  device_set_wakeup_enable() affects this flag;
+for the most part drivers should not change its value.  The initial value of
+should_wakeup is supposed to be false for the majority of devices; the major
+exceptions are power buttons, keyboards, and Ethernet adapters whose WoL
+(wake-on-LAN) feature has been set up with ethtool.
+
+Whether or not a device is capable of issuing wakeup events is a hardware
+matter, and the kernel is responsible for keeping track of it.  By contrast,
+whether or not a wakeup-capable device should issue wakeup events is a policy
+decision, and it is managed by user space through a sysfs attribute: the
+power/wakeup file.  User space can write the strings "enabled" or "disabled" to
+set or clear the should_wakeup flag, respectively.  Reads from the file will
+return the corresponding string if can_wakeup is true, but if can_wakeup is
+false then reads will return an empty string, to indicate that the device
+doesn't support wakeup events.  (But even though the file appears empty, writes
+will still affect the should_wakeup flag.)
+
+The device_may_wakeup() routine returns true only if both flags are set.
+Drivers should check this routine when putting devices in a low-power state
+during a system sleep transition, to see whether or not to enable the devices'
+wakeup mechanisms.  However for runtime power management, wakeup events should
+be enabled whenever the device and driver both support them, regardless of the
+should_wakeup flag.
+
+
+/sys/devices/.../power/control files
+------------------------------------
+Each device in the driver model has a flag to control whether it is subject to
+runtime power management.  This flag, called runtime_auto, is initialized by the
+bus type (or generally subsystem) code using pm_runtime_allow() or
+pm_runtime_forbid(); the default is to allow runtime power management.
+
+The setting can be adjusted by user space by writing either "on" or "auto" to
+the device's power/control sysfs file.  Writing "auto" calls pm_runtime_allow(),
+setting the flag and allowing the device to be runtime power-managed by its
+driver.  Writing "on" calls pm_runtime_forbid(), clearing the flag, returning
+the device to full power if it was in a low-power state, and preventing the
+device from being runtime power-managed.  User space can check the current value
+of the runtime_auto flag by reading the file.
+
+The device's runtime_auto flag has no effect on the handling of system-wide
+power transitions.  In particular, the device can (and in the majority of cases
+should and will) be put into a low-power state during a system-wide transition
+to a sleep state even though its runtime_auto flag is clear.
+
+For more information about the runtime power management framework, refer to
+Documentation/power/runtime_pm.txt.
+
+
+Calling Drivers to Enter and Leave System Sleep States
+======================================================
+When the system goes into a sleep state, each device's driver is asked to
+suspend the device by putting it into a state compatible with the target
 system state.  That's usually some version of "off", but the details are
 system-specific.  Also, wakeup-enabled devices will usually stay partly
 functional in order to wake the system.
 
-When the system leaves that low power state, the device's driver is asked
-to resume it.  The suspend and resume operations always go together, and
-both are multi-phase operations.
+When the system leaves that low-power state, the device's driver is asked to
+resume it by returning it to full power.  The suspend and resume operations
+always go together, and both are multi-phase operations.
 
-For simple drivers, suspend might quiesce the device using the class code
-and then turn its hardware as "off" as possible with late_suspend.  The
+For simple drivers, suspend might quiesce the device using class code
+and then turn its hardware as "off" as possible during suspend_noirq.  The
 matching resume calls would then completely reinitialize the hardware
 before reactivating its class I/O queues.
 
-More power-aware drivers drivers will use more than one device low power
-state, either at runtime or during system sleep states, and might trigger
-system wakeup events.
+More power-aware drivers might prepare the devices for triggering system wakeup
+events.
 
 
 Call Sequence Guarantees
 ------------------------
-To ensure that bridges and similar links needed to talk to a device are
+To ensure that bridges and similar links needing to talk to a device are
 available when the device is suspended or resumed, the device tree is
 walked in a bottom-up order to suspend devices.  A top-down order is
 used to resume those devices.
@@ -194,67 +232,310 @@ its parent; and can't be removed or suspended after that parent.
 The policy is that the device tree should match hardware bus topology.
 (Or at least the control bus, for devices which use multiple busses.)
 In particular, this means that a device registration may fail if the parent of
-the device is suspending (ie. has been chosen by the PM core as the next
+the device is suspending (i.e. has been chosen by the PM core as the next
 device to suspend) or has already suspended, as well as after all of the other
 devices have been suspended.  Device drivers must be prepared to cope with such
 situations.
 
 
-Suspending Devices
-------------------
-Suspending a given device is done in several phases.  Suspending the
-system always includes every phase, executing calls for every device
-before the next phase begins.  Not all busses or classes support all
-these callbacks; and not all drivers use all the callbacks.
+System Power Management Phases
+------------------------------
+Suspending or resuming the system is done in several phases.  Different phases
+are used for standby or memory sleep states ("suspend-to-RAM") and the
+hibernation state ("suspend-to-disk").  Each phase involves executing callbacks
+for every device before the next phase begins.  Not all busses or classes
+support all these callbacks and not all drivers use all the callbacks.  The
+various phases always run after tasks have been frozen and before they are
+unfrozen.  Furthermore, the *_noirq phases run at a time when IRQ handlers have
+been disabled (except for those marked with the IRQ_WAKEUP flag).
 
-The phases are seen by driver notifications issued in this order:
+Most phases use bus, type, and class callbacks (that is, methods defined in
+dev->bus->pm, dev->type->pm, and dev->class->pm).  The prepare and complete
+phases are exceptions; they use only bus callbacks.  When multiple callbacks
+are used in a phase, they are invoked in the order: <class, type, bus> during
+power-down transitions and in the opposite order during power-up transitions.
+For example, during the suspend phase the PM core invokes
 
-   1   class.suspend(dev, message) is called after tasks are frozen, for
-       devices associated with a class that has such a method.  This
-       method may sleep.
+       dev->class->pm.suspend(dev);
+       dev->type->pm.suspend(dev);
+       dev->bus->pm.suspend(dev);
 
-       Since I/O activity usually comes from such higher layers, this is
-       a good place to quiesce all drivers of a given type (and keep such
-       code out of those drivers).
+before moving on to the next device, whereas during the resume phase the core
+invokes
 
-   2   bus.suspend(dev, message) is called next.  This method may sleep,
-       and is often morphed into a device driver call with bus-specific
-       parameters and/or rules.
+       dev->bus->pm.resume(dev);
+       dev->type->pm.resume(dev);
+       dev->class->pm.resume(dev);
 
-       This call should handle parts of device suspend logic that require
-       sleeping.  It probably does work to quiesce the device which hasn't
-       been abstracted into class.suspend().
+These callbacks may in turn invoke device- or driver-specific methods stored in
+dev->driver->pm, but they don't have to.
 
-The pm_message_t parameter is currently used to refine those semantics
-(described later).
 
-At the end of those phases, drivers should normally have stopped all I/O
-transactions (DMA, IRQs), saved enough state that they can re-initialize
-or restore previous state (as needed by the hardware), and placed the
-device into a low-power state.  On many platforms they will also use
-clk_disable() to gate off one or more clock sources; sometimes they will
-also switch off power supplies, or reduce voltages.  Drivers which have
-runtime PM support may already have performed some or all of the steps
-needed to prepare for the upcoming system sleep state.
+Entering System Suspend
+-----------------------
+When the system goes into the standby or memory sleep state, the phases are:
+
+               prepare, suspend, suspend_noirq.
+
+    1. The prepare phase is meant to prevent races by preventing new devices
+       from being registered; the PM core would never know that all the
+       children of a device had been suspended if new children could be
+       registered at will.  (By contrast, devices may be unregistered at any
+       time.)  Unlike the other suspend-related phases, during the prepare
+       phase the device tree is traversed top-down.
+
+       The prepare phase uses only a bus callback.  After the callback method
+       returns, no new children may be registered below the device.  The method
+       may also prepare the device or driver in some way for the upcoming
+       system power transition, but it should not put the device into a
+       low-power state.
+
+    2. The suspend methods should quiesce the device to stop it from performing
+       I/O.  They also may save the device registers and put it into the
+       appropriate low-power state, depending on the bus type the device is on,
+       and they may enable wakeup events.
+
+    3. The suspend_noirq phase occurs after IRQ handlers have been disabled,
+       which means that the driver's interrupt handler will not be called while
+       the callback method is running.  The methods should save the values of
+       the device's registers that weren't saved previously and finally put the
+       device into the appropriate low-power state.
+
+       The majority of subsystems and device drivers need not implement this
+       callback.  However, bus types allowing devices to share interrupt
+       vectors, like PCI, generally need it; otherwise a driver might encounter
+       an error during the suspend phase by fielding a shared interrupt
+       generated by some other device after its own device had been set to low
+       power.
+
+At the end of these phases, drivers should have stopped all I/O transactions
+(DMA, IRQs), saved enough state that they can re-initialize or restore previous
+state (as needed by the hardware), and placed the device into a low-power state.
+On many platforms they will gate off one or more clock sources; sometimes they
+will also switch off power supplies or reduce voltages.  (Drivers supporting
+runtime PM may already have performed some or all of these steps.)
+
+If device_may_wakeup(dev) returns true, the device should be prepared for
+generating hardware wakeup signals to trigger a system wakeup event when the
+system is in the sleep state.  For example, enable_irq_wake() might identify
+GPIO signals hooked up to a switch or other external hardware, and
+pci_enable_wake() does something similar for the PCI PME signal.
+
+If any of these callbacks returns an error, the system won't enter the desired
+low-power state.  Instead the PM core will unwind its actions by resuming all
+the devices that were suspended.
+
+
+Leaving System Suspend
+----------------------
+When resuming from standby or memory sleep, the phases are:
+
+               resume_noirq, resume, complete.
+
+    1. The resume_noirq callback methods should perform any actions needed
+       before the driver's interrupt handlers are invoked.  This generally
+       means undoing the actions of the suspend_noirq phase.  If the bus type
+       permits devices to share interrupt vectors, like PCI, the method should
+       bring the device and its driver into a state in which the driver can
+       recognize if the device is the source of incoming interrupts, if any,
+       and handle them correctly.
+
+       For example, the PCI bus type's ->pm.resume_noirq() puts the device into
+       the full-power state (D0 in the PCI terminology) and restores the
+       standard configuration registers of the device.  Then it calls the
+       device driver's ->pm.resume_noirq() method to perform device-specific
+       actions.
+
+    2. The resume methods should bring the the device back to its operating
+       state, so that it can perform normal I/O.  This generally involves
+       undoing the actions of the suspend phase.
+
+    3. The complete phase uses only a bus callback.  The method should undo the
+       actions of the prepare phase.  Note, however, that new children may be
+       registered below the device as soon as the resume callbacks occur; it's
+       not necessary to wait until the complete phase.
+
+At the end of these phases, drivers should be as functional as they were before
+suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are
+gated on.  Even if the device was in a low-power state before the system sleep
+because of runtime power management, afterwards it should be back in its
+full-power state.  There are multiple reasons why it's best to do this; they are
+discussed in more detail in Documentation/power/runtime_pm.txt.
 
-When any driver sees that its device_can_wakeup(dev), it should make sure
-to use the relevant hardware signals to trigger a system wakeup event.
-For example, enable_irq_wake() might identify GPIO signals hooked up to
-a switch or other external hardware, and pci_enable_wake() does something
-similar for PCI's PME# signal.
+However, the details here may again be platform-specific.  For example,
+some systems support multiple "run" states, and the mode in effect at
+the end of resume might not be the one which preceded suspension.
+That means availability of certain clocks or power supplies changed,
+which could easily affect how a driver works.
+
+Drivers need to be able to handle hardware which has been reset since the
+suspend methods were called, for example by complete reinitialization.
+This may be the hardest part, and the one most protected by NDA'd documents
+and chip errata.  It's simplest if the hardware state hasn't changed since
+the suspend was carried out, but that can't be guaranteed (in fact, it ususally
+is not the case).
+
+Drivers must also be prepared to notice that the device has been removed
+while the system was powered down, whenever that's physically possible.
+PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses
+where common Linux platforms will see such removal.  Details of how drivers
+will notice and handle such removals are currently bus-specific, and often
+involve a separate thread.
+
+These callbacks may return an error value, but the PM core will ignore such
+errors since there's nothing it can do about them other than printing them in
+the system log.
+
+
+Entering Hibernation
+--------------------
+Hibernating the system is more complicated than putting it into the standby or
+memory sleep state, because it involves creating and saving a system image.
+Therefore there are more phases for hibernation, with a different set of
+callbacks.  These phases always run after tasks have been frozen and memory has
+been freed.
+
+The general procedure for hibernation is to quiesce all devices (freeze), create
+an image of the system memory while everything is stable, reactivate all
+devices (thaw), write the image to permanent storage, and finally shut down the
+system (poweroff).  The phases used to accomplish this are:
+
+       prepare, freeze, freeze_noirq, thaw_noirq, thaw, complete,
+       prepare, poweroff, poweroff_noirq
+
+    1. The prepare phase is discussed in the "Entering System Suspend" section
+       above.
+
+    2. The freeze methods should quiesce the device so that it doesn't generate
+       IRQs or DMA, and they may need to save the values of device registers.
+       However the device does not have to be put in a low-power state, and to
+       save time it's best not to do so.  Also, the device should not be
+       prepared to generate wakeup events.
+
+    3. The freeze_noirq phase is analogous to the suspend_noirq phase discussed
+       above, except again that the device should not be put in a low-power
+       state and should not be allowed to generate wakeup events.
+
+At this point the system image is created.  All devices should be inactive and
+the contents of memory should remain undisturbed while this happens, so that the
+image forms an atomic snapshot of the system state.
+
+    4. The thaw_noirq phase is analogous to the resume_noirq phase discussed
+       above.  The main difference is that its methods can assume the device is
+       in the same state as at the end of the freeze_noirq phase.
+
+    5. The thaw phase is analogous to the resume phase discussed above.  Its
+       methods should bring the device back to an operating state, so that it
+       can be used for saving the image if necessary.
+
+    6. The complete phase is discussed in the "Leaving System Suspend" section
+       above.
+
+At this point the system image is saved, and the devices then need to be
+prepared for the upcoming system shutdown.  This is much like suspending them
+before putting the system into the standby or memory sleep state, and the phases
+are similar.
+
+    7. The prepare phase is discussed above.
+
+    8. The poweroff phase is analogous to the suspend phase.
+
+    9. The poweroff_noirq phase is analogous to the suspend_noirq phase.
+
+The poweroff and poweroff_noirq callbacks should do essentially the same things
+as the suspend and suspend_noirq callbacks.  The only notable difference is that
+they need not store the device register values, because the registers should
+already have been stored during the freeze or freeze_noirq phases.
+
+
+Leaving Hibernation
+-------------------
+Resuming from hibernation is, again, more complicated than resuming from a sleep
+state in which the contents of main memory are preserved, because it requires
+a system image to be loaded into memory and the pre-hibernation memory contents
+to be restored before control can be passed back to the image kernel.
+
+Although in principle, the image might be loaded into memory and the
+pre-hibernation memory contents restored by the boot loader, in practice this
+can't be done because boot loaders aren't smart enough and there is no
+established protocol for passing the necessary information.  So instead, the
+boot loader loads a fresh instance of the kernel, called the boot kernel, into
+memory and passes control to it in the usual way.  Then the boot kernel reads
+the system image, restores the pre-hibernation memory contents, and passes
+control to the image kernel.  Thus two different kernels are involved in
+resuming from hibernation.  In fact, the boot kernel may be completely different
+from the image kernel: a different configuration and even a different version.
+This has important consequences for device drivers and their subsystems.
+
+To be able to load the system image into memory, the boot kernel needs to
+include at least a subset of device drivers allowing it to access the storage
+medium containing the image, although it doesn't need to include all of the
+drivers present in the image kernel.  After the image has been loaded, the
+devices managed by the boot kernel need to be prepared for passing control back
+to the image kernel.  This is very similar to the initial steps involved in
+creating a system image, and it is accomplished in the same way, using prepare,
+freeze, and freeze_noirq phases.  However the devices affected by these phases
+are only those having drivers in the boot kernel; other devices will still be in
+whatever state the boot loader left them.
+
+Should the restoration of the pre-hibernation memory contents fail, the boot
+kernel would go through the "thawing" procedure described above, using the
+thaw_noirq, thaw, and complete phases, and then continue running normally.  This
+happens only rarely.  Most often the pre-hibernation memory contents are
+restored successfully and control is passed to the image kernel, which then
+becomes responsible for bringing the system back to the working state.
+
+To achieve this, the image kernel must restore the devices' pre-hibernation
+functionality.  The operation is much like waking up from the memory sleep
+state, although it involves different phases:
+
+       restore_noirq, restore, complete
+
+    1. The restore_noirq phase is analogous to the resume_noirq phase.
+
+    2. The restore phase is analogous to the resume phase.
+
+    3. The complete phase is discussed above.
+
+The main difference from resume[_noirq] is that restore[_noirq] must assume the
+device has been accessed and reconfigured by the boot loader or the boot kernel.
+Consequently the state of the device may be different from the state remembered
+from the freeze and freeze_noirq phases.  The device may even need to be reset
+and completely re-initialized.  In many cases this difference doesn't matter, so
+the resume[_noirq] and restore[_norq] method pointers can be set to the same
+routines.  Nevertheless, different callback pointers are used in case there is a
+situation where it actually matters.
 
-If a driver (or bus, or class) fails it suspend method, the system won't
-enter the desired low power state; it will resume all the devices it's
-suspended so far.
 
-Note that drivers may need to perform different actions based on the target
-system lowpower/sleep state.  At this writing, there are only platform
-specific APIs through which drivers could determine those target states.
+System Devices
+--------------
+System devices (sysdevs) follow a slightly different API, which can be found in
+
+       include/linux/sysdev.h
+       drivers/base/sys.c
+
+System devices will be suspended with interrupts disabled, and after all other
+devices have been suspended.  On resume, they will be resumed before any other
+devices, and also with interrupts disabled.  These things occur in special
+"sysdev_driver" phases, which affect only system devices.
+
+Thus, after the suspend_noirq (or freeze_noirq or poweroff_noirq) phase, when
+the non-boot CPUs are all offline and IRQs are disabled on the remaining online
+CPU, then a sysdev_driver.suspend phase is carried out, and the system enters a
+sleep state (or a system image is created).  During resume (or after the image
+has been created or loaded) a sysdev_driver.resume phase is carried out, IRQs
+are enabled on the only online CPU, the non-boot CPUs are enabled, and the
+resume_noirq (or thaw_noirq or restore_noirq) phase begins.
+
+Code to actually enter and exit the system-wide low power state sometimes
+involves hardware details that are only known to the boot firmware, and
+may leave a CPU running software (from SRAM or flash memory) that monitors
+the system and manages its wakeup sequence.
 
 
 Device Low Power (suspend) States
 ---------------------------------
-Device low-power states aren't very standard.  One device might only handle
+Device low-power states aren't standard.  One device might only handle
 "on" and "off, while another might support a dozen different versions of
 "on" (how many engines are active?), plus a state that gets back to "on"
 faster than from a full "off".
@@ -265,7 +546,7 @@ PCI device may not perform DMA or issue IRQs, and any wakeup events it
 issues would be issued through the PME# bus signal.  Plus, there are
 several PCI-standard device states, some of which are optional.
 
-In contrast, integrated system-on-chip processors often use irqs as the
+In contrast, integrated system-on-chip processors often use IRQs as the
 wakeup event sources (so drivers would call enable_irq_wake) and might
 be able to treat DMA completion as a wakeup event (sometimes DMA can stay
 active too, it'd only be the CPU and some peripherals that sleep).
@@ -284,120 +565,17 @@ ways; the aforementioned LCD might be active in one product's "standby",
 but a different product using the same SOC might work differently.
 
 
-Meaning of pm_message_t.event
------------------------------
-Parameters to suspend calls include the device affected and a message of
-type pm_message_t, which has one field:  the event.  If driver does not
-recognize the event code, suspend calls may abort the request and return
-a negative errno.  However, most drivers will be fine if they implement
-PM_EVENT_SUSPEND semantics for all messages.
+Power Management Notifiers
+--------------------------
+There are some operations that cannot be carried out by the power management
+callbacks discussed above, because the callbacks occur too late or too early.
+To handle these cases, subsystems and device drivers may register power
+management notifiers that are called before tasks are frozen and after they have
+been thawed.  Generally speaking, the PM notifiers are suitable for performing
+actions that either require user space to be available, or at least won't
+interfere with user space.
 
-The event codes are used to refine the goal of suspending the device, and
-mostly matter when creating or resuming system memory image snapshots, as
-used with suspend-to-disk:
-
-    PM_EVENT_SUSPEND -- quiesce the driver and put hardware into a low-power
-       state.  When used with system sleep states like "suspend-to-RAM" or
-       "standby", the upcoming resume() call will often be able to rely on
-       state kept in hardware, or issue system wakeup events.
-
-    PM_EVENT_HIBERNATE -- Put hardware into a low-power state and enable wakeup
-       events as appropriate.  It is only used with hibernation
-       (suspend-to-disk) and few devices are able to wake up the system from
-       this state; most are completely powered off.
-
-    PM_EVENT_FREEZE -- quiesce the driver, but don't necessarily change into
-       any low power mode.  A system snapshot is about to be taken, often
-       followed by a call to the driver's resume() method.  Neither wakeup
-       events nor DMA are allowed.
-
-    PM_EVENT_PRETHAW -- quiesce the driver, knowing that the upcoming resume()
-       will restore a suspend-to-disk snapshot from a different kernel image.
-       Drivers that are smart enough to look at their hardware state during
-       resume() processing need that state to be correct ... a PRETHAW could
-       be used to invalidate that state (by resetting the device), like a
-       shutdown() invocation would before a kexec() or system halt.  Other
-       drivers might handle this the same way as PM_EVENT_FREEZE.  Neither
-       wakeup events nor DMA are allowed.
-
-To enter "standby" (ACPI S1) or "Suspend to RAM" (STR, ACPI S3) states, or
-the similarly named APM states, only PM_EVENT_SUSPEND is used; the other event
-codes are used for hibernation ("Suspend to Disk", STD, ACPI S4).
-
-There's also PM_EVENT_ON, a value which never appears as a suspend event
-but is sometimes used to record the "not suspended" device state.
-
-
-Resuming Devices
-----------------
-Resuming is done in multiple phases, much like suspending, with all
-devices processing each phase's calls before the next phase begins.
-
-The phases are seen by driver notifications issued in this order:
-
-   1   bus.resume(dev) reverses the effects of bus.suspend().  This may
-       be morphed into a device driver call with bus-specific parameters;
-       implementations may sleep.
-
-   2   class.resume(dev) is called for devices associated with a class
-       that has such a method.  Implementations may sleep.
-
-       This reverses the effects of class.suspend(), and would usually
-       reactivate the device's I/O queue.
-
-At the end of those phases, drivers should normally be as functional as
-they were before suspending:  I/O can be performed using DMA and IRQs, and
-the relevant clocks are gated on.  The device need not be "fully on"; it
-might be in a runtime lowpower/suspend state that acts as if it were.
-
-However, the details here may again be platform-specific.  For example,
-some systems support multiple "run" states, and the mode in effect at
-the end of resume() might not be the one which preceded suspension.
-That means availability of certain clocks or power supplies changed,
-which could easily affect how a driver works.
-
-
-Drivers need to be able to handle hardware which has been reset since the
-suspend methods were called, for example by complete reinitialization.
-This may be the hardest part, and the one most protected by NDA'd documents
-and chip errata.  It's simplest if the hardware state hasn't changed since
-the suspend() was called, but that can't always be guaranteed.
-
-Drivers must also be prepared to notice that the device has been removed
-while the system was powered off, whenever that's physically possible.
-PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses
-where common Linux platforms will see such removal.  Details of how drivers
-will notice and handle such removals are currently bus-specific, and often
-involve a separate thread.
-
-
-Note that the bus-specific runtime PM wakeup mechanism can exist, and might
-be defined to share some of the same driver code as for system wakeup.  For
-example, a bus-specific device driver's resume() method might be used there,
-so it wouldn't only be called from bus.resume() during system-wide wakeup.
-See bus-specific information about how runtime wakeup events are handled.
-
-
-System Devices
---------------
-System devices follow a slightly different API, which can be found in
-
-       include/linux/sysdev.h
-       drivers/base/sys.c
-
-System devices will only be suspended with interrupts disabled, and after
-all other devices have been suspended.  On resume, they will be resumed
-before any other devices, and also with interrupts disabled.
-
-That is, IRQs are disabled, the suspend_late() phase begins, then the
-sysdev_driver.suspend() phase, and the system enters a sleep state.  Then
-the sysdev_driver.resume() phase begins, followed by the resume_early()
-phase, after which IRQs are enabled.
-
-Code to actually enter and exit the system-wide low power state sometimes
-involves hardware details that are only known to the boot firmware, and
-may leave a CPU running software (from SRAM or flash memory) that monitors
-the system and manages its wakeup sequence.
+For details refer to Documentation/power/notifiers.txt.
 
 
 Runtime Power Management
@@ -407,82 +585,23 @@ running. This feature is useful for devices that are not being used, and
 can offer significant power savings on a running system.  These devices
 often support a range of runtime power states, which might use names such
 as "off", "sleep", "idle", "active", and so on.  Those states will in some
-cases (like PCI) be partially constrained by a bus the device uses, and will
+cases (like PCI) be partially constrained by the bus the device uses, and will
 usually include hardware states that are also used in system sleep states.
 
-However, note that if a driver puts a device into a runtime low power state
-and the system then goes into a system-wide sleep state, it normally ought
-to resume into that runtime low power state rather than "full on".  Such
-distinctions would be part of the driver-internal state machine for that
-hardware; the whole point of runtime power management is to be sure that
-drivers are decoupled in that way from the state machine governing phases
-of the system-wide power/sleep state transitions.
-
-
-Power Saving Techniques
------------------------
-Normally runtime power management is handled by the drivers without specific
-userspace or kernel intervention, by device-aware use of techniques like:
-
-    Using information provided by other system layers
-       - stay deeply "off" except between open() and close()
-       - if transceiver/PHY indicates "nobody connected", stay "off"
-       - application protocols may include power commands or hints
-
-    Using fewer CPU cycles
-       - using DMA instead of PIO
-       - removing timers, or making them lower frequency
-       - shortening "hot" code paths
-       - eliminating cache misses
-       - (sometimes) offloading work to device firmware
-
-    Reducing other resource costs
-       - gating off unused clocks in software (or hardware)
-       - switching off unused power supplies
-       - eliminating (or delaying/merging) IRQs
-       - tuning DMA to use word and/or burst modes
-
-    Using device-specific low power states
-       - using lower voltages
-       - avoiding needless DMA transfers
-
-Read your hardware documentation carefully to see the opportunities that
-may be available.  If you can, measure the actual power usage and check
-it against the budget established for your project.
-
-
-Examples:  USB hosts, system timer, system CPU
-----------------------------------------------
-USB host controllers make interesting, if complex, examples.  In many cases
-these have no work to do:  no USB devices are connected, or all of them are
-in the USB "suspend" state.  Linux host controller drivers can then disable
-periodic DMA transfers that would otherwise be a constant power drain on the
-memory subsystem, and enter a suspend state.  In power-aware controllers,
-entering that suspend state may disable the clock used with USB signaling,
-saving a certain amount of power.
-
-The controller will be woken from that state (with an IRQ) by changes to the
-signal state on the data lines of a given port, for example by an existing
-peripheral requesting "remote wakeup" or by plugging a new peripheral.  The
-same wakeup mechanism usually works from "standby" sleep states, and on some
-systems also from "suspend to RAM" (or even "suspend to disk") states.
-(Except that ACPI may be involved instead of normal IRQs, on some hardware.)
-
-System devices like timers and CPUs may have special roles in the platform
-power management scheme.  For example, system timers using a "dynamic tick"
-approach don't just save CPU cycles (by eliminating needless timer IRQs),
-but they may also open the door to using lower power CPU "idle" states that
-cost more than a jiffie to enter and exit.  On x86 systems these are states
-like "C3"; note that periodic DMA transfers from a USB host controller will
-also prevent entry to a C3 state, much like a periodic timer IRQ.
-
-That kind of runtime mechanism interaction is common.  "System On Chip" (SOC)
-processors often have low power idle modes that can't be entered unless
-certain medium-speed clocks (often 12 or 48 MHz) are gated off.  When the
-drivers gate those clocks effectively, then the system idle task may be able
-to use the lower power idle modes and thereby increase battery life.
-
-If the CPU can have a "cpufreq" driver, there also may be opportunities
-to shift to lower voltage settings and reduce the power cost of executing
-a given number of instructions.  (Without voltage adjustment, it's rare
-for cpufreq to save much power; the cost-per-instruction must go down.)
+A system-wide power transition can be started while some devices are in low
+power states due to runtime power management.  The system sleep PM callbacks
+should recognize such situations and react to them appropriately, but the
+necessary actions are subsystem-specific.
+
+In some cases the decision may be made at the subsystem level while in other
+cases the device driver may be left to decide.  In some cases it may be
+desirable to leave a suspended device in that state during a system-wide power
+transition, but in other cases the device must be put back into the full-power
+state temporarily, for example so that its system wakeup capability can be
+disabled.  This all depends on the hardware and the design of the subsystem and
+device driver in question.
+
+During system-wide resume from a sleep state it's best to put devices into the
+full-power state, as explained in Documentation/power/runtime_pm.txt.  Refer to
+that document for more information regarding this particular issue as well as
+for information on the device runtime power management framework in general.
index c40866e..bfed898 100644 (file)
@@ -18,44 +18,46 @@ and pm_qos_params.h.  This is done because having the available parameters
 being runtime configurable or changeable from a driver was seen as too easy to
 abuse.
 
-For each parameter a list of performance requirements is maintained along with
+For each parameter a list of performance requests is maintained along with
 an aggregated target value.  The aggregated target value is updated with
-changes to the requirement list or elements of the list.  Typically the
-aggregated target value is simply the max or min of the requirement values held
+changes to the request list or elements of the list.  Typically the
+aggregated target value is simply the max or min of the request values held
 in the parameter list elements.
 
 From kernel mode the use of this interface is simple:
-pm_qos_add_requirement(param_id, name, target_value):
-Will insert a named element in the list for that identified PM_QOS parameter
-with the target value.  Upon change to this list the new target is recomputed
-and any registered notifiers are called only if the target value is now
-different.
 
-pm_qos_update_requirement(param_id, name, new_target_value):
-Will search the list identified by the param_id for the named list element and
-then update its target value, calling the notification tree if the aggregated
-target is changed.  with that name is already registered.
+handle = pm_qos_add_request(param_class, target_value):
+Will insert an element into the list for that identified PM_QOS class with the
+target value.  Upon change to this list the new target is recomputed and any
+registered notifiers are called only if the target value is now different.
+Clients of pm_qos need to save the returned handle.
 
-pm_qos_remove_requirement(param_id, name):
-Will search the identified list for the named element and remove it, after
-removal it will update the aggregate target and call the notification tree if
-the target was changed as a result of removing the named requirement.
+void pm_qos_update_request(handle, new_target_value):
+Will update the list element pointed to by the handle with the new target value
+and recompute the new aggregated target, calling the notification tree if the
+target is changed.
+
+void pm_qos_remove_request(handle):
+Will remove the element.  After removal it will update the aggregate target and
+call the notification tree if the target was changed as a result of removing
+the request.
 
 
 From user mode:
-Only processes can register a pm_qos requirement.  To provide for automatic
-cleanup for process the interface requires the process to register its
-parameter requirements in the following way:
+Only processes can register a pm_qos request.  To provide for automatic
+cleanup of a process, the interface requires the process to register its
+parameter requests in the following way:
 
 To register the default pm_qos target for the specific parameter, the process
 must open one of /dev/[cpu_dma_latency, network_latency, network_throughput]
 
 As long as the device node is held open that process has a registered
-requirement on the parameter.  The name of the requirement is "process_<PID>"
-derived from the current->pid from within the open system call.
+request on the parameter.
 
-To change the requested target value the process needs to write a s32 value to
-the open device node.  This translates to a pm_qos_update_requirement call.
+To change the requested target value the process needs to write an s32 value to
+the open device node.  Alternatively the user mode program could write a hex
+string for the value using 10 char long format e.g. "0x12345678".  This
+translates to a pm_qos_update_request call.
 
 To remove the user mode request for a target value simply close the device
 node.
index cdebb51..55c4175 100644 (file)
@@ -8,11 +8,11 @@ Please see overview.txt for a description of the terms used in this text.
 1. Consumer Regulator Access (static & dynamic drivers)
 =======================================================
 
-A consumer driver can get access to it's supply regulator by calling :-
+A consumer driver can get access to its supply regulator by calling :-
 
 regulator = regulator_get(dev, "Vcc");
 
-The consumer passes in it's struct device pointer and power supply ID. The core
+The consumer passes in its struct device pointer and power supply ID. The core
 then finds the correct regulator by consulting a machine specific lookup table.
 If the lookup is successful then this call will return a pointer to the struct
 regulator that supplies this consumer.
@@ -34,7 +34,7 @@ usually be called in your device drivers probe() and remove() respectively.
 2. Regulator Output Enable & Disable (static & dynamic drivers)
 ====================================================================
 
-A consumer can enable it's power supply by calling:-
+A consumer can enable its power supply by calling:-
 
 int regulator_enable(regulator);
 
@@ -49,7 +49,7 @@ int regulator_is_enabled(regulator);
 This will return > zero when the regulator is enabled.
 
 
-A consumer can disable it's supply when no longer needed by calling :-
+A consumer can disable its supply when no longer needed by calling :-
 
 int regulator_disable(regulator);
 
@@ -140,7 +140,7 @@ by calling :-
 int regulator_set_optimum_mode(struct regulator *regulator, int load_uA);
 
 This will cause the core to recalculate the total load on the regulator (based
-on all it's consumers) and change operating mode (if necessary and permitted)
+on all its consumers) and change operating mode (if necessary and permitted)
 to best match the current operating load.
 
 The load_uA value can be determined from the consumers datasheet. e.g.most
index 63728fe..bdec39b 100644 (file)
@@ -52,7 +52,7 @@ static struct regulator_init_data regulator1_data = {
 };
 
 Regulator-1 supplies power to Regulator-2. This relationship must be registered
-with the core so that Regulator-1 is also enabled when Consumer A enables it's
+with the core so that Regulator-1 is also enabled when Consumer A enables its
 supply (Regulator-2). The supply regulator is set by the supply_regulator_dev
 field below:-
 
index ffd185b..9363e05 100644 (file)
@@ -35,16 +35,16 @@ Some terms used in this document:-
   o Consumer     - Electronic device that is supplied power by a regulator.
                    Consumers can be classified into two types:-
 
-                   Static: consumer does not change it's supply voltage or
+                   Static: consumer does not change its supply voltage or
                    current limit. It only needs to enable or disable it's
-                   power supply. It's supply voltage is set by the hardware,
+                   power supply. Its supply voltage is set by the hardware,
                    bootloader, firmware or kernel board initialisation code.
 
                    Dynamic: consumer needs to change it's supply voltage or
                    current limit to meet operation demands.
 
 
-  o Power Domain - Electronic circuit that is supplied it's input power by the
+  o Power Domain - Electronic circuit that is supplied its input power by the
                    output power of a regulator, switch or by another power
                    domain.
 
index b967cd9..81680f9 100644 (file)
@@ -24,6 +24,10 @@ assumed to be in the resume mode.  The device cannot be open for simultaneous
 reading and writing.  It is also impossible to have the device open more than
 once at a time.
 
+Even opening the device has side effects. Data structures are
+allocated, and PM_HIBERNATION_PREPARE / PM_RESTORE_PREPARE chains are
+called.
+
 The ioctl() commands recognized by the device are:
 
 SNAPSHOT_FREEZE - freeze user space processes (the current process is
index 79f533f..46d2210 100644 (file)
@@ -1289,7 +1289,7 @@ link between a device node and its interrupt parent in
 the interrupt tree.  The value of interrupt-parent is the
 phandle of the parent node.
 
-If the interrupt-parent property is not defined for a node, it's
+If the interrupt-parent property is not defined for a node, its
 interrupt parent is assumed to be an ancestor in the node's
 _device tree_ hierarchy.
 
index ea68046..299d092 100644 (file)
@@ -11,7 +11,7 @@
    control how the core is synthesized.  Historically, the EDK tool would
    extract the device parameters relevant to device drivers and copy them
    into an 'xparameters.h' in the form of #define symbols.  This tells the
-   device drivers how the IP cores are configured, but it requres the kernel
+   device drivers how the IP cores are configured, but it requires the kernel
    to be recompiled every time the FPGA bitstream is resynthesized.
 
    The new approach is to export the parameters into the device tree and
index c4682b9..ad34020 100644 (file)
@@ -19,7 +19,7 @@ dump offers several strong, practical advantages:
    immediately available to the system for normal use.
 -- After the dump is completed, no further reboots are
    required; the system will be fully usable, and running
-   in it's normal, production mode on it normal kernel.
+   in its normal, production mode on its normal kernel.
 
 The above can only be accomplished by coordination with,
 and assistance from the hypervisor. The procedure is
index aae8355..221f38b 100644 (file)
@@ -190,3 +190,61 @@ Example:
   for (node = rb_first(&mytree); node; node = rb_next(node))
        printk("key=%s\n", rb_entry(node, struct mytype, node)->keystring);
 
+Support for Augmented rbtrees
+-----------------------------
+
+Augmented rbtree is an rbtree with "some" additional data stored in each node.
+This data can be used to augment some new functionality to rbtree.
+Augmented rbtree is an optional feature built on top of basic rbtree
+infrastructure. rbtree user who wants this feature will have an augment
+callback function in rb_root initialized.
+
+This callback function will be called from rbtree core routines whenever
+a node has a change in one or both of its children. It is the responsibility
+of the callback function to recalculate the additional data that is in the
+rb node using new children information. Note that if this new additional
+data affects the parent node's additional data, then callback function has
+to handle it and do the recursive updates.
+
+
+Interval tree is an example of augmented rb tree. Reference -
+"Introduction to Algorithms" by Cormen, Leiserson, Rivest and Stein.
+More details about interval trees:
+
+Classical rbtree has a single key and it cannot be directly used to store
+interval ranges like [lo:hi] and do a quick lookup for any overlap with a new
+lo:hi or to find whether there is an exact match for a new lo:hi.
+
+However, rbtree can be augmented to store such interval ranges in a structured
+way making it possible to do efficient lookup and exact match.
+
+This "extra information" stored in each node is the maximum hi
+(max_hi) value among all the nodes that are its descendents. This
+information can be maintained at each node just be looking at the node
+and its immediate children. And this will be used in O(log n) lookup
+for lowest match (lowest start address among all possible matches)
+with something like:
+
+find_lowest_match(lo, hi, node)
+{
+       lowest_match = NULL;
+       while (node) {
+               if (max_hi(node->left) > lo) {
+                       // Lowest overlap if any must be on left side
+                       node = node->left;
+               } else if (overlap(lo, hi, node)) {
+                       lowest_match = node;
+                       break;
+               } else if (lo > node->lo) {
+                       // Lowest overlap if any must be on right side
+                       node = node->right;
+               } else {
+                       break;
+               }
+       }
+       return lowest_match;
+}
+
+Finding exact match will be to first find lowest match and then to follow
+successor nodes looking for exact match, until the start of a node is beyond
+the hi value we are looking for.
index 4b736d2..8df0b78 100644 (file)
@@ -657,7 +657,7 @@ here.
 
 The waiter structure has a "task" field that points to the task that is blocked
 on the mutex.  This field can be NULL the first time it goes through the loop
-or if the task is a pending owner and had it's mutex stolen.  If the "task"
+or if the task is a pending owner and had its mutex stolen.  If the "task"
 field is NULL then we need to set up the accounting for it.
 
 Task blocks on mutex
index 6f33593..8239ebb 100644 (file)
@@ -211,7 +211,7 @@ provide fair CPU time to each such task group.  For example, it may be
 desirable to first provide fair CPU time to each user on the system and then to
 each task belonging to a user.
 
-CONFIG_GROUP_SCHED strives to achieve exactly that.  It lets tasks to be
+CONFIG_CGROUP_SCHED strives to achieve exactly that.  It lets tasks to be
 grouped and divides CPU time fairly among such groups.
 
 CONFIG_RT_GROUP_SCHED permits to group real-time (i.e., SCHED_FIFO and
@@ -220,38 +220,11 @@ SCHED_RR) tasks.
 CONFIG_FAIR_GROUP_SCHED permits to group CFS (i.e., SCHED_NORMAL and
 SCHED_BATCH) tasks.
 
-At present, there are two (mutually exclusive) mechanisms to group tasks for
-CPU bandwidth control purposes:
-
- - Based on user id (CONFIG_USER_SCHED)
-
-   With this option, tasks are grouped according to their user id.
-
- - Based on "cgroup" pseudo filesystem (CONFIG_CGROUP_SCHED)
-
-   This options needs CONFIG_CGROUPS to be defined, and lets the administrator
+   These options need CONFIG_CGROUPS to be defined, and let the administrator
    create arbitrary groups of tasks, using the "cgroup" pseudo filesystem.  See
    Documentation/cgroups/cgroups.txt for more information about this filesystem.
 
-Only one of these options to group tasks can be chosen and not both.
-
-When CONFIG_USER_SCHED is defined, a directory is created in sysfs for each new
-user and a "cpu_share" file is added in that directory.
-
-       # cd /sys/kernel/uids
-       # cat 512/cpu_share             # Display user 512's CPU share
-       1024
-       # echo 2048 > 512/cpu_share     # Modify user 512's CPU share
-       # cat 512/cpu_share             # Display user 512's CPU share
-       2048
-       #
-
-CPU bandwidth between two users is divided in the ratio of their CPU shares.
-For example: if you would like user "root" to get twice the bandwidth of user
-"guest," then set the cpu_share for both the users such that "root"'s cpu_share
-is twice "guest"'s cpu_share.
-
-When CONFIG_CGROUP_SCHED is defined, a "cpu.shares" file is created for each
+When CONFIG_FAIR_GROUP_SCHED is defined, a "cpu.shares" file is created for each
 group created using the pseudo filesystem.  See example steps below to create
 task groups and modify their CPU share using the "cgroups" pseudo filesystem.
 
@@ -273,24 +246,3 @@ task groups and modify their CPU share using the "cgroups" pseudo filesystem.
 
        # #Launch gmplayer (or your favourite movie player)
        # echo <movie_player_pid> > multimedia/tasks
-
-8. Implementation note: user namespaces
-
-User namespaces are intended to be hierarchical.  But they are currently
-only partially implemented.  Each of those has ramifications for CFS.
-
-First, since user namespaces are hierarchical, the /sys/kernel/uids
-presentation is inadequate.  Eventually we will likely want to use sysfs
-tagging to provide private views of /sys/kernel/uids within each user
-namespace.
-
-Second, the hierarchical nature is intended to support completely
-unprivileged use of user namespaces.  So if using user groups, then
-we want the users in a user namespace to be children of the user
-who created it.
-
-That is currently unimplemented.  So instead, every user in a new
-user namespace will receive 1024 shares just like any user in the
-initial user namespace.  Note that at the moment creation of a new
-user namespace requires each of CAP_SYS_ADMIN, CAP_SETUID, and
-CAP_SETGID.
index 86eabe6..605b0d4 100644 (file)
@@ -126,23 +126,12 @@ priority!
 2.3 Basis for grouping tasks
 ----------------------------
 
-There are two compile-time settings for allocating CPU bandwidth. These are
-configured using the "Basis for grouping tasks" multiple choice menu under
-General setup > Group CPU Scheduler:
-
-a. CONFIG_USER_SCHED (aka "Basis for grouping tasks" =  "user id")
-
-This lets you use the virtual files under
-"/sys/kernel/uids/<uid>/cpu_rt_runtime_us" to control he CPU time reserved for
-each user .
-
-The other option is:
-
-.o CONFIG_CGROUP_SCHED (aka "Basis for grouping tasks" = "Control groups")
+Enabling CONFIG_RT_GROUP_SCHED lets you explicitly allocate real
+CPU bandwidth to task groups.
 
 This uses the /cgroup virtual file system and
 "/cgroup/<cgroup>/cpu.rt_runtime_us" to control the CPU time reserved for each
-control group instead.
+control group.
 
 For more information on working with control groups, you should read
 Documentation/cgroups/cgroups.txt as well.
@@ -161,8 +150,7 @@ For now, this can be simplified to just the following (but see Future plans):
 ===============
 
 There is work in progress to make the scheduling period for each group
-("/sys/kernel/uids/<uid>/cpu_rt_period_us" or
-"/cgroup/<cgroup>/cpu.rt_period_us" respectively) configurable as well.
+("/cgroup/<cgroup>/cpu.rt_period_us") configurable as well.
 
 The constraint on the period is that a subgroup must have a smaller or
 equal period to its parent. But realistically its not very useful _yet_
index 2ffc114..e759e92 100644 (file)
@@ -707,7 +707,7 @@ Changes from 20040920 to 20041018
        * Integrate patches from Christoph Hellwig: two new helpers common
          to lpfc_sli_resume_iocb and lpfc_sli_issue_iocb - singificant
          cleanup of those two functions - the unused SLI_IOCB_USE_TXQ is
-         gone - lpfc_sli_issue_iocb_wait loses it's flags argument
+         gone - lpfc_sli_issue_iocb_wait loses its flags argument
          totally.
        * Fix in lpfc_sli.c: we can not store a 5 bit value in a 4-bit
          field.
@@ -1028,7 +1028,7 @@ Changes from 20040614 to 20040709
        * Remove the need for buf_tmo.
        * Changed ULP_BDE64 to struct ulp_bde64.
        * Changed ULP_BDE to struct ulp_bde.
-       * Cleanup lpfc_os_return_scsi_cmd() and it's call path.
+       * Cleanup lpfc_os_return_scsi_cmd() and its call path.
        * Removed lpfc_no_device_delay.
        * Consolidating lpfc_hba_put_event() into lpfc_put_event().
        * Removed following attributes and their functionality:
index d5acaa3..1540a92 100644 (file)
@@ -71,7 +71,7 @@ peters@mylex.com
 
 Ever since its introduction last October, the BusLogic FlashPoint LT has
 been problematic for members of the Linux community, in that no Linux
-drivers have been available for this new Ultra SCSI product.  Despite it's
+drivers have been available for this new Ultra SCSI product.  Despite its
 officially being positioned as a desktop workstation product, and not being
 particularly well suited for a high performance multitasking operating
 system like Linux, the FlashPoint LT has been touted by computer system
index e8ae623..1d7af9f 100644 (file)
@@ -12,7 +12,7 @@ The 3180 does not.  Otherwise, they are identical.
 The DTC3x80 does not support DMA but it does have Pseudo-DMA which is
 supported by the driver.
 
-It's DTC406 scsi chip is supposedly compatible with the NCR 53C400.
+Its DTC406 scsi chip is supposedly compatible with the NCR 53C400.
 It is memory mapped, uses an IRQ, but no dma or io-port.  There is
 internal DMA, between SCSI bus and an on-chip 128-byte buffer.  Double
 buffering is done automagically by the chip.  Data is transferred
index 08e2b4d..cda5f8f 100644 (file)
@@ -1479,7 +1479,7 @@ Wide16 SCSI.
 Enabling serial NVRAM support enables detection of the serial NVRAM included
 on Symbios and some Symbios compatible host adaptors, and Tekram boards. The 
 serial NVRAM is used by Symbios and Tekram to hold set up parameters for the 
-host adaptor and it's attached drives.
+host adaptor and its attached drives.
 
 The Symbios NVRAM also holds data on the boot order of host adaptors in a
 system with more than one host adaptor. This enables the order of scanning
index f536907..2b21890 100644 (file)
@@ -40,7 +40,7 @@ behavior looks very much the same as st to the userspace applications.
 
 History
 -------
-In the first place, osst shared it's identity very much with st. That meant
+In the first place, osst shared its identity very much with st. That meant
 that it used the same kernel structures and the same device node as st.
 So you could only have either of them being present in the kernel. This has
 been fixed by registering an own device, now.
index aec6549..e00192d 100644 (file)
@@ -70,7 +70,7 @@ Overview:
     up to an administrative entity controlling the vport. For example,
     if vports are to be associated with virtual machines, a XEN mgmt
     utility would be responsible for creating wwpn/wwnn's for the vport,
-    using it's own naming authority and OUI. (Note: it already does this
+    using its own naming authority and OUI. (Note: it already does this
     for virtual MAC addresses).
 
 
@@ -81,7 +81,7 @@ Device Trees and Vport Objects:
   with rports and scsi target objects underneath it. Currently the FC
   transport creates the vport object and places it under the scsi_host
   object corresponding to the physical adapter.  The LLDD will allocate
-  a new scsi_host for the vport and link it's object under the vport.
+  a new scsi_host for the vport and link its object under the vport.
   The remainder of the tree under the vports scsi_host is the same
   as the non-NPIV case. The transport is written currently to easily
   allow the parent of the vport to be something other than the scsi_host.
index eb9a7b9..6f63b79 100644 (file)
@@ -687,7 +687,7 @@ maintain the driver code.
 Enabling serial NVRAM support enables detection of the serial NVRAM included
 on Symbios and some Symbios compatible host adaptors, and Tekram boards. The 
 serial NVRAM is used by Symbios and Tekram to hold set up parameters for the 
-host adaptor and it's attached drives.
+host adaptor and its attached drives.
 
 The Symbios NVRAM also holds data on the boot order of host adaptors in a
 system with more than one host adaptor.  This information is no longer used
index bfcbbf8..2075bbb 100644 (file)
@@ -227,6 +227,16 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
 
     The power-management is supported.
 
+  Module snd-asihpi
+  -----------------
+
+    Module for AudioScience ASI soundcards
+
+    enable_hpi_hwdep   - enable HPI hwdep for AudioScience soundcard
+
+    This module supports multiple cards.
+    The driver requires the firmware loader support on kernel.
+
   Module snd-atiixp
   -----------------
 
@@ -622,28 +632,23 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
     
     The power-management is supported.
 
-  Module snd-es968
-  ----------------
-
-    Module for sound cards based on ESS ES968 chip (PnP only).
-
-    This module supports multiple cards, PnP and autoprobe.
-    
-    The power-management is supported.
-
   Module snd-es1688
   -----------------
 
     Module for ESS AudioDrive ES-1688 and ES-688 sound cards.
 
-    port       - port # for ES-1688 chip (0x220,0x240,0x260)
-    fm_port    - port # for OPL3 (option; share the same port as default)
+    isapnp     - ISA PnP detection - 0 = disable, 1 = enable (default)
     mpu_port   - port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable (default)
-    irq                - IRQ # for ES-1688 chip (5,7,9,10)
     mpu_irq    - IRQ # for MPU-401 port (5,7,9,10)
+    fm_port    - port # for OPL3 (option; share the same port as default)
+
+    with isapnp=0, the following additional options are available:
+    port       - port # for ES-1688 chip (0x220,0x240,0x260)
+    irq                - IRQ # for ES-1688 chip (5,7,9,10)
     dma8       - DMA # for ES-1688 chip (0,1,3)
 
-    This module supports multiple cards and autoprobe (without MPU-401 port).
+    This module supports multiple cards and autoprobe (without MPU-401 port)
+    and PnP with the ES968 chip.
 
   Module snd-es18xx
   -----------------
index 98d14cb..bdafdbd 100644 (file)
@@ -204,7 +204,6 @@ generic parser regardless of the codec.  Usually the codec-specific
 parser is much better than the generic parser (as now).  Thus this
 option is more about the debugging purpose.
 
-
 Speaker and Headphone Output
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 One of the most frequent (and obvious) bugs with HD-audio is the
@@ -600,6 +599,9 @@ probing, the proc file is available, so you can get the raw codec
 information before modified by the driver.  Of course, the driver
 isn't usable with `probe_only=1`.  But you can continue the
 configuration via hwdep sysfs file if hda-reconfig option is enabled.
+Using `probe_only` mask 2 skips the reset of HDA codecs (use
+`probe_only=3` as module option). The hwdep interface can be used
+to determine the BIOS codec initialization.
 
 
 hda-verb
index 9ac842b..05bf5a0 100644 (file)
@@ -188,8 +188,8 @@ The WM8731 output mixer has 3 inputs (sources)
  3. Mic Sidetone Input
 
 Each input in this example has a kcontrol associated with it (defined in example
-above) and is connected to the output mixer via it's kcontrol name. We can now
-connect the destination widget (wrt audio signal) with it's source widgets.
+above) and is connected to the output mixer via its kcontrol name. We can now
+connect the destination widget (wrt audio signal) with its source widgets.
 
        /* output mixer */
        {"Output Mixer", "Line Bypass Switch", "Line Input"},
index bab7711..2524c75 100644 (file)
@@ -67,7 +67,7 @@ static struct snd_soc_dai_link corgi_dai = {
        .ops = &corgi_ops,
 };
 
-struct snd_soc_card then sets up the machine with it's DAIs. e.g.
+struct snd_soc_card then sets up the machine with its DAIs. e.g.
 
 /* corgi audio machine driver */
 static struct snd_soc_card snd_soc_corgi = {
index 1e4c6d3..138ac88 100644 (file)
@@ -33,7 +33,7 @@ features :-
     and machines.
 
   * Easy I2S/PCM audio interface setup between codec and SoC. Each SoC
-    interface and codec registers it's audio interface capabilities with the
+    interface and codec registers its audio interface capabilities with the
     core and are subsequently matched and configured when the application
     hardware parameters are known.
 
index 34c76a5..9b659c7 100644 (file)
@@ -54,12 +54,12 @@ Getting sparse
 ~~~~~~~~~~~~~~
 
 You can get latest released versions from the Sparse homepage at
-http://www.kernel.org/pub/linux/kernel/people/josh/sparse/
+https://sparse.wiki.kernel.org/index.php/Main_Page
 
 Alternatively, you can get snapshots of the latest development version
 of sparse using git to clone..
 
-        git://git.kernel.org/pub/scm/linux/kernel/git/josh/sparse.git
+        git://git.kernel.org/pub/scm/devel/sparse/sparse.git
 
 DaveJ has hourly generated tarballs of the git tree available at..
 
index 5d8bc2c..c1a1fd6 100644 (file)
@@ -125,7 +125,7 @@ versions of the sysfs interface.
 - Block
   The converted block subsystem at /sys/class/block or
   /sys/subsystem/block will contain the links for disks and partitions
-  at the same level, never in a hierarchy. Assuming the block subsytem to
+  at the same level, never in a hierarchy. Assuming the block subsystem to
   contain only disks and not partition devices in the same flat list is
   a bug in the application.
 
index 02ac6ed..09bd8e9 100644 (file)
@@ -90,7 +90,8 @@ In order to facilitate early boot debugging, use boot option:
 
        trace_event=[event-list]
 
-The format of this boot option is the same as described in section 2.1.
+event-list is a comma separated list of events. See section 2.1 for event
+format.
 
 3. Defining an event-enabled tracepoint
 =======================================
@@ -238,7 +239,7 @@ subsystem's filter file.
 
 For convenience, filters for every event in a subsystem can be set or
 cleared as a group by writing a filter expression into the filter file
-at the root of the subsytem.  Note however, that if a filter for any
+at the root of the subsystem.  Note however, that if a filter for any
 event within the subsystem lacks a field specified in the subsystem
 filter, or if the filter can't be applied for any other reason, the
 filter for that event will retain its previous setting.  This can
@@ -250,7 +251,7 @@ fields can be guaranteed to propagate successfully to all events.
 Here are a few subsystem filter examples that also illustrate the
 above points:
 
-Clear the filters on all events in the sched subsytem:
+Clear the filters on all events in the sched subsystem:
 
 # cd /sys/kernel/debug/tracing/events/sched
 # echo 0 > filter
@@ -260,7 +261,7 @@ none
 none
 
 Set a filter using only common fields for all events in the sched
-subsytem (all events end up with the same filter):
+subsystem (all events end up with the same filter):
 
 # cd /sys/kernel/debug/tracing/events/sched
 # echo common_pid == 0 > filter
@@ -270,7 +271,7 @@ common_pid == 0
 common_pid == 0
 
 Attempt to set a filter using a non-common field for all events in the
-sched subsytem (all events but those that have a prev_pid field retain
+sched subsystem (all events but those that have a prev_pid field retain
 their old filters):
 
 # cd /sys/kernel/debug/tracing/events/sched
index 03485bf..557c1ed 100644 (file)
@@ -155,6 +155,9 @@ of ftrace. Here is a list of some of the key files:
        to be traced. Echoing names of functions into this file
        will limit the trace to only those functions.
 
+       This interface also allows for commands to be used. See the
+       "Filter commands" section for more details.
+
   set_ftrace_notrace:
 
        This has an effect opposite to that of
@@ -1337,12 +1340,14 @@ ftrace_dump_on_oops must be set. To set ftrace_dump_on_oops, one
 can either use the sysctl function or set it via the proc system
 interface.
 
-  sysctl kernel.ftrace_dump_on_oops=1
+  sysctl kernel.ftrace_dump_on_oops=n
 
 or
 
-  echo 1 > /proc/sys/kernel/ftrace_dump_on_oops
+  echo n > /proc/sys/kernel/ftrace_dump_on_oops
 
+If n = 1, ftrace will dump buffers of all CPUs, if n = 2 ftrace will
+only dump the buffer of the CPU that triggered the oops.
 
 Here's an example of such a dump after a null pointer
 dereference in a kernel module:
@@ -1822,6 +1827,47 @@ this special filter via:
  echo > set_graph_function
 
 
+Filter commands
+---------------
+
+A few commands are supported by the set_ftrace_filter interface.
+Trace commands have the following format:
+
+<function>:<command>:<parameter>
+
+The following commands are supported:
+
+- mod
+  This command enables function filtering per module. The
+  parameter defines the module. For example, if only the write*
+  functions in the ext3 module are desired, run:
+
+   echo 'write*:mod:ext3' > set_ftrace_filter
+
+  This command interacts with the filter in the same way as
+  filtering based on function names. Thus, adding more functions
+  in a different module is accomplished by appending (>>) to the
+  filter file. Remove specific module functions by prepending
+  '!':
+
+   echo '!writeback*:mod:ext3' >> set_ftrace_filter
+
+- traceon/traceoff
+  These commands turn tracing on and off when the specified
+  functions are hit. The parameter determines how many times the
+  tracing system is turned on and off. If unspecified, there is
+  no limit. For example, to disable tracing when a schedule bug
+  is hit the first 5 times, run:
+
+   echo '__schedule_bug:traceoff:5' > set_ftrace_filter
+
+  These commands are cumulative whether or not they are appended
+  to set_ftrace_filter. To remove a command, prepend it by '!'
+  and drop the parameter:
+
+   echo '!__schedule_bug:traceoff' > set_ftrace_filter
+
+
 trace_pipe
 ----------
 
index a9100b2..ec94748 100644 (file)
@@ -40,7 +40,9 @@ Synopsis of kprobe_events
   $stack       : Fetch stack address.
   $retval      : Fetch return value.(*)
   +|-offs(FETCHARG) : Fetch memory at FETCHARG +|- offs address.(**)
-  NAME=FETCHARG: Set NAME as the argument name of FETCHARG.
+  NAME=FETCHARG : Set NAME as the argument name of FETCHARG.
+  FETCHARG:TYPE : Set TYPE as the type of FETCHARG. Currently, basic types
+                 (u8/u16/u32/u64/s8/s16/s32/s64) are supported.
 
   (*) only for return probe.
   (**) this is useful for fetching a field of data structures.
index c480e9c..4c5e379 100644 (file)
@@ -381,7 +381,7 @@ descriptor that gives us the status of the transfer, its identification
 we issue another URB to read into the destination buffer the chunk of
 data coming out of the remote endpoint. Done, wait for the next guy. The
 callbacks for the URBs issued from here are the ones that will declare
-the xfer complete at some point and call it's callback.
+the xfer complete at some point and call its callback.
 
 Seems simple, but the implementation is not trivial.
 
index f11c583..4739d56 100644 (file)
  99 -> AD-TVK503
 100 -> Hercules Smart TV Stereo
 101 -> Pace TV & Radio Card
-102 -> IVC-200                                             [0000:a155,0001:a155,0002:a155,0003:a155,0100:a155,0101:a155,0102:a155,0103:a155]
+102 -> IVC-200                                             [0000:a155,0001:a155,0002:a155,0003:a155,0100:a155,0101:a155,0102:a155,0103:a155,0800:a155,0801:a155,0802:a155,0803:a155]
 103 -> Grand X-Guard / Trust 814PCI                        [0304:0102]
 104 -> Nebula Electronics DigiTV                           [0071:0101]
 105 -> ProVideo PV143                                      [aa00:1430,aa00:1431,aa00:1432,aa00:1433,aa03:1433]
index 7ec3c4e..f251054 100644 (file)
@@ -82,3 +82,4 @@
  81 -> Leadtek WinFast DTV1800 Hybrid                      [107d:6654]
  82 -> WinFast DTV2000 H rev. J                            [107d:6f2b]
  83 -> Prof 7301 DVB-S/S2                                  [b034:3034]
+ 84 -> Samsung SMT 7020 DVB-S                              [18ac:dc00,18ac:dccd]
index 0c166ff..3a623aa 100644 (file)
@@ -1,5 +1,5 @@
   0 -> Unknown EM2800 video grabber             (em2800)        [eb1a:2800]
-  1 -> Unknown EM2750/28xx video grabber        (em2820/em2840) [eb1a:2710,eb1a:2820,eb1a:2821,eb1a:2860,eb1a:2861,eb1a:2862,eb1a:2870,eb1a:2881,eb1a:2883,eb1a:2868]
+  1 -> Unknown EM2750/28xx video grabber        (em2820/em2840) [eb1a:2710,eb1a:2820,eb1a:2821,eb1a:2860,eb1a:2861,eb1a:2862,eb1a:2863,eb1a:2870,eb1a:2881,eb1a:2883,eb1a:2868]
   2 -> Terratec Cinergy 250 USB                 (em2820/em2840) [0ccd:0036]
   3 -> Pinnacle PCTV USB 2                      (em2820/em2840) [2304:0208]
   4 -> Hauppauge WinTV USB 2                    (em2820/em2840) [2040:4200,2040:4201]
@@ -27,6 +27,7 @@
  26 -> Hercules Smart TV USB 2.0                (em2820/em2840)
  27 -> Pinnacle PCTV USB 2 (Philips FM1216ME)   (em2820/em2840)
  28 -> Leadtek Winfast USB II Deluxe            (em2820/em2840)
+ 29 -> EM2860/TVP5150 Reference Design          (em2860)
  30 -> Videology 20K14XUSB USB2.0               (em2820/em2840)
  31 -> Usbgear VD204v9                          (em2821)
  32 -> Supercomp USB 2.0 TV                     (em2821)
@@ -70,3 +71,4 @@
  72 -> Gadmei UTV330+                           (em2861)
  73 -> Reddo DVB-C USB TV Box                   (em2870)
  74 -> Actionmaster/LinXcel/Digitus VC211A      (em2800)
+ 75 -> Dikom DK300                              (em2882)
index b4a7670..070f257 100644 (file)
 174 -> Asus Europa Hybrid OEM                   [1043:4847]
 175 -> Leadtek Winfast DTV1000S                 [107d:6655]
 176 -> Beholder BeholdTV 505 RDS                [0000:5051]
+177 -> Hawell HW-404M7
+179 -> Beholder BeholdTV H7                    [5ace:7190]
+180 -> Beholder BeholdTV A7                    [5ace:7090]
index 2cb8160..47877de 100644 (file)
@@ -5,12 +5,18 @@
 #
 # In order to use, you need to:
 #      1) Download the windows driver with something like:
+#      Version 2.4
+#              wget http://www.twinhan.com/files/AW/BDA T/20080303_V1.0.6.7.zip
+#              or wget http://www.stefanringel.de/pub/20080303_V1.0.6.7.zip
+#      Version 2.7
 #              wget http://www.steventoth.net/linux/xc5000/HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip
-#      2) Extract the file hcw85bda.sys from the zip into the current dir:
+#      2) Extract the files from the zip into the current dir:
+#              unzip -j 20080303_V1.0.6.7.zip 20080303_v1.0.6.7/UDXTTM6000.sys
 #              unzip -j HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip Driver85/hcw85bda.sys
 #      3) run the script:
 #              ./extract_xc3028.pl
-#      4) copy the generated file:
+#      4) copy the generated files:
+#              cp xc3028-v24.fw /lib/firmware
 #              cp xc3028-v27.fw /lib/firmware
 
 #use strict;
@@ -135,7 +141,7 @@ sub write_hunk_fix_endian($$)
        }
 }
 
-sub main_firmware($$$$)
+sub main_firmware_24($$$$)
 {
        my $out;
        my $j=0;
@@ -146,8 +152,774 @@ sub main_firmware($$$$)
 
        for ($j = length($name); $j <32; $j++) {
                $name = $name.chr(0);
+       }
+
+       open OUTFILE, ">$outfile";
+       syswrite(OUTFILE, $name);
+       write_le16($version);
+       write_le16($nr_desc);
+
+       #
+       # Firmware 0, type: BASE FW   F8MHZ (0x00000003), id: (0000000000000000), size: 6635
+       #
+
+       write_le32(0x00000003);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6635);                       # Size
+       write_hunk_fix_endian(257752, 6635);
+
+       #
+       # Firmware 1, type: BASE FW   F8MHZ MTS (0x00000007), id: (0000000000000000), size: 6635
+       #
+
+       write_le32(0x00000007);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6635);                       # Size
+       write_hunk_fix_endian(264392, 6635);
+
+       #
+       # Firmware 2, type: BASE FW   FM (0x00000401), id: (0000000000000000), size: 6525
+       #
+
+       write_le32(0x00000401);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6525);                       # Size
+       write_hunk_fix_endian(271040, 6525);
+
+       #
+       # Firmware 3, type: BASE FW   FM INPUT1 (0x00000c01), id: (0000000000000000), size: 6539
+       #
+
+       write_le32(0x00000c01);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6539);                       # Size
+       write_hunk_fix_endian(277568, 6539);
+
+       #
+       # Firmware 4, type: BASE FW   (0x00000001), id: (0000000000000000), size: 6633
+       #
+
+       write_le32(0x00000001);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6633);                       # Size
+       write_hunk_fix_endian(284120, 6633);
+
+       #
+       # Firmware 5, type: BASE FW   MTS (0x00000005), id: (0000000000000000), size: 6617
+       #
+
+       write_le32(0x00000005);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(6617);                       # Size
+       write_hunk_fix_endian(290760, 6617);
+
+       #
+       # Firmware 6, type: STD FW    (0x00000000), id: PAL/BG A2/A (0000000100000007), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000001, 0x00000007);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(297384, 161);
+
+       #
+       # Firmware 7, type: STD FW    MTS (0x00000004), id: PAL/BG A2/A (0000000100000007), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000001, 0x00000007);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(297552, 169);
+
+       #
+       # Firmware 8, type: STD FW    (0x00000000), id: PAL/BG A2/B (0000000200000007), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000002, 0x00000007);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(297728, 161);
+
+       #
+       # Firmware 9, type: STD FW    MTS (0x00000004), id: PAL/BG A2/B (0000000200000007), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000002, 0x00000007);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(297896, 169);
+
+       #
+       # Firmware 10, type: STD FW    (0x00000000), id: PAL/BG NICAM/A (0000000400000007), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000004, 0x00000007);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(298072, 161);
+
+       #
+       # Firmware 11, type: STD FW    MTS (0x00000004), id: PAL/BG NICAM/A (0000000400000007), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000004, 0x00000007);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(298240, 169);
+
+       #
+       # Firmware 12, type: STD FW    (0x00000000), id: PAL/BG NICAM/B (0000000800000007), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000008, 0x00000007);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(298416, 161);
+
+       #
+       # Firmware 13, type: STD FW    MTS (0x00000004), id: PAL/BG NICAM/B (0000000800000007), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000008, 0x00000007);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(298584, 169);
+
+       #
+       # Firmware 14, type: STD FW    (0x00000000), id: PAL/DK A2 (00000003000000e0), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000003, 0x000000e0);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(298760, 161);
+
+       #
+       # Firmware 15, type: STD FW    MTS (0x00000004), id: PAL/DK A2 (00000003000000e0), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000003, 0x000000e0);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(298928, 169);
+
+       #
+       # Firmware 16, type: STD FW    (0x00000000), id: PAL/DK NICAM (0000000c000000e0), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x0000000c, 0x000000e0);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(299104, 161);
+
+       #
+       # Firmware 17, type: STD FW    MTS (0x00000004), id: PAL/DK NICAM (0000000c000000e0), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x0000000c, 0x000000e0);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(299272, 169);
+
+       #
+       # Firmware 18, type: STD FW    (0x00000000), id: SECAM/K1 (0000000000200000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x00200000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(299448, 161);
+
+       #
+       # Firmware 19, type: STD FW    MTS (0x00000004), id: SECAM/K1 (0000000000200000), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000000, 0x00200000);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(299616, 169);
+
+       #
+       # Firmware 20, type: STD FW    (0x00000000), id: SECAM/K3 (0000000004000000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x04000000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(299792, 161);
+
+       #
+       # Firmware 21, type: STD FW    MTS (0x00000004), id: SECAM/K3 (0000000004000000), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000000, 0x04000000);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(299960, 169);
+
+       #
+       # Firmware 22, type: STD FW    D2633 DTV6 ATSC (0x00010030), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00010030);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300136, 149);
+
+       #
+       # Firmware 23, type: STD FW    D2620 DTV6 QAM (0x00000068), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000068);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300296, 149);
+
+       #
+       # Firmware 24, type: STD FW    D2633 DTV6 QAM (0x00000070), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000070);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300448, 149);
+
+       #
+       # Firmware 25, type: STD FW    D2620 DTV7 (0x00000088), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000088);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300608, 149);
+
+       #
+       # Firmware 26, type: STD FW    D2633 DTV7 (0x00000090), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000090);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300760, 149);
+
+       #
+       # Firmware 27, type: STD FW    D2620 DTV78 (0x00000108), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000108);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(300920, 149);
+
+       #
+       # Firmware 28, type: STD FW    D2633 DTV78 (0x00000110), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000110);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(301072, 149);
+
+       #
+       # Firmware 29, type: STD FW    D2620 DTV8 (0x00000208), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000208);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(301232, 149);
+
+       #
+       # Firmware 30, type: STD FW    D2633 DTV8 (0x00000210), id: (0000000000000000), size: 149
+       #
+
+       write_le32(0x00000210);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(149);                        # Size
+       write_hunk_fix_endian(301384, 149);
+
+       #
+       # Firmware 31, type: STD FW    FM (0x00000400), id: (0000000000000000), size: 135
+       #
+
+       write_le32(0x00000400);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le32(135);                        # Size
+       write_hunk_fix_endian(301554, 135);
+
+       #
+       # Firmware 32, type: STD FW    (0x00000000), id: PAL/I (0000000000000010), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x00000010);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(301688, 161);
+
+       #
+       # Firmware 33, type: STD FW    MTS (0x00000004), id: PAL/I (0000000000000010), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000000, 0x00000010);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(301856, 169);
+
+       #
+       # Firmware 34, type: STD FW    (0x00000000), id: SECAM/L AM (0000001000400000), size: 169
+       #
+
+       #
+       # Firmware 35, type: STD FW    (0x00000000), id: SECAM/L NICAM (0000000c00400000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x0000000c, 0x00400000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(302032, 161);
+
+       #
+       # Firmware 36, type: STD FW    (0x00000000), id: SECAM/Lc (0000000000800000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x00800000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(302200, 161);
+
+       #
+       # Firmware 37, type: STD FW    (0x00000000), id: NTSC/M Kr (0000000000008000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(302368, 161);
+
+       #
+       # Firmware 38, type: STD FW    LCD (0x00001000), id: NTSC/M Kr (0000000000008000), size: 161
+       #
+
+       write_le32(0x00001000);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(302536, 161);
+
+       #
+       # Firmware 39, type: STD FW    LCD NOGD (0x00003000), id: NTSC/M Kr (0000000000008000), size: 161
+       #
+
+       write_le32(0x00003000);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(302704, 161);
+
+       #
+       # Firmware 40, type: STD FW    MTS (0x00000004), id: NTSC/M Kr (0000000000008000), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(302872, 169);
+
+       #
+       # Firmware 41, type: STD FW    (0x00000000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(303048, 161);
+
+       #
+       # Firmware 42, type: STD FW    LCD (0x00001000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
+       #
+
+       write_le32(0x00001000);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(303216, 161);
+
+       #
+       # Firmware 43, type: STD FW    LCD NOGD (0x00003000), id: NTSC PAL/M PAL/N (000000000000b700), size: 161
+       #
+
+       write_le32(0x00003000);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(303384, 161);
+
+       #
+       # Firmware 44, type: STD FW    (0x00000000), id: NTSC/M Jp (0000000000002000), size: 161
+       #
+
+       write_le32(0x00000000);                 # Type
+       write_le64(0x00000000, 0x00002000);     # ID
+       write_le32(161);                        # Size
+       write_hunk_fix_endian(303552, 161);
+
+       #
+       # Firmware 45, type: STD FW    MTS (0x00000004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
+       #
+
+       write_le32(0x00000004);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(303720, 169);
+
+       #
+       # Firmware 46, type: STD FW    MTS LCD (0x00001004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
+       #
+
+       write_le32(0x00001004);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(303896, 169);
+
+       #
+       # Firmware 47, type: STD FW    MTS LCD NOGD (0x00003004), id: NTSC PAL/M PAL/N (000000000000b700), size: 169
+       #
+
+       write_le32(0x00003004);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le32(169);                        # Size
+       write_hunk_fix_endian(304072, 169);
+
+       #
+       # Firmware 48, type: SCODE FW  HAS IF (0x60000000), IF = 3.28 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(3280);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(309048, 192);
+
+       #
+       # Firmware 49, type: SCODE FW  HAS IF (0x60000000), IF = 3.30 MHz id: (0000000000000000), size: 192
+       #
+
+#      write_le32(0x60000000);                 # Type
+#      write_le64(0x00000000, 0x00000000);     # ID
+#      write_le16(3300);                       # IF
+#      write_le32(192);                        # Size
+#      write_hunk(304440, 192);
+
+       #
+       # Firmware 50, type: SCODE FW  HAS IF (0x60000000), IF = 3.44 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(3440);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(309432, 192);
+
+       #
+       # Firmware 51, type: SCODE FW  HAS IF (0x60000000), IF = 3.46 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(3460);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(309624, 192);
+
+       #
+       # Firmware 52, type: SCODE FW  DTV6 ATSC OREN36 HAS IF (0x60210020), IF = 3.80 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60210020);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(3800);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(306936, 192);
+
+       #
+       # Firmware 53, type: SCODE FW  HAS IF (0x60000000), IF = 4.00 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4000);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(309240, 192);
+
+       #
+       # Firmware 54, type: SCODE FW  DTV6 ATSC TOYOTA388 HAS IF (0x60410020), IF = 4.08 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60410020);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4080);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(307128, 192);
+
+       #
+       # Firmware 55, type: SCODE FW  HAS IF (0x60000000), IF = 4.20 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4200);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(308856, 192);
+
+       #
+       # Firmware 56, type: SCODE FW  MONO HAS IF (0x60008000), IF = 4.32 MHz id: NTSC/M Kr (0000000000008000), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le16(4320);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305208, 192);
+
+       #
+       # Firmware 57, type: SCODE FW  HAS IF (0x60000000), IF = 4.45 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4450);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(309816, 192);
+
+       #
+       # Firmware 58, type: SCODE FW  MTS LCD NOGD MONO IF HAS IF (0x6002b004), IF = 4.50 MHz id: NTSC PAL/M PAL/N (000000000000b700), size: 192
+       #
+
+       write_le32(0x6002b004);                 # Type
+       write_le64(0x00000000, 0x0000b700);     # ID
+       write_le16(4500);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(304824, 192);
+
+       #
+       # Firmware 59, type: SCODE FW  LCD NOGD IF HAS IF (0x60023000), IF = 4.60 MHz id: NTSC/M Kr (0000000000008000), size: 192
+       #
+
+       write_le32(0x60023000);                 # Type
+       write_le64(0x00000000, 0x00008000);     # ID
+       write_le16(4600);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305016, 192);
+
+       #
+       # Firmware 60, type: SCODE FW  DTV6 QAM DTV7 DTV78 DTV8 ZARLINK456 HAS IF (0x620003e0), IF = 4.76 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x620003e0);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4760);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(304440, 192);
+
+       #
+       # Firmware 61, type: SCODE FW  HAS IF (0x60000000), IF = 4.94 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(4940);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(308664, 192);
+
+       #
+       # Firmware 62, type: SCODE FW  HAS IF (0x60000000), IF = 5.26 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(5260);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(307704, 192);
+
+       #
+       # Firmware 63, type: SCODE FW  MONO HAS IF (0x60008000), IF = 5.32 MHz id: PAL/BG A2 NICAM (0000000f00000007), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x0000000f, 0x00000007);     # ID
+       write_le16(5320);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(307896, 192);
+
+       #
+       # Firmware 64, type: SCODE FW  DTV7 DTV78 DTV8 DIBCOM52 CHINA HAS IF (0x65000380), IF = 5.40 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x65000380);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(5400);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(304248, 192);
+
+       #
+       # Firmware 65, type: SCODE FW  DTV6 ATSC OREN538 HAS IF (0x60110020), IF = 5.58 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60110020);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(5580);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(306744, 192);
+
+       #
+       # Firmware 66, type: SCODE FW  HAS IF (0x60000000), IF = 5.64 MHz id: PAL/BG A2 (0000000300000007), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000003, 0x00000007);     # ID
+       write_le16(5640);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305592, 192);
+
+       #
+       # Firmware 67, type: SCODE FW  HAS IF (0x60000000), IF = 5.74 MHz id: PAL/BG NICAM (0000000c00000007), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x0000000c, 0x00000007);     # ID
+       write_le16(5740);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305784, 192);
+
+       #
+       # Firmware 68, type: SCODE FW  HAS IF (0x60000000), IF = 5.90 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(5900);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(307512, 192);
+
+       #
+       # Firmware 69, type: SCODE FW  MONO HAS IF (0x60008000), IF = 6.00 MHz id: PAL/DK PAL/I SECAM/K3 SECAM/L SECAM/Lc NICAM (0000000c04c000f0), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x0000000c, 0x04c000f0);     # ID
+       write_le16(6000);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305576, 192);
+
+       #
+       # Firmware 70, type: SCODE FW  DTV6 QAM ATSC LG60 F6MHZ HAS IF (0x68050060), IF = 6.20 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x68050060);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(6200);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(306552, 192);
+
+       #
+       # Firmware 71, type: SCODE FW  HAS IF (0x60000000), IF = 6.24 MHz id: PAL/I (0000000000000010), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00000010);     # ID
+       write_le16(6240);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(305400, 192);
+
+       #
+       # Firmware 72, type: SCODE FW  MONO HAS IF (0x60008000), IF = 6.32 MHz id: SECAM/K1 (0000000000200000), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x00000000, 0x00200000);     # ID
+       write_le16(6320);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(308472, 192);
+
+       #
+       # Firmware 73, type: SCODE FW  HAS IF (0x60000000), IF = 6.34 MHz id: SECAM/K1 (0000000000200000), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000000, 0x00200000);     # ID
+       write_le16(6340);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(306360, 192);
+
+       #
+       # Firmware 74, type: SCODE FW  MONO HAS IF (0x60008000), IF = 6.50 MHz id: PAL/DK SECAM/K3 SECAM/L NICAM (0000000c044000e0), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x0000000c, 0x044000e0);     # ID
+       write_le16(6500);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(308280, 192);
+
+       #
+       # Firmware 75, type: SCODE FW  DTV6 ATSC ATI638 HAS IF (0x60090020), IF = 6.58 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60090020);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(6580);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(304632, 192);
+
+       #
+       # Firmware 76, type: SCODE FW  HAS IF (0x60000000), IF = 6.60 MHz id: PAL/DK A2 (00000003000000e0), size: 192
+       #
+
+       write_le32(0x60000000);                 # Type
+       write_le64(0x00000003, 0x000000e0);     # ID
+       write_le16(6600);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(306168, 192);
+
+       #
+       # Firmware 77, type: SCODE FW  MONO HAS IF (0x60008000), IF = 6.68 MHz id: PAL/DK A2 (00000003000000e0), size: 192
+       #
+
+       write_le32(0x60008000);                 # Type
+       write_le64(0x00000003, 0x000000e0);     # ID
+       write_le16(6680);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(308088, 192);
+
+       #
+       # Firmware 78, type: SCODE FW  DTV6 ATSC TOYOTA794 HAS IF (0x60810020), IF = 8.14 MHz id: (0000000000000000), size: 192
+       #
+
+       write_le32(0x60810020);                 # Type
+       write_le64(0x00000000, 0x00000000);     # ID
+       write_le16(8140);                       # IF
+       write_le32(192);                        # Size
+       write_hunk(307320, 192);
+
+       #
+       # Firmware 79, type: SCODE FW  HAS IF (0x60000000), IF = 8.20 MHz id: (0000000000000000), size: 192
+       #
+
+#      write_le32(0x60000000);                 # Type
+#      write_le64(0x00000000, 0x00000000);     # ID
+#      write_le16(8200);                       # IF
+#      write_le32(192);                        # Size
+#      write_hunk(308088, 192);
 }
 
+sub main_firmware_27($$$$)
+{
+       my $out;
+       my $j=0;
+       my $outfile = shift;
+       my $name    = shift;
+       my $version = shift;
+       my $nr_desc = shift;
+
+       for ($j = length($name); $j <32; $j++) {
+               $name = $name.chr(0);
+       }
+
        open OUTFILE, ">$outfile";
        syswrite(OUTFILE, $name);
        write_le16($version);
@@ -906,20 +1678,39 @@ sub main_firmware($$$$)
        write_hunk(812856, 192);
 }
 
+
 sub extract_firmware {
-       my $sourcefile = "hcw85bda.sys";
-       my $hash = "0e44dbf63bb0169d57446aec21881ff2";
-       my $outfile = "xc3028-v27.fw";
-       my $name = "xc2028 firmware";
-       my $version = 519;
-       my $nr_desc = 80;
+       my $sourcefile_24 = "UDXTTM6000.sys";
+       my $hash_24 = "cb9deb5508a5e150af2880f5b0066d78";
+       my $outfile_24 = "xc3028-v24.fw";
+       my $name_24 = "xc2028 firmware";
+       my $version_24 = 516;
+       my $nr_desc_24 = 77;
+       my $out;
+
+       my $sourcefile_27 = "hcw85bda.sys";
+       my $hash_27 = "0e44dbf63bb0169d57446aec21881ff2";
+       my $outfile_27 = "xc3028-v27.fw";
+       my $name_27 = "xc2028 firmware";
+       my $version_27 = 519;
+       my $nr_desc_27 = 80;
        my $out;
 
-       verify($sourcefile, $hash);
+       if (-e $sourcefile_24) {
+               verify($sourcefile_24, $hash_24);
 
-       open INFILE, "<$sourcefile";
-       main_firmware($outfile, $name, $version, $nr_desc);
-       close INFILE;
+               open INFILE, "<$sourcefile_24";
+               main_firmware_24($outfile_24, $name_24, $version_24, $nr_desc_24);
+               close INFILE;
+       }
+
+       if (-e $sourcefile_27) {
+               verify($sourcefile_27, $hash_27);
+
+               open INFILE, "<$sourcefile_27";
+               main_firmware_27($outfile_27, $name_27, $version_27, $nr_desc_27);
+               close INFILE;
+       }
 }
 
 extract_firmware;
index 181b9e6..8f3f5d3 100644 (file)
@@ -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
@@ -305,12 +307,14 @@ 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)
 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 +327,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)
index 2ae1634..cb47e72 100644 (file)
@@ -17,18 +17,18 @@ Generic scaling / cropping scheme
 -2-- -\
 |      --\
 |         --\
-+-5-- -\     -- -3--
-|       ---\
-|           --- -4-- -\
-|                      -\
-|                        - -6--
++-5-- .      -- -3-- -\
+|      `...            -\
+|          `... -4-- .   - -7..
+|                     `.
+|                       `. .6--
 |
-|                        - -6'-
-|                      -/
-|           --- -4'- -/
-|       ---/
-+-5'- -/
-|            -- -3'-
+|                        . .6'-
+|                      .´
+|           ... -4'- .´
+|       ...´             - -7'.
++-5'- .´               -/
+|            -- -3'- -/
 |         --/
 |      --/
 -2'- -/
@@ -36,7 +36,11 @@ Generic scaling / cropping scheme
 |
 -1'-
 
-Produced by user requests:
+In the above chart minuses and slashes represent "real" data amounts, points and
+accents represent "useful" data, basically, CEU scaled amd cropped output,
+mapped back onto the client's source plane.
+
+Such a configuration can be produced by user requests:
 
 S_CROP(left / top = (5) - (1), width / height = (5') - (5))
 S_FMT(width / height = (6') - (6))
@@ -106,52 +110,30 @@ window:
 S_CROP
 ------
 
-If old scale applied to new crop is invalid produce nearest new scale possible
-
-1. Calculate current combined scales.
-
-       scale_comb = (((4') - (4)) / ((6') - (6))) * (((2') - (2)) / ((3') - (3)))
-
-2. Apply iterative sensor S_CROP for new input window.
-
-3. If old combined scales applied to new crop produce an impossible user window,
-adjust scales to produce nearest possible window.
-
-       width_u_out = ((5') - (5)) / scale_comb
+The API at http://v4l2spec.bytesex.org/spec/x1904.htm says:
 
-       if (width_u_out > max)
-               scale_comb = ((5') - (5)) / max;
-       else if (width_u_out < min)
-               scale_comb = ((5') - (5)) / min;
+"...specification does not define an origin or units. However by convention
+drivers should horizontally count unscaled samples relative to 0H."
 
-4. Issue G_CROP to retrieve actual input window.
+We choose to follow the advise and interpret cropping units as client input
+pixels.
 
-5. Using actual input window and calculated combined scales calculate sensor
-target output window.
-
-       width_s_out = ((3') - (3)) = ((2') - (2)) / scale_comb
-
-6. Apply iterative S_FMT for new sensor target output window.
-
-7. Issue G_FMT to retrieve the actual sensor output window.
-
-8. Calculate sensor scales.
-
-       scale_s = ((3') - (3)) / ((2') - (2))
+Cropping is performed in the following 6 steps:
 
-9. Calculate sensor output subwindow to be cropped on CEU by applying sensor
-scales to the requested window.
+1. Request exactly user rectangle from the sensor.
 
-       width_ceu = ((5') - (5)) / scale_s
+2. If smaller - iterate until a larger one is obtained. Result: sensor cropped
+   to 2 : 2', target crop 5 : 5', current output format 6' - 6.
 
-10. Use CEU cropping for above calculated window.
+3. In the previous step the sensor has tried to preserve its output frame as
+   good as possible, but it could have changed. Retrieve it again.
 
-11. Calculate CEU scales from sensor scales from results of (10) and user window
-from (3)
+4. Sensor scaled to 3 : 3'. Sensor's scale is (2' - 2) / (3' - 3). Calculate
+   intermediate window: 4' - 4 = (5' - 5) * (3' - 3) / (2' - 2)
 
-       scale_ceu = calc_scale(((5') - (5)), &width_u_out)
+5. Calculate and apply host scale = (6' - 6) / (4' - 4)
 
-12. Apply CEU scales.
+6. Calculate and apply host crop: 6 - 7 = (5 - 2) * (6' - 6) / (5' - 5)
 
 --
 Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
index 5155700..e831aac 100644 (file)
@@ -545,12 +545,11 @@ unregister them:
 This will remove the device nodes from sysfs (causing udev to remove them
 from /dev).
 
-After video_unregister_device() returns no new opens can be done.
-
-However, in the case of USB devices some application might still have one
-of these device nodes open. You should block all new accesses to read,
-write, poll, etc. except possibly for certain ioctl operations like
-queueing buffers.
+After video_unregister_device() returns no new opens can be done. However,
+in the case of USB devices some application might still have one of these
+device nodes open. So after the unregister all file operations will return
+an error as well, except for the ioctl and unlocked_ioctl file operations:
+those will still be passed on since some buffer ioctls may still be needed.
 
 When the last user of the video device node exits, then the vdev->release()
 callback is called and you can do the final cleanup there.
@@ -609,3 +608,135 @@ scatter/gather method (videobuf-dma-sg), DMA with linear access
 
 Please see Documentation/video4linux/videobuf for more information on how
 to use the videobuf layer.
+
+struct v4l2_fh
+--------------
+
+struct v4l2_fh provides a way to easily keep file handle specific data
+that is used by the V4L2 framework. Using v4l2_fh is optional for
+drivers.
+
+The users of v4l2_fh (in the V4L2 framework, not the driver) know
+whether a driver uses v4l2_fh as its file->private_data pointer by
+testing the V4L2_FL_USES_V4L2_FH bit in video_device->flags.
+
+Useful functions:
+
+- v4l2_fh_init()
+
+  Initialise the file handle. This *MUST* be performed in the driver's
+  v4l2_file_operations->open() handler.
+
+- v4l2_fh_add()
+
+  Add a v4l2_fh to video_device file handle list. May be called after
+  initialising the file handle.
+
+- v4l2_fh_del()
+
+  Unassociate the file handle from video_device(). The file handle
+  exit function may now be called.
+
+- v4l2_fh_exit()
+
+  Uninitialise the file handle. After uninitialisation the v4l2_fh
+  memory can be freed.
+
+struct v4l2_fh is allocated as a part of the driver's own file handle
+structure and is set to file->private_data in the driver's open
+function by the driver. Drivers can extract their own file handle
+structure by using the container_of macro. Example:
+
+struct my_fh {
+       int blah;
+       struct v4l2_fh fh;
+};
+
+...
+
+int my_open(struct file *file)
+{
+       struct my_fh *my_fh;
+       struct video_device *vfd;
+       int ret;
+
+       ...
+
+       ret = v4l2_fh_init(&my_fh->fh, vfd);
+       if (ret)
+               return ret;
+
+       v4l2_fh_add(&my_fh->fh);
+
+       file->private_data = &my_fh->fh;
+
+       ...
+}
+
+int my_release(struct file *file)
+{
+       struct v4l2_fh *fh = file->private_data;
+       struct my_fh *my_fh = container_of(fh, struct my_fh, fh);
+
+       ...
+}
+
+V4L2 events
+-----------
+
+The V4L2 events provide a generic way to pass events to user space.
+The driver must use v4l2_fh to be able to support V4L2 events.
+
+Useful functions:
+
+- v4l2_event_alloc()
+
+  To use events, the driver must allocate events for the file handle. By
+  calling the function more than once, the driver may assure that at least n
+  events in total have been allocated. The function may not be called in
+  atomic context.
+
+- v4l2_event_queue()
+
+  Queue events to video device. The driver's only responsibility is to fill
+  in the type and the data fields. The other fields will be filled in by
+  V4L2.
+
+- v4l2_event_subscribe()
+
+  The video_device->ioctl_ops->vidioc_subscribe_event must check the driver
+  is able to produce events with specified event id. Then it calls
+  v4l2_event_subscribe() to subscribe the event.
+
+- v4l2_event_unsubscribe()
+
+  vidioc_unsubscribe_event in struct v4l2_ioctl_ops. A driver may use
+  v4l2_event_unsubscribe() directly unless it wants to be involved in
+  unsubscription process.
+
+  The special type V4L2_EVENT_ALL may be used to unsubscribe all events. The
+  drivers may want to handle this in a special way.
+
+- v4l2_event_pending()
+
+  Returns the number of pending events. Useful when implementing poll.
+
+Drivers do not initialise events directly. The events are initialised
+through v4l2_fh_init() if video_device->ioctl_ops->vidioc_subscribe_event is
+non-NULL. This *MUST* be performed in the driver's
+v4l2_file_operations->open() handler.
+
+Events are delivered to user space through the poll system call. The driver
+can use v4l2_fh->events->wait wait_queue_head_t as the argument for
+poll_wait().
+
+There are standard and private events. New standard events must use the
+smallest available event type. The drivers must allocate their events from
+their own class starting from class base. Class base is
+V4L2_EVENT_PRIVATE_START + n * 1000 where n is the lowest available number.
+The first event type in the class is reserved for future use, so the first
+available event type is 'class base + 1'.
+
+An example on how the V4L2 events may be used can be found in the OMAP
+3 ISP driver available at <URL:http://gitorious.org/omap3camera> as of
+writing this.
index be45dbb..6690fc3 100644 (file)
@@ -45,7 +45,7 @@ most general to most specific:
        to establish the task policy for a child task exec()'d from an
        executable image that has no awareness of memory policy.  See the
        MEMORY POLICY APIS section, below, for an overview of the system call
-       that a task may use to set/change it's task/process policy.
+       that a task may use to set/change its task/process policy.
 
        In a multi-threaded task, task policies apply only to the thread
        [Linux kernel task] that installs the policy and any threads
@@ -301,7 +301,7 @@ decrement this reference count, respectively.  mpol_put() will only free
 the structure back to the mempolicy kmem cache when the reference count
 goes to zero.
 
-When a new memory policy is allocated, it's reference count is initialized
+When a new memory policy is allocated, its reference count is initialized
 to '1', representing the reference held by the task that is installing the
 new policy.  When a pointer to a memory policy structure is stored in another
 structure, another reference is added, as the task's reference will be dropped
index e3333ee..212f4ac 100644 (file)
@@ -25,7 +25,7 @@ When a w1 master driver registers with the w1 subsystem, the following occurs:
  - sysfs entries for that w1 master are created
  - the w1 bus is periodically searched for new slave devices
 
-When a device is found on the bus, w1 core checks if driver for it's family is
+When a device is found on the bus, w1 core checks if driver for its family is
 loaded. If so, the family driver is attached to the slave.
 If there is no driver for the family, default one is assigned, which allows to perform
 almost any kind of operations. Each logical operation is a transaction
index d329b05..2449042 100644 (file)
@@ -586,6 +586,12 @@ F: drivers/mtd/nand/bcm_umi_bch.c
 F:     drivers/mtd/nand/bcm_umi_hamming.c
 F:     drivers/mtd/nand/nand_bcm_umi.h
 
+ARM/CAVIUM NETWORKS CNS3XXX MACHINE SUPPORT
+M:     Anton Vorontsov <avorontsov@mvista.com>
+S:     Maintained
+F:     arch/arm/mach-cns3xxx/
+T:     git git://git.infradead.org/users/cbou/linux-cns3xxx.git
+
 ARM/CIRRUS LOGIC EP93XX ARM ARCHITECTURE
 M:     Hartley Sweeten <hsweeten@visionengravers.com>
 M:     Ryan Mallon <ryan@bluewatersys.com>
@@ -775,11 +781,10 @@ M:        Philipp Zabel <philipp.zabel@gmail.com>
 S:     Maintained
 
 ARM/Marvell Loki/Kirkwood/MV78xx0/Orion SOC support
-M:     Lennert Buytenhek <buytenh@marvell.com>
-M:     Nicolas Pitre <nico@marvell.com>
+M:     Lennert Buytenhek <kernel@wantstofly.org>
+M:     Nicolas Pitre <nico@fluxnic.net>
 L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
-T:     git git://git.marvell.com/orion
-S:     Maintained
+S:     Odd Fixes
 F:     arch/arm/mach-loki/
 F:     arch/arm/mach-kirkwood/
 F:     arch/arm/mach-mv78xx0/
@@ -814,6 +819,7 @@ ARM/QUALCOMM MSM MACHINE SUPPORT
 M:     David Brown <davidb@codeaurora.org>
 M:     Daniel Walker <dwalker@codeaurora.org>
 M:     Bryan Huntsman <bryanh@codeaurora.org>
+L:     linux-arm-msm@vger.kernel.org
 F:     arch/arm/mach-msm/
 F:     drivers/video/msm/
 F:     drivers/mmc/host/msm_sdcc.c
@@ -994,6 +1000,20 @@ W:        http://www.arm.linux.org.uk/
 S:     Maintained
 F:     arch/arm/vfp/
 
+ARM/VOIPAC PXA270 SUPPORT
+M:     Marek Vasut <marek.vasut@gmail.com>
+L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
+S:     Maintained
+F:     arch/arm/mach-pxa/vpac270.c
+F:     arch/arm/mach-pxa/include/mach-pxa/vpac270.h
+
+ARM/ZIPIT Z2 SUPPORT
+M:     Marek Vasut <marek.vasut@gmail.com>
+L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
+S:     Maintained
+F:     arch/arm/mach-pxa/z2.c
+F:     arch/arm/mach-pxa/include/mach-pxa/z2.h
+
 ASC7621 HARDWARE MONITOR DRIVER
 M:     George Joseph <george.joseph@fairview5.com>
 L:     lm-sensors@lm-sensors.org
@@ -1729,6 +1749,20 @@ W:       http://www.openfabrics.org
 S:     Supported
 F:     drivers/infiniband/hw/cxgb3/
 
+CXGB4 ETHERNET DRIVER (CXGB4)
+M:     Dimitris Michailidis <dm@chelsio.com>
+L:     netdev@vger.kernel.org
+W:     http://www.chelsio.com
+S:     Supported
+F:     drivers/net/cxgb4/
+
+CXGB4 IWARP RNIC DRIVER (IW_CXGB4)
+M:     Steve Wise <swise@chelsio.com>
+L:     linux-rdma@vger.kernel.org
+W:     http://www.openfabrics.org
+S:     Supported
+F:     drivers/infiniband/hw/cxgb4/
+
 CYBERPRO FB DRIVER
 M:     Russell King <linux@arm.linux.org.uk>
 L:     linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -2667,16 +2701,12 @@ F:      Documentation/timers/hpet.txt
 F:     drivers/char/hpet.c
 F:     include/linux/hpet.h
 
-HPET:  i386
-M:     "Venkatesh Pallipadi (Venki)" <venkatesh.pallipadi@intel.com>
+HPET:  x86
+M:     "Venkatesh Pallipadi (Venki)" <venki@google.com>
 S:     Maintained
 F:     arch/x86/kernel/hpet.c
 F:     arch/x86/include/asm/hpet.h
 
-HPET:  x86_64
-M:     Vojtech Pavlik <vojtech@suse.cz>
-S:     Maintained
-
 HPET:  ACPI
 M:     Bob Picco <bob.picco@hp.com>
 S:     Maintained
@@ -2717,6 +2747,7 @@ M:        "Ben Dooks (embedded platforms)" <ben-linux@fluff.org>
 L:     linux-i2c@vger.kernel.org
 W:     http://i2c.wiki.kernel.org/
 T:     quilt kernel.org/pub/linux/kernel/people/jdelvare/linux-2.6/jdelvare-i2c/
+T:     git git://git.fluff.org/bjdooks/linux.git
 S:     Maintained
 F:     Documentation/i2c/
 F:     drivers/i2c/
@@ -2953,6 +2984,17 @@ S:       Odd Fixes
 F:     Documentation/networking/README.ipw2200
 F:     drivers/net/wireless/ipw2x00/ipw2200.*
 
+INTEL(R) TRUSTED EXECUTION TECHNOLOGY (TXT)
+M:     Joseph Cihula <joseph.cihula@intel.com>
+M:     Shane Wang <shane.wang@intel.com>
+L:     tboot-devel@lists.sourceforge.net
+W:     http://tboot.sourceforge.net
+T:     Mercurial http://www.bughost.org/repos.hg/tboot.hg
+S:     Supported
+F:     Documentation/intel_txt.txt
+F:     include/linux/tboot.h
+F:     arch/x86/kernel/tboot.c
+
 INTEL WIRELESS WIMAX CONNECTION 2400
 M:     Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
 M:     linux-wimax@intel.com
@@ -3624,7 +3666,8 @@ F:        drivers/net/wireless/mwl8k.c
 
 MARVELL SOC MMC/SD/SDIO CONTROLLER DRIVER
 M:     Nicolas Pitre <nico@fluxnic.net>
-S:     Maintained
+S:     Odd Fixes
+F: drivers/mmc/host/mvsdio.*
 
 MARVELL YUKON / SYSKONNECT DRIVER
 M:     Mirko Lindner <mlindner@syskonnect.de>
@@ -4165,6 +4208,7 @@ OPROFILE
 M:     Robert Richter <robert.richter@amd.com>
 L:     oprofile-list@lists.sf.net
 S:     Maintained
+F:     arch/*/include/asm/oprofile*.h
 F:     arch/*/oprofile/
 F:     drivers/oprofile/
 F:     include/linux/oprofile.h
@@ -4353,13 +4397,13 @@ M:      Paul Mackerras <paulus@samba.org>
 M:     Ingo Molnar <mingo@elte.hu>
 M:     Arnaldo Carvalho de Melo <acme@redhat.com>
 S:     Supported
-F:     kernel/perf_event.c
+F:     kernel/perf_event*.c
 F:     include/linux/perf_event.h
-F:     arch/*/kernel/perf_event.c
-F:     arch/*/kernel/*/perf_event.c
-F:     arch/*/kernel/*/*/perf_event.c
+F:     arch/*/kernel/perf_event*.c
+F:     arch/*/kernel/*/perf_event*.c
+F:     arch/*/kernel/*/*/perf_event*.c
 F:     arch/*/include/asm/perf_event.h
-F:     arch/*/lib/perf_event.c
+F:     arch/*/lib/perf_event*.c
 F:     arch/*/kernel/perf_callchain.c
 F:     tools/perf/
 
@@ -5121,7 +5165,7 @@ F:        mm/sl?b.c
 
 SMC91x ETHERNET DRIVER
 M:     Nicolas Pitre <nico@fluxnic.net>
-S:     Maintained
+S:     Odd Fixes
 F:     drivers/net/smc91x.*
 
 SMSC47B397 HARDWARE MONITOR DRIVER
@@ -5252,6 +5296,46 @@ F:       drivers/serial/sunsu.c
 F:     drivers/serial/sunzilog.c
 F:     drivers/serial/sunzilog.h
 
+SPEAR PLATFORM SUPPORT
+M:     Viresh Kumar <viresh.kumar@st.com>
+W:     http://www.st.com/spear
+S:     Maintained
+F:     arch/arm/plat-spear/
+
+SPEAR3XX MACHINE SUPPORT
+M:     Viresh Kumar <viresh.kumar@st.com>
+W:     http://www.st.com/spear
+S:     Maintained
+F:     arch/arm/mach-spear3xx/
+
+SPEAR6XX MACHINE SUPPORT
+M:     Rajeev Kumar <rajeev-dlh.kumar@st.com>
+W:     http://www.st.com/spear
+S:     Maintained
+F:     arch/arm/mach-spear6xx/
+
+SPEAR CLOCK FRAMEWORK SUPPORT
+M:     Viresh Kumar <viresh.kumar@st.com>
+W:     http://www.st.com/spear
+S:     Maintained
+F:     arch/arm/mach-spear*/clock.c
+F:     arch/arm/mach-spear*/include/mach/clkdev.h
+F:     arch/arm/plat-spear/clock.c
+F:     arch/arm/plat-spear/include/plat/clock.h and clkdev.h
+
+SPEAR PAD MULTIPLEXING SUPPORT
+M:     Viresh Kumar <viresh.kumar@st.com>
+W:     http://www.st.com/spear
+S:     Maintained
+F:     arch/arm/plat-spear/include/plat/padmux.h
+F:     arch/arm/plat-spear/padmux.c
+F:     arch/arm/mach-spear*/spear*xx.c
+F:     arch/arm/mach-spear*/include/mach/generic.h
+F:     arch/arm/mach-spear3xx/spear3*0.c
+F:     arch/arm/mach-spear3xx/spear3*0_evb.c
+F:     arch/arm/mach-spear6xx/spear600.c
+F:     arch/arm/mach-spear6xx/spear600_evb.c
+
 SPECIALIX IO8+ MULTIPORT SERIAL CARD DRIVER
 M:     Roger Wolff <R.E.Wolff@BitWizard.nl>
 S:     Supported
@@ -5880,7 +5964,7 @@ M:        Laurent Pinchart <laurent.pinchart@skynet.be>
 L:     linux-uvc-devel@lists.berlios.de (subscribers-only)
 L:     linux-media@vger.kernel.org
 T:     git git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6.git
-W:     http://linux-uvc.berlios.de
+W:     http://www.ideasonboard.org/uvc/
 S:     Maintained
 F:     drivers/media/video/uvc/
 
index e5eb133..acda512 100644 (file)
@@ -42,15 +42,10 @@ config KPROBES
          If in doubt, say "N".
 
 config OPTPROBES
-       bool "Kprobes jump optimization support (EXPERIMENTAL)"
-       default y
-       depends on KPROBES
+       def_bool y
+       depends on KPROBES && HAVE_OPTPROBES
        depends on !PREEMPT
-       depends on HAVE_OPTPROBES
        select KALLSYMS_ALL
-       help
-         This option will allow kprobes to optimize breakpoint to
-         a jump for reducing its overhead.
 
 config HAVE_EFFICIENT_UNALIGNED_ACCESS
        bool
@@ -142,6 +137,17 @@ config HAVE_HW_BREAKPOINT
        bool
        depends on PERF_EVENTS
 
+config HAVE_MIXED_BREAKPOINTS_REGS
+       bool
+       depends on HAVE_HW_BREAKPOINT
+       help
+         Depending on the arch implementation of hardware breakpoints,
+         some of them have separate registers for data and instruction
+         breakpoints addresses, others have mixed registers to store
+         them but define the access type in a control register.
+         Select this option if your arch implements breakpoints under the
+         latter fashion.
+
 config HAVE_USER_RETURN_NOTIFIER
        bool
 
index 75291fd..b719398 100644 (file)
@@ -55,6 +55,9 @@ config ARCH_USES_GETTIMEOFFSET
        bool
        default y
 
+config GENERIC_CMOS_UPDATE
+        def_bool y
+
 config ZONE_DMA
        bool
        default y
index 610dff4..e756d04 100644 (file)
@@ -17,8 +17,8 @@
 #define ATOMIC_INIT(i)         ( (atomic_t) { (i) } )
 #define ATOMIC64_INIT(i)       ( (atomic64_t) { (i) } )
 
-#define atomic_read(v)         ((v)->counter + 0)
-#define atomic64_read(v)       ((v)->counter + 0)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
 
 #define atomic_set(v,i)                ((v)->counter = (i))
 #define atomic64_set(v,i)      ((v)->counter = (i))
index 15f3ae2..296da1d 100644 (file)
@@ -405,29 +405,31 @@ static inline int fls(int x)
 
 #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67)
 /* Whee.  EV67 can calculate it directly.  */
-static inline unsigned long hweight64(unsigned long w)
+static inline unsigned long __arch_hweight64(unsigned long w)
 {
        return __kernel_ctpop(w);
 }
 
-static inline unsigned int hweight32(unsigned int w)
+static inline unsigned int __arch_weight32(unsigned int w)
 {
-       return hweight64(w);
+       return __arch_hweight64(w);
 }
 
-static inline unsigned int hweight16(unsigned int w)
+static inline unsigned int __arch_hweight16(unsigned int w)
 {
-       return hweight64(w & 0xffff);
+       return __arch_hweight64(w & 0xffff);
 }
 
-static inline unsigned int hweight8(unsigned int w)
+static inline unsigned int __arch_hweight8(unsigned int w)
 {
-       return hweight64(w & 0xff);
+       return __arch_hweight64(w & 0xff);
 }
 #else
-#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/arch_hweight.h>
 #endif
 
+#include <asm-generic/bitops/const_hweight.h>
+
 #endif /* __KERNEL__ */
 
 #include <asm-generic/bitops/find.h>
index b3e8886..6f32f9c 100644 (file)
@@ -77,7 +77,7 @@ register struct thread_info *__current_thread_info __asm__("$8");
 #define TIF_UAC_NOPRINT                10      /* see sysinfo.h */
 #define TIF_UAC_NOFIX          11
 #define TIF_UAC_SIGBUS         12
-#define TIF_MEMDIE             13
+#define TIF_MEMDIE             13      /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    14      /* restore signal mask in do_signal */
 #define TIF_FREEZE             16      /* is freezing for suspend */
 
index 5d08266..5465e93 100644 (file)
@@ -75,8 +75,6 @@ static struct {
        __u32 last_time;
        /* ticks/cycle * 2^48 */
        unsigned long scaled_ticks_per_cycle;
-       /* last time the CMOS clock got updated */
-       time_t last_rtc_update;
        /* partial unused tick */
        unsigned long partial_tick;
 } state;
@@ -91,6 +89,52 @@ static inline __u32 rpcc(void)
     return result;
 }
 
+int update_persistent_clock(struct timespec now)
+{
+       return set_rtc_mmss(now.tv_sec);
+}
+
+void read_persistent_clock(struct timespec *ts)
+{
+       unsigned int year, mon, day, hour, min, sec, epoch;
+
+       sec = CMOS_READ(RTC_SECONDS);
+       min = CMOS_READ(RTC_MINUTES);
+       hour = CMOS_READ(RTC_HOURS);
+       day = CMOS_READ(RTC_DAY_OF_MONTH);
+       mon = CMOS_READ(RTC_MONTH);
+       year = CMOS_READ(RTC_YEAR);
+
+       if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
+               sec = bcd2bin(sec);
+               min = bcd2bin(min);
+               hour = bcd2bin(hour);
+               day = bcd2bin(day);
+               mon = bcd2bin(mon);
+               year = bcd2bin(year);
+       }
+
+       /* PC-like is standard; used for year >= 70 */
+       epoch = 1900;
+       if (year < 20)
+               epoch = 2000;
+       else if (year >= 20 && year < 48)
+               /* NT epoch */
+               epoch = 1980;
+       else if (year >= 48 && year < 70)
+               /* Digital UNIX epoch */
+               epoch = 1952;
+
+       printk(KERN_INFO "Using epoch = %d\n", epoch);
+
+       if ((year += epoch) < 1970)
+               year += 100;
+
+       ts->tv_sec = mktime(year, mon, day, hour, min, sec);
+}
+
+
+
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick
@@ -123,19 +167,6 @@ irqreturn_t timer_interrupt(int irq, void *dev)
        if (nticks)
                do_timer(nticks);
 
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        */
-       if (ntp_synced()
-           && xtime.tv_sec > state.last_rtc_update + 660
-           && xtime.tv_nsec >= 500000 - ((unsigned) TICK_SIZE) / 2
-           && xtime.tv_nsec <= 500000 + ((unsigned) TICK_SIZE) / 2) {
-               int tmp = set_rtc_mmss(xtime.tv_sec);
-               state.last_rtc_update = xtime.tv_sec - (tmp ? 600 : 0);
-       }
-
        write_sequnlock(&xtime_lock);
 
 #ifndef CONFIG_SMP
@@ -304,7 +335,7 @@ rpcc_after_update_in_progress(void)
 void __init
 time_init(void)
 {
-       unsigned int year, mon, day, hour, min, sec, cc1, cc2, epoch;
+       unsigned int cc1, cc2;
        unsigned long cycle_freq, tolerance;
        long diff;
 
@@ -348,43 +379,6 @@ time_init(void)
           bogomips yet, but this is close on a 500Mhz box.  */
        __delay(1000000);
 
-       sec = CMOS_READ(RTC_SECONDS);
-       min = CMOS_READ(RTC_MINUTES);
-       hour = CMOS_READ(RTC_HOURS);
-       day = CMOS_READ(RTC_DAY_OF_MONTH);
-       mon = CMOS_READ(RTC_MONTH);
-       year = CMOS_READ(RTC_YEAR);
-
-       if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
-               sec = bcd2bin(sec);
-               min = bcd2bin(min);
-               hour = bcd2bin(hour);
-               day = bcd2bin(day);
-               mon = bcd2bin(mon);
-               year = bcd2bin(year);
-       }
-
-       /* PC-like is standard; used for year >= 70 */
-       epoch = 1900;
-       if (year < 20)
-               epoch = 2000;
-       else if (year >= 20 && year < 48)
-               /* NT epoch */
-               epoch = 1980;
-       else if (year >= 48 && year < 70)
-               /* Digital UNIX epoch */
-               epoch = 1952;
-
-       printk(KERN_INFO "Using epoch = %d\n", epoch);
-
-       if ((year += epoch) < 1970)
-               year += 100;
-
-       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       xtime.tv_nsec = 0;
-
-        wall_to_monotonic.tv_sec -= xtime.tv_sec;
-        wall_to_monotonic.tv_nsec = 0;
 
        if (HZ > (1<<16)) {
                extern void __you_loose (void);
@@ -394,7 +388,6 @@ time_init(void)
        state.last_time = cc1;
        state.scaled_ticks_per_cycle
                = ((unsigned long) HZ << FIX_SHIFT) / cycle_freq;
-       state.last_rtc_update = 0;
        state.partial_tick = 0L;
 
        /* Startup the timer source. */
index 92622eb..2d70cec 100644 (file)
@@ -13,7 +13,7 @@ config ARM
        select RTC_LIB
        select SYS_SUPPORTS_APM_EMULATION
        select GENERIC_ATOMIC64 if (!CPU_32v6K)
-       select HAVE_OPROFILE
+       select HAVE_OPROFILE if (HAVE_PERF_EVENTS)
        select HAVE_ARCH_KGDB
        select HAVE_KPROBES if (!XIP_KERNEL)
        select HAVE_KRETPROBES if (HAVE_KPROBES)
@@ -21,6 +21,7 @@ config ARM
        select HAVE_GENERIC_DMA_COHERENT
        select HAVE_KERNEL_GZIP
        select HAVE_KERNEL_LZO
+       select HAVE_KERNEL_LZMA
        select HAVE_PERF_EVENTS
        select PERF_USE_VMALLOC
        help
@@ -42,6 +43,11 @@ config GENERIC_GPIO
 
 config GENERIC_TIME
        bool
+       default y
+
+config ARCH_USES_GETTIMEOFFSET
+       bool
+       default n
 
 config GENERIC_CLOCKEVENTS
        bool
@@ -175,28 +181,6 @@ config ARM_L1_CACHE_SHIFT_6
        help
          Setting ARM L1 cache line size to 64 Bytes.
 
-if OPROFILE
-
-config OPROFILE_ARMV6
-       def_bool y
-       depends on CPU_V6 && !SMP
-       select OPROFILE_ARM11_CORE
-
-config OPROFILE_MPCORE
-       def_bool y
-       depends on CPU_V6 && SMP
-       select OPROFILE_ARM11_CORE
-
-config OPROFILE_ARM11_CORE
-       bool
-
-config OPROFILE_ARMV7
-       def_bool y
-       depends on CPU_V7 && !SMP
-       bool
-
-endif
-
 config VECTORS_BASE
        hex
        default 0xffff0000 if MMU || CPU_HIGH_VECTOR
@@ -231,6 +215,7 @@ config ARCH_AAEC2000
        select CPU_ARM920T
        select ARM_AMBA
        select HAVE_CLK
+       select ARCH_USES_GETTIMEOFFSET
        help
          This enables support for systems based on the Agilent AAEC-2000
 
@@ -238,21 +223,22 @@ config ARCH_INTEGRATOR
        bool "ARM Ltd. Integrator family"
        select ARM_AMBA
        select ARCH_HAS_CPUFREQ
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select ICST525
+       select ICST
+       select GENERIC_CLOCKEVENTS
+       select PLAT_VERSATILE
        help
          Support for ARM's Integrator platform.
 
 config ARCH_REALVIEW
        bool "ARM Ltd. RealView family"
        select ARM_AMBA
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select ICST307
-       select GENERIC_TIME
+       select ICST
        select GENERIC_CLOCKEVENTS
        select ARCH_WANT_OPTIONAL_GPIOLIB
+       select PLAT_VERSATILE
+       select ARM_TIMER_SP804
        select GPIO_PL061 if GPIOLIB
        help
          This enables support for ARM Ltd RealView boards.
@@ -261,20 +247,33 @@ config ARCH_VERSATILE
        bool "ARM Ltd. Versatile family"
        select ARM_AMBA
        select ARM_VIC
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select ICST307
-       select GENERIC_TIME
+       select ICST
        select GENERIC_CLOCKEVENTS
        select ARCH_WANT_OPTIONAL_GPIOLIB
+       select PLAT_VERSATILE
+       select ARM_TIMER_SP804
        help
          This enables support for ARM Ltd Versatile board.
 
+config ARCH_VEXPRESS
+       bool "ARM Ltd. Versatile Express family"
+       select ARCH_WANT_OPTIONAL_GPIOLIB
+       select ARM_AMBA
+       select ARM_TIMER_SP804
+       select COMMON_CLKDEV
+       select GENERIC_CLOCKEVENTS
+       select HAVE_CLK
+       select ICST
+       select PLAT_VERSATILE
+       help
+         This enables support for the ARM Ltd Versatile Express boards.
+
 config ARCH_AT91
        bool "Atmel AT91"
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
        select HAVE_CLK
+       select ARCH_USES_GETTIMEOFFSET
        help
          This enables support for systems based on the Atmel AT91RM9200,
          AT91SAM9 and AT91CAP9 processors.
@@ -285,7 +284,6 @@ config ARCH_BCMRING
        select CPU_V6
        select ARM_AMBA
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select ARCH_WANT_OPTIONAL_GPIOLIB
        help
@@ -294,14 +292,23 @@ config ARCH_BCMRING
 config ARCH_CLPS711X
        bool "Cirrus Logic CLPS711x/EP721x-based"
        select CPU_ARM720T
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for Cirrus Logic 711x/721x based boards.
 
+config ARCH_CNS3XXX
+       bool "Cavium Networks CNS3XXX family"
+       select CPU_V6
+       select GENERIC_CLOCKEVENTS
+       select ARM_GIC
+       help
+         Support for Cavium Networks CNS3XXX platform.
+
 config ARCH_GEMINI
        bool "Cortina Systems Gemini"
        select CPU_FA526
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for the Cortina Systems Gemini family SoCs
 
@@ -310,6 +317,7 @@ config ARCH_EBSA110
        select CPU_SA110
        select ISA
        select NO_IOPORT
+       select ARCH_USES_GETTIMEOFFSET
        help
          This is an evaluation board for the StrongARM processor available
          from Digital. It has limited hardware on-board, including an
@@ -321,11 +329,10 @@ config ARCH_EP93XX
        select CPU_ARM920T
        select ARM_AMBA
        select ARM_VIC
-       select GENERIC_GPIO
-       select HAVE_CLK
        select COMMON_CLKDEV
        select ARCH_REQUIRE_GPIOLIB
        select ARCH_HAS_HOLES_MEMORYMODEL
+       select ARCH_USES_GETTIMEOFFSET
        help
          This enables support for the Cirrus EP93xx series of CPUs.
 
@@ -333,16 +340,15 @@ config ARCH_FOOTBRIDGE
        bool "FootBridge"
        select CPU_SA110
        select FOOTBRIDGE
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for systems based on the DC21285 companion chip
          ("FootBridge"), such as the Simtec CATS and the Rebel NetWinder.
 
 config ARCH_MXC
        bool "Freescale MXC/iMX-based"
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select ARCH_REQUIRE_GPIOLIB
-       select HAVE_CLK
        select COMMON_CLKDEV
        help
          Support for Freescale MXC/iMX-based family of processors
@@ -350,12 +356,9 @@ config ARCH_MXC
 config ARCH_STMP3XXX
        bool "Freescale STMP3xxx"
        select CPU_ARM926T
-       select HAVE_CLK
        select COMMON_CLKDEV
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
-       select GENERIC_GPIO
        select USB_ARCH_HAS_EHCI
        help
          Support for systems based on the Freescale 3xxx CPUs.
@@ -365,7 +368,6 @@ config ARCH_NETX
        select CPU_ARM926T
        select ARM_VIC
        select GENERIC_CLOCKEVENTS
-       select GENERIC_TIME
        help
          This enables support for systems based on the Hilscher NetX Soc
 
@@ -373,6 +375,7 @@ config ARCH_H720X
        bool "Hynix HMS720x-based"
        select CPU_ARM720T
        select ISA_DMA_API
+       select ARCH_USES_GETTIMEOFFSET
        help
          This enables support for systems based on the Hynix HMS720x
 
@@ -393,7 +396,6 @@ config ARCH_IOP32X
        select CPU_XSCALE
        select PLAT_IOP
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
        help
          Support for Intel's 80219 and IOP32X (XScale) family of
@@ -405,7 +407,6 @@ config ARCH_IOP33X
        select CPU_XSCALE
        select PLAT_IOP
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
        help
          Support for Intel's IOP33X (XScale) family of processors.
@@ -415,6 +416,7 @@ config ARCH_IXP23XX
        depends on MMU
        select CPU_XSC3
        select PCI
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for Intel's IXP23xx (XScale) family of processors.
 
@@ -423,6 +425,7 @@ config ARCH_IXP2000
        depends on MMU
        select CPU_XSCALE
        select PCI
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for Intel's IXP2400/2800 (XScale) family of processors.
 
@@ -431,7 +434,6 @@ config ARCH_IXP4XX
        depends on MMU
        select CPU_XSCALE
        select GENERIC_GPIO
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select DMABOUNCE if PCI
        help
@@ -441,6 +443,7 @@ config ARCH_L7200
        bool "LinkUp-L7200"
        select CPU_ARM720T
        select FIQ
+       select ARCH_USES_GETTIMEOFFSET
        help
          Say Y here if you intend to run this kernel on a LinkUp Systems
          L7200 Software Development Board which uses an ARM720T processor.
@@ -454,9 +457,7 @@ config ARCH_L7200
 config ARCH_DOVE
        bool "Marvell Dove"
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select PLAT_ORION
        help
@@ -466,9 +467,7 @@ config ARCH_KIRKWOOD
        bool "Marvell Kirkwood"
        select CPU_FEROCEON
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select PLAT_ORION
        help
@@ -478,7 +477,6 @@ config ARCH_KIRKWOOD
 config ARCH_LOKI
        bool "Marvell Loki (88RC8480)"
        select CPU_FEROCEON
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select PLAT_ORION
        help
@@ -488,9 +486,7 @@ config ARCH_MV78XX0
        bool "Marvell MV78xx0"
        select CPU_FEROCEON
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select PLAT_ORION
        help
@@ -502,9 +498,7 @@ config ARCH_ORION5X
        depends on MMU
        select CPU_FEROCEON
        select PCI
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select PLAT_ORION
        help
@@ -515,11 +509,8 @@ config ARCH_ORION5X
 config ARCH_MMP
        bool "Marvell PXA168/910/MMP2"
        depends on MMU
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select TICK_ONESHOT
        select PLAT_PXA
@@ -529,8 +520,8 @@ config ARCH_MMP
 config ARCH_KS8695
        bool "Micrel/Kendin KS8695"
        select CPU_ARM922T
-       select GENERIC_GPIO
-        select ARCH_REQUIRE_GPIOLIB
+       select ARCH_REQUIRE_GPIOLIB
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for Micrel/Kendin KS8695 "Centaur" (ARM922T) based
          System-on-Chip devices.
@@ -539,7 +530,6 @@ config ARCH_NS9XXX
        bool "NetSilicon NS9xxx"
        select CPU_ARM926T
        select GENERIC_GPIO
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_CLK
        help
@@ -552,10 +542,7 @@ config ARCH_W90X900
        bool "Nuvoton W90X900 CPU"
        select CPU_ARM926T
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_GPIO
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        help
          Support for Nuvoton (Winbond logic dept.) ARM9 processor,
@@ -569,7 +556,6 @@ config ARCH_W90X900
 config ARCH_NUC93X
        bool "Nuvoton NUC93X CPU"
        select CPU_ARM926T
-       select HAVE_CLK
        select COMMON_CLKDEV
        help
          Support for Nuvoton (Winbond logic dept.) NUC93X MCU,The NUC93X is a
@@ -578,8 +564,8 @@ config ARCH_NUC93X
 config ARCH_PNX4008
        bool "Philips Nexperia PNX4008 Mobile"
        select CPU_ARM926T
-       select HAVE_CLK
        select COMMON_CLKDEV
+       select ARCH_USES_GETTIMEOFFSET
        help
          This enables support for Philips PNX4008 mobile platform.
 
@@ -588,11 +574,8 @@ config ARCH_PXA
        depends on MMU
        select ARCH_MTD_XIP
        select ARCH_HAS_CPUFREQ
-       select GENERIC_GPIO
-       select HAVE_CLK
        select COMMON_CLKDEV
        select ARCH_REQUIRE_GPIOLIB
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select TICK_ONESHOT
        select PLAT_PXA
@@ -601,14 +584,14 @@ config ARCH_PXA
 
 config ARCH_MSM
        bool "Qualcomm MSM"
-       select CPU_V6
-       select GENERIC_TIME
+       select HAVE_CLK
        select GENERIC_CLOCKEVENTS
        help
-         Support for Qualcomm MSM7K based systems.  This runs on the ARM11
-         apps processor of the MSM7K and depends on a shared memory
-         interface to the ARM9 modem processor which runs the baseband stack
-         and controls some vital subsystems (clock and power control, etc).
+         Support for Qualcomm MSM/QSD based systems.  This runs on the
+         apps processor of the MSM/QSD and depends on a shared memory
+         interface to the modem processor which runs the baseband
+         stack and controls some vital subsystems
+         (clock and power control, etc).
 
 config ARCH_SHMOBILE
        bool "Renesas SH-Mobile"
@@ -625,6 +608,7 @@ config ARCH_RPC
        select ISA_DMA_API
        select NO_IOPORT
        select ARCH_SPARSEMEM_ENABLE
+       select ARCH_USES_GETTIMEOFFSET
        help
          On the Acorn Risc-PC, Linux can support the internal IDE disk and
          CD-ROM interface, serial and parallel port, and the floppy drive.
@@ -637,8 +621,6 @@ config ARCH_SA1100
        select ARCH_MTD_XIP
        select ARCH_HAS_CPUFREQ
        select CPU_FREQ
-       select GENERIC_GPIO
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_CLK
        select TICK_ONESHOT
@@ -647,23 +629,28 @@ config ARCH_SA1100
          Support for StrongARM 11x0 based boards.
 
 config ARCH_S3C2410
-       bool "Samsung S3C2410, S3C2412, S3C2413, S3C2440, S3C2442, S3C2443"
+       bool "Samsung S3C2410, S3C2412, S3C2413, S3C2416, S3C2440, S3C2442, S3C2443, S3C2450"
        select GENERIC_GPIO
        select ARCH_HAS_CPUFREQ
        select HAVE_CLK
+       select ARCH_USES_GETTIMEOFFSET
        help
          Samsung S3C2410X CPU based systems, such as the Simtec Electronics
          BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
          the Samsung SMDK2410 development board (and derivatives).
 
+         Note, the S3C2416 and the S3C2450 are so close that they even share
+         the same SoC ID code. This means that there is no seperate machine
+         directory (no arch/arm/mach-s3c2450) as the S3C2416 was first.
+
 config ARCH_S3C64XX
        bool "Samsung S3C64XX"
        select PLAT_SAMSUNG
        select CPU_V6
-       select GENERIC_GPIO
        select ARM_VIC
        select HAVE_CLK
        select NO_IOPORT
+       select ARCH_USES_GETTIMEOFFSET
        select ARCH_HAS_CPUFREQ
        select ARCH_REQUIRE_GPIOLIB
        select SAMSUNG_CLKSRC
@@ -720,6 +707,7 @@ config ARCH_SHARK
        select ISA_DMA
        select ZONE_DMA
        select PCI
+       select ARCH_USES_GETTIMEOFFSET
        help
          Support for the StrongARM based Digital DNARD machine, also known
          as "Shark" (<http://www.shark-linux.de/shark.html>).
@@ -729,6 +717,7 @@ config ARCH_LH7A40X
        select CPU_ARM922T
        select ARCH_DISCONTIGMEM_ENABLE if !LH7A40X_CONTIGMEM
        select ARCH_SPARSEMEM_ENABLE if !LH7A40X_CONTIGMEM
+       select ARCH_USES_GETTIMEOFFSET
        help
          Say Y here for systems based on one of the Sharp LH7A40X
          System on a Chip processors.  These CPUs include an ARM922T
@@ -742,9 +731,7 @@ config ARCH_U300
        select HAVE_TCM
        select ARM_AMBA
        select ARM_VIC
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
-       select HAVE_CLK
        select COMMON_CLKDEV
        select GENERIC_GPIO
        help
@@ -754,9 +741,9 @@ config ARCH_U8500
        bool "ST-Ericsson U8500 Series"
        select CPU_V7
        select ARM_AMBA
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select COMMON_CLKDEV
+       select ARCH_REQUIRE_GPIOLIB
        help
          Support for ST-Ericsson's Ux500 architecture
 
@@ -765,23 +752,16 @@ config ARCH_NOMADIK
        select ARM_AMBA
        select ARM_VIC
        select CPU_ARM926T
-       select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
        help
          Support for the Nomadik platform by ST-Ericsson
 
 config ARCH_DAVINCI
        bool "TI DaVinci"
-       select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
-       select GENERIC_GPIO
        select ARCH_REQUIRE_GPIOLIB
-       select HAVE_CLK
        select ZONE_DMA
        select HAVE_IDE
        select COMMON_CLKDEV
@@ -792,16 +772,24 @@ config ARCH_DAVINCI
 
 config ARCH_OMAP
        bool "TI OMAP"
-       select GENERIC_GPIO
        select HAVE_CLK
        select ARCH_REQUIRE_GPIOLIB
        select ARCH_HAS_CPUFREQ
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select ARCH_HAS_HOLES_MEMORYMODEL
        help
          Support for TI's OMAP platform (OMAP1 and OMAP2).
 
+config PLAT_SPEAR
+       bool "ST SPEAr"
+       select ARM_AMBA
+       select ARCH_REQUIRE_GPIOLIB
+       select COMMON_CLKDEV
+       select GENERIC_CLOCKEVENTS
+       select HAVE_CLK
+       help
+         Support for ST's SPEAr platform (SPEAr3xx, SPEAr6xx and SPEAr13xx).
+
 endchoice
 
 #
@@ -817,6 +805,8 @@ source "arch/arm/mach-bcmring/Kconfig"
 
 source "arch/arm/mach-clps711x/Kconfig"
 
+source "arch/arm/mach-cns3xxx/Kconfig"
+
 source "arch/arm/mach-davinci/Kconfig"
 
 source "arch/arm/mach-dove/Kconfig"
@@ -887,11 +877,13 @@ source "arch/arm/plat-samsung/Kconfig"
 source "arch/arm/plat-s3c24xx/Kconfig"
 source "arch/arm/plat-s5p/Kconfig"
 source "arch/arm/plat-s5pc1xx/Kconfig"
+source "arch/arm/plat-spear/Kconfig"
 
 if ARCH_S3C2410
 source "arch/arm/mach-s3c2400/Kconfig"
 source "arch/arm/mach-s3c2410/Kconfig"
 source "arch/arm/mach-s3c2412/Kconfig"
+source "arch/arm/mach-s3c2416/Kconfig"
 source "arch/arm/mach-s3c2440/Kconfig"
 source "arch/arm/mach-s3c2443/Kconfig"
 endif
@@ -920,6 +912,8 @@ source "arch/arm/mach-ux500/Kconfig"
 
 source "arch/arm/mach-versatile/Kconfig"
 
+source "arch/arm/mach-vexpress/Kconfig"
+
 source "arch/arm/mach-w90x900/Kconfig"
 
 # Definitions to make life easier
@@ -929,7 +923,6 @@ config ARCH_ACORN
 config PLAT_IOP
        bool
        select GENERIC_CLOCKEVENTS
-       select GENERIC_TIME
 
 config PLAT_ORION
        bool
@@ -937,6 +930,12 @@ config PLAT_ORION
 config PLAT_PXA
        bool
 
+config PLAT_VERSATILE
+       bool
+
+config ARM_TIMER_SP804
+       bool
+
 source arch/arm/mm/Kconfig
 
 config IWMMXT
@@ -1065,6 +1064,10 @@ config PCI
          your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
          VESA. If you have PCI, say Y, otherwise N.
 
+config PCI_DOMAINS
+       bool
+       depends on PCI
+
 config PCI_SYSCALL
        def_bool PCI
 
@@ -1093,10 +1096,11 @@ source "kernel/time/Kconfig"
 config SMP
        bool "Symmetric Multi-Processing (EXPERIMENTAL)"
        depends on EXPERIMENTAL && (REALVIEW_EB_ARM11MP || REALVIEW_EB_A9MP ||\
-                MACH_REALVIEW_PB11MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || ARCH_U8500)
+                MACH_REALVIEW_PB11MP || MACH_REALVIEW_PBX || ARCH_OMAP4 ||\
+                ARCH_U8500 || ARCH_VEXPRESS_CA9X4)
        depends on GENERIC_CLOCKEVENTS
        select USE_GENERIC_SMP_HELPERS
-       select HAVE_ARM_SCU if (ARCH_REALVIEW || ARCH_OMAP4 || ARCH_U8500)
+       select HAVE_ARM_SCU if (ARCH_REALVIEW || ARCH_OMAP4 || ARCH_U8500 || ARCH_VEXPRESS_CA9X4)
        help
          This enables support for systems with more than one CPU. If you have
          a system with only one CPU, like most personal computers, say N. If
@@ -1277,7 +1281,7 @@ config HIGHPTE
 
 config HW_PERF_EVENTS
        bool "Enable hardware performance counter support for perf events"
-       depends on PERF_EVENTS && CPU_HAS_PMU && (CPU_V6 || CPU_V7)
+       depends on PERF_EVENTS && CPU_HAS_PMU
        default y
        help
          Enable hardware performance counter support for perf events. If
index ed820e7..4b857fb 100644 (file)
@@ -110,6 +110,8 @@ CHECKFLAGS  += -D__arm__
 head-y         := arch/arm/kernel/head$(MMUEXT).o arch/arm/kernel/init_task.o
 textofs-y      := 0x00008000
 textofs-$(CONFIG_ARCH_CLPS711X) := 0x00028000
+# We don't want the htc bootloader to corrupt kernel during resume
+textofs-$(CONFIG_PM_H1940)      := 0x00108000
 # SA1111 DMA bug: we don't want the kernel to live in precious DMA-able memory
 ifeq ($(CONFIG_ARCH_SA1100),y)
 textofs-$(CONFIG_SA1111) := 0x00208000
@@ -121,6 +123,7 @@ machine-$(CONFIG_ARCH_AAEC2000)             := aaec2000
 machine-$(CONFIG_ARCH_AT91)            := at91
 machine-$(CONFIG_ARCH_BCMRING)         := bcmring
 machine-$(CONFIG_ARCH_CLPS711X)                := clps711x
+machine-$(CONFIG_ARCH_CNS3XXX)         := cns3xxx
 machine-$(CONFIG_ARCH_DAVINCI)         := davinci
 machine-$(CONFIG_ARCH_DOVE)            := dove
 machine-$(CONFIG_ARCH_EBSA110)         := ebsa110
@@ -160,7 +163,7 @@ machine-$(CONFIG_ARCH_PNX4008)              := pnx4008
 machine-$(CONFIG_ARCH_PXA)             := pxa
 machine-$(CONFIG_ARCH_REALVIEW)                := realview
 machine-$(CONFIG_ARCH_RPC)             := rpc
-machine-$(CONFIG_ARCH_S3C2410)         := s3c2410 s3c2400 s3c2412 s3c2440 s3c2443
+machine-$(CONFIG_ARCH_S3C2410)         := s3c2410 s3c2400 s3c2412 s3c2416 s3c2440 s3c2443
 machine-$(CONFIG_ARCH_S3C24A0)         := s3c24a0
 machine-$(CONFIG_ARCH_S3C64XX)         := s3c64xx
 machine-$(CONFIG_ARCH_S5P6440)         := s5p6440
@@ -175,9 +178,14 @@ machine-$(CONFIG_ARCH_STMP37XX)            := stmp37xx
 machine-$(CONFIG_ARCH_U300)            := u300
 machine-$(CONFIG_ARCH_U8500)           := ux500
 machine-$(CONFIG_ARCH_VERSATILE)       := versatile
+machine-$(CONFIG_ARCH_VEXPRESS)                := vexpress
 machine-$(CONFIG_ARCH_W90X900)         := w90x900
 machine-$(CONFIG_ARCH_NUC93X)          := nuc93x
 machine-$(CONFIG_FOOTBRIDGE)           := footbridge
+machine-$(CONFIG_MACH_SPEAR300)                := spear3xx
+machine-$(CONFIG_MACH_SPEAR310)                := spear3xx
+machine-$(CONFIG_MACH_SPEAR320)                := spear3xx
+machine-$(CONFIG_MACH_SPEAR600)                := spear6xx
 
 # Platform directory name.  This list is sorted alphanumerically
 # by CONFIG_* macro name.
@@ -192,6 +200,8 @@ plat-$(CONFIG_PLAT_PXA)             := pxa
 plat-$(CONFIG_PLAT_S3C24XX)    := s3c24xx samsung
 plat-$(CONFIG_PLAT_S5PC1XX)    := s5pc1xx samsung
 plat-$(CONFIG_PLAT_S5P)                := s5p samsung
+plat-$(CONFIG_PLAT_SPEAR)      := spear
+plat-$(CONFIG_PLAT_VERSATILE)  := versatile
 
 ifeq ($(CONFIG_ARCH_EBSA110),y)
 # This is what happens if you forget the IOCS16 line.
index 97c89e7..53faa90 100644 (file)
@@ -65,6 +65,7 @@ SEDFLAGS      = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
 
 suffix_$(CONFIG_KERNEL_GZIP) = gzip
 suffix_$(CONFIG_KERNEL_LZO)  = lzo
+suffix_$(CONFIG_KERNEL_LZMA) = lzma
 
 targets       := vmlinux vmlinux.lds \
                 piggy.$(suffix_y) piggy.$(suffix_y).o \
index 9c09707..4c72a97 100644 (file)
@@ -40,6 +40,10 @@ extern void error(char *);
 #include "../../../../lib/decompress_unlzo.c"
 #endif
 
+#ifdef CONFIG_KERNEL_LZMA
+#include "../../../../lib/decompress_unlzma.c"
+#endif
+
 void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x))
 {
        decompress(input, len, NULL, NULL, output, NULL, error);
diff --git a/arch/arm/boot/compressed/piggy.lzma.S b/arch/arm/boot/compressed/piggy.lzma.S
new file mode 100644 (file)
index 0000000..d7e69cf
--- /dev/null
@@ -0,0 +1,6 @@
+       .section .piggydata,#alloc
+       .globl  input_data
+input_data:
+       .incbin "arch/arm/boot/compressed/piggy.lzma"
+       .globl  input_data_end
+input_data_end:
index 4efbb9d..0a34c81 100644 (file)
@@ -12,10 +12,10 @@ config ARM_VIC_NR
          The maximum number of VICs available in the system, for
          power management.
 
-config ICST525
+config ICST
        bool
 
-config ICST307
+config PL330
        bool
 
 config SA1111
@@ -40,3 +40,4 @@ config SHARP_SCOOP
 
 config COMMON_CLKDEV
        bool
+       select HAVE_CLK
index 76be7ff..e6e8664 100644 (file)
@@ -4,8 +4,8 @@
 
 obj-$(CONFIG_ARM_GIC)          += gic.o
 obj-$(CONFIG_ARM_VIC)          += vic.o
-obj-$(CONFIG_ICST525)          += icst525.o
-obj-$(CONFIG_ICST307)          += icst307.o
+obj-$(CONFIG_ICST)             += icst.o
+obj-$(CONFIG_PL330)            += pl330.o
 obj-$(CONFIG_SA1111)           += sa1111.o
 obj-$(CONFIG_PCI_HOST_VIA82C505) += via82c505.o
 obj-$(CONFIG_DMABOUNCE)                += dmabounce.o
index dba4c1d..e2b2bb6 100644 (file)
@@ -53,12 +53,13 @@ static struct clk *clk_find(const char *dev_id, const char *con_id)
                                continue;
                        match += 1;
                }
-               if (match == 0)
-                       continue;
 
                if (match > best) {
                        clk = p->clk;
-                       best = match;
+                       if (match != 3)
+                               best = match;
+                       else
+                               break;
                }
        }
        return clk;
diff --git a/arch/arm/common/icst.c b/arch/arm/common/icst.c
new file mode 100644 (file)
index 0000000..9a7f09c
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *  linux/arch/arm/common/icst307.c
+ *
+ *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ *  Support functions for calculating clocks/divisors for the ICST307
+ *  clock generators.  See http://www.icst.com/ for more information
+ *  on these devices.
+ *
+ *  This is an almost identical implementation to the ICST525 clock generator.
+ *  The s2div and idx2s files are different
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+#include <asm/hardware/icst.h>
+
+/*
+ * Divisors for each OD setting.
+ */
+const unsigned char icst307_s2div[8] = { 10, 2, 8, 4, 5, 7, 3, 6 };
+const unsigned char icst525_s2div[8] = { 10, 2, 8, 4, 5, 7, 9, 6 };
+EXPORT_SYMBOL(icst307_s2div);
+EXPORT_SYMBOL(icst525_s2div);
+
+unsigned long icst_hz(const struct icst_params *p, struct icst_vco vco)
+{
+       return p->ref * 2 * (vco.v + 8) / ((vco.r + 2) * p->s2div[vco.s]);
+}
+
+EXPORT_SYMBOL(icst_hz);
+
+/*
+ * Ascending divisor S values.
+ */
+const unsigned char icst307_idx2s[8] = { 1, 6, 3, 4, 7, 5, 2, 0 };
+const unsigned char icst525_idx2s[8] = { 1, 3, 4, 7, 5, 2, 6, 0 };
+EXPORT_SYMBOL(icst307_idx2s);
+EXPORT_SYMBOL(icst525_idx2s);
+
+struct icst_vco
+icst_hz_to_vco(const struct icst_params *p, unsigned long freq)
+{
+       struct icst_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max };
+       unsigned long f;
+       unsigned int i = 0, rd, best = (unsigned int)-1;
+
+       /*
+        * First, find the PLL output divisor such
+        * that the PLL output is within spec.
+        */
+       do {
+               f = freq * p->s2div[p->idx2s[i]];
+
+               if (f > p->vco_min && f <= p->vco_max)
+                       break;
+       } while (i < 8);
+
+       if (i >= 8)
+               return vco;
+
+       vco.s = p->idx2s[i];
+
+       /*
+        * Now find the closest divisor combination
+        * which gives a PLL output of 'f'.
+        */
+       for (rd = p->rd_min; rd <= p->rd_max; rd++) {
+               unsigned long fref_div, f_pll;
+               unsigned int vd;
+               int f_diff;
+
+               fref_div = (2 * p->ref) / rd;
+
+               vd = (f + fref_div / 2) / fref_div;
+               if (vd < p->vd_min || vd > p->vd_max)
+                       continue;
+
+               f_pll = fref_div * vd;
+               f_diff = f_pll - f;
+               if (f_diff < 0)
+                       f_diff = -f_diff;
+
+               if ((unsigned)f_diff < best) {
+                       vco.v = vd - 8;
+                       vco.r = rd - 2;
+                       if (f_diff == 0)
+                               break;
+                       best = f_diff;
+               }
+       }
+
+       return vco;
+}
+
+EXPORT_SYMBOL(icst_hz_to_vco);
diff --git a/arch/arm/common/icst307.c b/arch/arm/common/icst307.c
deleted file mode 100644 (file)
index 6d094c1..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- *  linux/arch/arm/common/icst307.c
- *
- *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
- * published by the Free Software Foundation.
- *
- *  Support functions for calculating clocks/divisors for the ICST307
- *  clock generators.  See http://www.icst.com/ for more information
- *  on these devices.
- *
- *  This is an almost identical implementation to the ICST525 clock generator.
- *  The s2div and idx2s files are different
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-
-#include <asm/hardware/icst307.h>
-
-/*
- * Divisors for each OD setting.
- */
-static unsigned char s2div[8] = { 10, 2, 8, 4, 5, 7, 3, 6 };
-
-unsigned long icst307_khz(const struct icst307_params *p, struct icst307_vco vco)
-{
-       return p->ref * 2 * (vco.v + 8) / ((vco.r + 2) * s2div[vco.s]);
-}
-
-EXPORT_SYMBOL(icst307_khz);
-
-/*
- * Ascending divisor S values.
- */
-static unsigned char idx2s[8] = { 1, 6, 3, 4, 7, 5, 2, 0 };
-
-struct icst307_vco
-icst307_khz_to_vco(const struct icst307_params *p, unsigned long freq)
-{
-       struct icst307_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max };
-       unsigned long f;
-       unsigned int i = 0, rd, best = (unsigned int)-1;
-
-       /*
-        * First, find the PLL output divisor such
-        * that the PLL output is within spec.
-        */
-       do {
-               f = freq * s2div[idx2s[i]];
-
-               /*
-                * f must be between 6MHz and 200MHz (3.3 or 5V)
-                */
-               if (f > 6000 && f <= p->vco_max)
-                       break;
-       } while (i < ARRAY_SIZE(idx2s));
-
-       if (i >= ARRAY_SIZE(idx2s))
-               return vco;
-
-       vco.s = idx2s[i];
-
-       /*
-        * Now find the closest divisor combination
-        * which gives a PLL output of 'f'.
-        */
-       for (rd = p->rd_min; rd <= p->rd_max; rd++) {
-               unsigned long fref_div, f_pll;
-               unsigned int vd;
-               int f_diff;
-
-               fref_div = (2 * p->ref) / rd;
-
-               vd = (f + fref_div / 2) / fref_div;
-               if (vd < p->vd_min || vd > p->vd_max)
-                       continue;
-
-               f_pll = fref_div * vd;
-               f_diff = f_pll - f;
-               if (f_diff < 0)
-                       f_diff = -f_diff;
-
-               if ((unsigned)f_diff < best) {
-                       vco.v = vd - 8;
-                       vco.r = rd - 2;
-                       if (f_diff == 0)
-                               break;
-                       best = f_diff;
-               }
-       }
-
-       return vco;
-}
-
-EXPORT_SYMBOL(icst307_khz_to_vco);
-
-struct icst307_vco
-icst307_ps_to_vco(const struct icst307_params *p, unsigned long period)
-{
-       struct icst307_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max };
-       unsigned long f, ps;
-       unsigned int i = 0, rd, best = (unsigned int)-1;
-
-       ps = 1000000000UL / p->vco_max;
-
-       /*
-        * First, find the PLL output divisor such
-        * that the PLL output is within spec.
-        */
-       do {
-               f = period / s2div[idx2s[i]];
-
-               /*
-                * f must be between 6MHz and 200MHz (3.3 or 5V)
-                */
-               if (f >= ps && f < 1000000000UL / 6000 + 1)
-                       break;
-       } while (i < ARRAY_SIZE(idx2s));
-
-       if (i >= ARRAY_SIZE(idx2s))
-               return vco;
-
-       vco.s = idx2s[i];
-
-       ps = 500000000UL / p->ref;
-
-       /*
-        * Now find the closest divisor combination
-        * which gives a PLL output of 'f'.
-        */
-       for (rd = p->rd_min; rd <= p->rd_max; rd++) {
-               unsigned long f_in_div, f_pll;
-               unsigned int vd;
-               int f_diff;
-
-               f_in_div = ps * rd;
-
-               vd = (f_in_div + f / 2) / f;
-               if (vd < p->vd_min || vd > p->vd_max)
-                       continue;
-
-               f_pll = (f_in_div + vd / 2) / vd;
-               f_diff = f_pll - f;
-               if (f_diff < 0)
-                       f_diff = -f_diff;
-
-               if ((unsigned)f_diff < best) {
-                       vco.v = vd - 8;
-                       vco.r = rd - 2;
-                       if (f_diff == 0)
-                               break;
-                       best = f_diff;
-               }
-       }
-
-       return vco;
-}
-
-EXPORT_SYMBOL(icst307_ps_to_vco);
diff --git a/arch/arm/common/icst525.c b/arch/arm/common/icst525.c
deleted file mode 100644 (file)
index 3d377c5..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- *  linux/arch/arm/common/icst525.c
- *
- *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
- * published by the Free Software Foundation.
- *
- *  Support functions for calculating clocks/divisors for the ICST525
- *  clock generators.  See http://www.icst.com/ for more information
- *  on these devices.
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-
-#include <asm/hardware/icst525.h>
-
-/*
- * Divisors for each OD setting.
- */
-static unsigned char s2div[8] = { 10, 2, 8, 4, 5, 7, 9, 6 };
-
-unsigned long icst525_khz(const struct icst525_params *p, struct icst525_vco vco)
-{
-       return p->ref * 2 * (vco.v + 8) / ((vco.r + 2) * s2div[vco.s]);
-}
-
-EXPORT_SYMBOL(icst525_khz);
-
-/*
- * Ascending divisor S values.
- */
-static unsigned char idx2s[] = { 1, 3, 4, 7, 5, 2, 6, 0 };
-
-struct icst525_vco
-icst525_khz_to_vco(const struct icst525_params *p, unsigned long freq)
-{
-       struct icst525_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max };
-       unsigned long f;
-       unsigned int i = 0, rd, best = (unsigned int)-1;
-
-       /*
-        * First, find the PLL output divisor such
-        * that the PLL output is within spec.
-        */
-       do {
-               f = freq * s2div[idx2s[i]];
-
-               /*
-                * f must be between 10MHz and
-                *  320MHz (5V) or 200MHz (3V)
-                */
-               if (f > 10000 && f <= p->vco_max)
-                       break;
-       } while (i < ARRAY_SIZE(idx2s));
-
-       if (i >= ARRAY_SIZE(idx2s))
-               return vco;
-
-       vco.s = idx2s[i];
-
-       /*
-        * Now find the closest divisor combination
-        * which gives a PLL output of 'f'.
-        */
-       for (rd = p->rd_min; rd <= p->rd_max; rd++) {
-               unsigned long fref_div, f_pll;
-               unsigned int vd;
-               int f_diff;
-
-               fref_div = (2 * p->ref) / rd;
-
-               vd = (f + fref_div / 2) / fref_div;
-               if (vd < p->vd_min || vd > p->vd_max)
-                       continue;
-
-               f_pll = fref_div * vd;
-               f_diff = f_pll - f;
-               if (f_diff < 0)
-                       f_diff = -f_diff;
-
-               if ((unsigned)f_diff < best) {
-                       vco.v = vd - 8;
-                       vco.r = rd - 2;
-                       if (f_diff == 0)
-                               break;
-                       best = f_diff;
-               }
-       }
-
-       return vco;
-}
-
-EXPORT_SYMBOL(icst525_khz_to_vco);
-
-struct icst525_vco
-icst525_ps_to_vco(const struct icst525_params *p, unsigned long period)
-{
-       struct icst525_vco vco = { .s = 1, .v = p->vd_max, .r = p->rd_max };
-       unsigned long f, ps;
-       unsigned int i = 0, rd, best = (unsigned int)-1;
-
-       ps = 1000000000UL / p->vco_max;
-
-       /*
-        * First, find the PLL output divisor such
-        * that the PLL output is within spec.
-        */
-       do {
-               f = period / s2div[idx2s[i]];
-
-               /*
-                * f must be between 10MHz and
-                *  320MHz (5V) or 200MHz (3V)
-                */
-               if (f >= ps && f < 100000)
-                       break;
-       } while (i < ARRAY_SIZE(idx2s));
-
-       if (i >= ARRAY_SIZE(idx2s))
-               return vco;
-
-       vco.s = idx2s[i];
-
-       ps = 500000000UL / p->ref;
-
-       /*
-        * Now find the closest divisor combination
-        * which gives a PLL output of 'f'.
-        */
-       for (rd = p->rd_min; rd <= p->rd_max; rd++) {
-               unsigned long f_in_div, f_pll;
-               unsigned int vd;
-               int f_diff;
-
-               f_in_div = ps * rd;
-
-               vd = (f_in_div + f / 2) / f;
-               if (vd < p->vd_min || vd > p->vd_max)
-                       continue;
-
-               f_pll = (f_in_div + vd / 2) / vd;
-               f_diff = f_pll - f;
-               if (f_diff < 0)
-                       f_diff = -f_diff;
-
-               if ((unsigned)f_diff < best) {
-                       vco.v = vd - 8;
-                       vco.r = rd - 2;
-                       if (f_diff == 0)
-                               break;
-                       best = f_diff;
-               }
-       }
-
-       return vco;
-}
-
-EXPORT_SYMBOL(icst525_ps_to_vco);
diff --git a/arch/arm/common/pl330.c b/arch/arm/common/pl330.c
new file mode 100644 (file)
index 0000000..5ebbab6
--- /dev/null
@@ -0,0 +1,1966 @@
+/* linux/arch/arm/common/pl330.c
+ *
+ * Copyright (C) 2010 Samsung Electronics Co Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+
+#include <asm/hardware/pl330.h>
+
+/* Register and Bit field Definitions */
+#define DS             0x0
+#define DS_ST_STOP     0x0
+#define DS_ST_EXEC     0x1
+#define DS_ST_CMISS    0x2
+#define DS_ST_UPDTPC   0x3
+#define DS_ST_WFE      0x4
+#define DS_ST_ATBRR    0x5
+#define DS_ST_QBUSY    0x6
+#define DS_ST_WFP      0x7
+#define DS_ST_KILL     0x8
+#define DS_ST_CMPLT    0x9
+#define DS_ST_FLTCMP   0xe
+#define DS_ST_FAULT    0xf
+
+#define DPC            0x4
+#define INTEN          0x20
+#define ES             0x24
+#define INTSTATUS      0x28
+#define INTCLR         0x2c
+#define FSM            0x30
+#define FSC            0x34
+#define FTM            0x38
+
+#define _FTC           0x40
+#define FTC(n)         (_FTC + (n)*0x4)
+
+#define _CS            0x100
+#define CS(n)          (_CS + (n)*0x8)
+#define CS_CNS         (1 << 21)
+
+#define _CPC           0x104
+#define CPC(n)         (_CPC + (n)*0x8)
+
+#define _SA            0x400
+#define SA(n)          (_SA + (n)*0x20)
+
+#define _DA            0x404
+#define DA(n)          (_DA + (n)*0x20)
+
+#define _CC            0x408
+#define CC(n)          (_CC + (n)*0x20)
+
+#define CC_SRCINC      (1 << 0)
+#define CC_DSTINC      (1 << 14)
+#define CC_SRCPRI      (1 << 8)
+#define CC_DSTPRI      (1 << 22)
+#define CC_SRCNS       (1 << 9)
+#define CC_DSTNS       (1 << 23)
+#define CC_SRCIA       (1 << 10)
+#define CC_DSTIA       (1 << 24)
+#define CC_SRCBRSTLEN_SHFT     4
+#define CC_DSTBRSTLEN_SHFT     18
+#define CC_SRCBRSTSIZE_SHFT    1
+#define CC_DSTBRSTSIZE_SHFT    15
+#define CC_SRCCCTRL_SHFT       11
+#define CC_SRCCCTRL_MASK       0x7
+#define CC_DSTCCTRL_SHFT       25
+#define CC_DRCCCTRL_MASK       0x7
+#define CC_SWAP_SHFT   28
+
+#define _LC0           0x40c
+#define LC0(n)         (_LC0 + (n)*0x20)
+
+#define _LC1           0x410
+#define LC1(n)         (_LC1 + (n)*0x20)
+
+#define DBGSTATUS      0xd00
+#define DBG_BUSY       (1 << 0)
+
+#define DBGCMD         0xd04
+#define DBGINST0       0xd08
+#define DBGINST1       0xd0c
+
+#define CR0            0xe00
+#define CR1            0xe04
+#define CR2            0xe08
+#define CR3            0xe0c
+#define CR4            0xe10
+#define CRD            0xe14
+
+#define PERIPH_ID      0xfe0
+#define PCELL_ID       0xff0
+
+#define CR0_PERIPH_REQ_SET     (1 << 0)
+#define CR0_BOOT_EN_SET                (1 << 1)
+#define CR0_BOOT_MAN_NS                (1 << 2)
+#define CR0_NUM_CHANS_SHIFT    4
+#define CR0_NUM_CHANS_MASK     0x7
+#define CR0_NUM_PERIPH_SHIFT   12
+#define CR0_NUM_PERIPH_MASK    0x1f
+#define CR0_NUM_EVENTS_SHIFT   17
+#define CR0_NUM_EVENTS_MASK    0x1f
+
+#define CR1_ICACHE_LEN_SHIFT   0
+#define CR1_ICACHE_LEN_MASK    0x7
+#define CR1_NUM_ICACHELINES_SHIFT      4
+#define CR1_NUM_ICACHELINES_MASK       0xf
+
+#define CRD_DATA_WIDTH_SHIFT   0
+#define CRD_DATA_WIDTH_MASK    0x7
+#define CRD_WR_CAP_SHIFT       4
+#define CRD_WR_CAP_MASK                0x7
+#define CRD_WR_Q_DEP_SHIFT     8
+#define CRD_WR_Q_DEP_MASK      0xf
+#define CRD_RD_CAP_SHIFT       12
+#define CRD_RD_CAP_MASK                0x7
+#define CRD_RD_Q_DEP_SHIFT     16
+#define CRD_RD_Q_DEP_MASK      0xf
+#define CRD_DATA_BUFF_SHIFT    20
+#define CRD_DATA_BUFF_MASK     0x3ff
+
+#define        PART            0x330
+#define DESIGNER       0x41
+#define REVISION       0x0
+#define INTEG_CFG      0x0
+#define PERIPH_ID_VAL  ((PART << 0) | (DESIGNER << 12) \
+                         | (REVISION << 20) | (INTEG_CFG << 24))
+
+#define PCELL_ID_VAL   0xb105f00d
+
+#define PL330_STATE_STOPPED            (1 << 0)
+#define PL330_STATE_EXECUTING          (1 << 1)
+#define PL330_STATE_WFE                        (1 << 2)
+#define PL330_STATE_FAULTING           (1 << 3)
+#define PL330_STATE_COMPLETING         (1 << 4)
+#define PL330_STATE_WFP                        (1 << 5)
+#define PL330_STATE_KILLING            (1 << 6)
+#define PL330_STATE_FAULT_COMPLETING   (1 << 7)
+#define PL330_STATE_CACHEMISS          (1 << 8)
+#define PL330_STATE_UPDTPC             (1 << 9)
+#define PL330_STATE_ATBARRIER          (1 << 10)
+#define PL330_STATE_QUEUEBUSY          (1 << 11)
+#define PL330_STATE_INVALID            (1 << 15)
+
+#define PL330_STABLE_STATES (PL330_STATE_STOPPED | PL330_STATE_EXECUTING \
+                               | PL330_STATE_WFE | PL330_STATE_FAULTING)
+
+#define CMD_DMAADDH    0x54
+#define CMD_DMAEND     0x00
+#define CMD_DMAFLUSHP  0x35
+#define CMD_DMAGO      0xa0
+#define CMD_DMALD      0x04
+#define CMD_DMALDP     0x25
+#define CMD_DMALP      0x20
+#define CMD_DMALPEND   0x28
+#define CMD_DMAKILL    0x01
+#define CMD_DMAMOV     0xbc
+#define CMD_DMANOP     0x18
+#define CMD_DMARMB     0x12
+#define CMD_DMASEV     0x34
+#define CMD_DMAST      0x08
+#define CMD_DMASTP     0x29
+#define CMD_DMASTZ     0x0c
+#define CMD_DMAWFE     0x36
+#define CMD_DMAWFP     0x30
+#define CMD_DMAWMB     0x13
+
+#define SZ_DMAADDH     3
+#define SZ_DMAEND      1
+#define SZ_DMAFLUSHP   2
+#define SZ_DMALD       1
+#define SZ_DMALDP      2
+#define SZ_DMALP       2
+#define SZ_DMALPEND    2
+#define SZ_DMAKILL     1
+#define SZ_DMAMOV      6
+#define SZ_DMANOP      1
+#define SZ_DMARMB      1
+#define SZ_DMASEV      2
+#define SZ_DMAST       1
+#define SZ_DMASTP      2
+#define SZ_DMASTZ      1
+#define SZ_DMAWFE      2
+#define SZ_DMAWFP      2
+#define SZ_DMAWMB      1
+#define SZ_DMAGO       6
+
+#define BRST_LEN(ccr)  ((((ccr) >> CC_SRCBRSTLEN_SHFT) & 0xf) + 1)
+#define BRST_SIZE(ccr) (1 << (((ccr) >> CC_SRCBRSTSIZE_SHFT) & 0x7))
+
+#define BYTE_TO_BURST(b, ccr)  ((b) / BRST_SIZE(ccr) / BRST_LEN(ccr))
+#define BURST_TO_BYTE(c, ccr)  ((c) * BRST_SIZE(ccr) * BRST_LEN(ccr))
+
+/*
+ * With 256 bytes, we can do more than 2.5MB and 5MB xfers per req
+ * at 1byte/burst for P<->M and M<->M respectively.
+ * For typical scenario, at 1word/burst, 10MB and 20MB xfers per req
+ * should be enough for P<->M and M<->M respectively.
+ */
+#define MCODE_BUFF_PER_REQ     256
+
+/*
+ * Mark a _pl330_req as free.
+ * We do it by writing DMAEND as the first instruction
+ * because no valid request is going to have DMAEND as
+ * its first instruction to execute.
+ */
+#define MARK_FREE(req) do { \
+                               _emit_END(0, (req)->mc_cpu); \
+                               (req)->mc_len = 0; \
+                       } while (0)
+
+/* If the _pl330_req is available to the client */
+#define IS_FREE(req)   (*((u8 *)((req)->mc_cpu)) == CMD_DMAEND)
+
+/* Use this _only_ to wait on transient states */
+#define UNTIL(t, s)    while (!(_state(t) & (s))) cpu_relax();
+
+#ifdef PL330_DEBUG_MCGEN
+static unsigned cmd_line;
+#define PL330_DBGCMD_DUMP(off, x...)   do { \
+                                               printk("%x:", cmd_line); \
+                                               printk(x); \
+                                               cmd_line += off; \
+                                       } while (0)
+#define PL330_DBGMC_START(addr)                (cmd_line = addr)
+#else
+#define PL330_DBGCMD_DUMP(off, x...)   do {} while (0)
+#define PL330_DBGMC_START(addr)                do {} while (0)
+#endif
+
+struct _xfer_spec {
+       u32 ccr;
+       struct pl330_req *r;
+       struct pl330_xfer *x;
+};
+
+enum dmamov_dst {
+       SAR = 0,
+       CCR,
+       DAR,
+};
+
+enum pl330_dst {
+       SRC = 0,
+       DST,
+};
+
+enum pl330_cond {
+       SINGLE,
+       BURST,
+       ALWAYS,
+};
+
+struct _pl330_req {
+       u32 mc_bus;
+       void *mc_cpu;
+       /* Number of bytes taken to setup MC for the req */
+       u32 mc_len;
+       struct pl330_req *r;
+       /* Hook to attach to DMAC's list of reqs with due callback */
+       struct list_head rqd;
+};
+
+/* ToBeDone for tasklet */
+struct _pl330_tbd {
+       bool reset_dmac;
+       bool reset_mngr;
+       u8 reset_chan;
+};
+
+/* A DMAC Thread */
+struct pl330_thread {
+       u8 id;
+       int ev;
+       /* If the channel is not yet acquired by any client */
+       bool free;
+       /* Parent DMAC */
+       struct pl330_dmac *dmac;
+       /* Only two at a time */
+       struct _pl330_req req[2];
+       /* Index of the last submitted request */
+       unsigned lstenq;
+};
+
+enum pl330_dmac_state {
+       UNINIT,
+       INIT,
+       DYING,
+};
+
+/* A DMAC */
+struct pl330_dmac {
+       spinlock_t              lock;
+       /* Holds list of reqs with due callbacks */
+       struct list_head        req_done;
+       /* Pointer to platform specific stuff */
+       struct pl330_info       *pinfo;
+       /* Maximum possible events/irqs */
+       int                     events[32];
+       /* BUS address of MicroCode buffer */
+       u32                     mcode_bus;
+       /* CPU address of MicroCode buffer */
+       void                    *mcode_cpu;
+       /* List of all Channel threads */
+       struct pl330_thread     *channels;
+       /* Pointer to the MANAGER thread */
+       struct pl330_thread     *manager;
+       /* To handle bad news in interrupt */
+       struct tasklet_struct   tasks;
+       struct _pl330_tbd       dmac_tbd;
+       /* State of DMAC operation */
+       enum pl330_dmac_state   state;
+};
+
+static inline void _callback(struct pl330_req *r, enum pl330_op_err err)
+{
+       if (r && r->xfer_cb)
+               r->xfer_cb(r->token, err);
+}
+
+static inline bool _queue_empty(struct pl330_thread *thrd)
+{
+       return (IS_FREE(&thrd->req[0]) && IS_FREE(&thrd->req[1]))
+               ? true : false;
+}
+
+static inline bool _queue_full(struct pl330_thread *thrd)
+{
+       return (IS_FREE(&thrd->req[0]) || IS_FREE(&thrd->req[1]))
+               ? false : true;
+}
+
+static inline bool is_manager(struct pl330_thread *thrd)
+{
+       struct pl330_dmac *pl330 = thrd->dmac;
+
+       /* MANAGER is indexed at the end */
+       if (thrd->id == pl330->pinfo->pcfg.num_chan)
+               return true;
+       else
+               return false;
+}
+
+/* If manager of the thread is in Non-Secure mode */
+static inline bool _manager_ns(struct pl330_thread *thrd)
+{
+       struct pl330_dmac *pl330 = thrd->dmac;
+
+       return (pl330->pinfo->pcfg.mode & DMAC_MODE_NS) ? true : false;
+}
+
+static inline u32 get_id(struct pl330_info *pi, u32 off)
+{
+       void __iomem *regs = pi->base;
+       u32 id = 0;
+
+       id |= (readb(regs + off + 0x0) << 0);
+       id |= (readb(regs + off + 0x4) << 8);
+       id |= (readb(regs + off + 0x8) << 16);
+       id |= (readb(regs + off + 0xc) << 24);
+
+       return id;
+}
+
+static inline u32 _emit_ADDH(unsigned dry_run, u8 buf[],
+               enum pl330_dst da, u16 val)
+{
+       if (dry_run)
+               return SZ_DMAADDH;
+
+       buf[0] = CMD_DMAADDH;
+       buf[0] |= (da << 1);
+       *((u16 *)&buf[1]) = val;
+
+       PL330_DBGCMD_DUMP(SZ_DMAADDH, "\tDMAADDH %s %u\n",
+               da == 1 ? "DA" : "SA", val);
+
+       return SZ_DMAADDH;
+}
+
+static inline u32 _emit_END(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMAEND;
+
+       buf[0] = CMD_DMAEND;
+
+       PL330_DBGCMD_DUMP(SZ_DMAEND, "\tDMAEND\n");
+
+       return SZ_DMAEND;
+}
+
+static inline u32 _emit_FLUSHP(unsigned dry_run, u8 buf[], u8 peri)
+{
+       if (dry_run)
+               return SZ_DMAFLUSHP;
+
+       buf[0] = CMD_DMAFLUSHP;
+
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+
+       PL330_DBGCMD_DUMP(SZ_DMAFLUSHP, "\tDMAFLUSHP %u\n", peri >> 3);
+
+       return SZ_DMAFLUSHP;
+}
+
+static inline u32 _emit_LD(unsigned dry_run, u8 buf[], enum pl330_cond cond)
+{
+       if (dry_run)
+               return SZ_DMALD;
+
+       buf[0] = CMD_DMALD;
+
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+
+       PL330_DBGCMD_DUMP(SZ_DMALD, "\tDMALD%c\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
+
+       return SZ_DMALD;
+}
+
+static inline u32 _emit_LDP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+{
+       if (dry_run)
+               return SZ_DMALDP;
+
+       buf[0] = CMD_DMALDP;
+
+       if (cond == BURST)
+               buf[0] |= (1 << 1);
+
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+
+       PL330_DBGCMD_DUMP(SZ_DMALDP, "\tDMALDP%c %u\n",
+               cond == SINGLE ? 'S' : 'B', peri >> 3);
+
+       return SZ_DMALDP;
+}
+
+static inline u32 _emit_LP(unsigned dry_run, u8 buf[],
+               unsigned loop, u8 cnt)
+{
+       if (dry_run)
+               return SZ_DMALP;
+
+       buf[0] = CMD_DMALP;
+
+       if (loop)
+               buf[0] |= (1 << 1);
+
+       cnt--; /* DMAC increments by 1 internally */
+       buf[1] = cnt;
+
+       PL330_DBGCMD_DUMP(SZ_DMALP, "\tDMALP_%c %u\n", loop ? '1' : '0', cnt);
+
+       return SZ_DMALP;
+}
+
+struct _arg_LPEND {
+       enum pl330_cond cond;
+       bool forever;
+       unsigned loop;
+       u8 bjump;
+};
+
+static inline u32 _emit_LPEND(unsigned dry_run, u8 buf[],
+               const struct _arg_LPEND *arg)
+{
+       enum pl330_cond cond = arg->cond;
+       bool forever = arg->forever;
+       unsigned loop = arg->loop;
+       u8 bjump = arg->bjump;
+
+       if (dry_run)
+               return SZ_DMALPEND;
+
+       buf[0] = CMD_DMALPEND;
+
+       if (loop)
+               buf[0] |= (1 << 2);
+
+       if (!forever)
+               buf[0] |= (1 << 4);
+
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+
+       buf[1] = bjump;
+
+       PL330_DBGCMD_DUMP(SZ_DMALPEND, "\tDMALP%s%c_%c bjmpto_%x\n",
+                       forever ? "FE" : "END",
+                       cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'),
+                       loop ? '1' : '0',
+                       bjump);
+
+       return SZ_DMALPEND;
+}
+
+static inline u32 _emit_KILL(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMAKILL;
+
+       buf[0] = CMD_DMAKILL;
+
+       return SZ_DMAKILL;
+}
+
+static inline u32 _emit_MOV(unsigned dry_run, u8 buf[],
+               enum dmamov_dst dst, u32 val)
+{
+       if (dry_run)
+               return SZ_DMAMOV;
+
+       buf[0] = CMD_DMAMOV;
+       buf[1] = dst;
+       *((u32 *)&buf[2]) = val;
+
+       PL330_DBGCMD_DUMP(SZ_DMAMOV, "\tDMAMOV %s 0x%x\n",
+               dst == SAR ? "SAR" : (dst == DAR ? "DAR" : "CCR"), val);
+
+       return SZ_DMAMOV;
+}
+
+static inline u32 _emit_NOP(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMANOP;
+
+       buf[0] = CMD_DMANOP;
+
+       PL330_DBGCMD_DUMP(SZ_DMANOP, "\tDMANOP\n");
+
+       return SZ_DMANOP;
+}
+
+static inline u32 _emit_RMB(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMARMB;
+
+       buf[0] = CMD_DMARMB;
+
+       PL330_DBGCMD_DUMP(SZ_DMARMB, "\tDMARMB\n");
+
+       return SZ_DMARMB;
+}
+
+static inline u32 _emit_SEV(unsigned dry_run, u8 buf[], u8 ev)
+{
+       if (dry_run)
+               return SZ_DMASEV;
+
+       buf[0] = CMD_DMASEV;
+
+       ev &= 0x1f;
+       ev <<= 3;
+       buf[1] = ev;
+
+       PL330_DBGCMD_DUMP(SZ_DMASEV, "\tDMASEV %u\n", ev >> 3);
+
+       return SZ_DMASEV;
+}
+
+static inline u32 _emit_ST(unsigned dry_run, u8 buf[], enum pl330_cond cond)
+{
+       if (dry_run)
+               return SZ_DMAST;
+
+       buf[0] = CMD_DMAST;
+
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (1 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (1 << 0);
+
+       PL330_DBGCMD_DUMP(SZ_DMAST, "\tDMAST%c\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'A'));
+
+       return SZ_DMAST;
+}
+
+static inline u32 _emit_STP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+{
+       if (dry_run)
+               return SZ_DMASTP;
+
+       buf[0] = CMD_DMASTP;
+
+       if (cond == BURST)
+               buf[0] |= (1 << 1);
+
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+
+       PL330_DBGCMD_DUMP(SZ_DMASTP, "\tDMASTP%c %u\n",
+               cond == SINGLE ? 'S' : 'B', peri >> 3);
+
+       return SZ_DMASTP;
+}
+
+static inline u32 _emit_STZ(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMASTZ;
+
+       buf[0] = CMD_DMASTZ;
+
+       PL330_DBGCMD_DUMP(SZ_DMASTZ, "\tDMASTZ\n");
+
+       return SZ_DMASTZ;
+}
+
+static inline u32 _emit_WFE(unsigned dry_run, u8 buf[], u8 ev,
+               unsigned invalidate)
+{
+       if (dry_run)
+               return SZ_DMAWFE;
+
+       buf[0] = CMD_DMAWFE;
+
+       ev &= 0x1f;
+       ev <<= 3;
+       buf[1] = ev;
+
+       if (invalidate)
+               buf[1] |= (1 << 1);
+
+       PL330_DBGCMD_DUMP(SZ_DMAWFE, "\tDMAWFE %u%s\n",
+               ev >> 3, invalidate ? ", I" : "");
+
+       return SZ_DMAWFE;
+}
+
+static inline u32 _emit_WFP(unsigned dry_run, u8 buf[],
+               enum pl330_cond cond, u8 peri)
+{
+       if (dry_run)
+               return SZ_DMAWFP;
+
+       buf[0] = CMD_DMAWFP;
+
+       if (cond == SINGLE)
+               buf[0] |= (0 << 1) | (0 << 0);
+       else if (cond == BURST)
+               buf[0] |= (1 << 1) | (0 << 0);
+       else
+               buf[0] |= (0 << 1) | (1 << 0);
+
+       peri &= 0x1f;
+       peri <<= 3;
+       buf[1] = peri;
+
+       PL330_DBGCMD_DUMP(SZ_DMAWFP, "\tDMAWFP%c %u\n",
+               cond == SINGLE ? 'S' : (cond == BURST ? 'B' : 'P'), peri >> 3);
+
+       return SZ_DMAWFP;
+}
+
+static inline u32 _emit_WMB(unsigned dry_run, u8 buf[])
+{
+       if (dry_run)
+               return SZ_DMAWMB;
+
+       buf[0] = CMD_DMAWMB;
+
+       PL330_DBGCMD_DUMP(SZ_DMAWMB, "\tDMAWMB\n");
+
+       return SZ_DMAWMB;
+}
+
+struct _arg_GO {
+       u8 chan;
+       u32 addr;
+       unsigned ns;
+};
+
+static inline u32 _emit_GO(unsigned dry_run, u8 buf[],
+               const struct _arg_GO *arg)
+{
+       u8 chan = arg->chan;
+       u32 addr = arg->addr;
+       unsigned ns = arg->ns;
+
+       if (dry_run)
+               return SZ_DMAGO;
+
+       buf[0] = CMD_DMAGO;
+       buf[0] |= (ns << 1);
+
+       buf[1] = chan & 0x7;
+
+       *((u32 *)&buf[2]) = addr;
+
+       return SZ_DMAGO;
+}
+
+#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
+
+/* Returns Time-Out */
+static bool _until_dmac_idle(struct pl330_thread *thrd)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       unsigned long loops = msecs_to_loops(5);
+
+       do {
+               /* Until Manager is Idle */
+               if (!(readl(regs + DBGSTATUS) & DBG_BUSY))
+                       break;
+
+               cpu_relax();
+       } while (--loops);
+
+       if (!loops)
+               return true;
+
+       return false;
+}
+
+static inline void _execute_DBGINSN(struct pl330_thread *thrd,
+               u8 insn[], bool as_manager)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u32 val;
+
+       val = (insn[0] << 16) | (insn[1] << 24);
+       if (!as_manager) {
+               val |= (1 << 0);
+               val |= (thrd->id << 8); /* Channel Number */
+       }
+       writel(val, regs + DBGINST0);
+
+       val = *((u32 *)&insn[2]);
+       writel(val, regs + DBGINST1);
+
+       /* If timed out due to halted state-machine */
+       if (_until_dmac_idle(thrd)) {
+               dev_err(thrd->dmac->pinfo->dev, "DMAC halted!\n");
+               return;
+       }
+
+       /* Get going */
+       writel(0, regs + DBGCMD);
+}
+
+static inline u32 _state(struct pl330_thread *thrd)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u32 val;
+
+       if (is_manager(thrd))
+               val = readl(regs + DS) & 0xf;
+       else
+               val = readl(regs + CS(thrd->id)) & 0xf;
+
+       switch (val) {
+       case DS_ST_STOP:
+               return PL330_STATE_STOPPED;
+       case DS_ST_EXEC:
+               return PL330_STATE_EXECUTING;
+       case DS_ST_CMISS:
+               return PL330_STATE_CACHEMISS;
+       case DS_ST_UPDTPC:
+               return PL330_STATE_UPDTPC;
+       case DS_ST_WFE:
+               return PL330_STATE_WFE;
+       case DS_ST_FAULT:
+               return PL330_STATE_FAULTING;
+       case DS_ST_ATBRR:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_ATBARRIER;
+       case DS_ST_QBUSY:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_QUEUEBUSY;
+       case DS_ST_WFP:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_WFP;
+       case DS_ST_KILL:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_KILLING;
+       case DS_ST_CMPLT:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_COMPLETING;
+       case DS_ST_FLTCMP:
+               if (is_manager(thrd))
+                       return PL330_STATE_INVALID;
+               else
+                       return PL330_STATE_FAULT_COMPLETING;
+       default:
+               return PL330_STATE_INVALID;
+       }
+}
+
+/* If the request 'req' of thread 'thrd' is currently active */
+static inline bool _req_active(struct pl330_thread *thrd,
+               struct _pl330_req *req)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u32 buf = req->mc_bus, pc = readl(regs + CPC(thrd->id));
+
+       if (IS_FREE(req))
+               return false;
+
+       return (pc >= buf && pc <= buf + req->mc_len) ? true : false;
+}
+
+/* Returns 0 if the thread is inactive, ID of active req + 1 otherwise */
+static inline unsigned _thrd_active(struct pl330_thread *thrd)
+{
+       if (_req_active(thrd, &thrd->req[0]))
+               return 1; /* First req active */
+
+       if (_req_active(thrd, &thrd->req[1]))
+               return 2; /* Second req active */
+
+       return 0;
+}
+
+static void _stop(struct pl330_thread *thrd)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       u8 insn[6] = {0, 0, 0, 0, 0, 0};
+
+       if (_state(thrd) == PL330_STATE_FAULT_COMPLETING)
+               UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+
+       /* Return if nothing needs to be done */
+       if (_state(thrd) == PL330_STATE_COMPLETING
+                 || _state(thrd) == PL330_STATE_KILLING
+                 || _state(thrd) == PL330_STATE_STOPPED)
+               return;
+
+       _emit_KILL(0, insn);
+
+       /* Stop generating interrupts for SEV */
+       writel(readl(regs + INTEN) & ~(1 << thrd->ev), regs + INTEN);
+
+       _execute_DBGINSN(thrd, insn, is_manager(thrd));
+}
+
+/* Start doing req 'idx' of thread 'thrd' */
+static bool _trigger(struct pl330_thread *thrd)
+{
+       void __iomem *regs = thrd->dmac->pinfo->base;
+       struct _pl330_req *req;
+       struct pl330_req *r;
+       struct _arg_GO go;
+       unsigned ns;
+       u8 insn[6] = {0, 0, 0, 0, 0, 0};
+
+       /* Return if already ACTIVE */
+       if (_state(thrd) != PL330_STATE_STOPPED)
+               return true;
+
+       if (!IS_FREE(&thrd->req[1 - thrd->lstenq]))
+               req = &thrd->req[1 - thrd->lstenq];
+       else if (!IS_FREE(&thrd->req[thrd->lstenq]))
+               req = &thrd->req[thrd->lstenq];
+       else
+               req = NULL;
+
+       /* Return if no request */
+       if (!req || !req->r)
+               return true;
+
+       r = req->r;
+
+       if (r->cfg)
+               ns = r->cfg->nonsecure ? 1 : 0;
+       else if (readl(regs + CS(thrd->id)) & CS_CNS)
+               ns = 1;
+       else
+               ns = 0;
+
+       /* See 'Abort Sources' point-4 at Page 2-25 */
+       if (_manager_ns(thrd) && !ns)
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d Recipe for ABORT!\n",
+                       __func__, __LINE__);
+
+       go.chan = thrd->id;
+       go.addr = req->mc_bus;
+       go.ns = ns;
+       _emit_GO(0, insn, &go);
+
+       /* Set to generate interrupts for SEV */
+       writel(readl(regs + INTEN) | (1 << thrd->ev), regs + INTEN);
+
+       /* Only manager can execute GO */
+       _execute_DBGINSN(thrd, insn, true);
+
+       return true;
+}
+
+static bool _start(struct pl330_thread *thrd)
+{
+       switch (_state(thrd)) {
+       case PL330_STATE_FAULT_COMPLETING:
+               UNTIL(thrd, PL330_STATE_FAULTING | PL330_STATE_KILLING);
+
+               if (_state(thrd) == PL330_STATE_KILLING)
+                       UNTIL(thrd, PL330_STATE_STOPPED)
+
+       case PL330_STATE_FAULTING:
+               _stop(thrd);
+
+       case PL330_STATE_KILLING:
+       case PL330_STATE_COMPLETING:
+               UNTIL(thrd, PL330_STATE_STOPPED)
+
+       case PL330_STATE_STOPPED:
+               return _trigger(thrd);
+
+       case PL330_STATE_WFP:
+       case PL330_STATE_QUEUEBUSY:
+       case PL330_STATE_ATBARRIER:
+       case PL330_STATE_UPDTPC:
+       case PL330_STATE_CACHEMISS:
+       case PL330_STATE_EXECUTING:
+               return true;
+
+       case PL330_STATE_WFE: /* For RESUME, nothing yet */
+       default:
+               return false;
+       }
+}
+
+static inline int _ldst_memtomem(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+{
+       int off = 0;
+
+       while (cyc--) {
+               off += _emit_LD(dry_run, &buf[off], ALWAYS);
+               off += _emit_RMB(dry_run, &buf[off]);
+               off += _emit_ST(dry_run, &buf[off], ALWAYS);
+               off += _emit_WMB(dry_run, &buf[off]);
+       }
+
+       return off;
+}
+
+static inline int _ldst_devtomem(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+{
+       int off = 0;
+
+       while (cyc--) {
+               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_LDP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_ST(dry_run, &buf[off], ALWAYS);
+               off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
+       }
+
+       return off;
+}
+
+static inline int _ldst_memtodev(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+{
+       int off = 0;
+
+       while (cyc--) {
+               off += _emit_WFP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_LD(dry_run, &buf[off], ALWAYS);
+               off += _emit_STP(dry_run, &buf[off], SINGLE, pxs->r->peri);
+               off += _emit_FLUSHP(dry_run, &buf[off], pxs->r->peri);
+       }
+
+       return off;
+}
+
+static int _bursts(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs, int cyc)
+{
+       int off = 0;
+
+       switch (pxs->r->rqtype) {
+       case MEMTODEV:
+               off += _ldst_memtodev(dry_run, &buf[off], pxs, cyc);
+               break;
+       case DEVTOMEM:
+               off += _ldst_devtomem(dry_run, &buf[off], pxs, cyc);
+               break;
+       case MEMTOMEM:
+               off += _ldst_memtomem(dry_run, &buf[off], pxs, cyc);
+               break;
+       default:
+               off += 0x40000000; /* Scare off the Client */
+               break;
+       }
+
+       return off;
+}
+
+/* Returns bytes consumed and updates bursts */
+static inline int _loop(unsigned dry_run, u8 buf[],
+               unsigned long *bursts, const struct _xfer_spec *pxs)
+{
+       int cyc, cycmax, szlp, szlpend, szbrst, off;
+       unsigned lcnt0, lcnt1, ljmp0, ljmp1;
+       struct _arg_LPEND lpend;
+
+       /* Max iterations possibile in DMALP is 256 */
+       if (*bursts >= 256*256) {
+               lcnt1 = 256;
+               lcnt0 = 256;
+               cyc = *bursts / lcnt1 / lcnt0;
+       } else if (*bursts > 256) {
+               lcnt1 = 256;
+               lcnt0 = *bursts / lcnt1;
+               cyc = 1;
+       } else {
+               lcnt1 = *bursts;
+               lcnt0 = 0;
+               cyc = 1;
+       }
+
+       szlp = _emit_LP(1, buf, 0, 0);
+       szbrst = _bursts(1, buf, pxs, 1);
+
+       lpend.cond = ALWAYS;
+       lpend.forever = false;
+       lpend.loop = 0;
+       lpend.bjump = 0;
+       szlpend = _emit_LPEND(1, buf, &lpend);
+
+       if (lcnt0) {
+               szlp *= 2;
+               szlpend *= 2;
+       }
+
+       /*
+        * Max bursts that we can unroll due to limit on the
+        * size of backward jump that can be encoded in DMALPEND
+        * which is 8-bits and hence 255
+        */
+       cycmax = (255 - (szlp + szlpend)) / szbrst;
+
+       cyc = (cycmax < cyc) ? cycmax : cyc;
+
+       off = 0;
+
+       if (lcnt0) {
+               off += _emit_LP(dry_run, &buf[off], 0, lcnt0);
+               ljmp0 = off;
+       }
+
+       off += _emit_LP(dry_run, &buf[off], 1, lcnt1);
+       ljmp1 = off;
+
+       off += _bursts(dry_run, &buf[off], pxs, cyc);
+
+       lpend.cond = ALWAYS;
+       lpend.forever = false;
+       lpend.loop = 1;
+       lpend.bjump = off - ljmp1;
+       off += _emit_LPEND(dry_run, &buf[off], &lpend);
+
+       if (lcnt0) {
+               lpend.cond = ALWAYS;
+               lpend.forever = false;
+               lpend.loop = 0;
+               lpend.bjump = off - ljmp0;
+               off += _emit_LPEND(dry_run, &buf[off], &lpend);
+       }
+
+       *bursts = lcnt1 * cyc;
+       if (lcnt0)
+               *bursts *= lcnt0;
+
+       return off;
+}
+
+static inline int _setup_loops(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs)
+{
+       struct pl330_xfer *x = pxs->x;
+       u32 ccr = pxs->ccr;
+       unsigned long c, bursts = BYTE_TO_BURST(x->bytes, ccr);
+       int off = 0;
+
+       while (bursts) {
+               c = bursts;
+               off += _loop(dry_run, &buf[off], &c, pxs);
+               bursts -= c;
+       }
+
+       return off;
+}
+
+static inline int _setup_xfer(unsigned dry_run, u8 buf[],
+               const struct _xfer_spec *pxs)
+{
+       struct pl330_xfer *x = pxs->x;
+       int off = 0;
+
+       /* DMAMOV SAR, x->src_addr */
+       off += _emit_MOV(dry_run, &buf[off], SAR, x->src_addr);
+       /* DMAMOV DAR, x->dst_addr */
+       off += _emit_MOV(dry_run, &buf[off], DAR, x->dst_addr);
+
+       /* Setup Loop(s) */
+       off += _setup_loops(dry_run, &buf[off], pxs);
+
+       return off;
+}
+
+/*
+ * A req is a sequence of one or more xfer units.
+ * Returns the number of bytes taken to setup the MC for the req.
+ */
+static int _setup_req(unsigned dry_run, struct pl330_thread *thrd,
+               unsigned index, struct _xfer_spec *pxs)
+{
+       struct _pl330_req *req = &thrd->req[index];
+       struct pl330_xfer *x;
+       u8 *buf = req->mc_cpu;
+       int off = 0;
+
+       PL330_DBGMC_START(req->mc_bus);
+
+       /* DMAMOV CCR, ccr */
+       off += _emit_MOV(dry_run, &buf[off], CCR, pxs->ccr);
+
+       x = pxs->r->x;
+       do {
+               /* Error if xfer length is not aligned at burst size */
+               if (x->bytes % (BRST_SIZE(pxs->ccr) * BRST_LEN(pxs->ccr)))
+                       return -EINVAL;
+
+               pxs->x = x;
+               off += _setup_xfer(dry_run, &buf[off], pxs);
+
+               x = x->next;
+       } while (x);
+
+       /* DMASEV peripheral/event */
+       off += _emit_SEV(dry_run, &buf[off], thrd->ev);
+       /* DMAEND */
+       off += _emit_END(dry_run, &buf[off]);
+
+       return off;
+}
+
+static inline u32 _prepare_ccr(const struct pl330_reqcfg *rqc)
+{
+       u32 ccr = 0;
+
+       if (rqc->src_inc)
+               ccr |= CC_SRCINC;
+
+       if (rqc->dst_inc)
+               ccr |= CC_DSTINC;
+
+       /* We set same protection levels for Src and DST for now */
+       if (rqc->privileged)
+               ccr |= CC_SRCPRI | CC_DSTPRI;
+       if (rqc->nonsecure)
+               ccr |= CC_SRCNS | CC_DSTNS;
+       if (rqc->insnaccess)
+               ccr |= CC_SRCIA | CC_DSTIA;
+
+       ccr |= (((rqc->brst_len - 1) & 0xf) << CC_SRCBRSTLEN_SHFT);
+       ccr |= (((rqc->brst_len - 1) & 0xf) << CC_DSTBRSTLEN_SHFT);
+
+       ccr |= (rqc->brst_size << CC_SRCBRSTSIZE_SHFT);
+       ccr |= (rqc->brst_size << CC_DSTBRSTSIZE_SHFT);
+
+       ccr |= (rqc->dcctl << CC_SRCCCTRL_SHFT);
+       ccr |= (rqc->scctl << CC_DSTCCTRL_SHFT);
+
+       ccr |= (rqc->swap << CC_SWAP_SHFT);
+
+       return ccr;
+}
+
+static inline bool _is_valid(u32 ccr)
+{
+       enum pl330_dstcachectrl dcctl;
+       enum pl330_srccachectrl scctl;
+
+       dcctl = (ccr >> CC_DSTCCTRL_SHFT) & CC_DRCCCTRL_MASK;
+       scctl = (ccr >> CC_SRCCCTRL_SHFT) & CC_SRCCCTRL_MASK;
+
+       if (dcctl == DINVALID1 || dcctl == DINVALID2
+                       || scctl == SINVALID1 || scctl == SINVALID2)
+               return false;
+       else
+               return true;
+}
+
+/*
+ * Submit a list of xfers after which the client wants notification.
+ * Client is not notified after each xfer unit, just once after all
+ * xfer units are done or some error occurs.
+ */
+int pl330_submit_req(void *ch_id, struct pl330_req *r)
+{
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       struct pl330_info *pi;
+       struct _xfer_spec xs;
+       unsigned long flags;
+       void __iomem *regs;
+       unsigned idx;
+       u32 ccr;
+       int ret = 0;
+
+       /* No Req or Unacquired Channel or DMAC */
+       if (!r || !thrd || thrd->free)
+               return -EINVAL;
+
+       pl330 = thrd->dmac;
+       pi = pl330->pinfo;
+       regs = pi->base;
+
+       if (pl330->state == DYING
+               || pl330->dmac_tbd.reset_chan & (1 << thrd->id)) {
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d\n",
+                       __func__, __LINE__);
+               return -EAGAIN;
+       }
+
+       /* If request for non-existing peripheral */
+       if (r->rqtype != MEMTOMEM && r->peri >= pi->pcfg.num_peri) {
+               dev_info(thrd->dmac->pinfo->dev,
+                               "%s:%d Invalid peripheral(%u)!\n",
+                               __func__, __LINE__, r->peri);
+               return -EINVAL;
+       }
+
+       spin_lock_irqsave(&pl330->lock, flags);
+
+       if (_queue_full(thrd)) {
+               ret = -EAGAIN;
+               goto xfer_exit;
+       }
+
+       /* Prefer Secure Channel */
+       if (!_manager_ns(thrd))
+               r->cfg->nonsecure = 0;
+       else
+               r->cfg->nonsecure = 1;
+
+       /* Use last settings, if not provided */
+       if (r->cfg)
+               ccr = _prepare_ccr(r->cfg);
+       else
+               ccr = readl(regs + CC(thrd->id));
+
+       /* If this req doesn't have valid xfer settings */
+       if (!_is_valid(ccr)) {
+               ret = -EINVAL;
+               dev_info(thrd->dmac->pinfo->dev, "%s:%d Invalid CCR(%x)!\n",
+                       __func__, __LINE__, ccr);
+               goto xfer_exit;
+       }
+
+       idx = IS_FREE(&thrd->req[0]) ? 0 : 1;
+
+       xs.ccr = ccr;
+       xs.r = r;
+
+       /* First dry run to check if req is acceptable */
+       ret = _setup_req(1, thrd, idx, &xs);
+       if (ret < 0)
+               goto xfer_exit;
+
+       if (ret > pi->mcbufsz / 2) {
+               dev_info(thrd->dmac->pinfo->dev,
+                       "%s:%d Trying increasing mcbufsz\n",
+                               __func__, __LINE__);
+               ret = -ENOMEM;
+               goto xfer_exit;
+       }
+
+       /* Hook the request */
+       thrd->lstenq = idx;
+       thrd->req[idx].mc_len = _setup_req(0, thrd, idx, &xs);
+       thrd->req[idx].r = r;
+
+       ret = 0;
+
+xfer_exit:
+       spin_unlock_irqrestore(&pl330->lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(pl330_submit_req);
+
+static void pl330_dotask(unsigned long data)
+{
+       struct pl330_dmac *pl330 = (struct pl330_dmac *) data;
+       struct pl330_info *pi = pl330->pinfo;
+       unsigned long flags;
+       int i;
+
+       spin_lock_irqsave(&pl330->lock, flags);
+
+       /* The DMAC itself gone nuts */
+       if (pl330->dmac_tbd.reset_dmac) {
+               pl330->state = DYING;
+               /* Reset the manager too */
+               pl330->dmac_tbd.reset_mngr = true;
+               /* Clear the reset flag */
+               pl330->dmac_tbd.reset_dmac = false;
+       }
+
+       if (pl330->dmac_tbd.reset_mngr) {
+               _stop(pl330->manager);
+               /* Reset all channels */
+               pl330->dmac_tbd.reset_chan = (1 << pi->pcfg.num_chan) - 1;
+               /* Clear the reset flag */
+               pl330->dmac_tbd.reset_mngr = false;
+       }
+
+       for (i = 0; i < pi->pcfg.num_chan; i++) {
+
+               if (pl330->dmac_tbd.reset_chan & (1 << i)) {
+                       struct pl330_thread *thrd = &pl330->channels[i];
+                       void __iomem *regs = pi->base;
+                       enum pl330_op_err err;
+
+                       _stop(thrd);
+
+                       if (readl(regs + FSC) & (1 << thrd->id))
+                               err = PL330_ERR_FAIL;
+                       else
+                               err = PL330_ERR_ABORT;
+
+                       spin_unlock_irqrestore(&pl330->lock, flags);
+
+                       _callback(thrd->req[1 - thrd->lstenq].r, err);
+                       _callback(thrd->req[thrd->lstenq].r, err);
+
+                       spin_lock_irqsave(&pl330->lock, flags);
+
+                       thrd->req[0].r = NULL;
+                       thrd->req[1].r = NULL;
+                       MARK_FREE(&thrd->req[0]);
+                       MARK_FREE(&thrd->req[1]);
+
+                       /* Clear the reset flag */
+                       pl330->dmac_tbd.reset_chan &= ~(1 << i);
+               }
+       }
+
+       spin_unlock_irqrestore(&pl330->lock, flags);
+
+       return;
+}
+
+/* Returns 1 if state was updated, 0 otherwise */
+int pl330_update(const struct pl330_info *pi)
+{
+       struct _pl330_req *rqdone;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       void __iomem *regs;
+       u32 val;
+       int id, ev, ret = 0;
+
+       if (!pi || !pi->pl330_data)
+               return 0;
+
+       regs = pi->base;
+       pl330 = pi->pl330_data;
+
+       spin_lock_irqsave(&pl330->lock, flags);
+
+       val = readl(regs + FSM) & 0x1;
+       if (val)
+               pl330->dmac_tbd.reset_mngr = true;
+       else
+               pl330->dmac_tbd.reset_mngr = false;
+
+       val = readl(regs + FSC) & ((1 << pi->pcfg.num_chan) - 1);
+       pl330->dmac_tbd.reset_chan |= val;
+       if (val) {
+               int i = 0;
+               while (i < pi->pcfg.num_chan) {
+                       if (val & (1 << i)) {
+                               dev_info(pi->dev,
+                                       "Reset Channel-%d\t CS-%x FTC-%x\n",
+                                               i, readl(regs + CS(i)),
+                                               readl(regs + FTC(i)));
+                               _stop(&pl330->channels[i]);
+                       }
+                       i++;
+               }
+       }
+
+       /* Check which event happened i.e, thread notified */
+       val = readl(regs + ES);
+       if (pi->pcfg.num_events < 32
+                       && val & ~((1 << pi->pcfg.num_events) - 1)) {
+               pl330->dmac_tbd.reset_dmac = true;
+               dev_err(pi->dev, "%s:%d Unexpected!\n", __func__, __LINE__);
+               ret = 1;
+               goto updt_exit;
+       }
+
+       for (ev = 0; ev < pi->pcfg.num_events; ev++) {
+               if (val & (1 << ev)) { /* Event occured */
+                       struct pl330_thread *thrd;
+                       u32 inten = readl(regs + INTEN);
+                       int active;
+
+                       /* Clear the event */
+                       if (inten & (1 << ev))
+                               writel(1 << ev, regs + INTCLR);
+
+                       ret = 1;
+
+                       id = pl330->events[ev];
+
+                       thrd = &pl330->channels[id];
+
+                       active = _thrd_active(thrd);
+                       if (!active) /* Aborted */
+                               continue;
+
+                       active -= 1;
+
+                       rqdone = &thrd->req[active];
+                       MARK_FREE(rqdone);
+
+                       /* Get going again ASAP */
+                       _start(thrd);
+
+                       /* For now, just make a list of callbacks to be done */
+                       list_add_tail(&rqdone->rqd, &pl330->req_done);
+               }
+       }
+
+       /* Now that we are in no hurry, do the callbacks */
+       while (!list_empty(&pl330->req_done)) {
+               rqdone = container_of(pl330->req_done.next,
+                                       struct _pl330_req, rqd);
+
+               list_del_init(&rqdone->rqd);
+
+               spin_unlock_irqrestore(&pl330->lock, flags);
+               _callback(rqdone->r, PL330_ERR_NONE);
+               spin_lock_irqsave(&pl330->lock, flags);
+       }
+
+updt_exit:
+       spin_unlock_irqrestore(&pl330->lock, flags);
+
+       if (pl330->dmac_tbd.reset_dmac
+                       || pl330->dmac_tbd.reset_mngr
+                       || pl330->dmac_tbd.reset_chan) {
+               ret = 1;
+               tasklet_schedule(&pl330->tasks);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(pl330_update);
+
+int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op)
+{
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       int ret = 0, active;
+
+       if (!thrd || thrd->free || thrd->dmac->state == DYING)
+               return -EINVAL;
+
+       pl330 = thrd->dmac;
+
+       spin_lock_irqsave(&pl330->lock, flags);
+
+       switch (op) {
+       case PL330_OP_FLUSH:
+               /* Make sure the channel is stopped */
+               _stop(thrd);
+
+               thrd->req[0].r = NULL;
+               thrd->req[1].r = NULL;
+               MARK_FREE(&thrd->req[0]);
+               MARK_FREE(&thrd->req[1]);
+               break;
+
+       case PL330_OP_ABORT:
+               active = _thrd_active(thrd);
+
+               /* Make sure the channel is stopped */
+               _stop(thrd);
+
+               /* ABORT is only for the active req */
+               if (!active)
+                       break;
+
+               active--;
+
+               thrd->req[active].r = NULL;
+               MARK_FREE(&thrd->req[active]);
+
+               /* Start the next */
+       case PL330_OP_START:
+               if (!_start(thrd))
+                       ret = -EIO;
+               break;
+
+       default:
+               ret = -EINVAL;
+       }
+
+       spin_unlock_irqrestore(&pl330->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(pl330_chan_ctrl);
+
+int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus)
+{
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       struct pl330_info *pi;
+       void __iomem *regs;
+       int active;
+       u32 val;
+
+       if (!pstatus || !thrd || thrd->free)
+               return -EINVAL;
+
+       pl330 = thrd->dmac;
+       pi = pl330->pinfo;
+       regs = pi->base;
+
+       /* The client should remove the DMAC and add again */
+       if (pl330->state == DYING)
+               pstatus->dmac_halted = true;
+       else
+               pstatus->dmac_halted = false;
+
+       val = readl(regs + FSC);
+       if (val & (1 << thrd->id))
+               pstatus->faulting = true;
+       else
+               pstatus->faulting = false;
+
+       active = _thrd_active(thrd);
+
+       if (!active) {
+               /* Indicate that the thread is not running */
+               pstatus->top_req = NULL;
+               pstatus->wait_req = NULL;
+       } else {
+               active--;
+               pstatus->top_req = thrd->req[active].r;
+               pstatus->wait_req = !IS_FREE(&thrd->req[1 - active])
+                                       ? thrd->req[1 - active].r : NULL;
+       }
+
+       pstatus->src_addr = readl(regs + SA(thrd->id));
+       pstatus->dst_addr = readl(regs + DA(thrd->id));
+
+       return 0;
+}
+EXPORT_SYMBOL(pl330_chan_status);
+
+/* Reserve an event */
+static inline int _alloc_event(struct pl330_thread *thrd)
+{
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+       int ev;
+
+       for (ev = 0; ev < pi->pcfg.num_events; ev++)
+               if (pl330->events[ev] == -1) {
+                       pl330->events[ev] = thrd->id;
+                       return ev;
+               }
+
+       return -1;
+}
+
+/* Upon success, returns IdentityToken for the
+ * allocated channel, NULL otherwise.
+ */
+void *pl330_request_channel(const struct pl330_info *pi)
+{
+       struct pl330_thread *thrd = NULL;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+       int chans, i;
+
+       if (!pi || !pi->pl330_data)
+               return NULL;
+
+       pl330 = pi->pl330_data;
+
+       if (pl330->state == DYING)
+               return NULL;
+
+       chans = pi->pcfg.num_chan;
+
+       spin_lock_irqsave(&pl330->lock, flags);
+
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               if (thrd->free) {
+                       thrd->ev = _alloc_event(thrd);
+                       if (thrd->ev >= 0) {
+                               thrd->free = false;
+                               thrd->lstenq = 1;
+                               thrd->req[0].r = NULL;
+                               MARK_FREE(&thrd->req[0]);
+                               thrd->req[1].r = NULL;
+                               MARK_FREE(&thrd->req[1]);
+                               break;
+                       }
+               }
+               thrd = NULL;
+       }
+
+       spin_unlock_irqrestore(&pl330->lock, flags);
+
+       return thrd;
+}
+EXPORT_SYMBOL(pl330_request_channel);
+
+/* Release an event */
+static inline void _free_event(struct pl330_thread *thrd, int ev)
+{
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+
+       /* If the event is valid and was held by the thread */
+       if (ev >= 0 && ev < pi->pcfg.num_events
+                       && pl330->events[ev] == thrd->id)
+               pl330->events[ev] = -1;
+}
+
+void pl330_release_channel(void *ch_id)
+{
+       struct pl330_thread *thrd = ch_id;
+       struct pl330_dmac *pl330;
+       unsigned long flags;
+
+       if (!thrd || thrd->free)
+               return;
+
+       _stop(thrd);
+
+       _callback(thrd->req[1 - thrd->lstenq].r, PL330_ERR_ABORT);
+       _callback(thrd->req[thrd->lstenq].r, PL330_ERR_ABORT);
+
+       pl330 = thrd->dmac;
+
+       spin_lock_irqsave(&pl330->lock, flags);
+       _free_event(thrd, thrd->ev);
+       thrd->free = true;
+       spin_unlock_irqrestore(&pl330->lock, flags);
+}
+EXPORT_SYMBOL(pl330_release_channel);
+
+/* Initialize the structure for PL330 configuration, that can be used
+ * by the client driver the make best use of the DMAC
+ */
+static void read_dmac_config(struct pl330_info *pi)
+{
+       void __iomem *regs = pi->base;
+       u32 val;
+
+       val = readl(regs + CRD) >> CRD_DATA_WIDTH_SHIFT;
+       val &= CRD_DATA_WIDTH_MASK;
+       pi->pcfg.data_bus_width = 8 * (1 << val);
+
+       val = readl(regs + CRD) >> CRD_DATA_BUFF_SHIFT;
+       val &= CRD_DATA_BUFF_MASK;
+       pi->pcfg.data_buf_dep = val + 1;
+
+       val = readl(regs + CR0) >> CR0_NUM_CHANS_SHIFT;
+       val &= CR0_NUM_CHANS_MASK;
+       val += 1;
+       pi->pcfg.num_chan = val;
+
+       val = readl(regs + CR0);
+       if (val & CR0_PERIPH_REQ_SET) {
+               val = (val >> CR0_NUM_PERIPH_SHIFT) & CR0_NUM_PERIPH_MASK;
+               val += 1;
+               pi->pcfg.num_peri = val;
+               pi->pcfg.peri_ns = readl(regs + CR4);
+       } else {
+               pi->pcfg.num_peri = 0;
+       }
+
+       val = readl(regs + CR0);
+       if (val & CR0_BOOT_MAN_NS)
+               pi->pcfg.mode |= DMAC_MODE_NS;
+       else
+               pi->pcfg.mode &= ~DMAC_MODE_NS;
+
+       val = readl(regs + CR0) >> CR0_NUM_EVENTS_SHIFT;
+       val &= CR0_NUM_EVENTS_MASK;
+       val += 1;
+       pi->pcfg.num_events = val;
+
+       pi->pcfg.irq_ns = readl(regs + CR3);
+
+       pi->pcfg.periph_id = get_id(pi, PERIPH_ID);
+       pi->pcfg.pcell_id = get_id(pi, PCELL_ID);
+}
+
+static inline void _reset_thread(struct pl330_thread *thrd)
+{
+       struct pl330_dmac *pl330 = thrd->dmac;
+       struct pl330_info *pi = pl330->pinfo;
+
+       thrd->req[0].mc_cpu = pl330->mcode_cpu
+                               + (thrd->id * pi->mcbufsz);
+       thrd->req[0].mc_bus = pl330->mcode_bus
+                               + (thrd->id * pi->mcbufsz);
+       thrd->req[0].r = NULL;
+       MARK_FREE(&thrd->req[0]);
+
+       thrd->req[1].mc_cpu = thrd->req[0].mc_cpu
+                               + pi->mcbufsz / 2;
+       thrd->req[1].mc_bus = thrd->req[0].mc_bus
+                               + pi->mcbufsz / 2;
+       thrd->req[1].r = NULL;
+       MARK_FREE(&thrd->req[1]);
+}
+
+static int dmac_alloc_threads(struct pl330_dmac *pl330)
+{
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       struct pl330_thread *thrd;
+       int i;
+
+       /* Allocate 1 Manager and 'chans' Channel threads */
+       pl330->channels = kzalloc((1 + chans) * sizeof(*thrd),
+                                       GFP_KERNEL);
+       if (!pl330->channels)
+               return -ENOMEM;
+
+       /* Init Channel threads */
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               thrd->id = i;
+               thrd->dmac = pl330;
+               _reset_thread(thrd);
+               thrd->free = true;
+       }
+
+       /* MANAGER is indexed at the end */
+       thrd = &pl330->channels[chans];
+       thrd->id = chans;
+       thrd->dmac = pl330;
+       thrd->free = false;
+       pl330->manager = thrd;
+
+       return 0;
+}
+
+static int dmac_alloc_resources(struct pl330_dmac *pl330)
+{
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       int ret;
+
+       /*
+        * Alloc MicroCode buffer for 'chans' Channel threads.
+        * A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN)
+        */
+       pl330->mcode_cpu = dma_alloc_coherent(pi->dev,
+                               chans * pi->mcbufsz,
+                               &pl330->mcode_bus, GFP_KERNEL);
+       if (!pl330->mcode_cpu) {
+               dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
+                       __func__, __LINE__);
+               return -ENOMEM;
+       }
+
+       ret = dmac_alloc_threads(pl330);
+       if (ret) {
+               dev_err(pi->dev, "%s:%d Can't to create channels for DMAC!\n",
+                       __func__, __LINE__);
+               dma_free_coherent(pi->dev,
+                               chans * pi->mcbufsz,
+                               pl330->mcode_cpu, pl330->mcode_bus);
+               return ret;
+       }
+
+       return 0;
+}
+
+int pl330_add(struct pl330_info *pi)
+{
+       struct pl330_dmac *pl330;
+       void __iomem *regs;
+       int i, ret;
+
+       if (!pi || !pi->dev)
+               return -EINVAL;
+
+       /* If already added */
+       if (pi->pl330_data)
+               return -EINVAL;
+
+       /*
+        * If the SoC can perform reset on the DMAC, then do it
+        * before reading its configuration.
+        */
+       if (pi->dmac_reset)
+               pi->dmac_reset(pi);
+
+       regs = pi->base;
+
+       /* Check if we can handle this DMAC */
+       if (get_id(pi, PERIPH_ID) != PERIPH_ID_VAL
+          || get_id(pi, PCELL_ID) != PCELL_ID_VAL) {
+               dev_err(pi->dev, "PERIPH_ID 0x%x, PCELL_ID 0x%x !\n",
+                       readl(regs + PERIPH_ID), readl(regs + PCELL_ID));
+               return -EINVAL;
+       }
+
+       /* Read the configuration of the DMAC */
+       read_dmac_config(pi);
+
+       if (pi->pcfg.num_events == 0) {
+               dev_err(pi->dev, "%s:%d Can't work without events!\n",
+                       __func__, __LINE__);
+               return -EINVAL;
+       }
+
+       pl330 = kzalloc(sizeof(*pl330), GFP_KERNEL);
+       if (!pl330) {
+               dev_err(pi->dev, "%s:%d Can't allocate memory!\n",
+                       __func__, __LINE__);
+               return -ENOMEM;
+       }
+
+       /* Assign the info structure and private data */
+       pl330->pinfo = pi;
+       pi->pl330_data = pl330;
+
+       spin_lock_init(&pl330->lock);
+
+       INIT_LIST_HEAD(&pl330->req_done);
+
+       /* Use default MC buffer size if not provided */
+       if (!pi->mcbufsz)
+               pi->mcbufsz = MCODE_BUFF_PER_REQ * 2;
+
+       /* Mark all events as free */
+       for (i = 0; i < pi->pcfg.num_events; i++)
+               pl330->events[i] = -1;
+
+       /* Allocate resources needed by the DMAC */
+       ret = dmac_alloc_resources(pl330);
+       if (ret) {
+               dev_err(pi->dev, "Unable to create channels for DMAC\n");
+               kfree(pl330);
+               return ret;
+       }
+
+       tasklet_init(&pl330->tasks, pl330_dotask, (unsigned long) pl330);
+
+       pl330->state = INIT;
+
+       return 0;
+}
+EXPORT_SYMBOL(pl330_add);
+
+static int dmac_free_threads(struct pl330_dmac *pl330)
+{
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+       struct pl330_thread *thrd;
+       int i;
+
+       /* Release Channel threads */
+       for (i = 0; i < chans; i++) {
+               thrd = &pl330->channels[i];
+               pl330_release_channel((void *)thrd);
+       }
+
+       /* Free memory */
+       kfree(pl330->channels);
+
+       return 0;
+}
+
+static void dmac_free_resources(struct pl330_dmac *pl330)
+{
+       struct pl330_info *pi = pl330->pinfo;
+       int chans = pi->pcfg.num_chan;
+
+       dmac_free_threads(pl330);
+
+       dma_free_coherent(pi->dev, chans * pi->mcbufsz,
+                               pl330->mcode_cpu, pl330->mcode_bus);
+}
+
+void pl330_del(struct pl330_info *pi)
+{
+       struct pl330_dmac *pl330;
+
+       if (!pi || !pi->pl330_data)
+               return;
+
+       pl330 = pi->pl330_data;
+
+       pl330->state = UNINIT;
+
+       tasklet_kill(&pl330->tasks);
+
+       /* Free DMAC resources */
+       dmac_free_resources(pl330);
+
+       kfree(pl330);
+       pi->pl330_data = NULL;
+}
+EXPORT_SYMBOL(pl330_del);
index 1cf999a..ba65f6e 100644 (file)
@@ -266,13 +266,53 @@ static int vic_set_wake(unsigned int irq, unsigned int on)
 #endif /* CONFIG_PM */
 
 static struct irq_chip vic_chip = {
-       .name   = "VIC",
-       .ack    = vic_ack_irq,
-       .mask   = vic_mask_irq,
-       .unmask = vic_unmask_irq,
-       .set_wake = vic_set_wake,
+       .name           = "VIC",
+       .ack            = vic_ack_irq,
+       .mask           = vic_mask_irq,
+       .unmask         = vic_unmask_irq,
+       .set_wake       = vic_set_wake,
 };
 
+static void __init vic_disable(void __iomem *base)
+{
+       writel(0, base + VIC_INT_SELECT);
+       writel(0, base + VIC_INT_ENABLE);
+       writel(~0, base + VIC_INT_ENABLE_CLEAR);
+       writel(0, base + VIC_IRQ_STATUS);
+       writel(0, base + VIC_ITCR);
+       writel(~0, base + VIC_INT_SOFT_CLEAR);
+}
+
+static void __init vic_clear_interrupts(void __iomem *base)
+{
+       unsigned int i;
+
+       writel(0, base + VIC_PL190_VECT_ADDR);
+       for (i = 0; i < 19; i++) {
+               unsigned int value;
+
+               value = readl(base + VIC_PL190_VECT_ADDR);
+               writel(value, base + VIC_PL190_VECT_ADDR);
+       }
+}
+
+static void __init vic_set_irq_sources(void __iomem *base,
+                               unsigned int irq_start, u32 vic_sources)
+{
+       unsigned int i;
+
+       for (i = 0; i < 32; i++) {
+               if (vic_sources & (1 << i)) {
+                       unsigned int irq = irq_start + i;
+
+                       set_irq_chip(irq, &vic_chip);
+                       set_irq_chip_data(irq, base);
+                       set_irq_handler(irq, handle_level_irq);
+                       set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
+               }
+       }
+}
+
 /*
  * The PL190 cell from ARM has been modified by ST to handle 64 interrupts.
  * The original cell has 32 interrupts, while the modified one has 64,
@@ -287,13 +327,7 @@ static void __init vic_init_st(void __iomem *base, unsigned int irq_start,
        int vic_2nd_block = ((unsigned long)base & ~PAGE_MASK) != 0;
 
        /* Disable all interrupts initially. */
-
-       writel(0, base + VIC_INT_SELECT);
-       writel(0, base + VIC_INT_ENABLE);
-       writel(~0, base + VIC_INT_ENABLE_CLEAR);
-       writel(0, base + VIC_IRQ_STATUS);
-       writel(0, base + VIC_ITCR);
-       writel(~0, base + VIC_INT_SOFT_CLEAR);
+       vic_disable(base);
 
        /*
         * Make sure we clear all existing interrupts. The vector registers
@@ -302,13 +336,8 @@ static void __init vic_init_st(void __iomem *base, unsigned int irq_start,
         * the second base address, which is 0x20 in the page
         */
        if (vic_2nd_block) {
-               writel(0, base + VIC_PL190_VECT_ADDR);
-               for (i = 0; i < 19; i++) {
-                       unsigned int value;
+               vic_clear_interrupts(base);
 
-                       value = readl(base + VIC_PL190_VECT_ADDR);
-                       writel(value, base + VIC_PL190_VECT_ADDR);
-               }
                /* ST has 16 vectors as well, but we don't enable them by now */
                for (i = 0; i < 16; i++) {
                        void __iomem *reg = base + VIC_VECT_CNTL0 + (i * 4);
@@ -318,16 +347,7 @@ static void __init vic_init_st(void __iomem *base, unsigned int irq_start,
                writel(32, base + VIC_PL190_DEF_VECT_ADDR);
        }
 
-       for (i = 0; i < 32; i++) {
-               if (vic_sources & (1 << i)) {
-                       unsigned int irq = irq_start + i;
-
-                       set_irq_chip(irq, &vic_chip);
-                       set_irq_chip_data(irq, base);
-                       set_irq_handler(irq, handle_level_irq);
-                       set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
-               }
-       }
+       vic_set_irq_sources(base, irq_start, vic_sources);
 }
 
 /**
@@ -365,37 +385,14 @@ void __init vic_init(void __iomem *base, unsigned int irq_start,
        }
 
        /* Disable all interrupts initially. */
+       vic_disable(base);
 
-       writel(0, base + VIC_INT_SELECT);
-       writel(0, base + VIC_INT_ENABLE);
-       writel(~0, base + VIC_INT_ENABLE_CLEAR);
-       writel(0, base + VIC_IRQ_STATUS);
-       writel(0, base + VIC_ITCR);
-       writel(~0, base + VIC_INT_SOFT_CLEAR);
-
-       /*
-        * Make sure we clear all existing interrupts
-        */
-       writel(0, base + VIC_PL190_VECT_ADDR);
-       for (i = 0; i < 19; i++) {
-               unsigned int value;
-
-               value = readl(base + VIC_PL190_VECT_ADDR);
-               writel(value, base + VIC_PL190_VECT_ADDR);
-       }
+       /* Make sure we clear all existing interrupts */
+       vic_clear_interrupts(base);
 
        vic_init2(base);
 
-       for (i = 0; i < 32; i++) {
-               if (vic_sources & (1 << i)) {
-                       unsigned int irq = irq_start + i;
-
-                       set_irq_chip(irq, &vic_chip);
-                       set_irq_chip_data(irq, base);
-                       set_irq_handler(irq, handle_level_irq);
-                       set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
-               }
-       }
+       vic_set_irq_sources(base, irq_start, vic_sources);
 
        vic_pm_register(base, irq_start, resume_sources);
 }
diff --git a/arch/arm/configs/cns3420vb_defconfig b/arch/arm/configs/cns3420vb_defconfig
new file mode 100644 (file)
index 0000000..d5c0881
--- /dev/null
@@ -0,0 +1,831 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.34-rc6
+# Sun May  2 21:58:08 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_HAVE_PROC_CPU=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_NEED_DMA_MAP_STATE=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_OPROFILE_ARMV6=y
+CONFIG_OPROFILE_ARM11_CORE=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_HAVE_KERNEL_GZIP=y
+CONFIG_HAVE_KERNEL_LZO=y
+CONFIG_KERNEL_GZIP=y
+# CONFIG_KERNEL_BZIP2 is not set
+# CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_BSD_PROCESS_ACCT is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_TINY_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+CONFIG_IKCONFIG=y
+CONFIG_IKCONFIG_PROC=y
+CONFIG_LOG_BUF_SHIFT=14
+CONFIG_CGROUPS=y
+# CONFIG_CGROUP_DEBUG is not set
+# CONFIG_CGROUP_NS is not set
+# CONFIG_CGROUP_FREEZER is not set
+# CONFIG_CGROUP_DEVICE is not set
+# CONFIG_CPUSETS is not set
+# CONFIG_CGROUP_CPUACCT is not set
+# CONFIG_RESOURCE_COUNTERS is not set
+# CONFIG_CGROUP_SCHED is not set
+CONFIG_SYSFS_DEPRECATED=y
+CONFIG_SYSFS_DEPRECATED_V2=y
+CONFIG_RELAY=y
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_RD_LZO=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+CONFIG_HAVE_PERF_EVENTS=y
+CONFIG_PERF_USE_VMALLOC=y
+
+#
+# Kernel Performance Events And Counters
+#
+# CONFIG_PERF_EVENTS is not set
+# CONFIG_PERF_COUNTERS is not set
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_COMPAT_BRK=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=m
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+CONFIG_SLOW_WORK=y
+# CONFIG_SLOW_WORK_DEBUG is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODULE_FORCE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=m
+# CONFIG_CFQ_GROUP_IOSCHED is not set
+CONFIG_DEFAULT_DEADLINE=y
+# CONFIG_DEFAULT_CFQ is not set
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="deadline"
+# CONFIG_INLINE_SPIN_TRYLOCK is not set
+# CONFIG_INLINE_SPIN_TRYLOCK_BH is not set
+# CONFIG_INLINE_SPIN_LOCK is not set
+# CONFIG_INLINE_SPIN_LOCK_BH is not set
+# CONFIG_INLINE_SPIN_LOCK_IRQ is not set
+# CONFIG_INLINE_SPIN_LOCK_IRQSAVE is not set
+CONFIG_INLINE_SPIN_UNLOCK=y
+# CONFIG_INLINE_SPIN_UNLOCK_BH is not set
+CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
+# CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE is not set
+# CONFIG_INLINE_READ_TRYLOCK is not set
+# CONFIG_INLINE_READ_LOCK is not set
+# CONFIG_INLINE_READ_LOCK_BH is not set
+# CONFIG_INLINE_READ_LOCK_IRQ is not set
+# CONFIG_INLINE_READ_LOCK_IRQSAVE is not set
+CONFIG_INLINE_READ_UNLOCK=y
+# CONFIG_INLINE_READ_UNLOCK_BH is not set
+CONFIG_INLINE_READ_UNLOCK_IRQ=y
+# CONFIG_INLINE_READ_UNLOCK_IRQRESTORE is not set
+# CONFIG_INLINE_WRITE_TRYLOCK is not set
+# CONFIG_INLINE_WRITE_LOCK is not set
+# CONFIG_INLINE_WRITE_LOCK_BH is not set
+# CONFIG_INLINE_WRITE_LOCK_IRQ is not set
+# CONFIG_INLINE_WRITE_LOCK_IRQSAVE is not set
+CONFIG_INLINE_WRITE_UNLOCK=y
+# CONFIG_INLINE_WRITE_UNLOCK_BH is not set
+CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
+# CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
+# CONFIG_MUTEX_SPIN_ON_OWNER is not set
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_BCMRING is not set
+# CONFIG_ARCH_CLPS711X is not set
+CONFIG_ARCH_CNS3XXX=y
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_DOVE is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_NUC93X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_SHMOBILE is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5P6440 is not set
+# CONFIG_ARCH_S5P6442 is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_S5PV210 is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_U8500 is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+
+#
+# CNS3XXX platform type
+#
+CONFIG_MACH_CNS3420VB=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_V6=y
+# CONFIG_CPU_32v6K is not set
+CONFIG_CPU_32v6=y
+CONFIG_CPU_ABRT_EV6=y
+CONFIG_CPU_PABRT_V6=y
+CONFIG_CPU_CACHE_V6=y
+CONFIG_CPU_CACHE_VIPT=y
+CONFIG_CPU_COPY_V6=y
+CONFIG_CPU_TLB_V6=y
+CONFIG_CPU_HAS_ASID=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# CONFIG_CPU_ICACHE_DISABLE is not set
+# CONFIG_CPU_DCACHE_DISABLE is not set
+# CONFIG_CPU_BPREDICT_DISABLE is not set
+CONFIG_ARM_L1_CACHE_SHIFT=5
+CONFIG_CPU_HAS_PMU=y
+# CONFIG_ARM_ERRATA_411920 is not set
+CONFIG_ARM_GIC=y
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+CONFIG_AEABI=y
+CONFIG_OABI_COMPAT=y
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="console=ttyS0,38400 mem=128M root=/dev/mmcblk0p1 ro rootwait"
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Power Management
+#
+# CONFIG_CPU_IDLE is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_NET is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+# CONFIG_FIRMWARE_IN_KERNEL is not set
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_SYS_HYPERVISOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_TESTS is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_GEN_PROBE=y
+# CONFIG_MTD_CFI_ADV_OPTIONS is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_CFI_INTELEXT is not set
+CONFIG_MTD_CFI_AMDSTD=y
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+# CONFIG_MTD_PHYSMAP_COMPAT is not set
+# CONFIG_MTD_ARM_INTEGRATOR is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# 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_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# LPDDR flash memory drivers
+#
+# CONFIG_MTD_LPDDR is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+
+#
+# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
+#
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=20000
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+CONFIG_SCSI_MOD=y
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+# CONFIG_SCSI_MULTI_LUN is not set
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+CONFIG_SCSI_LOWLEVEL=y
+# CONFIG_LIBFC is not set
+# CONFIG_LIBFCOE is not set
+# CONFIG_SCSI_DEBUG is not set
+# CONFIG_SCSI_DH is not set
+# CONFIG_SCSI_OSD_INITIATOR is not set
+CONFIG_ATA=y
+# CONFIG_ATA_NONSTANDARD is not set
+CONFIG_ATA_VERBOSE_ERROR=y
+# CONFIG_SATA_PMP is not set
+# CONFIG_ATA_SFF is not set
+# CONFIG_MD is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+# CONFIG_INPUT_SPARSEKMAP is not set
+
+#
+# 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 is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=4
+# CONFIG_SERIAL_8250_EXTENDED is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=16
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+CONFIG_MMC=y
+# CONFIG_MMC_DEBUG is not set
+# CONFIG_MMC_UNSAFE_RESUME is not set
+
+#
+# MMC/SD/SDIO Card Drivers
+#
+CONFIG_MMC_BLOCK=y
+CONFIG_MMC_BLOCK_BOUNCE=y
+# CONFIG_SDIO_UART is not set
+# CONFIG_MMC_TEST is not set
+
+#
+# MMC/SD/SDIO Host Controller Drivers
+#
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_PLTFM=y
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+# CONFIG_EXT2_FS_SECURITY is not set
+# CONFIG_EXT2_FS_XIP is not set
+# CONFIG_EXT3_FS is not set
+# CONFIG_EXT4_FS is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=y
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+CONFIG_FSCACHE=y
+# CONFIG_FSCACHE_STATS is not set
+# CONFIG_FSCACHE_HISTOGRAM is not set
+# CONFIG_FSCACHE_DEBUG is not set
+# CONFIG_FSCACHE_OBJECT_LIST is not set
+# CONFIG_CACHEFILES is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+# CONFIG_MSDOS_FS is not set
+# CONFIG_VFAT_FS is not set
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_NLS is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
+# CONFIG_ENABLE_MUST_CHECK is not set
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_MEMORY_INIT=y
+CONFIG_FRAME_POINTER=y
+# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_RING_BUFFER=y
+CONFIG_RING_BUFFER_ALLOW_SWAP=y
+CONFIG_TRACING_SUPPORT=y
+# CONFIG_FTRACE is not set
+# CONFIG_DYNAMIC_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_ARM_UNWIND is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_OC_ETM is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_DEFAULT_SECURITY_SELINUX is not set
+# CONFIG_DEFAULT_SECURITY_SMACK is not set
+# CONFIG_DEFAULT_SECURITY_TOMOYO is not set
+CONFIG_DEFAULT_SECURITY_DAC=y
+CONFIG_DEFAULT_SECURITY=""
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+CONFIG_GENERIC_FIND_LAST_BIT=y
+CONFIG_CRC_CCITT=y
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_LZO_DECOMPRESS=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_DECOMPRESS_LZO=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
+CONFIG_GENERIC_ATOMIC64=y
index 03f76cf..4b55dcb 100644 (file)
@@ -1,13 +1,14 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Tue Jan  5 13:55:22 2010
+# Linux kernel version: 2.6.34-rc5
+# Wed Apr 28 11:23:19 2010
 #
 CONFIG_ARM=y
 CONFIG_SYS_SUPPORTS_APM_EMULATION=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_HAVE_PROC_CPU=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_STACKTRACE_SUPPORT=y
 CONFIG_HAVE_LATENCYTOP_SUPPORT=y
@@ -18,6 +19,7 @@ CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_RWSEM_GENERIC_SPINLOCK=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
 CONFIG_VECTORS_BASE=0xffff0000
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
@@ -32,6 +34,12 @@ CONFIG_LOCK_KERNEL=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
 CONFIG_LOCALVERSION=""
 CONFIG_LOCALVERSION_AUTO=y
+CONFIG_HAVE_KERNEL_GZIP=y
+CONFIG_HAVE_KERNEL_LZO=y
+CONFIG_KERNEL_GZIP=y
+# CONFIG_KERNEL_BZIP2 is not set
+# CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -52,7 +60,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -85,10 +92,14 @@ CONFIG_TIMERFD=y
 CONFIG_EVENTFD=y
 CONFIG_SHMEM=y
 CONFIG_AIO=y
+CONFIG_HAVE_PERF_EVENTS=y
+CONFIG_PERF_USE_VMALLOC=y
 
 #
 # Kernel Performance Events And Counters
 #
+# CONFIG_PERF_EVENTS is not set
+# CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
 CONFIG_SLAB=y
@@ -104,6 +115,7 @@ CONFIG_HAVE_CLK=y
 #
 # GCOV-based kernel profiling
 #
+# CONFIG_GCOV_KERNEL is not set
 # CONFIG_SLOW_WORK is not set
 CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 CONFIG_SLABINFO=y
@@ -170,6 +182,7 @@ CONFIG_MMU=y
 # CONFIG_ARCH_REALVIEW is not set
 # CONFIG_ARCH_VERSATILE is not set
 # CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_BCMRING is not set
 # CONFIG_ARCH_CLPS711X is not set
 # CONFIG_ARCH_GEMINI is not set
 # CONFIG_ARCH_EBSA110 is not set
@@ -179,7 +192,6 @@ CONFIG_MMU=y
 # CONFIG_ARCH_STMP3XXX is not set
 # CONFIG_ARCH_NETX is not set
 # CONFIG_ARCH_H720X is not set
-# CONFIG_ARCH_NOMADIK is not set
 # CONFIG_ARCH_IOP13XX is not set
 # CONFIG_ARCH_IOP32X is not set
 # CONFIG_ARCH_IOP33X is not set
@@ -196,21 +208,26 @@ CONFIG_ARCH_MMP=y
 # CONFIG_ARCH_KS8695 is not set
 # CONFIG_ARCH_NS9XXX is not set
 # CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_NUC93X is not set
 # CONFIG_ARCH_PNX4008 is not set
 # CONFIG_ARCH_PXA is not set
 # CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_SHMOBILE is not set
 # CONFIG_ARCH_RPC is not set
 # CONFIG_ARCH_SA1100 is not set
 # CONFIG_ARCH_S3C2410 is not set
 # CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5P6440 is not set
+# CONFIG_ARCH_S5P6442 is not set
 # CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_S5PV210 is not set
 # CONFIG_ARCH_SHARK is not set
 # CONFIG_ARCH_LH7A40X is not set
 # CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_U8500 is not set
+# CONFIG_ARCH_NOMADIK is not set
 # CONFIG_ARCH_DAVINCI is not set
 # CONFIG_ARCH_OMAP is not set
-# CONFIG_ARCH_BCMRING is not set
-# CONFIG_ARCH_U8500 is not set
 # CONFIG_MACH_TAVOREVB is not set
 
 #
@@ -218,8 +235,10 @@ CONFIG_ARCH_MMP=y
 #
 # CONFIG_MACH_ASPENITE is not set
 # CONFIG_MACH_ZYLONITE2 is not set
+# CONFIG_MACH_AVENGERS_LITE is not set
 # CONFIG_MACH_TTC_DKB is not set
 CONFIG_MACH_FLINT=y
+CONFIG_MACH_MARVELL_JASPER=y
 CONFIG_CPU_MMP2=y
 CONFIG_PLAT_PXA=y
 
@@ -246,7 +265,10 @@ CONFIG_ARM_THUMB=y
 # CONFIG_CPU_ICACHE_DISABLE is not set
 # CONFIG_CPU_DCACHE_DISABLE is not set
 # CONFIG_CPU_BPREDICT_DISABLE is not set
+CONFIG_OUTER_CACHE=y
+CONFIG_CACHE_TAUROS2=y
 CONFIG_ARM_L1_CACHE_SHIFT=5
+CONFIG_CPU_HAS_PMU=y
 # CONFIG_ARM_ERRATA_411920 is not set
 CONFIG_COMMON_CLKDEV=y
 
@@ -298,7 +320,7 @@ CONFIG_ALIGNMENT_TRAP=y
 #
 CONFIG_ZBOOT_ROM_TEXT=0x0
 CONFIG_ZBOOT_ROM_BSS=0x0
-CONFIG_CMDLINE="root=/dev/nfs rootfstype=nfs nfsroot=192.168.1.100:/nfsroot/ ip=192.168.1.101:192.168.1.100::255.255.255.0::eth0:on console=ttyS0,115200 mem=128M user_debug=255"
+CONFIG_CMDLINE="root=/dev/nfs rootfstype=nfs nfsroot=192.168.1.100:/nfsroot/ ip=192.168.1.101:192.168.1.100::255.255.255.0::eth0:on console=ttyS2,38400 mem=128M user_debug=255"
 # CONFIG_XIP_KERNEL is not set
 # CONFIG_KEXEC is not set
 
@@ -338,7 +360,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -532,6 +553,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -640,6 +662,7 @@ CONFIG_SERIAL_PXA=y
 CONFIG_SERIAL_PXA_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -667,6 +690,7 @@ CONFIG_I2C_HELPER_AUTO=y
 CONFIG_I2C_PXA=y
 # CONFIG_I2C_PXA_SLAVE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -679,15 +703,9 @@ CONFIG_I2C_PXA=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -702,13 +720,16 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -737,10 +758,12 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 CONFIG_MFD_CORE=y
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_ASIC3 is not set
 # CONFIG_HTC_EGPIO is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
@@ -749,24 +772,27 @@ CONFIG_MFD_CORE=y
 # CONFIG_MFD_TC6393XB is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+CONFIG_MFD_MAX8925=y
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-CONFIG_MFD_88PM8607=y
 CONFIG_REGULATOR=y
 # CONFIG_REGULATOR_DEBUG is not set
+# CONFIG_REGULATOR_DUMMY is not set
 # CONFIG_REGULATOR_FIXED_VOLTAGE is not set
 # CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set
 # CONFIG_REGULATOR_USERSPACE_CONSUMER is not set
 # CONFIG_REGULATOR_BQ24022 is not set
 # CONFIG_REGULATOR_MAX1586 is not set
-CONFIG_REGULATOR_MAX8660=y
+CONFIG_REGULATOR_MAX8649=y
+# CONFIG_REGULATOR_MAX8660 is not set
+CONFIG_REGULATOR_MAX8925=y
 # CONFIG_REGULATOR_LP3971 is not set
 # CONFIG_REGULATOR_TPS65023 is not set
 # CONFIG_REGULATOR_TPS6507X is not set
-CONFIG_REGULATOR_88PM8607=y
 # CONFIG_MEDIA_SUPPORT is not set
 
 #
@@ -781,6 +807,7 @@ CONFIG_LCD_CLASS_DEVICE=y
 # CONFIG_LCD_PLATFORM is not set
 CONFIG_BACKLIGHT_CLASS_DEVICE=y
 CONFIG_BACKLIGHT_GENERIC=y
+CONFIG_BACKLIGHT_MAX8925=y
 
 #
 # Display device support
@@ -821,6 +848,7 @@ CONFIG_RTC_INTF_DEV=y
 # CONFIG_RTC_DRV_DS1374 is not set
 # CONFIG_RTC_DRV_DS1672 is not set
 # CONFIG_RTC_DRV_MAX6900 is not set
+CONFIG_RTC_DRV_MAX8925=y
 # CONFIG_RTC_DRV_RS5C372 is not set
 # CONFIG_RTC_DRV_ISL1208 is not set
 # CONFIG_RTC_DRV_X1205 is not set
@@ -872,7 +900,6 @@ CONFIG_RTC_INTF_DEV=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 CONFIG_FS_POSIX_ACL=y
@@ -883,7 +910,7 @@ CONFIG_FS_POSIX_ACL=y
 # CONFIG_NILFS2_FS is not set
 CONFIG_FILE_LOCKING=y
 CONFIG_FSNOTIFY=y
-CONFIG_DNOTIFY=y
+# CONFIG_DNOTIFY is not set
 CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
@@ -940,6 +967,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -967,6 +995,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -990,7 +1019,7 @@ CONFIG_FRAME_WARN=1024
 CONFIG_MAGIC_SYSRQ=y
 # CONFIG_STRIP_ASM_SYMS is not set
 # CONFIG_UNUSED_SYMBOLS is not set
-# CONFIG_DEBUG_FS is not set
+CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_SHIRQ is not set
@@ -1032,6 +1061,7 @@ CONFIG_DEBUG_MEMORY_INIT=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
@@ -1052,6 +1082,7 @@ CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
+CONFIG_DYNAMIC_DEBUG=y
 # CONFIG_SAMPLES is not set
 CONFIG_HAVE_ARCH_KGDB=y
 # CONFIG_KGDB is not set
@@ -1059,9 +1090,7 @@ CONFIG_ARM_UNWIND=y
 CONFIG_DEBUG_USER=y
 CONFIG_DEBUG_ERRORS=y
 # CONFIG_DEBUG_STACK_USAGE is not set
-CONFIG_DEBUG_LL=y
-# CONFIG_EARLY_PRINTK is not set
-# CONFIG_DEBUG_ICEDCC is not set
+# CONFIG_DEBUG_LL is not set
 # CONFIG_OC_ETM is not set
 
 #
diff --git a/arch/arm/configs/spear300_defconfig b/arch/arm/configs/spear300_defconfig
new file mode 100644 (file)
index 0000000..35e64d1
--- /dev/null
@@ -0,0 +1,773 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32
+# Tue Mar 23 14:36:23 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_CLK=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+# CONFIG_SLOW_WORK is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_BCMRING is not set
+CONFIG_PLAT_SPEAR=y
+CONFIG_ARCH_SPEAR3XX=y
+# CONFIG_ARCH_SPEAR6XX is not set
+CONFIG_MACH_SPEAR300=y
+# CONFIG_MACH_SPEAR310 is not set
+# CONFIG_MACH_SPEAR320 is not set
+CONFIG_BOARD_SPEAR300_EVB=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_LEGACY=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# 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_ARM_L1_CACHE_SHIFT=5
+CONFIG_ARM_VIC=y
+CONFIG_ARM_VIC_NR=2
+CONFIG_COMMON_CLKDEV=y
+
+#
+# Bus support
+#
+CONFIG_ARM_AMBA=y
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+# CONFIG_AEABI is not set
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_HAVE_MLOCK=y
+CONFIG_HAVE_MLOCKED_PAGE_BIT=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0
+CONFIG_ZBOOT_ROM_BSS=0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Power Management
+#
+# CONFIG_CPU_IDLE is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_MISC=y
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_NET is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+CONFIG_FIRMWARE_IN_KERNEL=y
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_ENCLOSURE_SERVICES is not set
+# CONFIG_C2PORT is not set
+
+#
+# EEPROM support
+#
+# CONFIG_EEPROM_93CX6 is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+CONFIG_INPUT_FF_MEMLESS=y
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# 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 is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+CONFIG_SERIO_SERPORT=y
+# CONFIG_SERIO_AMBAKMI is not set
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+# CONFIG_SERIAL_AMBA_PL010 is not set
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+CONFIG_RAW_DRIVER=y
+CONFIG_MAX_RAW_DEVS=8192
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
+CONFIG_GPIOLIB=y
+# CONFIG_DEBUG_GPIO is not set
+CONFIG_GPIO_SYSFS=y
+
+#
+# Memory mapped GPIO expanders:
+#
+CONFIG_GPIO_PL061=y
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# PCI GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+
+#
+# AC97 GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_MFD_T7L66XB is not set
+# CONFIG_MFD_TC6387XB is not set
+# CONFIG_MFD_TC6393XB is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+CONFIG_EXT2_FS_SECURITY=y
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+CONFIG_EXT3_FS_SECURITY=y
+# CONFIG_EXT4_FS is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+# CONFIG_INOTIFY is not set
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=m
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+# CONFIG_FSCACHE is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# 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_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="utf8"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+CONFIG_NLS_ASCII=m
+# CONFIG_NLS_ISO8859_1 is not set
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
+CONFIG_DETECT_HUNG_TASK=y
+# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
+CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+CONFIG_DEBUG_MEMORY_INIT=y
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+# CONFIG_DEBUG_NOTIFIERS is not set
+# CONFIG_DEBUG_CREDENTIALS is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+CONFIG_RCU_CPU_STALL_DETECTOR=y
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
+# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+# CONFIG_PAGE_POISONING is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_TRACING_SUPPORT=y
+CONFIG_FTRACE=y
+# CONFIG_FUNCTION_TRACER is not set
+# CONFIG_IRQSOFF_TRACER is not set
+# CONFIG_SCHED_TRACER is not set
+# CONFIG_ENABLE_DEFAULT_TRACERS is not set
+# CONFIG_BOOT_TRACER is not set
+CONFIG_BRANCH_PROFILE_NONE=y
+# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
+# CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_STACK_TRACER is not set
+# CONFIG_KMEMTRACE is not set
+# CONFIG_WORKQUEUE_TRACER is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_DYNAMIC_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_KGDB is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_DEBUG_ERRORS is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_LL is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/spear310_defconfig b/arch/arm/configs/spear310_defconfig
new file mode 100644 (file)
index 0000000..cbbfd29
--- /dev/null
@@ -0,0 +1,775 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32
+# Tue Mar 23 14:37:01 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_CLK=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+# CONFIG_SLOW_WORK is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_BCMRING is not set
+CONFIG_PLAT_SPEAR=y
+CONFIG_ARCH_SPEAR3XX=y
+# CONFIG_ARCH_SPEAR6XX is not set
+# CONFIG_MACH_SPEAR300 is not set
+CONFIG_MACH_SPEAR310=y
+# CONFIG_MACH_SPEAR320 is not set
+# CONFIG_BOARD_SPEAR300_EVB is not set
+CONFIG_BOARD_SPEAR310_EVB=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_LEGACY=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# 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_ARM_L1_CACHE_SHIFT=5
+CONFIG_ARM_VIC=y
+CONFIG_ARM_VIC_NR=2
+CONFIG_COMMON_CLKDEV=y
+
+#
+# Bus support
+#
+CONFIG_ARM_AMBA=y
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+# CONFIG_AEABI is not set
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_HAVE_MLOCK=y
+CONFIG_HAVE_MLOCKED_PAGE_BIT=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0
+CONFIG_ZBOOT_ROM_BSS=0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Power Management
+#
+# CONFIG_CPU_IDLE is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_MISC=y
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_NET is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+CONFIG_FIRMWARE_IN_KERNEL=y
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_MG_DISK is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_ENCLOSURE_SERVICES is not set
+# CONFIG_C2PORT is not set
+
+#
+# EEPROM support
+#
+# CONFIG_EEPROM_93CX6 is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+CONFIG_INPUT_FF_MEMLESS=y
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# 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 is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+CONFIG_SERIO_SERPORT=y
+# CONFIG_SERIO_AMBAKMI is not set
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+# CONFIG_SERIAL_AMBA_PL010 is not set
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+CONFIG_RAW_DRIVER=y
+CONFIG_MAX_RAW_DEVS=8192
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
+CONFIG_GPIOLIB=y
+# CONFIG_DEBUG_GPIO is not set
+CONFIG_GPIO_SYSFS=y
+
+#
+# Memory mapped GPIO expanders:
+#
+CONFIG_GPIO_PL061=y
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# PCI GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+
+#
+# AC97 GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_MFD_T7L66XB is not set
+# CONFIG_MFD_TC6387XB is not set
+# CONFIG_MFD_TC6393XB is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+CONFIG_EXT2_FS_SECURITY=y
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+CONFIG_EXT3_FS_SECURITY=y
+# CONFIG_EXT4_FS is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+# CONFIG_INOTIFY is not set
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=m
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+# CONFIG_FSCACHE is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# 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_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="utf8"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+CONFIG_NLS_ASCII=m
+# CONFIG_NLS_ISO8859_1 is not set
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
+CONFIG_DETECT_HUNG_TASK=y
+# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
+CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+CONFIG_DEBUG_MEMORY_INIT=y
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+# CONFIG_DEBUG_NOTIFIERS is not set
+# CONFIG_DEBUG_CREDENTIALS is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+CONFIG_RCU_CPU_STALL_DETECTOR=y
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
+# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+# CONFIG_PAGE_POISONING is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_TRACING_SUPPORT=y
+CONFIG_FTRACE=y
+# CONFIG_FUNCTION_TRACER is not set
+# CONFIG_IRQSOFF_TRACER is not set
+# CONFIG_SCHED_TRACER is not set
+# CONFIG_ENABLE_DEFAULT_TRACERS is not set
+# CONFIG_BOOT_TRACER is not set
+CONFIG_BRANCH_PROFILE_NONE=y
+# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
+# CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_STACK_TRACER is not set
+# CONFIG_KMEMTRACE is not set
+# CONFIG_WORKQUEUE_TRACER is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_DYNAMIC_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_KGDB is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_DEBUG_ERRORS is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_LL is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/spear320_defconfig b/arch/arm/configs/spear320_defconfig
new file mode 100644 (file)
index 0000000..2ae3c11
--- /dev/null
@@ -0,0 +1,775 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32
+# Tue Mar 23 14:37:12 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_CLK=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+# CONFIG_SLOW_WORK is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_BCMRING is not set
+CONFIG_PLAT_SPEAR=y
+CONFIG_ARCH_SPEAR3XX=y
+# CONFIG_ARCH_SPEAR6XX is not set
+# CONFIG_MACH_SPEAR300 is not set
+# CONFIG_MACH_SPEAR310 is not set
+CONFIG_MACH_SPEAR320=y
+# CONFIG_BOARD_SPEAR300_EVB is not set
+CONFIG_BOARD_SPEAR320_EVB=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_LEGACY=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# 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_ARM_L1_CACHE_SHIFT=5
+CONFIG_ARM_VIC=y
+CONFIG_ARM_VIC_NR=2
+CONFIG_COMMON_CLKDEV=y
+
+#
+# Bus support
+#
+CONFIG_ARM_AMBA=y
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+# CONFIG_AEABI is not set
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_HAVE_MLOCK=y
+CONFIG_HAVE_MLOCKED_PAGE_BIT=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0
+CONFIG_ZBOOT_ROM_BSS=0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Power Management
+#
+# CONFIG_CPU_IDLE is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_MISC=y
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_NET is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+CONFIG_FIRMWARE_IN_KERNEL=y
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_MG_DISK is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_ENCLOSURE_SERVICES is not set
+# CONFIG_C2PORT is not set
+
+#
+# EEPROM support
+#
+# CONFIG_EEPROM_93CX6 is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+CONFIG_INPUT_FF_MEMLESS=y
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# 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 is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+CONFIG_SERIO_SERPORT=y
+# CONFIG_SERIO_AMBAKMI is not set
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+# CONFIG_SERIAL_AMBA_PL010 is not set
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+CONFIG_RAW_DRIVER=y
+CONFIG_MAX_RAW_DEVS=8192
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
+CONFIG_GPIOLIB=y
+# CONFIG_DEBUG_GPIO is not set
+CONFIG_GPIO_SYSFS=y
+
+#
+# Memory mapped GPIO expanders:
+#
+CONFIG_GPIO_PL061=y
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# PCI GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+
+#
+# AC97 GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_MFD_T7L66XB is not set
+# CONFIG_MFD_TC6387XB is not set
+# CONFIG_MFD_TC6393XB is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+CONFIG_EXT2_FS_SECURITY=y
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+CONFIG_EXT3_FS_SECURITY=y
+# CONFIG_EXT4_FS is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+# CONFIG_INOTIFY is not set
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=m
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+# CONFIG_FSCACHE is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# 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_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="utf8"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+CONFIG_NLS_ASCII=m
+# CONFIG_NLS_ISO8859_1 is not set
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
+CONFIG_DETECT_HUNG_TASK=y
+# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
+CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+CONFIG_DEBUG_MEMORY_INIT=y
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+# CONFIG_DEBUG_NOTIFIERS is not set
+# CONFIG_DEBUG_CREDENTIALS is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+CONFIG_RCU_CPU_STALL_DETECTOR=y
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
+# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+# CONFIG_PAGE_POISONING is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_TRACING_SUPPORT=y
+CONFIG_FTRACE=y
+# CONFIG_FUNCTION_TRACER is not set
+# CONFIG_IRQSOFF_TRACER is not set
+# CONFIG_SCHED_TRACER is not set
+# CONFIG_ENABLE_DEFAULT_TRACERS is not set
+# CONFIG_BOOT_TRACER is not set
+CONFIG_BRANCH_PROFILE_NONE=y
+# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
+# CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_STACK_TRACER is not set
+# CONFIG_KMEMTRACE is not set
+# CONFIG_WORKQUEUE_TRACER is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_DYNAMIC_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_KGDB is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_DEBUG_ERRORS is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_LL is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/spear600_defconfig b/arch/arm/configs/spear600_defconfig
new file mode 100644 (file)
index 0000000..c85a029
--- /dev/null
@@ -0,0 +1,760 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.32
+# Tue Mar 23 14:37:26 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SWAP=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+
+#
+# RCU Subsystem
+#
+CONFIG_TREE_RCU=y
+# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=17
+# CONFIG_GROUP_SCHED is not set
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_ALL is not set
+CONFIG_KALLSYMS_EXTRA_PASS=y
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+
+#
+# Kernel Performance Events And Counters
+#
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_SLUB_DEBUG=y
+CONFIG_COMPAT_BRK=y
+# CONFIG_SLAB is not set
+CONFIG_SLUB=y
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_CLK=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_GCOV_KERNEL is not set
+# CONFIG_SLOW_WORK is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+CONFIG_MODVERSIONS=y
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+CONFIG_IOSCHED_AS=y
+CONFIG_IOSCHED_DEADLINE=y
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_AS is not set
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_FREEZER is not set
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+# CONFIG_ARCH_AT91 is not set
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_BCMRING is not set
+CONFIG_PLAT_SPEAR=y
+# CONFIG_ARCH_SPEAR3XX is not set
+CONFIG_ARCH_SPEAR6XX=y
+# CONFIG_MACH_SPEAR300 is not set
+# CONFIG_MACH_SPEAR310 is not set
+# CONFIG_MACH_SPEAR320 is not set
+# CONFIG_BOARD_SPEAR300_EVB is not set
+CONFIG_MACH_SPEAR600=y
+CONFIG_BOARD_SPEAR600_EVB=y
+
+#
+# Processor Type
+#
+CONFIG_CPU_32=y
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_LEGACY=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# 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_ARM_L1_CACHE_SHIFT=5
+CONFIG_ARM_VIC=y
+CONFIG_ARM_VIC_NR=2
+CONFIG_COMMON_CLKDEV=y
+
+#
+# Bus support
+#
+CONFIG_ARM_AMBA=y
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+# CONFIG_NO_HZ is not set
+# CONFIG_HIGH_RES_TIMERS is not set
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+CONFIG_PREEMPT_NONE=y
+# CONFIG_PREEMPT_VOLUNTARY is not set
+# CONFIG_PREEMPT is not set
+CONFIG_HZ=100
+# CONFIG_AEABI is not set
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=4096
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+CONFIG_HAVE_MLOCK=y
+CONFIG_HAVE_MLOCKED_PAGE_BIT=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0
+CONFIG_ZBOOT_ROM_BSS=0
+CONFIG_CMDLINE=""
+# CONFIG_XIP_KERNEL is not set
+# CONFIG_KEXEC is not set
+
+#
+# CPU Power Management
+#
+# CONFIG_CPU_IDLE is not set
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_FPE_NWFPE is not set
+# CONFIG_FPE_FASTFPE is not set
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+CONFIG_BINFMT_MISC=y
+# CONFIG_ARTHUR is not set
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+# CONFIG_NET is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+CONFIG_FIRMWARE_IN_KERNEL=y
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_DEBUG_DRIVER is not set
+# CONFIG_DEBUG_DEVRES is not set
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_MTD is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+# CONFIG_BLK_DEV_LOOP is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=16384
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_ENCLOSURE_SERVICES is not set
+# CONFIG_C2PORT is not set
+
+#
+# EEPROM support
+#
+# CONFIG_EEPROM_93CX6 is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+# CONFIG_SCSI is not set
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+CONFIG_INPUT_FF_MEMLESS=y
+# CONFIG_INPUT_POLLDEV is not set
+
+#
+# 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 is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Hardware I/O ports
+#
+CONFIG_SERIO=y
+CONFIG_SERIO_SERPORT=y
+# CONFIG_SERIO_AMBAKMI is not set
+# CONFIG_SERIO_RAW is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+# CONFIG_SERIAL_AMBA_PL010 is not set
+CONFIG_SERIAL_AMBA_PL011=y
+CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_R3964 is not set
+CONFIG_RAW_DRIVER=y
+CONFIG_MAX_RAW_DEVS=8192
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+# CONFIG_SPI is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
+CONFIG_GPIOLIB=y
+# CONFIG_DEBUG_GPIO is not set
+CONFIG_GPIO_SYSFS=y
+
+#
+# Memory mapped GPIO expanders:
+#
+CONFIG_GPIO_PL061=y
+
+#
+# I2C GPIO expanders:
+#
+
+#
+# PCI GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+
+#
+# AC97 GPIO expanders:
+#
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+# CONFIG_WATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_MFD_T7L66XB is not set
+# CONFIG_MFD_TC6387XB is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_HID_SUPPORT is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_MEMSTICK is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+# CONFIG_RTC_CLASS is not set
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+CONFIG_EXT2_FS_SECURITY=y
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+CONFIG_EXT3_FS_SECURITY=y
+# CONFIG_EXT4_FS is not set
+CONFIG_JBD=y
+# CONFIG_JBD_DEBUG is not set
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_GFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+# CONFIG_INOTIFY is not set
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+CONFIG_AUTOFS4_FS=m
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+# CONFIG_FSCACHE is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# 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_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+
+#
+# Partition Types
+#
+CONFIG_PARTITION_ADVANCED=y
+# CONFIG_ACORN_PARTITION is not set
+# CONFIG_OSF_PARTITION is not set
+# CONFIG_AMIGA_PARTITION is not set
+# CONFIG_ATARI_PARTITION is not set
+# CONFIG_MAC_PARTITION is not set
+CONFIG_MSDOS_PARTITION=y
+# CONFIG_BSD_DISKLABEL is not set
+# CONFIG_MINIX_SUBPARTITION is not set
+# CONFIG_SOLARIS_X86_PARTITION is not set
+# CONFIG_UNIXWARE_DISKLABEL is not set
+# CONFIG_LDM_PARTITION is not set
+# CONFIG_SGI_PARTITION is not set
+# CONFIG_ULTRIX_PARTITION is not set
+# CONFIG_SUN_PARTITION is not set
+# CONFIG_KARMA_PARTITION is not set
+# CONFIG_EFI_PARTITION is not set
+# CONFIG_SYSV68_PARTITION is not set
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="utf8"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+# CONFIG_NLS_CODEPAGE_850 is not set
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+CONFIG_NLS_ASCII=m
+# CONFIG_NLS_ISO8859_1 is not set
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+# CONFIG_NLS_ISO8859_15 is not set
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+# CONFIG_NLS_UTF8 is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+CONFIG_DEBUG_FS=y
+# CONFIG_HEADERS_CHECK is not set
+CONFIG_DEBUG_KERNEL=y
+# CONFIG_DEBUG_SHIRQ is not set
+CONFIG_DETECT_SOFTLOCKUP=y
+# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
+CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
+CONFIG_DETECT_HUNG_TASK=y
+# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
+CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
+CONFIG_SCHED_DEBUG=y
+# CONFIG_SCHEDSTATS is not set
+# CONFIG_TIMER_STATS is not set
+# CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_SLUB_DEBUG_ON is not set
+# CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
+# CONFIG_DEBUG_RT_MUTEXES is not set
+# CONFIG_RT_MUTEX_TESTER is not set
+CONFIG_DEBUG_SPINLOCK=y
+# CONFIG_DEBUG_MUTEXES is not set
+# CONFIG_DEBUG_LOCK_ALLOC is not set
+# CONFIG_PROVE_LOCKING is not set
+# CONFIG_LOCK_STAT is not set
+CONFIG_DEBUG_SPINLOCK_SLEEP=y
+# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
+# CONFIG_DEBUG_KOBJECT is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_INFO=y
+# CONFIG_DEBUG_VM is not set
+# CONFIG_DEBUG_WRITECOUNT is not set
+CONFIG_DEBUG_MEMORY_INIT=y
+# CONFIG_DEBUG_LIST is not set
+# CONFIG_DEBUG_SG is not set
+# CONFIG_DEBUG_NOTIFIERS is not set
+# CONFIG_DEBUG_CREDENTIALS is not set
+CONFIG_FRAME_POINTER=y
+# CONFIG_BOOT_PRINTK_DELAY is not set
+# CONFIG_RCU_TORTURE_TEST is not set
+CONFIG_RCU_CPU_STALL_DETECTOR=y
+# CONFIG_BACKTRACE_SELF_TEST is not set
+# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
+# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+# CONFIG_PAGE_POISONING is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_TRACING_SUPPORT=y
+CONFIG_FTRACE=y
+# CONFIG_FUNCTION_TRACER is not set
+# CONFIG_IRQSOFF_TRACER is not set
+# CONFIG_SCHED_TRACER is not set
+# CONFIG_ENABLE_DEFAULT_TRACERS is not set
+# CONFIG_BOOT_TRACER is not set
+CONFIG_BRANCH_PROFILE_NONE=y
+# CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
+# CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_STACK_TRACER is not set
+# CONFIG_KMEMTRACE is not set
+# CONFIG_WORKQUEUE_TRACER is not set
+# CONFIG_BLK_DEV_IO_TRACE is not set
+# CONFIG_DYNAMIC_DEBUG is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_KGDB is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_DEBUG_ERRORS is not set
+# CONFIG_DEBUG_STACK_USAGE is not set
+# CONFIG_DEBUG_LL is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+# CONFIG_CRC32 is not set
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
diff --git a/arch/arm/configs/stamp9g20_defconfig b/arch/arm/configs/stamp9g20_defconfig
new file mode 100644 (file)
index 0000000..06a8293
--- /dev/null
@@ -0,0 +1,1456 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.34-rc1
+# Wed Mar 17 16:38:03 2010
+#
+CONFIG_ARM=y
+CONFIG_SYS_SUPPORTS_APM_EMULATION=y
+CONFIG_GENERIC_GPIO=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_HAVE_PROC_CPU=y
+CONFIG_GENERIC_HARDIRQS=y
+CONFIG_STACKTRACE_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
+CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_TRACE_IRQFLAGS_SUPPORT=y
+CONFIG_HARDIRQS_SW_RESEND=y
+CONFIG_GENERIC_IRQ_PROBE=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_VECTORS_BASE=0xffff0000
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+CONFIG_CONSTRUCTORS=y
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+# CONFIG_LOCALVERSION_AUTO is not set
+CONFIG_HAVE_KERNEL_GZIP=y
+CONFIG_HAVE_KERNEL_LZO=y
+CONFIG_KERNEL_GZIP=y
+# CONFIG_KERNEL_BZIP2 is not set
+# CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
+# CONFIG_SWAP is not set
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+# CONFIG_BSD_PROCESS_ACCT is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_AUDIT is not set
+
+#
+# RCU Subsystem
+#
+# CONFIG_TREE_RCU is not set
+CONFIG_TREE_PREEMPT_RCU=y
+# CONFIG_TINY_RCU is not set
+# CONFIG_RCU_TRACE is not set
+CONFIG_RCU_FANOUT=32
+# CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_TREE_RCU_TRACE is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_SYSFS_DEPRECATED_V2 is not set
+# CONFIG_RELAY is not set
+CONFIG_NAMESPACES=y
+# CONFIG_UTS_NS is not set
+# CONFIG_IPC_NS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_NET_NS is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_RD_LZO=y
+CONFIG_CC_OPTIMIZE_FOR_SIZE=y
+CONFIG_SYSCTL=y
+CONFIG_ANON_INODES=y
+# CONFIG_EMBEDDED is not set
+CONFIG_UID16=y
+CONFIG_SYSCTL_SYSCALL=y
+CONFIG_KALLSYMS=y
+# CONFIG_KALLSYMS_EXTRA_PASS is not set
+CONFIG_HOTPLUG=y
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_TIMERFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+CONFIG_AIO=y
+CONFIG_HAVE_PERF_EVENTS=y
+CONFIG_PERF_USE_VMALLOC=y
+
+#
+# Kernel Performance Events And Counters
+#
+# CONFIG_PERF_EVENTS is not set
+# CONFIG_PERF_COUNTERS is not set
+CONFIG_VM_EVENT_COUNTERS=y
+CONFIG_COMPAT_BRK=y
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+# CONFIG_PROFILING is not set
+CONFIG_HAVE_OPROFILE=y
+# CONFIG_KPROBES is not set
+CONFIG_HAVE_KPROBES=y
+CONFIG_HAVE_KRETPROBES=y
+CONFIG_HAVE_CLK=y
+
+#
+# GCOV-based kernel profiling
+#
+# CONFIG_SLOW_WORK is not set
+CONFIG_HAVE_GENERIC_DMA_COHERENT=y
+CONFIG_SLABINFO=y
+CONFIG_RT_MUTEXES=y
+CONFIG_BASE_SMALL=0
+CONFIG_MODULES=y
+# CONFIG_MODULE_FORCE_LOAD is not set
+CONFIG_MODULE_UNLOAD=y
+# CONFIG_MODULE_FORCE_UNLOAD is not set
+# CONFIG_MODVERSIONS is not set
+# CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_BLOCK=y
+# CONFIG_LBDAF is not set
+# CONFIG_BLK_DEV_BSG is not set
+# CONFIG_BLK_DEV_INTEGRITY is not set
+
+#
+# IO Schedulers
+#
+CONFIG_IOSCHED_NOOP=y
+# CONFIG_IOSCHED_DEADLINE is not set
+CONFIG_IOSCHED_CFQ=y
+# CONFIG_DEFAULT_DEADLINE is not set
+CONFIG_DEFAULT_CFQ=y
+# CONFIG_DEFAULT_NOOP is not set
+CONFIG_DEFAULT_IOSCHED="cfq"
+# CONFIG_INLINE_SPIN_TRYLOCK is not set
+# CONFIG_INLINE_SPIN_TRYLOCK_BH is not set
+# CONFIG_INLINE_SPIN_LOCK is not set
+# CONFIG_INLINE_SPIN_LOCK_BH is not set
+# CONFIG_INLINE_SPIN_LOCK_IRQ is not set
+# CONFIG_INLINE_SPIN_LOCK_IRQSAVE is not set
+# CONFIG_INLINE_SPIN_UNLOCK is not set
+# CONFIG_INLINE_SPIN_UNLOCK_BH is not set
+# CONFIG_INLINE_SPIN_UNLOCK_IRQ is not set
+# CONFIG_INLINE_SPIN_UNLOCK_IRQRESTORE is not set
+# CONFIG_INLINE_READ_TRYLOCK is not set
+# CONFIG_INLINE_READ_LOCK is not set
+# CONFIG_INLINE_READ_LOCK_BH is not set
+# CONFIG_INLINE_READ_LOCK_IRQ is not set
+# CONFIG_INLINE_READ_LOCK_IRQSAVE is not set
+# CONFIG_INLINE_READ_UNLOCK is not set
+# CONFIG_INLINE_READ_UNLOCK_BH is not set
+# CONFIG_INLINE_READ_UNLOCK_IRQ is not set
+# CONFIG_INLINE_READ_UNLOCK_IRQRESTORE is not set
+# CONFIG_INLINE_WRITE_TRYLOCK is not set
+# CONFIG_INLINE_WRITE_LOCK is not set
+# CONFIG_INLINE_WRITE_LOCK_BH is not set
+# CONFIG_INLINE_WRITE_LOCK_IRQ is not set
+# CONFIG_INLINE_WRITE_LOCK_IRQSAVE is not set
+# CONFIG_INLINE_WRITE_UNLOCK is not set
+# CONFIG_INLINE_WRITE_UNLOCK_BH is not set
+# CONFIG_INLINE_WRITE_UNLOCK_IRQ is not set
+# CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
+# CONFIG_MUTEX_SPIN_ON_OWNER is not set
+CONFIG_FREEZER=y
+
+#
+# System Type
+#
+CONFIG_MMU=y
+# CONFIG_ARCH_AAEC2000 is not set
+# CONFIG_ARCH_INTEGRATOR is not set
+# CONFIG_ARCH_REALVIEW is not set
+# CONFIG_ARCH_VERSATILE is not set
+CONFIG_ARCH_AT91=y
+# CONFIG_ARCH_CLPS711X is not set
+# CONFIG_ARCH_GEMINI is not set
+# CONFIG_ARCH_EBSA110 is not set
+# CONFIG_ARCH_EP93XX is not set
+# CONFIG_ARCH_FOOTBRIDGE is not set
+# CONFIG_ARCH_MXC is not set
+# CONFIG_ARCH_STMP3XXX is not set
+# CONFIG_ARCH_NETX is not set
+# CONFIG_ARCH_H720X is not set
+# CONFIG_ARCH_NOMADIK is not set
+# CONFIG_ARCH_IOP13XX is not set
+# CONFIG_ARCH_IOP32X is not set
+# CONFIG_ARCH_IOP33X is not set
+# CONFIG_ARCH_IXP23XX is not set
+# CONFIG_ARCH_IXP2000 is not set
+# CONFIG_ARCH_IXP4XX is not set
+# CONFIG_ARCH_L7200 is not set
+# CONFIG_ARCH_DOVE is not set
+# CONFIG_ARCH_KIRKWOOD is not set
+# CONFIG_ARCH_LOKI is not set
+# CONFIG_ARCH_MV78XX0 is not set
+# CONFIG_ARCH_ORION5X is not set
+# CONFIG_ARCH_MMP is not set
+# CONFIG_ARCH_KS8695 is not set
+# CONFIG_ARCH_NS9XXX is not set
+# CONFIG_ARCH_W90X900 is not set
+# CONFIG_ARCH_NUC93X is not set
+# CONFIG_ARCH_PNX4008 is not set
+# CONFIG_ARCH_PXA is not set
+# CONFIG_ARCH_MSM is not set
+# CONFIG_ARCH_RPC is not set
+# CONFIG_ARCH_SA1100 is not set
+# CONFIG_ARCH_S3C2410 is not set
+# CONFIG_ARCH_S3C64XX is not set
+# CONFIG_ARCH_S5PC1XX is not set
+# CONFIG_ARCH_SHARK is not set
+# CONFIG_ARCH_LH7A40X is not set
+# CONFIG_ARCH_U300 is not set
+# CONFIG_ARCH_DAVINCI is not set
+# CONFIG_ARCH_OMAP is not set
+# CONFIG_ARCH_BCMRING is not set
+# CONFIG_ARCH_U8500 is not set
+CONFIG_HAVE_AT91_USART3=y
+CONFIG_HAVE_AT91_USART4=y
+CONFIG_HAVE_AT91_USART5=y
+
+#
+# Atmel AT91 System-on-Chip
+#
+# CONFIG_ARCH_AT91RM9200 is not set
+# CONFIG_ARCH_AT91SAM9260 is not set
+# CONFIG_ARCH_AT91SAM9261 is not set
+# CONFIG_ARCH_AT91SAM9G10 is not set
+# CONFIG_ARCH_AT91SAM9263 is not set
+# CONFIG_ARCH_AT91SAM9RL is not set
+CONFIG_ARCH_AT91SAM9G20=y
+# CONFIG_ARCH_AT91SAM9G45 is not set
+# CONFIG_ARCH_AT91CAP9 is not set
+# CONFIG_ARCH_AT572D940HF is not set
+# CONFIG_ARCH_AT91X40 is not set
+CONFIG_AT91_PMC_UNIT=y
+
+#
+# AT91SAM9G20 Board Type
+#
+# CONFIG_MACH_AT91SAM9G20EK is not set
+# CONFIG_MACH_AT91SAM9G20EK_2MMC is not set
+# CONFIG_MACH_CPU9G20 is not set
+CONFIG_MACH_PORTUXG20=y
+CONFIG_MACH_STAMP9G20=y
+
+#
+# AT91 Board Options
+#
+
+#
+# AT91 Feature Selections
+#
+CONFIG_AT91_PROGRAMMABLE_CLOCKS=y
+CONFIG_AT91_SLOW_CLOCK=y
+CONFIG_AT91_TIMER_HZ=100
+CONFIG_AT91_EARLY_DBGU=y
+# CONFIG_AT91_EARLY_USART0 is not set
+# CONFIG_AT91_EARLY_USART1 is not set
+# CONFIG_AT91_EARLY_USART2 is not set
+# CONFIG_AT91_EARLY_USART3 is not set
+# CONFIG_AT91_EARLY_USART4 is not set
+# CONFIG_AT91_EARLY_USART5 is not set
+
+#
+# Processor Type
+#
+CONFIG_CPU_ARM926T=y
+CONFIG_CPU_32v5=y
+CONFIG_CPU_ABRT_EV5TJ=y
+CONFIG_CPU_PABRT_LEGACY=y
+CONFIG_CPU_CACHE_VIVT=y
+CONFIG_CPU_COPY_V4WB=y
+CONFIG_CPU_TLB_V4WBI=y
+CONFIG_CPU_CP15=y
+CONFIG_CPU_CP15_MMU=y
+
+#
+# Processor Features
+#
+CONFIG_ARM_THUMB=y
+# 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_ARM_L1_CACHE_SHIFT=5
+
+#
+# Bus support
+#
+# CONFIG_PCI_SYSCALL is not set
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+# CONFIG_PCCARD is not set
+
+#
+# Kernel Features
+#
+CONFIG_TICK_ONESHOT=y
+CONFIG_NO_HZ=y
+CONFIG_HIGH_RES_TIMERS=y
+CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
+CONFIG_VMSPLIT_3G=y
+# CONFIG_VMSPLIT_2G is not set
+# CONFIG_VMSPLIT_1G is not set
+CONFIG_PAGE_OFFSET=0xC0000000
+# CONFIG_PREEMPT_NONE is not set
+# CONFIG_PREEMPT_VOLUNTARY is not set
+CONFIG_PREEMPT=y
+CONFIG_HZ=100
+CONFIG_AEABI=y
+# CONFIG_OABI_COMPAT is not set
+# CONFIG_ARCH_SPARSEMEM_DEFAULT is not set
+# CONFIG_ARCH_SELECT_MEMORY_MODEL is not set
+# CONFIG_HIGHMEM is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+CONFIG_PAGEFLAGS_EXTENDED=y
+CONFIG_SPLIT_PTLOCK_CPUS=999999
+# CONFIG_PHYS_ADDR_T_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_VIRT_TO_BUS=y
+# CONFIG_KSM is not set
+CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+# CONFIG_LEDS is not set
+CONFIG_ALIGNMENT_TRAP=y
+# CONFIG_UACCESS_WITH_MEMCPY is not set
+
+#
+# Boot options
+#
+CONFIG_ZBOOT_ROM_TEXT=0x0
+CONFIG_ZBOOT_ROM_BSS=0x0
+CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,3145728 root=/dev/ram0 rw"
+# CONFIG_XIP_KERNEL is not set
+CONFIG_KEXEC=y
+CONFIG_ATAGS_PROC=y
+
+#
+# CPU Power Management
+#
+CONFIG_CPU_IDLE=y
+CONFIG_CPU_IDLE_GOV_LADDER=y
+CONFIG_CPU_IDLE_GOV_MENU=y
+
+#
+# Floating point emulation
+#
+
+#
+# At least one emulation must be selected
+#
+# CONFIG_VFP is not set
+
+#
+# Userspace binary formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_HAVE_AOUT=y
+# CONFIG_BINFMT_AOUT is not set
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Power management options
+#
+CONFIG_PM=y
+# CONFIG_PM_DEBUG is not set
+CONFIG_PM_SLEEP=y
+CONFIG_SUSPEND=y
+CONFIG_SUSPEND_FREEZER=y
+# CONFIG_APM_EMULATION is not set
+# CONFIG_PM_RUNTIME is not set
+CONFIG_PM_OPS=y
+CONFIG_ARCH_SUSPEND_POSSIBLE=y
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+# CONFIG_IP_MULTICAST is not set
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+# CONFIG_IP_PNP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+CONFIG_INET_DIAG=y
+CONFIG_INET_TCP_DIAG=y
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_RDS is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_NET_DSA is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_PHONET is not set
+# CONFIG_IEEE802154 is not set
+# CONFIG_NET_SCHED is not set
+# CONFIG_DCB is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_CAN is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+# CONFIG_WIRELESS is not set
+# CONFIG_WIMAX is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
+# CONFIG_DEVTMPFS is not set
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+CONFIG_FW_LOADER=y
+CONFIG_FIRMWARE_IN_KERNEL=y
+CONFIG_EXTRA_FIRMWARE=""
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_TESTS is not set
+CONFIG_MTD_CONCAT=y
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AFS_PARTS is not set
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+# CONFIG_FTL is not set
+# CONFIG_NFTL is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+# CONFIG_MTD_CFI is not set
+# CONFIG_MTD_JEDECPROBE is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+CONFIG_MTD_DATAFLASH=y
+# CONFIG_MTD_DATAFLASH_WRITE_VERIFY is not set
+# CONFIG_MTD_DATAFLASH_OTP is not set
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SST25L is not set
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# 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_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+# CONFIG_MTD_NAND_GPIO is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+CONFIG_MTD_NAND_ATMEL=y
+# CONFIG_MTD_NAND_ATMEL_ECC_HW is not set
+CONFIG_MTD_NAND_ATMEL_ECC_SOFT=y
+# CONFIG_MTD_NAND_ATMEL_ECC_NONE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+# CONFIG_MTD_NAND_PLATFORM is not set
+# CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# LPDDR flash memory drivers
+#
+# CONFIG_MTD_LPDDR is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_BLK_DEV=y
+# CONFIG_BLK_DEV_COW_COMMON is not set
+CONFIG_BLK_DEV_LOOP=y
+# CONFIG_BLK_DEV_CRYPTOLOOP is not set
+
+#
+# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
+#
+# CONFIG_BLK_DEV_NBD is not set
+# CONFIG_BLK_DEV_UB is not set
+CONFIG_BLK_DEV_RAM=y
+CONFIG_BLK_DEV_RAM_COUNT=16
+CONFIG_BLK_DEV_RAM_SIZE=8192
+# CONFIG_BLK_DEV_XIP is not set
+# CONFIG_CDROM_PKTCDVD is not set
+# CONFIG_ATA_OVER_ETH is not set
+# CONFIG_MG_DISK is not set
+# CONFIG_MISC_DEVICES is not set
+CONFIG_HAVE_IDE=y
+# CONFIG_IDE is not set
+
+#
+# SCSI device support
+#
+# CONFIG_RAID_ATTRS is not set
+CONFIG_SCSI=y
+CONFIG_SCSI_DMA=y
+# CONFIG_SCSI_TGT is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_SCSI_PROC_FS=y
+
+#
+# SCSI support type (disk, tape, CD-ROM)
+#
+CONFIG_BLK_DEV_SD=y
+# CONFIG_CHR_DEV_ST is not set
+# CONFIG_CHR_DEV_OSST is not set
+# CONFIG_BLK_DEV_SR is not set
+# CONFIG_CHR_DEV_SG is not set
+# CONFIG_CHR_DEV_SCH is not set
+CONFIG_SCSI_MULTI_LUN=y
+# CONFIG_SCSI_CONSTANTS is not set
+# CONFIG_SCSI_LOGGING is not set
+# CONFIG_SCSI_SCAN_ASYNC is not set
+CONFIG_SCSI_WAIT_SCAN=m
+
+#
+# SCSI Transports
+#
+# CONFIG_SCSI_SPI_ATTRS is not set
+# CONFIG_SCSI_FC_ATTRS is not set
+# CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_LIBSAS is not set
+# CONFIG_SCSI_SRP_ATTRS is not set
+# CONFIG_SCSI_LOWLEVEL is not set
+# CONFIG_SCSI_DH is not set
+# CONFIG_SCSI_OSD_INITIATOR is not set
+# CONFIG_ATA is not set
+# CONFIG_MD is not set
+CONFIG_NETDEVICES=y
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+CONFIG_PHYLIB=y
+
+#
+# MII PHY device drivers
+#
+# CONFIG_MARVELL_PHY is not set
+# CONFIG_DAVICOM_PHY is not set
+# CONFIG_QSEMI_PHY is not set
+# CONFIG_LXT_PHY is not set
+# CONFIG_CICADA_PHY is not set
+# CONFIG_VITESSE_PHY is not set
+# CONFIG_SMSC_PHY is not set
+# CONFIG_BROADCOM_PHY is not set
+# CONFIG_ICPLUS_PHY is not set
+# CONFIG_REALTEK_PHY is not set
+# CONFIG_NATIONAL_PHY is not set
+# CONFIG_STE10XP is not set
+# CONFIG_LSI_ET1011C_PHY is not set
+# CONFIG_FIXED_PHY is not set
+# CONFIG_MDIO_BITBANG is not set
+CONFIG_NET_ETHERNET=y
+# CONFIG_MII is not set
+CONFIG_MACB=y
+# CONFIG_AX88796 is not set
+# CONFIG_SMC91X is not set
+# CONFIG_DM9000 is not set
+# CONFIG_ENC28J60 is not set
+# CONFIG_ETHOC is not set
+# CONFIG_SMC911X is not set
+# CONFIG_SMSC911X is not set
+# CONFIG_DNET is not set
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
+# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
+# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
+# CONFIG_B44 is not set
+# CONFIG_KS8842 is not set
+# CONFIG_KS8851 is not set
+# CONFIG_KS8851_MLL is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+# CONFIG_WLAN is not set
+
+#
+# Enable WiMAX (Networking options) to see the WiMAX drivers
+#
+
+#
+# USB Network Adapters
+#
+# CONFIG_USB_CATC is not set
+# CONFIG_USB_KAWETH is not set
+# CONFIG_USB_PEGASUS is not set
+# CONFIG_USB_RTL8150 is not set
+# CONFIG_USB_USBNET is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+CONFIG_INPUT=y
+# CONFIG_INPUT_FF_MEMLESS is not set
+# CONFIG_INPUT_POLLDEV is not set
+# CONFIG_INPUT_SPARSEKMAP is not set
+
+#
+# Userland interfaces
+#
+CONFIG_INPUT_MOUSEDEV=y
+# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
+CONFIG_INPUT_MOUSEDEV_SCREEN_X=320
+CONFIG_INPUT_MOUSEDEV_SCREEN_Y=240
+# CONFIG_INPUT_JOYDEV is not set
+# CONFIG_INPUT_EVDEV is not set
+# CONFIG_INPUT_EVBUG is not set
+
+#
+# Input Device Drivers
+#
+# CONFIG_INPUT_KEYBOARD is not set
+# CONFIG_INPUT_MOUSE is not set
+# CONFIG_INPUT_JOYSTICK is not set
+# CONFIG_INPUT_TABLET is not set
+# CONFIG_INPUT_TOUCHSCREEN is not set
+# CONFIG_INPUT_MISC is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+CONFIG_VT=y
+CONFIG_CONSOLE_TRANSLATIONS=y
+CONFIG_VT_CONSOLE=y
+CONFIG_HW_CONSOLE=y
+# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_DEVKMEM=y
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+# CONFIG_SERIAL_8250 is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_ATMEL=y
+CONFIG_SERIAL_ATMEL_CONSOLE=y
+CONFIG_SERIAL_ATMEL_PDC=y
+# CONFIG_SERIAL_ATMEL_TTYAT is not set
+# CONFIG_SERIAL_MAX3100 is not set
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
+CONFIG_UNIX98_PTYS=y
+# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
+# CONFIG_LEGACY_PTYS is not set
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+# CONFIG_R3964 is not set
+# CONFIG_RAW_DRIVER is not set
+# CONFIG_TCG_TPM is not set
+CONFIG_I2C=y
+CONFIG_I2C_BOARDINFO=y
+CONFIG_I2C_COMPAT=y
+CONFIG_I2C_CHARDEV=y
+CONFIG_I2C_HELPER_AUTO=y
+CONFIG_I2C_ALGOBIT=y
+
+#
+# I2C Hardware Bus support
+#
+
+#
+# I2C system bus drivers (mostly embedded / system-on-chip)
+#
+# CONFIG_I2C_DESIGNWARE is not set
+CONFIG_I2C_GPIO=y
+# CONFIG_I2C_OCORES is not set
+# CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
+
+#
+# External I2C/SMBus adapter drivers
+#
+# CONFIG_I2C_PARPORT_LIGHT is not set
+# CONFIG_I2C_TAOS_EVM is not set
+# CONFIG_I2C_TINY_USB is not set
+
+#
+# Other I2C/SMBus bus drivers
+#
+# CONFIG_I2C_PCA_PLATFORM is not set
+# CONFIG_I2C_STUB is not set
+
+#
+# Miscellaneous I2C Chip support
+#
+# CONFIG_SENSORS_TSL2550 is not set
+# CONFIG_I2C_DEBUG_CORE is not set
+# CONFIG_I2C_DEBUG_ALGO is not set
+# CONFIG_I2C_DEBUG_BUS is not set
+# CONFIG_I2C_DEBUG_CHIP is not set
+CONFIG_SPI=y
+CONFIG_SPI_MASTER=y
+
+#
+# SPI Master Controller Drivers
+#
+CONFIG_SPI_ATMEL=y
+# CONFIG_SPI_BITBANG is not set
+# CONFIG_SPI_GPIO is not set
+# CONFIG_SPI_XILINX is not set
+# CONFIG_SPI_DESIGNWARE is not set
+
+#
+# SPI Protocol Masters
+#
+CONFIG_SPI_SPIDEV=y
+# CONFIG_SPI_TLE62X0 is not set
+
+#
+# PPS support
+#
+# CONFIG_PPS is not set
+CONFIG_ARCH_REQUIRE_GPIOLIB=y
+CONFIG_GPIOLIB=y
+CONFIG_GPIO_SYSFS=y
+
+#
+# Memory mapped GPIO expanders:
+#
+# CONFIG_GPIO_IT8761E is not set
+
+#
+# I2C GPIO expanders:
+#
+# CONFIG_GPIO_MAX7300 is not set
+# CONFIG_GPIO_MAX732X is not set
+# CONFIG_GPIO_PCA953X is not set
+# CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
+
+#
+# PCI GPIO expanders:
+#
+
+#
+# SPI GPIO expanders:
+#
+# CONFIG_GPIO_MAX7301 is not set
+# CONFIG_GPIO_MCP23S08 is not set
+# CONFIG_GPIO_MC33880 is not set
+
+#
+# AC97 GPIO expanders:
+#
+CONFIG_W1=y
+
+#
+# 1-wire Bus Masters
+#
+# CONFIG_W1_MASTER_DS2490 is not set
+# CONFIG_W1_MASTER_DS2482 is not set
+# CONFIG_W1_MASTER_DS1WM is not set
+CONFIG_W1_MASTER_GPIO=y
+
+#
+# 1-wire Slaves
+#
+CONFIG_W1_SLAVE_THERM=y
+# CONFIG_W1_SLAVE_SMEM is not set
+CONFIG_W1_SLAVE_DS2431=y
+# CONFIG_W1_SLAVE_DS2433 is not set
+# CONFIG_W1_SLAVE_DS2760 is not set
+# CONFIG_W1_SLAVE_BQ27000 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_THERMAL is not set
+CONFIG_WATCHDOG=y
+# CONFIG_WATCHDOG_NOWAYOUT is not set
+
+#
+# Watchdog Device Drivers
+#
+# CONFIG_SOFT_WATCHDOG is not set
+# CONFIG_MAX63XX_WATCHDOG is not set
+CONFIG_AT91SAM9X_WATCHDOG=y
+
+#
+# USB-based Watchdog Cards
+#
+# CONFIG_USBPCWATCHDOG is not set
+CONFIG_SSB_POSSIBLE=y
+
+#
+# Sonics Silicon Backplane
+#
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
+# CONFIG_MFD_SM501 is not set
+# CONFIG_MFD_ASIC3 is not set
+# CONFIG_HTC_EGPIO is not set
+# CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
+# CONFIG_TPS65010 is not set
+# CONFIG_TWL4030_CORE is not set
+# CONFIG_MFD_TMIO is not set
+# CONFIG_MFD_T7L66XB is not set
+# CONFIG_MFD_TC6387XB is not set
+# CONFIG_MFD_TC6393XB is not set
+# CONFIG_PMIC_DA903X is not set
+# CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
+# CONFIG_MFD_WM8400 is not set
+# CONFIG_MFD_WM831X is not set
+# CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
+# CONFIG_MFD_PCF50633 is not set
+# CONFIG_MFD_MC13783 is not set
+# CONFIG_AB3100_CORE is not set
+# CONFIG_EZX_PCAP is not set
+# CONFIG_AB4500_CORE is not set
+# CONFIG_REGULATOR is not set
+# CONFIG_MEDIA_SUPPORT is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Console display driver support
+#
+# CONFIG_VGA_CONSOLE is not set
+CONFIG_DUMMY_CONSOLE=y
+# CONFIG_SOUND is not set
+# CONFIG_HID_SUPPORT is not set
+CONFIG_USB_SUPPORT=y
+CONFIG_USB_ARCH_HAS_HCD=y
+CONFIG_USB_ARCH_HAS_OHCI=y
+# CONFIG_USB_ARCH_HAS_EHCI is not set
+CONFIG_USB=y
+# CONFIG_USB_DEBUG is not set
+# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
+
+#
+# Miscellaneous USB options
+#
+CONFIG_USB_DEVICEFS=y
+# CONFIG_USB_DEVICE_CLASS is not set
+# CONFIG_USB_DYNAMIC_MINORS is not set
+# CONFIG_USB_OTG is not set
+CONFIG_USB_MON=y
+# CONFIG_USB_WUSB is not set
+# CONFIG_USB_WUSB_CBAF is not set
+
+#
+# USB Host Controller Drivers
+#
+# CONFIG_USB_C67X00_HCD is not set
+# CONFIG_USB_OXU210HP_HCD is not set
+# CONFIG_USB_ISP116X_HCD is not set
+# CONFIG_USB_ISP1760_HCD is not set
+# CONFIG_USB_ISP1362_HCD is not set
+CONFIG_USB_OHCI_HCD=y
+# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
+# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
+CONFIG_USB_OHCI_LITTLE_ENDIAN=y
+# CONFIG_USB_SL811_HCD is not set
+# CONFIG_USB_R8A66597_HCD is not set
+# CONFIG_USB_HWA_HCD is not set
+# CONFIG_USB_MUSB_HDRC is not set
+# CONFIG_USB_GADGET_MUSB_HDRC is not set
+
+#
+# USB Device Class drivers
+#
+# CONFIG_USB_ACM is not set
+# CONFIG_USB_PRINTER is not set
+# CONFIG_USB_WDM is not set
+# CONFIG_USB_TMC is not set
+
+#
+# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may
+#
+
+#
+# also be needed; see USB_STORAGE Help for more info
+#
+CONFIG_USB_STORAGE=y
+# CONFIG_USB_STORAGE_DEBUG is not set
+# CONFIG_USB_STORAGE_DATAFAB is not set
+# CONFIG_USB_STORAGE_FREECOM is not set
+# CONFIG_USB_STORAGE_ISD200 is not set
+# CONFIG_USB_STORAGE_USBAT is not set
+# CONFIG_USB_STORAGE_SDDR09 is not set
+# CONFIG_USB_STORAGE_SDDR55 is not set
+# CONFIG_USB_STORAGE_JUMPSHOT is not set
+# CONFIG_USB_STORAGE_ALAUDA is not set
+# CONFIG_USB_STORAGE_ONETOUCH is not set
+# CONFIG_USB_STORAGE_KARMA is not set
+# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
+# CONFIG_USB_LIBUSUAL is not set
+
+#
+# USB Imaging devices
+#
+# CONFIG_USB_MDC800 is not set
+# CONFIG_USB_MICROTEK is not set
+
+#
+# USB port drivers
+#
+# CONFIG_USB_SERIAL is not set
+
+#
+# USB Miscellaneous drivers
+#
+# CONFIG_USB_EMI62 is not set
+# CONFIG_USB_EMI26 is not set
+# CONFIG_USB_ADUTUX is not set
+# CONFIG_USB_SEVSEG is not set
+# CONFIG_USB_RIO500 is not set
+# CONFIG_USB_LEGOTOWER is not set
+# CONFIG_USB_LCD is not set
+# CONFIG_USB_LED is not set
+# CONFIG_USB_CYPRESS_CY7C63 is not set
+# CONFIG_USB_CYTHERM is not set
+# CONFIG_USB_IDMOUSE is not set
+# CONFIG_USB_FTDI_ELAN is not set
+# CONFIG_USB_APPLEDISPLAY is not set
+# CONFIG_USB_LD is not set
+# CONFIG_USB_TRANCEVIBRATOR is not set
+# CONFIG_USB_IOWARRIOR is not set
+# CONFIG_USB_TEST is not set
+# CONFIG_USB_ISIGHTFW is not set
+CONFIG_USB_GADGET=m
+# CONFIG_USB_GADGET_DEBUG_FILES is not set
+CONFIG_USB_GADGET_VBUS_DRAW=2
+CONFIG_USB_GADGET_SELECTED=y
+CONFIG_USB_GADGET_AT91=y
+CONFIG_USB_AT91=m
+# CONFIG_USB_GADGET_ATMEL_USBA is not set
+# CONFIG_USB_GADGET_FSL_USB2 is not set
+# CONFIG_USB_GADGET_LH7A40X is not set
+# CONFIG_USB_GADGET_OMAP is not set
+# CONFIG_USB_GADGET_PXA25X is not set
+# CONFIG_USB_GADGET_R8A66597 is not set
+# CONFIG_USB_GADGET_PXA27X is not set
+# CONFIG_USB_GADGET_S3C_HSOTG is not set
+# CONFIG_USB_GADGET_IMX is not set
+# CONFIG_USB_GADGET_S3C2410 is not set
+# CONFIG_USB_GADGET_M66592 is not set
+# CONFIG_USB_GADGET_AMD5536UDC is not set
+# CONFIG_USB_GADGET_FSL_QE is not set
+# CONFIG_USB_GADGET_CI13XXX is not set
+# CONFIG_USB_GADGET_NET2280 is not set
+# CONFIG_USB_GADGET_GOKU is not set
+# CONFIG_USB_GADGET_LANGWELL is not set
+# CONFIG_USB_GADGET_DUMMY_HCD is not set
+# CONFIG_USB_GADGET_DUALSPEED is not set
+CONFIG_USB_ZERO=m
+# CONFIG_USB_AUDIO is not set
+CONFIG_USB_ETH=m
+CONFIG_USB_ETH_RNDIS=y
+# CONFIG_USB_ETH_EEM is not set
+# CONFIG_USB_GADGETFS is not set
+CONFIG_USB_FILE_STORAGE=m
+# CONFIG_USB_FILE_STORAGE_TEST is not set
+# CONFIG_USB_MASS_STORAGE is not set
+CONFIG_USB_G_SERIAL=m
+# CONFIG_USB_MIDI_GADGET is not set
+# CONFIG_USB_G_PRINTER is not set
+# CONFIG_USB_CDC_COMPOSITE is not set
+# CONFIG_USB_G_NOKIA is not set
+# CONFIG_USB_G_MULTI is not set
+
+#
+# OTG and related infrastructure
+#
+# CONFIG_USB_GPIO_VBUS is not set
+# CONFIG_USB_ULPI is not set
+# CONFIG_NOP_USB_XCEIV is not set
+CONFIG_MMC=y
+# CONFIG_MMC_DEBUG is not set
+# CONFIG_MMC_UNSAFE_RESUME is not set
+
+#
+# MMC/SD/SDIO Card Drivers
+#
+CONFIG_MMC_BLOCK=y
+CONFIG_MMC_BLOCK_BOUNCE=y
+# CONFIG_SDIO_UART is not set
+# CONFIG_MMC_TEST is not set
+
+#
+# MMC/SD/SDIO Host Controller Drivers
+#
+# CONFIG_MMC_SDHCI is not set
+# CONFIG_MMC_AT91 is not set
+CONFIG_MMC_ATMELMCI=y
+# CONFIG_MMC_SPI is not set
+# CONFIG_MEMSTICK is not set
+CONFIG_NEW_LEDS=y
+CONFIG_LEDS_CLASS=y
+
+#
+# LED drivers
+#
+# CONFIG_LEDS_PCA9532 is not set
+CONFIG_LEDS_GPIO=y
+CONFIG_LEDS_GPIO_PLATFORM=y
+# CONFIG_LEDS_LP3944 is not set
+# CONFIG_LEDS_PCA955X is not set
+# CONFIG_LEDS_DAC124S085 is not set
+# CONFIG_LEDS_BD2802 is not set
+# CONFIG_LEDS_LT3593 is not set
+
+#
+# LED Triggers
+#
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_TIMER=y
+CONFIG_LEDS_TRIGGER_HEARTBEAT=y
+# CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
+# CONFIG_LEDS_TRIGGER_GPIO is not set
+CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
+
+#
+# iptables trigger is under Netfilter config (LED target)
+#
+# CONFIG_ACCESSIBILITY is not set
+CONFIG_RTC_LIB=y
+CONFIG_RTC_CLASS=y
+CONFIG_RTC_HCTOSYS=y
+CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
+# CONFIG_RTC_DEBUG is not set
+
+#
+# RTC interfaces
+#
+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_TEST is not set
+
+#
+# I2C RTC drivers
+#
+# CONFIG_RTC_DRV_DS1307 is not set
+# CONFIG_RTC_DRV_DS1374 is not set
+# CONFIG_RTC_DRV_DS1672 is not set
+# CONFIG_RTC_DRV_MAX6900 is not set
+# CONFIG_RTC_DRV_RS5C372 is not set
+# CONFIG_RTC_DRV_ISL1208 is not set
+# CONFIG_RTC_DRV_X1205 is not set
+# CONFIG_RTC_DRV_PCF8563 is not set
+# CONFIG_RTC_DRV_PCF8583 is not set
+# CONFIG_RTC_DRV_M41T80 is not set
+# CONFIG_RTC_DRV_BQ32K is not set
+# CONFIG_RTC_DRV_S35390A is not set
+# CONFIG_RTC_DRV_FM3130 is not set
+# CONFIG_RTC_DRV_RX8581 is not set
+# CONFIG_RTC_DRV_RX8025 is not set
+
+#
+# SPI RTC drivers
+#
+# CONFIG_RTC_DRV_M41T94 is not set
+# CONFIG_RTC_DRV_DS1305 is not set
+# CONFIG_RTC_DRV_DS1390 is not set
+# CONFIG_RTC_DRV_MAX6902 is not set
+# CONFIG_RTC_DRV_R9701 is not set
+# CONFIG_RTC_DRV_RS5C348 is not set
+# CONFIG_RTC_DRV_DS3234 is not set
+# CONFIG_RTC_DRV_PCF2123 is not set
+
+#
+# Platform RTC drivers
+#
+# CONFIG_RTC_DRV_CMOS is not set
+# CONFIG_RTC_DRV_DS1286 is not set
+# CONFIG_RTC_DRV_DS1511 is not set
+# CONFIG_RTC_DRV_DS1553 is not set
+# CONFIG_RTC_DRV_DS1742 is not set
+# CONFIG_RTC_DRV_STK17TA8 is not set
+# CONFIG_RTC_DRV_M48T86 is not set
+# CONFIG_RTC_DRV_M48T35 is not set
+# CONFIG_RTC_DRV_M48T59 is not set
+# CONFIG_RTC_DRV_MSM6242 is not set
+# CONFIG_RTC_DRV_BQ4802 is not set
+# CONFIG_RTC_DRV_RP5C01 is not set
+# CONFIG_RTC_DRV_V3020 is not set
+
+#
+# on-CPU RTC drivers
+#
+CONFIG_RTC_DRV_AT91SAM9=y
+CONFIG_RTC_DRV_AT91SAM9_RTT=0
+CONFIG_RTC_DRV_AT91SAM9_GPBR=0
+# CONFIG_DMADEVICES is not set
+# CONFIG_AUXDISPLAY is not set
+# CONFIG_UIO is not set
+
+#
+# TI VLYNQ
+#
+# CONFIG_STAGING is not set
+
+#
+# File systems
+#
+CONFIG_EXT2_FS=y
+# CONFIG_EXT2_FS_XATTR is not set
+# CONFIG_EXT2_FS_XIP is not set
+CONFIG_EXT3_FS=y
+# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
+CONFIG_EXT3_FS_XATTR=y
+# CONFIG_EXT3_FS_POSIX_ACL is not set
+# CONFIG_EXT3_FS_SECURITY is not set
+# CONFIG_EXT4_FS is not set
+CONFIG_JBD=y
+CONFIG_FS_MBCACHE=y
+# CONFIG_REISERFS_FS is not set
+# CONFIG_JFS_FS is not set
+# CONFIG_FS_POSIX_ACL is not set
+# CONFIG_XFS_FS is not set
+# CONFIG_OCFS2_FS is not set
+# CONFIG_BTRFS_FS is not set
+# CONFIG_NILFS2_FS is not set
+CONFIG_FILE_LOCKING=y
+CONFIG_FSNOTIFY=y
+CONFIG_DNOTIFY=y
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# Caches
+#
+# CONFIG_FSCACHE is not set
+
+#
+# CD-ROM/DVD Filesystems
+#
+# CONFIG_ISO9660_FS is not set
+# CONFIG_UDF_FS is not set
+
+#
+# DOS/FAT/NT Filesystems
+#
+CONFIG_FAT_FS=y
+# CONFIG_MSDOS_FS is not set
+CONFIG_VFAT_FS=y
+CONFIG_FAT_DEFAULT_CODEPAGE=437
+CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
+# CONFIG_NTFS_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_PROC_PAGE_MONITOR=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+CONFIG_MISC_FILESYSTEMS=y
+# CONFIG_ADFS_FS is not set
+# CONFIG_AFFS_FS is not set
+# CONFIG_HFS_FS is not set
+# CONFIG_HFSPLUS_FS is not set
+# CONFIG_BEFS_FS is not set
+# CONFIG_BFS_FS is not set
+# CONFIG_EFS_FS is not set
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+CONFIG_JFFS2_SUMMARY=y
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
+# CONFIG_CRAMFS is not set
+# CONFIG_SQUASHFS is not set
+# CONFIG_VXFS_FS is not set
+# CONFIG_MINIX_FS is not set
+# CONFIG_OMFS_FS is not set
+# CONFIG_HPFS_FS is not set
+# CONFIG_QNX4FS_FS is not set
+# CONFIG_ROMFS_FS is not set
+# CONFIG_SYSV_FS is not set
+# CONFIG_UFS_FS is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFSD is not set
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+
+#
+# Partition Types
+#
+# CONFIG_PARTITION_ADVANCED is not set
+CONFIG_MSDOS_PARTITION=y
+CONFIG_NLS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+# CONFIG_NLS_CODEPAGE_737 is not set
+# CONFIG_NLS_CODEPAGE_775 is not set
+CONFIG_NLS_CODEPAGE_850=y
+# CONFIG_NLS_CODEPAGE_852 is not set
+# CONFIG_NLS_CODEPAGE_855 is not set
+# CONFIG_NLS_CODEPAGE_857 is not set
+# CONFIG_NLS_CODEPAGE_860 is not set
+# CONFIG_NLS_CODEPAGE_861 is not set
+# CONFIG_NLS_CODEPAGE_862 is not set
+# CONFIG_NLS_CODEPAGE_863 is not set
+# CONFIG_NLS_CODEPAGE_864 is not set
+# CONFIG_NLS_CODEPAGE_865 is not set
+# CONFIG_NLS_CODEPAGE_866 is not set
+# CONFIG_NLS_CODEPAGE_869 is not set
+# CONFIG_NLS_CODEPAGE_936 is not set
+# CONFIG_NLS_CODEPAGE_950 is not set
+# CONFIG_NLS_CODEPAGE_932 is not set
+# CONFIG_NLS_CODEPAGE_949 is not set
+# CONFIG_NLS_CODEPAGE_874 is not set
+# CONFIG_NLS_ISO8859_8 is not set
+# CONFIG_NLS_CODEPAGE_1250 is not set
+# CONFIG_NLS_CODEPAGE_1251 is not set
+# CONFIG_NLS_ASCII is not set
+CONFIG_NLS_ISO8859_1=y
+# CONFIG_NLS_ISO8859_2 is not set
+# CONFIG_NLS_ISO8859_3 is not set
+# CONFIG_NLS_ISO8859_4 is not set
+# CONFIG_NLS_ISO8859_5 is not set
+# CONFIG_NLS_ISO8859_6 is not set
+# CONFIG_NLS_ISO8859_7 is not set
+# CONFIG_NLS_ISO8859_9 is not set
+# CONFIG_NLS_ISO8859_13 is not set
+# CONFIG_NLS_ISO8859_14 is not set
+CONFIG_NLS_ISO8859_15=y
+# CONFIG_NLS_KOI8_R is not set
+# CONFIG_NLS_KOI8_U is not set
+CONFIG_NLS_UTF8=y
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_FRAME_WARN=1024
+# CONFIG_MAGIC_SYSRQ is not set
+# CONFIG_STRIP_ASM_SYMS is not set
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+CONFIG_DEBUG_BUGVERBOSE=y
+CONFIG_DEBUG_MEMORY_INIT=y
+CONFIG_FRAME_POINTER=y
+# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LATENCYTOP is not set
+# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+CONFIG_HAVE_FUNCTION_TRACER=y
+CONFIG_TRACING_SUPPORT=y
+# CONFIG_FTRACE is not set
+# CONFIG_SAMPLES is not set
+CONFIG_HAVE_ARCH_KGDB=y
+# CONFIG_ARM_UNWIND is not set
+# CONFIG_DEBUG_USER is not set
+# CONFIG_OC_ETM is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITYFS is not set
+# CONFIG_DEFAULT_SECURITY_SELINUX is not set
+# CONFIG_DEFAULT_SECURITY_SMACK is not set
+# CONFIG_DEFAULT_SECURITY_TOMOYO is not set
+CONFIG_DEFAULT_SECURITY_DAC=y
+CONFIG_DEFAULT_SECURITY=""
+# CONFIG_CRYPTO is not set
+# CONFIG_BINARY_PRINTF is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+CONFIG_GENERIC_FIND_LAST_BIT=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_T10DIF is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_LZO_DECOMPRESS=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_DECOMPRESS_LZO=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
+CONFIG_NLATTR=y
+CONFIG_GENERIC_ATOMIC64=y
index e8ddec2..a0162fa 100644 (file)
@@ -24,7 +24,7 @@
  * strex/ldrex monitor on some implementations. The reason we can use it for
  * atomic_set() is the clrex or dummy strex done on every exception return.
  */
-#define atomic_read(v) ((v)->counter)
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
 #define atomic_set(v,i)        (((v)->counter) = (i))
 
 #if __LINUX_ARM_ARCH__ >= 6
index 04be3bd..c0f4e7b 100644 (file)
@@ -1,21 +1,30 @@
 #ifndef __ASM_ARM_HARDWARE_ARM_TIMER_H
 #define __ASM_ARM_HARDWARE_ARM_TIMER_H
 
-#define TIMER_LOAD     0x00
-#define TIMER_VALUE    0x04
-#define TIMER_CTRL     0x08
-#define TIMER_CTRL_ONESHOT     (1 << 0)
-#define TIMER_CTRL_32BIT       (1 << 1)
-#define TIMER_CTRL_DIV1                (0 << 2)
-#define TIMER_CTRL_DIV16       (1 << 2)
-#define TIMER_CTRL_DIV256      (2 << 2)
-#define TIMER_CTRL_IE          (1 << 5)        /* Interrupt Enable (versatile only) */
-#define TIMER_CTRL_PERIODIC    (1 << 6)
-#define TIMER_CTRL_ENABLE      (1 << 7)
+/*
+ * ARM timer implementation, found in Integrator, Versatile and Realview
+ * platforms.  Not all platforms support all registers and bits in these
+ * registers, so we mark them with A for Integrator AP, C for Integrator
+ * CP, V for Versatile and R for Realview.
+ *
+ * Integrator AP has 16-bit timers, Integrator CP, Versatile and Realview
+ * can have 16-bit or 32-bit selectable via a bit in the control register.
+ */
+#define TIMER_LOAD     0x00                    /* ACVR rw */
+#define TIMER_VALUE    0x04                    /* ACVR ro */
+#define TIMER_CTRL     0x08                    /* ACVR rw */
+#define TIMER_CTRL_ONESHOT     (1 << 0)        /*  CVR */
+#define TIMER_CTRL_32BIT       (1 << 1)        /*  CVR */
+#define TIMER_CTRL_DIV1                (0 << 2)        /* ACVR */
+#define TIMER_CTRL_DIV16       (1 << 2)        /* ACVR */
+#define TIMER_CTRL_DIV256      (2 << 2)        /* ACVR */
+#define TIMER_CTRL_IE          (1 << 5)        /*   VR */
+#define TIMER_CTRL_PERIODIC    (1 << 6)        /* ACVR */
+#define TIMER_CTRL_ENABLE      (1 << 7)        /* ACVR */
 
-#define TIMER_INTCLR   0x0c
-#define TIMER_RIS      0x10
-#define TIMER_MIS      0x14
-#define TIMER_BGLOAD   0x18
+#define TIMER_INTCLR   0x0c                    /* ACVR wo */
+#define TIMER_RIS      0x10                    /*  CVR ro */
+#define TIMER_MIS      0x14                    /*  CVR ro */
+#define TIMER_BGLOAD   0x18                    /*  CVR rw */
 
 #endif
index cdb9022..6bcba48 100644 (file)
@@ -21,6 +21,9 @@
 #define __ASM_ARM_HARDWARE_L2X0_H
 
 #define L2X0_CACHE_ID                  0x000
+#define   L2X0_CACHE_ID_PART_MASK      (0xf << 6)
+#define   L2X0_CACHE_ID_PART_L210      (1 << 6)
+#define   L2X0_CACHE_ID_PART_L310      (3 << 6)
 #define L2X0_CACHE_TYPE                        0x004
 #define L2X0_CTRL                      0x100
 #define L2X0_AUX_CTRL                  0x104
diff --git a/arch/arm/include/asm/hardware/icst.h b/arch/arm/include/asm/hardware/icst.h
new file mode 100644 (file)
index 0000000..10382a3
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ *  arch/arm/include/asm/hardware/icst.h
+ *
+ *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ *  Support functions for calculating clocks/divisors for the ICST
+ *  clock generators.  See http://www.icst.com/ for more information
+ *  on these devices.
+ */
+#ifndef ASMARM_HARDWARE_ICST_H
+#define ASMARM_HARDWARE_ICST_H
+
+struct icst_params {
+       unsigned long   ref;
+       unsigned long   vco_max;        /* inclusive */
+       unsigned long   vco_min;        /* exclusive */
+       unsigned short  vd_min;         /* inclusive */
+       unsigned short  vd_max;         /* inclusive */
+       unsigned char   rd_min;         /* inclusive */
+       unsigned char   rd_max;         /* inclusive */
+       const unsigned char *s2div;     /* chip specific s2div array */
+       const unsigned char *idx2s;     /* chip specific idx2s array */
+};
+
+struct icst_vco {
+       unsigned short  v;
+       unsigned char   r;
+       unsigned char   s;
+};
+
+unsigned long icst_hz(const struct icst_params *p, struct icst_vco vco);
+struct icst_vco icst_hz_to_vco(const struct icst_params *p, unsigned long freq);
+
+/*
+ * ICST307 VCO frequency must be between 6MHz and 200MHz (3.3 or 5V).
+ * This frequency is pre-output divider.
+ */
+#define ICST307_VCO_MIN        6000000
+#define ICST307_VCO_MAX        200000000
+
+extern const unsigned char icst307_s2div[];
+extern const unsigned char icst307_idx2s[];
+
+/*
+ * ICST525 VCO frequency must be between 10MHz and 200MHz (3V) or 320MHz (5V).
+ * This frequency is pre-output divider.
+ */
+#define ICST525_VCO_MIN                10000000
+#define ICST525_VCO_MAX_3V     200000000
+#define ICST525_VCO_MAX_5V     320000000
+
+extern const unsigned char icst525_s2div[];
+extern const unsigned char icst525_idx2s[];
+
+#endif
diff --git a/arch/arm/include/asm/hardware/icst307.h b/arch/arm/include/asm/hardware/icst307.h
deleted file mode 100644 (file)
index 554f128..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- *  arch/arm/include/asm/hardware/icst307.h
- *
- *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
- * published by the Free Software Foundation.
- *
- *  Support functions for calculating clocks/divisors for the ICS307
- *  clock generators.  See http://www.icst.com/ for more information
- *  on these devices.
- *
- *  This file is similar to the icst525.h file
- */
-#ifndef ASMARM_HARDWARE_ICST307_H
-#define ASMARM_HARDWARE_ICST307_H
-
-struct icst307_params {
-       unsigned long   ref;
-       unsigned long   vco_max;        /* inclusive */
-       unsigned short  vd_min;         /* inclusive */
-       unsigned short  vd_max;         /* inclusive */
-       unsigned char   rd_min;         /* inclusive */
-       unsigned char   rd_max;         /* inclusive */
-};
-
-struct icst307_vco {
-       unsigned short  v;
-       unsigned char   r;
-       unsigned char   s;
-};
-
-unsigned long icst307_khz(const struct icst307_params *p, struct icst307_vco vco);
-struct icst307_vco icst307_khz_to_vco(const struct icst307_params *p, unsigned long freq);
-struct icst307_vco icst307_ps_to_vco(const struct icst307_params *p, unsigned long period);
-
-#endif
diff --git a/arch/arm/include/asm/hardware/icst525.h b/arch/arm/include/asm/hardware/icst525.h
deleted file mode 100644 (file)
index 58f0dc4..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  arch/arm/include/asm/hardware/icst525.h
- *
- *  Copyright (C) 2003 Deep Blue Solutions, Ltd, 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 version 2 as
- * published by the Free Software Foundation.
- *
- *  Support functions for calculating clocks/divisors for the ICST525
- *  clock generators.  See http://www.icst.com/ for more information
- *  on these devices.
- */
-#ifndef ASMARM_HARDWARE_ICST525_H
-#define ASMARM_HARDWARE_ICST525_H
-
-struct icst525_params {
-       unsigned long   ref;
-       unsigned long   vco_max;        /* inclusive */
-       unsigned short  vd_min;         /* inclusive */
-       unsigned short  vd_max;         /* inclusive */
-       unsigned char   rd_min;         /* inclusive */
-       unsigned char   rd_max;         /* inclusive */
-};
-
-struct icst525_vco {
-       unsigned short  v;
-       unsigned char   r;
-       unsigned char   s;
-};
-
-unsigned long icst525_khz(const struct icst525_params *p, struct icst525_vco vco);
-struct icst525_vco icst525_khz_to_vco(const struct icst525_params *p, unsigned long freq);
-struct icst525_vco icst525_ps_to_vco(const struct icst525_params *p, unsigned long period);
-
-#endif
diff --git a/arch/arm/include/asm/hardware/pl330.h b/arch/arm/include/asm/hardware/pl330.h
new file mode 100644 (file)
index 0000000..575fa81
--- /dev/null
@@ -0,0 +1,217 @@
+/* linux/include/asm/hardware/pl330.h
+ *
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __PL330_CORE_H
+#define __PL330_CORE_H
+
+#define PL330_MAX_CHAN         8
+#define PL330_MAX_IRQS         32
+#define PL330_MAX_PERI         32
+
+enum pl330_srccachectrl {
+       SCCTRL0 = 0, /* Noncacheable and nonbufferable */
+       SCCTRL1, /* Bufferable only */
+       SCCTRL2, /* Cacheable, but do not allocate */
+       SCCTRL3, /* Cacheable and bufferable, but do not allocate */
+       SINVALID1,
+       SINVALID2,
+       SCCTRL6, /* Cacheable write-through, allocate on reads only */
+       SCCTRL7, /* Cacheable write-back, allocate on reads only */
+};
+
+enum pl330_dstcachectrl {
+       DCCTRL0 = 0, /* Noncacheable and nonbufferable */
+       DCCTRL1, /* Bufferable only */
+       DCCTRL2, /* Cacheable, but do not allocate */
+       DCCTRL3, /* Cacheable and bufferable, but do not allocate */
+       DINVALID1 = 8,
+       DINVALID2,
+       DCCTRL6, /* Cacheable write-through, allocate on writes only */
+       DCCTRL7, /* Cacheable write-back, allocate on writes only */
+};
+
+/* Populated by the PL330 core driver for DMA API driver's info */
+struct pl330_config {
+       u32     periph_id;
+       u32     pcell_id;
+#define DMAC_MODE_NS   (1 << 0)
+       unsigned int    mode;
+       unsigned int    data_bus_width:10; /* In number of bits */
+       unsigned int    data_buf_dep:10;
+       unsigned int    num_chan:4;
+       unsigned int    num_peri:6;
+       u32             peri_ns;
+       unsigned int    num_events:6;
+       u32             irq_ns;
+};
+
+/* Handle to the DMAC provided to the PL330 core */
+struct pl330_info {
+       /* Owning device */
+       struct device *dev;
+       /* Size of MicroCode buffers for each channel. */
+       unsigned mcbufsz;
+       /* ioremap'ed address of PL330 registers. */
+       void __iomem    *base;
+       /* Client can freely use it. */
+       void    *client_data;
+       /* PL330 core data, Client must not touch it. */
+       void    *pl330_data;
+       /* Populated by the PL330 core driver during pl330_add */
+       struct pl330_config     pcfg;
+       /*
+        * If the DMAC has some reset mechanism, then the
+        * client may want to provide pointer to the method.
+        */
+       void (*dmac_reset)(struct pl330_info *pi);
+};
+
+enum pl330_byteswap {
+       SWAP_NO = 0,
+       SWAP_2,
+       SWAP_4,
+       SWAP_8,
+       SWAP_16,
+};
+
+/**
+ * Request Configuration.
+ * The PL330 core does not modify this and uses the last
+ * working configuration if the request doesn't provide any.
+ *
+ * The Client may want to provide this info only for the
+ * first request and a request with new settings.
+ */
+struct pl330_reqcfg {
+       /* Address Incrementing */
+       unsigned dst_inc:1;
+       unsigned src_inc:1;
+
+       /*
+        * For now, the SRC & DST protection levels
+        * and burst size/length are assumed same.
+        */
+       bool nonsecure;
+       bool privileged;
+       bool insnaccess;
+       unsigned brst_len:5;
+       unsigned brst_size:3; /* in power of 2 */
+
+       enum pl330_dstcachectrl dcctl;
+       enum pl330_srccachectrl scctl;
+       enum pl330_byteswap swap;
+};
+
+/*
+ * One cycle of DMAC operation.
+ * There may be more than one xfer in a request.
+ */
+struct pl330_xfer {
+       u32 src_addr;
+       u32 dst_addr;
+       /* Size to xfer */
+       u32 bytes;
+       /*
+        * Pointer to next xfer in the list.
+        * The last xfer in the req must point to NULL.
+        */
+       struct pl330_xfer *next;
+};
+
+/* The xfer callbacks are made with one of these arguments. */
+enum pl330_op_err {
+       /* The all xfers in the request were success. */
+       PL330_ERR_NONE,
+       /* If req aborted due to global error. */
+       PL330_ERR_ABORT,
+       /* If req failed due to problem with Channel. */
+       PL330_ERR_FAIL,
+};
+
+enum pl330_reqtype {
+       MEMTOMEM,
+       MEMTODEV,
+       DEVTOMEM,
+       DEVTODEV,
+};
+
+/* A request defining Scatter-Gather List ending with NULL xfer. */
+struct pl330_req {
+       enum pl330_reqtype rqtype;
+       /* Index of peripheral for the xfer. */
+       unsigned peri:5;
+       /* Unique token for this xfer, set by the client. */
+       void *token;
+       /* Callback to be called after xfer. */
+       void (*xfer_cb)(void *token, enum pl330_op_err err);
+       /* If NULL, req will be done at last set parameters. */
+       struct pl330_reqcfg *cfg;
+       /* Pointer to first xfer in the request. */
+       struct pl330_xfer *x;
+};
+
+/*
+ * To know the status of the channel and DMAC, the client
+ * provides a pointer to this structure. The PL330 core
+ * fills it with current information.
+ */
+struct pl330_chanstatus {
+       /*
+        * If the DMAC engine halted due to some error,
+        * the client should remove-add DMAC.
+        */
+       bool dmac_halted;
+       /*
+        * If channel is halted due to some error,
+        * the client should ABORT/FLUSH and START the channel.
+        */
+       bool faulting;
+       /* Location of last load */
+       u32 src_addr;
+       /* Location of last store */
+       u32 dst_addr;
+       /*
+        * Pointer to the currently active req, NULL if channel is
+        * inactive, even though the requests may be present.
+        */
+       struct pl330_req *top_req;
+       /* Pointer to req waiting second in the queue if any. */
+       struct pl330_req *wait_req;
+};
+
+enum pl330_chan_op {
+       /* Start the channel */
+       PL330_OP_START,
+       /* Abort the active xfer */
+       PL330_OP_ABORT,
+       /* Stop xfer and flush queue */
+       PL330_OP_FLUSH,
+};
+
+extern int pl330_add(struct pl330_info *);
+extern void pl330_del(struct pl330_info *pi);
+extern int pl330_update(const struct pl330_info *pi);
+extern void pl330_release_channel(void *ch_id);
+extern void *pl330_request_channel(const struct pl330_info *pi);
+extern int pl330_chan_status(void *ch_id, struct pl330_chanstatus *pstatus);
+extern int pl330_chan_ctrl(void *ch_id, enum pl330_chan_op op);
+extern int pl330_submit_req(void *ch_id, struct pl330_req *r);
+
+#endif /* __PL330_CORE_H */
diff --git a/arch/arm/include/asm/hardware/sp810.h b/arch/arm/include/asm/hardware/sp810.h
new file mode 100644 (file)
index 0000000..a101f10
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * arch/arm/include/asm/hardware/sp810.h
+ *
+ * ARM PrimeXsys System Controller SP810 header file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __ASM_ARM_SP810_H
+#define __ASM_ARM_SP810_H
+
+#include <linux/io.h>
+
+/* sysctl registers offset */
+#define SCCTRL                 0x000
+#define SCSYSSTAT              0x004
+#define SCIMCTRL               0x008
+#define SCIMSTAT               0x00C
+#define SCXTALCTRL             0x010
+#define SCPLLCTRL              0x014
+#define SCPLLFCTRL             0x018
+#define SCPERCTRL0             0x01C
+#define SCPERCTRL1             0x020
+#define SCPEREN                        0x024
+#define SCPERDIS               0x028
+#define SCPERCLKEN             0x02C
+#define SCPERSTAT              0x030
+#define SCSYSID0               0xEE0
+#define SCSYSID1               0xEE4
+#define SCSYSID2               0xEE8
+#define SCSYSID3               0xEEC
+#define SCITCR                 0xF00
+#define SCITIR0                        0xF04
+#define SCITIR1                        0xF08
+#define SCITOR                 0xF0C
+#define SCCNTCTRL              0xF10
+#define SCCNTDATA              0xF14
+#define SCCNTSTEP              0xF18
+#define SCPERIPHID0            0xFE0
+#define SCPERIPHID1            0xFE4
+#define SCPERIPHID2            0xFE8
+#define SCPERIPHID3            0xFEC
+#define SCPCELLID0             0xFF0
+#define SCPCELLID1             0xFF4
+#define SCPCELLID2             0xFF8
+#define SCPCELLID3             0xFFC
+
+static inline void sysctl_soft_reset(void __iomem *base)
+{
+       /* writing any value to SCSYSSTAT reg will reset system */
+       writel(0, base + SCSYSSTAT);
+}
+
+#endif /* __ASM_ARM_SP810_H */
index a91d8a1..7f0b6d1 100644 (file)
@@ -53,6 +53,9 @@
 #define TIOCGPTN       _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 
+#define TIOCGRS485      0x542E
+#define TIOCSRS485      0x542F
+
 #define FIONCLEX       0x5450  /* these numbers need to be adjusted. */
 #define FIOCLEX                0x5451
 #define FIOASYNC       0x5452
index a38bdc7..52f0da1 100644 (file)
@@ -8,10 +8,16 @@
  * published by the Free Software Foundation.
  */
 
+#ifndef __ASM_MACH_PCI_H
+#define __ASM_MACH_PCI_H
+
 struct pci_sys_data;
 struct pci_bus;
 
 struct hw_pci {
+#ifdef CONFIG_PCI_DOMAINS
+       int             domain;
+#endif
        struct list_head buses;
        int             nr_controllers;
        int             (*setup)(int nr, struct pci_sys_data *);
@@ -26,6 +32,9 @@ struct hw_pci {
  * Per-controller structure
  */
 struct pci_sys_data {
+#ifdef CONFIG_PCI_DOMAINS
+       int             domain;
+#endif
        struct list_head node;
        int             busnr;          /* primary bus number                   */
        u64             mem_offset;     /* bus->cpu memory mapping offset       */
@@ -70,3 +79,5 @@ extern int pci_v3_setup(int nr, struct pci_sys_data *);
 extern struct pci_bus *pci_v3_scan_bus(int nr, struct pci_sys_data *);
 extern void pci_v3_preinit(void);
 extern void pci_v3_postinit(void);
+
+#endif /* __ASM_MACH_PCI_H */
index 8bffc3f..35d408f 100644 (file)
@@ -38,7 +38,7 @@ struct sys_timer {
        void                    (*init)(void);
        void                    (*suspend)(void);
        void                    (*resume)(void);
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
        unsigned long           (*offset)(void);
 #endif
 };
index 4798011..92e2a83 100644 (file)
@@ -4,8 +4,23 @@
 #ifdef __KERNEL__
 #include <asm-generic/pci-dma-compat.h>
 
+#include <asm/mach/pci.h> /* for pci_sys_data */
 #include <mach/hardware.h> /* for PCIBIOS_MIN_* */
 
+#ifdef CONFIG_PCI_DOMAINS
+static inline int pci_domain_nr(struct pci_bus *bus)
+{
+       struct pci_sys_data *root = bus->sysdata;
+
+       return root->domain;
+}
+
+static inline int pci_proc_domain(struct pci_bus *bus)
+{
+       return pci_domain_nr(bus);
+}
+#endif /* CONFIG_PCI_DOMAINS */
+
 #ifdef CONFIG_PCI_HOST_ITE8152
 /* ITE bridge requires setting latency timer to avoid early bus access
    termination by PIC bus mater devices
index 49e3049..48837e6 100644 (file)
@@ -28,4 +28,21 @@ set_perf_event_pending(void)
  * same indexes here for consistency. */
 #define PERF_EVENT_INDEX_OFFSET 1
 
+/* ARM perf PMU IDs for use by internal perf clients. */
+enum arm_perf_pmu_ids {
+       ARM_PERF_PMU_ID_XSCALE1 = 0,
+       ARM_PERF_PMU_ID_XSCALE2,
+       ARM_PERF_PMU_ID_V6,
+       ARM_PERF_PMU_ID_V6MP,
+       ARM_PERF_PMU_ID_CA8,
+       ARM_PERF_PMU_ID_CA9,
+       ARM_NUM_PMU_IDS,
+};
+
+extern enum arm_perf_pmu_ids
+armpmu_get_pmu_id(void);
+
+extern int
+armpmu_get_max_events(void);
+
 #endif /* __ARM_PERF_EVENT_H__ */
index 1139768..ab68cf1 100644 (file)
@@ -314,7 +314,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
        __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_UNCACHED)
 #define pgprot_writecombine(prot) \
        __pgprot_modify(prot, L_PTE_MT_MASK, L_PTE_MT_BUFFERABLE)
-#if __LINUX_ARM_ARCH__ >= 7
+#ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
 #define pgprot_dmacoherent(prot) \
        __pgprot_modify(prot, L_PTE_MT_MASK|L_PTE_EXEC, L_PTE_MT_BUFFERABLE)
 #else
index 2829b9f..8ccea01 100644 (file)
 #ifndef __ARM_PMU_H__
 #define __ARM_PMU_H__
 
-#ifdef CONFIG_CPU_HAS_PMU
-
-struct pmu_irqs {
-       const int   *irqs;
-       int         num_irqs;
+enum arm_pmu_type {
+       ARM_PMU_DEVICE_CPU      = 0,
+       ARM_NUM_PMU_DEVICES,
 };
 
+#ifdef CONFIG_CPU_HAS_PMU
+
 /**
  * reserve_pmu() - reserve the hardware performance counters
  *
  * Reserve the hardware performance counters in the system for exclusive use.
- * The 'struct pmu_irqs' for the system is returned on success, ERR_PTR()
+ * The platform_device for the system is returned on success, ERR_PTR()
  * encoded error on failure.
  */
-extern const struct pmu_irqs *
-reserve_pmu(void);
+extern struct platform_device *
+reserve_pmu(enum arm_pmu_type device);
 
 /**
  * release_pmu() - Relinquish control of the performance counters
  *
  * Release the performance counters and allow someone else to use them.
  * Callers must have disabled the counters and released IRQs before calling
- * this. The 'struct pmu_irqs' returned from reserve_pmu() must be passed as
+ * this. The platform_device returned from reserve_pmu() must be passed as
  * a cookie.
  */
 extern int
-release_pmu(const struct pmu_irqs *irqs);
+release_pmu(struct platform_device *pdev);
 
 /**
  * init_pmu() - Initialise the PMU.
@@ -48,24 +48,26 @@ release_pmu(const struct pmu_irqs *irqs);
  * the actual hardware initialisation.
  */
 extern int
-init_pmu(void);
+init_pmu(enum arm_pmu_type device);
 
 #else /* CONFIG_CPU_HAS_PMU */
 
-static inline const struct pmu_irqs *
-reserve_pmu(void)
+#include <linux/err.h>
+
+static inline struct platform_device *
+reserve_pmu(enum arm_pmu_type device)
 {
        return ERR_PTR(-ENODEV);
 }
 
 static inline int
-release_pmu(const struct pmu_irqs *irqs)
+release_pmu(struct platform_device *pdev)
 {
        return -ENODEV;
 }
 
 static inline int
-init_pmu(void)
+init_pmu(enum arm_pmu_type device)
 {
        return -ENODEV;
 }
index ca0a37d..bcda59f 100644 (file)
@@ -4,24 +4,8 @@
 #include <asm/memory.h>
 #include <asm/types.h>
 
-struct scatterlist {
-#ifdef CONFIG_DEBUG_SG
-       unsigned long   sg_magic;
-#endif
-       unsigned long   page_link;
-       unsigned int    offset;         /* buffer offset                 */
-       dma_addr_t      dma_address;    /* dma address                   */
-       unsigned int    length;         /* length                        */
-};
+#include <asm-generic/scatterlist.h>
 
-/*
- * These macros should be used after a pci_map_sg call has been done
- * to get bus addresses of each of the SG entries and their lengths.
- * You should only work with the number of sg entries pci_map_sg
- * returns, or alternatively stop on the first sg_dma_len(sg) which
- * is 0.
- */
-#define sg_dma_address(sg)      ((sg)->dma_address)
-#define sg_dma_len(sg)          ((sg)->length)
+#undef ARCH_HAS_SG_CHAIN
 
 #endif /* _ASMARM_SCATTERLIST_H */
index e0d763b..3d05190 100644 (file)
@@ -82,7 +82,7 @@ struct secondary_data {
 extern struct secondary_data secondary_data;
 
 extern int __cpu_disable(void);
-extern int mach_cpu_disable(unsigned int cpu);
+extern int platform_cpu_disable(unsigned int cpu);
 
 extern void __cpu_die(unsigned int cpu);
 extern void cpu_die(void);
index 4ace45e..5f4f480 100644 (file)
@@ -141,7 +141,7 @@ extern unsigned int user_debug;
 
 #ifdef CONFIG_ARCH_HAS_BARRIERS
 #include <mach/barriers.h>
-#elif __LINUX_ARM_ARCH__ >= 7 || defined(CONFIG_SMP)
+#elif defined(CONFIG_ARM_DMA_MEM_BUFFERABLE) || defined(CONFIG_SMP)
 #define mb()           do { dsb(); outer_sync(); } while (0)
 #define rmb()          dmb()
 #define wmb()          mb()
index b74970e..763e29f 100644 (file)
@@ -141,7 +141,7 @@ extern void vfp_flush_hwstate(struct thread_info *);
 #define TIF_SYSCALL_TRACE      8
 #define TIF_POLLING_NRFLAG     16
 #define TIF_USING_IWMMXT       17
-#define TIF_MEMDIE             18
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 #define TIF_FREEZE             19
 #define TIF_RESTORE_SIGMASK    20
 
index bd397e0..c6273a3 100644 (file)
@@ -527,6 +527,9 @@ static void __init pcibios_init_hw(struct hw_pci *hw)
                if (!sys)
                        panic("PCI: unable to allocate sys data!");
 
+#ifdef CONFIG_PCI_DOMAINS
+               sys->domain  = hw->domain;
+#endif
                sys->hw      = hw;
                sys->busnr   = busnr;
                sys->swizzle = hw->swizzle;
index 7d5b9fb..2c4a185 100644 (file)
@@ -16,6 +16,8 @@
 #include <linux/spinlock.h>
 #include <linux/errno.h>
 #include <linux/scatterlist.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
 
 #include <asm/dma.h>
 
@@ -264,3 +266,37 @@ int get_dma_residue(unsigned int chan)
        return ret;
 }
 EXPORT_SYMBOL(get_dma_residue);
+
+#ifdef CONFIG_PROC_FS
+static int proc_dma_show(struct seq_file *m, void *v)
+{
+       int i;
+
+       for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
+               dma_t *dma = dma_channel(i);
+               if (dma && dma->lock)
+                       seq_printf(m, "%2d: %s\n", i, dma->device_id);
+       }
+       return 0;
+}
+
+static int proc_dma_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, proc_dma_show, NULL);
+}
+
+static const struct file_operations proc_dma_operations = {
+       .open           = proc_dma_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int __init proc_dma_init(void)
+{
+       proc_create("dma", 0, NULL, &proc_dma_operations);
+       return 0;
+}
+
+__initcall(proc_dma_init);
+#endif
index 9e70f20..c457686 100644 (file)
@@ -16,7 +16,9 @@
 
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
+#include <linux/module.h>
 #include <linux/perf_event.h>
+#include <linux/platform_device.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
 
@@ -26,7 +28,7 @@
 #include <asm/pmu.h>
 #include <asm/stacktrace.h>
 
-static const struct pmu_irqs *pmu_irqs;
+static struct platform_device *pmu_device;
 
 /*
  * Hardware lock to serialize accesses to PMU registers. Needed for the
@@ -67,8 +69,18 @@ struct cpu_hw_events {
 };
 DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
 
+/* PMU names. */
+static const char *arm_pmu_names[] = {
+       [ARM_PERF_PMU_ID_XSCALE1] = "xscale1",
+       [ARM_PERF_PMU_ID_XSCALE2] = "xscale2",
+       [ARM_PERF_PMU_ID_V6]      = "v6",
+       [ARM_PERF_PMU_ID_V6MP]    = "v6mpcore",
+       [ARM_PERF_PMU_ID_CA8]     = "ARMv7 Cortex-A8",
+       [ARM_PERF_PMU_ID_CA9]     = "ARMv7 Cortex-A9",
+};
+
 struct arm_pmu {
-       char            *name;
+       enum arm_perf_pmu_ids id;
        irqreturn_t     (*handle_irq)(int irq_num, void *dev);
        void            (*enable)(struct hw_perf_event *evt, int idx);
        void            (*disable)(struct hw_perf_event *evt, int idx);
@@ -87,6 +99,30 @@ struct arm_pmu {
 /* Set at runtime when we know what CPU type we are. */
 static const struct arm_pmu *armpmu;
 
+enum arm_perf_pmu_ids
+armpmu_get_pmu_id(void)
+{
+       int id = -ENODEV;
+
+       if (armpmu != NULL)
+               id = armpmu->id;
+
+       return id;
+}
+EXPORT_SYMBOL_GPL(armpmu_get_pmu_id);
+
+int
+armpmu_get_max_events(void)
+{
+       int max_events = 0;
+
+       if (armpmu != NULL)
+               max_events = armpmu->num_events;
+
+       return max_events;
+}
+EXPORT_SYMBOL_GPL(armpmu_get_max_events);
+
 #define HW_OP_UNSUPPORTED              0xFFFF
 
 #define C(_x) \
@@ -314,38 +350,44 @@ validate_group(struct perf_event *event)
 static int
 armpmu_reserve_hardware(void)
 {
-       int i;
-       int err;
+       int i, err = -ENODEV, irq;
 
-       pmu_irqs = reserve_pmu();
-       if (IS_ERR(pmu_irqs)) {
+       pmu_device = reserve_pmu(ARM_PMU_DEVICE_CPU);
+       if (IS_ERR(pmu_device)) {
                pr_warning("unable to reserve pmu\n");
-               return PTR_ERR(pmu_irqs);
+               return PTR_ERR(pmu_device);
        }
 
-       init_pmu();
+       init_pmu(ARM_PMU_DEVICE_CPU);
 
-       if (pmu_irqs->num_irqs < 1) {
+       if (pmu_device->num_resources < 1) {
                pr_err("no irqs for PMUs defined\n");
                return -ENODEV;
        }
 
-       for (i = 0; i < pmu_irqs->num_irqs; ++i) {
-               err = request_irq(pmu_irqs->irqs[i], armpmu->handle_irq,
+       for (i = 0; i < pmu_device->num_resources; ++i) {
+               irq = platform_get_irq(pmu_device, i);
+               if (irq < 0)
+                       continue;
+
+               err = request_irq(irq, armpmu->handle_irq,
                                  IRQF_DISABLED | IRQF_NOBALANCING,
                                  "armpmu", NULL);
                if (err) {
-                       pr_warning("unable to request IRQ%d for ARM "
-                                  "perf counters\n", pmu_irqs->irqs[i]);
+                       pr_warning("unable to request IRQ%d for ARM perf "
+                               "counters\n", irq);
                        break;
                }
        }
 
        if (err) {
-               for (i = i - 1; i >= 0; --i)
-                       free_irq(pmu_irqs->irqs[i], NULL);
-               release_pmu(pmu_irqs);
-               pmu_irqs = NULL;
+               for (i = i - 1; i >= 0; --i) {
+                       irq = platform_get_irq(pmu_device, i);
+                       if (irq >= 0)
+                               free_irq(irq, NULL);
+               }
+               release_pmu(pmu_device);
+               pmu_device = NULL;
        }
 
        return err;
@@ -354,14 +396,17 @@ armpmu_reserve_hardware(void)
 static void
 armpmu_release_hardware(void)
 {
-       int i;
+       int i, irq;
 
-       for (i = pmu_irqs->num_irqs - 1; i >= 0; --i)
-               free_irq(pmu_irqs->irqs[i], NULL);
+       for (i = pmu_device->num_resources - 1; i >= 0; --i) {
+               irq = platform_get_irq(pmu_device, i);
+               if (irq >= 0)
+                       free_irq(irq, NULL);
+       }
        armpmu->stop();
 
-       release_pmu(pmu_irqs);
-       pmu_irqs = NULL;
+       release_pmu(pmu_device);
+       pmu_device = NULL;
 }
 
 static atomic_t active_events = ATOMIC_INIT(0);
@@ -1144,7 +1189,7 @@ armv6mpcore_pmu_disable_event(struct hw_perf_event *hwc,
 }
 
 static const struct arm_pmu armv6pmu = {
-       .name                   = "v6",
+       .id                     = ARM_PERF_PMU_ID_V6,
        .handle_irq             = armv6pmu_handle_irq,
        .enable                 = armv6pmu_enable_event,
        .disable                = armv6pmu_disable_event,
@@ -1167,7 +1212,7 @@ static const struct arm_pmu armv6pmu = {
  * reset the period and enable the interrupt reporting.
  */
 static const struct arm_pmu armv6mpcore_pmu = {
-       .name                   = "v6mpcore",
+       .id                     = ARM_PERF_PMU_ID_V6MP,
        .handle_irq             = armv6pmu_handle_irq,
        .enable                 = armv6pmu_enable_event,
        .disable                = armv6mpcore_pmu_disable_event,
@@ -1197,10 +1242,6 @@ static const struct arm_pmu armv6mpcore_pmu = {
  *  counter and all 4 performance counters together can be reset separately.
  */
 
-#define ARMV7_PMU_CORTEX_A8_NAME               "ARMv7 Cortex-A8"
-
-#define ARMV7_PMU_CORTEX_A9_NAME               "ARMv7 Cortex-A9"
-
 /* Common ARMv7 event types */
 enum armv7_perf_types {
        ARMV7_PERFCTR_PMNC_SW_INCR              = 0x00,
@@ -2079,6 +2120,803 @@ static u32 __init armv7_reset_read_pmnc(void)
        return nb_cnt + 1;
 }
 
+/*
+ * ARMv5 [xscale] Performance counter handling code.
+ *
+ * Based on xscale OProfile code.
+ *
+ * There are two variants of the xscale PMU that we support:
+ *     - xscale1pmu: 2 event counters and a cycle counter
+ *     - xscale2pmu: 4 event counters and a cycle counter
+ * The two variants share event definitions, but have different
+ * PMU structures.
+ */
+
+enum xscale_perf_types {
+       XSCALE_PERFCTR_ICACHE_MISS              = 0x00,
+       XSCALE_PERFCTR_ICACHE_NO_DELIVER        = 0x01,
+       XSCALE_PERFCTR_DATA_STALL               = 0x02,
+       XSCALE_PERFCTR_ITLB_MISS                = 0x03,
+       XSCALE_PERFCTR_DTLB_MISS                = 0x04,
+       XSCALE_PERFCTR_BRANCH                   = 0x05,
+       XSCALE_PERFCTR_BRANCH_MISS              = 0x06,
+       XSCALE_PERFCTR_INSTRUCTION              = 0x07,
+       XSCALE_PERFCTR_DCACHE_FULL_STALL        = 0x08,
+       XSCALE_PERFCTR_DCACHE_FULL_STALL_CONTIG = 0x09,
+       XSCALE_PERFCTR_DCACHE_ACCESS            = 0x0A,
+       XSCALE_PERFCTR_DCACHE_MISS              = 0x0B,
+       XSCALE_PERFCTR_DCACHE_WRITE_BACK        = 0x0C,
+       XSCALE_PERFCTR_PC_CHANGED               = 0x0D,
+       XSCALE_PERFCTR_BCU_REQUEST              = 0x10,
+       XSCALE_PERFCTR_BCU_FULL                 = 0x11,
+       XSCALE_PERFCTR_BCU_DRAIN                = 0x12,
+       XSCALE_PERFCTR_BCU_ECC_NO_ELOG          = 0x14,
+       XSCALE_PERFCTR_BCU_1_BIT_ERR            = 0x15,
+       XSCALE_PERFCTR_RMW                      = 0x16,
+       /* XSCALE_PERFCTR_CCNT is not hardware defined */
+       XSCALE_PERFCTR_CCNT                     = 0xFE,
+       XSCALE_PERFCTR_UNUSED                   = 0xFF,
+};
+
+enum xscale_counters {
+       XSCALE_CYCLE_COUNTER    = 1,
+       XSCALE_COUNTER0,
+       XSCALE_COUNTER1,
+       XSCALE_COUNTER2,
+       XSCALE_COUNTER3,
+};
+
+static const unsigned xscale_perf_map[PERF_COUNT_HW_MAX] = {
+       [PERF_COUNT_HW_CPU_CYCLES]          = XSCALE_PERFCTR_CCNT,
+       [PERF_COUNT_HW_INSTRUCTIONS]        = XSCALE_PERFCTR_INSTRUCTION,
+       [PERF_COUNT_HW_CACHE_REFERENCES]    = HW_OP_UNSUPPORTED,
+       [PERF_COUNT_HW_CACHE_MISSES]        = HW_OP_UNSUPPORTED,
+       [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] = XSCALE_PERFCTR_BRANCH,
+       [PERF_COUNT_HW_BRANCH_MISSES]       = XSCALE_PERFCTR_BRANCH_MISS,
+       [PERF_COUNT_HW_BUS_CYCLES]          = HW_OP_UNSUPPORTED,
+};
+
+static const unsigned xscale_perf_cache_map[PERF_COUNT_HW_CACHE_MAX]
+                                          [PERF_COUNT_HW_CACHE_OP_MAX]
+                                          [PERF_COUNT_HW_CACHE_RESULT_MAX] = {
+       [C(L1D)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = XSCALE_PERFCTR_DCACHE_ACCESS,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_DCACHE_MISS,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = XSCALE_PERFCTR_DCACHE_ACCESS,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_DCACHE_MISS,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(L1I)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_ICACHE_MISS,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_ICACHE_MISS,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(LL)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(DTLB)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_DTLB_MISS,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_DTLB_MISS,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(ITLB)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_ITLB_MISS,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = XSCALE_PERFCTR_ITLB_MISS,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+       [C(BPU)] = {
+               [C(OP_READ)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_WRITE)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+               [C(OP_PREFETCH)] = {
+                       [C(RESULT_ACCESS)]      = CACHE_OP_UNSUPPORTED,
+                       [C(RESULT_MISS)]        = CACHE_OP_UNSUPPORTED,
+               },
+       },
+};
+
+#define        XSCALE_PMU_ENABLE       0x001
+#define XSCALE_PMN_RESET       0x002
+#define        XSCALE_CCNT_RESET       0x004
+#define        XSCALE_PMU_RESET        (CCNT_RESET | PMN_RESET)
+#define XSCALE_PMU_CNT64       0x008
+
+static inline int
+xscalepmu_event_map(int config)
+{
+       int mapping = xscale_perf_map[config];
+       if (HW_OP_UNSUPPORTED == mapping)
+               mapping = -EOPNOTSUPP;
+       return mapping;
+}
+
+static u64
+xscalepmu_raw_event(u64 config)
+{
+       return config & 0xff;
+}
+
+#define XSCALE1_OVERFLOWED_MASK        0x700
+#define XSCALE1_CCOUNT_OVERFLOW        0x400
+#define XSCALE1_COUNT0_OVERFLOW        0x100
+#define XSCALE1_COUNT1_OVERFLOW        0x200
+#define XSCALE1_CCOUNT_INT_EN  0x040
+#define XSCALE1_COUNT0_INT_EN  0x010
+#define XSCALE1_COUNT1_INT_EN  0x020
+#define XSCALE1_COUNT0_EVT_SHFT        12
+#define XSCALE1_COUNT0_EVT_MASK        (0xff << XSCALE1_COUNT0_EVT_SHFT)
+#define XSCALE1_COUNT1_EVT_SHFT        20
+#define XSCALE1_COUNT1_EVT_MASK        (0xff << XSCALE1_COUNT1_EVT_SHFT)
+
+static inline u32
+xscale1pmu_read_pmnc(void)
+{
+       u32 val;
+       asm volatile("mrc p14, 0, %0, c0, c0, 0" : "=r" (val));
+       return val;
+}
+
+static inline void
+xscale1pmu_write_pmnc(u32 val)
+{
+       /* upper 4bits and 7, 11 are write-as-0 */
+       val &= 0xffff77f;
+       asm volatile("mcr p14, 0, %0, c0, c0, 0" : : "r" (val));
+}
+
+static inline int
+xscale1_pmnc_counter_has_overflowed(unsigned long pmnc,
+                                       enum xscale_counters counter)
+{
+       int ret = 0;
+
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               ret = pmnc & XSCALE1_CCOUNT_OVERFLOW;
+               break;
+       case XSCALE_COUNTER0:
+               ret = pmnc & XSCALE1_COUNT0_OVERFLOW;
+               break;
+       case XSCALE_COUNTER1:
+               ret = pmnc & XSCALE1_COUNT1_OVERFLOW;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", counter);
+       }
+
+       return ret;
+}
+
+static irqreturn_t
+xscale1pmu_handle_irq(int irq_num, void *dev)
+{
+       unsigned long pmnc;
+       struct perf_sample_data data;
+       struct cpu_hw_events *cpuc;
+       struct pt_regs *regs;
+       int idx;
+
+       /*
+        * NOTE: there's an A stepping erratum that states if an overflow
+        *       bit already exists and another occurs, the previous
+        *       Overflow bit gets cleared. There's no workaround.
+        *       Fixed in B stepping or later.
+        */
+       pmnc = xscale1pmu_read_pmnc();
+
+       /*
+        * Write the value back to clear the overflow flags. Overflow
+        * flags remain in pmnc for use below. We also disable the PMU
+        * while we process the interrupt.
+        */
+       xscale1pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE);
+
+       if (!(pmnc & XSCALE1_OVERFLOWED_MASK))
+               return IRQ_NONE;
+
+       regs = get_irq_regs();
+
+       perf_sample_data_init(&data, 0);
+
+       cpuc = &__get_cpu_var(cpu_hw_events);
+       for (idx = 0; idx <= armpmu->num_events; ++idx) {
+               struct perf_event *event = cpuc->events[idx];
+               struct hw_perf_event *hwc;
+
+               if (!test_bit(idx, cpuc->active_mask))
+                       continue;
+
+               if (!xscale1_pmnc_counter_has_overflowed(pmnc, idx))
+                       continue;
+
+               hwc = &event->hw;
+               armpmu_event_update(event, hwc, idx);
+               data.period = event->hw.last_period;
+               if (!armpmu_event_set_period(event, hwc, idx))
+                       continue;
+
+               if (perf_event_overflow(event, 0, &data, regs))
+                       armpmu->disable(hwc, idx);
+       }
+
+       perf_event_do_pending();
+
+       /*
+        * Re-enable the PMU.
+        */
+       pmnc = xscale1pmu_read_pmnc() | XSCALE_PMU_ENABLE;
+       xscale1pmu_write_pmnc(pmnc);
+
+       return IRQ_HANDLED;
+}
+
+static void
+xscale1pmu_enable_event(struct hw_perf_event *hwc, int idx)
+{
+       unsigned long val, mask, evt, flags;
+
+       switch (idx) {
+       case XSCALE_CYCLE_COUNTER:
+               mask = 0;
+               evt = XSCALE1_CCOUNT_INT_EN;
+               break;
+       case XSCALE_COUNTER0:
+               mask = XSCALE1_COUNT0_EVT_MASK;
+               evt = (hwc->config_base << XSCALE1_COUNT0_EVT_SHFT) |
+                       XSCALE1_COUNT0_INT_EN;
+               break;
+       case XSCALE_COUNTER1:
+               mask = XSCALE1_COUNT1_EVT_MASK;
+               evt = (hwc->config_base << XSCALE1_COUNT1_EVT_SHFT) |
+                       XSCALE1_COUNT1_INT_EN;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", idx);
+               return;
+       }
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale1pmu_read_pmnc();
+       val &= ~mask;
+       val |= evt;
+       xscale1pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static void
+xscale1pmu_disable_event(struct hw_perf_event *hwc, int idx)
+{
+       unsigned long val, mask, evt, flags;
+
+       switch (idx) {
+       case XSCALE_CYCLE_COUNTER:
+               mask = XSCALE1_CCOUNT_INT_EN;
+               evt = 0;
+               break;
+       case XSCALE_COUNTER0:
+               mask = XSCALE1_COUNT0_INT_EN | XSCALE1_COUNT0_EVT_MASK;
+               evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT0_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER1:
+               mask = XSCALE1_COUNT1_INT_EN | XSCALE1_COUNT1_EVT_MASK;
+               evt = XSCALE_PERFCTR_UNUSED << XSCALE1_COUNT1_EVT_SHFT;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", idx);
+               return;
+       }
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale1pmu_read_pmnc();
+       val &= ~mask;
+       val |= evt;
+       xscale1pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static int
+xscale1pmu_get_event_idx(struct cpu_hw_events *cpuc,
+                       struct hw_perf_event *event)
+{
+       if (XSCALE_PERFCTR_CCNT == event->config_base) {
+               if (test_and_set_bit(XSCALE_CYCLE_COUNTER, cpuc->used_mask))
+                       return -EAGAIN;
+
+               return XSCALE_CYCLE_COUNTER;
+       } else {
+               if (!test_and_set_bit(XSCALE_COUNTER1, cpuc->used_mask)) {
+                       return XSCALE_COUNTER1;
+               }
+
+               if (!test_and_set_bit(XSCALE_COUNTER0, cpuc->used_mask)) {
+                       return XSCALE_COUNTER0;
+               }
+
+               return -EAGAIN;
+       }
+}
+
+static void
+xscale1pmu_start(void)
+{
+       unsigned long flags, val;
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale1pmu_read_pmnc();
+       val |= XSCALE_PMU_ENABLE;
+       xscale1pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static void
+xscale1pmu_stop(void)
+{
+       unsigned long flags, val;
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale1pmu_read_pmnc();
+       val &= ~XSCALE_PMU_ENABLE;
+       xscale1pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static inline u32
+xscale1pmu_read_counter(int counter)
+{
+       u32 val = 0;
+
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               asm volatile("mrc p14, 0, %0, c1, c0, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER0:
+               asm volatile("mrc p14, 0, %0, c2, c0, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER1:
+               asm volatile("mrc p14, 0, %0, c3, c0, 0" : "=r" (val));
+               break;
+       }
+
+       return val;
+}
+
+static inline void
+xscale1pmu_write_counter(int counter, u32 val)
+{
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               asm volatile("mcr p14, 0, %0, c1, c0, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER0:
+               asm volatile("mcr p14, 0, %0, c2, c0, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER1:
+               asm volatile("mcr p14, 0, %0, c3, c0, 0" : : "r" (val));
+               break;
+       }
+}
+
+static const struct arm_pmu xscale1pmu = {
+       .id             = ARM_PERF_PMU_ID_XSCALE1,
+       .handle_irq     = xscale1pmu_handle_irq,
+       .enable         = xscale1pmu_enable_event,
+       .disable        = xscale1pmu_disable_event,
+       .event_map      = xscalepmu_event_map,
+       .raw_event      = xscalepmu_raw_event,
+       .read_counter   = xscale1pmu_read_counter,
+       .write_counter  = xscale1pmu_write_counter,
+       .get_event_idx  = xscale1pmu_get_event_idx,
+       .start          = xscale1pmu_start,
+       .stop           = xscale1pmu_stop,
+       .num_events     = 3,
+       .max_period     = (1LLU << 32) - 1,
+};
+
+#define XSCALE2_OVERFLOWED_MASK        0x01f
+#define XSCALE2_CCOUNT_OVERFLOW        0x001
+#define XSCALE2_COUNT0_OVERFLOW        0x002
+#define XSCALE2_COUNT1_OVERFLOW        0x004
+#define XSCALE2_COUNT2_OVERFLOW        0x008
+#define XSCALE2_COUNT3_OVERFLOW        0x010
+#define XSCALE2_CCOUNT_INT_EN  0x001
+#define XSCALE2_COUNT0_INT_EN  0x002
+#define XSCALE2_COUNT1_INT_EN  0x004
+#define XSCALE2_COUNT2_INT_EN  0x008
+#define XSCALE2_COUNT3_INT_EN  0x010
+#define XSCALE2_COUNT0_EVT_SHFT        0
+#define XSCALE2_COUNT0_EVT_MASK        (0xff << XSCALE2_COUNT0_EVT_SHFT)
+#define XSCALE2_COUNT1_EVT_SHFT        8
+#define XSCALE2_COUNT1_EVT_MASK        (0xff << XSCALE2_COUNT1_EVT_SHFT)
+#define XSCALE2_COUNT2_EVT_SHFT        16
+#define XSCALE2_COUNT2_EVT_MASK        (0xff << XSCALE2_COUNT2_EVT_SHFT)
+#define XSCALE2_COUNT3_EVT_SHFT        24
+#define XSCALE2_COUNT3_EVT_MASK        (0xff << XSCALE2_COUNT3_EVT_SHFT)
+
+static inline u32
+xscale2pmu_read_pmnc(void)
+{
+       u32 val;
+       asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (val));
+       /* bits 1-2 and 4-23 are read-unpredictable */
+       return val & 0xff000009;
+}
+
+static inline void
+xscale2pmu_write_pmnc(u32 val)
+{
+       /* bits 4-23 are write-as-0, 24-31 are write ignored */
+       val &= 0xf;
+       asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (val));
+}
+
+static inline u32
+xscale2pmu_read_overflow_flags(void)
+{
+       u32 val;
+       asm volatile("mrc p14, 0, %0, c5, c1, 0" : "=r" (val));
+       return val;
+}
+
+static inline void
+xscale2pmu_write_overflow_flags(u32 val)
+{
+       asm volatile("mcr p14, 0, %0, c5, c1, 0" : : "r" (val));
+}
+
+static inline u32
+xscale2pmu_read_event_select(void)
+{
+       u32 val;
+       asm volatile("mrc p14, 0, %0, c8, c1, 0" : "=r" (val));
+       return val;
+}
+
+static inline void
+xscale2pmu_write_event_select(u32 val)
+{
+       asm volatile("mcr p14, 0, %0, c8, c1, 0" : : "r"(val));
+}
+
+static inline u32
+xscale2pmu_read_int_enable(void)
+{
+       u32 val;
+       asm volatile("mrc p14, 0, %0, c4, c1, 0" : "=r" (val));
+       return val;
+}
+
+static void
+xscale2pmu_write_int_enable(u32 val)
+{
+       asm volatile("mcr p14, 0, %0, c4, c1, 0" : : "r" (val));
+}
+
+static inline int
+xscale2_pmnc_counter_has_overflowed(unsigned long of_flags,
+                                       enum xscale_counters counter)
+{
+       int ret = 0;
+
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               ret = of_flags & XSCALE2_CCOUNT_OVERFLOW;
+               break;
+       case XSCALE_COUNTER0:
+               ret = of_flags & XSCALE2_COUNT0_OVERFLOW;
+               break;
+       case XSCALE_COUNTER1:
+               ret = of_flags & XSCALE2_COUNT1_OVERFLOW;
+               break;
+       case XSCALE_COUNTER2:
+               ret = of_flags & XSCALE2_COUNT2_OVERFLOW;
+               break;
+       case XSCALE_COUNTER3:
+               ret = of_flags & XSCALE2_COUNT3_OVERFLOW;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", counter);
+       }
+
+       return ret;
+}
+
+static irqreturn_t
+xscale2pmu_handle_irq(int irq_num, void *dev)
+{
+       unsigned long pmnc, of_flags;
+       struct perf_sample_data data;
+       struct cpu_hw_events *cpuc;
+       struct pt_regs *regs;
+       int idx;
+
+       /* Disable the PMU. */
+       pmnc = xscale2pmu_read_pmnc();
+       xscale2pmu_write_pmnc(pmnc & ~XSCALE_PMU_ENABLE);
+
+       /* Check the overflow flag register. */
+       of_flags = xscale2pmu_read_overflow_flags();
+       if (!(of_flags & XSCALE2_OVERFLOWED_MASK))
+               return IRQ_NONE;
+
+       /* Clear the overflow bits. */
+       xscale2pmu_write_overflow_flags(of_flags);
+
+       regs = get_irq_regs();
+
+       perf_sample_data_init(&data, 0);
+
+       cpuc = &__get_cpu_var(cpu_hw_events);
+       for (idx = 0; idx <= armpmu->num_events; ++idx) {
+               struct perf_event *event = cpuc->events[idx];
+               struct hw_perf_event *hwc;
+
+               if (!test_bit(idx, cpuc->active_mask))
+                       continue;
+
+               if (!xscale2_pmnc_counter_has_overflowed(pmnc, idx))
+                       continue;
+
+               hwc = &event->hw;
+               armpmu_event_update(event, hwc, idx);
+               data.period = event->hw.last_period;
+               if (!armpmu_event_set_period(event, hwc, idx))
+                       continue;
+
+               if (perf_event_overflow(event, 0, &data, regs))
+                       armpmu->disable(hwc, idx);
+       }
+
+       perf_event_do_pending();
+
+       /*
+        * Re-enable the PMU.
+        */
+       pmnc = xscale2pmu_read_pmnc() | XSCALE_PMU_ENABLE;
+       xscale2pmu_write_pmnc(pmnc);
+
+       return IRQ_HANDLED;
+}
+
+static void
+xscale2pmu_enable_event(struct hw_perf_event *hwc, int idx)
+{
+       unsigned long flags, ien, evtsel;
+
+       ien = xscale2pmu_read_int_enable();
+       evtsel = xscale2pmu_read_event_select();
+
+       switch (idx) {
+       case XSCALE_CYCLE_COUNTER:
+               ien |= XSCALE2_CCOUNT_INT_EN;
+               break;
+       case XSCALE_COUNTER0:
+               ien |= XSCALE2_COUNT0_INT_EN;
+               evtsel &= ~XSCALE2_COUNT0_EVT_MASK;
+               evtsel |= hwc->config_base << XSCALE2_COUNT0_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER1:
+               ien |= XSCALE2_COUNT1_INT_EN;
+               evtsel &= ~XSCALE2_COUNT1_EVT_MASK;
+               evtsel |= hwc->config_base << XSCALE2_COUNT1_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER2:
+               ien |= XSCALE2_COUNT2_INT_EN;
+               evtsel &= ~XSCALE2_COUNT2_EVT_MASK;
+               evtsel |= hwc->config_base << XSCALE2_COUNT2_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER3:
+               ien |= XSCALE2_COUNT3_INT_EN;
+               evtsel &= ~XSCALE2_COUNT3_EVT_MASK;
+               evtsel |= hwc->config_base << XSCALE2_COUNT3_EVT_SHFT;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", idx);
+               return;
+       }
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       xscale2pmu_write_event_select(evtsel);
+       xscale2pmu_write_int_enable(ien);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static void
+xscale2pmu_disable_event(struct hw_perf_event *hwc, int idx)
+{
+       unsigned long flags, ien, evtsel;
+
+       ien = xscale2pmu_read_int_enable();
+       evtsel = xscale2pmu_read_event_select();
+
+       switch (idx) {
+       case XSCALE_CYCLE_COUNTER:
+               ien &= ~XSCALE2_CCOUNT_INT_EN;
+               break;
+       case XSCALE_COUNTER0:
+               ien &= ~XSCALE2_COUNT0_INT_EN;
+               evtsel &= ~XSCALE2_COUNT0_EVT_MASK;
+               evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT0_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER1:
+               ien &= ~XSCALE2_COUNT1_INT_EN;
+               evtsel &= ~XSCALE2_COUNT1_EVT_MASK;
+               evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT1_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER2:
+               ien &= ~XSCALE2_COUNT2_INT_EN;
+               evtsel &= ~XSCALE2_COUNT2_EVT_MASK;
+               evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT2_EVT_SHFT;
+               break;
+       case XSCALE_COUNTER3:
+               ien &= ~XSCALE2_COUNT3_INT_EN;
+               evtsel &= ~XSCALE2_COUNT3_EVT_MASK;
+               evtsel |= XSCALE_PERFCTR_UNUSED << XSCALE2_COUNT3_EVT_SHFT;
+               break;
+       default:
+               WARN_ONCE(1, "invalid counter number (%d)\n", idx);
+               return;
+       }
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       xscale2pmu_write_event_select(evtsel);
+       xscale2pmu_write_int_enable(ien);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static int
+xscale2pmu_get_event_idx(struct cpu_hw_events *cpuc,
+                       struct hw_perf_event *event)
+{
+       int idx = xscale1pmu_get_event_idx(cpuc, event);
+       if (idx >= 0)
+               goto out;
+
+       if (!test_and_set_bit(XSCALE_COUNTER3, cpuc->used_mask))
+               idx = XSCALE_COUNTER3;
+       else if (!test_and_set_bit(XSCALE_COUNTER2, cpuc->used_mask))
+               idx = XSCALE_COUNTER2;
+out:
+       return idx;
+}
+
+static void
+xscale2pmu_start(void)
+{
+       unsigned long flags, val;
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale2pmu_read_pmnc() & ~XSCALE_PMU_CNT64;
+       val |= XSCALE_PMU_ENABLE;
+       xscale2pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static void
+xscale2pmu_stop(void)
+{
+       unsigned long flags, val;
+
+       spin_lock_irqsave(&pmu_lock, flags);
+       val = xscale2pmu_read_pmnc();
+       val &= ~XSCALE_PMU_ENABLE;
+       xscale2pmu_write_pmnc(val);
+       spin_unlock_irqrestore(&pmu_lock, flags);
+}
+
+static inline u32
+xscale2pmu_read_counter(int counter)
+{
+       u32 val = 0;
+
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER0:
+               asm volatile("mrc p14, 0, %0, c0, c2, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER1:
+               asm volatile("mrc p14, 0, %0, c1, c2, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER2:
+               asm volatile("mrc p14, 0, %0, c2, c2, 0" : "=r" (val));
+               break;
+       case XSCALE_COUNTER3:
+               asm volatile("mrc p14, 0, %0, c3, c2, 0" : "=r" (val));
+               break;
+       }
+
+       return val;
+}
+
+static inline void
+xscale2pmu_write_counter(int counter, u32 val)
+{
+       switch (counter) {
+       case XSCALE_CYCLE_COUNTER:
+               asm volatile("mcr p14, 0, %0, c1, c1, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER0:
+               asm volatile("mcr p14, 0, %0, c0, c2, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER1:
+               asm volatile("mcr p14, 0, %0, c1, c2, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER2:
+               asm volatile("mcr p14, 0, %0, c2, c2, 0" : : "r" (val));
+               break;
+       case XSCALE_COUNTER3:
+               asm volatile("mcr p14, 0, %0, c3, c2, 0" : : "r" (val));
+               break;
+       }
+}
+
+static const struct arm_pmu xscale2pmu = {
+       .id             = ARM_PERF_PMU_ID_XSCALE2,
+       .handle_irq     = xscale2pmu_handle_irq,
+       .enable         = xscale2pmu_enable_event,
+       .disable        = xscale2pmu_disable_event,
+       .event_map      = xscalepmu_event_map,
+       .raw_event      = xscalepmu_raw_event,
+       .read_counter   = xscale2pmu_read_counter,
+       .write_counter  = xscale2pmu_write_counter,
+       .get_event_idx  = xscale2pmu_get_event_idx,
+       .start          = xscale2pmu_start,
+       .stop           = xscale2pmu_stop,
+       .num_events     = 5,
+       .max_period     = (1LLU << 32) - 1,
+};
+
 static int __init
 init_hw_perf_events(void)
 {
@@ -2086,7 +2924,7 @@ init_hw_perf_events(void)
        unsigned long implementor = (cpuid & 0xFF000000) >> 24;
        unsigned long part_number = (cpuid & 0xFFF0);
 
-       /* We only support ARM CPUs implemented by ARM at the moment. */
+       /* ARM Ltd CPUs. */
        if (0x41 == implementor) {
                switch (part_number) {
                case 0xB360:    /* ARM1136 */
@@ -2105,7 +2943,7 @@ init_hw_perf_events(void)
                        perf_max_events = armv6mpcore_pmu.num_events;
                        break;
                case 0xC080:    /* Cortex-A8 */
-                       armv7pmu.name = ARMV7_PMU_CORTEX_A8_NAME;
+                       armv7pmu.id = ARM_PERF_PMU_ID_CA8;
                        memcpy(armpmu_perf_cache_map, armv7_a8_perf_cache_map,
                                sizeof(armv7_a8_perf_cache_map));
                        armv7pmu.event_map = armv7_a8_pmu_event_map;
@@ -2117,7 +2955,7 @@ init_hw_perf_events(void)
                        perf_max_events = armv7pmu.num_events;
                        break;
                case 0xC090:    /* Cortex-A9 */
-                       armv7pmu.name = ARMV7_PMU_CORTEX_A9_NAME;
+                       armv7pmu.id = ARM_PERF_PMU_ID_CA9;
                        memcpy(armpmu_perf_cache_map, armv7_a9_perf_cache_map,
                                sizeof(armv7_a9_perf_cache_map));
                        armv7pmu.event_map = armv7_a9_pmu_event_map;
@@ -2128,15 +2966,33 @@ init_hw_perf_events(void)
                        armv7pmu.num_events = armv7_reset_read_pmnc();
                        perf_max_events = armv7pmu.num_events;
                        break;
-               default:
-                       pr_info("no hardware support available\n");
-                       perf_max_events = -1;
+               }
+       /* Intel CPUs [xscale]. */
+       } else if (0x69 == implementor) {
+               part_number = (cpuid >> 13) & 0x7;
+               switch (part_number) {
+               case 1:
+                       armpmu = &xscale1pmu;
+                       memcpy(armpmu_perf_cache_map, xscale_perf_cache_map,
+                                       sizeof(xscale_perf_cache_map));
+                       perf_max_events = xscale1pmu.num_events;
+                       break;
+               case 2:
+                       armpmu = &xscale2pmu;
+                       memcpy(armpmu_perf_cache_map, xscale_perf_cache_map,
+                                       sizeof(xscale_perf_cache_map));
+                       perf_max_events = xscale2pmu.num_events;
+                       break;
                }
        }
 
-       if (armpmu)
+       if (armpmu) {
                pr_info("enabled with %s PMU driver, %d counters available\n",
-                       armpmu->name, armpmu->num_events);
+                               arm_pmu_names[armpmu->id], armpmu->num_events);
+       } else {
+               pr_info("no hardware support available\n");
+               perf_max_events = -1;
+       }
 
        return 0;
 }
index a124312..b8af96e 100644 (file)
@@ -2,6 +2,7 @@
  *  linux/arch/arm/kernel/pmu.c
  *
  *  Copyright (C) 2009 picoChip Designs Ltd, Jamie Iles
+ *  Copyright (C) 2010 ARM Ltd, Will Deacon
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  *
  */
 
+#define pr_fmt(fmt) "PMU: " fmt
+
 #include <linux/cpumask.h>
 #include <linux/err.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
 
 #include <asm/pmu.h>
 
-/*
- * Define the IRQs for the system. We could use something like a platform
- * device but that seems fairly heavyweight for this. Also, the performance
- * counters can't be removed or hotplugged.
- *
- * Ordering is important: init_pmu() will use the ordering to set the affinity
- * to the corresponding core. e.g. the first interrupt will go to cpu 0, the
- * second goes to cpu 1 etc.
- */
-static const int irqs[] = {
-#if defined(CONFIG_ARCH_OMAP2)
-       3,
-#elif defined(CONFIG_ARCH_BCMRING)
-       IRQ_PMUIRQ,
-#elif defined(CONFIG_MACH_REALVIEW_EB)
-       IRQ_EB11MP_PMU_CPU0,
-       IRQ_EB11MP_PMU_CPU1,
-       IRQ_EB11MP_PMU_CPU2,
-       IRQ_EB11MP_PMU_CPU3,
-#elif defined(CONFIG_ARCH_OMAP3)
-       INT_34XX_BENCH_MPU_EMUL,
-#elif defined(CONFIG_ARCH_IOP32X)
-       IRQ_IOP32X_CORE_PMU,
-#elif defined(CONFIG_ARCH_IOP33X)
-       IRQ_IOP33X_CORE_PMU,
-#elif defined(CONFIG_ARCH_PXA)
-       IRQ_PMU,
-#endif
-};
+static volatile long pmu_lock;
+
+static struct platform_device *pmu_devices[ARM_NUM_PMU_DEVICES];
+
+static int __devinit pmu_device_probe(struct platform_device *pdev)
+{
+
+       if (pdev->id < 0 || pdev->id >= ARM_NUM_PMU_DEVICES) {
+               pr_warning("received registration request for unknown "
+                               "device %d\n", pdev->id);
+               return -EINVAL;
+       }
+
+       if (pmu_devices[pdev->id])
+               pr_warning("registering new PMU device type %d overwrites "
+                               "previous registration!\n", pdev->id);
+       else
+               pr_info("registered new PMU device of type %d\n",
+                               pdev->id);
 
-static const struct pmu_irqs pmu_irqs = {
-       .irqs       = irqs,
-       .num_irqs   = ARRAY_SIZE(irqs),
+       pmu_devices[pdev->id] = pdev;
+       return 0;
+}
+
+static struct platform_driver pmu_driver = {
+       .driver         = {
+               .name   = "arm-pmu",
+       },
+       .probe          = pmu_device_probe,
 };
 
-static volatile long pmu_lock;
+static int __init register_pmu_driver(void)
+{
+       return platform_driver_register(&pmu_driver);
+}
+device_initcall(register_pmu_driver);
 
-const struct pmu_irqs *
-reserve_pmu(void)
+struct platform_device *
+reserve_pmu(enum arm_pmu_type device)
 {
-       return test_and_set_bit_lock(0, &pmu_lock) ? ERR_PTR(-EBUSY) :
-               &pmu_irqs;
+       struct platform_device *pdev;
+
+       if (test_and_set_bit_lock(device, &pmu_lock)) {
+               pdev = ERR_PTR(-EBUSY);
+       } else if (pmu_devices[device] == NULL) {
+               clear_bit_unlock(device, &pmu_lock);
+               pdev = ERR_PTR(-ENODEV);
+       } else {
+               pdev = pmu_devices[device];
+       }
+
+       return pdev;
 }
 EXPORT_SYMBOL_GPL(reserve_pmu);
 
 int
-release_pmu(const struct pmu_irqs *irqs)
+release_pmu(struct platform_device *pdev)
 {
-       if (WARN_ON(irqs != &pmu_irqs))
+       if (WARN_ON(pdev != pmu_devices[pdev->id]))
                return -EINVAL;
-       clear_bit_unlock(0, &pmu_lock);
+       clear_bit_unlock(pdev->id, &pmu_lock);
        return 0;
 }
 EXPORT_SYMBOL_GPL(release_pmu);
@@ -87,17 +101,42 @@ set_irq_affinity(int irq,
 #endif
 }
 
-int
-init_pmu(void)
+static int
+init_cpu_pmu(void)
 {
        int i, err = 0;
+       struct platform_device *pdev = pmu_devices[ARM_PMU_DEVICE_CPU];
+
+       if (!pdev) {
+               err = -ENODEV;
+               goto out;
+       }
 
-       for (i = 0; i < pmu_irqs.num_irqs; ++i) {
-               err = set_irq_affinity(pmu_irqs.irqs[i], i);
+       for (i = 0; i < pdev->num_resources; ++i) {
+               err = set_irq_affinity(platform_get_irq(pdev, i), i);
                if (err)
                        break;
        }
 
+out:
+       return err;
+}
+
+int
+init_pmu(enum arm_pmu_type device)
+{
+       int err = 0;
+
+       switch (device) {
+       case ARM_PMU_DEVICE_CPU:
+               err = init_cpu_pmu();
+               break;
+       default:
+               pr_warning("attempt to initialise unknown device %d\n",
+                               device);
+               err = -EINVAL;
+       }
+
        return err;
 }
 EXPORT_SYMBOL_GPL(init_pmu);
index a01194e..b8c3d0f 100644 (file)
@@ -168,7 +168,7 @@ int __cpu_disable(void)
        struct task_struct *p;
        int ret;
 
-       ret = mach_cpu_disable(cpu);
+       ret = platform_cpu_disable(cpu);
        if (ret)
                return ret;
 
index 2875380..38c261f 100644 (file)
@@ -72,12 +72,15 @@ unsigned long profile_pc(struct pt_regs *regs)
 EXPORT_SYMBOL(profile_pc);
 #endif
 
-#ifndef CONFIG_GENERIC_TIME
-static unsigned long dummy_gettimeoffset(void)
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
+u32 arch_gettimeoffset(void)
 {
+       if (system_timer->offset != NULL)
+               return system_timer->offset() * 1000;
+
        return 0;
 }
-#endif
+#endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
 
 #ifdef CONFIG_LEDS_TIMER
 static inline void do_leds(void)
@@ -93,63 +96,6 @@ static inline void do_leds(void)
 #define        do_leds()
 #endif
 
-#ifndef CONFIG_GENERIC_TIME
-void do_gettimeofday(struct timeval *tv)
-{
-       unsigned long flags;
-       unsigned long seq;
-       unsigned long usec, sec;
-
-       do {
-               seq = read_seqbegin_irqsave(&xtime_lock, flags);
-               usec = system_timer->offset();
-               sec = xtime.tv_sec;
-               usec += xtime.tv_nsec / 1000;
-       } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-
-       /* usec may have gone up a lot: be safe */
-       while (usec >= 1000000) {
-               usec -= 1000000;
-               sec++;
-       }
-
-       tv->tv_sec = sec;
-       tv->tv_usec = usec;
-}
-
-EXPORT_SYMBOL(do_gettimeofday);
-
-int do_settimeofday(struct timespec *tv)
-{
-       time_t wtm_sec, sec = tv->tv_sec;
-       long wtm_nsec, nsec = tv->tv_nsec;
-
-       if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
-               return -EINVAL;
-
-       write_seqlock_irq(&xtime_lock);
-       /*
-        * This is revolting. We need to set "xtime" correctly. However, the
-        * value in this location is the value at the most recent update of
-        * wall time.  Discover what correction gettimeofday() would have
-        * done, and then undo it!
-        */
-       nsec -= system_timer->offset() * NSEC_PER_USEC;
-
-       wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
-       wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
-
-       set_normalized_timespec(&xtime, sec, nsec);
-       set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
-
-       ntp_clear();
-       write_sequnlock_irq(&xtime_lock);
-       clock_was_set();
-       return 0;
-}
-
-EXPORT_SYMBOL(do_settimeofday);
-#endif /* !CONFIG_GENERIC_TIME */
 
 #ifndef CONFIG_GENERIC_CLOCKEVENTS
 /*
@@ -214,10 +160,6 @@ device_initcall(timer_init_sysfs);
 
 void __init time_init(void)
 {
-#ifndef CONFIG_GENERIC_TIME
-       if (system_timer->offset == NULL)
-               system_timer->offset = dummy_gettimeoffset;
-#endif
        system_timer->init();
 }
 
index 2db43a5..841eaf8 100644 (file)
@@ -23,14 +23,12 @@ choice
 config ARCH_AT91RM9200
        bool "AT91RM9200"
        select CPU_ARM920T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_AT91_USART3
 
 config ARCH_AT91SAM9260
        bool "AT91SAM9260 or AT91SAM9XE"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_AT91_USART3
        select HAVE_AT91_USART4
@@ -39,28 +37,24 @@ config ARCH_AT91SAM9260
 config ARCH_AT91SAM9261
        bool "AT91SAM9261"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_FB_ATMEL
 
 config ARCH_AT91SAM9G10
        bool "AT91SAM9G10"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_FB_ATMEL
 
 config ARCH_AT91SAM9263
        bool "AT91SAM9263"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_FB_ATMEL
 
 config ARCH_AT91SAM9RL
        bool "AT91SAM9RL"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_AT91_USART3
        select HAVE_FB_ATMEL
@@ -68,7 +62,6 @@ config ARCH_AT91SAM9RL
 config ARCH_AT91SAM9G20
        bool "AT91SAM9G20"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_AT91_USART3
        select HAVE_AT91_USART4
@@ -77,7 +70,6 @@ config ARCH_AT91SAM9G20
 config ARCH_AT91SAM9G45
        bool "AT91SAM9G45"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_AT91_USART3
        select HAVE_FB_ATMEL
@@ -85,18 +77,17 @@ config ARCH_AT91SAM9G45
 config ARCH_AT91CAP9
        bool "AT91CAP9"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
        select HAVE_FB_ATMEL
 
 config ARCH_AT572D940HF
        bool "AT572D940HF"
        select CPU_ARM926T
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91X40
        bool "AT91x40"
+       select ARCH_USES_GETTIMEOFFSET
 
 endchoice
 
@@ -360,6 +351,19 @@ config MACH_CPU9G20
          Select this if you are using a Eukrea Electromatique's
          CPU9G20 Board <http://www.eukrea.com/>
 
+config MACH_PORTUXG20
+       bool "taskit PortuxG20"
+       help
+         Select this if you are using taskit's PortuxG20.
+         <http://www.taskit.de/en/>
+
+config MACH_STAMP9G20
+       bool "taskit Stamp9G20 CPU module"
+       help
+         Select this if you are using taskit's Stamp9G20 CPU module on its
+         evaluation board.
+         <http://www.taskit.de/en/>
+
 endif
 
 # ----------------------------------------------------------
index d400455..c1f821e 100644 (file)
@@ -63,6 +63,8 @@ obj-$(CONFIG_MACH_AT91SAM9RLEK)       += board-sam9rlek.o
 obj-$(CONFIG_MACH_AT91SAM9G20EK) += board-sam9g20ek.o
 obj-$(CONFIG_MACH_AT91SAM9G20EK_2MMC) += board-sam9g20ek-2slot-mmc.o
 obj-$(CONFIG_MACH_CPU9G20)     += board-cpu9krea.o
+obj-$(CONFIG_MACH_STAMP9G20)   += board-stamp9g20.o
+obj-$(CONFIG_MACH_PORTUXG20)   += board-stamp9g20.o
 
 # AT91SAM9G45 board-specific support
 obj-$(CONFIG_MACH_AT91SAM9G45EKES) += board-sam9m10g45ek.o
diff --git a/arch/arm/mach-at91/board-stamp9g20.c b/arch/arm/mach-at91/board-stamp9g20.c
new file mode 100644 (file)
index 0000000..8795827
--- /dev/null
@@ -0,0 +1,315 @@
+/*
+ *  Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
+ *                     taskit GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/mm.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/w1-gpio.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+#include <mach/board.h>
+#include <mach/at91sam9_smc.h>
+
+#include "sam9_smc.h"
+#include "generic.h"
+
+
+static void __init portuxg20_map_io(void)
+{
+       /* Initialize processor: 18.432 MHz crystal */
+       at91sam9260_initialize(18432000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                                               | ATMEL_UART_DTR | ATMEL_UART_DSR
+                                               | ATMEL_UART_DCD | ATMEL_UART_RI);
+
+       /* USART1 on ttyS2. (Rx, Tx, CTS, RTS) */
+       at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* USART2 on ttyS3. (Rx, Tx, CTS, RTS) */
+       at91_register_uart(AT91SAM9260_ID_US2, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
+
+       /* USART4 on ttyS5. (Rx, Tx only) */
+       at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
+
+       /* USART5 on ttyS6. (Rx, Tx only) */
+       at91_register_uart(AT91SAM9260_ID_US5, 6, 0);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
+}
+
+static void __init stamp9g20_map_io(void)
+{
+       /* Initialize processor: 18.432 MHz crystal */
+       at91sam9260_initialize(18432000);
+
+       /* DGBU on ttyS0. (Rx & Tx only) */
+       at91_register_uart(0, 0, 0);
+
+       /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
+       at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
+                                               | ATMEL_UART_DTR | ATMEL_UART_DSR
+                                               | ATMEL_UART_DCD | ATMEL_UART_RI);
+
+       /* set serial console to ttyS0 (ie, DBGU) */
+       at91_set_serial_console(0);
+}
+
+static void __init init_irq(void)
+{
+       at91sam9260_init_interrupts(NULL);
+}
+
+
+/*
+ * NAND flash
+ */
+static struct atmel_nand_data __initdata nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+       .rdy_pin        = AT91_PIN_PC13,
+       .enable_pin     = AT91_PIN_PC14,
+       .bus_width_16   = 0,
+};
+
+static struct sam9_smc_config __initdata nand_smc_config = {
+       .ncs_read_setup         = 0,
+       .nrd_setup              = 2,
+       .ncs_write_setup        = 0,
+       .nwe_setup              = 2,
+
+       .ncs_read_pulse         = 4,
+       .nrd_pulse              = 4,
+       .ncs_write_pulse        = 4,
+       .nwe_pulse              = 4,
+
+       .read_cycle             = 7,
+       .write_cycle            = 7,
+
+       .mode                   = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
+       .tdf_cycles             = 3,
+};
+
+static void __init add_device_nand(void)
+{
+       /* configure chip-select 3 (NAND) */
+       sam9_smc_configure(3, &nand_smc_config);
+
+       at91_add_device_nand(&nand_data);
+}
+
+
+/*
+ * MCI (SD/MMC)
+ * det_pin, wp_pin and vcc_pin are not connected
+ */
+#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
+static struct mci_platform_data __initdata mmc_data = {
+       .slot[0] = {
+               .bus_width      = 4,
+       },
+};
+#else
+static struct at91_mmc_data __initdata mmc_data = {
+       .slot_b         = 0,
+       .wire4          = 1,
+};
+#endif
+
+
+/*
+ * USB Host port
+ */
+static struct at91_usbh_data __initdata usbh_data = {
+       .ports          = 2,
+};
+
+
+/*
+ * USB Device port
+ */
+static struct at91_udc_data __initdata portuxg20_udc_data = {
+       .vbus_pin       = AT91_PIN_PC7,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+static struct at91_udc_data __initdata stamp9g20_udc_data = {
+       .vbus_pin       = AT91_PIN_PA22,
+       .pullup_pin     = 0,            /* pull-up driven by UDC */
+};
+
+
+/*
+ * MACB Ethernet device
+ */
+static struct at91_eth_data __initdata macb_data = {
+       .phy_irq_pin    = AT91_PIN_PA28,
+       .is_rmii        = 1,
+};
+
+
+/*
+ * LEDs
+ */
+static struct gpio_led portuxg20_leds[] = {
+       {
+               .name                   = "LED2",
+               .gpio                   = AT91_PIN_PC5,
+               .default_trigger        = "none",
+       }, {
+               .name                   = "LED3",
+               .gpio                   = AT91_PIN_PC4,
+               .default_trigger        = "none",
+       }, {
+               .name                   = "LED4",
+               .gpio                   = AT91_PIN_PC10,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+static struct gpio_led stamp9g20_leds[] = {
+       {
+               .name                   = "D8",
+               .gpio                   = AT91_PIN_PB18,
+               .active_low             = 1,
+               .default_trigger        = "none",
+       }, {
+               .name                   = "D9",
+               .gpio                   = AT91_PIN_PB19,
+               .active_low             = 1,
+               .default_trigger        = "none",
+       }, {
+               .name                   = "D10",
+               .gpio                   = AT91_PIN_PB20,
+               .active_low             = 1,
+               .default_trigger        = "heartbeat",
+       }
+};
+
+
+/*
+ * SPI devices
+ */
+static struct spi_board_info portuxg20_spi_devices[] = {
+       {
+               .modalias       = "spidev",
+               .chip_select    = 0,
+               .max_speed_hz   = 1 * 1000 * 1000,
+               .bus_num        = 0,
+       }, {
+               .modalias       = "spidev",
+               .chip_select    = 0,
+               .max_speed_hz   = 1 * 1000 * 1000,
+               .bus_num        = 1,
+       },
+};
+
+
+/*
+ * Dallas 1-Wire
+ */
+static struct w1_gpio_platform_data w1_gpio_pdata = {
+       .pin            = AT91_PIN_PA29,
+       .is_open_drain  = 1,
+};
+
+static struct platform_device w1_device = {
+       .name                   = "w1-gpio",
+       .id                     = -1,
+       .dev.platform_data      = &w1_gpio_pdata,
+};
+
+void add_w1(void)
+{
+       at91_set_GPIO_periph(w1_gpio_pdata.pin, 1);
+       at91_set_multi_drive(w1_gpio_pdata.pin, 1);
+       platform_device_register(&w1_device);
+}
+
+
+static void __init generic_board_init(void)
+{
+       /* Serial */
+       at91_add_device_serial();
+       /* NAND */
+       add_device_nand();
+       /* MMC */
+#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
+       at91_add_device_mci(0, &mmc_data);
+#else
+       at91_add_device_mmc(0, &mmc_data);
+#endif
+       /* USB Host */
+       at91_add_device_usbh(&usbh_data);
+       /* Ethernet */
+       at91_add_device_eth(&macb_data);
+       /* I2C */
+       at91_add_device_i2c(NULL, 0);
+       /* W1 */
+       add_w1();
+}
+
+static void __init portuxg20_board_init(void)
+{
+       generic_board_init();
+       /* SPI */
+       at91_add_device_spi(portuxg20_spi_devices, ARRAY_SIZE(portuxg20_spi_devices));
+       /* USB Device */
+       at91_add_device_udc(&portuxg20_udc_data);
+       /* LEDs */
+       at91_gpio_leds(portuxg20_leds, ARRAY_SIZE(portuxg20_leds));
+}
+
+static void __init stamp9g20_board_init(void)
+{
+       generic_board_init();
+       /* USB Device */
+       at91_add_device_udc(&stamp9g20_udc_data);
+       /* LEDs */
+       at91_gpio_leds(stamp9g20_leds, ARRAY_SIZE(stamp9g20_leds));
+}
+
+MACHINE_START(PORTUXG20, "taskit PortuxG20")
+       /* Maintainer: taskit GmbH */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = portuxg20_map_io,
+       .init_irq       = init_irq,
+       .init_machine   = portuxg20_board_init,
+MACHINE_END
+
+MACHINE_START(STAMP9G20, "taskit Stamp9G20")
+       /* Maintainer: taskit GmbH */
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = stamp9g20_map_io,
+       .init_irq       = init_irq,
+       .init_machine   = stamp9g20_board_init,
+MACHINE_END
index ceaec6c..df2ed84 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/usb/atmel_usba_udc.h>
 #include <linux/atmel-mci.h>
 #include <sound/atmel-ac97c.h>
+#include <linux/serial.h>
 
  /* USB Device */
 struct at91_udc_data {
@@ -143,9 +144,10 @@ extern struct platform_device *atmel_default_console_device;
 extern void __init __deprecated at91_init_serial(struct at91_uart_config *config);
 
 struct atmel_uart_data {
-       short           use_dma_tx;     /* use transmit DMA? */
-       short           use_dma_rx;     /* use receive DMA? */
-       void __iomem    *regs;          /* virtual base address, if any */
+       short                   use_dma_tx;     /* use transmit DMA? */
+       short                   use_dma_rx;     /* use receive DMA? */
+       void __iomem            *regs;          /* virt. base address, if any */
+       struct serial_rs485     rs485;          /* rs485 settings */
 };
 extern void __init at91_add_device_serial(void);
 
index 5a06501..833659d 100644 (file)
@@ -21,7 +21,7 @@
 #define ARCH_ID_AT91SAM9260    0x019803a0
 #define ARCH_ID_AT91SAM9261    0x019703a0
 #define ARCH_ID_AT91SAM9263    0x019607a0
-#define ARCH_ID_AT91SAM9G10    0x819903a0
+#define ARCH_ID_AT91SAM9G10    0x019903a0
 #define ARCH_ID_AT91SAM9G20    0x019905a0
 #define ARCH_ID_AT91SAM9RL64   0x019b03a0
 #define ARCH_ID_AT91SAM9G45    0x819b05a0
@@ -108,7 +108,7 @@ static inline unsigned long at91cap9_rev_identify(void)
 #endif
 
 #ifdef CONFIG_ARCH_AT91SAM9G10
-#define cpu_is_at91sam9g10()   (at91_cpu_identify() == ARCH_ID_AT91SAM9G10)
+#define cpu_is_at91sam9g10()   ((at91_cpu_identify() & ~AT91_CIDR_EXT) == ARCH_ID_AT91SAM9G10)
 #else
 #define cpu_is_at91sam9g10()   (0)
 #endif
index 5268af3..c80e090 100644 (file)
 #include <mach/hardware.h>
 #include <mach/at91_st.h>
 #include <mach/at91_dbgu.h>
+#include <mach/at91_pmc.h>
 
 static inline void arch_idle(void)
 {
+#ifndef CONFIG_DEBUG_KERNEL
        /*
         * Disable the processor clock.  The processor will be automatically
         * re-enabled by an interrupt or by a reset.
         */
-//     at91_sys_write(AT91_PMC_SCDR, AT91_PMC_PCK);
-
+       at91_sys_write(AT91_PMC_SCDR, AT91_PMC_PCK);
+#else
        /*
         * Set the processor (CP15) into 'Wait for Interrupt' mode.
         * Unlike disabling the processor clock via the PMC (above)
         *  this allows the processor to be woken via JTAG.
         */
        cpu_do_idle();
+#endif
 }
 
 void (*at91_arch_reset)(void);
index 53dd2a9..2f13919 100644 (file)
@@ -29,6 +29,7 @@
 #include <asm/setup.h>
 #include <asm/mach-types.h>
 #include <asm/mach/time.h>
+#include <asm/pmu.h>
 
 #include <asm/mach/arch.h>
 #include <mach/dma.h>
@@ -85,8 +86,23 @@ static struct platform_device nand_device = {
        .num_resources  = ARRAY_SIZE(nand_resource),
 };
 
+static struct resource pmu_resource = {
+       .start  = IRQ_PMUIRQ,
+       .end    = IRQ_PMUIRQ,
+       .flags  = IORESOURCE_IRQ,
+};
+
+static struct platform_device pmu_device = {
+       .name           = "arm-pmu",
+       .id             = ARM_PMU_DEVICE_CPU,
+       .resource       = &pmu_resource,
+       .num_resources  = 1,
+};
+
+
 static struct platform_device *devices[] __initdata = {
        &nand_device,
+       &pmu_device,
 };
 
 /****************************************************************************
index a7b4591..9865921 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/init.h>
-#include <linux/bootmem.h>
 
 #include <asm/sizes.h>
 #include <mach/hardware.h>
diff --git a/arch/arm/mach-cns3xxx/Kconfig b/arch/arm/mach-cns3xxx/Kconfig
new file mode 100644 (file)
index 0000000..9ebfcc4
--- /dev/null
@@ -0,0 +1,12 @@
+menu "CNS3XXX platform type"
+       depends on ARCH_CNS3XXX
+
+config MACH_CNS3420VB
+       bool "Support for CNS3420 Validation Board"
+       help
+         Include support for the Cavium Networks CNS3420 MPCore Platform
+         Baseboard.
+         This is a platform with an on-board ARM11 MPCore and has support
+         for USB, USB-OTG, MMC/SD/SDIO, SATA, PCI-E, etc.
+
+endmenu
diff --git a/arch/arm/mach-cns3xxx/Makefile b/arch/arm/mach-cns3xxx/Makefile
new file mode 100644 (file)
index 0000000..427507a
--- /dev/null
@@ -0,0 +1,2 @@
+obj-$(CONFIG_ARCH_CNS3XXX)             += core.o pm.o
+obj-$(CONFIG_MACH_CNS3420VB)           += cns3420vb.o
diff --git a/arch/arm/mach-cns3xxx/Makefile.boot b/arch/arm/mach-cns3xxx/Makefile.boot
new file mode 100644 (file)
index 0000000..7770128
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00C00000
diff --git a/arch/arm/mach-cns3xxx/cns3420vb.c b/arch/arm/mach-cns3xxx/cns3420vb.c
new file mode 100644 (file)
index 0000000..2e30c82
--- /dev/null
@@ -0,0 +1,148 @@
+/*
+ * Cavium Networks CNS3420 Validation Board
+ *
+ * Copyright 2000 Deep Blue Solutions Ltd
+ * Copyright 2008 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *               Scott Shu
+ * Copyright 2010 MontaVista Software, LLC.
+ *               Anton Vorontsov <avorontsov@mvista.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/compiler.h>
+#include <linux/io.h>
+#include <linux/serial_core.h>
+#include <linux/serial_8250.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/partitions.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <mach/hardware.h>
+#include <mach/cns3xxx.h>
+#include <mach/irqs.h>
+#include "core.h"
+
+/*
+ * NOR Flash
+ */
+static struct mtd_partition cns3420_nor_partitions[] = {
+       {
+               .name           = "uboot",
+               .size           = 0x00040000,
+               .offset         = 0,
+               .mask_flags     = MTD_WRITEABLE,
+       }, {
+               .name           = "kernel",
+               .size           = 0x004C0000,
+               .offset         = MTDPART_OFS_APPEND,
+       }, {
+               .name           = "filesystem",
+               .size           = 0x7000000,
+               .offset         = MTDPART_OFS_APPEND,
+       }, {
+               .name           = "filesystem2",
+               .size           = 0x0AE0000,
+               .offset         = MTDPART_OFS_APPEND,
+       }, {
+               .name           = "ubootenv",
+               .size           = MTDPART_SIZ_FULL,
+               .offset         = MTDPART_OFS_APPEND,
+       },
+};
+
+static struct physmap_flash_data cns3420_nor_pdata = {
+       .width = 2,
+       .parts = cns3420_nor_partitions,
+       .nr_parts = ARRAY_SIZE(cns3420_nor_partitions),
+};
+
+static struct resource cns3420_nor_res = {
+       .start = CNS3XXX_FLASH_BASE,
+       .end = CNS3XXX_FLASH_BASE + SZ_128M - 1,
+       .flags = IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+};
+
+static struct platform_device cns3420_nor_pdev = {
+       .name = "physmap-flash",
+       .id = 0,
+       .resource = &cns3420_nor_res,
+       .num_resources = 1,
+       .dev = {
+               .platform_data = &cns3420_nor_pdata,
+       },
+};
+
+/*
+ * UART
+ */
+static void __init cns3420_early_serial_setup(void)
+{
+#ifdef CONFIG_SERIAL_8250_CONSOLE
+       static struct uart_port cns3420_serial_port = {
+               .membase        = (void __iomem *)CNS3XXX_UART0_BASE_VIRT,
+               .mapbase        = CNS3XXX_UART0_BASE,
+               .irq            = IRQ_CNS3XXX_UART0,
+               .iotype         = UPIO_MEM,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_FIXED_TYPE,
+               .regshift       = 2,
+               .uartclk        = 24000000,
+               .line           = 0,
+               .type           = PORT_16550A,
+               .fifosize       = 16,
+       };
+
+       early_serial_setup(&cns3420_serial_port);
+#endif
+}
+
+/*
+ * Initialization
+ */
+static struct platform_device *cns3420_pdevs[] __initdata = {
+       &cns3420_nor_pdev,
+};
+
+static void __init cns3420_init(void)
+{
+       platform_add_devices(cns3420_pdevs, ARRAY_SIZE(cns3420_pdevs));
+
+       pm_power_off = cns3xxx_power_off;
+}
+
+static struct map_desc cns3420_io_desc[] __initdata = {
+       {
+               .virtual        = CNS3XXX_UART0_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_UART0_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       },
+};
+
+static void __init cns3420_map_io(void)
+{
+       cns3xxx_map_io();
+       iotable_init(cns3420_io_desc, ARRAY_SIZE(cns3420_io_desc));
+
+       cns3420_early_serial_setup();
+}
+
+MACHINE_START(CNS3420VB, "Cavium Networks CNS3420 Validation Board")
+       .phys_io        = CNS3XXX_UART0_BASE,
+       .io_pg_offst    = (CNS3XXX_UART0_BASE_VIRT >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .map_io         = cns3420_map_io,
+       .init_irq       = cns3xxx_init_irq,
+       .timer          = &cns3xxx_timer,
+       .init_machine   = cns3420_init,
+MACHINE_END
diff --git a/arch/arm/mach-cns3xxx/core.c b/arch/arm/mach-cns3xxx/core.c
new file mode 100644 (file)
index 0000000..9ca4d58
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Copyright 1999 - 2003 ARM Limited
+ * Copyright 2000 Deep Blue Solutions Ltd
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/clockchips.h>
+#include <linux/io.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <asm/mach/irq.h>
+#include <asm/hardware/gic.h>
+#include <mach/cns3xxx.h>
+#include "core.h"
+
+static struct map_desc cns3xxx_io_desc[] __initdata = {
+       {
+               .virtual        = CNS3XXX_TC11MP_TWD_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_TC11MP_TWD_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_TC11MP_GIC_CPU_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_TC11MP_GIC_DIST_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_TIMER1_2_3_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_TIMER1_2_3_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_GPIOA_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_GPIOA_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_GPIOB_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_GPIOB_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_MISC_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_MISC_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = CNS3XXX_PM_BASE_VIRT,
+               .pfn            = __phys_to_pfn(CNS3XXX_PM_BASE),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init cns3xxx_map_io(void)
+{
+       iotable_init(cns3xxx_io_desc, ARRAY_SIZE(cns3xxx_io_desc));
+}
+
+/* used by entry-macro.S */
+void __iomem *gic_cpu_base_addr;
+
+void __init cns3xxx_init_irq(void)
+{
+       gic_cpu_base_addr = __io(CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT);
+       gic_dist_init(0, __io(CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT), 29);
+       gic_cpu_init(0, gic_cpu_base_addr);
+}
+
+void cns3xxx_power_off(void)
+{
+       u32 __iomem *pm_base = __io(CNS3XXX_PM_BASE_VIRT);
+       u32 clkctrl;
+
+       printk(KERN_INFO "powering system down...\n");
+
+       clkctrl = readl(pm_base + PM_SYS_CLK_CTRL_OFFSET);
+       clkctrl &= 0xfffff1ff;
+       clkctrl |= (0x5 << 9);          /* Hibernate */
+       writel(clkctrl, pm_base + PM_SYS_CLK_CTRL_OFFSET);
+
+}
+
+/*
+ * Timer
+ */
+static void __iomem *cns3xxx_tmr1;
+
+static void cns3xxx_timer_set_mode(enum clock_event_mode mode,
+                                  struct clock_event_device *clk)
+{
+       unsigned long ctrl = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+       int pclk = cns3xxx_cpu_clock() / 8;
+       int reload;
+
+       switch (mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               reload = pclk * 20 / (3 * HZ) * 0x25000;
+               writel(reload, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
+               ctrl |= (1 << 0) | (1 << 2) | (1 << 9);
+               break;
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* period set, and timer enabled in 'next_event' hook */
+               ctrl |= (1 << 2) | (1 << 9);
+               break;
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       default:
+               ctrl = 0;
+       }
+
+       writel(ctrl, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+}
+
+static int cns3xxx_timer_set_next_event(unsigned long evt,
+                                       struct clock_event_device *unused)
+{
+       unsigned long ctrl = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+
+       writel(evt, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
+       writel(ctrl | (1 << 0), cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+
+       return 0;
+}
+
+static struct clock_event_device cns3xxx_tmr1_clockevent = {
+       .name           = "cns3xxx timer1",
+       .shift          = 8,
+       .features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
+       .set_mode       = cns3xxx_timer_set_mode,
+       .set_next_event = cns3xxx_timer_set_next_event,
+       .rating         = 350,
+       .cpumask        = cpu_all_mask,
+};
+
+static void __init cns3xxx_clockevents_init(unsigned int timer_irq)
+{
+       cns3xxx_tmr1_clockevent.irq = timer_irq;
+       cns3xxx_tmr1_clockevent.mult =
+               div_sc((cns3xxx_cpu_clock() >> 3) * 1000000, NSEC_PER_SEC,
+                      cns3xxx_tmr1_clockevent.shift);
+       cns3xxx_tmr1_clockevent.max_delta_ns =
+               clockevent_delta2ns(0xffffffff, &cns3xxx_tmr1_clockevent);
+       cns3xxx_tmr1_clockevent.min_delta_ns =
+               clockevent_delta2ns(0xf, &cns3xxx_tmr1_clockevent);
+
+       clockevents_register_device(&cns3xxx_tmr1_clockevent);
+}
+
+/*
+ * IRQ handler for the timer
+ */
+static irqreturn_t cns3xxx_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = &cns3xxx_tmr1_clockevent;
+       u32 __iomem *stat = cns3xxx_tmr1 + TIMER1_2_INTERRUPT_STATUS_OFFSET;
+       u32 val;
+
+       /* Clear the interrupt */
+       val = readl(stat);
+       writel(val & ~(1 << 2), stat);
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static struct irqaction cns3xxx_timer_irq = {
+       .name           = "timer",
+       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+       .handler        = cns3xxx_timer_interrupt,
+};
+
+/*
+ * Set up the clock source and clock events devices
+ */
+static void __init __cns3xxx_timer_init(unsigned int timer_irq)
+{
+       u32 val;
+       u32 irq_mask;
+
+       /*
+        * Initialise to a known state (all timers off)
+        */
+
+       /* disable timer1 and timer2 */
+       writel(0, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+       /* stop free running timer3 */
+       writel(0, cns3xxx_tmr1 + TIMER_FREERUN_CONTROL_OFFSET);
+
+       /* timer1 */
+       writel(0x5C800, cns3xxx_tmr1 + TIMER1_COUNTER_OFFSET);
+       writel(0x5C800, cns3xxx_tmr1 + TIMER1_AUTO_RELOAD_OFFSET);
+
+       writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V1_OFFSET);
+       writel(0, cns3xxx_tmr1 + TIMER1_MATCH_V2_OFFSET);
+
+       /* mask irq, non-mask timer1 overflow */
+       irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
+       irq_mask &= ~(1 << 2);
+       irq_mask |= 0x03;
+       writel(irq_mask, cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
+
+       /* down counter */
+       val = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+       val |= (1 << 9);
+       writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+
+       /* timer2 */
+       writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V1_OFFSET);
+       writel(0, cns3xxx_tmr1 + TIMER2_MATCH_V2_OFFSET);
+
+       /* mask irq */
+       irq_mask = readl(cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
+       irq_mask |= ((1 << 3) | (1 << 4) | (1 << 5));
+       writel(irq_mask, cns3xxx_tmr1 + TIMER1_2_INTERRUPT_MASK_OFFSET);
+
+       /* down counter */
+       val = readl(cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+       val |= (1 << 10);
+       writel(val, cns3xxx_tmr1 + TIMER1_2_CONTROL_OFFSET);
+
+       /* Make irqs happen for the system timer */
+       setup_irq(timer_irq, &cns3xxx_timer_irq);
+
+       cns3xxx_clockevents_init(timer_irq);
+}
+
+static void __init cns3xxx_timer_init(void)
+{
+       cns3xxx_tmr1 = __io(CNS3XXX_TIMER1_2_3_BASE_VIRT);
+
+       __cns3xxx_timer_init(IRQ_CNS3XXX_TIMER0);
+}
+
+struct sys_timer cns3xxx_timer = {
+       .init = cns3xxx_timer_init,
+};
diff --git a/arch/arm/mach-cns3xxx/core.h b/arch/arm/mach-cns3xxx/core.h
new file mode 100644 (file)
index 0000000..6b33ec1
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000 Deep Blue Solutions Ltd
+ * Copyright 2004 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __CNS3XXX_CORE_H
+#define __CNS3XXX_CORE_H
+
+extern void __iomem *gic_cpu_base_addr;
+extern struct sys_timer cns3xxx_timer;
+
+void __init cns3xxx_map_io(void);
+void __init cns3xxx_init_irq(void);
+void cns3xxx_power_off(void);
+void cns3xxx_pwr_power_up(unsigned int block);
+void cns3xxx_pwr_power_down(unsigned int block);
+
+#endif /* __CNS3XXX_CORE_H */
diff --git a/arch/arm/mach-cns3xxx/include/mach/cns3xxx.h b/arch/arm/mach-cns3xxx/include/mach/cns3xxx.h
new file mode 100644 (file)
index 0000000..8a2f5a2
--- /dev/null
@@ -0,0 +1,635 @@
+/*
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_BOARD_CNS3XXXH
+#define __MACH_BOARD_CNS3XXXH
+
+/*
+ * Memory map
+ */
+#define CNS3XXX_FLASH_BASE                     0x10000000      /* Flash/SRAM Memory Bank 0 */
+#define CNS3XXX_FLASH_SIZE                     SZ_256M
+
+#define CNS3XXX_DDR2SDRAM_BASE                 0x20000000      /* DDR2 SDRAM Memory */
+
+#define CNS3XXX_SPI_FLASH_BASE                 0x60000000      /* SPI Serial Flash Memory */
+
+#define CNS3XXX_SWITCH_BASE                    0x70000000      /* Switch and HNAT Control */
+#define CNS3XXX_SWITCH_BASE_VIRT               0xFFF00000
+
+#define CNS3XXX_PPE_BASE                       0x70001000      /* HANT */
+#define CNS3XXX_PPE_BASE_VIRT                  0xFFF50000
+
+#define CNS3XXX_EMBEDDED_SRAM_BASE             0x70002000      /* HANT Embedded SRAM */
+#define CNS3XXX_EMBEDDED_SRAM_BASE_VIRT                0xFFF60000
+
+#define CNS3XXX_SSP_BASE                       0x71000000      /* Synchronous Serial Port - SPI/PCM/I2C */
+#define CNS3XXX_SSP_BASE_VIRT                  0xFFF01000
+
+#define CNS3XXX_DMC_BASE                       0x72000000      /* DMC Control (DDR2 SDRAM) */
+#define CNS3XXX_DMC_BASE_VIRT                  0xFFF02000
+
+#define CNS3XXX_SMC_BASE                       0x73000000      /* SMC Control */
+#define CNS3XXX_SMC_BASE_VIRT                  0xFFF03000
+
+#define SMC_MEMC_STATUS_OFFSET                 0x000
+#define SMC_MEMIF_CFG_OFFSET                   0x004
+#define SMC_MEMC_CFG_SET_OFFSET                        0x008
+#define SMC_MEMC_CFG_CLR_OFFSET                        0x00C
+#define SMC_DIRECT_CMD_OFFSET                  0x010
+#define SMC_SET_CYCLES_OFFSET                  0x014
+#define SMC_SET_OPMODE_OFFSET                  0x018
+#define SMC_REFRESH_PERIOD_0_OFFSET            0x020
+#define SMC_REFRESH_PERIOD_1_OFFSET            0x024
+#define SMC_SRAM_CYCLES0_0_OFFSET              0x100
+#define SMC_NAND_CYCLES0_0_OFFSET              0x100
+#define SMC_OPMODE0_0_OFFSET                   0x104
+#define SMC_SRAM_CYCLES0_1_OFFSET              0x120
+#define SMC_NAND_CYCLES0_1_OFFSET              0x120
+#define SMC_OPMODE0_1_OFFSET                   0x124
+#define SMC_USER_STATUS_OFFSET                 0x200
+#define SMC_USER_CONFIG_OFFSET                 0x204
+#define SMC_ECC_STATUS_OFFSET                  0x300
+#define SMC_ECC_MEMCFG_OFFSET                  0x304
+#define SMC_ECC_MEMCOMMAND1_OFFSET             0x308
+#define SMC_ECC_MEMCOMMAND2_OFFSET             0x30C
+#define SMC_ECC_ADDR0_OFFSET                   0x310
+#define SMC_ECC_ADDR1_OFFSET                   0x314
+#define SMC_ECC_VALUE0_OFFSET                  0x318
+#define SMC_ECC_VALUE1_OFFSET                  0x31C
+#define SMC_ECC_VALUE2_OFFSET                  0x320
+#define SMC_ECC_VALUE3_OFFSET                  0x324
+#define SMC_PERIPH_ID_0_OFFSET                 0xFE0
+#define SMC_PERIPH_ID_1_OFFSET                 0xFE4
+#define SMC_PERIPH_ID_2_OFFSET                 0xFE8
+#define SMC_PERIPH_ID_3_OFFSET                 0xFEC
+#define SMC_PCELL_ID_0_OFFSET                  0xFF0
+#define SMC_PCELL_ID_1_OFFSET                  0xFF4
+#define SMC_PCELL_ID_2_OFFSET                  0xFF8
+#define SMC_PCELL_ID_3_OFFSET                  0xFFC
+
+#define CNS3XXX_GPIOA_BASE                     0x74000000      /* GPIO port A */
+#define CNS3XXX_GPIOA_BASE_VIRT                        0xFFF04000
+
+#define CNS3XXX_GPIOB_BASE                     0x74800000      /* GPIO port B */
+#define CNS3XXX_GPIOB_BASE_VIRT                        0xFFF05000
+
+#define CNS3XXX_RTC_BASE                       0x75000000      /* Real Time Clock */
+#define CNS3XXX_RTC_BASE_VIRT                  0xFFF06000
+
+#define RTC_SEC_OFFSET                         0x00
+#define RTC_MIN_OFFSET                         0x04
+#define RTC_HOUR_OFFSET                                0x08
+#define RTC_DAY_OFFSET                         0x0C
+#define RTC_SEC_ALM_OFFSET                     0x10
+#define RTC_MIN_ALM_OFFSET                     0x14
+#define RTC_HOUR_ALM_OFFSET                    0x18
+#define RTC_REC_OFFSET                         0x1C
+#define RTC_CTRL_OFFSET                                0x20
+#define RTC_INTR_STS_OFFSET                    0x34
+
+#define CNS3XXX_MISC_BASE                      0x76000000      /* Misc Control */
+#define CNS3XXX_MISC_BASE_VIRT                 0xFFF07000      /* Misc Control */
+
+#define CNS3XXX_PM_BASE                                0x77000000      /* Power Management Control */
+#define CNS3XXX_PM_BASE_VIRT                   0xFFF08000
+
+#define PM_CLK_GATE_OFFSET                     0x00
+#define PM_SOFT_RST_OFFSET                     0x04
+#define PM_HS_CFG_OFFSET                       0x08
+#define PM_CACTIVE_STA_OFFSET                  0x0C
+#define PM_PWR_STA_OFFSET                      0x10
+#define PM_SYS_CLK_CTRL_OFFSET                 0x14
+#define PM_PLL_LCD_I2S_CTRL_OFFSET             0x18
+#define PM_PLL_HM_PD_OFFSET                    0x1C
+
+#define CNS3XXX_UART0_BASE                     0x78000000      /* UART 0 */
+#define CNS3XXX_UART0_BASE_VIRT                        0xFFF09000
+
+#define CNS3XXX_UART1_BASE                     0x78400000      /* UART 1 */
+#define CNS3XXX_UART1_BASE_VIRT                        0xFFF0A000
+
+#define CNS3XXX_UART2_BASE                     0x78800000      /* UART 2 */
+#define CNS3XXX_UART2_BASE_VIRT                        0xFFF0B000
+
+#define CNS3XXX_DMAC_BASE                      0x79000000      /* Generic DMA Control */
+#define CNS3XXX_DMAC_BASE_VIRT                 0xFFF0D000
+
+#define CNS3XXX_CORESIGHT_BASE                 0x7A000000      /* CoreSight */
+#define CNS3XXX_CORESIGHT_BASE_VIRT            0xFFF0E000
+
+#define CNS3XXX_CRYPTO_BASE                    0x7B000000      /* Crypto */
+#define CNS3XXX_CRYPTO_BASE_VIRT               0xFFF0F000
+
+#define CNS3XXX_I2S_BASE                       0x7C000000      /* I2S */
+#define CNS3XXX_I2S_BASE_VIRT                  0xFFF10000
+
+#define CNS3XXX_TIMER1_2_3_BASE                        0x7C800000      /* Timer */
+#define CNS3XXX_TIMER1_2_3_BASE_VIRT           0xFFF10800
+
+#define TIMER1_COUNTER_OFFSET                  0x00
+#define TIMER1_AUTO_RELOAD_OFFSET              0x04
+#define TIMER1_MATCH_V1_OFFSET                 0x08
+#define TIMER1_MATCH_V2_OFFSET                 0x0C
+
+#define TIMER2_COUNTER_OFFSET                  0x10
+#define TIMER2_AUTO_RELOAD_OFFSET              0x14
+#define TIMER2_MATCH_V1_OFFSET                 0x18
+#define TIMER2_MATCH_V2_OFFSET                 0x1C
+
+#define TIMER1_2_CONTROL_OFFSET                        0x30
+#define TIMER1_2_INTERRUPT_STATUS_OFFSET       0x34
+#define TIMER1_2_INTERRUPT_MASK_OFFSET         0x38
+
+#define TIMER_FREERUN_OFFSET                   0x40
+#define TIMER_FREERUN_CONTROL_OFFSET           0x44
+
+#define CNS3XXX_HCIE_BASE                      0x7D000000      /* HCIE Control */
+#define CNS3XXX_HCIE_BASE_VIRT                 0xFFF30000
+
+#define CNS3XXX_RAID_BASE                      0x7E000000      /* RAID Control */
+#define CNS3XXX_RAID_BASE_VIRT                 0xFFF12000
+
+#define CNS3XXX_AXI_IXC_BASE                   0x7F000000      /* AXI IXC */
+#define CNS3XXX_AXI_IXC_BASE_VIRT              0xFFF13000
+
+#define CNS3XXX_CLCD_BASE                      0x80000000      /* LCD Control */
+#define CNS3XXX_CLCD_BASE_VIRT                 0xFFF14000
+
+#define CNS3XXX_USBOTG_BASE                    0x81000000      /* USB OTG Control */
+#define CNS3XXX_USBOTG_BASE_VIRT               0xFFF15000
+
+#define CNS3XXX_USB_BASE                       0x82000000      /* USB Host Control */
+#define CNS3XXX_USB_BASE_VIRT                  0xFFF16000
+
+#define CNS3XXX_SATA2_BASE                     0x83000000      /* SATA */
+#define CNS3XXX_SATA2_SIZE                     SZ_16M
+#define CNS3XXX_SATA2_BASE_VIRT                        0xFFF17000
+
+#define CNS3XXX_CAMERA_BASE                    0x84000000      /* Camera Interface */
+#define CNS3XXX_CAMERA_BASE_VIRT               0xFFF18000
+
+#define CNS3XXX_SDIO_BASE                      0x85000000      /* SDIO */
+#define CNS3XXX_SDIO_BASE_VIRT                 0xFFF19000
+
+#define CNS3XXX_I2S_TDM_BASE                   0x86000000      /* I2S TDM */
+#define CNS3XXX_I2S_TDM_BASE_VIRT              0xFFF1A000
+
+#define CNS3XXX_2DG_BASE                       0x87000000      /* 2D Graphic Control */
+#define CNS3XXX_2DG_BASE_VIRT                  0xFFF1B000
+
+#define CNS3XXX_USB_OHCI_BASE                  0x88000000      /* USB OHCI */
+#define CNS3XXX_USB_OHCI_BASE_VIRT             0xFFF1C000
+
+#define CNS3XXX_L2C_BASE                       0x92000000      /* L2 Cache Control */
+#define CNS3XXX_L2C_BASE_VIRT                  0xFFF27000
+
+#define CNS3XXX_PCIE0_MEM_BASE                 0xA0000000      /* PCIe Port 0 IO/Memory Space */
+#define CNS3XXX_PCIE0_MEM_BASE_VIRT            0xE0000000
+
+#define CNS3XXX_PCIE0_HOST_BASE                        0xAB000000      /* PCIe Port 0 RC Base */
+#define CNS3XXX_PCIE0_HOST_BASE_VIRT           0xE1000000
+
+#define CNS3XXX_PCIE0_IO_BASE                  0xAC000000      /* PCIe Port 0 */
+#define CNS3XXX_PCIE0_IO_BASE_VIRT             0xE2000000
+
+#define CNS3XXX_PCIE0_CFG0_BASE                        0xAD000000      /* PCIe Port 0 CFG Type 0 */
+#define CNS3XXX_PCIE0_CFG0_BASE_VIRT           0xE3000000
+
+#define CNS3XXX_PCIE0_CFG1_BASE                        0xAE000000      /* PCIe Port 0 CFG Type 1 */
+#define CNS3XXX_PCIE0_CFG1_BASE_VIRT           0xE4000000
+
+#define CNS3XXX_PCIE0_MSG_BASE                 0xAF000000      /* PCIe Port 0 Message Space */
+#define CNS3XXX_PCIE0_MSG_BASE_VIRT            0xE5000000
+
+#define CNS3XXX_PCIE1_MEM_BASE                 0xB0000000      /* PCIe Port 1 IO/Memory Space */
+#define CNS3XXX_PCIE1_MEM_BASE_VIRT            0xE8000000
+
+#define CNS3XXX_PCIE1_HOST_BASE                        0xBB000000      /* PCIe Port 1 RC Base */
+#define CNS3XXX_PCIE1_HOST_BASE_VIRT           0xE9000000
+
+#define CNS3XXX_PCIE1_IO_BASE                  0xBC000000      /* PCIe Port 1 */
+#define CNS3XXX_PCIE1_IO_BASE_VIRT             0xEA000000
+
+#define CNS3XXX_PCIE1_CFG0_BASE                        0xBD000000      /* PCIe Port 1 CFG Type 0 */
+#define CNS3XXX_PCIE1_CFG0_BASE_VIRT           0xEB000000
+
+#define CNS3XXX_PCIE1_CFG1_BASE                        0xBE000000      /* PCIe Port 1 CFG Type 1 */
+#define CNS3XXX_PCIE1_CFG1_BASE_VIRT           0xEC000000
+
+#define CNS3XXX_PCIE1_MSG_BASE                 0xBF000000      /* PCIe Port 1 Message Space */
+#define CNS3XXX_PCIE1_MSG_BASE_VIRT            0xED000000
+
+/*
+ * Testchip peripheral and fpga gic regions
+ */
+#define CNS3XXX_TC11MP_SCU_BASE                        0x90000000      /* IRQ, Test chip */
+#define CNS3XXX_TC11MP_SCU_BASE_VIRT           0xFF000000
+
+#define CNS3XXX_TC11MP_GIC_CPU_BASE            0x90000100      /* Test chip interrupt controller CPU interface */
+#define CNS3XXX_TC11MP_GIC_CPU_BASE_VIRT       0xFF000100
+
+#define CNS3XXX_TC11MP_TWD_BASE                        0x90000600
+#define CNS3XXX_TC11MP_TWD_BASE_VIRT           0xFF000600
+
+#define CNS3XXX_TC11MP_GIC_DIST_BASE           0x90001000      /* Test chip interrupt controller distributor */
+#define CNS3XXX_TC11MP_GIC_DIST_BASE_VIRT      0xFF001000
+
+#define CNS3XXX_TC11MP_L220_BASE               0x92002000      /* L220 registers */
+#define CNS3XXX_TC11MP_L220_BASE_VIRT          0xFF002000
+
+/*
+ * Misc block
+ */
+#define MISC_MEM_MAP(offs) (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + (offs))
+#define MISC_MEM_MAP_VALUE(offset) (*((volatile unsigned int *)(CNS3XXX_MISC_BASE_VIRT + (offset))))
+
+#define MISC_MEMORY_REMAP_REG                  MISC_MEM_MAP_VALUE(0x00)
+#define MISC_CHIP_CONFIG_REG                   MISC_MEM_MAP_VALUE(0x04)
+#define MISC_DEBUG_PROBE_DATA_REG              MISC_MEM_MAP_VALUE(0x08)
+#define MISC_DEBUG_PROBE_SELECTION_REG         MISC_MEM_MAP_VALUE(0x0C)
+#define MISC_IO_PIN_FUNC_SELECTION_REG         MISC_MEM_MAP_VALUE(0x10)
+#define MISC_GPIOA_PIN_ENABLE_REG              MISC_MEM_MAP_VALUE(0x14)
+#define MISC_GPIOB_PIN_ENABLE_REG              MISC_MEM_MAP_VALUE(0x18)
+#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_A      MISC_MEM_MAP_VALUE(0x1C)
+#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B      MISC_MEM_MAP_VALUE(0x20)
+#define MISC_GPIOA_15_0_PULL_CTRL_REG          MISC_MEM_MAP_VALUE(0x24)
+#define MISC_GPIOA_16_31_PULL_CTRL_REG         MISC_MEM_MAP_VALUE(0x28)
+#define MISC_GPIOB_15_0_PULL_CTRL_REG          MISC_MEM_MAP_VALUE(0x2C)
+#define MISC_GPIOB_16_31_PULL_CTRL_REG         MISC_MEM_MAP_VALUE(0x30)
+#define MISC_IO_PULL_CTRL_REG                  MISC_MEM_MAP_VALUE(0x34)
+#define MISC_E_FUSE_31_0_REG                   MISC_MEM_MAP_VALUE(0x40)
+#define MISC_E_FUSE_63_32_REG                  MISC_MEM_MAP_VALUE(0x44)
+#define MISC_E_FUSE_95_64_REG                  MISC_MEM_MAP_VALUE(0x48)
+#define MISC_E_FUSE_127_96_REG                 MISC_MEM_MAP_VALUE(0x4C)
+#define MISC_SOFTWARE_TEST_1_REG               MISC_MEM_MAP_VALUE(0x50)
+#define MISC_SOFTWARE_TEST_2_REG               MISC_MEM_MAP_VALUE(0x54)
+
+#define MISC_SATA_POWER_MODE                   MISC_MEM_MAP_VALUE(0x310)
+
+#define MISC_USB_CFG_REG                       MISC_MEM_MAP_VALUE(0x800)
+#define MISC_USB_STS_REG                       MISC_MEM_MAP_VALUE(0x804)
+#define MISC_USBPHY00_CFG_REG                  MISC_MEM_MAP_VALUE(0x808)
+#define MISC_USBPHY01_CFG_REG                  MISC_MEM_MAP_VALUE(0x80c)
+#define MISC_USBPHY10_CFG_REG                  MISC_MEM_MAP_VALUE(0x810)
+#define MISC_USBPHY11_CFG_REG                  MISC_MEM_MAP_VALUE(0x814)
+
+#define MISC_PCIEPHY_CMCTL(x)                  MISC_MEM_MAP(0x900 + (x) * 0x004)
+#define MISC_PCIEPHY_CTL(x)                    MISC_MEM_MAP(0x940 + (x) * 0x100)
+#define MISC_PCIE_AXIS_AWMISC(x)               MISC_MEM_MAP(0x944 + (x) * 0x100)
+#define MISC_PCIE_AXIS_ARMISC(x)               MISC_MEM_MAP(0x948 + (x) * 0x100)
+#define MISC_PCIE_AXIS_RMISC(x)                        MISC_MEM_MAP(0x94C + (x) * 0x100)
+#define MISC_PCIE_AXIS_BMISC(x)                        MISC_MEM_MAP(0x950 + (x) * 0x100)
+#define MISC_PCIE_AXIM_RMISC(x)                        MISC_MEM_MAP(0x954 + (x) * 0x100)
+#define MISC_PCIE_AXIM_BMISC(x)                        MISC_MEM_MAP(0x958 + (x) * 0x100)
+#define MISC_PCIE_CTRL(x)                      MISC_MEM_MAP(0x95C + (x) * 0x100)
+#define MISC_PCIE_PM_DEBUG(x)                  MISC_MEM_MAP(0x960 + (x) * 0x100)
+#define MISC_PCIE_RFC_DEBUG(x)                 MISC_MEM_MAP(0x964 + (x) * 0x100)
+#define MISC_PCIE_CXPL_DEBUGL(x)               MISC_MEM_MAP(0x968 + (x) * 0x100)
+#define MISC_PCIE_CXPL_DEBUGH(x)               MISC_MEM_MAP(0x96C + (x) * 0x100)
+#define MISC_PCIE_DIAG_DEBUGH(x)               MISC_MEM_MAP(0x970 + (x) * 0x100)
+#define MISC_PCIE_W1CLR(x)                     MISC_MEM_MAP(0x974 + (x) * 0x100)
+#define MISC_PCIE_INT_MASK(x)                  MISC_MEM_MAP(0x978 + (x) * 0x100)
+#define MISC_PCIE_INT_STATUS(x)                        MISC_MEM_MAP(0x97C + (x) * 0x100)
+
+/*
+ * Power management and clock control
+ */
+#define PMU_REG_VALUE(offset) (*((volatile unsigned int *)(CNS3XXX_PM_BASE_VIRT + (offset))))
+
+#define PM_CLK_GATE_REG                                        PMU_REG_VALUE(0x000)
+#define PM_SOFT_RST_REG                                        PMU_REG_VALUE(0x004)
+#define PM_HS_CFG_REG                                  PMU_REG_VALUE(0x008)
+#define PM_CACTIVE_STA_REG                             PMU_REG_VALUE(0x00C)
+#define PM_PWR_STA_REG                                 PMU_REG_VALUE(0x010)
+#define PM_CLK_CTRL_REG                                        PMU_REG_VALUE(0x014)
+#define PM_PLL_LCD_I2S_CTRL_REG                                PMU_REG_VALUE(0x018)
+#define PM_PLL_HM_PD_CTRL_REG                          PMU_REG_VALUE(0x01C)
+#define PM_REGULAT_CTRL_REG                            PMU_REG_VALUE(0x020)
+#define PM_WDT_CTRL_REG                                        PMU_REG_VALUE(0x024)
+#define PM_WU_CTRL0_REG                                        PMU_REG_VALUE(0x028)
+#define PM_WU_CTRL1_REG                                        PMU_REG_VALUE(0x02C)
+#define PM_CSR_REG                                     PMU_REG_VALUE(0x030)
+
+/* PM_CLK_GATE_REG */
+#define PM_CLK_GATE_REG_OFFSET_SDIO                    (25)
+#define PM_CLK_GATE_REG_OFFSET_GPU                     (24)
+#define PM_CLK_GATE_REG_OFFSET_CIM                     (23)
+#define PM_CLK_GATE_REG_OFFSET_LCDC                    (22)
+#define PM_CLK_GATE_REG_OFFSET_I2S                     (21)
+#define PM_CLK_GATE_REG_OFFSET_RAID                    (20)
+#define PM_CLK_GATE_REG_OFFSET_SATA                    (19)
+#define PM_CLK_GATE_REG_OFFSET_PCIE(x)                 (17 + (x))
+#define PM_CLK_GATE_REG_OFFSET_USB_HOST                        (16)
+#define PM_CLK_GATE_REG_OFFSET_USB_OTG                 (15)
+#define PM_CLK_GATE_REG_OFFSET_TIMER                   (14)
+#define PM_CLK_GATE_REG_OFFSET_CRYPTO                  (13)
+#define PM_CLK_GATE_REG_OFFSET_HCIE                    (12)
+#define PM_CLK_GATE_REG_OFFSET_SWITCH                  (11)
+#define PM_CLK_GATE_REG_OFFSET_GPIO                    (10)
+#define PM_CLK_GATE_REG_OFFSET_UART3                   (9)
+#define PM_CLK_GATE_REG_OFFSET_UART2                   (8)
+#define PM_CLK_GATE_REG_OFFSET_UART1                   (7)
+#define PM_CLK_GATE_REG_OFFSET_RTC                     (5)
+#define PM_CLK_GATE_REG_OFFSET_GDMA                    (4)
+#define PM_CLK_GATE_REG_OFFSET_SPI_PCM_I2C             (3)
+#define PM_CLK_GATE_REG_OFFSET_SMC_NFI                 (1)
+#define PM_CLK_GATE_REG_MASK                           (0x03FFFFBA)
+
+/* PM_SOFT_RST_REG */
+#define PM_SOFT_RST_REG_OFFST_WARM_RST_FLAG            (31)
+#define PM_SOFT_RST_REG_OFFST_CPU1                     (29)
+#define PM_SOFT_RST_REG_OFFST_CPU0                     (28)
+#define PM_SOFT_RST_REG_OFFST_SDIO                     (25)
+#define PM_SOFT_RST_REG_OFFST_GPU                      (24)
+#define PM_SOFT_RST_REG_OFFST_CIM                      (23)
+#define PM_SOFT_RST_REG_OFFST_LCDC                     (22)
+#define PM_SOFT_RST_REG_OFFST_I2S                      (21)
+#define PM_SOFT_RST_REG_OFFST_RAID                     (20)
+#define PM_SOFT_RST_REG_OFFST_SATA                     (19)
+#define PM_SOFT_RST_REG_OFFST_PCIE(x)                  (17 + (x))
+#define PM_SOFT_RST_REG_OFFST_USB_HOST                 (16)
+#define PM_SOFT_RST_REG_OFFST_USB_OTG                  (15)
+#define PM_SOFT_RST_REG_OFFST_TIMER                    (14)
+#define PM_SOFT_RST_REG_OFFST_CRYPTO                   (13)
+#define PM_SOFT_RST_REG_OFFST_HCIE                     (12)
+#define PM_SOFT_RST_REG_OFFST_SWITCH                   (11)
+#define PM_SOFT_RST_REG_OFFST_GPIO                     (10)
+#define PM_SOFT_RST_REG_OFFST_UART3                    (9)
+#define PM_SOFT_RST_REG_OFFST_UART2                    (8)
+#define PM_SOFT_RST_REG_OFFST_UART1                    (7)
+#define PM_SOFT_RST_REG_OFFST_RTC                      (5)
+#define PM_SOFT_RST_REG_OFFST_GDMA                     (4)
+#define PM_SOFT_RST_REG_OFFST_SPI_PCM_I2C              (3)
+#define PM_SOFT_RST_REG_OFFST_DMC                      (2)
+#define PM_SOFT_RST_REG_OFFST_SMC_NFI                  (1)
+#define PM_SOFT_RST_REG_OFFST_GLOBAL                   (0)
+#define PM_SOFT_RST_REG_MASK                           (0xF3FFFFBF)
+
+/* PMHS_CFG_REG */
+#define PM_HS_CFG_REG_OFFSET_SDIO                      (25)
+#define PM_HS_CFG_REG_OFFSET_GPU                       (24)
+#define PM_HS_CFG_REG_OFFSET_CIM                       (23)
+#define PM_HS_CFG_REG_OFFSET_LCDC                      (22)
+#define PM_HS_CFG_REG_OFFSET_I2S                       (21)
+#define PM_HS_CFG_REG_OFFSET_RAID                      (20)
+#define PM_HS_CFG_REG_OFFSET_SATA                      (19)
+#define PM_HS_CFG_REG_OFFSET_PCIE1                     (18)
+#define PM_HS_CFG_REG_OFFSET_PCIE0                     (17)
+#define PM_HS_CFG_REG_OFFSET_USB_HOST                  (16)
+#define PM_HS_CFG_REG_OFFSET_USB_OTG                   (15)
+#define PM_HS_CFG_REG_OFFSET_TIMER                     (14)
+#define PM_HS_CFG_REG_OFFSET_CRYPTO                    (13)
+#define PM_HS_CFG_REG_OFFSET_HCIE                      (12)
+#define PM_HS_CFG_REG_OFFSET_SWITCH                    (11)
+#define PM_HS_CFG_REG_OFFSET_GPIO                      (10)
+#define PM_HS_CFG_REG_OFFSET_UART3                     (9)
+#define PM_HS_CFG_REG_OFFSET_UART2                     (8)
+#define PM_HS_CFG_REG_OFFSET_UART1                     (7)
+#define PM_HS_CFG_REG_OFFSET_RTC                       (5)
+#define PM_HS_CFG_REG_OFFSET_GDMA                      (4)
+#define PM_HS_CFG_REG_OFFSET_SPI_PCM_I2S               (3)
+#define PM_HS_CFG_REG_OFFSET_DMC                       (2)
+#define PM_HS_CFG_REG_OFFSET_SMC_NFI                   (1)
+#define PM_HS_CFG_REG_MASK                             (0x03FFFFBE)
+#define PM_HS_CFG_REG_MASK_SUPPORT                     (0x01100806)
+
+/* PM_CACTIVE_STA_REG */
+#define PM_CACTIVE_STA_REG_OFFSET_SDIO                 (25)
+#define PM_CACTIVE_STA_REG_OFFSET_GPU                  (24)
+#define PM_CACTIVE_STA_REG_OFFSET_CIM                  (23)
+#define PM_CACTIVE_STA_REG_OFFSET_LCDC                 (22)
+#define PM_CACTIVE_STA_REG_OFFSET_I2S                  (21)
+#define PM_CACTIVE_STA_REG_OFFSET_RAID                 (20)
+#define PM_CACTIVE_STA_REG_OFFSET_SATA                 (19)
+#define PM_CACTIVE_STA_REG_OFFSET_PCIE1                        (18)
+#define PM_CACTIVE_STA_REG_OFFSET_PCIE0                        (17)
+#define PM_CACTIVE_STA_REG_OFFSET_USB_HOST             (16)
+#define PM_CACTIVE_STA_REG_OFFSET_USB_OTG              (15)
+#define PM_CACTIVE_STA_REG_OFFSET_TIMER                        (14)
+#define PM_CACTIVE_STA_REG_OFFSET_CRYPTO               (13)
+#define PM_CACTIVE_STA_REG_OFFSET_HCIE                 (12)
+#define PM_CACTIVE_STA_REG_OFFSET_SWITCH               (11)
+#define PM_CACTIVE_STA_REG_OFFSET_GPIO                 (10)
+#define PM_CACTIVE_STA_REG_OFFSET_UART3                        (9)
+#define PM_CACTIVE_STA_REG_OFFSET_UART2                        (8)
+#define PM_CACTIVE_STA_REG_OFFSET_UART1                        (7)
+#define PM_CACTIVE_STA_REG_OFFSET_RTC                  (5)
+#define PM_CACTIVE_STA_REG_OFFSET_GDMA                 (4)
+#define PM_CACTIVE_STA_REG_OFFSET_SPI_PCM_I2S          (3)
+#define PM_CACTIVE_STA_REG_OFFSET_DMC                  (2)
+#define PM_CACTIVE_STA_REG_OFFSET_SMC_NFI              (1)
+#define PM_CACTIVE_STA_REG_MASK                                (0x03FFFFBE)
+
+/* PM_PWR_STA_REG */
+#define PM_PWR_STA_REG_REG_OFFSET_SDIO                 (25)
+#define PM_PWR_STA_REG_REG_OFFSET_GPU                  (24)
+#define PM_PWR_STA_REG_REG_OFFSET_CIM                  (23)
+#define PM_PWR_STA_REG_REG_OFFSET_LCDC                 (22)
+#define PM_PWR_STA_REG_REG_OFFSET_I2S                  (21)
+#define PM_PWR_STA_REG_REG_OFFSET_RAID                 (20)
+#define PM_PWR_STA_REG_REG_OFFSET_SATA                 (19)
+#define PM_PWR_STA_REG_REG_OFFSET_PCIE1                        (18)
+#define PM_PWR_STA_REG_REG_OFFSET_PCIE0                        (17)
+#define PM_PWR_STA_REG_REG_OFFSET_USB_HOST             (16)
+#define PM_PWR_STA_REG_REG_OFFSET_USB_OTG              (15)
+#define PM_PWR_STA_REG_REG_OFFSET_TIMER                        (14)
+#define PM_PWR_STA_REG_REG_OFFSET_CRYPTO               (13)
+#define PM_PWR_STA_REG_REG_OFFSET_HCIE                 (12)
+#define PM_PWR_STA_REG_REG_OFFSET_SWITCH               (11)
+#define PM_PWR_STA_REG_REG_OFFSET_GPIO                 (10)
+#define PM_PWR_STA_REG_REG_OFFSET_UART3                        (9)
+#define PM_PWR_STA_REG_REG_OFFSET_UART2                        (8)
+#define PM_PWR_STA_REG_REG_OFFSET_UART1                        (7)
+#define PM_PWR_STA_REG_REG_OFFSET_RTC                  (5)
+#define PM_PWR_STA_REG_REG_OFFSET_GDMA                 (4)
+#define PM_PWR_STA_REG_REG_OFFSET_SPI_PCM_I2S          (3)
+#define PM_PWR_STA_REG_REG_OFFSET_DMC                  (2)
+#define PM_PWR_STA_REG_REG_OFFSET_SMC_NFI              (1)
+#define PM_PWR_STA_REG_REG_MASK                                (0x03FFFFBE)
+
+/* PM_CLK_CTRL_REG */
+#define PM_CLK_CTRL_REG_OFFSET_I2S_MCLK                        (31)
+#define PM_CLK_CTRL_REG_OFFSET_DDR2_CHG_EN             (30)
+#define PM_CLK_CTRL_REG_OFFSET_PCIE_REF1_EN            (29)
+#define PM_CLK_CTRL_REG_OFFSET_PCIE_REF0_EN            (28)
+#define PM_CLK_CTRL_REG_OFFSET_TIMER_SIM_MODE          (27)
+#define PM_CLK_CTRL_REG_OFFSET_I2SCLK_DIV              (24)
+#define PM_CLK_CTRL_REG_OFFSET_I2SCLK_SEL              (22)
+#define PM_CLK_CTRL_REG_OFFSET_CLKOUT_DIV              (20)
+#define PM_CLK_CTRL_REG_OFFSET_CLKOUT_SEL              (16)
+#define PM_CLK_CTRL_REG_OFFSET_MDC_DIV                 (14)
+#define PM_CLK_CTRL_REG_OFFSET_CRYPTO_CLK_SEL          (12)
+#define PM_CLK_CTRL_REG_OFFSET_CPU_PWR_MODE            (9)
+#define PM_CLK_CTRL_REG_OFFSET_PLL_DDR2_SEL            (7)
+#define PM_CLK_CTRL_REG_OFFSET_DIV_IMMEDIATE           (6)
+#define PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV             (4)
+#define PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL             (0)
+
+#define PM_CPU_CLK_DIV(DIV) { \
+       PM_CLK_CTRL_REG &= ~((0x3) << PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV); \
+       PM_CLK_CTRL_REG |= (((DIV)&0x3) << PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV); \
+}
+
+#define PM_PLL_CPU_SEL(CPU) { \
+       PM_CLK_CTRL_REG &= ~((0xF) << PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL); \
+       PM_CLK_CTRL_REG |= (((CPU)&0xF) << PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL); \
+}
+
+/* PM_PLL_LCD_I2S_CTRL_REG */
+#define PM_PLL_LCD_I2S_CTRL_REG_OFFSET_MCLK_SMC_DIV    (22)
+#define PM_PLL_LCD_I2S_CTRL_REG_OFFSET_R_SEL           (17)
+#define PM_PLL_LCD_I2S_CTRL_REG_OFFSET_PLL_LCD_P       (11)
+#define PM_PLL_LCD_I2S_CTRL_REG_OFFSET_PLL_LCD_M       (3)
+#define PM_PLL_LCD_I2S_CTRL_REG_OFFSET_PLL_LCD_S       (0)
+
+/* PM_PLL_HM_PD_CTRL_REG */
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY1         (11)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY0         (10)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_I2SCD         (6)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_I2S           (5)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_LCD           (4)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_USB           (3)
+#define PM_PLL_HM_PD_CTRL_REG_OFFSET_PLL_RGMII         (2)
+#define PM_PLL_HM_PD_CTRL_REG_MASK                     (0x00000C7C)
+
+/* PM_WDT_CTRL_REG */
+#define PM_WDT_CTRL_REG_OFFSET_RESET_CPU_ONLY          (0)
+
+/* PM_CSR_REG - Clock Scaling Register*/
+#define PM_CSR_REG_OFFSET_CSR_EN                       (30)
+#define PM_CSR_REG_OFFSET_CSR_NUM                      (0)
+
+#define CNS3XXX_PWR_CLK_EN(BLOCK) (0x1<<PM_CLK_GATE_REG_OFFSET_##BLOCK)
+
+/* Software reset*/
+#define CNS3XXX_PWR_SOFTWARE_RST(BLOCK) (0x1<<PM_SOFT_RST_REG_OFFST_##BLOCK)
+
+/*
+ * CNS3XXX support several power saving mode as following,
+ * DFS, IDLE, HALT, DOZE, SLEEP, Hibernate
+ */
+#define CNS3XXX_PWR_CPU_MODE_DFS                       (0)
+#define CNS3XXX_PWR_CPU_MODE_IDLE                      (1)
+#define CNS3XXX_PWR_CPU_MODE_HALT                      (2)
+#define CNS3XXX_PWR_CPU_MODE_DOZE                      (3)
+#define CNS3XXX_PWR_CPU_MODE_SLEEP                     (4)
+#define CNS3XXX_PWR_CPU_MODE_HIBERNATE                 (5)
+
+#define CNS3XXX_PWR_PLL(BLOCK) (0x1<<PM_PLL_HM_PD_CTRL_REG_OFFSET_##BLOCK)
+#define CNS3XXX_PWR_PLL_ALL    PM_PLL_HM_PD_CTRL_REG_MASK
+
+/* Change CPU frequency and divider */
+#define CNS3XXX_PWR_PLL_CPU_300MHZ                     (0)
+#define CNS3XXX_PWR_PLL_CPU_333MHZ                     (1)
+#define CNS3XXX_PWR_PLL_CPU_366MHZ                     (2)
+#define CNS3XXX_PWR_PLL_CPU_400MHZ                     (3)
+#define CNS3XXX_PWR_PLL_CPU_433MHZ                     (4)
+#define CNS3XXX_PWR_PLL_CPU_466MHZ                     (5)
+#define CNS3XXX_PWR_PLL_CPU_500MHZ                     (6)
+#define CNS3XXX_PWR_PLL_CPU_533MHZ                     (7)
+#define CNS3XXX_PWR_PLL_CPU_566MHZ                     (8)
+#define CNS3XXX_PWR_PLL_CPU_600MHZ                     (9)
+#define CNS3XXX_PWR_PLL_CPU_633MHZ                     (10)
+#define CNS3XXX_PWR_PLL_CPU_666MHZ                     (11)
+#define CNS3XXX_PWR_PLL_CPU_700MHZ                     (12)
+
+#define CNS3XXX_PWR_CPU_CLK_DIV_BY1                    (0)
+#define CNS3XXX_PWR_CPU_CLK_DIV_BY2                    (1)
+#define CNS3XXX_PWR_CPU_CLK_DIV_BY4                    (2)
+
+/* Change DDR2 frequency */
+#define CNS3XXX_PWR_PLL_DDR2_200MHZ                    (0)
+#define CNS3XXX_PWR_PLL_DDR2_266MHZ                    (1)
+#define CNS3XXX_PWR_PLL_DDR2_333MHZ                    (2)
+#define CNS3XXX_PWR_PLL_DDR2_400MHZ                    (3)
+
+void cns3xxx_pwr_soft_rst(unsigned int block);
+void cns3xxx_pwr_clk_en(unsigned int block);
+int cns3xxx_cpu_clock(void);
+
+/*
+ * ARM11 MPCore interrupt sources (primary GIC)
+ */
+#define IRQ_CNS3XXX_PMU                        (IRQ_TC11MP_GIC_START + 0)
+#define IRQ_CNS3XXX_SDIO               (IRQ_TC11MP_GIC_START + 1)
+#define IRQ_CNS3XXX_L2CC               (IRQ_TC11MP_GIC_START + 2)
+#define IRQ_CNS3XXX_RTC                        (IRQ_TC11MP_GIC_START + 3)
+#define IRQ_CNS3XXX_I2S                        (IRQ_TC11MP_GIC_START + 4)
+#define IRQ_CNS3XXX_PCM                        (IRQ_TC11MP_GIC_START + 5)
+#define IRQ_CNS3XXX_SPI                        (IRQ_TC11MP_GIC_START + 6)
+#define IRQ_CNS3XXX_I2C                        (IRQ_TC11MP_GIC_START + 7)
+#define IRQ_CNS3XXX_CIM                        (IRQ_TC11MP_GIC_START + 8)
+#define IRQ_CNS3XXX_GPU                        (IRQ_TC11MP_GIC_START + 9)
+#define IRQ_CNS3XXX_LCD                        (IRQ_TC11MP_GIC_START + 10)
+#define IRQ_CNS3XXX_GPIOA              (IRQ_TC11MP_GIC_START + 11)
+#define IRQ_CNS3XXX_GPIOB              (IRQ_TC11MP_GIC_START + 12)
+#define IRQ_CNS3XXX_UART0              (IRQ_TC11MP_GIC_START + 13)
+#define IRQ_CNS3XXX_UART1              (IRQ_TC11MP_GIC_START + 14)
+#define IRQ_CNS3XXX_UART2              (IRQ_TC11MP_GIC_START + 15)
+#define IRQ_CNS3XXX_ARM11              (IRQ_TC11MP_GIC_START + 16)
+
+#define IRQ_CNS3XXX_SW_STATUS          (IRQ_TC11MP_GIC_START + 17)
+#define IRQ_CNS3XXX_SW_R0TXC           (IRQ_TC11MP_GIC_START + 18)
+#define IRQ_CNS3XXX_SW_R0RXC           (IRQ_TC11MP_GIC_START + 19)
+#define IRQ_CNS3XXX_SW_R0QE            (IRQ_TC11MP_GIC_START + 20)
+#define IRQ_CNS3XXX_SW_R0QF            (IRQ_TC11MP_GIC_START + 21)
+#define IRQ_CNS3XXX_SW_R1TXC           (IRQ_TC11MP_GIC_START + 22)
+#define IRQ_CNS3XXX_SW_R1RXC           (IRQ_TC11MP_GIC_START + 23)
+#define IRQ_CNS3XXX_SW_R1QE            (IRQ_TC11MP_GIC_START + 24)
+#define IRQ_CNS3XXX_SW_R1QF            (IRQ_TC11MP_GIC_START + 25)
+#define IRQ_CNS3XXX_SW_PPE             (IRQ_TC11MP_GIC_START + 26)
+
+#define IRQ_CNS3XXX_CRYPTO             (IRQ_TC11MP_GIC_START + 27)
+#define IRQ_CNS3XXX_HCIE               (IRQ_TC11MP_GIC_START + 28)
+#define IRQ_CNS3XXX_PCIE0_DEVICE       (IRQ_TC11MP_GIC_START + 29)
+#define IRQ_CNS3XXX_PCIE1_DEVICE       (IRQ_TC11MP_GIC_START + 30)
+#define IRQ_CNS3XXX_USB_OTG            (IRQ_TC11MP_GIC_START + 31)
+#define IRQ_CNS3XXX_USB_EHCI           (IRQ_TC11MP_GIC_START + 32)
+#define IRQ_CNS3XXX_SATA               (IRQ_TC11MP_GIC_START + 33)
+#define IRQ_CNS3XXX_RAID               (IRQ_TC11MP_GIC_START + 34)
+#define IRQ_CNS3XXX_SMC                        (IRQ_TC11MP_GIC_START + 35)
+
+#define IRQ_CNS3XXX_DMAC_ABORT         (IRQ_TC11MP_GIC_START + 36)
+#define IRQ_CNS3XXX_DMAC0              (IRQ_TC11MP_GIC_START + 37)
+#define IRQ_CNS3XXX_DMAC1              (IRQ_TC11MP_GIC_START + 38)
+#define IRQ_CNS3XXX_DMAC2              (IRQ_TC11MP_GIC_START + 39)
+#define IRQ_CNS3XXX_DMAC3              (IRQ_TC11MP_GIC_START + 40)
+#define IRQ_CNS3XXX_DMAC4              (IRQ_TC11MP_GIC_START + 41)
+#define IRQ_CNS3XXX_DMAC5              (IRQ_TC11MP_GIC_START + 42)
+#define IRQ_CNS3XXX_DMAC6              (IRQ_TC11MP_GIC_START + 43)
+#define IRQ_CNS3XXX_DMAC7              (IRQ_TC11MP_GIC_START + 44)
+#define IRQ_CNS3XXX_DMAC8              (IRQ_TC11MP_GIC_START + 45)
+#define IRQ_CNS3XXX_DMAC9              (IRQ_TC11MP_GIC_START + 46)
+#define IRQ_CNS3XXX_DMAC10             (IRQ_TC11MP_GIC_START + 47)
+#define IRQ_CNS3XXX_DMAC11             (IRQ_TC11MP_GIC_START + 48)
+#define IRQ_CNS3XXX_DMAC12             (IRQ_TC11MP_GIC_START + 49)
+#define IRQ_CNS3XXX_DMAC13             (IRQ_TC11MP_GIC_START + 50)
+#define IRQ_CNS3XXX_DMAC14             (IRQ_TC11MP_GIC_START + 51)
+#define IRQ_CNS3XXX_DMAC15             (IRQ_TC11MP_GIC_START + 52)
+#define IRQ_CNS3XXX_DMAC16             (IRQ_TC11MP_GIC_START + 53)
+#define IRQ_CNS3XXX_DMAC17             (IRQ_TC11MP_GIC_START + 54)
+
+#define IRQ_CNS3XXX_PCIE0_RC           (IRQ_TC11MP_GIC_START + 55)
+#define IRQ_CNS3XXX_PCIE1_RC           (IRQ_TC11MP_GIC_START + 56)
+#define IRQ_CNS3XXX_TIMER0             (IRQ_TC11MP_GIC_START + 57)
+#define IRQ_CNS3XXX_TIMER1             (IRQ_TC11MP_GIC_START + 58)
+#define IRQ_CNS3XXX_USB_OHCI           (IRQ_TC11MP_GIC_START + 59)
+#define IRQ_CNS3XXX_TIMER2             (IRQ_TC11MP_GIC_START + 60)
+#define IRQ_CNS3XXX_EXTERNAL_PIN0      (IRQ_TC11MP_GIC_START + 61)
+#define IRQ_CNS3XXX_EXTERNAL_PIN1      (IRQ_TC11MP_GIC_START + 62)
+#define IRQ_CNS3XXX_EXTERNAL_PIN2      (IRQ_TC11MP_GIC_START + 63)
+
+#define NR_IRQS_CNS3XXX                        (IRQ_TC11MP_GIC_START + 64)
+
+#if !defined(NR_IRQS) || (NR_IRQS < NR_IRQS_CNS3XXX)
+#undef NR_IRQS
+#define NR_IRQS                                NR_IRQS_CNS3XXX
+#endif
+
+#endif /* __MACH_BOARD_CNS3XXX_H */
diff --git a/arch/arm/mach-cns3xxx/include/mach/debug-macro.S b/arch/arm/mach-cns3xxx/include/mach/debug-macro.S
new file mode 100644 (file)
index 0000000..d16ce7e
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * Debugging macro include header
+ *
+ * Copyright 1994-1999 Russell King
+ * Copyright 2008 Cavium Networks
+ * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+               .macro  addruart,rx
+               mrc     p15, 0, \rx, c1, c0
+               tst     \rx, #1                 @ MMU enabled?
+               moveq   \rx,      #0x10000000
+               movne   \rx,      #0xf0000000   @ virtual base
+               orr     \rx, \rx, #0x00009000
+               .endm
+
+#include <asm/hardware/debug-pl01x.S>
diff --git a/arch/arm/mach-cns3xxx/include/mach/entry-macro.S b/arch/arm/mach-cns3xxx/include/mach/entry-macro.S
new file mode 100644 (file)
index 0000000..5e1c554
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Low-level IRQ helper macros for Cavium Networks platforms
+ *
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <mach/hardware.h>
+#include <asm/hardware/gic.h>
+
+               .macro  disable_fiq
+               .endm
+
+               .macro  get_irqnr_preamble, base, tmp
+               ldr     \base, =gic_cpu_base_addr
+               ldr     \base, [\base]
+               .endm
+
+               .macro  arch_ret_to_user, tmp1, tmp2
+               .endm
+
+               /*
+                * The interrupt numbering scheme is defined in the
+                * interrupt controller spec.  To wit:
+                *
+                * Interrupts 0-15 are IPI
+                * 16-28 are reserved
+                * 29-31 are local.  We allow 30 to be used for the watchdog.
+                * 32-1020 are global
+                * 1021-1022 are reserved
+                * 1023 is "spurious" (no interrupt)
+                *
+                * For now, we ignore all local interrupts so only return an interrupt if it's
+                * between 30 and 1020.  The test_for_ipi routine below will pick up on IPIs.
+                *
+                * A simple read from the controller will tell us the number of the highest
+                 * priority enabled interrupt.  We then just need to check whether it is in the
+                * valid range for an IRQ (30-1020 inclusive).
+                */
+
+               .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+
+               ldr     \irqstat, [\base, #GIC_CPU_INTACK] /* bits 12-10 = src CPU, 9-0 = int # */
+
+               ldr     \tmp, =1021
+
+               bic     \irqnr, \irqstat, #0x1c00
+
+               cmp     \irqnr, #29
+               cmpcc   \irqnr, \irqnr
+               cmpne   \irqnr, \tmp
+               cmpcs   \irqnr, \irqnr
+
+               .endm
+
+               /* We assume that irqstat (the raw value of the IRQ acknowledge
+                * register) is preserved from the macro above.
+                * If there is an IPI, we immediately signal end of interrupt on the
+                * controller, since this requires the original irqstat value which
+                * we won't easily be able to recreate later.
+                */
+
+               .macro test_for_ipi, irqnr, irqstat, base, tmp
+               bic     \irqnr, \irqstat, #0x1c00
+               cmp     \irqnr, #16
+               strcc   \irqstat, [\base, #GIC_CPU_EOI]
+               cmpcs   \irqnr, \irqnr
+               .endm
+
+               /* As above, this assumes that irqstat and base are preserved.. */
+
+               .macro test_for_ltirq, irqnr, irqstat, base, tmp
+               bic     \irqnr, \irqstat, #0x1c00
+               mov     \tmp, #0
+               cmp     \irqnr, #29
+               moveq   \tmp, #1
+               streq   \irqstat, [\base, #GIC_CPU_EOI]
+               cmp     \tmp, #0
+               .endm
diff --git a/arch/arm/mach-cns3xxx/include/mach/hardware.h b/arch/arm/mach-cns3xxx/include/mach/hardware.h
new file mode 100644 (file)
index 0000000..57e0983
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * This file contains the hardware definitions of the Cavium Networks boards.
+ *
+ * Copyright 2003 ARM Limited.
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_HARDWARE_H
+#define __MACH_HARDWARE_H
+
+#include <asm/sizes.h>
+
+/* macro to get at IO space when running virtually */
+#define PCIBIOS_MIN_IO         0x00000000
+#define PCIBIOS_MIN_MEM                0x00000000
+#define pcibios_assign_all_busses()    1
+
+#endif
diff --git a/arch/arm/mach-cns3xxx/include/mach/io.h b/arch/arm/mach-cns3xxx/include/mach/io.h
new file mode 100644 (file)
index 0000000..33b6fc1
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2008 Cavium Networks
+ * Copyright 2003 ARM Limited
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+#ifndef __MACH_IO_H
+#define __MACH_IO_H
+
+#define IO_SPACE_LIMIT 0xffffffff
+
+#define __io(a)                        __typesafe_io(a)
+#define __mem_pci(a)           (a)
+
+#endif
diff --git a/arch/arm/mach-cns3xxx/include/mach/irqs.h b/arch/arm/mach-cns3xxx/include/mach/irqs.h
new file mode 100644 (file)
index 0000000..2ab96f8
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2000 Deep Blue Solutions Ltd.
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_IRQS_H
+#define __MACH_IRQS_H
+
+#define IRQ_LOCALTIMER         29
+#define IRQ_LOCALWDOG          30
+#define IRQ_TC11MP_GIC_START   32
+
+#include <mach/cns3xxx.h>
+
+#ifndef NR_IRQS
+#error "NR_IRQS not defined by the board-specific files"
+#endif
+
+#endif
diff --git a/arch/arm/mach-cns3xxx/include/mach/memory.h b/arch/arm/mach-cns3xxx/include/mach/memory.h
new file mode 100644 (file)
index 0000000..3b6b769
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_MEMORY_H
+#define __MACH_MEMORY_H
+
+/*
+ * Physical DRAM offset.
+ */
+#define PHYS_OFFSET            UL(0x00000000)
+
+#define __phys_to_bus(x)       ((x) + PHYS_OFFSET)
+#define __bus_to_phys(x)       ((x) - PHYS_OFFSET)
+
+#define __virt_to_bus(v)       __phys_to_bus(__virt_to_phys(v))
+#define __bus_to_virt(b)       __phys_to_virt(__bus_to_phys(b))
+#define __pfn_to_bus(p)                __phys_to_bus(__pfn_to_phys(p))
+#define __bus_to_pfn(b)                __phys_to_pfn(__bus_to_phys(b))
+
+#endif
diff --git a/arch/arm/mach-cns3xxx/include/mach/system.h b/arch/arm/mach-cns3xxx/include/mach/system.h
new file mode 100644 (file)
index 0000000..58bb03a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2000 Deep Blue Solutions Ltd
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __MACH_SYSTEM_H
+#define __MACH_SYSTEM_H
+
+#include <linux/io.h>
+#include <asm/proc-fns.h>
+#include <mach/hardware.h>
+
+static inline void arch_idle(void)
+{
+       /*
+        * This should do all the clock switching
+        * and wait for interrupt tricks
+        */
+       cpu_do_idle();
+}
+
+void arch_reset(char mode, const char *cmd);
+
+#endif
diff --git a/arch/arm/mach-cns3xxx/include/mach/timex.h b/arch/arm/mach-cns3xxx/include/mach/timex.h
new file mode 100644 (file)
index 0000000..1fd0421
--- /dev/null
@@ -0,0 +1,12 @@
+/*
+ * Cavium Networks architecture timex specifications
+ *
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#define CLOCK_TICK_RATE                (50000000 / 16)
diff --git a/arch/arm/mach-cns3xxx/include/mach/uncompress.h b/arch/arm/mach-cns3xxx/include/mach/uncompress.h
new file mode 100644 (file)
index 0000000..de8ead9
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <asm/mach-types.h>
+#include <mach/hardware.h>
+#include <mach/cns3xxx.h>
+
+#define AMBA_UART_DR(base)     (*(volatile unsigned char *)((base) + 0x00))
+#define AMBA_UART_LCRH(base)   (*(volatile unsigned char *)((base) + 0x2c))
+#define AMBA_UART_CR(base)     (*(volatile unsigned char *)((base) + 0x30))
+#define AMBA_UART_FR(base)     (*(volatile unsigned char *)((base) + 0x18))
+
+/*
+ * Return the UART base address
+ */
+static inline unsigned long get_uart_base(void)
+{
+       if (machine_is_cns3420vb())
+               return CNS3XXX_UART0_BASE;
+       else
+               return 0;
+}
+
+/*
+ * This does not append a newline
+ */
+static inline void putc(int c)
+{
+       unsigned long base = get_uart_base();
+
+       while (AMBA_UART_FR(base) & (1 << 5))
+               barrier();
+
+       AMBA_UART_DR(base) = c;
+}
+
+static inline void flush(void)
+{
+       unsigned long base = get_uart_base();
+
+       while (AMBA_UART_FR(base) & (1 << 3))
+               barrier();
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
diff --git a/arch/arm/mach-cns3xxx/include/mach/vmalloc.h b/arch/arm/mach-cns3xxx/include/mach/vmalloc.h
new file mode 100644 (file)
index 0000000..4d381ec
--- /dev/null
@@ -0,0 +1,11 @@
+/*
+ * Copyright 2000 Russell King.
+ * Copyright 2003 ARM Limited
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#define VMALLOC_END            0xd8000000
diff --git a/arch/arm/mach-cns3xxx/pm.c b/arch/arm/mach-cns3xxx/pm.c
new file mode 100644 (file)
index 0000000..725e1a4
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2008 Cavium Networks
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/delay.h>
+#include <mach/system.h>
+#include <mach/cns3xxx.h>
+
+void cns3xxx_pwr_clk_en(unsigned int block)
+{
+       PM_CLK_GATE_REG |= (block & PM_CLK_GATE_REG_MASK);
+}
+
+void cns3xxx_pwr_power_up(unsigned int block)
+{
+       PM_PLL_HM_PD_CTRL_REG &= ~(block & CNS3XXX_PWR_PLL_ALL);
+
+       /* Wait for 300us for the PLL output clock locked. */
+       udelay(300);
+};
+
+void cns3xxx_pwr_power_down(unsigned int block)
+{
+       /* write '1' to power down */
+       PM_PLL_HM_PD_CTRL_REG |= (block & CNS3XXX_PWR_PLL_ALL);
+};
+
+static void cns3xxx_pwr_soft_rst_force(unsigned int block)
+{
+       /*
+        * bit 0, 28, 29 => program low to reset,
+        * the other else program low and then high
+        */
+       if (block & 0x30000001) {
+               PM_SOFT_RST_REG &= ~(block & PM_SOFT_RST_REG_MASK);
+       } else {
+               PM_SOFT_RST_REG &= ~(block & PM_SOFT_RST_REG_MASK);
+               PM_SOFT_RST_REG |= (block & PM_SOFT_RST_REG_MASK);
+       }
+}
+
+void cns3xxx_pwr_soft_rst(unsigned int block)
+{
+       static unsigned int soft_reset;
+
+       if (soft_reset & block) {
+               /* SPI/I2C/GPIO use the same block, reset once. */
+               return;
+       } else {
+               soft_reset |= block;
+       }
+       cns3xxx_pwr_soft_rst_force(block);
+}
+
+void arch_reset(char mode, const char *cmd)
+{
+       /*
+        * To reset, we hit the on-board reset register
+        * in the system FPGA.
+        */
+       cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(GLOBAL));
+}
+
+/*
+ * cns3xxx_cpu_clock - return CPU/L2 clock
+ *  aclk: cpu clock/2
+ *  hclk: cpu clock/4
+ *  pclk: cpu clock/8
+ */
+int cns3xxx_cpu_clock(void)
+{
+       int cpu;
+       int cpu_sel;
+       int div_sel;
+
+       cpu_sel = (PM_CLK_CTRL_REG >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
+       div_sel = (PM_CLK_CTRL_REG >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
+
+       cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
+
+       return cpu;
+}
index 0ebe185..0316e20 100644 (file)
@@ -7,6 +7,7 @@ config CP_INTC
        bool
 
 config ARCH_DAVINCI_DMx
+       select CPU_ARM926T
        bool
 
 menu "TI DaVinci Implementations"
@@ -41,6 +42,7 @@ config ARCH_DAVINCI_DA850
        select ARCH_HAS_CPUFREQ
 
 config ARCH_DAVINCI_DA8XX
+       select CPU_ARM926T
        bool
 
 config ARCH_DAVINCI_DM365
index dc19870..212d970 100644 (file)
@@ -33,9 +33,6 @@
 #define DA830_EVM_PHY_MASK             0x0
 #define DA830_EVM_MDIO_FREQUENCY       2200000 /* PHY bus frequency */
 
-#define DA830_EMIF25_ASYNC_DATA_CE3_BASE       0x62000000
-#define DA830_EMIF25_CONTROL_BASE              0x68000000
-
 /*
  * USB1 VBUS is controlled by GPIO1[15], over-current is reported on GPIO2[4].
  */
@@ -157,7 +154,7 @@ static __init void da830_evm_usb_init(void)
                                   __func__, ret);
        }
 
-       ret = da8xx_pinmux_setup(da830_evm_usb11_pins);
+       ret = davinci_cfg_reg_list(da830_evm_usb11_pins);
        if (ret) {
                pr_warning("%s: USB 1.1 PinMux setup failed: %d\n",
                           __func__, ret);
@@ -229,15 +226,22 @@ static const short da830_evm_mmc_sd_pins[] = {
 };
 
 #define DA830_MMCSD_WP_PIN             GPIO_TO_PIN(2, 1)
+#define DA830_MMCSD_CD_PIN             GPIO_TO_PIN(2, 2)
 
 static int da830_evm_mmc_get_ro(int index)
 {
        return gpio_get_value(DA830_MMCSD_WP_PIN);
 }
 
+static int da830_evm_mmc_get_cd(int index)
+{
+       return !gpio_get_value(DA830_MMCSD_CD_PIN);
+}
+
 static struct davinci_mmc_config da830_evm_mmc_config = {
        .get_ro                 = da830_evm_mmc_get_ro,
-       .wires                  = 4,
+       .get_cd                 = da830_evm_mmc_get_cd,
+       .wires                  = 8,
        .max_freq               = 50000000,
        .caps                   = MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED,
        .version                = MMC_CTLR_VERSION_2,
@@ -247,7 +251,7 @@ static inline void da830_evm_init_mmc(void)
 {
        int ret;
 
-       ret = da8xx_pinmux_setup(da830_evm_mmc_sd_pins);
+       ret = davinci_cfg_reg_list(da830_evm_mmc_sd_pins);
        if (ret) {
                pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n",
                                ret);
@@ -262,6 +266,14 @@ static inline void da830_evm_init_mmc(void)
        }
        gpio_direction_input(DA830_MMCSD_WP_PIN);
 
+       ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n");
+       if (ret) {
+               pr_warning("da830_evm_init: can not open GPIO %d\n",
+                          DA830_MMCSD_CD_PIN);
+               return;
+       }
+       gpio_direction_input(DA830_MMCSD_CD_PIN);
+
        ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);
        if (ret) {
                pr_warning("da830_evm_init: mmc/sd registration failed: %d\n",
@@ -360,13 +372,13 @@ static struct davinci_nand_pdata da830_evm_nand_pdata = {
 
 static struct resource da830_evm_nand_resources[] = {
        [0] = {         /* First memory resource is NAND I/O window */
-               .start  = DA830_EMIF25_ASYNC_DATA_CE3_BASE,
-               .end    = DA830_EMIF25_ASYNC_DATA_CE3_BASE + PAGE_SIZE - 1,
+               .start  = DA8XX_AEMIF_CS3_BASE,
+               .end    = DA8XX_AEMIF_CS3_BASE + PAGE_SIZE - 1,
                .flags  = IORESOURCE_MEM,
        },
        [1] = {         /* Second memory resource is AEMIF control registers */
-               .start  = DA830_EMIF25_CONTROL_BASE,
-               .end    = DA830_EMIF25_CONTROL_BASE + SZ_32K - 1,
+               .start  = DA8XX_AEMIF_CTL_BASE,
+               .end    = DA8XX_AEMIF_CTL_BASE + SZ_32K - 1,
                .flags  = IORESOURCE_MEM,
        },
 };
@@ -392,7 +404,7 @@ static inline void da830_evm_init_nand(int mux_mode)
                return;
        }
 
-       ret = da8xx_pinmux_setup(da830_evm_emif25_pins);
+       ret = davinci_cfg_reg_list(da830_evm_emif25_pins);
        if (ret)
                pr_warning("da830_evm_init: emif25 mux setup failed: %d\n",
                                ret);
@@ -412,7 +424,7 @@ static inline void da830_evm_init_lcdc(int mux_mode)
 {
        int ret;
 
-       ret = da8xx_pinmux_setup(da830_lcdcntl_pins);
+       ret = davinci_cfg_reg_list(da830_lcdcntl_pins);
        if (ret)
                pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n",
                                ret);
@@ -492,7 +504,7 @@ static __init void da830_evm_init(void)
                pr_warning("da830_evm_init: edma registration failed: %d\n",
                                ret);
 
-       ret = da8xx_pinmux_setup(da830_i2c0_pins);
+       ret = davinci_cfg_reg_list(da830_i2c0_pins);
        if (ret)
                pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n",
                                ret);
@@ -508,7 +520,7 @@ static __init void da830_evm_init(void)
        soc_info->emac_pdata->mdio_max_freq = DA830_EVM_MDIO_FREQUENCY;
        soc_info->emac_pdata->rmii_en = 1;
 
-       ret = da8xx_pinmux_setup(da830_cpgmac_pins);
+       ret = davinci_cfg_reg_list(da830_cpgmac_pins);
        if (ret)
                pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n",
                                ret);
@@ -527,7 +539,7 @@ static __init void da830_evm_init(void)
        i2c_register_board_info(1, da830_evm_i2c_devices,
                        ARRAY_SIZE(da830_evm_i2c_devices));
 
-       ret = da8xx_pinmux_setup(da830_evm_mcasp1_pins);
+       ret = davinci_cfg_reg_list(da830_evm_mcasp1_pins);
        if (ret)
                pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n",
                                ret);
@@ -549,14 +561,6 @@ static int __init da830_evm_console_init(void)
 console_initcall(da830_evm_console_init);
 #endif
 
-static __init void da830_evm_irq_init(void)
-{
-       struct davinci_soc_info *soc_info = &davinci_soc_info;
-
-       cp_intc_init((void __iomem *)DA8XX_CP_INTC_VIRT, DA830_N_CP_INTC_IRQ,
-                       soc_info->intc_irq_prios);
-}
-
 static void __init da830_evm_map_io(void)
 {
        da830_init();
@@ -567,7 +571,7 @@ MACHINE_START(DAVINCI_DA830_EVM, "DaVinci DA830/OMAP-L137 EVM")
        .io_pg_offst    = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params    = (DA8XX_DDR_BASE + 0x100),
        .map_io         = da830_evm_map_io,
-       .init_irq       = da830_evm_irq_init,
+       .init_irq       = cp_intc_init,
        .timer          = &davinci_timer,
        .init_machine   = da830_evm_init,
 MACHINE_END
index 411284d..abd0493 100644 (file)
@@ -206,12 +206,12 @@ static __init void da850_evm_setup_nor_nand(void)
        int ret = 0;
 
        if (ui_card_detected & !HAS_MMC) {
-               ret = da8xx_pinmux_setup(da850_nand_pins);
+               ret = davinci_cfg_reg_list(da850_nand_pins);
                if (ret)
                        pr_warning("da850_evm_init: nand mux setup failed: "
                                        "%d\n", ret);
 
-               ret = da8xx_pinmux_setup(da850_nor_pins);
+               ret = davinci_cfg_reg_list(da850_nor_pins);
                if (ret)
                        pr_warning("da850_evm_init: nor mux setup failed: %d\n",
                                ret);
@@ -568,12 +568,12 @@ static int __init da850_evm_config_emac(void)
 
        if (rmii_en) {
                val |= BIT(8);
-               ret = da8xx_pinmux_setup(da850_rmii_pins);
+               ret = davinci_cfg_reg_list(da850_rmii_pins);
                pr_info("EMAC: RMII PHY configured, MII PHY will not be"
                                                        " functional\n");
        } else {
                val &= ~BIT(8);
-               ret = da8xx_pinmux_setup(da850_cpgmac_pins);
+               ret = davinci_cfg_reg_list(da850_cpgmac_pins);
                pr_info("EMAC: MII PHY configured, RMII PHY will not be"
                                                        " functional\n");
        }
@@ -626,7 +626,7 @@ static __init void da850_evm_init(void)
                pr_warning("da850_evm_init: edma registration failed: %d\n",
                                ret);
 
-       ret = da8xx_pinmux_setup(da850_i2c0_pins);
+       ret = davinci_cfg_reg_list(da850_i2c0_pins);
        if (ret)
                pr_warning("da850_evm_init: i2c0 mux setup failed: %d\n",
                                ret);
@@ -643,7 +643,7 @@ static __init void da850_evm_init(void)
                                ret);
 
        if (HAS_MMC) {
-               ret = da8xx_pinmux_setup(da850_mmcsd0_pins);
+               ret = davinci_cfg_reg_list(da850_mmcsd0_pins);
                if (ret)
                        pr_warning("da850_evm_init: mmcsd0 mux setup failed:"
                                        " %d\n", ret);
@@ -679,20 +679,20 @@ static __init void da850_evm_init(void)
        __raw_writel(0, IO_ADDRESS(DA8XX_UART1_BASE) + 0x30);
        __raw_writel(0, IO_ADDRESS(DA8XX_UART0_BASE) + 0x30);
 
-       ret = da8xx_pinmux_setup(da850_mcasp_pins);
+       ret = davinci_cfg_reg_list(da850_mcasp_pins);
        if (ret)
                pr_warning("da850_evm_init: mcasp mux setup failed: %d\n",
                                ret);
 
        da8xx_register_mcasp(0, &da850_evm_snd_data);
 
-       ret = da8xx_pinmux_setup(da850_lcdcntl_pins);
+       ret = davinci_cfg_reg_list(da850_lcdcntl_pins);
        if (ret)
                pr_warning("da850_evm_init: lcdcntl mux setup failed: %d\n",
                                ret);
 
        /* Handle board specific muxing for LCD here */
-       ret = da8xx_pinmux_setup(da850_evm_lcdc_pins);
+       ret = davinci_cfg_reg_list(da850_evm_lcdc_pins);
        if (ret)
                pr_warning("da850_evm_init: evm specific lcd mux setup "
                                "failed: %d\n", ret);
@@ -736,14 +736,6 @@ static int __init da850_evm_console_init(void)
 console_initcall(da850_evm_console_init);
 #endif
 
-static __init void da850_evm_irq_init(void)
-{
-       struct davinci_soc_info *soc_info = &davinci_soc_info;
-
-       cp_intc_init((void __iomem *)DA8XX_CP_INTC_VIRT, DA850_N_CP_INTC_IRQ,
-                       soc_info->intc_irq_prios);
-}
-
 static void __init da850_evm_map_io(void)
 {
        da850_init();
@@ -754,7 +746,7 @@ MACHINE_START(DAVINCI_DA850_EVM, "DaVinci DA850/OMAP-L138 EVM")
        .io_pg_offst    = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params    = (DA8XX_DDR_BASE + 0x100),
        .map_io         = da850_evm_map_io,
-       .init_irq       = da850_evm_irq_init,
+       .init_irq       = cp_intc_init,
        .timer          = &davinci_timer,
        .init_machine   = da850_evm_init,
 MACHINE_END
index aa48e3f..a319101 100644 (file)
@@ -33,9 +33,6 @@
 #include <mach/mmc.h>
 #include <mach/usb.h>
 
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x01e10000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x02000000
-
 /* NOTE:  this is geared for the standard config, with a socketed
  * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors.  If you
  * swap chips, maybe with a different block size, partitioning may
@@ -86,12 +83,12 @@ static struct davinci_nand_pdata davinci_nand_data = {
 
 static struct resource davinci_nand_resources[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
+               .start          = DM355_ASYNC_EMIF_DATA_CE0_BASE,
+               .end            = DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM355_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -353,17 +350,12 @@ static __init void dm355_evm_init(void)
        dm355_init_asp1(ASP1_TX_EVT_EN | ASP1_RX_EVT_EN, &dm355_evm_snd_data);
 }
 
-static __init void dm355_evm_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(DAVINCI_DM355_EVM, "DaVinci DM355 EVM")
        .phys_io      = IO_PHYS,
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (0x80000100),
        .map_io       = dm355_evm_map_io,
-       .init_irq     = dm355_evm_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = dm355_evm_init,
 MACHINE_END
index 21f32eb..f1d8132 100644 (file)
@@ -30,9 +30,6 @@
 #include <mach/mmc.h>
 #include <mach/usb.h>
 
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x01e10000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x02000000
-
 /* NOTE:  this is geared for the standard config, with a socketed
  * 2 GByte Micron NAND (MT29F16G08FAA) using 128KB sectors.  If you
  * swap chips, maybe with a different block size, partitioning may
@@ -82,12 +79,12 @@ static struct davinci_nand_pdata davinci_nand_data = {
 
 static struct resource davinci_nand_resources[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
+               .start          = DM355_ASYNC_EMIF_DATA_CE0_BASE,
+               .end            = DM355_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM355_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM355_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -272,17 +269,12 @@ static __init void dm355_leopard_init(void)
                        ARRAY_SIZE(dm355_leopard_spi_info));
 }
 
-static __init void dm355_leopard_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(DM355_LEOPARD, "DaVinci DM355 leopard")
        .phys_io      = IO_PHYS,
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (0x80000100),
        .map_io       = dm355_leopard_map_io,
-       .init_irq     = dm355_leopard_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = dm355_leopard_init,
 MACHINE_END
index df4ab21..84acef1 100644 (file)
@@ -54,11 +54,6 @@ static inline int have_tvp7002(void)
        return 0;
 }
 
-
-#define DM365_ASYNC_EMIF_CONTROL_BASE  0x01d10000
-#define DM365_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
-#define DM365_ASYNC_EMIF_DATA_CE1_BASE 0x04000000
-
 #define DM365_EVM_PHY_MASK             (0x2)
 #define DM365_EVM_MDIO_FREQUENCY       (2200000) /* PHY bus frequency */
 
@@ -605,7 +600,11 @@ static __init void dm365_evm_init(void)
        /* maybe setup mmc1/etc ... _after_ mmc0 */
        evm_init_cpld();
 
+#ifdef CONFIG_SND_DM365_AIC3X_CODEC
        dm365_init_asp(&dm365_evm_snd_data);
+#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
+       dm365_init_vc(&dm365_evm_snd_data);
+#endif
        dm365_init_rtc();
        dm365_init_ks(&dm365evm_ks_data);
 
@@ -613,17 +612,12 @@ static __init void dm365_evm_init(void)
                        ARRAY_SIZE(dm365_evm_spi_info));
 }
 
-static __init void dm365_evm_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(DAVINCI_DM365_EVM, "DaVinci DM365 EVM")
        .phys_io        = IO_PHYS,
        .io_pg_offst    = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params    = (0x80000100),
        .map_io         = dm365_evm_map_io,
-       .init_irq       = dm365_evm_irq_init,
+       .init_irq       = davinci_irq_init,
        .timer          = &davinci_timer,
        .init_machine   = dm365_evm_init,
 MACHINE_END
index 976e11b..34c8b41 100644 (file)
 #define DM644X_EVM_PHY_MASK            (0x2)
 #define DM644X_EVM_MDIO_FREQUENCY      (2200000) /* PHY bus frequency */
 
-#define DAVINCI_CFC_ATA_BASE             0x01C66000
-
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE   0x01e00000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE  0x02000000
-#define DAVINCI_ASYNC_EMIF_DATA_CE1_BASE  0x04000000
-#define DAVINCI_ASYNC_EMIF_DATA_CE2_BASE  0x06000000
-#define DAVINCI_ASYNC_EMIF_DATA_CE3_BASE  0x08000000
-
 #define LXT971_PHY_ID  (0x001378e2)
 #define LXT971_PHY_MASK        (0xfffffff0)
 
@@ -92,8 +84,8 @@ static struct physmap_flash_data davinci_evm_norflash_data = {
 /* NOTE: CFI probe will correctly detect flash part as 32M, but EMIF
  * limits addresses to 16M, so using addresses past 16M will wrap */
 static struct resource davinci_evm_norflash_resource = {
-       .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-       .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
+       .start          = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
+       .end            = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
        .flags          = IORESOURCE_MEM,
 };
 
@@ -111,7 +103,7 @@ static struct platform_device davinci_evm_norflash_device = {
  * It may used instead of the (default) NOR chip to boot, using TI's
  * tools to install the secondary boot loader (UBL) and U-Boot.
  */
-struct mtd_partition davinci_evm_nandflash_partition[] = {
+static struct mtd_partition davinci_evm_nandflash_partition[] = {
        /* Bootloader layout depends on whose u-boot is installed, but we
         * can hide all the details.
         *  - block 0 for u-boot environment ... in mainline u-boot
@@ -154,12 +146,12 @@ static struct davinci_nand_pdata davinci_evm_nandflash_data = {
 
 static struct resource davinci_evm_nandflash_resource[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
+               .start          = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
+               .end            = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM644X_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -258,32 +250,6 @@ static struct platform_device rtc_dev = {
        .id             = -1,
 };
 
-static struct resource ide_resources[] = {
-       {
-               .start          = DAVINCI_CFC_ATA_BASE,
-               .end            = DAVINCI_CFC_ATA_BASE + 0x7ff,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .start          = IRQ_IDE,
-               .end            = IRQ_IDE,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static u64 ide_dma_mask = DMA_BIT_MASK(32);
-
-static struct platform_device ide_dev = {
-       .name           = "palm_bk3710",
-       .id             = -1,
-       .resource       = ide_resources,
-       .num_resources  = ARRAY_SIZE(ide_resources),
-       .dev = {
-               .dma_mask               = &ide_dma_mask,
-               .coherent_dma_mask      = DMA_BIT_MASK(32),
-       },
-};
-
 static struct snd_platform_data dm644x_evm_snd_data;
 
 /*----------------------------------------------------------------------*/
@@ -704,10 +670,7 @@ static __init void davinci_evm_init(void)
                        pr_warning("WARNING: both IDE and Flash are "
                                "enabled, but they share AEMIF pins.\n"
                                "\tDisable IDE for NAND/NOR support.\n");
-               davinci_cfg_reg(DM644X_HPIEN_DISABLE);
-               davinci_cfg_reg(DM644X_ATAEN);
-               davinci_cfg_reg(DM644X_HDIREN);
-               platform_device_register(&ide_dev);
+               davinci_init_ide();
        } else if (HAS_NAND || HAS_NOR) {
                davinci_cfg_reg(DM644X_HPIEN_DISABLE);
                davinci_cfg_reg(DM644X_ATAEN_DISABLE);
@@ -741,18 +704,13 @@ static __init void davinci_evm_init(void)
 
 }
 
-static __init void davinci_evm_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(DAVINCI_EVM, "DaVinci DM644x EVM")
        /* Maintainer: MontaVista Software <source@mvista.com> */
        .phys_io      = IO_PHYS,
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (DAVINCI_DDR_BASE + 0x100),
        .map_io       = davinci_evm_map_io,
-       .init_irq     = davinci_evm_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = davinci_evm_init,
 MACHINE_END
index 5ba3cb2..6d88893 100644 (file)
@@ -80,17 +80,14 @@ static struct davinci_nand_pdata davinci_nand_data = {
        .options                = 0,
 };
 
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE                0x20008000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE       0x42000000
-
 static struct resource davinci_nand_resources[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_32M - 1,
+               .start          = DM646X_ASYNC_EMIF_CS2_SPACE_BASE,
+               .end            = DM646X_ASYNC_EMIF_CS2_SPACE_BASE + SZ_32M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM646X_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM646X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -736,17 +733,12 @@ static __init void evm_init(void)
        platform_device_register(&davinci_nand_device);
 
        if (HAS_ATA)
-               dm646x_init_ide();
+               davinci_init_ide();
 
        soc_info->emac_pdata->phy_mask = DM646X_EVM_PHY_MASK;
        soc_info->emac_pdata->mdio_max_freq = DM646X_EVM_MDIO_FREQUENCY;
 }
 
-static __init void davinci_dm646x_evm_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 #define DM646X_EVM_REF_FREQ            27000000
 #define DM6467T_EVM_REF_FREQ           33000000
 
@@ -763,7 +755,7 @@ MACHINE_START(DAVINCI_DM6467_EVM, "DaVinci DM646x EVM")
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (0x80000100),
        .map_io       = davinci_map_io,
-       .init_irq     = davinci_dm646x_evm_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = evm_init,
 MACHINE_END
@@ -773,7 +765,7 @@ MACHINE_START(DAVINCI_DM6467TEVM, "DaVinci DM6467T EVM")
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (0x80000100),
        .map_io       = davinci_map_io,
-       .init_irq     = davinci_dm646x_evm_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = evm_init,
 MACHINE_END
index bd9ca07..4c30e92 100644 (file)
@@ -31,6 +31,7 @@
 #include <asm/mach/arch.h>
 
 #include <mach/dm644x.h>
+#include <mach/common.h>
 #include <mach/i2c.h>
 #include <mach/serial.h>
 #include <mach/mux.h>
 #define NEUROS_OSD2_PHY_MASK           0x2
 #define NEUROS_OSD2_MDIO_FREQUENCY     2200000 /* PHY bus frequency */
 
-#define DAVINCI_CFC_ATA_BASE            0x01C66000
-
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE         0x01e00000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
-
 #define LXT971_PHY_ID                  0x001378e2
 #define LXT971_PHY_MASK                        0xfffffff0
 
@@ -60,7 +56,7 @@
 
 #define NAND_BLOCK_SIZE                SZ_128K
 
-struct mtd_partition davinci_ntosd2_nandflash_partition[] = {
+static struct mtd_partition davinci_ntosd2_nandflash_partition[] = {
        {
                /* UBL (a few copies) plus U-Boot */
                .name           = "bootloader",
@@ -98,12 +94,12 @@ static struct davinci_nand_pdata davinci_ntosd2_nandflash_data = {
 
 static struct resource davinci_ntosd2_nandflash_resource[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
+               .start          = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
+               .end            = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM644X_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -130,32 +126,6 @@ static struct platform_device davinci_fb_device = {
        .num_resources = 0,
 };
 
-static struct resource ide_resources[] = {
-       {
-               .start          = DAVINCI_CFC_ATA_BASE,
-               .end            = DAVINCI_CFC_ATA_BASE + 0x7ff,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .start          = IRQ_IDE,
-               .end            = IRQ_IDE,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static u64 ide_dma_mask = DMA_BIT_MASK(32);
-
-static struct platform_device ide_dev = {
-       .name           = "palm_bk3710",
-       .id             = -1,
-       .resource       = ide_resources,
-       .num_resources  = ARRAY_SIZE(ide_resources),
-       .dev = {
-               .dma_mask               = &ide_dma_mask,
-               .coherent_dma_mask      = DMA_BIT_MASK(32),
-       },
-};
-
 static struct snd_platform_data dm644x_ntosd2_snd_data;
 
 static struct gpio_led ntosd2_leds[] = {
@@ -259,10 +229,7 @@ static __init void davinci_ntosd2_init(void)
                        pr_warning("WARNING: both IDE and Flash are "
                                "enabled, but they share AEMIF pins.\n"
                                "\tDisable IDE for NAND/NOR support.\n");
-               davinci_cfg_reg(DM644X_HPIEN_DISABLE);
-               davinci_cfg_reg(DM644X_ATAEN);
-               davinci_cfg_reg(DM644X_HDIREN);
-               platform_device_register(&ide_dev);
+               davinci_init_ide();
        } else if (HAS_NAND) {
                davinci_cfg_reg(DM644X_HPIEN_DISABLE);
                davinci_cfg_reg(DM644X_ATAEN_DISABLE);
@@ -306,18 +273,13 @@ static __init void davinci_ntosd2_init(void)
        davinci_setup_mmc(0, &davinci_ntosd2_mmc_config);
 }
 
-static __init void davinci_ntosd2_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(NEUROS_OSD2, "Neuros OSD2")
        /* Maintainer: Neuros Technologies <neuros@groups.google.com> */
        .phys_io        = IO_PHYS,
        .io_pg_offst    = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params    = (DAVINCI_DDR_BASE + 0x100),
        .map_io          = davinci_ntosd2_map_io,
-       .init_irq       = davinci_ntosd2_irq_init,
+       .init_irq       = davinci_irq_init,
        .timer          = &davinci_timer,
        .init_machine = davinci_ntosd2_init,
 MACHINE_END
index 08d373b..23e664a 100644 (file)
 #define SFFSDR_PHY_MASK                (0x2)
 #define SFFSDR_MDIO_FREQUENCY  (2200000) /* PHY bus frequency */
 
-#define DAVINCI_ASYNC_EMIF_CONTROL_BASE   0x01e00000
-#define DAVINCI_ASYNC_EMIF_DATA_CE0_BASE  0x02000000
-
-struct mtd_partition davinci_sffsdr_nandflash_partition[] = {
+static struct mtd_partition davinci_sffsdr_nandflash_partition[] = {
        /* U-Boot Environment: Block 0
         * UBL:                Block 1
         * U-Boot:             Blocks 6-7 (256 kb)
@@ -76,12 +73,12 @@ static struct flash_platform_data davinci_sffsdr_nandflash_data = {
 
 static struct resource davinci_sffsdr_nandflash_resource[] = {
        {
-               .start          = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
+               .start          = DM644X_ASYNC_EMIF_DATA_CE0_BASE,
+               .end            = DM644X_ASYNC_EMIF_DATA_CE0_BASE + SZ_16M - 1,
                .flags          = IORESOURCE_MEM,
        }, {
-               .start          = DAVINCI_ASYNC_EMIF_CONTROL_BASE,
-               .end            = DAVINCI_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
+               .start          = DM644X_ASYNC_EMIF_CONTROL_BASE,
+               .end            = DM644X_ASYNC_EMIF_CONTROL_BASE + SZ_4K - 1,
                .flags          = IORESOURCE_MEM,
        },
 };
@@ -155,18 +152,13 @@ static __init void davinci_sffsdr_init(void)
        davinci_cfg_reg(DM644X_VLYNQWD);
 }
 
-static __init void davinci_sffsdr_irq_init(void)
-{
-       davinci_irq_init();
-}
-
 MACHINE_START(SFFSDR, "Lyrtech SFFSDR")
        /* Maintainer: Hugo Villeneuve hugo.villeneuve@lyrtech.com */
        .phys_io      = IO_PHYS,
        .io_pg_offst  = (__IO_ADDRESS(IO_PHYS) >> 18) & 0xfffc,
        .boot_params  = (DAVINCI_DDR_BASE + 0x100),
        .map_io       = davinci_sffsdr_map_io,
-       .init_irq     = davinci_sffsdr_irq_init,
+       .init_irq     = davinci_irq_init,
        .timer        = &davinci_timer,
        .init_machine = davinci_sffsdr_init,
 MACHINE_END
index aec3756..ba8b12b 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/i2c.h>
 
 #include <mach/clock.h>
+#include <mach/cdce949.h>
 
 #include "clock.h"
 
index bf6218e..054c303 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <mach/hardware.h>
 
+#include <mach/clock.h>
 #include <mach/psc.h>
 #include <mach/cputype.h>
 #include "clock.h"
@@ -42,7 +43,8 @@ static void __clk_enable(struct clk *clk)
        if (clk->parent)
                __clk_enable(clk->parent);
        if (clk->usecount++ == 0 && (clk->flags & CLK_PSC))
-               davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc, 1);
+               davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc,
+                               PSC_STATE_ENABLE);
 }
 
 static void __clk_disable(struct clk *clk)
@@ -51,7 +53,9 @@ static void __clk_disable(struct clk *clk)
                return;
        if (--clk->usecount == 0 && !(clk->flags & CLK_PLL) &&
            (clk->flags & CLK_PSC))
-               davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc, 0);
+               davinci_psc_config(psc_domain(clk), clk->gpsc, clk->lpsc,
+                               (clk->flags & PSC_SWRSTDISABLE) ?
+                               PSC_STATE_SWRSTDISABLE : PSC_STATE_DISABLE);
        if (clk->parent)
                __clk_disable(clk->parent);
 }
@@ -233,7 +237,10 @@ static int __init clk_disable_unused(void)
                        continue;
 
                pr_info("Clocks: disable unused %s\n", ck->name);
-               davinci_psc_config(psc_domain(ck), ck->gpsc, ck->lpsc, 0);
+
+               davinci_psc_config(psc_domain(ck), ck->gpsc, ck->lpsc,
+                               (ck->flags & PSC_SWRSTDISABLE) ?
+                               PSC_STATE_SWRSTDISABLE : PSC_STATE_DISABLE);
        }
        spin_unlock_irq(&clockfw_lock);
 
@@ -272,7 +279,7 @@ static unsigned long clk_sysclk_recalc(struct clk *clk)
 
        v = __raw_readl(pll->base + clk->div_reg);
        if (v & PLLDIV_EN) {
-               plldiv = (v & PLLDIV_RATIO_MASK) + 1;
+               plldiv = (v & pll->div_ratio_mask) + 1;
                if (plldiv)
                        rate /= plldiv;
        }
@@ -295,7 +302,6 @@ static unsigned long clk_pllclk_recalc(struct clk *clk)
        struct pll_data *pll = clk->pll_data;
        unsigned long rate = clk->rate;
 
-       pll->base = IO_ADDRESS(pll->phys_base);
        ctrl = __raw_readl(pll->base + PLLCTL);
        rate = pll->input_rate = clk->parent->rate;
 
@@ -312,7 +318,7 @@ static unsigned long clk_pllclk_recalc(struct clk *clk)
        if (pll->flags & PLL_HAS_PREDIV) {
                prediv = __raw_readl(pll->base + PREDIV);
                if (prediv & PLLDIV_EN)
-                       prediv = (prediv & PLLDIV_RATIO_MASK) + 1;
+                       prediv = (prediv & pll->div_ratio_mask) + 1;
                else
                        prediv = 1;
        }
@@ -324,7 +330,7 @@ static unsigned long clk_pllclk_recalc(struct clk *clk)
        if (pll->flags & PLL_HAS_POSTDIV) {
                postdiv = __raw_readl(pll->base + POSTDIV);
                if (postdiv & PLLDIV_EN)
-                       postdiv = (postdiv & PLLDIV_RATIO_MASK) + 1;
+                       postdiv = (postdiv & pll->div_ratio_mask) + 1;
                else
                        postdiv = 1;
        }
@@ -451,6 +457,18 @@ int __init davinci_clk_init(struct clk_lookup *clocks)
                                clk->recalc = clk_leafclk_recalc;
                }
 
+               if (clk->pll_data) {
+                       struct pll_data *pll = clk->pll_data;
+
+                       if (!pll->div_ratio_mask)
+                               pll->div_ratio_mask = PLLDIV_RATIO_MASK;
+
+                       if (pll->phys_base && !pll->base) {
+                               pll->base = ioremap(pll->phys_base, SZ_4K);
+                               WARN_ON(!pll->base);
+                       }
+               }
+
                if (clk->recalc)
                        clk->rate = clk->recalc(clk);
 
index aa0a611..01e3648 100644 (file)
@@ -76,6 +76,7 @@ struct pll_data {
        u32 num;
        u32 flags;
        u32 input_rate;
+       u32 div_ratio_mask;
 };
 #define PLL_HAS_PREDIV          0x01
 #define PLL_HAS_POSTDIV         0x02
@@ -101,10 +102,11 @@ struct clk {
 
 /* Clock flags: SoC-specific flags start at BIT(16) */
 #define ALWAYS_ENABLED         BIT(1)
-#define CLK_PSC                 BIT(2)
-#define PSC_DSP                 BIT(3) /* PSC uses DSP domain, not ARM */
+#define CLK_PSC                        BIT(2)
+#define PSC_DSP                        BIT(3) /* PSC uses DSP domain, not ARM */
 #define CLK_PLL                        BIT(4) /* PLL-derived clock */
-#define PRE_PLL                 BIT(5) /* source is before PLL mult/div */
+#define PRE_PLL                        BIT(5) /* source is before PLL mult/div */
+#define PSC_SWRSTDISABLE       BIT(6) /* Disable state is SwRstDisable */
 
 #define CLK(dev, con, ck)      \
        {                       \
@@ -118,6 +120,7 @@ int davinci_set_pllrate(struct pll_data *pll, unsigned int prediv,
                                unsigned int mult, unsigned int postdiv);
 
 extern struct platform_device davinci_wdt_device;
+extern void davinci_watchdog_reset(struct platform_device *);
 
 #endif
 
index 94f27cb..1d25573 100644 (file)
@@ -37,26 +37,43 @@ void davinci_get_mac_addr(struct memory_accessor *mem_acc, void *context)
                pr_info("Read MAC addr from EEPROM: %pM\n", mac_addr);
 }
 
-static struct davinci_id * __init davinci_get_id(u32 jtag_id)
+static int __init davinci_init_id(struct davinci_soc_info *soc_info)
 {
-       int i;
-       struct davinci_id *dip;
-       u8 variant = (jtag_id & 0xf0000000) >> 28;
-       u16 part_no = (jtag_id & 0x0ffff000) >> 12;
+       int                     i;
+       struct davinci_id       *dip;
+       u8                      variant;
+       u16                     part_no;
+       void __iomem            *base;
+
+       base = ioremap(soc_info->jtag_id_reg, SZ_4K);
+       if (!base) {
+               pr_err("Unable to map JTAG ID register\n");
+               return -ENOMEM;
+       }
+
+       soc_info->jtag_id = __raw_readl(base);
+       iounmap(base);
+
+       variant = (soc_info->jtag_id & 0xf0000000) >> 28;
+       part_no = (soc_info->jtag_id & 0x0ffff000) >> 12;
 
-       for (i = 0, dip = davinci_soc_info.ids; i < davinci_soc_info.ids_num;
+       for (i = 0, dip = soc_info->ids; i < soc_info->ids_num;
                        i++, dip++)
                /* Don't care about the manufacturer right now */
-               if ((dip->part_no == part_no) && (dip->variant == variant))
-                       return dip;
-
-       return NULL;
+               if ((dip->part_no == part_no) && (dip->variant == variant)) {
+                       soc_info->cpu_id = dip->cpu_id;
+                       pr_info("DaVinci %s variant 0x%x\n", dip->name,
+                                       dip->variant);
+                       return 0;
+               }
+
+       pr_err("Unknown DaVinci JTAG ID 0x%x\n", soc_info->jtag_id);
+       return -EINVAL;
 }
 
 void __init davinci_common_init(struct davinci_soc_info *soc_info)
 {
        int ret;
-       struct davinci_id *dip;
 
        if (!soc_info) {
                ret = -EINVAL;
@@ -77,22 +94,16 @@ void __init davinci_common_init(struct davinci_soc_info *soc_info)
        local_flush_tlb_all();
        flush_cache_all();
 
+       if (!davinci_soc_info.reset)
+               davinci_soc_info.reset = davinci_watchdog_reset;
+
        /*
         * We want to check CPU revision early for cpu_is_xxxx() macros.
         * IO space mapping must be initialized before we can do that.
         */
-       davinci_soc_info.jtag_id = __raw_readl(davinci_soc_info.jtag_id_base);
-
-       dip = davinci_get_id(davinci_soc_info.jtag_id);
-       if (!dip) {
-               ret = -EINVAL;
-               pr_err("Unknown DaVinci JTAG ID 0x%x\n",
-                                               davinci_soc_info.jtag_id);
+       ret = davinci_init_id(&davinci_soc_info);
+       if (ret < 0)
                goto err;
-       }
-
-       davinci_soc_info.cpu_id = dip->cpu_id;
-       pr_info("DaVinci %s variant 0x%x\n", dip->name, dip->variant);
 
        if (davinci_soc_info.cpu_clks) {
                ret = davinci_clk_init(davinci_soc_info.cpu_clks);
@@ -101,8 +112,6 @@ void __init davinci_common_init(struct davinci_soc_info *soc_info)
                        goto err;
        }
 
-       davinci_intc_base = davinci_soc_info.intc_base;
-       davinci_intc_type = davinci_soc_info.intc_type;
        return;
 
 err:
index 37311d1..bb4c40e 100644 (file)
 #include <linux/irq.h>
 #include <linux/io.h>
 
+#include <mach/common.h>
 #include <mach/cp_intc.h>
 
-static void __iomem *cp_intc_base;
-
 static inline unsigned int cp_intc_read(unsigned offset)
 {
-       return __raw_readl(cp_intc_base + offset);
+       return __raw_readl(davinci_intc_base + offset);
 }
 
 static inline void cp_intc_write(unsigned long value, unsigned offset)
 {
-       __raw_writel(value, cp_intc_base + offset);
+       __raw_writel(value, davinci_intc_base + offset);
 }
 
 static void cp_intc_ack_irq(unsigned int irq)
@@ -100,13 +99,18 @@ static struct irq_chip cp_intc_irq_chip = {
        .set_wake       = cp_intc_set_wake,
 };
 
-void __init cp_intc_init(void __iomem *base, unsigned short num_irq,
-                        u8 *irq_prio)
+void __init cp_intc_init(void)
 {
+       unsigned long num_irq   = davinci_soc_info.intc_irq_num;
+       u8 *irq_prio            = davinci_soc_info.intc_irq_prios;
+       u32 *host_map           = davinci_soc_info.intc_host_map;
        unsigned num_reg        = BITS_TO_LONGS(num_irq);
        int i;
 
-       cp_intc_base = base;
+       davinci_intc_type = DAVINCI_INTC_TYPE_CP_INTC;
+       davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_8K);
+       if (WARN_ON(!davinci_intc_base))
+               return;
 
        cp_intc_write(0, CP_INTC_GLOBAL_ENABLE);
 
@@ -157,6 +161,10 @@ void __init cp_intc_init(void __iomem *base, unsigned short num_irq,
                        cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i));
        }
 
+       if (host_map)
+               for (i = 0; host_map[i] != -1; i++)
+                       cp_intc_write(host_map[i], CP_INTC_HOST_MAP(i));
+
        /* Set up genirq dispatching for cp_intc */
        for (i = 0; i < num_irq; i++) {
                set_irq_chip(i, &cp_intc_irq_chip);
index e8cb982..23e9eda 100644 (file)
@@ -19,6 +19,7 @@
 #include <mach/common.h>
 #include <mach/time.h>
 #include <mach/da8xx.h>
+#include <mach/gpio.h>
 
 #include "clock.h"
 #include "mux.h"
@@ -1126,10 +1127,7 @@ static struct map_desc da830_io_desc[] = {
        },
 };
 
-static void __iomem *da830_psc_bases[] = {
-       IO_ADDRESS(DA8XX_PSC0_BASE),
-       IO_ADDRESS(DA8XX_PSC1_BASE),
-};
+static u32 da830_psc_bases[] = { DA8XX_PSC0_BASE, DA8XX_PSC1_BASE };
 
 /* Contents of JTAG ID register used to identify exact cpu type */
 static struct davinci_id da830_ids[] = {
@@ -1158,14 +1156,14 @@ static struct davinci_id da830_ids[] = {
 
 static struct davinci_timer_instance da830_timer_instance[2] = {
        {
-               .base           = IO_ADDRESS(DA8XX_TIMER64P0_BASE),
+               .base           = DA8XX_TIMER64P0_BASE,
                .bottom_irq     = IRQ_DA8XX_TINT12_0,
                .top_irq        = IRQ_DA8XX_TINT34_0,
                .cmp_off        = DA830_CMP12_0,
                .cmp_irq        = IRQ_DA830_T12CMPINT0_0,
        },
        {
-               .base           = IO_ADDRESS(DA8XX_TIMER64P1_BASE),
+               .base           = DA8XX_TIMER64P1_BASE,
                .bottom_irq     = IRQ_DA8XX_TINT12_1,
                .top_irq        = IRQ_DA8XX_TINT34_1,
                .cmp_off        = DA830_CMP12_0,
@@ -1187,34 +1185,33 @@ static struct davinci_timer_info da830_timer_info = {
 static struct davinci_soc_info davinci_soc_info_da830 = {
        .io_desc                = da830_io_desc,
        .io_desc_num            = ARRAY_SIZE(da830_io_desc),
+       .jtag_id_reg            = DA8XX_SYSCFG0_BASE + DA8XX_JTAG_ID_REG,
        .ids                    = da830_ids,
        .ids_num                = ARRAY_SIZE(da830_ids),
        .cpu_clks               = da830_clks,
        .psc_bases              = da830_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(da830_psc_bases),
+       .pinmux_base            = DA8XX_SYSCFG0_BASE + 0x120,
        .pinmux_pins            = da830_pins,
        .pinmux_pins_num        = ARRAY_SIZE(da830_pins),
-       .intc_base              = (void __iomem *)DA8XX_CP_INTC_VIRT,
+       .intc_base              = DA8XX_CP_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_CP_INTC,
        .intc_irq_prios         = da830_default_priorities,
        .intc_irq_num           = DA830_N_CP_INTC_IRQ,
        .timer_info             = &da830_timer_info,
-       .gpio_base              = IO_ADDRESS(DA8XX_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DA8XX_GPIO_BASE,
        .gpio_num               = 128,
        .gpio_irq               = IRQ_DA8XX_GPIO0,
        .serial_dev             = &da8xx_serial_device,
        .emac_pdata             = &da8xx_emac_pdata,
+       .reset_device           = &da8xx_wdt_device,
 };
 
 void __init da830_init(void)
 {
-       da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
-       if (WARN(!da8xx_syscfg0_base, "Unable to map syscfg0 module"))
-               return;
-
-       davinci_soc_info_da830.jtag_id_base =
-                                       DA8XX_SYSCFG0_VIRT(DA8XX_JTAG_ID_REG);
-       davinci_soc_info_da830.pinmux_base = DA8XX_SYSCFG0_VIRT(0x120);
-
        davinci_common_init(&davinci_soc_info_da830);
+
+       da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
+       WARN(!da8xx_syscfg0_base, "Unable to map syscfg0 module");
 }
index d0fd756..6b8331b 100644 (file)
@@ -27,6 +27,7 @@
 #include <mach/da8xx.h>
 #include <mach/cpufreq.h>
 #include <mach/pm.h>
+#include <mach/gpio.h>
 
 #include "clock.h"
 #include "mux.h"
@@ -781,10 +782,7 @@ static struct map_desc da850_io_desc[] = {
        },
 };
 
-static void __iomem *da850_psc_bases[] = {
-       IO_ADDRESS(DA8XX_PSC0_BASE),
-       IO_ADDRESS(DA8XX_PSC1_BASE),
-};
+static u32 da850_psc_bases[] = { DA8XX_PSC0_BASE, DA8XX_PSC1_BASE };
 
 /* Contents of JTAG ID register used to identify exact cpu type */
 static struct davinci_id da850_ids[] = {
@@ -799,22 +797,22 @@ static struct davinci_id da850_ids[] = {
 
 static struct davinci_timer_instance da850_timer_instance[4] = {
        {
-               .base           = IO_ADDRESS(DA8XX_TIMER64P0_BASE),
+               .base           = DA8XX_TIMER64P0_BASE,
                .bottom_irq     = IRQ_DA8XX_TINT12_0,
                .top_irq        = IRQ_DA8XX_TINT34_0,
        },
        {
-               .base           = IO_ADDRESS(DA8XX_TIMER64P1_BASE),
+               .base           = DA8XX_TIMER64P1_BASE,
                .bottom_irq     = IRQ_DA8XX_TINT12_1,
                .top_irq        = IRQ_DA8XX_TINT34_1,
        },
        {
-               .base           = IO_ADDRESS(DA850_TIMER64P2_BASE),
+               .base           = DA850_TIMER64P2_BASE,
                .bottom_irq     = IRQ_DA850_TINT12_2,
                .top_irq        = IRQ_DA850_TINT34_2,
        },
        {
-               .base           = IO_ADDRESS(DA850_TIMER64P3_BASE),
+               .base           = DA850_TIMER64P3_BASE,
                .bottom_irq     = IRQ_DA850_TINT12_3,
                .top_irq        = IRQ_DA850_TINT34_3,
        },
@@ -1072,31 +1070,37 @@ no_ddrpll_mem:
 static struct davinci_soc_info davinci_soc_info_da850 = {
        .io_desc                = da850_io_desc,
        .io_desc_num            = ARRAY_SIZE(da850_io_desc),
+       .jtag_id_reg            = DA8XX_SYSCFG0_BASE + DA8XX_JTAG_ID_REG,
        .ids                    = da850_ids,
        .ids_num                = ARRAY_SIZE(da850_ids),
        .cpu_clks               = da850_clks,
        .psc_bases              = da850_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(da850_psc_bases),
+       .pinmux_base            = DA8XX_SYSCFG0_BASE + 0x120,
        .pinmux_pins            = da850_pins,
        .pinmux_pins_num        = ARRAY_SIZE(da850_pins),
-       .intc_base              = (void __iomem *)DA8XX_CP_INTC_VIRT,
+       .intc_base              = DA8XX_CP_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_CP_INTC,
        .intc_irq_prios         = da850_default_priorities,
        .intc_irq_num           = DA850_N_CP_INTC_IRQ,
        .timer_info             = &da850_timer_info,
-       .gpio_base              = IO_ADDRESS(DA8XX_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DA8XX_GPIO_BASE,
        .gpio_num               = 144,
        .gpio_irq               = IRQ_DA8XX_GPIO0,
        .serial_dev             = &da8xx_serial_device,
        .emac_pdata             = &da8xx_emac_pdata,
        .sram_dma               = DA8XX_ARM_RAM_BASE,
        .sram_len               = SZ_8K,
+       .reset_device           = &da8xx_wdt_device,
 };
 
 void __init da850_init(void)
 {
        unsigned int v;
 
+       davinci_common_init(&davinci_soc_info_da850);
+
        da8xx_syscfg0_base = ioremap(DA8XX_SYSCFG0_BASE, SZ_4K);
        if (WARN(!da8xx_syscfg0_base, "Unable to map syscfg0 module"))
                return;
@@ -1105,12 +1109,6 @@ void __init da850_init(void)
        if (WARN(!da8xx_syscfg1_base, "Unable to map syscfg1 module"))
                return;
 
-       davinci_soc_info_da850.jtag_id_base =
-                                       DA8XX_SYSCFG0_VIRT(DA8XX_JTAG_ID_REG);
-       davinci_soc_info_da850.pinmux_base = DA8XX_SYSCFG0_VIRT(0x120);
-
-       davinci_common_init(&davinci_soc_info_da850);
-
        /*
         * Move the clock source of Async3 domain to PLL1 SYSCLK2.
         * This helps keeping the peripherals on this domain insulated
index 0a96791..8cda729 100644 (file)
@@ -326,7 +326,7 @@ static struct resource da8xx_watchdog_resources[] = {
        },
 };
 
-struct platform_device davinci_wdt_device = {
+struct platform_device da8xx_wdt_device = {
        .name           = "watchdog",
        .id             = -1,
        .num_resources  = ARRAY_SIZE(da8xx_watchdog_resources),
@@ -335,7 +335,7 @@ struct platform_device davinci_wdt_device = {
 
 int __init da8xx_register_watchdog(void)
 {
-       return platform_device_register(&davinci_wdt_device);
+       return platform_device_register(&da8xx_wdt_device);
 }
 
 static struct resource da8xx_emac_resources[] = {
@@ -584,10 +584,17 @@ static struct platform_device da8xx_rtc_device = {
 int da8xx_register_rtc(void)
 {
        int ret;
+       void __iomem *base;
+
+       base = ioremap(DA8XX_RTC_BASE, SZ_4K);
+       if (WARN_ON(!base))
+               return -ENOMEM;
 
        /* Unlock the rtc's registers */
-       __raw_writel(0x83e70b13, IO_ADDRESS(DA8XX_RTC_BASE + 0x6c));
-       __raw_writel(0x95a4f1e0, IO_ADDRESS(DA8XX_RTC_BASE + 0x70));
+       __raw_writel(0x83e70b13, base + 0x6c);
+       __raw_writel(0x95a4f1e0, base + 0x70);
+
+       iounmap(base);
 
        ret = platform_device_register(&da8xx_rtc_device);
        if (!ret)
index 1479496..8b7201e 100644 (file)
 #include <mach/mmc.h>
 #include <mach/time.h>
 
+#include "clock.h"
+
 #define DAVINCI_I2C_BASE            0x01C21000
+#define DAVINCI_ATA_BASE            0x01C66000
 #define DAVINCI_MMCSD0_BASE         0x01E10000
 #define DM355_MMCSD0_BASE           0x01E11000
 #define DM355_MMCSD1_BASE           0x01E00000
@@ -58,6 +61,49 @@ void __init davinci_init_i2c(struct davinci_i2c_platform_data *pdata)
        (void) platform_device_register(&davinci_i2c_device);
 }
 
+static struct resource ide_resources[] = {
+       {
+               .start          = DAVINCI_ATA_BASE,
+               .end            = DAVINCI_ATA_BASE + 0x7ff,
+               .flags          = IORESOURCE_MEM,
+       },
+       {
+               .start          = IRQ_IDE,
+               .end            = IRQ_IDE,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static u64 ide_dma_mask = DMA_BIT_MASK(32);
+
+static struct platform_device ide_device = {
+       .name           = "palm_bk3710",
+       .id             = -1,
+       .resource       = ide_resources,
+       .num_resources  = ARRAY_SIZE(ide_resources),
+       .dev = {
+               .dma_mask               = &ide_dma_mask,
+               .coherent_dma_mask      = DMA_BIT_MASK(32),
+       },
+};
+
+void __init davinci_init_ide(void)
+{
+       if (cpu_is_davinci_dm644x()) {
+               davinci_cfg_reg(DM644X_HPIEN_DISABLE);
+               davinci_cfg_reg(DM644X_ATAEN);
+               davinci_cfg_reg(DM644X_HDIREN);
+       } else if (cpu_is_davinci_dm646x()) {
+               /* IRQ_DM646X_IDE is the same as IRQ_IDE */
+               davinci_cfg_reg(DM646X_ATAEN);
+       } else {
+               WARN_ON(1);
+               return;
+       }
+
+       platform_device_register(&ide_device);
+}
+
 #if    defined(CONFIG_MMC_DAVINCI) || defined(CONFIG_MMC_DAVINCI_MODULE)
 
 static u64 mmcsd0_dma_mask = DMA_BIT_MASK(32);
@@ -251,12 +297,12 @@ static void davinci_init_wdt(void)
 
 struct davinci_timer_instance davinci_timer_instance[2] = {
        {
-               .base           = IO_ADDRESS(DAVINCI_TIMER0_BASE),
+               .base           = DAVINCI_TIMER0_BASE,
                .bottom_irq     = IRQ_TINT0_TINT12,
                .top_irq        = IRQ_TINT0_TINT34,
        },
        {
-               .base           = IO_ADDRESS(DAVINCI_TIMER1_BASE),
+               .base           = DAVINCI_TIMER1_BASE,
                .bottom_irq     = IRQ_TINT1_TINT12,
                .top_irq        = IRQ_TINT1_TINT34,
        },
index 3dc0a88..3834781 100644 (file)
@@ -450,11 +450,6 @@ void __init dm355_init_spi0(unsigned chipselect_mask,
 
 /*----------------------------------------------------------------------*/
 
-#define PINMUX0                0x00
-#define PINMUX1                0x04
-#define PINMUX2                0x08
-#define PINMUX3                0x0c
-#define PINMUX4                0x10
 #define INTMUX         0x18
 #define EVTMUX         0x1c
 
@@ -788,9 +783,7 @@ static struct davinci_id dm355_ids[] = {
        },
 };
 
-static void __iomem *dm355_psc_bases[] = {
-       IO_ADDRESS(DAVINCI_PWR_SLEEP_CNTRL_BASE),
-};
+static u32 dm355_psc_bases[] = { DAVINCI_PWR_SLEEP_CNTRL_BASE };
 
 /*
  * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
@@ -798,7 +791,7 @@ static void __iomem *dm355_psc_bases[] = {
  * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
  * T1_TOP: Timer 1, top   :  <unused>
  */
-struct davinci_timer_info dm355_timer_info = {
+static struct davinci_timer_info dm355_timer_info = {
        .timers         = davinci_timer_instance,
        .clockevent_id  = T0_BOT,
        .clocksource_id = T0_TOP,
@@ -845,26 +838,28 @@ static struct platform_device dm355_serial_device = {
 static struct davinci_soc_info davinci_soc_info_dm355 = {
        .io_desc                = dm355_io_desc,
        .io_desc_num            = ARRAY_SIZE(dm355_io_desc),
-       .jtag_id_base           = IO_ADDRESS(0x01c40028),
+       .jtag_id_reg            = 0x01c40028,
        .ids                    = dm355_ids,
        .ids_num                = ARRAY_SIZE(dm355_ids),
        .cpu_clks               = dm355_clks,
        .psc_bases              = dm355_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(dm355_psc_bases),
-       .pinmux_base            = IO_ADDRESS(DAVINCI_SYSTEM_MODULE_BASE),
+       .pinmux_base            = DAVINCI_SYSTEM_MODULE_BASE,
        .pinmux_pins            = dm355_pins,
        .pinmux_pins_num        = ARRAY_SIZE(dm355_pins),
-       .intc_base              = IO_ADDRESS(DAVINCI_ARM_INTC_BASE),
+       .intc_base              = DAVINCI_ARM_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_AINTC,
        .intc_irq_prios         = dm355_default_priorities,
        .intc_irq_num           = DAVINCI_N_AINTC_IRQ,
        .timer_info             = &dm355_timer_info,
-       .gpio_base              = IO_ADDRESS(DAVINCI_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DAVINCI_GPIO_BASE,
        .gpio_num               = 104,
        .gpio_irq               = IRQ_DM355_GPIOBNK0,
        .serial_dev             = &dm355_serial_device,
        .sram_dma               = 0x00010000,
        .sram_len               = SZ_32K,
+       .reset_device           = &davinci_wdt_device,
 };
 
 void __init dm355_init_asp1(u32 evt_enable, struct snd_platform_data *pdata)
index 0d6ee58..a146849 100644 (file)
@@ -467,11 +467,6 @@ static struct clk_lookup dm365_clks[] = {
 
 /*----------------------------------------------------------------------*/
 
-#define PINMUX0                0x00
-#define PINMUX1                0x04
-#define PINMUX2                0x08
-#define PINMUX3                0x0c
-#define PINMUX4                0x10
 #define INTMUX         0x18
 #define EVTMUX         0x1c
 
@@ -490,11 +485,14 @@ MUX_CFG(DM365,    SD1_DATA0,      4,   22,    3,    1,     false)
 MUX_CFG(DM365, I2C_SDA,        3,   23,    3,    2,     false)
 MUX_CFG(DM365, I2C_SCL,        3,   21,    3,    2,     false)
 
-MUX_CFG(DM365, AEMIF_AR,       2,   0,     3,    1,     false)
+MUX_CFG(DM365, AEMIF_AR_A14,   2,   0,     3,    1,     false)
+MUX_CFG(DM365, AEMIF_AR_BA0,   2,   0,     3,    2,     false)
 MUX_CFG(DM365, AEMIF_A3,       2,   2,     3,    1,     false)
 MUX_CFG(DM365, AEMIF_A7,       2,   4,     3,    1,     false)
 MUX_CFG(DM365, AEMIF_D15_8,    2,   6,     1,    1,     false)
 MUX_CFG(DM365, AEMIF_CE0,      2,   7,     1,    0,     false)
+MUX_CFG(DM365, AEMIF_CE1,      2,   8,     1,    0,     false)
+MUX_CFG(DM365, AEMIF_WE_OE,    2,   9,     1,    0,     false)
 
 MUX_CFG(DM365, MCBSP0_BDX,     0,   23,    1,    1,     false)
 MUX_CFG(DM365, MCBSP0_X,       0,   22,    1,    1,     false)
@@ -573,9 +571,17 @@ MUX_CFG(DM365,     SPI4_SDO,       4,   16,    3,    1,     false)
 MUX_CFG(DM365, SPI4_SDENA0,    4,   20,    3,    1,     false)
 MUX_CFG(DM365, SPI4_SDENA1,    4,   16,    3,    2,     false)
 
+MUX_CFG(DM365, CLKOUT0,        4,   20,    3,    3,     false)
+MUX_CFG(DM365, CLKOUT1,        4,   16,    3,    3,     false)
+MUX_CFG(DM365, CLKOUT2,        4,   8,     3,    3,     false)
+
 MUX_CFG(DM365, GPIO20,         3,   21,    3,    0,     false)
+MUX_CFG(DM365, GPIO30,         4,   6,     3,    0,     false)
+MUX_CFG(DM365, GPIO31,         4,   8,     3,    0,     false)
+MUX_CFG(DM365, GPIO32,         4,   10,    3,    0,     false)
 MUX_CFG(DM365, GPIO33,         4,   12,    3,    0,     false)
 MUX_CFG(DM365, GPIO40,         4,   26,    3,    0,     false)
+MUX_CFG(DM365, GPIO64_57,      2,   6,     1,    0,     false)
 
 MUX_CFG(DM365, VOUT_FIELD,     1,   18,    3,    1,     false)
 MUX_CFG(DM365, VOUT_FIELD_G81, 1,   18,    3,    0,     false)
@@ -1006,11 +1012,9 @@ static struct davinci_id dm365_ids[] = {
        },
 };
 
-static void __iomem *dm365_psc_bases[] = {
-       IO_ADDRESS(DAVINCI_PWR_SLEEP_CNTRL_BASE),
-};
+static u32 dm365_psc_bases[] = { DAVINCI_PWR_SLEEP_CNTRL_BASE };
 
-struct davinci_timer_info dm365_timer_info = {
+static struct davinci_timer_info dm365_timer_info = {
        .timers         = davinci_timer_instance,
        .clockevent_id  = T0_BOT,
        .clocksource_id = T0_TOP,
@@ -1049,21 +1053,22 @@ static struct platform_device dm365_serial_device = {
 static struct davinci_soc_info davinci_soc_info_dm365 = {
        .io_desc                = dm365_io_desc,
        .io_desc_num            = ARRAY_SIZE(dm365_io_desc),
-       .jtag_id_base           = IO_ADDRESS(0x01c40028),
+       .jtag_id_reg            = 0x01c40028,
        .ids                    = dm365_ids,
        .ids_num                = ARRAY_SIZE(dm365_ids),
        .cpu_clks               = dm365_clks,
        .psc_bases              = dm365_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(dm365_psc_bases),
-       .pinmux_base            = IO_ADDRESS(DAVINCI_SYSTEM_MODULE_BASE),
+       .pinmux_base            = DAVINCI_SYSTEM_MODULE_BASE,
        .pinmux_pins            = dm365_pins,
        .pinmux_pins_num        = ARRAY_SIZE(dm365_pins),
-       .intc_base              = IO_ADDRESS(DAVINCI_ARM_INTC_BASE),
+       .intc_base              = DAVINCI_ARM_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_AINTC,
        .intc_irq_prios         = dm365_default_priorities,
        .intc_irq_num           = DAVINCI_N_AINTC_IRQ,
        .timer_info             = &dm365_timer_info,
-       .gpio_base              = IO_ADDRESS(DAVINCI_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DAVINCI_GPIO_BASE,
        .gpio_num               = 104,
        .gpio_irq               = IRQ_DM365_GPIO0,
        .gpio_unbanked          = 8,    /* really 16 ... skip muxed GPIOs */
@@ -1071,6 +1076,7 @@ static struct davinci_soc_info davinci_soc_info_dm365 = {
        .emac_pdata             = &dm365_emac_pdata,
        .sram_dma               = 0x00010000,
        .sram_len               = SZ_32K,
+       .reset_device           = &davinci_wdt_device,
 };
 
 void __init dm365_init_asp(struct snd_platform_data *pdata)
index 2f2ae8b..7ad1520 100644 (file)
@@ -277,7 +277,7 @@ static struct clk timer2_clk = {
        .usecount = 1,              /* REVISIT: why cant' this be disabled? */
 };
 
-struct clk_lookup dm644x_clks[] = {
+static struct clk_lookup dm644x_clks[] = {
        CLK(NULL, "ref", &ref_clk),
        CLK(NULL, "pll1", &pll1_clk),
        CLK(NULL, "pll1_sysclk1", &pll1_sysclk1),
@@ -350,9 +350,6 @@ static struct platform_device dm644x_emac_device = {
        .resource       = dm644x_emac_resources,
 };
 
-#define PINMUX0                0x00
-#define PINMUX1                0x04
-
 /*
  * Device specific mux setup
  *
@@ -677,9 +674,7 @@ static struct davinci_id dm644x_ids[] = {
        },
 };
 
-static void __iomem *dm644x_psc_bases[] = {
-       IO_ADDRESS(DAVINCI_PWR_SLEEP_CNTRL_BASE),
-};
+static u32 dm644x_psc_bases[] = { DAVINCI_PWR_SLEEP_CNTRL_BASE };
 
 /*
  * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
@@ -687,7 +682,7 @@ static void __iomem *dm644x_psc_bases[] = {
  * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
  * T1_TOP: Timer 1, top   :  <unused>
  */
-struct davinci_timer_info dm644x_timer_info = {
+static struct davinci_timer_info dm644x_timer_info = {
        .timers         = davinci_timer_instance,
        .clockevent_id  = T0_BOT,
        .clocksource_id = T0_TOP,
@@ -734,27 +729,29 @@ static struct platform_device dm644x_serial_device = {
 static struct davinci_soc_info davinci_soc_info_dm644x = {
        .io_desc                = dm644x_io_desc,
        .io_desc_num            = ARRAY_SIZE(dm644x_io_desc),
-       .jtag_id_base           = IO_ADDRESS(0x01c40028),
+       .jtag_id_reg            = 0x01c40028,
        .ids                    = dm644x_ids,
        .ids_num                = ARRAY_SIZE(dm644x_ids),
        .cpu_clks               = dm644x_clks,
        .psc_bases              = dm644x_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(dm644x_psc_bases),
-       .pinmux_base            = IO_ADDRESS(DAVINCI_SYSTEM_MODULE_BASE),
+       .pinmux_base            = DAVINCI_SYSTEM_MODULE_BASE,
        .pinmux_pins            = dm644x_pins,
        .pinmux_pins_num        = ARRAY_SIZE(dm644x_pins),
-       .intc_base              = IO_ADDRESS(DAVINCI_ARM_INTC_BASE),
+       .intc_base              = DAVINCI_ARM_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_AINTC,
        .intc_irq_prios         = dm644x_default_priorities,
        .intc_irq_num           = DAVINCI_N_AINTC_IRQ,
        .timer_info             = &dm644x_timer_info,
-       .gpio_base              = IO_ADDRESS(DAVINCI_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DAVINCI_GPIO_BASE,
        .gpio_num               = 71,
        .gpio_irq               = IRQ_GPIOBNK0,
        .serial_dev             = &dm644x_serial_device,
        .emac_pdata             = &dm644x_emac_pdata,
        .sram_dma               = 0x00008000,
        .sram_len               = SZ_16K,
+       .reset_device           = &davinci_wdt_device,
 };
 
 void __init dm644x_init_asp(struct snd_platform_data *pdata)
index 893baf4..9404565 100644 (file)
@@ -311,7 +311,7 @@ static struct clk vpif1_clk = {
        .flags = ALWAYS_ENABLED,
 };
 
-struct clk_lookup dm646x_clks[] = {
+static struct clk_lookup dm646x_clks[] = {
        CLK(NULL, "ref", &ref_clk),
        CLK(NULL, "aux", &aux_clkin),
        CLK(NULL, "pll1", &pll1_clk),
@@ -401,9 +401,6 @@ static struct platform_device dm646x_emac_device = {
        .resource       = dm646x_emac_resources,
 };
 
-#define PINMUX0                0x00
-#define PINMUX1                0x04
-
 /*
  * Device specific mux setup
  *
@@ -596,32 +593,6 @@ static struct platform_device dm646x_edma_device = {
        .resource               = edma_resources,
 };
 
-static struct resource ide_resources[] = {
-       {
-               .start          = DM646X_ATA_REG_BASE,
-               .end            = DM646X_ATA_REG_BASE + 0x7ff,
-               .flags          = IORESOURCE_MEM,
-       },
-       {
-               .start          = IRQ_DM646X_IDE,
-               .end            = IRQ_DM646X_IDE,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static u64 ide_dma_mask = DMA_BIT_MASK(32);
-
-static struct platform_device ide_dev = {
-       .name           = "palm_bk3710",
-       .id             = -1,
-       .resource       = ide_resources,
-       .num_resources  = ARRAY_SIZE(ide_resources),
-       .dev = {
-               .dma_mask               = &ide_dma_mask,
-               .coherent_dma_mask      = DMA_BIT_MASK(32),
-       },
-};
-
 static struct resource dm646x_mcasp0_resources[] = {
        {
                .name   = "mcasp0",
@@ -787,9 +758,7 @@ static struct davinci_id dm646x_ids[] = {
        },
 };
 
-static void __iomem *dm646x_psc_bases[] = {
-       IO_ADDRESS(DAVINCI_PWR_SLEEP_CNTRL_BASE),
-};
+static u32 dm646x_psc_bases[] = { DAVINCI_PWR_SLEEP_CNTRL_BASE };
 
 /*
  * T0_BOT: Timer 0, bottom:  clockevent source for hrtimers
@@ -797,7 +766,7 @@ static void __iomem *dm646x_psc_bases[] = {
  * T1_BOT: Timer 1, bottom:  (used by DSP in TI DSPLink code)
  * T1_TOP: Timer 1, top   :  <unused>
  */
-struct davinci_timer_info dm646x_timer_info = {
+static struct davinci_timer_info dm646x_timer_info = {
        .timers         = davinci_timer_instance,
        .clockevent_id  = T0_BOT,
        .clocksource_id = T0_TOP,
@@ -844,35 +813,31 @@ static struct platform_device dm646x_serial_device = {
 static struct davinci_soc_info davinci_soc_info_dm646x = {
        .io_desc                = dm646x_io_desc,
        .io_desc_num            = ARRAY_SIZE(dm646x_io_desc),
-       .jtag_id_base           = IO_ADDRESS(0x01c40028),
+       .jtag_id_reg            = 0x01c40028,
        .ids                    = dm646x_ids,
        .ids_num                = ARRAY_SIZE(dm646x_ids),
        .cpu_clks               = dm646x_clks,
        .psc_bases              = dm646x_psc_bases,
        .psc_bases_num          = ARRAY_SIZE(dm646x_psc_bases),
-       .pinmux_base            = IO_ADDRESS(DAVINCI_SYSTEM_MODULE_BASE),
+       .pinmux_base            = DAVINCI_SYSTEM_MODULE_BASE,
        .pinmux_pins            = dm646x_pins,
        .pinmux_pins_num        = ARRAY_SIZE(dm646x_pins),
-       .intc_base              = IO_ADDRESS(DAVINCI_ARM_INTC_BASE),
+       .intc_base              = DAVINCI_ARM_INTC_BASE,
        .intc_type              = DAVINCI_INTC_TYPE_AINTC,
        .intc_irq_prios         = dm646x_default_priorities,
        .intc_irq_num           = DAVINCI_N_AINTC_IRQ,
        .timer_info             = &dm646x_timer_info,
-       .gpio_base              = IO_ADDRESS(DAVINCI_GPIO_BASE),
+       .gpio_type              = GPIO_TYPE_DAVINCI,
+       .gpio_base              = DAVINCI_GPIO_BASE,
        .gpio_num               = 43, /* Only 33 usable */
        .gpio_irq               = IRQ_DM646X_GPIOBNK0,
        .serial_dev             = &dm646x_serial_device,
        .emac_pdata             = &dm646x_emac_pdata,
        .sram_dma               = 0x10010000,
        .sram_len               = SZ_32K,
+       .reset_device           = &davinci_wdt_device,
 };
 
-void __init dm646x_init_ide()
-{
-       davinci_cfg_reg(DM646X_ATAEN);
-       platform_device_register(&ide_dev);
-}
-
 void __init dm646x_init_mcasp0(struct snd_platform_data *pdata)
 {
        dm646x_mcasp0_device.dev.platform_data = pdata;
index 5313738..d33827a 100644 (file)
@@ -243,7 +243,7 @@ struct edma {
        } intr_data[EDMA_MAX_DMACH];
 };
 
-static struct edma *edma_info[EDMA_MAX_CC];
+static struct edma *edma_cc[EDMA_MAX_CC];
 static int arch_num_cc;
 
 /* dummy param set used to (re)initialize parameter RAM slots */
@@ -261,7 +261,7 @@ static void map_dmach_queue(unsigned ctlr, unsigned ch_no,
 
        /* default to low priority queue */
        if (queue_no == EVENTQ_DEFAULT)
-               queue_no = edma_info[ctlr]->default_queue;
+               queue_no = edma_cc[ctlr]->default_queue;
 
        queue_no &= 7;
        edma_modify_array(ctlr, EDMA_DMAQNUM, (ch_no >> 3),
@@ -310,29 +310,27 @@ setup_dma_interrupt(unsigned lch,
        ctlr = EDMA_CTLR(lch);
        lch = EDMA_CHAN_SLOT(lch);
 
-       if (!callback) {
+       if (!callback)
                edma_shadow0_write_array(ctlr, SH_IECR, lch >> 5,
-                               (1 << (lch & 0x1f)));
-       }
+                               BIT(lch & 0x1f));
 
-       edma_info[ctlr]->intr_data[lch].callback = callback;
-       edma_info[ctlr]->intr_data[lch].data = data;
+       edma_cc[ctlr]->intr_data[lch].callback = callback;
+       edma_cc[ctlr]->intr_data[lch].data = data;
 
        if (callback) {
                edma_shadow0_write_array(ctlr, SH_ICR, lch >> 5,
-                               (1 << (lch & 0x1f)));
+                               BIT(lch & 0x1f));
                edma_shadow0_write_array(ctlr, SH_IESR, lch >> 5,
-                               (1 << (lch & 0x1f)));
+                               BIT(lch & 0x1f));
        }
 }
 
 static int irq2ctlr(int irq)
 {
-       if (irq >= edma_info[0]->irq_res_start &&
-               irq <= edma_info[0]->irq_res_end)
+       if (irq >= edma_cc[0]->irq_res_start && irq <= edma_cc[0]->irq_res_end)
                return 0;
-       else if (irq >= edma_info[1]->irq_res_start &&
-               irq <= edma_info[1]->irq_res_end)
+       else if (irq >= edma_cc[1]->irq_res_start &&
+               irq <= edma_cc[1]->irq_res_end)
                return 1;
 
        return -1;
@@ -353,15 +351,17 @@ static irqreturn_t dma_irq_handler(int irq, void *data)
 
        dev_dbg(data, "dma_irq_handler\n");
 
-       if ((edma_shadow0_read_array(ctlr, SH_IPR, 0) == 0)
-           && (edma_shadow0_read_array(ctlr, SH_IPR, 1) == 0))
+       if ((edma_shadow0_read_array(ctlr, SH_IPR, 0) == 0) &&
+           (edma_shadow0_read_array(ctlr, SH_IPR, 1) == 0))
                return IRQ_NONE;
 
        while (1) {
                int j;
-               if (edma_shadow0_read_array(ctlr, SH_IPR, 0))
+               if (edma_shadow0_read_array(ctlr, SH_IPR, 0) &
+                               edma_shadow0_read_array(ctlr, SH_IER, 0))
                        j = 0;
-               else if (edma_shadow0_read_array(ctlr, SH_IPR, 1))
+               else if (edma_shadow0_read_array(ctlr, SH_IPR, 1) &
+                               edma_shadow0_read_array(ctlr, SH_IER, 1))
                        j = 1;
                else
                        break;
@@ -369,17 +369,17 @@ static irqreturn_t dma_irq_handler(int irq, void *data)
                                edma_shadow0_read_array(ctlr, SH_IPR, j));
                for (i = 0; i < 32; i++) {
                        int k = (j << 5) + i;
-                       if (edma_shadow0_read_array(ctlr, SH_IPR, j) &
-                                                       (1 << i)) {
+                       if ((edma_shadow0_read_array(ctlr, SH_IPR, j) & BIT(i))
+                                       && (edma_shadow0_read_array(ctlr,
+                                                       SH_IER, j) & BIT(i))) {
                                /* Clear the corresponding IPR bits */
                                edma_shadow0_write_array(ctlr, SH_ICR, j,
-                                                       (1 << i));
-                               if (edma_info[ctlr]->intr_data[k].callback) {
-                                       edma_info[ctlr]->intr_data[k].callback(
+                                                       BIT(i));
+                               if (edma_cc[ctlr]->intr_data[k].callback)
+                                       edma_cc[ctlr]->intr_data[k].callback(
                                                k, DMA_COMPLETE,
-                                               edma_info[ctlr]->intr_data[k].
+                                               edma_cc[ctlr]->intr_data[k].
                                                data);
-                               }
                        }
                }
                cnt++;
@@ -423,19 +423,19 @@ static irqreturn_t dma_ccerr_handler(int irq, void *data)
                        for (i = 0; i < 32; i++) {
                                int k = (j << 5) + i;
                                if (edma_read_array(ctlr, EDMA_EMR, j) &
-                                                       (1 << i)) {
+                                                       BIT(i)) {
                                        /* Clear the corresponding EMR bits */
                                        edma_write_array(ctlr, EDMA_EMCR, j,
-                                                       1 << i);
+                                                       BIT(i));
                                        /* Clear any SER */
                                        edma_shadow0_write_array(ctlr, SH_SECR,
-                                                               j, (1 << i));
-                                       if (edma_info[ctlr]->intr_data[k].
+                                                               j, BIT(i));
+                                       if (edma_cc[ctlr]->intr_data[k].
                                                                callback) {
-                                               edma_info[ctlr]->intr_data[k].
+                                               edma_cc[ctlr]->intr_data[k].
                                                callback(k,
                                                DMA_CC_ERROR,
-                                               edma_info[ctlr]->intr_data
+                                               edma_cc[ctlr]->intr_data
                                                [k].data);
                                        }
                                }
@@ -444,11 +444,11 @@ static irqreturn_t dma_ccerr_handler(int irq, void *data)
                        dev_dbg(data, "QEMR %02x\n",
                                edma_read(ctlr, EDMA_QEMR));
                        for (i = 0; i < 8; i++) {
-                               if (edma_read(ctlr, EDMA_QEMR) & (1 << i)) {
+                               if (edma_read(ctlr, EDMA_QEMR) & BIT(i)) {
                                        /* Clear the corresponding IPR bits */
-                                       edma_write(ctlr, EDMA_QEMCR, 1 << i);
+                                       edma_write(ctlr, EDMA_QEMCR, BIT(i));
                                        edma_shadow0_write(ctlr, SH_QSECR,
-                                                               (1 << i));
+                                                               BIT(i));
 
                                        /* NOTE:  not reported!! */
                                }
@@ -460,20 +460,19 @@ static irqreturn_t dma_ccerr_handler(int irq, void *data)
                         * to just write CCERRCLR with CCERR value...
                         */
                        for (i = 0; i < 8; i++) {
-                               if (edma_read(ctlr, EDMA_CCERR) & (1 << i)) {
+                               if (edma_read(ctlr, EDMA_CCERR) & BIT(i)) {
                                        /* Clear the corresponding IPR bits */
-                                       edma_write(ctlr, EDMA_CCERRCLR, 1 << i);
+                                       edma_write(ctlr, EDMA_CCERRCLR, BIT(i));
 
                                        /* NOTE:  not reported!! */
                                }
                        }
                }
-               if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0)
-                   && (edma_read_array(ctlr, EDMA_EMR, 1) == 0)
-                   && (edma_read(ctlr, EDMA_QEMR) == 0)
-                   && (edma_read(ctlr, EDMA_CCERR) == 0)) {
+               if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0) &&
+                   (edma_read_array(ctlr, EDMA_EMR, 1) == 0) &&
+                   (edma_read(ctlr, EDMA_QEMR) == 0) &&
+                   (edma_read(ctlr, EDMA_CCERR) == 0))
                        break;
-               }
                cnt++;
                if (cnt > 10)
                        break;
@@ -511,9 +510,9 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
        int stop_slot = start_slot;
        DECLARE_BITMAP(tmp_inuse, EDMA_MAX_PARAMENTRY);
 
-       for (i = start_slot; i < edma_info[ctlr]->num_slots; ++i) {
+       for (i = start_slot; i < edma_cc[ctlr]->num_slots; ++i) {
                j = EDMA_CHAN_SLOT(i);
-               if (!test_and_set_bit(j, edma_info[ctlr]->edma_inuse)) {
+               if (!test_and_set_bit(j, edma_cc[ctlr]->edma_inuse)) {
                        /* Record our current beginning slot */
                        if (count == num_slots)
                                stop_slot = i;
@@ -529,8 +528,9 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
                        if (id == EDMA_CONT_PARAMS_FIXED_EXACT) {
                                stop_slot = i;
                                break;
-                       } else
+                       } else {
                                count = num_slots;
+                       }
                }
        }
 
@@ -540,12 +540,12 @@ static int reserve_contiguous_slots(int ctlr, unsigned int id,
         * of contiguous parameter RAM slots but do not find the exact number
         * requested as we may reach the total number of parameter RAM slots
         */
-       if (i == edma_info[ctlr]->num_slots)
+       if (i == edma_cc[ctlr]->num_slots)
                stop_slot = i;
 
        for (j = start_slot; j < stop_slot; j++)
                if (test_bit(j, tmp_inuse))
-                       clear_bit(j, edma_info[ctlr]->edma_inuse);
+                       clear_bit(j, edma_cc[ctlr]->edma_inuse);
 
        if (count)
                return -EBUSY;
@@ -567,7 +567,7 @@ static int prepare_unused_channel_list(struct device *dev, void *data)
                                (int)pdev->resource[i].start >= 0) {
                        ctlr = EDMA_CTLR(pdev->resource[i].start);
                        clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
-                                       edma_info[ctlr]->edma_unused);
+                                       edma_cc[ctlr]->edma_unused);
                }
        }
 
@@ -641,14 +641,13 @@ int edma_alloc_channel(int channel,
                for (i = 0; i < arch_num_cc; i++) {
                        channel = 0;
                        for (;;) {
-                               channel = find_next_bit(edma_info[i]->
-                                               edma_unused,
-                                               edma_info[i]->num_channels,
+                               channel = find_next_bit(edma_cc[i]->edma_unused,
+                                               edma_cc[i]->num_channels,
                                                channel);
-                               if (channel == edma_info[i]->num_channels)
+                               if (channel == edma_cc[i]->num_channels)
                                        break;
                                if (!test_and_set_bit(channel,
-                                               edma_info[i]->edma_inuse)) {
+                                               edma_cc[i]->edma_inuse)) {
                                        done = 1;
                                        ctlr = i;
                                        break;
@@ -660,14 +659,14 @@ int edma_alloc_channel(int channel,
                }
                if (!done)
                        return -ENOMEM;
-       } else if (channel >= edma_info[ctlr]->num_channels) {
+       } else if (channel >= edma_cc[ctlr]->num_channels) {
                return -EINVAL;
-       } else if (test_and_set_bit(channel, edma_info[ctlr]->edma_inuse)) {
+       } else if (test_and_set_bit(channel, edma_cc[ctlr]->edma_inuse)) {
                return -EBUSY;
        }
 
        /* ensure access through shadow region 0 */
-       edma_or_array2(ctlr, EDMA_DRAE, 0, channel >> 5, 1 << (channel & 0x1f));
+       edma_or_array2(ctlr, EDMA_DRAE, 0, channel >> 5, BIT(channel & 0x1f));
 
        /* ensure no events are pending */
        edma_stop(EDMA_CTLR_CHAN(ctlr, channel));
@@ -703,7 +702,7 @@ void edma_free_channel(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel >= edma_info[ctlr]->num_channels)
+       if (channel >= edma_cc[ctlr]->num_channels)
                return;
 
        setup_dma_interrupt(channel, NULL, NULL);
@@ -711,7 +710,7 @@ void edma_free_channel(unsigned channel)
 
        memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(channel),
                        &dummy_paramset, PARM_SIZE);
-       clear_bit(channel, edma_info[ctlr]->edma_inuse);
+       clear_bit(channel, edma_cc[ctlr]->edma_inuse);
 }
 EXPORT_SYMBOL(edma_free_channel);
 
@@ -735,20 +734,19 @@ int edma_alloc_slot(unsigned ctlr, int slot)
                slot = EDMA_CHAN_SLOT(slot);
 
        if (slot < 0) {
-               slot = edma_info[ctlr]->num_channels;
+               slot = edma_cc[ctlr]->num_channels;
                for (;;) {
-                       slot = find_next_zero_bit(edma_info[ctlr]->edma_inuse,
-                                       edma_info[ctlr]->num_slots, slot);
-                       if (slot == edma_info[ctlr]->num_slots)
+                       slot = find_next_zero_bit(edma_cc[ctlr]->edma_inuse,
+                                       edma_cc[ctlr]->num_slots, slot);
+                       if (slot == edma_cc[ctlr]->num_slots)
                                return -ENOMEM;
-                       if (!test_and_set_bit(slot,
-                                               edma_info[ctlr]->edma_inuse))
+                       if (!test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse))
                                break;
                }
-       } else if (slot < edma_info[ctlr]->num_channels ||
-                       slot >= edma_info[ctlr]->num_slots) {
+       } else if (slot < edma_cc[ctlr]->num_channels ||
+                       slot >= edma_cc[ctlr]->num_slots) {
                return -EINVAL;
-       } else if (test_and_set_bit(slot, edma_info[ctlr]->edma_inuse)) {
+       } else if (test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse)) {
                return -EBUSY;
        }
 
@@ -774,13 +772,13 @@ void edma_free_slot(unsigned slot)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_channels ||
-               slot >= edma_info[ctlr]->num_slots)
+       if (slot < edma_cc[ctlr]->num_channels ||
+               slot >= edma_cc[ctlr]->num_slots)
                return;
 
        memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
                        &dummy_paramset, PARM_SIZE);
-       clear_bit(slot, edma_info[ctlr]->edma_inuse);
+       clear_bit(slot, edma_cc[ctlr]->edma_inuse);
 }
 EXPORT_SYMBOL(edma_free_slot);
 
@@ -818,8 +816,8 @@ int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count)
         * of slots
         */
        if ((id != EDMA_CONT_PARAMS_ANY) &&
-               (slot < edma_info[ctlr]->num_channels ||
-               slot >= edma_info[ctlr]->num_slots))
+               (slot < edma_cc[ctlr]->num_channels ||
+               slot >= edma_cc[ctlr]->num_slots))
                return -EINVAL;
 
        /*
@@ -828,13 +826,13 @@ int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count)
         * channels
         */
        if (count < 1 || count >
-               (edma_info[ctlr]->num_slots - edma_info[ctlr]->num_channels))
+               (edma_cc[ctlr]->num_slots - edma_cc[ctlr]->num_channels))
                return -EINVAL;
 
        switch (id) {
        case EDMA_CONT_PARAMS_ANY:
                return reserve_contiguous_slots(ctlr, id, count,
-                                                edma_info[ctlr]->num_channels);
+                                                edma_cc[ctlr]->num_channels);
        case EDMA_CONT_PARAMS_FIXED_EXACT:
        case EDMA_CONT_PARAMS_FIXED_NOT_EXACT:
                return reserve_contiguous_slots(ctlr, id, count, slot);
@@ -866,8 +864,8 @@ int edma_free_cont_slots(unsigned slot, int count)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_channels ||
-               slot >= edma_info[ctlr]->num_slots ||
+       if (slot < edma_cc[ctlr]->num_channels ||
+               slot >= edma_cc[ctlr]->num_slots ||
                count < 1)
                return -EINVAL;
 
@@ -877,7 +875,7 @@ int edma_free_cont_slots(unsigned slot, int count)
 
                memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot_to_free),
                        &dummy_paramset, PARM_SIZE);
-               clear_bit(slot_to_free, edma_info[ctlr]->edma_inuse);
+               clear_bit(slot_to_free, edma_cc[ctlr]->edma_inuse);
        }
 
        return 0;
@@ -907,7 +905,7 @@ void edma_set_src(unsigned slot, dma_addr_t src_port,
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_slots) {
+       if (slot < edma_cc[ctlr]->num_slots) {
                unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
 
                if (mode) {
@@ -945,7 +943,7 @@ void edma_set_dest(unsigned slot, dma_addr_t dest_port,
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_slots) {
+       if (slot < edma_cc[ctlr]->num_slots) {
                unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
 
                if (mode) {
@@ -1005,7 +1003,7 @@ void edma_set_src_index(unsigned slot, s16 src_bidx, s16 src_cidx)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_slots) {
+       if (slot < edma_cc[ctlr]->num_slots) {
                edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
                                0xffff0000, src_bidx);
                edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
@@ -1031,7 +1029,7 @@ void edma_set_dest_index(unsigned slot, s16 dest_bidx, s16 dest_cidx)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_slots) {
+       if (slot < edma_cc[ctlr]->num_slots) {
                edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
                                0x0000ffff, dest_bidx << 16);
                edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
@@ -1078,7 +1076,7 @@ void edma_set_transfer_params(unsigned slot,
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot < edma_info[ctlr]->num_slots) {
+       if (slot < edma_cc[ctlr]->num_slots) {
                edma_parm_modify(ctlr, PARM_LINK_BCNTRLD, slot,
                                0x0000ffff, bcnt_rld << 16);
                if (sync_mode == ASYNC)
@@ -1108,9 +1106,9 @@ void edma_link(unsigned from, unsigned to)
        ctlr_to = EDMA_CTLR(to);
        to = EDMA_CHAN_SLOT(to);
 
-       if (from >= edma_info[ctlr_from]->num_slots)
+       if (from >= edma_cc[ctlr_from]->num_slots)
                return;
-       if (to >= edma_info[ctlr_to]->num_slots)
+       if (to >= edma_cc[ctlr_to]->num_slots)
                return;
        edma_parm_modify(ctlr_from, PARM_LINK_BCNTRLD, from, 0xffff0000,
                                PARM_OFFSET(to));
@@ -1131,7 +1129,7 @@ void edma_unlink(unsigned from)
        ctlr = EDMA_CTLR(from);
        from = EDMA_CHAN_SLOT(from);
 
-       if (from >= edma_info[ctlr]->num_slots)
+       if (from >= edma_cc[ctlr]->num_slots)
                return;
        edma_parm_or(ctlr, PARM_LINK_BCNTRLD, from, 0xffff);
 }
@@ -1158,7 +1156,7 @@ void edma_write_slot(unsigned slot, const struct edmacc_param *param)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot >= edma_info[ctlr]->num_slots)
+       if (slot >= edma_cc[ctlr]->num_slots)
                return;
        memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot), param,
                        PARM_SIZE);
@@ -1180,7 +1178,7 @@ void edma_read_slot(unsigned slot, struct edmacc_param *param)
        ctlr = EDMA_CTLR(slot);
        slot = EDMA_CHAN_SLOT(slot);
 
-       if (slot >= edma_info[ctlr]->num_slots)
+       if (slot >= edma_cc[ctlr]->num_slots)
                return;
        memcpy_fromio(param, edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
                        PARM_SIZE);
@@ -1205,8 +1203,8 @@ void edma_pause(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel < edma_info[ctlr]->num_channels) {
-               unsigned int mask = (1 << (channel & 0x1f));
+       if (channel < edma_cc[ctlr]->num_channels) {
+               unsigned int mask = BIT(channel & 0x1f);
 
                edma_shadow0_write_array(ctlr, SH_EECR, channel >> 5, mask);
        }
@@ -1226,8 +1224,8 @@ void edma_resume(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel < edma_info[ctlr]->num_channels) {
-               unsigned int mask = (1 << (channel & 0x1f));
+       if (channel < edma_cc[ctlr]->num_channels) {
+               unsigned int mask = BIT(channel & 0x1f);
 
                edma_shadow0_write_array(ctlr, SH_EESR, channel >> 5, mask);
        }
@@ -1252,12 +1250,12 @@ int edma_start(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel < edma_info[ctlr]->num_channels) {
+       if (channel < edma_cc[ctlr]->num_channels) {
                int j = channel >> 5;
-               unsigned int mask = (1 << (channel & 0x1f));
+               unsigned int mask = BIT(channel & 0x1f);
 
                /* EDMA channels without event association */
-               if (test_bit(channel, edma_info[ctlr]->edma_unused)) {
+               if (test_bit(channel, edma_cc[ctlr]->edma_unused)) {
                        pr_debug("EDMA: ESR%d %08x\n", j,
                                edma_shadow0_read_array(ctlr, SH_ESR, j));
                        edma_shadow0_write_array(ctlr, SH_ESR, j, mask);
@@ -1298,9 +1296,9 @@ void edma_stop(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel < edma_info[ctlr]->num_channels) {
+       if (channel < edma_cc[ctlr]->num_channels) {
                int j = channel >> 5;
-               unsigned int mask = (1 << (channel & 0x1f));
+               unsigned int mask = BIT(channel & 0x1f);
 
                edma_shadow0_write_array(ctlr, SH_EECR, j, mask);
                edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
@@ -1337,9 +1335,9 @@ void edma_clean_channel(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel < edma_info[ctlr]->num_channels) {
+       if (channel < edma_cc[ctlr]->num_channels) {
                int j = (channel >> 5);
-               unsigned int mask = 1 << (channel & 0x1f);
+               unsigned int mask = BIT(channel & 0x1f);
 
                pr_debug("EDMA: EMR%d %08x\n", j,
                                edma_read_array(ctlr, EDMA_EMR, j));
@@ -1348,7 +1346,7 @@ void edma_clean_channel(unsigned channel)
                edma_write_array(ctlr, EDMA_EMCR, j, mask);
                /* Clear any SER */
                edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
-               edma_write(ctlr, EDMA_CCERRCLR, (1 << 16) | 0x3);
+               edma_write(ctlr, EDMA_CCERRCLR, BIT(16) | BIT(1) | BIT(0));
        }
 }
 EXPORT_SYMBOL(edma_clean_channel);
@@ -1365,12 +1363,12 @@ void edma_clear_event(unsigned channel)
        ctlr = EDMA_CTLR(channel);
        channel = EDMA_CHAN_SLOT(channel);
 
-       if (channel >= edma_info[ctlr]->num_channels)
+       if (channel >= edma_cc[ctlr]->num_channels)
                return;
        if (channel < 32)
-               edma_write(ctlr, EDMA_ECR, 1 << channel);
+               edma_write(ctlr, EDMA_ECR, BIT(channel));
        else
-               edma_write(ctlr, EDMA_ECRH, 1 << (channel - 32));
+               edma_write(ctlr, EDMA_ECRH, BIT(channel - 32));
 }
 EXPORT_SYMBOL(edma_clear_event);
 
@@ -1402,8 +1400,9 @@ static int __init edma_probe(struct platform_device *pdev)
                                break;
                        else
                                return -ENODEV;
-               } else
+               } else {
                        found = 1;
+               }
 
                len[j] = resource_size(r[j]);
 
@@ -1420,38 +1419,37 @@ static int __init edma_probe(struct platform_device *pdev)
                        goto fail1;
                }
 
-               edma_info[j] = kmalloc(sizeof(struct edma), GFP_KERNEL);
-               if (!edma_info[j]) {
+               edma_cc[j] = kmalloc(sizeof(struct edma), GFP_KERNEL);
+               if (!edma_cc[j]) {
                        status = -ENOMEM;
                        goto fail1;
                }
-               memset(edma_info[j], 0, sizeof(struct edma));
+               memset(edma_cc[j], 0, sizeof(struct edma));
 
-               edma_info[j]->num_channels = min_t(unsigned, info[j].n_channel,
+               edma_cc[j]->num_channels = min_t(unsigned, info[j].n_channel,
                                                        EDMA_MAX_DMACH);
-               edma_info[j]->num_slots = min_t(unsigned, info[j].n_slot,
+               edma_cc[j]->num_slots = min_t(unsigned, info[j].n_slot,
                                                        EDMA_MAX_PARAMENTRY);
-               edma_info[j]->num_cc = min_t(unsigned, info[j].n_cc,
-                                                       EDMA_MAX_CC);
+               edma_cc[j]->num_cc = min_t(unsigned, info[j].n_cc, EDMA_MAX_CC);
 
-               edma_info[j]->default_queue = info[j].default_queue;
-               if (!edma_info[j]->default_queue)
-                       edma_info[j]->default_queue = EVENTQ_1;
+               edma_cc[j]->default_queue = info[j].default_queue;
+               if (!edma_cc[j]->default_queue)
+                       edma_cc[j]->default_queue = EVENTQ_1;
 
                dev_dbg(&pdev->dev, "DMA REG BASE ADDR=%p\n",
                        edmacc_regs_base[j]);
 
-               for (i = 0; i < edma_info[j]->num_slots; i++)
+               for (i = 0; i < edma_cc[j]->num_slots; i++)
                        memcpy_toio(edmacc_regs_base[j] + PARM_OFFSET(i),
                                        &dummy_paramset, PARM_SIZE);
 
                /* Mark all channels as unused */
-               memset(edma_info[j]->edma_unused, 0xff,
-                       sizeof(edma_info[j]->edma_unused));
+               memset(edma_cc[j]->edma_unused, 0xff,
+                       sizeof(edma_cc[j]->edma_unused));
 
                sprintf(irq_name, "edma%d", j);
                irq[j] = platform_get_irq_byname(pdev, irq_name);
-               edma_info[j]->irq_res_start = irq[j];
+               edma_cc[j]->irq_res_start = irq[j];
                status = request_irq(irq[j], dma_irq_handler, 0, "edma",
                                        &pdev->dev);
                if (status < 0) {
@@ -1462,7 +1460,7 @@ static int __init edma_probe(struct platform_device *pdev)
 
                sprintf(irq_name, "edma%d_err", j);
                err_irq[j] = platform_get_irq_byname(pdev, irq_name);
-               edma_info[j]->irq_res_end = err_irq[j];
+               edma_cc[j]->irq_res_end = err_irq[j];
                status = request_irq(err_irq[j], dma_ccerr_handler, 0,
                                        "edma_error", &pdev->dev);
                if (status < 0) {
@@ -1475,7 +1473,7 @@ static int __init edma_probe(struct platform_device *pdev)
                 * specified. This way, long transfers on the low priority queue
                 * started by the codec engine will not cause audio defects.
                 */
-               for (i = 0; i < edma_info[j]->num_channels; i++)
+               for (i = 0; i < edma_cc[j]->num_channels; i++)
                        map_dmach_queue(j, i, EVENTQ_1);
 
                queue_tc_mapping = info[j].queue_tc_mapping;
@@ -1538,7 +1536,7 @@ fail1:
                        release_mem_region(r[i]->start, len[i]);
                if (edmacc_regs_base[i])
                        iounmap(edmacc_regs_base[i]);
-               kfree(edma_info[i]);
+               kfree(edma_cc[i]);
        }
        return status;
 }
index 744755b..bf0ff58 100644 (file)
 
 #include <asm/mach/irq.h>
 
-static DEFINE_SPINLOCK(gpio_lock);
-
-struct davinci_gpio {
-       struct gpio_chip        chip;
-       struct gpio_controller  *__iomem regs;
-       int                     irq_base;
+struct davinci_gpio_regs {
+       u32     dir;
+       u32     out_data;
+       u32     set_data;
+       u32     clr_data;
+       u32     in_data;
+       u32     set_rising;
+       u32     clr_rising;
+       u32     set_falling;
+       u32     clr_falling;
+       u32     intstat;
 };
 
-static struct davinci_gpio chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
+#define chip2controller(chip)  \
+       container_of(chip, struct davinci_gpio_controller, chip)
+
+static struct davinci_gpio_controller chips[DIV_ROUND_UP(DAVINCI_N_GPIO, 32)];
+static void __iomem *gpio_base;
+
+static struct davinci_gpio_regs __iomem __init *gpio2regs(unsigned gpio)
+{
+       void __iomem *ptr;
+
+       if (gpio < 32 * 1)
+               ptr = gpio_base + 0x10;
+       else if (gpio < 32 * 2)
+               ptr = gpio_base + 0x38;
+       else if (gpio < 32 * 3)
+               ptr = gpio_base + 0x60;
+       else if (gpio < 32 * 4)
+               ptr = gpio_base + 0x88;
+       else if (gpio < 32 * 5)
+               ptr = gpio_base + 0xb0;
+       else
+               ptr = NULL;
+       return ptr;
+}
 
-/* create a non-inlined version */
-static struct gpio_controller __iomem * __init gpio2controller(unsigned gpio)
+static inline struct davinci_gpio_regs __iomem *irq2regs(int irq)
 {
-       return __gpio_to_controller(gpio);
+       struct davinci_gpio_regs __iomem *g;
+
+       g = (__force struct davinci_gpio_regs __iomem *)get_irq_chip_data(irq);
+
+       return g;
 }
 
 static int __init davinci_gpio_irq_setup(void);
 
 /*--------------------------------------------------------------------------*/
 
-/*
- * board setup code *MUST* set PINMUX0 and PINMUX1 as
- * needed, and enable the GPIO clock.
- */
-
-static int davinci_direction_in(struct gpio_chip *chip, unsigned offset)
+/* board setup code *MUST* setup pinmux and enable the GPIO clock. */
+static inline int __davinci_direction(struct gpio_chip *chip,
+                       unsigned offset, bool out, int value)
 {
-       struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
-       struct gpio_controller *__iomem g = d->regs;
+       struct davinci_gpio_controller *d = chip2controller(chip);
+       struct davinci_gpio_regs __iomem *g = d->regs;
+       unsigned long flags;
        u32 temp;
+       u32 mask = 1 << offset;
 
-       spin_lock(&gpio_lock);
+       spin_lock_irqsave(&d->lock, flags);
        temp = __raw_readl(&g->dir);
-       temp |= (1 << offset);
+       if (out) {
+               temp &= ~mask;
+               __raw_writel(mask, value ? &g->set_data : &g->clr_data);
+       } else {
+               temp |= mask;
+       }
        __raw_writel(temp, &g->dir);
-       spin_unlock(&gpio_lock);
+       spin_unlock_irqrestore(&d->lock, flags);
 
        return 0;
 }
 
+static int davinci_direction_in(struct gpio_chip *chip, unsigned offset)
+{
+       return __davinci_direction(chip, offset, false, 0);
+}
+
+static int
+davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
+{
+       return __davinci_direction(chip, offset, true, value);
+}
+
 /*
  * Read the pin's value (works even if it's set up as output);
  * returns zero/nonzero.
@@ -69,37 +115,20 @@ static int davinci_direction_in(struct gpio_chip *chip, unsigned offset)
  */
 static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
 {
-       struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
-       struct gpio_controller *__iomem g = d->regs;
+       struct davinci_gpio_controller *d = chip2controller(chip);
+       struct davinci_gpio_regs __iomem *g = d->regs;
 
        return (1 << offset) & __raw_readl(&g->in_data);
 }
 
-static int
-davinci_direction_out(struct gpio_chip *chip, unsigned offset, int value)
-{
-       struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
-       struct gpio_controller *__iomem g = d->regs;
-       u32 temp;
-       u32 mask = 1 << offset;
-
-       spin_lock(&gpio_lock);
-       temp = __raw_readl(&g->dir);
-       temp &= ~mask;
-       __raw_writel(mask, value ? &g->set_data : &g->clr_data);
-       __raw_writel(temp, &g->dir);
-       spin_unlock(&gpio_lock);
-       return 0;
-}
-
 /*
  * Assuming the pin is muxed as a gpio output, set its output value.
  */
 static void
 davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 {
-       struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
-       struct gpio_controller *__iomem g = d->regs;
+       struct davinci_gpio_controller *d = chip2controller(chip);
+       struct davinci_gpio_regs __iomem *g = d->regs;
 
        __raw_writel((1 << offset), value ? &g->set_data : &g->clr_data);
 }
@@ -109,6 +138,10 @@ static int __init davinci_gpio_setup(void)
        int i, base;
        unsigned ngpio;
        struct davinci_soc_info *soc_info = &davinci_soc_info;
+       struct davinci_gpio_regs *regs;
+
+       if (soc_info->gpio_type != GPIO_TYPE_DAVINCI)
+               return 0;
 
        /*
         * The gpio banks conceptually expose a segmented bitmap,
@@ -124,6 +157,10 @@ static int __init davinci_gpio_setup(void)
        if (WARN_ON(DAVINCI_N_GPIO < ngpio))
                ngpio = DAVINCI_N_GPIO;
 
+       gpio_base = ioremap(soc_info->gpio_base, SZ_4K);
+       if (WARN_ON(!gpio_base))
+               return -ENOMEM;
+
        for (i = 0, base = 0; base < ngpio; i++, base += 32) {
                chips[i].chip.label = "DaVinci";
 
@@ -137,11 +174,20 @@ static int __init davinci_gpio_setup(void)
                if (chips[i].chip.ngpio > 32)
                        chips[i].chip.ngpio = 32;
 
-               chips[i].regs = gpio2controller(base);
+               spin_lock_init(&chips[i].lock);
+
+               regs = gpio2regs(base);
+               chips[i].regs = regs;
+               chips[i].set_data = &regs->set_data;
+               chips[i].clr_data = &regs->clr_data;
+               chips[i].in_data = &regs->in_data;
 
                gpiochip_add(&chips[i].chip);
        }
 
+       soc_info->gpio_ctlrs = chips;
+       soc_info->gpio_ctlrs_num = DIV_ROUND_UP(ngpio, 32);
+
        davinci_gpio_irq_setup();
        return 0;
 }
@@ -161,7 +207,7 @@ pure_initcall(davinci_gpio_setup);
 
 static void gpio_irq_disable(unsigned irq)
 {
-       struct gpio_controller *__iomem g = get_irq_chip_data(irq);
+       struct davinci_gpio_regs __iomem *g = irq2regs(irq);
        u32 mask = (u32) get_irq_data(irq);
 
        __raw_writel(mask, &g->clr_falling);
@@ -170,7 +216,7 @@ static void gpio_irq_disable(unsigned irq)
 
 static void gpio_irq_enable(unsigned irq)
 {
-       struct gpio_controller *__iomem g = get_irq_chip_data(irq);
+       struct davinci_gpio_regs __iomem *g = irq2regs(irq);
        u32 mask = (u32) get_irq_data(irq);
        unsigned status = irq_desc[irq].status;
 
@@ -186,7 +232,7 @@ static void gpio_irq_enable(unsigned irq)
 
 static int gpio_irq_type(unsigned irq, unsigned trigger)
 {
-       struct gpio_controller *__iomem g = get_irq_chip_data(irq);
+       struct davinci_gpio_regs __iomem *g = irq2regs(irq);
        u32 mask = (u32) get_irq_data(irq);
 
        if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
@@ -215,7 +261,7 @@ static struct irq_chip gpio_irqchip = {
 static void
 gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 {
-       struct gpio_controller *__iomem g = get_irq_chip_data(irq);
+       struct davinci_gpio_regs __iomem *g = irq2regs(irq);
        u32 mask = 0xffff;
 
        /* we only care about one bank */
@@ -253,7 +299,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 
 static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
 {
-       struct davinci_gpio *d = container_of(chip, struct davinci_gpio, chip);
+       struct davinci_gpio_controller *d = chip2controller(chip);
 
        if (d->irq_base >= 0)
                return d->irq_base + offset;
@@ -276,7 +322,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
 
 static int gpio_irq_type_unbanked(unsigned irq, unsigned trigger)
 {
-       struct gpio_controller *__iomem g = get_irq_chip_data(irq);
+       struct davinci_gpio_regs __iomem *g = irq2regs(irq);
        u32 mask = (u32) get_irq_data(irq);
 
        if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
@@ -305,7 +351,7 @@ static int __init davinci_gpio_irq_setup(void)
        u32             binten = 0;
        unsigned        ngpio, bank_irq;
        struct davinci_soc_info *soc_info = &davinci_soc_info;
-       struct gpio_controller  *__iomem g;
+       struct davinci_gpio_regs        __iomem *g;
 
        ngpio = soc_info->gpio_num;
 
@@ -354,7 +400,7 @@ static int __init davinci_gpio_irq_setup(void)
                gpio_irqchip_unbanked.set_type = gpio_irq_type_unbanked;
 
                /* default trigger: both edges */
-               g = gpio2controller(0);
+               g = gpio2regs(0);
                __raw_writel(~0, &g->set_falling);
                __raw_writel(~0, &g->set_rising);
 
@@ -362,7 +408,7 @@ static int __init davinci_gpio_irq_setup(void)
                for (gpio = 0; gpio < soc_info->gpio_unbanked; gpio++, irq++) {
                        set_irq_chip(irq, &gpio_irqchip_unbanked);
                        set_irq_data(irq, (void *) __gpio_mask(gpio));
-                       set_irq_chip_data(irq, g);
+                       set_irq_chip_data(irq, (__force void *) g);
                        irq_desc[irq].status |= IRQ_TYPE_EDGE_BOTH;
                }
 
@@ -379,18 +425,18 @@ static int __init davinci_gpio_irq_setup(void)
                unsigned                i;
 
                /* disabled by default, enabled only as needed */
-               g = gpio2controller(gpio);
+               g = gpio2regs(gpio);
                __raw_writel(~0, &g->clr_falling);
                __raw_writel(~0, &g->clr_rising);
 
                /* set up all irqs in this bank */
                set_irq_chained_handler(bank_irq, gpio_irq_handler);
-               set_irq_chip_data(bank_irq, g);
-               set_irq_data(bank_irq, (void *)irq);
+               set_irq_chip_data(bank_irq, (__force void *) g);
+               set_irq_data(bank_irq, (void *) irq);
 
                for (i = 0; i < 16 && gpio < ngpio; i++, irq++, gpio++) {
                        set_irq_chip(irq, &gpio_irqchip);
-                       set_irq_chip_data(irq, g);
+                       set_irq_chip_data(irq, (__force void *) g);
                        set_irq_data(irq, (void *) __gpio_mask(gpio));
                        set_irq_handler(irq, handle_simple_irq);
                        set_irq_flags(irq, IRQF_VALID);
@@ -403,7 +449,7 @@ done:
        /* BINTEN -- per-bank interrupt enable. genirq would also let these
         * bits be set/cleared dynamically.
         */
-       __raw_writel(binten, soc_info->gpio_base + 0x08);
+       __raw_writel(binten, gpio_base + 0x08);
 
        printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
 
index 50a955f..a57cba2 100644 (file)
@@ -12,6 +12,9 @@
 #ifndef __ARCH_ARM_MACH_DAVINCI_COMMON_H
 #define __ARCH_ARM_MACH_DAVINCI_COMMON_H
 
+#include <linux/compiler.h>
+#include <linux/types.h>
+
 struct sys_timer;
 
 extern struct sys_timer davinci_timer;
@@ -21,7 +24,7 @@ extern void __iomem *davinci_intc_base;
 extern int davinci_intc_type;
 
 struct davinci_timer_instance {
-       void __iomem    *base;
+       u32             base;
        u32             bottom_irq;
        u32             top_irq;
        unsigned long   cmp_off;
@@ -34,39 +37,54 @@ struct davinci_timer_info {
        unsigned int                    clocksource_id;
 };
 
-/* SoC specific init support */
+struct davinci_gpio_controller;
+
+/*
+ * SoC info passed into common davinci modules.
+ *
+ * Base addresses in this structure should be physical and not virtual.
+ * Modules that take such base addresses, should internally ioremap() them to
+ * use.
+ */
 struct davinci_soc_info {
        struct map_desc                 *io_desc;
        unsigned long                   io_desc_num;
        u32                             cpu_id;
        u32                             jtag_id;
-       void __iomem                    *jtag_id_base;
+       u32                             jtag_id_reg;
        struct davinci_id               *ids;
        unsigned long                   ids_num;
        struct clk_lookup               *cpu_clks;
-       void __iomem                    **psc_bases;
+       u32                             *psc_bases;
        unsigned long                   psc_bases_num;
-       void __iomem                    *pinmux_base;
+       u32                             pinmux_base;
        const struct mux_config         *pinmux_pins;
        unsigned long                   pinmux_pins_num;
-       void __iomem                    *intc_base;
+       u32                             intc_base;
        int                             intc_type;
        u8                              *intc_irq_prios;
        unsigned long                   intc_irq_num;
+       u32                             *intc_host_map;
        struct davinci_timer_info       *timer_info;
-       void __iomem                    *gpio_base;
+       int                             gpio_type;
+       u32                             gpio_base;
        unsigned                        gpio_num;
        unsigned                        gpio_irq;
        unsigned                        gpio_unbanked;
+       struct davinci_gpio_controller  *gpio_ctlrs;
+       int                             gpio_ctlrs_num;
        struct platform_device          *serial_dev;
        struct emac_platform_data       *emac_pdata;
        dma_addr_t                      sram_dma;
        unsigned                        sram_len;
+       struct platform_device          *reset_device;
+       void                            (*reset)(struct platform_device *);
 };
 
 extern struct davinci_soc_info davinci_soc_info;
 
 extern void davinci_common_init(struct davinci_soc_info *soc_info);
+extern void davinci_init_ide(void);
 
 /* standard place to map on-chip SRAMs; they *may* support DMA */
 #define SRAM_VIRT      0xfffe0000
index c4d27ee..4e8190e 100644 (file)
@@ -51,7 +51,6 @@
 #define CP_INTC_HOST_PRIO_VECTOR(n)    (0x1600 + (n << 2))
 #define CP_INTC_VECTOR_ADDR(n)         (0x2000 + (n << 2))
 
-void __init cp_intc_init(void __iomem *base, unsigned short num_irq,
-                        u8 *irq_prio);
+void __init cp_intc_init(void);
 
 #endif /* __ASM_HARDWARE_CP_INTC_H */
index 189b1ff..cea6b89 100644 (file)
@@ -33,6 +33,7 @@ struct davinci_id {
 #define        DAVINCI_CPU_ID_DM365            0x03650000
 #define        DAVINCI_CPU_ID_DA830            0x08300000
 #define        DAVINCI_CPU_ID_DA850            0x08500000
+#define        DAVINCI_CPU_ID_TNETV107X        0x0b8a0000
 
 #define IS_DAVINCI_CPU(type, id)                                       \
 static inline int is_davinci_ ##type(void)                             \
@@ -46,6 +47,7 @@ IS_DAVINCI_CPU(dm355, DAVINCI_CPU_ID_DM355)
 IS_DAVINCI_CPU(dm365, DAVINCI_CPU_ID_DM365)
 IS_DAVINCI_CPU(da830, DAVINCI_CPU_ID_DA830)
 IS_DAVINCI_CPU(da850, DAVINCI_CPU_ID_DA850)
+IS_DAVINCI_CPU(tnetv107x, DAVINCI_CPU_ID_TNETV107X)
 
 #ifdef CONFIG_ARCH_DAVINCI_DM644x
 #define cpu_is_davinci_dm644x() is_davinci_dm644x()
@@ -83,4 +85,10 @@ IS_DAVINCI_CPU(da850, DAVINCI_CPU_ID_DA850)
 #define cpu_is_davinci_da850() 0
 #endif
 
+#ifdef CONFIG_ARCH_DAVINCI_TNETV107X
+#define cpu_is_davinci_tnetv107x() is_davinci_tnetv107x()
+#else
+#define cpu_is_davinci_tnetv107x() 0
+#endif
+
 #endif
index 03acfd3..1b31a9a 100644 (file)
@@ -64,27 +64,6 @@ extern void __iomem *da8xx_syscfg1_base;
 #define DA8XX_DDR2_CTL_BASE    0xb0000000
 #define DA8XX_ARM_RAM_BASE     0xffff0000
 
-#define PINMUX0                        0x00
-#define PINMUX1                        0x04
-#define PINMUX2                        0x08
-#define PINMUX3                        0x0c
-#define PINMUX4                        0x10
-#define PINMUX5                        0x14
-#define PINMUX6                        0x18
-#define PINMUX7                        0x1c
-#define PINMUX8                        0x20
-#define PINMUX9                        0x24
-#define PINMUX10               0x28
-#define PINMUX11               0x2c
-#define PINMUX12               0x30
-#define PINMUX13               0x34
-#define PINMUX14               0x38
-#define PINMUX15               0x3c
-#define PINMUX16               0x40
-#define PINMUX17               0x44
-#define PINMUX18               0x48
-#define PINMUX19               0x4c
-
 void __init da830_init(void);
 void __init da850_init(void);
 
@@ -108,6 +87,8 @@ extern struct emac_platform_data da8xx_emac_pdata;
 extern struct da8xx_lcdc_platform_data sharp_lcd035q3dg01_pdata;
 extern struct da8xx_lcdc_platform_data sharp_lk043t1dg01_pdata;
 
+extern struct platform_device da8xx_wdt_device;
+
 extern const short da830_emif25_pins[];
 extern const short da830_spi0_pins[];
 extern const short da830_spi1_pins[];
@@ -146,10 +127,4 @@ extern const short da850_mmcsd0_pins[];
 extern const short da850_nand_pins[];
 extern const short da850_nor_pins[];
 
-#ifdef CONFIG_DAVINCI_MUX
-int da8xx_pinmux_setup(const short pins[]);
-#else
-static inline int da8xx_pinmux_setup(const short pins[]) { return 0; }
-#endif
-
 #endif /* __ASM_ARCH_DAVINCI_DA8XX_H */
index 85536d8..36dff4a 100644 (file)
@@ -15,6 +15,9 @@
 #include <mach/asp.h>
 #include <media/davinci/vpfe_capture.h>
 
+#define DM355_ASYNC_EMIF_CONTROL_BASE  0x01E10000
+#define DM355_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
+
 #define ASP1_TX_EVT_EN 1
 #define ASP1_RX_EVT_EN 2
 
index 3a37b5a..ea5df3b 100644 (file)
 #define DAVINCI_DMA_VC_TX              2
 #define DAVINCI_DMA_VC_RX              3
 
+#define DM365_ASYNC_EMIF_CONTROL_BASE  0x01D10000
+#define DM365_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
+#define DM365_ASYNC_EMIF_DATA_CE1_BASE 0x04000000
+
 void __init dm365_init(void);
 void __init dm365_init_asp(struct snd_platform_data *pdata);
 void __init dm365_init_vc(struct snd_platform_data *pdata);
index 1a8b09c..6fca568 100644 (file)
 #define DM644X_EMAC_MDIO_OFFSET                (0x4000)
 #define DM644X_EMAC_CNTRL_RAM_SIZE     (0x2000)
 
+#define DM644X_ASYNC_EMIF_CONTROL_BASE 0x01E00000
+#define DM644X_ASYNC_EMIF_DATA_CE0_BASE 0x02000000
+#define DM644X_ASYNC_EMIF_DATA_CE1_BASE 0x04000000
+#define DM644X_ASYNC_EMIF_DATA_CE2_BASE 0x06000000
+#define DM644X_ASYNC_EMIF_DATA_CE3_BASE 0x08000000
+
 void __init dm644x_init(void);
 void __init dm644x_init_asp(struct snd_platform_data *pdata);
 void dm644x_set_vpfe_config(struct vpfe_config *cfg);
index 846da98..add6f79 100644 (file)
 #define DM646X_EMAC_MDIO_OFFSET                (0x4000)
 #define DM646X_EMAC_CNTRL_RAM_SIZE     (0x2000)
 
-#define DM646X_ATA_REG_BASE            (0x01C66000)
+#define DM646X_ASYNC_EMIF_CONTROL_BASE 0x20008000
+#define DM646X_ASYNC_EMIF_CS2_SPACE_BASE 0x42000000
 
 void __init dm646x_init(void);
-void __init dm646x_init_ide(void);
 void __init dm646x_init_mcasp0(struct snd_platform_data *pdata);
 void __init dm646x_init_mcasp1(struct snd_platform_data *pdata);
 void __init dm646x_board_setup_refclk(struct clk *clk);
index f3b8ef8..504cc18 100644 (file)
@@ -14,6 +14,8 @@
 #define        __DAVINCI_GPIO_H
 
 #include <linux/io.h>
+#include <linux/spinlock.h>
+
 #include <asm-generic/gpio.h>
 
 #include <mach/irqs.h>
 
 #define DAVINCI_GPIO_BASE 0x01C67000
 
+enum davinci_gpio_type {
+       GPIO_TYPE_DAVINCI = 0,
+};
+
 /*
  * basic gpio routines
  *
 /* Convert GPIO signal to GPIO pin number */
 #define GPIO_TO_PIN(bank, gpio)        (16 * (bank) + (gpio))
 
-struct gpio_controller {
-       u32     dir;
-       u32     out_data;
-       u32     set_data;
-       u32     clr_data;
-       u32     in_data;
-       u32     set_rising;
-       u32     clr_rising;
-       u32     set_falling;
-       u32     clr_falling;
-       u32     intstat;
+struct davinci_gpio_controller {
+       struct gpio_chip        chip;
+       int                     irq_base;
+       spinlock_t              lock;
+       void __iomem            *regs;
+       void __iomem            *set_data;
+       void __iomem            *clr_data;
+       void __iomem            *in_data;
 };
 
 /* The __gpio_to_controller() and __gpio_mask() functions inline to constants
@@ -67,25 +70,16 @@ struct gpio_controller {
  *
  * These are NOT part of the cross-platform GPIO interface
  */
-static inline struct gpio_controller *__iomem
+static inline struct davinci_gpio_controller *
 __gpio_to_controller(unsigned gpio)
 {
-       void *__iomem ptr;
-       void __iomem *base = davinci_soc_info.gpio_base;
-
-       if (gpio < 32 * 1)
-               ptr = base + 0x10;
-       else if (gpio < 32 * 2)
-               ptr = base + 0x38;
-       else if (gpio < 32 * 3)
-               ptr = base + 0x60;
-       else if (gpio < 32 * 4)
-               ptr = base + 0x88;
-       else if (gpio < 32 * 5)
-               ptr = base + 0xb0;
-       else
-               ptr = NULL;
-       return ptr;
+       struct davinci_gpio_controller *ctlrs = davinci_soc_info.gpio_ctlrs;
+       int index = gpio / 32;
+
+       if (!ctlrs || index >= davinci_soc_info.gpio_ctlrs_num)
+               return NULL;
+
+       return ctlrs + index;
 }
 
 static inline u32 __gpio_mask(unsigned gpio)
@@ -101,16 +95,16 @@ static inline u32 __gpio_mask(unsigned gpio)
  */
 static inline void gpio_set_value(unsigned gpio, int value)
 {
-       if (__builtin_constant_p(value) && gpio < DAVINCI_N_GPIO) {
-               struct gpio_controller  *__iomem g;
-               u32                     mask;
+       if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
+               struct davinci_gpio_controller *ctlr;
+               u32                             mask;
 
-               g = __gpio_to_controller(gpio);
+               ctlr = __gpio_to_controller(gpio);
                mask = __gpio_mask(gpio);
                if (value)
-                       __raw_writel(mask, &g->set_data);
+                       __raw_writel(mask, ctlr->set_data);
                else
-                       __raw_writel(mask, &g->clr_data);
+                       __raw_writel(mask, ctlr->clr_data);
                return;
        }
 
@@ -128,18 +122,18 @@ static inline void gpio_set_value(unsigned gpio, int value)
  */
 static inline int gpio_get_value(unsigned gpio)
 {
-       struct gpio_controller  *__iomem g;
+       struct davinci_gpio_controller *ctlr;
 
-       if (!__builtin_constant_p(gpio) || gpio >= DAVINCI_N_GPIO)
+       if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
                return __gpio_get_value(gpio);
 
-       g = __gpio_to_controller(gpio);
-       return __gpio_mask(gpio) & __raw_readl(&g->in_data);
+       ctlr = __gpio_to_controller(gpio);
+       return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
 }
 
 static inline int gpio_cansleep(unsigned gpio)
 {
-       if (__builtin_constant_p(gpio) && gpio < DAVINCI_N_GPIO)
+       if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
                return 0;
        else
                return __gpio_cansleep(gpio);
index 354af71..ec76c77 100644 (file)
 
 #define DA850_N_CP_INTC_IRQ            101
 
+
+/* TNETV107X specific interrupts */
+#define IRQ_TNETV107X_TDM1_TXDMA               0
+#define IRQ_TNETV107X_EXT_INT_0                        1
+#define IRQ_TNETV107X_EXT_INT_1                        2
+#define IRQ_TNETV107X_GPIO_INT12               3
+#define IRQ_TNETV107X_GPIO_INT13               4
+#define IRQ_TNETV107X_TIMER_0_TINT12           5
+#define IRQ_TNETV107X_TIMER_1_TINT12           6
+#define IRQ_TNETV107X_UART0                    7
+#define IRQ_TNETV107X_TDM1_RXDMA               8
+#define IRQ_TNETV107X_MCDMA_INT0               9
+#define IRQ_TNETV107X_MCDMA_INT1               10
+#define IRQ_TNETV107X_TPCC                     11
+#define IRQ_TNETV107X_TPCC_INT0                        12
+#define IRQ_TNETV107X_TPCC_INT1                        13
+#define IRQ_TNETV107X_TPCC_INT2                        14
+#define IRQ_TNETV107X_TPCC_INT3                        15
+#define IRQ_TNETV107X_TPTC0                    16
+#define IRQ_TNETV107X_TPTC1                    17
+#define IRQ_TNETV107X_TIMER_0_TINT34           18
+#define IRQ_TNETV107X_ETHSS                    19
+#define IRQ_TNETV107X_TIMER_1_TINT34           20
+#define IRQ_TNETV107X_DSP2ARM_INT0             21
+#define IRQ_TNETV107X_DSP2ARM_INT1             22
+#define IRQ_TNETV107X_ARM_NPMUIRQ              23
+#define IRQ_TNETV107X_USB1                     24
+#define IRQ_TNETV107X_VLYNQ                    25
+#define IRQ_TNETV107X_UART0_DMATX              26
+#define IRQ_TNETV107X_UART0_DMARX              27
+#define IRQ_TNETV107X_TDM1_TXMCSP              28
+#define IRQ_TNETV107X_SSP                      29
+#define IRQ_TNETV107X_MCDMA_INT2               30
+#define IRQ_TNETV107X_MCDMA_INT3               31
+#define IRQ_TNETV107X_TDM_CODECIF_EOT          32
+#define IRQ_TNETV107X_IMCOP_SQR_ARM            33
+#define IRQ_TNETV107X_USB0                     34
+#define IRQ_TNETV107X_USB_CDMA                 35
+#define IRQ_TNETV107X_LCD                      36
+#define IRQ_TNETV107X_KEYPAD                   37
+#define IRQ_TNETV107X_KEYPAD_FREE              38
+#define IRQ_TNETV107X_RNG                      39
+#define IRQ_TNETV107X_PKA                      40
+#define IRQ_TNETV107X_TDM0_TXDMA               41
+#define IRQ_TNETV107X_TDM0_RXDMA               42
+#define IRQ_TNETV107X_TDM0_TXMCSP              43
+#define IRQ_TNETV107X_TDM0_RXMCSP              44
+#define IRQ_TNETV107X_TDM1_RXMCSP              45
+#define IRQ_TNETV107X_SDIO1                    46
+#define IRQ_TNETV107X_SDIO0                    47
+#define IRQ_TNETV107X_TSC                      48
+#define IRQ_TNETV107X_TS                       49
+#define IRQ_TNETV107X_UART1                    50
+#define IRQ_TNETV107X_MBX_LITE                 51
+#define IRQ_TNETV107X_GPIO_INT00               52
+#define IRQ_TNETV107X_GPIO_INT01               53
+#define IRQ_TNETV107X_GPIO_INT02               54
+#define IRQ_TNETV107X_GPIO_INT03               55
+#define IRQ_TNETV107X_UART2                    56
+#define IRQ_TNETV107X_UART2_DMATX              57
+#define IRQ_TNETV107X_UART2_DMARX              58
+#define IRQ_TNETV107X_IMCOP_IMX                        59
+#define IRQ_TNETV107X_IMCOP_VLCD               60
+#define IRQ_TNETV107X_AES                      61
+#define IRQ_TNETV107X_DES                      62
+#define IRQ_TNETV107X_SHAMD5                   63
+#define IRQ_TNETV107X_TPCC_ERR                 68
+#define IRQ_TNETV107X_TPCC_PROT                        69
+#define IRQ_TNETV107X_TPTC0_ERR                        70
+#define IRQ_TNETV107X_TPTC1_ERR                        71
+#define IRQ_TNETV107X_UART0_ERR                        72
+#define IRQ_TNETV107X_UART1_ERR                        73
+#define IRQ_TNETV107X_AEMIF_ERR                        74
+#define IRQ_TNETV107X_DDR_ERR                  75
+#define IRQ_TNETV107X_WDTARM_INT0              76
+#define IRQ_TNETV107X_MCDMA_ERR                        77
+#define IRQ_TNETV107X_GPIO_ERR                 78
+#define IRQ_TNETV107X_MPU_ADDR                 79
+#define IRQ_TNETV107X_MPU_PROT                 80
+#define IRQ_TNETV107X_IOPU_ADDR                        81
+#define IRQ_TNETV107X_IOPU_PROT                        82
+#define IRQ_TNETV107X_KEYPAD_ADDR_ERR          83
+#define IRQ_TNETV107X_WDT0_ADDR_ERR            84
+#define IRQ_TNETV107X_WDT1_ADDR_ERR            85
+#define IRQ_TNETV107X_CLKCTL_ADDR_ERR          86
+#define IRQ_TNETV107X_PLL_UNLOCK               87
+#define IRQ_TNETV107X_WDTDSP_INT0              88
+#define IRQ_TNETV107X_SEC_CTRL_VIOLATION       89
+#define IRQ_TNETV107X_KEY_MNG_VIOLATION                90
+#define IRQ_TNETV107X_PBIST_CPU                        91
+#define IRQ_TNETV107X_WDTARM                   92
+#define IRQ_TNETV107X_PSC                      93
+#define IRQ_TNETV107X_MMC0                     94
+#define IRQ_TNETV107X_MMC1                     95
+
+#define TNETV107X_N_CP_INTC_IRQ                        96
+
 /* da850 currently has the most gpio pins (144) */
 #define DAVINCI_N_GPIO                 144
 /* da850 currently has the most irqs so use DA850_N_CP_INTC_IRQ */
index 2a68c1d..de11aac 100644 (file)
@@ -194,11 +194,14 @@ enum davinci_dm365_index {
        DM365_I2C_SCL,
 
        /* AEMIF */
-       DM365_AEMIF_AR,
+       DM365_AEMIF_AR_A14,
+       DM365_AEMIF_AR_BA0,
        DM365_AEMIF_A3,
        DM365_AEMIF_A7,
        DM365_AEMIF_D15_8,
        DM365_AEMIF_CE0,
+       DM365_AEMIF_CE1,
+       DM365_AEMIF_WE_OE,
 
        /* ASP0 function */
        DM365_MCBSP0_BDX,
@@ -287,10 +290,19 @@ enum davinci_dm365_index {
        DM365_SPI4_SDENA0,
        DM365_SPI4_SDENA1,
 
+       /* Clock */
+       DM365_CLKOUT0,
+       DM365_CLKOUT1,
+       DM365_CLKOUT2,
+
        /* GPIO */
        DM365_GPIO20,
+       DM365_GPIO30,
+       DM365_GPIO31,
+       DM365_GPIO32,
        DM365_GPIO33,
        DM365_GPIO40,
+       DM365_GPIO64_57,
 
        /* Video */
        DM365_VOUT_FIELD,
@@ -904,12 +916,288 @@ enum davinci_da850_index {
        DA850_RTC_ALARM,
 };
 
+enum davinci_tnetv107x_index {
+       TNETV107X_ASR_A00,
+       TNETV107X_GPIO32,
+       TNETV107X_ASR_A01,
+       TNETV107X_GPIO33,
+       TNETV107X_ASR_A02,
+       TNETV107X_GPIO34,
+       TNETV107X_ASR_A03,
+       TNETV107X_GPIO35,
+       TNETV107X_ASR_A04,
+       TNETV107X_GPIO36,
+       TNETV107X_ASR_A05,
+       TNETV107X_GPIO37,
+       TNETV107X_ASR_A06,
+       TNETV107X_GPIO38,
+       TNETV107X_ASR_A07,
+       TNETV107X_GPIO39,
+       TNETV107X_ASR_A08,
+       TNETV107X_GPIO40,
+       TNETV107X_ASR_A09,
+       TNETV107X_GPIO41,
+       TNETV107X_ASR_A10,
+       TNETV107X_GPIO42,
+       TNETV107X_ASR_A11,
+       TNETV107X_BOOT_STRP_0,
+       TNETV107X_ASR_A12,
+       TNETV107X_BOOT_STRP_1,
+       TNETV107X_ASR_A13,
+       TNETV107X_GPIO43,
+       TNETV107X_ASR_A14,
+       TNETV107X_GPIO44,
+       TNETV107X_ASR_A15,
+       TNETV107X_GPIO45,
+       TNETV107X_ASR_A16,
+       TNETV107X_GPIO46,
+       TNETV107X_ASR_A17,
+       TNETV107X_GPIO47,
+       TNETV107X_ASR_A18,
+       TNETV107X_GPIO48,
+       TNETV107X_SDIO1_DATA3_0,
+       TNETV107X_ASR_A19,
+       TNETV107X_GPIO49,
+       TNETV107X_SDIO1_DATA2_0,
+       TNETV107X_ASR_A20,
+       TNETV107X_GPIO50,
+       TNETV107X_SDIO1_DATA1_0,
+       TNETV107X_ASR_A21,
+       TNETV107X_GPIO51,
+       TNETV107X_SDIO1_DATA0_0,
+       TNETV107X_ASR_A22,
+       TNETV107X_GPIO52,
+       TNETV107X_SDIO1_CMD_0,
+       TNETV107X_ASR_A23,
+       TNETV107X_GPIO53,
+       TNETV107X_SDIO1_CLK_0,
+       TNETV107X_ASR_BA_1,
+       TNETV107X_GPIO54,
+       TNETV107X_SYS_PLL_CLK,
+       TNETV107X_ASR_CS0,
+       TNETV107X_ASR_CS1,
+       TNETV107X_ASR_CS2,
+       TNETV107X_TDM_PLL_CLK,
+       TNETV107X_ASR_CS3,
+       TNETV107X_ETH_PHY_CLK,
+       TNETV107X_ASR_D00,
+       TNETV107X_GPIO55,
+       TNETV107X_ASR_D01,
+       TNETV107X_GPIO56,
+       TNETV107X_ASR_D02,
+       TNETV107X_GPIO57,
+       TNETV107X_ASR_D03,
+       TNETV107X_GPIO58,
+       TNETV107X_ASR_D04,
+       TNETV107X_GPIO59_0,
+       TNETV107X_ASR_D05,
+       TNETV107X_GPIO60_0,
+       TNETV107X_ASR_D06,
+       TNETV107X_GPIO61_0,
+       TNETV107X_ASR_D07,
+       TNETV107X_GPIO62_0,
+       TNETV107X_ASR_D08,
+       TNETV107X_GPIO63_0,
+       TNETV107X_ASR_D09,
+       TNETV107X_GPIO64_0,
+       TNETV107X_ASR_D10,
+       TNETV107X_SDIO1_DATA3_1,
+       TNETV107X_ASR_D11,
+       TNETV107X_SDIO1_DATA2_1,
+       TNETV107X_ASR_D12,
+       TNETV107X_SDIO1_DATA1_1,
+       TNETV107X_ASR_D13,
+       TNETV107X_SDIO1_DATA0_1,
+       TNETV107X_ASR_D14,
+       TNETV107X_SDIO1_CMD_1,
+       TNETV107X_ASR_D15,
+       TNETV107X_SDIO1_CLK_1,
+       TNETV107X_ASR_OE,
+       TNETV107X_BOOT_STRP_2,
+       TNETV107X_ASR_RNW,
+       TNETV107X_GPIO29_0,
+       TNETV107X_ASR_WAIT,
+       TNETV107X_GPIO30_0,
+       TNETV107X_ASR_WE,
+       TNETV107X_BOOT_STRP_3,
+       TNETV107X_ASR_WE_DQM0,
+       TNETV107X_GPIO31,
+       TNETV107X_LCD_PD17_0,
+       TNETV107X_ASR_WE_DQM1,
+       TNETV107X_ASR_BA0_0,
+       TNETV107X_VLYNQ_CLK,
+       TNETV107X_GPIO14,
+       TNETV107X_LCD_PD19_0,
+       TNETV107X_VLYNQ_RXD0,
+       TNETV107X_GPIO15,
+       TNETV107X_LCD_PD20_0,
+       TNETV107X_VLYNQ_RXD1,
+       TNETV107X_GPIO16,
+       TNETV107X_LCD_PD21_0,
+       TNETV107X_VLYNQ_TXD0,
+       TNETV107X_GPIO17,
+       TNETV107X_LCD_PD22_0,
+       TNETV107X_VLYNQ_TXD1,
+       TNETV107X_GPIO18,
+       TNETV107X_LCD_PD23_0,
+       TNETV107X_SDIO0_CLK,
+       TNETV107X_GPIO19,
+       TNETV107X_SDIO0_CMD,
+       TNETV107X_GPIO20,
+       TNETV107X_SDIO0_DATA0,
+       TNETV107X_GPIO21,
+       TNETV107X_SDIO0_DATA1,
+       TNETV107X_GPIO22,
+       TNETV107X_SDIO0_DATA2,
+       TNETV107X_GPIO23,
+       TNETV107X_SDIO0_DATA3,
+       TNETV107X_GPIO24,
+       TNETV107X_EMU0,
+       TNETV107X_EMU1,
+       TNETV107X_RTCK,
+       TNETV107X_TRST_N,
+       TNETV107X_TCK,
+       TNETV107X_TDI,
+       TNETV107X_TDO,
+       TNETV107X_TMS,
+       TNETV107X_TDM1_CLK,
+       TNETV107X_TDM1_RX,
+       TNETV107X_TDM1_TX,
+       TNETV107X_TDM1_FS,
+       TNETV107X_KEYPAD_R0,
+       TNETV107X_KEYPAD_R1,
+       TNETV107X_KEYPAD_R2,
+       TNETV107X_KEYPAD_R3,
+       TNETV107X_KEYPAD_R4,
+       TNETV107X_KEYPAD_R5,
+       TNETV107X_KEYPAD_R6,
+       TNETV107X_GPIO12,
+       TNETV107X_KEYPAD_R7,
+       TNETV107X_GPIO10,
+       TNETV107X_KEYPAD_C0,
+       TNETV107X_KEYPAD_C1,
+       TNETV107X_KEYPAD_C2,
+       TNETV107X_KEYPAD_C3,
+       TNETV107X_KEYPAD_C4,
+       TNETV107X_KEYPAD_C5,
+       TNETV107X_KEYPAD_C6,
+       TNETV107X_GPIO13,
+       TNETV107X_TEST_CLK_IN,
+       TNETV107X_KEYPAD_C7,
+       TNETV107X_GPIO11,
+       TNETV107X_SSP0_0,
+       TNETV107X_SCC_DCLK,
+       TNETV107X_LCD_PD20_1,
+       TNETV107X_SSP0_1,
+       TNETV107X_SCC_CS_N,
+       TNETV107X_LCD_PD21_1,
+       TNETV107X_SSP0_2,
+       TNETV107X_SCC_D,
+       TNETV107X_LCD_PD22_1,
+       TNETV107X_SSP0_3,
+       TNETV107X_SCC_RESETN,
+       TNETV107X_LCD_PD23_1,
+       TNETV107X_SSP1_0,
+       TNETV107X_GPIO25,
+       TNETV107X_UART2_CTS,
+       TNETV107X_SSP1_1,
+       TNETV107X_GPIO26,
+       TNETV107X_UART2_RD,
+       TNETV107X_SSP1_2,
+       TNETV107X_GPIO27,
+       TNETV107X_UART2_RTS,
+       TNETV107X_SSP1_3,
+       TNETV107X_GPIO28,
+       TNETV107X_UART2_TD,
+       TNETV107X_UART0_CTS,
+       TNETV107X_UART0_RD,
+       TNETV107X_UART0_RTS,
+       TNETV107X_UART0_TD,
+       TNETV107X_UART1_RD,
+       TNETV107X_UART1_TD,
+       TNETV107X_LCD_AC_NCS,
+       TNETV107X_LCD_HSYNC_RNW,
+       TNETV107X_LCD_VSYNC_A0,
+       TNETV107X_LCD_MCLK,
+       TNETV107X_LCD_PD16_0,
+       TNETV107X_LCD_PCLK_E,
+       TNETV107X_LCD_PD00,
+       TNETV107X_LCD_PD01,
+       TNETV107X_LCD_PD02,
+       TNETV107X_LCD_PD03,
+       TNETV107X_LCD_PD04,
+       TNETV107X_LCD_PD05,
+       TNETV107X_LCD_PD06,
+       TNETV107X_LCD_PD07,
+       TNETV107X_LCD_PD08,
+       TNETV107X_GPIO59_1,
+       TNETV107X_LCD_PD09,
+       TNETV107X_GPIO60_1,
+       TNETV107X_LCD_PD10,
+       TNETV107X_ASR_BA0_1,
+       TNETV107X_GPIO61_1,
+       TNETV107X_LCD_PD11,
+       TNETV107X_GPIO62_1,
+       TNETV107X_LCD_PD12,
+       TNETV107X_GPIO63_1,
+       TNETV107X_LCD_PD13,
+       TNETV107X_GPIO64_1,
+       TNETV107X_LCD_PD14,
+       TNETV107X_GPIO29_1,
+       TNETV107X_LCD_PD15,
+       TNETV107X_GPIO30_1,
+       TNETV107X_EINT0,
+       TNETV107X_GPIO08,
+       TNETV107X_EINT1,
+       TNETV107X_GPIO09,
+       TNETV107X_GPIO00,
+       TNETV107X_LCD_PD20_2,
+       TNETV107X_TDM_CLK_IN_2,
+       TNETV107X_GPIO01,
+       TNETV107X_LCD_PD21_2,
+       TNETV107X_24M_CLK_OUT_1,
+       TNETV107X_GPIO02,
+       TNETV107X_LCD_PD22_2,
+       TNETV107X_GPIO03,
+       TNETV107X_LCD_PD23_2,
+       TNETV107X_GPIO04,
+       TNETV107X_LCD_PD16_1,
+       TNETV107X_USB0_RXERR,
+       TNETV107X_GPIO05,
+       TNETV107X_LCD_PD17_1,
+       TNETV107X_TDM_CLK_IN_1,
+       TNETV107X_GPIO06,
+       TNETV107X_LCD_PD18,
+       TNETV107X_24M_CLK_OUT_2,
+       TNETV107X_GPIO07,
+       TNETV107X_LCD_PD19_1,
+       TNETV107X_USB1_RXERR,
+       TNETV107X_ETH_PLL_CLK,
+       TNETV107X_MDIO,
+       TNETV107X_MDC,
+       TNETV107X_AIC_MUTE_STAT_N,
+       TNETV107X_TDM0_CLK,
+       TNETV107X_AIC_HNS_EN_N,
+       TNETV107X_TDM0_FS,
+       TNETV107X_AIC_HDS_EN_STAT_N,
+       TNETV107X_TDM0_TX,
+       TNETV107X_AIC_HNF_EN_STAT_N,
+       TNETV107X_TDM0_RX,
+};
+
+#define PINMUX(x)              (4 * (x))
+
 #ifdef CONFIG_DAVINCI_MUX
 /* setup pin muxing */
 extern int davinci_cfg_reg(unsigned long reg_cfg);
+extern int davinci_cfg_reg_list(const short pins[]);
 #else
 /* boot loader does it all (no warnings from CONFIG_DAVINCI_MUX_WARNINGS) */
 static inline int davinci_cfg_reg(unsigned long reg_cfg) { return 0; }
+static inline int davinci_cfg_reg_list(const short pins[])
+{
+       return 0;
+}
 #endif
 
 #endif /* __INC_MACH_MUX_H */
index 651f6d8..983da6e 100644 (file)
 #define DA8XX_LPSC1_CR_P3_SS           26
 #define DA8XX_LPSC1_L3_CBA_RAM         31
 
+/* TNETV107X LPSC Assignments */
+#define TNETV107X_LPSC_ARM                     0
+#define TNETV107X_LPSC_GEM                     1
+#define TNETV107X_LPSC_DDR2_PHY                        2
+#define TNETV107X_LPSC_TPCC                    3
+#define TNETV107X_LPSC_TPTC0                   4
+#define TNETV107X_LPSC_TPTC1                   5
+#define TNETV107X_LPSC_RAM                     6
+#define TNETV107X_LPSC_MBX_LITE                        7
+#define TNETV107X_LPSC_LCD                     8
+#define TNETV107X_LPSC_ETHSS                   9
+#define TNETV107X_LPSC_AEMIF                   10
+#define TNETV107X_LPSC_CHIP_CFG                        11
+#define TNETV107X_LPSC_TSC                     12
+#define TNETV107X_LPSC_ROM                     13
+#define TNETV107X_LPSC_UART2                   14
+#define TNETV107X_LPSC_PKTSEC                  15
+#define TNETV107X_LPSC_SECCTL                  16
+#define TNETV107X_LPSC_KEYMGR                  17
+#define TNETV107X_LPSC_KEYPAD                  18
+#define TNETV107X_LPSC_GPIO                    19
+#define TNETV107X_LPSC_MDIO                    20
+#define TNETV107X_LPSC_SDIO0                   21
+#define TNETV107X_LPSC_UART0                   22
+#define TNETV107X_LPSC_UART1                   23
+#define TNETV107X_LPSC_TIMER0                  24
+#define TNETV107X_LPSC_TIMER1                  25
+#define TNETV107X_LPSC_WDT_ARM                 26
+#define TNETV107X_LPSC_WDT_DSP                 27
+#define TNETV107X_LPSC_SSP                     28
+#define TNETV107X_LPSC_TDM0                    29
+#define TNETV107X_LPSC_VLYNQ                   30
+#define TNETV107X_LPSC_MCDMA                   31
+#define TNETV107X_LPSC_USB0                    32
+#define TNETV107X_LPSC_TDM1                    33
+#define TNETV107X_LPSC_DEBUGSS                 34
+#define TNETV107X_LPSC_ETHSS_RGMII             35
+#define TNETV107X_LPSC_SYSTEM                  36
+#define TNETV107X_LPSC_IMCOP                   37
+#define TNETV107X_LPSC_SPARE                   38
+#define TNETV107X_LPSC_SDIO1                   39
+#define TNETV107X_LPSC_USB1                    40
+#define TNETV107X_LPSC_USBSS                   41
+#define TNETV107X_LPSC_DDR2_EMIF1_VRST         42
+#define TNETV107X_LPSC_DDR2_EMIF2_VCTL_RST     43
+#define TNETV107X_LPSC_MAX                     44
+
 /* PSC register offsets */
 #define EPCPR          0x070
 #define PTCMD          0x120
 #define MDSTAT         0x800
 #define MDCTL          0xA00
 
+/* PSC module states */
+#define PSC_STATE_SWRSTDISABLE 0
+#define PSC_STATE_SYNCRST      1
+#define PSC_STATE_DISABLE      2
+#define PSC_STATE_ENABLE       3
+
 #define MDSTAT_STATE_MASK 0x1f
 
 #ifndef __ASSEMBLER__
 
 extern int davinci_psc_is_clk_active(unsigned int ctlr, unsigned int id);
 extern void davinci_psc_config(unsigned int domain, unsigned int ctlr,
-               unsigned int id, char enable);
+               unsigned int id, u32 next_state);
 
 #endif
 
index a584697..f6c4f34 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <mach/hardware.h>
 
-#define DAVINCI_MAX_NR_UARTS   3
 #define DAVINCI_UART0_BASE     (IO_PHYS + 0x20000)
 #define DAVINCI_UART1_BASE     (IO_PHYS + 0x20400)
 #define DAVINCI_UART2_BASE     (IO_PHYS + 0x20800)
index 5a7d758..e65629c 100644 (file)
@@ -11,7 +11,7 @@
 #ifndef __ASM_ARCH_SYSTEM_H
 #define __ASM_ARCH_SYSTEM_H
 
-extern void davinci_watchdog_reset(void);
+#include <mach/common.h>
 
 static inline void arch_idle(void)
 {
@@ -20,7 +20,8 @@ static inline void arch_idle(void)
 
 static inline void arch_reset(char mode, const char *cmd)
 {
-       davinci_watchdog_reset();
+       if (davinci_soc_info.reset)
+               davinci_soc_info.reset(davinci_soc_info.reset_device);
 }
 
 #endif /* __ASM_ARCH_SYSTEM_H */
index a1c0b6b..8ea60a8 100644 (file)
 #include <linux/io.h>
 
 #include <asm/tlb.h>
+#include <asm/mach/map.h>
 
-#define BETWEEN(p, st, sz)     ((p) >= (st) && (p) < ((st) + (sz)))
-#define XLATE(p, pst, vst)     ((void __iomem *)((p) - (pst) + (vst)))
+#include <mach/common.h>
 
 /*
  * Intercept ioremap() requests for addresses in our fixed mapping regions.
  */
 void __iomem *davinci_ioremap(unsigned long p, size_t size, unsigned int type)
 {
-       if (BETWEEN(p, IO_PHYS, IO_SIZE))
-               return XLATE(p, IO_PHYS, IO_VIRT);
+       struct map_desc *desc = davinci_soc_info.io_desc;
+       int desc_num = davinci_soc_info.io_desc_num;
+       int i;
 
-       return __arm_ioremap_caller(p, size, type, __builtin_return_address(0));
+       for (i = 0; i < desc_num; i++, desc++) {
+               unsigned long iophys = __pfn_to_phys(desc->pfn);
+               unsigned long iosize = desc->length;
+
+               if (p >= iophys && (p + size) <= (iophys + iosize))
+                       return __io(desc->virtual + p - iophys);
+       }
+
+       return __arm_ioremap_caller(p, size, type,
+                                       __builtin_return_address(0));
 }
 EXPORT_SYMBOL(davinci_ioremap);
 
index af92ffe..784ddf3 100644 (file)
@@ -116,6 +116,11 @@ void __init davinci_irq_init(void)
        unsigned i;
        const u8 *davinci_def_priorities = davinci_soc_info.intc_irq_prios;
 
+       davinci_intc_type = DAVINCI_INTC_TYPE_AINTC;
+       davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_4K);
+       if (WARN_ON(!davinci_intc_base))
+               return;
+
        /* Clear all interrupt requests */
        davinci_irq_writel(~0x0, FIQ_REG0_OFFSET);
        davinci_irq_writel(~0x0, FIQ_REG1_OFFSET);
@@ -148,7 +153,7 @@ void __init davinci_irq_init(void)
        }
 
        /* set up genirq dispatch for ARM INTC */
-       for (i = 0; i < DAVINCI_N_AINTC_IRQ; i++) {
+       for (i = 0; i < davinci_soc_info.intc_irq_num; i++) {
                set_irq_chip(i, &davinci_irq_chip_0);
                set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
                if (i != IRQ_TINT1_TINT34)
index f757e83..f34a8dc 100644 (file)
@@ -22,6 +22,8 @@
 #include <mach/mux.h>
 #include <mach/common.h>
 
+static void __iomem *pinmux_base;
+
 /*
  * Sets the DAVINCI MUX register based on the table
  */
@@ -29,14 +31,19 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
 {
        static DEFINE_SPINLOCK(mux_spin_lock);
        struct davinci_soc_info *soc_info = &davinci_soc_info;
-       void __iomem *base = soc_info->pinmux_base;
        unsigned long flags;
        const struct mux_config *cfg;
        unsigned int reg_orig = 0, reg = 0;
        unsigned int mask, warn = 0;
 
-       if (!soc_info->pinmux_pins)
-               BUG();
+       if (WARN_ON(!soc_info->pinmux_pins))
+               return -ENODEV;
+
+       if (!pinmux_base) {
+               pinmux_base = ioremap(soc_info->pinmux_base, SZ_4K);
+               if (WARN_ON(!pinmux_base))
+                       return -ENOMEM;
+       }
 
        if (index >= soc_info->pinmux_pins_num) {
                printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n",
@@ -57,7 +64,7 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
                unsigned        tmp1, tmp2;
 
                spin_lock_irqsave(&mux_spin_lock, flags);
-               reg_orig = __raw_readl(base + cfg->mux_reg);
+               reg_orig = __raw_readl(pinmux_base + cfg->mux_reg);
 
                mask = (cfg->mask << cfg->mask_offset);
                tmp1 = reg_orig & mask;
@@ -69,7 +76,7 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
                if (tmp1 != tmp2)
                        warn = 1;
 
-               __raw_writel(reg, base + cfg->mux_reg);
+               __raw_writel(reg, pinmux_base + cfg->mux_reg);
                spin_unlock_irqrestore(&mux_spin_lock, flags);
        }
 
@@ -91,7 +98,7 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
 }
 EXPORT_SYMBOL(davinci_cfg_reg);
 
-int da8xx_pinmux_setup(const short pins[])
+int __init_or_module davinci_cfg_reg_list(const short pins[])
 {
        int i, error = -EINVAL;
 
index adc8694..5aad1e7 100644 (file)
@@ -20,7 +20,7 @@
                        .name =  #desc,                                 \
                        .debug = dbg,                                   \
                        .mux_reg_name = "PINMUX"#muxreg,                \
-                       .mux_reg = PINMUX##muxreg,                      \
+                       .mux_reg = PINMUX(muxreg),                      \
                        .mask_offset = mode_offset,                     \
                        .mask = mode_mask,                              \
                        .mode = mux_mode,                               \
index adf6b5c..1b15dbd 100644 (file)
@@ -38,8 +38,9 @@ int __init davinci_psc_is_clk_active(unsigned int ctlr, unsigned int id)
                return 0;
        }
 
-       psc_base = soc_info->psc_bases[ctlr];
+       psc_base = ioremap(soc_info->psc_bases[ctlr], SZ_4K);
        mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
+       iounmap(psc_base);
 
        /* if clocked, state can be "Enable" or "SyncReset" */
        return mdstat & BIT(12);
@@ -47,12 +48,11 @@ int __init davinci_psc_is_clk_active(unsigned int ctlr, unsigned int id)
 
 /* Enable or disable a PSC domain */
 void davinci_psc_config(unsigned int domain, unsigned int ctlr,
-               unsigned int id, char enable)
+               unsigned int id, u32 next_state)
 {
        u32 epcpr, ptcmd, ptstat, pdstat, pdctl1, mdstat, mdctl;
        void __iomem *psc_base;
        struct davinci_soc_info *soc_info = &davinci_soc_info;
-       u32 next_state = enable ? 0x3 : 0x2; /* 0x3 enables, 0x2 disables */
 
        if (!soc_info->psc_bases || (ctlr >= soc_info->psc_bases_num)) {
                pr_warning("PSC: Bad psc data: 0x%x[%d]\n",
@@ -60,7 +60,7 @@ void davinci_psc_config(unsigned int domain, unsigned int ctlr,
                return;
        }
 
-       psc_base = soc_info->psc_bases[ctlr];
+       psc_base = ioremap(soc_info->psc_bases[ctlr], SZ_4K);
 
        mdctl = __raw_readl(psc_base + MDCTL + 4 * id);
        mdctl &= ~MDSTAT_STATE_MASK;
@@ -100,4 +100,6 @@ void davinci_psc_config(unsigned int domain, unsigned int ctlr,
        do {
                mdstat = __raw_readl(psc_base + MDSTAT + 4 * id);
        } while (!((mdstat & MDSTAT_STATE_MASK) == next_state));
+
+       iounmap(psc_base);
 }
index 7ce5ba0..1875740 100644 (file)
@@ -35,14 +35,20 @@ static inline unsigned int serial_read_reg(struct plat_serial8250_port *up,
                                           int offset)
 {
        offset <<= up->regshift;
-       return (unsigned int)__raw_readl(IO_ADDRESS(up->mapbase) + offset);
+
+       WARN_ONCE(!up->membase, "unmapped read: uart[%d]\n", offset);
+
+       return (unsigned int)__raw_readl(up->membase + offset);
 }
 
 static inline void serial_write_reg(struct plat_serial8250_port *p, int offset,
                                    int value)
 {
        offset <<= p->regshift;
-       __raw_writel(value, IO_ADDRESS(p->mapbase) + offset);
+
+       WARN_ONCE(!p->membase, "unmapped write: uart[%d]\n", offset);
+
+       __raw_writel(value, p->membase + offset);
 }
 
 static void __init davinci_serial_reset(struct plat_serial8250_port *p)
@@ -77,20 +83,32 @@ int __init davinci_serial_init(struct davinci_uart_config *info)
         * Make sure the serial ports are muxed on at this point.
         * You have to mux them off in device drivers later on if not needed.
         */
-       for (i = 0; i < DAVINCI_MAX_NR_UARTS; i++, p++) {
+       for (i = 0; p->flags; i++, p++) {
                if (!(info->enabled_uarts & (1 << i)))
                        continue;
 
                sprintf(name, "uart%d", i);
                uart_clk = clk_get(dev, name);
-               if (IS_ERR(uart_clk))
+               if (IS_ERR(uart_clk)) {
                        printk(KERN_ERR "%s:%d: failed to get UART%d clock\n",
                                        __func__, __LINE__, i);
-               else {
-                       clk_enable(uart_clk);
-                       p->uartclk = clk_get_rate(uart_clk);
-                       davinci_serial_reset(p);
+                       continue;
                }
+
+               clk_enable(uart_clk);
+               p->uartclk = clk_get_rate(uart_clk);
+
+               if (!p->membase && p->mapbase) {
+                       p->membase = ioremap(p->mapbase, SZ_4K);
+
+                       if (p->membase)
+                               p->flags &= ~UPF_IOREMAP;
+                       else
+                               pr_err("uart regs ioremap failed\n");
+               }
+
+               if (p->membase && p->type != PORT_AR7)
+                       davinci_serial_reset(p);
        }
 
        return platform_device_register(soc_info->serial_dev);
index 9e0b106..0f21c36 100644 (file)
@@ -197,32 +197,36 @@ static void __init timer_init(void)
 {
        struct davinci_soc_info *soc_info = &davinci_soc_info;
        struct davinci_timer_instance *dtip = soc_info->timer_info->timers;
+       void __iomem *base[2];
        int i;
 
        /* Global init of each 64-bit timer as a whole */
        for(i=0; i<2; i++) {
                u32 tgcr;
-               void __iomem *base = dtip[i].base;
+
+               base[i] = ioremap(dtip[i].base, SZ_4K);
+               if (WARN_ON(!base[i]))
+                       continue;
 
                /* Disabled, Internal clock source */
-               __raw_writel(0, base + TCR);
+               __raw_writel(0, base[i] + TCR);
 
                /* reset both timers, no pre-scaler for timer34 */
                tgcr = 0;
-               __raw_writel(tgcr, base + TGCR);
+               __raw_writel(tgcr, base[i] + TGCR);
 
                /* Set both timers to unchained 32-bit */
                tgcr = TGCR_TIMMODE_32BIT_UNCHAINED << TGCR_TIMMODE_SHIFT;
-               __raw_writel(tgcr, base + TGCR);
+               __raw_writel(tgcr, base[i] + TGCR);
 
                /* Unreset timers */
                tgcr |= (TGCR_UNRESET << TGCR_TIM12RS_SHIFT) |
                        (TGCR_UNRESET << TGCR_TIM34RS_SHIFT);
-               __raw_writel(tgcr, base + TGCR);
+               __raw_writel(tgcr, base[i] + TGCR);
 
                /* Init both counters to zero */
-               __raw_writel(0, base + TIM12);
-               __raw_writel(0, base + TIM34);
+               __raw_writel(0, base[i] + TIM12);
+               __raw_writel(0, base[i] + TIM34);
        }
 
        /* Init of each timer as a 32-bit timer */
@@ -231,7 +235,9 @@ static void __init timer_init(void)
                int timer = ID_TO_TIMER(t->id);
                u32 irq;
 
-               t->base = dtip[timer].base;
+               t->base = base[timer];
+               if (!t->base)
+                       continue;
 
                if (IS_TIMER_BOT(t->id)) {
                        t->enamode_shift = 6;
@@ -361,13 +367,13 @@ static void __init davinci_timer_init(void)
                }
        }
 
-       /* init timer hw */
-       timer_init();
-
        timer_clk = clk_get(NULL, "timer0");
        BUG_ON(IS_ERR(timer_clk));
        clk_enable(timer_clk);
 
+       /* init timer hw */
+       timer_init();
+
        davinci_clock_tick_rate = clk_get_rate(timer_clk);
 
        /* setup clocksource */
@@ -399,13 +405,16 @@ struct sys_timer davinci_timer = {
 
 
 /* reset board using watchdog timer */
-void davinci_watchdog_reset(void)
+void davinci_watchdog_reset(struct platform_device *pdev)
 {
        u32 tgcr, wdtcr;
-       struct platform_device *pdev = &davinci_wdt_device;
-       void __iomem *base = IO_ADDRESS(pdev->resource[0].start);
+       void __iomem *base;
        struct clk *wd_clk;
 
+       base = ioremap(pdev->resource[0].start, SZ_4K);
+       if (WARN_ON(!base))
+               return;
+
        wd_clk = clk_get(&pdev->dev, NULL);
        if (WARN_ON(IS_ERR(wd_clk)))
                return;
index caf6d51..3a1a855 100644 (file)
@@ -41,7 +41,7 @@ static struct platform_device adssphere_flash = {
        .resource       = &adssphere_flash_resource,
 };
 
-static struct ep93xx_eth_data adssphere_eth_data = {
+static struct ep93xx_eth_data __initdata adssphere_eth_data = {
        .phy_id         = 1,
 };
 
index 5f80092..e29bdef 100644 (file)
@@ -96,6 +96,10 @@ static struct clk clk_keypad = {
        .enable_mask    = EP93XX_SYSCON_KEYTCHCLKDIV_KEN,
        .set_rate       = set_keytchclk_rate,
 };
+static struct clk clk_spi = {
+       .parent         = &clk_xtali,
+       .rate           = EP93XX_EXT_CLK_RATE,
+};
 static struct clk clk_pwm = {
        .parent         = &clk_xtali,
        .rate           = EP93XX_EXT_CLK_RATE,
@@ -186,6 +190,7 @@ static struct clk_lookup clocks[] = {
        INIT_CK("ep93xx-ohci",          NULL,           &clk_usb_host),
        INIT_CK("ep93xx-keypad",        NULL,           &clk_keypad),
        INIT_CK("ep93xx-fb",            NULL,           &clk_video),
+       INIT_CK("ep93xx-spi.0",         NULL,           &clk_spi),
        INIT_CK(NULL,                   "pwm_clk",      &clk_pwm),
        INIT_CK(NULL,                   "m2p0",         &clk_m2p0),
        INIT_CK(NULL,                   "m2p1",         &clk_m2p1),
@@ -473,6 +478,14 @@ static int __init ep93xx_clock_init(void)
        /* Initialize the pll2 derived clocks */
        clk_usb_host.rate = clk_pll2.rate / (((value >> 28) & 0xf) + 1);
 
+       /*
+        * EP93xx SSP clock rate was doubled in version E2. For more information
+        * see:
+        *     http://www.cirrus.com/en/pubs/appNote/AN273REV4.pdf
+        */
+       if (ep93xx_chip_revision() < EP93XX_CHIP_REV_E2)
+               clk_spi.rate /= 2;
+
        pr_info("PLL1 running at %ld MHz, PLL2 at %ld MHz\n",
                clk_pll1.rate / 1000000, clk_pll2.rate / 1000000);
        pr_info("FCLK %ld MHz, HCLK %ld MHz, PCLK %ld MHz\n",
index 90fb591..9092677 100644 (file)
 #include <linux/amba/serial.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
+#include <linux/spi/spi.h>
 
 #include <mach/hardware.h>
 #include <mach/fb.h>
 #include <mach/ep93xx_keypad.h>
+#include <mach/ep93xx_spi.h>
 
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
@@ -222,6 +224,20 @@ void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
 }
 EXPORT_SYMBOL(ep93xx_devcfg_set_clear);
 
+/**
+ * ep93xx_chip_revision() - returns the EP93xx chip revision
+ *
+ * See <mach/platform.h> for more information.
+ */
+unsigned int ep93xx_chip_revision(void)
+{
+       unsigned int v;
+
+       v = __raw_readl(EP93XX_SYSCON_SYSCFG);
+       v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
+       v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
+       return v;
+}
 
 /*************************************************************************
  * EP93xx peripheral handling
@@ -330,6 +346,10 @@ static struct platform_device ep93xx_ohci_device = {
        .resource       = ep93xx_ohci_resources,
 };
 
+
+/*************************************************************************
+ * EP93xx ethernet peripheral handling
+ *************************************************************************/
 static struct ep93xx_eth_data ep93xx_eth_data;
 
 static struct resource ep93xx_eth_resource[] = {
@@ -354,6 +374,12 @@ static struct platform_device ep93xx_eth_device = {
        .resource       = ep93xx_eth_resource,
 };
 
+/**
+ * ep93xx_register_eth - Register the built-in ethernet platform device.
+ * @data:      platform specific ethernet configuration (__initdata)
+ * @copy_addr: flag indicating that the MAC address should be copied
+ *             from the IndAd registers (as programmed by the bootloader)
+ */
 void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
 {
        if (copy_addr)
@@ -370,11 +396,19 @@ void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
 static struct i2c_gpio_platform_data ep93xx_i2c_data;
 
 static struct platform_device ep93xx_i2c_device = {
-       .name                   = "i2c-gpio",
-       .id                     = 0,
-       .dev.platform_data      = &ep93xx_i2c_data,
+       .name           = "i2c-gpio",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &ep93xx_i2c_data,
+       },
 };
 
+/**
+ * ep93xx_register_i2c - Register the i2c platform device.
+ * @data:      platform specific i2c-gpio configuration (__initdata)
+ * @devices:   platform specific i2c bus device information (__initdata)
+ * @num:       the number of devices on the i2c bus
+ */
 void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
                                struct i2c_board_info *devices, int num)
 {
@@ -398,17 +432,67 @@ void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
        platform_device_register(&ep93xx_i2c_device);
 }
 
+/*************************************************************************
+ * EP93xx SPI peripheral handling
+ *************************************************************************/
+static struct ep93xx_spi_info ep93xx_spi_master_data;
+
+static struct resource ep93xx_spi_resources[] = {
+       {
+               .start  = EP93XX_SPI_PHYS_BASE,
+               .end    = EP93XX_SPI_PHYS_BASE + 0x18 - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = IRQ_EP93XX_SSP,
+               .end    = IRQ_EP93XX_SSP,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device ep93xx_spi_device = {
+       .name           = "ep93xx-spi",
+       .id             = 0,
+       .dev            = {
+               .platform_data = &ep93xx_spi_master_data,
+       },
+       .num_resources  = ARRAY_SIZE(ep93xx_spi_resources),
+       .resource       = ep93xx_spi_resources,
+};
+
+/**
+ * ep93xx_register_spi() - registers spi platform device
+ * @info: ep93xx board specific spi master info (__initdata)
+ * @devices: SPI devices to register (__initdata)
+ * @num: number of SPI devices to register
+ *
+ * This function registers platform device for the EP93xx SPI controller and
+ * also makes sure that SPI pins are muxed so that I2S is not using those pins.
+ */
+void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
+                               struct spi_board_info *devices, int num)
+{
+       /*
+        * When SPI is used, we need to make sure that I2S is muxed off from
+        * SPI pins.
+        */
+       ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
+
+       ep93xx_spi_master_data = *info;
+       spi_register_board_info(devices, num);
+       platform_device_register(&ep93xx_spi_device);
+}
 
 /*************************************************************************
  * EP93xx LEDs
  *************************************************************************/
 static struct gpio_led ep93xx_led_pins[] = {
        {
-               .name                   = "platform:grled",
-               .gpio                   = EP93XX_GPIO_LINE_GRLED,
+               .name   = "platform:grled",
+               .gpio   = EP93XX_GPIO_LINE_GRLED,
        }, {
-               .name                   = "platform:rdled",
-               .gpio                   = EP93XX_GPIO_LINE_RDLED,
+               .name   = "platform:rdled",
+               .gpio   = EP93XX_GPIO_LINE_RDLED,
        },
 };
 
@@ -528,7 +612,7 @@ static struct platform_device ep93xx_fb_device = {
        .name                   = "ep93xx-fb",
        .id                     = -1,
        .dev                    = {
-               .platform_data  = &ep93xxfb_data,
+               .platform_data          = &ep93xxfb_data,
                .coherent_dma_mask      = DMA_BIT_MASK(32),
                .dma_mask               = &ep93xx_fb_device.dev.coherent_dma_mask,
        },
@@ -536,6 +620,10 @@ static struct platform_device ep93xx_fb_device = {
        .resource               = ep93xx_fb_resource,
 };
 
+/**
+ * ep93xx_register_fb - Register the framebuffer platform device.
+ * @data:      platform specific framebuffer configuration (__initdata)
+ */
 void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
 {
        ep93xxfb_data = *data;
@@ -546,6 +634,8 @@ void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
 /*************************************************************************
  * EP93xx matrix keypad peripheral handling
  *************************************************************************/
+static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
+
 static struct resource ep93xx_keypad_resource[] = {
        {
                .start  = EP93XX_KEY_MATRIX_PHYS_BASE,
@@ -559,15 +649,22 @@ static struct resource ep93xx_keypad_resource[] = {
 };
 
 static struct platform_device ep93xx_keypad_device = {
-       .name                   = "ep93xx-keypad",
-       .id                     = -1,
-       .num_resources          = ARRAY_SIZE(ep93xx_keypad_resource),
-       .resource               = ep93xx_keypad_resource,
+       .name           = "ep93xx-keypad",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &ep93xx_keypad_data,
+       },
+       .num_resources  = ARRAY_SIZE(ep93xx_keypad_resource),
+       .resource       = ep93xx_keypad_resource,
 };
 
+/**
+ * ep93xx_register_keypad - Register the keypad platform device.
+ * @data:      platform specific keypad configuration (__initdata)
+ */
 void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
 {
-       ep93xx_keypad_device.dev.platform_data = data;
+       ep93xx_keypad_data = *data;
        platform_device_register(&ep93xx_keypad_device);
 }
 
index d22d67a..3884182 100644 (file)
@@ -74,7 +74,7 @@ static void __init edb93xx_register_flash(void)
        }
 }
 
-static struct ep93xx_eth_data edb93xx_eth_data = {
+static struct ep93xx_eth_data __initdata edb93xx_eth_data = {
        .phy_id         = 1,
 };
 
@@ -82,7 +82,7 @@ static struct ep93xx_eth_data edb93xx_eth_data = {
 /*************************************************************************
  * EDB93xx i2c peripheral handling
  *************************************************************************/
-static struct i2c_gpio_platform_data edb93xx_i2c_gpio_data = {
+static struct i2c_gpio_platform_data __initdata edb93xx_i2c_gpio_data = {
        .sda_pin                = EP93XX_GPIO_LINE_EEDAT,
        .sda_is_open_drain      = 0,
        .scl_pin                = EP93XX_GPIO_LINE_EECLK,
index 3da7ca8..a809618 100644 (file)
@@ -41,7 +41,7 @@ static struct platform_device gesbc9312_flash = {
        .resource       = &gesbc9312_flash_resource,
 };
 
-static struct ep93xx_eth_data gesbc9312_eth_data = {
+static struct ep93xx_eth_data __initdata gesbc9312_eth_data = {
        .phy_id         = 1,
 };
 
index 93e2ecc..b1e096f 100644 (file)
 
 #define EP93XX_AAC_BASE                        EP93XX_APB_IOMEM(0x00080000)
 
+#define EP93XX_SPI_PHYS_BASE           EP93XX_APB_PHYS(0x000a0000)
 #define EP93XX_SPI_BASE                        EP93XX_APB_IOMEM(0x000a0000)
 
 #define EP93XX_IRDA_BASE               EP93XX_APB_IOMEM(0x000b0000)
index c6dc14d..9a4413d 100644 (file)
@@ -6,9 +6,11 @@
 
 struct i2c_gpio_platform_data;
 struct i2c_board_info;
+struct spi_board_info;
 struct platform_device;
 struct ep93xxfb_mach_info;
 struct ep93xx_keypad_platform_data;
+struct ep93xx_spi_info;
 
 struct ep93xx_eth_data
 {
@@ -33,9 +35,19 @@ static inline void ep93xx_devcfg_clear_bits(unsigned int bits)
        ep93xx_devcfg_set_clear(0x00, bits);
 }
 
+#define EP93XX_CHIP_REV_D0     3
+#define EP93XX_CHIP_REV_D1     4
+#define EP93XX_CHIP_REV_E0     5
+#define EP93XX_CHIP_REV_E1     6
+#define EP93XX_CHIP_REV_E2     7
+
+unsigned int ep93xx_chip_revision(void);
+
 void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr);
 void ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
                         struct i2c_board_info *devices, int num);
+void ep93xx_register_spi(struct ep93xx_spi_info *info,
+                        struct spi_board_info *devices, int num);
 void ep93xx_register_fb(struct ep93xxfb_mach_info *data);
 void ep93xx_register_pwm(int pwm0, int pwm1);
 int ep93xx_pwm_acquire_gpio(struct platform_device *pdev);
index c33360e..1cc911b 100644 (file)
@@ -80,7 +80,7 @@ static void __init micro9_register_flash(void)
 /*************************************************************************
  * Micro9 Ethernet
  *************************************************************************/
-static struct ep93xx_eth_data micro9_eth_data = {
+static struct ep93xx_eth_data __initdata micro9_eth_data = {
        .phy_id         = 0x1f,
 };
 
index cd93990..388aec9 100644 (file)
@@ -49,17 +49,17 @@ static struct platform_device simone_flash = {
        },
 };
 
-static struct ep93xx_eth_data simone_eth_data = {
+static struct ep93xx_eth_data __initdata simone_eth_data = {
        .phy_id         = 1,
 };
 
-static struct ep93xxfb_mach_info simone_fb_info = {
+static struct ep93xxfb_mach_info __initdata simone_fb_info = {
        .num_modes      = EP93XXFB_USE_MODEDB,
        .bpp            = 16,
        .flags          = EP93XXFB_USE_SDCSN0 | EP93XXFB_PCLK_FALLING,
 };
 
-static struct i2c_gpio_platform_data simone_i2c_gpio_data = {
+static struct i2c_gpio_platform_data __initdata simone_i2c_gpio_data = {
        .sda_pin                = EP93XX_GPIO_LINE_EEDAT,
        .sda_is_open_drain      = 0,
        .scl_pin                = EP93XX_GPIO_LINE_EECLK,
index 51134b0..38deaee 100644 (file)
@@ -125,11 +125,11 @@ static struct platform_device snappercl15_nand_device = {
        .num_resources          = ARRAY_SIZE(snappercl15_nand_resource),
 };
 
-static struct ep93xx_eth_data snappercl15_eth_data = {
+static struct ep93xx_eth_data __initdata snappercl15_eth_data = {
        .phy_id                 = 1,
 };
 
-static struct i2c_gpio_platform_data snappercl15_i2c_gpio_data = {
+static struct i2c_gpio_platform_data __initdata snappercl15_i2c_gpio_data = {
        .sda_pin                = EP93XX_GPIO_LINE_EEDAT,
        .sda_is_open_drain      = 0,
        .scl_pin                = EP93XX_GPIO_LINE_EECLK,
@@ -145,7 +145,7 @@ static struct i2c_board_info __initdata snappercl15_i2c_data[] = {
        },
 };
 
-static struct ep93xxfb_mach_info snappercl15_fb_info = {
+static struct ep93xxfb_mach_info __initdata snappercl15_fb_info = {
        .num_modes              = EP93XXFB_USE_MODEDB,
        .bpp                    = 16,
 };
index fac1ec7..9553031 100644 (file)
@@ -186,7 +186,7 @@ static struct platform_device ts72xx_wdt_device = {
        .resource       = ts72xx_wdt_resources,
 };
 
-static struct ep93xx_eth_data ts72xx_eth_data = {
+static struct ep93xx_eth_data __initdata ts72xx_eth_data = {
        .phy_id         = 1,
 };
 
index df97d16..27db275 100644 (file)
@@ -11,6 +11,7 @@ config ARCH_INTEGRATOR_AP
 config ARCH_INTEGRATOR_CP
        bool "Support Integrator/CP platform"
        select ARCH_CINTEGRATOR
+       select ARM_TIMER_SP804
        help
          Include support for the ARM(R) Integrator CP platform.
 
index 6a5ef8d..ebeef96 100644 (file)
@@ -4,7 +4,7 @@
 
 # Object file lists.
 
-obj-y                                  := clock.o core.o lm.o
+obj-y                                  := core.o lm.o
 obj-$(CONFIG_ARCH_INTEGRATOR_AP)       += integrator_ap.o
 obj-$(CONFIG_ARCH_INTEGRATOR_CP)       += integrator_cp.o
 
diff --git a/arch/arm/mach-integrator/common.h b/arch/arm/mach-integrator/common.h
deleted file mode 100644 (file)
index 609c49d..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-extern void integrator_time_init(unsigned long, unsigned int);
-extern unsigned long integrator_gettimeoffset(void);
index 8b390e3..b02cfc0 100644 (file)
 #include <asm/clkdev.h>
 #include <mach/clkdev.h>
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/irq.h>
-#include <asm/hardware/arm_timer.h>
 #include <mach/cm.h>
 #include <asm/system.h>
 #include <asm/leds.h>
 #include <asm/mach/time.h>
 
-#include "common.h"
-
 static struct amba_pl010_data integrator_uart_data;
 
 static struct amba_device rtc_device = {
@@ -163,8 +161,8 @@ arch_initcall(integrator_init);
  *  UART0  7    6
  *  UART1  5    4
  */
-#define SC_CTRLC       (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLC_OFFSET)
-#define SC_CTRLS       (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_CTRLS_OFFSET)
+#define SC_CTRLC       IO_ADDRESS(INTEGRATOR_SC_CTRLC)
+#define SC_CTRLS       IO_ADDRESS(INTEGRATOR_SC_CTRLS)
 
 static void integrator_uart_set_mctrl(struct amba_device *dev, void __iomem *base, unsigned int mctrl)
 {
@@ -196,7 +194,7 @@ static struct amba_pl010_data integrator_uart_data = {
        .set_mctrl = integrator_uart_set_mctrl,
 };
 
-#define CM_CTRL        IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_CTRL_OFFSET
+#define CM_CTRL        IO_ADDRESS(INTEGRATOR_HDR_CTRL)
 
 static DEFINE_SPINLOCK(cm_lock);
 
@@ -217,120 +215,3 @@ void cm_control(u32 mask, u32 set)
 }
 
 EXPORT_SYMBOL(cm_control);
-
-/*
- * Where is the timer (VA)?
- */
-#define TIMER0_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000000)
-#define TIMER1_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000100)
-#define TIMER2_VA_BASE (IO_ADDRESS(INTEGRATOR_CT_BASE)+0x00000200)
-#define VA_IC_BASE     IO_ADDRESS(INTEGRATOR_IC_BASE) 
-
-/*
- * How long is the timer interval?
- */
-#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
-#if TIMER_INTERVAL >= 0x100000
-#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
-#elif TIMER_INTERVAL >= 0x10000
-#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
-#else
-#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
-#endif
-
-static unsigned long timer_reload;
-
-/*
- * Returns number of ms since last clock interrupt.  Note that interrupts
- * will have been disabled by do_gettimeoffset()
- */
-unsigned long integrator_gettimeoffset(void)
-{
-       unsigned long ticks1, ticks2, status;
-
-       /*
-        * Get the current number of ticks.  Note that there is a race
-        * condition between us reading the timer and checking for
-        * an interrupt.  We get around this by ensuring that the
-        * counter has not reloaded between our two reads.
-        */
-       ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
-       do {
-               ticks1 = ticks2;
-               status = __raw_readl(VA_IC_BASE + IRQ_RAW_STATUS);
-               ticks2 = readl(TIMER1_VA_BASE + TIMER_VALUE) & 0xffff;
-       } while (ticks2 > ticks1);
-
-       /*
-        * Number of ticks since last interrupt.
-        */
-       ticks1 = timer_reload - ticks2;
-
-       /*
-        * Interrupt pending?  If so, we've reloaded once already.
-        */
-       if (status & (1 << IRQ_TIMERINT1))
-               ticks1 += timer_reload;
-
-       /*
-        * Convert the ticks to usecs
-        */
-       return TICKS2USECS(ticks1);
-}
-
-/*
- * IRQ handler for the timer
- */
-static irqreturn_t
-integrator_timer_interrupt(int irq, void *dev_id)
-{
-       /*
-        * clear the interrupt
-        */
-       writel(1, TIMER1_VA_BASE + TIMER_INTCLR);
-
-       timer_tick();
-
-       return IRQ_HANDLED;
-}
-
-static struct irqaction integrator_timer_irq = {
-       .name           = "Integrator Timer Tick",
-       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
-       .handler        = integrator_timer_interrupt,
-};
-
-/*
- * Set up timer interrupt, and return the current time in seconds.
- */
-void __init integrator_time_init(unsigned long reload, unsigned int ctrl)
-{
-       unsigned int timer_ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
-
-       timer_reload = reload;
-       timer_ctrl |= ctrl;
-
-       if (timer_reload > 0x100000) {
-               timer_reload >>= 8;
-               timer_ctrl |= TIMER_CTRL_DIV256;
-       } else if (timer_reload > 0x010000) {
-               timer_reload >>= 4;
-               timer_ctrl |= TIMER_CTRL_DIV16;
-       }
-
-       /*
-        * Initialise to a known state (all timers off)
-        */
-       writel(0, TIMER0_VA_BASE + TIMER_CTRL);
-       writel(0, TIMER1_VA_BASE + TIMER_CTRL);
-       writel(0, TIMER2_VA_BASE + TIMER_CTRL);
-
-       writel(timer_reload, TIMER1_VA_BASE + TIMER_LOAD);
-       writel(timer_reload, TIMER1_VA_BASE + TIMER_VALUE);
-       writel(timer_ctrl, TIMER1_VA_BASE + TIMER_CTRL);
-
-       /*
-        * Make irqs happen for the system timer
-        */
-       setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
-}
index f77f202..a3fbcb3 100644 (file)
 #include <linux/io.h>
 
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/mach-types.h>
-#include <asm/hardware/icst525.h>
+#include <asm/hardware/icst.h>
 
 static struct cpufreq_driver integrator_driver;
 
-#define CM_ID          (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET)
-#define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET)
-#define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET)
-#define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
+#define CM_ID          IO_ADDRESS(INTEGRATOR_HDR_ID)
+#define CM_OSC IO_ADDRESS(INTEGRATOR_HDR_OSC)
+#define CM_STAT IO_ADDRESS(INTEGRATOR_HDR_STAT)
+#define CM_LOCK IO_ADDRESS(INTEGRATOR_HDR_LOCK)
 
-static const struct icst525_params lclk_params = {
-       .ref            = 24000,
-       .vco_max        = 320000,
+static const struct icst_params lclk_params = {
+       .ref            = 24000000,
+       .vco_max        = ICST525_VCO_MAX_5V,
+       .vco_min        = ICST525_VCO_MIN,
        .vd_min         = 8,
        .vd_max         = 132,
        .rd_min         = 24,
        .rd_max         = 24,
+       .s2div          = icst525_s2div,
+       .idx2s          = icst525_idx2s,
 };
 
-static const struct icst525_params cclk_params = {
-       .ref            = 24000,
-       .vco_max        = 320000,
+static const struct icst_params cclk_params = {
+       .ref            = 24000000,
+       .vco_max        = ICST525_VCO_MAX_5V,
+       .vco_min        = ICST525_VCO_MIN,
        .vd_min         = 12,
        .vd_max         = 160,
        .rd_min         = 24,
        .rd_max         = 24,
+       .s2div          = icst525_s2div,
+       .idx2s          = icst525_idx2s,
 };
 
 /*
@@ -52,17 +59,17 @@ static const struct icst525_params cclk_params = {
  */
 static int integrator_verify_policy(struct cpufreq_policy *policy)
 {
-       struct icst525_vco vco;
+       struct icst_vco vco;
 
        cpufreq_verify_within_limits(policy, 
                                     policy->cpuinfo.min_freq, 
                                     policy->cpuinfo.max_freq);
 
-       vco = icst525_khz_to_vco(&cclk_params, policy->max);
-       policy->max = icst525_khz(&cclk_params, vco);
+       vco = icst_hz_to_vco(&cclk_params, policy->max * 1000);
+       policy->max = icst_hz(&cclk_params, vco) / 1000;
 
-       vco = icst525_khz_to_vco(&cclk_params, policy->min);
-       policy->min = icst525_khz(&cclk_params, vco);
+       vco = icst_hz_to_vco(&cclk_params, policy->min * 1000);
+       policy->min = icst_hz(&cclk_params, vco) / 1000;
 
        cpufreq_verify_within_limits(policy, 
                                     policy->cpuinfo.min_freq, 
@@ -78,7 +85,7 @@ static int integrator_set_target(struct cpufreq_policy *policy,
 {
        cpumask_t cpus_allowed;
        int cpu = policy->cpu;
-       struct icst525_vco vco;
+       struct icst_vco vco;
        struct cpufreq_freqs freqs;
        u_int cm_osc;
 
@@ -104,17 +111,17 @@ static int integrator_set_target(struct cpufreq_policy *policy,
        }
        vco.v = cm_osc & 255;
        vco.r = 22;
-       freqs.old = icst525_khz(&cclk_params, vco);
+       freqs.old = icst_hz(&cclk_params, vco) / 1000;
 
-       /* icst525_khz_to_vco rounds down -- so we need the next
+       /* icst_hz_to_vco rounds down -- so we need the next
         * larger freq in case of CPUFREQ_RELATION_L.
         */
        if (relation == CPUFREQ_RELATION_L)
                target_freq += 999;
        if (target_freq > policy->max)
                target_freq = policy->max;
-       vco = icst525_khz_to_vco(&cclk_params, target_freq);
-       freqs.new = icst525_khz(&cclk_params, vco);
+       vco = icst_hz_to_vco(&cclk_params, target_freq * 1000);
+       freqs.new = icst_hz(&cclk_params, vco) / 1000;
 
        freqs.cpu = policy->cpu;
 
@@ -154,7 +161,7 @@ static unsigned int integrator_get(unsigned int cpu)
        cpumask_t cpus_allowed;
        unsigned int current_freq;
        u_int cm_osc;
-       struct icst525_vco vco;
+       struct icst_vco vco;
 
        cpus_allowed = current->cpus_allowed;
 
@@ -172,7 +179,7 @@ static unsigned int integrator_get(unsigned int cpu)
        vco.v = cm_osc & 255;
        vco.r = 22;
 
-       current_freq = icst525_khz(&cclk_params, vco); /* current freq */
+       current_freq = icst_hz(&cclk_params, vco) / 1000; /* current freq */
 
        set_cpus_allowed(current, cpus_allowed);
 
index 41b1072..fd684bf 100644 (file)
@@ -25,7 +25,7 @@
 
 #include <asm/clkdev.h>
 #include <mach/clkdev.h>
-#include <asm/hardware/icst525.h>
+#include <asm/hardware/icst.h>
 #include <mach/lm.h>
 #include <mach/impd1.h>
 #include <asm/sizes.h>
@@ -41,32 +41,25 @@ struct impd1_module {
        struct clk_lookup *clks[3];
 };
 
-static const struct icst525_params impd1_vco_params = {
-       .ref            = 24000,        /* 24 MHz */
-       .vco_max        = 200000,       /* 200 MHz */
+static const struct icst_params impd1_vco_params = {
+       .ref            = 24000000,     /* 24 MHz */
+       .vco_max        = ICST525_VCO_MAX_3V,
+       .vco_min        = ICST525_VCO_MIN,
        .vd_min         = 12,
        .vd_max         = 519,
        .rd_min         = 3,
        .rd_max         = 120,
+       .s2div          = icst525_s2div,
+       .idx2s          = icst525_idx2s,
 };
 
-static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
+static void impd1_setvco(struct clk *clk, struct icst_vco vco)
 {
        struct impd1_module *impd1 = clk->data;
-       int vconr = clk - impd1->vcos;
-       u32 val;
-
-       val = vco.v | (vco.r << 9) | (vco.s << 16);
+       u32 val = vco.v | (vco.r << 9) | (vco.s << 16);
 
        writel(0xa05f, impd1->base + IMPD1_LOCK);
-       switch (vconr) {
-       case 0:
-               writel(val, impd1->base + IMPD1_OSC1);
-               break;
-       case 1:
-               writel(val, impd1->base + IMPD1_OSC2);
-               break;
-       }
+       writel(val, clk->vcoreg);
        writel(0, impd1->base + IMPD1_LOCK);
 
 #ifdef DEBUG
@@ -74,11 +67,17 @@ static void impd1_setvco(struct clk *clk, struct icst525_vco vco)
        vco.r = (val >> 9) & 0x7f;
        vco.s = (val >> 16) & 7;
 
-       pr_debug("IM-PD1: VCO%d clock is %ld kHz\n",
-                vconr, icst525_khz(&impd1_vco_params, vco));
+       pr_debug("IM-PD1: VCO%d clock is %ld Hz\n",
+                vconr, icst525_hz(&impd1_vco_params, vco));
 #endif
 }
 
+static const struct clk_ops impd1_clk_ops = {
+       .round  = icst_clk_round,
+       .set    = icst_clk_set,
+       .setvco = impd1_setvco,
+};
+
 void impd1_tweak_control(struct device *dev, u32 mask, u32 val)
 {
        struct impd1_module *impd1 = dev_get_drvdata(dev);
@@ -374,11 +373,13 @@ static int impd1_probe(struct lm_device *dev)
                (unsigned long)dev->resource.start);
 
        for (i = 0; i < ARRAY_SIZE(impd1->vcos); i++) {
+               impd1->vcos[i].ops = &impd1_clk_ops,
                impd1->vcos[i].owner = THIS_MODULE,
                impd1->vcos[i].params = &impd1_vco_params,
-               impd1->vcos[i].data = impd1,
-               impd1->vcos[i].setvco = impd1_setvco;
+               impd1->vcos[i].data = impd1;
        }
+       impd1->vcos[0].vcoreg = impd1->base + IMPD1_OSC1;
+       impd1->vcos[1].vcoreg = impd1->base + IMPD1_OSC2;
 
        impd1->clks[0] = clkdev_alloc(&impd1->vcos[0], NULL, "lm%x:01000",
                                        dev->id);
index 9293e41..bfe0767 100644 (file)
@@ -2,14 +2,15 @@
 #define __ASM_MACH_CLKDEV_H
 
 #include <linux/module.h>
-#include <asm/hardware/icst525.h>
+#include <plat/clock.h>
 
 struct clk {
        unsigned long           rate;
+       const struct clk_ops    *ops;
        struct module           *owner;
-       const struct icst525_params *params;
+       const struct icst_params *params;
+       void __iomem            *vcoreg;
        void                    *data;
-       void                    (*setvco)(struct clk *, struct icst525_vco vco);
 };
 
 static inline int __clk_get(struct clk *clk)
index 7649c57..3d029c9 100644 (file)
@@ -8,6 +8,7 @@
  * warranty of any kind, whether express or implied.
  */
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <mach/irqs.h>
 
                .macro  disable_fiq
index d795642..8e26360 100644 (file)
@@ -23,7 +23,6 @@
 #define __ASM_ARCH_HARDWARE_H
 
 #include <asm/sizes.h>
-#include <mach/platform.h>
 
 /*
  * Where in virtual memory the IO devices (timers, system controllers
 #define PCIO_BASE              PCI_IO_VADDR
 #define PCIMEM_BASE            PCI_MEMORY_VADDR
 
-#ifdef CONFIG_MMU
-/* macro to get at IO space when running virtually */
-#define IO_ADDRESS(x) (((x) >> 4) + IO_BASE) 
-#else
-#define IO_ADDRESS(x) (x)
-#endif
-
 #define pcibios_assign_all_busses()    1
 
 #define PCIBIOS_MIN_IO         0x6000
 #define PCIBIOS_MIN_MEM        0x00100000
 
+/* macro to get at IO space when running virtually */
+#ifdef CONFIG_MMU
+#define IO_ADDRESS(x)  (((x) & 0x000fffff) | (((x) >> 4) & 0x0ff00000) | IO_BASE)
+#else
+#define IO_ADDRESS(x)  (x)
+#endif
+
+#define __io_address(n)                ((void __iomem *)IO_ADDRESS(n))
+
 #endif
 
index e00a262..5e6ea5c 100644 (file)
@@ -23,9 +23,6 @@
  *
  *   Integrator address map
  *
- *     NOTE: This is a multi-hosted header file for use with uHAL and
- *           supported debuggers.
- *
  * ***********************************************************************/
 
 #ifndef __address_h
 #define INTEGRATOR_DBG_LEDS             (INTEGRATOR_DBG_BASE + INTEGRATOR_DBG_LEDS_OFFSET)
 #define INTEGRATOR_DBG_SWITCH           (INTEGRATOR_DBG_BASE + INTEGRATOR_DBG_SWITCH_OFFSET)
 
+#define INTEGRATOR_AP_GPIO_BASE                0x1B000000      /* GPIO */
 
-#if defined(CONFIG_ARCH_INTEGRATOR_AP)
-#define INTEGRATOR_GPIO_BASE            0x1B000000      /*  GPIO */
-#elif defined(CONFIG_ARCH_INTEGRATOR_CP)
-#define INTEGRATOR_GPIO_BASE            0xC9000000      /*  GPIO */
-#endif
+#define INTEGRATOR_CP_MMC_BASE         0x1C000000      /* MMC */
+#define INTEGRATOR_CP_AACI_BASE                0x1D000000      /* AACI */
+#define INTEGRATOR_CP_ETH_BASE         0xC8000000      /* Ethernet */
+#define INTEGRATOR_CP_GPIO_BASE                0xC9000000      /* GPIO */
+#define INTEGRATOR_CP_SIC_BASE         0xCA000000      /* SIC */
+#define INTEGRATOR_CP_CTL_BASE         0xCB000000      /* CP system control */
 
 /* ------------------------------------------------------------------------
  *  KMI keyboard/mouse definitions
  */
 #define PHYS_PCI_V3_BASE                0x62000000
 
-#define PCI_DRAMSIZE                    INTEGRATOR_SSRAM_SIZE
-
-/* 'export' these to UHAL */
-#define UHAL_PCI_IO                     PCI_IO_BASE
-#define UHAL_PCI_MEM                    PCI_MEM_BASE
-#define UHAL_PCI_ALLOC_IO_BASE          0x00004000
-#define UHAL_PCI_ALLOC_MEM_BASE         PCI_MEM_BASE
-#define UHAL_PCI_MAX_SLOT               20
-
-/* ========================================================================
- *  Start of uHAL definitions
- * ========================================================================
- */
-
 /* ------------------------------------------------------------------------
  *  Integrator Interrupt Controllers
  * ------------------------------------------------------------------------
  */
 
 /* ------------------------------------------------------------------------
- *  LED's - The header LED is not accessible via the uHAL API
+ *  LED's
  * ------------------------------------------------------------------------
  *
  */
 
 #define LED_BANK                        INTEGRATOR_DBG_LEDS
 
-/*
- *  Memory definitions - run uHAL out of SSRAM.
- *
- */
-#define uHAL_MEMORY_SIZE                INTEGRATOR_SSRAM_SIZE
-
-/*
- *  Clean base - dummy
- *
- */
-#define CLEAN_BASE                      INTEGRATOR_BOOT_ROM_HI
-
 /*
  *  Timer definitions
  *
  *  Only use timer 1 & 2
  *  (both run at 24MHz and will need the clock divider set to 16).
  *
- *  Timer 0 runs at bus frequency and therefore could vary and currently
- *  uHAL can't handle that.
- *
+ *  Timer 0 runs at bus frequency
  */
 
 #define INTEGRATOR_TIMER0_BASE          INTEGRATOR_CT_BASE
 #define INTEGRATOR_TIMER1_BASE          (INTEGRATOR_CT_BASE + 0x100)
 #define INTEGRATOR_TIMER2_BASE          (INTEGRATOR_CT_BASE + 0x200)
 
-#define MAX_TIMER                       2
-#define MAX_PERIOD                      699050
 #define TICKS_PER_uSEC                  24
 
 /*
  *
  */
 #define mSEC_1                          1000
-#define mSEC_5                          (mSEC_1 * 5)
 #define mSEC_10                         (mSEC_1 * 10)
-#define mSEC_25                         (mSEC_1 * 25)
-#define SEC_1                           (mSEC_1 * 1000)
 
 #define INTEGRATOR_CSR_BASE             0x10000000
 #define INTEGRATOR_CSR_SIZE             0x10000000
 
 #endif
-
-/*     END */
index 8138a7e..227cf4d 100644 (file)
 #include <linux/sysdev.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/kmi.h>
+#include <linux/clocksource.h>
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
+#include <mach/platform.h>
+#include <asm/hardware/arm_timer.h>
 #include <asm/irq.h>
 #include <asm/setup.h>
 #include <asm/param.h>         /* HZ */
@@ -43,8 +48,6 @@
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 
-#include "common.h"
-
 /* 
  * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  * is the (PA >> 12).
@@ -55,7 +58,7 @@
 #define VA_IC_BASE     IO_ADDRESS(INTEGRATOR_IC_BASE) 
 #define VA_SC_BASE     IO_ADDRESS(INTEGRATOR_SC_BASE)
 #define VA_EBI_BASE    IO_ADDRESS(INTEGRATOR_EBI_BASE)
-#define VA_CMIC_BASE   IO_ADDRESS(INTEGRATOR_HDR_BASE) + INTEGRATOR_HDR_IC_OFFSET
+#define VA_CMIC_BASE   IO_ADDRESS(INTEGRATOR_HDR_IC)
 
 /*
  * Logical      Physical
@@ -117,8 +120,8 @@ static struct map_desc ap_io_desc[] __initdata = {
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }, {
-               .virtual        = IO_ADDRESS(INTEGRATOR_GPIO_BASE),
-               .pfn            = __phys_to_pfn(INTEGRATOR_GPIO_BASE),
+               .virtual        = IO_ADDRESS(INTEGRATOR_AP_GPIO_BASE),
+               .pfn            = __phys_to_pfn(INTEGRATOR_AP_GPIO_BASE),
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }, {
@@ -334,14 +337,163 @@ static void __init ap_init(void)
        }
 }
 
+/*
+ * Where is the timer (VA)?
+ */
+#define TIMER0_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER0_BASE)
+#define TIMER1_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER1_BASE)
+#define TIMER2_VA_BASE IO_ADDRESS(INTEGRATOR_TIMER2_BASE)
+
+/*
+ * How long is the timer interval?
+ */
+#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
+#if TIMER_INTERVAL >= 0x100000
+#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
+#elif TIMER_INTERVAL >= 0x10000
+#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
+#else
+#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
+#endif
+
+static unsigned long timer_reload;
+
+static void __iomem * const clksrc_base = (void __iomem *)TIMER2_VA_BASE;
+
+static cycle_t timersp_read(struct clocksource *cs)
+{
+       return ~(readl(clksrc_base + TIMER_VALUE) & 0xffff);
+}
+
+static struct clocksource clocksource_timersp = {
+       .name           = "timer2",
+       .rating         = 200,
+       .read           = timersp_read,
+       .mask           = CLOCKSOURCE_MASK(16),
+       .shift          = 16,
+       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static void integrator_clocksource_init(u32 khz)
+{
+       struct clocksource *cs = &clocksource_timersp;
+       void __iomem *base = clksrc_base;
+       u32 ctrl = TIMER_CTRL_ENABLE;
+
+       if (khz >= 1500) {
+               khz /= 16;
+               ctrl = TIMER_CTRL_DIV16;
+       }
+
+       writel(ctrl, base + TIMER_CTRL);
+       writel(0xffff, base + TIMER_LOAD);
+
+       cs->mult = clocksource_khz2mult(khz, cs->shift);
+       clocksource_register(cs);
+}
+
+static void __iomem * const clkevt_base = (void __iomem *)TIMER1_VA_BASE;
+
+/*
+ * IRQ handler for the timer
+ */
+static irqreturn_t integrator_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = dev_id;
+
+       /* clear the interrupt */
+       writel(1, clkevt_base + TIMER_INTCLR);
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static void clkevt_set_mode(enum clock_event_mode mode, struct clock_event_device *evt)
+{
+       u32 ctrl = readl(clkevt_base + TIMER_CTRL) & ~TIMER_CTRL_ENABLE;
+
+       BUG_ON(mode == CLOCK_EVT_MODE_ONESHOT);
+
+       if (mode == CLOCK_EVT_MODE_PERIODIC) {
+               writel(ctrl, clkevt_base + TIMER_CTRL);
+               writel(timer_reload, clkevt_base + TIMER_LOAD);
+               ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
+       }
+
+       writel(ctrl, clkevt_base + TIMER_CTRL);
+}
+
+static int clkevt_set_next_event(unsigned long next, struct clock_event_device *evt)
+{
+       unsigned long ctrl = readl(clkevt_base + TIMER_CTRL);
+
+       writel(ctrl & ~TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
+       writel(next, clkevt_base + TIMER_LOAD);
+       writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
+
+       return 0;
+}
+
+static struct clock_event_device integrator_clockevent = {
+       .name           = "timer1",
+       .shift          = 34,
+       .features       = CLOCK_EVT_FEAT_PERIODIC,
+       .set_mode       = clkevt_set_mode,
+       .set_next_event = clkevt_set_next_event,
+       .rating         = 300,
+       .cpumask        = cpu_all_mask,
+};
+
+static struct irqaction integrator_timer_irq = {
+       .name           = "timer",
+       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+       .handler        = integrator_timer_interrupt,
+       .dev_id         = &integrator_clockevent,
+};
+
+static void integrator_clockevent_init(u32 khz)
+{
+       struct clock_event_device *evt = &integrator_clockevent;
+       unsigned int ctrl = 0;
+
+       if (khz * 1000 > 0x100000 * HZ) {
+               khz /= 256;
+               ctrl |= TIMER_CTRL_DIV256;
+       } else if (khz * 1000 > 0x10000 * HZ) {
+               khz /= 16;
+               ctrl |= TIMER_CTRL_DIV16;
+       }
+
+       timer_reload = khz * 1000 / HZ;
+       writel(ctrl, clkevt_base + TIMER_CTRL);
+
+       evt->irq = IRQ_TIMERINT1;
+       evt->mult = div_sc(khz, NSEC_PER_MSEC, evt->shift);
+       evt->max_delta_ns = clockevent_delta2ns(0xffff, evt);
+       evt->min_delta_ns = clockevent_delta2ns(0xf, evt);
+
+       setup_irq(IRQ_TIMERINT1, &integrator_timer_irq);
+       clockevents_register_device(evt);
+}
+
+/*
+ * Set up timer(s).
+ */
 static void __init ap_init_timer(void)
 {
-       integrator_time_init(1000000 * TICKS_PER_uSEC / HZ, 0);
+       u32 khz = TICKS_PER_uSEC * 1000;
+
+       writel(0, TIMER0_VA_BASE + TIMER_CTRL);
+       writel(0, TIMER1_VA_BASE + TIMER_CTRL);
+       writel(0, TIMER2_VA_BASE + TIMER_CTRL);
+
+       integrator_clocksource_init(khz);
+       integrator_clockevent_init(khz);
 }
 
 static struct sys_timer ap_timer = {
        .init           = ap_init_timer,
-       .offset         = integrator_gettimeoffset,
 };
 
 MACHINE_START(INTEGRATOR, "ARM-Integrator")
index 15e6cc5..cde57b2 100644 (file)
 #include <asm/clkdev.h>
 #include <mach/clkdev.h>
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/irq.h>
 #include <asm/setup.h>
 #include <asm/mach-types.h>
-#include <asm/hardware/icst525.h>
+#include <asm/hardware/arm_timer.h>
+#include <asm/hardware/icst.h>
 
 #include <mach/cm.h>
 #include <mach/lm.h>
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 
-#include "common.h"
-
-#define INTCP_PA_MMC_BASE              0x1c000000
-#define INTCP_PA_AACI_BASE             0x1d000000
+#include <plat/timer-sp.h>
 
 #define INTCP_PA_FLASH_BASE            0x24000000
 #define INTCP_FLASH_SIZE               SZ_32M
 
 #define INTCP_PA_CLCD_BASE             0xc0000000
 
-#define INTCP_VA_CIC_BASE              IO_ADDRESS(INTEGRATOR_HDR_BASE) + 0x40
+#define INTCP_VA_CIC_BASE              IO_ADDRESS(INTEGRATOR_HDR_BASE + 0x40)
 #define INTCP_VA_PIC_BASE              IO_ADDRESS(INTEGRATOR_IC_BASE)
-#define INTCP_VA_SIC_BASE              IO_ADDRESS(0xca000000)
+#define INTCP_VA_SIC_BASE              IO_ADDRESS(INTEGRATOR_CP_SIC_BASE)
 
-#define INTCP_PA_ETH_BASE              0xc8000000
 #define INTCP_ETH_SIZE                 0x10
 
-#define INTCP_VA_CTRL_BASE             IO_ADDRESS(0xcb000000)
+#define INTCP_VA_CTRL_BASE             IO_ADDRESS(INTEGRATOR_CP_CTL_BASE)
 #define INTCP_FLASHPROG                        0x04
 #define CINTEGRATOR_FLASHPROG_FLVPPEN  (1 << 0)
 #define CINTEGRATOR_FLASHPROG_FLWREN   (1 << 1)
@@ -71,7 +69,9 @@
  * f1600000    16000000        UART 0
  * f1700000    17000000        UART 1
  * f1a00000    1a000000        Debug LEDs
- * f1b00000    1b000000        GPIO
+ * fc900000    c9000000        GPIO
+ * fca00000    ca000000        SIC
+ * fcb00000    cb000000        CP system control
  */
 
 static struct map_desc intcp_io_desc[] __initdata = {
@@ -116,18 +116,18 @@ static struct map_desc intcp_io_desc[] __initdata = {
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }, {
-               .virtual        = IO_ADDRESS(INTEGRATOR_GPIO_BASE),
-               .pfn            = __phys_to_pfn(INTEGRATOR_GPIO_BASE),
+               .virtual        = IO_ADDRESS(INTEGRATOR_CP_GPIO_BASE),
+               .pfn            = __phys_to_pfn(INTEGRATOR_CP_GPIO_BASE),
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }, {
-               .virtual        = IO_ADDRESS(0xca000000),
-               .pfn            = __phys_to_pfn(0xca000000),
+               .virtual        = IO_ADDRESS(INTEGRATOR_CP_SIC_BASE),
+               .pfn            = __phys_to_pfn(INTEGRATOR_CP_SIC_BASE),
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }, {
-               .virtual        = IO_ADDRESS(0xcb000000),
-               .pfn            = __phys_to_pfn(0xcb000000),
+               .virtual        = IO_ADDRESS(INTEGRATOR_CP_CTL_BASE),
+               .pfn            = __phys_to_pfn(INTEGRATOR_CP_CTL_BASE),
                .length         = SZ_4K,
                .type           = MT_DEVICE
        }
@@ -266,33 +266,43 @@ static void __init intcp_init_irq(void)
 /*
  * Clock handling
  */
-#define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
-#define CM_AUXOSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+0x1c)
+#define CM_LOCK                (__io_address(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET)
+#define CM_AUXOSC      (__io_address(INTEGRATOR_HDR_BASE)+0x1c)
 
-static const struct icst525_params cp_auxvco_params = {
-       .ref            = 24000,
-       .vco_max        = 320000,
+static const struct icst_params cp_auxvco_params = {
+       .ref            = 24000000,
+       .vco_max        = ICST525_VCO_MAX_5V,
+       .vco_min        = ICST525_VCO_MIN,
        .vd_min         = 8,
        .vd_max         = 263,
        .rd_min         = 3,
        .rd_max         = 65,
+       .s2div          = icst525_s2div,
+       .idx2s          = icst525_idx2s,
 };
 
-static void cp_auxvco_set(struct clk *clk, struct icst525_vco vco)
+static void cp_auxvco_set(struct clk *clk, struct icst_vco vco)
 {
        u32 val;
 
-       val = readl(CM_AUXOSC) & ~0x7ffff;
+       val = readl(clk->vcoreg) & ~0x7ffff;
        val |= vco.v | (vco.r << 9) | (vco.s << 16);
 
        writel(0xa05f, CM_LOCK);
-       writel(val, CM_AUXOSC);
+       writel(val, clk->vcoreg);
        writel(0, CM_LOCK);
 }
 
+static const struct clk_ops cp_auxclk_ops = {
+       .round  = icst_clk_round,
+       .set    = icst_clk_set,
+       .setvco = cp_auxvco_set,
+};
+
 static struct clk cp_auxclk = {
+       .ops    = &cp_auxclk_ops,
        .params = &cp_auxvco_params,
-       .setvco = cp_auxvco_set,
+       .vcoreg = CM_AUXOSC,
 };
 
 static struct clk_lookup cp_lookups[] = {
@@ -363,8 +373,8 @@ static struct platform_device intcp_flash_device = {
 
 static struct resource smc91x_resources[] = {
        [0] = {
-               .start  = INTCP_PA_ETH_BASE,
-               .end    = INTCP_PA_ETH_BASE + INTCP_ETH_SIZE - 1,
+               .start  = INTEGRATOR_CP_ETH_BASE,
+               .end    = INTEGRATOR_CP_ETH_BASE + INTCP_ETH_SIZE - 1,
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
@@ -394,8 +404,8 @@ static struct platform_device *intcp_devs[] __initdata = {
  */
 static unsigned int mmc_status(struct device *dev)
 {
-       unsigned int status = readl(IO_ADDRESS(0xca000000) + 4);
-       writel(8, IO_ADDRESS(0xcb000000) + 8);
+       unsigned int status = readl(IO_ADDRESS(0xca000000 + 4));
+       writel(8, IO_ADDRESS(INTEGRATOR_CP_CTL_BASE + 8));
 
        return status & 8;
 }
@@ -413,8 +423,8 @@ static struct amba_device mmc_device = {
                .platform_data = &mmc_data,
        },
        .res            = {
-               .start  = INTCP_PA_MMC_BASE,
-               .end    = INTCP_PA_MMC_BASE + SZ_4K - 1,
+               .start  = INTEGRATOR_CP_MMC_BASE,
+               .end    = INTEGRATOR_CP_MMC_BASE + SZ_4K - 1,
                .flags  = IORESOURCE_MEM,
        },
        .irq            = { IRQ_CP_MMCIINT0, IRQ_CP_MMCIINT1 },
@@ -426,8 +436,8 @@ static struct amba_device aaci_device = {
                .init_name = "mb:1d",
        },
        .res            = {
-               .start  = INTCP_PA_AACI_BASE,
-               .end    = INTCP_PA_AACI_BASE + SZ_4K - 1,
+               .start  = INTEGRATOR_CP_AACI_BASE,
+               .end    = INTEGRATOR_CP_AACI_BASE + SZ_4K - 1,
                .flags  = IORESOURCE_MEM,
        },
        .irq            = { IRQ_CP_AACIINT, NO_IRQ },
@@ -567,16 +577,22 @@ static void __init intcp_init(void)
        }
 }
 
-#define TIMER_CTRL_IE  (1 << 5)                        /* Interrupt Enable */
+#define TIMER0_VA_BASE __io_address(INTEGRATOR_TIMER0_BASE)
+#define TIMER1_VA_BASE __io_address(INTEGRATOR_TIMER1_BASE)
+#define TIMER2_VA_BASE __io_address(INTEGRATOR_TIMER2_BASE)
 
 static void __init intcp_timer_init(void)
 {
-       integrator_time_init(1000000 / HZ, TIMER_CTRL_IE);
+       writel(0, TIMER0_VA_BASE + TIMER_CTRL);
+       writel(0, TIMER1_VA_BASE + TIMER_CTRL);
+       writel(0, TIMER2_VA_BASE + TIMER_CTRL);
+
+       sp804_clocksource_init(TIMER2_VA_BASE);
+       sp804_clockevents_init(TIMER1_VA_BASE, IRQ_TIMERINT1);
 }
 
 static struct sys_timer cp_timer = {
        .init           = intcp_timer_init,
-       .offset         = integrator_gettimeoffset,
 };
 
 MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
index 8dcc823..28be186 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/io.h>
 
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/leds.h>
 #include <asm/system.h>
 #include <asm/mach-types.h>
index ffbd349..9cef059 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/io.h>
 
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/irq.h>
 #include <asm/signal.h>
 #include <asm/system.h>
@@ -389,9 +390,9 @@ static int __init pci_v3_setup_resources(struct resource **resource)
  * means I can't get additional information on the reason for the pm2fb
  * problems.  I suppose I'll just have to mind-meld with the machine. ;)
  */
-#define SC_PCI     (IO_ADDRESS(INTEGRATOR_SC_BASE) + INTEGRATOR_SC_PCIENABLE_OFFSET)
-#define SC_LBFADDR (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x20)
-#define SC_LBFCODE (IO_ADDRESS(INTEGRATOR_SC_BASE) + 0x24)
+#define SC_PCI     IO_ADDRESS(INTEGRATOR_SC_PCIENABLE)
+#define SC_LBFADDR IO_ADDRESS(INTEGRATOR_SC_BASE + 0x20)
+#define SC_LBFCODE IO_ADDRESS(INTEGRATOR_SC_BASE + 0x24)
 
 static int
 v3_pci_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
index 5d99039..f108a31 100644 (file)
@@ -176,7 +176,7 @@ static struct plat_serial8250_port n2100_serial_port[] = {
                .mapbase        = N2100_UART,
                .membase        = (char *)N2100_UART,
                .irq            = 0,
-               .flags          = UPF_SKIP_TEST,
+               .flags          = UPF_SKIP_TEST | UPF_AUTO_IRQ | UPF_SHARE_IRQ,
                .iotype         = UPIO_MEM,
                .regshift       = 0,
                .uartclk        = 1843200,
index 71728d3..0bce097 100644 (file)
@@ -21,7 +21,6 @@
 #include <linux/tty.h>
 #include <linux/platform_device.h>
 #include <linux/serial_core.h>
-#include <linux/bootmem.h>
 #include <linux/interrupt.h>
 #include <linux/bitops.h>
 #include <linux/time.h>
index 17879a8..29b2163 100644 (file)
@@ -38,6 +38,12 @@ config MACH_ESATA_SHEEVAPLUG
          Say 'Y' here if you want your kernel to support the
          Marvell eSATA SheevaPlug Reference Board.
 
+config MACH_GURUPLUG
+       bool "Marvell GuruPlug Reference Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell GuruPlug Reference Board.
+
 config MACH_TS219
        bool "QNAP TS-110, TS-119, TS-210, TS-219 and TS-219P Turbo NAS"
        help
@@ -81,6 +87,18 @@ config MACH_INETSPACE_V2
          Say 'Y' here if you want your kernel to support the
          LaCie Internet Space v2 NAS.
 
+config MACH_NET2BIG_V2
+       bool "LaCie 2Big Network v2 NAS Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         LaCie 2Big Network v2 NAS.
+
+config MACH_NET5BIG_V2
+       bool "LaCie 5Big Network v2 NAS Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         LaCie 5Big Network v2 NAS.
+
 endmenu
 
 endif
index a5530e3..c0cd5d3 100644 (file)
@@ -6,10 +6,13 @@ obj-$(CONFIG_MACH_RD88F6281)          += rd88f6281-setup.o
 obj-$(CONFIG_MACH_MV88F6281GTW_GE)     += mv88f6281gtw_ge-setup.o
 obj-$(CONFIG_MACH_SHEEVAPLUG)          += sheevaplug-setup.o
 obj-$(CONFIG_MACH_ESATA_SHEEVAPLUG)    += sheevaplug-setup.o
+obj-$(CONFIG_MACH_GURUPLUG)            += guruplug-setup.o
 obj-$(CONFIG_MACH_TS219)               += ts219-setup.o tsx1x-common.o
 obj-$(CONFIG_MACH_TS41X)               += ts41x-setup.o tsx1x-common.o
 obj-$(CONFIG_MACH_OPENRD)              += openrd-setup.o
 obj-$(CONFIG_MACH_NETSPACE_V2)         += netspace_v2-setup.o
 obj-$(CONFIG_MACH_INETSPACE_V2)                += netspace_v2-setup.o
+obj-$(CONFIG_MACH_NET2BIG_V2)          += netxbig_v2-setup.o
+obj-$(CONFIG_MACH_NET5BIG_V2)          += netxbig_v2-setup.o
 
 obj-$(CONFIG_CPU_IDLE)                 += cpuidle.o
diff --git a/arch/arm/mach-kirkwood/guruplug-setup.c b/arch/arm/mach-kirkwood/guruplug-setup.c
new file mode 100644 (file)
index 0000000..54d07c8
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * arch/arm/mach-kirkwood/guruplug-setup.c
+ *
+ * Marvell GuruPlug Reference Board Setup
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/partitions.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <mach/kirkwood.h>
+#include <plat/mvsdio.h>
+#include "common.h"
+#include "mpp.h"
+
+static struct mtd_partition guruplug_nand_parts[] = {
+       {
+               .name = "u-boot",
+               .offset = 0,
+               .size = SZ_1M
+       }, {
+               .name = "uImage",
+               .offset = MTDPART_OFS_NXTBLK,
+               .size = SZ_4M
+       }, {
+               .name = "root",
+               .offset = MTDPART_OFS_NXTBLK,
+               .size = MTDPART_SIZ_FULL
+       },
+};
+
+static struct mv643xx_eth_platform_data guruplug_ge00_data = {
+       .phy_addr       = MV643XX_ETH_PHY_ADDR(0),
+};
+
+static struct mv643xx_eth_platform_data guruplug_ge01_data = {
+       .phy_addr       = MV643XX_ETH_PHY_ADDR(1),
+};
+
+static struct mv_sata_platform_data guruplug_sata_data = {
+       .n_ports        = 1,
+};
+
+static struct mvsdio_platform_data guruplug_mvsdio_data = {
+       /* unfortunately the CD signal has not been connected */
+};
+
+static struct gpio_led guruplug_led_pins[] = {
+       {
+               .name                   = "guruplug:red:health",
+               .gpio                   = 46,
+               .active_low             = 1,
+       },
+       {
+               .name                   = "guruplug:green:health",
+               .gpio                   = 47,
+               .active_low             = 1,
+       },
+       {
+               .name                   = "guruplug:red:wmode",
+               .gpio                   = 48,
+               .active_low             = 1,
+       },
+       {
+               .name                   = "guruplug:green:wmode",
+               .gpio                   = 49,
+               .active_low             = 1,
+       },
+};
+
+static struct gpio_led_platform_data guruplug_led_data = {
+       .leds           = guruplug_led_pins,
+       .num_leds       = ARRAY_SIZE(guruplug_led_pins),
+};
+
+static struct platform_device guruplug_leds = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &guruplug_led_data,
+       }
+};
+
+static unsigned int guruplug_mpp_config[] __initdata = {
+       MPP46_GPIO,     /* M_RLED */
+       MPP47_GPIO,     /* M_GLED */
+       MPP48_GPIO,     /* B_RLED */
+       MPP49_GPIO,     /* B_GLED */
+       0
+};
+
+static void __init guruplug_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+       kirkwood_mpp_conf(guruplug_mpp_config);
+
+       kirkwood_uart0_init();
+       kirkwood_nand_init(ARRAY_AND_SIZE(guruplug_nand_parts), 25);
+
+       kirkwood_ehci_init();
+       kirkwood_ge00_init(&guruplug_ge00_data);
+       kirkwood_ge01_init(&guruplug_ge01_data);
+       kirkwood_sata_init(&guruplug_sata_data);
+       kirkwood_sdio_init(&guruplug_mvsdio_data);
+
+       platform_device_register(&guruplug_leds);
+}
+
+MACHINE_START(GURUPLUG, "Marvell GuruPlug Reference Board")
+       /* Maintainer: Siddarth Gore <gores@marvell.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = guruplug_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
diff --git a/arch/arm/mach-kirkwood/netxbig_v2-setup.c b/arch/arm/mach-kirkwood/netxbig_v2-setup.c
new file mode 100644 (file)
index 0000000..8a2bb02
--- /dev/null
@@ -0,0 +1,415 @@
+/*
+ * arch/arm/mach-kirkwood/netxbig_v2-setup.c
+ *
+ * LaCie 2Big and 5Big Network v2 board setup
+ *
+ * Copyright (C) 2010 Simon Guinot <sguinot@lacie.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 <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/spi/flash.h>
+#include <linux/spi/spi.h>
+#include <linux/ata_platform.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/i2c.h>
+#include <linux/i2c/at24.h>
+#include <linux/input.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/leds.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <mach/kirkwood.h>
+#include <plat/time.h>
+#include "common.h"
+#include "mpp.h"
+
+/*****************************************************************************
+ * 512KB SPI Flash on Boot Device (MACRONIX MX25L4005)
+ ****************************************************************************/
+
+static struct mtd_partition netxbig_v2_flash_parts[] = {
+       {
+               .name = "u-boot",
+               .size = MTDPART_SIZ_FULL,
+               .offset = 0,
+               .mask_flags = MTD_WRITEABLE, /* force read-only */
+       },
+};
+
+static const struct flash_platform_data netxbig_v2_flash = {
+       .type           = "mx25l4005a",
+       .name           = "spi_flash",
+       .parts          = netxbig_v2_flash_parts,
+       .nr_parts       = ARRAY_SIZE(netxbig_v2_flash_parts),
+};
+
+static struct spi_board_info __initdata netxbig_v2_spi_slave_info[] = {
+       {
+               .modalias       = "m25p80",
+               .platform_data  = &netxbig_v2_flash,
+               .irq            = -1,
+               .max_speed_hz   = 20000000,
+               .bus_num        = 0,
+               .chip_select    = 0,
+       },
+};
+
+/*****************************************************************************
+ * Ethernet
+ ****************************************************************************/
+
+static struct mv643xx_eth_platform_data netxbig_v2_ge00_data = {
+       .phy_addr       = MV643XX_ETH_PHY_ADDR(8),
+};
+
+static struct mv643xx_eth_platform_data netxbig_v2_ge01_data = {
+       .phy_addr       = MV643XX_ETH_PHY_ADDR(0),
+};
+
+/*****************************************************************************
+ * I2C devices
+ ****************************************************************************/
+
+static struct at24_platform_data at24c04 = {
+       .byte_len       = SZ_4K / 8,
+       .page_size      = 16,
+};
+
+/*
+ * i2c addr | chip         | description
+ * 0x50     | HT24LC04     | eeprom (512B)
+ */
+
+static struct i2c_board_info __initdata netxbig_v2_i2c_info[] = {
+       {
+               I2C_BOARD_INFO("24c04", 0x50),
+               .platform_data  = &at24c04,
+       }
+};
+
+/*****************************************************************************
+ * SATA
+ ****************************************************************************/
+
+static struct mv_sata_platform_data netxbig_v2_sata_data = {
+       .n_ports        = 2,
+};
+
+static int __initdata netxbig_v2_gpio_hdd_power[] = { 16, 17, 41, 42, 43 };
+
+static void __init netxbig_v2_sata_power_init(void)
+{
+       int i;
+       int err;
+       int hdd_nb;
+
+       if (machine_is_net2big_v2())
+               hdd_nb = 2;
+       else
+               hdd_nb = 5;
+
+       /* Power up all hard disks. */
+       for (i = 0; i < hdd_nb; i++) {
+               err = gpio_request(netxbig_v2_gpio_hdd_power[i], NULL);
+               if (err == 0) {
+                       err = gpio_direction_output(
+                                       netxbig_v2_gpio_hdd_power[i], 1);
+                       /* Free the HDD power GPIOs. This allow user-space to
+                        * configure them via the gpiolib sysfs interface. */
+                       gpio_free(netxbig_v2_gpio_hdd_power[i]);
+               }
+               if (err)
+                       pr_err("netxbig_v2: failed to power up HDD%d\n", i + 1);
+       }
+}
+
+/*****************************************************************************
+ * GPIO keys
+ ****************************************************************************/
+
+#define NETXBIG_V2_GPIO_SWITCH_POWER_ON                13
+#define NETXBIG_V2_GPIO_SWITCH_POWER_OFF       15
+#define NETXBIG_V2_GPIO_FUNC_BUTTON            34
+
+#define NETXBIG_V2_SWITCH_POWER_ON             0x1
+#define NETXBIG_V2_SWITCH_POWER_OFF            0x2
+
+static struct gpio_keys_button netxbig_v2_buttons[] = {
+       [0] = {
+               .type           = EV_SW,
+               .code           = NETXBIG_V2_SWITCH_POWER_ON,
+               .gpio           = NETXBIG_V2_GPIO_SWITCH_POWER_ON,
+               .desc           = "Back power switch (on|auto)",
+               .active_low     = 1,
+       },
+       [1] = {
+               .type           = EV_SW,
+               .code           = NETXBIG_V2_SWITCH_POWER_OFF,
+               .gpio           = NETXBIG_V2_GPIO_SWITCH_POWER_OFF,
+               .desc           = "Back power switch (auto|off)",
+               .active_low     = 1,
+       },
+       [2] = {
+               .code           = KEY_OPTION,
+               .gpio           = NETXBIG_V2_GPIO_FUNC_BUTTON,
+               .desc           = "Function button",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data netxbig_v2_button_data = {
+       .buttons        = netxbig_v2_buttons,
+       .nbuttons       = ARRAY_SIZE(netxbig_v2_buttons),
+};
+
+static struct platform_device netxbig_v2_gpio_buttons = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &netxbig_v2_button_data,
+       },
+};
+
+/*****************************************************************************
+ * GPIO LEDs
+ ****************************************************************************/
+
+/*
+ * The LEDs are controlled by a CPLD and can be configured through a GPIO
+ * extension bus:
+ *
+ * - address register : bit [0-2] -> GPIO [47-49]
+ * - data register    : bit [0-2] -> GPIO [44-46]
+ * - enable register  : GPIO 29
+ *
+ * Address register selection:
+ *
+ * addr | register
+ * ----------------------------
+ *   0  | front LED
+ *   1  | front LED brightness
+ *   2  | HDD LED brightness
+ *   3  | HDD1 LED
+ *   4  | HDD2 LED
+ *   5  | HDD3 LED
+ *   6  | HDD4 LED
+ *   7  | HDD5 LED
+ *
+ * Data register configuration:
+ *
+ * data | LED brightness
+ * -------------------------------------------------
+ *   0  | min (off)
+ *   -  | -
+ *   7  | max
+ *
+ * data | front LED mode
+ * -------------------------------------------------
+ *   0  | fix off
+ *   1  | fix blue on
+ *   2  | fix red on
+ *   3  | blink blue on=1 sec and blue off=1 sec
+ *   4  | blink red on=1 sec and red off=1 sec
+ *   5  | blink blue on=2.5 sec and red on=0.5 sec
+ *   6  | blink blue on=1 sec and red on=1 sec
+ *   7  | blink blue on=0.5 sec and blue off=2.5 sec
+ *
+ * data | HDD LED mode
+ * -------------------------------------------------
+ *   0  | fix blue on
+ *   1  | SATA activity blink
+ *   2  | fix red on
+ *   3  | blink blue on=1 sec and blue off=1 sec
+ *   4  | blink red on=1 sec and red off=1 sec
+ *   5  | blink blue on=2.5 sec and red on=0.5 sec
+ *   6  | blink blue on=1 sec and red on=1 sec
+ *   7  | blink blue on=0.5 sec and blue off=2.5 sec
+ */
+
+/*****************************************************************************
+ * Timer
+ ****************************************************************************/
+
+static void netxbig_v2_timer_init(void)
+{
+       kirkwood_tclk = 166666667;
+       orion_time_init(IRQ_KIRKWOOD_BRIDGE, kirkwood_tclk);
+}
+
+struct sys_timer netxbig_v2_timer = {
+       .init = netxbig_v2_timer_init,
+};
+
+/*****************************************************************************
+ * General Setup
+ ****************************************************************************/
+
+static unsigned int net2big_v2_mpp_config[] __initdata = {
+       MPP0_SPI_SCn,
+       MPP1_SPI_MOSI,
+       MPP2_SPI_SCK,
+       MPP3_SPI_MISO,
+       MPP6_SYSRST_OUTn,
+       MPP7_GPO,               /* Request power-off */
+       MPP8_TW_SDA,
+       MPP9_TW_SCK,
+       MPP10_UART0_TXD,
+       MPP11_UART0_RXD,
+       MPP13_GPIO,             /* Rear power switch (on|auto) */
+       MPP14_GPIO,             /* USB fuse alarm */
+       MPP15_GPIO,             /* Rear power switch (auto|off) */
+       MPP16_GPIO,             /* SATA HDD1 power */
+       MPP17_GPIO,             /* SATA HDD2 power */
+       MPP20_SATA1_ACTn,
+       MPP21_SATA0_ACTn,
+       MPP24_GPIO,             /* USB mode select */
+       MPP26_GPIO,             /* USB device vbus */
+       MPP28_GPIO,             /* USB enable host vbus */
+       MPP29_GPIO,             /* CPLD extension ALE */
+       MPP34_GPIO,             /* Rear Push button */
+       MPP35_GPIO,             /* Inhibit switch power-off */
+       MPP36_GPIO,             /* SATA HDD1 presence */
+       MPP37_GPIO,             /* SATA HDD2 presence */
+       MPP40_GPIO,             /* eSATA presence */
+       MPP44_GPIO,             /* CPLD extension (data 0) */
+       MPP45_GPIO,             /* CPLD extension (data 1) */
+       MPP46_GPIO,             /* CPLD extension (data 2) */
+       MPP47_GPIO,             /* CPLD extension (addr 0) */
+       MPP48_GPIO,             /* CPLD extension (addr 1) */
+       MPP49_GPIO,             /* CPLD extension (addr 2) */
+       0
+};
+
+static unsigned int net5big_v2_mpp_config[] __initdata = {
+       MPP0_SPI_SCn,
+       MPP1_SPI_MOSI,
+       MPP2_SPI_SCK,
+       MPP3_SPI_MISO,
+       MPP6_SYSRST_OUTn,
+       MPP7_GPO,               /* Request power-off */
+       MPP8_TW_SDA,
+       MPP9_TW_SCK,
+       MPP10_UART0_TXD,
+       MPP11_UART0_RXD,
+       MPP13_GPIO,             /* Rear power switch (on|auto) */
+       MPP14_GPIO,             /* USB fuse alarm */
+       MPP15_GPIO,             /* Rear power switch (auto|off) */
+       MPP16_GPIO,             /* SATA HDD1 power */
+       MPP17_GPIO,             /* SATA HDD2 power */
+       MPP20_GE1_0,
+       MPP21_GE1_1,
+       MPP22_GE1_2,
+       MPP23_GE1_3,
+       MPP24_GE1_4,
+       MPP25_GE1_5,
+       MPP26_GE1_6,
+       MPP27_GE1_7,
+       MPP28_GPIO,             /* USB enable host vbus */
+       MPP29_GPIO,             /* CPLD extension ALE */
+       MPP30_GE1_10,
+       MPP31_GE1_11,
+       MPP32_GE1_12,
+       MPP33_GE1_13,
+       MPP34_GPIO,             /* Rear Push button */
+       MPP35_GPIO,             /* Inhibit switch power-off */
+       MPP36_GPIO,             /* SATA HDD1 presence */
+       MPP37_GPIO,             /* SATA HDD2 presence */
+       MPP38_GPIO,             /* SATA HDD3 presence */
+       MPP39_GPIO,             /* SATA HDD4 presence */
+       MPP40_GPIO,             /* SATA HDD5 presence */
+       MPP41_GPIO,             /* SATA HDD3 power */
+       MPP42_GPIO,             /* SATA HDD4 power */
+       MPP43_GPIO,             /* SATA HDD5 power */
+       MPP44_GPIO,             /* CPLD extension (data 0) */
+       MPP45_GPIO,             /* CPLD extension (data 1) */
+       MPP46_GPIO,             /* CPLD extension (data 2) */
+       MPP47_GPIO,             /* CPLD extension (addr 0) */
+       MPP48_GPIO,             /* CPLD extension (addr 1) */
+       MPP49_GPIO,             /* CPLD extension (addr 2) */
+       0
+};
+
+#define NETXBIG_V2_GPIO_POWER_OFF              7
+
+static void netxbig_v2_power_off(void)
+{
+       gpio_set_value(NETXBIG_V2_GPIO_POWER_OFF, 1);
+}
+
+static void __init netxbig_v2_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+       if (machine_is_net2big_v2())
+               kirkwood_mpp_conf(net2big_v2_mpp_config);
+       else
+               kirkwood_mpp_conf(net5big_v2_mpp_config);
+
+       netxbig_v2_sata_power_init();
+
+       kirkwood_ehci_init();
+       kirkwood_ge00_init(&netxbig_v2_ge00_data);
+       if (machine_is_net5big_v2())
+               kirkwood_ge01_init(&netxbig_v2_ge01_data);
+       kirkwood_sata_init(&netxbig_v2_sata_data);
+       kirkwood_uart0_init();
+       spi_register_board_info(netxbig_v2_spi_slave_info,
+                               ARRAY_SIZE(netxbig_v2_spi_slave_info));
+       kirkwood_spi_init();
+       kirkwood_i2c_init();
+       i2c_register_board_info(0, netxbig_v2_i2c_info,
+                               ARRAY_SIZE(netxbig_v2_i2c_info));
+
+       platform_device_register(&netxbig_v2_gpio_buttons);
+
+       if (gpio_request(NETXBIG_V2_GPIO_POWER_OFF, "power-off") == 0 &&
+           gpio_direction_output(NETXBIG_V2_GPIO_POWER_OFF, 0) == 0)
+               pm_power_off = netxbig_v2_power_off;
+       else
+               pr_err("netxbig_v2: failed to configure power-off GPIO\n");
+}
+
+#ifdef CONFIG_MACH_NET2BIG_V2
+MACHINE_START(NET2BIG_V2, "LaCie 2Big Network v2")
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = netxbig_v2_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &netxbig_v2_timer,
+MACHINE_END
+#endif
+
+#ifdef CONFIG_MACH_NET5BIG_V2
+MACHINE_START(NET5BIG_V2, "LaCie 5Big Network v2")
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = netxbig_v2_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &netxbig_v2_timer,
+MACHINE_END
+#endif
index a2d307e..244655d 100644 (file)
@@ -59,6 +59,13 @@ static unsigned long common_pin_config[] __initdata = {
        /* UART1 */
        GPIO107_UART1_RXD,
        GPIO108_UART1_TXD,
+
+       /* SSP1 */
+       GPIO113_I2S_MCLK,
+       GPIO114_I2S_FRM,
+       GPIO115_I2S_BCLK,
+       GPIO116_I2S_RXD,
+       GPIO117_I2S_TXD,
 };
 
 static struct smc91x_platdata smc91x_info = {
@@ -123,12 +130,18 @@ static struct pxa3xx_nand_platform_data aspenite_nand_info = {
        .nr_parts       = ARRAY_SIZE(aspenite_nand_partitions),
 };
 
+static struct i2c_board_info aspenite_i2c_info[] __initdata = {
+       { I2C_BOARD_INFO("wm8753", 0x1b), },
+};
+
 static void __init common_init(void)
 {
        mfp_config(ARRAY_AND_SIZE(common_pin_config));
 
        /* on-chip devices */
        pxa168_add_uart(1);
+       pxa168_add_twsi(1, NULL, ARRAY_AND_SIZE(aspenite_i2c_info));
+       pxa168_add_ssp(1);
        pxa168_add_nand(&aspenite_nand_info);
 
        /* off-chip devices */
index ab26d13..ee8b02e 100644 (file)
@@ -10,7 +10,7 @@
 #define BANK_OFF(n)    (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
 #define GPIO_REG(x)    (*((volatile u32 *)(GPIO_REGS_VIRT + (x))))
 
-#define NR_BUILTIN_GPIO        (128)
+#define NR_BUILTIN_GPIO        (192)
 
 #define gpio_to_bank(gpio)     ((gpio) >> 5)
 #define gpio_to_irq(gpio)      (IRQ_GPIO_START + (gpio))
index 0270119..b379cde 100644 (file)
@@ -5,10 +5,10 @@
  * Interrupt numbers for PXA168
  */
 #define IRQ_PXA168_NONE                        (-1)
-#define IRQ_PXA168_SSP3                        0
-#define IRQ_PXA168_SSP2                        1
-#define IRQ_PXA168_SSP1                        2
-#define IRQ_PXA168_SSP0                        3
+#define IRQ_PXA168_SSP4                        0
+#define IRQ_PXA168_SSP3                        1
+#define IRQ_PXA168_SSP2                        2
+#define IRQ_PXA168_SSP1                        3
 #define IRQ_PXA168_PMIC_INT            4
 #define IRQ_PXA168_RTC_INT             5
 #define IRQ_PXA168_RTC_ALARM           6
@@ -20,7 +20,7 @@
 #define IRQ_PXA168_TIMER2              14
 #define IRQ_PXA168_TIMER3              15
 #define IRQ_PXA168_CMU                 16
-#define IRQ_PXA168_SSP4                        17
+#define IRQ_PXA168_SSP5                        17
 #define IRQ_PXA168_MSP_WAKEUP          19
 #define IRQ_PXA168_CF_WAKEUP           20
 #define IRQ_PXA168_XD_WAKEUP           21
index 9f9f814..761c2da 100644 (file)
@@ -9,6 +9,175 @@
 #define MFP_DRIVE_FAST         (0x8 << 13)
 
 /* GPIO */
+#define GPIO0_GPIO0            MFP_CFG(GPIO0, AF0)
+#define GPIO1_GPIO1            MFP_CFG(GPIO1, AF0)
+#define GPIO2_GPIO2            MFP_CFG(GPIO2, AF0)
+#define GPIO3_GPIO3            MFP_CFG(GPIO3, AF0)
+#define GPIO4_GPIO4            MFP_CFG(GPIO4, AF0)
+#define GPIO5_GPIO5            MFP_CFG(GPIO5, AF0)
+#define GPIO6_GPIO6            MFP_CFG(GPIO6, AF0)
+#define GPIO7_GPIO7            MFP_CFG(GPIO7, AF0)
+#define GPIO8_GPIO8            MFP_CFG(GPIO8, AF0)
+#define GPIO9_GPIO9            MFP_CFG(GPIO9, AF0)
+#define GPIO10_GPIO10          MFP_CFG(GPIO10, AF0)
+#define GPIO11_GPIO11          MFP_CFG(GPIO11, AF0)
+#define GPIO12_GPIO12          MFP_CFG(GPIO12, AF0)
+#define GPIO13_GPIO13          MFP_CFG(GPIO13, AF0)
+#define GPIO14_GPIO14          MFP_CFG(GPIO14, AF0)
+#define GPIO15_GPIO15          MFP_CFG(GPIO15, AF0)
+#define GPIO16_GPIO16          MFP_CFG(GPIO16, AF0)
+#define GPIO17_GPIO17          MFP_CFG(GPIO17, AF0)
+#define GPIO18_GPIO18          MFP_CFG(GPIO18, AF0)
+#define GPIO19_GPIO19          MFP_CFG(GPIO19, AF0)
+#define GPIO20_GPIO20          MFP_CFG(GPIO20, AF0)
+#define GPIO21_GPIO21          MFP_CFG(GPIO21, AF0)
+#define GPIO22_GPIO22          MFP_CFG(GPIO22, AF0)
+#define GPIO23_GPIO23          MFP_CFG(GPIO23, AF0)
+#define GPIO24_GPIO24          MFP_CFG(GPIO24, AF0)
+#define GPIO25_GPIO25          MFP_CFG(GPIO25, AF0)
+#define GPIO26_GPIO26          MFP_CFG(GPIO26, AF0)
+#define GPIO27_GPIO27          MFP_CFG(GPIO27, AF0)
+#define GPIO28_GPIO28          MFP_CFG(GPIO28, AF0)
+#define GPIO29_GPIO29          MFP_CFG(GPIO29, AF0)
+#define GPIO30_GPIO30          MFP_CFG(GPIO30, AF0)
+#define GPIO31_GPIO31          MFP_CFG(GPIO31, AF0)
+#define GPIO32_GPIO32          MFP_CFG(GPIO32, AF0)
+#define GPIO33_GPIO33          MFP_CFG(GPIO33, AF0)
+#define GPIO34_GPIO34          MFP_CFG(GPIO34, AF0)
+#define GPIO35_GPIO35          MFP_CFG(GPIO35, AF0)
+#define GPIO36_GPIO36          MFP_CFG(GPIO36, AF0)
+#define GPIO37_GPIO37          MFP_CFG(GPIO37, AF0)
+#define GPIO38_GPIO38          MFP_CFG(GPIO38, AF0)
+#define GPIO39_GPIO39          MFP_CFG(GPIO39, AF0)
+#define GPIO40_GPIO40          MFP_CFG(GPIO40, AF0)
+#define GPIO41_GPIO41          MFP_CFG(GPIO41, AF0)
+#define GPIO42_GPIO42          MFP_CFG(GPIO42, AF0)
+#define GPIO43_GPIO43          MFP_CFG(GPIO43, AF0)
+#define GPIO44_GPIO44          MFP_CFG(GPIO44, AF0)
+#define GPIO45_GPIO45          MFP_CFG(GPIO45, AF0)
+#define GPIO46_GPIO46          MFP_CFG(GPIO46, AF0)
+#define GPIO47_GPIO47          MFP_CFG(GPIO47, AF0)
+#define GPIO48_GPIO48          MFP_CFG(GPIO48, AF0)
+#define GPIO49_GPIO49          MFP_CFG(GPIO49, AF0)
+#define GPIO50_GPIO50          MFP_CFG(GPIO50, AF0)
+#define GPIO51_GPIO51          MFP_CFG(GPIO51, AF0)
+#define GPIO52_GPIO52          MFP_CFG(GPIO52, AF0)
+#define GPIO53_GPIO53          MFP_CFG(GPIO53, AF0)
+#define GPIO54_GPIO54          MFP_CFG(GPIO54, AF0)
+#define GPIO55_GPIO55          MFP_CFG(GPIO55, AF0)
+#define GPIO56_GPIO56          MFP_CFG(GPIO56, AF0)
+#define GPIO57_GPIO57          MFP_CFG(GPIO57, AF0)
+#define GPIO58_GPIO58          MFP_CFG(GPIO58, AF0)
+#define GPIO59_GPIO59          MFP_CFG(GPIO59, AF0)
+#define GPIO60_GPIO60          MFP_CFG(GPIO60, AF0)
+#define GPIO61_GPIO61          MFP_CFG(GPIO61, AF0)
+#define GPIO62_GPIO62          MFP_CFG(GPIO62, AF0)
+#define GPIO63_GPIO63          MFP_CFG(GPIO63, AF0)
+#define GPIO64_GPIO64          MFP_CFG(GPIO64, AF0)
+#define GPIO65_GPIO65          MFP_CFG(GPIO65, AF0)
+#define GPIO66_GPIO66          MFP_CFG(GPIO66, AF0)
+#define GPIO67_GPIO67          MFP_CFG(GPIO67, AF0)
+#define GPIO68_GPIO68          MFP_CFG(GPIO68, AF0)
+#define GPIO69_GPIO69          MFP_CFG(GPIO69, AF0)
+#define GPIO70_GPIO70          MFP_CFG(GPIO70, AF0)
+#define GPIO71_GPIO71          MFP_CFG(GPIO71, AF0)
+#define GPIO72_GPIO72          MFP_CFG(GPIO72, AF0)
+#define GPIO73_GPIO73          MFP_CFG(GPIO73, AF0)
+#define GPIO74_GPIO74          MFP_CFG(GPIO74, AF0)
+#define GPIO75_GPIO75          MFP_CFG(GPIO75, AF0)
+#define GPIO76_GPIO76          MFP_CFG(GPIO76, AF0)
+#define GPIO77_GPIO77          MFP_CFG(GPIO77, AF0)
+#define GPIO78_GPIO78          MFP_CFG(GPIO78, AF0)
+#define GPIO79_GPIO79          MFP_CFG(GPIO79, AF0)
+#define GPIO80_GPIO80          MFP_CFG(GPIO80, AF0)
+#define GPIO81_GPIO81          MFP_CFG(GPIO81, AF0)
+#define GPIO82_GPIO82          MFP_CFG(GPIO82, AF0)
+#define GPIO83_GPIO83          MFP_CFG(GPIO83, AF0)
+#define GPIO84_GPIO84          MFP_CFG(GPIO84, AF0)
+#define GPIO85_GPIO85          MFP_CFG(GPIO85, AF0)
+#define GPIO86_GPIO86          MFP_CFG(GPIO86, AF0)
+#define GPIO87_GPIO87          MFP_CFG(GPIO87, AF0)
+#define GPIO88_GPIO88          MFP_CFG(GPIO88, AF0)
+#define GPIO89_GPIO89          MFP_CFG(GPIO89, AF0)
+#define GPIO90_GPIO90          MFP_CFG(GPIO90, AF0)
+#define GPIO91_GPIO91          MFP_CFG(GPIO91, AF0)
+#define GPIO92_GPIO92          MFP_CFG(GPIO92, AF0)
+#define GPIO93_GPIO93          MFP_CFG(GPIO93, AF0)
+#define GPIO94_GPIO94          MFP_CFG(GPIO94, AF0)
+#define GPIO95_GPIO95          MFP_CFG(GPIO95, AF0)
+#define GPIO96_GPIO96          MFP_CFG(GPIO96, AF0)
+#define GPIO97_GPIO97          MFP_CFG(GPIO97, AF0)
+#define GPIO98_GPIO98          MFP_CFG(GPIO98, AF0)
+#define GPIO99_GPIO99          MFP_CFG(GPIO99, AF0)
+#define GPIO100_GPIO100                MFP_CFG(GPIO100, AF0)
+#define GPIO101_GPIO101                MFP_CFG(GPIO101, AF0)
+#define GPIO102_GPIO102                MFP_CFG(GPIO102, AF1)
+#define GPIO103_GPIO103                MFP_CFG(GPIO103, AF1)
+#define GPIO104_GPIO104                MFP_CFG(GPIO104, AF1)
+#define GPIO105_GPIO105                MFP_CFG(GPIO105, AF1)
+#define GPIO106_GPIO106                MFP_CFG(GPIO106, AF1)
+#define GPIO107_GPIO107                MFP_CFG(GPIO107, AF1)
+#define GPIO108_GPIO108                MFP_CFG(GPIO108, AF1)
+#define GPIO109_GPIO109                MFP_CFG(GPIO109, AF1)
+#define GPIO110_GPIO110                MFP_CFG(GPIO110, AF1)
+#define GPIO111_GPIO111                MFP_CFG(GPIO111, AF1)
+#define GPIO112_GPIO112                MFP_CFG(GPIO112, AF1)
+#define GPIO113_GPIO113                MFP_CFG(GPIO113, AF1)
+#define GPIO114_GPIO114                MFP_CFG(GPIO114, AF0)
+#define GPIO115_GPIO115                MFP_CFG(GPIO115, AF0)
+#define GPIO116_GPIO116                MFP_CFG(GPIO116, AF0)
+#define GPIO117_GPIO117                MFP_CFG(GPIO117, AF0)
+#define GPIO118_GPIO118                MFP_CFG(GPIO118, AF0)
+#define GPIO119_GPIO119                MFP_CFG(GPIO119, AF0)
+#define GPIO120_GPIO120                MFP_CFG(GPIO120, AF0)
+#define GPIO121_GPIO121                MFP_CFG(GPIO121, AF0)
+#define GPIO122_GPIO122                MFP_CFG(GPIO122, AF0)
+#define GPIO123_GPIO123                MFP_CFG(GPIO123, AF0)
+#define GPIO124_GPIO124                MFP_CFG(GPIO124, AF0)
+#define GPIO125_GPIO125                MFP_CFG(GPIO125, AF0)
+#define GPIO126_GPIO126                MFP_CFG(GPIO126, AF0)
+#define GPIO127_GPIO127                MFP_CFG(GPIO127, AF0)
+#define GPIO128_GPIO128                MFP_CFG(GPIO128, AF0)
+#define GPIO129_GPIO129                MFP_CFG(GPIO129, AF0)
+#define GPIO130_GPIO130                MFP_CFG(GPIO130, AF0)
+#define GPIO131_GPIO131                MFP_CFG(GPIO131, AF0)
+#define GPIO132_GPIO132                MFP_CFG(GPIO132, AF0)
+#define GPIO133_GPIO133                MFP_CFG(GPIO133, AF0)
+#define GPIO134_GPIO134                MFP_CFG(GPIO134, AF0)
+#define GPIO135_GPIO135                MFP_CFG(GPIO135, AF0)
+#define GPIO136_GPIO136                MFP_CFG(GPIO136, AF0)
+#define GPIO137_GPIO137                MFP_CFG(GPIO137, AF0)
+#define GPIO138_GPIO138                MFP_CFG(GPIO138, AF0)
+#define GPIO139_GPIO139                MFP_CFG(GPIO139, AF0)
+#define GPIO140_GPIO140                MFP_CFG(GPIO140, AF0)
+#define GPIO141_GPIO141                MFP_CFG(GPIO141, AF0)
+#define GPIO142_GPIO142                MFP_CFG(GPIO142, AF1)
+#define GPIO143_GPIO143                MFP_CFG(GPIO143, AF1)
+#define GPIO144_GPIO144                MFP_CFG(GPIO144, AF1)
+#define GPIO145_GPIO145                MFP_CFG(GPIO145, AF1)
+#define GPIO146_GPIO146                MFP_CFG(GPIO146, AF1)
+#define GPIO147_GPIO147                MFP_CFG(GPIO147, AF1)
+#define GPIO148_GPIO148                MFP_CFG(GPIO148, AF1)
+#define GPIO149_GPIO149                MFP_CFG(GPIO149, AF1)
+#define GPIO150_GPIO150                MFP_CFG(GPIO150, AF1)
+#define GPIO151_GPIO151                MFP_CFG(GPIO151, AF1)
+#define GPIO152_GPIO152                MFP_CFG(GPIO152, AF1)
+#define GPIO153_GPIO153                MFP_CFG(GPIO153, AF1)
+#define GPIO154_GPIO154                MFP_CFG(GPIO154, AF1)
+#define GPIO155_GPIO155                MFP_CFG(GPIO155, AF1)
+#define GPIO156_GPIO156                MFP_CFG(GPIO156, AF1)
+#define GPIO157_GPIO157                MFP_CFG(GPIO157, AF1)
+#define GPIO158_GPIO158                MFP_CFG(GPIO158, AF1)
+#define GPIO159_GPIO159                MFP_CFG(GPIO159, AF1)
+#define GPIO160_GPIO160                MFP_CFG(GPIO160, AF1)
+#define GPIO161_GPIO161                MFP_CFG(GPIO161, AF1)
+#define GPIO162_GPIO162                MFP_CFG(GPIO162, AF1)
+#define GPIO163_GPIO163                MFP_CFG(GPIO163, AF1)
+#define GPIO164_GPIO164                MFP_CFG(GPIO164, AF1)
+#define GPIO165_GPIO165                MFP_CFG(GPIO165, AF1)
+#define GPIO166_GPIO166                MFP_CFG(GPIO166, AF1)
+#define GPIO167_GPIO167                MFP_CFG(GPIO167, AF1)
+#define GPIO168_GPIO168                MFP_CFG(GPIO168, AF1)
 
 /* DFI */
 #define GPIO108_DFI_D15                MFP_CFG(GPIO108, AF0)
 
 /* Ethernet */
 #define GPIO155_SM_ADVMUX      MFP_CFG(GPIO155, AF2)
-#define GPIO155_GPIO155                MFP_CFG(GPIO155, AF1)
 
 /* UART1 */
 #define GPIO45_UART1_RXD       MFP_CFG(GPIO45, AF1)
 #define GPIO44_TWSI2_SDA       MFP_CFG_DRV(GPIO44, AF1, SLOW)
 #define GPIO71_TWSI3_SCL       MFP_CFG_DRV(GPIO71, AF1, SLOW)
 #define GPIO72_TWSI3_SDA       MFP_CFG_DRV(GPIO72, AF1, SLOW)
+#define TWSI4_SCL              MFP_CFG_DRV(TWSI4_SCL, AF0, SLOW)
+#define TWSI4_SDA              MFP_CFG_DRV(TWSI4_SDA, AF0, SLOW)
 #define GPIO99_TWSI5_SCL       MFP_CFG_DRV(GPIO99, AF4, SLOW)
 #define GPIO100_TWSI5_SDA      MFP_CFG_DRV(GPIO100, AF4, SLOW)
 #define GPIO97_TWSI6_SCL       MFP_CFG_DRV(GPIO97, AF2, SLOW)
 #define GPIO69_CAM_MCLK                MFP_CFG_DRV(GPIO69, AF1, FAST)
 #define GPIO70_CAM_PCLK                MFP_CFG_DRV(GPIO70, AF1, FAST)
 
-/* Wifi */
-#define GPIO45_GPIO45          MFP_CFG(GPIO45, AF0)
-#define GPIO46_GPIO46          MFP_CFG(GPIO46, AF0)
-#define GPIO21_GPIO21          MFP_CFG(GPIO21, AF0)
-#define GPIO22_GPIO22          MFP_CFG(GPIO22, AF0)
-#define GPIO55_GPIO55          MFP_CFG(GPIO55, AF0)
-#define GPIO56_GPIO56          MFP_CFG(GPIO56, AF0)
-#define GPIO57_GPIO57          MFP_CFG(GPIO57, AF0)
-#define GPIO58_GPIO58          MFP_CFG(GPIO58, AF0)
-
-/* Codec*/
-#define GPIO23_GPIO23          MFP_CFG(GPIO23, AF0)
-
-#define GPIO101_GPIO101                MFP_CFG(GPIO101, AF0)
-
 /* PMIC */
 #define PMIC_PMIC_INT          MFP_CFG(PMIC_INT, AF0)
 
index 459f3be..fec220b 100644 (file)
@@ -39,17 +39,17 @@ static inline int mmp2_add_twsi(int id, struct i2c_pxa_platform_data *data,
        int ret;
 
        switch (id) {
-       case 0: d = &mmp2_device_twsi1; break;
-       case 1: d = &mmp2_device_twsi2; break;
-       case 2: d = &mmp2_device_twsi3; break;
-       case 3: d = &mmp2_device_twsi4; break;
-       case 4: d = &mmp2_device_twsi5; break;
-       case 5: d = &mmp2_device_twsi6; break;
+       case 1: d = &mmp2_device_twsi1; break;
+       case 2: d = &mmp2_device_twsi2; break;
+       case 3: d = &mmp2_device_twsi3; break;
+       case 4: d = &mmp2_device_twsi4; break;
+       case 5: d = &mmp2_device_twsi5; break;
+       case 6: d = &mmp2_device_twsi6; break;
        default:
                return -EINVAL;
        }
 
-       ret = i2c_register_board_info(id, info, size);
+       ret = i2c_register_board_info(id - 1, info, size);
        if (ret)
                return ret;
 
index 3ad612c..3b2bd5d 100644 (file)
@@ -14,6 +14,11 @@ extern struct pxa_device_desc pxa168_device_pwm1;
 extern struct pxa_device_desc pxa168_device_pwm2;
 extern struct pxa_device_desc pxa168_device_pwm3;
 extern struct pxa_device_desc pxa168_device_pwm4;
+extern struct pxa_device_desc pxa168_device_ssp1;
+extern struct pxa_device_desc pxa168_device_ssp2;
+extern struct pxa_device_desc pxa168_device_ssp3;
+extern struct pxa_device_desc pxa168_device_ssp4;
+extern struct pxa_device_desc pxa168_device_ssp5;
 extern struct pxa_device_desc pxa168_device_nand;
 
 static inline int pxa168_add_uart(int id)
@@ -67,6 +72,22 @@ static inline int pxa168_add_pwm(int id)
        return pxa_register_device(d, NULL, 0);
 }
 
+static inline int pxa168_add_ssp(int id)
+{
+       struct pxa_device_desc *d = NULL;
+
+       switch (id) {
+       case 1: d = &pxa168_device_ssp1; break;
+       case 2: d = &pxa168_device_ssp2; break;
+       case 3: d = &pxa168_device_ssp3; break;
+       case 4: d = &pxa168_device_ssp4; break;
+       case 5: d = &pxa168_device_ssp5; break;
+       default:
+               return -EINVAL;
+       }
+       return pxa_register_device(d, NULL, 0);
+}
+
 static inline int pxa168_add_nand(struct pxa3xx_nand_platform_data *info)
 {
        return pxa_register_device(&pxa168_device_nand, info, sizeof(*info));
index 712af03..1a96585 100644 (file)
@@ -26,8 +26,6 @@
 #define APBC_PXA168_PWM2       APBC_REG(0x010)
 #define APBC_PXA168_PWM3       APBC_REG(0x014)
 #define APBC_PXA168_PWM4       APBC_REG(0x018)
-#define APBC_PXA168_SSP1       APBC_REG(0x01c)
-#define APBC_PXA168_SSP2       APBC_REG(0x020)
 #define APBC_PXA168_RTC                APBC_REG(0x028)
 #define APBC_PXA168_TWSI0      APBC_REG(0x02c)
 #define APBC_PXA168_KPC                APBC_REG(0x030)
 #define APBC_PXA168_AIB                APBC_REG(0x03c)
 #define APBC_PXA168_SW_JTAG    APBC_REG(0x040)
 #define APBC_PXA168_ONEWIRE    APBC_REG(0x048)
-#define APBC_PXA168_SSP3       APBC_REG(0x04c)
 #define APBC_PXA168_ASFAR      APBC_REG(0x050)
 #define APBC_PXA168_ASSAR      APBC_REG(0x054)
-#define APBC_PXA168_SSP4       APBC_REG(0x058)
-#define APBC_PXA168_SSP5       APBC_REG(0x05c)
 #define APBC_PXA168_TWSI1      APBC_REG(0x06c)
 #define APBC_PXA168_UART3      APBC_REG(0x070)
 #define APBC_PXA168_AC97       APBC_REG(0x084)
+#define APBC_PXA168_SSP1       APBC_REG(0x81c)
+#define APBC_PXA168_SSP2       APBC_REG(0x820)
+#define APBC_PXA168_SSP3       APBC_REG(0x84c)
+#define APBC_PXA168_SSP4       APBC_REG(0x858)
+#define APBC_PXA168_SSP5       APBC_REG(0x85c)
 
 /*
  * APB Clock register offsets for PXA910
diff --git a/arch/arm/mach-mmp/include/mach/regs-smc.h b/arch/arm/mach-mmp/include/mach/regs-smc.h
new file mode 100644 (file)
index 0000000..e484d40
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * linux/arch/arm/mach-mmp/include/mach/regs-smc.h
+ *
+ *  Static Memory Controller Registers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __ASM_MACH_REGS_SMC_H
+#define __ASM_MACH_REGS_SMC_H
+
+#include <mach/addr-map.h>
+
+#define SMC_VIRT_BASE          (AXI_VIRT_BASE + 0x83800)
+#define SMC_REG(x)             (SMC_VIRT_BASE + (x))
+
+#define SMC_MSC0               SMC_REG(0x0020)
+#define SMC_MSC1               SMC_REG(0x0024)
+#define SMC_SXCNFG0            SMC_REG(0x0030)
+#define SMC_SXCNFG1            SMC_REG(0x0034)
+#define SMC_MEMCLKCFG          SMC_REG(0x0068)
+#define SMC_CSDFICFG0          SMC_REG(0x0090)
+#define SMC_CSDFICFG1          SMC_REG(0x0094)
+#define SMC_CLK_RET_DEL                SMC_REG(0x00b0)
+#define SMC_ADV_RET_DEL                SMC_REG(0x00b4)
+#define SMC_CSADRMAP0          SMC_REG(0x00c0)
+#define SMC_CSADRMAP1          SMC_REG(0x00c4)
+#define SMC_WE_AP0             SMC_REG(0x00e0)
+#define SMC_WE_AP1             SMC_REG(0x00e4)
+#define SMC_OE_AP0             SMC_REG(0x00f0)
+#define SMC_OE_AP1             SMC_REG(0x00f4)
+#define SMC_ADV_AP0            SMC_REG(0x0100)
+#define SMC_ADV_AP1            SMC_REG(0x0104)
+
+#endif /* __ASM_MACH_REGS_SMC_H */
index 6cebbd0..70c9f1d 100644 (file)
@@ -6,4 +6,8 @@
  * published by the Free Software Foundation.
  */
 
+#ifdef CONFIG_CPU_MMP2
+#define CLOCK_TICK_RATE                6500000
+#else
 #define CLOCK_TICK_RATE                3250000
+#endif
index cfd4d66..d77dd41 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/max8649.h>
+#include <linux/mfd/max8925.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/addr-map.h>
 #include <mach/mfp-mmp2.h>
 #include <mach/mmp2.h>
+#include <mach/irqs.h>
 
 #include "common.h"
 
@@ -58,6 +62,63 @@ static unsigned long jasper_pin_config[] __initdata = {
        GPIO149_ND_CLE,
        GPIO112_ND_RDY0,
        GPIO160_ND_RDY1,
+
+       /* PMIC */
+       PMIC_PMIC_INT | MFP_LPM_EDGE_FALL,
+};
+
+static struct regulator_consumer_supply max8649_supply[] = {
+       REGULATOR_SUPPLY("vcc_core", NULL),
+};
+
+static struct regulator_init_data max8649_init_data = {
+       .constraints    = {
+               .name           = "vcc_core range",
+               .min_uV         = 1150000,
+               .max_uV         = 1280000,
+               .always_on      = 1,
+               .boot_on        = 1,
+               .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
+       },
+       .num_consumer_supplies  = 1,
+       .consumer_supplies      = &max8649_supply[0],
+};
+
+static struct max8649_platform_data jasper_max8649_info = {
+       .mode           = 2,    /* VID1 = 1, VID0 = 0 */
+       .extclk         = 0,
+       .ramp_timing    = MAX8649_RAMP_32MV,
+       .regulator      = &max8649_init_data,
+};
+
+static struct max8925_backlight_pdata jasper_backlight_data = {
+       .dual_string    = 0,
+};
+
+static struct max8925_power_pdata jasper_power_data = {
+       .batt_detect            = 0,    /* can't detect battery by ID pin */
+       .topoff_threshold       = MAX8925_TOPOFF_THR_10PER,
+       .fast_charge            = MAX8925_FCHG_1000MA,
+};
+
+static struct max8925_platform_data jasper_max8925_info = {
+       .backlight              = &jasper_backlight_data,
+       .power                  = &jasper_power_data,
+       .irq_base               = IRQ_BOARD_START,
+};
+
+static struct i2c_board_info jasper_twsi1_info[] = {
+       [0] = {
+               .type           = "max8649",
+               .addr           = 0x60,
+               .platform_data  = &jasper_max8649_info,
+       },
+       [1] = {
+               .type           = "max8925",
+               .addr           = 0x3c,
+               .irq            = IRQ_MMP2_PMIC,
+               .platform_data  = &jasper_max8925_info,
+       },
 };
 
 static void __init jasper_init(void)
@@ -67,6 +128,9 @@ static void __init jasper_init(void)
        /* on-chip devices */
        mmp2_add_uart(1);
        mmp2_add_uart(3);
+       mmp2_add_twsi(1, NULL, ARRAY_AND_SIZE(jasper_twsi1_info));
+
+       regulator_has_full_constraints();
 }
 
 MACHINE_START(MARVELL_JASPER, "Jasper Development Platform")
index 72eb9da..7f5eb05 100644 (file)
 #include <linux/init.h>
 #include <linux/io.h>
 
+#include <asm/hardware/cache-tauros2.h>
+
 #include <mach/addr-map.h>
 #include <mach/regs-apbc.h>
 #include <mach/regs-apmu.h>
 #include <mach/cputype.h>
 #include <mach/irqs.h>
+#include <mach/dma.h>
 #include <mach/mfp.h>
 #include <mach/gpio.h>
 #include <mach/devices.h>
 #define APMASK(i)      (GPIO_REGS_VIRT + BANK_OFF(i) + 0x9c)
 
 static struct mfp_addr_map mmp2_addr_map[] __initdata = {
+
+       MFP_ADDR_X(GPIO0, GPIO58, 0x54),
+       MFP_ADDR_X(GPIO59, GPIO73, 0x280),
+       MFP_ADDR_X(GPIO74, GPIO101, 0x170),
+
+       MFP_ADDR(GPIO102, 0x0),
+       MFP_ADDR(GPIO103, 0x4),
+       MFP_ADDR(GPIO104, 0x1fc),
+       MFP_ADDR(GPIO105, 0x1f8),
+       MFP_ADDR(GPIO106, 0x1f4),
+       MFP_ADDR(GPIO107, 0x1f0),
+       MFP_ADDR(GPIO108, 0x21c),
+       MFP_ADDR(GPIO109, 0x218),
+       MFP_ADDR(GPIO110, 0x214),
+       MFP_ADDR(GPIO111, 0x200),
+       MFP_ADDR(GPIO112, 0x244),
+       MFP_ADDR(GPIO113, 0x25c),
+       MFP_ADDR(GPIO114, 0x164),
+       MFP_ADDR_X(GPIO115, GPIO122, 0x260),
+
+       MFP_ADDR(GPIO123, 0x148),
+       MFP_ADDR_X(GPIO124, GPIO141, 0xc),
+
+       MFP_ADDR(GPIO142, 0x8),
+       MFP_ADDR_X(GPIO143, GPIO151, 0x220),
+       MFP_ADDR_X(GPIO152, GPIO153, 0x248),
+       MFP_ADDR_X(GPIO154, GPIO155, 0x254),
+       MFP_ADDR_X(GPIO156, GPIO159, 0x14c),
+
+       MFP_ADDR(GPIO160, 0x250),
+       MFP_ADDR(GPIO161, 0x210),
+       MFP_ADDR(GPIO162, 0x20c),
+       MFP_ADDR(GPIO163, 0x208),
+       MFP_ADDR(GPIO164, 0x204),
+       MFP_ADDR(GPIO165, 0x1ec),
+       MFP_ADDR(GPIO166, 0x1e8),
+       MFP_ADDR(GPIO167, 0x1e4),
+       MFP_ADDR(GPIO168, 0x1e0),
+
+       MFP_ADDR_X(TWSI1_SCL, TWSI1_SDA, 0x140),
+       MFP_ADDR_X(TWSI4_SCL, TWSI4_SDA, 0x2bc),
+
        MFP_ADDR(PMIC_INT, 0x2c4),
+       MFP_ADDR(CLK_REQ, 0x160),
 
        MFP_ADDR_END,
 };
@@ -99,9 +145,13 @@ static struct clk_lookup mmp2_clkregs[] = {
 static int __init mmp2_init(void)
 {
        if (cpu_is_mmp2()) {
+#ifdef CONFIG_CACHE_TAUROS2
+               tauros2_init();
+#endif
                mfp_init_base(MFPR_VIRT_BASE);
                mfp_init_addr(mmp2_addr_map);
-               clks_register(ARRAY_AND_SIZE(mmp2_clkregs));
+               pxa_init_dma(IRQ_MMP2_DMA_RIQ, 16);
+               clkdev_add_table(ARRAY_AND_SIZE(mmp2_clkregs));
        }
 
        return 0;
index 1873c82..652ae66 100644 (file)
@@ -72,6 +72,11 @@ static APBC_CLK(pwm1, PXA168_PWM1, 1, 13000000);
 static APBC_CLK(pwm2, PXA168_PWM2, 1, 13000000);
 static APBC_CLK(pwm3, PXA168_PWM3, 1, 13000000);
 static APBC_CLK(pwm4, PXA168_PWM4, 1, 13000000);
+static APBC_CLK(ssp1, PXA168_SSP1, 4, 0);
+static APBC_CLK(ssp2, PXA168_SSP2, 4, 0);
+static APBC_CLK(ssp3, PXA168_SSP3, 4, 0);
+static APBC_CLK(ssp4, PXA168_SSP4, 4, 0);
+static APBC_CLK(ssp5, PXA168_SSP5, 4, 0);
 
 static APMU_CLK(nand, NAND, 0x01db, 208000000);
 
@@ -85,6 +90,11 @@ static struct clk_lookup pxa168_clkregs[] = {
        INIT_CLKREG(&clk_pwm2, "pxa168-pwm.1", NULL),
        INIT_CLKREG(&clk_pwm3, "pxa168-pwm.2", NULL),
        INIT_CLKREG(&clk_pwm4, "pxa168-pwm.3", NULL),
+       INIT_CLKREG(&clk_ssp1, "pxa168-ssp.0", NULL),
+       INIT_CLKREG(&clk_ssp2, "pxa168-ssp.1", NULL),
+       INIT_CLKREG(&clk_ssp3, "pxa168-ssp.2", NULL),
+       INIT_CLKREG(&clk_ssp4, "pxa168-ssp.3", NULL),
+       INIT_CLKREG(&clk_ssp5, "pxa168-ssp.4", NULL),
        INIT_CLKREG(&clk_nand, "pxa3xx-nand", NULL),
 };
 
@@ -132,3 +142,8 @@ PXA168_DEVICE(pwm2, "pxa168-pwm", 1, NONE, 0xd401a400, 0x10);
 PXA168_DEVICE(pwm3, "pxa168-pwm", 2, NONE, 0xd401a800, 0x10);
 PXA168_DEVICE(pwm4, "pxa168-pwm", 3, NONE, 0xd401ac00, 0x10);
 PXA168_DEVICE(nand, "pxa3xx-nand", -1, NAND, 0xd4283000, 0x80, 97, 99);
+PXA168_DEVICE(ssp1, "pxa168-ssp", 0, SSP1, 0xd401b000, 0x40, 52, 53);
+PXA168_DEVICE(ssp2, "pxa168-ssp", 1, SSP2, 0xd401c000, 0x40, 54, 55);
+PXA168_DEVICE(ssp3, "pxa168-ssp", 2, SSP3, 0xd401f000, 0x40, 56, 57);
+PXA168_DEVICE(ssp4, "pxa168-ssp", 3, SSP4, 0xd4020000, 0x40, 58, 59);
+PXA168_DEVICE(ssp5, "pxa168-ssp", 4, SSP5, 0xd4021000, 0x40, 60, 61);
index f780086..47264a7 100644 (file)
@@ -1,7 +1,80 @@
 if ARCH_MSM
 
-comment "MSM Board Type"
+choice
+       prompt "Qualcomm MSM SoC Type"
+       default ARCH_MSM7X00A
+
+config ARCH_MSM7X00A
+       bool "MSM7x00A / MSM7x01A"
+       select ARCH_MSM_ARM11
+       select MSM_SMD
+       select MSM_SMD_PKG3
+       select CPU_V6
+
+config ARCH_MSM7X30
+       bool "MSM7x30"
+       select ARCH_MSM_SCORPION
+       select MSM_SMD
+       select MSM_VIC
+       select CPU_V7
+       select MSM_REMOTE_SPINLOCK_DEKKERS
+
+config ARCH_QSD8X50
+       bool "QSD8X50"
+       select ARCH_MSM_SCORPION
+       select MSM_SMD
+       select MSM_VIC
+       select CPU_V7
+       select MSM_REMOTE_SPINLOCK_LDREX
+endchoice
+
+config MSM_SOC_REV_A
+       bool
+
+config  ARCH_MSM_ARM11
+       bool
+config  ARCH_MSM_SCORPION
+       bool
+
+config  MSM_VIC
+       bool
+
+menu "Qualcomm MSM Board Type"
+
+config MACH_HALIBUT
        depends on ARCH_MSM
+       depends on ARCH_MSM7X00A
+       bool "Halibut Board (QCT SURF7201A)"
+       help
+         Support for the Qualcomm SURF7201A eval board.
+
+config MACH_TROUT
+       depends on ARCH_MSM
+       depends on ARCH_MSM7X00A
+       bool "HTC Dream (aka trout)"
+       help
+         Support for the HTC Dream, T-Mobile G1, Android ADP1 devices.
+
+config MACH_MSM7X30_SURF
+       depends on ARCH_MSM7X30
+       bool "MSM7x30 SURF"
+       help
+         Support for the Qualcomm MSM7x30 SURF eval board.
+
+config MACH_QSD8X50_SURF
+       depends on ARCH_QSD8X50
+       bool "QSD8x50 SURF"
+       help
+         Support for the Qualcomm QSD8x50 SURF eval board.
+
+config MACH_QSD8X50A_ST1_5
+       depends on ARCH_QSD8X50
+       select MSM_SOC_REV_A
+       bool "QSD8x50A ST1.5"
+       help
+         Support for the Qualcomm ST1.5.
+
+endmenu
 
 config MSM_DEBUG_UART
        int
@@ -27,17 +100,10 @@ choice
                bool "UART3"
 endchoice
 
-config MACH_HALIBUT
-       depends on ARCH_MSM
-       default y
-       bool "Halibut Board (QCT SURF7201A)"
-       help
-         Support for the Qualcomm SURF7201A eval board.
+config MSM_SMD_PKG3
+       bool
 
-config MACH_TROUT
-       default y
-       bool "HTC Dream (aka trout)"
-       help
-         Support for the HTC Dream, T-Mobile G1, Android ADP1 devices.
+config MSM_SMD
+       bool
 
 endif
index 91e6f5c..66677f0 100644 (file)
@@ -1,9 +1,22 @@
-obj-y += io.o idle.o irq.o timer.o dma.o
-obj-y += devices.o
 obj-y += proc_comm.o
+obj-y += io.o idle.o timer.o dma.o
 obj-y += vreg.o
-obj-y += clock.o clock-7x01a.o
+obj-y += acpuclock-arm11.o
+obj-y += clock.o clock-pcom.o
+obj-y += gpio.o
 
-obj-$(CONFIG_MACH_HALIBUT) += board-halibut.o
+ifdef CONFIG_MSM_VIC
+obj-y += irq-vic.o
+else
+obj-y += irq.o
+endif
+
+obj-$(CONFIG_ARCH_QSD8X50) += sirc.o
+obj-$(CONFIG_MSM_SMD) += smd.o smd_debug.o
+obj-$(CONFIG_MSM_SMD) += last_radio_log.o
+
+obj-$(CONFIG_MACH_TROUT) += board-trout.o devices-msm7x00.o
+obj-$(CONFIG_MACH_HALIBUT) += board-halibut.o devices-msm7x00.o
+obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o
+obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o
 
-obj-$(CONFIG_MACH_TROUT) += board-dream.o
diff --git a/arch/arm/mach-msm/acpuclock-arm11.c b/arch/arm/mach-msm/acpuclock-arm11.c
new file mode 100644 (file)
index 0000000..af5e85b
--- /dev/null
@@ -0,0 +1,526 @@
+/* arch/arm/mach-msm/acpuclock.c
+ *
+ * MSM architecture clock driver
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2007 QUALCOMM Incorporated
+ * Author: San Mehat <san@android.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/cpufreq.h>
+#include <linux/mutex.h>
+#include <linux/io.h>
+#include <mach/board.h>
+#include <mach/msm_iomap.h>
+
+#include "proc_comm.h"
+#include "acpuclock.h"
+
+
+#define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100)
+#define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104)
+#define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124)
+
+/*
+ * ARM11 clock configuration for specific ACPU speeds
+ */
+
+#define ACPU_PLL_TCXO  -1
+#define ACPU_PLL_0     0
+#define ACPU_PLL_1     1
+#define ACPU_PLL_2     2
+#define ACPU_PLL_3     3
+
+#define PERF_SWITCH_DEBUG 0
+#define PERF_SWITCH_STEP_DEBUG 0
+
+struct clock_state
+{
+       struct clkctl_acpu_speed        *current_speed;
+       struct mutex                    lock;
+       uint32_t                        acpu_switch_time_us;
+       uint32_t                        max_speed_delta_khz;
+       uint32_t                        vdd_switch_time_us;
+       unsigned long                   power_collapse_khz;
+       unsigned long                   wait_for_irq_khz;
+};
+
+static struct clk *ebi1_clk;
+static struct clock_state drv_state = { 0 };
+
+static void __init acpuclk_init(void);
+
+/* MSM7201A Levels 3-6 all correspond to 1.2V, level 7 corresponds to 1.325V. */
+enum {
+       VDD_0 = 0,
+       VDD_1 = 1,
+       VDD_2 = 2,
+       VDD_3 = 3,
+       VDD_4 = 3,
+       VDD_5 = 3,
+       VDD_6 = 3,
+       VDD_7 = 7,
+       VDD_END
+};
+
+struct clkctl_acpu_speed {
+       unsigned int    a11clk_khz;
+       int             pll;
+       unsigned int    a11clk_src_sel;
+       unsigned int    a11clk_src_div;
+       unsigned int    ahbclk_khz;
+       unsigned int    ahbclk_div;
+       int             vdd;
+       unsigned int    axiclk_khz;
+       unsigned long   lpj; /* loops_per_jiffy */
+/* Index in acpu_freq_tbl[] for steppings. */
+       short           down;
+       short           up;
+};
+
+/*
+ * ACPU speed table. Complete table is shown but certain speeds are commented
+ * out to optimized speed switching. Initalize loops_per_jiffy to 0.
+ *
+ * Table stepping up/down is optimized for 256mhz jumps while staying on the
+ * same PLL.
+ */
+#if (0)
+static struct clkctl_acpu_speed  acpu_freq_tbl[] = {
+       { 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, VDD_0, 30720, 0, 0, 8 },
+       { 61440, ACPU_PLL_0,  4, 3, 61440,  0, VDD_0, 30720,  0, 0, 8 },
+       { 81920, ACPU_PLL_0,  4, 2, 40960,  1, VDD_0, 61440,  0, 0, 8 },
+       { 96000, ACPU_PLL_1,  1, 7, 48000,  1, VDD_0, 61440,  0, 0, 9 },
+       { 122880, ACPU_PLL_0, 4, 1, 61440,  1, VDD_3, 61440,  0, 0, 8 },
+       { 128000, ACPU_PLL_1, 1, 5, 64000,  1, VDD_3, 61440,  0, 0, 12 },
+       { 176000, ACPU_PLL_2, 2, 5, 88000,  1, VDD_3, 61440,  0, 0, 11 },
+       { 192000, ACPU_PLL_1, 1, 3, 64000,  2, VDD_3, 61440,  0, 0, 12 },
+       { 245760, ACPU_PLL_0, 4, 0, 81920,  2, VDD_4, 61440,  0, 0, 12 },
+       { 256000, ACPU_PLL_1, 1, 2, 128000, 2, VDD_5, 128000, 0, 0, 12 },
+       { 264000, ACPU_PLL_2, 2, 3, 88000,  2, VDD_5, 128000, 0, 6, 13 },
+       { 352000, ACPU_PLL_2, 2, 2, 88000,  3, VDD_5, 128000, 0, 6, 13 },
+       { 384000, ACPU_PLL_1, 1, 1, 128000, 2, VDD_6, 128000, 0, 5, -1 },
+       { 528000, ACPU_PLL_2, 2, 1, 132000, 3, VDD_7, 128000, 0, 11, -1 },
+       { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+#else /* Table of freq we currently use. */
+static struct clkctl_acpu_speed  acpu_freq_tbl[] = {
+       { 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, VDD_0, 30720, 0, 0, 4 },
+       { 122880, ACPU_PLL_0, 4, 1, 61440, 1, VDD_3, 61440, 0, 0, 4 },
+       { 128000, ACPU_PLL_1, 1, 5, 64000, 1, VDD_3, 61440, 0, 0, 6 },
+       { 176000, ACPU_PLL_2, 2, 5, 88000, 1, VDD_3, 61440, 0, 0, 5 },
+       { 245760, ACPU_PLL_0, 4, 0, 81920, 2, VDD_4, 61440, 0, 0, 5 },
+       { 352000, ACPU_PLL_2, 2, 2, 88000, 3, VDD_5, 128000, 0, 3, 7 },
+       { 384000, ACPU_PLL_1, 1, 1, 128000, 2, VDD_6, 128000, 0, 2, -1 },
+       { 528000, ACPU_PLL_2, 2, 1, 132000, 3, VDD_7, 128000, 0, 5, -1 },
+       { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+#endif
+
+
+#ifdef CONFIG_CPU_FREQ_TABLE
+static struct cpufreq_frequency_table freq_table[] = {
+       { 0, 122880 },
+       { 1, 128000 },
+       { 2, 245760 },
+       { 3, 384000 },
+       { 4, 528000 },
+       { 5, CPUFREQ_TABLE_END },
+};
+#endif
+
+static int pc_pll_request(unsigned id, unsigned on)
+{
+       int res;
+       on = !!on;
+
+#if PERF_SWITCH_DEBUG
+       if (on)
+               printk(KERN_DEBUG "Enabling PLL %d\n", id);
+       else
+               printk(KERN_DEBUG "Disabling PLL %d\n", id);
+#endif
+
+       res = msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on);
+       if (res < 0)
+               return res;
+
+#if PERF_SWITCH_DEBUG
+       if (on)
+               printk(KERN_DEBUG "PLL %d enabled\n", id);
+       else
+               printk(KERN_DEBUG "PLL %d disabled\n", id);
+#endif
+       return res;
+}
+
+
+/*----------------------------------------------------------------------------
+ * ARM11 'owned' clock control
+ *---------------------------------------------------------------------------*/
+
+unsigned long acpuclk_power_collapse(void) {
+       int ret = acpuclk_get_rate();
+       ret *= 1000;
+       if (ret > drv_state.power_collapse_khz)
+               acpuclk_set_rate(drv_state.power_collapse_khz, 1);
+       return ret;
+}
+
+unsigned long acpuclk_get_wfi_rate(void)
+{
+       return drv_state.wait_for_irq_khz;
+}
+
+unsigned long acpuclk_wait_for_irq(void) {
+       int ret = acpuclk_get_rate();
+       ret *= 1000;
+       if (ret > drv_state.wait_for_irq_khz)
+               acpuclk_set_rate(drv_state.wait_for_irq_khz, 1);
+       return ret;
+}
+
+static int acpuclk_set_vdd_level(int vdd)
+{
+       uint32_t current_vdd;
+
+       current_vdd = readl(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07;
+
+#if PERF_SWITCH_DEBUG
+       printk(KERN_DEBUG "acpuclock: Switching VDD from %u -> %d\n",
+              current_vdd, vdd);
+#endif
+       writel((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR);
+       udelay(drv_state.vdd_switch_time_us);
+       if ((readl(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) {
+#if PERF_SWITCH_DEBUG
+               printk(KERN_ERR "acpuclock: VDD set failed\n");
+#endif
+               return -EIO;
+       }
+
+#if PERF_SWITCH_DEBUG
+       printk(KERN_DEBUG "acpuclock: VDD switched\n");
+#endif
+       return 0;
+}
+
+/* Set proper dividers for the given clock speed. */
+static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s) {
+       uint32_t reg_clkctl, reg_clksel, clk_div;
+
+       /* AHB_CLK_DIV */
+       clk_div = (readl(A11S_CLK_SEL_ADDR) >> 1) & 0x03;
+       /*
+        * If the new clock divider is higher than the previous, then
+        * program the divider before switching the clock
+        */
+       if (hunt_s->ahbclk_div > clk_div) {
+               reg_clksel = readl(A11S_CLK_SEL_ADDR);
+               reg_clksel &= ~(0x3 << 1);
+               reg_clksel |= (hunt_s->ahbclk_div << 1);
+               writel(reg_clksel, A11S_CLK_SEL_ADDR);
+       }
+       if ((readl(A11S_CLK_SEL_ADDR) & 0x01) == 0) {
+               /* SRC0 */
+
+               /* Program clock source */
+               reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
+               reg_clkctl &= ~(0x07 << 4);
+               reg_clkctl |= (hunt_s->a11clk_src_sel << 4);
+               writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
+
+               /* Program clock divider */
+               reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
+               reg_clkctl &= ~0xf;
+               reg_clkctl |= hunt_s->a11clk_src_div;
+               writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
+
+               /* Program clock source selection */
+               reg_clksel = readl(A11S_CLK_SEL_ADDR);
+               reg_clksel |= 1; /* CLK_SEL_SRC1NO  == SRC1 */
+               writel(reg_clksel, A11S_CLK_SEL_ADDR);
+       } else {
+               /* SRC1 */
+
+               /* Program clock source */
+               reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
+               reg_clkctl &= ~(0x07 << 12);
+               reg_clkctl |= (hunt_s->a11clk_src_sel << 12);
+               writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
+
+               /* Program clock divider */
+               reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
+               reg_clkctl &= ~(0xf << 8);
+               reg_clkctl |= (hunt_s->a11clk_src_div << 8);
+               writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
+
+               /* Program clock source selection */
+               reg_clksel = readl(A11S_CLK_SEL_ADDR);
+               reg_clksel &= ~1; /* CLK_SEL_SRC1NO  == SRC0 */
+               writel(reg_clksel, A11S_CLK_SEL_ADDR);
+       }
+
+       /*
+        * If the new clock divider is lower than the previous, then
+        * program the divider after switching the clock
+        */
+       if (hunt_s->ahbclk_div < clk_div) {
+               reg_clksel = readl(A11S_CLK_SEL_ADDR);
+               reg_clksel &= ~(0x3 << 1);
+               reg_clksel |= (hunt_s->ahbclk_div << 1);
+               writel(reg_clksel, A11S_CLK_SEL_ADDR);
+       }
+}
+
+int acpuclk_set_rate(unsigned long rate, int for_power_collapse)
+{
+       uint32_t reg_clkctl;
+       struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s;
+       int rc = 0;
+       unsigned int plls_enabled = 0, pll;
+
+       strt_s = cur_s = drv_state.current_speed;
+
+       WARN_ONCE(cur_s == NULL, "acpuclk_set_rate: not initialized\n");
+       if (cur_s == NULL)
+               return -ENOENT;
+
+       if (rate == (cur_s->a11clk_khz * 1000))
+               return 0;
+
+       for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) {
+               if (tgt_s->a11clk_khz == (rate / 1000))
+                       break;
+       }
+
+       if (tgt_s->a11clk_khz == 0)
+               return -EINVAL;
+
+       /* Choose the highest speed speed at or below 'rate' with same PLL. */
+       if (for_power_collapse && tgt_s->a11clk_khz < cur_s->a11clk_khz) {
+               while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll)
+                       tgt_s--;
+       }
+
+       if (strt_s->pll != ACPU_PLL_TCXO)
+               plls_enabled |= 1 << strt_s->pll;
+
+       if (!for_power_collapse) {
+               mutex_lock(&drv_state.lock);
+               if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) {
+                       rc = pc_pll_request(tgt_s->pll, 1);
+                       if (rc < 0) {
+                               pr_err("PLL%d enable failed (%d)\n",
+                                       tgt_s->pll, rc);
+                               goto out;
+                       }
+                       plls_enabled |= 1 << tgt_s->pll;
+               }
+               /* Increase VDD if needed. */
+               if (tgt_s->vdd > cur_s->vdd) {
+                       if ((rc = acpuclk_set_vdd_level(tgt_s->vdd)) < 0) {
+                               printk(KERN_ERR "Unable to switch ACPU vdd\n");
+                               goto out;
+                       }
+               }
+       }
+
+       /* Set wait states for CPU inbetween frequency changes */
+       reg_clkctl = readl(A11S_CLK_CNTL_ADDR);
+       reg_clkctl |= (100 << 16); /* set WT_ST_CNT */
+       writel(reg_clkctl, A11S_CLK_CNTL_ADDR);
+
+#if PERF_SWITCH_DEBUG
+       printk(KERN_INFO "acpuclock: Switching from ACPU rate %u -> %u\n",
+              strt_s->a11clk_khz * 1000, tgt_s->a11clk_khz * 1000);
+#endif
+
+       while (cur_s != tgt_s) {
+               /*
+                * Always jump to target freq if within 256mhz, regulardless of
+                * PLL. If differnece is greater, use the predefinied
+                * steppings in the table.
+                */
+               int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz));
+               if (d > drv_state.max_speed_delta_khz) {
+                       /* Step up or down depending on target vs current. */
+                       int clk_index = tgt_s->a11clk_khz > cur_s->a11clk_khz ?
+                               cur_s->up : cur_s->down;
+                       if (clk_index < 0) { /* This should not happen. */
+                               printk(KERN_ERR "cur:%u target: %u\n",
+                                       cur_s->a11clk_khz, tgt_s->a11clk_khz);
+                               rc = -EINVAL;
+                               goto out;
+                       }
+                       cur_s = &acpu_freq_tbl[clk_index];
+               } else {
+                       cur_s = tgt_s;
+               }
+#if PERF_SWITCH_STEP_DEBUG
+               printk(KERN_DEBUG "%s: STEP khz = %u, pll = %d\n",
+                       __FUNCTION__, cur_s->a11clk_khz, cur_s->pll);
+#endif
+               if (!for_power_collapse&& cur_s->pll != ACPU_PLL_TCXO
+                   && !(plls_enabled & (1 << cur_s->pll))) {
+                       rc = pc_pll_request(cur_s->pll, 1);
+                       if (rc < 0) {
+                               pr_err("PLL%d enable failed (%d)\n",
+                                       cur_s->pll, rc);
+                               goto out;
+                       }
+                       plls_enabled |= 1 << cur_s->pll;
+               }
+
+               acpuclk_set_div(cur_s);
+               drv_state.current_speed = cur_s;
+               /* Re-adjust lpj for the new clock speed. */
+               loops_per_jiffy = cur_s->lpj;
+               udelay(drv_state.acpu_switch_time_us);
+       }
+
+       /* Nothing else to do for power collapse. */
+       if (for_power_collapse)
+               return 0;
+
+       /* Disable PLLs we are not using anymore. */
+       plls_enabled &= ~(1 << tgt_s->pll);
+       for (pll = ACPU_PLL_0; pll <= ACPU_PLL_2; pll++)
+               if (plls_enabled & (1 << pll)) {
+                       rc = pc_pll_request(pll, 0);
+                       if (rc < 0) {
+                               pr_err("PLL%d disable failed (%d)\n", pll, rc);
+                               goto out;
+                       }
+               }
+
+       /* Change the AXI bus frequency if we can. */
+       if (strt_s->axiclk_khz != tgt_s->axiclk_khz) {
+               rc = clk_set_rate(ebi1_clk, tgt_s->axiclk_khz * 1000);
+               if (rc < 0)
+                       pr_err("Setting AXI min rate failed!\n");
+       }
+
+       /* Drop VDD level if we can. */
+       if (tgt_s->vdd < strt_s->vdd) {
+               if (acpuclk_set_vdd_level(tgt_s->vdd) < 0)
+                       printk(KERN_ERR "acpuclock: Unable to drop ACPU vdd\n");
+       }
+
+#if PERF_SWITCH_DEBUG
+       printk(KERN_DEBUG "%s: ACPU speed change complete\n", __FUNCTION__);
+#endif
+out:
+       if (!for_power_collapse)
+               mutex_unlock(&drv_state.lock);
+       return rc;
+}
+
+static void __init acpuclk_init(void)
+{
+       struct clkctl_acpu_speed *speed;
+       uint32_t div, sel;
+       int rc;
+
+       /*
+        * Determine the rate of ACPU clock
+        */
+
+       if (!(readl(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */
+               /* CLK_SRC0_SEL */
+               sel = (readl(A11S_CLK_CNTL_ADDR) >> 12) & 0x7;
+               /* CLK_SRC0_DIV */
+               div = (readl(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f;
+       } else {
+               /* CLK_SRC1_SEL */
+               sel = (readl(A11S_CLK_CNTL_ADDR) >> 4) & 0x07;
+               /* CLK_SRC1_DIV */
+               div = readl(A11S_CLK_CNTL_ADDR) & 0x0f;
+       }
+
+       for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) {
+               if (speed->a11clk_src_sel == sel
+                && (speed->a11clk_src_div == div))
+                       break;
+       }
+       if (speed->a11clk_khz == 0) {
+               printk(KERN_WARNING "Warning - ACPU clock reports invalid speed\n");
+               return;
+       }
+
+       drv_state.current_speed = speed;
+
+       rc = clk_set_rate(ebi1_clk, speed->axiclk_khz * 1000);
+       if (rc < 0)
+               pr_err("Setting AXI min rate failed!\n");
+
+       printk(KERN_INFO "ACPU running at %d KHz\n", speed->a11clk_khz);
+}
+
+unsigned long acpuclk_get_rate(void)
+{
+       WARN_ONCE(drv_state.current_speed == NULL,
+                 "acpuclk_get_rate: not initialized\n");
+       if (drv_state.current_speed)
+               return drv_state.current_speed->a11clk_khz;
+       else
+               return 0;
+}
+
+uint32_t acpuclk_get_switch_time(void)
+{
+       return drv_state.acpu_switch_time_us;
+}
+
+/*----------------------------------------------------------------------------
+ * Clock driver initialization
+ *---------------------------------------------------------------------------*/
+
+/* Initalize the lpj field in the acpu_freq_tbl. */
+static void __init lpj_init(void)
+{
+       int i;
+       const struct clkctl_acpu_speed *base_clk = drv_state.current_speed;
+       for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) {
+               acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy,
+                                               base_clk->a11clk_khz,
+                                               acpu_freq_tbl[i].a11clk_khz);
+       }
+}
+
+void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *clkdata)
+{
+       pr_info("acpu_clock_init()\n");
+
+       ebi1_clk = clk_get(NULL, "ebi1_clk");
+
+       mutex_init(&drv_state.lock);
+       drv_state.acpu_switch_time_us = clkdata->acpu_switch_time_us;
+       drv_state.max_speed_delta_khz = clkdata->max_speed_delta_khz;
+       drv_state.vdd_switch_time_us = clkdata->vdd_switch_time_us;
+       drv_state.power_collapse_khz = clkdata->power_collapse_khz;
+       drv_state.wait_for_irq_khz = clkdata->wait_for_irq_khz;
+       acpuclk_init();
+       lpj_init();
+#ifdef CONFIG_CPU_FREQ_TABLE
+       cpufreq_frequency_table_get_attr(freq_table, smp_processor_id());
+#endif
+}
diff --git a/arch/arm/mach-msm/acpuclock.h b/arch/arm/mach-msm/acpuclock.h
new file mode 100644 (file)
index 0000000..415de2e
--- /dev/null
@@ -0,0 +1,32 @@
+/* arch/arm/mach-msm/acpuclock.h
+ *
+ * MSM architecture clock driver header
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2007 QUALCOMM Incorporated
+ * Author: San Mehat <san@android.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __ARCH_ARM_MACH_MSM_ACPUCLOCK_H
+#define __ARCH_ARM_MACH_MSM_ACPUCLOCK_H
+
+int acpuclk_set_rate(unsigned long rate, int for_power_collapse);
+unsigned long acpuclk_get_rate(void);
+uint32_t acpuclk_get_switch_time(void);
+unsigned long acpuclk_wait_for_irq(void);
+unsigned long acpuclk_power_collapse(void);
+unsigned long acpuclk_get_wfi_rate(void);
+
+
+#endif
+
index e61967d..7bd72e8 100644 (file)
@@ -26,6 +26,7 @@
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/mach/flash.h>
+#include <asm/setup.h>
 
 #include <mach/irqs.h>
 #include <mach/board.h>
@@ -77,14 +78,28 @@ static void __init halibut_init(void)
        platform_add_devices(devices, ARRAY_SIZE(devices));
 }
 
+static void __init halibut_fixup(struct machine_desc *desc, struct tag *tags,
+                                char **cmdline, struct meminfo *mi)
+{
+       mi->nr_banks=1;
+       mi->bank[0].start = PHYS_OFFSET;
+       mi->bank[0].node = PHYS_TO_NID(PHYS_OFFSET);
+       mi->bank[0].size = (101*1024*1024);
+}
+
 static void __init halibut_map_io(void)
 {
        msm_map_common_io();
-       msm_clock_init();
+       msm_clock_init(msm_clocks_7x01a, msm_num_clocks_7x01a);
 }
 
 MACHINE_START(HALIBUT, "Halibut Board (QCT SURF7200A)")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
        .boot_params    = 0x10000100,
+       .fixup          = halibut_fixup,
        .map_io         = halibut_map_io,
        .init_irq       = halibut_init_irq,
        .init_machine   = halibut_init,
diff --git a/arch/arm/mach-msm/board-mahimahi.c b/arch/arm/mach-msm/board-mahimahi.c
new file mode 100644 (file)
index 0000000..bcbefdf
--- /dev/null
@@ -0,0 +1,87 @@
+/* linux/arch/arm/mach-msm/board-mahimahi.c
+ *
+ * Copyright (C) 2009 Google, Inc.
+ * Copyright (C) 2009 HTC Corporation.
+ * Author: Dima Zavin <dima@android.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/setup.h>
+
+#include <mach/board.h>
+#include <mach/hardware.h>
+#include <mach/system.h>
+
+#include "board-mahimahi.h"
+#include "devices.h"
+#include "proc_comm.h"
+
+static uint debug_uart;
+
+module_param_named(debug_uart, debug_uart, uint, 0);
+
+static struct platform_device *devices[] __initdata = {
+#if !defined(CONFIG_MSM_SERIAL_DEBUGGER)
+       &msm_device_uart1,
+#endif
+       &msm_device_uart_dm1,
+       &msm_device_nand,
+};
+
+static void __init mahimahi_init(void)
+{
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+}
+
+static void __init mahimahi_fixup(struct machine_desc *desc, struct tag *tags,
+                                char **cmdline, struct meminfo *mi)
+{
+       mi->nr_banks = 2;
+       mi->bank[0].start = PHYS_OFFSET;
+       mi->bank[0].node = PHYS_TO_NID(PHYS_OFFSET);
+       mi->bank[0].size = (219*1024*1024);
+       mi->bank[1].start = MSM_HIGHMEM_BASE;
+       mi->bank[1].node = PHYS_TO_NID(MSM_HIGHMEM_BASE);
+       mi->bank[1].size = MSM_HIGHMEM_SIZE;
+}
+
+static void __init mahimahi_map_io(void)
+{
+       msm_map_common_io();
+       msm_clock_init();
+}
+
+extern struct sys_timer msm_timer;
+
+MACHINE_START(MAHIMAHI, "mahimahi")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = 0x20000100,
+       .fixup          = mahimahi_fixup,
+       .map_io         = mahimahi_map_io,
+       .init_irq       = msm_init_irq,
+       .init_machine   = mahimahi_init,
+       .timer          = &msm_timer,
+MACHINE_END
diff --git a/arch/arm/mach-msm/board-msm7x27.c b/arch/arm/mach-msm/board-msm7x27.c
new file mode 100644 (file)
index 0000000..cccb9f3
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/bootmem.h>
+#include <linux/power_supply.h>
+
+#include <mach/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/flash.h>
+#include <asm/setup.h>
+#ifdef CONFIG_CACHE_L2X0
+#include <asm/hardware/cache-l2x0.h>
+#endif
+
+#include <mach/vreg.h>
+#include <mach/mpp.h>
+#include <mach/gpio.h>
+#include <mach/board.h>
+#include <mach/msm_iomap.h>
+
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+
+#include "devices.h"
+#include "socinfo.h"
+#include "clock.h"
+
+static struct resource smc91x_resources[] = {
+       [0] = {
+               .start  = 0x9C004300,
+               .end    = 0x9C0043ff,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = MSM_GPIO_TO_INT(132),
+               .end    = MSM_GPIO_TO_INT(132),
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device smc91x_device = {
+       .name           = "smc91x",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(smc91x_resources),
+       .resource       = smc91x_resources,
+};
+
+static struct platform_device *devices[] __initdata = {
+       &msm_device_uart3,
+       &msm_device_smd,
+       &msm_device_dmov,
+       &msm_device_nand,
+       &smc91x_device,
+};
+
+extern struct sys_timer msm_timer;
+
+static void __init msm7x2x_init_irq(void)
+{
+       msm_init_irq();
+}
+
+static void __init msm7x2x_init(void)
+{
+       if (socinfo_init() < 0)
+               BUG();
+
+       if (machine_is_msm7x25_ffa() || machine_is_msm7x27_ffa()) {
+               smc91x_resources[0].start = 0x98000300;
+               smc91x_resources[0].end = 0x980003ff;
+               smc91x_resources[1].start = MSM_GPIO_TO_INT(85);
+               smc91x_resources[1].end = MSM_GPIO_TO_INT(85);
+               if (gpio_tlmm_config(GPIO_CFG(85, 0,
+                                             GPIO_INPUT,
+                                             GPIO_PULL_DOWN,
+                                             GPIO_2MA),
+                                    GPIO_ENABLE)) {
+                       printk(KERN_ERR
+                              "%s: Err: Config GPIO-85 INT\n",
+                               __func__);
+               }
+       }
+
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+}
+
+static void __init msm7x2x_map_io(void)
+{
+       msm_map_common_io();
+       /* Technically dependent on the SoC but using machine_is
+        * macros since socinfo is not available this early and there
+        * are plans to restructure the code which will eliminate the
+        * need for socinfo.
+        */
+       if (machine_is_msm7x27_surf() || machine_is_msm7x27_ffa())
+               msm_clock_init(msm_clocks_7x27, msm_num_clocks_7x27);
+
+       if (machine_is_msm7x25_surf() || machine_is_msm7x25_ffa())
+               msm_clock_init(msm_clocks_7x25, msm_num_clocks_7x25);
+
+#ifdef CONFIG_CACHE_L2X0
+       if (machine_is_msm7x27_surf() || machine_is_msm7x27_ffa()) {
+               /* 7x27 has 256KB L2 cache:
+                       64Kb/Way and 4-Way Associativity;
+                       R/W latency: 3 cycles;
+                       evmon/parity/share disabled. */
+               l2x0_init(MSM_L2CC_BASE, 0x00068012, 0xfe000000);
+       }
+#endif
+}
+
+MACHINE_START(MSM7X27_SURF, "QCT MSM7x27 SURF")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = msm7x2x_map_io,
+       .init_irq       = msm7x2x_init_irq,
+       .init_machine   = msm7x2x_init,
+       .timer          = &msm_timer,
+MACHINE_END
+
+MACHINE_START(MSM7X27_FFA, "QCT MSM7x27 FFA")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = msm7x2x_map_io,
+       .init_irq       = msm7x2x_init_irq,
+       .init_machine   = msm7x2x_init,
+       .timer          = &msm_timer,
+MACHINE_END
+
+MACHINE_START(MSM7X25_SURF, "QCT MSM7x25 SURF")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = msm7x2x_map_io,
+       .init_irq       = msm7x2x_init_irq,
+       .init_machine   = msm7x2x_init,
+       .timer          = &msm_timer,
+MACHINE_END
+
+MACHINE_START(MSM7X25_FFA, "QCT MSM7x25 FFA")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .map_io         = msm7x2x_map_io,
+       .init_irq       = msm7x2x_init_irq,
+       .init_machine   = msm7x2x_init,
+       .timer          = &msm_timer,
+MACHINE_END
diff --git a/arch/arm/mach-msm/board-msm7x30.c b/arch/arm/mach-msm/board-msm7x30.c
new file mode 100644 (file)
index 0000000..bac1f3c
--- /dev/null
@@ -0,0 +1,120 @@
+/* Copyright (c) 2009-2010, Code Aurora Forum. 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 version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/bootmem.h>
+#include <linux/io.h>
+#include <linux/smsc911x.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/setup.h>
+
+#include <mach/gpio.h>
+#include <mach/board.h>
+#include <mach/memory.h>
+#include <mach/msm_iomap.h>
+#include <mach/dma.h>
+
+#include <mach/vreg.h>
+#include "devices.h"
+#include "proc_comm.h"
+
+extern struct sys_timer msm_timer;
+
+#ifdef CONFIG_SERIAL_MSM_CONSOLE
+static struct msm_gpio uart2_config_data[] = {
+       { GPIO_CFG(49, 2, GPIO_OUTPUT,  GPIO_PULL_DOWN, GPIO_2MA), "UART2_RFR"},
+       { GPIO_CFG(50, 2, GPIO_INPUT,   GPIO_PULL_DOWN, GPIO_2MA), "UART2_CTS"},
+       { GPIO_CFG(51, 2, GPIO_INPUT,   GPIO_PULL_DOWN, GPIO_2MA), "UART2_Rx"},
+       { GPIO_CFG(52, 2, GPIO_OUTPUT,  GPIO_PULL_DOWN, GPIO_2MA), "UART2_Tx"},
+};
+
+static void msm7x30_init_uart2(void)
+{
+       msm_gpios_request_enable(uart2_config_data,
+                       ARRAY_SIZE(uart2_config_data));
+
+}
+#endif
+
+static struct platform_device *devices[] __initdata = {
+#if defined(CONFIG_SERIAL_MSM) || defined(CONFIG_MSM_SERIAL_DEBUGGER)
+        &msm_device_uart2,
+#endif
+
+};
+
+static void __init msm7x30_init_irq(void)
+{
+       msm_init_irq();
+}
+
+static void __init msm7x30_init(void)
+{
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+#ifdef CONFIG_SERIAL_MSM_CONSOLE
+       msm7x30_init_uart2();
+#endif
+
+}
+
+static void __init msm7x30_map_io(void)
+{
+       msm_map_msm7x30_io();
+       msm_clock_init(msm_clocks_7x30, msm_num_clocks_7x30);
+}
+
+MACHINE_START(MSM7X30_SURF, "QCT MSM7X30 SURF")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io  = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = msm7x30_map_io,
+       .init_irq = msm7x30_init_irq,
+       .init_machine = msm7x30_init,
+       .timer = &msm_timer,
+MACHINE_END
+
+MACHINE_START(MSM7X30_FFA, "QCT MSM7X30 FFA")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io  = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = msm7x30_map_io,
+       .init_irq = msm7x30_init_irq,
+       .init_machine = msm7x30_init,
+       .timer = &msm_timer,
+MACHINE_END
+
+MACHINE_START(MSM7X30_FLUID, "QCT MSM7X30 FLUID")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io  = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = msm7x30_map_io,
+       .init_irq = msm7x30_init_irq,
+       .init_machine = msm7x30_init,
+       .timer = &msm_timer,
+MACHINE_END
diff --git a/arch/arm/mach-msm/board-qsd8x50.c b/arch/arm/mach-msm/board-qsd8x50.c
new file mode 100644 (file)
index 0000000..ec46066
--- /dev/null
@@ -0,0 +1,94 @@
+/* Copyright (c) 2008-2009, Code Aurora Forum. 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 version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include <linux/kernel.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/bootmem.h>
+#include <linux/delay.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/io.h>
+#include <asm/setup.h>
+
+#include <mach/board.h>
+#include <mach/irqs.h>
+#include <mach/sirc.h>
+#include <mach/gpio.h>
+
+#include "devices.h"
+
+extern struct sys_timer msm_timer;
+
+static struct msm_gpio uart3_config_data[] = {
+       { GPIO_CFG(86, 1, GPIO_INPUT,   GPIO_PULL_DOWN, GPIO_2MA), "UART2_Rx"},
+       { GPIO_CFG(87, 1, GPIO_OUTPUT,  GPIO_PULL_DOWN, GPIO_2MA), "UART2_Tx"},
+};
+
+static struct platform_device *devices[] __initdata = {
+       &msm_device_uart3,
+};
+
+static void msm8x50_init_uart3(void)
+{
+       msm_gpios_request_enable(uart3_config_data,
+                               ARRAY_SIZE(uart3_config_data));
+}
+
+static void __init qsd8x50_map_io(void)
+{
+       msm_map_qsd8x50_io();
+       msm_clock_init(msm_clocks_8x50, msm_num_clocks_8x50);
+}
+
+static void __init qsd8x50_init_irq(void)
+{
+       msm_init_irq();
+       msm_init_sirc();
+}
+
+static void __init qsd8x50_init(void)
+{
+       msm8x50_init_uart3();
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+}
+
+MACHINE_START(QSD8X50_SURF, "QCT QSD8X50 SURF")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io  = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = qsd8x50_map_io,
+       .init_irq = qsd8x50_init_irq,
+       .init_machine = qsd8x50_init,
+       .timer = &msm_timer,
+MACHINE_END
+
+MACHINE_START(QSD8X50A_ST1_5, "QCT QSD8X50A ST1.5")
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io  = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = qsd8x50_map_io,
+       .init_irq = qsd8x50_init_irq,
+       .init_machine = qsd8x50_init,
+       .timer = &msm_timer,
+MACHINE_END
diff --git a/arch/arm/mach-msm/board-sapphire.c b/arch/arm/mach-msm/board-sapphire.c
new file mode 100644 (file)
index 0000000..2bc1b9d
--- /dev/null
@@ -0,0 +1,118 @@
+/* linux/arch/arm/mach-msm/board-sapphire.c
+ * Copyright (C) 2007-2009 HTC Corporation.
+ * Author: Thomas Tsai <thomas_tsai@htc.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+*/
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/sysdev.h>
+
+#include <linux/delay.h>
+
+#include <asm/gpio.h>
+#include <mach/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/flash.h>
+#include <asm/system.h>
+#include <mach/system.h>
+#include <mach/vreg.h>
+#include <mach/board.h>
+
+#include <asm/io.h>
+#include <asm/delay.h>
+#include <asm/setup.h>
+
+#include <linux/mtd/nand.h>
+#include <linux/mtd/partitions.h>
+
+#include "gpio_chip.h"
+#include "board-sapphire.h"
+#include "proc_comm.h"
+#include "devices.h"
+
+void msm_init_irq(void);
+void msm_init_gpio(void);
+
+static struct platform_device *devices[] __initdata = {
+       &msm_device_smd,
+       &msm_device_dmov,
+       &msm_device_nand,
+       &msm_device_uart1,
+       &msm_device_uart3,
+};
+
+extern struct sys_timer msm_timer;
+
+static void __init sapphire_init_irq(void)
+{
+       msm_init_irq();
+}
+
+static void __init sapphire_init(void)
+{
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+}
+
+static struct map_desc sapphire_io_desc[] __initdata = {
+       {
+               .virtual = SAPPHIRE_CPLD_BASE,
+               .pfn     = __phys_to_pfn(SAPPHIRE_CPLD_START),
+               .length  = SAPPHIRE_CPLD_SIZE,
+               .type    = MT_DEVICE_NONSHARED
+       }
+};
+
+static void __init sapphire_fixup(struct machine_desc *desc, struct tag *tags,
+                                 char **cmdline, struct meminfo *mi)
+{
+       int smi_sz = parse_tag_smi((const struct tag *)tags);
+
+       mi->nr_banks = 1;
+       mi->bank[0].start = PHYS_OFFSET;
+       mi->bank[0].node = PHYS_TO_NID(PHYS_OFFSET);
+       if (smi_sz == 32) {
+               mi->bank[0].size = (84*1024*1024);
+       } else if (smi_sz == 64) {
+               mi->bank[0].size = (101*1024*1024);
+       } else {
+               /* Give a default value when not get smi size */
+               smi_sz = 64;
+               mi->bank[0].size = (101*1024*1024);
+       }
+}
+
+static void __init sapphire_map_io(void)
+{
+       msm_map_common_io();
+       iotable_init(sapphire_io_desc, ARRAY_SIZE(sapphire_io_desc));
+       msm_clock_init();
+}
+
+MACHINE_START(SAPPHIRE, "sapphire")
+/* Maintainer: Brian Swetland <swetland@google.com> */
+#ifdef CONFIG_MSM_DEBUG_UART
+       .phys_io        = MSM_DEBUG_UART_PHYS,
+       .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
+       .boot_params    = PHYS_OFFSET + 0x100,
+       .fixup          = sapphire_fixup,
+       .map_io         = sapphire_map_io,
+       .init_irq       = sapphire_init_irq,
+       .init_machine   = sapphire_init,
+       .timer          = &msm_timer,
+MACHINE_END
similarity index 93%
rename from arch/arm/mach-msm/board-dream.c
rename to arch/arm/mach-msm/board-trout.c
index 21afa85..dca5a5f 100644 (file)
@@ -1,4 +1,4 @@
-/* linux/arch/arm/mach-msm/board-dream.c
+/* linux/arch/arm/mach-msm/board-trout.c
  *
  * Copyright (C) 2009 Google, Inc.
  * Author: Brian Swetland <swetland@google.com>
@@ -28,7 +28,7 @@
 #include <mach/msm_iomap.h>
 
 #include "devices.h"
-#include "board-dream.h"
+#include "board-trout.h"
 
 static struct platform_device *devices[] __initdata = {
        &msm_device_uart3,
@@ -78,12 +78,14 @@ static void __init trout_map_io(void)
        writeb(0x80, TROUT_CPLD_BASE + 0x00);
 #endif
 
-       msm_clock_init();
+       msm_clock_init(msm_clocks_7x01a, msm_num_clocks_7x01a);
 }
 
 MACHINE_START(TROUT, "HTC Dream")
+#ifdef CONFIG_MSM_DEBUG_UART
        .phys_io        = MSM_DEBUG_UART_PHYS,
        .io_pg_offst    = ((MSM_DEBUG_UART_BASE) >> 18) & 0xfffc,
+#endif
        .boot_params    = 0x10000100,
        .fixup          = trout_fixup,
        .map_io         = trout_map_io,
diff --git a/arch/arm/mach-msm/clock-7x01a.c b/arch/arm/mach-msm/clock-7x01a.c
deleted file mode 100644 (file)
index 62230a3..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/* arch/arm/mach-msm/clock-7x01a.c
- *
- * Clock tables for MSM7X01A
- *
- * Copyright (C) 2007 Google, Inc.
- * Copyright (c) 2007 QUALCOMM Incorporated
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * 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.
- *
- */
-
-#include <linux/kernel.h>
-#include <linux/platform_device.h>
-
-#include "clock.h"
-#include "devices.h"
-
-/* clock IDs used by the modem processor */
-
-#define ACPU_CLK       0   /* Applications processor clock */
-#define ADM_CLK                1   /* Applications data mover clock */
-#define ADSP_CLK       2   /* ADSP clock */
-#define EBI1_CLK       3   /* External bus interface 1 clock */
-#define EBI2_CLK       4   /* External bus interface 2 clock */
-#define ECODEC_CLK     5   /* External CODEC clock */
-#define EMDH_CLK       6   /* External MDDI host clock */
-#define GP_CLK         7   /* General purpose clock */
-#define GRP_CLK                8   /* Graphics clock */
-#define I2C_CLK                9   /* I2C clock */
-#define ICODEC_RX_CLK  10  /* Internal CODEX RX clock */
-#define ICODEC_TX_CLK  11  /* Internal CODEX TX clock */
-#define IMEM_CLK       12  /* Internal graphics memory clock */
-#define MDC_CLK                13  /* MDDI client clock */
-#define MDP_CLK                14  /* Mobile display processor clock */
-#define PBUS_CLK       15  /* Peripheral bus clock */
-#define PCM_CLK                16  /* PCM clock */
-#define PMDH_CLK       17  /* Primary MDDI host clock */
-#define SDAC_CLK       18  /* Stereo DAC clock */
-#define SDC1_CLK       19  /* Secure Digital Card clocks */
-#define SDC1_PCLK      20
-#define SDC2_CLK       21
-#define SDC2_PCLK      22
-#define SDC3_CLK       23
-#define SDC3_PCLK      24
-#define SDC4_CLK       25
-#define SDC4_PCLK      26
-#define TSIF_CLK       27  /* Transport Stream Interface clocks */
-#define TSIF_REF_CLK   28
-#define TV_DAC_CLK     29  /* TV clocks */
-#define TV_ENC_CLK     30
-#define UART1_CLK      31  /* UART clocks */
-#define UART2_CLK      32
-#define UART3_CLK      33
-#define UART1DM_CLK    34
-#define UART2DM_CLK    35
-#define USB_HS_CLK     36  /* High speed USB core clock */
-#define USB_HS_PCLK    37  /* High speed USB pbus clock */
-#define USB_OTG_CLK    38  /* Full speed USB clock */
-#define VDC_CLK                39  /* Video controller clock */
-#define VFE_CLK                40  /* Camera / Video Front End clock */
-#define VFE_MDC_CLK    41  /* VFE MDDI client clock */
-
-#define NR_CLKS                42
-
-#define CLOCK(clk_name, clk_id, clk_dev, clk_flags) {  \
-       .name = clk_name, \
-       .id = clk_id, \
-       .flags = clk_flags, \
-       .dev = clk_dev, \
-       }
-
-#define OFF CLKFLAG_AUTO_OFF
-#define MINMAX CLKFLAG_USE_MIN_MAX_TO_SET
-
-struct clk msm_clocks[] = {
-       CLOCK("adm_clk",        ADM_CLK,        NULL, 0),
-       CLOCK("adsp_clk",       ADSP_CLK,       NULL, 0),
-       CLOCK("ebi1_clk",       EBI1_CLK,       NULL, 0),
-       CLOCK("ebi2_clk",       EBI2_CLK,       NULL, 0),
-       CLOCK("ecodec_clk",     ECODEC_CLK,     NULL, 0),
-       CLOCK("emdh_clk",       EMDH_CLK,       NULL, OFF),
-       CLOCK("gp_clk",         GP_CLK,         NULL, 0),
-       CLOCK("grp_clk",        GRP_CLK,        NULL, OFF),
-       CLOCK("i2c_clk",        I2C_CLK,        &msm_device_i2c.dev, 0),
-       CLOCK("icodec_rx_clk",  ICODEC_RX_CLK,  NULL, 0),
-       CLOCK("icodec_tx_clk",  ICODEC_TX_CLK,  NULL, 0),
-       CLOCK("imem_clk",       IMEM_CLK,       NULL, OFF),
-       CLOCK("mdc_clk",        MDC_CLK,        NULL, 0),
-       CLOCK("mdp_clk",        MDP_CLK,        NULL, OFF),
-       CLOCK("pbus_clk",       PBUS_CLK,       NULL, 0),
-       CLOCK("pcm_clk",        PCM_CLK,        NULL, 0),
-       CLOCK("pmdh_clk",       PMDH_CLK,       NULL, OFF | MINMAX),
-       CLOCK("sdac_clk",       SDAC_CLK,       NULL, OFF),
-       CLOCK("sdc_clk",        SDC1_CLK,       &msm_device_sdc1.dev, OFF),
-       CLOCK("sdc_pclk",       SDC1_PCLK,      &msm_device_sdc1.dev, OFF),
-       CLOCK("sdc_clk",        SDC2_CLK,       &msm_device_sdc2.dev, OFF),
-       CLOCK("sdc_pclk",       SDC2_PCLK,      &msm_device_sdc2.dev, OFF),
-       CLOCK("sdc_clk",        SDC3_CLK,       &msm_device_sdc3.dev, OFF),
-       CLOCK("sdc_pclk",       SDC3_PCLK,      &msm_device_sdc3.dev, OFF),
-       CLOCK("sdc_clk",        SDC4_CLK,       &msm_device_sdc4.dev, OFF),
-       CLOCK("sdc_pclk",       SDC4_PCLK,      &msm_device_sdc4.dev, OFF),
-       CLOCK("tsif_clk",       TSIF_CLK,       NULL, 0),
-       CLOCK("tsif_ref_clk",   TSIF_REF_CLK,   NULL, 0),
-       CLOCK("tv_dac_clk",     TV_DAC_CLK,     NULL, 0),
-       CLOCK("tv_enc_clk",     TV_ENC_CLK,     NULL, 0),
-       CLOCK("uart_clk",       UART1_CLK,      &msm_device_uart1.dev, OFF),
-       CLOCK("uart_clk",       UART2_CLK,      &msm_device_uart2.dev, 0),
-       CLOCK("uart_clk",       UART3_CLK,      &msm_device_uart3.dev, OFF),
-       CLOCK("uart1dm_clk",    UART1DM_CLK,    NULL, OFF),
-       CLOCK("uart2dm_clk",    UART2DM_CLK,    NULL, 0),
-       CLOCK("usb_hs_clk",     USB_HS_CLK,     &msm_device_hsusb.dev, OFF),
-       CLOCK("usb_hs_pclk",    USB_HS_PCLK,    &msm_device_hsusb.dev, OFF),
-       CLOCK("usb_otg_clk",    USB_OTG_CLK,    NULL, 0),
-       CLOCK("vdc_clk",        VDC_CLK,        NULL, OFF | MINMAX),
-       CLOCK("vfe_clk",        VFE_CLK,        NULL, OFF),
-       CLOCK("vfe_mdc_clk",    VFE_MDC_CLK,    NULL, OFF),
-};
-
-unsigned msm_num_clocks = ARRAY_SIZE(msm_clocks);
diff --git a/arch/arm/mach-msm/clock-7x30.h b/arch/arm/mach-msm/clock-7x30.h
new file mode 100644 (file)
index 0000000..e16f72f
--- /dev/null
@@ -0,0 +1,168 @@
+/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __ARCH_ARM_MACH_MSM_CLOCK_7X30_H
+#define __ARCH_ARM_MACH_MSM_CLOCK_7X30_H
+
+enum {
+       L_7X30_NONE_CLK = -1,
+       L_7X30_ADM_CLK,
+       L_7X30_I2C_CLK,
+       L_7X30_I2C_2_CLK,
+       L_7X30_QUP_I2C_CLK,
+       L_7X30_UART1DM_CLK,
+       L_7X30_UART1DM_P_CLK,
+       L_7X30_UART2DM_CLK,
+       L_7X30_UART2DM_P_CLK,
+       L_7X30_EMDH_CLK,
+       L_7X30_EMDH_P_CLK,
+       L_7X30_PMDH_CLK,
+       L_7X30_PMDH_P_CLK,
+       L_7X30_GRP_2D_CLK,
+       L_7X30_GRP_2D_P_CLK,
+       L_7X30_GRP_3D_SRC_CLK,
+       L_7X30_GRP_3D_CLK,
+       L_7X30_GRP_3D_P_CLK,
+       L_7X30_IMEM_CLK,
+       L_7X30_SDC1_CLK,
+       L_7X30_SDC1_P_CLK,
+       L_7X30_SDC2_CLK,
+       L_7X30_SDC2_P_CLK,
+       L_7X30_SDC3_CLK,
+       L_7X30_SDC3_P_CLK,
+       L_7X30_SDC4_CLK,
+       L_7X30_SDC4_P_CLK,
+       L_7X30_MDP_CLK,
+       L_7X30_MDP_P_CLK,
+       L_7X30_MDP_LCDC_PCLK_CLK,
+       L_7X30_MDP_LCDC_PAD_PCLK_CLK,
+       L_7X30_MDP_VSYNC_CLK,
+       L_7X30_MI2S_CODEC_RX_M_CLK,
+       L_7X30_MI2S_CODEC_RX_S_CLK,
+       L_7X30_MI2S_CODEC_TX_M_CLK,
+       L_7X30_MI2S_CODEC_TX_S_CLK,
+       L_7X30_MI2S_M_CLK,
+       L_7X30_MI2S_S_CLK,
+       L_7X30_LPA_CODEC_CLK,
+       L_7X30_LPA_CORE_CLK,
+       L_7X30_LPA_P_CLK,
+       L_7X30_MIDI_CLK,
+       L_7X30_MDC_CLK,
+       L_7X30_ROTATOR_IMEM_CLK,
+       L_7X30_ROTATOR_P_CLK,
+       L_7X30_SDAC_M_CLK,
+       L_7X30_SDAC_CLK,
+       L_7X30_UART1_CLK,
+       L_7X30_UART2_CLK,
+       L_7X30_UART3_CLK,
+       L_7X30_TV_CLK,
+       L_7X30_TV_DAC_CLK,
+       L_7X30_TV_ENC_CLK,
+       L_7X30_HDMI_CLK,
+       L_7X30_TSIF_REF_CLK,
+       L_7X30_TSIF_P_CLK,
+       L_7X30_USB_HS_SRC_CLK,
+       L_7X30_USB_HS_CLK,
+       L_7X30_USB_HS_CORE_CLK,
+       L_7X30_USB_HS_P_CLK,
+       L_7X30_USB_HS2_CLK,
+       L_7X30_USB_HS2_CORE_CLK,
+       L_7X30_USB_HS2_P_CLK,
+       L_7X30_USB_HS3_CLK,
+       L_7X30_USB_HS3_CORE_CLK,
+       L_7X30_USB_HS3_P_CLK,
+       L_7X30_VFE_CLK,
+       L_7X30_VFE_P_CLK,
+       L_7X30_VFE_MDC_CLK,
+       L_7X30_VFE_CAMIF_CLK,
+       L_7X30_CAMIF_PAD_P_CLK,
+       L_7X30_CAM_M_CLK,
+       L_7X30_JPEG_CLK,
+       L_7X30_JPEG_P_CLK,
+       L_7X30_VPE_CLK,
+       L_7X30_MFC_CLK,
+       L_7X30_MFC_DIV2_CLK,
+       L_7X30_MFC_P_CLK,
+       L_7X30_SPI_CLK,
+       L_7X30_SPI_P_CLK,
+       L_7X30_CSI0_CLK,
+       L_7X30_CSI0_VFE_CLK,
+       L_7X30_CSI0_P_CLK,
+       L_7X30_CSI1_CLK,
+       L_7X30_CSI1_VFE_CLK,
+       L_7X30_CSI1_P_CLK,
+       L_7X30_GLBL_ROOT_CLK,
+
+       L_7X30_AXI_LI_VG_CLK,
+       L_7X30_AXI_LI_GRP_CLK,
+       L_7X30_AXI_LI_JPEG_CLK,
+       L_7X30_AXI_GRP_2D_CLK,
+       L_7X30_AXI_MFC_CLK,
+       L_7X30_AXI_VPE_CLK,
+       L_7X30_AXI_LI_VFE_CLK,
+       L_7X30_AXI_LI_APPS_CLK,
+       L_7X30_AXI_MDP_CLK,
+       L_7X30_AXI_IMEM_CLK,
+       L_7X30_AXI_LI_ADSP_A_CLK,
+       L_7X30_AXI_ROTATOR_CLK,
+
+       L_7X30_NR_CLKS
+};
+
+struct clk_ops;
+extern struct clk_ops clk_ops_7x30;
+
+struct clk_ops *clk_7x30_is_local(uint32_t id);
+int clk_7x30_init(void);
+
+void pll_enable(uint32_t pll);
+void pll_disable(uint32_t pll);
+
+extern int internal_pwr_rail_ctl_auto(unsigned rail_id, bool enable);
+
+#define CLK_7X30(clk_name, clk_id, clk_dev, clk_flags) {       \
+       .name = clk_name, \
+       .id = L_7X30_##clk_id, \
+       .remote_id = P_##clk_id, \
+       .flags = clk_flags, \
+       .dev = clk_dev, \
+       .dbg_name = #clk_id, \
+       }
+
+#define CLK_7X30S(clk_name, l_id, r_id, clk_dev, clk_flags) {  \
+       .name = clk_name, \
+       .id = L_7X30_##l_id, \
+       .remote_id = P_##r_id, \
+       .flags = clk_flags, \
+       .dev = clk_dev, \
+       .dbg_name = #l_id, \
+       }
+
+#endif
+
diff --git a/arch/arm/mach-msm/clock-pcom.c b/arch/arm/mach-msm/clock-pcom.c
new file mode 100644 (file)
index 0000000..a3b4562
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/err.h>
+#include <linux/ctype.h>
+#include <linux/stddef.h>
+#include <mach/clk.h>
+
+#include "proc_comm.h"
+#include "clock.h"
+
+/*
+ * glue for the proc_comm interface
+ */
+int pc_clk_enable(unsigned id)
+{
+       int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+void pc_clk_disable(unsigned id)
+{
+       msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
+}
+
+int pc_clk_reset(unsigned id, enum clk_reset_action action)
+{
+       int rc;
+
+       if (action == CLK_RESET_ASSERT)
+               rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
+       else
+               rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_DEASSERT, &id, NULL);
+
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+int pc_clk_set_rate(unsigned id, unsigned rate)
+{
+       /* The rate _might_ be rounded off to the nearest KHz value by the
+        * remote function. So a return value of 0 doesn't necessarily mean
+        * that the exact rate was set successfully.
+        */
+       int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+int pc_clk_set_min_rate(unsigned id, unsigned rate)
+{
+       int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+int pc_clk_set_max_rate(unsigned id, unsigned rate)
+{
+       int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+int pc_clk_set_flags(unsigned id, unsigned flags)
+{
+       int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_FLAGS, &id, &flags);
+       if (rc < 0)
+               return rc;
+       else
+               return (int)id < 0 ? -EINVAL : 0;
+}
+
+unsigned pc_clk_get_rate(unsigned id)
+{
+       if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
+               return 0;
+       else
+               return id;
+}
+
+unsigned pc_clk_is_enabled(unsigned id)
+{
+       if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
+               return 0;
+       else
+               return id;
+}
+
+long pc_clk_round_rate(unsigned id, unsigned rate)
+{
+
+       /* Not really supported; pc_clk_set_rate() does rounding on it's own. */
+       return rate;
+}
+
+struct clk_ops clk_ops_pcom = {
+       .enable = pc_clk_enable,
+       .disable = pc_clk_disable,
+       .auto_off = pc_clk_disable,
+       .reset = pc_clk_reset,
+       .set_rate = pc_clk_set_rate,
+       .set_min_rate = pc_clk_set_min_rate,
+       .set_max_rate = pc_clk_set_max_rate,
+       .set_flags = pc_clk_set_flags,
+       .get_rate = pc_clk_get_rate,
+       .is_enabled = pc_clk_is_enabled,
+       .round_rate = pc_clk_round_rate,
+};
diff --git a/arch/arm/mach-msm/clock-pcom.h b/arch/arm/mach-msm/clock-pcom.h
new file mode 100644 (file)
index 0000000..17d027b
--- /dev/null
@@ -0,0 +1,153 @@
+/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __ARCH_ARM_MACH_MSM_CLOCK_PCOM_H
+#define __ARCH_ARM_MACH_MSM_CLOCK_PCOM_H
+
+/* clock IDs used by the modem processor */
+
+#define P_ACPU_CLK     0   /* Applications processor clock */
+#define P_ADM_CLK      1   /* Applications data mover clock */
+#define P_ADSP_CLK     2   /* ADSP clock */
+#define P_EBI1_CLK     3   /* External bus interface 1 clock */
+#define P_EBI2_CLK     4   /* External bus interface 2 clock */
+#define P_ECODEC_CLK   5   /* External CODEC clock */
+#define P_EMDH_CLK     6   /* External MDDI host clock */
+#define P_GP_CLK       7   /* General purpose clock */
+#define P_GRP_3D_CLK   8   /* Graphics clock */
+#define P_I2C_CLK      9   /* I2C clock */
+#define P_ICODEC_RX_CLK        10  /* Internal CODEX RX clock */
+#define P_ICODEC_TX_CLK        11  /* Internal CODEX TX clock */
+#define P_IMEM_CLK     12  /* Internal graphics memory clock */
+#define P_MDC_CLK      13  /* MDDI client clock */
+#define P_MDP_CLK      14  /* Mobile display processor clock */
+#define P_PBUS_CLK     15  /* Peripheral bus clock */
+#define P_PCM_CLK      16  /* PCM clock */
+#define P_PMDH_CLK     17  /* Primary MDDI host clock */
+#define P_SDAC_CLK     18  /* Stereo DAC clock */
+#define P_SDC1_CLK     19  /* Secure Digital Card clocks */
+#define P_SDC1_P_CLK   20
+#define P_SDC2_CLK     21
+#define P_SDC2_P_CLK   22
+#define P_SDC3_CLK     23
+#define P_SDC3_P_CLK   24
+#define P_SDC4_CLK     25
+#define P_SDC4_P_CLK   26
+#define P_TSIF_CLK     27  /* Transport Stream Interface clocks */
+#define P_TSIF_REF_CLK 28
+#define P_TV_DAC_CLK   29  /* TV clocks */
+#define P_TV_ENC_CLK   30
+#define P_UART1_CLK    31  /* UART clocks */
+#define P_UART2_CLK    32
+#define P_UART3_CLK    33
+#define P_UART1DM_CLK  34
+#define P_UART2DM_CLK  35
+#define P_USB_HS_CLK   36  /* High speed USB core clock */
+#define P_USB_HS_P_CLK 37  /* High speed USB pbus clock */
+#define P_USB_OTG_CLK  38  /* Full speed USB clock */
+#define P_VDC_CLK      39  /* Video controller clock */
+#define P_VFE_MDC_CLK  40  /* Camera / Video Front End clock */
+#define P_VFE_CLK      41  /* VFE MDDI client clock */
+#define P_MDP_LCDC_PCLK_CLK    42
+#define P_MDP_LCDC_PAD_PCLK_CLK 43
+#define P_MDP_VSYNC_CLK        44
+#define P_SPI_CLK      45
+#define P_VFE_AXI_CLK  46
+#define P_USB_HS2_CLK  47  /* High speed USB 2 core clock */
+#define P_USB_HS2_P_CLK        48  /* High speed USB 2 pbus clock */
+#define P_USB_HS3_CLK  49  /* High speed USB 3 core clock */
+#define P_USB_HS3_P_CLK        50  /* High speed USB 3 pbus clock */
+#define P_GRP_3D_P_CLK 51  /* Graphics pbus clock */
+#define P_USB_PHY_CLK  52  /* USB PHY clock */
+#define P_USB_HS_CORE_CLK      53  /* High speed USB 1 core clock */
+#define P_USB_HS2_CORE_CLK     54  /* High speed USB 2 core clock */
+#define P_USB_HS3_CORE_CLK     55  /* High speed USB 3 core clock */
+#define P_CAM_M_CLK            56
+#define P_CAMIF_PAD_P_CLK      57
+#define P_GRP_2D_CLK           58
+#define P_GRP_2D_P_CLK         59
+#define P_I2S_CLK              60
+#define P_JPEG_CLK             61
+#define P_JPEG_P_CLK           62
+#define P_LPA_CODEC_CLK                63
+#define P_LPA_CORE_CLK         64
+#define P_LPA_P_CLK            65
+#define P_MDC_IO_CLK           66
+#define P_MDC_P_CLK            67
+#define P_MFC_CLK              68
+#define P_MFC_DIV2_CLK         69
+#define P_MFC_P_CLK            70
+#define P_QUP_I2C_CLK          71
+#define P_ROTATOR_IMEM_CLK     72
+#define P_ROTATOR_P_CLK                73
+#define P_VFE_CAMIF_CLK                74
+#define P_VFE_P_CLK            75
+#define P_VPE_CLK              76
+#define P_I2C_2_CLK            77
+#define P_MI2S_CODEC_RX_S_CLK  78
+#define P_MI2S_CODEC_RX_M_CLK  79
+#define P_MI2S_CODEC_TX_S_CLK  80
+#define P_MI2S_CODEC_TX_M_CLK  81
+#define P_PMDH_P_CLK           82
+#define P_EMDH_P_CLK           83
+#define P_SPI_P_CLK            84
+#define P_TSIF_P_CLK           85
+#define P_MDP_P_CLK            86
+#define P_SDAC_M_CLK           87
+#define P_MI2S_S_CLK           88
+#define P_MI2S_M_CLK           89
+#define P_AXI_ROTATOR_CLK      90
+#define P_HDMI_CLK             91
+#define P_CSI0_CLK             92
+#define P_CSI0_VFE_CLK         93
+#define P_CSI0_P_CLK           94
+#define P_CSI1_CLK             95
+#define P_CSI1_VFE_CLK         96
+#define P_CSI1_P_CLK           97
+#define P_GSBI_CLK             98
+#define P_GSBI_P_CLK           99
+
+#define P_NR_CLKS              100
+
+struct clk_ops;
+extern struct clk_ops clk_ops_pcom;
+
+int pc_clk_reset(unsigned id, enum clk_reset_action action);
+
+#define CLK_PCOM(clk_name, clk_id, clk_dev, clk_flags) {       \
+       .name = clk_name, \
+       .id = P_##clk_id, \
+       .remote_id = P_##clk_id, \
+       .ops = &clk_ops_pcom, \
+       .flags = clk_flags, \
+       .dev = clk_dev, \
+       .dbg_name = #clk_id, \
+       }
+
+#endif
index 3b1ce36..9cb1276 100644 (file)
@@ -1,7 +1,7 @@
 /* arch/arm/mach-msm/clock.c
  *
  * Copyright (C) 2007 Google, Inc.
- * Copyright (c) 2007 QUALCOMM Incorporated
+ * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/spinlock.h>
+#include <linux/debugfs.h>
+#include <linux/ctype.h>
+#include <linux/pm_qos_params.h>
+#include <mach/clk.h>
 
 #include "clock.h"
 #include "proc_comm.h"
+#include "clock-7x30.h"
 
 static DEFINE_MUTEX(clocks_mutex);
 static DEFINE_SPINLOCK(clocks_lock);
 static LIST_HEAD(clocks);
+struct clk *msm_clocks;
+unsigned msm_num_clocks;
 
 /*
- * glue for the proc_comm interface
+ * Bitmap of enabled clocks, excluding ACPU which is always
+ * enabled
  */
-static inline int pc_clk_enable(unsigned id)
-{
-       return msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
-}
-
-static inline void pc_clk_disable(unsigned id)
-{
-       msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
-}
-
-static inline int pc_clk_set_rate(unsigned id, unsigned rate)
-{
-       return msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
-}
-
-static inline int pc_clk_set_min_rate(unsigned id, unsigned rate)
-{
-       return msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
-}
-
-static inline int pc_clk_set_max_rate(unsigned id, unsigned rate)
-{
-       return msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
-}
-
-static inline int pc_clk_set_flags(unsigned id, unsigned flags)
-{
-       return msm_proc_comm(PCOM_CLKCTL_RPC_SET_FLAGS, &id, &flags);
-}
-
-static inline unsigned pc_clk_get_rate(unsigned id)
-{
-       if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
-               return 0;
-       else
-               return id;
-}
-
-static inline unsigned pc_clk_is_enabled(unsigned id)
-{
-       if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
-               return 0;
-       else
-               return id;
-}
-
-static inline int pc_pll_request(unsigned id, unsigned on)
-{
-       on = !!on;
-       return msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on);
-}
+static DECLARE_BITMAP(clock_map_enabled, NR_CLKS);
+static DEFINE_SPINLOCK(clock_map_lock);
 
 /*
  * Standard clock functions defined in include/linux/clk.h
@@ -119,8 +78,12 @@ int clk_enable(struct clk *clk)
        unsigned long flags;
        spin_lock_irqsave(&clocks_lock, flags);
        clk->count++;
-       if (clk->count == 1)
-               pc_clk_enable(clk->id);
+       if (clk->count == 1) {
+               clk->ops->enable(clk->id);
+               spin_lock(&clock_map_lock);
+               clock_map_enabled[BIT_WORD(clk->id)] |= BIT_MASK(clk->id);
+               spin_unlock(&clock_map_lock);
+       }
        spin_unlock_irqrestore(&clocks_lock, flags);
        return 0;
 }
@@ -132,31 +95,54 @@ void clk_disable(struct clk *clk)
        spin_lock_irqsave(&clocks_lock, flags);
        BUG_ON(clk->count == 0);
        clk->count--;
-       if (clk->count == 0)
-               pc_clk_disable(clk->id);
+       if (clk->count == 0) {
+               clk->ops->disable(clk->id);
+               spin_lock(&clock_map_lock);
+               clock_map_enabled[BIT_WORD(clk->id)] &= ~BIT_MASK(clk->id);
+               spin_unlock(&clock_map_lock);
+       }
        spin_unlock_irqrestore(&clocks_lock, flags);
 }
 EXPORT_SYMBOL(clk_disable);
 
+int clk_reset(struct clk *clk, enum clk_reset_action action)
+{
+       if (!clk->ops->reset)
+               clk->ops->reset = &pc_clk_reset;
+       return clk->ops->reset(clk->remote_id, action);
+}
+EXPORT_SYMBOL(clk_reset);
+
 unsigned long clk_get_rate(struct clk *clk)
 {
-       return pc_clk_get_rate(clk->id);
+       return clk->ops->get_rate(clk->id);
 }
 EXPORT_SYMBOL(clk_get_rate);
 
 int clk_set_rate(struct clk *clk, unsigned long rate)
 {
-       int ret;
-       if (clk->flags & CLKFLAG_USE_MIN_MAX_TO_SET) {
-               ret = pc_clk_set_max_rate(clk->id, rate);
-               if (ret)
-                       return ret;
-               return pc_clk_set_min_rate(clk->id, rate);
-       }
-       return pc_clk_set_rate(clk->id, rate);
+       return clk->ops->set_rate(clk->id, rate);
 }
 EXPORT_SYMBOL(clk_set_rate);
 
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+       return clk->ops->round_rate(clk->id, rate);
+}
+EXPORT_SYMBOL(clk_round_rate);
+
+int clk_set_min_rate(struct clk *clk, unsigned long rate)
+{
+       return clk->ops->set_min_rate(clk->id, rate);
+}
+EXPORT_SYMBOL(clk_set_min_rate);
+
+int clk_set_max_rate(struct clk *clk, unsigned long rate)
+{
+       return clk->ops->set_max_rate(clk->id, rate);
+}
+EXPORT_SYMBOL(clk_set_max_rate);
+
 int clk_set_parent(struct clk *clk, struct clk *parent)
 {
        return -ENOSYS;
@@ -173,22 +159,153 @@ int clk_set_flags(struct clk *clk, unsigned long flags)
 {
        if (clk == NULL || IS_ERR(clk))
                return -EINVAL;
-       return pc_clk_set_flags(clk->id, flags);
+       return clk->ops->set_flags(clk->id, flags);
 }
 EXPORT_SYMBOL(clk_set_flags);
 
+/* EBI1 is the only shared clock that several clients want to vote on as of
+ * this commit. If this changes in the future, then it might be better to
+ * make clk_min_rate handle the voting or make ebi1_clk_set_min_rate more
+ * generic to support different clocks.
+ */
+static struct clk *ebi1_clk;
 
-void __init msm_clock_init(void)
+static void __init set_clock_ops(struct clk *clk)
+{
+       if (!clk->ops) {
+               clk->ops = &clk_ops_pcom;
+               clk->id = clk->remote_id;
+       }
+}
+
+void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks)
 {
        unsigned n;
 
        spin_lock_init(&clocks_lock);
        mutex_lock(&clocks_mutex);
-       for (n = 0; n < msm_num_clocks; n++)
+       msm_clocks = clock_tbl;
+       msm_num_clocks = num_clocks;
+       for (n = 0; n < msm_num_clocks; n++) {
+               set_clock_ops(&msm_clocks[n]);
                list_add_tail(&msm_clocks[n].list, &clocks);
+       }
        mutex_unlock(&clocks_mutex);
+
+       ebi1_clk = clk_get(NULL, "ebi1_clk");
+       BUG_ON(ebi1_clk == NULL);
+
+}
+
+#if defined(CONFIG_DEBUG_FS)
+static struct clk *msm_clock_get_nth(unsigned index)
+{
+       if (index < msm_num_clocks)
+               return msm_clocks + index;
+       else
+               return 0;
+}
+
+static int clock_debug_rate_set(void *data, u64 val)
+{
+       struct clk *clock = data;
+       int ret;
+
+       /* Only increases to max rate will succeed, but that's actually good
+        * for debugging purposes. So we don't check for error. */
+       if (clock->flags & CLK_MAX)
+               clk_set_max_rate(clock, val);
+       if (clock->flags & CLK_MIN)
+               ret = clk_set_min_rate(clock, val);
+       else
+               ret = clk_set_rate(clock, val);
+       if (ret != 0)
+               printk(KERN_ERR "clk_set%s_rate failed (%d)\n",
+                       (clock->flags & CLK_MIN) ? "_min" : "", ret);
+       return ret;
+}
+
+static int clock_debug_rate_get(void *data, u64 *val)
+{
+       struct clk *clock = data;
+       *val = clk_get_rate(clock);
+       return 0;
+}
+
+static int clock_debug_enable_set(void *data, u64 val)
+{
+       struct clk *clock = data;
+       int rc = 0;
+
+       if (val)
+               rc = clock->ops->enable(clock->id);
+       else
+               clock->ops->disable(clock->id);
+
+       return rc;
 }
 
+static int clock_debug_enable_get(void *data, u64 *val)
+{
+       struct clk *clock = data;
+
+       *val = clock->ops->is_enabled(clock->id);
+
+       return 0;
+}
+
+static int clock_debug_local_get(void *data, u64 *val)
+{
+       struct clk *clock = data;
+
+       *val = clock->ops != &clk_ops_pcom;
+
+       return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
+                       clock_debug_rate_set, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
+                       clock_debug_enable_set, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get,
+                       NULL, "%llu\n");
+
+static int __init clock_debug_init(void)
+{
+       struct dentry *dent_rate, *dent_enable, *dent_local;
+       struct clk *clock;
+       unsigned n = 0;
+       char temp[50], *ptr;
+
+       dent_rate = debugfs_create_dir("clk_rate", 0);
+       if (IS_ERR(dent_rate))
+               return PTR_ERR(dent_rate);
+
+       dent_enable = debugfs_create_dir("clk_enable", 0);
+       if (IS_ERR(dent_enable))
+               return PTR_ERR(dent_enable);
+
+       dent_local = debugfs_create_dir("clk_local", NULL);
+       if (IS_ERR(dent_local))
+               return PTR_ERR(dent_local);
+
+       while ((clock = msm_clock_get_nth(n++)) != 0) {
+               strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
+               for (ptr = temp; *ptr; ptr++)
+                       *ptr = tolower(*ptr);
+               debugfs_create_file(temp, 0644, dent_rate,
+                                   clock, &clock_rate_fops);
+               debugfs_create_file(temp, 0644, dent_enable,
+                                   clock, &clock_enable_fops);
+               debugfs_create_file(temp, S_IRUGO, dent_local,
+                                   clock, &clock_local_fops);
+       }
+       return 0;
+}
+
+device_initcall(clock_debug_init);
+#endif
+
 /* The bootloader and/or AMSS may have left various clocks enabled.
  * Disable any clocks that belong to us (CLKFLAG_AUTO_OFF) but have
  * not been explicitly enabled by a clk_enable() call.
@@ -205,7 +322,7 @@ static int __init clock_late_init(void)
                        spin_lock_irqsave(&clocks_lock, flags);
                        if (!clk->count) {
                                count++;
-                               pc_clk_disable(clk->id);
+                               clk->ops->auto_off(clk->id);
                        }
                        spin_unlock_irqrestore(&clocks_lock, flags);
                }
@@ -216,3 +333,4 @@ static int __init clock_late_init(void)
 }
 
 late_initcall(clock_late_init);
+
index f875e15..c270b55 100644 (file)
@@ -1,7 +1,7 @@
 /* arch/arm/mach-msm/clock.h
  *
  * Copyright (C) 2007 Google, Inc.
- * Copyright (c) 2007 QUALCOMM Incorporated
+ * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
 #define __ARCH_ARM_MACH_MSM_CLOCK_H
 
 #include <linux/list.h>
+#include <mach/clk.h>
+
+#include "clock-pcom.h"
+#include "clock-7x30.h"
 
 #define CLKFLAG_INVERT                 0x00000001
 #define CLKFLAG_NOINVERT               0x00000002
 #define CLKFLAG_NORESET                        0x00000008
 
 #define CLK_FIRST_AVAILABLE_FLAG       0x00000100
-#define CLKFLAG_USE_MIN_MAX_TO_SET     0x00000200
-#define CLKFLAG_AUTO_OFF               0x00000400
+#define CLKFLAG_AUTO_OFF               0x00000200
+#define CLKFLAG_MIN                    0x00000400
+#define CLKFLAG_MAX                    0x00000800
+
+struct clk_ops {
+       int (*enable)(unsigned id);
+       void (*disable)(unsigned id);
+       void (*auto_off)(unsigned id);
+       int (*reset)(unsigned id, enum clk_reset_action action);
+       int (*set_rate)(unsigned id, unsigned rate);
+       int (*set_min_rate)(unsigned id, unsigned rate);
+       int (*set_max_rate)(unsigned id, unsigned rate);
+       int (*set_flags)(unsigned id, unsigned flags);
+       unsigned (*get_rate)(unsigned id);
+       unsigned (*is_enabled)(unsigned id);
+       long (*round_rate)(unsigned id, unsigned rate);
+};
 
 struct clk {
        uint32_t id;
+       uint32_t remote_id;
        uint32_t count;
        uint32_t flags;
        const char *name;
+       struct clk_ops *ops;
+       const char *dbg_name;
        struct list_head list;
        struct device *dev;
 };
@@ -41,8 +63,47 @@ struct clk {
 #define A11S_CLK_SEL_ADDR              (MSM_CSR_BASE + 0x104)
 #define A11S_VDD_SVS_PLEVEL_ADDR       (MSM_CSR_BASE + 0x124)
 
-extern struct clk msm_clocks[];
-extern unsigned msm_num_clocks;
+#ifdef CONFIG_DEBUG_FS
+#define CLOCK_DBG_NAME(x) .dbg_name = x,
+#else
+#define CLOCK_DBG_NAME(x)
+#endif
+
+#define CLOCK(clk_name, clk_id, clk_dev, clk_flags) {  \
+       .name = clk_name, \
+       .id = clk_id, \
+       .flags = clk_flags, \
+       .dev = clk_dev, \
+        CLOCK_DBG_NAME(#clk_id) \
+       }
+
+#define OFF CLKFLAG_AUTO_OFF
+#define CLK_MIN CLKFLAG_MIN
+#define CLK_MAX CLKFLAG_MAX
+#define CLK_MINMAX (CLK_MIN | CLK_MAX)
+#define NR_CLKS        P_NR_CLKS
+
+enum {
+       PLL_0 = 0,
+       PLL_1,
+       PLL_2,
+       PLL_3,
+       PLL_4,
+       PLL_5,
+       PLL_6,
+       NUM_PLL
+};
+
+enum clkvote_client {
+       CLKVOTE_ACPUCLK = 0,
+       CLKVOTE_PMQOS,
+       CLKVOTE_MAX,
+};
+
+int msm_clock_require_tcxo(unsigned long *reason, int nbits);
+int msm_clock_get_name(uint32_t id, char *name, uint32_t size);
+int ebi1_clk_set_min_rate(enum clkvote_client client, unsigned long rate);
+unsigned long clk_get_max_axi_khz(void);
 
 #endif
 
similarity index 58%
rename from arch/arm/mach-msm/devices.c
rename to arch/arm/mach-msm/devices-msm7x00.c
index 31b6b30..fde9d8f 100644 (file)
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
 
+
+#include "clock.h"
+#include <mach/mmc.h>
+
 static struct resource resources_uart1[] = {
        {
                .start  = INT_UART1,
@@ -163,8 +167,19 @@ static struct resource resources_sdc1[] = {
        },
        {
                .start  = INT_SDC1_0,
+               .end    = INT_SDC1_0,
+               .flags  = IORESOURCE_IRQ,
+               .name   = "cmd_irq",
+       },
+       {
+               .start  = INT_SDC1_1,
                .end    = INT_SDC1_1,
                .flags  = IORESOURCE_IRQ,
+               .name   = "pio_irq",
+       },
+       {
+               .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
+               .name   = "status_irq"
        },
        {
                .start  = 8,
@@ -181,8 +196,19 @@ static struct resource resources_sdc2[] = {
        },
        {
                .start  = INT_SDC2_0,
+               .end    = INT_SDC2_0,
+               .flags  = IORESOURCE_IRQ,
+               .name   = "cmd_irq",
+       },
+               {
+               .start  = INT_SDC2_1,
                .end    = INT_SDC2_1,
                .flags  = IORESOURCE_IRQ,
+               .name   = "pio_irq",
+       },
+       {
+               .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
+               .name   = "status_irq"
        },
        {
                .start  = 8,
@@ -199,8 +225,19 @@ static struct resource resources_sdc3[] = {
        },
        {
                .start  = INT_SDC3_0,
+               .end    = INT_SDC3_0,
+               .flags  = IORESOURCE_IRQ,
+               .name   = "cmd_irq",
+       },
+               {
+               .start  = INT_SDC3_1,
                .end    = INT_SDC3_1,
                .flags  = IORESOURCE_IRQ,
+               .name   = "pio_irq",
+       },
+       {
+               .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
+               .name   = "status_irq"
        },
        {
                .start  = 8,
@@ -217,8 +254,19 @@ static struct resource resources_sdc4[] = {
        },
        {
                .start  = INT_SDC4_0,
+               .end    = INT_SDC4_0,
+               .flags  = IORESOURCE_IRQ,
+               .name   = "cmd_irq",
+       },
+               {
+               .start  = INT_SDC4_1,
                .end    = INT_SDC4_1,
                .flags  = IORESOURCE_IRQ,
+               .name   = "pio_irq",
+       },
+       {
+               .flags  = IORESOURCE_IRQ | IORESOURCE_DISABLED,
+               .name   = "status_irq"
        },
        {
                .start  = 8,
@@ -266,3 +314,80 @@ struct platform_device msm_device_sdc4 = {
                .coherent_dma_mask      = 0xffffffff,
        },
 };
+
+static struct platform_device *msm_sdcc_devices[] __initdata = {
+       &msm_device_sdc1,
+       &msm_device_sdc2,
+       &msm_device_sdc3,
+       &msm_device_sdc4,
+};
+
+int __init msm_add_sdcc(unsigned int controller, struct mmc_platform_data *plat,
+                       unsigned int stat_irq, unsigned long stat_irq_flags)
+{
+       struct platform_device  *pdev;
+       struct resource *res;
+
+       if (controller < 1 || controller > 4)
+               return -EINVAL;
+
+       pdev = msm_sdcc_devices[controller-1];
+       pdev->dev.platform_data = plat;
+
+       res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "status_irq");
+       if (!res)
+               return -EINVAL;
+       else if (stat_irq) {
+               res->start = res->end = stat_irq;
+               res->flags &= ~IORESOURCE_DISABLED;
+               res->flags |= stat_irq_flags;
+       }
+
+       return platform_device_register(pdev);
+}
+
+struct clk msm_clocks_7x01a[] = {
+       CLK_PCOM("adm_clk",     ADM_CLK,        NULL, 0),
+       CLK_PCOM("adsp_clk",    ADSP_CLK,       NULL, 0),
+       CLK_PCOM("ebi1_clk",    EBI1_CLK,       NULL, 0),
+       CLK_PCOM("ebi2_clk",    EBI2_CLK,       NULL, 0),
+       CLK_PCOM("ecodec_clk",  ECODEC_CLK,     NULL, 0),
+       CLK_PCOM("emdh_clk",    EMDH_CLK,       NULL, OFF),
+       CLK_PCOM("gp_clk",              GP_CLK,         NULL, 0),
+       CLK_PCOM("grp_clk",     GRP_3D_CLK,     NULL, OFF),
+       CLK_PCOM("i2c_clk",     I2C_CLK,        &msm_device_i2c.dev, 0),
+       CLK_PCOM("icodec_rx_clk",       ICODEC_RX_CLK,  NULL, 0),
+       CLK_PCOM("icodec_tx_clk",       ICODEC_TX_CLK,  NULL, 0),
+       CLK_PCOM("imem_clk",    IMEM_CLK,       NULL, OFF),
+       CLK_PCOM("mdc_clk",     MDC_CLK,        NULL, 0),
+       CLK_PCOM("mdp_clk",     MDP_CLK,        NULL, OFF),
+       CLK_PCOM("pbus_clk",    PBUS_CLK,       NULL, 0),
+       CLK_PCOM("pcm_clk",     PCM_CLK,        NULL, 0),
+       CLK_PCOM("pmdh_clk",    PMDH_CLK,       NULL, OFF ),
+       CLK_PCOM("sdac_clk",    SDAC_CLK,       NULL, OFF),
+       CLK_PCOM("sdc_clk",     SDC1_CLK,       &msm_device_sdc1.dev, OFF),
+       CLK_PCOM("sdc_pclk",    SDC1_P_CLK,     &msm_device_sdc1.dev, OFF),
+       CLK_PCOM("sdc_clk",     SDC2_CLK,       &msm_device_sdc2.dev, OFF),
+       CLK_PCOM("sdc_pclk",    SDC2_P_CLK,     &msm_device_sdc2.dev, OFF),
+       CLK_PCOM("sdc_clk",     SDC3_CLK,       &msm_device_sdc3.dev, OFF),
+       CLK_PCOM("sdc_pclk",    SDC3_P_CLK,     &msm_device_sdc3.dev, OFF),
+       CLK_PCOM("sdc_clk",     SDC4_CLK,       &msm_device_sdc4.dev, OFF),
+       CLK_PCOM("sdc_pclk",    SDC4_P_CLK,     &msm_device_sdc4.dev, OFF),
+       CLK_PCOM("tsif_clk",    TSIF_CLK,       NULL, 0),
+       CLK_PCOM("tsif_ref_clk",        TSIF_REF_CLK,   NULL, 0),
+       CLK_PCOM("tv_dac_clk",  TV_DAC_CLK,     NULL, 0),
+       CLK_PCOM("tv_enc_clk",  TV_ENC_CLK,     NULL, 0),
+       CLK_PCOM("uart_clk",    UART1_CLK,      &msm_device_uart1.dev, OFF),
+       CLK_PCOM("uart_clk",    UART2_CLK,      &msm_device_uart2.dev, 0),
+       CLK_PCOM("uart_clk",    UART3_CLK,      &msm_device_uart3.dev, OFF),
+       CLK_PCOM("uart1dm_clk", UART1DM_CLK,    NULL, OFF),
+       CLK_PCOM("uart2dm_clk", UART2DM_CLK,    NULL, 0),
+       CLK_PCOM("usb_hs_clk",  USB_HS_CLK,     &msm_device_hsusb.dev, OFF),
+       CLK_PCOM("usb_hs_pclk", USB_HS_P_CLK,   &msm_device_hsusb.dev, OFF),
+       CLK_PCOM("usb_otg_clk", USB_OTG_CLK,    NULL, 0),
+       CLK_PCOM("vdc_clk",     VDC_CLK,        NULL, OFF ),
+       CLK_PCOM("vfe_clk",     VFE_CLK,        NULL, OFF),
+       CLK_PCOM("vfe_mdc_clk", VFE_MDC_CLK,    NULL, OFF),
+};
+
+unsigned msm_num_clocks_7x01a = ARRAY_SIZE(msm_clocks_7x01a);
diff --git a/arch/arm/mach-msm/devices-msm7x30.c b/arch/arm/mach-msm/devices-msm7x30.c
new file mode 100644 (file)
index 0000000..b449e8a
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2008 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <linux/dma-mapping.h>
+#include <mach/irqs.h>
+#include <mach/msm_iomap.h>
+#include <mach/dma.h>
+#include <mach/board.h>
+
+#include "devices.h"
+#include "smd_private.h"
+
+#include <asm/mach/flash.h>
+
+#include "clock-pcom.h"
+
+#include <mach/mmc.h>
+
+static struct resource resources_uart2[] = {
+       {
+               .start  = INT_UART2,
+               .end    = INT_UART2,
+               .flags  = IORESOURCE_IRQ,
+       },
+       {
+               .start  = MSM_UART2_PHYS,
+               .end    = MSM_UART2_PHYS + MSM_UART2_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device msm_device_uart2 = {
+       .name   = "msm_serial",
+       .id     = 1,
+       .num_resources  = ARRAY_SIZE(resources_uart2),
+       .resource       = resources_uart2,
+};
+
+struct clk msm_clocks_7x30[] = {
+       CLK_PCOM("adm_clk",     ADM_CLK,        NULL, 0),
+       CLK_PCOM("adsp_clk",    ADSP_CLK,       NULL, 0),
+       CLK_PCOM("cam_m_clk",   CAM_M_CLK,      NULL, 0),
+       CLK_PCOM("camif_pad_pclk",      CAMIF_PAD_P_CLK,        NULL, OFF),
+       CLK_PCOM("ebi1_clk",    EBI1_CLK,       NULL, CLK_MIN),
+       CLK_PCOM("ecodec_clk",  ECODEC_CLK,     NULL, 0),
+       CLK_PCOM("emdh_clk",    EMDH_CLK,       NULL, OFF | CLK_MINMAX),
+       CLK_PCOM("emdh_pclk",   EMDH_P_CLK,     NULL, OFF),
+       CLK_PCOM("gp_clk",      GP_CLK,         NULL, 0),
+       CLK_PCOM("grp_2d_clk",  GRP_2D_CLK,     NULL, 0),
+       CLK_PCOM("grp_2d_pclk", GRP_2D_P_CLK,   NULL, 0),
+       CLK_PCOM("grp_clk",     GRP_3D_CLK,     NULL, 0),
+       CLK_PCOM("grp_pclk",    GRP_3D_P_CLK,   NULL, 0),
+       CLK_7X30S("grp_src_clk", GRP_3D_SRC_CLK, GRP_3D_CLK,    NULL, 0),
+       CLK_PCOM("hdmi_clk",    HDMI_CLK,       NULL, 0),
+       CLK_PCOM("imem_clk",    IMEM_CLK,       NULL, OFF),
+       CLK_PCOM("jpeg_clk",    JPEG_CLK,       NULL, OFF),
+       CLK_PCOM("jpeg_pclk",   JPEG_P_CLK,     NULL, OFF),
+       CLK_PCOM("lpa_codec_clk",       LPA_CODEC_CLK,          NULL, 0),
+       CLK_PCOM("lpa_core_clk",        LPA_CORE_CLK,           NULL, 0),
+       CLK_PCOM("lpa_pclk",            LPA_P_CLK,              NULL, 0),
+       CLK_PCOM("mdc_clk",     MDC_CLK,        NULL, 0),
+       CLK_PCOM("mddi_clk",    PMDH_CLK,       NULL, OFF | CLK_MINMAX),
+       CLK_PCOM("mddi_pclk",   PMDH_P_CLK,     NULL, 0),
+       CLK_PCOM("mdp_clk",     MDP_CLK,        NULL, OFF),
+       CLK_PCOM("mdp_pclk",    MDP_P_CLK,      NULL, 0),
+       CLK_PCOM("mdp_lcdc_pclk_clk", MDP_LCDC_PCLK_CLK, NULL, 0),
+       CLK_PCOM("mdp_lcdc_pad_pclk_clk", MDP_LCDC_PAD_PCLK_CLK, NULL, 0),
+       CLK_PCOM("mdp_vsync_clk",       MDP_VSYNC_CLK,  NULL, 0),
+       CLK_PCOM("mfc_clk",             MFC_CLK,                NULL, 0),
+       CLK_PCOM("mfc_div2_clk",        MFC_DIV2_CLK,           NULL, 0),
+       CLK_PCOM("mfc_pclk",            MFC_P_CLK,              NULL, 0),
+       CLK_PCOM("mi2s_m_clk",          MI2S_M_CLK,             NULL, 0),
+       CLK_PCOM("mi2s_s_clk",          MI2S_S_CLK,             NULL, 0),
+       CLK_PCOM("mi2s_codec_rx_m_clk", MI2S_CODEC_RX_M_CLK,  NULL, 0),
+       CLK_PCOM("mi2s_codec_rx_s_clk", MI2S_CODEC_RX_S_CLK,  NULL, 0),
+       CLK_PCOM("mi2s_codec_tx_m_clk", MI2S_CODEC_TX_M_CLK,  NULL, 0),
+       CLK_PCOM("mi2s_codec_tx_s_clk", MI2S_CODEC_TX_S_CLK,  NULL, 0),
+       CLK_PCOM("pbus_clk",    PBUS_CLK,       NULL, CLK_MIN),
+       CLK_PCOM("pcm_clk",     PCM_CLK,        NULL, 0),
+       CLK_PCOM("rotator_clk", AXI_ROTATOR_CLK,                NULL, 0),
+       CLK_PCOM("rotator_imem_clk",    ROTATOR_IMEM_CLK,       NULL, OFF),
+       CLK_PCOM("rotator_pclk",        ROTATOR_P_CLK,          NULL, OFF),
+       CLK_PCOM("sdac_clk",    SDAC_CLK,       NULL, OFF),
+       CLK_PCOM("spi_clk",     SPI_CLK,        NULL, 0),
+       CLK_PCOM("spi_pclk",    SPI_P_CLK,      NULL, 0),
+       CLK_7X30S("tv_src_clk", TV_CLK,         TV_ENC_CLK,     NULL, 0),
+       CLK_PCOM("tv_dac_clk",  TV_DAC_CLK,     NULL, 0),
+       CLK_PCOM("tv_enc_clk",  TV_ENC_CLK,     NULL, 0),
+       CLK_PCOM("uart_clk",    UART2_CLK,      &msm_device_uart2.dev, 0),
+       CLK_PCOM("usb_hs_clk",          USB_HS_CLK,             NULL, OFF),
+       CLK_PCOM("usb_hs_pclk",         USB_HS_P_CLK,           NULL, OFF),
+       CLK_PCOM("usb_hs_core_clk",     USB_HS_CORE_CLK,        NULL, OFF),
+       CLK_PCOM("usb_hs2_clk",         USB_HS2_CLK,            NULL, OFF),
+       CLK_PCOM("usb_hs2_pclk",        USB_HS2_P_CLK,          NULL, OFF),
+       CLK_PCOM("usb_hs2_core_clk",    USB_HS2_CORE_CLK,       NULL, OFF),
+       CLK_PCOM("usb_hs3_clk",         USB_HS3_CLK,            NULL, OFF),
+       CLK_PCOM("usb_hs3_pclk",        USB_HS3_P_CLK,          NULL, OFF),
+       CLK_PCOM("usb_hs3_core_clk",    USB_HS3_CORE_CLK,       NULL, OFF),
+       CLK_PCOM("vdc_clk",     VDC_CLK,        NULL, OFF | CLK_MIN),
+       CLK_PCOM("vfe_camif_clk",       VFE_CAMIF_CLK,  NULL, 0),
+       CLK_PCOM("vfe_clk",     VFE_CLK,        NULL, 0),
+       CLK_PCOM("vfe_mdc_clk", VFE_MDC_CLK,    NULL, 0),
+       CLK_PCOM("vfe_pclk",    VFE_P_CLK,      NULL, OFF),
+       CLK_PCOM("vpe_clk",     VPE_CLK,        NULL, 0),
+
+       /* 7x30 v2 hardware only. */
+       CLK_PCOM("csi_clk",     CSI0_CLK,       NULL, 0),
+       CLK_PCOM("csi_pclk",    CSI0_P_CLK,     NULL, 0),
+       CLK_PCOM("csi_vfe_clk", CSI0_VFE_CLK,   NULL, 0),
+};
+
+unsigned msm_num_clocks_7x30 = ARRAY_SIZE(msm_clocks_7x30);
+
diff --git a/arch/arm/mach-msm/devices-qsd8x50.c b/arch/arm/mach-msm/devices-qsd8x50.c
new file mode 100644 (file)
index 0000000..4d4a507
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2008 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <linux/dma-mapping.h>
+#include <mach/irqs.h>
+#include <mach/msm_iomap.h>
+#include <mach/dma.h>
+#include <mach/board.h>
+
+#include "devices.h"
+
+#include <asm/mach/flash.h>
+
+#include <mach/mmc.h>
+
+static struct resource resources_uart3[] = {
+       {
+               .start  = INT_UART3,
+               .end    = INT_UART3,
+               .flags  = IORESOURCE_IRQ,
+       },
+       {
+               .start  = MSM_UART3_PHYS,
+               .end    = MSM_UART3_PHYS + MSM_UART3_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device msm_device_uart3 = {
+       .name   = "msm_serial",
+       .id     = 2,
+       .num_resources  = ARRAY_SIZE(resources_uart3),
+       .resource       = resources_uart3,
+};
+
+struct clk msm_clocks_8x50[] = {
+       CLK_PCOM("adm_clk",     ADM_CLK,        NULL, 0),
+       CLK_PCOM("ebi1_clk",    EBI1_CLK,       NULL, CLK_MIN),
+       CLK_PCOM("ebi2_clk",    EBI2_CLK,       NULL, 0),
+       CLK_PCOM("ecodec_clk",  ECODEC_CLK,     NULL, 0),
+       CLK_PCOM("emdh_clk",    EMDH_CLK,       NULL, OFF | CLK_MINMAX),
+       CLK_PCOM("gp_clk",      GP_CLK,         NULL, 0),
+       CLK_PCOM("grp_clk",     GRP_3D_CLK,     NULL, 0),
+       CLK_PCOM("icodec_rx_clk",       ICODEC_RX_CLK,  NULL, 0),
+       CLK_PCOM("icodec_tx_clk",       ICODEC_TX_CLK,  NULL, 0),
+       CLK_PCOM("imem_clk",    IMEM_CLK,       NULL, OFF),
+       CLK_PCOM("mdc_clk",     MDC_CLK,        NULL, 0),
+       CLK_PCOM("mddi_clk",    PMDH_CLK,       NULL, OFF | CLK_MINMAX),
+       CLK_PCOM("mdp_clk",     MDP_CLK,        NULL, OFF),
+       CLK_PCOM("mdp_lcdc_pclk_clk", MDP_LCDC_PCLK_CLK, NULL, 0),
+       CLK_PCOM("mdp_lcdc_pad_pclk_clk", MDP_LCDC_PAD_PCLK_CLK, NULL, 0),
+       CLK_PCOM("mdp_vsync_clk",       MDP_VSYNC_CLK,  NULL, 0),
+       CLK_PCOM("pbus_clk",    PBUS_CLK,       NULL, CLK_MIN),
+       CLK_PCOM("pcm_clk",     PCM_CLK,        NULL, 0),
+       CLK_PCOM("sdac_clk",    SDAC_CLK,       NULL, OFF),
+       CLK_PCOM("spi_clk",     SPI_CLK,        NULL, 0),
+       CLK_PCOM("tsif_clk",    TSIF_CLK,       NULL, 0),
+       CLK_PCOM("tsif_ref_clk",        TSIF_REF_CLK,   NULL, 0),
+       CLK_PCOM("tv_dac_clk",  TV_DAC_CLK,     NULL, 0),
+       CLK_PCOM("tv_enc_clk",  TV_ENC_CLK,     NULL, 0),
+       CLK_PCOM("uart_clk",    UART3_CLK,      &msm_device_uart3.dev, OFF),
+       CLK_PCOM("usb_hs_clk",  USB_HS_CLK,     NULL, OFF),
+       CLK_PCOM("usb_hs_pclk", USB_HS_P_CLK,   NULL, OFF),
+       CLK_PCOM("usb_otg_clk", USB_OTG_CLK,    NULL, 0),
+       CLK_PCOM("vdc_clk",     VDC_CLK,        NULL, OFF | CLK_MIN),
+       CLK_PCOM("vfe_clk",     VFE_CLK,        NULL, OFF),
+       CLK_PCOM("vfe_mdc_clk", VFE_MDC_CLK,    NULL, OFF),
+       CLK_PCOM("vfe_axi_clk", VFE_AXI_CLK,    NULL, OFF),
+       CLK_PCOM("usb_hs2_clk", USB_HS2_CLK,    NULL, OFF),
+       CLK_PCOM("usb_hs2_pclk",        USB_HS2_P_CLK,  NULL, OFF),
+       CLK_PCOM("usb_hs3_clk", USB_HS3_CLK,    NULL, OFF),
+       CLK_PCOM("usb_hs3_pclk",        USB_HS3_P_CLK,  NULL, OFF),
+       CLK_PCOM("usb_phy_clk", USB_PHY_CLK,    NULL, 0),
+};
+
+unsigned msm_num_clocks_8x50 = ARRAY_SIZE(msm_clocks_8x50);
+
index 0744c4a..568443e 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef __ARCH_ARM_MACH_MSM_DEVICES_H
 #define __ARCH_ARM_MACH_MSM_DEVICES_H
 
+#include "clock.h"
+
 extern struct platform_device msm_device_uart1;
 extern struct platform_device msm_device_uart2;
 extern struct platform_device msm_device_uart3;
@@ -33,4 +35,13 @@ extern struct platform_device msm_device_smd;
 
 extern struct platform_device msm_device_nand;
 
+extern struct clk msm_clocks_7x01a[];
+extern unsigned msm_num_clocks_7x01a;
+
+extern struct clk msm_clocks_7x30[];
+extern unsigned msm_num_clocks_7x30;
+
+extern struct clk msm_clocks_8x50[];
+extern unsigned msm_num_clocks_8x50;
+
 #endif
index f5420f9..3d725ae 100644 (file)
@@ -13,6 +13,8 @@
  *
  */
 
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <linux/io.h>
 #include <linux/interrupt.h>
 #include <mach/dma.h>
@@ -26,6 +28,7 @@ enum {
 };
 
 static DEFINE_SPINLOCK(msm_dmov_lock);
+static struct clk *msm_dmov_clk;
 static unsigned int channel_active;
 static struct list_head ready_commands[MSM_DMOV_CHANNEL_COUNT];
 static struct list_head active_commands[MSM_DMOV_CHANNEL_COUNT];
@@ -54,6 +57,9 @@ void msm_dmov_enqueue_cmd(unsigned id, struct msm_dmov_cmd *cmd)
        unsigned int status;
 
        spin_lock_irqsave(&msm_dmov_lock, irq_flags);
+       if (!channel_active)
+               clk_enable(msm_dmov_clk);
+       dsb();
        status = readl(DMOV_STATUS(id));
        if (list_empty(&ready_commands[id]) &&
                (status & DMOV_STATUS_CMD_PTR_RDY)) {
@@ -70,6 +76,8 @@ void msm_dmov_enqueue_cmd(unsigned id, struct msm_dmov_cmd *cmd)
                channel_active |= 1U << id;
                writel(cmd->cmdptr, DMOV_CMD_PTR(id));
        } else {
+               if (!channel_active)
+                       clk_disable(msm_dmov_clk);
                if (list_empty(&active_commands[id]))
                        PRINT_ERROR("msm_dmov_enqueue_cmd(%d), error datamover stalled, status %x\n", id, status);
 
@@ -165,6 +173,7 @@ static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id)
                                        "for %p, result %x\n", id, cmd, ch_result);
                                if (cmd) {
                                        list_del(&cmd->list);
+                                       dsb();
                                        cmd->complete_func(cmd, ch_result, NULL);
                                }
                        }
@@ -181,6 +190,7 @@ static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id)
                                PRINT_FLOW("msm_datamover_irq_handler id %d, flush, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]);
                                if (cmd) {
                                        list_del(&cmd->list);
+                                       dsb();
                                        cmd->complete_func(cmd, ch_result, &errdata);
                                }
                        }
@@ -198,6 +208,7 @@ static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id)
                                PRINT_ERROR("msm_datamover_irq_handler id %d, error, result %x, flush0 %x\n", id, ch_result, errdata.flush[0]);
                                if (cmd) {
                                        list_del(&cmd->list);
+                                       dsb();
                                        cmd->complete_func(cmd, ch_result, &errdata);
                                }
                                /* this does not seem to work, once we get an error */
@@ -219,8 +230,10 @@ static irqreturn_t msm_datamover_irq_handler(int irq, void *dev_id)
                PRINT_FLOW("msm_datamover_irq_handler id %d, status %x\n", id, ch_status);
        }
 
-       if (!channel_active)
-               disable_irq(INT_ADM_AARM);
+       if (!channel_active) {
+               disable_irq_nosync(INT_ADM_AARM);
+               clk_disable(msm_dmov_clk);
+       }
 
        spin_unlock_irqrestore(&msm_dmov_lock, irq_flags);
        return IRQ_HANDLED;
@@ -230,11 +243,17 @@ static int __init msm_init_datamover(void)
 {
        int i;
        int ret;
+       struct clk *clk;
+
        for (i = 0; i < MSM_DMOV_CHANNEL_COUNT; i++) {
                INIT_LIST_HEAD(&ready_commands[i]);
                INIT_LIST_HEAD(&active_commands[i]);
                writel(DMOV_CONFIG_IRQ_EN | DMOV_CONFIG_FORCE_TOP_PTR_RSLT | DMOV_CONFIG_FORCE_FLUSH_RSLT, DMOV_CONFIG(i));
        }
+       clk = clk_get(NULL, "adm_clk");
+       if (IS_ERR(clk))
+               return PTR_ERR(clk);
+       msm_dmov_clk = clk;
        ret = request_irq(INT_ADM_AARM, msm_datamover_irq_handler, 0, "msmdatamover", NULL);
        if (ret)
                return ret;
diff --git a/arch/arm/mach-msm/gpio.c b/arch/arm/mach-msm/gpio.c
new file mode 100644 (file)
index 0000000..bc32c84
--- /dev/null
@@ -0,0 +1,85 @@
+/* linux/arch/arm/mach-msm/gpio.c
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/module.h>
+#include <mach/gpio.h>
+#include "proc_comm.h"
+
+int gpio_tlmm_config(unsigned config, unsigned disable)
+{
+       return msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX, &config, &disable);
+}
+EXPORT_SYMBOL(gpio_tlmm_config);
+
+int msm_gpios_enable(const struct msm_gpio *table, int size)
+{
+       int rc;
+       int i;
+       const struct msm_gpio *g;
+       for (i = 0; i < size; i++) {
+               g = table + i;
+               rc = gpio_tlmm_config(g->gpio_cfg, GPIO_ENABLE);
+               if (rc) {
+                       pr_err("gpio_tlmm_config(0x%08x, GPIO_ENABLE)"
+                              " <%s> failed: %d\n",
+                              g->gpio_cfg, g->label ?: "?", rc);
+                       pr_err("pin %d func %d dir %d pull %d drvstr %d\n",
+                              GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg),
+                              GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg),
+                              GPIO_DRVSTR(g->gpio_cfg));
+                       goto err;
+               }
+       }
+       return 0;
+err:
+       msm_gpios_disable(table, i);
+       return rc;
+}
+EXPORT_SYMBOL(msm_gpios_enable);
+
+void msm_gpios_disable(const struct msm_gpio *table, int size)
+{
+       int rc;
+       int i;
+       const struct msm_gpio *g;
+       for (i = size-1; i >= 0; i--) {
+               g = table + i;
+               rc = gpio_tlmm_config(g->gpio_cfg, GPIO_DISABLE);
+               if (rc) {
+                       pr_err("gpio_tlmm_config(0x%08x, GPIO_DISABLE)"
+                              " <%s> failed: %d\n",
+                              g->gpio_cfg, g->label ?: "?", rc);
+                       pr_err("pin %d func %d dir %d pull %d drvstr %d\n",
+                              GPIO_PIN(g->gpio_cfg), GPIO_FUNC(g->gpio_cfg),
+                              GPIO_DIR(g->gpio_cfg), GPIO_PULL(g->gpio_cfg),
+                              GPIO_DRVSTR(g->gpio_cfg));
+               }
+       }
+}
+EXPORT_SYMBOL(msm_gpios_disable);
+
+int msm_gpios_request_enable(const struct msm_gpio *table, int size)
+{
+       int rc = msm_gpios_enable(table, size);
+       return rc;
+}
+EXPORT_SYMBOL(msm_gpios_request_enable);
+
+void msm_gpios_disable_free(const struct msm_gpio *table, int size)
+{
+       msm_gpios_disable(table, size);
+}
+EXPORT_SYMBOL(msm_gpios_disable_free);
index 264d62e..e302fbd 100644 (file)
 
 /* platform device data structures */
 
-struct msm_mddi_platform_data
+struct msm_acpu_clock_platform_data
 {
-       void (*panel_power)(int on);
-       unsigned has_vsync_irq:1;
+       uint32_t acpu_switch_time_us;
+       uint32_t max_speed_delta_khz;
+       uint32_t vdd_switch_time_us;
+       unsigned long power_collapse_khz;
+       unsigned long wait_for_irq_khz;
 };
 
+struct clk;
+
 /* common init routines for use by arch/arm/mach-msm/board-*.c */
 
 void __init msm_add_devices(void);
 void __init msm_map_common_io(void);
 void __init msm_init_irq(void);
 void __init msm_init_gpio(void);
-void __init msm_clock_init(void);
+void __init msm_clock_init(struct clk *clock_tbl, unsigned num_clocks);
+void __init msm_acpu_clock_init(struct msm_acpu_clock_platform_data *);
 
 #endif
diff --git a/arch/arm/mach-msm/include/mach/clk.h b/arch/arm/mach-msm/include/mach/clk.h
new file mode 100644 (file)
index 0000000..c05ca40
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+#ifndef __MACH_CLK_H
+#define __MACH_CLK_H
+
+/* Magic rate value for use with PM QOS to request the board's maximum
+ * supported AXI rate. PM QOS will only pass positive s32 rate values
+ * through to the clock driver, so INT_MAX is used.
+ */
+#define MSM_AXI_MAX_FREQ       LONG_MAX
+
+enum clk_reset_action {
+       CLK_RESET_DEASSERT      = 0,
+       CLK_RESET_ASSERT        = 1
+};
+
+struct clk;
+
+/* Rate is minimum clock rate in Hz */
+int clk_set_min_rate(struct clk *clk, unsigned long rate);
+
+/* Rate is maximum clock rate in Hz */
+int clk_set_max_rate(struct clk *clk, unsigned long rate);
+
+/* Assert/Deassert reset to a hardware block associated with a clock */
+int clk_reset(struct clk *clk, enum clk_reset_action action);
+
+/* Set clock-specific configuration parameters */
+int clk_set_flags(struct clk *clk, unsigned long flags);
+
+#endif
index 5ab5bdf..04c51cc 100644 (file)
@@ -41,40 +41,42 @@ int msm_dmov_exec_cmd(unsigned id, unsigned int cmdptr);
 #define DMOV_SD2(off, ch) (MSM_DMOV_BASE + 0x0800 + (off) + ((ch) << 2))
 #define DMOV_SD3(off, ch) (MSM_DMOV_BASE + 0x0C00 + (off) + ((ch) << 2))
 
-/* only security domain 3 is available to the ARM11
- * SD0 -> mARM trusted, SD1 -> mARM nontrusted, SD2 -> aDSP, SD3 -> aARM
- */
+#if defined(CONFIG_ARCH_MSM7X30)
+#define DMOV_SD_AARM DMOV_SD2
+#else
+#define DMOV_SD_AARM DMOV_SD3
+#endif
 
-#define DMOV_CMD_PTR(ch)      DMOV_SD3(0x000, ch)
+#define DMOV_CMD_PTR(ch)      DMOV_SD_AARM(0x000, ch)
 #define DMOV_CMD_LIST         (0 << 29) /* does not work */
 #define DMOV_CMD_PTR_LIST     (1 << 29) /* works */
 #define DMOV_CMD_INPUT_CFG    (2 << 29) /* untested */
 #define DMOV_CMD_OUTPUT_CFG   (3 << 29) /* untested */
 #define DMOV_CMD_ADDR(addr)   ((addr) >> 3)
 
-#define DMOV_RSLT(ch)         DMOV_SD3(0x040, ch)
+#define DMOV_RSLT(ch)         DMOV_SD_AARM(0x040, ch)
 #define DMOV_RSLT_VALID       (1 << 31) /* 0 == host has empties result fifo */
 #define DMOV_RSLT_ERROR       (1 << 3)
 #define DMOV_RSLT_FLUSH       (1 << 2)
 #define DMOV_RSLT_DONE        (1 << 1)  /* top pointer done */
 #define DMOV_RSLT_USER        (1 << 0)  /* command with FR force result */
 
-#define DMOV_FLUSH0(ch)       DMOV_SD3(0x080, ch)
-#define DMOV_FLUSH1(ch)       DMOV_SD3(0x0C0, ch)
-#define DMOV_FLUSH2(ch)       DMOV_SD3(0x100, ch)
-#define DMOV_FLUSH3(ch)       DMOV_SD3(0x140, ch)
-#define DMOV_FLUSH4(ch)       DMOV_SD3(0x180, ch)
-#define DMOV_FLUSH5(ch)       DMOV_SD3(0x1C0, ch)
+#define DMOV_FLUSH0(ch)       DMOV_SD_AARM(0x080, ch)
+#define DMOV_FLUSH1(ch)       DMOV_SD_AARM(0x0C0, ch)
+#define DMOV_FLUSH2(ch)       DMOV_SD_AARM(0x100, ch)
+#define DMOV_FLUSH3(ch)       DMOV_SD_AARM(0x140, ch)
+#define DMOV_FLUSH4(ch)       DMOV_SD_AARM(0x180, ch)
+#define DMOV_FLUSH5(ch)       DMOV_SD_AARM(0x1C0, ch)
 
-#define DMOV_STATUS(ch)       DMOV_SD3(0x200, ch)
+#define DMOV_STATUS(ch)       DMOV_SD_AARM(0x200, ch)
 #define DMOV_STATUS_RSLT_COUNT(n)    (((n) >> 29))
 #define DMOV_STATUS_CMD_COUNT(n)     (((n) >> 27) & 3)
 #define DMOV_STATUS_RSLT_VALID       (1 << 1)
 #define DMOV_STATUS_CMD_PTR_RDY      (1 << 0)
 
-#define DMOV_ISR              DMOV_SD3(0x380, 0)
-
-#define DMOV_CONFIG(ch)       DMOV_SD3(0x300, ch)
+#define DMOV_ISR              DMOV_SD_AARM(0x380, 0)
+  
+#define DMOV_CONFIG(ch)       DMOV_SD_AARM(0x300, ch)
 #define DMOV_CONFIG_FORCE_TOP_PTR_RSLT (1 << 2)
 #define DMOV_CONFIG_FORCE_FLUSH_RSLT   (1 << 1)
 #define DMOV_CONFIG_IRQ_EN             (1 << 0)
diff --git a/arch/arm/mach-msm/include/mach/gpio.h b/arch/arm/mach-msm/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..262b441
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
+ * Author: Mike Lockwood <lockwood@android.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+#ifndef __ASM_ARCH_MSM_GPIO_H
+#define __ASM_ARCH_MSM_GPIO_H
+
+/**
+ * struct msm_gpio - GPIO pin description
+ * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
+ * @label - textual label
+ *
+ * Usually, GPIO's are operated by sets.
+ * This struct accumulate all GPIO information in single source
+ * and facilitete group operations provided by msm_gpios_xxx()
+ */
+struct msm_gpio {
+       u32 gpio_cfg;
+       const char *label;
+};
+
+/**
+ * msm_gpios_request_enable() - request and enable set of GPIOs
+ *
+ * Request and configure set of GPIO's
+ * In case of error, all operations rolled back.
+ * Return error code.
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+int msm_gpios_request_enable(const struct msm_gpio *table, int size);
+
+/**
+ * msm_gpios_disable_free() - disable and free set of GPIOs
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+void msm_gpios_disable_free(const struct msm_gpio *table, int size);
+
+/**
+ * msm_gpios_request() - request set of GPIOs
+ * In case of error, all operations rolled back.
+ * Return error code.
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+int msm_gpios_request(const struct msm_gpio *table, int size);
+
+/**
+ * msm_gpios_free() - free set of GPIOs
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+void msm_gpios_free(const struct msm_gpio *table, int size);
+
+/**
+ * msm_gpios_enable() - enable set of GPIOs
+ * In case of error, all operations rolled back.
+ * Return error code.
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+int msm_gpios_enable(const struct msm_gpio *table, int size);
+
+/**
+ * msm_gpios_disable() - disable set of GPIOs
+ *
+ * @table: GPIO table
+ * @size:  number of entries in @table
+ */
+void msm_gpios_disable(const struct msm_gpio *table, int size);
+
+/* GPIO TLMM (Top Level Multiplexing) Definitions */
+
+/* GPIO TLMM: Function -- GPIO specific */
+
+/* GPIO TLMM: Direction */
+enum {
+       GPIO_INPUT,
+       GPIO_OUTPUT,
+};
+
+/* GPIO TLMM: Pullup/Pulldown */
+enum {
+       GPIO_NO_PULL,
+       GPIO_PULL_DOWN,
+       GPIO_KEEPER,
+       GPIO_PULL_UP,
+};
+
+/* GPIO TLMM: Drive Strength */
+enum {
+       GPIO_2MA,
+       GPIO_4MA,
+       GPIO_6MA,
+       GPIO_8MA,
+       GPIO_10MA,
+       GPIO_12MA,
+       GPIO_14MA,
+       GPIO_16MA,
+};
+
+enum {
+       GPIO_ENABLE,
+       GPIO_DISABLE,
+};
+
+#define GPIO_CFG(gpio, func, dir, pull, drvstr) \
+       ((((gpio) & 0x3FF) << 4)        |         \
+        ((func) & 0xf)                  |        \
+        (((dir) & 0x1) << 14)           |        \
+        (((pull) & 0x3) << 15)          |        \
+        (((drvstr) & 0xF) << 17))
+
+/**
+ * extract GPIO pin from bit-field used for gpio_tlmm_config
+ */
+#define GPIO_PIN(gpio_cfg)    (((gpio_cfg) >>  4) & 0x3ff)
+#define GPIO_FUNC(gpio_cfg)   (((gpio_cfg) >>  0) & 0xf)
+#define GPIO_DIR(gpio_cfg)    (((gpio_cfg) >> 14) & 0x1)
+#define GPIO_PULL(gpio_cfg)   (((gpio_cfg) >> 15) & 0x3)
+#define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
+
+int gpio_tlmm_config(unsigned config, unsigned disable);
+
+#endif /* __ASM_ARCH_MSM_GPIO_H */
index aab9645..c35b29f 100644 (file)
@@ -26,4 +26,9 @@ void __iomem *__msm_ioremap(unsigned long phys_addr, size_t size, unsigned int m
 #define __io(a)                __typesafe_io(a)
 #define __mem_pci(a)    (a)
 
+void msm_map_qsd8x50_io(void);
+void msm_map_msm7x30_io(void);
+
+extern unsigned int msm_shared_ram_phys;
+
 #endif
diff --git a/arch/arm/mach-msm/include/mach/irqs-7x00.h b/arch/arm/mach-msm/include/mach/irqs-7x00.h
new file mode 100644 (file)
index 0000000..f1fe706
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ * Author: Brian Swetland <swetland@google.com>
+ */
+
+#ifndef __ASM_ARCH_MSM_IRQS_7X00_H
+#define __ASM_ARCH_MSM_IRQS_7X00_H
+
+/* MSM ARM11 Interrupt Numbers */
+/* See 80-VE113-1 A, pp219-221     */
+
+#define INT_A9_M2A_0         0
+#define INT_A9_M2A_1         1
+#define INT_A9_M2A_2         2
+#define INT_A9_M2A_3         3
+#define INT_A9_M2A_4         4
+#define INT_A9_M2A_5         5
+#define INT_A9_M2A_6         6
+#define INT_GP_TIMER_EXP     7
+#define INT_DEBUG_TIMER_EXP  8
+#define INT_UART1            9
+#define INT_UART2            10
+#define INT_UART3            11
+#define INT_UART1_RX         12
+#define INT_UART2_RX         13
+#define INT_UART3_RX         14
+#define INT_USB_OTG          15
+#define INT_MDDI_PRI         16
+#define INT_MDDI_EXT         17
+#define INT_MDDI_CLIENT      18
+#define INT_MDP              19
+#define INT_GRAPHICS         20
+#define INT_ADM_AARM         21
+#define INT_ADSP_A11         22
+#define INT_ADSP_A9_A11      23
+#define INT_SDC1_0           24
+#define INT_SDC1_1           25
+#define INT_SDC2_0           26
+#define INT_SDC2_1           27
+#define INT_KEYSENSE         28
+#define INT_TCHSCRN_SSBI     29
+#define INT_TCHSCRN1         30
+#define INT_TCHSCRN2         31
+
+#define INT_GPIO_GROUP1      (32 + 0)
+#define INT_GPIO_GROUP2      (32 + 1)
+#define INT_PWB_I2C          (32 + 2)
+#define INT_SOFTRESET        (32 + 3)
+#define INT_NAND_WR_ER_DONE  (32 + 4)
+#define INT_NAND_OP_DONE     (32 + 5)
+#define INT_PBUS_ARM11       (32 + 6)
+#define INT_AXI_MPU_SMI      (32 + 7)
+#define INT_AXI_MPU_EBI1     (32 + 8)
+#define INT_AD_HSSD          (32 + 9)
+#define INT_ARM11_PMU        (32 + 10)
+#define INT_ARM11_DMA        (32 + 11)
+#define INT_TSIF_IRQ         (32 + 12)
+#define INT_UART1DM_IRQ      (32 + 13)
+#define INT_UART1DM_RX       (32 + 14)
+#define INT_USB_HS           (32 + 15)
+#define INT_SDC3_0           (32 + 16)
+#define INT_SDC3_1           (32 + 17)
+#define INT_SDC4_0           (32 + 18)
+#define INT_SDC4_1           (32 + 19)
+#define INT_UART2DM_RX       (32 + 20)
+#define INT_UART2DM_IRQ      (32 + 21)
+
+/* 22-31 are reserved */
+
+#define NR_MSM_IRQS 64
+#define NR_GPIO_IRQS 122
+#define NR_BOARD_IRQS 64
+
+#endif
diff --git a/arch/arm/mach-msm/include/mach/irqs-7x30.h b/arch/arm/mach-msm/include/mach/irqs-7x30.h
new file mode 100644 (file)
index 0000000..67c5396
--- /dev/null
@@ -0,0 +1,170 @@
+/* Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_IRQS_7X30_H
+#define __ASM_ARCH_MSM_IRQS_7X30_H
+
+/* MSM ACPU Interrupt Numbers */
+
+#define INT_DEBUG_TIMER_EXP    0
+#define INT_GPT0_TIMER_EXP     1
+#define INT_GPT1_TIMER_EXP     2
+#define INT_WDT0_ACCSCSSBARK   3
+#define INT_WDT1_ACCSCSSBARK   4
+#define INT_AVS_SVIC           5
+#define INT_AVS_SVIC_SW_DONE   6
+#define INT_SC_DBG_RX_FULL     7
+#define INT_SC_DBG_TX_EMPTY    8
+#define INT_ARM11_PM           9
+#define INT_AVS_REQ_DOWN       10
+#define INT_AVS_REQ_UP         11
+#define INT_SC_ACG             12
+/* SCSS_VICFIQSTS0[13:15] are RESERVED */
+#define INT_L2_SVICCPUIRPTREQ  16
+#define INT_L2_SVICDMANSIRPTREQ 17
+#define INT_L2_SVICDMASIRPTREQ  18
+#define INT_L2_SVICSLVIRPTREQ  19
+#define INT_AD5A_MPROC_APPS_0  20
+#define INT_AD5A_MPROC_APPS_1  21
+#define INT_A9_M2A_0           22
+#define INT_A9_M2A_1           23
+#define INT_A9_M2A_2           24
+#define INT_A9_M2A_3           25
+#define INT_A9_M2A_4           26
+#define INT_A9_M2A_5           27
+#define INT_A9_M2A_6           28
+#define INT_A9_M2A_7           29
+#define INT_A9_M2A_8           30
+#define INT_A9_M2A_9           31
+
+#define INT_AXI_EBI1_SC                (32 + 0)
+#define INT_IMEM_ERR           (32 + 1)
+#define INT_AXI_EBI0_SC                (32 + 2)
+#define INT_PBUS_SC_IRQC       (32 + 3)
+#define INT_PERPH_BUS_BPM      (32 + 4)
+#define INT_CC_TEMP_SENSE      (32 + 5)
+#define INT_UXMC_EBI0          (32 + 6)
+#define INT_UXMC_EBI1          (32 + 7)
+#define INT_EBI2_OP_DONE       (32 + 8)
+#define INT_EBI2_WR_ER_DONE    (32 + 9)
+#define INT_TCSR_SPSS_CE       (32 + 10)
+#define INT_EMDH               (32 + 11)
+#define INT_PMDH               (32 + 12)
+#define INT_MDC                        (32 + 13)
+#define INT_MIDI_TO_SUPSS      (32 + 14)
+#define INT_LPA_2              (32 + 15)
+#define INT_GPIO_GROUP1_SECURE (32 + 16)
+#define INT_GPIO_GROUP2_SECURE (32 + 17)
+#define INT_GPIO_GROUP1                (32 + 18)
+#define INT_GPIO_GROUP2                (32 + 19)
+#define INT_MPRPH_SOFTRESET    (32 + 20)
+#define INT_PWB_I2C            (32 + 21)
+#define INT_PWB_I2C_2          (32 + 22)
+#define INT_TSSC_SAMPLE                (32 + 23)
+#define INT_TSSC_PENUP         (32 + 24)
+#define INT_TCHSCRN_SSBI       (32 + 25)
+#define INT_FM_RDS             (32 + 26)
+#define INT_KEYSENSE           (32 + 27)
+#define INT_USB_OTG_HS         (32 + 28)
+#define INT_USB_OTG_HS2                (32 + 29)
+#define INT_USB_OTG_HS3                (32 + 30)
+#define INT_CSI                        (32 + 31)
+
+#define INT_SPI_OUTPUT         (64 + 0)
+#define INT_SPI_INPUT          (64 + 1)
+#define INT_SPI_ERROR          (64 + 2)
+#define INT_UART1              (64 + 3)
+#define INT_UART1_RX           (64 + 4)
+#define INT_UART2              (64 + 5)
+#define INT_UART2_RX           (64 + 6)
+#define INT_UART3              (64 + 7)
+#define INT_UART3_RX           (64 + 8)
+#define INT_UART1DM_IRQ                (64 + 9)
+#define INT_UART1DM_RX         (64 + 10)
+#define INT_UART2DM_IRQ                (64 + 11)
+#define INT_UART2DM_RX         (64 + 12)
+#define INT_TSIF               (64 + 13)
+#define INT_ADM_SC1            (64 + 14)
+#define INT_ADM_SC2            (64 + 15)
+#define INT_MDP                        (64 + 16)
+#define INT_VPE                        (64 + 17)
+#define INT_GRP_2D             (64 + 18)
+#define INT_GRP_3D             (64 + 19)
+#define INT_ROTATOR            (64 + 20)
+#define INT_MFC720             (64 + 21)
+#define INT_JPEG               (64 + 22)
+#define INT_VFE                        (64 + 23)
+#define INT_TV_ENC             (64 + 24)
+#define INT_PMIC_SSBI          (64 + 25)
+#define INT_MPM_1              (64 + 26)
+#define INT_TCSR_SPSS_SAMPLE   (64 + 27)
+#define INT_TCSR_SPSS_PENUP    (64 + 28)
+#define INT_MPM_2              (64 + 29)
+#define INT_SDC1_0             (64 + 30)
+#define INT_SDC1_1             (64 + 31)
+
+#define INT_SDC3_0             (96 + 0)
+#define INT_SDC3_1             (96 + 1)
+#define INT_SDC2_0             (96 + 2)
+#define INT_SDC2_1             (96 + 3)
+#define INT_SDC4_0             (96 + 4)
+#define INT_SDC4_1             (96 + 5)
+#define INT_PWB_QUP_IN         (96 + 6)
+#define INT_PWB_QUP_OUT                (96 + 7)
+#define INT_PWB_QUP_ERR                (96 + 8)
+#define INT_SCSS_WDT0_BITE     (96 + 9)
+/* SCSS_VICFIQSTS3[10:31] are RESERVED */
+
+/* Retrofit universal macro names */
+#define INT_ADM_AARM           INT_ADM_SC2
+#define INT_USB_HS             INT_USB_OTG_HS
+#define INT_USB_OTG            INT_USB_OTG_HS
+#define INT_TCHSCRN1           INT_TSSC_SAMPLE
+#define INT_TCHSCRN2           INT_TSSC_PENUP
+#define INT_GP_TIMER_EXP       INT_GPT0_TIMER_EXP
+#define INT_ADSP_A11           INT_AD5A_MPROC_APPS_0
+#define INT_ADSP_A9_A11        INT_AD5A_MPROC_APPS_1
+#define INT_MDDI_EXT           INT_EMDH
+#define INT_MDDI_PRI           INT_PMDH
+#define INT_MDDI_CLIENT                INT_MDC
+#define INT_NAND_WR_ER_DONE    INT_EBI2_WR_ER_DONE
+#define INT_NAND_OP_DONE       INT_EBI2_OP_DONE
+
+#define NR_MSM_IRQS            128
+#define NR_GPIO_IRQS           182
+#define PMIC8058_IRQ_BASE      (NR_MSM_IRQS + NR_GPIO_IRQS)
+#define NR_PMIC8058_GPIO_IRQS  40
+#define NR_PMIC8058_MPP_IRQS   12
+#define NR_PMIC8058_MISC_IRQS  8
+#define NR_PMIC8058_IRQS       (NR_PMIC8058_GPIO_IRQS +\
+                               NR_PMIC8058_MPP_IRQS +\
+                               NR_PMIC8058_MISC_IRQS)
+#define NR_BOARD_IRQS          NR_PMIC8058_IRQS
+
+#endif /* __ASM_ARCH_MSM_IRQS_7X30_H */
diff --git a/arch/arm/mach-msm/include/mach/irqs-8x50.h b/arch/arm/mach-msm/include/mach/irqs-8x50.h
new file mode 100644 (file)
index 0000000..de3d8fe
--- /dev/null
@@ -0,0 +1,105 @@
+/* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_IRQS_8XXX_H
+#define __ASM_ARCH_MSM_IRQS_8XXX_H
+
+/* MSM ACPU Interrupt Numbers */
+
+#define INT_A9_M2A_0         0
+#define INT_A9_M2A_1         1
+#define INT_A9_M2A_2         2
+#define INT_A9_M2A_3         3
+#define INT_A9_M2A_4         4
+#define INT_A9_M2A_5         5
+#define INT_A9_M2A_6         6
+#define INT_GP_TIMER_EXP     7
+#define INT_DEBUG_TIMER_EXP  8
+#define INT_SIRC_0           9
+#define INT_SDC3_0           10
+#define INT_SDC3_1           11
+#define INT_SDC4_0           12
+#define INT_SDC4_1           13
+#define INT_AD6_EXT_VFR      14
+#define INT_USB_OTG          15
+#define INT_MDDI_PRI         16
+#define INT_MDDI_EXT         17
+#define INT_MDDI_CLIENT      18
+#define INT_MDP              19
+#define INT_GRAPHICS         20
+#define INT_ADM_AARM         21
+#define INT_ADSP_A11         22
+#define INT_ADSP_A9_A11      23
+#define INT_SDC1_0           24
+#define INT_SDC1_1           25
+#define INT_SDC2_0           26
+#define INT_SDC2_1           27
+#define INT_KEYSENSE         28
+#define INT_TCHSCRN_SSBI     29
+#define INT_TCHSCRN1         30
+#define INT_TCHSCRN2         31
+
+#define INT_TCSR_MPRPH_SC1   (32 + 0)
+#define INT_USB_FS2          (32 + 1)
+#define INT_PWB_I2C          (32 + 2)
+#define INT_SOFTRESET        (32 + 3)
+#define INT_NAND_WR_ER_DONE  (32 + 4)
+#define INT_NAND_OP_DONE     (32 + 5)
+#define INT_TCSR_MPRPH_SC2   (32 + 6)
+#define INT_OP_PEN           (32 + 7)
+#define INT_AD_HSSD          (32 + 8)
+#define INT_ARM11_PM         (32 + 9)
+#define INT_SDMA_NON_SECURE  (32 + 10)
+#define INT_TSIF_IRQ         (32 + 11)
+#define INT_UART1DM_IRQ      (32 + 12)
+#define INT_UART1DM_RX       (32 + 13)
+#define INT_SDMA_SECURE      (32 + 14)
+#define INT_SI2S_SLAVE       (32 + 15)
+#define INT_SC_I2CPU         (32 + 16)
+#define INT_SC_DBG_RDTRFULL  (32 + 17)
+#define INT_SC_DBG_WDTRFULL  (32 + 18)
+#define INT_SCPLL_CTL_DONE   (32 + 19)
+#define INT_UART2DM_IRQ      (32 + 20)
+#define INT_UART2DM_RX       (32 + 21)
+#define INT_VDC_MEC          (32 + 22)
+#define INT_VDC_DB           (32 + 23)
+#define INT_VDC_AXI          (32 + 24)
+#define INT_VFE              (32 + 25)
+#define INT_USB_HS           (32 + 26)
+#define INT_AUDIO_OUT0       (32 + 27)
+#define INT_AUDIO_OUT1       (32 + 28)
+#define INT_CRYPTO           (32 + 29)
+#define INT_AD6M_IDLE        (32 + 30)
+#define INT_SIRC_1           (32 + 31)
+
+#define NR_GPIO_IRQS 165
+#define NR_MSM_IRQS 64
+#define NR_BOARD_IRQS 64
+
+#endif
index 9dd4cf8..164d355 100644 (file)
@@ -1,6 +1,6 @@
-/* arch/arm/mach-msm/include/mach/irqs.h
- *
+/*
  * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
  * Author: Brian Swetland <swetland@google.com>
  *
  * This software is licensed under the terms of the GNU General Public
 #ifndef __ASM_ARCH_MSM_IRQS_H
 #define __ASM_ARCH_MSM_IRQS_H
 
-/* MSM ARM11 Interrupt Numbers */
-/* See 80-VE113-1 A, pp219-221     */
-
-#define INT_A9_M2A_0         0
-#define INT_A9_M2A_1         1
-#define INT_A9_M2A_2         2
-#define INT_A9_M2A_3         3
-#define INT_A9_M2A_4         4
-#define INT_A9_M2A_5         5
-#define INT_A9_M2A_6         6
-#define INT_GP_TIMER_EXP     7
-#define INT_DEBUG_TIMER_EXP  8
-#define INT_UART1            9
-#define INT_UART2            10
-#define INT_UART3            11
-#define INT_UART1_RX         12
-#define INT_UART2_RX         13
-#define INT_UART3_RX         14
-#define INT_USB_OTG          15
-#define INT_MDDI_PRI         16
-#define INT_MDDI_EXT         17
-#define INT_MDDI_CLIENT      18
-#define INT_MDP              19
-#define INT_GRAPHICS         20
-#define INT_ADM_AARM         21
-#define INT_ADSP_A11         22
-#define INT_ADSP_A9_A11      23
-#define INT_SDC1_0           24
-#define INT_SDC1_1           25
-#define INT_SDC2_0           26
-#define INT_SDC2_1           27
-#define INT_KEYSENSE         28
-#define INT_TCHSCRN_SSBI     29
-#define INT_TCHSCRN1         30
-#define INT_TCHSCRN2         31
-
-#define INT_GPIO_GROUP1      (32 + 0)
-#define INT_GPIO_GROUP2      (32 + 1)
-#define INT_PWB_I2C          (32 + 2)
-#define INT_SOFTRESET        (32 + 3)
-#define INT_NAND_WR_ER_DONE  (32 + 4)
-#define INT_NAND_OP_DONE     (32 + 5)
-#define INT_PBUS_ARM11       (32 + 6)
-#define INT_AXI_MPU_SMI      (32 + 7)
-#define INT_AXI_MPU_EBI1     (32 + 8)
-#define INT_AD_HSSD          (32 + 9)
-#define INT_ARM11_PMU        (32 + 10)
-#define INT_ARM11_DMA        (32 + 11)
-#define INT_TSIF_IRQ         (32 + 12)
-#define INT_UART1DM_IRQ      (32 + 13)
-#define INT_UART1DM_RX       (32 + 14)
-#define INT_USB_HS           (32 + 15)
-#define INT_SDC3_0           (32 + 16)
-#define INT_SDC3_1           (32 + 17)
-#define INT_SDC4_0           (32 + 18)
-#define INT_SDC4_1           (32 + 19)
-#define INT_UART2DM_RX       (32 + 20)
-#define INT_UART2DM_IRQ      (32 + 21)
-
-/* 22-31 are reserved */
-
 #define MSM_IRQ_BIT(irq)     (1 << ((irq) & 31))
 
-#define NR_MSM_IRQS 64
-#define NR_GPIO_IRQS 122
-#define NR_BOARD_IRQS 64
-#define NR_IRQS (NR_MSM_IRQS + NR_GPIO_IRQS + NR_BOARD_IRQS)
+#if defined(CONFIG_ARCH_MSM7X30)
+#include "irqs-7x30.h"
+#elif defined(CONFIG_ARCH_QSD8X50)
+#include "irqs-8x50.h"
+#include "sirc.h"
+#elif defined(CONFIG_ARCH_MSM_ARM11)
+#include "irqs-7x00.h"
+#else
+#error "Unknown architecture specification"
+#endif
 
+#define NR_IRQS (NR_MSM_IRQS + NR_GPIO_IRQS + NR_BOARD_IRQS)
 #define MSM_GPIO_TO_INT(n) (NR_MSM_IRQS + (n))
+#define MSM_INT_TO_REG(base, irq) (base + irq / 32)
 
 #endif
index f4698ba..50c7847 100644 (file)
 #define __ASM_ARCH_MEMORY_H
 
 /* physical offset of RAM */
+#if defined(CONFIG_ARCH_QSD8X50) && defined(CONFIG_MSM_SOC_REV_A)
+#define PHYS_OFFSET            UL(0x00000000)
+#elif defined(CONFIG_ARCH_QSD8X50)
+#define PHYS_OFFSET            UL(0x20000000)
+#elif defined(CONFIG_ARCH_MSM7X30)
+#define PHYS_OFFSET            UL(0x00200000)
+#else
 #define PHYS_OFFSET            UL(0x10000000)
+#endif
 
 #endif
 
diff --git a/arch/arm/mach-msm/include/mach/msm_fb.h b/arch/arm/mach-msm/include/mach/msm_fb.h
new file mode 100644 (file)
index 0000000..1f4fc81
--- /dev/null
@@ -0,0 +1,147 @@
+/* arch/arm/mach-msm/include/mach/msm_fb.h
+ *
+ * Internal shared definitions for various MSM framebuffer parts.
+ *
+ * Copyright (C) 2007 Google Incorporated
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ */
+
+#ifndef _MSM_FB_H_
+#define _MSM_FB_H_
+
+#include <linux/device.h>
+
+struct mddi_info;
+
+struct msm_fb_data {
+       int xres;       /* x resolution in pixels */
+       int yres;       /* y resolution in pixels */
+       int width;      /* disply width in mm */
+       int height;     /* display height in mm */
+       unsigned output_format;
+};
+
+struct msmfb_callback {
+       void (*func)(struct msmfb_callback *);
+};
+
+enum {
+       MSM_MDDI_PMDH_INTERFACE,
+       MSM_MDDI_EMDH_INTERFACE,
+       MSM_EBI2_INTERFACE,
+};
+
+#define MSMFB_CAP_PARTIAL_UPDATES      (1 << 0)
+
+struct msm_panel_data {
+       /* turns off the fb memory */
+       int (*suspend)(struct msm_panel_data *);
+       /* turns on the fb memory */
+       int (*resume)(struct msm_panel_data *);
+       /* turns off the panel */
+       int (*blank)(struct msm_panel_data *);
+       /* turns on the panel */
+       int (*unblank)(struct msm_panel_data *);
+       void (*wait_vsync)(struct msm_panel_data *);
+       void (*request_vsync)(struct msm_panel_data *, struct msmfb_callback *);
+       void (*clear_vsync)(struct msm_panel_data *);
+       /* from the enum above */
+       unsigned interface_type;
+       /* data to be passed to the fb driver */
+       struct msm_fb_data *fb_data;
+
+       /* capabilities supported by the panel */
+       uint32_t caps;
+};
+
+struct msm_mddi_client_data {
+       void (*suspend)(struct msm_mddi_client_data *);
+       void (*resume)(struct msm_mddi_client_data *);
+       void (*activate_link)(struct msm_mddi_client_data *);
+       void (*remote_write)(struct msm_mddi_client_data *, uint32_t val,
+                            uint32_t reg);
+       uint32_t (*remote_read)(struct msm_mddi_client_data *, uint32_t reg);
+       void (*auto_hibernate)(struct msm_mddi_client_data *, int);
+       /* custom data that needs to be passed from the board file to a 
+        * particular client */
+       void *private_client_data;
+       struct resource *fb_resource;
+       /* from the list above */
+       unsigned interface_type;
+};
+
+struct msm_mddi_platform_data {
+       unsigned int clk_rate;
+       void (*power_client)(struct msm_mddi_client_data *, int on);
+
+       /* fixup the mfr name, product id */
+       void (*fixup)(uint16_t *mfr_name, uint16_t *product_id);
+
+       struct resource *fb_resource; /*optional*/
+       /* number of clients in the list that follows */
+       int num_clients;
+       /* array of client information of clients */
+       struct {
+               unsigned product_id; /* mfr id in top 16 bits, product id
+                                     * in lower 16 bits
+                                     */
+               char *name;     /* the device name will be the platform
+                                * device name registered for the client,
+                                * it should match the name of the associated
+                                * driver
+                                */
+               unsigned id;    /* id for mddi client device node, will also
+                                * be used as device id of panel devices, if
+                                * the client device will have multiple panels
+                                * space must be left here for them
+                                */
+               void *client_data;      /* required private client data */
+               unsigned int clk_rate;  /* optional: if the client requires a
+                                       * different mddi clk rate
+                                       */
+       } client_platform_data[];
+};
+
+struct mdp_blit_req;
+struct fb_info;
+struct mdp_device {
+       struct device dev;
+       void (*dma)(struct mdp_device *mpd, uint32_t addr,
+                   uint32_t stride, uint32_t w, uint32_t h, uint32_t x,
+                   uint32_t y, struct msmfb_callback *callback, int interface);
+       void (*dma_wait)(struct mdp_device *mdp);
+       int (*blit)(struct mdp_device *mdp, struct fb_info *fb,
+                   struct mdp_blit_req *req);
+       void (*set_grp_disp)(struct mdp_device *mdp, uint32_t disp_id);
+};
+
+struct class_interface;
+int register_mdp_client(struct class_interface *class_intf);
+
+/**** private client data structs go below this line ***/
+
+struct msm_mddi_bridge_platform_data {
+       /* from board file */
+       int (*init)(struct msm_mddi_bridge_platform_data *,
+                   struct msm_mddi_client_data *);
+       int (*uninit)(struct msm_mddi_bridge_platform_data *,
+                     struct msm_mddi_client_data *);
+       /* passed to panel for use by the fb driver */
+       int (*blank)(struct msm_mddi_bridge_platform_data *,
+                    struct msm_mddi_client_data *);
+       int (*unblank)(struct msm_mddi_bridge_platform_data *,
+                      struct msm_mddi_client_data *);
+       struct msm_fb_data fb_data;
+};
+
+
+
+#endif
diff --git a/arch/arm/mach-msm/include/mach/msm_iomap-7x00.h b/arch/arm/mach-msm/include/mach/msm_iomap-7x00.h
new file mode 100644 (file)
index 0000000..cfff0e7
--- /dev/null
@@ -0,0 +1,139 @@
+/* arch/arm/mach-msm/include/mach/msm_iomap.h
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ *
+ * The MSM peripherals are spread all over across 768MB of physical
+ * space, which makes just having a simple IO_ADDRESS macro to slide
+ * them into the right virtual location rough.  Instead, we will
+ * provide a master phys->virt mapping for peripherals here.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_IOMAP_7X00_H
+#define __ASM_ARCH_MSM_IOMAP_7X00_H
+
+#include <asm/sizes.h>
+
+/* Physical base address and size of peripherals.
+ * Ordered by the virtual base addresses they will be mapped at.
+ *
+ * MSM_VIC_BASE must be an value that can be loaded via a "mov"
+ * instruction, otherwise entry-macro.S will not compile.
+ *
+ * If you add or remove entries here, you'll want to edit the
+ * msm_io_desc array in arch/arm/mach-msm/io.c to reflect your
+ * changes.
+ *
+ */
+
+#ifdef __ASSEMBLY__
+#define IOMEM(x)       x
+#else
+#define IOMEM(x)       ((void __force __iomem *)(x))
+#endif
+
+#define MSM_VIC_BASE          IOMEM(0xE0000000)
+#define MSM_VIC_PHYS          0xC0000000
+#define MSM_VIC_SIZE          SZ_4K
+
+#define MSM_CSR_BASE          IOMEM(0xE0001000)
+#define MSM_CSR_PHYS          0xC0100000
+#define MSM_CSR_SIZE          SZ_4K
+
+#define MSM_GPT_PHYS          MSM_CSR_PHYS
+#define MSM_GPT_BASE          MSM_CSR_BASE
+#define MSM_GPT_SIZE          SZ_4K
+
+#define MSM_DMOV_BASE         IOMEM(0xE0002000)
+#define MSM_DMOV_PHYS         0xA9700000
+#define MSM_DMOV_SIZE         SZ_4K
+
+#define MSM_GPIO1_BASE        IOMEM(0xE0003000)
+#define MSM_GPIO1_PHYS        0xA9200000
+#define MSM_GPIO1_SIZE        SZ_4K
+
+#define MSM_GPIO2_BASE        IOMEM(0xE0004000)
+#define MSM_GPIO2_PHYS        0xA9300000
+#define MSM_GPIO2_SIZE        SZ_4K
+
+#define MSM_CLK_CTL_BASE      IOMEM(0xE0005000)
+#define MSM_CLK_CTL_PHYS      0xA8600000
+#define MSM_CLK_CTL_SIZE      SZ_4K
+
+#define MSM_SHARED_RAM_BASE   IOMEM(0xE0100000)
+#define MSM_SHARED_RAM_PHYS   0x01F00000
+#define MSM_SHARED_RAM_SIZE   SZ_1M
+
+#define MSM_UART1_PHYS        0xA9A00000
+#define MSM_UART1_SIZE        SZ_4K
+
+#define MSM_UART2_PHYS        0xA9B00000
+#define MSM_UART2_SIZE        SZ_4K
+
+#define MSM_UART3_PHYS        0xA9C00000
+#define MSM_UART3_SIZE        SZ_4K
+
+#ifdef CONFIG_MSM_DEBUG_UART
+#define MSM_DEBUG_UART_BASE   0xE1000000
+#if CONFIG_MSM_DEBUG_UART == 1
+#define MSM_DEBUG_UART_PHYS   MSM_UART1_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 2
+#define MSM_DEBUG_UART_PHYS   MSM_UART2_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 3
+#define MSM_DEBUG_UART_PHYS   MSM_UART3_PHYS
+#endif
+#define MSM_DEBUG_UART_SIZE   SZ_4K
+#endif
+
+#define MSM_SDC1_PHYS         0xA0400000
+#define MSM_SDC1_SIZE         SZ_4K
+
+#define MSM_SDC2_PHYS         0xA0500000
+#define MSM_SDC2_SIZE         SZ_4K
+
+#define MSM_SDC3_PHYS         0xA0600000
+#define MSM_SDC3_SIZE         SZ_4K
+
+#define MSM_SDC4_PHYS         0xA0700000
+#define MSM_SDC4_SIZE         SZ_4K
+
+#define MSM_I2C_PHYS          0xA9900000
+#define MSM_I2C_SIZE          SZ_4K
+
+#define MSM_HSUSB_PHYS        0xA0800000
+#define MSM_HSUSB_SIZE        SZ_4K
+
+#define MSM_PMDH_PHYS         0xAA600000
+#define MSM_PMDH_SIZE         SZ_4K
+
+#define MSM_EMDH_PHYS         0xAA700000
+#define MSM_EMDH_SIZE         SZ_4K
+
+#define MSM_MDP_PHYS          0xAA200000
+#define MSM_MDP_SIZE          0x000F0000
+
+#define MSM_MDC_PHYS         0xAA500000
+#define MSM_MDC_SIZE         SZ_1M
+
+#define MSM_AD5_PHYS          0xAC000000
+#define MSM_AD5_SIZE          (SZ_1M*13)
+
+
+#if defined(CONFIG_ARCH_MSM7X30)
+#define MSM_GCC_BASE          IOMEM(0xF8009000)
+#define MSM_GCC_PHYS          0xC0182000
+#define MSM_GCC_SIZE          SZ_4K
+#endif
+
+#endif
diff --git a/arch/arm/mach-msm/include/mach/msm_iomap-7x30.h b/arch/arm/mach-msm/include/mach/msm_iomap-7x30.h
new file mode 100644 (file)
index 0000000..8a00c2d
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ *
+ * The MSM peripherals are spread all over across 768MB of physical
+ * space, which makes just having a simple IO_ADDRESS macro to slide
+ * them into the right virtual location rough.  Instead, we will
+ * provide a master phys->virt mapping for peripherals here.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_IOMAP_7X30_H
+#define __ASM_ARCH_MSM_IOMAP_7X30_H
+
+/* Physical base address and size of peripherals.
+ * Ordered by the virtual base addresses they will be mapped at.
+ *
+ * MSM_VIC_BASE must be an value that can be loaded via a "mov"
+ * instruction, otherwise entry-macro.S will not compile.
+ *
+ * If you add or remove entries here, you'll want to edit the
+ * msm_io_desc array in arch/arm/mach-msm/io.c to reflect your
+ * changes.
+ *
+ */
+
+#define MSM_VIC_BASE          IOMEM(0xE0000000)
+#define MSM_VIC_PHYS          0xC0080000
+#define MSM_VIC_SIZE          SZ_4K
+
+#define MSM_CSR_BASE          IOMEM(0xE0001000)
+#define MSM_CSR_PHYS          0xC0100000
+#define MSM_CSR_SIZE          SZ_4K
+
+#define MSM_TMR_PHYS          MSM_CSR_PHYS
+#define MSM_TMR_BASE          MSM_CSR_BASE
+#define MSM_TMR_SIZE          SZ_4K
+
+#define MSM_GPT_BASE         (MSM_TMR_BASE + 0x4)
+#define MSM_DGT_BASE         (MSM_TMR_BASE + 0x24)
+
+#define MSM_DMOV_BASE         IOMEM(0xE0002000)
+#define MSM_DMOV_PHYS         0xAC400000
+#define MSM_DMOV_SIZE         SZ_4K
+
+#define MSM_GPIO1_BASE        IOMEM(0xE0003000)
+#define MSM_GPIO1_PHYS        0xAC001000
+#define MSM_GPIO1_SIZE        SZ_4K
+
+#define MSM_GPIO2_BASE        IOMEM(0xE0004000)
+#define MSM_GPIO2_PHYS        0xAC101000
+#define MSM_GPIO2_SIZE        SZ_4K
+
+#define MSM_CLK_CTL_BASE      IOMEM(0xE0005000)
+#define MSM_CLK_CTL_PHYS      0xAB800000
+#define MSM_CLK_CTL_SIZE      SZ_4K
+
+#define MSM_CLK_CTL_SH2_BASE  IOMEM(0xE0006000)
+#define MSM_CLK_CTL_SH2_PHYS  0xABA01000
+#define MSM_CLK_CTL_SH2_SIZE  SZ_4K
+
+#define MSM_ACC_BASE          IOMEM(0xE0007000)
+#define MSM_ACC_PHYS          0xC0101000
+#define MSM_ACC_SIZE          SZ_4K
+
+#define MSM_SAW_BASE          IOMEM(0xE0008000)
+#define MSM_SAW_PHYS          0xC0102000
+#define MSM_SAW_SIZE          SZ_4K
+
+#define MSM_GCC_BASE         IOMEM(0xE0009000)
+#define MSM_GCC_PHYS         0xC0182000
+#define MSM_GCC_SIZE         SZ_4K
+
+#define MSM_TCSR_BASE        IOMEM(0xE000A000)
+#define MSM_TCSR_PHYS        0xAB600000
+#define MSM_TCSR_SIZE        SZ_4K
+
+#define MSM_SHARED_RAM_BASE   IOMEM(0xE0100000)
+#define MSM_SHARED_RAM_PHYS   0x00100000
+#define MSM_SHARED_RAM_SIZE   SZ_1M
+
+#define MSM_UART1_PHYS        0xACA00000
+#define MSM_UART1_SIZE        SZ_4K
+
+#define MSM_UART2_PHYS        0xACB00000
+#define MSM_UART2_SIZE        SZ_4K
+
+#define MSM_UART3_PHYS        0xACC00000
+#define MSM_UART3_SIZE        SZ_4K
+
+#ifdef CONFIG_MSM_DEBUG_UART
+#define MSM_DEBUG_UART_BASE   0xE1000000
+#if CONFIG_MSM_DEBUG_UART == 1
+#define MSM_DEBUG_UART_PHYS   MSM_UART1_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 2
+#define MSM_DEBUG_UART_PHYS   MSM_UART2_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 3
+#define MSM_DEBUG_UART_PHYS   MSM_UART3_PHYS
+#endif
+#define MSM_DEBUG_UART_SIZE   SZ_4K
+#endif
+
+#define MSM_MDC_BASE         IOMEM(0xE0200000)
+#define MSM_MDC_PHYS         0xAA500000
+#define MSM_MDC_SIZE         SZ_1M
+
+#define MSM_AD5_BASE          IOMEM(0xE0300000)
+#define MSM_AD5_PHYS          0xA7000000
+#define MSM_AD5_SIZE          (SZ_1M*13)
+
+#endif
diff --git a/arch/arm/mach-msm/include/mach/msm_iomap-8x50.h b/arch/arm/mach-msm/include/mach/msm_iomap-8x50.h
new file mode 100644 (file)
index 0000000..acc819e
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ *
+ * The MSM peripherals are spread all over across 768MB of physical
+ * space, which makes just having a simple IO_ADDRESS macro to slide
+ * them into the right virtual location rough.  Instead, we will
+ * provide a master phys->virt mapping for peripherals here.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_IOMAP_8X50_H
+#define __ASM_ARCH_MSM_IOMAP_8X50_H
+
+/* Physical base address and size of peripherals.
+ * Ordered by the virtual base addresses they will be mapped at.
+ *
+ * MSM_VIC_BASE must be an value that can be loaded via a "mov"
+ * instruction, otherwise entry-macro.S will not compile.
+ *
+ * If you add or remove entries here, you'll want to edit the
+ * msm_io_desc array in arch/arm/mach-msm/io.c to reflect your
+ * changes.
+ *
+ */
+
+#define MSM_VIC_BASE          IOMEM(0xE0000000)
+#define MSM_VIC_PHYS          0xAC000000
+#define MSM_VIC_SIZE          SZ_4K
+
+#define MSM_CSR_BASE          IOMEM(0xE0001000)
+#define MSM_CSR_PHYS          0xAC100000
+#define MSM_CSR_SIZE          SZ_4K
+
+#define MSM_TMR_PHYS          MSM_CSR_PHYS
+#define MSM_TMR_BASE          MSM_CSR_BASE
+#define MSM_TMR_SIZE          SZ_4K
+
+#define MSM_GPT_BASE          MSM_TMR_BASE
+#define MSM_DGT_BASE          (MSM_TMR_BASE + 0x10)
+
+#define MSM_DMOV_BASE         IOMEM(0xE0002000)
+#define MSM_DMOV_PHYS         0xA9700000
+#define MSM_DMOV_SIZE         SZ_4K
+
+#define MSM_GPIO1_BASE        IOMEM(0xE0003000)
+#define MSM_GPIO1_PHYS        0xA9000000
+#define MSM_GPIO1_SIZE        SZ_4K
+
+#define MSM_GPIO2_BASE        IOMEM(0xE0004000)
+#define MSM_GPIO2_PHYS        0xA9100000
+#define MSM_GPIO2_SIZE        SZ_4K
+
+#define MSM_CLK_CTL_BASE      IOMEM(0xE0005000)
+#define MSM_CLK_CTL_PHYS      0xA8600000
+#define MSM_CLK_CTL_SIZE      SZ_4K
+
+#define MSM_SIRC_BASE         IOMEM(0xE1006000)
+#define MSM_SIRC_PHYS         0xAC200000
+#define MSM_SIRC_SIZE         SZ_4K
+
+#define MSM_SCPLL_BASE        IOMEM(0xE1007000)
+#define MSM_SCPLL_PHYS        0xA8800000
+#define MSM_SCPLL_SIZE        SZ_4K
+
+#ifdef CONFIG_MSM_SOC_REV_A
+#define MSM_SMI_BASE 0xE0000000
+#else
+#define MSM_SMI_BASE 0x00000000
+#endif
+
+#define MSM_SHARED_RAM_BASE   IOMEM(0xE0100000)
+#define MSM_SHARED_RAM_PHYS (MSM_SMI_BASE + 0x00100000)
+#define MSM_SHARED_RAM_SIZE   SZ_1M
+
+#define MSM_UART1_PHYS        0xA9A00000
+#define MSM_UART1_SIZE        SZ_4K
+
+#define MSM_UART2_PHYS        0xA9B00000
+#define MSM_UART2_SIZE        SZ_4K
+
+#define MSM_UART3_PHYS        0xA9C00000
+#define MSM_UART3_SIZE        SZ_4K
+
+#ifdef CONFIG_MSM_DEBUG_UART
+#define MSM_DEBUG_UART_BASE   0xE1000000
+#if CONFIG_MSM_DEBUG_UART == 1
+#define MSM_DEBUG_UART_PHYS   MSM_UART1_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 2
+#define MSM_DEBUG_UART_PHYS   MSM_UART2_PHYS
+#elif CONFIG_MSM_DEBUG_UART == 3
+#define MSM_DEBUG_UART_PHYS   MSM_UART3_PHYS
+#endif
+#define MSM_DEBUG_UART_SIZE   SZ_4K
+#endif
+
+#define MSM_MDC_BASE         IOMEM(0xE0200000)
+#define MSM_MDC_PHYS         0xAA500000
+#define MSM_MDC_SIZE         SZ_1M
+
+#define MSM_AD5_BASE          IOMEM(0xE0300000)
+#define MSM_AD5_PHYS          0xAC000000
+#define MSM_AD5_SIZE          (SZ_1M*13)
+
+
+#define MSM_I2C_SIZE          SZ_4K
+#define MSM_I2C_PHYS          0xA9900000
+
+#define MSM_HSUSB_PHYS        0xA0800000
+#define MSM_HSUSB_SIZE        SZ_1K
+
+#define MSM_NAND_PHYS           0xA0A00000
+
+
+#define MSM_TSIF_PHYS        (0xa0100000)
+#define MSM_TSIF_SIZE        (0x200)
+
+#define MSM_TSSC_PHYS         0xAA300000
+
+#define MSM_UART1DM_PHYS      0xA0200000
+#define MSM_UART2DM_PHYS      0xA0900000
+
+
+#define MSM_SDC1_PHYS          0xA0400000
+#define MSM_SDC1_SIZE          SZ_4K
+
+#define MSM_SDC2_PHYS          0xA0500000
+#define MSM_SDC2_SIZE          SZ_4K
+
+#define MSM_SDC3_PHYS          0xA0600000
+#define MSM_SDC3_SIZE           SZ_4K
+
+#define MSM_SDC4_PHYS          0xA0700000
+#define MSM_SDC4_SIZE          SZ_4K
+
+#endif
index 9dae1a9..e6b1821 100644 (file)
@@ -1,6 +1,6 @@
-/* arch/arm/mach-msm/include/mach/msm_iomap.h
- *
+/*
  * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
  * Author: Brian Swetland <swetland@google.com>
  *
  * This software is licensed under the terms of the GNU General Public
 #define IOMEM(x)       ((void __force __iomem *)(x))
 #endif
 
-#define MSM_VIC_BASE          IOMEM(0xE0000000)
-#define MSM_VIC_PHYS          0xC0000000
-#define MSM_VIC_SIZE          SZ_4K
-
-#define MSM_CSR_BASE          IOMEM(0xE0001000)
-#define MSM_CSR_PHYS          0xC0100000
-#define MSM_CSR_SIZE          SZ_4K
-
-#define MSM_GPT_PHYS          MSM_CSR_PHYS
-#define MSM_GPT_BASE          MSM_CSR_BASE
-#define MSM_GPT_SIZE          SZ_4K
-
-#define MSM_DMOV_BASE         IOMEM(0xE0002000)
-#define MSM_DMOV_PHYS         0xA9700000
-#define MSM_DMOV_SIZE         SZ_4K
-
-#define MSM_GPIO1_BASE        IOMEM(0xE0003000)
-#define MSM_GPIO1_PHYS        0xA9200000
-#define MSM_GPIO1_SIZE        SZ_4K
-
-#define MSM_GPIO2_BASE        IOMEM(0xE0004000)
-#define MSM_GPIO2_PHYS        0xA9300000
-#define MSM_GPIO2_SIZE        SZ_4K
-
-#define MSM_CLK_CTL_BASE      IOMEM(0xE0005000)
-#define MSM_CLK_CTL_PHYS      0xA8600000
-#define MSM_CLK_CTL_SIZE      SZ_4K
-
-#define MSM_SHARED_RAM_BASE   IOMEM(0xE0100000)
-#define MSM_SHARED_RAM_PHYS   0x01F00000
-#define MSM_SHARED_RAM_SIZE   SZ_1M
-
-#define MSM_UART1_PHYS        0xA9A00000
-#define MSM_UART1_SIZE        SZ_4K
-
-#define MSM_UART2_PHYS        0xA9B00000
-#define MSM_UART2_SIZE        SZ_4K
-
-#define MSM_UART3_PHYS        0xA9C00000
-#define MSM_UART3_SIZE        SZ_4K
-
-#ifdef CONFIG_MSM_DEBUG_UART
-#define MSM_DEBUG_UART_BASE   0xE1000000
-#if CONFIG_MSM_DEBUG_UART == 1
-#define MSM_DEBUG_UART_PHYS   MSM_UART1_PHYS
-#elif CONFIG_MSM_DEBUG_UART == 2
-#define MSM_DEBUG_UART_PHYS   MSM_UART2_PHYS
-#elif CONFIG_MSM_DEBUG_UART == 3
-#define MSM_DEBUG_UART_PHYS   MSM_UART3_PHYS
-#endif
-#define MSM_DEBUG_UART_SIZE   SZ_4K
+#if defined(CONFIG_ARCH_MSM7X30)
+#include "msm_iomap-7x30.h"
+#elif defined(CONFIG_ARCH_QSD8X50)
+#include "msm_iomap-8x50.h"
+#else
+#include "msm_iomap-7x00.h"
 #endif
 
-#define MSM_SDC1_PHYS         0xA0400000
-#define MSM_SDC1_SIZE         SZ_4K
-
-#define MSM_SDC2_PHYS         0xA0500000
-#define MSM_SDC2_SIZE         SZ_4K
-
-#define MSM_SDC3_PHYS         0xA0600000
-#define MSM_SDC3_SIZE         SZ_4K
-
-#define MSM_SDC4_PHYS         0xA0700000
-#define MSM_SDC4_SIZE         SZ_4K
-
-#define MSM_I2C_PHYS          0xA9900000
-#define MSM_I2C_SIZE          SZ_4K
-
-#define MSM_HSUSB_PHYS        0xA0800000
-#define MSM_HSUSB_SIZE        SZ_4K
-
-#define MSM_PMDH_PHYS         0xAA600000
-#define MSM_PMDH_SIZE         SZ_4K
-
-#define MSM_EMDH_PHYS         0xAA700000
-#define MSM_EMDH_SIZE         SZ_4K
-
-#define MSM_MDP_PHYS          0xAA200000
-#define MSM_MDP_SIZE          0x000F0000
-
-#define MSM_MDC_PHYS         0xAA500000
-#define MSM_MDC_SIZE         SZ_1M
-
-#define MSM_AD5_PHYS          0xAC000000
-#define MSM_AD5_SIZE          (SZ_1M*13)
-
-
 #endif
diff --git a/arch/arm/mach-msm/include/mach/msm_smd.h b/arch/arm/mach-msm/include/mach/msm_smd.h
new file mode 100644 (file)
index 0000000..029463e
--- /dev/null
@@ -0,0 +1,109 @@
+/* linux/include/asm-arm/arch-msm/msm_smd.h
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_SMD_H
+#define __ASM_ARCH_MSM_SMD_H
+
+typedef struct smd_channel smd_channel_t;
+
+extern int (*msm_check_for_modem_crash)(void);
+
+/* warning: notify() may be called before open returns */
+int smd_open(const char *name, smd_channel_t **ch, void *priv,
+            void (*notify)(void *priv, unsigned event));
+
+#define SMD_EVENT_DATA 1
+#define SMD_EVENT_OPEN 2
+#define SMD_EVENT_CLOSE 3
+
+int smd_close(smd_channel_t *ch);
+
+/* passing a null pointer for data reads and discards */
+int smd_read(smd_channel_t *ch, void *data, int len);
+
+/* Write to stream channels may do a partial write and return
+** the length actually written.
+** Write to packet channels will never do a partial write --
+** it will return the requested length written or an error.
+*/
+int smd_write(smd_channel_t *ch, const void *data, int len);
+int smd_write_atomic(smd_channel_t *ch, const void *data, int len);
+
+int smd_write_avail(smd_channel_t *ch);
+int smd_read_avail(smd_channel_t *ch);
+
+/* Returns the total size of the current packet being read.
+** Returns 0 if no packets available or a stream channel.
+*/
+int smd_cur_packet_size(smd_channel_t *ch);
+
+/* used for tty unthrottling and the like -- causes the notify()
+** callback to be called from the same lock context as is used
+** when it is called from channel updates
+*/
+void smd_kick(smd_channel_t *ch);
+
+
+#if 0
+/* these are interruptable waits which will block you until the specified
+** number of bytes are readable or writable.
+*/
+int smd_wait_until_readable(smd_channel_t *ch, int bytes);
+int smd_wait_until_writable(smd_channel_t *ch, int bytes);
+#endif
+
+typedef enum {
+       SMD_PORT_DS = 0,
+       SMD_PORT_DIAG,
+       SMD_PORT_RPC_CALL,
+       SMD_PORT_RPC_REPLY,
+       SMD_PORT_BT,
+       SMD_PORT_CONTROL,
+       SMD_PORT_MEMCPY_SPARE1,
+       SMD_PORT_DATA1,
+       SMD_PORT_DATA2,
+       SMD_PORT_DATA3,
+       SMD_PORT_DATA4,
+       SMD_PORT_DATA5,
+       SMD_PORT_DATA6,
+       SMD_PORT_DATA7,
+       SMD_PORT_DATA8,
+       SMD_PORT_DATA9,
+       SMD_PORT_DATA10,
+       SMD_PORT_DATA11,
+       SMD_PORT_DATA12,
+       SMD_PORT_DATA13,
+       SMD_PORT_DATA14,
+       SMD_PORT_DATA15,
+       SMD_PORT_DATA16,
+       SMD_PORT_DATA17,
+       SMD_PORT_DATA18,
+       SMD_PORT_DATA19,
+       SMD_PORT_DATA20,
+       SMD_PORT_GPS_NMEA,
+       SMD_PORT_BRIDGE_1,
+       SMD_PORT_BRIDGE_2,
+       SMD_PORT_BRIDGE_3,
+       SMD_PORT_BRIDGE_4,
+       SMD_PORT_BRIDGE_5,
+       SMD_PORT_LOOPBACK,
+       SMD_PORT_CS_APPS_MODEM,
+       SMD_PORT_CS_APPS_DSP,
+       SMD_PORT_CS_MODEM_DSP,
+       SMD_NUM_PORTS,
+} smd_port_id_type;
+
+#endif
diff --git a/arch/arm/mach-msm/include/mach/sirc.h b/arch/arm/mach-msm/include/mach/sirc.h
new file mode 100644 (file)
index 0000000..7281337
--- /dev/null
@@ -0,0 +1,115 @@
+/* Copyright (c) 2008-2009, Code Aurora Forum. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *     * Redistributions of source code must retain the above copyright
+ *       notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials provided
+ *       with the distribution.
+ *     * Neither the name of Code Aurora Forum, Inc. nor the names of its
+ *       contributors may be used to endorse or promote products derived
+ *       from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#ifndef __ASM_ARCH_MSM_SIRC_H
+#define __ASM_ARCH_MSM_SIRC_H
+
+struct sirc_regs_t {
+       void    *int_enable;
+       void    *int_enable_clear;
+       void    *int_enable_set;
+       void    *int_type;
+       void    *int_polarity;
+       void    *int_clear;
+};
+
+struct sirc_cascade_regs {
+       void    *int_status;
+       unsigned int    cascade_irq;
+};
+
+void msm_init_sirc(void);
+void msm_sirc_enter_sleep(void);
+void msm_sirc_exit_sleep(void);
+
+#if defined(CONFIG_ARCH_MSM_SCORPION)
+
+#include <mach/msm_iomap.h>
+
+/*
+ * Secondary interrupt controller interrupts
+ */
+
+#define FIRST_SIRC_IRQ (NR_MSM_IRQS + NR_GPIO_IRQS)
+
+#define INT_UART1                     (FIRST_SIRC_IRQ + 0)
+#define INT_UART2                     (FIRST_SIRC_IRQ + 1)
+#define INT_UART3                     (FIRST_SIRC_IRQ + 2)
+#define INT_UART1_RX                  (FIRST_SIRC_IRQ + 3)
+#define INT_UART2_RX                  (FIRST_SIRC_IRQ + 4)
+#define INT_UART3_RX                  (FIRST_SIRC_IRQ + 5)
+#define INT_SPI_INPUT                 (FIRST_SIRC_IRQ + 6)
+#define INT_SPI_OUTPUT                (FIRST_SIRC_IRQ + 7)
+#define INT_SPI_ERROR                 (FIRST_SIRC_IRQ + 8)
+#define INT_GPIO_GROUP1               (FIRST_SIRC_IRQ + 9)
+#define INT_GPIO_GROUP2               (FIRST_SIRC_IRQ + 10)
+#define INT_GPIO_GROUP1_SECURE        (FIRST_SIRC_IRQ + 11)
+#define INT_GPIO_GROUP2_SECURE        (FIRST_SIRC_IRQ + 12)
+#define INT_AVS_SVIC                  (FIRST_SIRC_IRQ + 13)
+#define INT_AVS_REQ_UP                (FIRST_SIRC_IRQ + 14)
+#define INT_AVS_REQ_DOWN              (FIRST_SIRC_IRQ + 15)
+#define INT_PBUS_ERR                  (FIRST_SIRC_IRQ + 16)
+#define INT_AXI_ERR                   (FIRST_SIRC_IRQ + 17)
+#define INT_SMI_ERR                   (FIRST_SIRC_IRQ + 18)
+#define INT_EBI1_ERR                  (FIRST_SIRC_IRQ + 19)
+#define INT_IMEM_ERR                  (FIRST_SIRC_IRQ + 20)
+#define INT_TEMP_SENSOR               (FIRST_SIRC_IRQ + 21)
+#define INT_TV_ENC                    (FIRST_SIRC_IRQ + 22)
+#define INT_GRP2D                     (FIRST_SIRC_IRQ + 23)
+#define INT_GSBI_QUP                  (FIRST_SIRC_IRQ + 24)
+#define INT_SC_ACG                    (FIRST_SIRC_IRQ + 25)
+#define INT_WDT0                      (FIRST_SIRC_IRQ + 26)
+#define INT_WDT1                      (FIRST_SIRC_IRQ + 27)
+
+#if defined(CONFIG_MSM_SOC_REV_A)
+#define NR_SIRC_IRQS                  28
+#define SIRC_MASK                     0x0FFFFFFF
+#else
+#define NR_SIRC_IRQS                  23
+#define SIRC_MASK                     0x007FFFFF
+#endif
+
+#define LAST_SIRC_IRQ                 (FIRST_SIRC_IRQ + NR_SIRC_IRQS - 1)
+
+#define SPSS_SIRC_INT_SELECT          (MSM_SIRC_BASE + 0x00)
+#define SPSS_SIRC_INT_ENABLE          (MSM_SIRC_BASE + 0x04)
+#define SPSS_SIRC_INT_ENABLE_CLEAR    (MSM_SIRC_BASE + 0x08)
+#define SPSS_SIRC_INT_ENABLE_SET      (MSM_SIRC_BASE + 0x0C)
+#define SPSS_SIRC_INT_TYPE            (MSM_SIRC_BASE + 0x10)
+#define SPSS_SIRC_INT_POLARITY        (MSM_SIRC_BASE + 0x14)
+#define SPSS_SIRC_SECURITY            (MSM_SIRC_BASE + 0x18)
+#define SPSS_SIRC_IRQ_STATUS          (MSM_SIRC_BASE + 0x1C)
+#define SPSS_SIRC_IRQ1_STATUS         (MSM_SIRC_BASE + 0x20)
+#define SPSS_SIRC_RAW_STATUS          (MSM_SIRC_BASE + 0x24)
+#define SPSS_SIRC_INT_CLEAR           (MSM_SIRC_BASE + 0x28)
+#define SPSS_SIRC_SOFT_INT            (MSM_SIRC_BASE + 0x2C)
+
+#endif
+
+#endif
index 574ccc4..d2e83f4 100644 (file)
@@ -21,3 +21,8 @@ static inline void arch_reset(char mode, const char *cmd)
 {
        for (;;) ;  /* depends on IPC w/ other core */
 }
+
+/* low level hardware reset hook -- for example, hitting the
+ * PSHOLD line on the PMIC to hard reset the system
+ */
+extern void (*msm_hw_reset_hook)(void);
index 9f9e25c..6626e78 100644 (file)
@@ -23,7 +23,7 @@ struct vreg *vreg_get(struct device *dev, const char *id);
 void vreg_put(struct vreg *vreg);
 
 int vreg_enable(struct vreg *vreg);
-void vreg_disable(struct vreg *vreg);
+int vreg_disable(struct vreg *vreg);
 int vreg_set_level(struct vreg *vreg, unsigned mv);
 
 #endif
index 05f96b7..1c05060 100644 (file)
@@ -1,8 +1,9 @@
 /* arch/arm/mach-msm/io.c
  *
- * MSM7K io support
+ * MSM7K, QSD io support
  *
  * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
  * Author: Brian Swetland <swetland@google.com>
  *
  * This software is licensed under the terms of the GNU General Public
@@ -34,6 +35,8 @@
                .type = MT_DEVICE_NONSHARED, \
         }
 
+#if defined(CONFIG_ARCH_MSM7X00A) || defined(CONFIG_ARCH_MSM7X27) \
+       || defined(CONFIG_ARCH_MSM7X25)
 static struct map_desc msm_io_desc[] __initdata = {
        MSM_DEVICE(VIC),
        MSM_DEVICE(CSR),
@@ -44,10 +47,13 @@ static struct map_desc msm_io_desc[] __initdata = {
        MSM_DEVICE(CLK_CTL),
 #ifdef CONFIG_MSM_DEBUG_UART
        MSM_DEVICE(DEBUG_UART),
+#endif
+#ifdef CONFIG_ARCH_MSM7X30
+       MSM_DEVICE(GCC),
 #endif
        {
                .virtual =  (unsigned long) MSM_SHARED_RAM_BASE,
-               .pfn =      __phys_to_pfn(MSM_SHARED_RAM_PHYS),
+               .pfn = __phys_to_pfn(MSM_SHARED_RAM_PHYS),
                .length =   MSM_SHARED_RAM_SIZE,
                .type =     MT_DEVICE,
        },
@@ -60,9 +66,72 @@ void __init msm_map_common_io(void)
         * pages are peripheral interface or not.
         */
        asm("mcr p15, 0, %0, c15, c2, 4" : : "r" (0));
-
        iotable_init(msm_io_desc, ARRAY_SIZE(msm_io_desc));
 }
+#endif
+
+#ifdef CONFIG_ARCH_QSD8X50
+static struct map_desc qsd8x50_io_desc[] __initdata = {
+       MSM_DEVICE(VIC),
+       MSM_DEVICE(CSR),
+       MSM_DEVICE(TMR),
+       MSM_DEVICE(DMOV),
+       MSM_DEVICE(GPIO1),
+       MSM_DEVICE(GPIO2),
+       MSM_DEVICE(CLK_CTL),
+       MSM_DEVICE(SIRC),
+       MSM_DEVICE(SCPLL),
+       MSM_DEVICE(AD5),
+       MSM_DEVICE(MDC),
+#ifdef CONFIG_MSM_DEBUG_UART
+       MSM_DEVICE(DEBUG_UART),
+#endif
+       {
+               .virtual =  (unsigned long) MSM_SHARED_RAM_BASE,
+               .pfn = __phys_to_pfn(MSM_SHARED_RAM_PHYS),
+               .length =   MSM_SHARED_RAM_SIZE,
+               .type =     MT_DEVICE,
+       },
+};
+
+void __init msm_map_qsd8x50_io(void)
+{
+       iotable_init(qsd8x50_io_desc, ARRAY_SIZE(qsd8x50_io_desc));
+}
+#endif /* CONFIG_ARCH_QSD8X50 */
+
+#ifdef CONFIG_ARCH_MSM7X30
+static struct map_desc msm7x30_io_desc[] __initdata = {
+       MSM_DEVICE(VIC),
+       MSM_DEVICE(CSR),
+       MSM_DEVICE(TMR),
+       MSM_DEVICE(DMOV),
+       MSM_DEVICE(GPIO1),
+       MSM_DEVICE(GPIO2),
+       MSM_DEVICE(CLK_CTL),
+       MSM_DEVICE(CLK_CTL_SH2),
+       MSM_DEVICE(AD5),
+       MSM_DEVICE(MDC),
+       MSM_DEVICE(ACC),
+       MSM_DEVICE(SAW),
+       MSM_DEVICE(GCC),
+       MSM_DEVICE(TCSR),
+#ifdef CONFIG_MSM_DEBUG_UART
+       MSM_DEVICE(DEBUG_UART),
+#endif
+       {
+               .virtual =  (unsigned long) MSM_SHARED_RAM_BASE,
+               .pfn = __phys_to_pfn(MSM_SHARED_RAM_PHYS),
+               .length =   MSM_SHARED_RAM_SIZE,
+               .type =     MT_DEVICE,
+       },
+};
+
+void __init msm_map_msm7x30_io(void)
+{
+       iotable_init(msm7x30_io_desc, ARRAY_SIZE(msm7x30_io_desc));
+}
+#endif /* CONFIG_ARCH_MSM7X30 */
 
 void __iomem *
 __msm_ioremap(unsigned long phys_addr, size_t size, unsigned int mtype)
diff --git a/arch/arm/mach-msm/irq-vic.c b/arch/arm/mach-msm/irq-vic.c
new file mode 100644 (file)
index 0000000..99f2c34
--- /dev/null
@@ -0,0 +1,365 @@
+/*
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <linux/timer.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+
+#include <asm/cacheflush.h>
+
+#include <mach/hardware.h>
+
+#include <mach/msm_iomap.h>
+
+#include "smd_private.h"
+
+enum {
+       IRQ_DEBUG_SLEEP_INT_TRIGGER = 1U << 0,
+       IRQ_DEBUG_SLEEP_INT = 1U << 1,
+       IRQ_DEBUG_SLEEP_ABORT = 1U << 2,
+       IRQ_DEBUG_SLEEP = 1U << 3,
+       IRQ_DEBUG_SLEEP_REQUEST = 1U << 4,
+};
+static int msm_irq_debug_mask;
+module_param_named(debug_mask, msm_irq_debug_mask, int,
+                  S_IRUGO | S_IWUSR | S_IWGRP);
+
+#define VIC_REG(off) (MSM_VIC_BASE + (off))
+#define VIC_INT_TO_REG_ADDR(base, irq) (base + (irq / 32) * 4)
+#define VIC_INT_TO_REG_INDEX(irq) ((irq >> 5) & 3)
+
+#define VIC_INT_SELECT0     VIC_REG(0x0000)  /* 1: FIQ, 0: IRQ */
+#define VIC_INT_SELECT1     VIC_REG(0x0004)  /* 1: FIQ, 0: IRQ */
+#define VIC_INT_SELECT2     VIC_REG(0x0008)  /* 1: FIQ, 0: IRQ */
+#define VIC_INT_SELECT3     VIC_REG(0x000C)  /* 1: FIQ, 0: IRQ */
+#define VIC_INT_EN0         VIC_REG(0x0010)
+#define VIC_INT_EN1         VIC_REG(0x0014)
+#define VIC_INT_EN2         VIC_REG(0x0018)
+#define VIC_INT_EN3         VIC_REG(0x001C)
+#define VIC_INT_ENCLEAR0    VIC_REG(0x0020)
+#define VIC_INT_ENCLEAR1    VIC_REG(0x0024)
+#define VIC_INT_ENCLEAR2    VIC_REG(0x0028)
+#define VIC_INT_ENCLEAR3    VIC_REG(0x002C)
+#define VIC_INT_ENSET0      VIC_REG(0x0030)
+#define VIC_INT_ENSET1      VIC_REG(0x0034)
+#define VIC_INT_ENSET2      VIC_REG(0x0038)
+#define VIC_INT_ENSET3      VIC_REG(0x003C)
+#define VIC_INT_TYPE0       VIC_REG(0x0040)  /* 1: EDGE, 0: LEVEL  */
+#define VIC_INT_TYPE1       VIC_REG(0x0044)  /* 1: EDGE, 0: LEVEL  */
+#define VIC_INT_TYPE2       VIC_REG(0x0048)  /* 1: EDGE, 0: LEVEL  */
+#define VIC_INT_TYPE3       VIC_REG(0x004C)  /* 1: EDGE, 0: LEVEL  */
+#define VIC_INT_POLARITY0   VIC_REG(0x0050)  /* 1: NEG, 0: POS */
+#define VIC_INT_POLARITY1   VIC_REG(0x0054)  /* 1: NEG, 0: POS */
+#define VIC_INT_POLARITY2   VIC_REG(0x0058)  /* 1: NEG, 0: POS */
+#define VIC_INT_POLARITY3   VIC_REG(0x005C)  /* 1: NEG, 0: POS */
+#define VIC_NO_PEND_VAL     VIC_REG(0x0060)
+
+#if defined(CONFIG_ARCH_MSM_SCORPION)
+#define VIC_NO_PEND_VAL_FIQ VIC_REG(0x0064)
+#define VIC_INT_MASTEREN    VIC_REG(0x0068)  /* 1: IRQ, 2: FIQ     */
+#define VIC_CONFIG          VIC_REG(0x006C)  /* 1: USE SC VIC */
+#else
+#define VIC_INT_MASTEREN    VIC_REG(0x0064)  /* 1: IRQ, 2: FIQ     */
+#define VIC_PROTECTION      VIC_REG(0x006C)  /* 1: ENABLE          */
+#define VIC_CONFIG          VIC_REG(0x0068)  /* 1: USE ARM1136 VIC */
+#endif
+
+#define VIC_IRQ_STATUS0     VIC_REG(0x0080)
+#define VIC_IRQ_STATUS1     VIC_REG(0x0084)
+#define VIC_IRQ_STATUS2     VIC_REG(0x0088)
+#define VIC_IRQ_STATUS3     VIC_REG(0x008C)
+#define VIC_FIQ_STATUS0     VIC_REG(0x0090)
+#define VIC_FIQ_STATUS1     VIC_REG(0x0094)
+#define VIC_FIQ_STATUS2     VIC_REG(0x0098)
+#define VIC_FIQ_STATUS3     VIC_REG(0x009C)
+#define VIC_RAW_STATUS0     VIC_REG(0x00A0)
+#define VIC_RAW_STATUS1     VIC_REG(0x00A4)
+#define VIC_RAW_STATUS2     VIC_REG(0x00A8)
+#define VIC_RAW_STATUS3     VIC_REG(0x00AC)
+#define VIC_INT_CLEAR0      VIC_REG(0x00B0)
+#define VIC_INT_CLEAR1      VIC_REG(0x00B4)
+#define VIC_INT_CLEAR2      VIC_REG(0x00B8)
+#define VIC_INT_CLEAR3      VIC_REG(0x00BC)
+#define VIC_SOFTINT0        VIC_REG(0x00C0)
+#define VIC_SOFTINT1        VIC_REG(0x00C4)
+#define VIC_SOFTINT2        VIC_REG(0x00C8)
+#define VIC_SOFTINT3        VIC_REG(0x00CC)
+#define VIC_IRQ_VEC_RD      VIC_REG(0x00D0)  /* pending int # */
+#define VIC_IRQ_VEC_PEND_RD VIC_REG(0x00D4)  /* pending vector addr */
+#define VIC_IRQ_VEC_WR      VIC_REG(0x00D8)
+
+#if defined(CONFIG_ARCH_MSM_SCORPION)
+#define VIC_FIQ_VEC_RD      VIC_REG(0x00DC)
+#define VIC_FIQ_VEC_PEND_RD VIC_REG(0x00E0)
+#define VIC_FIQ_VEC_WR      VIC_REG(0x00E4)
+#define VIC_IRQ_IN_SERVICE  VIC_REG(0x00E8)
+#define VIC_IRQ_IN_STACK    VIC_REG(0x00EC)
+#define VIC_FIQ_IN_SERVICE  VIC_REG(0x00F0)
+#define VIC_FIQ_IN_STACK    VIC_REG(0x00F4)
+#define VIC_TEST_BUS_SEL    VIC_REG(0x00F8)
+#define VIC_IRQ_CTRL_CONFIG VIC_REG(0x00FC)
+#else
+#define VIC_IRQ_IN_SERVICE  VIC_REG(0x00E0)
+#define VIC_IRQ_IN_STACK    VIC_REG(0x00E4)
+#define VIC_TEST_BUS_SEL    VIC_REG(0x00E8)
+#endif
+
+#define VIC_VECTPRIORITY(n) VIC_REG(0x0200+((n) * 4))
+#define VIC_VECTADDR(n)     VIC_REG(0x0400+((n) * 4))
+
+#if defined(CONFIG_ARCH_MSM7X30)
+#define VIC_NUM_REGS       4
+#else
+#define VIC_NUM_REGS       2
+#endif
+
+#if VIC_NUM_REGS == 2
+#define DPRINT_REGS(base_reg, format, ...)                             \
+       printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__,              \
+                       readl(base_reg ## 0), readl(base_reg ## 1))
+#define DPRINT_ARRAY(array, format, ...)                               \
+       printk(KERN_INFO format " %x %x\n", ##__VA_ARGS__,              \
+                       array[0], array[1])
+#elif VIC_NUM_REGS == 4
+#define DPRINT_REGS(base_reg, format, ...) \
+       printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__,        \
+                       readl(base_reg ## 0), readl(base_reg ## 1),     \
+                       readl(base_reg ## 2), readl(base_reg ## 3))
+#define DPRINT_ARRAY(array, format, ...)                               \
+       printk(KERN_INFO format " %x %x %x %x\n", ##__VA_ARGS__,        \
+                       array[0], array[1],                             \
+                       array[2], array[3])
+#else
+#error "VIC_NUM_REGS set to illegal value"
+#endif
+
+static uint32_t msm_irq_smsm_wake_enable[2];
+static struct {
+       uint32_t int_en[2];
+       uint32_t int_type;
+       uint32_t int_polarity;
+       uint32_t int_select;
+} msm_irq_shadow_reg[VIC_NUM_REGS];
+static uint32_t msm_irq_idle_disable[VIC_NUM_REGS];
+
+#define SMSM_FAKE_IRQ (0xff)
+static uint8_t msm_irq_to_smsm[NR_IRQS] = {
+       [INT_MDDI_EXT] = 1,
+       [INT_MDDI_PRI] = 2,
+       [INT_MDDI_CLIENT] = 3,
+       [INT_USB_OTG] = 4,
+
+       [INT_PWB_I2C] = 5,
+       [INT_SDC1_0] = 6,
+       [INT_SDC1_1] = 7,
+       [INT_SDC2_0] = 8,
+
+       [INT_SDC2_1] = 9,
+       [INT_ADSP_A9_A11] = 10,
+       [INT_UART1] = 11,
+       [INT_UART2] = 12,
+
+       [INT_UART3] = 13,
+       [INT_UART1_RX] = 14,
+       [INT_UART2_RX] = 15,
+       [INT_UART3_RX] = 16,
+
+       [INT_UART1DM_IRQ] = 17,
+       [INT_UART1DM_RX] = 18,
+       [INT_KEYSENSE] = 19,
+#if !defined(CONFIG_ARCH_MSM7X30)
+       [INT_AD_HSSD] = 20,
+#endif
+
+       [INT_NAND_WR_ER_DONE] = 21,
+       [INT_NAND_OP_DONE] = 22,
+       [INT_TCHSCRN1] = 23,
+       [INT_TCHSCRN2] = 24,
+
+       [INT_TCHSCRN_SSBI] = 25,
+       [INT_USB_HS] = 26,
+       [INT_UART2DM_RX] = 27,
+       [INT_UART2DM_IRQ] = 28,
+
+       [INT_SDC4_1] = 29,
+       [INT_SDC4_0] = 30,
+       [INT_SDC3_1] = 31,
+       [INT_SDC3_0] = 32,
+
+       /* fake wakeup interrupts */
+       [INT_GPIO_GROUP1] = SMSM_FAKE_IRQ,
+       [INT_GPIO_GROUP2] = SMSM_FAKE_IRQ,
+       [INT_A9_M2A_0] = SMSM_FAKE_IRQ,
+       [INT_A9_M2A_1] = SMSM_FAKE_IRQ,
+       [INT_A9_M2A_5] = SMSM_FAKE_IRQ,
+       [INT_GP_TIMER_EXP] = SMSM_FAKE_IRQ,
+       [INT_DEBUG_TIMER_EXP] = SMSM_FAKE_IRQ,
+       [INT_ADSP_A11] = SMSM_FAKE_IRQ,
+#ifdef CONFIG_ARCH_QSD8X50
+       [INT_SIRC_0] = SMSM_FAKE_IRQ,
+       [INT_SIRC_1] = SMSM_FAKE_IRQ,
+#endif
+};
+
+static inline void msm_irq_write_all_regs(void __iomem *base, unsigned int val)
+{
+       int i;
+
+       for (i = 0; i < VIC_NUM_REGS; i++)
+               writel(val, base + (i * 4));
+}
+
+static void msm_irq_ack(unsigned int irq)
+{
+       void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_CLEAR0, irq);
+       irq = 1 << (irq & 31);
+       writel(irq, reg);
+}
+
+static void msm_irq_mask(unsigned int irq)
+{
+       void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENCLEAR0, irq);
+       unsigned index = VIC_INT_TO_REG_INDEX(irq);
+       uint32_t mask = 1UL << (irq & 31);
+       int smsm_irq = msm_irq_to_smsm[irq];
+
+       msm_irq_shadow_reg[index].int_en[0] &= ~mask;
+       writel(mask, reg);
+       if (smsm_irq == 0)
+               msm_irq_idle_disable[index] &= ~mask;
+       else {
+               mask = 1UL << (smsm_irq - 1);
+               msm_irq_smsm_wake_enable[0] &= ~mask;
+       }
+}
+
+static void msm_irq_unmask(unsigned int irq)
+{
+       void __iomem *reg = VIC_INT_TO_REG_ADDR(VIC_INT_ENSET0, irq);
+       unsigned index = VIC_INT_TO_REG_INDEX(irq);
+       uint32_t mask = 1UL << (irq & 31);
+       int smsm_irq = msm_irq_to_smsm[irq];
+
+       msm_irq_shadow_reg[index].int_en[0] |= mask;
+       writel(mask, reg);
+
+       if (smsm_irq == 0)
+               msm_irq_idle_disable[index] |= mask;
+       else {
+               mask = 1UL << (smsm_irq - 1);
+               msm_irq_smsm_wake_enable[0] |= mask;
+       }
+}
+
+static int msm_irq_set_wake(unsigned int irq, unsigned int on)
+{
+       unsigned index = VIC_INT_TO_REG_INDEX(irq);
+       uint32_t mask = 1UL << (irq & 31);
+       int smsm_irq = msm_irq_to_smsm[irq];
+
+       if (smsm_irq == 0) {
+               printk(KERN_ERR "msm_irq_set_wake: bad wakeup irq %d\n", irq);
+               return -EINVAL;
+       }
+       if (on)
+               msm_irq_shadow_reg[index].int_en[1] |= mask;
+       else
+               msm_irq_shadow_reg[index].int_en[1] &= ~mask;
+
+       if (smsm_irq == SMSM_FAKE_IRQ)
+               return 0;
+
+       mask = 1UL << (smsm_irq - 1);
+       if (on)
+               msm_irq_smsm_wake_enable[1] |= mask;
+       else
+               msm_irq_smsm_wake_enable[1] &= ~mask;
+       return 0;
+}
+
+static int msm_irq_set_type(unsigned int irq, unsigned int flow_type)
+{
+       void __iomem *treg = VIC_INT_TO_REG_ADDR(VIC_INT_TYPE0, irq);
+       void __iomem *preg = VIC_INT_TO_REG_ADDR(VIC_INT_POLARITY0, irq);
+       unsigned index = VIC_INT_TO_REG_INDEX(irq);
+       int b = 1 << (irq & 31);
+       uint32_t polarity;
+       uint32_t type;
+
+       polarity = msm_irq_shadow_reg[index].int_polarity;
+       if (flow_type & (IRQF_TRIGGER_FALLING | IRQF_TRIGGER_LOW))
+               polarity |= b;
+       if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_HIGH))
+               polarity &= ~b;
+       writel(polarity, preg);
+       msm_irq_shadow_reg[index].int_polarity = polarity;
+
+       type = msm_irq_shadow_reg[index].int_type;
+       if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
+               type |= b;
+               irq_desc[irq].handle_irq = handle_edge_irq;
+       }
+       if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) {
+               type &= ~b;
+               irq_desc[irq].handle_irq = handle_level_irq;
+       }
+       writel(type, treg);
+       msm_irq_shadow_reg[index].int_type = type;
+       return 0;
+}
+
+static struct irq_chip msm_irq_chip = {
+       .name      = "msm",
+       .disable   = msm_irq_mask,
+       .ack       = msm_irq_ack,
+       .mask      = msm_irq_mask,
+       .unmask    = msm_irq_unmask,
+       .set_wake  = msm_irq_set_wake,
+       .set_type  = msm_irq_set_type,
+};
+
+void __init msm_init_irq(void)
+{
+       unsigned n;
+
+       /* select level interrupts */
+       msm_irq_write_all_regs(VIC_INT_TYPE0, 0);
+
+       /* select highlevel interrupts */
+       msm_irq_write_all_regs(VIC_INT_POLARITY0, 0);
+
+       /* select IRQ for all INTs */
+       msm_irq_write_all_regs(VIC_INT_SELECT0, 0);
+
+       /* disable all INTs */
+       msm_irq_write_all_regs(VIC_INT_EN0, 0);
+
+       /* don't use vic */
+       writel(0, VIC_CONFIG);
+
+       /* enable interrupt controller */
+       writel(3, VIC_INT_MASTEREN);
+
+       for (n = 0; n < NR_MSM_IRQS; n++) {
+               set_irq_chip(n, &msm_irq_chip);
+               set_irq_handler(n, handle_level_irq);
+               set_irq_flags(n, IRQF_VALID);
+       }
+}
index 69ca0dd..6c8d5f8 100644 (file)
@@ -101,11 +101,11 @@ static int msm_irq_set_type(unsigned int irq, unsigned int flow_type)
 
        if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
                writel(readl(treg) | b, treg);
-               set_irq_handler(irq, handle_edge_irq);
+               irq_desc[irq].handle_irq = handle_edge_irq;
        }
        if (flow_type & (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW)) {
                writel(readl(treg) & (~b), treg);
-               set_irq_handler(irq, handle_level_irq);
+               irq_desc[irq].handle_irq = handle_level_irq;
        }
        return 0;
 }
diff --git a/arch/arm/mach-msm/last_radio_log.c b/arch/arm/mach-msm/last_radio_log.c
new file mode 100644 (file)
index 0000000..b64ba5a
--- /dev/null
@@ -0,0 +1,82 @@
+/* arch/arm/mach-msm/last_radio_log.c
+ *
+ * Extract the log from a modem crash though SMEM
+ *
+ * Copyright (C) 2007 Google, Inc.
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/proc_fs.h>
+#include <linux/uaccess.h>
+
+#include "smd_private.h"
+
+static void *radio_log_base;
+static size_t radio_log_size;
+
+extern void *smem_item(unsigned id, unsigned *size);
+
+static ssize_t last_radio_log_read(struct file *file, char __user *buf,
+                       size_t len, loff_t *offset)
+{
+       loff_t pos = *offset;
+       ssize_t count;
+
+       if (pos >= radio_log_size)
+               return 0;
+
+       count = min(len, (size_t)(radio_log_size - pos));
+       if (copy_to_user(buf, radio_log_base + pos, count)) {
+               pr_err("%s: copy to user failed\n", __func__);
+               return -EFAULT;
+       }
+
+       *offset += count;
+       return count;
+}
+
+static struct file_operations last_radio_log_fops = {
+       .read = last_radio_log_read
+};
+
+void msm_init_last_radio_log(struct module *owner)
+{
+       struct proc_dir_entry *entry;
+
+       if (last_radio_log_fops.owner) {
+               pr_err("%s: already claimed\n", __func__);
+               return;
+       }
+
+       radio_log_base = smem_item(SMEM_CLKREGIM_BSP, &radio_log_size);
+       if (!radio_log_base) {
+               pr_err("%s: could not retrieve SMEM_CLKREGIM_BSP\n", __func__);
+               return;
+       }
+
+       entry = create_proc_entry("last_radio_log", S_IFREG | S_IRUGO, NULL);
+       if (!entry) {
+               pr_err("%s: could not create proc entry for radio log\n",
+                               __func__);
+               return;
+       }
+
+       pr_err("%s: last radio log is %d bytes long\n", __func__,
+               radio_log_size);
+       last_radio_log_fops.owner = owner;
+       entry->proc_fops = &last_radio_log_fops;
+       entry->size = radio_log_size;
+}
+EXPORT_SYMBOL(msm_init_last_radio_log);
index 915ee70..67e701c 100644 (file)
 
 #include "proc_comm.h"
 
-#define MSM_A2M_INT(n) (MSM_CSR_BASE + 0x400 + (n) * 4)
+static inline void msm_a2m_int(uint32_t irq)
+{
+#if defined(CONFIG_ARCH_MSM7X30)
+       writel(1 << irq, MSM_GCC_BASE + 0x8);
+#else
+       writel(1, MSM_CSR_BASE + 0x400 + (irq * 4));
+#endif
+}
 
 static inline void notify_other_proc_comm(void)
 {
-       writel(1, MSM_A2M_INT(6));
+       msm_a2m_int(6);
 }
 
 #define APP_COMMAND 0x00
@@ -107,4 +114,17 @@ int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2)
        return ret;
 }
 
-
+/*
+ * We need to wait for the ARM9 to at least partially boot
+ * up before we can continue. Since the ARM9 does resource
+ * allocation, if we dont' wait we could end up crashing or in
+ * and unknown state. This function should be called early to
+ * wait on the ARM9.
+ */
+void __init proc_comm_boot_wait(void)
+{
+       void __iomem *base = MSM_SHARED_RAM_BASE;
+       proc_comm_wait_for(base + MDM_STATUS, PCOM_READY);
+}
index 834760f..12da4ca 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef _ARCH_ARM_MACH_MSM_PROC_COMM_H_
 #define _ARCH_ARM_MACH_MSM_PROC_COMM_H_
 
+#include <linux/init.h>
+
 enum {
        PCOM_CMD_IDLE = 0x0,
        PCOM_CMD_DONE,
@@ -62,19 +64,104 @@ enum {
        PCOM_RESET_CHIP_IMM,
        PCOM_PM_VID_EN,
        PCOM_VREG_PULLDOWN,
+       PCOM_GET_MODEM_VERSION,
+       PCOM_CLK_REGIME_SEC_RESET,
+       PCOM_CLK_REGIME_SEC_RESET_ASSERT,
+       PCOM_CLK_REGIME_SEC_RESET_DEASSERT,
+       PCOM_CLK_REGIME_SEC_PLL_REQUEST_WRP,
+       PCOM_CLK_REGIME_SEC_ENABLE,
+       PCOM_CLK_REGIME_SEC_DISABLE,
+       PCOM_CLK_REGIME_SEC_IS_ON,
+       PCOM_CLK_REGIME_SEC_SEL_CLK_INV,
+       PCOM_CLK_REGIME_SEC_SEL_CLK_SRC,
+       PCOM_CLK_REGIME_SEC_SEL_CLK_DIV,
+       PCOM_CLK_REGIME_SEC_ICODEC_CLK_ENABLE,
+       PCOM_CLK_REGIME_SEC_ICODEC_CLK_DISABLE,
+       PCOM_CLK_REGIME_SEC_SEL_SPEED,
+       PCOM_CLK_REGIME_SEC_CONFIG_GP_CLK_WRP,
+       PCOM_CLK_REGIME_SEC_CONFIG_MDH_CLK_WRP,
+       PCOM_CLK_REGIME_SEC_USB_XTAL_ON,
+       PCOM_CLK_REGIME_SEC_USB_XTAL_OFF,
+       PCOM_CLK_REGIME_SEC_SET_QDSP_DME_MODE,
+       PCOM_CLK_REGIME_SEC_SWITCH_ADSP_CLK,
+       PCOM_CLK_REGIME_SEC_GET_MAX_ADSP_CLK_KHZ,
+       PCOM_CLK_REGIME_SEC_GET_I2C_CLK_KHZ,
+       PCOM_CLK_REGIME_SEC_MSM_GET_CLK_FREQ_KHZ,
+       PCOM_CLK_REGIME_SEC_SEL_VFE_SRC,
+       PCOM_CLK_REGIME_SEC_MSM_SEL_CAMCLK,
+       PCOM_CLK_REGIME_SEC_MSM_SEL_LCDCLK,
+       PCOM_CLK_REGIME_SEC_VFE_RAIL_OFF,
+       PCOM_CLK_REGIME_SEC_VFE_RAIL_ON,
+       PCOM_CLK_REGIME_SEC_GRP_RAIL_OFF,
+       PCOM_CLK_REGIME_SEC_GRP_RAIL_ON,
+       PCOM_CLK_REGIME_SEC_VDC_RAIL_OFF,
+       PCOM_CLK_REGIME_SEC_VDC_RAIL_ON,
+       PCOM_CLK_REGIME_SEC_LCD_CTRL,
+       PCOM_CLK_REGIME_SEC_REGISTER_FOR_CPU_RESOURCE,
+       PCOM_CLK_REGIME_SEC_DEREGISTER_FOR_CPU_RESOURCE,
+       PCOM_CLK_REGIME_SEC_RESOURCE_REQUEST_WRP,
+       PCOM_CLK_REGIME_MSM_SEC_SEL_CLK_OWNER,
+       PCOM_CLK_REGIME_SEC_DEVMAN_REQUEST_WRP,
+       PCOM_GPIO_CONFIG,
+       PCOM_GPIO_CONFIGURE_GROUP,
+       PCOM_GPIO_TLMM_SET_PORT,
+       PCOM_GPIO_TLMM_CONFIG_EX,
+       PCOM_SET_FTM_BOOT_COUNT,
+       PCOM_RESERVED0,
+       PCOM_RESERVED1,
+       PCOM_CUSTOMER_CMD1,
+       PCOM_CUSTOMER_CMD2,
+       PCOM_CUSTOMER_CMD3,
+       PCOM_CLK_REGIME_ENTER_APPSBL_CHG_MODE,
+       PCOM_CLK_REGIME_EXIT_APPSBL_CHG_MODE,
+       PCOM_CLK_REGIME_SEC_RAIL_DISABLE,
+       PCOM_CLK_REGIME_SEC_RAIL_ENABLE,
+       PCOM_CLK_REGIME_SEC_RAIL_CONTROL,
+       PCOM_SET_SW_WATCHDOG_STATE,
+       PCOM_PM_MPP_CONFIG_DIGITAL_INPUT,
+       PCOM_PM_MPP_CONFIG_I_SINK,
+       PCOM_RESERVED_101,
+       PCOM_MSM_HSUSB_PHY_RESET,
+       PCOM_GET_BATT_MV_LEVEL,
+       PCOM_CHG_USB_IS_PC_CONNECTED,
+       PCOM_CHG_USB_IS_CHARGER_CONNECTED,
+       PCOM_CHG_USB_IS_DISCONNECTED,
+       PCOM_CHG_USB_IS_AVAILABLE,
+       PCOM_CLK_REGIME_SEC_MSM_SEL_FREQ,
+       PCOM_CLK_REGIME_SEC_SET_PCLK_AXI_POLICY,
+       PCOM_CLKCTL_RPC_RESET_ASSERT,
+       PCOM_CLKCTL_RPC_RESET_DEASSERT,
+       PCOM_CLKCTL_RPC_RAIL_ON,
+       PCOM_CLKCTL_RPC_RAIL_OFF,
+       PCOM_CLKCTL_RPC_RAIL_ENABLE,
+       PCOM_CLKCTL_RPC_RAIL_DISABLE,
+       PCOM_CLKCTL_RPC_RAIL_CONTROL,
+       PCOM_CLKCTL_RPC_MIN_MSMC1,
        PCOM_NUM_CMDS,
 };
 
 enum {
-        PCOM_INVALID_STATUS = 0x0,
-        PCOM_READY,
-        PCOM_CMD_RUNNING,
-        PCOM_CMD_SUCCESS,
-        PCOM_CMD_FAIL,
+       PCOM_INVALID_STATUS = 0x0,
+       PCOM_READY,
+       PCOM_CMD_RUNNING,
+       PCOM_CMD_SUCCESS,
+       PCOM_CMD_FAIL,
+       PCOM_CMD_FAIL_FALSE_RETURNED,
+       PCOM_CMD_FAIL_CMD_OUT_OF_BOUNDS_SERVER,
+       PCOM_CMD_FAIL_CMD_OUT_OF_BOUNDS_CLIENT,
+       PCOM_CMD_FAIL_CMD_UNREGISTERED,
+       PCOM_CMD_FAIL_CMD_LOCKED,
+       PCOM_CMD_FAIL_SERVER_NOT_YET_READY,
+       PCOM_CMD_FAIL_BAD_DESTINATION,
+       PCOM_CMD_FAIL_SERVER_RESET,
+       PCOM_CMD_FAIL_SMSM_NOT_INIT,
+       PCOM_CMD_FAIL_PROC_COMM_BUSY,
+       PCOM_CMD_FAIL_PROC_COMM_NOT_INIT,
+
 };
 
 /* List of VREGs that support the Pull Down Resistor setting. */
-enum {
+enum vreg_pdown_id {
        PM_VREG_PDOWN_MSMA_ID,
        PM_VREG_PDOWN_MSMP_ID,
        PM_VREG_PDOWN_MSME1_ID, /* Not supported in Panoramix */
@@ -131,6 +218,11 @@ enum {
        PM_VREG_PDOWN_XO_ID = PM_VREG_PDOWN_TCXO_ID
 };
 
+enum {
+       PCOM_CLKRGM_APPS_RESET_USB_PHY  = 34,
+       PCOM_CLKRGM_APPS_RESET_USBH     = 37,
+};
+
 /* gpio info for PCOM_RPC_GPIO_TLMM_CONFIG_EX */
 
 #define GPIO_ENABLE    0
@@ -161,5 +253,6 @@ enum {
                (((drvstr) & 0xF) << 17))
 
 int msm_proc_comm(unsigned cmd, unsigned *data1, unsigned *data2);
+void __init proc_comm_boot_wait(void);
 
 #endif
diff --git a/arch/arm/mach-msm/sirc.c b/arch/arm/mach-msm/sirc.c
new file mode 100644 (file)
index 0000000..b079452
--- /dev/null
@@ -0,0 +1,177 @@
+/* Copyright (c) 2008-2009, Code Aurora Forum. 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 version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ */
+
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <asm/irq.h>
+
+static unsigned int int_enable;
+static unsigned int wake_enable;
+
+static struct sirc_regs_t sirc_regs = {
+       .int_enable       = SPSS_SIRC_INT_ENABLE,
+       .int_enable_clear = SPSS_SIRC_INT_ENABLE_CLEAR,
+       .int_enable_set   = SPSS_SIRC_INT_ENABLE_SET,
+       .int_type         = SPSS_SIRC_INT_TYPE,
+       .int_polarity     = SPSS_SIRC_INT_POLARITY,
+       .int_clear        = SPSS_SIRC_INT_CLEAR,
+};
+
+static struct sirc_cascade_regs sirc_reg_table[] = {
+       {
+               .int_status  = SPSS_SIRC_IRQ_STATUS,
+               .cascade_irq = INT_SIRC_0,
+       }
+};
+
+static unsigned int save_type;
+static unsigned int save_polarity;
+
+/* Mask off the given interrupt. Keep the int_enable mask in sync with
+   the enable reg, so it can be restored after power collapse. */
+static void sirc_irq_mask(unsigned int irq)
+{
+       unsigned int mask;
+
+
+       mask = 1 << (irq - FIRST_SIRC_IRQ);
+       writel(mask, sirc_regs.int_enable_clear);
+       int_enable &= ~mask;
+       return;
+}
+
+/* Unmask the given interrupt. Keep the int_enable mask in sync with
+   the enable reg, so it can be restored after power collapse. */
+static void sirc_irq_unmask(unsigned int irq)
+{
+       unsigned int mask;
+
+       mask = 1 << (irq - FIRST_SIRC_IRQ);
+       writel(mask, sirc_regs.int_enable_set);
+       int_enable |= mask;
+       return;
+}
+
+static void sirc_irq_ack(unsigned int irq)
+{
+       unsigned int mask;
+
+       mask = 1 << (irq - FIRST_SIRC_IRQ);
+       writel(mask, sirc_regs.int_clear);
+       return;
+}
+
+static int sirc_irq_set_wake(unsigned int irq, unsigned int on)
+{
+       unsigned int mask;
+
+       /* Used to set the interrupt enable mask during power collapse. */
+       mask = 1 << (irq - FIRST_SIRC_IRQ);
+       if (on)
+               wake_enable |= mask;
+       else
+               wake_enable &= ~mask;
+
+       return 0;
+}
+
+static int sirc_irq_set_type(unsigned int irq, unsigned int flow_type)
+{
+       unsigned int mask;
+       unsigned int val;
+
+       mask = 1 << (irq - FIRST_SIRC_IRQ);
+       val = readl(sirc_regs.int_polarity);
+
+       if (flow_type & (IRQF_TRIGGER_LOW | IRQF_TRIGGER_FALLING))
+               val |= mask;
+       else
+               val &= ~mask;
+
+       writel(val, sirc_regs.int_polarity);
+
+       val = readl(sirc_regs.int_type);
+       if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
+               val |= mask;
+               irq_desc[irq].handle_irq = handle_edge_irq;
+       } else {
+               val &= ~mask;
+               irq_desc[irq].handle_irq = handle_level_irq;
+       }
+
+       writel(val, sirc_regs.int_type);
+
+       return 0;
+}
+
+/* Finds the pending interrupt on the passed cascade irq and redrives it */
+static void sirc_irq_handler(unsigned int irq, struct irq_desc *desc)
+{
+       unsigned int reg = 0;
+       unsigned int sirq;
+       unsigned int status;
+
+       while ((reg < ARRAY_SIZE(sirc_reg_table)) &&
+               (sirc_reg_table[reg].cascade_irq != irq))
+               reg++;
+
+       status = readl(sirc_reg_table[reg].int_status);
+       status &= SIRC_MASK;
+       if (status == 0)
+               return;
+
+       for (sirq = 0;
+            (sirq < NR_SIRC_IRQS) && ((status & (1U << sirq)) == 0);
+            sirq++)
+               ;
+       generic_handle_irq(sirq+FIRST_SIRC_IRQ);
+
+       desc->chip->ack(irq);
+}
+
+static struct irq_chip sirc_irq_chip = {
+       .name      = "sirc",
+       .ack       = sirc_irq_ack,
+       .mask      = sirc_irq_mask,
+       .unmask    = sirc_irq_unmask,
+       .set_wake  = sirc_irq_set_wake,
+       .set_type  = sirc_irq_set_type,
+};
+
+void __init msm_init_sirc(void)
+{
+       int i;
+
+       int_enable = 0;
+       wake_enable = 0;
+
+       for (i = FIRST_SIRC_IRQ; i < LAST_SIRC_IRQ; i++) {
+               set_irq_chip(i, &sirc_irq_chip);
+               set_irq_handler(i, handle_edge_irq);
+               set_irq_flags(i, IRQF_VALID);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(sirc_reg_table); i++) {
+               set_irq_chained_handler(sirc_reg_table[i].cascade_irq,
+                                       sirc_irq_handler);
+               set_irq_wake(sirc_reg_table[i].cascade_irq, 1);
+       }
+       return;
+}
+
diff --git a/arch/arm/mach-msm/smd.c b/arch/arm/mach-msm/smd.c
new file mode 100644 (file)
index 0000000..cf11d41
--- /dev/null
@@ -0,0 +1,1046 @@
+/* arch/arm/mach-msm/smd.c
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/cdev.h>
+#include <linux/device.h>
+#include <linux/wait.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/debugfs.h>
+#include <linux/delay.h>
+
+#include <mach/msm_smd.h>
+#include <mach/system.h>
+
+#include "smd_private.h"
+#include "proc_comm.h"
+
+#if defined(CONFIG_ARCH_QSD8X50)
+#define CONFIG_QDSP6 1
+#endif
+
+void (*msm_hw_reset_hook)(void);
+
+#define MODULE_NAME "msm_smd"
+
+enum {
+       MSM_SMD_DEBUG = 1U << 0,
+       MSM_SMSM_DEBUG = 1U << 0,
+};
+
+static int msm_smd_debug_mask;
+
+struct shared_info {
+       int ready;
+       unsigned state;
+};
+
+static unsigned dummy_state[SMSM_STATE_COUNT];
+
+static struct shared_info smd_info = {
+       .state = (unsigned) &dummy_state,
+};
+
+module_param_named(debug_mask, msm_smd_debug_mask,
+                  int, S_IRUGO | S_IWUSR | S_IWGRP);
+
+static unsigned last_heap_free = 0xffffffff;
+
+static inline void notify_other_smsm(void)
+{
+       msm_a2m_int(5);
+#ifdef CONFIG_QDSP6
+       msm_a2m_int(8);
+#endif
+}
+
+static inline void notify_modem_smd(void)
+{
+       msm_a2m_int(0);
+}
+
+static inline void notify_dsp_smd(void)
+{
+       msm_a2m_int(8);
+}
+
+static void smd_diag(void)
+{
+       char *x;
+
+       x = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG);
+       if (x != 0) {
+               x[SZ_DIAG_ERR_MSG - 1] = 0;
+               pr_info("smem: DIAG '%s'\n", x);
+       }
+}
+
+/* call when SMSM_RESET flag is set in the A9's smsm_state */
+static void handle_modem_crash(void)
+{
+       pr_err("ARM9 has CRASHED\n");
+       smd_diag();
+
+       /* hard reboot if possible */
+       if (msm_hw_reset_hook)
+               msm_hw_reset_hook();
+
+       /* in this case the modem or watchdog should reboot us */
+       for (;;)
+               ;
+}
+
+uint32_t raw_smsm_get_state(enum smsm_state_item item)
+{
+       return readl(smd_info.state + item * 4);
+}
+
+static int check_for_modem_crash(void)
+{
+       if (raw_smsm_get_state(SMSM_STATE_MODEM) & SMSM_RESET) {
+               handle_modem_crash();
+               return -1;
+       }
+       return 0;
+}
+
+/* the spinlock is used to synchronize between the
+ * irq handler and code that mutates the channel
+ * list or fiddles with channel state
+ */
+DEFINE_SPINLOCK(smd_lock);
+DEFINE_SPINLOCK(smem_lock);
+
+/* the mutex is used during open() and close()
+ * operations to avoid races while creating or
+ * destroying smd_channel structures
+ */
+static DEFINE_MUTEX(smd_creation_mutex);
+
+static int smd_initialized;
+
+LIST_HEAD(smd_ch_closed_list);
+LIST_HEAD(smd_ch_list_modem);
+LIST_HEAD(smd_ch_list_dsp);
+
+static unsigned char smd_ch_allocated[64];
+static struct work_struct probe_work;
+
+/* how many bytes are available for reading */
+static int smd_stream_read_avail(struct smd_channel *ch)
+{
+       return (ch->recv->head - ch->recv->tail) & ch->fifo_mask;
+}
+
+/* how many bytes we are free to write */
+static int smd_stream_write_avail(struct smd_channel *ch)
+{
+       return ch->fifo_mask -
+               ((ch->send->head - ch->send->tail) & ch->fifo_mask);
+}
+
+static int smd_packet_read_avail(struct smd_channel *ch)
+{
+       if (ch->current_packet) {
+               int n = smd_stream_read_avail(ch);
+               if (n > ch->current_packet)
+                       n = ch->current_packet;
+               return n;
+       } else {
+               return 0;
+       }
+}
+
+static int smd_packet_write_avail(struct smd_channel *ch)
+{
+       int n = smd_stream_write_avail(ch);
+       return n > SMD_HEADER_SIZE ? n - SMD_HEADER_SIZE : 0;
+}
+
+static int ch_is_open(struct smd_channel *ch)
+{
+       return (ch->recv->state == SMD_SS_OPENED) &&
+               (ch->send->state == SMD_SS_OPENED);
+}
+
+/* provide a pointer and length to readable data in the fifo */
+static unsigned ch_read_buffer(struct smd_channel *ch, void **ptr)
+{
+       unsigned head = ch->recv->head;
+       unsigned tail = ch->recv->tail;
+       *ptr = (void *) (ch->recv_data + tail);
+
+       if (tail <= head)
+               return head - tail;
+       else
+               return ch->fifo_size - tail;
+}
+
+/* advance the fifo read pointer after data from ch_read_buffer is consumed */
+static void ch_read_done(struct smd_channel *ch, unsigned count)
+{
+       BUG_ON(count > smd_stream_read_avail(ch));
+       ch->recv->tail = (ch->recv->tail + count) & ch->fifo_mask;
+       ch->send->fTAIL = 1;
+}
+
+/* basic read interface to ch_read_{buffer,done} used
+ * by smd_*_read() and update_packet_state()
+ * will read-and-discard if the _data pointer is null
+ */
+static int ch_read(struct smd_channel *ch, void *_data, int len)
+{
+       void *ptr;
+       unsigned n;
+       unsigned char *data = _data;
+       int orig_len = len;
+
+       while (len > 0) {
+               n = ch_read_buffer(ch, &ptr);
+               if (n == 0)
+                       break;
+
+               if (n > len)
+                       n = len;
+               if (_data)
+                       memcpy(data, ptr, n);
+
+               data += n;
+               len -= n;
+               ch_read_done(ch, n);
+       }
+
+       return orig_len - len;
+}
+
+static void update_stream_state(struct smd_channel *ch)
+{
+       /* streams have no special state requiring updating */
+}
+
+static void update_packet_state(struct smd_channel *ch)
+{
+       unsigned hdr[5];
+       int r;
+
+       /* can't do anything if we're in the middle of a packet */
+       if (ch->current_packet != 0)
+               return;
+
+       /* don't bother unless we can get the full header */
+       if (smd_stream_read_avail(ch) < SMD_HEADER_SIZE)
+               return;
+
+       r = ch_read(ch, hdr, SMD_HEADER_SIZE);
+       BUG_ON(r != SMD_HEADER_SIZE);
+
+       ch->current_packet = hdr[0];
+}
+
+/* provide a pointer and length to next free space in the fifo */
+static unsigned ch_write_buffer(struct smd_channel *ch, void **ptr)
+{
+       unsigned head = ch->send->head;
+       unsigned tail = ch->send->tail;
+       *ptr = (void *) (ch->send_data + head);
+
+       if (head < tail) {
+               return tail - head - 1;
+       } else {
+               if (tail == 0)
+                       return ch->fifo_size - head - 1;
+               else
+                       return ch->fifo_size - head;
+       }
+}
+
+/* advace the fifo write pointer after freespace
+ * from ch_write_buffer is filled
+ */
+static void ch_write_done(struct smd_channel *ch, unsigned count)
+{
+       BUG_ON(count > smd_stream_write_avail(ch));
+       ch->send->head = (ch->send->head + count) & ch->fifo_mask;
+       ch->send->fHEAD = 1;
+}
+
+static void ch_set_state(struct smd_channel *ch, unsigned n)
+{
+       if (n == SMD_SS_OPENED) {
+               ch->send->fDSR = 1;
+               ch->send->fCTS = 1;
+               ch->send->fCD = 1;
+       } else {
+               ch->send->fDSR = 0;
+               ch->send->fCTS = 0;
+               ch->send->fCD = 0;
+       }
+       ch->send->state = n;
+       ch->send->fSTATE = 1;
+       ch->notify_other_cpu();
+}
+
+static void do_smd_probe(void)
+{
+       struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
+       if (shared->heap_info.free_offset != last_heap_free) {
+               last_heap_free = shared->heap_info.free_offset;
+               schedule_work(&probe_work);
+       }
+}
+
+static void smd_state_change(struct smd_channel *ch,
+                            unsigned last, unsigned next)
+{
+       ch->last_state = next;
+
+       pr_info("SMD: ch %d %d -> %d\n", ch->n, last, next);
+
+       switch (next) {
+       case SMD_SS_OPENING:
+               ch->recv->tail = 0;
+       case SMD_SS_OPENED:
+               if (ch->send->state != SMD_SS_OPENED)
+                       ch_set_state(ch, SMD_SS_OPENED);
+               ch->notify(ch->priv, SMD_EVENT_OPEN);
+               break;
+       case SMD_SS_FLUSHING:
+       case SMD_SS_RESET:
+               /* we should force them to close? */
+       default:
+               ch->notify(ch->priv, SMD_EVENT_CLOSE);
+       }
+}
+
+static void handle_smd_irq(struct list_head *list, void (*notify)(void))
+{
+       unsigned long flags;
+       struct smd_channel *ch;
+       int do_notify = 0;
+       unsigned ch_flags;
+       unsigned tmp;
+
+       spin_lock_irqsave(&smd_lock, flags);
+       list_for_each_entry(ch, list, ch_list) {
+               ch_flags = 0;
+               if (ch_is_open(ch)) {
+                       if (ch->recv->fHEAD) {
+                               ch->recv->fHEAD = 0;
+                               ch_flags |= 1;
+                               do_notify |= 1;
+                       }
+                       if (ch->recv->fTAIL) {
+                               ch->recv->fTAIL = 0;
+                               ch_flags |= 2;
+                               do_notify |= 1;
+                       }
+                       if (ch->recv->fSTATE) {
+                               ch->recv->fSTATE = 0;
+                               ch_flags |= 4;
+                               do_notify |= 1;
+                       }
+               }
+               tmp = ch->recv->state;
+               if (tmp != ch->last_state)
+                       smd_state_change(ch, ch->last_state, tmp);
+               if (ch_flags) {
+                       ch->update_state(ch);
+                       ch->notify(ch->priv, SMD_EVENT_DATA);
+               }
+       }
+       if (do_notify)
+               notify();
+       spin_unlock_irqrestore(&smd_lock, flags);
+       do_smd_probe();
+}
+
+static irqreturn_t smd_modem_irq_handler(int irq, void *data)
+{
+       handle_smd_irq(&smd_ch_list_modem, notify_modem_smd);
+       return IRQ_HANDLED;
+}
+
+#if defined(CONFIG_QDSP6)
+static irqreturn_t smd_dsp_irq_handler(int irq, void *data)
+{
+       handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd);
+       return IRQ_HANDLED;
+}
+#endif
+
+static void smd_fake_irq_handler(unsigned long arg)
+{
+       handle_smd_irq(&smd_ch_list_modem, notify_modem_smd);
+       handle_smd_irq(&smd_ch_list_dsp, notify_dsp_smd);
+}
+
+static DECLARE_TASKLET(smd_fake_irq_tasklet, smd_fake_irq_handler, 0);
+
+static inline int smd_need_int(struct smd_channel *ch)
+{
+       if (ch_is_open(ch)) {
+               if (ch->recv->fHEAD || ch->recv->fTAIL || ch->recv->fSTATE)
+                       return 1;
+               if (ch->recv->state != ch->last_state)
+                       return 1;
+       }
+       return 0;
+}
+
+void smd_sleep_exit(void)
+{
+       unsigned long flags;
+       struct smd_channel *ch;
+       int need_int = 0;
+
+       spin_lock_irqsave(&smd_lock, flags);
+       list_for_each_entry(ch, &smd_ch_list_modem, ch_list) {
+               if (smd_need_int(ch)) {
+                       need_int = 1;
+                       break;
+               }
+       }
+       list_for_each_entry(ch, &smd_ch_list_dsp, ch_list) {
+               if (smd_need_int(ch)) {
+                       need_int = 1;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&smd_lock, flags);
+       do_smd_probe();
+
+       if (need_int) {
+               if (msm_smd_debug_mask & MSM_SMD_DEBUG)
+                       pr_info("smd_sleep_exit need interrupt\n");
+               tasklet_schedule(&smd_fake_irq_tasklet);
+       }
+}
+
+
+void smd_kick(smd_channel_t *ch)
+{
+       unsigned long flags;
+       unsigned tmp;
+
+       spin_lock_irqsave(&smd_lock, flags);
+       ch->update_state(ch);
+       tmp = ch->recv->state;
+       if (tmp != ch->last_state) {
+               ch->last_state = tmp;
+               if (tmp == SMD_SS_OPENED)
+                       ch->notify(ch->priv, SMD_EVENT_OPEN);
+               else
+                       ch->notify(ch->priv, SMD_EVENT_CLOSE);
+       }
+       ch->notify(ch->priv, SMD_EVENT_DATA);
+       ch->notify_other_cpu();
+       spin_unlock_irqrestore(&smd_lock, flags);
+}
+
+static int smd_is_packet(int chn, unsigned type)
+{
+       type &= SMD_KIND_MASK;
+       if (type == SMD_KIND_PACKET)
+               return 1;
+       if (type == SMD_KIND_STREAM)
+               return 0;
+
+       /* older AMSS reports SMD_KIND_UNKNOWN always */
+       if ((chn > 4) || (chn == 1))
+               return 1;
+       else
+               return 0;
+}
+
+static int smd_stream_write(smd_channel_t *ch, const void *_data, int len)
+{
+       void *ptr;
+       const unsigned char *buf = _data;
+       unsigned xfer;
+       int orig_len = len;
+
+       if (len < 0)
+               return -EINVAL;
+
+       while ((xfer = ch_write_buffer(ch, &ptr)) != 0) {
+               if (!ch_is_open(ch))
+                       break;
+               if (xfer > len)
+                       xfer = len;
+               memcpy(ptr, buf, xfer);
+               ch_write_done(ch, xfer);
+               len -= xfer;
+               buf += xfer;
+               if (len == 0)
+                       break;
+       }
+
+       ch->notify_other_cpu();
+
+       return orig_len - len;
+}
+
+static int smd_packet_write(smd_channel_t *ch, const void *_data, int len)
+{
+       unsigned hdr[5];
+
+       if (len < 0)
+               return -EINVAL;
+
+       if (smd_stream_write_avail(ch) < (len + SMD_HEADER_SIZE))
+               return -ENOMEM;
+
+       hdr[0] = len;
+       hdr[1] = hdr[2] = hdr[3] = hdr[4] = 0;
+
+       smd_stream_write(ch, hdr, sizeof(hdr));
+       smd_stream_write(ch, _data, len);
+
+       return len;
+}
+
+static int smd_stream_read(smd_channel_t *ch, void *data, int len)
+{
+       int r;
+
+       if (len < 0)
+               return -EINVAL;
+
+       r = ch_read(ch, data, len);
+       if (r > 0)
+               ch->notify_other_cpu();
+
+       return r;
+}
+
+static int smd_packet_read(smd_channel_t *ch, void *data, int len)
+{
+       unsigned long flags;
+       int r;
+
+       if (len < 0)
+               return -EINVAL;
+
+       if (len > ch->current_packet)
+               len = ch->current_packet;
+
+       r = ch_read(ch, data, len);
+       if (r > 0)
+               ch->notify_other_cpu();
+
+       spin_lock_irqsave(&smd_lock, flags);
+       ch->current_packet -= r;
+       update_packet_state(ch);
+       spin_unlock_irqrestore(&smd_lock, flags);
+
+       return r;
+}
+
+static int smd_alloc_channel(const char *name, uint32_t cid, uint32_t type)
+{
+       struct smd_channel *ch;
+
+       ch = kzalloc(sizeof(struct smd_channel), GFP_KERNEL);
+       if (ch == 0) {
+               pr_err("smd_alloc_channel() out of memory\n");
+               return -1;
+       }
+       ch->n = cid;
+
+       if (_smd_alloc_channel(ch)) {
+               kfree(ch);
+               return -1;
+       }
+
+       ch->fifo_mask = ch->fifo_size - 1;
+       ch->type = type;
+
+       if ((type & SMD_TYPE_MASK) == SMD_TYPE_APPS_MODEM)
+               ch->notify_other_cpu = notify_modem_smd;
+       else
+               ch->notify_other_cpu = notify_dsp_smd;
+
+       if (smd_is_packet(cid, type)) {
+               ch->read = smd_packet_read;
+               ch->write = smd_packet_write;
+               ch->read_avail = smd_packet_read_avail;
+               ch->write_avail = smd_packet_write_avail;
+               ch->update_state = update_packet_state;
+       } else {
+               ch->read = smd_stream_read;
+               ch->write = smd_stream_write;
+               ch->read_avail = smd_stream_read_avail;
+               ch->write_avail = smd_stream_write_avail;
+               ch->update_state = update_stream_state;
+       }
+
+       if ((type & 0xff) == 0)
+               memcpy(ch->name, "SMD_", 4);
+       else
+               memcpy(ch->name, "DSP_", 4);
+       memcpy(ch->name + 4, name, 20);
+       ch->name[23] = 0;
+       ch->pdev.name = ch->name;
+       ch->pdev.id = -1;
+
+       pr_info("smd_alloc_channel() cid=%02d size=%05d '%s'\n",
+               ch->n, ch->fifo_size, ch->name);
+
+       mutex_lock(&smd_creation_mutex);
+       list_add(&ch->ch_list, &smd_ch_closed_list);
+       mutex_unlock(&smd_creation_mutex);
+
+       platform_device_register(&ch->pdev);
+       return 0;
+}
+
+static void smd_channel_probe_worker(struct work_struct *work)
+{
+       struct smd_alloc_elm *shared;
+       unsigned ctype;
+       unsigned type;
+       unsigned n;
+
+       shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64);
+       if (!shared) {
+               pr_err("smd: cannot find allocation table\n");
+               return;
+       }
+       for (n = 0; n < 64; n++) {
+               if (smd_ch_allocated[n])
+                       continue;
+               if (!shared[n].ref_count)
+                       continue;
+               if (!shared[n].name[0])
+                       continue;
+               ctype = shared[n].ctype;
+               type = ctype & SMD_TYPE_MASK;
+
+               /* DAL channels are stream but neither the modem,
+                * nor the DSP correctly indicate this.  Fixup manually.
+                */
+               if (!memcmp(shared[n].name, "DAL", 3))
+                       ctype = (ctype & (~SMD_KIND_MASK)) | SMD_KIND_STREAM;
+
+               type = shared[n].ctype & SMD_TYPE_MASK;
+               if ((type == SMD_TYPE_APPS_MODEM) ||
+                   (type == SMD_TYPE_APPS_DSP))
+                       if (!smd_alloc_channel(shared[n].name, shared[n].cid, ctype))
+                               smd_ch_allocated[n] = 1;
+       }
+}
+
+static void do_nothing_notify(void *priv, unsigned flags)
+{
+}
+
+struct smd_channel *smd_get_channel(const char *name)
+{
+       struct smd_channel *ch;
+
+       mutex_lock(&smd_creation_mutex);
+       list_for_each_entry(ch, &smd_ch_closed_list, ch_list) {
+               if (!strcmp(name, ch->name)) {
+                       list_del(&ch->ch_list);
+                       mutex_unlock(&smd_creation_mutex);
+                       return ch;
+               }
+       }
+       mutex_unlock(&smd_creation_mutex);
+
+       return NULL;
+}
+
+int smd_open(const char *name, smd_channel_t **_ch,
+            void *priv, void (*notify)(void *, unsigned))
+{
+       struct smd_channel *ch;
+       unsigned long flags;
+
+       if (smd_initialized == 0) {
+               pr_info("smd_open() before smd_init()\n");
+               return -ENODEV;
+       }
+
+       ch = smd_get_channel(name);
+       if (!ch)
+               return -ENODEV;
+
+       if (notify == 0)
+               notify = do_nothing_notify;
+
+       ch->notify = notify;
+       ch->current_packet = 0;
+       ch->last_state = SMD_SS_CLOSED;
+       ch->priv = priv;
+
+       *_ch = ch;
+
+       spin_lock_irqsave(&smd_lock, flags);
+
+       if ((ch->type & SMD_TYPE_MASK) == SMD_TYPE_APPS_MODEM)
+               list_add(&ch->ch_list, &smd_ch_list_modem);
+       else
+               list_add(&ch->ch_list, &smd_ch_list_dsp);
+
+       /* If the remote side is CLOSING, we need to get it to
+        * move to OPENING (which we'll do by moving from CLOSED to
+        * OPENING) and then get it to move from OPENING to
+        * OPENED (by doing the same state change ourselves).
+        *
+        * Otherwise, it should be OPENING and we can move directly
+        * to OPENED so that it will follow.
+        */
+       if (ch->recv->state == SMD_SS_CLOSING) {
+               ch->send->head = 0;
+               ch_set_state(ch, SMD_SS_OPENING);
+       } else {
+               ch_set_state(ch, SMD_SS_OPENED);
+       }
+       spin_unlock_irqrestore(&smd_lock, flags);
+       smd_kick(ch);
+
+       return 0;
+}
+
+int smd_close(smd_channel_t *ch)
+{
+       unsigned long flags;
+
+       pr_info("smd_close(%p)\n", ch);
+
+       if (ch == 0)
+               return -1;
+
+       spin_lock_irqsave(&smd_lock, flags);
+       ch->notify = do_nothing_notify;
+       list_del(&ch->ch_list);
+       ch_set_state(ch, SMD_SS_CLOSED);
+       spin_unlock_irqrestore(&smd_lock, flags);
+
+       mutex_lock(&smd_creation_mutex);
+       list_add(&ch->ch_list, &smd_ch_closed_list);
+       mutex_unlock(&smd_creation_mutex);
+
+       return 0;
+}
+
+int smd_read(smd_channel_t *ch, void *data, int len)
+{
+       return ch->read(ch, data, len);
+}
+
+int smd_write(smd_channel_t *ch, const void *data, int len)
+{
+       return ch->write(ch, data, len);
+}
+
+int smd_write_atomic(smd_channel_t *ch, const void *data, int len)
+{
+       unsigned long flags;
+       int res;
+       spin_lock_irqsave(&smd_lock, flags);
+       res = ch->write(ch, data, len);
+       spin_unlock_irqrestore(&smd_lock, flags);
+       return res;
+}
+
+int smd_read_avail(smd_channel_t *ch)
+{
+       return ch->read_avail(ch);
+}
+
+int smd_write_avail(smd_channel_t *ch)
+{
+       return ch->write_avail(ch);
+}
+
+int smd_wait_until_readable(smd_channel_t *ch, int bytes)
+{
+       return -1;
+}
+
+int smd_wait_until_writable(smd_channel_t *ch, int bytes)
+{
+       return -1;
+}
+
+int smd_cur_packet_size(smd_channel_t *ch)
+{
+       return ch->current_packet;
+}
+
+
+/* ------------------------------------------------------------------------- */
+
+void *smem_alloc(unsigned id, unsigned size)
+{
+       return smem_find(id, size);
+}
+
+void *smem_item(unsigned id, unsigned *size)
+{
+       struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
+       struct smem_heap_entry *toc = shared->heap_toc;
+
+       if (id >= SMEM_NUM_ITEMS)
+               return 0;
+
+       if (toc[id].allocated) {
+               *size = toc[id].size;
+               return (void *) (MSM_SHARED_RAM_BASE + toc[id].offset);
+       } else {
+               *size = 0;
+       }
+
+       return 0;
+}
+
+void *smem_find(unsigned id, unsigned size_in)
+{
+       unsigned size;
+       void *ptr;
+
+       ptr = smem_item(id, &size);
+       if (!ptr)
+               return 0;
+
+       size_in = ALIGN(size_in, 8);
+       if (size_in != size) {
+               pr_err("smem_find(%d, %d): wrong size %d\n",
+                      id, size_in, size);
+               return 0;
+       }
+
+       return ptr;
+}
+
+static irqreturn_t smsm_irq_handler(int irq, void *data)
+{
+       unsigned long flags;
+       unsigned apps, modm;
+
+       spin_lock_irqsave(&smem_lock, flags);
+
+       apps = raw_smsm_get_state(SMSM_STATE_APPS);
+       modm = raw_smsm_get_state(SMSM_STATE_MODEM);
+
+       if (msm_smd_debug_mask & MSM_SMSM_DEBUG)
+               pr_info("<SM %08x %08x>\n", apps, modm);
+       if (modm & SMSM_RESET)
+               handle_modem_crash();
+
+       do_smd_probe();
+
+       spin_unlock_irqrestore(&smem_lock, flags);
+       return IRQ_HANDLED;
+}
+
+int smsm_change_state(enum smsm_state_item item,
+                     uint32_t clear_mask, uint32_t set_mask)
+{
+       unsigned long addr = smd_info.state + item * 4;
+       unsigned long flags;
+       unsigned state;
+
+       if (!smd_info.ready)
+               return -EIO;
+
+       spin_lock_irqsave(&smem_lock, flags);
+
+       if (raw_smsm_get_state(SMSM_STATE_MODEM) & SMSM_RESET)
+               handle_modem_crash();
+
+       state = (readl(addr) & ~clear_mask) | set_mask;
+       writel(state, addr);
+
+       if (msm_smd_debug_mask & MSM_SMSM_DEBUG)
+               pr_info("smsm_change_state %d %x\n", item, state);
+       notify_other_smsm();
+
+       spin_unlock_irqrestore(&smem_lock, flags);
+
+       return 0;
+}
+
+uint32_t smsm_get_state(enum smsm_state_item item)
+{
+       unsigned long flags;
+       uint32_t rv;
+
+       spin_lock_irqsave(&smem_lock, flags);
+
+       rv = readl(smd_info.state + item * 4);
+
+       if (item == SMSM_STATE_MODEM && (rv & SMSM_RESET))
+               handle_modem_crash();
+
+       spin_unlock_irqrestore(&smem_lock, flags);
+
+       return rv;
+}
+
+#ifdef CONFIG_ARCH_MSM_SCORPION
+
+int smsm_set_sleep_duration(uint32_t delay)
+{
+       struct msm_dem_slave_data *ptr;
+
+       ptr = smem_find(SMEM_APPS_DEM_SLAVE_DATA, sizeof(*ptr));
+       if (ptr == NULL) {
+               pr_err("smsm_set_sleep_duration <SM NO APPS_DEM_SLAVE_DATA>\n");
+               return -EIO;
+       }
+       if (msm_smd_debug_mask & MSM_SMSM_DEBUG)
+               pr_info("smsm_set_sleep_duration %d -> %d\n",
+                      ptr->sleep_time, delay);
+       ptr->sleep_time = delay;
+       return 0;
+}
+
+#else
+
+int smsm_set_sleep_duration(uint32_t delay)
+{
+       uint32_t *ptr;
+
+       ptr = smem_find(SMEM_SMSM_SLEEP_DELAY, sizeof(*ptr));
+       if (ptr == NULL) {
+               pr_err("smsm_set_sleep_duration <SM NO SLEEP_DELAY>\n");
+               return -EIO;
+       }
+       if (msm_smd_debug_mask & MSM_SMSM_DEBUG)
+               pr_info("smsm_set_sleep_duration %d -> %d\n",
+                      *ptr, delay);
+       *ptr = delay;
+       return 0;
+}
+
+#endif
+
+int smd_core_init(void)
+{
+       int r;
+       pr_info("smd_core_init()\n");
+
+       /* wait for essential items to be initialized */
+       for (;;) {
+               unsigned size;
+               void *state;
+               state = smem_item(SMEM_SMSM_SHARED_STATE, &size);
+               if (size == SMSM_V1_SIZE || size == SMSM_V2_SIZE) {
+                       smd_info.state = (unsigned)state;
+                       break;
+               }
+       }
+
+       smd_info.ready = 1;
+
+       r = request_irq(INT_A9_M2A_0, smd_modem_irq_handler,
+                       IRQF_TRIGGER_RISING, "smd_dev", 0);
+       if (r < 0)
+               return r;
+       r = enable_irq_wake(INT_A9_M2A_0);
+       if (r < 0)
+               pr_err("smd_core_init: enable_irq_wake failed for A9_M2A_0\n");
+
+       r = request_irq(INT_A9_M2A_5, smsm_irq_handler,
+                       IRQF_TRIGGER_RISING, "smsm_dev", 0);
+       if (r < 0) {
+               free_irq(INT_A9_M2A_0, 0);
+               return r;
+       }
+       r = enable_irq_wake(INT_A9_M2A_5);
+       if (r < 0)
+               pr_err("smd_core_init: enable_irq_wake failed for A9_M2A_5\n");
+
+#if defined(CONFIG_QDSP6)
+       r = request_irq(INT_ADSP_A11, smd_dsp_irq_handler,
+                       IRQF_TRIGGER_RISING, "smd_dsp", 0);
+       if (r < 0) {
+               free_irq(INT_A9_M2A_0, 0);
+               free_irq(INT_A9_M2A_5, 0);
+               return r;
+       }
+#endif
+
+       /* check for any SMD channels that may already exist */
+       do_smd_probe();
+
+       /* indicate that we're up and running */
+       smsm_change_state(SMSM_STATE_APPS,
+                         ~0, SMSM_INIT | SMSM_SMDINIT | SMSM_RPCINIT | SMSM_RUN);
+#ifdef CONFIG_ARCH_MSM_SCORPION
+       smsm_change_state(SMSM_STATE_APPS_DEM, ~0, 0);
+#endif
+
+       pr_info("smd_core_init() done\n");
+
+       return 0;
+}
+
+static int __init msm_smd_probe(struct platform_device *pdev)
+{
+       pr_info("smd_init()\n");
+
+       /*
+        * If we haven't waited for the ARM9 to boot up till now,
+        * then we need to wait here. Otherwise this should just
+        * return immediately.
+        */
+       proc_comm_boot_wait();
+
+       INIT_WORK(&probe_work, smd_channel_probe_worker);
+
+       if (smd_core_init()) {
+               pr_err("smd_core_init() failed\n");
+               return -1;
+       }
+
+       do_smd_probe();
+
+       msm_check_for_modem_crash = check_for_modem_crash;
+
+       msm_init_last_radio_log(THIS_MODULE);
+
+       smd_initialized = 1;
+
+       return 0;
+}
+
+static struct platform_driver msm_smd_driver = {
+       .probe = msm_smd_probe,
+       .driver = {
+               .name = MODULE_NAME,
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init msm_smd_init(void)
+{
+       return platform_driver_register(&msm_smd_driver);
+}
+
+module_init(msm_smd_init);
+
+MODULE_DESCRIPTION("MSM Shared Memory Core");
+MODULE_AUTHOR("Brian Swetland <swetland@google.com>");
+MODULE_LICENSE("GPL");
diff --git a/arch/arm/mach-msm/smd_debug.c b/arch/arm/mach-msm/smd_debug.c
new file mode 100644 (file)
index 0000000..3b2dd71
--- /dev/null
@@ -0,0 +1,315 @@
+/* arch/arm/mach-msm/smd_debug.c
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Author: Brian Swetland <swetland@google.com>
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+
+#include <linux/debugfs.h>
+#include <linux/list.h>
+
+#include <mach/msm_iomap.h>
+
+#include "smd_private.h"
+
+#if defined(CONFIG_DEBUG_FS)
+
+static char *chstate(unsigned n)
+{
+       switch (n) {
+       case SMD_SS_CLOSED:
+               return "CLOSED";
+       case SMD_SS_OPENING:
+               return "OPENING";
+       case SMD_SS_OPENED:
+               return "OPENED";
+       case SMD_SS_FLUSHING:
+               return "FLUSHING";
+       case SMD_SS_CLOSING:
+               return "CLOSING";
+       case SMD_SS_RESET:
+               return "RESET";
+       case SMD_SS_RESET_OPENING:
+               return "ROPENING";
+       default:
+               return "UNKNOWN";
+       }
+}
+
+
+static int dump_ch(char *buf, int max, struct smd_channel *ch)
+{
+       volatile struct smd_half_channel *s = ch->send;
+       volatile struct smd_half_channel *r = ch->recv;
+
+       return scnprintf(
+               buf, max,
+               "ch%02d:"
+               " %8s(%05d/%05d) %c%c%c%c%c%c%c <->"
+               " %8s(%05d/%05d) %c%c%c%c%c%c%c '%s'\n", ch->n,
+               chstate(s->state), s->tail, s->head,
+               s->fDSR ? 'D' : 'd',
+               s->fCTS ? 'C' : 'c',
+               s->fCD ? 'C' : 'c',
+               s->fRI ? 'I' : 'i',
+               s->fHEAD ? 'W' : 'w',
+               s->fTAIL ? 'R' : 'r',
+               s->fSTATE ? 'S' : 's',
+               chstate(r->state), r->tail, r->head,
+               r->fDSR ? 'D' : 'd',
+               r->fCTS ? 'R' : 'r',
+               r->fCD ? 'C' : 'c',
+               r->fRI ? 'I' : 'i',
+               r->fHEAD ? 'W' : 'w',
+               r->fTAIL ? 'R' : 'r',
+               r->fSTATE ? 'S' : 's',
+               ch->name
+               );
+}
+
+static int debug_read_stat(char *buf, int max)
+{
+       char *msg;
+       int i = 0;
+
+       msg = smem_find(ID_DIAG_ERR_MSG, SZ_DIAG_ERR_MSG);
+
+       if (raw_smsm_get_state(SMSM_STATE_MODEM) & SMSM_RESET)
+               i += scnprintf(buf + i, max - i,
+                              "smsm: ARM9 HAS CRASHED\n");
+
+       i += scnprintf(buf + i, max - i, "smsm: a9: %08x a11: %08x\n",
+                      raw_smsm_get_state(SMSM_STATE_MODEM),
+                      raw_smsm_get_state(SMSM_STATE_APPS));
+#ifdef CONFIG_ARCH_MSM_SCORPION
+       i += scnprintf(buf + i, max - i, "smsm dem: apps: %08x modem: %08x "
+                      "qdsp6: %08x power: %08x time: %08x\n",
+                      raw_smsm_get_state(SMSM_STATE_APPS_DEM),
+                      raw_smsm_get_state(SMSM_STATE_MODEM_DEM),
+                      raw_smsm_get_state(SMSM_STATE_QDSP6_DEM),
+                      raw_smsm_get_state(SMSM_STATE_POWER_MASTER_DEM),
+                      raw_smsm_get_state(SMSM_STATE_TIME_MASTER_DEM));
+#endif
+       if (msg) {
+               msg[SZ_DIAG_ERR_MSG - 1] = 0;
+               i += scnprintf(buf + i, max - i, "diag: '%s'\n", msg);
+       }
+       return i;
+}
+
+static int debug_read_mem(char *buf, int max)
+{
+       unsigned n;
+       struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
+       struct smem_heap_entry *toc = shared->heap_toc;
+       int i = 0;
+
+       i += scnprintf(buf + i, max - i,
+                      "heap: init=%d free=%d remain=%d\n",
+                      shared->heap_info.initialized,
+                      shared->heap_info.free_offset,
+                      shared->heap_info.heap_remaining);
+
+       for (n = 0; n < SMEM_NUM_ITEMS; n++) {
+               if (toc[n].allocated == 0)
+                       continue;
+               i += scnprintf(buf + i, max - i,
+                              "%04d: offset %08x size %08x\n",
+                              n, toc[n].offset, toc[n].size);
+       }
+       return i;
+}
+
+static int debug_read_ch(char *buf, int max)
+{
+       struct smd_channel *ch;
+       unsigned long flags;
+       int i = 0;
+
+       spin_lock_irqsave(&smd_lock, flags);
+       list_for_each_entry(ch, &smd_ch_list_dsp, ch_list)
+               i += dump_ch(buf + i, max - i, ch);
+       list_for_each_entry(ch, &smd_ch_list_modem, ch_list)
+               i += dump_ch(buf + i, max - i, ch);
+       list_for_each_entry(ch, &smd_ch_closed_list, ch_list)
+               i += dump_ch(buf + i, max - i, ch);
+       spin_unlock_irqrestore(&smd_lock, flags);
+
+       return i;
+}
+
+static int debug_read_version(char *buf, int max)
+{
+       struct smem_shared *shared = (void *) MSM_SHARED_RAM_BASE;
+       unsigned version = shared->version[VERSION_MODEM];
+       return sprintf(buf, "%d.%d\n", version >> 16, version & 0xffff);
+}
+
+static int debug_read_build_id(char *buf, int max)
+{
+       unsigned size;
+       void *data;
+
+       data = smem_item(SMEM_HW_SW_BUILD_ID, &size);
+       if (!data)
+               return 0;
+
+       if (size >= max)
+               size = max;
+       memcpy(buf, data, size);
+
+       return size;
+}
+
+static int debug_read_alloc_tbl(char *buf, int max)
+{
+       struct smd_alloc_elm *shared;
+       int n, i = 0;
+
+       shared = smem_find(ID_CH_ALLOC_TBL, sizeof(*shared) * 64);
+
+       for (n = 0; n < 64; n++) {
+               if (shared[n].ref_count == 0)
+                       continue;
+               i += scnprintf(buf + i, max - i,
+                              "%03d: %-20s cid=%02d type=%03d "
+                              "kind=%02d ref_count=%d\n",
+                              n, shared[n].name, shared[n].cid,
+                              shared[n].ctype & 0xff,
+                              (shared[n].ctype >> 8) & 0xf,
+                              shared[n].ref_count);
+       }
+
+       return i;
+}
+
+#define DEBUG_BUFMAX 4096
+static char debug_buffer[DEBUG_BUFMAX];
+
+static ssize_t debug_read(struct file *file, char __user *buf,
+                         size_t count, loff_t *ppos)
+{
+       int (*fill)(char *buf, int max) = file->private_data;
+       int bsize = fill(debug_buffer, DEBUG_BUFMAX);
+       return simple_read_from_buffer(buf, count, ppos, debug_buffer, bsize);
+}
+
+static int debug_open(struct inode *inode, struct file *file)
+{
+       file->private_data = inode->i_private;
+       return 0;
+}
+
+static const struct file_operations debug_ops = {
+       .read = debug_read,
+       .open = debug_open,
+};
+
+static void debug_create(const char *name, mode_t mode,
+                        struct dentry *dent,
+                        int (*fill)(char *buf, int max))
+{
+       debugfs_create_file(name, mode, dent, fill, &debug_ops);
+}
+
+static int smd_debugfs_init(void)
+{
+       struct dentry *dent;
+
+       dent = debugfs_create_dir("smd", 0);
+       if (IS_ERR(dent))
+               return 1;
+
+       debug_create("ch", 0444, dent, debug_read_ch);
+       debug_create("stat", 0444, dent, debug_read_stat);
+       debug_create("mem", 0444, dent, debug_read_mem);
+       debug_create("version", 0444, dent, debug_read_version);
+       debug_create("tbl", 0444, dent, debug_read_alloc_tbl);
+       debug_create("build", 0444, dent, debug_read_build_id);
+
+       return 0;
+}
+
+late_initcall(smd_debugfs_init);
+#endif
+
+
+#define MAX_NUM_SLEEP_CLIENTS          64
+#define MAX_SLEEP_NAME_LEN             8
+
+#define NUM_GPIO_INT_REGISTERS         6
+#define GPIO_SMEM_NUM_GROUPS           2
+#define GPIO_SMEM_MAX_PC_INTERRUPTS    8
+
+struct tramp_gpio_save {
+       unsigned int enable;
+       unsigned int detect;
+       unsigned int polarity;
+};
+
+struct tramp_gpio_smem {
+       uint16_t num_fired[GPIO_SMEM_NUM_GROUPS];
+       uint16_t fired[GPIO_SMEM_NUM_GROUPS][GPIO_SMEM_MAX_PC_INTERRUPTS];
+       uint32_t enabled[NUM_GPIO_INT_REGISTERS];
+       uint32_t detection[NUM_GPIO_INT_REGISTERS];
+       uint32_t polarity[NUM_GPIO_INT_REGISTERS];
+};
+
+
+void smsm_print_sleep_info(void)
+{
+       unsigned long flags;
+       uint32_t *ptr;
+       struct tramp_gpio_smem *gpio;
+       struct smsm_interrupt_info *int_info;
+
+
+       spin_lock_irqsave(&smem_lock, flags);
+
+       ptr = smem_alloc(SMEM_SMSM_SLEEP_DELAY, sizeof(*ptr));
+       if (ptr)
+               pr_info("SMEM_SMSM_SLEEP_DELAY: %x\n", *ptr);
+
+       ptr = smem_alloc(SMEM_SMSM_LIMIT_SLEEP, sizeof(*ptr));
+       if (ptr)
+               pr_info("SMEM_SMSM_LIMIT_SLEEP: %x\n", *ptr);
+
+       ptr = smem_alloc(SMEM_SLEEP_POWER_COLLAPSE_DISABLED, sizeof(*ptr));
+       if (ptr)
+               pr_info("SMEM_SLEEP_POWER_COLLAPSE_DISABLED: %x\n", *ptr);
+
+#ifndef CONFIG_ARCH_MSM_SCORPION
+       int_info = smem_alloc(SMEM_SMSM_INT_INFO, sizeof(*int_info));
+       if (int_info)
+               pr_info("SMEM_SMSM_INT_INFO %x %x %x\n",
+                       int_info->interrupt_mask,
+                       int_info->pending_interrupts,
+                       int_info->wakeup_reason);
+
+       gpio = smem_alloc(SMEM_GPIO_INT, sizeof(*gpio));
+       if (gpio) {
+               int i;
+               for (i = 0; i < NUM_GPIO_INT_REGISTERS; i++)
+                       pr_info("SMEM_GPIO_INT: %d: e %x d %x p %x\n",
+                               i, gpio->enabled[i], gpio->detection[i],
+                               gpio->polarity[i]);
+
+               for (i = 0; i < GPIO_SMEM_NUM_GROUPS; i++)
+                       pr_info("SMEM_GPIO_INT: %d: f %d: %d %d...\n",
+                               i, gpio->num_fired[i], gpio->fired[i][0],
+                               gpio->fired[i][1]);
+       }
+#else
+#endif
+       spin_unlock_irqrestore(&smem_lock, flags);
+}
+
diff --git a/arch/arm/mach-msm/smd_private.h b/arch/arm/mach-msm/smd_private.h
new file mode 100644 (file)
index 0000000..727bfe6
--- /dev/null
@@ -0,0 +1,403 @@
+/* arch/arm/mach-msm/smd_private.h
+ *
+ * Copyright (C) 2007 Google, Inc.
+ * Copyright (c) 2007 QUALCOMM Incorporated
+ *
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ *
+ * 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.
+ *
+ */
+#ifndef _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
+#define _ARCH_ARM_MACH_MSM_MSM_SMD_PRIVATE_H_
+
+#include <linux/platform_device.h>
+#include <linux/spinlock.h>
+#include <linux/list.h>
+#include <linux/io.h>
+
+#include <mach/msm_iomap.h>
+
+struct smem_heap_info {
+       unsigned initialized;
+       unsigned free_offset;
+       unsigned heap_remaining;
+       unsigned reserved;
+};
+
+struct smem_heap_entry {
+       unsigned allocated;
+       unsigned offset;
+       unsigned size;
+       unsigned reserved;
+};
+
+struct smem_proc_comm {
+       unsigned command;
+       unsigned status;
+       unsigned data1;
+       unsigned data2;
+};
+
+#define PC_APPS  0
+#define PC_MODEM 1
+
+#define VERSION_SMD       0
+#define VERSION_QDSP6     4
+#define VERSION_APPS_SBL  6
+#define VERSION_MODEM_SBL 7
+#define VERSION_APPS      8
+#define VERSION_MODEM     9
+
+struct smem_shared {
+       struct smem_proc_comm proc_comm[4];
+       unsigned version[32];
+       struct smem_heap_info heap_info;
+       struct smem_heap_entry heap_toc[512];
+};
+
+#define SMSM_V1_SIZE           (sizeof(unsigned) * 8)
+#define SMSM_V2_SIZE           (sizeof(unsigned) * 4)
+
+#ifdef CONFIG_MSM_SMD_PKG3
+struct smsm_interrupt_info {
+       uint32_t interrupt_mask;
+       uint32_t pending_interrupts;
+       uint32_t wakeup_reason;
+};
+#else
+#define DEM_MAX_PORT_NAME_LEN (20)
+struct msm_dem_slave_data {
+       uint32_t sleep_time;
+       uint32_t interrupt_mask;
+       uint32_t resources_used;
+       uint32_t reserved1;
+
+       uint32_t wakeup_reason;
+       uint32_t pending_interrupts;
+       uint32_t rpc_prog;
+       uint32_t rpc_proc;
+       char     smd_port_name[DEM_MAX_PORT_NAME_LEN];
+       uint32_t reserved2;
+};
+#endif
+
+#define SZ_DIAG_ERR_MSG 0xC8
+#define ID_DIAG_ERR_MSG SMEM_DIAG_ERR_MESSAGE
+#define ID_SMD_CHANNELS SMEM_SMD_BASE_ID
+#define ID_SHARED_STATE SMEM_SMSM_SHARED_STATE
+#define ID_CH_ALLOC_TBL SMEM_CHANNEL_ALLOC_TBL
+
+#define SMSM_INIT              0x00000001
+#define SMSM_SMDINIT           0x00000008
+#define SMSM_RPCINIT           0x00000020
+#define SMSM_RESET             0x00000040
+#define SMSM_RSA               0x00000080
+#define SMSM_RUN               0x00000100
+#define SMSM_PWRC              0x00000200
+#define SMSM_TIMEWAIT          0x00000400
+#define SMSM_TIMEINIT          0x00000800
+#define SMSM_PWRC_EARLY_EXIT   0x00001000
+#define SMSM_WFPI              0x00002000
+#define SMSM_SLEEP             0x00004000
+#define SMSM_SLEEPEXIT         0x00008000
+#define SMSM_APPS_REBOOT       0x00020000
+#define SMSM_SYSTEM_POWER_DOWN 0x00040000
+#define SMSM_SYSTEM_REBOOT     0x00080000
+#define SMSM_SYSTEM_DOWNLOAD   0x00100000
+#define SMSM_PWRC_SUSPEND      0x00200000
+#define SMSM_APPS_SHUTDOWN     0x00400000
+#define SMSM_SMD_LOOPBACK      0x00800000
+#define SMSM_RUN_QUIET         0x01000000
+#define SMSM_MODEM_WAIT                0x02000000
+#define SMSM_MODEM_BREAK       0x04000000
+#define SMSM_MODEM_CONTINUE    0x08000000
+#define SMSM_UNKNOWN           0x80000000
+
+#define SMSM_WKUP_REASON_RPC   0x00000001
+#define SMSM_WKUP_REASON_INT   0x00000002
+#define SMSM_WKUP_REASON_GPIO  0x00000004
+#define SMSM_WKUP_REASON_TIMER 0x00000008
+#define SMSM_WKUP_REASON_ALARM 0x00000010
+#define SMSM_WKUP_REASON_RESET 0x00000020
+
+#ifdef CONFIG_ARCH_MSM7X00A
+enum smsm_state_item {
+       SMSM_STATE_APPS = 1,
+       SMSM_STATE_MODEM = 3,
+       SMSM_STATE_COUNT,
+};
+#else
+enum smsm_state_item {
+       SMSM_STATE_APPS,
+       SMSM_STATE_MODEM,
+       SMSM_STATE_HEXAGON,
+       SMSM_STATE_APPS_DEM,
+       SMSM_STATE_MODEM_DEM,
+       SMSM_STATE_QDSP6_DEM,
+       SMSM_STATE_POWER_MASTER_DEM,
+       SMSM_STATE_TIME_MASTER_DEM,
+       SMSM_STATE_COUNT,
+};
+#endif
+
+void *smem_alloc(unsigned id, unsigned size);
+int smsm_change_state(enum smsm_state_item item, uint32_t clear_mask, uint32_t set_mask);
+uint32_t smsm_get_state(enum smsm_state_item item);
+int smsm_set_sleep_duration(uint32_t delay);
+void smsm_print_sleep_info(void);
+
+#define SMEM_NUM_SMD_CHANNELS        64
+
+typedef enum {
+       /* fixed items */
+       SMEM_PROC_COMM = 0,
+       SMEM_HEAP_INFO,
+       SMEM_ALLOCATION_TABLE,
+       SMEM_VERSION_INFO,
+       SMEM_HW_RESET_DETECT,
+       SMEM_AARM_WARM_BOOT,
+       SMEM_DIAG_ERR_MESSAGE,
+       SMEM_SPINLOCK_ARRAY,
+       SMEM_MEMORY_BARRIER_LOCATION,
+
+       /* dynamic items */
+       SMEM_AARM_PARTITION_TABLE,
+       SMEM_AARM_BAD_BLOCK_TABLE,
+       SMEM_RESERVE_BAD_BLOCKS,
+       SMEM_WM_UUID,
+       SMEM_CHANNEL_ALLOC_TBL,
+       SMEM_SMD_BASE_ID,
+       SMEM_SMEM_LOG_IDX = SMEM_SMD_BASE_ID + SMEM_NUM_SMD_CHANNELS,
+       SMEM_SMEM_LOG_EVENTS,
+       SMEM_SMEM_STATIC_LOG_IDX,
+       SMEM_SMEM_STATIC_LOG_EVENTS,
+       SMEM_SMEM_SLOW_CLOCK_SYNC,
+       SMEM_SMEM_SLOW_CLOCK_VALUE,
+       SMEM_BIO_LED_BUF,
+       SMEM_SMSM_SHARED_STATE,
+       SMEM_SMSM_INT_INFO,
+       SMEM_SMSM_SLEEP_DELAY,
+       SMEM_SMSM_LIMIT_SLEEP,
+       SMEM_SLEEP_POWER_COLLAPSE_DISABLED,
+       SMEM_KEYPAD_KEYS_PRESSED,
+       SMEM_KEYPAD_STATE_UPDATED,
+       SMEM_KEYPAD_STATE_IDX,
+       SMEM_GPIO_INT,
+       SMEM_MDDI_LCD_IDX,
+       SMEM_MDDI_HOST_DRIVER_STATE,
+       SMEM_MDDI_LCD_DISP_STATE,
+       SMEM_LCD_CUR_PANEL,
+       SMEM_MARM_BOOT_SEGMENT_INFO,
+       SMEM_AARM_BOOT_SEGMENT_INFO,
+       SMEM_SLEEP_STATIC,
+       SMEM_SCORPION_FREQUENCY,
+       SMEM_SMD_PROFILES,
+       SMEM_TSSC_BUSY,
+       SMEM_HS_SUSPEND_FILTER_INFO,
+       SMEM_BATT_INFO,
+       SMEM_APPS_BOOT_MODE,
+       SMEM_VERSION_FIRST,
+       SMEM_VERSION_LAST = SMEM_VERSION_FIRST + 24,
+       SMEM_OSS_RRCASN1_BUF1,
+       SMEM_OSS_RRCASN1_BUF2,
+       SMEM_ID_VENDOR0,
+       SMEM_ID_VENDOR1,
+       SMEM_ID_VENDOR2,
+       SMEM_HW_SW_BUILD_ID,
+       SMEM_SMD_BLOCK_PORT_BASE_ID,
+       SMEM_SMD_BLOCK_PORT_PROC0_HEAP = SMEM_SMD_BLOCK_PORT_BASE_ID + SMEM_NUM_SMD_CHANNELS,
+       SMEM_SMD_BLOCK_PORT_PROC1_HEAP = SMEM_SMD_BLOCK_PORT_PROC0_HEAP + SMEM_NUM_SMD_CHANNELS,
+       SMEM_I2C_MUTEX = SMEM_SMD_BLOCK_PORT_PROC1_HEAP + SMEM_NUM_SMD_CHANNELS,
+       SMEM_SCLK_CONVERSION,
+       SMEM_SMD_SMSM_INTR_MUX,
+       SMEM_SMSM_CPU_INTR_MASK,
+       SMEM_APPS_DEM_SLAVE_DATA,
+       SMEM_QDSP6_DEM_SLAVE_DATA,
+       SMEM_CLKREGIM_BSP,
+       SMEM_CLKREGIM_SOURCES,
+       SMEM_SMD_FIFO_BASE_ID,
+       SMEM_USABLE_RAM_PARTITION_TABLE = SMEM_SMD_FIFO_BASE_ID + SMEM_NUM_SMD_CHANNELS,
+       SMEM_POWER_ON_STATUS_INFO,
+       SMEM_DAL_AREA,
+       SMEM_SMEM_LOG_POWER_IDX,
+       SMEM_SMEM_LOG_POWER_WRAP,
+       SMEM_SMEM_LOG_POWER_EVENTS,
+       SMEM_ERR_CRASH_LOG,
+       SMEM_ERR_F3_TRACE_LOG,
+       SMEM_NUM_ITEMS,
+} smem_mem_type;
+
+
+#define SMD_SS_CLOSED          0x00000000
+#define SMD_SS_OPENING         0x00000001
+#define SMD_SS_OPENED          0x00000002
+#define SMD_SS_FLUSHING                0x00000003
+#define SMD_SS_CLOSING         0x00000004
+#define SMD_SS_RESET           0x00000005
+#define SMD_SS_RESET_OPENING   0x00000006
+
+#define SMD_BUF_SIZE           8192
+#define SMD_CHANNELS           64
+
+#define SMD_HEADER_SIZE                20
+
+struct smd_alloc_elm {
+       char name[20];
+       uint32_t cid;
+       uint32_t ctype;
+       uint32_t ref_count;
+};
+
+struct smd_half_channel {
+       unsigned state;
+       unsigned char fDSR;
+       unsigned char fCTS;
+       unsigned char fCD;
+       unsigned char fRI;
+       unsigned char fHEAD;
+       unsigned char fTAIL;
+       unsigned char fSTATE;
+       unsigned char fUNUSED;
+       unsigned tail;
+       unsigned head;
+} __attribute__(( aligned(4), packed ));
+
+/* Only used on SMD package v3 on msm7201a */
+struct smd_shared_v1 {
+       struct smd_half_channel ch0;
+       unsigned char data0[SMD_BUF_SIZE];
+       struct smd_half_channel ch1;
+       unsigned char data1[SMD_BUF_SIZE];
+};
+
+/* Used on SMD package v4 */
+struct smd_shared_v2 {
+       struct smd_half_channel ch0;
+       struct smd_half_channel ch1;
+};
+
+struct smd_channel {
+       volatile struct smd_half_channel *send;
+       volatile struct smd_half_channel *recv;
+       unsigned char *send_data;
+       unsigned char *recv_data;
+
+       unsigned fifo_mask;
+       unsigned fifo_size;
+       unsigned current_packet;
+       unsigned n;
+
+       struct list_head ch_list;
+
+       void *priv;
+       void (*notify)(void *priv, unsigned flags);
+
+       int (*read)(struct smd_channel *ch, void *data, int len);
+       int (*write)(struct smd_channel *ch, const void *data, int len);
+       int (*read_avail)(struct smd_channel *ch);
+       int (*write_avail)(struct smd_channel *ch);
+
+       void (*update_state)(struct smd_channel *ch);
+       unsigned last_state;
+       void (*notify_other_cpu)(void);
+       unsigned type;
+
+       char name[32];
+       struct platform_device pdev;
+};
+
+#define SMD_TYPE_MASK          0x0FF
+#define SMD_TYPE_APPS_MODEM    0x000
+#define SMD_TYPE_APPS_DSP      0x001
+#define SMD_TYPE_MODEM_DSP     0x002
+
+#define SMD_KIND_MASK          0xF00
+#define SMD_KIND_UNKNOWN       0x000
+#define SMD_KIND_STREAM                0x100
+#define SMD_KIND_PACKET                0x200
+
+extern struct list_head smd_ch_closed_list;
+extern struct list_head smd_ch_list_modem;
+extern struct list_head smd_ch_list_dsp;
+
+extern spinlock_t smd_lock;
+extern spinlock_t smem_lock;
+
+void *smem_find(unsigned id, unsigned size);
+void *smem_item(unsigned id, unsigned *size);
+uint32_t raw_smsm_get_state(enum smsm_state_item item);
+
+extern void msm_init_last_radio_log(struct module *);
+
+#ifdef CONFIG_MSM_SMD_PKG3
+/*
+ * This allocator assumes an SMD Package v3 which only exists on
+ * MSM7x00 SoC's.
+ */
+static inline int _smd_alloc_channel(struct smd_channel *ch)
+{
+       struct smd_shared_v1 *shared1;
+
+       shared1 = smem_alloc(ID_SMD_CHANNELS + ch->n, sizeof(*shared1));
+       if (!shared1) {
+               pr_err("smd_alloc_channel() cid %d does not exist\n", ch->n);
+               return -1;
+       }
+       ch->send = &shared1->ch0;
+       ch->recv = &shared1->ch1;
+       ch->send_data = shared1->data0;
+       ch->recv_data = shared1->data1;
+       ch->fifo_size = SMD_BUF_SIZE;
+       return 0;
+}
+#else
+/*
+ * This allocator assumes an SMD Package v4, the most common
+ * and the default.
+ */
+static inline int _smd_alloc_channel(struct smd_channel *ch)
+{
+       struct smd_shared_v2 *shared2;
+       void *buffer;
+       unsigned buffer_sz;
+
+       shared2 = smem_alloc(SMEM_SMD_BASE_ID + ch->n, sizeof(*shared2));
+       buffer = smem_item(SMEM_SMD_FIFO_BASE_ID + ch->n, &buffer_sz);
+
+       if (!buffer)
+               return -1;
+
+       /* buffer must be a power-of-two size */
+       if (buffer_sz & (buffer_sz - 1))
+               return -1;
+
+       buffer_sz /= 2;
+       ch->send = &shared2->ch0;
+       ch->recv = &shared2->ch1;
+       ch->send_data = buffer;
+       ch->recv_data = buffer + buffer_sz;
+       ch->fifo_size = buffer_sz;
+       return 0;
+}
+#endif /* CONFIG_MSM_SMD_PKG3 */
+
+#if defined(CONFIG_ARCH_MSM7X30)
+static inline void msm_a2m_int(uint32_t irq)
+{
+       writel(1 << irq, MSM_GCC_BASE + 0x8);
+}
+#else
+static inline void msm_a2m_int(uint32_t irq)
+{
+       writel(1, MSM_CSR_BASE + 0x400 + (irq * 4));
+}
+#endif /* CONFIG_ARCH_MSM7X30 */
+
+
+#endif
index 4855b8c..dec5ca6 100644 (file)
@@ -25,7 +25,9 @@
 #include <asm/mach/time.h>
 #include <mach/msm_iomap.h>
 
+#ifndef MSM_DGT_BASE
 #define MSM_DGT_BASE (MSM_GPT_BASE + 0x10)
+#endif
 #define MSM_DGT_SHIFT (5)
 
 #define TIMER_MATCH_VAL         0x0000
index fcb0b9f..a9103bc 100644 (file)
@@ -1,6 +1,7 @@
 /* arch/arm/mach-msm/vreg.c
  *
  * Copyright (C) 2008 Google, Inc.
+ * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
  * Author: Brian Swetland <swetland@google.com>
  *
  * This software is licensed under the terms of the GNU General Public
@@ -18,6 +19,7 @@
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/debugfs.h>
+#include <linux/string.h>
 #include <mach/vreg.h>
 
 #include "proc_comm.h"
 struct vreg {
        const char *name;
        unsigned id;
+       int status;
+       unsigned refcnt;
 };
 
-#define VREG(_name, _id) { .name = _name, .id = _id, }
+#define VREG(_name, _id, _status, _refcnt) \
+       { .name = _name, .id = _id, .status = _status, .refcnt = _refcnt }
 
 static struct vreg vregs[] = {
-       VREG("msma",    0),
-       VREG("msmp",    1),
-       VREG("msme1",   2),
-       VREG("msmc1",   3),
-       VREG("msmc2",   4),
-       VREG("gp3",     5),
-       VREG("msme2",   6),
-       VREG("gp4",     7),
-       VREG("gp1",     8),
-       VREG("tcxo",    9),
-       VREG("pa",      10),
-       VREG("rftx",    11),
-       VREG("rfrx1",   12),
-       VREG("rfrx2",   13),
-       VREG("synt",    14),
-       VREG("wlan",    15),
-       VREG("usb",     16),
-       VREG("boost",   17),
-       VREG("mmc",     18),
-       VREG("ruim",    19),
-       VREG("msmc0",   20),
-       VREG("gp2",     21),
-       VREG("gp5",     22),
-       VREG("gp6",     23),
-       VREG("rf",      24),
-       VREG("rf_vco",  26),
-       VREG("mpll",    27),
-       VREG("s2",      28),
-       VREG("s3",      29),
-       VREG("rfubm",   30),
-       VREG("ncp",     31),
+       VREG("msma",    0, 0, 0),
+       VREG("msmp",    1, 0, 0),
+       VREG("msme1",   2, 0, 0),
+       VREG("msmc1",   3, 0, 0),
+       VREG("msmc2",   4, 0, 0),
+       VREG("gp3",     5, 0, 0),
+       VREG("msme2",   6, 0, 0),
+       VREG("gp4",     7, 0, 0),
+       VREG("gp1",     8, 0, 0),
+       VREG("tcxo",    9, 0, 0),
+       VREG("pa",      10, 0, 0),
+       VREG("rftx",    11, 0, 0),
+       VREG("rfrx1",   12, 0, 0),
+       VREG("rfrx2",   13, 0, 0),
+       VREG("synt",    14, 0, 0),
+       VREG("wlan",    15, 0, 0),
+       VREG("usb",     16, 0, 0),
+       VREG("boost",   17, 0, 0),
+       VREG("mmc",     18, 0, 0),
+       VREG("ruim",    19, 0, 0),
+       VREG("msmc0",   20, 0, 0),
+       VREG("gp2",     21, 0, 0),
+       VREG("gp5",     22, 0, 0),
+       VREG("gp6",     23, 0, 0),
+       VREG("rf",      24, 0, 0),
+       VREG("rf_vco",  26, 0, 0),
+       VREG("mpll",    27, 0, 0),
+       VREG("s2",      28, 0, 0),
+       VREG("s3",      29, 0, 0),
+       VREG("rfubm",   30, 0, 0),
+       VREG("ncp",     31, 0, 0),
+       VREG("gp7",     32, 0, 0),
+       VREG("gp8",     33, 0, 0),
+       VREG("gp9",     34, 0, 0),
+       VREG("gp10",    35, 0, 0),
+       VREG("gp11",    36, 0, 0),
+       VREG("gp12",    37, 0, 0),
+       VREG("gp13",    38, 0, 0),
+       VREG("gp14",    39, 0, 0),
+       VREG("gp15",    40, 0, 0),
+       VREG("gp16",    41, 0, 0),
+       VREG("gp17",    42, 0, 0),
+       VREG("s4",      43, 0, 0),
+       VREG("usb2",    44, 0, 0),
+       VREG("wlan2",   45, 0, 0),
+       VREG("xo_out",  46, 0, 0),
+       VREG("lvsw0",   47, 0, 0),
+       VREG("lvsw1",   48, 0, 0),
 };
 
 struct vreg *vreg_get(struct device *dev, const char *id)
@@ -70,7 +92,7 @@ struct vreg *vreg_get(struct device *dev, const char *id)
                if (!strcmp(vregs[n].name, id))
                        return vregs + n;
        }
-       return 0;
+       return ERR_PTR(-ENOENT);
 }
 
 void vreg_put(struct vreg *vreg)
@@ -81,20 +103,39 @@ int vreg_enable(struct vreg *vreg)
 {
        unsigned id = vreg->id;
        unsigned enable = 1;
-       return msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
+
+       if (vreg->refcnt == 0)
+               vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
+
+       if ((vreg->refcnt < UINT_MAX) && (!vreg->status))
+               vreg->refcnt++;
+
+       return vreg->status;
 }
 
-void vreg_disable(struct vreg *vreg)
+int vreg_disable(struct vreg *vreg)
 {
        unsigned id = vreg->id;
        unsigned enable = 0;
-       msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
+
+       if (!vreg->refcnt)
+               return 0;
+
+       if (vreg->refcnt == 1)
+               vreg->status = msm_proc_comm(PCOM_VREG_SWITCH, &id, &enable);
+
+       if (!vreg->status)
+               vreg->refcnt--;
+
+       return vreg->status;
 }
 
 int vreg_set_level(struct vreg *vreg, unsigned mv)
 {
        unsigned id = vreg->id;
-       return msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
+
+       vreg->status = msm_proc_comm(PCOM_VREG_SET_LEVEL, &id, &mv);
+       return vreg->status;
 }
 
 #if defined(CONFIG_DEBUG_FS)
@@ -118,24 +159,59 @@ static int vreg_debug_set(void *data, u64 val)
 
 static int vreg_debug_get(void *data, u64 *val)
 {
-       return -ENOSYS;
+       struct vreg *vreg = data;
+
+       if (!vreg->status)
+               *val = 0;
+       else
+               *val = 1;
+
+       return 0;
+}
+
+static int vreg_debug_count_set(void *data, u64 val)
+{
+       struct vreg *vreg = data;
+       if (val > UINT_MAX)
+               val = UINT_MAX;
+       vreg->refcnt = val;
+       return 0;
+}
+
+static int vreg_debug_count_get(void *data, u64 *val)
+{
+       struct vreg *vreg = data;
+
+       *val = vreg->refcnt;
+
+       return 0;
 }
 
 DEFINE_SIMPLE_ATTRIBUTE(vreg_fops, vreg_debug_get, vreg_debug_set, "%llu\n");
+DEFINE_SIMPLE_ATTRIBUTE(vreg_count_fops, vreg_debug_count_get,
+                       vreg_debug_count_set, "%llu\n");
 
 static int __init vreg_debug_init(void)
 {
        struct dentry *dent;
        int n;
+       char name[32];
+       const char *refcnt_name = "_refcnt";
 
        dent = debugfs_create_dir("vreg", 0);
        if (IS_ERR(dent))
                return 0;
 
-       for (n = 0; n < ARRAY_SIZE(vregs); n++)
+       for (n = 0; n < ARRAY_SIZE(vregs); n++) {
                (void) debugfs_create_file(vregs[n].name, 0644,
                                           dent, vregs + n, &vreg_fops);
 
+               strlcpy(name, vregs[n].name, sizeof(name));
+               strlcat(name, refcnt_name, sizeof(name));
+               (void) debugfs_create_file(name, 0644,
+                                          dent, vregs + n, &vreg_count_fops);
+       }
+
        return 0;
 }
 
index 3c5e0f5..71f3ea6 100644 (file)
@@ -6,6 +6,7 @@ config MACH_NOMADIK_8815NHK
        bool "ST 8815 Nomadik Hardware Kit (evaluation board)"
        select NOMADIK_8815
        select HAS_MTU
+       select NOMADIK_GPIO
 
 endmenu
 
index 36f67fb..a6bbd1a 100644 (file)
@@ -7,7 +7,7 @@
 
 # Object file lists.
 
-obj-y                  += clock.o gpio.o
+obj-y                  += clock.o
 
 # Cpu revision
 obj-$(CONFIG_NOMADIK_8815) += cpu-8815.o
index ab3712c..841d459 100644 (file)
@@ -32,7 +32,6 @@
 #include <mach/setup.h>
 #include <mach/nand.h>
 #include <mach/fsmc.h>
-#include "clock.h"
 
 /* Initial value for SRC control register: all timers use MXTAL/8 source */
 #define SRC_CR_INIT_MASK       0x00007fff
@@ -202,11 +201,6 @@ static struct amba_device *amba_devs[] __initdata = {
        &uart1_device,
 };
 
-/* We have a fixed clock alone, by now */
-static struct clk nhk8815_clk_48 = {
-       .rate = 48*1000*1000,
-};
-
 static struct resource nhk8815_eth_resources[] = {
        {
                .name = "smc91x-regs",
@@ -276,10 +270,8 @@ static void __init nhk8815_platform_init(void)
        platform_add_devices(nhk8815_platform_devices,
                             ARRAY_SIZE(nhk8815_platform_devices));
 
-       for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
-               nmdk_clk_create(&nhk8815_clk_48, amba_devs[i]->dev.init_name);
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
                amba_device_register(amba_devs[i], &iomem_resource);
-       }
 }
 
 MACHINE_START(NOMADIK, "NHK8815")
index 9f92502..60f5bee 100644 (file)
@@ -32,14 +32,36 @@ void clk_disable(struct clk *clk)
 }
 EXPORT_SYMBOL(clk_disable);
 
-/* Create a clock structure with the given name */
-int nmdk_clk_create(struct clk *clk, const char *dev_id)
-{
-       struct clk_lookup *clkdev;
+/* We have a fixed clock alone, for now */
+static struct clk clk_48 = {
+       .rate = 48 * 1000 * 1000,
+};
+
+/*
+ * Catch-all default clock to satisfy drivers using the clk API.  We don't
+ * model the actual hardware clocks yet.
+ */
+static struct clk clk_default;
 
-       clkdev = clkdev_alloc(clk, NULL, dev_id);
-       if (!clkdev)
-               return -ENOMEM;
-       clkdev_add(clkdev);
+#define CLK(_clk, dev)                         \
+       {                                       \
+               .clk            = _clk,         \
+               .dev_id         = dev,          \
+       }
+
+static struct clk_lookup lookups[] = {
+       CLK(&clk_48, "uart0"),
+       CLK(&clk_48, "uart1"),
+       CLK(&clk_default, "gpio.0"),
+       CLK(&clk_default, "gpio.1"),
+       CLK(&clk_default, "gpio.2"),
+       CLK(&clk_default, "gpio.3"),
+};
+
+static int __init clk_init(void)
+{
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
        return 0;
 }
+
+arch_initcall(clk_init);
index 235faec..5563985 100644 (file)
@@ -11,4 +11,3 @@
 struct clk {
        unsigned long           rate;
 };
-extern int nmdk_clk_create(struct clk *clk, const char *dev_id);
index 9bf33b3..91c3c90 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/init.h>
 #include <linux/device.h>
 #include <linux/amba/bus.h>
+#include <linux/platform_device.h>
 #include <linux/gpio.h>
 
 #include <mach/hardware.h>
 #include <asm/cacheflush.h>
 #include <asm/hardware/cache-l2x0.h>
 
+#define __MEM_4K_RESOURCE(x) \
+       .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
+
 /* The 8815 has 4 GPIO blocks, let's register them immediately */
+
+#define GPIO_RESOURCE(block)                                           \
+       {                                                               \
+               .start  = NOMADIK_GPIO##block##_BASE,                   \
+               .end    = NOMADIK_GPIO##block##_BASE + SZ_4K - 1,       \
+               .flags  = IORESOURCE_MEM,                               \
+       },                                                              \
+       {                                                               \
+               .start  = IRQ_GPIO##block,                              \
+               .end    = IRQ_GPIO##block,                              \
+               .flags  = IORESOURCE_IRQ,                               \
+       }
+
+#define GPIO_DEVICE(block)                                             \
+       {                                                               \
+               .name           = "gpio",                               \
+               .id             = block,                                \
+               .num_resources  = 2,                                    \
+               .resource       = &cpu8815_gpio_resources[block * 2],   \
+               .dev = {                                                \
+                       .platform_data = &cpu8815_gpio[block],          \
+               },                                                      \
+       }
+
 static struct nmk_gpio_platform_data cpu8815_gpio[] = {
        {
                .name = "GPIO-0-31",
                .first_gpio = 0,
                .first_irq = NOMADIK_GPIO_TO_IRQ(0),
-               .parent_irq = IRQ_GPIO0,
        }, {
                .name = "GPIO-32-63",
                .first_gpio = 32,
                .first_irq = NOMADIK_GPIO_TO_IRQ(32),
-               .parent_irq = IRQ_GPIO1,
        }, {
                .name = "GPIO-64-95",
                .first_gpio = 64,
                .first_irq = NOMADIK_GPIO_TO_IRQ(64),
-               .parent_irq = IRQ_GPIO2,
        }, {
                .name = "GPIO-96-127", /* 124..127 not routed to pin */
                .first_gpio = 96,
                .first_irq = NOMADIK_GPIO_TO_IRQ(96),
-               .parent_irq = IRQ_GPIO3,
        }
 };
 
-#define __MEM_4K_RESOURCE(x) \
-       .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
+static struct resource cpu8815_gpio_resources[] = {
+       GPIO_RESOURCE(0),
+       GPIO_RESOURCE(1),
+       GPIO_RESOURCE(2),
+       GPIO_RESOURCE(3),
+};
 
-static struct amba_device cpu8815_amba_gpio[] = {
-       {
-               .dev = {
-                       .init_name = "gpio0",
-                       .platform_data = cpu8815_gpio + 0,
-               },
-               __MEM_4K_RESOURCE(NOMADIK_GPIO0_BASE),
-       }, {
-               .dev = {
-                       .init_name = "gpio1",
-                       .platform_data = cpu8815_gpio + 1,
-               },
-               __MEM_4K_RESOURCE(NOMADIK_GPIO1_BASE),
-       }, {
-               .dev = {
-                       .init_name = "gpio2",
-                       .platform_data = cpu8815_gpio + 2,
-               },
-               __MEM_4K_RESOURCE(NOMADIK_GPIO2_BASE),
-       }, {
-               .dev = {
-                       .init_name = "gpio3",
-                       .platform_data = cpu8815_gpio + 3,
-               },
-               __MEM_4K_RESOURCE(NOMADIK_GPIO3_BASE),
-       },
+static struct platform_device cpu8815_platform_gpio[] = {
+       GPIO_DEVICE(0),
+       GPIO_DEVICE(1),
+       GPIO_DEVICE(2),
+       GPIO_DEVICE(3),
 };
 
 static struct amba_device cpu8815_amba_rng = {
@@ -93,11 +100,14 @@ static struct amba_device cpu8815_amba_rng = {
        __MEM_4K_RESOURCE(NOMADIK_RNG_BASE),
 };
 
+static struct platform_device *platform_devs[] __initdata = {
+       cpu8815_platform_gpio + 0,
+       cpu8815_platform_gpio + 1,
+       cpu8815_platform_gpio + 2,
+       cpu8815_platform_gpio + 3,
+};
+
 static struct amba_device *amba_devs[] __initdata = {
-       cpu8815_amba_gpio + 0,
-       cpu8815_amba_gpio + 1,
-       cpu8815_amba_gpio + 2,
-       cpu8815_amba_gpio + 3,
        &cpu8815_amba_rng
 };
 
@@ -105,6 +115,7 @@ static int __init cpu8815_init(void)
 {
        int i;
 
+       platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
                amba_device_register(amba_devs[i], &iomem_resource);
        return 0;
index 61577c9..7a81a04 100644 (file)
@@ -1,71 +1,6 @@
-/*
- * Structures and registers for GPIO access in the Nomadik SoC
- *
- * Copyright (C) 2008 STMicroelectronics
- *     Author: Prafulla WADASKAR <prafulla.wadaskar@st.com>
- * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
 #ifndef __ASM_ARCH_GPIO_H
 #define __ASM_ARCH_GPIO_H
 
-#include <asm-generic/gpio.h>
-
-/*
- * These currently cause a function call to happen, they may be optimized
- * if needed by adding cpu-specific defines to identify blocks
- * (see mach-pxa/include/mach/gpio.h as an example using GPLR etc)
- */
-#define gpio_get_value  __gpio_get_value
-#define gpio_set_value  __gpio_set_value
-#define gpio_cansleep   __gpio_cansleep
-#define gpio_to_irq     __gpio_to_irq
-
-/*
- * "nmk_gpio" and "NMK_GPIO" stand for "Nomadik GPIO", leaving
- * the "gpio" namespace for generic and cross-machine functions
- */
-
-/* Register in the logic block */
-#define NMK_GPIO_DAT   0x00
-#define NMK_GPIO_DATS  0x04
-#define NMK_GPIO_DATC  0x08
-#define NMK_GPIO_PDIS  0x0c
-#define NMK_GPIO_DIR   0x10
-#define NMK_GPIO_DIRS  0x14
-#define NMK_GPIO_DIRC  0x18
-#define NMK_GPIO_SLPC  0x1c
-#define NMK_GPIO_AFSLA 0x20
-#define NMK_GPIO_AFSLB 0x24
-
-#define NMK_GPIO_RIMSC 0x40
-#define NMK_GPIO_FIMSC 0x44
-#define NMK_GPIO_IS    0x48
-#define NMK_GPIO_IC    0x4c
-#define NMK_GPIO_RWIMSC        0x50
-#define NMK_GPIO_FWIMSC        0x54
-#define NMK_GPIO_WKS   0x58
-
-/* Alternate functions: function C is set in hw by setting both A and B */
-#define NMK_GPIO_ALT_GPIO      0
-#define NMK_GPIO_ALT_A 1
-#define NMK_GPIO_ALT_B 2
-#define NMK_GPIO_ALT_C (NMK_GPIO_ALT_A | NMK_GPIO_ALT_B)
-
-extern int nmk_gpio_set_mode(int gpio, int gpio_mode);
-extern int nmk_gpio_get_mode(int gpio);
-
-/*
- * Platform data to register a block: only the initial gpio/irq number.
- */
-struct nmk_gpio_platform_data {
-       char *name;
-       int first_gpio;
-       int first_irq;
-       int parent_irq;
-};
+#include <plat/gpio.h>
 
 #endif /* __ASM_ARCH_GPIO_H */
index e36639f..8e313b4 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/input.h>
-#include <linux/bootmem.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
 
index 2271b9b..12154d1 100644 (file)
 #include <linux/clk.h>
 
 #include <mach/hardware.h>
+#include <mach/irqs.h>
 #include <asm/mach-types.h>
 #include <asm/mach/map.h>
+#include <asm/pmu.h>
 
 #include <plat/control.h>
 #include <plat/tc.h>
@@ -453,6 +455,37 @@ static void omap_init_mcspi(void)
 static inline void omap_init_mcspi(void) {}
 #endif
 
+static struct resource omap2_pmu_resource = {
+       .start  = 3,
+       .end    = 3,
+       .flags  = IORESOURCE_IRQ,
+};
+
+static struct resource omap3_pmu_resource = {
+       .start  = INT_34XX_BENCH_MPU_EMUL,
+       .end    = INT_34XX_BENCH_MPU_EMUL,
+       .flags  = IORESOURCE_IRQ,
+};
+
+static struct platform_device omap_pmu_device = {
+       .name           = "arm-pmu",
+       .id             = ARM_PMU_DEVICE_CPU,
+       .num_resources  = 1,
+};
+
+static void omap_init_pmu(void)
+{
+       if (cpu_is_omap24xx())
+               omap_pmu_device.resource = &omap2_pmu_resource;
+       else if (cpu_is_omap34xx())
+               omap_pmu_device.resource = &omap3_pmu_resource;
+       else
+               return;
+
+       platform_device_register(&omap_pmu_device);
+}
+
+
 #ifdef CONFIG_OMAP_SHA1_MD5
 static struct resource sha1_md5_resources[] = {
        {
@@ -797,6 +830,7 @@ static int __init omap2_init_devices(void)
        omap_init_camera();
        omap_init_mbox();
        omap_init_mcspi();
+       omap_init_pmu();
        omap_hdq_init();
        omap_init_sti();
        omap_init_sha1_md5();
index 2f3cad6..c293370 100644 (file)
@@ -187,32 +187,28 @@ static struct omap_mcbsp_platform_data omap44xx_mcbsp_pdata[] = {
                .phys_base      = OMAP44XX_MCBSP1_BASE,
                .dma_rx_sync    = OMAP44XX_DMA_MCBSP1_RX,
                .dma_tx_sync    = OMAP44XX_DMA_MCBSP1_TX,
-               .rx_irq         = INT_24XX_MCBSP1_IRQ_RX,
-               .tx_irq         = INT_24XX_MCBSP1_IRQ_TX,
+               .tx_irq         = OMAP44XX_IRQ_MCBSP1,
                .ops            = &omap2_mcbsp_ops,
        },
        {
                .phys_base      = OMAP44XX_MCBSP2_BASE,
                .dma_rx_sync    = OMAP44XX_DMA_MCBSP2_RX,
                .dma_tx_sync    = OMAP44XX_DMA_MCBSP2_TX,
-               .rx_irq         = INT_24XX_MCBSP2_IRQ_RX,
-               .tx_irq         = INT_24XX_MCBSP2_IRQ_TX,
+               .tx_irq         = OMAP44XX_IRQ_MCBSP2,
                .ops            = &omap2_mcbsp_ops,
        },
        {
                .phys_base      = OMAP44XX_MCBSP3_BASE,
                .dma_rx_sync    = OMAP44XX_DMA_MCBSP3_RX,
                .dma_tx_sync    = OMAP44XX_DMA_MCBSP3_TX,
-               .rx_irq         = INT_24XX_MCBSP3_IRQ_RX,
-               .tx_irq         = INT_24XX_MCBSP3_IRQ_TX,
+               .tx_irq         = OMAP44XX_IRQ_MCBSP3,
                .ops            = &omap2_mcbsp_ops,
        },
        {
                .phys_base      = OMAP44XX_MCBSP4_BASE,
                .dma_rx_sync    = OMAP44XX_DMA_MCBSP4_RX,
                .dma_tx_sync    = OMAP44XX_DMA_MCBSP4_TX,
-               .rx_irq         = INT_24XX_MCBSP4_IRQ_RX,
-               .tx_irq         = INT_24XX_MCBSP4_IRQ_TX,
+               .tx_irq         = OMAP44XX_IRQ_MCBSP4,
                .ops            = &omap2_mcbsp_ops,
        },
 };
index e436dcb..2c12e8c 100644 (file)
@@ -43,7 +43,6 @@
 #include <linux/err.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
-#include <linux/bootmem.h>
 
 #include <plat/common.h>
 #include <plat/cpu.h>
index 421b82f..685f34a 100644 (file)
@@ -439,6 +439,7 @@ static void __init dns323_init(void)
         */
        if (dns323_dev_id() == MV88F5181_DEV_ID) {
                dns323_leds[0].active_low = 1;
+               gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
                gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
        }
 
index 5b6ee46..3b51741 100644 (file)
@@ -19,7 +19,6 @@ config MACH_MAINSTONE
 config MACH_ZYLONITE
        bool
        select PXA3xx
-       select PXA_SSP
        select HAVE_PWM
        select PXA_HAVE_BOARD_IRQS
 
@@ -39,7 +38,6 @@ config MACH_LITTLETON
        select PXA3xx
        select CPU_PXA300
        select CPU_PXA310
-       select PXA_SSP
 
 config MACH_TAVOREVB
        bool "PXA930 Evaluation Board (aka TavorEVB)"
@@ -98,7 +96,6 @@ config MACH_ARMCORE
        select PXA27x
        select IWMMXT
        select PXA25x
-       select PXA_SSP
 
 config MACH_EM_X270
        bool "CompuLab EM-x270 platform"
@@ -161,7 +158,6 @@ config MACH_XCEP
        select MTD_CFI
        select MTD_CHAR
        select SMC91X
-       select PXA_SSP
        help
          PXA255 based Single Board Computer with SMC 91C111 ethernet chip and 64 MB of flash.
          Tuned for usage in Libera instruments for particle accelerators.
@@ -180,7 +176,6 @@ config MACH_TRIZEPS4WL
        depends on TRIZEPS_PXA
        select TRIZEPS_PCMCIA
        select PXA27x
-       select PXA_SSP
 
 choice
        prompt "Select base board for Trizeps module"
@@ -217,7 +212,6 @@ config MACH_PCM027
        bool "Phytec phyCORE-PXA270 CPU module (PCM-027)"
        select PXA27x
        select IWMMXT
-       select PXA_SSP
        select PXA_HAVE_BOARD_IRQS
 
 config MACH_PCM990_BASEBOARD
@@ -255,13 +249,19 @@ config MACH_COLIBRI320
        select PXA3xx
        select CPU_PXA320
 
+config MACH_VPAC270
+       bool "Voipac PXA270"
+       select PXA27x
+       select HAVE_PATA_PLATFORM
+       help
+         PXA270 based Single Board Computer.
+
 comment "End-user Products (sorted by vendor name)"
 
 config MACH_H4700
        bool "HP iPAQ hx4700"
        select PXA27x
        select IWMMXT
-       select PXA_SSP
        select HAVE_PWM
        select PXA_HAVE_BOARD_IRQS
 
@@ -277,7 +277,6 @@ config MACH_MAGICIAN
        bool "Enable HTC Magician Support"
        select PXA27x
        select IWMMXT
-       select PXA_SSP
        select HAVE_PWM
        select PXA_HAVE_BOARD_IRQS
 
@@ -431,13 +430,11 @@ config MACH_RAUMFELD_CONNECTOR
        bool "Raumfeld Connector"
        select PXA3xx
        select CPU_PXA300
-       select PXA_SSP
 
 config MACH_RAUMFELD_SPEAKER
        bool "Raumfeld Speaker"
        select PXA3xx
        select CPU_PXA300
-       select PXA_SSP
 
 config PXA_SHARPSL
        bool "SHARP Zaurus SL-5600, SL-C7xx and SL-Cxx00 Models"
@@ -461,21 +458,11 @@ config SHARPSL_PM_MAX1111
        select HWMON
        select SENSORS_MAX1111
 
-config CORGI_SSP_DEPRECATED
-       bool
-       select PXA_SSP
-       select PXA_SSP_LEGACY
-       help
-         This option will include corgi_ssp.c and corgi_lcd.c
-         that corgi_ts.c and other legacy drivers (corgi_bl.c
-         and sharpsl_pm.c) may depend on.
-
 config MACH_POODLE
        bool "Enable Sharp SL-5600 (Poodle) Support"
        depends on PXA_SHARPSL
        select PXA25x
        select SHARP_LOCOMO
-       select PXA_SSP
        select PXA_HAVE_BOARD_IRQS
 
 config MACH_CORGI
@@ -581,6 +568,12 @@ config MACH_E800
          Say Y here if you intend to run this kernel on a Toshiba
          e800 family PDA.
 
+config MACH_ZIPIT2
+       bool "Zipit Z2 Handheld"
+       select PXA27x
+       select HAVE_PWM
+       select PXA_HAVE_BOARD_IRQS
+
 endmenu
 
 config PXA25x
@@ -645,28 +638,16 @@ config CPU_PXA950
 
 config PXA_SHARP_C7xx
        bool
-       select PXA_SSP
        select SHARPSL_PM
        help
          Enable support for all Sharp C7xx models
 
 config PXA_SHARP_Cxx00
        bool
-       select PXA_SSP
        select SHARPSL_PM
        help
          Enable common support for Sharp Cxx00 models
 
-config PXA_SSP
-       tristate
-       help
-         Enable support for PXA2xx SSP ports
-
-config PXA_SSP_LEGACY
-       bool
-       help
-         Support of legacy SSP API
-
 config TOSA_BT
        tristate "Control the state of built-in bluetooth chip on Sharp SL-6000"
        depends on MACH_TOSA
@@ -675,6 +656,18 @@ config TOSA_BT
          This is a simple driver that is able to control
          the state of built in bluetooth chip on tosa.
 
+config TOSA_USE_EXT_KEYCODES
+       bool "Tosa keyboard: use extended keycodes"
+       depends on MACH_TOSA
+       default n
+       help
+         Say Y here to enable the tosa keyboard driver to generate extended
+         (>= 127) keycodes. Be aware, that they can't be correctly interpreted
+         by either console keyboard driver or by Kdrive keybd driver.
+
+         Say Y only if you know, what you are doing!
+
+
 config PXA_HAVE_BOARD_IRQS
        bool
 
index 86bc87b..b8f1f4b 100644 (file)
@@ -14,7 +14,6 @@ obj-$(CONFIG_PXA3xx)          += cpufreq-pxa3xx.o
 endif
 
 # Generic drivers that other drivers may depend upon
-obj-$(CONFIG_PXA_SSP)          += ssp.o
 
 # SoC-specific code
 obj-$(CONFIG_PXA25x)           += mfp-pxa2xx.o pxa2xx.o pxa25x.o
@@ -62,6 +61,7 @@ obj-$(CONFIG_MACH_PCM990_BASEBOARD)   += pcm990-baseboard.o
 obj-$(CONFIG_MACH_COLIBRI)     += colibri-pxa270.o
 obj-$(CONFIG_MACH_COLIBRI300)  += colibri-pxa3xx.o colibri-pxa300.o
 obj-$(CONFIG_MACH_COLIBRI320)  += colibri-pxa3xx.o colibri-pxa320.o
+obj-$(CONFIG_MACH_VPAC270)     += vpac270.o
 
 # End-user Products
 obj-$(CONFIG_MACH_H4700)       += hx4700.o
@@ -80,7 +80,6 @@ obj-$(CONFIG_MACH_PALMLD)     += palmld.o
 obj-$(CONFIG_PALM_TREO)                += palmtreo.o
 obj-$(CONFIG_PXA_SHARP_C7xx)   += corgi.o sharpsl_pm.o corgi_pm.o
 obj-$(CONFIG_PXA_SHARP_Cxx00)  += spitz.o sharpsl_pm.o spitz_pm.o
-obj-$(CONFIG_CORGI_SSP_DEPRECATED)     += corgi_ssp.o corgi_lcd.o
 obj-$(CONFIG_MACH_POODLE)      += poodle.o
 obj-$(CONFIG_MACH_TOSA)                += tosa.o
 obj-$(CONFIG_MACH_ICONTROL)     += icontrol.o mxm8x10.o
@@ -94,6 +93,7 @@ obj-$(CONFIG_MACH_E800)               += e800.o
 obj-$(CONFIG_MACH_RAUMFELD_RC)         += raumfeld.o
 obj-$(CONFIG_MACH_RAUMFELD_CONNECTOR)  += raumfeld.o
 obj-$(CONFIG_MACH_RAUMFELD_SPEAKER)    += raumfeld.o
+obj-$(CONFIG_MACH_ZIPIT2)      += z2.o
 
 # Support for blinky lights
 led-y := leds.o
index d37cfa1..fdda6be 100644 (file)
@@ -30,6 +30,9 @@
 #include <linux/i2c/pca953x.h>
 
 #include <linux/mfd/da903x.h>
+#include <linux/regulator/machine.h>
+#include <linux/power_supply.h>
+#include <linux/apm-emulation.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/spi_gpio.h>
@@ -430,7 +433,7 @@ static inline void cm_x300_init_nand(void) {}
 
 #if defined(CONFIG_MMC) || defined(CONFIG_MMC_MODULE)
 static struct pxamci_platform_data cm_x300_mci_platform_data = {
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .gpio_card_detect       = GPIO82_MMC_IRQ,
        .gpio_card_ro           = GPIO85_MMC_WP,
@@ -451,7 +454,7 @@ static void cm_x300_mci2_exit(struct device *dev, void *data)
 }
 
 static struct pxamci_platform_data cm_x300_mci2_platform_data = {
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .init                   = cm_x300_mci2_init,
        .exit                   = cm_x300_mci2_exit,
@@ -584,12 +587,87 @@ static void __init cm_x300_init_rtc(void)
 static inline void cm_x300_init_rtc(void) {}
 #endif
 
+/* Battery */
+struct power_supply_info cm_x300_psy_info = {
+       .name = "battery",
+       .technology = POWER_SUPPLY_TECHNOLOGY_LIPO,
+       .voltage_max_design = 4200000,
+       .voltage_min_design = 3000000,
+       .use_for_apm = 1,
+};
+
+static void cm_x300_battery_low(void)
+{
+#if defined(CONFIG_APM_EMULATION)
+       apm_queue_event(APM_LOW_BATTERY);
+#endif
+}
+
+static void cm_x300_battery_critical(void)
+{
+#if defined(CONFIG_APM_EMULATION)
+       apm_queue_event(APM_CRITICAL_SUSPEND);
+#endif
+}
+
+struct da9030_battery_info cm_x300_battery_info = {
+       .battery_info = &cm_x300_psy_info,
+
+       .charge_milliamp = 1000,
+       .charge_millivolt = 4200,
+
+       .vbat_low = 3600,
+       .vbat_crit = 3400,
+       .vbat_charge_start = 4100,
+       .vbat_charge_stop = 4200,
+       .vbat_charge_restart = 4000,
+
+       .vcharge_min = 3200,
+       .vcharge_max = 5500,
+
+       .tbat_low = 197,
+       .tbat_high = 78,
+       .tbat_restart = 100,
+
+       .batmon_interval = 0,
+
+       .battery_low = cm_x300_battery_low,
+       .battery_critical = cm_x300_battery_critical,
+};
+
+static struct regulator_consumer_supply buck2_consumers[] = {
+       {
+               .dev = NULL,
+               .supply = "vcc_core",
+       },
+};
+
+static struct regulator_init_data buck2_data = {
+       .constraints = {
+               .min_uV = 1375000,
+               .max_uV = 1375000,
+               .state_mem = {
+                       .enabled = 0,
+               },
+               .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
+               .apply_uV = 1,
+       },
+       .num_consumer_supplies = ARRAY_SIZE(buck2_consumers),
+       .consumer_supplies = buck2_consumers,
+};
+
 /* DA9030 */
 struct da903x_subdev_info cm_x300_da9030_subdevs[] = {
        {
-               .name = "da903x-backlight",
-               .id = DA9030_ID_WLED,
-       }
+               .name = "da903x-battery",
+               .id = DA9030_ID_BAT,
+               .platform_data = &cm_x300_battery_info,
+       },
+       {
+               .name = "da903x-regulator",
+               .id = DA9030_ID_BUCK2,
+               .platform_data = &buck2_data,
+       },
 };
 
 static struct da903x_platform_data cm_x300_da9030_info = {
@@ -599,7 +677,7 @@ static struct da903x_platform_data cm_x300_da9030_info = {
 
 static struct i2c_board_info cm_x300_pmic_info = {
        I2C_BOARD_INFO("da9030", 0x49),
-       .irq = IRQ_GPIO(0),
+       .irq = IRQ_WAKEUP0,
        .platform_data = &cm_x300_da9030_info,
 };
 
@@ -689,13 +767,13 @@ static void __init cm_x300_init(void)
 static void __init cm_x300_fixup(struct machine_desc *mdesc, struct tag *tags,
                                 char **cmdline, struct meminfo *mi)
 {
-       mi->nr_banks = 2;
-       mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
-       mi->bank[0].size = (64*1024*1024);
-       mi->bank[1].start = 0xc0000000;
-       mi->bank[1].node = 0;
-       mi->bank[1].size = (64*1024*1024);
+       /* Make sure that mi->bank[0].start = PHYS_ADDR */
+       for (; tags->hdr.size; tags = tag_next(tags))
+               if (tags->hdr.tag == ATAG_MEM &&
+                       tags->u.mem.start == 0x80000000) {
+                       tags->u.mem.start = 0xa0000000;
+                       break;
+               }
 }
 
 MACHINE_START(CM_X300, "CM-X300 module")
index e6c0a22..199afa2 100644 (file)
@@ -96,7 +96,7 @@ static void colibri_pxa3xx_mci_exit(struct device *dev, void *data)
 }
 
 static struct pxamci_platform_data colibri_pxa3xx_mci_platform_data = {
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
        .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
        .init                   = colibri_pxa3xx_mci_init,
        .exit                   = colibri_pxa3xx_mci_exit,
index da3156d..3d1dcb9 100644 (file)
@@ -106,18 +106,18 @@ static unsigned long corgi_pin_config[] __initdata = {
        GPIO8_MMC_CS0,
 
        /* GPIO Matrix Keypad */
-       GPIO66_GPIO,    /* column 0 */
-       GPIO67_GPIO,    /* column 1 */
-       GPIO68_GPIO,    /* column 2 */
-       GPIO69_GPIO,    /* column 3 */
-       GPIO70_GPIO,    /* column 4 */
-       GPIO71_GPIO,    /* column 5 */
-       GPIO72_GPIO,    /* column 6 */
-       GPIO73_GPIO,    /* column 7 */
-       GPIO74_GPIO,    /* column 8 */
-       GPIO75_GPIO,    /* column 9 */
-       GPIO76_GPIO,    /* column 10 */
-       GPIO77_GPIO,    /* column 11 */
+       GPIO66_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 0 */
+       GPIO67_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 1 */
+       GPIO68_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 2 */
+       GPIO69_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 3 */
+       GPIO70_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 4 */
+       GPIO71_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 5 */
+       GPIO72_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 6 */
+       GPIO73_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 7 */
+       GPIO74_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 8 */
+       GPIO75_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 9 */
+       GPIO76_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 10 */
+       GPIO77_GPIO | MFP_LPM_DRIVE_HIGH,       /* column 11 */
        GPIO58_GPIO,    /* row 0 */
        GPIO59_GPIO,    /* row 1 */
        GPIO60_GPIO,    /* row 2 */
@@ -128,13 +128,20 @@ static unsigned long corgi_pin_config[] __initdata = {
        GPIO65_GPIO,    /* row 7 */
 
        /* GPIO */
-       GPIO9_GPIO,     /* CORGI_GPIO_nSD_DETECT */
-       GPIO7_GPIO,     /* CORGI_GPIO_nSD_WP */
-       GPIO33_GPIO,    /* CORGI_GPIO_SD_PWR */
-       GPIO22_GPIO,    /* CORGI_GPIO_IR_ON */
-       GPIO44_GPIO,    /* CORGI_GPIO_HSYNC */
-
-       GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
+       GPIO9_GPIO,                             /* CORGI_GPIO_nSD_DETECT */
+       GPIO7_GPIO,                             /* CORGI_GPIO_nSD_WP */
+       GPIO11_GPIO | WAKEUP_ON_EDGE_BOTH,      /* CORGI_GPIO_MAIN_BAT_{LOW,COVER} */
+       GPIO13_GPIO | MFP_LPM_KEEP_OUTPUT,      /* CORGI_GPIO_LED_ORANGE */
+       GPIO21_GPIO,                            /* CORGI_GPIO_ADC_TEMP */
+       GPIO22_GPIO,                            /* CORGI_GPIO_IR_ON */
+       GPIO33_GPIO,                            /* CORGI_GPIO_SD_PWR */
+       GPIO38_GPIO | MFP_LPM_KEEP_OUTPUT,      /* CORGI_GPIO_CHRG_ON */
+       GPIO43_GPIO | MFP_LPM_KEEP_OUTPUT,      /* CORGI_GPIO_CHRG_UKN */
+       GPIO44_GPIO,                            /* CORGI_GPIO_HSYNC */
+
+       GPIO0_GPIO | WAKEUP_ON_EDGE_BOTH,       /* CORGI_GPIO_KEY_INT */
+       GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,       /* CORGI_GPIO_AC_IN */
+       GPIO3_GPIO | WAKEUP_ON_EDGE_BOTH,       /* CORGI_GPIO_WAKEUP */
 };
 
 /*
@@ -437,6 +444,7 @@ static struct platform_device corgiled_device = {
  * to give the card a chance to fully insert/eject.
  */
 static struct pxamci_platform_data corgi_mci_platform_data = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .gpio_card_detect       = -1,
        .gpio_card_ro           = CORGI_GPIO_nSD_WP,
@@ -672,6 +680,15 @@ static void __init corgi_init(void)
 
        pxa2xx_mfp_config(ARRAY_AND_SIZE(corgi_pin_config));
 
+       /* allow wakeup from various GPIOs */
+       gpio_set_wake(CORGI_GPIO_KEY_INT, 1);
+       gpio_set_wake(CORGI_GPIO_WAKEUP, 1);
+       gpio_set_wake(CORGI_GPIO_AC_IN, 1);
+       gpio_set_wake(CORGI_GPIO_CHRG_FULL, 1);
+
+       if (!machine_is_corgi())
+               gpio_set_wake(CORGI_GPIO_MAIN_BAT_LOW, 1);
+
        pxa_set_ffuart_info(NULL);
        pxa_set_btuart_info(NULL);
        pxa_set_stuart_info(NULL);
@@ -679,7 +696,6 @@ static void __init corgi_init(void)
        corgi_init_spi();
 
        pxa_set_udc_info(&udc_info);
-       corgi_mci_platform_data.detect_delay = msecs_to_jiffies(250);
        pxa_set_mci_info(&corgi_mci_platform_data);
        pxa_set_ficp_info(&corgi_ficp_platform_data);
        pxa_set_i2c_info(NULL);
diff --git a/arch/arm/mach-pxa/corgi_lcd.c b/arch/arm/mach-pxa/corgi_lcd.c
deleted file mode 100644 (file)
index d9b9631..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * linux/arch/arm/mach-pxa/corgi_lcd.c
- *
- * Corgi/Spitz LCD Specific Code
- *
- * Copyright (C) 2005 Richard Purdie
- *
- * Connectivity:
- *   Corgi - LCD to ATI Imageon w100 (Wallaby)
- *   Spitz - LCD to PXA Framebuffer
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#include <linux/delay.h>
-#include <linux/kernel.h>
-#include <linux/platform_device.h>
-#include <linux/module.h>
-#include <linux/string.h>
-#include <mach/corgi.h>
-#include <mach/hardware.h>
-#include <mach/sharpsl.h>
-#include <mach/spitz.h>
-#include <asm/hardware/scoop.h>
-#include <asm/mach/sharpsl_param.h>
-#include "generic.h"
-
-/* Register Addresses */
-#define RESCTL_ADRS     0x00
-#define PHACTRL_ADRS    0x01
-#define DUTYCTRL_ADRS   0x02
-#define POWERREG0_ADRS  0x03
-#define POWERREG1_ADRS  0x04
-#define GPOR3_ADRS      0x05
-#define PICTRL_ADRS     0x06
-#define POLCTRL_ADRS    0x07
-
-/* Register Bit Definitions */
-#define RESCTL_QVGA     0x01
-#define RESCTL_VGA      0x00
-
-#define POWER1_VW_ON    0x01  /* VW Supply FET ON */
-#define POWER1_GVSS_ON  0x02  /* GVSS(-8V) Power Supply ON */
-#define POWER1_VDD_ON   0x04  /* VDD(8V),SVSS(-4V) Power Supply ON */
-
-#define POWER1_VW_OFF   0x00  /* VW Supply FET OFF */
-#define POWER1_GVSS_OFF 0x00  /* GVSS(-8V) Power Supply OFF */
-#define POWER1_VDD_OFF  0x00  /* VDD(8V),SVSS(-4V) Power Supply OFF */
-
-#define POWER0_COM_DCLK 0x01  /* COM Voltage DC Bias DAC Serial Data Clock */
-#define POWER0_COM_DOUT 0x02  /* COM Voltage DC Bias DAC Serial Data Out */
-#define POWER0_DAC_ON   0x04  /* DAC Power Supply ON */
-#define POWER0_COM_ON   0x08  /* COM Power Supply ON */
-#define POWER0_VCC5_ON  0x10  /* VCC5 Power Supply ON */
-
-#define POWER0_DAC_OFF  0x00  /* DAC Power Supply OFF */
-#define POWER0_COM_OFF  0x00  /* COM Power Supply OFF */
-#define POWER0_VCC5_OFF 0x00  /* VCC5 Power Supply OFF */
-
-#define PICTRL_INIT_STATE      0x01
-#define PICTRL_INIOFF          0x02
-#define PICTRL_POWER_DOWN      0x04
-#define PICTRL_COM_SIGNAL_OFF  0x08
-#define PICTRL_DAC_SIGNAL_OFF  0x10
-
-#define POLCTRL_SYNC_POL_FALL  0x01
-#define POLCTRL_EN_POL_FALL    0x02
-#define POLCTRL_DATA_POL_FALL  0x04
-#define POLCTRL_SYNC_ACT_H     0x08
-#define POLCTRL_EN_ACT_L       0x10
-
-#define POLCTRL_SYNC_POL_RISE  0x00
-#define POLCTRL_EN_POL_RISE    0x00
-#define POLCTRL_DATA_POL_RISE  0x00
-#define POLCTRL_SYNC_ACT_L     0x00
-#define POLCTRL_EN_ACT_H       0x00
-
-#define PHACTRL_PHASE_MANUAL   0x01
-#define DEFAULT_PHAD_QVGA     (9)
-#define DEFAULT_COMADJ        (125)
-
-/*
- * This is only a psuedo I2C interface. We can't use the standard kernel
- * routines as the interface is write only. We just assume the data is acked...
- */
-static void lcdtg_ssp_i2c_send(u8 data)
-{
-       corgi_ssp_lcdtg_send(POWERREG0_ADRS, data);
-       udelay(10);
-}
-
-static void lcdtg_i2c_send_bit(u8 data)
-{
-       lcdtg_ssp_i2c_send(data);
-       lcdtg_ssp_i2c_send(data | POWER0_COM_DCLK);
-       lcdtg_ssp_i2c_send(data);
-}
-
-static void lcdtg_i2c_send_start(u8 base)
-{
-       lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
-       lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
-       lcdtg_ssp_i2c_send(base);
-}
-
-static void lcdtg_i2c_send_stop(u8 base)
-{
-       lcdtg_ssp_i2c_send(base);
-       lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK);
-       lcdtg_ssp_i2c_send(base | POWER0_COM_DCLK | POWER0_COM_DOUT);
-}
-
-static void lcdtg_i2c_send_byte(u8 base, u8 data)
-{
-       int i;
-       for (i = 0; i < 8; i++) {
-               if (data & 0x80)
-                       lcdtg_i2c_send_bit(base | POWER0_COM_DOUT);
-               else
-                       lcdtg_i2c_send_bit(base);
-               data <<= 1;
-       }
-}
-
-static void lcdtg_i2c_wait_ack(u8 base)
-{
-       lcdtg_i2c_send_bit(base);
-}
-
-static void lcdtg_set_common_voltage(u8 base_data, u8 data)
-{
-       /* Set Common Voltage to M62332FP via I2C */
-       lcdtg_i2c_send_start(base_data);
-       lcdtg_i2c_send_byte(base_data, 0x9c);
-       lcdtg_i2c_wait_ack(base_data);
-       lcdtg_i2c_send_byte(base_data, 0x00);
-       lcdtg_i2c_wait_ack(base_data);
-       lcdtg_i2c_send_byte(base_data, data);
-       lcdtg_i2c_wait_ack(base_data);
-       lcdtg_i2c_send_stop(base_data);
-}
-
-/* Set Phase Adjust */
-static void lcdtg_set_phadadj(int mode)
-{
-       int adj;
-       switch(mode) {
-               case 480:
-               case 640:
-                       /* Setting for VGA */
-                       adj = sharpsl_param.phadadj;
-                       if (adj < 0) {
-                               adj = PHACTRL_PHASE_MANUAL;
-                       } else {
-                               adj = ((adj & 0x0f) << 1) | PHACTRL_PHASE_MANUAL;
-                       }
-                       break;
-               case 240:
-               case 320:
-               default:
-                       /* Setting for QVGA */
-                       adj = (DEFAULT_PHAD_QVGA << 1) | PHACTRL_PHASE_MANUAL;
-                       break;
-       }
-
-       corgi_ssp_lcdtg_send(PHACTRL_ADRS, adj);
-}
-
-static int lcd_inited;
-
-void corgi_lcdtg_hw_init(int mode)
-{
-       if (!lcd_inited) {
-               int comadj;
-
-               /* Initialize Internal Logic & Port */
-               corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_POWER_DOWN | PICTRL_INIOFF | PICTRL_INIT_STATE
-                               | PICTRL_COM_SIGNAL_OFF | PICTRL_DAC_SIGNAL_OFF);
-
-               corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_OFF
-                               | POWER0_COM_OFF | POWER0_VCC5_OFF);
-
-               corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
-
-               /* VDD(+8V), SVSS(-4V) ON */
-               corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
-               mdelay(3);
-
-               /* DAC ON */
-               corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
-                               | POWER0_COM_OFF | POWER0_VCC5_OFF);
-
-               /* INIB = H, INI = L  */
-               /* PICTL[0] = H , PICTL[1] = PICTL[2] = PICTL[4] = L */
-               corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE | PICTRL_COM_SIGNAL_OFF);
-
-               /* Set Common Voltage */
-               comadj = sharpsl_param.comadj;
-               if (comadj < 0)
-                       comadj = DEFAULT_COMADJ;
-               lcdtg_set_common_voltage((POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF), comadj);
-
-               /* VCC5 ON, DAC ON */
-               corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON |
-                               POWER0_COM_OFF | POWER0_VCC5_ON);
-
-               /* GVSS(-8V) ON, VDD ON */
-               corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
-               mdelay(2);
-
-               /* COM SIGNAL ON (PICTL[3] = L) */
-               corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIT_STATE);
-
-               /* COM ON, DAC ON, VCC5_ON */
-               corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_COM_DCLK | POWER0_COM_DOUT | POWER0_DAC_ON
-                               | POWER0_COM_ON | POWER0_VCC5_ON);
-
-               /* VW ON, GVSS ON, VDD ON */
-               corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_ON | POWER1_GVSS_ON | POWER1_VDD_ON);
-
-               /* Signals output enable */
-               corgi_ssp_lcdtg_send(PICTRL_ADRS, 0);
-
-               /* Set Phase Adjust */
-               lcdtg_set_phadadj(mode);
-
-               /* Initialize for Input Signals from ATI */
-               corgi_ssp_lcdtg_send(POLCTRL_ADRS, POLCTRL_SYNC_POL_RISE | POLCTRL_EN_POL_RISE
-                               | POLCTRL_DATA_POL_RISE | POLCTRL_SYNC_ACT_L | POLCTRL_EN_ACT_H);
-               udelay(1000);
-
-               lcd_inited=1;
-       } else {
-               lcdtg_set_phadadj(mode);
-       }
-
-       switch(mode) {
-               case 480:
-               case 640:
-                       /* Set Lcd Resolution (VGA) */
-                       corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_VGA);
-                       break;
-               case 240:
-               case 320:
-               default:
-                       /* Set Lcd Resolution (QVGA) */
-                       corgi_ssp_lcdtg_send(RESCTL_ADRS, RESCTL_QVGA);
-                       break;
-       }
-}
-
-void corgi_lcdtg_suspend(void)
-{
-       /* 60Hz x 2 frame = 16.7msec x 2 = 33.4 msec */
-       mdelay(34);
-
-       /* (1)VW OFF */
-       corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_ON | POWER1_VDD_ON);
-
-       /* (2)COM OFF */
-       corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_COM_SIGNAL_OFF);
-       corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON);
-
-       /* (3)Set Common Voltage Bias 0V */
-       lcdtg_set_common_voltage(POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_ON, 0);
-
-       /* (4)GVSS OFF */
-       corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_ON);
-
-       /* (5)VCC5 OFF */
-       corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_ON | POWER0_COM_OFF | POWER0_VCC5_OFF);
-
-       /* (6)Set PDWN, INIOFF, DACOFF */
-       corgi_ssp_lcdtg_send(PICTRL_ADRS, PICTRL_INIOFF | PICTRL_DAC_SIGNAL_OFF |
-                       PICTRL_POWER_DOWN | PICTRL_COM_SIGNAL_OFF);
-
-       /* (7)DAC OFF */
-       corgi_ssp_lcdtg_send(POWERREG0_ADRS, POWER0_DAC_OFF | POWER0_COM_OFF | POWER0_VCC5_OFF);
-
-       /* (8)VDD OFF */
-       corgi_ssp_lcdtg_send(POWERREG1_ADRS, POWER1_VW_OFF | POWER1_GVSS_OFF | POWER1_VDD_OFF);
-
-       lcd_inited = 0;
-}
-
index d4a0733..3f1dc74 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/delay.h>
+#include <linux/gpio.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/apm-emulation.h>
@@ -25,7 +26,8 @@
 #include <mach/sharpsl.h>
 #include <mach/corgi.h>
 #include <mach/pxa2xx-regs.h>
-#include <mach/pxa2xx-gpio.h>
+
+#include "generic.h"
 #include "sharpsl.h"
 
 #define SHARPSL_CHARGE_ON_VOLT         0x99  /* 2.9V */
 #define SHARPSL_FATAL_ACIN_VOLT        182   /* 3.45V */
 #define SHARPSL_FATAL_NOACIN_VOLT      170   /* 3.40V */
 
+static struct gpio charger_gpios[] = {
+       { CORGI_GPIO_ADC_TEMP_ON, GPIOF_OUT_INIT_LOW, "ADC Temp On" },
+       { CORGI_GPIO_CHRG_ON,     GPIOF_OUT_INIT_LOW, "Charger On" },
+       { CORGI_GPIO_CHRG_UKN,    GPIOF_OUT_INIT_LOW, "Charger Unknown" },
+       { CORGI_GPIO_KEY_INT,     GPIOF_IN, "Key Interrupt" },
+};
+
 static void corgi_charger_init(void)
 {
-       pxa_gpio_mode(CORGI_GPIO_ADC_TEMP_ON | GPIO_OUT);
-       pxa_gpio_mode(CORGI_GPIO_CHRG_ON | GPIO_OUT);
-       pxa_gpio_mode(CORGI_GPIO_CHRG_UKN | GPIO_OUT);
-       pxa_gpio_mode(CORGI_GPIO_KEY_INT | GPIO_IN);
+       gpio_request_array(ARRAY_AND_SIZE(charger_gpios));
 }
 
 static void corgi_measure_temp(int on)
 {
-       if (on)
-               GPSR(CORGI_GPIO_ADC_TEMP_ON) = GPIO_bit(CORGI_GPIO_ADC_TEMP_ON);
-       else
-               GPCR(CORGI_GPIO_ADC_TEMP_ON) = GPIO_bit(CORGI_GPIO_ADC_TEMP_ON);
+       gpio_set_value(CORGI_GPIO_ADC_TEMP_ON, on);
 }
 
 static void corgi_charge(int on)
 {
        if (on) {
                if (machine_is_corgi() && (sharpsl_pm.flags & SHARPSL_SUSPENDED)) {
-                       GPCR(CORGI_GPIO_CHRG_ON) = GPIO_bit(CORGI_GPIO_CHRG_ON);
-                       GPSR(CORGI_GPIO_CHRG_UKN) = GPIO_bit(CORGI_GPIO_CHRG_UKN);
+                       gpio_set_value(CORGI_GPIO_CHRG_ON, 0);
+                       gpio_set_value(CORGI_GPIO_CHRG_UKN, 1);
                } else {
-                       GPSR(CORGI_GPIO_CHRG_ON) = GPIO_bit(CORGI_GPIO_CHRG_ON);
-                       GPCR(CORGI_GPIO_CHRG_UKN) = GPIO_bit(CORGI_GPIO_CHRG_UKN);
+                       gpio_set_value(CORGI_GPIO_CHRG_ON, 1);
+                       gpio_set_value(CORGI_GPIO_CHRG_UKN, 0);
                }
        } else {
-               GPCR(CORGI_GPIO_CHRG_ON) = GPIO_bit(CORGI_GPIO_CHRG_ON);
-               GPCR(CORGI_GPIO_CHRG_UKN) = GPIO_bit(CORGI_GPIO_CHRG_UKN);
+               gpio_set_value(CORGI_GPIO_CHRG_ON, 0);
+               gpio_set_value(CORGI_GPIO_CHRG_UKN, 0);
        }
 }
 
 static void corgi_discharge(int on)
 {
-       if (on)
-               GPSR(CORGI_GPIO_DISCHARGE_ON) = GPIO_bit(CORGI_GPIO_DISCHARGE_ON);
-       else
-               GPCR(CORGI_GPIO_DISCHARGE_ON) = GPIO_bit(CORGI_GPIO_DISCHARGE_ON);
+       gpio_set_value(CORGI_GPIO_DISCHARGE_ON, on);
 }
 
 static void corgi_presuspend(void)
 {
-       int i;
-       unsigned long wakeup_mask;
-
-       /* charging , so CHARGE_ON bit is HIGH during OFF. */
-       if (READ_GPIO_BIT(CORGI_GPIO_CHRG_ON))
-               PGSR1 |= GPIO_bit(CORGI_GPIO_CHRG_ON);
-       else
-               PGSR1 &= ~GPIO_bit(CORGI_GPIO_CHRG_ON);
-
-       if (READ_GPIO_BIT(CORGI_GPIO_LED_ORANGE))
-               PGSR0 |= GPIO_bit(CORGI_GPIO_LED_ORANGE);
-       else
-               PGSR0 &= ~GPIO_bit(CORGI_GPIO_LED_ORANGE);
-
-       if (READ_GPIO_BIT(CORGI_GPIO_CHRG_UKN))
-               PGSR1 |= GPIO_bit(CORGI_GPIO_CHRG_UKN);
-       else
-               PGSR1 &= ~GPIO_bit(CORGI_GPIO_CHRG_UKN);
-
-       /* Resume on keyboard power key */
-       PGSR2 = (PGSR2 & ~CORGI_GPIO_ALL_STROBE_BIT) | CORGI_GPIO_STROBE_BIT(0);
-
-       wakeup_mask = GPIO_bit(CORGI_GPIO_KEY_INT) | GPIO_bit(CORGI_GPIO_WAKEUP) | GPIO_bit(CORGI_GPIO_AC_IN) | GPIO_bit(CORGI_GPIO_CHRG_FULL);
-
-       if (!machine_is_corgi())
-               wakeup_mask |= GPIO_bit(CORGI_GPIO_MAIN_BAT_LOW);
-
-       PWER = wakeup_mask | PWER_RTC;
-       PRER = wakeup_mask;
-       PFER = wakeup_mask;
-
-       for (i = 0; i <=15; i++) {
-               if (PRER & PFER & GPIO_bit(i)) {
-                       if (GPLR0 & GPIO_bit(i) )
-                               PRER &= ~GPIO_bit(i);
-                       else
-                               PFER &= ~GPIO_bit(i);
-               }
-       }
 }
 
 static void corgi_postsuspend(void)
diff --git a/arch/arm/mach-pxa/corgi_ssp.c b/arch/arm/mach-pxa/corgi_ssp.c
deleted file mode 100644 (file)
index 9347254..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- *  SSP control code for Sharp Corgi devices
- *
- *  Copyright (c) 2004-2005 Richard Purdie
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- */
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/delay.h>
-#include <linux/platform_device.h>
-#include <mach/hardware.h>
-#include <asm/mach-types.h>
-
-#include <mach/ssp.h>
-#include <mach/pxa2xx-gpio.h>
-#include <mach/regs-ssp.h>
-#include "sharpsl.h"
-
-static DEFINE_SPINLOCK(corgi_ssp_lock);
-static struct ssp_dev corgi_ssp_dev;
-static struct ssp_state corgi_ssp_state;
-static struct corgissp_machinfo *ssp_machinfo;
-
-/*
- * There are three devices connected to the SSP interface:
- *   1. A touchscreen controller (TI ADS7846 compatible)
- *   2. An LCD controller (with some Backlight functionality)
- *   3. A battery monitoring IC (Maxim MAX1111)
- *
- * Each device uses a different speed/mode of communication.
- *
- * The touchscreen is very sensitive and the most frequently used
- * so the port is left configured for this.
- *
- * Devices are selected using Chip Selects on GPIOs.
- */
-
-/*
- *  ADS7846 Routines
- */
-unsigned long corgi_ssp_ads7846_putget(ulong data)
-{
-       unsigned long flag;
-       u32 ret = 0;
-
-       spin_lock_irqsave(&corgi_ssp_lock, flag);
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
-
-       ssp_write_word(&corgi_ssp_dev,data);
-       ssp_read_word(&corgi_ssp_dev, &ret);
-
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
-       spin_unlock_irqrestore(&corgi_ssp_lock, flag);
-
-       return ret;
-}
-
-/*
- * NOTE: These functions should always be called in interrupt context
- * and use the _lock and _unlock functions. They are very time sensitive.
- */
-void corgi_ssp_ads7846_lock(void)
-{
-       spin_lock(&corgi_ssp_lock);
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               GPCR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
-}
-
-void corgi_ssp_ads7846_unlock(void)
-{
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846);
-       spin_unlock(&corgi_ssp_lock);
-}
-
-void corgi_ssp_ads7846_put(ulong data)
-{
-       ssp_write_word(&corgi_ssp_dev,data);
-}
-
-unsigned long corgi_ssp_ads7846_get(void)
-{
-       u32 ret = 0;
-       ssp_read_word(&corgi_ssp_dev, &ret);
-       return ret;
-}
-
-EXPORT_SYMBOL(corgi_ssp_ads7846_putget);
-EXPORT_SYMBOL(corgi_ssp_ads7846_lock);
-EXPORT_SYMBOL(corgi_ssp_ads7846_unlock);
-EXPORT_SYMBOL(corgi_ssp_ads7846_put);
-EXPORT_SYMBOL(corgi_ssp_ads7846_get);
-
-
-/*
- *  LCD/Backlight Routines
- */
-unsigned long corgi_ssp_dac_put(ulong data)
-{
-       unsigned long flag, sscr1 = SSCR1_SPH;
-       u32 tmp;
-
-       spin_lock_irqsave(&corgi_ssp_lock, flag);
-
-       if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi())
-               sscr1 = 0;
-
-       ssp_disable(&corgi_ssp_dev);
-       ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), sscr1, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_lcdcon));
-       ssp_enable(&corgi_ssp_dev);
-
-       if (ssp_machinfo->cs_lcdcon >= 0)
-               GPCR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
-       ssp_write_word(&corgi_ssp_dev,data);
-       /* Read null data back from device to prevent SSP overflow */
-       ssp_read_word(&corgi_ssp_dev, &tmp);
-       if (ssp_machinfo->cs_lcdcon >= 0)
-               GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);
-
-       ssp_disable(&corgi_ssp_dev);
-       ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
-       ssp_enable(&corgi_ssp_dev);
-
-       spin_unlock_irqrestore(&corgi_ssp_lock, flag);
-
-       return 0;
-}
-
-void corgi_ssp_lcdtg_send(u8 adrs, u8 data)
-{
-       corgi_ssp_dac_put(((adrs & 0x07) << 5) | (data & 0x1f));
-}
-
-void corgi_ssp_blduty_set(int duty)
-{
-       corgi_ssp_lcdtg_send(0x02,duty);
-}
-
-EXPORT_SYMBOL(corgi_ssp_lcdtg_send);
-EXPORT_SYMBOL(corgi_ssp_blduty_set);
-
-/*
- *  Max1111 Routines
- */
-int corgi_ssp_max1111_get(ulong data)
-{
-       unsigned long flag;
-       long voltage = 0, voltage1 = 0, voltage2 = 0;
-
-       spin_lock_irqsave(&corgi_ssp_lock, flag);
-       if (ssp_machinfo->cs_max1111 >= 0)
-               GPCR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
-       ssp_disable(&corgi_ssp_dev);
-       ssp_config(&corgi_ssp_dev, (SSCR0_Motorola | (SSCR0_DSS & 0x07 )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_max1111));
-       ssp_enable(&corgi_ssp_dev);
-
-       udelay(1);
-
-       /* TB1/RB1 */
-       ssp_write_word(&corgi_ssp_dev,data);
-       ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1); /* null read */
-
-       /* TB12/RB2 */
-       ssp_write_word(&corgi_ssp_dev,0);
-       ssp_read_word(&corgi_ssp_dev, (u32*)&voltage1);
-
-       /* TB13/RB3*/
-       ssp_write_word(&corgi_ssp_dev,0);
-       ssp_read_word(&corgi_ssp_dev, (u32*)&voltage2);
-
-       ssp_disable(&corgi_ssp_dev);
-       ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
-       ssp_enable(&corgi_ssp_dev);
-       if (ssp_machinfo->cs_max1111 >= 0)
-               GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111);
-       spin_unlock_irqrestore(&corgi_ssp_lock, flag);
-
-       if (voltage1 & 0xc0 || voltage2 & 0x3f)
-               voltage = -1;
-       else
-               voltage = ((voltage1 << 2) & 0xfc) | ((voltage2 >> 6) & 0x03);
-
-       return voltage;
-}
-
-EXPORT_SYMBOL(corgi_ssp_max1111_get);
-
-/*
- *  Support Routines
- */
-
-void __init corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo)
-{
-       ssp_machinfo = machinfo;
-}
-
-static int __devinit corgi_ssp_probe(struct platform_device *dev)
-{
-       int ret;
-
-       /* Chip Select - Disable All */
-       if (ssp_machinfo->cs_lcdcon >= 0)
-               pxa_gpio_mode(ssp_machinfo->cs_lcdcon  | GPIO_OUT | GPIO_DFLT_HIGH);
-       if (ssp_machinfo->cs_max1111 >= 0)
-               pxa_gpio_mode(ssp_machinfo->cs_max1111 | GPIO_OUT | GPIO_DFLT_HIGH);
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               pxa_gpio_mode(ssp_machinfo->cs_ads7846 | GPIO_OUT | GPIO_DFLT_HIGH);
-
-       ret = ssp_init(&corgi_ssp_dev, ssp_machinfo->port, 0);
-
-       if (ret)
-               printk(KERN_ERR "Unable to register SSP handler!\n");
-       else {
-               ssp_disable(&corgi_ssp_dev);
-               ssp_config(&corgi_ssp_dev, (SSCR0_National | (SSCR0_DSS & 0x0b )), 0, 0, SSCR0_SerClkDiv(ssp_machinfo->clk_ads7846));
-               ssp_enable(&corgi_ssp_dev);
-       }
-
-       return ret;
-}
-
-static int corgi_ssp_remove(struct platform_device *dev)
-{
-       ssp_exit(&corgi_ssp_dev);
-       return 0;
-}
-
-static int corgi_ssp_suspend(struct platform_device *dev, pm_message_t state)
-{
-       ssp_flush(&corgi_ssp_dev);
-       ssp_save_state(&corgi_ssp_dev,&corgi_ssp_state);
-
-       return 0;
-}
-
-static int corgi_ssp_resume(struct platform_device *dev)
-{
-       if (ssp_machinfo->cs_lcdcon >= 0)
-               GPSR(ssp_machinfo->cs_lcdcon) = GPIO_bit(ssp_machinfo->cs_lcdcon);  /* High - Disable LCD Control/Timing Gen */
-       if (ssp_machinfo->cs_max1111 >= 0)
-               GPSR(ssp_machinfo->cs_max1111) = GPIO_bit(ssp_machinfo->cs_max1111); /* High - Disable MAX1111*/
-       if (ssp_machinfo->cs_ads7846 >= 0)
-               GPSR(ssp_machinfo->cs_ads7846) = GPIO_bit(ssp_machinfo->cs_ads7846); /* High - Disable ADS7846*/
-       ssp_restore_state(&corgi_ssp_dev,&corgi_ssp_state);
-       ssp_enable(&corgi_ssp_dev);
-
-       return 0;
-}
-
-static struct platform_driver corgissp_driver = {
-       .probe          = corgi_ssp_probe,
-       .remove         = corgi_ssp_remove,
-       .suspend        = corgi_ssp_suspend,
-       .resume         = corgi_ssp_resume,
-       .driver         = {
-               .name   = "corgi-ssp",
-       },
-};
-
-int __init corgi_ssp_init(void)
-{
-       return platform_driver_register(&corgissp_driver);
-}
-
-arch_initcall(corgi_ssp_init);
index 88575b8..91fd4fe 100644 (file)
@@ -125,18 +125,9 @@ static unsigned long csb726_pin_config[] = {
        GPIO118_I2C_SDA,
 };
 
-static struct pxamci_platform_data csb726_mci_data;
-
-static int csb726_mci_init(struct device *dev,
-               irq_handler_t detect, void *data)
-{
-       csb726_mci_data.detect_delay = msecs_to_jiffies(500);
-       return 0;
-}
-
 static struct pxamci_platform_data csb726_mci = {
+       .detect_delay_ms        = 500,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
-       .init                   = csb726_mci_init,
        /* FIXME setpower */
        .gpio_card_detect       = CSB726_GPIO_MMC_DETECT,
        .gpio_card_ro           = CSB726_GPIO_MMC_RO,
index aab04f3..0517c17 100644 (file)
@@ -626,6 +626,7 @@ static int em_x270_mci_get_ro(struct device *dev)
 }
 
 static struct pxamci_platform_data em_x270_mci_platform_data = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_20_21|MMC_VDD_21_22|MMC_VDD_22_23|
                                  MMC_VDD_24_25|MMC_VDD_25_26|MMC_VDD_26_27|
                                  MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
@@ -643,7 +644,6 @@ static void __init em_x270_init_mmc(void)
        if (machine_is_em_x270())
                em_x270_mci_platform_data.get_ro = em_x270_mci_get_ro;
 
-       em_x270_mci_platform_data.detect_delay  = msecs_to_jiffies(250);
        pxa_set_mci_info(&em_x270_mci_platform_data);
 }
 #else
index 3126a35..baabb3c 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <mach/reset.h>
 #include <mach/gpio.h>
-#include <mach/pxa2xx-gpio.h>
 
 #include "generic.h"
 
@@ -128,33 +127,3 @@ void __init pxa_map_io(void)
        iotable_init(standard_io_desc, ARRAY_SIZE(standard_io_desc));
        get_clk_frequency_khz(1);
 }
-
-/*
- * Configure pins for GPIO or other functions
- */
-int pxa_gpio_mode(int gpio_mode)
-{
-       unsigned long flags;
-       int gpio = gpio_mode & GPIO_MD_MASK_NR;
-       int fn = (gpio_mode & GPIO_MD_MASK_FN) >> 8;
-       int gafr;
-
-       if (gpio > pxa_last_gpio)
-               return -EINVAL;
-
-       local_irq_save(flags);
-       if (gpio_mode & GPIO_DFLT_LOW)
-               GPCR(gpio) = GPIO_bit(gpio);
-       else if (gpio_mode & GPIO_DFLT_HIGH)
-               GPSR(gpio) = GPIO_bit(gpio);
-       if (gpio_mode & GPIO_MD_MASK_DIR)
-               GPDR(gpio) |= GPIO_bit(gpio);
-       else
-               GPDR(gpio) &= ~GPIO_bit(gpio);
-       gafr = GAFR(gpio) & ~(0x3 << (((gpio) & 0xf)*2));
-       GAFR(gpio) = gafr |  (fn  << (((gpio) & 0xf)*2));
-       local_irq_restore(flags);
-
-       return 0;
-}
-EXPORT_SYMBOL(pxa_gpio_mode);
index 7239281..585970e 100644 (file)
  * Shared data structures
  */
 extern struct platform_device corgiscoop_device;
-extern struct platform_device corgissp_device;
 
 #endif /* __ASM_ARCH_CORGI_H  */
 
index 658b28e..c54cef2 100644 (file)
@@ -25,6 +25,8 @@
 #define MFP_DIR(x)             (((x) >> 23) & 0x1)
 
 #define MFP_LPM_CAN_WAKEUP     (0x1 << 24)
+#define MFP_LPM_KEEP_OUTPUT    (0x1 << 25)
+
 #define WAKEUP_ON_EDGE_RISE    (MFP_LPM_CAN_WAKEUP | MFP_LPM_EDGE_RISE)
 #define WAKEUP_ON_EDGE_FALL    (MFP_LPM_CAN_WAKEUP | MFP_LPM_EDGE_FALL)
 #define WAKEUP_ON_EDGE_BOTH    (MFP_LPM_CAN_WAKEUP | MFP_LPM_EDGE_BOTH)
index 02a69dc..9eb515b 100644 (file)
@@ -9,7 +9,7 @@ struct mmc_host;
 
 struct pxamci_platform_data {
        unsigned int ocr_mask;                  /* available voltages */
-       unsigned long detect_delay;             /* delay in jiffies before detecting cards after interrupt */
+       unsigned long detect_delay_ms;          /* delay in millisecond before detecting cards after interrupt */
        int (*init)(struct device *, irq_handler_t , void *);
        int (*get_ro)(struct device *);
        void (*setpower)(struct device *, unsigned int);
diff --git a/arch/arm/mach-pxa/include/mach/pxa2xx-gpio.h b/arch/arm/mach-pxa/include/mach/pxa2xx-gpio.h
deleted file mode 100644 (file)
index 1209c44..0000000
+++ /dev/null
@@ -1,375 +0,0 @@
-#ifndef __ASM_ARCH_PXA2XX_GPIO_H
-#define __ASM_ARCH_PXA2XX_GPIO_H
-
-#warning Please use mfp-pxa2[57]x.h instead of pxa2xx-gpio.h
-
-#include <mach/gpio.h>
-
-/* GPIO alternate function assignments */
-
-#define GPIO1_RST              1       /* reset */
-#define GPIO6_MMCCLK           6       /* MMC Clock */
-#define GPIO7_48MHz            7       /* 48 MHz clock output */
-#define GPIO8_MMCCS0           8       /* MMC Chip Select 0 */
-#define GPIO9_MMCCS1           9       /* MMC Chip Select 1 */
-#define GPIO10_RTCCLK          10      /* real time clock (1 Hz) */
-#define GPIO11_3_6MHz          11      /* 3.6 MHz oscillator out */
-#define GPIO12_32KHz           12      /* 32 kHz out */
-#define GPIO12_CIF_DD_7                12      /* Camera data pin 7 */
-#define GPIO13_MBGNT           13      /* memory controller grant */
-#define GPIO14_MBREQ           14      /* alternate bus master request */
-#define GPIO15_nCS_1           15      /* chip select 1 */
-#define GPIO16_PWM0            16      /* PWM0 output */
-#define GPIO17_PWM1            17      /* PWM1 output */
-#define GPIO17_CIF_DD_6                17      /* Camera data pin 6 */
-#define GPIO18_RDY             18      /* Ext. Bus Ready */
-#define GPIO19_DREQ1           19      /* External DMA Request */
-#define GPIO20_DREQ0           20      /* External DMA Request */
-#define GPIO23_SCLK            23      /* SSP clock */
-#define GPIO23_CIF_MCLK                23      /* Camera Master Clock */
-#define GPIO24_SFRM            24      /* SSP Frame */
-#define GPIO24_CIF_FV          24      /* Camera frame start signal */
-#define GPIO25_STXD            25      /* SSP transmit */
-#define GPIO25_CIF_LV          25      /* Camera line start signal */
-#define GPIO26_SRXD            26      /* SSP receive */
-#define GPIO26_CIF_PCLK                26      /* Camera Pixel Clock */
-#define GPIO27_SEXTCLK         27      /* SSP ext_clk */
-#define GPIO27_CIF_DD_0                27      /* Camera data pin 0 */
-#define GPIO28_BITCLK          28      /* AC97/I2S bit_clk */
-#define GPIO29_SDATA_IN                29      /* AC97 Sdata_in0 / I2S Sdata_in */
-#define GPIO30_SDATA_OUT       30      /* AC97/I2S Sdata_out */
-#define GPIO31_SYNC            31      /* AC97/I2S sync */
-#define GPIO32_SDATA_IN1       32      /* AC97 Sdata_in1 */
-#define GPIO32_SYSCLK          32      /* I2S System Clock */
-#define GPIO32_MMCCLK          32      /* MMC Clock (PXA270) */
-#define GPIO33_nCS_5           33      /* chip select 5 */
-#define GPIO34_FFRXD           34      /* FFUART receive */
-#define GPIO34_MMCCS0          34      /* MMC Chip Select 0 */
-#define GPIO35_FFCTS           35      /* FFUART Clear to send */
-#define GPIO36_FFDCD           36      /* FFUART Data carrier detect */
-#define GPIO37_FFDSR           37      /* FFUART data set ready */
-#define GPIO38_FFRI            38      /* FFUART Ring Indicator */
-#define GPIO39_MMCCS1          39      /* MMC Chip Select 1 */
-#define GPIO39_FFTXD           39      /* FFUART transmit data */
-#define GPIO40_FFDTR           40      /* FFUART data terminal Ready */
-#define GPIO41_FFRTS           41      /* FFUART request to send */
-#define GPIO42_BTRXD           42      /* BTUART receive data */
-#define GPIO42_HWRXD           42      /* HWUART receive data */
-#define GPIO42_CIF_MCLK                42      /* Camera Master Clock */
-#define GPIO43_BTTXD           43      /* BTUART transmit data */
-#define GPIO43_HWTXD           43      /* HWUART transmit data */
-#define GPIO43_CIF_FV          43      /* Camera frame start signal */
-#define GPIO44_BTCTS           44      /* BTUART clear to send */
-#define GPIO44_HWCTS           44      /* HWUART clear to send */
-#define GPIO44_CIF_LV          44      /* Camera line start signal */
-#define GPIO45_BTRTS           45      /* BTUART request to send */
-#define GPIO45_HWRTS           45      /* HWUART request to send */
-#define GPIO45_AC97_SYSCLK     45      /* AC97 System Clock */
-#define GPIO45_CIF_PCLK                45      /* Camera Pixel Clock */
-#define GPIO46_ICPRXD          46      /* ICP receive data */
-#define GPIO46_STRXD           46      /* STD_UART receive data */
-#define GPIO47_ICPTXD          47      /* ICP transmit data */
-#define GPIO47_STTXD           47      /* STD_UART transmit data */
-#define GPIO47_CIF_DD_0                47      /* Camera data pin 0 */
-#define GPIO48_nPOE            48      /* Output Enable for Card Space */
-#define GPIO48_CIF_DD_5                48      /* Camera data pin 5 */
-#define GPIO49_nPWE            49      /* Write Enable for Card Space */
-#define GPIO50_nPIOR           50      /* I/O Read for Card Space */
-#define GPIO50_CIF_DD_3                50      /* Camera data pin 3 */
-#define GPIO51_nPIOW           51      /* I/O Write for Card Space */
-#define GPIO51_CIF_DD_2                51      /* Camera data pin 2 */
-#define GPIO52_nPCE_1          52      /* Card Enable for Card Space */
-#define GPIO52_CIF_DD_4                52      /* Camera data pin 4 */
-#define GPIO53_nPCE_2          53      /* Card Enable for Card Space */
-#define GPIO53_MMCCLK          53      /* MMC Clock */
-#define GPIO53_CIF_MCLK                53      /* Camera Master Clock */
-#define GPIO54_MMCCLK          54      /* MMC Clock */
-#define GPIO54_pSKTSEL         54      /* Socket Select for Card Space */
-#define GPIO54_nPCE_2          54      /* Card Enable for Card Space (PXA27x) */
-#define GPIO54_CIF_PCLK                54      /* Camera Pixel Clock */
-#define GPIO55_nPREG           55      /* Card Address bit 26 */
-#define GPIO55_CIF_DD_1                55      /* Camera data pin 1 */
-#define GPIO56_nPWAIT          56      /* Wait signal for Card Space */
-#define GPIO57_nIOIS16         57      /* Bus Width select for I/O Card Space */
-#define GPIO58_LDD_0           58      /* LCD data pin 0 */
-#define GPIO59_LDD_1           59      /* LCD data pin 1 */
-#define GPIO60_LDD_2           60      /* LCD data pin 2 */
-#define GPIO61_LDD_3           61      /* LCD data pin 3 */
-#define GPIO62_LDD_4           62      /* LCD data pin 4 */
-#define GPIO63_LDD_5           63      /* LCD data pin 5 */
-#define GPIO64_LDD_6           64      /* LCD data pin 6 */
-#define GPIO65_LDD_7           65      /* LCD data pin 7 */
-#define GPIO66_LDD_8           66      /* LCD data pin 8 */
-#define GPIO66_MBREQ           66      /* alternate bus master req */
-#define GPIO67_LDD_9           67      /* LCD data pin 9 */
-#define GPIO67_MMCCS0          67      /* MMC Chip Select 0 */
-#define GPIO68_LDD_10          68      /* LCD data pin 10 */
-#define GPIO68_MMCCS1          68      /* MMC Chip Select 1 */
-#define GPIO69_LDD_11          69      /* LCD data pin 11 */
-#define GPIO69_MMCCLK          69      /* MMC_CLK */
-#define GPIO70_LDD_12          70      /* LCD data pin 12 */
-#define GPIO70_RTCCLK          70      /* Real Time clock (1 Hz) */
-#define GPIO71_LDD_13          71      /* LCD data pin 13 */
-#define GPIO71_3_6MHz          71      /* 3.6 MHz Oscillator clock */
-#define GPIO72_LDD_14          72      /* LCD data pin 14 */
-#define GPIO72_32kHz           72      /* 32 kHz clock */
-#define GPIO73_LDD_15          73      /* LCD data pin 15 */
-#define GPIO73_MBGNT           73      /* Memory controller grant */
-#define GPIO74_LCD_FCLK                74      /* LCD Frame clock */
-#define GPIO75_LCD_LCLK                75      /* LCD line clock */
-#define GPIO76_LCD_PCLK                76      /* LCD Pixel clock */
-#define GPIO77_LCD_ACBIAS      77      /* LCD AC Bias */
-#define GPIO78_nCS_2           78      /* chip select 2 */
-#define GPIO79_nCS_3           79      /* chip select 3 */
-#define GPIO80_nCS_4           80      /* chip select 4 */
-#define GPIO81_NSCLK           81      /* NSSP clock */
-#define GPIO81_CIF_DD_0                81      /* Camera data pin 0 */
-#define GPIO82_NSFRM           82      /* NSSP Frame */
-#define GPIO82_CIF_DD_5                82      /* Camera data pin 5 */
-#define GPIO83_NSTXD           83      /* NSSP transmit */
-#define GPIO83_CIF_DD_4                83      /* Camera data pin 4 */
-#define GPIO84_NSRXD           84      /* NSSP receive */
-#define GPIO84_CIF_FV          84      /* Camera frame start signal */
-#define GPIO85_nPCE_1          85      /* Card Enable for Card Space (PXA27x) */
-#define GPIO85_CIF_LV          85      /* Camera line start signal */
-#define GPIO90_CIF_DD_4                90      /* Camera data pin 4 */
-#define GPIO91_CIF_DD_5                91      /* Camera data pin 5 */
-#define GPIO92_MMCDAT0         92      /* MMC DAT0 (PXA27x) */
-#define GPIO93_CIF_DD_6                93      /* Camera data pin 6 */
-#define GPIO94_CIF_DD_5                94      /* Camera data pin 5 */
-#define GPIO95_CIF_DD_4                95      /* Camera data pin 4 */
-#define GPIO96_FFRXD           96      /* FFUART recieve */
-#define GPIO98_FFRTS           98      /* FFUART request to send */
-#define GPIO98_CIF_DD_0                98      /* Camera data pin 0 */
-#define GPIO99_FFTXD           99      /* FFUART transmit data */
-#define GPIO100_FFCTS          100     /* FFUART Clear to send */
-#define GPIO102_nPCE_1         102     /* PCMCIA (PXA27x) */
-#define GPIO103_CIF_DD_3       103     /* Camera data pin 3 */
-#define GPIO104_CIF_DD_2       104     /* Camera data pin 2 */
-#define GPIO105_CIF_DD_1       105     /* Camera data pin 1 */
-#define GPIO106_CIF_DD_9       106     /* Camera data pin 9 */
-#define GPIO107_CIF_DD_8       107     /* Camera data pin 8 */
-#define GPIO108_CIF_DD_7       108     /* Camera data pin 7 */
-#define GPIO109_MMCDAT1                109     /* MMC DAT1 (PXA27x) */
-#define GPIO110_MMCDAT2                110     /* MMC DAT2 (PXA27x) */
-#define GPIO110_MMCCS0         110     /* MMC Chip Select 0 (PXA27x) */
-#define GPIO111_MMCDAT3                111     /* MMC DAT3 (PXA27x) */
-#define GPIO111_MMCCS1         111     /* MMC Chip Select 1 (PXA27x) */
-#define GPIO112_MMCCMD         112     /* MMC CMD (PXA27x) */
-#define GPIO113_I2S_SYSCLK     113     /* I2S System Clock (PXA27x) */
-#define GPIO113_AC97_RESET_N   113     /* AC97 NRESET on (PXA27x) */
-#define GPIO114_CIF_DD_1       114     /* Camera data pin 1 */
-#define GPIO115_CIF_DD_3       115     /* Camera data pin 3 */
-#define GPIO116_CIF_DD_2       116     /* Camera data pin 2 */
-
-/* GPIO alternate function mode & direction */
-
-#define GPIO_IN                        0x000
-#define GPIO_OUT               0x080
-#define GPIO_ALT_FN_1_IN       0x100
-#define GPIO_ALT_FN_1_OUT      0x180
-#define GPIO_ALT_FN_2_IN       0x200
-#define GPIO_ALT_FN_2_OUT      0x280
-#define GPIO_ALT_FN_3_IN       0x300
-#define GPIO_ALT_FN_3_OUT      0x380
-#define GPIO_MD_MASK_NR                0x07f
-#define GPIO_MD_MASK_DIR       0x080
-#define GPIO_MD_MASK_FN                0x300
-#define GPIO_DFLT_LOW          0x400
-#define GPIO_DFLT_HIGH         0x800
-
-#define GPIO1_RTS_MD           ( 1 | GPIO_ALT_FN_1_IN)
-#define GPIO6_MMCCLK_MD                ( 6 | GPIO_ALT_FN_1_OUT)
-#define GPIO7_48MHz_MD         ( 7 | GPIO_ALT_FN_1_OUT)
-#define GPIO8_MMCCS0_MD                ( 8 | GPIO_ALT_FN_1_OUT)
-#define GPIO9_MMCCS1_MD                ( 9 | GPIO_ALT_FN_1_OUT)
-#define GPIO10_RTCCLK_MD       (10 | GPIO_ALT_FN_1_OUT)
-#define GPIO11_3_6MHz_MD       (11 | GPIO_ALT_FN_1_OUT)
-#define GPIO12_32KHz_MD                (12 | GPIO_ALT_FN_1_OUT)
-#define GPIO12_CIF_DD_7_MD     (12 | GPIO_ALT_FN_2_IN)
-#define GPIO13_MBGNT_MD                (13 | GPIO_ALT_FN_2_OUT)
-#define GPIO14_MBREQ_MD                (14 | GPIO_ALT_FN_1_IN)
-#define GPIO15_nCS_1_MD                (15 | GPIO_ALT_FN_2_OUT)
-#define GPIO16_PWM0_MD         (16 | GPIO_ALT_FN_2_OUT)
-#define GPIO17_PWM1_MD         (17 | GPIO_ALT_FN_2_OUT)
-#define GPIO17_CIF_DD_6_MD     (17 | GPIO_ALT_FN_2_IN)
-#define GPIO18_RDY_MD          (18 | GPIO_ALT_FN_1_IN)
-#define GPIO19_DREQ1_MD                (19 | GPIO_ALT_FN_1_IN)
-#define GPIO20_DREQ0_MD                (20 | GPIO_ALT_FN_1_IN)
-#define GPIO23_CIF_MCLK_MD     (23 | GPIO_ALT_FN_1_OUT)
-#define GPIO23_SCLK_MD         (23 | GPIO_ALT_FN_2_OUT)
-#define GPIO24_CIF_FV_MD       (24 | GPIO_ALT_FN_1_OUT)
-#define GPIO24_SFRM_MD         (24 | GPIO_ALT_FN_2_OUT)
-#define GPIO25_CIF_LV_MD       (25 | GPIO_ALT_FN_1_OUT)
-#define GPIO25_STXD_MD         (25 | GPIO_ALT_FN_2_OUT)
-#define GPIO26_SRXD_MD         (26 | GPIO_ALT_FN_1_IN)
-#define GPIO26_CIF_PCLK_MD     (26 | GPIO_ALT_FN_2_IN)
-#define GPIO27_SEXTCLK_MD      (27 | GPIO_ALT_FN_1_IN)
-#define GPIO27_CIF_DD_0_MD     (27 | GPIO_ALT_FN_3_IN)
-#define GPIO28_BITCLK_AC97_MD  (28 | GPIO_ALT_FN_1_IN)
-#define GPIO28_BITCLK_IN_I2S_MD        (28 | GPIO_ALT_FN_2_IN)
-#define GPIO28_BITCLK_OUT_I2S_MD       (28 | GPIO_ALT_FN_1_OUT)
-#define GPIO29_SDATA_IN_AC97_MD        (29 | GPIO_ALT_FN_1_IN)
-#define GPIO29_SDATA_IN_I2S_MD (29 | GPIO_ALT_FN_2_IN)
-#define GPIO30_SDATA_OUT_AC97_MD       (30 | GPIO_ALT_FN_2_OUT)
-#define GPIO30_SDATA_OUT_I2S_MD        (30 | GPIO_ALT_FN_1_OUT)
-#define GPIO31_SYNC_I2S_MD     (31 | GPIO_ALT_FN_1_OUT)
-#define GPIO31_SYNC_AC97_MD    (31 | GPIO_ALT_FN_2_OUT)
-#define GPIO32_SDATA_IN1_AC97_MD       (32 | GPIO_ALT_FN_1_IN)
-#define GPIO32_SYSCLK_I2S_MD   (32 | GPIO_ALT_FN_1_OUT)
-#define GPIO32_MMCCLK_MD       (32 | GPIO_ALT_FN_2_OUT)
-#define GPIO33_nCS_5_MD                (33 | GPIO_ALT_FN_2_OUT)
-#define GPIO34_FFRXD_MD                (34 | GPIO_ALT_FN_1_IN)
-#define GPIO34_MMCCS0_MD       (34 | GPIO_ALT_FN_2_OUT)
-#define GPIO35_FFCTS_MD                (35 | GPIO_ALT_FN_1_IN)
-#define GPIO35_KP_MKOUT6_MD    (35 | GPIO_ALT_FN_2_OUT)
-#define GPIO36_FFDCD_MD                (36 | GPIO_ALT_FN_1_IN)
-#define GPIO37_FFDSR_MD                (37 | GPIO_ALT_FN_1_IN)
-#define GPIO38_FFRI_MD         (38 | GPIO_ALT_FN_1_IN)
-#define GPIO39_MMCCS1_MD       (39 | GPIO_ALT_FN_1_OUT)
-#define GPIO39_FFTXD_MD                (39 | GPIO_ALT_FN_2_OUT)
-#define GPIO40_FFDTR_MD                (40 | GPIO_ALT_FN_2_OUT)
-#define GPIO41_FFRTS_MD                (41 | GPIO_ALT_FN_2_OUT)
-#define GPIO41_KP_MKOUT7_MD    (41 | GPIO_ALT_FN_1_OUT)
-#define GPIO42_BTRXD_MD                (42 | GPIO_ALT_FN_1_IN)
-#define GPIO42_HWRXD_MD                (42 | GPIO_ALT_FN_3_IN)
-#define GPIO42_CIF_MCLK_MD     (42 | GPIO_ALT_FN_3_OUT)
-#define GPIO43_BTTXD_MD                (43 | GPIO_ALT_FN_2_OUT)
-#define GPIO43_HWTXD_MD                (43 | GPIO_ALT_FN_3_OUT)
-#define GPIO43_CIF_FV_MD       (43 | GPIO_ALT_FN_3_OUT)
-#define GPIO44_BTCTS_MD                (44 | GPIO_ALT_FN_1_IN)
-#define GPIO44_HWCTS_MD                (44 | GPIO_ALT_FN_3_IN)
-#define GPIO44_CIF_LV_MD       (44 | GPIO_ALT_FN_3_OUT)
-#define GPIO45_CIF_PCLK_MD     (45 | GPIO_ALT_FN_3_IN)
-#define GPIO45_BTRTS_MD                (45 | GPIO_ALT_FN_2_OUT)
-#define GPIO45_HWRTS_MD                (45 | GPIO_ALT_FN_3_OUT)
-#define GPIO45_SYSCLK_AC97_MD  (45 | GPIO_ALT_FN_1_OUT)
-#define GPIO46_ICPRXD_MD       (46 | GPIO_ALT_FN_1_IN)
-#define GPIO46_STRXD_MD                (46 | GPIO_ALT_FN_2_IN)
-#define GPIO47_CIF_DD_0_MD     (47 | GPIO_ALT_FN_1_IN)
-#define GPIO47_ICPTXD_MD       (47 | GPIO_ALT_FN_2_OUT)
-#define GPIO47_STTXD_MD                (47 | GPIO_ALT_FN_1_OUT)
-#define GPIO48_CIF_DD_5_MD     (48 | GPIO_ALT_FN_1_IN)
-#define GPIO48_nPOE_MD         (48 | GPIO_ALT_FN_2_OUT)
-#define GPIO48_HWTXD_MD                (48 | GPIO_ALT_FN_1_OUT)
-#define GPIO48_nPOE_MD         (48 | GPIO_ALT_FN_2_OUT)
-#define GPIO49_HWRXD_MD                (49 | GPIO_ALT_FN_1_IN)
-#define GPIO49_nPWE_MD         (49 | GPIO_ALT_FN_2_OUT)
-#define GPIO50_CIF_DD_3_MD     (50 | GPIO_ALT_FN_1_IN)
-#define GPIO50_nPIOR_MD                (50 | GPIO_ALT_FN_2_OUT)
-#define GPIO50_HWCTS_MD                (50 | GPIO_ALT_FN_1_IN)
-#define GPIO50_CIF_DD_3_MD     (50 | GPIO_ALT_FN_1_IN)
-#define GPIO51_CIF_DD_2_MD     (51 | GPIO_ALT_FN_1_IN)
-#define GPIO51_nPIOW_MD                (51 | GPIO_ALT_FN_2_OUT)
-#define GPIO51_HWRTS_MD                (51 | GPIO_ALT_FN_1_OUT)
-#define GPIO51_CIF_DD_2_MD     (51 | GPIO_ALT_FN_1_IN)
-#define GPIO52_nPCE_1_MD       (52 | GPIO_ALT_FN_2_OUT)
-#define GPIO52_CIF_DD_4_MD     (52 | GPIO_ALT_FN_1_IN)
-#define GPIO53_nPCE_2_MD       (53 | GPIO_ALT_FN_2_OUT)
-#define GPIO53_MMCCLK_MD       (53 | GPIO_ALT_FN_1_OUT)
-#define GPIO53_CIF_MCLK_MD     (53 | GPIO_ALT_FN_2_OUT)
-#define GPIO54_MMCCLK_MD       (54 | GPIO_ALT_FN_1_OUT)
-#define GPIO54_nPCE_2_MD       (54 | GPIO_ALT_FN_2_OUT)
-#define GPIO54_pSKTSEL_MD      (54 | GPIO_ALT_FN_2_OUT)
-#define GPIO54_CIF_PCLK_MD     (54 | GPIO_ALT_FN_3_IN)
-#define GPIO55_nPREG_MD                (55 | GPIO_ALT_FN_2_OUT)
-#define GPIO55_CIF_DD_1_MD     (55 | GPIO_ALT_FN_1_IN)
-#define GPIO56_nPWAIT_MD       (56 | GPIO_ALT_FN_1_IN)
-#define GPIO57_nIOIS16_MD      (57 | GPIO_ALT_FN_1_IN)
-#define GPIO58_LDD_0_MD                (58 | GPIO_ALT_FN_2_OUT)
-#define GPIO59_LDD_1_MD                (59 | GPIO_ALT_FN_2_OUT)
-#define GPIO60_LDD_2_MD                (60 | GPIO_ALT_FN_2_OUT)
-#define GPIO61_LDD_3_MD                (61 | GPIO_ALT_FN_2_OUT)
-#define GPIO62_LDD_4_MD                (62 | GPIO_ALT_FN_2_OUT)
-#define GPIO63_LDD_5_MD                (63 | GPIO_ALT_FN_2_OUT)
-#define GPIO64_LDD_6_MD                (64 | GPIO_ALT_FN_2_OUT)
-#define GPIO65_LDD_7_MD                (65 | GPIO_ALT_FN_2_OUT)
-#define GPIO66_LDD_8_MD                (66 | GPIO_ALT_FN_2_OUT)
-#define GPIO66_MBREQ_MD                (66 | GPIO_ALT_FN_1_IN)
-#define GPIO67_LDD_9_MD                (67 | GPIO_ALT_FN_2_OUT)
-#define GPIO67_MMCCS0_MD       (67 | GPIO_ALT_FN_1_OUT)
-#define GPIO68_LDD_10_MD       (68 | GPIO_ALT_FN_2_OUT)
-#define GPIO68_MMCCS1_MD       (68 | GPIO_ALT_FN_1_OUT)
-#define GPIO69_LDD_11_MD       (69 | GPIO_ALT_FN_2_OUT)
-#define GPIO69_MMCCLK_MD       (69 | GPIO_ALT_FN_1_OUT)
-#define GPIO70_LDD_12_MD       (70 | GPIO_ALT_FN_2_OUT)
-#define GPIO70_RTCCLK_MD       (70 | GPIO_ALT_FN_1_OUT)
-#define GPIO71_LDD_13_MD       (71 | GPIO_ALT_FN_2_OUT)
-#define GPIO71_3_6MHz_MD       (71 | GPIO_ALT_FN_1_OUT)
-#define GPIO72_LDD_14_MD       (72 | GPIO_ALT_FN_2_OUT)
-#define GPIO72_32kHz_MD                (72 | GPIO_ALT_FN_1_OUT)
-#define GPIO73_LDD_15_MD       (73 | GPIO_ALT_FN_2_OUT)
-#define GPIO73_MBGNT_MD                (73 | GPIO_ALT_FN_1_OUT)
-#define GPIO74_LCD_FCLK_MD     (74 | GPIO_ALT_FN_2_OUT)
-#define GPIO75_LCD_LCLK_MD     (75 | GPIO_ALT_FN_2_OUT)
-#define GPIO76_LCD_PCLK_MD     (76 | GPIO_ALT_FN_2_OUT)
-#define GPIO77_LCD_ACBIAS_MD   (77 | GPIO_ALT_FN_2_OUT)
-#define GPIO78_nCS_2_MD                (78 | GPIO_ALT_FN_2_OUT)
-#define GPIO78_nPCE_2_MD       (78 | GPIO_ALT_FN_1_OUT)
-#define GPIO79_nCS_3_MD                (79 | GPIO_ALT_FN_2_OUT)
-#define GPIO79_pSKTSEL_MD      (79 | GPIO_ALT_FN_1_OUT)
-#define GPIO80_nCS_4_MD                (80 | GPIO_ALT_FN_2_OUT)
-#define GPIO81_NSSP_CLK_OUT    (81 | GPIO_ALT_FN_1_OUT)
-#define GPIO81_NSSP_CLK_IN     (81 | GPIO_ALT_FN_1_IN)
-#define GPIO81_CIF_DD_0_MD     (81 | GPIO_ALT_FN_2_IN)
-#define GPIO82_NSSP_FRM_OUT    (82 | GPIO_ALT_FN_1_OUT)
-#define GPIO82_NSSP_FRM_IN     (82 | GPIO_ALT_FN_1_IN)
-#define GPIO82_CIF_DD_5_MD     (82 | GPIO_ALT_FN_3_IN)
-#define GPIO83_NSSP_TX         (83 | GPIO_ALT_FN_1_OUT)
-#define GPIO83_NSSP_RX         (83 | GPIO_ALT_FN_2_IN)
-#define GPIO83_CIF_DD_4_MD     (83 | GPIO_ALT_FN_3_IN)
-#define GPIO84_NSSP_TX         (84 | GPIO_ALT_FN_1_OUT)
-#define GPIO84_NSSP_RX         (84 | GPIO_ALT_FN_2_IN)
-#define GPIO84_CIF_FV_MD       (84 | GPIO_ALT_FN_3_IN)
-#define GPIO85_nPCE_1_MD       (85 | GPIO_ALT_FN_1_OUT)
-#define GPIO85_CIF_LV_MD       (85 | GPIO_ALT_FN_3_IN)
-#define GPIO86_nPCE_1_MD       (86 | GPIO_ALT_FN_1_OUT)
-#define GPIO88_USBH1_PWR_MD    (88 | GPIO_ALT_FN_1_IN)
-#define GPIO89_USBH1_PEN_MD    (89 | GPIO_ALT_FN_2_OUT)
-#define GPIO90_CIF_DD_4_MD     (90 | GPIO_ALT_FN_3_IN)
-#define GPIO91_CIF_DD_5_MD     (91 | GPIO_ALT_FN_3_IN)
-#define GPIO92_MMCDAT0_MD      (92 | GPIO_ALT_FN_1_OUT)
-#define GPIO93_CIF_DD_6_MD     (93 | GPIO_ALT_FN_2_IN)
-#define GPIO94_CIF_DD_5_MD     (94 | GPIO_ALT_FN_2_IN)
-#define GPIO95_CIF_DD_4_MD     (95 | GPIO_ALT_FN_2_IN)
-#define GPIO95_KP_MKIN6_MD     (95 | GPIO_ALT_FN_3_IN)
-#define GPIO96_KP_DKIN3_MD     (96 | GPIO_ALT_FN_1_IN)
-#define GPIO96_FFRXD_MD                (96 | GPIO_ALT_FN_3_IN)
-#define GPIO97_KP_MKIN3_MD     (97 | GPIO_ALT_FN_3_IN)
-#define GPIO98_CIF_DD_0_MD     (98 | GPIO_ALT_FN_2_IN)
-#define GPIO98_FFRTS_MD                (98 | GPIO_ALT_FN_3_OUT)
-#define GPIO99_FFTXD_MD                (99 | GPIO_ALT_FN_3_OUT)
-#define GPIO100_KP_MKIN0_MD    (100 | GPIO_ALT_FN_1_IN)
-#define GPIO101_KP_MKIN1_MD    (101 | GPIO_ALT_FN_1_IN)
-#define GPIO102_nPCE_1_MD      (102 | GPIO_ALT_FN_1_OUT)
-#define GPIO102_KP_MKIN2_MD    (102 | GPIO_ALT_FN_1_IN)
-#define GPIO103_CIF_DD_3_MD    (103 | GPIO_ALT_FN_1_IN)
-#define GPIO103_KP_MKOUT0_MD   (103 | GPIO_ALT_FN_2_OUT)
-#define GPIO104_CIF_DD_2_MD    (104 | GPIO_ALT_FN_1_IN)
-#define GPIO104_pSKTSEL_MD     (104 | GPIO_ALT_FN_1_OUT)
-#define GPIO104_KP_MKOUT1_MD   (104 | GPIO_ALT_FN_2_OUT)
-#define GPIO105_CIF_DD_1_MD    (105 | GPIO_ALT_FN_1_IN)
-#define GPIO105_KP_MKOUT2_MD   (105 | GPIO_ALT_FN_2_OUT)
-#define GPIO106_CIF_DD_9_MD    (106 | GPIO_ALT_FN_1_IN)
-#define GPIO106_KP_MKOUT3_MD   (106 | GPIO_ALT_FN_2_OUT)
-#define GPIO107_CIF_DD_8_MD    (107 | GPIO_ALT_FN_1_IN)
-#define GPIO107_KP_MKOUT4_MD   (107 | GPIO_ALT_FN_2_OUT)
-#define GPIO108_CIF_DD_7_MD    (108 | GPIO_ALT_FN_1_IN)
-#define GPIO108_KP_MKOUT5_MD   (108 | GPIO_ALT_FN_2_OUT)
-#define GPIO109_MMCDAT1_MD     (109 | GPIO_ALT_FN_1_OUT)
-#define GPIO110_MMCDAT2_MD     (110 | GPIO_ALT_FN_1_OUT)
-#define GPIO110_MMCCS0_MD      (110 | GPIO_ALT_FN_1_OUT)
-#define GPIO111_MMCDAT3_MD     (111 | GPIO_ALT_FN_1_OUT)
-#define GPIO110_MMCCS1_MD      (111 | GPIO_ALT_FN_1_OUT)
-#define GPIO112_MMCCMD_MD      (112 | GPIO_ALT_FN_1_OUT)
-#define GPIO113_I2S_SYSCLK_MD  (113 | GPIO_ALT_FN_1_OUT)
-#define GPIO113_AC97_RESET_N_MD        (113 | GPIO_ALT_FN_2_OUT)
-#define GPIO117_I2CSCL_MD      (117 | GPIO_ALT_FN_1_IN)
-#define GPIO118_I2CSDA_MD      (118 | GPIO_ALT_FN_1_IN)
-
-/*
- * Handy routine to set GPIO alternate functions
- */
-extern int pxa_gpio_mode( int gpio_mode );
-
-#endif /* __ASM_ARCH_PXA2XX_GPIO_H */
diff --git a/arch/arm/mach-pxa/include/mach/ssp.h b/arch/arm/mach-pxa/include/mach/ssp.h
deleted file mode 100644 (file)
index be1be5b..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *  ssp.h
- *
- *  Copyright (C) 2003 Russell King, 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 version 2 as
- * published by the Free Software Foundation.
- *
- * This driver supports the following PXA CPU/SSP ports:-
- *
- *       PXA250     SSP
- *       PXA255     SSP, NSSP
- *       PXA26x     SSP, NSSP, ASSP
- *       PXA27x     SSP1, SSP2, SSP3
- *       PXA3xx     SSP1, SSP2, SSP3, SSP4
- */
-
-#ifndef __ASM_ARCH_SSP_H
-#define __ASM_ARCH_SSP_H
-
-#include <linux/list.h>
-#include <linux/io.h>
-
-enum pxa_ssp_type {
-       SSP_UNDEFINED = 0,
-       PXA25x_SSP,  /* pxa 210, 250, 255, 26x */
-       PXA25x_NSSP, /* pxa 255, 26x (including ASSP) */
-       PXA27x_SSP,
-};
-
-struct ssp_device {
-       struct platform_device *pdev;
-       struct list_head        node;
-
-       struct clk      *clk;
-       void __iomem    *mmio_base;
-       unsigned long   phys_base;
-
-       const char      *label;
-       int             port_id;
-       int             type;
-       int             use_count;
-       int             irq;
-       int             drcmr_rx;
-       int             drcmr_tx;
-};
-
-#ifdef CONFIG_PXA_SSP_LEGACY
-/*
- * SSP initialisation flags
- */
-#define SSP_NO_IRQ     0x1             /* don't register an irq handler in SSP driver */
-
-struct ssp_state {
-       u32     cr0;
-       u32 cr1;
-       u32 to;
-       u32 psp;
-};
-
-struct ssp_dev {
-       struct ssp_device *ssp;
-       u32 port;
-       u32 mode;
-       u32 flags;
-       u32 psp_flags;
-       u32 speed;
-       int irq;
-};
-
-int ssp_write_word(struct ssp_dev *dev, u32 data);
-int ssp_read_word(struct ssp_dev *dev, u32 *data);
-int ssp_flush(struct ssp_dev *dev);
-void ssp_enable(struct ssp_dev *dev);
-void ssp_disable(struct ssp_dev *dev);
-void ssp_save_state(struct ssp_dev *dev, struct ssp_state *ssp);
-void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *ssp);
-int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags);
-int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed);
-void ssp_exit(struct ssp_dev *dev);
-#endif /* CONFIG_PXA_SSP_LEGACY */
-
-/**
- * ssp_write_reg - Write to a SSP register
- *
- * @dev: SSP device to access
- * @reg: Register to write to
- * @val: Value to be written.
- */
-static inline void ssp_write_reg(struct ssp_device *dev, u32 reg, u32 val)
-{
-       __raw_writel(val, dev->mmio_base + reg);
-}
-
-/**
- * ssp_read_reg - Read from a SSP register
- *
- * @dev: SSP device to access
- * @reg: Register to read from
- */
-static inline u32 ssp_read_reg(struct ssp_device *dev, u32 reg)
-{
-       return __raw_readl(dev->mmio_base + reg);
-}
-
-struct ssp_device *ssp_request(int port, const char *label);
-void ssp_free(struct ssp_device *);
-#endif /* __ASM_ARCH_SSP_H */
index 4df2d38..1bbd1f2 100644 (file)
 
 #define TOSA_KEY_SYNC          KEY_102ND /* ??? */
 
-#ifndef CONFIG_KEYBOARD_TOSA_USE_EXT_KEYCODES
+#ifndef CONFIG_TOSA_USE_EXT_KEYCODES
 #define TOSA_KEY_RECORD                KEY_YEN
 #define TOSA_KEY_ADDRESSBOOK   KEY_KATAKANA
 #define TOSA_KEY_CANCEL                KEY_ESC
diff --git a/arch/arm/mach-pxa/include/mach/vpac270.h b/arch/arm/mach-pxa/include/mach/vpac270.h
new file mode 100644 (file)
index 0000000..7bfa3dd
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * GPIOs and interrupts for Voipac PXA270
+ *
+ * Copyright (C) 2010
+ * Marek Vasut <marek.vasut@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#ifndef _INCLUDE_VPAC270_H_
+#define _INCLUDE_VPAC270_H_
+
+#define        GPIO1_VPAC270_USER_BTN          1
+
+#define        GPIO15_VPAC270_LED_ORANGE       15
+
+#define        GPIO81_VPAC270_BKL_ON           81
+#define        GPIO83_VPAC270_NL_ON            83
+
+#define        GPIO52_VPAC270_SD_READONLY      52
+#define        GPIO53_VPAC270_SD_DETECT_N      53
+
+#define        GPIO84_VPAC270_PCMCIA_CD        84
+#define        GPIO35_VPAC270_PCMCIA_RDY       35
+#define        GPIO107_VPAC270_PCMCIA_PPEN     107
+#define        GPIO11_VPAC270_PCMCIA_RESET     11
+#define        GPIO17_VPAC270_CF_CD            17
+#define        GPIO12_VPAC270_CF_RDY           12
+#define        GPIO16_VPAC270_CF_RESET         16
+
+#define        GPIO41_VPAC270_UDC_DETECT       41
+
+#define        GPIO114_VPAC270_ETH_IRQ         114
+
+#define        GPIO36_VPAC270_IDE_IRQ          36
+
+#define        GPIO113_VPAC270_TS_IRQ          113
+
+#endif
diff --git a/arch/arm/mach-pxa/include/mach/z2.h b/arch/arm/mach-pxa/include/mach/z2.h
new file mode 100644 (file)
index 0000000..8835c16
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ *  arch/arm/mach-pxa/include/mach/z2.h
+ *
+ *  Author: Ken McGuire
+ *  Created: Feb 6, 2009
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef ASM_ARCH_ZIPIT2_H
+#define ASM_ARCH_ZIPIT2_H
+
+/* LEDs */
+#define        GPIO10_ZIPITZ2_LED_WIFI         10
+#define        GPIO85_ZIPITZ2_LED_CHARGED      85
+#define        GPIO83_ZIPITZ2_LED_CHARGING     83
+
+/* SD/MMC */
+#define        GPIO96_ZIPITZ2_SD_DETECT        96
+
+/* GPIO Buttons */
+#define        GPIO1_ZIPITZ2_POWER_BUTTON      1
+#define        GPIO98_ZIPITZ2_LID_BUTTON       98
+
+/* Libertas GSPI8686 WiFi */
+#define        GPIO14_ZIPITZ2_WIFI_RESET       14
+#define        GPIO15_ZIPITZ2_WIFI_POWER       15
+#define        GPIO24_ZIPITZ2_WIFI_CS          24
+#define        GPIO36_ZIPITZ2_WIFI_IRQ         36
+
+/* LCD */
+#define        GPIO19_ZIPITZ2_LCD_RESET        19
+#define        GPIO88_ZIPITZ2_LCD_CS           88
+
+/* MISC GPIOs */
+#define        GPIO0_ZIPITZ2_AC_DETECT         0
+#define GPIO37_ZIPITZ2_HEADSET_DETECT  37
+
+#endif
index fa527b2..9b90461 100644 (file)
@@ -41,7 +41,6 @@
 
 #include <mach/pxa300.h>
 #include <mach/pxafb.h>
-#include <mach/ssp.h>
 #include <mach/mmc.h>
 #include <mach/pxa2xx_spi.h>
 #include <mach/pxa27x_keypad.h>
@@ -272,7 +271,7 @@ static inline void littleton_init_keypad(void) {}
 
 #if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
 static struct pxamci_platform_data littleton_mci_platform_data = {
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
        .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
        .gpio_card_detect       = GPIO_MMC1_CARD_DETECT,
        .gpio_card_ro           = -1,
index 63d65a2..330c328 100644 (file)
@@ -478,7 +478,7 @@ static void lubbock_mci_exit(struct device *dev, void *data)
 
 static struct pxamci_platform_data lubbock_mci_platform_data = {
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
-       .detect_delay           = 1,
+       .detect_delay_ms        = 10,
        .init                   = lubbock_mci_init,
        .get_ro                 = lubbock_mci_get_ro,
        .exit                   = lubbock_mci_exit,
index cf6b720..1d1419b 100644 (file)
@@ -81,6 +81,7 @@ static int __mfp_config_gpio(unsigned gpio, unsigned long c)
                PGSR(bank) &= ~mask;
                is_out = 1;
                break;
+       case MFP_LPM_INPUT:
        case MFP_LPM_DEFAULT:
                break;
        default:
@@ -178,8 +179,17 @@ int gpio_set_wake(unsigned int gpio, unsigned int on)
        if (!d->valid)
                return -EINVAL;
 
-       if (d->keypad_gpio)
-               return -EINVAL;
+       /* Allow keypad GPIOs to wakeup system when
+        * configured as generic GPIOs.
+        */
+       if (d->keypad_gpio && (MFP_AF(d->config) == 0) &&
+           (d->config & MFP_LPM_CAN_WAKEUP)) {
+               if (on)
+                       PKWR |= d->mask;
+               else
+                       PKWR &= ~d->mask;
+               return 0;
+       }
 
        mux_taken = (PWER & d->mux_mask) & (~d->mask);
        if (on && mux_taken)
@@ -239,21 +249,25 @@ static int pxa27x_pkwr_gpio[] = {
 int keypad_set_wake(unsigned int on)
 {
        unsigned int i, gpio, mask = 0;
-
-       if (!on) {
-               PKWR = 0;
-               return 0;
-       }
+       struct gpio_desc *d;
 
        for (i = 0; i < ARRAY_SIZE(pxa27x_pkwr_gpio); i++) {
 
                gpio = pxa27x_pkwr_gpio[i];
+               d = &gpio_desc[gpio];
 
-               if (gpio_desc[gpio].config & MFP_LPM_CAN_WAKEUP)
+               /* skip if configured as generic GPIO */
+               if (MFP_AF(d->config) == 0)
+                       continue;
+
+               if (d->config & MFP_LPM_CAN_WAKEUP)
                        mask |= gpio_desc[gpio].mask;
        }
 
-       PKWR = mask;
+       if (on)
+               PKWR |= mask;
+       else
+               PKWR &= ~mask;
        return 0;
 }
 
@@ -328,6 +342,17 @@ static int pxa2xx_mfp_suspend(struct sys_device *d, pm_message_t state)
 {
        int i;
 
+       /* set corresponding PGSR bit of those marked MFP_LPM_KEEP_OUTPUT */
+       for (i = 0; i < pxa_last_gpio; i++) {
+               if ((gpio_desc[i].config & MFP_LPM_KEEP_OUTPUT) &&
+                   (GPDR(i) & GPIO_bit(i))) {
+                       if (GPLR(i) & GPIO_bit(i))
+                               PGSR(i) |= GPIO_bit(i);
+                       else
+                               PGSR(i) &= ~GPIO_bit(i);
+               }
+       }
+
        for (i = 0; i <= gpio_to_bank(pxa_last_gpio); i++) {
 
                saved_gafr[0][i] = GAFR_L(i);
index 7a50ed8..d60db87 100644 (file)
@@ -426,6 +426,7 @@ struct gpio_vbus_mach_info gpio_vbus_data = {
  * to give the card a chance to fully insert/eject.
  */
 static struct pxamci_platform_data mioa701_mci_info = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
        .gpio_card_detect       = GPIO15_SDIO_INSERT,
        .gpio_card_ro           = GPIO78_SDIO_RO,
@@ -791,7 +792,6 @@ static void __init mioa701_machine_init(void)
        mio_gpio_request(ARRAY_AND_SIZE(global_gpios));
        bootstrap_init();
        set_pxa_fb_info(&mioa701_pxafb_info);
-       mioa701_mci_info.detect_delay = msecs_to_jiffies(250);
        pxa_set_mci_info(&mioa701_mci_info);
        pxa_set_keypad_info(&mioa701_keypad_info);
        wm97xx_bat_set_pdata(&mioa701_battery_data);
index 8c9c6f0..462167a 100644 (file)
@@ -325,7 +325,7 @@ static mfp_cfg_t mfp_cfg[] __initdata = {
 #if defined(CONFIG_MMC)
 static struct pxamci_platform_data mxm_8x10_mci_platform_data = {
        .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
-       .detect_delay = 1,
+       .detect_delay_ms = 10,
        .gpio_card_detect = MXM_8X10_SD_nCD,
        .gpio_card_ro = MXM_8X10_SD_WP,
        .gpio_power = -1
index f70c75b..1963819 100644 (file)
@@ -168,7 +168,7 @@ static struct pxamci_platform_data palmld_mci_platform_data = {
        .gpio_card_detect       = GPIO_NR_PALMLD_SD_DETECT_N,
        .gpio_card_ro           = GPIO_NR_PALMLD_SD_READONLY,
        .gpio_power             = GPIO_NR_PALMLD_SD_POWER,
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
 };
 
 /******************************************************************************
index d902a81..5305a39 100644 (file)
@@ -110,7 +110,7 @@ static struct pxamci_platform_data palmt5_mci_platform_data = {
        .gpio_card_detect       = GPIO_NR_PALMT5_SD_DETECT_N,
        .gpio_card_ro           = GPIO_NR_PALMT5_SD_READONLY,
        .gpio_power             = GPIO_NR_PALMT5_SD_POWER,
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
 };
 
 /******************************************************************************
index 717d7a6..033b567 100644 (file)
@@ -121,7 +121,7 @@ static struct pxamci_platform_data palmtc_mci_platform_data = {
        .gpio_power             = GPIO_NR_PALMTC_SD_POWER,
        .gpio_card_ro           = GPIO_NR_PALMTC_SD_READONLY,
        .gpio_card_detect       = GPIO_NR_PALMTC_SD_DETECT_N,
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
 };
 
 /******************************************************************************
index 007b58c..ecc1a40 100644 (file)
@@ -170,7 +170,7 @@ static struct pxamci_platform_data palmtx_mci_platform_data = {
        .gpio_card_detect       = GPIO_NR_PALMTX_SD_DETECT_N,
        .gpio_card_ro           = GPIO_NR_PALMTX_SD_READONLY,
        .gpio_power             = GPIO_NR_PALMTX_SD_POWER,
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
 };
 
 /******************************************************************************
index 9d0ecea..f56ae10 100644 (file)
@@ -326,7 +326,7 @@ static void pcm990_mci_exit(struct device *dev, void *data)
 #define MSECS_PER_JIFFY (1000/HZ)
 
 static struct pxamci_platform_data pcm990_mci_platform_data = {
-       .detect_delay           = 250 / MSECS_PER_JIFFY,
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
        .init                   = pcm990_mci_init,
        .setpower               = pcm990_mci_setpower,
index d58a524..f4abdaa 100644 (file)
 #include <mach/pxa25x.h>
 #include <mach/mmc.h>
 #include <mach/udc.h>
-#include <plat/i2c.h>
 #include <mach/irda.h>
 #include <mach/poodle.h>
 #include <mach/pxafb.h>
 #include <mach/sharpsl.h>
-#include <mach/ssp.h>
 #include <mach/pxa2xx_spi.h>
+#include <plat/i2c.h>
 
 #include <asm/hardware/scoop.h>
 #include <asm/hardware/locomo.h>
@@ -277,6 +276,7 @@ static void poodle_mci_exit(struct device *dev, void *data)
 }
 
 static struct pxamci_platform_data poodle_mci_platform_data = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .init                   = poodle_mci_init,
        .setpower               = poodle_mci_setpower,
@@ -450,7 +450,6 @@ static void __init poodle_init(void)
        set_pxa_fb_parent(&poodle_locomo_device.dev);
        set_pxa_fb_info(&poodle_fb_info);
        pxa_set_udc_info(&udc_info);
-       poodle_mci_platform_data.detect_delay = msecs_to_jiffies(250);
        pxa_set_mci_info(&poodle_mci_platform_data);
        pxa_set_ficp_info(&poodle_ficp_platform_data);
        pxa_set_i2c_info(NULL);
index 4d7c03e..f544e58 100644 (file)
@@ -29,7 +29,6 @@
 #include <mach/ohci.h>
 #include <mach/pm.h>
 #include <mach/dma.h>
-#include <mach/ssp.h>
 #include <mach/regs-intc.h>
 #include <plat/i2c.h>
 
index d12667b..d4b61b3 100644 (file)
@@ -714,7 +714,7 @@ static void raumfeld_mci_exit(struct device *dev, void *data)
 static struct pxamci_platform_data raumfeld_mci_platform_data = {
        .init                   = raumfeld_mci_init,
        .exit                   = raumfeld_mci_exit,
-       .detect_delay           = 20,
+       .detect_delay_ms        = 200,
        .gpio_card_detect       = -1,
        .gpio_card_ro           = -1,
        .gpio_power             = -1,
index 1439785..0cc1203 100644 (file)
@@ -9,29 +9,6 @@
 
 #include <mach/sharpsl_pm.h>
 
-/*
- * SharpSL SSP Driver
- */
-struct corgissp_machinfo {
-       int port;
-       int cs_lcdcon;
-       int cs_ads7846;
-       int cs_max1111;
-       int clk_lcdcon;
-       int clk_ads7846;
-       int clk_max1111;
-};
-
-void corgi_ssp_set_machinfo(struct corgissp_machinfo *machinfo);
-
-
-/*
- * SharpSL/Corgi LCD Driver
- */
-void corgi_lcdtg_suspend(void);
-void corgi_lcdtg_hw_init(int mode);
-
-
 /*
  * SharpSL Battery/PM Driver
  */
index 463d874..cb47672 100644 (file)
@@ -28,7 +28,6 @@
 #include <asm/mach-types.h>
 #include <mach/pm.h>
 #include <mach/pxa2xx-regs.h>
-#include <mach/pxa2xx-gpio.h>
 #include <mach/regs-rtc.h>
 #include <mach/sharpsl.h>
 #include <mach/sharpsl_pm.h>
index 01bdd75..4d2413e 100644 (file)
@@ -86,6 +86,7 @@ static unsigned long spitz_pin_config[] __initdata = {
 
        /* GPIOs */
        GPIO9_GPIO,     /* SPITZ_GPIO_nSD_DETECT */
+       GPIO16_GPIO,    /* SPITZ_GPIO_SYNC */
        GPIO81_GPIO,    /* SPITZ_GPIO_nSD_WP */
        GPIO41_GPIO,    /* SPITZ_GPIO_USB_CONNECT */
        GPIO37_GPIO,    /* SPITZ_GPIO_USB_HOST */
@@ -119,7 +120,8 @@ static unsigned long spitz_pin_config[] __initdata = {
        GPIO117_I2C_SCL,
        GPIO118_I2C_SDA,
 
-       GPIO1_GPIO | WAKEUP_ON_EDGE_RISE,
+       GPIO0_GPIO | WAKEUP_ON_EDGE_RISE,       /* SPITZ_GPIO_KEY_INT */
+       GPIO1_GPIO | WAKEUP_ON_EDGE_FALL,       /* SPITZ_GPIO_RESET */
 };
 
 /*
@@ -537,6 +539,7 @@ static void spitz_mci_setpower(struct device *dev, unsigned int vdd)
 }
 
 static struct pxamci_platform_data spitz_mci_platform_data = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .setpower               = spitz_mci_setpower,
        .gpio_card_detect       = SPITZ_GPIO_nSD_DETECT,
@@ -757,7 +760,6 @@ static void __init common_init(void)
        spitz_init_spi();
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
-       spitz_mci_platform_data.detect_delay = msecs_to_jiffies(250);
        pxa_set_mci_info(&spitz_mci_platform_data);
        pxa_set_ohci_info(&spitz_ohci_platform_data);
        pxa_set_ficp_info(&spitz_ficp_platform_data);
index fc5a70c..4209ddf 100644 (file)
 
 #include <mach/sharpsl.h>
 #include <mach/spitz.h>
-#include <mach/pxa2xx-regs.h>
-#include <mach/pxa2xx-gpio.h>
+#include <mach/pxa27x.h>
+
 #include "sharpsl.h"
+#include "generic.h"
 
 #define SHARPSL_CHARGE_ON_VOLT         0x99  /* 2.9V */
 #define SHARPSL_CHARGE_ON_TEMP         0xe0  /* 2.9V */
 
 static int spitz_last_ac_status;
 
+static struct gpio spitz_charger_gpios[] = {
+       { SPITZ_GPIO_KEY_INT,   GPIOF_IN, "Keyboard Interrupt" },
+       { SPITZ_GPIO_SYNC,      GPIOF_IN, "Sync" },
+       { SPITZ_GPIO_ADC_TEMP_ON, GPIOF_OUT_INIT_LOW, "ADC Temp On" },
+       { SPITZ_GPIO_JK_B,        GPIOF_OUT_INIT_LOW, "JK B" },
+       { SPITZ_GPIO_CHRG_ON,     GPIOF_OUT_INIT_LOW, "Charger On" },
+};
+
 static void spitz_charger_init(void)
 {
-       pxa_gpio_mode(SPITZ_GPIO_KEY_INT | GPIO_IN);
-       pxa_gpio_mode(SPITZ_GPIO_SYNC | GPIO_IN);
+       gpio_request_array(ARRAY_AND_SIZE(spitz_charger_gpios));
 }
 
 static void spitz_measure_temp(int on)
@@ -76,6 +84,11 @@ static void spitz_discharge1(int on)
        gpio_set_value(SPITZ_GPIO_LED_GREEN, on);
 }
 
+static unsigned long gpio18_config[] = {
+       GPIO18_RDY,
+       GPIO18_GPIO,
+};
+
 static void spitz_presuspend(void)
 {
        spitz_last_ac_status = sharpsl_pm.machinfo->read_devdata(SHARPSL_STATUS_ACIN);
@@ -97,7 +110,9 @@ static void spitz_presuspend(void)
        PGSR3 &= ~SPITZ_GPIO_G3_STROBE_BIT;
        PGSR2 |= GPIO_bit(SPITZ_GPIO_KEY_STROBE0);
 
-       pxa_gpio_mode(GPIO18_RDY|GPIO_OUT | GPIO_DFLT_HIGH);
+       pxa2xx_mfp_config(&gpio18_config[0], 1);
+       gpio_request_one(18, GPIOF_OUT_INIT_HIGH, "Unknown");
+       gpio_free(18);
 
        PRER = GPIO_bit(SPITZ_GPIO_KEY_INT);
        PFER = GPIO_bit(SPITZ_GPIO_KEY_INT) | GPIO_bit(SPITZ_GPIO_RESET);
@@ -114,8 +129,7 @@ static void spitz_presuspend(void)
 
 static void spitz_postsuspend(void)
 {
-       pxa_gpio_mode(GPIO18_RDY_MD);
-       pxa_gpio_mode(10 | GPIO_IN);
+       pxa2xx_mfp_config(&gpio18_config[1], 1);
 }
 
 static int spitz_should_wakeup(unsigned int resume_on_alarm)
diff --git a/arch/arm/mach-pxa/ssp.c b/arch/arm/mach-pxa/ssp.c
deleted file mode 100644 (file)
index a81d6db..0000000
+++ /dev/null
@@ -1,510 +0,0 @@
-/*
- *  linux/arch/arm/mach-pxa/ssp.c
- *
- *  based on linux/arch/arm/mach-sa1100/ssp.c by Russell King
- *
- *  Copyright (C) 2003 Russell King.
- *  Copyright (C) 2003 Wolfson Microelectronics PLC
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- *  PXA2xx SSP driver.  This provides the generic core for simple
- *  IO-based SSP applications and allows easy port setup for DMA access.
- *
- *  Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/slab.h>
-#include <linux/errno.h>
-#include <linux/interrupt.h>
-#include <linux/ioport.h>
-#include <linux/init.h>
-#include <linux/mutex.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-#include <linux/platform_device.h>
-#include <linux/io.h>
-
-#include <asm/irq.h>
-#include <mach/hardware.h>
-#include <mach/ssp.h>
-#include <mach/regs-ssp.h>
-
-#ifdef CONFIG_PXA_SSP_LEGACY
-
-#define TIMEOUT 100000
-
-static irqreturn_t ssp_interrupt(int irq, void *dev_id)
-{
-       struct ssp_dev *dev = dev_id;
-       struct ssp_device *ssp = dev->ssp;
-       unsigned int status;
-
-       status = __raw_readl(ssp->mmio_base + SSSR);
-       __raw_writel(status, ssp->mmio_base + SSSR);
-
-       if (status & SSSR_ROR)
-               printk(KERN_WARNING "SSP(%d): receiver overrun\n", dev->port);
-
-       if (status & SSSR_TUR)
-               printk(KERN_WARNING "SSP(%d): transmitter underrun\n", dev->port);
-
-       if (status & SSSR_BCE)
-               printk(KERN_WARNING "SSP(%d): bit count error\n", dev->port);
-
-       return IRQ_HANDLED;
-}
-
-/**
- * ssp_write_word - write a word to the SSP port
- * @data: 32-bit, MSB justified data to write.
- *
- * Wait for a free entry in the SSP transmit FIFO, and write a data
- * word to the SSP port.
- *
- * The caller is expected to perform the necessary locking.
- *
- * Returns:
- *   %-ETIMEDOUT       timeout occurred
- *   0                 success
- */
-int ssp_write_word(struct ssp_dev *dev, u32 data)
-{
-       struct ssp_device *ssp = dev->ssp;
-       int timeout = TIMEOUT;
-
-       while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_TNF)) {
-               if (!--timeout)
-                       return -ETIMEDOUT;
-               cpu_relax();
-       }
-
-       __raw_writel(data, ssp->mmio_base + SSDR);
-
-       return 0;
-}
-
-/**
- * ssp_read_word - read a word from the SSP port
- *
- * Wait for a data word in the SSP receive FIFO, and return the
- * received data.  Data is LSB justified.
- *
- * Note: Currently, if data is not expected to be received, this
- * function will wait for ever.
- *
- * The caller is expected to perform the necessary locking.
- *
- * Returns:
- *   %-ETIMEDOUT       timeout occurred
- *   32-bit data       success
- */
-int ssp_read_word(struct ssp_dev *dev, u32 *data)
-{
-       struct ssp_device *ssp = dev->ssp;
-       int timeout = TIMEOUT;
-
-       while (!(__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE)) {
-               if (!--timeout)
-                       return -ETIMEDOUT;
-               cpu_relax();
-       }
-
-       *data = __raw_readl(ssp->mmio_base + SSDR);
-       return 0;
-}
-
-/**
- * ssp_flush - flush the transmit and receive FIFOs
- *
- * Wait for the SSP to idle, and ensure that the receive FIFO
- * is empty.
- *
- * The caller is expected to perform the necessary locking.
- */
-int ssp_flush(struct ssp_dev *dev)
-{
-       struct ssp_device *ssp = dev->ssp;
-       int timeout = TIMEOUT * 2;
-
-       /* ensure TX FIFO is empty instead of not full */
-       if (cpu_is_pxa3xx()) {
-               while (__raw_readl(ssp->mmio_base + SSSR) & 0xf00) {
-                       if (!--timeout)
-                               return -ETIMEDOUT;
-                       cpu_relax();
-               }
-               timeout = TIMEOUT * 2;
-       }
-
-       do {
-               while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_RNE) {
-                       if (!--timeout)
-                               return -ETIMEDOUT;
-                       (void)__raw_readl(ssp->mmio_base + SSDR);
-               }
-               if (!--timeout)
-                       return -ETIMEDOUT;
-       } while (__raw_readl(ssp->mmio_base + SSSR) & SSSR_BSY);
-
-       return 0;
-}
-
-/**
- * ssp_enable - enable the SSP port
- *
- * Turn on the SSP port.
- */
-void ssp_enable(struct ssp_dev *dev)
-{
-       struct ssp_device *ssp = dev->ssp;
-       uint32_t sscr0;
-
-       sscr0 = __raw_readl(ssp->mmio_base + SSCR0);
-       sscr0 |= SSCR0_SSE;
-       __raw_writel(sscr0, ssp->mmio_base + SSCR0);
-}
-
-/**
- * ssp_disable - shut down the SSP port
- *
- * Turn off the SSP port, optionally powering it down.
- */
-void ssp_disable(struct ssp_dev *dev)
-{
-       struct ssp_device *ssp = dev->ssp;
-       uint32_t sscr0;
-
-       sscr0 = __raw_readl(ssp->mmio_base + SSCR0);
-       sscr0 &= ~SSCR0_SSE;
-       __raw_writel(sscr0, ssp->mmio_base + SSCR0);
-}
-
-/**
- * ssp_save_state - save the SSP configuration
- * @ssp: pointer to structure to save SSP configuration
- *
- * Save the configured SSP state for suspend.
- */
-void ssp_save_state(struct ssp_dev *dev, struct ssp_state *state)
-{
-       struct ssp_device *ssp = dev->ssp;
-
-       state->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
-       state->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
-       state->to  = __raw_readl(ssp->mmio_base + SSTO);
-       state->psp = __raw_readl(ssp->mmio_base + SSPSP);
-
-       ssp_disable(dev);
-}
-
-/**
- * ssp_restore_state - restore a previously saved SSP configuration
- * @ssp: pointer to configuration saved by ssp_save_state
- *
- * Restore the SSP configuration saved previously by ssp_save_state.
- */
-void ssp_restore_state(struct ssp_dev *dev, struct ssp_state *state)
-{
-       struct ssp_device *ssp = dev->ssp;
-       uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
-
-       __raw_writel(sssr, ssp->mmio_base + SSSR);
-
-       __raw_writel(state->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
-       __raw_writel(state->cr1, ssp->mmio_base + SSCR1);
-       __raw_writel(state->to,  ssp->mmio_base + SSTO);
-       __raw_writel(state->psp, ssp->mmio_base + SSPSP);
-       __raw_writel(state->cr0, ssp->mmio_base + SSCR0);
-}
-
-/**
- * ssp_config - configure SSP port settings
- * @mode: port operating mode
- * @flags: port config flags
- * @psp_flags: port PSP config flags
- * @speed: port speed
- *
- * Port MUST be disabled by ssp_disable before making any config changes.
- */
-int ssp_config(struct ssp_dev *dev, u32 mode, u32 flags, u32 psp_flags, u32 speed)
-{
-       struct ssp_device *ssp = dev->ssp;
-
-       dev->mode = mode;
-       dev->flags = flags;
-       dev->psp_flags = psp_flags;
-       dev->speed = speed;
-
-       /* set up port type, speed, port settings */
-       __raw_writel((dev->speed | dev->mode), ssp->mmio_base + SSCR0);
-       __raw_writel(dev->flags, ssp->mmio_base + SSCR1);
-       __raw_writel(dev->psp_flags, ssp->mmio_base + SSPSP);
-
-       return 0;
-}
-
-/**
- * ssp_init - setup the SSP port
- *
- * initialise and claim resources for the SSP port.
- *
- * Returns:
- *   %-ENODEV  if the SSP port is unavailable
- *   %-EBUSY   if the resources are already in use
- *   %0                on success
- */
-int ssp_init(struct ssp_dev *dev, u32 port, u32 init_flags)
-{
-       struct ssp_device *ssp;
-       int ret;
-
-       ssp = ssp_request(port, "SSP");
-       if (ssp == NULL)
-               return -ENODEV;
-
-       dev->ssp = ssp;
-       dev->port = port;
-
-       /* do we need to get irq */
-       if (!(init_flags & SSP_NO_IRQ)) {
-               ret = request_irq(ssp->irq, ssp_interrupt,
-                               0, "SSP", dev);
-               if (ret)
-                       goto out_region;
-               dev->irq = ssp->irq;
-       } else
-               dev->irq = NO_IRQ;
-
-       /* turn on SSP port clock */
-       clk_enable(ssp->clk);
-       return 0;
-
-out_region:
-       ssp_free(ssp);
-       return ret;
-}
-
-/**
- * ssp_exit - undo the effects of ssp_init
- *
- * release and free resources for the SSP port.
- */
-void ssp_exit(struct ssp_dev *dev)
-{
-       struct ssp_device *ssp = dev->ssp;
-
-       ssp_disable(dev);
-       if (dev->irq != NO_IRQ)
-               free_irq(dev->irq, dev);
-       clk_disable(ssp->clk);
-       ssp_free(ssp);
-}
-#endif /* CONFIG_PXA_SSP_LEGACY */
-
-static DEFINE_MUTEX(ssp_lock);
-static LIST_HEAD(ssp_list);
-
-struct ssp_device *ssp_request(int port, const char *label)
-{
-       struct ssp_device *ssp = NULL;
-
-       mutex_lock(&ssp_lock);
-
-       list_for_each_entry(ssp, &ssp_list, node) {
-               if (ssp->port_id == port && ssp->use_count == 0) {
-                       ssp->use_count++;
-                       ssp->label = label;
-                       break;
-               }
-       }
-
-       mutex_unlock(&ssp_lock);
-
-       if (&ssp->node == &ssp_list)
-               return NULL;
-
-       return ssp;
-}
-EXPORT_SYMBOL(ssp_request);
-
-void ssp_free(struct ssp_device *ssp)
-{
-       mutex_lock(&ssp_lock);
-       if (ssp->use_count) {
-               ssp->use_count--;
-               ssp->label = NULL;
-       } else
-               dev_err(&ssp->pdev->dev, "device already free\n");
-       mutex_unlock(&ssp_lock);
-}
-EXPORT_SYMBOL(ssp_free);
-
-static int __devinit ssp_probe(struct platform_device *pdev)
-{
-       const struct platform_device_id *id = platform_get_device_id(pdev);
-       struct resource *res;
-       struct ssp_device *ssp;
-       int ret = 0;
-
-       ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL);
-       if (ssp == NULL) {
-               dev_err(&pdev->dev, "failed to allocate memory");
-               return -ENOMEM;
-       }
-       ssp->pdev = pdev;
-
-       ssp->clk = clk_get(&pdev->dev, NULL);
-       if (IS_ERR(ssp->clk)) {
-               ret = PTR_ERR(ssp->clk);
-               goto err_free;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "no memory resource defined\n");
-               ret = -ENODEV;
-               goto err_free_clk;
-       }
-
-       res = request_mem_region(res->start, res->end - res->start + 1,
-                       pdev->name);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "failed to request memory resource\n");
-               ret = -EBUSY;
-               goto err_free_clk;
-       }
-
-       ssp->phys_base = res->start;
-
-       ssp->mmio_base = ioremap(res->start, res->end - res->start + 1);
-       if (ssp->mmio_base == NULL) {
-               dev_err(&pdev->dev, "failed to ioremap() registers\n");
-               ret = -ENODEV;
-               goto err_free_mem;
-       }
-
-       ssp->irq = platform_get_irq(pdev, 0);
-       if (ssp->irq < 0) {
-               dev_err(&pdev->dev, "no IRQ resource defined\n");
-               ret = -ENODEV;
-               goto err_free_io;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "no SSP RX DRCMR defined\n");
-               ret = -ENODEV;
-               goto err_free_io;
-       }
-       ssp->drcmr_rx = res->start;
-
-       res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "no SSP TX DRCMR defined\n");
-               ret = -ENODEV;
-               goto err_free_io;
-       }
-       ssp->drcmr_tx = res->start;
-
-       /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
-        * starts from 0, do a translation here
-        */
-       ssp->port_id = pdev->id + 1;
-       ssp->use_count = 0;
-       ssp->type = (int)id->driver_data;
-
-       mutex_lock(&ssp_lock);
-       list_add(&ssp->node, &ssp_list);
-       mutex_unlock(&ssp_lock);
-
-       platform_set_drvdata(pdev, ssp);
-       return 0;
-
-err_free_io:
-       iounmap(ssp->mmio_base);
-err_free_mem:
-       release_mem_region(res->start, res->end - res->start + 1);
-err_free_clk:
-       clk_put(ssp->clk);
-err_free:
-       kfree(ssp);
-       return ret;
-}
-
-static int __devexit ssp_remove(struct platform_device *pdev)
-{
-       struct resource *res;
-       struct ssp_device *ssp;
-
-       ssp = platform_get_drvdata(pdev);
-       if (ssp == NULL)
-               return -ENODEV;
-
-       iounmap(ssp->mmio_base);
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       release_mem_region(res->start, res->end - res->start + 1);
-
-       clk_put(ssp->clk);
-
-       mutex_lock(&ssp_lock);
-       list_del(&ssp->node);
-       mutex_unlock(&ssp_lock);
-
-       kfree(ssp);
-       return 0;
-}
-
-static const struct platform_device_id ssp_id_table[] = {
-       { "pxa25x-ssp",         PXA25x_SSP },
-       { "pxa25x-nssp",        PXA25x_NSSP },
-       { "pxa27x-ssp",         PXA27x_SSP },
-       { },
-};
-
-static struct platform_driver ssp_driver = {
-       .probe          = ssp_probe,
-       .remove         = __devexit_p(ssp_remove),
-       .driver         = {
-               .owner  = THIS_MODULE,
-               .name   = "pxa2xx-ssp",
-       },
-       .id_table       = ssp_id_table,
-};
-
-static int __init pxa_ssp_init(void)
-{
-       return platform_driver_register(&ssp_driver);
-}
-
-static void __exit pxa_ssp_exit(void)
-{
-       platform_driver_unregister(&ssp_driver);
-}
-
-arch_initcall(pxa_ssp_init);
-module_exit(pxa_ssp_exit);
-
-#ifdef CONFIG_PXA_SSP_LEGACY
-EXPORT_SYMBOL(ssp_write_word);
-EXPORT_SYMBOL(ssp_read_word);
-EXPORT_SYMBOL(ssp_flush);
-EXPORT_SYMBOL(ssp_enable);
-EXPORT_SYMBOL(ssp_disable);
-EXPORT_SYMBOL(ssp_save_state);
-EXPORT_SYMBOL(ssp_restore_state);
-EXPORT_SYMBOL(ssp_init);
-EXPORT_SYMBOL(ssp_exit);
-EXPORT_SYMBOL(ssp_config);
-#endif
-
-MODULE_DESCRIPTION("PXA SSP driver");
-MODULE_AUTHOR("Liam Girdwood");
-MODULE_LICENSE("GPL");
-
index 2041eb1..af40d2a 100644 (file)
@@ -464,8 +464,6 @@ static struct platform_device smc91x_device = {
 
 
 
-static struct pxamci_platform_data stargate2_mci_platform_data;
-
 /*
  * The card detect interrupt isn't debounced so we delay it by 250ms
  * to give the card a chance to fully insert / eject.
@@ -489,8 +487,6 @@ static int stargate2_mci_init(struct device *dev,
                goto free_power_en;
        }
        gpio_direction_input(SG2_GPIO_nSD_DETECT);
-       /* Delay to allow for full insertion */
-       stargate2_mci_platform_data.detect_delay = msecs_to_jiffies(250);
 
        err = request_irq(IRQ_GPIO(SG2_GPIO_nSD_DETECT),
                          stargate2_detect_int,
@@ -529,6 +525,7 @@ static void stargate2_mci_exit(struct device *dev, void *data)
 }
 
 static struct pxamci_platform_data stargate2_mci_platform_data = {
+       .detect_delay_ms = 250,
        .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34,
        .init = stargate2_mci_init,
        .setpower = stargate2_mci_setpower,
index ad55279..7512b82 100644 (file)
@@ -275,6 +275,7 @@ static void tosa_mci_exit(struct device *dev, void *data)
 }
 
 static struct pxamci_platform_data tosa_mci_platform_data = {
+       .detect_delay_ms        = 250,
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
        .init                   = tosa_mci_init,
        .exit                   = tosa_mci_exit,
@@ -926,7 +927,6 @@ static void __init tosa_init(void)
        dummy = gpiochip_reserve(TOSA_SCOOP_JC_GPIO_BASE, 12);
        dummy = gpiochip_reserve(TOSA_TC6393XB_GPIO_BASE, 16);
 
-       tosa_mci_platform_data.detect_delay = msecs_to_jiffies(250);
        pxa_set_mci_info(&tosa_mci_platform_data);
        pxa_set_udc_info(&udc_info);
        pxa_set_ficp_info(&tosa_ficp_platform_data);
index 797f254..6968911 100644 (file)
@@ -349,7 +349,7 @@ static void trizeps4_mci_exit(struct device *dev, void *data)
 
 static struct pxamci_platform_data trizeps4_mci_platform_data = {
        .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
-       .detect_delay   = 1,
+       .detect_delay_ms= 10,
        .init           = trizeps4_mci_init,
        .exit           = trizeps4_mci_exit,
        .get_ro         = NULL, /* write-protection not supported */
diff --git a/arch/arm/mach-pxa/vpac270.c b/arch/arm/mach-pxa/vpac270.c
new file mode 100644 (file)
index 0000000..9884fa9
--- /dev/null
@@ -0,0 +1,615 @@
+/*
+ * Hardware definitions for Voipac PXA270
+ *
+ * Copyright (C) 2010
+ * Marek Vasut <marek.vasut@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/irq.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <linux/gpio.h>
+#include <linux/sysdev.h>
+#include <linux/usb/gpio_vbus.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+#include <linux/mtd/onenand.h>
+#include <linux/dm9000.h>
+#include <linux/ucb1400.h>
+#include <linux/ata_platform.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+#include <mach/pxa27x.h>
+#include <mach/audio.h>
+#include <mach/vpac270.h>
+#include <mach/mmc.h>
+#include <mach/pxafb.h>
+#include <mach/ohci.h>
+#include <mach/pxa27x-udc.h>
+#include <mach/udc.h>
+
+#include <plat/i2c.h>
+
+#include "generic.h"
+#include "devices.h"
+
+/******************************************************************************
+ * Pin configuration
+ ******************************************************************************/
+static unsigned long vpac270_pin_config[] __initdata = {
+       /* MMC */
+       GPIO32_MMC_CLK,
+       GPIO92_MMC_DAT_0,
+       GPIO109_MMC_DAT_1,
+       GPIO110_MMC_DAT_2,
+       GPIO111_MMC_DAT_3,
+       GPIO112_MMC_CMD,
+       GPIO53_GPIO,    /* SD detect */
+       GPIO52_GPIO,    /* SD r/o switch */
+
+       /* GPIO KEYS */
+       GPIO1_GPIO,     /* USER BTN */
+
+       /* LEDs */
+       GPIO15_GPIO,    /* orange led */
+
+       /* FFUART */
+       GPIO34_FFUART_RXD,
+       GPIO39_FFUART_TXD,
+       GPIO27_FFUART_RTS,
+       GPIO100_FFUART_CTS,
+       GPIO33_FFUART_DSR,
+       GPIO40_FFUART_DTR,
+       GPIO10_FFUART_DCD,
+       GPIO38_FFUART_RI,
+
+       /* LCD */
+       GPIO58_LCD_LDD_0,
+       GPIO59_LCD_LDD_1,
+       GPIO60_LCD_LDD_2,
+       GPIO61_LCD_LDD_3,
+       GPIO62_LCD_LDD_4,
+       GPIO63_LCD_LDD_5,
+       GPIO64_LCD_LDD_6,
+       GPIO65_LCD_LDD_7,
+       GPIO66_LCD_LDD_8,
+       GPIO67_LCD_LDD_9,
+       GPIO68_LCD_LDD_10,
+       GPIO69_LCD_LDD_11,
+       GPIO70_LCD_LDD_12,
+       GPIO71_LCD_LDD_13,
+       GPIO72_LCD_LDD_14,
+       GPIO73_LCD_LDD_15,
+       GPIO86_LCD_LDD_16,
+       GPIO87_LCD_LDD_17,
+       GPIO74_LCD_FCLK,
+       GPIO75_LCD_LCLK,
+       GPIO76_LCD_PCLK,
+       GPIO77_LCD_BIAS,
+
+       /* PCMCIA */
+       GPIO48_nPOE,
+       GPIO49_nPWE,
+       GPIO50_nPIOR,
+       GPIO51_nPIOW,
+       GPIO85_nPCE_1,
+       GPIO54_nPCE_2,
+       GPIO55_nPREG,
+       GPIO57_nIOIS16,
+       GPIO56_nPWAIT,
+       GPIO104_PSKTSEL,
+       GPIO84_GPIO,    /* PCMCIA CD */
+       GPIO35_GPIO,    /* PCMCIA RDY */
+       GPIO107_GPIO,   /* PCMCIA PPEN */
+       GPIO11_GPIO,    /* PCMCIA RESET */
+       GPIO17_GPIO,    /* CF CD */
+       GPIO12_GPIO,    /* CF RDY */
+       GPIO16_GPIO,    /* CF RESET */
+
+       /* UHC */
+       GPIO88_USBH1_PWR,
+       GPIO89_USBH1_PEN,
+       GPIO119_USBH2_PWR,
+       GPIO120_USBH2_PEN,
+
+       /* UDC */
+       GPIO41_GPIO,
+
+       /* Ethernet */
+       GPIO114_GPIO,   /* IRQ */
+
+       /* AC97 */
+       GPIO28_AC97_BITCLK,
+       GPIO29_AC97_SDATA_IN_0,
+       GPIO30_AC97_SDATA_OUT,
+       GPIO31_AC97_SYNC,
+       GPIO95_AC97_nRESET,
+       GPIO98_AC97_SYSCLK,
+       GPIO113_GPIO,   /* TS IRQ */
+
+       /* I2C */
+       GPIO117_I2C_SCL,
+       GPIO118_I2C_SDA,
+
+       /* IDE */
+       GPIO36_GPIO,    /* IDE IRQ */
+       GPIO80_DREQ_1,
+};
+
+/******************************************************************************
+ * NOR Flash
+ ******************************************************************************/
+#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
+static struct mtd_partition vpac270_nor_partitions[] = {
+       {
+               .name           = "Flash",
+               .offset         = 0x00000000,
+               .size           = MTDPART_SIZ_FULL,
+       }
+};
+
+static struct physmap_flash_data vpac270_flash_data[] = {
+       {
+               .width          = 2,    /* bankwidth in bytes */
+               .parts          = vpac270_nor_partitions,
+               .nr_parts       = ARRAY_SIZE(vpac270_nor_partitions)
+       }
+};
+
+static struct resource vpac270_flash_resource = {
+       .start  = PXA_CS0_PHYS,
+       .end    = PXA_CS0_PHYS + SZ_64M - 1,
+       .flags  = IORESOURCE_MEM,
+};
+
+static struct platform_device vpac270_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .resource       = &vpac270_flash_resource,
+       .num_resources  = 1,
+       .dev            = {
+               .platform_data = vpac270_flash_data,
+       },
+};
+static void __init vpac270_nor_init(void)
+{
+       platform_device_register(&vpac270_flash);
+}
+#else
+static inline void vpac270_nor_init(void) {}
+#endif
+
+/******************************************************************************
+ * OneNAND Flash
+ ******************************************************************************/
+#if defined(CONFIG_MTD_ONENAND) || defined(CONFIG_MTD_ONENAND_MODULE)
+static struct mtd_partition vpac270_onenand_partitions[] = {
+       {
+               .name           = "Flash",
+               .offset         = 0x00000000,
+               .size           = MTDPART_SIZ_FULL,
+       }
+};
+
+static struct onenand_platform_data vpac270_onenand_info = {
+       .parts          = vpac270_onenand_partitions,
+       .nr_parts       = ARRAY_SIZE(vpac270_onenand_partitions),
+};
+
+static struct resource vpac270_onenand_resources[] = {
+       [0] = {
+               .start  = PXA_CS0_PHYS,
+               .end    = PXA_CS0_PHYS + SZ_1M,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device vpac270_onenand = {
+       .name           = "onenand-flash",
+       .id             = -1,
+       .resource       = vpac270_onenand_resources,
+       .num_resources  = ARRAY_SIZE(vpac270_onenand_resources),
+       .dev            = {
+               .platform_data  = &vpac270_onenand_info,
+       },
+};
+
+static void __init vpac270_onenand_init(void)
+{
+       platform_device_register(&vpac270_onenand);
+}
+#else
+static void __init vpac270_onenand_init(void) {}
+#endif
+
+/******************************************************************************
+ * SD/MMC card controller
+ ******************************************************************************/
+#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
+static struct pxamci_platform_data vpac270_mci_platform_data = {
+       .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
+       .gpio_card_detect       = GPIO53_VPAC270_SD_DETECT_N,
+       .gpio_card_ro           = GPIO52_VPAC270_SD_READONLY,
+       .detect_delay_ms        = 200,
+};
+
+static void __init vpac270_mmc_init(void)
+{
+       pxa_set_mci_info(&vpac270_mci_platform_data);
+}
+#else
+static inline void vpac270_mmc_init(void) {}
+#endif
+
+/******************************************************************************
+ * GPIO keys
+ ******************************************************************************/
+#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
+static struct gpio_keys_button vpac270_pxa_buttons[] = {
+       {KEY_POWER, GPIO1_VPAC270_USER_BTN, 0, "USER BTN"},
+};
+
+static struct gpio_keys_platform_data vpac270_pxa_keys_data = {
+       .buttons        = vpac270_pxa_buttons,
+       .nbuttons       = ARRAY_SIZE(vpac270_pxa_buttons),
+};
+
+static struct platform_device vpac270_pxa_keys = {
+       .name   = "gpio-keys",
+       .id     = -1,
+       .dev    = {
+               .platform_data = &vpac270_pxa_keys_data,
+       },
+};
+
+static void __init vpac270_keys_init(void)
+{
+       platform_device_register(&vpac270_pxa_keys);
+}
+#else
+static inline void vpac270_keys_init(void) {}
+#endif
+
+/******************************************************************************
+ * LED
+ ******************************************************************************/
+#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
+struct gpio_led vpac270_gpio_leds[] = {
+{
+       .name                   = "vpac270:orange:user",
+       .default_trigger        = "none",
+       .gpio                   = GPIO15_VPAC270_LED_ORANGE,
+       .active_low             = 1,
+}
+};
+
+static struct gpio_led_platform_data vpac270_gpio_led_info = {
+       .leds           = vpac270_gpio_leds,
+       .num_leds       = ARRAY_SIZE(vpac270_gpio_leds),
+};
+
+static struct platform_device vpac270_leds = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &vpac270_gpio_led_info,
+       }
+};
+
+static void __init vpac270_leds_init(void)
+{
+       platform_device_register(&vpac270_leds);
+}
+#else
+static inline void vpac270_leds_init(void) {}
+#endif
+
+/******************************************************************************
+ * USB Host
+ ******************************************************************************/
+#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
+static int vpac270_ohci_init(struct device *dev)
+{
+       UP2OCR = UP2OCR_HXS | UP2OCR_HXOE | UP2OCR_DPPDE | UP2OCR_DMPDE;
+       return 0;
+}
+
+static struct pxaohci_platform_data vpac270_ohci_info = {
+       .port_mode      = PMM_PERPORT_MODE,
+       .flags          = ENABLE_PORT1 | ENABLE_PORT2 |
+                       POWER_CONTROL_LOW | POWER_SENSE_LOW,
+       .init           = vpac270_ohci_init,
+};
+
+static void __init vpac270_uhc_init(void)
+{
+       pxa_set_ohci_info(&vpac270_ohci_info);
+}
+#else
+static inline void vpac270_uhc_init(void) {}
+#endif
+
+/******************************************************************************
+ * USB Gadget
+ ******************************************************************************/
+#if defined(CONFIG_USB_GADGET_PXA27X)||defined(CONFIG_USB_GADGET_PXA27X_MODULE)
+static struct gpio_vbus_mach_info vpac270_gpio_vbus_info = {
+       .gpio_vbus              = GPIO41_VPAC270_UDC_DETECT,
+       .gpio_pullup            = -1,
+};
+
+static struct platform_device vpac270_gpio_vbus = {
+       .name   = "gpio-vbus",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &vpac270_gpio_vbus_info,
+       },
+};
+
+static void vpac270_udc_command(int cmd)
+{
+       if (cmd == PXA2XX_UDC_CMD_CONNECT)
+               UP2OCR = UP2OCR_HXOE | UP2OCR_DPPUE;
+       else if (cmd == PXA2XX_UDC_CMD_DISCONNECT)
+               UP2OCR = UP2OCR_HXOE;
+}
+
+static struct pxa2xx_udc_mach_info vpac270_udc_info __initdata = {
+       .udc_command            = vpac270_udc_command,
+       .gpio_pullup            = -1,
+};
+
+static void __init vpac270_udc_init(void)
+{
+       pxa_set_udc_info(&vpac270_udc_info);
+       platform_device_register(&vpac270_gpio_vbus);
+}
+#else
+static inline void vpac270_udc_init(void) {}
+#endif
+
+/******************************************************************************
+ * Ethernet
+ ******************************************************************************/
+#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
+static struct resource vpac270_dm9000_resources[] = {
+       [0] = {
+               .start  = PXA_CS2_PHYS + 0x300,
+               .end    = PXA_CS2_PHYS + 0x303,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = PXA_CS2_PHYS + 0x304,
+               .end    = PXA_CS2_PHYS + 0x343,
+               .flags  = IORESOURCE_MEM,
+       },
+       [2] = {
+               .start  = IRQ_GPIO(GPIO114_VPAC270_ETH_IRQ),
+               .end    = IRQ_GPIO(GPIO114_VPAC270_ETH_IRQ),
+               .flags  = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE,
+       },
+};
+
+static struct dm9000_plat_data vpac270_dm9000_platdata = {
+       .flags          = DM9000_PLATF_32BITONLY,
+};
+
+static struct platform_device vpac270_dm9000_device = {
+       .name           = "dm9000",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(vpac270_dm9000_resources),
+       .resource       = vpac270_dm9000_resources,
+       .dev            = {
+               .platform_data = &vpac270_dm9000_platdata,
+       }
+};
+
+static void __init vpac270_eth_init(void)
+{
+       platform_device_register(&vpac270_dm9000_device);
+}
+#else
+static inline void vpac270_eth_init(void) {}
+#endif
+
+/******************************************************************************
+ * Audio and Touchscreen
+ ******************************************************************************/
+#if    defined(CONFIG_TOUCHSCREEN_UCB1400) || \
+       defined(CONFIG_TOUCHSCREEN_UCB1400_MODULE)
+static pxa2xx_audio_ops_t vpac270_ac97_pdata = {
+       .reset_gpio     = 95,
+};
+
+static struct ucb1400_pdata vpac270_ucb1400_pdata = {
+       .irq            = IRQ_GPIO(GPIO113_VPAC270_TS_IRQ),
+};
+
+static struct platform_device vpac270_ucb1400_device = {
+       .name           = "ucb1400_core",
+       .id             = -1,
+       .dev            = {
+               .platform_data = &vpac270_ucb1400_pdata,
+       },
+};
+
+static void __init vpac270_ts_init(void)
+{
+       pxa_set_ac97_info(&vpac270_ac97_pdata);
+       platform_device_register(&vpac270_ucb1400_device);
+}
+#else
+static inline void vpac270_ts_init(void) {}
+#endif
+
+/******************************************************************************
+ * RTC
+ ******************************************************************************/
+#if defined(CONFIG_RTC_DRV_DS1307) || defined(CONFIG_RTC_DRV_DS1307_MODULE)
+static struct i2c_board_info __initdata vpac270_i2c_devs[] = {
+       {
+               I2C_BOARD_INFO("ds1339", 0x68),
+       },
+};
+
+static void __init vpac270_rtc_init(void)
+{
+       pxa_set_i2c_info(NULL);
+       i2c_register_board_info(0, ARRAY_AND_SIZE(vpac270_i2c_devs));
+}
+#else
+static inline void vpac270_rtc_init(void) {}
+#endif
+
+/******************************************************************************
+ * Framebuffer
+ ******************************************************************************/
+#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
+static struct pxafb_mode_info vpac270_lcd_modes[] = {
+{
+       .pixclock       = 57692,
+       .xres           = 640,
+       .yres           = 480,
+       .bpp            = 32,
+       .depth          = 18,
+
+       .left_margin    = 144,
+       .right_margin   = 32,
+       .upper_margin   = 13,
+       .lower_margin   = 30,
+
+       .hsync_len      = 32,
+       .vsync_len      = 2,
+
+       .sync           = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
+},
+};
+
+static struct pxafb_mach_info vpac270_lcd_screen = {
+       .modes          = vpac270_lcd_modes,
+       .num_modes      = ARRAY_SIZE(vpac270_lcd_modes),
+       .lcd_conn       = LCD_COLOR_TFT_18BPP,
+};
+
+static void vpac270_lcd_power(int on, struct fb_var_screeninfo *info)
+{
+       gpio_set_value(GPIO81_VPAC270_BKL_ON, on);
+}
+
+static void __init vpac270_lcd_init(void)
+{
+       int ret;
+
+       ret = gpio_request(GPIO81_VPAC270_BKL_ON, "BKL-ON");
+       if (ret) {
+               pr_err("Requesting BKL-ON GPIO failed!\n");
+               goto err;
+       }
+
+       ret = gpio_direction_output(GPIO81_VPAC270_BKL_ON, 1);
+       if (ret) {
+               pr_err("Setting BKL-ON GPIO direction failed!\n");
+               goto err2;
+       }
+
+       vpac270_lcd_screen.pxafb_lcd_power = vpac270_lcd_power;
+       set_pxa_fb_info(&vpac270_lcd_screen);
+       return;
+
+err2:
+       gpio_free(GPIO81_VPAC270_BKL_ON);
+err:
+       return;
+}
+#else
+static inline void vpac270_lcd_init(void) {}
+#endif
+
+/******************************************************************************
+ * PATA IDE
+ ******************************************************************************/
+#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
+static struct pata_platform_info vpac270_pata_pdata = {
+       .ioport_shift   = 1,
+       .irq_flags      = IRQF_TRIGGER_RISING,
+};
+
+static struct resource vpac270_ide_resources[] = {
+       [0] = { /* I/O Base address */
+              .start   = PXA_CS3_PHYS + 0x120,
+              .end     = PXA_CS3_PHYS + 0x13f,
+              .flags   = IORESOURCE_MEM
+       },
+       [1] = { /* CTL Base address */
+              .start   = PXA_CS3_PHYS + 0x15c,
+              .end     = PXA_CS3_PHYS + 0x15f,
+              .flags   = IORESOURCE_MEM
+       },
+       [2] = { /* IDE IRQ pin */
+              .start   = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ),
+              .end     = gpio_to_irq(GPIO36_VPAC270_IDE_IRQ),
+              .flags   = IORESOURCE_IRQ
+       }
+};
+
+static struct platform_device vpac270_ide_device = {
+       .name           = "pata_platform",
+       .num_resources  = ARRAY_SIZE(vpac270_ide_resources),
+       .resource       = vpac270_ide_resources,
+       .dev            = {
+               .platform_data  = &vpac270_pata_pdata,
+       }
+};
+
+static void __init vpac270_ide_init(void)
+{
+       platform_device_register(&vpac270_ide_device);
+}
+#else
+static inline void vpac270_ide_init(void) {}
+#endif
+
+/******************************************************************************
+ * Machine init
+ ******************************************************************************/
+static void __init vpac270_init(void)
+{
+       pxa2xx_mfp_config(ARRAY_AND_SIZE(vpac270_pin_config));
+
+       pxa_set_ffuart_info(NULL);
+       pxa_set_btuart_info(NULL);
+       pxa_set_stuart_info(NULL);
+
+       vpac270_lcd_init();
+       vpac270_mmc_init();
+       vpac270_nor_init();
+       vpac270_onenand_init();
+       vpac270_leds_init();
+       vpac270_keys_init();
+       vpac270_uhc_init();
+       vpac270_udc_init();
+       vpac270_eth_init();
+       vpac270_ts_init();
+       vpac270_rtc_init();
+       vpac270_ide_init();
+}
+
+MACHINE_START(VPAC270, "Voipac PXA270")
+       .phys_io        = 0x40000000,
+       .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
+       .boot_params    = 0xa0000100,
+       .map_io         = pxa_map_io,
+       .init_irq       = pxa27x_init_irq,
+       .timer          = &pxa_timer,
+       .init_machine   = vpac270_init
+MACHINE_END
diff --git a/arch/arm/mach-pxa/z2.c b/arch/arm/mach-pxa/z2.c
new file mode 100644 (file)
index 0000000..f5d1ae3
--- /dev/null
@@ -0,0 +1,609 @@
+/*
+ *  linux/arch/arm/mach-pxa/z2.c
+ *
+ *  Support for the Zipit Z2 Handheld device.
+ *
+ *  Author:    Ken McGuire
+ *  Created:   Jan 25, 2009
+ *  Based on mainstone.c as modified for the Zipit Z2.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+#include <linux/pwm_backlight.h>
+#include <linux/dma-mapping.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/libertas_spi.h>
+#include <linux/spi/lms283gf05.h>
+#include <linux/power_supply.h>
+#include <linux/mtd/physmap.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/delay.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+#include <mach/pxa27x.h>
+#include <mach/mfp-pxa27x.h>
+#include <mach/z2.h>
+#include <mach/pxafb.h>
+#include <mach/mmc.h>
+#include <mach/pxa27x_keypad.h>
+#include <mach/pxa2xx_spi.h>
+
+#include <plat/i2c.h>
+
+#include "generic.h"
+#include "devices.h"
+
+/******************************************************************************
+ * Pin configuration
+ ******************************************************************************/
+static unsigned long z2_pin_config[] = {
+
+       /* LCD - 16bpp Active TFT */
+       GPIO58_LCD_LDD_0,
+       GPIO59_LCD_LDD_1,
+       GPIO60_LCD_LDD_2,
+       GPIO61_LCD_LDD_3,
+       GPIO62_LCD_LDD_4,
+       GPIO63_LCD_LDD_5,
+       GPIO64_LCD_LDD_6,
+       GPIO65_LCD_LDD_7,
+       GPIO66_LCD_LDD_8,
+       GPIO67_LCD_LDD_9,
+       GPIO68_LCD_LDD_10,
+       GPIO69_LCD_LDD_11,
+       GPIO70_LCD_LDD_12,
+       GPIO71_LCD_LDD_13,
+       GPIO72_LCD_LDD_14,
+       GPIO73_LCD_LDD_15,
+       GPIO74_LCD_FCLK,
+       GPIO75_LCD_LCLK,
+       GPIO76_LCD_PCLK,
+       GPIO77_LCD_BIAS,
+       GPIO19_GPIO,            /* LCD reset */
+       GPIO88_GPIO,            /* LCD chipselect */
+
+       /* PWM */
+       GPIO115_PWM1_OUT,       /* Keypad Backlight */
+       GPIO11_PWM2_OUT,        /* LCD Backlight */
+
+       /* MMC */
+       GPIO32_MMC_CLK,
+       GPIO112_MMC_CMD,
+       GPIO92_MMC_DAT_0,
+       GPIO109_MMC_DAT_1,
+       GPIO110_MMC_DAT_2,
+       GPIO111_MMC_DAT_3,
+       GPIO96_GPIO,            /* SD detect */
+
+       /* STUART */
+       GPIO46_STUART_RXD,
+       GPIO47_STUART_TXD,
+
+       /* Keypad */
+       GPIO100_KP_MKIN_0       | WAKEUP_ON_LEVEL_HIGH,
+       GPIO101_KP_MKIN_1       | WAKEUP_ON_LEVEL_HIGH,
+       GPIO102_KP_MKIN_2       | WAKEUP_ON_LEVEL_HIGH,
+       GPIO34_KP_MKIN_3        | WAKEUP_ON_LEVEL_HIGH,
+       GPIO38_KP_MKIN_4        | WAKEUP_ON_LEVEL_HIGH,
+       GPIO16_KP_MKIN_5        | WAKEUP_ON_LEVEL_HIGH,
+       GPIO17_KP_MKIN_6        | WAKEUP_ON_LEVEL_HIGH,
+       GPIO103_KP_MKOUT_0,
+       GPIO104_KP_MKOUT_1,
+       GPIO105_KP_MKOUT_2,
+       GPIO106_KP_MKOUT_3,
+       GPIO107_KP_MKOUT_4,
+       GPIO108_KP_MKOUT_5,
+       GPIO35_KP_MKOUT_6,
+       GPIO41_KP_MKOUT_7,
+
+       /* I2C */
+       GPIO117_I2C_SCL,
+       GPIO118_I2C_SDA,
+
+       /* SSP1 */
+       GPIO23_SSP1_SCLK,       /* SSP1_SCK */
+       GPIO25_SSP1_TXD,        /* SSP1_TXD */
+       GPIO26_SSP1_RXD,        /* SSP1_RXD */
+
+       /* SSP2 */
+       GPIO22_SSP2_SCLK,       /* SSP2_SCK */
+       GPIO13_SSP2_TXD,        /* SSP2_TXD */
+       GPIO40_SSP2_RXD,        /* SSP2_RXD */
+
+       /* LEDs */
+       GPIO10_GPIO,            /* WiFi LED */
+       GPIO83_GPIO,            /* Charging LED */
+       GPIO85_GPIO,            /* Charged LED */
+
+       /* I2S */
+       GPIO28_I2S_BITCLK_OUT,
+       GPIO29_I2S_SDATA_IN,
+       GPIO30_I2S_SDATA_OUT,
+       GPIO31_I2S_SYNC,
+       GPIO113_I2S_SYSCLK,
+
+       /* MISC */
+       GPIO0_GPIO,             /* AC power detect */
+       GPIO1_GPIO,             /* Power button */
+       GPIO37_GPIO,            /* Headphone detect */
+       GPIO98_GPIO,            /* Lid switch */
+       GPIO14_GPIO,            /* WiFi Reset */
+       GPIO15_GPIO,            /* WiFi Power */
+       GPIO24_GPIO,            /* WiFi CS */
+       GPIO36_GPIO,            /* WiFi IRQ */
+       GPIO88_GPIO,            /* LCD CS */
+};
+
+/******************************************************************************
+ * NOR Flash
+ ******************************************************************************/
+#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
+static struct resource z2_flash_resource = {
+       .start  = PXA_CS0_PHYS,
+       .end    = PXA_CS0_PHYS + SZ_8M - 1,
+       .flags  = IORESOURCE_MEM,
+};
+
+static struct mtd_partition z2_flash_parts[] = {
+       {
+               .name   = "U-Boot Bootloader",
+               .offset = 0x0,
+               .size   = 0x20000,
+       },
+       {
+               .name   = "Linux Kernel",
+               .offset = 0x20000,
+               .size   = 0x220000,
+       },
+       {
+               .name   = "Filesystem",
+               .offset = 0x240000,
+               .size   = 0x5b0000,
+       },
+       {
+               .name   = "U-Boot Environment",
+               .offset = 0x7f0000,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct physmap_flash_data z2_flash_data = {
+       .width          = 2,
+       .parts          = z2_flash_parts,
+       .nr_parts       = ARRAY_SIZE(z2_flash_parts),
+};
+
+static struct platform_device z2_flash = {
+       .name           = "physmap-flash",
+       .id             = -1,
+       .resource       = &z2_flash_resource,
+       .num_resources  = 1,
+       .dev = {
+               .platform_data  = &z2_flash_data,
+       },
+};
+
+static void __init z2_nor_init(void)
+{
+       platform_device_register(&z2_flash);
+}
+#else
+static inline void z2_nor_init(void) {}
+#endif
+
+/******************************************************************************
+ * Backlight
+ ******************************************************************************/
+#if defined(CONFIG_BACKLIGHT_PWM) || defined(CONFIG_BACKLIGHT_PWM_MODULE)
+static struct platform_pwm_backlight_data z2_backlight_data[] = {
+       [0] = {
+               /* Keypad Backlight */
+               .pwm_id         = 1,
+               .max_brightness = 1023,
+               .dft_brightness = 512,
+               .pwm_period_ns  = 1260320,
+       },
+       [1] = {
+               /* LCD Backlight */
+               .pwm_id         = 2,
+               .max_brightness = 1023,
+               .dft_brightness = 512,
+               .pwm_period_ns  = 1260320,
+       },
+};
+
+static struct platform_device z2_backlight_devices[2] = {
+       {
+               .name   = "pwm-backlight",
+               .id     = 0,
+               .dev    = {
+                       .platform_data  = &z2_backlight_data[1],
+               },
+       },
+       {
+               .name   = "pwm-backlight",
+               .id     = 1,
+               .dev    = {
+                       .platform_data  = &z2_backlight_data[0],
+               },
+       },
+};
+static void __init z2_pwm_init(void)
+{
+       platform_device_register(&z2_backlight_devices[0]);
+       platform_device_register(&z2_backlight_devices[1]);
+}
+#else
+static inline void z2_pwm_init(void) {}
+#endif
+
+/******************************************************************************
+ * Framebuffer
+ ******************************************************************************/
+#if defined(CONFIG_FB_PXA) || defined(CONFIG_FB_PXA_MODULE)
+static struct pxafb_mode_info z2_lcd_modes[] = {
+{
+       .pixclock       = 192000,
+       .xres           = 240,
+       .yres           = 320,
+       .bpp            = 16,
+
+       .left_margin    = 4,
+       .right_margin   = 8,
+       .upper_margin   = 4,
+       .lower_margin   = 8,
+
+       .hsync_len      = 4,
+       .vsync_len      = 4,
+},
+};
+
+static struct pxafb_mach_info z2_lcd_screen = {
+       .modes          = z2_lcd_modes,
+       .num_modes      = ARRAY_SIZE(z2_lcd_modes),
+       .lcd_conn       = LCD_COLOR_TFT_16BPP | LCD_BIAS_ACTIVE_LOW |
+                         LCD_ALTERNATE_MAPPING,
+};
+
+static void __init z2_lcd_init(void)
+{
+       set_pxa_fb_info(&z2_lcd_screen);
+}
+#else
+static inline void z2_lcd_init(void) {}
+#endif
+
+/******************************************************************************
+ * SD/MMC card controller
+ ******************************************************************************/
+#if defined(CONFIG_MMC_PXA) || defined(CONFIG_MMC_PXA_MODULE)
+static struct pxamci_platform_data z2_mci_platform_data = {
+       .ocr_mask               = MMC_VDD_32_33 | MMC_VDD_33_34,
+       .gpio_card_detect       = GPIO96_ZIPITZ2_SD_DETECT,
+       .gpio_power             = -1,
+       .gpio_card_ro           = -1,
+       .detect_delay_ms        = 200,
+};
+
+static void __init z2_mmc_init(void)
+{
+       pxa_set_mci_info(&z2_mci_platform_data);
+}
+#else
+static inline void z2_mmc_init(void) {}
+#endif
+
+/******************************************************************************
+ * LEDs
+ ******************************************************************************/
+#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
+struct gpio_led z2_gpio_leds[] = {
+{
+       .name                   = "z2:green:wifi",
+       .default_trigger        = "none",
+       .gpio                   = GPIO10_ZIPITZ2_LED_WIFI,
+       .active_low             = 1,
+}, {
+       .name                   = "z2:green:charged",
+       .default_trigger        = "none",
+       .gpio                   = GPIO85_ZIPITZ2_LED_CHARGED,
+       .active_low             = 1,
+}, {
+       .name                   = "z2:amber:charging",
+       .default_trigger        = "none",
+       .gpio                   = GPIO83_ZIPITZ2_LED_CHARGING,
+       .active_low             = 1,
+},
+};
+
+static struct gpio_led_platform_data z2_gpio_led_info = {
+       .leds           = z2_gpio_leds,
+       .num_leds       = ARRAY_SIZE(z2_gpio_leds),
+};
+
+static struct platform_device z2_leds = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &z2_gpio_led_info,
+       }
+};
+
+static void __init z2_leds_init(void)
+{
+       platform_device_register(&z2_leds);
+}
+#else
+static inline void z2_leds_init(void) {}
+#endif
+
+/******************************************************************************
+ * GPIO keyboard
+ ******************************************************************************/
+#if defined(CONFIG_KEYBOARD_PXA27x) || defined(CONFIG_KEYBOARD_PXA27x_MODULE)
+static unsigned int z2_matrix_keys[] = {
+       KEY(0, 0, KEY_OPTION),
+       KEY(1, 0, KEY_UP),
+       KEY(2, 0, KEY_DOWN),
+       KEY(3, 0, KEY_LEFT),
+       KEY(4, 0, KEY_RIGHT),
+       KEY(5, 0, KEY_END),
+       KEY(6, 0, KEY_KPPLUS),
+
+       KEY(0, 1, KEY_HOME),
+       KEY(1, 1, KEY_Q),
+       KEY(2, 1, KEY_I),
+       KEY(3, 1, KEY_G),
+       KEY(4, 1, KEY_X),
+       KEY(5, 1, KEY_ENTER),
+       KEY(6, 1, KEY_KPMINUS),
+
+       KEY(0, 2, KEY_PAGEUP),
+       KEY(1, 2, KEY_W),
+       KEY(2, 2, KEY_O),
+       KEY(3, 2, KEY_H),
+       KEY(4, 2, KEY_C),
+       KEY(5, 2, KEY_LEFTALT),
+
+       KEY(0, 3, KEY_PAGEDOWN),
+       KEY(1, 3, KEY_E),
+       KEY(2, 3, KEY_P),
+       KEY(3, 3, KEY_J),
+       KEY(4, 3, KEY_V),
+       KEY(5, 3, KEY_LEFTSHIFT),
+
+       KEY(0, 4, KEY_ESC),
+       KEY(1, 4, KEY_R),
+       KEY(2, 4, KEY_A),
+       KEY(3, 4, KEY_K),
+       KEY(4, 4, KEY_B),
+       KEY(5, 4, KEY_LEFTCTRL),
+
+       KEY(0, 5, KEY_TAB),
+       KEY(1, 5, KEY_T),
+       KEY(2, 5, KEY_S),
+       KEY(3, 5, KEY_L),
+       KEY(4, 5, KEY_N),
+       KEY(5, 5, KEY_SPACE),
+
+       KEY(0, 6, KEY_STOPCD),
+       KEY(1, 6, KEY_Y),
+       KEY(2, 6, KEY_D),
+       KEY(3, 6, KEY_BACKSPACE),
+       KEY(4, 6, KEY_M),
+       KEY(5, 6, KEY_COMMA),
+
+       KEY(0, 7, KEY_PLAYCD),
+       KEY(1, 7, KEY_U),
+       KEY(2, 7, KEY_F),
+       KEY(3, 7, KEY_Z),
+       KEY(4, 7, KEY_SEMICOLON),
+       KEY(5, 7, KEY_DOT),
+};
+
+static struct pxa27x_keypad_platform_data z2_keypad_platform_data = {
+       .matrix_key_rows        = 7,
+       .matrix_key_cols        = 8,
+       .matrix_key_map         = z2_matrix_keys,
+       .matrix_key_map_size    = ARRAY_SIZE(z2_matrix_keys),
+
+       .debounce_interval      = 30,
+};
+
+static void __init z2_mkp_init(void)
+{
+       pxa_set_keypad_info(&z2_keypad_platform_data);
+}
+#else
+static inline void z2_mkp_init(void) {}
+#endif
+
+/******************************************************************************
+ * GPIO keys
+ ******************************************************************************/
+#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
+static struct gpio_keys_button z2_pxa_buttons[] = {
+       {KEY_POWER, GPIO1_ZIPITZ2_POWER_BUTTON, 0, "Power Button" },
+       {KEY_CLOSE, GPIO98_ZIPITZ2_LID_BUTTON, 0, "Lid Button" },
+};
+
+static struct gpio_keys_platform_data z2_pxa_keys_data = {
+       .buttons        = z2_pxa_buttons,
+       .nbuttons       = ARRAY_SIZE(z2_pxa_buttons),
+};
+
+static struct platform_device z2_pxa_keys = {
+       .name   = "gpio-keys",
+       .id     = -1,
+       .dev    = {
+               .platform_data = &z2_pxa_keys_data,
+       },
+};
+
+static void __init z2_keys_init(void)
+{
+       platform_device_register(&z2_pxa_keys);
+}
+#else
+static inline void z2_keys_init(void) {}
+#endif
+
+/******************************************************************************
+ * SSP Devices - WiFi and LCD control
+ ******************************************************************************/
+#if defined(CONFIG_SPI_PXA2XX) || defined(CONFIG_SPI_PXA2XX_MODULE)
+/* WiFi */
+static int z2_lbs_spi_setup(struct spi_device *spi)
+{
+       int ret = 0;
+
+       ret = gpio_request(GPIO15_ZIPITZ2_WIFI_POWER, "WiFi Power");
+       if (ret)
+               goto err;
+
+       ret = gpio_direction_output(GPIO15_ZIPITZ2_WIFI_POWER, 1);
+       if (ret)
+               goto err2;
+
+       ret = gpio_request(GPIO14_ZIPITZ2_WIFI_RESET, "WiFi Reset");
+       if (ret)
+               goto err2;
+
+       ret = gpio_direction_output(GPIO14_ZIPITZ2_WIFI_RESET, 0);
+       if (ret)
+               goto err3;
+
+       /* Reset the card */
+       mdelay(180);
+       gpio_set_value(GPIO14_ZIPITZ2_WIFI_RESET, 1);
+       mdelay(20);
+
+       spi->bits_per_word = 16;
+       spi->mode = SPI_MODE_2,
+
+       spi_setup(spi);
+
+       return 0;
+
+err3:
+       gpio_free(GPIO14_ZIPITZ2_WIFI_RESET);
+err2:
+       gpio_free(GPIO15_ZIPITZ2_WIFI_POWER);
+err:
+       return ret;
+};
+
+static int z2_lbs_spi_teardown(struct spi_device *spi)
+{
+       gpio_set_value(GPIO14_ZIPITZ2_WIFI_RESET, 0);
+       gpio_set_value(GPIO15_ZIPITZ2_WIFI_POWER, 0);
+       gpio_free(GPIO14_ZIPITZ2_WIFI_RESET);
+       gpio_free(GPIO15_ZIPITZ2_WIFI_POWER);
+       return 0;
+
+};
+
+static struct pxa2xx_spi_chip z2_lbs_chip_info = {
+       .rx_threshold   = 8,
+       .tx_threshold   = 8,
+       .timeout        = 1000,
+       .gpio_cs        = GPIO24_ZIPITZ2_WIFI_CS,
+};
+
+static struct libertas_spi_platform_data z2_lbs_pdata = {
+       .use_dummy_writes       = 1,
+       .setup                  = z2_lbs_spi_setup,
+       .teardown               = z2_lbs_spi_teardown,
+};
+
+/* LCD */
+static struct pxa2xx_spi_chip lms283_chip_info = {
+       .rx_threshold   = 1,
+       .tx_threshold   = 1,
+       .timeout        = 64,
+       .gpio_cs        = GPIO88_ZIPITZ2_LCD_CS,
+};
+
+static const struct lms283gf05_pdata lms283_pdata = {
+       .reset_gpio     = GPIO19_ZIPITZ2_LCD_RESET,
+};
+
+static struct spi_board_info spi_board_info[] __initdata = {
+{
+       .modalias               = "libertas_spi",
+       .platform_data          = &z2_lbs_pdata,
+       .controller_data        = &z2_lbs_chip_info,
+       .irq                    = gpio_to_irq(GPIO36_ZIPITZ2_WIFI_IRQ),
+       .max_speed_hz           = 13000000,
+       .bus_num                = 1,
+       .chip_select            = 0,
+},
+{
+       .modalias               = "lms283gf05",
+       .controller_data        = &lms283_chip_info,
+       .platform_data          = &lms283_pdata,
+       .max_speed_hz           = 400000,
+       .bus_num                = 2,
+       .chip_select            = 0,
+},
+};
+
+static struct pxa2xx_spi_master pxa_ssp1_master_info = {
+       .clock_enable   = CKEN_SSP,
+       .num_chipselect = 1,
+       .enable_dma     = 1,
+};
+
+static struct pxa2xx_spi_master pxa_ssp2_master_info = {
+       .clock_enable   = CKEN_SSP2,
+       .num_chipselect = 1,
+};
+
+static void __init z2_spi_init(void)
+{
+       pxa2xx_set_spi_info(1, &pxa_ssp1_master_info);
+       pxa2xx_set_spi_info(2, &pxa_ssp2_master_info);
+       spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
+}
+#else
+static inline void z2_spi_init(void) {}
+#endif
+
+/******************************************************************************
+ * Machine init
+ ******************************************************************************/
+static void __init z2_init(void)
+{
+       pxa2xx_mfp_config(ARRAY_AND_SIZE(z2_pin_config));
+
+       z2_lcd_init();
+       z2_mmc_init();
+       z2_mkp_init();
+
+       pxa_set_i2c_info(NULL);
+
+       z2_spi_init();
+       z2_nor_init();
+       z2_pwm_init();
+       z2_leds_init();
+       z2_keys_init();
+}
+
+MACHINE_START(ZIPIT2, "Zipit Z2")
+       .phys_io        = 0x40000000,
+       .boot_params    = 0xa0000100,
+       .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
+       .map_io         = pxa_map_io,
+       .init_irq       = pxa27x_init_irq,
+       .timer          = &pxa_timer,
+       .init_machine   = z2_init,
+MACHINE_END
index 39896d8..3680f6a 100644 (file)
@@ -644,7 +644,7 @@ static struct pxafb_mach_info zeus_fb_info = {
 
 static struct pxamci_platform_data zeus_mci_platform_data = {
        .ocr_mask               = MMC_VDD_32_33|MMC_VDD_33_34,
-       .detect_delay           = HZ/4,
+       .detect_delay_ms        = 250,
        .gpio_card_detect       = ZEUS_MMC_CD_GPIO,
        .gpio_card_ro           = ZEUS_MMC_WP_GPIO,
        .gpio_card_ro_invert    = 1,
index 2b4043c..c479cbe 100644 (file)
@@ -218,7 +218,7 @@ static inline void zylonite_init_lcd(void) {}
 
 #if defined(CONFIG_MMC)
 static struct pxamci_platform_data zylonite_mci_platform_data = {
-       .detect_delay   = 20,
+       .detect_delay_ms= 200,
        .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
        .gpio_card_detect = EXT_GPIO(0),
        .gpio_card_ro   = EXT_GPIO(2),
@@ -226,7 +226,7 @@ static struct pxamci_platform_data zylonite_mci_platform_data = {
 };
 
 static struct pxamci_platform_data zylonite_mci2_platform_data = {
-       .detect_delay   = 20,
+       .detect_delay_ms= 200,
        .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
        .gpio_card_detect = EXT_GPIO(1),
        .gpio_card_ro   = EXT_GPIO(3),
@@ -234,7 +234,7 @@ static struct pxamci_platform_data zylonite_mci2_platform_data = {
 };
 
 static struct pxamci_platform_data zylonite_mci3_platform_data = {
-       .detect_delay   = 20,
+       .detect_delay_ms= 200,
        .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
        .gpio_card_detect = EXT_GPIO(30),
        .gpio_card_ro   = EXT_GPIO(31),
index e704edb..a01b76b 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y                                  := core.o clock.o
+obj-y                                  := core.o
 obj-$(CONFIG_MACH_REALVIEW_EB)         += realview_eb.o
 obj-$(CONFIG_MACH_REALVIEW_PB11MP)     += realview_pb11mp.o
 obj-$(CONFIG_MACH_REALVIEW_PB1176)     += realview_pb1176.o
diff --git a/arch/arm/mach-realview/clock.c b/arch/arm/mach-realview/clock.c
deleted file mode 100644 (file)
index a704311..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- *  linux/arch/arm/mach-realview/clock.c
- *
- *  Copyright (C) 2004 ARM Limited.
- *  Written by Deep Blue Solutions Limited.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/device.h>
-#include <linux/list.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/string.h>
-#include <linux/clk.h>
-#include <linux/mutex.h>
-
-#include <asm/hardware/icst307.h>
-
-#include "clock.h"
-
-int clk_enable(struct clk *clk)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_enable);
-
-void clk_disable(struct clk *clk)
-{
-}
-EXPORT_SYMBOL(clk_disable);
-
-unsigned long clk_get_rate(struct clk *clk)
-{
-       return clk->rate;
-}
-EXPORT_SYMBOL(clk_get_rate);
-
-long clk_round_rate(struct clk *clk, unsigned long rate)
-{
-       struct icst307_vco vco;
-       vco = icst307_khz_to_vco(clk->params, rate / 1000);
-       return icst307_khz(clk->params, vco) * 1000;
-}
-EXPORT_SYMBOL(clk_round_rate);
-
-int clk_set_rate(struct clk *clk, unsigned long rate)
-{
-       int ret = -EIO;
-
-       if (clk->setvco) {
-               struct icst307_vco vco;
-
-               vco = icst307_khz_to_vco(clk->params, rate / 1000);
-               clk->rate = icst307_khz(clk->params, vco) * 1000;
-               clk->setvco(clk, vco);
-               ret = 0;
-       }
-       return ret;
-}
-EXPORT_SYMBOL(clk_set_rate);
diff --git a/arch/arm/mach-realview/clock.h b/arch/arm/mach-realview/clock.h
deleted file mode 100644 (file)
index ebbb0f0..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- *  linux/arch/arm/mach-realview/clock.h
- *
- *  Copyright (C) 2004 ARM Limited.
- *  Written by Deep Blue Solutions Limited.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-struct module;
-struct icst307_params;
-
-struct clk {
-       unsigned long           rate;
-       const struct icst307_params *params;
-       void                    *data;
-       void                    (*setvco)(struct clk *, struct icst307_vco vco);
-};
index d5a9573..595be19 100644 (file)
@@ -25,8 +25,6 @@
 #include <linux/interrupt.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/clcd.h>
-#include <linux/clocksource.h>
-#include <linux/clockchips.h>
 #include <linux/io.h>
 #include <linux/smsc911x.h>
 #include <linux/ata_platform.h>
@@ -40,7 +38,7 @@
 #include <asm/leds.h>
 #include <asm/mach-types.h>
 #include <asm/hardware/arm_timer.h>
-#include <asm/hardware/icst307.h>
+#include <asm/hardware/icst.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/flash.h>
 
 #include <asm/hardware/gic.h>
 
+#include <mach/clkdev.h>
 #include <mach/platform.h>
 #include <mach/irqs.h>
+#include <plat/timer-sp.h>
 
 #include "core.h"
-#include "clock.h"
-
-#define REALVIEW_REFCOUNTER    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
 
 /* used by entry-macro.S and platsmp.c */
 void __iomem *gic_cpu_base_addr;
@@ -79,20 +76,6 @@ void __init realview_adjust_zones(int node, unsigned long *size,
 }
 #endif
 
-/*
- * This is the RealView sched_clock implementation.  This has
- * a resolution of 41.7ns, and a maximum value of about 179s.
- */
-unsigned long long sched_clock(void)
-{
-       unsigned long long v;
-
-       v = (unsigned long long)readl(REALVIEW_REFCOUNTER) * 125;
-       do_div(v, 3);
-
-       return v;
-}
-
 
 #define REALVIEW_FLASHCTRL    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
 
@@ -274,37 +257,40 @@ struct mmci_platform_data realview_mmc1_plat_data = {
 /*
  * Clock handling
  */
-static const struct icst307_params realview_oscvco_params = {
-       .ref            = 24000,
-       .vco_max        = 200000,
+static const struct icst_params realview_oscvco_params = {
+       .ref            = 24000000,
+       .vco_max        = ICST307_VCO_MAX,
+       .vco_min        = ICST307_VCO_MIN,
        .vd_min         = 4 + 8,
        .vd_max         = 511 + 8,
        .rd_min         = 1 + 2,
        .rd_max         = 127 + 2,
+       .s2div          = icst307_s2div,
+       .idx2s          = icst307_idx2s,
 };
 
-static void realview_oscvco_set(struct clk *clk, struct icst307_vco vco)
+static void realview_oscvco_set(struct clk *clk, struct icst_vco vco)
 {
        void __iomem *sys_lock = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LOCK_OFFSET;
-       void __iomem *sys_osc;
        u32 val;
 
-       if (machine_is_realview_pb1176())
-               sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
-       else
-               sys_osc = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
-
-       val = readl(sys_osc) & ~0x7ffff;
+       val = readl(clk->vcoreg) & ~0x7ffff;
        val |= vco.v | (vco.r << 9) | (vco.s << 16);
 
        writel(0xa05f, sys_lock);
-       writel(val, sys_osc);
+       writel(val, clk->vcoreg);
        writel(0, sys_lock);
 }
 
+static const struct clk_ops oscvco_clk_ops = {
+       .round  = icst_clk_round,
+       .set    = icst_clk_set,
+       .setvco = realview_oscvco_set,
+};
+
 static struct clk oscvco_clk = {
+       .ops    = &oscvco_clk_ops,
        .params = &realview_oscvco_params,
-       .setvco = realview_oscvco_set,
 };
 
 /*
@@ -347,7 +333,13 @@ static struct clk_lookup lookups[] = {
 
 static int __init clk_init(void)
 {
+       if (machine_is_realview_pb1176())
+               oscvco_clk.vcoreg = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC0_OFFSET;
+       else
+               oscvco_clk.vcoreg = __io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_OSC4_OFFSET;
+
        clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return 0;
 }
 arch_initcall(clk_init);
@@ -643,133 +635,6 @@ void __iomem *timer1_va_base;
 void __iomem *timer2_va_base;
 void __iomem *timer3_va_base;
 
-/*
- * How long is the timer interval?
- */
-#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
-#if TIMER_INTERVAL >= 0x100000
-#define TIMER_RELOAD   (TIMER_INTERVAL >> 8)
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV256)
-#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
-#elif TIMER_INTERVAL >= 0x10000
-#define TIMER_RELOAD   (TIMER_INTERVAL >> 4)           /* Divide by 16 */
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV16)
-#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
-#else
-#define TIMER_RELOAD   (TIMER_INTERVAL)
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV1)
-#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
-#endif
-
-static void timer_set_mode(enum clock_event_mode mode,
-                          struct clock_event_device *clk)
-{
-       unsigned long ctrl;
-
-       switch(mode) {
-       case CLOCK_EVT_MODE_PERIODIC:
-               writel(TIMER_RELOAD, timer0_va_base + TIMER_LOAD);
-
-               ctrl = TIMER_CTRL_PERIODIC;
-               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
-               break;
-       case CLOCK_EVT_MODE_ONESHOT:
-               /* period set, and timer enabled in 'next_event' hook */
-               ctrl = TIMER_CTRL_ONESHOT;
-               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
-               break;
-       case CLOCK_EVT_MODE_UNUSED:
-       case CLOCK_EVT_MODE_SHUTDOWN:
-       default:
-               ctrl = 0;
-       }
-
-       writel(ctrl, timer0_va_base + TIMER_CTRL);
-}
-
-static int timer_set_next_event(unsigned long evt,
-                               struct clock_event_device *unused)
-{
-       unsigned long ctrl = readl(timer0_va_base + TIMER_CTRL);
-
-       writel(evt, timer0_va_base + TIMER_LOAD);
-       writel(ctrl | TIMER_CTRL_ENABLE, timer0_va_base + TIMER_CTRL);
-
-       return 0;
-}
-
-static struct clock_event_device timer0_clockevent =    {
-       .name           = "timer0",
-       .shift          = 32,
-       .features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
-       .set_mode       = timer_set_mode,
-       .set_next_event = timer_set_next_event,
-       .rating         = 300,
-       .cpumask        = cpu_all_mask,
-};
-
-static void __init realview_clockevents_init(unsigned int timer_irq)
-{
-       timer0_clockevent.irq = timer_irq;
-       timer0_clockevent.mult =
-               div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
-       timer0_clockevent.max_delta_ns =
-               clockevent_delta2ns(0xffffffff, &timer0_clockevent);
-       timer0_clockevent.min_delta_ns =
-               clockevent_delta2ns(0xf, &timer0_clockevent);
-
-       clockevents_register_device(&timer0_clockevent);
-}
-
-/*
- * IRQ handler for the timer
- */
-static irqreturn_t realview_timer_interrupt(int irq, void *dev_id)
-{
-       struct clock_event_device *evt = &timer0_clockevent;
-
-       /* clear the interrupt */
-       writel(1, timer0_va_base + TIMER_INTCLR);
-
-       evt->event_handler(evt);
-
-       return IRQ_HANDLED;
-}
-
-static struct irqaction realview_timer_irq = {
-       .name           = "RealView Timer Tick",
-       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
-       .handler        = realview_timer_interrupt,
-};
-
-static cycle_t realview_get_cycles(struct clocksource *cs)
-{
-       return ~readl(timer3_va_base + TIMER_VALUE);
-}
-
-static struct clocksource clocksource_realview = {
-       .name   = "timer3",
-       .rating = 200,
-       .read   = realview_get_cycles,
-       .mask   = CLOCKSOURCE_MASK(32),
-       .shift  = 20,
-       .flags  = CLOCK_SOURCE_IS_CONTINUOUS,
-};
-
-static void __init realview_clocksource_init(void)
-{
-       /* setup timer 0 as free-running clocksource */
-       writel(0, timer3_va_base + TIMER_CTRL);
-       writel(0xffffffff, timer3_va_base + TIMER_LOAD);
-       writel(0xffffffff, timer3_va_base + TIMER_VALUE);
-       writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
-               timer3_va_base + TIMER_CTRL);
-
-       clocksource_realview.mult =
-               clocksource_khz2mult(1000, clocksource_realview.shift);
-       clocksource_register(&clocksource_realview);
-}
-
 /*
  * Set up the clock source and clock events devices
  */
@@ -797,13 +662,8 @@ void __init realview_timer_init(unsigned int timer_irq)
        writel(0, timer2_va_base + TIMER_CTRL);
        writel(0, timer3_va_base + TIMER_CTRL);
 
-       /* 
-        * Make irqs happen for the system timer
-        */
-       setup_irq(timer_irq, &realview_timer_irq);
-
-       realview_clocksource_init();
-       realview_clockevents_init(timer_irq);
+       sp804_clocksource_init(timer3_va_base);
+       sp804_clockevents_init(timer0_va_base, timer_irq);
 }
 
 /*
index be048e3..f95521a 100644 (file)
@@ -131,7 +131,7 @@ void platform_cpu_die(unsigned int cpu)
        cpu_leave_lowpower();
 }
 
-int mach_cpu_disable(unsigned int cpu)
+int platform_cpu_disable(unsigned int cpu)
 {
        /*
         * we don't allow CPU 0 to be shutdown (it is still too special
index 04b37a8..e58d077 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef __ASM_MACH_CLKDEV_H
 #define __ASM_MACH_CLKDEV_H
 
+#include <plat/clock.h>
+
+struct clk {
+       unsigned long           rate;
+       const struct clk_ops    *ops;
+       const struct icst_params *params;
+       void __iomem            *vcoreg;
+};
+
 #define __clk_get(clk) ({ 1; })
 #define __clk_put(clk) do { } while (0)
 
index 2410d4f..830055b 100644 (file)
@@ -31,6 +31,7 @@
 #define IRQ_DC1176_SOFTINT     (IRQ_DC1176_GIC_START + 1)      /* Software interrupt */
 #define IRQ_DC1176_COMMRx      (IRQ_DC1176_GIC_START + 2)      /* Debug Comm Rx interrupt */
 #define IRQ_DC1176_COMMTx      (IRQ_DC1176_GIC_START + 3)      /* Debug Comm Tx interrupt */
+#define IRQ_DC1176_CORE_PMU    (IRQ_DC1176_GIC_START + 7)      /* Core PMU interrupt */
 #define IRQ_DC1176_TIMER0      (IRQ_DC1176_GIC_START + 8)      /* Timer 0 */
 #define IRQ_DC1176_TIMER1      (IRQ_DC1176_GIC_START + 9)      /* Timer 1 */
 #define IRQ_DC1176_TIMER2      (IRQ_DC1176_GIC_START + 10)     /* Timer 2 */
index 86792a9..4a88a4e 100644 (file)
 
 #define IRQ_PBA8_GIC_START                     32
 
-/* L220
-#define IRQ_PBA8_L220_EVENT    (IRQ_PBA8_GIC_START + 29)
-#define IRQ_PBA8_L220_SLAVE    (IRQ_PBA8_GIC_START + 30)
-#define IRQ_PBA8_L220_DECODE   (IRQ_PBA8_GIC_START + 31)
-*/
-
 /*
  * PB-A8 on-board gic irq sources
  */
@@ -65,6 +59,8 @@
 #define IRQ_PBA8_TSPEN         (IRQ_PBA8_GIC_START + 30)       /* Touchscreen pen */
 #define IRQ_PBA8_TSKPAD                (IRQ_PBA8_GIC_START + 31)       /* Touchscreen keypad */
 
+#define IRQ_PBA8_PMU           (IRQ_PBA8_GIC_START + 47)       /* Cortex-A8 PMU */
+
 /* ... */
 #define IRQ_PBA8_PCI0          (IRQ_PBA8_GIC_START + 50)
 #define IRQ_PBA8_PCI1          (IRQ_PBA8_GIC_START + 51)
index deaad43..206a300 100644 (file)
 
 #define IRQ_PBX_GIC_START                      32
 
-/* L220
-#define IRQ_PBX_L220_EVENT     (IRQ_PBX_GIC_START + 29)
-#define IRQ_PBX_L220_SLAVE     (IRQ_PBX_GIC_START + 30)
-#define IRQ_PBX_L220_DECODE    (IRQ_PBX_GIC_START + 31)
-*/
-
 /*
  * PBX on-board gic irq sources
  */
 #define IRQ_PBX_TIMER4_5        (IRQ_PBX_GIC_START + 41)        /* Timer 0/1 (default timer) */
 #define IRQ_PBX_TIMER6_7        (IRQ_PBX_GIC_START + 42)        /* Timer 2/3 */
 /* ... */
-#define IRQ_PBX_PMU_CPU3        (IRQ_PBX_GIC_START + 44)        /* CPU PMU Interrupts */
-#define IRQ_PBX_PMU_CPU2        (IRQ_PBX_GIC_START + 45)
-#define IRQ_PBX_PMU_CPU1        (IRQ_PBX_GIC_START + 46)
-#define IRQ_PBX_PMU_CPU0        (IRQ_PBX_GIC_START + 47)
+#define IRQ_PBX_PMU_CPU0        (IRQ_PBX_GIC_START + 44)        /* CPU PMU Interrupts */
+#define IRQ_PBX_PMU_CPU1        (IRQ_PBX_GIC_START + 45)
+#define IRQ_PBX_PMU_CPU2        (IRQ_PBX_GIC_START + 46)
+#define IRQ_PBX_PMU_CPU3        (IRQ_PBX_GIC_START + 47)
 
 /* ... */
 #define IRQ_PBX_PCI0           (IRQ_PBX_GIC_START + 50)
index 86c0c44..1b77a27 100644 (file)
 #define REALVIEW_INTREG_OFFSET         0x8     /* Interrupt control */
 #define REALVIEW_DECODE_OFFSET         0xC     /* Fitted logic modules */
 
-/* 
- *  Clean base - dummy
- * 
- */
-#define CLEAN_BASE                      REALVIEW_BOOT_ROM_HI
-
 /*
  * System controller bit assignment
  */
 #define REALVIEW_TIMER4_EnSel  21
 
 
-#define MAX_TIMER                       2
-#define MAX_PERIOD                      699050
-#define TICKS_PER_uSEC                  1
-
-/* 
- *  These are useconds NOT ticks.  
- * 
- */
-#define mSEC_1                          1000
-#define mSEC_5                          (mSEC_1 * 5)
-#define mSEC_10                         (mSEC_1 * 10)
-#define mSEC_25                         (mSEC_1 * 25)
-#define SEC_1                           (mSEC_1 * 1000)
-
 #define REALVIEW_CSR_BASE             0x10000000
 #define REALVIEW_CSR_SIZE             0x10000000
 
index 7d857d3..422ccd7 100644 (file)
@@ -31,8 +31,8 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/hardware/gic.h>
-#include <asm/hardware/icst307.h>
 #include <asm/hardware/cache-l2x0.h>
 #include <asm/localtimer.h>
 
@@ -44,7 +44,6 @@
 #include <mach/irqs.h>
 
 #include "core.h"
-#include "clock.h"
 
 static struct map_desc realview_eb_io_desc[] __initdata = {
        {
@@ -294,6 +293,36 @@ static struct resource realview_eb_isp1761_resources[] = {
        },
 };
 
+static struct resource pmu_resources[] = {
+       [0] = {
+               .start          = IRQ_EB11MP_PMU_CPU0,
+               .end            = IRQ_EB11MP_PMU_CPU0,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [1] = {
+               .start          = IRQ_EB11MP_PMU_CPU1,
+               .end            = IRQ_EB11MP_PMU_CPU1,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [2] = {
+               .start          = IRQ_EB11MP_PMU_CPU2,
+               .end            = IRQ_EB11MP_PMU_CPU2,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [3] = {
+               .start          = IRQ_EB11MP_PMU_CPU3,
+               .end            = IRQ_EB11MP_PMU_CPU3,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device pmu_device = {
+       .name                   = "arm-pmu",
+       .id                     = ARM_PMU_DEVICE_CPU,
+       .num_resources          = ARRAY_SIZE(pmu_resources),
+       .resource               = pmu_resources,
+};
+
 static void __init gic_init_irq(void)
 {
        if (core_tile_eb11mp() || core_tile_a9mp()) {
@@ -407,6 +436,7 @@ static void __init realview_eb_init(void)
                 * Bits:  .... ...0 0111 1001 0000 .... .... .... */
                l2x0_init(__io_address(REALVIEW_EB11MP_L220_BASE), 0x00790000, 0xfe000fff);
 #endif
+               platform_device_register(&pmu_device);
        }
 
        realview_flash_register(&realview_eb_flash_resource, 1);
index 44392e5..96568eb 100644 (file)
@@ -31,8 +31,8 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/hardware/gic.h>
-#include <asm/hardware/icst307.h>
 #include <asm/hardware/cache-l2x0.h>
 
 #include <asm/mach/arch.h>
@@ -44,7 +44,6 @@
 #include <mach/irqs.h>
 
 #include "core.h"
-#include "clock.h"
 
 static struct map_desc realview_pb1176_io_desc[] __initdata = {
        {
@@ -263,6 +262,19 @@ static struct resource realview_pb1176_isp1761_resources[] = {
        },
 };
 
+static struct resource pmu_resource = {
+       .start          = IRQ_DC1176_CORE_PMU,
+       .end            = IRQ_DC1176_CORE_PMU,
+       .flags          = IORESOURCE_IRQ,
+};
+
+static struct platform_device pmu_device = {
+       .name                   = "arm-pmu",
+       .id                     = ARM_PMU_DEVICE_CPU,
+       .num_resources          = 1,
+       .resource               = &pmu_resource,
+};
+
 static void __init gic_init_irq(void)
 {
        /* ARM1176 DevChip GIC, primary */
@@ -324,6 +336,7 @@ static void __init realview_pb1176_init(void)
        realview_eth_register(NULL, realview_pb1176_smsc911x_resources);
        platform_device_register(&realview_i2c_device);
        realview_usb_register(realview_pb1176_isp1761_resources);
+       platform_device_register(&pmu_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
                struct amba_device *d = amba_devs[i];
index 3e02731..7fbefbb 100644 (file)
@@ -31,8 +31,8 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/hardware/gic.h>
-#include <asm/hardware/icst307.h>
 #include <asm/hardware/cache-l2x0.h>
 #include <asm/localtimer.h>
 
@@ -45,7 +45,6 @@
 #include <mach/irqs.h>
 
 #include "core.h"
-#include "clock.h"
 
 static struct map_desc realview_pb11mp_io_desc[] __initdata = {
        {
@@ -260,6 +259,36 @@ static struct resource realview_pb11mp_isp1761_resources[] = {
        },
 };
 
+static struct resource pmu_resources[] = {
+       [0] = {
+               .start          = IRQ_TC11MP_PMU_CPU0,
+               .end            = IRQ_TC11MP_PMU_CPU0,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [1] = {
+               .start          = IRQ_TC11MP_PMU_CPU1,
+               .end            = IRQ_TC11MP_PMU_CPU1,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [2] = {
+               .start          = IRQ_TC11MP_PMU_CPU2,
+               .end            = IRQ_TC11MP_PMU_CPU2,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [3] = {
+               .start          = IRQ_TC11MP_PMU_CPU3,
+               .end            = IRQ_TC11MP_PMU_CPU3,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device pmu_device = {
+       .name                   = "arm-pmu",
+       .id                     = ARM_PMU_DEVICE_CPU,
+       .num_resources          = ARRAY_SIZE(pmu_resources),
+       .resource               = pmu_resources,
+};
+
 static void __init gic_init_irq(void)
 {
        unsigned int pldctrl;
@@ -329,6 +358,7 @@ static void __init realview_pb11mp_init(void)
        platform_device_register(&realview_i2c_device);
        platform_device_register(&realview_cf_device);
        realview_usb_register(realview_pb11mp_isp1761_resources);
+       platform_device_register(&pmu_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
                struct amba_device *d = amba_devs[i];
index fe4e25c..d3c113b 100644 (file)
@@ -30,8 +30,8 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/hardware/gic.h>
-#include <asm/hardware/icst307.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -42,7 +42,6 @@
 #include <mach/irqs.h>
 
 #include "core.h"
-#include "clock.h"
 
 static struct map_desc realview_pba8_io_desc[] __initdata = {
        {
@@ -250,6 +249,19 @@ static struct resource realview_pba8_isp1761_resources[] = {
        },
 };
 
+static struct resource pmu_resource = {
+       .start          = IRQ_PBA8_PMU,
+       .end            = IRQ_PBA8_PMU,
+       .flags          = IORESOURCE_IRQ,
+};
+
+static struct platform_device pmu_device = {
+       .name                   = "arm-pmu",
+       .id                     = ARM_PMU_DEVICE_CPU,
+       .num_resources          = 1,
+       .resource               = &pmu_resource,
+};
+
 static void __init gic_init_irq(void)
 {
        /* ARM PB-A8 on-board GIC */
@@ -296,6 +308,7 @@ static void __init realview_pba8_init(void)
        platform_device_register(&realview_i2c_device);
        platform_device_register(&realview_cf_device);
        realview_usb_register(realview_pba8_isp1761_resources);
+       platform_device_register(&pmu_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
                struct amba_device *d = amba_devs[i];
index d94857e..a235ba3 100644 (file)
@@ -29,6 +29,7 @@
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/mach-types.h>
+#include <asm/pmu.h>
 #include <asm/smp_twd.h>
 #include <asm/hardware/gic.h>
 #include <asm/hardware/cache-l2x0.h>
@@ -270,6 +271,36 @@ static struct resource realview_pbx_isp1761_resources[] = {
        },
 };
 
+static struct resource pmu_resources[] = {
+       [0] = {
+               .start          = IRQ_PBX_PMU_CPU0,
+               .end            = IRQ_PBX_PMU_CPU0,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [1] = {
+               .start          = IRQ_PBX_PMU_CPU1,
+               .end            = IRQ_PBX_PMU_CPU1,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [2] = {
+               .start          = IRQ_PBX_PMU_CPU2,
+               .end            = IRQ_PBX_PMU_CPU2,
+               .flags          = IORESOURCE_IRQ,
+       },
+       [3] = {
+               .start          = IRQ_PBX_PMU_CPU3,
+               .end            = IRQ_PBX_PMU_CPU3,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device pmu_device = {
+       .name                   = "arm-pmu",
+       .id                     = ARM_PMU_DEVICE_CPU,
+       .num_resources          = ARRAY_SIZE(pmu_resources),
+       .resource               = pmu_resources,
+};
+
 static void __init gic_init_irq(void)
 {
        /* ARM PBX on-board GIC */
@@ -354,6 +385,7 @@ static void __init realview_pbx_init(void)
                /* 16KB way size, 8-way associativity, parity disabled
                 * Bits:  .. 0 0 0 0 1 00 1 0 1 001 0 000 0 .... .... .... */
                l2x0_init(l2x0_base, 0x02520000, 0xc0000fff);
+               platform_device_register(&pmu_device);
        }
 #endif
 
index 5547318..7245a55 100644 (file)
@@ -6,6 +6,7 @@ config CPU_S3C2410
        bool
        depends on ARCH_S3C2410
        select CPU_ARM920T
+       select S3C_GPIO_PULL_UP
        select S3C2410_CLOCK
        select S3C2410_GPIO
        select CPU_LLSERIAL_S3C2410
@@ -76,6 +77,7 @@ config ARCH_H1940
        select PM_H1940 if PM
        select S3C_DEV_USB_HOST
        select S3C_DEV_NAND
+       select S3C2410_SETUP_TS
        help
          Say Y here if you are using the HP IPAQ H1940
 
@@ -95,12 +97,19 @@ config PM_H1940
 config MACH_N30
        bool "Acer N30 family"
        select CPU_S3C2410
+       select MACH_N35
        select S3C_DEV_USB_HOST
        select S3C_DEV_NAND
        help
          Say Y here if you want suppt for the Acer N30, Acer N35,
          Navman PiN570, Yakumo AlphaX or Airis NC05 PDAs.
 
+config MACH_N35
+       bool
+       help
+         Internal node in order to enable support for Acer N35 if Acer N30 is
+         selected.
+
 config ARCH_BAST
        bool "Simtec Electronics BAST (EB2410ITX)"
        select CPU_S3C2410
@@ -110,6 +119,7 @@ config ARCH_BAST
        select MACH_BAST_IDE
        select S3C24XX_DCLK
        select ISA
+       select S3C_DEV_HWMON
        select S3C_DEV_USB_HOST
        select S3C_DEV_NAND
        help
index 7dab2a0..58c1dd7 100644 (file)
@@ -1,3 +1,7 @@
-   zreladdr-y  := 0x30008000
-params_phys-y  := 0x30000100
-
+ifeq ($(CONFIG_PM_H1940),y)
+       zreladdr-y              := 0x30108000
+       params_phys-y   := 0x30100100
+else
+       zreladdr-y              := 0x30008000
+       params_phys-y   := 0x30000100
+endif
index a3f3c7b..8cdeb14 100644 (file)
@@ -33,14 +33,15 @@ static void h1940bt_enable(int on)
                h1940_latch_control(0, H1940_LATCH_BLUETOOTH_POWER);
                /* Reset the chip */
                mdelay(10);
-               s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
+
+               gpio_set_value(S3C2410_GPH(1), 1);
                mdelay(10);
-               s3c2410_gpio_setpin(S3C2410_GPH(1), 0);
+               gpio_set_value(S3C2410_GPH(1), 0);
        }
        else {
-               s3c2410_gpio_setpin(S3C2410_GPH(1), 1);
+               gpio_set_value(S3C2410_GPH(1), 1);
                mdelay(10);
-               s3c2410_gpio_setpin(S3C2410_GPH(1), 0);
+               gpio_set_value(S3C2410_GPH(1), 0);
                mdelay(10);
                h1940_latch_control(H1940_LATCH_BLUETOOTH_POWER, 0);
        }
@@ -61,15 +62,21 @@ static int __devinit h1940bt_probe(struct platform_device *pdev)
        struct rfkill *rfk;
        int ret = 0;
 
+       ret = gpio_request(S3C2410_GPH(1), dev_name(&pdev->dev));
+       if (ret) {
+               dev_err(&pdev->dev, "could not get GPH1\n");\
+               return ret;
+       }
+
        /* Configures BT serial port GPIOs */
-       s3c2410_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
-       s3c2410_gpio_pullup(S3C2410_GPH(0), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
-       s3c2410_gpio_pullup(S3C2410_GPH(1), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
-       s3c2410_gpio_pullup(S3C2410_GPH(2), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
-       s3c2410_gpio_pullup(S3C2410_GPH(3), 1);
+       s3c_gpio_cfgpin(S3C2410_GPH(0), S3C2410_GPH0_nCTS0);
+       s3c_gpio_cfgpull(S3C2410_GPH(0), S3C_GPIO_PULL_NONE);
+       s3c_gpio_cfgpin(S3C2410_GPH(1), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpull(S3C2410_GPH(1), S3C_GPIO_PULL_NONE);
+       s3c_gpio_cfgpin(S3C2410_GPH(2), S3C2410_GPH2_TXD0);
+       s3c_gpio_cfgpull(S3C2410_GPH(2), S3C_GPIO_PULL_NONE);
+       s3c_gpio_cfgpin(S3C2410_GPH(3), S3C2410_GPH3_RXD0);
+       s3c_gpio_cfgpull(S3C2410_GPH(3), S3C_GPIO_PULL_NONE);
 
 
        rfk = rfkill_alloc(DRV_NAME, &pdev->dev, RFKILL_TYPE_BLUETOOTH,
@@ -100,6 +107,7 @@ static int h1940bt_remove(struct platform_device *pdev)
        struct rfkill *rfk = platform_get_drvdata(pdev);
 
        platform_set_drvdata(pdev, NULL);
+       gpio_free(S3C2410_GPH(1));
 
        if (rfk) {
                rfkill_unregister(rfk);
index 08ac5f9..cf68136 100644 (file)
@@ -54,7 +54,7 @@ enum dma_ch {
 #define DMACH_LOW_LEVEL        (1<<28) /* use this to specifiy hardware ch no */
 
 /* we have 4 dma channels */
-#ifndef CONFIG_CPU_S3C2443
+#if !defined(CONFIG_CPU_S3C2443) && !defined(CONFIG_CPU_S3C2416)
 #define S3C_DMA_CHANNELS               (4)
 #else
 #define S3C_DMA_CHANNELS               (6)
index 035a493..f453c4f 100644 (file)
  * published by the Free Software Foundation.
 */
 
+#ifndef __MACH_GPIO_FNS_H
+#define __MACH_GPIO_FNS_H __FILE__
+
 /* These functions are in the to-be-removed category and it is strongly
  * encouraged not to use these in new code. They will be marked deprecated
  * very soon.
  *
  * Most of the functionality can be either replaced by the gpiocfg calls
  * for the s3c platform or by the generic GPIOlib API.
+ *
+ * As of 2.6.35-rc, these will be removed, with the few drivers using them
+ * either replaced or given a wrapper until the calls can be removed.
 */
 
+#include <plat/gpio-cfg.h>
+
+static inline void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int cfg)
+{
+       /* 1:1 mapping between cfgpin and setcfg calls at the moment */
+       s3c_gpio_cfgpin(pin, cfg);
+}
+
 /* external functions for GPIO support
  *
  * These allow various different clients to access the same GPIO
  * GPIO register, then it is safe to ioremap/__raw_{read|write} to it.
 */
 
-/* s3c2410_gpio_cfgpin
- *
- * set the configuration of the given pin to the value passed.
- *
- * eg:
- *    s3c2410_gpio_cfgpin(S3C2410_GPA(0), S3C2410_GPA0_ADDR0);
- *    s3c2410_gpio_cfgpin(S3C2410_GPE(8), S3C2410_GPE8_SDDAT1);
-*/
-
-extern void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function);
-
 extern unsigned int s3c2410_gpio_getcfg(unsigned int pin);
 
 /* s3c2410_gpio_getirq
@@ -71,6 +74,14 @@ extern int s3c2400_gpio_getirq(unsigned int pin);
 extern int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,
                                  unsigned int config);
 
+/* s3c2410_gpio_pullup
+ *
+ * This call should be replaced with s3c_gpio_setpull().
+ *
+ * As a note, there is currently no distinction between pull-up and pull-down
+ * in the s3c24xx series devices with only an on/off configuration.
+ */
+
 /* s3c2410_gpio_pullup
  *
  * configure the pull-up control on the given pin
@@ -86,18 +97,8 @@ extern int s3c2410_gpio_irqfilter(unsigned int pin, unsigned int on,
 
 extern void s3c2410_gpio_pullup(unsigned int pin, unsigned int to);
 
-/* s3c2410_gpio_getpull
- *
- * Read the state of the pull-up on a given pin
- *
- * return:
- *     < 0 => error code
- *       0 => enabled
- *       1 => disabled
-*/
-
-extern int s3c2410_gpio_getpull(unsigned int pin);
-
 extern void s3c2410_gpio_setpin(unsigned int pin, unsigned int to);
 
 extern unsigned int s3c2410_gpio_getpin(unsigned int pin);
+
+#endif /* __MACH_GPIO_FNS_H */
index 2edbb9c..4f7bf32 100644 (file)
 
 #define S3C2410_GPIONO(bank,offset) ((bank) + (offset))
 
-#define S3C2410_GPIO_BANKA   (32*0)
-#define S3C2410_GPIO_BANKB   (32*1)
-#define S3C2410_GPIO_BANKC   (32*2)
-#define S3C2410_GPIO_BANKD   (32*3)
-#define S3C2410_GPIO_BANKE   (32*4)
-#define S3C2410_GPIO_BANKF   (32*5)
 #define S3C2410_GPIO_BANKG   (32*6)
 #define S3C2410_GPIO_BANKH   (32*7)
 
+/* GPIO sizes for various SoCs:
+ *
+ *             2442
+ *   2410 2412 2440 2443 2416
+ *   ---- ---- ---- ---- ----
+ * A 23   22   25   16   25
+ * B 11   11   11   11   9
+ * C 16   15   16   16   16
+ * D 16   16   16   16   16
+ * E 16   16   16   16   16
+ * F 8    8    8    8    8
+ * G 16   16   16   16   8
+ * H 11   11   9    15   15
+ * J --   --   13   16   --
+ * K --   --   --   --   16
+ * L --   --   --   15   7
+ * M --   --   --   2    2
+ */
+
 /* GPIO bank sizes */
 #define S3C2410_GPIO_A_NR      (32)
 #define S3C2410_GPIO_B_NR      (32)
 #define S3C2410_GPIO_F_NR      (32)
 #define S3C2410_GPIO_G_NR      (32)
 #define S3C2410_GPIO_H_NR      (32)
+#define S3C2410_GPIO_J_NR      (32)    /* technically 16. */
+#define S3C2410_GPIO_K_NR      (32)    /* technically 16. */
+#define S3C2410_GPIO_L_NR      (32)    /* technically 15. */
+#define S3C2410_GPIO_M_NR      (32)    /* technically 2. */
 
 #if CONFIG_S3C_GPIO_SPACE != 0
 #error CONFIG_S3C_GPIO_SPACE cannot be zero at the moment
@@ -53,6 +70,10 @@ enum s3c_gpio_number {
        S3C2410_GPIO_F_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_E),
        S3C2410_GPIO_G_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_F),
        S3C2410_GPIO_H_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_G),
+       S3C2410_GPIO_J_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_H),
+       S3C2410_GPIO_K_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_J),
+       S3C2410_GPIO_L_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_K),
+       S3C2410_GPIO_M_START = S3C2410_GPIO_NEXT(S3C2410_GPIO_L),
 };
 
 #endif /* __ASSEMBLY__ */
@@ -67,6 +88,10 @@ enum s3c_gpio_number {
 #define S3C2410_GPF(_nr)       (S3C2410_GPIO_F_START + (_nr))
 #define S3C2410_GPG(_nr)       (S3C2410_GPIO_G_START + (_nr))
 #define S3C2410_GPH(_nr)       (S3C2410_GPIO_H_START + (_nr))
+#define S3C2410_GPJ(_nr)       (S3C2410_GPIO_J_START + (_nr))
+#define S3C2410_GPK(_nr)       (S3C2410_GPIO_K_START + (_nr))
+#define S3C2410_GPL(_nr)       (S3C2410_GPIO_L_START + (_nr))
+#define S3C2410_GPM(_nr)       (S3C2410_GPIO_M_START + (_nr))
 
 /* compatibility until drivers can be modified */
 
index acb2591..d67819d 100644 (file)
@@ -23,11 +23,11 @@ static inline struct s3c_gpio_chip *s3c_gpiolib_getchip(unsigned int pin)
 {
        struct s3c_gpio_chip *chip;
 
-       if (pin > S3C2410_GPG(10))
+       if (pin > S3C_GPIO_END)
                return NULL;
 
        chip = &s3c24xx_gpios[pin/32];
-       return (S3C2410_GPIO_OFFSET(pin) < chip->chip.ngpio) ? chip : NULL;
+       return ((pin - chip->chip.base) < chip->chip.ngpio) ? chip : NULL;
 }
 
 #endif /* __ASM_ARCH_GPIO_CORE_H */
index 15f0b3e..b649bf2 100644 (file)
  * devices that need GPIO.
  */
 
+#ifdef CONFIG_CPU_S3C244X
+#define ARCH_NR_GPIOS  (32 * 9 + CONFIG_S3C24XX_GPIO_EXTRA)
+#else
 #define ARCH_NR_GPIOS  (256 + CONFIG_S3C24XX_GPIO_EXTRA)
+#endif
 
 #include <asm-generic/gpio.h>
 #include <mach/gpio-nrs.h>
 #include <mach/gpio-fns.h>
 
+#ifdef CONFIG_CPU_S3C24XX
+#define S3C_GPIO_END   (S3C2410_GPIO_BANKJ + 32)
+#else
 #define S3C_GPIO_END   (S3C2410_GPIO_BANKH + 32)
+#endif
index 6c12c63..11bb0f0 100644 (file)
 #define IRQ_S3C2412_SDI                S3C2410_IRQSUB(13)
 #define IRQ_S3C2412_CF         S3C2410_IRQSUB(14)
 
+
+#define IRQ_S3C2416_EINT8t15   S3C2410_IRQ(5)
+#define IRQ_S3C2416_DMA                S3C2410_IRQ(17)
+#define IRQ_S3C2416_UART3      S3C2410_IRQ(18)
+#define IRQ_S3C2416_SDI1       S3C2410_IRQ(20)
+#define IRQ_S3C2416_SDI0       S3C2410_IRQ(21)
+
+#define IRQ_S3C2416_LCD2       S3C2410_IRQSUB(15)
+#define IRQ_S3C2416_LCD3       S3C2410_IRQSUB(16)
+#define IRQ_S3C2416_LCD4       S3C2410_IRQSUB(17)
+#define IRQ_S3C2416_DMA0       S3C2410_IRQSUB(18)
+#define IRQ_S3C2416_DMA1       S3C2410_IRQSUB(19)
+#define IRQ_S3C2416_DMA2       S3C2410_IRQSUB(20)
+#define IRQ_S3C2416_DMA3       S3C2410_IRQSUB(21)
+#define IRQ_S3C2416_DMA4       S3C2410_IRQSUB(22)
+#define IRQ_S3C2416_DMA5       S3C2410_IRQSUB(23)
+#define IRQ_S32416_WDT         S3C2410_IRQSUB(27)
+#define IRQ_S32416_AC97                S3C2410_IRQSUB(28)
+
+
 /* extra irqs for s3c2440 */
 
 #define IRQ_S3C2440_CAM_C      S3C2410_IRQSUB(11)      /* S3C2443 too */
 #define IRQ_S3C2443_HSMMC      S3C2410_IRQ(20)         /* IRQ_SDI */
 #define IRQ_S3C2443_NAND       S3C2410_IRQ(24)         /* reserved */
 
+#define IRQ_S3C2416_HSMMC0     S3C2410_IRQ(21)         /* S3C2416/S3C2450 */
+
 #define IRQ_HSMMC0             IRQ_S3C2443_HSMMC
+#define IRQ_HSMMC1             IRQ_S3C2416_HSMMC0
 
 #define IRQ_S3C2443_LCD1       S3C2410_IRQSUB(14)
 #define IRQ_S3C2443_LCD2       S3C2410_IRQSUB(15)
 #define IRQ_S3C2443_WDT                S3C2410_IRQSUB(27)
 #define IRQ_S3C2443_AC97       S3C2410_IRQSUB(28)
 
-#ifdef CONFIG_CPU_S3C2443
+#if defined(CONFIG_CPU_S3C2443) || defined(CONFIG_CPU_S3C2416)
 #define NR_IRQS (IRQ_S3C2443_AC97+1)
 #else
 #define NR_IRQS (IRQ_S3C2440_AC97+1)
 #define IRQ_S3CUART_TX3                IRQ_S3C2443_TX3
 #define IRQ_S3CUART_ERR3       IRQ_S3C2443_ERR3
 
+#define IRQ_LCD_VSYNC          IRQ_S3C2443_LCD3
+#define IRQ_LCD_SYSTEM         IRQ_S3C2443_LCD2
+
 #ifdef CONFIG_CPU_S3C2440
 #define IRQ_S3C244x_AC97 IRQ_S3C2440_AC97
 #else
index b049e61..091c98a 100644 (file)
 #define S3C2440_PA_AC97           (0x5B000000)
 #define S3C2440_SZ_AC97           SZ_1M
 
-/* S3C2443 High-speed SD/MMC */
+/* S3C2443/S3C2416 High-speed SD/MMC */
 #define S3C2443_PA_HSMMC   (0x4A800000)
-#define S3C2443_SZ_HSMMC   (256)
+#define S3C2416_PA_HSMMC0  (0x4AC00000)
+
+#define        S3C2443_PA_FB   (0x4C800000)
 
 /* S3C2412 memory and IO controls */
 #define S3C2412_PA_SSMC        (0x4F000000)
 #define S3C24XX_PA_SDI      S3C2410_PA_SDI
 #define S3C24XX_PA_NAND            S3C2410_PA_NAND
 
+#define S3C_PA_FB          S3C2443_PA_FB
 #define S3C_PA_IIC          S3C2410_PA_IIC
 #define S3C_PA_UART        S3C24XX_PA_UART
 #define S3C_PA_USBHOST S3C2410_PA_USBHOST
 #define S3C_PA_HSMMC0      S3C2443_PA_HSMMC
+#define S3C_PA_HSMMC1      S3C2416_PA_HSMMC0
 #define S3C_PA_NAND        S3C24XX_PA_NAND
 
 #endif /* __ASM_ARCH_MAP_H */
index 9a0d169..3415b60 100644 (file)
 
 #endif /* CONFIG_CPU_S3C2412 | CONFIG_CPU_S3C2413 */
 
+#define S3C2416_CLKDIV2                S3C2410_CLKREG(0x28)
+
 #endif /* __ASM_ARM_REGS_CLOCK */
index 3c3853c..98fd4a0 100644 (file)
 #define S3C2412_DSC1      S3C2410_GPIOREG(0xe0)
 #endif
 
+#if defined(CONFIG_CPU_S3C2416)
+#define S3C2416_DSC0      S3C2410_GPIOREG(0xc0)
+#define S3C2416_DSC1      S3C2410_GPIOREG(0xc4)
+#define S3C2416_DSC2      S3C2410_GPIOREG(0xc8)
+#define S3C2416_DSC3      S3C2410_GPIOREG(0x110)
+
+#define S3C2416_SELECT_DSC0    (0 << 30)
+#define S3C2416_SELECT_DSC1    (1 << 30)
+#define S3C2416_SELECT_DSC2    (2 << 30)
+#define S3C2416_SELECT_DSC3    (3 << 30)
+
+#define S3C2416_DSC_GETSHIFT(x)        (x & 30)
+
+#define S3C2416_DSC0_CF                (S3C2416_SELECT_DSC0 | 28)
+#define        S3C2416_DSC0_CF_5mA     (0 << 28)
+#define        S3C2416_DSC0_CF_10mA    (1 << 28)
+#define        S3C2416_DSC0_CF_15mA    (2 << 28)
+#define        S3C2416_DSC0_CF_21mA    (3 << 28)
+#define        S3C2416_DSC0_CF_MASK    (3 << 28)
+
+#define S3C2416_DSC0_nRBE      (S3C2416_SELECT_DSC0 | 26)
+#define        S3C2416_DSC0_nRBE_5mA   (0 << 26)
+#define        S3C2416_DSC0_nRBE_10mA  (1 << 26)
+#define        S3C2416_DSC0_nRBE_15mA  (2 << 26)
+#define        S3C2416_DSC0_nRBE_21mA  (3 << 26)
+#define        S3C2416_DSC0_nRBE_MASK  (3 << 26)
+
+#define S3C2416_DSC0_nROE      (S3C2416_SELECT_DSC0 | 24)
+#define        S3C2416_DSC0_nROE_5mA   (0 << 24)
+#define        S3C2416_DSC0_nROE_10mA  (1 << 24)
+#define        S3C2416_DSC0_nROE_15mA  (2 << 24)
+#define        S3C2416_DSC0_nROE_21mA  (3 << 24)
+#define        S3C2416_DSC0_nROE_MASK  (3 << 24)
+
+#endif
+
 #if defined(CONFIG_CPU_S3C244X)
 
 #define S3C2440_DSC0      S3C2410_GPIOREG(0xc4)
index fd672f3..a0a89d4 100644 (file)
 #include <mach/gpio-nrs.h>
 
 #ifdef CONFIG_CPU_S3C2400
-#define S3C24XX_GPIO_BASE(x)  S3C2400_GPIO_BASE(x)
-#define S3C24XX_MISCCR        S3C2400_MISCCR
+#define S3C24XX_MISCCR         S3C2400_MISCCR
 #else
-#define S3C24XX_GPIO_BASE(x)  S3C2410_GPIO_BASE(x)
-#define S3C24XX_MISCCR       S3C24XX_GPIOREG2(0x80)
+#define S3C24XX_MISCCR         S3C24XX_GPIOREG2(0x80)
 #endif /* CONFIG_CPU_S3C2400 */
 
-
-/* S3C2400 doesn't have a 1:1 mapping to S3C2410 gpio base pins */
-
-#define S3C2400_BANKNUM(pin)     (((pin) & ~31) / 32)
-#define S3C2400_BASEA2B(pin)     ((((pin) & ~31) >> 2))
-#define S3C2400_BASEC2H(pin)     ((S3C2400_BANKNUM(pin) * 10) + \
-                                 (2 * (S3C2400_BANKNUM(pin)-2)))
-
-#define S3C2400_GPIO_BASE(pin)   (pin < S3C2410_GPIO_BANKC ? \
-                                 S3C2400_BASEA2B(pin)+S3C24XX_VA_GPIO : \
-                                 S3C2400_BASEC2H(pin)+S3C24XX_VA_GPIO)
-
-
-#define S3C2410_GPIO_BASE(pin)   ((((pin) & ~31) >> 1) + S3C24XX_VA_GPIO)
-#define S3C2410_GPIO_OFFSET(pin) ((pin) & 31)
-
 /* general configuration options */
 
 #define S3C2410_GPIO_LEAVE   (0xFFFFFFFF)
 #define S3C2410_GPHUP     S3C2410_GPIOREG(0x78)
 
 #define S3C2410_GPH0_nCTS0  (0x02 << 0)
+#define S3C2416_GPH0_TXD0  (0x02 << 0)
 
 #define S3C2410_GPH1_nRTS0  (0x02 << 2)
+#define S3C2416_GPH1_RXD0  (0x02 << 2)
 
 #define S3C2410_GPH2_TXD0   (0x02 << 4)
+#define S3C2416_GPH2_TXD1   (0x02 << 4)
 
 #define S3C2410_GPH3_RXD0   (0x02 << 6)
+#define S3C2416_GPH3_RXD1   (0x02 << 6)
 
 #define S3C2410_GPH4_TXD1   (0x02 << 8)
+#define S3C2416_GPH4_TXD2   (0x02 << 8)
 
 #define S3C2410_GPH5_RXD1   (0x02 << 10)
+#define S3C2416_GPH5_RXD2   (0x02 << 10)
 
 #define S3C2410_GPH6_TXD2   (0x02 << 12)
+#define S3C2416_GPH6_TXD3   (0x02 << 12)
 #define S3C2410_GPH6_nRTS1  (0x03 << 12)
+#define S3C2416_GPH6_nRTS2  (0x03 << 12)
 
 #define S3C2410_GPH7_RXD2   (0x02 << 14)
+#define S3C2416_GPH7_RXD3   (0x02 << 14)
 #define S3C2410_GPH7_nCTS1  (0x03 << 14)
+#define S3C2416_GPH7_nCTS2  (0x03 << 14)
 
 #define S3C2410_GPH8_UCLK   (0x02 << 16)
+#define S3C2416_GPH8_nCTS0  (0x02 << 16)
 
 #define S3C2410_GPH9_CLKOUT0  (0x02 << 18)
 #define S3C2442_GPH9_nSPICS0  (0x03 << 18)
+#define S3C2416_GPH9_nRTS0    (0x02 << 18)
 
 #define S3C2410_GPH10_CLKOUT1 (0x02 << 20)
+#define S3C2416_GPH10_nCTS1   (0x02 << 20)
+
+#define S3C2416_GPH11_nRTS1   (0x02 << 22)
+
+#define S3C2416_GPH12_EXTUARTCLK (0x02 << 24)
+
+#define S3C2416_GPH13_CLKOUT0 (0x02 << 26)
+
+#define S3C2416_GPH14_CLKOUT1 (0x02 << 28)
 
 /* The S3C2412 and S3C2413 move the GPJ register set to after
  * GPH, which means all registers after 0x80 are now offset by 0x10
  * for the 2412/2413 from the 2410/2440/2442
 */
 
+/* S3C2443 and above */
+#define S3C2440_GPJCON    S3C2410_GPIOREG(0xD0)
+#define S3C2440_GPJDAT    S3C2410_GPIOREG(0xD4)
+#define S3C2440_GPJUP     S3C2410_GPIOREG(0xD8)
+
+#define S3C2443_GPKCON    S3C2410_GPIOREG(0xE0)
+#define S3C2443_GPKDAT    S3C2410_GPIOREG(0xE4)
+#define S3C2443_GPKUP     S3C2410_GPIOREG(0xE8)
+
+#define S3C2443_GPLCON    S3C2410_GPIOREG(0xF0)
+#define S3C2443_GPLDAT    S3C2410_GPIOREG(0xF4)
+#define S3C2443_GPLUP     S3C2410_GPIOREG(0xF8)
+
+#define S3C2443_GPMCON    S3C2410_GPIOREG(0x100)
+#define S3C2443_GPMDAT    S3C2410_GPIOREG(0x104)
+#define S3C2443_GPMUP     S3C2410_GPIOREG(0x108)
+
 /* miscellaneous control */
 #define S3C2400_MISCCR    S3C2410_GPIOREG(0x54)
 #define S3C2410_MISCCR    S3C2410_GPIOREG(0x80)
 #define S3C2412_MISCCR_CLK1_CLKsrc  (0<<8)
 
 #define S3C2410_MISCCR_USBSUSPND0   (1<<12)
+#define S3C2416_MISCCR_SEL_SUSPND   (1<<12)
 #define S3C2410_MISCCR_USBSUSPND1   (1<<13)
 
 #define S3C2410_MISCCR_nRSTCON     (1<<16)
 #define S3C2410_MISCCR_nEN_SCLKE    (1<<19)    /* not 2412 */
 #define S3C2410_MISCCR_SDSLEEP     (7<<17)
 
+#define S3C2416_MISCCR_FLT_I2C      (1<<24)
+#define S3C2416_MISCCR_HSSPI_EN2    (1<<31)
+
 /* external interrupt control... */
 /* S3C2410_EXTINT0 -> irq sense control for EINT0..EINT7
  * S3C2410_EXTINT1 -> irq sense control for EINT8..EINT15
 #define S3C2410_GSTATUS1_IDMASK           (0xffff0000)
 #define S3C2410_GSTATUS1_2410     (0x32410000)
 #define S3C2410_GSTATUS1_2412     (0x32412001)
+#define S3C2410_GSTATUS1_2416     (0x32416003)
 #define S3C2410_GSTATUS1_2440     (0x32440000)
 #define S3C2410_GSTATUS1_2442     (0x32440aaa)
+/* some 2416 CPUs report this value also */
+#define S3C2410_GSTATUS1_2450     (0x32450003)
 
 #define S3C2410_GSTATUS2_WTRESET   (1<<2)
 #define S3C2410_GSTATUS2_OFFRESET  (1<<1)
index 1202ca5..19575e0 100644 (file)
  * pull up works like all other ports.
 */
 
-#define S3C2440_GPIO_BANKJ  (416)
-
-#define S3C2440_GPJCON     S3C2410_GPIOREG(0xd0)
-#define S3C2440_GPJDAT     S3C2410_GPIOREG(0xd4)
-#define S3C2440_GPJUP      S3C2410_GPIOREG(0xd8)
-
 #define S3C2413_GPJCON         S3C2410_GPIOREG(0x80)
 #define S3C2413_GPJDAT         S3C2410_GPIOREG(0x84)
 #define S3C2413_GPJUP          S3C2410_GPIOREG(0x88)
 #define S3C2413_GPJSLPCON      S3C2410_GPIOREG(0x8C)
 
-#define S3C2440_GPJ0            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 0)
-#define S3C2440_GPJ0_INP        (0x00 << 0)
 #define S3C2440_GPJ0_OUTP       (0x01 << 0)
 #define S3C2440_GPJ0_CAMDATA0   (0x02 << 0)
 
-#define S3C2440_GPJ1            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 1)
-#define S3C2440_GPJ1_INP        (0x00 << 2)
 #define S3C2440_GPJ1_OUTP       (0x01 << 2)
 #define S3C2440_GPJ1_CAMDATA1   (0x02 << 2)
 
-#define S3C2440_GPJ2            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 2)
-#define S3C2440_GPJ2_INP        (0x00 << 4)
 #define S3C2440_GPJ2_OUTP       (0x01 << 4)
 #define S3C2440_GPJ2_CAMDATA2   (0x02 << 4)
 
-#define S3C2440_GPJ3            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 3)
-#define S3C2440_GPJ3_INP        (0x00 << 6)
 #define S3C2440_GPJ3_OUTP       (0x01 << 6)
 #define S3C2440_GPJ3_CAMDATA3   (0x02 << 6)
 
-#define S3C2440_GPJ4            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 4)
-#define S3C2440_GPJ4_INP        (0x00 << 8)
 #define S3C2440_GPJ4_OUTP       (0x01 << 8)
 #define S3C2440_GPJ4_CAMDATA4   (0x02 << 8)
 
-#define S3C2440_GPJ5            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 5)
-#define S3C2440_GPJ5_INP        (0x00 << 10)
 #define S3C2440_GPJ5_OUTP       (0x01 << 10)
 #define S3C2440_GPJ5_CAMDATA5   (0x02 << 10)
 
-#define S3C2440_GPJ6            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 6)
-#define S3C2440_GPJ6_INP        (0x00 << 12)
 #define S3C2440_GPJ6_OUTP       (0x01 << 12)
 #define S3C2440_GPJ6_CAMDATA6   (0x02 << 12)
 
-#define S3C2440_GPJ7            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 7)
-#define S3C2440_GPJ7_INP        (0x00 << 14)
 #define S3C2440_GPJ7_OUTP       (0x01 << 14)
 #define S3C2440_GPJ7_CAMDATA7   (0x02 << 14)
 
-#define S3C2440_GPJ8            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 8)
-#define S3C2440_GPJ8_INP        (0x00 << 16)
 #define S3C2440_GPJ8_OUTP       (0x01 << 16)
 #define S3C2440_GPJ8_CAMPCLK    (0x02 << 16)
 
-#define S3C2440_GPJ9            S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 9)
-#define S3C2440_GPJ9_INP        (0x00 << 18)
 #define S3C2440_GPJ9_OUTP       (0x01 << 18)
 #define S3C2440_GPJ9_CAMVSYNC   (0x02 << 18)
 
-#define S3C2440_GPJ10           S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 10)
-#define S3C2440_GPJ10_INP       (0x00 << 20)
 #define S3C2440_GPJ10_OUTP      (0x01 << 20)
 #define S3C2440_GPJ10_CAMHREF   (0x02 << 20)
 
-#define S3C2440_GPJ11           S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 11)
-#define S3C2440_GPJ11_INP       (0x00 << 22)
 #define S3C2440_GPJ11_OUTP      (0x01 << 22)
 #define S3C2440_GPJ11_CAMCLKOUT (0x02 << 22)
 
-#define S3C2440_GPJ12           S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 12)
-#define S3C2440_GPJ12_INP       (0x00 << 24)
 #define S3C2440_GPJ12_OUTP      (0x01 << 24)
 #define S3C2440_GPJ12_CAMRESET  (0x02 << 24)
 
-#define S3C2443_GPJ13          S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 13)
-#define S3C2443_GPJ14          S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 14)
-#define S3C2443_GPJ15          S3C2410_GPIONO(S3C2440_GPIO_BANKJ, 15)
-
 #endif /* __ASM_ARCH_REGS_GPIOJ_H */
 
index de86ee8..0f07ba3 100644 (file)
 #define S3C2410_SUBSRCPND      S3C2410_IRQREG(0x018)
 #define S3C2410_INTSUBMSK      S3C2410_IRQREG(0x01C)
 
+#define S3C2416_PRIORITY_MODE1         S3C2410_IRQREG(0x030)
+#define S3C2416_PRIORITY_UPDATE1       S3C2410_IRQREG(0x034)
+#define S3C2416_SRCPND2                        S3C2410_IRQREG(0x040)
+#define S3C2416_INTMOD2                        S3C2410_IRQREG(0x044)
+#define S3C2416_INTMSK2                        S3C2410_IRQREG(0x048)
+#define S3C2416_INTPND2                        S3C2410_IRQREG(0x050)
+#define S3C2416_INTOFFSET2             S3C2410_IRQREG(0x054)
+#define S3C2416_PRIORITY_MODE2         S3C2410_IRQREG(0x070)
+#define S3C2416_PRIORITY_UPDATE2       S3C2410_IRQREG(0x074)
+
 /* mask: 0=enable, 1=disable
  * 1 bit EINT, 4=EINT4, 23=EINT23
  * EINT0,1,2,3 are not handled here.
diff --git a/arch/arm/mach-s3c2410/include/mach/regs-s3c2416-mem.h b/arch/arm/mach-s3c2410/include/mach/regs-s3c2416-mem.h
new file mode 100644 (file)
index 0000000..2f31b74
--- /dev/null
@@ -0,0 +1,30 @@
+/* arch/arm/mach-s3c2410/include/mach/regs-s3c2416-mem.h
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
+ *     as part of OpenInkpot project
+ * Copyright (c) 2009 Promwad Innovation Company
+ *     Yauhen Kharuzhy <yauhen.kharuzhy@promwad.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * S3C2416 memory register definitions
+*/
+
+#ifndef __ASM_ARM_REGS_S3C2416_MEM
+#define __ASM_ARM_REGS_S3C2416_MEM
+
+#ifndef S3C2416_MEMREG
+#define S3C2416_MEMREG(x) (S3C24XX_VA_MEMCTRL + (x))
+#endif
+
+#define S3C2416_BANKCFG                        S3C2416_MEMREG(0x00)
+#define S3C2416_BANKCON1               S3C2416_MEMREG(0x04)
+#define S3C2416_BANKCON2               S3C2416_MEMREG(0x08)
+#define S3C2416_BANKCON3               S3C2416_MEMREG(0x0C)
+
+#define S3C2416_REFRESH                        S3C2416_MEMREG(0x10)
+#define S3C2416_TIMEOUT                        S3C2416_MEMREG(0x14)
+
+#endif /*  __ASM_ARM_REGS_S3C2416_MEM */
diff --git a/arch/arm/mach-s3c2410/include/mach/regs-s3c2416.h b/arch/arm/mach-s3c2410/include/mach/regs-s3c2416.h
new file mode 100644 (file)
index 0000000..e443167
--- /dev/null
@@ -0,0 +1,24 @@
+/* arch/arm/mach-s3c2410/include/mach/regs-s3c2416.h
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
+ *     as part of OpenInkpot project
+ * Copyright (c) 2009 Promwad Innovation Company
+ *     Yauhen Kharuzhy <yauhen.kharuzhy@promwad.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * S3C2416 specific register definitions
+*/
+
+#ifndef __ASM_ARCH_REGS_S3C2416_H
+#define __ASM_ARCH_REGS_S3C2416_H "s3c2416"
+
+#define S3C2416_SWRST          (S3C24XX_VA_CLKPWR + 0x44)
+#define S3C2416_SWRST_RESET    (0x533C2416)
+
+/* see regs-power.h for the other registers in the power block. */
+
+#endif /* __ASM_ARCH_REGS_S3C2416_H */
+
index d87ebe0..08ab9df 100644 (file)
@@ -83,8 +83,7 @@
 #define S3C2443_HCLKCON_DMA4           (1<<4)
 #define S3C2443_HCLKCON_DMA5           (1<<5)
 #define S3C2443_HCLKCON_CAMIF          (1<<8)
-#define S3C2443_HCLKCON_DISP           (1<<9)
-#define S3C2443_HCLKCON_LCDC           (1<<10)
+#define S3C2443_HCLKCON_LCDC           (1<<9)
 #define S3C2443_HCLKCON_USBH           (1<<11)
 #define S3C2443_HCLKCON_USBD           (1<<12)
 #define S3C2443_HCLKCON_HSMMC          (1<<16)
index 72f756c..8b283f8 100644 (file)
@@ -40,7 +40,9 @@ static void arch_detect_cpu(void)
        cpuid &= S3C2410_GSTATUS1_IDMASK;
 
        if (is_arm926() || cpuid == S3C2410_GSTATUS1_2440 ||
-           cpuid == S3C2410_GSTATUS1_2442) {
+           cpuid == S3C2410_GSTATUS1_2442 ||
+           cpuid == S3C2410_GSTATUS1_2416 ||
+           cpuid == S3C2410_GSTATUS1_2450) {
                fifo_mask = S3C2440_UFSTAT_TXMASK;
                fifo_max = 63 << S3C2440_UFSTAT_TXSHIFT;
        } else {
index 7047317..34fc05a 100644 (file)
@@ -56,6 +56,7 @@
 #include <plat/iic.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
+#include <plat/gpio-cfg.h>
 
 #ifdef CONFIG_MTD_PARTITIONS
 
@@ -225,8 +226,8 @@ static void amlm5900_init_pm(void)
        } else {
                enable_irq_wake(IRQ_EINT9);
                /* configure the suspend/resume status pin */
-               s3c2410_gpio_cfgpin(S3C2410_GPF(2), S3C2410_GPIO_OUTPUT);
-               s3c2410_gpio_pullup(S3C2410_GPF(2), 0);
+               s3c_gpio_cfgpin(S3C2410_GPF(2), S3C2410_GPIO_OUTPUT);
+               s3c_gpio_setpull(S3C2410_GPF(2), S3C_GPIO_PULL_UP);
        }
 }
 static void __init amlm5900_init(void)
index 02b1b62..c1f90f6 100644 (file)
@@ -61,6 +61,7 @@
 #include <plat/devs.h>
 #include <plat/cpu.h>
 #include <plat/cpu-freq.h>
+#include <plat/gpio-cfg.h>
 #include <plat/audio-simtec.h>
 
 #include "usb-simtec.h"
@@ -216,15 +217,13 @@ static struct s3c2410_uartcfg bast_uartcfgs[] __initdata = {
 static int bast_pm_suspend(struct sys_device *sd, pm_message_t state)
 {
        /* ensure that an nRESET is not generated on resume. */
-       s3c2410_gpio_setpin(S3C2410_GPA(21), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPIO_OUTPUT);
-
+       gpio_direction_output(S3C2410_GPA(21), 1);
        return 0;
 }
 
 static int bast_pm_resume(struct sys_device *sd)
 {
-       s3c2410_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPA21_nRSTOUT);
+       s3c_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPA21_nRSTOUT);
        return 0;
 }
 
@@ -634,7 +633,7 @@ static void __init bast_map_io(void)
 
        s3c24xx_register_clocks(bast_clocks, ARRAY_SIZE(bast_clocks));
 
-       s3c_device_hwmon.dev.platform_data = &bast_hwmon_info;
+       s3c_hwmon_set_platdata(&bast_hwmon_info);
 
        s3c24xx_init_io(bast_iodesc, ARRAY_SIZE(bast_iodesc));
        s3c24xx_init_clocks(0);
@@ -658,6 +657,8 @@ static void __init bast_init(void)
        nor_simtec_init();
        simtec_audio_add(NULL, true, &bast_audio);
 
+       WARN_ON(gpio_request(S3C2410_GPA(21), "bast nreset"));
+       
        s3c_cpufreq_setboard(&bast_cpufreq);
 }
 
index fbedd07..779b45b 100644 (file)
 #include <mach/h1940.h>
 #include <mach/h1940-latch.h>
 #include <mach/fb.h>
-#include <mach/ts.h>
 #include <plat/udc.h>
 #include <plat/iic.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/clock.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
 #include <plat/pll.h>
 #include <plat/pm.h>
 #include <plat/mci.h>
+#include <plat/ts.h>
 
 static struct map_desc h1940_iodesc[] __initdata = {
        [0] = {
@@ -145,6 +146,7 @@ static struct s3c2410_ts_mach_info h1940_ts_cfg __initdata = {
                .delay = 10000,
                .presc = 49,
                .oversampling_shift = 2,
+               .cfg_gpio = s3c24xx_ts_cfg_gpio,
 };
 
 /**
@@ -162,8 +164,8 @@ static struct s3c2410fb_display h1940_lcd __initdata = {
        .xres =         240,
        .yres =         320,
        .bpp =          16,
-       .left_margin =  20,
-       .right_margin = 8,
+       .left_margin =  8,
+       .right_margin = 20,
        .hsync_len =    4,
        .upper_margin = 8,
        .lower_margin = 7,
@@ -207,16 +209,16 @@ static int h1940_backlight_init(struct device *dev)
 {
        gpio_request(S3C2410_GPB(0), "Backlight");
 
-       s3c2410_gpio_setpin(S3C2410_GPB(0), 0);
-       s3c2410_gpio_pullup(S3C2410_GPB(0), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
+       gpio_direction_output(S3C2410_GPB(0), 0);
+       s3c_gpio_setpull(S3C2410_GPB(0), S3C_GPIO_PULL_NONE);
+       s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
 
        return 0;
 }
 
 static void h1940_backlight_exit(struct device *dev)
 {
-       s3c2410_gpio_cfgpin(S3C2410_GPB(0), 1/*S3C2410_GPB0_OUTP*/);
+       gpio_direction_output(S3C2410_GPB(0), 1);
 }
 
 static struct platform_pwm_backlight_data backlight_data = {
@@ -245,18 +247,18 @@ static void h1940_lcd_power_set(struct plat_lcd_data *pd,
 
        if (!power) {
                /* set to 3ec */
-               s3c2410_gpio_setpin(S3C2410_GPC(0), 0);
+               gpio_direction_output(S3C2410_GPC(0), 0);
                /* wait for 3ac */
                do {
-                       value = s3c2410_gpio_getpin(S3C2410_GPC(6));
+                       value = gpio_get_value(S3C2410_GPC(6));
                } while (value);
                /* set to 38c */
-               s3c2410_gpio_setpin(S3C2410_GPC(5), 0);
+               gpio_direction_output(S3C2410_GPC(5), 0);
        } else {
                /* Set to 3ac */
-               s3c2410_gpio_setpin(S3C2410_GPC(5), 1);
+               gpio_direction_output(S3C2410_GPC(5), 1);
                /* Set to 3ad */
-               s3c2410_gpio_setpin(S3C2410_GPC(0), 1);
+               gpio_direction_output(S3C2410_GPC(0), 1);
        }
 }
 
@@ -271,7 +273,6 @@ static struct platform_device h1940_lcd_powerdev = {
 };
 
 static struct platform_device *h1940_devices[] __initdata = {
-       &s3c_device_ts,
        &s3c_device_ohci,
        &s3c_device_lcd,
        &s3c_device_wdt,
@@ -285,6 +286,8 @@ static struct platform_device *h1940_devices[] __initdata = {
        &s3c_device_timer[0],
        &h1940_backlight,
        &h1940_lcd_powerdev,
+       &s3c_device_adc,
+       &s3c_device_ts,
 };
 
 static void __init h1940_map_io(void)
@@ -332,12 +335,13 @@ static void __init h1940_init(void)
        gpio_request(S3C2410_GPC(5), "LCD power");
        gpio_request(S3C2410_GPC(6), "LCD power");
 
+       gpio_direction_input(S3C2410_GPC(6));
 
        platform_add_devices(h1940_devices, ARRAY_SIZE(h1940_devices));
 }
 
 MACHINE_START(H1940, "IPAQ-H1940")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
index 684710f..41f299d 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/serial_core.h>
 #include <linux/timer.h>
 #include <linux/io.h>
+#include <linux/mmc/host.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>
@@ -46,6 +47,7 @@
 #include <plat/clock.h>
 #include <plat/cpu.h>
 #include <plat/devs.h>
+#include <plat/mci.h>
 #include <plat/s3c2410.h>
 #include <plat/udc.h>
 
@@ -86,10 +88,10 @@ static void n30_udc_pullup(enum s3c2410_udc_cmd_e cmd)
 {
        switch (cmd) {
        case S3C2410_UDC_P_ENABLE :
-               s3c2410_gpio_setpin(S3C2410_GPB(3), 1);
+               gpio_set_value(S3C2410_GPB(3), 1);
                break;
        case S3C2410_UDC_P_DISABLE :
-               s3c2410_gpio_setpin(S3C2410_GPB(3), 0);
+               gpio_set_value(S3C2410_GPB(3), 0);
                break;
        case S3C2410_UDC_P_RESET :
                break;
@@ -172,8 +174,10 @@ static struct gpio_keys_button n35_buttons[] = {
        {
                .gpio           = S3C2410_GPF(0),
                .code           = KEY_POWER,
+               .type           = EV_PWR,
                .desc           = "Power",
                .active_low     = 0,
+               .wakeup         = 1,
        },
        {
                .gpio           = S3C2410_GPG(9),
@@ -264,6 +268,14 @@ static struct s3c24xx_led_platdata n30_blue_led_pdata = {
        .def_trigger    = "",
 };
 
+/* This is the blue LED on the device. Originaly used to indicate GPS activity
+ * by flashing. */
+static struct s3c24xx_led_platdata n35_blue_led_pdata = {
+       .name           = "blue_led",
+       .gpio           = S3C2410_GPD(8),
+       .def_trigger    = "",
+};
+
 /* This LED is driven by the battery microcontroller, and is blinking
  * red, blinking green or solid green when the battery is low,
  * charging or full respectively.  By driving GPD9 low, it's possible
@@ -275,6 +287,13 @@ static struct s3c24xx_led_platdata n30_warning_led_pdata = {
        .def_trigger    = "",
 };
 
+static struct s3c24xx_led_platdata n35_warning_led_pdata = {
+       .name           = "warning_led",
+       .flags          = S3C24XX_LEDF_ACTLOW | S3C24XX_LEDF_TRISTATE,
+       .gpio           = S3C2410_GPD(9),
+       .def_trigger    = "",
+};
+
 static struct platform_device n30_blue_led = {
        .name           = "s3c24xx_led",
        .id             = 1,
@@ -283,6 +302,14 @@ static struct platform_device n30_blue_led = {
        },
 };
 
+static struct platform_device n35_blue_led = {
+       .name           = "s3c24xx_led",
+       .id             = 1,
+       .dev            = {
+               .platform_data  = &n35_blue_led_pdata,
+       },
+};
+
 static struct platform_device n30_warning_led = {
        .name           = "s3c24xx_led",
        .id             = 2,
@@ -291,6 +318,14 @@ static struct platform_device n30_warning_led = {
        },
 };
 
+static struct platform_device n35_warning_led = {
+       .name           = "s3c24xx_led",
+       .id             = 2,
+       .dev            = {
+               .platform_data  = &n35_warning_led_pdata,
+       },
+};
+
 static struct s3c2410fb_display n30_display __initdata = {
        .type           = S3C2410_LCDCON1_TFT,
        .width          = 240,
@@ -317,13 +352,36 @@ static struct s3c2410fb_mach_info n30_fb_info __initdata = {
        .lpcsel         = 0x06,
 };
 
+static void n30_sdi_set_power(unsigned char power_mode, unsigned short vdd)
+{
+       switch (power_mode) {
+       case MMC_POWER_ON:
+       case MMC_POWER_UP:
+               gpio_set_value(S3C2410_GPG(4), 1);
+               break;
+       case MMC_POWER_OFF:
+       default:
+               gpio_set_value(S3C2410_GPG(4), 0);
+               break;
+       }
+}
+
+static struct s3c24xx_mci_pdata n30_mci_cfg __initdata = {
+       .gpio_detect    = S3C2410_GPF(1),
+       .gpio_wprotect  = S3C2410_GPG(10),
+       .ocr_avail      = MMC_VDD_32_33,
+       .set_power      = n30_sdi_set_power,
+};
+
 static struct platform_device *n30_devices[] __initdata = {
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_ohci,
+       &s3c_device_rtc,
        &s3c_device_usbgadget,
+       &s3c_device_sdi,
        &n30_button_device,
        &n30_blue_led,
        &n30_warning_led,
@@ -334,8 +392,12 @@ static struct platform_device *n35_devices[] __initdata = {
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
+       &s3c_device_rtc,
        &s3c_device_usbgadget,
+       &s3c_device_sdi,
        &n35_button_device,
+       &n35_blue_led,
+       &n35_warning_led,
 };
 
 static struct s3c2410_platform_i2c __initdata n30_i2ccfg = {
@@ -490,17 +552,15 @@ static void __init n30_map_io(void)
        s3c24xx_init_uarts(n30_uartcfgs, ARRAY_SIZE(n30_uartcfgs));
 }
 
-static void __init n30_init_irq(void)
-{
-       s3c24xx_init_irq();
-}
-
 /* GPB3 is the line that controls the pull-up for the USB D+ line */
 
 static void __init n30_init(void)
 {
+       WARN_ON(gpio_request(S3C2410_GPG(4), "mmc power"));
+
        s3c24xx_fb_set_platdata(&n30_fb_info);
        s3c24xx_udc_set_platdata(&n30_udc_cfg);
+       s3c24xx_mci_set_platdata(&n30_mci_cfg);
        s3c_i2c0_set_platdata(&n30_i2ccfg);
 
        /* Turn off suspend on both USB ports, and switch the
@@ -532,10 +592,13 @@ static void __init n30_init(void)
                s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
                                      S3C2410_MISCCR_USBSUSPND0 |
                                      S3C2410_MISCCR_USBSUSPND1,
-                                     S3C2410_MISCCR_USBSUSPND1);
+                                     S3C2410_MISCCR_USBSUSPND0);
 
                platform_add_devices(n35_devices, ARRAY_SIZE(n35_devices));
        }
+
+       WARN_ON(gpio_request(S3C2410_GPB(3), "udc pup"));
+       gpio_direction_output(S3C2410_GPB(3), 0);
 }
 
 MACHINE_START(N30, "Acer-N30")
@@ -547,7 +610,7 @@ MACHINE_START(N30, "Acer-N30")
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
        .timer          = &s3c24xx_timer,
        .init_machine   = n30_init,
-       .init_irq       = n30_init_irq,
+       .init_irq       = s3c24xx_init_irq,
        .map_io         = n30_map_io,
 MACHINE_END
 
@@ -559,6 +622,6 @@ MACHINE_START(N35, "Acer-N35")
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
        .timer          = &s3c24xx_timer,
        .init_machine   = n30_init,
-       .init_irq       = n30_init_irq,
+       .init_irq       = s3c24xx_init_irq,
        .map_io         = n30_map_io,
 MACHINE_END
index 92a4ec3..d0e87b6 100644 (file)
@@ -58,6 +58,7 @@
 #include <plat/iic.h>
 
 #include <plat/common-smdk.h>
+#include <plat/gpio-cfg.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
 #include <plat/pm.h>
@@ -219,10 +220,10 @@ static void spi_gpio_cs(struct s3c2410_spigpio_info *spi, int cs)
 {
        switch (cs) {
        case BITBANG_CS_ACTIVE:
-               s3c2410_gpio_setpin(S3C2410_GPB(5), 0);
+               gpio_set_value(S3C2410_GPB(5), 0);
                break;
        case BITBANG_CS_INACTIVE:
-               s3c2410_gpio_setpin(S3C2410_GPB(5), 1);
+               gpio_set_value(S3C2410_GPB(5), 1);
                break;
        }
 }
@@ -347,13 +348,14 @@ static void __init qt2410_machine_init(void)
        }
        s3c24xx_fb_set_platdata(&qt2410_fb_info);
 
-       s3c2410_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPIO_OUTPUT);
        s3c2410_gpio_setpin(S3C2410_GPB(0), 1);
 
        s3c24xx_udc_set_platdata(&qt2410_udc_cfg);
        s3c_i2c0_set_platdata(NULL);
 
-       s3c2410_gpio_cfgpin(S3C2410_GPB(5), S3C2410_GPIO_OUTPUT);
+       WARN_ON(gpio_request(S3C2410_GPB(5), "spi cs"));
+       gpio_direction_output(S3C2410_GPB(5), 1);
 
        platform_add_devices(qt2410_devices, ARRAY_SIZE(qt2410_devices));
        s3c_pm_init();
index 9051f0d..d540d79 100644 (file)
@@ -357,8 +357,7 @@ static struct clk *vr1000_clocks[] __initdata = {
 
 static void vr1000_power_off(void)
 {
-       s3c2410_gpio_cfgpin(S3C2410_GPB(9), S3C2410_GPIO_OUTPUT);
-       s3c2410_gpio_setpin(S3C2410_GPB(9), 1);
+       gpio_direction_output(S3C2410_GPB(9), 1);
 }
 
 static void __init vr1000_map_io(void)
@@ -395,6 +394,8 @@ static void __init vr1000_init(void)
 
        nor_simtec_init();
        simtec_audio_add(NULL, true, NULL);
+
+       WARN_ON(gpio_request(S3C2410_GPB(9), "power off"));
 }
 
 MACHINE_START(VR1000, "Thorcom-VR1000")
index 966119c..725636f 100644 (file)
@@ -60,10 +60,10 @@ static void s3c2410_pm_prepare(void)
                __raw_writel(calc, phys_to_virt(H1940_SUSPEND_CHECKSUM));
        }
 
-       /* the RX3715 uses similar code and the same H1940 and the
+       /* RX3715 and RX1950 use similar to H1940 code and the
         * same offsets for resume and checksum pointers */
 
-       if (machine_is_rx3715()) {
+       if (machine_is_rx3715() || machine_is_rx1950()) {
                void *base = phys_to_virt(H1940_SUSPEND_CHECK);
                unsigned long ptr;
                unsigned long calc = 0;
@@ -79,6 +79,17 @@ static void s3c2410_pm_prepare(void)
        if ( machine_is_aml_m5900() )
                s3c2410_gpio_setpin(S3C2410_GPF(2), 1);
 
+       if (machine_is_rx1950()) {
+               /* According to S3C2442 user's manual, page 7-17,
+                * when the system is operating in NAND boot mode,
+                * the hardware pin configuration - EINT[23:21] â€“
+                * must be set as input for starting up after
+                * wakeup from sleep mode
+                */
+               s3c_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPIO_INPUT);
+       }
 }
 
 static int s3c2410_pm_resume(struct sys_device *dev)
index 91ba42f..adc90a3 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/list.h>
 #include <linux/timer.h>
 #include <linux/init.h>
+#include <linux/gpio.h>
 #include <linux/clk.h>
 #include <linux/sysdev.h>
 #include <linux/serial_core.h>
 #include <plat/clock.h>
 #include <plat/pll.h>
 
+#include <plat/gpio-core.h>
+#include <plat/gpio-cfg.h>
+#include <plat/gpio-cfg-helpers.h>
+
 /* Initial IO mappings */
 
 static struct map_desc s3c2410_iodesc[] __initdata = {
@@ -65,6 +70,9 @@ void __init s3c2410_init_uarts(struct s3c2410_uartcfg *cfg, int no)
 
 void __init s3c2410_map_io(void)
 {
+       s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_1up;
+       s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_1up;
+
        iotable_init(s3c2410_iodesc, ARRAY_SIZE(s3c2410_iodesc));
 }
 
index 9a8c065..cef6a65 100644 (file)
@@ -16,7 +16,8 @@ config CPU_S3C2412
 config CPU_S3C2412_ONLY
        bool
        depends on ARCH_S3C2410 && !CPU_S3C2400 && !CPU_S3C2410 && \
-                  !CPU_S3C2440 && !CPU_S3C2442 && !CPU_S3C2443 && CPU_S3C2412
+                  !CPU_2416 && !CPU_S3C2440 && !CPU_S3C2442 && \
+                  !CPU_S3C2443 && CPU_S3C2412
        default y if CPU_S3C2412
 
 config S3C2412_DMA
index e880524..7abecfc 100644 (file)
@@ -30,7 +30,6 @@
 #include <mach/regs-mem.h>
 #include <mach/regs-lcd.h>
 #include <mach/regs-sdi.h>
-#include <plat/regs-s3c2412-iis.h>
 #include <plat/regs-iis.h>
 #include <plat/regs-spi.h>
 
@@ -119,13 +118,11 @@ static struct s3c24xx_dma_map __initdata s3c2412_dma_mappings[] = {
                .name           = "i2s-sdi",
                .channels       = MAP(S3C2412_DMAREQSEL_I2SRX),
                .channels_rx    = MAP(S3C2412_DMAREQSEL_I2SRX),
-               .hw_addr.from   = S3C2410_PA_IIS + S3C2412_IISRXD,
        },
        [DMACH_I2S_OUT] = {
                .name           = "i2s-sdo",
                .channels       = MAP(S3C2412_DMAREQSEL_I2STX),
                .channels_rx    = MAP(S3C2412_DMAREQSEL_I2STX),
-               .hw_addr.to     = S3C2410_PA_IIS + S3C2412_IISTXD,
        },
        [DMACH_USB_EP1] = {
                .name           = "usb-ep1",
index f7afece..3404a87 100644 (file)
 #include <linux/types.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include <linux/gpio.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 
 #include <mach/regs-gpio.h>
-
 #include <mach/hardware.h>
 
+#include <plat/gpio-core.h>
+
 int s3c2412_gpio_set_sleepcfg(unsigned int pin, unsigned int state)
 {
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long offs = S3C2410_GPIO_OFFSET(pin);
+       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
+       unsigned long offs = pin - chip->chip.base;
        unsigned long flags;
        unsigned long slpcon;
 
        offs *= 2;
 
-       if (pin < S3C2410_GPIO_BANKB)
+       if (pin < S3C2410_GPB(0))
                return -EINVAL;
 
-       if (pin >= S3C2410_GPIO_BANKF &&
-           pin <= S3C2410_GPIO_BANKG)
+       if (pin >= S3C2410_GPF(0) &&
+           pin <= S3C2410_GPG(16))
                return -EINVAL;
 
-       if (pin > (S3C2410_GPIO_BANKH + 32))
+       if (pin > S3C2410_GPH(16))
                return -EINVAL;
 
        local_irq_save(flags);
 
-       slpcon = __raw_readl(base + 0x0C);
+       slpcon = __raw_readl(chip->base + 0x0C);
 
        slpcon &= ~(3 << offs);
        slpcon |= state << offs;
 
-       __raw_writel(slpcon, base + 0x0C);
+       __raw_writel(slpcon, chip->base + 0x0C);
 
        local_irq_restore(flags);
 
index 14f4798..478f4b4 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/mtd/nand_ecc.h>
 #include <linux/mtd/partitions.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/clock.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
@@ -357,8 +358,7 @@ static void jive_lcm_reset(unsigned int set)
 {
        printk(KERN_DEBUG "%s(%d)\n", __func__, set);
 
-       s3c2410_gpio_setpin(S3C2410_GPG(13), set);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_OUTPUT);
+       gpio_set_value(S3C2410_GPG(13), set);
 }
 
 #undef LCD_UPPER_MARGIN
@@ -391,7 +391,7 @@ static struct ili9320_platdata jive_lcm_config = {
 
 static void jive_lcd_spi_chipselect(struct s3c2410_spigpio_info *spi, int cs)
 {
-       s3c2410_gpio_setpin(S3C2410_GPB(7), cs ? 0 : 1);
+       gpio_set_value(S3C2410_GPB(7), cs ? 0 : 1);
 }
 
 static struct s3c2410_spigpio_info jive_lcd_spi = {
@@ -413,7 +413,7 @@ static struct platform_device jive_device_lcdspi = {
 
 static void jive_wm8750_chipselect(struct s3c2410_spigpio_info *spi, int cs)
 {
-       s3c2410_gpio_setpin(S3C2410_GPH(10), cs ? 0 : 1);
+       gpio_set_value(S3C2410_GPH(10), cs ? 0 : 1);
 }
 
 static struct s3c2410_spigpio_info jive_wm8750_spi = {
@@ -531,7 +531,7 @@ static void jive_power_off(void)
        printk(KERN_INFO "powering system down...\n");
 
        s3c2410_gpio_setpin(S3C2410_GPC(5), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPC(5), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPC(5), S3C2410_GPIO_OUTPUT);
 }
 
 static void __init jive_machine_init(void)
@@ -636,22 +636,22 @@ static void __init jive_machine_init(void)
 
        /* initialise the spi */
 
-       s3c2410_gpio_setpin(S3C2410_GPG(13), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPIO_OUTPUT);
+       gpio_request(S3C2410_GPG(13), "lcm reset");
+       gpio_direction_output(S3C2410_GPG(13), 0);
 
-       s3c2410_gpio_setpin(S3C2410_GPB(7), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPB(7), S3C2410_GPIO_OUTPUT);
+       gpio_request(S3C2410_GPB(7), "jive spi");
+       gpio_direction_output(S3C2410_GPB(7), 1);
 
        s3c2410_gpio_setpin(S3C2410_GPB(6), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPB(6), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPB(6), S3C2410_GPIO_OUTPUT);
 
        s3c2410_gpio_setpin(S3C2410_GPG(8), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(8), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPG(8), S3C2410_GPIO_OUTPUT);
 
        /* initialise the WM8750 spi */
 
-       s3c2410_gpio_setpin(S3C2410_GPH(10), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPH(10), S3C2410_GPIO_OUTPUT);
+       gpio_request(S3C2410_GPH(10), "jive wm8750 spi");
+       gpio_direction_output(S3C2410_GPH(10), 1);
 
        /* Turn off suspend on both USB ports, and switch the
         * selectable USB port to USB device mode. */
@@ -674,7 +674,7 @@ static void __init jive_machine_init(void)
 }
 
 MACHINE_START(JIVE, "JIVE")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
index 0392065..ba93a35 100644 (file)
@@ -85,10 +85,10 @@ static void smdk2413_udc_pullup(enum s3c2410_udc_cmd_e cmd)
        switch (cmd)
        {
                case S3C2410_UDC_P_ENABLE :
-                       s3c2410_gpio_setpin(S3C2410_GPF(2), 1);
+                       gpio_set_value(S3C2410_GPF(2), 1);
                        break;
                case S3C2410_UDC_P_DISABLE :
-                       s3c2410_gpio_setpin(S3C2410_GPF(2), 0);
+                       gpio_set_value(S3C2410_GPF(2), 0);
                        break;
                case S3C2410_UDC_P_RESET :
                        break;
@@ -134,8 +134,8 @@ static void __init smdk2413_machine_init(void)
 {      /* Turn off suspend on both USB ports, and switch the
         * selectable USB port to USB device mode. */
 
-       s3c2410_gpio_setpin(S3C2410_GPF(2), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(2), S3C2410_GPIO_OUTPUT);
+       WARN_ON(gpio_request(S3C2410_GPF(2), "udc pull"));
+       gpio_direction_output(S3C2410_GPF(2), 0);
 
        s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
                              S3C2410_MISCCR_USBSUSPND0 |
@@ -150,7 +150,7 @@ static void __init smdk2413_machine_init(void)
 }
 
 MACHINE_START(S3C2413, "S3C2413")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
@@ -163,7 +163,7 @@ MACHINE_START(S3C2413, "S3C2413")
 MACHINE_END
 
 MACHINE_START(SMDK2412, "SMDK2412")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
@@ -176,7 +176,7 @@ MACHINE_START(SMDK2412, "SMDK2412")
 MACHINE_END
 
 MACHINE_START(SMDK2413, "SMDK2413")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
diff --git a/arch/arm/mach-s3c2416/Kconfig b/arch/arm/mach-s3c2416/Kconfig
new file mode 100644 (file)
index 0000000..657e4fe
--- /dev/null
@@ -0,0 +1,39 @@
+# arch/arm/mach-s3c2416/Kconfig
+#
+# Copyright 2009 Yauhen Kharuzhy <jekhor@gmail.com>
+#
+# Licensed under GPLv2
+
+# note, this also supports the S3C2450 which is so similar it has the same
+# ID code as the S3C2416.
+
+config CPU_S3C2416
+       bool
+       depends on ARCH_S3C2410
+       select CPU_ARM926T
+       select S3C2416_DMA if S3C2410_DMA
+       select CPU_LLSERIAL_S3C2440
+       select S3C_GPIO_PULL_UPDOWN
+       select SAMSUNG_CLKSRC
+       select S3C2443_CLOCK
+       help
+         Support for the S3C2416 SoC from the S3C24XX line
+
+config S3C2416_DMA
+       bool
+       depends on CPU_S3C2416
+       help
+         Internal config node for S3C2416 DMA support
+
+menu "S3C2416 Machines"
+
+config MACH_SMDK2416
+       bool "SMDK2416"
+       select CPU_S3C2416
+       select S3C_DEV_FB
+       select S3C_DEV_HSMMC
+       select S3C_DEV_HSMMC1
+       help
+         Say Y here if you are using an SMDK2416
+
+endmenu
diff --git a/arch/arm/mach-s3c2416/Makefile b/arch/arm/mach-s3c2416/Makefile
new file mode 100644 (file)
index 0000000..6c12c7b
--- /dev/null
@@ -0,0 +1,19 @@
+# arch/arm/mach-s3c2416/Makefile
+#
+# Copyright 2009 Yauhen Kharuzhy <jekhor@gmail.com>
+#
+# Licensed under GPLv2
+
+obj-y                          :=
+obj-m                          :=
+obj-n                          :=
+obj-                           :=
+
+obj-$(CONFIG_CPU_S3C2416)      += s3c2416.o clock.o
+obj-$(CONFIG_CPU_S3C2416)      += irq.o
+
+#obj-$(CONFIG_S3C2416_DMA)     += dma.o
+
+# Machine support
+
+obj-$(CONFIG_MACH_SMDK2416)    += mach-smdk2416.o
diff --git a/arch/arm/mach-s3c2416/clock.c b/arch/arm/mach-s3c2416/clock.c
new file mode 100644 (file)
index 0000000..7ccf5a2
--- /dev/null
@@ -0,0 +1,135 @@
+/* linux/arch/arm/mach-s3c2416/clock.c
+ *
+ * Copyright (c) 2010 Simtec Electronics
+ * Copyright (c) 2010 Ben Dooks <ben-linux@fluff.org>
+ *
+ * S3C2416 Clock control 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.
+ */
+
+#include <linux/init.h>
+#include <linux/clk.h>
+
+#include <plat/s3c2416.h>
+#include <plat/s3c2443.h>
+#include <plat/clock.h>
+#include <plat/clock-clksrc.h>
+#include <plat/cpu.h>
+
+#include <plat/cpu-freq.h>
+#include <plat/pll6553x.h>
+#include <plat/pll.h>
+
+#include <asm/mach/map.h>
+
+#include <mach/regs-clock.h>
+#include <mach/regs-s3c2443-clock.h>
+
+static unsigned int armdiv[8] = {
+       [0] = 1,
+       [1] = 2,
+       [2] = 3,
+       [3] = 4,
+       [5] = 6,
+       [7] = 8,
+};
+
+/* ID to hardware numbering, 0 is HSMMC1, 1 is HSMMC0 */
+static struct clksrc_clk hsmmc_div[] = {
+       [0] = {
+               .clk = {
+                       .name   = "hsmmc-div",
+                       .id     = 1,
+                       .parent = &clk_esysclk.clk,
+               },
+               .reg_div = { .reg = S3C2416_CLKDIV2, .size = 2, .shift = 6 },
+       },
+       [1] = {
+               .clk = {
+                       .name   = "hsmmc-div",
+                       .id     = 0,
+                       .parent = &clk_esysclk.clk,
+               },
+               .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 6 },
+       },
+};
+
+static struct clksrc_clk hsmmc_mux[] = {
+       [0] = {
+               .clk    = {
+                       .id     = 1,
+                       .name   = "hsmmc-if",
+                       .ctrlbit = (1 << 6),
+                       .enable = s3c2443_clkcon_enable_s,
+               },
+               .sources = &(struct clksrc_sources) {
+                       .nr_sources = 2,
+                       .sources = (struct clk *[]) {
+                               [0] = &hsmmc_div[0].clk,
+                               [1] = NULL, /* to fix */
+                       },
+               },
+               .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 16 },
+       },
+       [1] = {
+               .clk    = {
+                       .id     = 0,
+                       .name   = "hsmmc-if",
+                       .ctrlbit = (1 << 12),
+                       .enable = s3c2443_clkcon_enable_s,
+               },
+               .sources = &(struct clksrc_sources) {
+                       .nr_sources = 2,
+                       .sources = (struct clk *[]) {
+                               [0] = &hsmmc_div[1].clk,
+                               [1] = NULL, /* to fix */
+                       },
+               },
+               .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 17 },
+       },
+};
+
+
+static inline unsigned int s3c2416_fclk_div(unsigned long clkcon0)
+{
+       clkcon0 &= 7 << S3C2443_CLKDIV0_ARMDIV_SHIFT;
+
+       return armdiv[clkcon0 >> S3C2443_CLKDIV0_ARMDIV_SHIFT];
+}
+
+void __init_or_cpufreq s3c2416_setup_clocks(void)
+{
+       s3c2443_common_setup_clocks(s3c2416_get_pll, s3c2416_fclk_div);
+}
+
+
+static struct clksrc_clk *clksrcs[] __initdata = {
+       &hsmmc_div[0],
+       &hsmmc_div[1],
+       &hsmmc_mux[0],
+       &hsmmc_mux[1],
+};
+
+void __init s3c2416_init_clocks(int xtal)
+{
+       u32 epllcon = __raw_readl(S3C2443_EPLLCON);
+       u32 epllcon1 = __raw_readl(S3C2443_EPLLCON+4);
+       int ptr;
+
+       /* s3c2416 EPLL compatible with s3c64xx */
+       clk_epll.rate = s3c_get_pll6553x(xtal, epllcon, epllcon1);
+
+       clk_epll.parent = &clk_epllref.clk;
+
+       s3c2443_common_init_clocks(xtal, s3c2416_get_pll, s3c2416_fclk_div);
+
+       for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
+               s3c_register_clksrc(clksrcs[ptr], 1);
+
+       s3c_pwmclk_init();
+
+}
diff --git a/arch/arm/mach-s3c2416/irq.c b/arch/arm/mach-s3c2416/irq.c
new file mode 100644 (file)
index 0000000..89f521d
--- /dev/null
@@ -0,0 +1,254 @@
+/* linux/arch/arm/mach-s3c2416/irq.c
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
+ *     as part of OpenInkpot project
+ * Copyright (c) 2009 Promwad Innovation Company
+ *     Yauhen Kharuzhy <yauhen.kharuzhy@promwad.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 <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/sysdev.h>
+#include <linux/io.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+
+#include <asm/mach/irq.h>
+
+#include <mach/regs-irq.h>
+#include <mach/regs-gpio.h>
+
+#include <plat/cpu.h>
+#include <plat/pm.h>
+#include <plat/irq.h>
+
+#define INTMSK(start, end) ((1 << ((end) + 1 - (start))) - 1)
+
+static inline void s3c2416_irq_demux(unsigned int irq, unsigned int len)
+{
+       unsigned int subsrc, submsk;
+       unsigned int end;
+
+       /* read the current pending interrupts, and the mask
+        * for what it is available */
+
+       subsrc = __raw_readl(S3C2410_SUBSRCPND);
+       submsk = __raw_readl(S3C2410_INTSUBMSK);
+
+       subsrc  &= ~submsk;
+       subsrc >>= (irq - S3C2410_IRQSUB(0));
+       subsrc  &= (1 << len)-1;
+
+       end = len + irq;
+
+       for (; irq < end && subsrc; irq++) {
+               if (subsrc & 1)
+                       generic_handle_irq(irq);
+
+               subsrc >>= 1;
+       }
+}
+
+/* WDT/AC97 sub interrupts */
+
+static void s3c2416_irq_demux_wdtac97(unsigned int irq, struct irq_desc *desc)
+{
+       s3c2416_irq_demux(IRQ_S3C2443_WDT, 4);
+}
+
+#define INTMSK_WDTAC97 (1UL << (IRQ_WDT - IRQ_EINT0))
+#define SUBMSK_WDTAC97 INTMSK(IRQ_S3C2443_WDT, IRQ_S3C2443_AC97)
+
+static void s3c2416_irq_wdtac97_mask(unsigned int irqno)
+{
+       s3c_irqsub_mask(irqno, INTMSK_WDTAC97, SUBMSK_WDTAC97);
+}
+
+static void s3c2416_irq_wdtac97_unmask(unsigned int irqno)
+{
+       s3c_irqsub_unmask(irqno, INTMSK_WDTAC97);
+}
+
+static void s3c2416_irq_wdtac97_ack(unsigned int irqno)
+{
+       s3c_irqsub_maskack(irqno, INTMSK_WDTAC97, SUBMSK_WDTAC97);
+}
+
+static struct irq_chip s3c2416_irq_wdtac97 = {
+       .mask       = s3c2416_irq_wdtac97_mask,
+       .unmask     = s3c2416_irq_wdtac97_unmask,
+       .ack        = s3c2416_irq_wdtac97_ack,
+};
+
+
+/* LCD sub interrupts */
+
+static void s3c2416_irq_demux_lcd(unsigned int irq, struct irq_desc *desc)
+{
+       s3c2416_irq_demux(IRQ_S3C2443_LCD1, 4);
+}
+
+#define INTMSK_LCD     (1UL << (IRQ_LCD - IRQ_EINT0))
+#define SUBMSK_LCD     INTMSK(IRQ_S3C2443_LCD1, IRQ_S3C2443_LCD4)
+
+static void s3c2416_irq_lcd_mask(unsigned int irqno)
+{
+       s3c_irqsub_mask(irqno, INTMSK_LCD, SUBMSK_LCD);
+}
+
+static void s3c2416_irq_lcd_unmask(unsigned int irqno)
+{
+       s3c_irqsub_unmask(irqno, INTMSK_LCD);
+}
+
+static void s3c2416_irq_lcd_ack(unsigned int irqno)
+{
+       s3c_irqsub_maskack(irqno, INTMSK_LCD, SUBMSK_LCD);
+}
+
+static struct irq_chip s3c2416_irq_lcd = {
+       .mask       = s3c2416_irq_lcd_mask,
+       .unmask     = s3c2416_irq_lcd_unmask,
+       .ack        = s3c2416_irq_lcd_ack,
+};
+
+
+/* DMA sub interrupts */
+
+static void s3c2416_irq_demux_dma(unsigned int irq, struct irq_desc *desc)
+{
+       s3c2416_irq_demux(IRQ_S3C2443_DMA0, 6);
+}
+
+#define INTMSK_DMA     (1UL << (IRQ_S3C2443_DMA - IRQ_EINT0))
+#define SUBMSK_DMA     INTMSK(IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5)
+
+
+static void s3c2416_irq_dma_mask(unsigned int irqno)
+{
+       s3c_irqsub_mask(irqno, INTMSK_DMA, SUBMSK_DMA);
+}
+
+static void s3c2416_irq_dma_unmask(unsigned int irqno)
+{
+       s3c_irqsub_unmask(irqno, INTMSK_DMA);
+}
+
+static void s3c2416_irq_dma_ack(unsigned int irqno)
+{
+       s3c_irqsub_maskack(irqno, INTMSK_DMA, SUBMSK_DMA);
+}
+
+static struct irq_chip s3c2416_irq_dma = {
+       .mask       = s3c2416_irq_dma_mask,
+       .unmask     = s3c2416_irq_dma_unmask,
+       .ack        = s3c2416_irq_dma_ack,
+};
+
+
+/* UART3 sub interrupts */
+
+static void s3c2416_irq_demux_uart3(unsigned int irq, struct irq_desc *desc)
+{
+       s3c2416_irq_demux(IRQ_S3C2443_UART3, 3);
+}
+
+#define INTMSK_UART3   (1UL << (IRQ_S3C2443_UART3 - IRQ_EINT0))
+#define SUBMSK_UART3   (0xf << (IRQ_S3C2443_RX3 - S3C2410_IRQSUB(0)))
+
+
+static void s3c2416_irq_uart3_mask(unsigned int irqno)
+{
+       s3c_irqsub_mask(irqno, INTMSK_UART3, SUBMSK_UART3);
+}
+
+static void s3c2416_irq_uart3_unmask(unsigned int irqno)
+{
+       s3c_irqsub_unmask(irqno, INTMSK_UART3);
+}
+
+static void s3c2416_irq_uart3_ack(unsigned int irqno)
+{
+       s3c_irqsub_maskack(irqno, INTMSK_UART3, SUBMSK_UART3);
+}
+
+static struct irq_chip s3c2416_irq_uart3 = {
+       .mask       = s3c2416_irq_uart3_mask,
+       .unmask     = s3c2416_irq_uart3_unmask,
+       .ack        = s3c2416_irq_uart3_ack,
+};
+
+
+/* IRQ initialisation code */
+
+static int __init s3c2416_add_sub(unsigned int base,
+                                  void (*demux)(unsigned int,
+                                                struct irq_desc *),
+                                  struct irq_chip *chip,
+                                  unsigned int start, unsigned int end)
+{
+       unsigned int irqno;
+
+       set_irq_chip(base, &s3c_irq_level_chip);
+       set_irq_handler(base, handle_level_irq);
+       set_irq_chained_handler(base, demux);
+
+       for (irqno = start; irqno <= end; irqno++) {
+               set_irq_chip(irqno, chip);
+               set_irq_handler(irqno, handle_level_irq);
+               set_irq_flags(irqno, IRQF_VALID);
+       }
+
+       return 0;
+}
+
+static int __init s3c2416_irq_add(struct sys_device *sysdev)
+{
+       printk(KERN_INFO "S3C2416: IRQ Support\n");
+
+       s3c2416_add_sub(IRQ_LCD, s3c2416_irq_demux_lcd, &s3c2416_irq_lcd,
+                       IRQ_S3C2443_LCD2, IRQ_S3C2443_LCD4);
+
+       s3c2416_add_sub(IRQ_S3C2443_DMA, s3c2416_irq_demux_dma,
+                       &s3c2416_irq_dma, IRQ_S3C2443_DMA0, IRQ_S3C2443_DMA5);
+
+       s3c2416_add_sub(IRQ_S3C2443_UART3, s3c2416_irq_demux_uart3,
+                       &s3c2416_irq_uart3,
+                       IRQ_S3C2443_RX3, IRQ_S3C2443_ERR3);
+
+       s3c2416_add_sub(IRQ_WDT, s3c2416_irq_demux_wdtac97,
+                       &s3c2416_irq_wdtac97,
+                       IRQ_S3C2443_WDT, IRQ_S3C2443_AC97);
+
+       return 0;
+}
+
+static struct sysdev_driver s3c2416_irq_driver = {
+       .add            = s3c2416_irq_add,
+};
+
+static int __init s3c2416_irq_init(void)
+{
+       return sysdev_driver_register(&s3c2416_sysclass, &s3c2416_irq_driver);
+}
+
+arch_initcall(s3c2416_irq_init);
+
diff --git a/arch/arm/mach-s3c2416/mach-smdk2416.c b/arch/arm/mach-s3c2416/mach-smdk2416.c
new file mode 100644 (file)
index 0000000..5fc3f67
--- /dev/null
@@ -0,0 +1,206 @@
+/* linux/arch/arm/mach-s3c2416/mach-hanlin_v3c.c
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
+ *     as part of OpenInkpot project
+ * Copyright (c) 2009 Promwad Innovation Company
+ *     Yauhen Kharuzhy <yauhen.kharuzhy@promwad.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/timer.h>
+#include <linux/init.h>
+#include <linux/serial_core.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/mtd/partitions.h>
+#include <linux/gpio.h>
+#include <linux/fb.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+#include <asm/mach-types.h>
+
+#include <plat/regs-serial.h>
+#include <mach/regs-gpio.h>
+#include <mach/regs-lcd.h>
+
+#include <mach/idle.h>
+#include <mach/leds-gpio.h>
+#include <plat/iic.h>
+
+#include <plat/s3c2416.h>
+#include <plat/gpio-cfg.h>
+#include <plat/clock.h>
+#include <plat/devs.h>
+#include <plat/cpu.h>
+#include <plat/nand.h>
+
+#include <plat/regs-fb-v4.h>
+#include <plat/fb.h>
+
+#include <plat/common-smdk.h>
+
+static struct map_desc smdk2416_iodesc[] __initdata = {
+       /* ISA IO Space map (memory space selected by A24) */
+
+       {
+               .virtual        = (u32)S3C24XX_VA_ISA_WORD,
+               .pfn            = __phys_to_pfn(S3C2410_CS2),
+               .length         = 0x10000,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = (u32)S3C24XX_VA_ISA_WORD + 0x10000,
+               .pfn            = __phys_to_pfn(S3C2410_CS2 + (1<<24)),
+               .length         = SZ_4M,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = (u32)S3C24XX_VA_ISA_BYTE,
+               .pfn            = __phys_to_pfn(S3C2410_CS2),
+               .length         = 0x10000,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = (u32)S3C24XX_VA_ISA_BYTE + 0x10000,
+               .pfn            = __phys_to_pfn(S3C2410_CS2 + (1<<24)),
+               .length         = SZ_4M,
+               .type           = MT_DEVICE,
+       }
+};
+
+#define UCON (S3C2410_UCON_DEFAULT     | \
+               S3C2440_UCON_PCLK       | \
+               S3C2443_UCON_RXERR_IRQEN)
+
+#define ULCON (S3C2410_LCON_CS8 | S3C2410_LCON_PNONE)
+
+#define UFCON (S3C2410_UFCON_RXTRIG8   | \
+               S3C2410_UFCON_FIFOMODE  | \
+               S3C2440_UFCON_TXTRIG16)
+
+static struct s3c2410_uartcfg smdk2416_uartcfgs[] __initdata = {
+       [0] = {
+               .hwport      = 0,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+       },
+       [1] = {
+               .hwport      = 1,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON,
+               .ufcon       = UFCON,
+       },
+       /* IR port */
+       [2] = {
+               .hwport      = 2,
+               .flags       = 0,
+               .ucon        = UCON,
+               .ulcon       = ULCON | 0x50,
+               .ufcon       = UFCON,
+       }
+};
+
+struct s3c_fb_pd_win smdk2416_fb_win[] = {
+       [0] = {
+               /* think this is the same as the smdk6410 */
+               .win_mode       = {
+                       .pixclock       = 41094,
+                       .left_margin    = 8,
+                       .right_margin   = 13,
+                       .upper_margin   = 7,
+                       .lower_margin   = 5,
+                       .hsync_len      = 3,
+                       .vsync_len      = 1,
+                       .xres           = 800,
+                       .yres           = 480,
+               },
+               .default_bpp    = 16,
+               .max_bpp        = 32,
+       },
+};
+
+static void s3c2416_fb_gpio_setup_24bpp(void)
+{
+       unsigned int gpio;
+
+       for (gpio = S3C2410_GPC(1); gpio <= S3C2410_GPC(4); gpio++) {
+               s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
+               s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
+       }
+
+       for (gpio = S3C2410_GPC(8); gpio <= S3C2410_GPC(15); gpio++) {
+               s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
+               s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
+       }
+
+       for (gpio = S3C2410_GPD(0); gpio <= S3C2410_GPD(15); gpio++) {
+               s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(2));
+               s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
+       }
+}
+
+static struct s3c_fb_platdata smdk2416_fb_platdata = {
+       .win[0]         = &smdk2416_fb_win[0],
+       .setup_gpio     = s3c2416_fb_gpio_setup_24bpp,
+       .vidcon0        = VIDCON0_VIDOUT_RGB | VIDCON0_PNRMODE_RGB,
+       .vidcon1        = VIDCON1_INV_HSYNC | VIDCON1_INV_VSYNC,
+};
+
+static struct platform_device *smdk2416_devices[] __initdata = {
+       &s3c_device_fb,
+       &s3c_device_wdt,
+       &s3c_device_ohci,
+       &s3c_device_i2c0,
+       &s3c_device_hsmmc0,
+       &s3c_device_hsmmc1,
+};
+
+static void __init smdk2416_map_io(void)
+{
+       s3c24xx_init_io(smdk2416_iodesc, ARRAY_SIZE(smdk2416_iodesc));
+       s3c24xx_init_clocks(12000000);
+       s3c24xx_init_uarts(smdk2416_uartcfgs, ARRAY_SIZE(smdk2416_uartcfgs));
+}
+
+static void __init smdk2416_machine_init(void)
+{
+       s3c_i2c0_set_platdata(NULL);
+       s3c_fb_set_platdata(&smdk2416_fb_platdata);
+
+       gpio_request(S3C2410_GPB(4), "USBHost Power");
+       gpio_direction_output(S3C2410_GPB(4), 1);
+
+       gpio_request(S3C2410_GPB(3), "Display Power");
+       gpio_direction_output(S3C2410_GPB(3), 1);
+
+       gpio_request(S3C2410_GPB(1), "Display Reset");
+       gpio_direction_output(S3C2410_GPB(1), 1);
+
+       platform_add_devices(smdk2416_devices, ARRAY_SIZE(smdk2416_devices));
+       smdk_machine_init();
+}
+
+MACHINE_START(SMDK2416, "SMDK2416")
+       /* Maintainer: Yauhen Kharuzhy <jekhor@gmail.com> */
+       .phys_io        = S3C2410_PA_UART,
+       .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
+       .boot_params    = S3C2410_SDRAM_PA + 0x100,
+
+       .init_irq       = s3c24xx_init_irq,
+       .map_io         = smdk2416_map_io,
+       .init_machine   = smdk2416_machine_init,
+       .timer          = &s3c24xx_timer,
+MACHINE_END
diff --git a/arch/arm/mach-s3c2416/s3c2416.c b/arch/arm/mach-s3c2416/s3c2416.c
new file mode 100644 (file)
index 0000000..35dabcc
--- /dev/null
@@ -0,0 +1,130 @@
+/* linux/arch/arm/mach-s3c2416/s3c2416.c
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>,
+ *     as part of OpenInkpot project
+ * Copyright (c) 2009 Promwad Innovation Company
+ *     Yauhen Kharuzhy <yauhen.kharuzhy@promwad.com>
+ *
+ * Samsung S3C2416 Mobile CPU 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
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/timer.h>
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/serial_core.h>
+#include <linux/sysdev.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/irq.h>
+
+#include <mach/hardware.h>
+#include <asm/proc-fns.h>
+#include <asm/irq.h>
+
+#include <mach/reset.h>
+#include <mach/idle.h>
+#include <mach/regs-s3c2443-clock.h>
+
+#include <plat/gpio-core.h>
+#include <plat/gpio-cfg.h>
+#include <plat/gpio-cfg-helpers.h>
+#include <plat/s3c2416.h>
+#include <plat/devs.h>
+#include <plat/cpu.h>
+
+#include <plat/iic-core.h>
+
+static struct map_desc s3c2416_iodesc[] __initdata = {
+       IODESC_ENT(WATCHDOG),
+       IODESC_ENT(CLKPWR),
+       IODESC_ENT(TIMER),
+};
+
+struct sysdev_class s3c2416_sysclass = {
+       .name = "s3c2416-core",
+};
+
+static struct sys_device s3c2416_sysdev = {
+       .cls            = &s3c2416_sysclass,
+};
+
+static void s3c2416_hard_reset(void)
+{
+       __raw_writel(S3C2443_SWRST_RESET, S3C2443_SWRST);
+}
+
+int __init s3c2416_init(void)
+{
+       printk(KERN_INFO "S3C2416: Initializing architecture\n");
+
+       s3c24xx_reset_hook = s3c2416_hard_reset;
+       /* s3c24xx_idle = s3c2416_idle; */
+
+       /* change WDT IRQ number */
+       s3c_device_wdt.resource[1].start = IRQ_S3C2443_WDT;
+       s3c_device_wdt.resource[1].end   = IRQ_S3C2443_WDT;
+
+       /* the i2c devices are directly compatible with s3c2440 */
+       s3c_i2c0_setname("s3c2440-i2c");
+       s3c_i2c1_setname("s3c2440-i2c");
+
+       s3c_device_fb.name = "s3c2443-fb";
+
+       return sysdev_register(&s3c2416_sysdev);
+}
+
+void __init s3c2416_init_uarts(struct s3c2410_uartcfg *cfg, int no)
+{
+       s3c24xx_init_uartdevs("s3c2440-uart", s3c2410_uart_resources, cfg, no);
+
+       s3c_device_nand.name = "s3c2416-nand";
+}
+
+/* s3c2416_map_io
+ *
+ * register the standard cpu IO areas, and any passed in from the
+ * machine specific initialisation.
+ */
+
+void __init s3c2416_map_io(void)
+{
+       s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_updown;
+       s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_updown;
+
+       iotable_init(s3c2416_iodesc, ARRAY_SIZE(s3c2416_iodesc));
+}
+
+/* need to register class before we actually register the device, and
+ * we also need to ensure that it has been initialised before any of the
+ * drivers even try to use it (even if not on an s3c2416 based system)
+ * as a driver which may support both 2443 and 2440 may try and use it.
+*/
+
+static int __init s3c2416_core_init(void)
+{
+       return sysdev_class_register(&s3c2416_sysclass);
+}
+
+core_initcall(s3c2416_core_init);
index 7f46526..cd8e7de 100644 (file)
@@ -6,6 +6,7 @@ config CPU_S3C2440
        bool
        depends on ARCH_S3C2410
        select CPU_ARM920T
+       select S3C_GPIO_PULL_UP
        select S3C2410_CLOCK
        select S3C2410_PM if PM
        select S3C2410_GPIO
@@ -187,4 +188,17 @@ config MACH_MINI2440
          Say Y here to select support for the MINI2440. Is a 10cm x 10cm board
          available via various sources. It can come with a 3.5" or 7" touch LCD.
 
+config MACH_RX1950
+       bool "HP iPAQ rx1950"
+       select CPU_S3C2442
+       select S3C24XX_DCLK
+       select PM_H1940 if PM
+       select I2C
+       select S3C2410_PWM
+       select S3C_DEV_NAND
+       select S3C2410_IOTIMING if S3C2440_CPUFREQ
+       select S3C2440_XTAL_16934400
+       help
+          Say Y here if you're using HP iPAQ rx1950
+
 endmenu
index c85ba32..d5440fa 100644 (file)
@@ -34,6 +34,7 @@ obj-$(CONFIG_MACH_NEXCODER_2440) += mach-nexcoder.o
 obj-$(CONFIG_MACH_AT2440EVB) += mach-at2440evb.o
 obj-$(CONFIG_MACH_MINI2440) += mach-mini2440.o
 obj-$(CONFIG_MACH_NEO1973_GTA02) += mach-gta02.o
+obj-$(CONFIG_MACH_RX1950) += mach-rx1950.o
 
 # extra machine support
 
index 571b176..a76bcda 100644 (file)
@@ -53,6 +53,7 @@
 #include <linux/mtd/nand_ecc.h>
 #include <linux/mtd/partitions.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/clock.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
@@ -102,10 +103,10 @@ static void mini2440_udc_pullup(enum s3c2410_udc_cmd_e cmd)
 
        switch (cmd) {
                case S3C2410_UDC_P_ENABLE :
-                       s3c2410_gpio_setpin(S3C2410_GPC(5), 1);
+                       gpio_set_value(S3C2410_GPC(5), 1);
                        break;
                case S3C2410_UDC_P_DISABLE :
-                       s3c2410_gpio_setpin(S3C2410_GPC(5), 0);
+                       gpio_set_value(S3C2410_GPC(5), 0);
                        break;
                case S3C2410_UDC_P_RESET :
                        break;
@@ -632,25 +633,25 @@ static void __init mini2440_init(void)
        mini2440_parse_features(&features, mini2440_features_str);
 
        /* turn LCD on */
-       s3c2410_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
+       s3c_gpio_cfgpin(S3C2410_GPC(0), S3C2410_GPC0_LEND);
 
        /* Turn the backlight early on */
-       s3c2410_gpio_setpin(S3C2410_GPG(4), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(4), S3C2410_GPIO_OUTPUT);
+       WARN_ON(gpio_request(S3C2410_GPG(4), "backlight"));
+       gpio_direction_output(S3C2410_GPG(4), 1);
 
        /* remove pullup on optional PWM backlight -- unused on 3.5 and 7"s */
-       s3c2410_gpio_pullup(S3C2410_GPB(1), 0);
+       s3c_gpio_setpull(S3C2410_GPB(1), S3C_GPIO_PULL_UP);
        s3c2410_gpio_setpin(S3C2410_GPB(1), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPIO_INPUT);
+       s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPIO_INPUT);
 
        /* Make sure the D+ pullup pin is output */
-       s3c2410_gpio_cfgpin(S3C2410_GPC(5), S3C2410_GPIO_OUTPUT);
+       WARN_ON(gpio_request(S3C2410_GPC(5), "udc pup"));
+       gpio_direction_output(S3C2410_GPC(5), 0);
 
        /* mark the key as input, without pullups (there is one on the board) */
        for (i = 0; i < ARRAY_SIZE(mini2440_buttons); i++) {
-               s3c2410_gpio_pullup(mini2440_buttons[i].gpio, 0);
-               s3c2410_gpio_cfgpin(mini2440_buttons[i].gpio,
-                                       S3C2410_GPIO_INPUT);
+               s3c_gpio_setpull(mini2440_buttons[i].gpio, S3C_GPIO_PULL_UP);
+               s3c_gpio_cfgpin(mini2440_buttons[i].gpio, S3C2410_GPIO_INPUT);
        }
        if (features.lcd_index != -1) {
                int li;
index 3420415..3ff62de 100644 (file)
@@ -40,6 +40,7 @@
 #include <plat/regs-serial.h>
 #include <plat/iic.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/s3c2410.h>
 #include <plat/s3c244x.h>
 #include <plat/clock.h>
@@ -122,15 +123,15 @@ static void __init nexcoder_sensorboard_init(void)
 {
        // Initialize SCCB bus
        s3c2410_gpio_setpin(S3C2410_GPE(14), 1); // IICSCL
-       s3c2410_gpio_cfgpin(S3C2410_GPE(14), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPE(14), S3C2410_GPIO_OUTPUT);
        s3c2410_gpio_setpin(S3C2410_GPE(15), 1); // IICSDA
-       s3c2410_gpio_cfgpin(S3C2410_GPE(15), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPE(15), S3C2410_GPIO_OUTPUT);
 
        // Power up the sensor board
        s3c2410_gpio_setpin(S3C2410_GPF(1), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(1), S3C2410_GPIO_OUTPUT); // CAM_GPIO7 => nLDO_PWRDN
+       s3c_gpio_cfgpin(S3C2410_GPF(1), S3C2410_GPIO_OUTPUT); // CAM_GPIO7 => nLDO_PWRDN
        s3c2410_gpio_setpin(S3C2410_GPF(2), 0);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(2), S3C2410_GPIO_OUTPUT); // CAM_GPIO6 => CAM_PWRDN
+       s3c_gpio_cfgpin(S3C2410_GPF(2), S3C2410_GPIO_OUTPUT); // CAM_GPIO6 => CAM_PWRDN
 }
 
 static void __init nexcoder_map_io(void)
index f35371d..319458d 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/mtd/nand_ecc.h>
 #include <linux/mtd/partitions.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/clock.h>
 #include <plat/devs.h>
 #include <plat/cpu.h>
@@ -298,7 +299,7 @@ static int osiris_pm_suspend(struct sys_device *sd, pm_message_t state)
 
        /* ensure that an nRESET is not generated on resume. */
        s3c2410_gpio_setpin(S3C2410_GPA(21), 1);
-       s3c2410_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPIO_OUTPUT);
 
        return 0;
 }
@@ -310,7 +311,7 @@ static int osiris_pm_resume(struct sys_device *sd)
 
        __raw_writeb(pm_osiris_ctrl0, OSIRIS_VA_CTRL0);
 
-       s3c2410_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPA21_nRSTOUT);
+       s3c_gpio_cfgpin(S3C2410_GPA(21), S3C2410_GPA21_nRSTOUT);
 
        return 0;
 }
diff --git a/arch/arm/mach-s3c2440/mach-rx1950.c b/arch/arm/mach-s3c2440/mach-rx1950.c
new file mode 100644 (file)
index 0000000..8603b57
--- /dev/null
@@ -0,0 +1,582 @@
+/* linux/arch/arm/mach-s3c2440/mach-rx1950.c
+ *
+ * Copyright (c) 2006-2009 Victor Chukhantsev, Denis Grigoriev,
+ * Copyright (c) 2007-2010 Vasily Khoruzhick
+ *
+ * based on smdk2440 written by Ben Dooks
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/delay.h>
+#include <linux/timer.h>
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/serial_core.h>
+#include <linux/input.h>
+#include <linux/gpio_keys.h>
+#include <linux/sysdev.h>
+#include <linux/pwm_backlight.h>
+#include <linux/pwm.h>
+
+#include <linux/mtd/mtd.h>
+#include <linux/mtd/partitions.h>
+
+#include <linux/mmc/host.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach-types.h>
+
+#include <mach/regs-gpio.h>
+#include <mach/regs-gpioj.h>
+#include <mach/h1940.h>
+#include <mach/fb.h>
+
+#include <plat/clock.h>
+#include <plat/regs-serial.h>
+#include <plat/regs-iic.h>
+#include <plat/mci.h>
+#include <plat/udc.h>
+#include <plat/nand.h>
+#include <plat/iic.h>
+#include <plat/devs.h>
+#include <plat/cpu.h>
+#include <plat/pm.h>
+#include <plat/irq.h>
+#include <plat/ts.h>
+
+#define LCD_PWM_PERIOD 192960
+#define LCD_PWM_DUTY 127353
+
+static struct map_desc rx1950_iodesc[] __initdata = {
+};
+
+static struct s3c24xx_uart_clksrc rx1950_serial_clocks[] = {
+       [0] = {
+              .name = "fclk",
+              .divisor = 0x0a,
+              .min_baud = 0,
+              .max_baud = 0,
+       },
+};
+
+static struct s3c2410_uartcfg rx1950_uartcfgs[] __initdata = {
+       [0] = {
+              .hwport = 0,
+              .flags = 0,
+              .ucon = 0x3c5,
+              .ulcon = 0x03,
+              .ufcon = 0x51,
+              .clocks = rx1950_serial_clocks,
+              .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
+       },
+       [1] = {
+              .hwport = 1,
+              .flags = 0,
+              .ucon = 0x3c5,
+              .ulcon = 0x03,
+              .ufcon = 0x51,
+              .clocks = rx1950_serial_clocks,
+              .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
+       },
+       /* IR port */
+       [2] = {
+              .hwport = 2,
+              .flags = 0,
+              .ucon = 0x3c5,
+              .ulcon = 0x43,
+              .ufcon = 0xf1,
+              .clocks = rx1950_serial_clocks,
+              .clocks_size = ARRAY_SIZE(rx1950_serial_clocks),
+       },
+};
+
+static struct s3c2410fb_display rx1950_display = {
+       .type = S3C2410_LCDCON1_TFT,
+       .width = 240,
+       .height = 320,
+       .xres = 240,
+       .yres = 320,
+       .bpp = 16,
+
+       .pixclock = 260000,
+       .left_margin = 10,
+       .right_margin = 20,
+       .hsync_len = 10,
+       .upper_margin = 2,
+       .lower_margin = 2,
+       .vsync_len = 2,
+
+       .lcdcon5 = S3C2410_LCDCON5_FRM565 |
+                          S3C2410_LCDCON5_INVVCLK |
+                          S3C2410_LCDCON5_INVVLINE |
+                          S3C2410_LCDCON5_INVVFRAME |
+                          S3C2410_LCDCON5_HWSWP |
+                          (0x02 << 13) |
+                          (0x02 << 15),
+
+};
+
+static struct s3c2410fb_mach_info rx1950_lcd_cfg = {
+       .displays = &rx1950_display,
+       .num_displays = 1,
+       .default_display = 0,
+
+       .lpcsel = 0x02,
+       .gpccon = 0xaa9556a9,
+       .gpccon_mask = 0xffc003fc,
+       .gpcup = 0x0000ffff,
+       .gpcup_mask = 0xffffffff,
+
+       .gpdcon = 0xaa90aaa1,
+       .gpdcon_mask = 0xffc0fff0,
+       .gpdup = 0x0000fcfd,
+       .gpdup_mask = 0xffffffff,
+
+};
+
+static struct pwm_device *lcd_pwm;
+
+void rx1950_lcd_power(int enable)
+{
+       int i;
+       static int enabled;
+       if (enabled == enable)
+               return;
+       if (!enable) {
+
+               /* GPC11-GPC15->OUTPUT */
+               for (i = 11; i < 16; i++)
+                       gpio_direction_output(S3C2410_GPC(i), 1);
+
+               /* Wait a bit here... */
+               mdelay(100);
+
+               /* GPD2-GPD7->OUTPUT */
+               /* GPD11-GPD15->OUTPUT */
+               /* GPD2-GPD7->1, GPD11-GPD15->1 */
+               for (i = 2; i < 8; i++)
+                       gpio_direction_output(S3C2410_GPD(i), 1);
+               for (i = 11; i < 16; i++)
+                       gpio_direction_output(S3C2410_GPD(i), 1);
+
+               /* Wait a bit here...*/
+               mdelay(100);
+
+               /* GPB0->OUTPUT, GPB0->0 */
+               gpio_direction_output(S3C2410_GPB(0), 0);
+
+               /* GPC1-GPC4->OUTPUT, GPC1-4->0 */
+               for (i = 1; i < 5; i++)
+                       gpio_direction_output(S3C2410_GPC(i), 0);
+
+               /* GPC15-GPC11->0 */
+               for (i = 11; i < 16; i++)
+                       gpio_direction_output(S3C2410_GPC(i), 0);
+
+               /* GPD15-GPD11->0, GPD2->GPD7->0 */
+               for (i = 11; i < 16; i++)
+                       gpio_direction_output(S3C2410_GPD(i), 0);
+
+               for (i = 2; i < 8; i++)
+                       gpio_direction_output(S3C2410_GPD(i), 0);
+
+               /* GPC6->0, GPC7->0, GPC5->0 */
+               gpio_direction_output(S3C2410_GPC(6), 0);
+               gpio_direction_output(S3C2410_GPC(7), 0);
+               gpio_direction_output(S3C2410_GPC(5), 0);
+
+               /* GPB1->OUTPUT, GPB1->0 */
+               gpio_direction_output(S3C2410_GPB(1), 0);
+               pwm_config(lcd_pwm, 0, LCD_PWM_PERIOD);
+               pwm_disable(lcd_pwm);
+
+               /* GPC0->0, GPC10->0 */
+               gpio_direction_output(S3C2410_GPC(0), 0);
+               gpio_direction_output(S3C2410_GPC(10), 0);
+       } else {
+               pwm_config(lcd_pwm, LCD_PWM_DUTY, LCD_PWM_PERIOD);
+               pwm_enable(lcd_pwm);
+
+               gpio_direction_output(S3C2410_GPC(0), 1);
+               gpio_direction_output(S3C2410_GPC(5), 1);
+
+               s3c_gpio_cfgpin(S3C2410_GPB(1), S3C2410_GPB1_TOUT1);
+               gpio_direction_output(S3C2410_GPC(7), 1);
+
+               for (i = 1; i < 5; i++)
+                       s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
+
+               for (i = 11; i < 16; i++)
+                       s3c_gpio_cfgpin(S3C2410_GPC(i), S3C_GPIO_SFN(2));
+
+               for (i = 2; i < 8; i++)
+                       s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
+
+               for (i = 11; i < 16; i++)
+                       s3c_gpio_cfgpin(S3C2410_GPD(i), S3C_GPIO_SFN(2));
+
+               gpio_direction_output(S3C2410_GPC(10), 1);
+               gpio_direction_output(S3C2410_GPC(6), 1);
+       }
+       enabled = enable;
+}
+
+static void rx1950_bl_power(int enable)
+{
+       static int enabled;
+       if (enabled == enable)
+               return;
+       if (!enable) {
+                       gpio_direction_output(S3C2410_GPB(0), 0);
+       } else {
+                       /* LED driver need a "push" to power on */
+                       gpio_direction_output(S3C2410_GPB(0), 1);
+                       /* Warm up backlight for one period of PWM.
+                        * Without this trick its almost impossible to
+                        * enable backlight with low brightness value
+                        */
+                       ndelay(48000);
+                       s3c_gpio_cfgpin(S3C2410_GPB(0), S3C2410_GPB0_TOUT0);
+       }
+       enabled = enable;
+}
+
+static int rx1950_backlight_init(struct device *dev)
+{
+       WARN_ON(gpio_request(S3C2410_GPB(0), "Backlight"));
+       lcd_pwm = pwm_request(1, "RX1950 LCD");
+       if (IS_ERR(lcd_pwm)) {
+               dev_err(dev, "Unable to request PWM for LCD power!\n");
+               return PTR_ERR(lcd_pwm);
+       }
+
+       rx1950_lcd_power(1);
+       rx1950_bl_power(1);
+
+       return 0;
+}
+
+static void rx1950_backlight_exit(struct device *dev)
+{
+       rx1950_bl_power(0);
+       rx1950_lcd_power(0);
+
+       pwm_free(lcd_pwm);
+       gpio_free(S3C2410_GPB(0));
+}
+
+
+static int rx1950_backlight_notify(struct device *dev, int brightness)
+{
+       if (!brightness) {
+               rx1950_bl_power(0);
+               rx1950_lcd_power(0);
+       } else {
+               rx1950_lcd_power(1);
+               rx1950_bl_power(1);
+       }
+       return brightness;
+}
+
+static struct platform_pwm_backlight_data rx1950_backlight_data = {
+       .pwm_id = 0,
+       .max_brightness = 24,
+       .dft_brightness = 4,
+       .pwm_period_ns = 48000,
+       .init = rx1950_backlight_init,
+       .notify = rx1950_backlight_notify,
+       .exit = rx1950_backlight_exit,
+};
+
+static struct platform_device rx1950_backlight = {
+       .name = "pwm-backlight",
+       .dev = {
+               .parent = &s3c_device_timer[0].dev,
+               .platform_data = &rx1950_backlight_data,
+       },
+};
+
+static void rx1950_set_mmc_power(unsigned char power_mode, unsigned short vdd)
+{
+       switch (power_mode) {
+       case MMC_POWER_OFF:
+               gpio_direction_output(S3C2410_GPJ(1), 0);
+               break;
+       case MMC_POWER_UP:
+       case MMC_POWER_ON:
+               gpio_direction_output(S3C2410_GPJ(1), 1);
+               break;
+       default:
+               break;
+       }
+}
+
+static struct s3c24xx_mci_pdata rx1950_mmc_cfg __initdata = {
+       .gpio_detect = S3C2410_GPF(5),
+       .gpio_wprotect = S3C2410_GPH(8),
+       .set_power = rx1950_set_mmc_power,
+       .ocr_avail = MMC_VDD_32_33,
+};
+
+static struct mtd_partition rx1950_nand_part[] = {
+       [0] = {
+                       .name = "Boot0",
+                       .offset = 0,
+                       .size = 0x4000,
+                       .mask_flags = MTD_WRITEABLE,
+       },
+       [1] = {
+                       .name = "Boot1",
+                       .offset = MTDPART_OFS_APPEND,
+                       .size = 0x40000,
+                       .mask_flags = MTD_WRITEABLE,
+       },
+       [2] = {
+                       .name = "Kernel",
+                       .offset = MTDPART_OFS_APPEND,
+                       .size = 0x300000,
+                       .mask_flags = 0,
+       },
+       [3] = {
+                       .name = "Filesystem",
+                       .offset = MTDPART_OFS_APPEND,
+                       .size = MTDPART_SIZ_FULL,
+                       .mask_flags = 0,
+       },
+};
+
+static struct s3c2410_nand_set rx1950_nand_sets[] = {
+       [0] = {
+                       .name = "Internal",
+                       .nr_chips = 1,
+                       .nr_partitions = ARRAY_SIZE(rx1950_nand_part),
+                       .partitions = rx1950_nand_part,
+       },
+};
+
+static struct s3c2410_platform_nand rx1950_nand_info = {
+       .tacls = 25,
+       .twrph0 = 50,
+       .twrph1 = 15,
+       .nr_sets = ARRAY_SIZE(rx1950_nand_sets),
+       .sets = rx1950_nand_sets,
+};
+
+static void rx1950_udc_pullup(enum s3c2410_udc_cmd_e cmd)
+{
+       switch (cmd) {
+       case S3C2410_UDC_P_ENABLE:
+               gpio_direction_output(S3C2410_GPJ(5), 1);
+               break;
+       case S3C2410_UDC_P_DISABLE:
+               gpio_direction_output(S3C2410_GPJ(5), 0);
+               break;
+       case S3C2410_UDC_P_RESET:
+               break;
+       default:
+               break;
+       }
+}
+
+static struct s3c2410_udc_mach_info rx1950_udc_cfg __initdata = {
+       .udc_command = rx1950_udc_pullup,
+       .vbus_pin = S3C2410_GPG(5),
+       .vbus_pin_inverted = 1,
+};
+
+static struct s3c2410_ts_mach_info rx1950_ts_cfg __initdata = {
+       .delay = 10000,
+       .presc = 49,
+       .oversampling_shift = 3,
+};
+
+static struct gpio_keys_button rx1950_gpio_keys_table[] = {
+       {
+               .code           = KEY_POWER,
+               .gpio           = S3C2410_GPF(0),
+               .active_low     = 1,
+               .desc           = "Power button",
+               .wakeup         = 1,
+       },
+       {
+               .code           = KEY_F5,
+               .gpio           = S3C2410_GPF(7),
+               .active_low     = 1,
+               .desc           = "Record button",
+       },
+       {
+               .code           = KEY_F1,
+               .gpio           = S3C2410_GPG(0),
+               .active_low     = 1,
+               .desc           = "Calendar button",
+       },
+       {
+               .code           = KEY_F2,
+               .gpio           = S3C2410_GPG(2),
+               .active_low     = 1,
+               .desc           = "Contacts button",
+       },
+       {
+               .code           = KEY_F3,
+               .gpio           = S3C2410_GPG(3),
+               .active_low     = 1,
+               .desc           = "Mail button",
+       },
+       {
+               .code           = KEY_F4,
+               .gpio           = S3C2410_GPG(7),
+               .active_low     = 1,
+               .desc           = "WLAN button",
+       },
+       {
+               .code           = KEY_LEFT,
+               .gpio           = S3C2410_GPG(10),
+               .active_low     = 1,
+               .desc           = "Left button",
+       },
+       {
+               .code           = KEY_RIGHT,
+               .gpio           = S3C2410_GPG(11),
+               .active_low     = 1,
+               .desc           = "Right button",
+       },
+       {
+               .code           = KEY_UP,
+               .gpio           = S3C2410_GPG(4),
+               .active_low     = 1,
+               .desc           = "Up button",
+       },
+       {
+               .code           = KEY_DOWN,
+               .gpio           = S3C2410_GPG(6),
+               .active_low     = 1,
+               .desc           = "Down button",
+       },
+       {
+               .code           = KEY_ENTER,
+               .gpio           = S3C2410_GPG(9),
+               .active_low     = 1,
+               .desc           = "Ok button"
+       },
+};
+
+static struct gpio_keys_platform_data rx1950_gpio_keys_data = {
+       .buttons = rx1950_gpio_keys_table,
+       .nbuttons = ARRAY_SIZE(rx1950_gpio_keys_table),
+};
+
+static struct platform_device rx1950_device_gpiokeys = {
+       .name = "gpio-keys",
+       .dev.platform_data = &rx1950_gpio_keys_data,
+};
+
+static struct s3c2410_platform_i2c rx1950_i2c_data = {
+       .flags = 0,
+       .slave_addr = 0x42,
+       .frequency = 400 * 1000,
+       .sda_delay = S3C2410_IICLC_SDA_DELAY5 | S3C2410_IICLC_FILTER_ON,
+};
+
+static struct platform_device *rx1950_devices[] __initdata = {
+       &s3c_device_lcd,
+       &s3c_device_wdt,
+       &s3c_device_i2c0,
+       &s3c_device_iis,
+       &s3c_device_usbgadget,
+       &s3c_device_rtc,
+       &s3c_device_nand,
+       &s3c_device_sdi,
+       &s3c_device_adc,
+       &s3c_device_ts,
+       &s3c_device_timer[0],
+       &s3c_device_timer[1],
+       &rx1950_backlight,
+       &rx1950_device_gpiokeys,
+};
+
+static struct clk *rx1950_clocks[] __initdata = {
+       &s3c24xx_clkout0,
+       &s3c24xx_clkout1,
+};
+
+static void __init rx1950_map_io(void)
+{
+       s3c24xx_clkout0.parent  = &clk_h;
+       s3c24xx_clkout1.parent  = &clk_f;
+
+       s3c24xx_register_clocks(rx1950_clocks, ARRAY_SIZE(rx1950_clocks));
+
+       s3c24xx_init_io(rx1950_iodesc, ARRAY_SIZE(rx1950_iodesc));
+       s3c24xx_init_clocks(16934000);
+       s3c24xx_init_uarts(rx1950_uartcfgs, ARRAY_SIZE(rx1950_uartcfgs));
+
+       /* setup PM */
+
+#ifdef CONFIG_PM_H1940
+       memcpy(phys_to_virt(H1940_SUSPEND_RESUMEAT), h1940_pm_return, 8);
+#endif
+
+       s3c_pm_init();
+}
+
+static void __init rx1950_init_machine(void)
+{
+       int i;
+
+       s3c24xx_fb_set_platdata(&rx1950_lcd_cfg);
+       s3c24xx_udc_set_platdata(&rx1950_udc_cfg);
+       s3c24xx_ts_set_platdata(&rx1950_ts_cfg);
+       s3c24xx_mci_set_platdata(&rx1950_mmc_cfg);
+       s3c_i2c0_set_platdata(&rx1950_i2c_data);
+       s3c_nand_set_platdata(&rx1950_nand_info);
+
+       /* Turn off suspend on both USB ports, and switch the
+        * selectable USB port to USB device mode. */
+       s3c2410_modify_misccr(S3C2410_MISCCR_USBHOST |
+                                               S3C2410_MISCCR_USBSUSPND0 |
+                                               S3C2410_MISCCR_USBSUSPND1, 0x0);
+
+       WARN_ON(gpio_request(S3C2410_GPJ(5), "UDC pullup"));
+       gpio_direction_output(S3C2410_GPJ(5), 0);
+
+       /* mmc power is disabled by default */
+       WARN_ON(gpio_request(S3C2410_GPJ(1), "MMC power"));
+       gpio_direction_output(S3C2410_GPJ(1), 0);
+
+       for (i = 0; i < 8; i++)
+               WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
+
+       for (i = 10; i < 16; i++)
+               WARN_ON(gpio_request(S3C2410_GPC(i), "LCD power"));
+
+       for (i = 2; i < 8; i++)
+               WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
+
+       for (i = 11; i < 16; i++)
+               WARN_ON(gpio_request(S3C2410_GPD(i), "LCD power"));
+
+       WARN_ON(gpio_request(S3C2410_GPB(1), "LCD power"));
+
+       platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices));
+}
+
+MACHINE_START(RX1950, "HP iPAQ RX1950")
+    /* Maintainers: Vasily Khoruzhick */
+    .phys_io = S3C2410_PA_UART,
+       .io_pg_offst = (((u32) S3C24XX_VA_UART) >> 18) & 0xfffc,
+       .boot_params = S3C2410_SDRAM_PA + 0x100,
+       .map_io = rx1950_map_io,
+       .init_irq = s3c24xx_init_irq,
+       .init_machine = rx1950_init_machine,
+       .timer = &s3c24xx_timer,
+MACHINE_END
index 1e836e5..d2946de 100644 (file)
@@ -209,7 +209,7 @@ static void __init rx3715_init_machine(void)
 }
 
 MACHINE_START(RX3715, "IPAQ-RX3715")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
index 3ac3d63..df83276 100644 (file)
@@ -174,7 +174,7 @@ static void __init smdk2440_machine_init(void)
 }
 
 MACHINE_START(S3C2440, "SMDK2440")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
index 2b68f7e..d50f3ae 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/platform_device.h>
 #include <linux/serial_core.h>
 #include <linux/sysdev.h>
+#include <linux/gpio.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 
 #include <plat/cpu.h>
 #include <plat/s3c244x.h>
 
+#include <plat/gpio-core.h>
+#include <plat/gpio-cfg.h>
+#include <plat/gpio-cfg-helpers.h>
+
 static struct sys_device s3c2440_sysdev = {
        .cls            = &s3c2440_sysclass,
 };
@@ -41,6 +46,9 @@ int __init s3c2440_init(void)
 {
        printk("S3C2440: Initialising architecture\n");
 
+       s3c24xx_gpiocfg_default.set_pull = s3c_gpio_setpull_1up;
+       s3c24xx_gpiocfg_default.get_pull = s3c_gpio_getpull_1up;
+
        /* change irq for watchdog */
 
        s3c_device_wdt.resource[1].start = IRQ_S3C2440_WDT;
index 698140a..4fef723 100644 (file)
@@ -8,6 +8,7 @@ config CPU_S3C2443
        select S3C2443_DMA if S3C2410_DMA
        select CPU_LLSERIAL_S3C2440
        select SAMSUNG_CLKSRC
+       select S3C2443_CLOCK
        help
          Support for the S3C2443 SoC from the S3C24XX line
 
index 62cd4ea..0c3c0c8 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include <linux/init.h>
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
  * set the correct muxing at initialisation
 */
 
-static int s3c2443_gate(void __iomem *reg, struct clk *clk, int enable)
-{
-       u32 ctrlbit = clk->ctrlbit;
-       u32 con = __raw_readl(reg);
-
-       if (enable)
-               con |= ctrlbit;
-       else
-               con &= ~ctrlbit;
-
-       __raw_writel(con, reg);
-       return 0;
-}
-
-static int s3c2443_clkcon_enable_h(struct clk *clk, int enable)
-{
-       return s3c2443_gate(S3C2443_HCLKCON, clk, enable);
-}
-
-static int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
-{
-       return s3c2443_gate(S3C2443_PCLKCON, clk, enable);
-}
-
-static int s3c2443_clkcon_enable_s(struct clk *clk, int enable)
-{
-       return s3c2443_gate(S3C2443_SCLKCON, clk, enable);
-}
-
 /* clock selections */
 
-/* mpllref is a direct descendant of clk_xtal by default, but it is not
- * elided as the EPLL can be either sourced by the XTAL or EXTCLK and as
- * such directly equating the two source clocks is impossible.
- */
-static struct clk clk_mpllref = {
-       .name           = "mpllref",
-       .parent         = &clk_xtal,
-       .id             = -1,
-};
-
 static struct clk clk_i2s_ext = {
        .name           = "i2s-ext",
        .id             = -1,
 };
 
-static struct clk *clk_epllref_sources[] = {
-       [0] = &clk_mpllref,
-       [1] = &clk_mpllref,
-       [2] = &clk_xtal,
-       [3] = &clk_ext,
-};
-
-static struct clksrc_clk clk_epllref = {
-       .clk    = {
-               .name           = "epllref",
-               .id             = -1,
-       },
-       .sources = &(struct clksrc_sources) {
-               .sources = clk_epllref_sources,
-               .nr_sources = ARRAY_SIZE(clk_epllref_sources),
-       },
-       .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 7 },
-};
-
-static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
-{
-       unsigned long parent_rate = clk_get_rate(clk->parent);
-       unsigned long div = __raw_readl(S3C2443_CLKDIV0);
-
-       div  &= S3C2443_CLKDIV0_EXTDIV_MASK;
-       div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1);       /* x2 */
-
-       return parent_rate / (div + 1);
-}
-
-static struct clk clk_mdivclk = {
-       .name           = "mdivclk",
-       .parent         = &clk_mpllref,
-       .id             = -1,
-       .ops            = &(struct clk_ops) {
-               .get_rate       = s3c2443_getrate_mdivclk,
-       },
-};
-
-static struct clk *clk_msysclk_sources[] = {
-       [0] = &clk_mpllref,
-       [1] = &clk_mpll,
-       [2] = &clk_mdivclk,
-       [3] = &clk_mpllref,
-};
-
-static struct clksrc_clk clk_msysclk = {
-       .clk    = {
-               .name           = "msysclk",
-               .parent         = &clk_xtal,
-               .id             = -1,
-       },
-       .sources = &(struct clksrc_sources) {
-               .sources = clk_msysclk_sources,
-               .nr_sources = ARRAY_SIZE(clk_msysclk_sources),
-       },
-       .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 3 },
-};
-
 /* armdiv
  *
  * this clock is sourced from msysclk and can have a number of
@@ -266,44 +169,6 @@ static struct clksrc_clk clk_arm = {
        .reg_src = { .reg = S3C2443_CLKDIV0, .size = 1, .shift = 13 },
 };
 
-/* esysclk
- *
- * this is sourced from either the EPLL or the EPLLref clock
-*/
-
-static struct clk *clk_sysclk_sources[] = {
-       [0] = &clk_epllref.clk,
-       [1] = &clk_epll,
-};
-
-static struct clksrc_clk clk_esysclk = {
-       .clk    = {
-               .name           = "esysclk",
-               .parent         = &clk_epll,
-               .id             = -1,
-       },
-       .sources = &(struct clksrc_sources) {
-               .sources = clk_sysclk_sources,
-               .nr_sources = ARRAY_SIZE(clk_sysclk_sources),
-       },
-       .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 6 },
-};
-
-/* uartclk
- *
- * UART baud-rate clock sourced from esysclk via a divisor
-*/
-
-static struct clksrc_clk clk_uart = {
-       .clk    = {
-               .name           = "uartclk",
-               .id             = -1,
-               .parent         = &clk_esysclk.clk,
-       },
-       .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 8 },
-};
-
-
 /* hsspi
  *
  * high-speed spi clock, sourced from esysclk
@@ -320,21 +185,6 @@ static struct clksrc_clk clk_hsspi = {
        .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
 };
 
-/* usbhost
- *
- * usb host bus-clock, usually 48MHz to provide USB bus clock timing
-*/
-
-static struct clksrc_clk clk_usb_bus_host = {
-       .clk    = {
-               .name           = "usb-bus-host-parent",
-               .id             = -1,
-               .parent         = &clk_esysclk.clk,
-               .ctrlbit        = S3C2443_SCLKCON_USBHOST,
-               .enable         = s3c2443_clkcon_enable_s,
-       },
-       .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
-};
 
 /* clk_hsmcc_div
  *
@@ -391,7 +241,7 @@ static struct clk clk_hsmmc = {
 
 /* i2s_eplldiv
  *
- * This clock is the output from the I2S divisor of ESYSCLK, and is seperate
+ * This clock is the output from the I2S divisor of ESYSCLK, and is separate
  * from the mux that comes after it (cannot merge into one single clock)
 */
 
@@ -433,88 +283,15 @@ static struct clksrc_clk clk_i2s = {
        .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 14 },
 };
 
-/* cam-if
- *
- * camera interface bus-clock, divided down from esysclk
-*/
-
-static struct clksrc_clk clk_cam = {
-       .clk    = {
-               .name           = "camif-upll", /* same as 2440 name */
-               .id             = -1,
-               .parent         = &clk_esysclk.clk,
-               .ctrlbit        = S3C2443_SCLKCON_CAMCLK,
-               .enable         = s3c2443_clkcon_enable_s,
-       },
-       .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 26 },
-};
-
-/* display-if
- *
- * display interface clock, divided from esysclk
-*/
-
-static struct clksrc_clk clk_display = {
-       .clk    = {
-               .name           = "display-if",
-               .id             = -1,
-               .parent         = &clk_esysclk.clk,
-               .ctrlbit        = S3C2443_SCLKCON_DISPCLK,
-               .enable         = s3c2443_clkcon_enable_s,
-       },
-       .reg_div = { .reg = S3C2443_CLKDIV1, .size = 8, .shift = 16 },
-};
-
-/* prediv
- *
- * this divides the msysclk down to pass to h/p/etc.
- */
-
-static unsigned long s3c2443_prediv_getrate(struct clk *clk)
-{
-       unsigned long rate = clk_get_rate(clk->parent);
-       unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
-
-       clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
-       clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
-
-       return rate / (clkdiv0 + 1);
-}
-
-static struct clk clk_prediv = {
-       .name           = "prediv",
-       .id             = -1,
-       .parent         = &clk_msysclk.clk,
-       .ops            = &(struct clk_ops) {
-               .get_rate       = s3c2443_prediv_getrate,
-       },
-};
-
 /* standard clock definitions */
 
-static struct clk init_clocks_disable[] = {
+static struct clk init_clocks_off[] = {
        {
-               .name           = "nand",
-               .id             = -1,
-               .parent         = &clk_h,
-       }, {
                .name           = "sdi",
                .id             = -1,
                .parent         = &clk_p,
                .enable         = s3c2443_clkcon_enable_p,
                .ctrlbit        = S3C2443_PCLKCON_SDI,
-       }, {
-               .name           = "adc",
-               .id             = -1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_ADC,
-       }, {
-               .name           = "i2c",
-               .id             = -1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_IIC,
        }, {
                .name           = "iis",
                .id             = -1,
@@ -537,179 +314,12 @@ static struct clk init_clocks_disable[] = {
 };
 
 static struct clk init_clocks[] = {
-       {
-               .name           = "dma",
-               .id             = 0,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA0,
-       }, {
-               .name           = "dma",
-               .id             = 1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA1,
-       }, {
-               .name           = "dma",
-               .id             = 2,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA2,
-       }, {
-               .name           = "dma",
-               .id             = 3,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA3,
-       }, {
-               .name           = "dma",
-               .id             = 4,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA4,
-       }, {
-               .name           = "dma",
-               .id             = 5,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_DMA5,
-       }, {
-               .name           = "lcd",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_LCDC,
-       }, {
-               .name           = "gpio",
-               .id             = -1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_GPIO,
-       }, {
-               .name           = "usb-host",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_USBH,
-       }, {
-               .name           = "usb-device",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_USBD,
-       }, {
-               .name           = "hsmmc",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_HSMMC,
-       }, {
-               .name           = "cfc",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_CFC,
-       }, {
-               .name           = "ssmc",
-               .id             = -1,
-               .parent         = &clk_h,
-               .enable         = s3c2443_clkcon_enable_h,
-               .ctrlbit        = S3C2443_HCLKCON_SSMC,
-       }, {
-               .name           = "timers",
-               .id             = -1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_PWMT,
-       }, {
-               .name           = "uart",
-               .id             = 0,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_UART0,
-       }, {
-               .name           = "uart",
-               .id             = 1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_UART1,
-       }, {
-               .name           = "uart",
-               .id             = 2,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_UART2,
-       }, {
-               .name           = "uart",
-               .id             = 3,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_UART3,
-       }, {
-               .name           = "rtc",
-               .id             = -1,
-               .parent         = &clk_p,
-               .enable         = s3c2443_clkcon_enable_p,
-               .ctrlbit        = S3C2443_PCLKCON_RTC,
-       }, {
-               .name           = "watchdog",
-               .id             = -1,
-               .parent         = &clk_p,
-               .ctrlbit        = S3C2443_PCLKCON_WDT,
-       }, {
-               .name           = "usb-bus-host",
-               .id             = -1,
-               .parent         = &clk_usb_bus_host.clk,
-       }, {
-               .name           = "ac97",
-               .id             = -1,
-               .parent         = &clk_p,
-               .ctrlbit        = S3C2443_PCLKCON_AC97,
-       }
-};
-
-/* clocks to add where we need to check their parentage */
-
-static struct clksrc_clk __initdata *init_list[] = {
-       &clk_epllref, /* should be first */
-       &clk_esysclk,
-       &clk_msysclk,
-       &clk_arm,
-       &clk_i2s_eplldiv,
-       &clk_i2s,
-       &clk_cam,
-       &clk_uart,
-       &clk_display,
-       &clk_hsmmc_div,
-       &clk_usb_bus_host,
 };
 
-static void __init s3c2443_clk_initparents(void)
-{
-       int ptr;
-
-       for (ptr = 0; ptr < ARRAY_SIZE(init_list); ptr++)
-               s3c_set_clksrc(init_list[ptr], true);
-}
-
-static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
-{
-       clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
-
-       return clkcon0 + 1;
-}
-
 /* clocks to add straight away */
 
 static struct clksrc_clk *clksrcs[] __initdata = {
-       &clk_usb_bus_host,
-       &clk_epllref,
-       &clk_esysclk,
-       &clk_msysclk,
        &clk_arm,
-       &clk_uart,
-       &clk_display,
-       &clk_cam,
        &clk_i2s_eplldiv,
        &clk_i2s,
        &clk_hsspi,
@@ -717,92 +327,32 @@ static struct clksrc_clk *clksrcs[] __initdata = {
 };
 
 static struct clk *clks[] __initdata = {
-       &clk_ext,
-       &clk_epll,
-       &clk_usb_bus,
-       &clk_mpllref,
        &clk_hsmmc,
        &clk_armdiv,
-       &clk_prediv,
 };
 
 void __init_or_cpufreq s3c2443_setup_clocks(void)
 {
-       unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
-       unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
-       struct clk *xtal_clk;
-       unsigned long xtal;
-       unsigned long pll;
-       unsigned long fclk;
-       unsigned long hclk;
-       unsigned long pclk;
-
-       xtal_clk = clk_get(NULL, "xtal");
-       xtal = clk_get_rate(xtal_clk);
-       clk_put(xtal_clk);
-
-       pll = s3c2443_get_mpll(mpllcon, xtal);
-       clk_msysclk.clk.rate = pll;
-
-       fclk = pll / s3c2443_fclk_div(clkdiv0);
-       hclk = s3c2443_prediv_getrate(&clk_prediv);
-       hclk /= s3c2443_get_hdiv(clkdiv0);
-       pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
-
-       s3c24xx_setup_clocks(fclk, hclk, pclk);
-
-       printk("S3C2443: mpll %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
-              (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
-              print_mhz(pll), print_mhz(fclk),
-              print_mhz(hclk), print_mhz(pclk));
-
-       s3c24xx_setup_clocks(fclk, hclk, pclk);
+       s3c2443_common_setup_clocks(s3c2443_get_mpll, s3c2443_fclk_div);
 }
 
 void __init s3c2443_init_clocks(int xtal)
 {
-       struct clk *clkp;
        unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
-       int ret;
        int ptr;
 
-       /* s3c2443 parents h and p clocks from prediv */
-       clk_h.parent = &clk_prediv;
-       clk_p.parent = &clk_prediv;
+       clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
+       clk_epll.parent = &clk_epllref.clk;
+
+       s3c2443_common_init_clocks(xtal, s3c2443_get_mpll, s3c2443_fclk_div);
 
-       s3c24xx_register_baseclocks(xtal);
        s3c2443_setup_clocks();
-       s3c2443_clk_initparents();
-
-       for (ptr = 0; ptr < ARRAY_SIZE(clks); ptr++) {
-               clkp = clks[ptr];
 
-               ret = s3c24xx_register_clock(clkp);
-               if (ret < 0) {
-                       printk(KERN_ERR "Failed to register clock %s (%d)\n",
-                              clkp->name, ret);
-               }
-       }
+       s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
 
        for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
                s3c_register_clksrc(clksrcs[ptr], 1);
 
-       clk_epll.rate = s3c2443_get_epll(epllcon, xtal);
-       clk_epll.parent = &clk_epllref.clk;
-       clk_usb_bus.parent = &clk_usb_bus_host.clk;
-
-       /* ensure usb bus clock is within correct rate of 48MHz */
-
-       if (clk_get_rate(&clk_usb_bus_host.clk) != (48 * 1000 * 1000)) {
-               printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
-               clk_set_rate(&clk_usb_bus_host.clk, 48*1000*1000);
-       }
-
-       printk("S3C2443: epll %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
-              (epllcon & S3C2443_PLLCON_OFF) ? "off":"on",
-              print_mhz(clk_get_rate(&clk_epll)),
-              print_mhz(clk_get_rate(&clk_usb_bus)));
-
        /* register clocks from clock array */
 
        s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
@@ -819,17 +369,8 @@ void __init s3c2443_init_clocks(int xtal)
 
        /* install (and disable) the clocks we do not need immediately */
 
-       clkp = init_clocks_disable;
-       for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
-
-               ret = s3c24xx_register_clock(clkp);
-               if (ret < 0) {
-                       printk(KERN_ERR "Failed to register clock %s (%d)\n",
-                              clkp->name, ret);
-               }
-
-               (clkp->enable)(clkp, 0);
-       }
+       s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
+       s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
        s3c_pwmclk_init();
 }
index e2e362b..4c863d3 100644 (file)
@@ -131,7 +131,7 @@ static void __init smdk2443_machine_init(void)
 }
 
 MACHINE_START(SMDK2443, "SMDK2443")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C2410_PA_UART,
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
index 959df38..69e9fbf 100644 (file)
@@ -85,6 +85,7 @@ config MACH_ANW6410
 config MACH_SMDK6410
        bool "SMDK6410"
        select CPU_S3C6410
+       select SAMSUNG_DEV_ADC
        select S3C_DEV_HSMMC
        select S3C_DEV_HSMMC1
        select S3C_DEV_I2C1
index 3758e15..a10f1fc 100644 (file)
@@ -56,7 +56,6 @@ obj-$(CONFIG_MACH_HMT)                += mach-hmt.o
 # device support
 
 obj-y                          += dev-uart.o
-obj-y                          += dev-rtc.o
 obj-y                          += dev-audio.o
-obj-$(CONFIG_S3C_ADC)          += dev-adc.o
 obj-$(CONFIG_S3C64XX_DEV_SPI)  += dev-spi.o
+obj-$(CONFIG_S3C64XX_DEV_TS)   += dev-ts.o
index 2ac2e7d..7a4138b 100644 (file)
@@ -88,6 +88,12 @@ struct clk clk_48m = {
        .enable         = clk_48m_ctrl,
 };
 
+struct clk clk_xusbxti = {
+       .name           = "xusbxti",
+       .id             = -1,
+       .rate           = 48000000,
+};
+
 static int inline s3c64xx_gate(void __iomem *reg,
                                struct clk *clk,
                                int enable)
@@ -518,6 +524,11 @@ static struct clk clk_iis_cd1 = {
        .id             = -1,
 };
 
+static struct clk clk_iisv4_cd = {
+       .name           = "iis_cdclk_v4",
+       .id             = -1,
+};
+
 static struct clk clk_pcm_cd = {
        .name           = "pcm_cdclk",
        .id             = -1,
@@ -549,6 +560,19 @@ static struct clksrc_sources clkset_audio1 = {
        .nr_sources     = ARRAY_SIZE(clkset_audio1_list),
 };
 
+static struct clk *clkset_audio2_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_dout_mpll,
+       [2] = &clk_fin_epll,
+       [3] = &clk_iisv4_cd,
+       [4] = &clk_pcm_cd,
+};
+
+static struct clksrc_sources clkset_audio2 = {
+       .sources        = clkset_audio2_list,
+       .nr_sources     = ARRAY_SIZE(clkset_audio2_list),
+};
+
 static struct clk *clkset_camif_list[] = {
        &clk_h2,
 };
@@ -650,6 +674,16 @@ static struct clksrc_clk clksrcs[] = {
                .reg_src        = { .reg = S3C_CLK_SRC, .shift = 10, .size = 3  },
                .reg_div        = { .reg = S3C_CLK_DIV2, .shift = 12, .size = 4  },
                .sources        = &clkset_audio1,
+       }, {
+               .clk    = {
+                       .name           = "audio-bus",
+                       .id             = -1,  /* There's only one IISv4 port */
+                       .ctrlbit        = S3C6410_CLKCON_SCLK_AUDIO2,
+                       .enable         = s3c64xx_sclk_ctrl,
+               },
+               .reg_src        = { .reg = S3C6410_CLK_SRC2, .shift = 0, .size = 3  },
+               .reg_div        = { .reg = S3C_CLK_DIV2, .shift = 24, .size = 4  },
+               .sources        = &clkset_audio2,
        }, {
                .clk    = {
                        .name           = "irda-bus",
@@ -749,6 +783,7 @@ static struct clk *clks1[] __initdata = {
        &clk_ext_xtal_mux,
        &clk_iis_cd0,
        &clk_iis_cd1,
+       &clk_iisv4_cd,
        &clk_pcm_cd,
        &clk_mout_epll.clk,
        &clk_mout_mpll.clk,
@@ -762,6 +797,7 @@ static struct clk *clks[] __initdata = {
        &clk_27m,
        &clk_48m,
        &clk_h2,
+       &clk_xusbxti,
 };
 
 /**
index 33ccf7b..5567e03 100644 (file)
@@ -414,7 +414,7 @@ err_buff:
 EXPORT_SYMBOL(s3c2410_dma_enqueue);
 
 
-int s3c2410_dma_devconfig(int channel,
+int s3c2410_dma_devconfig(unsigned int channel,
                          enum s3c2410_dmasrc source,
                          unsigned long devaddr)
 {
index 66e6794..60c929a 100644 (file)
@@ -51,6 +51,7 @@
 
 static struct s3c_gpio_cfg gpio_4bit_cfg_noint = {
        .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
+       .get_config     = s3c_gpio_getcfg_s3c64xx_4bit,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
 };
@@ -58,12 +59,14 @@ static struct s3c_gpio_cfg gpio_4bit_cfg_noint = {
 static struct s3c_gpio_cfg gpio_4bit_cfg_eint0111 = {
        .cfg_eint       = 7,
        .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
+       .get_config     = s3c_gpio_getcfg_s3c64xx_4bit,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
 };
 
 static struct s3c_gpio_cfg gpio_4bit_cfg_eint0011 = {
        .cfg_eint       = 3,
+       .get_config     = s3c_gpio_getcfg_s3c64xx_4bit,
        .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
@@ -171,6 +174,7 @@ static struct s3c_gpio_chip gpio_4bit2[] = {
 
 static struct s3c_gpio_cfg gpio_2bit_cfg_noint = {
        .set_config     = s3c_gpio_setcfg_s3c24xx,
+       .get_config     = s3c_gpio_getcfg_s3c24xx,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
 };
@@ -178,6 +182,7 @@ static struct s3c_gpio_cfg gpio_2bit_cfg_noint = {
 static struct s3c_gpio_cfg gpio_2bit_cfg_eint10 = {
        .cfg_eint       = 2,
        .set_config     = s3c_gpio_setcfg_s3c24xx,
+       .get_config     = s3c_gpio_getcfg_s3c24xx,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
 };
@@ -185,6 +190,7 @@ static struct s3c_gpio_cfg gpio_2bit_cfg_eint10 = {
 static struct s3c_gpio_cfg gpio_2bit_cfg_eint11 = {
        .cfg_eint       = 3,
        .set_config     = s3c_gpio_setcfg_s3c24xx,
+       .get_config     = s3c_gpio_getcfg_s3c24xx,
        .set_pull       = s3c_gpio_setpull_updown,
        .get_pull       = s3c_gpio_getpull_updown,
 };
index 801c1c0..9fdd50c 100644 (file)
 #define S3C_PA_USBHOST         S3C64XX_PA_USBHOST
 #define S3C_PA_USB_HSOTG       S3C64XX_PA_USB_HSOTG
 #define S3C_VA_USB_HSPHY       S3C64XX_VA_USB_HSPHY
+#define S3C_PA_RTC             S3C64XX_PA_RTC
+
+#define SAMSUNG_PA_ADC         S3C64XX_PA_ADC
 
 #endif /* __ASM_ARCH_6400_MAP_H */
index 90bbd72..5ef0bb6 100644 (file)
@@ -20,6 +20,7 @@
 #define S3C6400_PLL_SDIV_SHIFT (0)
 
 #include <asm/div64.h>
+#include <plat/pll6553x.h>
 
 static inline unsigned long s3c6400_get_pll(unsigned long baseclk,
                                            u32 pllcon)
@@ -37,38 +38,8 @@ static inline unsigned long s3c6400_get_pll(unsigned long baseclk,
        return (unsigned long)fvco;
 }
 
-#define S3C6400_EPLL_MDIV_MASK ((1 << (23-16)) - 1)
-#define S3C6400_EPLL_PDIV_MASK ((1 << (13-8)) - 1)
-#define S3C6400_EPLL_SDIV_MASK ((1 << (2-0)) - 1)
-#define S3C6400_EPLL_MDIV_SHIFT        (16)
-#define S3C6400_EPLL_PDIV_SHIFT        (8)
-#define S3C6400_EPLL_SDIV_SHIFT        (0)
-#define S3C6400_EPLL_KDIV_MASK  (0xffff)
-
 static inline unsigned long s3c6400_get_epll(unsigned long baseclk)
 {
-       unsigned long result;
-       u32 epll0 = __raw_readl(S3C_EPLL_CON0);
-       u32 epll1 = __raw_readl(S3C_EPLL_CON1);
-       u32 mdiv, pdiv, sdiv, kdiv;
-       u64 tmp;
-
-       mdiv = (epll0 >> S3C6400_EPLL_MDIV_SHIFT) & S3C6400_EPLL_MDIV_MASK;
-       pdiv = (epll0 >> S3C6400_EPLL_PDIV_SHIFT) & S3C6400_EPLL_PDIV_MASK;
-       sdiv = (epll0 >> S3C6400_EPLL_SDIV_SHIFT) & S3C6400_EPLL_SDIV_MASK;
-       kdiv = epll1 & S3C6400_EPLL_KDIV_MASK;
-
-       /* We need to multiple baseclk by mdiv (the integer part) and kdiv
-        * which is in 2^16ths, so shift mdiv up (does not overflow) and
-        * add kdiv before multiplying. The use of tmp is to avoid any
-        * overflows before shifting bac down into result when multipling
-        * by the mdiv and kdiv pair.
-        */
-
-       tmp = baseclk;
-       tmp *= (mdiv << 16) + kdiv;
-       do_div(tmp, (pdiv << sdiv));
-       result = tmp >> 16;
-
-       return result;
+       return s3c_get_pll6553x(baseclk, __raw_readl(S3C_EPLL_CON0),
+                               __raw_readl(S3C_EPLL_CON1));
 }
index 3ef6274..0114eb0 100644 (file)
@@ -33,6 +33,7 @@
 #define S3C_PCLK_GATE          S3C_CLKREG(0x34)
 #define S3C_SCLK_GATE          S3C_CLKREG(0x38)
 #define S3C_MEM0_GATE          S3C_CLKREG(0x3C)
+#define S3C6410_CLK_SRC2       S3C_CLKREG(0x10C)
 
 /* CLKDIV0 */
 #define S3C6400_CLKDIV0_PCLK_MASK      (0xf << 12)
index f7b1898..5991667 100644 (file)
@@ -84,7 +84,7 @@ static void __init smdk6400_machine_init(void)
 }
 
 MACHINE_START(SMDK6400, "SMDK6400")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C_PA_UART & 0xfff00000,
        .io_pg_offst    = (((u32)S3C_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C64XX_PA_SDRAM + 0x100,
index 2d5afd2..9d51455 100644 (file)
@@ -656,7 +656,7 @@ static void __init smdk6410_machine_init(void)
 }
 
 MACHINE_START(SMDK6410, "SMDK6410")
-       /* Maintainer: Ben Dooks <ben@fluff.org> */
+       /* Maintainer: Ben Dooks <ben-linux@fluff.org> */
        .phys_io        = S3C_PA_UART & 0xfff00000,
        .io_pg_offst    = (((u32)S3C_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C64XX_PA_SDRAM + 0x100,
index 59635d1..3ab695c 100644 (file)
@@ -38,6 +38,7 @@
 #include <plat/clock.h>
 #include <plat/sdhci.h>
 #include <plat/iic-core.h>
+#include <plat/adc.h>
 #include <mach/s3c6400.h>
 #include <mach/s3c6410.h>
 
@@ -52,6 +53,7 @@ void __init s3c6410_map_io(void)
        s3c_i2c0_setname("s3c2440-i2c");
        s3c_i2c1_setname("s3c2440-i2c");
 
+       s3c_device_adc.name     = "s3c64xx-adc";
        s3c_device_nand.name = "s3c6400-nand";
 }
 
index 4c29ff8..77aeffd 100644 (file)
@@ -9,6 +9,7 @@ if ARCH_S5P6440
 
 config CPU_S5P6440
        bool
+       select S3C_PL330_DMA
        help
          Enable S5P6440 CPU support
 
index 1ad894b..44facf4 100644 (file)
@@ -12,8 +12,12 @@ obj-                         :=
 
 # Core support for S5P6440 system
 
-obj-$(CONFIG_CPU_S5P6440)      += cpu.o init.o clock.o gpio.o
+obj-$(CONFIG_CPU_S5P6440)      += cpu.o init.o clock.o gpio.o dma.o
+obj-$(CONFIG_CPU_S5P6440)      += setup-i2c0.o
 
 # machine support
 
 obj-$(CONFIG_MACH_SMDK6440)    += mach-smdk6440.o
+
+# device support
+obj-y                          += dev-audio.o
index b2672e1..ca6e48d 100644 (file)
@@ -134,24 +134,6 @@ static struct clksrc_clk clk_mout_mpll = {
        .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 1, .size = 1 },
 };
 
-static struct clk clk_h_low = {
-       .name           = "hclk_low",
-       .id             = -1,
-       .rate           = 0,
-       .parent         = NULL,
-       .ctrlbit        = 0,
-       .ops            = &clk_ops_def_setrate,
-};
-
-static struct clk clk_p_low = {
-       .name           = "pclk_low",
-       .id             = -1,
-       .rate           = 0,
-       .parent         = NULL,
-       .ctrlbit        = 0,
-       .ops            = &clk_ops_def_setrate,
-};
-
 enum perf_level {
        L0 = 532*1000,
        L1 = 266*1000,
@@ -247,23 +229,70 @@ static struct clk_ops s5p6440_clkarm_ops = {
        .round_rate     = s5p6440_armclk_round_rate,
 };
 
-static unsigned long s5p6440_clk_doutmpll_get_rate(struct clk *clk)
-{
-       unsigned long rate = clk_get_rate(clk->parent);
+static struct clksrc_clk clk_armclk = {
+       .clk    = {
+               .name   = "armclk",
+               .id     = 1,
+               .parent = &clk_mout_apll.clk,
+               .ops    = &s5p6440_clkarm_ops,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 0, .size = 4 },
+};
 
-       if (__raw_readl(S5P_CLK_DIV0) & S5P_CLKDIV0_MPLL_MASK)
-               rate /= 2;
+static struct clksrc_clk clk_dout_mpll = {
+       .clk    = {
+               .name   = "dout_mpll",
+               .id     = -1,
+               .parent = &clk_mout_mpll.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 4, .size = 1 },
+};
 
-       return rate;
-}
+static struct clksrc_clk clk_hclk = {
+       .clk    = {
+               .name   = "clk_hclk",
+               .id     = -1,
+               .parent = &clk_armclk.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 8, .size = 4 },
+};
 
-static struct clk clk_dout_mpll = {
-       .name           = "dout_mpll",
-       .id             = -1,
-       .parent         = &clk_mout_mpll.clk,
-       .ops            = &(struct clk_ops) {
-               .get_rate       = s5p6440_clk_doutmpll_get_rate,
+static struct clksrc_clk clk_pclk = {
+       .clk    = {
+               .name   = "clk_pclk",
+               .id     = -1,
+               .parent = &clk_hclk.clk,
        },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 12, .size = 4 },
+};
+
+static struct clk *clkset_hclklow_list[] = {
+       &clk_mout_apll.clk,
+       &clk_mout_mpll.clk,
+};
+
+static struct clksrc_sources clkset_hclklow = {
+       .sources        = clkset_hclklow_list,
+       .nr_sources     = ARRAY_SIZE(clkset_hclklow_list),
+};
+
+static struct clksrc_clk clk_hclk_low = {
+       .clk = {
+               .name   = "hclk_low",
+               .id     = -1,
+       },
+       .sources        = &clkset_hclklow,
+       .reg_src        = { .reg = S5P_SYS_OTHERS, .shift = 6, .size = 1 },
+       .reg_div        = { .reg = S5P_CLK_DIV3, .shift = 8, .size = 4 },
+};
+
+static struct clksrc_clk clk_pclk_low = {
+       .clk    = {
+               .name   = "pclk_low",
+               .id     = -1,
+               .parent = &clk_hclk_low.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV3, .shift = 12, .size = 4 },
 };
 
 int s5p6440_clk48m_ctrl(struct clk *clk, int enable)
@@ -307,6 +336,11 @@ static int s5p6440_sclk_ctrl(struct clk *clk, int enable)
        return s5p_gatectrl(S5P_CLK_GATE_SCLK0, clk, enable);
 }
 
+static int s5p6440_sclk1_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLK_GATE_SCLK1, clk, enable);
+}
+
 static int s5p6440_mem_ctrl(struct clk *clk, int enable)
 {
        return s5p_gatectrl(S5P_CLK_GATE_MEM0, clk, enable);
@@ -321,37 +355,37 @@ static struct clk init_clocks_disable[] = {
        {
                .name           = "nand",
                .id             = -1,
-               .parent         = &clk_h,
+               .parent         = &clk_hclk.clk,
                .enable         = s5p6440_mem_ctrl,
                .ctrlbit        = S5P_CLKCON_MEM0_HCLK_NFCON,
        }, {
                .name           = "adc",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_TSADC,
        }, {
                .name           = "i2c",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_IIC0,
        }, {
                .name           = "i2s_v40",
                .id             = 0,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_IIS2,
        }, {
                .name           = "spi",
                .id             = 0,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_SPI0,
        }, {
                .name           = "spi",
                .id             = 1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_SPI1,
        }, {
@@ -387,58 +421,124 @@ static struct clk init_clocks_disable[] = {
        }, {
                .name           = "otg",
                .id             = -1,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk0_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK0_USB
        }, {
                .name           = "post",
                .id             = -1,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk0_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK0_POST0
        }, {
                .name           = "lcd",
                .id             = -1,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk1_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK1_DISPCON,
        }, {
                .name           = "hsmmc",
                .id             = 0,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk0_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK0_HSMMC0,
        }, {
                .name           = "hsmmc",
                .id             = 1,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk0_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK0_HSMMC1,
        }, {
                .name           = "hsmmc",
                .id             = 2,
-               .parent         = &clk_h_low,
+               .parent         = &clk_hclk_low.clk,
                .enable         = s5p6440_hclk0_ctrl,
                .ctrlbit        = S5P_CLKCON_HCLK0_HSMMC2,
        }, {
                .name           = "rtc",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_RTC,
        }, {
                .name           = "watchdog",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_WDT,
        }, {
                .name           = "timers",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_PWM,
-       }
+       }, {
+               .name           = "hclk_fimgvg",
+               .id             = -1,
+               .parent         = &clk_hclk.clk,
+               .enable         = s5p6440_hclk1_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "tsi",
+               .id             = -1,
+               .parent         = &clk_hclk_low.clk,
+               .enable         = s5p6440_hclk1_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "pclk_fimgvg",
+               .id             = -1,
+               .parent         = &clk_pclk.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 31),
+       }, {
+               .name           = "dmc0",
+               .id             = -1,
+               .parent         = &clk_pclk.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 30),
+       }, {
+               .name           = "etm",
+               .id             = -1,
+               .parent         = &clk_pclk.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 29),
+       }, {
+               .name           = "dsim",
+               .id             = -1,
+               .parent         = &clk_pclk_low.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 28),
+       }, {
+               .name           = "gps",
+               .id             = -1,
+               .parent         = &clk_pclk_low.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 25),
+       }, {
+               .name           = "pcm",
+               .id             = -1,
+               .parent         = &clk_pclk_low.clk,
+               .enable         = s5p6440_pclk_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "irom",
+               .id             = -1,
+               .parent         = &clk_hclk.clk,
+               .enable         = s5p6440_hclk0_ctrl,
+               .ctrlbit        = (1 << 25),
+       }, {
+               .name           = "dma",
+               .id             = -1,
+               .parent         = &clk_hclk_low.clk,
+               .enable         = s5p6440_hclk0_ctrl,
+               .ctrlbit        = (1 << 12),
+       }, {
+               .name           = "2d",
+               .id             = -1,
+               .parent         = &clk_hclk.clk,
+               .enable         = s5p6440_hclk0_ctrl,
+               .ctrlbit        = (1 << 8),
+       },
 };
 
 /*
@@ -448,34 +548,46 @@ static struct clk init_clocks[] = {
        {
                .name           = "gpio",
                .id             = -1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_GPIO,
        }, {
                .name           = "uart",
                .id             = 0,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_UART0,
        }, {
                .name           = "uart",
                .id             = 1,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_UART1,
        }, {
                .name           = "uart",
                .id             = 2,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_UART2,
        }, {
                .name           = "uart",
                .id             = 3,
-               .parent         = &clk_p_low,
+               .parent         = &clk_pclk_low.clk,
                .enable         = s5p6440_pclk_ctrl,
                .ctrlbit        = S5P_CLKCON_PCLK_UART3,
-       }
+       }, {
+               .name           = "mem",
+               .id             = -1,
+               .parent         = &clk_hclk.clk,
+               .enable         = s5p6440_hclk0_ctrl,
+               .ctrlbit        = (1 << 21),
+       }, {
+               .name           = "intc",
+               .id             = -1,
+               .parent         = &clk_hclk.clk,
+               .enable         = s5p6440_hclk0_ctrl,
+               .ctrlbit        = (1 << 1),
+       },
 };
 
 static struct clk clk_iis_cd_v40 = {
@@ -488,20 +600,20 @@ static struct clk clk_pcm_cd = {
        .id             = -1,
 };
 
-static struct clk *clkset_spi_mmc_list[] = {
+static struct clk *clkset_group1_list[] = {
        &clk_mout_epll.clk,
-       &clk_dout_mpll,
+       &clk_dout_mpll.clk,
        &clk_fin_epll,
 };
 
-static struct clksrc_sources clkset_spi_mmc = {
-       .sources        = clkset_spi_mmc_list,
-       .nr_sources     = ARRAY_SIZE(clkset_spi_mmc_list),
+static struct clksrc_sources clkset_group1 = {
+       .sources        = clkset_group1_list,
+       .nr_sources     = ARRAY_SIZE(clkset_group1_list),
 };
 
 static struct clk *clkset_uart_list[] = {
        &clk_mout_epll.clk,
-       &clk_dout_mpll
+       &clk_dout_mpll.clk,
 };
 
 static struct clksrc_sources clkset_uart = {
@@ -509,6 +621,19 @@ static struct clksrc_sources clkset_uart = {
        .nr_sources     = ARRAY_SIZE(clkset_uart_list),
 };
 
+static struct clk *clkset_audio_list[] = {
+       &clk_mout_epll.clk,
+       &clk_dout_mpll.clk,
+       &clk_fin_epll,
+       &clk_iis_cd_v40,
+       &clk_pcm_cd,
+};
+
+static struct clksrc_sources clkset_audio = {
+       .sources        = clkset_audio_list,
+       .nr_sources     = ARRAY_SIZE(clkset_audio_list),
+};
+
 static struct clksrc_clk clksrcs[] = {
        {
                .clk    = {
@@ -517,7 +642,7 @@ static struct clksrc_clk clksrcs[] = {
                        .ctrlbit        = S5P_CLKCON_SCLK0_MMC0,
                        .enable         = s5p6440_sclk_ctrl,
                },
-               .sources = &clkset_spi_mmc,
+               .sources = &clkset_group1,
                .reg_src = { .reg = S5P_CLK_SRC0, .shift = 18, .size = 2 },
                .reg_div = { .reg = S5P_CLK_DIV1, .shift = 0, .size = 4 },
        }, {
@@ -527,7 +652,7 @@ static struct clksrc_clk clksrcs[] = {
                        .ctrlbit        = S5P_CLKCON_SCLK0_MMC1,
                        .enable         = s5p6440_sclk_ctrl,
                },
-               .sources = &clkset_spi_mmc,
+               .sources = &clkset_group1,
                .reg_src = { .reg = S5P_CLK_SRC0, .shift = 20, .size = 2 },
                .reg_div = { .reg = S5P_CLK_DIV1, .shift = 4, .size = 4 },
        }, {
@@ -537,7 +662,7 @@ static struct clksrc_clk clksrcs[] = {
                        .ctrlbit        = S5P_CLKCON_SCLK0_MMC2,
                        .enable         = s5p6440_sclk_ctrl,
                },
-               .sources = &clkset_spi_mmc,
+               .sources = &clkset_group1,
                .reg_src = { .reg = S5P_CLK_SRC0, .shift = 22, .size = 2 },
                .reg_div = { .reg = S5P_CLK_DIV1, .shift = 8, .size = 4 },
        }, {
@@ -557,7 +682,7 @@ static struct clksrc_clk clksrcs[] = {
                        .ctrlbit        = S5P_CLKCON_SCLK0_SPI0,
                        .enable         = s5p6440_sclk_ctrl,
                },
-               .sources = &clkset_spi_mmc,
+               .sources = &clkset_group1,
                .reg_src = { .reg = S5P_CLK_SRC0, .shift = 14, .size = 2 },
                .reg_div = { .reg = S5P_CLK_DIV2, .shift = 0, .size = 4 },
        }, {
@@ -567,17 +692,63 @@ static struct clksrc_clk clksrcs[] = {
                        .ctrlbit        = S5P_CLKCON_SCLK0_SPI1,
                        .enable         = s5p6440_sclk_ctrl,
                },
-               .sources = &clkset_spi_mmc,
+               .sources = &clkset_group1,
                .reg_src = { .reg = S5P_CLK_SRC0, .shift = 16, .size = 2 },
                .reg_div = { .reg = S5P_CLK_DIV2, .shift = 4, .size = 4 },
-       }
+       }, {
+               .clk    = {
+                       .name           = "sclk_post",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 10),
+                       .enable         = s5p6440_sclk_ctrl,
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC0, .shift = 26, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV1, .shift = 12, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_dispcon",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 1),
+                       .enable         = s5p6440_sclk1_ctrl,
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 4, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 0, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimgvg",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 2),
+                       .enable         = s5p6440_sclk1_ctrl,
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 8, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 4, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_audio2",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 11),
+                       .enable         = s5p6440_sclk_ctrl,
+               },
+               .sources = &clkset_audio,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 0, .size = 3 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 24, .size = 4 },
+       },
 };
 
 /* Clock initialisation code */
-static struct clksrc_clk *init_parents[] = {
+static struct clksrc_clk *sysclks[] = {
        &clk_mout_apll,
        &clk_mout_epll,
        &clk_mout_mpll,
+       &clk_dout_mpll,
+       &clk_armclk,
+       &clk_hclk,
+       &clk_pclk,
+       &clk_hclk_low,
+       &clk_pclk_low,
 };
 
 void __init_or_cpufreq s5p6440_setup_clocks(void)
@@ -593,21 +764,13 @@ void __init_or_cpufreq s5p6440_setup_clocks(void)
        unsigned long apll;
        unsigned long mpll;
        unsigned int ptr;
-       u32 clkdiv0;
-       u32 clkdiv3;
 
        /* Set S5P6440 functions for clk_fout_epll */
        clk_fout_epll.enable = s5p6440_epll_enable;
        clk_fout_epll.ops = &s5p6440_epll_ops;
 
-       /* Set S5P6440 functions for arm clock */
-       clk_arm.parent = &clk_mout_apll.clk;
-       clk_arm.ops = &s5p6440_clkarm_ops;
        clk_48m.enable = s5p6440_clk48m_ctrl;
 
-       clkdiv0 = __raw_readl(S5P_CLK_DIV0);
-       clkdiv3 = __raw_readl(S5P_CLK_DIV3);
-
        xtal_clk = clk_get(NULL, "ext_xtal");
        BUG_ON(IS_ERR(xtal_clk));
 
@@ -619,41 +782,28 @@ void __init_or_cpufreq s5p6440_setup_clocks(void)
        mpll = s5p_get_pll45xx(xtal, __raw_readl(S5P_MPLL_CON), pll_4502);
        apll = s5p_get_pll45xx(xtal, __raw_readl(S5P_APLL_CON), pll_4502);
 
+       clk_fout_mpll.rate = mpll;
+       clk_fout_epll.rate = epll;
+       clk_fout_apll.rate = apll;
+
        printk(KERN_INFO "S5P6440: PLL settings, A=%ld.%ldMHz, M=%ld.%ldMHz," \
                        " E=%ld.%ldMHz\n",
                        print_mhz(apll), print_mhz(mpll), print_mhz(epll));
 
-       fclk = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_ARM);
-       hclk = fclk / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK);
-       pclk = hclk / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK);
-
-       if (__raw_readl(S5P_OTHERS) & S5P_OTHERS_HCLK_LOW_SEL_MPLL) {
-               /* Asynchronous mode */
-               hclk_low = mpll / GET_DIV(clkdiv3, S5P_CLKDIV3_HCLK_LOW);
-       } else {
-               /* Synchronous mode */
-               hclk_low = apll / GET_DIV(clkdiv3, S5P_CLKDIV3_HCLK_LOW);
-       }
-
-       pclk_low = hclk_low / GET_DIV(clkdiv3, S5P_CLKDIV3_PCLK_LOW);
+       fclk = clk_get_rate(&clk_armclk.clk);
+       hclk = clk_get_rate(&clk_hclk.clk);
+       pclk = clk_get_rate(&clk_pclk.clk);
+       hclk_low = clk_get_rate(&clk_hclk_low.clk);
+       pclk_low = clk_get_rate(&clk_pclk_low.clk);
 
        printk(KERN_INFO "S5P6440: HCLK=%ld.%ldMHz, HCLK_LOW=%ld.%ldMHz," \
                        " PCLK=%ld.%ldMHz, PCLK_LOW=%ld.%ldMHz\n",
                        print_mhz(hclk), print_mhz(hclk_low),
                        print_mhz(pclk), print_mhz(pclk_low));
 
-       clk_fout_mpll.rate = mpll;
-       clk_fout_epll.rate = epll;
-       clk_fout_apll.rate = apll;
-
        clk_f.rate = fclk;
        clk_h.rate = hclk;
        clk_p.rate = pclk;
-       clk_h_low.rate = hclk_low;
-       clk_p_low.rate = pclk_low;
-
-       for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
-               s3c_set_clksrc(init_parents[ptr], true);
 
        for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
                s3c_set_clksrc(&clksrcs[ptr], true);
@@ -661,13 +811,8 @@ void __init_or_cpufreq s5p6440_setup_clocks(void)
 
 static struct clk *clks[] __initdata = {
        &clk_ext,
-       &clk_mout_epll.clk,
-       &clk_mout_mpll.clk,
-       &clk_dout_mpll,
        &clk_iis_cd_v40,
        &clk_pcm_cd,
-       &clk_p_low,
-       &clk_h_low,
 };
 
 void __init s5p6440_register_clocks(void)
@@ -680,6 +825,9 @@ void __init s5p6440_register_clocks(void)
        if (ret > 0)
                printk(KERN_ERR "Failed to register %u clocks\n", ret);
 
+       for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
+               s3c_register_clksrc(sysclks[ptr], 1);
+
        s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
        s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
 
index 1794131..ca3b320 100644 (file)
@@ -88,7 +88,7 @@ void __init s5p6440_init_irq(void)
        s5p_init_irq(vic, ARRAY_SIZE(vic));
 }
 
-static struct sysdev_class s5p6440_sysclass = {
+struct sysdev_class s5p6440_sysclass = {
        .name   = "s5p6440-core",
 };
 
diff --git a/arch/arm/mach-s5p6440/dev-audio.c b/arch/arm/mach-s5p6440/dev-audio.c
new file mode 100644 (file)
index 0000000..0c53679
--- /dev/null
@@ -0,0 +1,127 @@
+/* linux/arch/arm/mach-s5p6440/dev-audio.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co. Ltd
+ *     Jaswinder Singh <jassi.brar@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/gpio-cfg.h>
+#include <plat/audio.h>
+
+#include <mach/gpio.h>
+#include <mach/map.h>
+#include <mach/dma.h>
+#include <mach/irqs.h>
+
+static int s5p6440_cfg_i2s(struct platform_device *pdev)
+{
+       /* configure GPIO for i2s port */
+       switch (pdev->id) {
+       case -1:
+               s3c_gpio_cfgpin(S5P6440_GPR(4), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(5), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(6), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(7), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(8), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(13), S3C_GPIO_SFN(5));
+               s3c_gpio_cfgpin(S5P6440_GPR(14), S3C_GPIO_SFN(5));
+               break;
+
+       default:
+               printk(KERN_ERR "Invalid Device %d\n", pdev->id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_i2s_pdata = {
+       .cfg_gpio = s5p6440_cfg_i2s,
+};
+
+static struct resource s5p6440_iis0_resource[] = {
+       [0] = {
+               .start = S5P6440_PA_I2S,
+               .end   = S5P6440_PA_I2S + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S0_TX,
+               .end   = DMACH_I2S0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S0_RX,
+               .end   = DMACH_I2S0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6440_device_iis = {
+       .name             = "s3c64xx-iis-v4",
+       .id               = -1,
+       .num_resources    = ARRAY_SIZE(s5p6440_iis0_resource),
+       .resource         = s5p6440_iis0_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+/* PCM Controller platform_devices */
+
+static int s5p6440_pcm_cfg_gpio(struct platform_device *pdev)
+{
+       switch (pdev->id) {
+       case 0:
+               s3c_gpio_cfgpin(S5P6440_GPR(7), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6440_GPR(13), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6440_GPR(14), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6440_GPR(8), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6440_GPR(6), S3C_GPIO_SFN(2));
+               break;
+
+       default:
+               printk(KERN_DEBUG "Invalid PCM Controller number!");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_pcm_pdata = {
+       .cfg_gpio = s5p6440_pcm_cfg_gpio,
+};
+
+static struct resource s5p6440_pcm0_resource[] = {
+       [0] = {
+               .start = S5P6440_PA_PCM,
+               .end   = S5P6440_PA_PCM + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM0_TX,
+               .end   = DMACH_PCM0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM0_RX,
+               .end   = DMACH_PCM0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6440_device_pcm = {
+       .name             = "samsung-pcm",
+       .id               = 0,
+       .num_resources    = ARRAY_SIZE(s5p6440_pcm0_resource),
+       .resource         = s5p6440_pcm0_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
diff --git a/arch/arm/mach-s5p6440/dma.c b/arch/arm/mach-s5p6440/dma.c
new file mode 100644 (file)
index 0000000..07606ad
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/devs.h>
+#include <plat/irqs.h>
+
+#include <mach/map.h>
+#include <mach/irqs.h>
+
+#include <plat/s3c-pl330-pdata.h>
+
+static u64 dma_dmamask = DMA_BIT_MASK(32);
+
+static struct resource s5p6440_pdma_resource[] = {
+       [0] = {
+               .start  = S5P6440_PA_PDMA,
+               .end    = S5P6440_PA_PDMA + SZ_4K,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_DMA0,
+               .end    = IRQ_DMA0,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct s3c_pl330_platdata s5p6440_pdma_pdata = {
+       .peri = {
+               [0] = DMACH_UART0_RX,
+               [1] = DMACH_UART0_TX,
+               [2] = DMACH_UART1_RX,
+               [3] = DMACH_UART1_TX,
+               [4] = DMACH_UART2_RX,
+               [5] = DMACH_UART2_TX,
+               [6] = DMACH_UART3_RX,
+               [7] = DMACH_UART3_TX,
+               [8] = DMACH_MAX,
+               [9] = DMACH_MAX,
+               [10] = DMACH_PCM0_TX,
+               [11] = DMACH_PCM0_RX,
+               [12] = DMACH_I2S0_TX,
+               [13] = DMACH_I2S0_RX,
+               [14] = DMACH_SPI0_TX,
+               [15] = DMACH_SPI0_RX,
+               [16] = DMACH_MAX,
+               [17] = DMACH_MAX,
+               [18] = DMACH_MAX,
+               [19] = DMACH_MAX,
+               [20] = DMACH_SPI1_TX,
+               [21] = DMACH_SPI1_RX,
+               [22] = DMACH_MAX,
+               [23] = DMACH_MAX,
+               [24] = DMACH_MAX,
+               [25] = DMACH_MAX,
+               [26] = DMACH_MAX,
+               [27] = DMACH_MAX,
+               [28] = DMACH_MAX,
+               [29] = DMACH_PWM,
+               [30] = DMACH_MAX,
+               [31] = DMACH_MAX,
+       },
+};
+
+static struct platform_device s5p6440_device_pdma = {
+       .name           = "s3c-pl330",
+       .id             = 1,
+       .num_resources  = ARRAY_SIZE(s5p6440_pdma_resource),
+       .resource       = s5p6440_pdma_resource,
+       .dev            = {
+               .dma_mask = &dma_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+               .platform_data = &s5p6440_pdma_pdata,
+       },
+};
+
+static struct platform_device *s5p6440_dmacs[] __initdata = {
+       &s5p6440_device_pdma,
+};
+
+static int __init s5p6440_dma_init(void)
+{
+       platform_add_devices(s5p6440_dmacs, ARRAY_SIZE(s5p6440_dmacs));
+
+       return 0;
+}
+arch_initcall(s5p6440_dma_init);
index b0ea741..262dc75 100644 (file)
@@ -161,12 +161,15 @@ static struct s3c_gpio_cfg s5p6440_gpio_cfgs[] = {
        }, {
                .cfg_eint       = 0,
                .set_config     = s3c_gpio_setcfg_s3c24xx,
+               .get_config     = s3c_gpio_getcfg_s3c24xx,
        }, {
                .cfg_eint       = 2,
                .set_config     = s3c_gpio_setcfg_s3c24xx,
+               .get_config     = s3c_gpio_getcfg_s3c24xx,
        }, {
                .cfg_eint       = 3,
                .set_config     = s3c_gpio_setcfg_s3c24xx,
+               .get_config     = s3c_gpio_getcfg_s3c24xx,
        },
 };
 
@@ -279,6 +282,8 @@ void __init s5p6440_gpiolib_set_cfg(struct s3c_gpio_cfg *chipcfg, int nr_chips)
        for (; nr_chips > 0; nr_chips--, chipcfg++) {
                if (!chipcfg->set_config)
                        chipcfg->set_config     = s3c_gpio_setcfg_s3c64xx_4bit;
+               if (!chipcfg->get_config)
+                       chipcfg->get_config     = s3c_gpio_getcfg_s3c64xx_4bit;
                if (!chipcfg->set_pull)
                        chipcfg->set_pull       = s3c_gpio_setpull_updown;
                if (!chipcfg->get_pull)
diff --git a/arch/arm/mach-s5p6440/include/mach/dma.h b/arch/arm/mach-s5p6440/include/mach/dma.h
new file mode 100644 (file)
index 0000000..81209eb
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MACH_DMA_H
+#define __MACH_DMA_H
+
+/* This platform uses the common S3C DMA API driver for PL330 */
+#include <plat/s3c-dma-pl330.h>
+
+#endif /* __MACH_DMA_H */
index 8924e5a..72aedad 100644 (file)
@@ -29,6 +29,8 @@
 #define S5P6440_PA_VIC0                (0xE4000000)
 #define S5P_PA_VIC0            S5P6440_PA_VIC0
 
+#define S5P6440_PA_PDMA                0xE9000000
+
 #define S5P6440_PA_VIC1                (0xE4100000)
 #define S5P_PA_VIC1            S5P6440_PA_VIC1
 
 #define S5P6440_PA_SDRAM       (0x20000000)
 #define S5P_PA_SDRAM           S5P6440_PA_SDRAM
 
+/* I2S */
+#define S5P6440_PA_I2S         0xF2000000
+
+/* PCM */
+#define S5P6440_PA_PCM         0xF2100000
+
 /* compatibiltiy defines. */
 #define S3C_PA_UART            S5P6440_PA_UART
 #define S3C_PA_IIC             S5P6440_PA_IIC0
index c4bb7c5..6a2a02f 100644 (file)
@@ -1,11 +1,14 @@
 /* linux/arch/arm/mach-s5p6440/include/mach/pwm-clock.h
  *
+ * Copyright (c) 2009 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * Copyright 2008 Openmoko, Inc.
  * Copyright 2008 Simtec Electronics
  *      Ben Dooks <ben@simtec.co.uk>
  *      http://armlinux.simtec.co.uk/
  *
- * Copyright 2009 Samsung Electronics Co., Ltd.
- *             http://www.samsung.com/
+ * Based on arch/arm/mach-s3c64xx/include/mach/pwm-clock.h
  *
  * S5P6440 - pwm clock and timer support
  *
  * published by the Free Software Foundation.
 */
 
+#ifndef __ASM_ARCH_PWMCLK_H
+#define __ASM_ARCH_PWMCLK_H __FILE__
+
 /**
  * pwm_cfg_src_is_tclk() - return whether the given mux config is a tclk
- * @cfg: The timer TCFG1 register bits shifted down to 0.
+ * @tcfg: The timer TCFG1 register bits shifted down to 0.
  *
  * Return true if the given configuration from TCFG1 is a TCLK instead
  * any of the TDIV clocks.
  */
 static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
 {
-       return tcfg == S3C2410_TCFG1_MUX_TCLK;
+       return 0;
 }
 
 /**
@@ -35,7 +41,7 @@ static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
  */
 static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
 {
-       return 1 << (1 + tcfg1);
+       return 1 << tcfg1;
 }
 
 /**
@@ -45,7 +51,7 @@ static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
  */
 static inline unsigned int pwm_tdiv_has_div1(void)
 {
-       return 0;
+       return 1;
 }
 
 /**
@@ -56,7 +62,9 @@ static inline unsigned int pwm_tdiv_has_div1(void)
  */
 static inline unsigned long pwm_tdiv_div_bits(unsigned int div)
 {
-       return ilog2(div) - 1;
+       return ilog2(div);
 }
 
-#define S3C_TCFG1_MUX_TCLK S3C2410_TCFG1_MUX_TCLK
+#define S3C_TCFG1_MUX_TCLK 0
+
+#endif /* __ASM_ARCH_PWMCLK_H */
index 3ae88f2..d7fede9 100644 (file)
@@ -84,6 +84,7 @@ static struct s3c2410_uartcfg smdk6440_uartcfgs[] __initdata = {
 };
 
 static struct platform_device *smdk6440_devices[] __initdata = {
+       &s5p6440_device_iis,
 };
 
 static void __init smdk6440_map_io(void)
similarity index 92%
rename from arch/arm/plat-s5p/setup-i2c0.c
rename to arch/arm/mach-s5p6440/setup-i2c0.c
index 67a66e0..69e8a66 100644 (file)
@@ -1,4 +1,4 @@
-/* linux/arch/arm/plat-s5p/setup-i2c0.c
+/* linux/arch/arm/mach-s5p6440/setup-i2c0.c
  *
  * Copyright (c) 2009 Samsung Electronics Co., Ltd.
  *             http://www.samsung.com/
index 4f3f6de..0fd41b4 100644 (file)
@@ -12,6 +12,7 @@ if ARCH_S5P6442
 config CPU_S5P6442
        bool
        select PLAT_S5P
+       select S3C_PL330_DMA
        help
          Enable S5P6442 CPU support
 
index dde39a6..e30a7f7 100644 (file)
@@ -12,8 +12,12 @@ obj-                         :=
 
 # Core support for S5P6442 system
 
-obj-$(CONFIG_CPU_S5P6442)      += cpu.o init.o clock.o
+obj-$(CONFIG_CPU_S5P6442)      += cpu.o init.o clock.o dma.o
+obj-$(CONFIG_CPU_S5P6442)      += setup-i2c0.o
 
 # machine support
 
 obj-$(CONFIG_MACH_SMDK6442)    += mach-smdk6442.o
+
+# device support
+obj-y                          += dev-audio.o
index bc2524d..a48fb55 100644 (file)
@@ -95,7 +95,7 @@ void __init s5p6442_init_irq(void)
        s5p_init_irq(vic, ARRAY_SIZE(vic));
 }
 
-static struct sysdev_class s5p6442_sysclass = {
+struct sysdev_class s5p6442_sysclass = {
        .name   = "s5p6442-core",
 };
 
diff --git a/arch/arm/mach-s5p6442/dev-audio.c b/arch/arm/mach-s5p6442/dev-audio.c
new file mode 100644 (file)
index 0000000..cb801e1
--- /dev/null
@@ -0,0 +1,197 @@
+/* linux/arch/arm/mach-s5p6442/dev-audio.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co. Ltd
+ *     Jaswinder Singh <jassi.brar@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/gpio-cfg.h>
+#include <plat/audio.h>
+
+#include <mach/gpio.h>
+#include <mach/map.h>
+#include <mach/dma.h>
+#include <mach/irqs.h>
+
+static int s5p6442_cfg_i2s(struct platform_device *pdev)
+{
+       /* configure GPIO for i2s port */
+       switch (pdev->id) {
+       case 1:
+               s3c_gpio_cfgpin(S5P6442_GPC1(0), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC1(1), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC1(2), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC1(3), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC1(4), S3C_GPIO_SFN(2));
+               break;
+
+       case -1:
+               s3c_gpio_cfgpin(S5P6442_GPC0(0), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC0(1), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC0(2), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC0(3), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5P6442_GPC0(4), S3C_GPIO_SFN(2));
+               break;
+
+       default:
+               printk(KERN_ERR "Invalid Device %d\n", pdev->id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_i2s_pdata = {
+       .cfg_gpio = s5p6442_cfg_i2s,
+};
+
+static struct resource s5p6442_iis0_resource[] = {
+       [0] = {
+               .start = S5P6442_PA_I2S0,
+               .end   = S5P6442_PA_I2S0 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S0_TX,
+               .end   = DMACH_I2S0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S0_RX,
+               .end   = DMACH_I2S0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6442_device_iis0 = {
+       .name             = "s3c64xx-iis-v4",
+       .id               = -1,
+       .num_resources    = ARRAY_SIZE(s5p6442_iis0_resource),
+       .resource         = s5p6442_iis0_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+static struct resource s5p6442_iis1_resource[] = {
+       [0] = {
+               .start = S5P6442_PA_I2S1,
+               .end   = S5P6442_PA_I2S1 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S1_TX,
+               .end   = DMACH_I2S1_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S1_RX,
+               .end   = DMACH_I2S1_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6442_device_iis1 = {
+       .name             = "s3c64xx-iis",
+       .id               = 1,
+       .num_resources    = ARRAY_SIZE(s5p6442_iis1_resource),
+       .resource         = s5p6442_iis1_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+/* PCM Controller platform_devices */
+
+static int s5p6442_pcm_cfg_gpio(struct platform_device *pdev)
+{
+       switch (pdev->id) {
+       case 0:
+               s3c_gpio_cfgpin(S5P6442_GPC0(0), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC0(1), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC0(2), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC0(3), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC0(4), S3C_GPIO_SFN(3));
+               break;
+
+       case 1:
+               s3c_gpio_cfgpin(S5P6442_GPC1(0), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC1(1), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC1(2), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC1(3), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5P6442_GPC1(4), S3C_GPIO_SFN(3));
+               break;
+
+       default:
+               printk(KERN_DEBUG "Invalid PCM Controller number!");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_pcm_pdata = {
+       .cfg_gpio = s5p6442_pcm_cfg_gpio,
+};
+
+static struct resource s5p6442_pcm0_resource[] = {
+       [0] = {
+               .start = S5P6442_PA_PCM0,
+               .end   = S5P6442_PA_PCM0 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM0_TX,
+               .end   = DMACH_PCM0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM0_RX,
+               .end   = DMACH_PCM0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6442_device_pcm0 = {
+       .name             = "samsung-pcm",
+       .id               = 0,
+       .num_resources    = ARRAY_SIZE(s5p6442_pcm0_resource),
+       .resource         = s5p6442_pcm0_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
+
+static struct resource s5p6442_pcm1_resource[] = {
+       [0] = {
+               .start = S5P6442_PA_PCM1,
+               .end   = S5P6442_PA_PCM1 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM1_TX,
+               .end   = DMACH_PCM1_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM1_RX,
+               .end   = DMACH_PCM1_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5p6442_device_pcm1 = {
+       .name             = "samsung-pcm",
+       .id               = 1,
+       .num_resources    = ARRAY_SIZE(s5p6442_pcm1_resource),
+       .resource         = s5p6442_pcm1_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
diff --git a/arch/arm/mach-s5p6442/dma.c b/arch/arm/mach-s5p6442/dma.c
new file mode 100644 (file)
index 0000000..ad4f870
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/devs.h>
+#include <plat/irqs.h>
+
+#include <mach/map.h>
+#include <mach/irqs.h>
+
+#include <plat/s3c-pl330-pdata.h>
+
+static u64 dma_dmamask = DMA_BIT_MASK(32);
+
+static struct resource s5p6442_pdma_resource[] = {
+       [0] = {
+               .start  = S5P6442_PA_PDMA,
+               .end    = S5P6442_PA_PDMA + SZ_4K,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_PDMA,
+               .end    = IRQ_PDMA,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct s3c_pl330_platdata s5p6442_pdma_pdata = {
+       .peri = {
+               [0] = DMACH_UART0_RX,
+               [1] = DMACH_UART0_TX,
+               [2] = DMACH_UART1_RX,
+               [3] = DMACH_UART1_TX,
+               [4] = DMACH_UART2_RX,
+               [5] = DMACH_UART2_TX,
+               [6] = DMACH_MAX,
+               [7] = DMACH_MAX,
+               [8] = DMACH_MAX,
+               [9] = DMACH_I2S0_RX,
+               [10] = DMACH_I2S0_TX,
+               [11] = DMACH_I2S0S_TX,
+               [12] = DMACH_I2S1_RX,
+               [13] = DMACH_I2S1_TX,
+               [14] = DMACH_MAX,
+               [15] = DMACH_MAX,
+               [16] = DMACH_SPI0_RX,
+               [17] = DMACH_SPI0_TX,
+               [18] = DMACH_MAX,
+               [19] = DMACH_MAX,
+               [20] = DMACH_PCM0_RX,
+               [21] = DMACH_PCM0_TX,
+               [22] = DMACH_PCM1_RX,
+               [23] = DMACH_PCM1_TX,
+               [24] = DMACH_MAX,
+               [25] = DMACH_MAX,
+               [26] = DMACH_MAX,
+               [27] = DMACH_MSM_REQ0,
+               [28] = DMACH_MSM_REQ1,
+               [29] = DMACH_MSM_REQ2,
+               [30] = DMACH_MSM_REQ3,
+               [31] = DMACH_MAX,
+       },
+};
+
+static struct platform_device s5p6442_device_pdma = {
+       .name           = "s3c-pl330",
+       .id             = 1,
+       .num_resources  = ARRAY_SIZE(s5p6442_pdma_resource),
+       .resource       = s5p6442_pdma_resource,
+       .dev            = {
+               .dma_mask = &dma_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+               .platform_data = &s5p6442_pdma_pdata,
+       },
+};
+
+static struct platform_device *s5p6442_dmacs[] __initdata = {
+       &s5p6442_device_pdma,
+};
+
+static int __init s5p6442_dma_init(void)
+{
+       platform_add_devices(s5p6442_dmacs, ARRAY_SIZE(s5p6442_dmacs));
+
+       return 0;
+}
+arch_initcall(s5p6442_dma_init);
diff --git a/arch/arm/mach-s5p6442/include/mach/dma.h b/arch/arm/mach-s5p6442/include/mach/dma.h
new file mode 100644 (file)
index 0000000..81209eb
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MACH_DMA_H
+#define __MACH_DMA_H
+
+/* This platform uses the common S3C DMA API driver for PL330 */
+#include <plat/s3c-dma-pl330.h>
+
+#endif /* __MACH_DMA_H */
index 685277d..7568dc0 100644 (file)
@@ -34,6 +34,9 @@
 #define S5P6442_PA_VIC2                (0xE4200000)
 #define S5P_PA_VIC2            S5P6442_PA_VIC2
 
+#define S5P6442_PA_MDMA                0xE8000000
+#define S5P6442_PA_PDMA                0xE9000000
+
 #define S5P6442_PA_TIMER       (0xEA000000)
 #define S5P_PA_TIMER           S5P6442_PA_TIMER
 
 #define S5P6442_PA_SDRAM       (0x20000000)
 #define S5P_PA_SDRAM           S5P6442_PA_SDRAM
 
+/* I2S */
+#define S5P6442_PA_I2S0                0xC0B00000
+#define S5P6442_PA_I2S1                0xF2200000
+
+/* PCM */
+#define S5P6442_PA_PCM0                0xF2400000
+#define S5P6442_PA_PCM1                0xF2500000
+
 /* compatibiltiy defines. */
 #define S3C_PA_UART            S5P6442_PA_UART
 #define S3C_PA_IIC             S5P6442_PA_IIC0
index 15e8525..2724b37 100644 (file)
@@ -1,13 +1,14 @@
 /* linux/arch/arm/mach-s5p6442/include/mach/pwm-clock.h
  *
+ * Copyright (c) 2010 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * Copyright 2008 Openmoko, Inc.
  * Copyright 2008 Simtec Electronics
  *      Ben Dooks <ben@simtec.co.uk>
  *      http://armlinux.simtec.co.uk/
  *
- * Copyright 2010 Samsung Electronics Co., Ltd.
- *             http://www.samsung.com/
- *
- * Based on arch/arm/plat-s3c24xx/include/mach/pwm-clock.h
+ * Based on arch/arm/mach-s3c64xx/include/mach/pwm-clock.h
  *
  * S5P6442 - pwm clock and timer support
  *
 
 /**
  * pwm_cfg_src_is_tclk() - return whether the given mux config is a tclk
- * @cfg: The timer TCFG1 register bits shifted down to 0.
+ * @tcfg: The timer TCFG1 register bits shifted down to 0.
  *
  * Return true if the given configuration from TCFG1 is a TCLK instead
  * any of the TDIV clocks.
  */
 static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
 {
-       return tcfg == S3C2410_TCFG1_MUX_TCLK;
+       return tcfg == S3C64XX_TCFG1_MUX_TCLK;
 }
 
 /**
@@ -40,7 +41,7 @@ static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
  */
 static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
 {
-       return 1 << (1 + tcfg1);
+       return 1 << tcfg1;
 }
 
 /**
@@ -50,7 +51,7 @@ static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
  */
 static inline unsigned int pwm_tdiv_has_div1(void)
 {
-       return 0;
+       return 1;
 }
 
 /**
@@ -61,9 +62,9 @@ static inline unsigned int pwm_tdiv_has_div1(void)
  */
 static inline unsigned long pwm_tdiv_div_bits(unsigned int div)
 {
-       return ilog2(div) - 1;
+       return ilog2(div);
 }
 
-#define S3C_TCFG1_MUX_TCLK S3C2410_TCFG1_MUX_TCLK
+#define S3C_TCFG1_MUX_TCLK S3C64XX_TCFG1_MUX_TCLK
 
 #endif /* __ASM_ARCH_PWMCLK_H */
index 0d63371..ebcf997 100644 (file)
@@ -65,6 +65,7 @@ static struct s3c2410_uartcfg smdk6442_uartcfgs[] __initdata = {
 };
 
 static struct platform_device *smdk6442_devices[] __initdata = {
+       &s5p6442_device_iis0,
 };
 
 static void __init smdk6442_map_io(void)
diff --git a/arch/arm/mach-s5p6442/setup-i2c0.c b/arch/arm/mach-s5p6442/setup-i2c0.c
new file mode 100644 (file)
index 0000000..662695d
--- /dev/null
@@ -0,0 +1,25 @@
+/* linux/arch/arm/mach-s5p6442/setup-i2c0.c
+ *
+ * Copyright (c) 2009 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * I2C0 GPIO configuration.
+ *
+ * Based on plat-s3c64xx/setup-i2c0.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+struct platform_device; /* don't need the contents */
+
+#include <plat/iic.h>
+
+void s3c_i2c0_cfg_gpio(struct platform_device *dev)
+{
+       /* Will be populated later */
+}
index 27ec167..8593337 100644 (file)
@@ -12,12 +12,22 @@ config CPU_S5PC100
        help
          Enable S5PC100 CPU support
 
+config S5PC100_SETUP_FB_24BPP
+       bool
+       help
+         Common setup code for S5PC1XX with an 24bpp RGB display helper.
+
 config S5PC100_SETUP_SDHCI
         bool
         select S5PC1XX_SETUP_SDHCI_GPIO
         help
           Internal helper functions for S5PC100 based SDHCI systems
 
+config S5PC100_SETUP_I2C1
+       bool
+       help
+         Common setup code for i2c bus 1.
+
 config MACH_SMDKC100
        bool "SMDKC100"
        select CPU_S5PC100
@@ -26,9 +36,8 @@ config MACH_SMDKC100
        select S3C_DEV_HSMMC
        select S3C_DEV_HSMMC1
        select S3C_DEV_HSMMC2
-       select S5PC1XX_SETUP_I2C0
-       select S5PC1XX_SETUP_I2C1
-       select S5PC1XX_SETUP_FB_24BPP
+       select S5PC100_SETUP_FB_24BPP
+       select S5PC100_SETUP_I2C1
        select S5PC100_SETUP_SDHCI
        help
          Machine support for the Samsung SMDKC100
index 809ff10..373bc54 100644 (file)
@@ -11,10 +11,13 @@ obj-                                :=
 
 # Core support for S5PC100 system
 
-obj-$(CONFIG_CPU_S5PC100)      += cpu.o
+obj-$(CONFIG_CPU_S5PC100)      += cpu.o gpiolib.o
+obj-$(CONFIG_CPU_S5PC100)      += setup-i2c0.o
 
 # Helper and device support
 
+obj-$(CONFIG_S5PC100_SETUP_FB_24BPP)   += setup-fb-24bpp.o
+obj-$(CONFIG_S5PC100_SETUP_I2C1)       += setup-i2c1.o
 obj-$(CONFIG_S5PC100_SETUP_SDHCI)       += setup-sdhci.o
 
 # machine support
diff --git a/arch/arm/mach-s5pc100/clock.c b/arch/arm/mach-s5pc100/clock.c
new file mode 100644 (file)
index 0000000..e3fed4c
--- /dev/null
@@ -0,0 +1,1358 @@
+/* linux/arch/arm/mach-s5pc100/clock.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * S5PC100 - Clock support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <mach/map.h>
+
+#include <plat/cpu-freq.h>
+#include <mach/regs-clock.h>
+#include <plat/clock.h>
+#include <plat/cpu.h>
+#include <plat/pll.h>
+#include <plat/s5p-clock.h>
+#include <plat/clock-clksrc.h>
+#include <plat/s5pc100.h>
+
+static struct clk s5p_clk_otgphy = {
+       .name           = "otg_phy",
+       .id             = -1,
+};
+
+static struct clk *clk_src_mout_href_list[] = {
+       [0] = &s5p_clk_27m,
+       [1] = &clk_fin_hpll,
+};
+
+static struct clksrc_sources clk_src_mout_href = {
+       .sources        = clk_src_mout_href_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mout_href_list),
+};
+
+static struct clksrc_clk clk_mout_href = {
+       .clk = {
+               .name           = "mout_href",
+               .id             = -1,
+       },
+       .sources        = &clk_src_mout_href,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 20, .size = 1 },
+};
+
+static struct clk *clk_src_mout_48m_list[] = {
+       [0] = &clk_xusbxti,
+       [1] = &s5p_clk_otgphy,
+};
+
+static struct clksrc_sources clk_src_mout_48m = {
+       .sources        = clk_src_mout_48m_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mout_48m_list),
+};
+
+static struct clksrc_clk clk_mout_48m = {
+       .clk = {
+               .name           = "mout_48m",
+               .id             = -1,
+       },
+       .sources        = &clk_src_mout_48m,
+       .reg_src        = { .reg = S5P_CLK_SRC1, .shift = 24, .size = 1 },
+};
+
+static struct clksrc_clk clk_mout_mpll = {
+       .clk = {
+               .name           = "mout_mpll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_mpll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 4, .size = 1 },
+};
+
+
+static struct clksrc_clk clk_mout_apll = {
+       .clk    = {
+               .name           = "mout_apll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_apll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
+};
+
+static struct clksrc_clk clk_mout_epll = {
+       .clk    = {
+               .name           = "mout_epll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_epll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 8, .size = 1 },
+};
+
+static struct clk *clk_src_mout_hpll_list[] = {
+       [0] = &s5p_clk_27m,
+};
+
+static struct clksrc_sources clk_src_mout_hpll = {
+       .sources        = clk_src_mout_hpll_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mout_hpll_list),
+};
+
+static struct clksrc_clk clk_mout_hpll = {
+       .clk    = {
+               .name           = "mout_hpll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_mout_hpll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 12, .size = 1 },
+};
+
+static struct clksrc_clk clk_div_apll = {
+       .clk    = {
+               .name   = "div_apll",
+               .id     = -1,
+               .parent = &clk_mout_apll.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 0, .size = 1 },
+};
+
+static struct clksrc_clk clk_div_arm = {
+       .clk    = {
+               .name   = "div_arm",
+               .id     = -1,
+               .parent = &clk_div_apll.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 4, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_d0_bus = {
+       .clk    = {
+               .name   = "div_d0_bus",
+               .id     = -1,
+               .parent = &clk_div_arm.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 8, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_pclkd0 = {
+       .clk    = {
+               .name   = "div_pclkd0",
+               .id     = -1,
+               .parent = &clk_div_d0_bus.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 12, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_secss = {
+       .clk    = {
+               .name   = "div_secss",
+               .id     = -1,
+               .parent = &clk_div_d0_bus.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 16, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_apll2 = {
+       .clk    = {
+               .name   = "div_apll2",
+               .id     = -1,
+               .parent = &clk_mout_apll.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 0, .size = 3 },
+};
+
+static struct clk *clk_src_mout_am_list[] = {
+       [0] = &clk_mout_mpll.clk,
+       [1] = &clk_div_apll2.clk,
+};
+
+struct clksrc_sources clk_src_mout_am = {
+       .sources        = clk_src_mout_am_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mout_am_list),
+};
+
+static struct clksrc_clk clk_mout_am = {
+       .clk    = {
+               .name   = "mout_am",
+               .id     = -1,
+       },
+       .sources = &clk_src_mout_am,
+       .reg_src = { .reg = S5P_CLK_SRC0, .shift = 16, .size = 1 },
+};
+
+static struct clksrc_clk clk_div_d1_bus = {
+       .clk    = {
+               .name   = "div_d1_bus",
+               .id     = -1,
+               .parent = &clk_mout_am.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 12, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_mpll2 = {
+       .clk    = {
+               .name   = "div_mpll2",
+               .id     = -1,
+               .parent = &clk_mout_am.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 8, .size = 1 },
+};
+
+static struct clksrc_clk clk_div_mpll = {
+       .clk    = {
+               .name   = "div_mpll",
+               .id     = -1,
+               .parent = &clk_mout_am.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 4, .size = 2 },
+};
+
+static struct clk *clk_src_mout_onenand_list[] = {
+       [0] = &clk_div_d0_bus.clk,
+       [1] = &clk_div_d1_bus.clk,
+};
+
+struct clksrc_sources clk_src_mout_onenand = {
+       .sources        = clk_src_mout_onenand_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mout_onenand_list),
+};
+
+static struct clksrc_clk clk_mout_onenand = {
+       .clk    = {
+               .name   = "mout_onenand",
+               .id     = -1,
+       },
+       .sources = &clk_src_mout_onenand,
+       .reg_src = { .reg = S5P_CLK_SRC0, .shift = 24, .size = 1 },
+};
+
+static struct clksrc_clk clk_div_onenand = {
+       .clk    = {
+               .name   = "div_onenand",
+               .id     = -1,
+               .parent = &clk_mout_onenand.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 20, .size = 2 },
+};
+
+static struct clksrc_clk clk_div_pclkd1 = {
+       .clk    = {
+               .name   = "div_pclkd1",
+               .id     = -1,
+               .parent = &clk_div_d1_bus.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 16, .size = 3 },
+};
+
+static struct clksrc_clk clk_div_cam = {
+       .clk    = {
+               .name   = "div_cam",
+               .id     = -1,
+               .parent = &clk_div_mpll2.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV1, .shift = 24, .size = 5 },
+};
+
+static struct clksrc_clk clk_div_hdmi = {
+       .clk    = {
+               .name   = "div_hdmi",
+               .id     = -1,
+               .parent = &clk_mout_hpll.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV3, .shift = 28, .size = 4 },
+};
+
+static int s5pc100_epll_enable(struct clk *clk, int enable)
+{
+       unsigned int ctrlbit = clk->ctrlbit;
+       unsigned int epll_con = __raw_readl(S5P_EPLL_CON) & ~ctrlbit;
+
+       if (enable)
+               __raw_writel(epll_con | ctrlbit, S5P_EPLL_CON);
+       else
+               __raw_writel(epll_con, S5P_EPLL_CON);
+
+       return 0;
+}
+
+static unsigned long s5pc100_epll_get_rate(struct clk *clk)
+{
+       return clk->rate;
+}
+
+static u32 epll_div[][4] = {
+       { 32750000,     131, 3, 4 },
+       { 32768000,     131, 3, 4 },
+       { 36000000,     72,  3, 3 },
+       { 45000000,     90,  3, 3 },
+       { 45158000,     90,  3, 3 },
+       { 45158400,     90,  3, 3 },
+       { 48000000,     96,  3, 3 },
+       { 49125000,     131, 4, 3 },
+       { 49152000,     131, 4, 3 },
+       { 60000000,     120, 3, 3 },
+       { 67737600,     226, 5, 3 },
+       { 67738000,     226, 5, 3 },
+       { 73800000,     246, 5, 3 },
+       { 73728000,     246, 5, 3 },
+       { 72000000,     144, 3, 3 },
+       { 84000000,     168, 3, 3 },
+       { 96000000,     96,  3, 2 },
+       { 144000000,    144, 3, 2 },
+       { 192000000,    96,  3, 1 }
+};
+
+static int s5pc100_epll_set_rate(struct clk *clk, unsigned long rate)
+{
+       unsigned int epll_con;
+       unsigned int i;
+
+       if (clk->rate == rate)  /* Return if nothing changed */
+               return 0;
+
+       epll_con = __raw_readl(S5P_EPLL_CON);
+
+       epll_con &= ~(PLL65XX_MDIV_MASK | PLL65XX_PDIV_MASK | PLL65XX_SDIV_MASK);
+
+       for (i = 0; i < ARRAY_SIZE(epll_div); i++) {
+               if (epll_div[i][0] == rate) {
+                       epll_con |= (epll_div[i][1] << PLL65XX_MDIV_SHIFT) |
+                                   (epll_div[i][2] << PLL65XX_PDIV_SHIFT) |
+                                   (epll_div[i][3] << PLL65XX_SDIV_SHIFT);
+                       break;
+               }
+       }
+
+       if (i == ARRAY_SIZE(epll_div)) {
+               printk(KERN_ERR "%s: Invalid Clock EPLL Frequency\n", __func__);
+               return -EINVAL;
+       }
+
+       __raw_writel(epll_con, S5P_EPLL_CON);
+
+       clk->rate = rate;
+
+       return 0;
+}
+
+static struct clk_ops s5pc100_epll_ops = {
+       .get_rate = s5pc100_epll_get_rate,
+       .set_rate = s5pc100_epll_set_rate,
+};
+
+static int s5pc100_d0_0_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D00, clk, enable);
+}
+
+static int s5pc100_d0_1_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D01, clk, enable);
+}
+
+static int s5pc100_d0_2_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D02, clk, enable);
+}
+
+static int s5pc100_d1_0_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D10, clk, enable);
+}
+
+static int s5pc100_d1_1_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D11, clk, enable);
+}
+
+static int s5pc100_d1_2_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D12, clk, enable);
+}
+
+static int s5pc100_d1_3_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D13, clk, enable);
+}
+
+static int s5pc100_d1_4_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D14, clk, enable);
+}
+
+static int s5pc100_d1_5_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_D15, clk, enable);
+}
+
+static int s5pc100_sclk0_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_SCLK0, clk, enable);
+}
+
+static int s5pc100_sclk1_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_SCLK1, clk, enable);
+}
+
+/*
+ * The following clocks will be disabled during clock initialization. It is
+ * recommended to keep the following clocks disabled until the driver requests
+ * for enabling the clock.
+ */
+static struct clk init_clocks_disable[] = {
+       {
+               .name           = "cssys",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 6),
+       }, {
+               .name           = "secss",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "g2d",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "mdma",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "cfcon",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "nfcon",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "onenandc",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "sdm",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_2_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "seckey",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_2_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "hsmmc",
+               .id             = 2,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "hsmmc",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 6),
+       }, {
+               .name           = "hsmmc",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "modemif",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "otg",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "usbhost",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "pdma",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "pdma",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "lcd",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "rotator",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "fimc",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "fimc",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "fimc",
+               .id             = 2,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "jpeg",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "mipi-dsim",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 6),
+       }, {
+               .name           = "mipi-csis",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_1_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "g3d",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_0_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "tv",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_2_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "vp",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_2_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "mixer",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_2_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "hdmi",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_2_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "mfc",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_2_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "apc",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "iec",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "systimer",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "watchdog",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "rtc",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 9),
+       }, {
+               .name           = "i2c",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "i2c",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "spi",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 6),
+       }, {
+               .name           = "spi",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "spi",
+               .id             = 2,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "irda",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 9),
+       }, {
+               .name           = "ccan",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 10),
+       }, {
+               .name           = "ccan",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 11),
+       }, {
+               .name           = "hsitx",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 12),
+       }, {
+               .name           = "hsirx",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 13),
+       }, {
+               .name           = "iis",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "iis",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "iis",
+               .id             = 2,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "ac97",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "pcm",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "pcm",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "spdif",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 6),
+       }, {
+               .name           = "adc",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "keyif",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_5_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "spi_48m",
+               .id             = 0,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 7),
+       }, {
+               .name           = "spi_48m",
+               .id             = 1,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 8),
+       }, {
+               .name           = "spi_48m",
+               .id             = 2,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 9),
+       }, {
+               .name           = "mmc_48m",
+               .id             = 0,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 15),
+       }, {
+               .name           = "mmc_48m",
+               .id             = 1,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 16),
+       }, {
+               .name           = "mmc_48m",
+               .id             = 2,
+               .parent         = &clk_mout_48m.clk,
+               .enable         = s5pc100_sclk0_ctrl,
+               .ctrlbit        = (1 << 17),
+       },
+};
+
+static struct clk clk_vclk54m = {
+       .name           = "vclk_54m",
+       .id             = -1,
+       .rate           = 54000000,
+};
+
+static struct clk clk_i2scdclk0 = {
+       .name           = "i2s_cdclk0",
+       .id             = -1,
+};
+
+static struct clk clk_i2scdclk1 = {
+       .name           = "i2s_cdclk1",
+       .id             = -1,
+};
+
+static struct clk clk_i2scdclk2 = {
+       .name           = "i2s_cdclk2",
+       .id             = -1,
+};
+
+static struct clk clk_pcmcdclk0 = {
+       .name           = "pcm_cdclk0",
+       .id             = -1,
+};
+
+static struct clk clk_pcmcdclk1 = {
+       .name           = "pcm_cdclk1",
+       .id             = -1,
+};
+
+static struct clk *clk_src_group1_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll2.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_group1 = {
+       .sources        = clk_src_group1_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group1_list),
+};
+
+static struct clk *clk_src_group2_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+};
+
+struct clksrc_sources clk_src_group2 = {
+       .sources        = clk_src_group2_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group2_list),
+};
+
+static struct clk *clk_src_group3_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_i2scdclk0,
+       [4] = &clk_pcmcdclk0,
+       [5] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_group3 = {
+       .sources        = clk_src_group3_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group3_list),
+};
+
+static struct clk *clk_src_group4_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_i2scdclk1,
+       [4] = &clk_pcmcdclk1,
+       [5] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_group4 = {
+       .sources        = clk_src_group4_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group4_list),
+};
+
+static struct clk *clk_src_group5_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_i2scdclk2,
+       [4] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_group5 = {
+       .sources        = clk_src_group5_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group5_list),
+};
+
+static struct clk *clk_src_group6_list[] = {
+       [0] = &s5p_clk_27m,
+       [1] = &clk_vclk54m,
+       [2] = &clk_div_hdmi.clk,
+};
+
+struct clksrc_sources clk_src_group6 = {
+       .sources        = clk_src_group6_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group6_list),
+};
+
+static struct clk *clk_src_group7_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_mout_hpll.clk,
+       [3] = &clk_vclk54m,
+};
+
+struct clksrc_sources clk_src_group7 = {
+       .sources        = clk_src_group7_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_group7_list),
+};
+
+static struct clk *clk_src_mmc0_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+};
+
+struct clksrc_sources clk_src_mmc0 = {
+       .sources        = clk_src_mmc0_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mmc0_list),
+};
+
+static struct clk *clk_src_mmc12_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_mmc12 = {
+       .sources        = clk_src_mmc12_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_mmc12_list),
+};
+
+static struct clk *clk_src_irda_usb_list[] = {
+       [0] = &clk_mout_epll.clk,
+       [1] = &clk_div_mpll.clk,
+       [2] = &clk_fin_epll,
+       [3] = &clk_mout_hpll.clk,
+};
+
+struct clksrc_sources clk_src_irda_usb = {
+       .sources        = clk_src_irda_usb_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_irda_usb_list),
+};
+
+static struct clk *clk_src_pwi_list[] = {
+       [0] = &clk_fin_epll,
+       [1] = &clk_mout_epll.clk,
+       [2] = &clk_div_mpll.clk,
+};
+
+struct clksrc_sources clk_src_pwi = {
+       .sources        = clk_src_pwi_list,
+       .nr_sources     = ARRAY_SIZE(clk_src_pwi_list),
+};
+
+static struct clksrc_clk clksrcs[] = {
+       {
+               .clk    = {
+                       .name           = "sclk_spi",
+                       .id             = 0,
+                       .ctrlbit        = (1 << 4),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_group1,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 4, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 4, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_spi",
+                       .id             = 1,
+                       .ctrlbit        = (1 << 5),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_group1,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 8, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 8, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_spi",
+                       .id             = 2,
+                       .ctrlbit        = (1 << 6),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_group1,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 12, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 12, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "uclk1",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 3),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_group2,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 0, .size = 1 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 0, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_mixer",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 6),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_group6,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 28, .size = 2 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_audio",
+                       .id             = 0,
+                       .ctrlbit        = (1 << 8),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group3,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 12, .size = 3 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 12, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_audio",
+                       .id             = 1,
+                       .ctrlbit        = (1 << 9),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group4,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 16, .size = 3 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 16, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_audio",
+                       .id             = 2,
+                       .ctrlbit        = (1 << 10),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group5,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 20, .size = 3 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 20, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_lcd",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 0),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group7,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 12, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 12, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 0,
+                       .ctrlbit        = (1 << 1),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group7,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 16, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 16, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 1,
+                       .ctrlbit        = (1 << 2),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group7,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 20, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 20, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 2,
+                       .ctrlbit        = (1 << 3),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_group7,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 24, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 24, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "mmc_bus",
+                       .id             = 0,
+                       .ctrlbit        = (1 << 12),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_mmc0,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 0, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 0, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "mmc_bus",
+                       .id             = 1,
+                       .ctrlbit        = (1 << 13),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_mmc12,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 4, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 4, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "mmc_bus",
+                       .id             = 2,
+                       .ctrlbit        = (1 << 14),
+                       .enable         = s5pc100_sclk1_ctrl,
+
+               },
+               .sources = &clk_src_mmc12,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 8, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 8, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_irda",
+                       .id             = 2,
+                       .ctrlbit        = (1 << 10),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_irda_usb,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 8, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 8, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_irda",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 10),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_mmc12,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 16, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 16, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_pwi",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 1),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_pwi,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 0, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 0, .size = 3 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_uhost",
+                       .id             = -1,
+                       .ctrlbit        = (1 << 11),
+                       .enable         = s5pc100_sclk0_ctrl,
+
+               },
+               .sources = &clk_src_irda_usb,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 20, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 20, .size = 4 },
+       },
+};
+
+/* Clock initialisation code */
+static struct clksrc_clk *sysclks[] = {
+       &clk_mout_apll,
+       &clk_mout_epll,
+       &clk_mout_mpll,
+       &clk_mout_hpll,
+       &clk_mout_href,
+       &clk_mout_48m,
+       &clk_div_apll,
+       &clk_div_arm,
+       &clk_div_d0_bus,
+       &clk_div_pclkd0,
+       &clk_div_secss,
+       &clk_div_apll2,
+       &clk_mout_am,
+       &clk_div_d1_bus,
+       &clk_div_mpll2,
+       &clk_div_mpll,
+       &clk_mout_onenand,
+       &clk_div_onenand,
+       &clk_div_pclkd1,
+       &clk_div_cam,
+       &clk_div_hdmi,
+};
+
+void __init_or_cpufreq s5pc100_setup_clocks(void)
+{
+       unsigned long xtal;
+       unsigned long arm;
+       unsigned long hclkd0;
+       unsigned long hclkd1;
+       unsigned long pclkd0;
+       unsigned long pclkd1;
+       unsigned long apll;
+       unsigned long mpll;
+       unsigned long epll;
+       unsigned long hpll;
+       unsigned int ptr;
+
+       /* Set S5PC100 functions for clk_fout_epll */
+       clk_fout_epll.enable = s5pc100_epll_enable;
+       clk_fout_epll.ops = &s5pc100_epll_ops;
+
+       printk(KERN_DEBUG "%s: registering clocks\n", __func__);
+
+       xtal = clk_get_rate(&clk_xtal);
+
+       printk(KERN_DEBUG "%s: xtal is %ld\n", __func__, xtal);
+
+       apll = s5p_get_pll65xx(xtal, __raw_readl(S5P_APLL_CON));
+       mpll = s5p_get_pll65xx(xtal, __raw_readl(S5P_MPLL_CON));
+       epll = s5p_get_pll65xx(xtal, __raw_readl(S5P_EPLL_CON));
+       hpll = s5p_get_pll65xx(xtal, __raw_readl(S5P_HPLL_CON));
+
+       printk(KERN_INFO "S5PC100: PLL settings, A=%ld.%ldMHz, M=%ld.%ldMHz, E=%ld.%ldMHz, H=%ld.%ldMHz\n",
+                       print_mhz(apll), print_mhz(mpll), print_mhz(epll), print_mhz(hpll));
+
+       clk_fout_apll.rate = apll;
+       clk_fout_mpll.rate = mpll;
+       clk_fout_epll.rate = epll;
+       clk_mout_hpll.clk.rate = hpll;
+
+       for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
+               s3c_set_clksrc(&clksrcs[ptr], true);
+
+       arm = clk_get_rate(&clk_div_arm.clk);
+       hclkd0 = clk_get_rate(&clk_div_d0_bus.clk);
+       pclkd0 = clk_get_rate(&clk_div_pclkd0.clk);
+       hclkd1 = clk_get_rate(&clk_div_d1_bus.clk);
+       pclkd1 = clk_get_rate(&clk_div_pclkd1.clk);
+
+       printk(KERN_INFO "S5PC100: HCLKD0=%ld.%ldMHz, HCLKD1=%ld.%ldMHz, PCLKD0=%ld.%ldMHz, PCLKD1=%ld.%ldMHz\n",
+                       print_mhz(hclkd0), print_mhz(hclkd1), print_mhz(pclkd0), print_mhz(pclkd1));
+
+       clk_f.rate = arm;
+       clk_h.rate = hclkd1;
+       clk_p.rate = pclkd1;
+}
+
+/*
+ * The following clocks will be enabled during clock initialization.
+ */
+static struct clk init_clocks[] = {
+       {
+               .name           = "tzic",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "intc",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_0_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "ebi",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 5),
+       }, {
+               .name           = "intmem",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 4),
+       }, {
+               .name           = "sromc",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "dmc",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "chipid",
+               .id             = -1,
+               .parent         = &clk_div_d0_bus.clk,
+               .enable         = s5pc100_d0_1_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "gpio",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "uart",
+               .id             = 0,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 0),
+       }, {
+               .name           = "uart",
+               .id             = 1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 1),
+       }, {
+               .name           = "uart",
+               .id             = 2,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 2),
+       }, {
+               .name           = "uart",
+               .id             = 3,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_4_ctrl,
+               .ctrlbit        = (1 << 3),
+       }, {
+               .name           = "timers",
+               .id             = -1,
+               .parent         = &clk_div_d1_bus.clk,
+               .enable         = s5pc100_d1_3_ctrl,
+               .ctrlbit        = (1 << 6),
+       },
+};
+
+static struct clk *clks[] __initdata = {
+       &clk_ext,
+       &clk_i2scdclk0,
+       &clk_i2scdclk1,
+       &clk_i2scdclk2,
+       &clk_pcmcdclk0,
+       &clk_pcmcdclk1,
+};
+
+void __init s5pc100_register_clocks(void)
+{
+       struct clk *clkp;
+       int ret;
+       int ptr;
+
+       s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
+
+       for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
+               s3c_register_clksrc(sysclks[ptr], 1);
+
+       s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
+       s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
+
+       clkp = init_clocks_disable;
+       for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
+
+               ret = s3c24xx_register_clock(clkp);
+               if (ret < 0) {
+                       printk(KERN_ERR "Failed to register clock %s (%d)\n",
+                              clkp->name, ret);
+               }
+               (clkp->enable)(clkp, 0);
+       }
+
+       s3c_pwmclk_init();
+}
similarity index 78%
rename from arch/arm/plat-s5pc1xx/gpiolib.c
rename to arch/arm/mach-s5pc100/gpiolib.c
index 1ffc57a..c8e8336 100644 (file)
 #include <linux/gpio.h>
 
 #include <mach/map.h>
+#include <mach/regs-gpio.h>
 
 #include <plat/gpio-core.h>
 #include <plat/gpio-cfg.h>
 #include <plat/gpio-cfg-helpers.h>
-#include <plat/regs-gpio.h>
 
 /* S5PC100 GPIO bank summary:
  *
  * L3  8       4Bit    None
  */
 
-#define OFF_GPCON      (0x00)
-#define OFF_GPDAT      (0x04)
-
-#define con_4bit_shift(__off) ((__off) * 4)
-
-#if 1
-#define gpio_dbg(x...) do { } while (0)
-#else
-#define gpio_dbg(x...) printk(KERN_DEBUG x)
-#endif
-
-/* The s5pc1xx_gpiolib routines are to control the gpio banks where
- * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
- * following example:
- *
- * base + 0x00: Control register, 4 bits per gpio
- *             gpio n: 4 bits starting at (4*n)
- *             0000 = input, 0001 = output, others mean special-function
- * base + 0x04: Data register, 1 bit per gpio
- *             bit n: data bit n
- *
- * Note, since the data register is one bit per gpio and is at base + 0x4
- * we can use s3c_gpiolib_get and s3c_gpiolib_set to change the state of
- * the output.
- */
-
-static int s5pc1xx_gpiolib_input(struct gpio_chip *chip, unsigned offset)
-{
-       struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
-       void __iomem *base = ourchip->base;
-       unsigned long con;
-
-       con = __raw_readl(base + OFF_GPCON);
-       con &= ~(0xf << con_4bit_shift(offset));
-       __raw_writel(con, base + OFF_GPCON);
-
-       gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con);
-
-       return 0;
-}
-
-static int s5pc1xx_gpiolib_output(struct gpio_chip *chip,
-                                      unsigned offset, int value)
-{
-       struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
-       void __iomem *base = ourchip->base;
-       unsigned long con;
-       unsigned long dat;
-
-       con = __raw_readl(base + OFF_GPCON);
-       con &= ~(0xf << con_4bit_shift(offset));
-       con |= 0x1 << con_4bit_shift(offset);
-
-       dat = __raw_readl(base + OFF_GPDAT);
-       if (value)
-               dat |= 1 << offset;
-       else
-               dat &= ~(1 << offset);
-
-       __raw_writel(dat, base + OFF_GPDAT);
-       __raw_writel(con, base + OFF_GPCON);
-       __raw_writel(dat, base + OFF_GPDAT);
-
-       gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
-
-       return 0;
-}
-
+#if 0
 static int s5pc1xx_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
 {
        return S3C_IRQ_GPIO(chip->base + offset);
@@ -152,7 +85,7 @@ static int s5pc1xx_gpiolib_to_eint(struct gpio_chip *chip, unsigned int offset)
                return IRQ_EINT(24 + offset);
        return -EINVAL;
 }
-
+#endif
 static struct s3c_gpio_cfg gpio_cfg = {
        .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
        .set_pull       = s3c_gpio_setpull_updown,
@@ -452,12 +385,9 @@ static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
 extern struct irq_chip s5pc1xx_gpioint;
 extern void s5pc1xx_irq_gpioint_handler(unsigned int irq, struct irq_desc *desc);
 
-static __init void s5pc1xx_gpiolib_link(struct s3c_gpio_chip *chip)
+static __init void s5pc100_gpiolib_link(struct s3c_gpio_chip *chip)
 {
-       chip->chip.direction_input = s5pc1xx_gpiolib_input;
-       chip->chip.direction_output = s5pc1xx_gpiolib_output;
-       chip->pm = __gpio_pm(&s3c_gpio_pm_4bit);
-
+#if 0
        /* Interrupt */
        if (chip->config == &gpio_cfg) {
                int i, irq;
@@ -473,31 +403,26 @@ static __init void s5pc1xx_gpiolib_link(struct s3c_gpio_chip *chip)
                }
        } else if (chip->config == &gpio_cfg_eint)
                chip->chip.to_irq = s5pc1xx_gpiolib_to_eint;
-}
-
-static __init void s5pc1xx_gpiolib_add(struct s3c_gpio_chip *chips,
-                                      int nr_chips,
-                                      void (*fn)(struct s3c_gpio_chip *))
-{
-       for (; nr_chips > 0; nr_chips--, chips++) {
-               if (fn)
-                       (fn)(chips);
-               s3c_gpiolib_add(chips);
-       }
+#endif
 }
 
 static __init int s5pc1xx_gpiolib_init(void)
 {
-       struct s3c_gpio_chip *chips;
+       struct s3c_gpio_chip *chip;
        int nr_chips;
 
-               chips = s5pc100_gpio_chips;
-               nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
+       chip = s5pc100_gpio_chips;
+       nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
+
+       for (; nr_chips > 0; nr_chips--, chip++)
+               s5pc100_gpiolib_link(chip);
 
-       s5pc1xx_gpiolib_add(chips, nr_chips, s5pc1xx_gpiolib_link);
+       samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips,
+                                      ARRAY_SIZE(s5pc100_gpio_chips));
+#if 0
        /* Interrupt */
        set_irq_chained_handler(IRQ_GPIOINT, s5pc1xx_irq_gpioint_handler);
-
+#endif
        return 0;
 }
 core_initcall(s5pc1xx_gpiolib_init);
index 2c4cbe8..29a8a12 100644 (file)
@@ -12,6 +12,9 @@
  * published by the Free Software Foundation.
 */
 
+#ifndef __ASM_ARCH_GPIO_H
+#define __ASM_ARCH_GPIO_H __FILE__
+
 #define gpio_get_value __gpio_get_value
 #define gpio_set_value __gpio_set_value
 #define gpio_cansleep  __gpio_cansleep
 #define S5PC100_GPIO_L2_NR     (8)
 #define S5PC100_GPIO_L3_NR     (8)
 #define S5PC100_GPIO_L4_NR     (8)
-#define S5PC100_GPIO_MP00_NR   (8)
-#define S5PC100_GPIO_MP01_NR   (8)
-#define S5PC100_GPIO_MP02_NR   (8)
-#define S5PC100_GPIO_MP03_NR   (8)
-#define S5PC100_GPIO_MP04_NR   (5)
 
 /* GPIO bank numbes */
 
  * change from one gpio bank to another can be caught.
 */
 
-#define S5PC1XX_GPIO_NEXT(__gpio) \
+#define S5PC100_GPIO_NEXT(__gpio) \
        ((__gpio##_START) + (__gpio##_NR) + CONFIG_S3C_GPIO_SPACE + 1)
 
-enum s3c_gpio_number {
+enum s5p_gpio_number {
        S5PC100_GPIO_A0_START   = 0,
-       S5PC100_GPIO_A1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_A0),
-       S5PC100_GPIO_B_START    = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_A1),
-       S5PC100_GPIO_C_START    = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_B),
-       S5PC100_GPIO_D_START    = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_C),
-       S5PC100_GPIO_E0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_D),
-       S5PC100_GPIO_E1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_E0),
-       S5PC100_GPIO_F0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_E1),
-       S5PC100_GPIO_F1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_F0),
-       S5PC100_GPIO_F2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_F1),
-       S5PC100_GPIO_F3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_F2),
-       S5PC100_GPIO_G0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_F3),
-       S5PC100_GPIO_G1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_G0),
-       S5PC100_GPIO_G2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_G1),
-       S5PC100_GPIO_G3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_G2),
-       S5PC100_GPIO_H0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_G3),
-       S5PC100_GPIO_H1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_H0),
-       S5PC100_GPIO_H2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_H1),
-       S5PC100_GPIO_H3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_H2),
-       S5PC100_GPIO_I_START    = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_H3),
-       S5PC100_GPIO_J0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_I),
-       S5PC100_GPIO_J1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_J0),
-       S5PC100_GPIO_J2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_J1),
-       S5PC100_GPIO_J3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_J2),
-       S5PC100_GPIO_J4_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_J3),
-       S5PC100_GPIO_K0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_J4),
-       S5PC100_GPIO_K1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_K0),
-       S5PC100_GPIO_K2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_K1),
-       S5PC100_GPIO_K3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_K2),
-       S5PC100_GPIO_L0_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_K3),
-       S5PC100_GPIO_L1_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_L0),
-       S5PC100_GPIO_L2_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_L1),
-       S5PC100_GPIO_L3_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_L2),
-       S5PC100_GPIO_L4_START   = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_L3),
-       S5PC100_GPIO_MP00_START = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_L4),
-       S5PC100_GPIO_MP01_START = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_MP00),
-       S5PC100_GPIO_MP02_START = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_MP01),
-       S5PC100_GPIO_MP03_START = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_MP02),
-       S5PC100_GPIO_MP04_START = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_MP03),
-       S5PC100_GPIO_END        = S5PC1XX_GPIO_NEXT(S5PC100_GPIO_MP04),
+       S5PC100_GPIO_A1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_A0),
+       S5PC100_GPIO_B_START    = S5PC100_GPIO_NEXT(S5PC100_GPIO_A1),
+       S5PC100_GPIO_C_START    = S5PC100_GPIO_NEXT(S5PC100_GPIO_B),
+       S5PC100_GPIO_D_START    = S5PC100_GPIO_NEXT(S5PC100_GPIO_C),
+       S5PC100_GPIO_E0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_D),
+       S5PC100_GPIO_E1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_E0),
+       S5PC100_GPIO_F0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_E1),
+       S5PC100_GPIO_F1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_F0),
+       S5PC100_GPIO_F2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_F1),
+       S5PC100_GPIO_F3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_F2),
+       S5PC100_GPIO_G0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_F3),
+       S5PC100_GPIO_G1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_G0),
+       S5PC100_GPIO_G2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_G1),
+       S5PC100_GPIO_G3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_G2),
+       S5PC100_GPIO_H0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_G3),
+       S5PC100_GPIO_H1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_H0),
+       S5PC100_GPIO_H2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_H1),
+       S5PC100_GPIO_H3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_H2),
+       S5PC100_GPIO_I_START    = S5PC100_GPIO_NEXT(S5PC100_GPIO_H3),
+       S5PC100_GPIO_J0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_I),
+       S5PC100_GPIO_J1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_J0),
+       S5PC100_GPIO_J2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_J1),
+       S5PC100_GPIO_J3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_J2),
+       S5PC100_GPIO_J4_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_J3),
+       S5PC100_GPIO_K0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_J4),
+       S5PC100_GPIO_K1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_K0),
+       S5PC100_GPIO_K2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_K1),
+       S5PC100_GPIO_K3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_K2),
+       S5PC100_GPIO_L0_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_K3),
+       S5PC100_GPIO_L1_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_L0),
+       S5PC100_GPIO_L2_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_L1),
+       S5PC100_GPIO_L3_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_L2),
+       S5PC100_GPIO_L4_START   = S5PC100_GPIO_NEXT(S5PC100_GPIO_L3),
+       S5PC100_GPIO_END        = S5PC100_GPIO_NEXT(S5PC100_GPIO_L4),
 };
 
 /* S5PC100 GPIO number definitions. */
@@ -146,17 +139,13 @@ enum s3c_gpio_number {
 #define S5PC100_GPL2(_nr)      (S5PC100_GPIO_L2_START + (_nr))
 #define S5PC100_GPL3(_nr)      (S5PC100_GPIO_L3_START + (_nr))
 #define S5PC100_GPL4(_nr)      (S5PC100_GPIO_L4_START + (_nr))
-#define S5PC100_MP00(_nr)      (S5PC100_GPIO_MP00_START + (_nr))
-#define S5PC100_MP01(_nr)      (S5PC100_GPIO_MP01_START + (_nr))
-#define S5PC100_MP02(_nr)      (S5PC100_GPIO_MP02_START + (_nr))
-#define S5PC100_MP03(_nr)      (S5PC100_GPIO_MP03_START + (_nr))
-#define S5PC100_MP04(_nr)      (S5PC100_GPIO_MP04_START + (_nr))
-#define S5PC100_MP05(_nr)      (S5PC100_GPIO_MP05_START + (_nr))
 
-/* It used the end of the S5PC1XX gpios */
+/* It used the end of the S5PC100 gpios */
 #define S3C_GPIO_END           S5PC100_GPIO_END
 
 /* define the number of gpios we need to the one after the MP04() range */
 #define ARCH_NR_GPIOS          (S5PC100_GPIO_END + 1)
 
 #include <asm-generic/gpio.h>
+
+#endif /* __ASM_ARCH_GPIO_H */
diff --git a/arch/arm/mach-s5pc100/include/mach/regs-clock.h b/arch/arm/mach-s5pc100/include/mach/regs-clock.h
new file mode 100644 (file)
index 0000000..f2283bd
--- /dev/null
@@ -0,0 +1,71 @@
+/* linux/arch/arm/mach-s5pc100/include/mach/regs-clock.h
+ *
+ * Copyright (c) 2010 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * S5PC100 - Clock register definitions
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#ifndef __ASM_ARCH_REGS_CLOCK_H
+#define __ASM_ARCH_REGS_CLOCK_H __FILE__
+
+#include <mach/map.h>
+
+#define S5P_CLKREG(x)          (S3C_VA_SYS + (x))
+
+#define S5P_APLL_LOCK          S5P_CLKREG(0x00)
+#define S5P_MPLL_LOCK          S5P_CLKREG(0x04)
+#define S5P_EPLL_LOCK          S5P_CLKREG(0x08)
+#define S5P_HPLL_LOCK          S5P_CLKREG(0x0C)
+
+#define S5P_APLL_CON           S5P_CLKREG(0x100)
+#define S5P_MPLL_CON           S5P_CLKREG(0x104)
+#define S5P_EPLL_CON           S5P_CLKREG(0x108)
+#define S5P_HPLL_CON           S5P_CLKREG(0x10C)
+
+#define S5P_CLK_SRC0           S5P_CLKREG(0x200)
+#define S5P_CLK_SRC1           S5P_CLKREG(0x204)
+#define S5P_CLK_SRC2           S5P_CLKREG(0x208)
+#define S5P_CLK_SRC3           S5P_CLKREG(0x20C)
+
+#define S5P_CLK_DIV0           S5P_CLKREG(0x300)
+#define S5P_CLK_DIV1           S5P_CLKREG(0x304)
+#define S5P_CLK_DIV2           S5P_CLKREG(0x308)
+#define S5P_CLK_DIV3           S5P_CLKREG(0x30C)
+#define S5P_CLK_DIV4           S5P_CLKREG(0x310)
+
+#define S5P_CLK_OUT            S5P_CLKREG(0x400)
+
+#define S5P_CLKGATE_D00                S5P_CLKREG(0x500)
+#define S5P_CLKGATE_D01                S5P_CLKREG(0x504)
+#define S5P_CLKGATE_D02                S5P_CLKREG(0x508)
+
+#define S5P_CLKGATE_D10                S5P_CLKREG(0x520)
+#define S5P_CLKGATE_D11                S5P_CLKREG(0x524)
+#define S5P_CLKGATE_D12                S5P_CLKREG(0x528)
+#define S5P_CLKGATE_D13                S5P_CLKREG(0x52C)
+#define S5P_CLKGATE_D14                S5P_CLKREG(0x530)
+#define S5P_CLKGATE_D15                S5P_CLKREG(0x534)
+
+#define S5P_CLKGATE_D20                S5P_CLKREG(0x540)
+
+#define S5P_CLKGATE_SCLK0      S5P_CLKREG(0x560)
+#define S5P_CLKGATE_SCLK1      S5P_CLKREG(0x564)
+
+/* CLKDIV0 */
+#define S5P_CLKDIV0_D0_MASK            (0x7<<8)
+#define S5P_CLKDIV0_D0_SHIFT           (8)
+#define S5P_CLKDIV0_PCLKD0_MASK                (0x7<<12)
+#define S5P_CLKDIV0_PCLKD0_SHIFT       (12)
+
+/* CLKDIV1 */
+#define S5P_CLKDIV1_D1_MASK            (0x7<<12)
+#define S5P_CLKDIV1_D1_SHIFT           (12)
+#define S5P_CLKDIV1_PCLKD1_MASK                (0x7<<16)
+#define S5P_CLKDIV1_PCLKD1_SHIFT       (16)
+
+#endif /* __ASM_ARCH_REGS_CLOCK_H */
@@ -3,11 +3,11 @@
  * Copyright 2009 Samsung Electronics Co.
  *      Byungho Min <bhmin@samsung.com>
  *
- * S5PC1XX - GPIO register definitions
+ * S5PC100 - GPIO register definitions
  */
 
-#ifndef __ASM_PLAT_S5PC1XX_REGS_GPIO_H
-#define __ASM_PLAT_S5PC1XX_REGS_GPIO_H __FILE__
+#ifndef __ASM_MACH_S5PC100_REGS_GPIO_H
+#define __ASM_MACH_S5PC100_REGS_GPIO_H __FILE__
 
 #include <mach/map.h>
 
@@ -66,5 +66,5 @@
 #define S5PC100_GPx_OUTPUT(__gpio)     (0x1 << ((__gpio) * 4))
 #define S5PC100_GPx_CONMASK(__gpio)    (0xf << ((__gpio) * 4))
 
-#endif /* __ASM_PLAT_S5PC1XX_REGS_GPIO_H */
+#endif /* __ASM_MACH_S5PC100_REGS_GPIO_H */
 
index ae3c52c..bfe67db 100644 (file)
@@ -35,7 +35,6 @@
 
 #include <plat/regs-serial.h>
 #include <plat/gpio-cfg.h>
-#include <plat/regs-gpio.h>
 
 #include <plat/clock.h>
 #include <plat/devs.h>
similarity index 89%
rename from arch/arm/plat-s5pc1xx/setup-fb-24bpp.c
rename to arch/arm/mach-s5pc100/setup-fb-24bpp.c
index 1a63768..6eba6cb 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * linux/arch/arm/plat-s5pc100/setup-fb-24bpp.c
+ * linux/arch/arm/mach-s5pc100/setup-fb-24bpp.c
  *
  * Copyright 2009 Samsung Electronics
  *
- * Base S5PC1XX setup information for 24bpp LCD framebuffer
+ * Base S5PC100 setup information for 24bpp LCD framebuffer
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -19,7 +19,6 @@
 #include <mach/map.h>
 #include <plat/fb.h>
 #include <plat/gpio-cfg.h>
-#include <plat/gpio-cfg-s5pc1xx.h>
 
 #define DISR_OFFSET    0x7008
 
similarity index 89%
rename from arch/arm/plat-s5pc1xx/setup-i2c0.c
rename to arch/arm/mach-s5pc100/setup-i2c0.c
index 5e4a7c3..dd3174e 100644 (file)
@@ -1,9 +1,9 @@
-/* linux/arch/arm/plat-s5pc1xx/setup-i2c0.c
+/* linux/arch/arm/mach-s5pc100/setup-i2c0.c
  *
  * Copyright 2009 Samsung Electronics Co.
  *     Byungho Min <bhmin@samsung.com>
  *
- * Base S5PC1XX I2C bus 0 gpio configuration
+ * Base S5PC100 I2C bus 0 gpio configuration
  *
  * Based on plat-s3c64xx/setup-i2c0.c
  *
similarity index 89%
rename from arch/arm/plat-s5pc1xx/setup-i2c1.c
rename to arch/arm/mach-s5pc100/setup-i2c1.c
index a0a8b4a..d1fec26 100644 (file)
@@ -1,9 +1,9 @@
-/* linux/arch/arm/plat-s3c64xx/setup-i2c1.c
+/* linux/arch/arm/mach-s5pc100/setup-i2c1.c
  *
  * Copyright 2009 Samsung Electronics Co.
  *     Byungho Min <bhmin@samsung.com>
  *
- * Base S5PC1XX I2C bus 1 gpio configuration
+ * Base S5PC100 I2C bus 1 gpio configuration
  *
  * Based on plat-s3c64xx/setup-i2c1.c
  *
index af33a1a..7601c28 100644 (file)
@@ -12,6 +12,7 @@ if ARCH_S5PV210
 config CPU_S5PV210
        bool
        select PLAT_S5P
+       select S3C_PL330_DMA
        help
          Enable S5PV210 CPU support
 
index 8ebf51c..9982781 100644 (file)
@@ -12,9 +12,14 @@ obj-                         :=
 
 # Core support for S5PV210 system
 
-obj-$(CONFIG_CPU_S5PV210)      += cpu.o init.o clock.o
+obj-$(CONFIG_CPU_S5PV210)      += cpu.o init.o clock.o dma.o gpiolib.o
+obj-$(CONFIG_CPU_S5PV210)      += setup-i2c0.o
 
 # machine support
 
 obj-$(CONFIG_MACH_SMDKV210)    += mach-smdkv210.o
 obj-$(CONFIG_MACH_SMDKC110)    += mach-smdkc110.o
+
+# device support
+
+obj-y                          += dev-audio.o
index ccccae2..154bca4 100644 (file)
 #include <plat/clock-clksrc.h>
 #include <plat/s5pv210.h>
 
+static struct clksrc_clk clk_mout_apll = {
+       .clk    = {
+               .name           = "mout_apll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_apll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
+};
+
+static struct clksrc_clk clk_mout_epll = {
+       .clk    = {
+               .name           = "mout_epll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_epll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 8, .size = 1 },
+};
+
+static struct clksrc_clk clk_mout_mpll = {
+       .clk = {
+               .name           = "mout_mpll",
+               .id             = -1,
+       },
+       .sources        = &clk_src_mpll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 4, .size = 1 },
+};
+
+static struct clk *clkset_armclk_list[] = {
+       [0] = &clk_mout_apll.clk,
+       [1] = &clk_mout_mpll.clk,
+};
+
+static struct clksrc_sources clkset_armclk = {
+       .sources        = clkset_armclk_list,
+       .nr_sources     = ARRAY_SIZE(clkset_armclk_list),
+};
+
+static struct clksrc_clk clk_armclk = {
+       .clk    = {
+               .name           = "armclk",
+               .id             = -1,
+       },
+       .sources        = &clkset_armclk,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 16, .size = 1 },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 0, .size = 3 },
+};
+
+static struct clksrc_clk clk_hclk_msys = {
+       .clk    = {
+               .name           = "hclk_msys",
+               .id             = -1,
+               .parent         = &clk_armclk.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 8, .size = 3 },
+};
+
+static struct clksrc_clk clk_pclk_msys = {
+       .clk    = {
+               .name           = "pclk_msys",
+               .id             = -1,
+               .parent         = &clk_hclk_msys.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 12, .size = 3 },
+};
+
+static struct clksrc_clk clk_sclk_a2m = {
+       .clk    = {
+               .name           = "sclk_a2m",
+               .id             = -1,
+               .parent         = &clk_mout_apll.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 4, .size = 3 },
+};
+
+static struct clk *clkset_hclk_sys_list[] = {
+       [0] = &clk_mout_mpll.clk,
+       [1] = &clk_sclk_a2m.clk,
+};
+
+static struct clksrc_sources clkset_hclk_sys = {
+       .sources        = clkset_hclk_sys_list,
+       .nr_sources     = ARRAY_SIZE(clkset_hclk_sys_list),
+};
+
+static struct clksrc_clk clk_hclk_dsys = {
+       .clk    = {
+               .name   = "hclk_dsys",
+               .id     = -1,
+       },
+       .sources        = &clkset_hclk_sys,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 20, .size = 1 },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 16, .size = 4 },
+};
+
+static struct clksrc_clk clk_pclk_dsys = {
+       .clk    = {
+               .name   = "pclk_dsys",
+               .id     = -1,
+               .parent = &clk_hclk_dsys.clk,
+       },
+       .reg_div = { .reg = S5P_CLK_DIV0, .shift = 20, .size = 3 },
+};
+
+static struct clksrc_clk clk_hclk_psys = {
+       .clk    = {
+               .name   = "hclk_psys",
+               .id     = -1,
+       },
+       .sources        = &clkset_hclk_sys,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 24, .size = 1 },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 24, .size = 4 },
+};
+
+static struct clksrc_clk clk_pclk_psys = {
+       .clk    = {
+               .name   = "pclk_psys",
+               .id     = -1,
+               .parent = &clk_hclk_psys.clk,
+       },
+       .reg_div        = { .reg = S5P_CLK_DIV0, .shift = 28, .size = 3 },
+};
+
 static int s5pv210_clk_ip0_ctrl(struct clk *clk, int enable)
 {
        return s5p_gatectrl(S5P_CLKGATE_IP0, clk, enable);
@@ -51,176 +173,226 @@ static int s5pv210_clk_ip3_ctrl(struct clk *clk, int enable)
        return s5p_gatectrl(S5P_CLKGATE_IP3, clk, enable);
 }
 
-static struct clk clk_h200 = {
-       .name           = "hclk200",
+static int s5pv210_clk_ip4_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLKGATE_IP4, clk, enable);
+}
+
+static int s5pv210_clk_mask0_ctrl(struct clk *clk, int enable)
+{
+       return s5p_gatectrl(S5P_CLK_SRC_MASK0, clk, enable);
+}
+
+static struct clk clk_sclk_hdmi27m = {
+       .name           = "sclk_hdmi27m",
        .id             = -1,
+       .rate           = 27000000,
 };
 
-static struct clk clk_h100 = {
-       .name           = "hclk100",
+static struct clk clk_sclk_hdmiphy = {
+       .name           = "sclk_hdmiphy",
        .id             = -1,
 };
 
-static struct clk clk_h166 = {
-       .name           = "hclk166",
+static struct clk clk_sclk_usbphy0 = {
+       .name           = "sclk_usbphy0",
        .id             = -1,
 };
 
-static struct clk clk_h133 = {
-       .name           = "hclk133",
+static struct clk clk_sclk_usbphy1 = {
+       .name           = "sclk_usbphy1",
        .id             = -1,
 };
 
-static struct clk clk_p100 = {
-       .name           = "pclk100",
+static struct clk clk_pcmcdclk0 = {
+       .name           = "pcmcdclk",
        .id             = -1,
 };
 
-static struct clk clk_p83 = {
-       .name           = "pclk83",
+static struct clk clk_pcmcdclk1 = {
+       .name           = "pcmcdclk",
        .id             = -1,
 };
 
-static struct clk clk_p66 = {
-       .name           = "pclk66",
+static struct clk clk_pcmcdclk2 = {
+       .name           = "pcmcdclk",
        .id             = -1,
 };
 
-static struct clk *sys_clks[] = {
-       &clk_h200,
-       &clk_h100,
-       &clk_h166,
-       &clk_h133,
-       &clk_p100,
-       &clk_p83,
-       &clk_p66
+static struct clk *clkset_vpllsrc_list[] = {
+       [0] = &clk_fin_vpll,
+       [1] = &clk_sclk_hdmi27m,
+};
+
+static struct clksrc_sources clkset_vpllsrc = {
+       .sources        = clkset_vpllsrc_list,
+       .nr_sources     = ARRAY_SIZE(clkset_vpllsrc_list),
+};
+
+static struct clksrc_clk clk_vpllsrc = {
+       .clk    = {
+               .name           = "vpll_src",
+               .id             = -1,
+               .enable         = s5pv210_clk_mask0_ctrl,
+               .ctrlbit        = (1 << 7),
+       },
+       .sources        = &clkset_vpllsrc,
+       .reg_src        = { .reg = S5P_CLK_SRC1, .shift = 28, .size = 1 },
+};
+
+static struct clk *clkset_sclk_vpll_list[] = {
+       [0] = &clk_vpllsrc.clk,
+       [1] = &clk_fout_vpll,
+};
+
+static struct clksrc_sources clkset_sclk_vpll = {
+       .sources        = clkset_sclk_vpll_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_vpll_list),
+};
+
+static struct clksrc_clk clk_sclk_vpll = {
+       .clk    = {
+               .name           = "sclk_vpll",
+               .id             = -1,
+       },
+       .sources        = &clkset_sclk_vpll,
+       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 12, .size = 1 },
+};
+
+static unsigned long s5pv210_clk_imem_get_rate(struct clk *clk)
+{
+       return clk_get_rate(clk->parent) / 2;
+}
+
+static struct clk_ops clk_hclk_imem_ops = {
+       .get_rate       = s5pv210_clk_imem_get_rate,
 };
 
 static struct clk init_clocks_disable[] = {
        {
                .name           = "rot",
                .id             = -1,
-               .parent         = &clk_h166,
+               .parent         = &clk_hclk_dsys.clk,
                .enable         = s5pv210_clk_ip0_ctrl,
                .ctrlbit        = (1<<29),
        }, {
                .name           = "otg",
                .id             = -1,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip1_ctrl,
                .ctrlbit        = (1<<16),
        }, {
                .name           = "usb-host",
                .id             = -1,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip1_ctrl,
                .ctrlbit        = (1<<17),
        }, {
                .name           = "lcd",
                .id             = -1,
-               .parent         = &clk_h166,
+               .parent         = &clk_hclk_dsys.clk,
                .enable         = s5pv210_clk_ip1_ctrl,
                .ctrlbit        = (1<<0),
        }, {
                .name           = "cfcon",
                .id             = 0,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip1_ctrl,
                .ctrlbit        = (1<<25),
        }, {
                .name           = "hsmmc",
                .id             = 0,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip2_ctrl,
                .ctrlbit        = (1<<16),
        }, {
                .name           = "hsmmc",
                .id             = 1,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip2_ctrl,
                .ctrlbit        = (1<<17),
        }, {
                .name           = "hsmmc",
                .id             = 2,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip2_ctrl,
                .ctrlbit        = (1<<18),
        }, {
                .name           = "hsmmc",
                .id             = 3,
-               .parent         = &clk_h133,
+               .parent         = &clk_hclk_psys.clk,
                .enable         = s5pv210_clk_ip2_ctrl,
                .ctrlbit        = (1<<19),
        }, {
                .name           = "systimer",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<16),
        }, {
                .name           = "watchdog",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<22),
        }, {
                .name           = "rtc",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<15),
        }, {
                .name           = "i2c",
                .id             = 0,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<7),
        }, {
                .name           = "i2c",
                .id             = 1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<8),
        }, {
                .name           = "i2c",
                .id             = 2,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<9),
        }, {
                .name           = "spi",
                .id             = 0,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<12),
        }, {
                .name           = "spi",
                .id             = 1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<13),
        }, {
                .name           = "spi",
                .id             = 2,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<14),
        }, {
                .name           = "timers",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<23),
        }, {
                .name           = "adc",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<24),
        }, {
                .name           = "keypad",
                .id             = -1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<21),
        }, {
@@ -246,106 +418,537 @@ static struct clk init_clocks_disable[] = {
 
 static struct clk init_clocks[] = {
        {
+               .name           = "hclk_imem",
+               .id             = -1,
+               .parent         = &clk_hclk_msys.clk,
+               .ctrlbit        = (1 << 5),
+               .enable         = s5pv210_clk_ip0_ctrl,
+               .ops            = &clk_hclk_imem_ops,
+       }, {
                .name           = "uart",
                .id             = 0,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<7),
        }, {
                .name           = "uart",
                .id             = 1,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<8),
        }, {
                .name           = "uart",
                .id             = 2,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<9),
        }, {
                .name           = "uart",
                .id             = 3,
-               .parent         = &clk_p66,
+               .parent         = &clk_pclk_psys.clk,
                .enable         = s5pv210_clk_ip3_ctrl,
                .ctrlbit        = (1<<10),
        },
 };
 
-static struct clksrc_clk clk_mout_apll = {
-       .clk    = {
-               .name           = "mout_apll",
+static struct clk *clkset_uart_list[] = {
+       [6] = &clk_mout_mpll.clk,
+       [7] = &clk_mout_epll.clk,
+};
+
+static struct clksrc_sources clkset_uart = {
+       .sources        = clkset_uart_list,
+       .nr_sources     = ARRAY_SIZE(clkset_uart_list),
+};
+
+static struct clk *clkset_group1_list[] = {
+       [0] = &clk_sclk_a2m.clk,
+       [1] = &clk_mout_mpll.clk,
+       [2] = &clk_mout_epll.clk,
+       [3] = &clk_sclk_vpll.clk,
+};
+
+static struct clksrc_sources clkset_group1 = {
+       .sources        = clkset_group1_list,
+       .nr_sources     = ARRAY_SIZE(clkset_group1_list),
+};
+
+static struct clk *clkset_sclk_onenand_list[] = {
+       [0] = &clk_hclk_psys.clk,
+       [1] = &clk_hclk_dsys.clk,
+};
+
+static struct clksrc_sources clkset_sclk_onenand = {
+       .sources        = clkset_sclk_onenand_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_onenand_list),
+};
+
+static struct clk *clkset_sclk_dac_list[] = {
+       [0] = &clk_sclk_vpll.clk,
+       [1] = &clk_sclk_hdmiphy,
+};
+
+static struct clksrc_sources clkset_sclk_dac = {
+       .sources        = clkset_sclk_dac_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_dac_list),
+};
+
+static struct clksrc_clk clk_sclk_dac = {
+       .clk            = {
+               .name           = "sclk_dac",
                .id             = -1,
+               .ctrlbit        = (1 << 10),
+               .enable         = s5pv210_clk_ip1_ctrl,
        },
-       .sources        = &clk_src_apll,
-       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 0, .size = 1 },
+       .sources        = &clkset_sclk_dac,
+       .reg_src        = { .reg = S5P_CLK_SRC1, .shift = 8, .size = 1 },
 };
 
-static struct clksrc_clk clk_mout_epll = {
-       .clk    = {
-               .name           = "mout_epll",
+static struct clksrc_clk clk_sclk_pixel = {
+       .clk            = {
+               .name           = "sclk_pixel",
                .id             = -1,
+               .parent         = &clk_sclk_vpll.clk,
        },
-       .sources        = &clk_src_epll,
-       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 8, .size = 1 },
+       .reg_div        = { .reg = S5P_CLK_DIV1, .shift = 0, .size = 4},
 };
 
-static struct clksrc_clk clk_mout_mpll = {
-       .clk = {
-               .name           = "mout_mpll",
+static struct clk *clkset_sclk_hdmi_list[] = {
+       [0] = &clk_sclk_pixel.clk,
+       [1] = &clk_sclk_hdmiphy,
+};
+
+static struct clksrc_sources clkset_sclk_hdmi = {
+       .sources        = clkset_sclk_hdmi_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_hdmi_list),
+};
+
+static struct clksrc_clk clk_sclk_hdmi = {
+       .clk            = {
+               .name           = "sclk_hdmi",
                .id             = -1,
+               .enable         = s5pv210_clk_ip1_ctrl,
+               .ctrlbit        = (1 << 11),
        },
-       .sources        = &clk_src_mpll,
-       .reg_src        = { .reg = S5P_CLK_SRC0, .shift = 4, .size = 1 },
+       .sources        = &clkset_sclk_hdmi,
+       .reg_src        = { .reg = S5P_CLK_SRC1, .shift = 0, .size = 1 },
 };
 
-static struct clk *clkset_uart_list[] = {
+static struct clk *clkset_sclk_mixer_list[] = {
+       [0] = &clk_sclk_dac.clk,
+       [1] = &clk_sclk_hdmi.clk,
+};
+
+static struct clksrc_sources clkset_sclk_mixer = {
+       .sources        = clkset_sclk_mixer_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_mixer_list),
+};
+
+static struct clk *clkset_sclk_audio0_list[] = {
+       [0] = &clk_ext_xtal_mux,
+       [1] = &clk_pcmcdclk0,
+       [2] = &clk_sclk_hdmi27m,
+       [3] = &clk_sclk_usbphy0,
+       [4] = &clk_sclk_usbphy1,
+       [5] = &clk_sclk_hdmiphy,
        [6] = &clk_mout_mpll.clk,
        [7] = &clk_mout_epll.clk,
+       [8] = &clk_sclk_vpll.clk,
 };
 
-static struct clksrc_sources clkset_uart = {
-       .sources        = clkset_uart_list,
-       .nr_sources     = ARRAY_SIZE(clkset_uart_list),
+static struct clksrc_sources clkset_sclk_audio0 = {
+       .sources        = clkset_sclk_audio0_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_audio0_list),
+};
+
+static struct clksrc_clk clk_sclk_audio0 = {
+       .clk            = {
+               .name           = "sclk_audio",
+               .id             = 0,
+               .enable         = s5pv210_clk_ip3_ctrl,
+               .ctrlbit        = (1 << 4),
+       },
+       .sources = &clkset_sclk_audio0,
+       .reg_src = { .reg = S5P_CLK_SRC6, .shift = 0, .size = 4 },
+       .reg_div = { .reg = S5P_CLK_DIV6, .shift = 0, .size = 4 },
+};
+
+static struct clk *clkset_sclk_audio1_list[] = {
+       [0] = &clk_ext_xtal_mux,
+       [1] = &clk_pcmcdclk1,
+       [2] = &clk_sclk_hdmi27m,
+       [3] = &clk_sclk_usbphy0,
+       [4] = &clk_sclk_usbphy1,
+       [5] = &clk_sclk_hdmiphy,
+       [6] = &clk_mout_mpll.clk,
+       [7] = &clk_mout_epll.clk,
+       [8] = &clk_sclk_vpll.clk,
+};
+
+static struct clksrc_sources clkset_sclk_audio1 = {
+       .sources        = clkset_sclk_audio1_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_audio1_list),
+};
+
+static struct clksrc_clk clk_sclk_audio1 = {
+       .clk            = {
+               .name           = "sclk_audio",
+               .id             = 1,
+               .enable         = s5pv210_clk_ip3_ctrl,
+               .ctrlbit        = (1 << 5),
+       },
+       .sources = &clkset_sclk_audio1,
+       .reg_src = { .reg = S5P_CLK_SRC6, .shift = 4, .size = 4 },
+       .reg_div = { .reg = S5P_CLK_DIV6, .shift = 4, .size = 4 },
+};
+
+static struct clk *clkset_sclk_audio2_list[] = {
+       [0] = &clk_ext_xtal_mux,
+       [1] = &clk_pcmcdclk0,
+       [2] = &clk_sclk_hdmi27m,
+       [3] = &clk_sclk_usbphy0,
+       [4] = &clk_sclk_usbphy1,
+       [5] = &clk_sclk_hdmiphy,
+       [6] = &clk_mout_mpll.clk,
+       [7] = &clk_mout_epll.clk,
+       [8] = &clk_sclk_vpll.clk,
+};
+
+static struct clksrc_sources clkset_sclk_audio2 = {
+       .sources        = clkset_sclk_audio2_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_audio2_list),
+};
+
+static struct clksrc_clk clk_sclk_audio2 = {
+       .clk            = {
+               .name           = "sclk_audio",
+               .id             = 2,
+               .enable         = s5pv210_clk_ip3_ctrl,
+               .ctrlbit        = (1 << 6),
+       },
+       .sources = &clkset_sclk_audio2,
+       .reg_src = { .reg = S5P_CLK_SRC6, .shift = 8, .size = 4 },
+       .reg_div = { .reg = S5P_CLK_DIV6, .shift = 8, .size = 4 },
+};
+
+static struct clk *clkset_sclk_spdif_list[] = {
+       [0] = &clk_sclk_audio0.clk,
+       [1] = &clk_sclk_audio1.clk,
+       [2] = &clk_sclk_audio2.clk,
+};
+
+static struct clksrc_sources clkset_sclk_spdif = {
+       .sources        = clkset_sclk_spdif_list,
+       .nr_sources     = ARRAY_SIZE(clkset_sclk_spdif_list),
+};
+
+static struct clk *clkset_group2_list[] = {
+       [0] = &clk_ext_xtal_mux,
+       [1] = &clk_xusbxti,
+       [2] = &clk_sclk_hdmi27m,
+       [3] = &clk_sclk_usbphy0,
+       [4] = &clk_sclk_usbphy1,
+       [5] = &clk_sclk_hdmiphy,
+       [6] = &clk_mout_mpll.clk,
+       [7] = &clk_mout_epll.clk,
+       [8] = &clk_sclk_vpll.clk,
+};
+
+static struct clksrc_sources clkset_group2 = {
+       .sources        = clkset_group2_list,
+       .nr_sources     = ARRAY_SIZE(clkset_group2_list),
 };
 
 static struct clksrc_clk clksrcs[] = {
        {
                .clk    = {
-                       .name           = "uclk1",
+                       .name           = "sclk_dmc",
                        .id             = -1,
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC6, .shift = 24, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV6, .shift = 28, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_onenand",
+                       .id             = -1,
+               },
+               .sources = &clkset_sclk_onenand,
+               .reg_src = { .reg = S5P_CLK_SRC0, .shift = 28, .size = 1 },
+               .reg_div = { .reg = S5P_CLK_DIV6, .shift = 12, .size = 3 },
+       }, {
+               .clk    = {
+                       .name           = "uclk1",
+                       .id             = 0,
                        .ctrlbit        = (1<<17),
                        .enable         = s5pv210_clk_ip3_ctrl,
                },
                .sources = &clkset_uart,
                .reg_src = { .reg = S5P_CLK_SRC4, .shift = 16, .size = 4 },
                .reg_div = { .reg = S5P_CLK_DIV4, .shift = 16, .size = 4 },
-       }
+       }, {
+               .clk            = {
+                       .name           = "uclk1",
+                       .id             = 1,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 18),
+               },
+               .sources = &clkset_uart,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 20, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 20, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "uclk1",
+                       .id             = 2,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 19),
+               },
+               .sources = &clkset_uart,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 24, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 24, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "uclk1",
+                       .id             = 3,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 20),
+               },
+               .sources = &clkset_uart,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 28, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 28, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_mixer",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip1_ctrl,
+                       .ctrlbit        = (1 << 9),
+               },
+               .sources = &clkset_sclk_mixer,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 4, .size = 1 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_spdif",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_mask0_ctrl,
+                       .ctrlbit        = (1 << 27),
+               },
+               .sources = &clkset_sclk_spdif,
+               .reg_src = { .reg = S5P_CLK_SRC6, .shift = 12, .size = 2 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 0,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 24),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 12, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 12, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 1,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 25),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 16, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 16, .size = 4 },
+       }, {
+               .clk    = {
+                       .name           = "sclk_fimc",
+                       .id             = 2,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 26),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC3, .shift = 20, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV3, .shift = 20, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_cam",
+                       .id             = 0,
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 12, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV1, .shift = 12, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_cam",
+                       .id             = 1,
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 16, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV1, .shift = 16, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_fimd",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip1_ctrl,
+                       .ctrlbit        = (1 << 0),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 20, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV1, .shift = 20, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_mmc",
+                       .id             = 0,
+                       .enable         = s5pv210_clk_ip2_ctrl,
+                       .ctrlbit        = (1 << 16),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 0, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 0, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_mmc",
+                       .id             = 1,
+                       .enable         = s5pv210_clk_ip2_ctrl,
+                       .ctrlbit        = (1 << 17),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 4, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 4, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_mmc",
+                       .id             = 2,
+                       .enable         = s5pv210_clk_ip2_ctrl,
+                       .ctrlbit        = (1 << 18),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 8, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 8, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_mmc",
+                       .id             = 3,
+                       .enable         = s5pv210_clk_ip2_ctrl,
+                       .ctrlbit        = (1 << 19),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC4, .shift = 12, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV4, .shift = 12, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_mfc",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 16),
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 4, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 4, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_g2d",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 12),
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 8, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 8, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_g3d",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 8),
+               },
+               .sources = &clkset_group1,
+               .reg_src = { .reg = S5P_CLK_SRC2, .shift = 0, .size = 2 },
+               .reg_div = { .reg = S5P_CLK_DIV2, .shift = 0, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_csis",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip0_ctrl,
+                       .ctrlbit        = (1 << 31),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC1, .shift = 24, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV1, .shift = 28, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_spi",
+                       .id             = 0,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 12),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC5, .shift = 0, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV5, .shift = 0, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_spi",
+                       .id             = 1,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 13),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC5, .shift = 4, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV5, .shift = 4, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_pwi",
+                       .id             = -1,
+                       .enable         = &s5pv210_clk_ip4_ctrl,
+                       .ctrlbit        = (1 << 2),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC6, .shift = 20, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV6, .shift = 24, .size = 4 },
+       }, {
+               .clk            = {
+                       .name           = "sclk_pwm",
+                       .id             = -1,
+                       .enable         = s5pv210_clk_ip3_ctrl,
+                       .ctrlbit        = (1 << 23),
+               },
+               .sources = &clkset_group2,
+               .reg_src = { .reg = S5P_CLK_SRC5, .shift = 12, .size = 4 },
+               .reg_div = { .reg = S5P_CLK_DIV5, .shift = 12, .size = 4 },
+       },
 };
 
 /* Clock initialisation code */
-static struct clksrc_clk *init_parents[] = {
+static struct clksrc_clk *sysclks[] = {
        &clk_mout_apll,
        &clk_mout_epll,
        &clk_mout_mpll,
+       &clk_armclk,
+       &clk_hclk_msys,
+       &clk_sclk_a2m,
+       &clk_hclk_dsys,
+       &clk_hclk_psys,
+       &clk_pclk_msys,
+       &clk_pclk_dsys,
+       &clk_pclk_psys,
+       &clk_vpllsrc,
+       &clk_sclk_vpll,
+       &clk_sclk_dac,
+       &clk_sclk_pixel,
+       &clk_sclk_hdmi,
 };
 
-#define GET_DIV(clk, field) ((((clk) & field##_MASK) >> field##_SHIFT) + 1)
-
 void __init_or_cpufreq s5pv210_setup_clocks(void)
 {
        struct clk *xtal_clk;
        unsigned long xtal;
+       unsigned long vpllsrc;
        unsigned long armclk;
-       unsigned long hclk200;
-       unsigned long hclk166;
-       unsigned long hclk133;
-       unsigned long pclk100;
-       unsigned long pclk83;
-       unsigned long pclk66;
+       unsigned long hclk_msys;
+       unsigned long hclk_dsys;
+       unsigned long hclk_psys;
+       unsigned long pclk_msys;
+       unsigned long pclk_dsys;
+       unsigned long pclk_psys;
        unsigned long apll;
        unsigned long mpll;
        unsigned long epll;
+       unsigned long vpll;
        unsigned int ptr;
        u32 clkdiv0, clkdiv1;
 
@@ -368,59 +971,46 @@ void __init_or_cpufreq s5pv210_setup_clocks(void)
        apll = s5p_get_pll45xx(xtal, __raw_readl(S5P_APLL_CON), pll_4508);
        mpll = s5p_get_pll45xx(xtal, __raw_readl(S5P_MPLL_CON), pll_4502);
        epll = s5p_get_pll45xx(xtal, __raw_readl(S5P_EPLL_CON), pll_4500);
-
-       printk(KERN_INFO "S5PV210: PLL settings, A=%ld, M=%ld, E=%ld",
-                       apll, mpll, epll);
-
-       armclk = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_APLL);
-       if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX200_MASK)
-               hclk200 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK200);
-       else
-               hclk200 = armclk / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK200);
-
-       if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX166_MASK) {
-               hclk166 = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_A2M);
-               hclk166 = hclk166 / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK166);
-       } else
-               hclk166 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK166);
-
-       if (__raw_readl(S5P_CLK_SRC0) & S5P_CLKSRC0_MUX133_MASK) {
-               hclk133 = apll / GET_DIV(clkdiv0, S5P_CLKDIV0_A2M);
-               hclk133 = hclk133 / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK133);
-       } else
-               hclk133 = mpll / GET_DIV(clkdiv0, S5P_CLKDIV0_HCLK133);
-
-       pclk100 = hclk200 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK100);
-       pclk83 = hclk166 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK83);
-       pclk66 = hclk133 / GET_DIV(clkdiv0, S5P_CLKDIV0_PCLK66);
-
-       printk(KERN_INFO "S5PV210: ARMCLK=%ld, HCLKM=%ld, HCLKD=%ld, \
-                       HCLKP=%ld, PCLKM=%ld, PCLKD=%ld, PCLKP=%ld\n",
-              armclk, hclk200, hclk166, hclk133, pclk100, pclk83, pclk66);
+       vpllsrc = clk_get_rate(&clk_vpllsrc.clk);
+       vpll = s5p_get_pll45xx(vpllsrc, __raw_readl(S5P_VPLL_CON), pll_4502);
 
        clk_fout_apll.rate = apll;
        clk_fout_mpll.rate = mpll;
        clk_fout_epll.rate = epll;
+       clk_fout_vpll.rate = vpll;
 
-       clk_f.rate = armclk;
-       clk_h.rate = hclk133;
-       clk_p.rate = pclk66;
-       clk_p66.rate = pclk66;
-       clk_p83.rate = pclk83;
-       clk_h133.rate = hclk133;
-       clk_h166.rate = hclk166;
-       clk_h200.rate = hclk200;
+       printk(KERN_INFO "S5PV210: PLL settings, A=%ld, M=%ld, E=%ld V=%ld",
+                       apll, mpll, epll, vpll);
+
+       armclk = clk_get_rate(&clk_armclk.clk);
+       hclk_msys = clk_get_rate(&clk_hclk_msys.clk);
+       hclk_dsys = clk_get_rate(&clk_hclk_dsys.clk);
+       hclk_psys = clk_get_rate(&clk_hclk_psys.clk);
+       pclk_msys = clk_get_rate(&clk_pclk_msys.clk);
+       pclk_dsys = clk_get_rate(&clk_pclk_dsys.clk);
+       pclk_psys = clk_get_rate(&clk_pclk_psys.clk);
+
+       printk(KERN_INFO "S5PV210: ARMCLK=%ld, HCLKM=%ld, HCLKD=%ld\n"
+                        "HCLKP=%ld, PCLKM=%ld, PCLKD=%ld, PCLKP=%ld\n",
+                       armclk, hclk_msys, hclk_dsys, hclk_psys,
+                       pclk_msys, pclk_dsys, pclk_psys);
 
-       for (ptr = 0; ptr < ARRAY_SIZE(init_parents); ptr++)
-               s3c_set_clksrc(init_parents[ptr], true);
+       clk_f.rate = armclk;
+       clk_h.rate = hclk_psys;
+       clk_p.rate = pclk_psys;
 
        for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
                s3c_set_clksrc(&clksrcs[ptr], true);
 }
 
 static struct clk *clks[] __initdata = {
-       &clk_mout_epll.clk,
-       &clk_mout_mpll.clk,
+       &clk_sclk_hdmi27m,
+       &clk_sclk_hdmiphy,
+       &clk_sclk_usbphy0,
+       &clk_sclk_usbphy1,
+       &clk_pcmcdclk0,
+       &clk_pcmcdclk1,
+       &clk_pcmcdclk2,
 };
 
 void __init s5pv210_register_clocks(void)
@@ -433,13 +1023,12 @@ void __init s5pv210_register_clocks(void)
        if (ret > 0)
                printk(KERN_ERR "Failed to register %u clocks\n", ret);
 
+       for (ptr = 0; ptr < ARRAY_SIZE(sysclks); ptr++)
+               s3c_register_clksrc(sysclks[ptr], 1);
+
        s3c_register_clksrc(clksrcs, ARRAY_SIZE(clksrcs));
        s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
 
-       ret = s3c24xx_register_clocks(sys_clks, ARRAY_SIZE(sys_clks));
-       if (ret > 0)
-               printk(KERN_ERR "Failed to register system clocks\n");
-
        clkp = init_clocks_disable;
        for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
                ret = s3c24xx_register_clock(clkp);
index 0e0f8fd..2b776eb 100644 (file)
@@ -100,7 +100,7 @@ void __init s5pv210_init_irq(void)
        s5p_init_irq(vic, ARRAY_SIZE(vic));
 }
 
-static struct sysdev_class s5pv210_sysclass = {
+struct sysdev_class s5pv210_sysclass = {
        .name   = "s5pv210-core",
 };
 
diff --git a/arch/arm/mach-s5pv210/dev-audio.c b/arch/arm/mach-s5pv210/dev-audio.c
new file mode 100644 (file)
index 0000000..6e21533
--- /dev/null
@@ -0,0 +1,327 @@
+/* linux/arch/arm/mach-s5pv210/dev-audio.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co. Ltd
+ *     Jaswinder Singh <jassi.brar@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/gpio-cfg.h>
+#include <plat/audio.h>
+
+#include <mach/gpio.h>
+#include <mach/map.h>
+#include <mach/dma.h>
+#include <mach/irqs.h>
+
+static int s5pv210_cfg_i2s(struct platform_device *pdev)
+{
+       /* configure GPIO for i2s port */
+       switch (pdev->id) {
+       case 1:
+               s3c_gpio_cfgpin(S5PV210_GPC0(0), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC0(1), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC0(2), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC0(3), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC0(4), S3C_GPIO_SFN(2));
+               break;
+
+       case 2:
+               s3c_gpio_cfgpin(S5PV210_GPC1(0), S3C_GPIO_SFN(4));
+               s3c_gpio_cfgpin(S5PV210_GPC1(1), S3C_GPIO_SFN(4));
+               s3c_gpio_cfgpin(S5PV210_GPC1(2), S3C_GPIO_SFN(4));
+               s3c_gpio_cfgpin(S5PV210_GPC1(3), S3C_GPIO_SFN(4));
+               s3c_gpio_cfgpin(S5PV210_GPC1(4), S3C_GPIO_SFN(4));
+               break;
+
+       case -1:
+               s3c_gpio_cfgpin(S5PV210_GPI(0), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(1), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(2), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(3), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(4), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(5), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPI(6), S3C_GPIO_SFN(2));
+               break;
+
+       default:
+               printk(KERN_ERR "Invalid Device %d\n", pdev->id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_i2s_pdata = {
+       .cfg_gpio = s5pv210_cfg_i2s,
+};
+
+static struct resource s5pv210_iis0_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_IIS0,
+               .end   = S5PV210_PA_IIS0 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S0_TX,
+               .end   = DMACH_I2S0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S0_RX,
+               .end   = DMACH_I2S0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_iis0 = {
+       .name             = "s3c64xx-iis-v4",
+       .id               = -1,
+       .num_resources    = ARRAY_SIZE(s5pv210_iis0_resource),
+       .resource         = s5pv210_iis0_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+static struct resource s5pv210_iis1_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_IIS1,
+               .end   = S5PV210_PA_IIS1 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S1_TX,
+               .end   = DMACH_I2S1_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S1_RX,
+               .end   = DMACH_I2S1_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_iis1 = {
+       .name             = "s3c64xx-iis",
+       .id               = 1,
+       .num_resources    = ARRAY_SIZE(s5pv210_iis1_resource),
+       .resource         = s5pv210_iis1_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+static struct resource s5pv210_iis2_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_IIS2,
+               .end   = S5PV210_PA_IIS2 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_I2S2_TX,
+               .end   = DMACH_I2S2_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_I2S2_RX,
+               .end   = DMACH_I2S2_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_iis2 = {
+       .name             = "s3c64xx-iis",
+       .id               = 2,
+       .num_resources    = ARRAY_SIZE(s5pv210_iis2_resource),
+       .resource         = s5pv210_iis2_resource,
+       .dev = {
+               .platform_data = &s3c_i2s_pdata,
+       },
+};
+
+/* PCM Controller platform_devices */
+
+static int s5pv210_pcm_cfg_gpio(struct platform_device *pdev)
+{
+       switch (pdev->id) {
+       case 0:
+               s3c_gpio_cfgpin(S5PV210_GPI(0), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPI(1), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPI(2), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPI(3), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPI(4), S3C_GPIO_SFN(3));
+               break;
+       case 1:
+               s3c_gpio_cfgpin(S5PV210_GPC0(0), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPC0(1), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPC0(2), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPC0(3), S3C_GPIO_SFN(3));
+               s3c_gpio_cfgpin(S5PV210_GPC0(4), S3C_GPIO_SFN(3));
+               break;
+       case 2:
+               s3c_gpio_cfgpin(S5PV210_GPC1(0), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC1(1), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC1(2), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC1(3), S3C_GPIO_SFN(2));
+               s3c_gpio_cfgpin(S5PV210_GPC1(4), S3C_GPIO_SFN(2));
+               break;
+       default:
+               printk(KERN_DEBUG "Invalid PCM Controller number!");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct s3c_audio_pdata s3c_pcm_pdata = {
+       .cfg_gpio = s5pv210_pcm_cfg_gpio,
+};
+
+static struct resource s5pv210_pcm0_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_PCM0,
+               .end   = S5PV210_PA_PCM0 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM0_TX,
+               .end   = DMACH_PCM0_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM0_RX,
+               .end   = DMACH_PCM0_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_pcm0 = {
+       .name             = "samsung-pcm",
+       .id               = 0,
+       .num_resources    = ARRAY_SIZE(s5pv210_pcm0_resource),
+       .resource         = s5pv210_pcm0_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
+
+static struct resource s5pv210_pcm1_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_PCM1,
+               .end   = S5PV210_PA_PCM1 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM1_TX,
+               .end   = DMACH_PCM1_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM1_RX,
+               .end   = DMACH_PCM1_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_pcm1 = {
+       .name             = "samsung-pcm",
+       .id               = 1,
+       .num_resources    = ARRAY_SIZE(s5pv210_pcm1_resource),
+       .resource         = s5pv210_pcm1_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
+
+static struct resource s5pv210_pcm2_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_PCM2,
+               .end   = S5PV210_PA_PCM2 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_PCM2_TX,
+               .end   = DMACH_PCM2_TX,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_PCM2_RX,
+               .end   = DMACH_PCM2_RX,
+               .flags = IORESOURCE_DMA,
+       },
+};
+
+struct platform_device s5pv210_device_pcm2 = {
+       .name             = "samsung-pcm",
+       .id               = 2,
+       .num_resources    = ARRAY_SIZE(s5pv210_pcm2_resource),
+       .resource         = s5pv210_pcm2_resource,
+       .dev = {
+               .platform_data = &s3c_pcm_pdata,
+       },
+};
+
+/* AC97 Controller platform devices */
+
+static int s5pv210_ac97_cfg_gpio(struct platform_device *pdev)
+{
+       s3c_gpio_cfgpin(S5PV210_GPC0(0), S3C_GPIO_SFN(4));
+       s3c_gpio_cfgpin(S5PV210_GPC0(1), S3C_GPIO_SFN(4));
+       s3c_gpio_cfgpin(S5PV210_GPC0(2), S3C_GPIO_SFN(4));
+       s3c_gpio_cfgpin(S5PV210_GPC0(3), S3C_GPIO_SFN(4));
+       s3c_gpio_cfgpin(S5PV210_GPC0(4), S3C_GPIO_SFN(4));
+
+       return 0;
+}
+
+static struct resource s5pv210_ac97_resource[] = {
+       [0] = {
+               .start = S5PV210_PA_AC97,
+               .end   = S5PV210_PA_AC97 + 0x100 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = DMACH_AC97_PCMOUT,
+               .end   = DMACH_AC97_PCMOUT,
+               .flags = IORESOURCE_DMA,
+       },
+       [2] = {
+               .start = DMACH_AC97_PCMIN,
+               .end   = DMACH_AC97_PCMIN,
+               .flags = IORESOURCE_DMA,
+       },
+       [3] = {
+               .start = DMACH_AC97_MICIN,
+               .end   = DMACH_AC97_MICIN,
+               .flags = IORESOURCE_DMA,
+       },
+       [4] = {
+               .start = IRQ_AC97,
+               .end   = IRQ_AC97,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct s3c_audio_pdata s3c_ac97_pdata = {
+       .cfg_gpio = s5pv210_ac97_cfg_gpio,
+};
+
+static u64 s5pv210_ac97_dmamask = DMA_BIT_MASK(32);
+
+struct platform_device s5pv210_device_ac97 = {
+       .name             = "s3c-ac97",
+       .id               = -1,
+       .num_resources    = ARRAY_SIZE(s5pv210_ac97_resource),
+       .resource         = s5pv210_ac97_resource,
+       .dev = {
+               .platform_data = &s3c_ac97_pdata,
+               .dma_mask = &s5pv210_ac97_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+       },
+};
diff --git a/arch/arm/mach-s5pv210/dma.c b/arch/arm/mach-s5pv210/dma.c
new file mode 100644 (file)
index 0000000..778ad5f
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+
+#include <plat/devs.h>
+#include <plat/irqs.h>
+
+#include <mach/map.h>
+#include <mach/irqs.h>
+
+#include <plat/s3c-pl330-pdata.h>
+
+static u64 dma_dmamask = DMA_BIT_MASK(32);
+
+static struct resource s5pv210_pdma0_resource[] = {
+       [0] = {
+               .start  = S5PV210_PA_PDMA0,
+               .end    = S5PV210_PA_PDMA0 + SZ_4K,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_PDMA0,
+               .end    = IRQ_PDMA0,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct s3c_pl330_platdata s5pv210_pdma0_pdata = {
+       .peri = {
+               [0] = DMACH_UART0_RX,
+               [1] = DMACH_UART0_TX,
+               [2] = DMACH_UART1_RX,
+               [3] = DMACH_UART1_TX,
+               [4] = DMACH_UART2_RX,
+               [5] = DMACH_UART2_TX,
+               [6] = DMACH_UART3_RX,
+               [7] = DMACH_UART3_TX,
+               [8] = DMACH_MAX,
+               [9] = DMACH_I2S0_RX,
+               [10] = DMACH_I2S0_TX,
+               [11] = DMACH_I2S0S_TX,
+               [12] = DMACH_I2S1_RX,
+               [13] = DMACH_I2S1_TX,
+               [14] = DMACH_MAX,
+               [15] = DMACH_MAX,
+               [16] = DMACH_SPI0_RX,
+               [17] = DMACH_SPI0_TX,
+               [18] = DMACH_SPI1_RX,
+               [19] = DMACH_SPI1_TX,
+               [20] = DMACH_MAX,
+               [21] = DMACH_MAX,
+               [22] = DMACH_AC97_MICIN,
+               [23] = DMACH_AC97_PCMIN,
+               [24] = DMACH_AC97_PCMOUT,
+               [25] = DMACH_MAX,
+               [26] = DMACH_PWM,
+               [27] = DMACH_SPDIF,
+               [28] = DMACH_MAX,
+               [29] = DMACH_MAX,
+               [30] = DMACH_MAX,
+               [31] = DMACH_MAX,
+       },
+};
+
+static struct platform_device s5pv210_device_pdma0 = {
+       .name           = "s3c-pl330",
+       .id             = 1,
+       .num_resources  = ARRAY_SIZE(s5pv210_pdma0_resource),
+       .resource       = s5pv210_pdma0_resource,
+       .dev            = {
+               .dma_mask = &dma_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+               .platform_data = &s5pv210_pdma0_pdata,
+       },
+};
+
+static struct resource s5pv210_pdma1_resource[] = {
+       [0] = {
+               .start  = S5PV210_PA_PDMA1,
+               .end    = S5PV210_PA_PDMA1 + SZ_4K,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_PDMA1,
+               .end    = IRQ_PDMA1,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct s3c_pl330_platdata s5pv210_pdma1_pdata = {
+       .peri = {
+               [0] = DMACH_UART0_RX,
+               [1] = DMACH_UART0_TX,
+               [2] = DMACH_UART1_RX,
+               [3] = DMACH_UART1_TX,
+               [4] = DMACH_UART2_RX,
+               [5] = DMACH_UART2_TX,
+               [6] = DMACH_UART3_RX,
+               [7] = DMACH_UART3_TX,
+               [8] = DMACH_MAX,
+               [9] = DMACH_I2S0_RX,
+               [10] = DMACH_I2S0_TX,
+               [11] = DMACH_I2S0S_TX,
+               [12] = DMACH_I2S1_RX,
+               [13] = DMACH_I2S1_TX,
+               [14] = DMACH_I2S2_RX,
+               [15] = DMACH_I2S2_TX,
+               [16] = DMACH_SPI0_RX,
+               [17] = DMACH_SPI0_TX,
+               [18] = DMACH_SPI1_RX,
+               [19] = DMACH_SPI1_TX,
+               [20] = DMACH_MAX,
+               [21] = DMACH_MAX,
+               [22] = DMACH_PCM0_RX,
+               [23] = DMACH_PCM0_TX,
+               [24] = DMACH_PCM1_RX,
+               [25] = DMACH_PCM1_TX,
+               [26] = DMACH_MSM_REQ0,
+               [27] = DMACH_MSM_REQ1,
+               [28] = DMACH_MSM_REQ2,
+               [29] = DMACH_MSM_REQ3,
+               [30] = DMACH_PCM2_RX,
+               [31] = DMACH_PCM2_TX,
+       },
+};
+
+static struct platform_device s5pv210_device_pdma1 = {
+       .name           = "s3c-pl330",
+       .id             = 2,
+       .num_resources  = ARRAY_SIZE(s5pv210_pdma1_resource),
+       .resource       = s5pv210_pdma1_resource,
+       .dev            = {
+               .dma_mask = &dma_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+               .platform_data = &s5pv210_pdma1_pdata,
+       },
+};
+
+static struct platform_device *s5pv210_dmacs[] __initdata = {
+       &s5pv210_device_pdma0,
+       &s5pv210_device_pdma1,
+};
+
+static int __init s5pv210_dma_init(void)
+{
+       platform_add_devices(s5pv210_dmacs, ARRAY_SIZE(s5pv210_dmacs));
+
+       return 0;
+}
+arch_initcall(s5pv210_dma_init);
diff --git a/arch/arm/mach-s5pv210/gpiolib.c b/arch/arm/mach-s5pv210/gpiolib.c
new file mode 100644 (file)
index 0000000..9ea8972
--- /dev/null
@@ -0,0 +1,261 @@
+/* linux/arch/arm/mach-s5pv210/gpiolib.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * S5PV210 - GPIOlib support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <plat/gpio-core.h>
+#include <plat/gpio-cfg.h>
+#include <plat/gpio-cfg-helpers.h>
+#include <mach/map.h>
+
+static struct s3c_gpio_cfg gpio_cfg = {
+       .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
+       .set_pull       = s3c_gpio_setpull_updown,
+       .get_pull       = s3c_gpio_getpull_updown,
+};
+
+static struct s3c_gpio_cfg gpio_cfg_noint = {
+       .set_config     = s3c_gpio_setcfg_s3c64xx_4bit,
+       .set_pull       = s3c_gpio_setpull_updown,
+       .get_pull       = s3c_gpio_getpull_updown,
+};
+
+/* GPIO bank's base address given the index of the bank in the
+ * list of all gpio banks.
+ */
+#define S5PV210_BANK_BASE(bank_nr)     (S5P_VA_GPIO + ((bank_nr) * 0x20))
+
+/*
+ * Following are the gpio banks in v210.
+ *
+ * The 'config' member when left to NULL, is initialized to the default
+ * structure gpio_cfg in the init function below.
+ *
+ * The 'base' member is also initialized in the init function below.
+ * Note: The initialization of 'base' member of s3c_gpio_chip structure
+ * uses the above macro and depends on the banks being listed in order here.
+ */
+static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {
+       {
+               .chip   = {
+                       .base   = S5PV210_GPA0(0),
+                       .ngpio  = S5PV210_GPIO_A0_NR,
+                       .label  = "GPA0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPA1(0),
+                       .ngpio  = S5PV210_GPIO_A1_NR,
+                       .label  = "GPA1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPB(0),
+                       .ngpio  = S5PV210_GPIO_B_NR,
+                       .label  = "GPB",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPC0(0),
+                       .ngpio  = S5PV210_GPIO_C0_NR,
+                       .label  = "GPC0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPC1(0),
+                       .ngpio  = S5PV210_GPIO_C1_NR,
+                       .label  = "GPC1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPD0(0),
+                       .ngpio  = S5PV210_GPIO_D0_NR,
+                       .label  = "GPD0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPD1(0),
+                       .ngpio  = S5PV210_GPIO_D1_NR,
+                       .label  = "GPD1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPE0(0),
+                       .ngpio  = S5PV210_GPIO_E0_NR,
+                       .label  = "GPE0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPE1(0),
+                       .ngpio  = S5PV210_GPIO_E1_NR,
+                       .label  = "GPE1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPF0(0),
+                       .ngpio  = S5PV210_GPIO_F0_NR,
+                       .label  = "GPF0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPF1(0),
+                       .ngpio  = S5PV210_GPIO_F1_NR,
+                       .label  = "GPF1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPF2(0),
+                       .ngpio  = S5PV210_GPIO_F2_NR,
+                       .label  = "GPF2",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPF3(0),
+                       .ngpio  = S5PV210_GPIO_F3_NR,
+                       .label  = "GPF3",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPG0(0),
+                       .ngpio  = S5PV210_GPIO_G0_NR,
+                       .label  = "GPG0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPG1(0),
+                       .ngpio  = S5PV210_GPIO_G1_NR,
+                       .label  = "GPG1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPG2(0),
+                       .ngpio  = S5PV210_GPIO_G2_NR,
+                       .label  = "GPG2",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPG3(0),
+                       .ngpio  = S5PV210_GPIO_G3_NR,
+                       .label  = "GPG3",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPI(0),
+                       .ngpio  = S5PV210_GPIO_I_NR,
+                       .label  = "GPI",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPJ0(0),
+                       .ngpio  = S5PV210_GPIO_J0_NR,
+                       .label  = "GPJ0",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPJ1(0),
+                       .ngpio  = S5PV210_GPIO_J1_NR,
+                       .label  = "GPJ1",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPJ2(0),
+                       .ngpio  = S5PV210_GPIO_J2_NR,
+                       .label  = "GPJ2",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPJ3(0),
+                       .ngpio  = S5PV210_GPIO_J3_NR,
+                       .label  = "GPJ3",
+               },
+       }, {
+               .chip   = {
+                       .base   = S5PV210_GPJ4(0),
+                       .ngpio  = S5PV210_GPIO_J4_NR,
+                       .label  = "GPJ4",
+               },
+       }, {
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_MP01(0),
+                       .ngpio  = S5PV210_GPIO_MP01_NR,
+                       .label  = "MP01",
+               },
+       }, {
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_MP02(0),
+                       .ngpio  = S5PV210_GPIO_MP02_NR,
+                       .label  = "MP02",
+               },
+       }, {
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_MP03(0),
+                       .ngpio  = S5PV210_GPIO_MP03_NR,
+                       .label  = "MP03",
+               },
+       }, {
+               .base   = (S5P_VA_GPIO + 0xC00),
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_GPH0(0),
+                       .ngpio  = S5PV210_GPIO_H0_NR,
+                       .label  = "GPH0",
+               },
+       }, {
+               .base   = (S5P_VA_GPIO + 0xC20),
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_GPH1(0),
+                       .ngpio  = S5PV210_GPIO_H1_NR,
+                       .label  = "GPH1",
+               },
+       }, {
+               .base   = (S5P_VA_GPIO + 0xC40),
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_GPH2(0),
+                       .ngpio  = S5PV210_GPIO_H2_NR,
+                       .label  = "GPH2",
+               },
+       }, {
+               .base   = (S5P_VA_GPIO + 0xC60),
+               .config = &gpio_cfg_noint,
+               .chip   = {
+                       .base   = S5PV210_GPH3(0),
+                       .ngpio  = S5PV210_GPIO_H3_NR,
+                       .label  = "GPH3",
+               },
+       },
+};
+
+static __init int s5pv210_gpiolib_init(void)
+{
+       struct s3c_gpio_chip *chip = s5pv210_gpio_4bit;
+       int nr_chips = ARRAY_SIZE(s5pv210_gpio_4bit);
+       int i = 0;
+
+       for (i = 0; i < nr_chips; i++, chip++) {
+               if (chip->config == NULL)
+                       chip->config = &gpio_cfg;
+               if (chip->base == NULL)
+                       chip->base = S5PV210_BANK_BASE(i);
+       }
+
+       samsung_gpiolib_add_4bit_chips(s5pv210_gpio_4bit, nr_chips);
+
+       return 0;
+}
+core_initcall(s5pv210_gpiolib_init);
diff --git a/arch/arm/mach-s5pv210/include/mach/dma.h b/arch/arm/mach-s5pv210/include/mach/dma.h
new file mode 100644 (file)
index 0000000..81209eb
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MACH_DMA_H
+#define __MACH_DMA_H
+
+/* This platform uses the common S3C DMA API driver for PL330 */
+#include <plat/s3c-dma-pl330.h>
+
+#endif /* __MACH_DMA_H */
index 533b020..d6461ba 100644 (file)
@@ -18,6 +18,8 @@
 #define gpio_cansleep  __gpio_cansleep
 #define gpio_to_irq    __gpio_to_irq
 
+/* Practically, GPIO banks upto MP03 are the configurable gpio banks */
+
 /* GPIO bank sizes */
 #define S5PV210_GPIO_A0_NR     (8)
 #define S5PV210_GPIO_A1_NR     (4)
 #define S5PV210_GPIO_J3_NR     (8)
 #define S5PV210_GPIO_J4_NR     (5)
 
+#define S5PV210_GPIO_MP01_NR   (8)
+#define S5PV210_GPIO_MP02_NR   (4)
+#define S5PV210_GPIO_MP03_NR   (8)
+
 /* GPIO bank numbers */
 
 /* CONFIG_S3C_GPIO_SPACE allows the user to select extra
@@ -85,6 +91,9 @@ enum s5p_gpio_number {
        S5PV210_GPIO_J2_START   = S5PV210_GPIO_NEXT(S5PV210_GPIO_J1),
        S5PV210_GPIO_J3_START   = S5PV210_GPIO_NEXT(S5PV210_GPIO_J2),
        S5PV210_GPIO_J4_START   = S5PV210_GPIO_NEXT(S5PV210_GPIO_J3),
+       S5PV210_GPIO_MP01_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_J4),
+       S5PV210_GPIO_MP02_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP01),
+       S5PV210_GPIO_MP03_START = S5PV210_GPIO_NEXT(S5PV210_GPIO_MP02),
 };
 
 /* S5PV210 GPIO number definitions */
@@ -115,13 +124,16 @@ enum s5p_gpio_number {
 #define S5PV210_GPJ2(_nr)      (S5PV210_GPIO_J2_START + (_nr))
 #define S5PV210_GPJ3(_nr)      (S5PV210_GPIO_J3_START + (_nr))
 #define S5PV210_GPJ4(_nr)      (S5PV210_GPIO_J4_START + (_nr))
+#define S5PV210_MP01(_nr)      (S5PV210_GPIO_MP01_START + (_nr))
+#define S5PV210_MP02(_nr)      (S5PV210_GPIO_MP02_START + (_nr))
+#define S5PV210_MP03(_nr)      (S5PV210_GPIO_MP03_START + (_nr))
 
 /* the end of the S5PV210 specific gpios */
-#define S5PV210_GPIO_END       (S5PV210_GPJ4(S5PV210_GPIO_J4_NR) + 1)
+#define S5PV210_GPIO_END       (S5PV210_MP03(S5PV210_GPIO_MP03_NR) + 1)
 #define S3C_GPIO_END           S5PV210_GPIO_END
 
-/* define the number of gpios we need to the one after the GPJ4() range */
-#define ARCH_NR_GPIOS          (S5PV210_GPJ4(S5PV210_GPIO_J4_NR) +     \
+/* define the number of gpios we need to the one after the MP03() range */
+#define ARCH_NR_GPIOS          (S5PV210_MP03(S5PV210_GPIO_MP03_NR) +   \
                                 CONFIG_SAMSUNG_GPIO_EXTRA + 1)
 
 #include <asm-generic/gpio.h>
index c22694c..5adcb9f 100644 (file)
 
 #define S5PV210_PA_SROMC       (0xE8000000)
 
+#define S5PV210_PA_MDMA                0xFA200000
+#define S5PV210_PA_PDMA0       0xE0900000
+#define S5PV210_PA_PDMA1       0xE0A00000
+
 #define S5PV210_PA_VIC0                (0xF2000000)
 #define S5P_PA_VIC0            S5PV210_PA_VIC0
 
 #define S5PV210_PA_SDRAM       (0x20000000)
 #define S5P_PA_SDRAM           S5PV210_PA_SDRAM
 
+/* I2S */
+#define S5PV210_PA_IIS0                0xEEE30000
+#define S5PV210_PA_IIS1                0xE2100000
+#define S5PV210_PA_IIS2                0xE2A00000
+
+/* PCM */
+#define S5PV210_PA_PCM0                0xE2300000
+#define S5PV210_PA_PCM1                0xE1200000
+#define S5PV210_PA_PCM2                0xE2B00000
+
+/* AC97 */
+#define S5PV210_PA_AC97                0xE2200000
+
 /* compatibiltiy defines. */
 #define S3C_PA_UART            S5PV210_PA_UART
 #define S3C_PA_IIC             S5PV210_PA_IIC0
index 69027fe..f8a9f1b 100644 (file)
@@ -1,13 +1,14 @@
 /* linux/arch/arm/mach-s5pv210/include/mach/pwm-clock.h
  *
+ * Copyright (c) 2009 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * Copyright 2008 Openmoko, Inc.
  * Copyright 2008 Simtec Electronics
  *      Ben Dooks <ben@simtec.co.uk>
  *      http://armlinux.simtec.co.uk/
  *
- * Copyright (c) 2009 Samsung Electronics Co., Ltd.
- *             http://www.samsung.com/
- *
- * Based on arch/arm/plat-s3c24xx/include/mach/pwm-clock.h
+ * Based on arch/arm/mach-s3c64xx/include/mach/pwm-clock.h
  *
  * S5PV210 - pwm clock and timer support
  *
 
 /**
  * pwm_cfg_src_is_tclk() - return whether the given mux config is a tclk
- * @cfg: The timer TCFG1 register bits shifted down to 0.
+ * @tcfg: The timer TCFG1 register bits shifted down to 0.
  *
  * Return true if the given configuration from TCFG1 is a TCLK instead
  * any of the TDIV clocks.
  */
 static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
 {
-       return tcfg == S3C2410_TCFG1_MUX_TCLK;
+       return tcfg == S3C64XX_TCFG1_MUX_TCLK;
 }
 
 /**
@@ -40,7 +41,7 @@ static inline int pwm_cfg_src_is_tclk(unsigned long tcfg)
  */
 static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
 {
-       return 1 << (1 + tcfg1);
+       return 1 << tcfg1;
 }
 
 /**
@@ -50,7 +51,7 @@ static inline unsigned long tcfg_to_divisor(unsigned long tcfg1)
  */
 static inline unsigned int pwm_tdiv_has_div1(void)
 {
-       return 0;
+       return 1;
 }
 
 /**
@@ -61,9 +62,9 @@ static inline unsigned int pwm_tdiv_has_div1(void)
  */
 static inline unsigned long pwm_tdiv_div_bits(unsigned int div)
 {
-       return ilog2(div) - 1;
+       return ilog2(div);
 }
 
-#define S3C_TCFG1_MUX_TCLK S3C2410_TCFG1_MUX_TCLK
+#define S3C_TCFG1_MUX_TCLK S3C64XX_TCFG1_MUX_TCLK
 
 #endif /* __ASM_ARCH_PWMCLK_H */
index ab4869d..6f9fd32 100644 (file)
@@ -72,6 +72,8 @@ static struct s3c2410_uartcfg smdkv210_uartcfgs[] __initdata = {
 };
 
 static struct platform_device *smdkc110_devices[] __initdata = {
+       &s5pv210_device_iis0,
+       &s5pv210_device_ac97,
 };
 
 static void __init smdkc110_map_io(void)
index a278832..3c29e18 100644 (file)
@@ -72,6 +72,8 @@ static struct s3c2410_uartcfg smdkv210_uartcfgs[] __initdata = {
 };
 
 static struct platform_device *smdkv210_devices[] __initdata = {
+       &s5pv210_device_iis0,
+       &s5pv210_device_ac97,
 };
 
 static void __init smdkv210_map_io(void)
diff --git a/arch/arm/mach-s5pv210/setup-i2c0.c b/arch/arm/mach-s5pv210/setup-i2c0.c
new file mode 100644 (file)
index 0000000..9ec6845
--- /dev/null
@@ -0,0 +1,25 @@
+/* linux/arch/arm/mach-s5pv210/setup-i2c0.c
+ *
+ * Copyright (c) 2009 Samsung Electronics Co., Ltd.
+ *             http://www.samsung.com/
+ *
+ * I2C0 GPIO configuration.
+ *
+ * Based on plat-s3c64xx/setup-i2c0.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+
+struct platform_device; /* don't need the contents */
+
+#include <plat/iic.h>
+
+void s3c_i2c0_cfg_gpio(struct platform_device *dev)
+{
+       /* Will be populated later */
+}
index aeceb9b..f2b88c5 100644 (file)
@@ -7,7 +7,6 @@ config ARCH_SH7367
        select CPU_V6
        select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
 
 config ARCH_SH7377
@@ -15,7 +14,6 @@ config ARCH_SH7377
        select CPU_V7
        select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
 
 config ARCH_SH7372
@@ -23,7 +21,6 @@ config ARCH_SH7372
        select CPU_V7
        select HAVE_CLK
        select COMMON_CLKDEV
-       select GENERIC_TIME
        select GENERIC_CLOCKEVENTS
 
 comment "SH-Mobile Board Type"
diff --git a/arch/arm/mach-spear3xx/Kconfig b/arch/arm/mach-spear3xx/Kconfig
new file mode 100644 (file)
index 0000000..20d1317
--- /dev/null
@@ -0,0 +1,33 @@
+#
+# SPEAr3XX Machine configuration file
+#
+
+if ARCH_SPEAR3XX
+
+choice
+       prompt "SPEAr3XX Family"
+       default MACH_SPEAR300
+
+config MACH_SPEAR300
+       bool "SPEAr300"
+       help
+         Supports ST SPEAr300 Machine
+
+config MACH_SPEAR310
+       bool "SPEAr310"
+       help
+         Supports ST SPEAr310 Machine
+
+config MACH_SPEAR320
+       bool "SPEAr320"
+       help
+         Supports ST SPEAr320 Machine
+
+endchoice
+
+# Adding SPEAr3XX machine specific configuration files
+source "arch/arm/mach-spear3xx/Kconfig300"
+source "arch/arm/mach-spear3xx/Kconfig310"
+source "arch/arm/mach-spear3xx/Kconfig320"
+
+endif #ARCH_SPEAR3XX
diff --git a/arch/arm/mach-spear3xx/Kconfig300 b/arch/arm/mach-spear3xx/Kconfig300
new file mode 100644 (file)
index 0000000..c519a05
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# SPEAr300 machine configuration file
+#
+
+if MACH_SPEAR300
+
+choice
+       prompt "SPEAr300 Boards"
+       default BOARD_SPEAR300_EVB
+
+config BOARD_SPEAR300_EVB
+       bool "SPEAr300 Evaluation Board"
+       help
+         Supports ST SPEAr300 Evaluation Board
+endchoice
+
+endif  #MACH_SPEAR300
diff --git a/arch/arm/mach-spear3xx/Kconfig310 b/arch/arm/mach-spear3xx/Kconfig310
new file mode 100644 (file)
index 0000000..60e7442
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# SPEAr310 machine configuration file
+#
+
+if MACH_SPEAR310
+
+choice
+       prompt "SPEAr310 Boards"
+       default BOARD_SPEAR310_EVB
+
+config BOARD_SPEAR310_EVB
+       bool "SPEAr310 Evaluation Board"
+       help
+         Supports ST SPEAr310 Evaluation Board
+endchoice
+
+endif  #MACH_SPEAR310
diff --git a/arch/arm/mach-spear3xx/Kconfig320 b/arch/arm/mach-spear3xx/Kconfig320
new file mode 100644 (file)
index 0000000..1c1d438
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# SPEAr320 machine configuration file
+#
+
+if MACH_SPEAR320
+
+choice
+       prompt "SPEAr320 Boards"
+       default BOARD_SPEAR320_EVB
+
+config BOARD_SPEAR320_EVB
+       bool "SPEAr320 Evaluation Board"
+       help
+         Supports ST SPEAr320 Evaluation Board
+endchoice
+
+endif  #MACH_SPEAR320
diff --git a/arch/arm/mach-spear3xx/Makefile b/arch/arm/mach-spear3xx/Makefile
new file mode 100644 (file)
index 0000000..b248624
--- /dev/null
@@ -0,0 +1,26 @@
+#
+# Makefile for SPEAr3XX machine series
+#
+
+# common files
+obj-y  += spear3xx.o clock.o
+
+# spear300 specific files
+obj-$(CONFIG_MACH_SPEAR300) += spear300.o
+
+# spear300 boards files
+obj-$(CONFIG_BOARD_SPEAR300_EVB) += spear300_evb.o
+
+
+# spear310 specific files
+obj-$(CONFIG_MACH_SPEAR310) += spear310.o
+
+# spear310 boards files
+obj-$(CONFIG_BOARD_SPEAR310_EVB) += spear310_evb.o
+
+
+# spear320 specific files
+obj-$(CONFIG_MACH_SPEAR320) += spear320.o
+
+# spear320 boards files
+obj-$(CONFIG_BOARD_SPEAR320_EVB) += spear320_evb.o
diff --git a/arch/arm/mach-spear3xx/Makefile.boot b/arch/arm/mach-spear3xx/Makefile.boot
new file mode 100644 (file)
index 0000000..7a1f3c0
--- /dev/null
@@ -0,0 +1,3 @@
+zreladdr-y     := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00800000
diff --git a/arch/arm/mach-spear3xx/clock.c b/arch/arm/mach-spear3xx/clock.c
new file mode 100644 (file)
index 0000000..39f6ccf
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * arch/arm/mach-spear3xx/clock.c
+ *
+ * SPEAr3xx machines clock framework source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <mach/misc_regs.h>
+#include <plat/clock.h>
+
+/* root clks */
+/* 32 KHz oscillator clock */
+static struct clk osc_32k_clk = {
+       .flags = ALWAYS_ENABLED,
+       .rate = 32000,
+};
+
+/* 24 MHz oscillator clock */
+static struct clk osc_24m_clk = {
+       .flags = ALWAYS_ENABLED,
+       .rate = 24000000,
+};
+
+/* clock derived from 32 KHz osc clk */
+/* rtc clock */
+static struct clk rtc_clk = {
+       .pclk = &osc_32k_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = RTC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from 24 MHz osc clk */
+/* pll1 configuration structure */
+static struct pll_clk_config pll1_config = {
+       .mode_reg = PLL1_CTR,
+       .cfg_reg = PLL1_FRQ,
+};
+
+/* PLL1 clock */
+static struct clk pll1_clk = {
+       .pclk = &osc_24m_clk,
+       .en_reg = PLL1_CTR,
+       .en_reg_bit = PLL_ENABLE,
+       .recalc = &pll1_clk_recalc,
+       .private_data = &pll1_config,
+};
+
+/* PLL3 48 MHz clock */
+static struct clk pll3_48m_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &osc_24m_clk,
+       .rate = 48000000,
+};
+
+/* watch dog timer clock */
+static struct clk wdt_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &osc_24m_clk,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from pll1 clk */
+/* cpu clock */
+static struct clk cpu_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &pll1_clk,
+       .recalc = &follow_parent,
+};
+
+/* ahb configuration structure */
+static struct bus_clk_config ahb_config = {
+       .reg = CORE_CLK_CFG,
+       .mask = PLL_HCLK_RATIO_MASK,
+       .shift = PLL_HCLK_RATIO_SHIFT,
+};
+
+/* ahb clock */
+static struct clk ahb_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &pll1_clk,
+       .recalc = &bus_clk_recalc,
+       .private_data = &ahb_config,
+};
+
+/* uart configurations */
+static struct aux_clk_config uart_config = {
+       .synth_reg = UART_CLK_SYNT,
+};
+
+/* uart parents */
+static struct pclk_info uart_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* uart parent select structure */
+static struct pclk_sel uart_pclk_sel = {
+       .pclk_info = uart_pclk_info,
+       .pclk_count = ARRAY_SIZE(uart_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = UART_CLK_MASK,
+};
+
+/* uart clock */
+static struct clk uart_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = UART_CLK_ENB,
+       .pclk_sel = &uart_pclk_sel,
+       .pclk_sel_shift = UART_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &uart_config,
+};
+
+/* firda configurations */
+static struct aux_clk_config firda_config = {
+       .synth_reg = FIRDA_CLK_SYNT,
+};
+
+/* firda parents */
+static struct pclk_info firda_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* firda parent select structure */
+static struct pclk_sel firda_pclk_sel = {
+       .pclk_info = firda_pclk_info,
+       .pclk_count = ARRAY_SIZE(firda_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = FIRDA_CLK_MASK,
+};
+
+/* firda clock */
+static struct clk firda_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = FIRDA_CLK_ENB,
+       .pclk_sel = &firda_pclk_sel,
+       .pclk_sel_shift = FIRDA_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &firda_config,
+};
+
+/* gpt parents */
+static struct pclk_info gpt_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* gpt parent select structure */
+static struct pclk_sel gpt_pclk_sel = {
+       .pclk_info = gpt_pclk_info,
+       .pclk_count = ARRAY_SIZE(gpt_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = GPT_CLK_MASK,
+};
+
+/* gpt0 configurations */
+static struct aux_clk_config gpt0_config = {
+       .synth_reg = PRSC1_CLK_CFG,
+};
+
+/* gpt0 timer clock */
+static struct clk gpt0_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT0_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt0_config,
+};
+
+/* gpt1 configurations */
+static struct aux_clk_config gpt1_config = {
+       .synth_reg = PRSC2_CLK_CFG,
+};
+
+/* gpt1 timer clock */
+static struct clk gpt1_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPT1_CLK_ENB,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT1_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt1_config,
+};
+
+/* gpt2 configurations */
+static struct aux_clk_config gpt2_config = {
+       .synth_reg = PRSC3_CLK_CFG,
+};
+
+/* gpt2 timer clock */
+static struct clk gpt2_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPT2_CLK_ENB,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT2_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt2_config,
+};
+
+/* clock derived from pll3 clk */
+/* usbh clock */
+static struct clk usbh_clk = {
+       .pclk = &pll3_48m_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = USBH_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* usbd clock */
+static struct clk usbd_clk = {
+       .pclk = &pll3_48m_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = USBD_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clcd clock */
+static struct clk clcd_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &pll3_48m_clk,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from ahb clk */
+/* apb configuration structure */
+static struct bus_clk_config apb_config = {
+       .reg = CORE_CLK_CFG,
+       .mask = HCLK_PCLK_RATIO_MASK,
+       .shift = HCLK_PCLK_RATIO_SHIFT,
+};
+
+/* apb clock */
+static struct clk apb_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &ahb_clk,
+       .recalc = &bus_clk_recalc,
+       .private_data = &apb_config,
+};
+
+/* i2c clock */
+static struct clk i2c_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = I2C_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* dma clock */
+static struct clk dma_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = DMA_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* jpeg clock */
+static struct clk jpeg_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = JPEG_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* gmac clock */
+static struct clk gmac_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GMAC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* smi clock */
+static struct clk smi_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SMI_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* c3 clock */
+static struct clk c3_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = C3_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from apb clk */
+/* adc clock */
+static struct clk adc_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = ADC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* ssp clock */
+static struct clk ssp_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SSP_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* gpio clock */
+static struct clk gpio_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPIO_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* array of all spear 3xx clock lookups */
+static struct clk_lookup spear_clk_lookups[] = {
+       /* root clks */
+       { .con_id = "osc_32k_clk",      .clk = &osc_32k_clk},
+       { .con_id = "osc_24m_clk",      .clk = &osc_24m_clk},
+       /* clock derived from 32 KHz osc clk */
+       { .dev_id = "rtc",              .clk = &rtc_clk},
+       /* clock derived from 24 MHz osc clk */
+       { .con_id = "pll1_clk",         .clk = &pll1_clk},
+       { .con_id = "pll3_48m_clk",     .clk = &pll3_48m_clk},
+       { .dev_id = "wdt",              .clk = &wdt_clk},
+       /* clock derived from pll1 clk */
+       { .con_id = "cpu_clk",          .clk = &cpu_clk},
+       { .con_id = "ahb_clk",          .clk = &ahb_clk},
+       { .dev_id = "uart",             .clk = &uart_clk},
+       { .dev_id = "firda",            .clk = &firda_clk},
+       { .dev_id = "gpt0",             .clk = &gpt0_clk},
+       { .dev_id = "gpt1",             .clk = &gpt1_clk},
+       { .dev_id = "gpt2",             .clk = &gpt2_clk},
+       /* clock derived from pll3 clk */
+       { .dev_id = "usbh",             .clk = &usbh_clk},
+       { .dev_id = "usbd",             .clk = &usbd_clk},
+       { .dev_id = "clcd",             .clk = &clcd_clk},
+       /* clock derived from ahb clk */
+       { .con_id = "apb_clk",          .clk = &apb_clk},
+       { .dev_id = "i2c",              .clk = &i2c_clk},
+       { .dev_id = "dma",              .clk = &dma_clk},
+       { .dev_id = "jpeg",             .clk = &jpeg_clk},
+       { .dev_id = "gmac",             .clk = &gmac_clk},
+       { .dev_id = "smi",              .clk = &smi_clk},
+       { .dev_id = "c3",               .clk = &c3_clk},
+       /* clock derived from apb clk */
+       { .dev_id = "adc",              .clk = &adc_clk},
+       { .dev_id = "ssp",              .clk = &ssp_clk},
+       { .dev_id = "gpio",             .clk = &gpio_clk},
+};
+
+void __init clk_init(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(spear_clk_lookups); i++)
+               clk_register(&spear_clk_lookups[i]);
+
+       recalc_root_clocks();
+}
diff --git a/arch/arm/mach-spear3xx/include/mach/clkdev.h b/arch/arm/mach-spear3xx/include/mach/clkdev.h
new file mode 100644 (file)
index 0000000..a3d0733
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/clkdev.h
+ *
+ * Clock Dev framework definitions for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_CLKDEV_H
+#define __MACH_CLKDEV_H
+
+#include <plat/clkdev.h>
+
+#endif /* __MACH_CLKDEV_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/debug-macro.S b/arch/arm/mach-spear3xx/include/mach/debug-macro.S
new file mode 100644 (file)
index 0000000..590519f
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/debug-macro.S
+ *
+ * Debugging macro include header spear3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <plat/debug-macro.S>
diff --git a/arch/arm/mach-spear3xx/include/mach/entry-macro.S b/arch/arm/mach-spear3xx/include/mach/entry-macro.S
new file mode 100644 (file)
index 0000000..947625d
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/entry-macro.S
+ *
+ * Low-level IRQ helper macros for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <mach/hardware.h>
+#include <mach/spear.h>
+#include <asm/hardware/vic.h>
+
+               .macro  disable_fiq
+               .endm
+
+               .macro  get_irqnr_preamble, base, tmp
+               .endm
+
+               .macro  arch_ret_to_user, tmp1, tmp2
+               .endm
+
+               .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+               ldr     \base, =VA_SPEAR3XX_ML1_VIC_BASE
+               ldr     \irqstat, [\base, #VIC_IRQ_STATUS]      @ get status
+               teq     \irqstat, #0
+               beq     1001f                           @ this will set/reset
+                                                       @ zero register
+               /*
+                * Following code will find bit position of least significang
+                * bit set in irqstat, using following equation
+                * least significant bit set in n = (n & ~(n-1))
+                */
+               sub     \tmp, \irqstat, #1              @ tmp = irqstat - 1
+               mvn     \tmp, \tmp                      @ tmp = ~tmp
+               and     \irqstat, \irqstat, \tmp        @ irqstat &= tmp
+               /* Now, irqstat is = bit no. of 1st bit set in vic irq status */
+               clz     \tmp, \irqstat                  @ tmp = leading zeros
+               rsb     \irqnr, \tmp, #0x1F             @ irqnr = 32 - tmp - 1
+
+1001:          /* EQ will be set if no irqs pending */
+               .endm
diff --git a/arch/arm/mach-spear3xx/include/mach/generic.h b/arch/arm/mach-spear3xx/include/mach/generic.h
new file mode 100644 (file)
index 0000000..af7e02c
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * arch/arm/mach-spear3xx/generic.h
+ *
+ * SPEAr3XX machine family generic header file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_GENERIC_H
+#define __MACH_GENERIC_H
+
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+#include <plat/padmux.h>
+
+/* spear3xx declarations */
+/*
+ * Each GPT has 2 timer channels
+ * Following GPT channels will be used as clock source and clockevent
+ */
+#define SPEAR_GPT0_BASE                SPEAR3XX_ML1_TMR_BASE
+#define SPEAR_GPT0_CHAN0_IRQ   IRQ_CPU_GPT1_1
+#define SPEAR_GPT0_CHAN1_IRQ   IRQ_CPU_GPT1_2
+
+/* Add spear3xx family device structure declarations here */
+extern struct amba_device gpio_device;
+extern struct amba_device uart_device;
+extern struct sys_timer spear_sys_timer;
+
+/* Add spear3xx family function declarations here */
+void __init clk_init(void);
+void __init spear3xx_map_io(void);
+void __init spear3xx_init_irq(void);
+void __init spear3xx_init(void);
+void spear_pmx_init(struct pmx_driver *pmx_driver, uint base, uint size);
+
+/* pad mux declarations */
+#define PMX_FIRDA_MASK         (1 << 14)
+#define PMX_I2C_MASK           (1 << 13)
+#define PMX_SSP_CS_MASK                (1 << 12)
+#define PMX_SSP_MASK           (1 << 11)
+#define PMX_MII_MASK           (1 << 10)
+#define PMX_GPIO_PIN0_MASK     (1 << 9)
+#define PMX_GPIO_PIN1_MASK     (1 << 8)
+#define PMX_GPIO_PIN2_MASK     (1 << 7)
+#define PMX_GPIO_PIN3_MASK     (1 << 6)
+#define PMX_GPIO_PIN4_MASK     (1 << 5)
+#define PMX_GPIO_PIN5_MASK     (1 << 4)
+#define PMX_UART0_MODEM_MASK   (1 << 3)
+#define PMX_UART0_MASK         (1 << 2)
+#define PMX_TIMER_3_4_MASK     (1 << 1)
+#define PMX_TIMER_1_2_MASK     (1 << 0)
+
+/* pad mux devices */
+extern struct pmx_dev pmx_firda;
+extern struct pmx_dev pmx_i2c;
+extern struct pmx_dev pmx_ssp_cs;
+extern struct pmx_dev pmx_ssp;
+extern struct pmx_dev pmx_mii;
+extern struct pmx_dev pmx_gpio_pin0;
+extern struct pmx_dev pmx_gpio_pin1;
+extern struct pmx_dev pmx_gpio_pin2;
+extern struct pmx_dev pmx_gpio_pin3;
+extern struct pmx_dev pmx_gpio_pin4;
+extern struct pmx_dev pmx_gpio_pin5;
+extern struct pmx_dev pmx_uart0_modem;
+extern struct pmx_dev pmx_uart0;
+extern struct pmx_dev pmx_timer_3_4;
+extern struct pmx_dev pmx_timer_1_2;
+
+#if defined(CONFIG_MACH_SPEAR310) || defined(CONFIG_MACH_SPEAR320)
+/* padmux plgpio devices */
+extern struct pmx_dev pmx_plgpio_0_1;
+extern struct pmx_dev pmx_plgpio_2_3;
+extern struct pmx_dev pmx_plgpio_4_5;
+extern struct pmx_dev pmx_plgpio_6_9;
+extern struct pmx_dev pmx_plgpio_10_27;
+extern struct pmx_dev pmx_plgpio_28;
+extern struct pmx_dev pmx_plgpio_29;
+extern struct pmx_dev pmx_plgpio_30;
+extern struct pmx_dev pmx_plgpio_31;
+extern struct pmx_dev pmx_plgpio_32;
+extern struct pmx_dev pmx_plgpio_33;
+extern struct pmx_dev pmx_plgpio_34_36;
+extern struct pmx_dev pmx_plgpio_37_42;
+extern struct pmx_dev pmx_plgpio_43_44_47_48;
+extern struct pmx_dev pmx_plgpio_45_46_49_50;
+#endif
+
+extern struct pmx_driver pmx_driver;
+
+/* spear300 declarations */
+#ifdef CONFIG_MACH_SPEAR300
+/* Add spear300 machine device structure declarations here */
+extern struct amba_device gpio1_device;
+
+/* pad mux modes */
+extern struct pmx_mode nand_mode;
+extern struct pmx_mode nor_mode;
+extern struct pmx_mode photo_frame_mode;
+extern struct pmx_mode lend_ip_phone_mode;
+extern struct pmx_mode hend_ip_phone_mode;
+extern struct pmx_mode lend_wifi_phone_mode;
+extern struct pmx_mode hend_wifi_phone_mode;
+extern struct pmx_mode ata_pabx_wi2s_mode;
+extern struct pmx_mode ata_pabx_i2s_mode;
+extern struct pmx_mode caml_lcdw_mode;
+extern struct pmx_mode camu_lcd_mode;
+extern struct pmx_mode camu_wlcd_mode;
+extern struct pmx_mode caml_lcd_mode;
+
+/* pad mux devices */
+extern struct pmx_dev pmx_fsmc_2_chips;
+extern struct pmx_dev pmx_fsmc_4_chips;
+extern struct pmx_dev pmx_keyboard;
+extern struct pmx_dev pmx_clcd;
+extern struct pmx_dev pmx_telecom_gpio;
+extern struct pmx_dev pmx_telecom_tdm;
+extern struct pmx_dev pmx_telecom_spi_cs_i2c_clk;
+extern struct pmx_dev pmx_telecom_camera;
+extern struct pmx_dev pmx_telecom_dac;
+extern struct pmx_dev pmx_telecom_i2s;
+extern struct pmx_dev pmx_telecom_boot_pins;
+extern struct pmx_dev pmx_telecom_sdio_4bit;
+extern struct pmx_dev pmx_telecom_sdio_8bit;
+extern struct pmx_dev pmx_gpio1;
+
+void spear300_pmx_init(void);
+
+/* Add spear300 machine function declarations here */
+void __init spear300_init(void);
+
+#endif /* CONFIG_MACH_SPEAR300 */
+
+/* spear310 declarations */
+#ifdef CONFIG_MACH_SPEAR310
+/* Add spear310 machine device structure declarations here */
+
+/* pad mux devices */
+extern struct pmx_dev pmx_emi_cs_0_1_4_5;
+extern struct pmx_dev pmx_emi_cs_2_3;
+extern struct pmx_dev pmx_uart1;
+extern struct pmx_dev pmx_uart2;
+extern struct pmx_dev pmx_uart3_4_5;
+extern struct pmx_dev pmx_fsmc;
+extern struct pmx_dev pmx_rs485_0_1;
+extern struct pmx_dev pmx_tdm0;
+
+void spear310_pmx_init(void);
+
+/* Add spear310 machine function declarations here */
+void __init spear310_init(void);
+
+#endif /* CONFIG_MACH_SPEAR310 */
+
+/* spear320 declarations */
+#ifdef CONFIG_MACH_SPEAR320
+/* Add spear320 machine device structure declarations here */
+
+/* pad mux modes */
+extern struct pmx_mode auto_net_smii_mode;
+extern struct pmx_mode auto_net_mii_mode;
+extern struct pmx_mode auto_exp_mode;
+extern struct pmx_mode small_printers_mode;
+
+/* pad mux devices */
+extern struct pmx_dev pmx_clcd;
+extern struct pmx_dev pmx_emi;
+extern struct pmx_dev pmx_fsmc;
+extern struct pmx_dev pmx_spp;
+extern struct pmx_dev pmx_sdio;
+extern struct pmx_dev pmx_i2s;
+extern struct pmx_dev pmx_uart1;
+extern struct pmx_dev pmx_uart1_modem;
+extern struct pmx_dev pmx_uart2;
+extern struct pmx_dev pmx_touchscreen;
+extern struct pmx_dev pmx_can;
+extern struct pmx_dev pmx_sdio_led;
+extern struct pmx_dev pmx_pwm0;
+extern struct pmx_dev pmx_pwm1;
+extern struct pmx_dev pmx_pwm2;
+extern struct pmx_dev pmx_pwm3;
+extern struct pmx_dev pmx_ssp1;
+extern struct pmx_dev pmx_ssp2;
+extern struct pmx_dev pmx_mii1;
+extern struct pmx_dev pmx_smii0;
+extern struct pmx_dev pmx_smii1;
+extern struct pmx_dev pmx_i2c1;
+
+void spear320_pmx_init(void);
+
+/* Add spear320 machine function declarations here */
+void __init spear320_init(void);
+
+#endif /* CONFIG_MACH_SPEAR320 */
+
+#endif /* __MACH_GENERIC_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/gpio.h b/arch/arm/mach-spear3xx/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..451b208
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/gpio.h
+ *
+ * GPIO macros for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_GPIO_H
+#define __MACH_GPIO_H
+
+#include <plat/gpio.h>
+
+#endif /* __MACH_GPIO_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/hardware.h b/arch/arm/mach-spear3xx/include/mach/hardware.h
new file mode 100644 (file)
index 0000000..4a86e6a
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/hardware.h
+ *
+ * Hardware definitions for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_HARDWARE_H
+#define __MACH_HARDWARE_H
+
+/* Vitual to physical translation of statically mapped space */
+#define IO_ADDRESS(x)          (x | 0xF0000000)
+
+#endif /* __MACH_HARDWARE_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/io.h b/arch/arm/mach-spear3xx/include/mach/io.h
new file mode 100644 (file)
index 0000000..30cff8a
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/io.h
+ *
+ * IO definitions for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_IO_H
+#define __MACH_IO_H
+
+#include <plat/io.h>
+
+#endif /* __MACH_IO_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/irqs.h b/arch/arm/mach-spear3xx/include/mach/irqs.h
new file mode 100644 (file)
index 0000000..7f940b8
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/irqs.h
+ *
+ * IRQ helper macros for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_IRQS_H
+#define __MACH_IRQS_H
+
+/* SPEAr3xx IRQ definitions */
+#define IRQ_HW_ACCEL_MOD_0                     0
+#define IRQ_INTRCOMM_RAS_ARM                   1
+#define IRQ_CPU_GPT1_1                         2
+#define IRQ_CPU_GPT1_2                         3
+#define IRQ_BASIC_GPT1_1                       4
+#define IRQ_BASIC_GPT1_2                       5
+#define IRQ_BASIC_GPT2_1                       6
+#define IRQ_BASIC_GPT2_2                       7
+#define IRQ_BASIC_DMA                          8
+#define IRQ_BASIC_SMI                          9
+#define IRQ_BASIC_RTC                          10
+#define IRQ_BASIC_GPIO                         11
+#define IRQ_BASIC_WDT                          12
+#define IRQ_DDR_CONTROLLER                     13
+#define IRQ_SYS_ERROR                          14
+#define IRQ_WAKEUP_RCV                         15
+#define IRQ_JPEG                               16
+#define IRQ_IRDA                               17
+#define IRQ_ADC                                        18
+#define IRQ_UART                               19
+#define IRQ_SSP                                        20
+#define IRQ_I2C                                        21
+#define IRQ_MAC_1                              22
+#define IRQ_MAC_2                              23
+#define IRQ_USB_DEV                            24
+#define IRQ_USB_H_OHCI_0                       25
+#define IRQ_USB_H_EHCI_0                       26
+#define IRQ_USB_H_EHCI_1                       IRQ_USB_H_EHCI_0
+#define IRQ_USB_H_OHCI_1                       27
+#define IRQ_GEN_RAS_1                          28
+#define IRQ_GEN_RAS_2                          29
+#define IRQ_GEN_RAS_3                          30
+#define IRQ_HW_ACCEL_MOD_1                     31
+#define IRQ_VIC_END                            32
+
+#define VIRQ_START                             IRQ_VIC_END
+
+/* SPEAr300 Virtual irq definitions */
+#ifdef CONFIG_MACH_SPEAR300
+/* IRQs sharing IRQ_GEN_RAS_1 */
+#define VIRQ_IT_PERS_S                         (VIRQ_START + 0)
+#define VIRQ_IT_CHANGE_S                       (VIRQ_START + 1)
+#define VIRQ_I2S                               (VIRQ_START + 2)
+#define VIRQ_TDM                               (VIRQ_START + 3)
+#define VIRQ_CAMERA_L                          (VIRQ_START + 4)
+#define VIRQ_CAMERA_F                          (VIRQ_START + 5)
+#define VIRQ_CAMERA_V                          (VIRQ_START + 6)
+#define VIRQ_KEYBOARD                          (VIRQ_START + 7)
+#define VIRQ_GPIO1                             (VIRQ_START + 8)
+
+/* IRQs sharing IRQ_GEN_RAS_3 */
+#define IRQ_CLCD                               IRQ_GEN_RAS_3
+
+/* IRQs sharing IRQ_INTRCOMM_RAS_ARM */
+#define IRQ_SDIO                               IRQ_INTRCOMM_RAS_ARM
+
+/* GPIO pins virtual irqs */
+#define SPEAR_GPIO_INT_BASE                    (VIRQ_START + 9)
+#define SPEAR_GPIO1_INT_BASE                   (SPEAR_GPIO_INT_BASE + 8)
+#define SPEAR_GPIO_INT_END                     (SPEAR_GPIO1_INT_BASE + 8)
+
+/* SPEAr310 Virtual irq definitions */
+#elif defined(CONFIG_MACH_SPEAR310)
+/* IRQs sharing IRQ_GEN_RAS_1 */
+#define VIRQ_SMII0                             (VIRQ_START + 0)
+#define VIRQ_SMII1                             (VIRQ_START + 1)
+#define VIRQ_SMII2                             (VIRQ_START + 2)
+#define VIRQ_SMII3                             (VIRQ_START + 3)
+#define VIRQ_WAKEUP_SMII0                      (VIRQ_START + 4)
+#define VIRQ_WAKEUP_SMII1                      (VIRQ_START + 5)
+#define VIRQ_WAKEUP_SMII2                      (VIRQ_START + 6)
+#define VIRQ_WAKEUP_SMII3                      (VIRQ_START + 7)
+
+/* IRQs sharing IRQ_GEN_RAS_2 */
+#define VIRQ_UART1                             (VIRQ_START + 8)
+#define VIRQ_UART2                             (VIRQ_START + 9)
+#define VIRQ_UART3                             (VIRQ_START + 10)
+#define VIRQ_UART4                             (VIRQ_START + 11)
+#define VIRQ_UART5                             (VIRQ_START + 12)
+
+/* IRQs sharing IRQ_GEN_RAS_3 */
+#define VIRQ_EMI                               (VIRQ_START + 13)
+#define VIRQ_PLGPIO                            (VIRQ_START + 14)
+
+/* IRQs sharing IRQ_INTRCOMM_RAS_ARM */
+#define VIRQ_TDM_HDLC                          (VIRQ_START + 15)
+#define VIRQ_RS485_0                           (VIRQ_START + 16)
+#define VIRQ_RS485_1                           (VIRQ_START + 17)
+
+/* GPIO pins virtual irqs */
+#define SPEAR_GPIO_INT_BASE                    (VIRQ_START + 18)
+
+/* SPEAr320 Virtual irq definitions */
+#else
+/* IRQs sharing IRQ_GEN_RAS_1 */
+#define VIRQ_EMI                               (VIRQ_START + 0)
+#define VIRQ_CLCD                              (VIRQ_START + 1)
+#define VIRQ_SPP                               (VIRQ_START + 2)
+
+/* IRQs sharing IRQ_GEN_RAS_2 */
+#define IRQ_SDIO                               IRQ_GEN_RAS_2
+
+/* IRQs sharing IRQ_GEN_RAS_3 */
+#define VIRQ_PLGPIO                            (VIRQ_START + 3)
+#define VIRQ_I2S_PLAY                          (VIRQ_START + 4)
+#define VIRQ_I2S_REC                           (VIRQ_START + 5)
+
+/* IRQs sharing IRQ_INTRCOMM_RAS_ARM */
+#define VIRQ_CANU                              (VIRQ_START + 6)
+#define VIRQ_CANL                              (VIRQ_START + 7)
+#define VIRQ_UART1                             (VIRQ_START + 8)
+#define VIRQ_UART2                             (VIRQ_START + 9)
+#define VIRQ_SSP1                              (VIRQ_START + 10)
+#define VIRQ_SSP2                              (VIRQ_START + 11)
+#define VIRQ_SMII0                             (VIRQ_START + 12)
+#define VIRQ_MII1_SMII1                                (VIRQ_START + 13)
+#define VIRQ_WAKEUP_SMII0                      (VIRQ_START + 14)
+#define VIRQ_WAKEUP_MII1_SMII1                 (VIRQ_START + 15)
+#define VIRQ_I2C                               (VIRQ_START + 16)
+
+/* GPIO pins virtual irqs */
+#define SPEAR_GPIO_INT_BASE                    (VIRQ_START + 17)
+
+#endif
+
+/* PLGPIO Virtual IRQs */
+#if defined(CONFIG_MACH_SPEAR310) || defined(CONFIG_MACH_SPEAR320)
+#define SPEAR_PLGPIO_INT_BASE                  (SPEAR_GPIO_INT_BASE + 8)
+#define SPEAR_GPIO_INT_END                     (SPEAR_PLGPIO_INT_BASE + 102)
+#endif
+
+#define VIRQ_END                               SPEAR_GPIO_INT_END
+#define NR_IRQS                                        VIRQ_END
+
+#endif /* __MACH_IRQS_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/memory.h b/arch/arm/mach-spear3xx/include/mach/memory.h
new file mode 100644 (file)
index 0000000..5173522
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/memory.h
+ *
+ * Memory map for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MEMORY_H
+#define __MACH_MEMORY_H
+
+#include <plat/memory.h>
+
+#endif /* __MACH_MEMORY_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/misc_regs.h b/arch/arm/mach-spear3xx/include/mach/misc_regs.h
new file mode 100644 (file)
index 0000000..38d767a
--- /dev/null
@@ -0,0 +1,163 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/misc_regs.h
+ *
+ * Miscellaneous registers definitions for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MISC_REGS_H
+#define __MACH_MISC_REGS_H
+
+#include <mach/spear.h>
+
+#define MISC_BASE              VA_SPEAR3XX_ICM3_MISC_REG_BASE
+
+#define SOC_CFG_CTR            ((unsigned int *)(MISC_BASE + 0x000))
+#define DIAG_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x004))
+#define PLL1_CTR               ((unsigned int *)(MISC_BASE + 0x008))
+#define PLL1_FRQ               ((unsigned int *)(MISC_BASE + 0x00C))
+#define PLL1_MOD               ((unsigned int *)(MISC_BASE + 0x010))
+#define PLL2_CTR               ((unsigned int *)(MISC_BASE + 0x014))
+/* PLL_CTR register masks */
+#define PLL_ENABLE             2
+#define PLL_MODE_SHIFT         4
+#define PLL_MODE_MASK          0x3
+#define PLL_MODE_NORMAL                0
+#define PLL_MODE_FRACTION      1
+#define PLL_MODE_DITH_DSB      2
+#define PLL_MODE_DITH_SSB      3
+
+#define PLL2_FRQ               ((unsigned int *)(MISC_BASE + 0x018))
+/* PLL FRQ register masks */
+#define PLL_DIV_N_SHIFT                0
+#define PLL_DIV_N_MASK         0xFF
+#define PLL_DIV_P_SHIFT                8
+#define PLL_DIV_P_MASK         0x7
+#define PLL_NORM_FDBK_M_SHIFT  24
+#define PLL_NORM_FDBK_M_MASK   0xFF
+#define PLL_DITH_FDBK_M_SHIFT  16
+#define PLL_DITH_FDBK_M_MASK   0xFFFF
+
+#define PLL2_MOD               ((unsigned int *)(MISC_BASE + 0x01C))
+#define PLL_CLK_CFG            ((unsigned int *)(MISC_BASE + 0x020))
+#define CORE_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x024))
+/* CORE CLK CFG register masks */
+#define PLL_HCLK_RATIO_SHIFT   10
+#define PLL_HCLK_RATIO_MASK    0x3
+#define HCLK_PCLK_RATIO_SHIFT  8
+#define HCLK_PCLK_RATIO_MASK   0x3
+
+#define PERIP_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x028))
+/* PERIP_CLK_CFG register masks */
+#define UART_CLK_SHIFT         4
+#define UART_CLK_MASK          0x1
+#define FIRDA_CLK_SHIFT                5
+#define FIRDA_CLK_MASK         0x3
+#define GPT0_CLK_SHIFT         8
+#define GPT1_CLK_SHIFT         11
+#define GPT2_CLK_SHIFT         12
+#define GPT_CLK_MASK           0x1
+#define AUX_CLK_PLL3_MASK      0
+#define AUX_CLK_PLL1_MASK      1
+
+#define PERIP1_CLK_ENB         ((unsigned int *)(MISC_BASE + 0x02C))
+/* PERIP1_CLK_ENB register masks */
+#define UART_CLK_ENB           3
+#define SSP_CLK_ENB            5
+#define I2C_CLK_ENB            7
+#define JPEG_CLK_ENB           8
+#define FIRDA_CLK_ENB          10
+#define GPT1_CLK_ENB           11
+#define GPT2_CLK_ENB           12
+#define ADC_CLK_ENB            15
+#define RTC_CLK_ENB            17
+#define GPIO_CLK_ENB           18
+#define DMA_CLK_ENB            19
+#define SMI_CLK_ENB            21
+#define GMAC_CLK_ENB           23
+#define USBD_CLK_ENB           24
+#define USBH_CLK_ENB           25
+#define C3_CLK_ENB             31
+
+#define SOC_CORE_ID            ((unsigned int *)(MISC_BASE + 0x030))
+#define RAS_CLK_ENB            ((unsigned int *)(MISC_BASE + 0x034))
+#define PERIP1_SOF_RST         ((unsigned int *)(MISC_BASE + 0x038))
+/* PERIP1_SOF_RST register masks */
+#define JPEG_SOF_RST           8
+
+#define SOC_USER_ID            ((unsigned int *)(MISC_BASE + 0x03C))
+#define RAS_SOF_RST            ((unsigned int *)(MISC_BASE + 0x040))
+#define PRSC1_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x044))
+#define PRSC2_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x048))
+#define PRSC3_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x04C))
+/* gpt synthesizer register masks */
+#define GPT_MSCALE_SHIFT       0
+#define GPT_MSCALE_MASK                0xFFF
+#define GPT_NSCALE_SHIFT       12
+#define GPT_NSCALE_MASK                0xF
+
+#define AMEM_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x050))
+#define EXPI_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x054))
+#define CLCD_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x05C))
+#define FIRDA_CLK_SYNT         ((unsigned int *)(MISC_BASE + 0x060))
+#define UART_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x064))
+#define GMAC_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x068))
+#define RAS1_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x06C))
+#define RAS2_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x070))
+#define RAS3_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x074))
+#define RAS4_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x078))
+/* aux clk synthesiser register masks for irda to ras4 */
+#define AUX_EQ_SEL_SHIFT       30
+#define AUX_EQ_SEL_MASK                1
+#define AUX_EQ1_SEL            0
+#define AUX_EQ2_SEL            1
+#define AUX_XSCALE_SHIFT       16
+#define AUX_XSCALE_MASK                0xFFF
+#define AUX_YSCALE_SHIFT       0
+#define AUX_YSCALE_MASK                0xFFF
+
+#define ICM1_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x07C))
+#define ICM2_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x080))
+#define ICM3_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x084))
+#define ICM4_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x088))
+#define ICM5_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x08C))
+#define ICM6_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x090))
+#define ICM7_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x094))
+#define ICM8_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x098))
+#define ICM9_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x09C))
+#define DMA_CHN_CFG            ((unsigned int *)(MISC_BASE + 0x0A0))
+#define USB2_PHY_CFG           ((unsigned int *)(MISC_BASE + 0x0A4))
+#define GMAC_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x0A8))
+#define EXPI_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x0AC))
+#define PRC1_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C0))
+#define PRC2_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C4))
+#define PRC3_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C8))
+#define PRC4_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0CC))
+#define PRC1_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D0))
+#define PRC2_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D4))
+#define PRC3_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D8))
+#define PRC4_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0DC))
+#define PWRDOWN_CFG_CTR                ((unsigned int *)(MISC_BASE + 0x0E0))
+#define COMPSSTL_1V8_CFG       ((unsigned int *)(MISC_BASE + 0x0E4))
+#define COMPSSTL_2V5_CFG       ((unsigned int *)(MISC_BASE + 0x0E8))
+#define COMPCOR_3V3_CFG                ((unsigned int *)(MISC_BASE + 0x0EC))
+#define SSTLPAD_CFG_CTR                ((unsigned int *)(MISC_BASE + 0x0F0))
+#define BIST1_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0F4))
+#define BIST2_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0F8))
+#define BIST3_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0FC))
+#define BIST4_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x100))
+#define BIST5_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x104))
+#define BIST1_STS_RES          ((unsigned int *)(MISC_BASE + 0x108))
+#define BIST2_STS_RES          ((unsigned int *)(MISC_BASE + 0x10C))
+#define BIST3_STS_RES          ((unsigned int *)(MISC_BASE + 0x110))
+#define BIST4_STS_RES          ((unsigned int *)(MISC_BASE + 0x114))
+#define BIST5_STS_RES          ((unsigned int *)(MISC_BASE + 0x118))
+#define SYSERR_CFG_CTR         ((unsigned int *)(MISC_BASE + 0x11C))
+
+#endif /* __MACH_MISC_REGS_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/spear.h b/arch/arm/mach-spear3xx/include/mach/spear.h
new file mode 100644 (file)
index 0000000..dcca856
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/spear.h
+ *
+ * SPEAr3xx Machine family specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_SPEAR3XX_H
+#define __MACH_SPEAR3XX_H
+
+#include <mach/hardware.h>
+#include <mach/spear300.h>
+#include <mach/spear310.h>
+#include <mach/spear320.h>
+
+#define SPEAR3XX_ML_SDRAM_BASE         0x00000000
+#define SPEAR3XX_ML_SDRAM_SIZE         0x40000000
+
+#define SPEAR3XX_ICM9_BASE             0xC0000000
+#define SPEAR3XX_ICM9_SIZE             0x10000000
+
+/* ICM1 - Low speed connection */
+#define SPEAR3XX_ICM1_2_BASE           0xD0000000
+#define SPEAR3XX_ICM1_2_SIZE           0x10000000
+
+#define SPEAR3XX_ICM1_UART_BASE                0xD0000000
+#define VA_SPEAR3XX_ICM1_UART_BASE     IO_ADDRESS(SPEAR3XX_ICM1_UART_BASE)
+#define SPEAR3XX_ICM1_UART_SIZE                0x00080000
+
+#define SPEAR3XX_ICM1_ADC_BASE         0xD0080000
+#define SPEAR3XX_ICM1_ADC_SIZE         0x00080000
+
+#define SPEAR3XX_ICM1_SSP_BASE         0xD0100000
+#define SPEAR3XX_ICM1_SSP_SIZE         0x00080000
+
+#define SPEAR3XX_ICM1_I2C_BASE         0xD0180000
+#define SPEAR3XX_ICM1_I2C_SIZE         0x00080000
+
+#define SPEAR3XX_ICM1_JPEG_BASE                0xD0800000
+#define SPEAR3XX_ICM1_JPEG_SIZE                0x00800000
+
+#define SPEAR3XX_ICM1_IRDA_BASE                0xD1000000
+#define SPEAR3XX_ICM1_IRDA_SIZE                0x00080000
+
+#define SPEAR3XX_ICM1_SRAM_BASE                0xD2800000
+#define SPEAR3XX_ICM1_SRAM_SIZE                0x05800000
+
+/* ICM2 - Application Subsystem */
+#define SPEAR3XX_ICM2_HWACCEL0_BASE    0xD8800000
+#define SPEAR3XX_ICM2_HWACCEL0_SIZE    0x00800000
+
+#define SPEAR3XX_ICM2_HWACCEL1_BASE    0xD9000000
+#define SPEAR3XX_ICM2_HWACCEL1_SIZE    0x00800000
+
+/* ICM4 - High Speed Connection */
+#define SPEAR3XX_ICM4_BASE             0xE0000000
+#define SPEAR3XX_ICM4_SIZE             0x08000000
+
+#define SPEAR3XX_ICM4_MII_BASE         0xE0800000
+#define SPEAR3XX_ICM4_MII_SIZE         0x00800000
+
+#define SPEAR3XX_ICM4_USBD_FIFO_BASE   0xE1000000
+#define SPEAR3XX_ICM4_USBD_FIFO_SIZE   0x00100000
+
+#define SPEAR3XX_ICM4_USBD_CSR_BASE    0xE1100000
+#define SPEAR3XX_ICM4_USBD_CSR_SIZE    0x00100000
+
+#define SPEAR3XX_ICM4_USBD_PLDT_BASE   0xE1200000
+#define SPEAR3XX_ICM4_USBD_PLDT_SIZE   0x00100000
+
+#define SPEAR3XX_ICM4_USB_EHCI0_1_BASE 0xE1800000
+#define SPEAR3XX_ICM4_USB_EHCI0_1_SIZE 0x00100000
+
+#define SPEAR3XX_ICM4_USB_OHCI0_BASE   0xE1900000
+#define SPEAR3XX_ICM4_USB_OHCI0_SIZE   0x00100000
+
+#define SPEAR3XX_ICM4_USB_OHCI1_BASE   0xE2100000
+#define SPEAR3XX_ICM4_USB_OHCI1_SIZE   0x00100000
+
+#define SPEAR3XX_ICM4_USB_ARB_BASE     0xE2800000
+#define SPEAR3XX_ICM4_USB_ARB_SIZE     0x00010000
+
+/* ML1 - Multi Layer CPU Subsystem */
+#define SPEAR3XX_ICM3_ML1_2_BASE       0xF0000000
+#define SPEAR3XX_ICM3_ML1_2_SIZE       0x0F000000
+
+#define SPEAR3XX_ML1_TMR_BASE          0xF0000000
+#define SPEAR3XX_ML1_TMR_SIZE          0x00100000
+
+#define SPEAR3XX_ML1_VIC_BASE          0xF1100000
+#define VA_SPEAR3XX_ML1_VIC_BASE       IO_ADDRESS(SPEAR3XX_ML1_VIC_BASE)
+#define SPEAR3XX_ML1_VIC_SIZE          0x00100000
+
+/* ICM3 - Basic Subsystem */
+#define SPEAR3XX_ICM3_SMEM_BASE                0xF8000000
+#define SPEAR3XX_ICM3_SMEM_SIZE                0x04000000
+
+#define SPEAR3XX_ICM3_SMI_CTRL_BASE    0xFC000000
+#define SPEAR3XX_ICM3_SMI_CTRL_SIZE    0x00200000
+
+#define SPEAR3XX_ICM3_DMA_BASE         0xFC400000
+#define SPEAR3XX_ICM3_DMA_SIZE         0x00200000
+
+#define SPEAR3XX_ICM3_SDRAM_CTRL_BASE  0xFC600000
+#define SPEAR3XX_ICM3_SDRAM_CTRL_SIZE  0x00200000
+
+#define SPEAR3XX_ICM3_TMR0_BASE                0xFC800000
+#define SPEAR3XX_ICM3_TMR0_SIZE                0x00080000
+
+#define SPEAR3XX_ICM3_WDT_BASE         0xFC880000
+#define SPEAR3XX_ICM3_WDT_SIZE         0x00080000
+
+#define SPEAR3XX_ICM3_RTC_BASE         0xFC900000
+#define SPEAR3XX_ICM3_RTC_SIZE         0x00080000
+
+#define SPEAR3XX_ICM3_GPIO_BASE                0xFC980000
+#define SPEAR3XX_ICM3_GPIO_SIZE                0x00080000
+
+#define SPEAR3XX_ICM3_SYS_CTRL_BASE    0xFCA00000
+#define VA_SPEAR3XX_ICM3_SYS_CTRL_BASE IO_ADDRESS(SPEAR3XX_ICM3_SYS_CTRL_BASE)
+#define SPEAR3XX_ICM3_SYS_CTRL_SIZE    0x00080000
+
+#define SPEAR3XX_ICM3_MISC_REG_BASE    0xFCA80000
+#define VA_SPEAR3XX_ICM3_MISC_REG_BASE IO_ADDRESS(SPEAR3XX_ICM3_MISC_REG_BASE)
+#define SPEAR3XX_ICM3_MISC_REG_SIZE    0x00080000
+
+#define SPEAR3XX_ICM3_TMR1_BASE                0xFCB00000
+#define SPEAR3XX_ICM3_TMR1_SIZE                0x00080000
+
+/* Debug uart for linux, will be used for debug and uncompress messages */
+#define SPEAR_DBG_UART_BASE            SPEAR3XX_ICM1_UART_BASE
+#define VA_SPEAR_DBG_UART_BASE         VA_SPEAR3XX_ICM1_UART_BASE
+
+/* Sysctl base for spear platform */
+#define SPEAR_SYS_CTRL_BASE            SPEAR3XX_ICM3_SYS_CTRL_BASE
+#define VA_SPEAR_SYS_CTRL_BASE         VA_SPEAR3XX_ICM3_SYS_CTRL_BASE
+
+#endif /* __MACH_SPEAR3XX_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/spear300.h b/arch/arm/mach-spear3xx/include/mach/spear300.h
new file mode 100644 (file)
index 0000000..ccaa765
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/spear300.h
+ *
+ * SPEAr300 Machine specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifdef CONFIG_MACH_SPEAR300
+
+#ifndef __MACH_SPEAR300_H
+#define __MACH_SPEAR300_H
+
+/* Base address of various IPs */
+#define SPEAR300_TELECOM_BASE          0x50000000
+#define SPEAR300_TELECOM_SIZE          0x10000000
+
+/* Interrupt registers offsets and masks */
+#define SPEAR300_TELECOM_REG_SIZE      0x00010000
+#define INT_ENB_MASK_REG               0x54
+#define INT_STS_MASK_REG               0x58
+#define IT_PERS_S_IRQ_MASK             (1 << 0)
+#define IT_CHANGE_S_IRQ_MASK           (1 << 1)
+#define I2S_IRQ_MASK                   (1 << 2)
+#define TDM_IRQ_MASK                   (1 << 3)
+#define CAMERA_L_IRQ_MASK              (1 << 4)
+#define CAMERA_F_IRQ_MASK              (1 << 5)
+#define CAMERA_V_IRQ_MASK              (1 << 6)
+#define KEYBOARD_IRQ_MASK              (1 << 7)
+#define GPIO1_IRQ_MASK                 (1 << 8)
+
+#define SHIRQ_RAS1_MASK                        0x1FF
+
+#define SPEAR300_CLCD_BASE             0x60000000
+#define SPEAR300_CLCD_SIZE             0x10000000
+
+#define SPEAR300_SDIO_BASE             0x70000000
+#define SPEAR300_SDIO_SIZE             0x10000000
+
+#define SPEAR300_NAND_0_BASE           0x80000000
+#define SPEAR300_NAND_0_SIZE           0x04000000
+
+#define SPEAR300_NAND_1_BASE           0x84000000
+#define SPEAR300_NAND_1_SIZE           0x04000000
+
+#define SPEAR300_NAND_2_BASE           0x88000000
+#define SPEAR300_NAND_2_SIZE           0x04000000
+
+#define SPEAR300_NAND_3_BASE           0x8c000000
+#define SPEAR300_NAND_3_SIZE           0x04000000
+
+#define SPEAR300_NOR_0_BASE            0x90000000
+#define SPEAR300_NOR_0_SIZE            0x01000000
+
+#define SPEAR300_NOR_1_BASE            0x91000000
+#define SPEAR300_NOR_1_SIZE            0x01000000
+
+#define SPEAR300_NOR_2_BASE            0x92000000
+#define SPEAR300_NOR_2_SIZE            0x01000000
+
+#define SPEAR300_NOR_3_BASE            0x93000000
+#define SPEAR300_NOR_3_SIZE            0x01000000
+
+#define SPEAR300_FSMC_BASE             0x94000000
+#define SPEAR300_FSMC_SIZE             0x05000000
+
+#define SPEAR300_SOC_CONFIG_BASE       0x99000000
+#define SPEAR300_SOC_CONFIG_SIZE       0x00000008
+
+#define SPEAR300_KEYBOARD_BASE         0xA0000000
+#define SPEAR300_KEYBOARD_SIZE         0x09000000
+
+#define SPEAR300_GPIO_BASE             0xA9000000
+#define SPEAR300_GPIO_SIZE             0x07000000
+
+#endif /* __MACH_SPEAR300_H */
+
+#endif /* CONFIG_MACH_SPEAR300 */
diff --git a/arch/arm/mach-spear3xx/include/mach/spear310.h b/arch/arm/mach-spear3xx/include/mach/spear310.h
new file mode 100644 (file)
index 0000000..b27bb8a
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/spear310.h
+ *
+ * SPEAr310 Machine specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifdef CONFIG_MACH_SPEAR310
+
+#ifndef __MACH_SPEAR310_H
+#define __MACH_SPEAR310_H
+
+#define SPEAR310_NAND_BASE             0x40000000
+#define SPEAR310_NAND_SIZE             0x04000000
+
+#define SPEAR310_FSMC_BASE             0x44000000
+#define SPEAR310_FSMC_SIZE             0x01000000
+
+#define SPEAR310_UART1_BASE            0xB2000000
+#define SPEAR310_UART2_BASE            0xB2080000
+#define SPEAR310_UART3_BASE            0xB2100000
+#define SPEAR310_UART4_BASE            0xB2180000
+#define SPEAR310_UART5_BASE            0xB2200000
+#define SPEAR310_UART_SIZE             0x00080000
+
+#define SPEAR310_HDLC_BASE             0xB2800000
+#define SPEAR310_HDLC_SIZE             0x00800000
+
+#define SPEAR310_RS485_0_BASE          0xB3000000
+#define SPEAR310_RS485_0_SIZE          0x00800000
+
+#define SPEAR310_RS485_1_BASE          0xB3800000
+#define SPEAR310_RS485_1_SIZE          0x00800000
+
+#define SPEAR310_SOC_CONFIG_BASE       0xB4000000
+#define SPEAR310_SOC_CONFIG_SIZE       0x00000070
+/* Interrupt registers offsets and masks */
+#define INT_STS_MASK_REG               0x04
+#define SMII0_IRQ_MASK                 (1 << 0)
+#define SMII1_IRQ_MASK                 (1 << 1)
+#define SMII2_IRQ_MASK                 (1 << 2)
+#define SMII3_IRQ_MASK                 (1 << 3)
+#define WAKEUP_SMII0_IRQ_MASK          (1 << 4)
+#define WAKEUP_SMII1_IRQ_MASK          (1 << 5)
+#define WAKEUP_SMII2_IRQ_MASK          (1 << 6)
+#define WAKEUP_SMII3_IRQ_MASK          (1 << 7)
+#define UART1_IRQ_MASK                 (1 << 8)
+#define UART2_IRQ_MASK                 (1 << 9)
+#define UART3_IRQ_MASK                 (1 << 10)
+#define UART4_IRQ_MASK                 (1 << 11)
+#define UART5_IRQ_MASK                 (1 << 12)
+#define EMI_IRQ_MASK                   (1 << 13)
+#define TDM_HDLC_IRQ_MASK              (1 << 14)
+#define RS485_0_IRQ_MASK               (1 << 15)
+#define RS485_1_IRQ_MASK               (1 << 16)
+
+#define SHIRQ_RAS1_MASK                        0x000FF
+#define SHIRQ_RAS2_MASK                        0x01F00
+#define SHIRQ_RAS3_MASK                        0x02000
+#define SHIRQ_INTRCOMM_RAS_MASK                0x1C000
+
+#endif /* __MACH_SPEAR310_H */
+
+#endif /* CONFIG_MACH_SPEAR310 */
diff --git a/arch/arm/mach-spear3xx/include/mach/spear320.h b/arch/arm/mach-spear3xx/include/mach/spear320.h
new file mode 100644 (file)
index 0000000..cacf17a
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/spear320.h
+ *
+ * SPEAr320 Machine specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifdef CONFIG_MACH_SPEAR320
+
+#ifndef __MACH_SPEAR320_H
+#define __MACH_SPEAR320_H
+
+#define SPEAR320_EMI_CTRL_BASE         0x40000000
+#define SPEAR320_EMI_CTRL_SIZE         0x08000000
+
+#define SPEAR320_FSMC_BASE             0x4C000000
+#define SPEAR320_FSMC_SIZE             0x01000000
+
+#define SPEAR320_I2S_BASE              0x60000000
+#define SPEAR320_I2S_SIZE              0x10000000
+
+#define SPEAR320_SDIO_BASE             0x70000000
+#define SPEAR320_SDIO_SIZE             0x10000000
+
+#define SPEAR320_CLCD_BASE             0x90000000
+#define SPEAR320_CLCD_SIZE             0x10000000
+
+#define SPEAR320_PAR_PORT_BASE         0xA0000000
+#define SPEAR320_PAR_PORT_SIZE         0x01000000
+
+#define SPEAR320_CAN0_BASE             0xA1000000
+#define SPEAR320_CAN0_SIZE             0x01000000
+
+#define SPEAR320_CAN1_BASE             0xA2000000
+#define SPEAR320_CAN1_SIZE             0x01000000
+
+#define SPEAR320_UART1_BASE            0xA3000000
+#define SPEAR320_UART2_BASE            0xA4000000
+#define SPEAR320_UART_SIZE             0x01000000
+
+#define SPEAR320_SSP0_BASE             0xA5000000
+#define SPEAR320_SSP0_SIZE             0x01000000
+
+#define SPEAR320_SSP1_BASE             0xA6000000
+#define SPEAR320_SSP1_SIZE             0x01000000
+
+#define SPEAR320_I2C_BASE              0xA7000000
+#define SPEAR320_I2C_SIZE              0x01000000
+
+#define SPEAR320_PWM_BASE              0xA8000000
+#define SPEAR320_PWM_SIZE              0x01000000
+
+#define SPEAR320_SMII0_BASE            0xAA000000
+#define SPEAR320_SMII0_SIZE            0x01000000
+
+#define SPEAR320_SMII1_BASE            0xAB000000
+#define SPEAR320_SMII1_SIZE            0x01000000
+
+#define SPEAR320_SOC_CONFIG_BASE       0xB4000000
+#define SPEAR320_SOC_CONFIG_SIZE       0x00000070
+/* Interrupt registers offsets and masks */
+#define INT_STS_MASK_REG               0x04
+#define INT_CLR_MASK_REG               0x04
+#define INT_ENB_MASK_REG               0x08
+#define GPIO_IRQ_MASK                  (1 << 0)
+#define I2S_PLAY_IRQ_MASK              (1 << 1)
+#define I2S_REC_IRQ_MASK               (1 << 2)
+#define EMI_IRQ_MASK                   (1 << 7)
+#define CLCD_IRQ_MASK                  (1 << 8)
+#define SPP_IRQ_MASK                   (1 << 9)
+#define SDIO_IRQ_MASK                  (1 << 10)
+#define CAN_U_IRQ_MASK                 (1 << 11)
+#define CAN_L_IRQ_MASK                 (1 << 12)
+#define UART1_IRQ_MASK                 (1 << 13)
+#define UART2_IRQ_MASK                 (1 << 14)
+#define SSP1_IRQ_MASK                  (1 << 15)
+#define SSP2_IRQ_MASK                  (1 << 16)
+#define SMII0_IRQ_MASK                 (1 << 17)
+#define MII1_SMII1_IRQ_MASK            (1 << 18)
+#define WAKEUP_SMII0_IRQ_MASK          (1 << 19)
+#define WAKEUP_MII1_SMII1_IRQ_MASK     (1 << 20)
+#define I2C1_IRQ_MASK                  (1 << 21)
+
+#define SHIRQ_RAS1_MASK                        0x000380
+#define SHIRQ_RAS3_MASK                        0x000007
+#define SHIRQ_INTRCOMM_RAS_MASK                0x3FF800
+
+#endif /* __MACH_SPEAR320_H */
+
+#endif /* CONFIG_MACH_SPEAR320 */
diff --git a/arch/arm/mach-spear3xx/include/mach/system.h b/arch/arm/mach-spear3xx/include/mach/system.h
new file mode 100644 (file)
index 0000000..92cee63
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/system.h
+ *
+ * SPEAr3xx Machine family specific architecture functions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_SYSTEM_H
+#define __MACH_SYSTEM_H
+
+#include <plat/system.h>
+
+#endif /* __MACH_SYSTEM_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/timex.h b/arch/arm/mach-spear3xx/include/mach/timex.h
new file mode 100644 (file)
index 0000000..a38cc9d
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/timex.h
+ *
+ * SPEAr3XX machine family specific timex definitions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_TIMEX_H
+#define __MACH_TIMEX_H
+
+#include <plat/timex.h>
+
+#endif /* __MACH_TIMEX_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/uncompress.h b/arch/arm/mach-spear3xx/include/mach/uncompress.h
new file mode 100644 (file)
index 0000000..53ba8bb
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/uncompress.h
+ *
+ * Serial port stubs for kernel decompress status messages
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_UNCOMPRESS_H
+#define __MACH_UNCOMPRESS_H
+
+#include <plat/uncompress.h>
+
+#endif /* __MACH_UNCOMPRESS_H */
diff --git a/arch/arm/mach-spear3xx/include/mach/vmalloc.h b/arch/arm/mach-spear3xx/include/mach/vmalloc.h
new file mode 100644 (file)
index 0000000..df977b3
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear3xx/include/mach/vmalloc.h
+ *
+ * Defining Vmalloc area for SPEAr3xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_VMALLOC_H
+#define __MACH_VMALLOC_H
+
+#include <plat/vmalloc.h>
+
+#endif /* __MACH_VMALLOC_H */
diff --git a/arch/arm/mach-spear3xx/spear300.c b/arch/arm/mach-spear3xx/spear300.c
new file mode 100644 (file)
index 0000000..3560f8c
--- /dev/null
@@ -0,0 +1,468 @@
+/*
+ * arch/arm/mach-spear3xx/spear300.c
+ *
+ * SPEAr300 machine source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/types.h>
+#include <linux/amba/pl061.h>
+#include <linux/ptrace.h>
+#include <asm/irq.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+#include <plat/shirq.h>
+
+/* pad multiplexing support */
+/* muxing registers */
+#define PAD_MUX_CONFIG_REG     0x00
+#define MODE_CONFIG_REG                0x04
+
+/* modes */
+#define NAND_MODE                      (1 << 0)
+#define NOR_MODE                       (1 << 1)
+#define PHOTO_FRAME_MODE               (1 << 2)
+#define LEND_IP_PHONE_MODE             (1 << 3)
+#define HEND_IP_PHONE_MODE             (1 << 4)
+#define LEND_WIFI_PHONE_MODE           (1 << 5)
+#define HEND_WIFI_PHONE_MODE           (1 << 6)
+#define ATA_PABX_WI2S_MODE             (1 << 7)
+#define ATA_PABX_I2S_MODE              (1 << 8)
+#define CAML_LCDW_MODE                 (1 << 9)
+#define CAMU_LCD_MODE                  (1 << 10)
+#define CAMU_WLCD_MODE                 (1 << 11)
+#define CAML_LCD_MODE                  (1 << 12)
+#define ALL_MODES                      0x1FFF
+
+struct pmx_mode nand_mode = {
+       .id = NAND_MODE,
+       .name = "nand mode",
+       .mask = 0x00,
+};
+
+struct pmx_mode nor_mode = {
+       .id = NOR_MODE,
+       .name = "nor mode",
+       .mask = 0x01,
+};
+
+struct pmx_mode photo_frame_mode = {
+       .id = PHOTO_FRAME_MODE,
+       .name = "photo frame mode",
+       .mask = 0x02,
+};
+
+struct pmx_mode lend_ip_phone_mode = {
+       .id = LEND_IP_PHONE_MODE,
+       .name = "lend ip phone mode",
+       .mask = 0x03,
+};
+
+struct pmx_mode hend_ip_phone_mode = {
+       .id = HEND_IP_PHONE_MODE,
+       .name = "hend ip phone mode",
+       .mask = 0x04,
+};
+
+struct pmx_mode lend_wifi_phone_mode = {
+       .id = LEND_WIFI_PHONE_MODE,
+       .name = "lend wifi phone mode",
+       .mask = 0x05,
+};
+
+struct pmx_mode hend_wifi_phone_mode = {
+       .id = HEND_WIFI_PHONE_MODE,
+       .name = "hend wifi phone mode",
+       .mask = 0x06,
+};
+
+struct pmx_mode ata_pabx_wi2s_mode = {
+       .id = ATA_PABX_WI2S_MODE,
+       .name = "ata pabx wi2s mode",
+       .mask = 0x07,
+};
+
+struct pmx_mode ata_pabx_i2s_mode = {
+       .id = ATA_PABX_I2S_MODE,
+       .name = "ata pabx i2s mode",
+       .mask = 0x08,
+};
+
+struct pmx_mode caml_lcdw_mode = {
+       .id = CAML_LCDW_MODE,
+       .name = "caml lcdw mode",
+       .mask = 0x0C,
+};
+
+struct pmx_mode camu_lcd_mode = {
+       .id = CAMU_LCD_MODE,
+       .name = "camu lcd mode",
+       .mask = 0x0D,
+};
+
+struct pmx_mode camu_wlcd_mode = {
+       .id = CAMU_WLCD_MODE,
+       .name = "camu wlcd mode",
+       .mask = 0x0E,
+};
+
+struct pmx_mode caml_lcd_mode = {
+       .id = CAML_LCD_MODE,
+       .name = "caml lcd mode",
+       .mask = 0x0F,
+};
+
+/* devices */
+struct pmx_dev_mode pmx_fsmc_2_chips_modes[] = {
+       {
+               .ids = NAND_MODE | NOR_MODE | PHOTO_FRAME_MODE |
+                       ATA_PABX_WI2S_MODE | ATA_PABX_I2S_MODE,
+               .mask = PMX_FIRDA_MASK,
+       },
+};
+
+struct pmx_dev pmx_fsmc_2_chips = {
+       .name = "fsmc_2_chips",
+       .modes = pmx_fsmc_2_chips_modes,
+       .mode_count = ARRAY_SIZE(pmx_fsmc_2_chips_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_fsmc_4_chips_modes[] = {
+       {
+               .ids = NAND_MODE | NOR_MODE | PHOTO_FRAME_MODE |
+                       ATA_PABX_WI2S_MODE | ATA_PABX_I2S_MODE,
+               .mask = PMX_FIRDA_MASK | PMX_UART0_MASK,
+       },
+};
+
+struct pmx_dev pmx_fsmc_4_chips = {
+       .name = "fsmc_4_chips",
+       .modes = pmx_fsmc_4_chips_modes,
+       .mode_count = ARRAY_SIZE(pmx_fsmc_4_chips_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_keyboard_modes[] = {
+       {
+               .ids = LEND_IP_PHONE_MODE | HEND_IP_PHONE_MODE |
+                       LEND_WIFI_PHONE_MODE | HEND_WIFI_PHONE_MODE |
+                       CAML_LCDW_MODE | CAMU_LCD_MODE | CAMU_WLCD_MODE |
+                       CAML_LCD_MODE,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_keyboard = {
+       .name = "keyboard",
+       .modes = pmx_keyboard_modes,
+       .mode_count = ARRAY_SIZE(pmx_keyboard_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_clcd_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK ,
+       }, {
+               .ids = HEND_IP_PHONE_MODE | HEND_WIFI_PHONE_MODE |
+                       CAMU_LCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_clcd = {
+       .name = "clcd",
+       .modes = pmx_clcd_modes,
+       .mode_count = ARRAY_SIZE(pmx_clcd_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_gpio_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE | CAMU_LCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_MII_MASK,
+       }, {
+               .ids = LEND_IP_PHONE_MODE | LEND_WIFI_PHONE_MODE,
+               .mask = PMX_MII_MASK | PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK,
+       }, {
+               .ids = ATA_PABX_I2S_MODE | CAML_LCDW_MODE | CAMU_WLCD_MODE,
+               .mask = PMX_MII_MASK | PMX_TIMER_3_4_MASK,
+       }, {
+               .ids = HEND_IP_PHONE_MODE | HEND_WIFI_PHONE_MODE,
+               .mask = PMX_MII_MASK | PMX_TIMER_1_2_MASK,
+       }, {
+               .ids = ATA_PABX_WI2S_MODE,
+               .mask = PMX_MII_MASK | PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK
+                       | PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_gpio = {
+       .name = "telecom_gpio",
+       .modes = pmx_telecom_gpio_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_gpio_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_tdm_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE | LEND_IP_PHONE_MODE |
+                       HEND_IP_PHONE_MODE | LEND_WIFI_PHONE_MODE
+                       | HEND_WIFI_PHONE_MODE | ATA_PABX_WI2S_MODE
+                       | ATA_PABX_I2S_MODE | CAML_LCDW_MODE | CAMU_LCD_MODE
+                       | CAMU_WLCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_UART0_MODEM_MASK | PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_tdm = {
+       .name = "telecom_tdm",
+       .modes = pmx_telecom_tdm_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_tdm_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_spi_cs_i2c_clk_modes[] = {
+       {
+               .ids = LEND_IP_PHONE_MODE | HEND_IP_PHONE_MODE |
+                       LEND_WIFI_PHONE_MODE | HEND_WIFI_PHONE_MODE
+                       | ATA_PABX_WI2S_MODE | ATA_PABX_I2S_MODE |
+                       CAML_LCDW_MODE | CAML_LCD_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_spi_cs_i2c_clk = {
+       .name = "telecom_spi_cs_i2c_clk",
+       .modes = pmx_telecom_spi_cs_i2c_clk_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_spi_cs_i2c_clk_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_camera_modes[] = {
+       {
+               .ids = CAML_LCDW_MODE | CAML_LCD_MODE,
+               .mask = PMX_MII_MASK,
+       }, {
+               .ids = CAMU_LCD_MODE | CAMU_WLCD_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK | PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_camera = {
+       .name = "telecom_camera",
+       .modes = pmx_telecom_camera_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_camera_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_dac_modes[] = {
+       {
+               .ids = ATA_PABX_I2S_MODE | CAML_LCDW_MODE | CAMU_LCD_MODE
+                       | CAMU_WLCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_TIMER_1_2_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_dac = {
+       .name = "telecom_dac",
+       .modes = pmx_telecom_dac_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_dac_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_i2s_modes[] = {
+       {
+               .ids = LEND_IP_PHONE_MODE | HEND_IP_PHONE_MODE
+                       | LEND_WIFI_PHONE_MODE | HEND_WIFI_PHONE_MODE |
+                       ATA_PABX_I2S_MODE | CAML_LCDW_MODE | CAMU_LCD_MODE
+                       | CAMU_WLCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_i2s = {
+       .name = "telecom_i2s",
+       .modes = pmx_telecom_i2s_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_i2s_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_boot_pins_modes[] = {
+       {
+               .ids = NAND_MODE | NOR_MODE,
+               .mask = PMX_UART0_MODEM_MASK | PMX_TIMER_1_2_MASK |
+                       PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_boot_pins = {
+       .name = "telecom_boot_pins",
+       .modes = pmx_telecom_boot_pins_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_boot_pins_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_sdio_4bit_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE | LEND_IP_PHONE_MODE |
+                       HEND_IP_PHONE_MODE | LEND_WIFI_PHONE_MODE |
+                       HEND_WIFI_PHONE_MODE | CAML_LCDW_MODE | CAMU_LCD_MODE |
+                       CAMU_WLCD_MODE | CAML_LCD_MODE | ATA_PABX_WI2S_MODE |
+                       ATA_PABX_I2S_MODE,
+               .mask = PMX_GPIO_PIN0_MASK | PMX_GPIO_PIN1_MASK |
+                       PMX_GPIO_PIN2_MASK | PMX_GPIO_PIN3_MASK |
+                       PMX_GPIO_PIN4_MASK | PMX_GPIO_PIN5_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_sdio_4bit = {
+       .name = "telecom_sdio_4bit",
+       .modes = pmx_telecom_sdio_4bit_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_sdio_4bit_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_telecom_sdio_8bit_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE | LEND_IP_PHONE_MODE |
+                       HEND_IP_PHONE_MODE | LEND_WIFI_PHONE_MODE |
+                       HEND_WIFI_PHONE_MODE | CAML_LCDW_MODE | CAMU_LCD_MODE |
+                       CAMU_WLCD_MODE | CAML_LCD_MODE,
+               .mask = PMX_GPIO_PIN0_MASK | PMX_GPIO_PIN1_MASK |
+                       PMX_GPIO_PIN2_MASK | PMX_GPIO_PIN3_MASK |
+                       PMX_GPIO_PIN4_MASK | PMX_GPIO_PIN5_MASK | PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_telecom_sdio_8bit = {
+       .name = "telecom_sdio_8bit",
+       .modes = pmx_telecom_sdio_8bit_modes,
+       .mode_count = ARRAY_SIZE(pmx_telecom_sdio_8bit_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_gpio1_modes[] = {
+       {
+               .ids = PHOTO_FRAME_MODE,
+               .mask = PMX_UART0_MODEM_MASK | PMX_TIMER_1_2_MASK |
+                       PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio1 = {
+       .name = "arm gpio1",
+       .modes = pmx_gpio1_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio1_modes),
+       .enb_on_reset = 1,
+};
+
+/* pmx driver structure */
+struct pmx_driver pmx_driver = {
+       .mode_reg = {.offset = MODE_CONFIG_REG, .mask = 0x0000000f},
+       .mux_reg = {.offset = PAD_MUX_CONFIG_REG, .mask = 0x00007fff},
+};
+
+/* Add spear300 specific devices here */
+/* arm gpio1 device registeration */
+static struct pl061_platform_data gpio1_plat_data = {
+       .gpio_base      = 8,
+       .irq_base       = SPEAR_GPIO1_INT_BASE,
+};
+
+struct amba_device gpio1_device = {
+       .dev = {
+               .init_name = "gpio1",
+               .platform_data = &gpio1_plat_data,
+       },
+       .res = {
+               .start = SPEAR300_GPIO_BASE,
+               .end = SPEAR300_GPIO_BASE + SPEAR300_GPIO_SIZE - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       .irq = {VIRQ_GPIO1, NO_IRQ},
+};
+
+/* spear3xx shared irq */
+struct shirq_dev_config shirq_ras1_config[] = {
+       {
+               .virq = VIRQ_IT_PERS_S,
+               .enb_mask = IT_PERS_S_IRQ_MASK,
+               .status_mask = IT_PERS_S_IRQ_MASK,
+       }, {
+               .virq = VIRQ_IT_CHANGE_S,
+               .enb_mask = IT_CHANGE_S_IRQ_MASK,
+               .status_mask = IT_CHANGE_S_IRQ_MASK,
+       }, {
+               .virq = VIRQ_I2S,
+               .enb_mask = I2S_IRQ_MASK,
+               .status_mask = I2S_IRQ_MASK,
+       }, {
+               .virq = VIRQ_TDM,
+               .enb_mask = TDM_IRQ_MASK,
+               .status_mask = TDM_IRQ_MASK,
+       }, {
+               .virq = VIRQ_CAMERA_L,
+               .enb_mask = CAMERA_L_IRQ_MASK,
+               .status_mask = CAMERA_L_IRQ_MASK,
+       }, {
+               .virq = VIRQ_CAMERA_F,
+               .enb_mask = CAMERA_F_IRQ_MASK,
+               .status_mask = CAMERA_F_IRQ_MASK,
+       }, {
+               .virq = VIRQ_CAMERA_V,
+               .enb_mask = CAMERA_V_IRQ_MASK,
+               .status_mask = CAMERA_V_IRQ_MASK,
+       }, {
+               .virq = VIRQ_KEYBOARD,
+               .enb_mask = KEYBOARD_IRQ_MASK,
+               .status_mask = KEYBOARD_IRQ_MASK,
+       }, {
+               .virq = VIRQ_GPIO1,
+               .enb_mask = GPIO1_IRQ_MASK,
+               .status_mask = GPIO1_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras1 = {
+       .irq = IRQ_GEN_RAS_1,
+       .dev_config = shirq_ras1_config,
+       .dev_count = ARRAY_SIZE(shirq_ras1_config),
+       .regs = {
+               .enb_reg = INT_ENB_MASK_REG,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS1_MASK,
+               .clear_reg = -1,
+       },
+};
+
+/* spear300 routines */
+void __init spear300_init(void)
+{
+       int ret = 0;
+
+       /* call spear3xx family common init function */
+       spear3xx_init();
+
+       /* shared irq registeration */
+       shirq_ras1.regs.base =
+               ioremap(SPEAR300_TELECOM_BASE, SPEAR300_TELECOM_REG_SIZE);
+       if (shirq_ras1.regs.base) {
+               ret = spear_shirq_register(&shirq_ras1);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ\n");
+       }
+}
+
+void spear300_pmx_init(void)
+{
+       spear_pmx_init(&pmx_driver, SPEAR300_SOC_CONFIG_BASE,
+                       SPEAR300_SOC_CONFIG_SIZE);
+}
diff --git a/arch/arm/mach-spear3xx/spear300_evb.c b/arch/arm/mach-spear3xx/spear300_evb.c
new file mode 100644 (file)
index 0000000..bb21db1
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * arch/arm/mach-spear3xx/spear300_evb.c
+ *
+ * SPEAr300 evaluation board source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* padmux devices to enable */
+static struct pmx_dev *pmx_devs[] = {
+       /* spear3xx specific devices */
+       &pmx_i2c,
+       &pmx_ssp_cs,
+       &pmx_ssp,
+       &pmx_mii,
+       &pmx_uart0,
+
+       /* spear300 specific devices */
+       &pmx_fsmc_2_chips,
+       &pmx_clcd,
+       &pmx_telecom_sdio_4bit,
+       &pmx_gpio1,
+};
+
+static struct amba_device *amba_devs[] __initdata = {
+       /* spear3xx specific devices */
+       &gpio_device,
+       &uart_device,
+
+       /* spear300 specific devices */
+       &gpio1_device,
+};
+
+static struct platform_device *plat_devs[] __initdata = {
+       /* spear3xx specific devices */
+
+       /* spear300 specific devices */
+};
+
+static void __init spear300_evb_init(void)
+{
+       unsigned int i;
+
+       /* call spear300 machine init function */
+       spear300_init();
+
+       /* padmux initialization */
+       pmx_driver.mode = &photo_frame_mode;
+       pmx_driver.devs = pmx_devs;
+       pmx_driver.devs_count = ARRAY_SIZE(pmx_devs);
+       spear300_pmx_init();
+
+       /* Add Platform Devices */
+       platform_add_devices(plat_devs, ARRAY_SIZE(plat_devs));
+
+       /* Add Amba Devices */
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
+               amba_device_register(amba_devs[i], &iomem_resource);
+}
+
+MACHINE_START(SPEAR300, "ST-SPEAR300-EVB")
+       .boot_params    =       0x00000100,
+       .map_io         =       spear3xx_map_io,
+       .init_irq       =       spear3xx_init_irq,
+       .timer          =       &spear_sys_timer,
+       .init_machine   =       spear300_evb_init,
+MACHINE_END
diff --git a/arch/arm/mach-spear3xx/spear310.c b/arch/arm/mach-spear3xx/spear310.c
new file mode 100644 (file)
index 0000000..96a1ab8
--- /dev/null
@@ -0,0 +1,302 @@
+/*
+ * arch/arm/mach-spear3xx/spear310.c
+ *
+ * SPEAr310 machine source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/ptrace.h>
+#include <asm/irq.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+#include <plat/shirq.h>
+
+/* pad multiplexing support */
+/* muxing registers */
+#define PAD_MUX_CONFIG_REG     0x08
+
+/* devices */
+struct pmx_dev_mode pmx_emi_cs_0_1_4_5_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_emi_cs_0_1_4_5 = {
+       .name = "emi_cs_0_1_4_5",
+       .modes = pmx_emi_cs_0_1_4_5_modes,
+       .mode_count = ARRAY_SIZE(pmx_emi_cs_0_1_4_5_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_emi_cs_2_3_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_TIMER_1_2_MASK,
+       },
+};
+
+struct pmx_dev pmx_emi_cs_2_3 = {
+       .name = "emi_cs_2_3",
+       .modes = pmx_emi_cs_2_3_modes,
+       .mode_count = ARRAY_SIZE(pmx_emi_cs_2_3_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart1_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_FIRDA_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart1 = {
+       .name = "uart1",
+       .modes = pmx_uart1_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart2_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_TIMER_1_2_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart2 = {
+       .name = "uart2",
+       .modes = pmx_uart2_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart2_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart3_4_5_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart3_4_5 = {
+       .name = "uart3_4_5",
+       .modes = pmx_uart3_4_5_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart3_4_5_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_fsmc_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_fsmc = {
+       .name = "fsmc",
+       .modes = pmx_fsmc_modes,
+       .mode_count = ARRAY_SIZE(pmx_fsmc_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_rs485_0_1_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_rs485_0_1 = {
+       .name = "rs485_0_1",
+       .modes = pmx_rs485_0_1_modes,
+       .mode_count = ARRAY_SIZE(pmx_rs485_0_1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_tdm0_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_tdm0 = {
+       .name = "tdm0",
+       .modes = pmx_tdm0_modes,
+       .mode_count = ARRAY_SIZE(pmx_tdm0_modes),
+       .enb_on_reset = 1,
+};
+
+/* pmx driver structure */
+struct pmx_driver pmx_driver = {
+       .mux_reg = {.offset = PAD_MUX_CONFIG_REG, .mask = 0x00007fff},
+};
+
+/* Add spear310 specific devices here */
+
+/* spear3xx shared irq */
+struct shirq_dev_config shirq_ras1_config[] = {
+       {
+               .virq = VIRQ_SMII0,
+               .status_mask = SMII0_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SMII1,
+               .status_mask = SMII1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SMII2,
+               .status_mask = SMII2_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SMII3,
+               .status_mask = SMII3_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_SMII0,
+               .status_mask = WAKEUP_SMII0_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_SMII1,
+               .status_mask = WAKEUP_SMII1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_SMII2,
+               .status_mask = WAKEUP_SMII2_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_SMII3,
+               .status_mask = WAKEUP_SMII3_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras1 = {
+       .irq = IRQ_GEN_RAS_1,
+       .dev_config = shirq_ras1_config,
+       .dev_count = ARRAY_SIZE(shirq_ras1_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS1_MASK,
+               .clear_reg = -1,
+       },
+};
+
+struct shirq_dev_config shirq_ras2_config[] = {
+       {
+               .virq = VIRQ_UART1,
+               .status_mask = UART1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART2,
+               .status_mask = UART2_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART3,
+               .status_mask = UART3_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART4,
+               .status_mask = UART4_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART5,
+               .status_mask = UART5_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras2 = {
+       .irq = IRQ_GEN_RAS_2,
+       .dev_config = shirq_ras2_config,
+       .dev_count = ARRAY_SIZE(shirq_ras2_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS2_MASK,
+               .clear_reg = -1,
+       },
+};
+
+struct shirq_dev_config shirq_ras3_config[] = {
+       {
+               .virq = VIRQ_EMI,
+               .status_mask = EMI_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras3 = {
+       .irq = IRQ_GEN_RAS_3,
+       .dev_config = shirq_ras3_config,
+       .dev_count = ARRAY_SIZE(shirq_ras3_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS3_MASK,
+               .clear_reg = -1,
+       },
+};
+
+struct shirq_dev_config shirq_intrcomm_ras_config[] = {
+       {
+               .virq = VIRQ_TDM_HDLC,
+               .status_mask = TDM_HDLC_IRQ_MASK,
+       }, {
+               .virq = VIRQ_RS485_0,
+               .status_mask = RS485_0_IRQ_MASK,
+       }, {
+               .virq = VIRQ_RS485_1,
+               .status_mask = RS485_1_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_intrcomm_ras = {
+       .irq = IRQ_INTRCOMM_RAS_ARM,
+       .dev_config = shirq_intrcomm_ras_config,
+       .dev_count = ARRAY_SIZE(shirq_intrcomm_ras_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_INTRCOMM_RAS_MASK,
+               .clear_reg = -1,
+       },
+};
+
+/* spear310 routines */
+void __init spear310_init(void)
+{
+       void __iomem *base;
+       int ret = 0;
+
+       /* call spear3xx family common init function */
+       spear3xx_init();
+
+       /* shared irq registeration */
+       base = ioremap(SPEAR310_SOC_CONFIG_BASE, SPEAR310_SOC_CONFIG_SIZE);
+       if (base) {
+               /* shirq 1 */
+               shirq_ras1.regs.base = base;
+               ret = spear_shirq_register(&shirq_ras1);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 1\n");
+
+               /* shirq 2 */
+               shirq_ras2.regs.base = base;
+               ret = spear_shirq_register(&shirq_ras2);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 2\n");
+
+               /* shirq 3 */
+               shirq_ras3.regs.base = base;
+               ret = spear_shirq_register(&shirq_ras3);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 3\n");
+
+               /* shirq 4 */
+               shirq_intrcomm_ras.regs.base = base;
+               ret = spear_shirq_register(&shirq_intrcomm_ras);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 4\n");
+       }
+}
+
+void spear310_pmx_init(void)
+{
+       spear_pmx_init(&pmx_driver, SPEAR310_SOC_CONFIG_BASE,
+                       SPEAR310_SOC_CONFIG_SIZE);
+}
diff --git a/arch/arm/mach-spear3xx/spear310_evb.c b/arch/arm/mach-spear3xx/spear310_evb.c
new file mode 100644 (file)
index 0000000..7facf66
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * arch/arm/mach-spear3xx/spear310_evb.c
+ *
+ * SPEAr310 evaluation board source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* padmux devices to enable */
+static struct pmx_dev *pmx_devs[] = {
+       /* spear3xx specific devices */
+       &pmx_i2c,
+       &pmx_ssp,
+       &pmx_gpio_pin0,
+       &pmx_gpio_pin1,
+       &pmx_gpio_pin2,
+       &pmx_gpio_pin3,
+       &pmx_gpio_pin4,
+       &pmx_gpio_pin5,
+       &pmx_uart0,
+
+       /* spear310 specific devices */
+       &pmx_emi_cs_0_1_4_5,
+       &pmx_emi_cs_2_3,
+       &pmx_uart1,
+       &pmx_uart2,
+       &pmx_uart3_4_5,
+       &pmx_fsmc,
+       &pmx_rs485_0_1,
+       &pmx_tdm0,
+};
+
+static struct amba_device *amba_devs[] __initdata = {
+       /* spear3xx specific devices */
+       &gpio_device,
+       &uart_device,
+
+       /* spear310 specific devices */
+};
+
+static struct platform_device *plat_devs[] __initdata = {
+       /* spear3xx specific devices */
+
+       /* spear310 specific devices */
+};
+
+static void __init spear310_evb_init(void)
+{
+       unsigned int i;
+
+       /* call spear310 machine init function */
+       spear310_init();
+
+       /* padmux initialization */
+       pmx_driver.mode = NULL;
+       pmx_driver.devs = pmx_devs;
+       pmx_driver.devs_count = ARRAY_SIZE(pmx_devs);
+       spear310_pmx_init();
+
+       /* Add Platform Devices */
+       platform_add_devices(plat_devs, ARRAY_SIZE(plat_devs));
+
+       /* Add Amba Devices */
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
+               amba_device_register(amba_devs[i], &iomem_resource);
+}
+
+MACHINE_START(SPEAR310, "ST-SPEAR310-EVB")
+       .boot_params    =       0x00000100,
+       .map_io         =       spear3xx_map_io,
+       .init_irq       =       spear3xx_init_irq,
+       .timer          =       &spear_sys_timer,
+       .init_machine   =       spear310_evb_init,
+MACHINE_END
diff --git a/arch/arm/mach-spear3xx/spear320.c b/arch/arm/mach-spear3xx/spear320.c
new file mode 100644 (file)
index 0000000..6a12195
--- /dev/null
@@ -0,0 +1,549 @@
+/*
+ * arch/arm/mach-spear3xx/spear320.c
+ *
+ * SPEAr320 machine source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/ptrace.h>
+#include <asm/irq.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+#include <plat/shirq.h>
+
+/* pad multiplexing support */
+/* muxing registers */
+#define PAD_MUX_CONFIG_REG     0x0C
+#define MODE_CONFIG_REG                0x10
+
+/* modes */
+#define AUTO_NET_SMII_MODE     (1 << 0)
+#define AUTO_NET_MII_MODE      (1 << 1)
+#define AUTO_EXP_MODE          (1 << 2)
+#define SMALL_PRINTERS_MODE    (1 << 3)
+#define ALL_MODES              0xF
+
+struct pmx_mode auto_net_smii_mode = {
+       .id = AUTO_NET_SMII_MODE,
+       .name = "Automation Networking SMII Mode",
+       .mask = 0x00,
+};
+
+struct pmx_mode auto_net_mii_mode = {
+       .id = AUTO_NET_MII_MODE,
+       .name = "Automation Networking MII Mode",
+       .mask = 0x01,
+};
+
+struct pmx_mode auto_exp_mode = {
+       .id = AUTO_EXP_MODE,
+       .name = "Automation Expanded Mode",
+       .mask = 0x02,
+};
+
+struct pmx_mode small_printers_mode = {
+       .id = SMALL_PRINTERS_MODE,
+       .name = "Small Printers Mode",
+       .mask = 0x03,
+};
+
+/* devices */
+struct pmx_dev_mode pmx_clcd_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_clcd = {
+       .name = "clcd",
+       .modes = pmx_clcd_modes,
+       .mode_count = ARRAY_SIZE(pmx_clcd_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_emi_modes[] = {
+       {
+               .ids = AUTO_EXP_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_emi = {
+       .name = "emi",
+       .modes = pmx_emi_modes,
+       .mode_count = ARRAY_SIZE(pmx_emi_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_fsmc_modes[] = {
+       {
+               .ids = ALL_MODES,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_fsmc = {
+       .name = "fsmc",
+       .modes = pmx_fsmc_modes,
+       .mode_count = ARRAY_SIZE(pmx_fsmc_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_spp_modes[] = {
+       {
+               .ids = SMALL_PRINTERS_MODE,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_spp = {
+       .name = "spp",
+       .modes = pmx_spp_modes,
+       .mode_count = ARRAY_SIZE(pmx_spp_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_sdio_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE |
+                       SMALL_PRINTERS_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_sdio = {
+       .name = "sdio",
+       .modes = pmx_sdio_modes,
+       .mode_count = ARRAY_SIZE(pmx_sdio_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_i2s_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE,
+               .mask = PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_i2s = {
+       .name = "i2s",
+       .modes = pmx_i2s_modes,
+       .mode_count = ARRAY_SIZE(pmx_i2s_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart1_modes[] = {
+       {
+               .ids = ALL_MODES,
+               .mask = PMX_GPIO_PIN0_MASK | PMX_GPIO_PIN1_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart1 = {
+       .name = "uart1",
+       .modes = pmx_uart1_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart1_modem_modes[] = {
+       {
+               .ids = AUTO_EXP_MODE,
+               .mask = PMX_TIMER_1_2_MASK | PMX_TIMER_3_4_MASK |
+                       PMX_SSP_CS_MASK,
+       }, {
+               .ids = SMALL_PRINTERS_MODE,
+               .mask = PMX_GPIO_PIN3_MASK | PMX_GPIO_PIN4_MASK |
+                       PMX_GPIO_PIN5_MASK | PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart1_modem = {
+       .name = "uart1_modem",
+       .modes = pmx_uart1_modem_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart1_modem_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_uart2_modes[] = {
+       {
+               .ids = ALL_MODES,
+               .mask = PMX_FIRDA_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart2 = {
+       .name = "uart2",
+       .modes = pmx_uart2_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart2_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_touchscreen_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE,
+               .mask = PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_touchscreen = {
+       .name = "touchscreen",
+       .modes = pmx_touchscreen_modes,
+       .mode_count = ARRAY_SIZE(pmx_touchscreen_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_can_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE | AUTO_EXP_MODE,
+               .mask = PMX_GPIO_PIN2_MASK | PMX_GPIO_PIN3_MASK |
+                       PMX_GPIO_PIN4_MASK | PMX_GPIO_PIN5_MASK,
+       },
+};
+
+struct pmx_dev pmx_can = {
+       .name = "can",
+       .modes = pmx_can_modes,
+       .mode_count = ARRAY_SIZE(pmx_can_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_sdio_led_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE,
+               .mask = PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_sdio_led = {
+       .name = "sdio_led",
+       .modes = pmx_sdio_led_modes,
+       .mode_count = ARRAY_SIZE(pmx_sdio_led_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_pwm0_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE,
+               .mask = PMX_UART0_MODEM_MASK,
+       }, {
+               .ids = AUTO_EXP_MODE | SMALL_PRINTERS_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_pwm0 = {
+       .name = "pwm0",
+       .modes = pmx_pwm0_modes,
+       .mode_count = ARRAY_SIZE(pmx_pwm0_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_pwm1_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE,
+               .mask = PMX_UART0_MODEM_MASK,
+       }, {
+               .ids = AUTO_EXP_MODE | SMALL_PRINTERS_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_pwm1 = {
+       .name = "pwm1",
+       .modes = pmx_pwm1_modes,
+       .mode_count = ARRAY_SIZE(pmx_pwm1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_pwm2_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_NET_MII_MODE,
+               .mask = PMX_SSP_CS_MASK,
+       }, {
+               .ids = AUTO_EXP_MODE | SMALL_PRINTERS_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_pwm2 = {
+       .name = "pwm2",
+       .modes = pmx_pwm2_modes,
+       .mode_count = ARRAY_SIZE(pmx_pwm2_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_pwm3_modes[] = {
+       {
+               .ids = AUTO_EXP_MODE | SMALL_PRINTERS_MODE | AUTO_NET_SMII_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_pwm3 = {
+       .name = "pwm3",
+       .modes = pmx_pwm3_modes,
+       .mode_count = ARRAY_SIZE(pmx_pwm3_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_ssp1_modes[] = {
+       {
+               .ids = SMALL_PRINTERS_MODE | AUTO_NET_SMII_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_ssp1 = {
+       .name = "ssp1",
+       .modes = pmx_ssp1_modes,
+       .mode_count = ARRAY_SIZE(pmx_ssp1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_ssp2_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_ssp2 = {
+       .name = "ssp2",
+       .modes = pmx_ssp2_modes,
+       .mode_count = ARRAY_SIZE(pmx_ssp2_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_mii1_modes[] = {
+       {
+               .ids = AUTO_NET_MII_MODE,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_mii1 = {
+       .name = "mii1",
+       .modes = pmx_mii1_modes,
+       .mode_count = ARRAY_SIZE(pmx_mii1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_smii0_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | AUTO_EXP_MODE | SMALL_PRINTERS_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_smii0 = {
+       .name = "smii0",
+       .modes = pmx_smii0_modes,
+       .mode_count = ARRAY_SIZE(pmx_smii0_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_smii1_modes[] = {
+       {
+               .ids = AUTO_NET_SMII_MODE | SMALL_PRINTERS_MODE,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_smii1 = {
+       .name = "smii1",
+       .modes = pmx_smii1_modes,
+       .mode_count = ARRAY_SIZE(pmx_smii1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_i2c1_modes[] = {
+       {
+               .ids = AUTO_EXP_MODE,
+               .mask = 0x0,
+       },
+};
+
+struct pmx_dev pmx_i2c1 = {
+       .name = "i2c1",
+       .modes = pmx_i2c1_modes,
+       .mode_count = ARRAY_SIZE(pmx_i2c1_modes),
+       .enb_on_reset = 1,
+};
+
+/* pmx driver structure */
+struct pmx_driver pmx_driver = {
+       .mode_reg = {.offset = MODE_CONFIG_REG, .mask = 0x00000007},
+       .mux_reg = {.offset = PAD_MUX_CONFIG_REG, .mask = 0x00007fff},
+};
+
+/* Add spear320 specific devices here */
+
+/* spear3xx shared irq */
+struct shirq_dev_config shirq_ras1_config[] = {
+       {
+               .virq = VIRQ_EMI,
+               .status_mask = EMI_IRQ_MASK,
+               .clear_mask = EMI_IRQ_MASK,
+       }, {
+               .virq = VIRQ_CLCD,
+               .status_mask = CLCD_IRQ_MASK,
+               .clear_mask = CLCD_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SPP,
+               .status_mask = SPP_IRQ_MASK,
+               .clear_mask = SPP_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras1 = {
+       .irq = IRQ_GEN_RAS_1,
+       .dev_config = shirq_ras1_config,
+       .dev_count = ARRAY_SIZE(shirq_ras1_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS1_MASK,
+               .clear_reg = INT_CLR_MASK_REG,
+               .reset_to_clear = 1,
+       },
+};
+
+struct shirq_dev_config shirq_ras3_config[] = {
+       {
+               .virq = VIRQ_PLGPIO,
+               .enb_mask = GPIO_IRQ_MASK,
+               .status_mask = GPIO_IRQ_MASK,
+               .clear_mask = GPIO_IRQ_MASK,
+       }, {
+               .virq = VIRQ_I2S_PLAY,
+               .enb_mask = I2S_PLAY_IRQ_MASK,
+               .status_mask = I2S_PLAY_IRQ_MASK,
+               .clear_mask = I2S_PLAY_IRQ_MASK,
+       }, {
+               .virq = VIRQ_I2S_REC,
+               .enb_mask = I2S_REC_IRQ_MASK,
+               .status_mask = I2S_REC_IRQ_MASK,
+               .clear_mask = I2S_REC_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_ras3 = {
+       .irq = IRQ_GEN_RAS_3,
+       .dev_config = shirq_ras3_config,
+       .dev_count = ARRAY_SIZE(shirq_ras3_config),
+       .regs = {
+               .enb_reg = INT_ENB_MASK_REG,
+               .reset_to_enb = 1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_RAS3_MASK,
+               .clear_reg = INT_CLR_MASK_REG,
+               .reset_to_clear = 1,
+       },
+};
+
+struct shirq_dev_config shirq_intrcomm_ras_config[] = {
+       {
+               .virq = VIRQ_CANU,
+               .status_mask = CAN_U_IRQ_MASK,
+               .clear_mask = CAN_U_IRQ_MASK,
+       }, {
+               .virq = VIRQ_CANL,
+               .status_mask = CAN_L_IRQ_MASK,
+               .clear_mask = CAN_L_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART1,
+               .status_mask = UART1_IRQ_MASK,
+               .clear_mask = UART1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_UART2,
+               .status_mask = UART2_IRQ_MASK,
+               .clear_mask = UART2_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SSP1,
+               .status_mask = SSP1_IRQ_MASK,
+               .clear_mask = SSP1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SSP2,
+               .status_mask = SSP2_IRQ_MASK,
+               .clear_mask = SSP2_IRQ_MASK,
+       }, {
+               .virq = VIRQ_SMII0,
+               .status_mask = SMII0_IRQ_MASK,
+               .clear_mask = SMII0_IRQ_MASK,
+       }, {
+               .virq = VIRQ_MII1_SMII1,
+               .status_mask = MII1_SMII1_IRQ_MASK,
+               .clear_mask = MII1_SMII1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_SMII0,
+               .status_mask = WAKEUP_SMII0_IRQ_MASK,
+               .clear_mask = WAKEUP_SMII0_IRQ_MASK,
+       }, {
+               .virq = VIRQ_WAKEUP_MII1_SMII1,
+               .status_mask = WAKEUP_MII1_SMII1_IRQ_MASK,
+               .clear_mask = WAKEUP_MII1_SMII1_IRQ_MASK,
+       }, {
+               .virq = VIRQ_I2C,
+               .status_mask = I2C1_IRQ_MASK,
+               .clear_mask = I2C1_IRQ_MASK,
+       },
+};
+
+struct spear_shirq shirq_intrcomm_ras = {
+       .irq = IRQ_INTRCOMM_RAS_ARM,
+       .dev_config = shirq_intrcomm_ras_config,
+       .dev_count = ARRAY_SIZE(shirq_intrcomm_ras_config),
+       .regs = {
+               .enb_reg = -1,
+               .status_reg = INT_STS_MASK_REG,
+               .status_reg_mask = SHIRQ_INTRCOMM_RAS_MASK,
+               .clear_reg = INT_CLR_MASK_REG,
+               .reset_to_clear = 1,
+       },
+};
+
+/* spear320 routines */
+void __init spear320_init(void)
+{
+       void __iomem *base;
+       int ret = 0;
+
+       /* call spear3xx family common init function */
+       spear3xx_init();
+
+       /* shared irq registeration */
+       base = ioremap(SPEAR320_SOC_CONFIG_BASE, SPEAR320_SOC_CONFIG_SIZE);
+       if (base) {
+               /* shirq 1 */
+               shirq_ras1.regs.base = base;
+               ret = spear_shirq_register(&shirq_ras1);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 1\n");
+
+               /* shirq 3 */
+               shirq_ras3.regs.base = base;
+               ret = spear_shirq_register(&shirq_ras3);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 3\n");
+
+               /* shirq 4 */
+               shirq_intrcomm_ras.regs.base = base;
+               ret = spear_shirq_register(&shirq_intrcomm_ras);
+               if (ret)
+                       printk(KERN_ERR "Error registering Shared IRQ 4\n");
+       }
+}
+
+void spear320_pmx_init(void)
+{
+       spear_pmx_init(&pmx_driver, SPEAR320_SOC_CONFIG_BASE,
+                       SPEAR320_SOC_CONFIG_SIZE);
+}
diff --git a/arch/arm/mach-spear3xx/spear320_evb.c b/arch/arm/mach-spear3xx/spear320_evb.c
new file mode 100644 (file)
index 0000000..62ac685
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * arch/arm/mach-spear3xx/spear320_evb.c
+ *
+ * SPEAr320 evaluation board source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* padmux devices to enable */
+static struct pmx_dev *pmx_devs[] = {
+       /* spear3xx specific devices */
+       &pmx_i2c,
+       &pmx_ssp,
+       &pmx_mii,
+       &pmx_uart0,
+
+       /* spear320 specific devices */
+       &pmx_fsmc,
+       &pmx_sdio,
+       &pmx_i2s,
+       &pmx_uart1,
+       &pmx_uart2,
+       &pmx_can,
+       &pmx_pwm0,
+       &pmx_pwm1,
+       &pmx_pwm2,
+       &pmx_mii1,
+};
+
+static struct amba_device *amba_devs[] __initdata = {
+       /* spear3xx specific devices */
+       &gpio_device,
+       &uart_device,
+
+       /* spear320 specific devices */
+};
+
+static struct platform_device *plat_devs[] __initdata = {
+       /* spear3xx specific devices */
+
+       /* spear320 specific devices */
+};
+
+static void __init spear320_evb_init(void)
+{
+       unsigned int i;
+
+       /* call spear320 machine init function */
+       spear320_init();
+
+       /* padmux initialization */
+       pmx_driver.mode = &auto_net_mii_mode;
+       pmx_driver.devs = pmx_devs;
+       pmx_driver.devs_count = ARRAY_SIZE(pmx_devs);
+       spear320_pmx_init();
+
+       /* Add Platform Devices */
+       platform_add_devices(plat_devs, ARRAY_SIZE(plat_devs));
+
+       /* Add Amba Devices */
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
+               amba_device_register(amba_devs[i], &iomem_resource);
+}
+
+MACHINE_START(SPEAR320, "ST-SPEAR320-EVB")
+       .boot_params    =       0x00000100,
+       .map_io         =       spear3xx_map_io,
+       .init_irq       =       spear3xx_init_irq,
+       .timer          =       &spear_sys_timer,
+       .init_machine   =       spear320_evb_init,
+MACHINE_END
diff --git a/arch/arm/mach-spear3xx/spear3xx.c b/arch/arm/mach-spear3xx/spear3xx.c
new file mode 100644 (file)
index 0000000..e87313a
--- /dev/null
@@ -0,0 +1,548 @@
+/*
+ * arch/arm/mach-spear3xx/spear3xx.c
+ *
+ * SPEAr3XX machines common source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/types.h>
+#include <linux/amba/pl061.h>
+#include <linux/ptrace.h>
+#include <linux/io.h>
+#include <asm/hardware/vic.h>
+#include <asm/irq.h>
+#include <asm/mach/arch.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* Add spear3xx machines common devices here */
+/* gpio device registeration */
+static struct pl061_platform_data gpio_plat_data = {
+       .gpio_base      = 0,
+       .irq_base       = SPEAR_GPIO_INT_BASE,
+};
+
+struct amba_device gpio_device = {
+       .dev = {
+               .init_name = "gpio",
+               .platform_data = &gpio_plat_data,
+       },
+       .res = {
+               .start = SPEAR3XX_ICM3_GPIO_BASE,
+               .end = SPEAR3XX_ICM3_GPIO_BASE + SPEAR3XX_ICM3_GPIO_SIZE - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       .irq = {IRQ_BASIC_GPIO, NO_IRQ},
+};
+
+/* uart device registeration */
+struct amba_device uart_device = {
+       .dev = {
+               .init_name = "uart",
+       },
+       .res = {
+               .start = SPEAR3XX_ICM1_UART_BASE,
+               .end = SPEAR3XX_ICM1_UART_BASE + SPEAR3XX_ICM1_UART_SIZE - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       .irq = {IRQ_UART, NO_IRQ},
+};
+
+/* Do spear3xx familiy common initialization part here */
+void __init spear3xx_init(void)
+{
+       /* nothing to do for now */
+}
+
+/* This will initialize vic */
+void __init spear3xx_init_irq(void)
+{
+       vic_init((void __iomem *)VA_SPEAR3XX_ML1_VIC_BASE, 0, ~0, 0);
+}
+
+/* Following will create static virtual/physical mappings */
+struct map_desc spear3xx_io_desc[] __initdata = {
+       {
+               .virtual        = VA_SPEAR3XX_ICM1_UART_BASE,
+               .pfn            = __phys_to_pfn(SPEAR3XX_ICM1_UART_BASE),
+               .length         = SPEAR3XX_ICM1_UART_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR3XX_ML1_VIC_BASE,
+               .pfn            = __phys_to_pfn(SPEAR3XX_ML1_VIC_BASE),
+               .length         = SPEAR3XX_ML1_VIC_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR3XX_ICM3_SYS_CTRL_BASE,
+               .pfn            = __phys_to_pfn(SPEAR3XX_ICM3_SYS_CTRL_BASE),
+               .length         = SPEAR3XX_ICM3_SYS_CTRL_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR3XX_ICM3_MISC_REG_BASE,
+               .pfn            = __phys_to_pfn(SPEAR3XX_ICM3_MISC_REG_BASE),
+               .length         = SPEAR3XX_ICM3_MISC_REG_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+/* This will create static memory mapping for selected devices */
+void __init spear3xx_map_io(void)
+{
+       iotable_init(spear3xx_io_desc, ARRAY_SIZE(spear3xx_io_desc));
+
+       /* This will initialize clock framework */
+       clk_init();
+}
+
+/* pad multiplexing support */
+/* devices */
+struct pmx_dev_mode pmx_firda_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_FIRDA_MASK,
+       },
+};
+
+struct pmx_dev pmx_firda = {
+       .name = "firda",
+       .modes = pmx_firda_modes,
+       .mode_count = ARRAY_SIZE(pmx_firda_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_i2c_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_I2C_MASK,
+       },
+};
+
+struct pmx_dev pmx_i2c = {
+       .name = "i2c",
+       .modes = pmx_i2c_modes,
+       .mode_count = ARRAY_SIZE(pmx_i2c_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_ssp_cs_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_ssp_cs = {
+       .name = "ssp_chip_selects",
+       .modes = pmx_ssp_cs_modes,
+       .mode_count = ARRAY_SIZE(pmx_ssp_cs_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_ssp_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_SSP_MASK,
+       },
+};
+
+struct pmx_dev pmx_ssp = {
+       .name = "ssp",
+       .modes = pmx_ssp_modes,
+       .mode_count = ARRAY_SIZE(pmx_ssp_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_mii_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_mii = {
+       .name = "mii",
+       .modes = pmx_mii_modes,
+       .mode_count = ARRAY_SIZE(pmx_mii_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin0_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN0_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin0 = {
+       .name = "gpio_pin0",
+       .modes = pmx_gpio_pin0_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin0_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin1_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN1_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin1 = {
+       .name = "gpio_pin1",
+       .modes = pmx_gpio_pin1_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin1_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin2_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN2_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin2 = {
+       .name = "gpio_pin2",
+       .modes = pmx_gpio_pin2_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin2_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin3_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN3_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin3 = {
+       .name = "gpio_pin3",
+       .modes = pmx_gpio_pin3_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin3_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin4_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN4_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin4 = {
+       .name = "gpio_pin4",
+       .modes = pmx_gpio_pin4_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin4_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_gpio_pin5_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_GPIO_PIN5_MASK,
+       },
+};
+
+struct pmx_dev pmx_gpio_pin5 = {
+       .name = "gpio_pin5",
+       .modes = pmx_gpio_pin5_modes,
+       .mode_count = ARRAY_SIZE(pmx_gpio_pin5_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_uart0_modem_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart0_modem = {
+       .name = "uart0_modem",
+       .modes = pmx_uart0_modem_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart0_modem_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_uart0_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_UART0_MASK,
+       },
+};
+
+struct pmx_dev pmx_uart0 = {
+       .name = "uart0",
+       .modes = pmx_uart0_modes,
+       .mode_count = ARRAY_SIZE(pmx_uart0_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_timer_3_4_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_timer_3_4 = {
+       .name = "timer_3_4",
+       .modes = pmx_timer_3_4_modes,
+       .mode_count = ARRAY_SIZE(pmx_timer_3_4_modes),
+       .enb_on_reset = 0,
+};
+
+struct pmx_dev_mode pmx_timer_1_2_modes[] = {
+       {
+               .ids = 0xffffffff,
+               .mask = PMX_TIMER_1_2_MASK,
+       },
+};
+
+struct pmx_dev pmx_timer_1_2 = {
+       .name = "timer_1_2",
+       .modes = pmx_timer_1_2_modes,
+       .mode_count = ARRAY_SIZE(pmx_timer_1_2_modes),
+       .enb_on_reset = 0,
+};
+
+#if defined(CONFIG_MACH_SPEAR310) || defined(CONFIG_MACH_SPEAR320)
+/* plgpios devices */
+struct pmx_dev_mode pmx_plgpio_0_1_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_FIRDA_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_0_1 = {
+       .name = "plgpio 0 and 1",
+       .modes = pmx_plgpio_0_1_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_0_1_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_2_3_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_UART0_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_2_3 = {
+       .name = "plgpio 2 and 3",
+       .modes = pmx_plgpio_2_3_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_2_3_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_4_5_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_I2C_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_4_5 = {
+       .name = "plgpio 4 and 5",
+       .modes = pmx_plgpio_4_5_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_4_5_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_6_9_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_SSP_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_6_9 = {
+       .name = "plgpio 6 to 9",
+       .modes = pmx_plgpio_6_9_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_6_9_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_10_27_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_MII_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_10_27 = {
+       .name = "plgpio 10 to 27",
+       .modes = pmx_plgpio_10_27_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_10_27_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_28_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN0_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_28 = {
+       .name = "plgpio 28",
+       .modes = pmx_plgpio_28_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_28_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_29_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN1_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_29 = {
+       .name = "plgpio 29",
+       .modes = pmx_plgpio_29_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_29_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_30_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN2_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_30 = {
+       .name = "plgpio 30",
+       .modes = pmx_plgpio_30_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_30_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_31_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN3_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_31 = {
+       .name = "plgpio 31",
+       .modes = pmx_plgpio_31_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_31_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_32_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN4_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_32 = {
+       .name = "plgpio 32",
+       .modes = pmx_plgpio_32_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_32_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_33_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_GPIO_PIN5_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_33 = {
+       .name = "plgpio 33",
+       .modes = pmx_plgpio_33_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_33_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_34_36_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_SSP_CS_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_34_36 = {
+       .name = "plgpio 34 to 36",
+       .modes = pmx_plgpio_34_36_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_34_36_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_37_42_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_UART0_MODEM_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_37_42 = {
+       .name = "plgpio 37 to 42",
+       .modes = pmx_plgpio_37_42_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_37_42_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_43_44_47_48_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_TIMER_1_2_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_43_44_47_48 = {
+       .name = "plgpio 43, 44, 47 and 48",
+       .modes = pmx_plgpio_43_44_47_48_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_43_44_47_48_modes),
+       .enb_on_reset = 1,
+};
+
+struct pmx_dev_mode pmx_plgpio_45_46_49_50_modes[] = {
+       {
+               .ids = 0x00,
+               .mask = PMX_TIMER_3_4_MASK,
+       },
+};
+
+struct pmx_dev pmx_plgpio_45_46_49_50 = {
+       .name = "plgpio 45, 46, 49 and 50",
+       .modes = pmx_plgpio_45_46_49_50_modes,
+       .mode_count = ARRAY_SIZE(pmx_plgpio_45_46_49_50_modes),
+       .enb_on_reset = 1,
+};
+
+#endif
+
+/* spear padmux initialization function */
+void spear_pmx_init(struct pmx_driver *pmx_driver, uint base, uint size)
+{
+       int ret = 0;
+
+       /* pad mux initialization */
+       pmx_driver->base = ioremap(base, size);
+       if (!pmx_driver->base) {
+               ret = -ENOMEM;
+               goto pmx_fail;
+       }
+
+       ret = pmx_register(pmx_driver);
+       iounmap(pmx_driver->base);
+
+pmx_fail:
+       if (ret)
+               printk(KERN_ERR "padmux: registeration failed. err no: %d\n",
+                               ret);
+}
diff --git a/arch/arm/mach-spear6xx/Kconfig b/arch/arm/mach-spear6xx/Kconfig
new file mode 100644 (file)
index 0000000..bddba03
--- /dev/null
@@ -0,0 +1,20 @@
+#
+# SPEAr6XX Machine configuration file
+#
+
+if ARCH_SPEAR6XX
+
+choice
+       prompt "SPEAr6XX Family"
+       default MACH_SPEAR600
+
+config MACH_SPEAR600
+       bool "SPEAr600"
+       help
+         Supports ST SPEAr600 Machine
+endchoice
+
+# Adding SPEAr6XX machine specific configuration files
+source "arch/arm/mach-spear6xx/Kconfig600"
+
+endif #ARCH_SPEAR6XX
diff --git a/arch/arm/mach-spear6xx/Kconfig600 b/arch/arm/mach-spear6xx/Kconfig600
new file mode 100644 (file)
index 0000000..9e19f65
--- /dev/null
@@ -0,0 +1,17 @@
+#
+# SPEAr600 machine configuration file
+#
+
+if MACH_SPEAR600
+
+choice
+       prompt "SPEAr600 Boards"
+       default BOARD_SPEAR600_EVB
+
+config BOARD_SPEAR600_EVB
+       bool "SPEAr600 Evaluation Board"
+       help
+         Supports ST SPEAr600 Evaluation Board
+endchoice
+
+endif  #MACH_SPEAR600
diff --git a/arch/arm/mach-spear6xx/Makefile b/arch/arm/mach-spear6xx/Makefile
new file mode 100644 (file)
index 0000000..cc1a4d8
--- /dev/null
@@ -0,0 +1,12 @@
+#
+# Makefile for SPEAr6XX machine series
+#
+
+# common files
+obj-y  += clock.o spear6xx.o
+
+# spear600 specific files
+obj-$(CONFIG_MACH_SPEAR600) += spear600.o
+
+# spear600 boards files
+obj-$(CONFIG_BOARD_SPEAR600_EVB) += spear600_evb.o
diff --git a/arch/arm/mach-spear6xx/Makefile.boot b/arch/arm/mach-spear6xx/Makefile.boot
new file mode 100644 (file)
index 0000000..7a1f3c0
--- /dev/null
@@ -0,0 +1,3 @@
+zreladdr-y     := 0x00008000
+params_phys-y  := 0x00000100
+initrd_phys-y  := 0x00800000
diff --git a/arch/arm/mach-spear6xx/clock.c b/arch/arm/mach-spear6xx/clock.c
new file mode 100644 (file)
index 0000000..13e27c7
--- /dev/null
@@ -0,0 +1,483 @@
+/*
+ * arch/arm/mach-spear6xx/clock.c
+ *
+ * SPEAr6xx machines clock framework source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <mach/misc_regs.h>
+#include <plat/clock.h>
+
+/* root clks */
+/* 32 KHz oscillator clock */
+static struct clk osc_32k_clk = {
+       .flags = ALWAYS_ENABLED,
+       .rate = 32000,
+};
+
+/* 30 MHz oscillator clock */
+static struct clk osc_30m_clk = {
+       .flags = ALWAYS_ENABLED,
+       .rate = 30000000,
+};
+
+/* clock derived from 32 KHz osc clk */
+/* rtc clock */
+static struct clk rtc_clk = {
+       .pclk = &osc_32k_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = RTC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from 30 MHz osc clk */
+/* pll1 configuration structure */
+static struct pll_clk_config pll1_config = {
+       .mode_reg = PLL1_CTR,
+       .cfg_reg = PLL1_FRQ,
+};
+
+/* PLL1 clock */
+static struct clk pll1_clk = {
+       .pclk = &osc_30m_clk,
+       .en_reg = PLL1_CTR,
+       .en_reg_bit = PLL_ENABLE,
+       .recalc = &pll1_clk_recalc,
+       .private_data = &pll1_config,
+};
+
+/* PLL3 48 MHz clock */
+static struct clk pll3_48m_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &osc_30m_clk,
+       .rate = 48000000,
+};
+
+/* watch dog timer clock */
+static struct clk wdt_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &osc_30m_clk,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from pll1 clk */
+/* cpu clock */
+static struct clk cpu_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &pll1_clk,
+       .recalc = &follow_parent,
+};
+
+/* ahb configuration structure */
+static struct bus_clk_config ahb_config = {
+       .reg = CORE_CLK_CFG,
+       .mask = PLL_HCLK_RATIO_MASK,
+       .shift = PLL_HCLK_RATIO_SHIFT,
+};
+
+/* ahb clock */
+static struct clk ahb_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &pll1_clk,
+       .recalc = &bus_clk_recalc,
+       .private_data = &ahb_config,
+};
+
+/* uart parents */
+static struct pclk_info uart_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* uart parent select structure */
+static struct pclk_sel uart_pclk_sel = {
+       .pclk_info = uart_pclk_info,
+       .pclk_count = ARRAY_SIZE(uart_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = UART_CLK_MASK,
+};
+
+/* uart configurations */
+static struct aux_clk_config uart_config = {
+       .synth_reg = UART_CLK_SYNT,
+};
+
+/* uart0 clock */
+static struct clk uart0_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = UART0_CLK_ENB,
+       .pclk_sel = &uart_pclk_sel,
+       .pclk_sel_shift = UART_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &uart_config,
+};
+
+/* uart1 clock */
+static struct clk uart1_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = UART1_CLK_ENB,
+       .pclk_sel = &uart_pclk_sel,
+       .pclk_sel_shift = UART_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &uart_config,
+};
+
+/* firda configurations */
+static struct aux_clk_config firda_config = {
+       .synth_reg = FIRDA_CLK_SYNT,
+};
+
+/* firda parents */
+static struct pclk_info firda_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* firda parent select structure */
+static struct pclk_sel firda_pclk_sel = {
+       .pclk_info = firda_pclk_info,
+       .pclk_count = ARRAY_SIZE(firda_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = FIRDA_CLK_MASK,
+};
+
+/* firda clock */
+static struct clk firda_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = FIRDA_CLK_ENB,
+       .pclk_sel = &firda_pclk_sel,
+       .pclk_sel_shift = FIRDA_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &firda_config,
+};
+
+/* clcd configurations */
+static struct aux_clk_config clcd_config = {
+       .synth_reg = CLCD_CLK_SYNT,
+};
+
+/* clcd parents */
+static struct pclk_info clcd_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* clcd parent select structure */
+static struct pclk_sel clcd_pclk_sel = {
+       .pclk_info = clcd_pclk_info,
+       .pclk_count = ARRAY_SIZE(clcd_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = CLCD_CLK_MASK,
+};
+
+/* clcd clock */
+static struct clk clcd_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = CLCD_CLK_ENB,
+       .pclk_sel = &clcd_pclk_sel,
+       .pclk_sel_shift = CLCD_CLK_SHIFT,
+       .recalc = &aux_clk_recalc,
+       .private_data = &clcd_config,
+};
+
+/* gpt parents */
+static struct pclk_info gpt_pclk_info[] = {
+       {
+               .pclk = &pll1_clk,
+               .pclk_mask = AUX_CLK_PLL1_MASK,
+               .scalable = 1,
+       }, {
+               .pclk = &pll3_48m_clk,
+               .pclk_mask = AUX_CLK_PLL3_MASK,
+               .scalable = 0,
+       },
+};
+
+/* gpt parent select structure */
+static struct pclk_sel gpt_pclk_sel = {
+       .pclk_info = gpt_pclk_info,
+       .pclk_count = ARRAY_SIZE(gpt_pclk_info),
+       .pclk_sel_reg = PERIP_CLK_CFG,
+       .pclk_sel_mask = GPT_CLK_MASK,
+};
+
+/* gpt0_1 configurations */
+static struct aux_clk_config gpt0_1_config = {
+       .synth_reg = PRSC1_CLK_CFG,
+};
+
+/* gpt0 ARM1 subsystem timer clock */
+static struct clk gpt0_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT0_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt0_1_config,
+};
+
+/* gpt1 timer clock */
+static struct clk gpt1_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT1_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt0_1_config,
+};
+
+/* gpt2 configurations */
+static struct aux_clk_config gpt2_config = {
+       .synth_reg = PRSC2_CLK_CFG,
+};
+
+/* gpt2 timer clock */
+static struct clk gpt2_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPT2_CLK_ENB,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT2_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt2_config,
+};
+
+/* gpt3 configurations */
+static struct aux_clk_config gpt3_config = {
+       .synth_reg = PRSC3_CLK_CFG,
+};
+
+/* gpt3 timer clock */
+static struct clk gpt3_clk = {
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPT3_CLK_ENB,
+       .pclk_sel = &gpt_pclk_sel,
+       .pclk_sel_shift = GPT3_CLK_SHIFT,
+       .recalc = &gpt_clk_recalc,
+       .private_data = &gpt3_config,
+};
+
+/* clock derived from pll3 clk */
+/* usbh0 clock */
+static struct clk usbh0_clk = {
+       .pclk = &pll3_48m_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = USBH0_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* usbh1 clock */
+static struct clk usbh1_clk = {
+       .pclk = &pll3_48m_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = USBH1_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* usbd clock */
+static struct clk usbd_clk = {
+       .pclk = &pll3_48m_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = USBD_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from ahb clk */
+/* apb configuration structure */
+static struct bus_clk_config apb_config = {
+       .reg = CORE_CLK_CFG,
+       .mask = HCLK_PCLK_RATIO_MASK,
+       .shift = HCLK_PCLK_RATIO_SHIFT,
+};
+
+/* apb clock */
+static struct clk apb_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &ahb_clk,
+       .recalc = &bus_clk_recalc,
+       .private_data = &apb_config,
+};
+
+/* i2c clock */
+static struct clk i2c_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = I2C_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* dma clock */
+static struct clk dma_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = DMA_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* jpeg clock */
+static struct clk jpeg_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = JPEG_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* gmac clock */
+static struct clk gmac_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GMAC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* smi clock */
+static struct clk smi_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SMI_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* fsmc clock */
+static struct clk fsmc_clk = {
+       .pclk = &ahb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = FSMC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* clock derived from apb clk */
+/* adc clock */
+static struct clk adc_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = ADC_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* ssp0 clock */
+static struct clk ssp0_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SSP0_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* ssp1 clock */
+static struct clk ssp1_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SSP1_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* ssp2 clock */
+static struct clk ssp2_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = SSP2_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* gpio0 ARM subsystem clock */
+static struct clk gpio0_clk = {
+       .flags = ALWAYS_ENABLED,
+       .pclk = &apb_clk,
+       .recalc = &follow_parent,
+};
+
+/* gpio1 clock */
+static struct clk gpio1_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPIO1_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* gpio2 clock */
+static struct clk gpio2_clk = {
+       .pclk = &apb_clk,
+       .en_reg = PERIP1_CLK_ENB,
+       .en_reg_bit = GPIO2_CLK_ENB,
+       .recalc = &follow_parent,
+};
+
+/* array of all spear 6xx clock lookups */
+static struct clk_lookup spear_clk_lookups[] = {
+       /* root clks */
+       { .con_id = "osc_32k_clk",      .clk = &osc_32k_clk},
+       { .con_id = "osc_30m_clk",      .clk = &osc_30m_clk},
+       /* clock derived from 32 KHz os          clk */
+       { .dev_id = "rtc",              .clk = &rtc_clk},
+       /* clock derived from 30 MHz os          clk */
+       { .con_id = "pll1_clk",         .clk = &pll1_clk},
+       { .con_id = "pll3_48m_clk",     .clk = &pll3_48m_clk},
+       { .dev_id = "wdt",              .clk = &wdt_clk},
+       /* clock derived from pll1 clk */
+       { .con_id = "cpu_clk",          .clk = &cpu_clk},
+       { .con_id = "ahb_clk",          .clk = &ahb_clk},
+       { .dev_id = "uart0",            .clk = &uart0_clk},
+       { .dev_id = "uart1",            .clk = &uart1_clk},
+       { .dev_id = "firda",            .clk = &firda_clk},
+       { .dev_id = "clcd",             .clk = &clcd_clk},
+       { .dev_id = "gpt0",             .clk = &gpt0_clk},
+       { .dev_id = "gpt1",             .clk = &gpt1_clk},
+       { .dev_id = "gpt2",             .clk = &gpt2_clk},
+       { .dev_id = "gpt3",             .clk = &gpt3_clk},
+       /* clock derived from pll3 clk */
+       { .dev_id = "usbh0",            .clk = &usbh0_clk},
+       { .dev_id = "usbh1",            .clk = &usbh1_clk},
+       { .dev_id = "usbd",             .clk = &usbd_clk},
+       /* clock derived from ahb clk */
+       { .con_id = "apb_clk",          .clk = &apb_clk},
+       { .dev_id = "i2c",              .clk = &i2c_clk},
+       { .dev_id = "dma",              .clk = &dma_clk},
+       { .dev_id = "jpeg",             .clk = &jpeg_clk},
+       { .dev_id = "gmac",             .clk = &gmac_clk},
+       { .dev_id = "smi",              .clk = &smi_clk},
+       { .dev_id = "fsmc",             .clk = &fsmc_clk},
+       /* clock derived from apb clk */
+       { .dev_id = "adc",              .clk = &adc_clk},
+       { .dev_id = "ssp0",             .clk = &ssp0_clk},
+       { .dev_id = "ssp1",             .clk = &ssp1_clk},
+       { .dev_id = "ssp2",             .clk = &ssp2_clk},
+       { .dev_id = "gpio0",            .clk = &gpio0_clk},
+       { .dev_id = "gpio1",            .clk = &gpio1_clk},
+       { .dev_id = "gpio2",            .clk = &gpio2_clk},
+};
+
+void __init clk_init(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(spear_clk_lookups); i++)
+               clk_register(&spear_clk_lookups[i]);
+
+       recalc_root_clocks();
+}
diff --git a/arch/arm/mach-spear6xx/include/mach/clkdev.h b/arch/arm/mach-spear6xx/include/mach/clkdev.h
new file mode 100644 (file)
index 0000000..05676bf
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/clkdev.h
+ *
+ * Clock Dev framework definitions for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_CLKDEV_H
+#define __MACH_CLKDEV_H
+
+#include <plat/clkdev.h>
+
+#endif /* __MACH_CLKDEV_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/debug-macro.S b/arch/arm/mach-spear6xx/include/mach/debug-macro.S
new file mode 100644 (file)
index 0000000..0f3ea39
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/debug-macro.S
+ *
+ * Debugging macro include header for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <plat/debug-macro.S>
diff --git a/arch/arm/mach-spear6xx/include/mach/entry-macro.S b/arch/arm/mach-spear6xx/include/mach/entry-macro.S
new file mode 100644 (file)
index 0000000..9eaecae
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/entry-macro.S
+ *
+ * Low-level IRQ helper macros for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <mach/hardware.h>
+#include <mach/spear.h>
+#include <asm/hardware/vic.h>
+
+               .macro  disable_fiq
+               .endm
+
+               .macro  get_irqnr_preamble, base, tmp
+               .endm
+
+               .macro  arch_ret_to_user, tmp1, tmp2
+               .endm
+
+               .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+               ldr     \base, =VA_SPEAR6XX_CPU_VIC_PRI_BASE
+               ldr     \irqstat, [\base, #VIC_IRQ_STATUS]      @ get status
+               mov     \irqnr, #0
+               teq     \irqstat, #0
+               bne     1001f
+               ldr     \base, =VA_SPEAR6XX_CPU_VIC_SEC_BASE
+               ldr     \irqstat, [\base, #VIC_IRQ_STATUS]      @ get status
+               teq     \irqstat, #0
+               beq     1002f                           @ this will set/reset
+                                                       @ zero register
+               mov     \irqnr, #32
+1001:
+               /*
+                * Following code will find bit position of least significang
+                * bit set in irqstat, using following equation
+                * least significant bit set in n = (n & ~(n-1))
+                */
+               sub     \tmp, \irqstat, #1              @ tmp = irqstat - 1
+               mvn     \tmp, \tmp                      @ tmp = ~tmp
+               and     \irqstat, \irqstat, \tmp        @ irqstat &= tmp
+               /* Now, irqstat is = bit no. of 1st bit set in vic irq status */
+               clz     \tmp, \irqstat                  @ tmp = leading zeros
+
+               rsb     \tmp, \tmp, #0x1F               @ tmp = 32 - tmp - 1
+               add     \irqnr, \irqnr, \tmp
+
+1002:          /* EQ will be set if no irqs pending */
+               .endm
diff --git a/arch/arm/mach-spear6xx/include/mach/generic.h b/arch/arm/mach-spear6xx/include/mach/generic.h
new file mode 100644 (file)
index 0000000..16205a5
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/generic.h
+ *
+ * SPEAr6XX machine family specific generic header file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_GENERIC_H
+#define __MACH_GENERIC_H
+
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+
+/*
+ * Each GPT has 2 timer channels
+ * Following GPT channels will be used as clock source and clockevent
+ */
+#define SPEAR_GPT0_BASE                SPEAR6XX_CPU_TMR_BASE
+#define SPEAR_GPT0_CHAN0_IRQ   IRQ_CPU_GPT1_1
+#define SPEAR_GPT0_CHAN1_IRQ   IRQ_CPU_GPT1_2
+
+/* Add spear6xx family device structure declarations here */
+extern struct amba_device gpio_device[];
+extern struct amba_device uart_device[];
+extern struct sys_timer spear_sys_timer;
+
+/* Add spear6xx family function declarations here */
+void __init spear6xx_map_io(void);
+void __init spear6xx_init_irq(void);
+void __init spear6xx_init(void);
+void __init spear600_init(void);
+void __init clk_init(void);
+
+/* Add spear600 machine device structure declarations here */
+
+#endif /* __MACH_GENERIC_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/gpio.h b/arch/arm/mach-spear6xx/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..3a789db
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/gpio.h
+ *
+ * GPIO macros for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_GPIO_H
+#define __MACH_GPIO_H
+
+#include <plat/gpio.h>
+
+#endif /* __MACH_GPIO_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/hardware.h b/arch/arm/mach-spear6xx/include/mach/hardware.h
new file mode 100644 (file)
index 0000000..7545116
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/hardware.h
+ *
+ * Hardware definitions for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_HARDWARE_H
+#define __MACH_HARDWARE_H
+
+/* Vitual to physical translation of statically mapped space */
+#define IO_ADDRESS(x)          (x | 0xF0000000)
+
+#endif /* __MACH_HARDWARE_H */
+
diff --git a/arch/arm/mach-spear6xx/include/mach/io.h b/arch/arm/mach-spear6xx/include/mach/io.h
new file mode 100644 (file)
index 0000000..fb7c106
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/io.h
+ *
+ * IO definitions for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_IO_H
+#define __MACH_IO_H
+
+#include <plat/io.h>
+
+#endif /* __MACH_IO_H */
+
diff --git a/arch/arm/mach-spear6xx/include/mach/irqs.h b/arch/arm/mach-spear6xx/include/mach/irqs.h
new file mode 100644 (file)
index 0000000..8f214b0
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/irqs.h
+ *
+ * IRQ helper macros for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_IRQS_H
+#define __MACH_IRQS_H
+
+/* IRQ definitions */
+/* VIC 1 */
+#define IRQ_INTRCOMM_SW_IRQ                    0
+#define IRQ_INTRCOMM_CPU_1                     1
+#define IRQ_INTRCOMM_CPU_2                     2
+#define IRQ_INTRCOMM_RAS2A11_1                 3
+#define IRQ_INTRCOMM_RAS2A11_2                 4
+#define IRQ_INTRCOMM_RAS2A12_1                 5
+#define IRQ_INTRCOMM_RAS2A12_2                 6
+#define IRQ_GEN_RAS_0                          7
+#define IRQ_GEN_RAS_1                          8
+#define IRQ_GEN_RAS_2                          9
+#define IRQ_GEN_RAS_3                          10
+#define IRQ_GEN_RAS_4                          11
+#define IRQ_GEN_RAS_5                          12
+#define IRQ_GEN_RAS_6                          13
+#define IRQ_GEN_RAS_7                          14
+#define IRQ_GEN_RAS_8                          15
+#define IRQ_CPU_GPT1_1                         16
+#define IRQ_CPU_GPT1_2                         17
+#define IRQ_LOCAL_GPIO                         18
+#define IRQ_PLL_UNLOCK                         19
+#define IRQ_JPEG                               20
+#define IRQ_FSMC                               21
+#define IRQ_IRDA                               22
+#define IRQ_RESERVED                           23
+#define IRQ_UART_0                             24
+#define IRQ_UART_1                             25
+#define IRQ_SSP_1                              26
+#define IRQ_SSP_2                              27
+#define IRQ_I2C                                        28
+#define IRQ_GEN_RAS_9                          29
+#define IRQ_GEN_RAS_10                         30
+#define IRQ_GEN_RAS_11                         31
+
+/* VIC 2 */
+#define IRQ_APPL_GPT1_1                                32
+#define IRQ_APPL_GPT1_2                                33
+#define IRQ_APPL_GPT2_1                                34
+#define IRQ_APPL_GPT2_2                                35
+#define IRQ_APPL_GPIO                          36
+#define IRQ_APPL_SSP                           37
+#define IRQ_APPL_ADC                           38
+#define IRQ_APPL_RESERVED                      39
+#define IRQ_AHB_EXP_MASTER                     40
+#define IRQ_DDR_CONTROLLER                     41
+#define IRQ_BASIC_DMA                          42
+#define IRQ_BASIC_RESERVED1                    43
+#define IRQ_BASIC_SMI                          44
+#define IRQ_BASIC_CLCD                         45
+#define IRQ_EXP_AHB_1                          46
+#define IRQ_EXP_AHB_2                          47
+#define IRQ_BASIC_GPT1_1                       48
+#define IRQ_BASIC_GPT1_2                       49
+#define IRQ_BASIC_RTC                          50
+#define IRQ_BASIC_GPIO                         51
+#define IRQ_BASIC_WDT                          52
+#define IRQ_BASIC_RESERVED                     53
+#define IRQ_AHB_EXP_SLAVE                      54
+#define IRQ_GMAC_1                             55
+#define IRQ_GMAC_2                             56
+#define IRQ_USB_DEV                            57
+#define IRQ_USB_H_OHCI_0                       58
+#define IRQ_USB_H_EHCI_0                       59
+#define IRQ_USB_H_OHCI_1                       60
+#define IRQ_USB_H_EHCI_1                       61
+#define IRQ_EXP_AHB_3                          62
+#define IRQ_EXP_AHB_4                          63
+
+#define IRQ_VIC_END                            64
+
+/* GPIO pins virtual irqs */
+#define SPEAR_GPIO_INT_BASE    IRQ_VIC_END
+#define SPEAR_GPIO0_INT_BASE   SPEAR_GPIO_INT_BASE
+#define SPEAR_GPIO1_INT_BASE   (SPEAR_GPIO0_INT_BASE + 8)
+#define SPEAR_GPIO2_INT_BASE   (SPEAR_GPIO1_INT_BASE + 8)
+#define SPEAR_GPIO_INT_END     (SPEAR_GPIO2_INT_BASE + 8)
+#define VIRTUAL_IRQS           (SPEAR_GPIO_INT_END - IRQ_VIC_END)
+#define NR_IRQS                        (IRQ_VIC_END + VIRTUAL_IRQS)
+
+#endif /* __MACH_IRQS_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/memory.h b/arch/arm/mach-spear6xx/include/mach/memory.h
new file mode 100644 (file)
index 0000000..781f088
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/memory.h
+ *
+ * Memory map for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MEMORY_H
+#define __MACH_MEMORY_H
+
+#include <plat/memory.h>
+
+#endif /* __MACH_MEMORY_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/misc_regs.h b/arch/arm/mach-spear6xx/include/mach/misc_regs.h
new file mode 100644 (file)
index 0000000..0390803
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/misc_regs.h
+ *
+ * Miscellaneous registers definitions for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_MISC_REGS_H
+#define __MACH_MISC_REGS_H
+
+#include <mach/spear.h>
+
+#define MISC_BASE              VA_SPEAR6XX_ICM3_MISC_REG_BASE
+
+#define SOC_CFG_CTR            ((unsigned int *)(MISC_BASE + 0x000))
+#define DIAG_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x004))
+#define PLL1_CTR               ((unsigned int *)(MISC_BASE + 0x008))
+#define PLL1_FRQ               ((unsigned int *)(MISC_BASE + 0x00C))
+#define PLL1_MOD               ((unsigned int *)(MISC_BASE + 0x010))
+#define PLL2_CTR               ((unsigned int *)(MISC_BASE + 0x014))
+/* PLL_CTR register masks */
+#define PLL_ENABLE             2
+#define PLL_MODE_SHIFT         4
+#define PLL_MODE_MASK          0x3
+#define PLL_MODE_NORMAL                0
+#define PLL_MODE_FRACTION      1
+#define PLL_MODE_DITH_DSB      2
+#define PLL_MODE_DITH_SSB      3
+
+#define PLL2_FRQ               ((unsigned int *)(MISC_BASE + 0x018))
+/* PLL FRQ register masks */
+#define PLL_DIV_N_SHIFT                0
+#define PLL_DIV_N_MASK         0xFF
+#define PLL_DIV_P_SHIFT                8
+#define PLL_DIV_P_MASK         0x7
+#define PLL_NORM_FDBK_M_SHIFT  24
+#define PLL_NORM_FDBK_M_MASK   0xFF
+#define PLL_DITH_FDBK_M_SHIFT  16
+#define PLL_DITH_FDBK_M_MASK   0xFFFF
+
+#define PLL2_MOD               ((unsigned int *)(MISC_BASE + 0x01C))
+#define PLL_CLK_CFG            ((unsigned int *)(MISC_BASE + 0x020))
+#define CORE_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x024))
+/* CORE CLK CFG register masks */
+#define PLL_HCLK_RATIO_SHIFT   10
+#define PLL_HCLK_RATIO_MASK    0x3
+#define HCLK_PCLK_RATIO_SHIFT  8
+#define HCLK_PCLK_RATIO_MASK   0x3
+
+#define PERIP_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x028))
+/* PERIP_CLK_CFG register masks */
+#define CLCD_CLK_SHIFT         2
+#define CLCD_CLK_MASK          0x3
+#define UART_CLK_SHIFT         4
+#define UART_CLK_MASK          0x1
+#define FIRDA_CLK_SHIFT                5
+#define FIRDA_CLK_MASK         0x3
+#define GPT0_CLK_SHIFT         8
+#define GPT1_CLK_SHIFT         10
+#define GPT2_CLK_SHIFT         11
+#define GPT3_CLK_SHIFT         12
+#define GPT_CLK_MASK           0x1
+#define AUX_CLK_PLL3_MASK      0
+#define AUX_CLK_PLL1_MASK      1
+
+#define PERIP1_CLK_ENB         ((unsigned int *)(MISC_BASE + 0x02C))
+/* PERIP1_CLK_ENB register masks */
+#define UART0_CLK_ENB          3
+#define UART1_CLK_ENB          4
+#define SSP0_CLK_ENB           5
+#define SSP1_CLK_ENB           6
+#define I2C_CLK_ENB            7
+#define JPEG_CLK_ENB           8
+#define FSMC_CLK_ENB           9
+#define FIRDA_CLK_ENB          10
+#define GPT2_CLK_ENB           11
+#define GPT3_CLK_ENB           12
+#define GPIO2_CLK_ENB          13
+#define SSP2_CLK_ENB           14
+#define ADC_CLK_ENB            15
+#define GPT1_CLK_ENB           11
+#define RTC_CLK_ENB            17
+#define GPIO1_CLK_ENB          18
+#define DMA_CLK_ENB            19
+#define SMI_CLK_ENB            21
+#define CLCD_CLK_ENB           22
+#define GMAC_CLK_ENB           23
+#define USBD_CLK_ENB           24
+#define USBH0_CLK_ENB          25
+#define USBH1_CLK_ENB          26
+
+#define SOC_CORE_ID            ((unsigned int *)(MISC_BASE + 0x030))
+#define RAS_CLK_ENB            ((unsigned int *)(MISC_BASE + 0x034))
+#define PERIP1_SOF_RST         ((unsigned int *)(MISC_BASE + 0x038))
+/* PERIP1_SOF_RST register masks */
+#define JPEG_SOF_RST           8
+
+#define SOC_USER_ID            ((unsigned int *)(MISC_BASE + 0x03C))
+#define RAS_SOF_RST            ((unsigned int *)(MISC_BASE + 0x040))
+#define PRSC1_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x044))
+#define PRSC2_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x048))
+#define PRSC3_CLK_CFG          ((unsigned int *)(MISC_BASE + 0x04C))
+/* gpt synthesizer register masks */
+#define GPT_MSCALE_SHIFT       0
+#define GPT_MSCALE_MASK                0xFFF
+#define GPT_NSCALE_SHIFT       12
+#define GPT_NSCALE_MASK                0xF
+
+#define AMEM_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x050))
+#define EXPI_CLK_CFG           ((unsigned int *)(MISC_BASE + 0x054))
+#define CLCD_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x05C))
+#define FIRDA_CLK_SYNT         ((unsigned int *)(MISC_BASE + 0x060))
+#define UART_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x064))
+#define GMAC_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x068))
+#define RAS1_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x06C))
+#define RAS2_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x070))
+#define RAS3_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x074))
+#define RAS4_CLK_SYNT          ((unsigned int *)(MISC_BASE + 0x078))
+/* aux clk synthesiser register masks for irda to ras4 */
+#define AUX_EQ_SEL_SHIFT       30
+#define AUX_EQ_SEL_MASK                1
+#define AUX_EQ1_SEL            0
+#define AUX_EQ2_SEL            1
+#define AUX_XSCALE_SHIFT       16
+#define AUX_XSCALE_MASK                0xFFF
+#define AUX_YSCALE_SHIFT       0
+#define AUX_YSCALE_MASK                0xFFF
+
+#define ICM1_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x07C))
+#define ICM2_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x080))
+#define ICM3_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x084))
+#define ICM4_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x088))
+#define ICM5_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x08C))
+#define ICM6_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x090))
+#define ICM7_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x094))
+#define ICM8_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x098))
+#define ICM9_ARB_CFG           ((unsigned int *)(MISC_BASE + 0x09C))
+#define DMA_CHN_CFG            ((unsigned int *)(MISC_BASE + 0x0A0))
+#define USB2_PHY_CFG           ((unsigned int *)(MISC_BASE + 0x0A4))
+#define GMAC_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x0A8))
+#define EXPI_CFG_CTR           ((unsigned int *)(MISC_BASE + 0x0AC))
+#define PRC1_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C0))
+#define PRC2_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C4))
+#define PRC3_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0C8))
+#define PRC4_LOCK_CTR          ((unsigned int *)(MISC_BASE + 0x0CC))
+#define PRC1_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D0))
+#define PRC2_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D4))
+#define PRC3_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0D8))
+#define PRC4_IRQ_CTR           ((unsigned int *)(MISC_BASE + 0x0DC))
+#define PWRDOWN_CFG_CTR                ((unsigned int *)(MISC_BASE + 0x0E0))
+#define COMPSSTL_1V8_CFG       ((unsigned int *)(MISC_BASE + 0x0E4))
+#define COMPSSTL_2V5_CFG       ((unsigned int *)(MISC_BASE + 0x0E8))
+#define COMPCOR_3V3_CFG                ((unsigned int *)(MISC_BASE + 0x0EC))
+#define SSTLPAD_CFG_CTR                ((unsigned int *)(MISC_BASE + 0x0F0))
+#define BIST1_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0F4))
+#define BIST2_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0F8))
+#define BIST3_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x0FC))
+#define BIST4_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x100))
+#define BIST5_CFG_CTR          ((unsigned int *)(MISC_BASE + 0x104))
+#define BIST1_STS_RES          ((unsigned int *)(MISC_BASE + 0x108))
+#define BIST2_STS_RES          ((unsigned int *)(MISC_BASE + 0x10C))
+#define BIST3_STS_RES          ((unsigned int *)(MISC_BASE + 0x110))
+#define BIST4_STS_RES          ((unsigned int *)(MISC_BASE + 0x114))
+#define BIST5_STS_RES          ((unsigned int *)(MISC_BASE + 0x118))
+#define SYSERR_CFG_CTR         ((unsigned int *)(MISC_BASE + 0x11C))
+
+#endif /* __MACH_MISC_REGS_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/spear.h b/arch/arm/mach-spear6xx/include/mach/spear.h
new file mode 100644 (file)
index 0000000..a835f5b
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/spear.h
+ *
+ * SPEAr6xx Machine family specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_SPEAR6XX_H
+#define __MACH_SPEAR6XX_H
+
+#include <mach/hardware.h>
+#include <mach/spear600.h>
+
+#define SPEAR6XX_ML_SDRAM_BASE         0x00000000
+#define SPEAR6XX_ML_SDRAM_SIZE         0x40000000
+
+/* ICM1 - Low speed connection */
+#define SPEAR6XX_ICM1_BASE             0xD0000000
+#define SPEAR6XX_ICM1_SIZE             0x08000000
+
+#define SPEAR6XX_ICM1_UART0_BASE       0xD0000000
+#define VA_SPEAR6XX_ICM1_UART0_BASE    IO_ADDRESS(SPEAR6XX_ICM1_UART0_BASE)
+#define SPEAR6XX_ICM1_UART0_SIZE       0x00080000
+
+#define SPEAR6XX_ICM1_UART1_BASE       0xD0080000
+#define SPEAR6XX_ICM1_UART1_SIZE       0x00080000
+
+#define SPEAR6XX_ICM1_SSP0_BASE                0xD0100000
+#define SPEAR6XX_ICM1_SSP0_SIZE                0x00080000
+
+#define SPEAR6XX_ICM1_SSP1_BASE                0xD0180000
+#define SPEAR6XX_ICM1_SSP1_SIZE                0x00080000
+
+#define SPEAR6XX_ICM1_I2C_BASE         0xD0200000
+#define SPEAR6XX_ICM1_I2C_SIZE         0x00080000
+
+#define SPEAR6XX_ICM1_JPEG_BASE                0xD0800000
+#define SPEAR6XX_ICM1_JPEG_SIZE                0x00800000
+
+#define SPEAR6XX_ICM1_IRDA_BASE                0xD1000000
+#define SPEAR6XX_ICM1_IRDA_SIZE                0x00800000
+
+#define SPEAR6XX_ICM1_FSMC_BASE                0xD1800000
+#define SPEAR6XX_ICM1_FSMC_SIZE                0x00800000
+
+#define SPEAR6XX_ICM1_NAND_BASE                0xD2000000
+#define SPEAR6XX_ICM1_NAND_SIZE                0x00800000
+
+#define SPEAR6XX_ICM1_SRAM_BASE                0xD2800000
+#define SPEAR6XX_ICM1_SRAM_SIZE                0x00800000
+
+/* ICM2 - Application Subsystem */
+#define SPEAR6XX_ICM2_BASE             0xD8000000
+#define SPEAR6XX_ICM2_SIZE             0x08000000
+
+#define SPEAR6XX_ICM2_TMR0_BASE                0xD8000000
+#define SPEAR6XX_ICM2_TMR0_SIZE                0x00080000
+
+#define SPEAR6XX_ICM2_TMR1_BASE                0xD8080000
+#define SPEAR6XX_ICM2_TMR1_SIZE                0x00080000
+
+#define SPEAR6XX_ICM2_GPIO_BASE                0xD8100000
+#define SPEAR6XX_ICM2_GPIO_SIZE                0x00080000
+
+#define SPEAR6XX_ICM2_SPI2_BASE                0xD8180000
+#define SPEAR6XX_ICM2_SPI2_SIZE                0x00080000
+
+#define SPEAR6XX_ICM2_ADC_BASE         0xD8200000
+#define SPEAR6XX_ICM2_ADC_SIZE         0x00080000
+
+/* ML-1, 2 - Multi Layer CPU Subsystem */
+#define SPEAR6XX_ML_CPU_BASE           0xF0000000
+#define SPEAR6XX_ML_CPU_SIZE           0x08000000
+
+#define SPEAR6XX_CPU_TMR_BASE          0xF0000000
+#define SPEAR6XX_CPU_TMR_SIZE          0x00100000
+
+#define SPEAR6XX_CPU_GPIO_BASE         0xF0100000
+#define SPEAR6XX_CPU_GPIO_SIZE         0x00100000
+
+#define SPEAR6XX_CPU_VIC_SEC_BASE      0xF1000000
+#define VA_SPEAR6XX_CPU_VIC_SEC_BASE   IO_ADDRESS(SPEAR6XX_CPU_VIC_SEC_BASE)
+#define SPEAR6XX_CPU_VIC_SEC_SIZE      0x00100000
+
+#define SPEAR6XX_CPU_VIC_PRI_BASE      0xF1100000
+#define VA_SPEAR6XX_CPU_VIC_PRI_BASE   IO_ADDRESS(SPEAR6XX_CPU_VIC_PRI_BASE)
+#define SPEAR6XX_CPU_VIC_PRI_SIZE      0x00100000
+
+/* ICM3 - Basic Subsystem */
+#define SPEAR6XX_ICM3_BASE             0xF8000000
+#define SPEAR6XX_ICM3_SIZE             0x08000000
+
+#define SPEAR6XX_ICM3_SMEM_BASE                0xF8000000
+#define SPEAR6XX_ICM3_SMEM_SIZE                0x04000000
+
+#define SPEAR6XX_ICM3_SMI_CTRL_BASE    0xFC000000
+#define SPEAR6XX_ICM3_SMI_CTRL_SIZE    0x00200000
+
+#define SPEAR6XX_ICM3_CLCD_BASE                0xFC200000
+#define SPEAR6XX_ICM3_CLCD_SIZE                0x00200000
+
+#define SPEAR6XX_ICM3_DMA_BASE         0xFC400000
+#define SPEAR6XX_ICM3_DMA_SIZE         0x00200000
+
+#define SPEAR6XX_ICM3_SDRAM_CTRL_BASE  0xFC600000
+#define SPEAR6XX_ICM3_SDRAM_CTRL_SIZE  0x00200000
+
+#define SPEAR6XX_ICM3_TMR_BASE         0xFC800000
+#define SPEAR6XX_ICM3_TMR_SIZE         0x00080000
+
+#define SPEAR6XX_ICM3_WDT_BASE         0xFC880000
+#define SPEAR6XX_ICM3_WDT_SIZE         0x00080000
+
+#define SPEAR6XX_ICM3_RTC_BASE         0xFC900000
+#define SPEAR6XX_ICM3_RTC_SIZE         0x00080000
+
+#define SPEAR6XX_ICM3_GPIO_BASE                0xFC980000
+#define SPEAR6XX_ICM3_GPIO_SIZE                0x00080000
+
+#define SPEAR6XX_ICM3_SYS_CTRL_BASE    0xFCA00000
+#define VA_SPEAR6XX_ICM3_SYS_CTRL_BASE IO_ADDRESS(SPEAR6XX_ICM3_SYS_CTRL_BASE)
+#define SPEAR6XX_ICM3_SYS_CTRL_SIZE    0x00080000
+
+#define SPEAR6XX_ICM3_MISC_REG_BASE    0xFCA80000
+#define VA_SPEAR6XX_ICM3_MISC_REG_BASE IO_ADDRESS(SPEAR6XX_ICM3_MISC_REG_BASE)
+#define SPEAR6XX_ICM3_MISC_REG_SIZE    0x00080000
+
+/* ICM4 - High Speed Connection */
+#define SPEAR6XX_ICM4_BASE             0xE0000000
+#define SPEAR6XX_ICM4_SIZE             0x08000000
+
+#define SPEAR6XX_ICM4_GMAC_BASE                0xE0800000
+#define SPEAR6XX_ICM4_GMAC_SIZE                0x00800000
+
+#define SPEAR6XX_ICM4_USBD_FIFO_BASE   0xE1000000
+#define SPEAR6XX_ICM4_USBD_FIFO_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USBD_CSR_BASE    0xE1100000
+#define SPEAR6XX_ICM4_USBD_CSR_SIZE    0x00100000
+
+#define SPEAR6XX_ICM4_USBD_PLDT_BASE   0xE1200000
+#define SPEAR6XX_ICM4_USBD_PLDT_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USB_EHCI0_BASE   0xE1800000
+#define SPEAR6XX_ICM4_USB_EHCI0_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USB_OHCI0_BASE   0xE1900000
+#define SPEAR6XX_ICM4_USB_OHCI0_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USB_EHCI1_BASE   0xE2000000
+#define SPEAR6XX_ICM4_USB_EHCI1_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USB_OHCI1_BASE   0xE2100000
+#define SPEAR6XX_ICM4_USB_OHCI1_SIZE   0x00100000
+
+#define SPEAR6XX_ICM4_USB_ARB_BASE     0xE2800000
+#define SPEAR6XX_ICM4_USB_ARB_SIZE     0x00010000
+
+/* Debug uart for linux, will be used for debug and uncompress messages */
+#define SPEAR_DBG_UART_BASE            SPEAR6XX_ICM1_UART0_BASE
+#define VA_SPEAR_DBG_UART_BASE         VA_SPEAR6XX_ICM1_UART0_BASE
+
+/* Sysctl base for spear platform */
+#define SPEAR_SYS_CTRL_BASE            SPEAR6XX_ICM3_SYS_CTRL_BASE
+#define VA_SPEAR_SYS_CTRL_BASE         VA_SPEAR6XX_ICM3_SYS_CTRL_BASE
+
+#endif /* __MACH_SPEAR6XX_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/spear600.h b/arch/arm/mach-spear6xx/include/mach/spear600.h
new file mode 100644 (file)
index 0000000..c068cc5
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * arch/arm/mach-spear66xx/include/mach/spear600.h
+ *
+ * SPEAr600 Machine specific definition
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifdef CONFIG_MACH_SPEAR600
+
+#ifndef __MACH_SPEAR600_H
+#define __MACH_SPEAR600_H
+
+#endif /* __MACH_SPEAR600_H */
+
+#endif /* CONFIG_MACH_SPEAR600 */
diff --git a/arch/arm/mach-spear6xx/include/mach/system.h b/arch/arm/mach-spear6xx/include/mach/system.h
new file mode 100644 (file)
index 0000000..0b1d2be
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/system.h
+ *
+ * SPEAr6xx Machine family specific architecture functions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_SYSTEM_H
+#define __MACH_SYSTEM_H
+
+#include <plat/system.h>
+
+#endif /* __MACH_SYSTEM_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/timex.h b/arch/arm/mach-spear6xx/include/mach/timex.h
new file mode 100644 (file)
index 0000000..ac1c5b0
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/timex.h
+ *
+ * SPEAr6XX machine family specific timex definitions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_TIMEX_H
+#define __MACH_TIMEX_H
+
+#include <plat/timex.h>
+
+#endif /* __MACH_TIMEX_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/uncompress.h b/arch/arm/mach-spear6xx/include/mach/uncompress.h
new file mode 100644 (file)
index 0000000..77f0765
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/uncompress.h
+ *
+ * Serial port stubs for kernel decompress status messages
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_UNCOMPRESS_H
+#define __MACH_UNCOMPRESS_H
+
+#include <plat/uncompress.h>
+
+#endif /* __MACH_UNCOMPRESS_H */
diff --git a/arch/arm/mach-spear6xx/include/mach/vmalloc.h b/arch/arm/mach-spear6xx/include/mach/vmalloc.h
new file mode 100644 (file)
index 0000000..4a0b56c
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/mach-spear6xx/include/mach/vmalloc.h
+ *
+ * Defining Vmalloc area for SPEAr6xx machine family
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_VMALLOC_H
+#define __MACH_VMALLOC_H
+
+#include <plat/vmalloc.h>
+
+#endif /* __MACH_VMALLOC_H */
diff --git a/arch/arm/mach-spear6xx/spear600.c b/arch/arm/mach-spear6xx/spear600.c
new file mode 100644 (file)
index 0000000..5c484c4
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * arch/arm/mach-spear6xx/spear600.c
+ *
+ * SPEAr600 machine source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/ptrace.h>
+#include <asm/irq.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* Add spear600 specific devices here */
+
+void __init spear600_init(void)
+{
+       /* call spear6xx family common init function */
+       spear6xx_init();
+}
diff --git a/arch/arm/mach-spear6xx/spear600_evb.c b/arch/arm/mach-spear6xx/spear600_evb.c
new file mode 100644 (file)
index 0000000..daff8d0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * arch/arm/mach-spear6xx/spear600_evb.c
+ *
+ * SPEAr600 evaluation board source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+static struct amba_device *amba_devs[] __initdata = {
+       &gpio_device[0],
+       &gpio_device[1],
+       &gpio_device[2],
+       &uart_device[0],
+       &uart_device[1],
+};
+
+static struct platform_device *plat_devs[] __initdata = {
+};
+
+static void __init spear600_evb_init(void)
+{
+       unsigned int i;
+
+       /* call spear600 machine init function */
+       spear600_init();
+
+       /* Add Platform Devices */
+       platform_add_devices(plat_devs, ARRAY_SIZE(plat_devs));
+
+       /* Add Amba Devices */
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
+               amba_device_register(amba_devs[i], &iomem_resource);
+}
+
+MACHINE_START(SPEAR600, "ST-SPEAR600-EVB")
+       .boot_params    =       0x00000100,
+       .map_io         =       spear6xx_map_io,
+       .init_irq       =       spear6xx_init_irq,
+       .timer          =       &spear_sys_timer,
+       .init_machine   =       spear600_evb_init,
+MACHINE_END
diff --git a/arch/arm/mach-spear6xx/spear6xx.c b/arch/arm/mach-spear6xx/spear6xx.c
new file mode 100644 (file)
index 0000000..b67e571
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * arch/arm/mach-spear6xx/spear6xx.c
+ *
+ * SPEAr6XX machines common source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Rajeev Kumar<rajeev-dlh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/types.h>
+#include <linux/amba/pl061.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/io.h>
+#include <asm/hardware/vic.h>
+#include <asm/irq.h>
+#include <asm/mach/arch.h>
+#include <mach/irqs.h>
+#include <mach/generic.h>
+#include <mach/spear.h>
+
+/* Add spear6xx machines common devices here */
+/* uart device registeration */
+struct amba_device uart_device[] = {
+       {
+               .dev = {
+                       .init_name = "uart0",
+               },
+               .res = {
+                       .start = SPEAR6XX_ICM1_UART0_BASE,
+                       .end = SPEAR6XX_ICM1_UART0_BASE +
+                               SPEAR6XX_ICM1_UART0_SIZE - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irq = {IRQ_UART_0, NO_IRQ},
+       }, {
+               .dev = {
+                       .init_name = "uart1",
+               },
+               .res = {
+                       .start = SPEAR6XX_ICM1_UART1_BASE,
+                       .end = SPEAR6XX_ICM1_UART1_BASE +
+                               SPEAR6XX_ICM1_UART1_SIZE - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irq = {IRQ_UART_1, NO_IRQ},
+       }
+};
+
+/* gpio device registeration */
+static struct pl061_platform_data gpio_plat_data[] = {
+       {
+               .gpio_base      = 0,
+               .irq_base       = SPEAR_GPIO0_INT_BASE,
+       }, {
+               .gpio_base      = 8,
+               .irq_base       = SPEAR_GPIO1_INT_BASE,
+       }, {
+               .gpio_base      = 16,
+               .irq_base       = SPEAR_GPIO2_INT_BASE,
+       },
+};
+
+struct amba_device gpio_device[] = {
+       {
+               .dev = {
+                       .init_name = "gpio0",
+                       .platform_data = &gpio_plat_data[0],
+               },
+               .res = {
+                       .start = SPEAR6XX_CPU_GPIO_BASE,
+                       .end = SPEAR6XX_CPU_GPIO_BASE +
+                               SPEAR6XX_CPU_GPIO_SIZE - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irq = {IRQ_LOCAL_GPIO, NO_IRQ},
+       }, {
+               .dev = {
+                       .init_name = "gpio1",
+                       .platform_data = &gpio_plat_data[1],
+               },
+               .res = {
+                       .start = SPEAR6XX_ICM3_GPIO_BASE,
+                       .end = SPEAR6XX_ICM3_GPIO_BASE +
+                               SPEAR6XX_ICM3_GPIO_SIZE - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irq = {IRQ_BASIC_GPIO, NO_IRQ},
+       }, {
+               .dev = {
+                       .init_name = "gpio2",
+                       .platform_data = &gpio_plat_data[2],
+               },
+               .res = {
+                       .start = SPEAR6XX_ICM2_GPIO_BASE,
+                       .end = SPEAR6XX_ICM2_GPIO_BASE +
+                               SPEAR6XX_ICM2_GPIO_SIZE - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irq = {IRQ_APPL_GPIO, NO_IRQ},
+       }
+};
+
+/* This will add devices, and do machine specific tasks */
+void __init spear6xx_init(void)
+{
+       /* nothing to do for now */
+}
+
+/* This will initialize vic */
+void __init spear6xx_init_irq(void)
+{
+       vic_init((void __iomem *)VA_SPEAR6XX_CPU_VIC_PRI_BASE, 0, ~0, 0);
+       vic_init((void __iomem *)VA_SPEAR6XX_CPU_VIC_SEC_BASE, 32, ~0, 0);
+}
+
+/* Following will create static virtual/physical mappings */
+static struct map_desc spear6xx_io_desc[] __initdata = {
+       {
+               .virtual        = VA_SPEAR6XX_ICM1_UART0_BASE,
+               .pfn            = __phys_to_pfn(SPEAR6XX_ICM1_UART0_BASE),
+               .length         = SPEAR6XX_ICM1_UART0_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR6XX_CPU_VIC_PRI_BASE,
+               .pfn            = __phys_to_pfn(SPEAR6XX_CPU_VIC_PRI_BASE),
+               .length         = SPEAR6XX_CPU_VIC_PRI_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR6XX_CPU_VIC_SEC_BASE,
+               .pfn            = __phys_to_pfn(SPEAR6XX_CPU_VIC_SEC_BASE),
+               .length         = SPEAR6XX_CPU_VIC_SEC_SIZE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR6XX_ICM3_SYS_CTRL_BASE,
+               .pfn            = __phys_to_pfn(SPEAR6XX_ICM3_SYS_CTRL_BASE),
+               .length         = SPEAR6XX_ICM3_MISC_REG_BASE,
+               .type           = MT_DEVICE
+       }, {
+               .virtual        = VA_SPEAR6XX_ICM3_MISC_REG_BASE,
+               .pfn            = __phys_to_pfn(SPEAR6XX_ICM3_MISC_REG_BASE),
+               .length         = SPEAR6XX_ICM3_MISC_REG_SIZE,
+               .type           = MT_DEVICE
+       },
+};
+
+/* This will create static memory mapping for selected devices */
+void __init spear6xx_map_io(void)
+{
+       iotable_init(spear6xx_io_desc, ARRAY_SIZE(spear6xx_io_desc));
+
+       /* This will initialize clock framework */
+       clk_init();
+}
index 77fbb1e..88506d0 100644 (file)
@@ -102,11 +102,12 @@ int __devinit mmc_init(struct amba_device *adev)
         * we have a regulator we can control instead.
         */
        /* Nominally 2.85V on our platform */
+       mmci_card->mmc0_plat_data.f_max = 24000000;
        mmci_card->mmc0_plat_data.status = mmc_status;
        mmci_card->mmc0_plat_data.gpio_wp = -1;
        mmci_card->mmc0_plat_data.gpio_cd = -1;
        mmci_card->mmc0_plat_data.capabilities = MMC_CAP_MMC_HIGHSPEED |
-               MMC_CAP_SD_HIGHSPEED | MMC_CAP_4_BIT_DATA;
+               MMC_CAP_SD_HIGHSPEED | MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA;
 
        mmcsd_device->platform_data = (void *) &mmci_card->mmc0_plat_data;
 
index 03625d7..6625e5b 100644 (file)
@@ -1,15 +1,42 @@
-menu "ST-Ericsson platform type"
-       depends on ARCH_U8500
+if ARCH_U8500
 
-comment "ST-Ericsson Multicore Mobile Platforms"
-
-config MACH_U8500_MOP
-       bool "U8500 Early Development platform"
+config UX500_SOC_COMMON
+       bool
        default y
        select ARM_GIC
        select HAS_MTU
+       select NOMADIK_GPIO
+
+config UX500_SOC_DB8500
+       bool
+
+config UX500_SOC_DB5500
+       bool
+
+choice
+       prompt "Ux500 target platform"
+       default MACH_U8500_MOP
+
+config MACH_U8500_MOP
+       bool "U8500 Development platform"
+       select UX500_SOC_DB8500
        help
          Include support for mop500 development platform
          based on U8500 architecture. The platform is based
          on early drop silicon version of 8500.
-endmenu
+
+config MACH_U5500
+       bool "U5500 Development platform"
+       select UX500_SOC_DB5500
+       help
+         Include support for the U5500 development platform.
+endchoice
+
+config UX500_DEBUG_UART
+       int "Ux500 UART to use for low-level debug"
+       default 2
+       help
+         Choose the UART on which kernel low-level debug messages should be
+         output.
+
+endif
index 95e6e24..c7bc419 100644 (file)
@@ -2,7 +2,9 @@
 # Makefile for the linux kernel, U8500 machine.
 #
 
-obj-y                          := clock.o
-obj-$(CONFIG_ARCH_U8500)       += cpu-u8500.o
+obj-y                          := clock.o cpu.o devices.o
+obj-$(CONFIG_UX500_SOC_DB5500) += cpu-db5500.o devices-db5500.o
+obj-$(CONFIG_UX500_SOC_DB8500) += cpu-db8500.o devices-db8500.o
 obj-$(CONFIG_MACH_U8500_MOP)   += board-mop500.o
+obj-$(CONFIG_MACH_U5500)       += board-u5500.o
 obj-$(CONFIG_SMP)              += platsmp.o headsmp.o localtimer.o
index 803aec1..072196c 100644 (file)
 #include <linux/amba/pl022.h>
 #include <linux/spi/spi.h>
 
-#include <asm/localtimer.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 
-#include <plat/mtu.h>
 #include <plat/i2c.h>
 
 #include <mach/hardware.h>
 #include <mach/setup.h>
-
-#define __MEM_4K_RESOURCE(x) \
-       .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
-
-/* These are active devices on this board */
-static struct amba_device uart0_device = {
-       .dev = { .init_name = "uart0" },
-       __MEM_4K_RESOURCE(U8500_UART0_BASE),
-       .irq = {IRQ_UART0, NO_IRQ},
-};
-
-static struct amba_device uart1_device = {
-       .dev = { .init_name = "uart1" },
-       __MEM_4K_RESOURCE(U8500_UART1_BASE),
-       .irq = {IRQ_UART1, NO_IRQ},
-};
-
-static struct amba_device uart2_device = {
-       .dev = { .init_name = "uart2" },
-       __MEM_4K_RESOURCE(U8500_UART2_BASE),
-       .irq = {IRQ_UART2, NO_IRQ},
-};
+#include <mach/devices.h>
 
 static void ab4500_spi_cs_control(u32 command)
 {
@@ -93,55 +70,8 @@ static struct pl022_ssp_controller ssp0_platform_data = {
        .num_chipselect = 5,
 };
 
-static struct amba_device pl022_device = {
-       .dev = {
-               .coherent_dma_mask = ~0,
-               .init_name = "pl022",
-               .platform_data = &ssp0_platform_data,
-       },
-       .res = {
-               .start = U8500_SSP0_BASE,
-               .end   = U8500_SSP0_BASE + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       .irq = {IRQ_SSP0, NO_IRQ },
-       /* ST-Ericsson modified id */
-       .periphid = SSP_PER_ID,
-};
-
-static struct amba_device pl031_device = {
-       .dev = {
-               .init_name = "pl031",
-       },
-       .res = {
-               .start = U8500_RTC_BASE,
-               .end = U8500_RTC_BASE + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       .irq = {IRQ_RTC_RTT, NO_IRQ},
-};
-
-#define U8500_I2C_RESOURCES(id, size)          \
-static struct resource u8500_i2c_resources_##id[] = {  \
-       [0] = {                                 \
-               .start  = U8500_I2C##id##_BASE, \
-               .end    = U8500_I2C##id##_BASE + size - 1, \
-               .flags  = IORESOURCE_MEM,       \
-       },                                      \
-       [1] = {                                 \
-               .start  = IRQ_I2C##id,          \
-               .end    = IRQ_I2C##id,          \
-               .flags  = IORESOURCE_IRQ        \
-       }                                       \
-}
-
-U8500_I2C_RESOURCES(0, SZ_4K);
-U8500_I2C_RESOURCES(1, SZ_4K);
-U8500_I2C_RESOURCES(2, SZ_4K);
-U8500_I2C_RESOURCES(3, SZ_4K);
-
 #define U8500_I2C_CONTROLLER(id, _slsu, _tft, _rft, clk, _sm) \
-static struct nmk_i2c_controller u8500_i2c_##id = { \
+static struct nmk_i2c_controller u8500_i2c##id##_data = { \
        /*                              \
         * slave data setup time, which is      \
         * 250 ns,100ns,10ns which is 14,6,2    \
@@ -169,58 +99,32 @@ U8500_I2C_CONTROLLER(1, 0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
 U8500_I2C_CONTROLLER(2,        0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
 U8500_I2C_CONTROLLER(3,        0xe, 1, 1, 100000, I2C_FREQ_MODE_STANDARD);
 
-#define U8500_I2C_PDEVICE(cid)         \
-static struct platform_device i2c_controller##cid = { \
-       .name = "nmk-i2c",              \
-       .id      = cid,                 \
-       .num_resources = 2,             \
-       .resource = u8500_i2c_resources_##cid,  \
-       .dev = {                        \
-               .platform_data = &u8500_i2c_##cid \
-       }                               \
-}
-
-U8500_I2C_PDEVICE(0);
-U8500_I2C_PDEVICE(1);
-U8500_I2C_PDEVICE(2);
-U8500_I2C_PDEVICE(3);
-
 static struct amba_device *amba_devs[] __initdata = {
-       &uart0_device,
-       &uart1_device,
-       &uart2_device,
-       &pl022_device,
-       &pl031_device,
+       &ux500_uart0_device,
+       &ux500_uart1_device,
+       &ux500_uart2_device,
+       &u8500_ssp0_device,
 };
 
 /* add any platform devices here - TODO */
 static struct platform_device *platform_devs[] __initdata = {
-       &i2c_controller0,
-       &i2c_controller1,
-       &i2c_controller2,
-       &i2c_controller3,
-};
-
-static void __init u8500_timer_init(void)
-{
-#ifdef CONFIG_LOCAL_TIMERS
-       /* Setup the local timer base */
-       twd_base = __io_address(U8500_TWD_BASE);
-#endif
-       /* Setup the MTU base */
-       mtu_base = __io_address(U8500_MTU0_BASE);
-
-       nmdk_timer_init();
-}
-
-static struct sys_timer u8500_timer = {
-       .init   = u8500_timer_init,
+       &u8500_i2c0_device,
+       &ux500_i2c1_device,
+       &ux500_i2c2_device,
+       &ux500_i2c3_device,
 };
 
 static void __init u8500_init_machine(void)
 {
        int i;
 
+       u8500_i2c0_device.dev.platform_data = &u8500_i2c0_data;
+       ux500_i2c1_device.dev.platform_data = &u8500_i2c1_data;
+       ux500_i2c2_device.dev.platform_data = &u8500_i2c2_data;
+       ux500_i2c3_device.dev.platform_data = &u8500_i2c3_data;
+
+       u8500_ssp0_device.dev.platform_data = &ssp0_platform_data;
+
        /* Register the active AMBA devices on this board */
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++)
                amba_device_register(amba_devs[i], &iomem_resource);
@@ -239,8 +143,8 @@ MACHINE_START(U8500, "ST-Ericsson MOP500 platform")
        .io_pg_offst    = (IO_ADDRESS(U8500_UART2_BASE) >> 18) & 0xfffc,
        .boot_params    = 0x100,
        .map_io         = u8500_map_io,
-       .init_irq       = u8500_init_irq,
+       .init_irq       = ux500_init_irq,
        /* we re-use nomadik timer here */
-       .timer          = &u8500_timer,
+       .timer          = &ux500_timer,
        .init_machine   = u8500_init_machine,
 MACHINE_END
diff --git a/arch/arm/mach-ux500/board-u5500.c b/arch/arm/mach-ux500/board-u5500.c
new file mode 100644 (file)
index 0000000..4430e69
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+#include <linux/gpio.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach-types.h>
+
+#include <mach/hardware.h>
+#include <mach/devices.h>
+#include <mach/setup.h>
+
+static struct amba_device *amba_board_devs[] __initdata = {
+       &ux500_uart0_device,
+       &ux500_uart1_device,
+       &ux500_uart2_device,
+};
+
+static void __init u5500_init_machine(void)
+{
+       u5500_init_devices();
+
+       amba_add_devices(amba_board_devs, ARRAY_SIZE(amba_board_devs));
+}
+
+MACHINE_START(U8500, "ST-Ericsson U5500 Platform")
+       .phys_io        = UX500_UART0_BASE,
+       .io_pg_offst    = (IO_ADDRESS(UX500_UART0_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .map_io         = u5500_map_io,
+       .init_irq       = ux500_init_irq,
+       .timer          = &ux500_timer,
+       .init_machine   = u5500_init_machine,
+MACHINE_END
index 8359a73..1b2c989 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright (C) 2009 ST-Ericsson
- *     heavily based on realview platform
+ *  Copyright (C) 2009 STMicroelectronics
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 #include <linux/errno.h>
 #include <linux/err.h>
 #include <linux/clk.h>
-#include <linux/mutex.h>
+#include <linux/io.h>
 
 #include <asm/clkdev.h>
 
-/* currently the clk structure
- * just supports rate. This would
- * be extended as and when new devices are
- * added - TODO
- */
-struct clk {
-       unsigned long           rate;
-};
+#include <mach/hardware.h>
+#include "clock.h"
+
+#define PRCC_PCKEN             0x00
+#define PRCC_PCKDIS            0x04
+#define PRCC_KCKEN             0x08
+#define PRCC_KCKDIS            0x0C
+
+#define PRCM_YYCLKEN0_MGT_SET  0x510
+#define PRCM_YYCLKEN1_MGT_SET  0x514
+#define PRCM_YYCLKEN0_MGT_CLR  0x518
+#define PRCM_YYCLKEN1_MGT_CLR  0x51C
+#define PRCM_YYCLKEN0_MGT_VAL  0x520
+#define PRCM_YYCLKEN1_MGT_VAL  0x524
+
+#define PRCM_SVAMMDSPCLK_MGT   0x008
+#define PRCM_SIAMMDSPCLK_MGT   0x00C
+#define PRCM_SGACLK_MGT                0x014
+#define PRCM_UARTCLK_MGT       0x018
+#define PRCM_MSP02CLK_MGT      0x01C
+#define PRCM_MSP1CLK_MGT       0x288
+#define PRCM_I2CCLK_MGT                0x020
+#define PRCM_SDMMCCLK_MGT      0x024
+#define PRCM_SLIMCLK_MGT       0x028
+#define PRCM_PER1CLK_MGT       0x02C
+#define PRCM_PER2CLK_MGT       0x030
+#define PRCM_PER3CLK_MGT       0x034
+#define PRCM_PER5CLK_MGT       0x038
+#define PRCM_PER6CLK_MGT       0x03C
+#define PRCM_PER7CLK_MGT       0x040
+#define PRCM_LCDCLK_MGT                0x044
+#define PRCM_BMLCLK_MGT                0x04C
+#define PRCM_HSITXCLK_MGT      0x050
+#define PRCM_HSIRXCLK_MGT      0x054
+#define PRCM_HDMICLK_MGT       0x058
+#define PRCM_APEATCLK_MGT      0x05C
+#define PRCM_APETRACECLK_MGT   0x060
+#define PRCM_MCDECLK_MGT       0x064
+#define PRCM_IPI2CCLK_MGT      0x068
+#define PRCM_DSIALTCLK_MGT     0x06C
+#define PRCM_DMACLK_MGT                0x074
+#define PRCM_B2R2CLK_MGT       0x078
+#define PRCM_TVCLK_MGT         0x07C
+#define PRCM_UNIPROCLK_MGT     0x278
+#define PRCM_SSPCLK_MGT                0x280
+#define PRCM_RNGCLK_MGT                0x284
+#define PRCM_UICCCLK_MGT       0x27C
+
+#define PRCM_MGT_ENABLE                (1 << 8)
+
+static DEFINE_SPINLOCK(clocks_lock);
+
+static void __clk_enable(struct clk *clk)
+{
+       if (clk->enabled++ == 0) {
+               if (clk->parent_cluster)
+                       __clk_enable(clk->parent_cluster);
+
+               if (clk->parent_periph)
+                       __clk_enable(clk->parent_periph);
+
+               if (clk->ops && clk->ops->enable)
+                       clk->ops->enable(clk);
+       }
+}
 
 int clk_enable(struct clk *clk)
 {
+       unsigned long flags;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       __clk_enable(clk);
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
        return 0;
 }
 EXPORT_SYMBOL(clk_enable);
 
+static void __clk_disable(struct clk *clk)
+{
+       if (--clk->enabled == 0) {
+               if (clk->ops && clk->ops->disable)
+                       clk->ops->disable(clk);
+
+               if (clk->parent_periph)
+                       __clk_disable(clk->parent_periph);
+
+               if (clk->parent_cluster)
+                       __clk_disable(clk->parent_cluster);
+       }
+}
+
 void clk_disable(struct clk *clk)
 {
+       unsigned long flags;
+
+       WARN_ON(!clk->enabled);
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       __clk_disable(clk);
+       spin_unlock_irqrestore(&clocks_lock, flags);
 }
 EXPORT_SYMBOL(clk_disable);
 
 unsigned long clk_get_rate(struct clk *clk)
 {
-       return clk->rate;
+       unsigned long rate;
+
+       if (clk->ops && clk->ops->get_rate)
+               return clk->ops->get_rate(clk);
+
+       rate = clk->rate;
+       if (!rate) {
+               if (clk->parent_periph)
+                       rate = clk_get_rate(clk->parent_periph);
+               else if (clk->parent_cluster)
+                       rate = clk_get_rate(clk->parent_cluster);
+       }
+
+       return rate;
 }
 EXPORT_SYMBOL(clk_get_rate);
 
@@ -56,37 +153,373 @@ int clk_set_rate(struct clk *clk, unsigned long rate)
 }
 EXPORT_SYMBOL(clk_set_rate);
 
-/* ssp clock */
-static struct clk ssp_clk = {
-       .rate = 48000000,
+static void clk_prcmu_enable(struct clk *clk)
+{
+       void __iomem *cg_set_reg = __io_address(U8500_PRCMU_BASE)
+                                  + PRCM_YYCLKEN0_MGT_SET + clk->prcmu_cg_off;
+
+       writel(1 << clk->prcmu_cg_bit, cg_set_reg);
+}
+
+static void clk_prcmu_disable(struct clk *clk)
+{
+       void __iomem *cg_clr_reg = __io_address(U8500_PRCMU_BASE)
+                                  + PRCM_YYCLKEN0_MGT_CLR + clk->prcmu_cg_off;
+
+       writel(1 << clk->prcmu_cg_bit, cg_clr_reg);
+}
+
+/* ED doesn't have the combined set/clr registers */
+static void clk_prcmu_ed_enable(struct clk *clk)
+{
+       void __iomem *addr = __io_address(U8500_PRCMU_BASE)
+                            + clk->prcmu_cg_mgt;
+
+       writel(readl(addr) | PRCM_MGT_ENABLE, addr);
+}
+
+static void clk_prcmu_ed_disable(struct clk *clk)
+{
+       void __iomem *addr = __io_address(U8500_PRCMU_BASE)
+                            + clk->prcmu_cg_mgt;
+
+       writel(readl(addr) & ~PRCM_MGT_ENABLE, addr);
+}
+
+static struct clkops clk_prcmu_ops = {
+       .enable = clk_prcmu_enable,
+       .disable = clk_prcmu_disable,
 };
 
-/* fixed clock */
-static struct clk f38_clk = {
-       .rate = 38400000,
+static unsigned int clkrst_base[] = {
+       [1] = U8500_CLKRST1_BASE,
+       [2] = U8500_CLKRST2_BASE,
+       [3] = U8500_CLKRST3_BASE,
+       [5] = U8500_CLKRST5_BASE,
+       [6] = U8500_CLKRST6_BASE,
+       [7] = U8500_CLKRST7_BASE_ED,
 };
 
-static struct clk_lookup lookups[] = {
-       {
-               /* UART0 */
-               .dev_id         = "uart0",
-               .clk            = &f38_clk,
-       }, {    /* UART1 */
-               .dev_id         = "uart1",
-               .clk            = &f38_clk,
-       }, {    /* UART2 */
-               .dev_id         = "uart2",
-               .clk            = &f38_clk,
-       }, {    /* SSP */
-               .dev_id         = "pl022",
-               .clk            = &ssp_clk,
-       }
+static void clk_prcc_enable(struct clk *clk)
+{
+       void __iomem *addr = __io_address(clkrst_base[clk->cluster]);
+
+       if (clk->prcc_kernel != -1)
+               writel(1 << clk->prcc_kernel, addr + PRCC_KCKEN);
+
+       if (clk->prcc_bus != -1)
+               writel(1 << clk->prcc_bus, addr + PRCC_PCKEN);
+}
+
+static void clk_prcc_disable(struct clk *clk)
+{
+       void __iomem *addr = __io_address(clkrst_base[clk->cluster]);
+
+       if (clk->prcc_bus != -1)
+               writel(1 << clk->prcc_bus, addr + PRCC_PCKDIS);
+
+       if (clk->prcc_kernel != -1)
+               writel(1 << clk->prcc_kernel, addr + PRCC_KCKDIS);
+}
+
+static struct clkops clk_prcc_ops = {
+       .enable = clk_prcc_enable,
+       .disable = clk_prcc_disable,
+};
+
+static struct clk clk_32khz = {
+       .rate = 32000,
+};
+
+/*
+ * PRCMU level clock gating
+ */
+
+/* Bank 0 */
+static DEFINE_PRCMU_CLK(svaclk,                0x0, 2, SVAMMDSPCLK);
+static DEFINE_PRCMU_CLK(siaclk,                0x0, 3, SIAMMDSPCLK);
+static DEFINE_PRCMU_CLK(sgaclk,                0x0, 4, SGACLK);
+static DEFINE_PRCMU_CLK_RATE(uartclk,  0x0, 5, UARTCLK, 38400000);
+static DEFINE_PRCMU_CLK(msp02clk,      0x0, 6, MSP02CLK);
+static DEFINE_PRCMU_CLK(msp1clk,       0x0, 7, MSP1CLK); /* v1 */
+static DEFINE_PRCMU_CLK_RATE(i2cclk,   0x0, 8, I2CCLK, 48000000);
+static DEFINE_PRCMU_CLK_RATE(sdmmcclk, 0x0, 9, SDMMCCLK, 50000000);
+static DEFINE_PRCMU_CLK(slimclk,       0x0, 10, SLIMCLK);
+static DEFINE_PRCMU_CLK(per1clk,       0x0, 11, PER1CLK);
+static DEFINE_PRCMU_CLK(per2clk,       0x0, 12, PER2CLK);
+static DEFINE_PRCMU_CLK(per3clk,       0x0, 13, PER3CLK);
+static DEFINE_PRCMU_CLK(per5clk,       0x0, 14, PER5CLK);
+static DEFINE_PRCMU_CLK_RATE(per6clk,  0x0, 15, PER6CLK, 133330000);
+static DEFINE_PRCMU_CLK_RATE(per7clk,  0x0, 16, PER7CLK, 100000000);
+static DEFINE_PRCMU_CLK(lcdclk,                0x0, 17, LCDCLK);
+static DEFINE_PRCMU_CLK(bmlclk,                0x0, 18, BMLCLK);
+static DEFINE_PRCMU_CLK(hsitxclk,      0x0, 19, HSITXCLK);
+static DEFINE_PRCMU_CLK(hsirxclk,      0x0, 20, HSIRXCLK);
+static DEFINE_PRCMU_CLK(hdmiclk,       0x0, 21, HDMICLK);
+static DEFINE_PRCMU_CLK(apeatclk,      0x0, 22, APEATCLK);
+static DEFINE_PRCMU_CLK(apetraceclk,   0x0, 23, APETRACECLK);
+static DEFINE_PRCMU_CLK(mcdeclk,       0x0, 24, MCDECLK);
+static DEFINE_PRCMU_CLK(ipi2clk,       0x0, 25, IPI2CCLK);
+static DEFINE_PRCMU_CLK(dsialtclk,     0x0, 26, DSIALTCLK); /* v1 */
+static DEFINE_PRCMU_CLK(dmaclk,                0x0, 27, DMACLK);
+static DEFINE_PRCMU_CLK(b2r2clk,       0x0, 28, B2R2CLK);
+static DEFINE_PRCMU_CLK(tvclk,         0x0, 29, TVCLK);
+static DEFINE_PRCMU_CLK(uniproclk,     0x0, 30, UNIPROCLK); /* v1 */
+static DEFINE_PRCMU_CLK_RATE(sspclk,   0x0, 31, SSPCLK, 48000000); /* v1 */
+
+/* Bank 1 */
+static DEFINE_PRCMU_CLK(rngclk,                0x4, 0, RNGCLK); /* v1 */
+static DEFINE_PRCMU_CLK(uiccclk,       0x4, 1, UICCCLK); /* v1 */
+
+/*
+ * PRCC level clock gating
+ * Format: per#, clk, PCKEN bit, KCKEN bit, parent
+ */
+
+/* Peripheral Cluster #1 */
+static DEFINE_PRCC_CLK(1, i2c4,        10, 9, &clk_i2cclk);
+static DEFINE_PRCC_CLK(1, gpio0,       9, -1, NULL);
+static DEFINE_PRCC_CLK(1, slimbus0,    8,  8, &clk_slimclk);
+static DEFINE_PRCC_CLK(1, spi3_ed,     7,  7, NULL);
+static DEFINE_PRCC_CLK(1, spi3_v1,     7, -1, NULL);
+static DEFINE_PRCC_CLK(1, i2c2,        6,  6, &clk_i2cclk);
+static DEFINE_PRCC_CLK(1, sdi0,                5,  5, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(1, msp1_ed,     4,  4, &clk_msp02clk);
+static DEFINE_PRCC_CLK(1, msp1_v1,     4,  4, &clk_msp1clk);
+static DEFINE_PRCC_CLK(1, msp0,        3,  3, &clk_msp02clk);
+static DEFINE_PRCC_CLK(1, i2c1,        2,  2, &clk_i2cclk);
+static DEFINE_PRCC_CLK(1, uart1,       1,  1, &clk_uartclk);
+static DEFINE_PRCC_CLK(1, uart0,       0,  0, &clk_uartclk);
+
+/* Peripheral Cluster #2 */
+
+static DEFINE_PRCC_CLK(2, gpio1_ed,    12, -1, NULL);
+static DEFINE_PRCC_CLK(2, ssitx_ed,    11, -1, NULL);
+static DEFINE_PRCC_CLK(2, ssirx_ed,    10, -1, NULL);
+static DEFINE_PRCC_CLK(2, spi0_ed,      9, -1, NULL);
+static DEFINE_PRCC_CLK(2, sdi3_ed,      8,  6, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, sdi1_ed,      7,  5, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, msp2_ed,      6,  4, &clk_msp02clk);
+static DEFINE_PRCC_CLK(2, sdi4_ed,      4,  2, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, pwl_ed,       3,  1, NULL);
+static DEFINE_PRCC_CLK(2, spi1_ed,      2, -1, NULL);
+static DEFINE_PRCC_CLK(2, spi2_ed,      1, -1, NULL);
+static DEFINE_PRCC_CLK(2, i2c3_ed,      0,  0, &clk_i2cclk);
+
+static DEFINE_PRCC_CLK(2, gpio1_v1,    11, -1, NULL);
+static DEFINE_PRCC_CLK(2, ssitx_v1,    10,  7, NULL);
+static DEFINE_PRCC_CLK(2, ssirx_v1,     9,  6, NULL);
+static DEFINE_PRCC_CLK(2, spi0_v1,      8, -1, NULL);
+static DEFINE_PRCC_CLK(2, sdi3_v1,      7,  5, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, sdi1_v1,      6,  4, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, msp2_v1,      5,  3, &clk_msp02clk);
+static DEFINE_PRCC_CLK(2, sdi4_v1,      4,  2, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(2, pwl_v1,       3,  1, NULL);
+static DEFINE_PRCC_CLK(2, spi1_v1,      2, -1, NULL);
+static DEFINE_PRCC_CLK(2, spi2_v1,      1, -1, NULL);
+static DEFINE_PRCC_CLK(2, i2c3_v1,      0,  0, &clk_i2cclk);
+
+/* Peripheral Cluster #3 */
+static DEFINE_PRCC_CLK(3, gpio2,       8, -1, NULL);
+static DEFINE_PRCC_CLK(3, sdi5,        7,  7, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(3, uart2,       6,  6, &clk_uartclk);
+static DEFINE_PRCC_CLK(3, ske,                 5,  5, &clk_32khz);
+static DEFINE_PRCC_CLK(3, sdi2,        4,  4, &clk_sdmmcclk);
+static DEFINE_PRCC_CLK(3, i2c0,        3,  3, &clk_i2cclk);
+static DEFINE_PRCC_CLK(3, ssp1_ed,     2,  2, &clk_i2cclk);
+static DEFINE_PRCC_CLK(3, ssp0_ed,     1,  1, &clk_i2cclk);
+static DEFINE_PRCC_CLK(3, ssp1_v1,     2,  2, &clk_sspclk);
+static DEFINE_PRCC_CLK(3, ssp0_v1,     1,  1, &clk_sspclk);
+static DEFINE_PRCC_CLK(3, fsmc,        0, -1, NULL);
+
+/* Peripheral Cluster #4 is in the always on domain */
+
+/* Peripheral Cluster #5 */
+static DEFINE_PRCC_CLK(5, gpio3,       1, -1, NULL);
+static DEFINE_PRCC_CLK(5, usb_ed,      0,  0, &clk_i2cclk);
+static DEFINE_PRCC_CLK(5, usb_v1,      0,  0, NULL);
+
+/* Peripheral Cluster #6 */
+
+static DEFINE_PRCC_CLK(6, mtu1_v1,     8, -1, NULL);
+static DEFINE_PRCC_CLK(6, mtu0_v1,     7, -1, NULL);
+static DEFINE_PRCC_CLK(6, cfgreg_v1,   6,  6, NULL);
+static DEFINE_PRCC_CLK(6, dmc_ed,      6,  6, NULL);
+static DEFINE_PRCC_CLK(6, hash1,       5, -1, NULL);
+static DEFINE_PRCC_CLK(6, unipro_v1,   4,  1, &clk_uniproclk);
+static DEFINE_PRCC_CLK(6, cryp1_ed,    4, -1, NULL);
+static DEFINE_PRCC_CLK(6, pka,                 3, -1, NULL);
+static DEFINE_PRCC_CLK(6, hash0,       2, -1, NULL);
+static DEFINE_PRCC_CLK(6, cryp0,       1, -1, NULL);
+static DEFINE_PRCC_CLK(6, rng_ed,      0,  0, &clk_i2cclk);
+static DEFINE_PRCC_CLK(6, rng_v1,      0,  0, &clk_rngclk);
+
+/* Peripheral Cluster #7 */
+
+static DEFINE_PRCC_CLK(7, tzpc0_ed,    4, -1, NULL);
+static DEFINE_PRCC_CLK(7, mtu1_ed,     3, -1, NULL);
+static DEFINE_PRCC_CLK(7, mtu0_ed,     2, -1, NULL);
+static DEFINE_PRCC_CLK(7, wdg_ed,      1, -1, NULL);
+static DEFINE_PRCC_CLK(7, cfgreg_ed,   0, -1, NULL);
+
+static struct clk_lookup u8500_common_clks[] = {
+       /* Peripheral Cluster #1 */
+       CLK(gpio0,      "gpio.0",       NULL),
+       CLK(gpio0,      "gpio.1",       NULL),
+       CLK(slimbus0,   "slimbus0",     NULL),
+       CLK(i2c2,       "nmk-i2c.2",    NULL),
+       CLK(sdi0,       "sdi0",         NULL),
+       CLK(msp0,       "msp0",         NULL),
+       CLK(i2c1,       "nmk-i2c.1",    NULL),
+       CLK(uart1,      "uart1",        NULL),
+       CLK(uart0,      "uart0",        NULL),
+
+       /* Peripheral Cluster #3 */
+       CLK(gpio2,      "gpio.2",       NULL),
+       CLK(gpio2,      "gpio.3",       NULL),
+       CLK(gpio2,      "gpio.4",       NULL),
+       CLK(gpio2,      "gpio.5",       NULL),
+       CLK(sdi5,       "sdi5",         NULL),
+       CLK(uart2,      "uart2",        NULL),
+       CLK(ske,        "ske",          NULL),
+       CLK(sdi2,       "sdi2",         NULL),
+       CLK(i2c0,       "nmk-i2c.0",    NULL),
+       CLK(fsmc,       "fsmc",         NULL),
+
+       /* Peripheral Cluster #5 */
+       CLK(gpio3,      "gpio.8",       NULL),
+
+       /* Peripheral Cluster #6 */
+       CLK(hash1,      "hash1",        NULL),
+       CLK(pka,        "pka",          NULL),
+       CLK(hash0,      "hash0",        NULL),
+       CLK(cryp0,      "cryp0",        NULL),
+
+       /* PRCMU level clock gating */
+
+       /* Bank 0 */
+       CLK(svaclk,     "sva",          NULL),
+       CLK(siaclk,     "sia",          NULL),
+       CLK(sgaclk,     "sga",          NULL),
+       CLK(slimclk,    "slim",         NULL),
+       CLK(lcdclk,     "lcd",          NULL),
+       CLK(bmlclk,     "bml",          NULL),
+       CLK(hsitxclk,   "stm-hsi.0",    NULL),
+       CLK(hsirxclk,   "stm-hsi.1",    NULL),
+       CLK(hdmiclk,    "hdmi",         NULL),
+       CLK(apeatclk,   "apeat",        NULL),
+       CLK(apetraceclk,        "apetrace",     NULL),
+       CLK(mcdeclk,    "mcde",         NULL),
+       CLK(ipi2clk,    "ipi2",         NULL),
+       CLK(dmaclk,     "dma40",        NULL),
+       CLK(b2r2clk,    "b2r2",         NULL),
+       CLK(tvclk,      "tv",           NULL),
+};
+
+static struct clk_lookup u8500_ed_clks[] = {
+       /* Peripheral Cluster #1 */
+       CLK(spi3_ed,    "spi3",         NULL),
+       CLK(msp1_ed,    "msp1",         NULL),
+
+       /* Peripheral Cluster #2 */
+       CLK(gpio1_ed,   "gpio.6",       NULL),
+       CLK(gpio1_ed,   "gpio.7",       NULL),
+       CLK(ssitx_ed,   "ssitx",        NULL),
+       CLK(ssirx_ed,   "ssirx",        NULL),
+       CLK(spi0_ed,    "spi0",         NULL),
+       CLK(sdi3_ed,    "sdi3",         NULL),
+       CLK(sdi1_ed,    "sdi1",         NULL),
+       CLK(msp2_ed,    "msp2",         NULL),
+       CLK(sdi4_ed,    "sdi4",         NULL),
+       CLK(pwl_ed,     "pwl",          NULL),
+       CLK(spi1_ed,    "spi1",         NULL),
+       CLK(spi2_ed,    "spi2",         NULL),
+       CLK(i2c3_ed,    "nmk-i2c.3",    NULL),
+
+       /* Peripheral Cluster #3 */
+       CLK(ssp1_ed,    "ssp1",         NULL),
+       CLK(ssp0_ed,    "ssp0",         NULL),
+
+       /* Peripheral Cluster #5 */
+       CLK(usb_ed,     "musb_hdrc.0",  "usb"),
+
+       /* Peripheral Cluster #6 */
+       CLK(dmc_ed,     "dmc",          NULL),
+       CLK(cryp1_ed,   "cryp1",        NULL),
+       CLK(rng_ed,     "rng",          NULL),
+
+       /* Peripheral Cluster #7 */
+       CLK(tzpc0_ed,   "tzpc0",        NULL),
+       CLK(mtu1_ed,    "mtu1",         NULL),
+       CLK(mtu0_ed,    "mtu0",         NULL),
+       CLK(wdg_ed,     "wdg",          NULL),
+       CLK(cfgreg_ed,  "cfgreg",       NULL),
+};
+
+static struct clk_lookup u8500_v1_clks[] = {
+       /* Peripheral Cluster #1 */
+       CLK(i2c4,       "nmk-i2c.4",    NULL),
+       CLK(spi3_v1,    "spi3",         NULL),
+       CLK(msp1_v1,    "msp1",         NULL),
+
+       /* Peripheral Cluster #2 */
+       CLK(gpio1_v1,   "gpio.6",       NULL),
+       CLK(gpio1_v1,   "gpio.7",       NULL),
+       CLK(ssitx_v1,   "ssitx",        NULL),
+       CLK(ssirx_v1,   "ssirx",        NULL),
+       CLK(spi0_v1,    "spi0",         NULL),
+       CLK(sdi3_v1,    "sdi3",         NULL),
+       CLK(sdi1_v1,    "sdi1",         NULL),
+       CLK(msp2_v1,    "msp2",         NULL),
+       CLK(sdi4_v1,    "sdi4",         NULL),
+       CLK(pwl_v1,     "pwl",          NULL),
+       CLK(spi1_v1,    "spi1",         NULL),
+       CLK(spi2_v1,    "spi2",         NULL),
+       CLK(i2c3_v1,    "nmk-i2c.3",    NULL),
+
+       /* Peripheral Cluster #3 */
+       CLK(ssp1_v1,    "ssp1",         NULL),
+       CLK(ssp0_v1,    "ssp0",         NULL),
+
+       /* Peripheral Cluster #5 */
+       CLK(usb_v1,     "musb_hdrc.0",  "usb"),
+
+       /* Peripheral Cluster #6 */
+       CLK(mtu1_v1,    "mtu1",         NULL),
+       CLK(mtu0_v1,    "mtu0",         NULL),
+       CLK(cfgreg_v1,  "cfgreg",       NULL),
+       CLK(hash1,      "hash1",        NULL),
+       CLK(unipro_v1,  "unipro",       NULL),
+       CLK(rng_v1,     "rng",          NULL),
+
+       /* PRCMU level clock gating */
+
+       /* Bank 0 */
+       CLK(uniproclk,  "uniproclk",    NULL),
+       CLK(dsialtclk,  "dsialt",       NULL),
+
+       /* Bank 1 */
+       CLK(rngclk,     "rng",          NULL),
+       CLK(uiccclk,    "uicc",         NULL),
 };
 
 static int __init clk_init(void)
 {
-       /* register the clock lookups */
-       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+       if (cpu_is_u8500ed()) {
+               clk_prcmu_ops.enable = clk_prcmu_ed_enable;
+               clk_prcmu_ops.disable = clk_prcmu_ed_disable;
+       } else if (cpu_is_u5500()) {
+               /* Clock tree for U5500 not implemented yet */
+               clk_prcc_ops.enable = clk_prcc_ops.disable = NULL;
+               clk_prcmu_ops.enable = clk_prcmu_ops.disable = NULL;
+       }
+
+       clkdev_add_table(u8500_common_clks, ARRAY_SIZE(u8500_common_clks));
+       if (cpu_is_u8500ed())
+               clkdev_add_table(u8500_ed_clks, ARRAY_SIZE(u8500_ed_clks));
+       else
+               clkdev_add_table(u8500_v1_clks, ARRAY_SIZE(u8500_v1_clks));
+
        return 0;
 }
 arch_initcall(clk_init);
diff --git a/arch/arm/mach-ux500/clock.h b/arch/arm/mach-ux500/clock.h
new file mode 100644 (file)
index 0000000..e4f99b6
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ *  Copyright (C) 2010 ST-Ericsson
+ *  Copyright (C) 2009 STMicroelectronics
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+/**
+ * struct clkops - ux500 clock operations
+ * @enable:    function to enable the clock
+ * @disable:   function to disable the clock
+ * @get_rate:  function to get the current clock rate
+ *
+ * This structure contains function pointers to functions that will be used to
+ * control the clock.  All of these functions are optional.  If get_rate is
+ * NULL, the rate in the struct clk will be used.
+ */
+struct clkops {
+       void (*enable) (struct clk *);
+       void (*disable) (struct clk *);
+       unsigned long (*get_rate) (struct clk *);
+};
+
+/**
+ * struct clk - ux500 clock structure
+ * @ops:               pointer to clkops struct used to control this clock
+ * @name:              name, for debugging
+ * @enabled:           refcount. positive if enabled, zero if disabled
+ * @rate:              fixed rate for clocks which don't implement
+ *                     ops->getrate
+ * @prcmu_cg_off:      address offset of the combined enable/disable register
+ *                     (used on u8500v1)
+ * @prcmu_cg_bit:      bit in the combined enable/disable register (used on
+ *                     u8500v1)
+ * @prcmu_cg_mgt:      address of the enable/disable register (used on
+ *                     u8500ed)
+ * @cluster:           peripheral cluster number
+ * @prcc_bus:          bit for the bus clock in the peripheral's CLKRST
+ * @prcc_kernel:       bit for the kernel clock in the peripheral's CLKRST.
+ *                     -1 if no kernel clock exists.
+ * @parent_cluster:    pointer to parent's cluster clk struct
+ * @parent_periph:     pointer to parent's peripheral clk struct
+ *
+ * Peripherals are organised into clusters, and each cluster has an associated
+ * bus clock.  Some peripherals also have a parent peripheral clock.
+ *
+ * In order to enable a clock for a peripheral, we need to enable:
+ *     (1) the parent cluster (bus) clock at the PRCMU level
+ *     (2) the parent peripheral clock (if any) at the PRCMU level
+ *     (3) the peripheral's bus & kernel clock at the PRCC level
+ *
+ * (1) and (2) are handled by defining clk structs (DEFINE_PRCMU_CLK) for each
+ * of the cluster and peripheral clocks, and hooking these as the parents of
+ * the individual peripheral clocks.
+ *
+ * (3) is handled by specifying the bits in the PRCC control registers required
+ * to enable these clocks and modifying them in the ->enable and
+ * ->disable callbacks of the peripheral clocks (DEFINE_PRCC_CLK).
+ *
+ * This structure describes both the PRCMU-level clocks and PRCC-level clocks.
+ * The prcmu_* fields are only used for the PRCMU clocks, and the cluster,
+ * prcc, and parent pointers are only used for the PRCC-level clocks.
+ */
+struct clk {
+       const struct clkops     *ops;
+       const char              *name;
+       unsigned int            enabled;
+
+       unsigned long           rate;
+       struct list_head        list;
+
+       /* These three are only for PRCMU clks */
+
+       unsigned int            prcmu_cg_off;
+       unsigned int            prcmu_cg_bit;
+       unsigned int            prcmu_cg_mgt;
+
+       /* The rest are only for PRCC clks */
+
+       int                     cluster;
+       unsigned int            prcc_bus;
+       unsigned int            prcc_kernel;
+
+       struct clk              *parent_cluster;
+       struct clk              *parent_periph;
+};
+
+#define DEFINE_PRCMU_CLK(_name, _cg_off, _cg_bit, _reg)                \
+struct clk clk_##_name = {                                     \
+               .name           = #_name,                       \
+               .ops            = &clk_prcmu_ops,               \
+               .prcmu_cg_off   = _cg_off,                      \
+               .prcmu_cg_bit   = _cg_bit,                      \
+               .prcmu_cg_mgt   = PRCM_##_reg##_MGT             \
+       }
+
+#define DEFINE_PRCMU_CLK_RATE(_name, _cg_off, _cg_bit, _reg, _rate)    \
+struct clk clk_##_name = {                                             \
+               .name           = #_name,                               \
+               .ops            = &clk_prcmu_ops,                       \
+               .prcmu_cg_off   = _cg_off,                              \
+               .prcmu_cg_bit   = _cg_bit,                              \
+               .rate           = _rate,                                \
+               .prcmu_cg_mgt   = PRCM_##_reg##_MGT                     \
+       }
+
+#define DEFINE_PRCC_CLK(_pclust, _name, _bus_en, _kernel_en, _kernclk) \
+struct clk clk_##_name = {                                             \
+               .name           = #_name,                               \
+               .ops            = &clk_prcc_ops,                        \
+               .cluster        = _pclust,                              \
+               .prcc_bus       = _bus_en,                              \
+               .prcc_kernel    = _kernel_en,                           \
+               .parent_cluster = &clk_per##_pclust##clk,               \
+               .parent_periph  = _kernclk                              \
+       }
+
+#define CLK(_clk, _devname, _conname)                  \
+       {                                               \
+               .clk    = &clk_##_clk,                  \
+               .dev_id = _devname,                     \
+               .con_id = _conname,                     \
+       }
diff --git a/arch/arm/mach-ux500/cpu-db5500.c b/arch/arm/mach-ux500/cpu-db5500.c
new file mode 100644 (file)
index 0000000..6a3ac45
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+#include <linux/io.h>
+
+#include <asm/mach/map.h>
+
+#include <mach/hardware.h>
+#include <mach/devices.h>
+#include <mach/setup.h>
+
+static struct map_desc u5500_io_desc[] __initdata = {
+       __IO_DEV_DESC(U5500_GPIO0_BASE, SZ_4K),
+       __IO_DEV_DESC(U5500_GPIO1_BASE, SZ_4K),
+       __IO_DEV_DESC(U5500_GPIO2_BASE, SZ_4K),
+       __IO_DEV_DESC(U5500_GPIO3_BASE, SZ_4K),
+       __IO_DEV_DESC(U5500_GPIO4_BASE, SZ_4K),
+};
+
+static struct platform_device *u5500_platform_devs[] __initdata = {
+       &u5500_gpio_devs[0],
+       &u5500_gpio_devs[1],
+       &u5500_gpio_devs[2],
+       &u5500_gpio_devs[3],
+       &u5500_gpio_devs[4],
+       &u5500_gpio_devs[5],
+       &u5500_gpio_devs[6],
+       &u5500_gpio_devs[7],
+};
+
+void __init u5500_map_io(void)
+{
+       ux500_map_io();
+
+       iotable_init(u5500_io_desc, ARRAY_SIZE(u5500_io_desc));
+}
+
+void __init u5500_init_devices(void)
+{
+       ux500_init_devices();
+
+       platform_add_devices(u5500_platform_devs,
+                            ARRAY_SIZE(u5500_platform_devs));
+}
similarity index 53%
rename from arch/arm/mach-ux500/cpu-u8500.c
rename to arch/arm/mach-ux500/cpu-db8500.c
index 397bc1f..d04299f 100644 (file)
 #include <linux/device.h>
 #include <linux/amba/bus.h>
 #include <linux/irq.h>
+#include <linux/gpio.h>
 #include <linux/platform_device.h>
+#include <linux/io.h>
 
-#include <asm/hardware/gic.h>
 #include <asm/mach/map.h>
 #include <mach/hardware.h>
+#include <mach/setup.h>
+#include <mach/devices.h>
 
-/* add any platform devices here - TODO */
 static struct platform_device *platform_devs[] __initdata = {
-       /* yet to be added, add i2c0, gpio.. */
+       &u8500_gpio_devs[0],
+       &u8500_gpio_devs[1],
+       &u8500_gpio_devs[2],
+       &u8500_gpio_devs[3],
+       &u8500_gpio_devs[4],
+       &u8500_gpio_devs[5],
+       &u8500_gpio_devs[6],
+       &u8500_gpio_devs[7],
+       &u8500_gpio_devs[8],
 };
 
-#define __IO_DEV_DESC(x, sz)   {               \
-       .virtual        = IO_ADDRESS(x),        \
-       .pfn            = __phys_to_pfn(x),     \
-       .length         = sz,                   \
-       .type           = MT_DEVICE,            \
-}
-
 /* minimum static i/o mapping required to boot U8500 platforms */
 static struct map_desc u8500_io_desc[] __initdata = {
-       __IO_DEV_DESC(U8500_UART2_BASE, SZ_4K),
-       __IO_DEV_DESC(U8500_GIC_CPU_BASE, SZ_4K),
-       __IO_DEV_DESC(U8500_GIC_DIST_BASE, SZ_4K),
+       __IO_DEV_DESC(U8500_PRCMU_BASE, SZ_4K),
+       __IO_DEV_DESC(U8500_GPIO0_BASE, SZ_4K),
+       __IO_DEV_DESC(U8500_GPIO1_BASE, SZ_4K),
+       __IO_DEV_DESC(U8500_GPIO2_BASE, SZ_4K),
+       __IO_DEV_DESC(U8500_GPIO3_BASE, SZ_4K),
+};
+
+static struct map_desc u8500ed_io_desc[] __initdata = {
+       __IO_DEV_DESC(U8500_MTU0_BASE_ED, SZ_4K),
+       __IO_DEV_DESC(U8500_CLKRST7_BASE_ED, SZ_8K),
+};
+
+static struct map_desc u8500v1_io_desc[] __initdata = {
        __IO_DEV_DESC(U8500_MTU0_BASE, SZ_4K),
-       __IO_DEV_DESC(U8500_TWD_BASE, SZ_4K),
-       __IO_DEV_DESC(U8500_SCU_BASE, SZ_4K),
-       __IO_DEV_DESC(U8500_BACKUPRAM0_BASE, SZ_8K),
 };
 
 void __init u8500_map_io(void)
 {
+       ux500_map_io();
+
        iotable_init(u8500_io_desc, ARRAY_SIZE(u8500_io_desc));
-}
 
-void __init u8500_init_irq(void)
-{
-       gic_dist_init(0, __io_address(U8500_GIC_DIST_BASE), 29);
-       gic_cpu_init(0, __io_address(U8500_GIC_CPU_BASE));
+       if (cpu_is_u8500ed())
+               iotable_init(u8500ed_io_desc, ARRAY_SIZE(u8500ed_io_desc));
+       else
+               iotable_init(u8500v1_io_desc, ARRAY_SIZE(u8500v1_io_desc));
 }
 
 /*
@@ -58,6 +69,8 @@ void __init u8500_init_irq(void)
  */
 void __init u8500_init_devices(void)
 {
+       ux500_init_devices();
+
        /* Register the platform devices */
        platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
 
diff --git a/arch/arm/mach-ux500/cpu.c b/arch/arm/mach-ux500/cpu.c
new file mode 100644 (file)
index 0000000..d81ad02
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+
+#include <asm/hardware/cache-l2x0.h>
+#include <asm/hardware/gic.h>
+#include <asm/mach/map.h>
+#include <asm/localtimer.h>
+
+#include <plat/mtu.h>
+#include <mach/hardware.h>
+#include <mach/setup.h>
+#include <mach/devices.h>
+
+#include "clock.h"
+
+static struct map_desc ux500_io_desc[] __initdata = {
+       __IO_DEV_DESC(UX500_UART0_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_UART2_BASE, SZ_4K),
+
+       __IO_DEV_DESC(UX500_GIC_CPU_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_GIC_DIST_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_L2CC_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_TWD_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_SCU_BASE, SZ_4K),
+
+       __IO_DEV_DESC(UX500_CLKRST1_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_CLKRST2_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_CLKRST3_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_CLKRST5_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_CLKRST6_BASE, SZ_4K),
+
+       __IO_DEV_DESC(UX500_MTU0_BASE, SZ_4K),
+       __IO_DEV_DESC(UX500_MTU1_BASE, SZ_4K),
+
+       __IO_DEV_DESC(UX500_BACKUPRAM0_BASE, SZ_8K),
+};
+
+static struct amba_device *ux500_amba_devs[] __initdata = {
+       &ux500_pl031_device,
+};
+
+void __init ux500_map_io(void)
+{
+       iotable_init(ux500_io_desc, ARRAY_SIZE(ux500_io_desc));
+}
+
+void __init ux500_init_devices(void)
+{
+       amba_add_devices(ux500_amba_devs, ARRAY_SIZE(ux500_amba_devs));
+}
+
+void __init ux500_init_irq(void)
+{
+       gic_dist_init(0, __io_address(UX500_GIC_DIST_BASE), 29);
+       gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
+}
+
+#ifdef CONFIG_CACHE_L2X0
+static int ux500_l2x0_init(void)
+{
+       void __iomem *l2x0_base;
+
+       l2x0_base = __io_address(UX500_L2CC_BASE);
+
+       /* 64KB way size, 8 way associativity, force WA */
+       l2x0_init(l2x0_base, 0x3e060000, 0xc0000fff);
+
+       return 0;
+}
+early_initcall(ux500_l2x0_init);
+#endif
+
+static void __init ux500_timer_init(void)
+{
+#ifdef CONFIG_LOCAL_TIMERS
+       /* Setup the local timer base */
+       twd_base = __io_address(UX500_TWD_BASE);
+#endif
+       /* Setup the MTU base */
+       if (cpu_is_u8500ed())
+               mtu_base = __io_address(U8500_MTU0_BASE_ED);
+       else
+               mtu_base = __io_address(UX500_MTU0_BASE);
+
+       nmdk_timer_init();
+}
+
+struct sys_timer ux500_timer = {
+       .init   = ux500_timer_init,
+};
diff --git a/arch/arm/mach-ux500/devices-db5500.c b/arch/arm/mach-ux500/devices-db5500.c
new file mode 100644 (file)
index 0000000..33e5b56
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/gpio.h>
+
+#include <mach/hardware.h>
+#include <mach/devices.h>
+
+static struct nmk_gpio_platform_data u5500_gpio_data[] = {
+       GPIO_DATA("GPIO-0-31", 0),
+       GPIO_DATA("GPIO-32-63", 32), /* 36..63 not routed to pin */
+       GPIO_DATA("GPIO-64-95", 64), /* 83..95 not routed to pin */
+       GPIO_DATA("GPIO-96-127", 96), /* 102..127 not routed to pin */
+       GPIO_DATA("GPIO-128-159", 128), /* 149..159 not routed to pin */
+       GPIO_DATA("GPIO-160-191", 160),
+       GPIO_DATA("GPIO-192-223", 192),
+       GPIO_DATA("GPIO-224-255", 224), /* 228..255 not routed to pin */
+};
+
+static struct resource u5500_gpio_resources[] = {
+       GPIO_RESOURCE(0),
+       GPIO_RESOURCE(1),
+       GPIO_RESOURCE(2),
+       GPIO_RESOURCE(3),
+       GPIO_RESOURCE(4),
+       GPIO_RESOURCE(5),
+       GPIO_RESOURCE(6),
+       GPIO_RESOURCE(7),
+};
+
+struct platform_device u5500_gpio_devs[] = {
+       GPIO_DEVICE(0),
+       GPIO_DEVICE(1),
+       GPIO_DEVICE(2),
+       GPIO_DEVICE(3),
+       GPIO_DEVICE(4),
+       GPIO_DEVICE(5),
+       GPIO_DEVICE(6),
+       GPIO_DEVICE(7),
+};
diff --git a/arch/arm/mach-ux500/devices-db8500.c b/arch/arm/mach-ux500/devices-db8500.c
new file mode 100644 (file)
index 0000000..2033423
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/amba/bus.h>
+
+#include <mach/hardware.h>
+#include <mach/setup.h>
+
+static struct nmk_gpio_platform_data u8500_gpio_data[] = {
+       GPIO_DATA("GPIO-0-31", 0),
+       GPIO_DATA("GPIO-32-63", 32), /* 37..63 not routed to pin */
+       GPIO_DATA("GPIO-64-95", 64),
+       GPIO_DATA("GPIO-96-127", 96), /* 98..127 not routed to pin */
+       GPIO_DATA("GPIO-128-159", 128),
+       GPIO_DATA("GPIO-160-191", 160), /* 172..191 not routed to pin */
+       GPIO_DATA("GPIO-192-223", 192),
+       GPIO_DATA("GPIO-224-255", 224), /* 231..255 not routed to pin */
+       GPIO_DATA("GPIO-256-288", 256), /* 268..288 not routed to pin */
+};
+
+static struct resource u8500_gpio_resources[] = {
+       GPIO_RESOURCE(0),
+       GPIO_RESOURCE(1),
+       GPIO_RESOURCE(2),
+       GPIO_RESOURCE(3),
+       GPIO_RESOURCE(4),
+       GPIO_RESOURCE(5),
+       GPIO_RESOURCE(6),
+       GPIO_RESOURCE(7),
+       GPIO_RESOURCE(8),
+};
+
+struct platform_device u8500_gpio_devs[] = {
+       GPIO_DEVICE(0),
+       GPIO_DEVICE(1),
+       GPIO_DEVICE(2),
+       GPIO_DEVICE(3),
+       GPIO_DEVICE(4),
+       GPIO_DEVICE(5),
+       GPIO_DEVICE(6),
+       GPIO_DEVICE(7),
+       GPIO_DEVICE(8),
+};
+
+struct amba_device u8500_ssp0_device = {
+       .dev = {
+               .coherent_dma_mask = ~0,
+               .init_name = "ssp0",
+       },
+       .res = {
+               .start = U8500_SSP0_BASE,
+               .end   = U8500_SSP0_BASE + SZ_4K - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       .irq = {IRQ_SSP0, NO_IRQ },
+       /* ST-Ericsson modified id */
+       .periphid = SSP_PER_ID,
+};
+
+static struct resource u8500_i2c0_resources[] = {
+       [0] = {
+               .start  = U8500_I2C0_BASE,
+               .end    = U8500_I2C0_BASE + SZ_4K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_I2C0,
+               .end    = IRQ_I2C0,
+               .flags  = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device u8500_i2c0_device = {
+       .name           = "nmk-i2c",
+       .id             = 0,
+       .resource       = u8500_i2c0_resources,
+       .num_resources  = ARRAY_SIZE(u8500_i2c0_resources),
+};
+
+static struct resource u8500_i2c4_resources[] = {
+       [0] = {
+               .start  = U8500_I2C4_BASE,
+               .end    = U8500_I2C4_BASE + SZ_4K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_I2C4,
+               .end    = IRQ_I2C4,
+               .flags  = IORESOURCE_IRQ,
+       }
+};
+
+struct platform_device u8500_i2c4_device = {
+       .name           = "nmk-i2c",
+       .id             = 4,
+       .resource       = u8500_i2c4_resources,
+       .num_resources  = ARRAY_SIZE(u8500_i2c4_resources),
+};
diff --git a/arch/arm/mach-ux500/devices.c b/arch/arm/mach-ux500/devices.c
new file mode 100644 (file)
index 0000000..8a26889
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/amba/bus.h>
+
+#include <mach/hardware.h>
+#include <mach/setup.h>
+
+#define __MEM_4K_RESOURCE(x) \
+       .res = {.start = (x), .end = (x) + SZ_4K - 1, .flags = IORESOURCE_MEM}
+
+struct amba_device ux500_pl031_device = {
+       .dev = {
+               .init_name = "pl031",
+       },
+       .res = {
+               .start  = UX500_RTC_BASE,
+               .end    = UX500_RTC_BASE + SZ_4K - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       .irq = {IRQ_RTC_RTT, NO_IRQ},
+};
+
+struct amba_device ux500_uart0_device = {
+       .dev = { .init_name = "uart0" },
+       __MEM_4K_RESOURCE(UX500_UART0_BASE),
+       .irq = {IRQ_UART0, NO_IRQ},
+};
+
+struct amba_device ux500_uart1_device = {
+       .dev = { .init_name = "uart1" },
+       __MEM_4K_RESOURCE(UX500_UART1_BASE),
+       .irq = {IRQ_UART1, NO_IRQ},
+};
+
+struct amba_device ux500_uart2_device = {
+       .dev = { .init_name = "uart2" },
+       __MEM_4K_RESOURCE(UX500_UART2_BASE),
+       .irq = {IRQ_UART2, NO_IRQ},
+};
+
+#define UX500_I2C_RESOURCES(id, size)                          \
+static struct resource ux500_i2c##id##_resources[] = {         \
+       [0] = {                                                 \
+               .start  = UX500_I2C##id##_BASE,                 \
+               .end    = UX500_I2C##id##_BASE + size - 1,      \
+               .flags  = IORESOURCE_MEM,                       \
+       },                                                      \
+       [1] = {                                                 \
+               .start  = IRQ_I2C##id,                          \
+               .end    = IRQ_I2C##id,                          \
+               .flags  = IORESOURCE_IRQ                        \
+       }                                                       \
+}
+
+UX500_I2C_RESOURCES(1, SZ_4K);
+UX500_I2C_RESOURCES(2, SZ_4K);
+UX500_I2C_RESOURCES(3, SZ_4K);
+
+#define UX500_I2C_PDEVICE(cid)                                 \
+struct platform_device ux500_i2c##cid##_device = {             \
+       .name           = "nmk-i2c",                            \
+       .id             = cid,                                  \
+       .num_resources  = 2,                                    \
+       .resource       = ux500_i2c##cid##_resources,           \
+}
+
+UX500_I2C_PDEVICE(1);
+UX500_I2C_PDEVICE(2);
+UX500_I2C_PDEVICE(3);
+
+void __init amba_add_devices(struct amba_device *devs[], int num)
+{
+       int i;
+
+       for (i = 0; i < num; i++) {
+               struct amba_device *d = devs[i];
+               amba_device_register(d, &iomem_resource);
+       }
+}
diff --git a/arch/arm/mach-ux500/include/mach/db5500-regs.h b/arch/arm/mach-ux500/include/mach/db5500-regs.h
new file mode 100644 (file)
index 0000000..545c80f
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __MACH_DB5500_REGS_H
+#define __MACH_DB5500_REGS_H
+
+#define U5500_PER1_BASE                0xA0020000
+#define U5500_PER2_BASE                0xA0010000
+#define U5500_PER3_BASE                0x80140000
+#define U5500_PER4_BASE                0x80150000
+#define U5500_PER5_BASE                0x80100000
+#define U5500_PER6_BASE                0x80120000
+
+#define U5500_GIC_DIST_BASE    0xA0411000
+#define U5500_GIC_CPU_BASE     0xA0410100
+#define U5500_DMA_BASE         0x90030000
+#define U5500_MCDE_BASE                0xA0400000
+#define U5500_MODEM_BASE       0xB0000000
+#define U5500_L2CC_BASE                0xA0412000
+#define U5500_SCU_BASE         0xA0410000
+#define U5500_DSI1_BASE                0xA0401000
+#define U5500_DSI2_BASE                0xA0402000
+#define U5500_SIA_BASE         0xA0100000
+#define U5500_SVA_BASE         0x80200000
+#define U5500_HSEM_BASE                0xA0000000
+#define U5500_NAND0_BASE       0x60000000
+#define U5500_NAND1_BASE       0x70000000
+#define U5500_TWD_BASE         0xa0410600
+#define U5500_B2R2_BASE                0xa0200000
+
+#define U5500_FSMC_BASE                (U5500_PER1_BASE + 0x0000)
+#define U5500_SDI0_BASE                (U5500_PER1_BASE + 0x1000)
+#define U5500_SDI2_BASE                (U5500_PER1_BASE + 0x2000)
+#define U5500_UART0_BASE       (U5500_PER1_BASE + 0x3000)
+#define U5500_I2C1_BASE                (U5500_PER1_BASE + 0x4000)
+#define U5500_MSP0_BASE                (U5500_PER1_BASE + 0x5000)
+#define U5500_GPIO0_BASE       (U5500_PER1_BASE + 0xE000)
+#define U5500_CLKRST1_BASE     (U5500_PER1_BASE + 0xF000)
+
+#define U5500_USBOTG_BASE      (U5500_PER2_BASE + 0x0000)
+#define U5500_GPIO1_BASE       (U5500_PER2_BASE + 0xE000)
+#define U5500_CLKRST2_BASE     (U5500_PER2_BASE + 0xF000)
+
+#define U5500_KEYPAD_BASE      (U5500_PER3_BASE + 0x0000)
+#define U5500_PWM_BASE         (U5500_PER3_BASE + 0x1000)
+#define U5500_GPIO3_BASE       (U5500_PER3_BASE + 0xE000)
+#define U5500_CLKRST3_BASE     (U5500_PER3_BASE + 0xF000)
+
+#define U5500_BACKUPRAM0_BASE  (U5500_PER4_BASE + 0x0000)
+#define U5500_BACKUPRAM1_BASE  (U5500_PER4_BASE + 0x1000)
+#define U5500_RTT0_BASE                (U5500_PER4_BASE + 0x2000)
+#define U5500_RTT1_BASE                (U5500_PER4_BASE + 0x3000)
+#define U5500_RTC_BASE         (U5500_PER4_BASE + 0x4000)
+#define U5500_SCR_BASE         (U5500_PER4_BASE + 0x5000)
+#define U5500_DMC_BASE         (U5500_PER4_BASE + 0x6000)
+#define U5500_PRCMU_BASE       (U5500_PER4_BASE + 0x7000)
+#define U5500_MSP1_BASE                (U5500_PER4_BASE + 0x9000)
+#define U5500_GPIO2_BASE       (U5500_PER4_BASE + 0xA000)
+#define U5500_CDETECT_BASE     (U5500_PER4_BASE + 0xF000)
+
+#define U5500_SPI0_BASE                (U5500_PER5_BASE + 0x0000)
+#define U5500_SPI1_BASE                (U5500_PER5_BASE + 0x1000)
+#define U5500_SPI2_BASE                (U5500_PER5_BASE + 0x2000)
+#define U5500_SPI3_BASE                (U5500_PER5_BASE + 0x3000)
+#define U5500_UART1_BASE       (U5500_PER5_BASE + 0x4000)
+#define U5500_UART2_BASE       (U5500_PER5_BASE + 0x5000)
+#define U5500_UART3_BASE       (U5500_PER5_BASE + 0x6000)
+#define U5500_SDI1_BASE                (U5500_PER5_BASE + 0x7000)
+#define U5500_SDI3_BASE                (U5500_PER5_BASE + 0x8000)
+#define U5500_SDI4_BASE                (U5500_PER5_BASE + 0x9000)
+#define U5500_I2C2_BASE                (U5500_PER5_BASE + 0xA000)
+#define U5500_I2C3_BASE                (U5500_PER5_BASE + 0xB000)
+#define U5500_MSP2_BASE                (U5500_PER5_BASE + 0xC000)
+#define U5500_IRDA_BASE                (U5500_PER5_BASE + 0xD000)
+#define U5500_IRRC_BASE                (U5500_PER5_BASE + 0x10000)
+#define U5500_GPIO4_BASE       (U5500_PER5_BASE + 0x1E000)
+#define U5500_CLKRST5_BASE     (U5500_PER5_BASE + 0x1F000)
+
+#define U5500_RNG_BASE         (U5500_PER6_BASE + 0x0000)
+#define U5500_HASH0_BASE       (U5500_PER6_BASE + 0x1000)
+#define U5500_HASH1_BASE       (U5500_PER6_BASE + 0x2000)
+#define U5500_PKA_BASE         (U5500_PER6_BASE + 0x4000)
+#define U5500_PKAM_BASE                (U5500_PER6_BASE + 0x5000)
+#define U5500_MTU0_BASE                (U5500_PER6_BASE + 0x6000)
+#define U5500_MTU1_BASE                (U5500_PER6_BASE + 0x7000)
+#define U5500_CR_BASE          (U5500_PER6_BASE + 0x8000)
+#define U5500_CRYP0_BASE       (U5500_PER6_BASE + 0xA000)
+#define U5500_CRYP1_BASE       (U5500_PER6_BASE + 0xB000)
+#define U5500_CLKRST6_BASE     (U5500_PER6_BASE + 0xF000)
+
+#define U5500_GPIOBANK0_BASE   U5500_GPIO0_BASE
+#define U5500_GPIOBANK1_BASE   (U5500_GPIO0_BASE + 0x80)
+#define U5500_GPIOBANK2_BASE   U5500_GPIO1_BASE
+#define U5500_GPIOBANK3_BASE   U5500_GPIO2_BASE
+#define U5500_GPIOBANK4_BASE   U5500_GPIO3_BASE
+#define U5500_GPIOBANK5_BASE   U5500_GPIO4_BASE
+#define U5500_GPIOBANK6_BASE   (U5500_GPIO4_BASE + 0x80)
+#define U5500_GPIOBANK7_BASE   (U5500_GPIO4_BASE + 0x100)
+
+#endif
diff --git a/arch/arm/mach-ux500/include/mach/db8500-regs.h b/arch/arm/mach-ux500/include/mach/db8500-regs.h
new file mode 100644 (file)
index 0000000..9169e1e
--- /dev/null
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __MACH_DB8500_REGS_H
+#define __MACH_DB8500_REGS_H
+
+#define U8500_PER3_BASE                0x80000000
+#define U8500_STM_BASE         0x80100000
+#define U8500_STM_REG_BASE     (U8500_STM_BASE + 0xF000)
+#define U8500_PER2_BASE                0x80110000
+#define U8500_PER1_BASE                0x80120000
+#define U8500_B2R2_BASE                0x80130000
+#define U8500_HSEM_BASE                0x80140000
+#define U8500_PER4_BASE                0x80150000
+#define U8500_ICN_BASE         0x81000000
+
+#define U8500_BOOT_ROM_BASE    0x90000000
+/* ASIC ID is at 0xff4 offset within this region */
+#define U8500_ASIC_ID_BASE     0x9001F000
+
+#define U8500_PER6_BASE                0xa03c0000
+#define U8500_PER5_BASE                0xa03e0000
+#define U8500_PER7_BASE_ED     0xa03d0000
+
+#define U8500_SVA_BASE         0xa0100000
+#define U8500_SIA_BASE         0xa0200000
+
+#define U8500_SGA_BASE         0xa0300000
+#define U8500_MCDE_BASE                0xa0350000
+#define U8500_DMA_BASE_ED      0xa0362000
+#define U8500_DMA_BASE         0x801C0000      /* v1 */
+
+#define U8500_SBAG_BASE                0xa0390000
+
+#define U8500_SCU_BASE         0xa0410000
+#define U8500_GIC_CPU_BASE     0xa0410100
+#define U8500_TWD_BASE         0xa0410600
+#define U8500_GIC_DIST_BASE    0xa0411000
+#define U8500_L2CC_BASE                0xa0412000
+
+#define U8500_MODEM_I2C                0xb7e02000
+
+#define U8500_GPIO0_BASE       (U8500_PER1_BASE + 0xE000)
+#define U8500_GPIO1_BASE       (U8500_PER3_BASE + 0xE000)
+#define U8500_GPIO2_BASE       (U8500_PER2_BASE + 0xE000)
+#define U8500_GPIO3_BASE       (U8500_PER5_BASE + 0x1E000)
+
+/* per7 base addressess */
+#define U8500_CR_BASE_ED       (U8500_PER7_BASE_ED + 0x8000)
+#define U8500_MTU0_BASE_ED     (U8500_PER7_BASE_ED + 0xa000)
+#define U8500_MTU1_BASE_ED     (U8500_PER7_BASE_ED + 0xb000)
+#define U8500_TZPC0_BASE_ED    (U8500_PER7_BASE_ED + 0xc000)
+#define U8500_CLKRST7_BASE_ED  (U8500_PER7_BASE_ED + 0xf000)
+
+#define U8500_UART0_BASE       (U8500_PER1_BASE + 0x0000)
+#define U8500_UART1_BASE       (U8500_PER1_BASE + 0x1000)
+
+/* per6 base addressess */
+#define U8500_RNG_BASE         (U8500_PER6_BASE + 0x0000)
+#define U8500_PKA_BASE         (U8500_PER6_BASE + 0x1000)
+#define U8500_PKAM_BASE                (U8500_PER6_BASE + 0x2000)
+#define U8500_MTU0_BASE                (U8500_PER6_BASE + 0x6000) /* v1 */
+#define U8500_MTU1_BASE                (U8500_PER6_BASE + 0x7000) /* v1 */
+#define U8500_CR_BASE          (U8500_PER6_BASE + 0x8000) /* v1 */
+#define U8500_CRYPTO0_BASE     (U8500_PER6_BASE + 0xa000)
+#define U8500_CRYPTO1_BASE     (U8500_PER6_BASE + 0xb000)
+#define U8500_CLKRST6_BASE     (U8500_PER6_BASE + 0xf000)
+
+/* per5 base addressess */
+#define U8500_USBOTG_BASE      (U8500_PER5_BASE + 0x00000)
+#define U8500_CLKRST5_BASE     (U8500_PER5_BASE + 0x1f000)
+
+/* per4 base addressess */
+#define U8500_BACKUPRAM0_BASE  (U8500_PER4_BASE + 0x00000)
+#define U8500_BACKUPRAM1_BASE  (U8500_PER4_BASE + 0x01000)
+#define U8500_RTT0_BASE                (U8500_PER4_BASE + 0x02000)
+#define U8500_RTT1_BASE                (U8500_PER4_BASE + 0x03000)
+#define U8500_RTC_BASE         (U8500_PER4_BASE + 0x04000)
+#define U8500_SCR_BASE         (U8500_PER4_BASE + 0x05000)
+#define U8500_DMC_BASE         (U8500_PER4_BASE + 0x06000)
+#define U8500_PRCMU_BASE       (U8500_PER4_BASE + 0x07000)
+#define U8500_PRCMU_TCDM_BASE  (U8500_PER4_BASE + 0x0f000)
+
+/* per3 base addresses */
+#define U8500_FSMC_BASE                (U8500_PER3_BASE + 0x0000)
+#define U8500_SSP0_BASE                (U8500_PER3_BASE + 0x2000)
+#define U8500_SSP1_BASE                (U8500_PER3_BASE + 0x3000)
+#define U8500_I2C0_BASE                (U8500_PER3_BASE + 0x4000)
+#define U8500_SDI2_BASE                (U8500_PER3_BASE + 0x5000)
+#define U8500_SKE_BASE         (U8500_PER3_BASE + 0x6000)
+#define U8500_UART2_BASE       (U8500_PER3_BASE + 0x7000)
+#define U8500_SDI5_BASE                (U8500_PER3_BASE + 0x8000)
+#define U8500_CLKRST3_BASE     (U8500_PER3_BASE + 0xf000)
+
+/* per2 base addressess */
+#define U8500_I2C3_BASE                (U8500_PER2_BASE + 0x0000)
+#define U8500_SPI2_BASE                (U8500_PER2_BASE + 0x1000)
+#define U8500_SPI1_BASE                (U8500_PER2_BASE + 0x2000)
+#define U8500_PWL_BASE         (U8500_PER2_BASE + 0x3000)
+#define U8500_SDI4_BASE                (U8500_PER2_BASE + 0x4000)
+#define U8500_MSP2_BASE                (U8500_PER2_BASE + 0x7000)
+#define U8500_SDI1_BASE                (U8500_PER2_BASE + 0x8000)
+#define U8500_SDI3_BASE                (U8500_PER2_BASE + 0x9000)
+#define U8500_SPI0_BASE                (U8500_PER2_BASE + 0xa000)
+#define U8500_HSIR_BASE                (U8500_PER2_BASE + 0xb000)
+#define U8500_HSIT_BASE                (U8500_PER2_BASE + 0xc000)
+#define U8500_CLKRST2_BASE     (U8500_PER2_BASE + 0xf000)
+
+/* per1 base addresses */
+#define U8500_I2C1_BASE                (U8500_PER1_BASE + 0x2000)
+#define U8500_MSP0_BASE                (U8500_PER1_BASE + 0x3000)
+#define U8500_MSP1_BASE                (U8500_PER1_BASE + 0x4000)
+#define U8500_SDI0_BASE                (U8500_PER1_BASE + 0x6000)
+#define U8500_I2C2_BASE                (U8500_PER1_BASE + 0x8000)
+#define U8500_SPI3_BASE                (U8500_PER1_BASE + 0x9000)
+#define U8500_I2C4_BASE                (U8500_PER1_BASE + 0xa000)
+#define U8500_SLIM0_BASE       (U8500_PER1_BASE + 0xb000)
+#define U8500_CLKRST1_BASE     (U8500_PER1_BASE + 0xf000)
+
+#define U8500_SHRM_GOP_INTERRUPT_BASE  0xB7C00040
+
+#define U8500_GPIOBANK0_BASE   U8500_GPIO0_BASE
+#define U8500_GPIOBANK1_BASE   (U8500_GPIO0_BASE + 0x80)
+#define U8500_GPIOBANK2_BASE   U8500_GPIO1_BASE
+#define U8500_GPIOBANK3_BASE   (U8500_GPIO1_BASE + 0x80)
+#define U8500_GPIOBANK4_BASE   (U8500_GPIO1_BASE + 0x100)
+#define U8500_GPIOBANK5_BASE   (U8500_GPIO1_BASE + 0x180)
+#define U8500_GPIOBANK6_BASE   U8500_GPIO2_BASE
+#define U8500_GPIOBANK7_BASE   (U8500_GPIO2_BASE + 0x80)
+#define U8500_GPIOBANK8_BASE   U8500_GPIO3_BASE
+
+#endif
index 09cbfda..c5203b7 100644 (file)
  */
 #include <mach/hardware.h>
 
+#if CONFIG_UX500_DEBUG_UART > 2
+#error Invalid Ux500 debug UART
+#endif
+
+#define __UX500_UART(n)        UX500_UART##n##_BASE
+#define UX500_UART(n)  __UX500_UART(n)
+#define UART_BASE      UX500_UART(CONFIG_UX500_DEBUG_UART)
+
        .macro  addruart, rx, tmp
        mrc     p15, 0, \rx, c1, c0
        tst     \rx, #1                                 @ MMU enabled?
-       ldreq   \rx, =U8500_UART2_BASE                  @ no, physical address
-       ldrne   \rx, =IO_ADDRESS(U8500_UART2_BASE)      @ yes, virtual address
+       ldreq   \rx, =UART_BASE                         @ no, physical address
+       ldrne   \rx, =IO_ADDRESS(UART_BASE)             @ yes, virtual address
        .endm
 
 #include <asm/hardware/debug-pl01x.S>
diff --git a/arch/arm/mach-ux500/include/mach/devices.h b/arch/arm/mach-ux500/include/mach/devices.h
new file mode 100644 (file)
index 0000000..0422af0
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __ASM_ARCH_DEVICES_H__
+#define __ASM_ARCH_DEVICES_H__
+
+struct platform_device;
+struct amba_device;
+
+extern struct platform_device u5500_gpio_devs[];
+extern struct platform_device u8500_gpio_devs[];
+
+extern struct amba_device ux500_pl031_device;
+extern struct amba_device u8500_ssp0_device;
+extern struct amba_device ux500_uart0_device;
+extern struct amba_device ux500_uart1_device;
+extern struct amba_device ux500_uart2_device;
+
+extern struct platform_device ux500_i2c1_device;
+extern struct platform_device ux500_i2c2_device;
+extern struct platform_device ux500_i2c3_device;
+
+extern struct platform_device u8500_i2c0_device;
+extern struct platform_device u8500_i2c4_device;
+
+#endif
index eece330..60ea88d 100644 (file)
@@ -17,7 +17,7 @@
                .endm
 
                .macro  get_irqnr_preamble, base, tmp
-               ldr     \base, =IO_ADDRESS(U8500_GIC_CPU_BASE)
+               ldr     \base, =IO_ADDRESS(UX500_GIC_CPU_BASE)
                .endm
 
                .macro  arch_ret_to_user, tmp1, tmp2
diff --git a/arch/arm/mach-ux500/include/mach/gpio.h b/arch/arm/mach-ux500/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..d548a62
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef __ASM_ARCH_GPIO_H
+#define __ASM_ARCH_GPIO_H
+
+/*
+ * 288 (#267 is the highest one actually hooked up) onchip GPIOs, plus enough
+ * room for a couple of GPIO expanders.
+ */
+#define ARCH_NR_GPIOS  350
+
+#include <plat/gpio.h>
+
+#define __GPIO_RESOURCE(soc, block)                                    \
+       {                                                               \
+               .start  = soc##_GPIOBANK##block##_BASE,                 \
+               .end    = soc##_GPIOBANK##block##_BASE + 127,           \
+               .flags  = IORESOURCE_MEM,                               \
+       },                                                              \
+       {                                                               \
+               .start  = IRQ_GPIO##block,                              \
+               .end    = IRQ_GPIO##block,                              \
+               .flags  = IORESOURCE_IRQ,                               \
+       }
+
+#define __GPIO_DEVICE(soc, block)                                      \
+       {                                                               \
+               .name           = "gpio",                               \
+               .id             = block,                                \
+               .num_resources  = 2,                                    \
+               .resource       = &soc##_gpio_resources[block * 2],     \
+               .dev = {                                                \
+                       .platform_data = &soc##_gpio_data[block],       \
+               },                                                      \
+       }
+
+#define GPIO_DATA(_name, first)                                                \
+       {                                                               \
+               .name           = _name,                                \
+               .first_gpio     = first,                                \
+               .first_irq      = NOMADIK_GPIO_TO_IRQ(first),           \
+       }
+
+#ifdef CONFIG_UX500_SOC_DB8500
+#define GPIO_RESOURCE(block)   __GPIO_RESOURCE(U8500, block)
+#define GPIO_DEVICE(block)     __GPIO_DEVICE(u8500, block)
+#elif defined(CONFIG_UX500_SOC_DB5500)
+#define GPIO_RESOURCE(block)   __GPIO_RESOURCE(U5500, block)
+#define GPIO_DEVICE(block)     __GPIO_DEVICE(u5500, block)
+#endif
+
+#endif /* __ASM_ARCH_GPIO_H */
index 04ea836..8656379 100644 (file)
 
 /* typesafe io address */
 #define __io_address(n)                __io(IO_ADDRESS(n))
+/* used by some plat-nomadik code */
+#define io_p2v(n)              __io_address(n)
 
-/*
- * Base address definitions for U8500 Onchip IPs. All the
- * peripherals are contained in a single 1 Mbyte region, with
- * AHB peripherals at the bottom and APB peripherals at the
- * top of the region. PER stands for PERIPHERAL region which
- * itself divided into sub regions.
- */
-#define U8500_PER3_BASE                0x80000000
-#define U8500_PER2_BASE                0x80110000
-#define U8500_PER1_BASE                0x80120000
-#define U8500_PER4_BASE                0x80150000
-
-#define U8500_PER6_BASE                0xa03c0000
-#define U8500_PER5_BASE                0xa03e0000
-#define U8500_PER7_BASE                0xa03d0000
-
-#define U8500_SVA_BASE         0xa0100000
-#define U8500_SIA_BASE         0xa0200000
-
-#define U8500_SGA_BASE         0xa0300000
-#define U8500_MCDE_BASE                0xa0350000
-#define U8500_DMA_BASE         0xa0362000
-
-#define U8500_SCU_BASE         0xa0410000
-#define U8500_GIC_CPU_BASE     0xa0410100
-#define U8500_TWD_BASE         0xa0410600
-#define U8500_GIC_DIST_BASE    0xa0411000
-#define U8500_L2CC_BASE                0xa0412000
-
-#define U8500_TWD_SIZE         0x100
-
-/* per7 base addressess */
-#define U8500_CR_BASE          (U8500_PER7_BASE + 0x8000)
-#define U8500_MTU0_BASE                (U8500_PER7_BASE + 0xa000)
-#define U8500_MTU1_BASE                (U8500_PER7_BASE + 0xb000)
-#define U8500_TZPC0_BASE       (U8500_PER7_BASE + 0xc000)
-#define U8500_CLKRST7_BASE     (U8500_PER7_BASE + 0xf000)
-
-/* per6 base addressess */
-#define U8500_RNG_BASE         (U8500_PER6_BASE + 0x0000)
-#define U8500_PKA_BASE         (U8500_PER6_BASE + 0x1000)
-#define U8500_PKAM_BASE                (U8500_PER6_BASE + 0x2000)
-#define U8500_CRYPTO0_BASE     (U8500_PER6_BASE + 0xa000)
-#define U8500_CRYPTO1_BASE     (U8500_PER6_BASE + 0xb000)
-#define U8500_CLKRST6_BASE     (U8500_PER6_BASE + 0xf000)
-
-/* per5 base addressess */
-#define U8500_USBOTG_BASE      (U8500_PER5_BASE + 0x00000)
-#define U8500_GPIO5_BASE       (U8500_PER5_BASE + 0x1e000)
-#define U8500_CLKRST5_BASE     (U8500_PER5_BASE + 0x1f000)
-
-/* per4 base addressess */
-#define U8500_BACKUPRAM0_BASE  (U8500_PER4_BASE + 0x0000)
-#define U8500_BACKUPRAM1_BASE  (U8500_PER4_BASE + 0x1000)
-#define U8500_RTT0_BASE                (U8500_PER4_BASE + 0x2000)
-#define U8500_RTT1_BASE                (U8500_PER4_BASE + 0x3000)
-#define U8500_RTC_BASE         (U8500_PER4_BASE + 0x4000)
-#define U8500_SCR_BASE         (U8500_PER4_BASE + 0x5000)
-#define U8500_DMC_BASE         (U8500_PER4_BASE + 0x6000)
-#define U8500_PRCMU_BASE       (U8500_PER4_BASE + 0x7000)
-
-/* per3 base addressess */
-#define U8500_FSMC_BASE                (U8500_PER3_BASE + 0x0000)
-#define U8500_SSP0_BASE                (U8500_PER3_BASE + 0x2000)
-#define U8500_SSP1_BASE                (U8500_PER3_BASE + 0x3000)
-#define U8500_I2C0_BASE                (U8500_PER3_BASE + 0x4000)
-#define U8500_SDI2_BASE                (U8500_PER3_BASE + 0x5000)
-#define U8500_SKE_BASE         (U8500_PER3_BASE + 0x6000)
-#define U8500_UART2_BASE       (U8500_PER3_BASE + 0x7000)
-#define U8500_SDI5_BASE                (U8500_PER3_BASE + 0x8000)
-#define U8500_GPIO3_BASE       (U8500_PER3_BASE + 0xe000)
-#define U8500_CLKRST3_BASE     (U8500_PER3_BASE + 0xf000)
-
-/* per2 base addressess */
-#define U8500_I2C3_BASE                (U8500_PER2_BASE + 0x0000)
-#define U8500_SPI2_BASE                (U8500_PER2_BASE + 0x1000)
-#define U8500_SPI1_BASE                (U8500_PER2_BASE + 0x2000)
-#define U8500_PWL_BASE         (U8500_PER2_BASE + 0x3000)
-#define U8500_SDI4_BASE                (U8500_PER2_BASE + 0x4000)
-#define U8500_MSP2_BASE                (U8500_PER2_BASE + 0x7000)
-#define U8500_SDI1_BASE                (U8500_PER2_BASE + 0x8000)
-#define U8500_SDI3_BASE                (U8500_PER2_BASE + 0x9000)
-#define U8500_SPI0_BASE                (U8500_PER2_BASE + 0xa000)
-#define U8500_HSIR_BASE                (U8500_PER2_BASE + 0xb000)
-#define U8500_HSIT_BASE                (U8500_PER2_BASE + 0xc000)
-#define U8500_GPIO2_BASE       (U8500_PER2_BASE + 0xe000)
-#define U8500_CLKRST2_BASE     (U8500_PER2_BASE + 0xf000)
-
-/* per1 base addresses */
-#define U8500_UART0_BASE       (U8500_PER1_BASE + 0x0000)
-#define U8500_UART1_BASE       (U8500_PER1_BASE + 0x1000)
-#define U8500_I2C1_BASE                (U8500_PER1_BASE + 0x2000)
-#define U8500_MSP0_BASE                (U8500_PER1_BASE + 0x3000)
-#define U8500_MSP1_BASE                (U8500_PER1_BASE + 0x4000)
-#define U8500_SDI0_BASE                (U8500_PER1_BASE + 0x6000)
-#define U8500_I2C2_BASE                (U8500_PER1_BASE + 0x8000)
-#define U8500_SPI3_BASE                (U8500_PER1_BASE + 0x9000)
-#define U8500_SLIM0_BASE       (U8500_PER1_BASE + 0xa000)
-#define U8500_GPIO1_BASE       (U8500_PER1_BASE + 0xe000)
-#define U8500_CLKRST1_BASE     (U8500_PER1_BASE + 0xf000)
+#include <mach/db8500-regs.h>
+#include <mach/db5500-regs.h>
+
+#ifdef CONFIG_UX500_SOC_DB8500
+#define UX500(periph)          U8500_##periph##_BASE
+#elif defined(CONFIG_UX500_SOC_DB5500)
+#define UX500(periph)          U5500_##periph##_BASE
+#endif
+
+#define UX500_BACKUPRAM0_BASE  UX500(BACKUPRAM0)
+#define UX500_BACKUPRAM1_BASE  UX500(BACKUPRAM1)
+#define UX500_B2R2_BASE                UX500(B2R2)
+
+#define UX500_CLKRST1_BASE     UX500(CLKRST1)
+#define UX500_CLKRST2_BASE     UX500(CLKRST2)
+#define UX500_CLKRST3_BASE     UX500(CLKRST3)
+#define UX500_CLKRST5_BASE     UX500(CLKRST5)
+#define UX500_CLKRST6_BASE     UX500(CLKRST6)
+
+#define UX500_DMA_BASE         UX500(DMA)
+#define UX500_FSMC_BASE                UX500(FSMC)
+
+#define UX500_GIC_CPU_BASE     UX500(GIC_CPU)
+#define UX500_GIC_DIST_BASE    UX500(GIC_DIST)
+
+#define UX500_I2C1_BASE                UX500(I2C1)
+#define UX500_I2C2_BASE                UX500(I2C2)
+#define UX500_I2C3_BASE                UX500(I2C3)
+
+#define UX500_L2CC_BASE                UX500(L2CC)
+#define UX500_MCDE_BASE                UX500(MCDE)
+#define UX500_MTU0_BASE                UX500(MTU0)
+#define UX500_MTU1_BASE                UX500(MTU1)
+#define UX500_PRCMU_BASE       UX500(PRCMU)
+
+#define UX500_RNG_BASE         UX500(RNG)
+#define UX500_RTC_BASE         UX500(RTC)
+
+#define UX500_SCU_BASE         UX500(SCU)
+
+#define UX500_SDI0_BASE                UX500(SDI0)
+#define UX500_SDI1_BASE                UX500(SDI1)
+#define UX500_SDI2_BASE                UX500(SDI2)
+#define UX500_SDI3_BASE                UX500(SDI3)
+#define UX500_SDI4_BASE                UX500(SDI4)
+
+#define UX500_SPI0_BASE                UX500(SPI0)
+#define UX500_SPI1_BASE                UX500(SPI1)
+#define UX500_SPI2_BASE                UX500(SPI2)
+#define UX500_SPI3_BASE                UX500(SPI3)
+
+#define UX500_SIA_BASE         UX500(SIA)
+#define UX500_SVA_BASE         UX500(SVA)
+
+#define UX500_TWD_BASE         UX500(TWD)
+
+#define UX500_UART0_BASE       UX500(UART0)
+#define UX500_UART1_BASE       UX500(UART1)
+#define UX500_UART2_BASE       UX500(UART2)
+
+#define UX500_USBOTG_BASE      UX500(USBOTG)
 
 /* ST-Ericsson modified pl022 id */
 #define SSP_PER_ID             0x01080022
 
+#ifndef __ASSEMBLY__
+
+#include <asm/cputype.h>
+
+static inline bool cpu_is_u8500(void)
+{
+#ifdef CONFIG_UX500_SOC_DB8500
+       return 1;
+#else
+       return 0;
+#endif
+}
+
+static inline bool cpu_is_u8500ed(void)
+{
+       return cpu_is_u8500() && (read_cpuid_id() & 15) == 0;
+}
+
+static inline bool cpu_is_u8500v1(void)
+{
+       return cpu_is_u8500() && (read_cpuid_id() & 15) == 1;
+}
+
+static inline bool cpu_is_u5500(void)
+{
+#ifdef CONFIG_UX500_SOC_DB5500
+       return 1;
+#else
+       return 0;
+#endif
+}
+
+#endif
+
 #endif                         /* __MACH_HARDWARE_H */
index 394b5dd..7970684 100644 (file)
@@ -42,6 +42,7 @@
 #define IRQ_AB4500             (IRQ_SHPI_START + 40)
 #define IRQ_DISP               (IRQ_SHPI_START + 48)
 #define IRQ_SiPI3              (IRQ_SHPI_START + 49)
+#define IRQ_I2C4               (IRQ_SHPI_START + 51)
 #define IRQ_SSP1               (IRQ_SHPI_START + 52)
 #define IRQ_I2C2               (IRQ_SHPI_START + 55)
 #define IRQ_SDMMC0             (IRQ_SHPI_START + 60)
 /* There are 128 shared peripheral interrupts assigned to
  * INTID[160:32]. The first 32 interrupts are reserved.
  */
-#define NR_IRQS                        161
+#define U8500_SOC_NR_IRQS              161
+
+/* After chip-specific IRQ numbers we have the GPIO ones */
+#define NOMADIK_NR_GPIO                        288
+#define NOMADIK_GPIO_TO_IRQ(gpio)      ((gpio) + U8500_SOC_NR_IRQS)
+#define NOMADIK_IRQ_TO_GPIO(irq)       ((irq) - U8500_SOC_NR_IRQS)
+#define NR_IRQS                                NOMADIK_GPIO_TO_IRQ(NOMADIK_NR_GPIO)
 
 #endif /*ASM_ARCH_IRQS_H*/
index cf0ce16..e978dbd 100644 (file)
 #include <asm/mach/time.h>
 #include <linux/init.h>
 
-extern void u8500_map_io(void);
-extern void u8500_init_devices(void);
-extern void u8500_init_irq(void);
+extern void __init ux500_map_io(void);
+extern void __init u5500_map_io(void);
+extern void __init u8500_map_io(void);
+
+extern void __init ux500_init_devices(void);
+extern void __init u5500_init_devices(void);
+extern void __init u8500_init_devices(void);
+
+extern void __init ux500_init_irq(void);
 /* We re-use nomadik_timer for this platform */
 extern void nmdk_timer_init(void);
 
+extern void __init amba_add_devices(struct amba_device *devs[], int num);
+
+struct sys_timer;
+extern struct sys_timer ux500_timer;
+
+#define __IO_DEV_DESC(x, sz)   {               \
+       .virtual        = IO_ADDRESS(x),        \
+       .pfn            = __phys_to_pfn(x),     \
+       .length         = sz,                   \
+       .type           = MT_DEVICE,            \
+}
+
 #endif /*  __ASM_ARCH_SETUP_H */
index 8dfe7ca..438ef16 100644 (file)
@@ -30,7 +30,7 @@ volatile int __cpuinitdata pen_release = -1;
 
 static unsigned int __init get_core_count(void)
 {
-       return scu_get_core_count(__io_address(U8500_SCU_BASE));
+       return scu_get_core_count(__io_address(UX500_SCU_BASE));
 }
 
 static DEFINE_SPINLOCK(boot_lock);
@@ -44,7 +44,7 @@ void __cpuinit platform_secondary_init(unsigned int cpu)
         * core (e.g. timer irq), then they will not have been enabled
         * for us: do so
         */
-       gic_cpu_init(0, __io_address(U8500_GIC_CPU_BASE));
+       gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
 
        /*
         * let the primary processor know we're out of the
@@ -75,7 +75,8 @@ int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
         * that it has been released by resetting pen_release.
         */
        pen_release = cpu;
-       flush_cache_all();
+       __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
+       outer_clean_range(__pa(&pen_release), __pa(&pen_release) + 1);
 
        timeout = jiffies + (1 * HZ);
        while (time_before(jiffies, timeout)) {
@@ -105,12 +106,12 @@ static void __init wakeup_secondary(void)
         */
 #define U8500_CPU1_JUMPADDR_OFFSET 0x1FF4
        __raw_writel(virt_to_phys(u8500_secondary_startup),
-               (void __iomem *)IO_ADDRESS(U8500_BACKUPRAM0_BASE) +
+               __io_address(UX500_BACKUPRAM0_BASE) +
                U8500_CPU1_JUMPADDR_OFFSET);
 
 #define U8500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
        __raw_writel(0xA1FEED01,
-               (void __iomem *)IO_ADDRESS(U8500_BACKUPRAM0_BASE) +
+               __io_address(UX500_BACKUPRAM0_BASE) +
                U8500_CPU1_WAKEMAGIC_OFFSET);
 
        /* make sure write buffer is drained */
@@ -171,7 +172,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
                 * boot CPU, but only if we have more than one CPU.
                 */
                percpu_timer_setup();
-               scu_enable(__io_address(U8500_SCU_BASE));
+               scu_enable(__io_address(UX500_SCU_BASE));
                wakeup_secondary();
        }
 }
index ba81e70..97cf4d8 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile for the linux kernel.
 #
 
-obj-y                                  := core.o clock.o
+obj-y                                  := core.o
 obj-$(CONFIG_ARCH_VERSATILE_PB)                += versatile_pb.o
 obj-$(CONFIG_MACH_VERSATILE_AB)                += versatile_ab.o
 obj-$(CONFIG_PCI)                      += pci.o
diff --git a/arch/arm/mach-versatile/clock.c b/arch/arm/mach-versatile/clock.c
deleted file mode 100644 (file)
index c50a44e..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  linux/arch/arm/mach-versatile/clock.c
- *
- *  Copyright (C) 2004 ARM Limited.
- *  Written by Deep Blue Solutions Limited.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/device.h>
-#include <linux/list.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/string.h>
-#include <linux/clk.h>
-#include <linux/mutex.h>
-
-#include <asm/clkdev.h>
-#include <asm/hardware/icst307.h>
-
-#include "clock.h"
-
-int clk_enable(struct clk *clk)
-{
-       return 0;
-}
-EXPORT_SYMBOL(clk_enable);
-
-void clk_disable(struct clk *clk)
-{
-}
-EXPORT_SYMBOL(clk_disable);
-
-unsigned long clk_get_rate(struct clk *clk)
-{
-       return clk->rate;
-}
-EXPORT_SYMBOL(clk_get_rate);
-
-long clk_round_rate(struct clk *clk, unsigned long rate)
-{
-       struct icst307_vco vco;
-       vco = icst307_khz_to_vco(clk->params, rate / 1000);
-       return icst307_khz(clk->params, vco) * 1000;
-}
-EXPORT_SYMBOL(clk_round_rate);
-
-int clk_set_rate(struct clk *clk, unsigned long rate)
-{
-       int ret = -EIO;
-
-       if (clk->setvco) {
-               struct icst307_vco vco;
-
-               vco = icst307_khz_to_vco(clk->params, rate / 1000);
-               clk->rate = icst307_khz(clk->params, vco) * 1000;
-               clk->setvco(clk, vco);
-               ret = 0;
-       }
-       return ret;
-}
-EXPORT_SYMBOL(clk_set_rate);
diff --git a/arch/arm/mach-versatile/clock.h b/arch/arm/mach-versatile/clock.h
deleted file mode 100644 (file)
index 03468fd..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- *  linux/arch/arm/mach-versatile/clock.h
- *
- *  Copyright (C) 2004 ARM Limited.
- *  Written by Deep Blue Solutions Limited.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-struct module;
-struct icst307_params;
-
-struct clk {
-       unsigned long           rate;
-       const struct icst307_params *params;
-       u32                     oscoff;
-       void                    *data;
-       void                    (*setvco)(struct clk *, struct icst307_vco vco);
-};
index 3b1a4ee..3dff864 100644 (file)
 #include <linux/amba/clcd.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
-#include <linux/clocksource.h>
-#include <linux/clockchips.h>
-#include <linux/cnt32_to_63.h>
 #include <linux/io.h>
 #include <linux/gfp.h>
 
 #include <asm/clkdev.h>
 #include <asm/system.h>
-#include <mach/hardware.h>
 #include <asm/irq.h>
 #include <asm/leds.h>
 #include <asm/hardware/arm_timer.h>
-#include <asm/hardware/icst307.h>
+#include <asm/hardware/icst.h>
 #include <asm/hardware/vic.h>
 #include <asm/mach-types.h>
 
 #include <asm/mach/irq.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
+#include <mach/clkdev.h>
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include <plat/timer-sp.h>
 
 #include "core.h"
-#include "clock.h"
 
 /*
  * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
@@ -59,7 +58,6 @@
  *
  * Setup a VA for the Versatile Vectored Interrupt Controller.
  */
-#define __io_address(n)                __io(IO_ADDRESS(n))
 #define VA_VIC_BASE            __io_address(VERSATILE_VIC_BASE)
 #define VA_SIC_BASE            __io_address(VERSATILE_SIC_BASE)
 
@@ -229,27 +227,6 @@ void __init versatile_map_io(void)
        iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
 }
 
-#define VERSATILE_REFCOUNTER   (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_24MHz_OFFSET)
-
-/*
- * This is the Versatile sched_clock implementation.  This has
- * a resolution of 41.7ns, and a maximum value of about 35583 days.
- *
- * The return value is guaranteed to be monotonic in that range as
- * long as there is always less than 89 seconds between successive
- * calls to this function.
- */
-unsigned long long sched_clock(void)
-{
-       unsigned long long v = cnt32_to_63(readl(VERSATILE_REFCOUNTER));
-
-       /* the <<1 gets rid of the cnt_32_to_63 top bit saving on a bic insn */
-       v *= 125<<1;
-       do_div(v, 3<<1);
-
-       return v;
-}
-
 
 #define VERSATILE_FLASHCTRL    (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_FLASH_OFFSET)
 
@@ -380,33 +357,40 @@ static struct mmci_platform_data mmc0_plat_data = {
 /*
  * Clock handling
  */
-static const struct icst307_params versatile_oscvco_params = {
-       .ref            = 24000,
-       .vco_max        = 200000,
+static const struct icst_params versatile_oscvco_params = {
+       .ref            = 24000000,
+       .vco_max        = ICST307_VCO_MAX,
+       .vco_min        = ICST307_VCO_MIN,
        .vd_min         = 4 + 8,
        .vd_max         = 511 + 8,
        .rd_min         = 1 + 2,
        .rd_max         = 127 + 2,
+       .s2div          = icst307_s2div,
+       .idx2s          = icst307_idx2s,
 };
 
-static void versatile_oscvco_set(struct clk *clk, struct icst307_vco vco)
+static void versatile_oscvco_set(struct clk *clk, struct icst_vco vco)
 {
-       void __iomem *sys = __io_address(VERSATILE_SYS_BASE);
-       void __iomem *sys_lock = sys + VERSATILE_SYS_LOCK_OFFSET;
+       void __iomem *sys_lock = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LOCK_OFFSET;
        u32 val;
 
-       val = readl(sys + clk->oscoff) & ~0x7ffff;
+       val = readl(clk->vcoreg) & ~0x7ffff;
        val |= vco.v | (vco.r << 9) | (vco.s << 16);
 
        writel(0xa05f, sys_lock);
-       writel(val, sys + clk->oscoff);
+       writel(val, clk->vcoreg);
        writel(0, sys_lock);
 }
 
+static const struct clk_ops osc4_clk_ops = {
+       .round  = icst_clk_round,
+       .set    = icst_clk_set,
+       .setvco = versatile_oscvco_set,
+};
+
 static struct clk osc4_clk = {
+       .ops    = &osc4_clk_ops,
        .params = &versatile_oscvco_params,
-       .oscoff = VERSATILE_SYS_OSCCLCD_OFFSET,
-       .setvco = versatile_oscvco_set,
 };
 
 /*
@@ -852,6 +836,8 @@ void __init versatile_init(void)
 {
        int i;
 
+       osc4_clk.vcoreg = __io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_OSCCLCD_OFFSET;
+
        clkdev_add_table(lookups, ARRAY_SIZE(lookups));
 
        platform_device_register(&versatile_flash_device);
@@ -875,120 +861,6 @@ void __init versatile_init(void)
 #define TIMER1_VA_BASE         (__io_address(VERSATILE_TIMER0_1_BASE) + 0x20)
 #define TIMER2_VA_BASE          __io_address(VERSATILE_TIMER2_3_BASE)
 #define TIMER3_VA_BASE         (__io_address(VERSATILE_TIMER2_3_BASE) + 0x20)
-#define VA_IC_BASE              __io_address(VERSATILE_VIC_BASE) 
-
-/*
- * How long is the timer interval?
- */
-#define TIMER_INTERVAL (TICKS_PER_uSEC * mSEC_10)
-#if TIMER_INTERVAL >= 0x100000
-#define TIMER_RELOAD   (TIMER_INTERVAL >> 8)
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV256)
-#define TICKS2USECS(x) (256 * (x) / TICKS_PER_uSEC)
-#elif TIMER_INTERVAL >= 0x10000
-#define TIMER_RELOAD   (TIMER_INTERVAL >> 4)           /* Divide by 16 */
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV16)
-#define TICKS2USECS(x) (16 * (x) / TICKS_PER_uSEC)
-#else
-#define TIMER_RELOAD   (TIMER_INTERVAL)
-#define TIMER_DIVISOR  (TIMER_CTRL_DIV1)
-#define TICKS2USECS(x) ((x) / TICKS_PER_uSEC)
-#endif
-
-static void timer_set_mode(enum clock_event_mode mode,
-                          struct clock_event_device *clk)
-{
-       unsigned long ctrl;
-
-       switch(mode) {
-       case CLOCK_EVT_MODE_PERIODIC:
-               writel(TIMER_RELOAD, TIMER0_VA_BASE + TIMER_LOAD);
-
-               ctrl = TIMER_CTRL_PERIODIC;
-               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE | TIMER_CTRL_ENABLE;
-               break;
-       case CLOCK_EVT_MODE_ONESHOT:
-               /* period set, and timer enabled in 'next_event' hook */
-               ctrl = TIMER_CTRL_ONESHOT;
-               ctrl |= TIMER_CTRL_32BIT | TIMER_CTRL_IE;
-               break;
-       case CLOCK_EVT_MODE_UNUSED:
-       case CLOCK_EVT_MODE_SHUTDOWN:
-       default:
-               ctrl = 0;
-       }
-
-       writel(ctrl, TIMER0_VA_BASE + TIMER_CTRL);
-}
-
-static int timer_set_next_event(unsigned long evt,
-                               struct clock_event_device *unused)
-{
-       unsigned long ctrl = readl(TIMER0_VA_BASE + TIMER_CTRL);
-
-       writel(evt, TIMER0_VA_BASE + TIMER_LOAD);
-       writel(ctrl | TIMER_CTRL_ENABLE, TIMER0_VA_BASE + TIMER_CTRL);
-
-       return 0;
-}
-
-static struct clock_event_device timer0_clockevent =    {
-       .name           = "timer0",
-       .shift          = 32,
-       .features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
-       .set_mode       = timer_set_mode,
-       .set_next_event = timer_set_next_event,
-};
-
-/*
- * IRQ handler for the timer
- */
-static irqreturn_t versatile_timer_interrupt(int irq, void *dev_id)
-{
-       struct clock_event_device *evt = &timer0_clockevent;
-
-       writel(1, TIMER0_VA_BASE + TIMER_INTCLR);
-
-       evt->event_handler(evt);
-
-       return IRQ_HANDLED;
-}
-
-static struct irqaction versatile_timer_irq = {
-       .name           = "Versatile Timer Tick",
-       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
-       .handler        = versatile_timer_interrupt,
-};
-
-static cycle_t versatile_get_cycles(struct clocksource *cs)
-{
-       return ~readl(TIMER3_VA_BASE + TIMER_VALUE);
-}
-
-static struct clocksource clocksource_versatile = {
-       .name           = "timer3",
-       .rating         = 200,
-       .read           = versatile_get_cycles,
-       .mask           = CLOCKSOURCE_MASK(32),
-       .shift          = 20,
-       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
-};
-
-static int __init versatile_clocksource_init(void)
-{
-       /* setup timer3 as free-running clocksource */
-       writel(0, TIMER3_VA_BASE + TIMER_CTRL);
-       writel(0xffffffff, TIMER3_VA_BASE + TIMER_LOAD);
-       writel(0xffffffff, TIMER3_VA_BASE + TIMER_VALUE);
-       writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
-              TIMER3_VA_BASE + TIMER_CTRL);
-
-       clocksource_versatile.mult =
-               clocksource_khz2mult(1000, clocksource_versatile.shift);
-       clocksource_register(&clocksource_versatile);
-
-       return 0;
-}
 
 /*
  * Set up timer interrupt, and return the current time in seconds.
@@ -1017,22 +889,8 @@ static void __init versatile_timer_init(void)
        writel(0, TIMER2_VA_BASE + TIMER_CTRL);
        writel(0, TIMER3_VA_BASE + TIMER_CTRL);
 
-       /* 
-        * Make irqs happen for the system timer
-        */
-       setup_irq(IRQ_TIMERINT0_1, &versatile_timer_irq);
-
-       versatile_clocksource_init();
-
-       timer0_clockevent.mult =
-               div_sc(1000000, NSEC_PER_SEC, timer0_clockevent.shift);
-       timer0_clockevent.max_delta_ns =
-               clockevent_delta2ns(0xffffffff, &timer0_clockevent);
-       timer0_clockevent.min_delta_ns =
-               clockevent_delta2ns(0xf, &timer0_clockevent);
-
-       timer0_clockevent.cpumask = cpumask_of(0);
-       clockevents_register_device(&timer0_clockevent);
+       sp804_clocksource_init(TIMER3_VA_BASE);
+       sp804_clockevents_init(TIMER0_VA_BASE, IRQ_TIMERINT0_1);
 }
 
 struct sys_timer versatile_timer = {
index 04b37a8..e58d077 100644 (file)
@@ -1,6 +1,15 @@
 #ifndef __ASM_MACH_CLKDEV_H
 #define __ASM_MACH_CLKDEV_H
 
+#include <plat/clock.h>
+
+struct clk {
+       unsigned long           rate;
+       const struct clk_ops    *ops;
+       const struct icst_params *params;
+       void __iomem            *vcoreg;
+};
+
 #define __clk_get(clk) ({ 1; })
 #define __clk_put(clk) do { } while (0)
 
index 8c80209..e6f7c16 100644 (file)
@@ -8,6 +8,7 @@
  * warranty of any kind, whether express or implied.
  */
 #include <mach/hardware.h>
+#include <mach/platform.h>
 #include <asm/hardware/vic.h>
 
                .macro  disable_fiq
index 7aa906c..4f8f99a 100644 (file)
@@ -23,7 +23,6 @@
 #define __ASM_ARCH_HARDWARE_H
 
 #include <asm/sizes.h>
-#include <mach/platform.h>
 
 /*
  * PCI space virtual addresses
@@ -49,4 +48,6 @@
 /* macro to get at IO space when running virtually */
 #define IO_ADDRESS(x)          (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
 
+#define __io_address(n)                __io(IO_ADDRESS(n))
+
 #endif
index 8320739..ec08740 100644 (file)
 #define VERSATILE_CLCD_BASE            0x10120000      /* CLCD */
 #define VERSATILE_DMAC_BASE            0x10130000      /* DMA controller */
 #define VERSATILE_VIC_BASE             0x10140000      /* Vectored interrupt controller */
-#define VERSATILE_PERIPH_BASE          0x10150000    /* off-chip peripherals alias from */
+#define VERSATILE_PERIPH_BASE          0x10150000      /* off-chip peripherals alias from */
                                                 /* 0x10000000 - 0x100FFFFF */
 #define VERSATILE_AHBM_BASE            0x101D0000      /* AHB monitor */
 #define VERSATILE_SCTL_BASE            0x101E0000      /* System controller */
 #define VERSATILE_TIMER0_1_BASE        0x101E2000      /* Timer 0 and 1 */
 #define VERSATILE_TIMER2_3_BASE        0x101E3000      /* Timer 2 and 3 */
 #define VERSATILE_GPIO0_BASE           0x101E4000      /* GPIO port 0 */
-#define VERSATILE_GPIO1_BASE           0x101E5000    /* GPIO port 1 */
+#define VERSATILE_GPIO1_BASE           0x101E5000      /* GPIO port 1 */
 #define VERSATILE_GPIO2_BASE           0x101E6000      /* GPIO port 2 */
 #define VERSATILE_GPIO3_BASE           0x101E7000      /* GPIO port 3 */
 #define VERSATILE_RTC_BASE             0x101E8000      /* Real Time Clock */
 #define SIC_INT_PCI3                    30
 
 
-/* 
- *  Clean base - dummy
- * 
- */
-#define CLEAN_BASE                      VERSATILE_BOOT_ROM_HI
-
 /*
  * System controller bit assignment
  */
 #define VERSATILE_TIMER4_EnSel 21
 
 
-#define MAX_TIMER                       2
-#define MAX_PERIOD                      699050
-#define TICKS_PER_uSEC                  1
-
-/* 
- *  These are useconds NOT ticks.  
- * 
- */
-#define mSEC_1                          1000
-#define mSEC_5                          (mSEC_1 * 5)
-#define mSEC_10                         (mSEC_1 * 10)
-#define mSEC_25                         (mSEC_1 * 25)
-#define SEC_1                           (mSEC_1 * 1000)
-
 #define VERSATILE_CSR_BASE             0x10000000
 #define VERSATILE_CSR_SIZE             0x10000000
 
 #endif
 
 #endif
-
-/*     END */
diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
new file mode 100644 (file)
index 0000000..3f19b66
--- /dev/null
@@ -0,0 +1,9 @@
+menu "Versatile Express platform type"
+       depends on ARCH_VEXPRESS
+
+config ARCH_VEXPRESS_CA9X4
+       bool "Versatile Express Cortex-A9x4 tile"
+       select CPU_V7
+       select ARM_GIC
+
+endmenu
diff --git a/arch/arm/mach-vexpress/Makefile b/arch/arm/mach-vexpress/Makefile
new file mode 100644 (file)
index 0000000..1b71b77
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the linux kernel.
+#
+
+obj-y                                  := v2m.o
+obj-$(CONFIG_ARCH_VEXPRESS_CA9X4)      += ct-ca9x4.o
+obj-$(CONFIG_SMP)                      += platsmp.o headsmp.o
+obj-$(CONFIG_LOCAL_TIMERS)             += localtimer.o
diff --git a/arch/arm/mach-vexpress/Makefile.boot b/arch/arm/mach-vexpress/Makefile.boot
new file mode 100644 (file)
index 0000000..07c2d9c
--- /dev/null
@@ -0,0 +1,3 @@
+   zreladdr-y  := 0x60008000
+params_phys-y  := 0x60000100
+initrd_phys-y  := 0x60800000
diff --git a/arch/arm/mach-vexpress/core.h b/arch/arm/mach-vexpress/core.h
new file mode 100644 (file)
index 0000000..57dd95c
--- /dev/null
@@ -0,0 +1,26 @@
+#define __MMIO_P2V(x)  (((x) & 0xfffff) | (((x) & 0x0f000000) >> 4) | 0xf8000000)
+#define MMIO_P2V(x)    ((void __iomem *)__MMIO_P2V(x))
+
+#define AMBA_DEVICE(name,busid,base,plat)      \
+struct amba_device name##_device = {           \
+       .dev            = {                     \
+               .coherent_dma_mask = ~0UL,      \
+               .init_name = busid,             \
+               .platform_data = plat,          \
+       },                                      \
+       .res            = {                     \
+               .start  = base,                 \
+               .end    = base + SZ_4K - 1,     \
+               .flags  = IORESOURCE_MEM,       \
+       },                                      \
+       .dma_mask       = ~0UL,                 \
+       .irq            = IRQ_##base,           \
+       /* .dma         = DMA_##base,*/         \
+}
+
+struct map_desc;
+
+void v2m_map_io(struct map_desc *tile, size_t num);
+extern struct sys_timer v2m_timer;
+
+extern void __iomem *gic_cpu_base_addr;
diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
new file mode 100644 (file)
index 0000000..e6f7303
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Versatile Express Core Tile Cortex A9x4 Support
+ */
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/clcd.h>
+
+#include <asm/clkdev.h>
+#include <asm/hardware/arm_timer.h>
+#include <asm/hardware/cache-l2x0.h>
+#include <asm/hardware/gic.h>
+#include <asm/mach-types.h>
+#include <asm/pmu.h>
+
+#include <mach/clkdev.h>
+#include <mach/ct-ca9x4.h>
+
+#include <plat/timer-sp.h>
+
+#include <asm/mach/arch.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+
+#include "core.h"
+
+#include <mach/motherboard.h>
+
+#define V2M_PA_CS7     0x10000000
+
+static struct map_desc ct_ca9x4_io_desc[] __initdata = {
+       {
+               .virtual        = __MMIO_P2V(CT_CA9X4_MPIC),
+               .pfn            = __phys_to_pfn(CT_CA9X4_MPIC),
+               .length         = SZ_16K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = __MMIO_P2V(CT_CA9X4_SP804_TIMER),
+               .pfn            = __phys_to_pfn(CT_CA9X4_SP804_TIMER),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       }, {
+               .virtual        = __MMIO_P2V(CT_CA9X4_L2CC),
+               .pfn            = __phys_to_pfn(CT_CA9X4_L2CC),
+               .length         = SZ_4K,
+               .type           = MT_DEVICE,
+       },
+};
+
+static void __init ct_ca9x4_map_io(void)
+{
+       v2m_map_io(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
+}
+
+void __iomem *gic_cpu_base_addr;
+
+static void __init ct_ca9x4_init_irq(void)
+{
+       gic_cpu_base_addr = MMIO_P2V(A9_MPCORE_GIC_CPU);
+       gic_dist_init(0, MMIO_P2V(A9_MPCORE_GIC_DIST), 29);
+       gic_cpu_init(0, gic_cpu_base_addr);
+}
+
+#if 0
+static void ct_ca9x4_timer_init(void)
+{
+       writel(0, MMIO_P2V(CT_CA9X4_TIMER0) + TIMER_CTRL);
+       writel(0, MMIO_P2V(CT_CA9X4_TIMER1) + TIMER_CTRL);
+
+       sp804_clocksource_init(MMIO_P2V(CT_CA9X4_TIMER1));
+       sp804_clockevents_init(MMIO_P2V(CT_CA9X4_TIMER0), IRQ_CT_CA9X4_TIMER0);
+}
+
+static struct sys_timer ct_ca9x4_timer = {
+       .init   = ct_ca9x4_timer_init,
+};
+#endif
+
+static struct clcd_panel xvga_panel = {
+       .mode           = {
+               .name           = "XVGA",
+               .refresh        = 60,
+               .xres           = 1024,
+               .yres           = 768,
+               .pixclock       = 15384,
+               .left_margin    = 168,
+               .right_margin   = 8,
+               .upper_margin   = 29,
+               .lower_margin   = 3,
+               .hsync_len      = 144,
+               .vsync_len      = 6,
+               .sync           = 0,
+               .vmode          = FB_VMODE_NONINTERLACED,
+       },
+       .width          = -1,
+       .height         = -1,
+       .tim2           = TIM2_BCD | TIM2_IPC,
+       .cntl           = CNTL_LCDTFT | CNTL_BGR | CNTL_LCDVCOMP(1),
+       .bpp            = 16,
+};
+
+static void ct_ca9x4_clcd_enable(struct clcd_fb *fb)
+{
+       v2m_cfg_write(SYS_CFG_MUXFPGA | SYS_CFG_SITE_DB1, 0);
+       v2m_cfg_write(SYS_CFG_DVIMODE | SYS_CFG_SITE_DB1, 2);
+}
+
+static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
+{
+       unsigned long framesize = 1024 * 768 * 2;
+       dma_addr_t dma;
+
+       fb->panel = &xvga_panel;
+
+       fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev, framesize,
+                               &dma, GFP_KERNEL);
+       if (!fb->fb.screen_base) {
+               printk(KERN_ERR "CLCD: unable to map frame buffer\n");
+               return -ENOMEM;
+       }
+       fb->fb.fix.smem_start = dma;
+       fb->fb.fix.smem_len = framesize;
+
+       return 0;
+}
+
+static int ct_ca9x4_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
+{
+       return dma_mmap_writecombine(&fb->dev->dev, vma, fb->fb.screen_base,
+               fb->fb.fix.smem_start, fb->fb.fix.smem_len);
+}
+
+static void ct_ca9x4_clcd_remove(struct clcd_fb *fb)
+{
+       dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
+               fb->fb.screen_base, fb->fb.fix.smem_start);
+}
+
+static struct clcd_board ct_ca9x4_clcd_data = {
+       .name           = "CT-CA9X4",
+       .check          = clcdfb_check,
+       .decode         = clcdfb_decode,
+       .enable         = ct_ca9x4_clcd_enable,
+       .setup          = ct_ca9x4_clcd_setup,
+       .mmap           = ct_ca9x4_clcd_mmap,
+       .remove         = ct_ca9x4_clcd_remove,
+};
+
+static AMBA_DEVICE(clcd, "ct:clcd", CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
+static AMBA_DEVICE(dmc, "ct:dmc", CT_CA9X4_DMC, NULL);
+static AMBA_DEVICE(smc, "ct:smc", CT_CA9X4_SMC, NULL);
+static AMBA_DEVICE(gpio, "ct:gpio", CT_CA9X4_GPIO, NULL);
+
+static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
+       &clcd_device,
+       &dmc_device,
+       &smc_device,
+       &gpio_device,
+};
+
+
+static long ct_round(struct clk *clk, unsigned long rate)
+{
+       return rate;
+}
+
+static int ct_set(struct clk *clk, unsigned long rate)
+{
+       return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_DB1 | 1, rate);
+}
+
+static const struct clk_ops osc1_clk_ops = {
+       .round  = ct_round,
+       .set    = ct_set,
+};
+
+static struct clk osc1_clk = {
+       .ops    = &osc1_clk_ops,
+       .rate   = 24000000,
+};
+
+static struct clk_lookup lookups[] = {
+       {       /* CLCD */
+               .dev_id         = "ct:clcd",
+               .clk            = &osc1_clk,
+       },
+};
+
+static struct resource pmu_resources[] = {
+       [0] = {
+               .start  = IRQ_CT_CA9X4_PMU_CPU0,
+               .end    = IRQ_CT_CA9X4_PMU_CPU0,
+               .flags  = IORESOURCE_IRQ,
+       },
+       [1] = {
+               .start  = IRQ_CT_CA9X4_PMU_CPU1,
+               .end    = IRQ_CT_CA9X4_PMU_CPU1,
+               .flags  = IORESOURCE_IRQ,
+       },
+       [2] = {
+               .start  = IRQ_CT_CA9X4_PMU_CPU2,
+               .end    = IRQ_CT_CA9X4_PMU_CPU2,
+               .flags  = IORESOURCE_IRQ,
+       },
+       [3] = {
+               .start  = IRQ_CT_CA9X4_PMU_CPU3,
+               .end    = IRQ_CT_CA9X4_PMU_CPU3,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device pmu_device = {
+       .name           = "arm-pmu",
+       .id             = ARM_PMU_DEVICE_CPU,
+       .num_resources  = ARRAY_SIZE(pmu_resources),
+       .resource       = pmu_resources,
+};
+
+static void ct_ca9x4_init(void)
+{
+       int i;
+
+#ifdef CONFIG_CACHE_L2X0
+       l2x0_init(MMIO_P2V(CT_CA9X4_L2CC), 0x00000000, 0xfe0fffff);
+#endif
+
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
+       for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
+               amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
+
+       platform_device_register(&pmu_device);
+}
+
+MACHINE_START(VEXPRESS, "ARM-Versatile Express CA9x4")
+       .phys_io        = V2M_UART0,
+       .io_pg_offst    = (__MMIO_P2V(V2M_UART0) >> 18) & 0xfffc,
+       .boot_params    = PHYS_OFFSET + 0x00000100,
+       .map_io         = ct_ca9x4_map_io,
+       .init_irq       = ct_ca9x4_init_irq,
+#if 0
+       .timer          = &ct_ca9x4_timer,
+#else
+       .timer          = &v2m_timer,
+#endif
+       .init_machine   = ct_ca9x4_init,
+MACHINE_END
diff --git a/arch/arm/mach-vexpress/headsmp.S b/arch/arm/mach-vexpress/headsmp.S
new file mode 100644 (file)
index 0000000..8a78ff6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  linux/arch/arm/mach-vexpress/headsmp.S
+ *
+ *  Copyright (c) 2003 ARM Limited
+ *  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 version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/linkage.h>
+#include <linux/init.h>
+
+       __INIT
+
+/*
+ * Versatile Express specific entry point for secondary CPUs.  This
+ * provides a "holding pen" into which all secondary cores are held
+ * until we're ready for them to initialise.
+ */
+ENTRY(vexpress_secondary_startup)
+       mrc     p15, 0, r0, c0, c0, 5
+       and     r0, r0, #15
+       adr     r4, 1f
+       ldmia   r4, {r5, r6}
+       sub     r4, r4, r5
+       add     r6, r6, r4
+pen:   ldr     r7, [r6]
+       cmp     r7, r0
+       bne     pen
+
+       /*
+        * we've been released from the holding pen: secondary_stack
+        * should now contain the SVC stack for this core
+        */
+       b       secondary_startup
+
+1:     .long   .
+       .long   pen_release
diff --git a/arch/arm/mach-vexpress/include/mach/clkdev.h b/arch/arm/mach-vexpress/include/mach/clkdev.h
new file mode 100644 (file)
index 0000000..3f8307d
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __ASM_MACH_CLKDEV_H
+#define __ASM_MACH_CLKDEV_H
+
+#include <plat/clock.h>
+
+struct clk {
+       const struct clk_ops    *ops;
+       unsigned long           rate;
+       const struct icst_params *params;
+};
+
+#define __clk_get(clk) ({ 1; })
+#define __clk_put(clk) do { } while (0)
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/ct-ca9x4.h b/arch/arm/mach-vexpress/include/mach/ct-ca9x4.h
new file mode 100644 (file)
index 0000000..8650f04
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef __MACH_CT_CA9X4_H
+#define __MACH_CT_CA9X4_H
+
+/*
+ * Physical base addresses
+ */
+#define CT_CA9X4_CLCDC         (0x10020000)
+#define CT_CA9X4_AXIRAM                (0x10060000)
+#define CT_CA9X4_DMC           (0x100e0000)
+#define CT_CA9X4_SMC           (0x100e1000)
+#define CT_CA9X4_SCC           (0x100e2000)
+#define CT_CA9X4_SP804_TIMER   (0x100e4000)
+#define CT_CA9X4_SP805_WDT     (0x100e5000)
+#define CT_CA9X4_TZPC          (0x100e6000)
+#define CT_CA9X4_GPIO          (0x100e8000)
+#define CT_CA9X4_FASTAXI       (0x100e9000)
+#define CT_CA9X4_SLOWAXI       (0x100ea000)
+#define CT_CA9X4_TZASC         (0x100ec000)
+#define CT_CA9X4_CORESIGHT     (0x10200000)
+#define CT_CA9X4_MPIC          (0x1e000000)
+#define CT_CA9X4_SYSTIMER      (0x1e004000)
+#define CT_CA9X4_SYSWDT                (0x1e007000)
+#define CT_CA9X4_L2CC          (0x1e00a000)
+
+#define CT_CA9X4_TIMER0                (CT_CA9X4_SP804_TIMER + 0x000)
+#define CT_CA9X4_TIMER1                (CT_CA9X4_SP804_TIMER + 0x020)
+
+#define A9_MPCORE_SCU          (CT_CA9X4_MPIC + 0x0000)
+#define A9_MPCORE_GIC_CPU      (CT_CA9X4_MPIC + 0x0100)
+#define A9_MPCORE_GIT          (CT_CA9X4_MPIC + 0x0200)
+#define A9_MPCORE_GIC_DIST     (CT_CA9X4_MPIC + 0x1000)
+
+/*
+ * Interrupts.  Those in {} are for AMBA devices
+ */
+#define IRQ_CT_CA9X4_CLCDC     { 76 }
+#define IRQ_CT_CA9X4_DMC       { -1 }
+#define IRQ_CT_CA9X4_SMC       { 77, 78 }
+#define IRQ_CT_CA9X4_TIMER0    80
+#define IRQ_CT_CA9X4_TIMER1    81
+#define IRQ_CT_CA9X4_GPIO      { 82 }
+#define IRQ_CT_CA9X4_PMU_CPU0  92
+#define IRQ_CT_CA9X4_PMU_CPU1  93
+#define IRQ_CT_CA9X4_PMU_CPU2  94
+#define IRQ_CT_CA9X4_PMU_CPU3  95
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/debug-macro.S b/arch/arm/mach-vexpress/include/mach/debug-macro.S
new file mode 100644 (file)
index 0000000..5167e2a
--- /dev/null
@@ -0,0 +1,23 @@
+/* arch/arm/mach-realview/include/mach/debug-macro.S
+ *
+ * Debugging macro include header
+ *
+ *  Copyright (C) 1994-1999 Russell King
+ *  Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#define DEBUG_LL_UART_OFFSET   0x00009000
+
+               .macro  addruart,rx,tmp
+               mrc     p15, 0, \rx, c1, c0
+               tst     \rx, #1                 @ MMU enabled?
+               moveq   \rx,      #0x10000000
+               movne   \rx,      #0xf8000000   @ virtual base
+               orr     \rx, \rx, #DEBUG_LL_UART_OFFSET
+               .endm
+
+#include <asm/hardware/debug-pl01x.S>
diff --git a/arch/arm/mach-vexpress/include/mach/entry-macro.S b/arch/arm/mach-vexpress/include/mach/entry-macro.S
new file mode 100644 (file)
index 0000000..20e9fb5
--- /dev/null
@@ -0,0 +1,67 @@
+#include <asm/hardware/gic.h>
+
+       .macro  disable_fiq
+       .endm
+
+       .macro  get_irqnr_preamble, base, tmp
+       ldr     \base, =gic_cpu_base_addr
+       ldr     \base, [\base]
+       .endm
+
+       .macro  arch_ret_to_user, tmp1, tmp2
+       .endm
+
+       /*
+        * The interrupt numbering scheme is defined in the
+        * interrupt controller spec.  To wit:
+        *
+        * Interrupts 0-15 are IPI
+        * 16-28 are reserved
+        * 29-31 are local.  We allow 30 to be used for the watchdog.
+        * 32-1020 are global
+        * 1021-1022 are reserved
+        * 1023 is "spurious" (no interrupt)
+        *
+        * For now, we ignore all local interrupts so only return an interrupt if it's
+        * between 30 and 1020.  The test_for_ipi routine below will pick up on IPIs.
+        *
+        * A simple read from the controller will tell us the number of the highest
+        * priority enabled interrupt.  We then just need to check whether it is in the
+        * valid range for an IRQ (30-1020 inclusive).
+        */
+
+       .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+       ldr     \irqstat, [\base, #GIC_CPU_INTACK] /* bits 12-10 = src CPU, 9-0 = int # */
+       ldr     \tmp, =1021
+       bic     \irqnr, \irqstat, #0x1c00
+       cmp     \irqnr, #29
+       cmpcc   \irqnr, \irqnr
+       cmpne   \irqnr, \tmp
+       cmpcs   \irqnr, \irqnr
+       .endm
+
+       /* We assume that irqstat (the raw value of the IRQ acknowledge
+        * register) is preserved from the macro above.
+        * If there is an IPI, we immediately signal end of interrupt on the
+        * controller, since this requires the original irqstat value which
+        * we won't easily be able to recreate later.
+        */
+
+       .macro test_for_ipi, irqnr, irqstat, base, tmp
+       bic     \irqnr, \irqstat, #0x1c00
+       cmp     \irqnr, #16
+       strcc   \irqstat, [\base, #GIC_CPU_EOI]
+       cmpcs   \irqnr, \irqnr
+       .endm
+
+       /* As above, this assumes that irqstat and base are preserved.. */
+
+       .macro test_for_ltirq, irqnr, irqstat, base, tmp
+       bic     \irqnr, \irqstat, #0x1c00
+       mov     \tmp, #0
+       cmp     \irqnr, #29
+       moveq   \tmp, #1
+       streq   \irqstat, [\base, #GIC_CPU_EOI]
+       cmp     \tmp, #0
+       .endm
+
diff --git a/arch/arm/mach-vexpress/include/mach/hardware.h b/arch/arm/mach-vexpress/include/mach/hardware.h
new file mode 100644 (file)
index 0000000..40a8c17
--- /dev/null
@@ -0,0 +1 @@
+/* empty */
diff --git a/arch/arm/mach-vexpress/include/mach/io.h b/arch/arm/mach-vexpress/include/mach/io.h
new file mode 100644 (file)
index 0000000..748bb52
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/io.h
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *
+ * 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
+ */
+#ifndef __ASM_ARM_ARCH_IO_H
+#define __ASM_ARM_ARCH_IO_H
+
+#define IO_SPACE_LIMIT 0xffffffff
+
+#define __io(a)                __typesafe_io(a)
+#define __mem_pci(a)   (a)
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/irqs.h b/arch/arm/mach-vexpress/include/mach/irqs.h
new file mode 100644 (file)
index 0000000..7054cbf
--- /dev/null
@@ -0,0 +1,4 @@
+#define IRQ_LOCALTIMER         29
+#define IRQ_LOCALWDOG          30
+
+#define NR_IRQS        128
diff --git a/arch/arm/mach-vexpress/include/mach/memory.h b/arch/arm/mach-vexpress/include/mach/memory.h
new file mode 100644 (file)
index 0000000..be28232
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/memory.h
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *
+ * 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
+ */
+#ifndef __ASM_ARCH_MEMORY_H
+#define __ASM_ARCH_MEMORY_H
+
+#define PHYS_OFFSET            UL(0x60000000)
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/motherboard.h b/arch/arm/mach-vexpress/include/mach/motherboard.h
new file mode 100644 (file)
index 0000000..98a8ded
--- /dev/null
@@ -0,0 +1,121 @@
+#ifndef __MACH_MOTHERBOARD_H
+#define __MACH_MOTHERBOARD_H
+
+/*
+ * Physical addresses, offset from V2M_PA_CS0-3
+ */
+#define V2M_NOR0               (V2M_PA_CS0)
+#define V2M_NOR1               (V2M_PA_CS1)
+#define V2M_SRAM               (V2M_PA_CS2)
+#define V2M_VIDEO_SRAM         (V2M_PA_CS3 + 0x00000000)
+#define V2M_LAN9118            (V2M_PA_CS3 + 0x02000000)
+#define V2M_ISP1761            (V2M_PA_CS3 + 0x03000000)
+
+/*
+ * Physical addresses, offset from V2M_PA_CS7
+ */
+#define V2M_SYSREGS            (V2M_PA_CS7 + 0x00000000)
+#define V2M_SYSCTL             (V2M_PA_CS7 + 0x00001000)
+#define V2M_SERIAL_BUS_PCI     (V2M_PA_CS7 + 0x00002000)
+
+#define V2M_AACI               (V2M_PA_CS7 + 0x00004000)
+#define V2M_MMCI               (V2M_PA_CS7 + 0x00005000)
+#define V2M_KMI0               (V2M_PA_CS7 + 0x00006000)
+#define V2M_KMI1               (V2M_PA_CS7 + 0x00007000)
+
+#define V2M_UART0              (V2M_PA_CS7 + 0x00009000)
+#define V2M_UART1              (V2M_PA_CS7 + 0x0000a000)
+#define V2M_UART2              (V2M_PA_CS7 + 0x0000b000)
+#define V2M_UART3              (V2M_PA_CS7 + 0x0000c000)
+
+#define V2M_WDT                        (V2M_PA_CS7 + 0x0000f000)
+
+#define V2M_TIMER01            (V2M_PA_CS7 + 0x00011000)
+#define V2M_TIMER23            (V2M_PA_CS7 + 0x00012000)
+
+#define V2M_SERIAL_BUS_DVI     (V2M_PA_CS7 + 0x00016000)
+#define V2M_RTC                        (V2M_PA_CS7 + 0x00017000)
+
+#define V2M_CF                 (V2M_PA_CS7 + 0x0001a000)
+#define V2M_CLCD               (V2M_PA_CS7 + 0x0001f000)
+
+#define V2M_SYS_ID             (V2M_SYSREGS + 0x000)
+#define V2M_SYS_SW             (V2M_SYSREGS + 0x004)
+#define V2M_SYS_LED            (V2M_SYSREGS + 0x008)
+#define V2M_SYS_100HZ          (V2M_SYSREGS + 0x024)
+#define V2M_SYS_FLAGS          (V2M_SYSREGS + 0x030)
+#define V2M_SYS_FLAGSSET       (V2M_SYSREGS + 0x030)
+#define V2M_SYS_FLAGSCLR       (V2M_SYSREGS + 0x034)
+#define V2M_SYS_NVFLAGS                (V2M_SYSREGS + 0x038)
+#define V2M_SYS_NVFLAGSSET     (V2M_SYSREGS + 0x038)
+#define V2M_SYS_NVFLAGSCLR     (V2M_SYSREGS + 0x03c)
+#define V2M_SYS_MCI            (V2M_SYSREGS + 0x048)
+#define V2M_SYS_FLASH          (V2M_SYSREGS + 0x03c)
+#define V2M_SYS_CFGSW          (V2M_SYSREGS + 0x058)
+#define V2M_SYS_24MHZ          (V2M_SYSREGS + 0x05c)
+#define V2M_SYS_MISC           (V2M_SYSREGS + 0x060)
+#define V2M_SYS_DMA            (V2M_SYSREGS + 0x064)
+#define V2M_SYS_PROCID0                (V2M_SYSREGS + 0x084)
+#define V2M_SYS_PROCID1                (V2M_SYSREGS + 0x088)
+#define V2M_SYS_CFGDATA                (V2M_SYSREGS + 0x0a0)
+#define V2M_SYS_CFGCTRL                (V2M_SYSREGS + 0x0a4)
+#define V2M_SYS_CFGSTAT                (V2M_SYSREGS + 0x0a8)
+
+#define V2M_TIMER0             (V2M_TIMER01 + 0x000)
+#define V2M_TIMER1             (V2M_TIMER01 + 0x020)
+
+#define V2M_TIMER2             (V2M_TIMER23 + 0x000)
+#define V2M_TIMER3             (V2M_TIMER23 + 0x020)
+
+
+/*
+ * Interrupts.  Those in {} are for AMBA devices
+ */
+#define IRQ_V2M_WDT            { (32 + 0) }
+#define IRQ_V2M_TIMER0         (32 + 2)
+#define IRQ_V2M_TIMER1         (32 + 2)
+#define IRQ_V2M_TIMER2         (32 + 3)
+#define IRQ_V2M_TIMER3         (32 + 3)
+#define IRQ_V2M_RTC            { (32 + 4) }
+#define IRQ_V2M_UART0          { (32 + 5) }
+#define IRQ_V2M_UART1          { (32 + 6) }
+#define IRQ_V2M_UART2          { (32 + 7) }
+#define IRQ_V2M_UART3          { (32 + 8) }
+#define IRQ_V2M_MMCI           { (32 + 9), (32 + 10) }
+#define IRQ_V2M_AACI           { (32 + 11) }
+#define IRQ_V2M_KMI0           { (32 + 12) }
+#define IRQ_V2M_KMI1           { (32 + 13) }
+#define IRQ_V2M_CLCD           { (32 + 14) }
+#define IRQ_V2M_LAN9118                (32 + 15)
+#define IRQ_V2M_ISP1761                (32 + 16)
+#define IRQ_V2M_PCIE           (32 + 17)
+
+
+/*
+ * Configuration
+ */
+#define SYS_CFG_START          (1 << 31)
+#define SYS_CFG_WRITE          (1 << 30)
+#define SYS_CFG_OSC            (1 << 20)
+#define SYS_CFG_VOLT           (2 << 20)
+#define SYS_CFG_AMP            (3 << 20)
+#define SYS_CFG_TEMP           (4 << 20)
+#define SYS_CFG_RESET          (5 << 20)
+#define SYS_CFG_SCC            (6 << 20)
+#define SYS_CFG_MUXFPGA                (7 << 20)
+#define SYS_CFG_SHUTDOWN       (8 << 20)
+#define SYS_CFG_REBOOT         (9 << 20)
+#define SYS_CFG_DVIMODE                (11 << 20)
+#define SYS_CFG_POWER          (12 << 20)
+#define SYS_CFG_SITE_MB                (0 << 16)
+#define SYS_CFG_SITE_DB1       (1 << 16)
+#define SYS_CFG_SITE_DB2       (2 << 16)
+#define SYS_CFG_STACK(n)       ((n) << 12)
+
+#define SYS_CFG_ERR            (1 << 1)
+#define SYS_CFG_COMPLETE       (1 << 0)
+
+int v2m_cfg_write(u32 devfn, u32 data);
+int v2m_cfg_read(u32 devfn, u32 *data);
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/smp.h b/arch/arm/mach-vexpress/include/mach/smp.h
new file mode 100644 (file)
index 0000000..72a9621
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __MACH_SMP_H
+#define __MACH_SMP_H
+
+#include <asm/hardware/gic.h>
+
+#define hard_smp_processor_id()                                \
+       ({                                              \
+               unsigned int cpunum;                    \
+               __asm__("mrc p15, 0, %0, c0, c0, 5"     \
+                       : "=r" (cpunum));               \
+               cpunum &= 0x0F;                         \
+       })
+
+/*
+ * We use IRQ1 as the IPI
+ */
+static inline void smp_cross_call(const struct cpumask *mask)
+{
+       gic_raise_softirq(mask, 1);
+}
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/system.h b/arch/arm/mach-vexpress/include/mach/system.h
new file mode 100644 (file)
index 0000000..899a4e6
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/system.h
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * 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
+ */
+#ifndef __ASM_ARCH_SYSTEM_H
+#define __ASM_ARCH_SYSTEM_H
+
+static inline void arch_idle(void)
+{
+       /*
+        * This should do all the clock switching
+        * and wait for interrupt tricks
+        */
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode, const char *cmd)
+{
+}
+
+#endif
diff --git a/arch/arm/mach-vexpress/include/mach/timex.h b/arch/arm/mach-vexpress/include/mach/timex.h
new file mode 100644 (file)
index 0000000..00029ba
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/timex.h
+ *
+ *  RealView architecture timex specifications
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *
+ * 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 CLOCK_TICK_RATE                (50000000 / 16)
diff --git a/arch/arm/mach-vexpress/include/mach/uncompress.h b/arch/arm/mach-vexpress/include/mach/uncompress.h
new file mode 100644 (file)
index 0000000..7972c57
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/uncompress.h
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *
+ * 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 AMBA_UART_DR(base)     (*(volatile unsigned char *)((base) + 0x00))
+#define AMBA_UART_LCRH(base)   (*(volatile unsigned char *)((base) + 0x2c))
+#define AMBA_UART_CR(base)     (*(volatile unsigned char *)((base) + 0x30))
+#define AMBA_UART_FR(base)     (*(volatile unsigned char *)((base) + 0x18))
+
+#define get_uart_base()        (0x10000000 + 0x00009000)
+
+/*
+ * This does not append a newline
+ */
+static inline void putc(int c)
+{
+       unsigned long base = get_uart_base();
+
+       while (AMBA_UART_FR(base) & (1 << 5))
+               barrier();
+
+       AMBA_UART_DR(base) = c;
+}
+
+static inline void flush(void)
+{
+       unsigned long base = get_uart_base();
+
+       while (AMBA_UART_FR(base) & (1 << 3))
+               barrier();
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
diff --git a/arch/arm/mach-vexpress/include/mach/vmalloc.h b/arch/arm/mach-vexpress/include/mach/vmalloc.h
new file mode 100644 (file)
index 0000000..f43a36e
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ *  arch/arm/mach-vexpress/include/mach/vmalloc.h
+ *
+ *  Copyright (C) 2003 ARM Limited
+ *  Copyright (C) 2000 Russell King.
+ *
+ * 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 VMALLOC_END            0xf8000000UL
diff --git a/arch/arm/mach-vexpress/localtimer.c b/arch/arm/mach-vexpress/localtimer.c
new file mode 100644 (file)
index 0000000..c0e3a59
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ *  linux/arch/arm/mach-vexpress/localtimer.c
+ *
+ *  Copyright (C) 2002 ARM Ltd.
+ *  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 version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/clockchips.h>
+
+#include <asm/smp_twd.h>
+#include <asm/localtimer.h>
+#include <mach/irqs.h>
+
+/*
+ * Setup the local clock events for a CPU.
+ */
+void __cpuinit local_timer_setup(struct clock_event_device *evt)
+{
+       evt->irq = IRQ_LOCALTIMER;
+       twd_timer_setup(evt);
+}
diff --git a/arch/arm/mach-vexpress/platsmp.c b/arch/arm/mach-vexpress/platsmp.c
new file mode 100644 (file)
index 0000000..6709706
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ *  linux/arch/arm/mach-vexpress/platsmp.c
+ *
+ *  Copyright (C) 2002 ARM Ltd.
+ *  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 version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/jiffies.h>
+#include <linux/smp.h>
+#include <linux/io.h>
+
+#include <asm/cacheflush.h>
+#include <asm/localtimer.h>
+#include <asm/smp_scu.h>
+#include <asm/unified.h>
+
+#include <mach/ct-ca9x4.h>
+#include <mach/motherboard.h>
+#define V2M_PA_CS7 0x10000000
+
+#include "core.h"
+
+extern void vexpress_secondary_startup(void);
+
+/*
+ * control for which core is the next to come out of the secondary
+ * boot "holding pen"
+ */
+volatile int __cpuinitdata pen_release = -1;
+
+static void __iomem *scu_base_addr(void)
+{
+       return MMIO_P2V(A9_MPCORE_SCU);
+}
+
+static DEFINE_SPINLOCK(boot_lock);
+
+void __cpuinit platform_secondary_init(unsigned int cpu)
+{
+       trace_hardirqs_off();
+
+       /*
+        * if any interrupts are already enabled for the primary
+        * core (e.g. timer irq), then they will not have been enabled
+        * for us: do so
+        */
+       gic_cpu_init(0, gic_cpu_base_addr);
+
+       /*
+        * let the primary processor know we're out of the
+        * pen, then head off into the C entry point
+        */
+       pen_release = -1;
+       smp_wmb();
+
+       /*
+        * Synchronise with the boot thread.
+        */
+       spin_lock(&boot_lock);
+       spin_unlock(&boot_lock);
+}
+
+int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
+{
+       unsigned long timeout;
+
+       /*
+        * Set synchronisation state between this boot processor
+        * and the secondary one
+        */
+       spin_lock(&boot_lock);
+
+       /*
+        * This is really belt and braces; we hold unintended secondary
+        * CPUs in the holding pen until we're ready for them.  However,
+        * since we haven't sent them a soft interrupt, they shouldn't
+        * be there.
+        */
+       pen_release = cpu;
+       __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
+       outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
+
+       /*
+        * Send the secondary CPU a soft interrupt, thereby causing
+        * the boot monitor to read the system wide flags register,
+        * and branch to the address found there.
+        */
+       smp_cross_call(cpumask_of(cpu));
+
+       timeout = jiffies + (1 * HZ);
+       while (time_before(jiffies, timeout)) {
+               smp_rmb();
+               if (pen_release == -1)
+                       break;
+
+               udelay(10);
+       }
+
+       /*
+        * now the secondary core is starting up let it run its
+        * calibrations, then wait for it to finish
+        */
+       spin_unlock(&boot_lock);
+
+       return pen_release != -1 ? -ENOSYS : 0;
+}
+
+/*
+ * Initialise the CPU possible map early - this describes the CPUs
+ * which may be present or become present in the system.
+ */
+void __init smp_init_cpus(void)
+{
+       void __iomem *scu_base = scu_base_addr();
+       unsigned int i, ncores;
+
+       ncores = scu_base ? scu_get_core_count(scu_base) : 1;
+
+       /* sanity check */
+       if (ncores == 0) {
+               printk(KERN_ERR
+                      "vexpress: strange CM count of 0? Default to 1\n");
+
+               ncores = 1;
+       }
+
+       if (ncores > NR_CPUS) {
+               printk(KERN_WARNING
+                      "vexpress: no. of cores (%d) greater than configured "
+                      "maximum of %d - clipping\n",
+                      ncores, NR_CPUS);
+               ncores = NR_CPUS;
+       }
+
+       for (i = 0; i < ncores; i++)
+               set_cpu_possible(i, true);
+}
+
+void __init smp_prepare_cpus(unsigned int max_cpus)
+{
+       unsigned int ncores = num_possible_cpus();
+       unsigned int cpu = smp_processor_id();
+       int i;
+
+       smp_store_cpu_info(cpu);
+
+       /*
+        * are we trying to boot more cores than exist?
+        */
+       if (max_cpus > ncores)
+               max_cpus = ncores;
+
+       /*
+        * Initialise the present map, which describes the set of CPUs
+        * actually populated at the present time.
+        */
+       for (i = 0; i < max_cpus; i++)
+               set_cpu_present(i, true);
+
+       /*
+        * Initialise the SCU if there are more than one CPU and let
+        * them know where to start.
+        */
+       if (max_cpus > 1) {
+               /*
+                * Enable the local timer or broadcast device for the
+                * boot CPU, but only if we have more than one CPU.
+                */
+               percpu_timer_setup();
+
+               scu_enable(scu_base_addr());
+
+               /*
+                * Write the address of secondary startup into the
+                * system-wide flags register. The boot monitor waits
+                * until it receives a soft interrupt, and then the
+                * secondary CPU branches to this address.
+                */
+               writel(~0, MMIO_P2V(V2M_SYS_FLAGSCLR));
+               writel(BSYM(virt_to_phys(vexpress_secondary_startup)),
+                       MMIO_P2V(V2M_SYS_FLAGSSET));
+       }
+}
diff --git a/arch/arm/mach-vexpress/v2m.c b/arch/arm/mach-vexpress/v2m.c
new file mode 100644 (file)
index 0000000..d250711
--- /dev/null
@@ -0,0 +1,361 @@
+/*
+ * Versatile Express V2M Motherboard Support
+ */
+#include <linux/device.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/mmci.h>
+#include <linux/io.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/smsc911x.h>
+#include <linux/spinlock.h>
+#include <linux/sysdev.h>
+#include <linux/usb/isp1760.h>
+
+#include <asm/clkdev.h>
+#include <asm/sizes.h>
+#include <asm/mach/flash.h>
+#include <asm/mach/map.h>
+#include <asm/mach/time.h>
+#include <asm/hardware/arm_timer.h>
+
+#include <mach/clkdev.h>
+#include <mach/motherboard.h>
+
+#include <plat/timer-sp.h>
+
+#include "core.h"
+
+#define V2M_PA_CS0     0x40000000
+#define V2M_PA_CS1     0x44000000
+#define V2M_PA_CS2     0x48000000
+#define V2M_PA_CS3     0x4c000000
+#define V2M_PA_CS7     0x10000000
+
+static struct map_desc v2m_io_desc[] __initdata = {
+       {
+               .virtual        = __MMIO_P2V(V2M_PA_CS7),
+               .pfn            = __phys_to_pfn(V2M_PA_CS7),
+               .length         = SZ_128K,
+               .type           = MT_DEVICE,
+       },
+};
+
+void __init v2m_map_io(struct map_desc *tile, size_t num)
+{
+       iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
+       iotable_init(tile, num);
+}
+
+
+static void v2m_timer_init(void)
+{
+       writel(0, MMIO_P2V(V2M_TIMER0) + TIMER_CTRL);
+       writel(0, MMIO_P2V(V2M_TIMER1) + TIMER_CTRL);
+
+       sp804_clocksource_init(MMIO_P2V(V2M_TIMER1));
+       sp804_clockevents_init(MMIO_P2V(V2M_TIMER0), IRQ_V2M_TIMER0);
+}
+
+struct sys_timer v2m_timer = {
+       .init   = v2m_timer_init,
+};
+
+
+static DEFINE_SPINLOCK(v2m_cfg_lock);
+
+int v2m_cfg_write(u32 devfn, u32 data)
+{
+       /* Configuration interface broken? */
+       u32 val;
+
+       printk("%s: writing %08x to %08x\n", __func__, data, devfn);
+
+       devfn |= SYS_CFG_START | SYS_CFG_WRITE;
+
+       spin_lock(&v2m_cfg_lock);
+       val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
+       writel(val & ~SYS_CFG_COMPLETE, MMIO_P2V(V2M_SYS_CFGSTAT));
+
+       writel(data, MMIO_P2V(V2M_SYS_CFGDATA));
+       writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
+
+       do {
+               val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
+       } while (val == 0);
+       spin_unlock(&v2m_cfg_lock);
+
+       return !!(val & SYS_CFG_ERR);
+}
+
+int v2m_cfg_read(u32 devfn, u32 *data)
+{
+       u32 val;
+
+       devfn |= SYS_CFG_START;
+
+       spin_lock(&v2m_cfg_lock);
+       writel(0, MMIO_P2V(V2M_SYS_CFGSTAT));
+       writel(devfn, MMIO_P2V(V2M_SYS_CFGCTRL));
+
+       mb();
+
+       do {
+               cpu_relax();
+               val = readl(MMIO_P2V(V2M_SYS_CFGSTAT));
+       } while (val == 0);
+
+       *data = readl(MMIO_P2V(V2M_SYS_CFGDATA));
+       spin_unlock(&v2m_cfg_lock);
+
+       return !!(val & SYS_CFG_ERR);
+}
+
+
+static struct resource v2m_pcie_i2c_resource = {
+       .start  = V2M_SERIAL_BUS_PCI,
+       .end    = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
+       .flags  = IORESOURCE_MEM,
+};
+
+static struct platform_device v2m_pcie_i2c_device = {
+       .name           = "versatile-i2c",
+       .id             = 0,
+       .num_resources  = 1,
+       .resource       = &v2m_pcie_i2c_resource,
+};
+
+static struct resource v2m_ddc_i2c_resource = {
+       .start  = V2M_SERIAL_BUS_DVI,
+       .end    = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
+       .flags  = IORESOURCE_MEM,
+};
+
+static struct platform_device v2m_ddc_i2c_device = {
+       .name           = "versatile-i2c",
+       .id             = 1,
+       .num_resources  = 1,
+       .resource       = &v2m_ddc_i2c_resource,
+};
+
+static struct resource v2m_eth_resources[] = {
+       {
+               .start  = V2M_LAN9118,
+               .end    = V2M_LAN9118 + SZ_64K - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_V2M_LAN9118,
+               .end    = IRQ_V2M_LAN9118,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct smsc911x_platform_config v2m_eth_config = {
+       .flags          = SMSC911X_USE_32BIT,
+       .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
+       .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
+       .phy_interface  = PHY_INTERFACE_MODE_MII,
+};
+
+static struct platform_device v2m_eth_device = {
+       .name           = "smsc911x",
+       .id             = -1,
+       .resource       = v2m_eth_resources,
+       .num_resources  = ARRAY_SIZE(v2m_eth_resources),
+       .dev.platform_data = &v2m_eth_config,
+};
+
+static struct resource v2m_usb_resources[] = {
+       {
+               .start  = V2M_ISP1761,
+               .end    = V2M_ISP1761 + SZ_128K - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_V2M_ISP1761,
+               .end    = IRQ_V2M_ISP1761,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct isp1760_platform_data v2m_usb_config = {
+       .is_isp1761             = true,
+       .bus_width_16           = false,
+       .port1_otg              = true,
+       .analog_oc              = false,
+       .dack_polarity_high     = false,
+       .dreq_polarity_high     = false,
+};
+
+static struct platform_device v2m_usb_device = {
+       .name           = "isp1760",
+       .id             = -1,
+       .resource       = v2m_usb_resources,
+       .num_resources  = ARRAY_SIZE(v2m_usb_resources),
+       .dev.platform_data = &v2m_usb_config,
+};
+
+static int v2m_flash_init(void)
+{
+       writel(0, MMIO_P2V(V2M_SYS_FLASH));
+       return 0;
+}
+
+static void v2m_flash_exit(void)
+{
+       writel(0, MMIO_P2V(V2M_SYS_FLASH));
+}
+
+static void v2m_flash_set_vpp(int on)
+{
+       writel(on != 0, MMIO_P2V(V2M_SYS_FLASH));
+}
+
+static struct flash_platform_data v2m_flash_data = {
+       .map_name       = "cfi_probe",
+       .width          = 4,
+       .init           = v2m_flash_init,
+       .exit           = v2m_flash_exit,
+       .set_vpp        = v2m_flash_set_vpp,
+};
+
+static struct resource v2m_flash_resources[] = {
+       {
+               .start  = V2M_NOR0,
+               .end    = V2M_NOR0 + SZ_64M - 1,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = V2M_NOR1,
+               .end    = V2M_NOR1 + SZ_64M - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device v2m_flash_device = {
+       .name           = "armflash",
+       .id             = -1,
+       .resource       = v2m_flash_resources,
+       .num_resources  = ARRAY_SIZE(v2m_flash_resources),
+       .dev.platform_data = &v2m_flash_data,
+};
+
+
+static unsigned int v2m_mmci_status(struct device *dev)
+{
+       return !(readl(MMIO_P2V(V2M_SYS_MCI)) & (1 << 0));
+}
+
+static struct mmci_platform_data v2m_mmci_data = {
+       .ocr_mask       = MMC_VDD_32_33|MMC_VDD_33_34,
+       .status         = v2m_mmci_status,
+};
+
+static AMBA_DEVICE(aaci,  "mb:aaci",  V2M_AACI, NULL);
+static AMBA_DEVICE(mmci,  "mb:mmci",  V2M_MMCI, &v2m_mmci_data);
+static AMBA_DEVICE(kmi0,  "mb:kmi0",  V2M_KMI0, NULL);
+static AMBA_DEVICE(kmi1,  "mb:kmi1",  V2M_KMI1, NULL);
+static AMBA_DEVICE(uart0, "mb:uart0", V2M_UART0, NULL);
+static AMBA_DEVICE(uart1, "mb:uart1", V2M_UART1, NULL);
+static AMBA_DEVICE(uart2, "mb:uart2", V2M_UART2, NULL);
+static AMBA_DEVICE(uart3, "mb:uart3", V2M_UART3, NULL);
+static AMBA_DEVICE(wdt,   "mb:wdt",   V2M_WDT, NULL);
+static AMBA_DEVICE(rtc,   "mb:rtc",   V2M_RTC, NULL);
+
+static struct amba_device *v2m_amba_devs[] __initdata = {
+       &aaci_device,
+       &mmci_device,
+       &kmi0_device,
+       &kmi1_device,
+       &uart0_device,
+       &uart1_device,
+       &uart2_device,
+       &uart3_device,
+       &wdt_device,
+       &rtc_device,
+};
+
+
+static long v2m_osc_round(struct clk *clk, unsigned long rate)
+{
+       return rate;
+}
+
+static int v2m_osc1_set(struct clk *clk, unsigned long rate)
+{
+       return v2m_cfg_write(SYS_CFG_OSC | SYS_CFG_SITE_MB | 1, rate);
+}
+
+static const struct clk_ops osc1_clk_ops = {
+       .round  = v2m_osc_round,
+       .set    = v2m_osc1_set,
+};
+
+static struct clk osc1_clk = {
+       .ops    = &osc1_clk_ops,
+       .rate   = 24000000,
+};
+
+static struct clk osc2_clk = {
+       .rate   = 24000000,
+};
+
+static struct clk_lookup v2m_lookups[] = {
+       {       /* UART0 */
+               .dev_id         = "mb:uart0",
+               .clk            = &osc2_clk,
+       }, {    /* UART1 */
+               .dev_id         = "mb:uart1",
+               .clk            = &osc2_clk,
+       }, {    /* UART2 */
+               .dev_id         = "mb:uart2",
+               .clk            = &osc2_clk,
+       }, {    /* UART3 */
+               .dev_id         = "mb:uart3",
+               .clk            = &osc2_clk,
+       }, {    /* KMI0 */
+               .dev_id         = "mb:kmi0",
+               .clk            = &osc2_clk,
+       }, {    /* KMI1 */
+               .dev_id         = "mb:kmi1",
+               .clk            = &osc2_clk,
+       }, {    /* MMC0 */
+               .dev_id         = "mb:mmci",
+               .clk            = &osc2_clk,
+       }, {    /* CLCD */
+               .dev_id         = "mb:clcd",
+               .clk            = &osc1_clk,
+       },
+};
+
+static void v2m_power_off(void)
+{
+       if (v2m_cfg_write(SYS_CFG_SHUTDOWN | SYS_CFG_SITE_MB, 0))
+               printk(KERN_EMERG "Unable to shutdown\n");
+}
+
+static void v2m_restart(char str, const char *cmd)
+{
+       if (v2m_cfg_write(SYS_CFG_REBOOT | SYS_CFG_SITE_MB, 0))
+               printk(KERN_EMERG "Unable to reboot\n");
+}
+
+static int __init v2m_init(void)
+{
+       int i;
+
+       clkdev_add_table(v2m_lookups, ARRAY_SIZE(v2m_lookups));
+
+       platform_device_register(&v2m_pcie_i2c_device);
+       platform_device_register(&v2m_ddc_i2c_device);
+       platform_device_register(&v2m_flash_device);
+       platform_device_register(&v2m_eth_device);
+       platform_device_register(&v2m_usb_device);
+
+       for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
+               amba_device_register(v2m_amba_devs[i], &iomem_resource);
+
+       pm_power_off = v2m_power_off;
+       arm_pm_restart = v2m_restart;
+
+       return 0;
+}
+arch_initcall(v2m_init);
index 5bd7c89..346ae14 100644 (file)
@@ -572,6 +572,8 @@ config CPU_TLB_V6
 config CPU_TLB_V7
        bool
 
+config VERIFY_PERMISSION_FAULT
+       bool
 endif
 
 config CPU_HAS_ASID
@@ -760,7 +762,8 @@ config CACHE_FEROCEON_L2_WRITETHROUGH
 config CACHE_L2X0
        bool "Enable the L2x0 outer cache controller"
        depends on REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || MACH_REALVIEW_PB1176 || \
-                  REALVIEW_EB_A9MP || ARCH_MX35 || ARCH_MX31 || MACH_REALVIEW_PBX || ARCH_NOMADIK || ARCH_OMAP4
+                  REALVIEW_EB_A9MP || ARCH_MX35 || ARCH_MX31 || MACH_REALVIEW_PBX || \
+                  ARCH_NOMADIK || ARCH_OMAP4 || ARCH_U8500 || ARCH_VEXPRESS_CA9X4
        default y
        select OUTER_CACHE
        select OUTER_CACHE_SYNC
@@ -769,7 +772,7 @@ config CACHE_L2X0
 
 config CACHE_TAUROS2
        bool "Enable the Tauros2 L2 cache controller"
-       depends on ARCH_DOVE
+       depends on (ARCH_DOVE || ARCH_MMP)
        default y
        select OUTER_CACHE
        help
@@ -789,6 +792,25 @@ config ARM_L1_CACHE_SHIFT
        default 6 if ARM_L1_CACHE_SHIFT_6
        default 5
 
+config ARM_DMA_MEM_BUFFERABLE
+       bool "Use non-cacheable memory for DMA" if CPU_V6 && !CPU_V7
+       default y if CPU_V6 || CPU_V7
+       help
+         Historically, the kernel has used strongly ordered mappings to
+         provide DMA coherent memory.  With the advent of ARMv7, mapping
+         memory with differing types results in unpredictable behaviour,
+         so on these CPUs, this option is forced on.
+
+         Multiple mappings with differing attributes is also unpredictable
+         on ARMv6 CPUs, but since they do not have aggressive speculative
+         prefetch, no harm appears to occur.
+
+         However, drivers may be missing the necessary barriers for ARMv6,
+         and therefore turning this on may result in unpredictable driver
+         behaviour.  Therefore, we offer this as an option.
+
+         You are recommended say 'Y' here and debug any affected drivers.
+
 config ARCH_HAS_BARRIERS
        bool
        help
index 2e6dc04..ec88b15 100644 (file)
@@ -29,5 +29,26 @@ ENTRY(v7_early_abort)
         * V6 code adjusts the returned DFSR.
         * New designs should not need to patch up faults.
         */
+
+#if defined(CONFIG_VERIFY_PERMISSION_FAULT)
+       /*
+        * Detect erroneous permission failures and fix
+        */
+       ldr     r3, =0x40d                      @ On permission fault
+       and     r3, r1, r3
+       cmp     r3, #0x0d
+       movne   pc, lr
+
+       mcr     p15, 0, r0, c7, c8, 0           @ Retranslate FAR
+       isb
+       mrc     p15, 0, r2, c7, c4, 0           @ Read the PAR
+       and     r3, r2, #0x7b                   @ On translation fault
+       cmp     r3, #0x0b
+       movne   pc, lr
+       bic     r1, r1, #0xf                    @ Fix up FSR FS[5:0]
+       and     r2, r2, #0x7e
+       orr     r1, r1, r2, LSR #1
+#endif
+
        mov     pc, lr
 ENDPROC(v7_early_abort)
index a2ab51f..6f98c35 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/errno.h>
 #include <linux/string.h>
 #include <linux/proc_fs.h>
+#include <linux/seq_file.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/uaccess.h>
@@ -94,36 +95,29 @@ static const char *usermode_action[] = {
        "signal+warn"
 };
 
-static int
-proc_alignment_read(char *page, char **start, off_t off, int count, int *eof,
-                   void *data)
+static int alignment_proc_show(struct seq_file *m, void *v)
 {
-       char *p = page;
-       int len;
-
-       p += sprintf(p, "User:\t\t%lu\n", ai_user);
-       p += sprintf(p, "System:\t\t%lu\n", ai_sys);
-       p += sprintf(p, "Skipped:\t%lu\n", ai_skipped);
-       p += sprintf(p, "Half:\t\t%lu\n", ai_half);
-       p += sprintf(p, "Word:\t\t%lu\n", ai_word);
+       seq_printf(m, "User:\t\t%lu\n", ai_user);
+       seq_printf(m, "System:\t\t%lu\n", ai_sys);
+       seq_printf(m, "Skipped:\t%lu\n", ai_skipped);
+       seq_printf(m, "Half:\t\t%lu\n", ai_half);
+       seq_printf(m, "Word:\t\t%lu\n", ai_word);
        if (cpu_architecture() >= CPU_ARCH_ARMv5TE)
-               p += sprintf(p, "DWord:\t\t%lu\n", ai_dword);
-       p += sprintf(p, "Multi:\t\t%lu\n", ai_multi);
-       p += sprintf(p, "User faults:\t%i (%s)\n", ai_usermode,
+               seq_printf(m, "DWord:\t\t%lu\n", ai_dword);
+       seq_printf(m, "Multi:\t\t%lu\n", ai_multi);
+       seq_printf(m, "User faults:\t%i (%s)\n", ai_usermode,
                        usermode_action[ai_usermode]);
 
-       len = (p - page) - off;
-       if (len < 0)
-               len = 0;
-
-       *eof = (len <= count) ? 1 : 0;
-       *start = page + off;
+       return 0;
+}
 
-       return len;
+static int alignment_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, alignment_proc_show, NULL);
 }
 
-static int proc_alignment_write(struct file *file, const char __user *buffer,
-                               unsigned long count, void *data)
+static ssize_t alignment_proc_write(struct file *file, const char __user *buffer,
+                                   size_t count, loff_t *pos)
 {
        char mode;
 
@@ -136,6 +130,13 @@ static int proc_alignment_write(struct file *file, const char __user *buffer,
        return count;
 }
 
+static const struct file_operations alignment_proc_fops = {
+       .open           = alignment_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+       .write          = alignment_proc_write,
+};
 #endif /* CONFIG_PROC_FS */
 
 union offset_union {
@@ -901,12 +902,10 @@ static int __init alignment_init(void)
 #ifdef CONFIG_PROC_FS
        struct proc_dir_entry *res;
 
-       res = create_proc_entry("cpu/alignment", S_IWUSR | S_IRUGO, NULL);
+       res = proc_create("cpu/alignment", S_IWUSR | S_IRUGO, NULL,
+                         &alignment_proc_fops);
        if (!res)
                return -ENOMEM;
-
-       res->read_proc = proc_alignment_read;
-       res->write_proc = proc_alignment_write;
 #endif
 
        /*
index 21ad68b..9819869 100644 (file)
@@ -27,6 +27,7 @@
 
 static void __iomem *l2x0_base;
 static DEFINE_SPINLOCK(l2x0_lock);
+static uint32_t l2x0_way_mask; /* Bitmask of active ways */
 
 static inline void cache_wait(void __iomem *reg, unsigned long mask)
 {
@@ -108,8 +109,8 @@ static inline void l2x0_inv_all(void)
 
        /* invalidate all ways */
        spin_lock_irqsave(&l2x0_lock, flags);
-       writel(0xff, l2x0_base + L2X0_INV_WAY);
-       cache_wait(l2x0_base + L2X0_INV_WAY, 0xff);
+       writel(l2x0_way_mask, l2x0_base + L2X0_INV_WAY);
+       cache_wait(l2x0_base + L2X0_INV_WAY, l2x0_way_mask);
        cache_sync();
        spin_unlock_irqrestore(&l2x0_lock, flags);
 }
@@ -208,9 +209,37 @@ static void l2x0_flush_range(unsigned long start, unsigned long end)
 void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
 {
        __u32 aux;
+       __u32 cache_id;
+       int ways;
+       const char *type;
 
        l2x0_base = base;
 
+       cache_id = readl(l2x0_base + L2X0_CACHE_ID);
+       aux = readl(l2x0_base + L2X0_AUX_CTRL);
+
+       /* Determine the number of ways */
+       switch (cache_id & L2X0_CACHE_ID_PART_MASK) {
+       case L2X0_CACHE_ID_PART_L310:
+               if (aux & (1 << 16))
+                       ways = 16;
+               else
+                       ways = 8;
+               type = "L310";
+               break;
+       case L2X0_CACHE_ID_PART_L210:
+               ways = (aux >> 13) & 0xf;
+               type = "L210";
+               break;
+       default:
+               /* Assume unknown chips have 8 ways */
+               ways = 8;
+               type = "L2x0 series";
+               break;
+       }
+
+       l2x0_way_mask = (1 << ways) - 1;
+
        /*
         * Check if l2x0 controller is already enabled.
         * If you are booting from non-secure mode
@@ -219,8 +248,6 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
        if (!(readl(l2x0_base + L2X0_CTRL) & 1)) {
 
                /* l2x0 controller is disabled */
-
-               aux = readl(l2x0_base + L2X0_AUX_CTRL);
                aux &= aux_mask;
                aux |= aux_val;
                writel(aux, l2x0_base + L2X0_AUX_CTRL);
@@ -236,5 +263,7 @@ void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
        outer_cache.flush_range = l2x0_flush_range;
        outer_cache.sync = l2x0_cache_sync;
 
-       printk(KERN_INFO "L2X0 cache controller enabled\n");
+       printk(KERN_INFO "%s cache controller enabled\n", type);
+       printk(KERN_INFO "l2x0: %d ways, CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
+                        ways, cache_id, aux);
 }
index b2a6008..d2852e1 100644 (file)
@@ -40,7 +40,7 @@ fa_copy_user_page(void *kto, const void *kfrom)
 }
 
 void fa_copy_user_highpage(struct page *to, struct page *from,
-       unsigned long vaddr)
+       unsigned long vaddr, struct vm_area_struct *vma)
 {
        void *kto, *kfrom;
 
index 0d414c2..9b906de 100644 (file)
@@ -134,8 +134,6 @@ make_coherent(struct address_space *mapping, struct vm_area_struct *vma,
        flush_dcache_mmap_unlock(mapping);
        if (aliases)
                do_adjust_pte(vma, addr, pfn, ptep);
-       else
-               flush_cache_page(vma, addr, pfn);
 }
 
 /*
index 9d40c34..92f5801 100644 (file)
@@ -463,7 +463,12 @@ static struct fsr_info {
        { do_bad,               SIGILL,  BUS_ADRALN,    "alignment exception"              },
        { do_bad,               SIGKILL, 0,             "terminal exception"               },
        { do_bad,               SIGILL,  BUS_ADRALN,    "alignment exception"              },
+/* Do we need runtime check ? */
+#if __LINUX_ARM_ARCH__ < 6
        { do_bad,               SIGBUS,  0,             "external abort on linefetch"      },
+#else
+       { do_translation_fault, SIGSEGV, SEGV_MAPERR,   "I-cache maintenance fault"        },
+#endif
        { do_translation_fault, SIGSEGV, SEGV_MAPERR,   "section translation fault"        },
        { do_bad,               SIGBUS,  0,             "external abort on linefetch"      },
        { do_page_fault,        SIGSEGV, SEGV_MAPERR,   "page translation fault"           },
index 0ed29bf..1ba6cf5 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/mman.h>
 #include <linux/nodemask.h>
 #include <linux/initrd.h>
-#include <linux/sort.h>
 #include <linux/highmem.h>
 #include <linux/gfp.h>
 
@@ -224,20 +223,6 @@ static int __init check_initrd(struct meminfo *mi)
        return initrd_node;
 }
 
-static inline void map_memory_bank(struct membank *bank)
-{
-#ifdef CONFIG_MMU
-       struct map_desc map;
-
-       map.pfn = bank_pfn_start(bank);
-       map.virtual = __phys_to_virt(bank_phys_start(bank));
-       map.length = bank_phys_size(bank);
-       map.type = MT_MEMORY;
-
-       create_mapping(&map);
-#endif
-}
-
 static void __init bootmem_init_node(int node, struct meminfo *mi,
        unsigned long start_pfn, unsigned long end_pfn)
 {
@@ -246,16 +231,6 @@ static void __init bootmem_init_node(int node, struct meminfo *mi,
        pg_data_t *pgdat;
        int i;
 
-       /*
-        * Map the memory banks for this node.
-        */
-       for_each_nodebank(i, mi, node) {
-               struct membank *bank = &mi->bank[i];
-
-               if (!bank->highmem)
-                       map_memory_bank(bank);
-       }
-
        /*
         * Allocate the bootmem bitmap page.
         */
@@ -385,21 +360,12 @@ static void arm_memory_present(struct meminfo *mi, int node)
 }
 #endif
 
-static int __init meminfo_cmp(const void *_a, const void *_b)
-{
-       const struct membank *a = _a, *b = _b;
-       long cmp = bank_pfn_start(a) - bank_pfn_start(b);
-       return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
-}
-
 void __init bootmem_init(void)
 {
        struct meminfo *mi = &meminfo;
        unsigned long min, max_low, max_high;
        int node, initrd_node;
 
-       sort(&mi->bank, mi->nr_banks, sizeof(mi->bank[0]), meminfo_cmp, NULL);
-
        /*
         * Locate which node contains the ramdisk image, if any.
         */
index a888363..815d08e 100644 (file)
@@ -28,10 +28,7 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page
 
 #endif
 
-struct map_desc;
-struct meminfo;
 struct pglist_data;
 
-void __init create_mapping(struct map_desc *md);
 void __init bootmem_init(void);
 void reserve_node_zero(struct pglist_data *pgdat);
index 241c24a..2858941 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/bootmem.h>
 #include <linux/mman.h>
 #include <linux/nodemask.h>
+#include <linux/sort.h>
 
 #include <asm/cputype.h>
 #include <asm/mach-types.h>
@@ -603,7 +604,7 @@ static void __init create_36bit_mapping(struct map_desc *md,
  * offsets, and we take full advantage of sections and
  * supersections.
  */
-void __init create_mapping(struct map_desc *md)
+static void __init create_mapping(struct map_desc *md)
 {
        unsigned long phys, addr, length, end;
        const struct mem_type *type;
@@ -869,9 +870,10 @@ void __init reserve_node_zero(pg_data_t *pgdat)
        if (machine_is_p720t())
                res_size = 0x00014000;
 
-       /* H1940 and RX3715 need to reserve this for suspend */
+       /* H1940, RX3715 and RX1950 need to reserve this for suspend */
 
-       if (machine_is_h1940() || machine_is_rx3715()) {
+       if (machine_is_h1940() || machine_is_rx3715()
+               || machine_is_rx1950()) {
                reserve_bootmem_node(pgdat, 0x30003000, 0x1000,
                                BOOTMEM_DEFAULT);
                reserve_bootmem_node(pgdat, 0x30081000, 0x1000,
@@ -1017,6 +1019,39 @@ static void __init kmap_init(void)
 #endif
 }
 
+static inline void map_memory_bank(struct membank *bank)
+{
+       struct map_desc map;
+
+       map.pfn = bank_pfn_start(bank);
+       map.virtual = __phys_to_virt(bank_phys_start(bank));
+       map.length = bank_phys_size(bank);
+       map.type = MT_MEMORY;
+
+       create_mapping(&map);
+}
+
+static void __init map_lowmem(void)
+{
+       struct meminfo *mi = &meminfo;
+       int i;
+
+       /* Map all the lowmem memory banks. */
+       for (i = 0; i < mi->nr_banks; i++) {
+               struct membank *bank = &mi->bank[i];
+
+               if (!bank->highmem)
+                       map_memory_bank(bank);
+       }
+}
+
+static int __init meminfo_cmp(const void *_a, const void *_b)
+{
+       const struct membank *a = _a, *b = _b;
+       long cmp = bank_pfn_start(a) - bank_pfn_start(b);
+       return cmp < 0 ? -1 : cmp > 0 ? 1 : 0;
+}
+
 /*
  * paging_init() sets up the page tables, initialises the zone memory
  * maps, and sets up the zero page, bad page and bad page tables.
@@ -1025,9 +1060,12 @@ void __init paging_init(struct machine_desc *mdesc)
 {
        void *zero_page;
 
+       sort(&meminfo.bank, meminfo.nr_banks, sizeof(meminfo.bank[0]), meminfo_cmp, NULL);
+
        build_mem_type_table();
        sanity_check_meminfo();
        prepare_page_table();
+       map_lowmem();
        bootmem_init();
        devicemaps_init(mdesc);
        kmap_init();
index 4c0ab50..cb7658e 100644 (file)
@@ -24,6 +24,7 @@
 #include "fpa11.h"
 
 #include <linux/module.h>
+#include <linux/moduleparam.h>
 
 /* XXX */
 #include <linux/errno.h>
@@ -134,13 +135,17 @@ a SIGFPE exception if necessary.  If not the relevant bits in the
 cumulative exceptions flag byte are set and we return.
 */
 
+#ifdef CONFIG_DEBUG_USER
+/* By default, ignore inexact errors as there are far too many of them to log */
+static int debug = ~BIT_IXC;
+#endif
+
 void float_raise(signed char flags)
 {
        register unsigned int fpsr, cumulativeTraps;
 
 #ifdef CONFIG_DEBUG_USER
-       /* Ignore inexact errors as there are far too many of them to log */
-       if (flags & ~BIT_IXC)
+       if (flags & debug)
                printk(KERN_DEBUG
                       "NWFPE: %s[%d] takes exception %08x at %p from %08lx\n",
                       current->comm, current->pid, flags,
@@ -179,3 +184,7 @@ module_exit(fpe_exit);
 MODULE_AUTHOR("Scott Bambrough <scottb@rebel.com>");
 MODULE_DESCRIPTION("NWFPE floating point emulator (" NWFPE_BITS " precision)");
 MODULE_LICENSE("GPL");
+
+#ifdef CONFIG_DEBUG_USER
+module_param(debug, int, 0644);
+#endif
index 88e31f5..e666eaf 100644 (file)
@@ -6,9 +6,4 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
                oprofilefs.o oprofile_stats.o \
                timer_int.o )
 
-oprofile-y                             := $(DRIVER_OBJS) common.o backtrace.o
-oprofile-$(CONFIG_CPU_XSCALE)          += op_model_xscale.o
-oprofile-$(CONFIG_OPROFILE_ARM11_CORE) += op_model_arm11_core.o
-oprofile-$(CONFIG_OPROFILE_ARMV6)      += op_model_v6.o
-oprofile-$(CONFIG_OPROFILE_MPCORE)     += op_model_mpcore.o
-oprofile-$(CONFIG_OPROFILE_ARMV7)      += op_model_v7.o
+oprofile-y                             := $(DRIVER_OBJS) common.o
diff --git a/arch/arm/oprofile/backtrace.c b/arch/arm/oprofile/backtrace.c
deleted file mode 100644 (file)
index d805a52..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Arm specific backtracing code for oprofile
- *
- * Copyright 2005 Openedhand Ltd.
- *
- * Author: Richard Purdie <rpurdie@openedhand.com>
- *
- * Based on i386 oprofile backtrace code by John Levon, David Smith
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- */
-
-#include <linux/oprofile.h>
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/uaccess.h>
-#include <asm/ptrace.h>
-#include <asm/stacktrace.h>
-
-static int report_trace(struct stackframe *frame, void *d)
-{
-       unsigned int *depth = d;
-
-       if (*depth) {
-               oprofile_add_trace(frame->pc);
-               (*depth)--;
-       }
-
-       return *depth == 0;
-}
-
-/*
- * The registers we're interested in are at the end of the variable
- * length saved register structure. The fp points at the end of this
- * structure so the address of this struct is:
- * (struct frame_tail *)(xxx->fp)-1
- */
-struct frame_tail {
-       struct frame_tail *fp;
-       unsigned long sp;
-       unsigned long lr;
-} __attribute__((packed));
-
-static struct frame_tail* user_backtrace(struct frame_tail *tail)
-{
-       struct frame_tail buftail[2];
-
-       /* Also check accessibility of one struct frame_tail beyond */
-       if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
-               return NULL;
-       if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
-               return NULL;
-
-       oprofile_add_trace(buftail[0].lr);
-
-       /* frame pointers should strictly progress back up the stack
-        * (towards higher addresses) */
-       if (tail >= buftail[0].fp)
-               return NULL;
-
-       return buftail[0].fp-1;
-}
-
-void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
-{
-       struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
-
-       if (!user_mode(regs)) {
-               struct stackframe frame;
-               frame.fp = regs->ARM_fp;
-               frame.sp = regs->ARM_sp;
-               frame.lr = regs->ARM_lr;
-               frame.pc = regs->ARM_pc;
-               walk_stackframe(&frame, report_trace, &depth);
-               return;
-       }
-
-       while (depth-- && tail && !((unsigned long) tail & 3))
-               tail = user_backtrace(tail);
-}
index 3fcd752..0691176 100644 (file)
  * @file common.c
  *
  * @remark Copyright 2004 Oprofile Authors
+ * @remark Copyright 2010 ARM Ltd.
  * @remark Read the file COPYING
  *
  * @author Zwane Mwaikambo
+ * @author Will Deacon [move to perf]
  */
 
+#include <linux/cpumask.h>
+#include <linux/err.h>
+#include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/mutex.h>
 #include <linux/oprofile.h>
-#include <linux/errno.h>
+#include <linux/perf_event.h>
+#include <linux/platform_device.h>
 #include <linux/slab.h>
-#include <linux/sysdev.h>
-#include <linux/mutex.h>
+#include <asm/stacktrace.h>
+#include <linux/uaccess.h>
 
-#include "op_counter.h"
-#include "op_arm_model.h"
+#include <asm/perf_event.h>
+#include <asm/ptrace.h>
+
+#ifdef CONFIG_HW_PERF_EVENTS
+/*
+ * Per performance monitor configuration as set via oprofilefs.
+ */
+struct op_counter_config {
+       unsigned long count;
+       unsigned long enabled;
+       unsigned long event;
+       unsigned long unit_mask;
+       unsigned long kernel;
+       unsigned long user;
+       struct perf_event_attr attr;
+};
 
-static struct op_arm_model_spec *op_arm_model;
 static int op_arm_enabled;
 static DEFINE_MUTEX(op_arm_mutex);
 
-struct op_counter_config *counter_config;
+static struct op_counter_config *counter_config;
+static struct perf_event **perf_events[nr_cpumask_bits];
+static int perf_num_counters;
+
+/*
+ * Overflow callback for oprofile.
+ */
+static void op_overflow_handler(struct perf_event *event, int unused,
+                       struct perf_sample_data *data, struct pt_regs *regs)
+{
+       int id;
+       u32 cpu = smp_processor_id();
+
+       for (id = 0; id < perf_num_counters; ++id)
+               if (perf_events[cpu][id] == event)
+                       break;
+
+       if (id != perf_num_counters)
+               oprofile_add_sample(regs, id);
+       else
+               pr_warning("oprofile: ignoring spurious overflow "
+                               "on cpu %u\n", cpu);
+}
+
+/*
+ * Called by op_arm_setup to create perf attributes to mirror the oprofile
+ * settings in counter_config. Attributes are created as `pinned' events and
+ * so are permanently scheduled on the PMU.
+ */
+static void op_perf_setup(void)
+{
+       int i;
+       u32 size = sizeof(struct perf_event_attr);
+       struct perf_event_attr *attr;
+
+       for (i = 0; i < perf_num_counters; ++i) {
+               attr = &counter_config[i].attr;
+               memset(attr, 0, size);
+               attr->type              = PERF_TYPE_RAW;
+               attr->size              = size;
+               attr->config            = counter_config[i].event;
+               attr->sample_period     = counter_config[i].count;
+               attr->pinned            = 1;
+       }
+}
+
+static int op_create_counter(int cpu, int event)
+{
+       int ret = 0;
+       struct perf_event *pevent;
+
+       if (!counter_config[event].enabled || (perf_events[cpu][event] != NULL))
+               return ret;
+
+       pevent = perf_event_create_kernel_counter(&counter_config[event].attr,
+                                                 cpu, -1,
+                                                 op_overflow_handler);
+
+       if (IS_ERR(pevent)) {
+               ret = PTR_ERR(pevent);
+       } else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {
+               pr_warning("oprofile: failed to enable event %d "
+                               "on CPU %d\n", event, cpu);
+               ret = -EBUSY;
+       } else {
+               perf_events[cpu][event] = pevent;
+       }
+
+       return ret;
+}
+
+static void op_destroy_counter(int cpu, int event)
+{
+       struct perf_event *pevent = perf_events[cpu][event];
+
+       if (pevent) {
+               perf_event_release_kernel(pevent);
+               perf_events[cpu][event] = NULL;
+       }
+}
+
+/*
+ * Called by op_arm_start to create active perf events based on the
+ * perviously configured attributes.
+ */
+static int op_perf_start(void)
+{
+       int cpu, event, ret = 0;
+
+       for_each_online_cpu(cpu) {
+               for (event = 0; event < perf_num_counters; ++event) {
+                       ret = op_create_counter(cpu, event);
+                       if (ret)
+                               goto out;
+               }
+       }
+
+out:
+       return ret;
+}
+
+/*
+ * Called by op_arm_stop at the end of a profiling run.
+ */
+static void op_perf_stop(void)
+{
+       int cpu, event;
+
+       for_each_online_cpu(cpu)
+               for (event = 0; event < perf_num_counters; ++event)
+                       op_destroy_counter(cpu, event);
+}
+
+
+static char *op_name_from_perf_id(enum arm_perf_pmu_ids id)
+{
+       switch (id) {
+       case ARM_PERF_PMU_ID_XSCALE1:
+               return "arm/xscale1";
+       case ARM_PERF_PMU_ID_XSCALE2:
+               return "arm/xscale2";
+       case ARM_PERF_PMU_ID_V6:
+               return "arm/armv6";
+       case ARM_PERF_PMU_ID_V6MP:
+               return "arm/mpcore";
+       case ARM_PERF_PMU_ID_CA8:
+               return "arm/armv7";
+       case ARM_PERF_PMU_ID_CA9:
+               return "arm/armv7-ca9";
+       default:
+               return NULL;
+       }
+}
 
 static int op_arm_create_files(struct super_block *sb, struct dentry *root)
 {
        unsigned int i;
 
-       for (i = 0; i < op_arm_model->num_counters; i++) {
+       for (i = 0; i < perf_num_counters; i++) {
                struct dentry *dir;
                char buf[4];
 
@@ -46,12 +198,10 @@ static int op_arm_create_files(struct super_block *sb, struct dentry *root)
 
 static int op_arm_setup(void)
 {
-       int ret;
-
        spin_lock(&oprofilefs_lock);
-       ret = op_arm_model->setup_ctrs();
+       op_perf_setup();
        spin_unlock(&oprofilefs_lock);
-       return ret;
+       return 0;
 }
 
 static int op_arm_start(void)
@@ -60,8 +210,9 @@ static int op_arm_start(void)
 
        mutex_lock(&op_arm_mutex);
        if (!op_arm_enabled) {
-               ret = op_arm_model->start();
-               op_arm_enabled = !ret;
+               ret = 0;
+               op_perf_start();
+               op_arm_enabled = 1;
        }
        mutex_unlock(&op_arm_mutex);
        return ret;
@@ -71,113 +222,205 @@ static void op_arm_stop(void)
 {
        mutex_lock(&op_arm_mutex);
        if (op_arm_enabled)
-               op_arm_model->stop();
+               op_perf_stop();
        op_arm_enabled = 0;
        mutex_unlock(&op_arm_mutex);
 }
 
 #ifdef CONFIG_PM
-static int op_arm_suspend(struct sys_device *dev, pm_message_t state)
+static int op_arm_suspend(struct platform_device *dev, pm_message_t state)
 {
        mutex_lock(&op_arm_mutex);
        if (op_arm_enabled)
-               op_arm_model->stop();
+               op_perf_stop();
        mutex_unlock(&op_arm_mutex);
        return 0;
 }
 
-static int op_arm_resume(struct sys_device *dev)
+static int op_arm_resume(struct platform_device *dev)
 {
        mutex_lock(&op_arm_mutex);
-       if (op_arm_enabled && op_arm_model->start())
+       if (op_arm_enabled && op_perf_start())
                op_arm_enabled = 0;
        mutex_unlock(&op_arm_mutex);
        return 0;
 }
 
-static struct sysdev_class oprofile_sysclass = {
-       .name           = "oprofile",
+static struct platform_driver oprofile_driver = {
+       .driver         = {
+               .name           = "arm-oprofile",
+       },
        .resume         = op_arm_resume,
        .suspend        = op_arm_suspend,
 };
 
-static struct sys_device device_oprofile = {
-       .id             = 0,
-       .cls            = &oprofile_sysclass,
-};
+static struct platform_device *oprofile_pdev;
 
 static int __init init_driverfs(void)
 {
        int ret;
 
-       if (!(ret = sysdev_class_register(&oprofile_sysclass)))
-               ret = sysdev_register(&device_oprofile);
+       ret = platform_driver_register(&oprofile_driver);
+       if (ret)
+               goto out;
 
+       oprofile_pdev = platform_device_register_simple(
+                               oprofile_driver.driver.name, 0, NULL, 0);
+       if (IS_ERR(oprofile_pdev)) {
+               ret = PTR_ERR(oprofile_pdev);
+               platform_driver_unregister(&oprofile_driver);
+       }
+
+out:
        return ret;
 }
 
 static void  exit_driverfs(void)
 {
-       sysdev_unregister(&device_oprofile);
-       sysdev_class_unregister(&oprofile_sysclass);
+       platform_device_unregister(oprofile_pdev);
+       platform_driver_unregister(&oprofile_driver);
 }
 #else
-#define init_driverfs()        do { } while (0)
+static int __init init_driverfs(void) { return 0; }
 #define exit_driverfs() do { } while (0)
 #endif /* CONFIG_PM */
 
-int __init oprofile_arch_init(struct oprofile_operations *ops)
+static int report_trace(struct stackframe *frame, void *d)
 {
-       struct op_arm_model_spec *spec = NULL;
-       int ret = -ENODEV;
+       unsigned int *depth = d;
 
-       ops->backtrace = arm_backtrace;
+       if (*depth) {
+               oprofile_add_trace(frame->pc);
+               (*depth)--;
+       }
 
-#ifdef CONFIG_CPU_XSCALE
-       spec = &op_xscale_spec;
-#endif
+       return *depth == 0;
+}
 
-#ifdef CONFIG_OPROFILE_ARMV6
-       spec = &op_armv6_spec;
-#endif
+/*
+ * The registers we're interested in are at the end of the variable
+ * length saved register structure. The fp points at the end of this
+ * structure so the address of this struct is:
+ * (struct frame_tail *)(xxx->fp)-1
+ */
+struct frame_tail {
+       struct frame_tail *fp;
+       unsigned long sp;
+       unsigned long lr;
+} __attribute__((packed));
 
-#ifdef CONFIG_OPROFILE_MPCORE
-       spec = &op_mpcore_spec;
-#endif
+static struct frame_tail* user_backtrace(struct frame_tail *tail)
+{
+       struct frame_tail buftail[2];
 
-#ifdef CONFIG_OPROFILE_ARMV7
-       spec = &op_armv7_spec;
-#endif
+       /* Also check accessibility of one struct frame_tail beyond */
+       if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))
+               return NULL;
+       if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))
+               return NULL;
 
-       if (spec) {
-               ret = spec->init();
-               if (ret < 0)
-                       return ret;
+       oprofile_add_trace(buftail[0].lr);
 
-               counter_config = kcalloc(spec->num_counters, sizeof(struct op_counter_config),
-                                        GFP_KERNEL);
-               if (!counter_config)
-                       return -ENOMEM;
+       /* frame pointers should strictly progress back up the stack
+        * (towards higher addresses) */
+       if (tail >= buftail[0].fp)
+               return NULL;
 
-               op_arm_model = spec;
-               init_driverfs();
-               ops->create_files = op_arm_create_files;
-               ops->setup = op_arm_setup;
-               ops->shutdown = op_arm_stop;
-               ops->start = op_arm_start;
-               ops->stop = op_arm_stop;
-               ops->cpu_type = op_arm_model->name;
-               printk(KERN_INFO "oprofile: using %s\n", spec->name);
+       return buftail[0].fp-1;
+}
+
+static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)
+{
+       struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;
+
+       if (!user_mode(regs)) {
+               struct stackframe frame;
+               frame.fp = regs->ARM_fp;
+               frame.sp = regs->ARM_sp;
+               frame.lr = regs->ARM_lr;
+               frame.pc = regs->ARM_pc;
+               walk_stackframe(&frame, report_trace, &depth);
+               return;
        }
 
+       while (depth-- && tail && !((unsigned long) tail & 3))
+               tail = user_backtrace(tail);
+}
+
+int __init oprofile_arch_init(struct oprofile_operations *ops)
+{
+       int cpu, ret = 0;
+
+       perf_num_counters = armpmu_get_max_events();
+
+       counter_config = kcalloc(perf_num_counters,
+                       sizeof(struct op_counter_config), GFP_KERNEL);
+
+       if (!counter_config) {
+               pr_info("oprofile: failed to allocate %d "
+                               "counters\n", perf_num_counters);
+               return -ENOMEM;
+       }
+
+       ret = init_driverfs();
+       if (ret) {
+               kfree(counter_config);
+               return ret;
+       }
+
+       for_each_possible_cpu(cpu) {
+               perf_events[cpu] = kcalloc(perf_num_counters,
+                               sizeof(struct perf_event *), GFP_KERNEL);
+               if (!perf_events[cpu]) {
+                       pr_info("oprofile: failed to allocate %d perf events "
+                                       "for cpu %d\n", perf_num_counters, cpu);
+                       while (--cpu >= 0)
+                               kfree(perf_events[cpu]);
+                       return -ENOMEM;
+               }
+       }
+
+       ops->backtrace          = arm_backtrace;
+       ops->create_files       = op_arm_create_files;
+       ops->setup              = op_arm_setup;
+       ops->start              = op_arm_start;
+       ops->stop               = op_arm_stop;
+       ops->shutdown           = op_arm_stop;
+       ops->cpu_type           = op_name_from_perf_id(armpmu_get_pmu_id());
+
+       if (!ops->cpu_type)
+               ret = -ENODEV;
+       else
+               pr_info("oprofile: using %s\n", ops->cpu_type);
+
        return ret;
 }
 
 void oprofile_arch_exit(void)
 {
-       if (op_arm_model) {
+       int cpu, id;
+       struct perf_event *event;
+
+       if (*perf_events) {
                exit_driverfs();
-               op_arm_model = NULL;
+               for_each_possible_cpu(cpu) {
+                       for (id = 0; id < perf_num_counters; ++id) {
+                               event = perf_events[cpu][id];
+                               if (event != NULL)
+                                       perf_event_release_kernel(event);
+                       }
+                       kfree(perf_events[cpu]);
+               }
        }
-       kfree(counter_config);
+
+       if (counter_config)
+               kfree(counter_config);
+}
+#else
+int __init oprofile_arch_init(struct oprofile_operations *ops)
+{
+       pr_info("oprofile: hardware counters not available\n");
+       return -ENODEV;
 }
+void oprofile_arch_exit(void) {}
+#endif /* CONFIG_HW_PERF_EVENTS */
diff --git a/arch/arm/oprofile/op_arm_model.h b/arch/arm/oprofile/op_arm_model.h
deleted file mode 100644 (file)
index 8c4e4f6..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * @file op_arm_model.h
- * interface to ARM machine specific operations
- *
- * @remark Copyright 2004 Oprofile Authors
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- */
-
-#ifndef OP_ARM_MODEL_H
-#define OP_ARM_MODEL_H
-
-struct op_arm_model_spec {
-       int (*init)(void);
-       unsigned int num_counters;
-       int (*setup_ctrs)(void);
-       int (*start)(void);
-       void (*stop)(void);
-       char *name;
-};
-
-#ifdef CONFIG_CPU_XSCALE
-extern struct op_arm_model_spec op_xscale_spec;
-#endif
-
-extern struct op_arm_model_spec op_armv6_spec;
-extern struct op_arm_model_spec op_mpcore_spec;
-extern struct op_arm_model_spec op_armv7_spec;
-
-extern void arm_backtrace(struct pt_regs * const regs, unsigned int depth);
-
-extern int __init op_arm_init(struct oprofile_operations *ops, struct op_arm_model_spec *spec);
-extern void op_arm_exit(void);
-#endif /* OP_ARM_MODEL_H */
diff --git a/arch/arm/oprofile/op_counter.h b/arch/arm/oprofile/op_counter.h
deleted file mode 100644 (file)
index ca942a6..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
- * @file op_counter.h
- *
- * @remark Copyright 2004 Oprofile Authors
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- */
-
-#ifndef OP_COUNTER_H
-#define OP_COUNTER_H
-
-/* Per performance monitor configuration as set via
- * oprofilefs.
- */
-struct op_counter_config {
-       unsigned long count;
-       unsigned long enabled;
-       unsigned long event;
-       unsigned long unit_mask;
-       unsigned long kernel;
-       unsigned long user;
-};
-
-extern struct op_counter_config *counter_config;
-
-#endif /* OP_COUNTER_H */
diff --git a/arch/arm/oprofile/op_model_arm11_core.c b/arch/arm/oprofile/op_model_arm11_core.c
deleted file mode 100644 (file)
index ef3e265..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/**
- * @file op_model_arm11_core.c
- * ARM11 Event Monitor Driver
- * @remark Copyright 2004 ARM SMP Development Team
- */
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/oprofile.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/smp.h>
-
-#include "op_counter.h"
-#include "op_arm_model.h"
-#include "op_model_arm11_core.h"
-
-/*
- * ARM11 PMU support
- */
-static inline void arm11_write_pmnc(u32 val)
-{
-       /* upper 4bits and 7, 11 are write-as-0 */
-       val &= 0x0ffff77f;
-       asm volatile("mcr p15, 0, %0, c15, c12, 0" : : "r" (val));
-}
-
-static inline u32 arm11_read_pmnc(void)
-{
-       u32 val;
-       asm volatile("mrc p15, 0, %0, c15, c12, 0" : "=r" (val));
-       return val;
-}
-
-static void arm11_reset_counter(unsigned int cnt)
-{
-       u32 val = -(u32)counter_config[CPU_COUNTER(smp_processor_id(), cnt)].count;
-       switch (cnt) {
-       case CCNT:
-               asm volatile("mcr p15, 0, %0, c15, c12, 1" : : "r" (val));
-               break;
-
-       case PMN0:
-               asm volatile("mcr p15, 0, %0, c15, c12, 2" : : "r" (val));
-               break;
-
-       case PMN1:
-               asm volatile("mcr p15, 0, %0, c15, c12, 3" : : "r" (val));
-               break;
-       }
-}
-
-int arm11_setup_pmu(void)
-{
-       unsigned int cnt;
-       u32 pmnc;
-
-       if (arm11_read_pmnc() & PMCR_E) {
-               printk(KERN_ERR "oprofile: CPU%u PMU still enabled when setup new event counter.\n", smp_processor_id());
-               return -EBUSY;
-       }
-
-       /* initialize PMNC, reset overflow, D bit, C bit and P bit. */
-       arm11_write_pmnc(PMCR_OFL_PMN0 | PMCR_OFL_PMN1 | PMCR_OFL_CCNT |
-                        PMCR_C | PMCR_P);
-
-       for (pmnc = 0, cnt = PMN0; cnt <= CCNT; cnt++) {
-               unsigned long event;
-
-               if (!counter_config[CPU_COUNTER(smp_processor_id(), cnt)].enabled)
-                       continue;
-
-               event = counter_config[CPU_COUNTER(smp_processor_id(), cnt)].event & 255;
-
-               /*
-                * Set event (if destined for PMNx counters)
-                */
-               if (cnt == PMN0) {
-                       pmnc |= event << 20;
-               } else if (cnt == PMN1) {
-                       pmnc |= event << 12;
-               }
-
-               /*
-                * We don't need to set the event if it's a cycle count
-                * Enable interrupt for this counter
-                */
-               pmnc |= PMCR_IEN_PMN0 << cnt;
-               arm11_reset_counter(cnt);
-       }
-       arm11_write_pmnc(pmnc);
-
-       return 0;
-}
-
-int arm11_start_pmu(void)
-{
-       arm11_write_pmnc(arm11_read_pmnc() | PMCR_E);
-       return 0;
-}
-
-int arm11_stop_pmu(void)
-{
-       unsigned int cnt;
-
-       arm11_write_pmnc(arm11_read_pmnc() & ~PMCR_E);
-
-       for (cnt = PMN0; cnt <= CCNT; cnt++)
-               arm11_reset_counter(cnt);
-
-       return 0;
-}
-
-/*
- * CPU counters' IRQ handler (one IRQ per CPU)
- */
-static irqreturn_t arm11_pmu_interrupt(int irq, void *arg)
-{
-       struct pt_regs *regs = get_irq_regs();
-       unsigned int cnt;
-       u32 pmnc;
-
-       pmnc = arm11_read_pmnc();
-
-       for (cnt = PMN0; cnt <= CCNT; cnt++) {
-               if ((pmnc & (PMCR_OFL_PMN0 << cnt)) && (pmnc & (PMCR_IEN_PMN0 << cnt))) {
-                       arm11_reset_counter(cnt);
-                       oprofile_add_sample(regs, CPU_COUNTER(smp_processor_id(), cnt));
-               }
-       }
-       /* Clear counter flag(s) */
-       arm11_write_pmnc(pmnc);
-       return IRQ_HANDLED;
-}
-
-int arm11_request_interrupts(const int *irqs, int nr)
-{
-       unsigned int i;
-       int ret = 0;
-
-       for(i = 0; i < nr; i++) {
-               ret = request_irq(irqs[i], arm11_pmu_interrupt, IRQF_DISABLED, "CP15 PMU", NULL);
-               if (ret != 0) {
-                       printk(KERN_ERR "oprofile: unable to request IRQ%u for MPCORE-EM\n",
-                              irqs[i]);
-                       break;
-               }
-       }
-
-       if (i != nr)
-               while (i-- != 0)
-                       free_irq(irqs[i], NULL);
-
-       return ret;
-}
-
-void arm11_release_interrupts(const int *irqs, int nr)
-{
-       unsigned int i;
-
-       for (i = 0; i < nr; i++)
-               free_irq(irqs[i], NULL);
-}
diff --git a/arch/arm/oprofile/op_model_arm11_core.h b/arch/arm/oprofile/op_model_arm11_core.h
deleted file mode 100644 (file)
index 1902b99..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * @file op_model_arm11_core.h
- * ARM11 Event Monitor Driver
- * @remark Copyright 2004 ARM SMP Development Team
- * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * @remark Copyright 2000-2004 MontaVista Software Inc
- * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * @remark Copyright 2004 Intel Corporation
- * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * @remark Copyright 2004 Oprofile Authors
- *
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- */
-#ifndef OP_MODEL_ARM11_CORE_H
-#define OP_MODEL_ARM11_CORE_H
-
-/*
- * Per-CPU PMCR
- */
-#define PMCR_E         (1 << 0)        /* Enable */
-#define PMCR_P         (1 << 1)        /* Count reset */
-#define PMCR_C         (1 << 2)        /* Cycle counter reset */
-#define PMCR_D         (1 << 3)        /* Cycle counter counts every 64th cpu cycle */
-#define PMCR_IEN_PMN0  (1 << 4)        /* Interrupt enable count reg 0 */
-#define PMCR_IEN_PMN1  (1 << 5)        /* Interrupt enable count reg 1 */
-#define PMCR_IEN_CCNT  (1 << 6)        /* Interrupt enable cycle counter */
-#define PMCR_OFL_PMN0  (1 << 8)        /* Count reg 0 overflow */
-#define PMCR_OFL_PMN1  (1 << 9)        /* Count reg 1 overflow */
-#define PMCR_OFL_CCNT  (1 << 10)       /* Cycle counter overflow */
-
-#define PMN0 0
-#define PMN1 1
-#define CCNT 2
-
-#define CPU_COUNTER(cpu, counter)      ((cpu) * 3 + (counter))
-
-int arm11_setup_pmu(void);
-int arm11_start_pmu(void);
-int arm11_stop_pmu(void);
-int arm11_request_interrupts(const int *, int);
-void arm11_release_interrupts(const int *, int);
-
-#endif
diff --git a/arch/arm/oprofile/op_model_mpcore.c b/arch/arm/oprofile/op_model_mpcore.c
deleted file mode 100644 (file)
index f73ce87..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/**
- * @file op_model_mpcore.c
- * MPCORE Event Monitor Driver
- * @remark Copyright 2004 ARM SMP Development Team
- * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * @remark Copyright 2000-2004 MontaVista Software Inc
- * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * @remark Copyright 2004 Intel Corporation
- * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * @remark Copyright 2004 Oprofile Authors
- *
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- *
- *  Counters:
- *    0: PMN0 on CPU0, per-cpu configurable event counter
- *    1: PMN1 on CPU0, per-cpu configurable event counter
- *    2: CCNT on CPU0
- *    3: PMN0 on CPU1
- *    4: PMN1 on CPU1
- *    5: CCNT on CPU1
- *    6: PMN0 on CPU1
- *    7: PMN1 on CPU1
- *    8: CCNT on CPU1
- *    9: PMN0 on CPU1
- *   10: PMN1 on CPU1
- *   11: CCNT on CPU1
- *   12-19: configurable SCU event counters
- */
-
-/* #define DEBUG */
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/sched.h>
-#include <linux/oprofile.h>
-#include <linux/interrupt.h>
-#include <linux/smp.h>
-#include <linux/io.h>
-
-#include <asm/irq.h>
-#include <asm/mach/irq.h>
-#include <mach/hardware.h>
-#include <mach/board-eb.h>
-#include <asm/system.h>
-#include <asm/pmu.h>
-
-#include "op_counter.h"
-#include "op_arm_model.h"
-#include "op_model_arm11_core.h"
-#include "op_model_mpcore.h"
-
-/*
- * MPCore SCU event monitor support
- */
-#define SCU_EVENTMONITORS_VA_BASE __io_address(REALVIEW_EB11MP_SCU_BASE + 0x10)
-
-/*
- * Bitmask of used SCU counters
- */
-static unsigned int scu_em_used;
-static const struct pmu_irqs *pmu_irqs;
-
-/*
- * 2 helper fns take a counter number from 0-7 (not the userspace-visible counter number)
- */
-static inline void scu_reset_counter(struct eventmonitor __iomem *emc, unsigned int n)
-{
-       writel(-(u32)counter_config[SCU_COUNTER(n)].count, &emc->MC[n]);
-}
-
-static inline void scu_set_event(struct eventmonitor __iomem *emc, unsigned int n, u32 event)
-{
-       event &= 0xff;
-       writeb(event, &emc->MCEB[n]);
-}
-
-/*
- * SCU counters' IRQ handler (one IRQ per counter => 2 IRQs per CPU)
- */
-static irqreturn_t scu_em_interrupt(int irq, void *arg)
-{
-       struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
-       unsigned int cnt;
-
-       cnt = irq - IRQ_EB11MP_PMU_SCU0;
-       oprofile_add_sample(get_irq_regs(), SCU_COUNTER(cnt));
-       scu_reset_counter(emc, cnt);
-
-       /* Clear overflow flag for this counter */
-       writel(1 << (cnt + 16), &emc->PMCR);
-
-       return IRQ_HANDLED;
-}
-
-/* Configure just the SCU counters that the user has requested */
-static void scu_setup(void)
-{
-       struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
-       unsigned int i;
-
-       scu_em_used = 0;
-
-       for (i = 0; i < NUM_SCU_COUNTERS; i++) {
-               if (counter_config[SCU_COUNTER(i)].enabled &&
-                   counter_config[SCU_COUNTER(i)].event) {
-                       scu_set_event(emc, i, 0); /* disable counter for now */
-                       scu_em_used |= 1 << i;
-               }
-       }
-}
-
-static int scu_start(void)
-{
-       struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
-       unsigned int temp, i;
-       unsigned long event;
-       int ret = 0;
-
-       /*
-        * request the SCU counter interrupts that we need
-        */
-       for (i = 0; i < NUM_SCU_COUNTERS; i++) {
-               if (scu_em_used & (1 << i)) {
-                       ret = request_irq(IRQ_EB11MP_PMU_SCU0 + i, scu_em_interrupt, IRQF_DISABLED, "SCU PMU", NULL);
-                       if (ret) {
-                               printk(KERN_ERR "oprofile: unable to request IRQ%u for SCU Event Monitor\n",
-                                      IRQ_EB11MP_PMU_SCU0 + i);
-                               goto err_free_scu;
-                       }
-               }
-       }
-
-       /*
-        * clear overflow and enable interrupt for all used counters
-        */
-       temp = readl(&emc->PMCR);
-       for (i = 0; i < NUM_SCU_COUNTERS; i++) {
-               if (scu_em_used & (1 << i)) {
-                       scu_reset_counter(emc, i);
-                       event = counter_config[SCU_COUNTER(i)].event;
-                       scu_set_event(emc, i, event);
-
-                       /* clear overflow/interrupt */
-                       temp |= 1 << (i + 16);
-                       /* enable interrupt*/
-                       temp |= 1 << (i + 8);
-               }
-       }
-
-       /* Enable all 8 counters */
-       temp |= PMCR_E;
-       writel(temp, &emc->PMCR);
-
-       return 0;
-
- err_free_scu:
-       while (i--)
-               free_irq(IRQ_EB11MP_PMU_SCU0 + i, NULL);
-       return ret;
-}
-
-static void scu_stop(void)
-{
-       struct eventmonitor __iomem *emc = SCU_EVENTMONITORS_VA_BASE;
-       unsigned int temp, i;
-
-       /* Disable counter interrupts */
-       /* Don't disable all 8 counters (with the E bit) as they may be in use */
-       temp = readl(&emc->PMCR);
-       for (i = 0; i < NUM_SCU_COUNTERS; i++) {
-               if (scu_em_used & (1 << i))
-                       temp &= ~(1 << (i + 8));
-       }
-       writel(temp, &emc->PMCR);
-
-       /* Free counter interrupts and reset counters */
-       for (i = 0; i < NUM_SCU_COUNTERS; i++) {
-               if (scu_em_used & (1 << i)) {
-                       scu_reset_counter(emc, i);
-                       free_irq(IRQ_EB11MP_PMU_SCU0 + i, NULL);
-               }
-       }
-}
-
-struct em_function_data {
-       int (*fn)(void);
-       int ret;
-};
-
-static void em_func(void *data)
-{
-       struct em_function_data *d = data;
-       int ret = d->fn();
-       if (ret)
-               d->ret = ret;
-}
-
-static int em_call_function(int (*fn)(void))
-{
-       struct em_function_data data;
-
-       data.fn = fn;
-       data.ret = 0;
-
-       preempt_disable();
-       smp_call_function(em_func, &data, 1);
-       em_func(&data);
-       preempt_enable();
-
-       return data.ret;
-}
-
-/*
- * Glue to stick the individual ARM11 PMUs and the SCU
- * into the oprofile framework.
- */
-static int em_setup_ctrs(void)
-{
-       int ret;
-
-       /* Configure CPU counters by cross-calling to the other CPUs */
-       ret = em_call_function(arm11_setup_pmu);
-       if (ret == 0)
-               scu_setup();
-
-       return 0;
-}
-
-static int em_start(void)
-{
-       int ret;
-
-       pmu_irqs = reserve_pmu();
-       if (IS_ERR(pmu_irqs)) {
-               ret = PTR_ERR(pmu_irqs);
-               goto out;
-       }
-
-       ret = arm11_request_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       if (ret == 0) {
-               em_call_function(arm11_start_pmu);
-
-               ret = scu_start();
-               if (ret) {
-                       arm11_release_interrupts(pmu_irqs->irqs,
-                                                pmu_irqs->num_irqs);
-               } else {
-                       release_pmu(pmu_irqs);
-                       pmu_irqs = NULL;
-               }
-       }
-
-out:
-       return ret;
-}
-
-static void em_stop(void)
-{
-       em_call_function(arm11_stop_pmu);
-       arm11_release_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       scu_stop();
-       release_pmu(pmu_irqs);
-}
-
-/*
- * Why isn't there a function to route an IRQ to a specific CPU in
- * genirq?
- */
-static void em_route_irq(int irq, unsigned int cpu)
-{
-       struct irq_desc *desc = irq_desc + irq;
-       const struct cpumask *mask = cpumask_of(cpu);
-
-       spin_lock_irq(&desc->lock);
-       cpumask_copy(desc->affinity, mask);
-       desc->chip->set_affinity(irq, mask);
-       spin_unlock_irq(&desc->lock);
-}
-
-static int em_setup(void)
-{
-       /*
-        * Send SCU PMU interrupts to the "owner" CPU.
-        */
-       em_route_irq(IRQ_EB11MP_PMU_SCU0, 0);
-       em_route_irq(IRQ_EB11MP_PMU_SCU1, 0);
-       em_route_irq(IRQ_EB11MP_PMU_SCU2, 1);
-       em_route_irq(IRQ_EB11MP_PMU_SCU3, 1);
-       em_route_irq(IRQ_EB11MP_PMU_SCU4, 2);
-       em_route_irq(IRQ_EB11MP_PMU_SCU5, 2);
-       em_route_irq(IRQ_EB11MP_PMU_SCU6, 3);
-       em_route_irq(IRQ_EB11MP_PMU_SCU7, 3);
-
-       return init_pmu();
-}
-
-struct op_arm_model_spec op_mpcore_spec = {
-       .init           = em_setup,
-       .num_counters   = MPCORE_NUM_COUNTERS,
-       .setup_ctrs     = em_setup_ctrs,
-       .start          = em_start,
-       .stop           = em_stop,
-       .name           = "arm/mpcore",
-};
diff --git a/arch/arm/oprofile/op_model_mpcore.h b/arch/arm/oprofile/op_model_mpcore.h
deleted file mode 100644 (file)
index 73d8110..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/**
- * @file op_model_mpcore.c
- * MPCORE Event Monitor Driver
- * @remark Copyright 2004 ARM SMP Development Team
- * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * @remark Copyright 2000-2004 MontaVista Software Inc
- * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * @remark Copyright 2004 Intel Corporation
- * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * @remark Copyright 2004 Oprofile Authors
- *
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- */
-#ifndef OP_MODEL_MPCORE_H
-#define OP_MODEL_MPCORE_H
-
-struct eventmonitor {
-       unsigned long PMCR;
-       unsigned char MCEB[8];
-       unsigned long MC[8];
-};
-
-/*
- * List of userspace counter numbers: note that the structure is important.
- * The code relies on CPUn's counters being CPU0's counters + 3n
- * and on CPU0's counters starting at 0
- */
-
-#define COUNTER_CPU0_PMN0 0
-#define COUNTER_CPU0_PMN1 1
-#define COUNTER_CPU0_CCNT 2
-
-#define COUNTER_CPU1_PMN0 3
-#define COUNTER_CPU1_PMN1 4
-#define COUNTER_CPU1_CCNT 5
-
-#define COUNTER_CPU2_PMN0 6
-#define COUNTER_CPU2_PMN1 7
-#define COUNTER_CPU2_CCNT 8
-
-#define COUNTER_CPU3_PMN0 9
-#define COUNTER_CPU3_PMN1 10
-#define COUNTER_CPU3_CCNT 11
-
-#define COUNTER_SCU_MN0 12
-#define COUNTER_SCU_MN1 13
-#define COUNTER_SCU_MN2 14
-#define COUNTER_SCU_MN3 15
-#define COUNTER_SCU_MN4 16
-#define COUNTER_SCU_MN5 17
-#define COUNTER_SCU_MN6 18
-#define COUNTER_SCU_MN7 19
-#define NUM_SCU_COUNTERS 8
-
-#define SCU_COUNTER(number)    ((number) + COUNTER_SCU_MN0)
-
-#define MPCORE_NUM_COUNTERS    SCU_COUNTER(NUM_SCU_COUNTERS)
-
-#endif
diff --git a/arch/arm/oprofile/op_model_v6.c b/arch/arm/oprofile/op_model_v6.c
deleted file mode 100644 (file)
index a22357a..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-/**
- * @file op_model_v6.c
- * ARM11 Performance Monitor Driver
- *
- * Based on op_model_xscale.c
- *
- * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * @remark Copyright 2000-2004 MontaVista Software Inc
- * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * @remark Copyright 2004 Intel Corporation
- * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * @remark Copyright 2004 OProfile Authors
- *
- * @remark Read the file COPYING
- *
- * @author Tony Lindgren <tony@atomide.com>
- */
-
-/* #define DEBUG */
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/sched.h>
-#include <linux/oprofile.h>
-#include <linux/interrupt.h>
-#include <asm/irq.h>
-#include <asm/system.h>
-#include <asm/pmu.h>
-
-#include "op_counter.h"
-#include "op_arm_model.h"
-#include "op_model_arm11_core.h"
-
-static const struct pmu_irqs *pmu_irqs;
-
-static void armv6_pmu_stop(void)
-{
-       arm11_stop_pmu();
-       arm11_release_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       release_pmu(pmu_irqs);
-       pmu_irqs = NULL;
-}
-
-static int armv6_pmu_start(void)
-{
-       int ret;
-
-       pmu_irqs = reserve_pmu();
-       if (IS_ERR(pmu_irqs)) {
-               ret = PTR_ERR(pmu_irqs);
-               goto out;
-       }
-
-       ret = arm11_request_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       if (ret >= 0) {
-               ret = arm11_start_pmu();
-       } else {
-               release_pmu(pmu_irqs);
-               pmu_irqs = NULL;
-       }
-
-out:
-       return ret;
-}
-
-static int armv6_detect_pmu(void)
-{
-       return 0;
-}
-
-struct op_arm_model_spec op_armv6_spec = {
-       .init           = armv6_detect_pmu,
-       .num_counters   = 3,
-       .setup_ctrs     = arm11_setup_pmu,
-       .start          = armv6_pmu_start,
-       .stop           = armv6_pmu_stop,
-       .name           = "arm/armv6",
-};
diff --git a/arch/arm/oprofile/op_model_v7.c b/arch/arm/oprofile/op_model_v7.c
deleted file mode 100644 (file)
index 8642d08..0000000
+++ /dev/null
@@ -1,415 +0,0 @@
-/**
- * op_model_v7.c
- * ARM V7 (Cortex A8) Event Monitor Driver
- *
- * Copyright 2008 Jean Pihet <jpihet@mvista.com>
- * Copyright 2004 ARM SMP Development Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/oprofile.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-#include <linux/smp.h>
-
-#include <asm/pmu.h>
-
-#include "op_counter.h"
-#include "op_arm_model.h"
-#include "op_model_v7.h"
-
-/* #define DEBUG */
-
-
-/*
- * ARM V7 PMNC support
- */
-
-static u32 cnt_en[CNTMAX];
-
-static inline void armv7_pmnc_write(u32 val)
-{
-       val &= PMNC_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r" (val));
-}
-
-static inline u32 armv7_pmnc_read(void)
-{
-       u32 val;
-
-       asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (val));
-       return val;
-}
-
-static inline u32 armv7_pmnc_enable_counter(unsigned int cnt)
-{
-       u32 val;
-
-       if (cnt >= CNTMAX) {
-               printk(KERN_ERR "oprofile: CPU%u enabling wrong PMNC counter"
-                       " %d\n", smp_processor_id(), cnt);
-               return -1;
-       }
-
-       if (cnt == CCNT)
-               val = CNTENS_C;
-       else
-               val = (1 << (cnt - CNT0));
-
-       val &= CNTENS_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (val));
-
-       return cnt;
-}
-
-static inline u32 armv7_pmnc_disable_counter(unsigned int cnt)
-{
-       u32 val;
-
-       if (cnt >= CNTMAX) {
-               printk(KERN_ERR "oprofile: CPU%u disabling wrong PMNC counter"
-                       " %d\n", smp_processor_id(), cnt);
-               return -1;
-       }
-
-       if (cnt == CCNT)
-               val = CNTENC_C;
-       else
-               val = (1 << (cnt - CNT0));
-
-       val &= CNTENC_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c12, 2" : : "r" (val));
-
-       return cnt;
-}
-
-static inline u32 armv7_pmnc_enable_intens(unsigned int cnt)
-{
-       u32 val;
-
-       if (cnt >= CNTMAX) {
-               printk(KERN_ERR "oprofile: CPU%u enabling wrong PMNC counter"
-                       " interrupt enable %d\n", smp_processor_id(), cnt);
-               return -1;
-       }
-
-       if (cnt == CCNT)
-               val = INTENS_C;
-       else
-               val = (1 << (cnt - CNT0));
-
-       val &= INTENS_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c14, 1" : : "r" (val));
-
-       return cnt;
-}
-
-static inline u32 armv7_pmnc_getreset_flags(void)
-{
-       u32 val;
-
-       /* Read */
-       asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val));
-
-       /* Write to clear flags */
-       val &= FLAG_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c12, 3" : : "r" (val));
-
-       return val;
-}
-
-static inline int armv7_pmnc_select_counter(unsigned int cnt)
-{
-       u32 val;
-
-       if ((cnt == CCNT) || (cnt >= CNTMAX)) {
-               printk(KERN_ERR "oprofile: CPU%u selecting wrong PMNC counteri"
-                       " %d\n", smp_processor_id(), cnt);
-               return -1;
-       }
-
-       val = (cnt - CNT0) & SELECT_MASK;
-       asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (val));
-
-       return cnt;
-}
-
-static inline void armv7_pmnc_write_evtsel(unsigned int cnt, u32 val)
-{
-       if (armv7_pmnc_select_counter(cnt) == cnt) {
-               val &= EVTSEL_MASK;
-               asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (val));
-       }
-}
-
-static void armv7_pmnc_reset_counter(unsigned int cnt)
-{
-       u32 cpu_cnt = CPU_COUNTER(smp_processor_id(), cnt);
-       u32 val = -(u32)counter_config[cpu_cnt].count;
-
-       switch (cnt) {
-       case CCNT:
-               armv7_pmnc_disable_counter(cnt);
-
-               asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (val));
-
-               if (cnt_en[cnt] != 0)
-                   armv7_pmnc_enable_counter(cnt);
-
-               break;
-
-       case CNT0:
-       case CNT1:
-       case CNT2:
-       case CNT3:
-               armv7_pmnc_disable_counter(cnt);
-
-               if (armv7_pmnc_select_counter(cnt) == cnt)
-                   asm volatile("mcr p15, 0, %0, c9, c13, 2" : : "r" (val));
-
-               if (cnt_en[cnt] != 0)
-                   armv7_pmnc_enable_counter(cnt);
-
-               break;
-
-       default:
-               printk(KERN_ERR "oprofile: CPU%u resetting wrong PMNC counter"
-                       " %d\n", smp_processor_id(), cnt);
-               break;
-       }
-}
-
-int armv7_setup_pmnc(void)
-{
-       unsigned int cnt;
-
-       if (armv7_pmnc_read() & PMNC_E) {
-               printk(KERN_ERR "oprofile: CPU%u PMNC still enabled when setup"
-                       " new event counter.\n", smp_processor_id());
-               return -EBUSY;
-       }
-
-       /* Initialize & Reset PMNC: C bit and P bit */
-       armv7_pmnc_write(PMNC_P | PMNC_C);
-
-
-       for (cnt = CCNT; cnt < CNTMAX; cnt++) {
-               unsigned long event;
-               u32 cpu_cnt = CPU_COUNTER(smp_processor_id(), cnt);
-
-               /*
-                * Disable counter
-                */
-               armv7_pmnc_disable_counter(cnt);
-               cnt_en[cnt] = 0;
-
-               if (!counter_config[cpu_cnt].enabled)
-                       continue;
-
-               event = counter_config[cpu_cnt].event & 255;
-
-               /*
-                * Set event (if destined for PMNx counters)
-                * We don't need to set the event if it's a cycle count
-                */
-               if (cnt != CCNT)
-                       armv7_pmnc_write_evtsel(cnt, event);
-
-               /*
-                * Enable interrupt for this counter
-                */
-               armv7_pmnc_enable_intens(cnt);
-
-               /*
-                * Reset counter
-                */
-               armv7_pmnc_reset_counter(cnt);
-
-               /*
-                * Enable counter
-                */
-               armv7_pmnc_enable_counter(cnt);
-               cnt_en[cnt] = 1;
-       }
-
-       return 0;
-}
-
-static inline void armv7_start_pmnc(void)
-{
-       armv7_pmnc_write(armv7_pmnc_read() | PMNC_E);
-}
-
-static inline void armv7_stop_pmnc(void)
-{
-       armv7_pmnc_write(armv7_pmnc_read() & ~PMNC_E);
-}
-
-/*
- * CPU counters' IRQ handler (one IRQ per CPU)
- */
-static irqreturn_t armv7_pmnc_interrupt(int irq, void *arg)
-{
-       struct pt_regs *regs = get_irq_regs();
-       unsigned int cnt;
-       u32 flags;
-
-
-       /*
-        * Stop IRQ generation
-        */
-       armv7_stop_pmnc();
-
-       /*
-        * Get and reset overflow status flags
-        */
-       flags = armv7_pmnc_getreset_flags();
-
-       /*
-        * Cycle counter
-        */
-       if (flags & FLAG_C) {
-               u32 cpu_cnt = CPU_COUNTER(smp_processor_id(), CCNT);
-               armv7_pmnc_reset_counter(CCNT);
-               oprofile_add_sample(regs, cpu_cnt);
-       }
-
-       /*
-        * PMNC counters 0:3
-        */
-       for (cnt = CNT0; cnt < CNTMAX; cnt++) {
-               if (flags & (1 << (cnt - CNT0))) {
-                       u32 cpu_cnt = CPU_COUNTER(smp_processor_id(), cnt);
-                       armv7_pmnc_reset_counter(cnt);
-                       oprofile_add_sample(regs, cpu_cnt);
-               }
-       }
-
-       /*
-        * Allow IRQ generation
-        */
-       armv7_start_pmnc();
-
-       return IRQ_HANDLED;
-}
-
-int armv7_request_interrupts(const int *irqs, int nr)
-{
-       unsigned int i;
-       int ret = 0;
-
-       for (i = 0; i < nr; i++) {
-               ret = request_irq(irqs[i], armv7_pmnc_interrupt,
-                               IRQF_DISABLED, "CP15 PMNC", NULL);
-               if (ret != 0) {
-                       printk(KERN_ERR "oprofile: unable to request IRQ%u"
-                               " for ARMv7\n",
-                              irqs[i]);
-                       break;
-               }
-       }
-
-       if (i != nr)
-               while (i-- != 0)
-                       free_irq(irqs[i], NULL);
-
-       return ret;
-}
-
-void armv7_release_interrupts(const int *irqs, int nr)
-{
-       unsigned int i;
-
-       for (i = 0; i < nr; i++)
-               free_irq(irqs[i], NULL);
-}
-
-#ifdef DEBUG
-static void armv7_pmnc_dump_regs(void)
-{
-       u32 val;
-       unsigned int cnt;
-
-       printk(KERN_INFO "PMNC registers dump:\n");
-
-       asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (val));
-       printk(KERN_INFO "PMNC  =0x%08x\n", val);
-
-       asm volatile("mrc p15, 0, %0, c9, c12, 1" : "=r" (val));
-       printk(KERN_INFO "CNTENS=0x%08x\n", val);
-
-       asm volatile("mrc p15, 0, %0, c9, c14, 1" : "=r" (val));
-       printk(KERN_INFO "INTENS=0x%08x\n", val);
-
-       asm volatile("mrc p15, 0, %0, c9, c12, 3" : "=r" (val));
-       printk(KERN_INFO "FLAGS =0x%08x\n", val);
-
-       asm volatile("mrc p15, 0, %0, c9, c12, 5" : "=r" (val));
-       printk(KERN_INFO "SELECT=0x%08x\n", val);
-
-       asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (val));
-       printk(KERN_INFO "CCNT  =0x%08x\n", val);
-
-       for (cnt = CNT0; cnt < CNTMAX; cnt++) {
-               armv7_pmnc_select_counter(cnt);
-               asm volatile("mrc p15, 0, %0, c9, c13, 2" : "=r" (val));
-               printk(KERN_INFO "CNT[%d] count =0x%08x\n", cnt-CNT0, val);
-               asm volatile("mrc p15, 0, %0, c9, c13, 1" : "=r" (val));
-               printk(KERN_INFO "CNT[%d] evtsel=0x%08x\n", cnt-CNT0, val);
-       }
-}
-#endif
-
-static const struct pmu_irqs *pmu_irqs;
-
-static void armv7_pmnc_stop(void)
-{
-#ifdef DEBUG
-       armv7_pmnc_dump_regs();
-#endif
-       armv7_stop_pmnc();
-       armv7_release_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       release_pmu(pmu_irqs);
-       pmu_irqs = NULL;
-}
-
-static int armv7_pmnc_start(void)
-{
-       int ret;
-
-       pmu_irqs = reserve_pmu();
-       if (IS_ERR(pmu_irqs))
-               return PTR_ERR(pmu_irqs);
-
-#ifdef DEBUG
-       armv7_pmnc_dump_regs();
-#endif
-       ret = armv7_request_interrupts(pmu_irqs->irqs, pmu_irqs->num_irqs);
-       if (ret >= 0) {
-               armv7_start_pmnc();
-       } else {
-               release_pmu(pmu_irqs);
-               pmu_irqs = NULL;
-       }
-
-       return ret;
-}
-
-static int armv7_detect_pmnc(void)
-{
-       return 0;
-}
-
-struct op_arm_model_spec op_armv7_spec = {
-       .init           = armv7_detect_pmnc,
-       .num_counters   = 5,
-       .setup_ctrs     = armv7_setup_pmnc,
-       .start          = armv7_pmnc_start,
-       .stop           = armv7_pmnc_stop,
-       .name           = "arm/armv7",
-};
diff --git a/arch/arm/oprofile/op_model_v7.h b/arch/arm/oprofile/op_model_v7.h
deleted file mode 100644 (file)
index 9ca334b..0000000
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * op_model_v7.h
- * ARM v7 (Cortex A8) Event Monitor Driver
- *
- * Copyright 2008 Jean Pihet <jpihet@mvista.com>
- * Copyright 2004 ARM SMP Development Team
- * Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * Copyright 2000-2004 MontaVista Software Inc
- * Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * Copyright 2004 Intel Corporation
- * Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * Copyright 2004 Oprofile Authors
- *
- * Read the file COPYING
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#ifndef OP_MODEL_V7_H
-#define OP_MODEL_V7_H
-
-/*
- * Per-CPU PMNC: config reg
- */
-#define PMNC_E         (1 << 0)        /* Enable all counters */
-#define PMNC_P         (1 << 1)        /* Reset all counters */
-#define PMNC_C         (1 << 2)        /* Cycle counter reset */
-#define PMNC_D         (1 << 3)        /* CCNT counts every 64th cpu cycle */
-#define PMNC_X         (1 << 4)        /* Export to ETM */
-#define PMNC_DP                (1 << 5)        /* Disable CCNT if non-invasive debug*/
-#define        PMNC_MASK       0x3f            /* Mask for writable bits */
-
-/*
- * Available counters
- */
-#define CCNT           0
-#define CNT0           1
-#define CNT1           2
-#define CNT2           3
-#define CNT3           4
-#define CNTMAX                 5
-
-#define CPU_COUNTER(cpu, counter)      ((cpu) * CNTMAX + (counter))
-
-/*
- * CNTENS: counters enable reg
- */
-#define CNTENS_P0      (1 << 0)
-#define CNTENS_P1      (1 << 1)
-#define CNTENS_P2      (1 << 2)
-#define CNTENS_P3      (1 << 3)
-#define CNTENS_C       (1 << 31)
-#define        CNTENS_MASK     0x8000000f      /* Mask for writable bits */
-
-/*
- * CNTENC: counters disable reg
- */
-#define CNTENC_P0      (1 << 0)
-#define CNTENC_P1      (1 << 1)
-#define CNTENC_P2      (1 << 2)
-#define CNTENC_P3      (1 << 3)
-#define CNTENC_C       (1 << 31)
-#define        CNTENC_MASK     0x8000000f      /* Mask for writable bits */
-
-/*
- * INTENS: counters overflow interrupt enable reg
- */
-#define INTENS_P0      (1 << 0)
-#define INTENS_P1      (1 << 1)
-#define INTENS_P2      (1 << 2)
-#define INTENS_P3      (1 << 3)
-#define INTENS_C       (1 << 31)
-#define        INTENS_MASK     0x8000000f      /* Mask for writable bits */
-
-/*
- * EVTSEL: Event selection reg
- */
-#define        EVTSEL_MASK     0x7f            /* Mask for writable bits */
-
-/*
- * SELECT: Counter selection reg
- */
-#define        SELECT_MASK     0x1f            /* Mask for writable bits */
-
-/*
- * FLAG: counters overflow flag status reg
- */
-#define FLAG_P0                (1 << 0)
-#define FLAG_P1                (1 << 1)
-#define FLAG_P2                (1 << 2)
-#define FLAG_P3                (1 << 3)
-#define FLAG_C         (1 << 31)
-#define        FLAG_MASK       0x8000000f      /* Mask for writable bits */
-
-
-int armv7_setup_pmu(void);
-int armv7_start_pmu(void);
-int armv7_stop_pmu(void);
-int armv7_request_interrupts(const int *, int);
-void armv7_release_interrupts(const int *, int);
-
-#endif
diff --git a/arch/arm/oprofile/op_model_xscale.c b/arch/arm/oprofile/op_model_xscale.c
deleted file mode 100644 (file)
index 1d34a02..0000000
+++ /dev/null
@@ -1,444 +0,0 @@
-/**
- * @file op_model_xscale.c
- * XScale Performance Monitor Driver
- *
- * @remark Copyright 2000-2004 Deepak Saxena <dsaxena@mvista.com>
- * @remark Copyright 2000-2004 MontaVista Software Inc
- * @remark Copyright 2004 Dave Jiang <dave.jiang@intel.com>
- * @remark Copyright 2004 Intel Corporation
- * @remark Copyright 2004 Zwane Mwaikambo <zwane@arm.linux.org.uk>
- * @remark Copyright 2004 OProfile Authors
- *
- * @remark Read the file COPYING
- *
- * @author Zwane Mwaikambo
- */
-
-/* #define DEBUG */
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/sched.h>
-#include <linux/oprofile.h>
-#include <linux/interrupt.h>
-#include <linux/irq.h>
-
-#include <asm/cputype.h>
-#include <asm/pmu.h>
-
-#include "op_counter.h"
-#include "op_arm_model.h"
-
-#define        PMU_ENABLE      0x001   /* Enable counters */
-#define PMN_RESET      0x002   /* Reset event counters */
-#define        CCNT_RESET      0x004   /* Reset clock counter */
-#define        PMU_RESET       (CCNT_RESET | PMN_RESET)
-#define PMU_CNT64      0x008   /* Make CCNT count every 64th cycle */
-
-/*
- * Different types of events that can be counted by the XScale PMU
- * as used by Oprofile userspace. Here primarily for documentation
- * purposes.
- */
-
-#define EVT_ICACHE_MISS                        0x00
-#define        EVT_ICACHE_NO_DELIVER           0x01
-#define        EVT_DATA_STALL                  0x02
-#define        EVT_ITLB_MISS                   0x03
-#define        EVT_DTLB_MISS                   0x04
-#define        EVT_BRANCH                      0x05
-#define        EVT_BRANCH_MISS                 0x06
-#define        EVT_INSTRUCTION                 0x07
-#define        EVT_DCACHE_FULL_STALL           0x08
-#define        EVT_DCACHE_FULL_STALL_CONTIG    0x09
-#define        EVT_DCACHE_ACCESS               0x0A
-#define        EVT_DCACHE_MISS                 0x0B
-#define        EVT_DCACE_WRITE_BACK            0x0C
-#define        EVT_PC_CHANGED                  0x0D
-#define        EVT_BCU_REQUEST                 0x10
-#define        EVT_BCU_FULL                    0x11
-#define        EVT_BCU_DRAIN                   0x12
-#define        EVT_BCU_ECC_NO_ELOG             0x14
-#define        EVT_BCU_1_BIT_ERR               0x15
-#define        EVT_RMW                         0x16
-/* EVT_CCNT is not hardware defined */
-#define EVT_CCNT                       0xFE
-#define EVT_UNUSED                     0xFF
-
-struct pmu_counter {
-       volatile unsigned long ovf;
-       unsigned long reset_counter;
-};
-
-enum { CCNT, PMN0, PMN1, PMN2, PMN3, MAX_COUNTERS };
-
-static struct pmu_counter results[MAX_COUNTERS];
-
-/*
- * There are two versions of the PMU in current XScale processors
- * with differing register layouts and number of performance counters.
- * e.g. IOP32x is xsc1 whilst IOP33x is xsc2.
- * We detect which register layout to use in xscale_detect_pmu()
- */
-enum { PMU_XSC1, PMU_XSC2 };
-
-struct pmu_type {
-       int id;
-       char *name;
-       int num_counters;
-       unsigned int int_enable;
-       unsigned int cnt_ovf[MAX_COUNTERS];
-       unsigned int int_mask[MAX_COUNTERS];
-};
-
-static struct pmu_type pmu_parms[] = {
-       {
-               .id             = PMU_XSC1,
-               .name           = "arm/xscale1",
-               .num_counters   = 3,
-               .int_mask       = { [PMN0] = 0x10, [PMN1] = 0x20,
-                                   [CCNT] = 0x40 },
-               .cnt_ovf        = { [CCNT] = 0x400, [PMN0] = 0x100,
-                                   [PMN1] = 0x200},
-       },
-       {
-               .id             = PMU_XSC2,
-               .name           = "arm/xscale2",
-               .num_counters   = 5,
-               .int_mask       = { [CCNT] = 0x01, [PMN0] = 0x02,
-                                   [PMN1] = 0x04, [PMN2] = 0x08,
-                                   [PMN3] = 0x10 },
-               .cnt_ovf        = { [CCNT] = 0x01, [PMN0] = 0x02,
-                                   [PMN1] = 0x04, [PMN2] = 0x08,
-                                   [PMN3] = 0x10 },
-       },
-};
-
-static struct pmu_type *pmu;
-
-static void write_pmnc(u32 val)
-{
-       if (pmu->id == PMU_XSC1) {
-               /* upper 4bits and 7, 11 are write-as-0 */
-               val &= 0xffff77f;
-               __asm__ __volatile__ ("mcr p14, 0, %0, c0, c0, 0" : : "r" (val));
-       } else {
-               /* bits 4-23 are write-as-0, 24-31 are write ignored */
-               val &= 0xf;
-               __asm__ __volatile__ ("mcr p14, 0, %0, c0, c1, 0" : : "r" (val));
-       }
-}
-
-static u32 read_pmnc(void)
-{
-       u32 val;
-
-       if (pmu->id == PMU_XSC1)
-               __asm__ __volatile__ ("mrc p14, 0, %0, c0, c0, 0" : "=r" (val));
-       else {
-               __asm__ __volatile__ ("mrc p14, 0, %0, c0, c1, 0" : "=r" (val));
-               /* bits 1-2 and 4-23 are read-unpredictable */
-               val &= 0xff000009;
-       }
-
-       return val;
-}
-
-static u32 __xsc1_read_counter(int counter)
-{
-       u32 val = 0;
-
-       switch (counter) {
-       case CCNT:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c1, c0, 0" : "=r" (val));
-               break;
-       case PMN0:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c2, c0, 0" : "=r" (val));
-               break;
-       case PMN1:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c3, c0, 0" : "=r" (val));
-               break;
-       }
-       return val;
-}
-
-static u32 __xsc2_read_counter(int counter)
-{
-       u32 val = 0;
-
-       switch (counter) {
-       case CCNT:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c1, c1, 0" : "=r" (val));
-               break;
-       case PMN0:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c0, c2, 0" : "=r" (val));
-               break;
-       case PMN1:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c1, c2, 0" : "=r" (val));
-               break;
-       case PMN2:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c2, c2, 0" : "=r" (val));
-               break;
-       case PMN3:
-               __asm__ __volatile__ ("mrc p14, 0, %0, c3, c2, 0" : "=r" (val));
-               break;
-       }
-       return val;
-}
-
-static u32 read_counter(int counter)
-{
-       u32 val;
-
-       if (pmu->id == PMU_XSC1)
-               val = __xsc1_read_counter(counter);
-       else
-               val = __xsc2_read_counter(counter);
-
-       return val;
-}
-
-static void __xsc1_write_counter(int counter, u32 val)
-{
-       switch (counter) {
-       case CCNT:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c1, c0, 0" : : "r" (val));
-               break;
-       case PMN0:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c2, c0, 0" : : "r" (val));
-               break;
-       case PMN1:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c3, c0, 0" : : "r" (val));
-               break;
-       }
-}
-
-static void __xsc2_write_counter(int counter, u32 val)
-{
-       switch (counter) {
-       case CCNT:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c1, c1, 0" : : "r" (val));
-               break;
-       case PMN0:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c0, c2, 0" : : "r" (val));
-               break;
-       case PMN1:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c1, c2, 0" : : "r" (val));
-               break;
-       case PMN2:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c2, c2, 0" : : "r" (val));
-               break;
-       case PMN3:
-               __asm__ __volatile__ ("mcr p14, 0, %0, c3, c2, 0" : : "r" (val));
-               break;
-       }
-}
-
-static void write_counter(int counter, u32 val)
-{
-       if (pmu->id == PMU_XSC1)
-               __xsc1_write_counter(counter, val);
-       else
-               __xsc2_write_counter(counter, val);
-}
-
-static int xscale_setup_ctrs(void)
-{
-       u32 evtsel, pmnc;
-       int i;
-
-       for (i = CCNT; i < MAX_COUNTERS; i++) {
-               if (counter_config[i].enabled)
-                       continue;
-
-               counter_config[i].event = EVT_UNUSED;
-       }
-
-       switch (pmu->id) {
-       case PMU_XSC1:
-               pmnc = (counter_config[PMN1].event << 20) | (counter_config[PMN0].event << 12);
-               pr_debug("xscale_setup_ctrs: pmnc: %#08x\n", pmnc);
-               write_pmnc(pmnc);
-               break;
-
-       case PMU_XSC2:
-               evtsel = counter_config[PMN0].event | (counter_config[PMN1].event << 8) |
-                       (counter_config[PMN2].event << 16) | (counter_config[PMN3].event << 24);
-
-               pr_debug("xscale_setup_ctrs: evtsel %#08x\n", evtsel);
-               __asm__ __volatile__ ("mcr p14, 0, %0, c8, c1, 0" : : "r" (evtsel));
-               break;
-       }
-
-       for (i = CCNT; i < MAX_COUNTERS; i++) {
-               if (counter_config[i].event == EVT_UNUSED) {
-                       counter_config[i].event = 0;
-                       pmu->int_enable &= ~pmu->int_mask[i];
-                       continue;
-               }
-
-               results[i].reset_counter = counter_config[i].count;
-               write_counter(i, -(u32)counter_config[i].count);
-               pmu->int_enable |= pmu->int_mask[i];
-               pr_debug("xscale_setup_ctrs: counter%d %#08x from %#08lx\n", i,
-                       read_counter(i), counter_config[i].count);
-       }
-
-       return 0;
-}
-
-static void inline __xsc1_check_ctrs(void)
-{
-       int i;
-       u32 pmnc = read_pmnc();
-
-       /* NOTE: there's an A stepping errata that states if an overflow */
-       /*       bit already exists and another occurs, the previous     */
-       /*       Overflow bit gets cleared. There's no workaround.       */
-       /*       Fixed in B stepping or later                            */
-
-       /* Write the value back to clear the overflow flags. Overflow */
-       /* flags remain in pmnc for use below */
-       write_pmnc(pmnc & ~PMU_ENABLE);
-
-       for (i = CCNT; i <= PMN1; i++) {
-               if (!(pmu->int_mask[i] & pmu->int_enable))
-                       continue;
-
-               if (pmnc & pmu->cnt_ovf[i])
-                       results[i].ovf++;
-       }
-}
-
-static void inline __xsc2_check_ctrs(void)
-{
-       int i;
-       u32 flag = 0, pmnc = read_pmnc();
-
-       pmnc &= ~PMU_ENABLE;
-       write_pmnc(pmnc);
-
-       /* read overflow flag register */
-       __asm__ __volatile__ ("mrc p14, 0, %0, c5, c1, 0" : "=r" (flag));
-
-       for (i = CCNT; i <= PMN3; i++) {
-               if (!(pmu->int_mask[i] & pmu->int_enable))
-                       continue;
-
-               if (flag & pmu->cnt_ovf[i])
-                       results[i].ovf++;
-       }
-
-       /* writeback clears overflow bits */
-       __asm__ __volatile__ ("mcr p14, 0, %0, c5, c1, 0" : : "r" (flag));
-}
-
-static irqreturn_t xscale_pmu_interrupt(int irq, void *arg)
-{
-       int i;
-       u32 pmnc;
-
-       if (pmu->id == PMU_XSC1)
-               __xsc1_check_ctrs();
-       else
-               __xsc2_check_ctrs();
-
-       for (i = CCNT; i < MAX_COUNTERS; i++) {
-               if (!results[i].ovf)
-                       continue;
-
-               write_counter(i, -(u32)results[i].reset_counter);
-               oprofile_add_sample(get_irq_regs(), i);
-               results[i].ovf--;
-       }
-
-       pmnc = read_pmnc() | PMU_ENABLE;
-       write_pmnc(pmnc);
-
-       return IRQ_HANDLED;
-}
-
-static const struct pmu_irqs *pmu_irqs;
-
-static void xscale_pmu_stop(void)
-{
-       u32 pmnc = read_pmnc();
-
-       pmnc &= ~PMU_ENABLE;
-       write_pmnc(pmnc);
-
-       free_irq(pmu_irqs->irqs[0], results);
-       release_pmu(pmu_irqs);
-       pmu_irqs = NULL;
-}
-
-static int xscale_pmu_start(void)
-{
-       int ret;
-       u32 pmnc;
-
-       pmu_irqs = reserve_pmu();
-       if (IS_ERR(pmu_irqs))
-               return PTR_ERR(pmu_irqs);
-
-       pmnc = read_pmnc();
-
-       ret = request_irq(pmu_irqs->irqs[0], xscale_pmu_interrupt,
-                         IRQF_DISABLED, "XScale PMU", (void *)results);
-
-       if (ret < 0) {
-               printk(KERN_ERR "oprofile: unable to request IRQ%d for XScale PMU\n",
-                      pmu_irqs->irqs[0]);
-               release_pmu(pmu_irqs);
-               pmu_irqs = NULL;
-               return ret;
-       }
-
-       if (pmu->id == PMU_XSC1)
-               pmnc |= pmu->int_enable;
-       else {
-               __asm__ __volatile__ ("mcr p14, 0, %0, c4, c1, 0" : : "r" (pmu->int_enable));
-               pmnc &= ~PMU_CNT64;
-       }
-
-       pmnc |= PMU_ENABLE;
-       write_pmnc(pmnc);
-       pr_debug("xscale_pmu_start: pmnc: %#08x mask: %08x\n", pmnc, pmu->int_enable);
-       return 0;
-}
-
-static int xscale_detect_pmu(void)
-{
-       int ret = 0;
-       u32 id;
-
-       id = (read_cpuid(CPUID_ID) >> 13) & 0x7;
-
-       switch (id) {
-       case 1:
-               pmu = &pmu_parms[PMU_XSC1];
-               break;
-       case 2:
-               pmu = &pmu_parms[PMU_XSC2];
-               break;
-       default:
-               ret = -ENODEV;
-               break;
-       }
-
-       if (!ret) {
-               op_xscale_spec.name = pmu->name;
-               op_xscale_spec.num_counters = pmu->num_counters;
-               pr_debug("xscale_detect_pmu: detected %s PMU\n", pmu->name);
-       }
-
-       return ret;
-}
-
-struct op_arm_model_spec op_xscale_spec = {
-       .init           = xscale_detect_pmu,
-       .setup_ctrs     = xscale_setup_ctrs,
-       .start          = xscale_pmu_start,
-       .stop           = xscale_pmu_stop,
-};
-
index 36bff03..69b09c1 100644 (file)
@@ -13,6 +13,7 @@ obj-$(CONFIG_ARCH_IOP32X) += time.o
 obj-$(CONFIG_ARCH_IOP32X) += io.o
 obj-$(CONFIG_ARCH_IOP32X) += cp6.o
 obj-$(CONFIG_ARCH_IOP32X) += adma.o
+obj-$(CONFIG_ARCH_IOP32X) += pmu.o
 
 # IOP33X
 obj-$(CONFIG_ARCH_IOP33X) += gpio.o
@@ -23,6 +24,7 @@ obj-$(CONFIG_ARCH_IOP33X) += time.o
 obj-$(CONFIG_ARCH_IOP33X) += io.o
 obj-$(CONFIG_ARCH_IOP33X) += cp6.o
 obj-$(CONFIG_ARCH_IOP33X) += adma.o
+obj-$(CONFIG_ARCH_IOP33X) += pmu.o
 
 # IOP13XX
 obj-$(CONFIG_ARCH_IOP13XX) += cp6.o
diff --git a/arch/arm/plat-iop/pmu.c b/arch/arm/plat-iop/pmu.c
new file mode 100644 (file)
index 0000000..a2024b8
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * PMU IRQ registration for the iop3xx xscale PMU families.
+ * Copyright (C) 2010 Will Deacon, ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <asm/pmu.h>
+#include <mach/irqs.h>
+
+static struct resource pmu_resource = {
+#ifdef CONFIG_ARCH_IOP32X
+       .start  = IRQ_IOP32X_CORE_PMU,
+       .end    = IRQ_IOP32X_CORE_PMU,
+#endif
+#ifdef CONFIG_ARCH_IOP33X
+       .start  = IRQ_IOP33X_CORE_PMU,
+       .end    = IRQ_IOP33X_CORE_PMU,
+#endif
+       .flags  = IORESOURCE_IRQ,
+};
+
+static struct platform_device pmu_device = {
+       .name           = "arm-pmu",
+       .id             = ARM_PMU_DEVICE_CPU,
+       .resource       = &pmu_resource,
+       .num_resources  = 1,
+};
+
+static int __init iop3xx_pmu_init(void)
+{
+       platform_device_register(&pmu_device);
+       return 0;
+}
+
+arch_initcall(iop3xx_pmu_init);
index 159daf5..5da3f97 100644 (file)
@@ -19,4 +19,9 @@ config HAS_MTU
          to multiple interrupt generating programmable
          32-bit free running decrementing counters.
 
+config NOMADIK_GPIO
+       bool
+       help
+         Support for the Nomadik GPIO controller.
+
 endif
index 37c7cdd..c335473 100644 (file)
@@ -3,3 +3,4 @@
 # Licensed under GPLv2
 
 obj-$(CONFIG_HAS_MTU)  += timer.o
+obj-$(CONFIG_NOMADIK_GPIO)     += gpio.o
similarity index 74%
rename from arch/arm/mach-nomadik/gpio.c
rename to arch/arm/plat-nomadik/gpio.c
index 66b1c91..5a6ef25 100644 (file)
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/device.h>
-#include <linux/amba/bus.h>
+#include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/clk.h>
+#include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
@@ -36,8 +38,9 @@
 struct nmk_gpio_chip {
        struct gpio_chip chip;
        void __iomem *addr;
+       struct clk *clk;
        unsigned int parent_irq;
-       spinlock_t *lock;
+       spinlock_t lock;
        /* Keep track of configured edges */
        u32 edge_rising;
        u32 edge_falling;
@@ -108,40 +111,37 @@ static void nmk_gpio_irq_ack(unsigned int irq)
        writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
 }
 
-static void nmk_gpio_irq_mask(unsigned int irq)
+static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
+                                 int gpio, bool enable)
 {
-       int gpio;
-       struct nmk_gpio_chip *nmk_chip;
-       unsigned long flags;
-       u32 bitmask, reg;
-
-       gpio = NOMADIK_IRQ_TO_GPIO(irq);
-       nmk_chip = get_irq_chip_data(irq);
-       bitmask = nmk_gpio_get_bitmask(gpio);
-       if (!nmk_chip)
-               return;
+       u32 bitmask = nmk_gpio_get_bitmask(gpio);
+       u32 reg;
 
-       /* we must individually clear the two edges */
-       spin_lock_irqsave(&nmk_chip->lock, flags);
+       /* we must individually set/clear the two edges */
        if (nmk_chip->edge_rising & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_RWIMSC);
-               reg &= ~bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_RWIMSC);
+               reg = readl(nmk_chip->addr + NMK_GPIO_RIMSC);
+               if (enable)
+                       reg |= bitmask;
+               else
+                       reg &= ~bitmask;
+               writel(reg, nmk_chip->addr + NMK_GPIO_RIMSC);
        }
        if (nmk_chip->edge_falling & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_FWIMSC);
-               reg &= ~bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_FWIMSC);
+               reg = readl(nmk_chip->addr + NMK_GPIO_FIMSC);
+               if (enable)
+                       reg |= bitmask;
+               else
+                       reg &= ~bitmask;
+               writel(reg, nmk_chip->addr + NMK_GPIO_FIMSC);
        }
-       spin_unlock_irqrestore(&nmk_chip->lock, flags);
-};
+}
 
-static void nmk_gpio_irq_unmask(unsigned int irq)
+static void nmk_gpio_irq_modify(unsigned int irq, bool enable)
 {
        int gpio;
        struct nmk_gpio_chip *nmk_chip;
        unsigned long flags;
-       u32 bitmask, reg;
+       u32 bitmask;
 
        gpio = NOMADIK_IRQ_TO_GPIO(irq);
        nmk_chip = get_irq_chip_data(irq);
@@ -149,23 +149,24 @@ static void nmk_gpio_irq_unmask(unsigned int irq)
        if (!nmk_chip)
                return;
 
-       /* we must individually set the two edges */
        spin_lock_irqsave(&nmk_chip->lock, flags);
-       if (nmk_chip->edge_rising & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_RWIMSC);
-               reg |= bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_RWIMSC);
-       }
-       if (nmk_chip->edge_falling & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_FWIMSC);
-               reg |= bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_FWIMSC);
-       }
+       __nmk_gpio_irq_modify(nmk_chip, gpio, enable);
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
 }
 
+static void nmk_gpio_irq_mask(unsigned int irq)
+{
+       nmk_gpio_irq_modify(irq, false);
+};
+
+static void nmk_gpio_irq_unmask(unsigned int irq)
+{
+       nmk_gpio_irq_modify(irq, true);
+}
+
 static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
 {
+       bool enabled = !(irq_to_desc(irq)->status & IRQ_DISABLED);
        int gpio;
        struct nmk_gpio_chip *nmk_chip;
        unsigned long flags;
@@ -184,19 +185,21 @@ static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
 
        spin_lock_irqsave(&nmk_chip->lock, flags);
 
+       if (enabled)
+               __nmk_gpio_irq_modify(nmk_chip, gpio, false);
+
        nmk_chip->edge_rising &= ~bitmask;
        if (type & IRQ_TYPE_EDGE_RISING)
                nmk_chip->edge_rising |= bitmask;
-       writel(nmk_chip->edge_rising, nmk_chip->addr + NMK_GPIO_RIMSC);
 
        nmk_chip->edge_falling &= ~bitmask;
        if (type & IRQ_TYPE_EDGE_FALLING)
                nmk_chip->edge_falling |= bitmask;
-       writel(nmk_chip->edge_falling, nmk_chip->addr + NMK_GPIO_FIMSC);
 
-       spin_unlock_irqrestore(&nmk_chip->lock, flags);
+       if (enabled)
+               __nmk_gpio_irq_modify(nmk_chip, gpio, true);
 
-       nmk_gpio_irq_unmask(irq);
+       spin_unlock_irqrestore(&nmk_chip->lock, flags);
 
        return 0;
 }
@@ -212,21 +215,27 @@ static struct irq_chip nmk_gpio_irq_chip = {
 static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
 {
        struct nmk_gpio_chip *nmk_chip;
-       struct irq_chip *host_chip;
+       struct irq_chip *host_chip = get_irq_chip(irq);
        unsigned int gpio_irq;
        u32 pending;
        unsigned int first_irq;
 
+       if (host_chip->mask_ack)
+               host_chip->mask_ack(irq);
+       else {
+               host_chip->mask(irq);
+               if (host_chip->ack)
+                       host_chip->ack(irq);
+       }
+
        nmk_chip = get_irq_data(irq);
        first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
        while ( (pending = readl(nmk_chip->addr + NMK_GPIO_IS)) ) {
                gpio_irq = first_irq + __ffs(pending);
                generic_handle_irq(gpio_irq);
        }
-       if (0) {/* don't ack parent irq, as ack == disable */
-               host_chip = get_irq_chip(irq);
-               host_chip->ack(irq);
-       }
+
+       host_chip->unmask(irq);
 }
 
 static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
@@ -240,6 +249,7 @@ static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
                set_irq_handler(i, handle_edge_irq);
                set_irq_flags(i, IRQF_VALID);
                set_irq_chip_data(i, nmk_chip);
+               set_irq_type(i, IRQ_TYPE_EDGE_FALLING);
        }
        set_irq_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
        set_irq_data(nmk_chip->parent_irq, nmk_chip);
@@ -298,30 +308,59 @@ static struct gpio_chip nmk_gpio_template = {
        .can_sleep              = 0,
 };
 
-static int __init nmk_gpio_probe(struct amba_device *dev, struct amba_id *id)
+static int __init nmk_gpio_probe(struct platform_device *dev)
 {
-       struct nmk_gpio_platform_data *pdata;
+       struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
        struct nmk_gpio_chip *nmk_chip;
        struct gpio_chip *chip;
+       struct resource *res;
+       struct clk *clk;
+       int irq;
        int ret;
 
-       pdata = dev->dev.platform_data;
-       ret = amba_request_regions(dev, pdata->name);
-       if (ret)
-               return ret;
+       if (!pdata)
+               return -ENODEV;
+
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (!res) {
+               ret = -ENOENT;
+               goto out;
+       }
+
+       irq = platform_get_irq(dev, 0);
+       if (irq < 0) {
+               ret = irq;
+               goto out;
+       }
+
+       if (request_mem_region(res->start, resource_size(res),
+                              dev_name(&dev->dev)) == NULL) {
+               ret = -EBUSY;
+               goto out;
+       }
+
+       clk = clk_get(&dev->dev, NULL);
+       if (IS_ERR(clk)) {
+               ret = PTR_ERR(clk);
+               goto out_release;
+       }
+
+       clk_enable(clk);
 
        nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
        if (!nmk_chip) {
                ret = -ENOMEM;
-               goto out_amba;
+               goto out_clk;
        }
        /*
         * The virt address in nmk_chip->addr is in the nomadik register space,
         * so we can simply convert the resource address, without remapping
         */
-       nmk_chip->addr = io_p2v(dev->res.start);
+       nmk_chip->clk = clk;
+       nmk_chip->addr = io_p2v(res->start);
        nmk_chip->chip = nmk_gpio_template;
-       nmk_chip->parent_irq = pdata->parent_irq;
+       nmk_chip->parent_irq = irq;
+       spin_lock_init(&nmk_chip->lock);
 
        chip = &nmk_chip->chip;
        chip->base = pdata->first_gpio;
@@ -333,7 +372,7 @@ static int __init nmk_gpio_probe(struct amba_device *dev, struct amba_id *id)
        if (ret)
                goto out_free;
 
-       amba_set_drvdata(dev, nmk_chip);
+       platform_set_drvdata(dev, nmk_chip);
 
        nmk_gpio_init_irq(nmk_chip);
 
@@ -341,51 +380,50 @@ static int __init nmk_gpio_probe(struct amba_device *dev, struct amba_id *id)
                 nmk_chip->chip.base, nmk_chip->chip.base+31, nmk_chip->addr);
        return 0;
 
- out_free:
+out_free:
        kfree(nmk_chip);
- out_amba:
-       amba_release_regions(dev);
+out_clk:
+       clk_disable(clk);
+       clk_put(clk);
+out_release:
+       release_mem_region(res->start, resource_size(res));
+out:
        dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
                  pdata->first_gpio, pdata->first_gpio+31);
        return ret;
 }
 
-static int nmk_gpio_remove(struct amba_device *dev)
+static int __exit nmk_gpio_remove(struct platform_device *dev)
 {
        struct nmk_gpio_chip *nmk_chip;
+       struct resource *res;
 
-       nmk_chip = amba_get_drvdata(dev);
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+
+       nmk_chip = platform_get_drvdata(dev);
        gpiochip_remove(&nmk_chip->chip);
+       clk_disable(nmk_chip->clk);
+       clk_put(nmk_chip->clk);
        kfree(nmk_chip);
-       amba_release_regions(dev);
+       release_mem_region(res->start, resource_size(res));
        return 0;
 }
 
 
-/* We have 0x1f080060 and 0x1f180060, accept both using the mask */
-static struct amba_id nmk_gpio_ids[] = {
-       {
-               .id     = 0x1f080060,
-               .mask   = 0xffefffff,
-       },
-       {0, 0},
-};
-
-static struct amba_driver nmk_gpio_driver = {
-       .drv = {
+static struct platform_driver nmk_gpio_driver = {
+       .driver = {
                .owner = THIS_MODULE,
                .name = "gpio",
                },
        .probe = nmk_gpio_probe,
-       .remove = nmk_gpio_remove,
+       .remove = __exit_p(nmk_gpio_remove),
        .suspend = NULL, /* to be done */
        .resume = NULL,
-       .id_table = nmk_gpio_ids,
 };
 
 static int __init nmk_gpio_init(void)
 {
-       return amba_driver_register(&nmk_gpio_driver);
+       return platform_driver_register(&nmk_gpio_driver);
 }
 
 arch_initcall(nmk_gpio_init);
diff --git a/arch/arm/plat-nomadik/include/plat/gpio.h b/arch/arm/plat-nomadik/include/plat/gpio.h
new file mode 100644 (file)
index 0000000..4200811
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Structures and registers for GPIO access in the Nomadik SoC
+ *
+ * Copyright (C) 2008 STMicroelectronics
+ *     Author: Prafulla WADASKAR <prafulla.wadaskar@st.com>
+ * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __ASM_PLAT_GPIO_H
+#define __ASM_PLAT_GPIO_H
+
+#include <asm-generic/gpio.h>
+
+/*
+ * These currently cause a function call to happen, they may be optimized
+ * if needed by adding cpu-specific defines to identify blocks
+ * (see mach-pxa/include/mach/gpio.h as an example using GPLR etc)
+ */
+#define gpio_get_value  __gpio_get_value
+#define gpio_set_value  __gpio_set_value
+#define gpio_cansleep   __gpio_cansleep
+#define gpio_to_irq     __gpio_to_irq
+
+/*
+ * "nmk_gpio" and "NMK_GPIO" stand for "Nomadik GPIO", leaving
+ * the "gpio" namespace for generic and cross-machine functions
+ */
+
+/* Register in the logic block */
+#define NMK_GPIO_DAT   0x00
+#define NMK_GPIO_DATS  0x04
+#define NMK_GPIO_DATC  0x08
+#define NMK_GPIO_PDIS  0x0c
+#define NMK_GPIO_DIR   0x10
+#define NMK_GPIO_DIRS  0x14
+#define NMK_GPIO_DIRC  0x18
+#define NMK_GPIO_SLPC  0x1c
+#define NMK_GPIO_AFSLA 0x20
+#define NMK_GPIO_AFSLB 0x24
+
+#define NMK_GPIO_RIMSC 0x40
+#define NMK_GPIO_FIMSC 0x44
+#define NMK_GPIO_IS    0x48
+#define NMK_GPIO_IC    0x4c
+#define NMK_GPIO_RWIMSC        0x50
+#define NMK_GPIO_FWIMSC        0x54
+#define NMK_GPIO_WKS   0x58
+
+/* Alternate functions: function C is set in hw by setting both A and B */
+#define NMK_GPIO_ALT_GPIO      0
+#define NMK_GPIO_ALT_A 1
+#define NMK_GPIO_ALT_B 2
+#define NMK_GPIO_ALT_C (NMK_GPIO_ALT_A | NMK_GPIO_ALT_B)
+
+extern int nmk_gpio_set_mode(int gpio, int gpio_mode);
+extern int nmk_gpio_get_mode(int gpio);
+
+/*
+ * Platform data to register a block: only the initial gpio/irq number.
+ */
+struct nmk_gpio_platform_data {
+       char *name;
+       int first_gpio;
+       int first_irq;
+};
+
+#endif /* __ASM_PLAT_GPIO_H */
index fa7cb3a..0ff3798 100644 (file)
@@ -2,7 +2,7 @@
  *  linux/arch/arm/mach-nomadik/timer.c
  *
  * Copyright (C) 2008 STMicroelectronics
- * Copyright (C) 2009 Alessandro Rubini, somewhat based on at91sam926x
+ * Copyright (C) 2010 Alessandro Rubini
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2, as
 
 #include <plat/mtu.h>
 
-static u32     nmdk_count;             /* accumulated count */
-static u32     nmdk_cycle;             /* write-once */
-
-/* setup by the platform code */
-void __iomem *mtu_base;
+void __iomem *mtu_base; /* ssigned by machine code */
 
 /*
- * clocksource: the MTU device is a decrementing counters, so we negate
- * the value being read.
+ * Kernel assumes that sched_clock can be called early
+ * but the MTU may not yet be initialized.
  */
-static cycle_t nmdk_read_timer(struct clocksource *cs)
+static cycle_t nmdk_read_timer_dummy(struct clocksource *cs)
 {
-       u32 count = readl(mtu_base + MTU_VAL(0));
-       return nmdk_count + nmdk_cycle - count;
+       return 0;
+}
 
+/* clocksource: MTU decrements, so we negate the value being read. */
+static cycle_t nmdk_read_timer(struct clocksource *cs)
+{
+       return -readl(mtu_base + MTU_VAL(0));
 }
 
 static struct clocksource nmdk_clksrc = {
        .name           = "mtu_0",
-       .rating         = 120,
-       .read           = nmdk_read_timer,
+       .rating         = 200,
+       .read           = nmdk_read_timer_dummy,
+       .mask           = CLOCKSOURCE_MASK(32),
        .shift          = 20,
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
 /*
- * Clockevent device: currently only periodic mode is supported
+ * Override the global weak sched_clock symbol with this
+ * local implementation which uses the clocksource to get some
+ * better resolution when scheduling the kernel. We accept that
+ * this wraps around for now, since it is just a relative time
+ * stamp. (Inspired by OMAP implementation.)
  */
+unsigned long long notrace sched_clock(void)
+{
+       return clocksource_cyc2ns(nmdk_clksrc.read(
+                                 &nmdk_clksrc),
+                                 nmdk_clksrc.mult,
+                                 nmdk_clksrc.shift);
+}
+
+/* Clockevent device: use one-shot mode */
 static void nmdk_clkevt_mode(enum clock_event_mode mode,
                             struct clock_event_device *dev)
 {
+       u32 cr;
+
        switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
-               /* count current value? */
-               writel(readl(mtu_base + MTU_IMSC) | 1, mtu_base + MTU_IMSC);
+               pr_err("%s: periodic mode not supported\n", __func__);
                break;
        case CLOCK_EVT_MODE_ONESHOT:
-               BUG(); /* Not supported, yet */
-               /* FALLTHROUGH */
+               /* Load highest value, enable device, enable interrupts */
+               cr = readl(mtu_base + MTU_CR(1));
+               writel(0, mtu_base + MTU_LR(1));
+               writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(1));
+               writel(0x2, mtu_base + MTU_IMSC);
+               break;
        case CLOCK_EVT_MODE_SHUTDOWN:
        case CLOCK_EVT_MODE_UNUSED:
-               writel(readl(mtu_base + MTU_IMSC) & ~1, mtu_base + MTU_IMSC);
+               /* disable irq */
+               writel(0, mtu_base + MTU_IMSC);
                break;
        case CLOCK_EVT_MODE_RESUME:
                break;
        }
 }
 
+static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev)
+{
+       /* writing the value has immediate effect */
+       writel(evt, mtu_base + MTU_LR(1));
+       return 0;
+}
+
 static struct clock_event_device nmdk_clkevt = {
-       .name           = "mtu_0",
-       .features       = CLOCK_EVT_FEAT_PERIODIC,
+       .name           = "mtu_1",
+       .features       = CLOCK_EVT_FEAT_ONESHOT,
        .shift          = 32,
-       .rating         = 100,
+       .rating         = 200,
        .set_mode       = nmdk_clkevt_mode,
+       .set_next_event = nmdk_clkevt_next,
 };
 
 /*
- * IRQ Handler for the timer 0 of the MTU block. The irq is not shared
- * as we are the only users of mtu0 by now.
+ * IRQ Handler for timer 1 of the MTU block.
  */
 static irqreturn_t nmdk_timer_interrupt(int irq, void *dev_id)
 {
-       /* ack: "interrupt clear register" */
-       writel(1 << 0, mtu_base + MTU_ICR);
-
-       /* we can't count lost ticks, unfortunately */
-       nmdk_count += nmdk_cycle;
-       nmdk_clkevt.event_handler(&nmdk_clkevt);
+       struct clock_event_device *evdev = dev_id;
 
+       writel(1 << 1, mtu_base + MTU_ICR); /* Interrupt clear reg */
+       evdev->event_handler(evdev);
        return IRQ_HANDLED;
 }
 
-/*
- * Set up timer interrupt, and return the current time in seconds.
- */
 static struct irqaction nmdk_timer_irq = {
        .name           = "Nomadik Timer Tick",
        .flags          = IRQF_DISABLED | IRQF_TIMER,
        .handler        = nmdk_timer_interrupt,
+       .dev_id         = &nmdk_clkevt,
 };
 
-static void nmdk_timer_reset(void)
-{
-       u32 cr;
-
-       writel(0, mtu_base + MTU_CR(0)); /* off */
-
-       /* configure load and background-load, and fire it up */
-       writel(nmdk_cycle, mtu_base + MTU_LR(0));
-       writel(nmdk_cycle, mtu_base + MTU_BGLR(0));
-       cr = MTU_CRn_PERIODIC | MTU_CRn_PRESCALE_1 | MTU_CRn_32BITS;
-       writel(cr, mtu_base + MTU_CR(0));
-       writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));
-}
-
 void __init nmdk_timer_init(void)
 {
        unsigned long rate;
-       int bits;
-
-       rate = CLOCK_TICK_RATE; /* 2.4MHz */
-       nmdk_cycle = (rate + HZ/2) / HZ;
+       u32 cr = MTU_CRn_32BITS;;
+
+       /*
+        * Tick rate is 2.4MHz for Nomadik and 110MHz for ux500:
+        * use a divide-by-16 counter if it's more than 16MHz
+        */
+       rate = CLOCK_TICK_RATE;
+       if (rate > 16 << 20) {
+               rate /= 16;
+               cr |= MTU_CRn_PRESCALE_16;
+       } else {
+               cr |= MTU_CRn_PRESCALE_1;
+       }
 
-       /* Init the timer and register clocksource */
-       nmdk_timer_reset();
+       /* Timer 0 is the free running clocksource */
+       writel(cr, mtu_base + MTU_CR(0));
+       writel(0, mtu_base + MTU_LR(0));
+       writel(0, mtu_base + MTU_BGLR(0));
+       writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));
 
        nmdk_clksrc.mult = clocksource_hz2mult(rate, nmdk_clksrc.shift);
-       bits =  8*sizeof(nmdk_count);
-       nmdk_clksrc.mask = CLOCKSOURCE_MASK(bits);
+       /* Now the scheduling clock is ready */
+       nmdk_clksrc.read = nmdk_read_timer;
 
        if (clocksource_register(&nmdk_clksrc))
-               printk(KERN_ERR "timer: failed to initialize clock "
-                       "source %s\n", nmdk_clksrc.name);
+               pr_err("timer: failed to initialize clock source %s\n",
+                      nmdk_clksrc.name);
+
+       /* Timer 1 is used for events, fix according to rate */
+       writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */
+       nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift);
+       nmdk_clkevt.max_delta_ns =
+               clockevent_delta2ns(0xffffffff, &nmdk_clkevt);
+       nmdk_clkevt.min_delta_ns =
+               clockevent_delta2ns(0x00000002, &nmdk_clkevt);
+       nmdk_clkevt.cpumask     = cpumask_of(0);
 
        /* Register irq and clockevents */
        setup_irq(IRQ_MTU0, &nmdk_timer_irq);
-       nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift);
-       nmdk_clkevt.cpumask = cpumask_of(0);
        clockevents_register_device(&nmdk_clkevt);
 }
index 624e262..f044b59 100644 (file)
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
+#include <linux/i2c-omap.h>
+
 #include <mach/irqs.h>
 #include <plat/mux.h>
 #include <plat/i2c.h>
+#include <plat/omap-pm.h>
 
 #define OMAP_I2C_SIZE          0x3f
 #define OMAP1_I2C_BASE         0xfffb3800
@@ -70,14 +73,14 @@ static struct resource i2c_resources[][2] = {
                },                                      \
        }
 
-static u32 i2c_rate[ARRAY_SIZE(i2c_resources)];
+static struct omap_i2c_bus_platform_data i2c_pdata[ARRAY_SIZE(i2c_resources)];
 static struct platform_device omap_i2c_devices[] = {
-       I2C_DEV_BUILDER(1, i2c_resources[0], &i2c_rate[0]),
+       I2C_DEV_BUILDER(1, i2c_resources[0], &i2c_pdata[0]),
 #if    defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
-       I2C_DEV_BUILDER(2, i2c_resources[1], &i2c_rate[1]),
+       I2C_DEV_BUILDER(2, i2c_resources[1], &i2c_pdata[1]),
 #endif
 #if    defined(CONFIG_ARCH_OMAP3)
-       I2C_DEV_BUILDER(3, i2c_resources[2], &i2c_rate[2]),
+       I2C_DEV_BUILDER(3, i2c_resources[2], &i2c_pdata[2]),
 #endif
 };
 
@@ -100,10 +103,12 @@ static int __init omap_i2c_nr_ports(void)
 static int __init omap_i2c_add_bus(int bus_id)
 {
        struct platform_device *pdev;
+       struct omap_i2c_bus_platform_data *pd;
        struct resource *res;
        resource_size_t base, irq;
 
        pdev = &omap_i2c_devices[bus_id - 1];
+       pd = pdev->dev.platform_data;
        if (bus_id == 1) {
                res = pdev->resource;
                if (cpu_class_is_omap1()) {
@@ -123,6 +128,15 @@ static int __init omap_i2c_add_bus(int bus_id)
        if (cpu_class_is_omap2())
                omap2_i2c_mux_pins(bus_id);
 
+       /*
+        * When waiting for completion of a i2c transfer, we need to
+        * set a wake up latency constraint for the MPU. This is to
+        * ensure quick enough wakeup from idle, when transfer
+        * completes.
+        */
+       if (cpu_is_omap34xx())
+               pd->set_mpu_wkup_lat = omap_pm_set_max_mpu_wakeup_lat;
+
        return platform_device_register(pdev);
 }
 
@@ -146,8 +160,8 @@ static int __init omap_i2c_bus_setup(char *str)
        get_options(str, 3, ints);
        if (ints[0] < 2 || ints[1] < 1 || ints[1] > ports)
                return 0;
-       i2c_rate[ints[1] - 1] = ints[2];
-       i2c_rate[ints[1] - 1] |= OMAP_I2C_CMDLINE_SETUP;
+       i2c_pdata[ints[1] - 1].clkrate = ints[2];
+       i2c_pdata[ints[1] - 1].clkrate |= OMAP_I2C_CMDLINE_SETUP;
 
        return 1;
 }
@@ -161,9 +175,9 @@ static int __init omap_register_i2c_bus_cmdline(void)
 {
        int i, err = 0;
 
-       for (i = 0; i < ARRAY_SIZE(i2c_rate); i++)
-               if (i2c_rate[i] & OMAP_I2C_CMDLINE_SETUP) {
-                       i2c_rate[i] &= ~OMAP_I2C_CMDLINE_SETUP;
+       for (i = 0; i < ARRAY_SIZE(i2c_pdata); i++)
+               if (i2c_pdata[i].clkrate & OMAP_I2C_CMDLINE_SETUP) {
+                       i2c_pdata[i].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
                        err = omap_i2c_add_bus(i + 1);
                        if (err)
                                goto out;
@@ -197,9 +211,10 @@ int __init omap_register_i2c_bus(int bus_id, u32 clkrate,
                        return err;
        }
 
-       if (!i2c_rate[bus_id - 1])
-               i2c_rate[bus_id - 1] = clkrate;
-       i2c_rate[bus_id - 1] &= ~OMAP_I2C_CMDLINE_SETUP;
+       if (!i2c_pdata[bus_id - 1].clkrate)
+               i2c_pdata[bus_id - 1].clkrate = clkrate;
+
+       i2c_pdata[bus_id - 1].clkrate &= ~OMAP_I2C_CMDLINE_SETUP;
 
        return omap_i2c_add_bus(bus_id);
 }
index 7de903d..975744f 100644 (file)
 #define OMAP_MCBSP_REG_WAKEUPEN        0xA8
 #define OMAP_MCBSP_REG_XCCR    0xAC
 #define OMAP_MCBSP_REG_RCCR    0xB0
+#define OMAP_MCBSP_REG_XBUFFSTAT       0xB4
+#define OMAP_MCBSP_REG_RBUFFSTAT       0xB8
 #define OMAP_MCBSP_REG_SSELCR  0xBC
 
 #define OMAP_ST_REG_REV                0x00
@@ -471,6 +473,8 @@ void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
 void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
 u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
 u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
+u16 omap_mcbsp_get_tx_delay(unsigned int id);
+u16 omap_mcbsp_get_rx_delay(unsigned int id);
 int omap_mcbsp_get_dma_op_mode(unsigned int id);
 #else
 static inline void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
@@ -479,6 +483,8 @@ static inline void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
 { }
 static inline u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) { return 0; }
 static inline u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) { return 0; }
+static inline u16 omap_mcbsp_get_tx_delay(unsigned int id) { return 0; }
+static inline u16 omap_mcbsp_get_rx_delay(unsigned int id) { return 0; }
 static inline int omap_mcbsp_get_dma_op_mode(unsigned int id) { return 0; }
 #endif
 int omap_mcbsp_request(unsigned int id);
index e1d0440..7e669c9 100644 (file)
@@ -489,7 +489,7 @@ void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
 {
        struct omap_mcbsp *mcbsp;
 
-       if (!cpu_is_omap34xx())
+       if (!cpu_is_omap34xx() && !cpu_is_omap44xx())
                return;
 
        if (!omap_mcbsp_check_valid_id(id)) {
@@ -511,7 +511,7 @@ void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
 {
        struct omap_mcbsp *mcbsp;
 
-       if (!cpu_is_omap34xx())
+       if (!cpu_is_omap34xx() && !cpu_is_omap44xx())
                return;
 
        if (!omap_mcbsp_check_valid_id(id)) {
@@ -560,6 +560,61 @@ u16 omap_mcbsp_get_max_rx_threshold(unsigned int id)
 }
 EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold);
 
+#define MCBSP2_FIFO_SIZE       0x500 /* 1024 + 256 locations */
+#define MCBSP1345_FIFO_SIZE    0x80  /* 128 locations */
+/*
+ * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
+ */
+u16 omap_mcbsp_get_tx_delay(unsigned int id)
+{
+       struct omap_mcbsp *mcbsp;
+       u16 buffstat;
+
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+       mcbsp = id_to_mcbsp_ptr(id);
+
+       /* Returns the number of free locations in the buffer */
+       buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
+
+       /* Number of slots are different in McBSP ports */
+       if (mcbsp->id == 2)
+               return MCBSP2_FIFO_SIZE - buffstat;
+       else
+               return MCBSP1345_FIFO_SIZE - buffstat;
+}
+EXPORT_SYMBOL(omap_mcbsp_get_tx_delay);
+
+/*
+ * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
+ * to reach the threshold value (when the DMA will be triggered to read it)
+ */
+u16 omap_mcbsp_get_rx_delay(unsigned int id)
+{
+       struct omap_mcbsp *mcbsp;
+       u16 buffstat, threshold;
+
+       if (!omap_mcbsp_check_valid_id(id)) {
+               printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
+               return -ENODEV;
+       }
+       mcbsp = id_to_mcbsp_ptr(id);
+
+       /* Returns the number of used locations in the buffer */
+       buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
+       /* RX threshold */
+       threshold = MCBSP_READ(mcbsp, THRSH1);
+
+       /* Return the number of location till we reach the threshold limit */
+       if (threshold <= buffstat)
+               return 0;
+       else
+               return threshold - buffstat;
+}
+EXPORT_SYMBOL(omap_mcbsp_get_rx_delay);
+
 /*
  * omap_mcbsp_get_dma_op_mode just return the current configured
  * operating mode for the mcbsp channel
@@ -587,7 +642,7 @@ static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
         * Enable wakup behavior, smart idle and all wakeups
         * REVISIT: some wakeups may be unnecessary
         */
-       if (cpu_is_omap34xx()) {
+       if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
                u16 syscon;
 
                syscon = MCBSP_READ(mcbsp, SYSCON);
@@ -610,7 +665,7 @@ static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
        /*
         * Disable wakup behavior, smart idle and all wakeups
         */
-       if (cpu_is_omap34xx()) {
+       if (cpu_is_omap34xx() || cpu_is_omap44xx()) {
                u16 syscon;
 
                syscon = MCBSP_READ(mcbsp, SYSCON);
@@ -724,14 +779,17 @@ int omap_mcbsp_request(unsigned int id)
                        goto err_clk_disable;
                }
 
-               init_completion(&mcbsp->rx_irq_completion);
-               err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler,
+               if (mcbsp->rx_irq) {
+                       init_completion(&mcbsp->rx_irq_completion);
+                       err = request_irq(mcbsp->rx_irq,
+                                       omap_mcbsp_rx_irq_handler,
                                        0, "McBSP", (void *)mcbsp);
-               if (err != 0) {
-                       dev_err(mcbsp->dev, "Unable to request RX IRQ %d "
-                                       "for McBSP%d\n", mcbsp->rx_irq,
-                                       mcbsp->id);
-                       goto err_free_irq;
+                       if (err != 0) {
+                               dev_err(mcbsp->dev, "Unable to request RX IRQ %d "
+                                               "for McBSP%d\n", mcbsp->rx_irq,
+                                               mcbsp->id);
+                               goto err_free_irq;
+                       }
                }
        }
 
@@ -781,7 +839,8 @@ void omap_mcbsp_free(unsigned int id)
 
        if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) {
                /* Free IRQs */
-               free_irq(mcbsp->rx_irq, (void *)mcbsp);
+               if (mcbsp->rx_irq)
+                       free_irq(mcbsp->rx_irq, (void *)mcbsp);
                free_irq(mcbsp->tx_irq, (void *)mcbsp);
        }
 
@@ -855,7 +914,7 @@ void omap_mcbsp_start(unsigned int id, int tx, int rx)
                MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
        }
 
-       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+       if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
                /* Release the transmitter and receiver */
                w = MCBSP_READ_CACHE(mcbsp, XCCR);
                w &= ~(tx ? XDISABLE : 0);
@@ -885,7 +944,7 @@ void omap_mcbsp_stop(unsigned int id, int tx, int rx)
 
        /* Reset transmitter */
        tx &= 1;
-       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+       if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
                w = MCBSP_READ_CACHE(mcbsp, XCCR);
                w |= (tx ? XDISABLE : 0);
                MCBSP_WRITE(mcbsp, XCCR, w);
@@ -895,7 +954,7 @@ void omap_mcbsp_stop(unsigned int id, int tx, int rx)
 
        /* Reset receiver */
        rx &= 1;
-       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+       if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
                w = MCBSP_READ_CACHE(mcbsp, RCCR);
                w |= (rx ? RDISABLE : 0);
                MCBSP_WRITE(mcbsp, RCCR, w);
index b158e98..da53395 100644 (file)
@@ -1,3 +1,8 @@
 if PLAT_PXA
 
+config PXA_SSP
+       tristate
+       help
+         Enable support for PXA2xx SSP ports
+
 endif
index 0264bfb..6187edf 100644 (file)
@@ -2,10 +2,11 @@
 # Makefile for code common across different PXA processor families
 #
 
-obj-y  := dma.o
+obj-y  := dma.o pmu.o
 
 obj-$(CONFIG_GENERIC_GPIO)     += gpio.o
 obj-$(CONFIG_PXA3xx)           += mfp.o
 obj-$(CONFIG_ARCH_MMP)         += mfp.o
 
 obj-$(CONFIG_HAVE_PWM)         += pwm.o
+obj-$(CONFIG_PXA_SSP)          += ssp.o
index 857a683..9e604c8 100644 (file)
@@ -316,6 +316,13 @@ enum {
        MFP_PIN_PMIC_INT,
        MFP_PIN_RDY,
 
+       /* additional pins on MMP2 */
+       MFP_PIN_TWSI1_SCL,
+       MFP_PIN_TWSI1_SDA,
+       MFP_PIN_TWSI4_SCL,
+       MFP_PIN_TWSI4_SDA,
+       MFP_PIN_CLK_REQ,
+
        MFP_PIN_MAX,
 };
 
similarity index 75%
rename from arch/arm/mach-pxa/include/mach/regs-ssp.h
rename to arch/arm/plat-pxa/include/plat/ssp.h
index 6a2ed35..fe43150 100644 (file)
@@ -1,5 +1,26 @@
-#ifndef __ASM_ARCH_REGS_SSP_H
-#define __ASM_ARCH_REGS_SSP_H
+/*
+ *  ssp.h
+ *
+ *  Copyright (C) 2003 Russell King, 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 version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This driver supports the following PXA CPU/SSP ports:-
+ *
+ *       PXA250     SSP
+ *       PXA255     SSP, NSSP
+ *       PXA26x     SSP, NSSP, ASSP
+ *       PXA27x     SSP1, SSP2, SSP3
+ *       PXA3xx     SSP1, SSP2, SSP3, SSP4
+ */
+
+#ifndef __ASM_ARCH_SSP_H
+#define __ASM_ARCH_SSP_H
+
+#include <linux/list.h>
+#include <linux/io.h>
 
 /*
  * SSP Serial Port Registers
 #define SSRSA          (0x34)  /* SSP Rx Timeslot Active */
 #define SSTSS          (0x38)  /* SSP Timeslot Status */
 #define SSACD          (0x3C)  /* SSP Audio Clock Divider */
-
-#if defined(CONFIG_PXA3xx)
 #define SSACDD         (0x40)  /* SSP Audio Clock Dither Divider */
-#endif
 
 /* Common PXA2xx bits first */
 #define SSCR0_DSS      (0x0000000f)    /* Data Size Select (mask) */
 #define SSCR0_National (0x2 << 4)      /* National Microwire */
 #define SSCR0_ECS      (1 << 6)        /* External clock select */
 #define SSCR0_SSE      (1 << 7)        /* Synchronous Serial Port Enable */
+#define SSCR0_SCR(x)   ((x) << 8)      /* Serial Clock Rate (mask) */
 
-#if defined(CONFIG_PXA25x)
-#define SSCR0_SCR      (0x0000ff00)    /* Serial Clock Rate (mask) */
-#define SSCR0_SerClkDiv(x) ((((x) - 2)/2) << 8) /* Divisor [2..512] */
-#elif defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
-#define SSCR0_SCR      (0x000fff00)    /* Serial Clock Rate (mask) */
-#define SSCR0_SerClkDiv(x) (((x) - 1) << 8) /* Divisor [1..4096] */
-#endif
-
-#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
+/* PXA27x, PXA3xx */
 #define SSCR0_EDSS     (1 << 20)       /* Extended data size select */
 #define SSCR0_NCS      (1 << 21)       /* Network clock select */
 #define SSCR0_RIM      (1 << 22)       /* Receive FIFO overrrun interrupt mask */
 #define SSCR0_TUM      (1 << 23)       /* Transmit FIFO underrun interrupt mask */
 #define SSCR0_FRDC     (0x07000000)    /* Frame rate divider control (mask) */
 #define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */
+#define SSCR0_FPCKE    (1 << 29)       /* FIFO packing enable */
 #define SSCR0_ACS      (1 << 30)       /* Audio clock select */
 #define SSCR0_MOD      (1 << 31)       /* Mode (normal or network) */
-#endif
 
-#if defined(CONFIG_PXA3xx)
-#define SSCR0_FPCKE    (1 << 29)       /* FIFO packing enable */
-#endif
 
 #define SSCR1_RIE      (1 << 0)        /* Receive FIFO Interrupt Enable */
 #define SSCR1_TIE      (1 << 1)        /* Transmit FIFO Interrupt Enable */
 #define SSSR_RFS       (1 << 6)        /* Receive FIFO Service Request */
 #define SSSR_ROR       (1 << 7)        /* Receive FIFO Overrun */
 
-#define SSCR0_TIM              (1 << 23)       /* Transmit FIFO Under Run Interrupt Mask */
-#define SSCR0_RIM              (1 << 22)       /* Receive FIFO Over Run interrupt Mask */
-#define SSCR0_NCS              (1 << 21)       /* Network Clock Select */
-#define SSCR0_EDSS             (1 << 20)       /* Extended Data Size Select */
 
 /* extra bits in PXA255, PXA26x and PXA27x SSP ports */
 #define SSCR0_TISSP            (1 << 4)        /* TI Sync Serial Protocol */
 #define SSSR_TINT              (1 << 19)       /* Receiver Time-out Interrupt */
 #define SSSR_PINT              (1 << 18)       /* Peripheral Trailing Byte Interrupt */
 
-#if defined(CONFIG_PXA3xx)
-#define SSPSP_EDMYSTOP(x)      ((x) << 28)     /* Extended Dummy Stop */
-#define SSPSP_EDMYSTRT(x)      ((x) << 26)     /* Extended Dummy Start */
-#endif
 
-#define SSPSP_FSRT             (1 << 25)       /* Frame Sync Relative Timing */
-#define SSPSP_DMYSTOP(x)       ((x) << 23)     /* Dummy Stop */
-#define SSPSP_SFRMWDTH(x)      ((x) << 16)     /* Serial Frame Width */
-#define SSPSP_SFRMDLY(x)       ((x) << 9)      /* Serial Frame Delay */
-#define SSPSP_DMYSTRT(x)       ((x) << 7)      /* Dummy Start */
-#define SSPSP_STRTDLY(x)       ((x) << 4)      /* Start Delay */
-#define SSPSP_ETDS             (1 << 3)        /* End of Transfer data State */
-#define SSPSP_SFRMP            (1 << 2)        /* Serial Frame Polarity */
 #define SSPSP_SCMODE(x)                ((x) << 0)      /* Serial Bit Rate Clock Mode */
+#define SSPSP_SFRMP            (1 << 2)        /* Serial Frame Polarity */
+#define SSPSP_ETDS             (1 << 3)        /* End of Transfer data State */
+#define SSPSP_STRTDLY(x)       ((x) << 4)      /* Start Delay */
+#define SSPSP_DMYSTRT(x)       ((x) << 7)      /* Dummy Start */
+#define SSPSP_SFRMDLY(x)       ((x) << 9)      /* Serial Frame Delay */
+#define SSPSP_SFRMWDTH(x)      ((x) << 16)     /* Serial Frame Width */
+#define SSPSP_DMYSTOP(x)       ((x) << 23)     /* Dummy Stop */
+#define SSPSP_FSRT             (1 << 25)       /* Frame Sync Relative Timing */
+
+/* PXA3xx */
+#define SSPSP_EDMYSTRT(x)      ((x) << 26)     /* Extended Dummy Start */
+#define SSPSP_EDMYSTOP(x)      ((x) << 28)     /* Extended Dummy Stop */
+#define SSPSP_TIMING_MASK      (0x7f8001f0)
 
 #define SSACD_SCDB             (1 << 3)        /* SSPSYSCLK Divider Bypass */
 #define SSACD_ACPS(x)          ((x) << 4)      /* Audio clock PLL select */
 #define SSACD_ACDS(x)          ((x) << 0)      /* Audio clock divider select */
-#if defined(CONFIG_PXA3xx)
 #define SSACD_SCDX8            (1 << 7)        /* SYSCLK division ratio select */
-#endif
-
 
-#endif /* __ASM_ARCH_REGS_SSP_H */
+enum pxa_ssp_type {
+       SSP_UNDEFINED = 0,
+       PXA25x_SSP,  /* pxa 210, 250, 255, 26x */
+       PXA25x_NSSP, /* pxa 255, 26x (including ASSP) */
+       PXA27x_SSP,
+       PXA168_SSP,
+};
+
+struct ssp_device {
+       struct platform_device *pdev;
+       struct list_head        node;
+
+       struct clk      *clk;
+       void __iomem    *mmio_base;
+       unsigned long   phys_base;
+
+       const char      *label;
+       int             port_id;
+       int             type;
+       int             use_count;
+       int             irq;
+       int             drcmr_rx;
+       int             drcmr_tx;
+};
+
+/**
+ * pxa_ssp_write_reg - Write to a SSP register
+ *
+ * @dev: SSP device to access
+ * @reg: Register to write to
+ * @val: Value to be written.
+ */
+static inline void pxa_ssp_write_reg(struct ssp_device *dev, u32 reg, u32 val)
+{
+       __raw_writel(val, dev->mmio_base + reg);
+}
+
+/**
+ * pxa_ssp_read_reg - Read from a SSP register
+ *
+ * @dev: SSP device to access
+ * @reg: Register to read from
+ */
+static inline u32 pxa_ssp_read_reg(struct ssp_device *dev, u32 reg)
+{
+       return __raw_readl(dev->mmio_base + reg);
+}
+
+struct ssp_device *pxa_ssp_request(int port, const char *label);
+void pxa_ssp_free(struct ssp_device *);
+#endif /* __ASM_ARCH_SSP_H */
index be58f9f..b77e018 100644 (file)
@@ -110,6 +110,7 @@ static const unsigned long mfpr_lpm[] = {
        MFPR_LPM_PULL_LOW,
        MFPR_LPM_PULL_HIGH,
        MFPR_LPM_FLOAT,
+       MFPR_LPM_INPUT,
 };
 
 /* mapping of MFP_PULL_* definitions to MFPR_PULL_* register bits */
diff --git a/arch/arm/plat-pxa/pmu.c b/arch/arm/plat-pxa/pmu.c
new file mode 100644 (file)
index 0000000..267ceb6
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * PMU IRQ registration for the PXA xscale PMU families.
+ * Copyright (C) 2010 Will Deacon, ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/platform_device.h>
+#include <asm/pmu.h>
+#include <mach/irqs.h>
+
+static struct resource pmu_resource = {
+       .start  = IRQ_PMU,
+       .end    = IRQ_PMU,
+       .flags  = IORESOURCE_IRQ,
+};
+
+static struct platform_device pmu_device = {
+       .name           = "arm-pmu",
+       .id             = ARM_PMU_DEVICE_CPU,
+       .resource       = &pmu_resource,
+       .num_resources  = 1,
+};
+
+static int __init pxa_pmu_init(void)
+{
+       platform_device_register(&pmu_device);
+       return 0;
+}
+arch_initcall(pxa_pmu_init);
diff --git a/arch/arm/plat-pxa/ssp.c b/arch/arm/plat-pxa/ssp.c
new file mode 100644 (file)
index 0000000..c6357e5
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ *  linux/arch/arm/mach-pxa/ssp.c
+ *
+ *  based on linux/arch/arm/mach-sa1100/ssp.c by Russell King
+ *
+ *  Copyright (C) 2003 Russell King.
+ *  Copyright (C) 2003 Wolfson Microelectronics PLC
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ *  PXA2xx SSP driver.  This provides the generic core for simple
+ *  IO-based SSP applications and allows easy port setup for DMA access.
+ *
+ *  Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/interrupt.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/mutex.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+#include <asm/irq.h>
+#include <mach/hardware.h>
+#include <plat/ssp.h>
+
+static DEFINE_MUTEX(ssp_lock);
+static LIST_HEAD(ssp_list);
+
+struct ssp_device *pxa_ssp_request(int port, const char *label)
+{
+       struct ssp_device *ssp = NULL;
+
+       mutex_lock(&ssp_lock);
+
+       list_for_each_entry(ssp, &ssp_list, node) {
+               if (ssp->port_id == port && ssp->use_count == 0) {
+                       ssp->use_count++;
+                       ssp->label = label;
+                       break;
+               }
+       }
+
+       mutex_unlock(&ssp_lock);
+
+       if (&ssp->node == &ssp_list)
+               return NULL;
+
+       return ssp;
+}
+EXPORT_SYMBOL(pxa_ssp_request);
+
+void pxa_ssp_free(struct ssp_device *ssp)
+{
+       mutex_lock(&ssp_lock);
+       if (ssp->use_count) {
+               ssp->use_count--;
+               ssp->label = NULL;
+       } else
+               dev_err(&ssp->pdev->dev, "device already free\n");
+       mutex_unlock(&ssp_lock);
+}
+EXPORT_SYMBOL(pxa_ssp_free);
+
+static int __devinit pxa_ssp_probe(struct platform_device *pdev)
+{
+       const struct platform_device_id *id = platform_get_device_id(pdev);
+       struct resource *res;
+       struct ssp_device *ssp;
+       int ret = 0;
+
+       ssp = kzalloc(sizeof(struct ssp_device), GFP_KERNEL);
+       if (ssp == NULL) {
+               dev_err(&pdev->dev, "failed to allocate memory");
+               return -ENOMEM;
+       }
+       ssp->pdev = pdev;
+
+       ssp->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(ssp->clk)) {
+               ret = PTR_ERR(ssp->clk);
+               goto err_free;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "no SSP RX DRCMR defined\n");
+               ret = -ENODEV;
+               goto err_free_clk;
+       }
+       ssp->drcmr_rx = res->start;
+
+       res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "no SSP TX DRCMR defined\n");
+               ret = -ENODEV;
+               goto err_free_clk;
+       }
+       ssp->drcmr_tx = res->start;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "no memory resource defined\n");
+               ret = -ENODEV;
+               goto err_free_clk;
+       }
+
+       res = request_mem_region(res->start, resource_size(res),
+                       pdev->name);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "failed to request memory resource\n");
+               ret = -EBUSY;
+               goto err_free_clk;
+       }
+
+       ssp->phys_base = res->start;
+
+       ssp->mmio_base = ioremap(res->start, resource_size(res));
+       if (ssp->mmio_base == NULL) {
+               dev_err(&pdev->dev, "failed to ioremap() registers\n");
+               ret = -ENODEV;
+               goto err_free_mem;
+       }
+
+       ssp->irq = platform_get_irq(pdev, 0);
+       if (ssp->irq < 0) {
+               dev_err(&pdev->dev, "no IRQ resource defined\n");
+               ret = -ENODEV;
+               goto err_free_io;
+       }
+
+       /* PXA2xx/3xx SSP ports starts from 1 and the internal pdev->id
+        * starts from 0, do a translation here
+        */
+       ssp->port_id = pdev->id + 1;
+       ssp->use_count = 0;
+       ssp->type = (int)id->driver_data;
+
+       mutex_lock(&ssp_lock);
+       list_add(&ssp->node, &ssp_list);
+       mutex_unlock(&ssp_lock);
+
+       platform_set_drvdata(pdev, ssp);
+       return 0;
+
+err_free_io:
+       iounmap(ssp->mmio_base);
+err_free_mem:
+       release_mem_region(res->start, resource_size(res));
+err_free_clk:
+       clk_put(ssp->clk);
+err_free:
+       kfree(ssp);
+       return ret;
+}
+
+static int __devexit pxa_ssp_remove(struct platform_device *pdev)
+{
+       struct resource *res;
+       struct ssp_device *ssp;
+
+       ssp = platform_get_drvdata(pdev);
+       if (ssp == NULL)
+               return -ENODEV;
+
+       iounmap(ssp->mmio_base);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       release_mem_region(res->start, resource_size(res));
+
+       clk_put(ssp->clk);
+
+       mutex_lock(&ssp_lock);
+       list_del(&ssp->node);
+       mutex_unlock(&ssp_lock);
+
+       kfree(ssp);
+       return 0;
+}
+
+static const struct platform_device_id ssp_id_table[] = {
+       { "pxa25x-ssp",         PXA25x_SSP },
+       { "pxa25x-nssp",        PXA25x_NSSP },
+       { "pxa27x-ssp",         PXA27x_SSP },
+       { "pxa168-ssp",         PXA168_SSP },
+       { },
+};
+
+static struct platform_driver pxa_ssp_driver = {
+       .probe          = pxa_ssp_probe,
+       .remove         = __devexit_p(pxa_ssp_remove),
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "pxa2xx-ssp",
+       },
+       .id_table       = ssp_id_table,
+};
+
+static int __init pxa_ssp_init(void)
+{
+       return platform_driver_register(&pxa_ssp_driver);
+}
+
+static void __exit pxa_ssp_exit(void)
+{
+       platform_driver_unregister(&pxa_ssp_driver);
+}
+
+arch_initcall(pxa_ssp_init);
+module_exit(pxa_ssp_exit);
+
+MODULE_DESCRIPTION("PXA SSP driver");
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_LICENSE("GPL");
index 6e93ef8..984bf66 100644 (file)
@@ -9,6 +9,7 @@ config PLAT_S3C24XX
        select NO_IOPORT
        select ARCH_REQUIRE_GPIOLIB
        select S3C_DEVICE_NAND
+       select S3C_GPIO_CFG_S3C24XX
        help
          Base platform code for any Samsung S3C24XX device
 
@@ -44,6 +45,12 @@ config S3C2410_CLOCK
          Clock code for the S3C2410, and similar processors which
          is currently includes the S3C2410, S3C2440, S3C2442.
 
+config S3C2443_CLOCK
+       bool
+       help
+         Clock code for the S3C2443 and similar processors, which includes
+         the S3C2416 and S3C2450.
+
 config S3C24XX_DCLK
        bool
        help
@@ -157,4 +164,9 @@ config S3C24XX_SIMTEC_AUDIO
        help
          Add audio devices for common Simtec S3C24XX boards
 
+config S3C2410_SETUP_TS
+       bool
+       help
+         Compile in platform device definition for Samsung TouchScreen.
+
 endif
index c2237c4..c2064c3 100644 (file)
@@ -30,6 +30,7 @@ obj-$(CONFIG_PM)              += pm.o
 obj-$(CONFIG_PM)               += irq-pm.o
 obj-$(CONFIG_PM)               += sleep.o
 obj-$(CONFIG_S3C2410_CLOCK)    += s3c2410-clock.o
+obj-$(CONFIG_S3C2443_CLOCK)    += s3c2443-clock.o
 obj-$(CONFIG_S3C2410_DMA)      += dma.o
 obj-$(CONFIG_S3C2410_IOTIMING) += s3c2410-iotiming.o
 obj-$(CONFIG_S3C2412_IOTIMING) += s3c2412-iotiming.o
@@ -37,6 +38,7 @@ obj-$(CONFIG_S3C2410_CPUFREQ_UTILS) += s3c2410-cpufreq-utils.o
 
 # device specific setup and/or initialisation
 obj-$(CONFIG_ARCH_S3C2410)     += setup-i2c.o
+obj-$(CONFIG_S3C2410_SETUP_TS) += setup-ts.o
 
 # SPI gpio central GPIO functions
 
index 9e0e20a..7b44d0c 100644 (file)
@@ -42,6 +42,7 @@
 #include <plat/nand.h>
 
 #include <plat/common-smdk.h>
+#include <plat/gpio-cfg.h>
 #include <plat/devs.h>
 #include <plat/pm.h>
 
@@ -185,10 +186,10 @@ void __init smdk_machine_init(void)
 {
        /* Configure the LEDs (even if we have no LED support)*/
 
-       s3c2410_gpio_cfgpin(S3C2410_GPF(4), S3C2410_GPIO_OUTPUT);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(5), S3C2410_GPIO_OUTPUT);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(6), S3C2410_GPIO_OUTPUT);
-       s3c2410_gpio_cfgpin(S3C2410_GPF(7), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPF(4), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPF(5), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPF(6), S3C2410_GPIO_OUTPUT);
+       s3c_gpio_cfgpin(S3C2410_GPF(7), S3C2410_GPIO_OUTPUT);
 
        s3c2410_gpio_setpin(S3C2410_GPF(4), 1);
        s3c2410_gpio_setpin(S3C2410_GPF(5), 1);
index 9ca64df..76d0858 100644 (file)
@@ -49,6 +49,7 @@
 #include <plat/s3c2400.h>
 #include <plat/s3c2410.h>
 #include <plat/s3c2412.h>
+#include <plat/s3c2416.h>
 #include <plat/s3c244x.h>
 #include <plat/s3c2443.h>
 
@@ -57,6 +58,7 @@
 static const char name_s3c2400[]  = "S3C2400";
 static const char name_s3c2410[]  = "S3C2410";
 static const char name_s3c2412[]  = "S3C2412";
+static const char name_s3c2416[]  = "S3C2416/S3C2450";
 static const char name_s3c2440[]  = "S3C2440";
 static const char name_s3c2442[]  = "S3C2442";
 static const char name_s3c2442b[]  = "S3C2442B";
@@ -137,6 +139,15 @@ static struct cpu_table cpu_ids[] __initdata = {
                .init           = s3c2412_init,
                .name           = name_s3c2412,
        },
+       {                       /* a strange version of the s3c2416 */
+               .idcode         = 0x32450003,
+               .idmask         = 0xffffffff,
+               .map_io         = s3c2416_map_io,
+               .init_clocks    = s3c2416_init_clocks,
+               .init_uarts     = s3c2416_init_uarts,
+               .init           = s3c2416_init,
+               .name           = name_s3c2416,
+       },
        {
                .idcode         = 0x32443001,
                .idmask         = 0xffffffff,
@@ -170,6 +181,16 @@ static struct map_desc s3c_iodesc[] __initdata = {
 
 static unsigned long s3c24xx_read_idcode_v5(void)
 {
+#if defined(CONFIG_CPU_S3C2416)
+       /* s3c2416 is v5, with S3C24XX_GSTATUS1 instead of S3C2412_GSTATUS1 */
+
+       u32 gs = __raw_readl(S3C24XX_GSTATUS1);
+
+       /* test for s3c2416 or similar device */
+       if ((gs >> 16) == 0x3245)
+               return gs;
+#endif
+
 #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
        return __raw_readl(S3C2412_GSTATUS1);
 #else
index 9265f09..5858373 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
@@ -38,8 +39,7 @@
 #include <plat/devs.h>
 #include <plat/cpu.h>
 #include <plat/regs-spi.h>
-
-#include <mach/ts.h>
+#include <plat/ts.h>
 
 /* Serial port registrations */
 
@@ -149,10 +149,14 @@ void __init s3c24xx_fb_set_platdata(struct s3c2410fb_mach_info *pd)
 {
        struct s3c2410fb_mach_info *npd;
 
-       npd = kmalloc(sizeof(*npd), GFP_KERNEL);
+       npd = kmemdup(pd, sizeof(*npd), GFP_KERNEL);
        if (npd) {
-               memcpy(npd, pd, sizeof(*npd));
                s3c_device_lcd.dev.platform_data = npd;
+               npd->displays = kmemdup(pd->displays,
+                       sizeof(struct s3c2410fb_display) * npd->num_displays,
+                       GFP_KERNEL);
+               if (!npd->displays)
+                       printk(KERN_ERR "no memory for LCD display data\n");
        } else {
                printk(KERN_ERR "no memory for LCD platform data\n");
        }
@@ -338,14 +342,6 @@ struct platform_device s3c_device_adc = {
        .resource         = s3c_adc_resource,
 };
 
-/* HWMON */
-
-struct platform_device s3c_device_hwmon = {
-       .name           = "s3c-hwmon",
-       .id             = -1,
-       .dev.parent     = &s3c_device_adc.dev,
-};
-
 /* SDI */
 
 static struct resource s3c_sdi_resource[] = {
@@ -371,7 +367,7 @@ struct platform_device s3c_device_sdi = {
 
 EXPORT_SYMBOL(s3c_device_sdi);
 
-void s3c24xx_mci_set_platdata(struct s3c24xx_mci_pdata *pdata)
+void __init s3c24xx_mci_set_platdata(struct s3c24xx_mci_pdata *pdata)
 {
        struct s3c24xx_mci_pdata *npd;
 
index 93827b3..6ad274e 100644 (file)
@@ -1104,7 +1104,7 @@ EXPORT_SYMBOL(s3c2410_dma_config);
  * devaddr:   physical address of the source
 */
 
-int s3c2410_dma_devconfig(int channel,
+int s3c2410_dma_devconfig(unsigned int channel,
                          enum s3c2410_dmasrc source,
                          unsigned long devaddr)
 {
index 5467470..2f3d7c0 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/plat-s3c24xx/gpio.c
  *
- * Copyright (c) 2004-2005 Simtec Electronics
+ * Copyright (c) 2004-2010 Simtec Electronics
  *     Ben Dooks <ben@simtec.co.uk>
  *
  * S3C24XX GPIO support
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
-
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
+#include <linux/gpio.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
 
 #include <mach/regs-gpio.h>
 
-void s3c2410_gpio_cfgpin(unsigned int pin, unsigned int function)
-{
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long mask;
-       unsigned long con;
-       unsigned long flags;
+#include <plat/gpio-core.h>
 
-       if (pin < S3C2410_GPIO_BANKB) {
-               mask = 1 << S3C2410_GPIO_OFFSET(pin);
-       } else {
-               mask = 3 << S3C2410_GPIO_OFFSET(pin)*2;
-       }
-
-       switch (function) {
-       case S3C2410_GPIO_LEAVE:
-               mask = 0;
-               function = 0;
-               break;
-
-       case S3C2410_GPIO_INPUT:
-       case S3C2410_GPIO_OUTPUT:
-       case S3C2410_GPIO_SFN2:
-       case S3C2410_GPIO_SFN3:
-               if (pin < S3C2410_GPIO_BANKB) {
-                       function -= 1;
-                       function &= 1;
-                       function <<= S3C2410_GPIO_OFFSET(pin);
-               } else {
-                       function &= 3;
-                       function <<= S3C2410_GPIO_OFFSET(pin)*2;
-               }
-       }
-
-       /* modify the specified register wwith IRQs off */
-
-       local_irq_save(flags);
-
-       con  = __raw_readl(base + 0x00);
-       con &= ~mask;
-       con |= function;
-
-       __raw_writel(con, base + 0x00);
-
-       local_irq_restore(flags);
-}
-
-EXPORT_SYMBOL(s3c2410_gpio_cfgpin);
-
-unsigned int s3c2410_gpio_getcfg(unsigned int pin)
-{
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long val = __raw_readl(base);
-
-       if (pin < S3C2410_GPIO_BANKB) {
-               val >>= S3C2410_GPIO_OFFSET(pin);
-               val &= 1;
-               val += 1;
-       } else {
-               val >>= S3C2410_GPIO_OFFSET(pin)*2;
-               val &= 3;
-       }
-
-       return val | S3C2410_GPIO_INPUT;
-}
-
-EXPORT_SYMBOL(s3c2410_gpio_getcfg);
+/* gpiolib wrappers until these are totally eliminated */
 
 void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
 {
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long offs = S3C2410_GPIO_OFFSET(pin);
-       unsigned long flags;
-       unsigned long up;
+       int ret;
 
-       if (pin < S3C2410_GPIO_BANKB)
-               return;
+       WARN_ON(to);    /* should be none of these left */
 
-       local_irq_save(flags);
-
-       up = __raw_readl(base + 0x08);
-       up &= ~(1L << offs);
-       up |= to << offs;
-       __raw_writel(up, base + 0x08);
+       if (!to) {
+               /* if pull is enabled, try first with up, and if that
+                * fails, try using down */
 
-       local_irq_restore(flags);
+               ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
+               if (ret)
+                       s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
+       } else {
+               s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
+       }
 }
-
 EXPORT_SYMBOL(s3c2410_gpio_pullup);
 
-int s3c2410_gpio_getpull(unsigned int pin)
-{
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long offs = S3C2410_GPIO_OFFSET(pin);
-
-       if (pin < S3C2410_GPIO_BANKB)
-               return -EINVAL;
-
-       return (__raw_readl(base + 0x08) & (1L << offs)) ? 1 : 0;
-}
-
-EXPORT_SYMBOL(s3c2410_gpio_getpull);
-
 void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
 {
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long offs = S3C2410_GPIO_OFFSET(pin);
-       unsigned long flags;
-       unsigned long dat;
+       /* do this via gpiolib until all users removed */
 
-       local_irq_save(flags);
-
-       dat = __raw_readl(base + 0x04);
-       dat &= ~(1 << offs);
-       dat |= to << offs;
-       __raw_writel(dat, base + 0x04);
-
-       local_irq_restore(flags);
+       gpio_request(pin, "temporary");
+       gpio_set_value(pin, to);
+       gpio_free(pin);
 }
 
 EXPORT_SYMBOL(s3c2410_gpio_setpin);
 
 unsigned int s3c2410_gpio_getpin(unsigned int pin)
 {
-       void __iomem *base = S3C24XX_GPIO_BASE(pin);
-       unsigned long offs = S3C2410_GPIO_OFFSET(pin);
+       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
+       unsigned long offs = pin - chip->chip.base;
 
-       return __raw_readl(base + 0x04) & (1<< offs);
+       return __raw_readl(chip->base + 0x04) & (1<< offs);
 }
 
 EXPORT_SYMBOL(s3c2410_gpio_getpin);
@@ -181,22 +94,3 @@ unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
 }
 
 EXPORT_SYMBOL(s3c2410_modify_misccr);
-
-int s3c2410_gpio_getirq(unsigned int pin)
-{
-       if (pin < S3C2410_GPF(0) || pin > S3C2410_GPG(15))
-               return -EINVAL; /* not valid interrupts */
-
-       if (pin < S3C2410_GPG(0) && pin > S3C2410_GPF(7))
-               return -EINVAL; /* not valid pin */
-
-       if (pin < S3C2410_GPF(4))
-               return (pin - S3C2410_GPF(0)) + IRQ_EINT0;
-
-       if (pin < S3C2410_GPG(0))
-               return (pin - S3C2410_GPF(4)) + IRQ_EINT4;
-
-       return (pin - S3C2410_GPG(0)) + IRQ_EINT8;
-}
-
-EXPORT_SYMBOL(s3c2410_gpio_getirq);
index 4f0f11a..4c0896f 100644 (file)
@@ -1,6 +1,6 @@
 /* linux/arch/arm/plat-s3c24xx/gpiolib.c
  *
- * Copyright (c) 2008 Simtec Electronics
+ * Copyright (c) 2008-2010 Simtec Electronics
  *     http://armlinux.simtec.co.uk/
  *     Ben Dooks <ben@simtec.co.uk>
  *
@@ -21,6 +21,8 @@
 #include <linux/gpio.h>
 
 #include <plat/gpio-core.h>
+#include <plat/gpio-cfg.h>
+#include <plat/gpio-cfg-helpers.h>
 #include <mach/hardware.h>
 #include <asm/irq.h>
 #include <plat/pm.h>
@@ -77,10 +79,21 @@ static int s3c24xx_gpiolib_bankg_toirq(struct gpio_chip *chip, unsigned offset)
        return IRQ_EINT8 + offset;
 }
 
+static struct s3c_gpio_cfg s3c24xx_gpiocfg_banka = {
+       .set_config     = s3c_gpio_setcfg_s3c24xx_a,
+       .get_config     = s3c_gpio_getcfg_s3c24xx_a,
+};
+
+struct s3c_gpio_cfg s3c24xx_gpiocfg_default = {
+       .set_config     = s3c_gpio_setcfg_s3c24xx,
+       .get_config     = s3c_gpio_getcfg_s3c24xx,
+};
+
 struct s3c_gpio_chip s3c24xx_gpios[] = {
        [0] = {
                .base   = S3C2410_GPACON,
                .pm     = __gpio_pm(&s3c_gpio_pm_1bit),
+               .config = &s3c24xx_gpiocfg_banka,
                .chip   = {
                        .base                   = S3C2410_GPA(0),
                        .owner                  = THIS_MODULE,
@@ -161,15 +174,58 @@ struct s3c_gpio_chip s3c24xx_gpios[] = {
                        .ngpio                  = 11,
                },
        },
+               /* GPIOS for the S3C2443 and later devices. */
+       {
+               .base   = S3C2440_GPJCON,
+               .pm     = __gpio_pm(&s3c_gpio_pm_2bit),
+               .chip   = {
+                       .base                   = S3C2410_GPJ(0),
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOJ",
+                       .ngpio                  = 16,
+               },
+       }, {
+               .base   = S3C2443_GPKCON,
+               .pm     = __gpio_pm(&s3c_gpio_pm_2bit),
+               .chip   = {
+                       .base                   = S3C2410_GPK(0),
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOK",
+                       .ngpio                  = 16,
+               },
+       }, {
+               .base   = S3C2443_GPLCON,
+               .pm     = __gpio_pm(&s3c_gpio_pm_2bit),
+               .chip   = {
+                       .base                   = S3C2410_GPL(0),
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOL",
+                       .ngpio                  = 15,
+               },
+       }, {
+               .base   = S3C2443_GPMCON,
+               .pm     = __gpio_pm(&s3c_gpio_pm_2bit),
+               .chip   = {
+                       .base                   = S3C2410_GPM(0),
+                       .owner                  = THIS_MODULE,
+                       .label                  = "GPIOM",
+                       .ngpio                  = 2,
+               },
+       },
 };
 
+
 static __init int s3c24xx_gpiolib_init(void)
 {
        struct s3c_gpio_chip *chip = s3c24xx_gpios;
        int gpn;
 
-       for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++)
+       for (gpn = 0; gpn < ARRAY_SIZE(s3c24xx_gpios); gpn++, chip++) {
+               if (!chip->config)
+                       chip->config = &s3c24xx_gpiocfg_default;
+
                s3c_gpiolib_add(chip);
+       }
 
        return 0;
 }
index 7ea8bff..005729a 100644 (file)
@@ -35,3 +35,28 @@ s3c24xx_get_pll(unsigned int pllval, unsigned int baseclk)
 
        return (unsigned int)fvco;
 }
+
+#define S3C2416_PLL_M_SHIFT    (14)
+#define S3C2416_PLL_P_SHIFT    (5)
+#define S3C2416_PLL_S_MASK     (7)
+#define S3C2416_PLL_M_MASK     ((1 << 10) - 1)
+#define S3C2416_PLL_P_MASK     (63)
+
+static inline unsigned int
+s3c2416_get_pll(unsigned int pllval, unsigned int baseclk)
+{
+       unsigned int m, p, s;
+       uint64_t fvco;
+
+       m = pllval >> S3C2416_PLL_M_SHIFT;
+       p = pllval >> S3C2416_PLL_P_SHIFT;
+
+       s = pllval & S3C2416_PLL_S_MASK;
+       m &= S3C2416_PLL_M_MASK;
+       p &= S3C2416_PLL_P_MASK;
+
+       fvco = (uint64_t)baseclk * m;
+       do_div(fvco, (p << s));
+
+       return (unsigned int)fvco;
+}
diff --git a/arch/arm/plat-s3c24xx/include/plat/s3c2416.h b/arch/arm/plat-s3c24xx/include/plat/s3c2416.h
new file mode 100644 (file)
index 0000000..dc3c090
--- /dev/null
@@ -0,0 +1,31 @@
+/* linux/include/asm-arm/plat-s3c24xx/s3c2443.h
+ *
+ * Copyright (c) 2009 Yauhen Kharuzhy <jekhor@gmail.com>
+ *
+ * Header file for s3c2416 cpu support
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#ifdef CONFIG_CPU_S3C2416
+
+struct s3c2410_uartcfg;
+
+extern  int s3c2416_init(void);
+
+extern void s3c2416_map_io(void);
+
+extern void s3c2416_init_uarts(struct s3c2410_uartcfg *cfg, int no);
+
+extern void s3c2416_init_clocks(int xtal);
+
+extern  int s3c2416_baseclk_add(void);
+
+#else
+#define s3c2416_init_clocks NULL
+#define s3c2416_init_uarts NULL
+#define s3c2416_map_io NULL
+#define s3c2416_init NULL
+#endif
index 815b107..a19715f 100644 (file)
@@ -30,3 +30,22 @@ extern  int s3c2443_baseclk_add(void);
 #define s3c2443_map_io NULL
 #define s3c2443_init NULL
 #endif
+
+/* common code used by s3c2443 and others.
+ * note, not to be used outside of arch/arm/mach-s3c* */
+
+struct clk;    /* some files don't need clk.h otherwise */
+
+typedef unsigned int (*pll_fn)(unsigned int reg, unsigned int base);
+typedef unsigned int (*fdiv_fn)(unsigned long clkcon0);
+
+extern void s3c2443_common_setup_clocks(pll_fn get_mpll, fdiv_fn fdiv);
+extern void s3c2443_common_init_clocks(int xtal, pll_fn get_mpll, fdiv_fn fdiv);
+
+extern int s3c2443_clkcon_enable_h(struct clk *clk, int enable);
+extern int s3c2443_clkcon_enable_p(struct clk *clk, int enable);
+extern int s3c2443_clkcon_enable_s(struct clk *clk, int enable);
+
+extern struct clksrc_clk clk_epllref;
+extern struct clksrc_clk clk_esysclk;
+extern struct clksrc_clk clk_msysclk;
index 3620dd2..60627e6 100644 (file)
@@ -43,6 +43,7 @@
 
 #include <asm/mach/time.h>
 
+#include <plat/gpio-cfg.h>
 #include <plat/pm.h>
 
 #define PFX "s3c24xx-pm: "
@@ -90,22 +91,22 @@ static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs)
 {
        unsigned long irqstate;
        unsigned long pinstate;
-       int irq = s3c2410_gpio_getirq(pin);
+       int irq = gpio_to_irq(pin);
 
        if (irqoffs < 4)
                irqstate = s3c_irqwake_intmask & (1L<<irqoffs);
        else
                irqstate = s3c_irqwake_eintmask & (1L<<irqoffs);
 
-       pinstate = s3c2410_gpio_getcfg(pin);
+       pinstate = s3c_gpio_getcfg(pin);
 
        if (!irqstate) {
                if (pinstate == S3C2410_GPIO_IRQ)
-                       S3C_PMDBG("Leaving IRQ %d (pin %d) enabled\n", irq, pin);
+                       S3C_PMDBG("Leaving IRQ %d (pin %d) as is\n", irq, pin);
        } else {
                if (pinstate == S3C2410_GPIO_IRQ) {
                        S3C_PMDBG("Disabling IRQ %d (pin %d)\n", irq, pin);
-                       s3c2410_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
+                       s3c_gpio_cfgpin(pin, S3C2410_GPIO_INPUT);
                }
        }
 }
index b61bdb7..9ecc5d9 100644 (file)
@@ -87,7 +87,7 @@ static int s3c2410_upll_enable(struct clk *clk, int enable)
 
 /* standard clock definitions */
 
-static struct clk init_clocks_disable[] = {
+static struct clk init_clocks_off[] = {
        {
                .name           = "nand",
                .id             = -1,
@@ -249,17 +249,8 @@ int __init s3c2410_baseclk_add(void)
 
        /* install (and disable) the clocks we do not need immediately */
 
-       clkp = init_clocks_disable;
-       for (ptr = 0; ptr < ARRAY_SIZE(init_clocks_disable); ptr++, clkp++) {
-
-               ret = s3c24xx_register_clock(clkp);
-               if (ret < 0) {
-                       printk(KERN_ERR "Failed to register clock %s (%d)\n",
-                              clkp->name, ret);
-               }
-
-               s3c2410_clkcon_enable(clkp, 0);
-       }
+       s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
+       s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
 
        /* show the clock-slow value */
 
diff --git a/arch/arm/plat-s3c24xx/s3c2443-clock.c b/arch/arm/plat-s3c24xx/s3c2443-clock.c
new file mode 100644 (file)
index 0000000..461f070
--- /dev/null
@@ -0,0 +1,472 @@
+/* linux/arch/arm/plat-s3c24xx/s3c2443-clock.c
+ *
+ * Copyright (c) 2007, 2010 Simtec Electronics
+ *     Ben Dooks <ben@simtec.co.uk>
+ *
+ * S3C2443 Clock control suport - common code
+ */
+
+#include <linux/init.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <mach/regs-s3c2443-clock.h>
+
+#include <plat/s3c2443.h>
+#include <plat/clock.h>
+#include <plat/clock-clksrc.h>
+#include <plat/cpu.h>
+
+#include <plat/cpu-freq.h>
+
+
+static int s3c2443_gate(void __iomem *reg, struct clk *clk, int enable)
+{
+       u32 ctrlbit = clk->ctrlbit;
+       u32 con = __raw_readl(reg);
+
+       if (enable)
+               con |= ctrlbit;
+       else
+               con &= ~ctrlbit;
+
+       __raw_writel(con, reg);
+       return 0;
+}
+
+int s3c2443_clkcon_enable_h(struct clk *clk, int enable)
+{
+       return s3c2443_gate(S3C2443_HCLKCON, clk, enable);
+}
+
+int s3c2443_clkcon_enable_p(struct clk *clk, int enable)
+{
+       return s3c2443_gate(S3C2443_PCLKCON, clk, enable);
+}
+
+int s3c2443_clkcon_enable_s(struct clk *clk, int enable)
+{
+       return s3c2443_gate(S3C2443_SCLKCON, clk, enable);
+}
+
+/* mpllref is a direct descendant of clk_xtal by default, but it is not
+ * elided as the EPLL can be either sourced by the XTAL or EXTCLK and as
+ * such directly equating the two source clocks is impossible.
+ */
+struct clk clk_mpllref = {
+       .name           = "mpllref",
+       .parent         = &clk_xtal,
+       .id             = -1,
+};
+
+static struct clk *clk_epllref_sources[] = {
+       [0] = &clk_mpllref,
+       [1] = &clk_mpllref,
+       [2] = &clk_xtal,
+       [3] = &clk_ext,
+};
+
+struct clksrc_clk clk_epllref = {
+       .clk    = {
+               .name           = "epllref",
+               .id             = -1,
+       },
+       .sources = &(struct clksrc_sources) {
+               .sources = clk_epllref_sources,
+               .nr_sources = ARRAY_SIZE(clk_epllref_sources),
+       },
+       .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 7 },
+};
+
+/* esysclk
+ *
+ * this is sourced from either the EPLL or the EPLLref clock
+*/
+
+static struct clk *clk_sysclk_sources[] = {
+       [0] = &clk_epllref.clk,
+       [1] = &clk_epll,
+};
+
+struct clksrc_clk clk_esysclk = {
+       .clk    = {
+               .name           = "esysclk",
+               .parent         = &clk_epll,
+               .id             = -1,
+       },
+       .sources = &(struct clksrc_sources) {
+               .sources = clk_sysclk_sources,
+               .nr_sources = ARRAY_SIZE(clk_sysclk_sources),
+       },
+       .reg_src = { .reg = S3C2443_CLKSRC, .size = 1, .shift = 6 },
+};
+
+static unsigned long s3c2443_getrate_mdivclk(struct clk *clk)
+{
+       unsigned long parent_rate = clk_get_rate(clk->parent);
+       unsigned long div = __raw_readl(S3C2443_CLKDIV0);
+
+       div  &= S3C2443_CLKDIV0_EXTDIV_MASK;
+       div >>= (S3C2443_CLKDIV0_EXTDIV_SHIFT-1);       /* x2 */
+
+       return parent_rate / (div + 1);
+}
+
+static struct clk clk_mdivclk = {
+       .name           = "mdivclk",
+       .parent         = &clk_mpllref,
+       .id             = -1,
+       .ops            = &(struct clk_ops) {
+               .get_rate       = s3c2443_getrate_mdivclk,
+       },
+};
+
+static struct clk *clk_msysclk_sources[] = {
+       [0] = &clk_mpllref,
+       [1] = &clk_mpll,
+       [2] = &clk_mdivclk,
+       [3] = &clk_mpllref,
+};
+
+struct clksrc_clk clk_msysclk = {
+       .clk    = {
+               .name           = "msysclk",
+               .parent         = &clk_xtal,
+               .id             = -1,
+       },
+       .sources = &(struct clksrc_sources) {
+               .sources = clk_msysclk_sources,
+               .nr_sources = ARRAY_SIZE(clk_msysclk_sources),
+       },
+       .reg_src = { .reg = S3C2443_CLKSRC, .size = 2, .shift = 3 },
+};
+
+/* prediv
+ *
+ * this divides the msysclk down to pass to h/p/etc.
+ */
+
+static unsigned long s3c2443_prediv_getrate(struct clk *clk)
+{
+       unsigned long rate = clk_get_rate(clk->parent);
+       unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
+
+       clkdiv0 &= S3C2443_CLKDIV0_PREDIV_MASK;
+       clkdiv0 >>= S3C2443_CLKDIV0_PREDIV_SHIFT;
+
+       return rate / (clkdiv0 + 1);
+}
+
+static struct clk clk_prediv = {
+       .name           = "prediv",
+       .id             = -1,
+       .parent         = &clk_msysclk.clk,
+       .ops            = &(struct clk_ops) {
+               .get_rate       = s3c2443_prediv_getrate,
+       },
+};
+
+/* usbhost
+ *
+ * usb host bus-clock, usually 48MHz to provide USB bus clock timing
+*/
+
+static struct clksrc_clk clk_usb_bus_host = {
+       .clk    = {
+               .name           = "usb-bus-host-parent",
+               .id             = -1,
+               .parent         = &clk_esysclk.clk,
+               .ctrlbit        = S3C2443_SCLKCON_USBHOST,
+               .enable         = s3c2443_clkcon_enable_s,
+       },
+       .reg_div = { .reg = S3C2443_CLKDIV1, .size = 2, .shift = 4 },
+};
+
+/* common clksrc clocks */
+
+static struct clksrc_clk clksrc_clks[] = {
+       {
+               /* ART baud-rate clock sourced from esysclk via a divisor */
+               .clk    = {
+                       .name           = "uartclk",
+                       .id             = -1,
+                       .parent         = &clk_esysclk.clk,
+               },
+               .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 8 },
+       }, {
+               /* camera interface bus-clock, divided down from esysclk */
+               .clk    = {
+                       .name           = "camif-upll", /* same as 2440 name */
+                       .id             = -1,
+                       .parent         = &clk_esysclk.clk,
+                       .ctrlbit        = S3C2443_SCLKCON_CAMCLK,
+                       .enable         = s3c2443_clkcon_enable_s,
+               },
+               .reg_div = { .reg = S3C2443_CLKDIV1, .size = 4, .shift = 26 },
+       }, {
+               .clk    = {
+                       .name           = "display-if",
+                       .id             = -1,
+                       .parent         = &clk_esysclk.clk,
+                       .ctrlbit        = S3C2443_SCLKCON_DISPCLK,
+                       .enable         = s3c2443_clkcon_enable_s,
+               },
+               .reg_div = { .reg = S3C2443_CLKDIV1, .size = 8, .shift = 16 },
+       },
+};
+
+
+static struct clk init_clocks_off[] = {
+       {
+               .name           = "adc",
+               .id             = -1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_ADC,
+       }, {
+               .name           = "i2c",
+               .id             = -1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_IIC,
+       }
+};
+
+static struct clk init_clocks[] = {
+       {
+               .name           = "dma",
+               .id             = 0,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA0,
+       }, {
+               .name           = "dma",
+               .id             = 1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA1,
+       }, {
+               .name           = "dma",
+               .id             = 2,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA2,
+       }, {
+               .name           = "dma",
+               .id             = 3,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA3,
+       }, {
+               .name           = "dma",
+               .id             = 4,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA4,
+       }, {
+               .name           = "dma",
+               .id             = 5,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_DMA5,
+       }, {
+               .name           = "hsmmc",
+               .id             = 0,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_HSMMC,
+       }, {
+               .name           = "gpio",
+               .id             = -1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_GPIO,
+       }, {
+               .name           = "usb-host",
+               .id             = -1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_USBH,
+       }, {
+               .name           = "usb-device",
+               .id             = -1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_USBD,
+       }, {
+               .name           = "lcd",
+               .id             = -1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_LCDC,
+
+       }, {
+               .name           = "timers",
+               .id             = -1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_PWMT,
+       }, {
+               .name           = "cfc",
+               .id             = -1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_CFC,
+       }, {
+               .name           = "ssmc",
+               .id             = -1,
+               .parent         = &clk_h,
+               .enable         = s3c2443_clkcon_enable_h,
+               .ctrlbit        = S3C2443_HCLKCON_SSMC,
+       }, {
+               .name           = "uart",
+               .id             = 0,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_UART0,
+       }, {
+               .name           = "uart",
+               .id             = 1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_UART1,
+       }, {
+               .name           = "uart",
+               .id             = 2,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_UART2,
+       }, {
+               .name           = "uart",
+               .id             = 3,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_UART3,
+       }, {
+               .name           = "rtc",
+               .id             = -1,
+               .parent         = &clk_p,
+               .enable         = s3c2443_clkcon_enable_p,
+               .ctrlbit        = S3C2443_PCLKCON_RTC,
+       }, {
+               .name           = "watchdog",
+               .id             = -1,
+               .parent         = &clk_p,
+               .ctrlbit        = S3C2443_PCLKCON_WDT,
+       }, {
+               .name           = "ac97",
+               .id             = -1,
+               .parent         = &clk_p,
+               .ctrlbit        = S3C2443_PCLKCON_AC97,
+       }, {
+               .name           = "nand",
+               .id             = -1,
+               .parent         = &clk_h,
+       }, {
+               .name           = "usb-bus-host",
+               .id             = -1,
+               .parent         = &clk_usb_bus_host.clk,
+       }
+};
+
+static inline unsigned long s3c2443_get_hdiv(unsigned long clkcon0)
+{
+       clkcon0 &= S3C2443_CLKDIV0_HCLKDIV_MASK;
+
+       return clkcon0 + 1;
+}
+
+/* EPLLCON compatible enough to get on/off information */
+
+void __init_or_cpufreq s3c2443_common_setup_clocks(pll_fn get_mpll,
+                                                  fdiv_fn get_fdiv)
+{
+       unsigned long epllcon = __raw_readl(S3C2443_EPLLCON);
+       unsigned long mpllcon = __raw_readl(S3C2443_MPLLCON);
+       unsigned long clkdiv0 = __raw_readl(S3C2443_CLKDIV0);
+       struct clk *xtal_clk;
+       unsigned long xtal;
+       unsigned long pll;
+       unsigned long fclk;
+       unsigned long hclk;
+       unsigned long pclk;
+       int ptr;
+
+       xtal_clk = clk_get(NULL, "xtal");
+       xtal = clk_get_rate(xtal_clk);
+       clk_put(xtal_clk);
+
+       pll = get_mpll(mpllcon, xtal);
+       clk_msysclk.clk.rate = pll;
+
+       fclk = pll / get_fdiv(clkdiv0);
+       hclk = s3c2443_prediv_getrate(&clk_prediv);
+       hclk /= s3c2443_get_hdiv(clkdiv0);
+       pclk = hclk / ((clkdiv0 & S3C2443_CLKDIV0_HALF_PCLK) ? 2 : 1);
+
+       s3c24xx_setup_clocks(fclk, hclk, pclk);
+
+       printk("CPU: MPLL %s %ld.%03ld MHz, cpu %ld.%03ld MHz, mem %ld.%03ld MHz, pclk %ld.%03ld MHz\n",
+              (mpllcon & S3C2443_PLLCON_OFF) ? "off":"on",
+              print_mhz(pll), print_mhz(fclk),
+              print_mhz(hclk), print_mhz(pclk));
+
+       for (ptr = 0; ptr < ARRAY_SIZE(clksrc_clks); ptr++)
+               s3c_set_clksrc(&clksrc_clks[ptr], true);
+
+       /* ensure usb bus clock is within correct rate of 48MHz */
+
+       if (clk_get_rate(&clk_usb_bus_host.clk) != (48 * 1000 * 1000)) {
+               printk(KERN_INFO "Warning: USB host bus not at 48MHz\n");
+               clk_set_rate(&clk_usb_bus_host.clk, 48*1000*1000);
+       }
+
+       printk("CPU: EPLL %s %ld.%03ld MHz, usb-bus %ld.%03ld MHz\n",
+              (epllcon & S3C2443_PLLCON_OFF) ? "off":"on",
+              print_mhz(clk_get_rate(&clk_epll)),
+              print_mhz(clk_get_rate(&clk_usb_bus)));
+}
+
+static struct clk *clks[] __initdata = {
+       &clk_prediv,
+       &clk_mpllref,
+       &clk_mdivclk,
+       &clk_ext,
+       &clk_epll,
+       &clk_usb_bus,
+};
+
+static struct clksrc_clk *clksrcs[] __initdata = {
+       &clk_usb_bus_host,
+       &clk_epllref,
+       &clk_esysclk,
+       &clk_msysclk,
+};
+
+void __init s3c2443_common_init_clocks(int xtal, pll_fn get_mpll,
+                                      fdiv_fn get_fdiv)
+{
+       int ptr;
+
+       /* s3c2443 parents h and p clocks from prediv */
+       clk_h.parent = &clk_prediv;
+       clk_p.parent = &clk_prediv;
+
+       clk_usb_bus.parent = &clk_usb_bus_host.clk;
+       clk_epll.parent = &clk_epllref.clk;
+
+       s3c24xx_register_baseclocks(xtal);
+       s3c24xx_register_clocks(clks, ARRAY_SIZE(clks));
+
+       for (ptr = 0; ptr < ARRAY_SIZE(clksrcs); ptr++)
+               s3c_register_clksrc(clksrcs[ptr], 1);
+
+       s3c_register_clksrc(clksrc_clks, ARRAY_SIZE(clksrc_clks));
+       s3c_register_clocks(init_clocks, ARRAY_SIZE(init_clocks));
+
+       /* See s3c2443/etc notes on disabling clocks at init time */
+       s3c_register_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
+       s3c_disable_clocks(init_clocks_off, ARRAY_SIZE(init_clocks_off));
+
+       s3c2443_common_setup_clocks(get_mpll, get_fdiv);
+}
index 71a6acc..9e90a7c 100644 (file)
 
 struct platform_device;
 
+#include <plat/gpio-cfg.h>
 #include <plat/iic.h>
 #include <mach/hardware.h>
 #include <mach/regs-gpio.h>
 
 void s3c_i2c0_cfg_gpio(struct platform_device *dev)
 {
-       s3c2410_gpio_cfgpin(S3C2410_GPE(15), S3C2410_GPE15_IICSDA);
-       s3c2410_gpio_cfgpin(S3C2410_GPE(14), S3C2410_GPE14_IICSCL);
+       s3c_gpio_cfgpin(S3C2410_GPE(15), S3C2410_GPE15_IICSDA);
+       s3c_gpio_cfgpin(S3C2410_GPE(14), S3C2410_GPE14_IICSCL);
 }
diff --git a/arch/arm/plat-s3c24xx/setup-ts.c b/arch/arm/plat-s3c24xx/setup-ts.c
new file mode 100644 (file)
index 0000000..ed26386
--- /dev/null
@@ -0,0 +1,34 @@
+/* linux/arch/arm/plat-s3c24xx/setup-ts.c
+ *
+ * Copyright (c) 2010 Samsung Electronics Co., Ltd.
+ *                     http://www.samsung.com/
+ *
+ * Based on S3C24XX setup for i2c device
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/gpio.h>
+
+struct platform_device; /* don't need the contents */
+
+#include <mach/hardware.h>
+#include <mach/regs-gpio.h>
+
+/**
+ * s3c24xx_ts_cfg_gpio - configure gpio for s3c2410 systems
+ *
+ * Configure the GPIO for the S3C2410 system, where we have external FETs
+ * connected to the device (later systems such as the S3C2440 integrate
+ * these into the device).
+ */
+void s3c24xx_ts_cfg_gpio(struct platform_device *dev)
+{
+       s3c2410_gpio_cfgpin(S3C2410_GPG(12), S3C2410_GPG12_XMON);
+       s3c2410_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPG13_nXPON);
+       s3c2410_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPG14_YMON);
+       s3c2410_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPG15_nYPON);
+}
index da7a617..9793544 100644 (file)
@@ -21,16 +21,16 @@ void s3c24xx_spi_gpiocfg_bus0_gpe11_12_13(struct s3c2410_spi_info *spi,
                                          int enable)
 {
        if (enable) {
-               s3c2410_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPE13_SPICLK0);
-               s3c2410_gpio_cfgpin(S3C2410_GPE(12), S3C2410_GPE12_SPIMOSI0);
-               s3c2410_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPE11_SPIMISO0);
+               s3c_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPE13_SPICLK0);
+               s3c_gpio_cfgpin(S3C2410_GPE(12), S3C2410_GPE12_SPIMOSI0);
+               s3c_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPE11_SPIMISO0);
                s3c2410_gpio_pullup(S3C2410_GPE(11), 0);
                s3c2410_gpio_pullup(S3C2410_GPE(13), 0);
        } else {
-               s3c2410_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_pullup(S3C2410_GPE(11), 1);
-               s3c2410_gpio_pullup(S3C2410_GPE(12), 1);
-               s3c2410_gpio_pullup(S3C2410_GPE(13), 1);
+               s3c_gpio_cfgpin(S3C2410_GPE(13), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpin(S3C2410_GPE(11), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpull(S3C2410_GPE(11), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPE(12), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPE(13), S3C_GPIO_PULL_NONE);
        }
 }
index 89fcf53..db9e9e4 100644 (file)
@@ -23,16 +23,16 @@ void s3c24xx_spi_gpiocfg_bus1_gpd8_9_10(struct s3c2410_spi_info *spi,
 
        printk(KERN_INFO "%s(%d)\n", __func__, enable);
        if (enable) {
-               s3c2410_gpio_cfgpin(S3C2410_GPD(10), S3C2440_GPD10_SPICLK1);
-               s3c2410_gpio_cfgpin(S3C2410_GPD(9), S3C2440_GPD9_SPIMOSI1);
-               s3c2410_gpio_cfgpin(S3C2410_GPD(8), S3C2440_GPD8_SPIMISO1);
+               s3c_gpio_cfgpin(S3C2410_GPD(10), S3C2440_GPD10_SPICLK1);
+               s3c_gpio_cfgpin(S3C2410_GPD(9), S3C2440_GPD9_SPIMOSI1);
+               s3c_gpio_cfgpin(S3C2410_GPD(8), S3C2440_GPD8_SPIMISO1);
                s3c2410_gpio_pullup(S3C2410_GPD(10), 0);
                s3c2410_gpio_pullup(S3C2410_GPD(9), 0);
        } else {
-               s3c2410_gpio_cfgpin(S3C2410_GPD(8), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_cfgpin(S3C2410_GPD(9), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_pullup(S3C2410_GPD(10), 1);
-               s3c2410_gpio_pullup(S3C2410_GPD(9), 1);
-               s3c2410_gpio_pullup(S3C2410_GPD(8), 1);
+               s3c_gpio_cfgpin(S3C2410_GPD(8), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpin(S3C2410_GPD(9), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpull(S3C2410_GPD(10), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPD(9), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPD(8), S3C_GPIO_PULL_NONE);
        }
 }
index 86b9edc..8ea663a 100644 (file)
@@ -21,16 +21,16 @@ void s3c24xx_spi_gpiocfg_bus1_gpg5_6_7(struct s3c2410_spi_info *spi,
                                       int enable)
 {
        if (enable) {
-               s3c2410_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPG7_SPICLK1);
-               s3c2410_gpio_cfgpin(S3C2410_GPG(6), S3C2410_GPG6_SPIMOSI1);
-               s3c2410_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPG5_SPIMISO1);
+               s3c_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPG7_SPICLK1);
+               s3c_gpio_cfgpin(S3C2410_GPG(6), S3C2410_GPG6_SPIMOSI1);
+               s3c_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPG5_SPIMISO1);
                s3c2410_gpio_pullup(S3C2410_GPG(5), 0);
                s3c2410_gpio_pullup(S3C2410_GPG(6), 0);
        } else {
-               s3c2410_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPIO_INPUT);
-               s3c2410_gpio_pullup(S3C2410_GPG(5), 1);
-               s3c2410_gpio_pullup(S3C2410_GPG(6), 1);
-               s3c2410_gpio_pullup(S3C2410_GPG(7), 1);
+               s3c_gpio_cfgpin(S3C2410_GPG(7), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpin(S3C2410_GPG(5), S3C2410_GPIO_INPUT);
+               s3c_gpio_cfgpull(S3C2410_GPG(5), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPG(6), S3C_GPIO_PULL_NONE);
+               s3c_gpio_cfgpull(S3C2410_GPG(7), S3C_GPIO_PULL_NONE);
        }
 }
index d400a6a..92bd756 100644 (file)
@@ -13,6 +13,7 @@ config PLAT_S5P
        select NO_IOPORT
        select ARCH_REQUIRE_GPIOLIB
        select S3C_GPIO_TRACK
+       select S5P_GPIO_DRVSTR
        select SAMSUNG_GPIOLIB_4BIT
        select S3C_GPIO_CFG_S3C64XX
        select S3C_GPIO_PULL_UPDOWN
index a7c54b3..0ec09a9 100644 (file)
@@ -16,4 +16,3 @@ obj-y                         += dev-uart.o
 obj-y                          += cpu.o
 obj-y                          += clock.o
 obj-y                          += irq.o
-obj-y                          += setup-i2c0.o
index aa96e33..24a931f 100644 (file)
@@ -33,7 +33,12 @@ struct clk clk_ext_xtal_mux = {
        .id             = -1,
 };
 
-static struct clk s5p_clk_27m = {
+struct clk clk_xusbxti = {
+       .name           = "xusbxti",
+       .id             = -1,
+};
+
+struct clk s5p_clk_27m = {
        .name           = "clk_27m",
        .id             = -1,
        .rate           = 27000000,
@@ -69,6 +74,13 @@ struct clk clk_fout_epll = {
        .ctrlbit        = (1 << 31),
 };
 
+/* VPLL clock output */
+struct clk clk_fout_vpll = {
+       .name           = "fout_vpll",
+       .id             = -1,
+       .ctrlbit        = (1 << 31),
+};
+
 /* ARM clock */
 struct clk clk_arm = {
        .name           = "armclk",
@@ -133,6 +145,7 @@ static struct clk *s5p_clks[] __initdata = {
        &clk_fout_apll,
        &clk_fout_mpll,
        &clk_fout_epll,
+       &clk_fout_vpll,
        &clk_arm,
        &clk_vpll,
 };
index 42e757f..9ff3d71 100644 (file)
@@ -79,7 +79,7 @@
 #define S5P_IRQ_VIC2(x)                (S5P_VIC2_BASE + (x))
 #define S5P_IRQ_VIC3(x)                (S5P_VIC3_BASE + (x))
 
-#define S5P_TIMER_IRQ(x)       S5P_IRQ(11 + (x))
+#define S5P_TIMER_IRQ(x)       (11 + (x))
 
 #define IRQ_TIMER0             S5P_TIMER_IRQ(0)
 #define IRQ_TIMER1             S5P_TIMER_IRQ(1)
index d48325b..7db3227 100644 (file)
@@ -81,3 +81,25 @@ static inline unsigned long s5p_get_pll90xx(unsigned long baseclk,
 
        return result;
 }
+
+#define PLL65XX_MDIV_MASK      (0x3FF)
+#define PLL65XX_PDIV_MASK      (0x3F)
+#define PLL65XX_SDIV_MASK      (0x7)
+#define PLL65XX_MDIV_SHIFT     (16)
+#define PLL65XX_PDIV_SHIFT     (8)
+#define PLL65XX_SDIV_SHIFT     (0)
+
+static inline unsigned long s5p_get_pll65xx(unsigned long baseclk, u32 pll_con)
+{
+       u32 mdiv, pdiv, sdiv;
+       u64 fvco = baseclk;
+
+       mdiv = (pll_con >> PLL65XX_MDIV_SHIFT) & PLL65XX_MDIV_MASK;
+       pdiv = (pll_con >> PLL65XX_PDIV_SHIFT) & PLL65XX_PDIV_MASK;
+       sdiv = (pll_con >> PLL65XX_SDIV_SHIFT) & PLL65XX_SDIV_MASK;
+
+       fvco *= mdiv;
+       do_div(fvco, (pdiv << sdiv));
+
+       return (unsigned long)fvco;
+}
index 56fb8b4..09418b1 100644 (file)
 #define clk_fin_mpll clk_ext_xtal_mux
 #define clk_fin_epll clk_ext_xtal_mux
 #define clk_fin_vpll clk_ext_xtal_mux
+#define clk_fin_hpll clk_ext_xtal_mux
 
 extern struct clk clk_ext_xtal_mux;
+extern struct clk clk_xusbxti;
 extern struct clk clk_48m;
+extern struct clk s5p_clk_27m;
 extern struct clk clk_fout_apll;
 extern struct clk clk_fout_mpll;
 extern struct clk clk_fout_epll;
+extern struct clk clk_fout_vpll;
 extern struct clk clk_arm;
 extern struct clk clk_vpll;
 
index c7ccdf2..c7bd2bb 100644 (file)
@@ -16,9 +16,10 @@ config PLAT_S5PC1XX
        select SAMSUNG_IRQ_VIC_TIMER
        select S3C_GPIO_TRACK
        select S3C_GPIO_PULL_UPDOWN
+       select S5P_GPIO_DRVSTR
        select S3C_GPIO_CFG_S3C24XX
        select S3C_GPIO_CFG_S3C64XX
-       select S5P_GPIO_CFG_S5PC1XX
+       select SAMSUNG_GPIOLIB_4BIT
        help
          Base platform code for any Samsung S5PC1XX device
 
@@ -38,25 +39,6 @@ config CPU_S5PC100_CLOCK
 
 # platform specific device setup
 
-config S5PC1XX_SETUP_FB_24BPP
-       bool
-       help
-          Common setup code for S5PC1XX with an 24bpp RGB display helper.
-
-config S5PC1XX_SETUP_I2C0
-       bool
-       default y
-       help
-         Common setup code for i2c bus 0.
-
-         Note, currently since i2c0 is always compiled, this setup helper
-         is always compiled with it.
-
-config S5PC1XX_SETUP_I2C1
-       bool
-       help
-         Common setup code for i2c bus 1.
-
 config S5PC1XX_SETUP_SDHCI_GPIO
        bool
        help
index 278f268..9ce6409 100644 (file)
@@ -13,9 +13,8 @@ obj-                          :=
 
 obj-y                          += dev-uart.o
 obj-y                          += cpu.o
-obj-y                          += irq.o irq-gpio.o irq-eint.o
+obj-y                          += irq.o
 obj-y                          += clock.o
-obj-y                          += gpiolib.o
 
 # CPU support
 
@@ -24,8 +23,4 @@ obj-$(CONFIG_CPU_S5PC100_CLOCK)       += s5pc100-clock.o
 
 # Device setup
 
-obj-$(CONFIG_S5P_GPIO_CFG_S5PC1XX) += gpio-config.o
-obj-$(CONFIG_S5PC1XX_SETUP_FB_24BPP) += setup-fb-24bpp.o
-obj-$(CONFIG_S5PC1XX_SETUP_I2C0) += setup-i2c0.o
-obj-$(CONFIG_S5PC1XX_SETUP_I2C1) += setup-i2c1.o
 obj-$(CONFIG_S5PC1XX_SETUP_SDHCI_GPIO) += setup-sdhci-gpio.o
diff --git a/arch/arm/plat-s5pc1xx/gpio-config.c b/arch/arm/plat-s5pc1xx/gpio-config.c
deleted file mode 100644 (file)
index a4f67e8..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/* linux/arch/arm/plat-s5pc1xx/gpio-config.c
- *
- * Copyright 2009 Samsung Electronics
- *
- * S5PC1XX GPIO Configuration.
- *
- * Based on plat-s3c64xx/gpio-config.c
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
-*/
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/gpio.h>
-#include <linux/io.h>
-
-#include <plat/gpio-core.h>
-#include <plat/gpio-cfg-s5pc1xx.h>
-
-s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin, unsigned int off)
-{
-       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
-       void __iomem *reg;
-       int shift = off * 2;
-       u32 drvstr;
-
-       if (!chip)
-               return -EINVAL;
-
-       reg = chip->base + 0x0C;
-
-       drvstr = __raw_readl(reg);
-       drvstr = 0xffff & (0x3 << shift);
-       drvstr = drvstr >> shift;
-
-       return (__force s5p_gpio_drvstr_t)drvstr;
-}
-EXPORT_SYMBOL(s5p_gpio_get_drvstr);
-
-int s5p_gpio_set_drvstr(unsigned int pin, unsigned int off,
-                       s5p_gpio_drvstr_t drvstr)
-{
-       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
-       void __iomem *reg;
-       int shift = off * 2;
-       u32 tmp;
-
-       if (!chip)
-               return -EINVAL;
-
-       reg = chip->base + 0x0C;
-
-       tmp = __raw_readl(reg);
-       tmp |= drvstr << shift;
-
-       __raw_writel(tmp, reg);
-
-       return 0;
-}
-EXPORT_SYMBOL(s5p_gpio_set_drvstr);
diff --git a/arch/arm/plat-s5pc1xx/include/plat/gpio-cfg-s5pc1xx.h b/arch/arm/plat-s5pc1xx/include/plat/gpio-cfg-s5pc1xx.h
deleted file mode 100644 (file)
index 72ad59f..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* linux/arch/arm/plat-s5pc1xx/include/plat/gpio-cfg.h
- *
- * Copyright 2009 Samsung Electronic
- *
- * S5PC1XX Platform - GPIO pin configuration
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
-*/
-
-/* This file contains the necessary definitions to get the basic gpio
- * pin configuration done such as setting a pin to input or output or
- * changing the pull-{up,down} configurations.
- */
-
-#ifndef __GPIO_CFG_S5PC1XX_H
-#define __GPIO_CFG_S5PC1XX_H __FILE__
-
-typedef unsigned int __bitwise__ s5p_gpio_drvstr_t;
-
-#define S5P_GPIO_DRVSTR_LV1    0x00
-#define S5P_GPIO_DRVSTR_LV2    0x01
-#define S5P_GPIO_DRVSTR_LV3    0x10
-#define S5P_GPIO_DRVSTR_LV4    0x11
-
-extern s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin, unsigned int off);
-
-extern int s5p_gpio_set_drvstr(unsigned int pin, unsigned int off,
-                       s5p_gpio_drvstr_t drvstr);
-
-#endif /* __GPIO_CFG_S5PC1XX_H */
index d552c65..229919e 100644 (file)
@@ -90,12 +90,6 @@ config S3C_GPIO_CFG_S3C64XX
          Internal configuration to enable S3C64XX style GPIO configuration
          functions.
 
-config S5P_GPIO_CFG_S5PC1XX
-       bool
-       help
-         Internal configuration to enable S5PC1XX style GPIO configuration
-         functions.
-
 config S3C_GPIO_PULL_UPDOWN
        bool
        help
@@ -111,6 +105,12 @@ config S3C_GPIO_PULL_UP
        help
          Internal configuration to enable the correct GPIO pull helper
 
+config S5P_GPIO_DRVSTR
+       bool
+       help
+         Internal configuration to get and set correct GPIO driver strength
+         helper
+
 config SAMSUNG_GPIO_EXTRA
        int "Number of additional GPIO pins"
        default 0
@@ -160,6 +160,11 @@ config S3C_DEV_HSMMC2
        help
          Compile in platform device definitions for HSMMC channel 2
 
+config S3C_DEV_HWMON
+       bool
+       help
+           Compile in platform device definitions for HWMON
+
 config S3C_DEV_I2C1
        bool
        help
@@ -185,12 +190,27 @@ config S3C_DEV_NAND
        help
          Compile in platform device definition for NAND controller
 
+config S3C_DEV_RTC
+       bool
+       help
+         Complie in platform device definition for RTC
+
+config SAMSUNG_DEV_ADC
+       bool
+       help
+         Compile in platform device definition for ADC controller
+
 config S3C64XX_DEV_SPI
        bool
        help
          Compile in platform device definitions for S3C64XX's type
          SPI controllers.
 
+config SAMSUNG_DEV_TS
+       bool
+       help
+           Common in platform device definitions for touchscreen device
+
 # DMA
 
 config S3C_DMA
@@ -198,6 +218,12 @@ config S3C_DMA
        help
          Internal configuration for S3C DMA core
 
+config S3C_PL330_DMA
+       bool
+       select PL330
+       help
+         S3C DMA API Driver for PL330 DMAC.
+
 comment "Power management"
 
 config SAMSUNG_PM_DEBUG
index 22c89d0..4828849 100644 (file)
@@ -33,6 +33,7 @@ obj-$(CONFIG_S3C_ADC) += adc.o
 obj-$(CONFIG_S3C_DEV_HSMMC)    += dev-hsmmc.o
 obj-$(CONFIG_S3C_DEV_HSMMC1)   += dev-hsmmc1.o
 obj-$(CONFIG_S3C_DEV_HSMMC2)   += dev-hsmmc2.o
+obj-$(CONFIG_S3C_DEV_HWMON)    += dev-hwmon.o
 obj-y                          += dev-i2c0.o
 obj-$(CONFIG_S3C_DEV_I2C1)     += dev-i2c1.o
 obj-$(CONFIG_S3C_DEV_FB)       += dev-fb.o
@@ -40,11 +41,17 @@ obj-y                               += dev-uart.o
 obj-$(CONFIG_S3C_DEV_USB_HOST) += dev-usb.o
 obj-$(CONFIG_S3C_DEV_USB_HSOTG)        += dev-usb-hsotg.o
 obj-$(CONFIG_S3C_DEV_NAND)     += dev-nand.o
+obj-$(CONFIG_S3C_DEV_RTC)      += dev-rtc.o
+
+obj-$(CONFIG_SAMSUNG_DEV_ADC)  += dev-adc.o
+obj-$(CONFIG_SAMSUNG_DEV_TS)   += dev-ts.o
 
 # DMA support
 
 obj-$(CONFIG_S3C_DMA)          += dma.o
 
+obj-$(CONFIG_S3C_PL330_DMA)    += s3c-pl330.o
+
 # PM support
 
 obj-$(CONFIG_PM)               += pm.o
index 1b25c9d..8bf79f3 100644 (file)
@@ -376,6 +376,21 @@ void __init s3c_register_clocks(struct clk *clkp, int nr_clks)
        }
 }
 
+/**
+ * s3c_disable_clocks() - disable an array of clocks
+ * @clkp: Pointer to the first clock in the array.
+ * @nr_clks: Number of clocks to register.
+ *
+ * for internal use only at initialisation time. disable the clocks in the
+ * @clkp array.
+ */
+
+void __init s3c_disable_clocks(struct clk *clkp, int nr_clks)
+{
+       for (; nr_clks > 0; nr_clks--, clkp++)
+               (clkp->enable)(clkp, 0);
+}
+
 /* initalise all the clocks */
 
 int __init s3c24xx_register_baseclocks(unsigned long xtal)
similarity index 86%
rename from arch/arm/mach-s3c64xx/dev-adc.c
rename to arch/arm/plat-samsung/dev-adc.c
index fafef9b..9d903d4 100644 (file)
@@ -1,4 +1,4 @@
-/* linux/arch/arm/plat-s3c64xx/dev-adc.c
+/* linux/arch/arm/plat-samsung/dev-adc.c
  *
  * Copyright 2010 Maurus Cuelenaere
  *
@@ -22,8 +22,8 @@
 
 static struct resource s3c_adc_resource[] = {
        [0] = {
-               .start = S3C64XX_PA_ADC,
-               .end   = S3C64XX_PA_ADC + SZ_256 - 1,
+               .start = SAMSUNG_PA_ADC,
+               .end   = SAMSUNG_PA_ADC + SZ_256 - 1,
                .flags = IORESOURCE_MEM,
        },
        [1] = {
@@ -39,7 +39,7 @@ static struct resource s3c_adc_resource[] = {
 };
 
 struct platform_device s3c_device_adc = {
-       .name           = "s3c64xx-adc",
+       .name           = "samsung-adc",
        .id             = -1,
        .num_resources  = ARRAY_SIZE(s3c_adc_resource),
        .resource       = s3c_adc_resource,
index 002a15f..bf60204 100644 (file)
@@ -19,7 +19,6 @@
 
 #include <mach/irqs.h>
 #include <mach/map.h>
-#include <mach/regs-fb.h>
 
 #include <plat/fb.h>
 #include <plat/devs.h>
diff --git a/arch/arm/plat-samsung/dev-hwmon.c b/arch/arm/plat-samsung/dev-hwmon.c
new file mode 100644 (file)
index 0000000..b3ffb95
--- /dev/null
@@ -0,0 +1,42 @@
+/* linux/arch/arm/plat-samsung/dev-hwmon.c
+ *
+ * Copyright 2008 Simtec Electronics
+ *     Ben Dooks <ben@simtec.co.uk>
+ *     http://armlinux.simtec.co.uk/
+ *
+ * Adapted for HWMON by Maurus Cuelenaere
+ *
+ * Samsung series device definition for HWMON
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+
+#include <plat/devs.h>
+#include <plat/hwmon.h>
+
+struct platform_device s3c_device_hwmon = {
+       .name           = "s3c-hwmon",
+       .id             = -1,
+       .dev.parent     = &s3c_device_adc.dev,
+};
+
+void __init s3c_hwmon_set_platdata(struct s3c_hwmon_pdata *pd)
+{
+       struct s3c_hwmon_pdata *npd;
+
+       if (!pd) {
+               printk(KERN_ERR "%s: no platform data\n", __func__);
+               return;
+       }
+
+       npd = kmemdup(pd, sizeof(struct s3c_hwmon_pdata), GFP_KERNEL);
+       if (!npd)
+               printk(KERN_ERR "%s: no memory for platform data\n", __func__);
+
+       s3c_device_hwmon.dev.platform_data = npd;
+}
similarity index 58%
rename from arch/arm/mach-s3c64xx/dev-rtc.c
rename to arch/arm/plat-samsung/dev-rtc.c
index b9e7a05..bf4e226 100644 (file)
@@ -1,4 +1,4 @@
-/* linux/arch/arm/plat-s3c64xx/dev-rtc.c
+/* linux/arch/arm/plat-samsung/dev-rtc.c
  *
  * Copyright 2009 by Maurus Cuelenaere <mcuelenaere@gmail.com>
  *
 
 static struct resource s3c_rtc_resource[] = {
        [0] = {
-               .start = S3C64XX_PA_RTC,
-               .end   = S3C64XX_PA_RTC + 0xff,
-               .flags = IORESOURCE_MEM,
+               .start  = S3C_PA_RTC,
+               .end    = S3C_PA_RTC + 0xff,
+               .flags  = IORESOURCE_MEM,
        },
        [1] = {
-               .start = IRQ_RTC_ALARM,
-               .end   = IRQ_RTC_ALARM,
-               .flags = IORESOURCE_IRQ,
+               .start  = IRQ_RTC_ALARM,
+               .end    = IRQ_RTC_ALARM,
+               .flags  = IORESOURCE_IRQ,
        },
        [2] = {
-               .start = IRQ_RTC_TIC,
-               .end   = IRQ_RTC_TIC,
-               .flags = IORESOURCE_IRQ
+               .start  = IRQ_RTC_TIC,
+               .end    = IRQ_RTC_TIC,
+               .flags  = IORESOURCE_IRQ
        }
 };
 
 struct platform_device s3c_device_rtc = {
-       .name             = "s3c64xx-rtc",
-       .id               = -1,
-       .num_resources    = ARRAY_SIZE(s3c_rtc_resource),
-       .resource         = s3c_rtc_resource,
+       .name           = "s3c64xx-rtc",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(s3c_rtc_resource),
+       .resource       = s3c_rtc_resource,
 };
 EXPORT_SYMBOL(s3c_device_rtc);
diff --git a/arch/arm/plat-samsung/dev-ts.c b/arch/arm/plat-samsung/dev-ts.c
new file mode 100644 (file)
index 0000000..236ef84
--- /dev/null
@@ -0,0 +1,61 @@
+/* linux/arch/arm/mach-s3c64xx/dev-ts.c
+ *
+ * Copyright (c) 2008 Simtec Electronics
+ *     http://armlinux.simtec.co.uk/
+ *     Ben Dooks <ben@simtec.co.uk>, <ben-linux@fluff.org>
+ *
+ * Adapted by Maurus Cuelenaere for s3c64xx
+ *
+ * S3C64XX series device definition for touchscreen device
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+
+#include <mach/irqs.h>
+#include <mach/map.h>
+
+#include <plat/devs.h>
+#include <plat/ts.h>
+
+static struct resource s3c_ts_resource[] = {
+       [0] = {
+               .start = SAMSUNG_PA_ADC,
+               .end   = SAMSUNG_PA_ADC + SZ_256 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = IRQ_TC,
+               .end   = IRQ_TC,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device s3c_device_ts = {
+       .name           = "s3c64xx-ts",
+       .id             = -1,
+       .num_resources  = ARRAY_SIZE(s3c_ts_resource),
+       .resource       = s3c_ts_resource,
+};
+
+void __init s3c24xx_ts_set_platdata(struct s3c2410_ts_mach_info *pd)
+{
+       struct s3c2410_ts_mach_info *npd;
+
+       if (!pd) {
+               printk(KERN_ERR "%s: no platform data\n", __func__);
+               return;
+       }
+
+       npd = kmemdup(pd, sizeof(struct s3c2410_ts_mach_info), GFP_KERNEL);
+       if (!npd)
+               printk(KERN_ERR "%s: no memory for platform data\n", __func__);
+
+       s3c_device_ts.dev.platform_data = npd;
+}
+EXPORT_SYMBOL(s3c24xx_ts_set_platdata);
index 44a84e8..57b68a5 100644 (file)
@@ -1,7 +1,7 @@
 /* linux/arch/arm/plat-s3c/gpio-config.c
  *
  * Copyright 2008 Openmoko, Inc.
- * Copyright 2008 Simtec Electronics
+ * Copyright 2008-2010 Simtec Electronics
  *     Ben Dooks <ben@simtec.co.uk>
  *     http://armlinux.simtec.co.uk/
  *
@@ -33,14 +33,34 @@ int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
 
        offset = pin - chip->chip.base;
 
-       local_irq_save(flags);
+       s3c_gpio_lock(chip, flags);
        ret = s3c_gpio_do_setcfg(chip, offset, config);
-       local_irq_restore(flags);
+       s3c_gpio_unlock(chip, flags);
 
        return ret;
 }
 EXPORT_SYMBOL(s3c_gpio_cfgpin);
 
+unsigned s3c_gpio_getcfg(unsigned int pin)
+{
+       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
+       unsigned long flags;
+       unsigned ret = 0;
+       int offset;
+
+       if (chip) {
+               offset = pin - chip->chip.base;
+
+               s3c_gpio_lock(chip, flags);
+               ret = s3c_gpio_do_getcfg(chip, offset);
+               s3c_gpio_unlock(chip, flags);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c_gpio_getcfg);
+
+
 int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
 {
        struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
@@ -52,17 +72,17 @@ int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull)
 
        offset = pin - chip->chip.base;
 
-       local_irq_save(flags);
+       s3c_gpio_lock(chip, flags);
        ret = s3c_gpio_do_setpull(chip, offset, pull);
-       local_irq_restore(flags);
+       s3c_gpio_unlock(chip, flags);
 
        return ret;
 }
 EXPORT_SYMBOL(s3c_gpio_setpull);
 
 #ifdef CONFIG_S3C_GPIO_CFG_S3C24XX
-int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip *chip,
-                                 unsigned int off, unsigned int cfg)
+int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
+                             unsigned int off, unsigned int cfg)
 {
        void __iomem *reg = chip->base;
        unsigned int shift = off;
@@ -87,6 +107,19 @@ int s3c_gpio_setcfg_s3c24xx_banka(struct s3c_gpio_chip *chip,
        return 0;
 }
 
+unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
+                                  unsigned int off)
+{
+       u32 con;
+
+       con = __raw_readl(chip->base);
+       con >>= off;
+       con &= 1;
+       con++;
+
+       return S3C_GPIO_SFN(con);
+}
+
 int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
                            unsigned int off, unsigned int cfg)
 {
@@ -109,6 +142,19 @@ int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
 
        return 0;
 }
+
+unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip,
+                                    unsigned int off)
+{
+       u32 con;
+
+       con = __raw_readl(chip->base);
+       con >>= off * 2;
+       con &= 3;
+
+       /* this conversion works for IN and OUT as well as special mode */
+       return S3C_GPIO_SPECIAL(con);
+}
 #endif
 
 #ifdef CONFIG_S3C_GPIO_CFG_S3C64XX
@@ -134,6 +180,25 @@ int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
 
        return 0;
 }
+
+unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
+                                     unsigned int off)
+{
+       void __iomem *reg = chip->base;
+       unsigned int shift = (off & 7) * 4;
+       u32 con;
+
+       if (off < 8 && chip->chip.ngpio > 8)
+               reg -= 4;
+
+       con = __raw_readl(reg);
+       con >>= shift;
+       con &= 0xf;
+
+       /* this conversion works for IN and OUT as well as special mode */
+       return S3C_GPIO_SPECIAL(con);
+}
+
 #endif /* CONFIG_S3C_GPIO_CFG_S3C64XX */
 
 #ifdef CONFIG_S3C_GPIO_PULL_UPDOWN
@@ -164,3 +229,83 @@ s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
        return (__force s3c_gpio_pull_t)pup;
 }
 #endif
+
+#ifdef CONFIG_S3C_GPIO_PULL_UP
+int s3c_gpio_setpull_1up(struct s3c_gpio_chip *chip,
+                        unsigned int off, s3c_gpio_pull_t pull)
+{
+       void __iomem *reg = chip->base + 0x08;
+       u32 pup = __raw_readl(reg);
+
+       pup = __raw_readl(reg);
+
+       if (pup == S3C_GPIO_PULL_UP)
+               pup &= ~(1 << off);
+       else if (pup == S3C_GPIO_PULL_NONE)
+               pup |= (1 << off);
+       else
+               return -EINVAL;
+
+       __raw_writel(pup, reg);
+       return 0;
+}
+
+s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
+                                    unsigned int off)
+{
+       void __iomem *reg = chip->base + 0x08;
+       u32 pup = __raw_readl(reg);
+
+       pup &= (1 << off);
+       return pup ? S3C_GPIO_PULL_NONE : S3C_GPIO_PULL_UP;
+}
+#endif /* CONFIG_S3C_GPIO_PULL_UP */
+
+#ifdef CONFIG_S5P_GPIO_DRVSTR
+s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
+{
+       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
+       unsigned int off;
+       void __iomem *reg;
+       int shift;
+       u32 drvstr;
+
+       if (!chip)
+               return -EINVAL;
+
+       off = chip->chip.base - pin;
+       shift = off * 2;
+       reg = chip->base + 0x0C;
+
+       drvstr = __raw_readl(reg);
+       drvstr = 0xffff & (0x3 << shift);
+       drvstr = drvstr >> shift;
+
+       return (__force s5p_gpio_drvstr_t)drvstr;
+}
+EXPORT_SYMBOL(s5p_gpio_get_drvstr);
+
+int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
+{
+       struct s3c_gpio_chip *chip = s3c_gpiolib_getchip(pin);
+       unsigned int off;
+       void __iomem *reg;
+       int shift;
+       u32 tmp;
+
+       if (!chip)
+               return -EINVAL;
+
+       off = chip->chip.base - pin;
+       shift = off * 2;
+       reg = chip->base + 0x0C;
+
+       tmp = __raw_readl(reg);
+       tmp |= drvstr << shift;
+
+       __raw_writel(tmp, reg);
+
+       return 0;
+}
+EXPORT_SYMBOL(s5p_gpio_set_drvstr);
+#endif /* CONFIG_S5P_GPIO_DRVSTR */
index 28d2ab8..b83a833 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/init.h>
 #include <linux/io.h>
 #include <linux/gpio.h>
+#include <linux/spinlock.h>
 
 #include <plat/gpio-core.h>
 
@@ -52,14 +53,14 @@ static int s3c_gpiolib_input(struct gpio_chip *chip, unsigned offset)
        unsigned long flags;
        unsigned long con;
 
-       local_irq_save(flags);
+       s3c_gpio_lock(ourchip, flags);
 
        con = __raw_readl(base + 0x00);
        con &= ~(3 << (offset * 2));
 
        __raw_writel(con, base + 0x00);
 
-       local_irq_restore(flags);
+       s3c_gpio_unlock(ourchip, flags);
        return 0;
 }
 
@@ -72,7 +73,7 @@ static int s3c_gpiolib_output(struct gpio_chip *chip,
        unsigned long dat;
        unsigned long con;
 
-       local_irq_save(flags);
+       s3c_gpio_lock(ourchip, flags);
 
        dat = __raw_readl(base + 0x04);
        dat &= ~(1 << offset);
@@ -87,7 +88,7 @@ static int s3c_gpiolib_output(struct gpio_chip *chip,
        __raw_writel(con, base + 0x00);
        __raw_writel(dat, base + 0x04);
 
-       local_irq_restore(flags);
+       s3c_gpio_unlock(ourchip, flags);
        return 0;
 }
 
@@ -99,7 +100,7 @@ static void s3c_gpiolib_set(struct gpio_chip *chip,
        unsigned long flags;
        unsigned long dat;
 
-       local_irq_save(flags);
+       s3c_gpio_lock(ourchip, flags);
 
        dat = __raw_readl(base + 0x04);
        dat &= ~(1 << offset);
@@ -107,7 +108,7 @@ static void s3c_gpiolib_set(struct gpio_chip *chip,
                dat |= 1 << offset;
        __raw_writel(dat, base + 0x04);
 
-       local_irq_restore(flags);
+       s3c_gpio_unlock(ourchip, flags);
 }
 
 static int s3c_gpiolib_get(struct gpio_chip *chip, unsigned offset)
@@ -131,6 +132,8 @@ __init void s3c_gpiolib_add(struct s3c_gpio_chip *chip)
        BUG_ON(!gc->label);
        BUG_ON(!gc->ngpio);
 
+       spin_lock_init(&chip->lock);
+
        if (!gc->direction_input)
                gc->direction_input = s3c_gpiolib_input;
        if (!gc->direction_output)
index 60b6269..0fbcd0e 100644 (file)
@@ -74,6 +74,7 @@ extern struct clk clk_ext;
 extern struct clk clk_h2;
 extern struct clk clk_27m;
 extern struct clk clk_48m;
+extern struct clk clk_xusbxti;
 
 extern int clk_default_setrate(struct clk *clk, unsigned long rate);
 extern struct clk_ops clk_ops_def_setrate;
@@ -91,6 +92,7 @@ extern int s3c24xx_register_clock(struct clk *clk);
 extern int s3c24xx_register_clocks(struct clk **clk, int nr_clks);
 
 extern void s3c_register_clocks(struct clk *clk, int nr_clks);
+extern void s3c_disable_clocks(struct clk *clkp, int nr_clks);
 
 extern int s3c24xx_register_baseclocks(unsigned long xtal);
 
index d316b4a..6412933 100644 (file)
@@ -73,11 +73,15 @@ extern struct sys_timer s3c24xx_timer;
 extern struct sysdev_class s3c2410_sysclass;
 extern struct sysdev_class s3c2410a_sysclass;
 extern struct sysdev_class s3c2412_sysclass;
+extern struct sysdev_class s3c2416_sysclass;
 extern struct sysdev_class s3c2440_sysclass;
 extern struct sysdev_class s3c2442_sysclass;
 extern struct sysdev_class s3c2443_sysclass;
 extern struct sysdev_class s3c6410_sysclass;
 extern struct sysdev_class s3c64xx_sysclass;
+extern struct sysdev_class s5p6440_sysclass;
+extern struct sysdev_class s5p6442_sysclass;
+extern struct sysdev_class s5pv210_sysclass;
 
 extern void (*s5pc1xx_idle)(void);
 
index 796d242..ef69e56 100644 (file)
@@ -64,6 +64,22 @@ extern struct platform_device s3c_device_nand;
 extern struct platform_device s3c_device_usbgadget;
 extern struct platform_device s3c_device_usb_hsotg;
 
+extern struct platform_device s5pv210_device_ac97;
+extern struct platform_device s5pv210_device_pcm0;
+extern struct platform_device s5pv210_device_pcm1;
+extern struct platform_device s5pv210_device_pcm2;
+extern struct platform_device s5pv210_device_iis0;
+extern struct platform_device s5pv210_device_iis1;
+extern struct platform_device s5pv210_device_iis2;
+
+extern struct platform_device s5p6442_device_pcm0;
+extern struct platform_device s5p6442_device_pcm1;
+extern struct platform_device s5p6442_device_iis0;
+extern struct platform_device s5p6442_device_iis1;
+
+extern struct platform_device s5p6440_device_pcm;
+extern struct platform_device s5p6440_device_iis;
+
 /* s3c2440 specific devices */
 
 #ifdef CONFIG_CPU_S3C2440
index 7584d75..2e8f8c6 100644 (file)
@@ -110,8 +110,8 @@ extern int s3c2410_dma_config(unsigned int channel, int xferunit);
  * configure the device we're talking to
 */
 
-extern int s3c2410_dma_devconfig(int channel, enum s3c2410_dmasrc source,
-                                unsigned long devaddr);
+extern int s3c2410_dma_devconfig(unsigned int channel,
+               enum s3c2410_dmasrc source, unsigned long devaddr);
 
 /* s3c2410_dma_getposition
  *
index ffc01a7..1f85649 100644 (file)
 #ifndef __PLAT_S3C_FB_H
 #define __PLAT_S3C_FB_H __FILE__
 
+/* S3C_FB_MAX_WIN
+ * Set to the maximum number of windows that any of the supported hardware
+ * can use. Since the platform data uses this for an array size, having it
+ * set to the maximum of any version of the hardware can do is safe.
+ */
+#define S3C_FB_MAX_WIN (5)
+
 /**
  * struct s3c_fb_pd_win - per window setup data
  * @win_mode: The display parameters to initialise (not for window 0)
index dda19da..3e21c75 100644 (file)
@@ -30,6 +30,12 @@ static inline int s3c_gpio_do_setcfg(struct s3c_gpio_chip *chip,
        return (chip->config->set_config)(chip, off, config);
 }
 
+static inline unsigned s3c_gpio_do_getcfg(struct s3c_gpio_chip *chip,
+                                         unsigned int off)
+{
+       return (chip->config->get_config)(chip, off);
+}
+
 static inline int s3c_gpio_do_setpull(struct s3c_gpio_chip *chip,
                                      unsigned int off, s3c_gpio_pull_t pull)
 {
@@ -52,6 +58,18 @@ static inline int s3c_gpio_do_setpull(struct s3c_gpio_chip *chip,
 extern int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
                                   unsigned int off, unsigned int cfg);
 
+/**
+ * s3c_gpio_getcfg_s3c24xx - S3C24XX style GPIO configuration read.
+ * @chip: The gpio chip that is being configured.
+ * @off: The offset for the GPIO being configured.
+ *
+ * The reverse of s3c_gpio_setcfg_s3c24xx(). Will return a value whicg
+ * could be directly passed back to s3c_gpio_setcfg_s3c24xx(), from the
+ * S3C_GPIO_SPECIAL() macro.
+ */
+unsigned int s3c_gpio_getcfg_s3c24xx(struct s3c_gpio_chip *chip,
+                                    unsigned int off);
+
 /**
  * s3c_gpio_setcfg_s3c24xx_a - S3C24XX style GPIO configuration (Bank A)
  * @chip: The gpio chip that is being configured.
@@ -65,6 +83,21 @@ extern int s3c_gpio_setcfg_s3c24xx(struct s3c_gpio_chip *chip,
 extern int s3c_gpio_setcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
                                     unsigned int off, unsigned int cfg);
 
+
+/**
+ * s3c_gpio_getcfg_s3c24xx_a - S3C24XX style GPIO configuration read (Bank A)
+ * @chip: The gpio chip that is being configured.
+ * @off: The offset for the GPIO being configured.
+ *
+ * The reverse of s3c_gpio_setcfg_s3c24xx_a() turning an GPIO into a usable
+ * GPIO configuration value.
+ *
+ * @sa s3c_gpio_getcfg_s3c24xx
+ * @sa s3c_gpio_getcfg_s3c64xx_4bit
+ */
+extern unsigned s3c_gpio_getcfg_s3c24xx_a(struct s3c_gpio_chip *chip,
+                                         unsigned int off);
+
 /**
  * s3c_gpio_setcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config.
  * @chip: The gpio chip that is being configured.
@@ -85,6 +118,20 @@ extern int s3c_gpio_setcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
                                        unsigned int off, unsigned int cfg);
 
 
+/**
+ * s3c_gpio_getcfg_s3c64xx_4bit - S3C64XX 4bit single register GPIO config read.
+ * @chip: The gpio chip that is being configured.
+ * @off: The offset for the GPIO being configured.
+ *
+ * The reverse of s3c_gpio_setcfg_s3c64xx_4bit(), turning a gpio configuration
+ * register setting into a value the software can use, such as could be passed
+ * to s3c_gpio_setcfg_s3c64xx_4bit().
+ *
+ * @sa s3c_gpio_getcfg_s3c24xx
+ */
+extern unsigned s3c_gpio_getcfg_s3c64xx_4bit(struct s3c_gpio_chip *chip,
+                                            unsigned int off);
+
 /* Pull-{up,down} resistor controls.
  *
  * S3C2410,S3C2440,S3C24A0 = Pull-UP,
@@ -145,6 +192,17 @@ extern int s3c_gpio_setpull_updown(struct s3c_gpio_chip *chip,
 extern s3c_gpio_pull_t s3c_gpio_getpull_updown(struct s3c_gpio_chip *chip,
                                               unsigned int off);
 
+/**
+ * s3c_gpio_getpull_1up() - Get configuration for choice of up or none
+ * @chip: The gpio chip that the GPIO pin belongs to
+ * @off: The offset to the pin to get the configuration of.
+ *
+ * This helper function reads the state of the pull-up resistor for the
+ * given GPIO in the same case as s3c_gpio_setpull_1up.
+*/
+extern s3c_gpio_pull_t s3c_gpio_getpull_1up(struct s3c_gpio_chip *chip,
+                                           unsigned int off);
+
 /**
  * s3c_gpio_setpull_s3c2443() - Pull configuration for s3c2443.
  * @chip: The gpio chip that is being configured.
index 29cd6a8..34efdd2 100644 (file)
@@ -25,6 +25,7 @@
 #define __PLAT_GPIO_CFG_H __FILE__
 
 typedef unsigned int __bitwise__ s3c_gpio_pull_t;
+typedef unsigned int __bitwise__ s5p_gpio_drvstr_t;
 
 /* forward declaration if gpio-core.h hasn't been included */
 struct s3c_gpio_chip;
@@ -77,6 +78,17 @@ struct s3c_gpio_cfg {
  */
 extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
 
+/**
+ * s3c_gpio_getcfg - Read the current function for a GPIO pin
+ * @pin: The pin to read the configuration value for.
+ *
+ * Read the configuration state of the given @pin, returning a value that
+ * could be passed back to s3c_gpio_cfgpin().
+ *
+ * @sa s3c_gpio_cfgpin
+ */
+extern unsigned s3c_gpio_getcfg(unsigned int pin);
+
 /* Define values for the pull-{up,down} available for each gpio pin.
  *
  * These values control the state of the weak pull-{up,down} resistors
@@ -107,4 +119,33 @@ extern int s3c_gpio_setpull(unsigned int pin, s3c_gpio_pull_t pull);
 */
 extern s3c_gpio_pull_t s3c_gpio_getpull(unsigned int pin);
 
+/* Define values for the drvstr available for each gpio pin.
+ *
+ * These values control the value of the output signal driver strength,
+ * configurable on most pins on the S5C series.
+ */
+#define S5P_GPIO_DRVSTR_LV1    ((__force s5p_gpio_drvstr_t)0x00)
+#define S5P_GPIO_DRVSTR_LV2    ((__force s5p_gpio_drvstr_t)0x01)
+#define S5P_GPIO_DRVSTR_LV3    ((__force s5p_gpio_drvstr_t)0x10)
+#define S5P_GPIO_DRVSTR_LV4    ((__force s5p_gpio_drvstr_t)0x11)
+
+/**
+ * s5c_gpio_get_drvstr() - get the driver streght value of a gpio pin
+ * @pin: The pin number to get the settings for
+ *
+ * Read the driver streght value for the specified pin.
+*/
+extern s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin);
+
+/**
+ * s3c_gpio_set_drvstr() - set the driver streght value of a gpio pin
+ * @pin: The pin number to configure the driver streght value
+ * @drvstr: The new value of the driver strength
+ *
+ * This function sets the driver strength value for the specified pin.
+ * It will return 0 if successfull, or a negative error code if the pin
+ * cannot support the requested setting.
+*/
+extern int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr);
+
 #endif /* __PLAT_GPIO_CFG_H */
index 49ff406..e358c7d 100644 (file)
@@ -44,16 +44,26 @@ struct s3c_gpio_cfg;
  * @chip: The chip structure to be exported via gpiolib.
  * @base: The base pointer to the gpio configuration registers.
  * @config: special function and pull-resistor control information.
+ * @lock: Lock for exclusive access to this gpio bank.
  * @pm_save: Save information for suspend/resume support.
  *
  * This wrapper provides the necessary information for the Samsung
  * specific gpios being registered with gpiolib.
+ *
+ * The lock protects each gpio bank from multiple access of the shared
+ * configuration registers, or from reading of data whilst another thread
+ * is writing to the register set.
+ *
+ * Each chip has its own lock to avoid any  contention between different
+ * CPU cores trying to get one lock for different GPIO banks, where each
+ * bank of GPIO has its own register space and configuration registers.
  */
 struct s3c_gpio_chip {
        struct gpio_chip        chip;
        struct s3c_gpio_cfg     *config;
        struct s3c_gpio_pm      *pm;
        void __iomem            *base;
+       spinlock_t               lock;
 #ifdef CONFIG_PM
        u32                     pm_save[4];
 #endif
@@ -97,7 +107,7 @@ extern void s3c_gpiolib_add(struct s3c_gpio_chip *chip);
  * others = Special functions (dependant on bank)
  *
  * Note, since the code to deal with the case where there are two control
- * registers instead of one, we do not have a seperate set of function
+ * registers instead of one, we do not have a separate set of function
  * (samsung_gpiolib_add_4bit2_chips)for each case.
  */
 extern void samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip,
@@ -108,6 +118,9 @@ extern void samsung_gpiolib_add_4bit2_chips(struct s3c_gpio_chip *chip,
 extern void samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip);
 extern void samsung_gpiolib_add_4bit2(struct s3c_gpio_chip *chip);
 
+/* exported for core SoC support to change */
+extern struct s3c_gpio_cfg s3c24xx_gpiocfg_default;
+
 #ifdef CONFIG_S3C_GPIO_TRACK
 extern struct s3c_gpio_chip *s3c_gpios[S3C_GPIO_END];
 
@@ -135,3 +148,7 @@ extern struct s3c_gpio_pm s3c_gpio_pm_4bit;
 #define __gpio_pm(x) NULL
 
 #endif /* CONFIG_PM */
+
+/* locking wrappers to deal with multiple access to the same gpio bank */
+#define s3c_gpio_lock(_oc, _fl) spin_lock_irqsave(&(_oc)->lock, _fl)
+#define s3c_gpio_unlock(_oc, _fl) spin_unlock_irqrestore(&(_oc)->lock, _fl)
index 1ba88ea..c167e44 100644 (file)
@@ -37,5 +37,15 @@ struct s3c_hwmon_pdata {
        struct s3c_hwmon_chcfg  *in[8];
 };
 
+/**
+ * s3c_hwmon_set_platdata - Set platform data for S3C HWMON device
+ * @pd: Platform data to register to device.
+ *
+ * Register the given platform data for use with the S3C HWMON device.
+ * The call will copy the platform data, so the board definitions can
+ * make the structure itself __initdata.
+ */
+extern void __init s3c_hwmon_set_platdata(struct s3c_hwmon_pdata *pd);
+
 #endif /* __ASM_ARCH_ADC_HWMON_H */
 
diff --git a/arch/arm/plat-samsung/include/plat/pll6553x.h b/arch/arm/plat-samsung/include/plat/pll6553x.h
new file mode 100644 (file)
index 0000000..b8b7e1d
--- /dev/null
@@ -0,0 +1,51 @@
+/* arch/arm/plat-samsung/include/plat/pll6553x.h
+ *     partially from arch/arm/mach-s3c64xx/include/mach/pll.h
+ *
+ * Copyright 2008 Openmoko, Inc.
+ * Copyright 2008 Simtec Electronics
+ *     Ben Dooks <ben@simtec.co.uk>
+ *     http://armlinux.simtec.co.uk/
+ *
+ * Samsung PLL6553x PLL code
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+/* S3C6400 and compatible (S3C2416, etc.) EPLL code */
+
+#define PLL6553X_MDIV_MASK     ((1 << (23-16)) - 1)
+#define PLL6553X_PDIV_MASK     ((1 << (13-8)) - 1)
+#define PLL6553X_SDIV_MASK     ((1 << (2-0)) - 1)
+#define PLL6553X_MDIV_SHIFT    (16)
+#define PLL6553X_PDIV_SHIFT    (8)
+#define PLL6553X_SDIV_SHIFT    (0)
+#define PLL6553X_KDIV_MASK     (0xffff)
+
+static inline unsigned long s3c_get_pll6553x(unsigned long baseclk,
+                                            u32 pll0, u32 pll1)
+{
+       unsigned long result;
+       u32 mdiv, pdiv, sdiv, kdiv;
+       u64 tmp;
+
+       mdiv = (pll0 >> PLL6553X_MDIV_SHIFT) & PLL6553X_MDIV_MASK;
+       pdiv = (pll0 >> PLL6553X_PDIV_SHIFT) & PLL6553X_PDIV_MASK;
+       sdiv = (pll0 >> PLL6553X_SDIV_SHIFT) & PLL6553X_SDIV_MASK;
+       kdiv = pll1 & PLL6553X_KDIV_MASK;
+
+       /* We need to multiple baseclk by mdiv (the integer part) and kdiv
+        * which is in 2^16ths, so shift mdiv up (does not overflow) and
+        * add kdiv before multiplying. The use of tmp is to avoid any
+        * overflows before shifting bac down into result when multipling
+        * by the mdiv and kdiv pair.
+        */
+
+       tmp = baseclk;
+       tmp *= (mdiv << 16) + kdiv;
+       do_div(tmp, (pdiv << sdiv));
+       result = tmp >> 16;
+
+       return result;
+}
diff --git a/arch/arm/plat-samsung/include/plat/s3c-dma-pl330.h b/arch/arm/plat-samsung/include/plat/s3c-dma-pl330.h
new file mode 100644 (file)
index 0000000..5fe6721
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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.
+ */
+
+#ifndef        __S3C_DMA_PL330_H_
+#define        __S3C_DMA_PL330_H_
+
+#define S3C2410_DMAF_AUTOSTART         (1 << 0)
+#define S3C2410_DMAF_CIRCULAR          (1 << 1)
+
+/*
+ * PL330 can assign any channel to communicate with
+ * any of the peripherals attched to the DMAC.
+ * For the sake of consistency across client drivers,
+ * We keep the channel names unchanged and only add
+ * missing peripherals are added.
+ * Order is not important since S3C PL330 API driver
+ * use these just as IDs.
+ */
+enum dma_ch {
+       DMACH_UART0_RX,
+       DMACH_UART0_TX,
+       DMACH_UART1_RX,
+       DMACH_UART1_TX,
+       DMACH_UART2_RX,
+       DMACH_UART2_TX,
+       DMACH_UART3_RX,
+       DMACH_UART3_TX,
+       DMACH_IRDA,
+       DMACH_I2S0_RX,
+       DMACH_I2S0_TX,
+       DMACH_I2S0S_TX,
+       DMACH_I2S1_RX,
+       DMACH_I2S1_TX,
+       DMACH_I2S2_RX,
+       DMACH_I2S2_TX,
+       DMACH_SPI0_RX,
+       DMACH_SPI0_TX,
+       DMACH_SPI1_RX,
+       DMACH_SPI1_TX,
+       DMACH_SPI2_RX,
+       DMACH_SPI2_TX,
+       DMACH_AC97_MICIN,
+       DMACH_AC97_PCMIN,
+       DMACH_AC97_PCMOUT,
+       DMACH_EXTERNAL,
+       DMACH_PWM,
+       DMACH_SPDIF,
+       DMACH_HSI_RX,
+       DMACH_HSI_TX,
+       DMACH_PCM0_TX,
+       DMACH_PCM0_RX,
+       DMACH_PCM1_TX,
+       DMACH_PCM1_RX,
+       DMACH_PCM2_TX,
+       DMACH_PCM2_RX,
+       DMACH_MSM_REQ3,
+       DMACH_MSM_REQ2,
+       DMACH_MSM_REQ1,
+       DMACH_MSM_REQ0,
+       /* END Marker, also used to denote a reserved channel */
+       DMACH_MAX,
+};
+
+static inline bool s3c_dma_has_circular(void)
+{
+       return true;
+}
+
+#include <plat/dma.h>
+
+#endif /* __S3C_DMA_PL330_H_ */
diff --git a/arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h b/arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h
new file mode 100644 (file)
index 0000000..bf5e2a9
--- /dev/null
@@ -0,0 +1,32 @@
+/* linux/arch/arm/plat-samsung/include/plat/s3c-pl330-pdata.h
+ *
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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.
+ */
+
+#ifndef __S3C_PL330_PDATA_H
+#define __S3C_PL330_PDATA_H
+
+#include <plat/s3c-dma-pl330.h>
+
+/*
+ * Every PL330 DMAC has max 32 peripheral interfaces,
+ * of which some may be not be really used in your
+ * DMAC's configuration.
+ * Populate this array of 32 peri i/fs with relevant
+ * channel IDs for used peri i/f and DMACH_MAX for
+ * those unused.
+ *
+ * The platforms just need to provide this info
+ * to the S3C DMA API driver for PL330.
+ */
+struct s3c_pl330_platdata {
+       enum dma_ch peri[32];
+};
+
+#endif /* __S3C_PL330_PDATA_H */
similarity index 72%
rename from arch/arm/mach-s3c2410/include/mach/ts.h
rename to arch/arm/plat-samsung/include/plat/ts.h
index dc36170..26fdb22 100644 (file)
@@ -1,4 +1,4 @@
-/* linux/include/asm/arch-s3c2410/ts.h
+/* arch/arm/plat-samsung/include/plat/ts.h
  *
  * Copyright (c) 2005 Arnaud Patard <arnaud.patard@rtp-net.org>
  *
@@ -14,8 +14,12 @@ struct s3c2410_ts_mach_info {
        int             delay;
        int             presc;
        int             oversampling_shift;
+       void    (*cfg_gpio)(struct platform_device *dev);
 };
 
 extern void s3c24xx_ts_set_platdata(struct s3c2410_ts_mach_info *);
 
+/* defined by architecture to configure gpio */
+extern void s3c24xx_ts_cfg_gpio(struct platform_device *dev);
+
 #endif /* __ASM_ARM_TS_H */
index 69a4c7f..d50ab9d 100644 (file)
@@ -329,7 +329,7 @@ void s3c_pm_save_gpios(void)
        struct s3c_gpio_chip *ourchip;
        unsigned int gpio_nr;
 
-       for (gpio_nr = 0; gpio_nr < S3C_GPIO_END; gpio_nr++) {
+       for (gpio_nr = 0; gpio_nr < S3C_GPIO_END;) {
                ourchip = s3c_gpiolib_getchip(gpio_nr);
                if (!ourchip)
                        continue;
@@ -367,7 +367,7 @@ void s3c_pm_restore_gpios(void)
        struct s3c_gpio_chip *ourchip;
        unsigned int gpio_nr;
 
-       for (gpio_nr = 0; gpio_nr < S3C_GPIO_END; gpio_nr++) {
+       for (gpio_nr = 0; gpio_nr < S3C_GPIO_END;) {
                ourchip = s3c_gpiolib_getchip(gpio_nr);
                if (!ourchip)
                        continue;
diff --git a/arch/arm/plat-samsung/s3c-pl330.c b/arch/arm/plat-samsung/s3c-pl330.c
new file mode 100644 (file)
index 0000000..a91305a
--- /dev/null
@@ -0,0 +1,1224 @@
+/* linux/arch/arm/plat-samsung/s3c-pl330.c
+ *
+ * Copyright (C) 2010 Samsung Electronics Co. Ltd.
+ *     Jaswinder Singh <jassi.brar@samsung.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.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+
+#include <asm/hardware/pl330.h>
+
+#include <plat/s3c-pl330-pdata.h>
+
+/**
+ * struct s3c_pl330_dmac - Logical representation of a PL330 DMAC.
+ * @busy_chan: Number of channels currently busy.
+ * @peri: List of IDs of peripherals this DMAC can work with.
+ * @node: To attach to the global list of DMACs.
+ * @pi: PL330 configuration info for the DMAC.
+ * @kmcache: Pool to quickly allocate xfers for all channels in the dmac.
+ */
+struct s3c_pl330_dmac {
+       unsigned                busy_chan;
+       enum dma_ch             *peri;
+       struct list_head        node;
+       struct pl330_info       *pi;
+       struct kmem_cache       *kmcache;
+};
+
+/**
+ * struct s3c_pl330_xfer - A request submitted by S3C DMA clients.
+ * @token: Xfer ID provided by the client.
+ * @node: To attach to the list of xfers on a channel.
+ * @px: Xfer for PL330 core.
+ * @chan: Owner channel of this xfer.
+ */
+struct s3c_pl330_xfer {
+       void                    *token;
+       struct list_head        node;
+       struct pl330_xfer       px;
+       struct s3c_pl330_chan   *chan;
+};
+
+/**
+ * struct s3c_pl330_chan - Logical channel to communicate with
+ *     a Physical peripheral.
+ * @pl330_chan_id: Token of a hardware channel thread of PL330 DMAC.
+ *     NULL if the channel is available to be acquired.
+ * @id: ID of the peripheral that this channel can communicate with.
+ * @options: Options specified by the client.
+ * @sdaddr: Address provided via s3c2410_dma_devconfig.
+ * @node: To attach to the global list of channels.
+ * @lrq: Pointer to the last submitted pl330_req to PL330 core.
+ * @xfer_list: To manage list of xfers enqueued.
+ * @req: Two requests to communicate with the PL330 engine.
+ * @callback_fn: Callback function to the client.
+ * @rqcfg: Channel configuration for the xfers.
+ * @xfer_head: Pointer to the xfer to be next excecuted.
+ * @dmac: Pointer to the DMAC that manages this channel, NULL if the
+ *     channel is available to be acquired.
+ * @client: Client of this channel. NULL if the
+ *     channel is available to be acquired.
+ */
+struct s3c_pl330_chan {
+       void                            *pl330_chan_id;
+       enum dma_ch                     id;
+       unsigned int                    options;
+       unsigned long                   sdaddr;
+       struct list_head                node;
+       struct pl330_req                *lrq;
+       struct list_head                xfer_list;
+       struct pl330_req                req[2];
+       s3c2410_dma_cbfn_t              callback_fn;
+       struct pl330_reqcfg             rqcfg;
+       struct s3c_pl330_xfer           *xfer_head;
+       struct s3c_pl330_dmac           *dmac;
+       struct s3c2410_dma_client       *client;
+};
+
+/* All DMACs in the platform */
+static LIST_HEAD(dmac_list);
+
+/* All channels to peripherals in the platform */
+static LIST_HEAD(chan_list);
+
+/*
+ * Since we add resources(DMACs and Channels) to the global pool,
+ * we need to guard access to the resources using a global lock
+ */
+static DEFINE_SPINLOCK(res_lock);
+
+/* Returns the channel with ID 'id' in the chan_list */
+static struct s3c_pl330_chan *id_to_chan(const enum dma_ch id)
+{
+       struct s3c_pl330_chan *ch;
+
+       list_for_each_entry(ch, &chan_list, node)
+               if (ch->id == id)
+                       return ch;
+
+       return NULL;
+}
+
+/* Allocate a new channel with ID 'id' and add to chan_list */
+static void chan_add(const enum dma_ch id)
+{
+       struct s3c_pl330_chan *ch = id_to_chan(id);
+
+       /* Return if the channel already exists */
+       if (ch)
+               return;
+
+       ch = kmalloc(sizeof(*ch), GFP_KERNEL);
+       /* Return silently to work with other channels */
+       if (!ch)
+               return;
+
+       ch->id = id;
+       ch->dmac = NULL;
+
+       list_add_tail(&ch->node, &chan_list);
+}
+
+/* If the channel is not yet acquired by any client */
+static bool chan_free(struct s3c_pl330_chan *ch)
+{
+       if (!ch)
+               return false;
+
+       /* Channel points to some DMAC only when it's acquired */
+       return ch->dmac ? false : true;
+}
+
+/*
+ * Returns 0 is peripheral i/f is invalid or not present on the dmac.
+ * Index + 1, otherwise.
+ */
+static unsigned iface_of_dmac(struct s3c_pl330_dmac *dmac, enum dma_ch ch_id)
+{
+       enum dma_ch *id = dmac->peri;
+       int i;
+
+       /* Discount invalid markers */
+       if (ch_id == DMACH_MAX)
+               return 0;
+
+       for (i = 0; i < PL330_MAX_PERI; i++)
+               if (id[i] == ch_id)
+                       return i + 1;
+
+       return 0;
+}
+
+/* If all channel threads of the DMAC are busy */
+static inline bool dmac_busy(struct s3c_pl330_dmac *dmac)
+{
+       struct pl330_info *pi = dmac->pi;
+
+       return (dmac->busy_chan < pi->pcfg.num_chan) ? false : true;
+}
+
+/*
+ * Returns the number of free channels that
+ * can be handled by this dmac only.
+ */
+static unsigned ch_onlyby_dmac(struct s3c_pl330_dmac *dmac)
+{
+       enum dma_ch *id = dmac->peri;
+       struct s3c_pl330_dmac *d;
+       struct s3c_pl330_chan *ch;
+       unsigned found, count = 0;
+       enum dma_ch p;
+       int i;
+
+       for (i = 0; i < PL330_MAX_PERI; i++) {
+               p = id[i];
+               ch = id_to_chan(p);
+
+               if (p == DMACH_MAX || !chan_free(ch))
+                       continue;
+
+               found = 0;
+               list_for_each_entry(d, &dmac_list, node) {
+                       if (d != dmac && iface_of_dmac(d, ch->id)) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found)
+                       count++;
+       }
+
+       return count;
+}
+
+/*
+ * Measure of suitability of 'dmac' handling 'ch'
+ *
+ * 0 indicates 'dmac' can not handle 'ch' either
+ * because it is not supported by the hardware or
+ * because all dmac channels are currently busy.
+ *
+ * >0 vlaue indicates 'dmac' has the capability.
+ * The bigger the value the more suitable the dmac.
+ */
+#define MAX_SUIT       UINT_MAX
+#define MIN_SUIT       0
+
+static unsigned suitablility(struct s3c_pl330_dmac *dmac,
+               struct s3c_pl330_chan *ch)
+{
+       struct pl330_info *pi = dmac->pi;
+       enum dma_ch *id = dmac->peri;
+       struct s3c_pl330_dmac *d;
+       unsigned s;
+       int i;
+
+       s = MIN_SUIT;
+       /* If all the DMAC channel threads are busy */
+       if (dmac_busy(dmac))
+               return s;
+
+       for (i = 0; i < PL330_MAX_PERI; i++)
+               if (id[i] == ch->id)
+                       break;
+
+       /* If the 'dmac' can't talk to 'ch' */
+       if (i == PL330_MAX_PERI)
+               return s;
+
+       s = MAX_SUIT;
+       list_for_each_entry(d, &dmac_list, node) {
+               /*
+                * If some other dmac can talk to this
+                * peri and has some channel free.
+                */
+               if (d != dmac && iface_of_dmac(d, ch->id) && !dmac_busy(d)) {
+                       s = 0;
+                       break;
+               }
+       }
+       if (s)
+               return s;
+
+       s = 100;
+
+       /* Good if free chans are more, bad otherwise */
+       s += (pi->pcfg.num_chan - dmac->busy_chan) - ch_onlyby_dmac(dmac);
+
+       return s;
+}
+
+/* More than one DMAC may have capability to transfer data with the
+ * peripheral. This function assigns most suitable DMAC to manage the
+ * channel and hence communicate with the peripheral.
+ */
+static struct s3c_pl330_dmac *map_chan_to_dmac(struct s3c_pl330_chan *ch)
+{
+       struct s3c_pl330_dmac *d, *dmac = NULL;
+       unsigned sn, sl = MIN_SUIT;
+
+       list_for_each_entry(d, &dmac_list, node) {
+               sn = suitablility(d, ch);
+
+               if (sn == MAX_SUIT)
+                       return d;
+
+               if (sn > sl)
+                       dmac = d;
+       }
+
+       return dmac;
+}
+
+/* Acquire the channel for peripheral 'id' */
+static struct s3c_pl330_chan *chan_acquire(const enum dma_ch id)
+{
+       struct s3c_pl330_chan *ch = id_to_chan(id);
+       struct s3c_pl330_dmac *dmac;
+
+       /* If the channel doesn't exist or is already acquired */
+       if (!ch || !chan_free(ch)) {
+               ch = NULL;
+               goto acq_exit;
+       }
+
+       dmac = map_chan_to_dmac(ch);
+       /* If couldn't map */
+       if (!dmac) {
+               ch = NULL;
+               goto acq_exit;
+       }
+
+       dmac->busy_chan++;
+       ch->dmac = dmac;
+
+acq_exit:
+       return ch;
+}
+
+/* Delete xfer from the queue */
+static inline void del_from_queue(struct s3c_pl330_xfer *xfer)
+{
+       struct s3c_pl330_xfer *t;
+       struct s3c_pl330_chan *ch;
+       int found;
+
+       if (!xfer)
+               return;
+
+       ch = xfer->chan;
+
+       /* Make sure xfer is in the queue */
+       found = 0;
+       list_for_each_entry(t, &ch->xfer_list, node)
+               if (t == xfer) {
+                       found = 1;
+                       break;
+               }
+
+       if (!found)
+               return;
+
+       /* If xfer is last entry in the queue */
+       if (xfer->node.next == &ch->xfer_list)
+               t = list_entry(ch->xfer_list.next,
+                               struct s3c_pl330_xfer, node);
+       else
+               t = list_entry(xfer->node.next,
+                               struct s3c_pl330_xfer, node);
+
+       /* If there was only one node left */
+       if (t == xfer)
+               ch->xfer_head = NULL;
+       else if (ch->xfer_head == xfer)
+               ch->xfer_head = t;
+
+       list_del(&xfer->node);
+}
+
+/* Provides pointer to the next xfer in the queue.
+ * If CIRCULAR option is set, the list is left intact,
+ * otherwise the xfer is removed from the list.
+ * Forced delete 'pluck' can be set to override the CIRCULAR option.
+ */
+static struct s3c_pl330_xfer *get_from_queue(struct s3c_pl330_chan *ch,
+               int pluck)
+{
+       struct s3c_pl330_xfer *xfer = ch->xfer_head;
+
+       if (!xfer)
+               return NULL;
+
+       /* If xfer is last entry in the queue */
+       if (xfer->node.next == &ch->xfer_list)
+               ch->xfer_head = list_entry(ch->xfer_list.next,
+                                       struct s3c_pl330_xfer, node);
+       else
+               ch->xfer_head = list_entry(xfer->node.next,
+                                       struct s3c_pl330_xfer, node);
+
+       if (pluck || !(ch->options & S3C2410_DMAF_CIRCULAR))
+               del_from_queue(xfer);
+
+       return xfer;
+}
+
+static inline void add_to_queue(struct s3c_pl330_chan *ch,
+               struct s3c_pl330_xfer *xfer, int front)
+{
+       struct pl330_xfer *xt;
+
+       /* If queue empty */
+       if (ch->xfer_head == NULL)
+               ch->xfer_head = xfer;
+
+       xt = &ch->xfer_head->px;
+       /* If the head already submitted (CIRCULAR head) */
+       if (ch->options & S3C2410_DMAF_CIRCULAR &&
+               (xt == ch->req[0].x || xt == ch->req[1].x))
+               ch->xfer_head = xfer;
+
+       /* If this is a resubmission, it should go at the head */
+       if (front) {
+               ch->xfer_head = xfer;
+               list_add(&xfer->node, &ch->xfer_list);
+       } else {
+               list_add_tail(&xfer->node, &ch->xfer_list);
+       }
+}
+
+static inline void _finish_off(struct s3c_pl330_xfer *xfer,
+               enum s3c2410_dma_buffresult res, int ffree)
+{
+       struct s3c_pl330_chan *ch;
+
+       if (!xfer)
+               return;
+
+       ch = xfer->chan;
+
+       /* Do callback */
+       if (ch->callback_fn)
+               ch->callback_fn(NULL, xfer->token, xfer->px.bytes, res);
+
+       /* Force Free or if buffer is not needed anymore */
+       if (ffree || !(ch->options & S3C2410_DMAF_CIRCULAR))
+               kmem_cache_free(ch->dmac->kmcache, xfer);
+}
+
+static inline int s3c_pl330_submit(struct s3c_pl330_chan *ch,
+               struct pl330_req *r)
+{
+       struct s3c_pl330_xfer *xfer;
+       int ret = 0;
+
+       /* If already submitted */
+       if (r->x)
+               return 0;
+
+       xfer = get_from_queue(ch, 0);
+       if (xfer) {
+               r->x = &xfer->px;
+
+               /* Use max bandwidth for M<->M xfers */
+               if (r->rqtype == MEMTOMEM) {
+                       struct pl330_info *pi = xfer->chan->dmac->pi;
+                       int burst = 1 << ch->rqcfg.brst_size;
+                       u32 bytes = r->x->bytes;
+                       int bl;
+
+                       bl = pi->pcfg.data_bus_width / 8;
+                       bl *= pi->pcfg.data_buf_dep;
+                       bl /= burst;
+
+                       /* src/dst_burst_len can't be more than 16 */
+                       if (bl > 16)
+                               bl = 16;
+
+                       while (bl > 1) {
+                               if (!(bytes % (bl * burst)))
+                                       break;
+                               bl--;
+                       }
+
+                       ch->rqcfg.brst_len = bl;
+               } else {
+                       ch->rqcfg.brst_len = 1;
+               }
+
+               ret = pl330_submit_req(ch->pl330_chan_id, r);
+
+               /* If submission was successful */
+               if (!ret) {
+                       ch->lrq = r; /* latest submitted req */
+                       return 0;
+               }
+
+               r->x = NULL;
+
+               /* If both of the PL330 ping-pong buffers filled */
+               if (ret == -EAGAIN) {
+                       dev_err(ch->dmac->pi->dev, "%s:%d!\n",
+                               __func__, __LINE__);
+                       /* Queue back again */
+                       add_to_queue(ch, xfer, 1);
+                       ret = 0;
+               } else {
+                       dev_err(ch->dmac->pi->dev, "%s:%d!\n",
+                               __func__, __LINE__);
+                       _finish_off(xfer, S3C2410_RES_ERR, 0);
+               }
+       }
+
+       return ret;
+}
+
+static void s3c_pl330_rq(struct s3c_pl330_chan *ch,
+       struct pl330_req *r, enum pl330_op_err err)
+{
+       unsigned long flags;
+       struct s3c_pl330_xfer *xfer;
+       struct pl330_xfer *xl = r->x;
+       enum s3c2410_dma_buffresult res;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       r->x = NULL;
+
+       s3c_pl330_submit(ch, r);
+
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       /* Map result to S3C DMA API */
+       if (err == PL330_ERR_NONE)
+               res = S3C2410_RES_OK;
+       else if (err == PL330_ERR_ABORT)
+               res = S3C2410_RES_ABORT;
+       else
+               res = S3C2410_RES_ERR;
+
+       /* If last request had some xfer */
+       if (xl) {
+               xfer = container_of(xl, struct s3c_pl330_xfer, px);
+               _finish_off(xfer, res, 0);
+       } else {
+               dev_info(ch->dmac->pi->dev, "%s:%d No Xfer?!\n",
+                       __func__, __LINE__);
+       }
+}
+
+static void s3c_pl330_rq0(void *token, enum pl330_op_err err)
+{
+       struct pl330_req *r = token;
+       struct s3c_pl330_chan *ch = container_of(r,
+                                       struct s3c_pl330_chan, req[0]);
+       s3c_pl330_rq(ch, r, err);
+}
+
+static void s3c_pl330_rq1(void *token, enum pl330_op_err err)
+{
+       struct pl330_req *r = token;
+       struct s3c_pl330_chan *ch = container_of(r,
+                                       struct s3c_pl330_chan, req[1]);
+       s3c_pl330_rq(ch, r, err);
+}
+
+/* Release an acquired channel */
+static void chan_release(struct s3c_pl330_chan *ch)
+{
+       struct s3c_pl330_dmac *dmac;
+
+       if (chan_free(ch))
+               return;
+
+       dmac = ch->dmac;
+       ch->dmac = NULL;
+       dmac->busy_chan--;
+}
+
+int s3c2410_dma_ctrl(enum dma_ch id, enum s3c2410_chan_op op)
+{
+       struct s3c_pl330_xfer *xfer;
+       enum pl330_chan_op pl330op;
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int idx, ret;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch)) {
+               ret = -EINVAL;
+               goto ctrl_exit;
+       }
+
+       switch (op) {
+       case S3C2410_DMAOP_START:
+               /* Make sure both reqs are enqueued */
+               idx = (ch->lrq == &ch->req[0]) ? 1 : 0;
+               s3c_pl330_submit(ch, &ch->req[idx]);
+               s3c_pl330_submit(ch, &ch->req[1 - idx]);
+               pl330op = PL330_OP_START;
+               break;
+
+       case S3C2410_DMAOP_STOP:
+               pl330op = PL330_OP_ABORT;
+               break;
+
+       case S3C2410_DMAOP_FLUSH:
+               pl330op = PL330_OP_FLUSH;
+               break;
+
+       case S3C2410_DMAOP_PAUSE:
+       case S3C2410_DMAOP_RESUME:
+       case S3C2410_DMAOP_TIMEOUT:
+       case S3C2410_DMAOP_STARTED:
+               spin_unlock_irqrestore(&res_lock, flags);
+               return 0;
+
+       default:
+               spin_unlock_irqrestore(&res_lock, flags);
+               return -EINVAL;
+       }
+
+       ret = pl330_chan_ctrl(ch->pl330_chan_id, pl330op);
+
+       if (pl330op == PL330_OP_START) {
+               spin_unlock_irqrestore(&res_lock, flags);
+               return ret;
+       }
+
+       idx = (ch->lrq == &ch->req[0]) ? 1 : 0;
+
+       /* Abort the current xfer */
+       if (ch->req[idx].x) {
+               xfer = container_of(ch->req[idx].x,
+                               struct s3c_pl330_xfer, px);
+
+               /* Drop xfer during FLUSH */
+               if (pl330op == PL330_OP_FLUSH)
+                       del_from_queue(xfer);
+
+               ch->req[idx].x = NULL;
+
+               spin_unlock_irqrestore(&res_lock, flags);
+               _finish_off(xfer, S3C2410_RES_ABORT,
+                               pl330op == PL330_OP_FLUSH ? 1 : 0);
+               spin_lock_irqsave(&res_lock, flags);
+       }
+
+       /* Flush the whole queue */
+       if (pl330op == PL330_OP_FLUSH) {
+
+               if (ch->req[1 - idx].x) {
+                       xfer = container_of(ch->req[1 - idx].x,
+                                       struct s3c_pl330_xfer, px);
+
+                       del_from_queue(xfer);
+
+                       ch->req[1 - idx].x = NULL;
+
+                       spin_unlock_irqrestore(&res_lock, flags);
+                       _finish_off(xfer, S3C2410_RES_ABORT, 1);
+                       spin_lock_irqsave(&res_lock, flags);
+               }
+
+               /* Finish off the remaining in the queue */
+               xfer = ch->xfer_head;
+               while (xfer) {
+
+                       del_from_queue(xfer);
+
+                       spin_unlock_irqrestore(&res_lock, flags);
+                       _finish_off(xfer, S3C2410_RES_ABORT, 1);
+                       spin_lock_irqsave(&res_lock, flags);
+
+                       xfer = ch->xfer_head;
+               }
+       }
+
+ctrl_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_ctrl);
+
+int s3c2410_dma_enqueue(enum dma_ch id, void *token,
+                       dma_addr_t addr, int size)
+{
+       struct s3c_pl330_chan *ch;
+       struct s3c_pl330_xfer *xfer;
+       unsigned long flags;
+       int idx, ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       /* Error if invalid or free channel */
+       if (!ch || chan_free(ch)) {
+               ret = -EINVAL;
+               goto enq_exit;
+       }
+
+       /* Error if size is unaligned */
+       if (ch->rqcfg.brst_size && size % (1 << ch->rqcfg.brst_size)) {
+               ret = -EINVAL;
+               goto enq_exit;
+       }
+
+       xfer = kmem_cache_alloc(ch->dmac->kmcache, GFP_ATOMIC);
+       if (!xfer) {
+               ret = -ENOMEM;
+               goto enq_exit;
+       }
+
+       xfer->token = token;
+       xfer->chan = ch;
+       xfer->px.bytes = size;
+       xfer->px.next = NULL; /* Single request */
+
+       /* For S3C DMA API, direction is always fixed for all xfers */
+       if (ch->req[0].rqtype == MEMTODEV) {
+               xfer->px.src_addr = addr;
+               xfer->px.dst_addr = ch->sdaddr;
+       } else {
+               xfer->px.src_addr = ch->sdaddr;
+               xfer->px.dst_addr = addr;
+       }
+
+       add_to_queue(ch, xfer, 0);
+
+       /* Try submitting on either request */
+       idx = (ch->lrq == &ch->req[0]) ? 1 : 0;
+
+       if (!ch->req[idx].x)
+               s3c_pl330_submit(ch, &ch->req[idx]);
+       else
+               s3c_pl330_submit(ch, &ch->req[1 - idx]);
+
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       if (ch->options & S3C2410_DMAF_AUTOSTART)
+               s3c2410_dma_ctrl(id, S3C2410_DMAOP_START);
+
+       return 0;
+
+enq_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_enqueue);
+
+int s3c2410_dma_request(enum dma_ch id,
+                       struct s3c2410_dma_client *client,
+                       void *dev)
+{
+       struct s3c_pl330_dmac *dmac;
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = chan_acquire(id);
+       if (!ch) {
+               ret = -EBUSY;
+               goto req_exit;
+       }
+
+       dmac = ch->dmac;
+
+       ch->pl330_chan_id = pl330_request_channel(dmac->pi);
+       if (!ch->pl330_chan_id) {
+               chan_release(ch);
+               ret = -EBUSY;
+               goto req_exit;
+       }
+
+       ch->client = client;
+       ch->options = 0; /* Clear any option */
+       ch->callback_fn = NULL; /* Clear any callback */
+       ch->lrq = NULL;
+
+       ch->rqcfg.brst_size = 2; /* Default word size */
+       ch->rqcfg.swap = SWAP_NO;
+       ch->rqcfg.scctl = SCCTRL0; /* Noncacheable and nonbufferable */
+       ch->rqcfg.dcctl = DCCTRL0; /* Noncacheable and nonbufferable */
+       ch->rqcfg.privileged = 0;
+       ch->rqcfg.insnaccess = 0;
+
+       /* Set invalid direction */
+       ch->req[0].rqtype = DEVTODEV;
+       ch->req[1].rqtype = ch->req[0].rqtype;
+
+       ch->req[0].cfg = &ch->rqcfg;
+       ch->req[1].cfg = ch->req[0].cfg;
+
+       ch->req[0].peri = iface_of_dmac(dmac, id) - 1; /* Original index */
+       ch->req[1].peri = ch->req[0].peri;
+
+       ch->req[0].token = &ch->req[0];
+       ch->req[0].xfer_cb = s3c_pl330_rq0;
+       ch->req[1].token = &ch->req[1];
+       ch->req[1].xfer_cb = s3c_pl330_rq1;
+
+       ch->req[0].x = NULL;
+       ch->req[1].x = NULL;
+
+       /* Reset xfer list */
+       INIT_LIST_HEAD(&ch->xfer_list);
+       ch->xfer_head = NULL;
+
+req_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_request);
+
+int s3c2410_dma_free(enum dma_ch id, struct s3c2410_dma_client *client)
+{
+       struct s3c_pl330_chan *ch;
+       struct s3c_pl330_xfer *xfer;
+       unsigned long flags;
+       int ret = 0;
+       unsigned idx;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch))
+               goto free_exit;
+
+       /* Refuse if someone else wanted to free the channel */
+       if (ch->client != client) {
+               ret = -EBUSY;
+               goto free_exit;
+       }
+
+       /* Stop any active xfer, Flushe the queue and do callbacks */
+       pl330_chan_ctrl(ch->pl330_chan_id, PL330_OP_FLUSH);
+
+       /* Abort the submitted requests */
+       idx = (ch->lrq == &ch->req[0]) ? 1 : 0;
+
+       if (ch->req[idx].x) {
+               xfer = container_of(ch->req[idx].x,
+                               struct s3c_pl330_xfer, px);
+
+               ch->req[idx].x = NULL;
+               del_from_queue(xfer);
+
+               spin_unlock_irqrestore(&res_lock, flags);
+               _finish_off(xfer, S3C2410_RES_ABORT, 1);
+               spin_lock_irqsave(&res_lock, flags);
+       }
+
+       if (ch->req[1 - idx].x) {
+               xfer = container_of(ch->req[1 - idx].x,
+                               struct s3c_pl330_xfer, px);
+
+               ch->req[1 - idx].x = NULL;
+               del_from_queue(xfer);
+
+               spin_unlock_irqrestore(&res_lock, flags);
+               _finish_off(xfer, S3C2410_RES_ABORT, 1);
+               spin_lock_irqsave(&res_lock, flags);
+       }
+
+       /* Pluck and Abort the queued requests in order */
+       do {
+               xfer = get_from_queue(ch, 1);
+
+               spin_unlock_irqrestore(&res_lock, flags);
+               _finish_off(xfer, S3C2410_RES_ABORT, 1);
+               spin_lock_irqsave(&res_lock, flags);
+       } while (xfer);
+
+       ch->client = NULL;
+
+       pl330_release_channel(ch->pl330_chan_id);
+
+       ch->pl330_chan_id = NULL;
+
+       chan_release(ch);
+
+free_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_free);
+
+int s3c2410_dma_config(enum dma_ch id, int xferunit)
+{
+       struct s3c_pl330_chan *ch;
+       struct pl330_info *pi;
+       unsigned long flags;
+       int i, dbwidth, ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch)) {
+               ret = -EINVAL;
+               goto cfg_exit;
+       }
+
+       pi = ch->dmac->pi;
+       dbwidth = pi->pcfg.data_bus_width / 8;
+
+       /* Max size of xfer can be pcfg.data_bus_width */
+       if (xferunit > dbwidth) {
+               ret = -EINVAL;
+               goto cfg_exit;
+       }
+
+       i = 0;
+       while (xferunit != (1 << i))
+               i++;
+
+       /* If valid value */
+       if (xferunit == (1 << i))
+               ch->rqcfg.brst_size = i;
+       else
+               ret = -EINVAL;
+
+cfg_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_config);
+
+/* Options that are supported by this driver */
+#define S3C_PL330_FLAGS (S3C2410_DMAF_CIRCULAR | S3C2410_DMAF_AUTOSTART)
+
+int s3c2410_dma_setflags(enum dma_ch id, unsigned int options)
+{
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch) || options & ~(S3C_PL330_FLAGS))
+               ret = -EINVAL;
+       else
+               ch->options = options;
+
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return 0;
+}
+EXPORT_SYMBOL(s3c2410_dma_setflags);
+
+int s3c2410_dma_set_buffdone_fn(enum dma_ch id, s3c2410_dma_cbfn_t rtn)
+{
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch))
+               ret = -EINVAL;
+       else
+               ch->callback_fn = rtn;
+
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_set_buffdone_fn);
+
+int s3c2410_dma_devconfig(enum dma_ch id, enum s3c2410_dmasrc source,
+                         unsigned long address)
+{
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       ch = id_to_chan(id);
+
+       if (!ch || chan_free(ch)) {
+               ret = -EINVAL;
+               goto devcfg_exit;
+       }
+
+       switch (source) {
+       case S3C2410_DMASRC_HW: /* P->M */
+               ch->req[0].rqtype = DEVTOMEM;
+               ch->req[1].rqtype = DEVTOMEM;
+               ch->rqcfg.src_inc = 0;
+               ch->rqcfg.dst_inc = 1;
+               break;
+       case S3C2410_DMASRC_MEM: /* M->P */
+               ch->req[0].rqtype = MEMTODEV;
+               ch->req[1].rqtype = MEMTODEV;
+               ch->rqcfg.src_inc = 1;
+               ch->rqcfg.dst_inc = 0;
+               break;
+       default:
+               ret = -EINVAL;
+               goto devcfg_exit;
+       }
+
+       ch->sdaddr = address;
+
+devcfg_exit:
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(s3c2410_dma_devconfig);
+
+int s3c2410_dma_getposition(enum dma_ch id, dma_addr_t *src, dma_addr_t *dst)
+{
+       struct s3c_pl330_chan *ch = id_to_chan(id);
+       struct pl330_chanstatus status;
+       int ret;
+
+       if (!ch || chan_free(ch))
+               return -EINVAL;
+
+       ret = pl330_chan_status(ch->pl330_chan_id, &status);
+       if (ret < 0)
+               return ret;
+
+       *src = status.src_addr;
+       *dst = status.dst_addr;
+
+       return 0;
+}
+EXPORT_SYMBOL(s3c2410_dma_getposition);
+
+static irqreturn_t pl330_irq_handler(int irq, void *data)
+{
+       if (pl330_update(data))
+               return IRQ_HANDLED;
+       else
+               return IRQ_NONE;
+}
+
+static int pl330_probe(struct platform_device *pdev)
+{
+       struct s3c_pl330_dmac *s3c_pl330_dmac;
+       struct s3c_pl330_platdata *pl330pd;
+       struct pl330_info *pl330_info;
+       struct resource *res;
+       int i, ret, irq;
+
+       pl330pd = pdev->dev.platform_data;
+
+       /* Can't do without the list of _32_ peripherals */
+       if (!pl330pd || !pl330pd->peri) {
+               dev_err(&pdev->dev, "platform data missing!\n");
+               return -ENODEV;
+       }
+
+       pl330_info = kzalloc(sizeof(*pl330_info), GFP_KERNEL);
+       if (!pl330_info)
+               return -ENOMEM;
+
+       pl330_info->pl330_data = NULL;
+       pl330_info->dev = &pdev->dev;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               ret = -ENODEV;
+               goto probe_err1;
+       }
+
+       request_mem_region(res->start, resource_size(res), pdev->name);
+
+       pl330_info->base = ioremap(res->start, resource_size(res));
+       if (!pl330_info->base) {
+               ret = -ENXIO;
+               goto probe_err2;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq < 0) {
+               ret = irq;
+               goto probe_err3;
+       }
+
+       ret = request_irq(irq, pl330_irq_handler, 0,
+                       dev_name(&pdev->dev), pl330_info);
+       if (ret)
+               goto probe_err4;
+
+       ret = pl330_add(pl330_info);
+       if (ret)
+               goto probe_err5;
+
+       /* Allocate a new DMAC */
+       s3c_pl330_dmac = kmalloc(sizeof(*s3c_pl330_dmac), GFP_KERNEL);
+       if (!s3c_pl330_dmac) {
+               ret = -ENOMEM;
+               goto probe_err6;
+       }
+
+       /* Hook the info */
+       s3c_pl330_dmac->pi = pl330_info;
+
+       /* No busy channels */
+       s3c_pl330_dmac->busy_chan = 0;
+
+       s3c_pl330_dmac->kmcache = kmem_cache_create(dev_name(&pdev->dev),
+                               sizeof(struct s3c_pl330_xfer), 0, 0, NULL);
+
+       if (!s3c_pl330_dmac->kmcache) {
+               ret = -ENOMEM;
+               goto probe_err7;
+       }
+
+       /* Get the list of peripherals */
+       s3c_pl330_dmac->peri = pl330pd->peri;
+
+       /* Attach to the list of DMACs */
+       list_add_tail(&s3c_pl330_dmac->node, &dmac_list);
+
+       /* Create a channel for each peripheral in the DMAC
+        * that is, if it doesn't already exist
+        */
+       for (i = 0; i < PL330_MAX_PERI; i++)
+               if (s3c_pl330_dmac->peri[i] != DMACH_MAX)
+                       chan_add(s3c_pl330_dmac->peri[i]);
+
+       printk(KERN_INFO
+               "Loaded driver for PL330 DMAC-%d %s\n", pdev->id, pdev->name);
+       printk(KERN_INFO
+               "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n",
+               pl330_info->pcfg.data_buf_dep,
+               pl330_info->pcfg.data_bus_width / 8, pl330_info->pcfg.num_chan,
+               pl330_info->pcfg.num_peri, pl330_info->pcfg.num_events);
+
+       return 0;
+
+probe_err7:
+       kfree(s3c_pl330_dmac);
+probe_err6:
+       pl330_del(pl330_info);
+probe_err5:
+       free_irq(irq, pl330_info);
+probe_err4:
+probe_err3:
+       iounmap(pl330_info->base);
+probe_err2:
+       release_mem_region(res->start, resource_size(res));
+probe_err1:
+       kfree(pl330_info);
+
+       return ret;
+}
+
+static int pl330_remove(struct platform_device *pdev)
+{
+       struct s3c_pl330_dmac *dmac, *d;
+       struct s3c_pl330_chan *ch;
+       unsigned long flags;
+       int del, found;
+
+       if (!pdev->dev.platform_data)
+               return -EINVAL;
+
+       spin_lock_irqsave(&res_lock, flags);
+
+       found = 0;
+       list_for_each_entry(d, &dmac_list, node)
+               if (d->pi->dev == &pdev->dev) {
+                       found = 1;
+                       break;
+               }
+
+       if (!found) {
+               spin_unlock_irqrestore(&res_lock, flags);
+               return 0;
+       }
+
+       dmac = d;
+
+       /* Remove all Channels that are managed only by this DMAC */
+       list_for_each_entry(ch, &chan_list, node) {
+
+               /* Only channels that are handled by this DMAC */
+               if (iface_of_dmac(dmac, ch->id))
+                       del = 1;
+               else
+                       continue;
+
+               /* Don't remove if some other DMAC has it too */
+               list_for_each_entry(d, &dmac_list, node)
+                       if (d != dmac && iface_of_dmac(d, ch->id)) {
+                               del = 0;
+                               break;
+                       }
+
+               if (del) {
+                       spin_unlock_irqrestore(&res_lock, flags);
+                       s3c2410_dma_free(ch->id, ch->client);
+                       spin_lock_irqsave(&res_lock, flags);
+                       list_del(&ch->node);
+                       kfree(ch);
+               }
+       }
+
+       /* Remove the DMAC */
+       list_del(&dmac->node);
+       kfree(dmac);
+
+       spin_unlock_irqrestore(&res_lock, flags);
+
+       return 0;
+}
+
+static struct platform_driver pl330_driver = {
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "s3c-pl330",
+       },
+       .probe          = pl330_probe,
+       .remove         = pl330_remove,
+};
+
+static int __init pl330_init(void)
+{
+       return platform_driver_register(&pl330_driver);
+}
+module_init(pl330_init);
+
+static void __exit pl330_exit(void)
+{
+       platform_driver_unregister(&pl330_driver);
+       return;
+}
+module_exit(pl330_exit);
+
+MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>");
+MODULE_DESCRIPTION("Driver for PL330 DMA Controller");
+MODULE_LICENSE("GPL");
diff --git a/arch/arm/plat-spear/Kconfig b/arch/arm/plat-spear/Kconfig
new file mode 100644 (file)
index 0000000..1bb3dbc
--- /dev/null
@@ -0,0 +1,31 @@
+#
+# SPEAr Platform configuration file
+#
+
+if PLAT_SPEAR
+
+choice
+       prompt "ST SPEAr Family"
+       default ARCH_SPEAR3XX
+
+config ARCH_SPEAR3XX
+       bool "SPEAr3XX"
+       select ARM_VIC
+       select CPU_ARM926T
+       help
+         Supports for ARM's SPEAR3XX family
+
+config ARCH_SPEAR6XX
+       bool "SPEAr6XX"
+       select ARM_VIC
+       select CPU_ARM926T
+       help
+         Supports for ARM's SPEAR6XX family
+
+endchoice
+
+# Adding SPEAr machine specific configuration files
+source "arch/arm/mach-spear3xx/Kconfig"
+source "arch/arm/mach-spear6xx/Kconfig"
+
+endif
diff --git a/arch/arm/plat-spear/Makefile b/arch/arm/plat-spear/Makefile
new file mode 100644 (file)
index 0000000..eb89540
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# SPEAr Platform specific Makefile
+#
+
+# Common support
+obj-y  := clock.o padmux.o time.o
+
+obj-$(CONFIG_ARCH_SPEAR3XX)    += shirq.o
diff --git a/arch/arm/plat-spear/clock.c b/arch/arm/plat-spear/clock.c
new file mode 100644 (file)
index 0000000..ee4f90e
--- /dev/null
@@ -0,0 +1,435 @@
+/*
+ * arch/arm/plat-spear/clock.c
+ *
+ * Clock framework for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/bug.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <mach/misc_regs.h>
+#include <plat/clock.h>
+
+static DEFINE_SPINLOCK(clocks_lock);
+static LIST_HEAD(root_clks);
+
+static void propagate_rate(struct list_head *);
+
+static int generic_clk_enable(struct clk *clk)
+{
+       unsigned int val;
+
+       if (!clk->en_reg)
+               return -EFAULT;
+
+       val = readl(clk->en_reg);
+       if (unlikely(clk->flags & RESET_TO_ENABLE))
+               val &= ~(1 << clk->en_reg_bit);
+       else
+               val |= 1 << clk->en_reg_bit;
+
+       writel(val, clk->en_reg);
+
+       return 0;
+}
+
+static void generic_clk_disable(struct clk *clk)
+{
+       unsigned int val;
+
+       if (!clk->en_reg)
+               return;
+
+       val = readl(clk->en_reg);
+       if (unlikely(clk->flags & RESET_TO_ENABLE))
+               val |= 1 << clk->en_reg_bit;
+       else
+               val &= ~(1 << clk->en_reg_bit);
+
+       writel(val, clk->en_reg);
+}
+
+/* generic clk ops */
+static struct clkops generic_clkops = {
+       .enable = generic_clk_enable,
+       .disable = generic_clk_disable,
+};
+
+/*
+ * clk_enable - inform the system when the clock source should be running.
+ * @clk: clock source
+ *
+ * If the clock can not be enabled/disabled, this should return success.
+ *
+ * Returns success (0) or negative errno.
+ */
+int clk_enable(struct clk *clk)
+{
+       unsigned long flags;
+       int ret = 0;
+
+       if (!clk || IS_ERR(clk))
+               return -EFAULT;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       if (clk->usage_count == 0) {
+               if (clk->ops && clk->ops->enable)
+                       ret = clk->ops->enable(clk);
+       }
+       clk->usage_count++;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_enable);
+
+/*
+ * clk_disable - inform the system when the clock source is no longer required.
+ * @clk: clock source
+ *
+ * Inform the system that a clock source is no longer required by
+ * a driver and may be shut down.
+ *
+ * Implementation detail: if the clock source is shared between
+ * multiple drivers, clk_enable() calls must be balanced by the
+ * same number of clk_disable() calls for the clock source to be
+ * disabled.
+ */
+void clk_disable(struct clk *clk)
+{
+       unsigned long flags;
+
+       if (!clk || IS_ERR(clk))
+               return;
+
+       WARN_ON(clk->usage_count == 0);
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       clk->usage_count--;
+       if (clk->usage_count == 0) {
+               if (clk->ops && clk->ops->disable)
+                       clk->ops->disable(clk);
+       }
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+EXPORT_SYMBOL(clk_disable);
+
+/**
+ * clk_get_rate - obtain the current clock rate (in Hz) for a clock source.
+ *              This is only valid once the clock source has been enabled.
+ * @clk: clock source
+ */
+unsigned long clk_get_rate(struct clk *clk)
+{
+       unsigned long flags, rate;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       rate = clk->rate;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
+       return rate;
+}
+EXPORT_SYMBOL(clk_get_rate);
+
+/**
+ * clk_set_parent - set the parent clock source for this clock
+ * @clk: clock source
+ * @parent: parent clock source
+ *
+ * Returns success (0) or negative errno.
+ */
+int clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       int i, found = 0, val = 0;
+       unsigned long flags;
+
+       if (!clk || IS_ERR(clk) || !parent || IS_ERR(parent))
+               return -EFAULT;
+       if (clk->usage_count)
+               return -EBUSY;
+       if (!clk->pclk_sel)
+               return -EPERM;
+       if (clk->pclk == parent)
+               return 0;
+
+       for (i = 0; i < clk->pclk_sel->pclk_count; i++) {
+               if (clk->pclk_sel->pclk_info[i].pclk == parent) {
+                       found = 1;
+                       break;
+               }
+       }
+
+       if (!found)
+               return -EINVAL;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       /* reflect parent change in hardware */
+       val = readl(clk->pclk_sel->pclk_sel_reg);
+       val &= ~(clk->pclk_sel->pclk_sel_mask << clk->pclk_sel_shift);
+       val |= clk->pclk_sel->pclk_info[i].pclk_mask << clk->pclk_sel_shift;
+       writel(val, clk->pclk_sel->pclk_sel_reg);
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
+       /* reflect parent change in software */
+       clk->recalc(clk);
+       propagate_rate(&clk->children);
+       return 0;
+}
+EXPORT_SYMBOL(clk_set_parent);
+
+/* registers clock in platform clock framework */
+void clk_register(struct clk_lookup *cl)
+{
+       struct clk *clk = cl->clk;
+       unsigned long flags;
+
+       if (!clk || IS_ERR(clk))
+               return;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+
+       INIT_LIST_HEAD(&clk->children);
+       if (clk->flags & ALWAYS_ENABLED)
+               clk->ops = NULL;
+       else if (!clk->ops)
+               clk->ops = &generic_clkops;
+
+       /* root clock don't have any parents */
+       if (!clk->pclk && !clk->pclk_sel) {
+               list_add(&clk->sibling, &root_clks);
+               /* add clocks with only one parent to parent's children list */
+       } else if (clk->pclk && !clk->pclk_sel) {
+               list_add(&clk->sibling, &clk->pclk->children);
+       } else {
+               /* add clocks with > 1 parent to 1st parent's children list */
+               list_add(&clk->sibling,
+                        &clk->pclk_sel->pclk_info[0].pclk->children);
+       }
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
+       /* add clock to arm clockdev framework */
+       clkdev_add(cl);
+}
+
+/**
+ * propagate_rate - recalculate and propagate all clocks in list head
+ *
+ * Recalculates all root clocks in list head, which if the clock's .recalc is
+ * set correctly, should also propagate their rates.
+ */
+static void propagate_rate(struct list_head *lhead)
+{
+       struct clk *clkp, *_temp;
+
+       list_for_each_entry_safe(clkp, _temp, lhead, sibling) {
+               if (clkp->recalc)
+                       clkp->recalc(clkp);
+               propagate_rate(&clkp->children);
+       }
+}
+
+/* returns current programmed clocks clock info structure */
+static struct pclk_info *pclk_info_get(struct clk *clk)
+{
+       unsigned int mask, i;
+       unsigned long flags;
+       struct pclk_info *info = NULL;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       mask = (readl(clk->pclk_sel->pclk_sel_reg) >> clk->pclk_sel_shift)
+                       & clk->pclk_sel->pclk_sel_mask;
+
+       for (i = 0; i < clk->pclk_sel->pclk_count; i++) {
+               if (clk->pclk_sel->pclk_info[i].pclk_mask == mask)
+                       info = &clk->pclk_sel->pclk_info[i];
+       }
+       spin_unlock_irqrestore(&clocks_lock, flags);
+
+       return info;
+}
+
+/*
+ * Set pclk as cclk's parent and add clock sibling node to current parents
+ * children list
+ */
+static void change_parent(struct clk *cclk, struct clk *pclk)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       list_del(&cclk->sibling);
+       list_add(&cclk->sibling, &pclk->children);
+
+       cclk->pclk = pclk;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/*
+ * calculates current programmed rate of pll1
+ *
+ * In normal mode
+ * rate = (2 * M[15:8] * Fin)/(N * 2^P)
+ *
+ * In Dithered mode
+ * rate = (2 * M[15:0] * Fin)/(256 * N * 2^P)
+ */
+void pll1_clk_recalc(struct clk *clk)
+{
+       struct pll_clk_config *config = clk->private_data;
+       unsigned int num = 2, den = 0, val, mode = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       mode = (readl(config->mode_reg) >> PLL_MODE_SHIFT) &
+               PLL_MODE_MASK;
+
+       val = readl(config->cfg_reg);
+       /* calculate denominator */
+       den = (val >> PLL_DIV_P_SHIFT) & PLL_DIV_P_MASK;
+       den = 1 << den;
+       den *= (val >> PLL_DIV_N_SHIFT) & PLL_DIV_N_MASK;
+
+       /* calculate numerator & denominator */
+       if (!mode) {
+               /* Normal mode */
+               num *= (val >> PLL_NORM_FDBK_M_SHIFT) & PLL_NORM_FDBK_M_MASK;
+       } else {
+               /* Dithered mode */
+               num *= (val >> PLL_DITH_FDBK_M_SHIFT) & PLL_DITH_FDBK_M_MASK;
+               den *= 256;
+       }
+
+       clk->rate = (((clk->pclk->rate/10000) * num) / den) * 10000;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/* calculates current programmed rate of ahb or apb bus */
+void bus_clk_recalc(struct clk *clk)
+{
+       struct bus_clk_config *config = clk->private_data;
+       unsigned int div;
+       unsigned long flags;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       div = ((readl(config->reg) >> config->shift) & config->mask) + 1;
+       clk->rate = (unsigned long)clk->pclk->rate / div;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/*
+ * calculates current programmed rate of auxiliary synthesizers
+ * used by: UART, FIRDA
+ *
+ * Fout from synthesizer can be given from two equations:
+ * Fout1 = (Fin * X/Y)/2
+ * Fout2 = Fin * X/Y
+ *
+ * Selection of eqn 1 or 2 is programmed in register
+ */
+void aux_clk_recalc(struct clk *clk)
+{
+       struct aux_clk_config *config = clk->private_data;
+       struct pclk_info *pclk_info = NULL;
+       unsigned int num = 1, den = 1, val, eqn;
+       unsigned long flags;
+
+       /* get current programmed parent */
+       pclk_info = pclk_info_get(clk);
+       if (!pclk_info) {
+               spin_lock_irqsave(&clocks_lock, flags);
+               clk->pclk = NULL;
+               clk->rate = 0;
+               spin_unlock_irqrestore(&clocks_lock, flags);
+               return;
+       }
+
+       change_parent(clk, pclk_info->pclk);
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       if (pclk_info->scalable) {
+               val = readl(config->synth_reg);
+
+               eqn = (val >> AUX_EQ_SEL_SHIFT) & AUX_EQ_SEL_MASK;
+               if (eqn == AUX_EQ1_SEL)
+                       den *= 2;
+
+               /* calculate numerator */
+               num = (val >> AUX_XSCALE_SHIFT) & AUX_XSCALE_MASK;
+
+               /* calculate denominator */
+               den *= (val >> AUX_YSCALE_SHIFT) & AUX_YSCALE_MASK;
+               val = (((clk->pclk->rate/10000) * num) / den) * 10000;
+       } else
+               val = clk->pclk->rate;
+
+       clk->rate = val;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/*
+ * calculates current programmed rate of gpt synthesizers
+ * Fout from synthesizer can be given from below equations:
+ * Fout= Fin/((2 ^ (N+1)) * (M+1))
+ */
+void gpt_clk_recalc(struct clk *clk)
+{
+       struct aux_clk_config *config = clk->private_data;
+       struct pclk_info *pclk_info = NULL;
+       unsigned int div = 1, val;
+       unsigned long flags;
+
+       pclk_info = pclk_info_get(clk);
+       if (!pclk_info) {
+               spin_lock_irqsave(&clocks_lock, flags);
+               clk->pclk = NULL;
+               clk->rate = 0;
+               spin_unlock_irqrestore(&clocks_lock, flags);
+               return;
+       }
+
+       change_parent(clk, pclk_info->pclk);
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       if (pclk_info->scalable) {
+               val = readl(config->synth_reg);
+               div += (val >> GPT_MSCALE_SHIFT) & GPT_MSCALE_MASK;
+               div *= 1 << (((val >> GPT_NSCALE_SHIFT) & GPT_NSCALE_MASK) + 1);
+       }
+
+       clk->rate = (unsigned long)clk->pclk->rate / div;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/*
+ * Used for clocks that always have same value as the parent clock divided by a
+ * fixed divisor
+ */
+void follow_parent(struct clk *clk)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&clocks_lock, flags);
+       clk->rate = clk->pclk->rate;
+       spin_unlock_irqrestore(&clocks_lock, flags);
+}
+
+/**
+ * recalc_root_clocks - recalculate and propagate all root clocks
+ *
+ * Recalculates all root clocks (clocks with no parent), which if the
+ * clock's .recalc is set correctly, should also propagate their rates.
+ */
+void recalc_root_clocks(void)
+{
+       propagate_rate(&root_clks);
+}
diff --git a/arch/arm/plat-spear/include/plat/clkdev.h b/arch/arm/plat-spear/include/plat/clkdev.h
new file mode 100644 (file)
index 0000000..a2d0112
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * arch/arm/plat-spear/include/plat/clkdev.h
+ *
+ * Clock Dev framework definitions for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_CLKDEV_H
+#define __PLAT_CLKDEV_H
+
+#define __clk_get(clk) ({ 1; })
+#define __clk_put(clk) do { } while (0)
+
+#endif /* __PLAT_CLKDEV_H */
diff --git a/arch/arm/plat-spear/include/plat/clock.h b/arch/arm/plat-spear/include/plat/clock.h
new file mode 100644 (file)
index 0000000..298bafc
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * arch/arm/plat-spear/include/plat/clock.h
+ *
+ * Clock framework definitions for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_CLOCK_H
+#define __PLAT_CLOCK_H
+
+#include <linux/list.h>
+#include <asm/clkdev.h>
+#include <linux/types.h>
+
+/* clk structure flags */
+#define        ALWAYS_ENABLED          (1 << 0) /* clock always enabled */
+#define        RESET_TO_ENABLE         (1 << 1) /* reset register bit to enable clk */
+
+/**
+ * struct clkops - clock operations
+ * @enable: pointer to clock enable function
+ * @disable: pointer to clock disable function
+ */
+struct clkops {
+       int (*enable) (struct clk *);
+       void (*disable) (struct clk *);
+};
+
+/**
+ * struct pclk_info - parents info
+ * @pclk: pointer to parent clk
+ * @pclk_mask: value to be written for selecting this parent
+ * @scalable: Is parent scalable (1 - YES, 0 - NO)
+ */
+struct pclk_info {
+       struct clk *pclk;
+       u8 pclk_mask;
+       u8 scalable;
+};
+
+/**
+ * struct pclk_sel - parents selection configuration
+ * @pclk_info: pointer to array of parent clock info
+ * @pclk_count: number of parents
+ * @pclk_sel_reg: register for selecting a parent
+ * @pclk_sel_mask: mask for selecting parent (can be used to clear bits also)
+ */
+struct pclk_sel {
+       struct pclk_info *pclk_info;
+       u8 pclk_count;
+       unsigned int *pclk_sel_reg;
+       unsigned int pclk_sel_mask;
+};
+
+/**
+ * struct clk - clock structure
+ * @usage_count: num of users who enabled this clock
+ * @flags: flags for clock properties
+ * @rate: programmed clock rate in Hz
+ * @en_reg: clk enable/disable reg
+ * @en_reg_bit: clk enable/disable bit
+ * @ops: clk enable/disable ops - generic_clkops selected if NULL
+ * @recalc: pointer to clock rate recalculate function
+ * @pclk: current parent clk
+ * @pclk_sel: pointer to parent selection structure
+ * @pclk_sel_shift: register shift for selecting parent of this clock
+ * @children: list for childrens or this clock
+ * @sibling: node for list of clocks having same parents
+ * @private_data: clock specific private data
+ */
+struct clk {
+       unsigned int usage_count;
+       unsigned int flags;
+       unsigned long rate;
+       unsigned int *en_reg;
+       u8 en_reg_bit;
+       const struct clkops *ops;
+       void (*recalc) (struct clk *);
+
+       struct clk *pclk;
+       struct pclk_sel *pclk_sel;
+       unsigned int pclk_sel_shift;
+
+       struct list_head children;
+       struct list_head sibling;
+       void *private_data;
+};
+
+/* pll configuration structure */
+struct pll_clk_config {
+       unsigned int *mode_reg;
+       unsigned int *cfg_reg;
+};
+
+/* ahb and apb bus configuration structure */
+struct bus_clk_config {
+       unsigned int *reg;
+       unsigned int mask;
+       unsigned int shift;
+};
+
+/*
+ * Aux clk configuration structure: applicable to GPT, UART and FIRDA
+ */
+struct aux_clk_config {
+       unsigned int *synth_reg;
+};
+
+/* platform specific clock functions */
+void clk_register(struct clk_lookup *cl);
+void recalc_root_clocks(void);
+
+/* clock recalc functions */
+void follow_parent(struct clk *clk);
+void pll1_clk_recalc(struct clk *clk);
+void bus_clk_recalc(struct clk *clk);
+void gpt_clk_recalc(struct clk *clk);
+void aux_clk_recalc(struct clk *clk);
+
+#endif /* __PLAT_CLOCK_H */
diff --git a/arch/arm/plat-spear/include/plat/debug-macro.S b/arch/arm/plat-spear/include/plat/debug-macro.S
new file mode 100644 (file)
index 0000000..1670734
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * arch/arm/plat-spear/include/plat/debug-macro.S
+ *
+ * Debugging macro include header for spear platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/amba/serial.h>
+#include <mach/spear.h>
+
+               .macro  addruart, rx
+               mrc     p15, 0, \rx, c1, c0
+               tst     \rx, #1                                 @ MMU enabled?
+               moveq   \rx, =SPEAR_DBG_UART_BASE               @ Physical base
+               movne   \rx, =VA_SPEAR_DBG_UART_BASE            @ Virtual base
+               .endm
+
+               .macro  senduart, rd, rx
+               strb    \rd, [\rx, #UART01x_DR]                 @ ASC_TX_BUFFER
+               .endm
+
+               .macro  waituart, rd, rx
+1001:          ldr     \rd, [\rx, #UART01x_FR]                 @ FLAG REGISTER
+               tst     \rd, #UART01x_FR_TXFF                   @ TX_FULL
+               bne     1001b
+               .endm
+
+               .macro  busyuart, rd, rx
+1002:          ldr     \rd, [\rx, #UART01x_FR]                 @ FLAG REGISTER
+               tst     \rd, #UART011_FR_TXFE                   @ TX_EMPTY
+               beq     1002b
+               .endm
diff --git a/arch/arm/plat-spear/include/plat/gpio.h b/arch/arm/plat-spear/include/plat/gpio.h
new file mode 100644 (file)
index 0000000..b857c91
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * arch/arm/plat-spear/include/plat/gpio.h
+ *
+ * GPIO macros for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_GPIO_H
+#define __PLAT_GPIO_H
+
+#include <asm-generic/gpio.h>
+
+#define gpio_get_value __gpio_get_value
+#define gpio_set_value __gpio_set_value
+#define gpio_cansleep  __gpio_cansleep
+#define gpio_to_irq    __gpio_to_irq
+
+#endif /* __PLAT_GPIO_H */
diff --git a/arch/arm/plat-spear/include/plat/io.h b/arch/arm/plat-spear/include/plat/io.h
new file mode 100644 (file)
index 0000000..4d4ba82
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * arch/arm/plat-spear/include/plat/io.h
+ *
+ * IO definitions for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_IO_H
+#define __PLAT_IO_H
+
+#define IO_SPACE_LIMIT         0xFFFFFFFF
+
+#define __io(a)                        __typesafe_io(a)
+#define __mem_pci(a)           (a)
+
+#endif /* __PLAT_IO_H */
diff --git a/arch/arm/plat-spear/include/plat/memory.h b/arch/arm/plat-spear/include/plat/memory.h
new file mode 100644 (file)
index 0000000..27a4aba
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * arch/arm/plat-spear/include/plat/memory.h
+ *
+ * Memory map for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_MEMORY_H
+#define __PLAT_MEMORY_H
+
+/* Physical DRAM offset */
+#define PHYS_OFFSET            UL(0x00000000)
+
+#endif /* __PLAT_MEMORY_H */
diff --git a/arch/arm/plat-spear/include/plat/padmux.h b/arch/arm/plat-spear/include/plat/padmux.h
new file mode 100644 (file)
index 0000000..877f3ad
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * arch/arm/plat-spear/include/plat/padmux.h
+ *
+ * SPEAr platform specific gpio pads muxing file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_PADMUX_H
+#define __PLAT_PADMUX_H
+
+#include <linux/types.h>
+
+/*
+ * struct pmx_reg: configuration structure for mode reg and mux reg
+ *
+ * offset: offset of mode reg
+ * mask: mask of mode reg
+ */
+struct pmx_reg {
+       u32 offset;
+       u32 mask;
+};
+
+/*
+ * struct pmx_dev_mode: configuration structure every group of modes of a device
+ *
+ * ids: all modes for this configuration
+ * mask: mask for supported mode
+ */
+struct pmx_dev_mode {
+       u32 ids;
+       u32 mask;
+};
+
+/*
+ * struct pmx_mode: mode definition structure
+ *
+ * name: mode name
+ * mask: mode mask
+ */
+struct pmx_mode {
+       char *name;
+       u32 id;
+       u32 mask;
+};
+
+/*
+ * struct pmx_dev: device definition structure
+ *
+ * name: device name
+ * modes: device configuration array for different modes supported
+ * mode_count: size of modes array
+ * is_active: is peripheral active/enabled
+ * enb_on_reset: if 1, mask bits to be cleared in reg otherwise to be set in reg
+ */
+struct pmx_dev {
+       char *name;
+       struct pmx_dev_mode *modes;
+       u8 mode_count;
+       bool is_active;
+       bool enb_on_reset;
+};
+
+/*
+ * struct pmx_driver: driver definition structure
+ *
+ * mode: mode to be set
+ * devs: array of pointer to pmx devices
+ * devs_count: ARRAY_SIZE of devs
+ * base: base address of soc config registers
+ * mode_reg: structure of mode config register
+ * mux_reg: structure of device mux config register
+ */
+struct pmx_driver {
+       struct pmx_mode *mode;
+       struct pmx_dev **devs;
+       u8 devs_count;
+       u32 *base;
+       struct pmx_reg mode_reg;
+       struct pmx_reg mux_reg;
+};
+
+/* pmx functions */
+int pmx_register(struct pmx_driver *driver);
+
+#endif /* __PLAT_PADMUX_H */
diff --git a/arch/arm/plat-spear/include/plat/shirq.h b/arch/arm/plat-spear/include/plat/shirq.h
new file mode 100644 (file)
index 0000000..03ed8b5
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * arch/arm/plat-spear/include/plat/shirq.h
+ *
+ * SPEAr platform shared irq layer header file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_SHIRQ_H
+#define __PLAT_SHIRQ_H
+
+#include <linux/irq.h>
+#include <linux/types.h>
+
+/*
+ * struct shirq_dev_config: shared irq device configuration
+ *
+ * virq: virtual irq number of device
+ * enb_mask: enable mask of device
+ * status_mask: status mask of device
+ * clear_mask: clear mask of device
+ */
+struct shirq_dev_config {
+       u32 virq;
+       u32 enb_mask;
+       u32 status_mask;
+       u32 clear_mask;
+};
+
+/*
+ * struct shirq_regs: shared irq register configuration
+ *
+ * base: base address of shared irq register
+ * enb_reg: enable register offset
+ * reset_to_enb: val 1 indicates, we need to clear bit for enabling interrupt
+ * status_reg: status register offset
+ * status_reg_mask: status register valid mask
+ * clear_reg: clear register offset
+ * reset_to_clear: val 1 indicates, we need to clear bit for clearing interrupt
+ */
+struct shirq_regs {
+       void __iomem *base;
+       u32 enb_reg;
+       u32 reset_to_enb;
+       u32 status_reg;
+       u32 status_reg_mask;
+       u32 clear_reg;
+       u32 reset_to_clear;
+};
+
+/*
+ * struct spear_shirq: shared irq structure
+ *
+ * irq: hardware irq number
+ * dev_config: array of device config structures which are using "irq" line
+ * dev_count: size of dev_config array
+ * regs: register configuration for shared irq block
+ */
+struct spear_shirq {
+       u32 irq;
+       struct shirq_dev_config *dev_config;
+       u32 dev_count;
+       struct shirq_regs regs;
+};
+
+int spear_shirq_register(struct spear_shirq *shirq);
+
+#endif /* __PLAT_SHIRQ_H */
diff --git a/arch/arm/plat-spear/include/plat/system.h b/arch/arm/plat-spear/include/plat/system.h
new file mode 100644 (file)
index 0000000..55a4e40
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * arch/arm/plat-spear/include/plat/system.h
+ *
+ * SPEAr platform specific architecture functions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_SYSTEM_H
+#define __PLAT_SYSTEM_H
+
+#include <asm/hardware/sp810.h>
+#include <linux/io.h>
+#include <mach/spear.h>
+
+static inline void arch_idle(void)
+{
+       /*
+        * This should do all the clock switching
+        * and wait for interrupt tricks
+        */
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode, const char *cmd)
+{
+       if (mode == 's') {
+               /* software reset, Jump into ROM at address 0 */
+               cpu_reset(0);
+       } else {
+               /* hardware reset, Use on-chip reset capability */
+               sysctl_soft_reset((void __iomem *)VA_SPEAR_SYS_CTRL_BASE);
+       }
+}
+
+#endif /* __PLAT_SYSTEM_H */
diff --git a/arch/arm/plat-spear/include/plat/timex.h b/arch/arm/plat-spear/include/plat/timex.h
new file mode 100644 (file)
index 0000000..914d09d
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/plat-spear/include/plat/timex.h
+ *
+ * SPEAr platform specific timex definitions
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_TIMEX_H
+#define __PLAT_TIMEX_H
+
+#define CLOCK_TICK_RATE                        48000000
+
+#endif /* __PLAT_TIMEX_H */
diff --git a/arch/arm/plat-spear/include/plat/uncompress.h b/arch/arm/plat-spear/include/plat/uncompress.h
new file mode 100644 (file)
index 0000000..99ba678
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * arch/arm/plat-spear/include/plat/uncompress.h
+ *
+ * Serial port stubs for kernel decompress status messages
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/io.h>
+#include <linux/amba/serial.h>
+#include <mach/spear.h>
+
+#ifndef __PLAT_UNCOMPRESS_H
+#define __PLAT_UNCOMPRESS_H
+/*
+ * This does not append a newline
+ */
+static inline void putc(int c)
+{
+       void __iomem *base = (void __iomem *)SPEAR_DBG_UART_BASE;
+
+       while (readl(base + UART01x_FR) & UART01x_FR_TXFF)
+               barrier();
+
+       writel(c, base + UART01x_DR);
+}
+
+static inline void flush(void)
+{
+}
+
+/*
+ * nothing to do
+ */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
+
+#endif /* __PLAT_UNCOMPRESS_H */
diff --git a/arch/arm/plat-spear/include/plat/vmalloc.h b/arch/arm/plat-spear/include/plat/vmalloc.h
new file mode 100644 (file)
index 0000000..09e9372
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * arch/arm/plat-spear/include/plat/vmalloc.h
+ *
+ * Defining Vmalloc area for SPEAr platform
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __PLAT_VMALLOC_H
+#define __PLAT_VMALLOC_H
+
+#define VMALLOC_END            0xF0000000
+
+#endif /* __PLAT_VMALLOC_H */
diff --git a/arch/arm/plat-spear/padmux.c b/arch/arm/plat-spear/padmux.c
new file mode 100644 (file)
index 0000000..d2aab3a
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * arch/arm/plat-spear/include/plat/padmux.c
+ *
+ * SPEAr platform specific gpio pads muxing source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <plat/padmux.h>
+
+/*
+ * struct pmx: pmx definition structure
+ *
+ * base: base address of configuration registers
+ * mode_reg: mode configurations
+ * mux_reg: muxing configurations
+ * active_mode: pointer to current active mode
+ */
+struct pmx {
+       u32 base;
+       struct pmx_reg mode_reg;
+       struct pmx_reg mux_reg;
+       struct pmx_mode *active_mode;
+};
+
+static struct pmx *pmx;
+
+/**
+ * pmx_mode_set - Enables an multiplexing mode
+ * @mode - pointer to pmx mode
+ *
+ * It will set mode of operation in hardware.
+ * Returns -ve on Err otherwise 0
+ */
+static int pmx_mode_set(struct pmx_mode *mode)
+{
+       u32 val;
+
+       if (!mode->name)
+               return -EFAULT;
+
+       pmx->active_mode = mode;
+
+       val = readl(pmx->base + pmx->mode_reg.offset);
+       val &= ~pmx->mode_reg.mask;
+       val |= mode->mask & pmx->mode_reg.mask;
+       writel(val, pmx->base + pmx->mode_reg.offset);
+
+       return 0;
+}
+
+/**
+ * pmx_devs_enable - Enables list of devices
+ * @devs - pointer to pmx device array
+ * @count - number of devices to enable
+ *
+ * It will enable pads for all required peripherals once and only once.
+ * If peripheral is not supported by current mode then request is rejected.
+ * Conflicts between peripherals are not handled and peripherals will be
+ * enabled in the order they are present in pmx_dev array.
+ * In case of conflicts last peripheral enalbed will be present.
+ * Returns -ve on Err otherwise 0
+ */
+static int pmx_devs_enable(struct pmx_dev **devs, u8 count)
+{
+       u32 val, i, mask;
+
+       if (!count)
+               return -EINVAL;
+
+       val = readl(pmx->base + pmx->mux_reg.offset);
+       for (i = 0; i < count; i++) {
+               u8 j = 0;
+
+               if (!devs[i]->name || !devs[i]->modes) {
+                       printk(KERN_ERR "padmux: dev name or modes is null\n");
+                       continue;
+               }
+               /* check if peripheral exists in active mode */
+               if (pmx->active_mode) {
+                       bool found = false;
+                       for (j = 0; j < devs[i]->mode_count; j++) {
+                               if (devs[i]->modes[j].ids &
+                                               pmx->active_mode->id) {
+                                       found = true;
+                                       break;
+                               }
+                       }
+                       if (found == false) {
+                               printk(KERN_ERR "%s device not available in %s"\
+                                               "mode\n", devs[i]->name,
+                                               pmx->active_mode->name);
+                               continue;
+                       }
+               }
+
+               /* enable peripheral */
+               mask = devs[i]->modes[j].mask & pmx->mux_reg.mask;
+               if (devs[i]->enb_on_reset)
+                       val &= ~mask;
+               else
+                       val |= mask;
+
+               devs[i]->is_active = true;
+       }
+       writel(val, pmx->base + pmx->mux_reg.offset);
+       kfree(pmx);
+
+       /* this will ensure that multiplexing can't be changed now */
+       pmx = (struct pmx *)-1;
+
+       return 0;
+}
+
+/**
+ * pmx_register - registers a platform requesting pad mux feature
+ * @driver - pointer to driver structure containing driver specific parameters
+ *
+ * Also this must be called only once. This will allocate memory for pmx
+ * structure, will call pmx_mode_set, will call pmx_devs_enable.
+ * Returns -ve on Err otherwise 0
+ */
+int pmx_register(struct pmx_driver *driver)
+{
+       int ret = 0;
+
+       if (pmx)
+               return -EPERM;
+       if (!driver->base || !driver->devs)
+               return -EFAULT;
+
+       pmx = kzalloc(sizeof(*pmx), GFP_KERNEL);
+       if (!pmx)
+               return -ENOMEM;
+
+       pmx->base = (u32)driver->base;
+       pmx->mode_reg.offset = driver->mode_reg.offset;
+       pmx->mode_reg.mask = driver->mode_reg.mask;
+       pmx->mux_reg.offset = driver->mux_reg.offset;
+       pmx->mux_reg.mask = driver->mux_reg.mask;
+
+       /* choose mode to enable */
+       if (driver->mode) {
+               ret = pmx_mode_set(driver->mode);
+               if (ret)
+                       goto pmx_fail;
+       }
+       ret = pmx_devs_enable(driver->devs, driver->devs_count);
+       if (ret)
+               goto pmx_fail;
+
+       return 0;
+
+pmx_fail:
+       return ret;
+}
diff --git a/arch/arm/plat-spear/shirq.c b/arch/arm/plat-spear/shirq.c
new file mode 100644 (file)
index 0000000..2172d69
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * arch/arm/plat-spear/shirq.c
+ *
+ * SPEAr platform shared irq layer source file
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Viresh Kumar<viresh.kumar@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/spinlock.h>
+#include <plat/shirq.h>
+
+struct spear_shirq *shirq;
+static DEFINE_SPINLOCK(lock);
+
+static void shirq_irq_mask(unsigned irq)
+{
+       struct spear_shirq *shirq = get_irq_chip_data(irq);
+       u32 val, id = irq - shirq->dev_config[0].virq;
+       unsigned long flags;
+
+       if ((shirq->regs.enb_reg == -1) || shirq->dev_config[id].enb_mask == -1)
+               return;
+
+       spin_lock_irqsave(&lock, flags);
+       val = readl(shirq->regs.base + shirq->regs.enb_reg);
+       if (shirq->regs.reset_to_enb)
+               val |= shirq->dev_config[id].enb_mask;
+       else
+               val &= ~(shirq->dev_config[id].enb_mask);
+       writel(val, shirq->regs.base + shirq->regs.enb_reg);
+       spin_unlock_irqrestore(&lock, flags);
+}
+
+static void shirq_irq_unmask(unsigned irq)
+{
+       struct spear_shirq *shirq = get_irq_chip_data(irq);
+       u32 val, id = irq - shirq->dev_config[0].virq;
+       unsigned long flags;
+
+       if ((shirq->regs.enb_reg == -1) || shirq->dev_config[id].enb_mask == -1)
+               return;
+
+       spin_lock_irqsave(&lock, flags);
+       val = readl(shirq->regs.base + shirq->regs.enb_reg);
+       if (shirq->regs.reset_to_enb)
+               val &= ~(shirq->dev_config[id].enb_mask);
+       else
+               val |= shirq->dev_config[id].enb_mask;
+       writel(val, shirq->regs.base + shirq->regs.enb_reg);
+       spin_unlock_irqrestore(&lock, flags);
+}
+
+static struct irq_chip shirq_chip = {
+       .name           = "spear_shirq",
+       .ack            = shirq_irq_mask,
+       .mask           = shirq_irq_mask,
+       .unmask         = shirq_irq_unmask,
+};
+
+static void shirq_handler(unsigned irq, struct irq_desc *desc)
+{
+       u32 i, val, mask;
+       struct spear_shirq *shirq = get_irq_data(irq);
+
+       desc->chip->ack(irq);
+       while ((val = readl(shirq->regs.base + shirq->regs.status_reg) &
+                               shirq->regs.status_reg_mask)) {
+               for (i = 0; (i < shirq->dev_count) && val; i++) {
+                       if (!(shirq->dev_config[i].status_mask & val))
+                               continue;
+
+                       generic_handle_irq(shirq->dev_config[i].virq);
+
+                       /* clear interrupt */
+                       val &= ~shirq->dev_config[i].status_mask;
+                       if ((shirq->regs.clear_reg == -1) ||
+                                       shirq->dev_config[i].clear_mask == -1)
+                               continue;
+                       mask = readl(shirq->regs.base + shirq->regs.clear_reg);
+                       if (shirq->regs.reset_to_clear)
+                               mask &= ~shirq->dev_config[i].clear_mask;
+                       else
+                               mask |= shirq->dev_config[i].clear_mask;
+                       writel(mask, shirq->regs.base + shirq->regs.clear_reg);
+               }
+       }
+       desc->chip->unmask(irq);
+}
+
+int spear_shirq_register(struct spear_shirq *shirq)
+{
+       int i;
+
+       if (!shirq || !shirq->dev_config || !shirq->regs.base)
+               return -EFAULT;
+
+       if (!shirq->dev_count)
+               return -EINVAL;
+
+       set_irq_chained_handler(shirq->irq, shirq_handler);
+       for (i = 0; i < shirq->dev_count; i++) {
+               set_irq_chip(shirq->dev_config[i].virq, &shirq_chip);
+               set_irq_handler(shirq->dev_config[i].virq, handle_simple_irq);
+               set_irq_flags(shirq->dev_config[i].virq, IRQF_VALID);
+               set_irq_chip_data(shirq->dev_config[i].virq, shirq);
+       }
+
+       set_irq_data(shirq->irq, shirq);
+       return 0;
+}
diff --git a/arch/arm/plat-spear/time.c b/arch/arm/plat-spear/time.c
new file mode 100644 (file)
index 0000000..a1025d3
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * arch/arm/plat-spear/time.c
+ *
+ * Copyright (C) 2009 ST Microelectronics
+ * Shiraz Hashim<shiraz.hashim@st.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/clk.h>
+#include <linux/clockchips.h>
+#include <linux/clocksource.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/time.h>
+#include <linux/irq.h>
+#include <asm/mach/time.h>
+#include <mach/irqs.h>
+#include <mach/hardware.h>
+#include <mach/spear.h>
+#include <mach/generic.h>
+
+/*
+ * We would use TIMER0 and TIMER1 as clockevent and clocksource.
+ * Timer0 and Timer1 both belong to same gpt block in cpu subbsystem. Further
+ * they share same functional clock. Any change in one's functional clock will
+ * also affect other timer.
+ */
+
+#define CLKEVT 0       /* gpt0, channel0 as clockevent */
+#define CLKSRC 1       /* gpt0, channel1 as clocksource */
+
+/* Register offsets, x is channel number */
+#define CR(x)          ((x) * 0x80 + 0x80)
+#define IR(x)          ((x) * 0x80 + 0x84)
+#define LOAD(x)                ((x) * 0x80 + 0x88)
+#define COUNT(x)       ((x) * 0x80 + 0x8C)
+
+/* Reg bit definitions */
+#define CTRL_INT_ENABLE                0x0100
+#define CTRL_ENABLE            0x0020
+#define CTRL_ONE_SHOT          0x0010
+
+#define CTRL_PRESCALER1                0x0
+#define CTRL_PRESCALER2                0x1
+#define CTRL_PRESCALER4                0x2
+#define CTRL_PRESCALER8                0x3
+#define CTRL_PRESCALER16       0x4
+#define CTRL_PRESCALER32       0x5
+#define CTRL_PRESCALER64       0x6
+#define CTRL_PRESCALER128      0x7
+#define CTRL_PRESCALER256      0x8
+
+#define INT_STATUS             0x1
+
+static __iomem void *gpt_base;
+static struct clk *gpt_clk;
+
+static void clockevent_set_mode(enum clock_event_mode mode,
+                               struct clock_event_device *clk_event_dev);
+static int clockevent_next_event(unsigned long evt,
+                                struct clock_event_device *clk_event_dev);
+
+/*
+ * Following clocksource_set_clock and clockevent_set_clock picked
+ * from arch/mips/kernel/time.c
+ */
+
+void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
+{
+       u64 temp;
+       u32 shift;
+
+       /* Find a shift value */
+       for (shift = 32; shift > 0; shift--) {
+               temp = (u64) NSEC_PER_SEC << shift;
+               do_div(temp, clock);
+               if ((temp >> 32) == 0)
+                       break;
+       }
+       cs->shift = shift;
+       cs->mult = (u32) temp;
+}
+
+void __init clockevent_set_clock(struct clock_event_device *cd,
+       unsigned int clock)
+{
+       u64 temp;
+       u32 shift;
+
+       /* Find a shift value */
+       for (shift = 32; shift > 0; shift--) {
+               temp = (u64) clock << shift;
+               do_div(temp, NSEC_PER_SEC);
+               if ((temp >> 32) == 0)
+                       break;
+       }
+       cd->shift = shift;
+       cd->mult = (u32) temp;
+}
+
+static cycle_t clocksource_read_cycles(struct clocksource *cs)
+{
+       return (cycle_t) readw(gpt_base + COUNT(CLKSRC));
+}
+
+static struct clocksource clksrc = {
+       .name = "tmr1",
+       .rating = 200,          /* its a pretty decent clock */
+       .read = clocksource_read_cycles,
+       .mask = 0xFFFF,         /* 16 bits */
+       .mult = 0,              /* to be computed */
+       .shift = 0,             /* to be computed */
+       .flags = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static void spear_clocksource_init(void)
+{
+       u32 tick_rate;
+       u16 val;
+
+       /* program the prescaler (/256)*/
+       writew(CTRL_PRESCALER256, gpt_base + CR(CLKSRC));
+
+       /* find out actual clock driving Timer */
+       tick_rate = clk_get_rate(gpt_clk);
+       tick_rate >>= CTRL_PRESCALER256;
+
+       writew(0xFFFF, gpt_base + LOAD(CLKSRC));
+
+       val = readw(gpt_base + CR(CLKSRC));
+       val &= ~CTRL_ONE_SHOT;  /* autoreload mode */
+       val |= CTRL_ENABLE ;
+       writew(val, gpt_base + CR(CLKSRC));
+
+       clocksource_set_clock(&clksrc, tick_rate);
+
+       /* register the clocksource */
+       clocksource_register(&clksrc);
+}
+
+static struct clock_event_device clkevt = {
+       .name = "tmr0",
+       .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
+       .set_mode = clockevent_set_mode,
+       .set_next_event = clockevent_next_event,
+       .shift = 0,     /* to be computed */
+};
+
+static void clockevent_set_mode(enum clock_event_mode mode,
+                               struct clock_event_device *clk_event_dev)
+{
+       u32 period;
+       u16 val;
+
+       /* stop the timer */
+       val = readw(gpt_base + CR(CLKEVT));
+       val &= ~CTRL_ENABLE;
+       writew(val, gpt_base + CR(CLKEVT));
+
+       switch (mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               period = clk_get_rate(gpt_clk) / HZ;
+               period >>= CTRL_PRESCALER16;
+               writew(period, gpt_base + LOAD(CLKEVT));
+
+               val = readw(gpt_base + CR(CLKEVT));
+               val &= ~CTRL_ONE_SHOT;
+               val |= CTRL_ENABLE | CTRL_INT_ENABLE;
+               writew(val, gpt_base + CR(CLKEVT));
+
+               break;
+       case CLOCK_EVT_MODE_ONESHOT:
+               val = readw(gpt_base + CR(CLKEVT));
+               val |= CTRL_ONE_SHOT;
+               writew(val, gpt_base + CR(CLKEVT));
+
+               break;
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       case CLOCK_EVT_MODE_RESUME:
+
+               break;
+       default:
+               pr_err("Invalid mode requested\n");
+               break;
+       }
+}
+
+static int clockevent_next_event(unsigned long cycles,
+                                struct clock_event_device *clk_event_dev)
+{
+       u16 val;
+
+       writew(cycles, gpt_base + LOAD(CLKEVT));
+
+       val = readw(gpt_base + CR(CLKEVT));
+       val |= CTRL_ENABLE | CTRL_INT_ENABLE;
+       writew(val, gpt_base + CR(CLKEVT));
+
+       return 0;
+}
+
+static irqreturn_t spear_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = &clkevt;
+
+       writew(INT_STATUS, gpt_base + IR(CLKEVT));
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static struct irqaction spear_timer_irq = {
+       .name = "timer",
+       .flags = IRQF_DISABLED | IRQF_TIMER,
+       .handler = spear_timer_interrupt
+};
+
+static void __init spear_clockevent_init(void)
+{
+       u32 tick_rate;
+
+       /* program the prescaler */
+       writew(CTRL_PRESCALER16, gpt_base + CR(CLKEVT));
+
+       tick_rate = clk_get_rate(gpt_clk);
+       tick_rate >>= CTRL_PRESCALER16;
+
+       clockevent_set_clock(&clkevt, tick_rate);
+
+       clkevt.max_delta_ns = clockevent_delta2ns(0xfff0,
+                       &clkevt);
+       clkevt.min_delta_ns = clockevent_delta2ns(3, &clkevt);
+
+       clkevt.cpumask = cpumask_of(0);
+
+       clockevents_register_device(&clkevt);
+
+       setup_irq(SPEAR_GPT0_CHAN0_IRQ, &spear_timer_irq);
+}
+
+void __init spear_setup_timer(void)
+{
+       struct clk *pll3_clk;
+
+       if (!request_mem_region(SPEAR_GPT0_BASE, SZ_1K, "gpt0")) {
+               pr_err("%s:cannot get IO addr\n", __func__);
+               return;
+       }
+
+       gpt_base = (void __iomem *)ioremap(SPEAR_GPT0_BASE, SZ_1K);
+       if (!gpt_base) {
+               pr_err("%s:ioremap failed for gpt\n", __func__);
+               goto err_mem;
+       }
+
+       gpt_clk = clk_get_sys("gpt0", NULL);
+       if (!gpt_clk) {
+               pr_err("%s:couldn't get clk for gpt\n", __func__);
+               goto err_iomap;
+       }
+
+       pll3_clk = clk_get(NULL, "pll3_48m_clk");
+       if (!pll3_clk) {
+               pr_err("%s:couldn't get PLL3 as parent for gpt\n", __func__);
+               goto err_iomap;
+       }
+
+       clk_set_parent(gpt_clk, pll3_clk);
+
+       spear_clockevent_init();
+       spear_clocksource_init();
+
+       return;
+
+err_iomap:
+       iounmap(gpt_base);
+
+err_mem:
+       release_mem_region(SPEAR_GPT0_BASE, SZ_1K);
+}
+
+struct sys_timer spear_sys_timer = {
+       .init = spear_setup_timer,
+};
diff --git a/arch/arm/plat-versatile/Makefile b/arch/arm/plat-versatile/Makefile
new file mode 100644 (file)
index 0000000..9b1a668
--- /dev/null
@@ -0,0 +1,4 @@
+obj-y  := clock.o
+obj-$(CONFIG_ARM_TIMER_SP804) += timer-sp.o
+obj-$(CONFIG_ARCH_REALVIEW) += sched-clock.o
+obj-$(CONFIG_ARCH_VERSATILE) += sched-clock.o
similarity index 59%
rename from arch/arm/mach-integrator/clock.c
rename to arch/arm/plat-versatile/clock.c
index 989ecf5..5c8b656 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  linux/arch/arm/mach-integrator/clock.c
+ *  linux/arch/arm/plat-versatile/clock.c
  *
  *  Copyright (C) 2004 ARM Limited.
  *  Written by Deep Blue Solutions Limited.
@@ -14,7 +14,8 @@
 #include <linux/clk.h>
 #include <linux/mutex.h>
 
-#include <asm/clkdev.h>
+#include <asm/hardware/icst.h>
+
 #include <mach/clkdev.h>
 
 int clk_enable(struct clk *clk)
@@ -36,24 +37,38 @@ EXPORT_SYMBOL(clk_get_rate);
 
 long clk_round_rate(struct clk *clk, unsigned long rate)
 {
-       struct icst525_vco vco;
-       vco = icst525_khz_to_vco(clk->params, rate / 1000);
-       return icst525_khz(clk->params, vco) * 1000;
+       long ret = -EIO;
+       if (clk->ops && clk->ops->round)
+               ret = clk->ops->round(clk, rate);
+       return ret;
 }
 EXPORT_SYMBOL(clk_round_rate);
 
 int clk_set_rate(struct clk *clk, unsigned long rate)
 {
        int ret = -EIO;
-
-       if (clk->setvco) {
-               struct icst525_vco vco;
-
-               vco = icst525_khz_to_vco(clk->params, rate / 1000);
-               clk->rate = icst525_khz(clk->params, vco) * 1000;
-               clk->setvco(clk, vco);
-               ret = 0;
-       }
+       if (clk->ops && clk->ops->set)
+               ret = clk->ops->set(clk, rate);
        return ret;
 }
 EXPORT_SYMBOL(clk_set_rate);
+
+long icst_clk_round(struct clk *clk, unsigned long rate)
+{
+       struct icst_vco vco;
+       vco = icst_hz_to_vco(clk->params, rate);
+       return icst_hz(clk->params, vco);
+}
+EXPORT_SYMBOL(icst_clk_round);
+
+int icst_clk_set(struct clk *clk, unsigned long rate)
+{
+       struct icst_vco vco;
+
+       vco = icst_hz_to_vco(clk->params, rate);
+       clk->rate = icst_hz(clk->params, vco);
+       clk->ops->setvco(clk, vco);
+
+       return 0;
+}
+EXPORT_SYMBOL(icst_clk_set);
diff --git a/arch/arm/plat-versatile/include/plat/clock.h b/arch/arm/plat-versatile/include/plat/clock.h
new file mode 100644 (file)
index 0000000..3cfb024
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef PLAT_CLOCK_H
+#define PLAT_CLOCK_H
+
+#include <asm/hardware/icst.h>
+
+struct clk_ops {
+       long    (*round)(struct clk *, unsigned long);
+       int     (*set)(struct clk *, unsigned long);
+       void    (*setvco)(struct clk *, struct icst_vco);
+};
+
+int icst_clk_set(struct clk *, unsigned long);
+long icst_clk_round(struct clk *, unsigned long);
+
+#endif
diff --git a/arch/arm/plat-versatile/include/plat/timer-sp.h b/arch/arm/plat-versatile/include/plat/timer-sp.h
new file mode 100644 (file)
index 0000000..21e75e3
--- /dev/null
@@ -0,0 +1,2 @@
+void sp804_clocksource_init(void __iomem *);
+void sp804_clockevents_init(void __iomem *, unsigned int);
diff --git a/arch/arm/plat-versatile/sched-clock.c b/arch/arm/plat-versatile/sched-clock.c
new file mode 100644 (file)
index 0000000..9768cf7
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  linux/arch/arm/plat-versatile/sched-clock.c
+ *
+ *  Copyright (C) 1999 - 2003 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <linux/cnt32_to_63.h>
+#include <linux/io.h>
+#include <asm/div64.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+
+#ifdef VERSATILE_SYS_BASE
+#define REFCOUNTER     (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_24MHz_OFFSET)
+#endif
+
+#ifdef REALVIEW_SYS_BASE
+#define REFCOUNTER     (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_24MHz_OFFSET)
+#endif
+
+/*
+ * This is the Realview and Versatile sched_clock implementation.  This
+ * has a resolution of 41.7ns, and a maximum value of about 35583 days.
+ *
+ * The return value is guaranteed to be monotonic in that range as
+ * long as there is always less than 89 seconds between successive
+ * calls to this function.
+ */
+unsigned long long sched_clock(void)
+{
+       unsigned long long v = cnt32_to_63(readl(REFCOUNTER));
+
+       /* the <<1 gets rid of the cnt_32_to_63 top bit saving on a bic insn */
+       v *= 125<<1;
+       do_div(v, 3<<1);
+
+       return v;
+}
diff --git a/arch/arm/plat-versatile/timer-sp.c b/arch/arm/plat-versatile/timer-sp.c
new file mode 100644 (file)
index 0000000..fb0d1c2
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ *  linux/arch/arm/plat-versatile/timer-sp.c
+ *
+ *  Copyright (C) 1999 - 2003 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <linux/clocksource.h>
+#include <linux/clockchips.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+
+#include <asm/hardware/arm_timer.h>
+
+#include <plat/timer-sp.h>
+
+/*
+ * These timers are currently always setup to be clocked at 1MHz.
+ */
+#define TIMER_FREQ_KHZ (1000)
+#define TIMER_RELOAD   (TIMER_FREQ_KHZ * 1000 / HZ)
+
+static void __iomem *clksrc_base;
+
+static cycle_t sp804_read(struct clocksource *cs)
+{
+       return ~readl(clksrc_base + TIMER_VALUE);
+}
+
+static struct clocksource clocksource_sp804 = {
+       .name           = "timer3",
+       .rating         = 200,
+       .read           = sp804_read,
+       .mask           = CLOCKSOURCE_MASK(32),
+       .shift          = 20,
+       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+void __init sp804_clocksource_init(void __iomem *base)
+{
+       struct clocksource *cs = &clocksource_sp804;
+
+       clksrc_base = base;
+
+       /* setup timer 0 as free-running clocksource */
+       writel(0, clksrc_base + TIMER_CTRL);
+       writel(0xffffffff, clksrc_base + TIMER_LOAD);
+       writel(0xffffffff, clksrc_base + TIMER_VALUE);
+       writel(TIMER_CTRL_32BIT | TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC,
+               clksrc_base + TIMER_CTRL);
+
+       cs->mult = clocksource_khz2mult(TIMER_FREQ_KHZ, cs->shift);
+       clocksource_register(cs);
+}
+
+
+static void __iomem *clkevt_base;
+
+/*
+ * IRQ handler for the timer
+ */
+static irqreturn_t sp804_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = dev_id;
+
+       /* clear the interrupt */
+       writel(1, clkevt_base + TIMER_INTCLR);
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static void sp804_set_mode(enum clock_event_mode mode,
+       struct clock_event_device *evt)
+{
+       unsigned long ctrl = TIMER_CTRL_32BIT | TIMER_CTRL_IE;
+
+       writel(ctrl, clkevt_base + TIMER_CTRL);
+
+       switch (mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               writel(TIMER_RELOAD, clkevt_base + TIMER_LOAD);
+               ctrl |= TIMER_CTRL_PERIODIC | TIMER_CTRL_ENABLE;
+               break;
+
+       case CLOCK_EVT_MODE_ONESHOT:
+               /* period set, and timer enabled in 'next_event' hook */
+               ctrl |= TIMER_CTRL_ONESHOT;
+               break;
+
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+       default:
+               break;
+       }
+
+       writel(ctrl, clkevt_base + TIMER_CTRL);
+}
+
+static int sp804_set_next_event(unsigned long next,
+       struct clock_event_device *evt)
+{
+       unsigned long ctrl = readl(clkevt_base + TIMER_CTRL);
+
+       writel(next, clkevt_base + TIMER_LOAD);
+       writel(ctrl | TIMER_CTRL_ENABLE, clkevt_base + TIMER_CTRL);
+
+       return 0;
+}
+
+static struct clock_event_device sp804_clockevent = {
+       .name           = "timer0",
+       .shift          = 32,
+       .features       = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
+       .set_mode       = sp804_set_mode,
+       .set_next_event = sp804_set_next_event,
+       .rating         = 300,
+       .cpumask        = cpu_all_mask,
+};
+
+static struct irqaction sp804_timer_irq = {
+       .name           = "timer",
+       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+       .handler        = sp804_timer_interrupt,
+       .dev_id         = &sp804_clockevent,
+};
+
+void __init sp804_clockevents_init(void __iomem *base, unsigned int timer_irq)
+{
+       struct clock_event_device *evt = &sp804_clockevent;
+
+       clkevt_base = base;
+
+       evt->irq = timer_irq;
+       evt->mult = div_sc(TIMER_FREQ_KHZ, NSEC_PER_MSEC, evt->shift);
+       evt->max_delta_ns = clockevent_delta2ns(0xffffffff, evt);
+       evt->min_delta_ns = clockevent_delta2ns(0xf, evt);
+
+       setup_irq(timer_irq, &sp804_timer_irq);
+       clockevents_register_device(evt);
+}
index b131c27..bbce6a1 100644 (file)
@@ -19,7 +19,7 @@
 
 #define ATOMIC_INIT(i)  { (i) }
 
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 /*
index fd0c5d7..7a9c03d 100644 (file)
@@ -81,7 +81,7 @@ static inline struct thread_info *current_thread_info(void)
                                           TIF_NEED_RESCHED */
 #define TIF_BREAKPOINT         4       /* enter monitor mode on return */
 #define TIF_SINGLE_STEP                5       /* single step in progress */
-#define TIF_MEMDIE             6
+#define TIF_MEMDIE             6       /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    7       /* restore signal mask in do_signal */
 #define TIF_CPU_GOING_TO_SLEEP 8       /* CPU is entering sleep 0 mode */
 #define TIF_NOTIFY_RESUME      9       /* callback before returning to user */
index f27aa3b..668ed28 100644 (file)
@@ -110,17 +110,17 @@ static struct clock_event_device comparator = {
        .set_mode       = comparator_mode,
 };
 
+void read_persistent_clock(struct timespec *ts)
+{
+       ts->tv_sec = mktime(2007, 1, 1, 0, 0, 0);
+       ts->tv_nsec = 0;
+}
+
 void __init time_init(void)
 {
        unsigned long counter_hz;
        int ret;
 
-       xtime.tv_sec = mktime(2007, 1, 1, 0, 0, 0);
-       xtime.tv_nsec = 0;
-
-       set_normalized_timespec(&wall_to_monotonic,
-                               -xtime.tv_sec, -xtime.tv_nsec);
-
        /* figure rate for counter */
        counter_hz = clk_get_rate(boot_cpu_data.clk);
        counter.mult = clocksource_hz2mult(counter_hz, counter.shift);
index e9a5614..02560fd 100644 (file)
@@ -98,7 +98,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_POLLING_NRFLAG     3       /* true if poll_idle() is polling
                                           TIF_NEED_RESCHED */
-#define TIF_MEMDIE             4
+#define TIF_MEMDIE             4       /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    5       /* restore signal mask in do_signal() */
 #define TIF_FREEZE             6       /* is freezing for suspend */
 #define TIF_IRQ_SYNC           7       /* sync pipeline stage */
index cb7a01d..8c9a43d 100644 (file)
@@ -353,9 +353,15 @@ void bfin_coretmr_clockevent_init(void)
 #endif /* CONFIG_TICKSOURCE_CORETMR */
 
 
-void __init time_init(void)
+void read_persistent_clock(struct timespec *ts)
 {
        time_t secs_since_1970 = (365 * 37 + 9) * 24 * 60 * 60; /* 1 Jan 2007 */
+       ts->tv_sec = secs_since_1970;
+       ts->tv_nsec = 0;
+}
+
+void __init time_init(void)
+{
 
 #ifdef CONFIG_RTC_DRV_BFIN
        /* [#2663] hack to filter junk RTC values that would cause
@@ -368,11 +374,6 @@ void __init time_init(void)
        }
 #endif
 
-       /* Initialize xtime. From now on, xtime is updated with timer interrupts */
-       xtime.tv_sec = secs_since_1970;
-       xtime.tv_nsec = 0;
-       set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
-
        bfin_cs_cycles_init();
        bfin_cs_gptimer0_init();
 
index 13c1ee3..c911361 100644 (file)
@@ -112,11 +112,6 @@ u32 arch_gettimeoffset(void)
 }
 #endif
 
-static inline int set_rtc_mmss(unsigned long nowtime)
-{
-       return 0;
-}
-
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick
@@ -126,29 +121,8 @@ __attribute__((l1_text))
 #endif
 irqreturn_t timer_interrupt(int irq, void *dummy)
 {
-       /* last time the cmos clock got updated */
-       static long last_rtc_update;
-
        write_seqlock(&xtime_lock);
        do_timer(1);
-
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        */
-       if (ntp_synced() &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           (xtime.tv_nsec / NSEC_PER_USEC) >=
-           500000 - ((unsigned)TICK_SIZE) / 2
-           && (xtime.tv_nsec / NSEC_PER_USEC) <=
-           500000 + ((unsigned)TICK_SIZE) / 2) {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else
-                       /* Do it again in 60s. */
-                       last_rtc_update = xtime.tv_sec - 600;
-       }
        write_sequnlock(&xtime_lock);
 
 #ifdef CONFIG_IPIPE
@@ -161,10 +135,15 @@ irqreturn_t timer_interrupt(int irq, void *dummy)
        return IRQ_HANDLED;
 }
 
-void __init time_init(void)
+void read_persistent_clock(struct timespec *ts)
 {
        time_t secs_since_1970 = (365 * 37 + 9) * 24 * 60 * 60; /* 1 Jan 2007 */
+       ts->tv_sec = secs_since_1970;
+       ts->tv_nsec = 0;
+}
 
+void __init time_init(void)
+{
 #ifdef CONFIG_RTC_DRV_BFIN
        /* [#2663] hack to filter junk RTC values that would cause
         * userspace to have to deal with time values greater than
@@ -176,11 +155,5 @@ void __init time_init(void)
        }
 #endif
 
-       /* Initialize xtime. From now on, xtime is updated with timer interrupts */
-       xtime.tv_sec = secs_since_1970;
-       xtime.tv_nsec = 0;
-
-       wall_to_monotonic.tv_sec = -xtime.tv_sec;
-
        time_sched_init(timer_interrupt);
 }
index 059eac6..e25bf44 100644 (file)
@@ -23,6 +23,9 @@ config RWSEM_XCHGADD_ALGORITHM
 config GENERIC_TIME
        def_bool y
 
+config GENERIC_CMOS_UPDATE
+       def_bool y
+
 config ARCH_USES_GETTIMEOFFSET
        def_bool y
 
index 31ca141..30adae5 100644 (file)
@@ -26,7 +26,6 @@
 /* it will make jiffies at 96 hz instead of 100 hz though */
 #undef USE_CASCADE_TIMERS
 
-extern void update_xtime_from_cmos(void);
 extern int set_rtc_mmss(unsigned long nowtime);
 extern int have_rtc;
 
@@ -188,8 +187,6 @@ stop_watchdog(void)
 #endif 
 }
 
-/* last time the cmos clock got updated */
-static long last_rtc_update = 0;
 
 /*
  * timer_interrupt() needs to keep up the real-time clock,
@@ -232,24 +229,6 @@ timer_interrupt(int irq, void *dev_id)
        do_timer(1);
        
         cris_do_profile(regs); /* Save profiling information */
-
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        *
-        * The division here is not time critical since it will run once in 
-        * 11 minutes
-        */
-       if (ntp_synced() &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           (xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 &&
-           (xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else
-                       last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
-       }
         return IRQ_HANDLED;
 }
 
@@ -274,22 +253,10 @@ time_init(void)
         */
        loops_per_usec = 50;
 
-       if(RTC_INIT() < 0) {
-               /* no RTC, start at 1980 */
-               xtime.tv_sec = 0;
-               xtime.tv_nsec = 0;
+       if(RTC_INIT() < 0)
                have_rtc = 0;
-       } else {                
-               /* get the current time */
+       else
                have_rtc = 1;
-               update_xtime_from_cmos();
-       }
-
-       /*
-        * Initialize wall_to_monotonic such that adding it to xtime will yield zero, the
-        * tv_nsec field must be normalized (i.e., 0 <= nsec < NSEC_PER_SEC).
-        */
-       set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
 
        /* Setup the etrax timers
         * Base frequency is 25000 hz, divider 250 -> 100 HZ
index b1920d8..1ee0e10 100644 (file)
@@ -44,7 +44,6 @@ unsigned long timer_regs[NR_CPUS] =
 #endif
 };
 
-extern void update_xtime_from_cmos(void);
 extern int set_rtc_mmss(unsigned long nowtime);
 extern int have_rtc;
 
@@ -198,9 +197,6 @@ handle_watchdog_bite(struct pt_regs* regs)
 #endif
 }
 
-/* Last time the cmos clock got updated. */
-static long last_rtc_update = 0;
-
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick.
@@ -238,25 +234,6 @@ timer_interrupt(int irq, void *dev_id)
 
        /* Call the real timer interrupt handler */
        do_timer(1);
-
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        *
-        * The division here is not time critical since it will run once in
-        * 11 minutes
-        */
-       if ((time_status & STA_UNSYNC) == 0 &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           (xtime.tv_nsec / 1000) >= 500000 - (tick_nsec / 1000) / 2 &&
-           (xtime.tv_nsec / 1000) <= 500000 + (tick_nsec / 1000) / 2) {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else
-                       /* Do it again in 60 s */
-                       last_rtc_update = xtime.tv_sec - 600;
-       }
         return IRQ_HANDLED;
 }
 
@@ -309,23 +286,10 @@ time_init(void)
         */
        loops_per_usec = 50;
 
-       if(RTC_INIT() < 0) {
-               /* No RTC, start at 1980 */
-               xtime.tv_sec = 0;
-               xtime.tv_nsec = 0;
+       if(RTC_INIT() < 0)
                have_rtc = 0;
-       } else {
-               /* Get the current time */
+       else
                have_rtc = 1;
-               update_xtime_from_cmos();
-       }
-
-       /*
-        * Initialize wall_to_monotonic such that adding it to
-        * xtime will yield zero, the tv_nsec field must be normalized
-        * (i.e., 0 <= nsec < NSEC_PER_SEC).
-        */
-       set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
 
        /* Start CPU local timer. */
        cris_timer_init();
index a6aca81..88dc9b9 100644 (file)
@@ -15,7 +15,7 @@
 
 #define ATOMIC_INIT(i)  { (i) }
 
-#define atomic_read(v) ((v)->counter)
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
 #define atomic_set(v,i) (((v)->counter) = (i))
 
 /* These should be written in asm but we do it in C for now. */
index c3aade3..9177606 100644 (file)
@@ -85,7 +85,7 @@ struct thread_info {
 #define TIF_NEED_RESCHED       3       /* rescheduling necessary */
 #define TIF_RESTORE_SIGMASK    9       /* restore signal mask in do_signal() */
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             17
+#define TIF_MEMDIE             17      /* is terminating due to OOM killer */
 #define TIF_FREEZE             18      /* is freezing for suspend */
 
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
index a05dd31..c72730d 100644 (file)
@@ -98,6 +98,8 @@ unsigned long
 get_cmos_time(void)
 {
        unsigned int year, mon, day, hour, min, sec;
+       if(!have_rtc)
+               return 0;
 
        sec = CMOS_READ(RTC_SECONDS);
        min = CMOS_READ(RTC_MINUTES);
@@ -119,19 +121,19 @@ get_cmos_time(void)
        return mktime(year, mon, day, hour, min, sec);
 }
 
-/* update xtime from the CMOS settings. used when /dev/rtc gets a SET_TIME.
- * TODO: this doesn't reset the fancy NTP phase stuff as do_settimeofday does.
- */
 
-void
-update_xtime_from_cmos(void)
+int update_persistent_clock(struct timespec now)
 {
-       if(have_rtc) {
-               xtime.tv_sec = get_cmos_time();
-               xtime.tv_nsec = 0;
-       }
+       return set_rtc_mmss(now.tv_sec);
 }
 
+void read_persistent_clock(struct timespec *ts)
+{
+       ts->tv_sec = get_cmos_time();
+       ts->tv_nsec = 0;
+}
+
+
 extern void cris_profile_sample(struct pt_regs* regs);
 
 void
index 00a57af..fae32c7 100644 (file)
@@ -36,7 +36,7 @@
 #define smp_mb__after_atomic_inc()     barrier()
 
 #define ATOMIC_INIT(i)         { (i) }
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = (i))
 
 #ifndef CONFIG_FRV_OUTOFLINE_ATOMIC_OPS
index e608e05..11f33ea 100644 (file)
@@ -113,7 +113,7 @@ register struct thread_info *__current_thread_info asm("gr15");
 #define TIF_SINGLESTEP         4       /* restore singlestep on return to user mode */
 #define TIF_RESTORE_SIGMASK    5       /* restore signal mask in do_signal() */
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             17      /* OOM killer killed process */
+#define TIF_MEMDIE             17      /* is terminating due to OOM killer */
 #define TIF_FREEZE             18      /* freezing for suspend */
 
 #define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
index fb0ce75..0ddbbae 100644 (file)
@@ -48,20 +48,12 @@ static struct irqaction timer_irq  = {
        .name = "timer",
 };
 
-static inline int set_rtc_mmss(unsigned long nowtime)
-{
-       return -1;
-}
-
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick
  */
 static irqreturn_t timer_interrupt(int irq, void *dummy)
 {
-       /* last time the cmos clock got updated */
-       static long last_rtc_update = 0;
-
        profile_tick(CPU_PROFILING);
        /*
         * Here we are in the timer irq handler. We just have irqs locally
@@ -74,22 +66,6 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
 
        do_timer(1);
 
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        */
-       if (ntp_synced() &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
-           (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2
-           ) {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else
-                       last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
-       }
-
 #ifdef CONFIG_HEARTBEAT
        static unsigned short n;
        n++;
@@ -119,7 +95,8 @@ void time_divisor_init(void)
        __set_TCSR_DATA(0, base >> 8);
 }
 
-void time_init(void)
+
+void read_persistent_clock(struct timespec *ts)
 {
        unsigned int year, mon, day, hour, min, sec;
 
@@ -135,9 +112,12 @@ void time_init(void)
 
        if ((year += 1900) < 1970)
                year += 100;
-       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       xtime.tv_nsec = 0;
+       ts->tv_sec = mktime(year, mon, day, hour, min, sec);
+       ts->tv_nsec = 0;
+}
 
+void time_init(void)
+{
        /* install scheduling interrupt handler */
        setup_irq(IRQ_CPU_TIMER0, &timer_irq);
 
index 33c8c0f..e936804 100644 (file)
@@ -10,7 +10,7 @@
 
 #define ATOMIC_INIT(i) { (i) }
 
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 #include <asm/system.h>
index 70e67e4..d6f1784 100644 (file)
@@ -87,7 +87,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_POLLING_NRFLAG     3       /* true if poll_idle() is polling
                                           TIF_NEED_RESCHED */
-#define TIF_MEMDIE             4
+#define TIF_MEMDIE             4       /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    5       /* restore signal mask in do_signal() */
 #define TIF_NOTIFY_RESUME      6       /* callback before returning to user */
 #define TIF_FREEZE             16      /* is freezing for suspend */
index 7f2d6cf..165005a 100644 (file)
@@ -41,7 +41,7 @@ void h8300_timer_tick(void)
        update_process_times(user_mode(get_irq_regs()));
 }
 
-void __init time_init(void)
+void read_persistent_clock(struct timespec *ts)
 {
        unsigned int year, mon, day, hour, min, sec;
 
@@ -56,8 +56,12 @@ void __init time_init(void)
 #endif
        if ((year += 1900) < 1970)
                year += 100;
-       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       xtime.tv_nsec = 0;
+       ts->tv_sec = mktime(year, mon, day, hour, min, sec);
+       ts->tv_nsec = 0;
+}
+
+void __init time_init(void)
+{
 
        h8300_timer_setup();
 }
index 4d4f418..9676100 100644 (file)
@@ -59,9 +59,6 @@ config NEED_DMA_MAP_STATE
 config SWIOTLB
        bool
 
-config IOMMU_HELPER
-       bool
-
 config GENERIC_LOCKBREAK
        def_bool n
 
index e14c492..4ce8d13 100644 (file)
@@ -2046,13 +2046,13 @@ acpi_sba_ioc_add(struct acpi_device *device)
        struct ioc *ioc;
        acpi_status status;
        u64 hpa, length;
-       struct acpi_device_info *dev_info;
+       struct acpi_device_info *adi;
 
        status = hp_acpi_csr_space(device->handle, &hpa, &length);
        if (ACPI_FAILURE(status))
                return 1;
 
-       status = acpi_get_object_info(device->handle, &dev_info);
+       status = acpi_get_object_info(device->handle, &adi);
        if (ACPI_FAILURE(status))
                return 1;
 
@@ -2060,13 +2060,13 @@ acpi_sba_ioc_add(struct acpi_device *device)
         * For HWP0001, only SBA appears in ACPI namespace.  It encloses the PCI
         * root bridges, and its CSR space includes the IOC function.
         */
-       if (strncmp("HWP0001", dev_info->hardware_id.string, 7) == 0) {
+       if (strncmp("HWP0001", adi->hardware_id.string, 7) == 0) {
                hpa += ZX1_IOC_OFFSET;
                /* zx1 based systems default to kernel page size iommu pages */
                if (!iovp_shift)
                        iovp_shift = min(PAGE_SHIFT, 16);
        }
-       kfree(dev_info);
+       kfree(adi);
 
        /*
         * default anything not caught above or specified on cmdline to 4k
index 88405cb..4e19484 100644 (file)
@@ -21,8 +21,8 @@
 #define ATOMIC_INIT(i)         ((atomic_t) { (i) })
 #define ATOMIC64_INIT(i)       ((atomic64_t) { (i) })
 
-#define atomic_read(v)         ((v)->counter)
-#define atomic64_read(v)       ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
 
 #define atomic_set(v,i)                (((v)->counter) = (i))
 #define atomic64_set(v,i)      (((v)->counter) = (i))
index 6ebc229..9da3df6 100644 (file)
@@ -437,17 +437,18 @@ __fls (unsigned long x)
  * hweightN: returns the hamming weight (i.e. the number
  * of bits set) of a N-bit word
  */
-static __inline__ unsigned long
-hweight64 (unsigned long x)
+static __inline__ unsigned long __arch_hweight64(unsigned long x)
 {
        unsigned long result;
        result = ia64_popcnt(x);
        return result;
 }
 
-#define hweight32(x)   (unsigned int) hweight64((x) & 0xfffffffful)
-#define hweight16(x)   (unsigned int) hweight64((x) & 0xfffful)
-#define hweight8(x)    (unsigned int) hweight64((x) & 0xfful)
+#define __arch_hweight32(x) ((unsigned int) __arch_hweight64((x) & 0xfffffffful))
+#define __arch_hweight16(x) ((unsigned int) __arch_hweight64((x) & 0xfffful))
+#define __arch_hweight8(x)  ((unsigned int) __arch_hweight64((x) & 0xfful))
+
+#include <asm-generic/bitops/const_hweight.h>
 
 #endif /* __KERNEL__ */
 
index f2ca320..e0de617 100644 (file)
 
 static inline int pfn_to_nid(unsigned long pfn)
 {
-#ifdef CONFIG_NUMA
        extern int paddr_to_nid(unsigned long);
        int nid = paddr_to_nid(pfn << PAGE_SHIFT);
        if (nid < 0)
                return 0;
        else
                return nid;
-#else
-       return 0;
-#endif
 }
 
 #ifdef CONFIG_IA64_DIG /* DIG systems are small */
index f7c00a5..1bd4082 100644 (file)
@@ -39,7 +39,10 @@ extern void *per_cpu_init(void);
  * On the positive side, using __ia64_per_cpu_var() instead of __get_cpu_var() is slightly
  * more efficient.
  */
-#define __ia64_per_cpu_var(var)        var
+#define __ia64_per_cpu_var(var) (*({                                   \
+       __verify_pcpu_ptr(&(var));                                      \
+       ((typeof(var) __kernel __force *)&(var));                       \
+}))
 
 #include <asm-generic/percpu.h>
 
index 8ce2e38..b6a5ba2 100644 (file)
@@ -102,7 +102,7 @@ struct thread_info {
 #define TIF_SINGLESTEP         4       /* restore singlestep on return to user mode */
 #define TIF_NOTIFY_RESUME      6       /* resumption notification requested */
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             17
+#define TIF_MEMDIE             17      /* is terminating due to OOM killer */
 #define TIF_MCA_INIT           18      /* this task is processing MCA or INIT */
 #define TIF_DB_DISABLED                19      /* debug trap disabled for fsyscall */
 #define TIF_FREEZE             20      /* is freezing for suspend */
index 4d1a7e9..c6c90f3 100644 (file)
@@ -785,6 +785,14 @@ int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
        return 0;
 }
 
+int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
+{
+       if (isa_irq >= 16)
+               return -1;
+       *gsi = isa_irq;
+       return 0;
+}
+
 /*
  *  ACPI based hotplug CPU support
  */
index b0b4e6e..22f6152 100644 (file)
@@ -113,7 +113,7 @@ processor_get_freq (
        dprintk("processor_get_freq\n");
 
        saved_mask = current->cpus_allowed;
-       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+       set_cpus_allowed_ptr(current, cpumask_of(cpu));
        if (smp_processor_id() != cpu)
                goto migrate_end;
 
@@ -121,7 +121,7 @@ processor_get_freq (
        ret = processor_get_pstate(&value);
 
        if (ret) {
-               set_cpus_allowed(current, saved_mask);
+               set_cpus_allowed_ptr(current, &saved_mask);
                printk(KERN_WARNING "get performance failed with error %d\n",
                       ret);
                ret = 0;
@@ -131,7 +131,7 @@ processor_get_freq (
        ret = (clock_freq*1000);
 
 migrate_end:
-       set_cpus_allowed(current, saved_mask);
+       set_cpus_allowed_ptr(current, &saved_mask);
        return ret;
 }
 
@@ -151,7 +151,7 @@ processor_set_freq (
        dprintk("processor_set_freq\n");
 
        saved_mask = current->cpus_allowed;
-       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+       set_cpus_allowed_ptr(current, cpumask_of(cpu));
        if (smp_processor_id() != cpu) {
                retval = -EAGAIN;
                goto migrate_end;
@@ -208,7 +208,7 @@ processor_set_freq (
        retval = 0;
 
 migrate_end:
-       set_cpus_allowed(current, saved_mask);
+       set_cpus_allowed_ptr(current, &saved_mask);
        return (retval);
 }
 
index 6404793..f14c35f 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/threads.h>
 #include <linux/bitops.h>
 #include <linux/irq.h>
+#include <linux/ratelimit.h>
 
 #include <asm/delay.h>
 #include <asm/intrinsics.h>
@@ -467,13 +468,9 @@ ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
                sp = ia64_getreg(_IA64_REG_SP);
 
                if ((sp - bsp) < 1024) {
-                       static unsigned char count;
-                       static long last_time;
+                       static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
 
-                       if (time_after(jiffies, last_time + 5 * HZ))
-                               count = 0;
-                       if (++count < 5) {
-                               last_time = jiffies;
+                       if (__ratelimit(&ratelimit)) {
                                printk("ia64_handle_irq: DANGER: less than "
                                       "1KB of free stack space!!\n"
                                       "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
index e6676fc..aa8b5fa 100644 (file)
@@ -404,10 +404,9 @@ static void
 call_on_cpu(int cpu, void (*fn)(void *), void *arg)
 {
        cpumask_t save_cpus_allowed = current->cpus_allowed;
-       cpumask_t new_cpus_allowed = cpumask_of_cpu(cpu);
-       set_cpus_allowed(current, new_cpus_allowed);
+       set_cpus_allowed_ptr(current, cpumask_of(cpu));
        (*fn)(arg);
-       set_cpus_allowed(current, save_cpus_allowed);
+       set_cpus_allowed_ptr(current, &save_cpus_allowed);
 }
 
 static void
index 47a1927..653b3c4 100644 (file)
@@ -430,18 +430,16 @@ static int __init rtc_init(void)
 }
 module_init(rtc_init);
 
+void read_persistent_clock(struct timespec *ts)
+{
+       efi_gettimeofday(ts);
+}
+
 void __init
 time_init (void)
 {
        register_percpu_irq(IA64_TIMER_VECTOR, &timer_irqaction);
-       efi_gettimeofday(&xtime);
        ia64_init_itm();
-
-       /*
-        * Initialize wall_to_monotonic such that adding it to xtime will yield zero, the
-        * tv_nsec field must be normalized (i.e., 0 <= nsec < NSEC_PER_SEC).
-        */
-       set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
 }
 
 /*
index 28f299d..0baa1bb 100644 (file)
@@ -361,12 +361,12 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
                return 0;
 
        oldmask = current->cpus_allowed;
-       retval = set_cpus_allowed(current, cpumask_of_cpu(cpu));
+       retval = set_cpus_allowed_ptr(current, cpumask_of(cpu));
        if (unlikely(retval))
                return retval;
 
        retval = cpu_cache_sysfs_init(cpu);
-       set_cpus_allowed(current, oldmask);
+       set_cpus_allowed_ptr(current, &oldmask);
        if (unlikely(retval < 0))
                return retval;
 
index 776dd40..622772b 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/kernel.h>
 #include <linux/sched.h>
 #include <linux/tty.h>
+#include <linux/ratelimit.h>
 
 #include <asm/intrinsics.h>
 #include <asm/processor.h>
@@ -1283,24 +1284,9 @@ emulate_store_float (unsigned long ifa, load_store_t ld, struct pt_regs *regs)
 /*
  * Make sure we log the unaligned access, so that user/sysadmin can notice it and
  * eventually fix the program.  However, we don't want to do that for every access so we
- * pace it with jiffies.  This isn't really MP-safe, but it doesn't really have to be
- * either...
+ * pace it with jiffies.
  */
-static int
-within_logging_rate_limit (void)
-{
-       static unsigned long count, last_time;
-
-       if (time_after(jiffies, last_time + 5 * HZ))
-               count = 0;
-       if (count < 5) {
-               last_time = jiffies;
-               count++;
-               return 1;
-       }
-       return 0;
-
-}
+static DEFINE_RATELIMIT_STATE(logging_rate_limit, 5 * HZ, 5);
 
 void
 ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
@@ -1337,7 +1323,7 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
 
                if (!no_unaligned_warning &&
                    !(current->thread.flags & IA64_THREAD_UAC_NOPRINT) &&
-                   within_logging_rate_limit())
+                   __ratelimit(&logging_rate_limit))
                {
                        char buf[200];  /* comm[] is at most 16 bytes... */
                        size_t len;
@@ -1370,7 +1356,7 @@ ia64_handle_unaligned (unsigned long ifa, struct pt_regs *regs)
                        }
                }
        } else {
-               if (within_logging_rate_limit()) {
+               if (__ratelimit(&logging_rate_limit)) {
                        printk(KERN_WARNING "kernel unaligned access to 0x%016lx, ip=0x%016lx\n",
                               ifa, regs->cr_iip + ipsr->ri);
                        if (unaligned_dump_stack)
index 19261a9..0799fea 100644 (file)
@@ -148,7 +148,6 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
        if ((vma->vm_flags & mask) != mask)
                goto bad_area;
 
-  survive:
        /*
         * If for any reason at all we couldn't handle the fault, make
         * sure we exit gracefully rather than endlessly redo the
@@ -276,13 +275,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
 
   out_of_memory:
        up_read(&mm->mmap_sem);
-       if (is_global_init(current)) {
-               yield();
-               down_read(&mm->mmap_sem);
-               goto survive;
-       }
-       printk(KERN_CRIT "VM: killing process %s\n", current->comm);
-       if (user_mode(regs))
-               do_group_exit(SIGKILL);
-       goto no_context;
+       if (!user_mode(regs))
+               goto no_context;
+       pagefault_out_of_memory();
 }
index 55ac3c4..f6c1c5f 100644 (file)
@@ -629,9 +629,9 @@ static int sn_hwperf_op_cpu(struct sn_hwperf_op_info *op_info)
                else {
                        /* migrate the task before calling SAL */ 
                        save_allowed = current->cpus_allowed;
-                       set_cpus_allowed(current, cpumask_of_cpu(cpu));
+                       set_cpus_allowed_ptr(current, cpumask_of(cpu));
                        sn_hwperf_call_sal(op_info);
-                       set_cpus_allowed(current, save_allowed);
+                       set_cpus_allowed_ptr(current, &save_allowed);
                }
        }
        r = op_info->ret;
index 63f0cf0..d44a51e 100644 (file)
@@ -26,7 +26,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v) ((v)->counter)
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
 
 /**
  * atomic_set - set atomic variable
index ed240b6..71faff5 100644 (file)
@@ -142,7 +142,7 @@ static inline unsigned int get_thread_fault_code(void)
 #define TIF_RESTORE_SIGMASK    8       /* restore signal mask in do_signal() */
 #define TIF_USEDFPU            16      /* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG     17      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             18      /* OOM killer killed process */
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 #define TIF_FREEZE             19      /* is freezing for suspend */
 
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
index 9cedcef..bda8682 100644 (file)
@@ -105,24 +105,6 @@ u32 arch_gettimeoffset(void)
        return elapsed_time * 1000;
 }
 
-/*
- * In order to set the CMOS clock precisely, set_rtc_mmss has to be
- * called 500 ms after the second nowtime has started, because when
- * nowtime is written into the registers of the CMOS clock, it will
- * jump to the next second precisely 500 ms later. Check the Motorola
- * MC146818A or Dallas DS12887 data sheet for details.
- *
- * BUG: This routine does not handle hour overflow properly; it just
- *      sets the minutes. Usually you won't notice until after reboot!
- */
-static inline int set_rtc_mmss(unsigned long nowtime)
-{
-       return 0;
-}
-
-/* last time the cmos clock got updated */
-static long last_rtc_update = 0;
-
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick
@@ -138,23 +120,6 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id)
 #ifndef CONFIG_SMP
        update_process_times(user_mode(get_irq_regs()));
 #endif
-       /*
-        * If we have an externally synchronized Linux clock, then update
-        * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
-        * called as close as possible to 500 ms before the new second starts.
-        */
-       write_seqlock(&xtime_lock);
-       if (ntp_synced()
-               && xtime.tv_sec > last_rtc_update + 660
-               && (xtime.tv_nsec / 1000) >= 500000 - ((unsigned)TICK_SIZE) / 2
-               && (xtime.tv_nsec / 1000) <= 500000 + ((unsigned)TICK_SIZE) / 2)
-       {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else    /* do it again in 60 s */
-                       last_rtc_update = xtime.tv_sec - 600;
-       }
-       write_sequnlock(&xtime_lock);
        /* As we return to user mode fire off the other CPU schedulers..
           this is basically because we don't yet share IRQ's around.
           This message is rigged to be safe on the 386 - basically it's
@@ -174,7 +139,7 @@ static struct irqaction irq0 = {
        .name = "MFT2",
 };
 
-void __init time_init(void)
+void read_persistent_clock(struct timespec *ts)
 {
        unsigned int epoch, year, mon, day, hour, min, sec;
 
@@ -194,11 +159,13 @@ void __init time_init(void)
                epoch = 1952;
        year += epoch;
 
-       xtime.tv_sec = mktime(year, mon, day, hour, min, sec);
-       xtime.tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
-       set_normalized_timespec(&wall_to_monotonic,
-               -xtime.tv_sec, -xtime.tv_nsec);
+       ts->tv_sec = mktime(year, mon, day, hour, min, sec);
+       ts->tv_nsec = (INITIAL_JIFFIES % HZ) * (NSEC_PER_SEC / HZ);
+}
 
+
+void __init time_init(void)
+{
 #if defined(CONFIG_CHIP_M32102) || defined(CONFIG_CHIP_XNUX2) \
        || defined(CONFIG_CHIP_VDEC2) || defined(CONFIG_CHIP_M32700) \
        || defined(CONFIG_CHIP_OPSP) || defined(CONFIG_CHIP_M32104)
index 6a0d765..11dd30b 100644 (file)
@@ -2,6 +2,6 @@
 # Makefile for Linux arch/m68k/amiga source directory
 #
 
-obj-y          := config.o amiints.o cia.o chipram.o amisound.o
+obj-y          := config.o amiints.o cia.o chipram.o amisound.o platform.o
 
 obj-$(CONFIG_AMIGA_PCMCIA)     += pcmcia.o
diff --git a/arch/m68k/amiga/platform.c b/arch/m68k/amiga/platform.c
new file mode 100644 (file)
index 0000000..38f18bf
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  Copyright (C) 2007-2009 Geert Uytterhoeven
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/zorro.h>
+
+#include <asm/amigahw.h>
+
+
+#ifdef CONFIG_ZORRO
+
+static const struct resource zorro_resources[] __initconst = {
+       /* Zorro II regions (on Zorro II/III) */
+       {
+               .name   = "Zorro II exp",
+               .start  = 0x00e80000,
+               .end    = 0x00efffff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "Zorro II mem",
+               .start  = 0x00200000,
+               .end    = 0x009fffff,
+               .flags  = IORESOURCE_MEM,
+       },
+       /* Zorro III regions (on Zorro III only) */
+       {
+               .name   = "Zorro III exp",
+               .start  = 0xff000000,
+               .end    = 0xffffffff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .name   = "Zorro III cfg",
+               .start  = 0x40000000,
+               .end    = 0x7fffffff,
+               .flags  = IORESOURCE_MEM,
+       }
+};
+
+
+static int __init amiga_init_bus(void)
+{
+       if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
+               return -ENODEV;
+
+       platform_device_register_simple("amiga-zorro", -1, zorro_resources,
+                                       AMIGAHW_PRESENT(ZORRO3) ? 4 : 2);
+       return 0;
+}
+
+subsys_initcall(amiga_init_bus);
+
+#endif /* CONFIG_ZORRO */
+
+
+static int __init amiga_init_devices(void)
+{
+       if (!MACH_IS_AMIGA)
+               return -ENODEV;
+
+       /* video hardware */
+       if (AMIGAHW_PRESENT(AMI_VIDEO))
+               platform_device_register_simple("amiga-video", -1, NULL, 0);
+
+
+       /* sound hardware */
+       if (AMIGAHW_PRESENT(AMI_AUDIO))
+               platform_device_register_simple("amiga-audio", -1, NULL, 0);
+
+
+       /* storage interfaces */
+       if (AMIGAHW_PRESENT(AMI_FLOPPY))
+               platform_device_register_simple("amiga-floppy", -1, NULL, 0);
+
+       return 0;
+}
+
+device_initcall(amiga_init_devices);
index b46ea17..cb8617b 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
-#include <linux/smp_lock.h>
 #include <linux/ioport.h>
 #include <linux/capability.h>
 #include <linux/fcntl.h>
 static unsigned char days_in_mo[] =
 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
 
-static char rtc_status;
+static atomic_t rtc_status = ATOMIC_INIT(1);
 
-static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-                    unsigned long arg)
+static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
        unsigned char msr;
@@ -132,29 +130,20 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 }
 
 /*
- *     We enforce only one user at a time here with the open/close.
- *     Also clear the previous interrupt data on an open, and clean
- *     up things on a close.
+ * We enforce only one user at a time here with the open/close.
  */
-
 static int rtc_open(struct inode *inode, struct file *file)
 {
-       lock_kernel();
-       if(rtc_status) {
-               unlock_kernel();
+       if (!atomic_dec_and_test(&rtc_status)) {
+               atomic_inc(&rtc_status);
                return -EBUSY;
        }
-
-       rtc_status = 1;
-       unlock_kernel();
        return 0;
 }
 
 static int rtc_release(struct inode *inode, struct file *file)
 {
-       lock_kernel();
-       rtc_status = 0;
-       unlock_kernel();
+       atomic_inc(&rtc_status);
        return 0;
 }
 
@@ -163,9 +152,9 @@ static int rtc_release(struct inode *inode, struct file *file)
  */
 
 static const struct file_operations rtc_fops = {
-       .ioctl =        rtc_ioctl,
-       .open =         rtc_open,
-       .release =      rtc_release,
+       .unlocked_ioctl = rtc_ioctl,
+       .open           = rtc_open,
+       .release        = rtc_release,
 };
 
 static struct miscdevice rtc_dev = {
index f5b3d09..7b98242 100644 (file)
@@ -1,4 +1,2 @@
 extern void hp300_sched_init(irq_handler_t vector);
-extern unsigned long hp300_gettimeoffset (void);
-
-
+extern unsigned long hp300_gettimeoffset(void);
index d9d2ed6..6a223b3 100644 (file)
@@ -15,7 +15,7 @@
 
 #define ATOMIC_INIT(i) { (i) }
 
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 static inline void atomic_add(int i, atomic_t *v)
index 5674cb9..289310c 100644 (file)
@@ -15,7 +15,7 @@
 
 #define ATOMIC_INIT(i) { (i) }
 
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v, i)       (((v)->counter) = i)
 
 static __inline__ void atomic_add(int i, atomic_t *v)
index 9bde784..b4ecdaa 100644 (file)
@@ -365,6 +365,10 @@ static inline int minix_test_bit(int nr, const void *vaddr)
 #define ext2_set_bit_atomic(lock, nr, addr)    test_and_set_bit((nr) ^ 24, (unsigned long *)(addr))
 #define ext2_clear_bit(nr, addr)               __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
 #define ext2_clear_bit_atomic(lock, nr, addr)  test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr))
+#define ext2_find_next_zero_bit(addr, size, offset) \
+       generic_find_next_zero_le_bit((unsigned long *)addr, size, offset)
+#define ext2_find_next_bit(addr, size, offset) \
+       generic_find_next_le_bit((unsigned long *)addr, size, offset)
 
 static inline int ext2_test_bit(int nr, const void *vaddr)
 {
@@ -394,10 +398,9 @@ static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size)
        return (p - addr) * 32 + res;
 }
 
-static inline int ext2_find_next_zero_bit(const void *vaddr, unsigned size,
-                                         unsigned offset)
+static inline unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,
+               unsigned long size, unsigned long offset)
 {
-       const unsigned long *addr = vaddr;
        const unsigned long *p = addr + (offset >> 5);
        int bit = offset & 31UL, res;
 
@@ -437,10 +440,9 @@ static inline int ext2_find_first_bit(const void *vaddr, unsigned size)
        return (p - addr) * 32 + res;
 }
 
-static inline int ext2_find_next_bit(const void *vaddr, unsigned size,
-                                    unsigned offset)
+static inline unsigned long generic_find_next_le_bit(const unsigned long *addr,
+               unsigned long size, unsigned long offset)
 {
-       const unsigned long *addr = vaddr;
        const unsigned long *p = addr + (offset >> 5);
        int bit = offset & 31UL, res;
 
index 85c41b7..36265cc 100644 (file)
@@ -1,26 +1,12 @@
 #ifndef _M68K_PARAM_H
 #define _M68K_PARAM_H
 
-#ifdef __KERNEL__
-# define HZ            CONFIG_HZ       /* Internal kernel timer frequency */
-# define USER_HZ       100             /* .. some user interfaces are in "ticks" */
-# define CLOCKS_PER_SEC        (USER_HZ)       /* like times() */
-#endif
-
-#ifndef HZ
-#define HZ 100
-#endif
-
 #ifdef __uClinux__
 #define EXEC_PAGESIZE  4096
 #else
 #define EXEC_PAGESIZE  8192
 #endif
 
-#ifndef NOGROUP
-#define NOGROUP                (-1)
-#endif
-
-#define MAXHOSTNAMELEN 64      /* max length of hostname */
+#include <asm-generic/param.h>
 
 #endif /* _M68K_PARAM_H */
index 67266c6..3bf31dc 100644 (file)
@@ -65,7 +65,7 @@ struct thread_info {
 #define TIF_NEED_RESCHED       7       /* rescheduling necessary */
 #define TIF_DELAYED_TRACE      14      /* single step a syscall */
 #define TIF_SYSCALL_TRACE      15      /* syscall trace active */
-#define TIF_MEMDIE             16
+#define TIF_MEMDIE             16      /* is terminating due to OOM killer */
 #define TIF_FREEZE             17      /* thread is freezing for suspend */
 
 #endif /* _ASM_M68K_THREAD_INFO_H */
index 884776f..51f354b 100644 (file)
@@ -85,7 +85,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_POLLING_NRFLAG     3       /* true if poll_idle() is polling
                                           TIF_NEED_RESCHED */
-#define TIF_MEMDIE             4
+#define TIF_MEMDIE             4       /* is terminating due to OOM killer */
 #define TIF_FREEZE             16      /* is freezing for suspend */
 
 /* as above, but as bit values */
index 17dc2a3..4926b38 100644 (file)
@@ -73,21 +73,24 @@ static irqreturn_t timer_interrupt(int irq, void *dummy)
        return IRQ_HANDLED;
 }
 
-void __init time_init(void)
+void read_persistent_clock(struct timespec *ts)
 {
        struct rtc_time time;
+       ts->tv_sec = 0;
+       ts->tv_nsec = 0;
 
        if (mach_hwclk) {
                mach_hwclk(0, &time);
 
                if ((time.tm_year += 1900) < 1970)
                        time.tm_year += 100;
-               xtime.tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
+               ts->tv_sec = mktime(time.tm_year, time.tm_mon, time.tm_mday,
                                      time.tm_hour, time.tm_min, time.tm_sec);
-               xtime.tv_nsec = 0;
        }
-       wall_to_monotonic.tv_sec = -xtime.tv_sec;
+}
 
+void __init time_init(void)
+{
        mach_sched_init(timer_interrupt);
 }
 
index aacd6d1..ada4f4c 100644 (file)
@@ -455,7 +455,7 @@ static inline void access_error040(struct frame *fp)
 
                if (do_page_fault(&fp->ptregs, addr, errorcode)) {
 #ifdef DEBUG
-                       printk("do_page_fault() !=0 \n");
+                       printk("do_page_fault() !=0\n");
 #endif
                        if (user_mode(&fp->ptregs)){
                                /* delay writebacks after signal delivery */
index 0356da9..1c16b1b 100644 (file)
@@ -148,7 +148,7 @@ static void mac_cache_card_flush(int writeback)
 void __init config_mac(void)
 {
        if (!MACH_IS_MAC)
-               printk(KERN_ERR "ERROR: no Mac, but config_mac() called!! \n");
+               printk(KERN_ERR "ERROR: no Mac, but config_mac() called!!\n");
 
        mach_sched_init = mac_sched_init;
        mach_init_IRQ = mac_init_IRQ;
@@ -867,7 +867,7 @@ static void __init mac_identify(void)
         */
        iop_preinit();
 
-       printk(KERN_INFO "Detected Macintosh model: %d \n", model);
+       printk(KERN_INFO "Detected Macintosh model: %d\n", model);
 
        /*
         * Report booter data:
@@ -878,12 +878,12 @@ static void __init mac_identify(void)
                mac_bi_data.videoaddr, mac_bi_data.videorow,
                mac_bi_data.videodepth, mac_bi_data.dimensions & 0xFFFF,
                mac_bi_data.dimensions >> 16);
-       printk(KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx \n",
+       printk(KERN_DEBUG " Videological 0x%lx phys. 0x%lx, SCC at 0x%lx\n",
                mac_bi_data.videological, mac_orig_videoaddr,
                mac_bi_data.sccbase);
-       printk(KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx \n",
+       printk(KERN_DEBUG " Boottime: 0x%lx GMTBias: 0x%lx\n",
                mac_bi_data.boottime, mac_bi_data.gmtbias);
-       printk(KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx \n",
+       printk(KERN_DEBUG " Machine ID: %ld CPUid: 0x%lx memory size: 0x%lx\n",
                mac_bi_data.id, mac_bi_data.cpuid, mac_bi_data.memsize);
 
        iop_init();
index d0e35cf..a96394a 100644 (file)
@@ -154,7 +154,6 @@ good_area:
         * the fault.
         */
 
- survive:
        fault = handle_mm_fault(mm, vma, address, write ? FAULT_FLAG_WRITE : 0);
 #ifdef DEBUG
        printk("handle_mm_fault returns %d\n",fault);
@@ -180,15 +179,10 @@ good_area:
  */
 out_of_memory:
        up_read(&mm->mmap_sem);
-       if (is_global_init(current)) {
-               yield();
-               down_read(&mm->mmap_sem);
-               goto survive;
-       }
-
-       printk("VM: killing process %s\n", current->comm);
-       if (user_mode(regs))
-               do_group_exit(SIGKILL);
+       if (!user_mode(regs))
+               goto no_context;
+       pagefault_out_of_memory();
+       return 0;
 
 no_context:
        current->thread.signo = SIGBUS;
index 8da9c25..11ac6f6 100644 (file)
@@ -9,7 +9,6 @@
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
-#include <linux/smp_lock.h>
 #include <linux/ioport.h>
 #include <linux/capability.h>
 #include <linux/fcntl.h>
@@ -36,8 +35,7 @@ static const unsigned char days_in_mo[] =
 
 static atomic_t rtc_ready = ATOMIC_INIT(1);
 
-static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
-                    unsigned long arg)
+static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        volatile MK48T08ptr_t rtc = (MK48T08ptr_t)MVME_RTC_BASE;
        unsigned long flags;
@@ -120,22 +118,15 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 }
 
 /*
- *     We enforce only one user at a time here with the open/close.
- *     Also clear the previous interrupt data on an open, and clean
- *     up things on a close.
+ * We enforce only one user at a time here with the open/close.
  */
-
 static int rtc_open(struct inode *inode, struct file *file)
 {
-       lock_kernel();
        if( !atomic_dec_and_test(&rtc_ready) )
        {
                atomic_inc( &rtc_ready );
-               unlock_kernel();
                return -EBUSY;
        }
-       unlock_kernel();
-
        return 0;
 }
 
@@ -150,9 +141,9 @@ static int rtc_release(struct inode *inode, struct file *file)
  */
 
 static const struct file_operations rtc_fops = {
-       .ioctl =        rtc_ioctl,
-       .open =         rtc_open,
-       .release =      rtc_release,
+       .unlocked_ioctl = rtc_ioctl,
+       .open           = rtc_open,
+       .release        = rtc_release,
 };
 
 static struct miscdevice rtc_dev=
index 31ab3f0..ad10fec 100644 (file)
@@ -126,7 +126,7 @@ static void q40_reset(void)
 {
         halted = 1;
         printk("\n\n*******************************************\n"
-               "Called q40_reset : press the RESET button!! \n"
+               "Called q40_reset : press the RESET button!!\n"
                "*******************************************\n");
        Q40_LED_ON();
        while (1)
index b2ca80f..8a8e9fc 100644 (file)
@@ -122,7 +122,7 @@ static inline struct thread_info *current_thread_info(void)
 /* restore singlestep on return to user mode */
 #define TIF_SINGLESTEP         4
 #define TIF_IRET               5 /* return with iret */
-#define TIF_MEMDIE             6
+#define TIF_MEMDIE             6       /* is terminating due to OOM killer */
 #define TIF_SYSCALL_AUDIT      9       /* syscall auditing active */
 #define TIF_SECCOMP            10      /* secure computing */
 #define TIF_FREEZE             14      /* Freezing for suspend */
index 519197e..59dc0c7 100644 (file)
@@ -29,7 +29,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 
 /*
  * atomic_set - set atomic variable
@@ -410,7 +410,7 @@ static __inline__ int atomic_add_unless(atomic_t *v, int a, int u)
  * @v: pointer of type atomic64_t
  *
  */
-#define atomic64_read(v)       ((v)->counter)
+#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
 
 /*
  * atomic64_set - set atomic variable
index 032ca73..48bb823 100644 (file)
@@ -12,7 +12,7 @@
 #define PIT_CH0                        0x40
 #define PIT_CH2                        0x42
 
-extern spinlock_t i8253_lock;
+extern raw_spinlock_t i8253_lock;
 
 extern void setup_pit_timer(void);
 
index 845da21..2376f2e 100644 (file)
@@ -112,7 +112,7 @@ register struct thread_info *__current_thread_info __asm__("$28");
 #define TIF_RESTORE_SIGMASK    9       /* restore signal mask in do_signal() */
 #define TIF_USEDFPU            16      /* FPU was used by this task this quantum (SMP) */
 #define TIF_POLLING_NRFLAG     17      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             18
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 #define TIF_FREEZE             19
 #define TIF_FIXADE             20      /* Fix address errors in software */
 #define TIF_LOGADE             21      /* Log address errors to syslog */
index ed5c441..9479406 100644 (file)
@@ -15,7 +15,7 @@
 #include <asm/io.h>
 #include <asm/time.h>
 
-DEFINE_SPINLOCK(i8253_lock);
+DEFINE_RAW_SPINLOCK(i8253_lock);
 EXPORT_SYMBOL(i8253_lock);
 
 /*
@@ -26,7 +26,7 @@ EXPORT_SYMBOL(i8253_lock);
 static void init_pit_timer(enum clock_event_mode mode,
                           struct clock_event_device *evt)
 {
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
 
        switch(mode) {
        case CLOCK_EVT_MODE_PERIODIC:
@@ -55,7 +55,7 @@ static void init_pit_timer(enum clock_event_mode mode,
                /* Nothing to do here */
                break;
        }
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
 }
 
 /*
@@ -65,10 +65,10 @@ static void init_pit_timer(enum clock_event_mode mode,
  */
 static int pit_next_event(unsigned long delta, struct clock_event_device *evt)
 {
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
        outb_p(delta & 0xff , PIT_CH0); /* LSB */
        outb(delta >> 8 , PIT_CH0);     /* MSB */
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
 
        return 0;
 }
@@ -137,7 +137,7 @@ static cycle_t pit_read(struct clocksource *cs)
        static int old_count;
        static u32 old_jifs;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
        /*
         * Although our caller may have the read side of xtime_lock,
         * this is now a seqlock, and we are cheating in this routine
@@ -183,7 +183,7 @@ static cycle_t pit_read(struct clocksource *cs)
        old_count = count;
        old_jifs = jifs;
 
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 
        count = (LATCH - 1) - count;
 
index 7a8b0a8..044bbe4 100644 (file)
@@ -253,7 +253,7 @@ void __init init_bcm1480_irqs(void)
  * On the second cpu, everything is set to IP5, which is
  * ignored, EXCEPT the mailbox interrupt.  That one is
  * set to IP[2] so it is handled.  This is needed so we
- * can do cross-cpu function calls, as requred by SMP
+ * can do cross-cpu function calls, as required by SMP
  */
 
 #define IMR_IP2_VAL    K_BCM1480_INT_MAP_I0
index 62371f7..12ac04a 100644 (file)
@@ -236,7 +236,7 @@ void __init init_sb1250_irqs(void)
  * On the second cpu, everything is set to IP5, which is
  * ignored, EXCEPT the mailbox interrupt.  That one is
  * set to IP[2] so it is handled.  This is needed so we
- * can do cross-cpu function calls, as requred by SMP
+ * can do cross-cpu function calls, as required by SMP
  */
 
 #define IMR_IP2_VAL    K_INT_MAP_I0
index 89faaca..1c4565a 100644 (file)
@@ -37,6 +37,9 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
 config GENERIC_CALIBRATE_DELAY
        def_bool y
 
+config GENERIC_CMOS_UPDATE
+        def_bool y
+
 config GENERIC_FIND_NEXT_BIT
        def_bool y
 
index 5bf5be9..e41222d 100644 (file)
@@ -31,7 +31,7 @@
  * Atomically reads the value of @v.  Note that the guaranteed
  * useful range of an atomic_t is only 24 bits.
  */
-#define atomic_read(v) ((v)->counter)
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
 
 /**
  * atomic_set - set atomic variable
index 58d64f8..2001cb6 100644 (file)
@@ -148,7 +148,7 @@ static inline unsigned long current_stack_pointer(void)
 #define TIF_SINGLESTEP         4       /* restore singlestep on return to user mode */
 #define TIF_RESTORE_SIGMASK    5       /* restore signal mask in do_signal() */
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             17      /* OOM killer killed process */
+#define TIF_MEMDIE             17      /* is terminating due to OOM killer */
 #define TIF_FREEZE             18      /* freezing for suspend */
 
 #define _TIF_SYSCALL_TRACE     +(1 << TIF_SYSCALL_TRACE)
index 7978470..815a933 100644 (file)
@@ -26,17 +26,15 @@ static long last_rtc_update;
 /* time for RTC to update itself in ioclks */
 static unsigned long mn10300_rtc_update_period;
 
-/*
- * read the current RTC time
- */
-unsigned long __init get_initial_rtc_time(void)
+void read_persistent_clock(struct timespec *ts)
 {
        struct rtc_time tm;
 
        get_rtc_time(&tm);
 
-       return mktime(tm.tm_year, tm.tm_mon, tm.tm_mday,
+       ts->tv_sec = mktime(tm.tm_year, tm.tm_mon, tm.tm_mday,
                      tm.tm_hour, tm.tm_min, tm.tm_sec);
+       ts->tv_nsec = 0;
 }
 
 /*
@@ -110,24 +108,9 @@ static int set_rtc_mmss(unsigned long nowtime)
        return retval;
 }
 
-void check_rtc_time(void)
+int update_persistent_clock(struct timespec now)
 {
-       /* the RTC clock just finished ticking over again this second
-        * - if we have an externally synchronized Linux clock, then update
-        *   RTC clock accordingly every ~11 minutes. set_rtc_mmss() has to be
-        *   called as close as possible to 500 ms before the new second starts.
-        */
-       if ((time_status & STA_UNSYNC) == 0 &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           xtime.tv_nsec / 1000 >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
-           xtime.tv_nsec / 1000 <= 500000 + ((unsigned) TICK_SIZE) / 2
-           ) {
-               if (set_rtc_mmss(xtime.tv_sec) == 0)
-                       last_rtc_update = xtime.tv_sec;
-               else
-                       /* do it again in 60s */
-                       last_rtc_update = xtime.tv_sec - 600;
-       }
+       return set_rtc_mms(now.tv_sec);
 }
 
 /*
index 395caf0..8f7f6d2 100644 (file)
@@ -111,7 +111,6 @@ static irqreturn_t timer_interrupt(int irq, void *dev_id)
                /* advance the kernel's time tracking system */
                profile_tick(CPU_PROFILING);
                do_timer(1);
-               check_rtc_time();
        }
 
        write_sequnlock(&xtime_lock);
@@ -139,9 +138,6 @@ void __init time_init(void)
               " (calibrated against RTC)\n",
               MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100);
 
-       xtime.tv_sec = get_initial_rtc_time();
-       xtime.tv_nsec = 0;
-
        mn10300_last_tsc = TMTSCBC;
 
        /* use timer 0 & 1 cascaded to tick at as close to HZ as possible */
index 716634d..f819559 100644 (file)
@@ -189,7 +189,7 @@ static __inline__ void atomic_set(atomic_t *v, int i)
 
 static __inline__ int atomic_read(const atomic_t *v)
 {
-       return v->counter;
+       return (*(volatile int *)&(v)->counter);
 }
 
 /* exported interface */
@@ -286,7 +286,7 @@ atomic64_set(atomic64_t *v, s64 i)
 static __inline__ s64
 atomic64_read(const atomic64_t *v)
 {
-       return v->counter;
+       return (*(volatile long *)&(v)->counter);
 }
 
 #define atomic64_add(i,v)      ((void)(__atomic64_add_return( ((s64)(i)),(v))))
index 7ecc103..aa8de72 100644 (file)
@@ -56,7 +56,7 @@ struct thread_info {
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_POLLING_NRFLAG     3       /* true if poll_idle() is polling TIF_NEED_RESCHED */
 #define TIF_32BIT               4       /* 32 bit binary */
-#define TIF_MEMDIE             5
+#define TIF_MEMDIE             5       /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    6       /* restore saved signal mask */
 #define TIF_FREEZE             7       /* is freezing for suspend */
 #define TIF_NOTIFY_RESUME      8       /* callback before returning to user */
index aa9d383..65eb859 100644 (file)
@@ -104,7 +104,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_PERFMON_CTXSW      6       /* perfmon needs ctxsw calls */
 #define TIF_SYSCALL_AUDIT      7       /* syscall auditing active */
 #define TIF_SINGLESTEP         8       /* singlestepping active */
-#define TIF_MEMDIE             9
+#define TIF_MEMDIE             9       /* is terminating due to OOM killer */
 #define TIF_SECCOMP            10      /* secure computing */
 #define TIF_RESTOREALL         11      /* Restore all regs (implies NOERROR) */
 #define TIF_NOERROR            12      /* Force successful syscall return */
index 08460a2..43b83c3 100644 (file)
@@ -35,6 +35,9 @@ struct cpu_hw_events {
        u64 alternatives[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
        unsigned long amasks[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
        unsigned long avalues[MAX_HWEVENTS][MAX_EVENT_ALTERNATIVES];
+
+       unsigned int group_flag;
+       int n_txn_start;
 };
 DEFINE_PER_CPU(struct cpu_hw_events, cpu_hw_events);
 
@@ -718,66 +721,6 @@ static int collect_events(struct perf_event *group, int max_count,
        return n;
 }
 
-static void event_sched_in(struct perf_event *event)
-{
-       event->state = PERF_EVENT_STATE_ACTIVE;
-       event->oncpu = smp_processor_id();
-       event->tstamp_running += event->ctx->time - event->tstamp_stopped;
-       if (is_software_event(event))
-               event->pmu->enable(event);
-}
-
-/*
- * Called to enable a whole group of events.
- * Returns 1 if the group was enabled, or -EAGAIN if it could not be.
- * Assumes the caller has disabled interrupts and has
- * frozen the PMU with hw_perf_save_disable.
- */
-int hw_perf_group_sched_in(struct perf_event *group_leader,
-              struct perf_cpu_context *cpuctx,
-              struct perf_event_context *ctx)
-{
-       struct cpu_hw_events *cpuhw;
-       long i, n, n0;
-       struct perf_event *sub;
-
-       if (!ppmu)
-               return 0;
-       cpuhw = &__get_cpu_var(cpu_hw_events);
-       n0 = cpuhw->n_events;
-       n = collect_events(group_leader, ppmu->n_counter - n0,
-                          &cpuhw->event[n0], &cpuhw->events[n0],
-                          &cpuhw->flags[n0]);
-       if (n < 0)
-               return -EAGAIN;
-       if (check_excludes(cpuhw->event, cpuhw->flags, n0, n))
-               return -EAGAIN;
-       i = power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n + n0);
-       if (i < 0)
-               return -EAGAIN;
-       cpuhw->n_events = n0 + n;
-       cpuhw->n_added += n;
-
-       /*
-        * OK, this group can go on; update event states etc.,
-        * and enable any software events
-        */
-       for (i = n0; i < n0 + n; ++i)
-               cpuhw->event[i]->hw.config = cpuhw->events[i];
-       cpuctx->active_oncpu += n;
-       n = 1;
-       event_sched_in(group_leader);
-       list_for_each_entry(sub, &group_leader->sibling_list, group_entry) {
-               if (sub->state != PERF_EVENT_STATE_OFF) {
-                       event_sched_in(sub);
-                       ++n;
-               }
-       }
-       ctx->nr_active += n;
-
-       return 1;
-}
-
 /*
  * Add a event to the PMU.
  * If all events are not already frozen, then we disable and
@@ -805,12 +748,22 @@ static int power_pmu_enable(struct perf_event *event)
        cpuhw->event[n0] = event;
        cpuhw->events[n0] = event->hw.config;
        cpuhw->flags[n0] = event->hw.event_base;
+
+       /*
+        * If group events scheduling transaction was started,
+        * skip the schedulability test here, it will be peformed
+        * at commit time(->commit_txn) as a whole
+        */
+       if (cpuhw->group_flag & PERF_EVENT_TXN_STARTED)
+               goto nocheck;
+
        if (check_excludes(cpuhw->event, cpuhw->flags, n0, 1))
                goto out;
        if (power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n0 + 1))
                goto out;
-
        event->hw.config = cpuhw->events[n0];
+
+nocheck:
        ++cpuhw->n_events;
        ++cpuhw->n_added;
 
@@ -896,11 +849,65 @@ static void power_pmu_unthrottle(struct perf_event *event)
        local_irq_restore(flags);
 }
 
+/*
+ * Start group events scheduling transaction
+ * Set the flag to make pmu::enable() not perform the
+ * schedulability test, it will be performed at commit time
+ */
+void power_pmu_start_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
+
+       cpuhw->group_flag |= PERF_EVENT_TXN_STARTED;
+       cpuhw->n_txn_start = cpuhw->n_events;
+}
+
+/*
+ * Stop group events scheduling transaction
+ * Clear the flag and pmu::enable() will perform the
+ * schedulability test.
+ */
+void power_pmu_cancel_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuhw = &__get_cpu_var(cpu_hw_events);
+
+       cpuhw->group_flag &= ~PERF_EVENT_TXN_STARTED;
+}
+
+/*
+ * Commit group events scheduling transaction
+ * Perform the group schedulability test as a whole
+ * Return 0 if success
+ */
+int power_pmu_commit_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuhw;
+       long i, n;
+
+       if (!ppmu)
+               return -EAGAIN;
+       cpuhw = &__get_cpu_var(cpu_hw_events);
+       n = cpuhw->n_events;
+       if (check_excludes(cpuhw->event, cpuhw->flags, 0, n))
+               return -EAGAIN;
+       i = power_check_constraints(cpuhw, cpuhw->events, cpuhw->flags, n);
+       if (i < 0)
+               return -EAGAIN;
+
+       for (i = cpuhw->n_txn_start; i < n; ++i)
+               cpuhw->event[i]->hw.config = cpuhw->events[i];
+
+       return 0;
+}
+
 struct pmu power_pmu = {
        .enable         = power_pmu_enable,
        .disable        = power_pmu_disable,
        .read           = power_pmu_read,
        .unthrottle     = power_pmu_unthrottle,
+       .start_txn      = power_pmu_start_txn,
+       .cancel_txn     = power_pmu_cancel_txn,
+       .commit_txn     = power_pmu_commit_txn,
 };
 
 /*
index 57e5b60..174a04a 100644 (file)
@@ -69,10 +69,10 @@ void __init wii_memory_fixups(void)
 
        /*
         * This is part of a workaround to allow the use of two
-        * discontiguous RAM ranges on the Wii, even if this is
+        * discontinuous RAM ranges on the Wii, even if this is
         * currently unsupported on 32-bit PowerPC Linux.
         *
-        * We coealesce the two memory ranges of the Wii into a
+        * We coalesce the two memory ranges of the Wii into a
         * single range, then create a reservation for the "hole"
         * between both ranges.
         */
index 0d8cd9b..79d0ca0 100644 (file)
@@ -444,13 +444,6 @@ config FORCE_MAX_ZONEORDER
        int
        default "9"
 
-config PROCESS_DEBUG
-       bool "Show crashed user process info"
-       help
-         Say Y to print all process fault locations to the console.  This is
-         a debugging option; you probably do not want to set it unless you
-         are an S390 port maintainer.
-
 config PFAULT
        bool "Pseudo page fault support"
        help
index 0da1074..30c5f01 100644 (file)
@@ -116,6 +116,12 @@ image bzImage: vmlinux
 zfcpdump:
        $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
 
+vdso_install:
+ifeq ($(CONFIG_64BIT),y)
+       $(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso64 $@
+endif
+       $(Q)$(MAKE) $(build)=arch/$(ARCH)/kernel/vdso32 $@
+
 archclean:
        $(Q)$(MAKE) $(clean)=$(boot)
 
index aea5720..fa487d4 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/fs.h>
 #include <linux/types.h>
+#include <linux/debugfs.h>
 
 #define REG_FILE_MODE    0440
 #define UPDATE_FILE_MODE 0220
@@ -34,6 +35,9 @@ extern int hypfs_diag_create_files(struct super_block *sb, struct dentry *root);
 
 /* VM Hypervisor */
 extern int hypfs_vm_init(void);
+extern void hypfs_vm_exit(void);
 extern int hypfs_vm_create_files(struct super_block *sb, struct dentry *root);
 
+/* Directory for debugfs files */
+extern struct dentry *hypfs_dbfs_dir;
 #endif /* _HYPFS_H_ */
index 5b1acdb..1211bb1 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/vmalloc.h>
+#include <linux/mm.h>
 #include <asm/ebcdic.h>
 #include "hypfs.h"
 
@@ -22,6 +23,8 @@
 #define CPU_NAME_LEN 16                /* type name len of cpus in diag224 name table */
 #define TMP_SIZE 64            /* size of temporary buffers */
 
+#define DBFS_D204_HDR_VERSION  0
+
 /* diag 204 subcodes */
 enum diag204_sc {
        SUBC_STIB4 = 4,
@@ -47,6 +50,8 @@ static void *diag204_buf;             /* 4K aligned buffer for diag204 data */
 static void *diag204_buf_vmalloc;      /* vmalloc pointer for diag204 data */
 static int diag204_buf_pages;          /* number of pages for diag204 data */
 
+static struct dentry *dbfs_d204_file;
+
 /*
  * DIAG 204 data structures and member access functions.
  *
@@ -364,18 +369,21 @@ static void diag204_free_buffer(void)
        } else {
                free_pages((unsigned long) diag204_buf, 0);
        }
-       diag204_buf_pages = 0;
        diag204_buf = NULL;
 }
 
+static void *page_align_ptr(void *ptr)
+{
+       return (void *) PAGE_ALIGN((unsigned long) ptr);
+}
+
 static void *diag204_alloc_vbuf(int pages)
 {
        /* The buffer has to be page aligned! */
        diag204_buf_vmalloc = vmalloc(PAGE_SIZE * (pages + 1));
        if (!diag204_buf_vmalloc)
                return ERR_PTR(-ENOMEM);
-       diag204_buf = (void*)((unsigned long)diag204_buf_vmalloc
-                               & ~0xfffUL) + 0x1000;
+       diag204_buf = page_align_ptr(diag204_buf_vmalloc);
        diag204_buf_pages = pages;
        return diag204_buf;
 }
@@ -468,17 +476,26 @@ fail_alloc:
        return rc;
 }
 
+static int diag204_do_store(void *buf, int pages)
+{
+       int rc;
+
+       rc = diag204((unsigned long) diag204_store_sc |
+                    (unsigned long) diag204_info_type, pages, buf);
+       return rc < 0 ? -ENOSYS : 0;
+}
+
 static void *diag204_store(void)
 {
        void *buf;
-       int pages;
+       int pages, rc;
 
        buf = diag204_get_buffer(diag204_info_type, &pages);
        if (IS_ERR(buf))
                goto out;
-       if (diag204((unsigned long)diag204_store_sc |
-                   (unsigned long)diag204_info_type, pages, buf) < 0)
-               return ERR_PTR(-ENOSYS);
+       rc = diag204_do_store(buf, pages);
+       if (rc)
+               return ERR_PTR(rc);
 out:
        return buf;
 }
@@ -526,6 +543,92 @@ static int diag224_idx2name(int index, char *name)
        return 0;
 }
 
+struct dbfs_d204_hdr {
+       u64     len;            /* Length of d204 buffer without header */
+       u16     version;        /* Version of header */
+       u8      sc;             /* Used subcode */
+       char    reserved[53];
+} __attribute__ ((packed));
+
+struct dbfs_d204 {
+       struct dbfs_d204_hdr    hdr;    /* 64 byte header */
+       char                    buf[];  /* d204 buffer */
+} __attribute__ ((packed));
+
+struct dbfs_d204_private {
+       struct dbfs_d204        *d204;  /* Aligned d204 data with header */
+       void                    *base;  /* Base pointer (needed for vfree) */
+};
+
+static int dbfs_d204_open(struct inode *inode, struct file *file)
+{
+       struct dbfs_d204_private *data;
+       struct dbfs_d204 *d204;
+       int rc, buf_size;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+       buf_size = PAGE_SIZE * (diag204_buf_pages + 1) + sizeof(d204->hdr);
+       data->base = vmalloc(buf_size);
+       if (!data->base) {
+               rc = -ENOMEM;
+               goto fail_kfree_data;
+       }
+       memset(data->base, 0, buf_size);
+       d204 = page_align_ptr(data->base + sizeof(d204->hdr))
+               - sizeof(d204->hdr);
+       rc = diag204_do_store(&d204->buf, diag204_buf_pages);
+       if (rc)
+               goto fail_vfree_base;
+       d204->hdr.version = DBFS_D204_HDR_VERSION;
+       d204->hdr.len = PAGE_SIZE * diag204_buf_pages;
+       d204->hdr.sc = diag204_store_sc;
+       data->d204 = d204;
+       file->private_data = data;
+       return nonseekable_open(inode, file);
+
+fail_vfree_base:
+       vfree(data->base);
+fail_kfree_data:
+       kfree(data);
+       return rc;
+}
+
+static int dbfs_d204_release(struct inode *inode, struct file *file)
+{
+       struct dbfs_d204_private *data = file->private_data;
+
+       vfree(data->base);
+       kfree(data);
+       return 0;
+}
+
+static ssize_t dbfs_d204_read(struct file *file, char __user *buf,
+                             size_t size, loff_t *ppos)
+{
+       struct dbfs_d204_private *data = file->private_data;
+
+       return simple_read_from_buffer(buf, size, ppos, data->d204,
+                                      data->d204->hdr.len +
+                                      sizeof(data->d204->hdr));
+}
+
+static const struct file_operations dbfs_d204_ops = {
+       .open           = dbfs_d204_open,
+       .read           = dbfs_d204_read,
+       .release        = dbfs_d204_release,
+};
+
+static int hypfs_dbfs_init(void)
+{
+       dbfs_d204_file = debugfs_create_file("diag_204", 0400, hypfs_dbfs_dir,
+                                            NULL, &dbfs_d204_ops);
+       if (IS_ERR(dbfs_d204_file))
+               return PTR_ERR(dbfs_d204_file);
+       return 0;
+}
+
 __init int hypfs_diag_init(void)
 {
        int rc;
@@ -540,11 +643,17 @@ __init int hypfs_diag_init(void)
                pr_err("The hardware system does not provide all "
                       "functions required by hypfs\n");
        }
+       if (diag204_info_type == INFO_EXT) {
+               rc = hypfs_dbfs_init();
+               if (rc)
+                       diag204_free_buffer();
+       }
        return rc;
 }
 
 void hypfs_diag_exit(void)
 {
+       debugfs_remove(dbfs_d204_file);
        diag224_delete_name_table();
        diag204_free_buffer();
 }
index f0b0d31..ee5ab1a 100644 (file)
 #include <linux/string.h>
 #include <linux/vmalloc.h>
 #include <asm/ebcdic.h>
+#include <asm/timex.h>
 #include "hypfs.h"
 
 #define NAME_LEN 8
+#define DBFS_D2FC_HDR_VERSION 0
 
 static char local_guest[] = "        ";
 static char all_guests[] = "*       ";
 static char *guest_query;
 
+static struct dentry *dbfs_d2fc_file;
+
 struct diag2fc_data {
        __u32 version;
        __u32 flags;
@@ -76,23 +80,26 @@ static int diag2fc(int size, char* query, void *addr)
                return -residual_cnt;
 }
 
-static struct diag2fc_data *diag2fc_store(char *query, int *count)
+/*
+ * Allocate buffer for "query" and store diag 2fc at "offset"
+ */
+static void *diag2fc_store(char *query, unsigned int *count, int offset)
 {
+       void *data;
        int size;
-       struct diag2fc_data *data;
 
        do {
                size = diag2fc(0, query, NULL);
                if (size < 0)
                        return ERR_PTR(-EACCES);
-               data = vmalloc(size);
+               data = vmalloc(size + offset);
                if (!data)
                        return ERR_PTR(-ENOMEM);
-               if (diag2fc(size, query, data) == 0)
+               if (diag2fc(size, query, data + offset) == 0)
                        break;
                vfree(data);
        } while (1);
-       *count = (size / sizeof(*data));
+       *count = (size / sizeof(struct diag2fc_data));
 
        return data;
 }
@@ -168,9 +175,10 @@ int hypfs_vm_create_files(struct super_block *sb, struct dentry *root)
 {
        struct dentry *dir, *file;
        struct diag2fc_data *data;
-       int rc, i, count = 0;
+       unsigned int count = 0;
+       int rc, i;
 
-       data = diag2fc_store(guest_query, &count);
+       data = diag2fc_store(guest_query, &count, 0);
        if (IS_ERR(data))
                return PTR_ERR(data);
 
@@ -218,8 +226,61 @@ failed:
        return rc;
 }
 
+struct dbfs_d2fc_hdr {
+       u64     len;            /* Length of d2fc buffer without header */
+       u16     version;        /* Version of header */
+       char    tod_ext[16];    /* TOD clock for d2fc */
+       u64     count;          /* Number of VM guests in d2fc buffer */
+       char    reserved[30];
+} __attribute__ ((packed));
+
+struct dbfs_d2fc {
+       struct dbfs_d2fc_hdr    hdr;    /* 64 byte header */
+       char                    buf[];  /* d2fc buffer */
+} __attribute__ ((packed));
+
+static int dbfs_d2fc_open(struct inode *inode, struct file *file)
+{
+       struct dbfs_d2fc *data;
+       unsigned int count;
+
+       data = diag2fc_store(guest_query, &count, sizeof(data->hdr));
+       if (IS_ERR(data))
+               return PTR_ERR(data);
+       get_clock_ext(data->hdr.tod_ext);
+       data->hdr.len = count * sizeof(struct diag2fc_data);
+       data->hdr.version = DBFS_D2FC_HDR_VERSION;
+       data->hdr.count = count;
+       memset(&data->hdr.reserved, 0, sizeof(data->hdr.reserved));
+       file->private_data = data;
+       return nonseekable_open(inode, file);
+}
+
+static int dbfs_d2fc_release(struct inode *inode, struct file *file)
+{
+       diag2fc_free(file->private_data);
+       return 0;
+}
+
+static ssize_t dbfs_d2fc_read(struct file *file, char __user *buf,
+                                   size_t size, loff_t *ppos)
+{
+       struct dbfs_d2fc *data = file->private_data;
+
+       return simple_read_from_buffer(buf, size, ppos, data, data->hdr.len +
+                                      sizeof(struct dbfs_d2fc_hdr));
+}
+
+static const struct file_operations dbfs_d2fc_ops = {
+       .open           = dbfs_d2fc_open,
+       .read           = dbfs_d2fc_read,
+       .release        = dbfs_d2fc_release,
+};
+
 int hypfs_vm_init(void)
 {
+       if (!MACHINE_IS_VM)
+               return 0;
        if (diag2fc(0, all_guests, NULL) > 0)
                guest_query = all_guests;
        else if (diag2fc(0, local_guest, NULL) > 0)
@@ -227,5 +288,17 @@ int hypfs_vm_init(void)
        else
                return -EACCES;
 
+       dbfs_d2fc_file = debugfs_create_file("diag_2fc", 0400, hypfs_dbfs_dir,
+                                            NULL, &dbfs_d2fc_ops);
+       if (IS_ERR(dbfs_d2fc_file))
+               return PTR_ERR(dbfs_d2fc_file);
+
        return 0;
 }
+
+void hypfs_vm_exit(void)
+{
+       if (!MACHINE_IS_VM)
+               return;
+       debugfs_remove(dbfs_d2fc_file);
+}
index c53f8ac..6b120f0 100644 (file)
@@ -46,6 +46,8 @@ static const struct super_operations hypfs_s_ops;
 /* start of list of all dentries, which have to be deleted on update */
 static struct dentry *hypfs_last_dentry;
 
+struct dentry *hypfs_dbfs_dir;
+
 static void hypfs_update_update(struct super_block *sb)
 {
        struct hypfs_sb_info *sb_info = sb->s_fs_info;
@@ -145,7 +147,7 @@ static int hypfs_open(struct inode *inode, struct file *filp)
                }
                mutex_unlock(&fs_info->lock);
        }
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
@@ -468,20 +470,22 @@ static int __init hypfs_init(void)
 {
        int rc;
 
-       if (MACHINE_IS_VM) {
-               if (hypfs_vm_init())
-                       /* no diag 2fc, just exit */
-                       return -ENODATA;
-       } else {
-               if (hypfs_diag_init()) {
-                       rc = -ENODATA;
-                       goto fail_diag;
-               }
+       hypfs_dbfs_dir = debugfs_create_dir("s390_hypfs", NULL);
+       if (IS_ERR(hypfs_dbfs_dir))
+               return PTR_ERR(hypfs_dbfs_dir);
+
+       if (hypfs_diag_init()) {
+               rc = -ENODATA;
+               goto fail_debugfs_remove;
+       }
+       if (hypfs_vm_init()) {
+               rc = -ENODATA;
+               goto fail_hypfs_diag_exit;
        }
        s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
        if (!s390_kobj) {
                rc = -ENOMEM;
-               goto fail_sysfs;
+               goto fail_hypfs_vm_exit;
        }
        rc = register_filesystem(&hypfs_type);
        if (rc)
@@ -490,18 +494,22 @@ static int __init hypfs_init(void)
 
 fail_filesystem:
        kobject_put(s390_kobj);
-fail_sysfs:
-       if (!MACHINE_IS_VM)
-               hypfs_diag_exit();
-fail_diag:
+fail_hypfs_vm_exit:
+       hypfs_vm_exit();
+fail_hypfs_diag_exit:
+       hypfs_diag_exit();
+fail_debugfs_remove:
+       debugfs_remove(hypfs_dbfs_dir);
+
        pr_err("Initialization of hypfs failed with rc=%i\n", rc);
        return rc;
 }
 
 static void __exit hypfs_exit(void)
 {
-       if (!MACHINE_IS_VM)
-               hypfs_diag_exit();
+       hypfs_diag_exit();
+       hypfs_vm_exit();
+       debugfs_remove(hypfs_dbfs_dir);
        unregister_filesystem(&hypfs_type);
        kobject_put(s390_kobj);
 }
index 258ba88..8b1a52a 100644 (file)
@@ -188,15 +188,16 @@ struct s390_idle_data {
 
 DECLARE_PER_CPU(struct s390_idle_data, s390_idle);
 
-void vtime_start_cpu(void);
+void vtime_start_cpu(__u64 int_clock, __u64 enter_timer);
 cputime64_t s390_get_idle_time(int cpu);
 
 #define arch_idle_time(cpu) s390_get_idle_time(cpu)
 
-static inline void s390_idle_check(void)
+static inline void s390_idle_check(struct pt_regs *regs, __u64 int_clock,
+                                  __u64 enter_timer)
 {
-       if ((&__get_cpu_var(s390_idle))->idle_enter != 0ULL)
-               vtime_start_cpu();
+       if (regs->psw.mask & PSW_MASK_WAIT)
+               vtime_start_cpu(int_clock, enter_timer);
 }
 
 static inline int s390_nohz_delay(int cpu)
index 05527c0..0f97ef2 100644 (file)
@@ -104,38 +104,39 @@ struct _lowcore {
        /* CPU time accounting values */
        __u64   sync_enter_timer;               /* 0x0250 */
        __u64   async_enter_timer;              /* 0x0258 */
-       __u64   exit_timer;                     /* 0x0260 */
-       __u64   user_timer;                     /* 0x0268 */
-       __u64   system_timer;                   /* 0x0270 */
-       __u64   steal_timer;                    /* 0x0278 */
-       __u64   last_update_timer;              /* 0x0280 */
-       __u64   last_update_clock;              /* 0x0288 */
+       __u64   mcck_enter_timer;               /* 0x0260 */
+       __u64   exit_timer;                     /* 0x0268 */
+       __u64   user_timer;                     /* 0x0270 */
+       __u64   system_timer;                   /* 0x0278 */
+       __u64   steal_timer;                    /* 0x0280 */
+       __u64   last_update_timer;              /* 0x0288 */
+       __u64   last_update_clock;              /* 0x0290 */
 
        /* Current process. */
-       __u32   current_task;                   /* 0x0290 */
-       __u32   thread_info;                    /* 0x0294 */
-       __u32   kernel_stack;                   /* 0x0298 */
+       __u32   current_task;                   /* 0x0298 */
+       __u32   thread_info;                    /* 0x029c */
+       __u32   kernel_stack;                   /* 0x02a0 */
 
        /* Interrupt and panic stack. */
-       __u32   async_stack;                    /* 0x029c */
-       __u32   panic_stack;                    /* 0x02a0 */
+       __u32   async_stack;                    /* 0x02a4 */
+       __u32   panic_stack;                    /* 0x02a8 */
 
        /* Address space pointer. */
-       __u32   kernel_asce;                    /* 0x02a4 */
-       __u32   user_asce;                      /* 0x02a8 */
-       __u32   user_exec_asce;                 /* 0x02ac */
+       __u32   kernel_asce;                    /* 0x02ac */
+       __u32   user_asce;                      /* 0x02b0 */
+       __u32   user_exec_asce;                 /* 0x02b4 */
 
        /* SMP info area */
-       struct cpuid cpu_id;                    /* 0x02b0 */
        __u32   cpu_nr;                         /* 0x02b8 */
        __u32   softirq_pending;                /* 0x02bc */
        __u32   percpu_offset;                  /* 0x02c0 */
        __u32   ext_call_fast;                  /* 0x02c4 */
        __u64   int_clock;                      /* 0x02c8 */
-       __u64   clock_comparator;               /* 0x02d0 */
-       __u32   machine_flags;                  /* 0x02d8 */
-       __u32   ftrace_func;                    /* 0x02dc */
-       __u8    pad_0x02e0[0x0300-0x02e0];      /* 0x02e0 */
+       __u64   mcck_clock;                     /* 0x02d0 */
+       __u64   clock_comparator;               /* 0x02d8 */
+       __u32   machine_flags;                  /* 0x02e0 */
+       __u32   ftrace_func;                    /* 0x02e4 */
+       __u8    pad_0x02e8[0x0300-0x02e8];      /* 0x02e8 */
 
        /* Interrupt response block */
        __u8    irb[64];                        /* 0x0300 */
@@ -189,14 +190,14 @@ struct _lowcore {
        __u32   data_exc_code;                  /* 0x0090 */
        __u16   mon_class_num;                  /* 0x0094 */
        __u16   per_perc_atmid;                 /* 0x0096 */
-       addr_t  per_address;                    /* 0x0098 */
+       __u64   per_address;                    /* 0x0098 */
        __u8    exc_access_id;                  /* 0x00a0 */
        __u8    per_access_id;                  /* 0x00a1 */
        __u8    op_access_id;                   /* 0x00a2 */
        __u8    ar_access_id;                   /* 0x00a3 */
        __u8    pad_0x00a4[0x00a8-0x00a4];      /* 0x00a4 */
-       addr_t  trans_exc_code;                 /* 0x00a8 */
-       addr_t  monitor_code;                   /* 0x00b0 */
+       __u64   trans_exc_code;                 /* 0x00a8 */
+       __u64   monitor_code;                   /* 0x00b0 */
        __u16   subchannel_id;                  /* 0x00b8 */
        __u16   subchannel_nr;                  /* 0x00ba */
        __u32   io_int_parm;                    /* 0x00bc */
@@ -207,7 +208,7 @@ struct _lowcore {
        __u32   mcck_interruption_code[2];      /* 0x00e8 */
        __u8    pad_0x00f0[0x00f4-0x00f0];      /* 0x00f0 */
        __u32   external_damage_code;           /* 0x00f4 */
-       addr_t  failing_storage_address;        /* 0x00f8 */
+       __u64   failing_storage_address;        /* 0x00f8 */
        __u8    pad_0x0100[0x0110-0x0100];      /* 0x0100 */
        __u64   breaking_event_addr;            /* 0x0110 */
        __u8    pad_0x0118[0x0120-0x0118];      /* 0x0118 */
@@ -233,39 +234,41 @@ struct _lowcore {
        /* CPU accounting and timing values. */
        __u64   sync_enter_timer;               /* 0x02a0 */
        __u64   async_enter_timer;              /* 0x02a8 */
-       __u64   exit_timer;                     /* 0x02b0 */
-       __u64   user_timer;                     /* 0x02b8 */
-       __u64   system_timer;                   /* 0x02c0 */
-       __u64   steal_timer;                    /* 0x02c8 */
-       __u64   last_update_timer;              /* 0x02d0 */
-       __u64   last_update_clock;              /* 0x02d8 */
+       __u64   mcck_enter_timer;               /* 0x02b0 */
+       __u64   exit_timer;                     /* 0x02b8 */
+       __u64   user_timer;                     /* 0x02c0 */
+       __u64   system_timer;                   /* 0x02c8 */
+       __u64   steal_timer;                    /* 0x02d0 */
+       __u64   last_update_timer;              /* 0x02d8 */
+       __u64   last_update_clock;              /* 0x02e0 */
 
        /* Current process. */
-       __u64   current_task;                   /* 0x02e0 */
-       __u64   thread_info;                    /* 0x02e8 */
-       __u64   kernel_stack;                   /* 0x02f0 */
+       __u64   current_task;                   /* 0x02e8 */
+       __u64   thread_info;                    /* 0x02f0 */
+       __u64   kernel_stack;                   /* 0x02f8 */
 
        /* Interrupt and panic stack. */
-       __u64   async_stack;                    /* 0x02f8 */
-       __u64   panic_stack;                    /* 0x0300 */
+       __u64   async_stack;                    /* 0x0300 */
+       __u64   panic_stack;                    /* 0x0308 */
 
        /* Address space pointer. */
-       __u64   kernel_asce;                    /* 0x0308 */
-       __u64   user_asce;                      /* 0x0310 */
-       __u64   user_exec_asce;                 /* 0x0318 */
+       __u64   kernel_asce;                    /* 0x0310 */
+       __u64   user_asce;                      /* 0x0318 */
+       __u64   user_exec_asce;                 /* 0x0320 */
 
        /* SMP info area */
-       struct cpuid cpu_id;                    /* 0x0320 */
        __u32   cpu_nr;                         /* 0x0328 */
        __u32   softirq_pending;                /* 0x032c */
        __u64   percpu_offset;                  /* 0x0330 */
        __u64   ext_call_fast;                  /* 0x0338 */
        __u64   int_clock;                      /* 0x0340 */
-       __u64   clock_comparator;               /* 0x0348 */
-       __u64   vdso_per_cpu_data;              /* 0x0350 */
-       __u64   machine_flags;                  /* 0x0358 */
-       __u64   ftrace_func;                    /* 0x0360 */
-       __u8    pad_0x0368[0x0380-0x0368];      /* 0x0368 */
+       __u64   mcck_clock;                     /* 0x0348 */
+       __u64   clock_comparator;               /* 0x0350 */
+       __u64   vdso_per_cpu_data;              /* 0x0358 */
+       __u64   machine_flags;                  /* 0x0360 */
+       __u64   ftrace_func;                    /* 0x0368 */
+       __u64   sie_hook;                       /* 0x0370 */
+       __u64   cmf_hpp;                        /* 0x0378 */
 
        /* Interrupt response block. */
        __u8    irb[64];                        /* 0x0380 */
index fef9b33..e2c218d 100644 (file)
@@ -328,8 +328,8 @@ struct pt_regs
        psw_t psw;
        unsigned long gprs[NUM_GPRS];
        unsigned long orig_gpr2;
-       unsigned short svcnr;
        unsigned short ilc;
+       unsigned short svcnr;
 };
 #endif
 
@@ -436,6 +436,7 @@ typedef struct
 #define PTRACE_PEEKDATA_AREA         0x5003
 #define PTRACE_POKETEXT_AREA         0x5004
 #define PTRACE_POKEDATA_AREA         0x5005
+#define PTRACE_GET_LAST_BREAK        0x5006
 
 /*
  * PT_PROT definition is loosely based on hppa bsd definition in
index 9b04b11..0eaae62 100644 (file)
@@ -368,14 +368,12 @@ struct qdio_initialize {
 #define QDIO_FLAG_SYNC_OUTPUT          0x02
 #define QDIO_FLAG_PCI_OUT              0x10
 
-extern int qdio_initialize(struct qdio_initialize *);
 extern int qdio_allocate(struct qdio_initialize *);
 extern int qdio_establish(struct qdio_initialize *);
 extern int qdio_activate(struct ccw_device *);
 
 extern int do_QDIO(struct ccw_device *cdev, unsigned int callflags,
                   int q_nr, unsigned int bufnr, unsigned int count);
-extern int qdio_cleanup(struct ccw_device*, int);
 extern int qdio_shutdown(struct ccw_device*, int);
 extern int qdio_free(struct ccw_device *);
 extern int qdio_get_ssqd_desc(struct ccw_device *dev, struct qdio_ssqd_desc*);
index 9ab6bd3..25e831d 100644 (file)
@@ -2,7 +2,7 @@
  *  include/asm-s390/setup.h
  *
  *  S390 version
- *    Copyright IBM Corp. 1999,2006
+ *    Copyright IBM Corp. 1999,2010
  */
 
 #ifndef _ASM_S390_SETUP_H
@@ -72,6 +72,7 @@ extern unsigned int user_mode;
 #define MACHINE_FLAG_HPAGE     (1UL << 10)
 #define MACHINE_FLAG_PFMF      (1UL << 11)
 #define MACHINE_FLAG_LPAR      (1UL << 12)
+#define MACHINE_FLAG_SPP       (1UL << 13)
 
 #define MACHINE_IS_VM          (S390_lowcore.machine_flags & MACHINE_FLAG_VM)
 #define MACHINE_IS_KVM         (S390_lowcore.machine_flags & MACHINE_FLAG_KVM)
@@ -88,6 +89,7 @@ extern unsigned int user_mode;
 #define MACHINE_HAS_MVCOS      (0)
 #define MACHINE_HAS_HPAGE      (0)
 #define MACHINE_HAS_PFMF       (0)
+#define MACHINE_HAS_SPP                (0)
 #else /* __s390x__ */
 #define MACHINE_HAS_IEEE       (1)
 #define MACHINE_HAS_CSP                (1)
@@ -97,6 +99,7 @@ extern unsigned int user_mode;
 #define MACHINE_HAS_MVCOS      (S390_lowcore.machine_flags & MACHINE_FLAG_MVCOS)
 #define MACHINE_HAS_HPAGE      (S390_lowcore.machine_flags & MACHINE_FLAG_HPAGE)
 #define MACHINE_HAS_PFMF       (S390_lowcore.machine_flags & MACHINE_FLAG_PFMF)
+#define MACHINE_HAS_SPP                (S390_lowcore.machine_flags & MACHINE_FLAG_SPP)
 #endif /* __s390x__ */
 
 #define ZFCPDUMP_HSA_SIZE      (32UL<<20)
index 1741c15..cef6621 100644 (file)
@@ -459,11 +459,6 @@ extern void (*_machine_power_off)(void);
 
 #define arch_align_stack(x) (x)
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-extern psw_t sysc_restore_trace_psw;
-extern psw_t io_restore_trace_psw;
-#endif
-
 static inline int tprot(unsigned long addr)
 {
        int rc = -EFAULT;
index 34f0873..5baf023 100644 (file)
@@ -50,6 +50,7 @@ struct thread_info {
        struct restart_block    restart_block;
        __u64                   user_timer;
        __u64                   system_timer;
+       unsigned long           last_break;     /* last breaking-event-address. */
 };
 
 /*
@@ -96,7 +97,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling
                                           TIF_NEED_RESCHED */
 #define TIF_31BIT              17      /* 32bit process */
-#define TIF_MEMDIE             18
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    19      /* restore signal mask in do_signal() */
 #define TIF_FREEZE             20      /* thread is freezing for suspend */
 
index f174bda..09d345a 100644 (file)
@@ -61,11 +61,15 @@ static inline unsigned long long get_clock (void)
        return clk;
 }
 
+static inline void get_clock_ext(char *clk)
+{
+       asm volatile("stcke %0" : "=Q" (*clk) : : "cc");
+}
+
 static inline unsigned long long get_clock_xt(void)
 {
        unsigned char clk[16];
-
-       asm volatile("stcke %0" : "=Q" (clk) : : "cc");
+       get_clock_ext(clk);
        return *((unsigned long long *)&clk[1]);
 }
 
index 6e7211a..dc8a672 100644 (file)
@@ -7,8 +7,10 @@
 
 const struct cpumask *cpu_coregroup_mask(unsigned int cpu);
 
+extern unsigned char cpu_core_id[NR_CPUS];
 extern cpumask_t cpu_core_map[NR_CPUS];
 
+#define topology_core_id(cpu)          (cpu_core_id[cpu])
 #define topology_core_cpumask(cpu)     (&cpu_core_map[cpu])
 
 int topology_set_cpu_management(int fc);
index a094089..d9b490a 100644 (file)
@@ -39,6 +39,7 @@ int main(void)
        DEFINE(__TI_precount, offsetof(struct thread_info, preempt_count));
        DEFINE(__TI_user_timer, offsetof(struct thread_info, user_timer));
        DEFINE(__TI_system_timer, offsetof(struct thread_info, system_timer));
+       DEFINE(__TI_last_break, offsetof(struct thread_info, last_break));
        BLANK();
        DEFINE(__PT_ARGS, offsetof(struct pt_regs, args));
        DEFINE(__PT_PSW, offsetof(struct pt_regs, psw));
@@ -112,6 +113,7 @@ int main(void)
        DEFINE(__LC_RETURN_MCCK_PSW, offsetof(struct _lowcore, return_mcck_psw));
        DEFINE(__LC_SYNC_ENTER_TIMER, offsetof(struct _lowcore, sync_enter_timer));
        DEFINE(__LC_ASYNC_ENTER_TIMER, offsetof(struct _lowcore, async_enter_timer));
+       DEFINE(__LC_MCCK_ENTER_TIMER, offsetof(struct _lowcore, mcck_enter_timer));
        DEFINE(__LC_EXIT_TIMER, offsetof(struct _lowcore, exit_timer));
        DEFINE(__LC_USER_TIMER, offsetof(struct _lowcore, user_timer));
        DEFINE(__LC_SYSTEM_TIMER, offsetof(struct _lowcore, system_timer));
@@ -126,10 +128,12 @@ int main(void)
        DEFINE(__LC_KERNEL_ASCE, offsetof(struct _lowcore, kernel_asce));
        DEFINE(__LC_USER_ASCE, offsetof(struct _lowcore, user_asce));
        DEFINE(__LC_USER_EXEC_ASCE, offsetof(struct _lowcore, user_exec_asce));
-       DEFINE(__LC_CPUID, offsetof(struct _lowcore, cpu_id));
        DEFINE(__LC_INT_CLOCK, offsetof(struct _lowcore, int_clock));
+       DEFINE(__LC_MCCK_CLOCK, offsetof(struct _lowcore, mcck_clock));
        DEFINE(__LC_MACHINE_FLAGS, offsetof(struct _lowcore, machine_flags));
        DEFINE(__LC_FTRACE_FUNC, offsetof(struct _lowcore, ftrace_func));
+       DEFINE(__LC_SIE_HOOK, offsetof(struct _lowcore, sie_hook));
+       DEFINE(__LC_CMF_HPP, offsetof(struct _lowcore, cmf_hpp));
        DEFINE(__LC_IRB, offsetof(struct _lowcore, irb));
        DEFINE(__LC_CPU_TIMER_SAVE_AREA, offsetof(struct _lowcore, cpu_timer_save_area));
        DEFINE(__LC_CLOCK_COMP_SAVE_AREA, offsetof(struct _lowcore, clock_comp_save_area));
index 0168472..9819226 100644 (file)
@@ -655,6 +655,7 @@ found:
        p_info->act_entry_offset = 0;
        file->private_data = p_info;
        debug_info_get(debug_info);
+       nonseekable_open(inode, file);
 out:
        mutex_unlock(&debug_mutex);
        return rc;
index 2d92c2c..c00856a 100644 (file)
@@ -356,6 +356,7 @@ static __init void detect_machine_facilities(void)
 {
 #ifdef CONFIG_64BIT
        unsigned int facilities;
+       unsigned long long facility_bits;
 
        facilities = stfl();
        if (facilities & (1 << 28))
@@ -364,6 +365,9 @@ static __init void detect_machine_facilities(void)
                S390_lowcore.machine_flags |= MACHINE_FLAG_PFMF;
        if (facilities & (1 << 4))
                S390_lowcore.machine_flags |= MACHINE_FLAG_MVCOS;
+       if ((stfle(&facility_bits, 1) > 0) &&
+           (facility_bits & (1ULL << (63 - 40))))
+               S390_lowcore.machine_flags |= MACHINE_FLAG_SPP;
 #endif
 }
 
index 6af7045..d5e3e60 100644 (file)
@@ -73,21 +73,24 @@ STACK_SIZE  = 1 << STACK_SHIFT
        basr    %r14,%r1
        .endm
 
-       .macro  TRACE_IRQS_CHECK
-       basr    %r2,%r0
+       .macro  TRACE_IRQS_CHECK_ON
        tm      SP_PSW(%r15),0x03       # irqs enabled?
-       jz      0f
-       l       %r1,BASED(.Ltrace_irq_on_caller)
-       basr    %r14,%r1
-       j       1f
-0:     l       %r1,BASED(.Ltrace_irq_off_caller)
-       basr    %r14,%r1
-1:
+       bz      BASED(0f)
+       TRACE_IRQS_ON
+0:
+       .endm
+
+       .macro  TRACE_IRQS_CHECK_OFF
+       tm      SP_PSW(%r15),0x03       # irqs enabled?
+       bz      BASED(0f)
+       TRACE_IRQS_OFF
+0:
        .endm
 #else
 #define TRACE_IRQS_ON
 #define TRACE_IRQS_OFF
-#define TRACE_IRQS_CHECK
+#define TRACE_IRQS_CHECK_ON
+#define TRACE_IRQS_CHECK_OFF
 #endif
 
 #ifdef CONFIG_LOCKDEP
@@ -177,9 +180,9 @@ STACK_SIZE  = 1 << STACK_SHIFT
        s       %r15,BASED(.Lc_spsize)  # make room for registers & psw
        mvc     SP_PSW(8,%r15),0(%r12)  # move user PSW to stack
        st      %r2,SP_ORIG_R2(%r15)    # store original content of gpr 2
-       icm     %r12,3,__LC_SVC_ILC
+       icm     %r12,12,__LC_SVC_ILC
        stm     %r0,%r11,SP_R0(%r15)    # store gprs %r0-%r11 to kernel stack
-       st      %r12,SP_SVCNR(%r15)
+       st      %r12,SP_ILC(%r15)
        mvc     SP_R12(16,%r15),\savearea # move %r12-%r15 to stack
        la      %r12,0
        st      %r12,__SF_BACKCHAIN(%r15)       # clear back chain
@@ -273,66 +276,45 @@ sysc_do_restart:
        st      %r2,SP_R2(%r15)   # store return value (change R2 on stack)
 
 sysc_return:
+       LOCKDEP_SYS_EXIT
+sysc_tif:
        tm      __TI_flags+3(%r9),_TIF_WORK_SVC
        bnz     BASED(sysc_work)  # there is work to do (signals etc.)
 sysc_restore:
-#ifdef CONFIG_TRACE_IRQFLAGS
-       la      %r1,BASED(sysc_restore_trace_psw_addr)
-       l       %r1,0(%r1)
-       lpsw    0(%r1)
-sysc_restore_trace:
-       TRACE_IRQS_CHECK
-       LOCKDEP_SYS_EXIT
-#endif
-sysc_leave:
        RESTORE_ALL __LC_RETURN_PSW,1
 sysc_done:
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-sysc_restore_trace_psw_addr:
-       .long sysc_restore_trace_psw
-
-       .section .data,"aw",@progbits
-       .align  8
-       .globl  sysc_restore_trace_psw
-sysc_restore_trace_psw:
-       .long   0, sysc_restore_trace + 0x80000000
-       .previous
-#endif
-
-#
-# recheck if there is more work to do
 #
-sysc_work_loop:
-       tm      __TI_flags+3(%r9),_TIF_WORK_SVC
-       bz      BASED(sysc_restore)     # there is no work to do
-#
-# One of the work bits is on. Find out which one.
+# There is work to do, but first we need to check if we return to userspace.
 #
 sysc_work:
        tm      SP_PSW+1(%r15),0x01     # returning to user ?
        bno     BASED(sysc_restore)
+
+#
+# One of the work bits is on. Find out which one.
+#
+sysc_work_tif:
        tm      __TI_flags+3(%r9),_TIF_MCCK_PENDING
        bo      BASED(sysc_mcck_pending)
        tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
        bo      BASED(sysc_reschedule)
        tm      __TI_flags+3(%r9),_TIF_SIGPENDING
-       bnz     BASED(sysc_sigpending)
+       b     BASED(sysc_sigpending)
        tm      __TI_flags+3(%r9),_TIF_NOTIFY_RESUME
-       bnz     BASED(sysc_notify_resume)
+       b     BASED(sysc_notify_resume)
        tm      __TI_flags+3(%r9),_TIF_RESTART_SVC
        bo      BASED(sysc_restart)
        tm      __TI_flags+3(%r9),_TIF_SINGLE_STEP
        bo      BASED(sysc_singlestep)
-       b       BASED(sysc_restore)
-sysc_work_done:
+       b       BASED(sysc_return)      # beware of critical section cleanup
 
 #
 # _TIF_NEED_RESCHED is set, call schedule
 #
 sysc_reschedule:
        l       %r1,BASED(.Lschedule)
-       la      %r14,BASED(sysc_work_loop)
+       la      %r14,BASED(sysc_return)
        br      %r1                     # call scheduler
 
 #
@@ -340,7 +322,7 @@ sysc_reschedule:
 #
 sysc_mcck_pending:
        l       %r1,BASED(.Ls390_handle_mcck)
-       la      %r14,BASED(sysc_work_loop)
+       la      %r14,BASED(sysc_return)
        br      %r1                     # TIF bit will be cleared by handler
 
 #
@@ -355,7 +337,7 @@ sysc_sigpending:
        bo      BASED(sysc_restart)
        tm      __TI_flags+3(%r9),_TIF_SINGLE_STEP
        bo      BASED(sysc_singlestep)
-       b       BASED(sysc_work_loop)
+       b       BASED(sysc_return)
 
 #
 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
@@ -363,7 +345,7 @@ sysc_sigpending:
 sysc_notify_resume:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        l       %r1,BASED(.Ldo_notify_resume)
-       la      %r14,BASED(sysc_work_loop)
+       la      %r14,BASED(sysc_return)
        br      %r1                     # call do_notify_resume
 
 
@@ -458,11 +440,13 @@ kernel_execve:
        br      %r14
        # execve succeeded.
 0:     stnsm   __SF_EMPTY(%r15),0xfc   # disable interrupts
+       TRACE_IRQS_OFF
        l       %r15,__LC_KERNEL_STACK  # load ksp
        s       %r15,BASED(.Lc_spsize)  # make room for registers & psw
        l       %r9,__LC_THREAD_INFO
        mvc     SP_PTREGS(__PT_SIZE,%r15),0(%r12)       # copy pt_regs
        xc      __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
+       TRACE_IRQS_ON
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        l       %r1,BASED(.Lexecve_tail)
        basr    %r14,%r1
@@ -499,8 +483,8 @@ pgm_check_handler:
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
 pgm_no_vtime:
+       TRACE_IRQS_CHECK_OFF
        l       %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       TRACE_IRQS_OFF
        l       %r3,__LC_PGM_ILC        # load program interruption code
        la      %r8,0x7f
        nr      %r8,%r3
@@ -509,8 +493,10 @@ pgm_do_call:
        sll     %r8,2
        l       %r7,0(%r8,%r7)          # load address of handler routine
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
-       la      %r14,BASED(sysc_return)
-       br      %r7                     # branch to interrupt-handler
+       basr    %r14,%r7                # branch to interrupt-handler
+pgm_exit:
+       TRACE_IRQS_CHECK_ON
+       b       BASED(sysc_return)
 
 #
 # handle per exception
@@ -537,19 +523,19 @@ pgm_per_std:
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
 pgm_no_vtime2:
+       TRACE_IRQS_CHECK_OFF
        l       %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       TRACE_IRQS_OFF
        l       %r1,__TI_task(%r9)
+       tm      SP_PSW+1(%r15),0x01     # kernel per event ?
+       bz      BASED(kernel_per)
        mvc     __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
        mvc     __THREAD_per+__PER_address(4,%r1),__LC_PER_ADDRESS
        mvc     __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
        oi      __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
-       tm      SP_PSW+1(%r15),0x01     # kernel per event ?
-       bz      BASED(kernel_per)
        l       %r3,__LC_PGM_ILC        # load program interruption code
        la      %r8,0x7f
        nr      %r8,%r3                 # clear per-event-bit and ilc
-       be      BASED(sysc_return)      # only per or per+check ?
+       be      BASED(pgm_exit)         # only per or per+check ?
        b       BASED(pgm_do_call)
 
 #
@@ -570,8 +556,8 @@ pgm_svcper:
        mvc     __THREAD_per+__PER_access_id(1,%r8),__LC_PER_ACCESS_ID
        oi      __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
        TRACE_IRQS_ON
-       lm      %r2,%r6,SP_R2(%r15)     # load svc arguments
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
+       lm      %r2,%r6,SP_R2(%r15)     # load svc arguments
        b       BASED(sysc_do_svc)
 
 #
@@ -582,8 +568,8 @@ kernel_per:
        mvi     SP_SVCNR+1(%r15),0xff
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        l       %r1,BASED(.Lhandle_per) # load adr. of per handler
-       la      %r14,BASED(sysc_restore)# load adr. of system return
-       br      %r1                     # branch to do_single_step
+       basr    %r14,%r1                # branch to do_single_step
+       b       BASED(pgm_exit)
 
 /*
  * IO interrupt handler routine
@@ -602,134 +588,126 @@ io_int_handler:
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
 io_no_vtime:
-       l       %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
        TRACE_IRQS_OFF
+       l       %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
        l       %r1,BASED(.Ldo_IRQ)     # load address of do_IRQ
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        basr    %r14,%r1                # branch to standard irq handler
 io_return:
+       LOCKDEP_SYS_EXIT
+       TRACE_IRQS_ON
+io_tif:
        tm      __TI_flags+3(%r9),_TIF_WORK_INT
        bnz     BASED(io_work)          # there is work to do (signals etc.)
 io_restore:
-#ifdef CONFIG_TRACE_IRQFLAGS
-       la      %r1,BASED(io_restore_trace_psw_addr)
-       l       %r1,0(%r1)
-       lpsw    0(%r1)
-io_restore_trace:
-       TRACE_IRQS_CHECK
-       LOCKDEP_SYS_EXIT
-#endif
-io_leave:
        RESTORE_ALL __LC_RETURN_PSW,0
 io_done:
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-io_restore_trace_psw_addr:
-       .long io_restore_trace_psw
-
-       .section .data,"aw",@progbits
-       .align  8
-       .globl  io_restore_trace_psw
-io_restore_trace_psw:
-       .long   0, io_restore_trace + 0x80000000
-       .previous
-#endif
-
 #
-# switch to kernel stack, then check the TIF bits
+# There is work todo, find out in which context we have been interrupted:
+# 1) if we return to user space we can do all _TIF_WORK_INT work
+# 2) if we return to kernel code and preemptive scheduling is enabled check
+#    the preemption counter and if it is zero call preempt_schedule_irq
+# Before any work can be done, a switch to the kernel stack is required.
 #
 io_work:
        tm      SP_PSW+1(%r15),0x01     # returning to user ?
-#ifndef CONFIG_PREEMPT
-       bno     BASED(io_restore)       # no-> skip resched & signal
-#else
-       bnz     BASED(io_work_user)     # no -> check for preemptive scheduling
+       bo      BASED(io_work_user)     # yes -> do resched & signal
+#ifdef CONFIG_PREEMPT
        # check for preemptive scheduling
        icm     %r0,15,__TI_precount(%r9)
        bnz     BASED(io_restore)       # preemption disabled
+       tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
+       bno     BASED(io_restore)
+       # switch to kernel stack
        l       %r1,SP_R15(%r15)
        s       %r1,BASED(.Lc_spsize)
        mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
        xc      __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
        lr      %r15,%r1
-io_resume_loop:
-       tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
-       bno     BASED(io_restore)
+       # TRACE_IRQS_ON already done at io_return, call
+       # TRACE_IRQS_OFF to keep things symmetrical
+       TRACE_IRQS_OFF
        l       %r1,BASED(.Lpreempt_schedule_irq)
-       la      %r14,BASED(io_resume_loop)
-       br      %r1                     # call schedule
+       basr    %r14,%r1                # call preempt_schedule_irq
+       b       BASED(io_return)
+#else
+       b       BASED(io_restore)
 #endif
 
+#
+# Need to do work before returning to userspace, switch to kernel stack
+#
 io_work_user:
        l       %r1,__LC_KERNEL_STACK
        s       %r1,BASED(.Lc_spsize)
        mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
        xc      __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
        lr      %r15,%r1
+
 #
 # One of the work bits is on. Find out which one.
-# Checked are: _TIF_SIGPENDING, _TIF_NEED_RESCHED
+# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
 #              and _TIF_MCCK_PENDING
 #
-io_work_loop:
+io_work_tif:
        tm      __TI_flags+3(%r9),_TIF_MCCK_PENDING
        bo      BASED(io_mcck_pending)
        tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
        bo      BASED(io_reschedule)
        tm      __TI_flags+3(%r9),_TIF_SIGPENDING
-       bnz     BASED(io_sigpending)
+       b     BASED(io_sigpending)
        tm      __TI_flags+3(%r9),_TIF_NOTIFY_RESUME
-       bnz     BASED(io_notify_resume)
-       b       BASED(io_restore)
-io_work_done:
+       bo      BASED(io_notify_resume)
+       b       BASED(io_return)        # beware of critical section cleanup
 
 #
 # _TIF_MCCK_PENDING is set, call handler
 #
 io_mcck_pending:
+       # TRACE_IRQS_ON already done at io_return
        l       %r1,BASED(.Ls390_handle_mcck)
        basr    %r14,%r1                # TIF bit will be cleared by handler
-       b       BASED(io_work_loop)
+       TRACE_IRQS_OFF
+       b       BASED(io_return)
 
 #
 # _TIF_NEED_RESCHED is set, call schedule
 #
 io_reschedule:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        l       %r1,BASED(.Lschedule)
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        basr    %r14,%r1                # call scheduler
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       tm      __TI_flags+3(%r9),_TIF_WORK_INT
-       bz      BASED(io_restore)       # there is no work to do
-       b       BASED(io_work_loop)
+       b       BASED(io_return)
 
 #
 # _TIF_SIGPENDING is set, call do_signal
 #
 io_sigpending:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        l       %r1,BASED(.Ldo_signal)
        basr    %r14,%r1                # call do_signal
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       b       BASED(io_work_loop)
+       b       BASED(io_return)
 
 #
 # _TIF_SIGPENDING is set, call do_signal
 #
 io_notify_resume:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        l       %r1,BASED(.Ldo_notify_resume)
        basr    %r14,%r1                # call do_signal
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       b       BASED(io_work_loop)
+       b       BASED(io_return)
 
 /*
  * External interrupt handler routine
@@ -764,15 +742,14 @@ __critical_end:
 
        .globl mcck_int_handler
 mcck_int_handler:
-       stck    __LC_INT_CLOCK
+       stck    __LC_MCCK_CLOCK
        spt     __LC_CPU_TIMER_SAVE_AREA        # revalidate cpu timer
        lm      %r0,%r15,__LC_GPREGS_SAVE_AREA  # revalidate gprs
        SAVE_ALL_BASE __LC_SAVE_AREA+32
        la      %r12,__LC_MCK_OLD_PSW
        tm      __LC_MCCK_CODE,0x80     # system damage?
        bo      BASED(mcck_int_main)    # yes -> rest of mcck code invalid
-       mvc     __LC_SAVE_AREA+52(8),__LC_ASYNC_ENTER_TIMER
-       mvc     __LC_ASYNC_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA
+       mvc     __LC_MCCK_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA
        tm      __LC_MCCK_CODE+5,0x02   # stored cpu timer value valid?
        bo      BASED(1f)
        la      %r14,__LC_SYNC_ENTER_TIMER
@@ -786,7 +763,7 @@ mcck_int_handler:
        bl      BASED(0f)
        la      %r14,__LC_LAST_UPDATE_TIMER
 0:     spt     0(%r14)
-       mvc     __LC_ASYNC_ENTER_TIMER(8),0(%r14)
+       mvc     __LC_MCCK_ENTER_TIMER(8),0(%r14)
 1:     tm      __LC_MCCK_CODE+2,0x09   # mwp + ia of old psw valid?
        bno     BASED(mcck_int_main)    # no -> skip cleanup critical
        tm      __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
@@ -808,9 +785,9 @@ mcck_int_main:
        bno     BASED(mcck_no_vtime)    # no -> skip cleanup critical
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        bz      BASED(mcck_no_vtime)
-       UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
+       UPDATE_VTIME __LC_EXIT_TIMER,__LC_MCCK_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
-       mvc     __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
+       mvc     __LC_LAST_UPDATE_TIMER(8),__LC_MCCK_ENTER_TIMER
 mcck_no_vtime:
        l       %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
@@ -833,7 +810,6 @@ mcck_no_vtime:
 mcck_return:
        mvc     __LC_RETURN_MCCK_PSW(8),SP_PSW(%r15) # move return PSW
        ni      __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
-       mvc     __LC_ASYNC_ENTER_TIMER(8),__LC_SAVE_AREA+52
        tm      __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
        bno     BASED(0f)
        lm      %r0,%r15,SP_R0(%r15)    # load gprs 0-15
@@ -917,18 +893,14 @@ stack_overflow:
 
 cleanup_table_system_call:
        .long   system_call + 0x80000000, sysc_do_svc + 0x80000000
-cleanup_table_sysc_return:
-       .long   sysc_return + 0x80000000, sysc_leave + 0x80000000
-cleanup_table_sysc_leave:
-       .long   sysc_leave + 0x80000000, sysc_done + 0x80000000
-cleanup_table_sysc_work_loop:
-       .long   sysc_work_loop + 0x80000000, sysc_work_done + 0x80000000
-cleanup_table_io_return:
-       .long   io_return + 0x80000000, io_leave + 0x80000000
-cleanup_table_io_leave:
-       .long   io_leave + 0x80000000, io_done + 0x80000000
-cleanup_table_io_work_loop:
-       .long   io_work_loop + 0x80000000, io_work_done + 0x80000000
+cleanup_table_sysc_tif:
+       .long   sysc_tif + 0x80000000, sysc_restore + 0x80000000
+cleanup_table_sysc_restore:
+       .long   sysc_restore + 0x80000000, sysc_done + 0x80000000
+cleanup_table_io_tif:
+       .long   io_tif + 0x80000000, io_restore + 0x80000000
+cleanup_table_io_restore:
+       .long   io_restore + 0x80000000, io_done + 0x80000000
 
 cleanup_critical:
        clc     4(4,%r12),BASED(cleanup_table_system_call)
@@ -936,49 +908,40 @@ cleanup_critical:
        clc     4(4,%r12),BASED(cleanup_table_system_call+4)
        bl      BASED(cleanup_system_call)
 0:
-       clc     4(4,%r12),BASED(cleanup_table_sysc_return)
-       bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_sysc_return+4)
-       bl      BASED(cleanup_sysc_return)
-0:
-       clc     4(4,%r12),BASED(cleanup_table_sysc_leave)
-       bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_sysc_leave+4)
-       bl      BASED(cleanup_sysc_leave)
-0:
-       clc     4(4,%r12),BASED(cleanup_table_sysc_work_loop)
+       clc     4(4,%r12),BASED(cleanup_table_sysc_tif)
        bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_sysc_work_loop+4)
-       bl      BASED(cleanup_sysc_return)
+       clc     4(4,%r12),BASED(cleanup_table_sysc_tif+4)
+       bl      BASED(cleanup_sysc_tif)
 0:
-       clc     4(4,%r12),BASED(cleanup_table_io_return)
+       clc     4(4,%r12),BASED(cleanup_table_sysc_restore)
        bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_io_return+4)
-       bl      BASED(cleanup_io_return)
+       clc     4(4,%r12),BASED(cleanup_table_sysc_restore+4)
+       bl      BASED(cleanup_sysc_restore)
 0:
-       clc     4(4,%r12),BASED(cleanup_table_io_leave)
+       clc     4(4,%r12),BASED(cleanup_table_io_tif)
        bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_io_leave+4)
-       bl      BASED(cleanup_io_leave)
+       clc     4(4,%r12),BASED(cleanup_table_io_tif+4)
+       bl      BASED(cleanup_io_tif)
 0:
-       clc     4(4,%r12),BASED(cleanup_table_io_work_loop)
+       clc     4(4,%r12),BASED(cleanup_table_io_restore)
        bl      BASED(0f)
-       clc     4(4,%r12),BASED(cleanup_table_io_work_loop+4)
-       bl      BASED(cleanup_io_work_loop)
+       clc     4(4,%r12),BASED(cleanup_table_io_restore+4)
+       bl      BASED(cleanup_io_restore)
 0:
        br      %r14
 
 cleanup_system_call:
        mvc     __LC_RETURN_PSW(8),0(%r12)
-       c       %r12,BASED(.Lmck_old_psw)
-       be      BASED(0f)
-       la      %r12,__LC_SAVE_AREA+16
-       b       BASED(1f)
-0:     la      %r12,__LC_SAVE_AREA+32
-1:
        clc     __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+4)
        bh      BASED(0f)
+       mvc     __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
+       c       %r12,BASED(.Lmck_old_psw)
+       be      BASED(0f)
        mvc     __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
+0:     c       %r12,BASED(.Lmck_old_psw)
+       la      %r12,__LC_SAVE_AREA+32
+       be      BASED(0f)
+       la      %r12,__LC_SAVE_AREA+16
 0:     clc     __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+8)
        bhe     BASED(cleanup_vtime)
        clc     __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn)
@@ -1011,61 +974,54 @@ cleanup_system_call_insn:
        .long   sysc_stime + 0x80000000
        .long   sysc_update + 0x80000000
 
-cleanup_sysc_return:
+cleanup_sysc_tif:
        mvc     __LC_RETURN_PSW(4),0(%r12)
-       mvc     __LC_RETURN_PSW+4(4),BASED(cleanup_table_sysc_return)
+       mvc     __LC_RETURN_PSW+4(4),BASED(cleanup_table_sysc_tif)
        la      %r12,__LC_RETURN_PSW
        br      %r14
 
-cleanup_sysc_leave:
-       clc     4(4,%r12),BASED(cleanup_sysc_leave_insn)
+cleanup_sysc_restore:
+       clc     4(4,%r12),BASED(cleanup_sysc_restore_insn)
        be      BASED(2f)
+       mvc     __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
+       c       %r12,BASED(.Lmck_old_psw)
+       be      BASED(0f)
        mvc     __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
-       clc     4(4,%r12),BASED(cleanup_sysc_leave_insn+4)
+0:     clc     4(4,%r12),BASED(cleanup_sysc_restore_insn+4)
        be      BASED(2f)
        mvc     __LC_RETURN_PSW(8),SP_PSW(%r15)
        c       %r12,BASED(.Lmck_old_psw)
-       bne     BASED(0f)
-       mvc     __LC_SAVE_AREA+32(16),SP_R12(%r15)
-       b       BASED(1f)
-0:     mvc     __LC_SAVE_AREA+16(16),SP_R12(%r15)
-1:     lm      %r0,%r11,SP_R0(%r15)
+       la      %r12,__LC_SAVE_AREA+32
+       be      BASED(1f)
+       la      %r12,__LC_SAVE_AREA+16
+1:     mvc     0(16,%r12),SP_R12(%r15)
+       lm      %r0,%r11,SP_R0(%r15)
        l       %r15,SP_R15(%r15)
 2:     la      %r12,__LC_RETURN_PSW
        br      %r14
-cleanup_sysc_leave_insn:
+cleanup_sysc_restore_insn:
        .long   sysc_done - 4 + 0x80000000
        .long   sysc_done - 8 + 0x80000000
 
-cleanup_io_return:
+cleanup_io_tif:
        mvc     __LC_RETURN_PSW(4),0(%r12)
-       mvc     __LC_RETURN_PSW+4(4),BASED(cleanup_table_io_return)
+       mvc     __LC_RETURN_PSW+4(4),BASED(cleanup_table_io_tif)
        la      %r12,__LC_RETURN_PSW
        br      %r14
 
-cleanup_io_work_loop:
-       mvc     __LC_RETURN_PSW(4),0(%r12)
-       mvc     __LC_RETURN_PSW+4(4),BASED(cleanup_table_io_work_loop)
-       la      %r12,__LC_RETURN_PSW
-       br      %r14
-
-cleanup_io_leave:
-       clc     4(4,%r12),BASED(cleanup_io_leave_insn)
-       be      BASED(2f)
-       mvc     __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
-       clc     4(4,%r12),BASED(cleanup_io_leave_insn+4)
-       be      BASED(2f)
+cleanup_io_restore:
+       clc     4(4,%r12),BASED(cleanup_io_restore_insn)
+       be      BASED(1f)
+       mvc     __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
+       clc     4(4,%r12),BASED(cleanup_io_restore_insn+4)
+       be      BASED(1f)
        mvc     __LC_RETURN_PSW(8),SP_PSW(%r15)
-       c       %r12,BASED(.Lmck_old_psw)
-       bne     BASED(0f)
        mvc     __LC_SAVE_AREA+32(16),SP_R12(%r15)
-       b       BASED(1f)
-0:     mvc     __LC_SAVE_AREA+16(16),SP_R12(%r15)
-1:     lm      %r0,%r11,SP_R0(%r15)
+       lm      %r0,%r11,SP_R0(%r15)
        l       %r15,SP_R15(%r15)
-2:     la      %r12,__LC_RETURN_PSW
+1:     la      %r12,__LC_RETURN_PSW
        br      %r14
-cleanup_io_leave_insn:
+cleanup_io_restore_insn:
        .long   io_done - 4 + 0x80000000
        .long   io_done - 8 + 0x80000000
 
index 52106d5..178d925 100644 (file)
@@ -2,7 +2,7 @@
  *  arch/s390/kernel/entry64.S
  *    S390 low-level entry points.
  *
- *    Copyright (C) IBM Corp. 1999,2006
+ *    Copyright (C) IBM Corp. 1999,2010
  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
  *              Hartmut Penner (hp@de.ibm.com),
  *              Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
@@ -59,30 +59,45 @@ _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
 
 #define BASED(name) name-system_call(%r13)
 
+       .macro  HANDLE_SIE_INTERCEPT
+#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
+       lg      %r3,__LC_SIE_HOOK
+       ltgr    %r3,%r3
+       jz      0f
+       basr    %r14,%r3
+       0:
+#endif
+       .endm
+
 #ifdef CONFIG_TRACE_IRQFLAGS
        .macro  TRACE_IRQS_ON
-        basr   %r2,%r0
-        brasl  %r14,trace_hardirqs_on_caller
+       basr    %r2,%r0
+       brasl   %r14,trace_hardirqs_on_caller
        .endm
 
        .macro  TRACE_IRQS_OFF
-        basr   %r2,%r0
-        brasl  %r14,trace_hardirqs_off_caller
+       basr    %r2,%r0
+       brasl   %r14,trace_hardirqs_off_caller
        .endm
 
-       .macro TRACE_IRQS_CHECK
-       basr    %r2,%r0
+       .macro TRACE_IRQS_CHECK_ON
        tm      SP_PSW(%r15),0x03       # irqs enabled?
        jz      0f
-       brasl   %r14,trace_hardirqs_on_caller
-       j       1f
-0:     brasl   %r14,trace_hardirqs_off_caller
-1:
+       TRACE_IRQS_ON
+0:
+       .endm
+
+       .macro TRACE_IRQS_CHECK_OFF
+       tm      SP_PSW(%r15),0x03       # irqs enabled?
+       jz      0f
+       TRACE_IRQS_OFF
+0:
        .endm
 #else
 #define TRACE_IRQS_ON
 #define TRACE_IRQS_OFF
-#define TRACE_IRQS_CHECK
+#define TRACE_IRQS_CHECK_ON
+#define TRACE_IRQS_CHECK_OFF
 #endif
 
 #ifdef CONFIG_LOCKDEP
@@ -111,31 +126,35 @@ _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
  *    R15 - kernel stack pointer
  */
 
-       .macro  SAVE_ALL_BASE savearea
-       stmg    %r12,%r15,\savearea
-       larl    %r13,system_call
-       .endm
-
        .macro  SAVE_ALL_SVC psworg,savearea
-       la      %r12,\psworg
+       stmg    %r11,%r15,\savearea
        lg      %r15,__LC_KERNEL_STACK  # problem state -> load ksp
+       aghi    %r15,-SP_SIZE           # make room for registers & psw
+       lg      %r11,__LC_LAST_BREAK
        .endm
 
-       .macro  SAVE_ALL_SYNC psworg,savearea
-       la      %r12,\psworg
+       .macro  SAVE_ALL_PGM psworg,savearea
+       stmg    %r11,%r15,\savearea
        tm      \psworg+1,0x01          # test problem state bit
-       jz      2f                      # skip stack setup save
-       lg      %r15,__LC_KERNEL_STACK  # problem state -> load ksp
 #ifdef CONFIG_CHECK_STACK
-       j       3f
-2:     tml     %r15,STACK_SIZE - CONFIG_STACK_GUARD
-       jz      stack_overflow
-3:
+       jnz     1f
+       tml     %r15,STACK_SIZE - CONFIG_STACK_GUARD
+       jnz     2f
+       la      %r12,\psworg
+       j       stack_overflow
+#else
+       jz      2f
 #endif
-2:
+1:     lg      %r15,__LC_KERNEL_STACK  # problem state -> load ksp
+2:     aghi    %r15,-SP_SIZE           # make room for registers & psw
+       larl    %r13,system_call
+       lg      %r11,__LC_LAST_BREAK
        .endm
 
        .macro  SAVE_ALL_ASYNC psworg,savearea
+       stmg    %r11,%r15,\savearea
+       larl    %r13,system_call
+       lg      %r11,__LC_LAST_BREAK
        la      %r12,\psworg
        tm      \psworg+1,0x01          # test problem state bit
        jnz     1f                      # from user -> load kernel stack
@@ -149,27 +168,23 @@ _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
 0:     lg      %r14,__LC_ASYNC_STACK   # are we already on the async. stack ?
        slgr    %r14,%r15
        srag    %r14,%r14,STACK_SHIFT
-       jz      2f
-1:     lg      %r15,__LC_ASYNC_STACK   # load async stack
 #ifdef CONFIG_CHECK_STACK
-       j       3f
-2:     tml     %r15,STACK_SIZE - CONFIG_STACK_GUARD
-       jz      stack_overflow
-3:
+       jnz     1f
+       tml     %r15,STACK_SIZE - CONFIG_STACK_GUARD
+       jnz     2f
+       j       stack_overflow
+#else
+       jz      2f
 #endif
-2:
+1:     lg      %r15,__LC_ASYNC_STACK   # load async stack
+2:     aghi    %r15,-SP_SIZE           # make room for registers & psw
        .endm
 
-       .macro  CREATE_STACK_FRAME psworg,savearea
-       aghi    %r15,-SP_SIZE           # make room for registers & psw
-       mvc     SP_PSW(16,%r15),0(%r12) # move user PSW to stack
+       .macro  CREATE_STACK_FRAME savearea
+       xc      __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
        stg     %r2,SP_ORIG_R2(%r15)    # store original content of gpr 2
-       icm     %r12,3,__LC_SVC_ILC
-       stmg    %r0,%r11,SP_R0(%r15)    # store gprs %r0-%r11 to kernel stack
-       st      %r12,SP_SVCNR(%r15)
-       mvc     SP_R12(32,%r15),\savearea # move %r12-%r15 to stack
-       la      %r12,0
-       stg     %r12,__SF_BACKCHAIN(%r15)
+       mvc     SP_R11(40,%r15),\savearea # move %r11-%r15 to stack
+       stmg    %r0,%r10,SP_R0(%r15)    # store gprs %r0-%r10 to kernel stack
        .endm
 
        .macro  RESTORE_ALL psworg,sync
@@ -185,6 +200,13 @@ _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
        lpswe   \psworg                 # back to caller
        .endm
 
+       .macro  LAST_BREAK
+       srag    %r10,%r11,23
+       jz      0f
+       stg     %r11,__TI_last_break(%r12)
+0:
+       .endm
+
 /*
  * Scheduler resume function, called by switch_to
  *  gpr2 = (task_struct *) prev
@@ -230,143 +252,129 @@ __critical_start:
 system_call:
        stpt    __LC_SYNC_ENTER_TIMER
 sysc_saveall:
-       SAVE_ALL_BASE __LC_SAVE_AREA
        SAVE_ALL_SVC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
-       CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
-       llgh    %r7,__LC_SVC_INT_CODE   # get svc number from lowcore
+       CREATE_STACK_FRAME __LC_SAVE_AREA
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
+       stg     %r7,SP_ARGS(%r15)
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
 sysc_vtime:
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
 sysc_stime:
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
 sysc_update:
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
+       LAST_BREAK
 sysc_do_svc:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       ltgr    %r7,%r7         # test for svc 0
+       llgh    %r7,SP_SVCNR(%r15)
+       slag    %r7,%r7,2       # shift and test for svc 0
        jnz     sysc_nr_ok
        # svc 0: system call number in %r1
-       cl      %r1,BASED(.Lnr_syscalls)
+       llgfr   %r1,%r1         # clear high word in r1
+       cghi    %r1,NR_syscalls
        jnl     sysc_nr_ok
-       lgfr    %r7,%r1         # clear high word in r1
+       sth     %r1,SP_SVCNR(%r15)
+       slag    %r7,%r1,2       # shift and test for svc 0
 sysc_nr_ok:
-       mvc     SP_ARGS(8,%r15),SP_R7(%r15)
-sysc_do_restart:
-       sth     %r7,SP_SVCNR(%r15)
-       sllg    %r7,%r7,2       # svc number * 4
        larl    %r10,sys_call_table
 #ifdef CONFIG_COMPAT
-       tm      __TI_flags+5(%r9),(_TIF_31BIT>>16)  # running in 31 bit mode ?
+       tm      __TI_flags+5(%r12),(_TIF_31BIT>>16)  # running in 31 bit mode ?
        jno     sysc_noemu
        larl    %r10,sys_call_table_emu  # use 31 bit emulation system calls
 sysc_noemu:
 #endif
-       tm      __TI_flags+6(%r9),_TIF_SYSCALL
+       tm      __TI_flags+6(%r12),_TIF_SYSCALL
        lgf     %r8,0(%r7,%r10) # load address of system call routine
        jnz     sysc_tracesys
        basr    %r14,%r8        # call sys_xxxx
        stg     %r2,SP_R2(%r15) # store return value (change R2 on stack)
 
 sysc_return:
-       tm      __TI_flags+7(%r9),_TIF_WORK_SVC
+       LOCKDEP_SYS_EXIT
+sysc_tif:
+       tm      __TI_flags+7(%r12),_TIF_WORK_SVC
        jnz     sysc_work       # there is work to do (signals etc.)
 sysc_restore:
-#ifdef CONFIG_TRACE_IRQFLAGS
-       larl    %r1,sysc_restore_trace_psw
-       lpswe   0(%r1)
-sysc_restore_trace:
-       TRACE_IRQS_CHECK
-       LOCKDEP_SYS_EXIT
-#endif
-sysc_leave:
        RESTORE_ALL __LC_RETURN_PSW,1
 sysc_done:
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-       .section .data,"aw",@progbits
-       .align  8
-       .globl sysc_restore_trace_psw
-sysc_restore_trace_psw:
-       .quad   0, sysc_restore_trace
-       .previous
-#endif
-
-#
-# recheck if there is more work to do
 #
-sysc_work_loop:
-       tm      __TI_flags+7(%r9),_TIF_WORK_SVC
-       jz      sysc_restore      # there is no work to do
-#
-# One of the work bits is on. Find out which one.
+# There is work to do, but first we need to check if we return to userspace.
 #
 sysc_work:
        tm      SP_PSW+1(%r15),0x01     # returning to user ?
        jno     sysc_restore
-       tm      __TI_flags+7(%r9),_TIF_MCCK_PENDING
+
+#
+# One of the work bits is on. Find out which one.
+#
+sysc_work_tif:
+       tm      __TI_flags+7(%r12),_TIF_MCCK_PENDING
        jo      sysc_mcck_pending
-       tm      __TI_flags+7(%r9),_TIF_NEED_RESCHED
+       tm      __TI_flags+7(%r12),_TIF_NEED_RESCHED
        jo      sysc_reschedule
-       tm      __TI_flags+7(%r9),_TIF_SIGPENDING
-       jnz     sysc_sigpending
-       tm      __TI_flags+7(%r9),_TIF_NOTIFY_RESUME
-       jnz     sysc_notify_resume
-       tm      __TI_flags+7(%r9),_TIF_RESTART_SVC
+       tm      __TI_flags+7(%r12),_TIF_SIGPENDING
+       j     sysc_sigpending
+       tm      __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
+       j     sysc_notify_resume
+       tm      __TI_flags+7(%r12),_TIF_RESTART_SVC
        jo      sysc_restart
-       tm      __TI_flags+7(%r9),_TIF_SINGLE_STEP
+       tm      __TI_flags+7(%r12),_TIF_SINGLE_STEP
        jo      sysc_singlestep
-       j       sysc_restore
-sysc_work_done:
+       j       sysc_return             # beware of critical section cleanup
 
 #
 # _TIF_NEED_RESCHED is set, call schedule
 #
 sysc_reschedule:
-       larl    %r14,sysc_work_loop
-       jg      schedule        # return point is sysc_return
+       larl    %r14,sysc_return
+       jg      schedule                # return point is sysc_return
 
 #
 # _TIF_MCCK_PENDING is set, call handler
 #
 sysc_mcck_pending:
-       larl    %r14,sysc_work_loop
+       larl    %r14,sysc_return
        jg      s390_handle_mcck        # TIF bit will be cleared by handler
 
 #
 # _TIF_SIGPENDING is set, call do_signal
 #
 sysc_sigpending:
-       ni      __TI_flags+7(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
+       ni      __TI_flags+7(%r12),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        brasl   %r14,do_signal          # call do_signal
-       tm      __TI_flags+7(%r9),_TIF_RESTART_SVC
+       tm      __TI_flags+7(%r12),_TIF_RESTART_SVC
        jo      sysc_restart
-       tm      __TI_flags+7(%r9),_TIF_SINGLE_STEP
+       tm      __TI_flags+7(%r12),_TIF_SINGLE_STEP
        jo      sysc_singlestep
-       j       sysc_work_loop
+       j       sysc_return
 
 #
 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
 #
 sysc_notify_resume:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
-       larl    %r14,sysc_work_loop
+       larl    %r14,sysc_return
        jg      do_notify_resume        # call do_notify_resume
 
 #
 # _TIF_RESTART_SVC is set, set up registers and restart svc
 #
 sysc_restart:
-       ni      __TI_flags+7(%r9),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
+       ni      __TI_flags+7(%r12),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
        lg      %r7,SP_R2(%r15)         # load new svc number
        mvc     SP_R2(8,%r15),SP_ORIG_R2(%r15) # restore first argument
        lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
-       j       sysc_do_restart         # restart svc
+       sth     %r7,SP_SVCNR(%r15)
+       slag    %r7,%r7,2
+       j       sysc_nr_ok              # restart svc
 
 #
 # _TIF_SINGLE_STEP is set, call do_single_step
 #
 sysc_singlestep:
-       ni      __TI_flags+7(%r9),255-_TIF_SINGLE_STEP  # clear TIF_SINGLE_STEP
+       ni      __TI_flags+7(%r12),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
        xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15)         # clear svc number
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        larl    %r14,sysc_return        # load adr. of system return
@@ -379,8 +387,8 @@ sysc_singlestep:
 sysc_tracesys:
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        la      %r3,0
-       srl     %r7,2
-       stg     %r7,SP_R2(%r15)
+       llgh    %r0,SP_SVCNR(%r15)
+       stg     %r0,SP_R2(%r15)
        brasl   %r14,do_syscall_trace_enter
        lghi    %r0,NR_syscalls
        clgr    %r0,%r2
@@ -393,7 +401,7 @@ sysc_tracego:
        basr    %r14,%r8                # call sys_xxx
        stg     %r2,SP_R2(%r15)         # store return value
 sysc_tracenogo:
-       tm      __TI_flags+6(%r9),_TIF_SYSCALL
+       tm      __TI_flags+6(%r12),_TIF_SYSCALL
        jz      sysc_return
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        larl    %r14,sysc_return        # return point is sysc_return
@@ -405,7 +413,7 @@ sysc_tracenogo:
        .globl  ret_from_fork
 ret_from_fork:
        lg      %r13,__LC_SVC_NEW_PSW+8
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # forking a kernel thread ?
        jo      0f
        stg     %r15,SP_R15(%r15)       # store stack pointer for new kthread
@@ -435,12 +443,14 @@ kernel_execve:
        br      %r14
        # execve succeeded.
 0:     stnsm   __SF_EMPTY(%r15),0xfc   # disable interrupts
+#      TRACE_IRQS_OFF
        lg      %r15,__LC_KERNEL_STACK  # load ksp
        aghi    %r15,-SP_SIZE           # make room for registers & psw
        lg      %r13,__LC_SVC_NEW_PSW+8
-       lg      %r9,__LC_THREAD_INFO
        mvc     SP_PTREGS(__PT_SIZE,%r15),0(%r12)       # copy pt_regs
+       lg      %r12,__LC_THREAD_INFO
        xc      __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
+#      TRACE_IRQS_ON
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        brasl   %r14,execve_tail
        j       sysc_return
@@ -465,20 +475,23 @@ pgm_check_handler:
  * for LPSW?).
  */
        stpt    __LC_SYNC_ENTER_TIMER
-       SAVE_ALL_BASE __LC_SAVE_AREA
        tm      __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
        jnz     pgm_per                  # got per exception -> special case
-       SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
-       CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
+       SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
+       CREATE_STACK_FRAME __LC_SAVE_AREA
+       xc      SP_ILC(4,%r15),SP_ILC(%r15)
+       mvc     SP_PSW(16,%r15),__LC_PGM_OLD_PSW
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        jz      pgm_no_vtime
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
+       LAST_BREAK
 pgm_no_vtime:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       mvc     SP_ARGS(8,%r15),__LC_LAST_BREAK
-       TRACE_IRQS_OFF
+       HANDLE_SIE_INTERCEPT
+       TRACE_IRQS_CHECK_OFF
+       stg     %r11,SP_ARGS(%r15)
        lgf     %r3,__LC_PGM_ILC        # load program interruption code
        lghi    %r8,0x7f
        ngr     %r8,%r3
@@ -487,8 +500,10 @@ pgm_do_call:
        larl    %r1,pgm_check_table
        lg      %r1,0(%r8,%r1)          # load address of handler routine
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
-       larl    %r14,sysc_return
-       br      %r1                     # branch to interrupt-handler
+       basr    %r14,%r1                # branch to interrupt-handler
+pgm_exit:
+       TRACE_IRQS_CHECK_ON
+       j       sysc_return
 
 #
 # handle per exception
@@ -500,55 +515,60 @@ pgm_per:
        clc     __LC_PGM_OLD_PSW(16),__LC_SVC_NEW_PSW
        je      pgm_svcper
 # no interesting special case, ignore PER event
-       lmg     %r12,%r15,__LC_SAVE_AREA
        lpswe   __LC_PGM_OLD_PSW
 
 #
 # Normal per exception
 #
 pgm_per_std:
-       SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
-       CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
+       SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
+       CREATE_STACK_FRAME __LC_SAVE_AREA
+       mvc     SP_PSW(16,%r15),__LC_PGM_OLD_PSW
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        jz      pgm_no_vtime2
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
+       LAST_BREAK
 pgm_no_vtime2:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       TRACE_IRQS_OFF
-       lg      %r1,__TI_task(%r9)
+       HANDLE_SIE_INTERCEPT
+       TRACE_IRQS_CHECK_OFF
+       lg      %r1,__TI_task(%r12)
        tm      SP_PSW+1(%r15),0x01     # kernel per event ?
        jz      kernel_per
        mvc     __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
        mvc     __THREAD_per+__PER_address(8,%r1),__LC_PER_ADDRESS
        mvc     __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
-       oi      __TI_flags+7(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
+       oi      __TI_flags+7(%r12),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
        lgf     %r3,__LC_PGM_ILC        # load program interruption code
        lghi    %r8,0x7f
        ngr     %r8,%r3                 # clear per-event-bit and ilc
-       je      sysc_return
+       je      pgm_exit
        j       pgm_do_call
 
 #
 # it was a single stepped SVC that is causing all the trouble
 #
 pgm_svcper:
-       SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
-       CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
+       SAVE_ALL_PGM __LC_SVC_OLD_PSW,__LC_SAVE_AREA
+       CREATE_STACK_FRAME __LC_SAVE_AREA
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
-       llgh    %r7,__LC_SVC_INT_CODE   # get svc number from lowcore
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
-       lg      %r8,__TI_task(%r9)
+       LAST_BREAK
+       TRACE_IRQS_OFF
+       lg      %r8,__TI_task(%r12)
        mvc     __THREAD_per+__PER_atmid(2,%r8),__LC_PER_ATMID
        mvc     __THREAD_per+__PER_address(8,%r8),__LC_PER_ADDRESS
        mvc     __THREAD_per+__PER_access_id(1,%r8),__LC_PER_ACCESS_ID
-       oi      __TI_flags+7(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
+       oi      __TI_flags+7(%r12),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
        TRACE_IRQS_ON
-       lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
+       lmg     %r2,%r6,SP_R2(%r15)     # load svc arguments
        j       sysc_do_svc
 
 #
@@ -557,8 +577,8 @@ pgm_svcper:
 kernel_per:
        xc      SP_SVCNR(2,%r15),SP_SVCNR(%r15) # clear svc number
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
-       larl    %r14,sysc_restore       # load adr. of system ret, no work
-       jg      do_single_step          # branch to do_single_step
+       brasl   %r14,do_single_step
+       j       pgm_exit
 
 /*
  * IO interrupt handler routine
@@ -567,162 +587,133 @@ kernel_per:
 io_int_handler:
        stck    __LC_INT_CLOCK
        stpt    __LC_ASYNC_ENTER_TIMER
-       SAVE_ALL_BASE __LC_SAVE_AREA+32
-       SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+32
-       CREATE_STACK_FRAME __LC_IO_OLD_PSW,__LC_SAVE_AREA+32
+       SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+40
+       CREATE_STACK_FRAME __LC_SAVE_AREA+40
+       mvc     SP_PSW(16,%r15),0(%r12) # move user PSW to stack
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        jz      io_no_vtime
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
+       LAST_BREAK
 io_no_vtime:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
+       HANDLE_SIE_INTERCEPT
        TRACE_IRQS_OFF
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        brasl   %r14,do_IRQ             # call standard irq handler
 io_return:
-       tm      __TI_flags+7(%r9),_TIF_WORK_INT
+       LOCKDEP_SYS_EXIT
+       TRACE_IRQS_ON
+io_tif:
+       tm      __TI_flags+7(%r12),_TIF_WORK_INT
        jnz     io_work                 # there is work to do (signals etc.)
 io_restore:
-#ifdef CONFIG_TRACE_IRQFLAGS
-       larl    %r1,io_restore_trace_psw
-       lpswe   0(%r1)
-io_restore_trace:
-       TRACE_IRQS_CHECK
-       LOCKDEP_SYS_EXIT
-#endif
-io_leave:
        RESTORE_ALL __LC_RETURN_PSW,0
 io_done:
 
-#ifdef CONFIG_TRACE_IRQFLAGS
-       .section .data,"aw",@progbits
-       .align  8
-       .globl io_restore_trace_psw
-io_restore_trace_psw:
-       .quad   0, io_restore_trace
-       .previous
-#endif
-
 #
-# There is work todo, we need to check if we return to userspace, then
-# check, if we are in SIE, if yes leave it
+# There is work todo, find out in which context we have been interrupted:
+# 1) if we return to user space we can do all _TIF_WORK_INT work
+# 2) if we return to kernel code and kvm is enabled check if we need to
+#    modify the psw to leave SIE
+# 3) if we return to kernel code and preemptive scheduling is enabled check
+#    the preemption counter and if it is zero call preempt_schedule_irq
+# Before any work can be done, a switch to the kernel stack is required.
 #
 io_work:
        tm      SP_PSW+1(%r15),0x01     # returning to user ?
-#ifndef CONFIG_PREEMPT
-#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
-       jnz     io_work_user            # yes -> no need to check for SIE
-       la      %r1, BASED(sie_opcode)  # we return to kernel here
-       lg      %r2, SP_PSW+8(%r15)
-       clc     0(2,%r1), 0(%r2)        # is current instruction = SIE?
-       jne     io_restore              # no-> return to kernel
-       lg      %r1, SP_PSW+8(%r15)     # yes-> add 4 bytes to leave SIE
-       aghi    %r1, 4
-       stg     %r1, SP_PSW+8(%r15)
-       j       io_restore              # return to kernel
-#else
-       jno     io_restore              # no-> skip resched & signal
-#endif
-#else
-       jnz     io_work_user            # yes -> do resched & signal
-#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
-       la      %r1, BASED(sie_opcode)
-       lg      %r2, SP_PSW+8(%r15)
-       clc     0(2,%r1), 0(%r2)        # is current instruction = SIE?
-       jne     0f                      # no -> leave PSW alone
-       lg      %r1, SP_PSW+8(%r15)     # yes-> add 4 bytes to leave SIE
-       aghi    %r1, 4
-       stg     %r1, SP_PSW+8(%r15)
-0:
-#endif
+       jo      io_work_user            # yes -> do resched & signal
+#ifdef CONFIG_PREEMPT
        # check for preemptive scheduling
-       icm     %r0,15,__TI_precount(%r9)
+       icm     %r0,15,__TI_precount(%r12)
        jnz     io_restore              # preemption is disabled
+       tm      __TI_flags+7(%r12),_TIF_NEED_RESCHED
+       jno     io_restore
        # switch to kernel stack
        lg      %r1,SP_R15(%r15)
        aghi    %r1,-SP_SIZE
        mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
        xc      __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
        lgr     %r15,%r1
-io_resume_loop:
-       tm      __TI_flags+7(%r9),_TIF_NEED_RESCHED
-       jno     io_restore
-       larl    %r14,io_resume_loop
-       jg      preempt_schedule_irq
+       # TRACE_IRQS_ON already done at io_return, call
+       # TRACE_IRQS_OFF to keep things symmetrical
+       TRACE_IRQS_OFF
+       brasl   %r14,preempt_schedule_irq
+       j       io_return
+#else
+       j       io_restore
 #endif
 
+#
+# Need to do work before returning to userspace, switch to kernel stack
+#
 io_work_user:
        lg      %r1,__LC_KERNEL_STACK
        aghi    %r1,-SP_SIZE
        mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
        xc      __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
        lgr     %r15,%r1
+
 #
 # One of the work bits is on. Find out which one.
-# Checked are: _TIF_SIGPENDING, _TIF_RESTORE_SIGPENDING, _TIF_NEED_RESCHED
+# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
 #             and _TIF_MCCK_PENDING
 #
-io_work_loop:
-       tm      __TI_flags+7(%r9),_TIF_MCCK_PENDING
+io_work_tif:
+       tm      __TI_flags+7(%r12),_TIF_MCCK_PENDING
        jo      io_mcck_pending
-       tm      __TI_flags+7(%r9),_TIF_NEED_RESCHED
+       tm      __TI_flags+7(%r12),_TIF_NEED_RESCHED
        jo      io_reschedule
-       tm      __TI_flags+7(%r9),_TIF_SIGPENDING
-       jnz     io_sigpending
-       tm      __TI_flags+7(%r9),_TIF_NOTIFY_RESUME
-       jnz     io_notify_resume
-       j       io_restore
-io_work_done:
-
-#if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
-sie_opcode:
-       .long 0xb2140000
-#endif
+       tm      __TI_flags+7(%r12),_TIF_SIGPENDING
+       jo      io_sigpending
+       tm      __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
+       jo      io_notify_resume
+       j       io_return               # beware of critical section cleanup
 
 #
 # _TIF_MCCK_PENDING is set, call handler
 #
 io_mcck_pending:
+       # TRACE_IRQS_ON already done at io_return
        brasl   %r14,s390_handle_mcck   # TIF bit will be cleared by handler
-       j       io_work_loop
+       TRACE_IRQS_OFF
+       j       io_return
 
 #
 # _TIF_NEED_RESCHED is set, call schedule
 #
 io_reschedule:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        brasl   %r14,schedule           # call scheduler
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       tm      __TI_flags+7(%r9),_TIF_WORK_INT
-       jz      io_restore              # there is no work to do
-       j       io_work_loop
+       j       io_return
 
 #
 # _TIF_SIGPENDING or is set, call do_signal
 #
 io_sigpending:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        brasl   %r14,do_signal          # call do_signal
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       j       io_work_loop
+       j       io_return
 
 #
 # _TIF_NOTIFY_RESUME or is set, call do_notify_resume
 #
 io_notify_resume:
-       TRACE_IRQS_ON
+       # TRACE_IRQS_ON already done at io_return
        stosm   __SF_EMPTY(%r15),0x03   # reenable interrupts
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        brasl   %r14,do_notify_resume   # call do_notify_resume
        stnsm   __SF_EMPTY(%r15),0xfc   # disable I/O and ext. interrupts
        TRACE_IRQS_OFF
-       j       io_work_loop
+       j       io_return
 
 /*
  * External interrupt handler routine
@@ -731,16 +722,18 @@ io_notify_resume:
 ext_int_handler:
        stck    __LC_INT_CLOCK
        stpt    __LC_ASYNC_ENTER_TIMER
-       SAVE_ALL_BASE __LC_SAVE_AREA+32
-       SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+32
-       CREATE_STACK_FRAME __LC_EXT_OLD_PSW,__LC_SAVE_AREA+32
+       SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+40
+       CREATE_STACK_FRAME __LC_SAVE_AREA+40
+       mvc     SP_PSW(16,%r15),0(%r12) # move user PSW to stack
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        jz      ext_no_vtime
        UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
+       LAST_BREAK
 ext_no_vtime:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
+       HANDLE_SIE_INTERCEPT
        TRACE_IRQS_OFF
        la      %r2,SP_PTREGS(%r15)     # address of register-save area
        llgh    %r3,__LC_EXT_INT_CODE   # get interruption code
@@ -754,17 +747,18 @@ __critical_end:
  */
        .globl mcck_int_handler
 mcck_int_handler:
-       stck    __LC_INT_CLOCK
+       stck    __LC_MCCK_CLOCK
        la      %r1,4095                # revalidate r1
        spt     __LC_CPU_TIMER_SAVE_AREA-4095(%r1)      # revalidate cpu timer
        lmg     %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
-       SAVE_ALL_BASE __LC_SAVE_AREA+64
+       stmg    %r11,%r15,__LC_SAVE_AREA+80
+       larl    %r13,system_call
+       lg      %r11,__LC_LAST_BREAK
        la      %r12,__LC_MCK_OLD_PSW
        tm      __LC_MCCK_CODE,0x80     # system damage?
        jo      mcck_int_main           # yes -> rest of mcck code invalid
        la      %r14,4095
-       mvc     __LC_SAVE_AREA+104(8),__LC_ASYNC_ENTER_TIMER
-       mvc     __LC_ASYNC_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA-4095(%r14)
+       mvc     __LC_MCCK_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA-4095(%r14)
        tm      __LC_MCCK_CODE+5,0x02   # stored cpu timer value valid?
        jo      1f
        la      %r14,__LC_SYNC_ENTER_TIMER
@@ -778,7 +772,7 @@ mcck_int_handler:
        jl      0f
        la      %r14,__LC_LAST_UPDATE_TIMER
 0:     spt     0(%r14)
-       mvc     __LC_ASYNC_ENTER_TIMER(8),0(%r14)
+       mvc     __LC_MCCK_ENTER_TIMER(8),0(%r14)
 1:     tm      __LC_MCCK_CODE+2,0x09   # mwp + ia of old psw valid?
        jno     mcck_int_main           # no -> skip cleanup critical
        tm      __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
@@ -794,16 +788,19 @@ mcck_int_main:
        srag    %r14,%r14,PAGE_SHIFT
        jz      0f
        lg      %r15,__LC_PANIC_STACK   # load panic stack
-0:     CREATE_STACK_FRAME __LC_MCK_OLD_PSW,__LC_SAVE_AREA+64
+0:     aghi    %r15,-SP_SIZE           # make room for registers & psw
+       CREATE_STACK_FRAME __LC_SAVE_AREA+80
+       mvc     SP_PSW(16,%r15),0(%r12)
+       lg      %r12,__LC_THREAD_INFO   # load pointer to thread_info struct
        tm      __LC_MCCK_CODE+2,0x08   # mwp of old psw valid?
        jno     mcck_no_vtime           # no -> no timer update
        tm      SP_PSW+1(%r15),0x01     # interrupting from user ?
        jz      mcck_no_vtime
-       UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
+       UPDATE_VTIME __LC_EXIT_TIMER,__LC_MCCK_ENTER_TIMER,__LC_USER_TIMER
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
-       mvc     __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
+       mvc     __LC_LAST_UPDATE_TIMER(8),__LC_MCCK_ENTER_TIMER
+       LAST_BREAK
 mcck_no_vtime:
-       lg      %r9,__LC_THREAD_INFO    # load pointer to thread_info struct
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
        brasl   %r14,s390_do_machine_check
        tm      SP_PSW+1(%r15),0x01     # returning to user ?
@@ -814,8 +811,9 @@ mcck_no_vtime:
        xc      __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
        lgr     %r15,%r1
        stosm   __SF_EMPTY(%r15),0x04   # turn dat on
-       tm      __TI_flags+7(%r9),_TIF_MCCK_PENDING
+       tm      __TI_flags+7(%r12),_TIF_MCCK_PENDING
        jno     mcck_return
+       HANDLE_SIE_INTERCEPT
        TRACE_IRQS_OFF
        brasl   %r14,s390_handle_mcck
        TRACE_IRQS_ON
@@ -823,11 +821,11 @@ mcck_return:
        mvc     __LC_RETURN_MCCK_PSW(16),SP_PSW(%r15) # move return PSW
        ni      __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
        lmg     %r0,%r15,SP_R0(%r15)    # load gprs 0-15
-       mvc     __LC_ASYNC_ENTER_TIMER(8),__LC_SAVE_AREA+104
        tm      __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
        jno     0f
        stpt    __LC_EXIT_TIMER
 0:     lpswe   __LC_RETURN_MCCK_PSW    # back to caller
+mcck_done:
 
 /*
  * Restart interruption handler, kick starter for additional CPUs
@@ -883,14 +881,14 @@ stack_overflow:
        lg      %r15,__LC_PANIC_STACK   # change to panic stack
        aghi    %r15,-SP_SIZE
        mvc     SP_PSW(16,%r15),0(%r12) # move user PSW to stack
-       stmg    %r0,%r11,SP_R0(%r15)    # store gprs %r0-%r11 to kernel stack
+       stmg    %r0,%r10,SP_R0(%r15)    # store gprs %r0-%r10 to kernel stack
        la      %r1,__LC_SAVE_AREA
        chi     %r12,__LC_SVC_OLD_PSW
        je      0f
        chi     %r12,__LC_PGM_OLD_PSW
        je      0f
-       la      %r1,__LC_SAVE_AREA+32
-0:     mvc     SP_R12(32,%r15),0(%r1)  # move %r12-%r15 to stack
+       la      %r1,__LC_SAVE_AREA+40
+0:     mvc     SP_R11(40,%r15),0(%r1)  # move %r11-%r15 to stack
        mvc     SP_ARGS(8,%r15),__LC_LAST_BREAK
        xc      __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # clear back chain
        la      %r2,SP_PTREGS(%r15)     # load pt_regs
@@ -899,18 +897,14 @@ stack_overflow:
 
 cleanup_table_system_call:
        .quad   system_call, sysc_do_svc
-cleanup_table_sysc_return:
-       .quad   sysc_return, sysc_leave
-cleanup_table_sysc_leave:
-       .quad   sysc_leave, sysc_done
-cleanup_table_sysc_work_loop:
-       .quad   sysc_work_loop, sysc_work_done
-cleanup_table_io_return:
-       .quad   io_return, io_leave
-cleanup_table_io_leave:
-       .quad   io_leave, io_done
-cleanup_table_io_work_loop:
-       .quad   io_work_loop, io_work_done
+cleanup_table_sysc_tif:
+       .quad   sysc_tif, sysc_restore
+cleanup_table_sysc_restore:
+       .quad   sysc_restore, sysc_done
+cleanup_table_io_tif:
+       .quad   io_tif, io_restore
+cleanup_table_io_restore:
+       .quad   io_restore, io_done
 
 cleanup_critical:
        clc     8(8,%r12),BASED(cleanup_table_system_call)
@@ -918,61 +912,54 @@ cleanup_critical:
        clc     8(8,%r12),BASED(cleanup_table_system_call+8)
        jl      cleanup_system_call
 0:
-       clc     8(8,%r12),BASED(cleanup_table_sysc_return)
-       jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_sysc_return+8)
-       jl      cleanup_sysc_return
-0:
-       clc     8(8,%r12),BASED(cleanup_table_sysc_leave)
+       clc     8(8,%r12),BASED(cleanup_table_sysc_tif)
        jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_sysc_leave+8)
-       jl      cleanup_sysc_leave
+       clc     8(8,%r12),BASED(cleanup_table_sysc_tif+8)
+       jl      cleanup_sysc_tif
 0:
-       clc     8(8,%r12),BASED(cleanup_table_sysc_work_loop)
+       clc     8(8,%r12),BASED(cleanup_table_sysc_restore)
        jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_sysc_work_loop+8)
-       jl      cleanup_sysc_return
+       clc     8(8,%r12),BASED(cleanup_table_sysc_restore+8)
+       jl      cleanup_sysc_restore
 0:
-       clc     8(8,%r12),BASED(cleanup_table_io_return)
+       clc     8(8,%r12),BASED(cleanup_table_io_tif)
        jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_io_return+8)
-       jl      cleanup_io_return
+       clc     8(8,%r12),BASED(cleanup_table_io_tif+8)
+       jl      cleanup_io_tif
 0:
-       clc     8(8,%r12),BASED(cleanup_table_io_leave)
+       clc     8(8,%r12),BASED(cleanup_table_io_restore)
        jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_io_leave+8)
-       jl      cleanup_io_leave
-0:
-       clc     8(8,%r12),BASED(cleanup_table_io_work_loop)
-       jl      0f
-       clc     8(8,%r12),BASED(cleanup_table_io_work_loop+8)
-       jl      cleanup_io_work_loop
+       clc     8(8,%r12),BASED(cleanup_table_io_restore+8)
+       jl      cleanup_io_restore
 0:
        br      %r14
 
 cleanup_system_call:
        mvc     __LC_RETURN_PSW(16),0(%r12)
-       cghi    %r12,__LC_MCK_OLD_PSW
-       je      0f
-       la      %r12,__LC_SAVE_AREA+32
-       j       1f
-0:     la      %r12,__LC_SAVE_AREA+64
-1:
        clc     __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+8)
        jh      0f
+       mvc     __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
+       cghi    %r12,__LC_MCK_OLD_PSW
+       je      0f
        mvc     __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
+0:     cghi    %r12,__LC_MCK_OLD_PSW
+       la      %r12,__LC_SAVE_AREA+80
+       je      0f
+       la      %r12,__LC_SAVE_AREA+40
 0:     clc     __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+16)
        jhe     cleanup_vtime
        clc     __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn)
        jh      0f
-       mvc     __LC_SAVE_AREA(32),0(%r12)
-0:     stg     %r13,8(%r12)
-       stg     %r12,__LC_SAVE_AREA+96  # argh
-       SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
-       CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
-       lg      %r12,__LC_SAVE_AREA+96  # argh
-       stg     %r15,24(%r12)
-       llgh    %r7,__LC_SVC_INT_CODE
+       mvc     __LC_SAVE_AREA(40),0(%r12)
+0:     lg      %r15,__LC_KERNEL_STACK  # problem state -> load ksp
+       aghi    %r15,-SP_SIZE           # make room for registers & psw
+       stg     %r15,32(%r12)
+       stg     %r11,0(%r12)
+       CREATE_STACK_FRAME __LC_SAVE_AREA
+       mvc     SP_PSW(16,%r15),__LC_SVC_OLD_PSW
+       mvc     SP_ILC(4,%r15),__LC_SVC_ILC
+       stg     %r7,SP_ARGS(%r15)
+       mvc     8(8,%r12),__LC_THREAD_INFO
 cleanup_vtime:
        clc     __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+24)
        jhe     cleanup_stime
@@ -983,7 +970,11 @@ cleanup_stime:
        UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
 cleanup_update:
        mvc     __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
-       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_system_call+8)
+       srag    %r12,%r11,23
+       lg      %r12,__LC_THREAD_INFO
+       jz      0f
+       stg     %r11,__TI_last_break(%r12)
+0:     mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_system_call+8)
        la      %r12,__LC_RETURN_PSW
        br      %r14
 cleanup_system_call_insn:
@@ -993,61 +984,54 @@ cleanup_system_call_insn:
        .quad   sysc_stime
        .quad   sysc_update
 
-cleanup_sysc_return:
+cleanup_sysc_tif:
        mvc     __LC_RETURN_PSW(8),0(%r12)
-       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_sysc_return)
+       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_sysc_tif)
        la      %r12,__LC_RETURN_PSW
        br      %r14
 
-cleanup_sysc_leave:
-       clc     8(8,%r12),BASED(cleanup_sysc_leave_insn)
-       je      3f
-       clc     8(8,%r12),BASED(cleanup_sysc_leave_insn+8)
+cleanup_sysc_restore:
+       clc     8(8,%r12),BASED(cleanup_sysc_restore_insn)
+       je      2f
+       clc     8(8,%r12),BASED(cleanup_sysc_restore_insn+8)
        jhe     0f
+       mvc     __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
+       cghi    %r12,__LC_MCK_OLD_PSW
+       je      0f
        mvc     __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
 0:     mvc     __LC_RETURN_PSW(16),SP_PSW(%r15)
        cghi    %r12,__LC_MCK_OLD_PSW
-       jne     1f
-       mvc     __LC_SAVE_AREA+64(32),SP_R12(%r15)
-       j       2f
-1:     mvc     __LC_SAVE_AREA+32(32),SP_R12(%r15)
-2:     lmg     %r0,%r11,SP_R0(%r15)
+       la      %r12,__LC_SAVE_AREA+80
+       je      1f
+       la      %r12,__LC_SAVE_AREA+40
+1:     mvc     0(40,%r12),SP_R11(%r15)
+       lmg     %r0,%r10,SP_R0(%r15)
        lg      %r15,SP_R15(%r15)
-3:     la      %r12,__LC_RETURN_PSW
+2:     la      %r12,__LC_RETURN_PSW
        br      %r14
-cleanup_sysc_leave_insn:
+cleanup_sysc_restore_insn:
        .quad   sysc_done - 4
        .quad   sysc_done - 16
 
-cleanup_io_return:
-       mvc     __LC_RETURN_PSW(8),0(%r12)
-       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_return)
-       la      %r12,__LC_RETURN_PSW
-       br      %r14
-
-cleanup_io_work_loop:
+cleanup_io_tif:
        mvc     __LC_RETURN_PSW(8),0(%r12)
-       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_work_loop)
+       mvc     __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_tif)
        la      %r12,__LC_RETURN_PSW
        br      %r14
 
-cleanup_io_leave:
-       clc     8(8,%r12),BASED(cleanup_io_leave_insn)
-       je      3f
-       clc     8(8,%r12),BASED(cleanup_io_leave_insn+8)
+cleanup_io_restore:
+       clc     8(8,%r12),BASED(cleanup_io_restore_insn)
+       je      1f
+       clc     8(8,%r12),BASED(cleanup_io_restore_insn+8)
        jhe     0f
-       mvc     __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
+       mvc     __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
 0:     mvc     __LC_RETURN_PSW(16),SP_PSW(%r15)
-       cghi    %r12,__LC_MCK_OLD_PSW
-       jne     1f
-       mvc     __LC_SAVE_AREA+64(32),SP_R12(%r15)
-       j       2f
-1:     mvc     __LC_SAVE_AREA+32(32),SP_R12(%r15)
-2:     lmg     %r0,%r11,SP_R0(%r15)
+       mvc     __LC_SAVE_AREA+80(40),SP_R11(%r15)
+       lmg     %r0,%r10,SP_R0(%r15)
        lg      %r15,SP_R15(%r15)
-3:     la      %r12,__LC_RETURN_PSW
+1:     la      %r12,__LC_RETURN_PSW
        br      %r14
-cleanup_io_leave_insn:
+cleanup_io_restore_insn:
        .quad   io_done - 4
        .quad   io_done - 16
 
@@ -1055,13 +1039,6 @@ cleanup_io_leave_insn:
  * Integer constants
  */
                .align  4
-.Lconst:
-.Lnr_syscalls: .long   NR_syscalls
-.L0x0130:      .short  0x130
-.L0x0140:      .short  0x140
-.L0x0150:      .short  0x150
-.L0x0160:      .short  0x160
-.L0x0170:      .short  0x170
 .Lcritical_start:
                .quad   __critical_start
 .Lcritical_end:
index 9d1f767..51838ad 100644 (file)
@@ -328,8 +328,8 @@ iplstart:
 #
 # reset files in VM reader
 #
-       stidp   __LC_CPUID              # store cpuid
-       tm      __LC_CPUID,0xff         # running VM ?
+       stidp   __LC_SAVE_AREA          # store cpuid
+       tm      __LC_SAVE_AREA,0xff     # running VM ?
        bno     .Lnoreset
        la      %r2,.Lreset
        lhi     %r3,26
index 015e27d..ac15139 100644 (file)
@@ -255,7 +255,8 @@ void notrace s390_do_machine_check(struct pt_regs *regs)
        int umode;
 
        nmi_enter();
-       s390_idle_check();
+       s390_idle_check(regs, S390_lowcore.mcck_clock,
+                       S390_lowcore.mcck_enter_timer);
 
        mci = (struct mci *) &S390_lowcore.mcck_interruption_code;
        mcck = &__get_cpu_var(cpu_mcck);
index 0729f36..ecb2d02 100644 (file)
 #include <asm/lowcore.h>
 #include <asm/param.h>
 
+static DEFINE_PER_CPU(struct cpuid, cpu_id);
+
+/*
+ * cpu_init - initializes state that is per-CPU.
+ */
+void __cpuinit cpu_init(void)
+{
+       struct cpuid *id = &per_cpu(cpu_id, smp_processor_id());
+
+       get_cpu_id(id);
+       atomic_inc(&init_mm.mm_count);
+       current->active_mm = &init_mm;
+       BUG_ON(current->mm);
+       enter_lazy_tlb(&init_mm, current);
+}
+
+/*
+ * print_cpu_info - print basic information about a cpu
+ */
 void __cpuinit print_cpu_info(void)
 {
+       struct cpuid *id = &per_cpu(cpu_id, smp_processor_id());
+
        pr_info("Processor %d started, address %d, identification %06X\n",
-               S390_lowcore.cpu_nr, S390_lowcore.cpu_addr,
-               S390_lowcore.cpu_id.ident);
+               S390_lowcore.cpu_nr, S390_lowcore.cpu_addr, id->ident);
 }
 
 /*
  * show_cpuinfo - Get information on one CPU for use by procfs.
  */
-
 static int show_cpuinfo(struct seq_file *m, void *v)
 {
        static const char *hwcap_str[10] = {
                "esan3", "zarch", "stfle", "msa", "ldisp", "eimm", "dfp",
                "edat", "etf3eh", "highgprs"
        };
-       struct _lowcore *lc;
        unsigned long n = (unsigned long) v - 1;
        int i;
 
@@ -55,19 +73,12 @@ static int show_cpuinfo(struct seq_file *m, void *v)
        }
 
        if (cpu_online(n)) {
-#ifdef CONFIG_SMP
-               lc = (smp_processor_id() == n) ?
-                       &S390_lowcore : lowcore_ptr[n];
-#else
-               lc = &S390_lowcore;
-#endif
+               struct cpuid *id = &per_cpu(cpu_id, n);
                seq_printf(m, "processor %li: "
                           "version = %02X,  "
                           "identification = %06X,  "
                           "machine = %04X\n",
-                          n, lc->cpu_id.version,
-                          lc->cpu_id.ident,
-                          lc->cpu_id.machine);
+                          n, id->version, id->ident, id->machine);
        }
        preempt_enable();
        return 0;
index 9f654da..83339d3 100644 (file)
@@ -57,6 +57,7 @@
 enum s390_regset {
        REGSET_GENERAL,
        REGSET_FP,
+       REGSET_LAST_BREAK,
        REGSET_GENERAL_EXTENDED,
 };
 
@@ -381,6 +382,10 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                        copied += sizeof(unsigned long);
                }
                return 0;
+       case PTRACE_GET_LAST_BREAK:
+               put_user(task_thread_info(child)->last_break,
+                        (unsigned long __user *) data);
+               return 0;
        default:
                /* Removing high order bit from addr (only for 31 bit). */
                addr &= PSW_ADDR_INSN;
@@ -633,6 +638,10 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
                        copied += sizeof(unsigned int);
                }
                return 0;
+       case PTRACE_GET_LAST_BREAK:
+               put_user(task_thread_info(child)->last_break,
+                        (unsigned int __user *) data);
+               return 0;
        }
        return compat_ptrace_request(child, request, addr, data);
 }
@@ -797,6 +806,28 @@ static int s390_fpregs_set(struct task_struct *target,
        return rc;
 }
 
+#ifdef CONFIG_64BIT
+
+static int s390_last_break_get(struct task_struct *target,
+                              const struct user_regset *regset,
+                              unsigned int pos, unsigned int count,
+                              void *kbuf, void __user *ubuf)
+{
+       if (count > 0) {
+               if (kbuf) {
+                       unsigned long *k = kbuf;
+                       *k = task_thread_info(target)->last_break;
+               } else {
+                       unsigned long  __user *u = ubuf;
+                       if (__put_user(task_thread_info(target)->last_break, u))
+                               return -EFAULT;
+               }
+       }
+       return 0;
+}
+
+#endif
+
 static const struct user_regset s390_regsets[] = {
        [REGSET_GENERAL] = {
                .core_note_type = NT_PRSTATUS,
@@ -814,6 +845,15 @@ static const struct user_regset s390_regsets[] = {
                .get = s390_fpregs_get,
                .set = s390_fpregs_set,
        },
+#ifdef CONFIG_64BIT
+       [REGSET_LAST_BREAK] = {
+               .core_note_type = NT_S390_LAST_BREAK,
+               .n = 1,
+               .size = sizeof(long),
+               .align = sizeof(long),
+               .get = s390_last_break_get,
+       },
+#endif
 };
 
 static const struct user_regset_view user_s390_view = {
@@ -948,6 +988,27 @@ static int s390_compat_regs_high_set(struct task_struct *target,
        return rc;
 }
 
+static int s390_compat_last_break_get(struct task_struct *target,
+                                     const struct user_regset *regset,
+                                     unsigned int pos, unsigned int count,
+                                     void *kbuf, void __user *ubuf)
+{
+       compat_ulong_t last_break;
+
+       if (count > 0) {
+               last_break = task_thread_info(target)->last_break;
+               if (kbuf) {
+                       unsigned long *k = kbuf;
+                       *k = last_break;
+               } else {
+                       unsigned long  __user *u = ubuf;
+                       if (__put_user(last_break, u))
+                               return -EFAULT;
+               }
+       }
+       return 0;
+}
+
 static const struct user_regset s390_compat_regsets[] = {
        [REGSET_GENERAL] = {
                .core_note_type = NT_PRSTATUS,
@@ -965,6 +1026,13 @@ static const struct user_regset s390_compat_regsets[] = {
                .get = s390_fpregs_get,
                .set = s390_fpregs_set,
        },
+       [REGSET_LAST_BREAK] = {
+               .core_note_type = NT_S390_LAST_BREAK,
+               .n = 1,
+               .size = sizeof(long),
+               .align = sizeof(long),
+               .get = s390_compat_last_break_get,
+       },
        [REGSET_GENERAL_EXTENDED] = {
                .core_note_type = NT_S390_HIGH_GPRS,
                .n = sizeof(s390_compat_regs_high) / sizeof(compat_long_t),
index 59618bc..9ce641b 100644 (file)
@@ -120,7 +120,8 @@ void __irq_entry do_extint(struct pt_regs *regs, unsigned short code)
        struct pt_regs *old_regs;
 
        old_regs = set_irq_regs(regs);
-       s390_idle_check();
+       s390_idle_check(regs, S390_lowcore.int_clock,
+                       S390_lowcore.async_enter_timer);
        irq_enter();
        if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
                /* Serve timer interrupts first. */
index 91625f7..7d89324 100644 (file)
@@ -2,7 +2,7 @@
  *  arch/s390/kernel/setup.c
  *
  *  S390 version
- *    Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
+ *    Copyright (C) IBM Corp. 1999,2010
  *    Author(s): Hartmut Penner (hp@de.ibm.com),
  *               Martin Schwidefsky (schwidefsky@de.ibm.com)
  *
@@ -112,22 +112,6 @@ static struct resource data_resource = {
        .flags = IORESOURCE_BUSY | IORESOURCE_MEM,
 };
 
-/*
- * cpu_init() initializes state that is per-CPU.
- */
-void __cpuinit cpu_init(void)
-{
-        /*
-         * Store processor id in lowcore (used e.g. in timer_interrupt)
-         */
-       get_cpu_id(&S390_lowcore.cpu_id);
-
-       atomic_inc(&init_mm.mm_count);
-       current->active_mm = &init_mm;
-       BUG_ON(current->mm);
-        enter_lazy_tlb(&init_mm, current);
-}
-
 /*
  * condev= and conmode= setup parameter.
  */
@@ -385,10 +369,6 @@ static void setup_addressing_mode(void)
                        pr_info("Address spaces switched, "
                                "mvcos not available\n");
        }
-#ifdef CONFIG_TRACE_IRQFLAGS
-       sysc_restore_trace_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
-       io_restore_trace_psw.mask = psw_kernel_bits & ~PSW_MASK_MCHECK;
-#endif
 }
 
 static void __init
@@ -421,6 +401,7 @@ setup_lowcore(void)
        lc->io_new_psw.mask = psw_kernel_bits;
        lc->io_new_psw.addr = PSW_ADDR_AMODE | (unsigned long) io_int_handler;
        lc->clock_comparator = -1ULL;
+       lc->cmf_hpp = -1ULL;
        lc->kernel_stack = ((unsigned long) &init_thread_union) + THREAD_SIZE;
        lc->async_stack = (unsigned long)
                __alloc_bootmem(ASYNC_SIZE, ASYNC_SIZE, 0) + ASYNC_SIZE;
@@ -695,6 +676,7 @@ static void __init setup_hwcaps(void)
        static const int stfl_bits[6] = { 0, 2, 7, 17, 19, 21 };
        unsigned long long facility_list_extended;
        unsigned int facility_list;
+       struct cpuid cpu_id;
        int i;
 
        facility_list = stfl();
@@ -756,7 +738,8 @@ static void __init setup_hwcaps(void)
         */
        elf_hwcap |= HWCAP_S390_HIGH_GPRS;
 
-       switch (S390_lowcore.cpu_id.machine) {
+       get_cpu_id(&cpu_id);
+       switch (cpu_id.machine) {
        case 0x9672:
 #if !defined(CONFIG_64BIT)
        default:        /* Use "g5" as default for 31 bit kernels. */
index 6289945..ee7ac8b 100644 (file)
@@ -313,6 +313,7 @@ static int setup_frame(int sig, struct k_sigaction *ka,
           To avoid breaking binary compatibility, they are passed as args. */
        regs->gprs[4] = current->thread.trap_no;
        regs->gprs[5] = current->thread.prot_addr;
+       regs->gprs[6] = task_thread_info(current)->last_break;
 
        /* Place signal number on stack to allow backtrace from handler.  */
        if (__put_user(regs->gprs[2], (int __user *) &frame->signo))
@@ -376,6 +377,7 @@ static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
        regs->gprs[2] = map_signal(sig);
        regs->gprs[3] = (unsigned long) &frame->info;
        regs->gprs[4] = (unsigned long) &frame->uc;
+       regs->gprs[5] = task_thread_info(current)->last_break;
        return 0;
 
 give_sigsegv:
index d906bf1..a2163c9 100644 (file)
@@ -391,7 +391,6 @@ static void __init time_init_wq(void)
        if (time_sync_wq)
                return;
        time_sync_wq = create_singlethread_workqueue("timesync");
-       stop_machine_create();
 }
 
 /*
index 247b4c2..bcef007 100644 (file)
@@ -37,7 +37,8 @@ struct tl_cpu {
 };
 
 struct tl_container {
-       unsigned char reserved[8];
+       unsigned char reserved[7];
+       unsigned char id;
 };
 
 union tl_entry {
@@ -58,6 +59,7 @@ struct tl_info {
 
 struct core_info {
        struct core_info *next;
+       unsigned char id;
        cpumask_t mask;
 };
 
@@ -73,6 +75,7 @@ static DECLARE_WORK(topology_work, topology_work_fn);
 static DEFINE_SPINLOCK(topology_lock);
 
 cpumask_t cpu_core_map[NR_CPUS];
+unsigned char cpu_core_id[NR_CPUS];
 
 static cpumask_t cpu_coregroup_map(unsigned int cpu)
 {
@@ -116,6 +119,7 @@ static void add_cpus_to_core(struct tl_cpu *tl_cpu, struct core_info *core)
                for_each_present_cpu(lcpu) {
                        if (cpu_logical_map(lcpu) == rcpu) {
                                cpu_set(lcpu, core->mask);
+                               cpu_core_id[lcpu] = core->id;
                                smp_cpu_polarization[lcpu] = tl_cpu->pp;
                        }
                }
@@ -158,6 +162,7 @@ static void tl_to_cores(struct tl_info *info)
                        break;
                case 1:
                        core = core->next;
+                       core->id = tle->container.id;
                        break;
                case 0:
                        add_cpus_to_core(&tle->cpu, core);
index 6e7ad63..5d8f0f3 100644 (file)
 
 pgm_check_handler_t *pgm_check_table[128];
 
-#ifdef CONFIG_SYSCTL
-#ifdef CONFIG_PROCESS_DEBUG
-int sysctl_userprocess_debug = 1;
-#else
-int sysctl_userprocess_debug = 0;
-#endif
-#endif
+int show_unhandled_signals;
 
 extern pgm_check_handler_t do_protection_exception;
 extern pgm_check_handler_t do_dat_exception;
@@ -315,18 +309,19 @@ void die(const char * str, struct pt_regs * regs, long err)
        do_exit(SIGSEGV);
 }
 
-static void inline
-report_user_fault(long interruption_code, struct pt_regs *regs)
+static void inline report_user_fault(struct pt_regs *regs, long int_code,
+                                    int signr)
 {
-#if defined(CONFIG_SYSCTL)
-       if (!sysctl_userprocess_debug)
+       if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
                return;
-#endif
-#if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG)
-       printk("User process fault: interruption code 0x%lX\n",
-              interruption_code);
+       if (!unhandled_signal(current, signr))
+               return;
+       if (!printk_ratelimit())
+               return;
+       printk("User process fault: interruption code 0x%lX ", int_code);
+       print_vma_addr("in ", regs->psw.addr & PSW_ADDR_INSN);
+       printk("\n");
        show_regs(regs);
-#endif
 }
 
 int is_valid_bugaddr(unsigned long addr)
@@ -354,7 +349,7 @@ static void __kprobes inline do_trap(long interruption_code, int signr,
 
                 tsk->thread.trap_no = interruption_code & 0xffff;
                force_sig_info(signr, info, tsk);
-               report_user_fault(interruption_code, regs);
+               report_user_fault(regs, interruption_code, signr);
         } else {
                 const struct exception_table_entry *fixup;
                 fixup = search_exception_tables(regs->psw.addr & PSW_ADDR_INSN);
@@ -390,8 +385,8 @@ static void default_trap_handler(struct pt_regs * regs, long interruption_code)
 {
         if (regs->psw.mask & PSW_MASK_PSTATE) {
                local_irq_enable();
+               report_user_fault(regs, interruption_code, SIGSEGV);
                do_exit(SIGSEGV);
-               report_user_fault(interruption_code, regs);
        } else
                die("Unknown program exception", regs, interruption_code);
 }
index 6bc9c19..6b83870 100644 (file)
@@ -102,11 +102,7 @@ static void vdso_init_per_cpu_data(int cpu, struct vdso_per_cpu_data *vpcd)
 /*
  * Allocate/free per cpu vdso data.
  */
-#ifdef CONFIG_64BIT
 #define SEGMENT_ORDER  2
-#else
-#define SEGMENT_ORDER  1
-#endif
 
 int vdso_alloc_per_cpu(int cpu, struct _lowcore *lowcore)
 {
index b59a812..3479f1b 100644 (file)
@@ -121,32 +121,35 @@ void account_system_vtime(struct task_struct *tsk)
 }
 EXPORT_SYMBOL_GPL(account_system_vtime);
 
-void vtime_start_cpu(void)
+void vtime_start_cpu(__u64 int_clock, __u64 enter_timer)
 {
        struct s390_idle_data *idle = &__get_cpu_var(s390_idle);
        struct vtimer_queue *vq = &__get_cpu_var(virt_cpu_timer);
        __u64 idle_time, expires;
 
+       if (idle->idle_enter == 0ULL)
+               return;
+
        /* Account time spent with enabled wait psw loaded as idle time. */
-       idle_time = S390_lowcore.int_clock - idle->idle_enter;
+       idle_time = int_clock - idle->idle_enter;
        account_idle_time(idle_time);
        S390_lowcore.steal_timer +=
                idle->idle_enter - S390_lowcore.last_update_clock;
-       S390_lowcore.last_update_clock = S390_lowcore.int_clock;
+       S390_lowcore.last_update_clock = int_clock;
 
        /* Account system time spent going idle. */
        S390_lowcore.system_timer += S390_lowcore.last_update_timer - vq->idle;
-       S390_lowcore.last_update_timer = S390_lowcore.async_enter_timer;
+       S390_lowcore.last_update_timer = enter_timer;
 
        /* Restart vtime CPU timer */
        if (vq->do_spt) {
                /* Program old expire value but first save progress. */
-               expires = vq->idle - S390_lowcore.async_enter_timer;
+               expires = vq->idle - enter_timer;
                expires += get_vtimer();
                set_vtimer(expires);
        } else {
                /* Don't account the CPU timer delta while the cpu was idle. */
-               vq->elapsed -= vq->idle - S390_lowcore.async_enter_timer;
+               vq->elapsed -= vq->idle - enter_timer;
        }
 
        idle->sequence++;
index a725158..2f4b687 100644 (file)
@@ -33,6 +33,17 @@ config KVM
 
          If unsure, say N.
 
+config KVM_AWARE_CMF
+       depends on KVM
+       bool "KVM aware sampling"
+       ---help---
+         This option enhances the sampling data from the CPU Measurement
+         Facility with additional information, that allows to distinguish
+         guest(s) and host when using the kernel based virtual machine
+         functionality.
+
+         If unsure, say N.
+
 # OK, it's a little counter-intuitive to do this, but it puts it neatly under
 # the virtualization menu.
 source drivers/vhost/Kconfig
index 934fd6a..31646bd 100644 (file)
@@ -1,20 +1,60 @@
 /*
  * sie64a.S - low level sie call
  *
- * Copyright IBM Corp. 2008
+ * Copyright IBM Corp. 2008,2010
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License (version 2 only)
  * as published by the Free Software Foundation.
  *
  *    Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
+ *              Christian Ehrhardt <ehrhardt@linux.vnet.ibm.com>
  */
 
 #include <linux/errno.h>
 #include <asm/asm-offsets.h>
+#include <asm/setup.h>
+#include <asm/asm-offsets.h>
+#include <asm/ptrace.h>
+#include <asm/thread_info.h>
+
+_TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
+
+/*
+ * offsets into stackframe
+ * SP_ = offsets into stack sie64 is called with
+ * SPI_ = offsets into irq stack
+ */
+SP_GREGS = __SF_EMPTY
+SP_HOOK  = __SF_EMPTY+8
+SP_GPP  = __SF_EMPTY+16
+SPI_PSW  = STACK_FRAME_OVERHEAD + __PT_PSW
+
 
-SP_R5 =        5 * 8   # offset into stackframe
-SP_R6 =        6 * 8
+       .macro SPP newpp
+#ifdef CONFIG_KVM_AWARE_CMF
+       tm      __LC_MACHINE_FLAGS+6,0x20       # MACHINE_FLAG_SPP
+       jz      0f
+       .insn   s,0xb2800000,\newpp
+       0:
+#endif
+       .endm
+
+sie_irq_handler:
+       SPP     __LC_CMF_HPP                    # set host id
+       larl    %r2,sie_inst
+       clg     %r2,SPI_PSW+8(0,%r15)           # intercepted sie
+       jne     1f
+       xc      __LC_SIE_HOOK(8),__LC_SIE_HOOK
+       lg      %r2,__LC_THREAD_INFO            # pointer thread_info struct
+       tm      __TI_flags+7(%r2),_TIF_EXIT_SIE
+       jz      0f
+       larl    %r2,sie_exit                    # work pending, leave sie
+       stg     %r2,__LC_RETURN_PSW+8
+       br      %r14
+0:     larl    %r2,sie_reenter                 # re-enter with guest id
+       stg     %r2,__LC_RETURN_PSW+8
+1:     br      %r14
 
 /*
  * sie64a calling convention:
@@ -23,23 +63,34 @@ SP_R6 =     6 * 8
  */
        .globl  sie64a
 sie64a:
-       lgr     %r5,%r3
-       stmg    %r5,%r14,SP_R5(%r15)    # save register on entry
-       lgr     %r14,%r2                # pointer to sie control block
-       lmg     %r0,%r13,0(%r3)         # load guest gprs 0-13
+       stg     %r3,SP_GREGS(%r15)              # save guest register save area
+       stmg    %r6,%r14,__SF_GPRS(%r15)        # save registers on entry
+       lgr     %r14,%r2                        # pointer to sie control block
+       larl    %r5,sie_irq_handler
+       stg     %r2,SP_GPP(%r15)
+       stg     %r5,SP_HOOK(%r15)               # save hook target
+       lmg     %r0,%r13,0(%r3)                 # load guest gprs 0-13
+sie_reenter:
+       mvc     __LC_SIE_HOOK(8),SP_HOOK(%r15)
+       SPP     SP_GPP(%r15)                    # set guest id
 sie_inst:
        sie     0(%r14)
-       lg      %r14,SP_R5(%r15)
-       stmg    %r0,%r13,0(%r14)        # save guest gprs 0-13
+       xc      __LC_SIE_HOOK(8),__LC_SIE_HOOK
+       SPP     __LC_CMF_HPP                    # set host id
+sie_exit:
+       lg      %r14,SP_GREGS(%r15)
+       stmg    %r0,%r13,0(%r14)                # save guest gprs 0-13
        lghi    %r2,0
-       lmg     %r6,%r14,SP_R6(%r15)
+       lmg     %r6,%r14,__SF_GPRS(%r15)
        br      %r14
 
 sie_err:
-       lg      %r14,SP_R5(%r15)
-       stmg    %r0,%r13,0(%r14)        # save guest gprs 0-13
+       xc      __LC_SIE_HOOK(8),__LC_SIE_HOOK
+       SPP     __LC_CMF_HPP                    # set host id
+       lg      %r14,SP_GREGS(%r15)
+       stmg    %r0,%r13,0(%r14)                # save guest gprs 0-13
        lghi    %r2,-EFAULT
-       lmg     %r6,%r14,SP_R6(%r15)
+       lmg     %r6,%r14,__SF_GPRS(%r15)
        br      %r14
 
        .section __ex_table,"a"
index 3040d7c..2505b2e 100644 (file)
 #define __PF_RES_FIELD 0x8000000000000000ULL
 #endif /* CONFIG_64BIT */
 
-#ifdef CONFIG_SYSCTL
-extern int sysctl_userprocess_debug;
-#endif
-
 #define VM_FAULT_BADCONTEXT    0x010000
 #define VM_FAULT_BADMAP                0x020000
 #define VM_FAULT_BADACCESS     0x040000
@@ -120,6 +116,22 @@ static inline int user_space_fault(unsigned long trans_exc_code)
        return trans_exc_code != 3;
 }
 
+static inline void report_user_fault(struct pt_regs *regs, long int_code,
+                                    int signr, unsigned long address)
+{
+       if ((task_pid_nr(current) > 1) && !show_unhandled_signals)
+               return;
+       if (!unhandled_signal(current, signr))
+               return;
+       if (!printk_ratelimit())
+               return;
+       printk("User process fault: interruption code 0x%lX ", int_code);
+       print_vma_addr(KERN_CONT "in ", regs->psw.addr & PSW_ADDR_INSN);
+       printk("\n");
+       printk("failing address: %lX\n", address);
+       show_regs(regs);
+}
+
 /*
  * Send SIGSEGV to task.  This is an external routine
  * to keep the stack usage of do_page_fault small.
@@ -133,17 +145,7 @@ static noinline void do_sigsegv(struct pt_regs *regs, long int_code,
        address = trans_exc_code & __FAIL_ADDR_MASK;
        current->thread.prot_addr = address;
        current->thread.trap_no = int_code;
-#if defined(CONFIG_SYSCTL) || defined(CONFIG_PROCESS_DEBUG)
-#if defined(CONFIG_SYSCTL)
-       if (sysctl_userprocess_debug)
-#endif
-       {
-               printk("User process fault: interruption code 0x%lX\n",
-                      int_code);
-               printk("failing address: %lX\n", address);
-               show_regs(regs);
-       }
-#endif
+       report_user_fault(regs, int_code, SIGSEGV, address);
        si.si_signo = SIGSEGV;
        si.si_code = si_code;
        si.si_addr = (void __user *) address;
index 5593999..8570d08 100644 (file)
@@ -92,7 +92,7 @@ register struct thread_info *__current_thread_info __asm__("r28");
 #define TIF_RESTORE_SIGMASK    9       /* restore signal mask in do_signal() */
 #define TIF_POLLING_NRFLAG     17      /* true if poll_idle() is polling
                                                 TIF_NEED_RESCHED */
-#define TIF_MEMDIE             18
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 
 #define _TIF_SYSCALL_TRACE     (1<<TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1<<TIF_SIGPENDING)
index 8d90564..0e318c9 100644 (file)
@@ -44,6 +44,7 @@ config SUPERH32
        select HAVE_FUNCTION_GRAPH_TRACER
        select HAVE_ARCH_KGDB
        select HAVE_HW_BREAKPOINT
+       select HAVE_MIXED_BREAKPOINTS_REGS
        select PERF_EVENTS if HAVE_HW_BREAKPOINT
        select ARCH_HIBERNATION_POSSIBLE if MMU
 
@@ -157,7 +158,6 @@ config LOCKDEP_SUPPORT
 
 config HAVE_LATENCYTOP_SUPPORT
        def_bool y
-       depends on !SMP
 
 config ARCH_HAS_ILOG2_U32
        def_bool n
@@ -237,6 +237,8 @@ config CPU_SHX2
 config CPU_SHX3
        bool
        select DMA_COHERENT
+       select SYS_SUPPORTS_SMP
+       select SYS_SUPPORTS_NUMA
 
 config ARCH_SHMOBILE
        bool
@@ -453,18 +455,12 @@ config CPU_SUBTYPE_SH7786
        select CPU_SH4A
        select CPU_SHX3
        select CPU_HAS_PTEAEX
-       select ARCH_SPARSEMEM_ENABLE
-       select SYS_SUPPORTS_NUMA
-       select SYS_SUPPORTS_SMP
        select GENERIC_CLOCKEVENTS_BROADCAST if SMP
 
 config CPU_SUBTYPE_SHX3
        bool "Support SH-X3 processor"
        select CPU_SH4A
        select CPU_SHX3
-       select ARCH_SPARSEMEM_ENABLE
-       select SYS_SUPPORTS_NUMA
-       select SYS_SUPPORTS_SMP
        select GENERIC_CLOCKEVENTS_BROADCAST if SMP
 
 # SH4AL-DSP Processor Support
@@ -634,7 +630,7 @@ config KEXEC
 
 config CRASH_DUMP
        bool "kernel crash dumps (EXPERIMENTAL)"
-       depends on SUPERH32 && EXPERIMENTAL
+       depends on SUPERH32 && EXPERIMENTAL && BROKEN_ON_SMP
        help
          Generate crash dump after being started by kexec.
          This should be normally only set in special crash dump kernels
@@ -706,6 +702,13 @@ config NR_CPUS
          This is purely to save memory - each supported CPU adds
          approximately eight kilobytes to the kernel image.
 
+config HOTPLUG_CPU
+       bool "Support for hot-pluggable CPUs (EXPERIMENTAL)"
+       depends on SMP && HOTPLUG && EXPERIMENTAL
+       help
+         Say Y here to experiment with turning CPUs off and on.  CPUs
+         can be controlled through /sys/devices/system/cpu.
+
 source "kernel/Kconfig.preempt"
 
 config GUSA
@@ -732,6 +735,8 @@ config GUSA_RB
          LLSC, this should be more efficient than the other alternative of
          disabling interrupts around the atomic sequence.
 
+source "drivers/sh/Kconfig"
+
 endmenu
 
 menu "Boot options"
@@ -863,4 +868,20 @@ source "security/Kconfig"
 
 source "crypto/Kconfig"
 
+menuconfig VIRTUALIZATION
+       bool "Virtualization"
+       default n
+       ---help---
+         Say Y here to get to see options for using your Linux host to run other
+         operating systems inside virtual machines (guests).
+         This option alone does not add any kernel code.
+
+         If you say N, all options in this submenu will be skipped and disabled.
+
+if VIRTUALIZATION
+
+source drivers/virtio/Kconfig
+
+endif # VIRTUALIZATION
+
 source "lib/Kconfig"
index 588579a..307b3a4 100644 (file)
@@ -83,7 +83,6 @@ defaultimage-$(CONFIG_SH_AP325RXA)            := uImage
 defaultimage-$(CONFIG_SH_7724_SOLUTION_ENGINE) := uImage
 defaultimage-$(CONFIG_SH_7206_SOLUTION_ENGINE) := vmlinux
 defaultimage-$(CONFIG_SH_7619_SOLUTION_ENGINE) := vmlinux
-defaultimage-$(CONFIG_SH_SDK7786)              := vmlinux.bin
 
 # Set some sensible Kbuild defaults
 KBUILD_IMAGE           := $(defaultimage-y)
index a9bd6e3..d81c609 100644 (file)
@@ -24,6 +24,7 @@
 #include <cpu/sh7786.h>
 #include <asm/heartbeat.h>
 #include <asm/sizes.h>
+#include <asm/smp-ops.h>
 
 /*
  * bit  1234 5678
@@ -203,6 +204,8 @@ static void __init urquell_setup(char **cmdline_p)
        printk(KERN_INFO "Renesas Technology Corp. Urquell support.\n");
 
        pm_power_off = urquell_power_off;
+
+       register_smp_ops(&shx3_smp_ops);
 }
 
 /*
index 6c13b92..6212388 100644 (file)
@@ -710,8 +710,6 @@ static struct clk_ops fsimck_clk_ops = {
 };
 
 static struct clk fsimckb_clk = {
-       .name           = "fsimckb_clk",
-       .id             = -1,
        .ops            = &fsimck_clk_ops,
        .enable_reg     = (void __iomem *)FCLKBCR,
        .rate           = 0, /* unknown */
@@ -1138,16 +1136,20 @@ static int __init arch_setup(void)
 
        /* set SPU2 clock to 83.4 MHz */
        clk = clk_get(NULL, "spu_clk");
-       clk_set_rate(clk, clk_round_rate(clk, 83333333));
-       clk_put(clk);
+       if (clk) {
+               clk_set_rate(clk, clk_round_rate(clk, 83333333));
+               clk_put(clk);
+       }
 
        /* change parent of FSI B */
        clk = clk_get(NULL, "fsib_clk");
-       clk_register(&fsimckb_clk);
-       clk_set_parent(clk, &fsimckb_clk);
-       clk_set_rate(clk, 11000);
-       clk_set_rate(&fsimckb_clk, 11000);
-       clk_put(clk);
+       if (clk) {
+               clk_register(&fsimckb_clk);
+               clk_set_parent(clk, &fsimckb_clk);
+               clk_set_rate(clk, 11000);
+               clk_set_rate(&fsimckb_clk, 11000);
+               clk_put(clk);
+       }
 
        gpio_request(GPIO_PTU0, NULL);
        gpio_direction_output(GPIO_PTU0, 0);
@@ -1159,8 +1161,10 @@ static int __init arch_setup(void)
 
        /* set VPU clock to 166 MHz */
        clk = clk_get(NULL, "vpu_clk");
-       clk_set_rate(clk, clk_round_rate(clk, 166000000));
-       clk_put(clk);
+       if (clk) {
+               clk_set_rate(clk, clk_round_rate(clk, 166000000));
+               clk_put(clk);
+       }
 
        /* enable IrDA */
        gpio_request(GPIO_FN_IRDA_OUT, NULL);
index affd667..a5ecfba 100644 (file)
@@ -14,6 +14,7 @@
  * for more details.
  */
 #include <linux/init.h>
+#include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/ata_platform.h>
 #include <linux/types.h>
@@ -26,6 +27,7 @@
 #include <net/ax88796.h>
 #include <asm/machvec.h>
 #include <mach/highlander.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/heartbeat.h>
 #include <asm/io.h>
@@ -326,7 +328,6 @@ static struct clk_ops ivdr_clk_ops = {
 };
 
 static struct clk ivdr_clk = {
-       .name           = "ivdr_clk",
        .ops            = &ivdr_clk_ops,
 };
 
@@ -334,6 +335,13 @@ static struct clk *r7780rp_clocks[] = {
        &ivdr_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("ivdr_clk", &ivdr_clk),
+};
+
 static void r7780rp_power_off(void)
 {
        if (mach_is_r7780mp() || mach_is_r7785rp())
@@ -370,6 +378,8 @@ static void __init highlander_setup(char **cmdline_p)
                clk_enable(clk);
        }
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        __raw_writew(0x0000, PA_OBLED); /* Clear LED. */
 
        if (mach_is_r7780rp())
index f094ea2..2ec1ea5 100644 (file)
@@ -21,6 +21,7 @@
 #include <asm/heartbeat.h>
 #include <asm/sizes.h>
 #include <asm/reboot.h>
+#include <asm/smp-ops.h>
 
 static struct resource heartbeat_resource = {
        .start          = 0x07fff8b0,
@@ -165,6 +166,19 @@ static void sdk7786_restart(char *cmd)
        fpga_write_reg(0xa5a5, SRSTR);
 }
 
+static void sdk7786_power_off(void)
+{
+       fpga_write_reg(fpga_read_reg(PWRCR) | PWRCR_PDWNREQ, PWRCR);
+
+       /*
+        * It can take up to 20us for the R8C to do its job, back off and
+        * wait a bit until we've been shut off. Even though newer FPGA
+        * versions don't set the ACK bit, the latency issue remains.
+        */
+       while ((fpga_read_reg(PWRCR) & PWRCR_PDWNACK) == 0)
+               cpu_sleep();
+}
+
 /* Initialize the board */
 static void __init sdk7786_setup(char **cmdline_p)
 {
@@ -175,6 +189,9 @@ static void __init sdk7786_setup(char **cmdline_p)
        pr_info("\tPCB revision:\t%d\n", fpga_read_reg(PCBRR) & 0xf);
 
        machine_ops.restart = sdk7786_restart;
+       pm_power_off = sdk7786_power_off;
+
+       register_smp_ops(&shx3_smp_ops);
 }
 
 /*
index ccaa290..e74ae7b 100644 (file)
@@ -276,8 +276,6 @@ static struct clk_ops fsimck_clk_ops = {
 };
 
 static struct clk fsimcka_clk = {
-       .name           = "fsimcka_clk",
-       .id             = -1,
        .ops            = &fsimck_clk_ops,
        .enable_reg     = (void __iomem *)FCLKACR,
        .rate           = 0, /* unknown */
@@ -771,16 +769,20 @@ static int __init devices_setup(void)
 
        /* set SPU2 clock to 83.4 MHz */
        clk = clk_get(NULL, "spu_clk");
-       clk_set_rate(clk, clk_round_rate(clk, 83333333));
-       clk_put(clk);
+       if (clk) {
+               clk_set_rate(clk, clk_round_rate(clk, 83333333));
+               clk_put(clk);
+       }
 
        /* change parent of FSI A */
        clk = clk_get(NULL, "fsia_clk");
-       clk_register(&fsimcka_clk);
-       clk_set_parent(clk, &fsimcka_clk);
-       clk_set_rate(clk, 11000);
-       clk_set_rate(&fsimcka_clk, 11000);
-       clk_put(clk);
+       if (clk) {
+               clk_register(&fsimcka_clk);
+               clk_set_parent(clk, &fsimcka_clk);
+               clk_set_rate(clk, 11000);
+               clk_set_rate(&fsimcka_clk, 11000);
+               clk_put(clk);
+       }
 
        /* SDHI0 connected to cn7 */
        gpio_request(GPIO_FN_SDHI0CD, NULL);
index e284592..102bf56 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/usb/r8a66597.h>
 #include <linux/usb/m66592.h>
 #include <asm/ilsel.h>
+#include <asm/smp-ops.h>
 
 static struct resource heartbeat_resources[] = {
        [0] = {
@@ -152,7 +153,13 @@ static void __init x3proto_init_irq(void)
        __raw_writel(__raw_readl(0xfe410000) | (1 << 21), 0xfe410000);
 }
 
+static void __init x3proto_setup(char **cmdline_p)
+{
+       register_smp_ops(&shx3_smp_ops);
+}
+
 static struct sh_machine_vector mv_x3proto __initmv = {
        .mv_name                = "x3proto",
+       .mv_setup               = x3proto_setup,
        .mv_init_irq            = x3proto_init_irq,
 };
index 5d660b9..cfa5a08 100644 (file)
@@ -14,10 +14,16 @@ OBJECTS = $(obj)/head_$(BITS).o $(obj)/misc.o $(obj)/cache.o
 #
 # IMAGE_OFFSET is the load offset of the compression loader
 #
+ifeq ($(CONFIG_32BIT),y)
+IMAGE_OFFSET   := $(shell /bin/bash -c 'printf "0x%08x" \
+                    $$[$(CONFIG_MEMORY_START)  + \
+                       $(CONFIG_BOOT_LINK_OFFSET)]')
+else
 IMAGE_OFFSET   := $(shell /bin/bash -c 'printf "0x%08x" \
                     $$[$(CONFIG_PAGE_OFFSET)  + \
                        $(KERNEL_MEMORY) + \
                        $(CONFIG_BOOT_LINK_OFFSET)]')
+endif
 
 LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
 
index 02a3093..200c1d4 100644 (file)
@@ -97,7 +97,11 @@ init_stack_addr:
 decompress_kernel_addr:
        .long   decompress_kernel
 kernel_start_addr:
+#ifdef CONFIG_32BIT
+       .long   ___pa(_text+PAGE_SIZE)
+#else
        .long   _text+PAGE_SIZE
+#endif
 
        .align  9
 fake_headers_as_bzImage:
index 8931a60..7fefa2b 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:10:59 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:04:35 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,11 +74,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -107,7 +105,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -116,13 +114,13 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,8 +235,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -246,6 +244,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -261,7 +261,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -335,7 +335,7 @@ CONFIG_SECCOMP=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -371,6 +371,7 @@ CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -378,7 +379,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -594,6 +594,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ICS932S401 is not set
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_TI_DAC7512 is not set
 # CONFIG_C2PORT is not set
@@ -613,6 +614,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -774,6 +776,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -802,6 +805,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -814,15 +818,9 @@ CONFIG_I2C_SH_MOBILE=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 CONFIG_SPI=y
 CONFIG_SPI_MASTER=y
 
@@ -853,13 +851,16 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -891,22 +892,25 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_MFD_MC13783 is not set
 # CONFIG_AB3100_CORE is not set
 # CONFIG_EZX_PCAP is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_AB4500_CORE is not set
 # CONFIG_REGULATOR is not set
 CONFIG_MEDIA_SUPPORT=y
@@ -1041,10 +1045,7 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 # MMC/SD/SDIO Host Controller Drivers
 #
 # CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
 CONFIG_MMC_SPI=y
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MEMSTICK is not set
 # CONFIG_NEW_LEDS is not set
 # CONFIG_ACCESSIBILITY is not set
@@ -1120,8 +1121,6 @@ CONFIG_RTC_DRV_PCF8563=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -1206,6 +1205,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
 # CONFIG_UBIFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1234,6 +1234,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1426,6 +1427,7 @@ CONFIG_CRYPTO_CBC=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 92589a9..edae0a6 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:14:50 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:01:02 2010
 #
 CONFIG_SUPERH=y
 # CONFIG_SUPERH32 is not set
@@ -13,7 +13,6 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
@@ -32,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 # CONFIG_SYSVIPC is not set
 CONFIG_POSIX_MQUEUE=y
@@ -70,7 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -114,7 +115,6 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
@@ -204,6 +204,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -225,7 +226,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -294,7 +295,6 @@ CONFIG_HZ=250
 # CONFIG_PREEMPT_NONE is not set
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -309,9 +309,9 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -337,7 +337,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -463,6 +462,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_HP_ILO is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_C2PORT is not set
 
@@ -480,6 +480,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -569,7 +570,7 @@ CONFIG_SCSI_LOWLEVEL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -638,6 +639,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -650,6 +653,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -732,6 +736,7 @@ CONFIG_DEVKMEM=y
 #
 # CONFIG_SERIAL_SH_SCI is not set
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -779,6 +784,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -791,15 +797,9 @@ CONFIG_I2C_HELPER_AUTO=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -823,10 +823,11 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
+# CONFIG_SENSORS_ADT7411 is not set
 # CONFIG_SENSORS_ADT7462 is not set
 # CONFIG_SENSORS_ADT7470 is not set
-# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ADT7475 is not set
+# CONFIG_SENSORS_ASC7621 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_I5K_AMB is not set
@@ -863,6 +864,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
 # CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_AMC6821 is not set
 # CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_TMP401 is not set
 # CONFIG_SENSORS_TMP421 is not set
@@ -909,9 +911,9 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_MFD_WM8400 is not set
-# CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
-# CONFIG_AB3100_CORE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -919,6 +921,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 CONFIG_VIDEO_OUTPUT_CONTROL=y
@@ -1125,6 +1128,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1153,6 +1157,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1208,6 +1213,7 @@ CONFIG_SCHEDSTATS=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1234,6 +1240,7 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
@@ -1361,6 +1368,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 55f652b..b96bf3d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:17:35 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:11:55 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -72,7 +75,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -124,6 +126,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -242,6 +245,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -263,7 +267,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -360,7 +364,6 @@ CONFIG_SECCOMP=y
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -377,9 +380,9 @@ CONFIG_CMDLINE="console=ttySC1,115200 panic=3"
 #
 CONFIG_MAPLE=y
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -404,7 +407,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -532,6 +534,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -549,7 +552,7 @@ CONFIG_HAVE_IDE=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -589,6 +592,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -717,6 +721,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -771,6 +776,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -778,6 +784,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 CONFIG_VIDEO_OUTPUT_CONTROL=m
@@ -918,7 +925,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -976,6 +982,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -990,6 +997,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1135,6 +1143,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 662c1ad..58aec9d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:18:17 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:14:56 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,11 +74,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -86,6 +84,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -111,7 +110,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -120,13 +119,13 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,8 +236,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x10000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -246,6 +245,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -261,7 +262,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -336,7 +337,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -370,6 +371,7 @@ CONFIG_PM=y
 # CONFIG_SUSPEND is not set
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -377,7 +379,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -485,6 +486,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -585,6 +587,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -650,6 +653,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -678,6 +682,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -690,15 +695,9 @@ CONFIG_I2C_SH_MOBILE=y
 # Other I2C/SMBus bus drivers
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -712,13 +711,16 @@ CONFIG_GPIO_SYSFS=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -747,20 +749,23 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -868,7 +873,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -880,7 +884,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -911,7 +914,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1027,6 +1029,7 @@ CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 CONFIG_HAVE_FUNCTION_TRACER=y
@@ -1056,6 +1059,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 6041c66..67c6656 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.34-rc2
-# Mon Mar 29 02:21:58 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:17:28 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -336,6 +336,7 @@ CONFIG_SECCOMP=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -762,6 +763,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -1755,6 +1757,7 @@ CONFIG_CRYPTO_CBC=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 72f8718..0883d87 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:24:26 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:21:52 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -12,8 +12,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -29,6 +29,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -43,9 +44,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SYSVIPC is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 
@@ -61,11 +64,11 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=17
-# CONFIG_CGROUPS is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
 # CONFIG_BLK_DEV_INITRD is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_ANON_INODES=y
 CONFIG_EMBEDDED=y
 # CONFIG_UID16 is not set
 # CONFIG_KALLSYMS is not set
@@ -87,7 +90,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_VM_EVENT_COUNTERS is not set
 # CONFIG_COMPAT_BRK is not set
@@ -103,6 +106,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -202,6 +206,7 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -217,7 +222,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -330,6 +335,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_SCSI_DMA is not set
 # CONFIG_SCSI_NETLINK is not set
 # CONFIG_PHONE is not set
@@ -361,6 +367,7 @@ CONFIG_HAVE_IDE=y
 # Non-8250 serial port support
 #
 # CONFIG_SERIAL_SH_SCI is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -440,6 +447,7 @@ CONFIG_INOTIFY_USER=y
 #
 # Caches
 #
+# CONFIG_FSCACHE is not set
 
 #
 # Pseudo filesystems
@@ -491,6 +499,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 0932e6d..8257f57 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:24:44 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:23:10 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -72,7 +75,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=17
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -83,6 +85,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -110,8 +113,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_SLUB_DEBUG=y
 CONFIG_COMPAT_BRK=y
@@ -128,6 +132,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -246,6 +251,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -261,7 +267,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -342,7 +348,6 @@ CONFIG_SCHED_HRTICK=y
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -379,7 +384,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -579,6 +583,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -685,6 +690,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -713,6 +719,7 @@ CONFIG_I2C_HELPER_AUTO=y
 CONFIG_I2C_SH7760=y
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -725,15 +732,9 @@ CONFIG_I2C_SH7760=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 CONFIG_I2C_DEBUG_CORE=y
 CONFIG_I2C_DEBUG_ALGO=y
 CONFIG_I2C_DEBUG_BUS=y
-CONFIG_I2C_DEBUG_CHIP=y
 # CONFIG_SPI is not set
 
 #
@@ -756,6 +757,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -763,12 +765,13 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -947,6 +950,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -969,6 +973,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1048,6 +1053,7 @@ CONFIG_TIMER_STATS=y
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_SLUB_DEBUG_ON is not set
 # CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1096,6 +1102,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1214,6 +1221,7 @@ CONFIG_CRYPTO_DES=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index f899e56..8acdc37 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:26:55 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:27:14 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,11 +72,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -112,7 +110,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -120,7 +117,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -131,6 +127,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -243,7 +240,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x0c000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
+# CONFIG_PMB is not set
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -253,6 +250,7 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -269,7 +267,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -344,7 +342,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -381,7 +379,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -444,7 +441,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -584,6 +580,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -688,6 +685,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -753,6 +751,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -944,7 +943,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -956,7 +954,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1052,6 +1049,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1078,6 +1076,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1144,13 +1143,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1158,10 +1156,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1269,7 +1264,8 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 0664490..f894bdc 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:30:31 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:30:50 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 # CONFIG_SYSVIPC is not set
 CONFIG_BSD_PROCESS_ACCT=y
@@ -66,7 +69,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -99,7 +101,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -115,6 +117,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -228,6 +231,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -243,7 +247,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -326,7 +330,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -344,7 +347,6 @@ CONFIG_ENTRY_OFFSET=0x00001000
 CONFIG_PCCARD=y
 CONFIG_PCMCIA=y
 CONFIG_PCMCIA_LOAD_CIS=y
-CONFIG_PCMCIA_IOCTL=y
 
 #
 # PC-card bridges
@@ -369,6 +371,7 @@ CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_APM_EMULATION=y
 # CONFIG_PM_RUNTIME is not set
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 # CONFIG_NET is not set
 
@@ -412,6 +415,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -544,6 +548,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -722,7 +727,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -780,6 +784,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -977,6 +982,7 @@ CONFIG_CRYPTO_MD5=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 3d834e5..8c54e16 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:31:09 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:33:23 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 # CONFIG_POSIX_MQUEUE is not set
@@ -70,11 +73,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -85,6 +83,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -110,7 +109,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -119,13 +118,13 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -222,8 +221,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -231,6 +230,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -246,7 +247,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -321,7 +322,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -354,6 +355,7 @@ CONFIG_PM=y
 # CONFIG_PM_DEBUG is not set
 # CONFIG_SUSPEND is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -361,7 +363,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -449,6 +450,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_SCSI_DMA is not set
 # CONFIG_SCSI_NETLINK is not set
 # CONFIG_NETDEVICES is not set
@@ -511,6 +513,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -538,6 +541,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -549,15 +553,9 @@ CONFIG_I2C_SH_MOBILE=y
 # Other I2C/SMBus bus drivers
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -571,13 +569,16 @@ CONFIG_GPIO_SYSFS=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -606,20 +607,23 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -690,6 +694,7 @@ CONFIG_USB_GADGET_DUALSPEED=y
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 CONFIG_USB_CDC_COMPOSITE=y
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -794,6 +799,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index f22be49..2e74b08 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:32:55 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:35:20 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -72,11 +75,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -87,6 +85,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -112,7 +111,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -121,13 +120,13 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -243,8 +242,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -252,6 +251,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -267,7 +268,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -343,7 +344,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -377,6 +378,7 @@ CONFIG_PM=y
 # CONFIG_SUSPEND is not set
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 CONFIG_CPU_IDLE=y
 CONFIG_CPU_IDLE_GOV_LADDER=y
 CONFIG_CPU_IDLE_GOV_MENU=y
@@ -386,7 +388,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -580,6 +581,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -659,6 +661,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -687,6 +690,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -699,15 +703,9 @@ CONFIG_I2C_SH_MOBILE=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -721,13 +719,16 @@ CONFIG_GPIO_SYSFS=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -756,20 +757,23 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -889,6 +893,7 @@ CONFIG_USB_GADGET_DUALSPEED=y
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 CONFIG_USB_CDC_COMPOSITE=m
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -912,9 +917,6 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 # MMC/SD/SDIO Host Controller Drivers
 #
 # CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MEMSTICK is not set
 # CONFIG_NEW_LEDS is not set
 # CONFIG_ACCESSIBILITY is not set
@@ -982,8 +984,6 @@ CONFIG_RTC_DRV_SH=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -996,7 +996,6 @@ CONFIG_UIO_PDRV_GENIRQ=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1074,6 +1073,7 @@ CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 CONFIG_HAVE_FUNCTION_TRACER=y
@@ -1103,6 +1103,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 2a42d49..8778934 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:35:31 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:38:08 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,7 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -102,7 +104,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -120,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -238,6 +241,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -253,7 +257,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -333,7 +337,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -348,15 +351,14 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 CONFIG_PCCARD=y
 CONFIG_PCMCIA=y
 CONFIG_PCMCIA_LOAD_CIS=y
-CONFIG_PCMCIA_IOCTL=y
 CONFIG_CARDBUS=y
 
 #
@@ -392,7 +394,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -612,6 +613,7 @@ CONFIG_BLK_DEV_IDEDMA=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -711,7 +713,7 @@ CONFIG_MD_RAID1=m
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -751,6 +753,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -798,6 +801,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -810,6 +815,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -835,6 +841,7 @@ CONFIG_WLAN=y
 CONFIG_USB_PEGASUS=m
 CONFIG_USB_RTL8150=m
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_NET_PCMCIA is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
@@ -910,6 +917,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -977,6 +985,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -984,6 +993,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1025,6 +1035,7 @@ CONFIG_USB_HID=m
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=m
 CONFIG_HID_APPLE=m
 CONFIG_HID_BELKIN=m
@@ -1040,14 +1051,19 @@ CONFIG_HID_GYRATION=m
 CONFIG_HID_LOGITECH=m
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=m
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=m
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=m
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=m
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=m
 CONFIG_HID_SONY=m
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=m
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1169,6 +1185,7 @@ CONFIG_USB_SERIAL_FTDI_SIO=m
 # CONFIG_USB_SERIAL_NAVMAN is not set
 CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_SERIAL_OTI6858 is not set
+# CONFIG_USB_SERIAL_QCAUX is not set
 # CONFIG_USB_SERIAL_QUALCOMM is not set
 # CONFIG_USB_SERIAL_SPCP8X5 is not set
 # CONFIG_USB_SERIAL_HP4X is not set
@@ -1182,6 +1199,7 @@ CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_SERIAL_OPTION is not set
 # CONFIG_USB_SERIAL_OMNINET is not set
 # CONFIG_USB_SERIAL_OPTICON is not set
+# CONFIG_USB_SERIAL_VIVOPAY_SERIAL is not set
 # CONFIG_USB_SERIAL_DEBUG is not set
 
 #
@@ -1194,7 +1212,6 @@ CONFIG_USB_EMI26=m
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1208,7 +1225,6 @@ CONFIG_USB_SISUSBVGA_CON=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1313,6 +1329,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1347,6 +1364,7 @@ CONFIG_SUNRPC=m
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 CONFIG_SMB_FS=m
 # CONFIG_SMB_NLS_DEFAULT is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1531,6 +1549,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index f2f1f8c..6088a76 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:37:01 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:42:57 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,7 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -102,7 +104,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -120,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -238,6 +241,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -253,7 +257,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -333,7 +337,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -349,15 +352,14 @@ CONFIG_CMDLINE="console=ttySC1,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 CONFIG_PCCARD=y
 CONFIG_PCMCIA=y
 CONFIG_PCMCIA_LOAD_CIS=y
-CONFIG_PCMCIA_IOCTL=y
 CONFIG_CARDBUS=y
 
 #
@@ -392,7 +394,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -552,6 +553,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -670,6 +672,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -707,7 +710,7 @@ CONFIG_PATA_PLATFORM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -747,6 +750,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -798,6 +802,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -810,6 +816,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -908,6 +915,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -975,6 +983,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -982,6 +991,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1155,6 +1165,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1173,6 +1184,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1357,6 +1369,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index a7a16ce..28c104d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:37:42 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:44:00 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,7 +74,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=17
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -82,6 +84,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -109,8 +112,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
 CONFIG_SLAB=y
@@ -126,6 +130,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -244,6 +249,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -259,7 +265,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -344,7 +350,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -380,7 +385,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -586,6 +590,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -741,6 +746,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -765,6 +771,7 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
@@ -953,6 +960,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -977,6 +985,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1051,6 +1060,7 @@ CONFIG_DEBUG_KERNEL=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1097,6 +1107,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1125,6 +1136,7 @@ CONFIG_DUMP_CODE=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 7d43fab..41cefa4 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:40:41 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:48:22 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 # CONFIG_SYSVIPC is not set
 # CONFIG_POSIX_MQUEUE is not set
@@ -69,7 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -80,6 +82,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -106,7 +109,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -122,6 +125,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -235,6 +239,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -256,7 +261,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -334,7 +339,6 @@ CONFIG_HZ=250
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -515,6 +519,7 @@ CONFIG_IDE_PROC_FS=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -596,6 +601,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -774,6 +780,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -800,6 +807,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -992,6 +1000,7 @@ CONFIG_CRYPTO_DES=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index d2b1831..1c889b7 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:41:41 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:01:29 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,7 +74,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -82,6 +84,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -109,7 +112,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -117,17 +119,16 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -243,7 +244,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x0c000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_X2TLB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_NUMA=y
 CONFIG_NODES_SHIFT=1
@@ -254,6 +255,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -271,7 +274,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_MIGRATION is not set
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -348,7 +351,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -384,6 +387,7 @@ CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -391,7 +395,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -454,7 +457,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -564,6 +566,7 @@ CONFIG_MTD_NAND_IDS=y
 # CONFIG_MTD_NAND_DISKONCHIP is not set
 # CONFIG_MTD_NAND_NANDSIM is not set
 CONFIG_MTD_NAND_PLATFORM=y
+# CONFIG_MTD_NAND_SH_FLCTL is not set
 # CONFIG_MTD_ONENAND is not set
 
 #
@@ -596,6 +599,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ICS932S401 is not set
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_C2PORT is not set
 
@@ -612,6 +616,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -764,6 +769,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -792,6 +798,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -804,15 +811,9 @@ CONFIG_I2C_SH_MOBILE=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -826,13 +827,16 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -861,20 +865,23 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 CONFIG_MEDIA_SUPPORT=y
 
@@ -1054,6 +1061,7 @@ CONFIG_USB_G_SERIAL=m
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 # CONFIG_USB_CDC_COMPOSITE is not set
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -1129,8 +1137,6 @@ CONFIG_RTC_DRV_SH=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -1143,7 +1149,6 @@ CONFIG_UIO_PDRV_GENIRQ=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1202,6 +1207,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1224,6 +1230,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1251,13 +1258,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1265,10 +1271,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1383,7 +1386,8 @@ CONFIG_CRYPTO_WORKQUEUE=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index d50c031..826b119 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 11:45:25 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:53:51 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,11 +74,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -109,8 +107,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
 CONFIG_SLAB=y
@@ -126,6 +125,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -244,6 +244,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -259,7 +260,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=999999
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -340,7 +341,6 @@ CONFIG_SCHED_HRTICK=y
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -377,7 +377,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -583,6 +582,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -712,6 +712,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -829,7 +830,6 @@ CONFIG_RTC_DRV_SH=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -896,6 +896,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -919,6 +920,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -958,6 +960,7 @@ CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 CONFIG_DEBUG_RT_MUTEXES=y
 CONFIG_DEBUG_PI_LIST=y
@@ -1010,6 +1013,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1038,6 +1042,7 @@ CONFIG_DUMP_CODE=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index efda63d..4b751bd 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:16:13 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 15:58:09 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_IO_TRAPPED=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,11 +76,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -112,7 +110,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -122,7 +119,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=m
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -133,6 +129,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -245,11 +242,8 @@ CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
-# CONFIG_29BIT is not set
-CONFIG_32BIT=y
-CONFIG_PMB_ENABLE=y
+CONFIG_29BIT=y
 # CONFIG_PMB is not set
-CONFIG_PMB_FIXED=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -257,6 +251,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -278,7 +273,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -358,7 +353,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -374,9 +369,9 @@ CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -402,7 +397,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -452,6 +446,7 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # CONFIG_ATM is not set
 CONFIG_STP=m
 CONFIG_BRIDGE=m
+CONFIG_BRIDGE_IGMP_SNOOPING=y
 # CONFIG_NET_DSA is not set
 # CONFIG_VLAN_8021Q is not set
 # CONFIG_DECNET is not set
@@ -472,7 +467,6 @@ CONFIG_LLC=m
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -621,6 +615,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_HP_ILO is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_C2PORT is not set
 
@@ -638,6 +633,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -755,6 +751,7 @@ CONFIG_SATA_SIL=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -791,7 +788,7 @@ CONFIG_PATA_PLATFORM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -832,6 +829,7 @@ CONFIG_NET_PCI=y
 CONFIG_PCNET32=m
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -884,6 +882,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -896,6 +896,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -995,6 +996,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -1043,6 +1045,7 @@ CONFIG_I2C_HIGHLANDER=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -1055,15 +1058,9 @@ CONFIG_I2C_HIGHLANDER=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -1087,10 +1084,11 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
+# CONFIG_SENSORS_ADT7411 is not set
 # CONFIG_SENSORS_ADT7462 is not set
 # CONFIG_SENSORS_ADT7470 is not set
-# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ADT7475 is not set
+# CONFIG_SENSORS_ASC7621 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_I5K_AMB is not set
@@ -1127,6 +1125,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
 # CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_AMC6821 is not set
 # CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_TMP401 is not set
 # CONFIG_SENSORS_TMP421 is not set
@@ -1156,6 +1155,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -1163,12 +1163,14 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1176,6 +1178,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1372,6 +1375,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1402,6 +1406,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1480,6 +1485,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_PREEMPT is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1490,7 +1496,6 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_LOCK_STAT is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
 # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-CONFIG_STACKTRACE=y
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 CONFIG_DEBUG_INFO=y
@@ -1507,11 +1512,11 @@ CONFIG_DEBUG_INFO=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 # CONFIG_PAGE_POISONING is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1519,10 +1524,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
@@ -1535,6 +1537,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1662,7 +1665,8 @@ CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index f4b0045..f5e3819 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:19:35 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:03:27 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -34,6 +34,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_IO_TRAPPED=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -49,9 +50,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -77,7 +80,6 @@ CONFIG_TREE_RCU_TRACE=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -112,7 +114,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -122,18 +123,17 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 CONFIG_KPROBES=y
 CONFIG_KRETPROBES=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -247,12 +247,9 @@ CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
-# CONFIG_29BIT is not set
-CONFIG_32BIT=y
-CONFIG_PMB_ENABLE=y
+CONFIG_29BIT=y
 # CONFIG_PMB is not set
-CONFIG_PMB_FIXED=y
-# CONFIG_X2TLB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 # CONFIG_NUMA is not set
 CONFIG_ARCH_FLATMEM_ENABLE=y
@@ -263,6 +260,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -285,7 +284,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=999999
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -303,6 +302,7 @@ CONFIG_CPU_LITTLE_ENDIAN=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_SH_FPU=y
 CONFIG_SH_STORE_QUEUES=y
+# CONFIG_SPECULATIVE_EXECUTION is not set
 CONFIG_CPU_HAS_INTEVT=y
 CONFIG_CPU_HAS_SR_RB=y
 CONFIG_CPU_HAS_FPU=y
@@ -377,7 +377,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -393,9 +393,9 @@ CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_LEGACY is not set
 # CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -421,7 +421,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -471,6 +470,7 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # CONFIG_ATM is not set
 CONFIG_STP=m
 CONFIG_BRIDGE=m
+CONFIG_BRIDGE_IGMP_SNOOPING=y
 # CONFIG_NET_DSA is not set
 # CONFIG_VLAN_8021Q is not set
 # CONFIG_DECNET is not set
@@ -492,7 +492,6 @@ CONFIG_LLC=m
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_NET_TCPPROBE is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -557,6 +556,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_HP_ILO is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_C2PORT is not set
 
@@ -574,6 +574,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -691,6 +692,7 @@ CONFIG_SATA_SIL=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -727,7 +729,7 @@ CONFIG_PATA_PLATFORM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -797,6 +799,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -809,6 +813,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -910,6 +915,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -959,6 +965,7 @@ CONFIG_I2C_HIGHLANDER=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -971,15 +978,9 @@ CONFIG_I2C_HIGHLANDER=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -994,13 +995,17 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
+# CONFIG_GPIO_SCH is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -1033,10 +1038,11 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
+# CONFIG_SENSORS_ADT7411 is not set
 # CONFIG_SENSORS_ADT7462 is not set
 # CONFIG_SENSORS_ADT7470 is not set
-# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ADT7475 is not set
+# CONFIG_SENSORS_ASC7621 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_I5K_AMB is not set
@@ -1074,6 +1080,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
 # CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_AMC6821 is not set
 # CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_TMP401 is not set
 # CONFIG_SENSORS_TMP421 is not set
@@ -1102,20 +1109,25 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
+# CONFIG_MFD_TIMBERDALE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1123,6 +1135,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1371,6 +1384,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1401,6 +1415,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1475,6 +1490,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_PREEMPT is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1510,7 +1526,6 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 # CONFIG_PAGE_POISONING is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1518,10 +1533,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
@@ -1534,6 +1546,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1661,7 +1674,8 @@ CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 2fc635a..80e7b41 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:23:12 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:09:18 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -44,9 +45,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_BSD_PROCESS_ACCT=y
@@ -65,7 +68,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 # CONFIG_IKCONFIG_PROC is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
 # CONFIG_RELAY is not set
@@ -79,6 +81,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -105,7 +108,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -114,7 +116,6 @@ CONFIG_COMPAT_BRK=y
 CONFIG_SLOB=y
 # CONFIG_MMAP_ALLOW_UNINITIALIZED is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -124,6 +125,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -240,6 +242,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -255,7 +258,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 CONFIG_NOMMU_INITIAL_TRIM_EXCESS=1
 
 #
@@ -326,7 +329,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -485,6 +487,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -545,6 +548,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=8
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -657,7 +661,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XATTR is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -720,6 +723,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -756,13 +760,12 @@ CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 CONFIG_SYSCTL_SYSCALL_CHECK=y
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -770,10 +773,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -795,7 +795,8 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 0169e60..66eb7d7 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:23:54 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:11:37 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_POSIX_MQUEUE=y
@@ -70,7 +73,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 # CONFIG_IKCONFIG_PROC is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
 # CONFIG_RELAY is not set
@@ -85,6 +87,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -112,7 +115,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -122,7 +124,6 @@ CONFIG_COMPAT_BRK=y
 CONFIG_SLOB=y
 # CONFIG_MMAP_ALLOW_UNINITIALIZED is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -132,6 +133,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -248,6 +250,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -263,7 +266,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 CONFIG_NOMMU_INITIAL_TRIM_EXCESS=1
 
 #
@@ -350,7 +353,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -448,7 +450,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -592,6 +593,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -662,6 +664,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -723,6 +726,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=4
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -745,6 +749,7 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
@@ -783,6 +788,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 CONFIG_REGULATOR=y
 # CONFIG_REGULATOR_DEBUG is not set
+# CONFIG_REGULATOR_DUMMY is not set
 # CONFIG_REGULATOR_FIXED_VOLTAGE is not set
 # CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set
 # CONFIG_REGULATOR_USERSPACE_CONSUMER is not set
@@ -816,6 +822,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -831,14 +838,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -859,7 +871,6 @@ CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
 CONFIG_USB_DEVICEFS=y
 CONFIG_USB_DEVICE_CLASS=y
 # CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
 # CONFIG_USB_OTG is not set
 # CONFIG_USB_OTG_WHITELIST is not set
 # CONFIG_USB_OTG_BLACKLIST_HUB is not set
@@ -916,7 +927,6 @@ CONFIG_USB_R8A66597_HCD=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -928,7 +938,6 @@ CONFIG_USB_R8A66597_HCD=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -948,11 +957,11 @@ CONFIG_LEDS_GPIO=y
 CONFIG_LEDS_GPIO_PLATFORM=y
 # CONFIG_LEDS_REGULATOR is not set
 # CONFIG_LEDS_LT3593 is not set
+CONFIG_LEDS_TRIGGERS=y
 
 #
 # LED Triggers
 #
-CONFIG_LEDS_TRIGGERS=y
 CONFIG_LEDS_TRIGGER_TIMER=y
 CONFIG_LEDS_TRIGGER_HEARTBEAT=y
 CONFIG_LEDS_TRIGGER_BACKLIGHT=y
@@ -1018,7 +1027,6 @@ CONFIG_RTC_DRV_SH=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1072,6 +1080,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1098,6 +1107,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1180,6 +1190,7 @@ CONFIG_DEBUG_OBJECTS=y
 # CONFIG_DEBUG_OBJECTS_TIMERS is not set
 # CONFIG_DEBUG_OBJECTS_WORK is not set
 CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1189,7 +1200,6 @@ CONFIG_DEBUG_MUTEXES=y
 # CONFIG_LOCK_STAT is not set
 CONFIG_DEBUG_SPINLOCK_SLEEP=y
 # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-CONFIG_STACKTRACE=y
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 CONFIG_DEBUG_INFO=y
@@ -1207,11 +1217,11 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 CONFIG_SYSCTL_SYSCALL_CHECK=y
 # CONFIG_PAGE_POISONING is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1219,10 +1229,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
@@ -1234,6 +1241,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1263,7 +1271,8 @@ CONFIG_DUMP_CODE=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index dba024d..6bd3d95 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:25:36 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:15:07 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_IO_TRAPPED=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -70,7 +73,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -104,7 +106,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -113,7 +114,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -124,6 +124,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -242,6 +243,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -257,7 +259,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -343,7 +345,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -359,9 +360,9 @@ CONFIG_CMDLINE="console=tty0 console=ttySC1,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -389,7 +390,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -449,7 +449,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -525,6 +524,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -642,6 +642,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -678,7 +679,7 @@ CONFIG_PATA_PLATFORM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -719,6 +720,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -771,6 +773,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -783,6 +787,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -805,6 +810,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -882,6 +888,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -964,6 +971,7 @@ CONFIG_MFD_SM501=y
 # CONFIG_MFD_MC13783 is not set
 # CONFIG_EZX_PCAP is not set
 # CONFIG_AB4500_CORE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -971,6 +979,7 @@ CONFIG_MFD_SM501=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 CONFIG_VIDEO_OUTPUT_CONTROL=m
@@ -1152,6 +1161,7 @@ CONFIG_SND_SPI=y
 CONFIG_SND_SUPERH=y
 CONFIG_SND_USB=y
 # CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_UA101 is not set
 # CONFIG_SND_USB_CAIAQ is not set
 # CONFIG_SND_SOC is not set
 CONFIG_SOUND_PRIME=m
@@ -1170,6 +1180,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1185,14 +1196,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1291,7 +1307,6 @@ CONFIG_USB_LIBUSUAL=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1303,7 +1318,6 @@ CONFIG_USB_LIBUSUAL=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1381,7 +1395,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1442,6 +1455,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1456,6 +1470,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1522,13 +1537,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1536,10 +1550,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1648,7 +1659,8 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 6d511d0..487abcc 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:26:39 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:20:00 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_IO_TRAPPED=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -70,7 +73,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -104,7 +106,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -113,7 +114,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -124,6 +124,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -242,6 +243,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -257,7 +259,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -343,7 +345,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -359,9 +360,9 @@ CONFIG_CMDLINE="console=tty0 console=ttySC1,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -389,7 +390,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -449,7 +449,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -611,6 +610,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -728,6 +728,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -764,7 +765,7 @@ CONFIG_PATA_PLATFORM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -805,6 +806,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -857,6 +859,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -869,6 +873,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -891,6 +896,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -968,6 +974,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -1050,6 +1057,7 @@ CONFIG_MFD_SM501=y
 # CONFIG_MFD_MC13783 is not set
 # CONFIG_EZX_PCAP is not set
 # CONFIG_AB4500_CORE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1057,6 +1065,7 @@ CONFIG_MFD_SM501=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 CONFIG_VIDEO_OUTPUT_CONTROL=m
@@ -1238,6 +1247,7 @@ CONFIG_SND_SPI=y
 CONFIG_SND_SUPERH=y
 CONFIG_SND_USB=y
 # CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_UA101 is not set
 # CONFIG_SND_USB_CAIAQ is not set
 # CONFIG_SND_SOC is not set
 CONFIG_SOUND_PRIME=m
@@ -1256,6 +1266,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1271,14 +1282,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1377,7 +1393,6 @@ CONFIG_USB_LIBUSUAL=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1389,7 +1404,6 @@ CONFIG_USB_LIBUSUAL=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1467,7 +1481,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1529,6 +1542,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1543,6 +1557,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1609,13 +1624,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1623,10 +1637,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1735,7 +1746,8 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 1859ba0..fe92314 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:27:20 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:21:00 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,7 +76,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=18
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -107,8 +109,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
 CONFIG_SLUB_DEBUG=y
@@ -126,6 +129,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,11 +241,8 @@ CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
-# CONFIG_29BIT is not set
-CONFIG_32BIT=y
-CONFIG_PMB_ENABLE=y
+CONFIG_29BIT=y
 # CONFIG_PMB is not set
-CONFIG_PMB_FIXED=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -249,6 +250,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -270,7 +272,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -353,7 +355,7 @@ CONFIG_SCHED_HRTICK=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -369,16 +371,15 @@ CONFIG_CMDLINE="mem=128M console=tty0 console=ttySC0,115200 ip=bootp root=/dev/n
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_LEGACY is not set
 CONFIG_PCI_DEBUG=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 CONFIG_PCCARD=y
 CONFIG_PCMCIA=y
 CONFIG_PCMCIA_LOAD_CIS=y
-CONFIG_PCMCIA_IOCTL=y
 CONFIG_CARDBUS=y
 
 #
@@ -417,7 +418,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -659,6 +659,7 @@ CONFIG_BLK_DEV_GENERIC=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -777,6 +778,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -824,7 +826,7 @@ CONFIG_BLK_DEV_DM=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -890,6 +892,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_NET_PCMCIA is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
@@ -995,6 +998,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -1057,6 +1061,7 @@ CONFIG_SSB_DRIVER_PCICORE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1064,6 +1069,7 @@ CONFIG_SSB_DRIVER_PCICORE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1167,6 +1173,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1182,14 +1189,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1288,7 +1300,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1301,7 +1312,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1317,10 +1327,6 @@ CONFIG_LEDS_CLASS=y
 #
 # LED drivers
 #
-
-#
-# LED Triggers
-#
 # CONFIG_LEDS_TRIGGERS is not set
 # CONFIG_ACCESSIBILITY is not set
 # CONFIG_INFINIBAND is not set
@@ -1416,6 +1422,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1444,6 +1451,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1523,6 +1531,7 @@ CONFIG_TIMER_STATS=y
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_SLUB_DEBUG_ON is not set
 # CONFIG_SLUB_STATS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1571,6 +1580,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1690,6 +1700,7 @@ CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 9b331ea..2698245 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc7
-# Tue Feb  9 15:27:06 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:03:37 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -18,6 +18,8 @@ CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
+CONFIG_GENERIC_CLOCKEVENTS_BROADCAST=y
+CONFIG_GENERIC_LOCKBREAK=y
 # CONFIG_ARCH_SUSPEND_POSSIBLE is not set
 CONFIG_ARCH_HIBERNATION_POSSIBLE=y
 CONFIG_SYS_SUPPORTS_HUGETLBFS=y
@@ -35,6 +37,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_COHERENT=y
 # CONFIG_DMA_NONCOHERENT is not set
+# CONFIG_NEED_DMA_MAP_STATE is not set
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -42,7 +45,6 @@ CONFIG_CONSTRUCTORS=y
 # General setup
 #
 CONFIG_EXPERIMENTAL=y
-CONFIG_BROKEN_ON_SMP=y
 CONFIG_LOCK_KERNEL=y
 CONFIG_INIT_ENV_ARG_LIMIT=32
 CONFIG_LOCALVERSION=""
@@ -51,25 +53,27 @@ CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
 CONFIG_HAVE_KERNEL_LZO=y
-CONFIG_KERNEL_GZIP=y
+# CONFIG_KERNEL_GZIP is not set
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
-# CONFIG_KERNEL_LZO is not set
+CONFIG_KERNEL_LZO=y
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_POSIX_MQUEUE=y
 CONFIG_POSIX_MQUEUE_SYSCTL=y
 CONFIG_BSD_PROCESS_ACCT=y
-# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+CONFIG_BSD_PROCESS_ACCT_V3=y
 # CONFIG_TASKSTATS is not set
-# CONFIG_AUDIT is not set
+CONFIG_AUDIT=y
+CONFIG_AUDITSYSCALL=y
+CONFIG_AUDIT_TREE=y
 
 #
 # RCU Subsystem
 #
-CONFIG_TREE_RCU=y
-# CONFIG_TREE_PREEMPT_RCU is not set
+# CONFIG_TREE_RCU is not set
+CONFIG_TREE_PREEMPT_RCU=y
 # CONFIG_TINY_RCU is not set
 CONFIG_RCU_TRACE=y
 CONFIG_RCU_FANOUT=32
@@ -77,32 +81,36 @@ CONFIG_RCU_FANOUT=32
 CONFIG_TREE_RCU_TRACE=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
-CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
+CONFIG_LOG_BUF_SHIFT=17
 CONFIG_CGROUPS=y
-# CONFIG_CGROUP_DEBUG is not set
+CONFIG_CGROUP_DEBUG=y
 CONFIG_CGROUP_NS=y
 CONFIG_CGROUP_FREEZER=y
 CONFIG_CGROUP_DEVICE=y
-# CONFIG_CPUSETS is not set
+CONFIG_CPUSETS=y
+# CONFIG_PROC_PID_CPUSET is not set
 CONFIG_CGROUP_CPUACCT=y
 CONFIG_RESOURCE_COUNTERS=y
 CONFIG_CGROUP_MEM_RES_CTLR=y
-# CONFIG_CGROUP_MEM_RES_CTLR_SWAP is not set
+CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_RT_GROUP_SCHED=y
 CONFIG_MM_OWNER=y
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
-# CONFIG_RELAY is not set
+CONFIG_RELAY=y
 CONFIG_NAMESPACES=y
 CONFIG_UTS_NS=y
 CONFIG_IPC_NS=y
 CONFIG_USER_NS=y
 CONFIG_PID_NS=y
 CONFIG_NET_NS=y
-# CONFIG_BLK_DEV_INITRD is not set
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_INITRAMFS_SOURCE=""
+CONFIG_RD_GZIP=y
+CONFIG_RD_BZIP2=y
+CONFIG_RD_LZMA=y
+CONFIG_RD_LZO=y
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -131,7 +139,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -142,13 +149,15 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
 CONFIG_TRACEPOINTS=y
-# CONFIG_OPROFILE is not set
+CONFIG_OPROFILE=m
 CONFIG_HAVE_OPROFILE=y
-# CONFIG_KPROBES is not set
+CONFIG_KPROBES=y
+CONFIG_KRETPROBES=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
+CONFIG_USE_GENERIC_SMP_HELPERS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
 CONFIG_HAVE_HW_BREAKPOINT=y
@@ -157,7 +166,8 @@ CONFIG_HAVE_HW_BREAKPOINT=y
 # GCOV-based kernel profiling
 #
 # CONFIG_GCOV_KERNEL is not set
-# CONFIG_SLOW_WORK is not set
+CONFIG_SLOW_WORK=y
+CONFIG_SLOW_WORK_DEBUG=y
 CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 CONFIG_SLABINFO=y
 CONFIG_RT_MUTEXES=y
@@ -168,9 +178,10 @@ CONFIG_MODULE_UNLOAD=y
 # CONFIG_MODULE_FORCE_UNLOAD is not set
 # CONFIG_MODVERSIONS is not set
 # CONFIG_MODULE_SRCVERSION_ALL is not set
+CONFIG_STOP_MACHINE=y
 CONFIG_BLOCK=y
-# CONFIG_LBDAF is not set
-# CONFIG_BLK_DEV_BSG is not set
+CONFIG_LBDAF=y
+CONFIG_BLK_DEV_BSG=y
 # CONFIG_BLK_DEV_INTEGRITY is not set
 CONFIG_BLK_CGROUP=y
 # CONFIG_DEBUG_BLK_CGROUP is not set
@@ -215,7 +226,7 @@ CONFIG_DEFAULT_IOSCHED="cfq"
 # CONFIG_INLINE_WRITE_UNLOCK_BH is not set
 # CONFIG_INLINE_WRITE_UNLOCK_IRQ is not set
 # CONFIG_INLINE_WRITE_UNLOCK_IRQRESTORE is not set
-# CONFIG_MUTEX_SPIN_ON_OWNER is not set
+CONFIG_MUTEX_SPIN_ON_OWNER=y
 CONFIG_FREEZER=y
 
 #
@@ -267,16 +278,15 @@ CONFIG_QUICKLIST=y
 CONFIG_MMU=y
 CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_FORCE_MAX_ZONEORDER=11
-CONFIG_MEMORY_START=0x60000000
+CONFIG_MEMORY_START=0x40000000
 CONFIG_MEMORY_SIZE=0x20000000
 # CONFIG_29BIT is not set
 CONFIG_32BIT=y
 CONFIG_PMB=y
-# CONFIG_PMB_LEGACY is not set
 CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
-# CONFIG_NUMA is not set
-CONFIG_ARCH_FLATMEM_ENABLE=y
+CONFIG_NUMA=y
+CONFIG_NODES_SHIFT=1
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
@@ -286,21 +296,23 @@ CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
 CONFIG_ARCH_MEMORY_PROBE=y
 CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
 # CONFIG_PAGE_SIZE_64KB is not set
 # CONFIG_HUGETLB_PAGE_SIZE_64K is not set
 # CONFIG_HUGETLB_PAGE_SIZE_256K is not set
-CONFIG_HUGETLB_PAGE_SIZE_1MB=y
+# CONFIG_HUGETLB_PAGE_SIZE_1MB is not set
 # CONFIG_HUGETLB_PAGE_SIZE_4MB is not set
-# CONFIG_HUGETLB_PAGE_SIZE_64MB is not set
+CONFIG_HUGETLB_PAGE_SIZE_64MB=y
 # CONFIG_HUGETLB_PAGE_SIZE_512MB is not set
 CONFIG_SELECT_MEMORY_MODEL=y
 # CONFIG_FLATMEM_MANUAL is not set
 # CONFIG_DISCONTIGMEM_MANUAL is not set
 CONFIG_SPARSEMEM_MANUAL=y
 CONFIG_SPARSEMEM=y
+CONFIG_NEED_MULTIPLE_NODES=y
 CONFIG_HAVE_MEMORY_PRESENT=y
 CONFIG_SPARSEMEM_STATIC=y
 CONFIG_MEMORY_HOTPLUG=y
@@ -313,6 +325,7 @@ CONFIG_ZONE_DMA_FLAG=0
 CONFIG_NR_QUICK=1
 CONFIG_KSM=y
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
+CONFIG_SCHED_MC=y
 
 #
 # Cache configuration
@@ -328,6 +341,7 @@ CONFIG_CPU_LITTLE_ENDIAN=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_SH_FPU=y
 CONFIG_SH_STORE_QUEUES=y
+CONFIG_SPECULATIVE_EXECUTION=y
 CONFIG_CPU_HAS_INTEVT=y
 CONFIG_CPU_HAS_SR_RB=y
 CONFIG_CPU_HAS_PTEAEX=y
@@ -372,7 +386,10 @@ CONFIG_SH_CPU_FREQ=y
 #
 # DMA support
 #
-# CONFIG_SH_DMA is not set
+CONFIG_SH_DMA=y
+# CONFIG_SH_DMA_API is not set
+CONFIG_NR_ONCHIP_DMA_CHANNELS=6
+# CONFIG_NR_DMA_CHANNELS_BOOL is not set
 
 #
 # Companion Chips
@@ -388,19 +405,21 @@ CONFIG_HEARTBEAT=y
 # Kernel features
 #
 # CONFIG_HZ_100 is not set
-CONFIG_HZ_250=y
+# CONFIG_HZ_250 is not set
 # CONFIG_HZ_300 is not set
-# CONFIG_HZ_1000 is not set
-CONFIG_HZ=250
+CONFIG_HZ_1000=y
+CONFIG_HZ=1000
 CONFIG_SCHED_HRTICK=y
 CONFIG_KEXEC=y
-# CONFIG_CRASH_DUMP is not set
 CONFIG_SECCOMP=y
-# CONFIG_SMP is not set
+CONFIG_SMP=y
+CONFIG_NR_CPUS=2
+CONFIG_HOTPLUG_CPU=y
 # CONFIG_PREEMPT_NONE is not set
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
-CONFIG_GUSA=y
+CONFIG_INTC_USERIMASK=y
+CONFIG_INTC_BALANCING=y
 
 #
 # Boot options
@@ -410,7 +429,7 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
 CONFIG_ENTRY_OFFSET=0x00001000
 CONFIG_CMDLINE_OVERWRITE=y
 # CONFIG_CMDLINE_EXTEND is not set
-CONFIG_CMDLINE="console=ttySC1,115200 earlyprintk=sh-sci.1,115200 root=/dev/sda1 nmi_debug=state,debounce rootdelay=10"
+CONFIG_CMDLINE="console=ttySC1,115200 earlyprintk=sh-sci.1,115200 root=/dev/sda1 nmi_debug=state,debounce rootdelay=5 pmb=iomap ignore_loglevel"
 
 #
 # Bus options
@@ -424,8 +443,7 @@ CONFIG_PCIEAER_INJECT=y
 CONFIG_PCIEASPM=y
 CONFIG_PCIEASPM_DEBUG=y
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_LEGACY is not set
-CONFIG_PCI_DEBUG=y
+# CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -435,7 +453,7 @@ CONFIG_PCI_DEBUG=y
 # Executable file formats
 #
 CONFIG_BINFMT_ELF=y
-# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
+CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
 # CONFIG_HAVE_AOUT is not set
 CONFIG_BINFMT_MISC=y
 
@@ -444,9 +462,11 @@ CONFIG_BINFMT_MISC=y
 #
 CONFIG_PM=y
 CONFIG_PM_DEBUG=y
+# CONFIG_PM_ADVANCED_DEBUG is not set
 CONFIG_PM_VERBOSE=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 CONFIG_CPU_IDLE=y
 CONFIG_CPU_IDLE_GOV_LADDER=y
 CONFIG_CPU_IDLE_GOV_MENU=y
@@ -456,7 +476,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -520,19 +539,14 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
+# CONFIG_NET_TCPPROBE is not set
 # CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
 # CONFIG_BT is not set
 # CONFIG_AF_RXRPC is not set
-CONFIG_WIRELESS=y
-# CONFIG_CFG80211 is not set
-# CONFIG_LIB80211 is not set
-
-#
-# CFG80211 needs to be enabled for MAC80211
-#
+# CONFIG_WIRELESS is not set
 # CONFIG_WIMAX is not set
 # CONFIG_RFKILL is not set
 # CONFIG_NET_9P is not set
@@ -553,14 +567,118 @@ CONFIG_PREVENT_FIRMWARE_BUILD=y
 # CONFIG_DEBUG_DEVRES is not set
 # CONFIG_SYS_HYPERVISOR is not set
 # CONFIG_CONNECTOR is not set
-# CONFIG_MTD is not set
+CONFIG_MTD=y
+# CONFIG_MTD_DEBUG is not set
+# CONFIG_MTD_TESTS is not set
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+# CONFIG_MTD_REDBOOT_PARTS is not set
+CONFIG_MTD_CMDLINE_PARTS=y
+# CONFIG_MTD_AR7_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+# CONFIG_MTD_CHAR is not set
+CONFIG_MTD_BLKDEVS=y
+CONFIG_MTD_BLOCK=y
+CONFIG_FTL=y
+CONFIG_NFTL=y
+# CONFIG_NFTL_RW is not set
+# CONFIG_INFTL is not set
+# CONFIG_RFD_FTL is not set
+# CONFIG_SSFDC is not set
+CONFIG_MTD_OOPS=m
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+# CONFIG_MTD_CFI_ADV_OPTIONS is not set
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+# CONFIG_MTD_CFI_I4 is not set
+# CONFIG_MTD_CFI_I8 is not set
+CONFIG_MTD_CFI_INTELEXT=m
+CONFIG_MTD_CFI_AMDSTD=m
+CONFIG_MTD_CFI_STAA=m
+CONFIG_MTD_CFI_UTIL=y
+CONFIG_MTD_RAM=y
+CONFIG_MTD_ROM=m
+CONFIG_MTD_ABSENT=m
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+# CONFIG_MTD_PHYSMAP is not set
+# CONFIG_MTD_INTEL_VR_NOR is not set
+CONFIG_MTD_PLATRAM=y
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_PMC551 is not set
+# CONFIG_MTD_DATAFLASH is not set
+# CONFIG_MTD_M25P80 is not set
+# CONFIG_MTD_SST25L is not set
+# CONFIG_MTD_SLRAM is not set
+CONFIG_MTD_PHRAM=y
+# CONFIG_MTD_MTDRAM is not set
+# CONFIG_MTD_BLOCK2MTD is not set
+
+#
+# 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_NAND=y
+# CONFIG_MTD_NAND_VERIFY_WRITE is not set
+# CONFIG_MTD_NAND_ECC_SMC is not set
+# CONFIG_MTD_NAND_MUSEUM_IDS is not set
+CONFIG_MTD_NAND_IDS=y
+# CONFIG_MTD_NAND_DISKONCHIP is not set
+# CONFIG_MTD_NAND_CAFE is not set
+# CONFIG_MTD_NAND_NANDSIM is not set
+CONFIG_MTD_NAND_PLATFORM=y
+# CONFIG_MTD_ALAUDA is not set
+CONFIG_MTD_NAND_SH_FLCTL=m
+# CONFIG_MTD_ONENAND is not set
+
+#
+# LPDDR flash memory drivers
+#
+# CONFIG_MTD_LPDDR is not set
+
+#
+# UBI - Unsorted block images
+#
+CONFIG_MTD_UBI=y
+CONFIG_MTD_UBI_WL_THRESHOLD=4096
+CONFIG_MTD_UBI_BEB_RESERVE=1
+CONFIG_MTD_UBI_GLUEBI=m
+
+#
+# UBI debugging options
+#
+# CONFIG_MTD_UBI_DEBUG is not set
 # CONFIG_PARPORT is not set
 CONFIG_BLK_DEV=y
 # CONFIG_BLK_CPQ_CISS_DA is not set
 # CONFIG_BLK_DEV_DAC960 is not set
 # CONFIG_BLK_DEV_UMEM is not set
 # CONFIG_BLK_DEV_COW_COMMON is not set
-# CONFIG_BLK_DEV_LOOP is not set
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_BLK_DEV_CRYPTOLOOP=y
 
 #
 # DRBD disabled because PROC_FS, INET or CONNECTOR not selected
@@ -575,34 +693,63 @@ CONFIG_BLK_DEV_RAM_SIZE=4096
 # CONFIG_CDROM_PKTCDVD is not set
 # CONFIG_ATA_OVER_ETH is not set
 # CONFIG_BLK_DEV_HD is not set
-CONFIG_MISC_DEVICES=y
-# CONFIG_AD525X_DPOT is not set
-# CONFIG_PHANTOM is not set
-# CONFIG_SGI_IOC4 is not set
-# CONFIG_TIFM_CORE is not set
-# CONFIG_ICS932S401 is not set
-# CONFIG_ENCLOSURE_SERVICES is not set
-# CONFIG_HP_ILO is not set
-# CONFIG_ISL29003 is not set
-# CONFIG_DS1682 is not set
-# CONFIG_TI_DAC7512 is not set
-# CONFIG_C2PORT is not set
-
-#
-# EEPROM support
-#
-# CONFIG_EEPROM_AT24 is not set
-# CONFIG_EEPROM_AT25 is not set
-# CONFIG_EEPROM_LEGACY is not set
-# CONFIG_EEPROM_MAX6875 is not set
-# CONFIG_EEPROM_93CX6 is not set
-# CONFIG_CB710_CORE is not set
+# CONFIG_MISC_DEVICES is not set
 CONFIG_HAVE_IDE=y
-# CONFIG_IDE is not set
+CONFIG_IDE=y
+
+#
+# Please see Documentation/ide/ide.txt for help/info on IDE drives
+#
+CONFIG_IDE_ATAPI=y
+# CONFIG_BLK_DEV_IDE_SATA is not set
+CONFIG_IDE_GD=y
+CONFIG_IDE_GD_ATA=y
+# CONFIG_IDE_GD_ATAPI is not set
+CONFIG_BLK_DEV_IDECD=y
+CONFIG_BLK_DEV_IDECD_VERBOSE_ERRORS=y
+# CONFIG_BLK_DEV_IDETAPE is not set
+# CONFIG_IDE_TASK_IOCTL is not set
+CONFIG_IDE_PROC_FS=y
+
+#
+# IDE chipset support/bugfixes
+#
+CONFIG_BLK_DEV_PLATFORM=y
+
+#
+# PCI IDE chipsets support
+#
+# CONFIG_BLK_DEV_GENERIC is not set
+# CONFIG_BLK_DEV_OPTI621 is not set
+# 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_CS5520 is not set
+# CONFIG_BLK_DEV_CS5530 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_IT8172 is not set
+# CONFIG_BLK_DEV_IT8213 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_SLC90E66 is not set
+# CONFIG_BLK_DEV_TRM290 is not set
+# CONFIG_BLK_DEV_VIA82CXXX is not set
+# CONFIG_BLK_DEV_TC86C001 is not set
+# CONFIG_BLK_DEV_IDEDMA is not set
 
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -616,11 +763,12 @@ CONFIG_SCSI_PROC_FS=y
 CONFIG_BLK_DEV_SD=y
 # CONFIG_CHR_DEV_ST is not set
 # CONFIG_CHR_DEV_OSST is not set
-# CONFIG_BLK_DEV_SR is not set
+CONFIG_BLK_DEV_SR=y
+# CONFIG_BLK_DEV_SR_VENDOR is not set
 # CONFIG_CHR_DEV_SG is not set
 # CONFIG_CHR_DEV_SCH is not set
-# CONFIG_SCSI_MULTI_LUN is not set
-# CONFIG_SCSI_CONSTANTS is not set
+CONFIG_SCSI_MULTI_LUN=y
+CONFIG_SCSI_CONSTANTS=y
 # CONFIG_SCSI_LOGGING is not set
 # CONFIG_SCSI_SCAN_ASYNC is not set
 CONFIG_SCSI_WAIT_SCAN=m
@@ -631,52 +779,10 @@ CONFIG_SCSI_WAIT_SCAN=m
 # CONFIG_SCSI_SPI_ATTRS is not set
 # CONFIG_SCSI_FC_ATTRS is not set
 # CONFIG_SCSI_ISCSI_ATTRS is not set
+# CONFIG_SCSI_SAS_ATTRS is not set
 # CONFIG_SCSI_SAS_LIBSAS is not set
 # CONFIG_SCSI_SRP_ATTRS is not set
-CONFIG_SCSI_LOWLEVEL=y
-# CONFIG_ISCSI_TCP is not set
-# CONFIG_SCSI_BNX2_ISCSI is not set
-# CONFIG_BE2ISCSI is not set
-# CONFIG_BLK_DEV_3W_XXXX_RAID is not set
-# CONFIG_SCSI_HPSA is not set
-# CONFIG_SCSI_3W_9XXX is not set
-# CONFIG_SCSI_3W_SAS is not set
-# CONFIG_SCSI_ACARD is not set
-# CONFIG_SCSI_AACRAID is not set
-# CONFIG_SCSI_AIC7XXX is not set
-# CONFIG_SCSI_AIC7XXX_OLD is not set
-# CONFIG_SCSI_AIC79XX is not set
-# CONFIG_SCSI_AIC94XX is not set
-# CONFIG_SCSI_MVSAS is not set
-# CONFIG_SCSI_ARCMSR is not set
-# CONFIG_MEGARAID_NEWGEN is not set
-# CONFIG_MEGARAID_LEGACY is not set
-# CONFIG_MEGARAID_SAS is not set
-# CONFIG_SCSI_MPT2SAS is not set
-# CONFIG_SCSI_HPTIOP is not set
-# CONFIG_LIBFC is not set
-# CONFIG_LIBFCOE is not set
-# CONFIG_FCOE is not set
-# CONFIG_SCSI_DMX3191D is not set
-# CONFIG_SCSI_FUTURE_DOMAIN is not set
-# CONFIG_SCSI_IPS is not set
-# CONFIG_SCSI_INITIO is not set
-# CONFIG_SCSI_INIA100 is not set
-# CONFIG_SCSI_STEX is not set
-# CONFIG_SCSI_SYM53C8XX_2 is not set
-# CONFIG_SCSI_IPR is not set
-# CONFIG_SCSI_QLOGIC_1280 is not set
-# CONFIG_SCSI_QLA_FC is not set
-# CONFIG_SCSI_QLA_ISCSI is not set
-# CONFIG_SCSI_LPFC is not set
-# CONFIG_SCSI_DC395x is not set
-# CONFIG_SCSI_DC390T is not set
-# CONFIG_SCSI_NSP32 is not set
-# CONFIG_SCSI_DEBUG is not set
-# CONFIG_SCSI_PMCRAID is not set
-# CONFIG_SCSI_PM8001 is not set
-# CONFIG_SCSI_SRP is not set
-# CONFIG_SCSI_BFA_FC is not set
+# CONFIG_SCSI_LOWLEVEL is not set
 # CONFIG_SCSI_DH is not set
 # CONFIG_SCSI_OSD_INITIATOR is not set
 CONFIG_ATA=y
@@ -719,6 +825,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -743,7 +850,17 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_WINBOND is not set
 CONFIG_PATA_PLATFORM=y
 # CONFIG_PATA_SCH is not set
-# CONFIG_MD is not set
+CONFIG_MD=y
+# CONFIG_BLK_DEV_MD is not set
+CONFIG_BLK_DEV_DM=y
+CONFIG_DM_DEBUG=y
+# CONFIG_DM_CRYPT is not set
+# CONFIG_DM_SNAPSHOT is not set
+# CONFIG_DM_MIRROR is not set
+# CONFIG_DM_ZERO is not set
+# CONFIG_DM_MULTIPATH is not set
+# CONFIG_DM_DELAY is not set
+CONFIG_DM_UEVENT=y
 # CONFIG_FUSION is not set
 
 #
@@ -820,11 +937,7 @@ CONFIG_SMSC911X=y
 # CONFIG_NETDEV_1000 is not set
 # CONFIG_NETDEV_10000 is not set
 # CONFIG_TR is not set
-CONFIG_WLAN=y
-# CONFIG_ATMEL is not set
-# CONFIG_PRISM54 is not set
-# CONFIG_USB_ZD1201 is not set
-# CONFIG_HOSTAP is not set
+# CONFIG_WLAN is not set
 
 #
 # Enable WiMAX (Networking options) to see the WiMAX drivers
@@ -838,6 +951,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -923,7 +1037,7 @@ CONFIG_VT=y
 CONFIG_CONSOLE_TRANSLATIONS=y
 CONFIG_VT_CONSOLE=y
 CONFIG_HW_CONSOLE=y
-# CONFIG_VT_HW_CONSOLE_BINDING is not set
+CONFIG_VT_HW_CONSOLE_BINDING=y
 CONFIG_DEVKMEM=y
 # CONFIG_SERIAL_NONSTANDARD is not set
 # CONFIG_NOZOMI is not set
@@ -940,9 +1054,11 @@ CONFIG_DEVKMEM=y
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
+CONFIG_SERIAL_SH_SCI_DMA=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -988,6 +1104,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -1001,15 +1118,9 @@ CONFIG_I2C_HELPER_AUTO=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 CONFIG_SPI=y
 # CONFIG_SPI_DEBUG is not set
 CONFIG_SPI_MASTER=y
@@ -1045,7 +1156,8 @@ CONFIG_WATCHDOG=y
 #
 # CONFIG_SOFT_WATCHDOG is not set
 # CONFIG_ALIM7101_WDT is not set
-# CONFIG_SH_WDT is not set
+CONFIG_SH_WDT=y
+# CONFIG_SH_WDT_MMAP is not set
 
 #
 # PCI-based Watchdog Cards
@@ -1068,6 +1180,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -1075,15 +1188,17 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_MFD_MC13783 is not set
 # CONFIG_AB3100_CORE is not set
 # CONFIG_EZX_PCAP is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_AB4500_CORE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1091,6 +1206,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 CONFIG_VIDEO_OUTPUT_CONTROL=m
@@ -1121,6 +1237,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 # CONFIG_HID_A4TECH is not set
 # CONFIG_HID_APPLE is not set
 # CONFIG_HID_BELKIN is not set
@@ -1135,12 +1252,16 @@ CONFIG_USB_HID=y
 # CONFIG_HID_KENSINGTON is not set
 # CONFIG_HID_LOGITECH is not set
 # CONFIG_HID_MICROSOFT is not set
+# CONFIG_HID_MOSART is not set
 # CONFIG_HID_MONTEREY is not set
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 # CONFIG_HID_PANTHERLORD is not set
 # CONFIG_HID_PETALYNX is not set
+# CONFIG_HID_QUANTA is not set
 # CONFIG_HID_SAMSUNG is not set
 # CONFIG_HID_SONY is not set
+# CONFIG_HID_STANTUM is not set
 # CONFIG_HID_SUNPLUS is not set
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1241,7 +1362,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1253,7 +1373,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 CONFIG_USB_GADGET=y
 # CONFIG_USB_GADGET_DEBUG is not set
 # CONFIG_USB_GADGET_DEBUG_FILES is not set
@@ -1291,6 +1410,7 @@ CONFIG_USB_GADGET_DUALSPEED=y
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 # CONFIG_USB_CDC_COMPOSITE is not set
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -1370,43 +1490,102 @@ CONFIG_RTC_DRV_MAX6900=y
 #
 CONFIG_RTC_DRV_SH=y
 # CONFIG_RTC_DRV_GENERIC is not set
-# CONFIG_DMADEVICES is not set
+CONFIG_DMADEVICES=y
+# CONFIG_DMADEVICES_DEBUG is not set
+
+#
+# DMA Devices
+#
+CONFIG_SH_DMAE=y
+CONFIG_DMA_ENGINE=y
+
+#
+# DMA Clients
+#
+# CONFIG_NET_DMA is not set
+# CONFIG_ASYNC_TX_DMA is not set
+# CONFIG_DMATEST is not set
 # CONFIG_AUXDISPLAY is not set
 CONFIG_UIO=m
 # CONFIG_UIO_CIF is not set
-# CONFIG_UIO_PDRV is not set
-# CONFIG_UIO_PDRV_GENIRQ is not set
-# CONFIG_UIO_SMX is not set
+CONFIG_UIO_PDRV=m
+CONFIG_UIO_PDRV_GENIRQ=m
 # CONFIG_UIO_AEC is not set
 # CONFIG_UIO_SERCOS3 is not set
-# CONFIG_UIO_PCI_GENERIC is not set
+CONFIG_UIO_PCI_GENERIC=m
+# CONFIG_UIO_NETX is not set
 
 #
 # TI VLYNQ
 #
-# CONFIG_STAGING is not set
+CONFIG_STAGING=y
+# CONFIG_STAGING_EXCLUDE_BUILD is not set
+# CONFIG_USB_IP_COMMON is not set
+# CONFIG_ECHO is not set
+# CONFIG_POCH is not set
+# CONFIG_COMEDI is not set
+# CONFIG_ASUS_OLED is not set
+# CONFIG_TRANZPORT is not set
+
+#
+# Qualcomm MSM Camera And Video
+#
+
+#
+# Camera Sensor Selection
+#
+# CONFIG_INPUT_GPIO is not set
+# CONFIG_POHMELFS is not set
+# CONFIG_IDE_PHISON is not set
+# CONFIG_VME_BUS is not set
+
+#
+# RAR Register Driver
+#
+# CONFIG_RAR_REGISTER is not set
+# CONFIG_IIO is not set
+CONFIG_RAMZSWAP=m
+CONFIG_RAMZSWAP_STATS=y
+# CONFIG_BATMAN_ADV is not set
+# CONFIG_STRIP is not set
+# CONFIG_DT3155 is not set
+# CONFIG_CRYSTALHD is not set
 
 #
 # File systems
 #
 CONFIG_EXT2_FS=y
-# CONFIG_EXT2_FS_XATTR is not set
+CONFIG_EXT2_FS_XATTR=y
+# CONFIG_EXT2_FS_POSIX_ACL is not set
+# CONFIG_EXT2_FS_SECURITY is not set
 # CONFIG_EXT2_FS_XIP is not set
 CONFIG_EXT3_FS=y
 # CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
 CONFIG_EXT3_FS_XATTR=y
 # CONFIG_EXT3_FS_POSIX_ACL is not set
 # CONFIG_EXT3_FS_SECURITY is not set
-# CONFIG_EXT4_FS is not set
+CONFIG_EXT4_FS=y
+CONFIG_EXT4_FS_XATTR=y
+# CONFIG_EXT4_FS_POSIX_ACL is not set
+# CONFIG_EXT4_FS_SECURITY is not set
+# CONFIG_EXT4_DEBUG is not set
 CONFIG_JBD=y
 # CONFIG_JBD_DEBUG is not set
+CONFIG_JBD2=y
+# CONFIG_JBD2_DEBUG is not set
 CONFIG_FS_MBCACHE=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
-# CONFIG_FS_POSIX_ACL is not set
-# CONFIG_XFS_FS is not set
+CONFIG_FS_POSIX_ACL=y
+CONFIG_XFS_FS=y
+# CONFIG_XFS_QUOTA is not set
+# CONFIG_XFS_POSIX_ACL is not set
+# CONFIG_XFS_RT is not set
+# CONFIG_XFS_DEBUG is not set
+# CONFIG_GFS2_FS is not set
 # CONFIG_OCFS2_FS is not set
-# CONFIG_BTRFS_FS is not set
+CONFIG_BTRFS_FS=y
+# CONFIG_BTRFS_FS_POSIX_ACL is not set
 # CONFIG_NILFS2_FS is not set
 CONFIG_FILE_LOCKING=y
 CONFIG_FSNOTIFY=y
@@ -1415,19 +1594,30 @@ CONFIG_INOTIFY=y
 CONFIG_INOTIFY_USER=y
 # CONFIG_QUOTA is not set
 # CONFIG_AUTOFS_FS is not set
-# CONFIG_AUTOFS4_FS is not set
-# CONFIG_FUSE_FS is not set
+CONFIG_AUTOFS4_FS=m
+CONFIG_FUSE_FS=y
+CONFIG_CUSE=m
 
 #
 # Caches
 #
-# CONFIG_FSCACHE is not set
+CONFIG_FSCACHE=m
+# CONFIG_FSCACHE_STATS is not set
+# CONFIG_FSCACHE_HISTOGRAM is not set
+# CONFIG_FSCACHE_DEBUG is not set
+# CONFIG_FSCACHE_OBJECT_LIST is not set
+CONFIG_CACHEFILES=m
+# CONFIG_CACHEFILES_DEBUG is not set
+# CONFIG_CACHEFILES_HISTOGRAM is not set
 
 #
 # CD-ROM/DVD Filesystems
 #
-# CONFIG_ISO9660_FS is not set
-# CONFIG_UDF_FS is not set
+CONFIG_ISO9660_FS=m
+CONFIG_JOLIET=y
+CONFIG_ZISOFS=y
+CONFIG_UDF_FS=m
+CONFIG_UDF_NLS=y
 
 #
 # DOS/FAT/NT Filesystems
@@ -1448,7 +1638,7 @@ CONFIG_TMPFS=y
 # CONFIG_TMPFS_POSIX_ACL is not set
 CONFIG_HUGETLBFS=y
 CONFIG_HUGETLB_PAGE=y
-# CONFIG_CONFIGFS_FS is not set
+CONFIG_CONFIGFS_FS=y
 CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_ADFS_FS is not set
 # CONFIG_AFFS_FS is not set
@@ -1457,30 +1647,60 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
-# CONFIG_CRAMFS is not set
-# CONFIG_SQUASHFS is not set
+CONFIG_JFFS2_FS=m
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+CONFIG_JFFS2_FS_XATTR=y
+CONFIG_JFFS2_FS_POSIX_ACL=y
+CONFIG_JFFS2_FS_SECURITY=y
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_UBIFS_FS=m
+# CONFIG_UBIFS_FS_XATTR is not set
+# CONFIG_UBIFS_FS_ADVANCED_COMPR is not set
+CONFIG_UBIFS_FS_LZO=y
+CONFIG_UBIFS_FS_ZLIB=y
+# CONFIG_UBIFS_FS_DEBUG is not set
+CONFIG_LOGFS=m
+CONFIG_CRAMFS=m
+CONFIG_SQUASHFS=m
+# CONFIG_SQUASHFS_EMBEDDED is not set
+CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE=3
 # CONFIG_VXFS_FS is not set
 # CONFIG_MINIX_FS is not set
 # CONFIG_OMFS_FS is not set
 # CONFIG_HPFS_FS is not set
 # CONFIG_QNX4FS_FS is not set
-# CONFIG_ROMFS_FS is not set
+CONFIG_ROMFS_FS=m
+CONFIG_ROMFS_BACKED_BY_BLOCK=y
+# CONFIG_ROMFS_BACKED_BY_MTD is not set
+# CONFIG_ROMFS_BACKED_BY_BOTH is not set
+CONFIG_ROMFS_ON_BLOCK=y
 # CONFIG_SYSV_FS is not set
 # CONFIG_UFS_FS is not set
 CONFIG_NETWORK_FILESYSTEMS=y
 CONFIG_NFS_FS=y
 CONFIG_NFS_V3=y
 # CONFIG_NFS_V3_ACL is not set
-# CONFIG_NFS_V4 is not set
+CONFIG_NFS_V4=y
+# CONFIG_NFS_V4_1 is not set
 CONFIG_ROOT_NFS=y
 # CONFIG_NFSD is not set
 CONFIG_LOCKD=y
 CONFIG_LOCKD_V4=y
+CONFIG_EXPORTFS=y
 CONFIG_NFS_COMMON=y
 CONFIG_SUNRPC=y
-# CONFIG_RPCSEC_GSS_KRB5 is not set
+CONFIG_SUNRPC_GSS=y
+CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1493,7 +1713,7 @@ CONFIG_SUNRPC=y
 CONFIG_MSDOS_PARTITION=y
 CONFIG_NLS=y
 CONFIG_NLS_DEFAULT="iso8859-1"
-# CONFIG_NLS_CODEPAGE_437 is not set
+CONFIG_NLS_CODEPAGE_437=y
 # CONFIG_NLS_CODEPAGE_737 is not set
 # CONFIG_NLS_CODEPAGE_775 is not set
 # CONFIG_NLS_CODEPAGE_850 is not set
@@ -1508,16 +1728,16 @@ CONFIG_NLS_DEFAULT="iso8859-1"
 # CONFIG_NLS_CODEPAGE_865 is not set
 # CONFIG_NLS_CODEPAGE_866 is not set
 # CONFIG_NLS_CODEPAGE_869 is not set
-# CONFIG_NLS_CODEPAGE_936 is not set
-# CONFIG_NLS_CODEPAGE_950 is not set
-# CONFIG_NLS_CODEPAGE_932 is not set
-# CONFIG_NLS_CODEPAGE_949 is not set
+CONFIG_NLS_CODEPAGE_936=m
+CONFIG_NLS_CODEPAGE_950=m
+CONFIG_NLS_CODEPAGE_932=y
+CONFIG_NLS_CODEPAGE_949=m
 # CONFIG_NLS_CODEPAGE_874 is not set
 # CONFIG_NLS_ISO8859_8 is not set
 # CONFIG_NLS_CODEPAGE_1250 is not set
 # CONFIG_NLS_CODEPAGE_1251 is not set
-# CONFIG_NLS_ASCII is not set
-# CONFIG_NLS_ISO8859_1 is not set
+CONFIG_NLS_ASCII=m
+CONFIG_NLS_ISO8859_1=y
 # CONFIG_NLS_ISO8859_2 is not set
 # CONFIG_NLS_ISO8859_3 is not set
 # CONFIG_NLS_ISO8859_4 is not set
@@ -1527,10 +1747,10 @@ CONFIG_NLS_DEFAULT="iso8859-1"
 # CONFIG_NLS_ISO8859_9 is not set
 # CONFIG_NLS_ISO8859_13 is not set
 # CONFIG_NLS_ISO8859_14 is not set
-# CONFIG_NLS_ISO8859_15 is not set
+CONFIG_NLS_ISO8859_15=m
 # CONFIG_NLS_KOI8_R is not set
 # CONFIG_NLS_KOI8_U is not set
-# CONFIG_NLS_UTF8 is not set
+CONFIG_NLS_UTF8=m
 # CONFIG_DLM is not set
 
 #
@@ -1538,7 +1758,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
 #
 CONFIG_TRACE_IRQFLAGS_SUPPORT=y
 CONFIG_PRINTK_TIME=y
-CONFIG_ENABLE_WARN_DEPRECATED=y
+# CONFIG_ENABLE_WARN_DEPRECATED is not set
 # CONFIG_ENABLE_MUST_CHECK is not set
 CONFIG_FRAME_WARN=1024
 CONFIG_MAGIC_SYSRQ=y
@@ -1547,7 +1767,7 @@ CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 CONFIG_DEBUG_KERNEL=y
-CONFIG_DEBUG_SHIRQ=y
+# CONFIG_DEBUG_SHIRQ is not set
 CONFIG_DETECT_SOFTLOCKUP=y
 # CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
 CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
@@ -1555,8 +1775,8 @@ CONFIG_DETECT_HUNG_TASK=y
 # CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
 CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
 CONFIG_SCHED_DEBUG=y
-# CONFIG_SCHEDSTATS is not set
-# CONFIG_TIMER_STATS is not set
+CONFIG_SCHEDSTATS=y
+CONFIG_TIMER_STATS=y
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
 CONFIG_DEBUG_PREEMPT=y
@@ -1573,24 +1793,28 @@ CONFIG_STACKTRACE=y
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
-CONFIG_DEBUG_VM=y
+# CONFIG_DEBUG_VM is not set
 # CONFIG_DEBUG_WRITECOUNT is not set
-# CONFIG_DEBUG_MEMORY_INIT is not set
+CONFIG_DEBUG_MEMORY_INIT=y
 # CONFIG_DEBUG_LIST is not set
 # CONFIG_DEBUG_SG is not set
 # CONFIG_DEBUG_NOTIFIERS is not set
 # CONFIG_DEBUG_CREDENTIALS is not set
 CONFIG_FRAME_POINTER=y
 # CONFIG_RCU_TORTURE_TEST is not set
-# CONFIG_RCU_CPU_STALL_DETECTOR is not set
+CONFIG_RCU_CPU_STALL_DETECTOR=y
+# CONFIG_RCU_CPU_STALL_VERBOSE is not set
+# CONFIG_KPROBES_SANITY_TEST is not set
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
-# CONFIG_LATENCYTOP is not set
-# CONFIG_SYSCTL_SYSCALL_CHECK is not set
+CONFIG_LATENCYTOP=y
+CONFIG_SYSCTL_SYSCALL_CHECK=y
 # CONFIG_PAGE_POISONING is not set
 CONFIG_NOP_TRACER=y
+CONFIG_HAVE_FTRACE_NMI_ENTER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1598,16 +1822,19 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
+CONFIG_FTRACE_NMI_ENTER=y
 CONFIG_EVENT_TRACING=y
 CONFIG_CONTEXT_SWITCH_TRACER=y
+CONFIG_RING_BUFFER_ALLOW_SWAP=y
 CONFIG_TRACING=y
+CONFIG_GENERIC_TRACER=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
-# CONFIG_FUNCTION_TRACER is not set
+CONFIG_FUNCTION_TRACER=y
+# CONFIG_FUNCTION_GRAPH_TRACER is not set
 # CONFIG_IRQSOFF_TRACER is not set
 # CONFIG_PREEMPT_TRACER is not set
 # CONFIG_SCHED_TRACER is not set
-# CONFIG_ENABLE_DEFAULT_TRACERS is not set
 # CONFIG_FTRACE_SYSCALLS is not set
 # CONFIG_BOOT_TRACER is not set
 CONFIG_BRANCH_PROFILE_NONE=y
@@ -1619,9 +1846,13 @@ CONFIG_KSYM_TRACER=y
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
 # CONFIG_BLK_DEV_IO_TRACE is not set
+CONFIG_DYNAMIC_FTRACE=y
+# CONFIG_FUNCTION_PROFILER is not set
+CONFIG_FTRACE_MCOUNT_RECORD=y
+# CONFIG_FTRACE_STARTUP_TEST is not set
 # CONFIG_RING_BUFFER_BENCHMARK is not set
 # CONFIG_DYNAMIC_DEBUG is not set
-# CONFIG_DMA_API_DEBUG is not set
+CONFIG_DMA_API_DEBUG=y
 # CONFIG_SAMPLES is not set
 CONFIG_HAVE_ARCH_KGDB=y
 # CONFIG_KGDB is not set
@@ -1632,6 +1863,7 @@ CONFIG_DEBUG_STACK_USAGE=y
 CONFIG_DUMP_CODE=y
 CONFIG_DWARF_UNWINDER=y
 # CONFIG_SH_NO_BSS_INIT is not set
+CONFIG_MCOUNT=y
 
 #
 # Security options
@@ -1649,10 +1881,21 @@ CONFIG_CRYPTO=y
 #
 # Crypto core or helper
 #
-# CONFIG_CRYPTO_MANAGER is not set
-# CONFIG_CRYPTO_MANAGER2 is not set
+CONFIG_CRYPTO_ALGAPI=y
+CONFIG_CRYPTO_ALGAPI2=y
+CONFIG_CRYPTO_AEAD2=y
+CONFIG_CRYPTO_BLKCIPHER=y
+CONFIG_CRYPTO_BLKCIPHER2=y
+CONFIG_CRYPTO_HASH=y
+CONFIG_CRYPTO_HASH2=y
+CONFIG_CRYPTO_RNG2=y
+CONFIG_CRYPTO_PCOMP=y
+CONFIG_CRYPTO_MANAGER=y
+CONFIG_CRYPTO_MANAGER2=y
 # CONFIG_CRYPTO_GF128MUL is not set
 # CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_PCRYPT is not set
+CONFIG_CRYPTO_WORKQUEUE=y
 # CONFIG_CRYPTO_CRYPTD is not set
 # CONFIG_CRYPTO_AUTHENC is not set
 # CONFIG_CRYPTO_TEST is not set
@@ -1667,7 +1910,7 @@ CONFIG_CRYPTO=y
 #
 # Block modes
 #
-# CONFIG_CRYPTO_CBC is not set
+CONFIG_CRYPTO_CBC=y
 # CONFIG_CRYPTO_CTR is not set
 # CONFIG_CRYPTO_CTS is not set
 # CONFIG_CRYPTO_ECB is not set
@@ -1685,10 +1928,10 @@ CONFIG_CRYPTO=y
 #
 # Digest
 #
-# CONFIG_CRYPTO_CRC32C is not set
+CONFIG_CRYPTO_CRC32C=y
 # CONFIG_CRYPTO_GHASH is not set
 # CONFIG_CRYPTO_MD4 is not set
-# CONFIG_CRYPTO_MD5 is not set
+CONFIG_CRYPTO_MD5=y
 # CONFIG_CRYPTO_MICHAEL_MIC is not set
 # CONFIG_CRYPTO_RMD128 is not set
 # CONFIG_CRYPTO_RMD160 is not set
@@ -1710,7 +1953,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_CAMELLIA is not set
 # CONFIG_CRYPTO_CAST5 is not set
 # CONFIG_CRYPTO_CAST6 is not set
-# CONFIG_CRYPTO_DES is not set
+CONFIG_CRYPTO_DES=y
 # CONFIG_CRYPTO_FCRYPT is not set
 # CONFIG_CRYPTO_KHAZAD is not set
 # CONFIG_CRYPTO_SALSA20 is not set
@@ -1722,9 +1965,9 @@ CONFIG_CRYPTO=y
 #
 # Compression
 #
-# CONFIG_CRYPTO_DEFLATE is not set
+CONFIG_CRYPTO_DEFLATE=m
 # CONFIG_CRYPTO_ZLIB is not set
-# CONFIG_CRYPTO_LZO is not set
+CONFIG_CRYPTO_LZO=m
 
 #
 # Random Number Generation
@@ -1732,6 +1975,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 CONFIG_BINARY_PRINTF=y
 
 #
@@ -1740,12 +1984,22 @@ CONFIG_BINARY_PRINTF=y
 CONFIG_BITREVERSE=y
 CONFIG_GENERIC_FIND_LAST_BIT=y
 # CONFIG_CRC_CCITT is not set
-# CONFIG_CRC16 is not set
+CONFIG_CRC16=y
 # CONFIG_CRC_T10DIF is not set
-# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC_ITU_T=m
 CONFIG_CRC32=y
 # CONFIG_CRC7 is not set
-# CONFIG_LIBCRC32C is not set
+CONFIG_LIBCRC32C=y
+CONFIG_AUDIT_GENERIC=y
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_LZO_COMPRESS=m
+CONFIG_LZO_DECOMPRESS=y
+CONFIG_DECOMPRESS_GZIP=y
+CONFIG_DECOMPRESS_BZIP2=y
+CONFIG_DECOMPRESS_LZMA=y
+CONFIG_DECOMPRESS_LZO=y
+CONFIG_BTREE=y
 CONFIG_HAS_IOMEM=y
 CONFIG_HAS_IOPORT=y
 CONFIG_HAS_DMA=y
index 43e6780..910eaec 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:30:00 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:34:06 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
 CONFIG_POSIX_MQUEUE=y
@@ -72,7 +75,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_TREE_RCU_TRACE=y
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 CONFIG_CGROUPS=y
 CONFIG_CGROUP_DEBUG=y
 CONFIG_CGROUP_NS=y
@@ -82,6 +84,7 @@ CONFIG_CGROUP_DEVICE=y
 CONFIG_CGROUP_CPUACCT=y
 CONFIG_RESOURCE_COUNTERS=y
 CONFIG_CGROUP_MEM_RES_CTLR=y
+# CONFIG_CGROUP_SCHED is not set
 CONFIG_MM_OWNER=y
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
 CONFIG_RELAY=y
@@ -96,6 +99,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -123,7 +127,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -133,7 +136,6 @@ CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_SLOB=y
 # CONFIG_MMAP_ALLOW_UNINITIALIZED is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -143,6 +145,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -162,7 +165,6 @@ CONFIG_BLOCK=y
 CONFIG_LBDAF=y
 # CONFIG_BLK_DEV_BSG is not set
 # CONFIG_BLK_DEV_INTEGRITY is not set
-# CONFIG_BLK_CGROUP is not set
 
 #
 # IO Schedulers
@@ -261,6 +263,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -276,7 +279,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 CONFIG_NOMMU_INITIAL_TRIM_EXCESS=1
 
 #
@@ -361,7 +364,6 @@ CONFIG_HZ=1000
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -400,7 +402,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -463,7 +464,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -607,6 +607,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -688,6 +689,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=4
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -799,7 +801,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XATTR is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -853,6 +854,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -881,6 +883,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -919,6 +922,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_SCHEDSTATS is not set
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -929,7 +933,6 @@ CONFIG_DEBUG_PREEMPT=y
 # CONFIG_LOCK_STAT is not set
 CONFIG_DEBUG_SPINLOCK_SLEEP=y
 # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-CONFIG_STACKTRACE=y
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
@@ -947,11 +950,11 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 # CONFIG_PAGE_POISONING is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -959,10 +962,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
@@ -975,6 +975,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1094,7 +1095,8 @@ CONFIG_CRYPTO_LZO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index ec494e3..586cb1e 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:30:41 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:37:31 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -70,11 +73,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -107,7 +105,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -124,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -245,6 +244,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -260,7 +260,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -335,7 +335,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -370,6 +370,7 @@ CONFIG_PM_SLEEP=y
 CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -377,7 +378,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -569,6 +569,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -635,6 +636,7 @@ CONFIG_USB_USBNET=y
 CONFIG_USB_NET_CDCETHER=y
 # CONFIG_USB_NET_CDC_EEM is not set
 CONFIG_USB_NET_DM9601=y
+# CONFIG_USB_NET_SMSC75XX is not set
 # CONFIG_USB_NET_SMSC95XX is not set
 # CONFIG_USB_NET_GL620A is not set
 # CONFIG_USB_NET_NET1080 is not set
@@ -644,6 +646,7 @@ CONFIG_USB_NET_DM9601=y
 # CONFIG_USB_NET_CDC_SUBSET is not set
 # CONFIG_USB_NET_ZAURUS is not set
 # CONFIG_USB_NET_INT51X1 is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -713,6 +716,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=4
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=256
@@ -739,6 +743,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -752,15 +757,9 @@ CONFIG_I2C_SH_MOBILE=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -783,6 +782,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -790,12 +790,13 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -878,6 +879,7 @@ CONFIG_SND_DRIVERS=y
 CONFIG_SND_SUPERH=y
 CONFIG_SND_USB=y
 # CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_UA101 is not set
 # CONFIG_SND_USB_CAIAQ is not set
 # CONFIG_SND_SOC is not set
 # CONFIG_SOUND_PRIME is not set
@@ -895,6 +897,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -910,14 +913,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -997,7 +1005,6 @@ CONFIG_USB_ISP116X_HCD=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1009,7 +1016,6 @@ CONFIG_USB_ISP116X_HCD=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1027,8 +1033,6 @@ CONFIG_RTC_LIB=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 # CONFIG_UIO_PDRV_GENIRQ is not set
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -1115,6 +1119,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1141,6 +1146,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1324,6 +1330,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index ee87e2b..acb3e02 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:34:15 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:41:13 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -44,9 +45,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SYSVIPC is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
 
@@ -62,7 +65,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
@@ -91,7 +93,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_VM_EVENT_COUNTERS is not set
 CONFIG_COMPAT_BRK=y
@@ -107,6 +109,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -217,6 +220,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -232,7 +236,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 CONFIG_NOMMU_INITIAL_TRIM_EXCESS=1
 
 #
@@ -301,7 +305,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -453,6 +456,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -513,6 +517,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -612,7 +617,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -664,6 +668,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -729,6 +734,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 03f4219..084fec9 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:34:37 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:42:43 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 # CONFIG_SYSVIPC is not set
 # CONFIG_POSIX_MQUEUE is not set
@@ -67,7 +70,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
@@ -76,6 +78,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -101,7 +104,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -117,6 +120,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -234,6 +238,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -249,7 +254,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -327,7 +332,6 @@ CONFIG_HZ=250
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -362,7 +366,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -562,6 +565,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -679,6 +683,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -798,7 +803,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -863,6 +867,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -885,6 +890,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1026,6 +1032,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index cfa5819..4487a23 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:44:56 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:05:15 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -12,8 +12,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -29,6 +29,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -43,9 +44,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -68,7 +71,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -102,8 +104,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
 CONFIG_SLAB=y
@@ -119,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -236,6 +240,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -251,7 +256,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -329,7 +334,6 @@ CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -366,7 +370,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -614,6 +617,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -754,6 +758,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -834,11 +839,11 @@ CONFIG_LEDS_CLASS=y
 #
 # LED drivers
 #
+CONFIG_LEDS_TRIGGERS=y
 
 #
 # LED Triggers
 #
-CONFIG_LEDS_TRIGGERS=y
 # CONFIG_LEDS_TRIGGER_TIMER is not set
 # CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
 # CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
@@ -940,6 +945,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -962,6 +968,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -997,6 +1004,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1042,6 +1050,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1167,6 +1176,7 @@ CONFIG_CRYPTO_DEFLATE=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 201283c..7c06b5c 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:46:58 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:06:03 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -12,8 +12,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -44,9 +45,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,11 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -107,8 +105,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
 CONFIG_SLAB=y
@@ -124,6 +123,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -241,6 +241,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -256,7 +257,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -334,7 +335,6 @@ CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -371,7 +371,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -620,6 +619,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -687,6 +687,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -764,6 +765,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -829,6 +831,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -844,14 +847,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -946,7 +954,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -958,7 +965,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -973,11 +979,11 @@ CONFIG_LEDS_CLASS=y
 #
 # LED drivers
 #
+CONFIG_LEDS_TRIGGERS=y
 
 #
 # LED Triggers
 #
-CONFIG_LEDS_TRIGGERS=y
 # CONFIG_LEDS_TRIGGER_TIMER is not set
 # CONFIG_LEDS_TRIGGER_HEARTBEAT is not set
 # CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
@@ -1082,6 +1088,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1163,6 +1170,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1208,6 +1216,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1333,6 +1342,7 @@ CONFIG_CRYPTO_DEFLATE=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 4a4efd2..42782e7 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 13:49:15 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:07:07 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,7 +76,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -84,6 +86,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -122,13 +125,13 @@ CONFIG_PROFILING=y
 # CONFIG_OPROFILE is not set
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -245,7 +248,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x0c000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_X2TLB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_NUMA=y
 CONFIG_NODES_SHIFT=1
@@ -256,6 +259,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -279,7 +284,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -356,7 +361,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -391,6 +396,7 @@ CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -398,7 +404,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -519,6 +524,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -676,6 +682,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -898,6 +905,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -912,6 +920,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -944,6 +953,7 @@ CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 CONFIG_HAVE_FUNCTION_TRACER=y
@@ -1059,6 +1069,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index ab371af..ebb4ac4 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:36:56 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 16:55:41 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -47,9 +48,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,11 +74,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -107,7 +105,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -116,13 +114,13 @@ CONFIG_SLAB=y
 # CONFIG_SLOB is not set
 # CONFIG_PROFILING is not set
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,8 +235,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -246,6 +244,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -261,7 +261,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -340,7 +340,7 @@ CONFIG_SECCOMP=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -376,6 +376,7 @@ CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -383,7 +384,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 # CONFIG_NET_KEY is not set
 CONFIG_INET=y
@@ -559,6 +559,7 @@ CONFIG_MTD_NAND_IDS=y
 # CONFIG_MTD_NAND_NANDSIM is not set
 # CONFIG_MTD_NAND_PLATFORM is not set
 # CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_NAND_SH_FLCTL is not set
 # CONFIG_MTD_ONENAND is not set
 
 #
@@ -600,6 +601,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ICS932S401 is not set
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_TI_DAC7512 is not set
 # CONFIG_C2PORT is not set
@@ -619,6 +621,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -726,6 +729,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -805,6 +809,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -833,6 +838,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -846,15 +852,9 @@ CONFIG_I2C_SH_MOBILE=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 CONFIG_SPI=y
 CONFIG_SPI_MASTER=y
 
@@ -885,13 +885,16 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -923,22 +926,25 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_MFD_MC13783 is not set
 # CONFIG_AB3100_CORE is not set
 # CONFIG_EZX_PCAP is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_AB4500_CORE is not set
 # CONFIG_REGULATOR is not set
 CONFIG_MEDIA_SUPPORT=y
@@ -1001,7 +1007,9 @@ CONFIG_USB_GSPCA=m
 # CONFIG_USB_M5602 is not set
 # CONFIG_USB_STV06XX is not set
 # CONFIG_USB_GL860 is not set
+# CONFIG_USB_GSPCA_BENQ is not set
 # CONFIG_USB_GSPCA_CONEX is not set
+# CONFIG_USB_GSPCA_CPIA1 is not set
 # CONFIG_USB_GSPCA_ETOMS is not set
 # CONFIG_USB_GSPCA_FINEPIX is not set
 # CONFIG_USB_GSPCA_JEILINJ is not set
@@ -1009,9 +1017,11 @@ CONFIG_USB_GSPCA=m
 # CONFIG_USB_GSPCA_MR97310A is not set
 # CONFIG_USB_GSPCA_OV519 is not set
 # CONFIG_USB_GSPCA_OV534 is not set
+# CONFIG_USB_GSPCA_OV534_9 is not set
 # CONFIG_USB_GSPCA_PAC207 is not set
 # CONFIG_USB_GSPCA_PAC7302 is not set
 # CONFIG_USB_GSPCA_PAC7311 is not set
+# CONFIG_USB_GSPCA_SN9C2028 is not set
 # CONFIG_USB_GSPCA_SN9C20X is not set
 # CONFIG_USB_GSPCA_SONIXB is not set
 # CONFIG_USB_GSPCA_SONIXJ is not set
@@ -1033,6 +1043,7 @@ CONFIG_USB_GSPCA=m
 # CONFIG_VIDEO_PVRUSB2 is not set
 # CONFIG_VIDEO_HDPVR is not set
 # CONFIG_VIDEO_EM28XX is not set
+# CONFIG_VIDEO_TLG2300 is not set
 # CONFIG_VIDEO_CX231XX is not set
 # CONFIG_VIDEO_USBVISION is not set
 # CONFIG_USB_ET61X251 is not set
@@ -1147,6 +1158,7 @@ CONFIG_SND_VERBOSE_PROCFS=y
 # CONFIG_SND_SUPERH is not set
 CONFIG_SND_USB=y
 # CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_UA101 is not set
 # CONFIG_SND_USB_CAIAQ is not set
 CONFIG_SND_SOC=m
 
@@ -1155,6 +1167,7 @@ CONFIG_SND_SOC=m
 #
 CONFIG_SND_SOC_SH4_FSI=m
 CONFIG_SND_FSI_AK4642=y
+# CONFIG_SND_FSI_DA7210 is not set
 CONFIG_SND_SOC_I2C_AND_SPI=m
 CONFIG_SND_SOC_ALL_CODECS=m
 CONFIG_SND_SOC_WM_HUBS=m
@@ -1167,6 +1180,7 @@ CONFIG_SND_SOC_AK4535=m
 CONFIG_SND_SOC_AK4642=m
 CONFIG_SND_SOC_AK4671=m
 CONFIG_SND_SOC_CS4270=m
+CONFIG_SND_SOC_DA7210=m
 CONFIG_SND_SOC_L3=m
 CONFIG_SND_SOC_PCM3008=m
 CONFIG_SND_SOC_SPDIF=m
@@ -1189,17 +1203,21 @@ CONFIG_SND_SOC_WM8753=m
 CONFIG_SND_SOC_WM8776=m
 CONFIG_SND_SOC_WM8900=m
 CONFIG_SND_SOC_WM8903=m
+CONFIG_SND_SOC_WM8904=m
 CONFIG_SND_SOC_WM8940=m
+CONFIG_SND_SOC_WM8955=m
 CONFIG_SND_SOC_WM8960=m
 CONFIG_SND_SOC_WM8961=m
 CONFIG_SND_SOC_WM8971=m
 CONFIG_SND_SOC_WM8974=m
+CONFIG_SND_SOC_WM8978=m
 CONFIG_SND_SOC_WM8988=m
 CONFIG_SND_SOC_WM8990=m
 CONFIG_SND_SOC_WM8993=m
 CONFIG_SND_SOC_WM9081=m
 CONFIG_SND_SOC_MAX9877=m
 CONFIG_SND_SOC_TPA6130A2=m
+CONFIG_SND_SOC_WM2000=m
 # CONFIG_SOUND_PRIME is not set
 CONFIG_HID_SUPPORT=y
 CONFIG_HID=y
@@ -1215,6 +1233,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 # CONFIG_HID_A4TECH is not set
 # CONFIG_HID_APPLE is not set
 # CONFIG_HID_BELKIN is not set
@@ -1229,12 +1248,16 @@ CONFIG_USB_HID=y
 # CONFIG_HID_KENSINGTON is not set
 # CONFIG_HID_LOGITECH is not set
 # CONFIG_HID_MICROSOFT is not set
+# CONFIG_HID_MOSART is not set
 # CONFIG_HID_MONTEREY is not set
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 # CONFIG_HID_PANTHERLORD is not set
 # CONFIG_HID_PETALYNX is not set
+# CONFIG_HID_QUANTA is not set
 # CONFIG_HID_SAMSUNG is not set
 # CONFIG_HID_SONY is not set
+# CONFIG_HID_STANTUM is not set
 # CONFIG_HID_SUNPLUS is not set
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1327,7 +1350,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1339,7 +1361,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 CONFIG_USB_GADGET=y
 # CONFIG_USB_GADGET_DEBUG_FILES is not set
 CONFIG_USB_GADGET_VBUS_DRAW=2
@@ -1378,6 +1399,7 @@ CONFIG_USB_G_SERIAL=m
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 # CONFIG_USB_CDC_COMPOSITE is not set
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -1401,10 +1423,7 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 # MMC/SD/SDIO Host Controller Drivers
 #
 # CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
 CONFIG_MMC_SPI=y
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MEMSTICK is not set
 # CONFIG_NEW_LEDS is not set
 # CONFIG_ACCESSIBILITY is not set
@@ -1480,8 +1499,6 @@ CONFIG_RTC_DRV_PCF8563=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -1566,6 +1583,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
 # CONFIG_UBIFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1594,6 +1612,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1786,6 +1805,7 @@ CONFIG_CRYPTO_CBC=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index b15a44e..e096c3e 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:39:10 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:00:16 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -70,7 +73,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -103,7 +105,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -120,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,6 +240,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -252,7 +256,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -329,7 +333,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -364,7 +367,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -580,6 +582,7 @@ CONFIG_IDE_PROC_FS=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -698,6 +701,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -816,7 +820,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -885,6 +888,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -907,6 +911,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1063,6 +1068,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index d1effde..84d3fac 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:39:56 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:03:26 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,7 +72,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -80,6 +82,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -106,7 +109,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -123,6 +126,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -240,6 +244,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -255,7 +260,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -333,7 +338,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -369,7 +373,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -589,6 +592,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -666,6 +670,7 @@ CONFIG_DEVKMEM=y
 # Non-8250 serial port support
 #
 # CONFIG_SERIAL_SH_SCI is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -785,7 +790,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -854,6 +858,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -868,6 +873,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1012,6 +1018,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 58533d5..f0d7e67 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:40:32 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:06:12 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -100,7 +103,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -117,6 +120,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -238,6 +242,7 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -253,7 +258,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -328,6 +333,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -343,9 +349,9 @@ CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/sda1"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 
@@ -362,7 +368,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -571,6 +576,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -714,7 +720,7 @@ CONFIG_SATA_SIL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -772,6 +778,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -807,6 +814,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_KAWETH is not set
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_PPP is not set
@@ -878,6 +886,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 # CONFIG_LEGACY_PTYS is not set
@@ -928,6 +937,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -935,6 +945,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1032,6 +1043,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1047,14 +1059,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1148,7 +1165,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1161,7 +1177,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1192,7 +1207,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -1211,6 +1225,7 @@ CONFIG_INOTIFY_USER=y
 #
 # Caches
 #
+# CONFIG_FSCACHE is not set
 
 #
 # CD-ROM/DVD Filesystems
@@ -1332,6 +1347,7 @@ CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 CONFIG_HAVE_FUNCTION_TRACER=y
@@ -1442,6 +1458,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 666fde1..562147d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:41:25 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:10:00 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,7 +76,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -84,6 +86,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -111,7 +114,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -120,7 +122,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=m
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -131,6 +132,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -250,6 +252,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -265,7 +268,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -342,7 +345,6 @@ CONFIG_HZ=250
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -358,9 +360,9 @@ CONFIG_CMDLINE="console=ttySC1,115200 mem=64M root=/dev/nfs"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -388,7 +390,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -453,7 +454,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -574,6 +574,7 @@ CONFIG_IDE_PROC_FS=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=m
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=m
 CONFIG_SCSI_DMA=y
@@ -664,7 +665,7 @@ CONFIG_SCSI_LOWLEVEL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -704,6 +705,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -751,6 +753,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -763,6 +767,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -853,6 +858,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -927,6 +933,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -934,6 +941,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1075,6 +1083,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1105,6 +1114,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1187,13 +1197,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1201,10 +1210,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1323,7 +1329,8 @@ CONFIG_CRYPTO_DEFLATE=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 35a3bee..98485ca 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 14:43:04 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:14:59 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -30,6 +30,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -44,9 +45,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -68,11 +71,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -105,7 +103,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -122,6 +120,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -240,6 +239,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -255,7 +255,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -331,7 +331,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -367,7 +366,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -620,6 +618,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -723,6 +722,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 CONFIG_LEGACY_PTYS=y
 CONFIG_LEGACY_PTY_COUNT=256
@@ -824,7 +824,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -890,6 +889,7 @@ CONFIG_JFFS2_ZLIB=y
 # CONFIG_JFFS2_LZO is not set
 CONFIG_JFFS2_RTIME=y
 # CONFIG_JFFS2_RUBIN is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -904,6 +904,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -934,6 +935,7 @@ CONFIG_DEBUG_FS=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 CONFIG_HAVE_FUNCTION_TRACER=y
@@ -1049,6 +1051,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index a3056b6..a6a9e68 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:03:45 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:17:36 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 # CONFIG_BSD_PROCESS_ACCT is not set
@@ -65,11 +68,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=17
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 CONFIG_CGROUPS=y
 # CONFIG_CGROUP_DEBUG is not set
 # CONFIG_CGROUP_NS is not set
@@ -78,6 +76,7 @@ CONFIG_CGROUPS=y
 # CONFIG_CPUSETS is not set
 # CONFIG_CGROUP_CPUACCT is not set
 # CONFIG_RESOURCE_COUNTERS is not set
+# CONFIG_CGROUP_SCHED is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
 # CONFIG_BLK_DEV_INITRD is not set
@@ -106,7 +105,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 # CONFIG_COMPAT_BRK is not set
@@ -114,21 +112,19 @@ CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_SLUB=y
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
 #
-# CONFIG_GCOV_KERNEL is not set
 # CONFIG_SLOW_WORK is not set
 CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 CONFIG_RT_MUTEXES=y
@@ -138,7 +134,6 @@ CONFIG_BLOCK=y
 CONFIG_LBDAF=y
 # CONFIG_BLK_DEV_BSG is not set
 # CONFIG_BLK_DEV_INTEGRITY is not set
-# CONFIG_BLK_CGROUP is not set
 
 #
 # IO Schedulers
@@ -235,8 +230,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -246,6 +241,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -262,7 +259,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -353,7 +350,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -390,6 +387,7 @@ CONFIG_HIBERNATION_NVS=y
 CONFIG_HIBERNATION=y
 CONFIG_PM_STD_PARTITION=""
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 CONFIG_CPU_IDLE=y
 CONFIG_CPU_IDLE_GOV_LADDER=y
 CONFIG_CPU_IDLE_GOV_MENU=y
@@ -428,6 +426,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -467,6 +466,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -491,6 +491,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -502,15 +503,9 @@ CONFIG_I2C_SH_MOBILE=y
 # Other I2C/SMBus bus drivers
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -533,6 +528,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -540,12 +536,13 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -629,8 +626,6 @@ CONFIG_RTC_DRV_SH=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -643,7 +638,6 @@ CONFIG_UIO_PDRV_GENIRQ=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -707,15 +701,12 @@ CONFIG_FRAME_WARN=1024
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_STRIP_ASM_SYMS is not set
 # CONFIG_UNUSED_SYMBOLS is not set
-CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
 # CONFIG_LATENCYTOP is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -723,13 +714,9 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
-# CONFIG_DYNAMIC_DEBUG is not set
 # CONFIG_DMA_API_DEBUG is not set
 # CONFIG_SAMPLES is not set
 CONFIG_HAVE_ARCH_KGDB=y
@@ -747,7 +734,8 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 04b841b..6f308b7 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:05:29 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:19:21 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -69,11 +72,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -112,7 +110,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -120,7 +117,6 @@ CONFIG_SLAB=y
 # CONFIG_SLUB is not set
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
@@ -131,6 +127,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -243,7 +240,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x0c000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
+# CONFIG_PMB is not set
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -253,6 +250,7 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -269,7 +267,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -344,7 +342,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -381,7 +379,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -444,7 +441,6 @@ CONFIG_DEFAULT_TCP_CONG="cubic"
 # Network testing
 #
 # CONFIG_NET_PKTGEN is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 # CONFIG_CAN is not set
 # CONFIG_IRDA is not set
@@ -585,6 +581,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -689,6 +686,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -754,6 +752,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=3
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -945,7 +944,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -957,7 +955,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -980,9 +977,6 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 # MMC/SD/SDIO Host Controller Drivers
 #
 # CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MEMSTICK is not set
 # CONFIG_NEW_LEDS is not set
 # CONFIG_ACCESSIBILITY is not set
@@ -1074,6 +1068,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1096,6 +1091,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1162,13 +1158,12 @@ CONFIG_FRAME_WARN=1024
 CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 # CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1176,10 +1171,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
 # CONFIG_DYNAMIC_DEBUG is not set
@@ -1287,7 +1279,8 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 7b24705..4327f89 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:06:28 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:20:25 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -45,9 +46,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 # CONFIG_BSD_PROCESS_ACCT is not set
@@ -64,11 +67,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=17
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 CONFIG_CGROUPS=y
 # CONFIG_CGROUP_DEBUG is not set
 # CONFIG_CGROUP_NS is not set
@@ -77,6 +75,7 @@ CONFIG_CGROUPS=y
 # CONFIG_CPUSETS is not set
 # CONFIG_CGROUP_CPUACCT is not set
 # CONFIG_RESOURCE_COUNTERS is not set
+# CONFIG_CGROUP_SCHED is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
 # CONFIG_BLK_DEV_INITRD is not set
@@ -105,7 +104,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 # CONFIG_COMPAT_BRK is not set
@@ -113,7 +111,6 @@ CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_SLUB=y
 # CONFIG_SLOB is not set
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 CONFIG_HAVE_IOREMAP_PROT=y
@@ -123,11 +120,11 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
 #
-# CONFIG_GCOV_KERNEL is not set
 # CONFIG_SLOW_WORK is not set
 CONFIG_HAVE_GENERIC_DMA_COHERENT=y
 CONFIG_RT_MUTEXES=y
@@ -137,7 +134,6 @@ CONFIG_BLOCK=y
 CONFIG_LBDAF=y
 # CONFIG_BLK_DEV_BSG is not set
 # CONFIG_BLK_DEV_INTEGRITY is not set
-# CONFIG_BLK_CGROUP is not set
 
 #
 # IO Schedulers
@@ -232,7 +228,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
+# CONFIG_PMB is not set
 CONFIG_VSYSCALL=y
 CONFIG_ARCH_FLATMEM_ENABLE=y
 CONFIG_ARCH_SPARSEMEM_ENABLE=y
@@ -242,6 +238,7 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -258,7 +255,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -347,7 +344,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -382,6 +379,7 @@ CONFIG_HIBERNATION_NVS=y
 CONFIG_HIBERNATION=y
 CONFIG_PM_STD_PARTITION=""
 # CONFIG_PM_RUNTIME is not set
+CONFIG_PM_OPS=y
 CONFIG_CPU_IDLE=y
 CONFIG_CPU_IDLE_GOV_LADDER=y
 CONFIG_CPU_IDLE_GOV_MENU=y
@@ -420,6 +418,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -459,6 +458,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -483,6 +483,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 CONFIG_I2C_SH_MOBILE=y
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -494,15 +495,9 @@ CONFIG_I2C_SH_MOBILE=y
 # Other I2C/SMBus bus drivers
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -525,6 +520,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 # CONFIG_MFD_SM501 is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -532,12 +528,13 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -621,8 +618,6 @@ CONFIG_RTC_DRV_SH=y
 CONFIG_UIO=y
 # CONFIG_UIO_PDRV is not set
 CONFIG_UIO_PDRV_GENIRQ=y
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -635,7 +630,6 @@ CONFIG_UIO_PDRV_GENIRQ=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -699,15 +693,12 @@ CONFIG_FRAME_WARN=1024
 # CONFIG_MAGIC_SYSRQ is not set
 # CONFIG_STRIP_ASM_SYMS is not set
 # CONFIG_UNUSED_SYMBOLS is not set
-CONFIG_DEBUG_FS=y
 # CONFIG_HEADERS_CHECK is not set
 # CONFIG_DEBUG_KERNEL is not set
-CONFIG_STACKTRACE=y
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
 # CONFIG_LATENCYTOP is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -715,13 +706,9 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 # CONFIG_FTRACE is not set
-# CONFIG_DYNAMIC_DEBUG is not set
 # CONFIG_DMA_API_DEBUG is not set
 # CONFIG_SAMPLES is not set
 CONFIG_HAVE_ARCH_KGDB=y
@@ -739,7 +726,8 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 8330813..e9af616 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:07:40 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:22:09 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -74,11 +77,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
 # CONFIG_RELAY is not set
@@ -112,7 +110,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 CONFIG_PERF_COUNTERS=y
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -126,13 +123,13 @@ CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 CONFIG_KPROBES=y
 CONFIG_KRETPROBES=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -246,12 +243,9 @@ CONFIG_PAGE_OFFSET=0x80000000
 CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x40000000
 CONFIG_MEMORY_SIZE=0x20000000
-# CONFIG_29BIT is not set
-CONFIG_32BIT=y
-CONFIG_PMB_ENABLE=y
+CONFIG_29BIT=y
 # CONFIG_PMB is not set
-CONFIG_PMB_FIXED=y
-# CONFIG_X2TLB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 # CONFIG_NUMA is not set
 CONFIG_ARCH_FLATMEM_ENABLE=y
@@ -262,6 +256,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -284,7 +280,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -302,6 +298,7 @@ CONFIG_CPU_LITTLE_ENDIAN=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_SH_FPU=y
 CONFIG_SH_STORE_QUEUES=y
+# CONFIG_SPECULATIVE_EXECUTION is not set
 CONFIG_CPU_HAS_INTEVT=y
 CONFIG_CPU_HAS_SR_RB=y
 CONFIG_CPU_HAS_FPU=y
@@ -311,7 +308,7 @@ CONFIG_CPU_HAS_FPU=y
 #
 # CONFIG_SH_HIGHLANDER is not set
 CONFIG_SH_SH7785LCR=y
-# CONFIG_SH_SH7785LCR_PT is not set
+CONFIG_SH_SH7785LCR_29BIT_PHYSMAPS=y
 
 #
 # Timer and clock configuration
@@ -374,7 +371,7 @@ CONFIG_SECCOMP=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-CONFIG_SPARSE_IRQ=y
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -389,9 +386,9 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_LEGACY is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 # CONFIG_PCCARD is not set
@@ -421,7 +418,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -633,6 +629,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -706,6 +703,7 @@ CONFIG_SATA_SIL=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -742,7 +740,7 @@ CONFIG_SATA_SIL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -797,6 +795,7 @@ CONFIG_R8169=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -901,6 +900,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
 # CONFIG_LEGACY_PTYS is not set
@@ -947,6 +947,7 @@ CONFIG_I2C_ALGOPCA=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -960,15 +961,9 @@ CONFIG_I2C_ALGOPCA=y
 #
 CONFIG_I2C_PCA_PLATFORM=y
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -1011,6 +1006,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 CONFIG_MFD_SM501=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -1018,12 +1014,14 @@ CONFIG_MFD_SM501=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1209,6 +1207,7 @@ CONFIG_SND_CMIPCI=y
 # CONFIG_SND_SUPERH is not set
 CONFIG_SND_USB=y
 # CONFIG_SND_USB_AUDIO is not set
+# CONFIG_SND_USB_UA101 is not set
 # CONFIG_SND_USB_CAIAQ is not set
 # CONFIG_SND_SOC is not set
 # CONFIG_SOUND_PRIME is not set
@@ -1226,6 +1225,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=m
 CONFIG_HID_APPLE=m
 CONFIG_HID_BELKIN=m
@@ -1242,14 +1242,19 @@ CONFIG_HID_KENSINGTON=m
 CONFIG_HID_LOGITECH=m
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=m
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=m
 CONFIG_HID_NTRIG=m
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=m
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=m
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=m
 CONFIG_HID_SONY=m
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=m
 CONFIG_HID_GREENASIA=m
 # CONFIG_GREENASIA_FF is not set
@@ -1273,7 +1278,6 @@ CONFIG_USB=y
 # CONFIG_USB_DEVICEFS is not set
 CONFIG_USB_DEVICE_CLASS=y
 # CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
 # CONFIG_USB_OTG is not set
 # CONFIG_USB_OTG_WHITELIST is not set
 # CONFIG_USB_OTG_BLACKLIST_HUB is not set
@@ -1351,7 +1355,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1364,7 +1367,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1390,10 +1392,7 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 CONFIG_MMC_SDHCI=m
 # CONFIG_MMC_SDHCI_PCI is not set
 CONFIG_MMC_SDHCI_PLTFM=m
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
 # CONFIG_MMC_TIFM_SD is not set
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MMC_CB710 is not set
 # CONFIG_MMC_VIA_SDMMC is not set
 # CONFIG_MEMSTICK is not set
@@ -1460,6 +1459,7 @@ CONFIG_RTC_DRV_RS5C372=y
 # CONFIG_RTC_DRV_SH is not set
 # CONFIG_RTC_DRV_GENERIC is not set
 CONFIG_DMADEVICES=y
+# CONFIG_DMADEVICES_DEBUG is not set
 
 #
 # DMA Devices
@@ -1469,10 +1469,10 @@ CONFIG_UIO=m
 # CONFIG_UIO_CIF is not set
 # CONFIG_UIO_PDRV is not set
 # CONFIG_UIO_PDRV_GENIRQ is not set
-# CONFIG_UIO_SMX is not set
 # CONFIG_UIO_AEC is not set
 # CONFIG_UIO_SERCOS3 is not set
 # CONFIG_UIO_PCI_GENERIC is not set
+# CONFIG_UIO_NETX is not set
 
 #
 # TI VLYNQ
@@ -1556,6 +1556,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1586,6 +1587,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1660,6 +1662,7 @@ CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_MEMORY_INIT is not set
 CONFIG_FRAME_POINTER=y
 # CONFIG_RCU_CPU_STALL_DETECTOR is not set
+# CONFIG_LKDTM is not set
 CONFIG_LATENCYTOP=y
 CONFIG_SYSCTL_SYSCALL_CHECK=y
 CONFIG_NOP_TRACER=y
@@ -1690,6 +1693,7 @@ CONFIG_SCHED_TRACER=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 CONFIG_STACK_TRACER=y
 CONFIG_KMEMTRACE=y
 CONFIG_WORKQUEUE_TRACER=y
@@ -1815,6 +1819,7 @@ CONFIG_CRYPTO_DES=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
+# CONFIG_VIRTUALIZATION is not set
 CONFIG_BINARY_PRINTF=y
 
 #
index f196e87..30f38c2 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:09:09 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:27:53 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,11 +76,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-# CONFIG_RT_GROUP_SCHED is not set
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -124,13 +122,13 @@ CONFIG_PROFILING=y
 # CONFIG_OPROFILE is not set
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -244,8 +242,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 # CONFIG_NUMA is not set
 CONFIG_ARCH_FLATMEM_ENABLE=y
@@ -254,6 +252,8 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -269,7 +269,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -287,6 +287,7 @@ CONFIG_CPU_LITTLE_ENDIAN=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_SH_FPU=y
 CONFIG_SH_STORE_QUEUES=y
+# CONFIG_SPECULATIVE_EXECUTION is not set
 CONFIG_CPU_HAS_INTEVT=y
 CONFIG_CPU_HAS_SR_RB=y
 CONFIG_CPU_HAS_FPU=y
@@ -344,7 +345,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -359,9 +360,9 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -387,7 +388,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -598,6 +598,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -671,6 +672,7 @@ CONFIG_SATA_SIL=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -707,7 +709,7 @@ CONFIG_SATA_SIL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -766,6 +768,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -851,6 +854,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -899,6 +903,7 @@ CONFIG_I2C_ALGOPCA=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -912,15 +917,9 @@ CONFIG_I2C_ALGOPCA=y
 #
 CONFIG_I2C_PCA_PLATFORM=y
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -943,6 +942,7 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 CONFIG_MFD_SM501=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
@@ -950,12 +950,14 @@ CONFIG_MFD_SM501=y
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -963,6 +965,7 @@ CONFIG_MFD_SM501=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1059,6 +1062,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1074,14 +1078,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1182,7 +1191,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1195,7 +1203,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 CONFIG_USB_TEST=m
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1353,6 +1360,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1383,6 +1391,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1461,6 +1470,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 CONFIG_DEBUG_PREEMPT=y
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
@@ -1509,6 +1519,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1633,6 +1644,7 @@ CONFIG_CRYPTO_DES=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 45441c0..4ba2705 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:10:09 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:32:23 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -12,8 +12,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -29,6 +29,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -43,9 +44,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 # CONFIG_SYSVIPC is not set
 # CONFIG_POSIX_MQUEUE is not set
@@ -65,7 +68,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 # CONFIG_RELAY is not set
 # CONFIG_NAMESPACES is not set
@@ -95,7 +97,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -111,6 +113,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -222,6 +225,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -237,7 +241,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -312,7 +316,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -544,6 +547,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -625,6 +629,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -719,7 +724,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -773,6 +777,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -797,6 +802,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -936,6 +942,7 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index ecf50cd..42f6bd3 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:10:45 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:08:45 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -28,6 +28,7 @@ CONFIG_SYS_SUPPORTS_NUMA=y
 CONFIG_SYS_SUPPORTS_TMU=y
 CONFIG_STACKTRACE_SUPPORT=y
 CONFIG_LOCKDEP_SUPPORT=y
+CONFIG_HAVE_LATENCYTOP_SUPPORT=y
 # CONFIG_ARCH_HAS_ILOG2_U32 is not set
 # CONFIG_ARCH_HAS_ILOG2_U64 is not set
 CONFIG_ARCH_NO_VIRT_TO_BUS=y
@@ -35,6 +36,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_COHERENT=y
 # CONFIG_DMA_NONCOHERENT is not set
+# CONFIG_NEED_DMA_MAP_STATE is not set
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -49,9 +51,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,15 +77,11 @@ CONFIG_TREE_RCU=y
 CONFIG_RCU_TRACE=y
 CONFIG_RCU_FANOUT=32
 # CONFIG_RCU_FANOUT_EXACT is not set
+# CONFIG_RCU_FAST_NO_HZ is not set
 CONFIG_TREE_RCU_TRACE=y
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-CONFIG_USER_SCHED=y
-# CONFIG_CGROUP_SCHED is not set
 CONFIG_CGROUPS=y
 # CONFIG_CGROUP_DEBUG is not set
 CONFIG_CGROUP_NS=y
@@ -92,6 +92,7 @@ CONFIG_CGROUP_CPUACCT=y
 CONFIG_RESOURCE_COUNTERS=y
 CONFIG_CGROUP_MEM_RES_CTLR=y
 # CONFIG_CGROUP_MEM_RES_CTLR_SWAP is not set
+# CONFIG_CGROUP_SCHED is not set
 CONFIG_MM_OWNER=y
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -131,7 +132,6 @@ CONFIG_PERF_USE_VMALLOC=y
 # Kernel Performance Events And Counters
 #
 CONFIG_PERF_EVENTS=y
-CONFIG_EVENT_PROFILE=y
 # CONFIG_PERF_COUNTERS is not set
 # CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
@@ -140,12 +140,10 @@ CONFIG_COMPAT_BRK=y
 # CONFIG_SLUB is not set
 CONFIG_SLOB=y
 CONFIG_PROFILING=y
-CONFIG_TRACEPOINTS=y
 CONFIG_OPROFILE=y
 CONFIG_HAVE_OPROFILE=y
 CONFIG_KPROBES=y
 CONFIG_KRETPROBES=y
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
@@ -153,6 +151,7 @@ CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_USE_GENERIC_SMP_HELPERS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -173,7 +172,6 @@ CONFIG_BLOCK=y
 CONFIG_LBDAF=y
 # CONFIG_BLK_DEV_BSG is not set
 # CONFIG_BLK_DEV_INTEGRITY is not set
-# CONFIG_BLK_CGROUP is not set
 
 #
 # IO Schedulers
@@ -269,8 +267,8 @@ CONFIG_FORCE_MAX_ZONEORDER=7
 CONFIG_MEMORY_START=0x0c000000
 CONFIG_MEMORY_SIZE=0x04000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_NUMA=y
 CONFIG_NODES_SHIFT=3
@@ -282,6 +280,8 @@ CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
 CONFIG_ARCH_MEMORY_PROBE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 # CONFIG_PAGE_SIZE_4KB is not set
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -307,7 +307,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 CONFIG_SCHED_MC=y
@@ -392,14 +392,14 @@ CONFIG_HZ_250=y
 CONFIG_HZ=250
 CONFIG_SCHED_HRTICK=y
 CONFIG_KEXEC=y
-# CONFIG_CRASH_DUMP is not set
 CONFIG_SECCOMP=y
 CONFIG_SMP=y
 CONFIG_NR_CPUS=4
+# CONFIG_HOTPLUG_CPU is not set
 # CONFIG_PREEMPT_NONE is not set
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -518,7 +518,6 @@ CONFIG_IPV6_NDISC_NODETYPE=y
 #
 # CONFIG_NET_PKTGEN is not set
 # CONFIG_NET_TCPPROBE is not set
-# CONFIG_NET_DROP_MONITOR is not set
 # CONFIG_HAMRADIO is not set
 CONFIG_CAN=m
 CONFIG_CAN_RAW=m
@@ -583,6 +582,7 @@ CONFIG_MISC_DEVICES=y
 # CONFIG_ICS932S401 is not set
 # CONFIG_ENCLOSURE_SERVICES is not set
 # CONFIG_ISL29003 is not set
+# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_DS1682 is not set
 # CONFIG_TI_DAC7512 is not set
 # CONFIG_C2PORT is not set
@@ -601,6 +601,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -693,6 +694,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -734,6 +736,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=2
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -760,6 +763,7 @@ CONFIG_I2C_HELPER_AUTO=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -773,15 +777,9 @@ CONFIG_I2C_HELPER_AUTO=y
 #
 # CONFIG_I2C_PCA_PLATFORM is not set
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 CONFIG_SPI=y
 # CONFIG_SPI_DEBUG is not set
 CONFIG_SPI_MASTER=y
@@ -838,10 +836,9 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_MFD_WM8400 is not set
-# CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_MFD_MC13783 is not set
-# CONFIG_AB3100_CORE is not set
 # CONFIG_EZX_PCAP is not set
 # CONFIG_AB4500_CORE is not set
 # CONFIG_REGULATOR is not set
@@ -933,7 +930,6 @@ CONFIG_USB_R8A66597_HCD=m
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -945,7 +941,6 @@ CONFIG_USB_R8A66597_HCD=m
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 CONFIG_USB_GADGET=y
 # CONFIG_USB_GADGET_DEBUG is not set
 # CONFIG_USB_GADGET_DEBUG_FILES is not set
@@ -983,6 +978,7 @@ CONFIG_USB_GADGET_DUALSPEED=y
 # CONFIG_USB_MIDI_GADGET is not set
 # CONFIG_USB_G_PRINTER is not set
 # CONFIG_USB_CDC_COMPOSITE is not set
+# CONFIG_USB_G_NOKIA is not set
 # CONFIG_USB_G_MULTI is not set
 
 #
@@ -1065,8 +1061,6 @@ CONFIG_RTC_DRV_SH=y
 CONFIG_UIO=m
 # CONFIG_UIO_PDRV is not set
 # CONFIG_UIO_PDRV_GENIRQ is not set
-# CONFIG_UIO_SMX is not set
-# CONFIG_UIO_SERCOS3 is not set
 
 #
 # TI VLYNQ
@@ -1145,6 +1139,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1159,6 +1154,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1246,7 +1242,6 @@ CONFIG_DEBUG_PREEMPT=y
 # CONFIG_LOCK_STAT is not set
 # CONFIG_DEBUG_SPINLOCK_SLEEP is not set
 # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
-CONFIG_STACKTRACE=y
 # CONFIG_DEBUG_KOBJECT is not set
 CONFIG_DEBUG_BUGVERBOSE=y
 # CONFIG_DEBUG_INFO is not set
@@ -1266,9 +1261,9 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
 # CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
+# CONFIG_LATENCYTOP is not set
 # CONFIG_SYSCTL_SYSCALL_CHECK is not set
 # CONFIG_PAGE_POISONING is not set
-CONFIG_NOP_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACER=y
 CONFIG_HAVE_FUNCTION_GRAPH_TRACER=y
 CONFIG_HAVE_FUNCTION_TRACE_MCOUNT_TEST=y
@@ -1276,10 +1271,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
 CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
 CONFIG_HAVE_SYSCALL_TRACEPOINTS=y
 CONFIG_RING_BUFFER=y
-CONFIG_EVENT_TRACING=y
-CONFIG_CONTEXT_SWITCH_TRACER=y
 CONFIG_RING_BUFFER_ALLOW_SWAP=y
-CONFIG_TRACING=y
 CONFIG_TRACING_SUPPORT=y
 CONFIG_FTRACE=y
 # CONFIG_FUNCTION_TRACER is not set
@@ -1292,6 +1284,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1329,6 +1322,7 @@ CONFIG_CRYPTO=y
 # CONFIG_CRYPTO_MANAGER2 is not set
 # CONFIG_CRYPTO_GF128MUL is not set
 # CONFIG_CRYPTO_NULL is not set
+# CONFIG_CRYPTO_PCRYPT is not set
 # CONFIG_CRYPTO_CRYPTD is not set
 # CONFIG_CRYPTO_AUTHENC is not set
 # CONFIG_CRYPTO_TEST is not set
@@ -1407,7 +1401,8 @@ CONFIG_CRYPTO=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
-CONFIG_BINARY_PRINTF=y
+# CONFIG_VIRTUALIZATION is not set
+# CONFIG_BINARY_PRINTF is not set
 
 #
 # Library routines
index 98352d7..513834d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:14:18 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:36:53 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 # CONFIG_SWAP is not set
 # CONFIG_SYSVIPC is not set
 # CONFIG_POSIX_MQUEUE is not set
@@ -68,7 +71,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -79,6 +81,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -105,7 +108,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
@@ -122,6 +125,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -235,6 +239,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -250,7 +255,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -335,7 +340,6 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -350,9 +354,9 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
 
@@ -569,6 +573,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -586,7 +591,7 @@ CONFIG_HAVE_IDE=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -626,6 +631,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -726,6 +732,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -764,6 +771,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -771,6 +779,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -848,7 +857,6 @@ CONFIG_EXT2_FS=y
 # CONFIG_EXT2_FS_XIP is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -907,6 +915,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -925,6 +934,7 @@ CONFIG_NETWORK_FILESYSTEMS=y
 # CONFIG_NFS_FS is not set
 # CONFIG_NFSD is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -983,6 +993,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 72982e3..14e69a2 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:14:50 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:39:19 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -31,6 +31,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 # CONFIG_SYSVIPC is not set
 # CONFIG_BSD_PROCESS_ACCT is not set
@@ -65,7 +68,6 @@ CONFIG_RCU_FANOUT=32
 # CONFIG_TREE_RCU_TRACE is not set
 # CONFIG_IKCONFIG is not set
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -76,6 +78,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -102,7 +105,7 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_COMPAT_BRK=y
@@ -119,6 +122,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -237,6 +241,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -252,7 +257,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -332,7 +337,6 @@ CONFIG_HZ=250
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -402,6 +406,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 # CONFIG_SCSI is not set
 # CONFIG_SCSI_DMA is not set
@@ -442,6 +447,7 @@ CONFIG_DEVKMEM=y
 # Non-8250 serial port support
 #
 # CONFIG_SERIAL_SH_SCI is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -552,7 +558,6 @@ CONFIG_RTC_LIB=y
 # CONFIG_EXT2_FS is not set
 # CONFIG_EXT3_FS is not set
 # CONFIG_EXT4_FS is not set
-CONFIG_EXT4_USE_FOR_EXT23=y
 # CONFIG_REISERFS_FS is not set
 # CONFIG_JFS_FS is not set
 # CONFIG_FS_POSIX_ACL is not set
@@ -609,6 +614,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BEFS_FS is not set
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -676,6 +682,7 @@ CONFIG_HAVE_ARCH_KGDB=y
 CONFIG_DEFAULT_SECURITY_DAC=y
 CONFIG_DEFAULT_SECURITY=""
 # CONFIG_CRYPTO is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 78c2570..79196b4 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:17:20 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 17:41:12 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -32,6 +32,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -46,9 +47,11 @@ CONFIG_LOCALVERSION=""
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -71,7 +74,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=16
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -82,6 +84,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 # CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -109,8 +112,9 @@ CONFIG_PERF_USE_VMALLOC=y
 #
 # Kernel Performance Events And Counters
 #
-# CONFIG_PERF_EVENTS is not set
+CONFIG_PERF_EVENTS=y
 # CONFIG_PERF_COUNTERS is not set
+# CONFIG_DEBUG_PERF_USE_VMALLOC is not set
 CONFIG_VM_EVENT_COUNTERS=y
 CONFIG_PCI_QUIRKS=y
 CONFIG_COMPAT_BRK=y
@@ -127,6 +131,7 @@ CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -245,6 +250,7 @@ CONFIG_ARCH_SPARSEMEM_DEFAULT=y
 CONFIG_MAX_ACTIVE_REGIONS=1
 CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -260,7 +266,7 @@ CONFIG_PAGEFLAGS_EXTENDED=y
 CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -345,7 +351,6 @@ CONFIG_PREEMPT_VOLUNTARY=y
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
 # CONFIG_GUSA_RB is not set
-# CONFIG_SPARSE_IRQ is not set
 
 #
 # Boot options
@@ -361,9 +366,9 @@ CONFIG_CMDLINE="console=ttySC1,38400N81 root=/dev/nfs ip=:::::eth1:autoconf rw"
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 # CONFIG_PCIEPORTBUS is not set
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-CONFIG_PCI_LEGACY=y
 # CONFIG_PCI_DEBUG is not set
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -392,7 +397,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -561,6 +565,7 @@ CONFIG_IP6_NF_RAW=m
 # CONFIG_ATM is not set
 CONFIG_STP=y
 CONFIG_BRIDGE=y
+CONFIG_BRIDGE_IGMP_SNOOPING=y
 # CONFIG_NET_DSA is not set
 CONFIG_VLAN_8021Q=y
 # CONFIG_VLAN_8021Q_GVRP is not set
@@ -749,6 +754,7 @@ CONFIG_MTD_NAND_IDS=m
 # CONFIG_MTD_NAND_CAFE is not set
 # CONFIG_MTD_NAND_PLATFORM is not set
 # CONFIG_MTD_ALAUDA is not set
+# CONFIG_MTD_NAND_SH_FLCTL is not set
 # CONFIG_MTD_ONENAND is not set
 
 #
@@ -768,10 +774,6 @@ CONFIG_BLK_DEV=y
 # CONFIG_BLK_DEV_COW_COMMON is not set
 CONFIG_BLK_DEV_LOOP=m
 CONFIG_BLK_DEV_CRYPTOLOOP=m
-
-#
-# DRBD disabled because PROC_FS, INET or CONNECTOR not selected
-#
 # CONFIG_BLK_DEV_DRBD is not set
 # CONFIG_BLK_DEV_NBD is not set
 # CONFIG_BLK_DEV_SX8 is not set
@@ -802,6 +804,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -892,7 +895,7 @@ CONFIG_SCSI_LOWLEVEL=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -951,6 +954,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -1002,6 +1006,8 @@ CONFIG_NETDEV_10000=y
 # CONFIG_CHELSIO_T1 is not set
 CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_CHELSIO_T3 is not set
+CONFIG_CHELSIO_T4_DEPENDS=y
+# CONFIG_CHELSIO_T4 is not set
 # CONFIG_ENIC is not set
 # CONFIG_IXGBE is not set
 # CONFIG_IXGB is not set
@@ -1014,6 +1020,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
 # CONFIG_MLX4_CORE is not set
 # CONFIG_TEHUTI is not set
 # CONFIG_BNX2X is not set
+# CONFIG_QLCNIC is not set
 # CONFIG_QLGE is not set
 # CONFIG_SFC is not set
 # CONFIG_BE2NET is not set
@@ -1040,6 +1047,7 @@ CONFIG_USB_NET_AX8817X=m
 CONFIG_USB_NET_CDCETHER=m
 # CONFIG_USB_NET_CDC_EEM is not set
 # CONFIG_USB_NET_DM9601 is not set
+# CONFIG_USB_NET_SMSC75XX is not set
 # CONFIG_USB_NET_SMSC95XX is not set
 # CONFIG_USB_NET_GL620A is not set
 CONFIG_USB_NET_NET1080=m
@@ -1049,6 +1057,7 @@ CONFIG_USB_NET_PLUSB=m
 # CONFIG_USB_NET_CDC_SUBSET is not set
 CONFIG_USB_NET_ZAURUS=m
 # CONFIG_USB_NET_INT51X1 is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -1136,6 +1145,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -1215,6 +1225,7 @@ CONFIG_SSB_POSSIBLE=y
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
 # CONFIG_MFD_TMIO is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 # CONFIG_MEDIA_SUPPORT is not set
 
@@ -1222,6 +1233,7 @@ CONFIG_SSB_POSSIBLE=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1372,6 +1384,7 @@ CONFIG_USB_SERIAL_ARK3116=m
 # CONFIG_USB_SERIAL_NAVMAN is not set
 CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_SERIAL_OTI6858 is not set
+# CONFIG_USB_SERIAL_QCAUX is not set
 # CONFIG_USB_SERIAL_QUALCOMM is not set
 # CONFIG_USB_SERIAL_SPCP8X5 is not set
 # CONFIG_USB_SERIAL_HP4X is not set
@@ -1385,6 +1398,7 @@ CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_SERIAL_OPTION is not set
 # CONFIG_USB_SERIAL_OMNINET is not set
 # CONFIG_USB_SERIAL_OPTICON is not set
+# CONFIG_USB_SERIAL_VIVOPAY_SERIAL is not set
 # CONFIG_USB_SERIAL_DEBUG is not set
 
 #
@@ -1397,7 +1411,6 @@ CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1410,7 +1423,6 @@ CONFIG_USB_SERIAL_PL2303=m
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1552,6 +1564,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1585,6 +1598,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 CONFIG_SMB_FS=m
 # CONFIG_SMB_NLS_DEFAULT is not set
+# CONFIG_CEPH_FS is not set
 CONFIG_CIFS=m
 # CONFIG_CIFS_STATS is not set
 CONFIG_CIFS_WEAK_PW_HASH=y
@@ -1680,6 +1694,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1726,6 +1741,7 @@ CONFIG_FTRACE=y
 CONFIG_BRANCH_PROFILE_NONE=y
 # CONFIG_PROFILE_ANNOTATED_BRANCHES is not set
 # CONFIG_PROFILE_ALL_BRANCHES is not set
+# CONFIG_KSYM_TRACER is not set
 # CONFIG_STACK_TRACER is not set
 # CONFIG_KMEMTRACE is not set
 # CONFIG_WORKQUEUE_TRACER is not set
@@ -1853,6 +1869,7 @@ CONFIG_CRYPTO_DEFLATE=y
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
 # CONFIG_CRYPTO_DEV_HIFN_795X is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 4fa03bf..17b7258 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:18:53 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:10:50 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 # CONFIG_GENERIC_GPIO is not set
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -33,6 +33,7 @@ CONFIG_ARCH_NO_VIRT_TO_BUS=y
 CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_NONCOHERENT=y
+CONFIG_NEED_DMA_MAP_STATE=y
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -48,9 +49,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -73,7 +76,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-# CONFIG_GROUP_SCHED is not set
 # CONFIG_CGROUPS is not set
 CONFIG_SYSFS_DEPRECATED=y
 CONFIG_SYSFS_DEPRECATED_V2=y
@@ -84,6 +86,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -122,13 +125,13 @@ CONFIG_PROFILING=y
 # CONFIG_OPROFILE is not set
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -244,7 +247,7 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x01f00000
 CONFIG_29BIT=y
-# CONFIG_X2TLB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 CONFIG_NUMA=y
 CONFIG_NODES_SHIFT=1
@@ -255,6 +258,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -278,7 +283,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 # CONFIG_MIGRATION is not set
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -352,7 +357,7 @@ CONFIG_KEXEC=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 CONFIG_PREEMPT=y
 CONFIG_GUSA=y
-# CONFIG_SPARSE_IRQ is not set
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -388,6 +393,7 @@ CONFIG_SUSPEND=y
 CONFIG_SUSPEND_FREEZER=y
 # CONFIG_HIBERNATION is not set
 CONFIG_PM_RUNTIME=y
+CONFIG_PM_OPS=y
 # CONFIG_CPU_IDLE is not set
 CONFIG_NET=y
 
@@ -395,7 +401,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-CONFIG_PACKET_MMAP=y
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -473,7 +478,7 @@ CONFIG_CFG80211=y
 # CONFIG_CFG80211_DEVELOPER_WARNINGS is not set
 # CONFIG_CFG80211_REG_DEBUG is not set
 CONFIG_CFG80211_DEFAULT_PS=y
-# CONFIG_WIRELESS_OLD_REGULATORY is not set
+# CONFIG_CFG80211_INTERNAL_REGDB is not set
 CONFIG_CFG80211_WEXT=y
 CONFIG_WIRELESS_EXT_SYSFS=y
 CONFIG_LIB80211=m
@@ -619,6 +624,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -709,6 +715,7 @@ CONFIG_LIBERTAS=m
 # CONFIG_LIBERTAS_USB is not set
 CONFIG_LIBERTAS_SDIO=m
 CONFIG_LIBERTAS_DEBUG=y
+# CONFIG_LIBERTAS_MESH is not set
 # CONFIG_P54_COMMON is not set
 # CONFIG_RT2X00 is not set
 # CONFIG_WL12XX is not set
@@ -730,6 +737,7 @@ CONFIG_USB_NET_AX8817X=y
 CONFIG_USB_NET_CDCETHER=y
 # CONFIG_USB_NET_CDC_EEM is not set
 # CONFIG_USB_NET_DM9601 is not set
+# CONFIG_USB_NET_SMSC75XX is not set
 # CONFIG_USB_NET_SMSC95XX is not set
 # CONFIG_USB_NET_GL620A is not set
 # CONFIG_USB_NET_NET1080 is not set
@@ -739,6 +747,7 @@ CONFIG_USB_NET_CDCETHER=y
 # CONFIG_USB_NET_CDC_SUBSET is not set
 # CONFIG_USB_NET_ZAURUS is not set
 # CONFIG_USB_NET_INT51X1 is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_PPP is not set
 # CONFIG_SLIP is not set
@@ -800,6 +809,7 @@ CONFIG_SERIAL_SH_SCI_NR_UARTS=1
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
+# CONFIG_SERIAL_TIMBERDALE is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_IPMI_HANDLER is not set
@@ -952,7 +962,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -964,7 +973,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -987,9 +995,6 @@ CONFIG_MMC_BLOCK_BOUNCE=y
 # MMC/SD/SDIO Host Controller Drivers
 #
 # CONFIG_MMC_SDHCI is not set
-# CONFIG_MMC_AT91 is not set
-# CONFIG_MMC_ATMELMCI is not set
-# CONFIG_MMC_TMIO is not set
 # CONFIG_MEMSTICK is not set
 # CONFIG_NEW_LEDS is not set
 # CONFIG_ACCESSIBILITY is not set
@@ -1079,6 +1084,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 CONFIG_CRAMFS=y
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1104,6 +1110,7 @@ CONFIG_SUNRPC=y
 # CONFIG_RPCSEC_GSS_KRB5 is not set
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1299,6 +1306,7 @@ CONFIG_CRYPTO_ARC4=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 CONFIG_CRYPTO_HW=y
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 23bda19..28bb19d 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Automatically generated make config: don't edit
-# Linux kernel version: 2.6.33-rc2
-# Mon Jan  4 15:27:53 2010
+# Linux kernel version: 2.6.34-rc5
+# Tue May 18 18:13:10 2010
 #
 CONFIG_SUPERH=y
 CONFIG_SUPERH32=y
@@ -13,8 +13,8 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
 CONFIG_GENERIC_HWEIGHT=y
 CONFIG_GENERIC_HARDIRQS=y
 CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
-CONFIG_GENERIC_IRQ_PROBE=y
 CONFIG_IRQ_PER_CPU=y
+CONFIG_SPARSE_IRQ=y
 CONFIG_GENERIC_GPIO=y
 CONFIG_GENERIC_TIME=y
 CONFIG_GENERIC_CLOCKEVENTS=y
@@ -35,6 +35,7 @@ CONFIG_ARCH_HAS_DEFAULT_IDLE=y
 CONFIG_ARCH_HAS_CPU_IDLE_WAIT=y
 CONFIG_DMA_COHERENT=y
 # CONFIG_DMA_NONCOHERENT is not set
+# CONFIG_NEED_DMA_MAP_STATE is not set
 CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
 CONFIG_CONSTRUCTORS=y
 
@@ -49,9 +50,11 @@ CONFIG_LOCALVERSION_AUTO=y
 CONFIG_HAVE_KERNEL_GZIP=y
 CONFIG_HAVE_KERNEL_BZIP2=y
 CONFIG_HAVE_KERNEL_LZMA=y
+CONFIG_HAVE_KERNEL_LZO=y
 CONFIG_KERNEL_GZIP=y
 # CONFIG_KERNEL_BZIP2 is not set
 # CONFIG_KERNEL_LZMA is not set
+# CONFIG_KERNEL_LZO is not set
 CONFIG_SWAP=y
 CONFIG_SYSVIPC=y
 CONFIG_SYSVIPC_SYSCTL=y
@@ -77,11 +80,6 @@ CONFIG_RCU_FANOUT=32
 CONFIG_IKCONFIG=y
 CONFIG_IKCONFIG_PROC=y
 CONFIG_LOG_BUF_SHIFT=14
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-# CONFIG_USER_SCHED is not set
-CONFIG_CGROUP_SCHED=y
 CONFIG_CGROUPS=y
 CONFIG_CGROUP_DEBUG=y
 CONFIG_CGROUP_NS=y
@@ -93,6 +91,9 @@ CONFIG_CGROUP_CPUACCT=y
 CONFIG_RESOURCE_COUNTERS=y
 CONFIG_CGROUP_MEM_RES_CTLR=y
 CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y
+CONFIG_CGROUP_SCHED=y
+CONFIG_FAIR_GROUP_SCHED=y
+CONFIG_RT_GROUP_SCHED=y
 CONFIG_MM_OWNER=y
 # CONFIG_SYSFS_DEPRECATED_V2 is not set
 # CONFIG_RELAY is not set
@@ -102,6 +103,7 @@ CONFIG_INITRAMFS_SOURCE=""
 CONFIG_RD_GZIP=y
 # CONFIG_RD_BZIP2 is not set
 # CONFIG_RD_LZMA is not set
+# CONFIG_RD_LZO is not set
 CONFIG_CC_OPTIMIZE_FOR_SIZE=y
 CONFIG_SYSCTL=y
 CONFIG_ANON_INODES=y
@@ -142,13 +144,13 @@ CONFIG_PROFILING=y
 # CONFIG_OPROFILE is not set
 CONFIG_HAVE_OPROFILE=y
 # CONFIG_KPROBES is not set
-CONFIG_HAVE_IOREMAP_PROT=y
 CONFIG_HAVE_KPROBES=y
 CONFIG_HAVE_KRETPROBES=y
 CONFIG_HAVE_ARCH_TRACEHOOK=y
 CONFIG_HAVE_DMA_ATTRS=y
 CONFIG_HAVE_CLK=y
 CONFIG_HAVE_DMA_API_DEBUG=y
+CONFIG_HAVE_HW_BREAKPOINT=y
 
 #
 # GCOV-based kernel profiling
@@ -169,7 +171,6 @@ CONFIG_BLOCK=y
 CONFIG_LBDAF=y
 # CONFIG_BLK_DEV_BSG is not set
 # CONFIG_BLK_DEV_INTEGRITY is not set
-# CONFIG_BLK_CGROUP is not set
 
 #
 # IO Schedulers
@@ -265,8 +266,8 @@ CONFIG_FORCE_MAX_ZONEORDER=11
 CONFIG_MEMORY_START=0x08000000
 CONFIG_MEMORY_SIZE=0x08000000
 CONFIG_29BIT=y
-# CONFIG_PMB_ENABLE is not set
-# CONFIG_X2TLB is not set
+# CONFIG_PMB is not set
+CONFIG_X2TLB=y
 CONFIG_VSYSCALL=y
 # CONFIG_NUMA is not set
 CONFIG_ARCH_FLATMEM_ENABLE=y
@@ -277,6 +278,8 @@ CONFIG_ARCH_POPULATES_NODE_MAP=y
 CONFIG_ARCH_SELECT_MEMORY_MODEL=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
 CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
+CONFIG_IOREMAP_FIXED=y
+CONFIG_UNCACHED_MAPPING=y
 CONFIG_PAGE_SIZE_4KB=y
 # CONFIG_PAGE_SIZE_8KB is not set
 # CONFIG_PAGE_SIZE_16KB is not set
@@ -299,7 +302,7 @@ CONFIG_SPLIT_PTLOCK_CPUS=4
 CONFIG_MIGRATION=y
 # CONFIG_PHYS_ADDR_T_64BIT is not set
 CONFIG_ZONE_DMA_FLAG=0
-CONFIG_NR_QUICK=2
+CONFIG_NR_QUICK=1
 # CONFIG_KSM is not set
 CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
 
@@ -317,6 +320,7 @@ CONFIG_CPU_LITTLE_ENDIAN=y
 # CONFIG_CPU_BIG_ENDIAN is not set
 CONFIG_SH_FPU=y
 CONFIG_SH_STORE_QUEUES=y
+# CONFIG_SPECULATIVE_EXECUTION is not set
 CONFIG_CPU_HAS_INTEVT=y
 CONFIG_CPU_HAS_SR_RB=y
 CONFIG_CPU_HAS_PTEAEX=y
@@ -325,15 +329,14 @@ CONFIG_CPU_HAS_FPU=y
 #
 # Board support
 #
+# CONFIG_SH_SDK7786 is not set
 CONFIG_SH_URQUELL=y
 
 #
 # Timer and clock configuration
 #
 CONFIG_SH_TIMER_TMU=y
-CONFIG_SH_PCLK_FREQ=33333333
 CONFIG_SH_CLK_CPG=y
-CONFIG_SH_CLK_CPG_LEGACY=y
 CONFIG_TICK_ONESHOT=y
 # CONFIG_NO_HZ is not set
 CONFIG_HIGH_RES_TIMERS=y
@@ -376,7 +379,7 @@ CONFIG_PREEMPT_NONE=y
 # CONFIG_PREEMPT_VOLUNTARY is not set
 # CONFIG_PREEMPT is not set
 CONFIG_GUSA=y
-CONFIG_SPARSE_IRQ=y
+# CONFIG_INTC_USERIMASK is not set
 
 #
 # Boot options
@@ -391,6 +394,7 @@ CONFIG_ENTRY_OFFSET=0x00001000
 # Bus options
 #
 CONFIG_PCI=y
+CONFIG_PCI_DOMAINS=y
 CONFIG_PCIEPORTBUS=y
 CONFIG_PCIEAER=y
 # CONFIG_PCIE_ECRC is not set
@@ -398,7 +402,6 @@ CONFIG_PCIEAER=y
 CONFIG_PCIEASPM=y
 CONFIG_PCIEASPM_DEBUG=y
 # CONFIG_ARCH_SUPPORTS_MSI is not set
-# CONFIG_PCI_LEGACY is not set
 CONFIG_PCI_DEBUG=y
 # CONFIG_PCI_STUB is not set
 # CONFIG_PCI_IOV is not set
@@ -428,7 +431,6 @@ CONFIG_NET=y
 # Networking options
 #
 CONFIG_PACKET=y
-# CONFIG_PACKET_MMAP is not set
 CONFIG_UNIX=y
 CONFIG_XFRM=y
 # CONFIG_XFRM_USER is not set
@@ -639,6 +641,7 @@ CONFIG_HAVE_IDE=y
 #
 # SCSI device support
 #
+CONFIG_SCSI_MOD=y
 # CONFIG_RAID_ATTRS is not set
 CONFIG_SCSI=y
 CONFIG_SCSI_DMA=y
@@ -712,6 +715,7 @@ CONFIG_ATA_SFF=y
 # CONFIG_PATA_IT821X is not set
 # CONFIG_PATA_IT8213 is not set
 # CONFIG_PATA_JMICRON is not set
+# CONFIG_PATA_LEGACY is not set
 # CONFIG_PATA_TRIFLEX is not set
 # CONFIG_PATA_MARVELL is not set
 # CONFIG_PATA_MPIIX is not set
@@ -748,7 +752,7 @@ CONFIG_ATA_SFF=y
 #
 
 #
-# See the help texts for more information.
+# The newer stack is recommended.
 #
 # CONFIG_FIREWIRE is not set
 # CONFIG_IEEE1394 is not set
@@ -807,6 +811,7 @@ CONFIG_NET_PCI=y
 # CONFIG_PCNET32 is not set
 # CONFIG_AMD8111_ETH is not set
 # CONFIG_ADAPTEC_STARFIRE is not set
+# CONFIG_KSZ884X_PCI is not set
 # CONFIG_B44 is not set
 # CONFIG_FORCEDETH is not set
 # CONFIG_E100 is not set
@@ -871,6 +876,7 @@ CONFIG_WLAN=y
 # CONFIG_USB_PEGASUS is not set
 # CONFIG_USB_RTL8150 is not set
 # CONFIG_USB_USBNET is not set
+# CONFIG_USB_IPHETH is not set
 # CONFIG_WAN is not set
 # CONFIG_FDDI is not set
 # CONFIG_HIPPI is not set
@@ -958,6 +964,7 @@ CONFIG_SERIAL_SH_SCI_CONSOLE=y
 CONFIG_SERIAL_CORE=y
 CONFIG_SERIAL_CORE_CONSOLE=y
 # CONFIG_SERIAL_JSM is not set
+# CONFIG_SERIAL_TIMBERDALE is not set
 CONFIG_UNIX98_PTYS=y
 # CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
 CONFIG_LEGACY_PTYS=y
@@ -1007,6 +1014,7 @@ CONFIG_I2C_ALGOPCA=y
 # CONFIG_I2C_OCORES is not set
 # CONFIG_I2C_SH_MOBILE is not set
 # CONFIG_I2C_SIMTEC is not set
+# CONFIG_I2C_XILINX is not set
 
 #
 # External I2C/SMBus adapter drivers
@@ -1020,15 +1028,9 @@ CONFIG_I2C_ALGOPCA=y
 #
 CONFIG_I2C_PCA_PLATFORM=y
 # CONFIG_I2C_STUB is not set
-
-#
-# Miscellaneous I2C Chip support
-#
-# CONFIG_SENSORS_TSL2550 is not set
 # CONFIG_I2C_DEBUG_CORE is not set
 # CONFIG_I2C_DEBUG_ALGO is not set
 # CONFIG_I2C_DEBUG_BUS is not set
-# CONFIG_I2C_DEBUG_CHIP is not set
 # CONFIG_SPI is not set
 
 #
@@ -1043,13 +1045,17 @@ CONFIG_GPIOLIB=y
 #
 # Memory mapped GPIO expanders:
 #
+# CONFIG_GPIO_IT8761E is not set
+# CONFIG_GPIO_SCH is not set
 
 #
 # I2C GPIO expanders:
 #
+# CONFIG_GPIO_MAX7300 is not set
 # CONFIG_GPIO_MAX732X is not set
 # CONFIG_GPIO_PCA953X is not set
 # CONFIG_GPIO_PCF857X is not set
+# CONFIG_GPIO_ADP5588 is not set
 
 #
 # PCI GPIO expanders:
@@ -1082,10 +1088,11 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_ADM1029 is not set
 # CONFIG_SENSORS_ADM1031 is not set
 # CONFIG_SENSORS_ADM9240 is not set
+# CONFIG_SENSORS_ADT7411 is not set
 # CONFIG_SENSORS_ADT7462 is not set
 # CONFIG_SENSORS_ADT7470 is not set
-# CONFIG_SENSORS_ADT7473 is not set
 # CONFIG_SENSORS_ADT7475 is not set
+# CONFIG_SENSORS_ASC7621 is not set
 # CONFIG_SENSORS_ATXP1 is not set
 # CONFIG_SENSORS_DS1621 is not set
 # CONFIG_SENSORS_I5K_AMB is not set
@@ -1123,6 +1130,7 @@ CONFIG_HWMON=y
 # CONFIG_SENSORS_SMSC47M192 is not set
 # CONFIG_SENSORS_SMSC47B397 is not set
 # CONFIG_SENSORS_ADS7828 is not set
+# CONFIG_SENSORS_AMC6821 is not set
 # CONFIG_SENSORS_THMC50 is not set
 # CONFIG_SENSORS_TMP401 is not set
 # CONFIG_SENSORS_TMP421 is not set
@@ -1151,21 +1159,26 @@ CONFIG_SSB_POSSIBLE=y
 # Multifunction device drivers
 #
 # CONFIG_MFD_CORE is not set
+# CONFIG_MFD_88PM860X is not set
 CONFIG_MFD_SM501=y
 # CONFIG_MFD_SM501_GPIO is not set
 # CONFIG_MFD_SH_MOBILE_SDHI is not set
 # CONFIG_HTC_PASIC3 is not set
+# CONFIG_HTC_I2CPLD is not set
 # CONFIG_TPS65010 is not set
 # CONFIG_TWL4030_CORE is not set
 # CONFIG_MFD_TMIO is not set
 # CONFIG_PMIC_DA903X is not set
 # CONFIG_PMIC_ADP5520 is not set
+# CONFIG_MFD_MAX8925 is not set
 # CONFIG_MFD_WM8400 is not set
 # CONFIG_MFD_WM831X is not set
 # CONFIG_MFD_WM8350_I2C is not set
+# CONFIG_MFD_WM8994 is not set
 # CONFIG_MFD_PCF50633 is not set
 # CONFIG_AB3100_CORE is not set
-# CONFIG_MFD_88PM8607 is not set
+# CONFIG_MFD_TIMBERDALE is not set
+# CONFIG_LPC_SCH is not set
 # CONFIG_REGULATOR is not set
 CONFIG_MEDIA_SUPPORT=y
 
@@ -1187,6 +1200,7 @@ CONFIG_VIDEO_IR=y
 # Graphics support
 #
 CONFIG_VGA_ARB=y
+CONFIG_VGA_ARB_MAX_GPUS=16
 # CONFIG_DRM is not set
 # CONFIG_VGASTATE is not set
 # CONFIG_VIDEO_OUTPUT_CONTROL is not set
@@ -1283,6 +1297,7 @@ CONFIG_USB_HID=y
 #
 # Special HID drivers
 #
+# CONFIG_HID_3M_PCT is not set
 CONFIG_HID_A4TECH=y
 CONFIG_HID_APPLE=y
 CONFIG_HID_BELKIN=y
@@ -1298,14 +1313,19 @@ CONFIG_HID_GYRATION=y
 CONFIG_HID_LOGITECH=y
 # CONFIG_LOGITECH_FF is not set
 # CONFIG_LOGIRUMBLEPAD2_FF is not set
+# CONFIG_LOGIG940_FF is not set
 CONFIG_HID_MICROSOFT=y
+# CONFIG_HID_MOSART is not set
 CONFIG_HID_MONTEREY=y
 # CONFIG_HID_NTRIG is not set
+# CONFIG_HID_ORTEK is not set
 CONFIG_HID_PANTHERLORD=y
 # CONFIG_PANTHERLORD_FF is not set
 CONFIG_HID_PETALYNX=y
+# CONFIG_HID_QUANTA is not set
 CONFIG_HID_SAMSUNG=y
 CONFIG_HID_SONY=y
+# CONFIG_HID_STANTUM is not set
 CONFIG_HID_SUNPLUS=y
 # CONFIG_HID_GREENASIA is not set
 # CONFIG_HID_SMARTJOYPLUS is not set
@@ -1326,7 +1346,6 @@ CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
 CONFIG_USB_DEVICEFS=y
 CONFIG_USB_DEVICE_CLASS=y
 # CONFIG_USB_DYNAMIC_MINORS is not set
-# CONFIG_USB_SUSPEND is not set
 # CONFIG_USB_OTG is not set
 # CONFIG_USB_OTG_WHITELIST is not set
 # CONFIG_USB_OTG_BLACKLIST_HUB is not set
@@ -1405,7 +1424,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_RIO500 is not set
 # CONFIG_USB_LEGOTOWER is not set
 # CONFIG_USB_LCD is not set
-# CONFIG_USB_BERRY_CHARGE is not set
 # CONFIG_USB_LED is not set
 # CONFIG_USB_CYPRESS_CY7C63 is not set
 # CONFIG_USB_CYTHERM is not set
@@ -1417,7 +1435,6 @@ CONFIG_USB_STORAGE=y
 # CONFIG_USB_IOWARRIOR is not set
 # CONFIG_USB_TEST is not set
 # CONFIG_USB_ISIGHTFW is not set
-# CONFIG_USB_VST is not set
 # CONFIG_USB_GADGET is not set
 
 #
@@ -1584,6 +1601,7 @@ CONFIG_MISC_FILESYSTEMS=y
 # CONFIG_BFS_FS is not set
 # CONFIG_EFS_FS is not set
 # CONFIG_JFFS2_FS is not set
+# CONFIG_LOGFS is not set
 # CONFIG_CRAMFS is not set
 # CONFIG_SQUASHFS is not set
 # CONFIG_VXFS_FS is not set
@@ -1610,6 +1628,7 @@ CONFIG_SUNRPC_GSS=y
 CONFIG_RPCSEC_GSS_KRB5=y
 # CONFIG_RPCSEC_GSS_SPKM3 is not set
 # CONFIG_SMB_FS is not set
+# CONFIG_CEPH_FS is not set
 # CONFIG_CIFS is not set
 # CONFIG_NCP_FS is not set
 # CONFIG_CODA_FS is not set
@@ -1688,6 +1707,7 @@ CONFIG_SCHED_DEBUG=y
 # CONFIG_TIMER_STATS is not set
 # CONFIG_DEBUG_OBJECTS is not set
 # CONFIG_DEBUG_SLAB is not set
+# CONFIG_DEBUG_KMEMLEAK is not set
 # CONFIG_DEBUG_RT_MUTEXES is not set
 # CONFIG_RT_MUTEX_TESTER is not set
 # CONFIG_DEBUG_SPINLOCK is not set
@@ -1713,6 +1733,7 @@ CONFIG_FRAME_POINTER=y
 # CONFIG_BACKTRACE_SELF_TEST is not set
 # CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
 # CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
+# CONFIG_LKDTM is not set
 # CONFIG_FAULT_INJECTION is not set
 # CONFIG_LATENCYTOP is not set
 CONFIG_SYSCTL_SYSCALL_CHECK=y
@@ -1846,6 +1867,7 @@ CONFIG_CRYPTO_DES=y
 #
 # CONFIG_CRYPTO_ANSI_CPRNG is not set
 # CONFIG_CRYPTO_HW is not set
+# CONFIG_VIRTUALIZATION is not set
 # CONFIG_BINARY_PRINTF is not set
 
 #
index 275a448..c798312 100644 (file)
@@ -13,7 +13,7 @@
 
 #define ATOMIC_INIT(i) ( (atomic_t) { (i) } )
 
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 #define atomic_set(v,i)                ((v)->counter = (i))
 
 #if defined(CONFIG_GUSA_RB)
index 02df18e..e461d67 100644 (file)
@@ -38,14 +38,10 @@ struct cache_info {
         * 2. those in the physical page number.
         */
        unsigned int alias_mask;
-
        unsigned int n_aliases;         /* Number of aliases */
 
        unsigned long flags;
 };
-
-int __init detect_cpu_and_cache_system(void);
-
 #endif /* __ASSEMBLY__ */
 #endif /* __KERNEL__ */
 #endif /* __ASM_SH_CACHE_H */
diff --git a/arch/sh/include/asm/clkdev.h b/arch/sh/include/asm/clkdev.h
new file mode 100644 (file)
index 0000000..5645f35
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ *  arch/sh/include/asm/clkdev.h
+ *
+ * Cloned from arch/arm/include/asm/clkdev.h:
+ *
+ *  Copyright (C) 2008 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Helper for the clk API to assist looking up a struct clk.
+ */
+#ifndef __ASM_CLKDEV_H
+#define __ASM_CLKDEV_H
+
+struct clk;
+
+struct clk_lookup {
+       struct list_head        node;
+       const char              *dev_id;
+       const char              *con_id;
+       struct clk              *clk;
+};
+
+struct clk_lookup *clkdev_alloc(struct clk *clk, const char *con_id,
+       const char *dev_fmt, ...);
+
+void clkdev_add(struct clk_lookup *cl);
+void clkdev_drop(struct clk_lookup *cl);
+
+void clkdev_add_table(struct clk_lookup *, size_t);
+int clk_add_alias(const char *, const char *, char *, struct device *);
+
+#endif
index 11da4c5..803d4c7 100644 (file)
 #ifndef __ASM_SH_CLOCK_H
 #define __ASM_SH_CLOCK_H
 
-#include <linux/list.h>
-#include <linux/seq_file.h>
-#include <linux/cpufreq.h>
-#include <linux/clk.h>
-#include <linux/err.h>
-
-struct clk;
-
-struct clk_ops {
-       void (*init)(struct clk *clk);
-       int (*enable)(struct clk *clk);
-       void (*disable)(struct clk *clk);
-       unsigned long (*recalc)(struct clk *clk);
-       int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
-       int (*set_parent)(struct clk *clk, struct clk *parent);
-       long (*round_rate)(struct clk *clk, unsigned long rate);
-};
-
-struct clk {
-       struct list_head        node;
-       const char              *name;
-       int                     id;
-       struct module           *owner;
-
-       struct clk              *parent;
-       struct clk_ops          *ops;
-
-       struct list_head        children;
-       struct list_head        sibling;        /* node for children */
-
-       int                     usecount;
-
-       unsigned long           rate;
-       unsigned long           flags;
-
-       void __iomem            *enable_reg;
-       unsigned int            enable_bit;
-
-       unsigned long           arch_flags;
-       void                    *priv;
-       struct dentry           *dentry;
-       struct cpufreq_frequency_table *freq_table;
-};
-
-struct clk_lookup {
-       struct list_head        node;
-       const char              *dev_id;
-       const char              *con_id;
-       struct clk              *clk;
-};
-
-#define CLK_ENABLE_ON_INIT     (1 << 0)
+#include <linux/sh_clk.h>
 
 /* Should be defined by processor-specific code */
 void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
 int __init arch_clk_init(void);
 
-/* arch/sh/kernel/cpu/clock.c */
-int clk_init(void);
-unsigned long followparent_recalc(struct clk *);
-void recalculate_root_clocks(void);
-void propagate_rate(struct clk *);
-int clk_reparent(struct clk *child, struct clk *parent);
-int clk_register(struct clk *);
-void clk_unregister(struct clk *);
-
 /* arch/sh/kernel/cpu/clock-cpg.c */
 int __init __deprecated cpg_clk_init(void);
 
-/* the exported API, in addition to clk_set_rate */
-/**
- * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
- * @clk: clock source
- * @rate: desired clock rate in Hz
- * @algo_id: algorithm id to be passed down to ops->set_rate
- *
- * Returns success (0) or negative errno.
- */
-int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
-
-enum clk_sh_algo_id {
-       NO_CHANGE = 0,
-
-       IUS_N1_N1,
-       IUS_322,
-       IUS_522,
-       IUS_N11,
-
-       SB_N1,
-
-       SB3_N1,
-       SB3_32,
-       SB3_43,
-       SB3_54,
-
-       BP_N1,
-
-       IP_N1,
-};
-
-struct clk_div_mult_table {
-       unsigned int *divisors;
-       unsigned int nr_divisors;
-       unsigned int *multipliers;
-       unsigned int nr_multipliers;
-};
-
-struct cpufreq_frequency_table;
-void clk_rate_table_build(struct clk *clk,
-                         struct cpufreq_frequency_table *freq_table,
-                         int nr_freqs,
-                         struct clk_div_mult_table *src_table,
-                         unsigned long *bitmap);
-
-long clk_rate_table_round(struct clk *clk,
-                         struct cpufreq_frequency_table *freq_table,
-                         unsigned long rate);
-
-int clk_rate_table_find(struct clk *clk,
-                       struct cpufreq_frequency_table *freq_table,
-                       unsigned long rate);
-
-#define SH_CLK_MSTP32(_name, _id, _parent, _enable_reg,        \
-           _enable_bit, _flags)                        \
-{                                                      \
-       .name           = _name,                        \
-       .id             = _id,                          \
-       .parent         = _parent,                      \
-       .enable_reg     = (void __iomem *)_enable_reg,  \
-       .enable_bit     = _enable_bit,                  \
-       .flags          = _flags,                       \
-}
-
-int sh_clk_mstp32_register(struct clk *clks, int nr);
-
-#define SH_CLK_DIV4(_name, _parent, _reg, _shift, _div_bitmap, _flags) \
-{                                                                      \
-       .name = _name,                                                  \
-       .parent = _parent,                                              \
-       .enable_reg = (void __iomem *)_reg,                             \
-       .enable_bit = _shift,                                           \
-       .arch_flags = _div_bitmap,                                      \
-       .flags = _flags,                                                \
-}
-
-struct clk_div4_table {
-       struct clk_div_mult_table *div_mult_table;
-       void (*kick)(struct clk *clk);
-};
-
-int sh_clk_div4_register(struct clk *clks, int nr,
-                        struct clk_div4_table *table);
-int sh_clk_div4_enable_register(struct clk *clks, int nr,
-                        struct clk_div4_table *table);
-int sh_clk_div4_reparent_register(struct clk *clks, int nr,
-                        struct clk_div4_table *table);
-
-#define SH_CLK_DIV6(_name, _parent, _reg, _flags)      \
-{                                                      \
-       .name = _name,                                  \
-       .parent = _parent,                              \
-       .enable_reg = (void __iomem *)_reg,             \
-       .flags = _flags,                                \
-}
-
-int sh_clk_div6_register(struct clk *clks, int nr);
+/* arch/sh/kernel/cpu/clock.c */
+int clk_init(void);
 
 #endif /* __ASM_SH_CLOCK_H */
index bf2f30c..2a02b61 100644 (file)
 #ifndef ASM_DMAENGINE_H
 #define ASM_DMAENGINE_H
 
-#include <linux/dmaengine.h>
-#include <linux/list.h>
+#include <linux/sh_dma.h>
 
-#include <asm/dma-register.h>
-
-#define SH_DMAC_MAX_CHANNELS   6
-
-enum sh_dmae_slave_chan_id {
+enum {
        SHDMA_SLAVE_SCIF0_TX,
        SHDMA_SLAVE_SCIF0_RX,
        SHDMA_SLAVE_SCIF1_TX,
@@ -34,60 +29,6 @@ enum sh_dmae_slave_chan_id {
        SHDMA_SLAVE_SIUA_RX,
        SHDMA_SLAVE_SIUB_TX,
        SHDMA_SLAVE_SIUB_RX,
-       SHDMA_SLAVE_NUMBER,     /* Must stay last */
-};
-
-struct sh_dmae_slave_config {
-       enum sh_dmae_slave_chan_id      slave_id;
-       dma_addr_t                      addr;
-       u32                             chcr;
-       char                            mid_rid;
-};
-
-struct sh_dmae_channel {
-       unsigned int    offset;
-       unsigned int    dmars;
-       unsigned int    dmars_bit;
-};
-
-struct sh_dmae_pdata {
-       struct sh_dmae_slave_config *slave;
-       int slave_num;
-       struct sh_dmae_channel *channel;
-       int channel_num;
-       unsigned int ts_low_shift;
-       unsigned int ts_low_mask;
-       unsigned int ts_high_shift;
-       unsigned int ts_high_mask;
-       unsigned int *ts_shift;
-       int ts_shift_num;
-       u16 dmaor_init;
-};
-
-struct device;
-
-/* Used by slave DMA clients to request DMA to/from a specific peripheral */
-struct sh_dmae_slave {
-       enum sh_dmae_slave_chan_id      slave_id; /* Set by the platform */
-       struct device                   *dma_dev; /* Set by the platform */
-       struct sh_dmae_slave_config     *config;  /* Set by the driver */
-};
-
-struct sh_dmae_regs {
-       u32 sar; /* SAR / source address */
-       u32 dar; /* DAR / destination address */
-       u32 tcr; /* TCR / transfer count */
-};
-
-struct sh_desc {
-       struct sh_dmae_regs hw;
-       struct list_head node;
-       struct dma_async_tx_descriptor async_tx;
-       enum dma_data_direction direction;
-       dma_cookie_t cookie;
-       size_t partial;
-       int chunks;
-       int mark;
 };
 
 #endif
index 965dd78..89890f6 100644 (file)
@@ -46,17 +46,20 @@ struct pmu;
 /* Maximum number of UBC channels */
 #define HBP_NUM                2
 
+static inline int hw_breakpoint_slots(int type)
+{
+       return HBP_NUM;
+}
+
 /* arch/sh/kernel/hw_breakpoint.c */
-extern int arch_check_va_in_userspace(unsigned long va, u16 hbp_len);
-extern int arch_validate_hwbkpt_settings(struct perf_event *bp,
-                                        struct task_struct *tsk);
+extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
+extern int arch_validate_hwbkpt_settings(struct perf_event *bp);
 extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
                                           unsigned long val, void *data);
 
 int arch_install_hw_breakpoint(struct perf_event *bp);
 void arch_uninstall_hw_breakpoint(struct perf_event *bp);
 void hw_breakpoint_pmu_read(struct perf_event *bp);
-void hw_breakpoint_pmu_unthrottle(struct perf_event *bp);
 
 extern void arch_fill_perf_breakpoint(struct perf_event *bp);
 extern int register_sh_ubc(struct sh_ubc *);
index 5d3ccae..855e945 100644 (file)
@@ -58,13 +58,11 @@ void hwblk_cnt_inc(struct hwblk_info *info, int hwblk, int cnt);
 void hwblk_cnt_dec(struct hwblk_info *info, int hwblk, int cnt);
 
 /* allow clocks to enable and disable hardware blocks */
-#define SH_HWBLK_CLK(_name, _id, _parent, _hwblk, _flags)      \
-{                                                      \
-       .name           = _name,                        \
-       .id             = _id,                          \
-       .parent         = _parent,                      \
-       .arch_flags     = _hwblk,                       \
-       .flags          = _flags,                       \
+#define SH_HWBLK_CLK(_hwblk, _parent, _flags)  \
+[_hwblk] = {                                   \
+       .parent         = _parent,              \
+       .arch_flags     = _hwblk,               \
+       .flags          = _flags,               \
 }
 
 int sh_hwblk_clk_register(struct clk *clks, int nr);
index 1e5d375..491df93 100644 (file)
@@ -38,5 +38,6 @@ void IO_CONCAT(__IO_PREFIX,iounmap)(void *addr);
 
 void __iomem *IO_CONCAT(__IO_PREFIX,ioport_map)(unsigned long addr, unsigned int size);
 void IO_CONCAT(__IO_PREFIX,ioport_unmap)(void __iomem *addr);
+void IO_CONCAT(__IO_PREFIX,mem_init)(void);
 
 #undef __IO_PREFIX
index df8e150..02c2f01 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __ASM_SH_IRQ_H
 #define __ASM_SH_IRQ_H
 
+#include <linux/cpumask.h>
 #include <asm/machvec.h>
 
 /*
 #define NR_IRQS                        256
 #define NR_IRQS_LEGACY         8       /* Legacy external IRQ0-7 */
 
+/*
+ * This is a special IRQ number for indicating that no IRQ has been
+ * triggered and to simply ignore the IRQ dispatch. This is a special
+ * case that can happen with IRQ auto-distribution when multiple CPUs
+ * are woken up and signalled in parallel.
+ */
+#define NO_IRQ_IGNORE          ((unsigned int)-1)
+
 /*
  * Convert back and forth between INTEVT and IRQ values.
  */
@@ -42,6 +51,8 @@ static inline int generic_irq_demux(int irq)
 #define irq_demux(irq)         sh_mv.mv_irq_demux(irq)
 
 void init_IRQ(void);
+void migrate_irqs(void);
+
 asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs);
 
 #ifdef CONFIG_IRQSTACKS
@@ -53,6 +64,14 @@ extern void irq_ctx_exit(int cpu);
 # define irq_ctx_exit(cpu) do { } while (0)
 #endif
 
+#ifdef CONFIG_INTC_BALANCING
+extern unsigned int irq_lookup(unsigned int irq);
+extern void irq_finish(unsigned int irq);
+#else
+#define irq_lookup(irq)                (irq)
+#define irq_finish(irq)                do { } while (0)
+#endif
+
 #include <asm-generic/irq.h>
 #ifdef CONFIG_CPU_SH5
 #include <cpu/irq.h>
index 765a5e1..ad6ef8a 100644 (file)
 /* The native architecture */
 #define KEXEC_ARCH KEXEC_ARCH_SH
 
+#ifdef CONFIG_KEXEC
+/* arch/sh/kernel/machine_kexec.c */
+void reserve_crashkernel(void);
+
 static inline void crash_setup_regs(struct pt_regs *newregs,
                                    struct pt_regs *oldregs)
 {
@@ -59,4 +63,8 @@ static inline void crash_setup_regs(struct pt_regs *newregs,
                newregs->pc = (unsigned long)current_text_addr();
        }
 }
+#else
+static inline void reserve_crashkernel(void) { }
+#endif /* CONFIG_KEXEC */
+
 #endif /* __ASM_SH_KEXEC_H */
index 9c30955..bc0218c 100644 (file)
@@ -49,6 +49,8 @@ struct sh_machine_vector {
 
        int (*mv_clk_init)(void);
        int (*mv_mode_pins)(void);
+
+       void (*mv_mem_init)(void);
 };
 
 extern struct sh_machine_vector sh_mv;
index 7f5363b..8887baf 100644 (file)
@@ -42,9 +42,10 @@ setup_bootmem_node(int nid, unsigned long start, unsigned long end)
 void __init plat_mem_setup(void);
 
 /* arch/sh/kernel/setup.c */
-void __init setup_bootmem_allocator(unsigned long start_pfn);
 void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
                               unsigned long end_pfn);
+/* arch/sh/mm/init.c */
+void __init allocate_pgdat(unsigned int nid);
 
 #endif /* __KERNEL__ */
 #endif /* __ASM_SH_MMZONE_H */
index d71feb3..fb703d1 100644 (file)
@@ -49,7 +49,7 @@
 
 extern unsigned long shm_align_mask;
 extern unsigned long max_low_pfn, min_low_pfn;
-extern unsigned long memory_start, memory_end;
+extern unsigned long memory_start, memory_end, memory_limit;
 
 static inline unsigned long
 pages_do_alias(unsigned long addr1, unsigned long addr2)
@@ -128,13 +128,18 @@ typedef struct page *pgtable_t;
  * added or subtracted as required.
  */
 #ifdef CONFIG_PMB
-#define __pa(x)        ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
-#define __va(x)        ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
+#define ___pa(x)       ((x)-PAGE_OFFSET+__MEMORY_START)
+#define ___va(x)       ((x)+PAGE_OFFSET-__MEMORY_START)
 #else
-#define __pa(x)        ((unsigned long)(x)-PAGE_OFFSET)
-#define __va(x)        ((void *)((unsigned long)(x)+PAGE_OFFSET))
+#define ___pa(x)       ((x)-PAGE_OFFSET)
+#define ___va(x)       ((x)+PAGE_OFFSET)
 #endif
 
+#ifndef __ASSEMBLY__
+#define __pa(x)                ___pa((unsigned long)x)
+#define __va(x)                (void *)___va((unsigned long)x)
+#endif /* !__ASSEMBLY__ */
+
 #ifdef CONFIG_UNCACHED_MAPPING
 #define UNCAC_ADDR(addr)       ((addr) - PAGE_OFFSET + uncached_start)
 #define CAC_ADDR(addr)         ((addr) - uncached_start + PAGE_OFFSET)
index 9605e06..0a58cb2 100644 (file)
@@ -85,6 +85,10 @@ struct sh_cpuinfo {
        struct tlb_info itlb;
        struct tlb_info dtlb;
 
+#ifdef CONFIG_SMP
+       struct task_struct *idle;
+#endif
+
        unsigned long flags;
 } __attribute__ ((aligned(L1_CACHE_BYTES)));
 
@@ -102,6 +106,9 @@ struct task_struct;
 
 extern struct pt_regs fake_swapper_regs;
 
+extern void cpu_init(void);
+extern void cpu_probe(void);
+
 /* arch/sh/kernel/process.c */
 extern unsigned int xstate_size;
 extern void free_thread_xstate(struct task_struct *);
index 572b4eb..61a445d 100644 (file)
@@ -27,8 +27,6 @@
 #define CCN_CVR                0xff000040
 #define CCN_PRR                0xff000044
 
-asmlinkage void __init sh_cpu_init(void);
-
 /*
  * User space process size: 2GB.
  *
index 4758325..01fa17a 100644 (file)
@@ -19,6 +19,7 @@
 #define COMMAND_LINE ((char *) (PARAM+0x100))
 
 void sh_mv_setup(void);
+void check_for_initrd(void);
 
 #endif /* __KERNEL__ */
 
index f1b1e69..e8d4142 100644 (file)
@@ -17,10 +17,10 @@ struct device;
 
 struct siu_platform {
        struct device *dma_dev;
-       enum sh_dmae_slave_chan_id dma_slave_tx_a;
-       enum sh_dmae_slave_chan_id dma_slave_rx_a;
-       enum sh_dmae_slave_chan_id dma_slave_tx_b;
-       enum sh_dmae_slave_chan_id dma_slave_rx_b;
+       unsigned int dma_slave_tx_a;
+       unsigned int dma_slave_rx_a;
+       unsigned int dma_slave_tx_b;
+       unsigned int dma_slave_rx_b;
 };
 
 #endif /* ASM_SIU_H */
diff --git a/arch/sh/include/asm/smp-ops.h b/arch/sh/include/asm/smp-ops.h
new file mode 100644 (file)
index 0000000..c590f76
--- /dev/null
@@ -0,0 +1,51 @@
+#ifndef __ASM_SH_SMP_OPS_H
+#define __ASM_SH_SMP_OPS_H
+
+struct plat_smp_ops {
+       void (*smp_setup)(void);
+       unsigned int (*smp_processor_id)(void);
+       void (*prepare_cpus)(unsigned int max_cpus);
+       void (*start_cpu)(unsigned int cpu, unsigned long entry_point);
+       void (*send_ipi)(unsigned int cpu, unsigned int message);
+       int (*cpu_disable)(unsigned int cpu);
+       void (*cpu_die)(unsigned int cpu);
+       void (*play_dead)(void);
+};
+
+extern struct plat_smp_ops *mp_ops;
+extern struct plat_smp_ops shx3_smp_ops;
+
+#ifdef CONFIG_SMP
+
+static inline void plat_smp_setup(void)
+{
+       BUG_ON(!mp_ops);
+       mp_ops->smp_setup();
+}
+
+static inline void play_dead(void)
+{
+       mp_ops->play_dead();
+}
+
+extern void register_smp_ops(struct plat_smp_ops *ops);
+
+#else
+
+static inline void plat_smp_setup(void)
+{
+       /* UP, nothing to do ... */
+}
+
+static inline void register_smp_ops(struct plat_smp_ops *ops)
+{
+}
+
+static inline void play_dead(void)
+{
+       BUG();
+}
+
+#endif /* CONFIG_SMP */
+
+#endif /* __ASM_SH_SMP_OPS_H */
index 53ef26c..9070d94 100644 (file)
@@ -3,15 +3,16 @@
 
 #include <linux/bitops.h>
 #include <linux/cpumask.h>
+#include <asm/smp-ops.h>
 
 #ifdef CONFIG_SMP
 
 #include <linux/spinlock.h>
 #include <asm/atomic.h>
 #include <asm/current.h>
+#include <asm/percpu.h>
 
 #define raw_smp_processor_id() (current_thread_info()->cpu)
-#define hard_smp_processor_id()        plat_smp_processor_id()
 
 /* Map from cpu id to sequential logical cpu number. */
 extern int __cpu_number_map[NR_CPUS];
@@ -30,20 +31,43 @@ enum {
        SMP_MSG_NR,     /* must be last */
 };
 
+DECLARE_PER_CPU(int, cpu_state);
+
 void smp_message_recv(unsigned int msg);
 void smp_timer_broadcast(const struct cpumask *mask);
 
 void local_timer_interrupt(void);
 void local_timer_setup(unsigned int cpu);
-
-void plat_smp_setup(void);
-void plat_prepare_cpus(unsigned int max_cpus);
-int plat_smp_processor_id(void);
-void plat_start_cpu(unsigned int cpu, unsigned long entry_point);
-void plat_send_ipi(unsigned int cpu, unsigned int message);
+void local_timer_stop(unsigned int cpu);
 
 void arch_send_call_function_single_ipi(int cpu);
-extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
+void arch_send_call_function_ipi_mask(const struct cpumask *mask);
+
+void native_play_dead(void);
+void native_cpu_die(unsigned int cpu);
+int native_cpu_disable(unsigned int cpu);
+
+#ifdef CONFIG_HOTPLUG_CPU
+void play_dead_common(void);
+extern int __cpu_disable(void);
+
+static inline void __cpu_die(unsigned int cpu)
+{
+       extern struct plat_smp_ops *mp_ops;     /* private */
+
+       mp_ops->cpu_die(cpu);
+}
+#endif
+
+static inline int hard_smp_processor_id(void)
+{
+       extern struct plat_smp_ops *mp_ops;     /* private */
+
+       if (!mp_ops)
+               return 0;       /* boot CPU */
+
+       return mp_ops->smp_processor_id();
+}
 
 #else
 
index 55a36fe..c228946 100644 (file)
@@ -121,7 +121,7 @@ extern void init_thread_xstate(void);
 #define TIF_NOTIFY_RESUME      7       /* callback before returning to user */
 #define TIF_SYSCALL_TRACEPOINT 8       /* for ftrace syscall instrumentation */
 #define TIF_POLLING_NRFLAG     17      /* true if poll_idle() is polling TIF_NEED_RESCHED */
-#define TIF_MEMDIE             18
+#define TIF_MEMDIE             18      /* is terminating due to OOM killer */
 #define TIF_FREEZE             19      /* Freezing for suspend */
 
 #define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
index de23595..9a6125e 100644 (file)
@@ -23,7 +23,8 @@
 #define CHCR_TS_HIGH_MASK      0
 #define CHCR_TS_HIGH_SHIFT     0
 #elif defined(CONFIG_CPU_SUBTYPE_SH7722) || \
-       defined(CONFIG_CPU_SUBTYPE_SH7724)
+       defined(CONFIG_CPU_SUBTYPE_SH7724) || \
+       defined(CONFIG_CPU_SUBTYPE_SH7786)
 #define CHCR_TS_LOW_MASK       0x00000018
 #define CHCR_TS_LOW_SHIFT      3
 #define CHCR_TS_HIGH_MASK      0x00300000
index 5963124..e46ec70 100644 (file)
 
 #define MMUCR          0xFF000010      /* MMU Control Register */
 
+#define MMU_TLB_ENTRY_SHIFT    8
+
 #define MMU_ITLB_ADDRESS_ARRAY  0xF2000000
 #define MMU_ITLB_ADDRESS_ARRAY2        0xF2800000
+#define MMU_ITLB_DATA_ARRAY    0xF3000000
+#define MMU_ITLB_DATA_ARRAY2   0xF3800000
+
 #define MMU_UTLB_ADDRESS_ARRAY 0xF6000000
 #define MMU_UTLB_ADDRESS_ARRAY2        0xF6800000
+#define MMU_UTLB_DATA_ARRAY    0xF7000000
+#define MMU_UTLB_DATA_ARRAY2   0xF7800000
 #define MMU_PAGE_ASSOC_BIT     0x80
 
-#define MMUCR_TI               (1<<2)
+#ifdef CONFIG_MMU
+#define MMUCR_AT               (1 << 0)
+#else
+#define MMUCR_AT               (0)
+#endif
+
+#define MMUCR_TI               (1 << 2)
 
 #define MMUCR_URB              0x00FC0000
 #define MMUCR_URB_SHIFT                18
@@ -58,7 +71,8 @@
 #endif
 
 #define MMU_NTLB_ENTRIES       64
-#define MMU_CONTROL_INIT       (0x05|MMUCR_SQMD|MMUCR_ME|MMUCR_SE|MMUCR_AEX)
+#define MMU_CONTROL_INIT       (MMUCR_AT | MMUCR_TI | MMUCR_SQMD | \
+                                MMUCR_ME | MMUCR_SE | MMUCR_AEX)
 
 #define TRA    0xff000020
 #define EXPEVT 0xff000024
index 2120d67..416b621 100644 (file)
 #define  SCBR_I2CCEN   BIT(1)  /* CPU I2C master enable */
 
 #define PWRCR          0x1a0
+#define  PWRCR_SCISEL0 BIT(0)
+#define  PWRCR_SCISEL1 BIT(1)
+#define  PWRCR_SCIEN   BIT(2)  /* Serial port enable */
+#define  PWRCR_PDWNACK BIT(5)  /* Power down acknowledge */
+#define  PWRCR_PDWNREQ BIT(7)  /* Power down request */
+#define  PWRCR_INT2    BIT(11) /* INT2 connection to power manager */
+#define  PWRCR_BUPINIT BIT(13) /* DDR backup initialize */
+#define  PWRCR_BKPRST  BIT(15) /* Backup power reset */
+
 #define SPCBR          0x1b0
 #define SPICR          0x1c0
 #define SPIDR          0x1d0
index 02fd3ae..650b92f 100644 (file)
@@ -11,7 +11,7 @@ endif
 
 CFLAGS_REMOVE_return_address.o = -pg
 
-obj-y  := debugtraps.o dma-nommu.o dumpstack.o                         \
+obj-y  := clkdev.o debugtraps.o dma-nommu.o dumpstack.o                \
           idle.o io.o io_generic.o irq.o                               \
           irq_$(BITS).o machvec.o nmi_debug.o process.o                \
           process_$(BITS).o ptrace_$(BITS).o                           \
diff --git a/arch/sh/kernel/clkdev.c b/arch/sh/kernel/clkdev.c
new file mode 100644 (file)
index 0000000..defdd6e
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * arch/sh/kernel/clkdev.c
+ *
+ * Cloned from arch/arm/common/clkdev.c:
+ *
+ *  Copyright (C) 2008 Russell King.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Helper for the clk API to assist looking up a struct clk.
+ */
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/string.h>
+#include <linux/mutex.h>
+#include <linux/clk.h>
+#include <linux/slab.h>
+#include <linux/bootmem.h>
+#include <linux/mm.h>
+#include <asm/clock.h>
+#include <asm/clkdev.h>
+
+static LIST_HEAD(clocks);
+static DEFINE_MUTEX(clocks_mutex);
+
+/*
+ * Find the correct struct clk for the device and connection ID.
+ * We do slightly fuzzy matching here:
+ *  An entry with a NULL ID is assumed to be a wildcard.
+ *  If an entry has a device ID, it must match
+ *  If an entry has a connection ID, it must match
+ * Then we take the most specific entry - with the following
+ * order of precidence: dev+con > dev only > con only.
+ */
+static struct clk *clk_find(const char *dev_id, const char *con_id)
+{
+       struct clk_lookup *p;
+       struct clk *clk = NULL;
+       int match, best = 0;
+
+       list_for_each_entry(p, &clocks, node) {
+               match = 0;
+               if (p->dev_id) {
+                       if (!dev_id || strcmp(p->dev_id, dev_id))
+                               continue;
+                       match += 2;
+               }
+               if (p->con_id) {
+                       if (!con_id || strcmp(p->con_id, con_id))
+                               continue;
+                       match += 1;
+               }
+               if (match == 0)
+                       continue;
+
+               if (match > best) {
+                       clk = p->clk;
+                       best = match;
+               }
+       }
+       return clk;
+}
+
+struct clk *clk_get_sys(const char *dev_id, const char *con_id)
+{
+       struct clk *clk;
+
+       mutex_lock(&clocks_mutex);
+       clk = clk_find(dev_id, con_id);
+       mutex_unlock(&clocks_mutex);
+
+       return clk ? clk : ERR_PTR(-ENOENT);
+}
+EXPORT_SYMBOL(clk_get_sys);
+
+void clkdev_add(struct clk_lookup *cl)
+{
+       mutex_lock(&clocks_mutex);
+       list_add_tail(&cl->node, &clocks);
+       mutex_unlock(&clocks_mutex);
+}
+EXPORT_SYMBOL(clkdev_add);
+
+void __init clkdev_add_table(struct clk_lookup *cl, size_t num)
+{
+       mutex_lock(&clocks_mutex);
+       while (num--) {
+               list_add_tail(&cl->node, &clocks);
+               cl++;
+       }
+       mutex_unlock(&clocks_mutex);
+}
+
+#define MAX_DEV_ID     20
+#define MAX_CON_ID     16
+
+struct clk_lookup_alloc {
+       struct clk_lookup cl;
+       char    dev_id[MAX_DEV_ID];
+       char    con_id[MAX_CON_ID];
+};
+
+struct clk_lookup * __init_refok
+clkdev_alloc(struct clk *clk, const char *con_id, const char *dev_fmt, ...)
+{
+       struct clk_lookup_alloc *cla;
+
+       if (!slab_is_available())
+               cla = alloc_bootmem_low_pages(sizeof(*cla));
+       else
+               cla = kzalloc(sizeof(*cla), GFP_KERNEL);
+
+       if (!cla)
+               return NULL;
+
+       cla->cl.clk = clk;
+       if (con_id) {
+               strlcpy(cla->con_id, con_id, sizeof(cla->con_id));
+               cla->cl.con_id = cla->con_id;
+       }
+
+       if (dev_fmt) {
+               va_list ap;
+
+               va_start(ap, dev_fmt);
+               vscnprintf(cla->dev_id, sizeof(cla->dev_id), dev_fmt, ap);
+               cla->cl.dev_id = cla->dev_id;
+               va_end(ap);
+       }
+
+       return &cla->cl;
+}
+EXPORT_SYMBOL(clkdev_alloc);
+
+int clk_add_alias(const char *alias, const char *alias_dev_name, char *id,
+       struct device *dev)
+{
+       struct clk *r = clk_get(dev, id);
+       struct clk_lookup *l;
+
+       if (IS_ERR(r))
+               return PTR_ERR(r);
+
+       l = clkdev_alloc(r, alias, alias_dev_name);
+       clk_put(r);
+       if (!l)
+               return -ENODEV;
+       clkdev_add(l);
+       return 0;
+}
+EXPORT_SYMBOL(clk_add_alias);
+
+/*
+ * clkdev_drop - remove a clock dynamically allocated
+ */
+void clkdev_drop(struct clk_lookup *cl)
+{
+       mutex_lock(&clocks_mutex);
+       list_del(&cl->node);
+       mutex_unlock(&clocks_mutex);
+       kfree(cl);
+}
+EXPORT_SYMBOL(clkdev_drop);
index 0e48bc6..4edcb60 100644 (file)
@@ -16,7 +16,7 @@ obj-$(CONFIG_ARCH_SHMOBILE)   += shmobile/
 # Common interfaces.
 
 obj-$(CONFIG_SH_ADC)           += adc.o
-obj-$(CONFIG_SH_CLK_CPG)       += clock-cpg.o
+obj-$(CONFIG_SH_CLK_CPG_LEGACY)        += clock-cpg.o
 obj-$(CONFIG_SH_FPU)           += fpu.o
 obj-$(CONFIG_SH_FPU_EMU)       += fpu.o
 
index eed5eaf..e2f63d6 100644 (file)
 #include <linux/compiler.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 
-static int sh_clk_mstp32_enable(struct clk *clk)
-{
-       __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
-                    clk->enable_reg);
-       return 0;
-}
-
-static void sh_clk_mstp32_disable(struct clk *clk)
-{
-       __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
-                    clk->enable_reg);
-}
-
-static struct clk_ops sh_clk_mstp32_clk_ops = {
-       .enable         = sh_clk_mstp32_enable,
-       .disable        = sh_clk_mstp32_disable,
-       .recalc         = followparent_recalc,
-};
-
-int __init sh_clk_mstp32_register(struct clk *clks, int nr)
-{
-       struct clk *clkp;
-       int ret = 0;
-       int k;
-
-       for (k = 0; !ret && (k < nr); k++) {
-               clkp = clks + k;
-               clkp->ops = &sh_clk_mstp32_clk_ops;
-               ret |= clk_register(clkp);
-       }
-
-       return ret;
-}
-
-static long sh_clk_div_round_rate(struct clk *clk, unsigned long rate)
-{
-       return clk_rate_table_round(clk, clk->freq_table, rate);
-}
-
-static int sh_clk_div6_divisors[64] = {
-       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
-       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
-       33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
-       49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
-};
-
-static struct clk_div_mult_table sh_clk_div6_table = {
-       .divisors = sh_clk_div6_divisors,
-       .nr_divisors = ARRAY_SIZE(sh_clk_div6_divisors),
-};
-
-static unsigned long sh_clk_div6_recalc(struct clk *clk)
-{
-       struct clk_div_mult_table *table = &sh_clk_div6_table;
-       unsigned int idx;
-
-       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, NULL);
-
-       idx = __raw_readl(clk->enable_reg) & 0x003f;
-
-       return clk->freq_table[idx].frequency;
-}
-
-static int sh_clk_div6_set_rate(struct clk *clk,
-                               unsigned long rate, int algo_id)
-{
-       unsigned long value;
-       int idx;
-
-       idx = clk_rate_table_find(clk, clk->freq_table, rate);
-       if (idx < 0)
-               return idx;
-
-       value = __raw_readl(clk->enable_reg);
-       value &= ~0x3f;
-       value |= idx;
-       __raw_writel(value, clk->enable_reg);
-       return 0;
-}
-
-static int sh_clk_div6_enable(struct clk *clk)
-{
-       unsigned long value;
-       int ret;
-
-       ret = sh_clk_div6_set_rate(clk, clk->rate, 0);
-       if (ret == 0) {
-               value = __raw_readl(clk->enable_reg);
-               value &= ~0x100; /* clear stop bit to enable clock */
-               __raw_writel(value, clk->enable_reg);
-       }
-       return ret;
-}
-
-static void sh_clk_div6_disable(struct clk *clk)
-{
-       unsigned long value;
-
-       value = __raw_readl(clk->enable_reg);
-       value |= 0x100; /* stop clock */
-       value |= 0x3f; /* VDIV bits must be non-zero, overwrite divider */
-       __raw_writel(value, clk->enable_reg);
-}
-
-static struct clk_ops sh_clk_div6_clk_ops = {
-       .recalc         = sh_clk_div6_recalc,
-       .round_rate     = sh_clk_div_round_rate,
-       .set_rate       = sh_clk_div6_set_rate,
-       .enable         = sh_clk_div6_enable,
-       .disable        = sh_clk_div6_disable,
-};
-
-int __init sh_clk_div6_register(struct clk *clks, int nr)
-{
-       struct clk *clkp;
-       void *freq_table;
-       int nr_divs = sh_clk_div6_table.nr_divisors;
-       int freq_table_size = sizeof(struct cpufreq_frequency_table);
-       int ret = 0;
-       int k;
-
-       freq_table_size *= (nr_divs + 1);
-       freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
-       if (!freq_table) {
-               pr_err("sh_clk_div6_register: unable to alloc memory\n");
-               return -ENOMEM;
-       }
-
-       for (k = 0; !ret && (k < nr); k++) {
-               clkp = clks + k;
-
-               clkp->ops = &sh_clk_div6_clk_ops;
-               clkp->id = -1;
-               clkp->freq_table = freq_table + (k * freq_table_size);
-               clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
-
-               ret = clk_register(clkp);
-       }
-
-       return ret;
-}
-
-static unsigned long sh_clk_div4_recalc(struct clk *clk)
-{
-       struct clk_div4_table *d4t = clk->priv;
-       struct clk_div_mult_table *table = d4t->div_mult_table;
-       unsigned int idx;
-
-       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, &clk->arch_flags);
-
-       idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
-
-       return clk->freq_table[idx].frequency;
-}
-
-static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
-{
-       struct clk_div4_table *d4t = clk->priv;
-       struct clk_div_mult_table *table = d4t->div_mult_table;
-       u32 value;
-       int ret;
-
-       if (!strcmp("pll_clk", parent->name))
-               value = __raw_readl(clk->enable_reg) & ~(1 << 7);
-       else
-               value = __raw_readl(clk->enable_reg) | (1 << 7);
-
-       ret = clk_reparent(clk, parent);
-       if (ret < 0)
-               return ret;
-
-       __raw_writel(value, clk->enable_reg);
-
-       /* Rebiuld the frequency table */
-       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
-                            table, &clk->arch_flags);
-
-       return 0;
-}
-
-static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate, int algo_id)
-{
-       struct clk_div4_table *d4t = clk->priv;
-       unsigned long value;
-       int idx = clk_rate_table_find(clk, clk->freq_table, rate);
-       if (idx < 0)
-               return idx;
-
-       value = __raw_readl(clk->enable_reg);
-       value &= ~(0xf << clk->enable_bit);
-       value |= (idx << clk->enable_bit);
-       __raw_writel(value, clk->enable_reg);
-
-       if (d4t->kick)
-               d4t->kick(clk);
-
-       return 0;
-}
-
-static int sh_clk_div4_enable(struct clk *clk)
-{
-       __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << 8), clk->enable_reg);
-       return 0;
-}
-
-static void sh_clk_div4_disable(struct clk *clk)
-{
-       __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
-}
-
-static struct clk_ops sh_clk_div4_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
-       .round_rate     = sh_clk_div_round_rate,
-};
-
-static struct clk_ops sh_clk_div4_enable_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
-       .round_rate     = sh_clk_div_round_rate,
-       .enable         = sh_clk_div4_enable,
-       .disable        = sh_clk_div4_disable,
-};
-
-static struct clk_ops sh_clk_div4_reparent_clk_ops = {
-       .recalc         = sh_clk_div4_recalc,
-       .set_rate       = sh_clk_div4_set_rate,
-       .round_rate     = sh_clk_div_round_rate,
-       .enable         = sh_clk_div4_enable,
-       .disable        = sh_clk_div4_disable,
-       .set_parent     = sh_clk_div4_set_parent,
-};
-
-static int __init sh_clk_div4_register_ops(struct clk *clks, int nr,
-                       struct clk_div4_table *table, struct clk_ops *ops)
-{
-       struct clk *clkp;
-       void *freq_table;
-       int nr_divs = table->div_mult_table->nr_divisors;
-       int freq_table_size = sizeof(struct cpufreq_frequency_table);
-       int ret = 0;
-       int k;
-
-       freq_table_size *= (nr_divs + 1);
-       freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
-       if (!freq_table) {
-               pr_err("sh_clk_div4_register: unable to alloc memory\n");
-               return -ENOMEM;
-       }
-
-       for (k = 0; !ret && (k < nr); k++) {
-               clkp = clks + k;
-
-               clkp->ops = ops;
-               clkp->id = -1;
-               clkp->priv = table;
-
-               clkp->freq_table = freq_table + (k * freq_table_size);
-               clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
-
-               ret = clk_register(clkp);
-       }
-
-       return ret;
-}
-
-int __init sh_clk_div4_register(struct clk *clks, int nr,
-                               struct clk_div4_table *table)
-{
-       return sh_clk_div4_register_ops(clks, nr, table, &sh_clk_div4_clk_ops);
-}
-
-int __init sh_clk_div4_enable_register(struct clk *clks, int nr,
-                               struct clk_div4_table *table)
-{
-       return sh_clk_div4_register_ops(clks, nr, table,
-                                       &sh_clk_div4_enable_clk_ops);
-}
-
-int __init sh_clk_div4_reparent_register(struct clk *clks, int nr,
-                               struct clk_div4_table *table)
-{
-       return sh_clk_div4_register_ops(clks, nr, table,
-                                       &sh_clk_div4_reparent_clk_ops);
-}
-
-#ifdef CONFIG_SH_CLK_CPG_LEGACY
 static struct clk master_clk = {
-       .name           = "master_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .rate           = CONFIG_SH_PCLK_FREQ,
 };
 
 static struct clk peripheral_clk = {
-       .name           = "peripheral_clk",
        .parent         = &master_clk,
        .flags          = CLK_ENABLE_ON_INIT,
 };
 
 static struct clk bus_clk = {
-       .name           = "bus_clk",
        .parent         = &master_clk,
        .flags          = CLK_ENABLE_ON_INIT,
 };
 
 static struct clk cpu_clk = {
-       .name           = "cpu_clk",
        .parent         = &master_clk,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -327,6 +35,16 @@ static struct clk *onchip_clocks[] = {
        &cpu_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("master_clk", &master_clk),
+       CLKDEV_CON_ID("peripheral_clk", &peripheral_clk),
+       CLKDEV_CON_ID("bus_clk", &bus_clk),
+       CLKDEV_CON_ID("cpu_clk", &cpu_clk),
+};
+
 int __init __deprecated cpg_clk_init(void)
 {
        int i, ret = 0;
@@ -338,6 +56,13 @@ int __init __deprecated cpg_clk_init(void)
                        ret |= clk_register(clk);
        }
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
+       clk_add_alias("tmu_fck", NULL, "peripheral_clk", NULL);
+       clk_add_alias("mtu2_fck", NULL, "peripheral_clk", NULL);
+       clk_add_alias("cmt_fck", NULL, "peripheral_clk", NULL);
+       clk_add_alias("sci_ick", NULL, "peripheral_clk", NULL);
+
        return ret;
 }
 
@@ -349,4 +74,3 @@ int __init __weak arch_clk_init(void)
 {
        return cpg_clk_init();
 }
-#endif /* CONFIG_SH_CPG_CLK_LEGACY */
index e9fa1bf..50f887d 100644 (file)
  *
  *  Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
  *
- *  With clkdev bits:
- *
- *     Copyright (C) 2008 Russell King.
- *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
-#include <linux/module.h>
-#include <linux/mutex.h>
-#include <linux/list.h>
-#include <linux/kobject.h>
-#include <linux/sysdev.h>
-#include <linux/seq_file.h>
-#include <linux/err.h>
-#include <linux/platform_device.h>
-#include <linux/debugfs.h>
-#include <linux/cpufreq.h>
+#include <linux/clk.h>
 #include <asm/clock.h>
 #include <asm/machvec.h>
 
-static LIST_HEAD(clock_list);
-static DEFINE_SPINLOCK(clock_lock);
-static DEFINE_MUTEX(clock_list_sem);
-
-void clk_rate_table_build(struct clk *clk,
-                         struct cpufreq_frequency_table *freq_table,
-                         int nr_freqs,
-                         struct clk_div_mult_table *src_table,
-                         unsigned long *bitmap)
-{
-       unsigned long mult, div;
-       unsigned long freq;
-       int i;
-
-       for (i = 0; i < nr_freqs; i++) {
-               div = 1;
-               mult = 1;
-
-               if (src_table->divisors && i < src_table->nr_divisors)
-                       div = src_table->divisors[i];
-
-               if (src_table->multipliers && i < src_table->nr_multipliers)
-                       mult = src_table->multipliers[i];
-
-               if (!div || !mult || (bitmap && !test_bit(i, bitmap)))
-                       freq = CPUFREQ_ENTRY_INVALID;
-               else
-                       freq = clk->parent->rate * mult / div;
-
-               freq_table[i].index = i;
-               freq_table[i].frequency = freq;
-       }
-
-       /* Termination entry */
-       freq_table[i].index = i;
-       freq_table[i].frequency = CPUFREQ_TABLE_END;
-}
-
-long clk_rate_table_round(struct clk *clk,
-                         struct cpufreq_frequency_table *freq_table,
-                         unsigned long rate)
-{
-       unsigned long rate_error, rate_error_prev = ~0UL;
-       unsigned long rate_best_fit = rate;
-       unsigned long highest, lowest;
-       int i;
-
-       highest = lowest = 0;
-
-       for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
-               unsigned long freq = freq_table[i].frequency;
-
-               if (freq == CPUFREQ_ENTRY_INVALID)
-                       continue;
-
-               if (freq > highest)
-                       highest = freq;
-               if (freq < lowest)
-                       lowest = freq;
-
-               rate_error = abs(freq - rate);
-               if (rate_error < rate_error_prev) {
-                       rate_best_fit = freq;
-                       rate_error_prev = rate_error;
-               }
-
-               if (rate_error == 0)
-                       break;
-       }
-
-       if (rate >= highest)
-               rate_best_fit = highest;
-       if (rate <= lowest)
-               rate_best_fit = lowest;
-
-       return rate_best_fit;
-}
-
-int clk_rate_table_find(struct clk *clk,
-                       struct cpufreq_frequency_table *freq_table,
-                       unsigned long rate)
-{
-       int i;
-
-       for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
-               unsigned long freq = freq_table[i].frequency;
-
-               if (freq == CPUFREQ_ENTRY_INVALID)
-                       continue;
-
-               if (freq == rate)
-                       return i;
-       }
-
-       return -ENOENT;
-}
-
-/* Used for clocks that always have same value as the parent clock */
-unsigned long followparent_recalc(struct clk *clk)
-{
-       return clk->parent ? clk->parent->rate : 0;
-}
-
-int clk_reparent(struct clk *child, struct clk *parent)
-{
-       list_del_init(&child->sibling);
-       if (parent)
-               list_add(&child->sibling, &parent->children);
-       child->parent = parent;
-
-       /* now do the debugfs renaming to reattach the child
-          to the proper parent */
-
-       return 0;
-}
-
-/* Propagate rate to children */
-void propagate_rate(struct clk *tclk)
-{
-       struct clk *clkp;
-
-       list_for_each_entry(clkp, &tclk->children, sibling) {
-               if (clkp->ops && clkp->ops->recalc)
-                       clkp->rate = clkp->ops->recalc(clkp);
-
-               propagate_rate(clkp);
-       }
-}
-
-static void __clk_disable(struct clk *clk)
-{
-       if (clk->usecount == 0) {
-               printk(KERN_ERR "Trying disable clock %s with 0 usecount\n",
-                      clk->name);
-               WARN_ON(1);
-               return;
-       }
-
-       if (!(--clk->usecount)) {
-               if (likely(clk->ops && clk->ops->disable))
-                       clk->ops->disable(clk);
-               if (likely(clk->parent))
-                       __clk_disable(clk->parent);
-       }
-}
-
-void clk_disable(struct clk *clk)
-{
-       unsigned long flags;
-
-       if (!clk)
-               return;
-
-       spin_lock_irqsave(&clock_lock, flags);
-       __clk_disable(clk);
-       spin_unlock_irqrestore(&clock_lock, flags);
-}
-EXPORT_SYMBOL_GPL(clk_disable);
-
-static int __clk_enable(struct clk *clk)
-{
-       int ret = 0;
-
-       if (clk->usecount++ == 0) {
-               if (clk->parent) {
-                       ret = __clk_enable(clk->parent);
-                       if (unlikely(ret))
-                               goto err;
-               }
-
-               if (clk->ops && clk->ops->enable) {
-                       ret = clk->ops->enable(clk);
-                       if (ret) {
-                               if (clk->parent)
-                                       __clk_disable(clk->parent);
-                               goto err;
-                       }
-               }
-       }
-
-       return ret;
-err:
-       clk->usecount--;
-       return ret;
-}
-
-int clk_enable(struct clk *clk)
-{
-       unsigned long flags;
-       int ret;
-
-       if (!clk)
-               return -EINVAL;
-
-       spin_lock_irqsave(&clock_lock, flags);
-       ret = __clk_enable(clk);
-       spin_unlock_irqrestore(&clock_lock, flags);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(clk_enable);
-
-static LIST_HEAD(root_clks);
-
-/**
- * recalculate_root_clocks - recalculate and propagate all root clocks
- *
- * Recalculates all root clocks (clocks with no parent), which if the
- * clock's .recalc is set correctly, should also propagate their rates.
- * Called at init.
- */
-void recalculate_root_clocks(void)
-{
-       struct clk *clkp;
-
-       list_for_each_entry(clkp, &root_clks, sibling) {
-               if (clkp->ops && clkp->ops->recalc)
-                       clkp->rate = clkp->ops->recalc(clkp);
-               propagate_rate(clkp);
-       }
-}
-
-int clk_register(struct clk *clk)
-{
-       if (clk == NULL || IS_ERR(clk))
-               return -EINVAL;
-
-       /*
-        * trap out already registered clocks
-        */
-       if (clk->node.next || clk->node.prev)
-               return 0;
-
-       mutex_lock(&clock_list_sem);
-
-       INIT_LIST_HEAD(&clk->children);
-       clk->usecount = 0;
-
-       if (clk->parent)
-               list_add(&clk->sibling, &clk->parent->children);
-       else
-               list_add(&clk->sibling, &root_clks);
-
-       list_add(&clk->node, &clock_list);
-       if (clk->ops && clk->ops->init)
-               clk->ops->init(clk);
-       mutex_unlock(&clock_list_sem);
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(clk_register);
-
-void clk_unregister(struct clk *clk)
-{
-       mutex_lock(&clock_list_sem);
-       list_del(&clk->sibling);
-       list_del(&clk->node);
-       mutex_unlock(&clock_list_sem);
-}
-EXPORT_SYMBOL_GPL(clk_unregister);
-
-static void clk_enable_init_clocks(void)
-{
-       struct clk *clkp;
-
-       list_for_each_entry(clkp, &clock_list, node)
-               if (clkp->flags & CLK_ENABLE_ON_INIT)
-                       clk_enable(clkp);
-}
-
-unsigned long clk_get_rate(struct clk *clk)
-{
-       return clk->rate;
-}
-EXPORT_SYMBOL_GPL(clk_get_rate);
-
-int clk_set_rate(struct clk *clk, unsigned long rate)
-{
-       return clk_set_rate_ex(clk, rate, 0);
-}
-EXPORT_SYMBOL_GPL(clk_set_rate);
-
-int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)
-{
-       int ret = -EOPNOTSUPP;
-       unsigned long flags;
-
-       spin_lock_irqsave(&clock_lock, flags);
-
-       if (likely(clk->ops && clk->ops->set_rate)) {
-               ret = clk->ops->set_rate(clk, rate, algo_id);
-               if (ret != 0)
-                       goto out_unlock;
-       } else {
-               clk->rate = rate;
-               ret = 0;
-       }
-
-       if (clk->ops && clk->ops->recalc)
-               clk->rate = clk->ops->recalc(clk);
-
-       propagate_rate(clk);
-
-out_unlock:
-       spin_unlock_irqrestore(&clock_lock, flags);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(clk_set_rate_ex);
-
-int clk_set_parent(struct clk *clk, struct clk *parent)
-{
-       unsigned long flags;
-       int ret = -EINVAL;
-
-       if (!parent || !clk)
-               return ret;
-       if (clk->parent == parent)
-               return 0;
-
-       spin_lock_irqsave(&clock_lock, flags);
-       if (clk->usecount == 0) {
-               if (clk->ops->set_parent)
-                       ret = clk->ops->set_parent(clk, parent);
-               else
-                       ret = clk_reparent(clk, parent);
-
-               if (ret == 0) {
-                       pr_debug("clock: set parent of %s to %s (new rate %ld)\n",
-                                clk->name, clk->parent->name, clk->rate);
-                       if (clk->ops->recalc)
-                               clk->rate = clk->ops->recalc(clk);
-                       propagate_rate(clk);
-               }
-       } else
-               ret = -EBUSY;
-       spin_unlock_irqrestore(&clock_lock, flags);
-
-       return ret;
-}
-EXPORT_SYMBOL_GPL(clk_set_parent);
-
-struct clk *clk_get_parent(struct clk *clk)
-{
-       return clk->parent;
-}
-EXPORT_SYMBOL_GPL(clk_get_parent);
-
-long clk_round_rate(struct clk *clk, unsigned long rate)
-{
-       if (likely(clk->ops && clk->ops->round_rate)) {
-               unsigned long flags, rounded;
-
-               spin_lock_irqsave(&clock_lock, flags);
-               rounded = clk->ops->round_rate(clk, rate);
-               spin_unlock_irqrestore(&clock_lock, flags);
-
-               return rounded;
-       }
-
-       return clk_get_rate(clk);
-}
-EXPORT_SYMBOL_GPL(clk_round_rate);
-
-/*
- * Find the correct struct clk for the device and connection ID.
- * We do slightly fuzzy matching here:
- *  An entry with a NULL ID is assumed to be a wildcard.
- *  If an entry has a device ID, it must match
- *  If an entry has a connection ID, it must match
- * Then we take the most specific entry - with the following
- * order of precedence: dev+con > dev only > con only.
- */
-static struct clk *clk_find(const char *dev_id, const char *con_id)
-{
-       struct clk_lookup *p;
-       struct clk *clk = NULL;
-       int match, best = 0;
-
-       list_for_each_entry(p, &clock_list, node) {
-               match = 0;
-               if (p->dev_id) {
-                       if (!dev_id || strcmp(p->dev_id, dev_id))
-                               continue;
-                       match += 2;
-               }
-               if (p->con_id) {
-                       if (!con_id || strcmp(p->con_id, con_id))
-                               continue;
-                       match += 1;
-               }
-               if (match == 0)
-                       continue;
-
-               if (match > best) {
-                       clk = p->clk;
-                       best = match;
-               }
-       }
-       return clk;
-}
-
-struct clk *clk_get_sys(const char *dev_id, const char *con_id)
-{
-       struct clk *clk;
-
-       mutex_lock(&clock_list_sem);
-       clk = clk_find(dev_id, con_id);
-       mutex_unlock(&clock_list_sem);
-
-       return clk ? clk : ERR_PTR(-ENOENT);
-}
-EXPORT_SYMBOL_GPL(clk_get_sys);
-
-/*
- * Returns a clock. Note that we first try to use device id on the bus
- * and clock name. If this fails, we try to use clock name only.
- */
-struct clk *clk_get(struct device *dev, const char *id)
-{
-       const char *dev_id = dev ? dev_name(dev) : NULL;
-       struct clk *p, *clk = ERR_PTR(-ENOENT);
-       int idno;
-
-       clk = clk_get_sys(dev_id, id);
-       if (clk && !IS_ERR(clk))
-               return clk;
-
-       if (dev == NULL || dev->bus != &platform_bus_type)
-               idno = -1;
-       else
-               idno = to_platform_device(dev)->id;
-
-       mutex_lock(&clock_list_sem);
-       list_for_each_entry(p, &clock_list, node) {
-               if (p->id == idno &&
-                   strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
-                       clk = p;
-                       goto found;
-               }
-       }
-
-       list_for_each_entry(p, &clock_list, node) {
-               if (strcmp(id, p->name) == 0 && try_module_get(p->owner)) {
-                       clk = p;
-                       break;
-               }
-       }
-
-found:
-       mutex_unlock(&clock_list_sem);
-
-       return clk;
-}
-EXPORT_SYMBOL_GPL(clk_get);
-
-void clk_put(struct clk *clk)
-{
-       if (clk && !IS_ERR(clk))
-               module_put(clk->owner);
-}
-EXPORT_SYMBOL_GPL(clk_put);
-
-#ifdef CONFIG_PM
-static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
-{
-       static pm_message_t prev_state;
-       struct clk *clkp;
-
-       switch (state.event) {
-       case PM_EVENT_ON:
-               /* Resumeing from hibernation */
-               if (prev_state.event != PM_EVENT_FREEZE)
-                       break;
-
-               list_for_each_entry(clkp, &clock_list, node) {
-                       if (likely(clkp->ops)) {
-                               unsigned long rate = clkp->rate;
-
-                               if (likely(clkp->ops->set_parent))
-                                       clkp->ops->set_parent(clkp,
-                                               clkp->parent);
-                               if (likely(clkp->ops->set_rate))
-                                       clkp->ops->set_rate(clkp,
-                                               rate, NO_CHANGE);
-                               else if (likely(clkp->ops->recalc))
-                                       clkp->rate = clkp->ops->recalc(clkp);
-                       }
-               }
-               break;
-       case PM_EVENT_FREEZE:
-               break;
-       case PM_EVENT_SUSPEND:
-               break;
-       }
-
-       prev_state = state;
-       return 0;
-}
-
-static int clks_sysdev_resume(struct sys_device *dev)
-{
-       return clks_sysdev_suspend(dev, PMSG_ON);
-}
-
-static struct sysdev_class clks_sysdev_class = {
-       .name = "clks",
-};
-
-static struct sysdev_driver clks_sysdev_driver = {
-       .suspend = clks_sysdev_suspend,
-       .resume = clks_sysdev_resume,
-};
-
-static struct sys_device clks_sysdev_dev = {
-       .cls = &clks_sysdev_class,
-};
-
-static int __init clk_sysdev_init(void)
-{
-       sysdev_class_register(&clks_sysdev_class);
-       sysdev_driver_register(&clks_sysdev_class, &clks_sysdev_driver);
-       sysdev_register(&clks_sysdev_dev);
-
-       return 0;
-}
-subsys_initcall(clk_sysdev_init);
-#endif
-
 int __init clk_init(void)
 {
        int ret;
@@ -591,89 +49,19 @@ int __init clk_init(void)
 }
 
 /*
- *     debugfs support to trace clock tree hierarchy and attributes
+ * Returns a clock. Note that we first try to use device id on the bus
+ * and clock name. If this fails, we try to use clock name only.
  */
-static struct dentry *clk_debugfs_root;
-
-static int clk_debugfs_register_one(struct clk *c)
+struct clk *clk_get(struct device *dev, const char *con_id)
 {
-       int err;
-       struct dentry *d, *child, *child_tmp;
-       struct clk *pa = c->parent;
-       char s[255];
-       char *p = s;
-
-       p += sprintf(p, "%s", c->name);
-       if (c->id >= 0)
-               sprintf(p, ":%d", c->id);
-       d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);
-       if (!d)
-               return -ENOMEM;
-       c->dentry = d;
-
-       d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);
-       if (!d) {
-               err = -ENOMEM;
-               goto err_out;
-       }
-       d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);
-       if (!d) {
-               err = -ENOMEM;
-               goto err_out;
-       }
-       d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);
-       if (!d) {
-               err = -ENOMEM;
-               goto err_out;
-       }
-       return 0;
+       const char *dev_id = dev ? dev_name(dev) : NULL;
 
-err_out:
-       d = c->dentry;
-       list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
-               debugfs_remove(child);
-       debugfs_remove(c->dentry);
-       return err;
+       return clk_get_sys(dev_id, con_id);
 }
+EXPORT_SYMBOL_GPL(clk_get);
 
-static int clk_debugfs_register(struct clk *c)
+void clk_put(struct clk *clk)
 {
-       int err;
-       struct clk *pa = c->parent;
-
-       if (pa && !pa->dentry) {
-               err = clk_debugfs_register(pa);
-               if (err)
-                       return err;
-       }
-
-       if (!c->dentry) {
-               err = clk_debugfs_register_one(c);
-               if (err)
-                       return err;
-       }
-       return 0;
 }
+EXPORT_SYMBOL_GPL(clk_put);
 
-static int __init clk_debugfs_init(void)
-{
-       struct clk *c;
-       struct dentry *d;
-       int err;
-
-       d = debugfs_create_dir("clock", NULL);
-       if (!d)
-               return -ENOMEM;
-       clk_debugfs_root = d;
-
-       list_for_each_entry(c, &clock_list, node) {
-               err = clk_debugfs_register(c);
-               if (err)
-                       goto err_out;
-       }
-       return 0;
-err_out:
-       debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */
-       return err;
-}
-late_initcall(clk_debugfs_init);
index 67a1e81..3e985aa 100644 (file)
@@ -146,6 +146,11 @@ int __init sh_hwblk_clk_register(struct clk *clks, int nr)
 
        for (k = 0; !ret && (k < nr); k++) {
                clkp = clks + k;
+
+               /* skip over clocks using hwblk 0 (HWBLK_UNKNOWN) */
+               if (!clkp->arch_flags)
+                       continue;
+
                clkp->ops = &sh_hwblk_clk_ops;
                ret |= clk_register(clkp);
        }
index c736422..9766106 100644 (file)
@@ -43,9 +43,9 @@
  * peripherals (nofpu, nodsp, and so forth).
  */
 #define onchip_setup(x)                                        \
-static int x##_disabled __initdata = !cpu_has_##x;     \
+static int x##_disabled __cpuinitdata = !cpu_has_##x;  \
                                                        \
-static int __init x##_setup(char *opts)                        \
+static int __cpuinit x##_setup(char *opts)                     \
 {                                                      \
        x##_disabled = 1;                               \
        return 1;                                       \
@@ -59,7 +59,7 @@ onchip_setup(dsp);
 #define CPUOPM         0xff2f0000
 #define CPUOPM_RABD    (1 << 5)
 
-static void __init speculative_execution_init(void)
+static void __cpuinit speculative_execution_init(void)
 {
        /* Clear RABD */
        __raw_writel(__raw_readl(CPUOPM) & ~CPUOPM_RABD, CPUOPM);
@@ -78,7 +78,7 @@ static void __init speculative_execution_init(void)
 #define EXPMASK_BRDSSLP                (1 << 1)
 #define EXPMASK_MMCAW          (1 << 4)
 
-static void __init expmask_init(void)
+static void __cpuinit expmask_init(void)
 {
        unsigned long expmask = __raw_readl(EXPMASK);
 
@@ -217,7 +217,7 @@ static void detect_cache_shape(void)
                l2_cache_shape = -1; /* No S-cache */
 }
 
-static void __init fpu_init(void)
+static void __cpuinit fpu_init(void)
 {
        /* Disable the FPU */
        if (fpu_disabled && (current_cpu_data.flags & CPU_HAS_FPU)) {
@@ -230,7 +230,7 @@ static void __init fpu_init(void)
 }
 
 #ifdef CONFIG_SH_DSP
-static void __init release_dsp(void)
+static void __cpuinit release_dsp(void)
 {
        unsigned long sr;
 
@@ -244,7 +244,7 @@ static void __init release_dsp(void)
        );
 }
 
-static void __init dsp_init(void)
+static void __cpuinit dsp_init(void)
 {
        unsigned long sr;
 
@@ -276,11 +276,11 @@ static void __init dsp_init(void)
        release_dsp();
 }
 #else
-static inline void __init dsp_init(void) { }
+static inline void __cpuinit dsp_init(void) { }
 #endif /* CONFIG_SH_DSP */
 
 /**
- * sh_cpu_init
+ * cpu_init
  *
  * This is our initial entry point for each CPU, and is invoked on the
  * boot CPU prior to calling start_kernel(). For SMP, a combination of
@@ -293,14 +293,14 @@ static inline void __init dsp_init(void) { }
  * subtype and initial configuration will all be done.
  *
  * Each processor family is still responsible for doing its own probing
- * and cache configuration in detect_cpu_and_cache_system().
+ * and cache configuration in cpu_probe().
  */
-asmlinkage void __init sh_cpu_init(void)
+asmlinkage void __cpuinit cpu_init(void)
 {
        current_thread_info()->cpu = hard_smp_processor_id();
 
        /* First, probe the CPU */
-       detect_cpu_and_cache_system();
+       cpu_probe();
 
        if (current_cpu_data.type == CPU_SH_NONE)
                panic("Unknown CPU");
index 1db6d88..bab8e75 100644 (file)
@@ -13,7 +13,7 @@
 #include <asm/processor.h>
 #include <asm/cache.h>
 
-int __init detect_cpu_and_cache_system(void)
+void __cpuinit cpu_probe(void)
 {
 #if defined(CONFIG_CPU_SUBTYPE_SH7619)
        boot_cpu_data.type                      = CPU_SH7619;
@@ -30,7 +30,4 @@ int __init detect_cpu_and_cache_system(void)
        boot_cpu_data.dcache.flags |= SH_CACHE_COMBINED;
        boot_cpu_data.icache = boot_cpu_data.dcache;
        boot_cpu_data.family = CPU_FAMILY_SH2;
-
-       return 0;
 }
-
index 114c7ce..c363851 100644 (file)
@@ -128,17 +128,14 @@ static struct platform_device eth_device = {
 };
 
 static struct sh_timer_config cmt0_platform_data = {
-       .name = "CMT0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt0_resources[] = {
        [0] = {
-               .name   = "CMT0",
                .start  = 0xf84a0072,
                .end    = 0xf84a0077,
                .flags  = IORESOURCE_MEM,
@@ -160,17 +157,14 @@ static struct platform_device cmt0_device = {
 };
 
 static struct sh_timer_config cmt1_platform_data = {
-       .name = "CMT1",
        .channel_offset = 0x08,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt1_resources[] = {
        [0] = {
-               .name   = "CMT1",
                .start  = 0xf84a0078,
                .end    = 0xf84a007d,
                .flags  = IORESOURCE_MEM,
index 6825d65..48e97a2 100644 (file)
@@ -13,7 +13,7 @@
 #include <asm/processor.h>
 #include <asm/cache.h>
 
-int __init detect_cpu_and_cache_system(void)
+void __cpuinit cpu_probe(void)
 {
        boot_cpu_data.family                    = CPU_FAMILY_SH2A;
 
@@ -51,6 +51,4 @@ int __init detect_cpu_and_cache_system(void)
         * on the cache info.
         */
        boot_cpu_data.icache            = boot_cpu_data.dcache;
-
-       return 0;
 }
index 8f669dc..6c96ea0 100644 (file)
@@ -115,16 +115,13 @@ static DECLARE_INTC_DESC(intc_desc, "mxg", vectors, groups,
                         mask_registers, prio_registers, NULL);
 
 static struct sh_timer_config mtu2_0_platform_data = {
-       .name = "MTU2_0",
        .channel_offset = -0x80,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_0_resources[] = {
        [0] = {
-               .name   = "MTU2_0",
                .start  = 0xff801300,
                .end    = 0xff801326,
                .flags  = IORESOURCE_MEM,
@@ -146,16 +143,13 @@ static struct platform_device mtu2_0_device = {
 };
 
 static struct sh_timer_config mtu2_1_platform_data = {
-       .name = "MTU2_1",
        .channel_offset = -0x100,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_1_resources[] = {
        [0] = {
-               .name   = "MTU2_1",
                .start  = 0xff801380,
                .end    = 0xff801390,
                .flags  = IORESOURCE_MEM,
@@ -177,16 +171,13 @@ static struct platform_device mtu2_1_device = {
 };
 
 static struct sh_timer_config mtu2_2_platform_data = {
-       .name = "MTU2_2",
        .channel_offset = 0x80,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_2_resources[] = {
        [0] = {
-               .name   = "MTU2_2",
                .start  = 0xff801000,
                .end    = 0xff80100a,
                .flags  = IORESOURCE_MEM,
index 4ccfeb5..d08bf4c 100644 (file)
@@ -318,16 +318,13 @@ static struct platform_device rtc_device = {
 };
 
 static struct sh_timer_config mtu2_0_platform_data = {
-       .name = "MTU2_0",
        .channel_offset = -0x80,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_0_resources[] = {
        [0] = {
-               .name   = "MTU2_0",
                .start  = 0xfffe4300,
                .end    = 0xfffe4326,
                .flags  = IORESOURCE_MEM,
@@ -349,16 +346,13 @@ static struct platform_device mtu2_0_device = {
 };
 
 static struct sh_timer_config mtu2_1_platform_data = {
-       .name = "MTU2_1",
        .channel_offset = -0x100,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_1_resources[] = {
        [0] = {
-               .name   = "MTU2_1",
                .start  = 0xfffe4380,
                .end    = 0xfffe4390,
                .flags  = IORESOURCE_MEM,
@@ -380,16 +374,13 @@ static struct platform_device mtu2_1_device = {
 };
 
 static struct sh_timer_config mtu2_2_platform_data = {
-       .name = "MTU2_2",
        .channel_offset = 0x80,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_2_resources[] = {
        [0] = {
-               .name   = "MTU2_2",
                .start  = 0xfffe4000,
                .end    = 0xfffe400a,
                .flags  = IORESOURCE_MEM,
index 3136966..832f401 100644 (file)
@@ -234,17 +234,14 @@ static struct platform_device scif3_device = {
 };
 
 static struct sh_timer_config cmt0_platform_data = {
-       .name = "CMT0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt0_resources[] = {
        [0] = {
-               .name   = "CMT0",
                .start  = 0xfffec002,
                .end    = 0xfffec007,
                .flags  = IORESOURCE_MEM,
@@ -266,17 +263,14 @@ static struct platform_device cmt0_device = {
 };
 
 static struct sh_timer_config cmt1_platform_data = {
-       .name = "CMT1",
        .channel_offset = 0x08,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt1_resources[] = {
        [0] = {
-               .name   = "CMT1",
                .start  = 0xfffec008,
                .end    = 0xfffec00d,
                .flags  = IORESOURCE_MEM,
@@ -298,16 +292,13 @@ static struct platform_device cmt1_device = {
 };
 
 static struct sh_timer_config mtu2_0_platform_data = {
-       .name = "MTU2_0",
        .channel_offset = -0x80,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_0_resources[] = {
        [0] = {
-               .name   = "MTU2_0",
                .start  = 0xfffe4300,
                .end    = 0xfffe4326,
                .flags  = IORESOURCE_MEM,
@@ -329,16 +320,13 @@ static struct platform_device mtu2_0_device = {
 };
 
 static struct sh_timer_config mtu2_1_platform_data = {
-       .name = "MTU2_1",
        .channel_offset = -0x100,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_1_resources[] = {
        [0] = {
-               .name   = "MTU2_1",
                .start  = 0xfffe4380,
                .end    = 0xfffe4390,
                .flags  = IORESOURCE_MEM,
index 0648735..dc47b04 100644 (file)
@@ -194,17 +194,14 @@ static struct platform_device scif3_device = {
 };
 
 static struct sh_timer_config cmt0_platform_data = {
-       .name = "CMT0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt0_resources[] = {
        [0] = {
-               .name   = "CMT0",
                .start  = 0xfffec002,
                .end    = 0xfffec007,
                .flags  = IORESOURCE_MEM,
@@ -226,17 +223,14 @@ static struct platform_device cmt0_device = {
 };
 
 static struct sh_timer_config cmt1_platform_data = {
-       .name = "CMT1",
        .channel_offset = 0x08,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 0, /* disabled due to code generation issues */
 };
 
 static struct resource cmt1_resources[] = {
        [0] = {
-               .name   = "CMT1",
                .start  = 0xfffec008,
                .end    = 0xfffec00d,
                .flags  = IORESOURCE_MEM,
@@ -258,16 +252,13 @@ static struct platform_device cmt1_device = {
 };
 
 static struct sh_timer_config mtu2_0_platform_data = {
-       .name = "MTU2_0",
        .channel_offset = -0x80,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_0_resources[] = {
        [0] = {
-               .name   = "MTU2_0",
                .start  = 0xfffe4300,
                .end    = 0xfffe4326,
                .flags  = IORESOURCE_MEM,
@@ -289,16 +280,13 @@ static struct platform_device mtu2_0_device = {
 };
 
 static struct sh_timer_config mtu2_1_platform_data = {
-       .name = "MTU2_1",
        .channel_offset = -0x100,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_1_resources[] = {
        [0] = {
-               .name   = "MTU2_1",
                .start  = 0xfffe4380,
                .end    = 0xfffe4390,
                .flags  = IORESOURCE_MEM,
@@ -320,16 +308,13 @@ static struct platform_device mtu2_1_device = {
 };
 
 static struct sh_timer_config mtu2_2_platform_data = {
-       .name = "MTU2_2",
        .channel_offset = 0x80,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource mtu2_2_resources[] = {
        [0] = {
-               .name   = "MTU2_2",
                .start  = 0xfffe4000,
                .end    = 0xfffe400a,
                .flags  = IORESOURCE_MEM,
index 295ec4c..bf23c32 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/cache.h>
 #include <asm/io.h>
 
-int detect_cpu_and_cache_system(void)
+void __cpuinit cpu_probe(void)
 {
        unsigned long addr0, addr1, data0, data1, data2, data3;
 
@@ -108,6 +108,4 @@ int detect_cpu_and_cache_system(void)
        boot_cpu_data.icache = boot_cpu_data.dcache;
 
        boot_cpu_data.family = CPU_FAMILY_SH3;
-
-       return 0;
 }
index 7b892d6..baadd7f 100644 (file)
@@ -124,16 +124,13 @@ static struct platform_device rtc_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xfffffe94,
                .end    = 0xfffffe9f,
                .flags  = IORESOURCE_MEM,
@@ -155,16 +152,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0xe,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xfffffea0,
                .end    = 0xfffffeab,
                .flags  = IORESOURCE_MEM,
@@ -186,15 +180,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1a,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xfffffeac,
                .end    = 0xfffffebb,
                .flags  = IORESOURCE_MEM,
index bc0c4f6..3cf8c8e 100644 (file)
@@ -157,16 +157,13 @@ static struct platform_device scif2_device = {
 #endif
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xfffffe94,
                .end    = 0xfffffe9f,
                .flags  = IORESOURCE_MEM,
@@ -188,16 +185,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0xe,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xfffffea0,
                .end    = 0xfffffeab,
                .flags  = IORESOURCE_MEM,
@@ -219,15 +213,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1a,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xfffffeac,
                .end    = 0xfffffebb,
                .flags  = IORESOURCE_MEM,
index 0845a3a..b0c2fb4 100644 (file)
@@ -127,16 +127,13 @@ static struct platform_device scif1_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xa412fe94,
                .end    = 0xa412fe9f,
                .flags  = IORESOURCE_MEM,
@@ -158,16 +155,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0xe,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xa412fea0,
                .end    = 0xa412feab,
                .flags  = IORESOURCE_MEM,
@@ -189,15 +183,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1a,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xa412feac,
                .end    = 0xa412feb5,
                .flags  = IORESOURCE_MEM,
index a718a62..24b1713 100644 (file)
@@ -130,17 +130,14 @@ static struct platform_device usbf_device = {
 };
 
 static struct sh_timer_config cmt0_platform_data = {
-       .name = "CMT0",
        .channel_offset = 0x10,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 125,
        .clocksource_rating = 125,
 };
 
 static struct resource cmt0_resources[] = {
        [0] = {
-               .name   = "CMT0",
                .start  = 0x044a0010,
                .end    = 0x044a001b,
                .flags  = IORESOURCE_MEM,
@@ -162,15 +159,12 @@ static struct platform_device cmt0_device = {
 };
 
 static struct sh_timer_config cmt1_platform_data = {
-       .name = "CMT1",
        .channel_offset = 0x20,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource cmt1_resources[] = {
        [0] = {
-               .name   = "CMT1",
                .start  = 0x044a0020,
                .end    = 0x044a002b,
                .flags  = IORESOURCE_MEM,
@@ -192,15 +186,12 @@ static struct platform_device cmt1_device = {
 };
 
 static struct sh_timer_config cmt2_platform_data = {
-       .name = "CMT2",
        .channel_offset = 0x30,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource cmt2_resources[] = {
        [0] = {
-               .name   = "CMT2",
                .start  = 0x044a0030,
                .end    = 0x044a003b,
                .flags  = IORESOURCE_MEM,
@@ -222,15 +213,12 @@ static struct platform_device cmt2_device = {
 };
 
 static struct sh_timer_config cmt3_platform_data = {
-       .name = "CMT3",
        .channel_offset = 0x40,
        .timer_bit = 3,
-       .clk = "peripheral_clk",
 };
 
 static struct resource cmt3_resources[] = {
        [0] = {
-               .name   = "CMT3",
                .start  = 0x044a0040,
                .end    = 0x044a004b,
                .flags  = IORESOURCE_MEM,
@@ -252,15 +240,12 @@ static struct platform_device cmt3_device = {
 };
 
 static struct sh_timer_config cmt4_platform_data = {
-       .name = "CMT4",
        .channel_offset = 0x50,
        .timer_bit = 4,
-       .clk = "peripheral_clk",
 };
 
 static struct resource cmt4_resources[] = {
        [0] = {
-               .name   = "CMT4",
                .start  = 0x044a0050,
                .end    = 0x044a005b,
                .flags  = IORESOURCE_MEM,
@@ -282,16 +267,13 @@ static struct platform_device cmt4_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x02,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xa412fe94,
                .end    = 0xa412fe9f,
                .flags  = IORESOURCE_MEM,
@@ -313,16 +295,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0xe,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xa412fea0,
                .end    = 0xa412feab,
                .flags  = IORESOURCE_MEM,
@@ -344,15 +323,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1a,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xa412feac,
                .end    = 0xa412feb5,
                .flags  = IORESOURCE_MEM,
index 6b80850..4eabc68 100644 (file)
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/err.h>
+#include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
-#include <asm/io.h>
 
 #define CPG2_FRQCR3    0xfe0a0018
 
@@ -45,7 +46,6 @@ static struct clk_ops sh4202_emi_clk_ops = {
 };
 
 static struct clk sh4202_emi_clk = {
-       .name           = "emi_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh4202_emi_clk_ops,
 };
@@ -61,7 +61,6 @@ static struct clk_ops sh4202_femi_clk_ops = {
 };
 
 static struct clk sh4202_femi_clk = {
-       .name           = "femi_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh4202_femi_clk_ops,
 };
@@ -139,7 +138,6 @@ static struct clk_ops sh4202_shoc_clk_ops = {
 };
 
 static struct clk sh4202_shoc_clk = {
-       .name           = "shoc_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh4202_shoc_clk_ops,
 };
@@ -150,6 +148,15 @@ static struct clk *sh4202_onchip_clocks[] = {
        &sh4202_shoc_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("emi_clk", &sh4202_emi_clk),
+       CLKDEV_CON_ID("femi_clk", &sh4202_femi_clk),
+       CLKDEV_CON_ID("shoc_clk", &sh4202_shoc_clk),
+};
+
 int __init arch_clk_init(void)
 {
        struct clk *clk;
@@ -167,5 +174,7 @@ int __init arch_clk_init(void)
 
        clk_put(clk);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return ret;
 }
index 822977a..d180f16 100644 (file)
@@ -15,7 +15,7 @@
 #include <asm/processor.h>
 #include <asm/cache.h>
 
-int __init detect_cpu_and_cache_system(void)
+void __cpuinit cpu_probe(void)
 {
        unsigned long pvr, prr, cvr;
        unsigned long size;
@@ -251,6 +251,4 @@ int __init detect_cpu_and_cache_system(void)
                                 boot_cpu_data.scache.linesz);
                }
        }
-
-       return 0;
 }
index b9b7e10..e916b18 100644 (file)
@@ -31,16 +31,13 @@ static struct platform_device scif0_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -62,16 +59,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -93,15 +87,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
index ffd79e5..911d196 100644 (file)
@@ -66,16 +66,13 @@ static struct platform_device scif1_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -97,16 +94,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -128,15 +122,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -163,15 +154,12 @@ static struct platform_device tmu2_device = {
        defined(CONFIG_CPU_SUBTYPE_SH7751R)
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xfe100008,
                .end    = 0xfe100013,
                .flags  = IORESOURCE_MEM,
@@ -193,15 +181,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xfe100014,
                .end    = 0xfe10001f,
                .flags  = IORESOURCE_MEM,
index a16eb36..48ea8fe 100644 (file)
@@ -187,16 +187,13 @@ static struct platform_device scif3_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -218,16 +215,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -249,15 +243,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
index 2c16df3..71291ae 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 
 /* SH7343 registers */
@@ -36,8 +37,6 @@
 
 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
 static struct clk r_clk = {
-       .name           = "rclk",
-       .id             = -1,
        .rate           = 32768,
 };
 
@@ -46,8 +45,6 @@ static struct clk r_clk = {
  * from the platform code.
  */
 struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -69,8 +66,6 @@ static struct clk_ops dll_clk_ops = {
 };
 
 static struct clk dll_clk = {
-       .name           = "dll_clk",
-       .id             = -1,
        .ops            = &dll_clk_ops,
        .parent         = &r_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -91,8 +86,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -121,72 +114,168 @@ static struct clk_div4_table div4_table = {
 enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
        DIV4_SIUA, DIV4_SIUB, DIV4_NR };
 
-#define DIV4(_str, _reg, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
+#define DIV4(_reg, _bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
-       [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
-       [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
+       [DIV4_I] = DIV4(FRQCR, 20, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),
+       [DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),
+       [DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),
 };
 
-struct clk div6_clks[] = {
-       SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
+enum { DIV6_V, DIV6_NR };
+
+struct clk div6_clks[DIV6_NR] = {
+       [DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
+};
+
+#define MSTP(_parent, _reg, _bit, _flags) \
+  SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
+
+enum { MSTP031, MSTP030, MSTP029, MSTP028, MSTP026,
+       MSTP023, MSTP022, MSTP021, MSTP020, MSTP019, MSTP018, MSTP017, MSTP016,
+       MSTP015, MSTP014, MSTP013, MSTP012, MSTP011, MSTP010,
+       MSTP007, MSTP006, MSTP005, MSTP004, MSTP003, MSTP002, MSTP001,
+       MSTP109, MSTP108, MSTP100,
+       MSTP225, MSTP224, MSTP218, MSTP217, MSTP216,
+       MSTP214, MSTP213, MSTP212, MSTP211, MSTP208,
+       MSTP206, MSTP205, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
+       MSTP_NR };
+
+static struct clk mstp_clks[MSTP_NR] = {
+       [MSTP031] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
+       [MSTP030] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
+       [MSTP029] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
+       [MSTP028] = MSTP(&div4_clks[DIV4_U], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
+       [MSTP026] = MSTP(&div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
+       [MSTP023] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 23, 0),
+       [MSTP022] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 22, 0),
+       [MSTP021] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
+       [MSTP020] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 20, 0),
+       [MSTP019] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 19, 0),
+       [MSTP017] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 17, 0),
+       [MSTP015] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 15, 0),
+       [MSTP014] = MSTP(&r_clk, MSTPCR0, 14, 0),
+       [MSTP013] = MSTP(&r_clk, MSTPCR0, 13, 0),
+       [MSTP011] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 11, 0),
+       [MSTP010] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 10, 0),
+       [MSTP007] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 7, 0),
+       [MSTP006] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 6, 0),
+       [MSTP005] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 5, 0),
+       [MSTP004] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 4, 0),
+       [MSTP003] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 3, 0),
+       [MSTP002] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
+       [MSTP001] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 1, 0),
+
+       [MSTP109] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 9, 0),
+       [MSTP108] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 8, 0),
+
+       [MSTP225] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 25, 0),
+       [MSTP224] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 24, 0),
+       [MSTP218] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 18, 0),
+       [MSTP217] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 17, 0),
+       [MSTP216] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 16, 0),
+       [MSTP214] = MSTP(&r_clk, MSTPCR2, 14, 0),
+       [MSTP213] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 13, 0),
+       [MSTP212] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 12, 0),
+       [MSTP211] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 11, 0),
+       [MSTP208] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 8, 0),
+       [MSTP206] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 6, CLK_ENABLE_ON_INIT),
+       [MSTP205] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 5, 0),
+       [MSTP204] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 4, 0),
+       [MSTP203] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 3, 0),
+       [MSTP202] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
+       [MSTP201] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
+       [MSTP200] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 0, 0),
 };
 
-#define MSTP(_str, _parent, _reg, _bit, _flags) \
-  SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _flags)
-
-static struct clk mstp_clks[] = {
-       MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
-       MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
-       MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
-       MSTP("uram0", &div4_clks[DIV4_U], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
-       MSTP("xymem0", &div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
-       MSTP("intc3", &div4_clks[DIV4_P], MSTPCR0, 23, 0),
-       MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 0),
-       MSTP("dmac0", &div4_clks[DIV4_P], MSTPCR0, 21, 0),
-       MSTP("sh0", &div4_clks[DIV4_P], MSTPCR0, 20, 0),
-       MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0),
-       MSTP("ubc0", &div4_clks[DIV4_P], MSTPCR0, 17, 0),
-       MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0),
-       MSTP("cmt0", &r_clk, MSTPCR0, 14, 0),
-       MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0),
-       MSTP("mfi0", &div4_clks[DIV4_P], MSTPCR0, 11, 0),
-       MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0),
-       MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 7, 0),
-       MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 6, 0),
-       MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 5, 0),
-       MSTP("scif3", &div4_clks[DIV4_P], MSTPCR0, 4, 0),
-       MSTP("sio0", &div4_clks[DIV4_P], MSTPCR0, 3, 0),
-       MSTP("siof0", &div4_clks[DIV4_P], MSTPCR0, 2, 0),
-       MSTP("siof1", &div4_clks[DIV4_P], MSTPCR0, 1, 0),
-
-       MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0),
-       MSTP("i2c1", &div4_clks[DIV4_P], MSTPCR1, 8, 0),
-
-       MSTP("tpu0", &div4_clks[DIV4_P], MSTPCR2, 25, 0),
-       MSTP("irda0", &div4_clks[DIV4_P], MSTPCR2, 24, 0),
-       MSTP("sdhi0", &div4_clks[DIV4_P], MSTPCR2, 18, 0),
-       MSTP("mmcif0", &div4_clks[DIV4_P], MSTPCR2, 17, 0),
-       MSTP("sim0", &div4_clks[DIV4_P], MSTPCR2, 16, 0),
-       MSTP("keysc0", &r_clk, MSTPCR2, 14, 0),
-       MSTP("tsif0", &div4_clks[DIV4_P], MSTPCR2, 13, 0),
-       MSTP("s3d40", &div4_clks[DIV4_P], MSTPCR2, 12, 0),
-       MSTP("usbf0", &div4_clks[DIV4_P], MSTPCR2, 11, 0),
-       MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 8, 0),
-       MSTP("jpu0", &div4_clks[DIV4_B], MSTPCR2, 6, CLK_ENABLE_ON_INIT),
-       MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0),
-       MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0),
-       MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0),
-       MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
-       MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
-       MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0),
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("rclk", &r_clk),
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("dll_clk", &dll_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+       CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("siua_clk", &div4_clks[DIV4_SIUA]),
+       CLKDEV_CON_ID("siub_clk", &div4_clks[DIV4_SIUB]),
+
+       /* DIV6 clocks */
+       CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
+
+       /* MSTP32 clocks */
+       CLKDEV_CON_ID("tlb0", &mstp_clks[MSTP031]),
+       CLKDEV_CON_ID("ic0", &mstp_clks[MSTP030]),
+       CLKDEV_CON_ID("oc0", &mstp_clks[MSTP029]),
+       CLKDEV_CON_ID("uram0", &mstp_clks[MSTP028]),
+       CLKDEV_CON_ID("xymem0", &mstp_clks[MSTP026]),
+       CLKDEV_CON_ID("intc3", &mstp_clks[MSTP023]),
+       CLKDEV_CON_ID("intc0", &mstp_clks[MSTP022]),
+       CLKDEV_CON_ID("dmac0", &mstp_clks[MSTP021]),
+       CLKDEV_CON_ID("sh0", &mstp_clks[MSTP020]),
+       CLKDEV_CON_ID("hudi0", &mstp_clks[MSTP019]),
+       CLKDEV_CON_ID("ubc0", &mstp_clks[MSTP017]),
+       CLKDEV_CON_ID("tmu_fck", &mstp_clks[MSTP015]),
+       CLKDEV_CON_ID("cmt_fck", &mstp_clks[MSTP014]),
+       CLKDEV_CON_ID("rwdt0", &mstp_clks[MSTP013]),
+       CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
+       CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
+       {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP007],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP006],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP005],
+       }, {
+               /* SCIF3 */
+               .dev_id         = "sh-sci.3",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP004],
+       },
+       CLKDEV_CON_ID("sio0", &mstp_clks[MSTP003]),
+       CLKDEV_CON_ID("siof0", &mstp_clks[MSTP002]),
+       CLKDEV_CON_ID("siof1", &mstp_clks[MSTP001]),
+       CLKDEV_CON_ID("i2c0", &mstp_clks[MSTP109]),
+       CLKDEV_CON_ID("i2c1", &mstp_clks[MSTP108]),
+       CLKDEV_CON_ID("tpu0", &mstp_clks[MSTP225]),
+       CLKDEV_CON_ID("irda0", &mstp_clks[MSTP224]),
+       CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP218]),
+       CLKDEV_CON_ID("mmcif0", &mstp_clks[MSTP217]),
+       CLKDEV_CON_ID("sim0", &mstp_clks[MSTP216]),
+       CLKDEV_CON_ID("keysc0", &mstp_clks[MSTP214]),
+       CLKDEV_CON_ID("tsif0", &mstp_clks[MSTP213]),
+       CLKDEV_CON_ID("s3d40", &mstp_clks[MSTP212]),
+       CLKDEV_CON_ID("usbf0", &mstp_clks[MSTP211]),
+       CLKDEV_CON_ID("siu0", &mstp_clks[MSTP208]),
+       CLKDEV_CON_ID("jpu0", &mstp_clks[MSTP206]),
+       CLKDEV_CON_ID("vou0", &mstp_clks[MSTP205]),
+       CLKDEV_CON_ID("beu0", &mstp_clks[MSTP204]),
+       CLKDEV_CON_ID("ceu0", &mstp_clks[MSTP203]),
+       CLKDEV_CON_ID("veu0", &mstp_clks[MSTP202]),
+       CLKDEV_CON_ID("vpu0", &mstp_clks[MSTP201]),
+       CLKDEV_CON_ID("lcdc0", &mstp_clks[MSTP200]),
 };
 
 int __init arch_clk_init(void)
@@ -202,14 +291,16 @@ int __init arch_clk_init(void)
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
                ret = clk_register(main_clks[k]);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
 
        if (!ret)
-               ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
+               ret = sh_clk_div6_register(div6_clks, DIV6_NR);
 
        if (!ret)
-               ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
 
        return ret;
 }
index 91588d2..7ce5bbc 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 
 /* SH7366 registers */
@@ -36,8 +37,6 @@
 
 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
 static struct clk r_clk = {
-       .name           = "rclk",
-       .id             = -1,
        .rate           = 32768,
 };
 
@@ -46,8 +45,6 @@ static struct clk r_clk = {
  * from the platform code.
  */
 struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -69,8 +66,6 @@ static struct clk_ops dll_clk_ops = {
 };
 
 static struct clk dll_clk = {
-       .name           = "dll_clk",
-       .id             = -1,
        .ops            = &dll_clk_ops,
        .parent         = &r_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -94,8 +89,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -124,69 +117,154 @@ static struct clk_div4_table div4_table = {
 enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
        DIV4_SIUA, DIV4_SIUB, DIV4_NR };
 
-#define DIV4(_str, _reg, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
+#define DIV4(_reg, _bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
-       [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
-       [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
-       [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
+       [DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
+       [DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),
+       [DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),
+       [DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),
 };
 
-struct clk div6_clks[] = {
-       SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
+enum { DIV6_V, DIV6_NR };
+
+struct clk div6_clks[DIV6_NR] = {
+       [DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
 };
 
-#define MSTP(_str, _parent, _reg, _bit, _flags) \
-  SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _flags)
+#define MSTP(_parent, _reg, _bit, _flags) \
+  SH_CLK_MSTP32(_parent, _reg, _bit, _flags)
+
+enum { MSTP031, MSTP030, MSTP029, MSTP028, MSTP026,
+       MSTP023, MSTP022, MSTP021, MSTP020, MSTP019, MSTP018, MSTP017, MSTP016,
+       MSTP015, MSTP014, MSTP013, MSTP012, MSTP011, MSTP010,
+       MSTP007, MSTP006, MSTP005, MSTP002, MSTP001,
+       MSTP109, MSTP100,
+       MSTP227, MSTP226, MSTP224, MSTP223, MSTP222, MSTP218, MSTP217,
+       MSTP211, MSTP207, MSTP205, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
+       MSTP_NR };
 
-static struct clk mstp_clks[] = {
+static struct clk mstp_clks[MSTP_NR] = {
        /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
-       MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
-       MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
-       MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
-       MSTP("rsmem0", &div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
-       MSTP("xymem0", &div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
-       MSTP("intc3", &div4_clks[DIV4_P], MSTPCR0, 23, 0),
-       MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 0),
-       MSTP("dmac0", &div4_clks[DIV4_P], MSTPCR0, 21, 0),
-       MSTP("sh0", &div4_clks[DIV4_P], MSTPCR0, 20, 0),
-       MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0),
-       MSTP("ubc0", &div4_clks[DIV4_P], MSTPCR0, 17, 0),
-       MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0),
-       MSTP("cmt0", &r_clk, MSTPCR0, 14, 0),
-       MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0),
-       MSTP("mfi0", &div4_clks[DIV4_P], MSTPCR0, 11, 0),
-       MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0),
-       MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 7, 0),
-       MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 6, 0),
-       MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 5, 0),
-       MSTP("msiof0", &div4_clks[DIV4_P], MSTPCR0, 2, 0),
-       MSTP("sbr0", &div4_clks[DIV4_P], MSTPCR0, 1, 0),
-
-       MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0),
-
-       MSTP("icb0", &div4_clks[DIV4_P], MSTPCR2, 27, 0),
-       MSTP("meram0", &div4_clks[DIV4_P], MSTPCR2, 26, 0),
-       MSTP("dacy1", &div4_clks[DIV4_P], MSTPCR2, 24, 0),
-       MSTP("dacy0", &div4_clks[DIV4_P], MSTPCR2, 23, 0),
-       MSTP("tsif0", &div4_clks[DIV4_P], MSTPCR2, 22, 0),
-       MSTP("sdhi0", &div4_clks[DIV4_P], MSTPCR2, 18, 0),
-       MSTP("mmcif0", &div4_clks[DIV4_P], MSTPCR2, 17, 0),
-       MSTP("usbf0", &div4_clks[DIV4_P], MSTPCR2, 11, 0),
-       MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 9, 0),
-       MSTP("veu1", &div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),
-       MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0),
-       MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0),
-       MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0),
-       MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
-       MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
-       MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0),
+       [MSTP031] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
+       [MSTP030] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
+       [MSTP029] = MSTP(&div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
+       [MSTP028] = MSTP(&div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
+       [MSTP026] = MSTP(&div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
+       [MSTP023] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 23, 0),
+       [MSTP022] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 22, 0),
+       [MSTP021] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
+       [MSTP020] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 20, 0),
+       [MSTP019] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 19, 0),
+       [MSTP017] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 17, 0),
+       [MSTP015] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 15, 0),
+       [MSTP014] = MSTP(&r_clk, MSTPCR0, 14, 0),
+       [MSTP013] = MSTP(&r_clk, MSTPCR0, 13, 0),
+       [MSTP011] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 11, 0),
+       [MSTP010] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 10, 0),
+       [MSTP007] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 7, 0),
+       [MSTP006] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 6, 0),
+       [MSTP005] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 5, 0),
+       [MSTP002] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
+       [MSTP001] = MSTP(&div4_clks[DIV4_P], MSTPCR0, 1, 0),
+
+       [MSTP109] = MSTP(&div4_clks[DIV4_P], MSTPCR1, 9, 0),
+
+       [MSTP227] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 27, 0),
+       [MSTP226] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 26, 0),
+       [MSTP224] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 24, 0),
+       [MSTP223] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 23, 0),
+       [MSTP222] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 22, 0),
+       [MSTP218] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 18, 0),
+       [MSTP217] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 17, 0),
+       [MSTP211] = MSTP(&div4_clks[DIV4_P], MSTPCR2, 11, 0),
+       [MSTP207] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),
+       [MSTP205] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 5, 0),
+       [MSTP204] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 4, 0),
+       [MSTP203] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 3, 0),
+       [MSTP202] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
+       [MSTP201] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
+       [MSTP200] = MSTP(&div4_clks[DIV4_B], MSTPCR2, 0, 0),
+};
+
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("rclk", &r_clk),
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("dll_clk", &dll_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+       CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("siua_clk", &div4_clks[DIV4_SIUA]),
+       CLKDEV_CON_ID("siub_clk", &div4_clks[DIV4_SIUB]),
+
+       /* DIV6 clocks */
+       CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
+
+       /* MSTP32 clocks */
+       CLKDEV_CON_ID("tlb0", &mstp_clks[MSTP031]),
+       CLKDEV_CON_ID("ic0", &mstp_clks[MSTP030]),
+       CLKDEV_CON_ID("oc0", &mstp_clks[MSTP029]),
+       CLKDEV_CON_ID("rsmem0", &mstp_clks[MSTP028]),
+       CLKDEV_CON_ID("xymem0", &mstp_clks[MSTP026]),
+       CLKDEV_CON_ID("intc3", &mstp_clks[MSTP023]),
+       CLKDEV_CON_ID("intc0", &mstp_clks[MSTP022]),
+       CLKDEV_CON_ID("dmac0", &mstp_clks[MSTP021]),
+       CLKDEV_CON_ID("sh0", &mstp_clks[MSTP020]),
+       CLKDEV_CON_ID("hudi0", &mstp_clks[MSTP019]),
+       CLKDEV_CON_ID("ubc0", &mstp_clks[MSTP017]),
+       CLKDEV_CON_ID("tmu_fck", &mstp_clks[MSTP015]),
+       CLKDEV_CON_ID("cmt_fck", &mstp_clks[MSTP014]),
+       CLKDEV_CON_ID("rwdt0", &mstp_clks[MSTP013]),
+       CLKDEV_CON_ID("mfi0", &mstp_clks[MSTP011]),
+       CLKDEV_CON_ID("flctl0", &mstp_clks[MSTP010]),
+       {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP007],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP006],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP005],
+       },
+       CLKDEV_CON_ID("msiof0", &mstp_clks[MSTP002]),
+       CLKDEV_CON_ID("sbr0", &mstp_clks[MSTP001]),
+       CLKDEV_CON_ID("i2c0", &mstp_clks[MSTP109]),
+       CLKDEV_CON_ID("icb0", &mstp_clks[MSTP227]),
+       CLKDEV_CON_ID("meram0", &mstp_clks[MSTP226]),
+       CLKDEV_CON_ID("dacy1", &mstp_clks[MSTP224]),
+       CLKDEV_CON_ID("dacy0", &mstp_clks[MSTP223]),
+       CLKDEV_CON_ID("tsif0", &mstp_clks[MSTP222]),
+       CLKDEV_CON_ID("sdhi0", &mstp_clks[MSTP218]),
+       CLKDEV_CON_ID("mmcif0", &mstp_clks[MSTP217]),
+       CLKDEV_CON_ID("usbf0", &mstp_clks[MSTP211]),
+       CLKDEV_CON_ID("veu1", &mstp_clks[MSTP207]),
+       CLKDEV_CON_ID("vou0", &mstp_clks[MSTP205]),
+       CLKDEV_CON_ID("beu0", &mstp_clks[MSTP204]),
+       CLKDEV_CON_ID("ceu0", &mstp_clks[MSTP203]),
+       CLKDEV_CON_ID("veu0", &mstp_clks[MSTP202]),
+       CLKDEV_CON_ID("vpu0", &mstp_clks[MSTP201]),
+       CLKDEV_CON_ID("lcdc0", &mstp_clks[MSTP200]),
 };
 
 int __init arch_clk_init(void)
@@ -202,14 +280,16 @@ int __init arch_clk_init(void)
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
                ret = clk_register(main_clks[k]);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
 
        if (!ret)
-               ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
+               ret = sh_clk_div6_register(div6_clks, DIV6_NR);
 
        if (!ret)
-               ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
 
        return ret;
 }
index 15db6d5..2030f3d 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/hwblk.h>
 #include <cpu/sh7722.h>
@@ -36,8 +37,6 @@
 
 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
 static struct clk r_clk = {
-       .name           = "rclk",
-       .id             = -1,
        .rate           = 32768,
 };
 
@@ -46,8 +45,6 @@ static struct clk r_clk = {
  * from the platform code.
  */
 struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -69,8 +66,6 @@ static struct clk_ops dll_clk_ops = {
 };
 
 static struct clk dll_clk = {
-       .name           = "dll_clk",
-       .id             = -1,
        .ops            = &dll_clk_ops,
        .parent         = &r_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -94,8 +89,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -121,68 +114,142 @@ static struct clk_div4_table div4_table = {
        .div_mult_table = &div4_div_mult_table,
 };
 
-#define DIV4(_str, _reg, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
+#define DIV4(_reg, _bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
 
 enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
-       [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
-       [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
+       [DIV4_I] = DIV4(FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
+       [DIV4_U] = DIV4(FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_B3] = DIV4(FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(FRQCR, 0, 0x1fff, 0),
 };
 
 enum { DIV4_IRDA, DIV4_ENABLE_NR };
 
 struct clk div4_enable_clks[DIV4_ENABLE_NR] = {
-       [DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x1fff, 0),
+       [DIV4_IRDA] = DIV4(IRDACLKCR, 0, 0x1fff, 0),
 };
 
 enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };
 
 struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {
-       [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
-       [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
+       [DIV4_SIUA] = DIV4(SCLKACR, 0, 0x1fff, 0),
+       [DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x1fff, 0),
 };
 
-struct clk div6_clks[] = {
-       SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
+enum { DIV6_V, DIV6_NR };
+
+struct clk div6_clks[DIV6_NR] = {
+       [DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
+};
+
+static struct clk mstp_clks[HWBLK_NR] = {
+       SH_HWBLK_CLK(HWBLK_URAM, &div4_clks[DIV4_U], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_XYMEM, &div4_clks[DIV4_B], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_TMU, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_CMT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_RWDT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_FLCTL, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF1, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF2, &div4_clks[DIV4_P], 0),
+
+       SH_HWBLK_CLK(HWBLK_IIC, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_RTC, &r_clk, 0),
+
+       SH_HWBLK_CLK(HWBLK_SDHI, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_KEYSC, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_USBF, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_2DG, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SIU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VOU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_JPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_BEU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_CEU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VEU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_LCDC, &div4_clks[DIV4_P], 0),
 };
 
-#define R_CLK &r_clk
-#define P_CLK &div4_clks[DIV4_P]
-#define B_CLK &div4_clks[DIV4_B]
-#define U_CLK &div4_clks[DIV4_U]
-
-static struct clk mstp_clks[] = {
-       SH_HWBLK_CLK("uram0", -1, U_CLK, HWBLK_URAM, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("xymem0", -1, B_CLK, HWBLK_XYMEM, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("tmu0", -1, P_CLK, HWBLK_TMU, 0),
-       SH_HWBLK_CLK("cmt0", -1, R_CLK, HWBLK_CMT, 0),
-       SH_HWBLK_CLK("rwdt0", -1, R_CLK, HWBLK_RWDT, 0),
-       SH_HWBLK_CLK("flctl0", -1, P_CLK, HWBLK_FLCTL, 0),
-       SH_HWBLK_CLK("scif0", -1, P_CLK, HWBLK_SCIF0, 0),
-       SH_HWBLK_CLK("scif1", -1, P_CLK, HWBLK_SCIF1, 0),
-       SH_HWBLK_CLK("scif2", -1, P_CLK, HWBLK_SCIF2, 0),
-
-       SH_HWBLK_CLK("i2c0", -1, P_CLK, HWBLK_IIC, 0),
-       SH_HWBLK_CLK("rtc0", -1, R_CLK, HWBLK_RTC, 0),
-
-       SH_HWBLK_CLK("sdhi0", -1, P_CLK, HWBLK_SDHI, 0),
-       SH_HWBLK_CLK("keysc0", -1, R_CLK, HWBLK_KEYSC, 0),
-       SH_HWBLK_CLK("usbf0", -1, P_CLK, HWBLK_USBF, 0),
-       SH_HWBLK_CLK("2dg0", -1, B_CLK, HWBLK_2DG, 0),
-       SH_HWBLK_CLK("siu0", -1, B_CLK, HWBLK_SIU, 0),
-       SH_HWBLK_CLK("vou0", -1, B_CLK, HWBLK_VOU, 0),
-       SH_HWBLK_CLK("jpu0", -1, B_CLK, HWBLK_JPU, 0),
-       SH_HWBLK_CLK("beu0", -1, B_CLK, HWBLK_BEU, 0),
-       SH_HWBLK_CLK("ceu0", -1, B_CLK, HWBLK_CEU, 0),
-       SH_HWBLK_CLK("veu0", -1, B_CLK, HWBLK_VEU, 0),
-       SH_HWBLK_CLK("vpu0", -1, B_CLK, HWBLK_VPU, 0),
-       SH_HWBLK_CLK("lcdc0", -1, P_CLK, HWBLK_LCDC, 0),
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("rclk", &r_clk),
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("dll_clk", &dll_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+       CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("irda_clk", &div4_enable_clks[DIV4_IRDA]),
+       CLKDEV_CON_ID("siua_clk", &div4_reparent_clks[DIV4_SIUA]),
+       CLKDEV_CON_ID("siub_clk", &div4_reparent_clks[DIV4_SIUB]),
+
+       /* DIV6 clocks */
+       CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
+
+       /* MSTP clocks */
+       CLKDEV_CON_ID("uram0", &mstp_clks[HWBLK_URAM]),
+       CLKDEV_CON_ID("xymem0", &mstp_clks[HWBLK_XYMEM]),
+       {
+               /* TMU0 */
+               .dev_id         = "sh_tmu.0",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU],
+       }, {
+               /* TMU1 */
+               .dev_id         = "sh_tmu.1",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU],
+       }, {
+               /* TMU2 */
+               .dev_id         = "sh_tmu.2",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU],
+       },
+       CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),
+       CLKDEV_CON_ID("rwdt0", &mstp_clks[HWBLK_RWDT]),
+       CLKDEV_CON_ID("flctl0", &mstp_clks[HWBLK_FLCTL]),
+       {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF0],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF1],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF2],
+       },
+       CLKDEV_CON_ID("i2c0", &mstp_clks[HWBLK_IIC]),
+       CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),
+       CLKDEV_CON_ID("sdhi0", &mstp_clks[HWBLK_SDHI]),
+       CLKDEV_CON_ID("keysc0", &mstp_clks[HWBLK_KEYSC]),
+       CLKDEV_CON_ID("usbf0", &mstp_clks[HWBLK_USBF]),
+       CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),
+       CLKDEV_CON_ID("siu0", &mstp_clks[HWBLK_SIU]),
+       CLKDEV_CON_ID("vou0", &mstp_clks[HWBLK_VOU]),
+       CLKDEV_CON_ID("jpu0", &mstp_clks[HWBLK_JPU]),
+       CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU]),
+       CLKDEV_CON_ID("ceu0", &mstp_clks[HWBLK_CEU]),
+       CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU]),
+       CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
+       CLKDEV_CON_ID("lcdc0", &mstp_clks[HWBLK_LCDC]),
 };
 
 int __init arch_clk_init(void)
@@ -198,6 +265,8 @@ int __init arch_clk_init(void)
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
                ret = clk_register(main_clks[k]);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
 
@@ -210,10 +279,10 @@ int __init arch_clk_init(void)
                                        DIV4_REPARENT_NR, &div4_table);
 
        if (!ret)
-               ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
+               ret = sh_clk_div6_register(div6_clks, DIV6_NR);
 
        if (!ret)
-               ret = sh_hwblk_clk_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);
 
        return ret;
 }
index 50babe0..d3938f0 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/clk.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/hwblk.h>
 #include <cpu/sh7723.h>
@@ -36,8 +38,6 @@
 
 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
 static struct clk r_clk = {
-       .name           = "rclk",
-       .id             = -1,
        .rate           = 32768,
 };
 
@@ -46,8 +46,6 @@ static struct clk r_clk = {
  * from the platform code.
  */
 struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -69,8 +67,6 @@ static struct clk_ops dll_clk_ops = {
 };
 
 static struct clk dll_clk = {
-       .name           = "dll_clk",
-       .id             = -1,
        .ops            = &dll_clk_ops,
        .parent         = &r_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -94,8 +90,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -123,92 +117,215 @@ static struct clk_div4_table div4_table = {
 
 enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P, DIV4_NR };
 
-#define DIV4(_str, _reg, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
+#define DIV4(_reg, _bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x0dbf, CLK_ENABLE_ON_INIT),
-       [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x0dbf, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x0dbf, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x0dbf, CLK_ENABLE_ON_INIT),
-       [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x0db4, CLK_ENABLE_ON_INIT),
-       [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x0dbf, 0),
+       [DIV4_I] = DIV4(FRQCR, 20, 0x0dbf, CLK_ENABLE_ON_INIT),
+       [DIV4_U] = DIV4(FRQCR, 16, 0x0dbf, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(FRQCR, 12, 0x0dbf, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(FRQCR, 8, 0x0dbf, CLK_ENABLE_ON_INIT),
+       [DIV4_B3] = DIV4(FRQCR, 4, 0x0db4, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(FRQCR, 0, 0x0dbf, 0),
 };
 
 enum { DIV4_IRDA, DIV4_ENABLE_NR };
 
 struct clk div4_enable_clks[DIV4_ENABLE_NR] = {
-       [DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x0dbf, 0),
+       [DIV4_IRDA] = DIV4(IRDACLKCR, 0, 0x0dbf, 0),
 };
 
 enum { DIV4_SIUA, DIV4_SIUB, DIV4_REPARENT_NR };
 
 struct clk div4_reparent_clks[DIV4_REPARENT_NR] = {
-       [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x0dbf, 0),
-       [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x0dbf, 0),
-};
-struct clk div6_clks[] = {
-       SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
+       [DIV4_SIUA] = DIV4(SCLKACR, 0, 0x0dbf, 0),
+       [DIV4_SIUB] = DIV4(SCLKBCR, 0, 0x0dbf, 0),
 };
+enum { DIV6_V, DIV6_NR };
 
-#define R_CLK (&r_clk)
-#define P_CLK (&div4_clks[DIV4_P])
-#define B_CLK (&div4_clks[DIV4_B])
-#define U_CLK (&div4_clks[DIV4_U])
-#define I_CLK (&div4_clks[DIV4_I])
-#define SH_CLK (&div4_clks[DIV4_SH])
+struct clk div6_clks[DIV6_NR] = {
+       [DIV6_V] = SH_CLK_DIV6(&pll_clk, VCLKCR, 0),
+};
 
 static struct clk mstp_clks[] = {
        /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
-       SH_HWBLK_CLK("tlb0", -1, I_CLK, HWBLK_TLB, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("ic0", -1, I_CLK, HWBLK_IC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("oc0", -1, I_CLK, HWBLK_OC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("l2c0", -1, SH_CLK, HWBLK_L2C, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("ilmem0", -1, I_CLK, HWBLK_ILMEM, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("fpu0", -1, I_CLK, HWBLK_FPU, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("intc0", -1, I_CLK, HWBLK_INTC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("dmac0", -1, B_CLK, HWBLK_DMAC0, 0),
-       SH_HWBLK_CLK("sh0", -1, SH_CLK, HWBLK_SHYWAY, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("hudi0", -1, P_CLK, HWBLK_HUDI, 0),
-       SH_HWBLK_CLK("ubc0", -1, I_CLK, HWBLK_UBC, 0),
-       SH_HWBLK_CLK("tmu0", -1, P_CLK, HWBLK_TMU0, 0),
-       SH_HWBLK_CLK("cmt0", -1, R_CLK, HWBLK_CMT, 0),
-       SH_HWBLK_CLK("rwdt0", -1, R_CLK, HWBLK_RWDT, 0),
-       SH_HWBLK_CLK("dmac1", -1, B_CLK, HWBLK_DMAC1, 0),
-       SH_HWBLK_CLK("tmu1", -1, P_CLK, HWBLK_TMU1, 0),
-       SH_HWBLK_CLK("flctl0", -1, P_CLK, HWBLK_FLCTL, 0),
-       SH_HWBLK_CLK("scif0", -1, P_CLK, HWBLK_SCIF0, 0),
-       SH_HWBLK_CLK("scif1", -1, P_CLK, HWBLK_SCIF1, 0),
-       SH_HWBLK_CLK("scif2", -1, P_CLK, HWBLK_SCIF2, 0),
-       SH_HWBLK_CLK("scif3", -1, B_CLK, HWBLK_SCIF3, 0),
-       SH_HWBLK_CLK("scif4", -1, B_CLK, HWBLK_SCIF4, 0),
-       SH_HWBLK_CLK("scif5", -1, B_CLK, HWBLK_SCIF5, 0),
-       SH_HWBLK_CLK("msiof0", -1, B_CLK, HWBLK_MSIOF0, 0),
-       SH_HWBLK_CLK("msiof1", -1, B_CLK, HWBLK_MSIOF1, 0),
-       SH_HWBLK_CLK("meram0", -1, SH_CLK, HWBLK_MERAM, 0),
-
-       SH_HWBLK_CLK("i2c0", -1, P_CLK, HWBLK_IIC, 0),
-       SH_HWBLK_CLK("rtc0", -1, R_CLK, HWBLK_RTC, 0),
-
-       SH_HWBLK_CLK("atapi0", -1, SH_CLK, HWBLK_ATAPI, 0),
-       SH_HWBLK_CLK("adc0", -1, P_CLK, HWBLK_ADC, 0),
-       SH_HWBLK_CLK("tpu0", -1, B_CLK, HWBLK_TPU, 0),
-       SH_HWBLK_CLK("irda0", -1, P_CLK, HWBLK_IRDA, 0),
-       SH_HWBLK_CLK("tsif0", -1, B_CLK, HWBLK_TSIF, 0),
-       SH_HWBLK_CLK("icb0", -1, B_CLK, HWBLK_ICB, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("sdhi0", -1, B_CLK, HWBLK_SDHI0, 0),
-       SH_HWBLK_CLK("sdhi1", -1, B_CLK, HWBLK_SDHI1, 0),
-       SH_HWBLK_CLK("keysc0", -1, R_CLK, HWBLK_KEYSC, 0),
-       SH_HWBLK_CLK("usb0", -1, B_CLK, HWBLK_USB, 0),
-       SH_HWBLK_CLK("2dg0", -1, B_CLK, HWBLK_2DG, 0),
-       SH_HWBLK_CLK("siu0", -1, B_CLK, HWBLK_SIU, 0),
-       SH_HWBLK_CLK("veu1", -1, B_CLK, HWBLK_VEU2H1, 0),
-       SH_HWBLK_CLK("vou0", -1, B_CLK, HWBLK_VOU, 0),
-       SH_HWBLK_CLK("beu0", -1, B_CLK, HWBLK_BEU, 0),
-       SH_HWBLK_CLK("ceu0", -1, B_CLK, HWBLK_CEU, 0),
-       SH_HWBLK_CLK("veu0", -1, B_CLK, HWBLK_VEU2H0, 0),
-       SH_HWBLK_CLK("vpu0", -1, B_CLK, HWBLK_VPU, 0),
-       SH_HWBLK_CLK("lcdc0", -1, B_CLK, HWBLK_LCDC, 0),
+       SH_HWBLK_CLK(HWBLK_TLB, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_IC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_OC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_L2C, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_ILMEM, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_FPU, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_INTC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_DMAC0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SHYWAY, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_HUDI, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_UBC, &div4_clks[DIV4_I], 0),
+       SH_HWBLK_CLK(HWBLK_TMU0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_CMT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_RWDT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_DMAC1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_TMU1, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_FLCTL, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF1, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF2, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF3, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF4, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF5, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_MSIOF0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_MSIOF1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_MERAM, &div4_clks[DIV4_SH], 0),
+
+       SH_HWBLK_CLK(HWBLK_IIC, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_RTC, &r_clk, 0),
+
+       SH_HWBLK_CLK(HWBLK_ATAPI, &div4_clks[DIV4_SH], 0),
+       SH_HWBLK_CLK(HWBLK_ADC, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_TPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_IRDA, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_TSIF, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_ICB, &div4_clks[DIV4_B], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_SDHI0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SDHI1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_KEYSC, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_USB, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_2DG, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SIU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VEU2H1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VOU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_BEU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_CEU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VEU2H0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_LCDC, &div4_clks[DIV4_B], 0),
+};
+
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("rclk", &r_clk),
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("dll_clk", &dll_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+       CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("b3_clk", &div4_clks[DIV4_B3]),
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("irda_clk", &div4_enable_clks[DIV4_IRDA]),
+       CLKDEV_CON_ID("siua_clk", &div4_reparent_clks[DIV4_SIUA]),
+       CLKDEV_CON_ID("siub_clk", &div4_reparent_clks[DIV4_SIUB]),
+
+       /* DIV6 clocks */
+       CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
+
+       /* MSTP clocks */
+       CLKDEV_CON_ID("tlb0", &mstp_clks[HWBLK_TLB]),
+       CLKDEV_CON_ID("ic0", &mstp_clks[HWBLK_IC]),
+       CLKDEV_CON_ID("oc0", &mstp_clks[HWBLK_OC]),
+       CLKDEV_CON_ID("l2c0", &mstp_clks[HWBLK_L2C]),
+       CLKDEV_CON_ID("ilmem0", &mstp_clks[HWBLK_ILMEM]),
+       CLKDEV_CON_ID("fpu0", &mstp_clks[HWBLK_FPU]),
+       CLKDEV_CON_ID("intc0", &mstp_clks[HWBLK_INTC]),
+       CLKDEV_CON_ID("dmac0", &mstp_clks[HWBLK_DMAC0]),
+       CLKDEV_CON_ID("sh0", &mstp_clks[HWBLK_SHYWAY]),
+       CLKDEV_CON_ID("hudi0", &mstp_clks[HWBLK_HUDI]),
+       CLKDEV_CON_ID("ubc0", &mstp_clks[HWBLK_UBC]),
+       {
+               /* TMU0 */
+               .dev_id         = "sh_tmu.0",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       }, {
+               /* TMU1 */
+               .dev_id         = "sh_tmu.1",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       }, {
+               /* TMU2 */
+               .dev_id         = "sh_tmu.2",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       },
+       CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),
+       CLKDEV_CON_ID("rwdt0", &mstp_clks[HWBLK_RWDT]),
+       CLKDEV_CON_ID("dmac1", &mstp_clks[HWBLK_DMAC1]),
+       {
+               /* TMU3 */
+               .dev_id         = "sh_tmu.3",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       }, {
+               /* TMU4 */
+               .dev_id         = "sh_tmu.4",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       }, {
+               /* TMU5 */
+               .dev_id         = "sh_tmu.5",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       },
+       CLKDEV_CON_ID("flctl0", &mstp_clks[HWBLK_FLCTL]),
+       {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF0],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF1],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF2],
+       }, {
+               /* SCIF3 */
+               .dev_id         = "sh-sci.3",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF3],
+       }, {
+               /* SCIF4 */
+               .dev_id         = "sh-sci.4",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF4],
+       }, {
+               /* SCIF5 */
+               .dev_id         = "sh-sci.5",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF5],
+       },
+       CLKDEV_CON_ID("msiof0", &mstp_clks[HWBLK_MSIOF0]),
+       CLKDEV_CON_ID("msiof1", &mstp_clks[HWBLK_MSIOF1]),
+       CLKDEV_CON_ID("meram0", &mstp_clks[HWBLK_MERAM]),
+       CLKDEV_CON_ID("i2c0", &mstp_clks[HWBLK_IIC]),
+       CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),
+       CLKDEV_CON_ID("atapi0", &mstp_clks[HWBLK_ATAPI]),
+       CLKDEV_CON_ID("adc0", &mstp_clks[HWBLK_ADC]),
+       CLKDEV_CON_ID("tpu0", &mstp_clks[HWBLK_TPU]),
+       CLKDEV_CON_ID("irda0", &mstp_clks[HWBLK_IRDA]),
+       CLKDEV_CON_ID("tsif0", &mstp_clks[HWBLK_TSIF]),
+       CLKDEV_CON_ID("icb0", &mstp_clks[HWBLK_ICB]),
+       CLKDEV_CON_ID("sdhi0", &mstp_clks[HWBLK_SDHI0]),
+       CLKDEV_CON_ID("sdhi1", &mstp_clks[HWBLK_SDHI1]),
+       CLKDEV_CON_ID("keysc0", &mstp_clks[HWBLK_KEYSC]),
+       CLKDEV_CON_ID("usb0", &mstp_clks[HWBLK_USB]),
+       CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),
+       CLKDEV_CON_ID("siu0", &mstp_clks[HWBLK_SIU]),
+       CLKDEV_CON_ID("veu1", &mstp_clks[HWBLK_VEU2H1]),
+       CLKDEV_CON_ID("vou0", &mstp_clks[HWBLK_VOU]),
+       CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU]),
+       CLKDEV_CON_ID("ceu0", &mstp_clks[HWBLK_CEU]),
+       CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU2H0]),
+       CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
+       CLKDEV_CON_ID("lcdc0", &mstp_clks[HWBLK_LCDC]),
 };
 
 int __init arch_clk_init(void)
@@ -222,7 +339,9 @@ int __init arch_clk_init(void)
                pll_clk.parent = &extal_clk;
 
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
-               ret = clk_register(main_clks[k]);
+               ret |= clk_register(main_clks[k]);
+
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
 
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
@@ -236,10 +355,10 @@ int __init arch_clk_init(void)
                                        DIV4_REPARENT_NR, &div4_table);
 
        if (!ret)
-               ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
+               ret = sh_clk_div6_register(div6_clks, DIV6_NR);
 
        if (!ret)
-               ret = sh_hwblk_clk_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);
 
        return ret;
 }
index 6707061..2d9700c 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <linux/clk.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/hwblk.h>
 #include <cpu/sh7724.h>
@@ -39,8 +41,6 @@
 
 /* Fixed 32 KHz root clock for RTC and Power Management purposes */
 static struct clk r_clk = {
-       .name           = "rclk",
-       .id             = -1,
        .rate           = 32768,
 };
 
@@ -49,8 +49,6 @@ static struct clk r_clk = {
  * from the platform code.
  */
 struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -74,8 +72,6 @@ static struct clk_ops fll_clk_ops = {
 };
 
 static struct clk fll_clk = {
-       .name           = "fll_clk",
-       .id             = -1,
        .ops            = &fll_clk_ops,
        .parent         = &r_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -96,8 +92,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .flags          = CLK_ENABLE_ON_INIT,
 };
@@ -113,8 +107,6 @@ static struct clk_ops div3_clk_ops = {
 };
 
 static struct clk div3_clk = {
-       .name           = "div3_clk",
-       .id             = -1,
        .ops            = &div3_clk_ops,
        .parent         = &pll_clk,
 };
@@ -151,86 +143,215 @@ static struct clk_div4_table div4_table = {
 
 enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_P, DIV4_M1, DIV4_NR };
 
-#define DIV4(_str, _reg, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
+#define DIV4(_reg, _bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, _reg, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_I] = DIV4("cpu_clk", FRQCRA, 20, 0x2f7d, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", FRQCRA, 12, 0x2f7c, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", FRQCRA, 8, 0x2f7c, CLK_ENABLE_ON_INIT),
-       [DIV4_P] = DIV4("peripheral_clk", FRQCRA, 0, 0x2f7c, 0),
-       [DIV4_M1] = DIV4("vpu_clk", FRQCRB, 4, 0x2f7c, CLK_ENABLE_ON_INIT),
+       [DIV4_I] = DIV4(FRQCRA, 20, 0x2f7d, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(FRQCRA, 12, 0x2f7c, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(FRQCRA, 8, 0x2f7c, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(FRQCRA, 0, 0x2f7c, 0),
+       [DIV4_M1] = DIV4(FRQCRB, 4, 0x2f7c, CLK_ENABLE_ON_INIT),
 };
 
-struct clk div6_clks[] = {
-       SH_CLK_DIV6("video_clk", &div3_clk, VCLKCR, 0),
-       SH_CLK_DIV6("fsia_clk", &div3_clk, FCLKACR, 0),
-       SH_CLK_DIV6("fsib_clk", &div3_clk, FCLKBCR, 0),
-       SH_CLK_DIV6("irda_clk", &div3_clk, IRDACLKCR, 0),
-       SH_CLK_DIV6("spu_clk", &div3_clk, SPUCLKCR, CLK_ENABLE_ON_INIT),
+enum { DIV6_V, DIV6_FA, DIV6_FB, DIV6_I, DIV6_S, DIV6_NR };
+
+struct clk div6_clks[DIV6_NR] = {
+       [DIV6_V] = SH_CLK_DIV6(&div3_clk, VCLKCR, 0),
+       [DIV6_FA] = SH_CLK_DIV6(&div3_clk, FCLKACR, 0),
+       [DIV6_FB] = SH_CLK_DIV6(&div3_clk, FCLKBCR, 0),
+       [DIV6_I] = SH_CLK_DIV6(&div3_clk, IRDACLKCR, 0),
+       [DIV6_S] = SH_CLK_DIV6(&div3_clk, SPUCLKCR, CLK_ENABLE_ON_INIT),
+};
+
+static struct clk mstp_clks[HWBLK_NR] = {
+       SH_HWBLK_CLK(HWBLK_TLB, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_IC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_OC, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_RSMEM, &div4_clks[DIV4_B], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_ILMEM, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_L2C, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_FPU, &div4_clks[DIV4_I], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_INTC, &div4_clks[DIV4_P], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_DMAC0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SHYWAY, &div4_clks[DIV4_SH], CLK_ENABLE_ON_INIT),
+       SH_HWBLK_CLK(HWBLK_HUDI, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_UBC, &div4_clks[DIV4_I], 0),
+       SH_HWBLK_CLK(HWBLK_TMU0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_CMT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_RWDT, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_DMAC1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_TMU1, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF1, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF2, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF3, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF4, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SCIF5, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_MSIOF0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_MSIOF1, &div4_clks[DIV4_B], 0),
+
+       SH_HWBLK_CLK(HWBLK_KEYSC, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_RTC, &r_clk, 0),
+       SH_HWBLK_CLK(HWBLK_IIC0, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_IIC1, &div4_clks[DIV4_P], 0),
+
+       SH_HWBLK_CLK(HWBLK_MMC, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_ETHER, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_ATAPI, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_TPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_IRDA, &div4_clks[DIV4_P], 0),
+       SH_HWBLK_CLK(HWBLK_TSIF, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_USB1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_USB0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_2DG, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SDHI0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_SDHI1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VEU1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_CEU1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_BEU1, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_2DDMAC, &div4_clks[DIV4_SH], 0),
+       SH_HWBLK_CLK(HWBLK_SPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_JPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VOU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_BEU0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_CEU0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VEU0, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_VPU, &div4_clks[DIV4_B], 0),
+       SH_HWBLK_CLK(HWBLK_LCDC, &div4_clks[DIV4_B], 0),
 };
 
-#define R_CLK (&r_clk)
-#define P_CLK (&div4_clks[DIV4_P])
-#define B_CLK (&div4_clks[DIV4_B])
-#define I_CLK (&div4_clks[DIV4_I])
-#define SH_CLK (&div4_clks[DIV4_SH])
-
-static struct clk mstp_clks[] = {
-       SH_HWBLK_CLK("tlb0", -1, I_CLK, HWBLK_TLB, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("ic0", -1, I_CLK, HWBLK_IC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("oc0", -1, I_CLK, HWBLK_OC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("rs0", -1, B_CLK, HWBLK_RSMEM, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("ilmem0", -1, I_CLK, HWBLK_ILMEM, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("l2c0", -1, SH_CLK, HWBLK_L2C, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("fpu0", -1, I_CLK, HWBLK_FPU, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("intc0", -1, P_CLK, HWBLK_INTC, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("dmac0", -1, B_CLK, HWBLK_DMAC0, 0),
-       SH_HWBLK_CLK("sh0", -1, SH_CLK, HWBLK_SHYWAY, CLK_ENABLE_ON_INIT),
-       SH_HWBLK_CLK("hudi0", -1, P_CLK, HWBLK_HUDI, 0),
-       SH_HWBLK_CLK("ubc0", -1, I_CLK, HWBLK_UBC, 0),
-       SH_HWBLK_CLK("tmu0", -1, P_CLK, HWBLK_TMU0, 0),
-       SH_HWBLK_CLK("cmt0", -1, R_CLK, HWBLK_CMT, 0),
-       SH_HWBLK_CLK("rwdt0", -1, R_CLK, HWBLK_RWDT, 0),
-       SH_HWBLK_CLK("dmac1", -1, B_CLK, HWBLK_DMAC1, 0),
-       SH_HWBLK_CLK("tmu1", -1, P_CLK, HWBLK_TMU1, 0),
-       SH_HWBLK_CLK("scif0", -1, P_CLK, HWBLK_SCIF0, 0),
-       SH_HWBLK_CLK("scif1", -1, P_CLK, HWBLK_SCIF1, 0),
-       SH_HWBLK_CLK("scif2", -1, P_CLK, HWBLK_SCIF2, 0),
-       SH_HWBLK_CLK("scif3", -1, B_CLK, HWBLK_SCIF3, 0),
-       SH_HWBLK_CLK("scif4", -1, B_CLK, HWBLK_SCIF4, 0),
-       SH_HWBLK_CLK("scif5", -1, B_CLK, HWBLK_SCIF5, 0),
-       SH_HWBLK_CLK("msiof0", -1, B_CLK, HWBLK_MSIOF0, 0),
-       SH_HWBLK_CLK("msiof1", -1, B_CLK, HWBLK_MSIOF1, 0),
-
-       SH_HWBLK_CLK("keysc0", -1, R_CLK, HWBLK_KEYSC, 0),
-       SH_HWBLK_CLK("rtc0", -1, R_CLK, HWBLK_RTC, 0),
-       SH_HWBLK_CLK("i2c0", -1, P_CLK, HWBLK_IIC0, 0),
-       SH_HWBLK_CLK("i2c1", -1, P_CLK, HWBLK_IIC1, 0),
-
-       SH_HWBLK_CLK("mmc0", -1, B_CLK, HWBLK_MMC, 0),
-       SH_HWBLK_CLK("eth0", -1, B_CLK, HWBLK_ETHER, 0),
-       SH_HWBLK_CLK("atapi0", -1, B_CLK, HWBLK_ATAPI, 0),
-       SH_HWBLK_CLK("tpu0", -1, B_CLK, HWBLK_TPU, 0),
-       SH_HWBLK_CLK("irda0", -1, P_CLK, HWBLK_IRDA, 0),
-       SH_HWBLK_CLK("tsif0", -1, B_CLK, HWBLK_TSIF, 0),
-       SH_HWBLK_CLK("usb1", -1, B_CLK, HWBLK_USB1, 0),
-       SH_HWBLK_CLK("usb0", -1, B_CLK, HWBLK_USB0, 0),
-       SH_HWBLK_CLK("2dg0", -1, B_CLK, HWBLK_2DG, 0),
-       SH_HWBLK_CLK("sdhi0", -1, B_CLK, HWBLK_SDHI0, 0),
-       SH_HWBLK_CLK("sdhi1", -1, B_CLK, HWBLK_SDHI1, 0),
-       SH_HWBLK_CLK("veu1", -1, B_CLK, HWBLK_VEU1, 0),
-       SH_HWBLK_CLK("ceu1", -1, B_CLK, HWBLK_CEU1, 0),
-       SH_HWBLK_CLK("beu1", -1, B_CLK, HWBLK_BEU1, 0),
-       SH_HWBLK_CLK("2ddmac0", -1, SH_CLK, HWBLK_2DDMAC, 0),
-       SH_HWBLK_CLK("spu0", -1, B_CLK, HWBLK_SPU, 0),
-       SH_HWBLK_CLK("jpu0", -1, B_CLK, HWBLK_JPU, 0),
-       SH_HWBLK_CLK("vou0", -1, B_CLK, HWBLK_VOU, 0),
-       SH_HWBLK_CLK("beu0", -1, B_CLK, HWBLK_BEU0, 0),
-       SH_HWBLK_CLK("ceu0", -1, B_CLK, HWBLK_CEU0, 0),
-       SH_HWBLK_CLK("veu0", -1, B_CLK, HWBLK_VEU0, 0),
-       SH_HWBLK_CLK("vpu0", -1, B_CLK, HWBLK_VPU, 0),
-       SH_HWBLK_CLK("lcdc0", -1, B_CLK, HWBLK_LCDC, 0),
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("rclk", &r_clk),
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("fll_clk", &fll_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+       CLKDEV_CON_ID("div3_clk", &div3_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("vpu_clk", &div4_clks[DIV4_M1]),
+
+       /* DIV6 clocks */
+       CLKDEV_CON_ID("video_clk", &div6_clks[DIV6_V]),
+       CLKDEV_CON_ID("fsia_clk", &div6_clks[DIV6_FA]),
+       CLKDEV_CON_ID("fsib_clk", &div6_clks[DIV6_FB]),
+       CLKDEV_CON_ID("irda_clk", &div6_clks[DIV6_I]),
+       CLKDEV_CON_ID("spu_clk", &div6_clks[DIV6_S]),
+
+       /* MSTP clocks */
+       CLKDEV_CON_ID("tlb0", &mstp_clks[HWBLK_TLB]),
+       CLKDEV_CON_ID("ic0", &mstp_clks[HWBLK_IC]),
+       CLKDEV_CON_ID("oc0", &mstp_clks[HWBLK_OC]),
+       CLKDEV_CON_ID("rs0", &mstp_clks[HWBLK_RSMEM]),
+       CLKDEV_CON_ID("ilmem0", &mstp_clks[HWBLK_ILMEM]),
+       CLKDEV_CON_ID("l2c0", &mstp_clks[HWBLK_L2C]),
+       CLKDEV_CON_ID("fpu0", &mstp_clks[HWBLK_FPU]),
+       CLKDEV_CON_ID("intc0", &mstp_clks[HWBLK_INTC]),
+       CLKDEV_CON_ID("dmac0", &mstp_clks[HWBLK_DMAC0]),
+       CLKDEV_CON_ID("sh0", &mstp_clks[HWBLK_SHYWAY]),
+       CLKDEV_CON_ID("hudi0", &mstp_clks[HWBLK_HUDI]),
+       CLKDEV_CON_ID("ubc0", &mstp_clks[HWBLK_UBC]),
+       {
+               /* TMU0 */
+               .dev_id         = "sh_tmu.0",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       }, {
+               /* TMU1 */
+               .dev_id         = "sh_tmu.1",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       }, {
+               /* TMU2 */
+               .dev_id         = "sh_tmu.2",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU0],
+       }, {
+               /* TMU3 */
+               .dev_id         = "sh_tmu.3",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       },
+       CLKDEV_CON_ID("cmt_fck", &mstp_clks[HWBLK_CMT]),
+       CLKDEV_CON_ID("rwdt0", &mstp_clks[HWBLK_RWDT]),
+       CLKDEV_CON_ID("dmac1", &mstp_clks[HWBLK_DMAC1]),
+       {
+               /* TMU4 */
+               .dev_id         = "sh_tmu.4",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       }, {
+               /* TMU5 */
+               .dev_id         = "sh_tmu.5",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[HWBLK_TMU1],
+       }, {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF0],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF1],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF2],
+       }, {
+               /* SCIF3 */
+               .dev_id         = "sh-sci.3",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF3],
+       }, {
+               /* SCIF4 */
+               .dev_id         = "sh-sci.4",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF4],
+       }, {
+               /* SCIF5 */
+               .dev_id         = "sh-sci.5",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[HWBLK_SCIF5],
+       },
+       CLKDEV_CON_ID("msiof0", &mstp_clks[HWBLK_MSIOF0]),
+       CLKDEV_CON_ID("msiof1", &mstp_clks[HWBLK_MSIOF1]),
+       CLKDEV_CON_ID("keysc0", &mstp_clks[HWBLK_KEYSC]),
+       CLKDEV_CON_ID("rtc0", &mstp_clks[HWBLK_RTC]),
+       CLKDEV_CON_ID("i2c0", &mstp_clks[HWBLK_IIC0]),
+       CLKDEV_CON_ID("i2c1", &mstp_clks[HWBLK_IIC1]),
+       CLKDEV_CON_ID("mmc0", &mstp_clks[HWBLK_MMC]),
+       CLKDEV_CON_ID("eth0", &mstp_clks[HWBLK_ETHER]),
+       CLKDEV_CON_ID("atapi0", &mstp_clks[HWBLK_ATAPI]),
+       CLKDEV_CON_ID("tpu0", &mstp_clks[HWBLK_TPU]),
+       CLKDEV_CON_ID("irda0", &mstp_clks[HWBLK_IRDA]),
+       CLKDEV_CON_ID("tsif0", &mstp_clks[HWBLK_TSIF]),
+       CLKDEV_CON_ID("usb1", &mstp_clks[HWBLK_USB1]),
+       CLKDEV_CON_ID("usb0", &mstp_clks[HWBLK_USB0]),
+       CLKDEV_CON_ID("2dg0", &mstp_clks[HWBLK_2DG]),
+       CLKDEV_CON_ID("sdhi0", &mstp_clks[HWBLK_SDHI0]),
+       CLKDEV_CON_ID("sdhi1", &mstp_clks[HWBLK_SDHI1]),
+       CLKDEV_CON_ID("veu1", &mstp_clks[HWBLK_VEU1]),
+       CLKDEV_CON_ID("ceu1", &mstp_clks[HWBLK_CEU1]),
+       CLKDEV_CON_ID("beu1", &mstp_clks[HWBLK_BEU1]),
+       CLKDEV_CON_ID("2ddmac0", &mstp_clks[HWBLK_2DDMAC]),
+       CLKDEV_CON_ID("spu0", &mstp_clks[HWBLK_SPU]),
+       CLKDEV_CON_ID("jpu0", &mstp_clks[HWBLK_JPU]),
+       CLKDEV_CON_ID("vou0", &mstp_clks[HWBLK_VOU]),
+       CLKDEV_CON_ID("beu0", &mstp_clks[HWBLK_BEU0]),
+       CLKDEV_CON_ID("ceu0", &mstp_clks[HWBLK_CEU0]),
+       CLKDEV_CON_ID("veu0", &mstp_clks[HWBLK_VEU0]),
+       CLKDEV_CON_ID("vpu0", &mstp_clks[HWBLK_VPU]),
+       CLKDEV_CON_ID("lcdc0", &mstp_clks[HWBLK_LCDC]),
 };
 
 int __init arch_clk_init(void)
@@ -246,14 +367,16 @@ int __init arch_clk_init(void)
        for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
                ret = clk_register(main_clks[k]);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
 
        if (!ret)
-               ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
+               ret = sh_clk_div6_register(div6_clks, DIV6_NR);
 
        if (!ret)
-               ret = sh_hwblk_clk_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_hwblk_clk_register(mstp_clks, HWBLK_NR);
 
        return ret;
 }
index 86aae60..0a752bd 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
 
@@ -87,7 +88,6 @@ static struct clk_ops sh7757_shyway_clk_ops = {
 };
 
 static struct clk sh7757_shyway_clk = {
-       .name           = "shyway_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh7757_shyway_clk_ops,
 };
@@ -100,6 +100,13 @@ static struct clk *sh7757_onchip_clocks[] = {
        &sh7757_shyway_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("shyway_clk", &sh7757_shyway_clk),
+};
+
 static int __init sh7757_clk_init(void)
 {
        struct clk *clk = clk_get(NULL, "master_clk");
@@ -123,6 +130,8 @@ static int __init sh7757_clk_init(void)
 
        clk_put(clk);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return 0;
 }
 
index 9f40116..1f1df48 100644 (file)
@@ -12,6 +12,8 @@
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
 #include <asm/io.h>
@@ -77,7 +79,6 @@ static struct clk_ops sh7763_shyway_clk_ops = {
 };
 
 static struct clk sh7763_shyway_clk = {
-       .name           = "shyway_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh7763_shyway_clk_ops,
 };
@@ -90,6 +91,13 @@ static struct clk *sh7763_onchip_clocks[] = {
        &sh7763_shyway_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("shyway_clk", &sh7763_shyway_clk),
+};
+
 int __init arch_clk_init(void)
 {
        struct clk *clk;
@@ -107,5 +115,7 @@ int __init arch_clk_init(void)
 
        clk_put(clk);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return ret;
 }
index 150963a..62d7063 100644 (file)
@@ -11,6 +11,8 @@
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
 #include <asm/io.h>
@@ -83,7 +85,6 @@ static struct clk_ops sh7780_shyway_clk_ops = {
 };
 
 static struct clk sh7780_shyway_clk = {
-       .name           = "shyway_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &sh7780_shyway_clk_ops,
 };
@@ -96,6 +97,13 @@ static struct clk *sh7780_onchip_clocks[] = {
        &sh7780_shyway_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("shyway_clk", &sh7780_shyway_clk),
+};
+
 int __init arch_clk_init(void)
 {
        struct clk *clk;
@@ -113,5 +121,7 @@ int __init arch_clk_init(void)
 
        clk_put(clk);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return ret;
 }
index d997f0a..c3e458a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * SH7785 support for the clock framework
  *
- *  Copyright (C) 2007 - 2009  Paul Mundt
+ *  Copyright (C) 2007 - 2010  Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/cpufreq.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
 #include <cpu/sh7785.h>
@@ -23,8 +24,6 @@
  * from the platform code.
  */
 static struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -42,8 +41,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .parent         = &extal_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -69,48 +66,149 @@ static struct clk_div4_table div4_table = {
 enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_GA,
        DIV4_DU, DIV4_P, DIV4_NR };
 
-#define DIV4(_str, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, FRQMR1, _bit, _mask, _flags)
+#define DIV4(_bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, FRQMR1, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_P] = DIV4("peripheral_clk", 0, 0x0f80, 0),
-       [DIV4_DU] = DIV4("du_clk", 4, 0x0ff0, 0),
-       [DIV4_GA] = DIV4("ga_clk", 8, 0x0030, 0),
-       [DIV4_DDR] = DIV4("ddr_clk", 12, 0x000c, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", 16, 0x0fe0, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", 20, 0x000c, CLK_ENABLE_ON_INIT),
-       [DIV4_U] = DIV4("umem_clk", 24, 0x000c, CLK_ENABLE_ON_INIT),
-       [DIV4_I] = DIV4("cpu_clk", 28, 0x000e, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(0, 0x0f80, 0),
+       [DIV4_DU] = DIV4(4, 0x0ff0, 0),
+       [DIV4_GA] = DIV4(8, 0x0030, 0),
+       [DIV4_DDR] = DIV4(12, 0x000c, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(16, 0x0fe0, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(20, 0x000c, CLK_ENABLE_ON_INIT),
+       [DIV4_U] = DIV4(24, 0x000c, CLK_ENABLE_ON_INIT),
+       [DIV4_I] = DIV4(28, 0x000e, CLK_ENABLE_ON_INIT),
 };
 
 #define MSTPCR0                0xffc80030
 #define MSTPCR1                0xffc80034
 
-static struct clk mstp_clks[] = {
+enum { MSTP029, MSTP028, MSTP027, MSTP026, MSTP025, MSTP024,
+       MSTP021, MSTP020, MSTP017, MSTP016,
+       MSTP013, MSTP012, MSTP009, MSTP008, MSTP003, MSTP002,
+       MSTP119, MSTP117, MSTP105, MSTP104, MSTP100,
+       MSTP_NR };
+
+static struct clk mstp_clks[MSTP_NR] = {
        /* MSTPCR0 */
-       SH_CLK_MSTP32("scif_fck", 5, &div4_clks[DIV4_P], MSTPCR0, 29, 0),
-       SH_CLK_MSTP32("scif_fck", 4, &div4_clks[DIV4_P], MSTPCR0, 28, 0),
-       SH_CLK_MSTP32("scif_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 27, 0),
-       SH_CLK_MSTP32("scif_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 26, 0),
-       SH_CLK_MSTP32("scif_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 25, 0),
-       SH_CLK_MSTP32("scif_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 24, 0),
-       SH_CLK_MSTP32("ssi_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 21, 0),
-       SH_CLK_MSTP32("ssi_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 20, 0),
-       SH_CLK_MSTP32("hac_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 17, 0),
-       SH_CLK_MSTP32("hac_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 16, 0),
-       SH_CLK_MSTP32("mmcif_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 13, 0),
-       SH_CLK_MSTP32("flctl_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 12, 0),
-       SH_CLK_MSTP32("tmu345_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 9, 0),
-       SH_CLK_MSTP32("tmu012_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 8, 0),
-       SH_CLK_MSTP32("siof_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 3, 0),
-       SH_CLK_MSTP32("hspi_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 2, 0),
+       [MSTP029] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 29, 0),
+       [MSTP028] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 28, 0),
+       [MSTP027] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 27, 0),
+       [MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),
+       [MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),
+       [MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),
+       [MSTP021] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
+       [MSTP020] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 20, 0),
+       [MSTP017] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 17, 0),
+       [MSTP016] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 16, 0),
+       [MSTP013] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 13, 0),
+       [MSTP012] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 12, 0),
+       [MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),
+       [MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),
+       [MSTP003] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 3, 0),
+       [MSTP002] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
 
        /* MSTPCR1 */
-       SH_CLK_MSTP32("hudi_fck", -1, NULL, MSTPCR1, 19, 0),
-       SH_CLK_MSTP32("ubc_fck", -1, NULL, MSTPCR1, 17, 0),
-       SH_CLK_MSTP32("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
-       SH_CLK_MSTP32("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
-       SH_CLK_MSTP32("gdta_fck", -1, NULL, MSTPCR1, 0, 0),
+       [MSTP119] = SH_CLK_MSTP32(NULL, MSTPCR1, 19, 0),
+       [MSTP117] = SH_CLK_MSTP32(NULL, MSTPCR1, 17, 0),
+       [MSTP105] = SH_CLK_MSTP32(NULL, MSTPCR1, 5, 0),
+       [MSTP104] = SH_CLK_MSTP32(NULL, MSTPCR1, 4, 0),
+       [MSTP100] = SH_CLK_MSTP32(NULL, MSTPCR1, 0, 0),
+};
+
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("du_clk", &div4_clks[DIV4_DU]),
+       CLKDEV_CON_ID("ga_clk", &div4_clks[DIV4_GA]),
+       CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_DDR]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("umem_clk", &div4_clks[DIV4_U]),
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+
+       /* MSTP32 clocks */
+       {
+               /* SCIF5 */
+               .dev_id         = "sh-sci.5",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP029],
+       }, {
+               /* SCIF4 */
+               .dev_id         = "sh-sci.4",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP028],
+       }, {
+               /* SCIF3 */
+               .dev_id         = "sh-sci.3",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP027],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP026],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP025],
+       }, {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP024],
+       },
+       CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]),
+       CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),
+       CLKDEV_CON_ID("hac1_fck", &mstp_clks[MSTP017]),
+       CLKDEV_CON_ID("hac0_fck", &mstp_clks[MSTP016]),
+       CLKDEV_CON_ID("mmcif_fck", &mstp_clks[MSTP013]),
+       CLKDEV_CON_ID("flctl_fck", &mstp_clks[MSTP012]),
+       {
+               /* TMU0 */
+               .dev_id         = "sh_tmu.0",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU1 */
+               .dev_id         = "sh_tmu.1",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU2 */
+               .dev_id         = "sh_tmu.2",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU3 */
+               .dev_id         = "sh_tmu.3",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       }, {
+               /* TMU4 */
+               .dev_id         = "sh_tmu.4",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       }, {
+               /* TMU5 */
+               .dev_id         = "sh_tmu.5",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       },
+       CLKDEV_CON_ID("siof_fck", &mstp_clks[MSTP003]),
+       CLKDEV_CON_ID("hspi_fck", &mstp_clks[MSTP002]),
+       CLKDEV_CON_ID("hudi_fck", &mstp_clks[MSTP119]),
+       CLKDEV_CON_ID("ubc_fck", &mstp_clks[MSTP117]),
+       CLKDEV_CON_ID("dmac_11_6_fck", &mstp_clks[MSTP105]),
+       CLKDEV_CON_ID("dmac_5_0_fck", &mstp_clks[MSTP104]),
+       CLKDEV_CON_ID("gdta_fck", &mstp_clks[MSTP100]),
 };
 
 int __init arch_clk_init(void)
@@ -119,12 +217,14 @@ int __init arch_clk_init(void)
 
        for (i = 0; i < ARRAY_SIZE(clks); i++)
                ret |= clk_register(clks[i]);
+       for (i = 0; i < ARRAY_SIZE(lookups); i++)
+               clkdev_add(&lookups[i]);
 
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
                                           &div4_table);
        if (!ret)
-               ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
 
        return ret;
 }
index af69fd4..105a6d4 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/kernel.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/clk.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
 
@@ -21,8 +23,6 @@
  * from the platform code.
  */
 static struct clk extal_clk = {
-       .name           = "extal",
-       .id             = -1,
        .rate           = 33333333,
 };
 
@@ -44,8 +44,6 @@ static struct clk_ops pll_clk_ops = {
 };
 
 static struct clk pll_clk = {
-       .name           = "pll_clk",
-       .id             = -1,
        .ops            = &pll_clk_ops,
        .parent         = &extal_clk,
        .flags          = CLK_ENABLE_ON_INIT,
@@ -70,54 +68,191 @@ static struct clk_div4_table div4_table = {
 
 enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_DU, DIV4_P, DIV4_NR };
 
-#define DIV4(_str, _bit, _mask, _flags) \
-  SH_CLK_DIV4(_str, &pll_clk, FRQMR1, _bit, _mask, _flags)
+#define DIV4(_bit, _mask, _flags) \
+  SH_CLK_DIV4(&pll_clk, FRQMR1, _bit, _mask, _flags)
 
 struct clk div4_clks[DIV4_NR] = {
-       [DIV4_P] = DIV4("peripheral_clk", 0, 0x0b40, 0),
-       [DIV4_DU] = DIV4("du_clk", 4, 0x0010, 0),
-       [DIV4_DDR] = DIV4("ddr_clk", 12, 0x0002, CLK_ENABLE_ON_INIT),
-       [DIV4_B] = DIV4("bus_clk", 16, 0x0360, CLK_ENABLE_ON_INIT),
-       [DIV4_SH] = DIV4("shyway_clk", 20, 0x0002, CLK_ENABLE_ON_INIT),
-       [DIV4_I] = DIV4("cpu_clk", 28, 0x0006, CLK_ENABLE_ON_INIT),
+       [DIV4_P] = DIV4(0, 0x0b40, 0),
+       [DIV4_DU] = DIV4(4, 0x0010, 0),
+       [DIV4_DDR] = DIV4(12, 0x0002, CLK_ENABLE_ON_INIT),
+       [DIV4_B] = DIV4(16, 0x0360, CLK_ENABLE_ON_INIT),
+       [DIV4_SH] = DIV4(20, 0x0002, CLK_ENABLE_ON_INIT),
+       [DIV4_I] = DIV4(28, 0x0006, CLK_ENABLE_ON_INIT),
 };
 
 #define MSTPCR0                0xffc40030
 #define MSTPCR1                0xffc40034
 
-static struct clk mstp_clks[] = {
+enum { MSTP029, MSTP028, MSTP027, MSTP026, MSTP025, MSTP024,
+       MSTP023, MSTP022, MSTP021, MSTP020, MSTP017, MSTP016,
+       MSTP015, MSTP014, MSTP011, MSTP010, MSTP009, MSTP008,
+       MSTP005, MSTP004, MSTP002,
+       MSTP112, MSTP110, MSTP109, MSTP108,
+       MSTP105, MSTP104, MSTP103, MSTP102,
+       MSTP_NR };
+
+static struct clk mstp_clks[MSTP_NR] = {
        /* MSTPCR0 */
-       SH_CLK_MSTP32("scif_fck", 5, &div4_clks[DIV4_P], MSTPCR0, 29, 0),
-       SH_CLK_MSTP32("scif_fck", 4, &div4_clks[DIV4_P], MSTPCR0, 28, 0),
-       SH_CLK_MSTP32("scif_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 27, 0),
-       SH_CLK_MSTP32("scif_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 26, 0),
-       SH_CLK_MSTP32("scif_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 25, 0),
-       SH_CLK_MSTP32("scif_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 24, 0),
-       SH_CLK_MSTP32("ssi_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 23, 0),
-       SH_CLK_MSTP32("ssi_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 22, 0),
-       SH_CLK_MSTP32("ssi_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 21, 0),
-       SH_CLK_MSTP32("ssi_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 20, 0),
-       SH_CLK_MSTP32("hac_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 17, 0),
-       SH_CLK_MSTP32("hac_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 16, 0),
-       SH_CLK_MSTP32("i2c_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 15, 0),
-       SH_CLK_MSTP32("i2c_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 14, 0),
-       SH_CLK_MSTP32("tmu9_11_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 11, 0),
-       SH_CLK_MSTP32("tmu678_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 10, 0),
-       SH_CLK_MSTP32("tmu345_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 9, 0),
-       SH_CLK_MSTP32("tmu012_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 8, 0),
-       SH_CLK_MSTP32("sdif_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 5, 0),
-       SH_CLK_MSTP32("sdif_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 4, 0),
-       SH_CLK_MSTP32("hspi_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 2, 0),
+       [MSTP029] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 29, 0),
+       [MSTP028] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 28, 0),
+       [MSTP027] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 27, 0),
+       [MSTP026] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 26, 0),
+       [MSTP025] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 25, 0),
+       [MSTP024] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 24, 0),
+       [MSTP023] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 23, 0),
+       [MSTP022] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 22, 0),
+       [MSTP021] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 21, 0),
+       [MSTP020] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 20, 0),
+       [MSTP017] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 17, 0),
+       [MSTP016] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 16, 0),
+       [MSTP015] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 15, 0),
+       [MSTP014] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 14, 0),
+       [MSTP011] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 11, 0),
+       [MSTP010] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 10, 0),
+       [MSTP009] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 9, 0),
+       [MSTP008] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 8, 0),
+       [MSTP005] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 5, 0),
+       [MSTP004] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 4, 0),
+       [MSTP002] = SH_CLK_MSTP32(&div4_clks[DIV4_P], MSTPCR0, 2, 0),
 
        /* MSTPCR1 */
-       SH_CLK_MSTP32("usb_fck", -1, NULL, MSTPCR1, 12, 0),
-       SH_CLK_MSTP32("pcie_fck", 2, NULL, MSTPCR1, 10, 0),
-       SH_CLK_MSTP32("pcie_fck", 1, NULL, MSTPCR1, 9, 0),
-       SH_CLK_MSTP32("pcie_fck", 0, NULL, MSTPCR1, 8, 0),
-       SH_CLK_MSTP32("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
-       SH_CLK_MSTP32("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
-       SH_CLK_MSTP32("du_fck", -1, NULL, MSTPCR1, 3, 0),
-       SH_CLK_MSTP32("ether_fck", -1, NULL, MSTPCR1, 2, 0),
+       [MSTP112] = SH_CLK_MSTP32(NULL, MSTPCR1, 12, 0),
+       [MSTP110] = SH_CLK_MSTP32(NULL, MSTPCR1, 10, 0),
+       [MSTP109] = SH_CLK_MSTP32(NULL, MSTPCR1, 9, 0),
+       [MSTP108] = SH_CLK_MSTP32(NULL, MSTPCR1, 8, 0),
+       [MSTP105] = SH_CLK_MSTP32(NULL, MSTPCR1, 5, 0),
+       [MSTP104] = SH_CLK_MSTP32(NULL, MSTPCR1, 4, 0),
+       [MSTP103] = SH_CLK_MSTP32(NULL, MSTPCR1, 3, 0),
+       [MSTP102] = SH_CLK_MSTP32(NULL, MSTPCR1, 2, 0),
+};
+
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("extal", &extal_clk),
+       CLKDEV_CON_ID("pll_clk", &pll_clk),
+
+       /* DIV4 clocks */
+       CLKDEV_CON_ID("peripheral_clk", &div4_clks[DIV4_P]),
+       CLKDEV_CON_ID("du_clk", &div4_clks[DIV4_DU]),
+       CLKDEV_CON_ID("ddr_clk", &div4_clks[DIV4_DDR]),
+       CLKDEV_CON_ID("bus_clk", &div4_clks[DIV4_B]),
+       CLKDEV_CON_ID("shyway_clk", &div4_clks[DIV4_SH]),
+       CLKDEV_CON_ID("cpu_clk", &div4_clks[DIV4_I]),
+
+       /* MSTP32 clocks */
+       {
+               /* SCIF5 */
+               .dev_id         = "sh-sci.5",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP029],
+       }, {
+               /* SCIF4 */
+               .dev_id         = "sh-sci.4",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP028],
+       }, {
+               /* SCIF3 */
+               .dev_id         = "sh-sci.3",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP027],
+       }, {
+               /* SCIF2 */
+               .dev_id         = "sh-sci.2",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP026],
+       }, {
+               /* SCIF1 */
+               .dev_id         = "sh-sci.1",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP025],
+       }, {
+               /* SCIF0 */
+               .dev_id         = "sh-sci.0",
+               .con_id         = "sci_fck",
+               .clk            = &mstp_clks[MSTP024],
+       },
+       CLKDEV_CON_ID("ssi3_fck", &mstp_clks[MSTP023]),
+       CLKDEV_CON_ID("ssi2_fck", &mstp_clks[MSTP022]),
+       CLKDEV_CON_ID("ssi1_fck", &mstp_clks[MSTP021]),
+       CLKDEV_CON_ID("ssi0_fck", &mstp_clks[MSTP020]),
+       CLKDEV_CON_ID("hac1_fck", &mstp_clks[MSTP017]),
+       CLKDEV_CON_ID("hac0_fck", &mstp_clks[MSTP016]),
+       CLKDEV_CON_ID("i2c1_fck", &mstp_clks[MSTP015]),
+       CLKDEV_CON_ID("i2c0_fck", &mstp_clks[MSTP014]),
+       {
+               /* TMU0 */
+               .dev_id         = "sh_tmu.0",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU1 */
+               .dev_id         = "sh_tmu.1",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU2 */
+               .dev_id         = "sh_tmu.2",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP008],
+       }, {
+               /* TMU3 */
+               .dev_id         = "sh_tmu.3",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       }, {
+               /* TMU4 */
+               .dev_id         = "sh_tmu.4",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       }, {
+               /* TMU5 */
+               .dev_id         = "sh_tmu.5",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP009],
+       }, {
+               /* TMU6 */
+               .dev_id         = "sh_tmu.6",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP010],
+       }, {
+               /* TMU7 */
+               .dev_id         = "sh_tmu.7",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP010],
+       }, {
+               /* TMU8 */
+               .dev_id         = "sh_tmu.8",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP010],
+       }, {
+               /* TMU9 */
+               .dev_id         = "sh_tmu.9",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP011],
+       }, {
+               /* TMU10 */
+               .dev_id         = "sh_tmu.10",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP011],
+       }, {
+               /* TMU11 */
+               .dev_id         = "sh_tmu.11",
+               .con_id         = "tmu_fck",
+               .clk            = &mstp_clks[MSTP011],
+       },
+       CLKDEV_CON_ID("sdif1_fck", &mstp_clks[MSTP005]),
+       CLKDEV_CON_ID("sdif0_fck", &mstp_clks[MSTP004]),
+       CLKDEV_CON_ID("hspi_fck", &mstp_clks[MSTP002]),
+       CLKDEV_CON_ID("usb_fck", &mstp_clks[MSTP112]),
+       CLKDEV_CON_ID("pcie2_fck", &mstp_clks[MSTP110]),
+       CLKDEV_CON_ID("pcie1_fck", &mstp_clks[MSTP109]),
+       CLKDEV_CON_ID("pcie0_fck", &mstp_clks[MSTP108]),
+       CLKDEV_CON_ID("dmac_11_6_fck", &mstp_clks[MSTP105]),
+       CLKDEV_CON_ID("dmac_5_0_fck", &mstp_clks[MSTP104]),
+       CLKDEV_CON_ID("du_fck", &mstp_clks[MSTP103]),
+       CLKDEV_CON_ID("ether_fck", &mstp_clks[MSTP102]),
 };
 
 int __init arch_clk_init(void)
@@ -126,12 +261,14 @@ int __init arch_clk_init(void)
 
        for (i = 0; i < ARRAY_SIZE(clks); i++)
                ret |= clk_register(clks[i]);
+       for (i = 0; i < ARRAY_SIZE(lookups); i++)
+               clkdev_add(&lookups[i]);
 
        if (!ret)
                ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
                                           &div4_table);
        if (!ret)
-               ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
+               ret = sh_clk_mstp32_register(mstp_clks, MSTP_NR);
 
        return ret;
 }
index e75c57b..236a628 100644 (file)
  */
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/io.h>
+#include <asm/clkdev.h>
 #include <asm/clock.h>
 #include <asm/freq.h>
-#include <asm/io.h>
 
 static int ifc_divisors[] = { 1, 2, 4 ,6 };
 static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18, 24, 32, 36, 48 };
@@ -94,7 +95,6 @@ static struct clk_ops shx3_shyway_clk_ops = {
 };
 
 static struct clk shx3_shyway_clk = {
-       .name           = "shyway_clk",
        .flags          = CLK_ENABLE_ON_INIT,
        .ops            = &shx3_shyway_clk_ops,
 };
@@ -107,6 +107,13 @@ static struct clk *shx3_onchip_clocks[] = {
        &shx3_shyway_clk,
 };
 
+#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
+
+static struct clk_lookup lookups[] = {
+       /* main clocks */
+       CLKDEV_CON_ID("shyway_clk", &shx3_shyway_clk),
+};
+
 int __init arch_clk_init(void)
 {
        struct clk *clk;
@@ -124,5 +131,7 @@ int __init arch_clk_init(void)
 
        clk_put(clk);
 
+       clkdev_add_table(lookups, ARRAY_SIZE(lookups));
+
        return ret;
 }
index 45eb1bf..3681caf 100644 (file)
@@ -21,7 +21,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 80, 80, 80, 80 },
-       .clk            = "scif0",
 };
 
 static struct platform_device scif0_device = {
@@ -37,7 +36,6 @@ static struct plat_sci_port scif1_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 81, 81, 81, 81 },
-       .clk            = "scif1",
 };
 
 static struct platform_device scif1_device = {
@@ -53,7 +51,6 @@ static struct plat_sci_port scif2_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 82, 82, 82, 82 },
-       .clk            = "scif2",
 };
 
 static struct platform_device scif2_device = {
@@ -69,7 +66,6 @@ static struct plat_sci_port scif3_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 83, 83, 83, 83 },
-       .clk            = "scif3",
 };
 
 static struct platform_device scif3_device = {
@@ -207,17 +203,14 @@ static struct platform_device jpu_device = {
 };
 
 static struct sh_timer_config cmt_platform_data = {
-       .name = "CMT",
        .channel_offset = 0x60,
        .timer_bit = 5,
-       .clk = "cmt0",
        .clockevent_rating = 125,
        .clocksource_rating = 200,
 };
 
 static struct resource cmt_resources[] = {
        [0] = {
-               .name   = "CMT",
                .start  = 0x044a0060,
                .end    = 0x044a006b,
                .flags  = IORESOURCE_MEM,
@@ -239,16 +232,13 @@ static struct platform_device cmt_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu0",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -270,16 +260,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu0",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -301,15 +288,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu0",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002b,
                .flags  = IORESOURCE_MEM,
index c494c19..8dab9e1 100644 (file)
@@ -23,7 +23,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 80, 80, 80, 80 },
-       .clk            = "scif0",
 };
 
 static struct platform_device scif0_device = {
@@ -169,17 +168,14 @@ static struct platform_device veu1_device = {
 };
 
 static struct sh_timer_config cmt_platform_data = {
-       .name = "CMT",
        .channel_offset = 0x60,
        .timer_bit = 5,
-       .clk = "cmt0",
        .clockevent_rating = 125,
        .clocksource_rating = 200,
 };
 
 static struct resource cmt_resources[] = {
        [0] = {
-               .name   = "CMT",
                .start  = 0x044a0060,
                .end    = 0x044a006b,
                .flags  = IORESOURCE_MEM,
@@ -201,16 +197,13 @@ static struct platform_device cmt_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu0",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -232,16 +225,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu0",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -263,15 +253,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu0",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002b,
                .flags  = IORESOURCE_MEM,
index fd7e363..24c6167 100644 (file)
@@ -24,7 +24,7 @@
 #include <cpu/dma-register.h>
 #include <cpu/sh7722.h>
 
-static struct sh_dmae_slave_config sh7722_dmae_slaves[] = {
+static const struct sh_dmae_slave_config sh7722_dmae_slaves[] = {
        {
                .slave_id       = SHDMA_SLAVE_SCIF0_TX,
                .addr           = 0xffe0000c,
@@ -78,7 +78,7 @@ static struct sh_dmae_slave_config sh7722_dmae_slaves[] = {
        },
 };
 
-static struct sh_dmae_channel sh7722_dmae_channels[] = {
+static const struct sh_dmae_channel sh7722_dmae_channels[] = {
        {
                .offset = 0,
                .dmars = 0,
@@ -106,7 +106,7 @@ static struct sh_dmae_channel sh7722_dmae_channels[] = {
        }
 };
 
-static unsigned int ts_shift[] = TS_SHIFT;
+static const unsigned int ts_shift[] = TS_SHIFT;
 
 static struct sh_dmae_pdata dma_platform_data = {
        .slave          = sh7722_dmae_slaves,
@@ -174,7 +174,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 80, 80, 80, 80 },
-       .clk            = "scif0",
 };
 
 static struct platform_device scif0_device = {
@@ -190,7 +189,6 @@ static struct plat_sci_port scif1_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 81, 81, 81, 81 },
-       .clk            = "scif1",
 };
 
 static struct platform_device scif1_device = {
@@ -206,7 +204,6 @@ static struct plat_sci_port scif2_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 82, 82, 82, 82 },
-       .clk            = "scif2",
 };
 
 static struct platform_device scif2_device = {
@@ -401,17 +398,14 @@ static struct platform_device jpu_device = {
 };
 
 static struct sh_timer_config cmt_platform_data = {
-       .name = "CMT",
        .channel_offset = 0x60,
        .timer_bit = 5,
-       .clk = "cmt0",
        .clockevent_rating = 125,
        .clocksource_rating = 125,
 };
 
 static struct resource cmt_resources[] = {
        [0] = {
-               .name   = "CMT",
                .start  = 0x044a0060,
                .end    = 0x044a006b,
                .flags  = IORESOURCE_MEM,
@@ -436,16 +430,13 @@ static struct platform_device cmt_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu0",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -470,16 +461,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu0",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -504,15 +492,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu0",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002b,
                .flags  = IORESOURCE_MEM,
index 85c61f6..0eadefd 100644 (file)
@@ -26,7 +26,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 80, 80, 80, 80 },
-       .clk            = "scif0",
 };
 
 static struct platform_device scif0_device = {
@@ -42,7 +41,6 @@ static struct plat_sci_port scif1_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 81, 81, 81, 81 },
-       .clk            = "scif1",
 };
 
 static struct platform_device scif1_device = {
@@ -58,7 +56,6 @@ static struct plat_sci_port scif2_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 82, 82, 82, 82 },
-       .clk            = "scif2",
 };
 
 static struct platform_device scif2_device = {
@@ -74,7 +71,6 @@ static struct plat_sci_port scif3_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 56, 56, 56, 56 },
-       .clk            = "scif3",
 };
 
 static struct platform_device scif3_device = {
@@ -90,7 +86,6 @@ static struct plat_sci_port scif4_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 88, 88, 88, 88 },
-       .clk            = "scif4",
 };
 
 static struct platform_device scif4_device = {
@@ -106,7 +101,6 @@ static struct plat_sci_port scif5_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 109, 109, 109, 109 },
-       .clk            = "scif5",
 };
 
 static struct platform_device scif5_device = {
@@ -211,17 +205,14 @@ static struct platform_device veu1_device = {
 };
 
 static struct sh_timer_config cmt_platform_data = {
-       .name = "CMT",
        .channel_offset = 0x60,
        .timer_bit = 5,
-       .clk = "cmt0",
        .clockevent_rating = 125,
        .clocksource_rating = 125,
 };
 
 static struct resource cmt_resources[] = {
        [0] = {
-               .name   = "CMT",
                .start  = 0x044a0060,
                .end    = 0x044a006b,
                .flags  = IORESOURCE_MEM,
@@ -246,16 +237,13 @@ static struct platform_device cmt_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu0",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -280,16 +268,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu0",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -314,15 +299,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu0",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002b,
                .flags  = IORESOURCE_MEM,
@@ -347,15 +329,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu1",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffd90008,
                .end    = 0xffd90013,
                .flags  = IORESOURCE_MEM,
@@ -380,15 +359,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu1",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffd90014,
                .end    = 0xffd9001f,
                .flags  = IORESOURCE_MEM,
@@ -413,15 +389,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu1",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffd90020,
                .end    = 0xffd9002b,
                .flags  = IORESOURCE_MEM,
index e7fa2a9..89fe16d 100644 (file)
@@ -31,7 +31,7 @@
 #include <cpu/sh7724.h>
 
 /* DMA */
-static struct sh_dmae_channel sh7724_dmae0_channels[] = {
+static const struct sh_dmae_channel sh7724_dmae_channels[] = {
        {
                .offset = 0,
                .dmars = 0,
@@ -59,51 +59,11 @@ static struct sh_dmae_channel sh7724_dmae0_channels[] = {
        }
 };
 
-static struct sh_dmae_channel sh7724_dmae1_channels[] = {
-       {
-               .offset = 0,
-               .dmars = 0,
-               .dmars_bit = 0,
-       }, {
-               .offset = 0x10,
-               .dmars = 0,
-               .dmars_bit = 8,
-       }, {
-               .offset = 0x20,
-               .dmars = 4,
-               .dmars_bit = 0,
-       }, {
-               .offset = 0x30,
-               .dmars = 4,
-               .dmars_bit = 8,
-       }, {
-               .offset = 0x50,
-               .dmars = 8,
-               .dmars_bit = 0,
-       }, {
-               .offset = 0x60,
-               .dmars = 8,
-               .dmars_bit = 8,
-       }
-};
-
-static unsigned int ts_shift[] = TS_SHIFT;
-
-static struct sh_dmae_pdata dma0_platform_data = {
-       .channel        = sh7724_dmae0_channels,
-       .channel_num    = ARRAY_SIZE(sh7724_dmae0_channels),
-       .ts_low_shift   = CHCR_TS_LOW_SHIFT,
-       .ts_low_mask    = CHCR_TS_LOW_MASK,
-       .ts_high_shift  = CHCR_TS_HIGH_SHIFT,
-       .ts_high_mask   = CHCR_TS_HIGH_MASK,
-       .ts_shift       = ts_shift,
-       .ts_shift_num   = ARRAY_SIZE(ts_shift),
-       .dmaor_init     = DMAOR_INIT,
-};
+static const unsigned int ts_shift[] = TS_SHIFT;
 
-static struct sh_dmae_pdata dma1_platform_data = {
-       .channel        = sh7724_dmae1_channels,
-       .channel_num    = ARRAY_SIZE(sh7724_dmae1_channels),
+static struct sh_dmae_pdata dma_platform_data = {
+       .channel        = sh7724_dmae_channels,
+       .channel_num    = ARRAY_SIZE(sh7724_dmae_channels),
        .ts_low_shift   = CHCR_TS_LOW_SHIFT,
        .ts_low_mask    = CHCR_TS_LOW_MASK,
        .ts_high_shift  = CHCR_TS_HIGH_SHIFT,
@@ -187,7 +147,7 @@ static struct platform_device dma0_device = {
        .resource       = sh7724_dmae0_resources,
        .num_resources  = ARRAY_SIZE(sh7724_dmae0_resources),
        .dev            = {
-               .platform_data  = &dma0_platform_data,
+               .platform_data  = &dma_platform_data,
        },
        .archdata = {
                .hwblk_id = HWBLK_DMAC0,
@@ -200,7 +160,7 @@ static struct platform_device dma1_device = {
        .resource       = sh7724_dmae1_resources,
        .num_resources  = ARRAY_SIZE(sh7724_dmae1_resources),
        .dev            = {
-               .platform_data  = &dma1_platform_data,
+               .platform_data  = &dma_platform_data,
        },
        .archdata = {
                .hwblk_id = HWBLK_DMAC1,
@@ -213,7 +173,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 80, 80, 80, 80 },
-       .clk            = "scif0",
 };
 
 static struct platform_device scif0_device = {
@@ -229,7 +188,6 @@ static struct plat_sci_port scif1_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 81, 81, 81, 81 },
-       .clk            = "scif1",
 };
 
 static struct platform_device scif1_device = {
@@ -245,7 +203,6 @@ static struct plat_sci_port scif2_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 82, 82, 82, 82 },
-       .clk            = "scif2",
 };
 
 static struct platform_device scif2_device = {
@@ -261,7 +218,6 @@ static struct plat_sci_port scif3_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 56, 56, 56, 56 },
-       .clk            = "scif3",
 };
 
 static struct platform_device scif3_device = {
@@ -277,7 +233,6 @@ static struct plat_sci_port scif4_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 88, 88, 88, 88 },
-       .clk            = "scif4",
 };
 
 static struct platform_device scif4_device = {
@@ -293,7 +248,6 @@ static struct plat_sci_port scif5_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIFA,
        .irqs           = { 109, 109, 109, 109 },
-       .clk            = "scif5",
 };
 
 static struct platform_device scif5_device = {
@@ -485,17 +439,14 @@ static struct platform_device veu1_device = {
 };
 
 static struct sh_timer_config cmt_platform_data = {
-       .name = "CMT",
        .channel_offset = 0x60,
        .timer_bit = 5,
-       .clk = "cmt0",
        .clockevent_rating = 125,
        .clocksource_rating = 200,
 };
 
 static struct resource cmt_resources[] = {
        [0] = {
-               .name   = "CMT",
                .start  = 0x044a0060,
                .end    = 0x044a006b,
                .flags  = IORESOURCE_MEM,
@@ -520,16 +471,13 @@ static struct platform_device cmt_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu0",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -554,16 +502,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu0",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -588,15 +533,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu0",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002b,
                .flags  = IORESOURCE_MEM,
@@ -622,15 +564,12 @@ static struct platform_device tmu2_device = {
 
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu1",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffd90008,
                .end    = 0xffd90013,
                .flags  = IORESOURCE_MEM,
@@ -655,15 +594,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu1",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffd90014,
                .end    = 0xffd9001f,
                .flags  = IORESOURCE_MEM,
@@ -688,15 +624,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu1",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffd90020,
                .end    = 0xffd9002b,
                .flags  = IORESOURCE_MEM,
index e75edf5..444aca9 100644 (file)
@@ -63,16 +63,13 @@ static struct platform_device scif4_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xfe430008,
                .end    = 0xfe430013,
                .flags  = IORESOURCE_MEM,
@@ -94,16 +91,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xfe430014,
                .end    = 0xfe43001f,
                .flags  = IORESOURCE_MEM,
index 7f6b0a5..5b5f6b0 100644 (file)
@@ -131,16 +131,13 @@ static struct platform_device usbf_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -162,16 +159,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -193,15 +187,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -223,15 +214,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffd88008,
                .end    = 0xffd88013,
                .flags  = IORESOURCE_MEM,
@@ -253,15 +241,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffd88014,
                .end    = 0xffd8801f,
                .flags  = IORESOURCE_MEM,
@@ -283,15 +268,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffd88020,
                .end    = 0xffd8802b,
                .flags  = IORESOURCE_MEM,
index 86d681e..7270d7f 100644 (file)
@@ -165,16 +165,13 @@ static struct platform_device scif9_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -196,16 +193,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -227,15 +221,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -257,15 +248,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffd81008,
                .end    = 0xffd81013,
                .flags  = IORESOURCE_MEM,
@@ -287,15 +275,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffd81014,
                .end    = 0xffd8101f,
                .flags  = IORESOURCE_MEM,
@@ -317,15 +302,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffd81020,
                .end    = 0xffd8102f,
                .flags  = IORESOURCE_MEM,
@@ -347,15 +329,12 @@ static struct platform_device tmu5_device = {
 };
 
 static struct sh_timer_config tmu6_platform_data = {
-       .name = "TMU6",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu6_resources[] = {
        [0] = {
-               .name   = "TMU6",
                .start  = 0xffd82008,
                .end    = 0xffd82013,
                .flags  = IORESOURCE_MEM,
@@ -377,15 +356,12 @@ static struct platform_device tmu6_device = {
 };
 
 static struct sh_timer_config tmu7_platform_data = {
-       .name = "TMU7",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu7_resources[] = {
        [0] = {
-               .name   = "TMU7",
                .start  = 0xffd82014,
                .end    = 0xffd8201f,
                .flags  = IORESOURCE_MEM,
@@ -407,15 +383,12 @@ static struct platform_device tmu7_device = {
 };
 
 static struct sh_timer_config tmu8_platform_data = {
-       .name = "TMU8",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu8_resources[] = {
        [0] = {
-               .name   = "TMU8",
                .start  = 0xffd82020,
                .end    = 0xffd8202b,
                .flags  = IORESOURCE_MEM,
index 02e792c..b12f537 100644 (file)
@@ -49,16 +49,13 @@ static struct platform_device scif1_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -80,16 +77,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -111,15 +105,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -141,15 +132,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffdc0008,
                .end    = 0xffdc0013,
                .flags  = IORESOURCE_MEM,
@@ -171,15 +159,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffdc0014,
                .end    = 0xffdc001f,
                .flags  = IORESOURCE_MEM,
@@ -201,15 +186,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffdc0020,
                .end    = 0xffdc002b,
                .flags  = IORESOURCE_MEM,
@@ -251,7 +233,7 @@ static struct platform_device rtc_device = {
 };
 
 /* DMA */
-static struct sh_dmae_channel sh7780_dmae0_channels[] = {
+static const struct sh_dmae_channel sh7780_dmae0_channels[] = {
        {
                .offset = 0,
                .dmars = 0,
@@ -279,7 +261,7 @@ static struct sh_dmae_channel sh7780_dmae0_channels[] = {
        }
 };
 
-static struct sh_dmae_channel sh7780_dmae1_channels[] = {
+static const struct sh_dmae_channel sh7780_dmae1_channels[] = {
        {
                .offset = 0,
        }, {
@@ -295,7 +277,7 @@ static struct sh_dmae_channel sh7780_dmae1_channels[] = {
        }
 };
 
-static unsigned int ts_shift[] = TS_SHIFT;
+static const unsigned int ts_shift[] = TS_SHIFT;
 
 static struct sh_dmae_pdata dma0_platform_data = {
        .channel        = sh7780_dmae0_channels,
index 1fcd88b..f3e3ea0 100644 (file)
@@ -25,7 +25,6 @@ static struct plat_sci_port scif0_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 40, 40, 40, 40 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif0_device = {
@@ -41,7 +40,6 @@ static struct plat_sci_port scif1_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 44, 44, 44, 44 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif1_device = {
@@ -57,7 +55,6 @@ static struct plat_sci_port scif2_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 60, 60, 60, 60 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif2_device = {
@@ -73,7 +70,6 @@ static struct plat_sci_port scif3_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 61, 61, 61, 61 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif3_device = {
@@ -89,7 +85,6 @@ static struct plat_sci_port scif4_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 62, 62, 62, 62 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif4_device = {
@@ -105,7 +100,6 @@ static struct plat_sci_port scif5_platform_data = {
        .flags          = UPF_BOOT_AUTOCONF,
        .type           = PORT_SCIF,
        .irqs           = { 63, 63, 63, 63 },
-       .clk            = "scif_fck",
 };
 
 static struct platform_device scif5_device = {
@@ -117,16 +111,13 @@ static struct platform_device scif5_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu012_fck",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -148,16 +139,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu012_fck",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -179,15 +167,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu012_fck",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -209,15 +194,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "tmu345_fck",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffdc0008,
                .end    = 0xffdc0013,
                .flags  = IORESOURCE_MEM,
@@ -239,15 +221,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "tmu345_fck",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffdc0014,
                .end    = 0xffdc001f,
                .flags  = IORESOURCE_MEM,
@@ -269,15 +248,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "tmu345_fck",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffdc0020,
                .end    = 0xffdc002b,
                .flags  = IORESOURCE_MEM,
@@ -299,7 +275,7 @@ static struct platform_device tmu5_device = {
 };
 
 /* DMA */
-static struct sh_dmae_channel sh7785_dmae0_channels[] = {
+static const struct sh_dmae_channel sh7785_dmae0_channels[] = {
        {
                .offset = 0,
                .dmars = 0,
@@ -327,7 +303,7 @@ static struct sh_dmae_channel sh7785_dmae0_channels[] = {
        }
 };
 
-static struct sh_dmae_channel sh7785_dmae1_channels[] = {
+static const struct sh_dmae_channel sh7785_dmae1_channels[] = {
        {
                .offset = 0,
        }, {
@@ -343,7 +319,7 @@ static struct sh_dmae_channel sh7785_dmae1_channels[] = {
        }
 };
 
-static unsigned int ts_shift[] = TS_SHIFT;
+static const unsigned int ts_shift[] = TS_SHIFT;
 
 static struct sh_dmae_pdata dma0_platform_data = {
        .channel        = sh7785_dmae0_channels,
index 7e58532..8165709 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * SH7786 Setup
  *
- * Copyright (C) 2009  Renesas Solutions Corp.
+ * Copyright (C) 2009 - 2010  Renesas Solutions Corp.
  * Kuninori Morimoto <morimoto.kuninori@renesas.com>
  * Paul Mundt <paul.mundt@renesas.com>
  *
 #include <linux/mm.h>
 #include <linux/dma-mapping.h>
 #include <linux/sh_timer.h>
+#include <linux/sh_intc.h>
+#include <cpu/dma-register.h>
 #include <asm/mmzone.h>
+#include <asm/dmaengine.h>
 
 static struct plat_sci_port scif0_platform_data = {
        .mapbase        = 0xffea0000,
@@ -117,16 +120,13 @@ static struct platform_device scif5_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffd80008,
                .end    = 0xffd80013,
                .flags  = IORESOURCE_MEM,
@@ -148,16 +148,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffd80014,
                .end    = 0xffd8001f,
                .flags  = IORESOURCE_MEM,
@@ -179,15 +176,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffd80020,
                .end    = 0xffd8002f,
                .flags  = IORESOURCE_MEM,
@@ -209,15 +203,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffda0008,
                .end    = 0xffda0013,
                .flags  = IORESOURCE_MEM,
@@ -239,15 +230,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffda0014,
                .end    = 0xffda001f,
                .flags  = IORESOURCE_MEM,
@@ -269,15 +257,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffda0020,
                .end    = 0xffda002b,
                .flags  = IORESOURCE_MEM,
@@ -299,15 +284,12 @@ static struct platform_device tmu5_device = {
 };
 
 static struct sh_timer_config tmu6_platform_data = {
-       .name = "TMU6",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu6_resources[] = {
        [0] = {
-               .name   = "TMU6",
                .start  = 0xffdc0008,
                .end    = 0xffdc0013,
                .flags  = IORESOURCE_MEM,
@@ -329,15 +311,12 @@ static struct platform_device tmu6_device = {
 };
 
 static struct sh_timer_config tmu7_platform_data = {
-       .name = "TMU7",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu7_resources[] = {
        [0] = {
-               .name   = "TMU7",
                .start  = 0xffdc0014,
                .end    = 0xffdc001f,
                .flags  = IORESOURCE_MEM,
@@ -359,15 +338,12 @@ static struct platform_device tmu7_device = {
 };
 
 static struct sh_timer_config tmu8_platform_data = {
-       .name = "TMU8",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu8_resources[] = {
        [0] = {
-               .name   = "TMU8",
                .start  = 0xffdc0020,
                .end    = 0xffdc002b,
                .flags  = IORESOURCE_MEM,
@@ -389,15 +365,12 @@ static struct platform_device tmu8_device = {
 };
 
 static struct sh_timer_config tmu9_platform_data = {
-       .name = "TMU9",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu9_resources[] = {
        [0] = {
-               .name   = "TMU9",
                .start  = 0xffde0008,
                .end    = 0xffde0013,
                .flags  = IORESOURCE_MEM,
@@ -419,15 +392,12 @@ static struct platform_device tmu9_device = {
 };
 
 static struct sh_timer_config tmu10_platform_data = {
-       .name = "TMU10",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu10_resources[] = {
        [0] = {
-               .name   = "TMU10",
                .start  = 0xffde0014,
                .end    = 0xffde001f,
                .flags  = IORESOURCE_MEM,
@@ -449,15 +419,12 @@ static struct platform_device tmu10_device = {
 };
 
 static struct sh_timer_config tmu11_platform_data = {
-       .name = "TMU11",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu11_resources[] = {
        [0] = {
-               .name   = "TMU11",
                .start  = 0xffde0020,
                .end    = 0xffde002b,
                .flags  = IORESOURCE_MEM,
@@ -478,6 +445,83 @@ static struct platform_device tmu11_device = {
        .num_resources  = ARRAY_SIZE(tmu11_resources),
 };
 
+static const struct sh_dmae_channel dmac0_channels[] = {
+       {
+               .offset = 0,
+               .dmars = 0,
+               .dmars_bit = 0,
+       }, {
+               .offset = 0x10,
+               .dmars = 0,
+               .dmars_bit = 8,
+       }, {
+               .offset = 0x20,
+               .dmars = 4,
+               .dmars_bit = 0,
+       }, {
+               .offset = 0x30,
+               .dmars = 4,
+               .dmars_bit = 8,
+       }, {
+               .offset = 0x50,
+               .dmars = 8,
+               .dmars_bit = 0,
+       }, {
+               .offset = 0x60,
+               .dmars = 8,
+               .dmars_bit = 8,
+       }
+};
+
+static const unsigned int ts_shift[] = TS_SHIFT;
+
+static struct sh_dmae_pdata dma0_platform_data = {
+       .channel        = dmac0_channels,
+       .channel_num    = ARRAY_SIZE(dmac0_channels),
+       .ts_low_shift   = CHCR_TS_LOW_SHIFT,
+       .ts_low_mask    = CHCR_TS_LOW_MASK,
+       .ts_high_shift  = CHCR_TS_HIGH_SHIFT,
+       .ts_high_mask   = CHCR_TS_HIGH_MASK,
+       .ts_shift       = ts_shift,
+       .ts_shift_num   = ARRAY_SIZE(ts_shift),
+       .dmaor_init     = DMAOR_INIT,
+};
+
+/* Resource order important! */
+static struct resource dmac0_resources[] = {
+       {
+               /* Channel registers and DMAOR */
+               .start  = 0xfe008020,
+               .end    = 0xfe00808f,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               /* DMARSx */
+               .start  = 0xfe009000,
+               .end    = 0xfe00900b,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               /* DMA error IRQ */
+               .start  = evt2irq(0x5c0),
+               .end    = evt2irq(0x5c0),
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               /* IRQ for channels 0-5 */
+               .start  = evt2irq(0x500),
+               .end    = evt2irq(0x5a0),
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device dma0_device = {
+       .name           = "sh-dma-engine",
+       .id             = 0,
+       .resource       = dmac0_resources,
+       .num_resources  = ARRAY_SIZE(dmac0_resources),
+       .dev            = {
+               .platform_data  = &dma0_platform_data,
+       },
+};
+
 static struct resource usb_ohci_resources[] = {
        [0] = {
                .start  = 0xffe70400,
@@ -525,10 +569,10 @@ static struct platform_device *sh7786_early_devices[] __initdata = {
 };
 
 static struct platform_device *sh7786_devices[] __initdata = {
+       &dma0_device,
        &usb_ohci_device,
 };
 
-
 /*
  * Please call this function if your platform board
  * use external clock for USB
@@ -536,6 +580,7 @@ static struct platform_device *sh7786_devices[] __initdata = {
 #define USBCTL0                0xffe70858
 #define CLOCK_MODE_MASK 0xffffff7f
 #define EXT_CLOCK_MODE  0x00000080
+
 void __init sh7786_usb_use_exclock(void)
 {
        u32 val = __raw_readl(USBCTL0) & CLOCK_MODE_MASK;
@@ -553,6 +598,7 @@ void __init sh7786_usb_use_exclock(void)
 #define PLL_ENB                0x00000002
 #define PHY_RST                0x00000004
 #define ACT_PLL_STATUS 0xc0000000
+
 static void __init sh7786_usb_setup(void)
 {
        int i = 1000000;
@@ -708,9 +754,19 @@ static struct intc_vect vectors[] __initdata = {
 #define INTMSK2                0xfe410068
 #define INTMSKCLR2     0xfe41006c
 
+#define INTDISTCR0     0xfe4100b0
+#define INTDISTCR1     0xfe4100b4
+#define INTACK         0xfe4100b8
+#define INTACKCLR      0xfe4100bc
+#define INT2DISTCR0    0xfe410900
+#define INT2DISTCR1    0xfe410904
+#define INT2DISTCR2    0xfe410908
+#define INT2DISTCR3    0xfe41090c
+
 static struct intc_mask_reg mask_registers[] __initdata = {
        { CnINTMSK0, CnINTMSKCLR0, 32,
-         { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
+         { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 },
+           INTC_SMP_BALANCING(INTDISTCR0) },
        { INTMSK2, INTMSKCLR2, 32,
          { IRL0_LLLL, IRL0_LLLH, IRL0_LLHL, IRL0_LLHH,
            IRL0_LHLL, IRL0_LHLH, IRL0_LHHL, IRL0_LHHH,
@@ -722,7 +778,8 @@ static struct intc_mask_reg mask_registers[] __initdata = {
            IRL4_HHLL, IRL4_HHLH, IRL4_HHHL, 0, } },
        { CnINT2MSKR0, CnINT2MSKCR0 , 32,
          { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, WDT } },
+           0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, WDT },
+           INTC_SMP_BALANCING(INT2DISTCR0) },
        { CnINT2MSKR1, CnINT2MSKCR1, 32,
          { TMU0_0, TMU0_1, TMU0_2, TMU0_3, TMU1_0, TMU1_1, TMU1_2, 0,
            DMAC0_0, DMAC0_1, DMAC0_2, DMAC0_3, DMAC0_4, DMAC0_5, DMAC0_6,
@@ -731,14 +788,14 @@ static struct intc_mask_reg mask_registers[] __initdata = {
            HPB_0, HPB_1, HPB_2,
            SCIF0_0, SCIF0_1, SCIF0_2, SCIF0_3,
            SCIF1,
-           TMU2, TMU3, 0, } },
+           TMU2, TMU3, 0, }, INTC_SMP_BALANCING(INT2DISTCR1) },
        { CnINT2MSKR2, CnINT2MSKCR2, 32,
          { 0, 0, SCIF2, SCIF3, SCIF4, SCIF5,
            Eth_0, Eth_1,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            PCIeC0_0, PCIeC0_1, PCIeC0_2,
            PCIeC1_0, PCIeC1_1, PCIeC1_2,
-           USB, 0, 0 } },
+           USB, 0, 0 }, INTC_SMP_BALANCING(INT2DISTCR2) },
        { CnINT2MSKR3, CnINT2MSKCR3, 32,
          { 0, 0, 0, 0, 0, 0,
            I2C0, I2C1,
@@ -747,7 +804,7 @@ static struct intc_mask_reg mask_registers[] __initdata = {
            HAC0, HAC1,
            FLCTL, 0,
            HSPI, GPIO0, GPIO1, Thermal,
-           0, 0, 0, 0, 0, 0, 0, 0 } },
+           0, 0, 0, 0, 0, 0, 0, 0 }, INTC_SMP_BALANCING(INT2DISTCR3) },
 };
 
 static struct intc_prio_reg prio_registers[] __initdata = {
@@ -863,6 +920,19 @@ static DECLARE_INTC_DESC(intc_desc_irl4567, "sh7786-irl4567", vectors_irl4567,
 #define INTC_INTMSK2   INTMSK2
 #define INTC_INTMSKCLR1        CnINTMSKCLR1
 #define INTC_INTMSKCLR2        INTMSKCLR2
+#define INTC_USERIMASK 0xfe411000
+
+#ifdef CONFIG_INTC_BALANCING
+unsigned int irq_lookup(unsigned int irq)
+{
+       return __raw_readl(INTACK) & 1 ? irq : NO_IRQ_IGNORE;
+}
+
+void irq_finish(unsigned int irq)
+{
+       __raw_writel(irq2evt(irq), INTACKCLR);
+}
+#endif
 
 void __init plat_irq_setup(void)
 {
@@ -877,6 +947,7 @@ void __init plat_irq_setup(void)
        __raw_writel(__raw_readl(INTC_ICR0) & ~0x00c00000, INTC_ICR0);
 
        register_intc_controller(&intc_desc);
+       register_intc_userimask(INTC_USERIMASK);
 }
 
 void __init plat_irq_setup_pins(int mode)
index 780ba17..9158bc5 100644 (file)
@@ -70,16 +70,13 @@ static struct platform_device scif2_device = {
 };
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = 0xffc10008,
                .end    = 0xffc10013,
                .flags  = IORESOURCE_MEM,
@@ -101,16 +98,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = 0xffc10014,
                .end    = 0xffc1001f,
                .flags  = IORESOURCE_MEM,
@@ -132,15 +126,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = 0xffc10020,
                .end    = 0xffc1002f,
                .flags  = IORESOURCE_MEM,
@@ -162,15 +153,12 @@ static struct platform_device tmu2_device = {
 };
 
 static struct sh_timer_config tmu3_platform_data = {
-       .name = "TMU3",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu3_resources[] = {
        [0] = {
-               .name   = "TMU3",
                .start  = 0xffc20008,
                .end    = 0xffc20013,
                .flags  = IORESOURCE_MEM,
@@ -192,15 +180,12 @@ static struct platform_device tmu3_device = {
 };
 
 static struct sh_timer_config tmu4_platform_data = {
-       .name = "TMU4",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu4_resources[] = {
        [0] = {
-               .name   = "TMU4",
                .start  = 0xffc20014,
                .end    = 0xffc2001f,
                .flags  = IORESOURCE_MEM,
@@ -222,15 +207,12 @@ static struct platform_device tmu4_device = {
 };
 
 static struct sh_timer_config tmu5_platform_data = {
-       .name = "TMU5",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu5_resources[] = {
        [0] = {
-               .name   = "TMU5",
                .start  = 0xffc20020,
                .end    = 0xffc2002b,
                .flags  = IORESOURCE_MEM,
index 11bf4c1..de865ca 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * SH-X3 SMP
  *
- *  Copyright (C) 2007 - 2008  Paul Mundt
+ *  Copyright (C) 2007 - 2010  Paul Mundt
  *  Copyright (C) 2007  Magnus Damm
  *
  * This file is subject to the terms and conditions of the GNU General Public
@@ -9,16 +9,22 @@
  * for more details.
  */
 #include <linux/init.h>
+#include <linux/kernel.h>
 #include <linux/cpumask.h>
 #include <linux/smp.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <linux/cpu.h>
+#include <asm/sections.h>
 
 #define STBCR_REG(phys_id) (0xfe400004 | (phys_id << 12))
 #define RESET_REG(phys_id) (0xfe400008 | (phys_id << 12))
 
 #define STBCR_MSTP     0x00000001
 #define STBCR_RESET    0x00000002
+#define STBCR_SLEEP    0x00000004
 #define STBCR_LTSLP    0x80000000
 
 static irqreturn_t ipi_interrupt_handler(int irq, void *arg)
@@ -37,7 +43,7 @@ static irqreturn_t ipi_interrupt_handler(int irq, void *arg)
        return IRQ_HANDLED;
 }
 
-void __init plat_smp_setup(void)
+static void shx3_smp_setup(void)
 {
        unsigned int cpu = 0;
        int i, num;
@@ -63,7 +69,7 @@ void __init plat_smp_setup(void)
         printk(KERN_INFO "Detected %i available secondary CPU(s)\n", num);
 }
 
-void __init plat_prepare_cpus(unsigned int max_cpus)
+static void shx3_prepare_cpus(unsigned int max_cpus)
 {
        int i;
 
@@ -72,11 +78,14 @@ void __init plat_prepare_cpus(unsigned int max_cpus)
        BUILD_BUG_ON(SMP_MSG_NR >= 8);
 
        for (i = 0; i < SMP_MSG_NR; i++)
-               request_irq(104 + i, ipi_interrupt_handler, IRQF_DISABLED,
-                           "IPI", (void *)(long)i);
+               request_irq(104 + i, ipi_interrupt_handler,
+                           IRQF_DISABLED | IRQF_PERCPU, "IPI", (void *)(long)i);
+
+       for (i = 0; i < max_cpus; i++)
+               set_cpu_present(i, true);
 }
 
-void plat_start_cpu(unsigned int cpu, unsigned long entry_point)
+static void shx3_start_cpu(unsigned int cpu, unsigned long entry_point)
 {
        if (__in_29bit_mode())
                __raw_writel(entry_point, RESET_REG(cpu));
@@ -93,12 +102,12 @@ void plat_start_cpu(unsigned int cpu, unsigned long entry_point)
        __raw_writel(STBCR_RESET | STBCR_LTSLP, STBCR_REG(cpu));
 }
 
-int plat_smp_processor_id(void)
+static unsigned int shx3_smp_processor_id(void)
 {
        return __raw_readl(0xff000048); /* CPIDR */
 }
 
-void plat_send_ipi(unsigned int cpu, unsigned int message)
+static void shx3_send_ipi(unsigned int cpu, unsigned int message)
 {
        unsigned long addr = 0xfe410070 + (cpu * 4);
 
@@ -106,3 +115,52 @@ void plat_send_ipi(unsigned int cpu, unsigned int message)
 
        __raw_writel(1 << (message << 2), addr); /* C0INTICI..CnINTICI */
 }
+
+static void shx3_update_boot_vector(unsigned int cpu)
+{
+       __raw_writel(STBCR_MSTP, STBCR_REG(cpu));
+       while (!(__raw_readl(STBCR_REG(cpu)) & STBCR_MSTP))
+               cpu_relax();
+       __raw_writel(STBCR_RESET, STBCR_REG(cpu));
+}
+
+static int __cpuinit
+shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
+{
+       unsigned int cpu = (unsigned int)hcpu;
+
+       switch (action) {
+       case CPU_UP_PREPARE:
+               shx3_update_boot_vector(cpu);
+               break;
+       case CPU_ONLINE:
+               pr_info("CPU %u is now online\n", cpu);
+               break;
+       case CPU_DEAD:
+               break;
+       }
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
+       .notifier_call          = shx3_cpu_callback,
+};
+
+static int __cpuinit register_shx3_cpu_notifier(void)
+{
+       register_hotcpu_notifier(&shx3_cpu_notifier);
+       return 0;
+}
+late_initcall(register_shx3_cpu_notifier);
+
+struct plat_smp_ops shx3_smp_ops = {
+       .smp_setup              = shx3_smp_setup,
+       .prepare_cpus           = shx3_prepare_cpus,
+       .start_cpu              = shx3_start_cpu,
+       .smp_processor_id       = shx3_smp_processor_id,
+       .send_ipi               = shx3_send_ipi,
+       .cpu_die                = native_cpu_die,
+       .cpu_disable            = native_cpu_disable,
+       .play_dead              = native_play_dead,
+};
index 521d05b..9e88240 100644 (file)
@@ -17,7 +17,7 @@
 #include <asm/cache.h>
 #include <asm/tlb.h>
 
-int __init detect_cpu_and_cache_system(void)
+void __cpuinit cpu_probe(void)
 {
        unsigned long long cir;
 
@@ -72,6 +72,4 @@ int __init detect_cpu_and_cache_system(void)
 
        /* Setup some I/D TLB defaults */
        sh64_tlb_init();
-
-       return 0;
 }
index e7a3c1e..d910666 100644 (file)
@@ -68,16 +68,13 @@ static struct platform_device rtc_device = {
 #define TMU2_BASE      (TMU_BASE + 0x8 + (0xc * 0x2))
 
 static struct sh_timer_config tmu0_platform_data = {
-       .name = "TMU0",
        .channel_offset = 0x04,
        .timer_bit = 0,
-       .clk = "peripheral_clk",
        .clockevent_rating = 200,
 };
 
 static struct resource tmu0_resources[] = {
        [0] = {
-               .name   = "TMU0",
                .start  = TMU0_BASE,
                .end    = TMU0_BASE + 0xc - 1,
                .flags  = IORESOURCE_MEM,
@@ -99,16 +96,13 @@ static struct platform_device tmu0_device = {
 };
 
 static struct sh_timer_config tmu1_platform_data = {
-       .name = "TMU1",
        .channel_offset = 0x10,
        .timer_bit = 1,
-       .clk = "peripheral_clk",
        .clocksource_rating = 200,
 };
 
 static struct resource tmu1_resources[] = {
        [0] = {
-               .name   = "TMU1",
                .start  = TMU1_BASE,
                .end    = TMU1_BASE + 0xc - 1,
                .flags  = IORESOURCE_MEM,
@@ -130,15 +124,12 @@ static struct platform_device tmu1_device = {
 };
 
 static struct sh_timer_config tmu2_platform_data = {
-       .name = "TMU2",
        .channel_offset = 0x1c,
        .timer_bit = 2,
-       .clk = "peripheral_clk",
 };
 
 static struct resource tmu2_resources[] = {
        [0] = {
-               .name   = "TMU2",
                .start  = TMU2_BASE,
                .end    = TMU2_BASE + 0xc - 1,
                .flags  = IORESOURCE_MEM,
index 95d2162..37c97d4 100644 (file)
@@ -4,7 +4,6 @@
  *     Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
  *     Copyright (C) IBM Corporation, 2004. All rights reserved
  */
-
 #include <linux/errno.h>
 #include <linux/crash_dump.h>
 #include <linux/io.h>
 /* Stores the physical address of elf header of crash image. */
 unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
 
+/*
+ * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
+ * is_kdump_kernel() to determine if we are booting after a panic. Hence
+ * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
+ *
+ * elfcorehdr= specifies the location of elf core header
+ * stored by the crashed kernel.
+ */
+static int __init parse_elfcorehdr(char *arg)
+{
+       if (!arg)
+               return -EINVAL;
+
+       elfcorehdr_addr = memparse(arg, &arg);
+
+       return 0;
+}
+early_param("elfcorehdr", parse_elfcorehdr);
+
 /**
  * copy_oldmem_page - copy one page from "oldmem"
  * @pfn: page frame number to be copied
index a8234b2..5ec1d18 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/mm.h>
 #include <linux/elf.h>
 #include <linux/ftrace.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <asm/dwarf.h>
 #include <asm/unwinder.h>
index fe0b743..6e35f01 100644 (file)
@@ -131,6 +131,7 @@ ENTRY(_stext)
  *     r8 = scratch register
  *     r9 = scratch register
  *     r10 = number of PMB entries we've setup
+ *     r11 = scratch register
  */
 
        mov.l   .LMMUCR, r1     /* Flush the TLB */
@@ -167,8 +168,9 @@ ENTRY(_stext)
 
 .Lvalidate_existing_mappings:
 
+       mov.l   .LPMB_DATA_MASK, r11
        mov.l   @r7, r8
-       and     r0, r8
+       and     r11, r8
        cmp/eq  r0, r8          /* Check for valid __MEMORY_START mappings */
        bt      .Lpmb_done
 
@@ -335,12 +337,13 @@ ENTRY(stack_start)
 3:     .long   __bss_start
 4:     .long   _end
 5:     .long   start_kernel
-6:     .long   sh_cpu_init
+6:     .long   cpu_init
 7:     .long   init_thread_union
 
 #ifdef CONFIG_PMB
 .LPMB_ADDR:            .long   PMB_ADDR
 .LPMB_DATA:            .long   PMB_DATA
+.LPMB_DATA_MASK:       .long   PMB_PFN_MASK | PMB_V
 .LFIRST_ADDR_ENTRY:    .long   PAGE_OFFSET | PMB_V
 .LFIRST_DATA_ENTRY:    .long   __MEMORY_START | PMB_V
 .LMMUCR:               .long   MMUCR
index 675eea7..efae6ab 100644 (file)
@@ -119,26 +119,17 @@ static int get_hbp_len(u16 hbp_len)
        return len_in_bytes;
 }
 
-/*
- * Check for virtual address in user space.
- */
-int arch_check_va_in_userspace(unsigned long va, u16 hbp_len)
-{
-       unsigned int len;
-
-       len = get_hbp_len(hbp_len);
-
-       return (va <= TASK_SIZE - len);
-}
-
 /*
  * Check for virtual address in kernel space.
  */
-static int arch_check_va_in_kernelspace(unsigned long va, u8 hbp_len)
+int arch_check_bp_in_kernelspace(struct perf_event *bp)
 {
        unsigned int len;
+       unsigned long va;
+       struct arch_hw_breakpoint *info = counter_arch_bp(bp);
 
-       len = get_hbp_len(hbp_len);
+       va = info->address;
+       len = get_hbp_len(info->len);
 
        return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE);
 }
@@ -226,8 +217,7 @@ static int arch_build_bp_info(struct perf_event *bp)
 /*
  * Validate the arch-specific HW Breakpoint register settings
  */
-int arch_validate_hwbkpt_settings(struct perf_event *bp,
-                                 struct task_struct *tsk)
+int arch_validate_hwbkpt_settings(struct perf_event *bp)
 {
        struct arch_hw_breakpoint *info = counter_arch_bp(bp);
        unsigned int align;
@@ -270,15 +260,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp,
        if (info->address & align)
                return -EINVAL;
 
-       /* Check that the virtual address is in the proper range */
-       if (tsk) {
-               if (!arch_check_va_in_userspace(info->address, info->len))
-                       return -EFAULT;
-       } else {
-               if (!arch_check_va_in_kernelspace(info->address, info->len))
-                       return -EFAULT;
-       }
-
        return 0;
 }
 
@@ -363,8 +344,7 @@ static int __kprobes hw_breakpoint_handler(struct die_args *args)
                perf_bp_event(bp, args->regs);
 
                /* Deliver the signal to userspace */
-               if (arch_check_va_in_userspace(bp->attr.bp_addr,
-                                              bp->attr.bp_len)) {
+               if (!arch_check_bp_in_kernelspace(bp)) {
                        siginfo_t info;
 
                        info.si_signo = args->signr;
@@ -425,11 +405,6 @@ void hw_breakpoint_pmu_read(struct perf_event *bp)
        /* TODO */
 }
 
-void hw_breakpoint_pmu_unthrottle(struct perf_event *bp)
-{
-       /* TODO */
-}
-
 int register_sh_ubc(struct sh_ubc *ubc)
 {
        /* Bail if it's already assigned */
index 273f890..425d604 100644 (file)
@@ -19,6 +19,7 @@
 #include <asm/pgalloc.h>
 #include <asm/system.h>
 #include <asm/atomic.h>
+#include <asm/smp.h>
 
 void (*pm_idle)(void) = NULL;
 
@@ -89,10 +90,13 @@ void cpu_idle(void)
        while (1) {
                tick_nohz_stop_sched_tick(1);
 
-               while (!need_resched() && cpu_online(cpu)) {
+               while (!need_resched()) {
                        check_pgt_cache();
                        rmb();
 
+                       if (cpu_is_offline(cpu))
+                               play_dead();
+
                        local_irq_disable();
                        /* Don't trace irqs off for idle */
                        stop_critical_timings();
@@ -133,7 +137,7 @@ static void do_nothing(void *unused)
 void stop_this_cpu(void *unused)
 {
        local_irq_disable();
-       cpu_clear(smp_processor_id(), cpu_online_map);
+       set_cpu_online(smp_processor_id(), false);
 
        for (;;)
                cpu_sleep();
index d2d41d0..257de1f 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kernel_stat.h>
 #include <linux/seq_file.h>
 #include <linux/ftrace.h>
+#include <linux/delay.h>
 #include <asm/processor.h>
 #include <asm/machvec.h>
 #include <asm/uaccess.h>
@@ -113,19 +114,14 @@ union irq_ctx {
 
 static union irq_ctx *hardirq_ctx[NR_CPUS] __read_mostly;
 static union irq_ctx *softirq_ctx[NR_CPUS] __read_mostly;
-#endif
 
-asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
+static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
+static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
+
+static inline void handle_one_irq(unsigned int irq)
 {
-       struct pt_regs *old_regs = set_irq_regs(regs);
-#ifdef CONFIG_IRQSTACKS
        union irq_ctx *curctx, *irqctx;
-#endif
-
-       irq_enter();
-       irq = irq_demux(irq);
 
-#ifdef CONFIG_IRQSTACKS
        curctx = (union irq_ctx *)current_thread_info();
        irqctx = hardirq_ctx[smp_processor_id()];
 
@@ -164,20 +160,9 @@ asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
                          "r5", "r6", "r7", "r8", "t", "pr"
                );
        } else
-#endif
                generic_handle_irq(irq);
-
-       irq_exit();
-
-       set_irq_regs(old_regs);
-       return 1;
 }
 
-#ifdef CONFIG_IRQSTACKS
-static char softirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
-
-static char hardirq_stack[NR_CPUS * THREAD_SIZE] __page_aligned_bss;
-
 /*
  * allocate per-cpu stacks for hardirq and for softirq processing
  */
@@ -257,8 +242,33 @@ asmlinkage void do_softirq(void)
 
        local_irq_restore(flags);
 }
+#else
+static inline void handle_one_irq(unsigned int irq)
+{
+       generic_handle_irq(irq);
+}
 #endif
 
+asmlinkage __irq_entry int do_IRQ(unsigned int irq, struct pt_regs *regs)
+{
+       struct pt_regs *old_regs = set_irq_regs(regs);
+
+       irq_enter();
+
+       irq = irq_demux(irq_lookup(irq));
+
+       if (irq != NO_IRQ_IGNORE) {
+               handle_one_irq(irq);
+               irq_finish(irq);
+       }
+
+       irq_exit();
+
+       set_irq_regs(old_regs);
+
+       return IRQ_HANDLED;
+}
+
 void __init init_IRQ(void)
 {
        plat_irq_setup();
@@ -283,3 +293,44 @@ int __init arch_probe_nr_irqs(void)
        return 0;
 }
 #endif
+
+#ifdef CONFIG_HOTPLUG_CPU
+static void route_irq(struct irq_desc *desc, unsigned int irq, unsigned int cpu)
+{
+       printk(KERN_INFO "IRQ%u: moving from cpu%u to cpu%u\n",
+              irq, desc->node, cpu);
+
+       raw_spin_lock_irq(&desc->lock);
+       desc->chip->set_affinity(irq, cpumask_of(cpu));
+       raw_spin_unlock_irq(&desc->lock);
+}
+
+/*
+ * The CPU has been marked offline.  Migrate IRQs off this CPU.  If
+ * the affinity settings do not allow other CPUs, force them onto any
+ * available CPU.
+ */
+void migrate_irqs(void)
+{
+       struct irq_desc *desc;
+       unsigned int irq, cpu = smp_processor_id();
+
+       for_each_irq_desc(irq, desc) {
+               if (desc->node == cpu) {
+                       unsigned int newcpu = cpumask_any_and(desc->affinity,
+                                                             cpu_online_mask);
+                       if (newcpu >= nr_cpu_ids) {
+                               if (printk_ratelimit())
+                                       printk(KERN_INFO "IRQ%u no longer affine to CPU%u\n",
+                                              irq, cpu);
+
+                               cpumask_setall(desc->affinity);
+                               newcpu = cpumask_any_and(desc->affinity,
+                                                        cpu_online_mask);
+                       }
+
+                       route_irq(desc, irq, newcpu);
+               }
+       }
+}
+#endif
index 0b04e7d..8bfc6df 100644 (file)
@@ -44,7 +44,7 @@ static void dummy_timer_set_mode(enum clock_event_mode mode,
 {
 }
 
-void __cpuinit local_timer_setup(unsigned int cpu)
+void local_timer_setup(unsigned int cpu)
 {
        struct clock_event_device *clk = &per_cpu(local_clockevent, cpu);
 
@@ -60,3 +60,7 @@ void __cpuinit local_timer_setup(unsigned int cpu)
 
        clockevents_register_device(clk);
 }
+
+void local_timer_stop(unsigned int cpu)
+{
+}
index 7672141..5a559e6 100644 (file)
@@ -8,7 +8,6 @@
  * This source code is licensed under the GNU General Public License,
  * Version 2.  See the file COPYING for more details.
  */
-
 #include <linux/mm.h>
 #include <linux/kexec.h>
 #include <linux/delay.h>
@@ -16,6 +15,7 @@
 #include <linux/numa.h>
 #include <linux/ftrace.h>
 #include <linux/suspend.h>
+#include <linux/lmb.h>
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
@@ -147,4 +147,64 @@ void arch_crash_save_vmcoreinfo(void)
        VMCOREINFO_SYMBOL(node_data);
        VMCOREINFO_LENGTH(node_data, MAX_NUMNODES);
 #endif
+#ifdef CONFIG_X2TLB
+       VMCOREINFO_CONFIG(X2TLB);
+#endif
+}
+
+void __init reserve_crashkernel(void)
+{
+       unsigned long long crash_size, crash_base;
+       int ret;
+
+       /* this is necessary because of lmb_phys_mem_size() */
+       lmb_analyze();
+
+       ret = parse_crashkernel(boot_command_line, lmb_phys_mem_size(),
+                       &crash_size, &crash_base);
+       if (ret == 0 && crash_size > 0) {
+               crashk_res.start = crash_base;
+               crashk_res.end = crash_base + crash_size - 1;
+       }
+
+       if (crashk_res.end == crashk_res.start)
+               goto disable;
+
+       crash_size = PAGE_ALIGN(crashk_res.end - crashk_res.start + 1);
+       if (!crashk_res.start) {
+               unsigned long max = lmb_end_of_DRAM() - memory_limit;
+               crashk_res.start = __lmb_alloc_base(crash_size, PAGE_SIZE, max);
+               if (!crashk_res.start) {
+                       pr_err("crashkernel allocation failed\n");
+                       goto disable;
+               }
+       } else {
+               ret = lmb_reserve(crashk_res.start, crash_size);
+               if (unlikely(ret < 0)) {
+                       pr_err("crashkernel reservation failed - "
+                              "memory is in use\n");
+                       goto disable;
+               }
+       }
+
+       crashk_res.end = crashk_res.start + crash_size - 1;
+
+       /*
+        * Crash kernel trumps memory limit
+        */
+       if ((lmb_end_of_DRAM() - memory_limit) <= crashk_res.end) {
+               memory_limit = 0;
+               pr_info("Disabled memory limit for crashkernel\n");
+       }
+
+       pr_info("Reserving %ldMB of memory at 0x%08lx "
+               "for crashkernel (System RAM: %ldMB)\n",
+               (unsigned long)(crash_size >> 20),
+               (unsigned long)(crashk_res.start),
+               (unsigned long)(lmb_phys_mem_size() >> 20));
+
+       return;
+
+disable:
+       crashk_res.start = crashk_res.end = 0;
 }
index 1652340..85cfaf9 100644 (file)
@@ -131,6 +131,7 @@ void __init sh_mv_setup(void)
        mv_set(ioport_unmap);
        mv_set(irq_demux);
        mv_set(mode_pins);
+       mv_set(mem_init);
 
        if (!sh_mv.mv_nr_irqs)
                sh_mv.mv_nr_irqs = NR_IRQS;
index 17f89aa..dcb126d 100644 (file)
@@ -90,7 +90,7 @@ void arch_task_cache_init(void)
 # define HAVE_SOFTFP   0
 #endif
 
-void init_thread_xstate(void)
+void __cpuinit init_thread_xstate(void)
 {
        if (boot_cpu_data.flags & CPU_HAS_FPU)
                xstate_size = sizeof(struct sh_fpu_hard_struct);
index 7759a9a..d4104ce 100644 (file)
@@ -85,7 +85,7 @@ static int set_single_step(struct task_struct *tsk, unsigned long addr)
 
        bp = thread->ptrace_bps[0];
        if (!bp) {
-               hw_breakpoint_init(&attr);
+               ptrace_breakpoint_init(&attr);
 
                attr.bp_addr = addr;
                attr.bp_len = HW_BREAKPOINT_LEN_2;
index 8870d6b..2727346 100644 (file)
@@ -4,7 +4,7 @@
  * This file handles the architecture-dependent parts of initialization
  *
  *  Copyright (C) 1999  Niibe Yutaka
- *  Copyright (C) 2002 - 2007 Paul Mundt
+ *  Copyright (C) 2002 - 2010 Paul Mundt
  */
 #include <linux/screen_info.h>
 #include <linux/ioport.h>
@@ -39,7 +39,9 @@
 #include <asm/irq.h>
 #include <asm/setup.h>
 #include <asm/clock.h>
+#include <asm/smp.h>
 #include <asm/mmu_context.h>
+#include <asm/mmzone.h>
 
 /*
  * Initialize loops_per_jiffy as 10000000 (1000MIPS).
@@ -93,6 +95,7 @@ unsigned long memory_start;
 EXPORT_SYMBOL(memory_start);
 unsigned long memory_end = 0;
 EXPORT_SYMBOL(memory_end);
+unsigned long memory_limit = 0;
 
 static struct resource mem_resources[MAX_NUMNODES];
 
@@ -100,92 +103,73 @@ int l1i_cache_shape, l1d_cache_shape, l2_cache_shape;
 
 static int __init early_parse_mem(char *p)
 {
-       unsigned long size;
+       if (!p)
+               return 1;
 
-       memory_start = (unsigned long)__va(__MEMORY_START);
-       size = memparse(p, &p);
+       memory_limit = PAGE_ALIGN(memparse(p, &p));
 
-       if (size > __MEMORY_SIZE) {
-               printk(KERN_ERR
-                       "Using mem= to increase the size of kernel memory "
-                       "is not allowed.\n"
-                       "  Recompile the kernel with the correct value for "
-                       "CONFIG_MEMORY_SIZE.\n");
-               return 0;
-       }
-
-       memory_end = memory_start + size;
+       pr_notice("Memory limited to %ldMB\n", memory_limit >> 20);
 
        return 0;
 }
 early_param("mem", early_parse_mem);
 
-/*
- * Register fully available low RAM pages with the bootmem allocator.
- */
-static void __init register_bootmem_low_pages(void)
+void __init check_for_initrd(void)
 {
-       unsigned long curr_pfn, last_pfn, pages;
+#ifdef CONFIG_BLK_DEV_INITRD
+       unsigned long start, end;
+
+       /*
+        * Check for the rare cases where boot loaders adhere to the boot
+        * ABI.
+        */
+       if (!LOADER_TYPE || !INITRD_START || !INITRD_SIZE)
+               goto disable;
+
+       start = INITRD_START + __MEMORY_START;
+       end = start + INITRD_SIZE;
+
+       if (unlikely(end <= start))
+               goto disable;
+       if (unlikely(start & ~PAGE_MASK)) {
+               pr_err("initrd must be page aligned\n");
+               goto disable;
+       }
+
+       if (unlikely(start < PAGE_OFFSET)) {
+               pr_err("initrd start < PAGE_OFFSET\n");
+               goto disable;
+       }
+
+       if (unlikely(end > lmb_end_of_DRAM())) {
+               pr_err("initrd extends beyond end of memory "
+                      "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
+                      end, (unsigned long)lmb_end_of_DRAM());
+               goto disable;
+       }
 
        /*
-        * We are rounding up the start address of usable memory:
+        * If we got this far inspite of the boot loader's best efforts
+        * to the contrary, assume we actually have a valid initrd and
+        * fix up the root dev.
         */
-       curr_pfn = PFN_UP(__MEMORY_START);
+       ROOT_DEV = Root_RAM0;
 
        /*
-        * ... and at the end of the usable range downwards:
+        * Address sanitization
         */
-       last_pfn = PFN_DOWN(__pa(memory_end));
+       initrd_start = (unsigned long)__va(__pa(start));
+       initrd_end = initrd_start + INITRD_SIZE;
 
-       if (last_pfn > max_low_pfn)
-               last_pfn = max_low_pfn;
+       lmb_reserve(__pa(initrd_start), INITRD_SIZE);
 
-       pages = last_pfn - curr_pfn;
-       free_bootmem(PFN_PHYS(curr_pfn), PFN_PHYS(pages));
-}
+       return;
 
-#ifdef CONFIG_KEXEC
-static void __init reserve_crashkernel(void)
-{
-       unsigned long long free_mem;
-       unsigned long long crash_size, crash_base;
-       void *vp;
-       int ret;
-
-       free_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
-
-       ret = parse_crashkernel(boot_command_line, free_mem,
-                       &crash_size, &crash_base);
-       if (ret == 0 && crash_size) {
-               if (crash_base <= 0) {
-                       vp = alloc_bootmem_nopanic(crash_size);
-                       if (!vp) {
-                               printk(KERN_INFO "crashkernel allocation "
-                                      "failed\n");
-                               return;
-                       }
-                       crash_base = __pa(vp);
-               } else if (reserve_bootmem(crash_base, crash_size,
-                                       BOOTMEM_EXCLUSIVE) < 0) {
-                       printk(KERN_INFO "crashkernel reservation failed - "
-                                       "memory is in use\n");
-                       return;
-               }
-
-               printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
-                               "for crashkernel (System RAM: %ldMB)\n",
-                               (unsigned long)(crash_size >> 20),
-                               (unsigned long)(crash_base >> 20),
-                               (unsigned long)(free_mem >> 20));
-               crashk_res.start = crash_base;
-               crashk_res.end   = crash_base + crash_size - 1;
-               insert_resource(&iomem_resource, &crashk_res);
-       }
-}
-#else
-static inline void __init reserve_crashkernel(void)
-{}
+disable:
+       pr_info("initrd disabled\n");
+       initrd_start = initrd_end = 0;
 #endif
+}
 
 void __cpuinit calibrate_delay(void)
 {
@@ -207,13 +191,18 @@ void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
                                                unsigned long end_pfn)
 {
        struct resource *res = &mem_resources[nid];
+       unsigned long start, end;
 
        WARN_ON(res->name); /* max one active range per node for now */
 
+       start = start_pfn << PAGE_SHIFT;
+       end = end_pfn << PAGE_SHIFT;
+
        res->name = "System RAM";
-       res->start = start_pfn << PAGE_SHIFT;
-       res->end = (end_pfn << PAGE_SHIFT) - 1;
+       res->start = start;
+       res->end = end - 1;
        res->flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+
        if (request_resource(&iomem_resource, res)) {
                pr_err("unable to request memory_resource 0x%lx 0x%lx\n",
                       start_pfn, end_pfn);
@@ -229,138 +218,18 @@ void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
        request_resource(res, &data_resource);
        request_resource(res, &bss_resource);
 
-       add_active_range(nid, start_pfn, end_pfn);
-}
-
-void __init setup_bootmem_allocator(unsigned long free_pfn)
-{
-       unsigned long bootmap_size;
-       unsigned long bootmap_pages, bootmem_paddr;
-       u64 total_pages = (lmb_end_of_DRAM() - __MEMORY_START) >> PAGE_SHIFT;
-       int i;
-
-       bootmap_pages = bootmem_bootmap_pages(total_pages);
-
-       bootmem_paddr = lmb_alloc(bootmap_pages << PAGE_SHIFT, PAGE_SIZE);
-
-       /*
-        * Find a proper area for the bootmem bitmap. After this
-        * bootstrap step all allocations (until the page allocator
-        * is intact) must be done via bootmem_alloc().
-        */
-       bootmap_size = init_bootmem_node(NODE_DATA(0),
-                                        bootmem_paddr >> PAGE_SHIFT,
-                                        min_low_pfn, max_low_pfn);
-
-       /* Add active regions with valid PFNs. */
-       for (i = 0; i < lmb.memory.cnt; i++) {
-               unsigned long start_pfn, end_pfn;
-               start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
-               end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
-               __add_active_range(0, start_pfn, end_pfn);
-       }
-
-       /*
-        * Add all physical memory to the bootmem map and mark each
-        * area as present.
-        */
-       register_bootmem_low_pages();
-
-       /* Reserve the sections we're already using. */
-       for (i = 0; i < lmb.reserved.cnt; i++)
-               reserve_bootmem(lmb.reserved.region[i].base,
-                               lmb_size_bytes(&lmb.reserved, i),
-                               BOOTMEM_DEFAULT);
-
-       node_set_online(0);
-
-       sparse_memory_present_with_active_regions(0);
-
-#ifdef CONFIG_BLK_DEV_INITRD
-       ROOT_DEV = Root_RAM0;
-
-       if (LOADER_TYPE && INITRD_START) {
-               unsigned long initrd_start_phys = INITRD_START + __MEMORY_START;
-
-               if (initrd_start_phys + INITRD_SIZE <= PFN_PHYS(max_low_pfn)) {
-                       reserve_bootmem(initrd_start_phys, INITRD_SIZE,
-                                       BOOTMEM_DEFAULT);
-                       initrd_start = (unsigned long)__va(initrd_start_phys);
-                       initrd_end = initrd_start + INITRD_SIZE;
-               } else {
-                       printk("initrd extends beyond end of memory "
-                              "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
-                              initrd_start_phys + INITRD_SIZE,
-                              (unsigned long)PFN_PHYS(max_low_pfn));
-                       initrd_start = 0;
-               }
-       }
-#endif
-
-       reserve_crashkernel();
-}
-
-#ifndef CONFIG_NEED_MULTIPLE_NODES
-static void __init setup_memory(void)
-{
-       unsigned long start_pfn;
-       u64 base = min_low_pfn << PAGE_SHIFT;
-       u64 size = (max_low_pfn << PAGE_SHIFT) - base;
-
-       /*
-        * Partially used pages are not usable - thus
-        * we are rounding upwards:
-        */
-       start_pfn = PFN_UP(__pa(_end));
-
-       lmb_add(base, size);
-
-       /*
-        * Reserve the kernel text and
-        * Reserve the bootmem bitmap. We do this in two steps (first step
-        * was init_bootmem()), because this catches the (definitely buggy)
-        * case of us accidentally initializing the bootmem allocator with
-        * an invalid RAM area.
-        */
-       lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
-                   (PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -
-                   (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
-
        /*
-        * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
+        * Also make sure that there is a PMB mapping that covers this
+        * range before we attempt to activate it, to avoid reset by MMU.
+        * We can hit this path with NUMA or memory hot-add.
         */
-       if (CONFIG_ZERO_PAGE_OFFSET != 0)
-               lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
-
-       lmb_analyze();
-       lmb_dump_all();
+       pmb_bolt_mapping((unsigned long)__va(start), start, end - start,
+                        PAGE_KERNEL);
 
-       setup_bootmem_allocator(start_pfn);
-}
-#else
-extern void __init setup_memory(void);
-#endif
-
-/*
- * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
- * is_kdump_kernel() to determine if we are booting after a panic. Hence
- * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
- */
-#ifdef CONFIG_CRASH_DUMP
-/* elfcorehdr= specifies the location of elf core header
- * stored by the crashed kernel.
- */
-static int __init parse_elfcorehdr(char *arg)
-{
-       if (!arg)
-               return -EINVAL;
-       elfcorehdr_addr = memparse(arg, &arg);
-       return 0;
+       add_active_range(nid, start_pfn, end_pfn);
 }
-early_param("elfcorehdr", parse_elfcorehdr);
-#endif
 
-void __init __attribute__ ((weak)) plat_early_device_setup(void)
+void __init __weak plat_early_device_setup(void)
 {
 }
 
@@ -401,10 +270,6 @@ void __init setup_arch(char **cmdline_p)
        bss_resource.start = virt_to_phys(__bss_start);
        bss_resource.end = virt_to_phys(_ebss)-1;
 
-       memory_start = (unsigned long)__va(__MEMORY_START);
-       if (!memory_end)
-               memory_end = memory_start + __MEMORY_SIZE;
-
 #ifdef CONFIG_CMDLINE_OVERWRITE
        strlcpy(command_line, CONFIG_CMDLINE, sizeof(command_line));
 #else
@@ -421,47 +286,24 @@ void __init setup_arch(char **cmdline_p)
 
        parse_early_param();
 
-       uncached_init();
-
        plat_early_device_setup();
 
-       /* Let earlyprintk output early console messages */
-       early_platform_driver_probe("earlyprintk", 1, 1);
-
        sh_mv_setup();
 
-       /*
-        * Find the highest page frame number we have available
-        */
-       max_pfn = PFN_DOWN(__pa(memory_end));
-
-       /*
-        * Determine low and high memory ranges:
-        */
-       max_low_pfn = max_pfn;
-       min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
-
-       nodes_clear(node_online_map);
+       /* Let earlyprintk output early console messages */
+       early_platform_driver_probe("earlyprintk", 1, 1);
 
-       pmb_init();
-       lmb_init();
-       setup_memory();
-       sparse_init();
+       paging_init();
 
 #ifdef CONFIG_DUMMY_CONSOLE
        conswitchp = &dummy_con;
 #endif
-       paging_init();
-
-       ioremap_fixed_init();
 
        /* Perform the machine specific initialisation */
        if (likely(sh_mv.mv_setup))
                sh_mv.mv_setup(cmdline_p);
 
-#ifdef CONFIG_SMP
        plat_smp_setup();
-#endif
 }
 
 /* processor boot mode configuration */
index 002cc61..509b36b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * SMP support for the SuperH processors.
  *
- * Copyright (C) 2002 - 2008 Paul Mundt
+ * Copyright (C) 2002 - 2010 Paul Mundt
  * Copyright (C) 2006 - 2007 Akio Idehara
  *
  * This file is subject to the terms and conditions of the GNU General Public
 int __cpu_number_map[NR_CPUS];         /* Map physical to logical */
 int __cpu_logical_map[NR_CPUS];                /* Map logical to physical */
 
-static inline void __init smp_store_cpu_info(unsigned int cpu)
+struct plat_smp_ops *mp_ops = NULL;
+
+/* State of each CPU */
+DEFINE_PER_CPU(int, cpu_state) = { 0 };
+
+void __cpuinit register_smp_ops(struct plat_smp_ops *ops)
+{
+       if (mp_ops)
+               printk(KERN_WARNING "Overriding previously set SMP ops\n");
+
+       mp_ops = ops;
+}
+
+static inline void __cpuinit smp_store_cpu_info(unsigned int cpu)
 {
        struct sh_cpuinfo *c = cpu_data + cpu;
 
@@ -46,14 +59,14 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
 
        init_new_context(current, &init_mm);
        current_thread_info()->cpu = cpu;
-       plat_prepare_cpus(max_cpus);
+       mp_ops->prepare_cpus(max_cpus);
 
 #ifndef CONFIG_HOTPLUG_CPU
        init_cpu_present(&cpu_possible_map);
 #endif
 }
 
-void __devinit smp_prepare_boot_cpu(void)
+void __init smp_prepare_boot_cpu(void)
 {
        unsigned int cpu = smp_processor_id();
 
@@ -62,37 +75,137 @@ void __devinit smp_prepare_boot_cpu(void)
 
        set_cpu_online(cpu, true);
        set_cpu_possible(cpu, true);
+
+       per_cpu(cpu_state, cpu) = CPU_ONLINE;
+}
+
+#ifdef CONFIG_HOTPLUG_CPU
+void native_cpu_die(unsigned int cpu)
+{
+       unsigned int i;
+
+       for (i = 0; i < 10; i++) {
+               smp_rmb();
+               if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
+                       if (system_state == SYSTEM_RUNNING)
+                               pr_info("CPU %u is now offline\n", cpu);
+
+                       return;
+               }
+
+               msleep(100);
+       }
+
+       pr_err("CPU %u didn't die...\n", cpu);
+}
+
+int native_cpu_disable(unsigned int cpu)
+{
+       return cpu == 0 ? -EPERM : 0;
+}
+
+void play_dead_common(void)
+{
+       idle_task_exit();
+       irq_ctx_exit(raw_smp_processor_id());
+       mb();
+
+       __get_cpu_var(cpu_state) = CPU_DEAD;
+       local_irq_disable();
+}
+
+void native_play_dead(void)
+{
+       play_dead_common();
 }
 
+int __cpu_disable(void)
+{
+       unsigned int cpu = smp_processor_id();
+       struct task_struct *p;
+       int ret;
+
+       ret = mp_ops->cpu_disable(cpu);
+       if (ret)
+               return ret;
+
+       /*
+        * Take this CPU offline.  Once we clear this, we can't return,
+        * and we must not schedule until we're ready to give up the cpu.
+        */
+       set_cpu_online(cpu, false);
+
+       /*
+        * OK - migrate IRQs away from this CPU
+        */
+       migrate_irqs();
+
+       /*
+        * Stop the local timer for this CPU.
+        */
+       local_timer_stop(cpu);
+
+       /*
+        * Flush user cache and TLB mappings, and then remove this CPU
+        * from the vm mask set of all processes.
+        */
+       flush_cache_all();
+       local_flush_tlb_all();
+
+       read_lock(&tasklist_lock);
+       for_each_process(p)
+               if (p->mm)
+                       cpumask_clear_cpu(cpu, mm_cpumask(p->mm));
+       read_unlock(&tasklist_lock);
+
+       return 0;
+}
+#else /* ... !CONFIG_HOTPLUG_CPU */
+int native_cpu_disable(unsigned int cpu)
+{
+       return -ENOSYS;
+}
+
+void native_cpu_die(unsigned int cpu)
+{
+       /* We said "no" in __cpu_disable */
+       BUG();
+}
+
+void native_play_dead(void)
+{
+       BUG();
+}
+#endif
+
 asmlinkage void __cpuinit start_secondary(void)
 {
-       unsigned int cpu;
+       unsigned int cpu = smp_processor_id();
        struct mm_struct *mm = &init_mm;
 
        enable_mmu();
        atomic_inc(&mm->mm_count);
        atomic_inc(&mm->mm_users);
        current->active_mm = mm;
-       BUG_ON(current->mm);
        enter_lazy_tlb(mm, current);
+       local_flush_tlb_all();
 
        per_cpu_trap_init();
 
        preempt_disable();
 
-       notify_cpu_starting(smp_processor_id());
+       notify_cpu_starting(cpu);
 
        local_irq_enable();
 
-       cpu = smp_processor_id();
-
        /* Enable local timers */
        local_timer_setup(cpu);
        calibrate_delay();
 
        smp_store_cpu_info(cpu);
 
-       cpu_set(cpu, cpu_online_map);
+       set_cpu_online(cpu, true);
+       per_cpu(cpu_state, cpu) = CPU_ONLINE;
 
        cpu_idle();
 }
@@ -111,12 +224,19 @@ int __cpuinit __cpu_up(unsigned int cpu)
        struct task_struct *tsk;
        unsigned long timeout;
 
-       tsk = fork_idle(cpu);
-       if (IS_ERR(tsk)) {
-               printk(KERN_ERR "Failed forking idle task for cpu %d\n", cpu);
-               return PTR_ERR(tsk);
+       tsk = cpu_data[cpu].idle;
+       if (!tsk) {
+               tsk = fork_idle(cpu);
+               if (IS_ERR(tsk)) {
+                       pr_err("Failed forking idle task for cpu %d\n", cpu);
+                       return PTR_ERR(tsk);
+               }
+
+               cpu_data[cpu].idle = tsk;
        }
 
+       per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
+
        /* Fill in data in head.S for secondary cpus */
        stack_start.sp = tsk->thread.sp;
        stack_start.thread_info = tsk->stack;
@@ -127,7 +247,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
                           (unsigned long)&stack_start + sizeof(stack_start));
        wmb();
 
-       plat_start_cpu(cpu, (unsigned long)_stext);
+       mp_ops->start_cpu(cpu, (unsigned long)_stext);
 
        timeout = jiffies + HZ;
        while (time_before(jiffies, timeout)) {
@@ -135,6 +255,7 @@ int __cpuinit __cpu_up(unsigned int cpu)
                        break;
 
                udelay(10);
+               barrier();
        }
 
        if (cpu_online(cpu))
@@ -159,7 +280,7 @@ void __init smp_cpus_done(unsigned int max_cpus)
 
 void smp_send_reschedule(int cpu)
 {
-       plat_send_ipi(cpu, SMP_MSG_RESCHEDULE);
+       mp_ops->send_ipi(cpu, SMP_MSG_RESCHEDULE);
 }
 
 void smp_send_stop(void)
@@ -172,12 +293,12 @@ void arch_send_call_function_ipi_mask(const struct cpumask *mask)
        int cpu;
 
        for_each_cpu(cpu, mask)
-               plat_send_ipi(cpu, SMP_MSG_FUNCTION);
+               mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION);
 }
 
 void arch_send_call_function_single_ipi(int cpu)
 {
-       plat_send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
+       mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
 }
 
 void smp_timer_broadcast(const struct cpumask *mask)
@@ -185,7 +306,7 @@ void smp_timer_broadcast(const struct cpumask *mask)
        int cpu;
 
        for_each_cpu(cpu, mask)
-               plat_send_ipi(cpu, SMP_MSG_TIMER);
+               mp_ops->send_ipi(cpu, SMP_MSG_TIMER);
 }
 
 static void ipi_timer(void)
@@ -249,7 +370,6 @@ static void flush_tlb_mm_ipi(void *mm)
  * behalf of debugees, kswapd stealing pages from another process etc).
  * Kanoj 07/00.
  */
-
 void flush_tlb_mm(struct mm_struct *mm)
 {
        preempt_disable();
index 9b0b633..948fdb6 100644 (file)
@@ -52,7 +52,11 @@ static int __init topology_init(void)
 #endif
 
        for_each_present_cpu(i) {
-               ret = register_cpu(&per_cpu(cpu_devices, i), i);
+               struct cpu *c = &per_cpu(cpu_devices, i);
+
+               c->hotpluggable = 1;
+
+               ret = register_cpu(c, i);
                if (unlikely(ret))
                        printk(KERN_WARNING "%s: register_cpu %d failed (%d)\n",
                               __func__, i, ret);
index e3f92eb..e67e140 100644 (file)
@@ -944,3 +944,8 @@ asmlinkage void do_debug_interrupt(unsigned long code, struct pt_regs *regs)
        /* Clear all DEBUGINT causes */
        poke_real_address_q(DM_EXP_CAUSE_PHY, 0x0);
 }
+
+void __cpuinit per_cpu_trap_init(void)
+{
+       /* Nothing to do for now, VBR initialization later. */
+}
index 3dc8a8a..53f7c68 100644 (file)
@@ -10,6 +10,7 @@ cacheops-$(CONFIG_CPU_SH3)            := cache-sh3.o
 cacheops-$(CONFIG_CPU_SH4)             := cache-sh4.o flush-sh4.o
 cacheops-$(CONFIG_CPU_SH5)             := cache-sh5.o flush-sh4.o
 cacheops-$(CONFIG_SH7705_CACHE_32KB)   += cache-sh7705.o
+cacheops-$(CONFIG_CPU_SHX3)            += cache-shx3.o
 
 obj-y                  += $(cacheops-y)
 
@@ -18,13 +19,14 @@ mmu-$(CONFIG_MMU)   := extable_$(BITS).o fault_$(BITS).o \
                           ioremap.o kmap.o pgtable.o tlbflush_$(BITS).o
 
 obj-y                  += $(mmu-y)
-obj-$(CONFIG_DEBUG_FS) += asids-debugfs.o
 
-ifdef CONFIG_DEBUG_FS
-obj-$(CONFIG_CPU_SH4)  += cache-debugfs.o
+debugfs-y                      := asids-debugfs.o
+ifndef CONFIG_CACHE_OFF
+debugfs-$(CONFIG_CPU_SH4)      += cache-debugfs.o
 endif
 
 ifdef CONFIG_MMU
+debugfs-$(CONFIG_CPU_SH4)      += tlb-debugfs.o
 tlb-$(CONFIG_CPU_SH3)          := tlb-sh3.o
 tlb-$(CONFIG_CPU_SH4)          := tlb-sh4.o tlb-urb.o
 tlb-$(CONFIG_CPU_SH5)          := tlb-sh5.o
@@ -32,6 +34,7 @@ tlb-$(CONFIG_CPU_HAS_PTEAEX)  := tlb-pteaex.o tlb-urb.o
 obj-y                          += $(tlb-y)
 endif
 
+obj-$(CONFIG_DEBUG_FS)         += $(debugfs-y)
 obj-$(CONFIG_HUGETLB_PAGE)     += hugetlbpage.o
 obj-$(CONFIG_PMB)              += pmb.o
 obj-$(CONFIG_NUMA)             += numa.o
diff --git a/arch/sh/mm/cache-shx3.c b/arch/sh/mm/cache-shx3.c
new file mode 100644 (file)
index 0000000..c0adbee
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * arch/sh/mm/cache-shx3.c - SH-X3 optimized cache ops
+ *
+ * Copyright (C) 2010  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/io.h>
+#include <asm/cache.h>
+
+#define CCR_CACHE_SNM  0x40000         /* Hardware-assisted synonym avoidance */
+#define CCR_CACHE_IBE  0x1000000       /* ICBI broadcast */
+
+void __init shx3_cache_init(void)
+{
+       unsigned int ccr;
+
+       ccr = __raw_readl(CCR);
+
+       /*
+        * If we've got cache aliases, resolve them in hardware.
+        */
+       if (boot_cpu_data.dcache.n_aliases || boot_cpu_data.icache.n_aliases) {
+               ccr |= CCR_CACHE_SNM;
+
+               boot_cpu_data.icache.n_aliases = 0;
+               boot_cpu_data.dcache.n_aliases = 0;
+
+               pr_info("Enabling hardware synonym avoidance\n");
+       }
+
+#ifdef CONFIG_SMP
+       /*
+        * Broadcast I-cache block invalidations by default.
+        */
+       ccr |= CCR_CACHE_IBE;
+#endif
+
+       writel_uncached(ccr, CCR);
+}
index 0f4095d..ba401d1 100644 (file)
@@ -334,6 +334,13 @@ void __init cpu_cache_init(void)
                extern void __weak sh4_cache_init(void);
 
                sh4_cache_init();
+
+               if ((boot_cpu_data.type == CPU_SH7786) ||
+                   (boot_cpu_data.type == CPU_SHX3)) {
+                       extern void __weak shx3_cache_init(void);
+
+                       shx3_cache_init();
+               }
        }
 
        if (boot_cpu_data.family == CPU_FAMILY_SH5) {
index 8bf79e3..d4c34d7 100644 (file)
@@ -200,7 +200,6 @@ good_area:
         * make sure we exit gracefully rather than endlessly redo
         * the fault.
         */
-survive:
        fault = handle_mm_fault(mm, vma, address, writeaccess ? FAULT_FLAG_WRITE : 0);
        if (unlikely(fault & VM_FAULT_ERROR)) {
                if (fault & VM_FAULT_OOM)
@@ -290,15 +289,10 @@ no_context:
  */
 out_of_memory:
        up_read(&mm->mmap_sem);
-       if (is_global_init(current)) {
-               yield();
-               down_read(&mm->mmap_sem);
-               goto survive;
-       }
-       printk("VM: killing process %s\n", tsk->comm);
-       if (user_mode(regs))
-               do_group_exit(SIGKILL);
-       goto no_context;
+       if (!user_mode(regs))
+               goto no_context;
+       pagefault_out_of_memory();
+       return;
 
 do_sigbus:
        up_read(&mm->mmap_sem);
index c505de6..46f84de 100644 (file)
@@ -2,7 +2,7 @@
  * linux/arch/sh/mm/init.c
  *
  *  Copyright (C) 1999  Niibe Yutaka
- *  Copyright (C) 2002 - 2007  Paul Mundt
+ *  Copyright (C) 2002 - 2010  Paul Mundt
  *
  *  Based on linux/arch/i386/mm/init.c:
  *   Copyright (C) 1995  Linus Torvalds
 #include <linux/pagemap.h>
 #include <linux/percpu.h>
 #include <linux/io.h>
+#include <linux/lmb.h>
 #include <linux/dma-mapping.h>
 #include <asm/mmu_context.h>
+#include <asm/mmzone.h>
+#include <asm/kexec.h>
 #include <asm/tlb.h>
 #include <asm/cacheflush.h>
 #include <asm/sections.h>
+#include <asm/setup.h>
 #include <asm/cache.h>
 #include <asm/sizes.h>
 
 DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
 pgd_t swapper_pg_dir[PTRS_PER_PGD];
 
+void __init generic_mem_init(void)
+{
+       lmb_add(__MEMORY_START, __MEMORY_SIZE);
+}
+
+void __init __weak plat_mem_setup(void)
+{
+       /* Nothing to see here, move along. */
+}
+
 #ifdef CONFIG_MMU
 static pte_t *__get_pte_phys(unsigned long addr)
 {
@@ -152,15 +166,166 @@ void __init page_table_range_init(unsigned long start, unsigned long end,
 }
 #endif /* CONFIG_MMU */
 
-/*
- * paging_init() sets up the page tables
- */
+void __init allocate_pgdat(unsigned int nid)
+{
+       unsigned long start_pfn, end_pfn;
+#ifdef CONFIG_NEED_MULTIPLE_NODES
+       unsigned long phys;
+#endif
+
+       get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
+
+#ifdef CONFIG_NEED_MULTIPLE_NODES
+       phys = __lmb_alloc_base(sizeof(struct pglist_data),
+                               SMP_CACHE_BYTES, end_pfn << PAGE_SHIFT);
+       /* Retry with all of system memory */
+       if (!phys)
+               phys = __lmb_alloc_base(sizeof(struct pglist_data),
+                                       SMP_CACHE_BYTES, lmb_end_of_DRAM());
+       if (!phys)
+               panic("Can't allocate pgdat for node %d\n", nid);
+
+       NODE_DATA(nid) = __va(phys);
+       memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
+
+       NODE_DATA(nid)->bdata = &bootmem_node_data[nid];
+#endif
+
+       NODE_DATA(nid)->node_start_pfn = start_pfn;
+       NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
+}
+
+static void __init bootmem_init_one_node(unsigned int nid)
+{
+       unsigned long total_pages, paddr;
+       unsigned long end_pfn;
+       struct pglist_data *p;
+       int i;
+
+       p = NODE_DATA(nid);
+
+       /* Nothing to do.. */
+       if (!p->node_spanned_pages)
+               return;
+
+       end_pfn = p->node_start_pfn + p->node_spanned_pages;
+
+       total_pages = bootmem_bootmap_pages(p->node_spanned_pages);
+
+       paddr = lmb_alloc(total_pages << PAGE_SHIFT, PAGE_SIZE);
+       if (!paddr)
+               panic("Can't allocate bootmap for nid[%d]\n", nid);
+
+       init_bootmem_node(p, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);
+
+       free_bootmem_with_active_regions(nid, end_pfn);
+
+       /*
+        * XXX Handle initial reservations for the system memory node
+        * only for the moment, we'll refactor this later for handling
+        * reservations in other nodes.
+        */
+       if (nid == 0) {
+               /* Reserve the sections we're already using. */
+               for (i = 0; i < lmb.reserved.cnt; i++)
+                       reserve_bootmem(lmb.reserved.region[i].base,
+                                       lmb_size_bytes(&lmb.reserved, i),
+                                       BOOTMEM_DEFAULT);
+       }
+
+       sparse_memory_present_with_active_regions(nid);
+}
+
+static void __init do_init_bootmem(void)
+{
+       int i;
+
+       /* Add active regions with valid PFNs. */
+       for (i = 0; i < lmb.memory.cnt; i++) {
+               unsigned long start_pfn, end_pfn;
+               start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
+               end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
+               __add_active_range(0, start_pfn, end_pfn);
+       }
+
+       /* All of system RAM sits in node 0 for the non-NUMA case */
+       allocate_pgdat(0);
+       node_set_online(0);
+
+       plat_mem_setup();
+
+       for_each_online_node(i)
+               bootmem_init_one_node(i);
+
+       sparse_init();
+}
+
+static void __init early_reserve_mem(void)
+{
+       unsigned long start_pfn;
+
+       /*
+        * Partially used pages are not usable - thus
+        * we are rounding upwards:
+        */
+       start_pfn = PFN_UP(__pa(_end));
+
+       /*
+        * Reserve the kernel text and Reserve the bootmem bitmap. We do
+        * this in two steps (first step was init_bootmem()), because
+        * this catches the (definitely buggy) case of us accidentally
+        * initializing the bootmem allocator with an invalid RAM area.
+        */
+       lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
+                   (PFN_PHYS(start_pfn) + PAGE_SIZE - 1) -
+                   (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
+
+       /*
+        * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
+        */
+       if (CONFIG_ZERO_PAGE_OFFSET != 0)
+               lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
+
+       /*
+        * Handle additional early reservations
+        */
+       check_for_initrd();
+       reserve_crashkernel();
+}
+
 void __init paging_init(void)
 {
        unsigned long max_zone_pfns[MAX_NR_ZONES];
        unsigned long vaddr, end;
        int nid;
 
+       lmb_init();
+
+       sh_mv.mv_mem_init();
+
+       early_reserve_mem();
+
+       lmb_enforce_memory_limit(memory_limit);
+       lmb_analyze();
+
+       lmb_dump_all();
+
+       /*
+        * Determine low and high memory ranges:
+        */
+       max_low_pfn = max_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
+       min_low_pfn = __MEMORY_START >> PAGE_SHIFT;
+
+       nodes_clear(node_online_map);
+
+       memory_start = (unsigned long)__va(__MEMORY_START);
+       memory_end = memory_start + (memory_limit ?: lmb_phys_mem_size());
+
+       uncached_init();
+       pmb_init();
+       do_init_bootmem();
+       ioremap_fixed_init();
+
        /* We don't need to map the kernel through the TLB, as
         * it is permanatly mapped using P1. So clear the
         * entire pgd. */
index 961b340..a2e645f 100644 (file)
@@ -24,44 +24,6 @@ EXPORT_SYMBOL_GPL(node_data);
  * latency. Each node's pgdat is node-local at the beginning of the node,
  * immediately followed by the node mem map.
  */
-void __init setup_memory(void)
-{
-       unsigned long free_pfn = PFN_UP(__pa(_end));
-       u64 base = min_low_pfn << PAGE_SHIFT;
-       u64 size = (max_low_pfn << PAGE_SHIFT) - base;
-
-       lmb_add(base, size);
-
-       /* Reserve the LMB regions used by the kernel, initrd, etc.. */
-       lmb_reserve(__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET,
-                   (PFN_PHYS(free_pfn) + PAGE_SIZE - 1) -
-                   (__MEMORY_START + CONFIG_ZERO_PAGE_OFFSET));
-
-       /*
-        * Reserve physical pages below CONFIG_ZERO_PAGE_OFFSET.
-        */
-       if (CONFIG_ZERO_PAGE_OFFSET != 0)
-               lmb_reserve(__MEMORY_START, CONFIG_ZERO_PAGE_OFFSET);
-
-       lmb_analyze();
-       lmb_dump_all();
-
-       /*
-        * Node 0 sets up its pgdat at the first available pfn,
-        * and bumps it up before setting up the bootmem allocator.
-        */
-       NODE_DATA(0) = pfn_to_kaddr(free_pfn);
-       memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
-       free_pfn += PFN_UP(sizeof(struct pglist_data));
-       NODE_DATA(0)->bdata = &bootmem_node_data[0];
-
-       /* Set up node 0 */
-       setup_bootmem_allocator(free_pfn);
-
-       /* Give the platforms a chance to hook up their nodes */
-       plat_mem_setup();
-}
-
 void __init setup_bootmem_node(int nid, unsigned long start, unsigned long end)
 {
        unsigned long bootmap_pages;
index e43ec60..18623ba 100644 (file)
@@ -341,6 +341,8 @@ int pmb_bolt_mapping(unsigned long vaddr, phys_addr_t phys,
        unsigned long flags, pmb_flags;
        int i, mapped;
 
+       if (size < SZ_16M)
+               return -EINVAL;
        if (!pmb_addr_valid(vaddr, size))
                return -EFAULT;
        if (pmb_mapping_exists(vaddr, phys, size))
@@ -680,7 +682,7 @@ static void __init pmb_merge(struct pmb_entry *head)
        /*
         * The merged page size must be valid.
         */
-       if (!pmb_size_valid(newsize))
+       if (!depth || !pmb_size_valid(newsize))
                return;
 
        head->flags &= ~PMB_SZ_MASK;
diff --git a/arch/sh/mm/tlb-debugfs.c b/arch/sh/mm/tlb-debugfs.c
new file mode 100644 (file)
index 0000000..229bf75
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * arch/sh/mm/tlb-debugfs.c
+ *
+ * debugfs ops for SH-4 ITLB/UTLBs.
+ *
+ * Copyright (C) 2010  Matt Fleming
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/debugfs.h>
+#include <linux/seq_file.h>
+#include <asm/processor.h>
+#include <asm/mmu_context.h>
+#include <asm/tlbflush.h>
+
+enum tlb_type {
+       TLB_TYPE_ITLB,
+       TLB_TYPE_UTLB,
+};
+
+static struct {
+       int bits;
+       const char *size;
+} tlb_sizes[] = {
+       { 0x0, "  1KB" },
+       { 0x1, "  4KB" },
+       { 0x2, "  8KB" },
+       { 0x4, " 64KB" },
+       { 0x5, "256KB" },
+       { 0x7, "  1MB" },
+       { 0x8, "  4MB" },
+       { 0xc, " 64MB" },
+};
+
+static int tlb_seq_show(struct seq_file *file, void *iter)
+{
+       unsigned int tlb_type = (unsigned int)file->private;
+       unsigned long addr1, addr2, data1, data2;
+       unsigned long flags;
+       unsigned long mmucr;
+       unsigned int nentries, entry;
+       unsigned int urb;
+
+       mmucr = __raw_readl(MMUCR);
+       if ((mmucr & 0x1) == 0) {
+               seq_printf(file, "address translation disabled\n");
+               return 0;
+       }
+
+       if (tlb_type == TLB_TYPE_ITLB) {
+               addr1 = MMU_ITLB_ADDRESS_ARRAY;
+               addr2 = MMU_ITLB_ADDRESS_ARRAY2;
+               data1 = MMU_ITLB_DATA_ARRAY;
+               data2 = MMU_ITLB_DATA_ARRAY2;
+               nentries = 4;
+       } else {
+               addr1 = MMU_UTLB_ADDRESS_ARRAY;
+               addr2 = MMU_UTLB_ADDRESS_ARRAY2;
+               data1 = MMU_UTLB_DATA_ARRAY;
+               data2 = MMU_UTLB_DATA_ARRAY2;
+               nentries = 64;
+       }
+
+       local_irq_save(flags);
+       jump_to_uncached();
+
+       urb = (mmucr & MMUCR_URB) >> MMUCR_URB_SHIFT;
+
+       /* Make the "entry >= urb" test fail. */
+       if (urb == 0)
+               urb = MMUCR_URB_NENTRIES + 1;
+
+       if (tlb_type == TLB_TYPE_ITLB) {
+               addr1 = MMU_ITLB_ADDRESS_ARRAY;
+               addr2 = MMU_ITLB_ADDRESS_ARRAY2;
+               data1 = MMU_ITLB_DATA_ARRAY;
+               data2 = MMU_ITLB_DATA_ARRAY2;
+               nentries = 4;
+       } else {
+               addr1 = MMU_UTLB_ADDRESS_ARRAY;
+               addr2 = MMU_UTLB_ADDRESS_ARRAY2;
+               data1 = MMU_UTLB_DATA_ARRAY;
+               data2 = MMU_UTLB_DATA_ARRAY2;
+               nentries = 64;
+       }
+
+       seq_printf(file, "entry:     vpn        ppn     asid  size valid wired\n");
+
+       for (entry = 0; entry < nentries; entry++) {
+               unsigned long vpn, ppn, asid, size;
+               unsigned long valid;
+               unsigned long val;
+               const char *sz = "    ?";
+               int i;
+
+               val = __raw_readl(addr1 | (entry << MMU_TLB_ENTRY_SHIFT));
+               ctrl_barrier();
+               vpn = val & 0xfffffc00;
+               valid = val & 0x100;
+
+               val = __raw_readl(addr2 | (entry << MMU_TLB_ENTRY_SHIFT));
+               ctrl_barrier();
+               asid = val & MMU_CONTEXT_ASID_MASK;
+
+               val = __raw_readl(data1 | (entry << MMU_TLB_ENTRY_SHIFT));
+               ctrl_barrier();
+               ppn = (val & 0x0ffffc00) << 4;
+
+               val = __raw_readl(data2 | (entry << MMU_TLB_ENTRY_SHIFT));
+               ctrl_barrier();
+               size = (val & 0xf0) >> 4;
+
+               for (i = 0; i < ARRAY_SIZE(tlb_sizes); i++) {
+                       if (tlb_sizes[i].bits == size)
+                               break;
+               }
+
+               if (i != ARRAY_SIZE(tlb_sizes))
+                       sz = tlb_sizes[i].size;
+
+               seq_printf(file, "%2d:    0x%08lx 0x%08lx %5lu %s   %s     %s\n",
+                          entry, vpn, ppn, asid,
+                          sz, valid ? "V" : "-",
+                          (urb <= entry) ? "W" : "-");
+       }
+
+       back_to_cached();
+       local_irq_restore(flags);
+
+       return 0;
+}
+
+static int tlb_debugfs_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, tlb_seq_show, inode->i_private);
+}
+
+static const struct file_operations tlb_debugfs_fops = {
+       .owner          = THIS_MODULE,
+       .open           = tlb_debugfs_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int __init tlb_debugfs_init(void)
+{
+       struct dentry *itlb, *utlb;
+
+       itlb = debugfs_create_file("itlb", S_IRUSR, sh_debugfs_root,
+                                  (unsigned int *)TLB_TYPE_ITLB,
+                                  &tlb_debugfs_fops);
+       if (unlikely(!itlb))
+               return -ENOMEM;
+       if (IS_ERR(itlb))
+               return PTR_ERR(itlb);
+
+       utlb = debugfs_create_file("utlb", S_IRUSR, sh_debugfs_root,
+                                  (unsigned int *)TLB_TYPE_UTLB,
+                                  &tlb_debugfs_fops);
+       if (unlikely(!utlb)) {
+               debugfs_remove(itlb);
+               return -ENOMEM;
+       }
+
+       if (IS_ERR(utlb)) {
+               debugfs_remove(itlb);
+               return PTR_ERR(utlb);
+       }
+
+       return 0;
+}
+module_init(tlb_debugfs_init);
+
+MODULE_LICENSE("GPL v2");
index 706da1d..03db41c 100644 (file)
@@ -189,7 +189,6 @@ good_area:
         * make sure we exit gracefully rather than endlessly redo
         * the fault.
         */
-survive:
        fault = handle_mm_fault(mm, vma, address, writeaccess ? FAULT_FLAG_WRITE : 0);
        if (unlikely(fault & VM_FAULT_ERROR)) {
                if (fault & VM_FAULT_OOM)
@@ -294,22 +293,11 @@ no_context:
  * us unable to handle the page fault gracefully.
  */
 out_of_memory:
-       if (is_global_init(current)) {
-               panic("INIT out of memory\n");
-               yield();
-               goto survive;
-       }
-       printk("fault:Out of memory\n");
        up_read(&mm->mmap_sem);
-       if (is_global_init(current)) {
-               yield();
-               down_read(&mm->mmap_sem);
-               goto survive;
-       }
-       printk("VM: killing process %s\n", tsk->comm);
-       if (user_mode(regs))
-               do_group_exit(SIGKILL);
-       goto no_context;
+       if (!user_mode(regs))
+               goto no_context;
+       pagefault_out_of_memory();
+       return;
 
 do_sigbus:
        printk("fault:Do sigbus\n");
index 9908d47..d6781ce 100644 (file)
@@ -75,7 +75,7 @@ config ARCH_USES_GETTIMEOFFSET
 
 config GENERIC_CMOS_UPDATE
        bool
-       default y if SPARC64
+       default y
 
 config GENERIC_CLOCKEVENTS
        bool
index f0d343c..7ae128b 100644 (file)
@@ -25,7 +25,7 @@ extern int atomic_cmpxchg(atomic_t *, int, int);
 extern int atomic_add_unless(atomic_t *, int, int);
 extern void atomic_set(atomic_t *, int);
 
-#define atomic_read(v)          ((v)->counter)
+#define atomic_read(v)          (*(volatile int *)&(v)->counter)
 
 #define atomic_add(i, v)       ((void)__atomic_add_return( (int)(i), (v)))
 #define atomic_sub(i, v)       ((void)__atomic_add_return(-(int)(i), (v)))
index f2e4800..2050ca0 100644 (file)
@@ -13,8 +13,8 @@
 #define ATOMIC_INIT(i)         { (i) }
 #define ATOMIC64_INIT(i)       { (i) }
 
-#define atomic_read(v)         ((v)->counter)
-#define atomic64_read(v)       ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
+#define atomic64_read(v)       (*(volatile long *)&(v)->counter)
 
 #define atomic_set(v, i)       (((v)->counter) = i)
 #define atomic64_set(v, i)     (((v)->counter) = i)
index e72ac9c..766121a 100644 (file)
@@ -44,7 +44,7 @@ extern void change_bit(unsigned long nr, volatile unsigned long *addr);
 
 #ifdef ULTRA_HAS_POPULATION_COUNT
 
-static inline unsigned int hweight64(unsigned long w)
+static inline unsigned int __arch_hweight64(unsigned long w)
 {
        unsigned int res;
 
@@ -52,7 +52,7 @@ static inline unsigned int hweight64(unsigned long w)
        return res;
 }
 
-static inline unsigned int hweight32(unsigned int w)
+static inline unsigned int __arch_hweight32(unsigned int w)
 {
        unsigned int res;
 
@@ -60,7 +60,7 @@ static inline unsigned int hweight32(unsigned int w)
        return res;
 }
 
-static inline unsigned int hweight16(unsigned int w)
+static inline unsigned int __arch_hweight16(unsigned int w)
 {
        unsigned int res;
 
@@ -68,7 +68,7 @@ static inline unsigned int hweight16(unsigned int w)
        return res;
 }
 
-static inline unsigned int hweight8(unsigned int w)
+static inline unsigned int __arch_hweight8(unsigned int w)
 {
        unsigned int res;
 
@@ -78,9 +78,10 @@ static inline unsigned int hweight8(unsigned int w)
 
 #else
 
-#include <asm-generic/bitops/hweight.h>
+#include <asm-generic/bitops/arch_hweight.h>
 
 #endif
+#include <asm-generic/bitops/const_hweight.h>
 #include <asm-generic/bitops/lock.h>
 #endif /* __KERNEL__ */
 
index 41f85ae..78b0700 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef _SPARC_CACHE_H
 #define _SPARC_CACHE_H
 
+#define ARCH_SLAB_MINALIGN     __alignof__(unsigned long long)
+
 #define L1_CACHE_SHIFT 5
 #define L1_CACHE_BYTES 32
 #define L1_CACHE_ALIGN(x) ((((x)+(L1_CACHE_BYTES-1))&~(L1_CACHE_BYTES-1)))
index 844d73a..9dd0318 100644 (file)
@@ -132,7 +132,7 @@ BTFIXUPDEF_CALL(void, free_thread_info, struct thread_info *)
                                         * this quantum (SMP) */
 #define TIF_POLLING_NRFLAG     9       /* true if poll_idle() is polling
                                         * TIF_NEED_RESCHED */
-#define TIF_MEMDIE             10
+#define TIF_MEMDIE             10      /* is terminating due to OOM killer */
 #define TIF_FREEZE             11      /* is freezing for suspend */
 
 /* as above, but as bit values */
index 4827a3a..fb2ea77 100644 (file)
@@ -223,7 +223,7 @@ register struct thread_info *current_thread_info_reg asm("g6");
  *       an immediate value in instructions such as andcc.
  */
 /* flag bit 12 is available */
-#define TIF_MEMDIE             13
+#define TIF_MEMDIE             13      /* is terminating due to OOM killer */
 #define TIF_POLLING_NRFLAG     14
 #define TIF_FREEZE             15      /* is freezing for suspend */
 
index e277193..34ce49f 100644 (file)
@@ -14,6 +14,7 @@
 
 #include <linux/perf_event.h>
 #include <linux/kprobes.h>
+#include <linux/ftrace.h>
 #include <linux/kernel.h>
 #include <linux/kdebug.h>
 #include <linux/mutex.h>
@@ -1276,6 +1277,9 @@ static void perf_callchain_kernel(struct pt_regs *regs,
                                  struct perf_callchain_entry *entry)
 {
        unsigned long ksp, fp;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+       int graph = 0;
+#endif
 
        callchain_store(entry, PERF_CONTEXT_KERNEL);
        callchain_store(entry, regs->tpc);
@@ -1303,6 +1307,16 @@ static void perf_callchain_kernel(struct pt_regs *regs,
                        fp = (unsigned long)sf->fp + STACK_BIAS;
                }
                callchain_store(entry, pc);
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+               if ((pc + 8UL) == (unsigned long) &return_to_handler) {
+                       int index = current->curr_ret_stack;
+                       if (current->ret_stack && index >= graph) {
+                               pc = current->ret_stack[index - graph].ret;
+                               callchain_store(entry, pc);
+                               graph++;
+                       }
+               }
+#endif
        } while (entry->nr < PERF_MAX_STACK_DEPTH);
 }
 
index a5cf386..dbe81a3 100644 (file)
@@ -202,6 +202,7 @@ void show_regs(struct pt_regs *regs)
               regs->u_regs[15]);
        printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
        show_regwindow(regs);
+       show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
 }
 
 struct global_reg_snapshot global_reg_snapshot[NR_CPUS];
index acb12f6..3e08153 100644 (file)
@@ -1,6 +1,7 @@
 #include <linux/sched.h>
 #include <linux/stacktrace.h>
 #include <linux/thread_info.h>
+#include <linux/ftrace.h>
 #include <linux/module.h>
 #include <asm/ptrace.h>
 #include <asm/stacktrace.h>
@@ -12,6 +13,10 @@ static void __save_stack_trace(struct thread_info *tp,
                               bool skip_sched)
 {
        unsigned long ksp, fp;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+       struct task_struct *t;
+       int graph = 0;
+#endif
 
        if (tp == current_thread_info()) {
                stack_trace_flush();
@@ -21,6 +26,9 @@ static void __save_stack_trace(struct thread_info *tp,
        }
 
        fp = ksp + STACK_BIAS;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+       t = tp->task;
+#endif
        do {
                struct sparc_stackf *sf;
                struct pt_regs *regs;
@@ -44,8 +52,21 @@ static void __save_stack_trace(struct thread_info *tp,
 
                if (trace->skip > 0)
                        trace->skip--;
-               else if (!skip_sched || !in_sched_functions(pc))
+               else if (!skip_sched || !in_sched_functions(pc)) {
                        trace->entries[trace->nr_entries++] = pc;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+                       if ((pc + 8UL) == (unsigned long) &return_to_handler) {
+                               int index = t->curr_ret_stack;
+                               if (t->ret_stack && index >= graph) {
+                                       pc = t->ret_stack[index - graph].ret;
+                                       if (trace->nr_entries <
+                                           trace->max_entries)
+                                               trace->entries[trace->nr_entries++] = pc;
+                                       graph++;
+                               }
+                       }
+#endif
+               }
        } while (trace->nr_entries < trace->max_entries);
 }
 
index 0d4c09b..4453003 100644 (file)
@@ -78,6 +78,11 @@ __volatile__ unsigned int *master_l10_counter;
 
 u32 (*do_arch_gettimeoffset)(void);
 
+int update_persistent_clock(struct timespec now)
+{
+       return set_rtc_mmss(now.tv_sec);
+}
+
 /*
  * timer_interrupt() needs to keep up the real-time clock,
  * as well as call the "do_timer()" routine every clocktick
@@ -87,9 +92,6 @@ u32 (*do_arch_gettimeoffset)(void);
 
 static irqreturn_t timer_interrupt(int dummy, void *dev_id)
 {
-       /* last time the cmos clock got updated */
-       static long last_rtc_update;
-
 #ifndef CONFIG_SMP
        profile_tick(CPU_PROFILING);
 #endif
@@ -101,16 +103,6 @@ static irqreturn_t timer_interrupt(int dummy, void *dev_id)
 
        do_timer(1);
 
-       /* Determine when to update the Mostek clock. */
-       if (ntp_synced() &&
-           xtime.tv_sec > last_rtc_update + 660 &&
-           (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
-           (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
-         if (set_rtc_mmss(xtime.tv_sec) == 0)
-           last_rtc_update = xtime.tv_sec;
-         else
-           last_rtc_update = xtime.tv_sec - 600; /* do it again in 60 s */
-       }
        write_sequnlock(&xtime_lock);
 
 #ifndef CONFIG_SMP
index 9da57f0..42ad2ba 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/kdebug.h>
+#include <linux/ftrace.h>
 #include <linux/gfp.h>
 
 #include <asm/smp.h>
@@ -2154,6 +2155,9 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
        unsigned long fp, thread_base, ksp;
        struct thread_info *tp;
        int count = 0;
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+       int graph = 0;
+#endif
 
        ksp = (unsigned long) _ksp;
        if (!tsk)
@@ -2193,6 +2197,16 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
                }
 
                printk(" [%016lx] %pS\n", pc, (void *) pc);
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+               if ((pc + 8UL) == (unsigned long) &return_to_handler) {
+                       int index = tsk->curr_ret_stack;
+                       if (tsk->ret_stack && index >= graph) {
+                               pc = tsk->ret_stack[index - graph].ret;
+                               printk(" [%016lx] %pS\n", pc, (void *) pc);
+                               graph++;
+                       }
+               }
+#endif
        } while (++count < 16);
 }
 
index 7a656bd..7f7338c 100644 (file)
@@ -19,7 +19,6 @@ static irqreturn_t line_interrupt(int irq, void *data)
 {
        struct chan *chan = data;
        struct line *line = chan->line;
-       struct tty_struct *tty;
 
        if (line)
                chan_interrupt(&line->chan_list, &line->task, line->tty, irq);
index 753346e..93af1cf 100644 (file)
@@ -3,11 +3,8 @@
 
 #include "sysdep/system.h"
 
-extern void *switch_to(void *prev, void *next, void *last);
-
 extern int get_signals(void);
 extern int set_signals(int enable);
-extern int get_signals(void);
 extern void block_signals(void);
 extern void unblock_signals(void);
 
index fd911f8..e2cf786 100644 (file)
@@ -63,10 +63,9 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_SIGPENDING         1       /* signal pending */
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_POLLING_NRFLAG      3       /* true if poll_idle() is polling
-                                        * TIF_NEED_RESCHED
-                                        */
-#define TIF_RESTART_BLOCK      4
-#define TIF_MEMDIE             5
+                                        * TIF_NEED_RESCHED */
+#define TIF_RESTART_BLOCK      4
+#define TIF_MEMDIE             5       /* is terminating due to OOM killer */
 #define TIF_SYSCALL_AUDIT      6
 #define TIF_RESTORE_SIGMASK    7
 #define TIF_FREEZE             16      /* is freezing for suspend */
index 4e3b820..f5173e1 100644 (file)
@@ -10,7 +10,7 @@
 #include "sysdep/syscalls.h"
 
 extern int syscall_table_size;
-#define NR_syscalls (syscall_table_size / sizeof(void *))
+#define NR_SYSCALLS (syscall_table_size / sizeof(void *))
 
 void handle_syscall(struct uml_pt_regs *r)
 {
@@ -30,7 +30,7 @@ void handle_syscall(struct uml_pt_regs *r)
         * in case it's a compiler bug.
         */
        syscall = UPT_SYSCALL_NR(r);
-       if ((syscall >= NR_syscalls) || (syscall < 0))
+       if ((syscall >= NR_SYSCALLS) || (syscall < 0))
                result = -ENOSYS;
        else result = EXECUTE_SYSCALL(syscall, regs);
 
index e64cd41..a979a22 100644 (file)
@@ -75,6 +75,8 @@ typedef struct user_i387_struct elf_fpregset_t;
        pr_reg[16] = PT_REGS_SS(regs);          \
 } while (0);
 
+struct task_struct;
+
 extern int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu);
 
 #define ELF_CORE_COPY_FPREGS(t, fpu) elf_core_copy_fpregs(t, fpu)
index 49655c8..d760967 100644 (file)
@@ -95,6 +95,8 @@ typedef struct user_i387_struct elf_fpregset_t;
        (pr_reg)[25] = 0;                                       \
        (pr_reg)[26] = 0;
 
+struct task_struct;
+
 extern int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu);
 
 #define ELF_CORE_COPY_FPREGS(t, fpu) elf_core_copy_fpregs(t, fpu)
index 1a899a7..b6b65c7 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <linux/personality.h>
 #include <linux/ptrace.h>
+#include <linux/kernel.h>
 #include <asm/unistd.h>
 #include <asm/uaccess.h>
 #include <asm/ucontext.h>
@@ -165,8 +166,6 @@ struct rt_sigframe
        struct _fpstate fpstate;
 };
 
-#define round_down(m, n) (((m) / (n)) * (n))
-
 int setup_signal_stack_si(unsigned long stack_top, int sig,
                          struct k_sigaction *ka, struct pt_regs * regs,
                          siginfo_t *info, sigset_t *set)
index 9458685..a2d3a5f 100644 (file)
@@ -53,11 +53,15 @@ config X86
        select HAVE_KERNEL_LZMA
        select HAVE_KERNEL_LZO
        select HAVE_HW_BREAKPOINT
+       select HAVE_MIXED_BREAKPOINTS_REGS
        select PERF_EVENTS
        select ANON_INODES
        select HAVE_ARCH_KMEMCHECK
        select HAVE_USER_RETURN_NOTIFIER
 
+config INSTRUCTION_DECODER
+       def_bool (KPROBES || PERF_EVENTS)
+
 config OUTPUT_FORMAT
        string
        default "elf32-i386" if X86_32
@@ -197,20 +201,17 @@ config HAVE_INTEL_TXT
 
 # Use the generic interrupt handling code in kernel/irq/:
 config GENERIC_HARDIRQS
-       bool
-       default y
+       def_bool y
 
 config GENERIC_HARDIRQS_NO__DO_IRQ
        def_bool y
 
 config GENERIC_IRQ_PROBE
-       bool
-       default y
+       def_bool y
 
 config GENERIC_PENDING_IRQ
-       bool
+       def_bool y
        depends on GENERIC_HARDIRQS && SMP
-       default y
 
 config USE_GENERIC_SMP_HELPERS
        def_bool y
@@ -225,19 +226,22 @@ config X86_64_SMP
        depends on X86_64 && SMP
 
 config X86_HT
-       bool
+       def_bool y
        depends on SMP
-       default y
 
 config X86_TRAMPOLINE
-       bool
+       def_bool y
        depends on SMP || (64BIT && ACPI_SLEEP)
-       default y
 
 config X86_32_LAZY_GS
        def_bool y
        depends on X86_32 && !CC_STACKPROTECTOR
 
+config ARCH_HWEIGHT_CFLAGS
+       string
+       default "-fcall-saved-ecx -fcall-saved-edx" if X86_32
+       default "-fcall-saved-rdi -fcall-saved-rsi -fcall-saved-rdx -fcall-saved-rcx -fcall-saved-r8 -fcall-saved-r9 -fcall-saved-r10 -fcall-saved-r11" if X86_64
+
 config KTIME_SCALAR
        def_bool X86_32
 source "init/Kconfig"
@@ -447,7 +451,7 @@ config X86_NUMAQ
          firmware with - send email to <Martin.Bligh@us.ibm.com>.
 
 config X86_SUPPORTS_MEMORY_FAILURE
-       bool
+       def_bool y
        # MCE code calls memory_failure():
        depends on X86_MCE
        # On 32-bit this adds too big of NODES_SHIFT and we run out of page flags:
@@ -455,7 +459,6 @@ config X86_SUPPORTS_MEMORY_FAILURE
        # On 32-bit SPARSEMEM adds too big of SECTIONS_WIDTH:
        depends on X86_64 || !SPARSEMEM
        select ARCH_SUPPORTS_MEMORY_FAILURE
-       default y
 
 config X86_VISWS
        bool "SGI 320/540 (Visual Workstation)"
@@ -570,7 +573,6 @@ config PARAVIRT_SPINLOCKS
 
 config PARAVIRT_CLOCK
        bool
-       default n
 
 endif
 
@@ -749,7 +751,6 @@ config MAXSMP
        bool "Configure Maximum number of SMP Processors and NUMA Nodes"
        depends on X86_64 && SMP && DEBUG_KERNEL && EXPERIMENTAL
        select CPUMASK_OFFSTACK
-       default n
        ---help---
          Configure maximum number of CPUS and NUMA Nodes for this architecture.
          If unsure, say N.
@@ -829,7 +830,6 @@ config X86_VISWS_APIC
 
 config X86_REROUTE_FOR_BROKEN_BOOT_IRQS
        bool "Reroute for broken boot IRQs"
-       default n
        depends on X86_IO_APIC
        ---help---
          This option enables a workaround that fixes a source of
@@ -876,9 +876,8 @@ config X86_MCE_AMD
           the DRAM Error Threshold.
 
 config X86_ANCIENT_MCE
-       def_bool n
+       bool "Support for old Pentium 5 / WinChip machine checks"
        depends on X86_32 && X86_MCE
-       prompt "Support for old Pentium 5 / WinChip machine checks"
        ---help---
          Include support for machine check handling on old Pentium 5 or WinChip
          systems. These typically need to be enabled explicitely on the command
@@ -886,8 +885,7 @@ config X86_ANCIENT_MCE
 
 config X86_MCE_THRESHOLD
        depends on X86_MCE_AMD || X86_MCE_INTEL
-       bool
-       default y
+       def_bool y
 
 config X86_MCE_INJECT
        depends on X86_MCE
@@ -1026,8 +1024,8 @@ config X86_CPUID
 
 choice
        prompt "High Memory Support"
-       default HIGHMEM4G if !X86_NUMAQ
        default HIGHMEM64G if X86_NUMAQ
+       default HIGHMEM4G
        depends on X86_32
 
 config NOHIGHMEM
@@ -1285,7 +1283,7 @@ source "mm/Kconfig"
 
 config HIGHPTE
        bool "Allocate 3rd-level pagetables from highmem"
-       depends on X86_32 && (HIGHMEM4G || HIGHMEM64G)
+       depends on HIGHMEM
        ---help---
          The VM uses one page table entry for each page of physical memory.
          For systems with a lot of RAM, this can be wasteful of precious
@@ -1369,8 +1367,7 @@ config MATH_EMULATION
          kernel, it won't hurt.
 
 config MTRR
-       bool
-       default y
+       def_bool y
        prompt "MTRR (Memory Type Range Register) support" if EMBEDDED
        ---help---
          On Intel P6 family processors (Pentium Pro, Pentium II and later)
@@ -1436,8 +1433,7 @@ config MTRR_SANITIZER_SPARE_REG_NR_DEFAULT
          mtrr_spare_reg_nr=N on the kernel command line.
 
 config X86_PAT
-       bool
-       default y
+       def_bool y
        prompt "x86 PAT support" if EMBEDDED
        depends on MTRR
        ---help---
@@ -1605,8 +1601,7 @@ config X86_NEED_RELOCS
        depends on X86_32 && RELOCATABLE
 
 config PHYSICAL_ALIGN
-       hex
-       prompt "Alignment value to which kernel should be aligned" if X86_32
+       hex "Alignment value to which kernel should be aligned" if X86_32
        default "0x1000000"
        range 0x2000 0x1000000
        ---help---
@@ -1653,7 +1648,6 @@ config COMPAT_VDSO
 
 config CMDLINE_BOOL
        bool "Built-in kernel command line"
-       default n
        ---help---
          Allow for specifying boot arguments to the kernel at
          build time.  On some systems (e.g. embedded ones), it is
@@ -1687,7 +1681,6 @@ config CMDLINE
 
 config CMDLINE_OVERRIDE
        bool "Built-in command line overrides boot loader arguments"
-       default n
        depends on CMDLINE_BOOL
        ---help---
          Set this option to 'Y' to have the kernel ignore the boot loader
@@ -1723,8 +1716,7 @@ source "drivers/acpi/Kconfig"
 source "drivers/sfi/Kconfig"
 
 config X86_APM_BOOT
-       bool
-       default y
+       def_bool y
        depends on APM || APM_MODULE
 
 menuconfig APM
@@ -1953,8 +1945,7 @@ config DMAR_DEFAULT_ON
          experimental.
 
 config DMAR_BROKEN_GFX_WA
-       def_bool n
-       prompt "Workaround broken graphics drivers (going away soon)"
+       bool "Workaround broken graphics drivers (going away soon)"
        depends on DMAR && BROKEN
        ---help---
          Current Graphics drivers tend to use physical address
@@ -2052,7 +2043,6 @@ config SCx200HR_TIMER
 config OLPC
        bool "One Laptop Per Child support"
        select GPIOLIB
-       default n
        ---help---
          Add support for detecting the unique features of the OLPC
          XO hardware.
index a198293..2ac9069 100644 (file)
@@ -338,6 +338,10 @@ config X86_F00F_BUG
        def_bool y
        depends on M586MMX || M586TSC || M586 || M486 || M386
 
+config X86_INVD_BUG
+       def_bool y
+       depends on M486 || M386
+
 config X86_WP_WORKS_OK
        def_bool y
        depends on !M386
@@ -502,23 +506,3 @@ config CPU_SUP_UMC_32
          CPU might render the kernel unbootable.
 
          If unsure, say N.
-
-config X86_DS
-       def_bool X86_PTRACE_BTS
-       depends on X86_DEBUGCTLMSR
-       select HAVE_HW_BRANCH_TRACER
-
-config X86_PTRACE_BTS
-       bool "Branch Trace Store"
-       default y
-       depends on X86_DEBUGCTLMSR
-       depends on BROKEN
-       ---help---
-         This adds a ptrace interface to the hardware's branch trace store.
-
-         Debuggers may use it to collect an execution trace of the debugged
-         application in order to answer the question 'how did I get here?'.
-         Debuggers may trace user mode as well as kernel mode.
-
-         Say Y unless there is no application development on this machine
-         and you want to save a small amount of code size.
index bc01e3e..7508508 100644 (file)
@@ -45,7 +45,6 @@ config EARLY_PRINTK
 
 config EARLY_PRINTK_DBGP
        bool "Early printk via EHCI debug port"
-       default n
        depends on EARLY_PRINTK && PCI
        ---help---
          Write kernel log output directly into the EHCI debug port.
@@ -76,7 +75,6 @@ config DEBUG_PER_CPU_MAPS
        bool "Debug access to per_cpu maps"
        depends on DEBUG_KERNEL
        depends on SMP
-       default n
        ---help---
          Say Y to verify that the per_cpu map being accessed has
          been setup.  Adds a fair amount of code to kernel memory
@@ -174,15 +172,6 @@ config IOMMU_LEAK
          Add a simple leak tracer to the IOMMU code. This is useful when you
          are debugging a buggy device driver that leaks IOMMU mappings.
 
-config X86_DS_SELFTEST
-    bool "DS selftest"
-    default y
-    depends on DEBUG_KERNEL
-    depends on X86_DS
-       ---help---
-         Perform Debug Store selftests at boot time.
-         If in doubt, say "N".
-
 config HAVE_MMIOTRACE_SUPPORT
        def_bool y
 
index 0a43dc5..8aa1b59 100644 (file)
@@ -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)
 
index b97f786..a63a68b 100644 (file)
@@ -6,8 +6,8 @@
        .macro LOCK_PREFIX
 1:     lock
        .section .smp_locks,"a"
-       _ASM_ALIGN
-       _ASM_PTR 1b
+       .balign 4
+       .long 1b - .
        .previous
        .endm
 #else
index b09ec55..03b6bb5 100644 (file)
  */
 
 #ifdef CONFIG_SMP
-#define LOCK_PREFIX \
+#define LOCK_PREFIX_HERE \
                ".section .smp_locks,\"a\"\n"   \
-               _ASM_ALIGN "\n"                 \
-               _ASM_PTR "661f\n" /* address */ \
+               ".balign 4\n"                   \
+               ".long 671f - .\n" /* offset */ \
                ".previous\n"                   \
-               "661:\n\tlock; "
+               "671:"
+
+#define LOCK_PREFIX LOCK_PREFIX_HERE "\n\tlock; "
 
 #else /* ! CONFIG_SMP */
+#define LOCK_PREFIX_HERE ""
 #define LOCK_PREFIX ""
 #endif
 
-/* This must be included *after* the definition of LOCK_PREFIX */
-#include <asm/cpufeature.h>
-
 struct alt_instr {
        u8 *instr;              /* original instruction */
        u8 *replacement;
@@ -95,6 +95,12 @@ static inline int alternatives_text_reserved(void *start, void *end)
       "663:\n\t" newinstr "\n664:\n"           /* replacement     */   \
       ".previous"
 
+/*
+ * This must be included *after* the definition of ALTERNATIVE due to
+ * <asm/arch_hweight.h>
+ */
+#include <asm/cpufeature.h>
+
 /*
  * Alternative instructions for different CPU types or capabilities.
  *
index 86a0ff0..7014e88 100644 (file)
                                (~((1ULL << (12 + ((lvl) * 9))) - 1)))
 #define PM_ALIGNED(lvl, addr)  ((PM_MAP_MASK(lvl) & (addr)) == (addr))
 
+/*
+ * Returns the page table level to use for a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_LEVEL(pagesize) \
+               ((__ffs(pagesize) - 12) / 9)
+/*
+ * Returns the number of ptes to use for a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_PTE_COUNT(pagesize) \
+               (1ULL << ((__ffs(pagesize) - 12) % 9))
+
+/*
+ * Aligns a given io-virtual address to a given page size
+ * Pagesize is expected to be a power-of-two
+ */
+#define PAGE_SIZE_ALIGN(address, pagesize) \
+               ((address) & ~((pagesize) - 1))
+/*
+ * Creates an IOMMU PTE for an address an a given pagesize
+ * The PTE has no permission bits set
+ * Pagesize is expected to be a power-of-two larger than 4096
+ */
+#define PAGE_SIZE_PTE(address, pagesize)               \
+               (((address) | ((pagesize) - 1)) &       \
+                (~(pagesize >> 1)) & PM_ADDR_MASK)
+
+/*
+ * Takes a PTE value with mode=0x07 and returns the page size it maps
+ */
+#define PTE_PAGE_SIZE(pte) \
+       (1ULL << (1 + ffz(((pte) | 0xfffULL))))
+
 #define IOMMU_PTE_P  (1ULL << 0)
 #define IOMMU_PTE_TV (1ULL << 1)
 #define IOMMU_PTE_U  (1ULL << 59)
index b4ac2cd..1fa03e0 100644 (file)
@@ -373,6 +373,7 @@ extern atomic_t init_deasserted;
 extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip);
 #endif
 
+#ifdef CONFIG_X86_LOCAL_APIC
 static inline u32 apic_read(u32 reg)
 {
        return apic->read(reg);
@@ -403,10 +404,19 @@ static inline u32 safe_apic_wait_icr_idle(void)
        return apic->safe_wait_icr_idle();
 }
 
+#else /* CONFIG_X86_LOCAL_APIC */
+
+static inline u32 apic_read(u32 reg) { return 0; }
+static inline void apic_write(u32 reg, u32 val) { }
+static inline u64 apic_icr_read(void) { return 0; }
+static inline void apic_icr_write(u32 low, u32 high) { }
+static inline void apic_wait_icr_idle(void) { }
+static inline u32 safe_apic_wait_icr_idle(void) { return 0; }
+
+#endif /* CONFIG_X86_LOCAL_APIC */
 
 static inline void ack_APIC_irq(void)
 {
-#ifdef CONFIG_X86_LOCAL_APIC
        /*
         * ack_APIC_irq() actually gets compiled as a single instruction
         * ... yummie.
@@ -414,7 +424,6 @@ static inline void ack_APIC_irq(void)
 
        /* Docs say use 0 for future compatibility */
        apic_write(APIC_EOI, 0);
-#endif
 }
 
 static inline unsigned default_get_apic_id(unsigned long x)
diff --git a/arch/x86/include/asm/arch_hweight.h b/arch/x86/include/asm/arch_hweight.h
new file mode 100644 (file)
index 0000000..9686c3d
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef _ASM_X86_HWEIGHT_H
+#define _ASM_X86_HWEIGHT_H
+
+#ifdef CONFIG_64BIT
+/* popcnt %edi, %eax -- redundant REX prefix for alignment */
+#define POPCNT32 ".byte 0xf3,0x40,0x0f,0xb8,0xc7"
+/* popcnt %rdi, %rax */
+#define POPCNT64 ".byte 0xf3,0x48,0x0f,0xb8,0xc7"
+#define REG_IN "D"
+#define REG_OUT "a"
+#else
+/* popcnt %eax, %eax */
+#define POPCNT32 ".byte 0xf3,0x0f,0xb8,0xc0"
+#define REG_IN "a"
+#define REG_OUT "a"
+#endif
+
+/*
+ * __sw_hweightXX are called from within the alternatives below
+ * and callee-clobbered registers need to be taken care of. See
+ * ARCH_HWEIGHT_CFLAGS in <arch/x86/Kconfig> for the respective
+ * compiler switches.
+ */
+static inline unsigned int __arch_hweight32(unsigned int w)
+{
+       unsigned int res = 0;
+
+       asm (ALTERNATIVE("call __sw_hweight32", POPCNT32, X86_FEATURE_POPCNT)
+                    : "="REG_OUT (res)
+                    : REG_IN (w));
+
+       return res;
+}
+
+static inline unsigned int __arch_hweight16(unsigned int w)
+{
+       return __arch_hweight32(w & 0xffff);
+}
+
+static inline unsigned int __arch_hweight8(unsigned int w)
+{
+       return __arch_hweight32(w & 0xff);
+}
+
+static inline unsigned long __arch_hweight64(__u64 w)
+{
+       unsigned long res = 0;
+
+#ifdef CONFIG_X86_32
+       return  __arch_hweight32((u32)w) +
+               __arch_hweight32((u32)(w >> 32));
+#else
+       asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
+                    : "="REG_OUT (res)
+                    : REG_IN (w));
+#endif /* CONFIG_X86_32 */
+
+       return res;
+}
+
+#endif
index 8f8217b..952a826 100644 (file)
@@ -22,7 +22,7 @@
  */
 static inline int atomic_read(const atomic_t *v)
 {
-       return v->counter;
+       return (*(volatile int *)&(v)->counter);
 }
 
 /**
@@ -246,6 +246,29 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
 
 #define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
 
+/*
+ * atomic_dec_if_positive - decrement by 1 if old value positive
+ * @v: pointer of type atomic_t
+ *
+ * The function returns the old value of *v minus 1, even if
+ * the atomic variable, v, was not decremented.
+ */
+static inline int atomic_dec_if_positive(atomic_t *v)
+{
+       int c, old, dec;
+       c = atomic_read(v);
+       for (;;) {
+               dec = c - 1;
+               if (unlikely(dec < 0))
+                       break;
+               old = atomic_cmpxchg((v), c, dec);
+               if (likely(old == c))
+                       break;
+               c = old;
+       }
+       return dec;
+}
+
 /**
  * atomic_inc_short - increment of a short integer
  * @v: pointer to type int
index 03027bf..2a934aa 100644 (file)
@@ -14,109 +14,193 @@ typedef struct {
 
 #define ATOMIC64_INIT(val)     { (val) }
 
-extern u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val);
+#ifdef CONFIG_X86_CMPXCHG64
+#define ATOMIC64_ALTERNATIVE_(f, g) "call atomic64_" #g "_cx8"
+#else
+#define ATOMIC64_ALTERNATIVE_(f, g) ALTERNATIVE("call atomic64_" #f "_386", "call atomic64_" #g "_cx8", X86_FEATURE_CX8)
+#endif
+
+#define ATOMIC64_ALTERNATIVE(f) ATOMIC64_ALTERNATIVE_(f, f)
+
+/**
+ * atomic64_cmpxchg - cmpxchg atomic64 variable
+ * @p: pointer to type atomic64_t
+ * @o: expected value
+ * @n: new value
+ *
+ * Atomically sets @v to @n if it was equal to @o and returns
+ * the old value.
+ */
+
+static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n)
+{
+       return cmpxchg64(&v->counter, o, n);
+}
 
 /**
  * atomic64_xchg - xchg atomic64 variable
- * @ptr:      pointer to type atomic64_t
- * @new_val:  value to assign
+ * @v: pointer to type atomic64_t
+ * @n: value to assign
  *
- * Atomically xchgs the value of @ptr to @new_val and returns
+ * Atomically xchgs the value of @v to @n and returns
  * the old value.
  */
-extern u64 atomic64_xchg(atomic64_t *ptr, u64 new_val);
+static inline long long atomic64_xchg(atomic64_t *v, long long n)
+{
+       long long o;
+       unsigned high = (unsigned)(n >> 32);
+       unsigned low = (unsigned)n;
+       asm volatile(ATOMIC64_ALTERNATIVE(xchg)
+                    : "=A" (o), "+b" (low), "+c" (high)
+                    : "S" (v)
+                    : "memory"
+                    );
+       return o;
+}
 
 /**
  * atomic64_set - set atomic64 variable
- * @ptr:      pointer to type atomic64_t
- * @new_val:  value to assign
+ * @v: pointer to type atomic64_t
+ * @n: value to assign
  *
- * Atomically sets the value of @ptr to @new_val.
+ * Atomically sets the value of @v to @n.
  */
-extern void atomic64_set(atomic64_t *ptr, u64 new_val);
+static inline void atomic64_set(atomic64_t *v, long long i)
+{
+       unsigned high = (unsigned)(i >> 32);
+       unsigned low = (unsigned)i;
+       asm volatile(ATOMIC64_ALTERNATIVE(set)
+                    : "+b" (low), "+c" (high)
+                    : "S" (v)
+                    : "eax", "edx", "memory"
+                    );
+}
 
 /**
  * atomic64_read - read atomic64 variable
- * @ptr:      pointer to type atomic64_t
+ * @v: pointer to type atomic64_t
  *
- * Atomically reads the value of @ptr and returns it.
+ * Atomically reads the value of @v and returns it.
  */
-static inline u64 atomic64_read(atomic64_t *ptr)
+static inline long long atomic64_read(atomic64_t *v)
 {
-       u64 res;
-
-       /*
-        * Note, we inline this atomic64_t primitive because
-        * it only clobbers EAX/EDX and leaves the others
-        * untouched. We also (somewhat subtly) rely on the
-        * fact that cmpxchg8b returns the current 64-bit value
-        * of the memory location we are touching:
-        */
-       asm volatile(
-               "mov %%ebx, %%eax\n\t"
-               "mov %%ecx, %%edx\n\t"
-               LOCK_PREFIX "cmpxchg8b %1\n"
-                       : "=&A" (res)
-                       : "m" (*ptr)
-               );
-
-       return res;
-}
-
-extern u64 atomic64_read(atomic64_t *ptr);
+       long long r;
+       asm volatile(ATOMIC64_ALTERNATIVE(read)
+                    : "=A" (r), "+c" (v)
+                    : : "memory"
+                    );
+       return r;
+ }
 
 /**
  * atomic64_add_return - add and return
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
+ * @i: integer value to add
+ * @v: pointer to type atomic64_t
  *
- * Atomically adds @delta to @ptr and returns @delta + *@ptr
+ * Atomically adds @i to @v and returns @i + *@v
  */
-extern u64 atomic64_add_return(u64 delta, atomic64_t *ptr);
+static inline long long atomic64_add_return(long long i, atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE(add_return)
+                    : "+A" (i), "+c" (v)
+                    : : "memory"
+                    );
+       return i;
+}
 
 /*
  * Other variants with different arithmetic operators:
  */
-extern u64 atomic64_sub_return(u64 delta, atomic64_t *ptr);
-extern u64 atomic64_inc_return(atomic64_t *ptr);
-extern u64 atomic64_dec_return(atomic64_t *ptr);
+static inline long long atomic64_sub_return(long long i, atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE(sub_return)
+                    : "+A" (i), "+c" (v)
+                    : : "memory"
+                    );
+       return i;
+}
+
+static inline long long atomic64_inc_return(atomic64_t *v)
+{
+       long long a;
+       asm volatile(ATOMIC64_ALTERNATIVE(inc_return)
+                    : "=A" (a)
+                    : "S" (v)
+                    : "memory", "ecx"
+                    );
+       return a;
+}
+
+static inline long long atomic64_dec_return(atomic64_t *v)
+{
+       long long a;
+       asm volatile(ATOMIC64_ALTERNATIVE(dec_return)
+                    : "=A" (a)
+                    : "S" (v)
+                    : "memory", "ecx"
+                    );
+       return a;
+}
 
 /**
  * atomic64_add - add integer to atomic64 variable
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
+ * @i: integer value to add
+ * @v: pointer to type atomic64_t
  *
- * Atomically adds @delta to @ptr.
+ * Atomically adds @i to @v.
  */
-extern void atomic64_add(u64 delta, atomic64_t *ptr);
+static inline long long atomic64_add(long long i, atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE_(add, add_return)
+                    : "+A" (i), "+c" (v)
+                    : : "memory"
+                    );
+       return i;
+}
 
 /**
  * atomic64_sub - subtract the atomic64 variable
- * @delta: integer value to subtract
- * @ptr:   pointer to type atomic64_t
+ * @i: integer value to subtract
+ * @v: pointer to type atomic64_t
  *
- * Atomically subtracts @delta from @ptr.
+ * Atomically subtracts @i from @v.
  */
-extern void atomic64_sub(u64 delta, atomic64_t *ptr);
+static inline long long atomic64_sub(long long i, atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE_(sub, sub_return)
+                    : "+A" (i), "+c" (v)
+                    : : "memory"
+                    );
+       return i;
+}
 
 /**
  * atomic64_sub_and_test - subtract value from variable and test result
- * @delta: integer value to subtract
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically subtracts @delta from @ptr and returns
+ * @i: integer value to subtract
+ * @v: pointer to type atomic64_t
 *
+ * Atomically subtracts @i from @v and returns
  * true if the result is zero, or false for all
  * other cases.
  */
-extern int atomic64_sub_and_test(u64 delta, atomic64_t *ptr);
+static inline int atomic64_sub_and_test(long long i, atomic64_t *v)
+{
+       return atomic64_sub_return(i, v) == 0;
+}
 
 /**
  * atomic64_inc - increment atomic64 variable
- * @ptr: pointer to type atomic64_t
+ * @v: pointer to type atomic64_t
  *
- * Atomically increments @ptr by 1.
+ * Atomically increments @v by 1.
  */
-extern void atomic64_inc(atomic64_t *ptr);
+static inline void atomic64_inc(atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE_(inc, inc_return)
+                    : : "S" (v)
+                    : "memory", "eax", "ecx", "edx"
+                    );
+}
 
 /**
  * atomic64_dec - decrement atomic64 variable
@@ -124,37 +208,97 @@ extern void atomic64_inc(atomic64_t *ptr);
  *
  * Atomically decrements @ptr by 1.
  */
-extern void atomic64_dec(atomic64_t *ptr);
+static inline void atomic64_dec(atomic64_t *v)
+{
+       asm volatile(ATOMIC64_ALTERNATIVE_(dec, dec_return)
+                    : : "S" (v)
+                    : "memory", "eax", "ecx", "edx"
+                    );
+}
 
 /**
  * atomic64_dec_and_test - decrement and test
- * @ptr: pointer to type atomic64_t
+ * @v: pointer to type atomic64_t
  *
- * Atomically decrements @ptr by 1 and
+ * Atomically decrements @v by 1 and
  * returns true if the result is 0, or false for all other
  * cases.
  */
-extern int atomic64_dec_and_test(atomic64_t *ptr);
+static inline int atomic64_dec_and_test(atomic64_t *v)
+{
+       return atomic64_dec_return(v) == 0;
+}
 
 /**
  * atomic64_inc_and_test - increment and test
- * @ptr: pointer to type atomic64_t
+ * @v: pointer to type atomic64_t
  *
- * Atomically increments @ptr by 1
+ * Atomically increments @v by 1
  * and returns true if the result is zero, or false for all
  * other cases.
  */
-extern int atomic64_inc_and_test(atomic64_t *ptr);
+static inline int atomic64_inc_and_test(atomic64_t *v)
+{
+       return atomic64_inc_return(v) == 0;
+}
 
 /**
  * atomic64_add_negative - add and test if negative
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
+ * @i: integer value to add
+ * @v: pointer to type atomic64_t
  *
- * Atomically adds @delta to @ptr and returns true
+ * Atomically adds @i to @v and returns true
  * if the result is negative, or false when
  * result is greater than or equal to zero.
  */
-extern int atomic64_add_negative(u64 delta, atomic64_t *ptr);
+static inline int atomic64_add_negative(long long i, atomic64_t *v)
+{
+       return atomic64_add_return(i, v) < 0;
+}
+
+/**
+ * atomic64_add_unless - add unless the number is a given value
+ * @v: pointer of type atomic64_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
+ *
+ * Atomically adds @a to @v, so long as it was not @u.
+ * Returns non-zero if @v was not @u, and zero otherwise.
+ */
+static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
+{
+       unsigned low = (unsigned)u;
+       unsigned high = (unsigned)(u >> 32);
+       asm volatile(ATOMIC64_ALTERNATIVE(add_unless) "\n\t"
+                    : "+A" (a), "+c" (v), "+S" (low), "+D" (high)
+                    : : "memory");
+       return (int)a;
+}
+
+
+static inline int atomic64_inc_not_zero(atomic64_t *v)
+{
+       int r;
+       asm volatile(ATOMIC64_ALTERNATIVE(inc_not_zero)
+                    : "=a" (r)
+                    : "S" (v)
+                    : "ecx", "edx", "memory"
+                    );
+       return r;
+}
+
+static inline long long atomic64_dec_if_positive(atomic64_t *v)
+{
+       long long r;
+       asm volatile(ATOMIC64_ALTERNATIVE(dec_if_positive)
+                    : "=A" (r)
+                    : "S" (v)
+                    : "ecx", "memory"
+                    );
+       return r;
+}
+
+#undef ATOMIC64_ALTERNATIVE
+#undef ATOMIC64_ALTERNATIVE_
 
 #endif /* _ASM_X86_ATOMIC64_32_H */
index 51c5b40..49fd1ea 100644 (file)
@@ -18,7 +18,7 @@
  */
 static inline long atomic64_read(const atomic64_t *v)
 {
-       return v->counter;
+       return (*(volatile long *)&(v)->counter);
 }
 
 /**
@@ -221,4 +221,27 @@ static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
 
 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
 
+/*
+ * atomic64_dec_if_positive - decrement by 1 if old value positive
+ * @v: pointer of type atomic_t
+ *
+ * The function returns the old value of *v minus 1, even if
+ * the atomic variable, v, was not decremented.
+ */
+static inline long atomic64_dec_if_positive(atomic64_t *v)
+{
+       long c, old, dec;
+       c = atomic64_read(v);
+       for (;;) {
+               dec = c - 1;
+               if (unlikely(dec < 0))
+                       break;
+               old = atomic64_cmpxchg((v), c, dec);
+               if (likely(old == c))
+                       break;
+               c = old;
+       }
+       return dec;
+}
+
 #endif /* _ASM_X86_ATOMIC64_64_H */
index 02b47a6..545776e 100644 (file)
@@ -444,7 +444,9 @@ static inline int fls(int x)
 
 #define ARCH_HAS_FAST_MULTIPLIER 1
 
-#include <asm-generic/bitops/hweight.h>
+#include <asm/arch_hweight.h>
+
+#include <asm-generic/bitops/const_hweight.h>
 
 #endif /* __KERNEL__ */
 
index 7a10659..3b62ab5 100644 (file)
@@ -24,7 +24,7 @@
 #define MIN_KERNEL_ALIGN       (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2)
 
 #if (CONFIG_PHYSICAL_ALIGN & (CONFIG_PHYSICAL_ALIGN-1)) || \
-       (CONFIG_PHYSICAL_ALIGN < (_AC(1, UL) << MIN_KERNEL_ALIGN_LG2))
+       (CONFIG_PHYSICAL_ALIGN < MIN_KERNEL_ALIGN)
 #error "Invalid value for CONFIG_PHYSICAL_ALIGN"
 #endif
 
index 634c40a..c70068d 100644 (file)
@@ -44,9 +44,6 @@ static inline void copy_from_user_page(struct vm_area_struct *vma,
        memcpy(dst, src, len);
 }
 
-#define PG_WC                          PG_arch_1
-PAGEFLAG(WC, WC)
-
 #ifdef CONFIG_X86_PAT
 /*
  * X86 PAT uses page flags WC and Uncached together to keep track of
@@ -55,16 +52,24 @@ PAGEFLAG(WC, WC)
  * _PAGE_CACHE_UC_MINUS and fourth state where page's memory type has not
  * been changed from its default (value of -1 used to denote this).
  * Note we do not support _PAGE_CACHE_UC here.
- *
- * Caller must hold memtype_lock for atomicity.
  */
+
+#define _PGMT_DEFAULT          0
+#define _PGMT_WC               (1UL << PG_arch_1)
+#define _PGMT_UC_MINUS         (1UL << PG_uncached)
+#define _PGMT_WB               (1UL << PG_uncached | 1UL << PG_arch_1)
+#define _PGMT_MASK             (1UL << PG_uncached | 1UL << PG_arch_1)
+#define _PGMT_CLEAR_MASK       (~_PGMT_MASK)
+
 static inline unsigned long get_page_memtype(struct page *pg)
 {
-       if (!PageUncached(pg) && !PageWC(pg))
+       unsigned long pg_flags = pg->flags & _PGMT_MASK;
+
+       if (pg_flags == _PGMT_DEFAULT)
                return -1;
-       else if (!PageUncached(pg) && PageWC(pg))
+       else if (pg_flags == _PGMT_WC)
                return _PAGE_CACHE_WC;
-       else if (PageUncached(pg) && !PageWC(pg))
+       else if (pg_flags == _PGMT_UC_MINUS)
                return _PAGE_CACHE_UC_MINUS;
        else
                return _PAGE_CACHE_WB;
@@ -72,25 +77,26 @@ static inline unsigned long get_page_memtype(struct page *pg)
 
 static inline void set_page_memtype(struct page *pg, unsigned long memtype)
 {
+       unsigned long memtype_flags = _PGMT_DEFAULT;
+       unsigned long old_flags;
+       unsigned long new_flags;
+
        switch (memtype) {
        case _PAGE_CACHE_WC:
-               ClearPageUncached(pg);
-               SetPageWC(pg);
+               memtype_flags = _PGMT_WC;
                break;
        case _PAGE_CACHE_UC_MINUS:
-               SetPageUncached(pg);
-               ClearPageWC(pg);
+               memtype_flags = _PGMT_UC_MINUS;
                break;
        case _PAGE_CACHE_WB:
-               SetPageUncached(pg);
-               SetPageWC(pg);
-               break;
-       default:
-       case -1:
-               ClearPageUncached(pg);
-               ClearPageWC(pg);
+               memtype_flags = _PGMT_WB;
                break;
        }
+
+       do {
+               old_flags = pg->flags;
+               new_flags = (old_flags & _PGMT_CLEAR_MASK) | memtype_flags;
+       } while (cmpxchg(&pg->flags, old_flags, new_flags) != old_flags);
 }
 #else
 static inline unsigned long get_page_memtype(struct page *pg) { return -1; }
index ffb9bb6..8859e12 100644 (file)
@@ -271,7 +271,8 @@ extern unsigned long long cmpxchg_486_u64(volatile void *, u64, u64);
        __typeof__(*(ptr)) __ret;                               \
        __typeof__(*(ptr)) __old = (o);                         \
        __typeof__(*(ptr)) __new = (n);                         \
-       alternative_io("call cmpxchg8b_emu",                    \
+       alternative_io(LOCK_PREFIX_HERE                         \
+                       "call cmpxchg8b_emu",                   \
                        "lock; cmpxchg8b (%%esi)" ,             \
                       X86_FEATURE_CX8,                         \
                       "=A" (__ret),                            \
index 0cd82d0..dca9c54 100644 (file)
  */
 #define X86_FEATURE_IDA                (7*32+ 0) /* Intel Dynamic Acceleration */
 #define X86_FEATURE_ARAT       (7*32+ 1) /* Always Running APIC Timer */
+#define X86_FEATURE_CPB                (7*32+ 2) /* AMD Core Performance Boost */
 
 /* Virtualization flags: Linux defined */
 #define X86_FEATURE_TPR_SHADOW  (8*32+ 0) /* Intel TPR Shadow */
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 
+#include <asm/asm.h>
 #include <linux/bitops.h>
 
 extern const char * const x86_cap_flags[NCAPINTS*32];
@@ -283,6 +285,62 @@ extern const char * const x86_power_flags[32];
 
 #endif /* CONFIG_X86_64 */
 
+/*
+ * Static testing of CPU features.  Used the same as boot_cpu_has().
+ * These are only valid after alternatives have run, but will statically
+ * patch the target code for additional performance.
+ *
+ */
+static __always_inline __pure bool __static_cpu_has(u8 bit)
+{
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
+               asm goto("1: jmp %l[t_no]\n"
+                        "2:\n"
+                        ".section .altinstructions,\"a\"\n"
+                        _ASM_ALIGN "\n"
+                        _ASM_PTR "1b\n"
+                        _ASM_PTR "0\n"         /* no replacement */
+                        " .byte %P0\n"         /* feature bit */
+                        " .byte 2b - 1b\n"     /* source len */
+                        " .byte 0\n"           /* replacement len */
+                        " .byte 0xff + 0 - (2b-1b)\n"  /* padding */
+                        ".previous\n"
+                        : : "i" (bit) : : t_no);
+               return true;
+       t_no:
+               return false;
+#else
+               u8 flag;
+               /* Open-coded due to __stringify() in ALTERNATIVE() */
+               asm volatile("1: movb $0,%0\n"
+                            "2:\n"
+                            ".section .altinstructions,\"a\"\n"
+                            _ASM_ALIGN "\n"
+                            _ASM_PTR "1b\n"
+                            _ASM_PTR "3f\n"
+                            " .byte %P1\n"             /* feature bit */
+                            " .byte 2b - 1b\n"         /* source len */
+                            " .byte 4f - 3f\n"         /* replacement len */
+                            " .byte 0xff + (4f-3f) - (2b-1b)\n" /* padding */
+                            ".previous\n"
+                            ".section .altinstr_replacement,\"ax\"\n"
+                            "3: movb $1,%0\n"
+                            "4:\n"
+                            ".previous\n"
+                            : "=qm" (flag) : "i" (bit));
+               return flag;
+#endif
+}
+
+#define static_cpu_has(bit)                                    \
+(                                                              \
+       __builtin_constant_p(boot_cpu_has(bit)) ?               \
+               boot_cpu_has(bit) :                             \
+       (__builtin_constant_p(bit) && !((bit) & ~0xff)) ?       \
+               __static_cpu_has(bit) :                         \
+               boot_cpu_has(bit)                               \
+)
+
 #endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
 
 #endif /* _ASM_X86_CPUFEATURE_H */
diff --git a/arch/x86/include/asm/ds.h b/arch/x86/include/asm/ds.h
deleted file mode 100644 (file)
index 70dac19..0000000
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Debug Store (DS) support
- *
- * This provides a low-level interface to the hardware's Debug Store
- * feature that is used for branch trace store (BTS) and
- * precise-event based sampling (PEBS).
- *
- * It manages:
- * - DS and BTS hardware configuration
- * - buffer overflow handling (to be done)
- * - buffer access
- *
- * It does not do:
- * - security checking (is the caller allowed to trace the task)
- * - buffer allocation (memory accounting)
- *
- *
- * Copyright (C) 2007-2009 Intel Corporation.
- * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009
- */
-
-#ifndef _ASM_X86_DS_H
-#define _ASM_X86_DS_H
-
-
-#include <linux/types.h>
-#include <linux/init.h>
-#include <linux/err.h>
-
-
-#ifdef CONFIG_X86_DS
-
-struct task_struct;
-struct ds_context;
-struct ds_tracer;
-struct bts_tracer;
-struct pebs_tracer;
-
-typedef void (*bts_ovfl_callback_t)(struct bts_tracer *);
-typedef void (*pebs_ovfl_callback_t)(struct pebs_tracer *);
-
-
-/*
- * A list of features plus corresponding macros to talk about them in
- * the ds_request function's flags parameter.
- *
- * We use the enum to index an array of corresponding control bits;
- * we use the macro to index a flags bit-vector.
- */
-enum ds_feature {
-       dsf_bts = 0,
-       dsf_bts_kernel,
-#define BTS_KERNEL (1 << dsf_bts_kernel)
-       /* trace kernel-mode branches */
-
-       dsf_bts_user,
-#define BTS_USER (1 << dsf_bts_user)
-       /* trace user-mode branches */
-
-       dsf_bts_overflow,
-       dsf_bts_max,
-       dsf_pebs = dsf_bts_max,
-
-       dsf_pebs_max,
-       dsf_ctl_max = dsf_pebs_max,
-       dsf_bts_timestamps = dsf_ctl_max,
-#define BTS_TIMESTAMPS (1 << dsf_bts_timestamps)
-       /* add timestamps into BTS trace */
-
-#define BTS_USER_FLAGS (BTS_KERNEL | BTS_USER | BTS_TIMESTAMPS)
-};
-
-
-/*
- * Request BTS or PEBS
- *
- * Due to alignement constraints, the actual buffer may be slightly
- * smaller than the requested or provided buffer.
- *
- * Returns a pointer to a tracer structure on success, or
- * ERR_PTR(errcode) on failure.
- *
- * The interrupt threshold is independent from the overflow callback
- * to allow users to use their own overflow interrupt handling mechanism.
- *
- * The function might sleep.
- *
- * task: the task to request recording for
- * cpu:  the cpu to request recording for
- * base: the base pointer for the (non-pageable) buffer;
- * size: the size of the provided buffer in bytes
- * ovfl: pointer to a function to be called on buffer overflow;
- *       NULL if cyclic buffer requested
- * th: the interrupt threshold in records from the end of the buffer;
- *     -1 if no interrupt threshold is requested.
- * flags: a bit-mask of the above flags
- */
-extern struct bts_tracer *ds_request_bts_task(struct task_struct *task,
-                                             void *base, size_t size,
-                                             bts_ovfl_callback_t ovfl,
-                                             size_t th, unsigned int flags);
-extern struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size,
-                                            bts_ovfl_callback_t ovfl,
-                                            size_t th, unsigned int flags);
-extern struct pebs_tracer *ds_request_pebs_task(struct task_struct *task,
-                                               void *base, size_t size,
-                                               pebs_ovfl_callback_t ovfl,
-                                               size_t th, unsigned int flags);
-extern struct pebs_tracer *ds_request_pebs_cpu(int cpu,
-                                              void *base, size_t size,
-                                              pebs_ovfl_callback_t ovfl,
-                                              size_t th, unsigned int flags);
-
-/*
- * Release BTS or PEBS resources
- * Suspend and resume BTS or PEBS tracing
- *
- * Must be called with irq's enabled.
- *
- * tracer: the tracer handle returned from ds_request_~()
- */
-extern void ds_release_bts(struct bts_tracer *tracer);
-extern void ds_suspend_bts(struct bts_tracer *tracer);
-extern void ds_resume_bts(struct bts_tracer *tracer);
-extern void ds_release_pebs(struct pebs_tracer *tracer);
-extern void ds_suspend_pebs(struct pebs_tracer *tracer);
-extern void ds_resume_pebs(struct pebs_tracer *tracer);
-
-/*
- * Release BTS or PEBS resources
- * Suspend and resume BTS or PEBS tracing
- *
- * Cpu tracers must call this on the traced cpu.
- * Task tracers must call ds_release_~_noirq() for themselves.
- *
- * May be called with irq's disabled.
- *
- * Returns 0 if successful;
- * -EPERM if the cpu tracer does not trace the current cpu.
- * -EPERM if the task tracer does not trace itself.
- *
- * tracer: the tracer handle returned from ds_request_~()
- */
-extern int ds_release_bts_noirq(struct bts_tracer *tracer);
-extern int ds_suspend_bts_noirq(struct bts_tracer *tracer);
-extern int ds_resume_bts_noirq(struct bts_tracer *tracer);
-extern int ds_release_pebs_noirq(struct pebs_tracer *tracer);
-extern int ds_suspend_pebs_noirq(struct pebs_tracer *tracer);
-extern int ds_resume_pebs_noirq(struct pebs_tracer *tracer);
-
-
-/*
- * The raw DS buffer state as it is used for BTS and PEBS recording.
- *
- * This is the low-level, arch-dependent interface for working
- * directly on the raw trace data.
- */
-struct ds_trace {
-       /* the number of bts/pebs records */
-       size_t n;
-       /* the size of a bts/pebs record in bytes */
-       size_t size;
-       /* pointers into the raw buffer:
-          - to the first entry */
-       void *begin;
-       /* - one beyond the last entry */
-       void *end;
-       /* - one beyond the newest entry */
-       void *top;
-       /* - the interrupt threshold */
-       void *ith;
-       /* flags given on ds_request() */
-       unsigned int flags;
-};
-
-/*
- * An arch-independent view on branch trace data.
- */
-enum bts_qualifier {
-       bts_invalid,
-#define BTS_INVALID bts_invalid
-
-       bts_branch,
-#define BTS_BRANCH bts_branch
-
-       bts_task_arrives,
-#define BTS_TASK_ARRIVES bts_task_arrives
-
-       bts_task_departs,
-#define BTS_TASK_DEPARTS bts_task_departs
-
-       bts_qual_bit_size = 4,
-       bts_qual_max = (1 << bts_qual_bit_size),
-};
-
-struct bts_struct {
-       __u64 qualifier;
-       union {
-               /* BTS_BRANCH */
-               struct {
-                       __u64 from;
-                       __u64 to;
-               } lbr;
-               /* BTS_TASK_ARRIVES or BTS_TASK_DEPARTS */
-               struct {
-                       __u64 clock;
-                       pid_t pid;
-               } event;
-       } variant;
-};
-
-
-/*
- * The BTS state.
- *
- * This gives access to the raw DS state and adds functions to provide
- * an arch-independent view of the BTS data.
- */
-struct bts_trace {
-       struct ds_trace ds;
-
-       int (*read)(struct bts_tracer *tracer, const void *at,
-                   struct bts_struct *out);
-       int (*write)(struct bts_tracer *tracer, const struct bts_struct *in);
-};
-
-
-/*
- * The PEBS state.
- *
- * This gives access to the raw DS state and the PEBS-specific counter
- * reset value.
- */
-struct pebs_trace {
-       struct ds_trace ds;
-
-       /* the number of valid counters in the below array */
-       unsigned int counters;
-
-#define MAX_PEBS_COUNTERS 4
-       /* the counter reset value */
-       unsigned long long counter_reset[MAX_PEBS_COUNTERS];
-};
-
-
-/*
- * Read the BTS or PEBS trace.
- *
- * Returns a view on the trace collected for the parameter tracer.
- *
- * The view remains valid as long as the traced task is not running or
- * the tracer is suspended.
- * Writes into the trace buffer are not reflected.
- *
- * tracer: the tracer handle returned from ds_request_~()
- */
-extern const struct bts_trace *ds_read_bts(struct bts_tracer *tracer);
-extern const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer);
-
-
-/*
- * Reset the write pointer of the BTS/PEBS buffer.
- *
- * Returns 0 on success; -Eerrno on error
- *
- * tracer: the tracer handle returned from ds_request_~()
- */
-extern int ds_reset_bts(struct bts_tracer *tracer);
-extern int ds_reset_pebs(struct pebs_tracer *tracer);
-
-/*
- * Set the PEBS counter reset value.
- *
- * Returns 0 on success; -Eerrno on error
- *
- * tracer: the tracer handle returned from ds_request_pebs()
- * counter: the index of the counter
- * value: the new counter reset value
- */
-extern int ds_set_pebs_reset(struct pebs_tracer *tracer,
-                            unsigned int counter, u64 value);
-
-/*
- * Initialization
- */
-struct cpuinfo_x86;
-extern void __cpuinit ds_init_intel(struct cpuinfo_x86 *);
-
-/*
- * Context switch work
- */
-extern void ds_switch_to(struct task_struct *prev, struct task_struct *next);
-
-#else /* CONFIG_X86_DS */
-
-struct cpuinfo_x86;
-static inline void __cpuinit ds_init_intel(struct cpuinfo_x86 *ignored) {}
-static inline void ds_switch_to(struct task_struct *prev,
-                               struct task_struct *next) {}
-
-#endif /* CONFIG_X86_DS */
-#endif /* _ASM_X86_DS_H */
index ae6253a..733f7e9 100644 (file)
 #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
 
 /*
index 0e22296..ec8a52d 100644 (file)
 #define E820_NVS       4
 #define E820_UNUSABLE  5
 
-/* reserved RAM used by kernel itself */
+/*
+ * reserved RAM used by kernel itself
+ * if CONFIG_INTEL_TXT is enabled, memory of this type will be
+ * included in the S3 integrity calculation and so should not include
+ * any memory that BIOS might alter over the S3 transition
+ */
 #define E820_RESERVED_KERN        128
 
 #ifndef __ASSEMBLY__
index 0f85764..aeab29a 100644 (file)
@@ -35,7 +35,7 @@ DECLARE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
 
 #define __ARCH_IRQ_STAT
 
-#define inc_irq_stat(member)   percpu_add(irq_stat.member, 1)
+#define inc_irq_stat(member)   percpu_inc(irq_stat.member)
 
 #define local_softirq_pending()        percpu_read(irq_stat.__softirq_pending)
 
index 1d5c08a..004e6e2 100644 (file)
@@ -68,6 +68,7 @@ extern unsigned long force_hpet_address;
 extern u8 hpet_blockid;
 extern int hpet_force_user;
 extern u8 hpet_msi_disable;
+extern u8 hpet_readback_cmp;
 extern int is_hpet_enabled(void);
 extern int hpet_enable(void);
 extern void hpet_disable(void);
index 2a1bd8f..9422553 100644 (file)
@@ -41,12 +41,16 @@ struct arch_hw_breakpoint {
 /* Total number of available HW breakpoint registers */
 #define HBP_NUM 4
 
+static inline int hw_breakpoint_slots(int type)
+{
+       return HBP_NUM;
+}
+
 struct perf_event;
 struct pmu;
 
-extern int arch_check_va_in_userspace(unsigned long va, u8 hbp_len);
-extern int arch_validate_hwbkpt_settings(struct perf_event *bp,
-                                        struct task_struct *tsk);
+extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
+extern int arch_validate_hwbkpt_settings(struct perf_event *bp);
 extern int hw_breakpoint_exceptions_notify(struct notifier_block *unused,
                                           unsigned long val, void *data);
 
index e153a2b..5df477a 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef _ASM_X86_KVM_HYPERV_H
-#define _ASM_X86_KVM_HYPERV_H
+#ifndef _ASM_X86_HYPERV_H
+#define _ASM_X86_HYPERV_H
 
 #include <linux/types.h>
 
 #define HYPERV_CPUID_ENLIGHTMENT_INFO          0x40000004
 #define HYPERV_CPUID_IMPLEMENT_LIMITS          0x40000005
 
+#define HYPERV_HYPERVISOR_PRESENT_BIT          0x80000000
+#define HYPERV_CPUID_MIN                       0x40000005
+#define HYPERV_CPUID_MAX                       0x4000ffff
+
 /*
  * Feature identification. EAX indicates which features are available
  * to the partition based upon the current partition privileges.
 /* MSR used to provide vcpu index */
 #define HV_X64_MSR_VP_INDEX                    0x40000002
 
+/* MSR used to read the per-partition time reference counter */
+#define HV_X64_MSR_TIME_REF_COUNT              0x40000020
+
 /* Define the virtual APIC registers */
 #define HV_X64_MSR_EOI                         0x40000070
 #define HV_X64_MSR_ICR                         0x40000071
index b78c094..70abda7 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  */
-#ifndef ASM_X86__HYPERVISOR_H
-#define ASM_X86__HYPERVISOR_H
+#ifndef _ASM_X86_HYPERVISOR_H
+#define _ASM_X86_HYPERVISOR_H
 
 extern void init_hypervisor(struct cpuinfo_x86 *c);
 extern void init_hypervisor_platform(void);
 
+/*
+ * x86 hypervisor information
+ */
+struct hypervisor_x86 {
+       /* Hypervisor name */
+       const char      *name;
+
+       /* Detection routine */
+       bool            (*detect)(void);
+
+       /* Adjust CPU feature bits (run once per CPU) */
+       void            (*set_cpu_features)(struct cpuinfo_x86 *);
+
+       /* Platform setup (run once per boot) */
+       void            (*init_platform)(void);
+};
+
+extern const struct hypervisor_x86 *x86_hyper;
+
+/* Recognized hypervisors */
+extern const struct hypervisor_x86 x86_hyper_vmware;
+extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
+
 #endif
index da29309..c991b3a 100644 (file)
@@ -16,7 +16,9 @@
 #include <linux/kernel_stat.h>
 #include <linux/regset.h>
 #include <linux/hardirq.h>
+#include <linux/slab.h>
 #include <asm/asm.h>
+#include <asm/cpufeature.h>
 #include <asm/processor.h>
 #include <asm/sigcontext.h>
 #include <asm/user.h>
@@ -56,6 +58,11 @@ extern int restore_i387_xstate_ia32(void __user *buf);
 
 #define X87_FSW_ES (1 << 7)    /* Exception Summary */
 
+static __always_inline __pure bool use_xsave(void)
+{
+       return static_cpu_has(X86_FEATURE_XSAVE);
+}
+
 #ifdef CONFIG_X86_64
 
 /* Ignore delayed exceptions from user space */
@@ -91,15 +98,15 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
    values. The kernel data segment can be sometimes 0 and sometimes
    new user value. Both should be ok.
    Use the PDA as safe address because it should be already in L1. */
-static inline void clear_fpu_state(struct task_struct *tsk)
+static inline void fpu_clear(struct fpu *fpu)
 {
-       struct xsave_struct *xstate = &tsk->thread.xstate->xsave;
-       struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave;
+       struct xsave_struct *xstate = &fpu->state->xsave;
+       struct i387_fxsave_struct *fx = &fpu->state->fxsave;
 
        /*
         * xsave header may indicate the init state of the FP.
         */
-       if ((task_thread_info(tsk)->status & TS_XSAVE) &&
+       if (use_xsave() &&
            !(xstate->xsave_hdr.xstate_bv & XSTATE_FP))
                return;
 
@@ -111,6 +118,11 @@ static inline void clear_fpu_state(struct task_struct *tsk)
                          X86_FEATURE_FXSAVE_LEAK);
 }
 
+static inline void clear_fpu_state(struct task_struct *tsk)
+{
+       fpu_clear(&tsk->thread.fpu);
+}
+
 static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
 {
        int err;
@@ -135,7 +147,7 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
        return err;
 }
 
-static inline void fxsave(struct task_struct *tsk)
+static inline void fpu_fxsave(struct fpu *fpu)
 {
        /* Using "rex64; fxsave %0" is broken because, if the memory operand
           uses any extended registers for addressing, a second REX prefix
@@ -145,42 +157,45 @@ static inline void fxsave(struct task_struct *tsk)
        /* Using "fxsaveq %0" would be the ideal choice, but is only supported
           starting with gas 2.16. */
        __asm__ __volatile__("fxsaveq %0"
-                            : "=m" (tsk->thread.xstate->fxsave));
+                            : "=m" (fpu->state->fxsave));
 #elif 0
        /* Using, as a workaround, the properly prefixed form below isn't
           accepted by any binutils version so far released, complaining that
           the same type of prefix is used twice if an extended register is
           needed for addressing (fix submitted to mainline 2005-11-21). */
        __asm__ __volatile__("rex64/fxsave %0"
-                            : "=m" (tsk->thread.xstate->fxsave));
+                            : "=m" (fpu->state->fxsave));
 #else
        /* This, however, we can work around by forcing the compiler to select
           an addressing mode that doesn't require extended registers. */
        __asm__ __volatile__("rex64/fxsave (%1)"
-                            : "=m" (tsk->thread.xstate->fxsave)
-                            : "cdaSDb" (&tsk->thread.xstate->fxsave));
+                            : "=m" (fpu->state->fxsave)
+                            : "cdaSDb" (&fpu->state->fxsave));
 #endif
 }
 
-static inline void __save_init_fpu(struct task_struct *tsk)
+static inline void fpu_save_init(struct fpu *fpu)
 {
-       if (task_thread_info(tsk)->status & TS_XSAVE)
-               xsave(tsk);
+       if (use_xsave())
+               fpu_xsave(fpu);
        else
-               fxsave(tsk);
+               fpu_fxsave(fpu);
+
+       fpu_clear(fpu);
+}
 
-       clear_fpu_state(tsk);
+static inline void __save_init_fpu(struct task_struct *tsk)
+{
+       fpu_save_init(&tsk->thread.fpu);
        task_thread_info(tsk)->status &= ~TS_USEDFPU;
 }
 
 #else  /* CONFIG_X86_32 */
 
 #ifdef CONFIG_MATH_EMULATION
-extern void finit_task(struct task_struct *tsk);
+extern void finit_soft_fpu(struct i387_soft_struct *soft);
 #else
-static inline void finit_task(struct task_struct *tsk)
-{
-}
+static inline void finit_soft_fpu(struct i387_soft_struct *soft) {}
 #endif
 
 static inline void tolerant_fwait(void)
@@ -216,13 +231,13 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
 /*
  * These must be called with preempt disabled
  */
-static inline void __save_init_fpu(struct task_struct *tsk)
+static inline void fpu_save_init(struct fpu *fpu)
 {
-       if (task_thread_info(tsk)->status & TS_XSAVE) {
-               struct xsave_struct *xstate = &tsk->thread.xstate->xsave;
-               struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave;
+       if (use_xsave()) {
+               struct xsave_struct *xstate = &fpu->state->xsave;
+               struct i387_fxsave_struct *fx = &fpu->state->fxsave;
 
-               xsave(tsk);
+               fpu_xsave(fpu);
 
                /*
                 * xsave header may indicate the init state of the FP.
@@ -246,8 +261,8 @@ static inline void __save_init_fpu(struct task_struct *tsk)
                "fxsave %[fx]\n"
                "bt $7,%[fsw] ; jnc 1f ; fnclex\n1:",
                X86_FEATURE_FXSR,
-               [fx] "m" (tsk->thread.xstate->fxsave),
-               [fsw] "m" (tsk->thread.xstate->fxsave.swd) : "memory");
+               [fx] "m" (fpu->state->fxsave),
+               [fsw] "m" (fpu->state->fxsave.swd) : "memory");
 clear_state:
        /* AMD K7/K8 CPUs don't save/restore FDP/FIP/FOP unless an exception
           is pending.  Clear the x87 state here by setting it to fixed
@@ -259,17 +274,34 @@ clear_state:
                X86_FEATURE_FXSAVE_LEAK,
                [addr] "m" (safe_address));
 end:
+       ;
+}
+
+static inline void __save_init_fpu(struct task_struct *tsk)
+{
+       fpu_save_init(&tsk->thread.fpu);
        task_thread_info(tsk)->status &= ~TS_USEDFPU;
 }
 
+
 #endif /* CONFIG_X86_64 */
 
-static inline int restore_fpu_checking(struct task_struct *tsk)
+static inline int fpu_fxrstor_checking(struct fpu *fpu)
 {
-       if (task_thread_info(tsk)->status & TS_XSAVE)
-               return xrstor_checking(&tsk->thread.xstate->xsave);
+       return fxrstor_checking(&fpu->state->fxsave);
+}
+
+static inline int fpu_restore_checking(struct fpu *fpu)
+{
+       if (use_xsave())
+               return fpu_xrstor_checking(fpu);
        else
-               return fxrstor_checking(&tsk->thread.xstate->fxsave);
+               return fpu_fxrstor_checking(fpu);
+}
+
+static inline int restore_fpu_checking(struct task_struct *tsk)
+{
+       return fpu_restore_checking(&tsk->thread.fpu);
 }
 
 /*
@@ -397,30 +429,59 @@ static inline void clear_fpu(struct task_struct *tsk)
 static inline unsigned short get_fpu_cwd(struct task_struct *tsk)
 {
        if (cpu_has_fxsr) {
-               return tsk->thread.xstate->fxsave.cwd;
+               return tsk->thread.fpu.state->fxsave.cwd;
        } else {
-               return (unsigned short)tsk->thread.xstate->fsave.cwd;
+               return (unsigned short)tsk->thread.fpu.state->fsave.cwd;
        }
 }
 
 static inline unsigned short get_fpu_swd(struct task_struct *tsk)
 {
        if (cpu_has_fxsr) {
-               return tsk->thread.xstate->fxsave.swd;
+               return tsk->thread.fpu.state->fxsave.swd;
        } else {
-               return (unsigned short)tsk->thread.xstate->fsave.swd;
+               return (unsigned short)tsk->thread.fpu.state->fsave.swd;
        }
 }
 
 static inline unsigned short get_fpu_mxcsr(struct task_struct *tsk)
 {
        if (cpu_has_xmm) {
-               return tsk->thread.xstate->fxsave.mxcsr;
+               return tsk->thread.fpu.state->fxsave.mxcsr;
        } else {
                return MXCSR_DEFAULT;
        }
 }
 
+static bool fpu_allocated(struct fpu *fpu)
+{
+       return fpu->state != NULL;
+}
+
+static inline int fpu_alloc(struct fpu *fpu)
+{
+       if (fpu_allocated(fpu))
+               return 0;
+       fpu->state = kmem_cache_alloc(task_xstate_cachep, GFP_KERNEL);
+       if (!fpu->state)
+               return -ENOMEM;
+       WARN_ON((unsigned long)fpu->state & 15);
+       return 0;
+}
+
+static inline void fpu_free(struct fpu *fpu)
+{
+       if (fpu->state) {
+               kmem_cache_free(task_xstate_cachep, fpu->state);
+               fpu->state = NULL;
+       }
+}
+
+static inline void fpu_copy(struct fpu *dst, struct fpu *src)
+{
+       memcpy(dst->state, src->state, xstate_size);
+}
+
 #endif /* __ASSEMBLY__ */
 
 #define PSHUFB_XMM5_XMM0 .byte 0x66, 0x0f, 0x38, 0x00, 0xc5
index 1edbf89..fc1f579 100644 (file)
@@ -6,7 +6,7 @@
 #define PIT_CH0                        0x40
 #define PIT_CH2                        0x42
 
-extern spinlock_t i8253_lock;
+extern raw_spinlock_t i8253_lock;
 
 extern struct clock_event_device *global_clock_event;
 
index 96c2e0a..88c765e 100644 (file)
@@ -68,6 +68,8 @@ struct insn {
        const insn_byte_t *next_byte;
 };
 
+#define MAX_INSN_SIZE  16
+
 #define X86_MODRM_MOD(modrm) (((modrm) & 0xc0) >> 6)
 #define X86_MODRM_REG(modrm) (((modrm) & 0x38) >> 3)
 #define X86_MODRM_RM(modrm) ((modrm) & 0x07)
index 35832a0..63cb409 100644 (file)
@@ -159,7 +159,6 @@ struct io_apic_irq_attr;
 extern int io_apic_set_pci_routing(struct device *dev, int irq,
                 struct io_apic_irq_attr *irq_attr);
 void setup_IO_APIC_irq_extra(u32 gsi);
-extern int (*ioapic_renumber_irq)(int ioapic, int irq);
 extern void ioapic_init_mappings(void);
 extern void ioapic_insert_resources(void);
 
@@ -180,12 +179,13 @@ extern void ioapic_write_entry(int apic, int pin,
 extern void setup_ioapic_ids_from_mpc(void);
 
 struct mp_ioapic_gsi{
-       int gsi_base;
-       int gsi_end;
+       u32 gsi_base;
+       u32 gsi_end;
 };
 extern struct mp_ioapic_gsi  mp_gsi_routing[];
-int mp_find_ioapic(int gsi);
-int mp_find_ioapic_pin(int ioapic, int gsi);
+extern u32 gsi_end;
+int mp_find_ioapic(u32 gsi);
+int mp_find_ioapic_pin(int ioapic, u32 gsi);
 void __init mp_register_ioapic(int id, u32 address, u32 gsi_base);
 extern void __init pre_init_apic_IRQ0(void);
 
@@ -197,7 +197,8 @@ static const int timer_through_8259 = 0;
 static inline void ioapic_init_mappings(void)  { }
 static inline void ioapic_insert_resources(void) { }
 static inline void probe_nr_irqs_gsi(void)     { }
-static inline int mp_find_ioapic(int gsi) { return 0; }
+#define gsi_end (NR_IRQS_LEGACY - 1)
+static inline int mp_find_ioapic(u32 gsi) { return 0; }
 
 struct io_apic_irq_attr;
 static inline int io_apic_set_pci_routing(struct device *dev, int irq,
index 4ffa345..5478825 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
+#include <asm/insn.h>
 
 #define  __ARCH_WANT_KPROBES_INSN_SLOT
 
@@ -36,7 +37,6 @@ typedef u8 kprobe_opcode_t;
 #define RELATIVEJUMP_SIZE 5
 #define RELATIVECALL_OPCODE 0xe8
 #define RELATIVE_ADDR_SIZE 4
-#define MAX_INSN_SIZE 16
 #define MAX_STACK_SIZE 64
 #define MIN_STACK_SIZE(ADDR)                                          \
        (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
index d8bf23a..c82868e 100644 (file)
@@ -105,16 +105,6 @@ extern void mp_config_acpi_legacy_irqs(void);
 struct device;
 extern int mp_register_gsi(struct device *dev, u32 gsi, int edge_level,
                                 int active_high_low);
-extern int acpi_probe_gsi(void);
-#ifdef CONFIG_X86_IO_APIC
-extern int mp_find_ioapic(int gsi);
-extern int mp_find_ioapic_pin(int ioapic, int gsi);
-#endif
-#else /* !CONFIG_ACPI: */
-static inline int acpi_probe_gsi(void)
-{
-       return 0;
-}
 #endif /* CONFIG_ACPI */
 
 #define PHYSID_ARRAY_SIZE      BITS_TO_LONGS(MAX_APICS)
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
new file mode 100644 (file)
index 0000000..79ce568
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _ASM_X86_MSHYPER_H
+#define _ASM_X86_MSHYPER_H
+
+#include <linux/types.h>
+#include <asm/hyperv.h>
+
+struct ms_hyperv_info {
+       u32 features;
+       u32 hints;
+};
+
+extern struct ms_hyperv_info ms_hyperv;
+
+#endif
index 4604e6a..bc473ac 100644 (file)
 #define MSR_IA32_LASTINTTOIP           0x000001de
 
 /* DEBUGCTLMSR bits (others vary by model): */
-#define _DEBUGCTLMSR_LBR       0 /* last branch recording */
-#define _DEBUGCTLMSR_BTF       1 /* single-step on branches */
-
-#define DEBUGCTLMSR_LBR                (1UL << _DEBUGCTLMSR_LBR)
-#define DEBUGCTLMSR_BTF                (1UL << _DEBUGCTLMSR_BTF)
+#define DEBUGCTLMSR_LBR                        (1UL <<  0) /* last branch recording */
+#define DEBUGCTLMSR_BTF                        (1UL <<  1) /* single-step on branches */
+#define DEBUGCTLMSR_TR                 (1UL <<  6)
+#define DEBUGCTLMSR_BTS                        (1UL <<  7)
+#define DEBUGCTLMSR_BTINT              (1UL <<  8)
+#define DEBUGCTLMSR_BTS_OFF_OS         (1UL <<  9)
+#define DEBUGCTLMSR_BTS_OFF_USR                (1UL << 10)
+#define DEBUGCTLMSR_FREEZE_LBRS_ON_PMI (1UL << 11)
 
 #define MSR_IA32_MC0_CTL               0x00000400
 #define MSR_IA32_MC0_STATUS            0x00000401
 #define MSR_P4_U2L_ESCR0               0x000003b0
 #define MSR_P4_U2L_ESCR1               0x000003b1
 
+#define MSR_P4_PEBS_MATRIX_VERT                0x000003f2
+
 /* Intel Core-based CPU performance counters */
 #define MSR_CORE_PERF_FIXED_CTR0       0x00000309
 #define MSR_CORE_PERF_FIXED_CTR1       0x0000030a
index 66a272d..0797e74 100644 (file)
@@ -105,7 +105,7 @@ do {                                                        \
 
 /*
  * Generate a percpu add to memory instruction and optimize code
- * if one is added or subtracted.
+ * if one is added or subtracted.
  */
 #define percpu_add_op(var, val)                                                \
 do {                                                                   \
@@ -190,6 +190,29 @@ do {                                                                       \
        pfo_ret__;                                      \
 })
 
+#define percpu_unary_op(op, var)                       \
+({                                                     \
+       switch (sizeof(var)) {                          \
+       case 1:                                         \
+               asm(op "b "__percpu_arg(0)              \
+                   : "+m" (var));                      \
+               break;                                  \
+       case 2:                                         \
+               asm(op "w "__percpu_arg(0)              \
+                   : "+m" (var));                      \
+               break;                                  \
+       case 4:                                         \
+               asm(op "l "__percpu_arg(0)              \
+                   : "+m" (var));                      \
+               break;                                  \
+       case 8:                                         \
+               asm(op "q "__percpu_arg(0)              \
+                   : "+m" (var));                      \
+               break;                                  \
+       default: __bad_percpu_size();                   \
+       }                                               \
+})
+
 /*
  * percpu_read() makes gcc load the percpu variable every time it is
  * accessed while percpu_read_stable() allows the value to be cached.
@@ -207,6 +230,7 @@ do {                                                                        \
 #define percpu_and(var, val)           percpu_to_op("and", var, val)
 #define percpu_or(var, val)            percpu_to_op("or", var, val)
 #define percpu_xor(var, val)           percpu_to_op("xor", var, val)
+#define percpu_inc(var)                percpu_unary_op("inc", var)
 
 #define __this_cpu_read_1(pcp)         percpu_from_op("mov", (pcp), "m"(pcp))
 #define __this_cpu_read_2(pcp)         percpu_from_op("mov", (pcp), "m"(pcp))
index db6109a..254883d 100644 (file)
@@ -5,7 +5,7 @@
  * Performance event hw details:
  */
 
-#define X86_PMC_MAX_GENERIC                                    8
+#define X86_PMC_MAX_GENERIC                                   32
 #define X86_PMC_MAX_FIXED                                      3
 
 #define X86_PMC_IDX_GENERIC                                    0
 #define MSR_ARCH_PERFMON_EVENTSEL0                          0x186
 #define MSR_ARCH_PERFMON_EVENTSEL1                          0x187
 
-#define ARCH_PERFMON_EVENTSEL_ENABLE                     (1 << 22)
-#define ARCH_PERFMON_EVENTSEL_ANY                        (1 << 21)
-#define ARCH_PERFMON_EVENTSEL_INT                        (1 << 20)
-#define ARCH_PERFMON_EVENTSEL_OS                         (1 << 17)
-#define ARCH_PERFMON_EVENTSEL_USR                        (1 << 16)
-
-/*
- * Includes eventsel and unit mask as well:
- */
-
-
-#define INTEL_ARCH_EVTSEL_MASK         0x000000FFULL
-#define INTEL_ARCH_UNIT_MASK           0x0000FF00ULL
-#define INTEL_ARCH_EDGE_MASK           0x00040000ULL
-#define INTEL_ARCH_INV_MASK            0x00800000ULL
-#define INTEL_ARCH_CNT_MASK            0xFF000000ULL
-#define INTEL_ARCH_EVENT_MASK  (INTEL_ARCH_UNIT_MASK|INTEL_ARCH_EVTSEL_MASK)
-
-/*
- * filter mask to validate fixed counter events.
- * the following filters disqualify for fixed counters:
- *  - inv
- *  - edge
- *  - cnt-mask
- *  The other filters are supported by fixed counters.
- *  The any-thread option is supported starting with v3.
- */
-#define INTEL_ARCH_FIXED_MASK \
-       (INTEL_ARCH_CNT_MASK| \
-        INTEL_ARCH_INV_MASK| \
-        INTEL_ARCH_EDGE_MASK|\
-        INTEL_ARCH_UNIT_MASK|\
-        INTEL_ARCH_EVENT_MASK)
+#define ARCH_PERFMON_EVENTSEL_EVENT                    0x000000FFULL
+#define ARCH_PERFMON_EVENTSEL_UMASK                    0x0000FF00ULL
+#define ARCH_PERFMON_EVENTSEL_USR                      (1ULL << 16)
+#define ARCH_PERFMON_EVENTSEL_OS                       (1ULL << 17)
+#define ARCH_PERFMON_EVENTSEL_EDGE                     (1ULL << 18)
+#define ARCH_PERFMON_EVENTSEL_INT                      (1ULL << 20)
+#define ARCH_PERFMON_EVENTSEL_ANY                      (1ULL << 21)
+#define ARCH_PERFMON_EVENTSEL_ENABLE                   (1ULL << 22)
+#define ARCH_PERFMON_EVENTSEL_INV                      (1ULL << 23)
+#define ARCH_PERFMON_EVENTSEL_CMASK                    0xFF000000ULL
+
+#define AMD64_EVENTSEL_EVENT   \
+       (ARCH_PERFMON_EVENTSEL_EVENT | (0x0FULL << 32))
+#define INTEL_ARCH_EVENT_MASK  \
+       (ARCH_PERFMON_EVENTSEL_UMASK | ARCH_PERFMON_EVENTSEL_EVENT)
+
+#define X86_RAW_EVENT_MASK             \
+       (ARCH_PERFMON_EVENTSEL_EVENT |  \
+        ARCH_PERFMON_EVENTSEL_UMASK |  \
+        ARCH_PERFMON_EVENTSEL_EDGE  |  \
+        ARCH_PERFMON_EVENTSEL_INV   |  \
+        ARCH_PERFMON_EVENTSEL_CMASK)
+#define AMD64_RAW_EVENT_MASK           \
+       (X86_RAW_EVENT_MASK          |  \
+        AMD64_EVENTSEL_EVENT)
 
 #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_SEL                0x3c
 #define ARCH_PERFMON_UNHALTED_CORE_CYCLES_UMASK                (0x00 << 8)
@@ -67,7 +59,7 @@
 union cpuid10_eax {
        struct {
                unsigned int version_id:8;
-               unsigned int num_events:8;
+               unsigned int num_counters:8;
                unsigned int bit_width:8;
                unsigned int mask_length:8;
        } split;
@@ -76,7 +68,7 @@ union cpuid10_eax {
 
 union cpuid10_edx {
        struct {
-               unsigned int num_events_fixed:4;
+               unsigned int num_counters_fixed:4;
                unsigned int reserved:28;
        } split;
        unsigned int full;
@@ -136,6 +128,18 @@ extern void perf_events_lapic_init(void);
 
 #define PERF_EVENT_INDEX_OFFSET                        0
 
+/*
+ * Abuse bit 3 of the cpu eflags register to indicate proper PEBS IP fixups.
+ * This flag is otherwise unused and ABI specified to be 0, so nobody should
+ * care what we do with it.
+ */
+#define PERF_EFLAGS_EXACT      (1UL << 3)
+
+struct pt_regs;
+extern unsigned long perf_instruction_pointer(struct pt_regs *regs);
+extern unsigned long perf_misc_flags(struct pt_regs *regs);
+#define perf_misc_flags(regs)  perf_misc_flags(regs)
+
 #else
 static inline void init_hw_perf_events(void)           { }
 static inline void perf_events_lapic_init(void)        { }
diff --git a/arch/x86/include/asm/perf_event_p4.h b/arch/x86/include/asm/perf_event_p4.h
new file mode 100644 (file)
index 0000000..b05400a
--- /dev/null
@@ -0,0 +1,794 @@
+/*
+ * Netburst Perfomance Events (P4, old Xeon)
+ */
+
+#ifndef PERF_EVENT_P4_H
+#define PERF_EVENT_P4_H
+
+#include <linux/cpu.h>
+#include <linux/bitops.h>
+
+/*
+ * NetBurst has perfomance MSRs shared between
+ * threads if HT is turned on, ie for both logical
+ * processors (mem: in turn in Atom with HT support
+ * perf-MSRs are not shared and every thread has its
+ * own perf-MSRs set)
+ */
+#define ARCH_P4_TOTAL_ESCR     (46)
+#define ARCH_P4_RESERVED_ESCR  (2) /* IQ_ESCR(0,1) not always present */
+#define ARCH_P4_MAX_ESCR       (ARCH_P4_TOTAL_ESCR - ARCH_P4_RESERVED_ESCR)
+#define ARCH_P4_MAX_CCCR       (18)
+#define ARCH_P4_MAX_COUNTER    (ARCH_P4_MAX_CCCR / 2)
+
+#define P4_ESCR_EVENT_MASK     0x7e000000U
+#define P4_ESCR_EVENT_SHIFT    25
+#define P4_ESCR_EVENTMASK_MASK 0x01fffe00U
+#define P4_ESCR_EVENTMASK_SHIFT        9
+#define P4_ESCR_TAG_MASK       0x000001e0U
+#define P4_ESCR_TAG_SHIFT      5
+#define P4_ESCR_TAG_ENABLE     0x00000010U
+#define P4_ESCR_T0_OS          0x00000008U
+#define P4_ESCR_T0_USR         0x00000004U
+#define P4_ESCR_T1_OS          0x00000002U
+#define P4_ESCR_T1_USR         0x00000001U
+
+#define P4_ESCR_EVENT(v)       ((v) << P4_ESCR_EVENT_SHIFT)
+#define P4_ESCR_EMASK(v)       ((v) << P4_ESCR_EVENTMASK_SHIFT)
+#define P4_ESCR_TAG(v)         ((v) << P4_ESCR_TAG_SHIFT)
+
+/* Non HT mask */
+#define P4_ESCR_MASK                   \
+       (P4_ESCR_EVENT_MASK     |       \
+       P4_ESCR_EVENTMASK_MASK  |       \
+       P4_ESCR_TAG_MASK        |       \
+       P4_ESCR_TAG_ENABLE      |       \
+       P4_ESCR_T0_OS           |       \
+       P4_ESCR_T0_USR)
+
+/* HT mask */
+#define P4_ESCR_MASK_HT                        \
+       (P4_ESCR_MASK | P4_ESCR_T1_OS | P4_ESCR_T1_USR)
+
+#define P4_CCCR_OVF                    0x80000000U
+#define P4_CCCR_CASCADE                        0x40000000U
+#define P4_CCCR_OVF_PMI_T0             0x04000000U
+#define P4_CCCR_OVF_PMI_T1             0x08000000U
+#define P4_CCCR_FORCE_OVF              0x02000000U
+#define P4_CCCR_EDGE                   0x01000000U
+#define P4_CCCR_THRESHOLD_MASK         0x00f00000U
+#define P4_CCCR_THRESHOLD_SHIFT                20
+#define P4_CCCR_COMPLEMENT             0x00080000U
+#define P4_CCCR_COMPARE                        0x00040000U
+#define P4_CCCR_ESCR_SELECT_MASK       0x0000e000U
+#define P4_CCCR_ESCR_SELECT_SHIFT      13
+#define P4_CCCR_ENABLE                 0x00001000U
+#define P4_CCCR_THREAD_SINGLE          0x00010000U
+#define P4_CCCR_THREAD_BOTH            0x00020000U
+#define P4_CCCR_THREAD_ANY             0x00030000U
+#define P4_CCCR_RESERVED               0x00000fffU
+
+#define P4_CCCR_THRESHOLD(v)           ((v) << P4_CCCR_THRESHOLD_SHIFT)
+#define P4_CCCR_ESEL(v)                        ((v) << P4_CCCR_ESCR_SELECT_SHIFT)
+
+/* Custom bits in reerved CCCR area */
+#define P4_CCCR_CACHE_OPS_MASK         0x0000003fU
+
+
+/* Non HT mask */
+#define P4_CCCR_MASK                           \
+       (P4_CCCR_OVF                    |       \
+       P4_CCCR_CASCADE                 |       \
+       P4_CCCR_OVF_PMI_T0              |       \
+       P4_CCCR_FORCE_OVF               |       \
+       P4_CCCR_EDGE                    |       \
+       P4_CCCR_THRESHOLD_MASK          |       \
+       P4_CCCR_COMPLEMENT              |       \
+       P4_CCCR_COMPARE                 |       \
+       P4_CCCR_ESCR_SELECT_MASK        |       \
+       P4_CCCR_ENABLE)
+
+/* HT mask */
+#define P4_CCCR_MASK_HT        (P4_CCCR_MASK | P4_CCCR_THREAD_ANY)
+
+#define P4_GEN_ESCR_EMASK(class, name, bit)    \
+       class##__##name = ((1 << bit) << P4_ESCR_EVENTMASK_SHIFT)
+#define P4_ESCR_EMASK_BIT(class, name)         class##__##name
+
+/*
+ * config field is 64bit width and consists of
+ * HT << 63 | ESCR << 32 | CCCR
+ * where HT is HyperThreading bit (since ESCR
+ * has it reserved we may use it for own purpose)
+ *
+ * note that this is NOT the addresses of respective
+ * ESCR and CCCR but rather an only packed value should
+ * be unpacked and written to a proper addresses
+ *
+ * the base idea is to pack as much info as
+ * possible
+ */
+#define p4_config_pack_escr(v)         (((u64)(v)) << 32)
+#define p4_config_pack_cccr(v)         (((u64)(v)) & 0xffffffffULL)
+#define p4_config_unpack_escr(v)       (((u64)(v)) >> 32)
+#define p4_config_unpack_cccr(v)       (((u64)(v)) & 0xffffffffULL)
+
+#define p4_config_unpack_emask(v)                      \
+       ({                                              \
+               u32 t = p4_config_unpack_escr((v));     \
+               t = t &  P4_ESCR_EVENTMASK_MASK;        \
+               t = t >> P4_ESCR_EVENTMASK_SHIFT;       \
+               t;                                      \
+       })
+
+#define p4_config_unpack_event(v)                      \
+       ({                                              \
+               u32 t = p4_config_unpack_escr((v));     \
+               t = t &  P4_ESCR_EVENT_MASK;            \
+               t = t >> P4_ESCR_EVENT_SHIFT;           \
+               t;                                      \
+       })
+
+#define p4_config_unpack_cache_event(v)        (((u64)(v)) & P4_CCCR_CACHE_OPS_MASK)
+
+#define P4_CONFIG_HT_SHIFT             63
+#define P4_CONFIG_HT                   (1ULL << P4_CONFIG_HT_SHIFT)
+
+static inline bool p4_is_event_cascaded(u64 config)
+{
+       u32 cccr = p4_config_unpack_cccr(config);
+       return !!(cccr & P4_CCCR_CASCADE);
+}
+
+static inline int p4_ht_config_thread(u64 config)
+{
+       return !!(config & P4_CONFIG_HT);
+}
+
+static inline u64 p4_set_ht_bit(u64 config)
+{
+       return config | P4_CONFIG_HT;
+}
+
+static inline u64 p4_clear_ht_bit(u64 config)
+{
+       return config & ~P4_CONFIG_HT;
+}
+
+static inline int p4_ht_active(void)
+{
+#ifdef CONFIG_SMP
+       return smp_num_siblings > 1;
+#endif
+       return 0;
+}
+
+static inline int p4_ht_thread(int cpu)
+{
+#ifdef CONFIG_SMP
+       if (smp_num_siblings == 2)
+               return cpu != cpumask_first(__get_cpu_var(cpu_sibling_map));
+#endif
+       return 0;
+}
+
+static inline int p4_should_swap_ts(u64 config, int cpu)
+{
+       return p4_ht_config_thread(config) ^ p4_ht_thread(cpu);
+}
+
+static inline u32 p4_default_cccr_conf(int cpu)
+{
+       /*
+        * Note that P4_CCCR_THREAD_ANY is "required" on
+        * non-HT machines (on HT machines we count TS events
+        * regardless the state of second logical processor
+        */
+       u32 cccr = P4_CCCR_THREAD_ANY;
+
+       if (!p4_ht_thread(cpu))
+               cccr |= P4_CCCR_OVF_PMI_T0;
+       else
+               cccr |= P4_CCCR_OVF_PMI_T1;
+
+       return cccr;
+}
+
+static inline u32 p4_default_escr_conf(int cpu, int exclude_os, int exclude_usr)
+{
+       u32 escr = 0;
+
+       if (!p4_ht_thread(cpu)) {
+               if (!exclude_os)
+                       escr |= P4_ESCR_T0_OS;
+               if (!exclude_usr)
+                       escr |= P4_ESCR_T0_USR;
+       } else {
+               if (!exclude_os)
+                       escr |= P4_ESCR_T1_OS;
+               if (!exclude_usr)
+                       escr |= P4_ESCR_T1_USR;
+       }
+
+       return escr;
+}
+
+enum P4_EVENTS {
+       P4_EVENT_TC_DELIVER_MODE,
+       P4_EVENT_BPU_FETCH_REQUEST,
+       P4_EVENT_ITLB_REFERENCE,
+       P4_EVENT_MEMORY_CANCEL,
+       P4_EVENT_MEMORY_COMPLETE,
+       P4_EVENT_LOAD_PORT_REPLAY,
+       P4_EVENT_STORE_PORT_REPLAY,
+       P4_EVENT_MOB_LOAD_REPLAY,
+       P4_EVENT_PAGE_WALK_TYPE,
+       P4_EVENT_BSQ_CACHE_REFERENCE,
+       P4_EVENT_IOQ_ALLOCATION,
+       P4_EVENT_IOQ_ACTIVE_ENTRIES,
+       P4_EVENT_FSB_DATA_ACTIVITY,
+       P4_EVENT_BSQ_ALLOCATION,
+       P4_EVENT_BSQ_ACTIVE_ENTRIES,
+       P4_EVENT_SSE_INPUT_ASSIST,
+       P4_EVENT_PACKED_SP_UOP,
+       P4_EVENT_PACKED_DP_UOP,
+       P4_EVENT_SCALAR_SP_UOP,
+       P4_EVENT_SCALAR_DP_UOP,
+       P4_EVENT_64BIT_MMX_UOP,
+       P4_EVENT_128BIT_MMX_UOP,
+       P4_EVENT_X87_FP_UOP,
+       P4_EVENT_TC_MISC,
+       P4_EVENT_GLOBAL_POWER_EVENTS,
+       P4_EVENT_TC_MS_XFER,
+       P4_EVENT_UOP_QUEUE_WRITES,
+       P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE,
+       P4_EVENT_RETIRED_BRANCH_TYPE,
+       P4_EVENT_RESOURCE_STALL,
+       P4_EVENT_WC_BUFFER,
+       P4_EVENT_B2B_CYCLES,
+       P4_EVENT_BNR,
+       P4_EVENT_SNOOP,
+       P4_EVENT_RESPONSE,
+       P4_EVENT_FRONT_END_EVENT,
+       P4_EVENT_EXECUTION_EVENT,
+       P4_EVENT_REPLAY_EVENT,
+       P4_EVENT_INSTR_RETIRED,
+       P4_EVENT_UOPS_RETIRED,
+       P4_EVENT_UOP_TYPE,
+       P4_EVENT_BRANCH_RETIRED,
+       P4_EVENT_MISPRED_BRANCH_RETIRED,
+       P4_EVENT_X87_ASSIST,
+       P4_EVENT_MACHINE_CLEAR,
+       P4_EVENT_INSTR_COMPLETED,
+};
+
+#define P4_OPCODE(event)               event##_OPCODE
+#define P4_OPCODE_ESEL(opcode)         ((opcode & 0x00ff) >> 0)
+#define P4_OPCODE_EVNT(opcode)         ((opcode & 0xff00) >> 8)
+#define P4_OPCODE_PACK(event, sel)     (((event) << 8) | sel)
+
+/*
+ * Comments below the event represent ESCR restriction
+ * for this event and counter index per ESCR
+ *
+ * MSR_P4_IQ_ESCR0 and MSR_P4_IQ_ESCR1 are available only on early
+ * processor builds (family 0FH, models 01H-02H). These MSRs
+ * are not available on later versions, so that we don't use
+ * them completely
+ *
+ * Also note that CCCR1 do not have P4_CCCR_ENABLE bit properly
+ * working so that we should not use this CCCR and respective
+ * counter as result
+ */
+enum P4_EVENT_OPCODES {
+       P4_OPCODE(P4_EVENT_TC_DELIVER_MODE)             = P4_OPCODE_PACK(0x01, 0x01),
+       /*
+        * MSR_P4_TC_ESCR0:     4, 5
+        * MSR_P4_TC_ESCR1:     6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST)           = P4_OPCODE_PACK(0x03, 0x00),
+       /*
+        * MSR_P4_BPU_ESCR0:    0, 1
+        * MSR_P4_BPU_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_ITLB_REFERENCE)              = P4_OPCODE_PACK(0x18, 0x03),
+       /*
+        * MSR_P4_ITLB_ESCR0:   0, 1
+        * MSR_P4_ITLB_ESCR1:   2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_MEMORY_CANCEL)               = P4_OPCODE_PACK(0x02, 0x05),
+       /*
+        * MSR_P4_DAC_ESCR0:    8, 9
+        * MSR_P4_DAC_ESCR1:    10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_MEMORY_COMPLETE)             = P4_OPCODE_PACK(0x08, 0x02),
+       /*
+        * MSR_P4_SAAT_ESCR0:   8, 9
+        * MSR_P4_SAAT_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY)            = P4_OPCODE_PACK(0x04, 0x02),
+       /*
+        * MSR_P4_SAAT_ESCR0:   8, 9
+        * MSR_P4_SAAT_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY)           = P4_OPCODE_PACK(0x05, 0x02),
+       /*
+        * MSR_P4_SAAT_ESCR0:   8, 9
+        * MSR_P4_SAAT_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY)             = P4_OPCODE_PACK(0x03, 0x02),
+       /*
+        * MSR_P4_MOB_ESCR0:    0, 1
+        * MSR_P4_MOB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE)              = P4_OPCODE_PACK(0x01, 0x04),
+       /*
+        * MSR_P4_PMH_ESCR0:    0, 1
+        * MSR_P4_PMH_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE)         = P4_OPCODE_PACK(0x0c, 0x07),
+       /*
+        * MSR_P4_BSU_ESCR0:    0, 1
+        * MSR_P4_BSU_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_IOQ_ALLOCATION)              = P4_OPCODE_PACK(0x03, 0x06),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES)          = P4_OPCODE_PACK(0x1a, 0x06),
+       /*
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY)           = P4_OPCODE_PACK(0x17, 0x06),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_BSQ_ALLOCATION)              = P4_OPCODE_PACK(0x05, 0x07),
+       /*
+        * MSR_P4_BSU_ESCR0:    0, 1
+        */
+
+       P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES)          = P4_OPCODE_PACK(0x06, 0x07),
+       /*
+        * NOTE: no ESCR name in docs, it's guessed
+        * MSR_P4_BSU_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST)            = P4_OPCODE_PACK(0x34, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_PACKED_SP_UOP)               = P4_OPCODE_PACK(0x08, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_PACKED_DP_UOP)               = P4_OPCODE_PACK(0x0c, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_SCALAR_SP_UOP)               = P4_OPCODE_PACK(0x0a, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_SCALAR_DP_UOP)               = P4_OPCODE_PACK(0x0e, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_64BIT_MMX_UOP)               = P4_OPCODE_PACK(0x02, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_128BIT_MMX_UOP)              = P4_OPCODE_PACK(0x1a, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_X87_FP_UOP)                  = P4_OPCODE_PACK(0x04, 0x01),
+       /*
+        * MSR_P4_FIRM_ESCR0:   8, 9
+        * MSR_P4_FIRM_ESCR1:   10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_TC_MISC)                     = P4_OPCODE_PACK(0x06, 0x01),
+       /*
+        * MSR_P4_TC_ESCR0:     4, 5
+        * MSR_P4_TC_ESCR1:     6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS)         = P4_OPCODE_PACK(0x13, 0x06),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_TC_MS_XFER)                  = P4_OPCODE_PACK(0x05, 0x00),
+       /*
+        * MSR_P4_MS_ESCR0:     4, 5
+        * MSR_P4_MS_ESCR1:     6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES)            = P4_OPCODE_PACK(0x09, 0x00),
+       /*
+        * MSR_P4_MS_ESCR0:     4, 5
+        * MSR_P4_MS_ESCR1:     6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE) = P4_OPCODE_PACK(0x05, 0x02),
+       /*
+        * MSR_P4_TBPU_ESCR0:   4, 5
+        * MSR_P4_TBPU_ESCR1:   6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE)         = P4_OPCODE_PACK(0x04, 0x02),
+       /*
+        * MSR_P4_TBPU_ESCR0:   4, 5
+        * MSR_P4_TBPU_ESCR1:   6, 7
+        */
+
+       P4_OPCODE(P4_EVENT_RESOURCE_STALL)              = P4_OPCODE_PACK(0x01, 0x01),
+       /*
+        * MSR_P4_ALF_ESCR0:    12, 13, 16
+        * MSR_P4_ALF_ESCR1:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_WC_BUFFER)                   = P4_OPCODE_PACK(0x05, 0x05),
+       /*
+        * MSR_P4_DAC_ESCR0:    8, 9
+        * MSR_P4_DAC_ESCR1:    10, 11
+        */
+
+       P4_OPCODE(P4_EVENT_B2B_CYCLES)                  = P4_OPCODE_PACK(0x16, 0x03),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_BNR)                         = P4_OPCODE_PACK(0x08, 0x03),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_SNOOP)                       = P4_OPCODE_PACK(0x06, 0x03),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_RESPONSE)                    = P4_OPCODE_PACK(0x04, 0x03),
+       /*
+        * MSR_P4_FSB_ESCR0:    0, 1
+        * MSR_P4_FSB_ESCR1:    2, 3
+        */
+
+       P4_OPCODE(P4_EVENT_FRONT_END_EVENT)             = P4_OPCODE_PACK(0x08, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_EXECUTION_EVENT)             = P4_OPCODE_PACK(0x0c, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_REPLAY_EVENT)                = P4_OPCODE_PACK(0x09, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_INSTR_RETIRED)               = P4_OPCODE_PACK(0x02, 0x04),
+       /*
+        * MSR_P4_CRU_ESCR0:    12, 13, 16
+        * MSR_P4_CRU_ESCR1:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_UOPS_RETIRED)                = P4_OPCODE_PACK(0x01, 0x04),
+       /*
+        * MSR_P4_CRU_ESCR0:    12, 13, 16
+        * MSR_P4_CRU_ESCR1:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_UOP_TYPE)                    = P4_OPCODE_PACK(0x02, 0x02),
+       /*
+        * MSR_P4_RAT_ESCR0:    12, 13, 16
+        * MSR_P4_RAT_ESCR1:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_BRANCH_RETIRED)              = P4_OPCODE_PACK(0x06, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED)      = P4_OPCODE_PACK(0x03, 0x04),
+       /*
+        * MSR_P4_CRU_ESCR0:    12, 13, 16
+        * MSR_P4_CRU_ESCR1:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_X87_ASSIST)                  = P4_OPCODE_PACK(0x03, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_MACHINE_CLEAR)               = P4_OPCODE_PACK(0x02, 0x05),
+       /*
+        * MSR_P4_CRU_ESCR2:    12, 13, 16
+        * MSR_P4_CRU_ESCR3:    14, 15, 17
+        */
+
+       P4_OPCODE(P4_EVENT_INSTR_COMPLETED)             = P4_OPCODE_PACK(0x07, 0x04),
+       /*
+        * MSR_P4_CRU_ESCR0:    12, 13, 16
+        * MSR_P4_CRU_ESCR1:    14, 15, 17
+        */
+};
+
+/*
+ * a caller should use P4_ESCR_EMASK_NAME helper to
+ * pick the EventMask needed, for example
+ *
+ *     P4_ESCR_EMASK_NAME(P4_EVENT_TC_DELIVER_MODE, DD)
+ */
+enum P4_ESCR_EMASKS {
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DD, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DB, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, DI, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BD, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BB, 4),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, BI, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_DELIVER_MODE, ID, 6),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_BPU_FETCH_REQUEST, TCMISS, 0),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, MISS, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_ITLB_REFERENCE, HIT_UK, 2),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, ST_RB_FULL, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_CANCEL, 64K_CONF, 3),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, LSC, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MEMORY_COMPLETE, SSC, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_LOAD_PORT_REPLAY, SPLIT_LD, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_STORE_PORT_REPLAY, SPLIT_ST, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STA, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, NO_STD, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, PARTIAL_DATA, 4),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MOB_LOAD_REPLAY, UNALGN_ADDR, 5),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, DTMISS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_PAGE_WALK_TYPE, ITMISS, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE, 4),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS, 8),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS, 9),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS, 10),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, DEFAULT, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_READ, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, ALL_WRITE, 6),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_UC, 7),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WC, 8),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WT, 9),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WP, 10),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, MEM_WB, 11),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OWN, 13),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, OTHER, 14),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ALLOCATION, PREFETCH, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, DEFAULT, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_READ, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, ALL_WRITE, 6),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_UC, 7),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WC, 8),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WT, 9),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WP, 10),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, MEM_WB, 11),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OWN, 13),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, OTHER, 14),
+       P4_GEN_ESCR_EMASK(P4_EVENT_IOQ_ACTIVE_ENTRIES, PREFETCH, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OTHER, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_DRV, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OWN, 4),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FSB_DATA_ACTIVITY, DBSY_OTHER, 5),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE0, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_TYPE1, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN0, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LEN1, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_IO_TYPE, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_LOCK_TYPE, 6),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_CACHE_TYPE, 7),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_SPLIT_TYPE, 8),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_DEM_TYPE, 9),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, REQ_ORD_TYPE, 10),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE0, 11),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE1, 12),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ALLOCATION, MEM_TYPE2, 13),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE0, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_TYPE1, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN0, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LEN1, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_IO_TYPE, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_LOCK_TYPE, 6),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_CACHE_TYPE, 7),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_SPLIT_TYPE, 8),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_DEM_TYPE, 9),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, REQ_ORD_TYPE, 10),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE0, 11),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE1, 12),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BSQ_ACTIVE_ENTRIES, MEM_TYPE2, 13),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_SSE_INPUT_ASSIST, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_SP_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_PACKED_DP_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_SP_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_SCALAR_DP_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_64BIT_MMX_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_128BIT_MMX_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_FP_UOP, ALL, 15),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_MISC, FLUSH, 4),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING, 0),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_TC_MS_XFER, CISC, 0),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_BUILD, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_TC_DELIVER, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOP_QUEUE_WRITES, FROM_ROM, 2),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CONDITIONAL, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, CALL, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, RETURN, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE, INDIRECT, 4),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, CALL, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT, 4),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_RESOURCE_STALL, SBFULL, 5),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_EVICTS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_WC_BUFFER, WCB_FULL_EVICTS, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, NBOGUS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_FRONT_END_EVENT, BOGUS, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS0, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS1, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS2, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, NBOGUS3, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS0, 4),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS1, 5),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS2, 6),
+       P4_GEN_ESCR_EMASK(P4_EVENT_EXECUTION_EVENT, BOGUS3, 7),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, NBOGUS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_REPLAY_EVENT, BOGUS, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, NBOGUSTAG, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSNTAG, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_RETIRED, BOGUSTAG, 3),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, NBOGUS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOPS_RETIRED, BOGUS, 1),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGLOADS, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_UOP_TYPE, TAGSTORES, 2),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNP, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMNM, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTP, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_BRANCH_RETIRED, MMTM, 3),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS, 0),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSU, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, FPSO, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAO, 2),
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, POAU, 3),
+       P4_GEN_ESCR_EMASK(P4_EVENT_X87_ASSIST, PREA, 4),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, CLEAR, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, MOCLEAR, 1),
+       P4_GEN_ESCR_EMASK(P4_EVENT_MACHINE_CLEAR, SMCLEAR, 2),
+
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, NBOGUS, 0),
+       P4_GEN_ESCR_EMASK(P4_EVENT_INSTR_COMPLETED, BOGUS, 1),
+};
+
+/* P4 PEBS: stale for a while */
+#define P4_PEBS_METRIC_MASK    0x00001fffU
+#define P4_PEBS_UOB_TAG                0x01000000U
+#define P4_PEBS_ENABLE         0x02000000U
+
+/* Replay metrics for MSR_IA32_PEBS_ENABLE and MSR_P4_PEBS_MATRIX_VERT */
+#define P4_PEBS__1stl_cache_load_miss_retired  0x3000001
+#define P4_PEBS__2ndl_cache_load_miss_retired  0x3000002
+#define P4_PEBS__dtlb_load_miss_retired                0x3000004
+#define P4_PEBS__dtlb_store_miss_retired       0x3000004
+#define P4_PEBS__dtlb_all_miss_retired         0x3000004
+#define P4_PEBS__tagged_mispred_branch         0x3018000
+#define P4_PEBS__mob_load_replay_retired       0x3000200
+#define P4_PEBS__split_load_retired            0x3000400
+#define P4_PEBS__split_store_retired           0x3000400
+
+#define P4_VERT__1stl_cache_load_miss_retired  0x0000001
+#define P4_VERT__2ndl_cache_load_miss_retired  0x0000001
+#define P4_VERT__dtlb_load_miss_retired                0x0000001
+#define P4_VERT__dtlb_store_miss_retired       0x0000002
+#define P4_VERT__dtlb_all_miss_retired         0x0000003
+#define P4_VERT__tagged_mispred_branch         0x0000010
+#define P4_VERT__mob_load_replay_retired       0x0000001
+#define P4_VERT__split_load_retired            0x0000001
+#define P4_VERT__split_store_retired           0x0000002
+
+enum P4_CACHE_EVENTS {
+       P4_CACHE__NONE,
+
+       P4_CACHE__1stl_cache_load_miss_retired,
+       P4_CACHE__2ndl_cache_load_miss_retired,
+       P4_CACHE__dtlb_load_miss_retired,
+       P4_CACHE__dtlb_store_miss_retired,
+       P4_CACHE__itlb_reference_hit,
+       P4_CACHE__itlb_reference_miss,
+
+       P4_CACHE__MAX
+};
+
+#endif /* PERF_EVENT_P4_H */
index b753ea5..5a51379 100644 (file)
@@ -21,7 +21,6 @@ struct mm_struct;
 #include <asm/msr.h>
 #include <asm/desc_defs.h>
 #include <asm/nops.h>
-#include <asm/ds.h>
 
 #include <linux/personality.h>
 #include <linux/cpumask.h>
@@ -29,6 +28,7 @@ struct mm_struct;
 #include <linux/threads.h>
 #include <linux/math64.h>
 #include <linux/init.h>
+#include <linux/err.h>
 
 #define HBP_NUM 4
 /*
@@ -113,7 +113,6 @@ struct cpuinfo_x86 {
        /* Index into per_cpu list: */
        u16                     cpu_index;
 #endif
-       unsigned int            x86_hyper_vendor;
 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
 
 #define X86_VENDOR_INTEL       0
@@ -127,9 +126,6 @@ struct cpuinfo_x86 {
 
 #define X86_VENDOR_UNKNOWN     0xff
 
-#define X86_HYPER_VENDOR_NONE  0
-#define X86_HYPER_VENDOR_VMWARE 1
-
 /*
  * capabilities of CPUs
  */
@@ -380,6 +376,10 @@ union thread_xstate {
        struct xsave_struct             xsave;
 };
 
+struct fpu {
+       union thread_xstate *state;
+};
+
 #ifdef CONFIG_X86_64
 DECLARE_PER_CPU(struct orig_ist, orig_ist);
 
@@ -457,7 +457,7 @@ struct thread_struct {
        unsigned long           trap_no;
        unsigned long           error_code;
        /* floating point and extended processor state */
-       union thread_xstate     *xstate;
+       struct fpu              fpu;
 #ifdef CONFIG_X86_32
        /* Virtual 86 mode info */
        struct vm86_struct __user *vm86_info;
@@ -473,10 +473,6 @@ struct thread_struct {
        unsigned long           iopl;
        /* Max allowed port in the bitmap, in bytes: */
        unsigned                io_bitmap_max;
-/* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
-       unsigned long   debugctlmsr;
-       /* Debug Store context; see asm/ds.h */
-       struct ds_context       *ds_ctx;
 };
 
 static inline unsigned long native_get_debugreg(int regno)
@@ -803,7 +799,7 @@ extern void cpu_init(void);
 
 static inline unsigned long get_debugctlmsr(void)
 {
-    unsigned long debugctlmsr = 0;
+       unsigned long debugctlmsr = 0;
 
 #ifndef CONFIG_X86_DEBUGCTLMSR
        if (boot_cpu_data.x86 < 6)
@@ -811,21 +807,6 @@ static inline unsigned long get_debugctlmsr(void)
 #endif
        rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
 
-    return debugctlmsr;
-}
-
-static inline unsigned long get_debugctlmsr_on_cpu(int cpu)
-{
-       u64 debugctlmsr = 0;
-       u32 val1, val2;
-
-#ifndef CONFIG_X86_DEBUGCTLMSR
-       if (boot_cpu_data.x86 < 6)
-               return 0;
-#endif
-       rdmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR, &val1, &val2);
-       debugctlmsr = val1 | ((u64)val2 << 32);
-
        return debugctlmsr;
 }
 
@@ -838,18 +819,6 @@ static inline void update_debugctlmsr(unsigned long debugctlmsr)
        wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr);
 }
 
-static inline void update_debugctlmsr_on_cpu(int cpu,
-                                            unsigned long debugctlmsr)
-{
-#ifndef CONFIG_X86_DEBUGCTLMSR
-       if (boot_cpu_data.x86 < 6)
-               return;
-#endif
-       wrmsr_on_cpu(cpu, MSR_IA32_DEBUGCTLMSR,
-                    (u32)((u64)debugctlmsr),
-                    (u32)((u64)debugctlmsr >> 32));
-}
-
 /*
  * from system description table in BIOS. Mostly for MCA use, but
  * others may find it useful:
index 8672303..52b098a 100644 (file)
 
 #ifndef __ASSEMBLY__
 #include <linux/types.h>
-
-/* configuration/status structure used in PTRACE_BTS_CONFIG and
-   PTRACE_BTS_STATUS commands.
-*/
-struct ptrace_bts_config {
-       /* requested or actual size of BTS buffer in bytes */
-       __u32 size;
-       /* bitmask of below flags */
-       __u32 flags;
-       /* buffer overflow signal */
-       __u32 signal;
-       /* actual size of bts_struct in bytes */
-       __u32 bts_size;
-};
-#endif /* __ASSEMBLY__ */
-
-#define PTRACE_BTS_O_TRACE     0x1 /* branch trace */
-#define PTRACE_BTS_O_SCHED     0x2 /* scheduling events w/ jiffies */
-#define PTRACE_BTS_O_SIGNAL     0x4 /* send SIG<signal> on buffer overflow
-                                      instead of wrapping around */
-#define PTRACE_BTS_O_ALLOC     0x8 /* (re)allocate buffer */
-
-#define PTRACE_BTS_CONFIG      40
-/* Configure branch trace recording.
-   ADDR points to a struct ptrace_bts_config.
-   DATA gives the size of that buffer.
-   A new buffer is allocated, if requested in the flags.
-   An overflow signal may only be requested for new buffers.
-   Returns the number of bytes read.
-*/
-#define PTRACE_BTS_STATUS      41
-/* Return the current configuration in a struct ptrace_bts_config
-   pointed to by ADDR; DATA gives the size of that buffer.
-   Returns the number of bytes written.
-*/
-#define PTRACE_BTS_SIZE                42
-/* Return the number of available BTS records for draining.
-   DATA and ADDR are ignored.
-*/
-#define PTRACE_BTS_GET         43
-/* Get a single BTS record.
-   DATA defines the index into the BTS array, where 0 is the newest
-   entry, and higher indices refer to older entries.
-   ADDR is pointing to struct bts_struct (see asm/ds.h).
-*/
-#define PTRACE_BTS_CLEAR       44
-/* Clear the BTS buffer.
-   DATA and ADDR are ignored.
-*/
-#define PTRACE_BTS_DRAIN       45
-/* Read all available BTS records and clear the buffer.
-   ADDR points to an array of struct bts_struct.
-   DATA gives the size of that buffer.
-   BTS records are read from oldest to newest.
-   Returns number of BTS records drained.
-*/
+#endif
 
 #endif /* _ASM_X86_PTRACE_ABI_H */
index 69a686a..78cd1ea 100644 (file)
@@ -289,12 +289,6 @@ extern int do_get_thread_area(struct task_struct *p, int idx,
 extern int do_set_thread_area(struct task_struct *p, int idx,
                              struct user_desc __user *info, int can_allocate);
 
-#ifdef CONFIG_X86_PTRACE_BTS
-extern void ptrace_bts_untrace(struct task_struct *tsk);
-
-#define arch_ptrace_untrace(tsk)       ptrace_bts_untrace(tsk)
-#endif /* CONFIG_X86_PTRACE_BTS */
-
 #endif /* __KERNEL__ */
 
 #endif /* !__ASSEMBLY__ */
index e0d2890..62ba940 100644 (file)
@@ -87,13 +87,12 @@ struct thread_info {
 #define TIF_NOTSC              16      /* TSC is not accessible in userland */
 #define TIF_IA32               17      /* 32bit process */
 #define TIF_FORK               18      /* ret_from_fork */
-#define TIF_MEMDIE             20
+#define TIF_MEMDIE             20      /* is terminating due to OOM killer */
 #define TIF_DEBUG              21      /* uses debug registers */
 #define TIF_IO_BITMAP          22      /* uses I/O bitmap */
 #define TIF_FREEZE             23      /* is freezing for suspend */
 #define TIF_FORCED_TF          24      /* true if TF in eflags artificially */
-#define TIF_DEBUGCTLMSR                25      /* uses thread_struct.debugctlmsr */
-#define TIF_DS_AREA_MSR                26      /* uses thread_struct.ds_area_msr */
+#define TIF_BLOCKSTEP          25      /* set when we want DEBUGCTLMSR_BTF */
 #define TIF_LAZY_MMU_UPDATES   27      /* task is updating the mmu lazily */
 #define TIF_SYSCALL_TRACEPOINT 28      /* syscall tracepoint instrumentation */
 
@@ -115,8 +114,7 @@ struct thread_info {
 #define _TIF_IO_BITMAP         (1 << TIF_IO_BITMAP)
 #define _TIF_FREEZE            (1 << TIF_FREEZE)
 #define _TIF_FORCED_TF         (1 << TIF_FORCED_TF)
-#define _TIF_DEBUGCTLMSR       (1 << TIF_DEBUGCTLMSR)
-#define _TIF_DS_AREA_MSR       (1 << TIF_DS_AREA_MSR)
+#define _TIF_BLOCKSTEP         (1 << TIF_BLOCKSTEP)
 #define _TIF_LAZY_MMU_UPDATES  (1 << TIF_LAZY_MMU_UPDATES)
 #define _TIF_SYSCALL_TRACEPOINT        (1 << TIF_SYSCALL_TRACEPOINT)
 
@@ -147,7 +145,7 @@ struct thread_info {
 
 /* flags to check in __switch_to() */
 #define _TIF_WORK_CTXSW                                                        \
-       (_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC)
+       (_TIF_IO_BITMAP|_TIF_NOTSC|_TIF_BLOCKSTEP)
 
 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
@@ -244,7 +242,6 @@ static inline struct thread_info *current_thread_info(void)
 #define TS_POLLING             0x0004  /* true if in idle loop
                                           and not sleeping */
 #define TS_RESTORE_SIGMASK     0x0008  /* restore signal mask in do_signal() */
-#define TS_XSAVE               0x0010  /* Use xsave/xrstor */
 
 #define tsk_is_polling(t) (task_thread_info(t)->status & TS_POLLING)
 
index 4da91ad..f66cda5 100644 (file)
@@ -79,7 +79,7 @@ static inline int get_si_code(unsigned long condition)
 
 extern int panic_on_unrecovered_nmi;
 
-void math_error(void __user *);
+void math_error(struct pt_regs *, int, int);
 void math_emulate(struct math_emu_info *);
 #ifndef CONFIG_X86_32
 asmlinkage void smp_thermal_interrupt(void);
index b414d2b..aa558ac 100644 (file)
  * set 2 is at BASE + 2*512, set 3 at BASE + 3*512, and so on.
  *
  * We will use 31 sets, one for sending BAU messages from each of the 32
- * cpu's on the node.
+ * cpu's on the uvhub.
  *
  * TLB shootdown will use the first of the 8 descriptors of each set.
  * Each of the descriptors is 64 bytes in size (8*64 = 512 bytes in a set).
  */
 
 #define UV_ITEMS_PER_DESCRIPTOR                8
+#define MAX_BAU_CONCURRENT             3
 #define UV_CPUS_PER_ACT_STATUS         32
 #define UV_ACT_STATUS_MASK             0x3
 #define UV_ACT_STATUS_SIZE             2
@@ -45,6 +46,9 @@
 #define UV_PAYLOADQ_PNODE_SHIFT                49
 #define UV_PTC_BASENAME                        "sgi_uv/ptc_statistics"
 #define uv_physnodeaddr(x)             ((__pa((unsigned long)(x)) & uv_mmask))
+#define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15
+#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16
+#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
 
 /*
  * bits in UVH_LB_BAU_SB_ACTIVATION_STATUS_0/1
 #define DESC_STATUS_SOURCE_TIMEOUT     3
 
 /*
- * source side thresholds at which message retries print a warning
+ * source side threshholds at which message retries print a warning
  */
 #define SOURCE_TIMEOUT_LIMIT           20
 #define DESTINATION_TIMEOUT_LIMIT      20
 
+/*
+ * misc. delays, in microseconds
+ */
+#define THROTTLE_DELAY                 10
+#define TIMEOUT_DELAY                  10
+#define BIOS_TO                                1000
+/* BIOS is assumed to set the destination timeout to 1003520 nanoseconds */
+
+/*
+ * threshholds at which to use IPI to free resources
+ */
+#define PLUGSB4RESET 100
+#define TIMEOUTSB4RESET 100
+
 /*
  * number of entries in the destination side payload queue
  */
-#define DEST_Q_SIZE                    17
+#define DEST_Q_SIZE                    20
 /*
  * number of destination side software ack resources
  */
 /*
  * completion statuses for sending a TLB flush message
  */
-#define        FLUSH_RETRY                     1
-#define        FLUSH_GIVEUP                    2
-#define        FLUSH_COMPLETE                  3
+#define FLUSH_RETRY_PLUGGED            1
+#define FLUSH_RETRY_TIMEOUT            2
+#define FLUSH_GIVEUP                   3
+#define FLUSH_COMPLETE                 4
 
 /*
  * Distribution: 32 bytes (256 bits) (bytes 0-0x1f of descriptor)
  * 'base_dest_nodeid' field of the header corresponds to the
  * destination nodeID associated with that specified bit.
  */
-struct bau_target_nodemask {
-       unsigned long bits[BITS_TO_LONGS(256)];
+struct bau_target_uvhubmask {
+       unsigned long bits[BITS_TO_LONGS(UV_DISTRIBUTION_SIZE)];
 };
 
 /*
- * mask of cpu's on a node
+ * mask of cpu's on a uvhub
  * (during initialization we need to check that unsigned long has
- *  enough bits for max. cpu's per node)
+ *  enough bits for max. cpu's per uvhub)
  */
 struct bau_local_cpumask {
        unsigned long bits;
@@ -135,8 +154,8 @@ struct bau_msg_payload {
 struct bau_msg_header {
        unsigned int dest_subnodeid:6;  /* must be 0x10, for the LB */
        /* bits 5:0 */
-       unsigned int base_dest_nodeid:15; /* nasid>>1 (pnode) of */
-       /* bits 20:6 */                   /* first bit in node_map */
+       unsigned int base_dest_nodeid:15; /* nasid (pnode<<1) of */
+       /* bits 20:6 */                   /* first bit in uvhub map */
        unsigned int command:8; /* message type */
        /* bits 28:21 */
                                /* 0x38: SN3net EndPoint Message */
@@ -146,26 +165,38 @@ struct bau_msg_header {
        unsigned int rsvd_2:9;  /* must be zero */
        /* bits 40:32 */
                                /* Suppl_A is 56-41 */
-       unsigned int payload_2a:8;/* becomes byte 16 of msg */
-       /* bits 48:41 */        /* not currently using */
-       unsigned int payload_2b:8;/* becomes byte 17 of msg */
-       /* bits 56:49 */        /* not currently using */
+       unsigned int sequence:16;/* message sequence number */
+       /* bits 56:41 */        /* becomes bytes 16-17 of msg */
                                /* Address field (96:57) is never used as an
                                   address (these are address bits 42:3) */
+
        unsigned int rsvd_3:1;  /* must be zero */
        /* bit 57 */
                                /* address bits 27:4 are payload */
-                               /* these 24 bits become bytes 12-14 of msg */
+       /* these next 24  (58-81) bits become bytes 12-14 of msg */
+
+       /* bits 65:58 land in byte 12 */
        unsigned int replied_to:1;/* sent as 0 by the source to byte 12 */
        /* bit 58 */
-
-       unsigned int payload_1a:5;/* not currently used */
-       /* bits 63:59 */
-       unsigned int payload_1b:8;/* not currently used */
-       /* bits 71:64 */
-       unsigned int payload_1c:8;/* not currently used */
-       /* bits 79:72 */
-       unsigned int payload_1d:2;/* not currently used */
+       unsigned int msg_type:3; /* software type of the message*/
+       /* bits 61:59 */
+       unsigned int canceled:1; /* message canceled, resource to be freed*/
+       /* bit 62 */
+       unsigned int payload_1a:1;/* not currently used */
+       /* bit 63 */
+       unsigned int payload_1b:2;/* not currently used */
+       /* bits 65:64 */
+
+       /* bits 73:66 land in byte 13 */
+       unsigned int payload_1ca:6;/* not currently used */
+       /* bits 71:66 */
+       unsigned int payload_1c:2;/* not currently used */
+       /* bits 73:72 */
+
+       /* bits 81:74 land in byte 14 */
+       unsigned int payload_1d:6;/* not currently used */
+       /* bits 79:74 */
+       unsigned int payload_1e:2;/* not currently used */
        /* bits 81:80 */
 
        unsigned int rsvd_4:7;  /* must be zero */
@@ -178,7 +209,7 @@ struct bau_msg_header {
        /* bits 95:90 */
        unsigned int rsvd_6:5;  /* must be zero */
        /* bits 100:96 */
-       unsigned int int_both:1;/* if 1, interrupt both sockets on the blade */
+       unsigned int int_both:1;/* if 1, interrupt both sockets on the uvhub */
        /* bit 101*/
        unsigned int fairness:3;/* usually zero */
        /* bits 104:102 */
@@ -191,13 +222,18 @@ struct bau_msg_header {
        /* bits 127:107 */
 };
 
+/* see msg_type: */
+#define MSG_NOOP 0
+#define MSG_REGULAR 1
+#define MSG_RETRY 2
+
 /*
  * The activation descriptor:
  * The format of the message to send, plus all accompanying control
  * Should be 64 bytes
  */
 struct bau_desc {
-       struct bau_target_nodemask distribution;
+       struct bau_target_uvhubmask distribution;
        /*
         * message template, consisting of header and payload:
         */
@@ -237,19 +273,25 @@ struct bau_payload_queue_entry {
        unsigned short acknowledge_count; /* filled in by destination */
        /* 16 bits, bytes 10-11 */
 
-       unsigned short replied_to:1;    /* sent as 0 by the source */
-       /* 1 bit */
-       unsigned short unused1:7;       /* not currently using */
-       /* 7 bits: byte 12) */
+       /* these next 3 bytes come from bits 58-81 of the message header */
+       unsigned short replied_to:1;    /* sent as 0 by the source */
+       unsigned short msg_type:3;      /* software message type */
+       unsigned short canceled:1;      /* sent as 0 by the source */
+       unsigned short unused1:3;       /* not currently using */
+       /* byte 12 */
 
-       unsigned char unused2[2];       /* not currently using */
-       /* bytes 13-14 */
+       unsigned char unused2a;         /* not currently using */
+       /* byte 13 */
+       unsigned char unused2;          /* not currently using */
+       /* byte 14 */
 
        unsigned char sw_ack_vector;    /* filled in by the hardware */
        /* byte 15 (bits 127:120) */
 
-       unsigned char unused4[3];       /* not currently using bytes 17-19 */
-       /* bytes 17-19 */
+       unsigned short sequence;        /* message sequence number */
+       /* bytes 16-17 */
+       unsigned char unused4[2];       /* not currently using bytes 18-19 */
+       /* bytes 18-19 */
 
        int number_of_cpus;             /* filled in at destination */
        /* 32 bits, bytes 20-23 (aligned) */
@@ -259,63 +301,93 @@ struct bau_payload_queue_entry {
 };
 
 /*
- * one for every slot in the destination payload queue
- */
-struct bau_msg_status {
-       struct bau_local_cpumask seen_by;       /* map of cpu's */
-};
-
-/*
- * one for every slot in the destination software ack resources
- */
-struct bau_sw_ack_status {
-       struct bau_payload_queue_entry *msg;    /* associated message */
-       int watcher;                            /* cpu monitoring, or -1 */
-};
-
-/*
- * one on every node and per-cpu; to locate the software tables
+ * one per-cpu; to locate the software tables
  */
 struct bau_control {
        struct bau_desc *descriptor_base;
-       struct bau_payload_queue_entry *bau_msg_head;
        struct bau_payload_queue_entry *va_queue_first;
        struct bau_payload_queue_entry *va_queue_last;
-       struct bau_msg_status *msg_statuses;
-       int *watching; /* pointer to array */
+       struct bau_payload_queue_entry *bau_msg_head;
+       struct bau_control *uvhub_master;
+       struct bau_control *socket_master;
+       unsigned long timeout_interval;
+       atomic_t active_descriptor_count;
+       int max_concurrent;
+       int max_concurrent_constant;
+       int retry_message_scans;
+       int plugged_tries;
+       int timeout_tries;
+       int ipi_attempts;
+       int conseccompletes;
+       short cpu;
+       short uvhub_cpu;
+       short uvhub;
+       short cpus_in_socket;
+       short cpus_in_uvhub;
+       unsigned short message_number;
+       unsigned short uvhub_quiesce;
+       short socket_acknowledge_count[DEST_Q_SIZE];
+       cycles_t send_message;
+       spinlock_t masks_lock;
+       spinlock_t uvhub_lock;
+       spinlock_t queue_lock;
 };
 
 /*
  * This structure is allocated per_cpu for UV TLB shootdown statistics.
  */
 struct ptc_stats {
-       unsigned long ptc_i;    /* number of IPI-style flushes */
-       unsigned long requestor;        /* number of nodes this cpu sent to */
-       unsigned long requestee;        /* times cpu was remotely requested */
-       unsigned long alltlb;   /* times all tlb's on this cpu were flushed */
-       unsigned long onetlb;   /* times just one tlb on this cpu was flushed */
-       unsigned long s_retry;  /* retries on source side timeouts */
-       unsigned long d_retry;  /* retries on destination side timeouts */
-       unsigned long sflush;   /* cycles spent in uv_flush_tlb_others */
-       unsigned long dflush;   /* cycles spent on destination side */
-       unsigned long retriesok; /* successes on retries */
-       unsigned long nomsg;    /* interrupts with no message */
-       unsigned long multmsg;  /* interrupts with multiple messages */
-       unsigned long ntargeted;/* nodes targeted */
+       /* sender statistics */
+       unsigned long s_giveup; /* number of fall backs to IPI-style flushes */
+       unsigned long s_requestor; /* number of shootdown requests */
+       unsigned long s_stimeout; /* source side timeouts */
+       unsigned long s_dtimeout; /* destination side timeouts */
+       unsigned long s_time; /* time spent in sending side */
+       unsigned long s_retriesok; /* successful retries */
+       unsigned long s_ntargcpu; /* number of cpus targeted */
+       unsigned long s_ntarguvhub; /* number of uvhubs targeted */
+       unsigned long s_ntarguvhub16; /* number of times >= 16 target hubs */
+       unsigned long s_ntarguvhub8; /* number of times >= 8 target hubs */
+       unsigned long s_ntarguvhub4; /* number of times >= 4 target hubs */
+       unsigned long s_ntarguvhub2; /* number of times >= 2 target hubs */
+       unsigned long s_ntarguvhub1; /* number of times == 1 target hub */
+       unsigned long s_resets_plug; /* ipi-style resets from plug state */
+       unsigned long s_resets_timeout; /* ipi-style resets from timeouts */
+       unsigned long s_busy; /* status stayed busy past s/w timer */
+       unsigned long s_throttles; /* waits in throttle */
+       unsigned long s_retry_messages; /* retry broadcasts */
+       /* destination statistics */
+       unsigned long d_alltlb; /* times all tlb's on this cpu were flushed */
+       unsigned long d_onetlb; /* times just one tlb on this cpu was flushed */
+       unsigned long d_multmsg; /* interrupts with multiple messages */
+       unsigned long d_nomsg; /* interrupts with no message */
+       unsigned long d_time; /* time spent on destination side */
+       unsigned long d_requestee; /* number of messages processed */
+       unsigned long d_retries; /* number of retry messages processed */
+       unsigned long d_canceled; /* number of messages canceled by retries */
+       unsigned long d_nocanceled; /* retries that found nothing to cancel */
+       unsigned long d_resets; /* number of ipi-style requests processed */
+       unsigned long d_rcanceled; /* number of messages canceled by resets */
 };
 
-static inline int bau_node_isset(int node, struct bau_target_nodemask *dstp)
+static inline int bau_uvhub_isset(int uvhub, struct bau_target_uvhubmask *dstp)
 {
-       return constant_test_bit(node, &dstp->bits[0]);
+       return constant_test_bit(uvhub, &dstp->bits[0]);
 }
-static inline void bau_node_set(int node, struct bau_target_nodemask *dstp)
+static inline void bau_uvhub_set(int uvhub, struct bau_target_uvhubmask *dstp)
 {
-       __set_bit(node, &dstp->bits[0]);
+       __set_bit(uvhub, &dstp->bits[0]);
 }
-static inline void bau_nodes_clear(struct bau_target_nodemask *dstp, int nbits)
+static inline void bau_uvhubs_clear(struct bau_target_uvhubmask *dstp,
+                                   int nbits)
 {
        bitmap_zero(&dstp->bits[0], nbits);
 }
+static inline int bau_uvhub_weight(struct bau_target_uvhubmask *dstp)
+{
+       return bitmap_weight((unsigned long *)&dstp->bits[0],
+                               UV_DISTRIBUTION_SIZE);
+}
 
 static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits)
 {
@@ -328,4 +400,35 @@ static inline void bau_cpubits_clear(struct bau_local_cpumask *dstp, int nbits)
 extern void uv_bau_message_intr1(void);
 extern void uv_bau_timeout_intr1(void);
 
+struct atomic_short {
+       short counter;
+};
+
+/**
+ * atomic_read_short - read a short atomic variable
+ * @v: pointer of type atomic_short
+ *
+ * Atomically reads the value of @v.
+ */
+static inline int atomic_read_short(const struct atomic_short *v)
+{
+       return v->counter;
+}
+
+/**
+ * atomic_add_short_return - add and return a short int
+ * @i: short value to add
+ * @v: pointer of type atomic_short
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static inline int atomic_add_short_return(short i, struct atomic_short *v)
+{
+       short __i = i;
+       asm volatile(LOCK_PREFIX "xaddw %0, %1"
+                       : "+r" (i), "+m" (v->counter)
+                       : : "memory");
+       return i + __i;
+}
+
 #endif /* _ASM_X86_UV_UV_BAU_H */
index 14cc74b..bf6b88e 100644 (file)
@@ -307,7 +307,7 @@ static inline unsigned long uv_read_global_mmr32(int pnode, unsigned long offset
  * Access Global MMR space using the MMR space located at the top of physical
  * memory.
  */
-static inline unsigned long *uv_global_mmr64_address(int pnode, unsigned long offset)
+static inline volatile void __iomem *uv_global_mmr64_address(int pnode, unsigned long offset)
 {
        return __va(UV_GLOBAL_MMR64_BASE |
                    UV_GLOBAL_MMR64_PNODE_BITS(pnode) | offset);
index 2cae46c..b2f2d2e 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * This file is subject to the terms and conditions of the GNU General Public
  * License.  See the file "COPYING" in the main directory of this archive
 
 #define UV_MMR_ENABLE          (1UL << 63)
 
+/* ========================================================================= */
+/*                          UVH_BAU_DATA_BROADCAST                           */
+/* ========================================================================= */
+#define UVH_BAU_DATA_BROADCAST 0x61688UL
+#define UVH_BAU_DATA_BROADCAST_32 0x0440
+
+#define UVH_BAU_DATA_BROADCAST_ENABLE_SHFT 0
+#define UVH_BAU_DATA_BROADCAST_ENABLE_MASK 0x0000000000000001UL
+
+union uvh_bau_data_broadcast_u {
+    unsigned long      v;
+    struct uvh_bau_data_broadcast_s {
+       unsigned long   enable :  1;  /* RW */
+       unsigned long   rsvd_1_63: 63;  /*    */
+    } s;
+};
+
 /* ========================================================================= */
 /*                           UVH_BAU_DATA_CONFIG                             */
 /* ========================================================================= */
-#define UVH_LB_BAU_MISC_CONTROL 0x320170UL
-#define UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT 15
-#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT 16
-#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD 0x000000000bUL
-/* 1011 timebase 7 (168millisec) * 3 ticks -> 500ms */
 #define UVH_BAU_DATA_CONFIG 0x61680UL
 #define UVH_BAU_DATA_CONFIG_32 0x0438
 
@@ -603,6 +614,68 @@ union uvh_lb_bau_intd_software_acknowledge_u {
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS 0x0000000000320088UL
 #define UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS_32 0x0a70
 
+/* ========================================================================= */
+/*                         UVH_LB_BAU_MISC_CONTROL                           */
+/* ========================================================================= */
+#define UVH_LB_BAU_MISC_CONTROL 0x320170UL
+#define UVH_LB_BAU_MISC_CONTROL_32 0x00a10
+
+#define UVH_LB_BAU_MISC_CONTROL_REJECTION_DELAY_SHFT 0
+#define UVH_LB_BAU_MISC_CONTROL_REJECTION_DELAY_MASK 0x00000000000000ffUL
+#define UVH_LB_BAU_MISC_CONTROL_APIC_MODE_SHFT 8
+#define UVH_LB_BAU_MISC_CONTROL_APIC_MODE_MASK 0x0000000000000100UL
+#define UVH_LB_BAU_MISC_CONTROL_FORCE_BROADCAST_SHFT 9
+#define UVH_LB_BAU_MISC_CONTROL_FORCE_BROADCAST_MASK 0x0000000000000200UL
+#define UVH_LB_BAU_MISC_CONTROL_FORCE_LOCK_NOP_SHFT 10
+#define UVH_LB_BAU_MISC_CONTROL_FORCE_LOCK_NOP_MASK 0x0000000000000400UL
+#define UVH_LB_BAU_MISC_CONTROL_CSI_AGENT_PRESENCE_VECTOR_SHFT 11
+#define UVH_LB_BAU_MISC_CONTROL_CSI_AGENT_PRESENCE_VECTOR_MASK 0x0000000000003800UL
+#define UVH_LB_BAU_MISC_CONTROL_DESCRIPTOR_FETCH_MODE_SHFT 14
+#define UVH_LB_BAU_MISC_CONTROL_DESCRIPTOR_FETCH_MODE_MASK 0x0000000000004000UL
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT 15
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_MASK 0x0000000000008000UL
+#define UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT 16
+#define UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_MASK 0x00000000000f0000UL
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_DUAL_MAPPING_MODE_SHFT 20
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_DUAL_MAPPING_MODE_MASK 0x0000000000100000UL
+#define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_DECODE_ENABLE_SHFT 21
+#define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_DECODE_ENABLE_MASK 0x0000000000200000UL
+#define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_16_BIT_DECODE_SHFT 22
+#define UVH_LB_BAU_MISC_CONTROL_VGA_IO_PORT_16_BIT_DECODE_MASK 0x0000000000400000UL
+#define UVH_LB_BAU_MISC_CONTROL_SUPPRESS_DEST_REGISTRATION_SHFT 23
+#define UVH_LB_BAU_MISC_CONTROL_SUPPRESS_DEST_REGISTRATION_MASK 0x0000000000800000UL
+#define UVH_LB_BAU_MISC_CONTROL_PROGRAMMED_INITIAL_PRIORITY_SHFT 24
+#define UVH_LB_BAU_MISC_CONTROL_PROGRAMMED_INITIAL_PRIORITY_MASK 0x0000000007000000UL
+#define UVH_LB_BAU_MISC_CONTROL_USE_INCOMING_PRIORITY_SHFT 27
+#define UVH_LB_BAU_MISC_CONTROL_USE_INCOMING_PRIORITY_MASK 0x0000000008000000UL
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_PROGRAMMED_INITIAL_PRIORITY_SHFT 28
+#define UVH_LB_BAU_MISC_CONTROL_ENABLE_PROGRAMMED_INITIAL_PRIORITY_MASK 0x0000000010000000UL
+#define UVH_LB_BAU_MISC_CONTROL_FUN_SHFT 48
+#define UVH_LB_BAU_MISC_CONTROL_FUN_MASK 0xffff000000000000UL
+
+union uvh_lb_bau_misc_control_u {
+    unsigned long      v;
+    struct uvh_lb_bau_misc_control_s {
+       unsigned long   rejection_delay                    :  8;  /* RW */
+       unsigned long   apic_mode                          :  1;  /* RW */
+       unsigned long   force_broadcast                    :  1;  /* RW */
+       unsigned long   force_lock_nop                     :  1;  /* RW */
+       unsigned long   csi_agent_presence_vector          :  3;  /* RW */
+       unsigned long   descriptor_fetch_mode              :  1;  /* RW */
+       unsigned long   enable_intd_soft_ack_mode          :  1;  /* RW */
+       unsigned long   intd_soft_ack_timeout_period       :  4;  /* RW */
+       unsigned long   enable_dual_mapping_mode           :  1;  /* RW */
+       unsigned long   vga_io_port_decode_enable          :  1;  /* RW */
+       unsigned long   vga_io_port_16_bit_decode          :  1;  /* RW */
+       unsigned long   suppress_dest_registration         :  1;  /* RW */
+       unsigned long   programmed_initial_priority        :  3;  /* RW */
+       unsigned long   use_incoming_priority              :  1;  /* RW */
+       unsigned long   enable_programmed_initial_priority :  1;  /* RW */
+       unsigned long   rsvd_29_47                         : 19;  /*    */
+       unsigned long   fun                                : 16;  /* RW */
+    } s;
+};
+
 /* ========================================================================= */
 /*                     UVH_LB_BAU_SB_ACTIVATION_CONTROL                      */
 /* ========================================================================= */
@@ -680,334 +753,6 @@ union uvh_lb_bau_sb_descriptor_base_u {
     } s;
 };
 
-/* ========================================================================= */
-/*                      UVH_LB_MCAST_AOERR0_RPT_ENABLE                       */
-/* ========================================================================= */
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE 0x50b20UL
-
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_SHFT 0
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_OBESE_MSG_MASK 0x0000000000000001UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_SHFT 1
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_DATA_SB_ERR_MASK 0x0000000000000002UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_SHFT 2
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_NACK_BUFF_PARITY_MASK 0x0000000000000004UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_SHFT 3
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_TIMEOUT_MASK 0x0000000000000008UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_SHFT 4
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_INACTIVE_REPLY_MASK 0x0000000000000010UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_SHFT 5
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_UPGRADE_ERROR_MASK 0x0000000000000020UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_SHFT 6
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REG_COUNT_UNDERFLOW_MASK 0x0000000000000040UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_SHFT 7
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MCAST_REP_OBESE_MSG_MASK 0x0000000000000080UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_SHFT 8
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_RUNT_MSG_MASK 0x0000000000000100UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_SHFT 9
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_OBESE_MSG_MASK 0x0000000000000200UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_SHFT 10
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REQ_DATA_SB_ERR_MASK 0x0000000000000400UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_SHFT 11
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_RUNT_MSG_MASK 0x0000000000000800UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_SHFT 12
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_OBESE_MSG_MASK 0x0000000000001000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_SHFT 13
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_DATA_SB_ERR_MASK 0x0000000000002000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_SHFT 14
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_REP_COMMAND_ERR_MASK 0x0000000000004000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_SHFT 15
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_UCACHE_PEND_TIMEOUT_MASK 0x0000000000008000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_SHFT 16
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_RUNT_MSG_MASK 0x0000000000010000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_SHFT 17
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_OBESE_MSG_MASK 0x0000000000020000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_SHFT 18
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REQ_DATA_SB_ERR_MASK 0x0000000000040000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_SHFT 19
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_RUNT_MSG_MASK 0x0000000000080000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_SHFT 20
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_OBESE_MSG_MASK 0x0000000000100000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_SHFT 21
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_REP_DATA_SB_ERR_MASK 0x0000000000200000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_SHFT 22
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_AMO_TIMEOUT_MASK 0x0000000000400000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_SHFT 23
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_PUT_TIMEOUT_MASK 0x0000000000800000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_SHFT 24
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_MACC_SPURIOUS_EVENT_MASK 0x0000000001000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_SHFT 25
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IOH_DESTINATION_TABLE_PARITY_MASK 0x0000000002000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_SHFT 26
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_HAD_ERROR_REPLY_MASK 0x0000000004000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_SHFT 27
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_GET_TIMEOUT_MASK 0x0000000008000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_SHFT 28
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_LOCK_MANAGER_HAD_ERROR_REPLY_MASK 0x0000000010000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_SHFT 29
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_HAD_ERROR_REPLY_MASK 0x0000000020000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_SHFT 30
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_PUT_TIMEOUT_MASK 0x0000000040000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_SHFT 31
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SB_ACTIVATION_OVERRUN_MASK 0x0000000080000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_SHFT 32
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_HAD_ERROR_REPLY_MASK 0x0000000100000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_SHFT 33
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_COMPLETED_GB_ACTIVATION_TIMEOUT_MASK 0x0000000200000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_SHFT 34
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_0_PARITY_MASK 0x0000000400000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_SHFT 35
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_DESCRIPTOR_BUFFER_1_PARITY_MASK 0x0000000800000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_SHFT 36
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_SOCKET_DESTINATION_TABLE_PARITY_MASK 0x0000001000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_SHFT 37
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_BAU_REPLY_PAYLOAD_CORRUPTION_MASK 0x0000002000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_SHFT 38
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_IO_PORT_DESTINATION_TABLE_PARITY_MASK 0x0000004000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_SHFT 39
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INTD_SOFT_ACK_TIMEOUT_MASK 0x0000008000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_SHFT 40
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_OBESE_MSG_MASK 0x0000010000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_SHFT 41
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_REP_COMMAND_ERR_MASK 0x0000020000000000UL
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_SHFT 42
-#define UVH_LB_MCAST_AOERR0_RPT_ENABLE_INT_TIMEOUT_MASK 0x0000040000000000UL
-
-union uvh_lb_mcast_aoerr0_rpt_enable_u {
-    unsigned long      v;
-    struct uvh_lb_mcast_aoerr0_rpt_enable_s {
-       unsigned long   mcast_obese_msg                         :  1;  /* RW */
-       unsigned long   mcast_data_sb_err                       :  1;  /* RW */
-       unsigned long   mcast_nack_buff_parity                  :  1;  /* RW */
-       unsigned long   mcast_timeout                           :  1;  /* RW */
-       unsigned long   mcast_inactive_reply                    :  1;  /* RW */
-       unsigned long   mcast_upgrade_error                     :  1;  /* RW */
-       unsigned long   mcast_reg_count_underflow               :  1;  /* RW */
-       unsigned long   mcast_rep_obese_msg                     :  1;  /* RW */
-       unsigned long   ucache_req_runt_msg                     :  1;  /* RW */
-       unsigned long   ucache_req_obese_msg                    :  1;  /* RW */
-       unsigned long   ucache_req_data_sb_err                  :  1;  /* RW */
-       unsigned long   ucache_rep_runt_msg                     :  1;  /* RW */
-       unsigned long   ucache_rep_obese_msg                    :  1;  /* RW */
-       unsigned long   ucache_rep_data_sb_err                  :  1;  /* RW */
-       unsigned long   ucache_rep_command_err                  :  1;  /* RW */
-       unsigned long   ucache_pend_timeout                     :  1;  /* RW */
-       unsigned long   macc_req_runt_msg                       :  1;  /* RW */
-       unsigned long   macc_req_obese_msg                      :  1;  /* RW */
-       unsigned long   macc_req_data_sb_err                    :  1;  /* RW */
-       unsigned long   macc_rep_runt_msg                       :  1;  /* RW */
-       unsigned long   macc_rep_obese_msg                      :  1;  /* RW */
-       unsigned long   macc_rep_data_sb_err                    :  1;  /* RW */
-       unsigned long   macc_amo_timeout                        :  1;  /* RW */
-       unsigned long   macc_put_timeout                        :  1;  /* RW */
-       unsigned long   macc_spurious_event                     :  1;  /* RW */
-       unsigned long   ioh_destination_table_parity            :  1;  /* RW */
-       unsigned long   get_had_error_reply                     :  1;  /* RW */
-       unsigned long   get_timeout                             :  1;  /* RW */
-       unsigned long   lock_manager_had_error_reply            :  1;  /* RW */
-       unsigned long   put_had_error_reply                     :  1;  /* RW */
-       unsigned long   put_timeout                             :  1;  /* RW */
-       unsigned long   sb_activation_overrun                   :  1;  /* RW */
-       unsigned long   completed_gb_activation_had_error_reply :  1;  /* RW */
-       unsigned long   completed_gb_activation_timeout         :  1;  /* RW */
-       unsigned long   descriptor_buffer_0_parity              :  1;  /* RW */
-       unsigned long   descriptor_buffer_1_parity              :  1;  /* RW */
-       unsigned long   socket_destination_table_parity         :  1;  /* RW */
-       unsigned long   bau_reply_payload_corruption            :  1;  /* RW */
-       unsigned long   io_port_destination_table_parity        :  1;  /* RW */
-       unsigned long   intd_soft_ack_timeout                   :  1;  /* RW */
-       unsigned long   int_rep_obese_msg                       :  1;  /* RW */
-       unsigned long   int_rep_command_err                     :  1;  /* RW */
-       unsigned long   int_timeout                             :  1;  /* RW */
-       unsigned long   rsvd_43_63                              : 21;  /*    */
-    } s;
-};
-
-/* ========================================================================= */
-/*                          UVH_LOCAL_INT0_CONFIG                            */
-/* ========================================================================= */
-#define UVH_LOCAL_INT0_CONFIG 0x61000UL
-
-#define UVH_LOCAL_INT0_CONFIG_VECTOR_SHFT 0
-#define UVH_LOCAL_INT0_CONFIG_VECTOR_MASK 0x00000000000000ffUL
-#define UVH_LOCAL_INT0_CONFIG_DM_SHFT 8
-#define UVH_LOCAL_INT0_CONFIG_DM_MASK 0x0000000000000700UL
-#define UVH_LOCAL_INT0_CONFIG_DESTMODE_SHFT 11
-#define UVH_LOCAL_INT0_CONFIG_DESTMODE_MASK 0x0000000000000800UL
-#define UVH_LOCAL_INT0_CONFIG_STATUS_SHFT 12
-#define UVH_LOCAL_INT0_CONFIG_STATUS_MASK 0x0000000000001000UL
-#define UVH_LOCAL_INT0_CONFIG_P_SHFT 13
-#define UVH_LOCAL_INT0_CONFIG_P_MASK 0x0000000000002000UL
-#define UVH_LOCAL_INT0_CONFIG_T_SHFT 15
-#define UVH_LOCAL_INT0_CONFIG_T_MASK 0x0000000000008000UL
-#define UVH_LOCAL_INT0_CONFIG_M_SHFT 16
-#define UVH_LOCAL_INT0_CONFIG_M_MASK 0x0000000000010000UL
-#define UVH_LOCAL_INT0_CONFIG_APIC_ID_SHFT 32
-#define UVH_LOCAL_INT0_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
-
-union uvh_local_int0_config_u {
-    unsigned long      v;
-    struct uvh_local_int0_config_s {
-       unsigned long   vector_  :  8;  /* RW */
-       unsigned long   dm       :  3;  /* RW */
-       unsigned long   destmode :  1;  /* RW */
-       unsigned long   status   :  1;  /* RO */
-       unsigned long   p        :  1;  /* RO */
-       unsigned long   rsvd_14  :  1;  /*    */
-       unsigned long   t        :  1;  /* RO */
-       unsigned long   m        :  1;  /* RW */
-       unsigned long   rsvd_17_31: 15;  /*    */
-       unsigned long   apic_id  : 32;  /* RW */
-    } s;
-};
-
-/* ========================================================================= */
-/*                          UVH_LOCAL_INT0_ENABLE                            */
-/* ========================================================================= */
-#define UVH_LOCAL_INT0_ENABLE 0x65000UL
-
-#define UVH_LOCAL_INT0_ENABLE_LB_HCERR_SHFT 0
-#define UVH_LOCAL_INT0_ENABLE_LB_HCERR_MASK 0x0000000000000001UL
-#define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_SHFT 1
-#define UVH_LOCAL_INT0_ENABLE_GR0_HCERR_MASK 0x0000000000000002UL
-#define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_SHFT 2
-#define UVH_LOCAL_INT0_ENABLE_GR1_HCERR_MASK 0x0000000000000004UL
-#define UVH_LOCAL_INT0_ENABLE_LH_HCERR_SHFT 3
-#define UVH_LOCAL_INT0_ENABLE_LH_HCERR_MASK 0x0000000000000008UL
-#define UVH_LOCAL_INT0_ENABLE_RH_HCERR_SHFT 4
-#define UVH_LOCAL_INT0_ENABLE_RH_HCERR_MASK 0x0000000000000010UL
-#define UVH_LOCAL_INT0_ENABLE_XN_HCERR_SHFT 5
-#define UVH_LOCAL_INT0_ENABLE_XN_HCERR_MASK 0x0000000000000020UL
-#define UVH_LOCAL_INT0_ENABLE_SI_HCERR_SHFT 6
-#define UVH_LOCAL_INT0_ENABLE_SI_HCERR_MASK 0x0000000000000040UL
-#define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_SHFT 7
-#define UVH_LOCAL_INT0_ENABLE_LB_AOERR0_MASK 0x0000000000000080UL
-#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_SHFT 8
-#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR0_MASK 0x0000000000000100UL
-#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_SHFT 9
-#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR0_MASK 0x0000000000000200UL
-#define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_SHFT 10
-#define UVH_LOCAL_INT0_ENABLE_LH_AOERR0_MASK 0x0000000000000400UL
-#define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_SHFT 11
-#define UVH_LOCAL_INT0_ENABLE_RH_AOERR0_MASK 0x0000000000000800UL
-#define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_SHFT 12
-#define UVH_LOCAL_INT0_ENABLE_XN_AOERR0_MASK 0x0000000000001000UL
-#define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_SHFT 13
-#define UVH_LOCAL_INT0_ENABLE_SI_AOERR0_MASK 0x0000000000002000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_SHFT 14
-#define UVH_LOCAL_INT0_ENABLE_LB_AOERR1_MASK 0x0000000000004000UL
-#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_SHFT 15
-#define UVH_LOCAL_INT0_ENABLE_GR0_AOERR1_MASK 0x0000000000008000UL
-#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_SHFT 16
-#define UVH_LOCAL_INT0_ENABLE_GR1_AOERR1_MASK 0x0000000000010000UL
-#define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_SHFT 17
-#define UVH_LOCAL_INT0_ENABLE_LH_AOERR1_MASK 0x0000000000020000UL
-#define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_SHFT 18
-#define UVH_LOCAL_INT0_ENABLE_RH_AOERR1_MASK 0x0000000000040000UL
-#define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_SHFT 19
-#define UVH_LOCAL_INT0_ENABLE_XN_AOERR1_MASK 0x0000000000080000UL
-#define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_SHFT 20
-#define UVH_LOCAL_INT0_ENABLE_SI_AOERR1_MASK 0x0000000000100000UL
-#define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_SHFT 21
-#define UVH_LOCAL_INT0_ENABLE_RH_VPI_INT_MASK 0x0000000000200000UL
-#define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_SHFT 22
-#define UVH_LOCAL_INT0_ENABLE_SYSTEM_SHUTDOWN_INT_MASK 0x0000000000400000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_SHFT 23
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_0_MASK 0x0000000000800000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_SHFT 24
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_1_MASK 0x0000000001000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_SHFT 25
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_2_MASK 0x0000000002000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_SHFT 26
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_3_MASK 0x0000000004000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_SHFT 27
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_4_MASK 0x0000000008000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_SHFT 28
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_5_MASK 0x0000000010000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_SHFT 29
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_6_MASK 0x0000000020000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_SHFT 30
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_7_MASK 0x0000000040000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_SHFT 31
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_8_MASK 0x0000000080000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_SHFT 32
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_9_MASK 0x0000000100000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_SHFT 33
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_10_MASK 0x0000000200000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_SHFT 34
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_11_MASK 0x0000000400000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_SHFT 35
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_12_MASK 0x0000000800000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_SHFT 36
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_13_MASK 0x0000001000000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_SHFT 37
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_14_MASK 0x0000002000000000UL
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_SHFT 38
-#define UVH_LOCAL_INT0_ENABLE_LB_IRQ_INT_15_MASK 0x0000004000000000UL
-#define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_SHFT 39
-#define UVH_LOCAL_INT0_ENABLE_L1_NMI_INT_MASK 0x0000008000000000UL
-#define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_SHFT 40
-#define UVH_LOCAL_INT0_ENABLE_STOP_CLOCK_MASK 0x0000010000000000UL
-#define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_SHFT 41
-#define UVH_LOCAL_INT0_ENABLE_ASIC_TO_L1_MASK 0x0000020000000000UL
-#define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_SHFT 42
-#define UVH_LOCAL_INT0_ENABLE_L1_TO_ASIC_MASK 0x0000040000000000UL
-#define UVH_LOCAL_INT0_ENABLE_LTC_INT_SHFT 43
-#define UVH_LOCAL_INT0_ENABLE_LTC_INT_MASK 0x0000080000000000UL
-#define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_SHFT 44
-#define UVH_LOCAL_INT0_ENABLE_LA_SEQ_TRIGGER_MASK 0x0000100000000000UL
-
-union uvh_local_int0_enable_u {
-    unsigned long      v;
-    struct uvh_local_int0_enable_s {
-       unsigned long   lb_hcerr            :  1;  /* RW */
-       unsigned long   gr0_hcerr           :  1;  /* RW */
-       unsigned long   gr1_hcerr           :  1;  /* RW */
-       unsigned long   lh_hcerr            :  1;  /* RW */
-       unsigned long   rh_hcerr            :  1;  /* RW */
-       unsigned long   xn_hcerr            :  1;  /* RW */
-       unsigned long   si_hcerr            :  1;  /* RW */
-       unsigned long   lb_aoerr0           :  1;  /* RW */
-       unsigned long   gr0_aoerr0          :  1;  /* RW */
-       unsigned long   gr1_aoerr0          :  1;  /* RW */
-       unsigned long   lh_aoerr0           :  1;  /* RW */
-       unsigned long   rh_aoerr0           :  1;  /* RW */
-       unsigned long   xn_aoerr0           :  1;  /* RW */
-       unsigned long   si_aoerr0           :  1;  /* RW */
-       unsigned long   lb_aoerr1           :  1;  /* RW */
-       unsigned long   gr0_aoerr1          :  1;  /* RW */
-       unsigned long   gr1_aoerr1          :  1;  /* RW */
-       unsigned long   lh_aoerr1           :  1;  /* RW */
-       unsigned long   rh_aoerr1           :  1;  /* RW */
-       unsigned long   xn_aoerr1           :  1;  /* RW */
-       unsigned long   si_aoerr1           :  1;  /* RW */
-       unsigned long   rh_vpi_int          :  1;  /* RW */
-       unsigned long   system_shutdown_int :  1;  /* RW */
-       unsigned long   lb_irq_int_0        :  1;  /* RW */
-       unsigned long   lb_irq_int_1        :  1;  /* RW */
-       unsigned long   lb_irq_int_2        :  1;  /* RW */
-       unsigned long   lb_irq_int_3        :  1;  /* RW */
-       unsigned long   lb_irq_int_4        :  1;  /* RW */
-       unsigned long   lb_irq_int_5        :  1;  /* RW */
-       unsigned long   lb_irq_int_6        :  1;  /* RW */
-       unsigned long   lb_irq_int_7        :  1;  /* RW */
-       unsigned long   lb_irq_int_8        :  1;  /* RW */
-       unsigned long   lb_irq_int_9        :  1;  /* RW */
-       unsigned long   lb_irq_int_10       :  1;  /* RW */
-       unsigned long   lb_irq_int_11       :  1;  /* RW */
-       unsigned long   lb_irq_int_12       :  1;  /* RW */
-       unsigned long   lb_irq_int_13       :  1;  /* RW */
-       unsigned long   lb_irq_int_14       :  1;  /* RW */
-       unsigned long   lb_irq_int_15       :  1;  /* RW */
-       unsigned long   l1_nmi_int          :  1;  /* RW */
-       unsigned long   stop_clock          :  1;  /* RW */
-       unsigned long   asic_to_l1          :  1;  /* RW */
-       unsigned long   l1_to_asic          :  1;  /* RW */
-       unsigned long   ltc_int             :  1;  /* RW */
-       unsigned long   la_seq_trigger      :  1;  /* RW */
-       unsigned long   rsvd_45_63          : 19;  /*    */
-    } s;
-};
-
 /* ========================================================================= */
 /*                               UVH_NODE_ID                                 */
 /* ========================================================================= */
@@ -1111,26 +856,6 @@ union uvh_rh_gam_alias210_redirect_config_2_mmr_u {
     } s;
 };
 
-/* ========================================================================= */
-/*                    UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR                      */
-/* ========================================================================= */
-#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR 0x1600020UL
-
-#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_SHFT 26
-#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_BASE_MASK 0x00003ffffc000000UL
-#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_SHFT 63
-#define UVH_RH_GAM_CFG_OVERLAY_CONFIG_MMR_ENABLE_MASK 0x8000000000000000UL
-
-union uvh_rh_gam_cfg_overlay_config_mmr_u {
-    unsigned long      v;
-    struct uvh_rh_gam_cfg_overlay_config_mmr_s {
-       unsigned long   rsvd_0_25: 26;  /*    */
-       unsigned long   base   : 20;  /* RW */
-       unsigned long   rsvd_46_62: 17;  /*    */
-       unsigned long   enable :  1;  /* RW */
-    } s;
-};
-
 /* ========================================================================= */
 /*                    UVH_RH_GAM_GRU_OVERLAY_CONFIG_MMR                      */
 /* ========================================================================= */
@@ -1262,101 +987,6 @@ union uvh_rtc1_int_config_u {
     } s;
 };
 
-/* ========================================================================= */
-/*                           UVH_RTC2_INT_CONFIG                             */
-/* ========================================================================= */
-#define UVH_RTC2_INT_CONFIG 0x61600UL
-
-#define UVH_RTC2_INT_CONFIG_VECTOR_SHFT 0
-#define UVH_RTC2_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
-#define UVH_RTC2_INT_CONFIG_DM_SHFT 8
-#define UVH_RTC2_INT_CONFIG_DM_MASK 0x0000000000000700UL
-#define UVH_RTC2_INT_CONFIG_DESTMODE_SHFT 11
-#define UVH_RTC2_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
-#define UVH_RTC2_INT_CONFIG_STATUS_SHFT 12
-#define UVH_RTC2_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
-#define UVH_RTC2_INT_CONFIG_P_SHFT 13
-#define UVH_RTC2_INT_CONFIG_P_MASK 0x0000000000002000UL
-#define UVH_RTC2_INT_CONFIG_T_SHFT 15
-#define UVH_RTC2_INT_CONFIG_T_MASK 0x0000000000008000UL
-#define UVH_RTC2_INT_CONFIG_M_SHFT 16
-#define UVH_RTC2_INT_CONFIG_M_MASK 0x0000000000010000UL
-#define UVH_RTC2_INT_CONFIG_APIC_ID_SHFT 32
-#define UVH_RTC2_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
-
-union uvh_rtc2_int_config_u {
-    unsigned long      v;
-    struct uvh_rtc2_int_config_s {
-       unsigned long   vector_  :  8;  /* RW */
-       unsigned long   dm       :  3;  /* RW */
-       unsigned long   destmode :  1;  /* RW */
-       unsigned long   status   :  1;  /* RO */
-       unsigned long   p        :  1;  /* RO */
-       unsigned long   rsvd_14  :  1;  /*    */
-       unsigned long   t        :  1;  /* RO */
-       unsigned long   m        :  1;  /* RW */
-       unsigned long   rsvd_17_31: 15;  /*    */
-       unsigned long   apic_id  : 32;  /* RW */
-    } s;
-};
-
-/* ========================================================================= */
-/*                           UVH_RTC3_INT_CONFIG                             */
-/* ========================================================================= */
-#define UVH_RTC3_INT_CONFIG 0x61640UL
-
-#define UVH_RTC3_INT_CONFIG_VECTOR_SHFT 0
-#define UVH_RTC3_INT_CONFIG_VECTOR_MASK 0x00000000000000ffUL
-#define UVH_RTC3_INT_CONFIG_DM_SHFT 8
-#define UVH_RTC3_INT_CONFIG_DM_MASK 0x0000000000000700UL
-#define UVH_RTC3_INT_CONFIG_DESTMODE_SHFT 11
-#define UVH_RTC3_INT_CONFIG_DESTMODE_MASK 0x0000000000000800UL
-#define UVH_RTC3_INT_CONFIG_STATUS_SHFT 12
-#define UVH_RTC3_INT_CONFIG_STATUS_MASK 0x0000000000001000UL
-#define UVH_RTC3_INT_CONFIG_P_SHFT 13
-#define UVH_RTC3_INT_CONFIG_P_MASK 0x0000000000002000UL
-#define UVH_RTC3_INT_CONFIG_T_SHFT 15
-#define UVH_RTC3_INT_CONFIG_T_MASK 0x0000000000008000UL
-#define UVH_RTC3_INT_CONFIG_M_SHFT 16
-#define UVH_RTC3_INT_CONFIG_M_MASK 0x0000000000010000UL
-#define UVH_RTC3_INT_CONFIG_APIC_ID_SHFT 32
-#define UVH_RTC3_INT_CONFIG_APIC_ID_MASK 0xffffffff00000000UL
-
-union uvh_rtc3_int_config_u {
-    unsigned long      v;
-    struct uvh_rtc3_int_config_s {
-       unsigned long   vector_  :  8;  /* RW */
-       unsigned long   dm       :  3;  /* RW */
-       unsigned long   destmode :  1;  /* RW */
-       unsigned long   status   :  1;  /* RO */
-       unsigned long   p        :  1;  /* RO */
-       unsigned long   rsvd_14  :  1;  /*    */
-       unsigned long   t        :  1;  /* RO */
-       unsigned long   m        :  1;  /* RW */
-       unsigned long   rsvd_17_31: 15;  /*    */
-       unsigned long   apic_id  : 32;  /* RW */
-    } s;
-};
-
-/* ========================================================================= */
-/*                            UVH_RTC_INC_RATIO                              */
-/* ========================================================================= */
-#define UVH_RTC_INC_RATIO 0x350000UL
-
-#define UVH_RTC_INC_RATIO_FRACTION_SHFT 0
-#define UVH_RTC_INC_RATIO_FRACTION_MASK 0x00000000000fffffUL
-#define UVH_RTC_INC_RATIO_RATIO_SHFT 20
-#define UVH_RTC_INC_RATIO_RATIO_MASK 0x0000000000700000UL
-
-union uvh_rtc_inc_ratio_u {
-    unsigned long      v;
-    struct uvh_rtc_inc_ratio_s {
-       unsigned long   fraction : 20;  /* RW */
-       unsigned long   ratio    :  3;  /* RW */
-       unsigned long   rsvd_23_63: 41;  /*    */
-    } s;
-};
-
 /* ========================================================================= */
 /*                          UVH_SI_ADDR_MAP_CONFIG                           */
 /* ========================================================================= */
diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h
deleted file mode 100644 (file)
index e49ed6d..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Copyright (C) 2008, VMware, 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 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, GOOD TITLE or
- * NON INFRINGEMENT.  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-#ifndef ASM_X86__VMWARE_H
-#define ASM_X86__VMWARE_H
-
-extern void vmware_platform_setup(void);
-extern int vmware_platform(void);
-extern void vmware_set_feature_bits(struct cpuinfo_x86 *c);
-
-#endif
index ddc04cc..2c4390c 100644 (file)
@@ -37,8 +37,9 @@ extern int check_for_xstate(struct i387_fxsave_struct __user *buf,
                            void __user *fpstate,
                            struct _fpx_sw_bytes *sw);
 
-static inline int xrstor_checking(struct xsave_struct *fx)
+static inline int fpu_xrstor_checking(struct fpu *fpu)
 {
+       struct xsave_struct *fx = &fpu->state->xsave;
        int err;
 
        asm volatile("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
@@ -110,12 +111,12 @@ static inline void xrstor_state(struct xsave_struct *fx, u64 mask)
                     :   "memory");
 }
 
-static inline void xsave(struct task_struct *tsk)
+static inline void fpu_xsave(struct fpu *fpu)
 {
        /* This, however, we can work around by forcing the compiler to select
           an addressing mode that doesn't require extended registers. */
        __asm__ __volatile__(".byte " REX_PREFIX "0x0f,0xae,0x27"
-                            : : "D" (&(tsk->thread.xstate->xsave)),
+                            : : "D" (&(fpu->state->xsave)),
                                 "a" (-1), "d"(-1) : "memory");
 }
 #endif
index 4c58352..e77b220 100644 (file)
@@ -47,8 +47,6 @@ obj-$(CONFIG_X86_TRAMPOLINE)  += trampoline.o
 obj-y                          += process.o
 obj-y                          += i387.o xsave.o
 obj-y                          += ptrace.o
-obj-$(CONFIG_X86_DS)           += ds.o
-obj-$(CONFIG_X86_DS_SELFTEST)          += ds_selftest.o
 obj-$(CONFIG_X86_32)           += tls.o
 obj-$(CONFIG_IA32_EMULATION)   += tls.o
 obj-y                          += step.o
index cd40aba..488be46 100644 (file)
@@ -93,6 +93,53 @@ static u64 acpi_lapic_addr __initdata = APIC_DEFAULT_PHYS_BASE;
 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_PIC;
 
 
+/*
+ * ISA irqs by default are the first 16 gsis but can be
+ * any gsi as specified by an interrupt source override.
+ */
+static u32 isa_irq_to_gsi[NR_IRQS_LEGACY] __read_mostly = {
+       0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
+};
+
+static unsigned int gsi_to_irq(unsigned int gsi)
+{
+       unsigned int irq = gsi + NR_IRQS_LEGACY;
+       unsigned int i;
+
+       for (i = 0; i < NR_IRQS_LEGACY; i++) {
+               if (isa_irq_to_gsi[i] == gsi) {
+                       return i;
+               }
+       }
+
+       /* Provide an identity mapping of gsi == irq
+        * except on truly weird platforms that have
+        * non isa irqs in the first 16 gsis.
+        */
+       if (gsi >= NR_IRQS_LEGACY)
+               irq = gsi;
+       else
+               irq = gsi_end + 1 + gsi;
+
+       return irq;
+}
+
+static u32 irq_to_gsi(int irq)
+{
+       unsigned int gsi;
+
+       if (irq < NR_IRQS_LEGACY)
+               gsi = isa_irq_to_gsi[irq];
+       else if (irq <= gsi_end)
+               gsi = irq;
+       else if (irq <= (gsi_end + NR_IRQS_LEGACY))
+               gsi = irq - gsi_end;
+       else
+               gsi = 0xffffffff;
+
+       return gsi;
+}
+
 /*
  * Temporarily use the virtual area starting from FIX_IO_APIC_BASE_END,
  * to map the target physical address. The problem is that set_fixmap()
@@ -313,7 +360,7 @@ acpi_parse_ioapic(struct acpi_subtable_header * header, const unsigned long end)
 /*
  * Parse Interrupt Source Override for the ACPI SCI
  */
-static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
+static void __init acpi_sci_ioapic_setup(u8 bus_irq, u16 polarity, u16 trigger, u32 gsi)
 {
        if (trigger == 0)       /* compatible SCI trigger is level */
                trigger = 3;
@@ -333,7 +380,7 @@ static void __init acpi_sci_ioapic_setup(u32 gsi, u16 polarity, u16 trigger)
         * If GSI is < 16, this will update its flags,
         * else it will create a new mp_irqs[] entry.
         */
-       mp_override_legacy_irq(gsi, polarity, trigger, gsi);
+       mp_override_legacy_irq(bus_irq, polarity, trigger, gsi);
 
        /*
         * stash over-ride to indicate we've been here
@@ -357,9 +404,10 @@ acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
        acpi_table_print_madt_entry(header);
 
        if (intsrc->source_irq == acpi_gbl_FADT.sci_interrupt) {
-               acpi_sci_ioapic_setup(intsrc->global_irq,
+               acpi_sci_ioapic_setup(intsrc->source_irq,
                                      intsrc->inti_flags & ACPI_MADT_POLARITY_MASK,
-                                     (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2);
+                                     (intsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) >> 2,
+                                     intsrc->global_irq);
                return 0;
        }
 
@@ -448,7 +496,7 @@ void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
 
 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
 {
-       *irq = gsi;
+       *irq = gsi_to_irq(gsi);
 
 #ifdef CONFIG_X86_IO_APIC
        if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC)
@@ -458,6 +506,14 @@ int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
        return 0;
 }
 
+int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
+{
+       if (isa_irq >= 16)
+               return -1;
+       *gsi = irq_to_gsi(isa_irq);
+       return 0;
+}
+
 /*
  * success: return IRQ number (>=0)
  * failure: return < 0
@@ -482,7 +538,7 @@ int acpi_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
                plat_gsi = mp_register_gsi(dev, gsi, trigger, polarity);
        }
 #endif
-       irq = plat_gsi;
+       irq = gsi_to_irq(plat_gsi);
 
        return irq;
 }
@@ -867,29 +923,6 @@ static int __init acpi_parse_madt_lapic_entries(void)
 extern int es7000_plat;
 #endif
 
-int __init acpi_probe_gsi(void)
-{
-       int idx;
-       int gsi;
-       int max_gsi = 0;
-
-       if (acpi_disabled)
-               return 0;
-
-       if (!acpi_ioapic)
-               return 0;
-
-       max_gsi = 0;
-       for (idx = 0; idx < nr_ioapics; idx++) {
-               gsi = mp_gsi_routing[idx].gsi_end;
-
-               if (gsi > max_gsi)
-                       max_gsi = gsi;
-       }
-
-       return max_gsi + 1;
-}
-
 static void assign_to_mp_irq(struct mpc_intsrc *m,
                                    struct mpc_intsrc *mp_irq)
 {
@@ -947,13 +980,13 @@ void __init mp_override_legacy_irq(u8 bus_irq, u8 polarity, u8 trigger, u32 gsi)
        mp_irq.dstirq = pin;    /* INTIN# */
 
        save_mp_irq(&mp_irq);
+
+       isa_irq_to_gsi[bus_irq] = gsi;
 }
 
 void __init mp_config_acpi_legacy_irqs(void)
 {
        int i;
-       int ioapic;
-       unsigned int dstapic;
        struct mpc_intsrc mp_irq;
 
 #if defined (CONFIG_MCA) || defined (CONFIG_EISA)
@@ -973,20 +1006,28 @@ void __init mp_config_acpi_legacy_irqs(void)
                return;
 #endif
 
-       /*
-        * Locate the IOAPIC that manages the ISA IRQs (0-15).
-        */
-       ioapic = mp_find_ioapic(0);
-       if (ioapic < 0)
-               return;
-       dstapic = mp_ioapics[ioapic].apicid;
-
        /*
         * Use the default configuration for the IRQs 0-15.  Unless
         * overridden by (MADT) interrupt source override entries.
         */
        for (i = 0; i < 16; i++) {
+               int ioapic, pin;
+               unsigned int dstapic;
                int idx;
+               u32 gsi;
+
+               /* Locate the gsi that irq i maps to. */
+               if (acpi_isa_irq_to_gsi(i, &gsi))
+                       continue;
+
+               /*
+                * Locate the IOAPIC that manages the ISA IRQ.
+                */
+               ioapic = mp_find_ioapic(gsi);
+               if (ioapic < 0)
+                       continue;
+               pin = mp_find_ioapic_pin(ioapic, gsi);
+               dstapic = mp_ioapics[ioapic].apicid;
 
                for (idx = 0; idx < mp_irq_entries; idx++) {
                        struct mpc_intsrc *irq = mp_irqs + idx;
@@ -996,7 +1037,7 @@ void __init mp_config_acpi_legacy_irqs(void)
                                break;
 
                        /* Do we already have a mapping for this IOAPIC pin */
-                       if (irq->dstapic == dstapic && irq->dstirq == i)
+                       if (irq->dstapic == dstapic && irq->dstirq == pin)
                                break;
                }
 
@@ -1011,7 +1052,7 @@ void __init mp_config_acpi_legacy_irqs(void)
                mp_irq.dstapic = dstapic;
                mp_irq.irqtype = mp_INT;
                mp_irq.srcbusirq = i; /* Identity mapped */
-               mp_irq.dstirq = i;
+               mp_irq.dstirq = pin;
 
                save_mp_irq(&mp_irq);
        }
@@ -1076,11 +1117,6 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
 
        ioapic_pin = mp_find_ioapic_pin(ioapic, gsi);
 
-#ifdef CONFIG_X86_32
-       if (ioapic_renumber_irq)
-               gsi = ioapic_renumber_irq(ioapic, gsi);
-#endif
-
        if (ioapic_pin > MP_MAX_IOAPIC_PIN) {
                printk(KERN_ERR "Invalid reference to IOAPIC pin "
                       "%d-%d\n", mp_ioapics[ioapic].apicid,
@@ -1094,7 +1130,7 @@ int mp_register_gsi(struct device *dev, u32 gsi, int trigger, int polarity)
        set_io_apic_irq_attr(&irq_attr, ioapic, ioapic_pin,
                             trigger == ACPI_EDGE_SENSITIVE ? 0 : 1,
                             polarity == ACPI_ACTIVE_HIGH ? 0 : 1);
-       io_apic_set_pci_routing(dev, gsi, &irq_attr);
+       io_apic_set_pci_routing(dev, gsi_to_irq(gsi), &irq_attr);
 
        return gsi;
 }
@@ -1154,7 +1190,8 @@ static int __init acpi_parse_madt_ioapic_entries(void)
         * pretend we got one so we can set the SCI flags.
         */
        if (!acpi_sci_override_gsi)
-               acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0);
+               acpi_sci_ioapic_setup(acpi_gbl_FADT.sci_interrupt, 0, 0,
+                                     acpi_gbl_FADT.sci_interrupt);
 
        /* Fill in identity legacy mappings where no override */
        mp_config_acpi_legacy_irqs();
@@ -1576,6 +1613,10 @@ static int __init parse_acpi(char *arg)
        /* "acpi=noirq" disables ACPI interrupt routing */
        else if (strcmp(arg, "noirq") == 0) {
                acpi_noirq_set();
+       }
+       /* "acpi=copy_dsdt" copys DSDT */
+       else if (strcmp(arg, "copy_dsdt") == 0) {
+               acpi_gbl_copy_dsdt_locally = 1;
        } else {
                /* Core will printk when we return error. */
                return -EINVAL;
index 1a160d5..7023773 100644 (file)
@@ -194,7 +194,7 @@ static void __init_or_module add_nops(void *insns, unsigned int len)
 }
 
 extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
-extern u8 *__smp_locks[], *__smp_locks_end[];
+extern s32 __smp_locks[], __smp_locks_end[];
 static void *text_poke_early(void *addr, const void *opcode, size_t len);
 
 /* Replace instructions with better alternatives for this CPU type.
@@ -235,37 +235,41 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
 
 #ifdef CONFIG_SMP
 
-static void alternatives_smp_lock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_lock(const s32 *start, const s32 *end,
+                                 u8 *text, u8 *text_end)
 {
-       u8 **ptr;
+       const s32 *poff;
 
        mutex_lock(&text_mutex);
-       for (ptr = start; ptr < end; ptr++) {
-               if (*ptr < text)
-                       continue;
-               if (*ptr > text_end)
+       for (poff = start; poff < end; poff++) {
+               u8 *ptr = (u8 *)poff + *poff;
+
+               if (!*poff || ptr < text || ptr >= text_end)
                        continue;
                /* turn DS segment override prefix into lock prefix */
-               text_poke(*ptr, ((unsigned char []){0xf0}), 1);
+               if (*ptr == 0x3e)
+                       text_poke(ptr, ((unsigned char []){0xf0}), 1);
        };
        mutex_unlock(&text_mutex);
 }
 
-static void alternatives_smp_unlock(u8 **start, u8 **end, u8 *text, u8 *text_end)
+static void alternatives_smp_unlock(const s32 *start, const s32 *end,
+                                   u8 *text, u8 *text_end)
 {
-       u8 **ptr;
+       const s32 *poff;
 
        if (noreplace_smp)
                return;
 
        mutex_lock(&text_mutex);
-       for (ptr = start; ptr < end; ptr++) {
-               if (*ptr < text)
-                       continue;
-               if (*ptr > text_end)
+       for (poff = start; poff < end; poff++) {
+               u8 *ptr = (u8 *)poff + *poff;
+
+               if (!*poff || ptr < text || ptr >= text_end)
                        continue;
                /* turn lock prefix into DS segment override prefix */
-               text_poke(*ptr, ((unsigned char []){0x3E}), 1);
+               if (*ptr == 0xf0)
+                       text_poke(ptr, ((unsigned char []){0x3E}), 1);
        };
        mutex_unlock(&text_mutex);
 }
@@ -276,8 +280,8 @@ struct smp_alt_module {
        char            *name;
 
        /* ptrs to lock prefixes */
-       u8              **locks;
-       u8              **locks_end;
+       const s32       *locks;
+       const s32       *locks_end;
 
        /* .text segment, needed to avoid patching init code ;) */
        u8              *text;
@@ -398,16 +402,19 @@ void alternatives_smp_switch(int smp)
 int alternatives_text_reserved(void *start, void *end)
 {
        struct smp_alt_module *mod;
-       u8 **ptr;
+       const s32 *poff;
        u8 *text_start = start;
        u8 *text_end = end;
 
        list_for_each_entry(mod, &smp_alt_modules, next) {
                if (mod->text > text_end || mod->text_end < text_start)
                        continue;
-               for (ptr = mod->locks; ptr < mod->locks_end; ptr++)
-                       if (text_start <= *ptr && text_end >= *ptr)
+               for (poff = mod->locks; poff < mod->locks_end; poff++) {
+                       const u8 *ptr = (const u8 *)poff + *poff;
+
+                       if (text_start <= ptr && text_end > ptr)
                                return 1;
+               }
        }
 
        return 0;
index f854d89..fa5a147 100644 (file)
@@ -731,18 +731,22 @@ static bool increase_address_space(struct protection_domain *domain,
 
 static u64 *alloc_pte(struct protection_domain *domain,
                      unsigned long address,
-                     int end_lvl,
+                     unsigned long page_size,
                      u64 **pte_page,
                      gfp_t gfp)
 {
+       int level, end_lvl;
        u64 *pte, *page;
-       int level;
+
+       BUG_ON(!is_power_of_2(page_size));
 
        while (address > PM_LEVEL_SIZE(domain->mode))
                increase_address_space(domain, gfp);
 
-       level =  domain->mode - 1;
-       pte   = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
+       level   = domain->mode - 1;
+       pte     = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
+       address = PAGE_SIZE_ALIGN(address, page_size);
+       end_lvl = PAGE_SIZE_LEVEL(page_size);
 
        while (level > end_lvl) {
                if (!IOMMU_PTE_PRESENT(*pte)) {
@@ -752,6 +756,10 @@ static u64 *alloc_pte(struct protection_domain *domain,
                        *pte = PM_LEVEL_PDE(level, virt_to_phys(page));
                }
 
+               /* No level skipping support yet */
+               if (PM_PTE_LEVEL(*pte) != level)
+                       return NULL;
+
                level -= 1;
 
                pte = IOMMU_PTE_PAGE(*pte);
@@ -769,28 +777,47 @@ static u64 *alloc_pte(struct protection_domain *domain,
  * This function checks if there is a PTE for a given dma address. If
  * there is one, it returns the pointer to it.
  */
-static u64 *fetch_pte(struct protection_domain *domain,
-                     unsigned long address, int map_size)
+static u64 *fetch_pte(struct protection_domain *domain, unsigned long address)
 {
        int level;
        u64 *pte;
 
-       level =  domain->mode - 1;
-       pte   = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
+       if (address > PM_LEVEL_SIZE(domain->mode))
+               return NULL;
+
+       level   =  domain->mode - 1;
+       pte     = &domain->pt_root[PM_LEVEL_INDEX(level, address)];
 
-       while (level > map_size) {
+       while (level > 0) {
+
+               /* Not Present */
                if (!IOMMU_PTE_PRESENT(*pte))
                        return NULL;
 
+               /* Large PTE */
+               if (PM_PTE_LEVEL(*pte) == 0x07) {
+                       unsigned long pte_mask, __pte;
+
+                       /*
+                        * If we have a series of large PTEs, make
+                        * sure to return a pointer to the first one.
+                        */
+                       pte_mask = PTE_PAGE_SIZE(*pte);
+                       pte_mask = ~((PAGE_SIZE_PTE_COUNT(pte_mask) << 3) - 1);
+                       __pte    = ((unsigned long)pte) & pte_mask;
+
+                       return (u64 *)__pte;
+               }
+
+               /* No level skipping support yet */
+               if (PM_PTE_LEVEL(*pte) != level)
+                       return NULL;
+
                level -= 1;
 
+               /* Walk to the next level */
                pte = IOMMU_PTE_PAGE(*pte);
                pte = &pte[PM_LEVEL_INDEX(level, address)];
-
-               if ((PM_PTE_LEVEL(*pte) == 0) && level != map_size) {
-                       pte = NULL;
-                       break;
-               }
        }
 
        return pte;
@@ -807,44 +834,84 @@ static int iommu_map_page(struct protection_domain *dom,
                          unsigned long bus_addr,
                          unsigned long phys_addr,
                          int prot,
-                         int map_size)
+                         unsigned long page_size)
 {
        u64 __pte, *pte;
-
-       bus_addr  = PAGE_ALIGN(bus_addr);
-       phys_addr = PAGE_ALIGN(phys_addr);
-
-       BUG_ON(!PM_ALIGNED(map_size, bus_addr));
-       BUG_ON(!PM_ALIGNED(map_size, phys_addr));
+       int i, count;
 
        if (!(prot & IOMMU_PROT_MASK))
                return -EINVAL;
 
-       pte = alloc_pte(dom, bus_addr, map_size, NULL, GFP_KERNEL);
+       bus_addr  = PAGE_ALIGN(bus_addr);
+       phys_addr = PAGE_ALIGN(phys_addr);
+       count     = PAGE_SIZE_PTE_COUNT(page_size);
+       pte       = alloc_pte(dom, bus_addr, page_size, NULL, GFP_KERNEL);
+
+       for (i = 0; i < count; ++i)
+               if (IOMMU_PTE_PRESENT(pte[i]))
+                       return -EBUSY;
 
-       if (IOMMU_PTE_PRESENT(*pte))
-               return -EBUSY;
+       if (page_size > PAGE_SIZE) {
+               __pte = PAGE_SIZE_PTE(phys_addr, page_size);
+               __pte |= PM_LEVEL_ENC(7) | IOMMU_PTE_P | IOMMU_PTE_FC;
+       } else
+               __pte = phys_addr | IOMMU_PTE_P | IOMMU_PTE_FC;
 
-       __pte = phys_addr | IOMMU_PTE_P;
        if (prot & IOMMU_PROT_IR)
                __pte |= IOMMU_PTE_IR;
        if (prot & IOMMU_PROT_IW)
                __pte |= IOMMU_PTE_IW;
 
-       *pte = __pte;
+       for (i = 0; i < count; ++i)
+               pte[i] = __pte;
 
        update_domain(dom);
 
        return 0;
 }
 
-static void iommu_unmap_page(struct protection_domain *dom,
-                            unsigned long bus_addr, int map_size)
+static unsigned long iommu_unmap_page(struct protection_domain *dom,
+                                     unsigned long bus_addr,
+                                     unsigned long page_size)
 {
-       u64 *pte = fetch_pte(dom, bus_addr, map_size);
+       unsigned long long unmap_size, unmapped;
+       u64 *pte;
+
+       BUG_ON(!is_power_of_2(page_size));
+
+       unmapped = 0;
 
-       if (pte)
-               *pte = 0;
+       while (unmapped < page_size) {
+
+               pte = fetch_pte(dom, bus_addr);
+
+               if (!pte) {
+                       /*
+                        * No PTE for this address
+                        * move forward in 4kb steps
+                        */
+                       unmap_size = PAGE_SIZE;
+               } else if (PM_PTE_LEVEL(*pte) == 0) {
+                       /* 4kb PTE found for this address */
+                       unmap_size = PAGE_SIZE;
+                       *pte       = 0ULL;
+               } else {
+                       int count, i;
+
+                       /* Large PTE found which maps this address */
+                       unmap_size = PTE_PAGE_SIZE(*pte);
+                       count      = PAGE_SIZE_PTE_COUNT(unmap_size);
+                       for (i = 0; i < count; i++)
+                               pte[i] = 0ULL;
+               }
+
+               bus_addr  = (bus_addr & ~(unmap_size - 1)) + unmap_size;
+               unmapped += unmap_size;
+       }
+
+       BUG_ON(!is_power_of_2(unmapped));
+
+       return unmapped;
 }
 
 /*
@@ -878,7 +945,7 @@ static int dma_ops_unity_map(struct dma_ops_domain *dma_dom,
        for (addr = e->address_start; addr < e->address_end;
             addr += PAGE_SIZE) {
                ret = iommu_map_page(&dma_dom->domain, addr, addr, e->prot,
-                                    PM_MAP_4k);
+                                    PAGE_SIZE);
                if (ret)
                        return ret;
                /*
@@ -1006,7 +1073,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
                u64 *pte, *pte_page;
 
                for (i = 0; i < num_ptes; ++i) {
-                       pte = alloc_pte(&dma_dom->domain, address, PM_MAP_4k,
+                       pte = alloc_pte(&dma_dom->domain, address, PAGE_SIZE,
                                        &pte_page, gfp);
                        if (!pte)
                                goto out_free;
@@ -1042,7 +1109,7 @@ static int alloc_new_range(struct dma_ops_domain *dma_dom,
        for (i = dma_dom->aperture[index]->offset;
             i < dma_dom->aperture_size;
             i += PAGE_SIZE) {
-               u64 *pte = fetch_pte(&dma_dom->domain, i, PM_MAP_4k);
+               u64 *pte = fetch_pte(&dma_dom->domain, i);
                if (!pte || !IOMMU_PTE_PRESENT(*pte))
                        continue;
 
@@ -1712,7 +1779,7 @@ static u64* dma_ops_get_pte(struct dma_ops_domain *dom,
 
        pte = aperture->pte_pages[APERTURE_PAGE_INDEX(address)];
        if (!pte) {
-               pte = alloc_pte(&dom->domain, address, PM_MAP_4k, &pte_page,
+               pte = alloc_pte(&dom->domain, address, PAGE_SIZE, &pte_page,
                                GFP_ATOMIC);
                aperture->pte_pages[APERTURE_PAGE_INDEX(address)] = pte_page;
        } else
@@ -2439,12 +2506,11 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,
        return ret;
 }
 
-static int amd_iommu_map_range(struct iommu_domain *dom,
-                              unsigned long iova, phys_addr_t paddr,
-                              size_t size, int iommu_prot)
+static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
+                        phys_addr_t paddr, int gfp_order, int iommu_prot)
 {
+       unsigned long page_size = 0x1000UL << gfp_order;
        struct protection_domain *domain = dom->priv;
-       unsigned long i,  npages = iommu_num_pages(paddr, size, PAGE_SIZE);
        int prot = 0;
        int ret;
 
@@ -2453,61 +2519,50 @@ static int amd_iommu_map_range(struct iommu_domain *dom,
        if (iommu_prot & IOMMU_WRITE)
                prot |= IOMMU_PROT_IW;
 
-       iova  &= PAGE_MASK;
-       paddr &= PAGE_MASK;
-
        mutex_lock(&domain->api_lock);
-
-       for (i = 0; i < npages; ++i) {
-               ret = iommu_map_page(domain, iova, paddr, prot, PM_MAP_4k);
-               if (ret)
-                       return ret;
-
-               iova  += PAGE_SIZE;
-               paddr += PAGE_SIZE;
-       }
-
+       ret = iommu_map_page(domain, iova, paddr, prot, page_size);
        mutex_unlock(&domain->api_lock);
 
-       return 0;
+       return ret;
 }
 
-static void amd_iommu_unmap_range(struct iommu_domain *dom,
-                                 unsigned long iova, size_t size)
+static int amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
+                          int gfp_order)
 {
-
        struct protection_domain *domain = dom->priv;
-       unsigned long i,  npages = iommu_num_pages(iova, size, PAGE_SIZE);
+       unsigned long page_size, unmap_size;
 
-       iova  &= PAGE_MASK;
+       page_size  = 0x1000UL << gfp_order;
 
        mutex_lock(&domain->api_lock);
-
-       for (i = 0; i < npages; ++i) {
-               iommu_unmap_page(domain, iova, PM_MAP_4k);
-               iova  += PAGE_SIZE;
-       }
+       unmap_size = iommu_unmap_page(domain, iova, page_size);
+       mutex_unlock(&domain->api_lock);
 
        iommu_flush_tlb_pde(domain);
 
-       mutex_unlock(&domain->api_lock);
+       return get_order(unmap_size);
 }
 
 static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
                                          unsigned long iova)
 {
        struct protection_domain *domain = dom->priv;
-       unsigned long offset = iova & ~PAGE_MASK;
+       unsigned long offset_mask;
        phys_addr_t paddr;
-       u64 *pte;
+       u64 *pte, __pte;
 
-       pte = fetch_pte(domain, iova, PM_MAP_4k);
+       pte = fetch_pte(domain, iova);
 
        if (!pte || !IOMMU_PTE_PRESENT(*pte))
                return 0;
 
-       paddr  = *pte & IOMMU_PAGE_MASK;
-       paddr |= offset;
+       if (PM_PTE_LEVEL(*pte) == 0)
+               offset_mask = PAGE_SIZE - 1;
+       else
+               offset_mask = PTE_PAGE_SIZE(*pte) - 1;
+
+       __pte = *pte & PM_ADDR_MASK;
+       paddr = (__pte & ~offset_mask) | (iova & offset_mask);
 
        return paddr;
 }
@@ -2523,8 +2578,8 @@ static struct iommu_ops amd_iommu_ops = {
        .domain_destroy = amd_iommu_domain_destroy,
        .attach_dev = amd_iommu_attach_device,
        .detach_dev = amd_iommu_detach_device,
-       .map = amd_iommu_map_range,
-       .unmap = amd_iommu_unmap_range,
+       .map = amd_iommu_map,
+       .unmap = amd_iommu_unmap,
        .iova_to_phys = amd_iommu_iova_to_phys,
        .domain_has_cap = amd_iommu_domain_has_cap,
 };
index 6360abf..3bacb4d 100644 (file)
@@ -120,6 +120,7 @@ struct ivmd_header {
 bool amd_iommu_dump;
 
 static int __initdata amd_iommu_detected;
+static bool __initdata amd_iommu_disabled;
 
 u16 amd_iommu_last_bdf;                        /* largest PCI device id we have
                                           to handle */
@@ -1372,6 +1373,9 @@ void __init amd_iommu_detect(void)
        if (no_iommu || (iommu_detected && !gart_iommu_aperture))
                return;
 
+       if (amd_iommu_disabled)
+               return;
+
        if (acpi_table_parse("IVRS", early_amd_iommu_detect) == 0) {
                iommu_detected = 1;
                amd_iommu_detected = 1;
@@ -1401,6 +1405,8 @@ static int __init parse_amd_iommu_options(char *str)
        for (; *str; ++str) {
                if (strncmp(str, "fullflush", 9) == 0)
                        amd_iommu_unmap_flush = true;
+               if (strncmp(str, "off", 3) == 0)
+                       amd_iommu_disabled = true;
        }
 
        return 1;
index 03ba1b8..425e53a 100644 (file)
@@ -131,24 +131,6 @@ int                                        es7000_plat;
 
 static unsigned int                    base;
 
-static int
-es7000_rename_gsi(int ioapic, int gsi)
-{
-       if (es7000_plat == ES7000_ZORRO)
-               return gsi;
-
-       if (!base) {
-               int i;
-               for (i = 0; i < nr_ioapics; i++)
-                       base += nr_ioapic_registers[i];
-       }
-
-       if (!ioapic && (gsi < 16))
-               gsi += base;
-
-       return gsi;
-}
-
 static int __cpuinit wakeup_secondary_cpu_via_mip(int cpu, unsigned long eip)
 {
        unsigned long vect = 0, psaival = 0;
@@ -190,7 +172,6 @@ static void setup_unisys(void)
                es7000_plat = ES7000_ZORRO;
        else
                es7000_plat = ES7000_CLASSIC;
-       ioapic_renumber_irq = es7000_rename_gsi;
 }
 
 /*
index eb2789c..33f3563 100644 (file)
@@ -89,6 +89,9 @@ int nr_ioapics;
 /* IO APIC gsi routing info */
 struct mp_ioapic_gsi  mp_gsi_routing[MAX_IO_APICS];
 
+/* The last gsi number used */
+u32 gsi_end;
+
 /* MP IRQ source entries */
 struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
 
@@ -1013,10 +1016,9 @@ static inline int irq_trigger(int idx)
        return MPBIOS_trigger(idx);
 }
 
-int (*ioapic_renumber_irq)(int ioapic, int irq);
 static int pin_2_irq(int idx, int apic, int pin)
 {
-       int irq, i;
+       int irq;
        int bus = mp_irqs[idx].srcbus;
 
        /*
@@ -1028,18 +1030,12 @@ static int pin_2_irq(int idx, int apic, int pin)
        if (test_bit(bus, mp_bus_not_pci)) {
                irq = mp_irqs[idx].srcbusirq;
        } else {
-               /*
-                * PCI IRQs are mapped in order
-                */
-               i = irq = 0;
-               while (i < apic)
-                       irq += nr_ioapic_registers[i++];
-               irq += pin;
-               /*
-                 * For MPS mode, so far only needed by ES7000 platform
-                 */
-               if (ioapic_renumber_irq)
-                       irq = ioapic_renumber_irq(apic, irq);
+               u32 gsi = mp_gsi_routing[apic].gsi_base + pin;
+
+               if (gsi >= NR_IRQS_LEGACY)
+                       irq = gsi;
+               else
+                       irq = gsi_end + 1 + gsi;
        }
 
 #ifdef CONFIG_X86_32
@@ -1950,20 +1946,8 @@ static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
 
 void __init enable_IO_APIC(void)
 {
-       union IO_APIC_reg_01 reg_01;
        int i8259_apic, i8259_pin;
        int apic;
-       unsigned long flags;
-
-       /*
-        * The number of IO-APIC IRQ registers (== #pins):
-        */
-       for (apic = 0; apic < nr_ioapics; apic++) {
-               raw_spin_lock_irqsave(&ioapic_lock, flags);
-               reg_01.raw = io_apic_read(apic, 1);
-               raw_spin_unlock_irqrestore(&ioapic_lock, flags);
-               nr_ioapic_registers[apic] = reg_01.bits.entries+1;
-       }
 
        if (!legacy_pic->nr_legacy_irqs)
                return;
@@ -3858,27 +3842,20 @@ int __init io_apic_get_redir_entries (int ioapic)
        reg_01.raw = io_apic_read(ioapic, 1);
        raw_spin_unlock_irqrestore(&ioapic_lock, flags);
 
-       return reg_01.bits.entries;
+       /* The register returns the maximum index redir index
+        * supported, which is one less than the total number of redir
+        * entries.
+        */
+       return reg_01.bits.entries + 1;
 }
 
 void __init probe_nr_irqs_gsi(void)
 {
-       int nr = 0;
+       int nr;
 
-       nr = acpi_probe_gsi();
-       if (nr > nr_irqs_gsi) {
+       nr = gsi_end + 1 + NR_IRQS_LEGACY;
+       if (nr > nr_irqs_gsi)
                nr_irqs_gsi = nr;
-       } else {
-               /* for acpi=off or acpi is not compiled in */
-               int idx;
-
-               nr = 0;
-               for (idx = 0; idx < nr_ioapics; idx++)
-                       nr += io_apic_get_redir_entries(idx) + 1;
-
-               if (nr > nr_irqs_gsi)
-                       nr_irqs_gsi = nr;
-       }
 
        printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
 }
@@ -4085,22 +4062,27 @@ int __init io_apic_get_version(int ioapic)
        return reg_01.bits.version;
 }
 
-int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity)
+int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity)
 {
-       int i;
+       int ioapic, pin, idx;
 
        if (skip_ioapic_setup)
                return -1;
 
-       for (i = 0; i < mp_irq_entries; i++)
-               if (mp_irqs[i].irqtype == mp_INT &&
-                   mp_irqs[i].srcbusirq == bus_irq)
-                       break;
-       if (i >= mp_irq_entries)
+       ioapic = mp_find_ioapic(gsi);
+       if (ioapic < 0)
                return -1;
 
-       *trigger = irq_trigger(i);
-       *polarity = irq_polarity(i);
+       pin = mp_find_ioapic_pin(ioapic, gsi);
+       if (pin < 0)
+               return -1;
+
+       idx = find_irq_entry(ioapic, pin, mp_INT);
+       if (idx < 0)
+               return -1;
+
+       *trigger = irq_trigger(idx);
+       *polarity = irq_polarity(idx);
        return 0;
 }
 
@@ -4241,7 +4223,7 @@ void __init ioapic_insert_resources(void)
        }
 }
 
-int mp_find_ioapic(int gsi)
+int mp_find_ioapic(u32 gsi)
 {
        int i = 0;
 
@@ -4256,7 +4238,7 @@ int mp_find_ioapic(int gsi)
        return -1;
 }
 
-int mp_find_ioapic_pin(int ioapic, int gsi)
+int mp_find_ioapic_pin(int ioapic, u32 gsi)
 {
        if (WARN_ON(ioapic == -1))
                return -1;
@@ -4284,6 +4266,7 @@ static int bad_ioapic(unsigned long address)
 void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
 {
        int idx = 0;
+       int entries;
 
        if (bad_ioapic(address))
                return;
@@ -4302,9 +4285,17 @@ void __init mp_register_ioapic(int id, u32 address, u32 gsi_base)
         * Build basic GSI lookup table to facilitate gsi->io_apic lookups
         * and to prevent reprogramming of IOAPIC pins (PCI GSIs).
         */
+       entries = io_apic_get_redir_entries(idx);
        mp_gsi_routing[idx].gsi_base = gsi_base;
-       mp_gsi_routing[idx].gsi_end = gsi_base +
-           io_apic_get_redir_entries(idx);
+       mp_gsi_routing[idx].gsi_end = gsi_base + entries - 1;
+
+       /*
+        * The number of IO-APIC IRQ registers (== #pins):
+        */
+       nr_ioapic_registers[idx] = entries;
+
+       if (mp_gsi_routing[idx].gsi_end > gsi_end)
+               gsi_end = mp_gsi_routing[idx].gsi_end;
 
        printk(KERN_INFO "IOAPIC[%d]: apic_id %d, version %d, address 0x%x, "
               "GSI %d-%d\n", idx, mp_ioapics[idx].apicid,
index c085d52..e46f98f 100644 (file)
@@ -735,9 +735,6 @@ void __init uv_system_init(void)
                uv_node_to_blade[nid] = blade;
                uv_cpu_to_blade[cpu] = blade;
                max_pnode = max(pnode, max_pnode);
-
-               printk(KERN_DEBUG "UV: cpu %d, apicid 0x%x, pnode %d, nid %d, lcpu %d, blade %d\n",
-                       cpu, apicid, pnode, nid, lcpu, blade);
        }
 
        /* Add blade/pnode info for nodes without cpus */
index 031aa88..c4f9182 100644 (file)
@@ -1224,7 +1224,7 @@ static void reinit_timer(void)
 #ifdef INIT_TIMER_AFTER_SUSPEND
        unsigned long flags;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
        /* set the clock to HZ */
        outb_pit(0x34, PIT_MODE);               /* binary, mode 2, LSB/MSB, ch 0 */
        udelay(10);
@@ -1232,7 +1232,7 @@ static void reinit_timer(void)
        udelay(10);
        outb_pit(LATCH >> 8, PIT_CH0);  /* MSB */
        udelay(10);
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 #endif
 }
 
index c202b62..3a785da 100644 (file)
@@ -14,7 +14,7 @@ CFLAGS_common.o               := $(nostackp)
 
 obj-y                  := intel_cacheinfo.o addon_cpuid_features.o
 obj-y                  += proc.o capflags.o powerflags.o common.o
-obj-y                  += vmware.o hypervisor.o sched.o
+obj-y                  += vmware.o hypervisor.o sched.o mshyperv.o
 
 obj-$(CONFIG_X86_32)   += bugs.o cmpxchg.o
 obj-$(CONFIG_X86_64)   += bugs_64.o
index 97ad79c..10fa568 100644 (file)
@@ -30,12 +30,14 @@ void __cpuinit init_scattered_cpuid_features(struct cpuinfo_x86 *c)
        const struct cpuid_bit *cb;
 
        static const struct cpuid_bit __cpuinitconst cpuid_bits[] = {
-               { X86_FEATURE_IDA, CR_EAX, 1, 0x00000006 },
-               { X86_FEATURE_ARAT, CR_EAX, 2, 0x00000006 },
-               { X86_FEATURE_NPT,   CR_EDX, 0, 0x8000000a },
-               { X86_FEATURE_LBRV,  CR_EDX, 1, 0x8000000a },
-               { X86_FEATURE_SVML,  CR_EDX, 2, 0x8000000a },
-               { X86_FEATURE_NRIPS, CR_EDX, 3, 0x8000000a },
+               { X86_FEATURE_IDA,              CR_EAX, 1, 0x00000006 },
+               { X86_FEATURE_ARAT,             CR_EAX, 2, 0x00000006 },
+               { X86_FEATURE_APERFMPERF,       CR_ECX, 0, 0x00000006 },
+               { X86_FEATURE_CPB,              CR_EDX, 9, 0x80000007 },
+               { X86_FEATURE_NPT,              CR_EDX, 0, 0x8000000a },
+               { X86_FEATURE_LBRV,             CR_EDX, 1, 0x8000000a },
+               { X86_FEATURE_SVML,             CR_EDX, 2, 0x8000000a },
+               { X86_FEATURE_NRIPS,            CR_EDX, 3, 0x8000000a },
                { 0, 0, 0, 0 }
        };
 
index 01a2652..c39576c 100644 (file)
@@ -86,7 +86,7 @@ static void __init check_fpu(void)
 
 static void __init check_hlt(void)
 {
-       if (paravirt_enabled())
+       if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
                return;
 
        printk(KERN_INFO "Checking 'hlt' instruction... ");
index 4868e4a..c1c00d0 100644 (file)
@@ -1243,10 +1243,7 @@ void __cpuinit cpu_init(void)
        /*
         * Force FPU initialization:
         */
-       if (cpu_has_xsave)
-               current_thread_info()->status = TS_XSAVE;
-       else
-               current_thread_info()->status = 0;
+       current_thread_info()->status = 0;
        clear_used_math();
        mxcsr_feature_mask_init();
 
index 1840c0a..bd54bf6 100644 (file)
@@ -2,8 +2,8 @@
 # K8 systems. ACPI is preferred to all other hardware-specific drivers.
 # speedstep-* is preferred over p4-clockmod.
 
-obj-$(CONFIG_X86_POWERNOW_K8)          += powernow-k8.o
-obj-$(CONFIG_X86_ACPI_CPUFREQ)         += acpi-cpufreq.o
+obj-$(CONFIG_X86_POWERNOW_K8)          += powernow-k8.o mperf.o
+obj-$(CONFIG_X86_ACPI_CPUFREQ)         += acpi-cpufreq.o mperf.o
 obj-$(CONFIG_X86_PCC_CPUFREQ)          += pcc-cpufreq.o
 obj-$(CONFIG_X86_POWERNOW_K6)          += powernow-k6.o
 obj-$(CONFIG_X86_POWERNOW_K7)          += powernow-k7.o
index 4591680..1d3cdda 100644 (file)
@@ -46,6 +46,7 @@
 #include <asm/msr.h>
 #include <asm/processor.h>
 #include <asm/cpufeature.h>
+#include "mperf.h"
 
 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
                "acpi-cpufreq", msg)
@@ -71,8 +72,6 @@ struct acpi_cpufreq_data {
 
 static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data);
 
-static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf);
-
 /* acpi_perf_data is a pointer to percpu data. */
 static struct acpi_processor_performance *acpi_perf_data;
 
@@ -240,45 +239,6 @@ static u32 get_cur_val(const struct cpumask *mask)
        return cmd.val;
 }
 
-/* Called via smp_call_function_single(), on the target CPU */
-static void read_measured_perf_ctrs(void *_cur)
-{
-       struct aperfmperf *am = _cur;
-
-       get_aperfmperf(am);
-}
-
-/*
- * Return the measured active (C0) frequency on this CPU since last call
- * to this function.
- * Input: cpu number
- * Return: Average CPU frequency in terms of max frequency (zero on error)
- *
- * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
- * over a period of time, while CPU is in C0 state.
- * IA32_MPERF counts at the rate of max advertised frequency
- * IA32_APERF counts at the rate of actual CPU frequency
- * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
- * no meaning should be associated with absolute values of these MSRs.
- */
-static unsigned int get_measured_perf(struct cpufreq_policy *policy,
-                                     unsigned int cpu)
-{
-       struct aperfmperf perf;
-       unsigned long ratio;
-       unsigned int retval;
-
-       if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1))
-               return 0;
-
-       ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf);
-       per_cpu(acfreq_old_perf, cpu) = perf;
-
-       retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT;
-
-       return retval;
-}
-
 static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
 {
        struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu);
@@ -702,7 +662,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
 
        /* Check for APERF/MPERF support in hardware */
        if (cpu_has(c, X86_FEATURE_APERFMPERF))
-               acpi_cpufreq_driver.getavg = get_measured_perf;
+               acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
 
        dprintk("CPU%u - ACPI performance management activated.\n", cpu);
        for (i = 0; i < perf->state_count; i++)
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.c b/arch/x86/kernel/cpu/cpufreq/mperf.c
new file mode 100644 (file)
index 0000000..911e193
--- /dev/null
@@ -0,0 +1,51 @@
+#include <linux/kernel.h>
+#include <linux/smp.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/cpufreq.h>
+#include <linux/slab.h>
+
+#include "mperf.h"
+
+static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf);
+
+/* Called via smp_call_function_single(), on the target CPU */
+static void read_measured_perf_ctrs(void *_cur)
+{
+       struct aperfmperf *am = _cur;
+
+       get_aperfmperf(am);
+}
+
+/*
+ * Return the measured active (C0) frequency on this CPU since last call
+ * to this function.
+ * Input: cpu number
+ * Return: Average CPU frequency in terms of max frequency (zero on error)
+ *
+ * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
+ * over a period of time, while CPU is in C0 state.
+ * IA32_MPERF counts at the rate of max advertised frequency
+ * IA32_APERF counts at the rate of actual CPU frequency
+ * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
+ * no meaning should be associated with absolute values of these MSRs.
+ */
+unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
+                                       unsigned int cpu)
+{
+       struct aperfmperf perf;
+       unsigned long ratio;
+       unsigned int retval;
+
+       if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1))
+               return 0;
+
+       ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf);
+       per_cpu(acfreq_old_perf, cpu) = perf;
+
+       retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT;
+
+       return retval;
+}
+EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf);
+MODULE_LICENSE("GPL");
diff --git a/arch/x86/kernel/cpu/cpufreq/mperf.h b/arch/x86/kernel/cpu/cpufreq/mperf.h
new file mode 100644 (file)
index 0000000..5dbf295
--- /dev/null
@@ -0,0 +1,9 @@
+/*
+ *  (c) 2010 Advanced Micro Devices, Inc.
+ *  Your use of this code is subject to the terms and conditions of the
+ *  GNU general public license version 2. See "COPYING" or
+ *  http://www.gnu.org/licenses/gpl.html
+ */
+
+unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy,
+                                       unsigned int cpu);
index b6215b9..6f3dc8f 100644 (file)
@@ -1,6 +1,5 @@
-
 /*
- *   (c) 2003-2006 Advanced Micro Devices, Inc.
+ *   (c) 2003-2010 Advanced Micro Devices, Inc.
  *  Your use of this code is subject to the terms and conditions of the
  *  GNU general public license version 2. See "COPYING" or
  *  http://www.gnu.org/licenses/gpl.html
@@ -46,6 +45,7 @@
 #define PFX "powernow-k8: "
 #define VERSION "version 2.20.00"
 #include "powernow-k8.h"
+#include "mperf.h"
 
 /* serialize freq changes  */
 static DEFINE_MUTEX(fidvid_mutex);
@@ -54,6 +54,12 @@ static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data);
 
 static int cpu_family = CPU_OPTERON;
 
+/* core performance boost */
+static bool cpb_capable, cpb_enabled;
+static struct msr __percpu *msrs;
+
+static struct cpufreq_driver cpufreq_amd64_driver;
+
 #ifndef CONFIG_SMP
 static inline const struct cpumask *cpu_core_mask(int cpu)
 {
@@ -1249,6 +1255,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
        struct powernow_k8_data *data;
        struct init_on_cpu init_on_cpu;
        int rc;
+       struct cpuinfo_x86 *c = &cpu_data(pol->cpu);
 
        if (!cpu_online(pol->cpu))
                return -ENODEV;
@@ -1323,6 +1330,10 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
                return -EINVAL;
        }
 
+       /* Check for APERF/MPERF support in hardware */
+       if (cpu_has(c, X86_FEATURE_APERFMPERF))
+               cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf;
+
        cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu);
 
        if (cpu_family == CPU_HW_PSTATE)
@@ -1394,8 +1405,77 @@ out:
        return khz;
 }
 
+static void _cpb_toggle_msrs(bool t)
+{
+       int cpu;
+
+       get_online_cpus();
+
+       rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs);
+
+       for_each_cpu(cpu, cpu_online_mask) {
+               struct msr *reg = per_cpu_ptr(msrs, cpu);
+               if (t)
+                       reg->l &= ~BIT(25);
+               else
+                       reg->l |= BIT(25);
+       }
+       wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs);
+
+       put_online_cpus();
+}
+
+/*
+ * Switch on/off core performance boosting.
+ *
+ * 0=disable
+ * 1=enable.
+ */
+static void cpb_toggle(bool t)
+{
+       if (!cpb_capable)
+               return;
+
+       if (t && !cpb_enabled) {
+               cpb_enabled = true;
+               _cpb_toggle_msrs(t);
+               printk(KERN_INFO PFX "Core Boosting enabled.\n");
+       } else if (!t && cpb_enabled) {
+               cpb_enabled = false;
+               _cpb_toggle_msrs(t);
+               printk(KERN_INFO PFX "Core Boosting disabled.\n");
+       }
+}
+
+static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf,
+                                size_t count)
+{
+       int ret = -EINVAL;
+       unsigned long val = 0;
+
+       ret = strict_strtoul(buf, 10, &val);
+       if (!ret && (val == 0 || val == 1) && cpb_capable)
+               cpb_toggle(val);
+       else
+               return -EINVAL;
+
+       return count;
+}
+
+static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf)
+{
+       return sprintf(buf, "%u\n", cpb_enabled);
+}
+
+#define define_one_rw(_name) \
+static struct freq_attr _name = \
+__ATTR(_name, 0644, show_##_name, store_##_name)
+
+define_one_rw(cpb);
+
 static struct freq_attr *powernow_k8_attr[] = {
        &cpufreq_freq_attr_scaling_available_freqs,
+       &cpb,
        NULL,
 };
 
@@ -1411,10 +1491,51 @@ static struct cpufreq_driver cpufreq_amd64_driver = {
        .attr           = powernow_k8_attr,
 };
 
+/*
+ * Clear the boost-disable flag on the CPU_DOWN path so that this cpu
+ * cannot block the remaining ones from boosting. On the CPU_UP path we
+ * simply keep the boost-disable flag in sync with the current global
+ * state.
+ */
+static int __cpuinit cpb_notify(struct notifier_block *nb, unsigned long action,
+                               void *hcpu)
+{
+       unsigned cpu = (long)hcpu;
+       u32 lo, hi;
+
+       switch (action) {
+       case CPU_UP_PREPARE:
+       case CPU_UP_PREPARE_FROZEN:
+
+               if (!cpb_enabled) {
+                       rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi);
+                       lo |= BIT(25);
+                       wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi);
+               }
+               break;
+
+       case CPU_DOWN_PREPARE:
+       case CPU_DOWN_PREPARE_FROZEN:
+               rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi);
+               lo &= ~BIT(25);
+               wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi);
+               break;
+
+       default:
+               break;
+       }
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block __cpuinitdata cpb_nb = {
+       .notifier_call          = cpb_notify,
+};
+
 /* driver entry point for init */
 static int __cpuinit powernowk8_init(void)
 {
-       unsigned int i, supported_cpus = 0;
+       unsigned int i, supported_cpus = 0, cpu;
 
        for_each_online_cpu(i) {
                int rc;
@@ -1423,15 +1544,36 @@ static int __cpuinit powernowk8_init(void)
                        supported_cpus++;
        }
 
-       if (supported_cpus == num_online_cpus()) {
-               printk(KERN_INFO PFX "Found %d %s "
-                       "processors (%d cpu cores) (" VERSION ")\n",
-                       num_online_nodes(),
-                       boot_cpu_data.x86_model_id, supported_cpus);
-               return cpufreq_register_driver(&cpufreq_amd64_driver);
+       if (supported_cpus != num_online_cpus())
+               return -ENODEV;
+
+       printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n",
+               num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus);
+
+       if (boot_cpu_has(X86_FEATURE_CPB)) {
+
+               cpb_capable = true;
+
+               register_cpu_notifier(&cpb_nb);
+
+               msrs = msrs_alloc();
+               if (!msrs) {
+                       printk(KERN_ERR "%s: Error allocating msrs!\n", __func__);
+                       return -ENOMEM;
+               }
+
+               rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs);
+
+               for_each_cpu(cpu, cpu_online_mask) {
+                       struct msr *reg = per_cpu_ptr(msrs, cpu);
+                       cpb_enabled |= !(!!(reg->l & BIT(25)));
+               }
+
+               printk(KERN_INFO PFX "Core Performance Boosting: %s.\n",
+                       (cpb_enabled ? "on" : "off"));
        }
 
-       return -ENODEV;
+       return cpufreq_register_driver(&cpufreq_amd64_driver);
 }
 
 /* driver entry point for term */
@@ -1439,6 +1581,13 @@ static void __exit powernowk8_exit(void)
 {
        dprintk("exit\n");
 
+       if (boot_cpu_has(X86_FEATURE_CPB)) {
+               msrs_free(msrs);
+               msrs = NULL;
+
+               unregister_cpu_notifier(&cpb_nb);
+       }
+
        cpufreq_unregister_driver(&cpufreq_amd64_driver);
 }
 
index 02ce824..df3529b 100644 (file)
@@ -5,7 +5,6 @@
  *  http://www.gnu.org/licenses/gpl.html
  */
 
-
 enum pstate {
        HW_PSTATE_INVALID = 0xff,
        HW_PSTATE_0 = 0,
@@ -55,7 +54,6 @@ struct powernow_k8_data {
        struct cpumask *available_cores;
 };
 
-
 /* processor's cpuid instruction support */
 #define CPUID_PROCESSOR_SIGNATURE      1       /* function 1 */
 #define CPUID_XFAM                     0x0ff00000      /* extended family */
index 08be922..dd531cc 100644 (file)
  *
  */
 
+#include <linux/module.h>
 #include <asm/processor.h>
-#include <asm/vmware.h>
 #include <asm/hypervisor.h>
 
-static inline void __cpuinit
-detect_hypervisor_vendor(struct cpuinfo_x86 *c)
+/*
+ * Hypervisor detect order.  This is specified explicitly here because
+ * some hypervisors might implement compatibility modes for other
+ * hypervisors and therefore need to be detected in specific sequence.
+ */
+static const __initconst struct hypervisor_x86 * const hypervisors[] =
 {
-       if (vmware_platform())
-               c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE;
-       else
-               c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE;
-}
+       &x86_hyper_vmware,
+       &x86_hyper_ms_hyperv,
+};
 
-static inline void __cpuinit
-hypervisor_set_feature_bits(struct cpuinfo_x86 *c)
+const struct hypervisor_x86 *x86_hyper;
+EXPORT_SYMBOL(x86_hyper);
+
+static inline void __init
+detect_hypervisor_vendor(void)
 {
-       if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) {
-               vmware_set_feature_bits(c);
-               return;
+       const struct hypervisor_x86 *h, * const *p;
+
+       for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
+               h = *p;
+               if (h->detect()) {
+                       x86_hyper = h;
+                       printk(KERN_INFO "Hypervisor detected: %s\n", h->name);
+                       break;
+               }
        }
 }
 
 void __cpuinit init_hypervisor(struct cpuinfo_x86 *c)
 {
-       detect_hypervisor_vendor(c);
-       hypervisor_set_feature_bits(c);
+       if (x86_hyper && x86_hyper->set_cpu_features)
+               x86_hyper->set_cpu_features(c);
 }
 
 void __init init_hypervisor_platform(void)
 {
+
+       detect_hypervisor_vendor();
+
+       if (!x86_hyper)
+               return;
+
        init_hypervisor(&boot_cpu_data);
-       if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
-               vmware_platform_setup();
+
+       if (x86_hyper->init_platform)
+               x86_hyper->init_platform();
 }
index 1366c7c..85f69cd 100644 (file)
@@ -12,7 +12,6 @@
 #include <asm/processor.h>
 #include <asm/pgtable.h>
 #include <asm/msr.h>
-#include <asm/ds.h>
 #include <asm/bugs.h>
 #include <asm/cpu.h>
 
@@ -373,12 +372,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
                        set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
        }
 
-       if (c->cpuid_level > 6) {
-               unsigned ecx = cpuid_ecx(6);
-               if (ecx & 0x01)
-                       set_cpu_cap(c, X86_FEATURE_APERFMPERF);
-       }
-
        if (cpu_has_xmm2)
                set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
        if (cpu_has_ds) {
@@ -388,7 +381,6 @@ static void __cpuinit init_intel(struct cpuinfo_x86 *c)
                        set_cpu_cap(c, X86_FEATURE_BTS);
                if (!(l1 & (1<<12)))
                        set_cpu_cap(c, X86_FEATURE_PEBS);
-               ds_init_intel(c);
        }
 
        if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush)
index 95962a9..33eae20 100644 (file)
@@ -148,13 +148,19 @@ union _cpuid4_leaf_ecx {
        u32 full;
 };
 
+struct amd_l3_cache {
+       struct   pci_dev *dev;
+       bool     can_disable;
+       unsigned indices;
+       u8       subcaches[4];
+};
+
 struct _cpuid4_info {
        union _cpuid4_leaf_eax eax;
        union _cpuid4_leaf_ebx ebx;
        union _cpuid4_leaf_ecx ecx;
        unsigned long size;
-       bool can_disable;
-       unsigned int l3_indices;
+       struct amd_l3_cache *l3;
        DECLARE_BITMAP(shared_cpu_map, NR_CPUS);
 };
 
@@ -164,8 +170,7 @@ struct _cpuid4_info_regs {
        union _cpuid4_leaf_ebx ebx;
        union _cpuid4_leaf_ecx ecx;
        unsigned long size;
-       bool can_disable;
-       unsigned int l3_indices;
+       struct amd_l3_cache *l3;
 };
 
 unsigned short                 num_cache_leaves;
@@ -302,91 +307,163 @@ struct _cache_attr {
 };
 
 #ifdef CONFIG_CPU_SUP_AMD
-static unsigned int __cpuinit amd_calc_l3_indices(void)
+
+/*
+ * L3 cache descriptors
+ */
+static struct amd_l3_cache **__cpuinitdata l3_caches;
+
+static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3)
 {
-       /*
-        * We're called over smp_call_function_single() and therefore
-        * are on the correct cpu.
-        */
-       int cpu = smp_processor_id();
-       int node = cpu_to_node(cpu);
-       struct pci_dev *dev = node_to_k8_nb_misc(node);
        unsigned int sc0, sc1, sc2, sc3;
        u32 val = 0;
 
-       pci_read_config_dword(dev, 0x1C4, &val);
+       pci_read_config_dword(l3->dev, 0x1C4, &val);
 
        /* calculate subcache sizes */
-       sc0 = !(val & BIT(0));
-       sc1 = !(val & BIT(4));
-       sc2 = !(val & BIT(8))  + !(val & BIT(9));
-       sc3 = !(val & BIT(12)) + !(val & BIT(13));
+       l3->subcaches[0] = sc0 = !(val & BIT(0));
+       l3->subcaches[1] = sc1 = !(val & BIT(4));
+       l3->subcaches[2] = sc2 = !(val & BIT(8))  + !(val & BIT(9));
+       l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13));
+
+       l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
+}
+
+static struct amd_l3_cache * __cpuinit amd_init_l3_cache(int node)
+{
+       struct amd_l3_cache *l3;
+       struct pci_dev *dev = node_to_k8_nb_misc(node);
 
-       return (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
+       l3 = kzalloc(sizeof(struct amd_l3_cache), GFP_ATOMIC);
+       if (!l3) {
+               printk(KERN_WARNING "Error allocating L3 struct\n");
+               return NULL;
+       }
+
+       l3->dev = dev;
+
+       amd_calc_l3_indices(l3);
+
+       return l3;
 }
 
 static void __cpuinit
 amd_check_l3_disable(int index, struct _cpuid4_info_regs *this_leaf)
 {
-       if (index < 3)
+       int node;
+
+       if (boot_cpu_data.x86 != 0x10)
                return;
 
-       if (boot_cpu_data.x86 == 0x11)
+       if (index < 3)
                return;
 
        /* see errata #382 and #388 */
-       if ((boot_cpu_data.x86 == 0x10) &&
-           ((boot_cpu_data.x86_model < 0x8) ||
-            (boot_cpu_data.x86_mask  < 0x1)))
+       if (boot_cpu_data.x86_model < 0x8)
                return;
 
+       if ((boot_cpu_data.x86_model == 0x8 ||
+            boot_cpu_data.x86_model == 0x9)
+               &&
+            boot_cpu_data.x86_mask < 0x1)
+                       return;
+
        /* not in virtualized environments */
        if (num_k8_northbridges == 0)
                return;
 
-       this_leaf->can_disable = true;
-       this_leaf->l3_indices  = amd_calc_l3_indices();
+       /*
+        * Strictly speaking, the amount in @size below is leaked since it is
+        * never freed but this is done only on shutdown so it doesn't matter.
+        */
+       if (!l3_caches) {
+               int size = num_k8_northbridges * sizeof(struct amd_l3_cache *);
+
+               l3_caches = kzalloc(size, GFP_ATOMIC);
+               if (!l3_caches)
+                       return;
+       }
+
+       node = amd_get_nb_id(smp_processor_id());
+
+       if (!l3_caches[node]) {
+               l3_caches[node] = amd_init_l3_cache(node);
+               l3_caches[node]->can_disable = true;
+       }
+
+       WARN_ON(!l3_caches[node]);
+
+       this_leaf->l3 = l3_caches[node];
 }
 
 static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
-                                 unsigned int index)
+                                 unsigned int slot)
 {
-       int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
-       int node = amd_get_nb_id(cpu);
-       struct pci_dev *dev = node_to_k8_nb_misc(node);
+       struct pci_dev *dev = this_leaf->l3->dev;
        unsigned int reg = 0;
 
-       if (!this_leaf->can_disable)
+       if (!this_leaf->l3 || !this_leaf->l3->can_disable)
                return -EINVAL;
 
        if (!dev)
                return -EINVAL;
 
-       pci_read_config_dword(dev, 0x1BC + index * 4, &reg);
+       pci_read_config_dword(dev, 0x1BC + slot * 4, &reg);
        return sprintf(buf, "0x%08x\n", reg);
 }
 
-#define SHOW_CACHE_DISABLE(index)                                      \
+#define SHOW_CACHE_DISABLE(slot)                                       \
 static ssize_t                                                         \
-show_cache_disable_##index(struct _cpuid4_info *this_leaf, char *buf)  \
+show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf)   \
 {                                                                      \
-       return show_cache_disable(this_leaf, buf, index);               \
+       return show_cache_disable(this_leaf, buf, slot);                \
 }
 SHOW_CACHE_DISABLE(0)
 SHOW_CACHE_DISABLE(1)
 
+static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu,
+                                unsigned slot, unsigned long idx)
+{
+       int i;
+
+       idx |= BIT(30);
+
+       /*
+        *  disable index in all 4 subcaches
+        */
+       for (i = 0; i < 4; i++) {
+               u32 reg = idx | (i << 20);
+
+               if (!l3->subcaches[i])
+                       continue;
+
+               pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg);
+
+               /*
+                * We need to WBINVD on a core on the node containing the L3
+                * cache which indices we disable therefore a simple wbinvd()
+                * is not sufficient.
+                */
+               wbinvd_on_cpu(cpu);
+
+               reg |= BIT(31);
+               pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg);
+       }
+}
+
+
 static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
-       const char *buf, size_t count, unsigned int index)
+                                  const char *buf, size_t count,
+                                  unsigned int slot)
 {
+       struct pci_dev *dev = this_leaf->l3->dev;
        int cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
-       int node = amd_get_nb_id(cpu);
-       struct pci_dev *dev = node_to_k8_nb_misc(node);
        unsigned long val = 0;
 
 #define SUBCACHE_MASK  (3UL << 20)
 #define SUBCACHE_INDEX 0xfff
 
-       if (!this_leaf->can_disable)
+       if (!this_leaf->l3 || !this_leaf->l3->can_disable)
                return -EINVAL;
 
        if (!capable(CAP_SYS_ADMIN))
@@ -400,26 +477,20 @@ static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
 
        /* do not allow writes outside of allowed bits */
        if ((val & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) ||
-           ((val & SUBCACHE_INDEX) > this_leaf->l3_indices))
+           ((val & SUBCACHE_INDEX) > this_leaf->l3->indices))
                return -EINVAL;
 
-       val |= BIT(30);
-       pci_write_config_dword(dev, 0x1BC + index * 4, val);
-       /*
-        * We need to WBINVD on a core on the node containing the L3 cache which
-        * indices we disable therefore a simple wbinvd() is not sufficient.
-        */
-       wbinvd_on_cpu(cpu);
-       pci_write_config_dword(dev, 0x1BC + index * 4, val | BIT(31));
+       amd_l3_disable_index(this_leaf->l3, cpu, slot, val);
+
        return count;
 }
 
-#define STORE_CACHE_DISABLE(index)                                     \
+#define STORE_CACHE_DISABLE(slot)                                      \
 static ssize_t                                                         \
-store_cache_disable_##index(struct _cpuid4_info *this_leaf,            \
+store_cache_disable_##slot(struct _cpuid4_info *this_leaf,             \
                            const char *buf, size_t count)              \
 {                                                                      \
-       return store_cache_disable(this_leaf, buf, count, index);       \
+       return store_cache_disable(this_leaf, buf, count, slot);        \
 }
 STORE_CACHE_DISABLE(0)
 STORE_CACHE_DISABLE(1)
@@ -447,8 +518,7 @@ __cpuinit cpuid4_cache_lookup_regs(int index,
 
        if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
                amd_cpuid4(index, &eax, &ebx, &ecx);
-               if (boot_cpu_data.x86 >= 0x10)
-                       amd_check_l3_disable(index, this_leaf);
+               amd_check_l3_disable(index, this_leaf);
        } else {
                cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx);
        }
@@ -705,6 +775,7 @@ static void __cpuinit free_cache_attributes(unsigned int cpu)
        for (i = 0; i < num_cache_leaves; i++)
                cache_remove_shared_cpu_map(cpu, i);
 
+       kfree(per_cpu(ici_cpuid4_info, cpu)->l3);
        kfree(per_cpu(ici_cpuid4_info, cpu));
        per_cpu(ici_cpuid4_info, cpu) = NULL;
 }
@@ -989,7 +1060,7 @@ static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
 
                this_leaf = CPUID4_INFO_IDX(cpu, i);
 
-               if (this_leaf->can_disable)
+               if (this_leaf->l3 && this_leaf->l3->can_disable)
                        ktype_cache.default_attrs = default_l3_attrs;
                else
                        ktype_cache.default_attrs = default_attrs;
index 8a6f0af..7a355dd 100644 (file)
@@ -539,7 +539,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
        struct mce m;
        int i;
 
-       __get_cpu_var(mce_poll_count)++;
+       percpu_inc(mce_poll_count);
 
        mce_setup(&m);
 
@@ -934,7 +934,7 @@ void do_machine_check(struct pt_regs *regs, long error_code)
 
        atomic_inc(&mce_entry);
 
-       __get_cpu_var(mce_exception_count)++;
+       percpu_inc(mce_exception_count);
 
        if (notify_die(DIE_NMI, "machine check", regs, error_code,
                           18, SIGKILL) == NOTIFY_STOP)
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
new file mode 100644 (file)
index 0000000..16f41bb
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * HyperV  Detection code.
+ *
+ * Copyright (C) 2010, Novell, Inc.
+ * Author : K. Y. Srinivasan <ksrinivasan@novell.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; version 2 of the License.
+ *
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <asm/processor.h>
+#include <asm/hypervisor.h>
+#include <asm/hyperv.h>
+#include <asm/mshyperv.h>
+
+struct ms_hyperv_info ms_hyperv;
+
+static bool __init ms_hyperv_platform(void)
+{
+       u32 eax;
+       u32 hyp_signature[3];
+
+       if (!boot_cpu_has(X86_FEATURE_HYPERVISOR))
+               return false;
+
+       cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS,
+             &eax, &hyp_signature[0], &hyp_signature[1], &hyp_signature[2]);
+
+       return eax >= HYPERV_CPUID_MIN &&
+               eax <= HYPERV_CPUID_MAX &&
+               !memcmp("Microsoft Hv", hyp_signature, 12);
+}
+
+static void __init ms_hyperv_init_platform(void)
+{
+       /*
+        * Extract the features and hints
+        */
+       ms_hyperv.features = cpuid_eax(HYPERV_CPUID_FEATURES);
+       ms_hyperv.hints    = cpuid_eax(HYPERV_CPUID_ENLIGHTMENT_INFO);
+
+       printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n",
+              ms_hyperv.features, ms_hyperv.hints);
+}
+
+const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
+       .name                   = "Microsoft HyperV",
+       .detect                 = ms_hyperv_platform,
+       .init_platform          = ms_hyperv_init_platform,
+};
+EXPORT_SYMBOL(x86_hyper_ms_hyperv);
index db5bdc8..fd4db0d 100644 (file)
 #include <asm/nmi.h>
 #include <asm/compat.h>
 
-static u64 perf_event_mask __read_mostly;
+#if 0
+#undef wrmsrl
+#define wrmsrl(msr, val)                                       \
+do {                                                           \
+       trace_printk("wrmsrl(%lx, %lx)\n", (unsigned long)(msr),\
+                       (unsigned long)(val));                  \
+       native_write_msr((msr), (u32)((u64)(val)),              \
+                       (u32)((u64)(val) >> 32));               \
+} while (0)
+#endif
 
-/* The maximal number of PEBS events: */
-#define MAX_PEBS_EVENTS        4
+/*
+ * best effort, GUP based copy_from_user() that assumes IRQ or NMI context
+ */
+static unsigned long
+copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
+{
+       unsigned long offset, addr = (unsigned long)from;
+       int type = in_nmi() ? KM_NMI : KM_IRQ0;
+       unsigned long size, len = 0;
+       struct page *page;
+       void *map;
+       int ret;
 
-/* The size of a BTS record in bytes: */
-#define BTS_RECORD_SIZE                24
+       do {
+               ret = __get_user_pages_fast(addr, 1, 0, &page);
+               if (!ret)
+                       break;
 
-/* The size of a per-cpu BTS buffer in bytes: */
-#define BTS_BUFFER_SIZE                (BTS_RECORD_SIZE * 2048)
+               offset = addr & (PAGE_SIZE - 1);
+               size = min(PAGE_SIZE - offset, n - len);
 
-/* The BTS overflow threshold in bytes from the end of the buffer: */
-#define BTS_OVFL_TH            (BTS_RECORD_SIZE * 128)
+               map = kmap_atomic(page, type);
+               memcpy(to, map+offset, size);
+               kunmap_atomic(map, type);
+               put_page(page);
 
+               len  += size;
+               to   += size;
+               addr += size;
 
-/*
- * Bits in the debugctlmsr controlling branch tracing.
- */
-#define X86_DEBUGCTL_TR                        (1 << 6)
-#define X86_DEBUGCTL_BTS               (1 << 7)
-#define X86_DEBUGCTL_BTINT             (1 << 8)
-#define X86_DEBUGCTL_BTS_OFF_OS                (1 << 9)
-#define X86_DEBUGCTL_BTS_OFF_USR       (1 << 10)
+       } while (len < n);
 
-/*
- * A debug store configuration.
- *
- * We only support architectures that use 64bit fields.
- */
-struct debug_store {
-       u64     bts_buffer_base;
-       u64     bts_index;
-       u64     bts_absolute_maximum;
-       u64     bts_interrupt_threshold;
-       u64     pebs_buffer_base;
-       u64     pebs_index;
-       u64     pebs_absolute_maximum;
-       u64     pebs_interrupt_threshold;
-       u64     pebs_event_reset[MAX_PEBS_EVENTS];
-};
+       return len;
+}
 
 struct event_constraint {
        union {
@@ -89,18 +94,41 @@ struct amd_nb {
        struct event_constraint event_constraints[X86_PMC_IDX_MAX];
 };
 
+#define MAX_LBR_ENTRIES                16
+
 struct cpu_hw_events {
+       /*
+        * Generic x86 PMC bits
+        */
        struct perf_event       *events[X86_PMC_IDX_MAX]; /* in counter order */
        unsigned long           active_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
-       unsigned long           interrupts;
        int                     enabled;
-       struct debug_store      *ds;
 
        int                     n_events;
        int                     n_added;
        int                     assign[X86_PMC_IDX_MAX]; /* event to counter assignment */
        u64                     tags[X86_PMC_IDX_MAX];
        struct perf_event       *event_list[X86_PMC_IDX_MAX]; /* in enabled order */
+
+       unsigned int            group_flag;
+
+       /*
+        * Intel DebugStore bits
+        */
+       struct debug_store      *ds;
+       u64                     pebs_enabled;
+
+       /*
+        * Intel LBR bits
+        */
+       int                             lbr_users;
+       void                            *lbr_context;
+       struct perf_branch_stack        lbr_stack;
+       struct perf_branch_entry        lbr_entries[MAX_LBR_ENTRIES];
+
+       /*
+        * AMD specific bits
+        */
        struct amd_nb           *amd_nb;
 };
 
@@ -114,44 +142,75 @@ struct cpu_hw_events {
 #define EVENT_CONSTRAINT(c, n, m)      \
        __EVENT_CONSTRAINT(c, n, m, HWEIGHT(n))
 
+/*
+ * Constraint on the Event code.
+ */
 #define INTEL_EVENT_CONSTRAINT(c, n)   \
-       EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVTSEL_MASK)
+       EVENT_CONSTRAINT(c, n, ARCH_PERFMON_EVENTSEL_EVENT)
 
+/*
+ * Constraint on the Event code + UMask + fixed-mask
+ *
+ * filter mask to validate fixed counter events.
+ * the following filters disqualify for fixed counters:
+ *  - inv
+ *  - edge
+ *  - cnt-mask
+ *  The other filters are supported by fixed counters.
+ *  The any-thread option is supported starting with v3.
+ */
 #define FIXED_EVENT_CONSTRAINT(c, n)   \
-       EVENT_CONSTRAINT(c, (1ULL << (32+n)), INTEL_ARCH_FIXED_MASK)
+       EVENT_CONSTRAINT(c, (1ULL << (32+n)), X86_RAW_EVENT_MASK)
+
+/*
+ * Constraint on the Event code + UMask
+ */
+#define PEBS_EVENT_CONSTRAINT(c, n)    \
+       EVENT_CONSTRAINT(c, n, INTEL_ARCH_EVENT_MASK)
 
 #define EVENT_CONSTRAINT_END           \
        EVENT_CONSTRAINT(0, 0, 0)
 
 #define for_each_event_constraint(e, c)        \
-       for ((e) = (c); (e)->cmask; (e)++)
+       for ((e) = (c); (e)->weight; (e)++)
+
+union perf_capabilities {
+       struct {
+               u64     lbr_format    : 6;
+               u64     pebs_trap     : 1;
+               u64     pebs_arch_reg : 1;
+               u64     pebs_format   : 4;
+               u64     smm_freeze    : 1;
+       };
+       u64     capabilities;
+};
 
 /*
  * struct x86_pmu - generic x86 pmu
  */
 struct x86_pmu {
+       /*
+        * Generic x86 PMC bits
+        */
        const char      *name;
        int             version;
        int             (*handle_irq)(struct pt_regs *);
        void            (*disable_all)(void);
-       void            (*enable_all)(void);
+       void            (*enable_all)(int added);
        void            (*enable)(struct perf_event *);
        void            (*disable)(struct perf_event *);
+       int             (*hw_config)(struct perf_event *event);
+       int             (*schedule_events)(struct cpu_hw_events *cpuc, int n, int *assign);
        unsigned        eventsel;
        unsigned        perfctr;
        u64             (*event_map)(int);
-       u64             (*raw_event)(u64);
        int             max_events;
-       int             num_events;
-       int             num_events_fixed;
-       int             event_bits;
-       u64             event_mask;
+       int             num_counters;
+       int             num_counters_fixed;
+       int             cntval_bits;
+       u64             cntval_mask;
        int             apic;
        u64             max_period;
-       u64             intel_ctrl;
-       void            (*enable_bts)(u64 config);
-       void            (*disable_bts)(void);
-
        struct event_constraint *
                        (*get_event_constraints)(struct cpu_hw_events *cpuc,
                                                 struct perf_event *event);
@@ -159,11 +218,32 @@ struct x86_pmu {
        void            (*put_event_constraints)(struct cpu_hw_events *cpuc,
                                                 struct perf_event *event);
        struct event_constraint *event_constraints;
+       void            (*quirks)(void);
 
        int             (*cpu_prepare)(int cpu);
        void            (*cpu_starting)(int cpu);
        void            (*cpu_dying)(int cpu);
        void            (*cpu_dead)(int cpu);
+
+       /*
+        * Intel Arch Perfmon v2+
+        */
+       u64                     intel_ctrl;
+       union perf_capabilities intel_cap;
+
+       /*
+        * Intel DebugStore bits
+        */
+       int             bts, pebs;
+       int             pebs_record_size;
+       void            (*drain_pebs)(struct pt_regs *regs);
+       struct event_constraint *pebs_constraints;
+
+       /*
+        * Intel LBR
+        */
+       unsigned long   lbr_tos, lbr_from, lbr_to; /* MSR base regs       */
+       int             lbr_nr;                    /* hardware stack size */
 };
 
 static struct x86_pmu x86_pmu __read_mostly;
@@ -198,7 +278,7 @@ static u64
 x86_perf_event_update(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
-       int shift = 64 - x86_pmu.event_bits;
+       int shift = 64 - x86_pmu.cntval_bits;
        u64 prev_raw_count, new_raw_count;
        int idx = hwc->idx;
        s64 delta;
@@ -241,33 +321,32 @@ again:
 static atomic_t active_events;
 static DEFINE_MUTEX(pmc_reserve_mutex);
 
+#ifdef CONFIG_X86_LOCAL_APIC
+
 static bool reserve_pmc_hardware(void)
 {
-#ifdef CONFIG_X86_LOCAL_APIC
        int i;
 
        if (nmi_watchdog == NMI_LOCAL_APIC)
                disable_lapic_nmi_watchdog();
 
-       for (i = 0; i < x86_pmu.num_events; i++) {
+       for (i = 0; i < x86_pmu.num_counters; i++) {
                if (!reserve_perfctr_nmi(x86_pmu.perfctr + i))
                        goto perfctr_fail;
        }
 
-       for (i = 0; i < x86_pmu.num_events; i++) {
+       for (i = 0; i < x86_pmu.num_counters; i++) {
                if (!reserve_evntsel_nmi(x86_pmu.eventsel + i))
                        goto eventsel_fail;
        }
-#endif
 
        return true;
 
-#ifdef CONFIG_X86_LOCAL_APIC
 eventsel_fail:
        for (i--; i >= 0; i--)
                release_evntsel_nmi(x86_pmu.eventsel + i);
 
-       i = x86_pmu.num_events;
+       i = x86_pmu.num_counters;
 
 perfctr_fail:
        for (i--; i >= 0; i--)
@@ -277,128 +356,36 @@ perfctr_fail:
                enable_lapic_nmi_watchdog();
 
        return false;
-#endif
 }
 
 static void release_pmc_hardware(void)
 {
-#ifdef CONFIG_X86_LOCAL_APIC
        int i;
 
-       for (i = 0; i < x86_pmu.num_events; i++) {
+       for (i = 0; i < x86_pmu.num_counters; i++) {
                release_perfctr_nmi(x86_pmu.perfctr + i);
                release_evntsel_nmi(x86_pmu.eventsel + i);
        }
 
        if (nmi_watchdog == NMI_LOCAL_APIC)
                enable_lapic_nmi_watchdog();
-#endif
-}
-
-static inline bool bts_available(void)
-{
-       return x86_pmu.enable_bts != NULL;
 }
 
-static void init_debug_store_on_cpu(int cpu)
-{
-       struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
-
-       if (!ds)
-               return;
-
-       wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA,
-                    (u32)((u64)(unsigned long)ds),
-                    (u32)((u64)(unsigned long)ds >> 32));
-}
-
-static void fini_debug_store_on_cpu(int cpu)
-{
-       if (!per_cpu(cpu_hw_events, cpu).ds)
-               return;
-
-       wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0);
-}
-
-static void release_bts_hardware(void)
-{
-       int cpu;
-
-       if (!bts_available())
-               return;
-
-       get_online_cpus();
-
-       for_each_online_cpu(cpu)
-               fini_debug_store_on_cpu(cpu);
-
-       for_each_possible_cpu(cpu) {
-               struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
-
-               if (!ds)
-                       continue;
-
-               per_cpu(cpu_hw_events, cpu).ds = NULL;
-
-               kfree((void *)(unsigned long)ds->bts_buffer_base);
-               kfree(ds);
-       }
-
-       put_online_cpus();
-}
-
-static int reserve_bts_hardware(void)
-{
-       int cpu, err = 0;
-
-       if (!bts_available())
-               return 0;
-
-       get_online_cpus();
-
-       for_each_possible_cpu(cpu) {
-               struct debug_store *ds;
-               void *buffer;
-
-               err = -ENOMEM;
-               buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL);
-               if (unlikely(!buffer))
-                       break;
-
-               ds = kzalloc(sizeof(*ds), GFP_KERNEL);
-               if (unlikely(!ds)) {
-                       kfree(buffer);
-                       break;
-               }
-
-               ds->bts_buffer_base = (u64)(unsigned long)buffer;
-               ds->bts_index = ds->bts_buffer_base;
-               ds->bts_absolute_maximum =
-                       ds->bts_buffer_base + BTS_BUFFER_SIZE;
-               ds->bts_interrupt_threshold =
-                       ds->bts_absolute_maximum - BTS_OVFL_TH;
-
-               per_cpu(cpu_hw_events, cpu).ds = ds;
-               err = 0;
-       }
+#else
 
-       if (err)
-               release_bts_hardware();
-       else {
-               for_each_online_cpu(cpu)
-                       init_debug_store_on_cpu(cpu);
-       }
+static bool reserve_pmc_hardware(void) { return true; }
+static void release_pmc_hardware(void) {}
 
-       put_online_cpus();
+#endif
 
-       return err;
-}
+static int reserve_ds_buffers(void);
+static void release_ds_buffers(void);
 
 static void hw_perf_event_destroy(struct perf_event *event)
 {
        if (atomic_dec_and_mutex_lock(&active_events, &pmc_reserve_mutex)) {
                release_pmc_hardware();
-               release_bts_hardware();
+               release_ds_buffers();
                mutex_unlock(&pmc_reserve_mutex);
        }
 }
@@ -441,54 +428,11 @@ set_ext_hw_attr(struct hw_perf_event *hwc, struct perf_event_attr *attr)
        return 0;
 }
 
-/*
- * Setup the hardware configuration for a given attr_type
- */
-static int __hw_perf_event_init(struct perf_event *event)
+static int x86_setup_perfctr(struct perf_event *event)
 {
        struct perf_event_attr *attr = &event->attr;
        struct hw_perf_event *hwc = &event->hw;
        u64 config;
-       int err;
-
-       if (!x86_pmu_initialized())
-               return -ENODEV;
-
-       err = 0;
-       if (!atomic_inc_not_zero(&active_events)) {
-               mutex_lock(&pmc_reserve_mutex);
-               if (atomic_read(&active_events) == 0) {
-                       if (!reserve_pmc_hardware())
-                               err = -EBUSY;
-                       else
-                               err = reserve_bts_hardware();
-               }
-               if (!err)
-                       atomic_inc(&active_events);
-               mutex_unlock(&pmc_reserve_mutex);
-       }
-       if (err)
-               return err;
-
-       event->destroy = hw_perf_event_destroy;
-
-       /*
-        * Generate PMC IRQs:
-        * (keep 'enabled' bit clear for now)
-        */
-       hwc->config = ARCH_PERFMON_EVENTSEL_INT;
-
-       hwc->idx = -1;
-       hwc->last_cpu = -1;
-       hwc->last_tag = ~0ULL;
-
-       /*
-        * Count user and OS events unless requested not to.
-        */
-       if (!attr->exclude_user)
-               hwc->config |= ARCH_PERFMON_EVENTSEL_USR;
-       if (!attr->exclude_kernel)
-               hwc->config |= ARCH_PERFMON_EVENTSEL_OS;
 
        if (!hwc->sample_period) {
                hwc->sample_period = x86_pmu.max_period;
@@ -505,16 +449,8 @@ static int __hw_perf_event_init(struct perf_event *event)
                        return -EOPNOTSUPP;
        }
 
-       /*
-        * Raw hw_event type provide the config in the hw_event structure
-        */
-       if (attr->type == PERF_TYPE_RAW) {
-               hwc->config |= x86_pmu.raw_event(attr->config);
-               if ((hwc->config & ARCH_PERFMON_EVENTSEL_ANY) &&
-                   perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
-                       return -EACCES;
+       if (attr->type == PERF_TYPE_RAW)
                return 0;
-       }
 
        if (attr->type == PERF_TYPE_HW_CACHE)
                return set_ext_hw_attr(hwc, attr);
@@ -539,11 +475,11 @@ static int __hw_perf_event_init(struct perf_event *event)
        if ((attr->config == PERF_COUNT_HW_BRANCH_INSTRUCTIONS) &&
            (hwc->sample_period == 1)) {
                /* BTS is not supported by this architecture. */
-               if (!bts_available())
+               if (!x86_pmu.bts)
                        return -EOPNOTSUPP;
 
                /* BTS is currently only allowed for user-mode. */
-               if (hwc->config & ARCH_PERFMON_EVENTSEL_OS)
+               if (!attr->exclude_kernel)
                        return -EOPNOTSUPP;
        }
 
@@ -552,12 +488,87 @@ static int __hw_perf_event_init(struct perf_event *event)
        return 0;
 }
 
+static int x86_pmu_hw_config(struct perf_event *event)
+{
+       if (event->attr.precise_ip) {
+               int precise = 0;
+
+               /* Support for constant skid */
+               if (x86_pmu.pebs)
+                       precise++;
+
+               /* Support for IP fixup */
+               if (x86_pmu.lbr_nr)
+                       precise++;
+
+               if (event->attr.precise_ip > precise)
+                       return -EOPNOTSUPP;
+       }
+
+       /*
+        * Generate PMC IRQs:
+        * (keep 'enabled' bit clear for now)
+        */
+       event->hw.config = ARCH_PERFMON_EVENTSEL_INT;
+
+       /*
+        * Count user and OS events unless requested not to
+        */
+       if (!event->attr.exclude_user)
+               event->hw.config |= ARCH_PERFMON_EVENTSEL_USR;
+       if (!event->attr.exclude_kernel)
+               event->hw.config |= ARCH_PERFMON_EVENTSEL_OS;
+
+       if (event->attr.type == PERF_TYPE_RAW)
+               event->hw.config |= event->attr.config & X86_RAW_EVENT_MASK;
+
+       return x86_setup_perfctr(event);
+}
+
+/*
+ * Setup the hardware configuration for a given attr_type
+ */
+static int __hw_perf_event_init(struct perf_event *event)
+{
+       int err;
+
+       if (!x86_pmu_initialized())
+               return -ENODEV;
+
+       err = 0;
+       if (!atomic_inc_not_zero(&active_events)) {
+               mutex_lock(&pmc_reserve_mutex);
+               if (atomic_read(&active_events) == 0) {
+                       if (!reserve_pmc_hardware())
+                               err = -EBUSY;
+                       else {
+                               err = reserve_ds_buffers();
+                               if (err)
+                                       release_pmc_hardware();
+                       }
+               }
+               if (!err)
+                       atomic_inc(&active_events);
+               mutex_unlock(&pmc_reserve_mutex);
+       }
+       if (err)
+               return err;
+
+       event->destroy = hw_perf_event_destroy;
+
+       event->hw.idx = -1;
+       event->hw.last_cpu = -1;
+       event->hw.last_tag = ~0ULL;
+
+       return x86_pmu.hw_config(event);
+}
+
 static void x86_pmu_disable_all(void)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        int idx;
 
-       for (idx = 0; idx < x86_pmu.num_events; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
                u64 val;
 
                if (!test_bit(idx, cpuc->active_mask))
@@ -587,12 +598,12 @@ void hw_perf_disable(void)
        x86_pmu.disable_all();
 }
 
-static void x86_pmu_enable_all(void)
+static void x86_pmu_enable_all(int added)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        int idx;
 
-       for (idx = 0; idx < x86_pmu.num_events; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
                struct perf_event *event = cpuc->events[idx];
                u64 val;
 
@@ -667,14 +678,14 @@ static int x86_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)
         * assign events to counters starting with most
         * constrained events.
         */
-       wmax = x86_pmu.num_events;
+       wmax = x86_pmu.num_counters;
 
        /*
         * when fixed event counters are present,
         * wmax is incremented by 1 to account
         * for one more choice
         */
-       if (x86_pmu.num_events_fixed)
+       if (x86_pmu.num_counters_fixed)
                wmax++;
 
        for (w = 1, num = n; num && w <= wmax; w++) {
@@ -724,7 +735,7 @@ static int collect_events(struct cpu_hw_events *cpuc, struct perf_event *leader,
        struct perf_event *event;
        int n, max_count;
 
-       max_count = x86_pmu.num_events + x86_pmu.num_events_fixed;
+       max_count = x86_pmu.num_counters + x86_pmu.num_counters_fixed;
 
        /* current number of events already accepted */
        n = cpuc->n_events;
@@ -795,7 +806,7 @@ void hw_perf_enable(void)
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        struct perf_event *event;
        struct hw_perf_event *hwc;
-       int i;
+       int i, added = cpuc->n_added;
 
        if (!x86_pmu_initialized())
                return;
@@ -847,19 +858,20 @@ void hw_perf_enable(void)
        cpuc->enabled = 1;
        barrier();
 
-       x86_pmu.enable_all();
+       x86_pmu.enable_all(added);
 }
 
-static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc)
+static inline void __x86_pmu_enable_event(struct hw_perf_event *hwc,
+                                         u64 enable_mask)
 {
-       (void)checking_wrmsrl(hwc->config_base + hwc->idx,
-                             hwc->config | ARCH_PERFMON_EVENTSEL_ENABLE);
+       wrmsrl(hwc->config_base + hwc->idx, hwc->config | enable_mask);
 }
 
 static inline void x86_pmu_disable_event(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
-       (void)checking_wrmsrl(hwc->config_base + hwc->idx, hwc->config);
+
+       wrmsrl(hwc->config_base + hwc->idx, hwc->config);
 }
 
 static DEFINE_PER_CPU(u64 [X86_PMC_IDX_MAX], pmc_prev_left);
@@ -874,7 +886,7 @@ x86_perf_event_set_period(struct perf_event *event)
        struct hw_perf_event *hwc = &event->hw;
        s64 left = atomic64_read(&hwc->period_left);
        s64 period = hwc->sample_period;
-       int err, ret = 0, idx = hwc->idx;
+       int ret = 0, idx = hwc->idx;
 
        if (idx == X86_PMC_IDX_FIXED_BTS)
                return 0;
@@ -912,8 +924,8 @@ x86_perf_event_set_period(struct perf_event *event)
         */
        atomic64_set(&hwc->prev_count, (u64)-left);
 
-       err = checking_wrmsrl(hwc->event_base + idx,
-                            (u64)(-left) & x86_pmu.event_mask);
+       wrmsrl(hwc->event_base + idx,
+                       (u64)(-left) & x86_pmu.cntval_mask);
 
        perf_event_update_userpage(event);
 
@@ -924,7 +936,8 @@ static void x86_pmu_enable_event(struct perf_event *event)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
        if (cpuc->enabled)
-               __x86_pmu_enable_event(&event->hw);
+               __x86_pmu_enable_event(&event->hw,
+                                      ARCH_PERFMON_EVENTSEL_ENABLE);
 }
 
 /*
@@ -950,7 +963,15 @@ static int x86_pmu_enable(struct perf_event *event)
        if (n < 0)
                return n;
 
-       ret = x86_schedule_events(cpuc, n, assign);
+       /*
+        * If group events scheduling transaction was started,
+        * skip the schedulability test here, it will be peformed
+        * at commit time(->commit_txn) as a whole
+        */
+       if (cpuc->group_flag & PERF_EVENT_TXN_STARTED)
+               goto out;
+
+       ret = x86_pmu.schedule_events(cpuc, n, assign);
        if (ret)
                return ret;
        /*
@@ -959,6 +980,7 @@ static int x86_pmu_enable(struct perf_event *event)
         */
        memcpy(cpuc->assign, assign, n*sizeof(int));
 
+out:
        cpuc->n_events = n;
        cpuc->n_added += n - n0;
 
@@ -991,11 +1013,12 @@ static void x86_pmu_unthrottle(struct perf_event *event)
 void perf_event_print_debug(void)
 {
        u64 ctrl, status, overflow, pmc_ctrl, pmc_count, prev_left, fixed;
+       u64 pebs;
        struct cpu_hw_events *cpuc;
        unsigned long flags;
        int cpu, idx;
 
-       if (!x86_pmu.num_events)
+       if (!x86_pmu.num_counters)
                return;
 
        local_irq_save(flags);
@@ -1008,16 +1031,18 @@ void perf_event_print_debug(void)
                rdmsrl(MSR_CORE_PERF_GLOBAL_STATUS, status);
                rdmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, overflow);
                rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR_CTRL, fixed);
+               rdmsrl(MSR_IA32_PEBS_ENABLE, pebs);
 
                pr_info("\n");
                pr_info("CPU#%d: ctrl:       %016llx\n", cpu, ctrl);
                pr_info("CPU#%d: status:     %016llx\n", cpu, status);
                pr_info("CPU#%d: overflow:   %016llx\n", cpu, overflow);
                pr_info("CPU#%d: fixed:      %016llx\n", cpu, fixed);
+               pr_info("CPU#%d: pebs:       %016llx\n", cpu, pebs);
        }
-       pr_info("CPU#%d: active:       %016llx\n", cpu, *(u64 *)cpuc->active_mask);
+       pr_info("CPU#%d: active:     %016llx\n", cpu, *(u64 *)cpuc->active_mask);
 
-       for (idx = 0; idx < x86_pmu.num_events; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
                rdmsrl(x86_pmu.eventsel + idx, pmc_ctrl);
                rdmsrl(x86_pmu.perfctr  + idx, pmc_count);
 
@@ -1030,7 +1055,7 @@ void perf_event_print_debug(void)
                pr_info("CPU#%d:   gen-PMC%d left:  %016llx\n",
                        cpu, idx, prev_left);
        }
-       for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++) {
                rdmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, pmc_count);
 
                pr_info("CPU#%d: fixed-PMC%d count: %016llx\n",
@@ -1095,7 +1120,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
 
        cpuc = &__get_cpu_var(cpu_hw_events);
 
-       for (idx = 0; idx < x86_pmu.num_events; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
                if (!test_bit(idx, cpuc->active_mask))
                        continue;
 
@@ -1103,7 +1128,7 @@ static int x86_pmu_handle_irq(struct pt_regs *regs)
                hwc = &event->hw;
 
                val = x86_perf_event_update(event);
-               if (val & (1ULL << (x86_pmu.event_bits - 1)))
+               if (val & (1ULL << (x86_pmu.cntval_bits - 1)))
                        continue;
 
                /*
@@ -1146,7 +1171,6 @@ void set_perf_event_pending(void)
 
 void perf_events_lapic_init(void)
 {
-#ifdef CONFIG_X86_LOCAL_APIC
        if (!x86_pmu.apic || !x86_pmu_initialized())
                return;
 
@@ -1154,7 +1178,6 @@ void perf_events_lapic_init(void)
         * Always use NMI for PMU
         */
        apic_write(APIC_LVTPC, APIC_DM_NMI);
-#endif
 }
 
 static int __kprobes
@@ -1178,9 +1201,7 @@ perf_event_nmi_handler(struct notifier_block *self,
 
        regs = args->regs;
 
-#ifdef CONFIG_X86_LOCAL_APIC
        apic_write(APIC_LVTPC, APIC_DM_NMI);
-#endif
        /*
         * Can't rely on the handled return value to say it was our NMI, two
         * events could trigger 'simultaneously' raising two back-to-back NMIs.
@@ -1217,118 +1238,11 @@ x86_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
        return &unconstrained;
 }
 
-static int x86_event_sched_in(struct perf_event *event,
-                         struct perf_cpu_context *cpuctx)
-{
-       int ret = 0;
-
-       event->state = PERF_EVENT_STATE_ACTIVE;
-       event->oncpu = smp_processor_id();
-       event->tstamp_running += event->ctx->time - event->tstamp_stopped;
-
-       if (!is_x86_event(event))
-               ret = event->pmu->enable(event);
-
-       if (!ret && !is_software_event(event))
-               cpuctx->active_oncpu++;
-
-       if (!ret && event->attr.exclusive)
-               cpuctx->exclusive = 1;
-
-       return ret;
-}
-
-static void x86_event_sched_out(struct perf_event *event,
-                           struct perf_cpu_context *cpuctx)
-{
-       event->state = PERF_EVENT_STATE_INACTIVE;
-       event->oncpu = -1;
-
-       if (!is_x86_event(event))
-               event->pmu->disable(event);
-
-       event->tstamp_running -= event->ctx->time - event->tstamp_stopped;
-
-       if (!is_software_event(event))
-               cpuctx->active_oncpu--;
-
-       if (event->attr.exclusive || !cpuctx->active_oncpu)
-               cpuctx->exclusive = 0;
-}
-
-/*
- * Called to enable a whole group of events.
- * Returns 1 if the group was enabled, or -EAGAIN if it could not be.
- * Assumes the caller has disabled interrupts and has
- * frozen the PMU with hw_perf_save_disable.
- *
- * called with PMU disabled. If successful and return value 1,
- * then guaranteed to call perf_enable() and hw_perf_enable()
- */
-int hw_perf_group_sched_in(struct perf_event *leader,
-              struct perf_cpu_context *cpuctx,
-              struct perf_event_context *ctx)
-{
-       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
-       struct perf_event *sub;
-       int assign[X86_PMC_IDX_MAX];
-       int n0, n1, ret;
-
-       /* n0 = total number of events */
-       n0 = collect_events(cpuc, leader, true);
-       if (n0 < 0)
-               return n0;
-
-       ret = x86_schedule_events(cpuc, n0, assign);
-       if (ret)
-               return ret;
-
-       ret = x86_event_sched_in(leader, cpuctx);
-       if (ret)
-               return ret;
-
-       n1 = 1;
-       list_for_each_entry(sub, &leader->sibling_list, group_entry) {
-               if (sub->state > PERF_EVENT_STATE_OFF) {
-                       ret = x86_event_sched_in(sub, cpuctx);
-                       if (ret)
-                               goto undo;
-                       ++n1;
-               }
-       }
-       /*
-        * copy new assignment, now we know it is possible
-        * will be used by hw_perf_enable()
-        */
-       memcpy(cpuc->assign, assign, n0*sizeof(int));
-
-       cpuc->n_events  = n0;
-       cpuc->n_added  += n1;
-       ctx->nr_active += n1;
-
-       /*
-        * 1 means successful and events are active
-        * This is not quite true because we defer
-        * actual activation until hw_perf_enable() but
-        * this way we* ensure caller won't try to enable
-        * individual events
-        */
-       return 1;
-undo:
-       x86_event_sched_out(leader, cpuctx);
-       n0  = 1;
-       list_for_each_entry(sub, &leader->sibling_list, group_entry) {
-               if (sub->state == PERF_EVENT_STATE_ACTIVE) {
-                       x86_event_sched_out(sub, cpuctx);
-                       if (++n0 == n1)
-                               break;
-               }
-       }
-       return ret;
-}
-
 #include "perf_event_amd.c"
 #include "perf_event_p6.c"
+#include "perf_event_p4.c"
+#include "perf_event_intel_lbr.c"
+#include "perf_event_intel_ds.c"
 #include "perf_event_intel.c"
 
 static int __cpuinit
@@ -1402,48 +1316,50 @@ void __init init_hw_perf_events(void)
 
        pr_cont("%s PMU driver.\n", x86_pmu.name);
 
-       if (x86_pmu.num_events > X86_PMC_MAX_GENERIC) {
+       if (x86_pmu.quirks)
+               x86_pmu.quirks();
+
+       if (x86_pmu.num_counters > X86_PMC_MAX_GENERIC) {
                WARN(1, KERN_ERR "hw perf events %d > max(%d), clipping!",
-                    x86_pmu.num_events, X86_PMC_MAX_GENERIC);
-               x86_pmu.num_events = X86_PMC_MAX_GENERIC;
+                    x86_pmu.num_counters, X86_PMC_MAX_GENERIC);
+               x86_pmu.num_counters = X86_PMC_MAX_GENERIC;
        }
-       perf_event_mask = (1 << x86_pmu.num_events) - 1;
-       perf_max_events = x86_pmu.num_events;
+       x86_pmu.intel_ctrl = (1 << x86_pmu.num_counters) - 1;
+       perf_max_events = x86_pmu.num_counters;
 
-       if (x86_pmu.num_events_fixed > X86_PMC_MAX_FIXED) {
+       if (x86_pmu.num_counters_fixed > X86_PMC_MAX_FIXED) {
                WARN(1, KERN_ERR "hw perf events fixed %d > max(%d), clipping!",
-                    x86_pmu.num_events_fixed, X86_PMC_MAX_FIXED);
-               x86_pmu.num_events_fixed = X86_PMC_MAX_FIXED;
+                    x86_pmu.num_counters_fixed, X86_PMC_MAX_FIXED);
+               x86_pmu.num_counters_fixed = X86_PMC_MAX_FIXED;
        }
 
-       perf_event_mask |=
-               ((1LL << x86_pmu.num_events_fixed)-1) << X86_PMC_IDX_FIXED;
-       x86_pmu.intel_ctrl = perf_event_mask;
+       x86_pmu.intel_ctrl |=
+               ((1LL << x86_pmu.num_counters_fixed)-1) << X86_PMC_IDX_FIXED;
 
        perf_events_lapic_init();
        register_die_notifier(&perf_event_nmi_notifier);
 
        unconstrained = (struct event_constraint)
-               __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_events) - 1,
-                                  0, x86_pmu.num_events);
+               __EVENT_CONSTRAINT(0, (1ULL << x86_pmu.num_counters) - 1,
+                                  0, x86_pmu.num_counters);
 
        if (x86_pmu.event_constraints) {
                for_each_event_constraint(c, x86_pmu.event_constraints) {
-                       if (c->cmask != INTEL_ARCH_FIXED_MASK)
+                       if (c->cmask != X86_RAW_EVENT_MASK)
                                continue;
 
-                       c->idxmsk64 |= (1ULL << x86_pmu.num_events) - 1;
-                       c->weight += x86_pmu.num_events;
+                       c->idxmsk64 |= (1ULL << x86_pmu.num_counters) - 1;
+                       c->weight += x86_pmu.num_counters;
                }
        }
 
        pr_info("... version:                %d\n",     x86_pmu.version);
-       pr_info("... bit width:              %d\n",     x86_pmu.event_bits);
-       pr_info("... generic registers:      %d\n",     x86_pmu.num_events);
-       pr_info("... value mask:             %016Lx\n", x86_pmu.event_mask);
+       pr_info("... bit width:              %d\n",     x86_pmu.cntval_bits);
+       pr_info("... generic registers:      %d\n",     x86_pmu.num_counters);
+       pr_info("... value mask:             %016Lx\n", x86_pmu.cntval_mask);
        pr_info("... max period:             %016Lx\n", x86_pmu.max_period);
-       pr_info("... fixed-purpose events:   %d\n",     x86_pmu.num_events_fixed);
-       pr_info("... event mask:             %016Lx\n", perf_event_mask);
+       pr_info("... fixed-purpose events:   %d\n",     x86_pmu.num_counters_fixed);
+       pr_info("... event mask:             %016Lx\n", x86_pmu.intel_ctrl);
 
        perf_cpu_notifier(x86_pmu_notifier);
 }
@@ -1453,6 +1369,59 @@ static inline void x86_pmu_read(struct perf_event *event)
        x86_perf_event_update(event);
 }
 
+/*
+ * Start group events scheduling transaction
+ * Set the flag to make pmu::enable() not perform the
+ * schedulability test, it will be performed at commit time
+ */
+static void x86_pmu_start_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       cpuc->group_flag |= PERF_EVENT_TXN_STARTED;
+}
+
+/*
+ * Stop group events scheduling transaction
+ * Clear the flag and pmu::enable() will perform the
+ * schedulability test.
+ */
+static void x86_pmu_cancel_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       cpuc->group_flag &= ~PERF_EVENT_TXN_STARTED;
+}
+
+/*
+ * Commit group events scheduling transaction
+ * Perform the group schedulability test as a whole
+ * Return 0 if success
+ */
+static int x86_pmu_commit_txn(const struct pmu *pmu)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       int assign[X86_PMC_IDX_MAX];
+       int n, ret;
+
+       n = cpuc->n_events;
+
+       if (!x86_pmu_initialized())
+               return -EAGAIN;
+
+       ret = x86_pmu.schedule_events(cpuc, n, assign);
+       if (ret)
+               return ret;
+
+       /*
+        * copy new assignment, now we know it is possible
+        * will be used by hw_perf_enable()
+        */
+       memcpy(cpuc->assign, assign, n*sizeof(int));
+
+       return 0;
+}
+
 static const struct pmu pmu = {
        .enable         = x86_pmu_enable,
        .disable        = x86_pmu_disable,
@@ -1460,8 +1429,37 @@ static const struct pmu pmu = {
        .stop           = x86_pmu_stop,
        .read           = x86_pmu_read,
        .unthrottle     = x86_pmu_unthrottle,
+       .start_txn      = x86_pmu_start_txn,
+       .cancel_txn     = x86_pmu_cancel_txn,
+       .commit_txn     = x86_pmu_commit_txn,
 };
 
+/*
+ * validate that we can schedule this event
+ */
+static int validate_event(struct perf_event *event)
+{
+       struct cpu_hw_events *fake_cpuc;
+       struct event_constraint *c;
+       int ret = 0;
+
+       fake_cpuc = kmalloc(sizeof(*fake_cpuc), GFP_KERNEL | __GFP_ZERO);
+       if (!fake_cpuc)
+               return -ENOMEM;
+
+       c = x86_pmu.get_event_constraints(fake_cpuc, event);
+
+       if (!c || !c->weight)
+               ret = -ENOSPC;
+
+       if (x86_pmu.put_event_constraints)
+               x86_pmu.put_event_constraints(fake_cpuc, event);
+
+       kfree(fake_cpuc);
+
+       return ret;
+}
+
 /*
  * validate a single event group
  *
@@ -1502,7 +1500,7 @@ static int validate_group(struct perf_event *event)
 
        fake_cpuc->n_events = n;
 
-       ret = x86_schedule_events(fake_cpuc, n, NULL);
+       ret = x86_pmu.schedule_events(fake_cpuc, n, NULL);
 
 out_free:
        kfree(fake_cpuc);
@@ -1527,6 +1525,8 @@ const struct pmu *hw_perf_event_init(struct perf_event *event)
 
                if (event->group_leader != event)
                        err = validate_group(event);
+               else
+                       err = validate_event(event);
 
                event->pmu = tmp;
        }
@@ -1574,8 +1574,7 @@ static void backtrace_address(void *data, unsigned long addr, int reliable)
 {
        struct perf_callchain_entry *entry = data;
 
-       if (reliable)
-               callchain_store(entry, addr);
+       callchain_store(entry, addr);
 }
 
 static const struct stacktrace_ops backtrace_ops = {
@@ -1597,41 +1596,6 @@ perf_callchain_kernel(struct pt_regs *regs, struct perf_callchain_entry *entry)
        dump_trace(NULL, regs, NULL, regs->bp, &backtrace_ops, entry);
 }
 
-/*
- * best effort, GUP based copy_from_user() that assumes IRQ or NMI context
- */
-static unsigned long
-copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
-{
-       unsigned long offset, addr = (unsigned long)from;
-       int type = in_nmi() ? KM_NMI : KM_IRQ0;
-       unsigned long size, len = 0;
-       struct page *page;
-       void *map;
-       int ret;
-
-       do {
-               ret = __get_user_pages_fast(addr, 1, 0, &page);
-               if (!ret)
-                       break;
-
-               offset = addr & (PAGE_SIZE - 1);
-               size = min(PAGE_SIZE - offset, n - len);
-
-               map = kmap_atomic(page, type);
-               memcpy(to, map+offset, size);
-               kunmap_atomic(map, type);
-               put_page(page);
-
-               len  += size;
-               to   += size;
-               addr += size;
-
-       } while (len < n);
-
-       return len;
-}
-
 #ifdef CONFIG_COMPAT
 static inline int
 perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
@@ -1727,6 +1691,11 @@ struct perf_callchain_entry *perf_callchain(struct pt_regs *regs)
 {
        struct perf_callchain_entry *entry;
 
+       if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+               /* TODO: We don't support guest os callchain now */
+               return NULL;
+       }
+
        if (in_nmi())
                entry = &__get_cpu_var(pmc_nmi_entry);
        else
@@ -1750,3 +1719,37 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski
        regs->cs = __KERNEL_CS;
        local_save_flags(regs->flags);
 }
+
+unsigned long perf_instruction_pointer(struct pt_regs *regs)
+{
+       unsigned long ip;
+
+       if (perf_guest_cbs && perf_guest_cbs->is_in_guest())
+               ip = perf_guest_cbs->get_guest_ip();
+       else
+               ip = instruction_pointer(regs);
+
+       return ip;
+}
+
+unsigned long perf_misc_flags(struct pt_regs *regs)
+{
+       int misc = 0;
+
+       if (perf_guest_cbs && perf_guest_cbs->is_in_guest()) {
+               if (perf_guest_cbs->is_user_mode())
+                       misc |= PERF_RECORD_MISC_GUEST_USER;
+               else
+                       misc |= PERF_RECORD_MISC_GUEST_KERNEL;
+       } else {
+               if (user_mode(regs))
+                       misc |= PERF_RECORD_MISC_USER;
+               else
+                       misc |= PERF_RECORD_MISC_KERNEL;
+       }
+
+       if (regs->flags & PERF_EFLAGS_EXACT)
+               misc |= PERF_RECORD_MISC_EXACT_IP;
+
+       return misc;
+}
index db6f7d4..611df11 100644 (file)
@@ -2,7 +2,7 @@
 
 static DEFINE_RAW_SPINLOCK(amd_nb_lock);
 
-static __initconst u64 amd_hw_cache_event_ids
+static __initconst const u64 amd_hw_cache_event_ids
                                [PERF_COUNT_HW_CACHE_MAX]
                                [PERF_COUNT_HW_CACHE_OP_MAX]
                                [PERF_COUNT_HW_CACHE_RESULT_MAX] =
@@ -111,22 +111,19 @@ static u64 amd_pmu_event_map(int hw_event)
        return amd_perfmon_event_map[hw_event];
 }
 
-static u64 amd_pmu_raw_event(u64 hw_event)
+static int amd_pmu_hw_config(struct perf_event *event)
 {
-#define K7_EVNTSEL_EVENT_MASK  0xF000000FFULL
-#define K7_EVNTSEL_UNIT_MASK   0x00000FF00ULL
-#define K7_EVNTSEL_EDGE_MASK   0x000040000ULL
-#define K7_EVNTSEL_INV_MASK    0x000800000ULL
-#define K7_EVNTSEL_REG_MASK    0x0FF000000ULL
-
-#define K7_EVNTSEL_MASK                        \
-       (K7_EVNTSEL_EVENT_MASK |        \
-        K7_EVNTSEL_UNIT_MASK  |        \
-        K7_EVNTSEL_EDGE_MASK  |        \
-        K7_EVNTSEL_INV_MASK   |        \
-        K7_EVNTSEL_REG_MASK)
-
-       return hw_event & K7_EVNTSEL_MASK;
+       int ret = x86_pmu_hw_config(event);
+
+       if (ret)
+               return ret;
+
+       if (event->attr.type != PERF_TYPE_RAW)
+               return 0;
+
+       event->hw.config |= event->attr.config & AMD64_RAW_EVENT_MASK;
+
+       return 0;
 }
 
 /*
@@ -165,7 +162,7 @@ static void amd_put_event_constraints(struct cpu_hw_events *cpuc,
         * be removed on one CPU at a time AND PMU is disabled
         * when we come here
         */
-       for (i = 0; i < x86_pmu.num_events; i++) {
+       for (i = 0; i < x86_pmu.num_counters; i++) {
                if (nb->owners[i] == event) {
                        cmpxchg(nb->owners+i, event, NULL);
                        break;
@@ -215,7 +212,7 @@ amd_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event)
        struct hw_perf_event *hwc = &event->hw;
        struct amd_nb *nb = cpuc->amd_nb;
        struct perf_event *old = NULL;
-       int max = x86_pmu.num_events;
+       int max = x86_pmu.num_counters;
        int i, j, k = -1;
 
        /*
@@ -293,7 +290,7 @@ static struct amd_nb *amd_alloc_nb(int cpu, int nb_id)
        /*
         * initialize all possible NB constraints
         */
-       for (i = 0; i < x86_pmu.num_events; i++) {
+       for (i = 0; i < x86_pmu.num_counters; i++) {
                __set_bit(i, nb->event_constraints[i].idxmsk);
                nb->event_constraints[i].weight = 1;
        }
@@ -371,21 +368,22 @@ static void amd_pmu_cpu_dead(int cpu)
        raw_spin_unlock(&amd_nb_lock);
 }
 
-static __initconst struct x86_pmu amd_pmu = {
+static __initconst const struct x86_pmu amd_pmu = {
        .name                   = "AMD",
        .handle_irq             = x86_pmu_handle_irq,
        .disable_all            = x86_pmu_disable_all,
        .enable_all             = x86_pmu_enable_all,
        .enable                 = x86_pmu_enable_event,
        .disable                = x86_pmu_disable_event,
+       .hw_config              = amd_pmu_hw_config,
+       .schedule_events        = x86_schedule_events,
        .eventsel               = MSR_K7_EVNTSEL0,
        .perfctr                = MSR_K7_PERFCTR0,
        .event_map              = amd_pmu_event_map,
-       .raw_event              = amd_pmu_raw_event,
        .max_events             = ARRAY_SIZE(amd_perfmon_event_map),
-       .num_events             = 4,
-       .event_bits             = 48,
-       .event_mask             = (1ULL << 48) - 1,
+       .num_counters           = 4,
+       .cntval_bits            = 48,
+       .cntval_mask            = (1ULL << 48) - 1,
        .apic                   = 1,
        /* use highest bit to detect overflow */
        .max_period             = (1ULL << 47) - 1,
index 9c794ac..fdbc652 100644 (file)
@@ -88,7 +88,7 @@ static u64 intel_pmu_event_map(int hw_event)
        return intel_perfmon_event_map[hw_event];
 }
 
-static __initconst u64 westmere_hw_cache_event_ids
+static __initconst const u64 westmere_hw_cache_event_ids
                                [PERF_COUNT_HW_CACHE_MAX]
                                [PERF_COUNT_HW_CACHE_OP_MAX]
                                [PERF_COUNT_HW_CACHE_RESULT_MAX] =
@@ -179,7 +179,7 @@ static __initconst u64 westmere_hw_cache_event_ids
  },
 };
 
-static __initconst u64 nehalem_hw_cache_event_ids
+static __initconst const u64 nehalem_hw_cache_event_ids
                                [PERF_COUNT_HW_CACHE_MAX]
                                [PERF_COUNT_HW_CACHE_OP_MAX]
                                [PERF_COUNT_HW_CACHE_RESULT_MAX] =
@@ -270,7 +270,7 @@ static __initconst u64 nehalem_hw_cache_event_ids
  },
 };
 
-static __initconst u64 core2_hw_cache_event_ids
+static __initconst const u64 core2_hw_cache_event_ids
                                [PERF_COUNT_HW_CACHE_MAX]
                                [PERF_COUNT_HW_CACHE_OP_MAX]
                                [PERF_COUNT_HW_CACHE_RESULT_MAX] =
@@ -361,7 +361,7 @@ static __initconst u64 core2_hw_cache_event_ids
  },
 };
 
-static __initconst u64 atom_hw_cache_event_ids
+static __initconst const u64 atom_hw_cache_event_ids
                                [PERF_COUNT_HW_CACHE_MAX]
                                [PERF_COUNT_HW_CACHE_OP_MAX]
                                [PERF_COUNT_HW_CACHE_RESULT_MAX] =
@@ -452,60 +452,6 @@ static __initconst u64 atom_hw_cache_event_ids
  },
 };
 
-static u64 intel_pmu_raw_event(u64 hw_event)
-{
-#define CORE_EVNTSEL_EVENT_MASK                0x000000FFULL
-#define CORE_EVNTSEL_UNIT_MASK         0x0000FF00ULL
-#define CORE_EVNTSEL_EDGE_MASK         0x00040000ULL
-#define CORE_EVNTSEL_INV_MASK          0x00800000ULL
-#define CORE_EVNTSEL_REG_MASK          0xFF000000ULL
-
-#define CORE_EVNTSEL_MASK              \
-       (INTEL_ARCH_EVTSEL_MASK |       \
-        INTEL_ARCH_UNIT_MASK   |       \
-        INTEL_ARCH_EDGE_MASK   |       \
-        INTEL_ARCH_INV_MASK    |       \
-        INTEL_ARCH_CNT_MASK)
-
-       return hw_event & CORE_EVNTSEL_MASK;
-}
-
-static void intel_pmu_enable_bts(u64 config)
-{
-       unsigned long debugctlmsr;
-
-       debugctlmsr = get_debugctlmsr();
-
-       debugctlmsr |= X86_DEBUGCTL_TR;
-       debugctlmsr |= X86_DEBUGCTL_BTS;
-       debugctlmsr |= X86_DEBUGCTL_BTINT;
-
-       if (!(config & ARCH_PERFMON_EVENTSEL_OS))
-               debugctlmsr |= X86_DEBUGCTL_BTS_OFF_OS;
-
-       if (!(config & ARCH_PERFMON_EVENTSEL_USR))
-               debugctlmsr |= X86_DEBUGCTL_BTS_OFF_USR;
-
-       update_debugctlmsr(debugctlmsr);
-}
-
-static void intel_pmu_disable_bts(void)
-{
-       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
-       unsigned long debugctlmsr;
-
-       if (!cpuc->ds)
-               return;
-
-       debugctlmsr = get_debugctlmsr();
-
-       debugctlmsr &=
-               ~(X86_DEBUGCTL_TR | X86_DEBUGCTL_BTS | X86_DEBUGCTL_BTINT |
-                 X86_DEBUGCTL_BTS_OFF_OS | X86_DEBUGCTL_BTS_OFF_USR);
-
-       update_debugctlmsr(debugctlmsr);
-}
-
 static void intel_pmu_disable_all(void)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
@@ -514,12 +460,17 @@ static void intel_pmu_disable_all(void)
 
        if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask))
                intel_pmu_disable_bts();
+
+       intel_pmu_pebs_disable_all();
+       intel_pmu_lbr_disable_all();
 }
 
-static void intel_pmu_enable_all(void)
+static void intel_pmu_enable_all(int added)
 {
        struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
 
+       intel_pmu_pebs_enable_all();
+       intel_pmu_lbr_enable_all();
        wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, x86_pmu.intel_ctrl);
 
        if (test_bit(X86_PMC_IDX_FIXED_BTS, cpuc->active_mask)) {
@@ -533,6 +484,42 @@ static void intel_pmu_enable_all(void)
        }
 }
 
+/*
+ * Workaround for:
+ *   Intel Errata AAK100 (model 26)
+ *   Intel Errata AAP53  (model 30)
+ *   Intel Errata BD53   (model 44)
+ *
+ * These chips need to be 'reset' when adding counters by programming
+ * the magic three (non counting) events 0x4300D2, 0x4300B1 and 0x4300B5
+ * either in sequence on the same PMC or on different PMCs.
+ */
+static void intel_pmu_nhm_enable_all(int added)
+{
+       if (added) {
+               struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+               int i;
+
+               wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 0, 0x4300D2);
+               wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 1, 0x4300B1);
+               wrmsrl(MSR_ARCH_PERFMON_EVENTSEL0 + 2, 0x4300B5);
+
+               wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x3);
+               wrmsrl(MSR_CORE_PERF_GLOBAL_CTRL, 0x0);
+
+               for (i = 0; i < 3; i++) {
+                       struct perf_event *event = cpuc->events[i];
+
+                       if (!event)
+                               continue;
+
+                       __x86_pmu_enable_event(&event->hw,
+                                              ARCH_PERFMON_EVENTSEL_ENABLE);
+               }
+       }
+       intel_pmu_enable_all(added);
+}
+
 static inline u64 intel_pmu_get_status(void)
 {
        u64 status;
@@ -547,8 +534,7 @@ static inline void intel_pmu_ack_status(u64 ack)
        wrmsrl(MSR_CORE_PERF_GLOBAL_OVF_CTRL, ack);
 }
 
-static inline void
-intel_pmu_disable_fixed(struct hw_perf_event *hwc)
+static void intel_pmu_disable_fixed(struct hw_perf_event *hwc)
 {
        int idx = hwc->idx - X86_PMC_IDX_FIXED;
        u64 ctrl_val, mask;
@@ -557,71 +543,10 @@ intel_pmu_disable_fixed(struct hw_perf_event *hwc)
 
        rdmsrl(hwc->config_base, ctrl_val);
        ctrl_val &= ~mask;
-       (void)checking_wrmsrl(hwc->config_base, ctrl_val);
-}
-
-static void intel_pmu_drain_bts_buffer(void)
-{
-       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
-       struct debug_store *ds = cpuc->ds;
-       struct bts_record {
-               u64     from;
-               u64     to;
-               u64     flags;
-       };
-       struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS];
-       struct bts_record *at, *top;
-       struct perf_output_handle handle;
-       struct perf_event_header header;
-       struct perf_sample_data data;
-       struct pt_regs regs;
-
-       if (!event)
-               return;
-
-       if (!ds)
-               return;
-
-       at  = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
-       top = (struct bts_record *)(unsigned long)ds->bts_index;
-
-       if (top <= at)
-               return;
-
-       ds->bts_index = ds->bts_buffer_base;
-
-       perf_sample_data_init(&data, 0);
-
-       data.period     = event->hw.last_period;
-       regs.ip         = 0;
-
-       /*
-        * Prepare a generic sample, i.e. fill in the invariant fields.
-        * We will overwrite the from and to address before we output
-        * the sample.
-        */
-       perf_prepare_sample(&header, &data, event, &regs);
-
-       if (perf_output_begin(&handle, event,
-                             header.size * (top - at), 1, 1))
-               return;
-
-       for (; at < top; at++) {
-               data.ip         = at->from;
-               data.addr       = at->to;
-
-               perf_output_sample(&handle, &header, &data, event);
-       }
-
-       perf_output_end(&handle);
-
-       /* There's new data available. */
-       event->hw.interrupts++;
-       event->pending_kill = POLL_IN;
+       wrmsrl(hwc->config_base, ctrl_val);
 }
 
-static inline void
-intel_pmu_disable_event(struct perf_event *event)
+static void intel_pmu_disable_event(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
 
@@ -637,14 +562,15 @@ intel_pmu_disable_event(struct perf_event *event)
        }
 
        x86_pmu_disable_event(event);
+
+       if (unlikely(event->attr.precise_ip))
+               intel_pmu_pebs_disable(event);
 }
 
-static inline void
-intel_pmu_enable_fixed(struct hw_perf_event *hwc)
+static void intel_pmu_enable_fixed(struct hw_perf_event *hwc)
 {
        int idx = hwc->idx - X86_PMC_IDX_FIXED;
        u64 ctrl_val, bits, mask;
-       int err;
 
        /*
         * Enable IRQ generation (0x8),
@@ -669,7 +595,7 @@ intel_pmu_enable_fixed(struct hw_perf_event *hwc)
        rdmsrl(hwc->config_base, ctrl_val);
        ctrl_val &= ~mask;
        ctrl_val |= bits;
-       err = checking_wrmsrl(hwc->config_base, ctrl_val);
+       wrmsrl(hwc->config_base, ctrl_val);
 }
 
 static void intel_pmu_enable_event(struct perf_event *event)
@@ -689,7 +615,10 @@ static void intel_pmu_enable_event(struct perf_event *event)
                return;
        }
 
-       __x86_pmu_enable_event(hwc);
+       if (unlikely(event->attr.precise_ip))
+               intel_pmu_pebs_enable(event);
+
+       __x86_pmu_enable_event(hwc, ARCH_PERFMON_EVENTSEL_ENABLE);
 }
 
 /*
@@ -708,20 +637,20 @@ static void intel_pmu_reset(void)
        unsigned long flags;
        int idx;
 
-       if (!x86_pmu.num_events)
+       if (!x86_pmu.num_counters)
                return;
 
        local_irq_save(flags);
 
        printk("clearing PMU state on CPU#%d\n", smp_processor_id());
 
-       for (idx = 0; idx < x86_pmu.num_events; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
                checking_wrmsrl(x86_pmu.eventsel + idx, 0ull);
                checking_wrmsrl(x86_pmu.perfctr  + idx, 0ull);
        }
-       for (idx = 0; idx < x86_pmu.num_events_fixed; idx++) {
+       for (idx = 0; idx < x86_pmu.num_counters_fixed; idx++)
                checking_wrmsrl(MSR_ARCH_PERFMON_FIXED_CTR0 + idx, 0ull);
-       }
+
        if (ds)
                ds->bts_index = ds->bts_buffer_base;
 
@@ -747,7 +676,7 @@ static int intel_pmu_handle_irq(struct pt_regs *regs)
        intel_pmu_drain_bts_buffer();
        status = intel_pmu_get_status();
        if (!status) {
-               intel_pmu_enable_all();
+               intel_pmu_enable_all(0);
                return 0;
        }
 
@@ -762,6 +691,15 @@ again:
 
        inc_irq_stat(apic_perf_irqs);
        ack = status;
+
+       intel_pmu_lbr_read();
+
+       /*
+        * PEBS overflow sets bit 62 in the global status register
+        */
+       if (__test_and_clear_bit(62, (unsigned long *)&status))
+               x86_pmu.drain_pebs(regs);
+
        for_each_set_bit(bit, (unsigned long *)&status, X86_PMC_IDX_MAX) {
                struct perf_event *event = cpuc->events[bit];
 
@@ -787,26 +725,22 @@ again:
                goto again;
 
 done:
-       intel_pmu_enable_all();
+       intel_pmu_enable_all(0);
        return 1;
 }
 
-static struct event_constraint bts_constraint =
-       EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0);
-
 static struct event_constraint *
-intel_special_constraints(struct perf_event *event)
+intel_bts_constraints(struct perf_event *event)
 {
-       unsigned int hw_event;
-
-       hw_event = event->hw.config & INTEL_ARCH_EVENT_MASK;
+       struct hw_perf_event *hwc = &event->hw;
+       unsigned int hw_event, bts_event;
 
-       if (unlikely((hw_event ==
-                     x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS)) &&
-                    (event->hw.sample_period == 1))) {
+       hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
+       bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
 
+       if (unlikely(hw_event == bts_event && hwc->sample_period == 1))
                return &bts_constraint;
-       }
+
        return NULL;
 }
 
@@ -815,24 +749,53 @@ intel_get_event_constraints(struct cpu_hw_events *cpuc, struct perf_event *event
 {
        struct event_constraint *c;
 
-       c = intel_special_constraints(event);
+       c = intel_bts_constraints(event);
+       if (c)
+               return c;
+
+       c = intel_pebs_constraints(event);
        if (c)
                return c;
 
        return x86_get_event_constraints(cpuc, event);
 }
 
-static __initconst struct x86_pmu core_pmu = {
+static int intel_pmu_hw_config(struct perf_event *event)
+{
+       int ret = x86_pmu_hw_config(event);
+
+       if (ret)
+               return ret;
+
+       if (event->attr.type != PERF_TYPE_RAW)
+               return 0;
+
+       if (!(event->attr.config & ARCH_PERFMON_EVENTSEL_ANY))
+               return 0;
+
+       if (x86_pmu.version < 3)
+               return -EINVAL;
+
+       if (perf_paranoid_cpu() && !capable(CAP_SYS_ADMIN))
+               return -EACCES;
+
+       event->hw.config |= ARCH_PERFMON_EVENTSEL_ANY;
+
+       return 0;
+}
+
+static __initconst const struct x86_pmu core_pmu = {
        .name                   = "core",
        .handle_irq             = x86_pmu_handle_irq,
        .disable_all            = x86_pmu_disable_all,
        .enable_all             = x86_pmu_enable_all,
        .enable                 = x86_pmu_enable_event,
        .disable                = x86_pmu_disable_event,
+       .hw_config              = x86_pmu_hw_config,
+       .schedule_events        = x86_schedule_events,
        .eventsel               = MSR_ARCH_PERFMON_EVENTSEL0,
        .perfctr                = MSR_ARCH_PERFMON_PERFCTR0,
        .event_map              = intel_pmu_event_map,
-       .raw_event              = intel_pmu_raw_event,
        .max_events             = ARRAY_SIZE(intel_perfmon_event_map),
        .apic                   = 1,
        /*
@@ -845,17 +808,32 @@ static __initconst struct x86_pmu core_pmu = {
        .event_constraints      = intel_core_event_constraints,
 };
 
-static __initconst struct x86_pmu intel_pmu = {
+static void intel_pmu_cpu_starting(int cpu)
+{
+       init_debug_store_on_cpu(cpu);
+       /*
+        * Deal with CPUs that don't clear their LBRs on power-up.
+        */
+       intel_pmu_lbr_reset();
+}
+
+static void intel_pmu_cpu_dying(int cpu)
+{
+       fini_debug_store_on_cpu(cpu);
+}
+
+static __initconst const struct x86_pmu intel_pmu = {
        .name                   = "Intel",
        .handle_irq             = intel_pmu_handle_irq,
        .disable_all            = intel_pmu_disable_all,
        .enable_all             = intel_pmu_enable_all,
        .enable                 = intel_pmu_enable_event,
        .disable                = intel_pmu_disable_event,
+       .hw_config              = intel_pmu_hw_config,
+       .schedule_events        = x86_schedule_events,
        .eventsel               = MSR_ARCH_PERFMON_EVENTSEL0,
        .perfctr                = MSR_ARCH_PERFMON_PERFCTR0,
        .event_map              = intel_pmu_event_map,
-       .raw_event              = intel_pmu_raw_event,
        .max_events             = ARRAY_SIZE(intel_perfmon_event_map),
        .apic                   = 1,
        /*
@@ -864,14 +842,38 @@ static __initconst struct x86_pmu intel_pmu = {
         * the generic event period:
         */
        .max_period             = (1ULL << 31) - 1,
-       .enable_bts             = intel_pmu_enable_bts,
-       .disable_bts            = intel_pmu_disable_bts,
        .get_event_constraints  = intel_get_event_constraints,
 
-       .cpu_starting           = init_debug_store_on_cpu,
-       .cpu_dying              = fini_debug_store_on_cpu,
+       .cpu_starting           = intel_pmu_cpu_starting,
+       .cpu_dying              = intel_pmu_cpu_dying,
 };
 
+static void intel_clovertown_quirks(void)
+{
+       /*
+        * PEBS is unreliable due to:
+        *
+        *   AJ67  - PEBS may experience CPL leaks
+        *   AJ68  - PEBS PMI may be delayed by one event
+        *   AJ69  - GLOBAL_STATUS[62] will only be set when DEBUGCTL[12]
+        *   AJ106 - FREEZE_LBRS_ON_PMI doesn't work in combination with PEBS
+        *
+        * AJ67 could be worked around by restricting the OS/USR flags.
+        * AJ69 could be worked around by setting PMU_FREEZE_ON_PMI.
+        *
+        * AJ106 could possibly be worked around by not allowing LBR
+        *       usage from PEBS, including the fixup.
+        * AJ68  could possibly be worked around by always programming
+        *       a pebs_event_reset[0] value and coping with the lost events.
+        *
+        * But taken together it might just make sense to not enable PEBS on
+        * these chips.
+        */
+       printk(KERN_WARNING "PEBS disabled due to CPU errata.\n");
+       x86_pmu.pebs = 0;
+       x86_pmu.pebs_constraints = NULL;
+}
+
 static __init int intel_pmu_init(void)
 {
        union cpuid10_edx edx;
@@ -881,12 +883,13 @@ static __init int intel_pmu_init(void)
        int version;
 
        if (!cpu_has(&boot_cpu_data, X86_FEATURE_ARCH_PERFMON)) {
-               /* check for P6 processor family */
-          if (boot_cpu_data.x86 == 6) {
-               return p6_pmu_init();
-          } else {
+               switch (boot_cpu_data.x86) {
+               case 0x6:
+                       return p6_pmu_init();
+               case 0xf:
+                       return p4_pmu_init();
+               }
                return -ENODEV;
-          }
        }
 
        /*
@@ -904,16 +907,28 @@ static __init int intel_pmu_init(void)
                x86_pmu = intel_pmu;
 
        x86_pmu.version                 = version;
-       x86_pmu.num_events              = eax.split.num_events;
-       x86_pmu.event_bits              = eax.split.bit_width;
-       x86_pmu.event_mask              = (1ULL << eax.split.bit_width) - 1;
+       x86_pmu.num_counters            = eax.split.num_counters;
+       x86_pmu.cntval_bits             = eax.split.bit_width;
+       x86_pmu.cntval_mask             = (1ULL << eax.split.bit_width) - 1;
 
        /*
         * Quirk: v2 perfmon does not report fixed-purpose events, so
         * assume at least 3 events:
         */
        if (version > 1)
-               x86_pmu.num_events_fixed = max((int)edx.split.num_events_fixed, 3);
+               x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
+
+       /*
+        * v2 and above have a perf capabilities MSR
+        */
+       if (version > 1) {
+               u64 capabilities;
+
+               rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
+               x86_pmu.intel_cap.capabilities = capabilities;
+       }
+
+       intel_ds_init();
 
        /*
         * Install the hw-cache-events table:
@@ -924,12 +939,15 @@ static __init int intel_pmu_init(void)
                break;
 
        case 15: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */
+               x86_pmu.quirks = intel_clovertown_quirks;
        case 22: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */
        case 23: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */
        case 29: /* six-core 45 nm xeon "Dunnington" */
                memcpy(hw_cache_event_ids, core2_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
 
+               intel_pmu_lbr_init_core();
+
                x86_pmu.event_constraints = intel_core2_event_constraints;
                pr_cont("Core2 events, ");
                break;
@@ -940,13 +958,19 @@ static __init int intel_pmu_init(void)
                memcpy(hw_cache_event_ids, nehalem_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
 
+               intel_pmu_lbr_init_nhm();
+
                x86_pmu.event_constraints = intel_nehalem_event_constraints;
-               pr_cont("Nehalem/Corei7 events, ");
+               x86_pmu.enable_all = intel_pmu_nhm_enable_all;
+               pr_cont("Nehalem events, ");
                break;
+
        case 28: /* Atom */
                memcpy(hw_cache_event_ids, atom_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
 
+               intel_pmu_lbr_init_atom();
+
                x86_pmu.event_constraints = intel_gen_event_constraints;
                pr_cont("Atom events, ");
                break;
@@ -956,7 +980,10 @@ static __init int intel_pmu_init(void)
                memcpy(hw_cache_event_ids, westmere_hw_cache_event_ids,
                       sizeof(hw_cache_event_ids));
 
+               intel_pmu_lbr_init_nhm();
+
                x86_pmu.event_constraints = intel_westmere_event_constraints;
+               x86_pmu.enable_all = intel_pmu_nhm_enable_all;
                pr_cont("Westmere events, ");
                break;
 
diff --git a/arch/x86/kernel/cpu/perf_event_intel_ds.c b/arch/x86/kernel/cpu/perf_event_intel_ds.c
new file mode 100644 (file)
index 0000000..18018d1
--- /dev/null
@@ -0,0 +1,641 @@
+#ifdef CONFIG_CPU_SUP_INTEL
+
+/* The maximal number of PEBS events: */
+#define MAX_PEBS_EVENTS                4
+
+/* The size of a BTS record in bytes: */
+#define BTS_RECORD_SIZE                24
+
+#define BTS_BUFFER_SIZE                (PAGE_SIZE << 4)
+#define PEBS_BUFFER_SIZE       PAGE_SIZE
+
+/*
+ * pebs_record_32 for p4 and core not supported
+
+struct pebs_record_32 {
+       u32 flags, ip;
+       u32 ax, bc, cx, dx;
+       u32 si, di, bp, sp;
+};
+
+ */
+
+struct pebs_record_core {
+       u64 flags, ip;
+       u64 ax, bx, cx, dx;
+       u64 si, di, bp, sp;
+       u64 r8,  r9,  r10, r11;
+       u64 r12, r13, r14, r15;
+};
+
+struct pebs_record_nhm {
+       u64 flags, ip;
+       u64 ax, bx, cx, dx;
+       u64 si, di, bp, sp;
+       u64 r8,  r9,  r10, r11;
+       u64 r12, r13, r14, r15;
+       u64 status, dla, dse, lat;
+};
+
+/*
+ * A debug store configuration.
+ *
+ * We only support architectures that use 64bit fields.
+ */
+struct debug_store {
+       u64     bts_buffer_base;
+       u64     bts_index;
+       u64     bts_absolute_maximum;
+       u64     bts_interrupt_threshold;
+       u64     pebs_buffer_base;
+       u64     pebs_index;
+       u64     pebs_absolute_maximum;
+       u64     pebs_interrupt_threshold;
+       u64     pebs_event_reset[MAX_PEBS_EVENTS];
+};
+
+static void init_debug_store_on_cpu(int cpu)
+{
+       struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
+
+       if (!ds)
+               return;
+
+       wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA,
+                    (u32)((u64)(unsigned long)ds),
+                    (u32)((u64)(unsigned long)ds >> 32));
+}
+
+static void fini_debug_store_on_cpu(int cpu)
+{
+       if (!per_cpu(cpu_hw_events, cpu).ds)
+               return;
+
+       wrmsr_on_cpu(cpu, MSR_IA32_DS_AREA, 0, 0);
+}
+
+static void release_ds_buffers(void)
+{
+       int cpu;
+
+       if (!x86_pmu.bts && !x86_pmu.pebs)
+               return;
+
+       get_online_cpus();
+
+       for_each_online_cpu(cpu)
+               fini_debug_store_on_cpu(cpu);
+
+       for_each_possible_cpu(cpu) {
+               struct debug_store *ds = per_cpu(cpu_hw_events, cpu).ds;
+
+               if (!ds)
+                       continue;
+
+               per_cpu(cpu_hw_events, cpu).ds = NULL;
+
+               kfree((void *)(unsigned long)ds->pebs_buffer_base);
+               kfree((void *)(unsigned long)ds->bts_buffer_base);
+               kfree(ds);
+       }
+
+       put_online_cpus();
+}
+
+static int reserve_ds_buffers(void)
+{
+       int cpu, err = 0;
+
+       if (!x86_pmu.bts && !x86_pmu.pebs)
+               return 0;
+
+       get_online_cpus();
+
+       for_each_possible_cpu(cpu) {
+               struct debug_store *ds;
+               void *buffer;
+               int max, thresh;
+
+               err = -ENOMEM;
+               ds = kzalloc(sizeof(*ds), GFP_KERNEL);
+               if (unlikely(!ds))
+                       break;
+               per_cpu(cpu_hw_events, cpu).ds = ds;
+
+               if (x86_pmu.bts) {
+                       buffer = kzalloc(BTS_BUFFER_SIZE, GFP_KERNEL);
+                       if (unlikely(!buffer))
+                               break;
+
+                       max = BTS_BUFFER_SIZE / BTS_RECORD_SIZE;
+                       thresh = max / 16;
+
+                       ds->bts_buffer_base = (u64)(unsigned long)buffer;
+                       ds->bts_index = ds->bts_buffer_base;
+                       ds->bts_absolute_maximum = ds->bts_buffer_base +
+                               max * BTS_RECORD_SIZE;
+                       ds->bts_interrupt_threshold = ds->bts_absolute_maximum -
+                               thresh * BTS_RECORD_SIZE;
+               }
+
+               if (x86_pmu.pebs) {
+                       buffer = kzalloc(PEBS_BUFFER_SIZE, GFP_KERNEL);
+                       if (unlikely(!buffer))
+                               break;
+
+                       max = PEBS_BUFFER_SIZE / x86_pmu.pebs_record_size;
+
+                       ds->pebs_buffer_base = (u64)(unsigned long)buffer;
+                       ds->pebs_index = ds->pebs_buffer_base;
+                       ds->pebs_absolute_maximum = ds->pebs_buffer_base +
+                               max * x86_pmu.pebs_record_size;
+                       /*
+                        * Always use single record PEBS
+                        */
+                       ds->pebs_interrupt_threshold = ds->pebs_buffer_base +
+                               x86_pmu.pebs_record_size;
+               }
+
+               err = 0;
+       }
+
+       if (err)
+               release_ds_buffers();
+       else {
+               for_each_online_cpu(cpu)
+                       init_debug_store_on_cpu(cpu);
+       }
+
+       put_online_cpus();
+
+       return err;
+}
+
+/*
+ * BTS
+ */
+
+static struct event_constraint bts_constraint =
+       EVENT_CONSTRAINT(0, 1ULL << X86_PMC_IDX_FIXED_BTS, 0);
+
+static void intel_pmu_enable_bts(u64 config)
+{
+       unsigned long debugctlmsr;
+
+       debugctlmsr = get_debugctlmsr();
+
+       debugctlmsr |= DEBUGCTLMSR_TR;
+       debugctlmsr |= DEBUGCTLMSR_BTS;
+       debugctlmsr |= DEBUGCTLMSR_BTINT;
+
+       if (!(config & ARCH_PERFMON_EVENTSEL_OS))
+               debugctlmsr |= DEBUGCTLMSR_BTS_OFF_OS;
+
+       if (!(config & ARCH_PERFMON_EVENTSEL_USR))
+               debugctlmsr |= DEBUGCTLMSR_BTS_OFF_USR;
+
+       update_debugctlmsr(debugctlmsr);
+}
+
+static void intel_pmu_disable_bts(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       unsigned long debugctlmsr;
+
+       if (!cpuc->ds)
+               return;
+
+       debugctlmsr = get_debugctlmsr();
+
+       debugctlmsr &=
+               ~(DEBUGCTLMSR_TR | DEBUGCTLMSR_BTS | DEBUGCTLMSR_BTINT |
+                 DEBUGCTLMSR_BTS_OFF_OS | DEBUGCTLMSR_BTS_OFF_USR);
+
+       update_debugctlmsr(debugctlmsr);
+}
+
+static void intel_pmu_drain_bts_buffer(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       struct debug_store *ds = cpuc->ds;
+       struct bts_record {
+               u64     from;
+               u64     to;
+               u64     flags;
+       };
+       struct perf_event *event = cpuc->events[X86_PMC_IDX_FIXED_BTS];
+       struct bts_record *at, *top;
+       struct perf_output_handle handle;
+       struct perf_event_header header;
+       struct perf_sample_data data;
+       struct pt_regs regs;
+
+       if (!event)
+               return;
+
+       if (!ds)
+               return;
+
+       at  = (struct bts_record *)(unsigned long)ds->bts_buffer_base;
+       top = (struct bts_record *)(unsigned long)ds->bts_index;
+
+       if (top <= at)
+               return;
+
+       ds->bts_index = ds->bts_buffer_base;
+
+       perf_sample_data_init(&data, 0);
+       data.period = event->hw.last_period;
+       regs.ip     = 0;
+
+       /*
+        * Prepare a generic sample, i.e. fill in the invariant fields.
+        * We will overwrite the from and to address before we output
+        * the sample.
+        */
+       perf_prepare_sample(&header, &data, event, &regs);
+
+       if (perf_output_begin(&handle, event, header.size * (top - at), 1, 1))
+               return;
+
+       for (; at < top; at++) {
+               data.ip         = at->from;
+               data.addr       = at->to;
+
+               perf_output_sample(&handle, &header, &data, event);
+       }
+
+       perf_output_end(&handle);
+
+       /* There's new data available. */
+       event->hw.interrupts++;
+       event->pending_kill = POLL_IN;
+}
+
+/*
+ * PEBS
+ */
+
+static struct event_constraint intel_core_pebs_events[] = {
+       PEBS_EVENT_CONSTRAINT(0x00c0, 0x1), /* INSTR_RETIRED.ANY */
+       PEBS_EVENT_CONSTRAINT(0xfec1, 0x1), /* X87_OPS_RETIRED.ANY */
+       PEBS_EVENT_CONSTRAINT(0x00c5, 0x1), /* BR_INST_RETIRED.MISPRED */
+       PEBS_EVENT_CONSTRAINT(0x1fc7, 0x1), /* SIMD_INST_RETURED.ANY */
+       PEBS_EVENT_CONSTRAINT(0x01cb, 0x1), /* MEM_LOAD_RETIRED.L1D_MISS */
+       PEBS_EVENT_CONSTRAINT(0x02cb, 0x1), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */
+       PEBS_EVENT_CONSTRAINT(0x04cb, 0x1), /* MEM_LOAD_RETIRED.L2_MISS */
+       PEBS_EVENT_CONSTRAINT(0x08cb, 0x1), /* MEM_LOAD_RETIRED.L2_LINE_MISS */
+       PEBS_EVENT_CONSTRAINT(0x10cb, 0x1), /* MEM_LOAD_RETIRED.DTLB_MISS */
+       EVENT_CONSTRAINT_END
+};
+
+static struct event_constraint intel_nehalem_pebs_events[] = {
+       PEBS_EVENT_CONSTRAINT(0x00c0, 0xf), /* INSTR_RETIRED.ANY */
+       PEBS_EVENT_CONSTRAINT(0xfec1, 0xf), /* X87_OPS_RETIRED.ANY */
+       PEBS_EVENT_CONSTRAINT(0x00c5, 0xf), /* BR_INST_RETIRED.MISPRED */
+       PEBS_EVENT_CONSTRAINT(0x1fc7, 0xf), /* SIMD_INST_RETURED.ANY */
+       PEBS_EVENT_CONSTRAINT(0x01cb, 0xf), /* MEM_LOAD_RETIRED.L1D_MISS */
+       PEBS_EVENT_CONSTRAINT(0x02cb, 0xf), /* MEM_LOAD_RETIRED.L1D_LINE_MISS */
+       PEBS_EVENT_CONSTRAINT(0x04cb, 0xf), /* MEM_LOAD_RETIRED.L2_MISS */
+       PEBS_EVENT_CONSTRAINT(0x08cb, 0xf), /* MEM_LOAD_RETIRED.L2_LINE_MISS */
+       PEBS_EVENT_CONSTRAINT(0x10cb, 0xf), /* MEM_LOAD_RETIRED.DTLB_MISS */
+       EVENT_CONSTRAINT_END
+};
+
+static struct event_constraint *
+intel_pebs_constraints(struct perf_event *event)
+{
+       struct event_constraint *c;
+
+       if (!event->attr.precise_ip)
+               return NULL;
+
+       if (x86_pmu.pebs_constraints) {
+               for_each_event_constraint(c, x86_pmu.pebs_constraints) {
+                       if ((event->hw.config & c->cmask) == c->code)
+                               return c;
+               }
+       }
+
+       return &emptyconstraint;
+}
+
+static void intel_pmu_pebs_enable(struct perf_event *event)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       struct hw_perf_event *hwc = &event->hw;
+
+       hwc->config &= ~ARCH_PERFMON_EVENTSEL_INT;
+
+       cpuc->pebs_enabled |= 1ULL << hwc->idx;
+       WARN_ON_ONCE(cpuc->enabled);
+
+       if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1)
+               intel_pmu_lbr_enable(event);
+}
+
+static void intel_pmu_pebs_disable(struct perf_event *event)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       struct hw_perf_event *hwc = &event->hw;
+
+       cpuc->pebs_enabled &= ~(1ULL << hwc->idx);
+       if (cpuc->enabled)
+               wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
+
+       hwc->config |= ARCH_PERFMON_EVENTSEL_INT;
+
+       if (x86_pmu.intel_cap.pebs_trap && event->attr.precise_ip > 1)
+               intel_pmu_lbr_disable(event);
+}
+
+static void intel_pmu_pebs_enable_all(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (cpuc->pebs_enabled)
+               wrmsrl(MSR_IA32_PEBS_ENABLE, cpuc->pebs_enabled);
+}
+
+static void intel_pmu_pebs_disable_all(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (cpuc->pebs_enabled)
+               wrmsrl(MSR_IA32_PEBS_ENABLE, 0);
+}
+
+#include <asm/insn.h>
+
+static inline bool kernel_ip(unsigned long ip)
+{
+#ifdef CONFIG_X86_32
+       return ip > PAGE_OFFSET;
+#else
+       return (long)ip < 0;
+#endif
+}
+
+static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       unsigned long from = cpuc->lbr_entries[0].from;
+       unsigned long old_to, to = cpuc->lbr_entries[0].to;
+       unsigned long ip = regs->ip;
+
+       /*
+        * We don't need to fixup if the PEBS assist is fault like
+        */
+       if (!x86_pmu.intel_cap.pebs_trap)
+               return 1;
+
+       /*
+        * No LBR entry, no basic block, no rewinding
+        */
+       if (!cpuc->lbr_stack.nr || !from || !to)
+               return 0;
+
+       /*
+        * Basic blocks should never cross user/kernel boundaries
+        */
+       if (kernel_ip(ip) != kernel_ip(to))
+               return 0;
+
+       /*
+        * unsigned math, either ip is before the start (impossible) or
+        * the basic block is larger than 1 page (sanity)
+        */
+       if ((ip - to) > PAGE_SIZE)
+               return 0;
+
+       /*
+        * We sampled a branch insn, rewind using the LBR stack
+        */
+       if (ip == to) {
+               regs->ip = from;
+               return 1;
+       }
+
+       do {
+               struct insn insn;
+               u8 buf[MAX_INSN_SIZE];
+               void *kaddr;
+
+               old_to = to;
+               if (!kernel_ip(ip)) {
+                       int bytes, size = MAX_INSN_SIZE;
+
+                       bytes = copy_from_user_nmi(buf, (void __user *)to, size);
+                       if (bytes != size)
+                               return 0;
+
+                       kaddr = buf;
+               } else
+                       kaddr = (void *)to;
+
+               kernel_insn_init(&insn, kaddr);
+               insn_get_length(&insn);
+               to += insn.length;
+       } while (to < ip);
+
+       if (to == ip) {
+               regs->ip = old_to;
+               return 1;
+       }
+
+       /*
+        * Even though we decoded the basic block, the instruction stream
+        * never matched the given IP, either the TO or the IP got corrupted.
+        */
+       return 0;
+}
+
+static int intel_pmu_save_and_restart(struct perf_event *event);
+
+static void __intel_pmu_pebs_event(struct perf_event *event,
+                                  struct pt_regs *iregs, void *__pebs)
+{
+       /*
+        * We cast to pebs_record_core since that is a subset of
+        * both formats and we don't use the other fields in this
+        * routine.
+        */
+       struct pebs_record_core *pebs = __pebs;
+       struct perf_sample_data data;
+       struct pt_regs regs;
+
+       if (!intel_pmu_save_and_restart(event))
+               return;
+
+       perf_sample_data_init(&data, 0);
+       data.period = event->hw.last_period;
+
+       /*
+        * We use the interrupt regs as a base because the PEBS record
+        * does not contain a full regs set, specifically it seems to
+        * lack segment descriptors, which get used by things like
+        * user_mode().
+        *
+        * In the simple case fix up only the IP and BP,SP regs, for
+        * PERF_SAMPLE_IP and PERF_SAMPLE_CALLCHAIN to function properly.
+        * A possible PERF_SAMPLE_REGS will have to transfer all regs.
+        */
+       regs = *iregs;
+       regs.ip = pebs->ip;
+       regs.bp = pebs->bp;
+       regs.sp = pebs->sp;
+
+       if (event->attr.precise_ip > 1 && intel_pmu_pebs_fixup_ip(&regs))
+               regs.flags |= PERF_EFLAGS_EXACT;
+       else
+               regs.flags &= ~PERF_EFLAGS_EXACT;
+
+       if (perf_event_overflow(event, 1, &data, &regs))
+               x86_pmu_stop(event);
+}
+
+static void intel_pmu_drain_pebs_core(struct pt_regs *iregs)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       struct debug_store *ds = cpuc->ds;
+       struct perf_event *event = cpuc->events[0]; /* PMC0 only */
+       struct pebs_record_core *at, *top;
+       int n;
+
+       if (!ds || !x86_pmu.pebs)
+               return;
+
+       at  = (struct pebs_record_core *)(unsigned long)ds->pebs_buffer_base;
+       top = (struct pebs_record_core *)(unsigned long)ds->pebs_index;
+
+       /*
+        * Whatever else happens, drain the thing
+        */
+       ds->pebs_index = ds->pebs_buffer_base;
+
+       if (!test_bit(0, cpuc->active_mask))
+               return;
+
+       WARN_ON_ONCE(!event);
+
+       if (!event->attr.precise_ip)
+               return;
+
+       n = top - at;
+       if (n <= 0)
+               return;
+
+       /*
+        * Should not happen, we program the threshold at 1 and do not
+        * set a reset value.
+        */
+       WARN_ON_ONCE(n > 1);
+       at += n - 1;
+
+       __intel_pmu_pebs_event(event, iregs, at);
+}
+
+static void intel_pmu_drain_pebs_nhm(struct pt_regs *iregs)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       struct debug_store *ds = cpuc->ds;
+       struct pebs_record_nhm *at, *top;
+       struct perf_event *event = NULL;
+       u64 status = 0;
+       int bit, n;
+
+       if (!ds || !x86_pmu.pebs)
+               return;
+
+       at  = (struct pebs_record_nhm *)(unsigned long)ds->pebs_buffer_base;
+       top = (struct pebs_record_nhm *)(unsigned long)ds->pebs_index;
+
+       ds->pebs_index = ds->pebs_buffer_base;
+
+       n = top - at;
+       if (n <= 0)
+               return;
+
+       /*
+        * Should not happen, we program the threshold at 1 and do not
+        * set a reset value.
+        */
+       WARN_ON_ONCE(n > MAX_PEBS_EVENTS);
+
+       for ( ; at < top; at++) {
+               for_each_set_bit(bit, (unsigned long *)&at->status, MAX_PEBS_EVENTS) {
+                       event = cpuc->events[bit];
+                       if (!test_bit(bit, cpuc->active_mask))
+                               continue;
+
+                       WARN_ON_ONCE(!event);
+
+                       if (!event->attr.precise_ip)
+                               continue;
+
+                       if (__test_and_set_bit(bit, (unsigned long *)&status))
+                               continue;
+
+                       break;
+               }
+
+               if (!event || bit >= MAX_PEBS_EVENTS)
+                       continue;
+
+               __intel_pmu_pebs_event(event, iregs, at);
+       }
+}
+
+/*
+ * BTS, PEBS probe and setup
+ */
+
+static void intel_ds_init(void)
+{
+       /*
+        * No support for 32bit formats
+        */
+       if (!boot_cpu_has(X86_FEATURE_DTES64))
+               return;
+
+       x86_pmu.bts  = boot_cpu_has(X86_FEATURE_BTS);
+       x86_pmu.pebs = boot_cpu_has(X86_FEATURE_PEBS);
+       if (x86_pmu.pebs) {
+               char pebs_type = x86_pmu.intel_cap.pebs_trap ?  '+' : '-';
+               int format = x86_pmu.intel_cap.pebs_format;
+
+               switch (format) {
+               case 0:
+                       printk(KERN_CONT "PEBS fmt0%c, ", pebs_type);
+                       x86_pmu.pebs_record_size = sizeof(struct pebs_record_core);
+                       x86_pmu.drain_pebs = intel_pmu_drain_pebs_core;
+                       x86_pmu.pebs_constraints = intel_core_pebs_events;
+                       break;
+
+               case 1:
+                       printk(KERN_CONT "PEBS fmt1%c, ", pebs_type);
+                       x86_pmu.pebs_record_size = sizeof(struct pebs_record_nhm);
+                       x86_pmu.drain_pebs = intel_pmu_drain_pebs_nhm;
+                       x86_pmu.pebs_constraints = intel_nehalem_pebs_events;
+                       break;
+
+               default:
+                       printk(KERN_CONT "no PEBS fmt%d%c, ", format, pebs_type);
+                       x86_pmu.pebs = 0;
+                       break;
+               }
+       }
+}
+
+#else /* CONFIG_CPU_SUP_INTEL */
+
+static int reserve_ds_buffers(void)
+{
+       return 0;
+}
+
+static void release_ds_buffers(void)
+{
+}
+
+#endif /* CONFIG_CPU_SUP_INTEL */
diff --git a/arch/x86/kernel/cpu/perf_event_intel_lbr.c b/arch/x86/kernel/cpu/perf_event_intel_lbr.c
new file mode 100644 (file)
index 0000000..d202c1b
--- /dev/null
@@ -0,0 +1,218 @@
+#ifdef CONFIG_CPU_SUP_INTEL
+
+enum {
+       LBR_FORMAT_32           = 0x00,
+       LBR_FORMAT_LIP          = 0x01,
+       LBR_FORMAT_EIP          = 0x02,
+       LBR_FORMAT_EIP_FLAGS    = 0x03,
+};
+
+/*
+ * We only support LBR implementations that have FREEZE_LBRS_ON_PMI
+ * otherwise it becomes near impossible to get a reliable stack.
+ */
+
+static void __intel_pmu_lbr_enable(void)
+{
+       u64 debugctl;
+
+       rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+       debugctl |= (DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI);
+       wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+}
+
+static void __intel_pmu_lbr_disable(void)
+{
+       u64 debugctl;
+
+       rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+       debugctl &= ~(DEBUGCTLMSR_LBR | DEBUGCTLMSR_FREEZE_LBRS_ON_PMI);
+       wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctl);
+}
+
+static void intel_pmu_lbr_reset_32(void)
+{
+       int i;
+
+       for (i = 0; i < x86_pmu.lbr_nr; i++)
+               wrmsrl(x86_pmu.lbr_from + i, 0);
+}
+
+static void intel_pmu_lbr_reset_64(void)
+{
+       int i;
+
+       for (i = 0; i < x86_pmu.lbr_nr; i++) {
+               wrmsrl(x86_pmu.lbr_from + i, 0);
+               wrmsrl(x86_pmu.lbr_to   + i, 0);
+       }
+}
+
+static void intel_pmu_lbr_reset(void)
+{
+       if (!x86_pmu.lbr_nr)
+               return;
+
+       if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
+               intel_pmu_lbr_reset_32();
+       else
+               intel_pmu_lbr_reset_64();
+}
+
+static void intel_pmu_lbr_enable(struct perf_event *event)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (!x86_pmu.lbr_nr)
+               return;
+
+       WARN_ON_ONCE(cpuc->enabled);
+
+       /*
+        * Reset the LBR stack if we changed task context to
+        * avoid data leaks.
+        */
+
+       if (event->ctx->task && cpuc->lbr_context != event->ctx) {
+               intel_pmu_lbr_reset();
+               cpuc->lbr_context = event->ctx;
+       }
+
+       cpuc->lbr_users++;
+}
+
+static void intel_pmu_lbr_disable(struct perf_event *event)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (!x86_pmu.lbr_nr)
+               return;
+
+       cpuc->lbr_users--;
+       WARN_ON_ONCE(cpuc->lbr_users < 0);
+
+       if (cpuc->enabled && !cpuc->lbr_users)
+               __intel_pmu_lbr_disable();
+}
+
+static void intel_pmu_lbr_enable_all(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (cpuc->lbr_users)
+               __intel_pmu_lbr_enable();
+}
+
+static void intel_pmu_lbr_disable_all(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (cpuc->lbr_users)
+               __intel_pmu_lbr_disable();
+}
+
+static inline u64 intel_pmu_lbr_tos(void)
+{
+       u64 tos;
+
+       rdmsrl(x86_pmu.lbr_tos, tos);
+
+       return tos;
+}
+
+static void intel_pmu_lbr_read_32(struct cpu_hw_events *cpuc)
+{
+       unsigned long mask = x86_pmu.lbr_nr - 1;
+       u64 tos = intel_pmu_lbr_tos();
+       int i;
+
+       for (i = 0; i < x86_pmu.lbr_nr; i++) {
+               unsigned long lbr_idx = (tos - i) & mask;
+               union {
+                       struct {
+                               u32 from;
+                               u32 to;
+                       };
+                       u64     lbr;
+               } msr_lastbranch;
+
+               rdmsrl(x86_pmu.lbr_from + lbr_idx, msr_lastbranch.lbr);
+
+               cpuc->lbr_entries[i].from  = msr_lastbranch.from;
+               cpuc->lbr_entries[i].to    = msr_lastbranch.to;
+               cpuc->lbr_entries[i].flags = 0;
+       }
+       cpuc->lbr_stack.nr = i;
+}
+
+#define LBR_FROM_FLAG_MISPRED  (1ULL << 63)
+
+/*
+ * Due to lack of segmentation in Linux the effective address (offset)
+ * is the same as the linear address, allowing us to merge the LIP and EIP
+ * LBR formats.
+ */
+static void intel_pmu_lbr_read_64(struct cpu_hw_events *cpuc)
+{
+       unsigned long mask = x86_pmu.lbr_nr - 1;
+       int lbr_format = x86_pmu.intel_cap.lbr_format;
+       u64 tos = intel_pmu_lbr_tos();
+       int i;
+
+       for (i = 0; i < x86_pmu.lbr_nr; i++) {
+               unsigned long lbr_idx = (tos - i) & mask;
+               u64 from, to, flags = 0;
+
+               rdmsrl(x86_pmu.lbr_from + lbr_idx, from);
+               rdmsrl(x86_pmu.lbr_to   + lbr_idx, to);
+
+               if (lbr_format == LBR_FORMAT_EIP_FLAGS) {
+                       flags = !!(from & LBR_FROM_FLAG_MISPRED);
+                       from = (u64)((((s64)from) << 1) >> 1);
+               }
+
+               cpuc->lbr_entries[i].from  = from;
+               cpuc->lbr_entries[i].to    = to;
+               cpuc->lbr_entries[i].flags = flags;
+       }
+       cpuc->lbr_stack.nr = i;
+}
+
+static void intel_pmu_lbr_read(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+
+       if (!cpuc->lbr_users)
+               return;
+
+       if (x86_pmu.intel_cap.lbr_format == LBR_FORMAT_32)
+               intel_pmu_lbr_read_32(cpuc);
+       else
+               intel_pmu_lbr_read_64(cpuc);
+}
+
+static void intel_pmu_lbr_init_core(void)
+{
+       x86_pmu.lbr_nr     = 4;
+       x86_pmu.lbr_tos    = 0x01c9;
+       x86_pmu.lbr_from   = 0x40;
+       x86_pmu.lbr_to     = 0x60;
+}
+
+static void intel_pmu_lbr_init_nhm(void)
+{
+       x86_pmu.lbr_nr     = 16;
+       x86_pmu.lbr_tos    = 0x01c9;
+       x86_pmu.lbr_from   = 0x680;
+       x86_pmu.lbr_to     = 0x6c0;
+}
+
+static void intel_pmu_lbr_init_atom(void)
+{
+       x86_pmu.lbr_nr     = 8;
+       x86_pmu.lbr_tos    = 0x01c9;
+       x86_pmu.lbr_from   = 0x40;
+       x86_pmu.lbr_to     = 0x60;
+}
+
+#endif /* CONFIG_CPU_SUP_INTEL */
diff --git a/arch/x86/kernel/cpu/perf_event_p4.c b/arch/x86/kernel/cpu/perf_event_p4.c
new file mode 100644 (file)
index 0000000..424fc8d
--- /dev/null
@@ -0,0 +1,857 @@
+/*
+ * Netburst Perfomance Events (P4, old Xeon)
+ *
+ *  Copyright (C) 2010 Parallels, Inc., Cyrill Gorcunov <gorcunov@openvz.org>
+ *  Copyright (C) 2010 Intel Corporation, Lin Ming <ming.m.lin@intel.com>
+ *
+ *  For licencing details see kernel-base/COPYING
+ */
+
+#ifdef CONFIG_CPU_SUP_INTEL
+
+#include <asm/perf_event_p4.h>
+
+#define P4_CNTR_LIMIT 3
+/*
+ * array indices: 0,1 - HT threads, used with HT enabled cpu
+ */
+struct p4_event_bind {
+       unsigned int opcode;                    /* Event code and ESCR selector */
+       unsigned int escr_msr[2];               /* ESCR MSR for this event */
+       char cntr[2][P4_CNTR_LIMIT];            /* counter index (offset), -1 on abscence */
+};
+
+struct p4_cache_event_bind {
+       unsigned int metric_pebs;
+       unsigned int metric_vert;
+};
+
+#define P4_GEN_CACHE_EVENT_BIND(name)          \
+       [P4_CACHE__##name] = {                  \
+               .metric_pebs = P4_PEBS__##name, \
+               .metric_vert = P4_VERT__##name, \
+       }
+
+static struct p4_cache_event_bind p4_cache_event_bind_map[] = {
+       P4_GEN_CACHE_EVENT_BIND(1stl_cache_load_miss_retired),
+       P4_GEN_CACHE_EVENT_BIND(2ndl_cache_load_miss_retired),
+       P4_GEN_CACHE_EVENT_BIND(dtlb_load_miss_retired),
+       P4_GEN_CACHE_EVENT_BIND(dtlb_store_miss_retired),
+};
+
+/*
+ * Note that we don't use CCCR1 here, there is an
+ * exception for P4_BSQ_ALLOCATION but we just have
+ * no workaround
+ *
+ * consider this binding as resources which particular
+ * event may borrow, it doesn't contain EventMask,
+ * Tags and friends -- they are left to a caller
+ */
+static struct p4_event_bind p4_event_bind_map[] = {
+       [P4_EVENT_TC_DELIVER_MODE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_TC_DELIVER_MODE),
+               .escr_msr       = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_BPU_FETCH_REQUEST] = {
+               .opcode         = P4_OPCODE(P4_EVENT_BPU_FETCH_REQUEST),
+               .escr_msr       = { MSR_P4_BPU_ESCR0, MSR_P4_BPU_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_ITLB_REFERENCE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_ITLB_REFERENCE),
+               .escr_msr       = { MSR_P4_ITLB_ESCR0, MSR_P4_ITLB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_MEMORY_CANCEL] = {
+               .opcode         = P4_OPCODE(P4_EVENT_MEMORY_CANCEL),
+               .escr_msr       = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_MEMORY_COMPLETE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_MEMORY_COMPLETE),
+               .escr_msr       = { MSR_P4_SAAT_ESCR0 , MSR_P4_SAAT_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_LOAD_PORT_REPLAY] = {
+               .opcode         = P4_OPCODE(P4_EVENT_LOAD_PORT_REPLAY),
+               .escr_msr       = { MSR_P4_SAAT_ESCR0, MSR_P4_SAAT_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_STORE_PORT_REPLAY] = {
+               .opcode         = P4_OPCODE(P4_EVENT_STORE_PORT_REPLAY),
+               .escr_msr       = { MSR_P4_SAAT_ESCR0 ,  MSR_P4_SAAT_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_MOB_LOAD_REPLAY] = {
+               .opcode         = P4_OPCODE(P4_EVENT_MOB_LOAD_REPLAY),
+               .escr_msr       = { MSR_P4_MOB_ESCR0, MSR_P4_MOB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_PAGE_WALK_TYPE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_PAGE_WALK_TYPE),
+               .escr_msr       = { MSR_P4_PMH_ESCR0, MSR_P4_PMH_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_BSQ_CACHE_REFERENCE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_BSQ_CACHE_REFERENCE),
+               .escr_msr       = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_IOQ_ALLOCATION] = {
+               .opcode         = P4_OPCODE(P4_EVENT_IOQ_ALLOCATION),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_IOQ_ACTIVE_ENTRIES] = {       /* shared ESCR */
+               .opcode         = P4_OPCODE(P4_EVENT_IOQ_ACTIVE_ENTRIES),
+               .escr_msr       = { MSR_P4_FSB_ESCR1,  MSR_P4_FSB_ESCR1 },
+               .cntr           = { {2, -1, -1}, {3, -1, -1} },
+       },
+       [P4_EVENT_FSB_DATA_ACTIVITY] = {
+               .opcode         = P4_OPCODE(P4_EVENT_FSB_DATA_ACTIVITY),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_BSQ_ALLOCATION] = {           /* shared ESCR, broken CCCR1 */
+               .opcode         = P4_OPCODE(P4_EVENT_BSQ_ALLOCATION),
+               .escr_msr       = { MSR_P4_BSU_ESCR0, MSR_P4_BSU_ESCR0 },
+               .cntr           = { {0, -1, -1}, {1, -1, -1} },
+       },
+       [P4_EVENT_BSQ_ACTIVE_ENTRIES] = {       /* shared ESCR */
+               .opcode         = P4_OPCODE(P4_EVENT_BSQ_ACTIVE_ENTRIES),
+               .escr_msr       = { MSR_P4_BSU_ESCR1 , MSR_P4_BSU_ESCR1 },
+               .cntr           = { {2, -1, -1}, {3, -1, -1} },
+       },
+       [P4_EVENT_SSE_INPUT_ASSIST] = {
+               .opcode         = P4_OPCODE(P4_EVENT_SSE_INPUT_ASSIST),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_PACKED_SP_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_PACKED_SP_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_PACKED_DP_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_PACKED_DP_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_SCALAR_SP_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_SCALAR_SP_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_SCALAR_DP_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_SCALAR_DP_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_64BIT_MMX_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_64BIT_MMX_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_128BIT_MMX_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_128BIT_MMX_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_X87_FP_UOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_X87_FP_UOP),
+               .escr_msr       = { MSR_P4_FIRM_ESCR0, MSR_P4_FIRM_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_TC_MISC] = {
+               .opcode         = P4_OPCODE(P4_EVENT_TC_MISC),
+               .escr_msr       = { MSR_P4_TC_ESCR0, MSR_P4_TC_ESCR1 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_GLOBAL_POWER_EVENTS] = {
+               .opcode         = P4_OPCODE(P4_EVENT_GLOBAL_POWER_EVENTS),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_TC_MS_XFER] = {
+               .opcode         = P4_OPCODE(P4_EVENT_TC_MS_XFER),
+               .escr_msr       = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_UOP_QUEUE_WRITES] = {
+               .opcode         = P4_OPCODE(P4_EVENT_UOP_QUEUE_WRITES),
+               .escr_msr       = { MSR_P4_MS_ESCR0, MSR_P4_MS_ESCR1 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_RETIRED_MISPRED_BRANCH_TYPE),
+               .escr_msr       = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR0 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_RETIRED_BRANCH_TYPE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_RETIRED_BRANCH_TYPE),
+               .escr_msr       = { MSR_P4_TBPU_ESCR0 , MSR_P4_TBPU_ESCR1 },
+               .cntr           = { {4, 5, -1}, {6, 7, -1} },
+       },
+       [P4_EVENT_RESOURCE_STALL] = {
+               .opcode         = P4_OPCODE(P4_EVENT_RESOURCE_STALL),
+               .escr_msr       = { MSR_P4_ALF_ESCR0, MSR_P4_ALF_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_WC_BUFFER] = {
+               .opcode         = P4_OPCODE(P4_EVENT_WC_BUFFER),
+               .escr_msr       = { MSR_P4_DAC_ESCR0, MSR_P4_DAC_ESCR1 },
+               .cntr           = { {8, 9, -1}, {10, 11, -1} },
+       },
+       [P4_EVENT_B2B_CYCLES] = {
+               .opcode         = P4_OPCODE(P4_EVENT_B2B_CYCLES),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_BNR] = {
+               .opcode         = P4_OPCODE(P4_EVENT_BNR),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_SNOOP] = {
+               .opcode         = P4_OPCODE(P4_EVENT_SNOOP),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_RESPONSE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_RESPONSE),
+               .escr_msr       = { MSR_P4_FSB_ESCR0, MSR_P4_FSB_ESCR1 },
+               .cntr           = { {0, -1, -1}, {2, -1, -1} },
+       },
+       [P4_EVENT_FRONT_END_EVENT] = {
+               .opcode         = P4_OPCODE(P4_EVENT_FRONT_END_EVENT),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_EXECUTION_EVENT] = {
+               .opcode         = P4_OPCODE(P4_EVENT_EXECUTION_EVENT),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_REPLAY_EVENT] = {
+               .opcode         = P4_OPCODE(P4_EVENT_REPLAY_EVENT),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_INSTR_RETIRED] = {
+               .opcode         = P4_OPCODE(P4_EVENT_INSTR_RETIRED),
+               .escr_msr       = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_UOPS_RETIRED] = {
+               .opcode         = P4_OPCODE(P4_EVENT_UOPS_RETIRED),
+               .escr_msr       = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_UOP_TYPE] = {
+               .opcode         = P4_OPCODE(P4_EVENT_UOP_TYPE),
+               .escr_msr       = { MSR_P4_RAT_ESCR0, MSR_P4_RAT_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_BRANCH_RETIRED] = {
+               .opcode         = P4_OPCODE(P4_EVENT_BRANCH_RETIRED),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_MISPRED_BRANCH_RETIRED] = {
+               .opcode         = P4_OPCODE(P4_EVENT_MISPRED_BRANCH_RETIRED),
+               .escr_msr       = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_X87_ASSIST] = {
+               .opcode         = P4_OPCODE(P4_EVENT_X87_ASSIST),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_MACHINE_CLEAR] = {
+               .opcode         = P4_OPCODE(P4_EVENT_MACHINE_CLEAR),
+               .escr_msr       = { MSR_P4_CRU_ESCR2, MSR_P4_CRU_ESCR3 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+       [P4_EVENT_INSTR_COMPLETED] = {
+               .opcode         = P4_OPCODE(P4_EVENT_INSTR_COMPLETED),
+               .escr_msr       = { MSR_P4_CRU_ESCR0, MSR_P4_CRU_ESCR1 },
+               .cntr           = { {12, 13, 16}, {14, 15, 17} },
+       },
+};
+
+#define P4_GEN_CACHE_EVENT(event, bit, cache_event)                      \
+       p4_config_pack_escr(P4_ESCR_EVENT(event)                        | \
+                           P4_ESCR_EMASK_BIT(event, bit))              | \
+       p4_config_pack_cccr(cache_event                                 | \
+                           P4_CCCR_ESEL(P4_OPCODE_ESEL(P4_OPCODE(event))))
+
+static __initconst const u64 p4_hw_cache_event_ids
+                               [PERF_COUNT_HW_CACHE_MAX]
+                               [PERF_COUNT_HW_CACHE_OP_MAX]
+                               [PERF_COUNT_HW_CACHE_RESULT_MAX] =
+{
+ [ C(L1D ) ] = {
+       [ C(OP_READ) ] = {
+               [ C(RESULT_ACCESS) ] = 0x0,
+               [ C(RESULT_MISS)   ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
+                                               P4_CACHE__1stl_cache_load_miss_retired),
+       },
+ },
+ [ C(LL  ) ] = {
+       [ C(OP_READ) ] = {
+               [ C(RESULT_ACCESS) ] = 0x0,
+               [ C(RESULT_MISS)   ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
+                                               P4_CACHE__2ndl_cache_load_miss_retired),
+       },
+},
+ [ C(DTLB) ] = {
+       [ C(OP_READ) ] = {
+               [ C(RESULT_ACCESS) ] = 0x0,
+               [ C(RESULT_MISS)   ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
+                                               P4_CACHE__dtlb_load_miss_retired),
+       },
+       [ C(OP_WRITE) ] = {
+               [ C(RESULT_ACCESS) ] = 0x0,
+               [ C(RESULT_MISS)   ] = P4_GEN_CACHE_EVENT(P4_EVENT_REPLAY_EVENT, NBOGUS,
+                                               P4_CACHE__dtlb_store_miss_retired),
+       },
+ },
+ [ C(ITLB) ] = {
+       [ C(OP_READ) ] = {
+               [ C(RESULT_ACCESS) ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, HIT,
+                                               P4_CACHE__itlb_reference_hit),
+               [ C(RESULT_MISS)   ] = P4_GEN_CACHE_EVENT(P4_EVENT_ITLB_REFERENCE, MISS,
+                                               P4_CACHE__itlb_reference_miss),
+       },
+       [ C(OP_WRITE) ] = {
+               [ C(RESULT_ACCESS) ] = -1,
+               [ C(RESULT_MISS)   ] = -1,
+       },
+       [ C(OP_PREFETCH) ] = {
+               [ C(RESULT_ACCESS) ] = -1,
+               [ C(RESULT_MISS)   ] = -1,
+       },
+ },
+};
+
+static u64 p4_general_events[PERF_COUNT_HW_MAX] = {
+  /* non-halted CPU clocks */
+  [PERF_COUNT_HW_CPU_CYCLES] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_GLOBAL_POWER_EVENTS)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_GLOBAL_POWER_EVENTS, RUNNING)),
+
+  /*
+   * retired instructions
+   * in a sake of simplicity we don't use the FSB tagging
+   */
+  [PERF_COUNT_HW_INSTRUCTIONS] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_INSTR_RETIRED)               |
+               P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, NBOGUSNTAG)           |
+               P4_ESCR_EMASK_BIT(P4_EVENT_INSTR_RETIRED, BOGUSNTAG)),
+
+  /* cache hits */
+  [PERF_COUNT_HW_CACHE_REFERENCES] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITS)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITE)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_HITM)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITS)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITE)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_HITM)),
+
+  /* cache misses */
+  [PERF_COUNT_HW_CACHE_MISSES] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_BSQ_CACHE_REFERENCE)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_2ndL_MISS)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, RD_3rdL_MISS)   |
+               P4_ESCR_EMASK_BIT(P4_EVENT_BSQ_CACHE_REFERENCE, WR_2ndL_MISS)),
+
+  /* branch instructions retired */
+  [PERF_COUNT_HW_BRANCH_INSTRUCTIONS] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_RETIRED_BRANCH_TYPE)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CONDITIONAL)    |
+               P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, CALL)           |
+               P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, RETURN)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_RETIRED_BRANCH_TYPE, INDIRECT)),
+
+  /* mispredicted branches retired */
+  [PERF_COUNT_HW_BRANCH_MISSES]        =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_MISPRED_BRANCH_RETIRED)      |
+               P4_ESCR_EMASK_BIT(P4_EVENT_MISPRED_BRANCH_RETIRED, NBOGUS)),
+
+  /* bus ready clocks (cpu is driving #DRDY_DRV\#DRDY_OWN):  */
+  [PERF_COUNT_HW_BUS_CYCLES] =
+       p4_config_pack_escr(P4_ESCR_EVENT(P4_EVENT_FSB_DATA_ACTIVITY)           |
+               P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_DRV)         |
+               P4_ESCR_EMASK_BIT(P4_EVENT_FSB_DATA_ACTIVITY, DRDY_OWN))        |
+       p4_config_pack_cccr(P4_CCCR_EDGE | P4_CCCR_COMPARE),
+};
+
+static struct p4_event_bind *p4_config_get_bind(u64 config)
+{
+       unsigned int evnt = p4_config_unpack_event(config);
+       struct p4_event_bind *bind = NULL;
+
+       if (evnt < ARRAY_SIZE(p4_event_bind_map))
+               bind = &p4_event_bind_map[evnt];
+
+       return bind;
+}
+
+static u64 p4_pmu_event_map(int hw_event)
+{
+       struct p4_event_bind *bind;
+       unsigned int esel;
+       u64 config;
+
+       config = p4_general_events[hw_event];
+       bind = p4_config_get_bind(config);
+       esel = P4_OPCODE_ESEL(bind->opcode);
+       config |= p4_config_pack_cccr(P4_CCCR_ESEL(esel));
+
+       return config;
+}
+
+static int p4_hw_config(struct perf_event *event)
+{
+       int cpu = get_cpu();
+       int rc = 0;
+       unsigned int evnt;
+       u32 escr, cccr;
+
+       /*
+        * the reason we use cpu that early is that: if we get scheduled
+        * first time on the same cpu -- we will not need swap thread
+        * specific flags in config (and will save some cpu cycles)
+        */
+
+       cccr = p4_default_cccr_conf(cpu);
+       escr = p4_default_escr_conf(cpu, event->attr.exclude_kernel,
+                                        event->attr.exclude_user);
+       event->hw.config = p4_config_pack_escr(escr) |
+                          p4_config_pack_cccr(cccr);
+
+       if (p4_ht_active() && p4_ht_thread(cpu))
+               event->hw.config = p4_set_ht_bit(event->hw.config);
+
+       if (event->attr.type == PERF_TYPE_RAW) {
+
+               /* user data may have out-of-bound event index */
+               evnt = p4_config_unpack_event(event->attr.config);
+               if (evnt >= ARRAY_SIZE(p4_event_bind_map)) {
+                       rc = -EINVAL;
+                       goto out;
+               }
+
+               /*
+                * We don't control raw events so it's up to the caller
+                * to pass sane values (and we don't count the thread number
+                * on HT machine but allow HT-compatible specifics to be
+                * passed on)
+                *
+                * XXX: HT wide things should check perf_paranoid_cpu() &&
+                *      CAP_SYS_ADMIN
+                */
+               event->hw.config |= event->attr.config &
+                       (p4_config_pack_escr(P4_ESCR_MASK_HT) |
+                        p4_config_pack_cccr(P4_CCCR_MASK_HT));
+       }
+
+       rc = x86_setup_perfctr(event);
+out:
+       put_cpu();
+       return rc;
+}
+
+static inline void p4_pmu_clear_cccr_ovf(struct hw_perf_event *hwc)
+{
+       unsigned long dummy;
+
+       rdmsrl(hwc->config_base + hwc->idx, dummy);
+       if (dummy & P4_CCCR_OVF) {
+               (void)checking_wrmsrl(hwc->config_base + hwc->idx,
+                       ((u64)dummy) & ~P4_CCCR_OVF);
+       }
+}
+
+static inline void p4_pmu_disable_event(struct perf_event *event)
+{
+       struct hw_perf_event *hwc = &event->hw;
+
+       /*
+        * If event gets disabled while counter is in overflowed
+        * state we need to clear P4_CCCR_OVF, otherwise interrupt get
+        * asserted again and again
+        */
+       (void)checking_wrmsrl(hwc->config_base + hwc->idx,
+               (u64)(p4_config_unpack_cccr(hwc->config)) &
+                       ~P4_CCCR_ENABLE & ~P4_CCCR_OVF & ~P4_CCCR_RESERVED);
+}
+
+static void p4_pmu_disable_all(void)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       int idx;
+
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
+               struct perf_event *event = cpuc->events[idx];
+               if (!test_bit(idx, cpuc->active_mask))
+                       continue;
+               p4_pmu_disable_event(event);
+       }
+}
+
+static void p4_pmu_enable_event(struct perf_event *event)
+{
+       struct hw_perf_event *hwc = &event->hw;
+       int thread = p4_ht_config_thread(hwc->config);
+       u64 escr_conf = p4_config_unpack_escr(p4_clear_ht_bit(hwc->config));
+       unsigned int idx = p4_config_unpack_event(hwc->config);
+       unsigned int idx_cache = p4_config_unpack_cache_event(hwc->config);
+       struct p4_event_bind *bind;
+       struct p4_cache_event_bind *bind_cache;
+       u64 escr_addr, cccr;
+
+       bind = &p4_event_bind_map[idx];
+       escr_addr = (u64)bind->escr_msr[thread];
+
+       /*
+        * - we dont support cascaded counters yet
+        * - and counter 1 is broken (erratum)
+        */
+       WARN_ON_ONCE(p4_is_event_cascaded(hwc->config));
+       WARN_ON_ONCE(hwc->idx == 1);
+
+       /* we need a real Event value */
+       escr_conf &= ~P4_ESCR_EVENT_MASK;
+       escr_conf |= P4_ESCR_EVENT(P4_OPCODE_EVNT(bind->opcode));
+
+       cccr = p4_config_unpack_cccr(hwc->config);
+
+       /*
+        * it could be Cache event so that we need to
+        * set metrics into additional MSRs
+        */
+       BUILD_BUG_ON(P4_CACHE__MAX > P4_CCCR_CACHE_OPS_MASK);
+       if (idx_cache > P4_CACHE__NONE &&
+               idx_cache < ARRAY_SIZE(p4_cache_event_bind_map)) {
+               bind_cache = &p4_cache_event_bind_map[idx_cache];
+               (void)checking_wrmsrl(MSR_IA32_PEBS_ENABLE, (u64)bind_cache->metric_pebs);
+               (void)checking_wrmsrl(MSR_P4_PEBS_MATRIX_VERT, (u64)bind_cache->metric_vert);
+       }
+
+       (void)checking_wrmsrl(escr_addr, escr_conf);
+       (void)checking_wrmsrl(hwc->config_base + hwc->idx,
+                               (cccr & ~P4_CCCR_RESERVED) | P4_CCCR_ENABLE);
+}
+
+static void p4_pmu_enable_all(int added)
+{
+       struct cpu_hw_events *cpuc = &__get_cpu_var(cpu_hw_events);
+       int idx;
+
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
+               struct perf_event *event = cpuc->events[idx];
+               if (!test_bit(idx, cpuc->active_mask))
+                       continue;
+               p4_pmu_enable_event(event);
+       }
+}
+
+static int p4_pmu_handle_irq(struct pt_regs *regs)
+{
+       struct perf_sample_data data;
+       struct cpu_hw_events *cpuc;
+       struct perf_event *event;
+       struct hw_perf_event *hwc;
+       int idx, handled = 0;
+       u64 val;
+
+       data.addr = 0;
+       data.raw = NULL;
+
+       cpuc = &__get_cpu_var(cpu_hw_events);
+
+       for (idx = 0; idx < x86_pmu.num_counters; idx++) {
+
+               if (!test_bit(idx, cpuc->active_mask))
+                       continue;
+
+               event = cpuc->events[idx];
+               hwc = &event->hw;
+
+               WARN_ON_ONCE(hwc->idx != idx);
+
+               /*
+                * FIXME: Redundant call, actually not needed
+                * but just to check if we're screwed
+                */
+               p4_pmu_clear_cccr_ovf(hwc);
+
+               val = x86_perf_event_update(event);
+               if (val & (1ULL << (x86_pmu.cntval_bits - 1)))
+                       continue;
+
+               /*
+                * event overflow
+                */
+               handled         = 1;
+               data.period     = event->hw.last_period;
+
+               if (!x86_perf_event_set_period(event))
+                       continue;
+               if (perf_event_overflow(event, 1, &data, regs))
+                       p4_pmu_disable_event(event);
+       }
+
+       if (handled) {
+               /* p4 quirk: unmask it again */
+               apic_write(APIC_LVTPC, apic_read(APIC_LVTPC) & ~APIC_LVT_MASKED);
+               inc_irq_stat(apic_perf_irqs);
+       }
+
+       return handled;
+}
+
+/*
+ * swap thread specific fields according to a thread
+ * we are going to run on
+ */
+static void p4_pmu_swap_config_ts(struct hw_perf_event *hwc, int cpu)
+{
+       u32 escr, cccr;
+
+       /*
+        * we either lucky and continue on same cpu or no HT support
+        */
+       if (!p4_should_swap_ts(hwc->config, cpu))
+               return;
+
+       /*
+        * the event is migrated from an another logical
+        * cpu, so we need to swap thread specific flags
+        */
+
+       escr = p4_config_unpack_escr(hwc->config);
+       cccr = p4_config_unpack_cccr(hwc->config);
+
+       if (p4_ht_thread(cpu)) {
+               cccr &= ~P4_CCCR_OVF_PMI_T0;
+               cccr |= P4_CCCR_OVF_PMI_T1;
+               if (escr & P4_ESCR_T0_OS) {
+                       escr &= ~P4_ESCR_T0_OS;
+                       escr |= P4_ESCR_T1_OS;
+               }
+               if (escr & P4_ESCR_T0_USR) {
+                       escr &= ~P4_ESCR_T0_USR;
+                       escr |= P4_ESCR_T1_USR;
+               }
+               hwc->config  = p4_config_pack_escr(escr);
+               hwc->config |= p4_config_pack_cccr(cccr);
+               hwc->config |= P4_CONFIG_HT;
+       } else {
+               cccr &= ~P4_CCCR_OVF_PMI_T1;
+               cccr |= P4_CCCR_OVF_PMI_T0;
+               if (escr & P4_ESCR_T1_OS) {
+                       escr &= ~P4_ESCR_T1_OS;
+                       escr |= P4_ESCR_T0_OS;
+               }
+               if (escr & P4_ESCR_T1_USR) {
+                       escr &= ~P4_ESCR_T1_USR;
+                       escr |= P4_ESCR_T0_USR;
+               }
+               hwc->config  = p4_config_pack_escr(escr);
+               hwc->config |= p4_config_pack_cccr(cccr);
+               hwc->config &= ~P4_CONFIG_HT;
+       }
+}
+
+/*
+ * ESCR address hashing is tricky, ESCRs are not sequential
+ * in memory but all starts from MSR_P4_BSU_ESCR0 (0x03e0) and
+ * the metric between any ESCRs is laid in range [0xa0,0xe1]
+ *
+ * so we make ~70% filled hashtable
+ */
+
+#define P4_ESCR_MSR_BASE               0x000003a0
+#define P4_ESCR_MSR_MAX                        0x000003e1
+#define P4_ESCR_MSR_TABLE_SIZE         (P4_ESCR_MSR_MAX - P4_ESCR_MSR_BASE + 1)
+#define P4_ESCR_MSR_IDX(msr)           (msr - P4_ESCR_MSR_BASE)
+#define P4_ESCR_MSR_TABLE_ENTRY(msr)   [P4_ESCR_MSR_IDX(msr)] = msr
+
+static const unsigned int p4_escr_table[P4_ESCR_MSR_TABLE_SIZE] = {
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ALF_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BPU_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_BSU_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR2),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR3),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR4),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_CRU_ESCR5),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_DAC_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FIRM_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FLAME_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_FSB_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IQ_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IS_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_ITLB_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_IX_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MOB_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_MS_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_PMH_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_RAT_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SAAT_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_SSU_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TBPU_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_TC_ESCR1),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR0),
+       P4_ESCR_MSR_TABLE_ENTRY(MSR_P4_U2L_ESCR1),
+};
+
+static int p4_get_escr_idx(unsigned int addr)
+{
+       unsigned int idx = P4_ESCR_MSR_IDX(addr);
+
+       if (unlikely(idx >= P4_ESCR_MSR_TABLE_SIZE ||
+                       !p4_escr_table[idx])) {
+               WARN_ONCE(1, "P4 PMU: Wrong address passed: %x\n", addr);
+               return -1;
+       }
+
+       return idx;
+}
+
+static int p4_next_cntr(int thread, unsigned long *used_mask,
+                       struct p4_event_bind *bind)
+{
+       int i, j;
+
+       for (i = 0; i < P4_CNTR_LIMIT; i++) {
+               j = bind->cntr[thread][i];
+               if (j != -1 && !test_bit(j, used_mask))
+                       return j;
+       }
+
+       return -1;
+}
+
+static int p4_pmu_schedule_events(struct cpu_hw_events *cpuc, int n, int *assign)
+{
+       unsigned long used_mask[BITS_TO_LONGS(X86_PMC_IDX_MAX)];
+       unsigned long escr_mask[BITS_TO_LONGS(P4_ESCR_MSR_TABLE_SIZE)];
+       int cpu = raw_smp_processor_id();
+       struct hw_perf_event *hwc;
+       struct p4_event_bind *bind;
+       unsigned int i, thread, num;
+       int cntr_idx, escr_idx;
+
+       bitmap_zero(used_mask, X86_PMC_IDX_MAX);
+       bitmap_zero(escr_mask, P4_ESCR_MSR_TABLE_SIZE);
+
+       for (i = 0, num = n; i < n; i++, num--) {
+
+               hwc = &cpuc->event_list[i]->hw;
+               thread = p4_ht_thread(cpu);
+               bind = p4_config_get_bind(hwc->config);
+               escr_idx = p4_get_escr_idx(bind->escr_msr[thread]);
+               if (unlikely(escr_idx == -1))
+                       goto done;
+
+               if (hwc->idx != -1 && !p4_should_swap_ts(hwc->config, cpu)) {
+                       cntr_idx = hwc->idx;
+                       if (assign)
+                               assign[i] = hwc->idx;
+                       goto reserve;
+               }
+
+               cntr_idx = p4_next_cntr(thread, used_mask, bind);
+               if (cntr_idx == -1 || test_bit(escr_idx, escr_mask))
+                       goto done;
+
+               p4_pmu_swap_config_ts(hwc, cpu);
+               if (assign)
+                       assign[i] = cntr_idx;
+reserve:
+               set_bit(cntr_idx, used_mask);
+               set_bit(escr_idx, escr_mask);
+       }
+
+done:
+       return num ? -ENOSPC : 0;
+}
+
+static __initconst const struct x86_pmu p4_pmu = {
+       .name                   = "Netburst P4/Xeon",
+       .handle_irq             = p4_pmu_handle_irq,
+       .disable_all            = p4_pmu_disable_all,
+       .enable_all             = p4_pmu_enable_all,
+       .enable                 = p4_pmu_enable_event,
+       .disable                = p4_pmu_disable_event,
+       .eventsel               = MSR_P4_BPU_CCCR0,
+       .perfctr                = MSR_P4_BPU_PERFCTR0,
+       .event_map              = p4_pmu_event_map,
+       .max_events             = ARRAY_SIZE(p4_general_events),
+       .get_event_constraints  = x86_get_event_constraints,
+       /*
+        * IF HT disabled we may need to use all
+        * ARCH_P4_MAX_CCCR counters simulaneously
+        * though leave it restricted at moment assuming
+        * HT is on
+        */
+       .num_counters           = ARCH_P4_MAX_CCCR,
+       .apic                   = 1,
+       .cntval_bits            = 40,
+       .cntval_mask            = (1ULL << 40) - 1,
+       .max_period             = (1ULL << 39) - 1,
+       .hw_config              = p4_hw_config,
+       .schedule_events        = p4_pmu_schedule_events,
+};
+
+static __init int p4_pmu_init(void)
+{
+       unsigned int low, high;
+
+       /* If we get stripped -- indexig fails */
+       BUILD_BUG_ON(ARCH_P4_MAX_CCCR > X86_PMC_MAX_GENERIC);
+
+       rdmsr(MSR_IA32_MISC_ENABLE, low, high);
+       if (!(low & (1 << 7))) {
+               pr_cont("unsupported Netburst CPU model %d ",
+                       boot_cpu_data.x86_model);
+               return -ENODEV;
+       }
+
+       memcpy(hw_cache_event_ids, p4_hw_cache_event_ids,
+               sizeof(hw_cache_event_ids));
+
+       pr_cont("Netburst events, ");
+
+       x86_pmu = p4_pmu;
+
+       return 0;
+}
+
+#endif /* CONFIG_CPU_SUP_INTEL */
index a330485..34ba07b 100644 (file)
@@ -27,24 +27,6 @@ static u64 p6_pmu_event_map(int hw_event)
  */
 #define P6_NOP_EVENT                   0x0000002EULL
 
-static u64 p6_pmu_raw_event(u64 hw_event)
-{
-#define P6_EVNTSEL_EVENT_MASK          0x000000FFULL
-#define P6_EVNTSEL_UNIT_MASK           0x0000FF00ULL
-#define P6_EVNTSEL_EDGE_MASK           0x00040000ULL
-#define P6_EVNTSEL_INV_MASK            0x00800000ULL
-#define P6_EVNTSEL_REG_MASK            0xFF000000ULL
-
-#define P6_EVNTSEL_MASK                        \
-       (P6_EVNTSEL_EVENT_MASK |        \
-        P6_EVNTSEL_UNIT_MASK  |        \
-        P6_EVNTSEL_EDGE_MASK  |        \
-        P6_EVNTSEL_INV_MASK   |        \
-        P6_EVNTSEL_REG_MASK)
-
-       return hw_event & P6_EVNTSEL_MASK;
-}
-
 static struct event_constraint p6_event_constraints[] =
 {
        INTEL_EVENT_CONSTRAINT(0xc1, 0x1),      /* FLOPS */
@@ -66,7 +48,7 @@ static void p6_pmu_disable_all(void)
        wrmsrl(MSR_P6_EVNTSEL0, val);
 }
 
-static void p6_pmu_enable_all(void)
+static void p6_pmu_enable_all(int added)
 {
        unsigned long val;
 
@@ -102,22 +84,23 @@ static void p6_pmu_enable_event(struct perf_event *event)
        (void)checking_wrmsrl(hwc->config_base + hwc->idx, val);
 }
 
-static __initconst struct x86_pmu p6_pmu = {
+static __initconst const struct x86_pmu p6_pmu = {
        .name                   = "p6",
        .handle_irq             = x86_pmu_handle_irq,
        .disable_all            = p6_pmu_disable_all,
        .enable_all             = p6_pmu_enable_all,
        .enable                 = p6_pmu_enable_event,
        .disable                = p6_pmu_disable_event,
+       .hw_config              = x86_pmu_hw_config,
+       .schedule_events        = x86_schedule_events,
        .eventsel               = MSR_P6_EVNTSEL0,
        .perfctr                = MSR_P6_PERFCTR0,
        .event_map              = p6_pmu_event_map,
-       .raw_event              = p6_pmu_raw_event,
        .max_events             = ARRAY_SIZE(p6_perfmon_event_map),
        .apic                   = 1,
        .max_period             = (1ULL << 31) - 1,
        .version                = 0,
-       .num_events             = 2,
+       .num_counters           = 2,
        /*
         * Events have 40 bits implemented. However they are designed such
         * that bits [32-39] are sign extensions of bit 31. As such the
@@ -125,8 +108,8 @@ static __initconst struct x86_pmu p6_pmu = {
         *
         * See IA-32 Intel Architecture Software developer manual Vol 3B
         */
-       .event_bits             = 32,
-       .event_mask             = (1ULL << 32) - 1,
+       .cntval_bits            = 32,
+       .cntval_mask            = (1ULL << 32) - 1,
        .get_event_constraints  = x86_get_event_constraints,
        .event_constraints      = p6_event_constraints,
 };
index dfdb4db..b9d1ff5 100644 (file)
@@ -24,8 +24,8 @@
 #include <linux/dmi.h>
 #include <linux/module.h>
 #include <asm/div64.h>
-#include <asm/vmware.h>
 #include <asm/x86_init.h>
+#include <asm/hypervisor.h>
 
 #define CPUID_VMWARE_INFO_LEAF 0x40000000
 #define VMWARE_HYPERVISOR_MAGIC        0x564D5868
@@ -65,7 +65,7 @@ static unsigned long vmware_get_tsc_khz(void)
        return tsc_hz;
 }
 
-void __init vmware_platform_setup(void)
+static void __init vmware_platform_setup(void)
 {
        uint32_t eax, ebx, ecx, edx;
 
@@ -83,26 +83,22 @@ void __init vmware_platform_setup(void)
  * serial key should be enough, as this will always have a VMware
  * specific string when running under VMware hypervisor.
  */
-int vmware_platform(void)
+static bool __init vmware_platform(void)
 {
        if (cpu_has_hypervisor) {
-               unsigned int eax, ebx, ecx, edx;
-               char hyper_vendor_id[13];
-
-               cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &ebx, &ecx, &edx);
-               memcpy(hyper_vendor_id + 0, &ebx, 4);
-               memcpy(hyper_vendor_id + 4, &ecx, 4);
-               memcpy(hyper_vendor_id + 8, &edx, 4);
-               hyper_vendor_id[12] = '\0';
-               if (!strcmp(hyper_vendor_id, "VMwareVMware"))
-                       return 1;
+               unsigned int eax;
+               unsigned int hyper_vendor_id[3];
+
+               cpuid(CPUID_VMWARE_INFO_LEAF, &eax, &hyper_vendor_id[0],
+                     &hyper_vendor_id[1], &hyper_vendor_id[2]);
+               if (!memcmp(hyper_vendor_id, "VMwareVMware", 12))
+                       return true;
        } else if (dmi_available && dmi_name_in_serial("VMware") &&
                   __vmware_platform())
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
-EXPORT_SYMBOL(vmware_platform);
 
 /*
  * VMware hypervisor takes care of exporting a reliable TSC to the guest.
@@ -116,8 +112,16 @@ EXPORT_SYMBOL(vmware_platform);
  * so that the kernel could just trust the hypervisor with providing a
  * reliable virtual TSC that is suitable for timekeeping.
  */
-void __cpuinit vmware_set_feature_bits(struct cpuinfo_x86 *c)
+static void __cpuinit vmware_set_cpu_features(struct cpuinfo_x86 *c)
 {
        set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
        set_cpu_cap(c, X86_FEATURE_TSC_RELIABLE);
 }
+
+const __refconst struct hypervisor_x86 x86_hyper_vmware = {
+       .name                   = "VMware",
+       .detect                 = vmware_platform,
+       .set_cpu_features       = vmware_set_cpu_features,
+       .init_platform          = vmware_platform_setup,
+};
+EXPORT_SYMBOL(x86_hyper_vmware);
diff --git a/arch/x86/kernel/ds.c b/arch/x86/kernel/ds.c
deleted file mode 100644 (file)
index 1c47390..0000000
+++ /dev/null
@@ -1,1437 +0,0 @@
-/*
- * Debug Store support
- *
- * This provides a low-level interface to the hardware's Debug Store
- * feature that is used for branch trace store (BTS) and
- * precise-event based sampling (PEBS).
- *
- * It manages:
- * - DS and BTS hardware configuration
- * - buffer overflow handling (to be done)
- * - buffer access
- *
- * It does not do:
- * - security checking (is the caller allowed to trace the task)
- * - buffer allocation (memory accounting)
- *
- *
- * Copyright (C) 2007-2009 Intel Corporation.
- * Markus Metzger <markus.t.metzger@intel.com>, 2007-2009
- */
-
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/trace_clock.h>
-
-#include <asm/ds.h>
-
-#include "ds_selftest.h"
-
-/*
- * The configuration for a particular DS hardware implementation:
- */
-struct ds_configuration {
-       /* The name of the configuration: */
-       const char              *name;
-
-       /* The size of pointer-typed fields in DS, BTS, and PEBS: */
-       unsigned char           sizeof_ptr_field;
-
-       /* The size of a BTS/PEBS record in bytes: */
-       unsigned char           sizeof_rec[2];
-
-       /* The number of pebs counter reset values in the DS structure. */
-       unsigned char           nr_counter_reset;
-
-       /* Control bit-masks indexed by enum ds_feature: */
-       unsigned long           ctl[dsf_ctl_max];
-};
-static struct ds_configuration ds_cfg __read_mostly;
-
-
-/* Maximal size of a DS configuration: */
-#define MAX_SIZEOF_DS          0x80
-
-/* Maximal size of a BTS record: */
-#define MAX_SIZEOF_BTS         (3 * 8)
-
-/* BTS and PEBS buffer alignment: */
-#define DS_ALIGNMENT           (1 << 3)
-
-/* Number of buffer pointers in DS: */
-#define NUM_DS_PTR_FIELDS      8
-
-/* Size of a pebs reset value in DS: */
-#define PEBS_RESET_FIELD_SIZE  8
-
-/* Mask of control bits in the DS MSR register: */
-#define BTS_CONTROL                              \
-       ( ds_cfg.ctl[dsf_bts]                   | \
-         ds_cfg.ctl[dsf_bts_kernel]            | \
-         ds_cfg.ctl[dsf_bts_user]              | \
-         ds_cfg.ctl[dsf_bts_overflow] )
-
-/*
- * A BTS or PEBS tracer.
- *
- * This holds the configuration of the tracer and serves as a handle
- * to identify tracers.
- */
-struct ds_tracer {
-       /* The DS context (partially) owned by this tracer. */
-       struct ds_context       *context;
-       /* The buffer provided on ds_request() and its size in bytes. */
-       void                    *buffer;
-       size_t                  size;
-};
-
-struct bts_tracer {
-       /* The common DS part: */
-       struct ds_tracer        ds;
-
-       /* The trace including the DS configuration: */
-       struct bts_trace        trace;
-
-       /* Buffer overflow notification function: */
-       bts_ovfl_callback_t     ovfl;
-
-       /* Active flags affecting trace collection. */
-       unsigned int            flags;
-};
-
-struct pebs_tracer {
-       /* The common DS part: */
-       struct ds_tracer        ds;
-
-       /* The trace including the DS configuration: */
-       struct pebs_trace       trace;
-
-       /* Buffer overflow notification function: */
-       pebs_ovfl_callback_t    ovfl;
-};
-
-/*
- * Debug Store (DS) save area configuration (see Intel64 and IA32
- * Architectures Software Developer's Manual, section 18.5)
- *
- * The DS configuration consists of the following fields; different
- * architetures vary in the size of those fields.
- *
- * - double-word aligned base linear address of the BTS buffer
- * - write pointer into the BTS buffer
- * - end linear address of the BTS buffer (one byte beyond the end of
- *   the buffer)
- * - interrupt pointer into BTS buffer
- *   (interrupt occurs when write pointer passes interrupt pointer)
- * - double-word aligned base linear address of the PEBS buffer
- * - write pointer into the PEBS buffer
- * - end linear address of the PEBS buffer (one byte beyond the end of
- *   the buffer)
- * - interrupt pointer into PEBS buffer
- *   (interrupt occurs when write pointer passes interrupt pointer)
- * - value to which counter is reset following counter overflow
- *
- * Later architectures use 64bit pointers throughout, whereas earlier
- * architectures use 32bit pointers in 32bit mode.
- *
- *
- * We compute the base address for the first 8 fields based on:
- * - the field size stored in the DS configuration
- * - the relative field position
- * - an offset giving the start of the respective region
- *
- * This offset is further used to index various arrays holding
- * information for BTS and PEBS at the respective index.
- *
- * On later 32bit processors, we only access the lower 32bit of the
- * 64bit pointer fields. The upper halves will be zeroed out.
- */
-
-enum ds_field {
-       ds_buffer_base = 0,
-       ds_index,
-       ds_absolute_maximum,
-       ds_interrupt_threshold,
-};
-
-enum ds_qualifier {
-       ds_bts = 0,
-       ds_pebs
-};
-
-static inline unsigned long
-ds_get(const unsigned char *base, enum ds_qualifier qual, enum ds_field field)
-{
-       base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual)));
-       return *(unsigned long *)base;
-}
-
-static inline void
-ds_set(unsigned char *base, enum ds_qualifier qual, enum ds_field field,
-       unsigned long value)
-{
-       base += (ds_cfg.sizeof_ptr_field * (field + (4 * qual)));
-       (*(unsigned long *)base) = value;
-}
-
-
-/*
- * Locking is done only for allocating BTS or PEBS resources.
- */
-static DEFINE_SPINLOCK(ds_lock);
-
-/*
- * We either support (system-wide) per-cpu or per-thread allocation.
- * We distinguish the two based on the task_struct pointer, where a
- * NULL pointer indicates per-cpu allocation for the current cpu.
- *
- * Allocations are use-counted. As soon as resources are allocated,
- * further allocations must be of the same type (per-cpu or
- * per-thread). We model this by counting allocations (i.e. the number
- * of tracers of a certain type) for one type negatively:
- *   =0  no tracers
- *   >0  number of per-thread tracers
- *   <0  number of per-cpu tracers
- *
- * Tracers essentially gives the number of ds contexts for a certain
- * type of allocation.
- */
-static atomic_t tracers = ATOMIC_INIT(0);
-
-static inline int get_tracer(struct task_struct *task)
-{
-       int error;
-
-       spin_lock_irq(&ds_lock);
-
-       if (task) {
-               error = -EPERM;
-               if (atomic_read(&tracers) < 0)
-                       goto out;
-               atomic_inc(&tracers);
-       } else {
-               error = -EPERM;
-               if (atomic_read(&tracers) > 0)
-                       goto out;
-               atomic_dec(&tracers);
-       }
-
-       error = 0;
-out:
-       spin_unlock_irq(&ds_lock);
-       return error;
-}
-
-static inline void put_tracer(struct task_struct *task)
-{
-       if (task)
-               atomic_dec(&tracers);
-       else
-               atomic_inc(&tracers);
-}
-
-/*
- * The DS context is either attached to a thread or to a cpu:
- * - in the former case, the thread_struct contains a pointer to the
- *   attached context.
- * - in the latter case, we use a static array of per-cpu context
- *   pointers.
- *
- * Contexts are use-counted. They are allocated on first access and
- * deallocated when the last user puts the context.
- */
-struct ds_context {
-       /* The DS configuration; goes into MSR_IA32_DS_AREA: */
-       unsigned char           ds[MAX_SIZEOF_DS];
-
-       /* The owner of the BTS and PEBS configuration, respectively: */
-       struct bts_tracer       *bts_master;
-       struct pebs_tracer      *pebs_master;
-
-       /* Use count: */
-       unsigned long           count;
-
-       /* Pointer to the context pointer field: */
-       struct ds_context       **this;
-
-       /* The traced task; NULL for cpu tracing: */
-       struct task_struct      *task;
-
-       /* The traced cpu; only valid if task is NULL: */
-       int                     cpu;
-};
-
-static DEFINE_PER_CPU(struct ds_context *, cpu_ds_context);
-
-
-static struct ds_context *ds_get_context(struct task_struct *task, int cpu)
-{
-       struct ds_context **p_context =
-               (task ? &task->thread.ds_ctx : &per_cpu(cpu_ds_context, cpu));
-       struct ds_context *context = NULL;
-       struct ds_context *new_context = NULL;
-
-       /* Chances are small that we already have a context. */
-       new_context = kzalloc(sizeof(*new_context), GFP_KERNEL);
-       if (!new_context)
-               return NULL;
-
-       spin_lock_irq(&ds_lock);
-
-       context = *p_context;
-       if (likely(!context)) {
-               context = new_context;
-
-               context->this = p_context;
-               context->task = task;
-               context->cpu = cpu;
-               context->count = 0;
-
-               *p_context = context;
-       }
-
-       context->count++;
-
-       spin_unlock_irq(&ds_lock);
-
-       if (context != new_context)
-               kfree(new_context);
-
-       return context;
-}
-
-static void ds_put_context(struct ds_context *context)
-{
-       struct task_struct *task;
-       unsigned long irq;
-
-       if (!context)
-               return;
-
-       spin_lock_irqsave(&ds_lock, irq);
-
-       if (--context->count) {
-               spin_unlock_irqrestore(&ds_lock, irq);
-               return;
-       }
-
-       *(context->this) = NULL;
-
-       task = context->task;
-
-       if (task)
-               clear_tsk_thread_flag(task, TIF_DS_AREA_MSR);
-
-       /*
-        * We leave the (now dangling) pointer to the DS configuration in
-        * the DS_AREA msr. This is as good or as bad as replacing it with
-        * NULL - the hardware would crash if we enabled tracing.
-        *
-        * This saves us some problems with having to write an msr on a
-        * different cpu while preventing others from doing the same for the
-        * next context for that same cpu.
-        */
-
-       spin_unlock_irqrestore(&ds_lock, irq);
-
-       /* The context might still be in use for context switching. */
-       if (task && (task != current))
-               wait_task_context_switch(task);
-
-       kfree(context);
-}
-
-static void ds_install_ds_area(struct ds_context *context)
-{
-       unsigned long ds;
-
-       ds = (unsigned long)context->ds;
-
-       /*
-        * There is a race between the bts master and the pebs master.
-        *
-        * The thread/cpu access is synchronized via get/put_cpu() for
-        * task tracing and via wrmsr_on_cpu for cpu tracing.
-        *
-        * If bts and pebs are collected for the same task or same cpu,
-        * the same confiuration is written twice.
-        */
-       if (context->task) {
-               get_cpu();
-               if (context->task == current)
-                       wrmsrl(MSR_IA32_DS_AREA, ds);
-               set_tsk_thread_flag(context->task, TIF_DS_AREA_MSR);
-               put_cpu();
-       } else
-               wrmsr_on_cpu(context->cpu, MSR_IA32_DS_AREA,
-                            (u32)((u64)ds), (u32)((u64)ds >> 32));
-}
-
-/*
- * Call the tracer's callback on a buffer overflow.
- *
- * context: the ds context
- * qual: the buffer type
- */
-static void ds_overflow(struct ds_context *context, enum ds_qualifier qual)
-{
-       switch (qual) {
-       case ds_bts:
-               if (context->bts_master &&
-                   context->bts_master->ovfl)
-                       context->bts_master->ovfl(context->bts_master);
-               break;
-       case ds_pebs:
-               if (context->pebs_master &&
-                   context->pebs_master->ovfl)
-                       context->pebs_master->ovfl(context->pebs_master);
-               break;
-       }
-}
-
-
-/*
- * Write raw data into the BTS or PEBS buffer.
- *
- * The remainder of any partially written record is zeroed out.
- *
- * context: the DS context
- * qual:    the buffer type
- * record:  the data to write
- * size:    the size of the data
- */
-static int ds_write(struct ds_context *context, enum ds_qualifier qual,
-                   const void *record, size_t size)
-{
-       int bytes_written = 0;
-
-       if (!record)
-               return -EINVAL;
-
-       while (size) {
-               unsigned long base, index, end, write_end, int_th;
-               unsigned long write_size, adj_write_size;
-
-               /*
-                * Write as much as possible without producing an
-                * overflow interrupt.
-                *
-                * Interrupt_threshold must either be
-                * - bigger than absolute_maximum or
-                * - point to a record between buffer_base and absolute_maximum
-                *
-                * Index points to a valid record.
-                */
-               base   = ds_get(context->ds, qual, ds_buffer_base);
-               index  = ds_get(context->ds, qual, ds_index);
-               end    = ds_get(context->ds, qual, ds_absolute_maximum);
-               int_th = ds_get(context->ds, qual, ds_interrupt_threshold);
-
-               write_end = min(end, int_th);
-
-               /*
-                * If we are already beyond the interrupt threshold,
-                * we fill the entire buffer.
-                */
-               if (write_end <= index)
-                       write_end = end;
-
-               if (write_end <= index)
-                       break;
-
-               write_size = min((unsigned long) size, write_end - index);
-               memcpy((void *)index, record, write_size);
-
-               record = (const char *)record + write_size;
-               size -= write_size;
-               bytes_written += write_size;
-
-               adj_write_size = write_size / ds_cfg.sizeof_rec[qual];
-               adj_write_size *= ds_cfg.sizeof_rec[qual];
-
-               /* Zero out trailing bytes. */
-               memset((char *)index + write_size, 0,
-                      adj_write_size - write_size);
-               index += adj_write_size;
-
-               if (index >= end)
-                       index = base;
-               ds_set(context->ds, qual, ds_index, index);
-
-               if (index >= int_th)
-                       ds_overflow(context, qual);
-       }
-
-       return bytes_written;
-}
-
-
-/*
- * Branch Trace Store (BTS) uses the following format. Different
- * architectures vary in the size of those fields.
- * - source linear address
- * - destination linear address
- * - flags
- *
- * Later architectures use 64bit pointers throughout, whereas earlier
- * architectures use 32bit pointers in 32bit mode.
- *
- * We compute the base address for the fields based on:
- * - the field size stored in the DS configuration
- * - the relative field position
- *
- * In order to store additional information in the BTS buffer, we use
- * a special source address to indicate that the record requires
- * special interpretation.
- *
- * Netburst indicated via a bit in the flags field whether the branch
- * was predicted; this is ignored.
- *
- * We use two levels of abstraction:
- * - the raw data level defined here
- * - an arch-independent level defined in ds.h
- */
-
-enum bts_field {
-       bts_from,
-       bts_to,
-       bts_flags,
-
-       bts_qual                = bts_from,
-       bts_clock               = bts_to,
-       bts_pid                 = bts_flags,
-
-       bts_qual_mask           = (bts_qual_max - 1),
-       bts_escape              = ((unsigned long)-1 & ~bts_qual_mask)
-};
-
-static inline unsigned long bts_get(const char *base, unsigned long field)
-{
-       base += (ds_cfg.sizeof_ptr_field * field);
-       return *(unsigned long *)base;
-}
-
-static inline void bts_set(char *base, unsigned long field, unsigned long val)
-{
-       base += (ds_cfg.sizeof_ptr_field * field);
-       (*(unsigned long *)base) = val;
-}
-
-
-/*
- * The raw BTS data is architecture dependent.
- *
- * For higher-level users, we give an arch-independent view.
- * - ds.h defines struct bts_struct
- * - bts_read translates one raw bts record into a bts_struct
- * - bts_write translates one bts_struct into the raw format and
- *   writes it into the top of the parameter tracer's buffer.
- *
- * return: bytes read/written on success; -Eerrno, otherwise
- */
-static int
-bts_read(struct bts_tracer *tracer, const void *at, struct bts_struct *out)
-{
-       if (!tracer)
-               return -EINVAL;
-
-       if (at < tracer->trace.ds.begin)
-               return -EINVAL;
-
-       if (tracer->trace.ds.end < (at + tracer->trace.ds.size))
-               return -EINVAL;
-
-       memset(out, 0, sizeof(*out));
-       if ((bts_get(at, bts_qual) & ~bts_qual_mask) == bts_escape) {
-               out->qualifier = (bts_get(at, bts_qual) & bts_qual_mask);
-               out->variant.event.clock = bts_get(at, bts_clock);
-               out->variant.event.pid = bts_get(at, bts_pid);
-       } else {
-               out->qualifier = bts_branch;
-               out->variant.lbr.from = bts_get(at, bts_from);
-               out->variant.lbr.to   = bts_get(at, bts_to);
-
-               if (!out->variant.lbr.from && !out->variant.lbr.to)
-                       out->qualifier = bts_invalid;
-       }
-
-       return ds_cfg.sizeof_rec[ds_bts];
-}
-
-static int bts_write(struct bts_tracer *tracer, const struct bts_struct *in)
-{
-       unsigned char raw[MAX_SIZEOF_BTS];
-
-       if (!tracer)
-               return -EINVAL;
-
-       if (MAX_SIZEOF_BTS < ds_cfg.sizeof_rec[ds_bts])
-               return -EOVERFLOW;
-
-       switch (in->qualifier) {
-       case bts_invalid:
-               bts_set(raw, bts_from, 0);
-               bts_set(raw, bts_to, 0);
-               bts_set(raw, bts_flags, 0);
-               break;
-       case bts_branch:
-               bts_set(raw, bts_from, in->variant.lbr.from);
-               bts_set(raw, bts_to,   in->variant.lbr.to);
-               bts_set(raw, bts_flags, 0);
-               break;
-       case bts_task_arrives:
-       case bts_task_departs:
-               bts_set(raw, bts_qual, (bts_escape | in->qualifier));
-               bts_set(raw, bts_clock, in->variant.event.clock);
-               bts_set(raw, bts_pid, in->variant.event.pid);
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       return ds_write(tracer->ds.context, ds_bts, raw,
-                       ds_cfg.sizeof_rec[ds_bts]);
-}
-
-
-static void ds_write_config(struct ds_context *context,
-                           struct ds_trace *cfg, enum ds_qualifier qual)
-{
-       unsigned char *ds = context->ds;
-
-       ds_set(ds, qual, ds_buffer_base, (unsigned long)cfg->begin);
-       ds_set(ds, qual, ds_index, (unsigned long)cfg->top);
-       ds_set(ds, qual, ds_absolute_maximum, (unsigned long)cfg->end);
-       ds_set(ds, qual, ds_interrupt_threshold, (unsigned long)cfg->ith);
-}
-
-static void ds_read_config(struct ds_context *context,
-                          struct ds_trace *cfg, enum ds_qualifier qual)
-{
-       unsigned char *ds = context->ds;
-
-       cfg->begin = (void *)ds_get(ds, qual, ds_buffer_base);
-       cfg->top = (void *)ds_get(ds, qual, ds_index);
-       cfg->end = (void *)ds_get(ds, qual, ds_absolute_maximum);
-       cfg->ith = (void *)ds_get(ds, qual, ds_interrupt_threshold);
-}
-
-static void ds_init_ds_trace(struct ds_trace *trace, enum ds_qualifier qual,
-                            void *base, size_t size, size_t ith,
-                            unsigned int flags) {
-       unsigned long buffer, adj;
-
-       /*
-        * Adjust the buffer address and size to meet alignment
-        * constraints:
-        * - buffer is double-word aligned
-        * - size is multiple of record size
-        *
-        * We checked the size at the very beginning; we have enough
-        * space to do the adjustment.
-        */
-       buffer = (unsigned long)base;
-
-       adj = ALIGN(buffer, DS_ALIGNMENT) - buffer;
-       buffer += adj;
-       size   -= adj;
-
-       trace->n = size / ds_cfg.sizeof_rec[qual];
-       trace->size = ds_cfg.sizeof_rec[qual];
-
-       size = (trace->n * trace->size);
-
-       trace->begin = (void *)buffer;
-       trace->top = trace->begin;
-       trace->end = (void *)(buffer + size);
-       /*
-        * The value for 'no threshold' is -1, which will set the
-        * threshold outside of the buffer, just like we want it.
-        */
-       ith *= ds_cfg.sizeof_rec[qual];
-       trace->ith = (void *)(buffer + size - ith);
-
-       trace->flags = flags;
-}
-
-
-static int ds_request(struct ds_tracer *tracer, struct ds_trace *trace,
-                     enum ds_qualifier qual, struct task_struct *task,
-                     int cpu, void *base, size_t size, size_t th)
-{
-       struct ds_context *context;
-       int error;
-       size_t req_size;
-
-       error = -EOPNOTSUPP;
-       if (!ds_cfg.sizeof_rec[qual])
-               goto out;
-
-       error = -EINVAL;
-       if (!base)
-               goto out;
-
-       req_size = ds_cfg.sizeof_rec[qual];
-       /* We might need space for alignment adjustments. */
-       if (!IS_ALIGNED((unsigned long)base, DS_ALIGNMENT))
-               req_size += DS_ALIGNMENT;
-
-       error = -EINVAL;
-       if (size < req_size)
-               goto out;
-
-       if (th != (size_t)-1) {
-               th *= ds_cfg.sizeof_rec[qual];
-
-               error = -EINVAL;
-               if (size <= th)
-                       goto out;
-       }
-
-       tracer->buffer = base;
-       tracer->size = size;
-
-       error = -ENOMEM;
-       context = ds_get_context(task, cpu);
-       if (!context)
-               goto out;
-       tracer->context = context;
-
-       /*
-        * Defer any tracer-specific initialization work for the context until
-        * context ownership has been clarified.
-        */
-
-       error = 0;
- out:
-       return error;
-}
-
-static struct bts_tracer *ds_request_bts(struct task_struct *task, int cpu,
-                                        void *base, size_t size,
-                                        bts_ovfl_callback_t ovfl, size_t th,
-                                        unsigned int flags)
-{
-       struct bts_tracer *tracer;
-       int error;
-
-       /* Buffer overflow notification is not yet implemented. */
-       error = -EOPNOTSUPP;
-       if (ovfl)
-               goto out;
-
-       error = get_tracer(task);
-       if (error < 0)
-               goto out;
-
-       error = -ENOMEM;
-       tracer = kzalloc(sizeof(*tracer), GFP_KERNEL);
-       if (!tracer)
-               goto out_put_tracer;
-       tracer->ovfl = ovfl;
-
-       /* Do some more error checking and acquire a tracing context. */
-       error = ds_request(&tracer->ds, &tracer->trace.ds,
-                          ds_bts, task, cpu, base, size, th);
-       if (error < 0)
-               goto out_tracer;
-
-       /* Claim the bts part of the tracing context we acquired above. */
-       spin_lock_irq(&ds_lock);
-
-       error = -EPERM;
-       if (tracer->ds.context->bts_master)
-               goto out_unlock;
-       tracer->ds.context->bts_master = tracer;
-
-       spin_unlock_irq(&ds_lock);
-
-       /*
-        * Now that we own the bts part of the context, let's complete the
-        * initialization for that part.
-        */
-       ds_init_ds_trace(&tracer->trace.ds, ds_bts, base, size, th, flags);
-       ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_bts);
-       ds_install_ds_area(tracer->ds.context);
-
-       tracer->trace.read  = bts_read;
-       tracer->trace.write = bts_write;
-
-       /* Start tracing. */
-       ds_resume_bts(tracer);
-
-       return tracer;
-
- out_unlock:
-       spin_unlock_irq(&ds_lock);
-       ds_put_context(tracer->ds.context);
- out_tracer:
-       kfree(tracer);
- out_put_tracer:
-       put_tracer(task);
- out:
-       return ERR_PTR(error);
-}
-
-struct bts_tracer *ds_request_bts_task(struct task_struct *task,
-                                      void *base, size_t size,
-                                      bts_ovfl_callback_t ovfl,
-                                      size_t th, unsigned int flags)
-{
-       return ds_request_bts(task, 0, base, size, ovfl, th, flags);
-}
-
-struct bts_tracer *ds_request_bts_cpu(int cpu, void *base, size_t size,
-                                     bts_ovfl_callback_t ovfl,
-                                     size_t th, unsigned int flags)
-{
-       return ds_request_bts(NULL, cpu, base, size, ovfl, th, flags);
-}
-
-static struct pebs_tracer *ds_request_pebs(struct task_struct *task, int cpu,
-                                          void *base, size_t size,
-                                          pebs_ovfl_callback_t ovfl, size_t th,
-                                          unsigned int flags)
-{
-       struct pebs_tracer *tracer;
-       int error;
-
-       /* Buffer overflow notification is not yet implemented. */
-       error = -EOPNOTSUPP;
-       if (ovfl)
-               goto out;
-
-       error = get_tracer(task);
-       if (error < 0)
-               goto out;
-
-       error = -ENOMEM;
-       tracer = kzalloc(sizeof(*tracer), GFP_KERNEL);
-       if (!tracer)
-               goto out_put_tracer;
-       tracer->ovfl = ovfl;
-
-       /* Do some more error checking and acquire a tracing context. */
-       error = ds_request(&tracer->ds, &tracer->trace.ds,
-                          ds_pebs, task, cpu, base, size, th);
-       if (error < 0)
-               goto out_tracer;
-
-       /* Claim the pebs part of the tracing context we acquired above. */
-       spin_lock_irq(&ds_lock);
-
-       error = -EPERM;
-       if (tracer->ds.context->pebs_master)
-               goto out_unlock;
-       tracer->ds.context->pebs_master = tracer;
-
-       spin_unlock_irq(&ds_lock);
-
-       /*
-        * Now that we own the pebs part of the context, let's complete the
-        * initialization for that part.
-        */
-       ds_init_ds_trace(&tracer->trace.ds, ds_pebs, base, size, th, flags);
-       ds_write_config(tracer->ds.context, &tracer->trace.ds, ds_pebs);
-       ds_install_ds_area(tracer->ds.context);
-
-       /* Start tracing. */
-       ds_resume_pebs(tracer);
-
-       return tracer;
-
- out_unlock:
-       spin_unlock_irq(&ds_lock);
-       ds_put_context(tracer->ds.context);
- out_tracer:
-       kfree(tracer);
- out_put_tracer:
-       put_tracer(task);
- out:
-       return ERR_PTR(error);
-}
-
-struct pebs_tracer *ds_request_pebs_task(struct task_struct *task,
-                                        void *base, size_t size,
-                                        pebs_ovfl_callback_t ovfl,
-                                        size_t th, unsigned int flags)
-{
-       return ds_request_pebs(task, 0, base, size, ovfl, th, flags);
-}
-
-struct pebs_tracer *ds_request_pebs_cpu(int cpu, void *base, size_t size,
-                                       pebs_ovfl_callback_t ovfl,
-                                       size_t th, unsigned int flags)
-{
-       return ds_request_pebs(NULL, cpu, base, size, ovfl, th, flags);
-}
-
-static void ds_free_bts(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-
-       task = tracer->ds.context->task;
-
-       WARN_ON_ONCE(tracer->ds.context->bts_master != tracer);
-       tracer->ds.context->bts_master = NULL;
-
-       /* Make sure tracing stopped and the tracer is not in use. */
-       if (task && (task != current))
-               wait_task_context_switch(task);
-
-       ds_put_context(tracer->ds.context);
-       put_tracer(task);
-
-       kfree(tracer);
-}
-
-void ds_release_bts(struct bts_tracer *tracer)
-{
-       might_sleep();
-
-       if (!tracer)
-               return;
-
-       ds_suspend_bts(tracer);
-       ds_free_bts(tracer);
-}
-
-int ds_release_bts_noirq(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long irq;
-       int error;
-
-       if (!tracer)
-               return 0;
-
-       task = tracer->ds.context->task;
-
-       local_irq_save(irq);
-
-       error = -EPERM;
-       if (!task &&
-           (tracer->ds.context->cpu != smp_processor_id()))
-               goto out;
-
-       error = -EPERM;
-       if (task && (task != current))
-               goto out;
-
-       ds_suspend_bts_noirq(tracer);
-       ds_free_bts(tracer);
-
-       error = 0;
- out:
-       local_irq_restore(irq);
-       return error;
-}
-
-static void update_task_debugctlmsr(struct task_struct *task,
-                                   unsigned long debugctlmsr)
-{
-       task->thread.debugctlmsr = debugctlmsr;
-
-       get_cpu();
-       if (task == current)
-               update_debugctlmsr(debugctlmsr);
-       put_cpu();
-}
-
-void ds_suspend_bts(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long debugctlmsr;
-       int cpu;
-
-       if (!tracer)
-               return;
-
-       tracer->flags = 0;
-
-       task = tracer->ds.context->task;
-       cpu  = tracer->ds.context->cpu;
-
-       WARN_ON(!task && irqs_disabled());
-
-       debugctlmsr = (task ?
-                      task->thread.debugctlmsr :
-                      get_debugctlmsr_on_cpu(cpu));
-       debugctlmsr &= ~BTS_CONTROL;
-
-       if (task)
-               update_task_debugctlmsr(task, debugctlmsr);
-       else
-               update_debugctlmsr_on_cpu(cpu, debugctlmsr);
-}
-
-int ds_suspend_bts_noirq(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long debugctlmsr, irq;
-       int cpu, error = 0;
-
-       if (!tracer)
-               return 0;
-
-       tracer->flags = 0;
-
-       task = tracer->ds.context->task;
-       cpu  = tracer->ds.context->cpu;
-
-       local_irq_save(irq);
-
-       error = -EPERM;
-       if (!task && (cpu != smp_processor_id()))
-               goto out;
-
-       debugctlmsr = (task ?
-                      task->thread.debugctlmsr :
-                      get_debugctlmsr());
-       debugctlmsr &= ~BTS_CONTROL;
-
-       if (task)
-               update_task_debugctlmsr(task, debugctlmsr);
-       else
-               update_debugctlmsr(debugctlmsr);
-
-       error = 0;
- out:
-       local_irq_restore(irq);
-       return error;
-}
-
-static unsigned long ds_bts_control(struct bts_tracer *tracer)
-{
-       unsigned long control;
-
-       control = ds_cfg.ctl[dsf_bts];
-       if (!(tracer->trace.ds.flags & BTS_KERNEL))
-               control |= ds_cfg.ctl[dsf_bts_kernel];
-       if (!(tracer->trace.ds.flags & BTS_USER))
-               control |= ds_cfg.ctl[dsf_bts_user];
-
-       return control;
-}
-
-void ds_resume_bts(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long debugctlmsr;
-       int cpu;
-
-       if (!tracer)
-               return;
-
-       tracer->flags = tracer->trace.ds.flags;
-
-       task = tracer->ds.context->task;
-       cpu  = tracer->ds.context->cpu;
-
-       WARN_ON(!task && irqs_disabled());
-
-       debugctlmsr = (task ?
-                      task->thread.debugctlmsr :
-                      get_debugctlmsr_on_cpu(cpu));
-       debugctlmsr |= ds_bts_control(tracer);
-
-       if (task)
-               update_task_debugctlmsr(task, debugctlmsr);
-       else
-               update_debugctlmsr_on_cpu(cpu, debugctlmsr);
-}
-
-int ds_resume_bts_noirq(struct bts_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long debugctlmsr, irq;
-       int cpu, error = 0;
-
-       if (!tracer)
-               return 0;
-
-       tracer->flags = tracer->trace.ds.flags;
-
-       task = tracer->ds.context->task;
-       cpu  = tracer->ds.context->cpu;
-
-       local_irq_save(irq);
-
-       error = -EPERM;
-       if (!task && (cpu != smp_processor_id()))
-               goto out;
-
-       debugctlmsr = (task ?
-                      task->thread.debugctlmsr :
-                      get_debugctlmsr());
-       debugctlmsr |= ds_bts_control(tracer);
-
-       if (task)
-               update_task_debugctlmsr(task, debugctlmsr);
-       else
-               update_debugctlmsr(debugctlmsr);
-
-       error = 0;
- out:
-       local_irq_restore(irq);
-       return error;
-}
-
-static void ds_free_pebs(struct pebs_tracer *tracer)
-{
-       struct task_struct *task;
-
-       task = tracer->ds.context->task;
-
-       WARN_ON_ONCE(tracer->ds.context->pebs_master != tracer);
-       tracer->ds.context->pebs_master = NULL;
-
-       ds_put_context(tracer->ds.context);
-       put_tracer(task);
-
-       kfree(tracer);
-}
-
-void ds_release_pebs(struct pebs_tracer *tracer)
-{
-       might_sleep();
-
-       if (!tracer)
-               return;
-
-       ds_suspend_pebs(tracer);
-       ds_free_pebs(tracer);
-}
-
-int ds_release_pebs_noirq(struct pebs_tracer *tracer)
-{
-       struct task_struct *task;
-       unsigned long irq;
-       int error;
-
-       if (!tracer)
-               return 0;
-
-       task = tracer->ds.context->task;
-
-       local_irq_save(irq);
-
-       error = -EPERM;
-       if (!task &&
-           (tracer->ds.context->cpu != smp_processor_id()))
-               goto out;
-
-       error = -EPERM;
-       if (task && (task != current))
-               goto out;
-
-       ds_suspend_pebs_noirq(tracer);
-       ds_free_pebs(tracer);
-
-       error = 0;
- out:
-       local_irq_restore(irq);
-       return error;
-}
-
-void ds_suspend_pebs(struct pebs_tracer *tracer)
-{
-
-}
-
-int ds_suspend_pebs_noirq(struct pebs_tracer *tracer)
-{
-       return 0;
-}
-
-void ds_resume_pebs(struct pebs_tracer *tracer)
-{
-
-}
-
-int ds_resume_pebs_noirq(struct pebs_tracer *tracer)
-{
-       return 0;
-}
-
-const struct bts_trace *ds_read_bts(struct bts_tracer *tracer)
-{
-       if (!tracer)
-               return NULL;
-
-       ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_bts);
-       return &tracer->trace;
-}
-
-const struct pebs_trace *ds_read_pebs(struct pebs_tracer *tracer)
-{
-       if (!tracer)
-               return NULL;
-
-       ds_read_config(tracer->ds.context, &tracer->trace.ds, ds_pebs);
-
-       tracer->trace.counters = ds_cfg.nr_counter_reset;
-       memcpy(tracer->trace.counter_reset,
-              tracer->ds.context->ds +
-              (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field),
-              ds_cfg.nr_counter_reset * PEBS_RESET_FIELD_SIZE);
-
-       return &tracer->trace;
-}
-
-int ds_reset_bts(struct bts_tracer *tracer)
-{
-       if (!tracer)
-               return -EINVAL;
-
-       tracer->trace.ds.top = tracer->trace.ds.begin;
-
-       ds_set(tracer->ds.context->ds, ds_bts, ds_index,
-              (unsigned long)tracer->trace.ds.top);
-
-       return 0;
-}
-
-int ds_reset_pebs(struct pebs_tracer *tracer)
-{
-       if (!tracer)
-               return -EINVAL;
-
-       tracer->trace.ds.top = tracer->trace.ds.begin;
-
-       ds_set(tracer->ds.context->ds, ds_pebs, ds_index,
-              (unsigned long)tracer->trace.ds.top);
-
-       return 0;
-}
-
-int ds_set_pebs_reset(struct pebs_tracer *tracer,
-                     unsigned int counter, u64 value)
-{
-       if (!tracer)
-               return -EINVAL;
-
-       if (ds_cfg.nr_counter_reset < counter)
-               return -EINVAL;
-
-       *(u64 *)(tracer->ds.context->ds +
-                (NUM_DS_PTR_FIELDS * ds_cfg.sizeof_ptr_field) +
-                (counter * PEBS_RESET_FIELD_SIZE)) = value;
-
-       return 0;
-}
-
-static const struct ds_configuration ds_cfg_netburst = {
-       .name = "Netburst",
-       .ctl[dsf_bts]           = (1 << 2) | (1 << 3),
-       .ctl[dsf_bts_kernel]    = (1 << 5),
-       .ctl[dsf_bts_user]      = (1 << 6),
-       .nr_counter_reset       = 1,
-};
-static const struct ds_configuration ds_cfg_pentium_m = {
-       .name = "Pentium M",
-       .ctl[dsf_bts]           = (1 << 6) | (1 << 7),
-       .nr_counter_reset       = 1,
-};
-static const struct ds_configuration ds_cfg_core2_atom = {
-       .name = "Core 2/Atom",
-       .ctl[dsf_bts]           = (1 << 6) | (1 << 7),
-       .ctl[dsf_bts_kernel]    = (1 << 9),
-       .ctl[dsf_bts_user]      = (1 << 10),
-       .nr_counter_reset       = 1,
-};
-static const struct ds_configuration ds_cfg_core_i7 = {
-       .name = "Core i7",
-       .ctl[dsf_bts]           = (1 << 6) | (1 << 7),
-       .ctl[dsf_bts_kernel]    = (1 << 9),
-       .ctl[dsf_bts_user]      = (1 << 10),
-       .nr_counter_reset       = 4,
-};
-
-static void
-ds_configure(const struct ds_configuration *cfg,
-            struct cpuinfo_x86 *cpu)
-{
-       unsigned long nr_pebs_fields = 0;
-
-       printk(KERN_INFO "[ds] using %s configuration\n", cfg->name);
-
-#ifdef __i386__
-       nr_pebs_fields = 10;
-#else
-       nr_pebs_fields = 18;
-#endif
-
-       /*
-        * Starting with version 2, architectural performance
-        * monitoring supports a format specifier.
-        */
-       if ((cpuid_eax(0xa) & 0xff) > 1) {
-               unsigned long perf_capabilities, format;
-
-               rdmsrl(MSR_IA32_PERF_CAPABILITIES, perf_capabilities);
-
-               format = (perf_capabilities >> 8) & 0xf;
-
-               switch (format) {
-               case 0:
-                       nr_pebs_fields = 18;
-                       break;
-               case 1:
-                       nr_pebs_fields = 22;
-                       break;
-               default:
-                       printk(KERN_INFO
-                              "[ds] unknown PEBS format: %lu\n", format);
-                       nr_pebs_fields = 0;
-                       break;
-               }
-       }
-
-       memset(&ds_cfg, 0, sizeof(ds_cfg));
-       ds_cfg = *cfg;
-
-       ds_cfg.sizeof_ptr_field =
-               (cpu_has(cpu, X86_FEATURE_DTES64) ? 8 : 4);
-
-       ds_cfg.sizeof_rec[ds_bts]  = ds_cfg.sizeof_ptr_field * 3;
-       ds_cfg.sizeof_rec[ds_pebs] = ds_cfg.sizeof_ptr_field * nr_pebs_fields;
-
-       if (!cpu_has(cpu, X86_FEATURE_BTS)) {
-               ds_cfg.sizeof_rec[ds_bts] = 0;
-               printk(KERN_INFO "[ds] bts not available\n");
-       }
-       if (!cpu_has(cpu, X86_FEATURE_PEBS)) {
-               ds_cfg.sizeof_rec[ds_pebs] = 0;
-               printk(KERN_INFO "[ds] pebs not available\n");
-       }
-
-       printk(KERN_INFO "[ds] sizes: address: %u bit, ",
-              8 * ds_cfg.sizeof_ptr_field);
-       printk("bts/pebs record: %u/%u bytes\n",
-              ds_cfg.sizeof_rec[ds_bts], ds_cfg.sizeof_rec[ds_pebs]);
-
-       WARN_ON_ONCE(MAX_PEBS_COUNTERS < ds_cfg.nr_counter_reset);
-}
-
-void __cpuinit ds_init_intel(struct cpuinfo_x86 *c)
-{
-       /* Only configure the first cpu. Others are identical. */
-       if (ds_cfg.name)
-               return;
-
-       switch (c->x86) {
-       case 0x6:
-               switch (c->x86_model) {
-               case 0x9:
-               case 0xd: /* Pentium M */
-                       ds_configure(&ds_cfg_pentium_m, c);
-                       break;
-               case 0xf:
-               case 0x17: /* Core2 */
-               case 0x1c: /* Atom */
-                       ds_configure(&ds_cfg_core2_atom, c);
-                       break;
-               case 0x1a: /* Core i7 */
-                       ds_configure(&ds_cfg_core_i7, c);
-                       break;
-               default:
-                       /* Sorry, don't know about them. */
-                       break;
-               }
-               break;
-       case 0xf:
-               switch (c->x86_model) {
-               case 0x0:
-               case 0x1:
-               case 0x2: /* Netburst */
-                       ds_configure(&ds_cfg_netburst, c);
-                       break;
-               default:
-                       /* Sorry, don't know about them. */
-                       break;
-               }
-               break;
-       default:
-               /* Sorry, don't know about them. */
-               break;
-       }
-}
-
-static inline void ds_take_timestamp(struct ds_context *context,
-                                    enum bts_qualifier qualifier,
-                                    struct task_struct *task)
-{
-       struct bts_tracer *tracer = context->bts_master;
-       struct bts_struct ts;
-
-       /* Prevent compilers from reading the tracer pointer twice. */
-       barrier();
-
-       if (!tracer || !(tracer->flags & BTS_TIMESTAMPS))
-               return;
-
-       memset(&ts, 0, sizeof(ts));
-       ts.qualifier            = qualifier;
-       ts.variant.event.clock  = trace_clock_global();
-       ts.variant.event.pid    = task->pid;
-
-       bts_write(tracer, &ts);
-}
-
-/*
- * Change the DS configuration from tracing prev to tracing next.
- */
-void ds_switch_to(struct task_struct *prev, struct task_struct *next)
-{
-       struct ds_context *prev_ctx     = prev->thread.ds_ctx;
-       struct ds_context *next_ctx     = next->thread.ds_ctx;
-       unsigned long debugctlmsr       = next->thread.debugctlmsr;
-
-       /* Make sure all data is read before we start. */
-       barrier();
-
-       if (prev_ctx) {
-               update_debugctlmsr(0);
-
-               ds_take_timestamp(prev_ctx, bts_task_departs, prev);
-       }
-
-       if (next_ctx) {
-               ds_take_timestamp(next_ctx, bts_task_arrives, next);
-
-               wrmsrl(MSR_IA32_DS_AREA, (unsigned long)next_ctx->ds);
-       }
-
-       update_debugctlmsr(debugctlmsr);
-}
-
-static __init int ds_selftest(void)
-{
-       if (ds_cfg.sizeof_rec[ds_bts]) {
-               int error;
-
-               error = ds_selftest_bts();
-               if (error) {
-                       WARN(1, "[ds] selftest failed. disabling bts.\n");
-                       ds_cfg.sizeof_rec[ds_bts] = 0;
-               }
-       }
-
-       if (ds_cfg.sizeof_rec[ds_pebs]) {
-               int error;
-
-               error = ds_selftest_pebs();
-               if (error) {
-                       WARN(1, "[ds] selftest failed. disabling pebs.\n");
-                       ds_cfg.sizeof_rec[ds_pebs] = 0;
-               }
-       }
-
-       return 0;
-}
-device_initcall(ds_selftest);
diff --git a/arch/x86/kernel/ds_selftest.c b/arch/x86/kernel/ds_selftest.c
deleted file mode 100644 (file)
index 6bc7c19..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Debug Store support - selftest
- *
- *
- * Copyright (C) 2009 Intel Corporation.
- * Markus Metzger <markus.t.metzger@intel.com>, 2009
- */
-
-#include "ds_selftest.h"
-
-#include <linux/kernel.h>
-#include <linux/string.h>
-#include <linux/smp.h>
-#include <linux/cpu.h>
-
-#include <asm/ds.h>
-
-
-#define BUFFER_SIZE            521     /* Intentionally chose an odd size. */
-#define SMALL_BUFFER_SIZE      24      /* A single bts entry. */
-
-struct ds_selftest_bts_conf {
-       struct bts_tracer *tracer;
-       int error;
-       int (*suspend)(struct bts_tracer *);
-       int (*resume)(struct bts_tracer *);
-};
-
-static int ds_selftest_bts_consistency(const struct bts_trace *trace)
-{
-       int error = 0;
-
-       if (!trace) {
-               printk(KERN_CONT "failed to access trace...");
-               /* Bail out. Other tests are pointless. */
-               return -1;
-       }
-
-       if (!trace->read) {
-               printk(KERN_CONT "bts read not available...");
-               error = -1;
-       }
-
-       /* Do some sanity checks on the trace configuration. */
-       if (!trace->ds.n) {
-               printk(KERN_CONT "empty bts buffer...");
-               error = -1;
-       }
-       if (!trace->ds.size) {
-               printk(KERN_CONT "bad bts trace setup...");
-               error = -1;
-       }
-       if (trace->ds.end !=
-           (char *)trace->ds.begin + (trace->ds.n * trace->ds.size)) {
-               printk(KERN_CONT "bad bts buffer setup...");
-               error = -1;
-       }
-       /*
-        * We allow top in [begin; end], since its not clear when the
-        * overflow adjustment happens: after the increment or before the
-        * write.
-        */
-       if ((trace->ds.top < trace->ds.begin) ||
-           (trace->ds.end < trace->ds.top)) {
-               printk(KERN_CONT "bts top out of bounds...");
-               error = -1;
-       }
-
-       return error;
-}
-
-static int ds_selftest_bts_read(struct bts_tracer *tracer,
-                               const struct bts_trace *trace,
-                               const void *from, const void *to)
-{
-       const unsigned char *at;
-
-       /*
-        * Check a few things which do not belong to this test.
-        * They should be covered by other tests.
-        */
-       if (!trace)
-               return -1;
-
-       if (!trace->read)
-               return -1;
-
-       if (to < from)
-               return -1;
-
-       if (from < trace->ds.begin)
-               return -1;
-
-       if (trace->ds.end < to)
-               return -1;
-
-       if (!trace->ds.size)
-               return -1;
-
-       /* Now to the test itself. */
-       for (at = from; (void *)at < to; at += trace->ds.size) {
-               struct bts_struct bts;
-               unsigned long index;
-               int error;
-
-               if (((void *)at - trace->ds.begin) % trace->ds.size) {
-                       printk(KERN_CONT
-                              "read from non-integer index...");
-                       return -1;
-               }
-               index = ((void *)at - trace->ds.begin) / trace->ds.size;
-
-               memset(&bts, 0, sizeof(bts));
-               error = trace->read(tracer, at, &bts);
-               if (error < 0) {
-                       printk(KERN_CONT
-                              "error reading bts trace at [%lu] (0x%p)...",
-                              index, at);
-                       return error;
-               }
-
-               switch (bts.qualifier) {
-               case BTS_BRANCH:
-                       break;
-               default:
-                       printk(KERN_CONT
-                              "unexpected bts entry %llu at [%lu] (0x%p)...",
-                              bts.qualifier, index, at);
-                       return -1;
-               }
-       }
-
-       return 0;
-}
-
-static void ds_selftest_bts_cpu(void *arg)
-{
-       struct ds_selftest_bts_conf *conf = arg;
-       const struct bts_trace *trace;
-       void *top;
-
-       if (IS_ERR(conf->tracer)) {
-               conf->error = PTR_ERR(conf->tracer);
-               conf->tracer = NULL;
-
-               printk(KERN_CONT
-                      "initialization failed (err: %d)...", conf->error);
-               return;
-       }
-
-       /* We should meanwhile have enough trace. */
-       conf->error = conf->suspend(conf->tracer);
-       if (conf->error < 0)
-               return;
-
-       /* Let's see if we can access the trace. */
-       trace = ds_read_bts(conf->tracer);
-
-       conf->error = ds_selftest_bts_consistency(trace);
-       if (conf->error < 0)
-               return;
-
-       /* If everything went well, we should have a few trace entries. */
-       if (trace->ds.top == trace->ds.begin) {
-               /*
-                * It is possible but highly unlikely that we got a
-                * buffer overflow and end up at exactly the same
-                * position we started from.
-                * Let's issue a warning, but continue.
-                */
-               printk(KERN_CONT "no trace/overflow...");
-       }
-
-       /* Let's try to read the trace we collected. */
-       conf->error =
-               ds_selftest_bts_read(conf->tracer, trace,
-                                    trace->ds.begin, trace->ds.top);
-       if (conf->error < 0)
-               return;
-
-       /*
-        * Let's read the trace again.
-        * Since we suspended tracing, we should get the same result.
-        */
-       top = trace->ds.top;
-
-       trace = ds_read_bts(conf->tracer);
-       conf->error = ds_selftest_bts_consistency(trace);
-       if (conf->error < 0)
-               return;
-
-       if (top != trace->ds.top) {
-               printk(KERN_CONT "suspend not working...");
-               conf->error = -1;
-               return;
-       }
-
-       /* Let's collect some more trace - see if resume is working. */
-       conf->error = conf->resume(conf->tracer);
-       if (conf->error < 0)
-               return;
-
-       conf->error = conf->suspend(conf->tracer);
-       if (conf->error < 0)
-               return;
-
-       trace = ds_read_bts(conf->tracer);
-
-       conf->error = ds_selftest_bts_consistency(trace);
-       if (conf->error < 0)
-               return;
-
-       if (trace->ds.top == top) {
-               /*
-                * It is possible but highly unlikely that we got a
-                * buffer overflow and end up at exactly the same
-                * position we started from.
-                * Let's issue a warning and check the full trace.
-                */
-               printk(KERN_CONT
-                      "no resume progress/overflow...");
-
-               conf->error =
-                       ds_selftest_bts_read(conf->tracer, trace,
-                                            trace->ds.begin, trace->ds.end);
-       } else if (trace->ds.top < top) {
-               /*
-                * We had a buffer overflow - the entire buffer should
-                * contain trace records.
-                */
-               conf->error =
-                       ds_selftest_bts_read(conf->tracer, trace,
-                                            trace->ds.begin, trace->ds.end);
-       } else {
-               /*
-                * It is quite likely that the buffer did not overflow.
-                * Let's just check the delta trace.
-                */
-               conf->error =
-                       ds_selftest_bts_read(conf->tracer, trace, top,
-                                            trace->ds.top);
-       }
-       if (conf->error < 0)
-               return;
-
-       conf->error = 0;
-}
-
-static int ds_suspend_bts_wrap(struct bts_tracer *tracer)
-{
-       ds_suspend_bts(tracer);
-       return 0;
-}
-
-static int ds_resume_bts_wrap(struct bts_tracer *tracer)
-{
-       ds_resume_bts(tracer);
-       return 0;
-}
-
-static void ds_release_bts_noirq_wrap(void *tracer)
-{
-       (void)ds_release_bts_noirq(tracer);
-}
-
-static int ds_selftest_bts_bad_release_noirq(int cpu,
-                                            struct bts_tracer *tracer)
-{
-       int error = -EPERM;
-
-       /* Try to release the tracer on the wrong cpu. */
-       get_cpu();
-       if (cpu != smp_processor_id()) {
-               error = ds_release_bts_noirq(tracer);
-               if (error != -EPERM)
-                       printk(KERN_CONT "release on wrong cpu...");
-       }
-       put_cpu();
-
-       return error ? 0 : -1;
-}
-
-static int ds_selftest_bts_bad_request_cpu(int cpu, void *buffer)
-{
-       struct bts_tracer *tracer;
-       int error;
-
-       /* Try to request cpu tracing while task tracing is active. */
-       tracer = ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE, NULL,
-                                   (size_t)-1, BTS_KERNEL);
-       error = PTR_ERR(tracer);
-       if (!IS_ERR(tracer)) {
-               ds_release_bts(tracer);
-               error = 0;
-       }
-
-       if (error != -EPERM)
-               printk(KERN_CONT "cpu/task tracing overlap...");
-
-       return error ? 0 : -1;
-}
-
-static int ds_selftest_bts_bad_request_task(void *buffer)
-{
-       struct bts_tracer *tracer;
-       int error;
-
-       /* Try to request cpu tracing while task tracing is active. */
-       tracer = ds_request_bts_task(current, buffer, BUFFER_SIZE, NULL,
-                                   (size_t)-1, BTS_KERNEL);
-       error = PTR_ERR(tracer);
-       if (!IS_ERR(tracer)) {
-               error = 0;
-               ds_release_bts(tracer);
-       }
-
-       if (error != -EPERM)
-               printk(KERN_CONT "task/cpu tracing overlap...");
-
-       return error ? 0 : -1;
-}
-
-int ds_selftest_bts(void)
-{
-       struct ds_selftest_bts_conf conf;
-       unsigned char buffer[BUFFER_SIZE], *small_buffer;
-       unsigned long irq;
-       int cpu;
-
-       printk(KERN_INFO "[ds] bts selftest...");
-       conf.error = 0;
-
-       small_buffer = (unsigned char *)ALIGN((unsigned long)buffer, 8) + 8;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu) {
-               conf.suspend = ds_suspend_bts_wrap;
-               conf.resume = ds_resume_bts_wrap;
-               conf.tracer =
-                       ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE,
-                                          NULL, (size_t)-1, BTS_KERNEL);
-               ds_selftest_bts_cpu(&conf);
-               if (conf.error >= 0)
-                       conf.error = ds_selftest_bts_bad_request_task(buffer);
-               ds_release_bts(conf.tracer);
-               if (conf.error < 0)
-                       goto out;
-
-               conf.suspend = ds_suspend_bts_noirq;
-               conf.resume = ds_resume_bts_noirq;
-               conf.tracer =
-                       ds_request_bts_cpu(cpu, buffer, BUFFER_SIZE,
-                                          NULL, (size_t)-1, BTS_KERNEL);
-               smp_call_function_single(cpu, ds_selftest_bts_cpu, &conf, 1);
-               if (conf.error >= 0) {
-                       conf.error =
-                               ds_selftest_bts_bad_release_noirq(cpu,
-                                                                 conf.tracer);
-                       /* We must not release the tracer twice. */
-                       if (conf.error < 0)
-                               conf.tracer = NULL;
-               }
-               if (conf.error >= 0)
-                       conf.error = ds_selftest_bts_bad_request_task(buffer);
-               smp_call_function_single(cpu, ds_release_bts_noirq_wrap,
-                                        conf.tracer, 1);
-               if (conf.error < 0)
-                       goto out;
-       }
-
-       conf.suspend = ds_suspend_bts_wrap;
-       conf.resume = ds_resume_bts_wrap;
-       conf.tracer =
-               ds_request_bts_task(current, buffer, BUFFER_SIZE,
-                                   NULL, (size_t)-1, BTS_KERNEL);
-       ds_selftest_bts_cpu(&conf);
-       if (conf.error >= 0)
-               conf.error = ds_selftest_bts_bad_request_cpu(0, buffer);
-       ds_release_bts(conf.tracer);
-       if (conf.error < 0)
-               goto out;
-
-       conf.suspend = ds_suspend_bts_noirq;
-       conf.resume = ds_resume_bts_noirq;
-       conf.tracer =
-               ds_request_bts_task(current, small_buffer, SMALL_BUFFER_SIZE,
-                                  NULL, (size_t)-1, BTS_KERNEL);
-       local_irq_save(irq);
-       ds_selftest_bts_cpu(&conf);
-       if (conf.error >= 0)
-               conf.error = ds_selftest_bts_bad_request_cpu(0, buffer);
-       ds_release_bts_noirq(conf.tracer);
-       local_irq_restore(irq);
-       if (conf.error < 0)
-               goto out;
-
-       conf.error = 0;
- out:
-       put_online_cpus();
-       printk(KERN_CONT "%s.\n", (conf.error ? "failed" : "passed"));
-
-       return conf.error;
-}
-
-int ds_selftest_pebs(void)
-{
-       return 0;
-}
diff --git a/arch/x86/kernel/ds_selftest.h b/arch/x86/kernel/ds_selftest.h
deleted file mode 100644 (file)
index 2ba8745..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Debug Store support - selftest
- *
- *
- * Copyright (C) 2009 Intel Corporation.
- * Markus Metzger <markus.t.metzger@intel.com>, 2009
- */
-
-#ifdef CONFIG_X86_DS_SELFTEST
-extern int ds_selftest_bts(void);
-extern int ds_selftest_pebs(void);
-#else
-static inline int ds_selftest_bts(void) { return 0; }
-static inline int ds_selftest_pebs(void) { return 0; }
-#endif
index 6d81755..c89a386 100644 (file)
@@ -224,11 +224,6 @@ unsigned __kprobes long oops_begin(void)
        int cpu;
        unsigned long flags;
 
-       /* notify the hw-branch tracer so it may disable tracing and
-          add the last trace to the trace buffer -
-          the earlier this happens, the more useful the trace. */
-       trace_hw_branch_oops();
-
        oops_enter();
 
        /* racy, but better than risking deadlock. */
index 44a8e0d..cd49141 100644 (file)
@@ -53,6 +53,7 @@
 #include <asm/processor-flags.h>
 #include <asm/ftrace.h>
 #include <asm/irq_vectors.h>
+#include <asm/cpufeature.h>
 
 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this.  */
 #include <linux/elf-em.h>
@@ -905,7 +906,25 @@ ENTRY(simd_coprocessor_error)
        RING0_INT_FRAME
        pushl $0
        CFI_ADJUST_CFA_OFFSET 4
+#ifdef CONFIG_X86_INVD_BUG
+       /* AMD 486 bug: invd from userspace calls exception 19 instead of #GP */
+661:   pushl $do_general_protection
+662:
+.section .altinstructions,"a"
+       .balign 4
+       .long 661b
+       .long 663f
+       .byte X86_FEATURE_XMM
+       .byte 662b-661b
+       .byte 664f-663f
+.previous
+.section .altinstr_replacement,"ax"
+663:   pushl $do_simd_coprocessor_error
+664:
+.previous
+#else
        pushl $do_simd_coprocessor_error
+#endif
        CFI_ADJUST_CFA_OFFSET 4
        jmp error_code
        CFI_ENDPROC
index 23b4ecd..a198b7c 100644 (file)
@@ -36,6 +36,7 @@
 unsigned long                          hpet_address;
 u8                                     hpet_blockid; /* OS timer block num */
 u8                                     hpet_msi_disable;
+u8                                     hpet_readback_cmp;
 
 #ifdef CONFIG_PCI_MSI
 static unsigned long                   hpet_num_timers;
@@ -395,19 +396,23 @@ static int hpet_next_event(unsigned long delta,
         * at that point and we would wait for the next hpet interrupt
         * forever. We found out that reading the CMP register back
         * forces the transfer so we can rely on the comparison with
-        * the counter register below. If the read back from the
-        * compare register does not match the value we programmed
-        * then we might have a real hardware problem. We can not do
-        * much about it here, but at least alert the user/admin with
-        * a prominent warning.
-        * An erratum on some chipsets (ICH9,..), results in comparator read
-        * immediately following a write returning old value. Workaround
-        * for this is to read this value second time, when first
-        * read returns old value.
+        * the counter register below.
+        *
+        * That works fine on those ATI chipsets, but on newer Intel
+        * chipsets (ICH9...) this triggers due to an erratum: Reading
+        * the comparator immediately following a write is returning
+        * the old value.
+        *
+        * We restrict the read back to the affected ATI chipsets (set
+        * by quirks) and also run it with hpet=verbose for debugging
+        * purposes.
         */
-       if (unlikely((u32)hpet_readl(HPET_Tn_CMP(timer)) != cnt)) {
-               WARN_ONCE(hpet_readl(HPET_Tn_CMP(timer)) != cnt,
-                 KERN_WARNING "hpet: compare register read back failed.\n");
+       if (hpet_readback_cmp || hpet_verbose) {
+               u32 cmp = hpet_readl(HPET_Tn_CMP(timer));
+
+               if (cmp != cnt)
+                       printk_once(KERN_WARNING
+                           "hpet: compare register read back failed.\n");
        }
 
        return (s32)(hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0;
index d6cc065..a8f1b80 100644 (file)
@@ -188,26 +188,17 @@ static int get_hbp_len(u8 hbp_len)
        return len_in_bytes;
 }
 
-/*
- * Check for virtual address in user space.
- */
-int arch_check_va_in_userspace(unsigned long va, u8 hbp_len)
-{
-       unsigned int len;
-
-       len = get_hbp_len(hbp_len);
-
-       return (va <= TASK_SIZE - len);
-}
-
 /*
  * Check for virtual address in kernel space.
  */
-static int arch_check_va_in_kernelspace(unsigned long va, u8 hbp_len)
+int arch_check_bp_in_kernelspace(struct perf_event *bp)
 {
        unsigned int len;
+       unsigned long va;
+       struct arch_hw_breakpoint *info = counter_arch_bp(bp);
 
-       len = get_hbp_len(hbp_len);
+       va = info->address;
+       len = get_hbp_len(info->len);
 
        return (va >= TASK_SIZE) && ((va + len - 1) >= TASK_SIZE);
 }
@@ -300,8 +291,7 @@ static int arch_build_bp_info(struct perf_event *bp)
 /*
  * Validate the arch-specific HW Breakpoint register settings
  */
-int arch_validate_hwbkpt_settings(struct perf_event *bp,
-                                 struct task_struct *tsk)
+int arch_validate_hwbkpt_settings(struct perf_event *bp)
 {
        struct arch_hw_breakpoint *info = counter_arch_bp(bp);
        unsigned int align;
@@ -314,16 +304,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp,
 
        ret = -EINVAL;
 
-       if (info->type == X86_BREAKPOINT_EXECUTE)
-               /*
-                * Ptrace-refactoring code
-                * For now, we'll allow instruction breakpoint only for user-space
-                * addresses
-                */
-               if ((!arch_check_va_in_userspace(info->address, info->len)) &&
-                       info->len != X86_BREAKPOINT_EXECUTE)
-                       return ret;
-
        switch (info->len) {
        case X86_BREAKPOINT_LEN_1:
                align = 0;
@@ -350,15 +330,6 @@ int arch_validate_hwbkpt_settings(struct perf_event *bp,
        if (info->address & align)
                return -EINVAL;
 
-       /* Check that the virtual address is in the proper range */
-       if (tsk) {
-               if (!arch_check_va_in_userspace(info->address, info->len))
-                       return -EFAULT;
-       } else {
-               if (!arch_check_va_in_kernelspace(info->address, info->len))
-                       return -EFAULT;
-       }
-
        return 0;
 }
 
index 54c31c2..86cef6b 100644 (file)
@@ -102,65 +102,62 @@ void __cpuinit fpu_init(void)
 
        mxcsr_feature_mask_init();
        /* clean state in init */
-       if (cpu_has_xsave)
-               current_thread_info()->status = TS_XSAVE;
-       else
-               current_thread_info()->status = 0;
+       current_thread_info()->status = 0;
        clear_used_math();
 }
 #endif /* CONFIG_X86_64 */
 
-/*
- * The _current_ task is using the FPU for the first time
- * so initialize it and set the mxcsr to its default
- * value at reset if we support XMM instructions and then
- * remeber the current task has used the FPU.
- */
-int init_fpu(struct task_struct *tsk)
+static void fpu_finit(struct fpu *fpu)
 {
-       if (tsk_used_math(tsk)) {
-               if (HAVE_HWFP && tsk == current)
-                       unlazy_fpu(tsk);
-               return 0;
-       }
-
-       /*
-        * Memory allocation at the first usage of the FPU and other state.
-        */
-       if (!tsk->thread.xstate) {
-               tsk->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
-                                                     GFP_KERNEL);
-               if (!tsk->thread.xstate)
-                       return -ENOMEM;
-       }
-
 #ifdef CONFIG_X86_32
        if (!HAVE_HWFP) {
-               memset(tsk->thread.xstate, 0, xstate_size);
-               finit_task(tsk);
-               set_stopped_child_used_math(tsk);
-               return 0;
+               finit_soft_fpu(&fpu->state->soft);
+               return;
        }
 #endif
 
        if (cpu_has_fxsr) {
-               struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave;
+               struct i387_fxsave_struct *fx = &fpu->state->fxsave;
 
                memset(fx, 0, xstate_size);
                fx->cwd = 0x37f;
                if (cpu_has_xmm)
                        fx->mxcsr = MXCSR_DEFAULT;
        } else {
-               struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave;
+               struct i387_fsave_struct *fp = &fpu->state->fsave;
                memset(fp, 0, xstate_size);
                fp->cwd = 0xffff037fu;
                fp->swd = 0xffff0000u;
                fp->twd = 0xffffffffu;
                fp->fos = 0xffff0000u;
        }
+}
+
+/*
+ * The _current_ task is using the FPU for the first time
+ * so initialize it and set the mxcsr to its default
+ * value at reset if we support XMM instructions and then
+ * remeber the current task has used the FPU.
+ */
+int init_fpu(struct task_struct *tsk)
+{
+       int ret;
+
+       if (tsk_used_math(tsk)) {
+               if (HAVE_HWFP && tsk == current)
+                       unlazy_fpu(tsk);
+               return 0;
+       }
+
        /*
-        * Only the device not available exception or ptrace can call init_fpu.
+        * Memory allocation at the first usage of the FPU and other state.
         */
+       ret = fpu_alloc(&tsk->thread.fpu);
+       if (ret)
+               return ret;
+
+       fpu_finit(&tsk->thread.fpu);
+
        set_stopped_child_used_math(tsk);
        return 0;
 }
@@ -194,7 +191,7 @@ int xfpregs_get(struct task_struct *target, const struct user_regset *regset,
                return ret;
 
        return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-                                  &target->thread.xstate->fxsave, 0, -1);
+                                  &target->thread.fpu.state->fxsave, 0, -1);
 }
 
 int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
@@ -211,19 +208,19 @@ int xfpregs_set(struct task_struct *target, const struct user_regset *regset,
                return ret;
 
        ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
-                                &target->thread.xstate->fxsave, 0, -1);
+                                &target->thread.fpu.state->fxsave, 0, -1);
 
        /*
         * mxcsr reserved bits must be masked to zero for security reasons.
         */
-       target->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask;
+       target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask;
 
        /*
         * update the header bits in the xsave header, indicating the
         * presence of FP and SSE state.
         */
        if (cpu_has_xsave)
-               target->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
+               target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
 
        return ret;
 }
@@ -246,14 +243,14 @@ int xstateregs_get(struct task_struct *target, const struct user_regset *regset,
         * memory layout in the thread struct, so that we can copy the entire
         * xstateregs to the user using one user_regset_copyout().
         */
-       memcpy(&target->thread.xstate->fxsave.sw_reserved,
+       memcpy(&target->thread.fpu.state->fxsave.sw_reserved,
               xstate_fx_sw_bytes, sizeof(xstate_fx_sw_bytes));
 
        /*
         * Copy the xstate memory layout.
         */
        ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-                                 &target->thread.xstate->xsave, 0, -1);
+                                 &target->thread.fpu.state->xsave, 0, -1);
        return ret;
 }
 
@@ -272,14 +269,14 @@ int xstateregs_set(struct task_struct *target, const struct user_regset *regset,
                return ret;
 
        ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
-                                &target->thread.xstate->xsave, 0, -1);
+                                &target->thread.fpu.state->xsave, 0, -1);
 
        /*
         * mxcsr reserved bits must be masked to zero for security reasons.
         */
-       target->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask;
+       target->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask;
 
-       xsave_hdr = &target->thread.xstate->xsave.xsave_hdr;
+       xsave_hdr = &target->thread.fpu.state->xsave.xsave_hdr;
 
        xsave_hdr->xstate_bv &= pcntxt_mask;
        /*
@@ -365,7 +362,7 @@ static inline u32 twd_fxsr_to_i387(struct i387_fxsave_struct *fxsave)
 static void
 convert_from_fxsr(struct user_i387_ia32_struct *env, struct task_struct *tsk)
 {
-       struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave;
+       struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave;
        struct _fpreg *to = (struct _fpreg *) &env->st_space[0];
        struct _fpxreg *from = (struct _fpxreg *) &fxsave->st_space[0];
        int i;
@@ -405,7 +402,7 @@ static void convert_to_fxsr(struct task_struct *tsk,
                            const struct user_i387_ia32_struct *env)
 
 {
-       struct i387_fxsave_struct *fxsave = &tsk->thread.xstate->fxsave;
+       struct i387_fxsave_struct *fxsave = &tsk->thread.fpu.state->fxsave;
        struct _fpreg *from = (struct _fpreg *) &env->st_space[0];
        struct _fpxreg *to = (struct _fpxreg *) &fxsave->st_space[0];
        int i;
@@ -445,7 +442,7 @@ int fpregs_get(struct task_struct *target, const struct user_regset *regset,
 
        if (!cpu_has_fxsr) {
                return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
-                                          &target->thread.xstate->fsave, 0,
+                                          &target->thread.fpu.state->fsave, 0,
                                           -1);
        }
 
@@ -475,7 +472,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
 
        if (!cpu_has_fxsr) {
                return user_regset_copyin(&pos, &count, &kbuf, &ubuf,
-                                         &target->thread.xstate->fsave, 0, -1);
+                                         &target->thread.fpu.state->fsave, 0, -1);
        }
 
        if (pos > 0 || count < sizeof(env))
@@ -490,7 +487,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
         * presence of FP.
         */
        if (cpu_has_xsave)
-               target->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FP;
+               target->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FP;
        return ret;
 }
 
@@ -501,7 +498,7 @@ int fpregs_set(struct task_struct *target, const struct user_regset *regset,
 static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf)
 {
        struct task_struct *tsk = current;
-       struct i387_fsave_struct *fp = &tsk->thread.xstate->fsave;
+       struct i387_fsave_struct *fp = &tsk->thread.fpu.state->fsave;
 
        fp->status = fp->swd;
        if (__copy_to_user(buf, fp, sizeof(struct i387_fsave_struct)))
@@ -512,7 +509,7 @@ static inline int save_i387_fsave(struct _fpstate_ia32 __user *buf)
 static int save_i387_fxsave(struct _fpstate_ia32 __user *buf)
 {
        struct task_struct *tsk = current;
-       struct i387_fxsave_struct *fx = &tsk->thread.xstate->fxsave;
+       struct i387_fxsave_struct *fx = &tsk->thread.fpu.state->fxsave;
        struct user_i387_ia32_struct env;
        int err = 0;
 
@@ -547,7 +544,7 @@ static int save_i387_xsave(void __user *buf)
         * header as well as change any contents in the memory layout.
         * xrestore as part of sigreturn will capture all the changes.
         */
-       tsk->thread.xstate->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
+       tsk->thread.fpu.state->xsave.xsave_hdr.xstate_bv |= XSTATE_FPSSE;
 
        if (save_i387_fxsave(fx) < 0)
                return -1;
@@ -599,7 +596,7 @@ static inline int restore_i387_fsave(struct _fpstate_ia32 __user *buf)
 {
        struct task_struct *tsk = current;
 
-       return __copy_from_user(&tsk->thread.xstate->fsave, buf,
+       return __copy_from_user(&tsk->thread.fpu.state->fsave, buf,
                                sizeof(struct i387_fsave_struct));
 }
 
@@ -610,10 +607,10 @@ static int restore_i387_fxsave(struct _fpstate_ia32 __user *buf,
        struct user_i387_ia32_struct env;
        int err;
 
-       err = __copy_from_user(&tsk->thread.xstate->fxsave, &buf->_fxsr_env[0],
+       err = __copy_from_user(&tsk->thread.fpu.state->fxsave, &buf->_fxsr_env[0],
                               size);
        /* mxcsr reserved bits must be masked to zero for security reasons */
-       tsk->thread.xstate->fxsave.mxcsr &= mxcsr_feature_mask;
+       tsk->thread.fpu.state->fxsave.mxcsr &= mxcsr_feature_mask;
        if (err || __copy_from_user(&env, buf, sizeof(env)))
                return 1;
        convert_to_fxsr(tsk, &env);
@@ -629,7 +626,7 @@ static int restore_i387_xsave(void __user *buf)
        struct i387_fxsave_struct __user *fx =
                (struct i387_fxsave_struct __user *) &fx_user->_fxsr_env[0];
        struct xsave_hdr_struct *xsave_hdr =
-                               &current->thread.xstate->xsave.xsave_hdr;
+                               &current->thread.fpu.state->xsave.xsave_hdr;
        u64 mask;
        int err;
 
index 23c1679..2dfd315 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/hpet.h>
 #include <asm/smp.h>
 
-DEFINE_SPINLOCK(i8253_lock);
+DEFINE_RAW_SPINLOCK(i8253_lock);
 EXPORT_SYMBOL(i8253_lock);
 
 /*
@@ -33,7 +33,7 @@ struct clock_event_device *global_clock_event;
 static void init_pit_timer(enum clock_event_mode mode,
                           struct clock_event_device *evt)
 {
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
 
        switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
@@ -62,7 +62,7 @@ static void init_pit_timer(enum clock_event_mode mode,
                /* Nothing to do here */
                break;
        }
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
 }
 
 /*
@@ -72,10 +72,10 @@ static void init_pit_timer(enum clock_event_mode mode,
  */
 static int pit_next_event(unsigned long delta, struct clock_event_device *evt)
 {
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
        outb_pit(delta & 0xff , PIT_CH0);       /* LSB */
        outb_pit(delta >> 8 , PIT_CH0);         /* MSB */
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
 
        return 0;
 }
@@ -130,7 +130,7 @@ static cycle_t pit_read(struct clocksource *cs)
        int count;
        u32 jifs;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
        /*
         * Although our caller may have the read side of xtime_lock,
         * this is now a seqlock, and we are cheating in this routine
@@ -176,7 +176,7 @@ static cycle_t pit_read(struct clocksource *cs)
        old_count = count;
        old_jifs = jifs;
 
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 
        count = (LATCH - 1) - count;
 
index 0ed2d30..990ae7c 100644 (file)
@@ -60,7 +60,7 @@ static irqreturn_t math_error_irq(int cpl, void *dev_id)
        outb(0, 0xF0);
        if (ignore_fpu_irq || !boot_cpu_data.hard_math)
                return IRQ_NONE;
-       math_error((void __user *)get_irq_regs()->ip);
+       math_error(get_irq_regs(), 0, 16);
        return IRQ_HANDLED;
 }
 
index 1658efd..345a4b1 100644 (file)
@@ -422,14 +422,22 @@ static void __kprobes set_current_kprobe(struct kprobe *p, struct pt_regs *regs,
 
 static void __kprobes clear_btf(void)
 {
-       if (test_thread_flag(TIF_DEBUGCTLMSR))
-               update_debugctlmsr(0);
+       if (test_thread_flag(TIF_BLOCKSTEP)) {
+               unsigned long debugctl = get_debugctlmsr();
+
+               debugctl &= ~DEBUGCTLMSR_BTF;
+               update_debugctlmsr(debugctl);
+       }
 }
 
 static void __kprobes restore_btf(void)
 {
-       if (test_thread_flag(TIF_DEBUGCTLMSR))
-               update_debugctlmsr(current->thread.debugctlmsr);
+       if (test_thread_flag(TIF_BLOCKSTEP)) {
+               unsigned long debugctl = get_debugctlmsr();
+
+               debugctl |= DEBUGCTLMSR_BTF;
+               update_debugctlmsr(debugctl);
+       }
 }
 
 void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
index cceb5bc..2cd8c54 100644 (file)
@@ -201,9 +201,9 @@ static int do_microcode_update(const void __user *buf, size_t size)
        return error;
 }
 
-static int microcode_open(struct inode *unused1, struct file *unused2)
+static int microcode_open(struct inode *inode, struct file *file)
 {
-       return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
+       return capable(CAP_SYS_RAWIO) ? nonseekable_open(inode, file) : -EPERM;
 }
 
 static ssize_t microcode_write(struct file *file, const char __user *buf,
index 85a343e..3561702 100644 (file)
@@ -343,10 +343,11 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
                                int (*get_ucode_data)(void *, const void *, size_t))
 {
        struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
-       u8 *ucode_ptr = data, *new_mc = NULL, *mc;
+       u8 *ucode_ptr = data, *new_mc = NULL, *mc = NULL;
        int new_rev = uci->cpu_sig.rev;
        unsigned int leftover = size;
        enum ucode_state state = UCODE_OK;
+       unsigned int curr_mc_size = 0;
 
        while (leftover) {
                struct microcode_header_intel mc_header;
@@ -361,9 +362,15 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
                        break;
                }
 
-               mc = vmalloc(mc_size);
-               if (!mc)
-                       break;
+               /* For performance reasons, reuse mc area when possible */
+               if (!mc || mc_size > curr_mc_size) {
+                       if (mc)
+                               vfree(mc);
+                       mc = vmalloc(mc_size);
+                       if (!mc)
+                               break;
+                       curr_mc_size = mc_size;
+               }
 
                if (get_ucode_data(mc, ucode_ptr, mc_size) ||
                    microcode_sanity_check(mc) < 0) {
@@ -376,13 +383,16 @@ static enum ucode_state generic_load_microcode(int cpu, void *data, size_t size,
                                vfree(new_mc);
                        new_rev = mc_header.rev;
                        new_mc  = mc;
-               } else
-                       vfree(mc);
+                       mc = NULL;      /* trigger new vmalloc */
+               }
 
                ucode_ptr += mc_size;
                leftover  -= mc_size;
        }
 
+       if (mc)
+               vfree(mc);
+
        if (leftover) {
                if (new_mc)
                        vfree(new_mc);
index e81030f..5ae5d24 100644 (file)
@@ -115,21 +115,6 @@ static void __init MP_bus_info(struct mpc_bus *m)
                printk(KERN_WARNING "Unknown bustype %s - ignoring\n", str);
 }
 
-static int bad_ioapic(unsigned long address)
-{
-       if (nr_ioapics >= MAX_IO_APICS) {
-               printk(KERN_ERR "ERROR: Max # of I/O APICs (%d) exceeded "
-                      "(found %d)\n", MAX_IO_APICS, nr_ioapics);
-               panic("Recompile kernel with bigger MAX_IO_APICS!\n");
-       }
-       if (!address) {
-               printk(KERN_ERR "WARNING: Bogus (zero) I/O APIC address"
-                      " found in table, skipping!\n");
-               return 1;
-       }
-       return 0;
-}
-
 static void __init MP_ioapic_info(struct mpc_ioapic *m)
 {
        if (!(m->flags & MPC_APIC_USABLE))
@@ -138,15 +123,7 @@ static void __init MP_ioapic_info(struct mpc_ioapic *m)
        printk(KERN_INFO "I/O APIC #%d Version %d at 0x%X.\n",
               m->apicid, m->apicver, m->apicaddr);
 
-       if (bad_ioapic(m->apicaddr))
-               return;
-
-       mp_ioapics[nr_ioapics].apicaddr = m->apicaddr;
-       mp_ioapics[nr_ioapics].apicid = m->apicid;
-       mp_ioapics[nr_ioapics].type = m->type;
-       mp_ioapics[nr_ioapics].apicver = m->apicver;
-       mp_ioapics[nr_ioapics].flags = m->flags;
-       nr_ioapics++;
+       mp_register_ioapic(m->apicid, m->apicaddr, gsi_end + 1);
 }
 
 static void print_MP_intsrc_info(struct mpc_intsrc *m)
index 0aad867..e796448 100644 (file)
@@ -237,4 +237,9 @@ void __init x86_mrst_early_setup(void)
        x86_init.pci.fixup_irqs = x86_init_noop;
 
        legacy_pic = &null_legacy_pic;
+
+       /* Avoid searching for BIOS MP tables */
+       x86_init.mpparse.find_smp_config = x86_init_noop;
+       x86_init.mpparse.get_smp_config = x86_init_uint_noop;
+
 }
index 0415c3e..e7e3521 100644 (file)
@@ -20,7 +20,6 @@
 #include <asm/idle.h>
 #include <asm/uaccess.h>
 #include <asm/i387.h>
-#include <asm/ds.h>
 #include <asm/debugreg.h>
 
 unsigned long idle_halt;
@@ -32,26 +31,22 @@ struct kmem_cache *task_xstate_cachep;
 
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 {
+       int ret;
+
        *dst = *src;
-       if (src->thread.xstate) {
-               dst->thread.xstate = kmem_cache_alloc(task_xstate_cachep,
-                                                     GFP_KERNEL);
-               if (!dst->thread.xstate)
-                       return -ENOMEM;
-               WARN_ON((unsigned long)dst->thread.xstate & 15);
-               memcpy(dst->thread.xstate, src->thread.xstate, xstate_size);
+       if (fpu_allocated(&src->thread.fpu)) {
+               memset(&dst->thread.fpu, 0, sizeof(dst->thread.fpu));
+               ret = fpu_alloc(&dst->thread.fpu);
+               if (ret)
+                       return ret;
+               fpu_copy(&dst->thread.fpu, &src->thread.fpu);
        }
        return 0;
 }
 
 void free_thread_xstate(struct task_struct *tsk)
 {
-       if (tsk->thread.xstate) {
-               kmem_cache_free(task_xstate_cachep, tsk->thread.xstate);
-               tsk->thread.xstate = NULL;
-       }
-
-       WARN(tsk->thread.ds_ctx, "leaking DS context\n");
+       fpu_free(&tsk->thread.fpu);
 }
 
 void free_thread_info(struct thread_info *ti)
@@ -198,11 +193,16 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
        prev = &prev_p->thread;
        next = &next_p->thread;
 
-       if (test_tsk_thread_flag(next_p, TIF_DS_AREA_MSR) ||
-           test_tsk_thread_flag(prev_p, TIF_DS_AREA_MSR))
-               ds_switch_to(prev_p, next_p);
-       else if (next->debugctlmsr != prev->debugctlmsr)
-               update_debugctlmsr(next->debugctlmsr);
+       if (test_tsk_thread_flag(prev_p, TIF_BLOCKSTEP) ^
+           test_tsk_thread_flag(next_p, TIF_BLOCKSTEP)) {
+               unsigned long debugctl = get_debugctlmsr();
+
+               debugctl &= ~DEBUGCTLMSR_BTF;
+               if (test_tsk_thread_flag(next_p, TIF_BLOCKSTEP))
+                       debugctl |= DEBUGCTLMSR_BTF;
+
+               update_debugctlmsr(debugctl);
+       }
 
        if (test_tsk_thread_flag(prev_p, TIF_NOTSC) ^
            test_tsk_thread_flag(next_p, TIF_NOTSC)) {
index f6c6266..8d12878 100644 (file)
@@ -55,7 +55,6 @@
 #include <asm/cpu.h>
 #include <asm/idle.h>
 #include <asm/syscalls.h>
-#include <asm/ds.h>
 #include <asm/debugreg.h>
 
 asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
@@ -238,13 +237,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
                kfree(p->thread.io_bitmap_ptr);
                p->thread.io_bitmap_max = 0;
        }
-
-       clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
-       p->thread.ds_ctx = NULL;
-
-       clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR);
-       p->thread.debugctlmsr = 0;
-
        return err;
 }
 
@@ -317,7 +309,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 
        /* we're going to use this soon, after a few expensive things */
        if (preload_fpu)
-               prefetch(next->xstate);
+               prefetch(next->fpu.state);
 
        /*
         * Reload esp0.
index 17cb329..3c2422a 100644 (file)
@@ -49,7 +49,6 @@
 #include <asm/ia32.h>
 #include <asm/idle.h>
 #include <asm/syscalls.h>
-#include <asm/ds.h>
 #include <asm/debugreg.h>
 
 asmlinkage extern void ret_from_fork(void);
@@ -313,13 +312,6 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
                if (err)
                        goto out;
        }
-
-       clear_tsk_thread_flag(p, TIF_DS_AREA_MSR);
-       p->thread.ds_ctx = NULL;
-
-       clear_tsk_thread_flag(p, TIF_DEBUGCTLMSR);
-       p->thread.debugctlmsr = 0;
-
        err = 0;
 out:
        if (err && p->thread.io_bitmap_ptr) {
@@ -396,7 +388,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
 
        /* we're going to use this soon, after a few expensive things */
        if (preload_fpu)
-               prefetch(next->xstate);
+               prefetch(next->fpu.state);
 
        /*
         * Reload esp0, LDT and the page table pointer:
index 2e9b550..70c4872 100644 (file)
@@ -2,9 +2,6 @@
 /*
  * Pentium III FXSR, SSE support
  *     Gareth Hughes <gareth@valinux.com>, May 2000
- *
- * BTS tracing
- *     Markus Metzger <markus.t.metzger@intel.com>, Dec 2007
  */
 
 #include <linux/kernel.h>
@@ -22,7 +19,6 @@
 #include <linux/audit.h>
 #include <linux/seccomp.h>
 #include <linux/signal.h>
-#include <linux/workqueue.h>
 #include <linux/perf_event.h>
 #include <linux/hw_breakpoint.h>
 
@@ -36,7 +32,6 @@
 #include <asm/desc.h>
 #include <asm/prctl.h>
 #include <asm/proto.h>
-#include <asm/ds.h>
 #include <asm/hw_breakpoint.h>
 
 #include "tls.h"
@@ -693,7 +688,7 @@ static int ptrace_set_breakpoint_addr(struct task_struct *tsk, int nr,
        struct perf_event_attr attr;
 
        if (!t->ptrace_bps[nr]) {
-               hw_breakpoint_init(&attr);
+               ptrace_breakpoint_init(&attr);
                /*
                 * Put stub len and type to register (reserve) an inactive but
                 * correct bp
@@ -789,342 +784,6 @@ static int ioperm_get(struct task_struct *target,
                                   0, IO_BITMAP_BYTES);
 }
 
-#ifdef CONFIG_X86_PTRACE_BTS
-/*
- * A branch trace store context.
- *
- * Contexts may only be installed by ptrace_bts_config() and only for
- * ptraced tasks.
- *
- * Contexts are destroyed when the tracee is detached from the tracer.
- * The actual destruction work requires interrupts enabled, so the
- * work is deferred and will be scheduled during __ptrace_unlink().
- *
- * Contexts hold an additional task_struct reference on the traced
- * task, as well as a reference on the tracer's mm.
- *
- * Ptrace already holds a task_struct for the duration of ptrace operations,
- * but since destruction is deferred, it may be executed after both
- * tracer and tracee exited.
- */
-struct bts_context {
-       /* The branch trace handle. */
-       struct bts_tracer       *tracer;
-
-       /* The buffer used to store the branch trace and its size. */
-       void                    *buffer;
-       unsigned int            size;
-
-       /* The mm that paid for the above buffer. */
-       struct mm_struct        *mm;
-
-       /* The task this context belongs to. */
-       struct task_struct      *task;
-
-       /* The signal to send on a bts buffer overflow. */
-       unsigned int            bts_ovfl_signal;
-
-       /* The work struct to destroy a context. */
-       struct work_struct      work;
-};
-
-static int alloc_bts_buffer(struct bts_context *context, unsigned int size)
-{
-       void *buffer = NULL;
-       int err = -ENOMEM;
-
-       err = account_locked_memory(current->mm, current->signal->rlim, size);
-       if (err < 0)
-               return err;
-
-       buffer = kzalloc(size, GFP_KERNEL);
-       if (!buffer)
-               goto out_refund;
-
-       context->buffer = buffer;
-       context->size = size;
-       context->mm = get_task_mm(current);
-
-       return 0;
-
- out_refund:
-       refund_locked_memory(current->mm, size);
-       return err;
-}
-
-static inline void free_bts_buffer(struct bts_context *context)
-{
-       if (!context->buffer)
-               return;
-
-       kfree(context->buffer);
-       context->buffer = NULL;
-
-       refund_locked_memory(context->mm, context->size);
-       context->size = 0;
-
-       mmput(context->mm);
-       context->mm = NULL;
-}
-
-static void free_bts_context_work(struct work_struct *w)
-{
-       struct bts_context *context;
-
-       context = container_of(w, struct bts_context, work);
-
-       ds_release_bts(context->tracer);
-       put_task_struct(context->task);
-       free_bts_buffer(context);
-       kfree(context);
-}
-
-static inline void free_bts_context(struct bts_context *context)
-{
-       INIT_WORK(&context->work, free_bts_context_work);
-       schedule_work(&context->work);
-}
-
-static inline struct bts_context *alloc_bts_context(struct task_struct *task)
-{
-       struct bts_context *context = kzalloc(sizeof(*context), GFP_KERNEL);
-       if (context) {
-               context->task = task;
-               task->bts = context;
-
-               get_task_struct(task);
-       }
-
-       return context;
-}
-
-static int ptrace_bts_read_record(struct task_struct *child, size_t index,
-                                 struct bts_struct __user *out)
-{
-       struct bts_context *context;
-       const struct bts_trace *trace;
-       struct bts_struct bts;
-       const unsigned char *at;
-       int error;
-
-       context = child->bts;
-       if (!context)
-               return -ESRCH;
-
-       trace = ds_read_bts(context->tracer);
-       if (!trace)
-               return -ESRCH;
-
-       at = trace->ds.top - ((index + 1) * trace->ds.size);
-       if ((void *)at < trace->ds.begin)
-               at += (trace->ds.n * trace->ds.size);
-
-       if (!trace->read)
-               return -EOPNOTSUPP;
-
-       error = trace->read(context->tracer, at, &bts);
-       if (error < 0)
-               return error;
-
-       if (copy_to_user(out, &bts, sizeof(bts)))
-               return -EFAULT;
-
-       return sizeof(bts);
-}
-
-static int ptrace_bts_drain(struct task_struct *child,
-                           long size,
-                           struct bts_struct __user *out)
-{
-       struct bts_context *context;
-       const struct bts_trace *trace;
-       const unsigned char *at;
-       int error, drained = 0;
-
-       context = child->bts;
-       if (!context)
-               return -ESRCH;
-
-       trace = ds_read_bts(context->tracer);
-       if (!trace)
-               return -ESRCH;
-
-       if (!trace->read)
-               return -EOPNOTSUPP;
-
-       if (size < (trace->ds.top - trace->ds.begin))
-               return -EIO;
-
-       for (at = trace->ds.begin; (void *)at < trace->ds.top;
-            out++, drained++, at += trace->ds.size) {
-               struct bts_struct bts;
-
-               error = trace->read(context->tracer, at, &bts);
-               if (error < 0)
-                       return error;
-
-               if (copy_to_user(out, &bts, sizeof(bts)))
-                       return -EFAULT;
-       }
-
-       memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
-
-       error = ds_reset_bts(context->tracer);
-       if (error < 0)
-               return error;
-
-       return drained;
-}
-
-static int ptrace_bts_config(struct task_struct *child,
-                            long cfg_size,
-                            const struct ptrace_bts_config __user *ucfg)
-{
-       struct bts_context *context;
-       struct ptrace_bts_config cfg;
-       unsigned int flags = 0;
-
-       if (cfg_size < sizeof(cfg))
-               return -EIO;
-
-       if (copy_from_user(&cfg, ucfg, sizeof(cfg)))
-               return -EFAULT;
-
-       context = child->bts;
-       if (!context)
-               context = alloc_bts_context(child);
-       if (!context)
-               return -ENOMEM;
-
-       if (cfg.flags & PTRACE_BTS_O_SIGNAL) {
-               if (!cfg.signal)
-                       return -EINVAL;
-
-               return -EOPNOTSUPP;
-               context->bts_ovfl_signal = cfg.signal;
-       }
-
-       ds_release_bts(context->tracer);
-       context->tracer = NULL;
-
-       if ((cfg.flags & PTRACE_BTS_O_ALLOC) && (cfg.size != context->size)) {
-               int err;
-
-               free_bts_buffer(context);
-               if (!cfg.size)
-                       return 0;
-
-               err = alloc_bts_buffer(context, cfg.size);
-               if (err < 0)
-                       return err;
-       }
-
-       if (cfg.flags & PTRACE_BTS_O_TRACE)
-               flags |= BTS_USER;
-
-       if (cfg.flags & PTRACE_BTS_O_SCHED)
-               flags |= BTS_TIMESTAMPS;
-
-       context->tracer =
-               ds_request_bts_task(child, context->buffer, context->size,
-                                   NULL, (size_t)-1, flags);
-       if (unlikely(IS_ERR(context->tracer))) {
-               int error = PTR_ERR(context->tracer);
-
-               free_bts_buffer(context);
-               context->tracer = NULL;
-               return error;
-       }
-
-       return sizeof(cfg);
-}
-
-static int ptrace_bts_status(struct task_struct *child,
-                            long cfg_size,
-                            struct ptrace_bts_config __user *ucfg)
-{
-       struct bts_context *context;
-       const struct bts_trace *trace;
-       struct ptrace_bts_config cfg;
-
-       context = child->bts;
-       if (!context)
-               return -ESRCH;
-
-       if (cfg_size < sizeof(cfg))
-               return -EIO;
-
-       trace = ds_read_bts(context->tracer);
-       if (!trace)
-               return -ESRCH;
-
-       memset(&cfg, 0, sizeof(cfg));
-       cfg.size        = trace->ds.end - trace->ds.begin;
-       cfg.signal      = context->bts_ovfl_signal;
-       cfg.bts_size    = sizeof(struct bts_struct);
-
-       if (cfg.signal)
-               cfg.flags |= PTRACE_BTS_O_SIGNAL;
-
-       if (trace->ds.flags & BTS_USER)
-               cfg.flags |= PTRACE_BTS_O_TRACE;
-
-       if (trace->ds.flags & BTS_TIMESTAMPS)
-               cfg.flags |= PTRACE_BTS_O_SCHED;
-
-       if (copy_to_user(ucfg, &cfg, sizeof(cfg)))
-               return -EFAULT;
-
-       return sizeof(cfg);
-}
-
-static int ptrace_bts_clear(struct task_struct *child)
-{
-       struct bts_context *context;
-       const struct bts_trace *trace;
-
-       context = child->bts;
-       if (!context)
-               return -ESRCH;
-
-       trace = ds_read_bts(context->tracer);
-       if (!trace)
-               return -ESRCH;
-
-       memset(trace->ds.begin, 0, trace->ds.n * trace->ds.size);
-
-       return ds_reset_bts(context->tracer);
-}
-
-static int ptrace_bts_size(struct task_struct *child)
-{
-       struct bts_context *context;
-       const struct bts_trace *trace;
-
-       context = child->bts;
-       if (!context)
-               return -ESRCH;
-
-       trace = ds_read_bts(context->tracer);
-       if (!trace)
-               return -ESRCH;
-
-       return (trace->ds.top - trace->ds.begin) / trace->ds.size;
-}
-
-/*
- * Called from __ptrace_unlink() after the child has been moved back
- * to its original parent.
- */
-void ptrace_bts_untrace(struct task_struct *child)
-{
-       if (unlikely(child->bts)) {
-               free_bts_context(child->bts);
-               child->bts = NULL;
-       }
-}
-#endif /* CONFIG_X86_PTRACE_BTS */
-
 /*
  * Called by kernel/ptrace.c when detaching..
  *
@@ -1252,39 +911,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
                break;
 #endif
 
-       /*
-        * These bits need more cooking - not enabled yet:
-        */
-#ifdef CONFIG_X86_PTRACE_BTS
-       case PTRACE_BTS_CONFIG:
-               ret = ptrace_bts_config
-                       (child, data, (struct ptrace_bts_config __user *)addr);
-               break;
-
-       case PTRACE_BTS_STATUS:
-               ret = ptrace_bts_status
-                       (child, data, (struct ptrace_bts_config __user *)addr);
-               break;
-
-       case PTRACE_BTS_SIZE:
-               ret = ptrace_bts_size(child);
-               break;
-
-       case PTRACE_BTS_GET:
-               ret = ptrace_bts_read_record
-                       (child, data, (struct bts_struct __user *) addr);
-               break;
-
-       case PTRACE_BTS_CLEAR:
-               ret = ptrace_bts_clear(child);
-               break;
-
-       case PTRACE_BTS_DRAIN:
-               ret = ptrace_bts_drain
-                       (child, data, (struct bts_struct __user *) addr);
-               break;
-#endif /* CONFIG_X86_PTRACE_BTS */
-
        default:
                ret = ptrace_request(child, request, addr, data);
                break;
@@ -1544,14 +1170,6 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
 
        case PTRACE_GET_THREAD_AREA:
        case PTRACE_SET_THREAD_AREA:
-#ifdef CONFIG_X86_PTRACE_BTS
-       case PTRACE_BTS_CONFIG:
-       case PTRACE_BTS_STATUS:
-       case PTRACE_BTS_SIZE:
-       case PTRACE_BTS_GET:
-       case PTRACE_BTS_CLEAR:
-       case PTRACE_BTS_DRAIN:
-#endif /* CONFIG_X86_PTRACE_BTS */
                return arch_ptrace(child, request, addr, data);
 
        default:
index 12e9fea..e72d3fc 100644 (file)
@@ -495,10 +495,18 @@ void force_hpet_resume(void)
 /*
  * HPET MSI on some boards (ATI SB700/SB800) has side effect on
  * floppy DMA. Disable HPET MSI on such platforms.
+ * See erratum #27 (Misinterpreted MSI Requests May Result in
+ * Corrupted LPC DMA Data) in AMD Publication #46837,
+ * "SB700 Family Product Errata", Rev. 1.0, March 2010.
+ *
+ * Also force the read back of the CMP register in hpet_next_event()
+ * to work around the problem that the CMP register write seems to be
+ * delayed. See hpet_next_event() for details.
  */
 static void force_disable_hpet_msi(struct pci_dev *unused)
 {
        hpet_msi_disable = 1;
+       hpet_readback_cmp = 1;
 }
 
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
index 34e0993..7ded578 100644 (file)
@@ -81,7 +81,6 @@ static int __init sfi_parse_cpus(struct sfi_table_header *table)
 #endif /* CONFIG_X86_LOCAL_APIC */
 
 #ifdef CONFIG_X86_IO_APIC
-static u32 gsi_base;
 
 static int __init sfi_parse_ioapic(struct sfi_table_header *table)
 {
@@ -94,8 +93,7 @@ static int __init sfi_parse_ioapic(struct sfi_table_header *table)
        pentry = (struct sfi_apic_table_entry *)sb->pentry;
 
        for (i = 0; i < num; i++) {
-               mp_register_ioapic(i, pentry->phys_addr, gsi_base);
-               gsi_base += io_apic_get_redir_entries(i);
+               mp_register_ioapic(i, pentry->phys_addr, gsi_end + 1);
                pentry++;
        }
 
index 3149032..58de45e 100644 (file)
@@ -157,22 +157,6 @@ static int enable_single_step(struct task_struct *child)
        return 1;
 }
 
-/*
- * Install this value in MSR_IA32_DEBUGCTLMSR whenever child is running.
- */
-static void write_debugctlmsr(struct task_struct *child, unsigned long val)
-{
-       if (child->thread.debugctlmsr == val)
-               return;
-
-       child->thread.debugctlmsr = val;
-
-       if (child != current)
-               return;
-
-       update_debugctlmsr(val);
-}
-
 /*
  * Enable single or block step.
  */
@@ -186,15 +170,17 @@ static void enable_step(struct task_struct *child, bool block)
         * that uses user-mode single stepping itself.
         */
        if (enable_single_step(child) && block) {
-               set_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
-               write_debugctlmsr(child,
-                                 child->thread.debugctlmsr | DEBUGCTLMSR_BTF);
-       } else {
-               write_debugctlmsr(child,
-                                 child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF);
-
-               if (!child->thread.debugctlmsr)
-                       clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+               unsigned long debugctl = get_debugctlmsr();
+
+               debugctl |= DEBUGCTLMSR_BTF;
+               update_debugctlmsr(debugctl);
+               set_tsk_thread_flag(child, TIF_BLOCKSTEP);
+       } else if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) {
+               unsigned long debugctl = get_debugctlmsr();
+
+               debugctl &= ~DEBUGCTLMSR_BTF;
+               update_debugctlmsr(debugctl);
+               clear_tsk_thread_flag(child, TIF_BLOCKSTEP);
        }
 }
 
@@ -213,11 +199,13 @@ void user_disable_single_step(struct task_struct *child)
        /*
         * Make sure block stepping (BTF) is disabled.
         */
-       write_debugctlmsr(child,
-                         child->thread.debugctlmsr & ~DEBUGCTLMSR_BTF);
+       if (test_tsk_thread_flag(child, TIF_BLOCKSTEP)) {
+               unsigned long debugctl = get_debugctlmsr();
 
-       if (!child->thread.debugctlmsr)
-               clear_tsk_thread_flag(child, TIF_DEBUGCTLMSR);
+               debugctl &= ~DEBUGCTLMSR_BTF;
+               update_debugctlmsr(debugctl);
+               clear_tsk_thread_flag(child, TIF_BLOCKSTEP);
+       }
 
        /* Always clear TIF_SINGLESTEP... */
        clear_tsk_thread_flag(child, TIF_SINGLESTEP);
index 86c9f91..cc2c604 100644 (file)
@@ -175,6 +175,9 @@ static void add_mac_region(phys_addr_t start, unsigned long size)
        struct tboot_mac_region *mr;
        phys_addr_t end = start + size;
 
+       if (tboot->num_mac_regions >= MAX_TB_MAC_REGIONS)
+               panic("tboot: Too many MAC regions\n");
+
        if (start && size) {
                mr = &tboot->mac_regions[tboot->num_mac_regions++];
                mr->start = round_down(start, PAGE_SIZE);
@@ -184,18 +187,17 @@ static void add_mac_region(phys_addr_t start, unsigned long size)
 
 static int tboot_setup_sleep(void)
 {
+       int i;
+
        tboot->num_mac_regions = 0;
 
-       /* S3 resume code */
-       add_mac_region(acpi_wakeup_address, WAKEUP_SIZE);
+       for (i = 0; i < e820.nr_map; i++) {
+               if ((e820.map[i].type != E820_RAM)
+                && (e820.map[i].type != E820_RESERVED_KERN))
+                       continue;
 
-#ifdef CONFIG_X86_TRAMPOLINE
-       /* AP trampoline code */
-       add_mac_region(virt_to_phys(trampoline_base), TRAMPOLINE_SIZE);
-#endif
-
-       /* kernel code + data + bss */
-       add_mac_region(virt_to_phys(_text), _end - _text);
+               add_mac_region(e820.map[i].addr, e820.map[i].size);
+       }
 
        tboot->acpi_sinfo.kernel_s3_resume_vector = acpi_wakeup_address;
 
index 17b03dd..7fea555 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     SGI UltraViolet TLB flush routines.
  *
- *     (c) 2008 Cliff Wickman <cpw@sgi.com>, SGI.
+ *     (c) 2008-2010 Cliff Wickman <cpw@sgi.com>, SGI.
  *
  *     This code is released under the GNU General Public License version 2 or
  *     later.
 #include <asm/idle.h>
 #include <asm/tsc.h>
 #include <asm/irq_vectors.h>
+#include <asm/timer.h>
 
-static struct bau_control      **uv_bau_table_bases __read_mostly;
-static int                     uv_bau_retry_limit __read_mostly;
+struct msg_desc {
+       struct bau_payload_queue_entry *msg;
+       int msg_slot;
+       int sw_ack_slot;
+       struct bau_payload_queue_entry *va_queue_first;
+       struct bau_payload_queue_entry *va_queue_last;
+};
 
-/* base pnode in this partition */
-static int                     uv_partition_base_pnode __read_mostly;
+#define UV_INTD_SOFT_ACK_TIMEOUT_PERIOD        0x000000000bUL
+
+static int uv_bau_max_concurrent __read_mostly;
+
+static int nobau;
+static int __init setup_nobau(char *arg)
+{
+       nobau = 1;
+       return 0;
+}
+early_param("nobau", setup_nobau);
 
-static unsigned long           uv_mmask __read_mostly;
+/* base pnode in this partition */
+static int uv_partition_base_pnode __read_mostly;
+/* position of pnode (which is nasid>>1): */
+static int uv_nshift __read_mostly;
+static unsigned long uv_mmask __read_mostly;
 
 static DEFINE_PER_CPU(struct ptc_stats, ptcstats);
 static DEFINE_PER_CPU(struct bau_control, bau_control);
+static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
+
+struct reset_args {
+       int sender;
+};
 
 /*
- * Determine the first node on a blade.
+ * Determine the first node on a uvhub. 'Nodes' are used for kernel
+ * memory allocation.
  */
-static int __init blade_to_first_node(int blade)
+static int __init uvhub_to_first_node(int uvhub)
 {
        int node, b;
 
        for_each_online_node(node) {
                b = uv_node_to_blade_id(node);
-               if (blade == b)
+               if (uvhub == b)
                        return node;
        }
-       return -1; /* shouldn't happen */
+       return -1;
 }
 
 /*
- * Determine the apicid of the first cpu on a blade.
+ * Determine the apicid of the first cpu on a uvhub.
  */
-static int __init blade_to_first_apicid(int blade)
+static int __init uvhub_to_first_apicid(int uvhub)
 {
        int cpu;
 
        for_each_present_cpu(cpu)
-               if (blade == uv_cpu_to_blade_id(cpu))
+               if (uvhub == uv_cpu_to_blade_id(cpu))
                        return per_cpu(x86_cpu_to_apicid, cpu);
        return -1;
 }
@@ -68,195 +93,459 @@ static int __init blade_to_first_apicid(int blade)
  * clear of the Timeout bit (as well) will free the resource. No reply will
  * be sent (the hardware will only do one reply per message).
  */
-static void uv_reply_to_message(int resource,
-                               struct bau_payload_queue_entry *msg,
-                               struct bau_msg_status *msp)
+static inline void uv_reply_to_message(struct msg_desc *mdp,
+                                      struct bau_control *bcp)
 {
        unsigned long dw;
+       struct bau_payload_queue_entry *msg;
 
-       dw = (1 << (resource + UV_SW_ACK_NPENDING)) | (1 << resource);
+       msg = mdp->msg;
+       if (!msg->canceled) {
+               dw = (msg->sw_ack_vector << UV_SW_ACK_NPENDING) |
+                                               msg->sw_ack_vector;
+               uv_write_local_mmr(
+                               UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
+       }
        msg->replied_to = 1;
        msg->sw_ack_vector = 0;
-       if (msp)
-               msp->seen_by.bits = 0;
-       uv_write_local_mmr(UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS, dw);
 }
 
 /*
- * Do all the things a cpu should do for a TLB shootdown message.
- * Other cpu's may come here at the same time for this message.
+ * Process the receipt of a RETRY message
  */
-static void uv_bau_process_message(struct bau_payload_queue_entry *msg,
-                                  int msg_slot, int sw_ack_slot)
+static inline void uv_bau_process_retry_msg(struct msg_desc *mdp,
+                                           struct bau_control *bcp)
 {
-       unsigned long this_cpu_mask;
-       struct bau_msg_status *msp;
-       int cpu;
+       int i;
+       int cancel_count = 0;
+       int slot2;
+       unsigned long msg_res;
+       unsigned long mmr = 0;
+       struct bau_payload_queue_entry *msg;
+       struct bau_payload_queue_entry *msg2;
+       struct ptc_stats *stat;
 
-       msp = __get_cpu_var(bau_control).msg_statuses + msg_slot;
-       cpu = uv_blade_processor_id();
-       msg->number_of_cpus =
-               uv_blade_nr_online_cpus(uv_node_to_blade_id(numa_node_id()));
-       this_cpu_mask = 1UL << cpu;
-       if (msp->seen_by.bits & this_cpu_mask)
-               return;
-       atomic_or_long(&msp->seen_by.bits, this_cpu_mask);
+       msg = mdp->msg;
+       stat = &per_cpu(ptcstats, bcp->cpu);
+       stat->d_retries++;
+       /*
+        * cancel any message from msg+1 to the retry itself
+        */
+       for (msg2 = msg+1, i = 0; i < DEST_Q_SIZE; msg2++, i++) {
+               if (msg2 > mdp->va_queue_last)
+                       msg2 = mdp->va_queue_first;
+               if (msg2 == msg)
+                       break;
+
+               /* same conditions for cancellation as uv_do_reset */
+               if ((msg2->replied_to == 0) && (msg2->canceled == 0) &&
+                   (msg2->sw_ack_vector) && ((msg2->sw_ack_vector &
+                       msg->sw_ack_vector) == 0) &&
+                   (msg2->sending_cpu == msg->sending_cpu) &&
+                   (msg2->msg_type != MSG_NOOP)) {
+                       slot2 = msg2 - mdp->va_queue_first;
+                       mmr = uv_read_local_mmr
+                               (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
+                       msg_res = ((msg2->sw_ack_vector << 8) |
+                                  msg2->sw_ack_vector);
+                       /*
+                        * This is a message retry; clear the resources held
+                        * by the previous message only if they timed out.
+                        * If it has not timed out we have an unexpected
+                        * situation to report.
+                        */
+                       if (mmr & (msg_res << 8)) {
+                               /*
+                                * is the resource timed out?
+                                * make everyone ignore the cancelled message.
+                                */
+                               msg2->canceled = 1;
+                               stat->d_canceled++;
+                               cancel_count++;
+                               uv_write_local_mmr(
+                                   UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
+                                       (msg_res << 8) | msg_res);
+                       } else
+                               printk(KERN_INFO "note bau retry: no effect\n");
+               }
+       }
+       if (!cancel_count)
+               stat->d_nocanceled++;
+}
 
-       if (msg->replied_to == 1)
-               return;
+/*
+ * Do all the things a cpu should do for a TLB shootdown message.
+ * Other cpu's may come here at the same time for this message.
+ */
+static void uv_bau_process_message(struct msg_desc *mdp,
+                                  struct bau_control *bcp)
+{
+       int msg_ack_count;
+       short socket_ack_count = 0;
+       struct ptc_stats *stat;
+       struct bau_payload_queue_entry *msg;
+       struct bau_control *smaster = bcp->socket_master;
 
+       /*
+        * This must be a normal message, or retry of a normal message
+        */
+       msg = mdp->msg;
+       stat = &per_cpu(ptcstats, bcp->cpu);
        if (msg->address == TLB_FLUSH_ALL) {
                local_flush_tlb();
-               __get_cpu_var(ptcstats).alltlb++;
+               stat->d_alltlb++;
        } else {
                __flush_tlb_one(msg->address);
-               __get_cpu_var(ptcstats).onetlb++;
+               stat->d_onetlb++;
        }
+       stat->d_requestee++;
+
+       /*
+        * One cpu on each uvhub has the additional job on a RETRY
+        * of releasing the resource held by the message that is
+        * being retried.  That message is identified by sending
+        * cpu number.
+        */
+       if (msg->msg_type == MSG_RETRY && bcp == bcp->uvhub_master)
+               uv_bau_process_retry_msg(mdp, bcp);
 
-       __get_cpu_var(ptcstats).requestee++;
+       /*
+        * This is a sw_ack message, so we have to reply to it.
+        * Count each responding cpu on the socket. This avoids
+        * pinging the count's cache line back and forth between
+        * the sockets.
+        */
+       socket_ack_count = atomic_add_short_return(1, (struct atomic_short *)
+                       &smaster->socket_acknowledge_count[mdp->msg_slot]);
+       if (socket_ack_count == bcp->cpus_in_socket) {
+               /*
+                * Both sockets dump their completed count total into
+                * the message's count.
+                */
+               smaster->socket_acknowledge_count[mdp->msg_slot] = 0;
+               msg_ack_count = atomic_add_short_return(socket_ack_count,
+                               (struct atomic_short *)&msg->acknowledge_count);
+
+               if (msg_ack_count == bcp->cpus_in_uvhub) {
+                       /*
+                        * All cpus in uvhub saw it; reply
+                        */
+                       uv_reply_to_message(mdp, bcp);
+               }
+       }
 
-       atomic_inc_short(&msg->acknowledge_count);
-       if (msg->number_of_cpus == msg->acknowledge_count)
-               uv_reply_to_message(sw_ack_slot, msg, msp);
+       return;
 }
 
 /*
- * Examine the payload queue on one distribution node to see
- * which messages have not been seen, and which cpu(s) have not seen them.
+ * Determine the first cpu on a uvhub.
+ */
+static int uvhub_to_first_cpu(int uvhub)
+{
+       int cpu;
+       for_each_present_cpu(cpu)
+               if (uvhub == uv_cpu_to_blade_id(cpu))
+                       return cpu;
+       return -1;
+}
+
+/*
+ * Last resort when we get a large number of destination timeouts is
+ * to clear resources held by a given cpu.
+ * Do this with IPI so that all messages in the BAU message queue
+ * can be identified by their nonzero sw_ack_vector field.
  *
- * Returns the number of cpu's that have not responded.
+ * This is entered for a single cpu on the uvhub.
+ * The sender want's this uvhub to free a specific message's
+ * sw_ack resources.
  */
-static int uv_examine_destination(struct bau_control *bau_tablesp, int sender)
+static void
+uv_do_reset(void *ptr)
 {
-       struct bau_payload_queue_entry *msg;
-       struct bau_msg_status *msp;
-       int count = 0;
        int i;
-       int j;
+       int slot;
+       int count = 0;
+       unsigned long mmr;
+       unsigned long msg_res;
+       struct bau_control *bcp;
+       struct reset_args *rap;
+       struct bau_payload_queue_entry *msg;
+       struct ptc_stats *stat;
 
-       for (msg = bau_tablesp->va_queue_first, i = 0; i < DEST_Q_SIZE;
-            msg++, i++) {
-               if ((msg->sending_cpu == sender) && (!msg->replied_to)) {
-                       msp = bau_tablesp->msg_statuses + i;
-                       printk(KERN_DEBUG
-                              "blade %d: address:%#lx %d of %d, not cpu(s): ",
-                              i, msg->address, msg->acknowledge_count,
-                              msg->number_of_cpus);
-                       for (j = 0; j < msg->number_of_cpus; j++) {
-                               if (!((1L << j) & msp->seen_by.bits)) {
-                                       count++;
-                                       printk("%d ", j);
-                               }
+       bcp = &per_cpu(bau_control, smp_processor_id());
+       rap = (struct reset_args *)ptr;
+       stat = &per_cpu(ptcstats, bcp->cpu);
+       stat->d_resets++;
+
+       /*
+        * We're looking for the given sender, and
+        * will free its sw_ack resource.
+        * If all cpu's finally responded after the timeout, its
+        * message 'replied_to' was set.
+        */
+       for (msg = bcp->va_queue_first, i = 0; i < DEST_Q_SIZE; msg++, i++) {
+               /* uv_do_reset: same conditions for cancellation as
+                  uv_bau_process_retry_msg() */
+               if ((msg->replied_to == 0) &&
+                   (msg->canceled == 0) &&
+                   (msg->sending_cpu == rap->sender) &&
+                   (msg->sw_ack_vector) &&
+                   (msg->msg_type != MSG_NOOP)) {
+                       /*
+                        * make everyone else ignore this message
+                        */
+                       msg->canceled = 1;
+                       slot = msg - bcp->va_queue_first;
+                       count++;
+                       /*
+                        * only reset the resource if it is still pending
+                        */
+                       mmr = uv_read_local_mmr
+                                       (UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE);
+                       msg_res = ((msg->sw_ack_vector << 8) |
+                                                  msg->sw_ack_vector);
+                       if (mmr & msg_res) {
+                               stat->d_rcanceled++;
+                               uv_write_local_mmr(
+                                   UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE_ALIAS,
+                                                       msg_res);
                        }
-                       printk("\n");
                }
        }
-       return count;
+       return;
 }
 
 /*
- * Examine the payload queue on all the distribution nodes to see
- * which messages have not been seen, and which cpu(s) have not seen them.
- *
- * Returns the number of cpu's that have not responded.
+ * Use IPI to get all target uvhubs to release resources held by
+ * a given sending cpu number.
  */
-static int uv_examine_destinations(struct bau_target_nodemask *distribution)
+static void uv_reset_with_ipi(struct bau_target_uvhubmask *distribution,
+                             int sender)
 {
-       int sender;
-       int i;
-       int count = 0;
+       int uvhub;
+       int cpu;
+       cpumask_t mask;
+       struct reset_args reset_args;
+
+       reset_args.sender = sender;
 
-       sender = smp_processor_id();
-       for (i = 0; i < sizeof(struct bau_target_nodemask) * BITSPERBYTE; i++) {
-               if (!bau_node_isset(i, distribution))
+       cpus_clear(mask);
+       /* find a single cpu for each uvhub in this distribution mask */
+       for (uvhub = 0;
+                   uvhub < sizeof(struct bau_target_uvhubmask) * BITSPERBYTE;
+                   uvhub++) {
+               if (!bau_uvhub_isset(uvhub, distribution))
                        continue;
-               count += uv_examine_destination(uv_bau_table_bases[i], sender);
+               /* find a cpu for this uvhub */
+               cpu = uvhub_to_first_cpu(uvhub);
+               cpu_set(cpu, mask);
        }
-       return count;
+       /* IPI all cpus; Preemption is already disabled */
+       smp_call_function_many(&mask, uv_do_reset, (void *)&reset_args, 1);
+       return;
+}
+
+static inline unsigned long
+cycles_2_us(unsigned long long cyc)
+{
+       unsigned long long ns;
+       unsigned long us;
+       ns =  (cyc * per_cpu(cyc2ns, smp_processor_id()))
+                                               >> CYC2NS_SCALE_FACTOR;
+       us = ns / 1000;
+       return us;
 }
 
 /*
- * wait for completion of a broadcast message
- *
- * return COMPLETE, RETRY or GIVEUP
+ * wait for all cpus on this hub to finish their sends and go quiet
+ * leaves uvhub_quiesce set so that no new broadcasts are started by
+ * bau_flush_send_and_wait()
+ */
+static inline void
+quiesce_local_uvhub(struct bau_control *hmaster)
+{
+       atomic_add_short_return(1, (struct atomic_short *)
+                &hmaster->uvhub_quiesce);
+}
+
+/*
+ * mark this quiet-requestor as done
+ */
+static inline void
+end_uvhub_quiesce(struct bau_control *hmaster)
+{
+       atomic_add_short_return(-1, (struct atomic_short *)
+               &hmaster->uvhub_quiesce);
+}
+
+/*
+ * Wait for completion of a broadcast software ack message
+ * return COMPLETE, RETRY(PLUGGED or TIMEOUT) or GIVEUP
  */
 static int uv_wait_completion(struct bau_desc *bau_desc,
-                             unsigned long mmr_offset, int right_shift)
+       unsigned long mmr_offset, int right_shift, int this_cpu,
+       struct bau_control *bcp, struct bau_control *smaster, long try)
 {
-       int exams = 0;
-       long destination_timeouts = 0;
-       long source_timeouts = 0;
+       int relaxes = 0;
        unsigned long descriptor_status;
+       unsigned long mmr;
+       unsigned long mask;
+       cycles_t ttime;
+       cycles_t timeout_time;
+       struct ptc_stats *stat = &per_cpu(ptcstats, this_cpu);
+       struct bau_control *hmaster;
+
+       hmaster = bcp->uvhub_master;
+       timeout_time = get_cycles() + bcp->timeout_interval;
 
+       /* spin on the status MMR, waiting for it to go idle */
        while ((descriptor_status = (((unsigned long)
                uv_read_local_mmr(mmr_offset) >>
                        right_shift) & UV_ACT_STATUS_MASK)) !=
                        DESC_STATUS_IDLE) {
-               if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
-                       source_timeouts++;
-                       if (source_timeouts > SOURCE_TIMEOUT_LIMIT)
-                               source_timeouts = 0;
-                       __get_cpu_var(ptcstats).s_retry++;
-                       return FLUSH_RETRY;
-               }
                /*
-                * spin here looking for progress at the destinations
+                * Our software ack messages may be blocked because there are
+                * no swack resources available.  As long as none of them
+                * has timed out hardware will NACK our message and its
+                * state will stay IDLE.
                 */
-               if (descriptor_status == DESC_STATUS_DESTINATION_TIMEOUT) {
-                       destination_timeouts++;
-                       if (destination_timeouts > DESTINATION_TIMEOUT_LIMIT) {
-                               /*
-                                * returns number of cpus not responding
-                                */
-                               if (uv_examine_destinations
-                                   (&bau_desc->distribution) == 0) {
-                                       __get_cpu_var(ptcstats).d_retry++;
-                                       return FLUSH_RETRY;
-                               }
-                               exams++;
-                               if (exams >= uv_bau_retry_limit) {
-                                       printk(KERN_DEBUG
-                                              "uv_flush_tlb_others");
-                                       printk("giving up on cpu %d\n",
-                                              smp_processor_id());
+               if (descriptor_status == DESC_STATUS_SOURCE_TIMEOUT) {
+                       stat->s_stimeout++;
+                       return FLUSH_GIVEUP;
+               } else if (descriptor_status ==
+                                       DESC_STATUS_DESTINATION_TIMEOUT) {
+                       stat->s_dtimeout++;
+                       ttime = get_cycles();
+
+                       /*
+                        * Our retries may be blocked by all destination
+                        * swack resources being consumed, and a timeout
+                        * pending.  In that case hardware returns the
+                        * ERROR that looks like a destination timeout.
+                        */
+                       if (cycles_2_us(ttime - bcp->send_message) < BIOS_TO) {
+                               bcp->conseccompletes = 0;
+                               return FLUSH_RETRY_PLUGGED;
+                       }
+
+                       bcp->conseccompletes = 0;
+                       return FLUSH_RETRY_TIMEOUT;
+               } else {
+                       /*
+                        * descriptor_status is still BUSY
+                        */
+                       cpu_relax();
+                       relaxes++;
+                       if (relaxes >= 10000) {
+                               relaxes = 0;
+                               if (get_cycles() > timeout_time) {
+                                       quiesce_local_uvhub(hmaster);
+
+                                       /* single-thread the register change */
+                                       spin_lock(&hmaster->masks_lock);
+                                       mmr = uv_read_local_mmr(mmr_offset);
+                                       mask = 0UL;
+                                       mask |= (3UL < right_shift);
+                                       mask = ~mask;
+                                       mmr &= mask;
+                                       uv_write_local_mmr(mmr_offset, mmr);
+                                       spin_unlock(&hmaster->masks_lock);
+                                       end_uvhub_quiesce(hmaster);
+                                       stat->s_busy++;
                                        return FLUSH_GIVEUP;
                                }
-                               /*
-                                * delays can hang the simulator
-                                  udelay(1000);
-                                */
-                               destination_timeouts = 0;
                        }
                }
-               cpu_relax();
        }
+       bcp->conseccompletes++;
        return FLUSH_COMPLETE;
 }
 
+static inline cycles_t
+sec_2_cycles(unsigned long sec)
+{
+       unsigned long ns;
+       cycles_t cyc;
+
+       ns = sec * 1000000000;
+       cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
+       return cyc;
+}
+
+/*
+ * conditionally add 1 to *v, unless *v is >= u
+ * return 0 if we cannot add 1 to *v because it is >= u
+ * return 1 if we can add 1 to *v because it is < u
+ * the add is atomic
+ *
+ * This is close to atomic_add_unless(), but this allows the 'u' value
+ * to be lowered below the current 'v'.  atomic_add_unless can only stop
+ * on equal.
+ */
+static inline int atomic_inc_unless_ge(spinlock_t *lock, atomic_t *v, int u)
+{
+       spin_lock(lock);
+       if (atomic_read(v) >= u) {
+               spin_unlock(lock);
+               return 0;
+       }
+       atomic_inc(v);
+       spin_unlock(lock);
+       return 1;
+}
+
 /**
  * uv_flush_send_and_wait
  *
- * Send a broadcast and wait for a broadcast message to complete.
+ * Send a broadcast and wait for it to complete.
  *
- * The flush_mask contains the cpus the broadcast was sent to.
+ * The flush_mask contains the cpus the broadcast is to be sent to, plus
+ * cpus that are on the local uvhub.
  *
- * Returns NULL if all remote flushing was done. The mask is zeroed.
+ * Returns NULL if all flushing represented in the mask was done. The mask
+ * is zeroed.
  * Returns @flush_mask if some remote flushing remains to be done. The
- * mask will have some bits still set.
+ * mask will have some bits still set, representing any cpus on the local
+ * uvhub (not current cpu) and any on remote uvhubs if the broadcast failed.
  */
-const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode,
-                                            struct bau_desc *bau_desc,
-                                            struct cpumask *flush_mask)
+const struct cpumask *uv_flush_send_and_wait(struct bau_desc *bau_desc,
+                                            struct cpumask *flush_mask,
+                                            struct bau_control *bcp)
 {
-       int completion_status = 0;
        int right_shift;
-       int tries = 0;
-       int pnode;
+       int uvhub;
        int bit;
+       int completion_status = 0;
+       int seq_number = 0;
+       long try = 0;
+       int cpu = bcp->uvhub_cpu;
+       int this_cpu = bcp->cpu;
+       int this_uvhub = bcp->uvhub;
        unsigned long mmr_offset;
        unsigned long index;
        cycles_t time1;
        cycles_t time2;
+       struct ptc_stats *stat = &per_cpu(ptcstats, bcp->cpu);
+       struct bau_control *smaster = bcp->socket_master;
+       struct bau_control *hmaster = bcp->uvhub_master;
+
+       /*
+        * Spin here while there are hmaster->max_concurrent or more active
+        * descriptors. This is the per-uvhub 'throttle'.
+        */
+       if (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
+                       &hmaster->active_descriptor_count,
+                       hmaster->max_concurrent)) {
+               stat->s_throttles++;
+               do {
+                       cpu_relax();
+               } while (!atomic_inc_unless_ge(&hmaster->uvhub_lock,
+                       &hmaster->active_descriptor_count,
+                       hmaster->max_concurrent));
+       }
+
+       while (hmaster->uvhub_quiesce)
+               cpu_relax();
 
        if (cpu < UV_CPUS_PER_ACT_STATUS) {
                mmr_offset = UVH_LB_BAU_SB_ACTIVATION_STATUS_0;
@@ -268,24 +557,108 @@ const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode,
        }
        time1 = get_cycles();
        do {
-               tries++;
+               /*
+                * Every message from any given cpu gets a unique message
+                * sequence number. But retries use that same number.
+                * Our message may have timed out at the destination because
+                * all sw-ack resources are in use and there is a timeout
+                * pending there.  In that case, our last send never got
+                * placed into the queue and we need to persist until it
+                * does.
+                *
+                * Make any retry a type MSG_RETRY so that the destination will
+                * free any resource held by a previous message from this cpu.
+                */
+               if (try == 0) {
+                       /* use message type set by the caller the first time */
+                       seq_number = bcp->message_number++;
+               } else {
+                       /* use RETRY type on all the rest; same sequence */
+                       bau_desc->header.msg_type = MSG_RETRY;
+                       stat->s_retry_messages++;
+               }
+               bau_desc->header.sequence = seq_number;
                index = (1UL << UVH_LB_BAU_SB_ACTIVATION_CONTROL_PUSH_SHFT) |
-                       cpu;
+                       bcp->uvhub_cpu;
+               bcp->send_message = get_cycles();
+
                uv_write_local_mmr(UVH_LB_BAU_SB_ACTIVATION_CONTROL, index);
+
+               try++;
                completion_status = uv_wait_completion(bau_desc, mmr_offset,
-                                       right_shift);
-       } while (completion_status == FLUSH_RETRY);
+                       right_shift, this_cpu, bcp, smaster, try);
+
+               if (completion_status == FLUSH_RETRY_PLUGGED) {
+                       /*
+                        * Our retries may be blocked by all destination swack
+                        * resources being consumed, and a timeout pending. In
+                        * that case hardware immediately returns the ERROR
+                        * that looks like a destination timeout.
+                        */
+                       udelay(TIMEOUT_DELAY);
+                       bcp->plugged_tries++;
+                       if (bcp->plugged_tries >= PLUGSB4RESET) {
+                               bcp->plugged_tries = 0;
+                               quiesce_local_uvhub(hmaster);
+                               spin_lock(&hmaster->queue_lock);
+                               uv_reset_with_ipi(&bau_desc->distribution,
+                                                       this_cpu);
+                               spin_unlock(&hmaster->queue_lock);
+                               end_uvhub_quiesce(hmaster);
+                               bcp->ipi_attempts++;
+                               stat->s_resets_plug++;
+                       }
+               } else if (completion_status == FLUSH_RETRY_TIMEOUT) {
+                       hmaster->max_concurrent = 1;
+                       bcp->timeout_tries++;
+                       udelay(TIMEOUT_DELAY);
+                       if (bcp->timeout_tries >= TIMEOUTSB4RESET) {
+                               bcp->timeout_tries = 0;
+                               quiesce_local_uvhub(hmaster);
+                               spin_lock(&hmaster->queue_lock);
+                               uv_reset_with_ipi(&bau_desc->distribution,
+                                                               this_cpu);
+                               spin_unlock(&hmaster->queue_lock);
+                               end_uvhub_quiesce(hmaster);
+                               bcp->ipi_attempts++;
+                               stat->s_resets_timeout++;
+                       }
+               }
+               if (bcp->ipi_attempts >= 3) {
+                       bcp->ipi_attempts = 0;
+                       completion_status = FLUSH_GIVEUP;
+                       break;
+               }
+               cpu_relax();
+       } while ((completion_status == FLUSH_RETRY_PLUGGED) ||
+                (completion_status == FLUSH_RETRY_TIMEOUT));
        time2 = get_cycles();
-       __get_cpu_var(ptcstats).sflush += (time2 - time1);
-       if (tries > 1)
-               __get_cpu_var(ptcstats).retriesok++;
 
-       if (completion_status == FLUSH_GIVEUP) {
+       if ((completion_status == FLUSH_COMPLETE) && (bcp->conseccompletes > 5)
+           && (hmaster->max_concurrent < hmaster->max_concurrent_constant))
+                       hmaster->max_concurrent++;
+
+       /*
+        * hold any cpu not timing out here; no other cpu currently held by
+        * the 'throttle' should enter the activation code
+        */
+       while (hmaster->uvhub_quiesce)
+               cpu_relax();
+       atomic_dec(&hmaster->active_descriptor_count);
+
+       /* guard against cycles wrap */
+       if (time2 > time1)
+               stat->s_time += (time2 - time1);
+       else
+               stat->s_requestor--; /* don't count this one */
+       if (completion_status == FLUSH_COMPLETE && try > 1)
+               stat->s_retriesok++;
+       else if (completion_status == FLUSH_GIVEUP) {
                /*
                 * Cause the caller to do an IPI-style TLB shootdown on
-                * the cpu's, all of which are still in the mask.
+                * the target cpu's, all of which are still in the mask.
                 */
-               __get_cpu_var(ptcstats).ptc_i++;
+               stat->s_giveup++;
                return flush_mask;
        }
 
@@ -294,18 +667,17 @@ const struct cpumask *uv_flush_send_and_wait(int cpu, int this_pnode,
         * use the IPI method of shootdown on them.
         */
        for_each_cpu(bit, flush_mask) {
-               pnode = uv_cpu_to_pnode(bit);
-               if (pnode == this_pnode)
+               uvhub = uv_cpu_to_blade_id(bit);
+               if (uvhub == this_uvhub)
                        continue;
                cpumask_clear_cpu(bit, flush_mask);
        }
        if (!cpumask_empty(flush_mask))
                return flush_mask;
+
        return NULL;
 }
 
-static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
-
 /**
  * uv_flush_tlb_others - globally purge translation cache of a virtual
  * address or all TLB's
@@ -322,8 +694,8 @@ static DEFINE_PER_CPU(cpumask_var_t, uv_flush_tlb_mask);
  * The caller has derived the cpumask from the mm_struct.  This function
  * is called only if there are bits set in the mask. (e.g. flush_tlb_page())
  *
- * The cpumask is converted into a nodemask of the nodes containing
- * the cpus.
+ * The cpumask is converted into a uvhubmask of the uvhubs containing
+ * those cpus.
  *
  * Note that this function should be called with preemption disabled.
  *
@@ -335,52 +707,82 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
                                          struct mm_struct *mm,
                                          unsigned long va, unsigned int cpu)
 {
-       struct cpumask *flush_mask = __get_cpu_var(uv_flush_tlb_mask);
-       int i;
-       int bit;
-       int pnode;
-       int uv_cpu;
-       int this_pnode;
+       int remotes;
+       int tcpu;
+       int uvhub;
        int locals = 0;
        struct bau_desc *bau_desc;
+       struct cpumask *flush_mask;
+       struct ptc_stats *stat;
+       struct bau_control *bcp;
 
-       cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
+       if (nobau)
+               return cpumask;
 
-       uv_cpu = uv_blade_processor_id();
-       this_pnode = uv_hub_info->pnode;
-       bau_desc = __get_cpu_var(bau_control).descriptor_base;
-       bau_desc += UV_ITEMS_PER_DESCRIPTOR * uv_cpu;
+       bcp = &per_cpu(bau_control, cpu);
+       /*
+        * Each sending cpu has a per-cpu mask which it fills from the caller's
+        * cpu mask.  Only remote cpus are converted to uvhubs and copied.
+        */
+       flush_mask = (struct cpumask *)per_cpu(uv_flush_tlb_mask, cpu);
+       /*
+        * copy cpumask to flush_mask, removing current cpu
+        * (current cpu should already have been flushed by the caller and
+        *  should never be returned if we return flush_mask)
+        */
+       cpumask_andnot(flush_mask, cpumask, cpumask_of(cpu));
+       if (cpu_isset(cpu, *cpumask))
+               locals++;  /* current cpu was targeted */
 
-       bau_nodes_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
+       bau_desc = bcp->descriptor_base;
+       bau_desc += UV_ITEMS_PER_DESCRIPTOR * bcp->uvhub_cpu;
 
-       i = 0;
-       for_each_cpu(bit, flush_mask) {
-               pnode = uv_cpu_to_pnode(bit);
-               BUG_ON(pnode > (UV_DISTRIBUTION_SIZE - 1));
-               if (pnode == this_pnode) {
+       bau_uvhubs_clear(&bau_desc->distribution, UV_DISTRIBUTION_SIZE);
+       remotes = 0;
+       for_each_cpu(tcpu, flush_mask) {
+               uvhub = uv_cpu_to_blade_id(tcpu);
+               if (uvhub == bcp->uvhub) {
                        locals++;
                        continue;
                }
-               bau_node_set(pnode - uv_partition_base_pnode,
-                               &bau_desc->distribution);
-               i++;
+               bau_uvhub_set(uvhub, &bau_desc->distribution);
+               remotes++;
        }
-       if (i == 0) {
+       if (remotes == 0) {
                /*
-                * no off_node flushing; return status for local node
+                * No off_hub flushing; return status for local hub.
+                * Return the caller's mask if all were local (the current
+                * cpu may be in that mask).
                 */
                if (locals)
-                       return flush_mask;
+                       return cpumask;
                else
                        return NULL;
        }
-       __get_cpu_var(ptcstats).requestor++;
-       __get_cpu_var(ptcstats).ntargeted += i;
+       stat = &per_cpu(ptcstats, cpu);
+       stat->s_requestor++;
+       stat->s_ntargcpu += remotes;
+       remotes = bau_uvhub_weight(&bau_desc->distribution);
+       stat->s_ntarguvhub += remotes;
+       if (remotes >= 16)
+               stat->s_ntarguvhub16++;
+       else if (remotes >= 8)
+               stat->s_ntarguvhub8++;
+       else if (remotes >= 4)
+               stat->s_ntarguvhub4++;
+       else if (remotes >= 2)
+               stat->s_ntarguvhub2++;
+       else
+               stat->s_ntarguvhub1++;
 
        bau_desc->payload.address = va;
        bau_desc->payload.sending_cpu = cpu;
 
-       return uv_flush_send_and_wait(uv_cpu, this_pnode, bau_desc, flush_mask);
+       /*
+        * uv_flush_send_and_wait returns null if all cpu's were messaged, or
+        * the adjusted flush_mask if any cpu's were not messaged.
+        */
+       return uv_flush_send_and_wait(bau_desc, flush_mask, bcp);
 }
 
 /*
@@ -389,87 +791,70 @@ const struct cpumask *uv_flush_tlb_others(const struct cpumask *cpumask,
  *
  * We received a broadcast assist message.
  *
- * Interrupts may have been disabled; this interrupt could represent
+ * Interrupts are disabled; this interrupt could represent
  * the receipt of several messages.
  *
- * All cores/threads on this node get this interrupt.
- * The last one to see it does the s/w ack.
+ * All cores/threads on this hub get this interrupt.
+ * The last one to see it does the software ack.
  * (the resource will not be freed until noninterruptable cpus see this
- *  interrupt; hardware will timeout the s/w ack and reply ERROR)
+ *  interrupt; hardware may timeout the s/w ack and reply ERROR)
  */
 void uv_bau_message_interrupt(struct pt_regs *regs)
 {
-       struct bau_payload_queue_entry *va_queue_first;
-       struct bau_payload_queue_entry *va_queue_last;
-       struct bau_payload_queue_entry *msg;
-       struct pt_regs *old_regs = set_irq_regs(regs);
-       cycles_t time1;
-       cycles_t time2;
-       int msg_slot;
-       int sw_ack_slot;
-       int fw;
        int count = 0;
-       unsigned long local_pnode;
-
-       ack_APIC_irq();
-       exit_idle();
-       irq_enter();
-
-       time1 = get_cycles();
-
-       local_pnode = uv_blade_to_pnode(uv_numa_blade_id());
-
-       va_queue_first = __get_cpu_var(bau_control).va_queue_first;
-       va_queue_last = __get_cpu_var(bau_control).va_queue_last;
-
-       msg = __get_cpu_var(bau_control).bau_msg_head;
+       cycles_t time_start;
+       struct bau_payload_queue_entry *msg;
+       struct bau_control *bcp;
+       struct ptc_stats *stat;
+       struct msg_desc msgdesc;
+
+       time_start = get_cycles();
+       bcp = &per_cpu(bau_control, smp_processor_id());
+       stat = &per_cpu(ptcstats, smp_processor_id());
+       msgdesc.va_queue_first = bcp->va_queue_first;
+       msgdesc.va_queue_last = bcp->va_queue_last;
+       msg = bcp->bau_msg_head;
        while (msg->sw_ack_vector) {
                count++;
-               fw = msg->sw_ack_vector;
-               msg_slot = msg - va_queue_first;
-               sw_ack_slot = ffs(fw) - 1;
-
-               uv_bau_process_message(msg, msg_slot, sw_ack_slot);
-
+               msgdesc.msg_slot = msg - msgdesc.va_queue_first;
+               msgdesc.sw_ack_slot = ffs(msg->sw_ack_vector) - 1;
+               msgdesc.msg = msg;
+               uv_bau_process_message(&msgdesc, bcp);
                msg++;
-               if (msg > va_queue_last)
-                       msg = va_queue_first;
-               __get_cpu_var(bau_control).bau_msg_head = msg;
+               if (msg > msgdesc.va_queue_last)
+                       msg = msgdesc.va_queue_first;
+               bcp->bau_msg_head = msg;
        }
+       stat->d_time += (get_cycles() - time_start);
        if (!count)
-               __get_cpu_var(ptcstats).nomsg++;
+               stat->d_nomsg++;
        else if (count > 1)
-               __get_cpu_var(ptcstats).multmsg++;
-
-       time2 = get_cycles();
-       __get_cpu_var(ptcstats).dflush += (time2 - time1);
-
-       irq_exit();
-       set_irq_regs(old_regs);
+               stat->d_multmsg++;
+       ack_APIC_irq();
 }
 
 /*
  * uv_enable_timeouts
  *
- * Each target blade (i.e. blades that have cpu's) needs to have
+ * Each target uvhub (i.e. a uvhub that has no cpu's) needs to have
  * shootdown message timeouts enabled.  The timeout does not cause
  * an interrupt, but causes an error message to be returned to
  * the sender.
  */
 static void uv_enable_timeouts(void)
 {
-       int blade;
-       int nblades;
+       int uvhub;
+       int nuvhubs;
        int pnode;
        unsigned long mmr_image;
 
-       nblades = uv_num_possible_blades();
+       nuvhubs = uv_num_possible_blades();
 
-       for (blade = 0; blade < nblades; blade++) {
-               if (!uv_blade_nr_possible_cpus(blade))
+       for (uvhub = 0; uvhub < nuvhubs; uvhub++) {
+               if (!uv_blade_nr_possible_cpus(uvhub))
                        continue;
 
-               pnode = uv_blade_to_pnode(blade);
+               pnode = uv_blade_to_pnode(uvhub);
                mmr_image =
                    uv_read_global_mmr64(pnode, UVH_LB_BAU_MISC_CONTROL);
                /*
@@ -479,16 +864,16 @@ static void uv_enable_timeouts(void)
                 * To program the period, the SOFT_ACK_MODE must be off.
                 */
                mmr_image &= ~((unsigned long)1 <<
-                              UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT);
+                   UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
                uv_write_global_mmr64
                    (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
                /*
                 * Set the 4-bit period.
                 */
                mmr_image &= ~((unsigned long)0xf <<
-                       UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT);
+                    UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
                mmr_image |= (UV_INTD_SOFT_ACK_TIMEOUT_PERIOD <<
-                            UV_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHIFT);
+                    UVH_LB_BAU_MISC_CONTROL_INTD_SOFT_ACK_TIMEOUT_PERIOD_SHFT);
                uv_write_global_mmr64
                    (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
                /*
@@ -497,7 +882,7 @@ static void uv_enable_timeouts(void)
                 * indicated in bits 2:0 (7 causes all of them to timeout).
                 */
                mmr_image |= ((unsigned long)1 <<
-                             UV_ENABLE_INTD_SOFT_ACK_MODE_SHIFT);
+                   UVH_LB_BAU_MISC_CONTROL_ENABLE_INTD_SOFT_ACK_MODE_SHFT);
                uv_write_global_mmr64
                    (pnode, UVH_LB_BAU_MISC_CONTROL, mmr_image);
        }
@@ -522,9 +907,20 @@ static void uv_ptc_seq_stop(struct seq_file *file, void *data)
 {
 }
 
+static inline unsigned long long
+millisec_2_cycles(unsigned long millisec)
+{
+       unsigned long ns;
+       unsigned long long cyc;
+
+       ns = millisec * 1000;
+       cyc = (ns << CYC2NS_SCALE_FACTOR)/(per_cpu(cyc2ns, smp_processor_id()));
+       return cyc;
+}
+
 /*
- * Display the statistics thru /proc
- * data points to the cpu number
+ * Display the statistics thru /proc.
+ * 'data' points to the cpu number
  */
 static int uv_ptc_seq_show(struct seq_file *file, void *data)
 {
@@ -535,78 +931,155 @@ static int uv_ptc_seq_show(struct seq_file *file, void *data)
 
        if (!cpu) {
                seq_printf(file,
-               "# cpu requestor requestee one all sretry dretry ptc_i ");
+                       "# cpu sent stime numuvhubs numuvhubs16 numuvhubs8 ");
                seq_printf(file,
-               "sw_ack sflush dflush sok dnomsg dmult starget\n");
+                       "numuvhubs4 numuvhubs2 numuvhubs1 numcpus dto ");
+               seq_printf(file,
+                       "retries rok resetp resett giveup sto bz throt ");
+               seq_printf(file,
+                       "sw_ack recv rtime all ");
+               seq_printf(file,
+                       "one mult none retry canc nocan reset rcan\n");
        }
        if (cpu < num_possible_cpus() && cpu_online(cpu)) {
                stat = &per_cpu(ptcstats, cpu);
-               seq_printf(file, "cpu %d %ld %ld %ld %ld %ld %ld %ld ",
-                          cpu, stat->requestor,
-                          stat->requestee, stat->onetlb, stat->alltlb,
-                          stat->s_retry, stat->d_retry, stat->ptc_i);
-               seq_printf(file, "%lx %ld %ld %ld %ld %ld %ld\n",
+               /* source side statistics */
+               seq_printf(file,
+                       "cpu %d %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld ",
+                          cpu, stat->s_requestor, cycles_2_us(stat->s_time),
+                          stat->s_ntarguvhub, stat->s_ntarguvhub16,
+                          stat->s_ntarguvhub8, stat->s_ntarguvhub4,
+                          stat->s_ntarguvhub2, stat->s_ntarguvhub1,
+                          stat->s_ntargcpu, stat->s_dtimeout);
+               seq_printf(file, "%ld %ld %ld %ld %ld %ld %ld %ld ",
+                          stat->s_retry_messages, stat->s_retriesok,
+                          stat->s_resets_plug, stat->s_resets_timeout,
+                          stat->s_giveup, stat->s_stimeout,
+                          stat->s_busy, stat->s_throttles);
+               /* destination side statistics */
+               seq_printf(file,
+                          "%lx %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld\n",
                           uv_read_global_mmr64(uv_cpu_to_pnode(cpu),
                                        UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE),
-                          stat->sflush, stat->dflush,
-                          stat->retriesok, stat->nomsg,
-                          stat->multmsg, stat->ntargeted);
+                          stat->d_requestee, cycles_2_us(stat->d_time),
+                          stat->d_alltlb, stat->d_onetlb, stat->d_multmsg,
+                          stat->d_nomsg, stat->d_retries, stat->d_canceled,
+                          stat->d_nocanceled, stat->d_resets,
+                          stat->d_rcanceled);
        }
 
        return 0;
 }
 
 /*
+ * -1: resetf the statistics
  *  0: display meaning of the statistics
- * >0: retry limit
+ * >0: maximum concurrent active descriptors per uvhub (throttle)
  */
 static ssize_t uv_ptc_proc_write(struct file *file, const char __user *user,
                                 size_t count, loff_t *data)
 {
-       long newmode;
+       int cpu;
+       long input_arg;
        char optstr[64];
+       struct ptc_stats *stat;
+       struct bau_control *bcp;
 
        if (count == 0 || count > sizeof(optstr))
                return -EINVAL;
        if (copy_from_user(optstr, user, count))
                return -EFAULT;
        optstr[count - 1] = '\0';
-       if (strict_strtoul(optstr, 10, &newmode) < 0) {
+       if (strict_strtol(optstr, 10, &input_arg) < 0) {
                printk(KERN_DEBUG "%s is invalid\n", optstr);
                return -EINVAL;
        }
 
-       if (newmode == 0) {
+       if (input_arg == 0) {
                printk(KERN_DEBUG "# cpu:      cpu number\n");
+               printk(KERN_DEBUG "Sender statistics:\n");
+               printk(KERN_DEBUG
+               "sent:     number of shootdown messages sent\n");
+               printk(KERN_DEBUG
+               "stime:    time spent sending messages\n");
+               printk(KERN_DEBUG
+               "numuvhubs: number of hubs targeted with shootdown\n");
+               printk(KERN_DEBUG
+               "numuvhubs16: number times 16 or more hubs targeted\n");
+               printk(KERN_DEBUG
+               "numuvhubs8: number times 8 or more hubs targeted\n");
+               printk(KERN_DEBUG
+               "numuvhubs4: number times 4 or more hubs targeted\n");
+               printk(KERN_DEBUG
+               "numuvhubs2: number times 2 or more hubs targeted\n");
+               printk(KERN_DEBUG
+               "numuvhubs1: number times 1 hub targeted\n");
+               printk(KERN_DEBUG
+               "numcpus:  number of cpus targeted with shootdown\n");
+               printk(KERN_DEBUG
+               "dto:      number of destination timeouts\n");
+               printk(KERN_DEBUG
+               "retries:  destination timeout retries sent\n");
+               printk(KERN_DEBUG
+               "rok:   :  destination timeouts successfully retried\n");
+               printk(KERN_DEBUG
+               "resetp:   ipi-style resource resets for plugs\n");
+               printk(KERN_DEBUG
+               "resett:   ipi-style resource resets for timeouts\n");
+               printk(KERN_DEBUG
+               "giveup:   fall-backs to ipi-style shootdowns\n");
+               printk(KERN_DEBUG
+               "sto:      number of source timeouts\n");
+               printk(KERN_DEBUG
+               "bz:       number of stay-busy's\n");
+               printk(KERN_DEBUG
+               "throt:    number times spun in throttle\n");
+               printk(KERN_DEBUG "Destination side statistics:\n");
                printk(KERN_DEBUG
-               "requestor:  times this cpu was the flush requestor\n");
+               "sw_ack:   image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
                printk(KERN_DEBUG
-               "requestee:  times this cpu was requested to flush its TLBs\n");
+               "recv:     shootdown messages received\n");
                printk(KERN_DEBUG
-               "one:        times requested to flush a single address\n");
+               "rtime:    time spent processing messages\n");
                printk(KERN_DEBUG
-               "all:        times requested to flush all TLB's\n");
+               "all:      shootdown all-tlb messages\n");
                printk(KERN_DEBUG
-               "sretry:     number of retries of source-side timeouts\n");
+               "one:      shootdown one-tlb messages\n");
                printk(KERN_DEBUG
-               "dretry:     number of retries of destination-side timeouts\n");
+               "mult:     interrupts that found multiple messages\n");
                printk(KERN_DEBUG
-               "ptc_i:      times UV fell through to IPI-style flushes\n");
+               "none:     interrupts that found no messages\n");
                printk(KERN_DEBUG
-               "sw_ack:     image of UVH_LB_BAU_INTD_SOFTWARE_ACKNOWLEDGE\n");
+               "retry:    number of retry messages processed\n");
                printk(KERN_DEBUG
-               "sflush_us:  cycles spent in uv_flush_tlb_others()\n");
+               "canc:     number messages canceled by retries\n");
                printk(KERN_DEBUG
-               "dflush_us:  cycles spent in handling flush requests\n");
-               printk(KERN_DEBUG "sok:        successes on retry\n");
-               printk(KERN_DEBUG "dnomsg:     interrupts with no message\n");
+               "nocan:    number retries that found nothing to cancel\n");
                printk(KERN_DEBUG
-               "dmult:      interrupts with multiple messages\n");
-               printk(KERN_DEBUG "starget:    nodes targeted\n");
+               "reset:    number of ipi-style reset requests processed\n");
+               printk(KERN_DEBUG
+               "rcan:     number messages canceled by reset requests\n");
+       } else if (input_arg == -1) {
+               for_each_present_cpu(cpu) {
+                       stat = &per_cpu(ptcstats, cpu);
+                       memset(stat, 0, sizeof(struct ptc_stats));
+               }
        } else {
-               uv_bau_retry_limit = newmode;
-               printk(KERN_DEBUG "timeout retry limit:%d\n",
-                      uv_bau_retry_limit);
+               uv_bau_max_concurrent = input_arg;
+               bcp = &per_cpu(bau_control, smp_processor_id());
+               if (uv_bau_max_concurrent < 1 ||
+                   uv_bau_max_concurrent > bcp->cpus_in_uvhub) {
+                       printk(KERN_DEBUG
+                               "Error: BAU max concurrent %d; %d is invalid\n",
+                               bcp->max_concurrent, uv_bau_max_concurrent);
+                       return -EINVAL;
+               }
+               printk(KERN_DEBUG "Set BAU max concurrent:%d\n",
+                      uv_bau_max_concurrent);
+               for_each_present_cpu(cpu) {
+                       bcp = &per_cpu(bau_control, cpu);
+                       bcp->max_concurrent = uv_bau_max_concurrent;
+               }
        }
 
        return count;
@@ -649,80 +1122,31 @@ static int __init uv_ptc_init(void)
        return 0;
 }
 
-/*
- * begin the initialization of the per-blade control structures
- */
-static struct bau_control * __init uv_table_bases_init(int blade, int node)
-{
-       int i;
-       struct bau_msg_status *msp;
-       struct bau_control *bau_tabp;
-
-       bau_tabp =
-           kmalloc_node(sizeof(struct bau_control), GFP_KERNEL, node);
-       BUG_ON(!bau_tabp);
-
-       bau_tabp->msg_statuses =
-           kmalloc_node(sizeof(struct bau_msg_status) *
-                        DEST_Q_SIZE, GFP_KERNEL, node);
-       BUG_ON(!bau_tabp->msg_statuses);
-
-       for (i = 0, msp = bau_tabp->msg_statuses; i < DEST_Q_SIZE; i++, msp++)
-               bau_cpubits_clear(&msp->seen_by, (int)
-                                 uv_blade_nr_possible_cpus(blade));
-
-       uv_bau_table_bases[blade] = bau_tabp;
-
-       return bau_tabp;
-}
-
-/*
- * finish the initialization of the per-blade control structures
- */
-static void __init
-uv_table_bases_finish(int blade,
-                     struct bau_control *bau_tablesp,
-                     struct bau_desc *adp)
-{
-       struct bau_control *bcp;
-       int cpu;
-
-       for_each_present_cpu(cpu) {
-               if (blade != uv_cpu_to_blade_id(cpu))
-                       continue;
-
-               bcp = (struct bau_control *)&per_cpu(bau_control, cpu);
-               bcp->bau_msg_head       = bau_tablesp->va_queue_first;
-               bcp->va_queue_first     = bau_tablesp->va_queue_first;
-               bcp->va_queue_last      = bau_tablesp->va_queue_last;
-               bcp->msg_statuses       = bau_tablesp->msg_statuses;
-               bcp->descriptor_base    = adp;
-       }
-}
-
 /*
  * initialize the sending side's sending buffers
  */
-static struct bau_desc * __init
+static void
 uv_activation_descriptor_init(int node, int pnode)
 {
        int i;
+       int cpu;
        unsigned long pa;
        unsigned long m;
        unsigned long n;
-       struct bau_desc *adp;
-       struct bau_desc *ad2;
+       struct bau_desc *bau_desc;
+       struct bau_desc *bd2;
+       struct bau_control *bcp;
 
        /*
         * each bau_desc is 64 bytes; there are 8 (UV_ITEMS_PER_DESCRIPTOR)
-        * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per blade
+        * per cpu; and up to 32 (UV_ADP_SIZE) cpu's per uvhub
         */
-       adp = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
+       bau_desc = (struct bau_desc *)kmalloc_node(sizeof(struct bau_desc)*
                UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR, GFP_KERNEL, node);
-       BUG_ON(!adp);
+       BUG_ON(!bau_desc);
 
-       pa = uv_gpa(adp); /* need the real nasid*/
-       n = uv_gpa_to_pnode(pa);
+       pa = uv_gpa(bau_desc); /* need the real nasid*/
+       n = pa >> uv_nshift;
        m = pa & uv_mmask;
 
        uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_DESCRIPTOR_BASE,
@@ -731,96 +1155,188 @@ uv_activation_descriptor_init(int node, int pnode)
        /*
         * initializing all 8 (UV_ITEMS_PER_DESCRIPTOR) descriptors for each
         * cpu even though we only use the first one; one descriptor can
-        * describe a broadcast to 256 nodes.
+        * describe a broadcast to 256 uv hubs.
         */
-       for (i = 0, ad2 = adp; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
-               i++, ad2++) {
-               memset(ad2, 0, sizeof(struct bau_desc));
-               ad2->header.sw_ack_flag = 1;
+       for (i = 0, bd2 = bau_desc; i < (UV_ADP_SIZE*UV_ITEMS_PER_DESCRIPTOR);
+               i++, bd2++) {
+               memset(bd2, 0, sizeof(struct bau_desc));
+               bd2->header.sw_ack_flag = 1;
                /*
-                * base_dest_nodeid is the first node in the partition, so
-                * the bit map will indicate partition-relative node numbers.
-                * note that base_dest_nodeid is actually a nasid.
+                * base_dest_nodeid is the nasid (pnode<<1) of the first uvhub
+                * in the partition. The bit map will indicate uvhub numbers,
+                * which are 0-N in a partition. Pnodes are unique system-wide.
                 */
-               ad2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
-               ad2->header.dest_subnodeid = 0x10; /* the LB */
-               ad2->header.command = UV_NET_ENDPOINT_INTD;
-               ad2->header.int_both = 1;
+               bd2->header.base_dest_nodeid = uv_partition_base_pnode << 1;
+               bd2->header.dest_subnodeid = 0x10; /* the LB */
+               bd2->header.command = UV_NET_ENDPOINT_INTD;
+               bd2->header.int_both = 1;
                /*
                 * all others need to be set to zero:
                 *   fairness chaining multilevel count replied_to
                 */
        }
-       return adp;
+       for_each_present_cpu(cpu) {
+               if (pnode != uv_blade_to_pnode(uv_cpu_to_blade_id(cpu)))
+                       continue;
+               bcp = &per_cpu(bau_control, cpu);
+               bcp->descriptor_base = bau_desc;
+       }
 }
 
 /*
  * initialize the destination side's receiving buffers
+ * entered for each uvhub in the partition
+ * - node is first node (kernel memory notion) on the uvhub
+ * - pnode is the uvhub's physical identifier
  */
-static struct bau_payload_queue_entry * __init
-uv_payload_queue_init(int node, int pnode, struct bau_control *bau_tablesp)
+static void
+uv_payload_queue_init(int node, int pnode)
 {
-       struct bau_payload_queue_entry *pqp;
-       unsigned long pa;
        int pn;
+       int cpu;
        char *cp;
+       unsigned long pa;
+       struct bau_payload_queue_entry *pqp;
+       struct bau_payload_queue_entry *pqp_malloc;
+       struct bau_control *bcp;
 
        pqp = (struct bau_payload_queue_entry *) kmalloc_node(
                (DEST_Q_SIZE + 1) * sizeof(struct bau_payload_queue_entry),
                GFP_KERNEL, node);
        BUG_ON(!pqp);
+       pqp_malloc = pqp;
 
        cp = (char *)pqp + 31;
        pqp = (struct bau_payload_queue_entry *)(((unsigned long)cp >> 5) << 5);
-       bau_tablesp->va_queue_first = pqp;
+
+       for_each_present_cpu(cpu) {
+               if (pnode != uv_cpu_to_pnode(cpu))
+                       continue;
+               /* for every cpu on this pnode: */
+               bcp = &per_cpu(bau_control, cpu);
+               bcp->va_queue_first = pqp;
+               bcp->bau_msg_head = pqp;
+               bcp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
+       }
        /*
         * need the pnode of where the memory was really allocated
         */
        pa = uv_gpa(pqp);
-       pn = uv_gpa_to_pnode(pa);
+       pn = pa >> uv_nshift;
        uv_write_global_mmr64(pnode,
                              UVH_LB_BAU_INTD_PAYLOAD_QUEUE_FIRST,
                              ((unsigned long)pn << UV_PAYLOADQ_PNODE_SHIFT) |
                              uv_physnodeaddr(pqp));
        uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_TAIL,
                              uv_physnodeaddr(pqp));
-       bau_tablesp->va_queue_last = pqp + (DEST_Q_SIZE - 1);
        uv_write_global_mmr64(pnode, UVH_LB_BAU_INTD_PAYLOAD_QUEUE_LAST,
                              (unsigned long)
-                             uv_physnodeaddr(bau_tablesp->va_queue_last));
+                             uv_physnodeaddr(pqp + (DEST_Q_SIZE - 1)));
+       /* in effect, all msg_type's are set to MSG_NOOP */
        memset(pqp, 0, sizeof(struct bau_payload_queue_entry) * DEST_Q_SIZE);
-
-       return pqp;
 }
 
 /*
- * Initialization of each UV blade's structures
+ * Initialization of each UV hub's structures
  */
-static int __init uv_init_blade(int blade)
+static void __init uv_init_uvhub(int uvhub, int vector)
 {
        int node;
        int pnode;
-       unsigned long pa;
        unsigned long apicid;
-       struct bau_desc *adp;
-       struct bau_payload_queue_entry *pqp;
-       struct bau_control *bau_tablesp;
-
-       node = blade_to_first_node(blade);
-       bau_tablesp = uv_table_bases_init(blade, node);
-       pnode = uv_blade_to_pnode(blade);
-       adp = uv_activation_descriptor_init(node, pnode);
-       pqp = uv_payload_queue_init(node, pnode, bau_tablesp);
-       uv_table_bases_finish(blade, bau_tablesp, adp);
+
+       node = uvhub_to_first_node(uvhub);
+       pnode = uv_blade_to_pnode(uvhub);
+       uv_activation_descriptor_init(node, pnode);
+       uv_payload_queue_init(node, pnode);
        /*
         * the below initialization can't be in firmware because the
         * messaging IRQ will be determined by the OS
         */
-       apicid = blade_to_first_apicid(blade);
-       pa = uv_read_global_mmr64(pnode, UVH_BAU_DATA_CONFIG);
+       apicid = uvhub_to_first_apicid(uvhub);
        uv_write_global_mmr64(pnode, UVH_BAU_DATA_CONFIG,
-                                     ((apicid << 32) | UV_BAU_MESSAGE));
-       return 0;
+                                     ((apicid << 32) | vector));
+}
+
+/*
+ * initialize the bau_control structure for each cpu
+ */
+static void uv_init_per_cpu(int nuvhubs)
+{
+       int i, j, k;
+       int cpu;
+       int pnode;
+       int uvhub;
+       short socket = 0;
+       struct bau_control *bcp;
+       struct uvhub_desc *bdp;
+       struct socket_desc *sdp;
+       struct bau_control *hmaster = NULL;
+       struct bau_control *smaster = NULL;
+       struct socket_desc {
+               short num_cpus;
+               short cpu_number[16];
+       };
+       struct uvhub_desc {
+               short num_sockets;
+               short num_cpus;
+               short uvhub;
+               short pnode;
+               struct socket_desc socket[2];
+       };
+       struct uvhub_desc *uvhub_descs;
+
+       uvhub_descs = (struct uvhub_desc *)
+               kmalloc(nuvhubs * sizeof(struct uvhub_desc), GFP_KERNEL);
+       memset(uvhub_descs, 0, nuvhubs * sizeof(struct uvhub_desc));
+       for_each_present_cpu(cpu) {
+               bcp = &per_cpu(bau_control, cpu);
+               memset(bcp, 0, sizeof(struct bau_control));
+               spin_lock_init(&bcp->masks_lock);
+               bcp->max_concurrent = uv_bau_max_concurrent;
+               pnode = uv_cpu_hub_info(cpu)->pnode;
+               uvhub = uv_cpu_hub_info(cpu)->numa_blade_id;
+               bdp = &uvhub_descs[uvhub];
+               bdp->num_cpus++;
+               bdp->uvhub = uvhub;
+               bdp->pnode = pnode;
+               /* time interval to catch a hardware stay-busy bug */
+               bcp->timeout_interval = millisec_2_cycles(3);
+               /* kludge: assume uv_hub.h is constant */
+               socket = (cpu_physical_id(cpu)>>5)&1;
+               if (socket >= bdp->num_sockets)
+                       bdp->num_sockets = socket+1;
+               sdp = &bdp->socket[socket];
+               sdp->cpu_number[sdp->num_cpus] = cpu;
+               sdp->num_cpus++;
+       }
+       socket = 0;
+       for_each_possible_blade(uvhub) {
+               bdp = &uvhub_descs[uvhub];
+               for (i = 0; i < bdp->num_sockets; i++) {
+                       sdp = &bdp->socket[i];
+                       for (j = 0; j < sdp->num_cpus; j++) {
+                               cpu = sdp->cpu_number[j];
+                               bcp = &per_cpu(bau_control, cpu);
+                               bcp->cpu = cpu;
+                               if (j == 0) {
+                                       smaster = bcp;
+                                       if (i == 0)
+                                               hmaster = bcp;
+                               }
+                               bcp->cpus_in_uvhub = bdp->num_cpus;
+                               bcp->cpus_in_socket = sdp->num_cpus;
+                               bcp->socket_master = smaster;
+                               bcp->uvhub_master = hmaster;
+                               for (k = 0; k < DEST_Q_SIZE; k++)
+                                       bcp->socket_acknowledge_count[k] = 0;
+                               bcp->uvhub_cpu =
+                                 uv_cpu_hub_info(cpu)->blade_processor_id;
+                       }
+                       socket++;
+               }
+       }
+       kfree(uvhub_descs);
 }
 
 /*
@@ -828,38 +1344,54 @@ static int __init uv_init_blade(int blade)
  */
 static int __init uv_bau_init(void)
 {
-       int blade;
-       int nblades;
+       int uvhub;
+       int pnode;
+       int nuvhubs;
        int cur_cpu;
+       int vector;
+       unsigned long mmr;
 
        if (!is_uv_system())
                return 0;
 
+       if (nobau)
+               return 0;
+
        for_each_possible_cpu(cur_cpu)
                zalloc_cpumask_var_node(&per_cpu(uv_flush_tlb_mask, cur_cpu),
                                       GFP_KERNEL, cpu_to_node(cur_cpu));
 
-       uv_bau_retry_limit = 1;
+       uv_bau_max_concurrent = MAX_BAU_CONCURRENT;
+       uv_nshift = uv_hub_info->m_val;
        uv_mmask = (1UL << uv_hub_info->m_val) - 1;
-       nblades = uv_num_possible_blades();
+       nuvhubs = uv_num_possible_blades();
 
-       uv_bau_table_bases = (struct bau_control **)
-           kmalloc(nblades * sizeof(struct bau_control *), GFP_KERNEL);
-       BUG_ON(!uv_bau_table_bases);
+       uv_init_per_cpu(nuvhubs);
 
        uv_partition_base_pnode = 0x7fffffff;
-       for (blade = 0; blade < nblades; blade++)
-               if (uv_blade_nr_possible_cpus(blade) &&
-                       (uv_blade_to_pnode(blade) < uv_partition_base_pnode))
-                       uv_partition_base_pnode = uv_blade_to_pnode(blade);
-       for (blade = 0; blade < nblades; blade++)
-               if (uv_blade_nr_possible_cpus(blade))
-                       uv_init_blade(blade);
-
-       alloc_intr_gate(UV_BAU_MESSAGE, uv_bau_message_intr1);
+       for (uvhub = 0; uvhub < nuvhubs; uvhub++)
+               if (uv_blade_nr_possible_cpus(uvhub) &&
+                       (uv_blade_to_pnode(uvhub) < uv_partition_base_pnode))
+                       uv_partition_base_pnode = uv_blade_to_pnode(uvhub);
+
+       vector = UV_BAU_MESSAGE;
+       for_each_possible_blade(uvhub)
+               if (uv_blade_nr_possible_cpus(uvhub))
+                       uv_init_uvhub(uvhub, vector);
+
        uv_enable_timeouts();
+       alloc_intr_gate(vector, uv_bau_message_intr1);
+
+       for_each_possible_blade(uvhub) {
+               pnode = uv_blade_to_pnode(uvhub);
+               /* INIT the bau */
+               uv_write_global_mmr64(pnode, UVH_LB_BAU_SB_ACTIVATION_CONTROL,
+                                     ((unsigned long)1 << 63));
+               mmr = 1; /* should be 1 to broadcast to both sockets */
+               uv_write_global_mmr64(pnode, UVH_BAU_DATA_BROADCAST, mmr);
+       }
 
        return 0;
 }
-__initcall(uv_bau_init);
-__initcall(uv_ptc_init);
+core_initcall(uv_bau_init);
+core_initcall(uv_ptc_init);
index 1168e44..02cfb9b 100644 (file)
@@ -108,15 +108,6 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
        dec_preempt_count();
 }
 
-#ifdef CONFIG_X86_32
-static inline void
-die_if_kernel(const char *str, struct pt_regs *regs, long err)
-{
-       if (!user_mode_vm(regs))
-               die(str, regs, err);
-}
-#endif
-
 static void __kprobes
 do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
        long error_code, siginfo_t *info)
@@ -543,11 +534,11 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
 
        /* DR6 may or may not be cleared by the CPU */
        set_debugreg(0, 6);
+
        /*
         * The processor cleared BTF, so don't mark that we need it set.
         */
-       clear_tsk_thread_flag(tsk, TIF_DEBUGCTLMSR);
-       tsk->thread.debugctlmsr = 0;
+       clear_tsk_thread_flag(tsk, TIF_BLOCKSTEP);
 
        /* Store the virtualized DR6 value */
        tsk->thread.debugreg6 = dr6;
@@ -585,55 +576,67 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
        return;
 }
 
-#ifdef CONFIG_X86_64
-static int kernel_math_error(struct pt_regs *regs, const char *str, int trapnr)
-{
-       if (fixup_exception(regs))
-               return 1;
-
-       notify_die(DIE_GPF, str, regs, 0, trapnr, SIGFPE);
-       /* Illegal floating point operation in the kernel */
-       current->thread.trap_no = trapnr;
-       die(str, regs, 0);
-       return 0;
-}
-#endif
-
 /*
  * Note that we play around with the 'TS' bit in an attempt to get
  * the correct behaviour even in the presence of the asynchronous
  * IRQ13 behaviour
  */
-void math_error(void __user *ip)
+void math_error(struct pt_regs *regs, int error_code, int trapnr)
 {
-       struct task_struct *task;
+       struct task_struct *task = current;
        siginfo_t info;
-       unsigned short cwd, swd, err;
+       unsigned short err;
+       char *str = (trapnr == 16) ? "fpu exception" : "simd exception";
+
+       if (notify_die(DIE_TRAP, str, regs, error_code, trapnr, SIGFPE) == NOTIFY_STOP)
+               return;
+       conditional_sti(regs);
+
+       if (!user_mode_vm(regs))
+       {
+               if (!fixup_exception(regs)) {
+                       task->thread.error_code = error_code;
+                       task->thread.trap_no = trapnr;
+                       die(str, regs, error_code);
+               }
+               return;
+       }
 
        /*
         * Save the info for the exception handler and clear the error.
         */
-       task = current;
        save_init_fpu(task);
-       task->thread.trap_no = 16;
-       task->thread.error_code = 0;
+       task->thread.trap_no = trapnr;
+       task->thread.error_code = error_code;
        info.si_signo = SIGFPE;
        info.si_errno = 0;
-       info.si_addr = ip;
-       /*
-        * (~cwd & swd) will mask out exceptions that are not set to unmasked
-        * status.  0x3f is the exception bits in these regs, 0x200 is the
-        * C1 reg you need in case of a stack fault, 0x040 is the stack
-        * fault bit.  We should only be taking one exception at a time,
-        * so if this combination doesn't produce any single exception,
-        * then we have a bad program that isn't synchronizing its FPU usage
-        * and it will suffer the consequences since we won't be able to
-        * fully reproduce the context of the exception
-        */
-       cwd = get_fpu_cwd(task);
-       swd = get_fpu_swd(task);
+       info.si_addr = (void __user *)regs->ip;
+       if (trapnr == 16) {
+               unsigned short cwd, swd;
+               /*
+                * (~cwd & swd) will mask out exceptions that are not set to unmasked
+                * status.  0x3f is the exception bits in these regs, 0x200 is the
+                * C1 reg you need in case of a stack fault, 0x040 is the stack
+                * fault bit.  We should only be taking one exception at a time,
+                * so if this combination doesn't produce any single exception,
+                * then we have a bad program that isn't synchronizing its FPU usage
+                * and it will suffer the consequences since we won't be able to
+                * fully reproduce the context of the exception
+                */
+               cwd = get_fpu_cwd(task);
+               swd = get_fpu_swd(task);
 
-       err = swd & ~cwd;
+               err = swd & ~cwd;
+       } else {
+               /*
+                * The SIMD FPU exceptions are handled a little differently, as there
+                * is only a single status/control register.  Thus, to determine which
+                * unmasked exception was caught we must mask the exception mask bits
+                * at 0x1f80, and then use these to mask the exception bits at 0x3f.
+                */
+               unsigned short mxcsr = get_fpu_mxcsr(task);
+               err = ~(mxcsr >> 7) & mxcsr;
+       }
 
        if (err & 0x001) {      /* Invalid op */
                /*
@@ -662,97 +665,17 @@ void math_error(void __user *ip)
 
 dotraplinkage void do_coprocessor_error(struct pt_regs *regs, long error_code)
 {
-       conditional_sti(regs);
-
 #ifdef CONFIG_X86_32
        ignore_fpu_irq = 1;
-#else
-       if (!user_mode(regs) &&
-           kernel_math_error(regs, "kernel x87 math error", 16))
-               return;
 #endif
 
-       math_error((void __user *)regs->ip);
-}
-
-static void simd_math_error(void __user *ip)
-{
-       struct task_struct *task;
-       siginfo_t info;
-       unsigned short mxcsr;
-
-       /*
-        * Save the info for the exception handler and clear the error.
-        */
-       task = current;
-       save_init_fpu(task);
-       task->thread.trap_no = 19;
-       task->thread.error_code = 0;
-       info.si_signo = SIGFPE;
-       info.si_errno = 0;
-       info.si_code = __SI_FAULT;
-       info.si_addr = ip;
-       /*
-        * The SIMD FPU exceptions are handled a little differently, as there
-        * is only a single status/control register.  Thus, to determine which
-        * unmasked exception was caught we must mask the exception mask bits
-        * at 0x1f80, and then use these to mask the exception bits at 0x3f.
-        */
-       mxcsr = get_fpu_mxcsr(task);
-       switch (~((mxcsr & 0x1f80) >> 7) & (mxcsr & 0x3f)) {
-       case 0x000:
-       default:
-               break;
-       case 0x001: /* Invalid Op */
-               info.si_code = FPE_FLTINV;
-               break;
-       case 0x002: /* Denormalize */
-       case 0x010: /* Underflow */
-               info.si_code = FPE_FLTUND;
-               break;
-       case 0x004: /* Zero Divide */
-               info.si_code = FPE_FLTDIV;
-               break;
-       case 0x008: /* Overflow */
-               info.si_code = FPE_FLTOVF;
-               break;
-       case 0x020: /* Precision */
-               info.si_code = FPE_FLTRES;
-               break;
-       }
-       force_sig_info(SIGFPE, &info, task);
+       math_error(regs, error_code, 16);
 }
 
 dotraplinkage void
 do_simd_coprocessor_error(struct pt_regs *regs, long error_code)
 {
-       conditional_sti(regs);
-
-#ifdef CONFIG_X86_32
-       if (cpu_has_xmm) {
-               /* Handle SIMD FPU exceptions on PIII+ processors. */
-               ignore_fpu_irq = 1;
-               simd_math_error((void __user *)regs->ip);
-               return;
-       }
-       /*
-        * Handle strange cache flush from user space exception
-        * in all other cases.  This is undocumented behaviour.
-        */
-       if (regs->flags & X86_VM_MASK) {
-               handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
-               return;
-       }
-       current->thread.trap_no = 19;
-       current->thread.error_code = error_code;
-       die_if_kernel("cache flush denied", regs, error_code);
-       force_sig(SIGSEGV, current);
-#else
-       if (!user_mode(regs) &&
-                       kernel_math_error(regs, "kernel simd math error", 19))
-               return;
-       simd_math_error((void __user *)regs->ip);
-#endif
+       math_error(regs, error_code, 19);
 }
 
 dotraplinkage void
index 1d40336..1132129 100644 (file)
@@ -44,7 +44,7 @@ static void uv_ack_apic(unsigned int irq)
        ack_APIC_irq();
 }
 
-struct irq_chip uv_irq_chip = {
+static struct irq_chip uv_irq_chip = {
        .name           = "UV-CORE",
        .startup        = uv_noop_ret,
        .shutdown       = uv_noop,
@@ -141,7 +141,7 @@ int uv_irq_2_mmr_info(int irq, unsigned long *offset, int *pnode)
  */
 static int
 arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade,
-                      unsigned long mmr_offset, int restrict)
+                      unsigned long mmr_offset, int limit)
 {
        const struct cpumask *eligible_cpu = cpumask_of(cpu);
        struct irq_desc *desc = irq_to_desc(irq);
@@ -160,7 +160,7 @@ arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade,
        if (err != 0)
                return err;
 
-       if (restrict == UV_AFFINITY_CPU)
+       if (limit == UV_AFFINITY_CPU)
                desc->status |= IRQ_NO_BALANCING;
        else
                desc->status |= IRQ_MOVE_PCNTXT;
@@ -214,7 +214,7 @@ static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask)
        unsigned long mmr_value;
        struct uv_IO_APIC_route_entry *entry;
        unsigned long mmr_offset;
-       unsigned mmr_pnode;
+       int mmr_pnode;
 
        if (set_desc_affinity(desc, mask, &dest))
                return -1;
@@ -248,7 +248,7 @@ static int uv_set_irq_affinity(unsigned int irq, const struct cpumask *mask)
  * interrupt is raised.
  */
 int uv_setup_irq(char *irq_name, int cpu, int mmr_blade,
-                unsigned long mmr_offset, int restrict)
+                unsigned long mmr_offset, int limit)
 {
        int irq, ret;
 
@@ -258,7 +258,7 @@ int uv_setup_irq(char *irq_name, int cpu, int mmr_blade,
                return -EBUSY;
 
        ret = arch_enable_uv_irq(irq_name, irq, cpu, mmr_blade, mmr_offset,
-               restrict);
+               limit);
        if (ret == irq)
                uv_set_irq_2_mmr_info(irq, mmr_offset, mmr_blade);
        else
index 693920b..1b950d1 100644 (file)
@@ -54,7 +54,6 @@ EXPORT_SYMBOL(memcpy);
 EXPORT_SYMBOL(__memcpy);
 
 EXPORT_SYMBOL(empty_zero_page);
-EXPORT_SYMBOL(init_level4_pgt);
 #ifndef CONFIG_PARAVIRT
 EXPORT_SYMBOL(native_load_gs_index);
 #endif
index 782c3a3..37e68fc 100644 (file)
@@ -99,7 +99,7 @@ int save_i387_xstate(void __user *buf)
                if (err)
                        return err;
 
-               if (task_thread_info(tsk)->status & TS_XSAVE)
+               if (use_xsave())
                        err = xsave_user(buf);
                else
                        err = fxsave_user(buf);
@@ -109,14 +109,14 @@ int save_i387_xstate(void __user *buf)
                task_thread_info(tsk)->status &= ~TS_USEDFPU;
                stts();
        } else {
-               if (__copy_to_user(buf, &tsk->thread.xstate->fxsave,
+               if (__copy_to_user(buf, &tsk->thread.fpu.state->fxsave,
                                   xstate_size))
                        return -1;
        }
 
        clear_used_math(); /* trigger finit */
 
-       if (task_thread_info(tsk)->status & TS_XSAVE) {
+       if (use_xsave()) {
                struct _fpstate __user *fx = buf;
                struct _xstate __user *x = buf;
                u64 xstate_bv;
@@ -225,7 +225,7 @@ int restore_i387_xstate(void __user *buf)
                clts();
                task_thread_info(current)->status |= TS_USEDFPU;
        }
-       if (task_thread_info(tsk)->status & TS_XSAVE)
+       if (use_xsave())
                err = restore_user_xstate(buf);
        else
                err = fxrstor_checking((__force struct i387_fxsave_struct *)
index 2f8db0e..edca080 100644 (file)
@@ -3659,8 +3659,11 @@ static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
 
        /* We need to handle NMIs before interrupts are enabled */
        if ((exit_intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR &&
-           (exit_intr_info & INTR_INFO_VALID_MASK))
+           (exit_intr_info & INTR_INFO_VALID_MASK)) {
+               kvm_before_handle_nmi(&vmx->vcpu);
                asm("int $2");
+               kvm_after_handle_nmi(&vmx->vcpu);
+       }
 
        idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK;
 
index c4f35b5..dd9bc8f 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/user-return-notifier.h>
 #include <linux/srcu.h>
 #include <linux/slab.h>
+#include <linux/perf_event.h>
 #include <trace/events/kvm.h>
 #undef TRACE_INCLUDE_FILE
 #define CREATE_TRACE_POINTS
@@ -3747,6 +3748,51 @@ static void kvm_timer_init(void)
        }
 }
 
+static DEFINE_PER_CPU(struct kvm_vcpu *, current_vcpu);
+
+static int kvm_is_in_guest(void)
+{
+       return percpu_read(current_vcpu) != NULL;
+}
+
+static int kvm_is_user_mode(void)
+{
+       int user_mode = 3;
+
+       if (percpu_read(current_vcpu))
+               user_mode = kvm_x86_ops->get_cpl(percpu_read(current_vcpu));
+
+       return user_mode != 0;
+}
+
+static unsigned long kvm_get_guest_ip(void)
+{
+       unsigned long ip = 0;
+
+       if (percpu_read(current_vcpu))
+               ip = kvm_rip_read(percpu_read(current_vcpu));
+
+       return ip;
+}
+
+static struct perf_guest_info_callbacks kvm_guest_cbs = {
+       .is_in_guest            = kvm_is_in_guest,
+       .is_user_mode           = kvm_is_user_mode,
+       .get_guest_ip           = kvm_get_guest_ip,
+};
+
+void kvm_before_handle_nmi(struct kvm_vcpu *vcpu)
+{
+       percpu_write(current_vcpu, vcpu);
+}
+EXPORT_SYMBOL_GPL(kvm_before_handle_nmi);
+
+void kvm_after_handle_nmi(struct kvm_vcpu *vcpu)
+{
+       percpu_write(current_vcpu, NULL);
+}
+EXPORT_SYMBOL_GPL(kvm_after_handle_nmi);
+
 int kvm_arch_init(void *opaque)
 {
        int r;
@@ -3783,6 +3829,8 @@ int kvm_arch_init(void *opaque)
 
        kvm_timer_init();
 
+       perf_register_guest_info_callbacks(&kvm_guest_cbs);
+
        return 0;
 
 out:
@@ -3791,6 +3839,8 @@ out:
 
 void kvm_arch_exit(void)
 {
+       perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
+
        if (!boot_cpu_has(X86_FEATURE_CONSTANT_TSC))
                cpufreq_unregister_notifier(&kvmclock_cpufreq_notifier_block,
                                            CPUFREQ_TRANSITION_NOTIFIER);
index 2d10163..b7a4047 100644 (file)
@@ -65,4 +65,7 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
        return kvm_read_cr0_bits(vcpu, X86_CR0_PG);
 }
 
+void kvm_before_handle_nmi(struct kvm_vcpu *vcpu);
+void kvm_after_handle_nmi(struct kvm_vcpu *vcpu);
+
 #endif
index 419386c..f871e04 100644 (file)
@@ -20,17 +20,18 @@ lib-y := delay.o
 lib-y += thunk_$(BITS).o
 lib-y += usercopy_$(BITS).o getuser.o putuser.o
 lib-y += memcpy_$(BITS).o
-lib-$(CONFIG_KPROBES) += insn.o inat.o
+lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o
 
 obj-y += msr.o msr-reg.o msr-reg-export.o
 
 ifeq ($(CONFIG_X86_32),y)
         obj-y += atomic64_32.o
+        lib-y += atomic64_cx8_32.o
         lib-y += checksum_32.o
         lib-y += strstr_32.o
         lib-y += semaphore_32.o string_32.o
 ifneq ($(CONFIG_X86_CMPXCHG64),y)
-        lib-y += cmpxchg8b_emu.o
+        lib-y += cmpxchg8b_emu.o atomic64_386_32.o
 endif
         lib-$(CONFIG_X86_USE_3DNOW) += mmx_32.o
 else
index 824fa0b..540179e 100644 (file)
 #include <asm/cmpxchg.h>
 #include <asm/atomic.h>
 
-static noinline u64 cmpxchg8b(u64 *ptr, u64 old, u64 new)
-{
-       u32 low = new;
-       u32 high = new >> 32;
-
-       asm volatile(
-               LOCK_PREFIX "cmpxchg8b %1\n"
-                    : "+A" (old), "+m" (*ptr)
-                    :  "b" (low),  "c" (high)
-                    );
-       return old;
-}
-
-u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old_val, u64 new_val)
-{
-       return cmpxchg8b(&ptr->counter, old_val, new_val);
-}
-EXPORT_SYMBOL(atomic64_cmpxchg);
-
-/**
- * atomic64_xchg - xchg atomic64 variable
- * @ptr:      pointer to type atomic64_t
- * @new_val:  value to assign
- *
- * Atomically xchgs the value of @ptr to @new_val and returns
- * the old value.
- */
-u64 atomic64_xchg(atomic64_t *ptr, u64 new_val)
-{
-       /*
-        * Try first with a (possibly incorrect) assumption about
-        * what we have there. We'll do two loops most likely,
-        * but we'll get an ownership MESI transaction straight away
-        * instead of a read transaction followed by a
-        * flush-for-ownership transaction:
-        */
-       u64 old_val, real_val = 0;
-
-       do {
-               old_val = real_val;
-
-               real_val = atomic64_cmpxchg(ptr, old_val, new_val);
-
-       } while (real_val != old_val);
-
-       return old_val;
-}
-EXPORT_SYMBOL(atomic64_xchg);
-
-/**
- * atomic64_set - set atomic64 variable
- * @ptr:      pointer to type atomic64_t
- * @new_val:  value to assign
- *
- * Atomically sets the value of @ptr to @new_val.
- */
-void atomic64_set(atomic64_t *ptr, u64 new_val)
-{
-       atomic64_xchg(ptr, new_val);
-}
-EXPORT_SYMBOL(atomic64_set);
-
-/**
-EXPORT_SYMBOL(atomic64_read);
- * atomic64_add_return - add and return
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically adds @delta to @ptr and returns @delta + *@ptr
- */
-noinline u64 atomic64_add_return(u64 delta, atomic64_t *ptr)
-{
-       /*
-        * Try first with a (possibly incorrect) assumption about
-        * what we have there. We'll do two loops most likely,
-        * but we'll get an ownership MESI transaction straight away
-        * instead of a read transaction followed by a
-        * flush-for-ownership transaction:
-        */
-       u64 old_val, new_val, real_val = 0;
-
-       do {
-               old_val = real_val;
-               new_val = old_val + delta;
-
-               real_val = atomic64_cmpxchg(ptr, old_val, new_val);
-
-       } while (real_val != old_val);
-
-       return new_val;
-}
-EXPORT_SYMBOL(atomic64_add_return);
-
-u64 atomic64_sub_return(u64 delta, atomic64_t *ptr)
-{
-       return atomic64_add_return(-delta, ptr);
-}
-EXPORT_SYMBOL(atomic64_sub_return);
-
-u64 atomic64_inc_return(atomic64_t *ptr)
-{
-       return atomic64_add_return(1, ptr);
-}
-EXPORT_SYMBOL(atomic64_inc_return);
-
-u64 atomic64_dec_return(atomic64_t *ptr)
-{
-       return atomic64_sub_return(1, ptr);
-}
-EXPORT_SYMBOL(atomic64_dec_return);
-
-/**
- * atomic64_add - add integer to atomic64 variable
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically adds @delta to @ptr.
- */
-void atomic64_add(u64 delta, atomic64_t *ptr)
-{
-       atomic64_add_return(delta, ptr);
-}
-EXPORT_SYMBOL(atomic64_add);
-
-/**
- * atomic64_sub - subtract the atomic64 variable
- * @delta: integer value to subtract
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically subtracts @delta from @ptr.
- */
-void atomic64_sub(u64 delta, atomic64_t *ptr)
-{
-       atomic64_add(-delta, ptr);
-}
-EXPORT_SYMBOL(atomic64_sub);
-
-/**
- * atomic64_sub_and_test - subtract value from variable and test result
- * @delta: integer value to subtract
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically subtracts @delta from @ptr and returns
- * true if the result is zero, or false for all
- * other cases.
- */
-int atomic64_sub_and_test(u64 delta, atomic64_t *ptr)
-{
-       u64 new_val = atomic64_sub_return(delta, ptr);
-
-       return new_val == 0;
-}
-EXPORT_SYMBOL(atomic64_sub_and_test);
-
-/**
- * atomic64_inc - increment atomic64 variable
- * @ptr: pointer to type atomic64_t
- *
- * Atomically increments @ptr by 1.
- */
-void atomic64_inc(atomic64_t *ptr)
-{
-       atomic64_add(1, ptr);
-}
-EXPORT_SYMBOL(atomic64_inc);
-
-/**
- * atomic64_dec - decrement atomic64 variable
- * @ptr: pointer to type atomic64_t
- *
- * Atomically decrements @ptr by 1.
- */
-void atomic64_dec(atomic64_t *ptr)
-{
-       atomic64_sub(1, ptr);
-}
-EXPORT_SYMBOL(atomic64_dec);
-
-/**
- * atomic64_dec_and_test - decrement and test
- * @ptr: pointer to type atomic64_t
- *
- * Atomically decrements @ptr by 1 and
- * returns true if the result is 0, or false for all other
- * cases.
- */
-int atomic64_dec_and_test(atomic64_t *ptr)
-{
-       return atomic64_sub_and_test(1, ptr);
-}
-EXPORT_SYMBOL(atomic64_dec_and_test);
-
-/**
- * atomic64_inc_and_test - increment and test
- * @ptr: pointer to type atomic64_t
- *
- * Atomically increments @ptr by 1
- * and returns true if the result is zero, or false for all
- * other cases.
- */
-int atomic64_inc_and_test(atomic64_t *ptr)
-{
-       return atomic64_sub_and_test(-1, ptr);
-}
-EXPORT_SYMBOL(atomic64_inc_and_test);
-
-/**
- * atomic64_add_negative - add and test if negative
- * @delta: integer value to add
- * @ptr:   pointer to type atomic64_t
- *
- * Atomically adds @delta to @ptr and returns true
- * if the result is negative, or false when
- * result is greater than or equal to zero.
- */
-int atomic64_add_negative(u64 delta, atomic64_t *ptr)
-{
-       s64 new_val = atomic64_add_return(delta, ptr);
-
-       return new_val < 0;
-}
-EXPORT_SYMBOL(atomic64_add_negative);
+long long atomic64_read_cx8(long long, const atomic64_t *v);
+EXPORT_SYMBOL(atomic64_read_cx8);
+long long atomic64_set_cx8(long long, const atomic64_t *v);
+EXPORT_SYMBOL(atomic64_set_cx8);
+long long atomic64_xchg_cx8(long long, unsigned high);
+EXPORT_SYMBOL(atomic64_xchg_cx8);
+long long atomic64_add_return_cx8(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_add_return_cx8);
+long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_sub_return_cx8);
+long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_inc_return_cx8);
+long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_dec_return_cx8);
+long long atomic64_dec_if_positive_cx8(atomic64_t *v);
+EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
+int atomic64_inc_not_zero_cx8(atomic64_t *v);
+EXPORT_SYMBOL(atomic64_inc_not_zero_cx8);
+int atomic64_add_unless_cx8(atomic64_t *v, long long a, long long u);
+EXPORT_SYMBOL(atomic64_add_unless_cx8);
+
+#ifndef CONFIG_X86_CMPXCHG64
+long long atomic64_read_386(long long, const atomic64_t *v);
+EXPORT_SYMBOL(atomic64_read_386);
+long long atomic64_set_386(long long, const atomic64_t *v);
+EXPORT_SYMBOL(atomic64_set_386);
+long long atomic64_xchg_386(long long, unsigned high);
+EXPORT_SYMBOL(atomic64_xchg_386);
+long long atomic64_add_return_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_add_return_386);
+long long atomic64_sub_return_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_sub_return_386);
+long long atomic64_inc_return_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_inc_return_386);
+long long atomic64_dec_return_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_dec_return_386);
+long long atomic64_add_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_add_386);
+long long atomic64_sub_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_sub_386);
+long long atomic64_inc_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_inc_386);
+long long atomic64_dec_386(long long a, atomic64_t *v);
+EXPORT_SYMBOL(atomic64_dec_386);
+long long atomic64_dec_if_positive_386(atomic64_t *v);
+EXPORT_SYMBOL(atomic64_dec_if_positive_386);
+int atomic64_inc_not_zero_386(atomic64_t *v);
+EXPORT_SYMBOL(atomic64_inc_not_zero_386);
+int atomic64_add_unless_386(atomic64_t *v, long long a, long long u);
+EXPORT_SYMBOL(atomic64_add_unless_386);
+#endif
diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
new file mode 100644 (file)
index 0000000..4a5979a
--- /dev/null
@@ -0,0 +1,174 @@
+/*
+ * atomic64_t for 386/486
+ *
+ * Copyright Â© 2010  Luca Barbieri
+ *
+ * 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/alternative-asm.h>
+#include <asm/dwarf2.h>
+
+/* if you want SMP support, implement these with real spinlocks */
+.macro LOCK reg
+       pushfl
+       CFI_ADJUST_CFA_OFFSET 4
+       cli
+.endm
+
+.macro UNLOCK reg
+       popfl
+       CFI_ADJUST_CFA_OFFSET -4
+.endm
+
+.macro BEGIN func reg
+$v = \reg
+
+ENTRY(atomic64_\func\()_386)
+       CFI_STARTPROC
+       LOCK $v
+
+.macro RETURN
+       UNLOCK $v
+       ret
+.endm
+
+.macro END_
+       CFI_ENDPROC
+ENDPROC(atomic64_\func\()_386)
+.purgem RETURN
+.purgem END_
+.purgem END
+.endm
+
+.macro END
+RETURN
+END_
+.endm
+.endm
+
+BEGIN read %ecx
+       movl  ($v), %eax
+       movl 4($v), %edx
+END
+
+BEGIN set %esi
+       movl %ebx,  ($v)
+       movl %ecx, 4($v)
+END
+
+BEGIN xchg %esi
+       movl  ($v), %eax
+       movl 4($v), %edx
+       movl %ebx,  ($v)
+       movl %ecx, 4($v)
+END
+
+BEGIN add %ecx
+       addl %eax,  ($v)
+       adcl %edx, 4($v)
+END
+
+BEGIN add_return %ecx
+       addl  ($v), %eax
+       adcl 4($v), %edx
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+END
+
+BEGIN sub %ecx
+       subl %eax,  ($v)
+       sbbl %edx, 4($v)
+END
+
+BEGIN sub_return %ecx
+       negl %edx
+       negl %eax
+       sbbl $0, %edx
+       addl  ($v), %eax
+       adcl 4($v), %edx
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+END
+
+BEGIN inc %esi
+       addl $1,  ($v)
+       adcl $0, 4($v)
+END
+
+BEGIN inc_return %esi
+       movl  ($v), %eax
+       movl 4($v), %edx
+       addl $1, %eax
+       adcl $0, %edx
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+END
+
+BEGIN dec %esi
+       subl $1,  ($v)
+       sbbl $0, 4($v)
+END
+
+BEGIN dec_return %esi
+       movl  ($v), %eax
+       movl 4($v), %edx
+       subl $1, %eax
+       sbbl $0, %edx
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+END
+
+BEGIN add_unless %ecx
+       addl %eax, %esi
+       adcl %edx, %edi
+       addl  ($v), %eax
+       adcl 4($v), %edx
+       cmpl %eax, %esi
+       je 3f
+1:
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+       movl $1, %eax
+2:
+RETURN
+3:
+       cmpl %edx, %edi
+       jne 1b
+       xorl %eax, %eax
+       jmp 2b
+END_
+
+BEGIN inc_not_zero %esi
+       movl  ($v), %eax
+       movl 4($v), %edx
+       testl %eax, %eax
+       je 3f
+1:
+       addl $1, %eax
+       adcl $0, %edx
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+       movl $1, %eax
+2:
+RETURN
+3:
+       testl %edx, %edx
+       jne 1b
+       jmp 2b
+END_
+
+BEGIN dec_if_positive %esi
+       movl  ($v), %eax
+       movl 4($v), %edx
+       subl $1, %eax
+       sbbl $0, %edx
+       js 1f
+       movl %eax,  ($v)
+       movl %edx, 4($v)
+1:
+END
diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
new file mode 100644 (file)
index 0000000..71e080d
--- /dev/null
@@ -0,0 +1,224 @@
+/*
+ * atomic64_t for 586+
+ *
+ * Copyright Â© 2010  Luca Barbieri
+ *
+ * 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.
+ */
+
+#include <linux/linkage.h>
+#include <asm/alternative-asm.h>
+#include <asm/dwarf2.h>
+
+.macro SAVE reg
+       pushl %\reg
+       CFI_ADJUST_CFA_OFFSET 4
+       CFI_REL_OFFSET \reg, 0
+.endm
+
+.macro RESTORE reg
+       popl %\reg
+       CFI_ADJUST_CFA_OFFSET -4
+       CFI_RESTORE \reg
+.endm
+
+.macro read64 reg
+       movl %ebx, %eax
+       movl %ecx, %edx
+/* we need LOCK_PREFIX since otherwise cmpxchg8b always does the write */
+       LOCK_PREFIX
+       cmpxchg8b (\reg)
+.endm
+
+ENTRY(atomic64_read_cx8)
+       CFI_STARTPROC
+
+       read64 %ecx
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_read_cx8)
+
+ENTRY(atomic64_set_cx8)
+       CFI_STARTPROC
+
+1:
+/* we don't need LOCK_PREFIX since aligned 64-bit writes
+ * are atomic on 586 and newer */
+       cmpxchg8b (%esi)
+       jne 1b
+
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_set_cx8)
+
+ENTRY(atomic64_xchg_cx8)
+       CFI_STARTPROC
+
+       movl %ebx, %eax
+       movl %ecx, %edx
+1:
+       LOCK_PREFIX
+       cmpxchg8b (%esi)
+       jne 1b
+
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_xchg_cx8)
+
+.macro addsub_return func ins insc
+ENTRY(atomic64_\func\()_return_cx8)
+       CFI_STARTPROC
+       SAVE ebp
+       SAVE ebx
+       SAVE esi
+       SAVE edi
+
+       movl %eax, %esi
+       movl %edx, %edi
+       movl %ecx, %ebp
+
+       read64 %ebp
+1:
+       movl %eax, %ebx
+       movl %edx, %ecx
+       \ins\()l %esi, %ebx
+       \insc\()l %edi, %ecx
+       LOCK_PREFIX
+       cmpxchg8b (%ebp)
+       jne 1b
+
+10:
+       movl %ebx, %eax
+       movl %ecx, %edx
+       RESTORE edi
+       RESTORE esi
+       RESTORE ebx
+       RESTORE ebp
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_\func\()_return_cx8)
+.endm
+
+addsub_return add add adc
+addsub_return sub sub sbb
+
+.macro incdec_return func ins insc
+ENTRY(atomic64_\func\()_return_cx8)
+       CFI_STARTPROC
+       SAVE ebx
+
+       read64 %esi
+1:
+       movl %eax, %ebx
+       movl %edx, %ecx
+       \ins\()l $1, %ebx
+       \insc\()l $0, %ecx
+       LOCK_PREFIX
+       cmpxchg8b (%esi)
+       jne 1b
+
+10:
+       movl %ebx, %eax
+       movl %ecx, %edx
+       RESTORE ebx
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_\func\()_return_cx8)
+.endm
+
+incdec_return inc add adc
+incdec_return dec sub sbb
+
+ENTRY(atomic64_dec_if_positive_cx8)
+       CFI_STARTPROC
+       SAVE ebx
+
+       read64 %esi
+1:
+       movl %eax, %ebx
+       movl %edx, %ecx
+       subl $1, %ebx
+       sbb $0, %ecx
+       js 2f
+       LOCK_PREFIX
+       cmpxchg8b (%esi)
+       jne 1b
+
+2:
+       movl %ebx, %eax
+       movl %ecx, %edx
+       RESTORE ebx
+       ret
+       CFI_ENDPROC
+ENDPROC(atomic64_dec_if_positive_cx8)
+
+ENTRY(atomic64_add_unless_cx8)
+       CFI_STARTPROC
+       SAVE ebp
+       SAVE ebx
+/* these just push these two parameters on the stack */
+       SAVE edi
+       SAVE esi
+
+       movl %ecx, %ebp
+       movl %eax, %esi
+       movl %edx, %edi
+
+       read64 %ebp
+1:
+       cmpl %eax, 0(%esp)
+       je 4f
+2:
+       movl %eax, %ebx
+       movl %edx, %ecx
+       addl %esi, %ebx
+       adcl %edi, %ecx
+       LOCK_PREFIX
+       cmpxchg8b (%ebp)
+       jne 1b
+
+       movl $1, %eax
+3:
+       addl $8, %esp
+       CFI_ADJUST_CFA_OFFSET -8
+       RESTORE ebx
+       RESTORE ebp
+       ret
+4:
+       cmpl %edx, 4(%esp)
+       jne 2b
+       xorl %eax, %eax
+       jmp 3b
+       CFI_ENDPROC
+ENDPROC(atomic64_add_unless_cx8)
+
+ENTRY(atomic64_inc_not_zero_cx8)
+       CFI_STARTPROC
+       SAVE ebx
+
+       read64 %esi
+1:
+       testl %eax, %eax
+       je 4f
+2:
+       movl %eax, %ebx
+       movl %edx, %ecx
+       addl $1, %ebx
+       adcl $0, %ecx
+       LOCK_PREFIX
+       cmpxchg8b (%esi)
+       jne 1b
+
+       movl $1, %eax
+3:
+       RESTORE ebx
+       ret
+4:
+       testl %edx, %edx
+       jne 2b
+       jmp 3b
+       CFI_ENDPROC
+ENDPROC(atomic64_inc_not_zero_cx8)
index aa09870..dc8adad 100644 (file)
@@ -30,10 +30,10 @@ static void fclex(void)
 }
 
 /* Needs to be externally visible */
-void finit_task(struct task_struct *tsk)
+void finit_soft_fpu(struct i387_soft_struct *soft)
 {
-       struct i387_soft_struct *soft = &tsk->thread.xstate->soft;
        struct address *oaddr, *iaddr;
+       memset(soft, 0, sizeof(*soft));
        soft->cwd = 0x037f;
        soft->swd = 0;
        soft->ftop = 0; /* We don't keep top in the status word internally. */
@@ -52,7 +52,7 @@ void finit_task(struct task_struct *tsk)
 
 void finit(void)
 {
-       finit_task(current);
+       finit_soft_fpu(&current->thread.fpu.state->soft);
 }
 
 /*
index 5d87f58..7718541 100644 (file)
@@ -681,7 +681,7 @@ int fpregs_soft_set(struct task_struct *target,
                    unsigned int pos, unsigned int count,
                    const void *kbuf, const void __user *ubuf)
 {
-       struct i387_soft_struct *s387 = &target->thread.xstate->soft;
+       struct i387_soft_struct *s387 = &target->thread.fpu.state->soft;
        void *space = s387->st_space;
        int ret;
        int offset, other, i, tags, regnr, tag, newtop;
@@ -733,7 +733,7 @@ int fpregs_soft_get(struct task_struct *target,
                    unsigned int pos, unsigned int count,
                    void *kbuf, void __user *ubuf)
 {
-       struct i387_soft_struct *s387 = &target->thread.xstate->soft;
+       struct i387_soft_struct *s387 = &target->thread.fpu.state->soft;
        const void *space = s387->st_space;
        int ret;
        int offset = (S387->ftop & 7) * 10, other = 80 - offset;
index 50fa0ec..2c61441 100644 (file)
@@ -31,7 +31,7 @@
 #define SEG_EXPAND_DOWN(s)     (((s).b & ((1 << 11) | (1 << 10))) \
                                 == (1 << 10))
 
-#define I387                   (current->thread.xstate)
+#define I387                   (current->thread.fpu.state)
 #define FPU_info               (I387->soft.info)
 
 #define FPU_CS                 (*(unsigned short *) &(FPU_info->regs->cs))
index 06630d2..a4c7683 100644 (file)
@@ -6,6 +6,7 @@ nostackp := $(call cc-option, -fno-stack-protector)
 CFLAGS_physaddr.o              := $(nostackp)
 CFLAGS_setup_nx.o              := $(nostackp)
 
+obj-$(CONFIG_X86_PAT)          += pat_rbtree.o
 obj-$(CONFIG_SMP)              += tlb.o
 
 obj-$(CONFIG_X86_32)           += pgtable_32.o iomap_32.o
index edc8b95..bbe5502 100644 (file)
@@ -30,6 +30,8 @@
 #include <asm/pat.h>
 #include <asm/io.h>
 
+#include "pat_internal.h"
+
 #ifdef CONFIG_X86_PAT
 int __read_mostly pat_enabled = 1;
 
@@ -53,19 +55,15 @@ static inline void pat_disable(const char *reason)
 #endif
 
 
-static int debug_enable;
+int pat_debug_enable;
 
 static int __init pat_debug_setup(char *str)
 {
-       debug_enable = 1;
+       pat_debug_enable = 1;
        return 0;
 }
 __setup("debugpat", pat_debug_setup);
 
-#define dprintk(fmt, arg...) \
-       do { if (debug_enable) printk(KERN_INFO fmt, ##arg); } while (0)
-
-
 static u64 __read_mostly boot_pat_state;
 
 enum {
@@ -132,84 +130,7 @@ void pat_init(void)
 
 #undef PAT
 
-static char *cattr_name(unsigned long flags)
-{
-       switch (flags & _PAGE_CACHE_MASK) {
-       case _PAGE_CACHE_UC:            return "uncached";
-       case _PAGE_CACHE_UC_MINUS:      return "uncached-minus";
-       case _PAGE_CACHE_WB:            return "write-back";
-       case _PAGE_CACHE_WC:            return "write-combining";
-       default:                        return "broken";
-       }
-}
-
-/*
- * The global memtype list keeps track of memory type for specific
- * physical memory areas. Conflicting memory types in different
- * mappings can cause CPU cache corruption. To avoid this we keep track.
- *
- * The list is sorted based on starting address and can contain multiple
- * entries for each address (this allows reference counting for overlapping
- * areas). All the aliases have the same cache attributes of course.
- * Zero attributes are represented as holes.
- *
- * The data structure is a list that is also organized as an rbtree
- * sorted on the start address of memtype range.
- *
- * memtype_lock protects both the linear list and rbtree.
- */
-
-struct memtype {
-       u64                     start;
-       u64                     end;
-       unsigned long           type;
-       struct list_head        nd;
-       struct rb_node          rb;
-};
-
-static struct rb_root memtype_rbroot = RB_ROOT;
-static LIST_HEAD(memtype_list);
-static DEFINE_SPINLOCK(memtype_lock);  /* protects memtype list */
-
-static struct memtype *memtype_rb_search(struct rb_root *root, u64 start)
-{
-       struct rb_node *node = root->rb_node;
-       struct memtype *last_lower = NULL;
-
-       while (node) {
-               struct memtype *data = container_of(node, struct memtype, rb);
-
-               if (data->start < start) {
-                       last_lower = data;
-                       node = node->rb_right;
-               } else if (data->start > start) {
-                       node = node->rb_left;
-               } else
-                       return data;
-       }
-
-       /* Will return NULL if there is no entry with its start <= start */
-       return last_lower;
-}
-
-static void memtype_rb_insert(struct rb_root *root, struct memtype *data)
-{
-       struct rb_node **new = &(root->rb_node);
-       struct rb_node *parent = NULL;
-
-       while (*new) {
-               struct memtype *this = container_of(*new, struct memtype, rb);
-
-               parent = *new;
-               if (data->start <= this->start)
-                       new = &((*new)->rb_left);
-               else if (data->start > this->start)
-                       new = &((*new)->rb_right);
-       }
-
-       rb_link_node(&data->rb, parent, new);
-       rb_insert_color(&data->rb, root);
-}
+static DEFINE_SPINLOCK(memtype_lock);  /* protects memtype accesses */
 
 /*
  * Does intersection of PAT memory type and MTRR memory type and returns
@@ -237,33 +158,6 @@ static unsigned long pat_x_mtrr_type(u64 start, u64 end, unsigned long req_type)
        return req_type;
 }
 
-static int
-chk_conflict(struct memtype *new, struct memtype *entry, unsigned long *type)
-{
-       if (new->type != entry->type) {
-               if (type) {
-                       new->type = entry->type;
-                       *type = entry->type;
-               } else
-                       goto conflict;
-       }
-
-        /* check overlaps with more than one entry in the list */
-       list_for_each_entry_continue(entry, &memtype_list, nd) {
-               if (new->end <= entry->start)
-                       break;
-               else if (new->type != entry->type)
-                       goto conflict;
-       }
-       return 0;
-
- conflict:
-       printk(KERN_INFO "%s:%d conflicting memory types "
-              "%Lx-%Lx %s<->%s\n", current->comm, current->pid, new->start,
-              new->end, cattr_name(new->type), cattr_name(entry->type));
-       return -EBUSY;
-}
-
 static int pat_pagerange_is_ram(unsigned long start, unsigned long end)
 {
        int ram_page = 0, not_rampage = 0;
@@ -296,8 +190,6 @@ static int pat_pagerange_is_ram(unsigned long start, unsigned long end)
  * Here we do two pass:
  * - Find the memtype of all the pages in the range, look for any conflicts
  * - In case of no conflicts, set the new memtype for pages in the range
- *
- * Caller must hold memtype_lock for atomicity.
  */
 static int reserve_ram_pages_type(u64 start, u64 end, unsigned long req_type,
                                  unsigned long *new_type)
@@ -364,9 +256,8 @@ static int free_ram_pages_type(u64 start, u64 end)
 int reserve_memtype(u64 start, u64 end, unsigned long req_type,
                    unsigned long *new_type)
 {
-       struct memtype *new, *entry;
+       struct memtype *new;
        unsigned long actual_type;
-       struct list_head *where;
        int is_range_ram;
        int err = 0;
 
@@ -404,9 +295,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
        is_range_ram = pat_pagerange_is_ram(start, end);
        if (is_range_ram == 1) {
 
-               spin_lock(&memtype_lock);
                err = reserve_ram_pages_type(start, end, req_type, new_type);
-               spin_unlock(&memtype_lock);
 
                return err;
        } else if (is_range_ram < 0) {
@@ -423,42 +312,7 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
 
        spin_lock(&memtype_lock);
 
-       /* Search for existing mapping that overlaps the current range */
-       where = NULL;
-       list_for_each_entry(entry, &memtype_list, nd) {
-               if (end <= entry->start) {
-                       where = entry->nd.prev;
-                       break;
-               } else if (start <= entry->start) { /* end > entry->start */
-                       err = chk_conflict(new, entry, new_type);
-                       if (!err) {
-                               dprintk("Overlap at 0x%Lx-0x%Lx\n",
-                                       entry->start, entry->end);
-                               where = entry->nd.prev;
-                       }
-                       break;
-               } else if (start < entry->end) { /* start > entry->start */
-                       err = chk_conflict(new, entry, new_type);
-                       if (!err) {
-                               dprintk("Overlap at 0x%Lx-0x%Lx\n",
-                                       entry->start, entry->end);
-
-                               /*
-                                * Move to right position in the linked
-                                * list to add this new entry
-                                */
-                               list_for_each_entry_continue(entry,
-                                                       &memtype_list, nd) {
-                                       if (start <= entry->start) {
-                                               where = entry->nd.prev;
-                                               break;
-                                       }
-                               }
-                       }
-                       break;
-               }
-       }
-
+       err = rbt_memtype_check_insert(new, new_type);
        if (err) {
                printk(KERN_INFO "reserve_memtype failed 0x%Lx-0x%Lx, "
                       "track %s, req %s\n",
@@ -469,13 +323,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
                return err;
        }
 
-       if (where)
-               list_add(&new->nd, where);
-       else
-               list_add_tail(&new->nd, &memtype_list);
-
-       memtype_rb_insert(&memtype_rbroot, new);
-
        spin_unlock(&memtype_lock);
 
        dprintk("reserve_memtype added 0x%Lx-0x%Lx, track %s, req %s, ret %s\n",
@@ -487,7 +334,6 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
 
 int free_memtype(u64 start, u64 end)
 {
-       struct memtype *entry, *saved_entry;
        int err = -EINVAL;
        int is_range_ram;
 
@@ -501,9 +347,7 @@ int free_memtype(u64 start, u64 end)
        is_range_ram = pat_pagerange_is_ram(start, end);
        if (is_range_ram == 1) {
 
-               spin_lock(&memtype_lock);
                err = free_ram_pages_type(start, end);
-               spin_unlock(&memtype_lock);
 
                return err;
        } else if (is_range_ram < 0) {
@@ -511,46 +355,7 @@ int free_memtype(u64 start, u64 end)
        }
 
        spin_lock(&memtype_lock);
-
-       entry = memtype_rb_search(&memtype_rbroot, start);
-       if (unlikely(entry == NULL))
-               goto unlock_ret;
-
-       /*
-        * Saved entry points to an entry with start same or less than what
-        * we searched for. Now go through the list in both directions to look
-        * for the entry that matches with both start and end, with list stored
-        * in sorted start address
-        */
-       saved_entry = entry;
-       list_for_each_entry_from(entry, &memtype_list, nd) {
-               if (entry->start == start && entry->end == end) {
-                       rb_erase(&entry->rb, &memtype_rbroot);
-                       list_del(&entry->nd);
-                       kfree(entry);
-                       err = 0;
-                       break;
-               } else if (entry->start > start) {
-                       break;
-               }
-       }
-
-       if (!err)
-               goto unlock_ret;
-
-       entry = saved_entry;
-       list_for_each_entry_reverse(entry, &memtype_list, nd) {
-               if (entry->start == start && entry->end == end) {
-                       rb_erase(&entry->rb, &memtype_rbroot);
-                       list_del(&entry->nd);
-                       kfree(entry);
-                       err = 0;
-                       break;
-               } else if (entry->start < start) {
-                       break;
-               }
-       }
-unlock_ret:
+       err = rbt_memtype_erase(start, end);
        spin_unlock(&memtype_lock);
 
        if (err) {
@@ -583,10 +388,8 @@ static unsigned long lookup_memtype(u64 paddr)
 
        if (pat_pagerange_is_ram(paddr, paddr + PAGE_SIZE)) {
                struct page *page;
-               spin_lock(&memtype_lock);
                page = pfn_to_page(paddr >> PAGE_SHIFT);
                rettype = get_page_memtype(page);
-               spin_unlock(&memtype_lock);
                /*
                 * -1 from get_page_memtype() implies RAM page is in its
                 * default state and not reserved, and hence of type WB
@@ -599,7 +402,7 @@ static unsigned long lookup_memtype(u64 paddr)
 
        spin_lock(&memtype_lock);
 
-       entry = memtype_rb_search(&memtype_rbroot, paddr);
+       entry = rbt_memtype_lookup(paddr);
        if (entry != NULL)
                rettype = entry->type;
        else
@@ -936,29 +739,25 @@ EXPORT_SYMBOL_GPL(pgprot_writecombine);
 
 #if defined(CONFIG_DEBUG_FS) && defined(CONFIG_X86_PAT)
 
-/* get Nth element of the linked list */
 static struct memtype *memtype_get_idx(loff_t pos)
 {
-       struct memtype *list_node, *print_entry;
-       int i = 1;
+       struct memtype *print_entry;
+       int ret;
 
-       print_entry  = kmalloc(sizeof(struct memtype), GFP_KERNEL);
+       print_entry  = kzalloc(sizeof(struct memtype), GFP_KERNEL);
        if (!print_entry)
                return NULL;
 
        spin_lock(&memtype_lock);
-       list_for_each_entry(list_node, &memtype_list, nd) {
-               if (pos == i) {
-                       *print_entry = *list_node;
-                       spin_unlock(&memtype_lock);
-                       return print_entry;
-               }
-               ++i;
-       }
+       ret = rbt_memtype_copy_nth_element(print_entry, pos);
        spin_unlock(&memtype_lock);
-       kfree(print_entry);
 
-       return NULL;
+       if (!ret) {
+               return print_entry;
+       } else {
+               kfree(print_entry);
+               return NULL;
+       }
 }
 
 static void *memtype_seq_start(struct seq_file *seq, loff_t *pos)
diff --git a/arch/x86/mm/pat_internal.h b/arch/x86/mm/pat_internal.h
new file mode 100644 (file)
index 0000000..4f39eef
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __PAT_INTERNAL_H_
+#define __PAT_INTERNAL_H_
+
+extern int pat_debug_enable;
+
+#define dprintk(fmt, arg...) \
+       do { if (pat_debug_enable) printk(KERN_INFO fmt, ##arg); } while (0)
+
+struct memtype {
+       u64                     start;
+       u64                     end;
+       u64                     subtree_max_end;
+       unsigned long           type;
+       struct rb_node          rb;
+};
+
+static inline char *cattr_name(unsigned long flags)
+{
+       switch (flags & _PAGE_CACHE_MASK) {
+       case _PAGE_CACHE_UC:            return "uncached";
+       case _PAGE_CACHE_UC_MINUS:      return "uncached-minus";
+       case _PAGE_CACHE_WB:            return "write-back";
+       case _PAGE_CACHE_WC:            return "write-combining";
+       default:                        return "broken";
+       }
+}
+
+#ifdef CONFIG_X86_PAT
+extern int rbt_memtype_check_insert(struct memtype *new,
+                                       unsigned long *new_type);
+extern int rbt_memtype_erase(u64 start, u64 end);
+extern struct memtype *rbt_memtype_lookup(u64 addr);
+extern int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos);
+#else
+static inline int rbt_memtype_check_insert(struct memtype *new,
+                                       unsigned long *new_type)
+{ return 0; }
+static inline int rbt_memtype_erase(u64 start, u64 end)
+{ return 0; }
+static inline struct memtype *rbt_memtype_lookup(u64 addr)
+{ return NULL; }
+static inline int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos)
+{ return 0; }
+#endif
+
+#endif /* __PAT_INTERNAL_H_ */
diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
new file mode 100644 (file)
index 0000000..07de4cb
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+ * Handle caching attributes in page tables (PAT)
+ *
+ * Authors: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
+ *          Suresh B Siddha <suresh.b.siddha@intel.com>
+ *
+ * Interval tree (augmented rbtree) used to store the PAT memory type
+ * reservations.
+ */
+
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/rbtree.h>
+#include <linux/sched.h>
+#include <linux/gfp.h>
+
+#include <asm/pgtable.h>
+#include <asm/pat.h>
+
+#include "pat_internal.h"
+
+/*
+ * The memtype tree keeps track of memory type for specific
+ * physical memory areas. Without proper tracking, conflicting memory
+ * types in different mappings can cause CPU cache corruption.
+ *
+ * The tree is an interval tree (augmented rbtree) with tree ordered
+ * on starting address. Tree can contain multiple entries for
+ * different regions which overlap. All the aliases have the same
+ * cache attributes of course.
+ *
+ * memtype_lock protects the rbtree.
+ */
+
+static void memtype_rb_augment_cb(struct rb_node *node);
+static struct rb_root memtype_rbroot = RB_AUGMENT_ROOT(&memtype_rb_augment_cb);
+
+static int is_node_overlap(struct memtype *node, u64 start, u64 end)
+{
+       if (node->start >= end || node->end <= start)
+               return 0;
+
+       return 1;
+}
+
+static u64 get_subtree_max_end(struct rb_node *node)
+{
+       u64 ret = 0;
+       if (node) {
+               struct memtype *data = container_of(node, struct memtype, rb);
+               ret = data->subtree_max_end;
+       }
+       return ret;
+}
+
+/* Update 'subtree_max_end' for a node, based on node and its children */
+static void update_node_max_end(struct rb_node *node)
+{
+       struct memtype *data;
+       u64 max_end, child_max_end;
+
+       if (!node)
+               return;
+
+       data = container_of(node, struct memtype, rb);
+       max_end = data->end;
+
+       child_max_end = get_subtree_max_end(node->rb_right);
+       if (child_max_end > max_end)
+               max_end = child_max_end;
+
+       child_max_end = get_subtree_max_end(node->rb_left);
+       if (child_max_end > max_end)
+               max_end = child_max_end;
+
+       data->subtree_max_end = max_end;
+}
+
+/* Update 'subtree_max_end' for a node and all its ancestors */
+static void update_path_max_end(struct rb_node *node)
+{
+       u64 old_max_end, new_max_end;
+
+       while (node) {
+               struct memtype *data = container_of(node, struct memtype, rb);
+
+               old_max_end = data->subtree_max_end;
+               update_node_max_end(node);
+               new_max_end = data->subtree_max_end;
+
+               if (new_max_end == old_max_end)
+                       break;
+
+               node = rb_parent(node);
+       }
+}
+
+/* Find the first (lowest start addr) overlapping range from rb tree */
+static struct memtype *memtype_rb_lowest_match(struct rb_root *root,
+                               u64 start, u64 end)
+{
+       struct rb_node *node = root->rb_node;
+       struct memtype *last_lower = NULL;
+
+       while (node) {
+               struct memtype *data = container_of(node, struct memtype, rb);
+
+               if (get_subtree_max_end(node->rb_left) > start) {
+                       /* Lowest overlap if any must be on left side */
+                       node = node->rb_left;
+               } else if (is_node_overlap(data, start, end)) {
+                       last_lower = data;
+                       break;
+               } else if (start >= data->start) {
+                       /* Lowest overlap if any must be on right side */
+                       node = node->rb_right;
+               } else {
+                       break;
+               }
+       }
+       return last_lower; /* Returns NULL if there is no overlap */
+}
+
+static struct memtype *memtype_rb_exact_match(struct rb_root *root,
+                               u64 start, u64 end)
+{
+       struct memtype *match;
+
+       match = memtype_rb_lowest_match(root, start, end);
+       while (match != NULL && match->start < end) {
+               struct rb_node *node;
+
+               if (match->start == start && match->end == end)
+                       return match;
+
+               node = rb_next(&match->rb);
+               if (node)
+                       match = container_of(node, struct memtype, rb);
+               else
+                       match = NULL;
+       }
+
+       return NULL; /* Returns NULL if there is no exact match */
+}
+
+static int memtype_rb_check_conflict(struct rb_root *root,
+                               u64 start, u64 end,
+                               unsigned long reqtype, unsigned long *newtype)
+{
+       struct rb_node *node;
+       struct memtype *match;
+       int found_type = reqtype;
+
+       match = memtype_rb_lowest_match(&memtype_rbroot, start, end);
+       if (match == NULL)
+               goto success;
+
+       if (match->type != found_type && newtype == NULL)
+               goto failure;
+
+       dprintk("Overlap at 0x%Lx-0x%Lx\n", match->start, match->end);
+       found_type = match->type;
+
+       node = rb_next(&match->rb);
+       while (node) {
+               match = container_of(node, struct memtype, rb);
+
+               if (match->start >= end) /* Checked all possible matches */
+                       goto success;
+
+               if (is_node_overlap(match, start, end) &&
+                   match->type != found_type) {
+                       goto failure;
+               }
+
+               node = rb_next(&match->rb);
+       }
+success:
+       if (newtype)
+               *newtype = found_type;
+
+       return 0;
+
+failure:
+       printk(KERN_INFO "%s:%d conflicting memory types "
+               "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
+               end, cattr_name(found_type), cattr_name(match->type));
+       return -EBUSY;
+}
+
+static void memtype_rb_augment_cb(struct rb_node *node)
+{
+       if (node)
+               update_path_max_end(node);
+}
+
+static void memtype_rb_insert(struct rb_root *root, struct memtype *newdata)
+{
+       struct rb_node **node = &(root->rb_node);
+       struct rb_node *parent = NULL;
+
+       while (*node) {
+               struct memtype *data = container_of(*node, struct memtype, rb);
+
+               parent = *node;
+               if (newdata->start <= data->start)
+                       node = &((*node)->rb_left);
+               else if (newdata->start > data->start)
+                       node = &((*node)->rb_right);
+       }
+
+       rb_link_node(&newdata->rb, parent, node);
+       rb_insert_color(&newdata->rb, root);
+}
+
+int rbt_memtype_check_insert(struct memtype *new, unsigned long *ret_type)
+{
+       int err = 0;
+
+       err = memtype_rb_check_conflict(&memtype_rbroot, new->start, new->end,
+                                               new->type, ret_type);
+
+       if (!err) {
+               if (ret_type)
+                       new->type = *ret_type;
+
+               memtype_rb_insert(&memtype_rbroot, new);
+       }
+       return err;
+}
+
+int rbt_memtype_erase(u64 start, u64 end)
+{
+       struct memtype *data;
+
+       data = memtype_rb_exact_match(&memtype_rbroot, start, end);
+       if (!data)
+               return -EINVAL;
+
+       rb_erase(&data->rb, &memtype_rbroot);
+       return 0;
+}
+
+struct memtype *rbt_memtype_lookup(u64 addr)
+{
+       struct memtype *data;
+       data = memtype_rb_lowest_match(&memtype_rbroot, addr, addr + PAGE_SIZE);
+       return data;
+}
+
+#if defined(CONFIG_DEBUG_FS)
+int rbt_memtype_copy_nth_element(struct memtype *out, loff_t pos)
+{
+       struct rb_node *node;
+       int i = 1;
+
+       node = rb_first(&memtype_rbroot);
+       while (node && pos != i) {
+               node = rb_next(node);
+               i++;
+       }
+
+       if (node) { /* pos == i */
+               struct memtype *this = container_of(node, struct memtype, rb);
+               *out = *this;
+               return 0;
+       } else {
+               return 1;
+       }
+}
+#endif
index 38512d0..f9897f7 100644 (file)
@@ -363,6 +363,54 @@ int __init acpi_scan_nodes(unsigned long start, unsigned long end)
        for (i = 0; i < MAX_NUMNODES; i++)
                cutoff_node(i, start, end);
 
+       /*
+        * Join together blocks on the same node, holes between
+        * which don't overlap with memory on other nodes.
+        */
+       for (i = 0; i < num_node_memblks; ++i) {
+               int j, k;
+
+               for (j = i + 1; j < num_node_memblks; ++j) {
+                       unsigned long start, end;
+
+                       if (memblk_nodeid[i] != memblk_nodeid[j])
+                               continue;
+                       start = min(node_memblk_range[i].end,
+                                   node_memblk_range[j].end);
+                       end = max(node_memblk_range[i].start,
+                                 node_memblk_range[j].start);
+                       for (k = 0; k < num_node_memblks; ++k) {
+                               if (memblk_nodeid[i] == memblk_nodeid[k])
+                                       continue;
+                               if (start < node_memblk_range[k].end &&
+                                   end > node_memblk_range[k].start)
+                                       break;
+                       }
+                       if (k < num_node_memblks)
+                               continue;
+                       start = min(node_memblk_range[i].start,
+                                   node_memblk_range[j].start);
+                       end = max(node_memblk_range[i].end,
+                                 node_memblk_range[j].end);
+                       printk(KERN_INFO "SRAT: Node %d "
+                              "[%Lx,%Lx) + [%Lx,%Lx) -> [%lx,%lx)\n",
+                              memblk_nodeid[i],
+                              node_memblk_range[i].start,
+                              node_memblk_range[i].end,
+                              node_memblk_range[j].start,
+                              node_memblk_range[j].end,
+                              start, end);
+                       node_memblk_range[i].start = start;
+                       node_memblk_range[i].end = end;
+                       k = --num_node_memblks - j;
+                       memmove(memblk_nodeid + j, memblk_nodeid + j+1,
+                               k * sizeof(*memblk_nodeid));
+                       memmove(node_memblk_range + j, node_memblk_range + j+1,
+                               k * sizeof(*node_memblk_range));
+                       --j;
+               }
+       }
+
        memnode_shift = compute_hash_shift(node_memblk_range, num_node_memblks,
                                           memblk_nodeid);
        if (memnode_shift < 0) {
index 2c505ee..b28d2f1 100644 (file)
@@ -31,8 +31,9 @@ static struct op_x86_model_spec *model;
 static DEFINE_PER_CPU(struct op_msrs, cpu_msrs);
 static DEFINE_PER_CPU(unsigned long, saved_lvtpc);
 
-/* 0 == registered but off, 1 == registered and on */
-static int nmi_enabled = 0;
+/* must be protected with get_online_cpus()/put_online_cpus(): */
+static int nmi_enabled;
+static int ctr_running;
 
 struct op_counter_config counter_config[OP_MAX_COUNTER];
 
@@ -61,12 +62,16 @@ static int profile_exceptions_notify(struct notifier_block *self,
 {
        struct die_args *args = (struct die_args *)data;
        int ret = NOTIFY_DONE;
-       int cpu = smp_processor_id();
 
        switch (val) {
        case DIE_NMI:
        case DIE_NMI_IPI:
-               model->check_ctrs(args->regs, &per_cpu(cpu_msrs, cpu));
+               if (ctr_running)
+                       model->check_ctrs(args->regs, &__get_cpu_var(cpu_msrs));
+               else if (!nmi_enabled)
+                       break;
+               else
+                       model->stop(&__get_cpu_var(cpu_msrs));
                ret = NOTIFY_STOP;
                break;
        default:
@@ -95,24 +100,36 @@ static void nmi_cpu_save_registers(struct op_msrs *msrs)
 static void nmi_cpu_start(void *dummy)
 {
        struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
-       model->start(msrs);
+       if (!msrs->controls)
+               WARN_ON_ONCE(1);
+       else
+               model->start(msrs);
 }
 
 static int nmi_start(void)
 {
+       get_online_cpus();
        on_each_cpu(nmi_cpu_start, NULL, 1);
+       ctr_running = 1;
+       put_online_cpus();
        return 0;
 }
 
 static void nmi_cpu_stop(void *dummy)
 {
        struct op_msrs const *msrs = &__get_cpu_var(cpu_msrs);
-       model->stop(msrs);
+       if (!msrs->controls)
+               WARN_ON_ONCE(1);
+       else
+               model->stop(msrs);
 }
 
 static void nmi_stop(void)
 {
+       get_online_cpus();
        on_each_cpu(nmi_cpu_stop, NULL, 1);
+       ctr_running = 0;
+       put_online_cpus();
 }
 
 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
@@ -252,7 +269,10 @@ static int nmi_switch_event(void)
        if (nmi_multiplex_on() < 0)
                return -EINVAL;         /* not necessary */
 
-       on_each_cpu(nmi_cpu_switch, NULL, 1);
+       get_online_cpus();
+       if (ctr_running)
+               on_each_cpu(nmi_cpu_switch, NULL, 1);
+       put_online_cpus();
 
        return 0;
 }
@@ -295,6 +315,7 @@ static void free_msrs(void)
                kfree(per_cpu(cpu_msrs, i).controls);
                per_cpu(cpu_msrs, i).controls = NULL;
        }
+       nmi_shutdown_mux();
 }
 
 static int allocate_msrs(void)
@@ -307,14 +328,21 @@ static int allocate_msrs(void)
                per_cpu(cpu_msrs, i).counters = kzalloc(counters_size,
                                                        GFP_KERNEL);
                if (!per_cpu(cpu_msrs, i).counters)
-                       return 0;
+                       goto fail;
                per_cpu(cpu_msrs, i).controls = kzalloc(controls_size,
                                                        GFP_KERNEL);
                if (!per_cpu(cpu_msrs, i).controls)
-                       return 0;
+                       goto fail;
        }
 
+       if (!nmi_setup_mux())
+               goto fail;
+
        return 1;
+
+fail:
+       free_msrs();
+       return 0;
 }
 
 static void nmi_cpu_setup(void *dummy)
@@ -336,49 +364,6 @@ static struct notifier_block profile_exceptions_nb = {
        .priority = 2
 };
 
-static int nmi_setup(void)
-{
-       int err = 0;
-       int cpu;
-
-       if (!allocate_msrs())
-               err = -ENOMEM;
-       else if (!nmi_setup_mux())
-               err = -ENOMEM;
-       else
-               err = register_die_notifier(&profile_exceptions_nb);
-
-       if (err) {
-               free_msrs();
-               nmi_shutdown_mux();
-               return err;
-       }
-
-       /* We need to serialize save and setup for HT because the subset
-        * of msrs are distinct for save and setup operations
-        */
-
-       /* Assume saved/restored counters are the same on all CPUs */
-       model->fill_in_addresses(&per_cpu(cpu_msrs, 0));
-       for_each_possible_cpu(cpu) {
-               if (!cpu)
-                       continue;
-
-               memcpy(per_cpu(cpu_msrs, cpu).counters,
-                      per_cpu(cpu_msrs, 0).counters,
-                      sizeof(struct op_msr) * model->num_counters);
-
-               memcpy(per_cpu(cpu_msrs, cpu).controls,
-                      per_cpu(cpu_msrs, 0).controls,
-                      sizeof(struct op_msr) * model->num_controls);
-
-               mux_clone(cpu);
-       }
-       on_each_cpu(nmi_cpu_setup, NULL, 1);
-       nmi_enabled = 1;
-       return 0;
-}
-
 static void nmi_cpu_restore_registers(struct op_msrs *msrs)
 {
        struct op_msr *counters = msrs->counters;
@@ -412,20 +397,24 @@ static void nmi_cpu_shutdown(void *dummy)
        apic_write(APIC_LVTPC, per_cpu(saved_lvtpc, cpu));
        apic_write(APIC_LVTERR, v);
        nmi_cpu_restore_registers(msrs);
+       if (model->cpu_down)
+               model->cpu_down();
 }
 
-static void nmi_shutdown(void)
+static void nmi_cpu_up(void *dummy)
 {
-       struct op_msrs *msrs;
+       if (nmi_enabled)
+               nmi_cpu_setup(dummy);
+       if (ctr_running)
+               nmi_cpu_start(dummy);
+}
 
-       nmi_enabled = 0;
-       on_each_cpu(nmi_cpu_shutdown, NULL, 1);
-       unregister_die_notifier(&profile_exceptions_nb);
-       nmi_shutdown_mux();
-       msrs = &get_cpu_var(cpu_msrs);
-       model->shutdown(msrs);
-       free_msrs();
-       put_cpu_var(cpu_msrs);
+static void nmi_cpu_down(void *dummy)
+{
+       if (ctr_running)
+               nmi_cpu_stop(dummy);
+       if (nmi_enabled)
+               nmi_cpu_shutdown(dummy);
 }
 
 static int nmi_create_files(struct super_block *sb, struct dentry *root)
@@ -457,7 +446,6 @@ static int nmi_create_files(struct super_block *sb, struct dentry *root)
        return 0;
 }
 
-#ifdef CONFIG_SMP
 static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
                                 void *data)
 {
@@ -465,10 +453,10 @@ static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
        switch (action) {
        case CPU_DOWN_FAILED:
        case CPU_ONLINE:
-               smp_call_function_single(cpu, nmi_cpu_start, NULL, 0);
+               smp_call_function_single(cpu, nmi_cpu_up, NULL, 0);
                break;
        case CPU_DOWN_PREPARE:
-               smp_call_function_single(cpu, nmi_cpu_stop, NULL, 1);
+               smp_call_function_single(cpu, nmi_cpu_down, NULL, 1);
                break;
        }
        return NOTIFY_DONE;
@@ -477,7 +465,75 @@ static int oprofile_cpu_notifier(struct notifier_block *b, unsigned long action,
 static struct notifier_block oprofile_cpu_nb = {
        .notifier_call = oprofile_cpu_notifier
 };
-#endif
+
+static int nmi_setup(void)
+{
+       int err = 0;
+       int cpu;
+
+       if (!allocate_msrs())
+               return -ENOMEM;
+
+       /* We need to serialize save and setup for HT because the subset
+        * of msrs are distinct for save and setup operations
+        */
+
+       /* Assume saved/restored counters are the same on all CPUs */
+       err = model->fill_in_addresses(&per_cpu(cpu_msrs, 0));
+       if (err)
+               goto fail;
+
+       for_each_possible_cpu(cpu) {
+               if (!cpu)
+                       continue;
+
+               memcpy(per_cpu(cpu_msrs, cpu).counters,
+                      per_cpu(cpu_msrs, 0).counters,
+                      sizeof(struct op_msr) * model->num_counters);
+
+               memcpy(per_cpu(cpu_msrs, cpu).controls,
+                      per_cpu(cpu_msrs, 0).controls,
+                      sizeof(struct op_msr) * model->num_controls);
+
+               mux_clone(cpu);
+       }
+
+       nmi_enabled = 0;
+       ctr_running = 0;
+       barrier();
+       err = register_die_notifier(&profile_exceptions_nb);
+       if (err)
+               goto fail;
+
+       get_online_cpus();
+       register_cpu_notifier(&oprofile_cpu_nb);
+       on_each_cpu(nmi_cpu_setup, NULL, 1);
+       nmi_enabled = 1;
+       put_online_cpus();
+
+       return 0;
+fail:
+       free_msrs();
+       return err;
+}
+
+static void nmi_shutdown(void)
+{
+       struct op_msrs *msrs;
+
+       get_online_cpus();
+       unregister_cpu_notifier(&oprofile_cpu_nb);
+       on_each_cpu(nmi_cpu_shutdown, NULL, 1);
+       nmi_enabled = 0;
+       ctr_running = 0;
+       put_online_cpus();
+       barrier();
+       unregister_die_notifier(&profile_exceptions_nb);
+       msrs = &get_cpu_var(cpu_msrs);
+       model->shutdown(msrs);
+       free_msrs();
+       put_cpu_var(cpu_msrs);
+}
 
 #ifdef CONFIG_PM
 
@@ -687,9 +743,6 @@ int __init op_nmi_init(struct oprofile_operations *ops)
                return -ENODEV;
        }
 
-#ifdef CONFIG_SMP
-       register_cpu_notifier(&oprofile_cpu_nb);
-#endif
        /* default values, can be overwritten by model */
        ops->create_files       = nmi_create_files;
        ops->setup              = nmi_setup;
@@ -716,12 +769,6 @@ int __init op_nmi_init(struct oprofile_operations *ops)
 
 void op_nmi_exit(void)
 {
-       if (using_nmi) {
+       if (using_nmi)
                exit_sysfs();
-#ifdef CONFIG_SMP
-               unregister_cpu_notifier(&oprofile_cpu_nb);
-#endif
-       }
-       if (model->exit)
-               model->exit();
 }
index 090cbbe..b67a6b5 100644 (file)
 #include "op_counter.h"
 
 #define NUM_COUNTERS 4
-#define NUM_CONTROLS 4
 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
 #define NUM_VIRT_COUNTERS 32
-#define NUM_VIRT_CONTROLS 32
 #else
 #define NUM_VIRT_COUNTERS NUM_COUNTERS
-#define NUM_VIRT_CONTROLS NUM_CONTROLS
 #endif
 
 #define OP_EVENT_MASK                  0x0FFF
@@ -105,102 +102,6 @@ static u32 get_ibs_caps(void)
        return ibs_caps;
 }
 
-#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
-
-static void op_mux_switch_ctrl(struct op_x86_model_spec const *model,
-                              struct op_msrs const * const msrs)
-{
-       u64 val;
-       int i;
-
-       /* enable active counters */
-       for (i = 0; i < NUM_COUNTERS; ++i) {
-               int virt = op_x86_phys_to_virt(i);
-               if (!reset_value[virt])
-                       continue;
-               rdmsrl(msrs->controls[i].addr, val);
-               val &= model->reserved;
-               val |= op_x86_get_ctrl(model, &counter_config[virt]);
-               wrmsrl(msrs->controls[i].addr, val);
-       }
-}
-
-#endif
-
-/* functions for op_amd_spec */
-
-static void op_amd_fill_in_addresses(struct op_msrs * const msrs)
-{
-       int i;
-
-       for (i = 0; i < NUM_COUNTERS; i++) {
-               if (reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i))
-                       msrs->counters[i].addr = MSR_K7_PERFCTR0 + i;
-       }
-
-       for (i = 0; i < NUM_CONTROLS; i++) {
-               if (reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i))
-                       msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i;
-       }
-}
-
-static void op_amd_setup_ctrs(struct op_x86_model_spec const *model,
-                             struct op_msrs const * const msrs)
-{
-       u64 val;
-       int i;
-
-       /* setup reset_value */
-       for (i = 0; i < NUM_VIRT_COUNTERS; ++i) {
-               if (counter_config[i].enabled
-                   && msrs->counters[op_x86_virt_to_phys(i)].addr)
-                       reset_value[i] = counter_config[i].count;
-               else
-                       reset_value[i] = 0;
-       }
-
-       /* clear all counters */
-       for (i = 0; i < NUM_CONTROLS; ++i) {
-               if (unlikely(!msrs->controls[i].addr)) {
-                       if (counter_config[i].enabled && !smp_processor_id())
-                               /*
-                                * counter is reserved, this is on all
-                                * cpus, so report only for cpu #0
-                                */
-                               op_x86_warn_reserved(i);
-                       continue;
-               }
-               rdmsrl(msrs->controls[i].addr, val);
-               if (val & ARCH_PERFMON_EVENTSEL_ENABLE)
-                       op_x86_warn_in_use(i);
-               val &= model->reserved;
-               wrmsrl(msrs->controls[i].addr, val);
-       }
-
-       /* avoid a false detection of ctr overflows in NMI handler */
-       for (i = 0; i < NUM_COUNTERS; ++i) {
-               if (unlikely(!msrs->counters[i].addr))
-                       continue;
-               wrmsrl(msrs->counters[i].addr, -1LL);
-       }
-
-       /* enable active counters */
-       for (i = 0; i < NUM_COUNTERS; ++i) {
-               int virt = op_x86_phys_to_virt(i);
-               if (!reset_value[virt])
-                       continue;
-
-               /* setup counter registers */
-               wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]);
-
-               /* setup control registers */
-               rdmsrl(msrs->controls[i].addr, val);
-               val &= model->reserved;
-               val |= op_x86_get_ctrl(model, &counter_config[virt]);
-               wrmsrl(msrs->controls[i].addr, val);
-       }
-}
-
 /*
  * 16-bit Linear Feedback Shift Register (LFSR)
  *
@@ -365,6 +266,125 @@ static void op_amd_stop_ibs(void)
                wrmsrl(MSR_AMD64_IBSOPCTL, 0);
 }
 
+#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
+
+static void op_mux_switch_ctrl(struct op_x86_model_spec const *model,
+                              struct op_msrs const * const msrs)
+{
+       u64 val;
+       int i;
+
+       /* enable active counters */
+       for (i = 0; i < NUM_COUNTERS; ++i) {
+               int virt = op_x86_phys_to_virt(i);
+               if (!reset_value[virt])
+                       continue;
+               rdmsrl(msrs->controls[i].addr, val);
+               val &= model->reserved;
+               val |= op_x86_get_ctrl(model, &counter_config[virt]);
+               wrmsrl(msrs->controls[i].addr, val);
+       }
+}
+
+#endif
+
+/* functions for op_amd_spec */
+
+static void op_amd_shutdown(struct op_msrs const * const msrs)
+{
+       int i;
+
+       for (i = 0; i < NUM_COUNTERS; ++i) {
+               if (!msrs->counters[i].addr)
+                       continue;
+               release_perfctr_nmi(MSR_K7_PERFCTR0 + i);
+               release_evntsel_nmi(MSR_K7_EVNTSEL0 + i);
+       }
+}
+
+static int op_amd_fill_in_addresses(struct op_msrs * const msrs)
+{
+       int i;
+
+       for (i = 0; i < NUM_COUNTERS; i++) {
+               if (!reserve_perfctr_nmi(MSR_K7_PERFCTR0 + i))
+                       goto fail;
+               if (!reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i)) {
+                       release_perfctr_nmi(MSR_K7_PERFCTR0 + i);
+                       goto fail;
+               }
+               /* both registers must be reserved */
+               msrs->counters[i].addr = MSR_K7_PERFCTR0 + i;
+               msrs->controls[i].addr = MSR_K7_EVNTSEL0 + i;
+               continue;
+       fail:
+               if (!counter_config[i].enabled)
+                       continue;
+               op_x86_warn_reserved(i);
+               op_amd_shutdown(msrs);
+               return -EBUSY;
+       }
+
+       return 0;
+}
+
+static void op_amd_setup_ctrs(struct op_x86_model_spec const *model,
+                             struct op_msrs const * const msrs)
+{
+       u64 val;
+       int i;
+
+       /* setup reset_value */
+       for (i = 0; i < NUM_VIRT_COUNTERS; ++i) {
+               if (counter_config[i].enabled
+                   && msrs->counters[op_x86_virt_to_phys(i)].addr)
+                       reset_value[i] = counter_config[i].count;
+               else
+                       reset_value[i] = 0;
+       }
+
+       /* clear all counters */
+       for (i = 0; i < NUM_COUNTERS; ++i) {
+               if (!msrs->controls[i].addr)
+                       continue;
+               rdmsrl(msrs->controls[i].addr, val);
+               if (val & ARCH_PERFMON_EVENTSEL_ENABLE)
+                       op_x86_warn_in_use(i);
+               val &= model->reserved;
+               wrmsrl(msrs->controls[i].addr, val);
+               /*
+                * avoid a false detection of ctr overflows in NMI
+                * handler
+                */
+               wrmsrl(msrs->counters[i].addr, -1LL);
+       }
+
+       /* enable active counters */
+       for (i = 0; i < NUM_COUNTERS; ++i) {
+               int virt = op_x86_phys_to_virt(i);
+               if (!reset_value[virt])
+                       continue;
+
+               /* setup counter registers */
+               wrmsrl(msrs->counters[i].addr, -(u64)reset_value[virt]);
+
+               /* setup control registers */
+               rdmsrl(msrs->controls[i].addr, val);
+               val &= model->reserved;
+               val |= op_x86_get_ctrl(model, &counter_config[virt]);
+               wrmsrl(msrs->controls[i].addr, val);
+       }
+
+       if (ibs_caps)
+               setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0);
+}
+
+static void op_amd_cpu_shutdown(void)
+{
+       if (ibs_caps)
+               setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1);
+}
+
 static int op_amd_check_ctrs(struct pt_regs * const regs,
                             struct op_msrs const * const msrs)
 {
@@ -425,42 +445,16 @@ static void op_amd_stop(struct op_msrs const * const msrs)
        op_amd_stop_ibs();
 }
 
-static void op_amd_shutdown(struct op_msrs const * const msrs)
-{
-       int i;
-
-       for (i = 0; i < NUM_COUNTERS; ++i) {
-               if (msrs->counters[i].addr)
-                       release_perfctr_nmi(MSR_K7_PERFCTR0 + i);
-       }
-       for (i = 0; i < NUM_CONTROLS; ++i) {
-               if (msrs->controls[i].addr)
-                       release_evntsel_nmi(MSR_K7_EVNTSEL0 + i);
-       }
-}
-
-static u8 ibs_eilvt_off;
-
-static inline void apic_init_ibs_nmi_per_cpu(void *arg)
-{
-       ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_NMI, 0);
-}
-
-static inline void apic_clear_ibs_nmi_per_cpu(void *arg)
-{
-       setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1);
-}
-
-static int init_ibs_nmi(void)
+static int __init_ibs_nmi(void)
 {
 #define IBSCTL_LVTOFFSETVAL            (1 << 8)
 #define IBSCTL                         0x1cc
        struct pci_dev *cpu_cfg;
        int nodes;
        u32 value = 0;
+       u8 ibs_eilvt_off;
 
-       /* per CPU setup */
-       on_each_cpu(apic_init_ibs_nmi_per_cpu, NULL, 1);
+       ibs_eilvt_off = setup_APIC_eilvt_ibs(0, APIC_EILVT_MSG_FIX, 1);
 
        nodes = 0;
        cpu_cfg = NULL;
@@ -490,22 +484,15 @@ static int init_ibs_nmi(void)
        return 0;
 }
 
-/* uninitialize the APIC for the IBS interrupts if needed */
-static void clear_ibs_nmi(void)
-{
-       if (ibs_caps)
-               on_each_cpu(apic_clear_ibs_nmi_per_cpu, NULL, 1);
-}
-
 /* initialize the APIC for the IBS interrupts if available */
-static void ibs_init(void)
+static void init_ibs(void)
 {
        ibs_caps = get_ibs_caps();
 
        if (!ibs_caps)
                return;
 
-       if (init_ibs_nmi()) {
+       if (__init_ibs_nmi()) {
                ibs_caps = 0;
                return;
        }
@@ -514,14 +501,6 @@ static void ibs_init(void)
               (unsigned)ibs_caps);
 }
 
-static void ibs_exit(void)
-{
-       if (!ibs_caps)
-               return;
-
-       clear_ibs_nmi();
-}
-
 static int (*create_arch_files)(struct super_block *sb, struct dentry *root);
 
 static int setup_ibs_files(struct super_block *sb, struct dentry *root)
@@ -570,27 +549,22 @@ static int setup_ibs_files(struct super_block *sb, struct dentry *root)
 
 static int op_amd_init(struct oprofile_operations *ops)
 {
-       ibs_init();
+       init_ibs();
        create_arch_files = ops->create_files;
        ops->create_files = setup_ibs_files;
        return 0;
 }
 
-static void op_amd_exit(void)
-{
-       ibs_exit();
-}
-
 struct op_x86_model_spec op_amd_spec = {
        .num_counters           = NUM_COUNTERS,
-       .num_controls           = NUM_CONTROLS,
+       .num_controls           = NUM_COUNTERS,
        .num_virt_counters      = NUM_VIRT_COUNTERS,
        .reserved               = MSR_AMD_EVENTSEL_RESERVED,
        .event_mask             = OP_EVENT_MASK,
        .init                   = op_amd_init,
-       .exit                   = op_amd_exit,
        .fill_in_addresses      = &op_amd_fill_in_addresses,
        .setup_ctrs             = &op_amd_setup_ctrs,
+       .cpu_down               = &op_amd_cpu_shutdown,
        .check_ctrs             = &op_amd_check_ctrs,
        .start                  = &op_amd_start,
        .stop                   = &op_amd_stop,
index e6a160a..182558d 100644 (file)
@@ -385,8 +385,26 @@ static unsigned int get_stagger(void)
 
 static unsigned long reset_value[NUM_COUNTERS_NON_HT];
 
+static void p4_shutdown(struct op_msrs const * const msrs)
+{
+       int i;
 
-static void p4_fill_in_addresses(struct op_msrs * const msrs)
+       for (i = 0; i < num_counters; ++i) {
+               if (msrs->counters[i].addr)
+                       release_perfctr_nmi(msrs->counters[i].addr);
+       }
+       /*
+        * some of the control registers are specially reserved in
+        * conjunction with the counter registers (hence the starting offset).
+        * This saves a few bits.
+        */
+       for (i = num_counters; i < num_controls; ++i) {
+               if (msrs->controls[i].addr)
+                       release_evntsel_nmi(msrs->controls[i].addr);
+       }
+}
+
+static int p4_fill_in_addresses(struct op_msrs * const msrs)
 {
        unsigned int i;
        unsigned int addr, cccraddr, stag;
@@ -468,6 +486,18 @@ static void p4_fill_in_addresses(struct op_msrs * const msrs)
                        msrs->controls[i++].addr = MSR_P4_CRU_ESCR5;
                }
        }
+
+       for (i = 0; i < num_counters; ++i) {
+               if (!counter_config[i].enabled)
+                       continue;
+               if (msrs->controls[i].addr)
+                       continue;
+               op_x86_warn_reserved(i);
+               p4_shutdown(msrs);
+               return -EBUSY;
+       }
+
+       return 0;
 }
 
 
@@ -668,26 +698,6 @@ static void p4_stop(struct op_msrs const * const msrs)
        }
 }
 
-static void p4_shutdown(struct op_msrs const * const msrs)
-{
-       int i;
-
-       for (i = 0; i < num_counters; ++i) {
-               if (msrs->counters[i].addr)
-                       release_perfctr_nmi(msrs->counters[i].addr);
-       }
-       /*
-        * some of the control registers are specially reserved in
-        * conjunction with the counter registers (hence the starting offset).
-        * This saves a few bits.
-        */
-       for (i = num_counters; i < num_controls; ++i) {
-               if (msrs->controls[i].addr)
-                       release_evntsel_nmi(msrs->controls[i].addr);
-       }
-}
-
-
 #ifdef CONFIG_SMP
 struct op_x86_model_spec op_p4_ht2_spec = {
        .num_counters           = NUM_COUNTERS_HT2,
index 2bf90fa..d769cda 100644 (file)
@@ -30,19 +30,46 @@ static int counter_width = 32;
 
 static u64 *reset_value;
 
-static void ppro_fill_in_addresses(struct op_msrs * const msrs)
+static void ppro_shutdown(struct op_msrs const * const msrs)
 {
        int i;
 
-       for (i = 0; i < num_counters; i++) {
-               if (reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i))
-                       msrs->counters[i].addr = MSR_P6_PERFCTR0 + i;
+       for (i = 0; i < num_counters; ++i) {
+               if (!msrs->counters[i].addr)
+                       continue;
+               release_perfctr_nmi(MSR_P6_PERFCTR0 + i);
+               release_evntsel_nmi(MSR_P6_EVNTSEL0 + i);
+       }
+       if (reset_value) {
+               kfree(reset_value);
+               reset_value = NULL;
        }
+}
+
+static int ppro_fill_in_addresses(struct op_msrs * const msrs)
+{
+       int i;
 
        for (i = 0; i < num_counters; i++) {
-               if (reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i))
-                       msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i;
+               if (!reserve_perfctr_nmi(MSR_P6_PERFCTR0 + i))
+                       goto fail;
+               if (!reserve_evntsel_nmi(MSR_P6_EVNTSEL0 + i)) {
+                       release_perfctr_nmi(MSR_P6_PERFCTR0 + i);
+                       goto fail;
+               }
+               /* both registers must be reserved */
+               msrs->counters[i].addr = MSR_P6_PERFCTR0 + i;
+               msrs->controls[i].addr = MSR_P6_EVNTSEL0 + i;
+               continue;
+       fail:
+               if (!counter_config[i].enabled)
+                       continue;
+               op_x86_warn_reserved(i);
+               ppro_shutdown(msrs);
+               return -EBUSY;
        }
+
+       return 0;
 }
 
 
@@ -78,26 +105,17 @@ static void ppro_setup_ctrs(struct op_x86_model_spec const *model,
 
        /* clear all counters */
        for (i = 0; i < num_counters; ++i) {
-               if (unlikely(!msrs->controls[i].addr)) {
-                       if (counter_config[i].enabled && !smp_processor_id())
-                               /*
-                                * counter is reserved, this is on all
-                                * cpus, so report only for cpu #0
-                                */
-                               op_x86_warn_reserved(i);
+               if (!msrs->controls[i].addr)
                        continue;
-               }
                rdmsrl(msrs->controls[i].addr, val);
                if (val & ARCH_PERFMON_EVENTSEL_ENABLE)
                        op_x86_warn_in_use(i);
                val &= model->reserved;
                wrmsrl(msrs->controls[i].addr, val);
-       }
-
-       /* avoid a false detection of ctr overflows in NMI handler */
-       for (i = 0; i < num_counters; ++i) {
-               if (unlikely(!msrs->counters[i].addr))
-                       continue;
+               /*
+                * avoid a false detection of ctr overflows in NMI *
+                * handler
+                */
                wrmsrl(msrs->counters[i].addr, -1LL);
        }
 
@@ -189,25 +207,6 @@ static void ppro_stop(struct op_msrs const * const msrs)
        }
 }
 
-static void ppro_shutdown(struct op_msrs const * const msrs)
-{
-       int i;
-
-       for (i = 0; i < num_counters; ++i) {
-               if (msrs->counters[i].addr)
-                       release_perfctr_nmi(MSR_P6_PERFCTR0 + i);
-       }
-       for (i = 0; i < num_counters; ++i) {
-               if (msrs->controls[i].addr)
-                       release_evntsel_nmi(MSR_P6_EVNTSEL0 + i);
-       }
-       if (reset_value) {
-               kfree(reset_value);
-               reset_value = NULL;
-       }
-}
-
-
 struct op_x86_model_spec op_ppro_spec = {
        .num_counters           = 2,
        .num_controls           = 2,
@@ -239,11 +238,11 @@ static void arch_perfmon_setup_counters(void)
        if (eax.split.version_id == 0 && current_cpu_data.x86 == 6 &&
                current_cpu_data.x86_model == 15) {
                eax.split.version_id = 2;
-               eax.split.num_events = 2;
+               eax.split.num_counters = 2;
                eax.split.bit_width = 40;
        }
 
-       num_counters = eax.split.num_events;
+       num_counters = eax.split.num_counters;
 
        op_arch_perfmon_spec.num_counters = num_counters;
        op_arch_perfmon_spec.num_controls = num_counters;
index ff82a75..89017fa 100644 (file)
@@ -40,10 +40,10 @@ struct op_x86_model_spec {
        u64             reserved;
        u16             event_mask;
        int             (*init)(struct oprofile_operations *ops);
-       void            (*exit)(void);
-       void            (*fill_in_addresses)(struct op_msrs * const msrs);
+       int             (*fill_in_addresses)(struct op_msrs * const msrs);
        void            (*setup_ctrs)(struct op_x86_model_spec const *model,
                                      struct op_msrs const * const msrs);
+       void            (*cpu_down)(void);
        int             (*check_ctrs)(struct pt_regs * const regs,
                                      struct op_msrs const * const msrs);
        void            (*start)(struct op_msrs const * const msrs);
index 1cdc02c..7ef3a27 100644 (file)
@@ -109,7 +109,7 @@ static int pci_device_update_fixed(struct pci_bus *bus, unsigned int devfn,
                        decode++;
                        decode = ~(decode - 1);
                } else {
-                       decode = ~0;
+                       decode = 0;
                }
 
                /*
index 32764b8..b3c6c59 100644 (file)
@@ -476,6 +476,7 @@ void xen_timer_resume(void)
 __init void xen_time_init(void)
 {
        int cpu = smp_processor_id();
+       struct timespec tp;
 
        clocksource_register(&xen_clocksource);
 
@@ -487,9 +488,8 @@ __init void xen_time_init(void)
        }
 
        /* Set initial system time with full resolution */
-       xen_read_wallclock(&xtime);
-       set_normalized_timespec(&wall_to_monotonic,
-                               -xtime.tv_sec, -xtime.tv_nsec);
+       xen_read_wallclock(&tp);
+       do_settimeofday(&tp);
 
        setup_force_cpu_cap(X86_FEATURE_TSC);
 
index 22d6dde..a96a061 100644 (file)
@@ -46,7 +46,7 @@
  *
  * Atomically reads the value of @v.
  */
-#define atomic_read(v)         ((v)->counter)
+#define atomic_read(v)         (*(volatile int *)&(v)->counter)
 
 /**
  * atomic_set - set atomic variable
index 1316564..7be8acc 100644 (file)
@@ -129,7 +129,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_NEED_RESCHED       2       /* rescheduling necessary */
 #define TIF_SINGLESTEP         3       /* restore singlestep on return to user mode */
 #define TIF_IRET               4       /* return with iret */
-#define TIF_MEMDIE             5
+#define TIF_MEMDIE             5       /* is terminating due to OOM killer */
 #define TIF_RESTORE_SIGMASK    6       /* restore signal mask in do_signal() */
 #define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
 #define TIF_FREEZE             17      /* is freezing for suspend */
index 19f7df3..19df764 100644 (file)
@@ -60,11 +60,6 @@ static struct irqaction timer_irqaction = {
 
 void __init time_init(void)
 {
-       /* FIXME: xtime&wall_to_monotonic are set in timekeeping_init. */
-       read_persistent_clock(&xtime);
-       set_normalized_timespec(&wall_to_monotonic,
-               -xtime.tv_sec, -xtime.tv_nsec);
-
 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
        printk("Calibrating CPU frequency ");
        platform_calibrate_ccount();
index 403857a..9d9434f 100644 (file)
@@ -28,7 +28,7 @@ config CRYPTO_FIPS
          This options enables the fips boot option which is
          required if you want to system to operate in a FIPS 200
          certification.  You should say no unless you know what
-         this is. Note that CRYPTO_ANSI_CPRNG is requred if this
+         this is. Note that CRYPTO_ANSI_CPRNG is required if this
          option is selected
 
 config CRYPTO_ALGAPI
index 7423052..d93cc06 100644 (file)
@@ -14,12 +14,12 @@ acpi-y := dsfield.o   dsmthdat.o  dsopcode.o  dswexec.o  dswscope.o \
 
 acpi-y += evevent.o  evregion.o  evsci.o    evxfevnt.o \
         evmisc.o   evrgnini.o  evxface.o  evxfregn.o \
-        evgpe.o    evgpeblk.o
+        evgpe.o    evgpeblk.o evgpeinit.o  evgpeutil.o
 
 acpi-y += exconfig.o  exfield.o  exnames.o   exoparg6.o  exresolv.o  exstorob.o\
         exconvrt.o  exfldio.o  exoparg1.o  exprep.o    exresop.o   exsystem.o\
         excreate.o  exmisc.o   exoparg2.o  exregion.o  exstore.o   exutils.o \
-        exdump.o    exmutex.o  exoparg3.o  exresnte.o  exstoren.o
+        exdump.o    exmutex.o  exoparg3.o  exresnte.o  exstoren.o  exdebug.o
 
 acpi-y += hwacpi.o  hwgpe.o  hwregs.o  hwsleep.o hwxface.o hwvalid.o
 
index 3e6ba99..64d1e5c 100644 (file)
@@ -73,8 +73,10 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node *node,
                             u32 notify_value);
 
 /*
- * evgpe - GPE handling and dispatch
+ * evgpe - Low-level GPE support
  */
+u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
+
 acpi_status
 acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info);
 
@@ -85,19 +87,13 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info);
 struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
                                                       u32 gpe_number);
 
+struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
+                                                    struct acpi_gpe_block_info
+                                                    *gpe_block);
+
 /*
- * evgpeblk
+ * evgpeblk - Upper-level GPE block support
  */
-u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info);
-
-acpi_status
-acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context);
-
-acpi_status
-acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
-                           struct acpi_gpe_block_info *gpe_block,
-                           void *context);
-
 acpi_status
 acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
                         struct acpi_generic_address *gpe_block_address,
@@ -116,12 +112,37 @@ u32
 acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info,
                     u32 gpe_number);
 
-u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info *gpe_xrupt_list);
+/*
+ * evgpeinit - GPE initialization and update
+ */
+acpi_status acpi_ev_gpe_initialize(void);
+
+void acpi_ev_update_gpes(acpi_owner_id table_owner_id);
 
 acpi_status
-acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info);
+acpi_ev_match_gpe_method(acpi_handle obj_handle,
+                        u32 level, void *context, void **return_value);
 
-acpi_status acpi_ev_gpe_initialize(void);
+acpi_status
+acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
+                         u32 level, void *context, void **return_value);
+
+/*
+ * evgpeutil - GPE utilities
+ */
+acpi_status
+acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context);
+
+u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info);
+
+struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 interrupt_number);
+
+acpi_status acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
+
+acpi_status
+acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+                           struct acpi_gpe_block_info *gpe_block,
+                           void *context);
 
 /*
  * evregion - Address Space handling
index f8dd8f2..9070f1f 100644 (file)
@@ -112,6 +112,19 @@ u8 ACPI_INIT_GLOBAL(acpi_gbl_leave_wake_gpes_disabled, TRUE);
  */
 u8 ACPI_INIT_GLOBAL(acpi_gbl_use_default_register_widths, TRUE);
 
+/*
+ * Optionally enable output from the AML Debug Object.
+ */
+u8 ACPI_INIT_GLOBAL(acpi_gbl_enable_aml_debug_object, FALSE);
+
+/*
+ * Optionally copy the entire DSDT to local memory (instead of simply
+ * mapping it.) There are some BIOSs that corrupt or replace the original
+ * DSDT, creating the need for this option. Default is FALSE, do not copy
+ * the DSDT.
+ */
+u8 ACPI_INIT_GLOBAL(acpi_gbl_copy_dsdt_locally, FALSE);
+
 /* acpi_gbl_FADT is a local copy of the FADT, converted to a common format. */
 
 struct acpi_table_fadt acpi_gbl_FADT;
@@ -145,11 +158,10 @@ ACPI_EXTERN u32 acpi_gbl_trace_dbg_layer;
  ****************************************************************************/
 
 /*
- * acpi_gbl_root_table_list is the master list of ACPI tables found in the
- * RSDT/XSDT.
- *
+ * acpi_gbl_root_table_list is the master list of ACPI tables that were
+ * found in the RSDT/XSDT.
  */
-ACPI_EXTERN struct acpi_internal_rsdt acpi_gbl_root_table_list;
+ACPI_EXTERN struct acpi_table_list acpi_gbl_root_table_list;
 ACPI_EXTERN struct acpi_table_facs *acpi_gbl_FACS;
 
 /* These addresses are calculated from the FADT Event Block addresses */
@@ -160,6 +172,11 @@ ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1a_enable;
 ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_status;
 ACPI_EXTERN struct acpi_generic_address acpi_gbl_xpm1b_enable;
 
+/* DSDT information. Used to check for DSDT corruption */
+
+ACPI_EXTERN struct acpi_table_header *acpi_gbl_DSDT;
+ACPI_EXTERN struct acpi_table_header acpi_gbl_original_dsdt_header;
+
 /*
  * Handle both ACPI 1.0 and ACPI 2.0 Integer widths. The integer width is
  * determined by the revision of the DSDT: If the DSDT revision is less than
index 6df3f84..049e203 100644 (file)
@@ -120,6 +120,13 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
                               union acpi_operand_object **result_desc,
                               struct acpi_walk_state *walk_state);
 
+/*
+ * exdebug - AML debug object
+ */
+void
+acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
+                       u32 level, u32 index);
+
 /*
  * exfield - ACPI AML (p-code) execution - field manipulation
  */
@@ -274,7 +281,7 @@ acpi_status
 acpi_ex_system_do_notify_op(union acpi_operand_object *value,
                            union acpi_operand_object *obj_desc);
 
-acpi_status acpi_ex_system_do_suspend(u64 time);
+acpi_status acpi_ex_system_do_sleep(u64 time);
 
 acpi_status acpi_ex_system_do_stall(u32 time);
 
index 24b8faa..147a7e6 100644 (file)
@@ -213,12 +213,12 @@ struct acpi_namespace_node {
 #define ANOBJ_IS_BIT_OFFSET             0x40   /* i_aSL only: Reference is a bit offset */
 #define ANOBJ_IS_REFERENCED             0x80   /* i_aSL only: Object was referenced */
 
-/* One internal RSDT for table management */
+/* Internal ACPI table management - master table list */
 
-struct acpi_internal_rsdt {
-       struct acpi_table_desc *tables;
-       u32 count;
-       u32 size;
+struct acpi_table_list {
+       struct acpi_table_desc *tables; /* Table descriptor array */
+       u32 current_table_count;        /* Tables currently in the array */
+       u32 max_table_count;    /* Max tables array will hold */
        u8 flags;
 };
 
@@ -427,8 +427,8 @@ struct acpi_gpe_event_info {
        struct acpi_gpe_register_info *register_info;   /* Backpointer to register info */
        u8 flags;               /* Misc info about this GPE */
        u8 gpe_number;          /* This GPE */
-       u8 runtime_count;
-       u8 wakeup_count;
+       u8 runtime_count;       /* References to a run GPE */
+       u8 wakeup_count;        /* References to a wake GPE */
 };
 
 /* Information about a GPE register pair, one per each status/enable pair in an array */
@@ -454,6 +454,7 @@ struct acpi_gpe_block_info {
        struct acpi_gpe_event_info *event_info; /* One for each GPE */
        struct acpi_generic_address block_address;      /* Base address of the block */
        u32 register_count;     /* Number of register pairs in block */
+       u16 gpe_count;          /* Number of individual GPEs in block */
        u8 block_base_number;   /* Base GPE number for this block */
 };
 
@@ -469,6 +470,10 @@ struct acpi_gpe_xrupt_info {
 struct acpi_gpe_walk_info {
        struct acpi_namespace_node *gpe_device;
        struct acpi_gpe_block_info *gpe_block;
+       u16 count;
+       acpi_owner_id owner_id;
+       u8 enable_this_gpe;
+       u8 execute_by_owner_id;
 };
 
 struct acpi_gpe_device_info {
index 8ff3b74..62a576e 100644 (file)
@@ -107,6 +107,10 @@ u8 acpi_tb_checksum(u8 *buffer, u32 length);
 acpi_status
 acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length);
 
+void acpi_tb_check_dsdt_header(void);
+
+struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index);
+
 void
 acpi_tb_install_table(acpi_physical_address address,
                      char *signature, u32 table_index);
index bb13817..347bee1 100644 (file)
@@ -323,7 +323,7 @@ acpi_ds_get_field_names(struct acpi_create_field_info *info,
                default:
 
                        ACPI_ERROR((AE_INFO,
-                                   "Invalid opcode in field list: %X",
+                                   "Invalid opcode in field list: 0x%X",
                                    arg->common.aml_opcode));
                        return_ACPI_STATUS(AE_AML_BAD_OPCODE);
                }
index 7210392..2a9a561 100644 (file)
@@ -225,7 +225,7 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
                    (walk_state->thread->current_sync_level >
                     obj_desc->method.mutex->mutex.sync_level)) {
                        ACPI_ERROR((AE_INFO,
-                                   "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%d)",
+                                   "Cannot acquire Mutex for method [%4.4s], current SyncLevel is too large (%u)",
                                    acpi_ut_get_node_name(method_node),
                                    walk_state->thread->current_sync_level));
 
index cc343b9..f3d52f5 100644 (file)
@@ -262,7 +262,7 @@ acpi_ds_method_data_get_node(u8 type,
 
                if (index > ACPI_METHOD_MAX_LOCAL) {
                        ACPI_ERROR((AE_INFO,
-                                   "Local index %d is invalid (max %d)",
+                                   "Local index %u is invalid (max %u)",
                                    index, ACPI_METHOD_MAX_LOCAL));
                        return_ACPI_STATUS(AE_AML_INVALID_INDEX);
                }
@@ -276,7 +276,7 @@ acpi_ds_method_data_get_node(u8 type,
 
                if (index > ACPI_METHOD_MAX_ARG) {
                        ACPI_ERROR((AE_INFO,
-                                   "Arg index %d is invalid (max %d)",
+                                   "Arg index %u is invalid (max %u)",
                                    index, ACPI_METHOD_MAX_ARG));
                        return_ACPI_STATUS(AE_AML_INVALID_INDEX);
                }
@@ -287,7 +287,7 @@ acpi_ds_method_data_get_node(u8 type,
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Type %d is invalid", type));
+               ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
                return_ACPI_STATUS(AE_TYPE);
        }
 
@@ -424,7 +424,7 @@ acpi_ds_method_data_get_value(u8 type,
                        case ACPI_REFCLASS_ARG:
 
                                ACPI_ERROR((AE_INFO,
-                                           "Uninitialized Arg[%d] at node %p",
+                                           "Uninitialized Arg[%u] at node %p",
                                            index, node));
 
                                return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
@@ -440,7 +440,7 @@ acpi_ds_method_data_get_value(u8 type,
                        default:
 
                                ACPI_ERROR((AE_INFO,
-                                           "Not a Arg/Local opcode: %X",
+                                           "Not a Arg/Local opcode: 0x%X",
                                            type));
                                return_ACPI_STATUS(AE_AML_INTERNAL);
                        }
index 891e08b..3607adc 100644 (file)
@@ -288,7 +288,7 @@ acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state,
        if (byte_list) {
                if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) {
                        ACPI_ERROR((AE_INFO,
-                                   "Expecting bytelist, got AML opcode %X in op %p",
+                                   "Expecting bytelist, found AML opcode 0x%X in op %p",
                                    byte_list->common.aml_opcode, byte_list));
 
                        acpi_ut_remove_reference(obj_desc);
@@ -511,7 +511,7 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                }
 
                ACPI_INFO((AE_INFO,
-                          "Actual Package length (0x%X) is larger than NumElements field (0x%X), truncated\n",
+                          "Actual Package length (%u) is larger than NumElements field (%u), truncated\n",
                           i, element_count));
        } else if (i < element_count) {
                /*
@@ -519,7 +519,7 @@ acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state,
                 * Note: this is not an error, the package is padded out with NULLs.
                 */
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                 "Package List length (0x%X) smaller than NumElements count (0x%X), padded with null elements\n",
+                                 "Package List length (%u) smaller than NumElements count (%u), padded with null elements\n",
                                  i, element_count));
        }
 
@@ -701,7 +701,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                        default:
 
                                ACPI_ERROR((AE_INFO,
-                                           "Unknown constant opcode %X",
+                                           "Unknown constant opcode 0x%X",
                                            opcode));
                                status = AE_AML_OPERAND_TYPE;
                                break;
@@ -717,7 +717,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                        break;
 
                default:
-                       ACPI_ERROR((AE_INFO, "Unknown Integer type %X",
+                       ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X",
                                    op_info->type));
                        status = AE_AML_OPERAND_TYPE;
                        break;
@@ -806,7 +806,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
                        default:
 
                                ACPI_ERROR((AE_INFO,
-                                           "Unimplemented reference type for AML opcode: %4.4X",
+                                           "Unimplemented reference type for AML opcode: 0x%4.4X",
                                            opcode));
                                return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
                        }
@@ -816,7 +816,7 @@ acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unimplemented data type: %X",
+               ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X",
                            obj_desc->common.type));
 
                status = AE_AML_OPERAND_TYPE;
index bf980ca..53a7e41 100644 (file)
@@ -292,7 +292,7 @@ acpi_status acpi_ds_get_buffer_arguments(union acpi_operand_object *obj_desc)
        node = obj_desc->buffer.node;
        if (!node) {
                ACPI_ERROR((AE_INFO,
-                           "No pointer back to NS node in buffer obj %p",
+                           "No pointer back to namespace node in buffer object %p",
                            obj_desc));
                return_ACPI_STATUS(AE_AML_INTERNAL);
        }
@@ -336,7 +336,7 @@ acpi_status acpi_ds_get_package_arguments(union acpi_operand_object *obj_desc)
        node = obj_desc->package.node;
        if (!node) {
                ACPI_ERROR((AE_INFO,
-                           "No pointer back to NS node in package %p",
+                           "No pointer back to namespace node in package %p",
                            obj_desc));
                return_ACPI_STATUS(AE_AML_INTERNAL);
        }
@@ -580,7 +580,8 @@ acpi_ds_init_buffer_field(u16 aml_opcode,
        default:
 
                ACPI_ERROR((AE_INFO,
-                           "Unknown field creation opcode %02x", aml_opcode));
+                           "Unknown field creation opcode 0x%02X",
+                           aml_opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
        }
@@ -589,7 +590,7 @@ acpi_ds_init_buffer_field(u16 aml_opcode,
 
        if ((bit_offset + bit_count) > (8 * (u32) buffer_desc->buffer.length)) {
                ACPI_ERROR((AE_INFO,
-                           "Field [%4.4s] at %d exceeds Buffer [%4.4s] size %d (bits)",
+                           "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
                            acpi_ut_get_node_name(result_desc),
                            bit_offset + bit_count,
                            acpi_ut_get_node_name(buffer_desc->buffer.node),
@@ -693,7 +694,7 @@ acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
        status = acpi_ex_resolve_operands(op->common.aml_opcode,
                                          ACPI_WALK_OPERANDS, walk_state);
        if (ACPI_FAILURE(status)) {
-               ACPI_ERROR((AE_INFO, "(%s) bad operand(s) (%X)",
+               ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
                            acpi_ps_get_opcode_name(op->common.aml_opcode),
                            status));
 
@@ -1461,7 +1462,7 @@ acpi_ds_exec_end_control_op(struct acpi_walk_state * walk_state,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown control opcode=%X Op=%p",
+               ACPI_ERROR((AE_INFO, "Unknown control opcode=0x%X Op=%p",
                            op->common.aml_opcode, op));
 
                status = AE_AML_BAD_OPCODE;
index 6b76c48..d555b37 100644 (file)
@@ -140,7 +140,7 @@ acpi_ds_get_predicate_value(struct acpi_walk_state *walk_state,
 
        if (local_obj_desc->common.type != ACPI_TYPE_INTEGER) {
                ACPI_ERROR((AE_INFO,
-                           "Bad predicate (not an integer) ObjDesc=%p State=%p Type=%X",
+                           "Bad predicate (not an integer) ObjDesc=%p State=%p Type=0x%X",
                            obj_desc, walk_state, obj_desc->common.type));
 
                status = AE_AML_OPERAND_TYPE;
@@ -354,7 +354,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
        op_class = walk_state->op_info->class;
 
        if (op_class == AML_CLASS_UNKNOWN) {
-               ACPI_ERROR((AE_INFO, "Unknown opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown opcode 0x%X",
                            op->common.aml_opcode));
                return_ACPI_STATUS(AE_NOT_IMPLEMENTED);
        }
@@ -678,7 +678,7 @@ acpi_status acpi_ds_exec_end_op(struct acpi_walk_state *walk_state)
                default:
 
                        ACPI_ERROR((AE_INFO,
-                                   "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p",
+                                   "Unimplemented opcode, class=0x%X type=0x%X Opcode=-0x%X Op=%p",
                                    op_class, op_type, op->common.aml_opcode,
                                    op));
 
index 050df81..83155dd 100644 (file)
@@ -179,7 +179,7 @@ acpi_ds_result_push(union acpi_operand_object * object,
 
        if (!object) {
                ACPI_ERROR((AE_INFO,
-                           "Null Object! Obj=%p State=%p Num=%X",
+                           "Null Object! Obj=%p State=%p Num=%u",
                            object, walk_state, walk_state->result_count));
                return (AE_BAD_PARAMETER);
        }
@@ -223,7 +223,7 @@ static acpi_status acpi_ds_result_stack_push(struct acpi_walk_state *walk_state)
 
        if (((u32) walk_state->result_size + ACPI_RESULTS_FRAME_OBJ_NUM) >
            ACPI_RESULTS_OBJ_NUM_MAX) {
-               ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%X",
+               ACPI_ERROR((AE_INFO, "Result stack overflow: State=%p Num=%u",
                            walk_state, walk_state->result_size));
                return (AE_STACK_OVERFLOW);
        }
@@ -314,7 +314,7 @@ acpi_ds_obj_stack_push(void *object, struct acpi_walk_state * walk_state)
 
        if (walk_state->num_operands >= ACPI_OBJ_NUM_OPERANDS) {
                ACPI_ERROR((AE_INFO,
-                           "Object stack overflow! Obj=%p State=%p #Ops=%X",
+                           "Object stack overflow! Obj=%p State=%p #Ops=%u",
                            object, walk_state, walk_state->num_operands));
                return (AE_STACK_OVERFLOW);
        }
@@ -365,7 +365,7 @@ acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
 
                if (walk_state->num_operands == 0) {
                        ACPI_ERROR((AE_INFO,
-                                   "Object stack underflow! Count=%X State=%p #Ops=%X",
+                                   "Object stack underflow! Count=%X State=%p #Ops=%u",
                                    pop_count, walk_state,
                                    walk_state->num_operands));
                        return (AE_STACK_UNDERFLOW);
@@ -377,7 +377,7 @@ acpi_ds_obj_stack_pop(u32 pop_count, struct acpi_walk_state * walk_state)
                walk_state->operands[walk_state->num_operands] = NULL;
        }
 
-       ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",
+       ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",
                          pop_count, walk_state, walk_state->num_operands));
 
        return (AE_OK);
index c1e6f47..f579591 100644 (file)
@@ -302,7 +302,7 @@ static u32 acpi_ev_fixed_event_dispatch(u32 event)
                                              ACPI_DISABLE_EVENT);
 
                ACPI_ERROR((AE_INFO,
-                           "No installed handler for fixed event [%08X]",
+                           "No installed handler for fixed event [0x%08X]",
                            event));
 
                return (ACPI_INTERRUPT_NOT_HANDLED);
index 78c5550..a221ad4 100644 (file)
@@ -60,7 +60,8 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Updates GPE register enable masks based on the GPE type
+ * DESCRIPTION: Updates GPE register enable masks based upon whether there are
+ *              references (either wake or run) to this GPE
  *
  ******************************************************************************/
 
@@ -81,14 +82,20 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info)
            (1 <<
             (gpe_event_info->gpe_number - gpe_register_info->base_gpe_number));
 
+       /* Clear the wake/run bits up front */
+
        ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake, register_bit);
        ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
 
-       if (gpe_event_info->runtime_count)
+       /* Set the mask bits only if there are references to this GPE */
+
+       if (gpe_event_info->runtime_count) {
                ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
+       }
 
-       if (gpe_event_info->wakeup_count)
+       if (gpe_event_info->wakeup_count) {
                ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
+       }
 
        return_ACPI_STATUS(AE_OK);
 }
@@ -101,7 +108,10 @@ acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info)
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Enable a GPE based on the GPE type
+ * DESCRIPTION: Hardware-enable a GPE. Always enables the GPE, regardless
+ *              of type or number of references.
+ *
+ * Note: The GPE lock should be already acquired when this function is called.
  *
  ******************************************************************************/
 
@@ -109,20 +119,36 @@ acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
 {
        acpi_status status;
 
+
        ACPI_FUNCTION_TRACE(ev_enable_gpe);
 
-       /* Make sure HW enable masks are updated */
+
+       /*
+        * We will only allow a GPE to be enabled if it has either an
+        * associated method (_Lxx/_Exx) or a handler. Otherwise, the
+        * GPE will be immediately disabled by acpi_ev_gpe_dispatch the
+        * first time it fires.
+        */
+       if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)) {
+               return_ACPI_STATUS(AE_NO_HANDLER);
+       }
+
+       /* Ensure the HW enable masks are current */
 
        status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
-       if (ACPI_FAILURE(status))
+       if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
+       }
+
+       /* Clear the GPE (of stale events) */
 
-       /* Clear the GPE (of stale events), then enable it */
        status = acpi_hw_clear_gpe(gpe_event_info);
-       if (ACPI_FAILURE(status))
+       if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
+       }
 
        /* Enable the requested GPE */
+
        status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
        return_ACPI_STATUS(status);
 }
@@ -135,7 +161,10 @@ acpi_status acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info)
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Disable a GPE based on the GPE type
+ * DESCRIPTION: Hardware-disable a GPE. Always disables the requested GPE,
+ *              regardless of the type or number of references.
+ *
+ * Note: The GPE lock should be already acquired when this function is called.
  *
  ******************************************************************************/
 
@@ -145,24 +174,71 @@ acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
 
        ACPI_FUNCTION_TRACE(ev_disable_gpe);
 
-       /* Make sure HW enable masks are updated */
+
+       /*
+        * Note: Always disable the GPE, even if we think that that it is already
+        * disabled. It is possible that the AML or some other code has enabled
+        * the GPE behind our back.
+        */
+
+       /* Ensure the HW enable masks are current */
 
        status = acpi_ev_update_gpe_enable_masks(gpe_event_info);
-       if (ACPI_FAILURE(status))
+       if (ACPI_FAILURE(status)) {
                return_ACPI_STATUS(status);
+       }
 
        /*
-        * Even if we don't know the GPE type, make sure that we always
-        * disable it. low_disable_gpe will just clear the enable bit for this
-        * GPE and write it. It will not write out the current GPE enable mask,
-        * since this may inadvertently enable GPEs too early, if a rogue GPE has
-        * come in during ACPICA initialization - possibly as a result of AML or
-        * other code that has enabled the GPE.
+        * Always H/W disable this GPE, even if we don't know the GPE type.
+        * Simply clear the enable bit for this particular GPE, but do not
+        * write out the current GPE enable mask since this may inadvertently
+        * enable GPEs too early. An example is a rogue GPE that has arrived
+        * during ACPICA initialization - possibly because AML or other code
+        * has enabled the GPE.
         */
        status = acpi_hw_low_disable_gpe(gpe_event_info);
        return_ACPI_STATUS(status);
 }
 
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_low_get_gpe_info
+ *
+ * PARAMETERS:  gpe_number          - Raw GPE number
+ *              gpe_block           - A GPE info block
+ *
+ * RETURN:      A GPE event_info struct. NULL if not a valid GPE (The gpe_number
+ *              is not within the specified GPE block)
+ *
+ * DESCRIPTION: Returns the event_info struct associated with this GPE. This is
+ *              the low-level implementation of ev_get_gpe_event_info.
+ *
+ ******************************************************************************/
+
+struct acpi_gpe_event_info *acpi_ev_low_get_gpe_info(u32 gpe_number,
+                                                    struct acpi_gpe_block_info
+                                                    *gpe_block)
+{
+       u32 gpe_index;
+
+       /*
+        * Validate that the gpe_number is within the specified gpe_block.
+        * (Two steps)
+        */
+       if (!gpe_block || (gpe_number < gpe_block->block_base_number)) {
+               return (NULL);
+       }
+
+       gpe_index = gpe_number - gpe_block->block_base_number;
+       if (gpe_index >= gpe_block->gpe_count) {
+               return (NULL);
+       }
+
+       return (&gpe_block->event_info[gpe_index]);
+}
+
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_get_gpe_event_info
@@ -184,29 +260,23 @@ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
                                                       u32 gpe_number)
 {
        union acpi_operand_object *obj_desc;
-       struct acpi_gpe_block_info *gpe_block;
+       struct acpi_gpe_event_info *gpe_info;
        u32 i;
 
        ACPI_FUNCTION_ENTRY();
 
-       /* A NULL gpe_block means use the FADT-defined GPE block(s) */
+       /* A NULL gpe_device means use the FADT-defined GPE block(s) */
 
        if (!gpe_device) {
 
                /* Examine GPE Block 0 and 1 (These blocks are permanent) */
 
                for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
-                       gpe_block = acpi_gbl_gpe_fadt_blocks[i];
-                       if (gpe_block) {
-                               if ((gpe_number >= gpe_block->block_base_number)
-                                   && (gpe_number <
-                                       gpe_block->block_base_number +
-                                       (gpe_block->register_count * 8))) {
-                                       return (&gpe_block->
-                                               event_info[gpe_number -
-                                                          gpe_block->
-                                                          block_base_number]);
-                               }
+                       gpe_info = acpi_ev_low_get_gpe_info(gpe_number,
+                                                           acpi_gbl_gpe_fadt_blocks
+                                                           [i]);
+                       if (gpe_info) {
+                               return (gpe_info);
                        }
                }
 
@@ -223,16 +293,8 @@ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
                return (NULL);
        }
 
-       gpe_block = obj_desc->device.gpe_block;
-
-       if ((gpe_number >= gpe_block->block_base_number) &&
-           (gpe_number <
-            gpe_block->block_base_number + (gpe_block->register_count * 8))) {
-               return (&gpe_block->
-                       event_info[gpe_number - gpe_block->block_base_number]);
-       }
-
-       return (NULL);
+       return (acpi_ev_low_get_gpe_info
+               (gpe_number, obj_desc->device.gpe_block));
 }
 
 /*******************************************************************************
@@ -389,7 +451,7 @@ static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
                return_VOID;
        }
 
-       /* Set the GPE flags for return to enabled state */
+       /* Update the GPE register masks for return to enabled state */
 
        (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
 
@@ -499,7 +561,7 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                status = acpi_hw_clear_gpe(gpe_event_info);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Unable to clear GPE[%2X]",
+                                       "Unable to clear GPE[0x%2X]",
                                        gpe_number));
                        return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
                }
@@ -532,7 +594,7 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                        status = acpi_hw_clear_gpe(gpe_event_info);
                        if (ACPI_FAILURE(status)) {
                                ACPI_EXCEPTION((AE_INFO, status,
-                                               "Unable to clear GPE[%2X]",
+                                       "Unable to clear GPE[0x%2X]",
                                                gpe_number));
                                return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
                        }
@@ -548,7 +610,7 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                status = acpi_ev_disable_gpe(gpe_event_info);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Unable to disable GPE[%2X]",
+                                       "Unable to disable GPE[0x%2X]",
                                        gpe_number));
                        return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
                }
@@ -562,27 +624,30 @@ acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
                                         gpe_event_info);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Unable to queue handler for GPE[%2X] - event disabled",
+                                       "Unable to queue handler for GPE[0x%2X] - event disabled",
                                        gpe_number));
                }
                break;
 
        default:
 
-               /* No handler or method to run! */
-
+               /*
+                * No handler or method to run!
+                * 03/2010: This case should no longer be possible. We will not allow
+                * a GPE to be enabled if it has no handler or method.
+                */
                ACPI_ERROR((AE_INFO,
-                           "No handler or method for GPE[%2X], disabling event",
+                           "No handler or method for GPE[0x%2X], disabling event",
                            gpe_number));
 
                /*
-                * Disable the GPE. The GPE will remain disabled until the ACPICA
-                * Core Subsystem is restarted, or a handler is installed.
+                * Disable the GPE. The GPE will remain disabled a handler
+                * is installed or ACPICA is restarted.
                 */
                status = acpi_ev_disable_gpe(gpe_event_info);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Unable to disable GPE[%2X]",
+                                       "Unable to disable GPE[0x%2X]",
                                        gpe_number));
                        return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
                }
index fef7219..7c28f2d 100644 (file)
 ACPI_MODULE_NAME("evgpeblk")
 
 /* Local prototypes */
-static acpi_status
-acpi_ev_save_method_info(acpi_handle obj_handle,
-                        u32 level, void *obj_desc, void **return_value);
-
-static acpi_status
-acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
-                         u32 level, void *info, void **return_value);
-
-static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
-                                                              interrupt_number);
-
-static acpi_status
-acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
-
 static acpi_status
 acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
                          u32 interrupt_number);
@@ -71,527 +57,6 @@ acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
 static acpi_status
 acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_valid_gpe_event
- *
- * PARAMETERS:  gpe_event_info              - Info for this GPE
- *
- * RETURN:      TRUE if the gpe_event is valid
- *
- * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
- *              Should be called only when the GPE lists are semaphore locked
- *              and not subject to change.
- *
- ******************************************************************************/
-
-u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
-{
-       struct acpi_gpe_xrupt_info *gpe_xrupt_block;
-       struct acpi_gpe_block_info *gpe_block;
-
-       ACPI_FUNCTION_ENTRY();
-
-       /* No need for spin lock since we are not changing any list elements */
-
-       /* Walk the GPE interrupt levels */
-
-       gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
-       while (gpe_xrupt_block) {
-               gpe_block = gpe_xrupt_block->gpe_block_list_head;
-
-               /* Walk the GPE blocks on this interrupt level */
-
-               while (gpe_block) {
-                       if ((&gpe_block->event_info[0] <= gpe_event_info) &&
-                           (&gpe_block->event_info[((acpi_size)
-                                                    gpe_block->
-                                                    register_count) * 8] >
-                            gpe_event_info)) {
-                               return (TRUE);
-                       }
-
-                       gpe_block = gpe_block->next;
-               }
-
-               gpe_xrupt_block = gpe_xrupt_block->next;
-       }
-
-       return (FALSE);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_walk_gpe_list
- *
- * PARAMETERS:  gpe_walk_callback   - Routine called for each GPE block
- *              Context             - Value passed to callback
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Walk the GPE lists.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
-{
-       struct acpi_gpe_block_info *gpe_block;
-       struct acpi_gpe_xrupt_info *gpe_xrupt_info;
-       acpi_status status = AE_OK;
-       acpi_cpu_flags flags;
-
-       ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
-
-       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
-
-       /* Walk the interrupt level descriptor list */
-
-       gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
-       while (gpe_xrupt_info) {
-
-               /* Walk all Gpe Blocks attached to this interrupt level */
-
-               gpe_block = gpe_xrupt_info->gpe_block_list_head;
-               while (gpe_block) {
-
-                       /* One callback per GPE block */
-
-                       status =
-                           gpe_walk_callback(gpe_xrupt_info, gpe_block,
-                                             context);
-                       if (ACPI_FAILURE(status)) {
-                               if (status == AE_CTRL_END) {    /* Callback abort */
-                                       status = AE_OK;
-                               }
-                               goto unlock_and_exit;
-                       }
-
-                       gpe_block = gpe_block->next;
-               }
-
-               gpe_xrupt_info = gpe_xrupt_info->next;
-       }
-
-      unlock_and_exit:
-       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
-       return_ACPI_STATUS(status);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_delete_gpe_handlers
- *
- * PARAMETERS:  gpe_xrupt_info      - GPE Interrupt info
- *              gpe_block           - Gpe Block info
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
- *              Used only prior to termination.
- *
- ******************************************************************************/
-
-acpi_status
-acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
-                           struct acpi_gpe_block_info *gpe_block,
-                           void *context)
-{
-       struct acpi_gpe_event_info *gpe_event_info;
-       u32 i;
-       u32 j;
-
-       ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
-
-       /* Examine each GPE Register within the block */
-
-       for (i = 0; i < gpe_block->register_count; i++) {
-
-               /* Now look at the individual GPEs in this byte register */
-
-               for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
-                       gpe_event_info = &gpe_block->event_info[((acpi_size) i *
-                                                                ACPI_GPE_REGISTER_WIDTH)
-                                                               + j];
-
-                       if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
-                           ACPI_GPE_DISPATCH_HANDLER) {
-                               ACPI_FREE(gpe_event_info->dispatch.handler);
-                               gpe_event_info->dispatch.handler = NULL;
-                               gpe_event_info->flags &=
-                                   ~ACPI_GPE_DISPATCH_MASK;
-                       }
-               }
-       }
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_save_method_info
- *
- * PARAMETERS:  Callback from walk_namespace
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
- *              control method under the _GPE portion of the namespace.
- *              Extract the name and GPE type from the object, saving this
- *              information for quick lookup during GPE dispatch
- *
- *              The name of each GPE control method is of the form:
- *              "_Lxx" or "_Exx"
- *              Where:
- *                  L      - means that the GPE is level triggered
- *                  E      - means that the GPE is edge triggered
- *                  xx     - is the GPE number [in HEX]
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_ev_save_method_info(acpi_handle obj_handle,
-                        u32 level, void *obj_desc, void **return_value)
-{
-       struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
-       struct acpi_gpe_event_info *gpe_event_info;
-       u32 gpe_number;
-       char name[ACPI_NAME_SIZE + 1];
-       u8 type;
-
-       ACPI_FUNCTION_TRACE(ev_save_method_info);
-
-       /*
-        * _Lxx and _Exx GPE method support
-        *
-        * 1) Extract the name from the object and convert to a string
-        */
-       ACPI_MOVE_32_TO_32(name,
-                          &((struct acpi_namespace_node *)obj_handle)->name.
-                          integer);
-       name[ACPI_NAME_SIZE] = 0;
-
-       /*
-        * 2) Edge/Level determination is based on the 2nd character
-        *    of the method name
-        *
-        * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
-        * if a _PRW object is found that points to this GPE.
-        */
-       switch (name[1]) {
-       case 'L':
-               type = ACPI_GPE_LEVEL_TRIGGERED;
-               break;
-
-       case 'E':
-               type = ACPI_GPE_EDGE_TRIGGERED;
-               break;
-
-       default:
-               /* Unknown method type, just ignore it! */
-
-               ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
-                                 "Ignoring unknown GPE method type: %s "
-                                 "(name not of form _Lxx or _Exx)", name));
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* Convert the last two characters of the name to the GPE Number */
-
-       gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
-       if (gpe_number == ACPI_UINT32_MAX) {
-
-               /* Conversion failed; invalid method, just ignore it */
-
-               ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
-                                 "Could not extract GPE number from name: %s "
-                                 "(name is not of form _Lxx or _Exx)", name));
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* Ensure that we have a valid GPE number for this GPE block */
-
-       if ((gpe_number < gpe_block->block_base_number) ||
-           (gpe_number >= (gpe_block->block_base_number +
-                           (gpe_block->register_count * 8)))) {
-               /*
-                * Not valid for this GPE block, just ignore it. However, it may be
-                * valid for a different GPE block, since GPE0 and GPE1 methods both
-                * appear under \_GPE.
-                */
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /*
-        * Now we can add this information to the gpe_event_info block for use
-        * during dispatch of this GPE.
-        */
-       gpe_event_info =
-           &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
-
-       gpe_event_info->flags = (u8) (type | ACPI_GPE_DISPATCH_METHOD);
-
-       gpe_event_info->dispatch.method_node =
-           (struct acpi_namespace_node *)obj_handle;
-
-       ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
-                         "Registered GPE method %s as GPE number 0x%.2X\n",
-                         name, gpe_number));
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_match_prw_and_gpe
- *
- * PARAMETERS:  Callback from walk_namespace
- *
- * RETURN:      Status. NOTE: We ignore errors so that the _PRW walk is
- *              not aborted on a single _PRW failure.
- *
- * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
- *              Device. Run the _PRW method. If present, extract the GPE
- *              number and mark the GPE as a WAKE GPE.
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
-                         u32 level, void *info, void **return_value)
-{
-       struct acpi_gpe_walk_info *gpe_info = (void *)info;
-       struct acpi_namespace_node *gpe_device;
-       struct acpi_gpe_block_info *gpe_block;
-       struct acpi_namespace_node *target_gpe_device;
-       struct acpi_gpe_event_info *gpe_event_info;
-       union acpi_operand_object *pkg_desc;
-       union acpi_operand_object *obj_desc;
-       u32 gpe_number;
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
-
-       /* Check for a _PRW method under this device */
-
-       status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
-                                        ACPI_BTYPE_PACKAGE, &pkg_desc);
-       if (ACPI_FAILURE(status)) {
-
-               /* Ignore all errors from _PRW, we don't want to abort the subsystem */
-
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* The returned _PRW package must have at least two elements */
-
-       if (pkg_desc->package.count < 2) {
-               goto cleanup;
-       }
-
-       /* Extract pointers from the input context */
-
-       gpe_device = gpe_info->gpe_device;
-       gpe_block = gpe_info->gpe_block;
-
-       /*
-        * The _PRW object must return a package, we are only interested in the
-        * first element
-        */
-       obj_desc = pkg_desc->package.elements[0];
-
-       if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
-
-               /* Use FADT-defined GPE device (from definition of _PRW) */
-
-               target_gpe_device = acpi_gbl_fadt_gpe_device;
-
-               /* Integer is the GPE number in the FADT described GPE blocks */
-
-               gpe_number = (u32) obj_desc->integer.value;
-       } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
-
-               /* Package contains a GPE reference and GPE number within a GPE block */
-
-               if ((obj_desc->package.count < 2) ||
-                   ((obj_desc->package.elements[0])->common.type !=
-                    ACPI_TYPE_LOCAL_REFERENCE) ||
-                   ((obj_desc->package.elements[1])->common.type !=
-                    ACPI_TYPE_INTEGER)) {
-                       goto cleanup;
-               }
-
-               /* Get GPE block reference and decode */
-
-               target_gpe_device =
-                   obj_desc->package.elements[0]->reference.node;
-               gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
-       } else {
-               /* Unknown type, just ignore it */
-
-               goto cleanup;
-       }
-
-       /*
-        * Is this GPE within this block?
-        *
-        * TRUE if and only if these conditions are true:
-        *     1) The GPE devices match.
-        *     2) The GPE index(number) is within the range of the Gpe Block
-        *          associated with the GPE device.
-        */
-       if ((gpe_device == target_gpe_device) &&
-           (gpe_number >= gpe_block->block_base_number) &&
-           (gpe_number < gpe_block->block_base_number +
-            (gpe_block->register_count * 8))) {
-               gpe_event_info = &gpe_block->event_info[gpe_number -
-                                                       gpe_block->
-                                                       block_base_number];
-
-               gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
-       }
-
-      cleanup:
-       acpi_ut_remove_reference(pkg_desc);
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_get_gpe_xrupt_block
- *
- * PARAMETERS:  interrupt_number     - Interrupt for a GPE block
- *
- * RETURN:      A GPE interrupt block
- *
- * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
- *              block per unique interrupt level used for GPEs. Should be
- *              called only when the GPE lists are semaphore locked and not
- *              subject to change.
- *
- ******************************************************************************/
-
-static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
-                                                              interrupt_number)
-{
-       struct acpi_gpe_xrupt_info *next_gpe_xrupt;
-       struct acpi_gpe_xrupt_info *gpe_xrupt;
-       acpi_status status;
-       acpi_cpu_flags flags;
-
-       ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
-
-       /* No need for lock since we are not changing any list elements here */
-
-       next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
-       while (next_gpe_xrupt) {
-               if (next_gpe_xrupt->interrupt_number == interrupt_number) {
-                       return_PTR(next_gpe_xrupt);
-               }
-
-               next_gpe_xrupt = next_gpe_xrupt->next;
-       }
-
-       /* Not found, must allocate a new xrupt descriptor */
-
-       gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
-       if (!gpe_xrupt) {
-               return_PTR(NULL);
-       }
-
-       gpe_xrupt->interrupt_number = interrupt_number;
-
-       /* Install new interrupt descriptor with spin lock */
-
-       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
-       if (acpi_gbl_gpe_xrupt_list_head) {
-               next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
-               while (next_gpe_xrupt->next) {
-                       next_gpe_xrupt = next_gpe_xrupt->next;
-               }
-
-               next_gpe_xrupt->next = gpe_xrupt;
-               gpe_xrupt->previous = next_gpe_xrupt;
-       } else {
-               acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
-       }
-       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
-
-       /* Install new interrupt handler if not SCI_INT */
-
-       if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
-               status = acpi_os_install_interrupt_handler(interrupt_number,
-                                                          acpi_ev_gpe_xrupt_handler,
-                                                          gpe_xrupt);
-               if (ACPI_FAILURE(status)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "Could not install GPE interrupt handler at level 0x%X",
-                                   interrupt_number));
-                       return_PTR(NULL);
-               }
-       }
-
-       return_PTR(gpe_xrupt);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_delete_gpe_xrupt
- *
- * PARAMETERS:  gpe_xrupt       - A GPE interrupt info block
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
- *              interrupt handler if not the SCI interrupt.
- *
- ******************************************************************************/
-
-static acpi_status
-acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
-{
-       acpi_status status;
-       acpi_cpu_flags flags;
-
-       ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
-
-       /* We never want to remove the SCI interrupt handler */
-
-       if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
-               gpe_xrupt->gpe_block_list_head = NULL;
-               return_ACPI_STATUS(AE_OK);
-       }
-
-       /* Disable this interrupt */
-
-       status =
-           acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
-                                            acpi_ev_gpe_xrupt_handler);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /* Unlink the interrupt block with lock */
-
-       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
-       if (gpe_xrupt->previous) {
-               gpe_xrupt->previous->next = gpe_xrupt->next;
-       } else {
-               /* No previous, update list head */
-
-               acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
-       }
-
-       if (gpe_xrupt->next) {
-               gpe_xrupt->next->previous = gpe_xrupt->previous;
-       }
-       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
-
-       /* Free the block */
-
-       ACPI_FREE(gpe_xrupt);
-       return_ACPI_STATUS(AE_OK);
-}
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ev_install_gpe_block
@@ -705,8 +170,7 @@ acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
                acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
        }
 
-       acpi_current_gpe_count -=
-           gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH;
+       acpi_current_gpe_count -= gpe_block->gpe_count;
 
        /* Free the gpe_block */
 
@@ -760,9 +224,7 @@ acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
         * Allocate the GPE event_info block. There are eight distinct GPEs
         * per register. Initialization to zeros is sufficient.
         */
-       gpe_event_info = ACPI_ALLOCATE_ZEROED(((acpi_size) gpe_block->
-                                              register_count *
-                                              ACPI_GPE_REGISTER_WIDTH) *
+       gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
                                              sizeof(struct
                                                     acpi_gpe_event_info));
        if (!gpe_event_info) {
@@ -880,6 +342,7 @@ acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
 {
        acpi_status status;
        struct acpi_gpe_block_info *gpe_block;
+       struct acpi_gpe_walk_info walk_info;
 
        ACPI_FUNCTION_TRACE(ev_create_gpe_block);
 
@@ -897,6 +360,7 @@ acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
        /* Initialize the new GPE block */
 
        gpe_block->node = gpe_device;
+       gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
        gpe_block->register_count = register_count;
        gpe_block->block_base_number = gpe_block_base_number;
 
@@ -921,12 +385,17 @@ acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
                return_ACPI_STATUS(status);
        }
 
-       /* Find all GPE methods (_Lxx, _Exx) for this block */
+       /* Find all GPE methods (_Lxx or_Exx) for this block */
+
+       walk_info.gpe_block = gpe_block;
+       walk_info.gpe_device = gpe_device;
+       walk_info.enable_this_gpe = FALSE;
+       walk_info.execute_by_owner_id = FALSE;
 
        status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
                                        ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
-                                       acpi_ev_save_method_info, NULL,
-                                       gpe_block, NULL);
+                                       acpi_ev_match_gpe_method, NULL,
+                                       &walk_info, NULL);
 
        /* Return the new block */
 
@@ -938,14 +407,13 @@ acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
                          "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
                          (u32) gpe_block->block_base_number,
                          (u32) (gpe_block->block_base_number +
-                                ((gpe_block->register_count *
-                                  ACPI_GPE_REGISTER_WIDTH) - 1)),
+                               (gpe_block->gpe_count - 1)),
                          gpe_device->name.ascii, gpe_block->register_count,
                          interrupt_number));
 
        /* Update global count of currently available GPEs */
 
-       acpi_current_gpe_count += register_count * ACPI_GPE_REGISTER_WIDTH;
+       acpi_current_gpe_count += gpe_block->gpe_count;
        return_ACPI_STATUS(AE_OK);
 }
 
@@ -969,10 +437,13 @@ acpi_status
 acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
                             struct acpi_gpe_block_info *gpe_block)
 {
+       acpi_status status;
        struct acpi_gpe_event_info *gpe_event_info;
-       struct acpi_gpe_walk_info gpe_info;
+       struct acpi_gpe_walk_info walk_info;
        u32 wake_gpe_count;
        u32 gpe_enabled_count;
+       u32 gpe_index;
+       u32 gpe_number;
        u32 i;
        u32 j;
 
@@ -995,210 +466,75 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
                 * definition a wake GPE and will not be enabled while the machine
                 * is running.
                 */
-               gpe_info.gpe_block = gpe_block;
-               gpe_info.gpe_device = gpe_device;
+               walk_info.gpe_block = gpe_block;
+               walk_info.gpe_device = gpe_device;
+               walk_info.execute_by_owner_id = FALSE;
 
-               acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+               status =
+                   acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
                                           ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
                                           acpi_ev_match_prw_and_gpe, NULL,
-                                          &gpe_info, NULL);
+                                          &walk_info, NULL);
+               if (ACPI_FAILURE(status)) {
+                       ACPI_EXCEPTION((AE_INFO, status,
+                                       "While executing _PRW methods"));
+               }
        }
 
        /*
-        * Enable all GPEs that have a corresponding method and aren't
+        * Enable all GPEs that have a corresponding method and are not
         * capable of generating wakeups. Any other GPEs within this block
-        * must be enabled via the acpi_enable_gpe() interface.
+        * must be enabled via the acpi_enable_gpe interface.
         */
        wake_gpe_count = 0;
        gpe_enabled_count = 0;
-       if (gpe_device == acpi_gbl_fadt_gpe_device)
+
+       if (gpe_device == acpi_gbl_fadt_gpe_device) {
                gpe_device = NULL;
+       }
 
        for (i = 0; i < gpe_block->register_count; i++) {
                for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
-                       acpi_status status;
-                       acpi_size gpe_index;
-                       int gpe_number;
 
                        /* Get the info block for this particular GPE */
-                       gpe_index = (acpi_size)i * ACPI_GPE_REGISTER_WIDTH + j;
+
+                       gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
                        gpe_event_info = &gpe_block->event_info[gpe_index];
 
                        if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
                                wake_gpe_count++;
-                               if (acpi_gbl_leave_wake_gpes_disabled)
+                               if (acpi_gbl_leave_wake_gpes_disabled) {
                                        continue;
+                               }
                        }
 
-                       if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD))
+                       /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
+
+                       if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
                                continue;
+                       }
+
+                       /* Enable this GPE */
 
                        gpe_number = gpe_index + gpe_block->block_base_number;
                        status = acpi_enable_gpe(gpe_device, gpe_number,
-                                               ACPI_GPE_TYPE_RUNTIME);
-                       if (ACPI_FAILURE(status))
-                               ACPI_ERROR((AE_INFO,
-                                               "Failed to enable GPE %02X\n",
-                                               gpe_number));
-                       else
-                               gpe_enabled_count++;
-               }
-       }
-
-       ACPI_DEBUG_PRINT((ACPI_DB_INIT,
-                         "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
-                         wake_gpe_count, gpe_enabled_count));
-
-       return_ACPI_STATUS(AE_OK);
-}
-
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ev_gpe_initialize
- *
- * PARAMETERS:  None
- *
- * RETURN:      Status
- *
- * DESCRIPTION: Initialize the GPE data structures
- *
- ******************************************************************************/
-
-acpi_status acpi_ev_gpe_initialize(void)
-{
-       u32 register_count0 = 0;
-       u32 register_count1 = 0;
-       u32 gpe_number_max = 0;
-       acpi_status status;
-
-       ACPI_FUNCTION_TRACE(ev_gpe_initialize);
-
-       status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
-       if (ACPI_FAILURE(status)) {
-               return_ACPI_STATUS(status);
-       }
-
-       /*
-        * Initialize the GPE Block(s) defined in the FADT
-        *
-        * Why the GPE register block lengths are divided by 2:  From the ACPI
-        * Spec, section "General-Purpose Event Registers", we have:
-        *
-        * "Each register block contains two registers of equal length
-        *  GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
-        *  GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
-        *  The length of the GPE1_STS and GPE1_EN registers is equal to
-        *  half the GPE1_LEN. If a generic register block is not supported
-        *  then its respective block pointer and block length values in the
-        *  FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
-        *  to be the same size."
-        */
-
-       /*
-        * Determine the maximum GPE number for this machine.
-        *
-        * Note: both GPE0 and GPE1 are optional, and either can exist without
-        * the other.
-        *
-        * If EITHER the register length OR the block address are zero, then that
-        * particular block is not supported.
-        */
-       if (acpi_gbl_FADT.gpe0_block_length &&
-           acpi_gbl_FADT.xgpe0_block.address) {
-
-               /* GPE block 0 exists (has both length and address > 0) */
-
-               register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
-
-               gpe_number_max =
-                   (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
-
-               /* Install GPE Block 0 */
-
-               status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
-                                                 &acpi_gbl_FADT.xgpe0_block,
-                                                 register_count0, 0,
-                                                 acpi_gbl_FADT.sci_interrupt,
-                                                 &acpi_gbl_gpe_fadt_blocks[0]);
-
-               if (ACPI_FAILURE(status)) {
-                       ACPI_EXCEPTION((AE_INFO, status,
-                                       "Could not create GPE Block 0"));
-               }
-       }
-
-       if (acpi_gbl_FADT.gpe1_block_length &&
-           acpi_gbl_FADT.xgpe1_block.address) {
-
-               /* GPE block 1 exists (has both length and address > 0) */
-
-               register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
-
-               /* Check for GPE0/GPE1 overlap (if both banks exist) */
-
-               if ((register_count0) &&
-                   (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
-                       ACPI_ERROR((AE_INFO,
-                                   "GPE0 block (GPE 0 to %d) overlaps the GPE1 block "
-                                   "(GPE %d to %d) - Ignoring GPE1",
-                                   gpe_number_max, acpi_gbl_FADT.gpe1_base,
-                                   acpi_gbl_FADT.gpe1_base +
-                                   ((register_count1 *
-                                     ACPI_GPE_REGISTER_WIDTH) - 1)));
-
-                       /* Ignore GPE1 block by setting the register count to zero */
-
-                       register_count1 = 0;
-               } else {
-                       /* Install GPE Block 1 */
-
-                       status =
-                           acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
-                                                    &acpi_gbl_FADT.xgpe1_block,
-                                                    register_count1,
-                                                    acpi_gbl_FADT.gpe1_base,
-                                                    acpi_gbl_FADT.
-                                                    sci_interrupt,
-                                                    &acpi_gbl_gpe_fadt_blocks
-                                                    [1]);
-
+                                                ACPI_GPE_TYPE_RUNTIME);
                        if (ACPI_FAILURE(status)) {
                                ACPI_EXCEPTION((AE_INFO, status,
-                                               "Could not create GPE Block 1"));
+                                               "Could not enable GPE 0x%02X",
+                                               gpe_number));
+                               continue;
                        }
 
-                       /*
-                        * GPE0 and GPE1 do not have to be contiguous in the GPE number
-                        * space. However, GPE0 always starts at GPE number zero.
-                        */
-                       gpe_number_max = acpi_gbl_FADT.gpe1_base +
-                           ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
+                       gpe_enabled_count++;
                }
        }
 
-       /* Exit if there are no GPE registers */
-
-       if ((register_count0 + register_count1) == 0) {
-
-               /* GPEs are not required by ACPI, this is OK */
-
+       if (gpe_enabled_count || wake_gpe_count) {
                ACPI_DEBUG_PRINT((ACPI_DB_INIT,
-                                 "There are no GPE blocks defined in the FADT\n"));
-               status = AE_OK;
-               goto cleanup;
-       }
-
-       /* Check for Max GPE number out-of-range */
-
-       if (gpe_number_max > ACPI_GPE_MAX) {
-               ACPI_ERROR((AE_INFO,
-                           "Maximum GPE number from FADT is too large: 0x%X",
-                           gpe_number_max));
-               status = AE_BAD_VALUE;
-               goto cleanup;
+                                 "Enabled %u Runtime GPEs, added %u Wake GPEs in this block\n",
+                                 gpe_enabled_count, wake_gpe_count));
        }
 
-      cleanup:
-       (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
        return_ACPI_STATUS(AE_OK);
 }
diff --git a/drivers/acpi/acpica/evgpeinit.c b/drivers/acpi/acpica/evgpeinit.c
new file mode 100644 (file)
index 0000000..3f6c2d2
--- /dev/null
@@ -0,0 +1,653 @@
+/******************************************************************************
+ *
+ * Module Name: evgpeinit - System GPE initialization and update
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2010, Intel Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include "accommon.h"
+#include "acevents.h"
+#include "acnamesp.h"
+#include "acinterp.h"
+
+#define _COMPONENT          ACPI_EVENTS
+ACPI_MODULE_NAME("evgpeinit")
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_gpe_initialize
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Initialize the GPE data structures and the FADT GPE 0/1 blocks
+ *
+ ******************************************************************************/
+acpi_status acpi_ev_gpe_initialize(void)
+{
+       u32 register_count0 = 0;
+       u32 register_count1 = 0;
+       u32 gpe_number_max = 0;
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(ev_gpe_initialize);
+
+       status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
+       /*
+        * Initialize the GPE Block(s) defined in the FADT
+        *
+        * Why the GPE register block lengths are divided by 2:  From the ACPI
+        * Spec, section "General-Purpose Event Registers", we have:
+        *
+        * "Each register block contains two registers of equal length
+        *  GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
+        *  GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
+        *  The length of the GPE1_STS and GPE1_EN registers is equal to
+        *  half the GPE1_LEN. If a generic register block is not supported
+        *  then its respective block pointer and block length values in the
+        *  FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
+        *  to be the same size."
+        */
+
+       /*
+        * Determine the maximum GPE number for this machine.
+        *
+        * Note: both GPE0 and GPE1 are optional, and either can exist without
+        * the other.
+        *
+        * If EITHER the register length OR the block address are zero, then that
+        * particular block is not supported.
+        */
+       if (acpi_gbl_FADT.gpe0_block_length &&
+           acpi_gbl_FADT.xgpe0_block.address) {
+
+               /* GPE block 0 exists (has both length and address > 0) */
+
+               register_count0 = (u16)(acpi_gbl_FADT.gpe0_block_length / 2);
+
+               gpe_number_max =
+                   (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
+
+               /* Install GPE Block 0 */
+
+               status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
+                                                 &acpi_gbl_FADT.xgpe0_block,
+                                                 register_count0, 0,
+                                                 acpi_gbl_FADT.sci_interrupt,
+                                                 &acpi_gbl_gpe_fadt_blocks[0]);
+
+               if (ACPI_FAILURE(status)) {
+                       ACPI_EXCEPTION((AE_INFO, status,
+                                       "Could not create GPE Block 0"));
+               }
+       }
+
+       if (acpi_gbl_FADT.gpe1_block_length &&
+           acpi_gbl_FADT.xgpe1_block.address) {
+
+               /* GPE block 1 exists (has both length and address > 0) */
+
+               register_count1 = (u16)(acpi_gbl_FADT.gpe1_block_length / 2);
+
+               /* Check for GPE0/GPE1 overlap (if both banks exist) */
+
+               if ((register_count0) &&
+                   (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
+                                   "(GPE %u to %u) - Ignoring GPE1",
+                                   gpe_number_max, acpi_gbl_FADT.gpe1_base,
+                                   acpi_gbl_FADT.gpe1_base +
+                                   ((register_count1 *
+                                     ACPI_GPE_REGISTER_WIDTH) - 1)));
+
+                       /* Ignore GPE1 block by setting the register count to zero */
+
+                       register_count1 = 0;
+               } else {
+                       /* Install GPE Block 1 */
+
+                       status =
+                           acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
+                                                    &acpi_gbl_FADT.xgpe1_block,
+                                                    register_count1,
+                                                    acpi_gbl_FADT.gpe1_base,
+                                                    acpi_gbl_FADT.
+                                                    sci_interrupt,
+                                                    &acpi_gbl_gpe_fadt_blocks
+                                                    [1]);
+
+                       if (ACPI_FAILURE(status)) {
+                               ACPI_EXCEPTION((AE_INFO, status,
+                                               "Could not create GPE Block 1"));
+                       }
+
+                       /*
+                        * GPE0 and GPE1 do not have to be contiguous in the GPE number
+                        * space. However, GPE0 always starts at GPE number zero.
+                        */
+                       gpe_number_max = acpi_gbl_FADT.gpe1_base +
+                           ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
+               }
+       }
+
+       /* Exit if there are no GPE registers */
+
+       if ((register_count0 + register_count1) == 0) {
+
+               /* GPEs are not required by ACPI, this is OK */
+
+               ACPI_DEBUG_PRINT((ACPI_DB_INIT,
+                                 "There are no GPE blocks defined in the FADT\n"));
+               status = AE_OK;
+               goto cleanup;
+       }
+
+       /* Check for Max GPE number out-of-range */
+
+       if (gpe_number_max > ACPI_GPE_MAX) {
+               ACPI_ERROR((AE_INFO,
+                           "Maximum GPE number from FADT is too large: 0x%X",
+                           gpe_number_max));
+               status = AE_BAD_VALUE;
+               goto cleanup;
+       }
+
+      cleanup:
+       (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_update_gpes
+ *
+ * PARAMETERS:  table_owner_id      - ID of the newly-loaded ACPI table
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
+ *              result of a Load() or load_table() operation. If new GPE
+ *              methods have been installed, register the new methods and
+ *              enable and runtime GPEs that are associated with them. Also,
+ *              run any newly loaded _PRW methods in order to discover any
+ *              new CAN_WAKE GPEs.
+ *
+ ******************************************************************************/
+
+void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
+{
+       struct acpi_gpe_xrupt_info *gpe_xrupt_info;
+       struct acpi_gpe_block_info *gpe_block;
+       struct acpi_gpe_walk_info walk_info;
+       acpi_status status = AE_OK;
+       u32 new_wake_gpe_count = 0;
+
+       /* We will examine only _PRW/_Lxx/_Exx methods owned by this table */
+
+       walk_info.owner_id = table_owner_id;
+       walk_info.execute_by_owner_id = TRUE;
+       walk_info.count = 0;
+
+       if (acpi_gbl_leave_wake_gpes_disabled) {
+               /*
+                * 1) Run any newly-loaded _PRW methods to find any GPEs that
+                * can now be marked as CAN_WAKE GPEs. Note: We must run the
+                * _PRW methods before we process the _Lxx/_Exx methods because
+                * we will enable all runtime GPEs associated with the new
+                * _Lxx/_Exx methods at the time we process those methods.
+                *
+                * Unlock interpreter so that we can run the _PRW methods.
+                */
+               walk_info.gpe_block = NULL;
+               walk_info.gpe_device = NULL;
+
+               acpi_ex_exit_interpreter();
+
+               status =
+                   acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
+                                          ACPI_UINT32_MAX,
+                                          ACPI_NS_WALK_NO_UNLOCK,
+                                          acpi_ev_match_prw_and_gpe, NULL,
+                                          &walk_info, NULL);
+               if (ACPI_FAILURE(status)) {
+                       ACPI_EXCEPTION((AE_INFO, status,
+                                       "While executing _PRW methods"));
+               }
+
+               acpi_ex_enter_interpreter();
+               new_wake_gpe_count = walk_info.count;
+       }
+
+       /*
+        * 2) Find any _Lxx/_Exx GPE methods that have just been loaded.
+        *
+        * Any GPEs that correspond to new _Lxx/_Exx methods and are not
+        * marked as CAN_WAKE are immediately enabled.
+        *
+        * Examine the namespace underneath each gpe_device within the
+        * gpe_block lists.
+        */
+       status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
+       if (ACPI_FAILURE(status)) {
+               return;
+       }
+
+       walk_info.count = 0;
+       walk_info.enable_this_gpe = TRUE;
+
+       /* Walk the interrupt level descriptor list */
+
+       gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
+       while (gpe_xrupt_info) {
+
+               /* Walk all Gpe Blocks attached to this interrupt level */
+
+               gpe_block = gpe_xrupt_info->gpe_block_list_head;
+               while (gpe_block) {
+                       walk_info.gpe_block = gpe_block;
+                       walk_info.gpe_device = gpe_block->node;
+
+                       status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
+                                                       walk_info.gpe_device,
+                                                       ACPI_UINT32_MAX,
+                                                       ACPI_NS_WALK_NO_UNLOCK,
+                                                       acpi_ev_match_gpe_method,
+                                                       NULL, &walk_info, NULL);
+                       if (ACPI_FAILURE(status)) {
+                               ACPI_EXCEPTION((AE_INFO, status,
+                                               "While decoding _Lxx/_Exx methods"));
+                       }
+
+                       gpe_block = gpe_block->next;
+               }
+
+               gpe_xrupt_info = gpe_xrupt_info->next;
+       }
+
+       if (walk_info.count || new_wake_gpe_count) {
+               ACPI_INFO((AE_INFO,
+                          "Enabled %u new runtime GPEs, added %u new wakeup GPEs",
+                          walk_info.count, new_wake_gpe_count));
+       }
+
+       (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
+       return;
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_match_gpe_method
+ *
+ * PARAMETERS:  Callback from walk_namespace
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
+ *              control method under the _GPE portion of the namespace.
+ *              Extract the name and GPE type from the object, saving this
+ *              information for quick lookup during GPE dispatch. Allows a
+ *              per-owner_id evaluation if execute_by_owner_id is TRUE in the
+ *              walk_info parameter block.
+ *
+ *              The name of each GPE control method is of the form:
+ *              "_Lxx" or "_Exx", where:
+ *                  L      - means that the GPE is level triggered
+ *                  E      - means that the GPE is edge triggered
+ *                  xx     - is the GPE number [in HEX]
+ *
+ * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
+ *    with that owner.
+ * If walk_info->enable_this_gpe is TRUE, the GPE that is referred to by a GPE
+ *    method is immediately enabled (Used for Load/load_table operators)
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ev_match_gpe_method(acpi_handle obj_handle,
+                        u32 level, void *context, void **return_value)
+{
+       struct acpi_namespace_node *method_node =
+           ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
+       struct acpi_gpe_walk_info *walk_info =
+           ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
+       struct acpi_gpe_event_info *gpe_event_info;
+       struct acpi_namespace_node *gpe_device;
+       acpi_status status;
+       u32 gpe_number;
+       char name[ACPI_NAME_SIZE + 1];
+       u8 type;
+
+       ACPI_FUNCTION_TRACE(ev_match_gpe_method);
+
+       /* Check if requested owner_id matches this owner_id */
+
+       if ((walk_info->execute_by_owner_id) &&
+           (method_node->owner_id != walk_info->owner_id)) {
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /*
+        * Match and decode the _Lxx and _Exx GPE method names
+        *
+        * 1) Extract the method name and null terminate it
+        */
+       ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
+       name[ACPI_NAME_SIZE] = 0;
+
+       /* 2) Name must begin with an underscore */
+
+       if (name[0] != '_') {
+               return_ACPI_STATUS(AE_OK);      /* Ignore this method */
+       }
+
+       /*
+        * 3) Edge/Level determination is based on the 2nd character
+        *    of the method name
+        *
+        * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
+        * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
+        */
+       switch (name[1]) {
+       case 'L':
+               type = ACPI_GPE_LEVEL_TRIGGERED;
+               break;
+
+       case 'E':
+               type = ACPI_GPE_EDGE_TRIGGERED;
+               break;
+
+       default:
+               /* Unknown method type, just ignore it */
+
+               ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
+                                 "Ignoring unknown GPE method type: %s "
+                                 "(name not of form _Lxx or _Exx)", name));
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* 4) The last two characters of the name are the hex GPE Number */
+
+       gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
+       if (gpe_number == ACPI_UINT32_MAX) {
+
+               /* Conversion failed; invalid method, just ignore it */
+
+               ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
+                                 "Could not extract GPE number from name: %s "
+                                 "(name is not of form _Lxx or _Exx)", name));
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* Ensure that we have a valid GPE number for this GPE block */
+
+       gpe_event_info =
+           acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
+       if (!gpe_event_info) {
+               /*
+                * This gpe_number is not valid for this GPE block, just ignore it.
+                * However, it may be valid for a different GPE block, since GPE0
+                * and GPE1 methods both appear under \_GPE.
+                */
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
+           ACPI_GPE_DISPATCH_HANDLER) {
+
+               /* If there is already a handler, ignore this GPE method */
+
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
+           ACPI_GPE_DISPATCH_METHOD) {
+               /*
+                * If there is already a method, ignore this method. But check
+                * for a type mismatch (if both the _Lxx AND _Exx exist)
+                */
+               if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
+                                   gpe_number, gpe_number, gpe_number));
+               }
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /*
+        * Add the GPE information from above to the gpe_event_info block for
+        * use during dispatch of this GPE.
+        */
+       gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD);
+       gpe_event_info->dispatch.method_node = method_node;
+
+       /*
+        * Enable this GPE if requested. This only happens when during the
+        * execution of a Load or load_table operator. We have found a new
+        * GPE method and want to immediately enable the GPE if it is a
+        * runtime GPE.
+        */
+       if (walk_info->enable_this_gpe) {
+
+               /* Ignore GPEs that can wake the system */
+
+               if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE) ||
+                   !acpi_gbl_leave_wake_gpes_disabled) {
+                       walk_info->count++;
+                       gpe_device = walk_info->gpe_device;
+
+                       if (gpe_device == acpi_gbl_fadt_gpe_device) {
+                               gpe_device = NULL;
+                       }
+
+                       status = acpi_enable_gpe(gpe_device, gpe_number,
+                                                ACPI_GPE_TYPE_RUNTIME);
+                       if (ACPI_FAILURE(status)) {
+                               ACPI_EXCEPTION((AE_INFO, status,
+                                               "Could not enable GPE 0x%02X",
+                                               gpe_number));
+                       }
+               }
+       }
+
+       ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
+                         "Registered GPE method %s as GPE number 0x%.2X\n",
+                         name, gpe_number));
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_match_prw_and_gpe
+ *
+ * PARAMETERS:  Callback from walk_namespace
+ *
+ * RETURN:      Status. NOTE: We ignore errors so that the _PRW walk is
+ *              not aborted on a single _PRW failure.
+ *
+ * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
+ *              Device. Run the _PRW method. If present, extract the GPE
+ *              number and mark the GPE as a CAN_WAKE GPE. Allows a
+ *              per-owner_id execution if execute_by_owner_id is TRUE in the
+ *              walk_info parameter block.
+ *
+ * If walk_info->execute_by_owner_id is TRUE, we only execute _PRWs with that
+ *    owner.
+ * If walk_info->gpe_device is NULL, we execute every _PRW found. Otherwise,
+ *    we only execute _PRWs that refer to the input gpe_device.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
+                         u32 level, void *context, void **return_value)
+{
+       struct acpi_gpe_walk_info *walk_info =
+           ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
+       struct acpi_namespace_node *gpe_device;
+       struct acpi_gpe_block_info *gpe_block;
+       struct acpi_namespace_node *target_gpe_device;
+       struct acpi_namespace_node *prw_node;
+       struct acpi_gpe_event_info *gpe_event_info;
+       union acpi_operand_object *pkg_desc;
+       union acpi_operand_object *obj_desc;
+       u32 gpe_number;
+       acpi_status status;
+
+       ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
+
+       /* Check for a _PRW method under this device */
+
+       status = acpi_ns_get_node(obj_handle, METHOD_NAME__PRW,
+                                 ACPI_NS_NO_UPSEARCH, &prw_node);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* Check if requested owner_id matches this owner_id */
+
+       if ((walk_info->execute_by_owner_id) &&
+           (prw_node->owner_id != walk_info->owner_id)) {
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* Execute the _PRW */
+
+       status = acpi_ut_evaluate_object(prw_node, NULL,
+                                        ACPI_BTYPE_PACKAGE, &pkg_desc);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* The returned _PRW package must have at least two elements */
+
+       if (pkg_desc->package.count < 2) {
+               goto cleanup;
+       }
+
+       /* Extract pointers from the input context */
+
+       gpe_device = walk_info->gpe_device;
+       gpe_block = walk_info->gpe_block;
+
+       /*
+        * The _PRW object must return a package, we are only interested
+        * in the first element
+        */
+       obj_desc = pkg_desc->package.elements[0];
+
+       if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
+
+               /* Use FADT-defined GPE device (from definition of _PRW) */
+
+               target_gpe_device = NULL;
+               if (gpe_device) {
+                       target_gpe_device = acpi_gbl_fadt_gpe_device;
+               }
+
+               /* Integer is the GPE number in the FADT described GPE blocks */
+
+               gpe_number = (u32)obj_desc->integer.value;
+       } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
+
+               /* Package contains a GPE reference and GPE number within a GPE block */
+
+               if ((obj_desc->package.count < 2) ||
+                   ((obj_desc->package.elements[0])->common.type !=
+                    ACPI_TYPE_LOCAL_REFERENCE) ||
+                   ((obj_desc->package.elements[1])->common.type !=
+                    ACPI_TYPE_INTEGER)) {
+                       goto cleanup;
+               }
+
+               /* Get GPE block reference and decode */
+
+               target_gpe_device =
+                   obj_desc->package.elements[0]->reference.node;
+               gpe_number = (u32)obj_desc->package.elements[1]->integer.value;
+       } else {
+               /* Unknown type, just ignore it */
+
+               goto cleanup;
+       }
+
+       /* Get the gpe_event_info for this GPE */
+
+       if (gpe_device) {
+               /*
+                * Is this GPE within this block?
+                *
+                * TRUE if and only if these conditions are true:
+                *     1) The GPE devices match.
+                *     2) The GPE index(number) is within the range of the Gpe Block
+                *          associated with the GPE device.
+                */
+               if (gpe_device != target_gpe_device) {
+                       goto cleanup;
+               }
+
+               gpe_event_info =
+                   acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
+       } else {
+               /* gpe_device is NULL, just match the target_device and gpe_number */
+
+               gpe_event_info =
+                   acpi_ev_get_gpe_event_info(target_gpe_device, gpe_number);
+       }
+
+       if (gpe_event_info) {
+               if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
+
+                       /* This GPE can wake the system */
+
+                       gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
+                       walk_info->count++;
+               }
+       }
+
+      cleanup:
+       acpi_ut_remove_reference(pkg_desc);
+       return_ACPI_STATUS(AE_OK);
+}
diff --git a/drivers/acpi/acpica/evgpeutil.c b/drivers/acpi/acpica/evgpeutil.c
new file mode 100644 (file)
index 0000000..19a0e51
--- /dev/null
@@ -0,0 +1,337 @@
+/******************************************************************************
+ *
+ * Module Name: evgpeutil - GPE utilities
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2010, Intel Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include "accommon.h"
+#include "acevents.h"
+
+#define _COMPONENT          ACPI_EVENTS
+ACPI_MODULE_NAME("evgpeutil")
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_walk_gpe_list
+ *
+ * PARAMETERS:  gpe_walk_callback   - Routine called for each GPE block
+ *              Context             - Value passed to callback
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Walk the GPE lists.
+ *
+ ******************************************************************************/
+acpi_status
+acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
+{
+       struct acpi_gpe_block_info *gpe_block;
+       struct acpi_gpe_xrupt_info *gpe_xrupt_info;
+       acpi_status status = AE_OK;
+       acpi_cpu_flags flags;
+
+       ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
+
+       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+
+       /* Walk the interrupt level descriptor list */
+
+       gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
+       while (gpe_xrupt_info) {
+
+               /* Walk all Gpe Blocks attached to this interrupt level */
+
+               gpe_block = gpe_xrupt_info->gpe_block_list_head;
+               while (gpe_block) {
+
+                       /* One callback per GPE block */
+
+                       status =
+                           gpe_walk_callback(gpe_xrupt_info, gpe_block,
+                                             context);
+                       if (ACPI_FAILURE(status)) {
+                               if (status == AE_CTRL_END) {    /* Callback abort */
+                                       status = AE_OK;
+                               }
+                               goto unlock_and_exit;
+                       }
+
+                       gpe_block = gpe_block->next;
+               }
+
+               gpe_xrupt_info = gpe_xrupt_info->next;
+       }
+
+      unlock_and_exit:
+       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+       return_ACPI_STATUS(status);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_valid_gpe_event
+ *
+ * PARAMETERS:  gpe_event_info              - Info for this GPE
+ *
+ * RETURN:      TRUE if the gpe_event is valid
+ *
+ * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
+ *              Should be called only when the GPE lists are semaphore locked
+ *              and not subject to change.
+ *
+ ******************************************************************************/
+
+u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
+{
+       struct acpi_gpe_xrupt_info *gpe_xrupt_block;
+       struct acpi_gpe_block_info *gpe_block;
+
+       ACPI_FUNCTION_ENTRY();
+
+       /* No need for spin lock since we are not changing any list elements */
+
+       /* Walk the GPE interrupt levels */
+
+       gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
+       while (gpe_xrupt_block) {
+               gpe_block = gpe_xrupt_block->gpe_block_list_head;
+
+               /* Walk the GPE blocks on this interrupt level */
+
+               while (gpe_block) {
+                       if ((&gpe_block->event_info[0] <= gpe_event_info) &&
+                           (&gpe_block->event_info[gpe_block->gpe_count] >
+                            gpe_event_info)) {
+                               return (TRUE);
+                       }
+
+                       gpe_block = gpe_block->next;
+               }
+
+               gpe_xrupt_block = gpe_xrupt_block->next;
+       }
+
+       return (FALSE);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_get_gpe_xrupt_block
+ *
+ * PARAMETERS:  interrupt_number     - Interrupt for a GPE block
+ *
+ * RETURN:      A GPE interrupt block
+ *
+ * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
+ *              block per unique interrupt level used for GPEs. Should be
+ *              called only when the GPE lists are semaphore locked and not
+ *              subject to change.
+ *
+ ******************************************************************************/
+
+struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 interrupt_number)
+{
+       struct acpi_gpe_xrupt_info *next_gpe_xrupt;
+       struct acpi_gpe_xrupt_info *gpe_xrupt;
+       acpi_status status;
+       acpi_cpu_flags flags;
+
+       ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
+
+       /* No need for lock since we are not changing any list elements here */
+
+       next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
+       while (next_gpe_xrupt) {
+               if (next_gpe_xrupt->interrupt_number == interrupt_number) {
+                       return_PTR(next_gpe_xrupt);
+               }
+
+               next_gpe_xrupt = next_gpe_xrupt->next;
+       }
+
+       /* Not found, must allocate a new xrupt descriptor */
+
+       gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
+       if (!gpe_xrupt) {
+               return_PTR(NULL);
+       }
+
+       gpe_xrupt->interrupt_number = interrupt_number;
+
+       /* Install new interrupt descriptor with spin lock */
+
+       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+       if (acpi_gbl_gpe_xrupt_list_head) {
+               next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
+               while (next_gpe_xrupt->next) {
+                       next_gpe_xrupt = next_gpe_xrupt->next;
+               }
+
+               next_gpe_xrupt->next = gpe_xrupt;
+               gpe_xrupt->previous = next_gpe_xrupt;
+       } else {
+               acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
+       }
+       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+
+       /* Install new interrupt handler if not SCI_INT */
+
+       if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
+               status = acpi_os_install_interrupt_handler(interrupt_number,
+                                                          acpi_ev_gpe_xrupt_handler,
+                                                          gpe_xrupt);
+               if (ACPI_FAILURE(status)) {
+                       ACPI_ERROR((AE_INFO,
+                                   "Could not install GPE interrupt handler at level 0x%X",
+                                   interrupt_number));
+                       return_PTR(NULL);
+               }
+       }
+
+       return_PTR(gpe_xrupt);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_delete_gpe_xrupt
+ *
+ * PARAMETERS:  gpe_xrupt       - A GPE interrupt info block
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
+ *              interrupt handler if not the SCI interrupt.
+ *
+ ******************************************************************************/
+
+acpi_status acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
+{
+       acpi_status status;
+       acpi_cpu_flags flags;
+
+       ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
+
+       /* We never want to remove the SCI interrupt handler */
+
+       if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
+               gpe_xrupt->gpe_block_list_head = NULL;
+               return_ACPI_STATUS(AE_OK);
+       }
+
+       /* Disable this interrupt */
+
+       status =
+           acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
+                                            acpi_ev_gpe_xrupt_handler);
+       if (ACPI_FAILURE(status)) {
+               return_ACPI_STATUS(status);
+       }
+
+       /* Unlink the interrupt block with lock */
+
+       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+       if (gpe_xrupt->previous) {
+               gpe_xrupt->previous->next = gpe_xrupt->next;
+       } else {
+               /* No previous, update list head */
+
+               acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
+       }
+
+       if (gpe_xrupt->next) {
+               gpe_xrupt->next->previous = gpe_xrupt->previous;
+       }
+       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
+
+       /* Free the block */
+
+       ACPI_FREE(gpe_xrupt);
+       return_ACPI_STATUS(AE_OK);
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ev_delete_gpe_handlers
+ *
+ * PARAMETERS:  gpe_xrupt_info      - GPE Interrupt info
+ *              gpe_block           - Gpe Block info
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
+ *              Used only prior to termination.
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
+                           struct acpi_gpe_block_info *gpe_block,
+                           void *context)
+{
+       struct acpi_gpe_event_info *gpe_event_info;
+       u32 i;
+       u32 j;
+
+       ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
+
+       /* Examine each GPE Register within the block */
+
+       for (i = 0; i < gpe_block->register_count; i++) {
+
+               /* Now look at the individual GPEs in this byte register */
+
+               for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
+                       gpe_event_info = &gpe_block->event_info[((acpi_size) i *
+                                                                ACPI_GPE_REGISTER_WIDTH)
+                                                               + j];
+
+                       if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
+                           ACPI_GPE_DISPATCH_HANDLER) {
+                               ACPI_FREE(gpe_event_info->dispatch.handler);
+                               gpe_event_info->dispatch.handler = NULL;
+                               gpe_event_info->flags &=
+                                   ~ACPI_GPE_DISPATCH_MASK;
+                       }
+               }
+       }
+
+       return_ACPI_STATUS(AE_OK);
+}
index 9a3cb70..df0aea9 100644 (file)
@@ -590,7 +590,7 @@ void acpi_ev_terminate(void)
                        status = acpi_disable_event(i, 0);
                        if (ACPI_FAILURE(status)) {
                                ACPI_ERROR((AE_INFO,
-                                           "Could not disable fixed event %d",
+                                           "Could not disable fixed event %u",
                                            (u32) i));
                        }
                }
index b407579..cc82502 100644 (file)
@@ -142,7 +142,7 @@ acpi_install_fixed_event_handler(u32 event,
        if (ACPI_SUCCESS(status))
                status = acpi_enable_event(event, 0);
        if (ACPI_FAILURE(status)) {
-               ACPI_WARNING((AE_INFO, "Could not enable fixed event %X",
+               ACPI_WARNING((AE_INFO, "Could not enable fixed event 0x%X",
                              event));
 
                /* Remove the handler */
@@ -203,7 +203,7 @@ acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
 
        if (ACPI_FAILURE(status)) {
                ACPI_WARNING((AE_INFO,
-                             "Could not write to fixed event enable register %X",
+                             "Could not write to fixed event enable register 0x%X",
                              event));
        } else {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n",
@@ -682,14 +682,13 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
 
        /* Parameter validation */
 
-       if ((!address) || (type > ACPI_GPE_XRUPT_TYPE_MASK)) {
-               status = AE_BAD_PARAMETER;
-               goto exit;
+       if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
+               return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
        status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
        if (ACPI_FAILURE(status)) {
-               goto exit;
+               return_ACPI_STATUS(status);
        }
 
        /* Ensure that we have a valid GPE number */
@@ -720,6 +719,13 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
        handler->context = context;
        handler->method_node = gpe_event_info->dispatch.method_node;
 
+       /* Disable the GPE before installing the handler */
+
+       status = acpi_ev_disable_gpe(gpe_event_info);
+       if (ACPI_FAILURE (status)) {
+               goto unlock_and_exit;
+       }
+
        /* Install the handler */
 
        flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
@@ -733,12 +739,8 @@ acpi_install_gpe_handler(acpi_handle gpe_device,
 
        acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
 
-      unlock_and_exit:
+unlock_and_exit:
        (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
-      exit:
-       if (ACPI_FAILURE(status))
-               ACPI_EXCEPTION((AE_INFO, status,
-                               "Installing notify handler failed"));
        return_ACPI_STATUS(status);
 }
 
index 5ff32c7..7c7bbb4 100644 (file)
@@ -203,21 +203,26 @@ ACPI_EXPORT_SYMBOL(acpi_enable_event)
  *
  * FUNCTION:    acpi_set_gpe
  *
- * PARAMETERS:  gpe_device      - Parent GPE Device
+ * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
  *              gpe_number      - GPE level within the GPE block
- *              action          - Enable or disable
- *                                Called from ISR or not
+ *              action          - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Enable or disable an ACPI event (general purpose)
+ * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
+ *              the reference count mechanism used in the acpi_enable_gpe and
+ *              acpi_disable_gpe interfaces -- and should be used with care.
+ *
+ * Note: Typically used to disable a runtime GPE for short period of time,
+ * then re-enable it, without disturbing the existing reference counts. This
+ * is useful, for example, in the Embedded Controller (EC) driver.
  *
  ******************************************************************************/
 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
 {
-       acpi_status status = AE_OK;
-       acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
+       acpi_status status;
+       acpi_cpu_flags flags;
 
        ACPI_FUNCTION_TRACE(acpi_set_gpe);
 
@@ -243,7 +248,6 @@ acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Invalid action\n"));
                status = AE_BAD_PARAMETER;
                break;
        }
@@ -259,25 +263,31 @@ ACPI_EXPORT_SYMBOL(acpi_set_gpe)
  *
  * FUNCTION:    acpi_enable_gpe
  *
- * PARAMETERS:  gpe_device      - Parent GPE Device
+ * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
  *              gpe_number      - GPE level within the GPE block
- *              type            - Purpose the GPE will be used for
+ *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
+ *                                or both
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Take a reference to a GPE and enable it if necessary
+ * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
+ *              hardware-enabled (for runtime GPEs), or the GPE register mask
+ *              is updated (for wake GPEs).
  *
  ******************************************************************************/
-acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
+acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
 {
        acpi_status status = AE_OK;
-       acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
+       acpi_cpu_flags flags;
 
        ACPI_FUNCTION_TRACE(acpi_enable_gpe);
 
-       if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
+       /* Parameter validation */
+
+       if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
                return_ACPI_STATUS(AE_BAD_PARAMETER);
+       }
 
        flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 
@@ -289,26 +299,43 @@ acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
                goto unlock_and_exit;
        }
 
-       if (type & ACPI_GPE_TYPE_RUNTIME) {
-               if (++gpe_event_info->runtime_count == 1) {
+       if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
+               if (gpe_event_info->runtime_count == ACPI_UINT8_MAX) {
+                       status = AE_LIMIT;      /* Too many references */
+                       goto unlock_and_exit;
+               }
+
+               gpe_event_info->runtime_count++;
+               if (gpe_event_info->runtime_count == 1) {
                        status = acpi_ev_enable_gpe(gpe_event_info);
-                       if (ACPI_FAILURE(status))
+                       if (ACPI_FAILURE(status)) {
                                gpe_event_info->runtime_count--;
+                               goto unlock_and_exit;
+                       }
                }
        }
 
-       if (type & ACPI_GPE_TYPE_WAKE) {
+       if (gpe_type & ACPI_GPE_TYPE_WAKE) {
+               /* The GPE must have the ability to wake the system */
+
                if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
-                       status = AE_BAD_PARAMETER;
+                       status = AE_TYPE;
+                       goto unlock_and_exit;
+               }
+
+               if (gpe_event_info->wakeup_count == ACPI_UINT8_MAX) {
+                       status = AE_LIMIT;      /* Too many references */
                        goto unlock_and_exit;
                }
 
                /*
-                * Wake-up GPEs are only enabled right prior to putting the
-                * system into a sleep state.
+                * Update the enable mask on the first wakeup reference. Wake GPEs
+                * are only hardware-enabled just before sleeping.
                 */
-               if (++gpe_event_info->wakeup_count == 1)
-                       acpi_ev_update_gpe_enable_masks(gpe_event_info);
+               gpe_event_info->wakeup_count++;
+               if (gpe_event_info->wakeup_count == 1) {
+                       (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
+               }
        }
 
 unlock_and_exit:
@@ -321,27 +348,34 @@ ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
  *
  * FUNCTION:    acpi_disable_gpe
  *
- * PARAMETERS:  gpe_device      - Parent GPE Device
+ * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
  *              gpe_number      - GPE level within the GPE block
- *              type            - Purpose the GPE won't be used for any more
+ *              gpe_type        - ACPI_GPE_TYPE_RUNTIME or ACPI_GPE_TYPE_WAKE
+ *                                or both
  *
  * RETURN:      Status
  *
- * DESCRIPTION: Release a reference to a GPE and disable it if necessary
+ * DESCRIPTION: Remove a reference to a GPE. When the last reference is
+ *              removed, only then is the GPE disabled (for runtime GPEs), or
+ *              the GPE mask bit disabled (for wake GPEs)
  *
  ******************************************************************************/
-acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
+acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type)
 {
        acpi_status status = AE_OK;
-       acpi_cpu_flags flags;
        struct acpi_gpe_event_info *gpe_event_info;
+       acpi_cpu_flags flags;
 
        ACPI_FUNCTION_TRACE(acpi_disable_gpe);
 
-       if (type & ~ACPI_GPE_TYPE_WAKE_RUN)
+       /* Parameter validation */
+
+       if (!gpe_type || (gpe_type & ~ACPI_GPE_TYPE_WAKE_RUN)) {
                return_ACPI_STATUS(AE_BAD_PARAMETER);
+       }
 
        flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
+
        /* Ensure that we have a valid GPE number */
 
        gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
@@ -350,18 +384,39 @@ acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type)
                goto unlock_and_exit;
        }
 
-       if ((type & ACPI_GPE_TYPE_RUNTIME) && gpe_event_info->runtime_count) {
-               if (--gpe_event_info->runtime_count == 0)
+       /* Hardware-disable a runtime GPE on removal of the last reference */
+
+       if (gpe_type & ACPI_GPE_TYPE_RUNTIME) {
+               if (!gpe_event_info->runtime_count) {
+                       status = AE_LIMIT;      /* There are no references to remove */
+                       goto unlock_and_exit;
+               }
+
+               gpe_event_info->runtime_count--;
+               if (!gpe_event_info->runtime_count) {
                        status = acpi_ev_disable_gpe(gpe_event_info);
+                       if (ACPI_FAILURE(status)) {
+                               gpe_event_info->runtime_count++;
+                               goto unlock_and_exit;
+                       }
+               }
        }
 
-       if ((type & ACPI_GPE_TYPE_WAKE) && gpe_event_info->wakeup_count) {
-               /*
-                * Wake-up GPEs are not enabled after leaving system sleep
-                * states, so we don't need to disable them here.
-                */
-               if (--gpe_event_info->wakeup_count == 0)
-                       acpi_ev_update_gpe_enable_masks(gpe_event_info);
+       /*
+        * Update masks for wake GPE on removal of the last reference.
+        * No need to hardware-disable wake GPEs here, they are not currently
+        * enabled.
+        */
+       if (gpe_type & ACPI_GPE_TYPE_WAKE) {
+               if (!gpe_event_info->wakeup_count) {
+                       status = AE_LIMIT;      /* There are no references to remove */
+                       goto unlock_and_exit;
+               }
+
+               gpe_event_info->wakeup_count--;
+               if (!gpe_event_info->wakeup_count) {
+                       (void)acpi_ev_update_gpe_enable_masks(gpe_event_info);
+               }
        }
 
 unlock_and_exit:
@@ -465,30 +520,23 @@ ACPI_EXPORT_SYMBOL(acpi_clear_event)
  *
  * FUNCTION:    acpi_clear_gpe
  *
- * PARAMETERS:  gpe_device      - Parent GPE Device
+ * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
  *              gpe_number      - GPE level within the GPE block
- *              Flags           - Called from an ISR or not
  *
  * RETURN:      Status
  *
  * DESCRIPTION: Clear an ACPI event (general purpose)
  *
  ******************************************************************************/
-acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
+acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
 {
        acpi_status status = AE_OK;
        struct acpi_gpe_event_info *gpe_event_info;
+       acpi_cpu_flags flags;
 
        ACPI_FUNCTION_TRACE(acpi_clear_gpe);
 
-       /* Use semaphore lock if not executing at interrupt level */
-
-       if (flags & ACPI_NOT_ISR) {
-               status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-       }
+       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 
        /* Ensure that we have a valid GPE number */
 
@@ -501,9 +549,7 @@ acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
        status = acpi_hw_clear_gpe(gpe_event_info);
 
       unlock_and_exit:
-       if (flags & ACPI_NOT_ISR) {
-               (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
-       }
+       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
        return_ACPI_STATUS(status);
 }
 
@@ -569,9 +615,8 @@ ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  *
  * FUNCTION:    acpi_get_gpe_status
  *
- * PARAMETERS:  gpe_device      - Parent GPE Device
+ * PARAMETERS:  gpe_device      - Parent GPE Device. NULL for GPE0/GPE1
  *              gpe_number      - GPE level within the GPE block
- *              Flags           - Called from an ISR or not
  *              event_status    - Where the current status of the event will
  *                                be returned
  *
@@ -582,21 +627,15 @@ ACPI_EXPORT_SYMBOL(acpi_get_event_status)
  ******************************************************************************/
 acpi_status
 acpi_get_gpe_status(acpi_handle gpe_device,
-                   u32 gpe_number, u32 flags, acpi_event_status * event_status)
+                   u32 gpe_number, acpi_event_status *event_status)
 {
        acpi_status status = AE_OK;
        struct acpi_gpe_event_info *gpe_event_info;
+       acpi_cpu_flags flags;
 
        ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
 
-       /* Use semaphore lock if not executing at interrupt level */
-
-       if (flags & ACPI_NOT_ISR) {
-               status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
-               if (ACPI_FAILURE(status)) {
-                       return_ACPI_STATUS(status);
-               }
-       }
+       flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
 
        /* Ensure that we have a valid GPE number */
 
@@ -614,9 +653,7 @@ acpi_get_gpe_status(acpi_handle gpe_device,
                *event_status |= ACPI_EVENT_FLAG_HANDLE;
 
       unlock_and_exit:
-       if (flags & ACPI_NOT_ISR) {
-               (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
-       }
+       acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
        return_ACPI_STATUS(status);
 }
 
@@ -673,20 +710,15 @@ acpi_install_gpe_block(acpi_handle gpe_device,
                goto unlock_and_exit;
        }
 
-       /* Run the _PRW methods and enable the GPEs */
-
-       status = acpi_ev_initialize_gpe_block(node, gpe_block);
-       if (ACPI_FAILURE(status)) {
-               goto unlock_and_exit;
-       }
-
-       /* Get the device_object attached to the node */
+       /* Install block in the device_object attached to the node */
 
        obj_desc = acpi_ns_get_attached_object(node);
        if (!obj_desc) {
 
-               /* No object, create a new one */
-
+               /*
+                * No object, create a new one (Device nodes do not always have
+                * an attached object)
+                */
                obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
                if (!obj_desc) {
                        status = AE_NO_MEMORY;
@@ -705,10 +737,14 @@ acpi_install_gpe_block(acpi_handle gpe_device,
                }
        }
 
-       /* Install the GPE block in the device_object */
+       /* Now install the GPE block in the device_object */
 
        obj_desc->device.gpe_block = gpe_block;
 
+       /* Run the _PRW methods and enable the runtime GPEs in the new block */
+
+       status = acpi_ev_initialize_gpe_block(node, gpe_block);
+
       unlock_and_exit:
        (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
        return_ACPI_STATUS(status);
@@ -839,8 +875,7 @@ acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
 
        /* Increment Index by the number of GPEs in this block */
 
-       info->next_block_base_index +=
-           (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);
+       info->next_block_base_index += gpe_block->gpe_count;
 
        if (info->index < info->next_block_base_index) {
                /*
index 7e8b3be..008621c 100644 (file)
@@ -82,8 +82,9 @@ acpi_ex_add_table(u32 table_index,
                  struct acpi_namespace_node *parent_node,
                  union acpi_operand_object **ddb_handle)
 {
-       acpi_status status;
        union acpi_operand_object *obj_desc;
+       acpi_status status;
+       acpi_owner_id owner_id;
 
        ACPI_FUNCTION_TRACE(ex_add_table);
 
@@ -119,7 +120,14 @@ acpi_ex_add_table(u32 table_index,
        acpi_ns_exec_module_code_list();
        acpi_ex_enter_interpreter();
 
-       return_ACPI_STATUS(status);
+       /* Update GPEs for any new _PRW or _Lxx/_Exx methods. Ignore errors */
+
+       status = acpi_tb_get_owner_id(table_index, &owner_id);
+       if (ACPI_SUCCESS(status)) {
+               acpi_ev_update_gpes(owner_id);
+       }
+
+       return_ACPI_STATUS(AE_OK);
 }
 
 /*******************************************************************************
@@ -248,10 +256,8 @@ acpi_ex_load_table_op(struct acpi_walk_state *walk_state,
 
        status = acpi_get_table_by_index(table_index, &table);
        if (ACPI_SUCCESS(status)) {
-               ACPI_INFO((AE_INFO,
-                          "Dynamic OEM Table Load - [%.4s] OemId [%.6s] OemTableId [%.8s]",
-                          table->signature, table->oem_id,
-                          table->oem_table_id));
+               ACPI_INFO((AE_INFO, "Dynamic OEM Table Load:"));
+               acpi_tb_print_table_header(0, table);
        }
 
        /* Invoke table handler if present */
@@ -525,6 +531,9 @@ acpi_ex_load_op(union acpi_operand_object *obj_desc,
                return_ACPI_STATUS(status);
        }
 
+       ACPI_INFO((AE_INFO, "Dynamic OEM Table Load:"));
+       acpi_tb_print_table_header(0, table_desc.pointer);
+
        /* Remove the reference by added by acpi_ex_store above */
 
        acpi_ut_remove_reference(ddb_handle);
index bda7aed..b73bc50 100644 (file)
@@ -650,7 +650,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
 
                default:
                        ACPI_ERROR((AE_INFO,
-                                   "Bad destination type during conversion: %X",
+                                   "Bad destination type during conversion: 0x%X",
                                    destination_type));
                        status = AE_AML_INTERNAL;
                        break;
@@ -665,7 +665,7 @@ acpi_ex_convert_to_target_type(acpi_object_type destination_type,
 
        default:
                ACPI_ERROR((AE_INFO,
-                           "Unknown Target type ID 0x%X AmlOpcode %X DestType %s",
+                           "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
                            GET_CURRENT_ARG_TYPE(walk_state->op_info->
                                                 runtime_args),
                            walk_state->opcode,
index 0aa57d9..3c61b48 100644 (file)
@@ -306,12 +306,12 @@ acpi_ex_create_region(u8 * aml_start,
         */
        if ((region_space >= ACPI_NUM_PREDEFINED_REGIONS) &&
            (region_space < ACPI_USER_REGION_BEGIN)) {
-               ACPI_ERROR((AE_INFO, "Invalid AddressSpace type %X",
+               ACPI_ERROR((AE_INFO, "Invalid AddressSpace type 0x%X",
                            region_space));
                return_ACPI_STATUS(AE_AML_INVALID_SPACE_ID);
        }
 
-       ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (%X)\n",
+       ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Region Type - %s (0x%X)\n",
                          acpi_ut_get_region_name(region_space), region_space));
 
        /* Create the region descriptor */
diff --git a/drivers/acpi/acpica/exdebug.c b/drivers/acpi/acpica/exdebug.c
new file mode 100644 (file)
index 0000000..be8c98b
--- /dev/null
@@ -0,0 +1,261 @@
+/******************************************************************************
+ *
+ * Module Name: exdebug - Support for stores to the AML Debug Object
+ *
+ *****************************************************************************/
+
+/*
+ * Copyright (C) 2000 - 2010, Intel Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions, and the following disclaimer,
+ *    without modification.
+ * 2. Redistributions in binary form must reproduce at minimum a disclaimer
+ *    substantially similar to the "NO WARRANTY" disclaimer below
+ *    ("Disclaimer") and any redistribution must be conditioned upon
+ *    including a substantially similar Disclaimer requirement for further
+ *    binary redistribution.
+ * 3. Neither the names of the above-listed copyright holders nor the names
+ *    of any contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * Alternatively, this software may be distributed under the terms of the
+ * GNU General Public License ("GPL") version 2 as published by the Free
+ * Software Foundation.
+ *
+ * NO WARRANTY
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <acpi/acpi.h>
+#include "accommon.h"
+#include "acinterp.h"
+
+#define _COMPONENT          ACPI_EXECUTER
+ACPI_MODULE_NAME("exdebug")
+
+#ifndef ACPI_NO_ERROR_MESSAGES
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ex_do_debug_object
+ *
+ * PARAMETERS:  source_desc         - Object to be output to "Debug Object"
+ *              Level               - Indentation level (used for packages)
+ *              Index               - Current package element, zero if not pkg
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Handles stores to the AML Debug Object. For example:
+ *              Store(INT1, Debug)
+ *
+ * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
+ *
+ * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
+ * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
+ * operational case, stores to the debug object are ignored but can be easily
+ * enabled if necessary.
+ *
+ ******************************************************************************/
+void
+acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
+                       u32 level, u32 index)
+{
+       u32 i;
+
+       ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
+
+       /* Output must be enabled via the debug_object global or the dbg_level */
+
+       if (!acpi_gbl_enable_aml_debug_object &&
+           !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
+               return_VOID;
+       }
+
+       /*
+        * Print line header as long as we are not in the middle of an
+        * object display
+        */
+       if (!((level > 0) && index == 0)) {
+               acpi_os_printf("[ACPI Debug] %*s", level, " ");
+       }
+
+       /* Display the index for package output only */
+
+       if (index > 0) {
+               acpi_os_printf("(%.2u) ", index - 1);
+       }
+
+       if (!source_desc) {
+               acpi_os_printf("[Null Object]\n");
+               return_VOID;
+       }
+
+       if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
+               acpi_os_printf("%s ",
+                              acpi_ut_get_object_type_name(source_desc));
+
+               if (!acpi_ut_valid_internal_object(source_desc)) {
+                       acpi_os_printf("%p, Invalid Internal Object!\n",
+                                      source_desc);
+                       return_VOID;
+               }
+       } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
+                  ACPI_DESC_TYPE_NAMED) {
+               acpi_os_printf("%s: %p\n",
+                              acpi_ut_get_type_name(((struct
+                                                      acpi_namespace_node *)
+                                                     source_desc)->type),
+                              source_desc);
+               return_VOID;
+       } else {
+               return_VOID;
+       }
+
+       /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
+
+       switch (source_desc->common.type) {
+       case ACPI_TYPE_INTEGER:
+
+               /* Output correct integer width */
+
+               if (acpi_gbl_integer_byte_width == 4) {
+                       acpi_os_printf("0x%8.8X\n",
+                                      (u32)source_desc->integer.value);
+               } else {
+                       acpi_os_printf("0x%8.8X%8.8X\n",
+                                      ACPI_FORMAT_UINT64(source_desc->integer.
+                                                         value));
+               }
+               break;
+
+       case ACPI_TYPE_BUFFER:
+
+               acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
+               acpi_ut_dump_buffer2(source_desc->buffer.pointer,
+                                    (source_desc->buffer.length < 256) ?
+                                    source_desc->buffer.length : 256,
+                                    DB_BYTE_DISPLAY);
+               break;
+
+       case ACPI_TYPE_STRING:
+
+               acpi_os_printf("[0x%.2X] \"%s\"\n",
+                              source_desc->string.length,
+                              source_desc->string.pointer);
+               break;
+
+       case ACPI_TYPE_PACKAGE:
+
+               acpi_os_printf("[Contains 0x%.2X Elements]\n",
+                              source_desc->package.count);
+
+               /* Output the entire contents of the package */
+
+               for (i = 0; i < source_desc->package.count; i++) {
+                       acpi_ex_do_debug_object(source_desc->package.
+                                               elements[i], level + 4, i + 1);
+               }
+               break;
+
+       case ACPI_TYPE_LOCAL_REFERENCE:
+
+               acpi_os_printf("[%s] ",
+                              acpi_ut_get_reference_name(source_desc));
+
+               /* Decode the reference */
+
+               switch (source_desc->reference.class) {
+               case ACPI_REFCLASS_INDEX:
+
+                       acpi_os_printf("0x%X\n", source_desc->reference.value);
+                       break;
+
+               case ACPI_REFCLASS_TABLE:
+
+                       /* Case for ddb_handle */
+
+                       acpi_os_printf("Table Index 0x%X\n",
+                                      source_desc->reference.value);
+                       return;
+
+               default:
+                       break;
+               }
+
+               acpi_os_printf(" ");
+
+               /* Check for valid node first, then valid object */
+
+               if (source_desc->reference.node) {
+                       if (ACPI_GET_DESCRIPTOR_TYPE
+                           (source_desc->reference.node) !=
+                           ACPI_DESC_TYPE_NAMED) {
+                               acpi_os_printf
+                                   (" %p - Not a valid namespace node\n",
+                                    source_desc->reference.node);
+                       } else {
+                               acpi_os_printf("Node %p [%4.4s] ",
+                                              source_desc->reference.node,
+                                              (source_desc->reference.node)->
+                                              name.ascii);
+
+                               switch ((source_desc->reference.node)->type) {
+
+                                       /* These types have no attached object */
+
+                               case ACPI_TYPE_DEVICE:
+                                       acpi_os_printf("Device\n");
+                                       break;
+
+                               case ACPI_TYPE_THERMAL:
+                                       acpi_os_printf("Thermal Zone\n");
+                                       break;
+
+                               default:
+                                       acpi_ex_do_debug_object((source_desc->
+                                                                reference.
+                                                                node)->object,
+                                                               level + 4, 0);
+                                       break;
+                               }
+                       }
+               } else if (source_desc->reference.object) {
+                       if (ACPI_GET_DESCRIPTOR_TYPE
+                           (source_desc->reference.object) ==
+                           ACPI_DESC_TYPE_NAMED) {
+                               acpi_ex_do_debug_object(((struct
+                                                         acpi_namespace_node *)
+                                                        source_desc->reference.
+                                                        object)->object,
+                                                       level + 4, 0);
+                       } else {
+                               acpi_ex_do_debug_object(source_desc->reference.
+                                                       object, level + 4, 0);
+                       }
+               }
+               break;
+
+       default:
+
+               acpi_os_printf("%p\n", source_desc);
+               break;
+       }
+
+       ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
+       return_VOID;
+}
+#endif
index 6c79fec..f17d2ff 100644 (file)
@@ -281,7 +281,7 @@ acpi_ex_write_data_to_field(union acpi_operand_object *source_desc,
 
                if (source_desc->buffer.length < length) {
                        ACPI_ERROR((AE_INFO,
-                                   "SMBus or IPMI write requires Buffer of length %X, found length %X",
+                                   "SMBus or IPMI write requires Buffer of length %u, found length %u",
                                    length, source_desc->buffer.length));
 
                        return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
index f68a216..a6dc26f 100644 (file)
@@ -94,7 +94,7 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
        /* We must have a valid region */
 
        if (rgn_desc->common.type != ACPI_TYPE_REGION) {
-               ACPI_ERROR((AE_INFO, "Needed Region, found type %X (%s)",
+               ACPI_ERROR((AE_INFO, "Needed Region, found type 0x%X (%s)",
                            rgn_desc->common.type,
                            acpi_ut_get_object_type_name(rgn_desc)));
 
@@ -175,7 +175,7 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
                         * byte, and a field with Dword access specified.
                         */
                        ACPI_ERROR((AE_INFO,
-                                   "Field [%4.4s] access width (%d bytes) too large for region [%4.4s] (length %X)",
+                                   "Field [%4.4s] access width (%u bytes) too large for region [%4.4s] (length %u)",
                                    acpi_ut_get_node_name(obj_desc->
                                                          common_field.node),
                                    obj_desc->common_field.access_byte_width,
@@ -189,7 +189,7 @@ acpi_ex_setup_region(union acpi_operand_object *obj_desc,
                 * exceeds region length, indicate an error
                 */
                ACPI_ERROR((AE_INFO,
-                           "Field [%4.4s] Base+Offset+Width %X+%X+%X is beyond end of region [%4.4s] (length %X)",
+                           "Field [%4.4s] Base+Offset+Width %u+%u+%u is beyond end of region [%4.4s] (length %u)",
                            acpi_ut_get_node_name(obj_desc->common_field.node),
                            obj_desc->common_field.base_byte_offset,
                            field_datum_byte_offset,
@@ -281,13 +281,13 @@ acpi_ex_access_region(union acpi_operand_object *obj_desc,
        if (ACPI_FAILURE(status)) {
                if (status == AE_NOT_IMPLEMENTED) {
                        ACPI_ERROR((AE_INFO,
-                                   "Region %s(%X) not implemented",
+                                   "Region %s(0x%X) not implemented",
                                    acpi_ut_get_region_name(rgn_desc->region.
                                                            space_id),
                                    rgn_desc->region.space_id));
                } else if (status == AE_NOT_EXIST) {
                        ACPI_ERROR((AE_INFO,
-                                   "Region %s(%X) has no handler",
+                                   "Region %s(0x%X) has no handler",
                                    acpi_ut_get_region_name(rgn_desc->region.
                                                            space_id),
                                    rgn_desc->region.space_id));
@@ -525,7 +525,7 @@ acpi_ex_field_datum_io(union acpi_operand_object *obj_desc,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %X",
+               ACPI_ERROR((AE_INFO, "Wrong object type in field I/O %u",
                            obj_desc->common.type));
                status = AE_AML_INTERNAL;
                break;
@@ -630,7 +630,7 @@ acpi_ex_write_with_update_rule(union acpi_operand_object *obj_desc,
                default:
 
                        ACPI_ERROR((AE_INFO,
-                                   "Unknown UpdateRule value: %X",
+                                   "Unknown UpdateRule value: 0x%X",
                                    (obj_desc->common_field.
                                     field_flags &
                                     AML_FIELD_UPDATE_RULE_MASK)));
@@ -689,7 +689,7 @@ acpi_ex_extract_from_field(union acpi_operand_object *obj_desc,
        if (buffer_length <
            ACPI_ROUND_BITS_UP_TO_BYTES(obj_desc->common_field.bit_length)) {
                ACPI_ERROR((AE_INFO,
-                           "Field size %X (bits) is too large for buffer (%X)",
+                           "Field size %u (bits) is too large for buffer (%u)",
                            obj_desc->common_field.bit_length, buffer_length));
 
                return_ACPI_STATUS(AE_BUFFER_OVERFLOW);
index c5bb1ee..95db4be 100644 (file)
@@ -99,7 +99,7 @@ acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
 
                default:
 
-                       ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
+                       ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X",
                                    obj_desc->reference.class));
                        return_ACPI_STATUS(AE_AML_INTERNAL);
                }
@@ -115,7 +115,7 @@ acpi_ex_get_object_reference(union acpi_operand_object *obj_desc,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Invalid descriptor type %X",
+               ACPI_ERROR((AE_INFO, "Invalid descriptor type 0x%X",
                            ACPI_GET_DESCRIPTOR_TYPE(obj_desc)));
                return_ACPI_STATUS(AE_TYPE);
        }
@@ -276,7 +276,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Invalid object type: %X",
+               ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X",
                            operand0->common.type));
                status = AE_AML_INTERNAL;
        }
@@ -378,7 +378,7 @@ acpi_ex_do_concatenate(union acpi_operand_object *operand0,
 
                /* Invalid object type, should not happen here */
 
-               ACPI_ERROR((AE_INFO, "Invalid object type: %X",
+               ACPI_ERROR((AE_INFO, "Invalid object type: 0x%X",
                            operand0->common.type));
                status = AE_AML_INTERNAL;
                goto cleanup;
index 7116bc8..f73be97 100644 (file)
@@ -85,10 +85,10 @@ void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
                (obj_desc->mutex.prev)->mutex.next = obj_desc->mutex.next;
 
                /*
-                * Migrate the previous sync level associated with this mutex to the
-                * previous mutex on the list so that it may be preserved. This handles
-                * the case where several mutexes have been acquired at the same level,
-                * but are not released in opposite order.
+                * Migrate the previous sync level associated with this mutex to
+                * the previous mutex on the list so that it may be preserved.
+                * This handles the case where several mutexes have been acquired
+                * at the same level, but are not released in opposite order.
                 */
                (obj_desc->mutex.prev)->mutex.original_sync_level =
                    obj_desc->mutex.original_sync_level;
@@ -101,8 +101,8 @@ void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
  *
  * FUNCTION:    acpi_ex_link_mutex
  *
- * PARAMETERS:  obj_desc        - The mutex to be linked
- *              Thread          - Current executing thread object
+ * PARAMETERS:  obj_desc            - The mutex to be linked
+ *              Thread              - Current executing thread object
  *
  * RETURN:      None
  *
@@ -138,9 +138,9 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
  *
  * FUNCTION:    acpi_ex_acquire_mutex_object
  *
- * PARAMETERS:  time_desc           - Timeout in milliseconds
+ * PARAMETERS:  Timeout             - Timeout in milliseconds
  *              obj_desc            - Mutex object
- *              Thread              - Current thread state
+ *              thread_id           - Current thread state
  *
  * RETURN:      Status
  *
@@ -234,7 +234,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
-       /* Must have a valid thread ID */
+       /* Must have a valid thread state struct */
 
        if (!walk_state->thread) {
                ACPI_ERROR((AE_INFO,
@@ -249,7 +249,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
         */
        if (walk_state->thread->current_sync_level > obj_desc->mutex.sync_level) {
                ACPI_ERROR((AE_INFO,
-                           "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%d)",
+                           "Cannot acquire Mutex [%4.4s], current SyncLevel is too large (%u)",
                            acpi_ut_get_node_name(obj_desc->mutex.node),
                            walk_state->thread->current_sync_level));
                return_ACPI_STATUS(AE_AML_MUTEX_ORDER);
@@ -359,6 +359,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
 {
        acpi_status status = AE_OK;
        u8 previous_sync_level;
+       struct acpi_thread_state *owner_thread;
 
        ACPI_FUNCTION_TRACE(ex_release_mutex);
 
@@ -366,9 +367,11 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
+       owner_thread = obj_desc->mutex.owner_thread;
+
        /* The mutex must have been previously acquired in order to release it */
 
-       if (!obj_desc->mutex.owner_thread) {
+       if (!owner_thread) {
                ACPI_ERROR((AE_INFO,
                            "Cannot release Mutex [%4.4s], not acquired",
                            acpi_ut_get_node_name(obj_desc->mutex.node)));
@@ -387,16 +390,13 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
         * The Mutex is owned, but this thread must be the owner.
         * Special case for Global Lock, any thread can release
         */
-       if ((obj_desc->mutex.owner_thread->thread_id !=
-            walk_state->thread->thread_id)
-           && (obj_desc != acpi_gbl_global_lock_mutex)) {
+       if ((owner_thread->thread_id != walk_state->thread->thread_id) &&
+           (obj_desc != acpi_gbl_global_lock_mutex)) {
                ACPI_ERROR((AE_INFO,
                            "Thread %p cannot release Mutex [%4.4s] acquired by thread %p",
                            ACPI_CAST_PTR(void, walk_state->thread->thread_id),
                            acpi_ut_get_node_name(obj_desc->mutex.node),
-                           ACPI_CAST_PTR(void,
-                                         obj_desc->mutex.owner_thread->
-                                         thread_id)));
+                           ACPI_CAST_PTR(void, owner_thread->thread_id)));
                return_ACPI_STATUS(AE_AML_NOT_OWNER);
        }
 
@@ -407,10 +407,9 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
         * different level can only mean that the mutex ordering rule is being
         * violated. This behavior is clarified in ACPI 4.0 specification.
         */
-       if (obj_desc->mutex.sync_level !=
-           walk_state->thread->current_sync_level) {
+       if (obj_desc->mutex.sync_level != owner_thread->current_sync_level) {
                ACPI_ERROR((AE_INFO,
-                           "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %d current %d",
+                           "Cannot release Mutex [%4.4s], SyncLevel mismatch: mutex %u current %u",
                            acpi_ut_get_node_name(obj_desc->mutex.node),
                            obj_desc->mutex.sync_level,
                            walk_state->thread->current_sync_level));
@@ -423,7 +422,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
         * acquired, but are not released in reverse order.
         */
        previous_sync_level =
-           walk_state->thread->acquired_mutex_list->mutex.original_sync_level;
+           owner_thread->acquired_mutex_list->mutex.original_sync_level;
 
        status = acpi_ex_release_mutex_object(obj_desc);
        if (ACPI_FAILURE(status)) {
@@ -434,8 +433,9 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
 
                /* Restore the previous sync_level */
 
-               walk_state->thread->current_sync_level = previous_sync_level;
+               owner_thread->current_sync_level = previous_sync_level;
        }
+
        return_ACPI_STATUS(status);
 }
 
@@ -443,7 +443,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
  *
  * FUNCTION:    acpi_ex_release_all_mutexes
  *
- * PARAMETERS:  Thread          - Current executing thread object
+ * PARAMETERS:  Thread              - Current executing thread object
  *
  * RETURN:      Status
  *
index 679f308..d11e539 100644 (file)
@@ -102,7 +102,7 @@ static char *acpi_ex_allocate_name_string(u32 prefix_count, u32 num_name_segs)
        name_string = ACPI_ALLOCATE(size_needed);
        if (!name_string) {
                ACPI_ERROR((AE_INFO,
-                           "Could not allocate size %d", size_needed));
+                           "Could not allocate size %u", size_needed));
                return_PTR(NULL);
        }
 
@@ -216,7 +216,7 @@ static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string)
                 */
                status = AE_AML_BAD_NAME;
                ACPI_ERROR((AE_INFO,
-                           "Bad character %02x in name, at %p",
+                           "Bad character 0x%02x in name, at %p",
                            *aml_address, aml_address));
        }
 
index 99adbab..84e4d18 100644 (file)
@@ -110,7 +110,7 @@ acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
 
        default:                /*  Unknown opcode  */
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                break;
@@ -173,7 +173,7 @@ acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
 
        case AML_SLEEP_OP:      /*  Sleep (msec_time) */
 
-               status = acpi_ex_system_do_suspend(operand[0]->integer.value);
+               status = acpi_ex_system_do_sleep(operand[0]->integer.value);
                break;
 
        case AML_STALL_OP:      /*  Stall (usec_time) */
@@ -189,7 +189,7 @@ acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
 
        default:                /*  Unknown opcode  */
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                break;
@@ -229,7 +229,7 @@ acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
 
        default:                /* Unknown opcode */
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
@@ -399,7 +399,7 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
 
                        if (digit > 0) {
                                ACPI_ERROR((AE_INFO,
-                                           "Integer too large to convert to BCD: %8.8X%8.8X",
+                                           "Integer too large to convert to BCD: 0x%8.8X%8.8X",
                                            ACPI_FORMAT_UINT64(operand[0]->
                                                               integer.value)));
                                status = AE_AML_NUMERIC_OVERFLOW;
@@ -540,7 +540,7 @@ acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
 
        default:                /* Unknown opcode */
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
@@ -979,7 +979,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
                                default:
 
                                        ACPI_ERROR((AE_INFO,
-                                                   "Unknown Index TargetType %X in reference object %p",
+                                                   "Unknown Index TargetType 0x%X in reference object %p",
                                                    operand[0]->reference.
                                                    target_type, operand[0]));
                                        status = AE_AML_OPERAND_TYPE;
@@ -1007,7 +1007,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
 
                        default:
                                ACPI_ERROR((AE_INFO,
-                                           "Unknown class in reference(%p) - %2.2X",
+                                           "Unknown class in reference(%p) - 0x%2.2X",
                                            operand[0],
                                            operand[0]->reference.class));
 
@@ -1019,7 +1019,7 @@ acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
index 22841bb..10e104c 100644 (file)
@@ -119,33 +119,6 @@ acpi_status acpi_ex_opcode_2A_0T_0R(struct acpi_walk_state *walk_state)
                        status = AE_AML_OPERAND_TYPE;
                        break;
                }
-#ifdef ACPI_GPE_NOTIFY_CHECK
-               /*
-                * GPE method wake/notify check.  Here, we want to ensure that we
-                * don't receive any "DeviceWake" Notifies from a GPE _Lxx or _Exx
-                * GPE method during system runtime.  If we do, the GPE is marked
-                * as "wake-only" and disabled.
-                *
-                * 1) Is the Notify() value == device_wake?
-                * 2) Is this a GPE deferred method?  (An _Lxx or _Exx method)
-                * 3) Did the original GPE happen at system runtime?
-                *    (versus during wake)
-                *
-                * If all three cases are true, this is a wake-only GPE that should
-                * be disabled at runtime.
-                */
-               if (value == 2) {       /* device_wake */
-                       status =
-                           acpi_ev_check_for_wake_only_gpe(walk_state->
-                                                           gpe_event_info);
-                       if (ACPI_FAILURE(status)) {
-
-                               /* AE_WAKE_ONLY_GPE only error, means ignore this notify */
-
-                               return_ACPI_STATUS(AE_OK)
-                       }
-               }
-#endif
 
                /*
                 * Dispatch the notify to the appropriate handler
@@ -159,7 +132,7 @@ acpi_status acpi_ex_opcode_2A_0T_0R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
        }
@@ -224,7 +197,7 @@ acpi_status acpi_ex_opcode_2A_2T_1R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
@@ -441,7 +414,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
 
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Index (%X%8.8X) is beyond end of object",
+                                       "Index (0x%8.8X%8.8X) is beyond end of object",
                                        ACPI_FORMAT_UINT64(index)));
                        goto cleanup;
                }
@@ -464,7 +437,7 @@ acpi_status acpi_ex_opcode_2A_1T_1R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                break;
@@ -572,7 +545,7 @@ acpi_status acpi_ex_opcode_2A_0T_1R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
index 8bb1012..7a08d23 100644 (file)
@@ -119,7 +119,7 @@ acpi_status acpi_ex_opcode_3A_0T_0R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
@@ -244,7 +244,7 @@ acpi_status acpi_ex_opcode_3A_1T_1R(struct acpi_walk_state *walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
index f256b6a..4b50730 100644 (file)
@@ -245,7 +245,7 @@ acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
                index = operand[5]->integer.value;
                if (index >= operand[0]->package.count) {
                        ACPI_ERROR((AE_INFO,
-                                   "Index (%X%8.8X) beyond package end (%X)",
+                                   "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
                                    ACPI_FORMAT_UINT64(index),
                                    operand[0]->package.count));
                        status = AE_AML_PACKAGE_LIMIT;
@@ -314,7 +314,7 @@ acpi_status acpi_ex_opcode_6A_0T_1R(struct acpi_walk_state * walk_state)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
                            walk_state->opcode));
                status = AE_AML_BAD_OPCODE;
                goto cleanup;
index 2fbfe51..25059da 100644 (file)
@@ -275,7 +275,7 @@ acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
        default:
                /* Invalid field access type */
 
-               ACPI_ERROR((AE_INFO, "Unknown field access type %X", access));
+               ACPI_ERROR((AE_INFO, "Unknown field access type 0x%X", access));
                return_UINT32(0);
        }
 
@@ -430,7 +430,7 @@ acpi_status acpi_ex_prep_field_value(struct acpi_create_field_info *info)
                type = acpi_ns_get_type(info->region_node);
                if (type != ACPI_TYPE_REGION) {
                        ACPI_ERROR((AE_INFO,
-                                   "Needed Region, found type %X (%s)",
+                                   "Needed Region, found type 0x%X (%s)",
                                    type, acpi_ut_get_type_name(type)));
 
                        return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
index 486b2e5..531000f 100644 (file)
@@ -105,7 +105,7 @@ acpi_ex_system_memory_space_handler(u32 function,
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %d",
+               ACPI_ERROR((AE_INFO, "Invalid SystemMemory width %u",
                            bit_width));
                return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
        }
@@ -173,7 +173,7 @@ acpi_ex_system_memory_space_handler(u32 function,
                mem_info->mapped_logical_address = acpi_os_map_memory((acpi_physical_address) address, map_length);
                if (!mem_info->mapped_logical_address) {
                        ACPI_ERROR((AE_INFO,
-                                   "Could not map memory at %8.8X%8.8X, size %X",
+                                   "Could not map memory at 0x%8.8X%8.8X, size %u",
                                    ACPI_FORMAT_NATIVE_UINT(address),
                                    (u32) map_length));
                        mem_info->mapped_length = 0;
@@ -491,8 +491,10 @@ acpi_ex_data_table_space_handler(u32 function,
 {
        ACPI_FUNCTION_TRACE(ex_data_table_space_handler);
 
-       /* Perform the memory read or write */
-
+       /*
+        * Perform the memory read or write. The bit_width was already
+        * validated.
+        */
        switch (function) {
        case ACPI_READ:
 
@@ -502,9 +504,14 @@ acpi_ex_data_table_space_handler(u32 function,
                break;
 
        case ACPI_WRITE:
+
+               ACPI_MEMCPY(ACPI_PHYSADDR_TO_PTR(address),
+                           ACPI_CAST_PTR(char, value), ACPI_DIV_8(bit_width));
+               break;
+
        default:
 
-               return_ACPI_STATUS(AE_SUPPORT);
+               return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
 
        return_ACPI_STATUS(AE_OK);
index fdc1b27..1fa4289 100644 (file)
@@ -252,7 +252,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
                        /* No named references are allowed here */
 
                        ACPI_ERROR((AE_INFO,
-                                   "Unsupported Reference type %X",
+                                   "Unsupported Reference type 0x%X",
                                    source_desc->reference.class));
 
                        return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -264,7 +264,7 @@ acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
                /* Default case is for unknown types */
 
                ACPI_ERROR((AE_INFO,
-                           "Node %p - Unknown object type %X",
+                           "Node %p - Unknown object type 0x%X",
                            node, entry_type));
 
                return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
index fdd6a70..7ca35ea 100644 (file)
@@ -231,7 +231,7 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
                                /* Invalid reference object */
 
                                ACPI_ERROR((AE_INFO,
-                                           "Unknown TargetType %X in Index/Reference object %p",
+                                           "Unknown TargetType 0x%X in Index/Reference object %p",
                                            stack_desc->reference.target_type,
                                            stack_desc));
                                status = AE_AML_INTERNAL;
@@ -273,8 +273,8 @@ acpi_ex_resolve_object_to_value(union acpi_operand_object **stack_ptr,
                default:
 
                        ACPI_ERROR((AE_INFO,
-                                   "Unknown Reference type %X in %p", ref_type,
-                                   stack_desc));
+                                   "Unknown Reference type 0x%X in %p",
+                                   ref_type, stack_desc));
                        status = AE_AML_INTERNAL;
                        break;
                }
@@ -403,7 +403,8 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
 
                        if (ACPI_GET_DESCRIPTOR_TYPE(node) !=
                            ACPI_DESC_TYPE_NAMED) {
-                               ACPI_ERROR((AE_INFO, "Not a NS node %p [%s]",
+                               ACPI_ERROR((AE_INFO,
+                                           "Not a namespace node %p [%s]",
                                            node,
                                            acpi_ut_get_descriptor_name(node)));
                                return_ACPI_STATUS(AE_AML_INTERNAL);
@@ -507,7 +508,7 @@ acpi_ex_resolve_multiple(struct acpi_walk_state *walk_state,
                default:
 
                        ACPI_ERROR((AE_INFO,
-                                   "Unknown Reference Class %2.2X",
+                                   "Unknown Reference Class 0x%2.2X",
                                    obj_desc->reference.class));
                        return_ACPI_STATUS(AE_AML_INTERNAL);
                }
index c5ecd61..8c97cfd 100644 (file)
@@ -153,7 +153,7 @@ acpi_ex_resolve_operands(u16 opcode,
 
        arg_types = op_info->runtime_args;
        if (arg_types == ARGI_INVALID_OPCODE) {
-               ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", opcode));
+               ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X", opcode));
 
                return_ACPI_STATUS(AE_AML_INTERNAL);
        }
@@ -218,7 +218,7 @@ acpi_ex_resolve_operands(u16 opcode,
 
                        if (!acpi_ut_valid_object_type(object_type)) {
                                ACPI_ERROR((AE_INFO,
-                                           "Bad operand object type [%X]",
+                                           "Bad operand object type [0x%X]",
                                            object_type));
 
                                return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
@@ -253,7 +253,7 @@ acpi_ex_resolve_operands(u16 opcode,
                                default:
 
                                        ACPI_ERROR((AE_INFO,
-                                                   "Unknown Reference Class %2.2X in %p",
+                                                   "Unknown Reference Class 0x%2.2X in %p",
                                                    obj_desc->reference.class,
                                                    obj_desc));
 
@@ -665,7 +665,7 @@ acpi_ex_resolve_operands(u16 opcode,
                        /* Unknown type */
 
                        ACPI_ERROR((AE_INFO,
-                                   "Internal - Unknown ARGI (required operand) type %X",
+                                   "Internal - Unknown ARGI (required operand) type 0x%X",
                                    this_arg_type));
 
                        return_ACPI_STATUS(AE_BAD_PARAMETER);
index 702b9ec..1624436 100644 (file)
@@ -1,4 +1,3 @@
-
 /******************************************************************************
  *
  * Module Name: exstore - AML Interpreter object store support
 ACPI_MODULE_NAME("exstore")
 
 /* Local prototypes */
-static void
-acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
-                       u32 level, u32 index);
-
 static acpi_status
 acpi_ex_store_object_to_index(union acpi_operand_object *val_desc,
                              union acpi_operand_object *dest_desc,
                              struct acpi_walk_state *walk_state);
 
-/*******************************************************************************
- *
- * FUNCTION:    acpi_ex_do_debug_object
- *
- * PARAMETERS:  source_desc         - Value to be stored
- *              Level               - Indentation level (used for packages)
- *              Index               - Current package element, zero if not pkg
- *
- * RETURN:      None
- *
- * DESCRIPTION: Handles stores to the Debug Object.
- *
- ******************************************************************************/
-
-static void
-acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
-                       u32 level, u32 index)
-{
-       u32 i;
-
-       ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
-
-       /* Print line header as long as we are not in the middle of an object display */
-
-       if (!((level > 0) && index == 0)) {
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[ACPI Debug] %*s",
-                                     level, " "));
-       }
-
-       /* Display index for package output only */
-
-       if (index > 0) {
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                     "(%.2u) ", index - 1));
-       }
-
-       if (!source_desc) {
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[Null Object]\n"));
-               return_VOID;
-       }
-
-       if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s ",
-                                     acpi_ut_get_object_type_name
-                                     (source_desc)));
-
-               if (!acpi_ut_valid_internal_object(source_desc)) {
-                       ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                             "%p, Invalid Internal Object!\n",
-                                             source_desc));
-                       return_VOID;
-               }
-       } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
-                  ACPI_DESC_TYPE_NAMED) {
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%s: %p\n",
-                                     acpi_ut_get_type_name(((struct
-                                                             acpi_namespace_node
-                                                             *)source_desc)->
-                                                           type),
-                                     source_desc));
-               return_VOID;
-       } else {
-               return_VOID;
-       }
-
-       /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
-
-       switch (source_desc->common.type) {
-       case ACPI_TYPE_INTEGER:
-
-               /* Output correct integer width */
-
-               if (acpi_gbl_integer_byte_width == 4) {
-                       ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%8.8X\n",
-                                             (u32) source_desc->integer.
-                                             value));
-               } else {
-                       ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                             "0x%8.8X%8.8X\n",
-                                             ACPI_FORMAT_UINT64(source_desc->
-                                                                integer.
-                                                                value)));
-               }
-               break;
-
-       case ACPI_TYPE_BUFFER:
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X]\n",
-                                     (u32) source_desc->buffer.length));
-               ACPI_DUMP_BUFFER(source_desc->buffer.pointer,
-                                (source_desc->buffer.length <
-                                 256) ? source_desc->buffer.length : 256);
-               break;
-
-       case ACPI_TYPE_STRING:
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[0x%.2X] \"%s\"\n",
-                                     source_desc->string.length,
-                                     source_desc->string.pointer));
-               break;
-
-       case ACPI_TYPE_PACKAGE:
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                     "[Contains 0x%.2X Elements]\n",
-                                     source_desc->package.count));
-
-               /* Output the entire contents of the package */
-
-               for (i = 0; i < source_desc->package.count; i++) {
-                       acpi_ex_do_debug_object(source_desc->package.
-                                               elements[i], level + 4, i + 1);
-               }
-               break;
-
-       case ACPI_TYPE_LOCAL_REFERENCE:
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "[%s] ",
-                                     acpi_ut_get_reference_name(source_desc)));
-
-               /* Decode the reference */
-
-               switch (source_desc->reference.class) {
-               case ACPI_REFCLASS_INDEX:
-
-                       ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "0x%X\n",
-                                             source_desc->reference.value));
-                       break;
-
-               case ACPI_REFCLASS_TABLE:
-
-                       /* Case for ddb_handle */
-
-                       ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                             "Table Index 0x%X\n",
-                                             source_desc->reference.value));
-                       return;
-
-               default:
-                       break;
-               }
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "  "));
-
-               /* Check for valid node first, then valid object */
-
-               if (source_desc->reference.node) {
-                       if (ACPI_GET_DESCRIPTOR_TYPE
-                           (source_desc->reference.node) !=
-                           ACPI_DESC_TYPE_NAMED) {
-                               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                                     " %p - Not a valid namespace node\n",
-                                                     source_desc->reference.
-                                                     node));
-                       } else {
-                               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT,
-                                                     "Node %p [%4.4s] ",
-                                                     source_desc->reference.
-                                                     node,
-                                                     (source_desc->reference.
-                                                      node)->name.ascii));
-
-                               switch ((source_desc->reference.node)->type) {
-
-                                       /* These types have no attached object */
-
-                               case ACPI_TYPE_DEVICE:
-                                       acpi_os_printf("Device\n");
-                                       break;
-
-                               case ACPI_TYPE_THERMAL:
-                                       acpi_os_printf("Thermal Zone\n");
-                                       break;
-
-                               default:
-                                       acpi_ex_do_debug_object((source_desc->
-                                                                reference.
-                                                                node)->object,
-                                                               level + 4, 0);
-                                       break;
-                               }
-                       }
-               } else if (source_desc->reference.object) {
-                       if (ACPI_GET_DESCRIPTOR_TYPE
-                           (source_desc->reference.object) ==
-                           ACPI_DESC_TYPE_NAMED) {
-                               acpi_ex_do_debug_object(((struct
-                                                         acpi_namespace_node *)
-                                                        source_desc->reference.
-                                                        object)->object,
-                                                       level + 4, 0);
-                       } else {
-                               acpi_ex_do_debug_object(source_desc->reference.
-                                                       object, level + 4, 0);
-                       }
-               }
-               break;
-
-       default:
-
-               ACPI_DEBUG_PRINT_RAW((ACPI_DB_DEBUG_OBJECT, "%p\n",
-                                     source_desc));
-               break;
-       }
-
-       ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
-       return_VOID;
-}
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ex_store
@@ -402,12 +188,12 @@ acpi_ex_store(union acpi_operand_object *source_desc,
                                  source_desc,
                                  acpi_ut_get_object_type_name(source_desc)));
 
-               acpi_ex_do_debug_object(source_desc, 0, 0);
+               ACPI_DEBUG_OBJECT(source_desc, 0, 0);
                break;
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown Reference Class %2.2X",
+               ACPI_ERROR((AE_INFO, "Unknown Reference Class 0x%2.2X",
                            ref_desc->reference.class));
                ACPI_DUMP_ENTRY(ref_desc, ACPI_LV_INFO);
 
index e11b6cb..6d32e09 100644 (file)
@@ -170,7 +170,7 @@ acpi_status acpi_ex_system_do_stall(u32 how_long)
                 * (ACPI specifies 100 usec as max, but this gives some slack in
                 * order to support existing BIOSs)
                 */
-               ACPI_ERROR((AE_INFO, "Time parameter is too large (%d)",
+               ACPI_ERROR((AE_INFO, "Time parameter is too large (%u)",
                            how_long));
                status = AE_AML_OPERAND_VALUE;
        } else {
@@ -182,18 +182,18 @@ acpi_status acpi_ex_system_do_stall(u32 how_long)
 
 /*******************************************************************************
  *
- * FUNCTION:    acpi_ex_system_do_suspend
+ * FUNCTION:    acpi_ex_system_do_sleep
  *
- * PARAMETERS:  how_long        - The amount of time to suspend,
+ * PARAMETERS:  how_long        - The amount of time to sleep,
  *                                in milliseconds
  *
  * RETURN:      None
  *
- * DESCRIPTION: Suspend running thread for specified amount of time.
+ * DESCRIPTION: Sleep the running thread for specified amount of time.
  *
  ******************************************************************************/
 
-acpi_status acpi_ex_system_do_suspend(u64 how_long)
+acpi_status acpi_ex_system_do_sleep(u64 how_long)
 {
        ACPI_FUNCTION_ENTRY();
 
index ec7fc22..5d1273b 100644 (file)
@@ -299,7 +299,7 @@ struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
        ACPI_FUNCTION_ENTRY();
 
        if (register_id > ACPI_BITREG_MAX) {
-               ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: %X",
+               ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
                            register_id));
                return (NULL);
        }
@@ -413,7 +413,7 @@ acpi_hw_register_read(u32 register_id, u32 * return_value)
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
+               ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
                status = AE_BAD_PARAMETER;
                break;
        }
@@ -549,7 +549,7 @@ acpi_status acpi_hw_register_write(u32 register_id, u32 value)
                break;
 
        default:
-               ACPI_ERROR((AE_INFO, "Unknown Register ID: %X", register_id));
+               ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
                status = AE_BAD_PARAMETER;
                break;
        }
index 5e6d4db..36eb803 100644 (file)
@@ -245,7 +245,7 @@ acpi_status asmlinkage acpi_enter_sleep_state(u8 sleep_state)
 
        if ((acpi_gbl_sleep_type_a > ACPI_SLEEP_TYPE_MAX) ||
            (acpi_gbl_sleep_type_b > ACPI_SLEEP_TYPE_MAX)) {
-               ACPI_ERROR((AE_INFO, "Sleep values out of range: A=%X B=%X",
+               ACPI_ERROR((AE_INFO, "Sleep values out of range: A=0x%X B=0x%X",
                            acpi_gbl_sleep_type_a, acpi_gbl_sleep_type_b));
                return_ACPI_STATUS(AE_AML_OPERAND_VALUE);
        }
index e26c17d..c10d587 100644 (file)
@@ -150,7 +150,7 @@ acpi_hw_validate_io_request(acpi_io_address address, u32 bit_width)
 
        if (last_address > ACPI_UINT16_MAX) {
                ACPI_ERROR((AE_INFO,
-                           "Illegal I/O port address/length above 64K: 0x%p/%X",
+                           "Illegal I/O port address/length above 64K: %p/0x%X",
                            ACPI_CAST_PTR(void, address), byte_width));
                return_ACPI_STATUS(AE_LIMIT);
        }
index aa2b801..3a28146 100644 (file)
@@ -222,7 +222,7 @@ acpi_status acpi_ns_root_initialize(void)
                        default:
 
                                ACPI_ERROR((AE_INFO,
-                                           "Unsupported initial type value %X",
+                                           "Unsupported initial type value 0x%X",
                                            init_val->type));
                                acpi_ut_remove_reference(obj_desc);
                                obj_desc = NULL;
index 0689d36..2110cc2 100644 (file)
@@ -205,8 +205,8 @@ acpi_ns_dump_one_object(acpi_handle obj_handle,
                /* Check the node type and name */
 
                if (type > ACPI_TYPE_LOCAL_MAX) {
-                       ACPI_WARNING((AE_INFO, "Invalid ACPI Object Type %08X",
-                                     type));
+                       ACPI_WARNING((AE_INFO,
+                                     "Invalid ACPI Object Type 0x%08X", type));
                }
 
                if (!acpi_ut_valid_acpi_name(this_node->name.integer)) {
index 9593724..7dea003 100644 (file)
@@ -107,7 +107,7 @@ acpi_ns_build_external_path(struct acpi_namespace_node *node,
 
        if (index != 0) {
                ACPI_ERROR((AE_INFO,
-                           "Could not construct external pathname; index=%X, size=%X, Path=%s",
+                           "Could not construct external pathname; index=%u, size=%u, Path=%s",
                            (u32) index, (u32) size, &name_buffer[size]));
 
                return (AE_BAD_PARAMETER);
index 08f8b3f..a8e42b5 100644 (file)
@@ -311,7 +311,7 @@ acpi_ns_search_and_enter(u32 target_name,
 
        if (!node || !target_name || !return_node) {
                ACPI_ERROR((AE_INFO,
-                           "Null parameter: Node %p Name %X ReturnNode %p",
+                           "Null parameter: Node %p Name 0x%X ReturnNode %p",
                            node, target_name, return_node));
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
index 24d05a8..bab5597 100644 (file)
@@ -276,7 +276,7 @@ u32 acpi_ns_local(acpi_object_type type)
 
                /* Type code out of range  */
 
-               ACPI_WARNING((AE_INFO, "Invalid Object Type %X", type));
+               ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type));
                return_UINT32(ACPI_NS_NORMAL);
        }
 
@@ -764,7 +764,7 @@ u32 acpi_ns_opens_scope(acpi_object_type type)
 
                /* type code out of range  */
 
-               ACPI_WARNING((AE_INFO, "Invalid Object Type %X", type));
+               ACPI_WARNING((AE_INFO, "Invalid Object Type 0x%X", type));
                return_UINT32(ACPI_NS_NORMAL);
        }
 
index 00493e1..7df1a4c 100644 (file)
@@ -460,7 +460,7 @@ acpi_ps_get_next_simple_arg(struct acpi_parse_state *parser_state,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Invalid ArgType %X", arg_type));
+               ACPI_ERROR((AE_INFO, "Invalid ArgType 0x%X", arg_type));
                return_VOID;
        }
 
@@ -742,7 +742,7 @@ acpi_ps_get_next_arg(struct acpi_walk_state *walk_state,
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Invalid ArgType: %X", arg_type));
+               ACPI_ERROR((AE_INFO, "Invalid ArgType: 0x%X", arg_type));
                status = AE_AML_OPERAND_TYPE;
                break;
        }
index 59aabae..2f2e776 100644 (file)
@@ -136,7 +136,7 @@ static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state)
                /* The opcode is unrecognized. Just skip unknown opcodes */
 
                ACPI_ERROR((AE_INFO,
-                           "Found unknown opcode %X at AML address %p offset %X, ignoring",
+                           "Found unknown opcode 0x%X at AML address %p offset 0x%X, ignoring",
                            walk_state->opcode, walk_state->parser_state.aml,
                            walk_state->aml_offset));
 
@@ -1021,7 +1021,6 @@ acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state)
                                        if (status == AE_AML_NO_RETURN_VALUE) {
                                                ACPI_EXCEPTION((AE_INFO, status,
                                                                "Invoked method did not return a value"));
-
                                        }
 
                                        ACPI_EXCEPTION((AE_INFO, status,
index 6064dd4..c42f067 100644 (file)
@@ -46,6 +46,7 @@
 #include "acparser.h"
 #include "acdispat.h"
 #include "acinterp.h"
+#include "actables.h"
 #include "amlcode.h"
 
 #define _COMPONENT          ACPI_PARSER
@@ -220,6 +221,10 @@ acpi_status acpi_ps_execute_method(struct acpi_evaluate_info *info)
 
        ACPI_FUNCTION_TRACE(ps_execute_method);
 
+       /* Quick validation of DSDT header */
+
+       acpi_tb_check_dsdt_header();
+
        /* Validate the Info and method Node */
 
        if (!info || !info->resolved_node) {
index f2ee3b5..c80a2ee 100644 (file)
@@ -212,7 +212,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
 
                if ((*top_object_list)->common.type != ACPI_TYPE_PACKAGE) {
                        ACPI_ERROR((AE_INFO,
-                                   "(PRT[%X]) Need sub-package, found %s",
+                                   "(PRT[%u]) Need sub-package, found %s",
                                    index,
                                    acpi_ut_get_object_type_name
                                    (*top_object_list)));
@@ -223,7 +223,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
 
                if ((*top_object_list)->package.count != 4) {
                        ACPI_ERROR((AE_INFO,
-                                   "(PRT[%X]) Need package of length 4, found length %d",
+                                   "(PRT[%u]) Need package of length 4, found length %u",
                                    index, (*top_object_list)->package.count));
                        return_ACPI_STATUS(AE_AML_PACKAGE_LIMIT);
                }
@@ -240,7 +240,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
                obj_desc = sub_object_list[0];
                if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
                        ACPI_ERROR((AE_INFO,
-                                   "(PRT[%X].Address) Need Integer, found %s",
+                                   "(PRT[%u].Address) Need Integer, found %s",
                                    index,
                                    acpi_ut_get_object_type_name(obj_desc)));
                        return_ACPI_STATUS(AE_BAD_DATA);
@@ -253,7 +253,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
                obj_desc = sub_object_list[1];
                if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
                        ACPI_ERROR((AE_INFO,
-                                   "(PRT[%X].Pin) Need Integer, found %s",
+                                   "(PRT[%u].Pin) Need Integer, found %s",
                                    index,
                                    acpi_ut_get_object_type_name(obj_desc)));
                        return_ACPI_STATUS(AE_BAD_DATA);
@@ -289,7 +289,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
                                if (obj_desc->reference.class !=
                                    ACPI_REFCLASS_NAME) {
                                        ACPI_ERROR((AE_INFO,
-                                                   "(PRT[%X].Source) Need name, found Reference Class %X",
+                                                   "(PRT[%u].Source) Need name, found Reference Class 0x%X",
                                                    index,
                                                    obj_desc->reference.class));
                                        return_ACPI_STATUS(AE_BAD_DATA);
@@ -340,7 +340,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
                        default:
 
                                ACPI_ERROR((AE_INFO,
-                                           "(PRT[%X].Source) Need Ref/String/Integer, found %s",
+                                           "(PRT[%u].Source) Need Ref/String/Integer, found %s",
                                            index,
                                            acpi_ut_get_object_type_name
                                            (obj_desc)));
@@ -358,7 +358,7 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
                obj_desc = sub_object_list[3];
                if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
                        ACPI_ERROR((AE_INFO,
-                                   "(PRT[%X].SourceIndex) Need Integer, found %s",
+                                   "(PRT[%u].SourceIndex) Need Integer, found %s",
                                    index,
                                    acpi_ut_get_object_type_name(obj_desc)));
                        return_ACPI_STATUS(AE_BAD_DATA);
index fd057c7..7335f22 100644 (file)
@@ -94,7 +94,7 @@ acpi_rs_convert_aml_to_resources(u8 * aml,
                                            [resource_index]);
        if (ACPI_FAILURE(status)) {
                ACPI_EXCEPTION((AE_INFO, status,
-                               "Could not convert AML resource (Type %X)",
+                               "Could not convert AML resource (Type 0x%X)",
                                *aml));
                return_ACPI_STATUS(status);
        }
@@ -147,7 +147,7 @@ acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
 
                if (resource->type > ACPI_RESOURCE_TYPE_MAX) {
                        ACPI_ERROR((AE_INFO,
-                                   "Invalid descriptor type (%X) in resource list",
+                                   "Invalid descriptor type (0x%X) in resource list",
                                    resource->type));
                        return_ACPI_STATUS(AE_BAD_DATA);
                }
@@ -161,7 +161,7 @@ acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
                                                         [resource->type]);
                if (ACPI_FAILURE(status)) {
                        ACPI_EXCEPTION((AE_INFO, status,
-                                       "Could not convert resource (type %X) to AML",
+                                       "Could not convert resource (type 0x%X) to AML",
                                        resource->type));
                        return_ACPI_STATUS(status);
                }
index 07de352..f8cd9e8 100644 (file)
@@ -88,7 +88,7 @@ acpi_rs_convert_aml_to_resource(struct acpi_resource *resource,
                /* Each internal resource struct is expected to be 32-bit aligned */
 
                ACPI_WARNING((AE_INFO,
-                             "Misaligned resource pointer (get): %p Type %2.2X Len %X",
+                             "Misaligned resource pointer (get): %p Type 0x%2.2X Length %u",
                              resource, resource->type, resource->length));
        }
 
@@ -541,7 +541,7 @@ if (((aml->irq.flags & 0x09) == 0x00) || ((aml->irq.flags & 0x09) == 0x09)) {
         * "IRQ Format"), so 0x00 and 0x09 are illegal.
         */
        ACPI_ERROR((AE_INFO,
-                   "Invalid interrupt polarity/trigger in resource list, %X",
+                   "Invalid interrupt polarity/trigger in resource list, 0x%X",
                    aml->irq.flags));
        return_ACPI_STATUS(AE_BAD_DATA);
 }
index f43fbe0..1728cb9 100644 (file)
@@ -283,7 +283,7 @@ void acpi_tb_create_local_fadt(struct acpi_table_header *table, u32 length)
        if (length > sizeof(struct acpi_table_fadt)) {
                ACPI_WARNING((AE_INFO,
                              "FADT (revision %u) is longer than ACPI 2.0 version, "
-                             "truncating length 0x%X to 0x%X",
+                             "truncating length %u to %u",
                              table->revision, length,
                              (u32)sizeof(struct acpi_table_fadt)));
        }
@@ -422,7 +422,7 @@ static void acpi_tb_convert_fadt(void)
                if (address64->address && address32 &&
                    (address64->address != (u64) address32)) {
                        ACPI_ERROR((AE_INFO,
-                                   "32/64X address mismatch in %s: %8.8X/%8.8X%8.8X, using 32",
+                                   "32/64X address mismatch in %s: 0x%8.8X/0x%8.8X%8.8X, using 32",
                                    fadt_info_table[i].name, address32,
                                    ACPI_FORMAT_UINT64(address64->address)));
                }
@@ -481,7 +481,7 @@ static void acpi_tb_validate_fadt(void)
            (acpi_gbl_FADT.Xfacs != (u64) acpi_gbl_FADT.facs)) {
                ACPI_WARNING((AE_INFO,
                              "32/64X FACS address mismatch in FADT - "
-                             "%8.8X/%8.8X%8.8X, using 32",
+                             "0x%8.8X/0x%8.8X%8.8X, using 32",
                              acpi_gbl_FADT.facs,
                              ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xfacs)));
 
@@ -492,7 +492,7 @@ static void acpi_tb_validate_fadt(void)
            (acpi_gbl_FADT.Xdsdt != (u64) acpi_gbl_FADT.dsdt)) {
                ACPI_WARNING((AE_INFO,
                              "32/64X DSDT address mismatch in FADT - "
-                             "%8.8X/%8.8X%8.8X, using 32",
+                             "0x%8.8X/0x%8.8X%8.8X, using 32",
                              acpi_gbl_FADT.dsdt,
                              ACPI_FORMAT_UINT64(acpi_gbl_FADT.Xdsdt)));
 
@@ -521,7 +521,7 @@ static void acpi_tb_validate_fadt(void)
                if (address64->address &&
                    (address64->bit_width != ACPI_MUL_8(length))) {
                        ACPI_WARNING((AE_INFO,
-                                     "32/64X length mismatch in %s: %d/%d",
+                                     "32/64X length mismatch in %s: %u/%u",
                                      name, ACPI_MUL_8(length),
                                      address64->bit_width));
                }
@@ -534,7 +534,7 @@ static void acpi_tb_validate_fadt(void)
                        if (!address64->address || !length) {
                                ACPI_ERROR((AE_INFO,
                                            "Required field %s has zero address and/or length:"
-                                           " %8.8X%8.8X/%X",
+                                           " 0x%8.8X%8.8X/0x%X",
                                            name,
                                            ACPI_FORMAT_UINT64(address64->
                                                               address),
@@ -550,7 +550,7 @@ static void acpi_tb_validate_fadt(void)
                            (!address64->address && length)) {
                                ACPI_WARNING((AE_INFO,
                                              "Optional field %s has zero address or length: "
-                                             "%8.8X%8.8X/%X",
+                                             "0x%8.8X%8.8X/0x%X",
                                              name,
                                              ACPI_FORMAT_UINT64(address64->
                                                                 address),
@@ -600,7 +600,7 @@ static void acpi_tb_setup_fadt_registers(void)
                            (fadt_info_table[i].default_length !=
                             target64->bit_width)) {
                                ACPI_WARNING((AE_INFO,
-                                             "Invalid length for %s: %d, using default %d",
+                                             "Invalid length for %s: %u, using default %u",
                                              fadt_info_table[i].name,
                                              target64->bit_width,
                                              fadt_info_table[i].
index e252180..989d5c8 100644 (file)
@@ -83,7 +83,7 @@ acpi_tb_find_table(char *signature,
 
        /* Search for the table */
 
-       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+       for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
                if (ACPI_MEMCMP(&(acpi_gbl_root_table_list.tables[i].signature),
                                header.signature, ACPI_NAME_SIZE)) {
 
index 7ec02b0..83d7af8 100644 (file)
@@ -137,7 +137,7 @@ acpi_tb_add_table(struct acpi_table_desc *table_desc, u32 *table_index)
 
        /* Check if table is already registered */
 
-       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+       for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
                if (!acpi_gbl_root_table_list.tables[i].pointer) {
                        status =
                            acpi_tb_verify_table(&acpi_gbl_root_table_list.
@@ -273,7 +273,7 @@ acpi_status acpi_tb_resize_root_table_list(void)
        /* Increase the Table Array size */
 
        tables = ACPI_ALLOCATE_ZEROED(((acpi_size) acpi_gbl_root_table_list.
-                                      size +
+                                      max_table_count +
                                       ACPI_ROOT_TABLE_SIZE_INCREMENT) *
                                      sizeof(struct acpi_table_desc));
        if (!tables) {
@@ -286,8 +286,8 @@ acpi_status acpi_tb_resize_root_table_list(void)
 
        if (acpi_gbl_root_table_list.tables) {
                ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables,
-                           (acpi_size) acpi_gbl_root_table_list.size *
-                           sizeof(struct acpi_table_desc));
+                           (acpi_size) acpi_gbl_root_table_list.
+                           max_table_count * sizeof(struct acpi_table_desc));
 
                if (acpi_gbl_root_table_list.flags & ACPI_ROOT_ORIGIN_ALLOCATED) {
                        ACPI_FREE(acpi_gbl_root_table_list.tables);
@@ -295,8 +295,9 @@ acpi_status acpi_tb_resize_root_table_list(void)
        }
 
        acpi_gbl_root_table_list.tables = tables;
-       acpi_gbl_root_table_list.size += ACPI_ROOT_TABLE_SIZE_INCREMENT;
-       acpi_gbl_root_table_list.flags |= (u8) ACPI_ROOT_ORIGIN_ALLOCATED;
+       acpi_gbl_root_table_list.max_table_count +=
+           ACPI_ROOT_TABLE_SIZE_INCREMENT;
+       acpi_gbl_root_table_list.flags |= (u8)ACPI_ROOT_ORIGIN_ALLOCATED;
 
        return_ACPI_STATUS(AE_OK);
 }
@@ -321,38 +322,36 @@ acpi_tb_store_table(acpi_physical_address address,
                    struct acpi_table_header *table,
                    u32 length, u8 flags, u32 *table_index)
 {
-       acpi_status status = AE_OK;
+       acpi_status status;
+       struct acpi_table_desc *new_table;
 
        /* Ensure that there is room for the table in the Root Table List */
 
-       if (acpi_gbl_root_table_list.count >= acpi_gbl_root_table_list.size) {
+       if (acpi_gbl_root_table_list.current_table_count >=
+           acpi_gbl_root_table_list.max_table_count) {
                status = acpi_tb_resize_root_table_list();
                if (ACPI_FAILURE(status)) {
                        return (status);
                }
        }
 
+       new_table =
+           &acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
+                                            current_table_count];
+
        /* Initialize added table */
 
-       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
-           address = address;
-       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
-           pointer = table;
-       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].length =
-           length;
-       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
-           owner_id = 0;
-       acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].flags =
-           flags;
-
-       ACPI_MOVE_32_TO_32(&
-                          (acpi_gbl_root_table_list.
-                           tables[acpi_gbl_root_table_list.count].signature),
-                          table->signature);
-
-       *table_index = acpi_gbl_root_table_list.count;
-       acpi_gbl_root_table_list.count++;
-       return (status);
+       new_table->address = address;
+       new_table->pointer = table;
+       new_table->length = length;
+       new_table->owner_id = 0;
+       new_table->flags = flags;
+
+       ACPI_MOVE_32_TO_32(&new_table->signature, table->signature);
+
+       *table_index = acpi_gbl_root_table_list.current_table_count;
+       acpi_gbl_root_table_list.current_table_count++;
+       return (AE_OK);
 }
 
 /*******************************************************************************
@@ -408,7 +407,7 @@ void acpi_tb_terminate(void)
 
        /* Delete the individual tables */
 
-       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+       for (i = 0; i < acpi_gbl_root_table_list.current_table_count; i++) {
                acpi_tb_delete_table(&acpi_gbl_root_table_list.tables[i]);
        }
 
@@ -422,7 +421,7 @@ void acpi_tb_terminate(void)
 
        acpi_gbl_root_table_list.tables = NULL;
        acpi_gbl_root_table_list.flags = 0;
-       acpi_gbl_root_table_list.count = 0;
+       acpi_gbl_root_table_list.current_table_count = 0;
 
        ACPI_DEBUG_PRINT((ACPI_DB_INFO, "ACPI Tables freed\n"));
        (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
@@ -452,7 +451,7 @@ acpi_status acpi_tb_delete_namespace_by_owner(u32 table_index)
                return_ACPI_STATUS(status);
        }
 
-       if (table_index >= acpi_gbl_root_table_list.count) {
+       if (table_index >= acpi_gbl_root_table_list.current_table_count) {
 
                /* The table index does not exist */
 
@@ -505,7 +504,7 @@ acpi_status acpi_tb_allocate_owner_id(u32 table_index)
        ACPI_FUNCTION_TRACE(tb_allocate_owner_id);
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (table_index < acpi_gbl_root_table_list.count) {
+       if (table_index < acpi_gbl_root_table_list.current_table_count) {
                status = acpi_ut_allocate_owner_id
                    (&(acpi_gbl_root_table_list.tables[table_index].owner_id));
        }
@@ -533,7 +532,7 @@ acpi_status acpi_tb_release_owner_id(u32 table_index)
        ACPI_FUNCTION_TRACE(tb_release_owner_id);
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (table_index < acpi_gbl_root_table_list.count) {
+       if (table_index < acpi_gbl_root_table_list.current_table_count) {
                acpi_ut_release_owner_id(&
                                         (acpi_gbl_root_table_list.
                                          tables[table_index].owner_id));
@@ -564,7 +563,7 @@ acpi_status acpi_tb_get_owner_id(u32 table_index, acpi_owner_id *owner_id)
        ACPI_FUNCTION_TRACE(tb_get_owner_id);
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (table_index < acpi_gbl_root_table_list.count) {
+       if (table_index < acpi_gbl_root_table_list.current_table_count) {
                *owner_id =
                    acpi_gbl_root_table_list.tables[table_index].owner_id;
                status = AE_OK;
@@ -589,7 +588,7 @@ u8 acpi_tb_is_table_loaded(u32 table_index)
        u8 is_loaded = FALSE;
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (table_index < acpi_gbl_root_table_list.count) {
+       if (table_index < acpi_gbl_root_table_list.current_table_count) {
                is_loaded = (u8)
                    (acpi_gbl_root_table_list.tables[table_index].flags &
                     ACPI_TABLE_IS_LOADED);
@@ -616,7 +615,7 @@ void acpi_tb_set_table_loaded_flag(u32 table_index, u8 is_loaded)
 {
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       if (table_index < acpi_gbl_root_table_list.count) {
+       if (table_index < acpi_gbl_root_table_list.current_table_count) {
                if (is_loaded) {
                        acpi_gbl_root_table_list.tables[table_index].flags |=
                            ACPI_TABLE_IS_LOADED;
index 02723a9..34f9c2b 100644 (file)
@@ -158,7 +158,7 @@ acpi_status acpi_tb_initialize_facs(void)
 u8 acpi_tb_tables_loaded(void)
 {
 
-       if (acpi_gbl_root_table_list.count >= 3) {
+       if (acpi_gbl_root_table_list.current_table_count >= 3) {
                return (TRUE);
        }
 
@@ -309,7 +309,7 @@ acpi_status acpi_tb_verify_checksum(struct acpi_table_header *table, u32 length)
 
        if (checksum) {
                ACPI_WARNING((AE_INFO,
-                             "Incorrect checksum in table [%4.4s] - %2.2X, should be %2.2X",
+                             "Incorrect checksum in table [%4.4s] - 0x%2.2X, should be 0x%2.2X",
                              table->signature, table->checksum,
                              (u8) (table->checksum - checksum)));
 
@@ -347,6 +347,84 @@ u8 acpi_tb_checksum(u8 *buffer, u32 length)
        return sum;
 }
 
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_check_dsdt_header
+ *
+ * PARAMETERS:  None
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Quick compare to check validity of the DSDT. This will detect
+ *              if the DSDT has been replaced from outside the OS and/or if
+ *              the DSDT header has been corrupted.
+ *
+ ******************************************************************************/
+
+void acpi_tb_check_dsdt_header(void)
+{
+
+       /* Compare original length and checksum to current values */
+
+       if (acpi_gbl_original_dsdt_header.length != acpi_gbl_DSDT->length ||
+           acpi_gbl_original_dsdt_header.checksum != acpi_gbl_DSDT->checksum) {
+               ACPI_ERROR((AE_INFO,
+                           "The DSDT has been corrupted or replaced - old, new headers below"));
+               acpi_tb_print_table_header(0, &acpi_gbl_original_dsdt_header);
+               acpi_tb_print_table_header(0, acpi_gbl_DSDT);
+
+               ACPI_ERROR((AE_INFO,
+                           "Please send DMI info to linux-acpi@vger.kernel.org\n"
+                           "If system does not work as expected, please boot with acpi=copy_dsdt"));
+
+               /* Disable further error messages */
+
+               acpi_gbl_original_dsdt_header.length = acpi_gbl_DSDT->length;
+               acpi_gbl_original_dsdt_header.checksum =
+                   acpi_gbl_DSDT->checksum;
+       }
+}
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_tb_copy_dsdt
+ *
+ * PARAMETERS:  table_desc          - Installed table to copy
+ *
+ * RETURN:      None
+ *
+ * DESCRIPTION: Implements a subsystem option to copy the DSDT to local memory.
+ *              Some very bad BIOSs are known to either corrupt the DSDT or
+ *              install a new, bad DSDT. This copy works around the problem.
+ *
+ ******************************************************************************/
+
+struct acpi_table_header *acpi_tb_copy_dsdt(u32 table_index)
+{
+       struct acpi_table_header *new_table;
+       struct acpi_table_desc *table_desc;
+
+       table_desc = &acpi_gbl_root_table_list.tables[table_index];
+
+       new_table = ACPI_ALLOCATE(table_desc->length);
+       if (!new_table) {
+               ACPI_ERROR((AE_INFO, "Could not copy DSDT of length 0x%X",
+                           table_desc->length));
+               return (NULL);
+       }
+
+       ACPI_MEMCPY(new_table, table_desc->pointer, table_desc->length);
+       acpi_tb_delete_table(table_desc);
+       table_desc->pointer = new_table;
+       table_desc->flags = ACPI_TABLE_ORIGIN_ALLOCATED;
+
+       ACPI_INFO((AE_INFO,
+                  "Forced DSDT copy: length 0x%05X copied locally, original unmapped",
+                  new_table->length));
+
+       return (new_table);
+}
+
 /*******************************************************************************
  *
  * FUNCTION:    acpi_tb_install_table
@@ -496,7 +574,7 @@ acpi_tb_get_root_table_entry(u8 *table_entry, u32 table_entry_size)
                        /* Will truncate 64-bit address to 32 bits, issue warning */
 
                        ACPI_WARNING((AE_INFO,
-                                     "64-bit Physical Address in XSDT is too large (%8.8X%8.8X),"
+                                     "64-bit Physical Address in XSDT is too large (0x%8.8X%8.8X),"
                                      " truncating",
                                      ACPI_FORMAT_UINT64(address64)));
                }
@@ -629,14 +707,14 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
         */
        table_entry =
            ACPI_CAST_PTR(u8, table) + sizeof(struct acpi_table_header);
-       acpi_gbl_root_table_list.count = 2;
+       acpi_gbl_root_table_list.current_table_count = 2;
 
        /*
         * Initialize the root table array from the RSDT/XSDT
         */
        for (i = 0; i < table_count; i++) {
-               if (acpi_gbl_root_table_list.count >=
-                   acpi_gbl_root_table_list.size) {
+               if (acpi_gbl_root_table_list.current_table_count >=
+                   acpi_gbl_root_table_list.max_table_count) {
 
                        /* There is no more room in the root table array, attempt resize */
 
@@ -646,19 +724,20 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
                                              "Truncating %u table entries!",
                                              (unsigned) (table_count -
                                               (acpi_gbl_root_table_list.
-                                              count - 2))));
+                                                         current_table_count -
+                                                         2))));
                                break;
                        }
                }
 
                /* Get the table physical address (32-bit for RSDT, 64-bit for XSDT) */
 
-               acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.count].
-                   address =
+               acpi_gbl_root_table_list.tables[acpi_gbl_root_table_list.
+                                               current_table_count].address =
                    acpi_tb_get_root_table_entry(table_entry, table_entry_size);
 
                table_entry += table_entry_size;
-               acpi_gbl_root_table_list.count++;
+               acpi_gbl_root_table_list.current_table_count++;
        }
 
        /*
@@ -671,7 +750,7 @@ acpi_tb_parse_root_table(acpi_physical_address rsdp_address)
         * Complete the initialization of the root table array by examining
         * the header of each table
         */
-       for (i = 2; i < acpi_gbl_root_table_list.count; i++) {
+       for (i = 2; i < acpi_gbl_root_table_list.current_table_count; i++) {
                acpi_tb_install_table(acpi_gbl_root_table_list.tables[i].
                                      address, NULL, i);
 
index 5217a61..4a8b9e6 100644 (file)
@@ -72,7 +72,7 @@ static int no_auto_ssdt;
 acpi_status acpi_allocate_root_table(u32 initial_table_count)
 {
 
-       acpi_gbl_root_table_list.size = initial_table_count;
+       acpi_gbl_root_table_list.max_table_count = initial_table_count;
        acpi_gbl_root_table_list.flags = ACPI_ROOT_ALLOW_RESIZE;
 
        return (acpi_tb_resize_root_table_list());
@@ -130,7 +130,7 @@ acpi_initialize_tables(struct acpi_table_desc * initial_table_array,
                            sizeof(struct acpi_table_desc));
 
                acpi_gbl_root_table_list.tables = initial_table_array;
-               acpi_gbl_root_table_list.size = initial_table_count;
+               acpi_gbl_root_table_list.max_table_count = initial_table_count;
                acpi_gbl_root_table_list.flags = ACPI_ROOT_ORIGIN_UNKNOWN;
                if (allow_resize) {
                        acpi_gbl_root_table_list.flags |=
@@ -172,6 +172,7 @@ acpi_status acpi_reallocate_root_table(void)
 {
        struct acpi_table_desc *tables;
        acpi_size new_size;
+       acpi_size current_size;
 
        ACPI_FUNCTION_TRACE(acpi_reallocate_root_table);
 
@@ -183,10 +184,17 @@ acpi_status acpi_reallocate_root_table(void)
                return_ACPI_STATUS(AE_SUPPORT);
        }
 
-       new_size = ((acpi_size) acpi_gbl_root_table_list.count +
-                   ACPI_ROOT_TABLE_SIZE_INCREMENT) *
+       /*
+        * Get the current size of the root table and add the default
+        * increment to create the new table size.
+        */
+       current_size = (acpi_size)
+           acpi_gbl_root_table_list.current_table_count *
            sizeof(struct acpi_table_desc);
 
+       new_size = current_size +
+           (ACPI_ROOT_TABLE_SIZE_INCREMENT * sizeof(struct acpi_table_desc));
+
        /* Create new array and copy the old array */
 
        tables = ACPI_ALLOCATE_ZEROED(new_size);
@@ -194,10 +202,17 @@ acpi_status acpi_reallocate_root_table(void)
                return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
-       ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, new_size);
+       ACPI_MEMCPY(tables, acpi_gbl_root_table_list.tables, current_size);
 
-       acpi_gbl_root_table_list.size = acpi_gbl_root_table_list.count;
+       /*
+        * Update the root table descriptor. The new size will be the current
+        * number of tables plus the increment, independent of the reserved
+        * size of the original table list.
+        */
        acpi_gbl_root_table_list.tables = tables;
+       acpi_gbl_root_table_list.max_table_count =
+           acpi_gbl_root_table_list.current_table_count +
+           ACPI_ROOT_TABLE_SIZE_INCREMENT;
        acpi_gbl_root_table_list.flags =
            ACPI_ROOT_ORIGIN_ALLOCATED | ACPI_ROOT_ALLOW_RESIZE;
 
@@ -278,7 +293,8 @@ acpi_get_table_header(char *signature,
 
        /* Walk the root table list */
 
-       for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
+       for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
+            i++) {
                if (!ACPI_COMPARE_NAME
                    (&(acpi_gbl_root_table_list.tables[i].signature),
                     signature)) {
@@ -341,7 +357,7 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
        ACPI_FUNCTION_TRACE(acpi_unload_table_id);
 
        /* Find table in the global table list */
-       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+       for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
                if (id != acpi_gbl_root_table_list.tables[i].owner_id) {
                        continue;
                }
@@ -391,7 +407,8 @@ acpi_get_table_with_size(char *signature,
 
        /* Walk the root table list */
 
-       for (i = 0, j = 0; i < acpi_gbl_root_table_list.count; i++) {
+       for (i = 0, j = 0; i < acpi_gbl_root_table_list.current_table_count;
+            i++) {
                if (!ACPI_COMPARE_NAME
                    (&(acpi_gbl_root_table_list.tables[i].signature),
                     signature)) {
@@ -459,7 +476,7 @@ acpi_get_table_by_index(u32 table_index, struct acpi_table_header **table)
 
        /* Validate index */
 
-       if (table_index >= acpi_gbl_root_table_list.count) {
+       if (table_index >= acpi_gbl_root_table_list.current_table_count) {
                (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
                return_ACPI_STATUS(AE_BAD_PARAMETER);
        }
@@ -500,16 +517,17 @@ static acpi_status acpi_tb_load_namespace(void)
 {
        acpi_status status;
        u32 i;
+       struct acpi_table_header *new_dsdt;
 
        ACPI_FUNCTION_TRACE(tb_load_namespace);
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
 
        /*
-        * Load the namespace. The DSDT is required, but any SSDT and PSDT tables
-        * are optional.
+        * Load the namespace. The DSDT is required, but any SSDT and
+        * PSDT tables are optional. Verify the DSDT.
         */
-       if (!acpi_gbl_root_table_list.count ||
+       if (!acpi_gbl_root_table_list.current_table_count ||
            !ACPI_COMPARE_NAME(&
                               (acpi_gbl_root_table_list.
                                tables[ACPI_TABLE_INDEX_DSDT].signature),
@@ -522,17 +540,35 @@ static acpi_status acpi_tb_load_namespace(void)
                goto unlock_and_exit;
        }
 
-       /* A valid DSDT is required */
-
-       status =
-           acpi_tb_verify_table(&acpi_gbl_root_table_list.
-                                tables[ACPI_TABLE_INDEX_DSDT]);
-       if (ACPI_FAILURE(status)) {
+       /*
+        * Save the DSDT pointer for simple access. This is the mapped memory
+        * address. We must take care here because the address of the .Tables
+        * array can change dynamically as tables are loaded at run-time. Note:
+        * .Pointer field is not validated until after call to acpi_tb_verify_table.
+        */
+       acpi_gbl_DSDT =
+           acpi_gbl_root_table_list.tables[ACPI_TABLE_INDEX_DSDT].pointer;
 
-               status = AE_NO_ACPI_TABLES;
-               goto unlock_and_exit;
+       /*
+        * Optionally copy the entire DSDT to local memory (instead of simply
+        * mapping it.) There are some BIOSs that corrupt or replace the original
+        * DSDT, creating the need for this option. Default is FALSE, do not copy
+        * the DSDT.
+        */
+       if (acpi_gbl_copy_dsdt_locally) {
+               new_dsdt = acpi_tb_copy_dsdt(ACPI_TABLE_INDEX_DSDT);
+               if (new_dsdt) {
+                       acpi_gbl_DSDT = new_dsdt;
+               }
        }
 
+       /*
+        * Save the original DSDT header for detection of table corruption
+        * and/or replacement of the DSDT from outside the OS.
+        */
+       ACPI_MEMCPY(&acpi_gbl_original_dsdt_header, acpi_gbl_DSDT,
+                   sizeof(struct acpi_table_header));
+
        (void)acpi_ut_release_mutex(ACPI_MTX_TABLES);
 
        /* Load and parse tables */
@@ -545,7 +581,7 @@ static acpi_status acpi_tb_load_namespace(void)
        /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
 
        (void)acpi_ut_acquire_mutex(ACPI_MTX_TABLES);
-       for (i = 0; i < acpi_gbl_root_table_list.count; ++i) {
+       for (i = 0; i < acpi_gbl_root_table_list.current_table_count; ++i) {
                if ((!ACPI_COMPARE_NAME
                     (&(acpi_gbl_root_table_list.tables[i].signature),
                      ACPI_SIG_SSDT)
index dda6e8c..fd2c07d 100644 (file)
@@ -134,7 +134,7 @@ acpi_status acpi_find_root_pointer(acpi_size *table_address)
                                       ACPI_EBDA_PTR_LENGTH);
        if (!table_ptr) {
                ACPI_ERROR((AE_INFO,
-                           "Could not map memory at %8.8X for length %X",
+                           "Could not map memory at 0x%8.8X for length %u",
                            ACPI_EBDA_PTR_LOCATION, ACPI_EBDA_PTR_LENGTH));
 
                return_ACPI_STATUS(AE_NO_MEMORY);
@@ -159,7 +159,7 @@ acpi_status acpi_find_root_pointer(acpi_size *table_address)
                                               ACPI_EBDA_WINDOW_SIZE);
                if (!table_ptr) {
                        ACPI_ERROR((AE_INFO,
-                                   "Could not map memory at %8.8X for length %X",
+                                   "Could not map memory at 0x%8.8X for length %u",
                                    physical_address, ACPI_EBDA_WINDOW_SIZE));
 
                        return_ACPI_STATUS(AE_NO_MEMORY);
@@ -191,7 +191,7 @@ acpi_status acpi_find_root_pointer(acpi_size *table_address)
 
        if (!table_ptr) {
                ACPI_ERROR((AE_INFO,
-                           "Could not map memory at %8.8X for length %X",
+                           "Could not map memory at 0x%8.8X for length %u",
                            ACPI_HI_RSDP_WINDOW_BASE,
                            ACPI_HI_RSDP_WINDOW_SIZE));
 
index 3d706b8..8f08962 100644 (file)
@@ -340,7 +340,7 @@ void *acpi_ut_allocate(acpi_size size,
                /* Report allocation error */
 
                ACPI_WARNING((module, line,
-                             "Could not allocate size %X", (u32) size));
+                             "Could not allocate size %u", (u32) size));
 
                return_PTR(NULL);
        }
index 97ec362..6fef83f 100644 (file)
@@ -677,16 +677,24 @@ acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
        u16 reference_count;
        union acpi_operand_object *next_object;
        acpi_status status;
+       acpi_size copy_size;
 
        /* Save fields from destination that we don't want to overwrite */
 
        reference_count = dest_desc->common.reference_count;
        next_object = dest_desc->common.next_object;
 
-       /* Copy the entire source object over the destination object */
+       /*
+        * Copy the entire source object over the destination object.
+        * Note: Source can be either an operand object or namespace node.
+        */
+       copy_size = sizeof(union acpi_operand_object);
+       if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_NAMED) {
+               copy_size = sizeof(struct acpi_namespace_node);
+       }
 
-       ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
-                   sizeof(union acpi_operand_object));
+       ACPI_MEMCPY(ACPI_CAST_PTR(char, dest_desc),
+                   ACPI_CAST_PTR(char, source_desc), copy_size);
 
        /* Restore the saved fields */
 
index 16b51c6..ed794cd 100644 (file)
@@ -434,7 +434,7 @@ acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
 
        default:
 
-               ACPI_ERROR((AE_INFO, "Unknown action (%X)", action));
+               ACPI_ERROR((AE_INFO, "Unknown action (0x%X)", action));
                break;
        }
 
@@ -444,8 +444,8 @@ acpi_ut_update_ref_count(union acpi_operand_object *object, u32 action)
         */
        if (count > ACPI_MAX_REFERENCE_COUNT) {
                ACPI_WARNING((AE_INFO,
-                             "Large Reference Count (%X) in object %p", count,
-                             object));
+                             "Large Reference Count (0x%X) in object %p",
+                             count, object));
        }
 }
 
index 7f5e734..6dfdeb6 100644 (file)
@@ -307,7 +307,7 @@ acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
                                  prefix_node, path, AE_TYPE);
 
                ACPI_ERROR((AE_INFO,
-                           "Type returned from %s was incorrect: %s, expected Btypes: %X",
+                           "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
                            path,
                            acpi_ut_get_object_type_name(info->return_object),
                            expected_return_btypes));
index eda3e65..6611675 100644 (file)
@@ -785,6 +785,7 @@ acpi_status acpi_ut_init_globals(void)
 
        /* Miscellaneous variables */
 
+       acpi_gbl_DSDT = NULL;
        acpi_gbl_cm_single_step = FALSE;
        acpi_gbl_db_terminate_threads = FALSE;
        acpi_gbl_shutdown = FALSE;
index 32982e2..e8d0724 100644 (file)
@@ -205,7 +205,7 @@ acpi_status acpi_ut_allocate_owner_id(acpi_owner_id * owner_id)
        /* Guard against multiple allocations of ID to the same location */
 
        if (*owner_id) {
-               ACPI_ERROR((AE_INFO, "Owner ID [%2.2X] already exists",
+               ACPI_ERROR((AE_INFO, "Owner ID [0x%2.2X] already exists",
                            *owner_id));
                return_ACPI_STATUS(AE_ALREADY_EXISTS);
        }
@@ -315,7 +315,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
        /* Zero is not a valid owner_iD */
 
        if (owner_id == 0) {
-               ACPI_ERROR((AE_INFO, "Invalid OwnerId: %2.2X", owner_id));
+               ACPI_ERROR((AE_INFO, "Invalid OwnerId: 0x%2.2X", owner_id));
                return_VOID;
        }
 
@@ -341,7 +341,7 @@ void acpi_ut_release_owner_id(acpi_owner_id * owner_id_ptr)
                acpi_gbl_owner_id_mask[index] ^= bit;
        } else {
                ACPI_ERROR((AE_INFO,
-                           "Release of non-allocated OwnerId: %2.2X",
+                           "Release of non-allocated OwnerId: 0x%2.2X",
                            owner_id + 1));
        }
 
index 55d014e..058b3df 100644 (file)
@@ -258,7 +258,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
                acpi_gbl_mutex_info[mutex_id].thread_id = this_thread_id;
        } else {
                ACPI_EXCEPTION((AE_INFO, status,
-                               "Thread %p could not acquire Mutex [%X]",
+                               "Thread %p could not acquire Mutex [0x%X]",
                                ACPI_CAST_PTR(void, this_thread_id), mutex_id));
        }
 
@@ -297,7 +297,7 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
         */
        if (acpi_gbl_mutex_info[mutex_id].thread_id == ACPI_MUTEX_NOT_ACQUIRED) {
                ACPI_ERROR((AE_INFO,
-                           "Mutex [%X] is not acquired, cannot release",
+                           "Mutex [0x%X] is not acquired, cannot release",
                            mutex_id));
 
                return (AE_NOT_ACQUIRED);
index 3356f0c..fd1fa27 100644 (file)
@@ -251,7 +251,7 @@ union acpi_operand_object *acpi_ut_create_buffer_object(acpi_size buffer_size)
 
                buffer = ACPI_ALLOCATE_ZEROED(buffer_size);
                if (!buffer) {
-                       ACPI_ERROR((AE_INFO, "Could not allocate size %X",
+                       ACPI_ERROR((AE_INFO, "Could not allocate size %u",
                                    (u32) buffer_size));
                        acpi_ut_remove_reference(buffer_desc);
                        return_PTR(NULL);
@@ -303,7 +303,7 @@ union acpi_operand_object *acpi_ut_create_string_object(acpi_size string_size)
         */
        string = ACPI_ALLOCATE_ZEROED(string_size + 1);
        if (!string) {
-               ACPI_ERROR((AE_INFO, "Could not allocate size %X",
+               ACPI_ERROR((AE_INFO, "Could not allocate size %u",
                            (u32) string_size));
                acpi_ut_remove_reference(string_desc);
                return_PTR(NULL);
@@ -533,7 +533,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
                         */
                        ACPI_ERROR((AE_INFO,
                                    "Cannot convert to external object - "
-                                   "unsupported Reference Class [%s] %X in object %p",
+                                   "unsupported Reference Class [%s] 0x%X in object %p",
                                    acpi_ut_get_reference_name(internal_object),
                                    internal_object->reference.class,
                                    internal_object));
@@ -545,7 +545,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
        default:
 
                ACPI_ERROR((AE_INFO, "Cannot convert to external object - "
-                           "unsupported type [%s] %X in object %p",
+                           "unsupported type [%s] 0x%X in object %p",
                            acpi_ut_get_object_type_name(internal_object),
                            internal_object->common.type, internal_object));
                status = AE_TYPE;
index 743576b..9042a85 100644 (file)
@@ -69,6 +69,44 @@ static struct dmi_system_id __cpuinitdata power_nocheck_dmi_table[] = {
 };
 
 
+#ifdef CONFIG_X86
+static int set_copy_dsdt(const struct dmi_system_id *id)
+{
+       printk(KERN_NOTICE "%s detected - "
+               "force copy of DSDT to local memory\n", id->ident);
+       acpi_gbl_copy_dsdt_locally = 1;
+       return 0;
+}
+
+static struct dmi_system_id dsdt_dmi_table[] __initdata = {
+       /*
+        * Insyde BIOS on some TOSHIBA machines corrupt the DSDT.
+        * https://bugzilla.kernel.org/show_bug.cgi?id=14679
+        */
+       {
+        .callback = set_copy_dsdt,
+        .ident = "TOSHIBA Satellite A505",
+        .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Satellite A505"),
+               },
+       },
+       {
+        .callback = set_copy_dsdt,
+        .ident = "TOSHIBA Satellite L505D",
+        .matches = {
+               DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
+               DMI_MATCH(DMI_PRODUCT_NAME, "Satellite L505D"),
+               },
+       },
+       {}
+};
+#else
+static struct dmi_system_id dsdt_dmi_table[] __initdata = {
+       {}
+};
+#endif
+
 /* --------------------------------------------------------------------------
                                 Device Management
    -------------------------------------------------------------------------- */
@@ -813,6 +851,12 @@ void __init acpi_early_init(void)
 
        acpi_gbl_permanent_mmap = 1;
 
+       /*
+        * If the machine falls into the DMI check table,
+        * DSDT will be copied to memory
+        */
+       dmi_check_system(dsdt_dmi_table);
+
        status = acpi_reallocate_root_table();
        if (ACPI_FAILURE(status)) {
                printk(KERN_ERR PREFIX
index 7594f65..4bc1c41 100644 (file)
@@ -1406,7 +1406,7 @@ acpi_os_invalidate_address(
        switch (space_id) {
        case ACPI_ADR_SPACE_SYSTEM_IO:
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
-               /* Only interference checks against SystemIO and SytemMemory
+               /* Only interference checks against SystemIO and SystemMemory
                   are needed */
                res.start = address;
                res.end = address + length - 1;
@@ -1458,7 +1458,7 @@ acpi_os_validate_address (
        switch (space_id) {
        case ACPI_ADR_SPACE_SYSTEM_IO:
        case ACPI_ADR_SPACE_SYSTEM_MEMORY:
-               /* Only interference checks against SystemIO and SytemMemory
+               /* Only interference checks against SystemIO and SystemMemory
                   are needed */
                res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
                if (!res)
index b0a71ec..e4804fb 100644 (file)
@@ -401,11 +401,13 @@ int acpi_pci_irq_enable(struct pci_dev *dev)
         * driver reported one, then use it. Exit in any case.
         */
        if (gsi < 0) {
+               u32 dev_gsi;
                dev_warn(&dev->dev, "PCI INT %c: no GSI", pin_name(pin));
                /* Interrupt Line values above 0xF are forbidden */
-               if (dev->irq > 0 && (dev->irq <= 0xF)) {
-                       printk(" - using IRQ %d\n", dev->irq);
-                       acpi_register_gsi(&dev->dev, dev->irq,
+               if (dev->irq > 0 && (dev->irq <= 0xF) &&
+                   (acpi_isa_irq_to_gsi(dev->irq, &dev_gsi) == 0)) {
+                       printk(" - using ISA IRQ %d\n", dev->irq);
+                       acpi_register_gsi(&dev->dev, dev_gsi,
                                          ACPI_LEVEL_SENSITIVE,
                                          ACPI_ACTIVE_LOW);
                        return 0;
index ddc7678..f74d3b3 100644 (file)
@@ -172,7 +172,6 @@ static int acpi_power_get_list_state(struct acpi_handle_list *list, int *state)
                return -EINVAL;
 
        /* The state of the list is 'on' IFF all resources are 'on'. */
-       /* */
 
        for (i = 0; i < list->count; i++) {
                /*
index 5939e7f..c3817e1 100644 (file)
@@ -698,7 +698,7 @@ static int acpi_processor_power_seq_show(struct seq_file *seq, void *offset)
                   "max_cstate:              C%d\n"
                   "maximum allowed latency: %d usec\n",
                   pr->power.state ? pr->power.state - pr->power.states : 0,
-                  max_cstate, pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY));
+                  max_cstate, pm_qos_request(PM_QOS_CPU_DMA_LATENCY));
 
        seq_puts(seq, "states:\n");
 
index 0338f51..7f2e051 100644 (file)
@@ -765,7 +765,7 @@ static void acpi_bus_set_run_wake_flags(struct acpi_device *device)
        }
 
        status = acpi_get_gpe_status(NULL, device->wakeup.gpe_number,
-                                       ACPI_NOT_ISR, &event_status);
+                                       &event_status);
        if (status == AE_OK)
                device->wakeup.flags.run_wake =
                                !!(event_status & ACPI_EVENT_FLAG_HANDLE);
index 4aaf249..e35525b 100644 (file)
@@ -303,8 +303,7 @@ static int get_status(u32 index, acpi_event_status *status, acpi_handle *handle)
                                "Invalid GPE 0x%x\n", index));
                        goto end;
                }
-               result = acpi_get_gpe_status(*handle, index,
-                                               ACPI_NOT_ISR, status);
+               result = acpi_get_gpe_status(*handle, index, status);
        } else if (index < (num_gpes + ACPI_NUM_FIXED_EVENTS))
                result = acpi_get_event_status(index - num_gpes, status);
 
@@ -395,7 +394,7 @@ static ssize_t counter_set(struct kobject *kobj,
                        result = acpi_set_gpe(handle, index, ACPI_GPE_ENABLE);
                else if (!strcmp(buf, "clear\n") &&
                                (status & ACPI_EVENT_FLAG_SET))
-                       result = acpi_clear_gpe(handle, index, ACPI_NOT_ISR);
+                       result = acpi_clear_gpe(handle, index);
                else
                        all_counters[index].count = strtoul(buf, NULL, 0);
        } else if (index < num_gpes + ACPI_NUM_FIXED_EVENTS) {
index 01c52c4..e68541f 100644 (file)
@@ -65,6 +65,14 @@ config SATA_AHCI
 
          If unsure, say N.
 
+config SATA_AHCI_PLATFORM
+       tristate "Platform AHCI SATA support"
+       help
+         This option enables support for Platform AHCI Serial ATA
+         controllers.
+
+         If unsure, say N.
+
 config SATA_SIL24
        tristate "Silicon Image 3124/3132 SATA support"
        depends on PCI
@@ -73,6 +81,12 @@ config SATA_SIL24
 
          If unsure, say N.
 
+config SATA_INIC162X
+       tristate "Initio 162x SATA support"
+       depends on PCI
+       help
+         This option enables support for Initio 162x Serial ATA.
+
 config SATA_FSL
        tristate "Freescale 3.0Gbps SATA support"
        depends on FSL_SOC
@@ -213,12 +227,6 @@ config SATA_VITESSE
 
          If unsure, say N.
 
-config SATA_INIC162X
-       tristate "Initio 162x SATA support"
-       depends on PCI
-       help
-         This option enables support for Initio 162x Serial ATA.
-
 config PATA_ACPI
        tristate "ACPI firmware driver for PATA"
        depends on ATA_ACPI
index fc936d4..d0a93c4 100644 (file)
@@ -1,7 +1,8 @@
 
 obj-$(CONFIG_ATA)              += libata.o
 
-obj-$(CONFIG_SATA_AHCI)                += ahci.o
+obj-$(CONFIG_SATA_AHCI)                += ahci.o libahci.o
+obj-$(CONFIG_SATA_AHCI_PLATFORM) += ahci_platform.o libahci.o
 obj-$(CONFIG_SATA_SVW)         += sata_svw.o
 obj-$(CONFIG_ATA_PIIX)         += ata_piix.o
 obj-$(CONFIG_SATA_PROMISE)     += sata_promise.o
index 5326af2..8ca16f5 100644 (file)
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_cmnd.h>
 #include <linux/libata.h>
+#include "ahci.h"
 
 #define DRV_NAME       "ahci"
 #define DRV_VERSION    "3.0"
 
-/* Enclosure Management Control */
-#define EM_CTRL_MSG_TYPE              0x000f0000
-
-/* Enclosure Management LED Message Type */
-#define EM_MSG_LED_HBA_PORT           0x0000000f
-#define EM_MSG_LED_PMP_SLOT           0x0000ff00
-#define EM_MSG_LED_VALUE              0xffff0000
-#define EM_MSG_LED_VALUE_ACTIVITY     0x00070000
-#define EM_MSG_LED_VALUE_OFF          0xfff80000
-#define EM_MSG_LED_VALUE_ON           0x00010000
-
-static int ahci_skip_host_reset;
-static int ahci_ignore_sss;
-
-module_param_named(skip_host_reset, ahci_skip_host_reset, int, 0444);
-MODULE_PARM_DESC(skip_host_reset, "skip global host reset (0=don't skip, 1=skip)");
-
-module_param_named(ignore_sss, ahci_ignore_sss, int, 0444);
-MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)");
-
-static int ahci_enable_alpm(struct ata_port *ap,
-               enum link_pm policy);
-static void ahci_disable_alpm(struct ata_port *ap);
-static ssize_t ahci_led_show(struct ata_port *ap, char *buf);
-static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
-                             size_t size);
-static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
-                                       ssize_t size);
-
 enum {
        AHCI_PCI_BAR            = 5,
-       AHCI_MAX_PORTS          = 32,
-       AHCI_MAX_SG             = 168, /* hardware max is 64K */
-       AHCI_DMA_BOUNDARY       = 0xffffffff,
-       AHCI_MAX_CMDS           = 32,
-       AHCI_CMD_SZ             = 32,
-       AHCI_CMD_SLOT_SZ        = AHCI_MAX_CMDS * AHCI_CMD_SZ,
-       AHCI_RX_FIS_SZ          = 256,
-       AHCI_CMD_TBL_CDB        = 0x40,
-       AHCI_CMD_TBL_HDR_SZ     = 0x80,
-       AHCI_CMD_TBL_SZ         = AHCI_CMD_TBL_HDR_SZ + (AHCI_MAX_SG * 16),
-       AHCI_CMD_TBL_AR_SZ      = AHCI_CMD_TBL_SZ * AHCI_MAX_CMDS,
-       AHCI_PORT_PRIV_DMA_SZ   = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ +
-                                 AHCI_RX_FIS_SZ,
-       AHCI_PORT_PRIV_FBS_DMA_SZ       = AHCI_CMD_SLOT_SZ +
-                                         AHCI_CMD_TBL_AR_SZ +
-                                         (AHCI_RX_FIS_SZ * 16),
-       AHCI_IRQ_ON_SG          = (1 << 31),
-       AHCI_CMD_ATAPI          = (1 << 5),
-       AHCI_CMD_WRITE          = (1 << 6),
-       AHCI_CMD_PREFETCH       = (1 << 7),
-       AHCI_CMD_RESET          = (1 << 8),
-       AHCI_CMD_CLR_BUSY       = (1 << 10),
-
-       RX_FIS_D2H_REG          = 0x40, /* offset of D2H Register FIS data */
-       RX_FIS_SDB              = 0x58, /* offset of SDB FIS data */
-       RX_FIS_UNK              = 0x60, /* offset of Unknown FIS data */
-
-       board_ahci              = 0,
-       board_ahci_vt8251       = 1,
-       board_ahci_ign_iferr    = 2,
-       board_ahci_sb600        = 3,
-       board_ahci_mv           = 4,
-       board_ahci_sb700        = 5, /* for SB700 and SB800 */
-       board_ahci_mcp65        = 6,
-       board_ahci_nopmp        = 7,
-       board_ahci_yesncq       = 8,
-       board_ahci_nosntf       = 9,
-
-       /* global controller registers */
-       HOST_CAP                = 0x00, /* host capabilities */
-       HOST_CTL                = 0x04, /* global host control */
-       HOST_IRQ_STAT           = 0x08, /* interrupt status */
-       HOST_PORTS_IMPL         = 0x0c, /* bitmap of implemented ports */
-       HOST_VERSION            = 0x10, /* AHCI spec. version compliancy */
-       HOST_EM_LOC             = 0x1c, /* Enclosure Management location */
-       HOST_EM_CTL             = 0x20, /* Enclosure Management Control */
-       HOST_CAP2               = 0x24, /* host capabilities, extended */
-
-       /* HOST_CTL bits */
-       HOST_RESET              = (1 << 0),  /* reset controller; self-clear */
-       HOST_IRQ_EN             = (1 << 1),  /* global IRQ enable */
-       HOST_AHCI_EN            = (1 << 31), /* AHCI enabled */
-
-       /* HOST_CAP bits */
-       HOST_CAP_SXS            = (1 << 5),  /* Supports External SATA */
-       HOST_CAP_EMS            = (1 << 6),  /* Enclosure Management support */
-       HOST_CAP_CCC            = (1 << 7),  /* Command Completion Coalescing */
-       HOST_CAP_PART           = (1 << 13), /* Partial state capable */
-       HOST_CAP_SSC            = (1 << 14), /* Slumber state capable */
-       HOST_CAP_PIO_MULTI      = (1 << 15), /* PIO multiple DRQ support */
-       HOST_CAP_FBS            = (1 << 16), /* FIS-based switching support */
-       HOST_CAP_PMP            = (1 << 17), /* Port Multiplier support */
-       HOST_CAP_ONLY           = (1 << 18), /* Supports AHCI mode only */
-       HOST_CAP_CLO            = (1 << 24), /* Command List Override support */
-       HOST_CAP_LED            = (1 << 25), /* Supports activity LED */
-       HOST_CAP_ALPM           = (1 << 26), /* Aggressive Link PM support */
-       HOST_CAP_SSS            = (1 << 27), /* Staggered Spin-up */
-       HOST_CAP_MPS            = (1 << 28), /* Mechanical presence switch */
-       HOST_CAP_SNTF           = (1 << 29), /* SNotification register */
-       HOST_CAP_NCQ            = (1 << 30), /* Native Command Queueing */
-       HOST_CAP_64             = (1 << 31), /* PCI DAC (64-bit DMA) support */
-
-       /* HOST_CAP2 bits */
-       HOST_CAP2_BOH           = (1 << 0),  /* BIOS/OS handoff supported */
-       HOST_CAP2_NVMHCI        = (1 << 1),  /* NVMHCI supported */
-       HOST_CAP2_APST          = (1 << 2),  /* Automatic partial to slumber */
-
-       /* registers for each SATA port */
-       PORT_LST_ADDR           = 0x00, /* command list DMA addr */
-       PORT_LST_ADDR_HI        = 0x04, /* command list DMA addr hi */
-       PORT_FIS_ADDR           = 0x08, /* FIS rx buf addr */
-       PORT_FIS_ADDR_HI        = 0x0c, /* FIS rx buf addr hi */
-       PORT_IRQ_STAT           = 0x10, /* interrupt status */
-       PORT_IRQ_MASK           = 0x14, /* interrupt enable/disable mask */
-       PORT_CMD                = 0x18, /* port command */
-       PORT_TFDATA             = 0x20, /* taskfile data */
-       PORT_SIG                = 0x24, /* device TF signature */
-       PORT_CMD_ISSUE          = 0x38, /* command issue */
-       PORT_SCR_STAT           = 0x28, /* SATA phy register: SStatus */
-       PORT_SCR_CTL            = 0x2c, /* SATA phy register: SControl */
-       PORT_SCR_ERR            = 0x30, /* SATA phy register: SError */
-       PORT_SCR_ACT            = 0x34, /* SATA phy register: SActive */
-       PORT_SCR_NTF            = 0x3c, /* SATA phy register: SNotification */
-       PORT_FBS                = 0x40, /* FIS-based Switching */
-
-       /* PORT_IRQ_{STAT,MASK} bits */
-       PORT_IRQ_COLD_PRES      = (1 << 31), /* cold presence detect */
-       PORT_IRQ_TF_ERR         = (1 << 30), /* task file error */
-       PORT_IRQ_HBUS_ERR       = (1 << 29), /* host bus fatal error */
-       PORT_IRQ_HBUS_DATA_ERR  = (1 << 28), /* host bus data error */
-       PORT_IRQ_IF_ERR         = (1 << 27), /* interface fatal error */
-       PORT_IRQ_IF_NONFATAL    = (1 << 26), /* interface non-fatal error */
-       PORT_IRQ_OVERFLOW       = (1 << 24), /* xfer exhausted available S/G */
-       PORT_IRQ_BAD_PMP        = (1 << 23), /* incorrect port multiplier */
-
-       PORT_IRQ_PHYRDY         = (1 << 22), /* PhyRdy changed */
-       PORT_IRQ_DEV_ILCK       = (1 << 7), /* device interlock */
-       PORT_IRQ_CONNECT        = (1 << 6), /* port connect change status */
-       PORT_IRQ_SG_DONE        = (1 << 5), /* descriptor processed */
-       PORT_IRQ_UNK_FIS        = (1 << 4), /* unknown FIS rx'd */
-       PORT_IRQ_SDB_FIS        = (1 << 3), /* Set Device Bits FIS rx'd */
-       PORT_IRQ_DMAS_FIS       = (1 << 2), /* DMA Setup FIS rx'd */
-       PORT_IRQ_PIOS_FIS       = (1 << 1), /* PIO Setup FIS rx'd */
-       PORT_IRQ_D2H_REG_FIS    = (1 << 0), /* D2H Register FIS rx'd */
-
-       PORT_IRQ_FREEZE         = PORT_IRQ_HBUS_ERR |
-                                 PORT_IRQ_IF_ERR |
-                                 PORT_IRQ_CONNECT |
-                                 PORT_IRQ_PHYRDY |
-                                 PORT_IRQ_UNK_FIS |
-                                 PORT_IRQ_BAD_PMP,
-       PORT_IRQ_ERROR          = PORT_IRQ_FREEZE |
-                                 PORT_IRQ_TF_ERR |
-                                 PORT_IRQ_HBUS_DATA_ERR,
-       DEF_PORT_IRQ            = PORT_IRQ_ERROR | PORT_IRQ_SG_DONE |
-                                 PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS |
-                                 PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS,
-
-       /* PORT_CMD bits */
-       PORT_CMD_ASP            = (1 << 27), /* Aggressive Slumber/Partial */
-       PORT_CMD_ALPE           = (1 << 26), /* Aggressive Link PM enable */
-       PORT_CMD_ATAPI          = (1 << 24), /* Device is ATAPI */
-       PORT_CMD_FBSCP          = (1 << 22), /* FBS Capable Port */
-       PORT_CMD_PMP            = (1 << 17), /* PMP attached */
-       PORT_CMD_LIST_ON        = (1 << 15), /* cmd list DMA engine running */
-       PORT_CMD_FIS_ON         = (1 << 14), /* FIS DMA engine running */
-       PORT_CMD_FIS_RX         = (1 << 4), /* Enable FIS receive DMA engine */
-       PORT_CMD_CLO            = (1 << 3), /* Command list override */
-       PORT_CMD_POWER_ON       = (1 << 2), /* Power up device */
-       PORT_CMD_SPIN_UP        = (1 << 1), /* Spin up device */
-       PORT_CMD_START          = (1 << 0), /* Enable port DMA engine */
-
-       PORT_CMD_ICC_MASK       = (0xf << 28), /* i/f ICC state mask */
-       PORT_CMD_ICC_ACTIVE     = (0x1 << 28), /* Put i/f in active state */
-       PORT_CMD_ICC_PARTIAL    = (0x2 << 28), /* Put i/f in partial state */
-       PORT_CMD_ICC_SLUMBER    = (0x6 << 28), /* Put i/f in slumber state */
-
-       PORT_FBS_DWE_OFFSET     = 16, /* FBS device with error offset */
-       PORT_FBS_ADO_OFFSET     = 12, /* FBS active dev optimization offset */
-       PORT_FBS_DEV_OFFSET     = 8,  /* FBS device to issue offset */
-       PORT_FBS_DEV_MASK       = (0xf << PORT_FBS_DEV_OFFSET),  /* FBS.DEV */
-       PORT_FBS_SDE            = (1 << 2), /* FBS single device error */
-       PORT_FBS_DEC            = (1 << 1), /* FBS device error clear */
-       PORT_FBS_EN             = (1 << 0), /* Enable FBS */
-
-       /* hpriv->flags bits */
-       AHCI_HFLAG_NO_NCQ               = (1 << 0),
-       AHCI_HFLAG_IGN_IRQ_IF_ERR       = (1 << 1), /* ignore IRQ_IF_ERR */
-       AHCI_HFLAG_IGN_SERR_INTERNAL    = (1 << 2), /* ignore SERR_INTERNAL */
-       AHCI_HFLAG_32BIT_ONLY           = (1 << 3), /* force 32bit */
-       AHCI_HFLAG_MV_PATA              = (1 << 4), /* PATA port */
-       AHCI_HFLAG_NO_MSI               = (1 << 5), /* no PCI MSI */
-       AHCI_HFLAG_NO_PMP               = (1 << 6), /* no PMP */
-       AHCI_HFLAG_NO_HOTPLUG           = (1 << 7), /* ignore PxSERR.DIAG.N */
-       AHCI_HFLAG_SECT255              = (1 << 8), /* max 255 sectors */
-       AHCI_HFLAG_YES_NCQ              = (1 << 9), /* force NCQ cap on */
-       AHCI_HFLAG_NO_SUSPEND           = (1 << 10), /* don't suspend */
-       AHCI_HFLAG_SRST_TOUT_IS_OFFLINE = (1 << 11), /* treat SRST timeout as
-                                                       link offline */
-       AHCI_HFLAG_NO_SNTF              = (1 << 12), /* no sntf */
-
-       /* ap->flags bits */
-
-       AHCI_FLAG_COMMON                = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
-                                         ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
-                                         ATA_FLAG_ACPI_SATA | ATA_FLAG_AN |
-                                         ATA_FLAG_IPM,
-
-       ICH_MAP                         = 0x90, /* ICH MAP register */
-
-       /* em constants */
-       EM_MAX_SLOTS                    = 8,
-       EM_MAX_RETRY                    = 5,
-
-       /* em_ctl bits */
-       EM_CTL_RST                      = (1 << 9), /* Reset */
-       EM_CTL_TM                       = (1 << 8), /* Transmit Message */
-       EM_CTL_ALHD                     = (1 << 26), /* Activity LED */
-};
-
-struct ahci_cmd_hdr {
-       __le32                  opts;
-       __le32                  status;
-       __le32                  tbl_addr;
-       __le32                  tbl_addr_hi;
-       __le32                  reserved[4];
 };
 
-struct ahci_sg {
-       __le32                  addr;
-       __le32                  addr_hi;
-       __le32                  reserved;
-       __le32                  flags_size;
+enum board_ids {
+       /* board IDs by feature in alphabetical order */
+       board_ahci,
+       board_ahci_ign_iferr,
+       board_ahci_nosntf,
+
+       /* board IDs for specific chipsets in alphabetical order */
+       board_ahci_mcp65,
+       board_ahci_mcp77,
+       board_ahci_mcp89,
+       board_ahci_mv,
+       board_ahci_sb600,
+       board_ahci_sb700,       /* for SB700 and SB800 */
+       board_ahci_vt8251,
+
+       /* aliases */
+       board_ahci_mcp_linux    = board_ahci_mcp65,
+       board_ahci_mcp67        = board_ahci_mcp65,
+       board_ahci_mcp73        = board_ahci_mcp65,
+       board_ahci_mcp79        = board_ahci_mcp77,
 };
 
-struct ahci_em_priv {
-       enum sw_activity blink_policy;
-       struct timer_list timer;
-       unsigned long saved_activity;
-       unsigned long activity;
-       unsigned long led_state;
-};
-
-struct ahci_host_priv {
-       unsigned int            flags;          /* AHCI_HFLAG_* */
-       u32                     cap;            /* cap to use */
-       u32                     cap2;           /* cap2 to use */
-       u32                     port_map;       /* port map to use */
-       u32                     saved_cap;      /* saved initial cap */
-       u32                     saved_cap2;     /* saved initial cap2 */
-       u32                     saved_port_map; /* saved initial port_map */
-       u32                     em_loc; /* enclosure management location */
-};
-
-struct ahci_port_priv {
-       struct ata_link         *active_link;
-       struct ahci_cmd_hdr     *cmd_slot;
-       dma_addr_t              cmd_slot_dma;
-       void                    *cmd_tbl;
-       dma_addr_t              cmd_tbl_dma;
-       void                    *rx_fis;
-       dma_addr_t              rx_fis_dma;
-       /* for NCQ spurious interrupt analysis */
-       unsigned int            ncq_saw_d2h:1;
-       unsigned int            ncq_saw_dmas:1;
-       unsigned int            ncq_saw_sdb:1;
-       u32                     intr_mask;      /* interrupts to enable */
-       bool                    fbs_supported;  /* set iff FBS is supported */
-       bool                    fbs_enabled;    /* set iff FBS is enabled */
-       int                     fbs_last_dev;   /* save FBS.DEV of last FIS */
-       /* enclosure management info per PM slot */
-       struct ahci_em_priv     em_priv[EM_MAX_SLOTS];
-};
-
-static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
-static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
 static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
-static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
-static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc);
-static int ahci_port_start(struct ata_port *ap);
-static void ahci_port_stop(struct ata_port *ap);
-static int ahci_pmp_qc_defer(struct ata_queued_cmd *qc);
-static void ahci_qc_prep(struct ata_queued_cmd *qc);
-static void ahci_freeze(struct ata_port *ap);
-static void ahci_thaw(struct ata_port *ap);
-static void ahci_enable_fbs(struct ata_port *ap);
-static void ahci_disable_fbs(struct ata_port *ap);
-static void ahci_pmp_attach(struct ata_port *ap);
-static void ahci_pmp_detach(struct ata_port *ap);
-static int ahci_softreset(struct ata_link *link, unsigned int *class,
-                         unsigned long deadline);
 static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
                          unsigned long deadline);
-static int ahci_hardreset(struct ata_link *link, unsigned int *class,
-                         unsigned long deadline);
 static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
                                 unsigned long deadline);
 static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
                                unsigned long deadline);
-static void ahci_postreset(struct ata_link *link, unsigned int *class);
-static void ahci_error_handler(struct ata_port *ap);
-static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
-static int ahci_port_resume(struct ata_port *ap);
-static void ahci_dev_config(struct ata_device *dev);
-static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
-                              u32 opts);
 #ifdef CONFIG_PM
-static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
 static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
 static int ahci_pci_device_resume(struct pci_dev *pdev);
 #endif
-static ssize_t ahci_activity_show(struct ata_device *dev, char *buf);
-static ssize_t ahci_activity_store(struct ata_device *dev,
-                                  enum sw_activity val);
-static void ahci_init_sw_activity(struct ata_link *link);
-
-static ssize_t ahci_show_host_caps(struct device *dev,
-                                  struct device_attribute *attr, char *buf);
-static ssize_t ahci_show_host_cap2(struct device *dev,
-                                  struct device_attribute *attr, char *buf);
-static ssize_t ahci_show_host_version(struct device *dev,
-                                     struct device_attribute *attr, char *buf);
-static ssize_t ahci_show_port_cmd(struct device *dev,
-                                 struct device_attribute *attr, char *buf);
-
-static DEVICE_ATTR(ahci_host_caps, S_IRUGO, ahci_show_host_caps, NULL);
-static DEVICE_ATTR(ahci_host_cap2, S_IRUGO, ahci_show_host_cap2, NULL);
-static DEVICE_ATTR(ahci_host_version, S_IRUGO, ahci_show_host_version, NULL);
-static DEVICE_ATTR(ahci_port_cmd, S_IRUGO, ahci_show_port_cmd, NULL);
-
-static struct device_attribute *ahci_shost_attrs[] = {
-       &dev_attr_link_power_management_policy,
-       &dev_attr_em_message_type,
-       &dev_attr_em_message,
-       &dev_attr_ahci_host_caps,
-       &dev_attr_ahci_host_cap2,
-       &dev_attr_ahci_host_version,
-       &dev_attr_ahci_port_cmd,
-       NULL
-};
-
-static struct device_attribute *ahci_sdev_attrs[] = {
-       &dev_attr_sw_activity,
-       &dev_attr_unload_heads,
-       NULL
-};
-
-static struct scsi_host_template ahci_sht = {
-       ATA_NCQ_SHT(DRV_NAME),
-       .can_queue              = AHCI_MAX_CMDS - 1,
-       .sg_tablesize           = AHCI_MAX_SG,
-       .dma_boundary           = AHCI_DMA_BOUNDARY,
-       .shost_attrs            = ahci_shost_attrs,
-       .sdev_attrs             = ahci_sdev_attrs,
-};
-
-static struct ata_port_operations ahci_ops = {
-       .inherits               = &sata_pmp_port_ops,
-
-       .qc_defer               = ahci_pmp_qc_defer,
-       .qc_prep                = ahci_qc_prep,
-       .qc_issue               = ahci_qc_issue,
-       .qc_fill_rtf            = ahci_qc_fill_rtf,
-
-       .freeze                 = ahci_freeze,
-       .thaw                   = ahci_thaw,
-       .softreset              = ahci_softreset,
-       .hardreset              = ahci_hardreset,
-       .postreset              = ahci_postreset,
-       .pmp_softreset          = ahci_softreset,
-       .error_handler          = ahci_error_handler,
-       .post_internal_cmd      = ahci_post_internal_cmd,
-       .dev_config             = ahci_dev_config,
-
-       .scr_read               = ahci_scr_read,
-       .scr_write              = ahci_scr_write,
-       .pmp_attach             = ahci_pmp_attach,
-       .pmp_detach             = ahci_pmp_detach,
-
-       .enable_pm              = ahci_enable_alpm,
-       .disable_pm             = ahci_disable_alpm,
-       .em_show                = ahci_led_show,
-       .em_store               = ahci_led_store,
-       .sw_activity_show       = ahci_activity_show,
-       .sw_activity_store      = ahci_activity_store,
-#ifdef CONFIG_PM
-       .port_suspend           = ahci_port_suspend,
-       .port_resume            = ahci_port_resume,
-#endif
-       .port_start             = ahci_port_start,
-       .port_stop              = ahci_port_stop,
-};
 
 static struct ata_port_operations ahci_vt8251_ops = {
        .inherits               = &ahci_ops,
@@ -463,6 +108,7 @@ static struct ata_port_operations ahci_sb600_ops = {
 #define AHCI_HFLAGS(flags)     .private_data   = (void *)(flags)
 
 static const struct ata_port_info ahci_port_info[] = {
+       /* by features */
        [board_ahci] =
        {
                .flags          = AHCI_FLAG_COMMON,
@@ -470,81 +116,83 @@ static const struct ata_port_info ahci_port_info[] = {
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &ahci_ops,
        },
-       [board_ahci_vt8251] =
+       [board_ahci_ign_iferr] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP),
+               AHCI_HFLAGS     (AHCI_HFLAG_IGN_IRQ_IF_ERR),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_vt8251_ops,
+               .port_ops       = &ahci_ops,
        },
-       [board_ahci_ign_iferr] =
+       [board_ahci_nosntf] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_IGN_IRQ_IF_ERR),
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_SNTF),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &ahci_ops,
        },
-       [board_ahci_sb600] =
+       /* by chipsets */
+       [board_ahci_mcp65] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_IGN_SERR_INTERNAL |
-                                AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255 |
-                                AHCI_HFLAG_32BIT_ONLY),
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP |
+                                AHCI_HFLAG_YES_NCQ),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_sb600_ops,
+               .port_ops       = &ahci_ops,
        },
-       [board_ahci_mv] =
+       [board_ahci_mcp77] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
-                                AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
-               .flags          = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
-                                 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_FPDMA_AA | AHCI_HFLAG_NO_PMP),
+               .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &ahci_ops,
        },
-       [board_ahci_sb700] =    /* for SB700 and SB800 */
+       [board_ahci_mcp89] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_IGN_SERR_INTERNAL),
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_FPDMA_AA),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_sb600_ops,
+               .port_ops       = &ahci_ops,
        },
-       [board_ahci_mcp65] =
+       [board_ahci_mv] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_YES_NCQ),
-               .flags          = AHCI_FLAG_COMMON,
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
+                                AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
+               .flags          = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
+                                 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
                .port_ops       = &ahci_ops,
        },
-       [board_ahci_nopmp] =
+       [board_ahci_sb600] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_NO_PMP),
+               AHCI_HFLAGS     (AHCI_HFLAG_IGN_SERR_INTERNAL |
+                                AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255 |
+                                AHCI_HFLAG_32BIT_ONLY),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_ops,
+               .port_ops       = &ahci_sb600_ops,
        },
-       [board_ahci_yesncq] =
+       [board_ahci_sb700] =    /* for SB700 and SB800 */
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_YES_NCQ),
+               AHCI_HFLAGS     (AHCI_HFLAG_IGN_SERR_INTERNAL),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_ops,
+               .port_ops       = &ahci_sb600_ops,
        },
-       [board_ahci_nosntf] =
+       [board_ahci_vt8251] =
        {
-               AHCI_HFLAGS     (AHCI_HFLAG_NO_SNTF),
+               AHCI_HFLAGS     (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP),
                .flags          = AHCI_FLAG_COMMON,
                .pio_mask       = ATA_PIO4,
                .udma_mask      = ATA_UDMA6,
-               .port_ops       = &ahci_ops,
+               .port_ops       = &ahci_vt8251_ops,
        },
 };
 
@@ -629,2019 +277,323 @@ static const struct pci_device_id ahci_pci_tbl[] = {
        { PCI_VDEVICE(NVIDIA, 0x045d), board_ahci_mcp65 },      /* MCP65 */
        { PCI_VDEVICE(NVIDIA, 0x045e), board_ahci_mcp65 },      /* MCP65 */
        { PCI_VDEVICE(NVIDIA, 0x045f), board_ahci_mcp65 },      /* MCP65 */
-       { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0557), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0558), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0559), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x055a), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x055b), board_ahci_yesncq },     /* MCP67 */
-       { PCI_VDEVICE(NVIDIA, 0x0580), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0581), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0582), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0583), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0584), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0585), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0586), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0587), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0588), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x0589), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058a), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058b), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058c), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058d), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058e), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x058f), board_ahci_yesncq },     /* Linux ID */
-       { PCI_VDEVICE(NVIDIA, 0x07f0), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f1), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f2), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f3), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f4), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f5), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f6), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f7), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f8), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07f9), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07fa), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x07fb), board_ahci_yesncq },     /* MCP73 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad0), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad1), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad2), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad3), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad4), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad5), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad6), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad7), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad8), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci },            /* MCP77 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0abb), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0abc), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0abd), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0abe), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0abf), board_ahci },            /* MCP79 */
-       { PCI_VDEVICE(NVIDIA, 0x0d84), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d85), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d86), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d87), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d88), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d89), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8a), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8b), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8c), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8d), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8e), board_ahci },            /* MCP89 */
-       { PCI_VDEVICE(NVIDIA, 0x0d8f), board_ahci },            /* MCP89 */
-
-       /* SiS */
-       { PCI_VDEVICE(SI, 0x1184), board_ahci },                /* SiS 966 */
-       { PCI_VDEVICE(SI, 0x1185), board_ahci },                /* SiS 968 */
-       { PCI_VDEVICE(SI, 0x0186), board_ahci },                /* SiS 968 */
-
-       /* Marvell */
-       { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv },        /* 6145 */
-       { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv },        /* 6121 */
-
-       /* Promise */
-       { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci },   /* PDC42819 */
-
-       /* Generic, PCI class code for AHCI */
-       { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
-         PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
-
-       { }     /* terminate list */
-};
-
-
-static struct pci_driver ahci_pci_driver = {
-       .name                   = DRV_NAME,
-       .id_table               = ahci_pci_tbl,
-       .probe                  = ahci_init_one,
-       .remove                 = ata_pci_remove_one,
-#ifdef CONFIG_PM
-       .suspend                = ahci_pci_device_suspend,
-       .resume                 = ahci_pci_device_resume,
-#endif
-};
-
-static int ahci_em_messages = 1;
-module_param(ahci_em_messages, int, 0444);
-/* add other LED protocol types when they become supported */
-MODULE_PARM_DESC(ahci_em_messages,
-       "Set AHCI Enclosure Management Message type (0 = disabled, 1 = LED");
-
-#if defined(CONFIG_PATA_MARVELL) || defined(CONFIG_PATA_MARVELL_MODULE)
-static int marvell_enable;
-#else
-static int marvell_enable = 1;
-#endif
-module_param(marvell_enable, int, 0644);
-MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
-
-
-static inline int ahci_nr_ports(u32 cap)
-{
-       return (cap & 0x1f) + 1;
-}
-
-static inline void __iomem *__ahci_port_base(struct ata_host *host,
-                                            unsigned int port_no)
-{
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-
-       return mmio + 0x100 + (port_no * 0x80);
-}
-
-static inline void __iomem *ahci_port_base(struct ata_port *ap)
-{
-       return __ahci_port_base(ap->host, ap->port_no);
-}
-
-static void ahci_enable_ahci(void __iomem *mmio)
-{
-       int i;
-       u32 tmp;
-
-       /* turn on AHCI_EN */
-       tmp = readl(mmio + HOST_CTL);
-       if (tmp & HOST_AHCI_EN)
-               return;
-
-       /* Some controllers need AHCI_EN to be written multiple times.
-        * Try a few times before giving up.
-        */
-       for (i = 0; i < 5; i++) {
-               tmp |= HOST_AHCI_EN;
-               writel(tmp, mmio + HOST_CTL);
-               tmp = readl(mmio + HOST_CTL);   /* flush && sanity check */
-               if (tmp & HOST_AHCI_EN)
-                       return;
-               msleep(10);
-       }
-
-       WARN_ON(1);
-}
-
-static ssize_t ahci_show_host_caps(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-
-       return sprintf(buf, "%x\n", hpriv->cap);
-}
-
-static ssize_t ahci_show_host_cap2(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-
-       return sprintf(buf, "%x\n", hpriv->cap2);
-}
-
-static ssize_t ahci_show_host_version(struct device *dev,
-                                  struct device_attribute *attr, char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
-
-       return sprintf(buf, "%x\n", readl(mmio + HOST_VERSION));
-}
-
-static ssize_t ahci_show_port_cmd(struct device *dev,
-                                 struct device_attribute *attr, char *buf)
-{
-       struct Scsi_Host *shost = class_to_shost(dev);
-       struct ata_port *ap = ata_shost_to_port(shost);
-       void __iomem *port_mmio = ahci_port_base(ap);
-
-       return sprintf(buf, "%x\n", readl(port_mmio + PORT_CMD));
-}
-
-/**
- *     ahci_save_initial_config - Save and fixup initial config values
- *     @pdev: target PCI device
- *     @hpriv: host private area to store config values
- *
- *     Some registers containing configuration info might be setup by
- *     BIOS and might be cleared on reset.  This function saves the
- *     initial values of those registers into @hpriv such that they
- *     can be restored after controller reset.
- *
- *     If inconsistent, config values are fixed up by this function.
- *
- *     LOCKING:
- *     None.
- */
-static void ahci_save_initial_config(struct pci_dev *pdev,
-                                    struct ahci_host_priv *hpriv)
-{
-       void __iomem *mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
-       u32 cap, cap2, vers, port_map;
-       int i;
-       int mv;
-
-       /* make sure AHCI mode is enabled before accessing CAP */
-       ahci_enable_ahci(mmio);
-
-       /* Values prefixed with saved_ are written back to host after
-        * reset.  Values without are used for driver operation.
-        */
-       hpriv->saved_cap = cap = readl(mmio + HOST_CAP);
-       hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL);
-
-       /* CAP2 register is only defined for AHCI 1.2 and later */
-       vers = readl(mmio + HOST_VERSION);
-       if ((vers >> 16) > 1 ||
-          ((vers >> 16) == 1 && (vers & 0xFFFF) >= 0x200))
-               hpriv->saved_cap2 = cap2 = readl(mmio + HOST_CAP2);
-       else
-               hpriv->saved_cap2 = cap2 = 0;
-
-       /* some chips have errata preventing 64bit use */
-       if ((cap & HOST_CAP_64) && (hpriv->flags & AHCI_HFLAG_32BIT_ONLY)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "controller can't do 64bit DMA, forcing 32bit\n");
-               cap &= ~HOST_CAP_64;
-       }
-
-       if ((cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_NO_NCQ)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "controller can't do NCQ, turning off CAP_NCQ\n");
-               cap &= ~HOST_CAP_NCQ;
-       }
-
-       if (!(cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_YES_NCQ)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "controller can do NCQ, turning on CAP_NCQ\n");
-               cap |= HOST_CAP_NCQ;
-       }
-
-       if ((cap & HOST_CAP_PMP) && (hpriv->flags & AHCI_HFLAG_NO_PMP)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "controller can't do PMP, turning off CAP_PMP\n");
-               cap &= ~HOST_CAP_PMP;
-       }
-
-       if ((cap & HOST_CAP_SNTF) && (hpriv->flags & AHCI_HFLAG_NO_SNTF)) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "controller can't do SNTF, turning off CAP_SNTF\n");
-               cap &= ~HOST_CAP_SNTF;
-       }
-
-       if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361 &&
-           port_map != 1) {
-               dev_printk(KERN_INFO, &pdev->dev,
-                          "JMB361 has only one port, port_map 0x%x -> 0x%x\n",
-                          port_map, 1);
-               port_map = 1;
-       }
-
-       /*
-        * Temporary Marvell 6145 hack: PATA port presence
-        * is asserted through the standard AHCI port
-        * presence register, as bit 4 (counting from 0)
-        */
-       if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
-               if (pdev->device == 0x6121)
-                       mv = 0x3;
-               else
-                       mv = 0xf;
-               dev_printk(KERN_ERR, &pdev->dev,
-                          "MV_AHCI HACK: port_map %x -> %x\n",
-                          port_map,
-                          port_map & mv);
-               dev_printk(KERN_ERR, &pdev->dev,
-                         "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
-
-               port_map &= mv;
-       }
-
-       /* cross check port_map and cap.n_ports */
-       if (port_map) {
-               int map_ports = 0;
-
-               for (i = 0; i < AHCI_MAX_PORTS; i++)
-                       if (port_map & (1 << i))
-                               map_ports++;
-
-               /* If PI has more ports than n_ports, whine, clear
-                * port_map and let it be generated from n_ports.
-                */
-               if (map_ports > ahci_nr_ports(cap)) {
-                       dev_printk(KERN_WARNING, &pdev->dev,
-                                  "implemented port map (0x%x) contains more "
-                                  "ports than nr_ports (%u), using nr_ports\n",
-                                  port_map, ahci_nr_ports(cap));
-                       port_map = 0;
-               }
-       }
-
-       /* fabricate port_map from cap.nr_ports */
-       if (!port_map) {
-               port_map = (1 << ahci_nr_ports(cap)) - 1;
-               dev_printk(KERN_WARNING, &pdev->dev,
-                          "forcing PORTS_IMPL to 0x%x\n", port_map);
-
-               /* write the fixed up value to the PI register */
-               hpriv->saved_port_map = port_map;
-       }
-
-       /* record values to use during operation */
-       hpriv->cap = cap;
-       hpriv->cap2 = cap2;
-       hpriv->port_map = port_map;
-}
-
-/**
- *     ahci_restore_initial_config - Restore initial config
- *     @host: target ATA host
- *
- *     Restore initial config stored by ahci_save_initial_config().
- *
- *     LOCKING:
- *     None.
- */
-static void ahci_restore_initial_config(struct ata_host *host)
-{
-       struct ahci_host_priv *hpriv = host->private_data;
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-
-       writel(hpriv->saved_cap, mmio + HOST_CAP);
-       if (hpriv->saved_cap2)
-               writel(hpriv->saved_cap2, mmio + HOST_CAP2);
-       writel(hpriv->saved_port_map, mmio + HOST_PORTS_IMPL);
-       (void) readl(mmio + HOST_PORTS_IMPL);   /* flush */
-}
-
-static unsigned ahci_scr_offset(struct ata_port *ap, unsigned int sc_reg)
-{
-       static const int offset[] = {
-               [SCR_STATUS]            = PORT_SCR_STAT,
-               [SCR_CONTROL]           = PORT_SCR_CTL,
-               [SCR_ERROR]             = PORT_SCR_ERR,
-               [SCR_ACTIVE]            = PORT_SCR_ACT,
-               [SCR_NOTIFICATION]      = PORT_SCR_NTF,
-       };
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-
-       if (sc_reg < ARRAY_SIZE(offset) &&
-           (sc_reg != SCR_NOTIFICATION || (hpriv->cap & HOST_CAP_SNTF)))
-               return offset[sc_reg];
-       return 0;
-}
-
-static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
-{
-       void __iomem *port_mmio = ahci_port_base(link->ap);
-       int offset = ahci_scr_offset(link->ap, sc_reg);
-
-       if (offset) {
-               *val = readl(port_mmio + offset);
-               return 0;
-       }
-       return -EINVAL;
-}
-
-static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
-{
-       void __iomem *port_mmio = ahci_port_base(link->ap);
-       int offset = ahci_scr_offset(link->ap, sc_reg);
-
-       if (offset) {
-               writel(val, port_mmio + offset);
-               return 0;
-       }
-       return -EINVAL;
-}
-
-static void ahci_start_engine(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 tmp;
-
-       /* start DMA */
-       tmp = readl(port_mmio + PORT_CMD);
-       tmp |= PORT_CMD_START;
-       writel(tmp, port_mmio + PORT_CMD);
-       readl(port_mmio + PORT_CMD); /* flush */
-}
-
-static int ahci_stop_engine(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 tmp;
-
-       tmp = readl(port_mmio + PORT_CMD);
-
-       /* check if the HBA is idle */
-       if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0)
-               return 0;
-
-       /* setting HBA to idle */
-       tmp &= ~PORT_CMD_START;
-       writel(tmp, port_mmio + PORT_CMD);
-
-       /* wait for engine to stop. This could be as long as 500 msec */
-       tmp = ata_wait_register(port_mmio + PORT_CMD,
-                               PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
-       if (tmp & PORT_CMD_LIST_ON)
-               return -EIO;
-
-       return 0;
-}
-
-static void ahci_start_fis_rx(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       struct ahci_port_priv *pp = ap->private_data;
-       u32 tmp;
-
-       /* set FIS registers */
-       if (hpriv->cap & HOST_CAP_64)
-               writel((pp->cmd_slot_dma >> 16) >> 16,
-                      port_mmio + PORT_LST_ADDR_HI);
-       writel(pp->cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR);
-
-       if (hpriv->cap & HOST_CAP_64)
-               writel((pp->rx_fis_dma >> 16) >> 16,
-                      port_mmio + PORT_FIS_ADDR_HI);
-       writel(pp->rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
-
-       /* enable FIS reception */
-       tmp = readl(port_mmio + PORT_CMD);
-       tmp |= PORT_CMD_FIS_RX;
-       writel(tmp, port_mmio + PORT_CMD);
-
-       /* flush */
-       readl(port_mmio + PORT_CMD);
-}
-
-static int ahci_stop_fis_rx(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 tmp;
-
-       /* disable FIS reception */
-       tmp = readl(port_mmio + PORT_CMD);
-       tmp &= ~PORT_CMD_FIS_RX;
-       writel(tmp, port_mmio + PORT_CMD);
-
-       /* wait for completion, spec says 500ms, give it 1000 */
-       tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
-                               PORT_CMD_FIS_ON, 10, 1000);
-       if (tmp & PORT_CMD_FIS_ON)
-               return -EBUSY;
-
-       return 0;
-}
-
-static void ahci_power_up(struct ata_port *ap)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 cmd;
-
-       cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
-
-       /* spin up device */
-       if (hpriv->cap & HOST_CAP_SSS) {
-               cmd |= PORT_CMD_SPIN_UP;
-               writel(cmd, port_mmio + PORT_CMD);
-       }
-
-       /* wake up link */
-       writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD);
-}
-
-static void ahci_disable_alpm(struct ata_port *ap)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 cmd;
-       struct ahci_port_priv *pp = ap->private_data;
-
-       /* IPM bits should be disabled by libata-core */
-       /* get the existing command bits */
-       cmd = readl(port_mmio + PORT_CMD);
-
-       /* disable ALPM and ASP */
-       cmd &= ~PORT_CMD_ASP;
-       cmd &= ~PORT_CMD_ALPE;
-
-       /* force the interface back to active */
-       cmd |= PORT_CMD_ICC_ACTIVE;
-
-       /* write out new cmd value */
-       writel(cmd, port_mmio + PORT_CMD);
-       cmd = readl(port_mmio + PORT_CMD);
-
-       /* wait 10ms to be sure we've come out of any low power state */
-       msleep(10);
-
-       /* clear out any PhyRdy stuff from interrupt status */
-       writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT);
-
-       /* go ahead and clean out PhyRdy Change from Serror too */
-       ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
-
-       /*
-        * Clear flag to indicate that we should ignore all PhyRdy
-        * state changes
-        */
-       hpriv->flags &= ~AHCI_HFLAG_NO_HOTPLUG;
-
-       /*
-        * Enable interrupts on Phy Ready.
-        */
-       pp->intr_mask |= PORT_IRQ_PHYRDY;
-       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
-
-       /*
-        * don't change the link pm policy - we can be called
-        * just to turn of link pm temporarily
-        */
-}
-
-static int ahci_enable_alpm(struct ata_port *ap,
-       enum link_pm policy)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 cmd;
-       struct ahci_port_priv *pp = ap->private_data;
-       u32 asp;
-
-       /* Make sure the host is capable of link power management */
-       if (!(hpriv->cap & HOST_CAP_ALPM))
-               return -EINVAL;
-
-       switch (policy) {
-       case MAX_PERFORMANCE:
-       case NOT_AVAILABLE:
-               /*
-                * if we came here with NOT_AVAILABLE,
-                * it just means this is the first time we
-                * have tried to enable - default to max performance,
-                * and let the user go to lower power modes on request.
-                */
-               ahci_disable_alpm(ap);
-               return 0;
-       case MIN_POWER:
-               /* configure HBA to enter SLUMBER */
-               asp = PORT_CMD_ASP;
-               break;
-       case MEDIUM_POWER:
-               /* configure HBA to enter PARTIAL */
-               asp = 0;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       /*
-        * Disable interrupts on Phy Ready. This keeps us from
-        * getting woken up due to spurious phy ready interrupts
-        * TBD - Hot plug should be done via polling now, is
-        * that even supported?
-        */
-       pp->intr_mask &= ~PORT_IRQ_PHYRDY;
-       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
-
-       /*
-        * Set a flag to indicate that we should ignore all PhyRdy
-        * state changes since these can happen now whenever we
-        * change link state
-        */
-       hpriv->flags |= AHCI_HFLAG_NO_HOTPLUG;
-
-       /* get the existing command bits */
-       cmd = readl(port_mmio + PORT_CMD);
-
-       /*
-        * Set ASP based on Policy
-        */
-       cmd |= asp;
-
-       /*
-        * Setting this bit will instruct the HBA to aggressively
-        * enter a lower power link state when it's appropriate and
-        * based on the value set above for ASP
-        */
-       cmd |= PORT_CMD_ALPE;
-
-       /* write out new cmd value */
-       writel(cmd, port_mmio + PORT_CMD);
-       cmd = readl(port_mmio + PORT_CMD);
-
-       /* IPM bits should be set by libata-core */
-       return 0;
-}
-
-#ifdef CONFIG_PM
-static void ahci_power_down(struct ata_port *ap)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 cmd, scontrol;
-
-       if (!(hpriv->cap & HOST_CAP_SSS))
-               return;
-
-       /* put device into listen mode, first set PxSCTL.DET to 0 */
-       scontrol = readl(port_mmio + PORT_SCR_CTL);
-       scontrol &= ~0xf;
-       writel(scontrol, port_mmio + PORT_SCR_CTL);
-
-       /* then set PxCMD.SUD to 0 */
-       cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
-       cmd &= ~PORT_CMD_SPIN_UP;
-       writel(cmd, port_mmio + PORT_CMD);
-}
-#endif
-
-static void ahci_start_port(struct ata_port *ap)
-{
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ata_link *link;
-       struct ahci_em_priv *emp;
-       ssize_t rc;
-       int i;
-
-       /* enable FIS reception */
-       ahci_start_fis_rx(ap);
-
-       /* enable DMA */
-       ahci_start_engine(ap);
-
-       /* turn on LEDs */
-       if (ap->flags & ATA_FLAG_EM) {
-               ata_for_each_link(link, ap, EDGE) {
-                       emp = &pp->em_priv[link->pmp];
-
-                       /* EM Transmit bit maybe busy during init */
-                       for (i = 0; i < EM_MAX_RETRY; i++) {
-                               rc = ahci_transmit_led_message(ap,
-                                                              emp->led_state,
-                                                              4);
-                               if (rc == -EBUSY)
-                                       msleep(1);
-                               else
-                                       break;
-                       }
-               }
-       }
-
-       if (ap->flags & ATA_FLAG_SW_ACTIVITY)
-               ata_for_each_link(link, ap, EDGE)
-                       ahci_init_sw_activity(link);
-
-}
-
-static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
-{
-       int rc;
-
-       /* disable DMA */
-       rc = ahci_stop_engine(ap);
-       if (rc) {
-               *emsg = "failed to stop engine";
-               return rc;
-       }
-
-       /* disable FIS reception */
-       rc = ahci_stop_fis_rx(ap);
-       if (rc) {
-               *emsg = "failed stop FIS RX";
-               return rc;
-       }
-
-       return 0;
-}
-
-static int ahci_reset_controller(struct ata_host *host)
-{
-       struct pci_dev *pdev = to_pci_dev(host->dev);
-       struct ahci_host_priv *hpriv = host->private_data;
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-       u32 tmp;
-
-       /* we must be in AHCI mode, before using anything
-        * AHCI-specific, such as HOST_RESET.
-        */
-       ahci_enable_ahci(mmio);
-
-       /* global controller reset */
-       if (!ahci_skip_host_reset) {
-               tmp = readl(mmio + HOST_CTL);
-               if ((tmp & HOST_RESET) == 0) {
-                       writel(tmp | HOST_RESET, mmio + HOST_CTL);
-                       readl(mmio + HOST_CTL); /* flush */
-               }
-
-               /*
-                * to perform host reset, OS should set HOST_RESET
-                * and poll until this bit is read to be "0".
-                * reset must complete within 1 second, or
-                * the hardware should be considered fried.
-                */
-               tmp = ata_wait_register(mmio + HOST_CTL, HOST_RESET,
-                                       HOST_RESET, 10, 1000);
-
-               if (tmp & HOST_RESET) {
-                       dev_printk(KERN_ERR, host->dev,
-                                  "controller reset failed (0x%x)\n", tmp);
-                       return -EIO;
-               }
-
-               /* turn on AHCI mode */
-               ahci_enable_ahci(mmio);
-
-               /* Some registers might be cleared on reset.  Restore
-                * initial values.
-                */
-               ahci_restore_initial_config(host);
-       } else
-               dev_printk(KERN_INFO, host->dev,
-                          "skipping global host reset\n");
-
-       if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
-               u16 tmp16;
-
-               /* configure PCS */
-               pci_read_config_word(pdev, 0x92, &tmp16);
-               if ((tmp16 & hpriv->port_map) != hpriv->port_map) {
-                       tmp16 |= hpriv->port_map;
-                       pci_write_config_word(pdev, 0x92, tmp16);
-               }
-       }
-
-       return 0;
-}
-
-static void ahci_sw_activity(struct ata_link *link)
-{
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
-
-       if (!(link->flags & ATA_LFLAG_SW_ACTIVITY))
-               return;
-
-       emp->activity++;
-       if (!timer_pending(&emp->timer))
-               mod_timer(&emp->timer, jiffies + msecs_to_jiffies(10));
-}
-
-static void ahci_sw_activity_blink(unsigned long arg)
-{
-       struct ata_link *link = (struct ata_link *)arg;
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
-       unsigned long led_message = emp->led_state;
-       u32 activity_led_state;
-       unsigned long flags;
-
-       led_message &= EM_MSG_LED_VALUE;
-       led_message |= ap->port_no | (link->pmp << 8);
-
-       /* check to see if we've had activity.  If so,
-        * toggle state of LED and reset timer.  If not,
-        * turn LED to desired idle state.
-        */
-       spin_lock_irqsave(ap->lock, flags);
-       if (emp->saved_activity != emp->activity) {
-               emp->saved_activity = emp->activity;
-               /* get the current LED state */
-               activity_led_state = led_message & EM_MSG_LED_VALUE_ON;
-
-               if (activity_led_state)
-                       activity_led_state = 0;
-               else
-                       activity_led_state = 1;
-
-               /* clear old state */
-               led_message &= ~EM_MSG_LED_VALUE_ACTIVITY;
-
-               /* toggle state */
-               led_message |= (activity_led_state << 16);
-               mod_timer(&emp->timer, jiffies + msecs_to_jiffies(100));
-       } else {
-               /* switch to idle */
-               led_message &= ~EM_MSG_LED_VALUE_ACTIVITY;
-               if (emp->blink_policy == BLINK_OFF)
-                       led_message |= (1 << 16);
-       }
-       spin_unlock_irqrestore(ap->lock, flags);
-       ahci_transmit_led_message(ap, led_message, 4);
-}
-
-static void ahci_init_sw_activity(struct ata_link *link)
-{
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
-
-       /* init activity stats, setup timer */
-       emp->saved_activity = emp->activity = 0;
-       setup_timer(&emp->timer, ahci_sw_activity_blink, (unsigned long)link);
-
-       /* check our blink policy and set flag for link if it's enabled */
-       if (emp->blink_policy)
-               link->flags |= ATA_LFLAG_SW_ACTIVITY;
-}
-
-static int ahci_reset_em(struct ata_host *host)
-{
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-       u32 em_ctl;
-
-       em_ctl = readl(mmio + HOST_EM_CTL);
-       if ((em_ctl & EM_CTL_TM) || (em_ctl & EM_CTL_RST))
-               return -EINVAL;
-
-       writel(em_ctl | EM_CTL_RST, mmio + HOST_EM_CTL);
-       return 0;
-}
-
-static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
-                                       ssize_t size)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       struct ahci_port_priv *pp = ap->private_data;
-       void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
-       u32 em_ctl;
-       u32 message[] = {0, 0};
-       unsigned long flags;
-       int pmp;
-       struct ahci_em_priv *emp;
-
-       /* get the slot number from the message */
-       pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
-       if (pmp < EM_MAX_SLOTS)
-               emp = &pp->em_priv[pmp];
-       else
-               return -EINVAL;
-
-       spin_lock_irqsave(ap->lock, flags);
-
-       /*
-        * if we are still busy transmitting a previous message,
-        * do not allow
-        */
-       em_ctl = readl(mmio + HOST_EM_CTL);
-       if (em_ctl & EM_CTL_TM) {
-               spin_unlock_irqrestore(ap->lock, flags);
-               return -EBUSY;
-       }
-
-       /*
-        * create message header - this is all zero except for
-        * the message size, which is 4 bytes.
-        */
-       message[0] |= (4 << 8);
-
-       /* ignore 0:4 of byte zero, fill in port info yourself */
-       message[1] = ((state & ~EM_MSG_LED_HBA_PORT) | ap->port_no);
-
-       /* write message to EM_LOC */
-       writel(message[0], mmio + hpriv->em_loc);
-       writel(message[1], mmio + hpriv->em_loc+4);
-
-       /* save off new led state for port/slot */
-       emp->led_state = state;
-
-       /*
-        * tell hardware to transmit the message
-        */
-       writel(em_ctl | EM_CTL_TM, mmio + HOST_EM_CTL);
-
-       spin_unlock_irqrestore(ap->lock, flags);
-       return size;
-}
-
-static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
-{
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ata_link *link;
-       struct ahci_em_priv *emp;
-       int rc = 0;
-
-       ata_for_each_link(link, ap, EDGE) {
-               emp = &pp->em_priv[link->pmp];
-               rc += sprintf(buf, "%lx\n", emp->led_state);
-       }
-       return rc;
-}
-
-static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
-                               size_t size)
-{
-       int state;
-       int pmp;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp;
-
-       state = simple_strtoul(buf, NULL, 0);
-
-       /* get the slot number from the message */
-       pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
-       if (pmp < EM_MAX_SLOTS)
-               emp = &pp->em_priv[pmp];
-       else
-               return -EINVAL;
-
-       /* mask off the activity bits if we are in sw_activity
-        * mode, user should turn off sw_activity before setting
-        * activity led through em_message
-        */
-       if (emp->blink_policy)
-               state &= ~EM_MSG_LED_VALUE_ACTIVITY;
-
-       return ahci_transmit_led_message(ap, state, size);
-}
-
-static ssize_t ahci_activity_store(struct ata_device *dev, enum sw_activity val)
-{
-       struct ata_link *link = dev->link;
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
-       u32 port_led_state = emp->led_state;
-
-       /* save the desired Activity LED behavior */
-       if (val == OFF) {
-               /* clear LFLAG */
-               link->flags &= ~(ATA_LFLAG_SW_ACTIVITY);
-
-               /* set the LED to OFF */
-               port_led_state &= EM_MSG_LED_VALUE_OFF;
-               port_led_state |= (ap->port_no | (link->pmp << 8));
-               ahci_transmit_led_message(ap, port_led_state, 4);
-       } else {
-               link->flags |= ATA_LFLAG_SW_ACTIVITY;
-               if (val == BLINK_OFF) {
-                       /* set LED to ON for idle */
-                       port_led_state &= EM_MSG_LED_VALUE_OFF;
-                       port_led_state |= (ap->port_no | (link->pmp << 8));
-                       port_led_state |= EM_MSG_LED_VALUE_ON; /* check this */
-                       ahci_transmit_led_message(ap, port_led_state, 4);
-               }
-       }
-       emp->blink_policy = val;
-       return 0;
-}
-
-static ssize_t ahci_activity_show(struct ata_device *dev, char *buf)
-{
-       struct ata_link *link = dev->link;
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
-
-       /* display the saved value of activity behavior for this
-        * disk.
-        */
-       return sprintf(buf, "%d\n", emp->blink_policy);
-}
-
-static void ahci_port_init(struct pci_dev *pdev, struct ata_port *ap,
-                          int port_no, void __iomem *mmio,
-                          void __iomem *port_mmio)
-{
-       const char *emsg = NULL;
-       int rc;
-       u32 tmp;
-
-       /* make sure port is not active */
-       rc = ahci_deinit_port(ap, &emsg);
-       if (rc)
-               dev_printk(KERN_WARNING, &pdev->dev,
-                          "%s (%d)\n", emsg, rc);
-
-       /* clear SError */
-       tmp = readl(port_mmio + PORT_SCR_ERR);
-       VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
-       writel(tmp, port_mmio + PORT_SCR_ERR);
-
-       /* clear port IRQ */
-       tmp = readl(port_mmio + PORT_IRQ_STAT);
-       VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
-       if (tmp)
-               writel(tmp, port_mmio + PORT_IRQ_STAT);
-
-       writel(1 << port_no, mmio + HOST_IRQ_STAT);
-}
-
-static void ahci_init_controller(struct ata_host *host)
-{
-       struct ahci_host_priv *hpriv = host->private_data;
-       struct pci_dev *pdev = to_pci_dev(host->dev);
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-       int i;
-       void __iomem *port_mmio;
-       u32 tmp;
-       int mv;
-
-       if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
-               if (pdev->device == 0x6121)
-                       mv = 2;
-               else
-                       mv = 4;
-               port_mmio = __ahci_port_base(host, mv);
-
-               writel(0, port_mmio + PORT_IRQ_MASK);
-
-               /* clear port IRQ */
-               tmp = readl(port_mmio + PORT_IRQ_STAT);
-               VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
-               if (tmp)
-                       writel(tmp, port_mmio + PORT_IRQ_STAT);
-       }
-
-       for (i = 0; i < host->n_ports; i++) {
-               struct ata_port *ap = host->ports[i];
-
-               port_mmio = ahci_port_base(ap);
-               if (ata_port_is_dummy(ap))
-                       continue;
-
-               ahci_port_init(pdev, ap, i, mmio, port_mmio);
-       }
-
-       tmp = readl(mmio + HOST_CTL);
-       VPRINTK("HOST_CTL 0x%x\n", tmp);
-       writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
-       tmp = readl(mmio + HOST_CTL);
-       VPRINTK("HOST_CTL 0x%x\n", tmp);
-}
-
-static void ahci_dev_config(struct ata_device *dev)
-{
-       struct ahci_host_priv *hpriv = dev->link->ap->host->private_data;
-
-       if (hpriv->flags & AHCI_HFLAG_SECT255) {
-               dev->max_sectors = 255;
-               ata_dev_printk(dev, KERN_INFO,
-                              "SB600 AHCI: limiting to 255 sectors per cmd\n");
-       }
-}
-
-static unsigned int ahci_dev_classify(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ata_taskfile tf;
-       u32 tmp;
-
-       tmp = readl(port_mmio + PORT_SIG);
-       tf.lbah         = (tmp >> 24)   & 0xff;
-       tf.lbam         = (tmp >> 16)   & 0xff;
-       tf.lbal         = (tmp >> 8)    & 0xff;
-       tf.nsect        = (tmp)         & 0xff;
-
-       return ata_dev_classify(&tf);
-}
-
-static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
-                              u32 opts)
-{
-       dma_addr_t cmd_tbl_dma;
-
-       cmd_tbl_dma = pp->cmd_tbl_dma + tag * AHCI_CMD_TBL_SZ;
-
-       pp->cmd_slot[tag].opts = cpu_to_le32(opts);
-       pp->cmd_slot[tag].status = 0;
-       pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffffff);
-       pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
-}
-
-static int ahci_kick_engine(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
-       u32 tmp;
-       int busy, rc;
-
-       /* stop engine */
-       rc = ahci_stop_engine(ap);
-       if (rc)
-               goto out_restart;
-
-       /* need to do CLO?
-        * always do CLO if PMP is attached (AHCI-1.3 9.2)
-        */
-       busy = status & (ATA_BUSY | ATA_DRQ);
-       if (!busy && !sata_pmp_attached(ap)) {
-               rc = 0;
-               goto out_restart;
-       }
-
-       if (!(hpriv->cap & HOST_CAP_CLO)) {
-               rc = -EOPNOTSUPP;
-               goto out_restart;
-       }
-
-       /* perform CLO */
-       tmp = readl(port_mmio + PORT_CMD);
-       tmp |= PORT_CMD_CLO;
-       writel(tmp, port_mmio + PORT_CMD);
-
-       rc = 0;
-       tmp = ata_wait_register(port_mmio + PORT_CMD,
-                               PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
-       if (tmp & PORT_CMD_CLO)
-               rc = -EIO;
-
-       /* restart engine */
- out_restart:
-       ahci_start_engine(ap);
-       return rc;
-}
-
-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
-                               struct ata_taskfile *tf, int is_cmd, u16 flags,
-                               unsigned long timeout_msec)
-{
-       const u32 cmd_fis_len = 5; /* five dwords */
-       struct ahci_port_priv *pp = ap->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u8 *fis = pp->cmd_tbl;
-       u32 tmp;
-
-       /* prep the command */
-       ata_tf_to_fis(tf, pmp, is_cmd, fis);
-       ahci_fill_cmd_slot(pp, 0, cmd_fis_len | flags | (pmp << 12));
-
-       /* issue & wait */
-       writel(1, port_mmio + PORT_CMD_ISSUE);
-
-       if (timeout_msec) {
-               tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1,
-                                       1, timeout_msec);
-               if (tmp & 0x1) {
-                       ahci_kick_engine(ap);
-                       return -EBUSY;
-               }
-       } else
-               readl(port_mmio + PORT_CMD_ISSUE);      /* flush */
-
-       return 0;
-}
-
-static int ahci_do_softreset(struct ata_link *link, unsigned int *class,
-                            int pmp, unsigned long deadline,
-                            int (*check_ready)(struct ata_link *link))
-{
-       struct ata_port *ap = link->ap;
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       const char *reason = NULL;
-       unsigned long now, msecs;
-       struct ata_taskfile tf;
-       int rc;
-
-       DPRINTK("ENTER\n");
-
-       /* prepare for SRST (AHCI-1.1 10.4.1) */
-       rc = ahci_kick_engine(ap);
-       if (rc && rc != -EOPNOTSUPP)
-               ata_link_printk(link, KERN_WARNING,
-                               "failed to reset engine (errno=%d)\n", rc);
-
-       ata_tf_init(link->device, &tf);
-
-       /* issue the first D2H Register FIS */
-       msecs = 0;
-       now = jiffies;
-       if (time_after(now, deadline))
-               msecs = jiffies_to_msecs(deadline - now);
-
-       tf.ctl |= ATA_SRST;
-       if (ahci_exec_polled_cmd(ap, pmp, &tf, 0,
-                                AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY, msecs)) {
-               rc = -EIO;
-               reason = "1st FIS failed";
-               goto fail;
-       }
-
-       /* spec says at least 5us, but be generous and sleep for 1ms */
-       msleep(1);
-
-       /* issue the second D2H Register FIS */
-       tf.ctl &= ~ATA_SRST;
-       ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0);
-
-       /* wait for link to become ready */
-       rc = ata_wait_after_reset(link, deadline, check_ready);
-       if (rc == -EBUSY && hpriv->flags & AHCI_HFLAG_SRST_TOUT_IS_OFFLINE) {
-               /*
-                * Workaround for cases where link online status can't
-                * be trusted.  Treat device readiness timeout as link
-                * offline.
-                */
-               ata_link_printk(link, KERN_INFO,
-                               "device not ready, treating as offline\n");
-               *class = ATA_DEV_NONE;
-       } else if (rc) {
-               /* link occupied, -ENODEV too is an error */
-               reason = "device not ready";
-               goto fail;
-       } else
-               *class = ahci_dev_classify(ap);
-
-       DPRINTK("EXIT, class=%u\n", *class);
-       return 0;
-
- fail:
-       ata_link_printk(link, KERN_ERR, "softreset failed (%s)\n", reason);
-       return rc;
-}
-
-static int ahci_check_ready(struct ata_link *link)
-{
-       void __iomem *port_mmio = ahci_port_base(link->ap);
-       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
-
-       return ata_check_ready(status);
-}
-
-static int ahci_softreset(struct ata_link *link, unsigned int *class,
-                         unsigned long deadline)
-{
-       int pmp = sata_srst_pmp(link);
-
-       DPRINTK("ENTER\n");
-
-       return ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
-}
-
-static int ahci_sb600_check_ready(struct ata_link *link)
-{
-       void __iomem *port_mmio = ahci_port_base(link->ap);
-       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
-       u32 irq_status = readl(port_mmio + PORT_IRQ_STAT);
-
-       /*
-        * There is no need to check TFDATA if BAD PMP is found due to HW bug,
-        * which can save timeout delay.
-        */
-       if (irq_status & PORT_IRQ_BAD_PMP)
-               return -EIO;
-
-       return ata_check_ready(status);
-}
-
-static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
-                               unsigned long deadline)
-{
-       struct ata_port *ap = link->ap;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       int pmp = sata_srst_pmp(link);
-       int rc;
-       u32 irq_sts;
-
-       DPRINTK("ENTER\n");
-
-       rc = ahci_do_softreset(link, class, pmp, deadline,
-                              ahci_sb600_check_ready);
-
-       /*
-        * Soft reset fails on some ATI chips with IPMS set when PMP
-        * is enabled but SATA HDD/ODD is connected to SATA port,
-        * do soft reset again to port 0.
-        */
-       if (rc == -EIO) {
-               irq_sts = readl(port_mmio + PORT_IRQ_STAT);
-               if (irq_sts & PORT_IRQ_BAD_PMP) {
-                       ata_link_printk(link, KERN_WARNING,
-                                       "applying SB600 PMP SRST workaround "
-                                       "and retrying\n");
-                       rc = ahci_do_softreset(link, class, 0, deadline,
-                                              ahci_check_ready);
-               }
-       }
-
-       return rc;
-}
-
-static int ahci_hardreset(struct ata_link *link, unsigned int *class,
-                         unsigned long deadline)
-{
-       const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
-       struct ata_taskfile tf;
-       bool online;
-       int rc;
-
-       DPRINTK("ENTER\n");
-
-       ahci_stop_engine(ap);
-
-       /* clear D2H reception area to properly wait for D2H FIS */
-       ata_tf_init(link->device, &tf);
-       tf.command = 0x80;
-       ata_tf_to_fis(&tf, 0, 0, d2h_fis);
-
-       rc = sata_link_hardreset(link, timing, deadline, &online,
-                                ahci_check_ready);
-
-       ahci_start_engine(ap);
-
-       if (online)
-               *class = ahci_dev_classify(ap);
-
-       DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
-       return rc;
-}
-
-static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
-                                unsigned long deadline)
-{
-       struct ata_port *ap = link->ap;
-       bool online;
-       int rc;
-
-       DPRINTK("ENTER\n");
-
-       ahci_stop_engine(ap);
-
-       rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
-                                deadline, &online, NULL);
-
-       ahci_start_engine(ap);
-
-       DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
-
-       /* vt8251 doesn't clear BSY on signature FIS reception,
-        * request follow-up softreset.
-        */
-       return online ? -EAGAIN : rc;
-}
-
-static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
-                               unsigned long deadline)
-{
-       struct ata_port *ap = link->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
-       struct ata_taskfile tf;
-       bool online;
-       int rc;
-
-       ahci_stop_engine(ap);
-
-       /* clear D2H reception area to properly wait for D2H FIS */
-       ata_tf_init(link->device, &tf);
-       tf.command = 0x80;
-       ata_tf_to_fis(&tf, 0, 0, d2h_fis);
-
-       rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
-                                deadline, &online, NULL);
-
-       ahci_start_engine(ap);
-
-       /* The pseudo configuration device on SIMG4726 attached to
-        * ASUS P5W-DH Deluxe doesn't send signature FIS after
-        * hardreset if no device is attached to the first downstream
-        * port && the pseudo device locks up on SRST w/ PMP==0.  To
-        * work around this, wait for !BSY only briefly.  If BSY isn't
-        * cleared, perform CLO and proceed to IDENTIFY (achieved by
-        * ATA_LFLAG_NO_SRST and ATA_LFLAG_ASSUME_ATA).
-        *
-        * Wait for two seconds.  Devices attached to downstream port
-        * which can't process the following IDENTIFY after this will
-        * have to be reset again.  For most cases, this should
-        * suffice while making probing snappish enough.
-        */
-       if (online) {
-               rc = ata_wait_after_reset(link, jiffies + 2 * HZ,
-                                         ahci_check_ready);
-               if (rc)
-                       ahci_kick_engine(ap);
-       }
-       return rc;
-}
-
-static void ahci_postreset(struct ata_link *link, unsigned int *class)
-{
-       struct ata_port *ap = link->ap;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 new_tmp, tmp;
-
-       ata_std_postreset(link, class);
-
-       /* Make sure port's ATAPI bit is set appropriately */
-       new_tmp = tmp = readl(port_mmio + PORT_CMD);
-       if (*class == ATA_DEV_ATAPI)
-               new_tmp |= PORT_CMD_ATAPI;
-       else
-               new_tmp &= ~PORT_CMD_ATAPI;
-       if (new_tmp != tmp) {
-               writel(new_tmp, port_mmio + PORT_CMD);
-               readl(port_mmio + PORT_CMD); /* flush */
-       }
-}
-
-static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
-{
-       struct scatterlist *sg;
-       struct ahci_sg *ahci_sg = cmd_tbl + AHCI_CMD_TBL_HDR_SZ;
-       unsigned int si;
-
-       VPRINTK("ENTER\n");
-
-       /*
-        * Next, the S/G list.
-        */
-       for_each_sg(qc->sg, sg, qc->n_elem, si) {
-               dma_addr_t addr = sg_dma_address(sg);
-               u32 sg_len = sg_dma_len(sg);
-
-               ahci_sg[si].addr = cpu_to_le32(addr & 0xffffffff);
-               ahci_sg[si].addr_hi = cpu_to_le32((addr >> 16) >> 16);
-               ahci_sg[si].flags_size = cpu_to_le32(sg_len - 1);
-       }
-
-       return si;
-}
-
-static int ahci_pmp_qc_defer(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-
-       if (!sata_pmp_attached(ap) || pp->fbs_enabled)
-               return ata_std_qc_defer(qc);
-       else
-               return sata_pmp_qc_defer_cmd_switch(qc);
-}
-
-static void ahci_qc_prep(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       struct ahci_port_priv *pp = ap->private_data;
-       int is_atapi = ata_is_atapi(qc->tf.protocol);
-       void *cmd_tbl;
-       u32 opts;
-       const u32 cmd_fis_len = 5; /* five dwords */
-       unsigned int n_elem;
-
-       /*
-        * Fill in command table information.  First, the header,
-        * a SATA Register - Host to Device command FIS.
-        */
-       cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
-
-       ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
-       if (is_atapi) {
-               memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
-               memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len);
-       }
-
-       n_elem = 0;
-       if (qc->flags & ATA_QCFLAG_DMAMAP)
-               n_elem = ahci_fill_sg(qc, cmd_tbl);
-
-       /*
-        * Fill in command slot information.
-        */
-       opts = cmd_fis_len | n_elem << 16 | (qc->dev->link->pmp << 12);
-       if (qc->tf.flags & ATA_TFLAG_WRITE)
-               opts |= AHCI_CMD_WRITE;
-       if (is_atapi)
-               opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
-
-       ahci_fill_cmd_slot(pp, qc->tag, opts);
-}
-
-static void ahci_fbs_dec_intr(struct ata_port *ap)
-{
-       struct ahci_port_priv *pp = ap->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 fbs = readl(port_mmio + PORT_FBS);
-       int retries = 3;
-
-       DPRINTK("ENTER\n");
-       BUG_ON(!pp->fbs_enabled);
-
-       /* time to wait for DEC is not specified by AHCI spec,
-        * add a retry loop for safety.
-        */
-       writel(fbs | PORT_FBS_DEC, port_mmio + PORT_FBS);
-       fbs = readl(port_mmio + PORT_FBS);
-       while ((fbs & PORT_FBS_DEC) && retries--) {
-               udelay(1);
-               fbs = readl(port_mmio + PORT_FBS);
-       }
-
-       if (fbs & PORT_FBS_DEC)
-               dev_printk(KERN_ERR, ap->host->dev,
-                          "failed to clear device error\n");
-}
-
-static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ata_eh_info *host_ehi = &ap->link.eh_info;
-       struct ata_link *link = NULL;
-       struct ata_queued_cmd *active_qc;
-       struct ata_eh_info *active_ehi;
-       bool fbs_need_dec = false;
-       u32 serror;
-
-       /* determine active link with error */
-       if (pp->fbs_enabled) {
-               void __iomem *port_mmio = ahci_port_base(ap);
-               u32 fbs = readl(port_mmio + PORT_FBS);
-               int pmp = fbs >> PORT_FBS_DWE_OFFSET;
-
-               if ((fbs & PORT_FBS_SDE) && (pmp < ap->nr_pmp_links) &&
-                   ata_link_online(&ap->pmp_link[pmp])) {
-                       link = &ap->pmp_link[pmp];
-                       fbs_need_dec = true;
-               }
-
-       } else
-               ata_for_each_link(link, ap, EDGE)
-                       if (ata_link_active(link))
-                               break;
-
-       if (!link)
-               link = &ap->link;
-
-       active_qc = ata_qc_from_tag(ap, link->active_tag);
-       active_ehi = &link->eh_info;
-
-       /* record irq stat */
-       ata_ehi_clear_desc(host_ehi);
-       ata_ehi_push_desc(host_ehi, "irq_stat 0x%08x", irq_stat);
-
-       /* AHCI needs SError cleared; otherwise, it might lock up */
-       ahci_scr_read(&ap->link, SCR_ERROR, &serror);
-       ahci_scr_write(&ap->link, SCR_ERROR, serror);
-       host_ehi->serror |= serror;
-
-       /* some controllers set IRQ_IF_ERR on device errors, ignore it */
-       if (hpriv->flags & AHCI_HFLAG_IGN_IRQ_IF_ERR)
-               irq_stat &= ~PORT_IRQ_IF_ERR;
-
-       if (irq_stat & PORT_IRQ_TF_ERR) {
-               /* If qc is active, charge it; otherwise, the active
-                * link.  There's no active qc on NCQ errors.  It will
-                * be determined by EH by reading log page 10h.
-                */
-               if (active_qc)
-                       active_qc->err_mask |= AC_ERR_DEV;
-               else
-                       active_ehi->err_mask |= AC_ERR_DEV;
-
-               if (hpriv->flags & AHCI_HFLAG_IGN_SERR_INTERNAL)
-                       host_ehi->serror &= ~SERR_INTERNAL;
-       }
-
-       if (irq_stat & PORT_IRQ_UNK_FIS) {
-               u32 *unk = (u32 *)(pp->rx_fis + RX_FIS_UNK);
-
-               active_ehi->err_mask |= AC_ERR_HSM;
-               active_ehi->action |= ATA_EH_RESET;
-               ata_ehi_push_desc(active_ehi,
-                                 "unknown FIS %08x %08x %08x %08x" ,
-                                 unk[0], unk[1], unk[2], unk[3]);
-       }
-
-       if (sata_pmp_attached(ap) && (irq_stat & PORT_IRQ_BAD_PMP)) {
-               active_ehi->err_mask |= AC_ERR_HSM;
-               active_ehi->action |= ATA_EH_RESET;
-               ata_ehi_push_desc(active_ehi, "incorrect PMP");
-       }
-
-       if (irq_stat & (PORT_IRQ_HBUS_ERR | PORT_IRQ_HBUS_DATA_ERR)) {
-               host_ehi->err_mask |= AC_ERR_HOST_BUS;
-               host_ehi->action |= ATA_EH_RESET;
-               ata_ehi_push_desc(host_ehi, "host bus error");
-       }
-
-       if (irq_stat & PORT_IRQ_IF_ERR) {
-               if (fbs_need_dec)
-                       active_ehi->err_mask |= AC_ERR_DEV;
-               else {
-                       host_ehi->err_mask |= AC_ERR_ATA_BUS;
-                       host_ehi->action |= ATA_EH_RESET;
-               }
-
-               ata_ehi_push_desc(host_ehi, "interface fatal error");
-       }
-
-       if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) {
-               ata_ehi_hotplugged(host_ehi);
-               ata_ehi_push_desc(host_ehi, "%s",
-                       irq_stat & PORT_IRQ_CONNECT ?
-                       "connection status changed" : "PHY RDY changed");
-       }
-
-       /* okay, let's hand over to EH */
-
-       if (irq_stat & PORT_IRQ_FREEZE)
-               ata_port_freeze(ap);
-       else if (fbs_need_dec) {
-               ata_link_abort(link);
-               ahci_fbs_dec_intr(ap);
-       } else
-               ata_port_abort(ap);
-}
-
-static void ahci_port_intr(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ata_eh_info *ehi = &ap->link.eh_info;
-       struct ahci_port_priv *pp = ap->private_data;
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       int resetting = !!(ap->pflags & ATA_PFLAG_RESETTING);
-       u32 status, qc_active = 0;
-       int rc;
-
-       status = readl(port_mmio + PORT_IRQ_STAT);
-       writel(status, port_mmio + PORT_IRQ_STAT);
-
-       /* ignore BAD_PMP while resetting */
-       if (unlikely(resetting))
-               status &= ~PORT_IRQ_BAD_PMP;
-
-       /* If we are getting PhyRdy, this is
-        * just a power state change, we should
-        * clear out this, plus the PhyRdy/Comm
-        * Wake bits from Serror
-        */
-       if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) &&
-               (status & PORT_IRQ_PHYRDY)) {
-               status &= ~PORT_IRQ_PHYRDY;
-               ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
-       }
-
-       if (unlikely(status & PORT_IRQ_ERROR)) {
-               ahci_error_intr(ap, status);
-               return;
-       }
-
-       if (status & PORT_IRQ_SDB_FIS) {
-               /* If SNotification is available, leave notification
-                * handling to sata_async_notification().  If not,
-                * emulate it by snooping SDB FIS RX area.
-                *
-                * Snooping FIS RX area is probably cheaper than
-                * poking SNotification but some constrollers which
-                * implement SNotification, ICH9 for example, don't
-                * store AN SDB FIS into receive area.
-                */
-               if (hpriv->cap & HOST_CAP_SNTF)
-                       sata_async_notification(ap);
-               else {
-                       /* If the 'N' bit in word 0 of the FIS is set,
-                        * we just received asynchronous notification.
-                        * Tell libata about it.
-                        *
-                        * Lack of SNotification should not appear in
-                        * ahci 1.2, so the workaround is unnecessary
-                        * when FBS is enabled.
-                        */
-                       if (pp->fbs_enabled)
-                               WARN_ON_ONCE(1);
-                       else {
-                               const __le32 *f = pp->rx_fis + RX_FIS_SDB;
-                               u32 f0 = le32_to_cpu(f[0]);
-                               if (f0 & (1 << 15))
-                                       sata_async_notification(ap);
-                       }
-               }
-       }
-
-       /* pp->active_link is not reliable once FBS is enabled, both
-        * PORT_SCR_ACT and PORT_CMD_ISSUE should be checked because
-        * NCQ and non-NCQ commands may be in flight at the same time.
-        */
-       if (pp->fbs_enabled) {
-               if (ap->qc_active) {
-                       qc_active = readl(port_mmio + PORT_SCR_ACT);
-                       qc_active |= readl(port_mmio + PORT_CMD_ISSUE);
-               }
-       } else {
-               /* pp->active_link is valid iff any command is in flight */
-               if (ap->qc_active && pp->active_link->sactive)
-                       qc_active = readl(port_mmio + PORT_SCR_ACT);
-               else
-                       qc_active = readl(port_mmio + PORT_CMD_ISSUE);
-       }
-
-       rc = ata_qc_complete_multiple(ap, qc_active);
-
-       /* while resetting, invalid completions are expected */
-       if (unlikely(rc < 0 && !resetting)) {
-               ehi->err_mask |= AC_ERR_HSM;
-               ehi->action |= ATA_EH_RESET;
-               ata_port_freeze(ap);
-       }
-}
-
-static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
-{
-       struct ata_host *host = dev_instance;
-       struct ahci_host_priv *hpriv;
-       unsigned int i, handled = 0;
-       void __iomem *mmio;
-       u32 irq_stat, irq_masked;
-
-       VPRINTK("ENTER\n");
-
-       hpriv = host->private_data;
-       mmio = host->iomap[AHCI_PCI_BAR];
+       { PCI_VDEVICE(NVIDIA, 0x0550), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0551), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0552), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0553), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0554), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0555), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0556), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0557), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0558), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0559), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x055a), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x055b), board_ahci_mcp67 },      /* MCP67 */
+       { PCI_VDEVICE(NVIDIA, 0x0580), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0581), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0582), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0583), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0584), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0585), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0586), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0587), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0588), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x0589), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058a), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058b), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058c), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058d), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058e), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x058f), board_ahci_mcp_linux },  /* Linux ID */
+       { PCI_VDEVICE(NVIDIA, 0x07f0), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f1), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f2), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f3), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f4), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f5), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f6), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f7), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f8), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07f9), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07fa), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x07fb), board_ahci_mcp73 },      /* MCP73 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad0), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad1), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad2), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad3), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad4), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad5), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad6), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad7), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad8), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ad9), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ada), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0adb), board_ahci_mcp77 },      /* MCP77 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab4), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab5), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab6), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab7), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab8), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0ab9), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0aba), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0abb), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0abc), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0abd), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0abe), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0abf), board_ahci_mcp79 },      /* MCP79 */
+       { PCI_VDEVICE(NVIDIA, 0x0d84), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d85), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d86), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d87), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d88), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d89), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8a), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8b), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8c), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8d), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8e), board_ahci_mcp89 },      /* MCP89 */
+       { PCI_VDEVICE(NVIDIA, 0x0d8f), board_ahci_mcp89 },      /* MCP89 */
 
-       /* sigh.  0xffffffff is a valid return from h/w */
-       irq_stat = readl(mmio + HOST_IRQ_STAT);
-       if (!irq_stat)
-               return IRQ_NONE;
+       /* SiS */
+       { PCI_VDEVICE(SI, 0x1184), board_ahci },                /* SiS 966 */
+       { PCI_VDEVICE(SI, 0x1185), board_ahci },                /* SiS 968 */
+       { PCI_VDEVICE(SI, 0x0186), board_ahci },                /* SiS 968 */
 
-       irq_masked = irq_stat & hpriv->port_map;
+       /* Marvell */
+       { PCI_VDEVICE(MARVELL, 0x6145), board_ahci_mv },        /* 6145 */
+       { PCI_VDEVICE(MARVELL, 0x6121), board_ahci_mv },        /* 6121 */
 
-       spin_lock(&host->lock);
+       /* Promise */
+       { PCI_VDEVICE(PROMISE, 0x3f20), board_ahci },   /* PDC42819 */
 
-       for (i = 0; i < host->n_ports; i++) {
-               struct ata_port *ap;
-
-               if (!(irq_masked & (1 << i)))
-                       continue;
-
-               ap = host->ports[i];
-               if (ap) {
-                       ahci_port_intr(ap);
-                       VPRINTK("port %u\n", i);
-               } else {
-                       VPRINTK("port %u (no irq)\n", i);
-                       if (ata_ratelimit())
-                               dev_printk(KERN_WARNING, host->dev,
-                                       "interrupt on disabled port %u\n", i);
-               }
+       /* Generic, PCI class code for AHCI */
+       { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
+         PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
 
-               handled = 1;
-       }
+       { }     /* terminate list */
+};
 
-       /* HOST_IRQ_STAT behaves as level triggered latch meaning that
-        * it should be cleared after all the port events are cleared;
-        * otherwise, it will raise a spurious interrupt after each
-        * valid one.  Please read section 10.6.2 of ahci 1.1 for more
-        * information.
-        *
-        * Also, use the unmasked value to clear interrupt as spurious
-        * pending event on a dummy port might cause screaming IRQ.
-        */
-       writel(irq_stat, mmio + HOST_IRQ_STAT);
 
-       spin_unlock(&host->lock);
+static struct pci_driver ahci_pci_driver = {
+       .name                   = DRV_NAME,
+       .id_table               = ahci_pci_tbl,
+       .probe                  = ahci_init_one,
+       .remove                 = ata_pci_remove_one,
+#ifdef CONFIG_PM
+       .suspend                = ahci_pci_device_suspend,
+       .resume                 = ahci_pci_device_resume,
+#endif
+};
 
-       VPRINTK("EXIT\n");
+#if defined(CONFIG_PATA_MARVELL) || defined(CONFIG_PATA_MARVELL_MODULE)
+static int marvell_enable;
+#else
+static int marvell_enable = 1;
+#endif
+module_param(marvell_enable, int, 0644);
+MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
 
-       return IRQ_RETVAL(handled);
-}
 
-static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
+static void ahci_pci_save_initial_config(struct pci_dev *pdev,
+                                        struct ahci_host_priv *hpriv)
 {
-       struct ata_port *ap = qc->ap;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ahci_port_priv *pp = ap->private_data;
-
-       /* Keep track of the currently active link.  It will be used
-        * in completion path to determine whether NCQ phase is in
-        * progress.
-        */
-       pp->active_link = qc->dev->link;
-
-       if (qc->tf.protocol == ATA_PROT_NCQ)
-               writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
+       unsigned int force_port_map = 0;
+       unsigned int mask_port_map = 0;
 
-       if (pp->fbs_enabled && pp->fbs_last_dev != qc->dev->link->pmp) {
-               u32 fbs = readl(port_mmio + PORT_FBS);
-               fbs &= ~(PORT_FBS_DEV_MASK | PORT_FBS_DEC);
-               fbs |= qc->dev->link->pmp << PORT_FBS_DEV_OFFSET;
-               writel(fbs, port_mmio + PORT_FBS);
-               pp->fbs_last_dev = qc->dev->link->pmp;
+       if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
+               dev_info(&pdev->dev, "JMB361 has only one port\n");
+               force_port_map = 1;
        }
 
-       writel(1 << qc->tag, port_mmio + PORT_CMD_ISSUE);
-
-       ahci_sw_activity(qc->dev->link);
+       /*
+        * Temporary Marvell 6145 hack: PATA port presence
+        * is asserted through the standard AHCI port
+        * presence register, as bit 4 (counting from 0)
+        */
+       if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
+               if (pdev->device == 0x6121)
+                       mask_port_map = 0x3;
+               else
+                       mask_port_map = 0xf;
+               dev_info(&pdev->dev,
+                         "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
+       }
 
-       return 0;
+       ahci_save_initial_config(&pdev->dev, hpriv, force_port_map,
+                                mask_port_map);
 }
 
-static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc)
+static int ahci_pci_reset_controller(struct ata_host *host)
 {
-       struct ahci_port_priv *pp = qc->ap->private_data;
-       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
+       struct pci_dev *pdev = to_pci_dev(host->dev);
 
-       if (pp->fbs_enabled)
-               d2h_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ;
+       ahci_reset_controller(host);
 
-       ata_tf_from_fis(d2h_fis, &qc->result_tf);
-       return true;
-}
+       if (pdev->vendor == PCI_VENDOR_ID_INTEL) {
+               struct ahci_host_priv *hpriv = host->private_data;
+               u16 tmp16;
 
-static void ahci_freeze(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
+               /* configure PCS */
+               pci_read_config_word(pdev, 0x92, &tmp16);
+               if ((tmp16 & hpriv->port_map) != hpriv->port_map) {
+                       tmp16 |= hpriv->port_map;
+                       pci_write_config_word(pdev, 0x92, tmp16);
+               }
+       }
 
-       /* turn IRQ off */
-       writel(0, port_mmio + PORT_IRQ_MASK);
+       return 0;
 }
 
-static void ahci_thaw(struct ata_port *ap)
+static void ahci_pci_init_controller(struct ata_host *host)
 {
-       void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
-       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_host_priv *hpriv = host->private_data;
+       struct pci_dev *pdev = to_pci_dev(host->dev);
+       void __iomem *port_mmio;
        u32 tmp;
-       struct ahci_port_priv *pp = ap->private_data;
+       int mv;
 
-       /* clear IRQ */
-       tmp = readl(port_mmio + PORT_IRQ_STAT);
-       writel(tmp, port_mmio + PORT_IRQ_STAT);
-       writel(1 << ap->port_no, mmio + HOST_IRQ_STAT);
+       if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
+               if (pdev->device == 0x6121)
+                       mv = 2;
+               else
+                       mv = 4;
+               port_mmio = __ahci_port_base(host, mv);
 
-       /* turn IRQ back on */
-       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
-}
+               writel(0, port_mmio + PORT_IRQ_MASK);
 
-static void ahci_error_handler(struct ata_port *ap)
-{
-       if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
-               /* restart engine */
-               ahci_stop_engine(ap);
-               ahci_start_engine(ap);
+               /* clear port IRQ */
+               tmp = readl(port_mmio + PORT_IRQ_STAT);
+               VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
+               if (tmp)
+                       writel(tmp, port_mmio + PORT_IRQ_STAT);
        }
 
-       sata_pmp_error_handler(ap);
+       ahci_init_controller(host);
 }
 
-static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
+static int ahci_sb600_check_ready(struct ata_link *link)
 {
-       struct ata_port *ap = qc->ap;
+       void __iomem *port_mmio = ahci_port_base(link->ap);
+       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
+       u32 irq_status = readl(port_mmio + PORT_IRQ_STAT);
 
-       /* make DMA engine forget about the failed command */
-       if (qc->flags & ATA_QCFLAG_FAILED)
-               ahci_kick_engine(ap);
+       /*
+        * There is no need to check TFDATA if BAD PMP is found due to HW bug,
+        * which can save timeout delay.
+        */
+       if (irq_status & PORT_IRQ_BAD_PMP)
+               return -EIO;
+
+       return ata_check_ready(status);
 }
 
-static void ahci_enable_fbs(struct ata_port *ap)
+static int ahci_sb600_softreset(struct ata_link *link, unsigned int *class,
+                               unsigned long deadline)
 {
-       struct ahci_port_priv *pp = ap->private_data;
+       struct ata_port *ap = link->ap;
        void __iomem *port_mmio = ahci_port_base(ap);
-       u32 fbs;
+       int pmp = sata_srst_pmp(link);
        int rc;
+       u32 irq_sts;
 
-       if (!pp->fbs_supported)
-               return;
-
-       fbs = readl(port_mmio + PORT_FBS);
-       if (fbs & PORT_FBS_EN) {
-               pp->fbs_enabled = true;
-               pp->fbs_last_dev = -1; /* initialization */
-               return;
-       }
+       DPRINTK("ENTER\n");
 
-       rc = ahci_stop_engine(ap);
-       if (rc)
-               return;
+       rc = ahci_do_softreset(link, class, pmp, deadline,
+                              ahci_sb600_check_ready);
 
-       writel(fbs | PORT_FBS_EN, port_mmio + PORT_FBS);
-       fbs = readl(port_mmio + PORT_FBS);
-       if (fbs & PORT_FBS_EN) {
-               dev_printk(KERN_INFO, ap->host->dev, "FBS is enabled.\n");
-               pp->fbs_enabled = true;
-               pp->fbs_last_dev = -1; /* initialization */
-       } else
-               dev_printk(KERN_ERR, ap->host->dev, "Failed to enable FBS\n");
+       /*
+        * Soft reset fails on some ATI chips with IPMS set when PMP
+        * is enabled but SATA HDD/ODD is connected to SATA port,
+        * do soft reset again to port 0.
+        */
+       if (rc == -EIO) {
+               irq_sts = readl(port_mmio + PORT_IRQ_STAT);
+               if (irq_sts & PORT_IRQ_BAD_PMP) {
+                       ata_link_printk(link, KERN_WARNING,
+                                       "applying SB600 PMP SRST workaround "
+                                       "and retrying\n");
+                       rc = ahci_do_softreset(link, class, 0, deadline,
+                                              ahci_check_ready);
+               }
+       }
 
-       ahci_start_engine(ap);
+       return rc;
 }
 
-static void ahci_disable_fbs(struct ata_port *ap)
+static int ahci_vt8251_hardreset(struct ata_link *link, unsigned int *class,
+                                unsigned long deadline)
 {
-       struct ahci_port_priv *pp = ap->private_data;
-       void __iomem *port_mmio = ahci_port_base(ap);
-       u32 fbs;
+       struct ata_port *ap = link->ap;
+       bool online;
        int rc;
 
-       if (!pp->fbs_supported)
-               return;
-
-       fbs = readl(port_mmio + PORT_FBS);
-       if ((fbs & PORT_FBS_EN) == 0) {
-               pp->fbs_enabled = false;
-               return;
-       }
+       DPRINTK("ENTER\n");
 
-       rc = ahci_stop_engine(ap);
-       if (rc)
-               return;
+       ahci_stop_engine(ap);
 
-       writel(fbs & ~PORT_FBS_EN, port_mmio + PORT_FBS);
-       fbs = readl(port_mmio + PORT_FBS);
-       if (fbs & PORT_FBS_EN)
-               dev_printk(KERN_ERR, ap->host->dev, "Failed to disable FBS\n");
-       else {
-               dev_printk(KERN_INFO, ap->host->dev, "FBS is disabled.\n");
-               pp->fbs_enabled = false;
-       }
+       rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
+                                deadline, &online, NULL);
 
        ahci_start_engine(ap);
-}
-
-static void ahci_pmp_attach(struct ata_port *ap)
-{
-       void __iomem *port_mmio = ahci_port_base(ap);
-       struct ahci_port_priv *pp = ap->private_data;
-       u32 cmd;
-
-       cmd = readl(port_mmio + PORT_CMD);
-       cmd |= PORT_CMD_PMP;
-       writel(cmd, port_mmio + PORT_CMD);
 
-       ahci_enable_fbs(ap);
+       DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
 
-       pp->intr_mask |= PORT_IRQ_BAD_PMP;
-       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+       /* vt8251 doesn't clear BSY on signature FIS reception,
+        * request follow-up softreset.
+        */
+       return online ? -EAGAIN : rc;
 }
 
-static void ahci_pmp_detach(struct ata_port *ap)
+static int ahci_p5wdh_hardreset(struct ata_link *link, unsigned int *class,
+                               unsigned long deadline)
 {
-       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ata_port *ap = link->ap;
        struct ahci_port_priv *pp = ap->private_data;
-       u32 cmd;
-
-       ahci_disable_fbs(ap);
-
-       cmd = readl(port_mmio + PORT_CMD);
-       cmd &= ~PORT_CMD_PMP;
-       writel(cmd, port_mmio + PORT_CMD);
-
-       pp->intr_mask &= ~PORT_IRQ_BAD_PMP;
-       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
-}
+       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
+       struct ata_taskfile tf;
+       bool online;
+       int rc;
 
-static int ahci_port_resume(struct ata_port *ap)
-{
-       ahci_power_up(ap);
-       ahci_start_port(ap);
+       ahci_stop_engine(ap);
 
-       if (sata_pmp_attached(ap))
-               ahci_pmp_attach(ap);
-       else
-               ahci_pmp_detach(ap);
+       /* clear D2H reception area to properly wait for D2H FIS */
+       ata_tf_init(link->device, &tf);
+       tf.command = 0x80;
+       ata_tf_to_fis(&tf, 0, 0, d2h_fis);
 
-       return 0;
-}
+       rc = sata_link_hardreset(link, sata_ehc_deb_timing(&link->eh_context),
+                                deadline, &online, NULL);
 
-#ifdef CONFIG_PM
-static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
-{
-       const char *emsg = NULL;
-       int rc;
+       ahci_start_engine(ap);
 
-       rc = ahci_deinit_port(ap, &emsg);
-       if (rc == 0)
-               ahci_power_down(ap);
-       else {
-               ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc);
-               ahci_start_port(ap);
+       /* The pseudo configuration device on SIMG4726 attached to
+        * ASUS P5W-DH Deluxe doesn't send signature FIS after
+        * hardreset if no device is attached to the first downstream
+        * port && the pseudo device locks up on SRST w/ PMP==0.  To
+        * work around this, wait for !BSY only briefly.  If BSY isn't
+        * cleared, perform CLO and proceed to IDENTIFY (achieved by
+        * ATA_LFLAG_NO_SRST and ATA_LFLAG_ASSUME_ATA).
+        *
+        * Wait for two seconds.  Devices attached to downstream port
+        * which can't process the following IDENTIFY after this will
+        * have to be reset again.  For most cases, this should
+        * suffice while making probing snappish enough.
+        */
+       if (online) {
+               rc = ata_wait_after_reset(link, jiffies + 2 * HZ,
+                                         ahci_check_ready);
+               if (rc)
+                       ahci_kick_engine(ap);
        }
-
        return rc;
 }
 
+#ifdef CONFIG_PM
 static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
        struct ata_host *host = dev_get_drvdata(&pdev->dev);
        struct ahci_host_priv *hpriv = host->private_data;
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
+       void __iomem *mmio = hpriv->mmio;
        u32 ctl;
 
        if (mesg.event & PM_EVENT_SUSPEND &&
@@ -2675,11 +627,11 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
                return rc;
 
        if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
-               rc = ahci_reset_controller(host);
+               rc = ahci_pci_reset_controller(host);
                if (rc)
                        return rc;
 
-               ahci_init_controller(host);
+               ahci_pci_init_controller(host);
        }
 
        ata_host_resume(host);
@@ -2688,92 +640,6 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
 }
 #endif
 
-static int ahci_port_start(struct ata_port *ap)
-{
-       struct ahci_host_priv *hpriv = ap->host->private_data;
-       struct device *dev = ap->host->dev;
-       struct ahci_port_priv *pp;
-       void *mem;
-       dma_addr_t mem_dma;
-       size_t dma_sz, rx_fis_sz;
-
-       pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
-       if (!pp)
-               return -ENOMEM;
-
-       /* check FBS capability */
-       if ((hpriv->cap & HOST_CAP_FBS) && sata_pmp_supported(ap)) {
-               void __iomem *port_mmio = ahci_port_base(ap);
-               u32 cmd = readl(port_mmio + PORT_CMD);
-               if (cmd & PORT_CMD_FBSCP)
-                       pp->fbs_supported = true;
-               else
-                       dev_printk(KERN_WARNING, dev,
-                                  "The port is not capable of FBS\n");
-       }
-
-       if (pp->fbs_supported) {
-               dma_sz = AHCI_PORT_PRIV_FBS_DMA_SZ;
-               rx_fis_sz = AHCI_RX_FIS_SZ * 16;
-       } else {
-               dma_sz = AHCI_PORT_PRIV_DMA_SZ;
-               rx_fis_sz = AHCI_RX_FIS_SZ;
-       }
-
-       mem = dmam_alloc_coherent(dev, dma_sz, &mem_dma, GFP_KERNEL);
-       if (!mem)
-               return -ENOMEM;
-       memset(mem, 0, dma_sz);
-
-       /*
-        * First item in chunk of DMA memory: 32-slot command table,
-        * 32 bytes each in size
-        */
-       pp->cmd_slot = mem;
-       pp->cmd_slot_dma = mem_dma;
-
-       mem += AHCI_CMD_SLOT_SZ;
-       mem_dma += AHCI_CMD_SLOT_SZ;
-
-       /*
-        * Second item: Received-FIS area
-        */
-       pp->rx_fis = mem;
-       pp->rx_fis_dma = mem_dma;
-
-       mem += rx_fis_sz;
-       mem_dma += rx_fis_sz;
-
-       /*
-        * Third item: data area for storing a single command
-        * and its scatter-gather table
-        */
-       pp->cmd_tbl = mem;
-       pp->cmd_tbl_dma = mem_dma;
-
-       /*
-        * Save off initial list of interrupts to be enabled.
-        * This could be changed later
-        */
-       pp->intr_mask = DEF_PORT_IRQ;
-
-       ap->private_data = pp;
-
-       /* engage engines, captain */
-       return ahci_port_resume(ap);
-}
-
-static void ahci_port_stop(struct ata_port *ap)
-{
-       const char *emsg = NULL;
-       int rc;
-
-       /* de-initialize port */
-       rc = ahci_deinit_port(ap, &emsg);
-       if (rc)
-               ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
-}
-
 static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
 {
        int rc;
@@ -2806,31 +672,12 @@ static int ahci_configure_dma_masks(struct pci_dev *pdev, int using_dac)
        return 0;
 }
 
-static void ahci_print_info(struct ata_host *host)
+static void ahci_pci_print_info(struct ata_host *host)
 {
-       struct ahci_host_priv *hpriv = host->private_data;
        struct pci_dev *pdev = to_pci_dev(host->dev);
-       void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
-       u32 vers, cap, cap2, impl, speed;
-       const char *speed_s;
        u16 cc;
        const char *scc_s;
 
-       vers = readl(mmio + HOST_VERSION);
-       cap = hpriv->cap;
-       cap2 = hpriv->cap2;
-       impl = hpriv->port_map;
-
-       speed = (cap >> 20) & 0xf;
-       if (speed == 1)
-               speed_s = "1.5";
-       else if (speed == 2)
-               speed_s = "3";
-       else if (speed == 3)
-               speed_s = "6";
-       else
-               speed_s = "?";
-
        pci_read_config_word(pdev, 0x0a, &cc);
        if (cc == PCI_CLASS_STORAGE_IDE)
                scc_s = "IDE";
@@ -2841,50 +688,7 @@ static void ahci_print_info(struct ata_host *host)
        else
                scc_s = "unknown";
 
-       dev_printk(KERN_INFO, &pdev->dev,
-               "AHCI %02x%02x.%02x%02x "
-               "%u slots %u ports %s Gbps 0x%x impl %s mode\n"
-               ,
-
-               (vers >> 24) & 0xff,
-               (vers >> 16) & 0xff,
-               (vers >> 8) & 0xff,
-               vers & 0xff,
-
-               ((cap >> 8) & 0x1f) + 1,
-               (cap & 0x1f) + 1,
-               speed_s,
-               impl,
-               scc_s);
-
-       dev_printk(KERN_INFO, &pdev->dev,
-               "flags: "
-               "%s%s%s%s%s%s%s"
-               "%s%s%s%s%s%s%s"
-               "%s%s%s%s%s%s\n"
-               ,
-
-               cap & HOST_CAP_64 ? "64bit " : "",
-               cap & HOST_CAP_NCQ ? "ncq " : "",
-               cap & HOST_CAP_SNTF ? "sntf " : "",
-               cap & HOST_CAP_MPS ? "ilck " : "",
-               cap & HOST_CAP_SSS ? "stag " : "",
-               cap & HOST_CAP_ALPM ? "pm " : "",
-               cap & HOST_CAP_LED ? "led " : "",
-               cap & HOST_CAP_CLO ? "clo " : "",
-               cap & HOST_CAP_ONLY ? "only " : "",
-               cap & HOST_CAP_PMP ? "pmp " : "",
-               cap & HOST_CAP_FBS ? "fbs " : "",
-               cap & HOST_CAP_PIO_MULTI ? "pio " : "",
-               cap & HOST_CAP_SSC ? "slum " : "",
-               cap & HOST_CAP_PART ? "part " : "",
-               cap & HOST_CAP_CCC ? "ccc " : "",
-               cap & HOST_CAP_EMS ? "ems " : "",
-               cap & HOST_CAP_SXS ? "sxs " : "",
-               cap2 & HOST_CAP2_APST ? "apst " : "",
-               cap2 & HOST_CAP2_NVMHCI ? "nvmp " : "",
-               cap2 & HOST_CAP2_BOH ? "boh " : ""
-               );
+       ahci_print_info(host, scc_s);
 }
 
 /* On ASUS P5W DH Deluxe, the second port of PCI device 00:1f.2 is
@@ -3308,41 +1112,28 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev))
                pci_intx(pdev, 1);
 
+       hpriv->mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
+
        /* save initial config */
-       ahci_save_initial_config(pdev, hpriv);
+       ahci_pci_save_initial_config(pdev, hpriv);
 
        /* prepare host */
        if (hpriv->cap & HOST_CAP_NCQ) {
                pi.flags |= ATA_FLAG_NCQ;
-               /* Auto-activate optimization is supposed to be supported on
-                  all AHCI controllers indicating NCQ support, but it seems
-                  to be broken at least on some NVIDIA MCP79 chipsets.
-                  Until we get info on which NVIDIA chipsets don't have this
-                  issue, if any, disable AA on all NVIDIA AHCIs. */
-               if (pdev->vendor != PCI_VENDOR_ID_NVIDIA)
+               /*
+                * Auto-activate optimization is supposed to be
+                * supported on all AHCI controllers indicating NCQ
+                * capability, but it seems to be broken on some
+                * chipsets including NVIDIAs.
+                */
+               if (!(hpriv->flags & AHCI_HFLAG_NO_FPDMA_AA))
                        pi.flags |= ATA_FLAG_FPDMA_AA;
        }
 
        if (hpriv->cap & HOST_CAP_PMP)
                pi.flags |= ATA_FLAG_PMP;
 
-       if (ahci_em_messages && (hpriv->cap & HOST_CAP_EMS)) {
-               u8 messages;
-               void __iomem *mmio = pcim_iomap_table(pdev)[AHCI_PCI_BAR];
-               u32 em_loc = readl(mmio + HOST_EM_LOC);
-               u32 em_ctl = readl(mmio + HOST_EM_CTL);
-
-               messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
-
-               /* we only support LED message type right now */
-               if ((messages & 0x01) && (ahci_em_messages == 1)) {
-                       /* store em_loc */
-                       hpriv->em_loc = ((em_loc >> 16) * 4);
-                       pi.flags |= ATA_FLAG_EM;
-                       if (!(em_ctl & EM_CTL_ALHD))
-                               pi.flags |= ATA_FLAG_SW_ACTIVITY;
-               }
-       }
+       ahci_set_em_messages(hpriv, &pi);
 
        if (ahci_broken_system_poweroff(pdev)) {
                pi.flags |= ATA_FLAG_NO_POWEROFF_SPINDOWN;
@@ -3372,7 +1163,6 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
        if (!host)
                return -ENOMEM;
-       host->iomap = pcim_iomap_table(pdev);
        host->private_data = hpriv;
 
        if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
@@ -3395,7 +1185,7 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
                /* set enclosure management message type */
                if (ap->flags & ATA_FLAG_EM)
-                       ap->em_message_type = ahci_em_messages;
+                       ap->em_message_type = hpriv->em_msg_type;
 
 
                /* disabled/not-implemented port */
@@ -3414,12 +1204,12 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc)
                return rc;
 
-       rc = ahci_reset_controller(host);
+       rc = ahci_pci_reset_controller(host);
        if (rc)
                return rc;
 
-       ahci_init_controller(host);
-       ahci_print_info(host);
+       ahci_pci_init_controller(host);
+       ahci_pci_print_info(host);
 
        pci_set_master(pdev);
        return ata_host_activate(host, pdev->irq, ahci_interrupt, IRQF_SHARED,
diff --git a/drivers/ata/ahci.h b/drivers/ata/ahci.h
new file mode 100644 (file)
index 0000000..7113c57
--- /dev/null
@@ -0,0 +1,343 @@
+/*
+ *  ahci.h - Common AHCI SATA definitions and declarations
+ *
+ *  Maintained by:  Jeff Garzik <jgarzik@pobox.com>
+ *                 Please ALWAYS copy linux-ide@vger.kernel.org
+ *                 on emails.
+ *
+ *  Copyright 2004-2005 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; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * libata documentation is available via 'make {ps|pdf}docs',
+ * as Documentation/DocBook/libata.*
+ *
+ * AHCI hardware documentation:
+ * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf
+ * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf
+ *
+ */
+
+#ifndef _AHCI_H
+#define _AHCI_H
+
+#include <linux/libata.h>
+
+/* Enclosure Management Control */
+#define EM_CTRL_MSG_TYPE              0x000f0000
+
+/* Enclosure Management LED Message Type */
+#define EM_MSG_LED_HBA_PORT           0x0000000f
+#define EM_MSG_LED_PMP_SLOT           0x0000ff00
+#define EM_MSG_LED_VALUE              0xffff0000
+#define EM_MSG_LED_VALUE_ACTIVITY     0x00070000
+#define EM_MSG_LED_VALUE_OFF          0xfff80000
+#define EM_MSG_LED_VALUE_ON           0x00010000
+
+enum {
+       AHCI_MAX_PORTS          = 32,
+       AHCI_MAX_SG             = 168, /* hardware max is 64K */
+       AHCI_DMA_BOUNDARY       = 0xffffffff,
+       AHCI_MAX_CMDS           = 32,
+       AHCI_CMD_SZ             = 32,
+       AHCI_CMD_SLOT_SZ        = AHCI_MAX_CMDS * AHCI_CMD_SZ,
+       AHCI_RX_FIS_SZ          = 256,
+       AHCI_CMD_TBL_CDB        = 0x40,
+       AHCI_CMD_TBL_HDR_SZ     = 0x80,
+       AHCI_CMD_TBL_SZ         = AHCI_CMD_TBL_HDR_SZ + (AHCI_MAX_SG * 16),
+       AHCI_CMD_TBL_AR_SZ      = AHCI_CMD_TBL_SZ * AHCI_MAX_CMDS,
+       AHCI_PORT_PRIV_DMA_SZ   = AHCI_CMD_SLOT_SZ + AHCI_CMD_TBL_AR_SZ +
+                                 AHCI_RX_FIS_SZ,
+       AHCI_PORT_PRIV_FBS_DMA_SZ       = AHCI_CMD_SLOT_SZ +
+                                         AHCI_CMD_TBL_AR_SZ +
+                                         (AHCI_RX_FIS_SZ * 16),
+       AHCI_IRQ_ON_SG          = (1 << 31),
+       AHCI_CMD_ATAPI          = (1 << 5),
+       AHCI_CMD_WRITE          = (1 << 6),
+       AHCI_CMD_PREFETCH       = (1 << 7),
+       AHCI_CMD_RESET          = (1 << 8),
+       AHCI_CMD_CLR_BUSY       = (1 << 10),
+
+       RX_FIS_D2H_REG          = 0x40, /* offset of D2H Register FIS data */
+       RX_FIS_SDB              = 0x58, /* offset of SDB FIS data */
+       RX_FIS_UNK              = 0x60, /* offset of Unknown FIS data */
+
+       /* global controller registers */
+       HOST_CAP                = 0x00, /* host capabilities */
+       HOST_CTL                = 0x04, /* global host control */
+       HOST_IRQ_STAT           = 0x08, /* interrupt status */
+       HOST_PORTS_IMPL         = 0x0c, /* bitmap of implemented ports */
+       HOST_VERSION            = 0x10, /* AHCI spec. version compliancy */
+       HOST_EM_LOC             = 0x1c, /* Enclosure Management location */
+       HOST_EM_CTL             = 0x20, /* Enclosure Management Control */
+       HOST_CAP2               = 0x24, /* host capabilities, extended */
+
+       /* HOST_CTL bits */
+       HOST_RESET              = (1 << 0),  /* reset controller; self-clear */
+       HOST_IRQ_EN             = (1 << 1),  /* global IRQ enable */
+       HOST_AHCI_EN            = (1 << 31), /* AHCI enabled */
+
+       /* HOST_CAP bits */
+       HOST_CAP_SXS            = (1 << 5),  /* Supports External SATA */
+       HOST_CAP_EMS            = (1 << 6),  /* Enclosure Management support */
+       HOST_CAP_CCC            = (1 << 7),  /* Command Completion Coalescing */
+       HOST_CAP_PART           = (1 << 13), /* Partial state capable */
+       HOST_CAP_SSC            = (1 << 14), /* Slumber state capable */
+       HOST_CAP_PIO_MULTI      = (1 << 15), /* PIO multiple DRQ support */
+       HOST_CAP_FBS            = (1 << 16), /* FIS-based switching support */
+       HOST_CAP_PMP            = (1 << 17), /* Port Multiplier support */
+       HOST_CAP_ONLY           = (1 << 18), /* Supports AHCI mode only */
+       HOST_CAP_CLO            = (1 << 24), /* Command List Override support */
+       HOST_CAP_LED            = (1 << 25), /* Supports activity LED */
+       HOST_CAP_ALPM           = (1 << 26), /* Aggressive Link PM support */
+       HOST_CAP_SSS            = (1 << 27), /* Staggered Spin-up */
+       HOST_CAP_MPS            = (1 << 28), /* Mechanical presence switch */
+       HOST_CAP_SNTF           = (1 << 29), /* SNotification register */
+       HOST_CAP_NCQ            = (1 << 30), /* Native Command Queueing */
+       HOST_CAP_64             = (1 << 31), /* PCI DAC (64-bit DMA) support */
+
+       /* HOST_CAP2 bits */
+       HOST_CAP2_BOH           = (1 << 0),  /* BIOS/OS handoff supported */
+       HOST_CAP2_NVMHCI        = (1 << 1),  /* NVMHCI supported */
+       HOST_CAP2_APST          = (1 << 2),  /* Automatic partial to slumber */
+
+       /* registers for each SATA port */
+       PORT_LST_ADDR           = 0x00, /* command list DMA addr */
+       PORT_LST_ADDR_HI        = 0x04, /* command list DMA addr hi */
+       PORT_FIS_ADDR           = 0x08, /* FIS rx buf addr */
+       PORT_FIS_ADDR_HI        = 0x0c, /* FIS rx buf addr hi */
+       PORT_IRQ_STAT           = 0x10, /* interrupt status */
+       PORT_IRQ_MASK           = 0x14, /* interrupt enable/disable mask */
+       PORT_CMD                = 0x18, /* port command */
+       PORT_TFDATA             = 0x20, /* taskfile data */
+       PORT_SIG                = 0x24, /* device TF signature */
+       PORT_CMD_ISSUE          = 0x38, /* command issue */
+       PORT_SCR_STAT           = 0x28, /* SATA phy register: SStatus */
+       PORT_SCR_CTL            = 0x2c, /* SATA phy register: SControl */
+       PORT_SCR_ERR            = 0x30, /* SATA phy register: SError */
+       PORT_SCR_ACT            = 0x34, /* SATA phy register: SActive */
+       PORT_SCR_NTF            = 0x3c, /* SATA phy register: SNotification */
+       PORT_FBS                = 0x40, /* FIS-based Switching */
+
+       /* PORT_IRQ_{STAT,MASK} bits */
+       PORT_IRQ_COLD_PRES      = (1 << 31), /* cold presence detect */
+       PORT_IRQ_TF_ERR         = (1 << 30), /* task file error */
+       PORT_IRQ_HBUS_ERR       = (1 << 29), /* host bus fatal error */
+       PORT_IRQ_HBUS_DATA_ERR  = (1 << 28), /* host bus data error */
+       PORT_IRQ_IF_ERR         = (1 << 27), /* interface fatal error */
+       PORT_IRQ_IF_NONFATAL    = (1 << 26), /* interface non-fatal error */
+       PORT_IRQ_OVERFLOW       = (1 << 24), /* xfer exhausted available S/G */
+       PORT_IRQ_BAD_PMP        = (1 << 23), /* incorrect port multiplier */
+
+       PORT_IRQ_PHYRDY         = (1 << 22), /* PhyRdy changed */
+       PORT_IRQ_DEV_ILCK       = (1 << 7), /* device interlock */
+       PORT_IRQ_CONNECT        = (1 << 6), /* port connect change status */
+       PORT_IRQ_SG_DONE        = (1 << 5), /* descriptor processed */
+       PORT_IRQ_UNK_FIS        = (1 << 4), /* unknown FIS rx'd */
+       PORT_IRQ_SDB_FIS        = (1 << 3), /* Set Device Bits FIS rx'd */
+       PORT_IRQ_DMAS_FIS       = (1 << 2), /* DMA Setup FIS rx'd */
+       PORT_IRQ_PIOS_FIS       = (1 << 1), /* PIO Setup FIS rx'd */
+       PORT_IRQ_D2H_REG_FIS    = (1 << 0), /* D2H Register FIS rx'd */
+
+       PORT_IRQ_FREEZE         = PORT_IRQ_HBUS_ERR |
+                                 PORT_IRQ_IF_ERR |
+                                 PORT_IRQ_CONNECT |
+                                 PORT_IRQ_PHYRDY |
+                                 PORT_IRQ_UNK_FIS |
+                                 PORT_IRQ_BAD_PMP,
+       PORT_IRQ_ERROR          = PORT_IRQ_FREEZE |
+                                 PORT_IRQ_TF_ERR |
+                                 PORT_IRQ_HBUS_DATA_ERR,
+       DEF_PORT_IRQ            = PORT_IRQ_ERROR | PORT_IRQ_SG_DONE |
+                                 PORT_IRQ_SDB_FIS | PORT_IRQ_DMAS_FIS |
+                                 PORT_IRQ_PIOS_FIS | PORT_IRQ_D2H_REG_FIS,
+
+       /* PORT_CMD bits */
+       PORT_CMD_ASP            = (1 << 27), /* Aggressive Slumber/Partial */
+       PORT_CMD_ALPE           = (1 << 26), /* Aggressive Link PM enable */
+       PORT_CMD_ATAPI          = (1 << 24), /* Device is ATAPI */
+       PORT_CMD_FBSCP          = (1 << 22), /* FBS Capable Port */
+       PORT_CMD_PMP            = (1 << 17), /* PMP attached */
+       PORT_CMD_LIST_ON        = (1 << 15), /* cmd list DMA engine running */
+       PORT_CMD_FIS_ON         = (1 << 14), /* FIS DMA engine running */
+       PORT_CMD_FIS_RX         = (1 << 4), /* Enable FIS receive DMA engine */
+       PORT_CMD_CLO            = (1 << 3), /* Command list override */
+       PORT_CMD_POWER_ON       = (1 << 2), /* Power up device */
+       PORT_CMD_SPIN_UP        = (1 << 1), /* Spin up device */
+       PORT_CMD_START          = (1 << 0), /* Enable port DMA engine */
+
+       PORT_CMD_ICC_MASK       = (0xf << 28), /* i/f ICC state mask */
+       PORT_CMD_ICC_ACTIVE     = (0x1 << 28), /* Put i/f in active state */
+       PORT_CMD_ICC_PARTIAL    = (0x2 << 28), /* Put i/f in partial state */
+       PORT_CMD_ICC_SLUMBER    = (0x6 << 28), /* Put i/f in slumber state */
+
+       PORT_FBS_DWE_OFFSET     = 16, /* FBS device with error offset */
+       PORT_FBS_ADO_OFFSET     = 12, /* FBS active dev optimization offset */
+       PORT_FBS_DEV_OFFSET     = 8,  /* FBS device to issue offset */
+       PORT_FBS_DEV_MASK       = (0xf << PORT_FBS_DEV_OFFSET),  /* FBS.DEV */
+       PORT_FBS_SDE            = (1 << 2), /* FBS single device error */
+       PORT_FBS_DEC            = (1 << 1), /* FBS device error clear */
+       PORT_FBS_EN             = (1 << 0), /* Enable FBS */
+
+       /* hpriv->flags bits */
+       AHCI_HFLAG_NO_NCQ               = (1 << 0),
+       AHCI_HFLAG_IGN_IRQ_IF_ERR       = (1 << 1), /* ignore IRQ_IF_ERR */
+       AHCI_HFLAG_IGN_SERR_INTERNAL    = (1 << 2), /* ignore SERR_INTERNAL */
+       AHCI_HFLAG_32BIT_ONLY           = (1 << 3), /* force 32bit */
+       AHCI_HFLAG_MV_PATA              = (1 << 4), /* PATA port */
+       AHCI_HFLAG_NO_MSI               = (1 << 5), /* no PCI MSI */
+       AHCI_HFLAG_NO_PMP               = (1 << 6), /* no PMP */
+       AHCI_HFLAG_NO_HOTPLUG           = (1 << 7), /* ignore PxSERR.DIAG.N */
+       AHCI_HFLAG_SECT255              = (1 << 8), /* max 255 sectors */
+       AHCI_HFLAG_YES_NCQ              = (1 << 9), /* force NCQ cap on */
+       AHCI_HFLAG_NO_SUSPEND           = (1 << 10), /* don't suspend */
+       AHCI_HFLAG_SRST_TOUT_IS_OFFLINE = (1 << 11), /* treat SRST timeout as
+                                                       link offline */
+       AHCI_HFLAG_NO_SNTF              = (1 << 12), /* no sntf */
+       AHCI_HFLAG_NO_FPDMA_AA          = (1 << 13), /* no FPDMA AA */
+
+       /* ap->flags bits */
+
+       AHCI_FLAG_COMMON                = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
+                                         ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
+                                         ATA_FLAG_ACPI_SATA | ATA_FLAG_AN |
+                                         ATA_FLAG_IPM,
+
+       ICH_MAP                         = 0x90, /* ICH MAP register */
+
+       /* em constants */
+       EM_MAX_SLOTS                    = 8,
+       EM_MAX_RETRY                    = 5,
+
+       /* em_ctl bits */
+       EM_CTL_RST              = (1 << 9), /* Reset */
+       EM_CTL_TM               = (1 << 8), /* Transmit Message */
+       EM_CTL_MR               = (1 << 0), /* Message Recieved */
+       EM_CTL_ALHD             = (1 << 26), /* Activity LED */
+       EM_CTL_XMT              = (1 << 25), /* Transmit Only */
+       EM_CTL_SMB              = (1 << 24), /* Single Message Buffer */
+
+       /* em message type */
+       EM_MSG_TYPE_LED         = (1 << 0), /* LED */
+       EM_MSG_TYPE_SAFTE       = (1 << 1), /* SAF-TE */
+       EM_MSG_TYPE_SES2        = (1 << 2), /* SES-2 */
+       EM_MSG_TYPE_SGPIO       = (1 << 3), /* SGPIO */
+};
+
+struct ahci_cmd_hdr {
+       __le32                  opts;
+       __le32                  status;
+       __le32                  tbl_addr;
+       __le32                  tbl_addr_hi;
+       __le32                  reserved[4];
+};
+
+struct ahci_sg {
+       __le32                  addr;
+       __le32                  addr_hi;
+       __le32                  reserved;
+       __le32                  flags_size;
+};
+
+struct ahci_em_priv {
+       enum sw_activity blink_policy;
+       struct timer_list timer;
+       unsigned long saved_activity;
+       unsigned long activity;
+       unsigned long led_state;
+};
+
+struct ahci_port_priv {
+       struct ata_link         *active_link;
+       struct ahci_cmd_hdr     *cmd_slot;
+       dma_addr_t              cmd_slot_dma;
+       void                    *cmd_tbl;
+       dma_addr_t              cmd_tbl_dma;
+       void                    *rx_fis;
+       dma_addr_t              rx_fis_dma;
+       /* for NCQ spurious interrupt analysis */
+       unsigned int            ncq_saw_d2h:1;
+       unsigned int            ncq_saw_dmas:1;
+       unsigned int            ncq_saw_sdb:1;
+       u32                     intr_mask;      /* interrupts to enable */
+       bool                    fbs_supported;  /* set iff FBS is supported */
+       bool                    fbs_enabled;    /* set iff FBS is enabled */
+       int                     fbs_last_dev;   /* save FBS.DEV of last FIS */
+       /* enclosure management info per PM slot */
+       struct ahci_em_priv     em_priv[EM_MAX_SLOTS];
+};
+
+struct ahci_host_priv {
+       void __iomem *          mmio;           /* bus-independant mem map */
+       unsigned int            flags;          /* AHCI_HFLAG_* */
+       u32                     cap;            /* cap to use */
+       u32                     cap2;           /* cap2 to use */
+       u32                     port_map;       /* port map to use */
+       u32                     saved_cap;      /* saved initial cap */
+       u32                     saved_cap2;     /* saved initial cap2 */
+       u32                     saved_port_map; /* saved initial port_map */
+       u32                     em_loc; /* enclosure management location */
+       u32                     em_buf_sz;      /* EM buffer size in byte */
+       u32                     em_msg_type;    /* EM message type */
+};
+
+extern int ahci_ignore_sss;
+
+extern struct scsi_host_template ahci_sht;
+extern struct ata_port_operations ahci_ops;
+
+void ahci_save_initial_config(struct device *dev,
+                             struct ahci_host_priv *hpriv,
+                             unsigned int force_port_map,
+                             unsigned int mask_port_map);
+void ahci_init_controller(struct ata_host *host);
+int ahci_reset_controller(struct ata_host *host);
+
+int ahci_do_softreset(struct ata_link *link, unsigned int *class,
+                     int pmp, unsigned long deadline,
+                     int (*check_ready)(struct ata_link *link));
+
+int ahci_stop_engine(struct ata_port *ap);
+void ahci_start_engine(struct ata_port *ap);
+int ahci_check_ready(struct ata_link *link);
+int ahci_kick_engine(struct ata_port *ap);
+void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+                         struct ata_port_info *pi);
+int ahci_reset_em(struct ata_host *host);
+irqreturn_t ahci_interrupt(int irq, void *dev_instance);
+void ahci_print_info(struct ata_host *host, const char *scc_s);
+
+static inline void __iomem *__ahci_port_base(struct ata_host *host,
+                                            unsigned int port_no)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+
+       return mmio + 0x100 + (port_no * 0x80);
+}
+
+static inline void __iomem *ahci_port_base(struct ata_port *ap)
+{
+       return __ahci_port_base(ap->host, ap->port_no);
+}
+
+static inline int ahci_nr_ports(u32 cap)
+{
+       return (cap & 0x1f) + 1;
+}
+
+#endif /* _AHCI_H */
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
new file mode 100644 (file)
index 0000000..5e11b16
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * AHCI SATA platform driver
+ *
+ * Copyright 2004-2005  Red Hat, Inc.
+ *   Jeff Garzik <jgarzik@pobox.com>
+ * Copyright 2010  MontaVista Software, LLC.
+ *   Anton Vorontsov <avorontsov@ru.mvista.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, or (at your option)
+ * any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/gfp.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/libata.h>
+#include <linux/ahci_platform.h>
+#include "ahci.h"
+
+static int __init ahci_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct ahci_platform_data *pdata = dev->platform_data;
+       struct ata_port_info pi = {
+               .flags          = AHCI_FLAG_COMMON,
+               .pio_mask       = ATA_PIO4,
+               .udma_mask      = ATA_UDMA6,
+               .port_ops       = &ahci_ops,
+       };
+       const struct ata_port_info *ppi[] = { &pi, NULL };
+       struct ahci_host_priv *hpriv;
+       struct ata_host *host;
+       struct resource *mem;
+       int irq;
+       int n_ports;
+       int i;
+       int rc;
+
+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!mem) {
+               dev_err(dev, "no mmio space\n");
+               return -EINVAL;
+       }
+
+       irq = platform_get_irq(pdev, 0);
+       if (irq <= 0) {
+               dev_err(dev, "no irq\n");
+               return -EINVAL;
+       }
+
+       if (pdata && pdata->init) {
+               rc = pdata->init(dev);
+               if (rc)
+                       return rc;
+       }
+
+       if (pdata && pdata->ata_port_info)
+               pi = *pdata->ata_port_info;
+
+       hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
+       if (!hpriv) {
+               rc = -ENOMEM;
+               goto err0;
+       }
+
+       hpriv->flags |= (unsigned long)pi.private_data;
+
+       hpriv->mmio = devm_ioremap(dev, mem->start, resource_size(mem));
+       if (!hpriv->mmio) {
+               dev_err(dev, "can't map %pR\n", mem);
+               rc = -ENOMEM;
+               goto err0;
+       }
+
+       ahci_save_initial_config(dev, hpriv,
+               pdata ? pdata->force_port_map : 0,
+               pdata ? pdata->mask_port_map  : 0);
+
+       /* prepare host */
+       if (hpriv->cap & HOST_CAP_NCQ)
+               pi.flags |= ATA_FLAG_NCQ;
+
+       if (hpriv->cap & HOST_CAP_PMP)
+               pi.flags |= ATA_FLAG_PMP;
+
+       ahci_set_em_messages(hpriv, &pi);
+
+       /* CAP.NP sometimes indicate the index of the last enabled
+        * port, at other times, that of the last possible port, so
+        * determining the maximum port number requires looking at
+        * both CAP.NP and port_map.
+        */
+       n_ports = max(ahci_nr_ports(hpriv->cap), fls(hpriv->port_map));
+
+       host = ata_host_alloc_pinfo(dev, ppi, n_ports);
+       if (!host) {
+               rc = -ENOMEM;
+               goto err0;
+       }
+
+       host->private_data = hpriv;
+
+       if (!(hpriv->cap & HOST_CAP_SSS) || ahci_ignore_sss)
+               host->flags |= ATA_HOST_PARALLEL_SCAN;
+       else
+               printk(KERN_INFO "ahci: SSS flag set, parallel bus scan disabled\n");
+
+       if (pi.flags & ATA_FLAG_EM)
+               ahci_reset_em(host);
+
+       for (i = 0; i < host->n_ports; i++) {
+               struct ata_port *ap = host->ports[i];
+
+               ata_port_desc(ap, "mmio %pR", mem);
+               ata_port_desc(ap, "port 0x%x", 0x100 + ap->port_no * 0x80);
+
+               /* set initial link pm policy */
+               ap->pm_policy = NOT_AVAILABLE;
+
+               /* set enclosure management message type */
+               if (ap->flags & ATA_FLAG_EM)
+                       ap->em_message_type = hpriv->em_msg_type;
+
+               /* disabled/not-implemented port */
+               if (!(hpriv->port_map & (1 << i)))
+                       ap->ops = &ata_dummy_port_ops;
+       }
+
+       rc = ahci_reset_controller(host);
+       if (rc)
+               goto err0;
+
+       ahci_init_controller(host);
+       ahci_print_info(host, "platform");
+
+       rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
+                              &ahci_sht);
+       if (rc)
+               goto err0;
+
+       return 0;
+err0:
+       if (pdata && pdata->exit)
+               pdata->exit(dev);
+       return rc;
+}
+
+static int __devexit ahci_remove(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct ahci_platform_data *pdata = dev->platform_data;
+       struct ata_host *host = dev_get_drvdata(dev);
+
+       ata_host_detach(host);
+
+       if (pdata && pdata->exit)
+               pdata->exit(dev);
+
+       return 0;
+}
+
+static struct platform_driver ahci_driver = {
+       .probe = ahci_probe,
+       .remove = __devexit_p(ahci_remove),
+       .driver = {
+               .name = "ahci",
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init ahci_init(void)
+{
+       return platform_driver_probe(&ahci_driver, ahci_probe);
+}
+module_init(ahci_init);
+
+static void __exit ahci_exit(void)
+{
+       platform_driver_unregister(&ahci_driver);
+}
+module_exit(ahci_exit);
+
+MODULE_DESCRIPTION("AHCI SATA platform driver");
+MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ahci");
index 83bc49f..ec52fc6 100644 (file)
@@ -43,7 +43,7 @@
  * driver the list of errata that are relevant is below, going back to
  * PIIX4. Older device documentation is now a bit tricky to find.
  *
- * The chipsets all follow very much the same design. The orginal Triton
+ * The chipsets all follow very much the same design. The original Triton
  * series chipsets do _not_ support independant device timings, but this
  * is fixed in Triton II. With the odd mobile exception the chips then
  * change little except in gaining more modes until SATA arrives. This
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
new file mode 100644 (file)
index 0000000..1984a6e
--- /dev/null
@@ -0,0 +1,2216 @@
+/*
+ *  libahci.c - Common AHCI SATA low-level routines
+ *
+ *  Maintained by:  Jeff Garzik <jgarzik@pobox.com>
+ *                 Please ALWAYS copy linux-ide@vger.kernel.org
+ *                 on emails.
+ *
+ *  Copyright 2004-2005 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; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ *
+ * libata documentation is available via 'make {ps|pdf}docs',
+ * as Documentation/DocBook/libata.*
+ *
+ * AHCI hardware documentation:
+ * http://www.intel.com/technology/serialata/pdf/rev1_0.pdf
+ * http://www.intel.com/technology/serialata/pdf/rev1_1.pdf
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/gfp.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/blkdev.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/dma-mapping.h>
+#include <linux/device.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_cmnd.h>
+#include <linux/libata.h>
+#include "ahci.h"
+
+static int ahci_skip_host_reset;
+int ahci_ignore_sss;
+EXPORT_SYMBOL_GPL(ahci_ignore_sss);
+
+module_param_named(skip_host_reset, ahci_skip_host_reset, int, 0444);
+MODULE_PARM_DESC(skip_host_reset, "skip global host reset (0=don't skip, 1=skip)");
+
+module_param_named(ignore_sss, ahci_ignore_sss, int, 0444);
+MODULE_PARM_DESC(ignore_sss, "Ignore staggered spinup flag (0=don't ignore, 1=ignore)");
+
+static int ahci_enable_alpm(struct ata_port *ap,
+               enum link_pm policy);
+static void ahci_disable_alpm(struct ata_port *ap);
+static ssize_t ahci_led_show(struct ata_port *ap, char *buf);
+static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
+                             size_t size);
+static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
+                                       ssize_t size);
+
+
+
+static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
+static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
+static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc);
+static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc);
+static int ahci_port_start(struct ata_port *ap);
+static void ahci_port_stop(struct ata_port *ap);
+static void ahci_qc_prep(struct ata_queued_cmd *qc);
+static int ahci_pmp_qc_defer(struct ata_queued_cmd *qc);
+static void ahci_freeze(struct ata_port *ap);
+static void ahci_thaw(struct ata_port *ap);
+static void ahci_enable_fbs(struct ata_port *ap);
+static void ahci_disable_fbs(struct ata_port *ap);
+static void ahci_pmp_attach(struct ata_port *ap);
+static void ahci_pmp_detach(struct ata_port *ap);
+static int ahci_softreset(struct ata_link *link, unsigned int *class,
+                         unsigned long deadline);
+static int ahci_hardreset(struct ata_link *link, unsigned int *class,
+                         unsigned long deadline);
+static void ahci_postreset(struct ata_link *link, unsigned int *class);
+static void ahci_error_handler(struct ata_port *ap);
+static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
+static int ahci_port_resume(struct ata_port *ap);
+static void ahci_dev_config(struct ata_device *dev);
+static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
+                              u32 opts);
+#ifdef CONFIG_PM
+static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
+#endif
+static ssize_t ahci_activity_show(struct ata_device *dev, char *buf);
+static ssize_t ahci_activity_store(struct ata_device *dev,
+                                  enum sw_activity val);
+static void ahci_init_sw_activity(struct ata_link *link);
+
+static ssize_t ahci_show_host_caps(struct device *dev,
+                                  struct device_attribute *attr, char *buf);
+static ssize_t ahci_show_host_cap2(struct device *dev,
+                                  struct device_attribute *attr, char *buf);
+static ssize_t ahci_show_host_version(struct device *dev,
+                                     struct device_attribute *attr, char *buf);
+static ssize_t ahci_show_port_cmd(struct device *dev,
+                                 struct device_attribute *attr, char *buf);
+static ssize_t ahci_read_em_buffer(struct device *dev,
+                                  struct device_attribute *attr, char *buf);
+static ssize_t ahci_store_em_buffer(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t size);
+
+static DEVICE_ATTR(ahci_host_caps, S_IRUGO, ahci_show_host_caps, NULL);
+static DEVICE_ATTR(ahci_host_cap2, S_IRUGO, ahci_show_host_cap2, NULL);
+static DEVICE_ATTR(ahci_host_version, S_IRUGO, ahci_show_host_version, NULL);
+static DEVICE_ATTR(ahci_port_cmd, S_IRUGO, ahci_show_port_cmd, NULL);
+static DEVICE_ATTR(em_buffer, S_IWUSR | S_IRUGO,
+                  ahci_read_em_buffer, ahci_store_em_buffer);
+
+static struct device_attribute *ahci_shost_attrs[] = {
+       &dev_attr_link_power_management_policy,
+       &dev_attr_em_message_type,
+       &dev_attr_em_message,
+       &dev_attr_ahci_host_caps,
+       &dev_attr_ahci_host_cap2,
+       &dev_attr_ahci_host_version,
+       &dev_attr_ahci_port_cmd,
+       &dev_attr_em_buffer,
+       NULL
+};
+
+static struct device_attribute *ahci_sdev_attrs[] = {
+       &dev_attr_sw_activity,
+       &dev_attr_unload_heads,
+       NULL
+};
+
+struct scsi_host_template ahci_sht = {
+       ATA_NCQ_SHT("ahci"),
+       .can_queue              = AHCI_MAX_CMDS - 1,
+       .sg_tablesize           = AHCI_MAX_SG,
+       .dma_boundary           = AHCI_DMA_BOUNDARY,
+       .shost_attrs            = ahci_shost_attrs,
+       .sdev_attrs             = ahci_sdev_attrs,
+};
+EXPORT_SYMBOL_GPL(ahci_sht);
+
+struct ata_port_operations ahci_ops = {
+       .inherits               = &sata_pmp_port_ops,
+
+       .qc_defer               = ahci_pmp_qc_defer,
+       .qc_prep                = ahci_qc_prep,
+       .qc_issue               = ahci_qc_issue,
+       .qc_fill_rtf            = ahci_qc_fill_rtf,
+
+       .freeze                 = ahci_freeze,
+       .thaw                   = ahci_thaw,
+       .softreset              = ahci_softreset,
+       .hardreset              = ahci_hardreset,
+       .postreset              = ahci_postreset,
+       .pmp_softreset          = ahci_softreset,
+       .error_handler          = ahci_error_handler,
+       .post_internal_cmd      = ahci_post_internal_cmd,
+       .dev_config             = ahci_dev_config,
+
+       .scr_read               = ahci_scr_read,
+       .scr_write              = ahci_scr_write,
+       .pmp_attach             = ahci_pmp_attach,
+       .pmp_detach             = ahci_pmp_detach,
+
+       .enable_pm              = ahci_enable_alpm,
+       .disable_pm             = ahci_disable_alpm,
+       .em_show                = ahci_led_show,
+       .em_store               = ahci_led_store,
+       .sw_activity_show       = ahci_activity_show,
+       .sw_activity_store      = ahci_activity_store,
+#ifdef CONFIG_PM
+       .port_suspend           = ahci_port_suspend,
+       .port_resume            = ahci_port_resume,
+#endif
+       .port_start             = ahci_port_start,
+       .port_stop              = ahci_port_stop,
+};
+EXPORT_SYMBOL_GPL(ahci_ops);
+
+int ahci_em_messages = 1;
+EXPORT_SYMBOL_GPL(ahci_em_messages);
+module_param(ahci_em_messages, int, 0444);
+/* add other LED protocol types when they become supported */
+MODULE_PARM_DESC(ahci_em_messages,
+       "AHCI Enclosure Management Message control (0 = off, 1 = on)");
+
+static void ahci_enable_ahci(void __iomem *mmio)
+{
+       int i;
+       u32 tmp;
+
+       /* turn on AHCI_EN */
+       tmp = readl(mmio + HOST_CTL);
+       if (tmp & HOST_AHCI_EN)
+               return;
+
+       /* Some controllers need AHCI_EN to be written multiple times.
+        * Try a few times before giving up.
+        */
+       for (i = 0; i < 5; i++) {
+               tmp |= HOST_AHCI_EN;
+               writel(tmp, mmio + HOST_CTL);
+               tmp = readl(mmio + HOST_CTL);   /* flush && sanity check */
+               if (tmp & HOST_AHCI_EN)
+                       return;
+               msleep(10);
+       }
+
+       WARN_ON(1);
+}
+
+static ssize_t ahci_show_host_caps(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+
+       return sprintf(buf, "%x\n", hpriv->cap);
+}
+
+static ssize_t ahci_show_host_cap2(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+
+       return sprintf(buf, "%x\n", hpriv->cap2);
+}
+
+static ssize_t ahci_show_host_version(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+
+       return sprintf(buf, "%x\n", readl(mmio + HOST_VERSION));
+}
+
+static ssize_t ahci_show_port_cmd(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       void __iomem *port_mmio = ahci_port_base(ap);
+
+       return sprintf(buf, "%x\n", readl(port_mmio + PORT_CMD));
+}
+
+static ssize_t ahci_read_em_buffer(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       void __iomem *em_mmio = mmio + hpriv->em_loc;
+       u32 em_ctl, msg;
+       unsigned long flags;
+       size_t count;
+       int i;
+
+       spin_lock_irqsave(ap->lock, flags);
+
+       em_ctl = readl(mmio + HOST_EM_CTL);
+       if (!(ap->flags & ATA_FLAG_EM) || em_ctl & EM_CTL_XMT ||
+           !(hpriv->em_msg_type & EM_MSG_TYPE_SGPIO)) {
+               spin_unlock_irqrestore(ap->lock, flags);
+               return -EINVAL;
+       }
+
+       if (!(em_ctl & EM_CTL_MR)) {
+               spin_unlock_irqrestore(ap->lock, flags);
+               return -EAGAIN;
+       }
+
+       if (!(em_ctl & EM_CTL_SMB))
+               em_mmio += hpriv->em_buf_sz;
+
+       count = hpriv->em_buf_sz;
+
+       /* the count should not be larger than PAGE_SIZE */
+       if (count > PAGE_SIZE) {
+               if (printk_ratelimit())
+                       ata_port_printk(ap, KERN_WARNING,
+                                       "EM read buffer size too large: "
+                                       "buffer size %u, page size %lu\n",
+                                       hpriv->em_buf_sz, PAGE_SIZE);
+               count = PAGE_SIZE;
+       }
+
+       for (i = 0; i < count; i += 4) {
+               msg = readl(em_mmio + i);
+               buf[i] = msg & 0xff;
+               buf[i + 1] = (msg >> 8) & 0xff;
+               buf[i + 2] = (msg >> 16) & 0xff;
+               buf[i + 3] = (msg >> 24) & 0xff;
+       }
+
+       spin_unlock_irqrestore(ap->lock, flags);
+
+       return i;
+}
+
+static ssize_t ahci_store_em_buffer(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t size)
+{
+       struct Scsi_Host *shost = class_to_shost(dev);
+       struct ata_port *ap = ata_shost_to_port(shost);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       void __iomem *em_mmio = mmio + hpriv->em_loc;
+       u32 em_ctl, msg;
+       unsigned long flags;
+       int i;
+
+       /* check size validity */
+       if (!(ap->flags & ATA_FLAG_EM) ||
+           !(hpriv->em_msg_type & EM_MSG_TYPE_SGPIO) ||
+           size % 4 || size > hpriv->em_buf_sz)
+               return -EINVAL;
+
+       spin_lock_irqsave(ap->lock, flags);
+
+       em_ctl = readl(mmio + HOST_EM_CTL);
+       if (em_ctl & EM_CTL_TM) {
+               spin_unlock_irqrestore(ap->lock, flags);
+               return -EBUSY;
+       }
+
+       for (i = 0; i < size; i += 4) {
+               msg = buf[i] | buf[i + 1] << 8 |
+                     buf[i + 2] << 16 | buf[i + 3] << 24;
+               writel(msg, em_mmio + i);
+       }
+
+       writel(em_ctl | EM_CTL_TM, mmio + HOST_EM_CTL);
+
+       spin_unlock_irqrestore(ap->lock, flags);
+
+       return size;
+}
+
+/**
+ *     ahci_save_initial_config - Save and fixup initial config values
+ *     @dev: target AHCI device
+ *     @hpriv: host private area to store config values
+ *     @force_port_map: force port map to a specified value
+ *     @mask_port_map: mask out particular bits from port map
+ *
+ *     Some registers containing configuration info might be setup by
+ *     BIOS and might be cleared on reset.  This function saves the
+ *     initial values of those registers into @hpriv such that they
+ *     can be restored after controller reset.
+ *
+ *     If inconsistent, config values are fixed up by this function.
+ *
+ *     LOCKING:
+ *     None.
+ */
+void ahci_save_initial_config(struct device *dev,
+                             struct ahci_host_priv *hpriv,
+                             unsigned int force_port_map,
+                             unsigned int mask_port_map)
+{
+       void __iomem *mmio = hpriv->mmio;
+       u32 cap, cap2, vers, port_map;
+       int i;
+
+       /* make sure AHCI mode is enabled before accessing CAP */
+       ahci_enable_ahci(mmio);
+
+       /* Values prefixed with saved_ are written back to host after
+        * reset.  Values without are used for driver operation.
+        */
+       hpriv->saved_cap = cap = readl(mmio + HOST_CAP);
+       hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL);
+
+       /* CAP2 register is only defined for AHCI 1.2 and later */
+       vers = readl(mmio + HOST_VERSION);
+       if ((vers >> 16) > 1 ||
+          ((vers >> 16) == 1 && (vers & 0xFFFF) >= 0x200))
+               hpriv->saved_cap2 = cap2 = readl(mmio + HOST_CAP2);
+       else
+               hpriv->saved_cap2 = cap2 = 0;
+
+       /* some chips have errata preventing 64bit use */
+       if ((cap & HOST_CAP_64) && (hpriv->flags & AHCI_HFLAG_32BIT_ONLY)) {
+               dev_printk(KERN_INFO, dev,
+                          "controller can't do 64bit DMA, forcing 32bit\n");
+               cap &= ~HOST_CAP_64;
+       }
+
+       if ((cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_NO_NCQ)) {
+               dev_printk(KERN_INFO, dev,
+                          "controller can't do NCQ, turning off CAP_NCQ\n");
+               cap &= ~HOST_CAP_NCQ;
+       }
+
+       if (!(cap & HOST_CAP_NCQ) && (hpriv->flags & AHCI_HFLAG_YES_NCQ)) {
+               dev_printk(KERN_INFO, dev,
+                          "controller can do NCQ, turning on CAP_NCQ\n");
+               cap |= HOST_CAP_NCQ;
+       }
+
+       if ((cap & HOST_CAP_PMP) && (hpriv->flags & AHCI_HFLAG_NO_PMP)) {
+               dev_printk(KERN_INFO, dev,
+                          "controller can't do PMP, turning off CAP_PMP\n");
+               cap &= ~HOST_CAP_PMP;
+       }
+
+       if ((cap & HOST_CAP_SNTF) && (hpriv->flags & AHCI_HFLAG_NO_SNTF)) {
+               dev_printk(KERN_INFO, dev,
+                          "controller can't do SNTF, turning off CAP_SNTF\n");
+               cap &= ~HOST_CAP_SNTF;
+       }
+
+       if (force_port_map && port_map != force_port_map) {
+               dev_printk(KERN_INFO, dev, "forcing port_map 0x%x -> 0x%x\n",
+                          port_map, force_port_map);
+               port_map = force_port_map;
+       }
+
+       if (mask_port_map) {
+               dev_printk(KERN_ERR, dev, "masking port_map 0x%x -> 0x%x\n",
+                          port_map,
+                          port_map & mask_port_map);
+               port_map &= mask_port_map;
+       }
+
+       /* cross check port_map and cap.n_ports */
+       if (port_map) {
+               int map_ports = 0;
+
+               for (i = 0; i < AHCI_MAX_PORTS; i++)
+                       if (port_map & (1 << i))
+                               map_ports++;
+
+               /* If PI has more ports than n_ports, whine, clear
+                * port_map and let it be generated from n_ports.
+                */
+               if (map_ports > ahci_nr_ports(cap)) {
+                       dev_printk(KERN_WARNING, dev,
+                                  "implemented port map (0x%x) contains more "
+                                  "ports than nr_ports (%u), using nr_ports\n",
+                                  port_map, ahci_nr_ports(cap));
+                       port_map = 0;
+               }
+       }
+
+       /* fabricate port_map from cap.nr_ports */
+       if (!port_map) {
+               port_map = (1 << ahci_nr_ports(cap)) - 1;
+               dev_printk(KERN_WARNING, dev,
+                          "forcing PORTS_IMPL to 0x%x\n", port_map);
+
+               /* write the fixed up value to the PI register */
+               hpriv->saved_port_map = port_map;
+       }
+
+       /* record values to use during operation */
+       hpriv->cap = cap;
+       hpriv->cap2 = cap2;
+       hpriv->port_map = port_map;
+}
+EXPORT_SYMBOL_GPL(ahci_save_initial_config);
+
+/**
+ *     ahci_restore_initial_config - Restore initial config
+ *     @host: target ATA host
+ *
+ *     Restore initial config stored by ahci_save_initial_config().
+ *
+ *     LOCKING:
+ *     None.
+ */
+static void ahci_restore_initial_config(struct ata_host *host)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+
+       writel(hpriv->saved_cap, mmio + HOST_CAP);
+       if (hpriv->saved_cap2)
+               writel(hpriv->saved_cap2, mmio + HOST_CAP2);
+       writel(hpriv->saved_port_map, mmio + HOST_PORTS_IMPL);
+       (void) readl(mmio + HOST_PORTS_IMPL);   /* flush */
+}
+
+static unsigned ahci_scr_offset(struct ata_port *ap, unsigned int sc_reg)
+{
+       static const int offset[] = {
+               [SCR_STATUS]            = PORT_SCR_STAT,
+               [SCR_CONTROL]           = PORT_SCR_CTL,
+               [SCR_ERROR]             = PORT_SCR_ERR,
+               [SCR_ACTIVE]            = PORT_SCR_ACT,
+               [SCR_NOTIFICATION]      = PORT_SCR_NTF,
+       };
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+
+       if (sc_reg < ARRAY_SIZE(offset) &&
+           (sc_reg != SCR_NOTIFICATION || (hpriv->cap & HOST_CAP_SNTF)))
+               return offset[sc_reg];
+       return 0;
+}
+
+static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
+{
+       void __iomem *port_mmio = ahci_port_base(link->ap);
+       int offset = ahci_scr_offset(link->ap, sc_reg);
+
+       if (offset) {
+               *val = readl(port_mmio + offset);
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int ahci_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
+{
+       void __iomem *port_mmio = ahci_port_base(link->ap);
+       int offset = ahci_scr_offset(link->ap, sc_reg);
+
+       if (offset) {
+               writel(val, port_mmio + offset);
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int ahci_is_device_present(void __iomem *port_mmio)
+{
+       u8 status = readl(port_mmio + PORT_TFDATA) & 0xff;
+
+       /* Make sure PxTFD.STS.BSY and PxTFD.STS.DRQ are 0 */
+       if (status & (ATA_BUSY | ATA_DRQ))
+               return 0;
+
+       /* Make sure PxSSTS.DET is 3h */
+       status = readl(port_mmio + PORT_SCR_STAT) & 0xf;
+       if (status != 3)
+               return 0;
+       return 1;
+}
+
+void ahci_start_engine(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 tmp;
+
+       if (!ahci_is_device_present(port_mmio))
+               return;
+
+       /* start DMA */
+       tmp = readl(port_mmio + PORT_CMD);
+       tmp |= PORT_CMD_START;
+       writel(tmp, port_mmio + PORT_CMD);
+       readl(port_mmio + PORT_CMD); /* flush */
+}
+EXPORT_SYMBOL_GPL(ahci_start_engine);
+
+int ahci_stop_engine(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 tmp;
+
+       tmp = readl(port_mmio + PORT_CMD);
+
+       /* check if the HBA is idle */
+       if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0)
+               return 0;
+
+       /* setting HBA to idle */
+       tmp &= ~PORT_CMD_START;
+       writel(tmp, port_mmio + PORT_CMD);
+
+       /* wait for engine to stop. This could be as long as 500 msec */
+       tmp = ata_wait_register(port_mmio + PORT_CMD,
+                               PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
+       if (tmp & PORT_CMD_LIST_ON)
+               return -EIO;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ahci_stop_engine);
+
+static void ahci_start_fis_rx(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       struct ahci_port_priv *pp = ap->private_data;
+       u32 tmp;
+
+       /* set FIS registers */
+       if (hpriv->cap & HOST_CAP_64)
+               writel((pp->cmd_slot_dma >> 16) >> 16,
+                      port_mmio + PORT_LST_ADDR_HI);
+       writel(pp->cmd_slot_dma & 0xffffffff, port_mmio + PORT_LST_ADDR);
+
+       if (hpriv->cap & HOST_CAP_64)
+               writel((pp->rx_fis_dma >> 16) >> 16,
+                      port_mmio + PORT_FIS_ADDR_HI);
+       writel(pp->rx_fis_dma & 0xffffffff, port_mmio + PORT_FIS_ADDR);
+
+       /* enable FIS reception */
+       tmp = readl(port_mmio + PORT_CMD);
+       tmp |= PORT_CMD_FIS_RX;
+       writel(tmp, port_mmio + PORT_CMD);
+
+       /* flush */
+       readl(port_mmio + PORT_CMD);
+}
+
+static int ahci_stop_fis_rx(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 tmp;
+
+       /* disable FIS reception */
+       tmp = readl(port_mmio + PORT_CMD);
+       tmp &= ~PORT_CMD_FIS_RX;
+       writel(tmp, port_mmio + PORT_CMD);
+
+       /* wait for completion, spec says 500ms, give it 1000 */
+       tmp = ata_wait_register(port_mmio + PORT_CMD, PORT_CMD_FIS_ON,
+                               PORT_CMD_FIS_ON, 10, 1000);
+       if (tmp & PORT_CMD_FIS_ON)
+               return -EBUSY;
+
+       return 0;
+}
+
+static void ahci_power_up(struct ata_port *ap)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 cmd;
+
+       cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
+
+       /* spin up device */
+       if (hpriv->cap & HOST_CAP_SSS) {
+               cmd |= PORT_CMD_SPIN_UP;
+               writel(cmd, port_mmio + PORT_CMD);
+       }
+
+       /* wake up link */
+       writel(cmd | PORT_CMD_ICC_ACTIVE, port_mmio + PORT_CMD);
+}
+
+static void ahci_disable_alpm(struct ata_port *ap)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 cmd;
+       struct ahci_port_priv *pp = ap->private_data;
+
+       /* IPM bits should be disabled by libata-core */
+       /* get the existing command bits */
+       cmd = readl(port_mmio + PORT_CMD);
+
+       /* disable ALPM and ASP */
+       cmd &= ~PORT_CMD_ASP;
+       cmd &= ~PORT_CMD_ALPE;
+
+       /* force the interface back to active */
+       cmd |= PORT_CMD_ICC_ACTIVE;
+
+       /* write out new cmd value */
+       writel(cmd, port_mmio + PORT_CMD);
+       cmd = readl(port_mmio + PORT_CMD);
+
+       /* wait 10ms to be sure we've come out of any low power state */
+       msleep(10);
+
+       /* clear out any PhyRdy stuff from interrupt status */
+       writel(PORT_IRQ_PHYRDY, port_mmio + PORT_IRQ_STAT);
+
+       /* go ahead and clean out PhyRdy Change from Serror too */
+       ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
+
+       /*
+        * Clear flag to indicate that we should ignore all PhyRdy
+        * state changes
+        */
+       hpriv->flags &= ~AHCI_HFLAG_NO_HOTPLUG;
+
+       /*
+        * Enable interrupts on Phy Ready.
+        */
+       pp->intr_mask |= PORT_IRQ_PHYRDY;
+       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+
+       /*
+        * don't change the link pm policy - we can be called
+        * just to turn of link pm temporarily
+        */
+}
+
+static int ahci_enable_alpm(struct ata_port *ap,
+       enum link_pm policy)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 cmd;
+       struct ahci_port_priv *pp = ap->private_data;
+       u32 asp;
+
+       /* Make sure the host is capable of link power management */
+       if (!(hpriv->cap & HOST_CAP_ALPM))
+               return -EINVAL;
+
+       switch (policy) {
+       case MAX_PERFORMANCE:
+       case NOT_AVAILABLE:
+               /*
+                * if we came here with NOT_AVAILABLE,
+                * it just means this is the first time we
+                * have tried to enable - default to max performance,
+                * and let the user go to lower power modes on request.
+                */
+               ahci_disable_alpm(ap);
+               return 0;
+       case MIN_POWER:
+               /* configure HBA to enter SLUMBER */
+               asp = PORT_CMD_ASP;
+               break;
+       case MEDIUM_POWER:
+               /* configure HBA to enter PARTIAL */
+               asp = 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /*
+        * Disable interrupts on Phy Ready. This keeps us from
+        * getting woken up due to spurious phy ready interrupts
+        * TBD - Hot plug should be done via polling now, is
+        * that even supported?
+        */
+       pp->intr_mask &= ~PORT_IRQ_PHYRDY;
+       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+
+       /*
+        * Set a flag to indicate that we should ignore all PhyRdy
+        * state changes since these can happen now whenever we
+        * change link state
+        */
+       hpriv->flags |= AHCI_HFLAG_NO_HOTPLUG;
+
+       /* get the existing command bits */
+       cmd = readl(port_mmio + PORT_CMD);
+
+       /*
+        * Set ASP based on Policy
+        */
+       cmd |= asp;
+
+       /*
+        * Setting this bit will instruct the HBA to aggressively
+        * enter a lower power link state when it's appropriate and
+        * based on the value set above for ASP
+        */
+       cmd |= PORT_CMD_ALPE;
+
+       /* write out new cmd value */
+       writel(cmd, port_mmio + PORT_CMD);
+       cmd = readl(port_mmio + PORT_CMD);
+
+       /* IPM bits should be set by libata-core */
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static void ahci_power_down(struct ata_port *ap)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 cmd, scontrol;
+
+       if (!(hpriv->cap & HOST_CAP_SSS))
+               return;
+
+       /* put device into listen mode, first set PxSCTL.DET to 0 */
+       scontrol = readl(port_mmio + PORT_SCR_CTL);
+       scontrol &= ~0xf;
+       writel(scontrol, port_mmio + PORT_SCR_CTL);
+
+       /* then set PxCMD.SUD to 0 */
+       cmd = readl(port_mmio + PORT_CMD) & ~PORT_CMD_ICC_MASK;
+       cmd &= ~PORT_CMD_SPIN_UP;
+       writel(cmd, port_mmio + PORT_CMD);
+}
+#endif
+
+static void ahci_start_port(struct ata_port *ap)
+{
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ata_link *link;
+       struct ahci_em_priv *emp;
+       ssize_t rc;
+       int i;
+
+       /* enable FIS reception */
+       ahci_start_fis_rx(ap);
+
+       /* enable DMA */
+       ahci_start_engine(ap);
+
+       /* turn on LEDs */
+       if (ap->flags & ATA_FLAG_EM) {
+               ata_for_each_link(link, ap, EDGE) {
+                       emp = &pp->em_priv[link->pmp];
+
+                       /* EM Transmit bit maybe busy during init */
+                       for (i = 0; i < EM_MAX_RETRY; i++) {
+                               rc = ahci_transmit_led_message(ap,
+                                                              emp->led_state,
+                                                              4);
+                               if (rc == -EBUSY)
+                                       msleep(1);
+                               else
+                                       break;
+                       }
+               }
+       }
+
+       if (ap->flags & ATA_FLAG_SW_ACTIVITY)
+               ata_for_each_link(link, ap, EDGE)
+                       ahci_init_sw_activity(link);
+
+}
+
+static int ahci_deinit_port(struct ata_port *ap, const char **emsg)
+{
+       int rc;
+
+       /* disable DMA */
+       rc = ahci_stop_engine(ap);
+       if (rc) {
+               *emsg = "failed to stop engine";
+               return rc;
+       }
+
+       /* disable FIS reception */
+       rc = ahci_stop_fis_rx(ap);
+       if (rc) {
+               *emsg = "failed stop FIS RX";
+               return rc;
+       }
+
+       return 0;
+}
+
+int ahci_reset_controller(struct ata_host *host)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       u32 tmp;
+
+       /* we must be in AHCI mode, before using anything
+        * AHCI-specific, such as HOST_RESET.
+        */
+       ahci_enable_ahci(mmio);
+
+       /* global controller reset */
+       if (!ahci_skip_host_reset) {
+               tmp = readl(mmio + HOST_CTL);
+               if ((tmp & HOST_RESET) == 0) {
+                       writel(tmp | HOST_RESET, mmio + HOST_CTL);
+                       readl(mmio + HOST_CTL); /* flush */
+               }
+
+               /*
+                * to perform host reset, OS should set HOST_RESET
+                * and poll until this bit is read to be "0".
+                * reset must complete within 1 second, or
+                * the hardware should be considered fried.
+                */
+               tmp = ata_wait_register(mmio + HOST_CTL, HOST_RESET,
+                                       HOST_RESET, 10, 1000);
+
+               if (tmp & HOST_RESET) {
+                       dev_printk(KERN_ERR, host->dev,
+                                  "controller reset failed (0x%x)\n", tmp);
+                       return -EIO;
+               }
+
+               /* turn on AHCI mode */
+               ahci_enable_ahci(mmio);
+
+               /* Some registers might be cleared on reset.  Restore
+                * initial values.
+                */
+               ahci_restore_initial_config(host);
+       } else
+               dev_printk(KERN_INFO, host->dev,
+                          "skipping global host reset\n");
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ahci_reset_controller);
+
+static void ahci_sw_activity(struct ata_link *link)
+{
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
+
+       if (!(link->flags & ATA_LFLAG_SW_ACTIVITY))
+               return;
+
+       emp->activity++;
+       if (!timer_pending(&emp->timer))
+               mod_timer(&emp->timer, jiffies + msecs_to_jiffies(10));
+}
+
+static void ahci_sw_activity_blink(unsigned long arg)
+{
+       struct ata_link *link = (struct ata_link *)arg;
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
+       unsigned long led_message = emp->led_state;
+       u32 activity_led_state;
+       unsigned long flags;
+
+       led_message &= EM_MSG_LED_VALUE;
+       led_message |= ap->port_no | (link->pmp << 8);
+
+       /* check to see if we've had activity.  If so,
+        * toggle state of LED and reset timer.  If not,
+        * turn LED to desired idle state.
+        */
+       spin_lock_irqsave(ap->lock, flags);
+       if (emp->saved_activity != emp->activity) {
+               emp->saved_activity = emp->activity;
+               /* get the current LED state */
+               activity_led_state = led_message & EM_MSG_LED_VALUE_ON;
+
+               if (activity_led_state)
+                       activity_led_state = 0;
+               else
+                       activity_led_state = 1;
+
+               /* clear old state */
+               led_message &= ~EM_MSG_LED_VALUE_ACTIVITY;
+
+               /* toggle state */
+               led_message |= (activity_led_state << 16);
+               mod_timer(&emp->timer, jiffies + msecs_to_jiffies(100));
+       } else {
+               /* switch to idle */
+               led_message &= ~EM_MSG_LED_VALUE_ACTIVITY;
+               if (emp->blink_policy == BLINK_OFF)
+                       led_message |= (1 << 16);
+       }
+       spin_unlock_irqrestore(ap->lock, flags);
+       ahci_transmit_led_message(ap, led_message, 4);
+}
+
+static void ahci_init_sw_activity(struct ata_link *link)
+{
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
+
+       /* init activity stats, setup timer */
+       emp->saved_activity = emp->activity = 0;
+       setup_timer(&emp->timer, ahci_sw_activity_blink, (unsigned long)link);
+
+       /* check our blink policy and set flag for link if it's enabled */
+       if (emp->blink_policy)
+               link->flags |= ATA_LFLAG_SW_ACTIVITY;
+}
+
+int ahci_reset_em(struct ata_host *host)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       u32 em_ctl;
+
+       em_ctl = readl(mmio + HOST_EM_CTL);
+       if ((em_ctl & EM_CTL_TM) || (em_ctl & EM_CTL_RST))
+               return -EINVAL;
+
+       writel(em_ctl | EM_CTL_RST, mmio + HOST_EM_CTL);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ahci_reset_em);
+
+static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
+                                       ssize_t size)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       struct ahci_port_priv *pp = ap->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       u32 em_ctl;
+       u32 message[] = {0, 0};
+       unsigned long flags;
+       int pmp;
+       struct ahci_em_priv *emp;
+
+       /* get the slot number from the message */
+       pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
+       if (pmp < EM_MAX_SLOTS)
+               emp = &pp->em_priv[pmp];
+       else
+               return -EINVAL;
+
+       spin_lock_irqsave(ap->lock, flags);
+
+       /*
+        * if we are still busy transmitting a previous message,
+        * do not allow
+        */
+       em_ctl = readl(mmio + HOST_EM_CTL);
+       if (em_ctl & EM_CTL_TM) {
+               spin_unlock_irqrestore(ap->lock, flags);
+               return -EBUSY;
+       }
+
+       if (hpriv->em_msg_type & EM_MSG_TYPE_LED) {
+               /*
+                * create message header - this is all zero except for
+                * the message size, which is 4 bytes.
+                */
+               message[0] |= (4 << 8);
+
+               /* ignore 0:4 of byte zero, fill in port info yourself */
+               message[1] = ((state & ~EM_MSG_LED_HBA_PORT) | ap->port_no);
+
+               /* write message to EM_LOC */
+               writel(message[0], mmio + hpriv->em_loc);
+               writel(message[1], mmio + hpriv->em_loc+4);
+
+               /*
+                * tell hardware to transmit the message
+                */
+               writel(em_ctl | EM_CTL_TM, mmio + HOST_EM_CTL);
+       }
+
+       /* save off new led state for port/slot */
+       emp->led_state = state;
+
+       spin_unlock_irqrestore(ap->lock, flags);
+       return size;
+}
+
+static ssize_t ahci_led_show(struct ata_port *ap, char *buf)
+{
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ata_link *link;
+       struct ahci_em_priv *emp;
+       int rc = 0;
+
+       ata_for_each_link(link, ap, EDGE) {
+               emp = &pp->em_priv[link->pmp];
+               rc += sprintf(buf, "%lx\n", emp->led_state);
+       }
+       return rc;
+}
+
+static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
+                               size_t size)
+{
+       int state;
+       int pmp;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp;
+
+       state = simple_strtoul(buf, NULL, 0);
+
+       /* get the slot number from the message */
+       pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
+       if (pmp < EM_MAX_SLOTS)
+               emp = &pp->em_priv[pmp];
+       else
+               return -EINVAL;
+
+       /* mask off the activity bits if we are in sw_activity
+        * mode, user should turn off sw_activity before setting
+        * activity led through em_message
+        */
+       if (emp->blink_policy)
+               state &= ~EM_MSG_LED_VALUE_ACTIVITY;
+
+       return ahci_transmit_led_message(ap, state, size);
+}
+
+static ssize_t ahci_activity_store(struct ata_device *dev, enum sw_activity val)
+{
+       struct ata_link *link = dev->link;
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
+       u32 port_led_state = emp->led_state;
+
+       /* save the desired Activity LED behavior */
+       if (val == OFF) {
+               /* clear LFLAG */
+               link->flags &= ~(ATA_LFLAG_SW_ACTIVITY);
+
+               /* set the LED to OFF */
+               port_led_state &= EM_MSG_LED_VALUE_OFF;
+               port_led_state |= (ap->port_no | (link->pmp << 8));
+               ahci_transmit_led_message(ap, port_led_state, 4);
+       } else {
+               link->flags |= ATA_LFLAG_SW_ACTIVITY;
+               if (val == BLINK_OFF) {
+                       /* set LED to ON for idle */
+                       port_led_state &= EM_MSG_LED_VALUE_OFF;
+                       port_led_state |= (ap->port_no | (link->pmp << 8));
+                       port_led_state |= EM_MSG_LED_VALUE_ON; /* check this */
+                       ahci_transmit_led_message(ap, port_led_state, 4);
+               }
+       }
+       emp->blink_policy = val;
+       return 0;
+}
+
+static ssize_t ahci_activity_show(struct ata_device *dev, char *buf)
+{
+       struct ata_link *link = dev->link;
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_em_priv *emp = &pp->em_priv[link->pmp];
+
+       /* display the saved value of activity behavior for this
+        * disk.
+        */
+       return sprintf(buf, "%d\n", emp->blink_policy);
+}
+
+static void ahci_port_init(struct device *dev, struct ata_port *ap,
+                          int port_no, void __iomem *mmio,
+                          void __iomem *port_mmio)
+{
+       const char *emsg = NULL;
+       int rc;
+       u32 tmp;
+
+       /* make sure port is not active */
+       rc = ahci_deinit_port(ap, &emsg);
+       if (rc)
+               dev_warn(dev, "%s (%d)\n", emsg, rc);
+
+       /* clear SError */
+       tmp = readl(port_mmio + PORT_SCR_ERR);
+       VPRINTK("PORT_SCR_ERR 0x%x\n", tmp);
+       writel(tmp, port_mmio + PORT_SCR_ERR);
+
+       /* clear port IRQ */
+       tmp = readl(port_mmio + PORT_IRQ_STAT);
+       VPRINTK("PORT_IRQ_STAT 0x%x\n", tmp);
+       if (tmp)
+               writel(tmp, port_mmio + PORT_IRQ_STAT);
+
+       writel(1 << port_no, mmio + HOST_IRQ_STAT);
+}
+
+void ahci_init_controller(struct ata_host *host)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       int i;
+       void __iomem *port_mmio;
+       u32 tmp;
+
+       for (i = 0; i < host->n_ports; i++) {
+               struct ata_port *ap = host->ports[i];
+
+               port_mmio = ahci_port_base(ap);
+               if (ata_port_is_dummy(ap))
+                       continue;
+
+               ahci_port_init(host->dev, ap, i, mmio, port_mmio);
+       }
+
+       tmp = readl(mmio + HOST_CTL);
+       VPRINTK("HOST_CTL 0x%x\n", tmp);
+       writel(tmp | HOST_IRQ_EN, mmio + HOST_CTL);
+       tmp = readl(mmio + HOST_CTL);
+       VPRINTK("HOST_CTL 0x%x\n", tmp);
+}
+EXPORT_SYMBOL_GPL(ahci_init_controller);
+
+static void ahci_dev_config(struct ata_device *dev)
+{
+       struct ahci_host_priv *hpriv = dev->link->ap->host->private_data;
+
+       if (hpriv->flags & AHCI_HFLAG_SECT255) {
+               dev->max_sectors = 255;
+               ata_dev_printk(dev, KERN_INFO,
+                              "SB600 AHCI: limiting to 255 sectors per cmd\n");
+       }
+}
+
+static unsigned int ahci_dev_classify(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ata_taskfile tf;
+       u32 tmp;
+
+       tmp = readl(port_mmio + PORT_SIG);
+       tf.lbah         = (tmp >> 24)   & 0xff;
+       tf.lbam         = (tmp >> 16)   & 0xff;
+       tf.lbal         = (tmp >> 8)    & 0xff;
+       tf.nsect        = (tmp)         & 0xff;
+
+       return ata_dev_classify(&tf);
+}
+
+static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
+                              u32 opts)
+{
+       dma_addr_t cmd_tbl_dma;
+
+       cmd_tbl_dma = pp->cmd_tbl_dma + tag * AHCI_CMD_TBL_SZ;
+
+       pp->cmd_slot[tag].opts = cpu_to_le32(opts);
+       pp->cmd_slot[tag].status = 0;
+       pp->cmd_slot[tag].tbl_addr = cpu_to_le32(cmd_tbl_dma & 0xffffffff);
+       pp->cmd_slot[tag].tbl_addr_hi = cpu_to_le32((cmd_tbl_dma >> 16) >> 16);
+}
+
+int ahci_kick_engine(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
+       u32 tmp;
+       int busy, rc;
+
+       /* stop engine */
+       rc = ahci_stop_engine(ap);
+       if (rc)
+               goto out_restart;
+
+       /* need to do CLO?
+        * always do CLO if PMP is attached (AHCI-1.3 9.2)
+        */
+       busy = status & (ATA_BUSY | ATA_DRQ);
+       if (!busy && !sata_pmp_attached(ap)) {
+               rc = 0;
+               goto out_restart;
+       }
+
+       if (!(hpriv->cap & HOST_CAP_CLO)) {
+               rc = -EOPNOTSUPP;
+               goto out_restart;
+       }
+
+       /* perform CLO */
+       tmp = readl(port_mmio + PORT_CMD);
+       tmp |= PORT_CMD_CLO;
+       writel(tmp, port_mmio + PORT_CMD);
+
+       rc = 0;
+       tmp = ata_wait_register(port_mmio + PORT_CMD,
+                               PORT_CMD_CLO, PORT_CMD_CLO, 1, 500);
+       if (tmp & PORT_CMD_CLO)
+               rc = -EIO;
+
+       /* restart engine */
+ out_restart:
+       ahci_start_engine(ap);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(ahci_kick_engine);
+
+static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
+                               struct ata_taskfile *tf, int is_cmd, u16 flags,
+                               unsigned long timeout_msec)
+{
+       const u32 cmd_fis_len = 5; /* five dwords */
+       struct ahci_port_priv *pp = ap->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u8 *fis = pp->cmd_tbl;
+       u32 tmp;
+
+       /* prep the command */
+       ata_tf_to_fis(tf, pmp, is_cmd, fis);
+       ahci_fill_cmd_slot(pp, 0, cmd_fis_len | flags | (pmp << 12));
+
+       /* issue & wait */
+       writel(1, port_mmio + PORT_CMD_ISSUE);
+
+       if (timeout_msec) {
+               tmp = ata_wait_register(port_mmio + PORT_CMD_ISSUE, 0x1, 0x1,
+                                       1, timeout_msec);
+               if (tmp & 0x1) {
+                       ahci_kick_engine(ap);
+                       return -EBUSY;
+               }
+       } else
+               readl(port_mmio + PORT_CMD_ISSUE);      /* flush */
+
+       return 0;
+}
+
+int ahci_do_softreset(struct ata_link *link, unsigned int *class,
+                     int pmp, unsigned long deadline,
+                     int (*check_ready)(struct ata_link *link))
+{
+       struct ata_port *ap = link->ap;
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       const char *reason = NULL;
+       unsigned long now, msecs;
+       struct ata_taskfile tf;
+       int rc;
+
+       DPRINTK("ENTER\n");
+
+       /* prepare for SRST (AHCI-1.1 10.4.1) */
+       rc = ahci_kick_engine(ap);
+       if (rc && rc != -EOPNOTSUPP)
+               ata_link_printk(link, KERN_WARNING,
+                               "failed to reset engine (errno=%d)\n", rc);
+
+       ata_tf_init(link->device, &tf);
+
+       /* issue the first D2H Register FIS */
+       msecs = 0;
+       now = jiffies;
+       if (time_after(now, deadline))
+               msecs = jiffies_to_msecs(deadline - now);
+
+       tf.ctl |= ATA_SRST;
+       if (ahci_exec_polled_cmd(ap, pmp, &tf, 0,
+                                AHCI_CMD_RESET | AHCI_CMD_CLR_BUSY, msecs)) {
+               rc = -EIO;
+               reason = "1st FIS failed";
+               goto fail;
+       }
+
+       /* spec says at least 5us, but be generous and sleep for 1ms */
+       msleep(1);
+
+       /* issue the second D2H Register FIS */
+       tf.ctl &= ~ATA_SRST;
+       ahci_exec_polled_cmd(ap, pmp, &tf, 0, 0, 0);
+
+       /* wait for link to become ready */
+       rc = ata_wait_after_reset(link, deadline, check_ready);
+       if (rc == -EBUSY && hpriv->flags & AHCI_HFLAG_SRST_TOUT_IS_OFFLINE) {
+               /*
+                * Workaround for cases where link online status can't
+                * be trusted.  Treat device readiness timeout as link
+                * offline.
+                */
+               ata_link_printk(link, KERN_INFO,
+                               "device not ready, treating as offline\n");
+               *class = ATA_DEV_NONE;
+       } else if (rc) {
+               /* link occupied, -ENODEV too is an error */
+               reason = "device not ready";
+               goto fail;
+       } else
+               *class = ahci_dev_classify(ap);
+
+       DPRINTK("EXIT, class=%u\n", *class);
+       return 0;
+
+ fail:
+       ata_link_printk(link, KERN_ERR, "softreset failed (%s)\n", reason);
+       return rc;
+}
+
+int ahci_check_ready(struct ata_link *link)
+{
+       void __iomem *port_mmio = ahci_port_base(link->ap);
+       u8 status = readl(port_mmio + PORT_TFDATA) & 0xFF;
+
+       return ata_check_ready(status);
+}
+EXPORT_SYMBOL_GPL(ahci_check_ready);
+
+static int ahci_softreset(struct ata_link *link, unsigned int *class,
+                         unsigned long deadline)
+{
+       int pmp = sata_srst_pmp(link);
+
+       DPRINTK("ENTER\n");
+
+       return ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
+}
+EXPORT_SYMBOL_GPL(ahci_do_softreset);
+
+static int ahci_hardreset(struct ata_link *link, unsigned int *class,
+                         unsigned long deadline)
+{
+       const unsigned long *timing = sata_ehc_deb_timing(&link->eh_context);
+       struct ata_port *ap = link->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
+       struct ata_taskfile tf;
+       bool online;
+       int rc;
+
+       DPRINTK("ENTER\n");
+
+       ahci_stop_engine(ap);
+
+       /* clear D2H reception area to properly wait for D2H FIS */
+       ata_tf_init(link->device, &tf);
+       tf.command = 0x80;
+       ata_tf_to_fis(&tf, 0, 0, d2h_fis);
+
+       rc = sata_link_hardreset(link, timing, deadline, &online,
+                                ahci_check_ready);
+
+       ahci_start_engine(ap);
+
+       if (online)
+               *class = ahci_dev_classify(ap);
+
+       DPRINTK("EXIT, rc=%d, class=%u\n", rc, *class);
+       return rc;
+}
+
+static void ahci_postreset(struct ata_link *link, unsigned int *class)
+{
+       struct ata_port *ap = link->ap;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 new_tmp, tmp;
+
+       ata_std_postreset(link, class);
+
+       /* Make sure port's ATAPI bit is set appropriately */
+       new_tmp = tmp = readl(port_mmio + PORT_CMD);
+       if (*class == ATA_DEV_ATAPI)
+               new_tmp |= PORT_CMD_ATAPI;
+       else
+               new_tmp &= ~PORT_CMD_ATAPI;
+       if (new_tmp != tmp) {
+               writel(new_tmp, port_mmio + PORT_CMD);
+               readl(port_mmio + PORT_CMD); /* flush */
+       }
+}
+
+static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl)
+{
+       struct scatterlist *sg;
+       struct ahci_sg *ahci_sg = cmd_tbl + AHCI_CMD_TBL_HDR_SZ;
+       unsigned int si;
+
+       VPRINTK("ENTER\n");
+
+       /*
+        * Next, the S/G list.
+        */
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
+               dma_addr_t addr = sg_dma_address(sg);
+               u32 sg_len = sg_dma_len(sg);
+
+               ahci_sg[si].addr = cpu_to_le32(addr & 0xffffffff);
+               ahci_sg[si].addr_hi = cpu_to_le32((addr >> 16) >> 16);
+               ahci_sg[si].flags_size = cpu_to_le32(sg_len - 1);
+       }
+
+       return si;
+}
+
+static int ahci_pmp_qc_defer(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+
+       if (!sata_pmp_attached(ap) || pp->fbs_enabled)
+               return ata_std_qc_defer(qc);
+       else
+               return sata_pmp_qc_defer_cmd_switch(qc);
+}
+
+static void ahci_qc_prep(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       struct ahci_port_priv *pp = ap->private_data;
+       int is_atapi = ata_is_atapi(qc->tf.protocol);
+       void *cmd_tbl;
+       u32 opts;
+       const u32 cmd_fis_len = 5; /* five dwords */
+       unsigned int n_elem;
+
+       /*
+        * Fill in command table information.  First, the header,
+        * a SATA Register - Host to Device command FIS.
+        */
+       cmd_tbl = pp->cmd_tbl + qc->tag * AHCI_CMD_TBL_SZ;
+
+       ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, cmd_tbl);
+       if (is_atapi) {
+               memset(cmd_tbl + AHCI_CMD_TBL_CDB, 0, 32);
+               memcpy(cmd_tbl + AHCI_CMD_TBL_CDB, qc->cdb, qc->dev->cdb_len);
+       }
+
+       n_elem = 0;
+       if (qc->flags & ATA_QCFLAG_DMAMAP)
+               n_elem = ahci_fill_sg(qc, cmd_tbl);
+
+       /*
+        * Fill in command slot information.
+        */
+       opts = cmd_fis_len | n_elem << 16 | (qc->dev->link->pmp << 12);
+       if (qc->tf.flags & ATA_TFLAG_WRITE)
+               opts |= AHCI_CMD_WRITE;
+       if (is_atapi)
+               opts |= AHCI_CMD_ATAPI | AHCI_CMD_PREFETCH;
+
+       ahci_fill_cmd_slot(pp, qc->tag, opts);
+}
+
+static void ahci_fbs_dec_intr(struct ata_port *ap)
+{
+       struct ahci_port_priv *pp = ap->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 fbs = readl(port_mmio + PORT_FBS);
+       int retries = 3;
+
+       DPRINTK("ENTER\n");
+       BUG_ON(!pp->fbs_enabled);
+
+       /* time to wait for DEC is not specified by AHCI spec,
+        * add a retry loop for safety.
+        */
+       writel(fbs | PORT_FBS_DEC, port_mmio + PORT_FBS);
+       fbs = readl(port_mmio + PORT_FBS);
+       while ((fbs & PORT_FBS_DEC) && retries--) {
+               udelay(1);
+               fbs = readl(port_mmio + PORT_FBS);
+       }
+
+       if (fbs & PORT_FBS_DEC)
+               dev_printk(KERN_ERR, ap->host->dev,
+                          "failed to clear device error\n");
+}
+
+static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ata_eh_info *host_ehi = &ap->link.eh_info;
+       struct ata_link *link = NULL;
+       struct ata_queued_cmd *active_qc;
+       struct ata_eh_info *active_ehi;
+       bool fbs_need_dec = false;
+       u32 serror;
+
+       /* determine active link with error */
+       if (pp->fbs_enabled) {
+               void __iomem *port_mmio = ahci_port_base(ap);
+               u32 fbs = readl(port_mmio + PORT_FBS);
+               int pmp = fbs >> PORT_FBS_DWE_OFFSET;
+
+               if ((fbs & PORT_FBS_SDE) && (pmp < ap->nr_pmp_links) &&
+                   ata_link_online(&ap->pmp_link[pmp])) {
+                       link = &ap->pmp_link[pmp];
+                       fbs_need_dec = true;
+               }
+
+       } else
+               ata_for_each_link(link, ap, EDGE)
+                       if (ata_link_active(link))
+                               break;
+
+       if (!link)
+               link = &ap->link;
+
+       active_qc = ata_qc_from_tag(ap, link->active_tag);
+       active_ehi = &link->eh_info;
+
+       /* record irq stat */
+       ata_ehi_clear_desc(host_ehi);
+       ata_ehi_push_desc(host_ehi, "irq_stat 0x%08x", irq_stat);
+
+       /* AHCI needs SError cleared; otherwise, it might lock up */
+       ahci_scr_read(&ap->link, SCR_ERROR, &serror);
+       ahci_scr_write(&ap->link, SCR_ERROR, serror);
+       host_ehi->serror |= serror;
+
+       /* some controllers set IRQ_IF_ERR on device errors, ignore it */
+       if (hpriv->flags & AHCI_HFLAG_IGN_IRQ_IF_ERR)
+               irq_stat &= ~PORT_IRQ_IF_ERR;
+
+       if (irq_stat & PORT_IRQ_TF_ERR) {
+               /* If qc is active, charge it; otherwise, the active
+                * link.  There's no active qc on NCQ errors.  It will
+                * be determined by EH by reading log page 10h.
+                */
+               if (active_qc)
+                       active_qc->err_mask |= AC_ERR_DEV;
+               else
+                       active_ehi->err_mask |= AC_ERR_DEV;
+
+               if (hpriv->flags & AHCI_HFLAG_IGN_SERR_INTERNAL)
+                       host_ehi->serror &= ~SERR_INTERNAL;
+       }
+
+       if (irq_stat & PORT_IRQ_UNK_FIS) {
+               u32 *unk = (u32 *)(pp->rx_fis + RX_FIS_UNK);
+
+               active_ehi->err_mask |= AC_ERR_HSM;
+               active_ehi->action |= ATA_EH_RESET;
+               ata_ehi_push_desc(active_ehi,
+                                 "unknown FIS %08x %08x %08x %08x" ,
+                                 unk[0], unk[1], unk[2], unk[3]);
+       }
+
+       if (sata_pmp_attached(ap) && (irq_stat & PORT_IRQ_BAD_PMP)) {
+               active_ehi->err_mask |= AC_ERR_HSM;
+               active_ehi->action |= ATA_EH_RESET;
+               ata_ehi_push_desc(active_ehi, "incorrect PMP");
+       }
+
+       if (irq_stat & (PORT_IRQ_HBUS_ERR | PORT_IRQ_HBUS_DATA_ERR)) {
+               host_ehi->err_mask |= AC_ERR_HOST_BUS;
+               host_ehi->action |= ATA_EH_RESET;
+               ata_ehi_push_desc(host_ehi, "host bus error");
+       }
+
+       if (irq_stat & PORT_IRQ_IF_ERR) {
+               if (fbs_need_dec)
+                       active_ehi->err_mask |= AC_ERR_DEV;
+               else {
+                       host_ehi->err_mask |= AC_ERR_ATA_BUS;
+                       host_ehi->action |= ATA_EH_RESET;
+               }
+
+               ata_ehi_push_desc(host_ehi, "interface fatal error");
+       }
+
+       if (irq_stat & (PORT_IRQ_CONNECT | PORT_IRQ_PHYRDY)) {
+               ata_ehi_hotplugged(host_ehi);
+               ata_ehi_push_desc(host_ehi, "%s",
+                       irq_stat & PORT_IRQ_CONNECT ?
+                       "connection status changed" : "PHY RDY changed");
+       }
+
+       /* okay, let's hand over to EH */
+
+       if (irq_stat & PORT_IRQ_FREEZE)
+               ata_port_freeze(ap);
+       else if (fbs_need_dec) {
+               ata_link_abort(link);
+               ahci_fbs_dec_intr(ap);
+       } else
+               ata_port_abort(ap);
+}
+
+static void ahci_port_intr(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ata_eh_info *ehi = &ap->link.eh_info;
+       struct ahci_port_priv *pp = ap->private_data;
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       int resetting = !!(ap->pflags & ATA_PFLAG_RESETTING);
+       u32 status, qc_active = 0;
+       int rc;
+
+       status = readl(port_mmio + PORT_IRQ_STAT);
+       writel(status, port_mmio + PORT_IRQ_STAT);
+
+       /* ignore BAD_PMP while resetting */
+       if (unlikely(resetting))
+               status &= ~PORT_IRQ_BAD_PMP;
+
+       /* If we are getting PhyRdy, this is
+        * just a power state change, we should
+        * clear out this, plus the PhyRdy/Comm
+        * Wake bits from Serror
+        */
+       if ((hpriv->flags & AHCI_HFLAG_NO_HOTPLUG) &&
+               (status & PORT_IRQ_PHYRDY)) {
+               status &= ~PORT_IRQ_PHYRDY;
+               ahci_scr_write(&ap->link, SCR_ERROR, ((1 << 16) | (1 << 18)));
+       }
+
+       if (unlikely(status & PORT_IRQ_ERROR)) {
+               ahci_error_intr(ap, status);
+               return;
+       }
+
+       if (status & PORT_IRQ_SDB_FIS) {
+               /* If SNotification is available, leave notification
+                * handling to sata_async_notification().  If not,
+                * emulate it by snooping SDB FIS RX area.
+                *
+                * Snooping FIS RX area is probably cheaper than
+                * poking SNotification but some constrollers which
+                * implement SNotification, ICH9 for example, don't
+                * store AN SDB FIS into receive area.
+                */
+               if (hpriv->cap & HOST_CAP_SNTF)
+                       sata_async_notification(ap);
+               else {
+                       /* If the 'N' bit in word 0 of the FIS is set,
+                        * we just received asynchronous notification.
+                        * Tell libata about it.
+                        *
+                        * Lack of SNotification should not appear in
+                        * ahci 1.2, so the workaround is unnecessary
+                        * when FBS is enabled.
+                        */
+                       if (pp->fbs_enabled)
+                               WARN_ON_ONCE(1);
+                       else {
+                               const __le32 *f = pp->rx_fis + RX_FIS_SDB;
+                               u32 f0 = le32_to_cpu(f[0]);
+                               if (f0 & (1 << 15))
+                                       sata_async_notification(ap);
+                       }
+               }
+       }
+
+       /* pp->active_link is not reliable once FBS is enabled, both
+        * PORT_SCR_ACT and PORT_CMD_ISSUE should be checked because
+        * NCQ and non-NCQ commands may be in flight at the same time.
+        */
+       if (pp->fbs_enabled) {
+               if (ap->qc_active) {
+                       qc_active = readl(port_mmio + PORT_SCR_ACT);
+                       qc_active |= readl(port_mmio + PORT_CMD_ISSUE);
+               }
+       } else {
+               /* pp->active_link is valid iff any command is in flight */
+               if (ap->qc_active && pp->active_link->sactive)
+                       qc_active = readl(port_mmio + PORT_SCR_ACT);
+               else
+                       qc_active = readl(port_mmio + PORT_CMD_ISSUE);
+       }
+
+
+       rc = ata_qc_complete_multiple(ap, qc_active);
+
+       /* while resetting, invalid completions are expected */
+       if (unlikely(rc < 0 && !resetting)) {
+               ehi->err_mask |= AC_ERR_HSM;
+               ehi->action |= ATA_EH_RESET;
+               ata_port_freeze(ap);
+       }
+}
+
+irqreturn_t ahci_interrupt(int irq, void *dev_instance)
+{
+       struct ata_host *host = dev_instance;
+       struct ahci_host_priv *hpriv;
+       unsigned int i, handled = 0;
+       void __iomem *mmio;
+       u32 irq_stat, irq_masked;
+
+       VPRINTK("ENTER\n");
+
+       hpriv = host->private_data;
+       mmio = hpriv->mmio;
+
+       /* sigh.  0xffffffff is a valid return from h/w */
+       irq_stat = readl(mmio + HOST_IRQ_STAT);
+       if (!irq_stat)
+               return IRQ_NONE;
+
+       irq_masked = irq_stat & hpriv->port_map;
+
+       spin_lock(&host->lock);
+
+       for (i = 0; i < host->n_ports; i++) {
+               struct ata_port *ap;
+
+               if (!(irq_masked & (1 << i)))
+                       continue;
+
+               ap = host->ports[i];
+               if (ap) {
+                       ahci_port_intr(ap);
+                       VPRINTK("port %u\n", i);
+               } else {
+                       VPRINTK("port %u (no irq)\n", i);
+                       if (ata_ratelimit())
+                               dev_printk(KERN_WARNING, host->dev,
+                                       "interrupt on disabled port %u\n", i);
+               }
+
+               handled = 1;
+       }
+
+       /* HOST_IRQ_STAT behaves as level triggered latch meaning that
+        * it should be cleared after all the port events are cleared;
+        * otherwise, it will raise a spurious interrupt after each
+        * valid one.  Please read section 10.6.2 of ahci 1.1 for more
+        * information.
+        *
+        * Also, use the unmasked value to clear interrupt as spurious
+        * pending event on a dummy port might cause screaming IRQ.
+        */
+       writel(irq_stat, mmio + HOST_IRQ_STAT);
+
+       spin_unlock(&host->lock);
+
+       VPRINTK("EXIT\n");
+
+       return IRQ_RETVAL(handled);
+}
+EXPORT_SYMBOL_GPL(ahci_interrupt);
+
+static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_port_priv *pp = ap->private_data;
+
+       /* Keep track of the currently active link.  It will be used
+        * in completion path to determine whether NCQ phase is in
+        * progress.
+        */
+       pp->active_link = qc->dev->link;
+
+       if (qc->tf.protocol == ATA_PROT_NCQ)
+               writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
+
+       if (pp->fbs_enabled && pp->fbs_last_dev != qc->dev->link->pmp) {
+               u32 fbs = readl(port_mmio + PORT_FBS);
+               fbs &= ~(PORT_FBS_DEV_MASK | PORT_FBS_DEC);
+               fbs |= qc->dev->link->pmp << PORT_FBS_DEV_OFFSET;
+               writel(fbs, port_mmio + PORT_FBS);
+               pp->fbs_last_dev = qc->dev->link->pmp;
+       }
+
+       writel(1 << qc->tag, port_mmio + PORT_CMD_ISSUE);
+
+       ahci_sw_activity(qc->dev->link);
+
+       return 0;
+}
+
+static bool ahci_qc_fill_rtf(struct ata_queued_cmd *qc)
+{
+       struct ahci_port_priv *pp = qc->ap->private_data;
+       u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
+
+       if (pp->fbs_enabled)
+               d2h_fis += qc->dev->link->pmp * AHCI_RX_FIS_SZ;
+
+       ata_tf_from_fis(d2h_fis, &qc->result_tf);
+       return true;
+}
+
+static void ahci_freeze(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+
+       /* turn IRQ off */
+       writel(0, port_mmio + PORT_IRQ_MASK);
+}
+
+static void ahci_thaw(struct ata_port *ap)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 tmp;
+       struct ahci_port_priv *pp = ap->private_data;
+
+       /* clear IRQ */
+       tmp = readl(port_mmio + PORT_IRQ_STAT);
+       writel(tmp, port_mmio + PORT_IRQ_STAT);
+       writel(1 << ap->port_no, mmio + HOST_IRQ_STAT);
+
+       /* turn IRQ back on */
+       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+}
+
+static void ahci_error_handler(struct ata_port *ap)
+{
+       if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
+               /* restart engine */
+               ahci_stop_engine(ap);
+               ahci_start_engine(ap);
+       }
+
+       sata_pmp_error_handler(ap);
+}
+
+static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+
+       /* make DMA engine forget about the failed command */
+       if (qc->flags & ATA_QCFLAG_FAILED)
+               ahci_kick_engine(ap);
+}
+
+static void ahci_enable_fbs(struct ata_port *ap)
+{
+       struct ahci_port_priv *pp = ap->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 fbs;
+       int rc;
+
+       if (!pp->fbs_supported)
+               return;
+
+       fbs = readl(port_mmio + PORT_FBS);
+       if (fbs & PORT_FBS_EN) {
+               pp->fbs_enabled = true;
+               pp->fbs_last_dev = -1; /* initialization */
+               return;
+       }
+
+       rc = ahci_stop_engine(ap);
+       if (rc)
+               return;
+
+       writel(fbs | PORT_FBS_EN, port_mmio + PORT_FBS);
+       fbs = readl(port_mmio + PORT_FBS);
+       if (fbs & PORT_FBS_EN) {
+               dev_printk(KERN_INFO, ap->host->dev, "FBS is enabled.\n");
+               pp->fbs_enabled = true;
+               pp->fbs_last_dev = -1; /* initialization */
+       } else
+               dev_printk(KERN_ERR, ap->host->dev, "Failed to enable FBS\n");
+
+       ahci_start_engine(ap);
+}
+
+static void ahci_disable_fbs(struct ata_port *ap)
+{
+       struct ahci_port_priv *pp = ap->private_data;
+       void __iomem *port_mmio = ahci_port_base(ap);
+       u32 fbs;
+       int rc;
+
+       if (!pp->fbs_supported)
+               return;
+
+       fbs = readl(port_mmio + PORT_FBS);
+       if ((fbs & PORT_FBS_EN) == 0) {
+               pp->fbs_enabled = false;
+               return;
+       }
+
+       rc = ahci_stop_engine(ap);
+       if (rc)
+               return;
+
+       writel(fbs & ~PORT_FBS_EN, port_mmio + PORT_FBS);
+       fbs = readl(port_mmio + PORT_FBS);
+       if (fbs & PORT_FBS_EN)
+               dev_printk(KERN_ERR, ap->host->dev, "Failed to disable FBS\n");
+       else {
+               dev_printk(KERN_INFO, ap->host->dev, "FBS is disabled.\n");
+               pp->fbs_enabled = false;
+       }
+
+       ahci_start_engine(ap);
+}
+
+static void ahci_pmp_attach(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_port_priv *pp = ap->private_data;
+       u32 cmd;
+
+       cmd = readl(port_mmio + PORT_CMD);
+       cmd |= PORT_CMD_PMP;
+       writel(cmd, port_mmio + PORT_CMD);
+
+       ahci_enable_fbs(ap);
+
+       pp->intr_mask |= PORT_IRQ_BAD_PMP;
+       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+}
+
+static void ahci_pmp_detach(struct ata_port *ap)
+{
+       void __iomem *port_mmio = ahci_port_base(ap);
+       struct ahci_port_priv *pp = ap->private_data;
+       u32 cmd;
+
+       ahci_disable_fbs(ap);
+
+       cmd = readl(port_mmio + PORT_CMD);
+       cmd &= ~PORT_CMD_PMP;
+       writel(cmd, port_mmio + PORT_CMD);
+
+       pp->intr_mask &= ~PORT_IRQ_BAD_PMP;
+       writel(pp->intr_mask, port_mmio + PORT_IRQ_MASK);
+}
+
+static int ahci_port_resume(struct ata_port *ap)
+{
+       ahci_power_up(ap);
+       ahci_start_port(ap);
+
+       if (sata_pmp_attached(ap))
+               ahci_pmp_attach(ap);
+       else
+               ahci_pmp_detach(ap);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
+{
+       const char *emsg = NULL;
+       int rc;
+
+       rc = ahci_deinit_port(ap, &emsg);
+       if (rc == 0)
+               ahci_power_down(ap);
+       else {
+               ata_port_printk(ap, KERN_ERR, "%s (%d)\n", emsg, rc);
+               ahci_start_port(ap);
+       }
+
+       return rc;
+}
+#endif
+
+static int ahci_port_start(struct ata_port *ap)
+{
+       struct ahci_host_priv *hpriv = ap->host->private_data;
+       struct device *dev = ap->host->dev;
+       struct ahci_port_priv *pp;
+       void *mem;
+       dma_addr_t mem_dma;
+       size_t dma_sz, rx_fis_sz;
+
+       pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
+       if (!pp)
+               return -ENOMEM;
+
+       /* check FBS capability */
+       if ((hpriv->cap & HOST_CAP_FBS) && sata_pmp_supported(ap)) {
+               void __iomem *port_mmio = ahci_port_base(ap);
+               u32 cmd = readl(port_mmio + PORT_CMD);
+               if (cmd & PORT_CMD_FBSCP)
+                       pp->fbs_supported = true;
+               else
+                       dev_printk(KERN_WARNING, dev,
+                                  "The port is not capable of FBS\n");
+       }
+
+       if (pp->fbs_supported) {
+               dma_sz = AHCI_PORT_PRIV_FBS_DMA_SZ;
+               rx_fis_sz = AHCI_RX_FIS_SZ * 16;
+       } else {
+               dma_sz = AHCI_PORT_PRIV_DMA_SZ;
+               rx_fis_sz = AHCI_RX_FIS_SZ;
+       }
+
+       mem = dmam_alloc_coherent(dev, dma_sz, &mem_dma, GFP_KERNEL);
+       if (!mem)
+               return -ENOMEM;
+       memset(mem, 0, dma_sz);
+
+       /*
+        * First item in chunk of DMA memory: 32-slot command table,
+        * 32 bytes each in size
+        */
+       pp->cmd_slot = mem;
+       pp->cmd_slot_dma = mem_dma;
+
+       mem += AHCI_CMD_SLOT_SZ;
+       mem_dma += AHCI_CMD_SLOT_SZ;
+
+       /*
+        * Second item: Received-FIS area
+        */
+       pp->rx_fis = mem;
+       pp->rx_fis_dma = mem_dma;
+
+       mem += rx_fis_sz;
+       mem_dma += rx_fis_sz;
+
+       /*
+        * Third item: data area for storing a single command
+        * and its scatter-gather table
+        */
+       pp->cmd_tbl = mem;
+       pp->cmd_tbl_dma = mem_dma;
+
+       /*
+        * Save off initial list of interrupts to be enabled.
+        * This could be changed later
+        */
+       pp->intr_mask = DEF_PORT_IRQ;
+
+       ap->private_data = pp;
+
+       /* engage engines, captain */
+       return ahci_port_resume(ap);
+}
+
+static void ahci_port_stop(struct ata_port *ap)
+{
+       const char *emsg = NULL;
+       int rc;
+
+       /* de-initialize port */
+       rc = ahci_deinit_port(ap, &emsg);
+       if (rc)
+               ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
+}
+
+void ahci_print_info(struct ata_host *host, const char *scc_s)
+{
+       struct ahci_host_priv *hpriv = host->private_data;
+       void __iomem *mmio = hpriv->mmio;
+       u32 vers, cap, cap2, impl, speed;
+       const char *speed_s;
+
+       vers = readl(mmio + HOST_VERSION);
+       cap = hpriv->cap;
+       cap2 = hpriv->cap2;
+       impl = hpriv->port_map;
+
+       speed = (cap >> 20) & 0xf;
+       if (speed == 1)
+               speed_s = "1.5";
+       else if (speed == 2)
+               speed_s = "3";
+       else if (speed == 3)
+               speed_s = "6";
+       else
+               speed_s = "?";
+
+       dev_info(host->dev,
+               "AHCI %02x%02x.%02x%02x "
+               "%u slots %u ports %s Gbps 0x%x impl %s mode\n"
+               ,
+
+               (vers >> 24) & 0xff,
+               (vers >> 16) & 0xff,
+               (vers >> 8) & 0xff,
+               vers & 0xff,
+
+               ((cap >> 8) & 0x1f) + 1,
+               (cap & 0x1f) + 1,
+               speed_s,
+               impl,
+               scc_s);
+
+       dev_info(host->dev,
+               "flags: "
+               "%s%s%s%s%s%s%s"
+               "%s%s%s%s%s%s%s"
+               "%s%s%s%s%s%s\n"
+               ,
+
+               cap & HOST_CAP_64 ? "64bit " : "",
+               cap & HOST_CAP_NCQ ? "ncq " : "",
+               cap & HOST_CAP_SNTF ? "sntf " : "",
+               cap & HOST_CAP_MPS ? "ilck " : "",
+               cap & HOST_CAP_SSS ? "stag " : "",
+               cap & HOST_CAP_ALPM ? "pm " : "",
+               cap & HOST_CAP_LED ? "led " : "",
+               cap & HOST_CAP_CLO ? "clo " : "",
+               cap & HOST_CAP_ONLY ? "only " : "",
+               cap & HOST_CAP_PMP ? "pmp " : "",
+               cap & HOST_CAP_FBS ? "fbs " : "",
+               cap & HOST_CAP_PIO_MULTI ? "pio " : "",
+               cap & HOST_CAP_SSC ? "slum " : "",
+               cap & HOST_CAP_PART ? "part " : "",
+               cap & HOST_CAP_CCC ? "ccc " : "",
+               cap & HOST_CAP_EMS ? "ems " : "",
+               cap & HOST_CAP_SXS ? "sxs " : "",
+               cap2 & HOST_CAP2_APST ? "apst " : "",
+               cap2 & HOST_CAP2_NVMHCI ? "nvmp " : "",
+               cap2 & HOST_CAP2_BOH ? "boh " : ""
+               );
+}
+EXPORT_SYMBOL_GPL(ahci_print_info);
+
+void ahci_set_em_messages(struct ahci_host_priv *hpriv,
+                         struct ata_port_info *pi)
+{
+       u8 messages;
+       void __iomem *mmio = hpriv->mmio;
+       u32 em_loc = readl(mmio + HOST_EM_LOC);
+       u32 em_ctl = readl(mmio + HOST_EM_CTL);
+
+       if (!ahci_em_messages || !(hpriv->cap & HOST_CAP_EMS))
+               return;
+
+       messages = (em_ctl & EM_CTRL_MSG_TYPE) >> 16;
+
+       if (messages) {
+               /* store em_loc */
+               hpriv->em_loc = ((em_loc >> 16) * 4);
+               hpriv->em_buf_sz = ((em_loc & 0xff) * 4);
+               hpriv->em_msg_type = messages;
+               pi->flags |= ATA_FLAG_EM;
+               if (!(em_ctl & EM_CTL_ALHD))
+                       pi->flags |= ATA_FLAG_SW_ACTIVITY;
+       }
+}
+EXPORT_SYMBOL_GPL(ahci_set_em_messages);
+
+MODULE_AUTHOR("Jeff Garzik");
+MODULE_DESCRIPTION("Common AHCI SATA low-level routines");
+MODULE_LICENSE("GPL");
index 49cffb6..c47373f 100644 (file)
@@ -65,6 +65,7 @@
 #include <linux/libata.h>
 #include <asm/byteorder.h>
 #include <linux/cdrom.h>
+#include <linux/ratelimit.h>
 
 #include "libata.h"
 
@@ -96,7 +97,6 @@ static void ata_dev_xfermask(struct ata_device *dev);
 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
 
 unsigned int ata_print_id = 1;
-static struct workqueue_struct *ata_wq;
 
 struct workqueue_struct *ata_aux_wq;
 
@@ -1685,52 +1685,6 @@ unsigned long ata_id_xfermask(const u16 *id)
        return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
 }
 
-/**
- *     ata_pio_queue_task - Queue port_task
- *     @ap: The ata_port to queue port_task for
- *     @data: data for @fn to use
- *     @delay: delay time in msecs for workqueue function
- *
- *     Schedule @fn(@data) for execution after @delay jiffies using
- *     port_task.  There is one port_task per port and it's the
- *     user(low level driver)'s responsibility to make sure that only
- *     one task is active at any given time.
- *
- *     libata core layer takes care of synchronization between
- *     port_task and EH.  ata_pio_queue_task() may be ignored for EH
- *     synchronization.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-void ata_pio_queue_task(struct ata_port *ap, void *data, unsigned long delay)
-{
-       ap->port_task_data = data;
-
-       /* may fail if ata_port_flush_task() in progress */
-       queue_delayed_work(ata_wq, &ap->port_task, msecs_to_jiffies(delay));
-}
-
-/**
- *     ata_port_flush_task - Flush port_task
- *     @ap: The ata_port to flush port_task for
- *
- *     After this function completes, port_task is guranteed not to
- *     be running or scheduled.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep)
- */
-void ata_port_flush_task(struct ata_port *ap)
-{
-       DPRINTK("ENTER\n");
-
-       cancel_rearming_delayed_work(&ap->port_task);
-
-       if (ata_msg_ctl(ap))
-               ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__);
-}
-
 static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
 {
        struct completion *waiting = qc->private_data;
@@ -1852,7 +1806,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
 
        rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout));
 
-       ata_port_flush_task(ap);
+       ata_sff_flush_pio_task(ap);
 
        if (!rc) {
                spin_lock_irqsave(ap->lock, flags);
@@ -1906,22 +1860,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
        ap->qc_active = preempted_qc_active;
        ap->nr_active_links = preempted_nr_active_links;
 
-       /* XXX - Some LLDDs (sata_mv) disable port on command failure.
-        * Until those drivers are fixed, we detect the condition
-        * here, fail the command with AC_ERR_SYSTEM and reenable the
-        * port.
-        *
-        * Note that this doesn't change any behavior as internal
-        * command failure results in disabling the device in the
-        * higher layer for LLDDs without new reset/EH callbacks.
-        *
-        * Kill the following code as soon as those drivers are fixed.
-        */
-       if (ap->flags & ATA_FLAG_DISABLED) {
-               err_mask |= AC_ERR_SYSTEM;
-               ata_port_probe(ap);
-       }
-
        spin_unlock_irqrestore(ap->lock, flags);
 
        if ((err_mask & AC_ERR_TIMEOUT) && auto_timeout)
@@ -2767,8 +2705,6 @@ int ata_bus_probe(struct ata_port *ap)
        int rc;
        struct ata_device *dev;
 
-       ata_port_probe(ap);
-
        ata_for_each_dev(dev, &ap->link, ALL)
                tries[dev->devno] = ATA_PROBE_MAX_TRIES;
 
@@ -2796,8 +2732,7 @@ int ata_bus_probe(struct ata_port *ap)
        ap->ops->phy_reset(ap);
 
        ata_for_each_dev(dev, &ap->link, ALL) {
-               if (!(ap->flags & ATA_FLAG_DISABLED) &&
-                   dev->class != ATA_DEV_UNKNOWN)
+               if (dev->class != ATA_DEV_UNKNOWN)
                        classes[dev->devno] = dev->class;
                else
                        classes[dev->devno] = ATA_DEV_NONE;
@@ -2805,8 +2740,6 @@ int ata_bus_probe(struct ata_port *ap)
                dev->class = ATA_DEV_UNKNOWN;
        }
 
-       ata_port_probe(ap);
-
        /* read IDENTIFY page and configure devices. We have to do the identify
           specific sequence bass-ackwards so that PDIAG- is released by
           the slave device */
@@ -2856,8 +2789,6 @@ int ata_bus_probe(struct ata_port *ap)
        ata_for_each_dev(dev, &ap->link, ENABLED)
                return 0;
 
-       /* no device present, disable port */
-       ata_port_disable(ap);
        return -ENODEV;
 
  fail:
@@ -2888,22 +2819,6 @@ int ata_bus_probe(struct ata_port *ap)
        goto retry;
 }
 
-/**
- *     ata_port_probe - Mark port as enabled
- *     @ap: Port for which we indicate enablement
- *
- *     Modify @ap data structure such that the system
- *     thinks that the entire port is enabled.
- *
- *     LOCKING: host lock, or some other form of
- *     serialization.
- */
-
-void ata_port_probe(struct ata_port *ap)
-{
-       ap->flags &= ~ATA_FLAG_DISABLED;
-}
-
 /**
  *     sata_print_link_status - Print SATA link status
  *     @link: SATA link to printk link status about
@@ -2950,26 +2865,6 @@ struct ata_device *ata_dev_pair(struct ata_device *adev)
        return pair;
 }
 
-/**
- *     ata_port_disable - Disable port.
- *     @ap: Port to be disabled.
- *
- *     Modify @ap data structure such that the system
- *     thinks that the entire port is disabled, and should
- *     never attempt to probe or communicate with devices
- *     on this port.
- *
- *     LOCKING: host lock, or some other form of
- *     serialization.
- */
-
-void ata_port_disable(struct ata_port *ap)
-{
-       ap->link.device[0].class = ATA_DEV_NONE;
-       ap->link.device[1].class = ATA_DEV_NONE;
-       ap->flags |= ATA_FLAG_DISABLED;
-}
-
 /**
  *     sata_down_spd_limit - adjust SATA spd limit downward
  *     @link: Link to adjust SATA spd limit for
@@ -3631,9 +3526,15 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
                   int (*check_ready)(struct ata_link *link))
 {
        unsigned long start = jiffies;
-       unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
+       unsigned long nodev_deadline;
        int warned = 0;
 
+       /* choose which 0xff timeout to use, read comment in libata.h */
+       if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN)
+               nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT_LONG);
+       else
+               nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
+
        /* Slave readiness can't be tested separately from master.  On
         * M/S emulation configuration, this function should be called
         * only on the master and it will handle both master and slave.
@@ -3651,12 +3552,12 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
                if (ready > 0)
                        return 0;
 
-               /* -ENODEV could be transient.  Ignore -ENODEV if link
+               /*
+                * -ENODEV could be transient.  Ignore -ENODEV if link
                 * is online.  Also, some SATA devices take a long
-                * time to clear 0xff after reset.  For example,
-                * HHD424020F7SV00 iVDR needs >= 800ms while Quantum
-                * GoVault needs even more than that.  Wait for
-                * ATA_TMOUT_FF_WAIT on -ENODEV if link isn't offline.
+                * time to clear 0xff after reset.  Wait for
+                * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't
+                * offline.
                 *
                 * Note that some PATA controllers (pata_ali) explode
                 * if status register is read more than once when
@@ -5557,30 +5458,6 @@ void ata_host_resume(struct ata_host *host)
 }
 #endif
 
-/**
- *     ata_port_start - Set port up for dma.
- *     @ap: Port to initialize
- *
- *     Called just after data structures for each port are
- *     initialized.  Allocates space for PRD table.
- *
- *     May be used as the port_start() entry in ata_port_operations.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-int ata_port_start(struct ata_port *ap)
-{
-       struct device *dev = ap->dev;
-
-       ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma,
-                                     GFP_KERNEL);
-       if (!ap->prd)
-               return -ENOMEM;
-
-       return 0;
-}
-
 /**
  *     ata_dev_init - Initialize an ata_device structure
  *     @dev: Device structure to initialize
@@ -5709,12 +5586,9 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
 
        ap->pflags |= ATA_PFLAG_INITIALIZING;
        ap->lock = &host->lock;
-       ap->flags = ATA_FLAG_DISABLED;
        ap->print_id = -1;
-       ap->ctl = ATA_DEVCTL_OBS;
        ap->host = host;
        ap->dev = host->dev;
-       ap->last_ctl = 0xFF;
 
 #if defined(ATA_VERBOSE_DEBUG)
        /* turn on all debugging levels */
@@ -5725,11 +5599,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
-#ifdef CONFIG_ATA_SFF
-       INIT_DELAYED_WORK(&ap->port_task, ata_pio_task);
-#else
-       INIT_DELAYED_WORK(&ap->port_task, NULL);
-#endif
        INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
        INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
        INIT_LIST_HEAD(&ap->eh_done_q);
@@ -5747,6 +5616,8 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        ap->stats.unhandled_irq = 1;
        ap->stats.idle_irq = 1;
 #endif
+       ata_sff_port_init(ap);
+
        return ap;
 }
 
@@ -6138,8 +6009,6 @@ static void async_port_probe(void *data, async_cookie_t cookie)
                struct ata_eh_info *ehi = &ap->link.eh_info;
                unsigned long flags;
 
-               ata_port_probe(ap);
-
                /* kick EH for boot probing */
                spin_lock_irqsave(ap->lock, flags);
 
@@ -6663,62 +6532,43 @@ static void __init ata_parse_force_param(void)
 
 static int __init ata_init(void)
 {
-       ata_parse_force_param();
+       int rc = -ENOMEM;
 
-       /*
-        * FIXME: In UP case, there is only one workqueue thread and if you
-        * have more than one PIO device, latency is bloody awful, with
-        * occasional multi-second "hiccups" as one PIO device waits for
-        * another.  It's an ugly wart that users DO occasionally complain
-        * about; luckily most users have at most one PIO polled device.
-        */
-       ata_wq = create_workqueue("ata");
-       if (!ata_wq)
-               goto free_force_tbl;
+       ata_parse_force_param();
 
        ata_aux_wq = create_singlethread_workqueue("ata_aux");
        if (!ata_aux_wq)
-               goto free_wq;
+               goto fail;
+
+       rc = ata_sff_init();
+       if (rc)
+               goto fail;
 
        printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
        return 0;
 
-free_wq:
-       destroy_workqueue(ata_wq);
-free_force_tbl:
+fail:
        kfree(ata_force_tbl);
-       return -ENOMEM;
+       if (ata_aux_wq)
+               destroy_workqueue(ata_aux_wq);
+       return rc;
 }
 
 static void __exit ata_exit(void)
 {
+       ata_sff_exit();
        kfree(ata_force_tbl);
-       destroy_workqueue(ata_wq);
        destroy_workqueue(ata_aux_wq);
 }
 
 subsys_initcall(ata_init);
 module_exit(ata_exit);
 
-static unsigned long ratelimit_time;
-static DEFINE_SPINLOCK(ata_ratelimit_lock);
+static DEFINE_RATELIMIT_STATE(ratelimit, HZ / 5, 1);
 
 int ata_ratelimit(void)
 {
-       int rc;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ata_ratelimit_lock, flags);
-
-       if (time_after(jiffies, ratelimit_time)) {
-               rc = 1;
-               ratelimit_time = jiffies + (HZ/5);
-       } else
-               rc = 0;
-
-       spin_unlock_irqrestore(&ata_ratelimit_lock, flags);
-
-       return rc;
+       return __ratelimit(&ratelimit);
 }
 
 /**
@@ -6826,11 +6676,9 @@ EXPORT_SYMBOL_GPL(ata_xfer_mode2mask);
 EXPORT_SYMBOL_GPL(ata_xfer_mode2shift);
 EXPORT_SYMBOL_GPL(ata_mode_string);
 EXPORT_SYMBOL_GPL(ata_id_xfermask);
-EXPORT_SYMBOL_GPL(ata_port_start);
 EXPORT_SYMBOL_GPL(ata_do_set_mode);
 EXPORT_SYMBOL_GPL(ata_std_qc_defer);
 EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
-EXPORT_SYMBOL_GPL(ata_port_probe);
 EXPORT_SYMBOL_GPL(ata_dev_disable);
 EXPORT_SYMBOL_GPL(sata_set_spd);
 EXPORT_SYMBOL_GPL(ata_wait_after_reset);
@@ -6842,7 +6690,6 @@ EXPORT_SYMBOL_GPL(sata_std_hardreset);
 EXPORT_SYMBOL_GPL(ata_std_postreset);
 EXPORT_SYMBOL_GPL(ata_dev_classify);
 EXPORT_SYMBOL_GPL(ata_dev_pair);
-EXPORT_SYMBOL_GPL(ata_port_disable);
 EXPORT_SYMBOL_GPL(ata_ratelimit);
 EXPORT_SYMBOL_GPL(ata_wait_register);
 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
@@ -6864,7 +6711,6 @@ EXPORT_SYMBOL_GPL(ata_id_c_string);
 EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
 
-EXPORT_SYMBOL_GPL(ata_pio_queue_task);
 EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
 EXPORT_SYMBOL_GPL(ata_timing_find_mode);
 EXPORT_SYMBOL_GPL(ata_timing_compute);
index 228740f..f77a673 100644 (file)
@@ -550,8 +550,8 @@ void ata_scsi_error(struct Scsi_Host *host)
 
        DPRINTK("ENTER\n");
 
-       /* synchronize with port task */
-       ata_port_flush_task(ap);
+       /* make sure sff pio task is not running */
+       ata_sff_flush_pio_task(ap);
 
        /* synchronize with host lock and sort out timeouts */
 
@@ -3684,7 +3684,7 @@ void ata_std_error_handler(struct ata_port *ap)
        ata_reset_fn_t hardreset = ops->hardreset;
 
        /* ignore built-in hardreset if SCR access is not available */
-       if (ata_is_builtin_hardreset(hardreset) && !sata_scr_valid(&ap->link))
+       if (hardreset == sata_std_hardreset && !sata_scr_valid(&ap->link))
                hardreset = NULL;
 
        ata_do_eh(ap, ops->prereset, ops->softreset, hardreset, ops->postreset);
index 00305f4..224faab 100644 (file)
@@ -231,10 +231,14 @@ static const char *sata_pmp_spec_rev_str(const u32 *gscr)
        return "<unknown>";
 }
 
+#define PMP_GSCR_SII_POL 129
+
 static int sata_pmp_configure(struct ata_device *dev, int print_info)
 {
        struct ata_port *ap = dev->link->ap;
        u32 *gscr = dev->gscr;
+       u16 vendor = sata_pmp_gscr_vendor(gscr);
+       u16 devid = sata_pmp_gscr_devid(gscr);
        unsigned int err_mask = 0;
        const char *reason;
        int nr_ports, rc;
@@ -260,12 +264,34 @@ static int sata_pmp_configure(struct ata_device *dev, int print_info)
                goto fail;
        }
 
+       /* Disable sending Early R_OK.
+        * With "cached read" HDD testing and multiple ports busy on a SATA
+        * host controller, 3726 PMP will very rarely drop a deferred
+        * R_OK that was intended for the host. Symptom will be all
+        * 5 drives under test will timeout, get reset, and recover.
+        */
+       if (vendor == 0x1095 && devid == 0x3726) {
+               u32 reg;
+
+               err_mask = sata_pmp_read(&ap->link, PMP_GSCR_SII_POL, &reg);
+               if (err_mask) {
+                       rc = -EIO;
+                       reason = "failed to read Sil3726 Private Register";
+                       goto fail;
+               }
+               reg &= ~0x1;
+               err_mask = sata_pmp_write(&ap->link, PMP_GSCR_SII_POL, reg);
+               if (err_mask) {
+                       rc = -EIO;
+                       reason = "failed to write Sil3726 Private Register";
+                       goto fail;
+               }
+       }
+
        if (print_info) {
                ata_dev_printk(dev, KERN_INFO, "Port Multiplier %s, "
                               "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
-                              sata_pmp_spec_rev_str(gscr),
-                              sata_pmp_gscr_vendor(gscr),
-                              sata_pmp_gscr_devid(gscr),
+                              sata_pmp_spec_rev_str(gscr), vendor, devid,
                               sata_pmp_gscr_rev(gscr),
                               nr_ports, gscr[SATA_PMP_GSCR_FEAT_EN],
                               gscr[SATA_PMP_GSCR_FEAT]);
index 0088cde..cfa9dd3 100644 (file)
@@ -3345,9 +3345,6 @@ void ata_scsi_scan_host(struct ata_port *ap, int sync)
        struct ata_link *link;
        struct ata_device *dev;
 
-       if (ap->flags & ATA_FLAG_DISABLED)
-               return;
-
  repeat:
        ata_for_each_link(link, ap, EDGE) {
                ata_for_each_dev(dev, link, ENABLED) {
index e3877b6..19ddf92 100644 (file)
 
 #include "libata.h"
 
+static struct workqueue_struct *ata_sff_wq;
+
 const struct ata_port_operations ata_sff_port_ops = {
        .inherits               = &ata_base_port_ops,
 
-       .qc_prep                = ata_sff_qc_prep,
+       .qc_prep                = ata_noop_qc_prep,
        .qc_issue               = ata_sff_qc_issue,
        .qc_fill_rtf            = ata_sff_qc_fill_rtf,
 
@@ -53,9 +55,7 @@ const struct ata_port_operations ata_sff_port_ops = {
        .softreset              = ata_sff_softreset,
        .hardreset              = sata_sff_hardreset,
        .postreset              = ata_sff_postreset,
-       .drain_fifo             = ata_sff_drain_fifo,
        .error_handler          = ata_sff_error_handler,
-       .post_internal_cmd      = ata_sff_post_internal_cmd,
 
        .sff_dev_select         = ata_sff_dev_select,
        .sff_check_status       = ata_sff_check_status,
@@ -63,178 +63,13 @@ const struct ata_port_operations ata_sff_port_ops = {
        .sff_tf_read            = ata_sff_tf_read,
        .sff_exec_command       = ata_sff_exec_command,
        .sff_data_xfer          = ata_sff_data_xfer,
-       .sff_irq_on             = ata_sff_irq_on,
        .sff_irq_clear          = ata_sff_irq_clear,
+       .sff_drain_fifo         = ata_sff_drain_fifo,
 
        .lost_interrupt         = ata_sff_lost_interrupt,
-
-       .port_start             = ata_sff_port_start,
 };
 EXPORT_SYMBOL_GPL(ata_sff_port_ops);
 
-const struct ata_port_operations ata_bmdma_port_ops = {
-       .inherits               = &ata_sff_port_ops,
-
-       .mode_filter            = ata_bmdma_mode_filter,
-
-       .bmdma_setup            = ata_bmdma_setup,
-       .bmdma_start            = ata_bmdma_start,
-       .bmdma_stop             = ata_bmdma_stop,
-       .bmdma_status           = ata_bmdma_status,
-};
-EXPORT_SYMBOL_GPL(ata_bmdma_port_ops);
-
-const struct ata_port_operations ata_bmdma32_port_ops = {
-       .inherits               = &ata_bmdma_port_ops,
-
-       .sff_data_xfer          = ata_sff_data_xfer32,
-       .port_start             = ata_sff_port_start32,
-};
-EXPORT_SYMBOL_GPL(ata_bmdma32_port_ops);
-
-/**
- *     ata_fill_sg - Fill PCI IDE PRD table
- *     @qc: Metadata associated with taskfile to be transferred
- *
- *     Fill PCI IDE PRD (scatter-gather) table with segments
- *     associated with the current disk command.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- *
- */
-static void ata_fill_sg(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       struct scatterlist *sg;
-       unsigned int si, pi;
-
-       pi = 0;
-       for_each_sg(qc->sg, sg, qc->n_elem, si) {
-               u32 addr, offset;
-               u32 sg_len, len;
-
-               /* determine if physical DMA addr spans 64K boundary.
-                * Note h/w doesn't support 64-bit, so we unconditionally
-                * truncate dma_addr_t to u32.
-                */
-               addr = (u32) sg_dma_address(sg);
-               sg_len = sg_dma_len(sg);
-
-               while (sg_len) {
-                       offset = addr & 0xffff;
-                       len = sg_len;
-                       if ((offset + sg_len) > 0x10000)
-                               len = 0x10000 - offset;
-
-                       ap->prd[pi].addr = cpu_to_le32(addr);
-                       ap->prd[pi].flags_len = cpu_to_le32(len & 0xffff);
-                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
-
-                       pi++;
-                       sg_len -= len;
-                       addr += len;
-               }
-       }
-
-       ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
-}
-
-/**
- *     ata_fill_sg_dumb - Fill PCI IDE PRD table
- *     @qc: Metadata associated with taskfile to be transferred
- *
- *     Fill PCI IDE PRD (scatter-gather) table with segments
- *     associated with the current disk command. Perform the fill
- *     so that we avoid writing any length 64K records for
- *     controllers that don't follow the spec.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- *
- */
-static void ata_fill_sg_dumb(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       struct scatterlist *sg;
-       unsigned int si, pi;
-
-       pi = 0;
-       for_each_sg(qc->sg, sg, qc->n_elem, si) {
-               u32 addr, offset;
-               u32 sg_len, len, blen;
-
-               /* determine if physical DMA addr spans 64K boundary.
-                * Note h/w doesn't support 64-bit, so we unconditionally
-                * truncate dma_addr_t to u32.
-                */
-               addr = (u32) sg_dma_address(sg);
-               sg_len = sg_dma_len(sg);
-
-               while (sg_len) {
-                       offset = addr & 0xffff;
-                       len = sg_len;
-                       if ((offset + sg_len) > 0x10000)
-                               len = 0x10000 - offset;
-
-                       blen = len & 0xffff;
-                       ap->prd[pi].addr = cpu_to_le32(addr);
-                       if (blen == 0) {
-                               /* Some PATA chipsets like the CS5530 can't
-                                  cope with 0x0000 meaning 64K as the spec
-                                  says */
-                               ap->prd[pi].flags_len = cpu_to_le32(0x8000);
-                               blen = 0x8000;
-                               ap->prd[++pi].addr = cpu_to_le32(addr + 0x8000);
-                       }
-                       ap->prd[pi].flags_len = cpu_to_le32(blen);
-                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
-
-                       pi++;
-                       sg_len -= len;
-                       addr += len;
-               }
-       }
-
-       ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
-}
-
-/**
- *     ata_sff_qc_prep - Prepare taskfile for submission
- *     @qc: Metadata associated with taskfile to be prepared
- *
- *     Prepare ATA taskfile for submission.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- */
-void ata_sff_qc_prep(struct ata_queued_cmd *qc)
-{
-       if (!(qc->flags & ATA_QCFLAG_DMAMAP))
-               return;
-
-       ata_fill_sg(qc);
-}
-EXPORT_SYMBOL_GPL(ata_sff_qc_prep);
-
-/**
- *     ata_sff_dumb_qc_prep - Prepare taskfile for submission
- *     @qc: Metadata associated with taskfile to be prepared
- *
- *     Prepare ATA taskfile for submission.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- */
-void ata_sff_dumb_qc_prep(struct ata_queued_cmd *qc)
-{
-       if (!(qc->flags & ATA_QCFLAG_DMAMAP))
-               return;
-
-       ata_fill_sg_dumb(qc);
-}
-EXPORT_SYMBOL_GPL(ata_sff_dumb_qc_prep);
-
 /**
  *     ata_sff_check_status - Read device status reg & clear interrupt
  *     @ap: port where the device is
@@ -445,6 +280,27 @@ int ata_sff_wait_ready(struct ata_link *link, unsigned long deadline)
 }
 EXPORT_SYMBOL_GPL(ata_sff_wait_ready);
 
+/**
+ *     ata_sff_set_devctl - Write device control reg
+ *     @ap: port where the device is
+ *     @ctl: value to write
+ *
+ *     Writes ATA taskfile device control register.
+ *
+ *     Note: may NOT be used as the sff_set_devctl() entry in
+ *     ata_port_operations.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+static void ata_sff_set_devctl(struct ata_port *ap, u8 ctl)
+{
+       if (ap->ops->sff_set_devctl)
+               ap->ops->sff_set_devctl(ap, ctl);
+       else
+               iowrite8(ctl, ap->ioaddr.ctl_addr);
+}
+
 /**
  *     ata_sff_dev_select - Select device 0/1 on ATA bus
  *     @ap: ATA channel to manipulate
@@ -491,7 +347,7 @@ EXPORT_SYMBOL_GPL(ata_sff_dev_select);
  *     LOCKING:
  *     caller.
  */
-void ata_dev_select(struct ata_port *ap, unsigned int device,
+static void ata_dev_select(struct ata_port *ap, unsigned int device,
                           unsigned int wait, unsigned int can_sleep)
 {
        if (ata_msg_probe(ap))
@@ -517,24 +373,29 @@ void ata_dev_select(struct ata_port *ap, unsigned int device,
  *     Enable interrupts on a legacy IDE device using MMIO or PIO,
  *     wait for idle, clear any pending interrupts.
  *
+ *     Note: may NOT be used as the sff_irq_on() entry in
+ *     ata_port_operations.
+ *
  *     LOCKING:
  *     Inherited from caller.
  */
-u8 ata_sff_irq_on(struct ata_port *ap)
+void ata_sff_irq_on(struct ata_port *ap)
 {
        struct ata_ioports *ioaddr = &ap->ioaddr;
-       u8 tmp;
+
+       if (ap->ops->sff_irq_on) {
+               ap->ops->sff_irq_on(ap);
+               return;
+       }
 
        ap->ctl &= ~ATA_NIEN;
        ap->last_ctl = ap->ctl;
 
-       if (ioaddr->ctl_addr)
-               iowrite8(ap->ctl, ioaddr->ctl_addr);
-       tmp = ata_wait_idle(ap);
+       if (ap->ops->sff_set_devctl || ioaddr->ctl_addr)
+               ata_sff_set_devctl(ap, ap->ctl);
+       ata_wait_idle(ap);
 
        ap->ops->sff_irq_clear(ap);
-
-       return tmp;
 }
 EXPORT_SYMBOL_GPL(ata_sff_irq_on);
 
@@ -579,7 +440,6 @@ void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
                if (ioaddr->ctl_addr)
                        iowrite8(tf->ctl, ioaddr->ctl_addr);
                ap->last_ctl = tf->ctl;
-               ata_wait_idle(ap);
        }
 
        if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
@@ -615,8 +475,6 @@ void ata_sff_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
                iowrite8(tf->device, ioaddr->device_addr);
                VPRINTK("device 0x%X\n", tf->device);
        }
-
-       ata_wait_idle(ap);
 }
 EXPORT_SYMBOL_GPL(ata_sff_tf_load);
 
@@ -894,7 +752,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
                                       do_write);
        }
 
-       if (!do_write)
+       if (!do_write && !PageSlab(page))
                flush_dcache_page(page);
 
        qc->curbytes += qc->sect_size;
@@ -1165,7 +1023,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
                        qc = ata_qc_from_tag(ap, qc->tag);
                        if (qc) {
                                if (likely(!(qc->err_mask & AC_ERR_HSM))) {
-                                       ap->ops->sff_irq_on(ap);
+                                       ata_sff_irq_on(ap);
                                        ata_qc_complete(qc);
                                } else
                                        ata_port_freeze(ap);
@@ -1181,7 +1039,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
        } else {
                if (in_wq) {
                        spin_lock_irqsave(ap->lock, flags);
-                       ap->ops->sff_irq_on(ap);
+                       ata_sff_irq_on(ap);
                        ata_qc_complete(qc);
                        spin_unlock_irqrestore(ap->lock, flags);
                } else
@@ -1293,7 +1151,7 @@ fsm_start:
                if (in_wq)
                        spin_unlock_irqrestore(ap->lock, flags);
 
-               /* if polling, ata_pio_task() handles the rest.
+               /* if polling, ata_sff_pio_task() handles the rest.
                 * otherwise, interrupt handler takes over from here.
                 */
                break;
@@ -1458,14 +1316,38 @@ fsm_start:
 }
 EXPORT_SYMBOL_GPL(ata_sff_hsm_move);
 
-void ata_pio_task(struct work_struct *work)
+void ata_sff_queue_pio_task(struct ata_port *ap, unsigned long delay)
+{
+       /* may fail if ata_sff_flush_pio_task() in progress */
+       queue_delayed_work(ata_sff_wq, &ap->sff_pio_task,
+                          msecs_to_jiffies(delay));
+}
+EXPORT_SYMBOL_GPL(ata_sff_queue_pio_task);
+
+void ata_sff_flush_pio_task(struct ata_port *ap)
+{
+       DPRINTK("ENTER\n");
+
+       cancel_rearming_delayed_work(&ap->sff_pio_task);
+       ap->hsm_task_state = HSM_ST_IDLE;
+
+       if (ata_msg_ctl(ap))
+               ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__);
+}
+
+static void ata_sff_pio_task(struct work_struct *work)
 {
        struct ata_port *ap =
-               container_of(work, struct ata_port, port_task.work);
-       struct ata_queued_cmd *qc = ap->port_task_data;
+               container_of(work, struct ata_port, sff_pio_task.work);
+       struct ata_queued_cmd *qc;
        u8 status;
        int poll_next;
 
+       /* qc can be NULL if timeout occurred */
+       qc = ata_qc_from_tag(ap, ap->link.active_tag);
+       if (!qc)
+               return;
+
 fsm_start:
        WARN_ON_ONCE(ap->hsm_task_state == HSM_ST_IDLE);
 
@@ -1481,7 +1363,7 @@ fsm_start:
                msleep(2);
                status = ata_sff_busy_wait(ap, ATA_BUSY, 10);
                if (status & ATA_BUSY) {
-                       ata_pio_queue_task(ap, qc, ATA_SHORT_PAUSE);
+                       ata_sff_queue_pio_task(ap, ATA_SHORT_PAUSE);
                        return;
                }
        }
@@ -1497,15 +1379,11 @@ fsm_start:
 }
 
 /**
- *     ata_sff_qc_issue - issue taskfile to device in proto-dependent manner
+ *     ata_sff_qc_issue - issue taskfile to a SFF controller
  *     @qc: command to issue to device
  *
- *     Using various libata functions and hooks, this function
- *     starts an ATA command.  ATA commands are grouped into
- *     classes called "protocols", and issuing each type of protocol
- *     is slightly different.
- *
- *     May be used as the qc_issue() entry in ata_port_operations.
+ *     This function issues a PIO or NODATA command to a SFF
+ *     controller.
  *
  *     LOCKING:
  *     spin_lock_irqsave(host lock)
@@ -1520,23 +1398,8 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
        /* Use polling pio if the LLD doesn't handle
         * interrupt driven pio and atapi CDB interrupt.
         */
-       if (ap->flags & ATA_FLAG_PIO_POLLING) {
-               switch (qc->tf.protocol) {
-               case ATA_PROT_PIO:
-               case ATA_PROT_NODATA:
-               case ATAPI_PROT_PIO:
-               case ATAPI_PROT_NODATA:
-                       qc->tf.flags |= ATA_TFLAG_POLLING;
-                       break;
-               case ATAPI_PROT_DMA:
-                       if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
-                               /* see ata_dma_blacklisted() */
-                               BUG();
-                       break;
-               default:
-                       break;
-               }
-       }
+       if (ap->flags & ATA_FLAG_PIO_POLLING)
+               qc->tf.flags |= ATA_TFLAG_POLLING;
 
        /* select the device */
        ata_dev_select(ap, qc->dev->devno, 1, 0);
@@ -1551,17 +1414,8 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
                ap->hsm_task_state = HSM_ST_LAST;
 
                if (qc->tf.flags & ATA_TFLAG_POLLING)
-                       ata_pio_queue_task(ap, qc, 0);
-
-               break;
-
-       case ATA_PROT_DMA:
-               WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING);
+                       ata_sff_queue_pio_task(ap, 0);
 
-               ap->ops->sff_tf_load(ap, &qc->tf);  /* load tf registers */
-               ap->ops->bmdma_setup(qc);           /* set up bmdma */
-               ap->ops->bmdma_start(qc);           /* initiate bmdma */
-               ap->hsm_task_state = HSM_ST_LAST;
                break;
 
        case ATA_PROT_PIO:
@@ -1573,20 +1427,21 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
                if (qc->tf.flags & ATA_TFLAG_WRITE) {
                        /* PIO data out protocol */
                        ap->hsm_task_state = HSM_ST_FIRST;
-                       ata_pio_queue_task(ap, qc, 0);
+                       ata_sff_queue_pio_task(ap, 0);
 
-                       /* always send first data block using
-                        * the ata_pio_task() codepath.
+                       /* always send first data block using the
+                        * ata_sff_pio_task() codepath.
                         */
                } else {
                        /* PIO data in protocol */
                        ap->hsm_task_state = HSM_ST;
 
                        if (qc->tf.flags & ATA_TFLAG_POLLING)
-                               ata_pio_queue_task(ap, qc, 0);
+                               ata_sff_queue_pio_task(ap, 0);
 
-                       /* if polling, ata_pio_task() handles the rest.
-                        * otherwise, interrupt handler takes over from here.
+                       /* if polling, ata_sff_pio_task() handles the
+                        * rest.  otherwise, interrupt handler takes
+                        * over from here.
                         */
                }
 
@@ -1604,19 +1459,7 @@ unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc)
                /* send cdb by polling if no cdb interrupt */
                if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
                    (qc->tf.flags & ATA_TFLAG_POLLING))
-                       ata_pio_queue_task(ap, qc, 0);
-               break;
-
-       case ATAPI_PROT_DMA:
-               WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING);
-
-               ap->ops->sff_tf_load(ap, &qc->tf);  /* load tf registers */
-               ap->ops->bmdma_setup(qc);           /* set up bmdma */
-               ap->hsm_task_state = HSM_ST_FIRST;
-
-               /* send cdb by polling if no cdb interrupt */
-               if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
-                       ata_pio_queue_task(ap, qc, 0);
+                       ata_sff_queue_pio_task(ap, 0);
                break;
 
        default:
@@ -1728,7 +1571,7 @@ unsigned int ata_sff_host_intr(struct ata_port *ap,
                        goto idle_irq;
        }
 
-       /* ack bmdma irq events */
+       /* clear irq events */
        ap->ops->sff_irq_clear(ap);
 
        ata_sff_hsm_move(ap, qc, status, 0);
@@ -1785,9 +1628,6 @@ retry:
                struct ata_port *ap = host->ports[i];
                struct ata_queued_cmd *qc;
 
-               if (unlikely(ap->flags & ATA_FLAG_DISABLED))
-                       continue;
-
                qc = ata_qc_from_tag(ap, ap->link.active_tag);
                if (qc) {
                        if (!(qc->tf.flags & ATA_TFLAG_POLLING))
@@ -1862,11 +1702,8 @@ void ata_sff_lost_interrupt(struct ata_port *ap)
 
        /* Only one outstanding command per SFF channel */
        qc = ata_qc_from_tag(ap, ap->link.active_tag);
-       /* Check we have a live one.. */
-       if (qc == NULL ||  !(qc->flags & ATA_QCFLAG_ACTIVE))
-               return;
-       /* We cannot lose an interrupt on a polled command */
-       if (qc->tf.flags & ATA_TFLAG_POLLING)
+       /* We cannot lose an interrupt on a non-existent or polled command */
+       if (!qc || qc->tf.flags & ATA_TFLAG_POLLING)
                return;
        /* See if the controller thinks it is still busy - if so the command
           isn't a lost IRQ but is still in progress */
@@ -1888,20 +1725,18 @@ EXPORT_SYMBOL_GPL(ata_sff_lost_interrupt);
  *     ata_sff_freeze - Freeze SFF controller port
  *     @ap: port to freeze
  *
- *     Freeze BMDMA controller port.
+ *     Freeze SFF controller port.
  *
  *     LOCKING:
  *     Inherited from caller.
  */
 void ata_sff_freeze(struct ata_port *ap)
 {
-       struct ata_ioports *ioaddr = &ap->ioaddr;
-
        ap->ctl |= ATA_NIEN;
        ap->last_ctl = ap->ctl;
 
-       if (ioaddr->ctl_addr)
-               iowrite8(ap->ctl, ioaddr->ctl_addr);
+       if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr)
+               ata_sff_set_devctl(ap, ap->ctl);
 
        /* Under certain circumstances, some controllers raise IRQ on
         * ATA_NIEN manipulation.  Also, many controllers fail to mask
@@ -1927,7 +1762,7 @@ void ata_sff_thaw(struct ata_port *ap)
        /* clear & re-enable interrupts */
        ap->ops->sff_check_status(ap);
        ap->ops->sff_irq_clear(ap);
-       ap->ops->sff_irq_on(ap);
+       ata_sff_irq_on(ap);
 }
 EXPORT_SYMBOL_GPL(ata_sff_thaw);
 
@@ -2301,8 +2136,8 @@ void ata_sff_postreset(struct ata_link *link, unsigned int *classes)
        }
 
        /* set up device control */
-       if (ap->ioaddr.ctl_addr) {
-               iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
+       if (ap->ops->sff_set_devctl || ap->ioaddr.ctl_addr) {
+               ata_sff_set_devctl(ap, ap->ctl);
                ap->last_ctl = ap->ctl;
        }
 }
@@ -2342,7 +2177,7 @@ void ata_sff_drain_fifo(struct ata_queued_cmd *qc)
 EXPORT_SYMBOL_GPL(ata_sff_drain_fifo);
 
 /**
- *     ata_sff_error_handler - Stock error handler for BMDMA controller
+ *     ata_sff_error_handler - Stock error handler for SFF controller
  *     @ap: port to handle error for
  *
  *     Stock error handler for SFF controller.  It can handle both
@@ -2359,62 +2194,32 @@ void ata_sff_error_handler(struct ata_port *ap)
        ata_reset_fn_t hardreset = ap->ops->hardreset;
        struct ata_queued_cmd *qc;
        unsigned long flags;
-       int thaw = 0;
 
        qc = __ata_qc_from_tag(ap, ap->link.active_tag);
        if (qc && !(qc->flags & ATA_QCFLAG_FAILED))
                qc = NULL;
 
-       /* reset PIO HSM and stop DMA engine */
        spin_lock_irqsave(ap->lock, flags);
 
-       ap->hsm_task_state = HSM_ST_IDLE;
-
-       if (ap->ioaddr.bmdma_addr &&
-           qc && (qc->tf.protocol == ATA_PROT_DMA ||
-                  qc->tf.protocol == ATAPI_PROT_DMA)) {
-               u8 host_stat;
-
-               host_stat = ap->ops->bmdma_status(ap);
-
-               /* BMDMA controllers indicate host bus error by
-                * setting DMA_ERR bit and timing out.  As it wasn't
-                * really a timeout event, adjust error mask and
-                * cancel frozen state.
-                */
-               if (qc->err_mask == AC_ERR_TIMEOUT
-                                               && (host_stat & ATA_DMA_ERR)) {
-                       qc->err_mask = AC_ERR_HOST_BUS;
-                       thaw = 1;
-               }
-
-               ap->ops->bmdma_stop(qc);
-       }
-
-       ata_sff_sync(ap);               /* FIXME: We don't need this */
-       ap->ops->sff_check_status(ap);
-       ap->ops->sff_irq_clear(ap);
-       /* We *MUST* do FIFO draining before we issue a reset as several
-        * devices helpfully clear their internal state and will lock solid
-        * if we touch the data port post reset. Pass qc in case anyone wants
-        *  to do different PIO/DMA recovery or has per command fixups
+       /*
+        * We *MUST* do FIFO draining before we issue a reset as
+        * several devices helpfully clear their internal state and
+        * will lock solid if we touch the data port post reset. Pass
+        * qc in case anyone wants to do different PIO/DMA recovery or
+        * has per command fixups
         */
-       if (ap->ops->drain_fifo)
-               ap->ops->drain_fifo(qc);
+       if (ap->ops->sff_drain_fifo)
+               ap->ops->sff_drain_fifo(qc);
 
        spin_unlock_irqrestore(ap->lock, flags);
 
-       if (thaw)
-               ata_eh_thaw_port(ap);
-
-       /* PIO and DMA engines have been stopped, perform recovery */
-
-       /* Ignore ata_sff_softreset if ctl isn't accessible and
-        * built-in hardresets if SCR access isn't available.
-        */
+       /* ignore ata_sff_softreset if ctl isn't accessible */
        if (softreset == ata_sff_softreset && !ap->ioaddr.ctl_addr)
                softreset = NULL;
-       if (ata_is_builtin_hardreset(hardreset) && !sata_scr_valid(&ap->link))
+
+       /* ignore built-in hardresets if SCR access is not available */
+       if ((hardreset == sata_std_hardreset ||
+            hardreset == sata_sff_hardreset) && !sata_scr_valid(&ap->link))
                hardreset = NULL;
 
        ata_do_eh(ap, ap->ops->prereset, softreset, hardreset,
@@ -2423,84 +2228,17 @@ void ata_sff_error_handler(struct ata_port *ap)
 EXPORT_SYMBOL_GPL(ata_sff_error_handler);
 
 /**
- *     ata_sff_post_internal_cmd - Stock post_internal_cmd for SFF controller
- *     @qc: internal command to clean up
+ *     ata_sff_std_ports - initialize ioaddr with standard port offsets.
+ *     @ioaddr: IO address structure to be initialized
  *
- *     LOCKING:
- *     Kernel thread context (may sleep)
+ *     Utility function which initializes data_addr, error_addr,
+ *     feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
+ *     device_addr, status_addr, and command_addr to standard offsets
+ *     relative to cmd_addr.
+ *
+ *     Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
  */
-void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       unsigned long flags;
-
-       spin_lock_irqsave(ap->lock, flags);
-
-       ap->hsm_task_state = HSM_ST_IDLE;
-
-       if (ap->ioaddr.bmdma_addr)
-               ap->ops->bmdma_stop(qc);
-
-       spin_unlock_irqrestore(ap->lock, flags);
-}
-EXPORT_SYMBOL_GPL(ata_sff_post_internal_cmd);
-
-/**
- *     ata_sff_port_start - Set port up for dma.
- *     @ap: Port to initialize
- *
- *     Called just after data structures for each port are
- *     initialized.  Allocates space for PRD table if the device
- *     is DMA capable SFF.
- *
- *     May be used as the port_start() entry in ata_port_operations.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-int ata_sff_port_start(struct ata_port *ap)
-{
-       if (ap->ioaddr.bmdma_addr)
-               return ata_port_start(ap);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_sff_port_start);
-
-/**
- *     ata_sff_port_start32 - Set port up for dma.
- *     @ap: Port to initialize
- *
- *     Called just after data structures for each port are
- *     initialized.  Allocates space for PRD table if the device
- *     is DMA capable SFF.
- *
- *     May be used as the port_start() entry in ata_port_operations for
- *     devices that are capable of 32bit PIO.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-int ata_sff_port_start32(struct ata_port *ap)
-{
-       ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
-       if (ap->ioaddr.bmdma_addr)
-               return ata_port_start(ap);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_sff_port_start32);
-
-/**
- *     ata_sff_std_ports - initialize ioaddr with standard port offsets.
- *     @ioaddr: IO address structure to be initialized
- *
- *     Utility function which initializes data_addr, error_addr,
- *     feature_addr, nsect_addr, lbal_addr, lbam_addr, lbah_addr,
- *     device_addr, status_addr, and command_addr to standard offsets
- *     relative to cmd_addr.
- *
- *     Does not set ctl_addr, altstatus_addr, bmdma_addr, or scr_addr.
- */
-void ata_sff_std_ports(struct ata_ioports *ioaddr)
+void ata_sff_std_ports(struct ata_ioports *ioaddr)
 {
        ioaddr->data_addr = ioaddr->cmd_addr + ATA_REG_DATA;
        ioaddr->error_addr = ioaddr->cmd_addr + ATA_REG_ERR;
@@ -2515,448 +2253,145 @@ void ata_sff_std_ports(struct ata_ioports *ioaddr)
 }
 EXPORT_SYMBOL_GPL(ata_sff_std_ports);
 
-unsigned long ata_bmdma_mode_filter(struct ata_device *adev,
-                                   unsigned long xfer_mask)
+#ifdef CONFIG_PCI
+
+static int ata_resources_present(struct pci_dev *pdev, int port)
 {
-       /* Filter out DMA modes if the device has been configured by
-          the BIOS as PIO only */
+       int i;
 
-       if (adev->link->ap->ioaddr.bmdma_addr == NULL)
-               xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
-       return xfer_mask;
+       /* Check the PCI resources for this channel are enabled */
+       port = port * 2;
+       for (i = 0; i < 2; i++) {
+               if (pci_resource_start(pdev, port + i) == 0 ||
+                   pci_resource_len(pdev, port + i) == 0)
+                       return 0;
+       }
+       return 1;
 }
-EXPORT_SYMBOL_GPL(ata_bmdma_mode_filter);
 
 /**
- *     ata_bmdma_setup - Set up PCI IDE BMDMA transaction
- *     @qc: Info associated with this ATA transaction.
+ *     ata_pci_sff_init_host - acquire native PCI ATA resources and init host
+ *     @host: target ATA host
+ *
+ *     Acquire native PCI ATA resources for @host and initialize the
+ *     first two ports of @host accordingly.  Ports marked dummy are
+ *     skipped and allocation failure makes the port dummy.
+ *
+ *     Note that native PCI resources are valid even for legacy hosts
+ *     as we fix up pdev resources array early in boot, so this
+ *     function can be used for both native and legacy SFF hosts.
  *
  *     LOCKING:
- *     spin_lock_irqsave(host lock)
+ *     Inherited from calling layer (may sleep).
+ *
+ *     RETURNS:
+ *     0 if at least one port is initialized, -ENODEV if no port is
+ *     available.
  */
-void ata_bmdma_setup(struct ata_queued_cmd *qc)
+int ata_pci_sff_init_host(struct ata_host *host)
 {
-       struct ata_port *ap = qc->ap;
-       unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
-       u8 dmactl;
-
-       /* load PRD table addr. */
-       mb();   /* make sure PRD table writes are visible to controller */
-       iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
+       struct device *gdev = host->dev;
+       struct pci_dev *pdev = to_pci_dev(gdev);
+       unsigned int mask = 0;
+       int i, rc;
 
-       /* specify data direction, triple-check start bit is clear */
-       dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
-       if (!rw)
-               dmactl |= ATA_DMA_WR;
-       iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+       /* request, iomap BARs and init port addresses accordingly */
+       for (i = 0; i < 2; i++) {
+               struct ata_port *ap = host->ports[i];
+               int base = i * 2;
+               void __iomem * const *iomap;
 
-       /* issue r/w command */
-       ap->ops->sff_exec_command(ap, &qc->tf);
-}
-EXPORT_SYMBOL_GPL(ata_bmdma_setup);
+               if (ata_port_is_dummy(ap))
+                       continue;
 
-/**
- *     ata_bmdma_start - Start a PCI IDE BMDMA transaction
- *     @qc: Info associated with this ATA transaction.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- */
-void ata_bmdma_start(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       u8 dmactl;
+               /* Discard disabled ports.  Some controllers show
+                * their unused channels this way.  Disabled ports are
+                * made dummy.
+                */
+               if (!ata_resources_present(pdev, i)) {
+                       ap->ops = &ata_dummy_port_ops;
+                       continue;
+               }
 
-       /* start host DMA transaction */
-       dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
-       iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+               rc = pcim_iomap_regions(pdev, 0x3 << base,
+                                       dev_driver_string(gdev));
+               if (rc) {
+                       dev_printk(KERN_WARNING, gdev,
+                                  "failed to request/iomap BARs for port %d "
+                                  "(errno=%d)\n", i, rc);
+                       if (rc == -EBUSY)
+                               pcim_pin_device(pdev);
+                       ap->ops = &ata_dummy_port_ops;
+                       continue;
+               }
+               host->iomap = iomap = pcim_iomap_table(pdev);
 
-       /* Strictly, one may wish to issue an ioread8() here, to
-        * flush the mmio write.  However, control also passes
-        * to the hardware at this point, and it will interrupt
-        * us when we are to resume control.  So, in effect,
-        * we don't care when the mmio write flushes.
-        * Further, a read of the DMA status register _immediately_
-        * following the write may not be what certain flaky hardware
-        * is expected, so I think it is best to not add a readb()
-        * without first all the MMIO ATA cards/mobos.
-        * Or maybe I'm just being paranoid.
-        *
-        * FIXME: The posting of this write means I/O starts are
-        * unneccessarily delayed for MMIO
-        */
-}
-EXPORT_SYMBOL_GPL(ata_bmdma_start);
+               ap->ioaddr.cmd_addr = iomap[base];
+               ap->ioaddr.altstatus_addr =
+               ap->ioaddr.ctl_addr = (void __iomem *)
+                       ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
+               ata_sff_std_ports(&ap->ioaddr);
 
-/**
- *     ata_bmdma_stop - Stop PCI IDE BMDMA transfer
- *     @qc: Command we are ending DMA for
- *
- *     Clears the ATA_DMA_START flag in the dma control register
- *
- *     May be used as the bmdma_stop() entry in ata_port_operations.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- */
-void ata_bmdma_stop(struct ata_queued_cmd *qc)
-{
-       struct ata_port *ap = qc->ap;
-       void __iomem *mmio = ap->ioaddr.bmdma_addr;
+               ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
+                       (unsigned long long)pci_resource_start(pdev, base),
+                       (unsigned long long)pci_resource_start(pdev, base + 1));
 
-       /* clear start/stop bit */
-       iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
-                mmio + ATA_DMA_CMD);
+               mask |= 1 << i;
+       }
 
-       /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
-       ata_sff_dma_pause(ap);
-}
-EXPORT_SYMBOL_GPL(ata_bmdma_stop);
+       if (!mask) {
+               dev_printk(KERN_ERR, gdev, "no available native port\n");
+               return -ENODEV;
+       }
 
-/**
- *     ata_bmdma_status - Read PCI IDE BMDMA status
- *     @ap: Port associated with this ATA transaction.
- *
- *     Read and return BMDMA status register.
- *
- *     May be used as the bmdma_status() entry in ata_port_operations.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host lock)
- */
-u8 ata_bmdma_status(struct ata_port *ap)
-{
-       return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
+       return 0;
 }
-EXPORT_SYMBOL_GPL(ata_bmdma_status);
+EXPORT_SYMBOL_GPL(ata_pci_sff_init_host);
 
 /**
- *     ata_bus_reset - reset host port and associated ATA channel
- *     @ap: port to reset
+ *     ata_pci_sff_prepare_host - helper to prepare native PCI ATA host
+ *     @pdev: target PCI device
+ *     @ppi: array of port_info, must be enough for two ports
+ *     @r_host: out argument for the initialized ATA host
  *
- *     This is typically the first time we actually start issuing
- *     commands to the ATA channel.  We wait for BSY to clear, then
- *     issue EXECUTE DEVICE DIAGNOSTIC command, polling for its
- *     result.  Determine what devices, if any, are on the channel
- *     by looking at the device 0/1 error register.  Look at the signature
- *     stored in each device's taskfile registers, to determine if
- *     the device is ATA or ATAPI.
+ *     Helper to allocate ATA host for @pdev, acquire all native PCI
+ *     resources and initialize it accordingly in one go.
  *
  *     LOCKING:
- *     PCI/etc. bus probe sem.
- *     Obtains host lock.
- *
- *     SIDE EFFECTS:
- *     Sets ATA_FLAG_DISABLED if bus reset fails.
+ *     Inherited from calling layer (may sleep).
  *
- *     DEPRECATED:
- *     This function is only for drivers which still use old EH and
- *     will be removed soon.
+ *     RETURNS:
+ *     0 on success, -errno otherwise.
  */
-void ata_bus_reset(struct ata_port *ap)
+int ata_pci_sff_prepare_host(struct pci_dev *pdev,
+                            const struct ata_port_info * const *ppi,
+                            struct ata_host **r_host)
 {
-       struct ata_device *device = ap->link.device;
-       struct ata_ioports *ioaddr = &ap->ioaddr;
-       unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
-       u8 err;
-       unsigned int dev0, dev1 = 0, devmask = 0;
+       struct ata_host *host;
        int rc;
 
-       DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
+       if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
+               return -ENOMEM;
 
-       /* determine if device 0/1 are present */
-       if (ap->flags & ATA_FLAG_SATA_RESET)
-               dev0 = 1;
-       else {
-               dev0 = ata_devchk(ap, 0);
-               if (slave_possible)
-                       dev1 = ata_devchk(ap, 1);
+       host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
+       if (!host) {
+               dev_printk(KERN_ERR, &pdev->dev,
+                          "failed to allocate ATA host\n");
+               rc = -ENOMEM;
+               goto err_out;
        }
 
-       if (dev0)
-               devmask |= (1 << 0);
-       if (dev1)
-               devmask |= (1 << 1);
+       rc = ata_pci_sff_init_host(host);
+       if (rc)
+               goto err_out;
 
-       /* select device 0 again */
-       ap->ops->sff_dev_select(ap, 0);
+       /* init DMA related stuff */
+       ata_pci_bmdma_init(host);
 
-       /* issue bus reset */
-       if (ap->flags & ATA_FLAG_SRST) {
-               rc = ata_bus_softreset(ap, devmask,
-                                      ata_deadline(jiffies, 40000));
-               if (rc && rc != -ENODEV)
-                       goto err_out;
-       }
+       devres_remove_group(&pdev->dev, NULL);
+       *r_host = host;
+       return 0;
 
-       /*
-        * determine by signature whether we have ATA or ATAPI devices
-        */
-       device[0].class = ata_sff_dev_classify(&device[0], dev0, &err);
-       if ((slave_possible) && (err != 0x81))
-               device[1].class = ata_sff_dev_classify(&device[1], dev1, &err);
-
-       /* is double-select really necessary? */
-       if (device[1].class != ATA_DEV_NONE)
-               ap->ops->sff_dev_select(ap, 1);
-       if (device[0].class != ATA_DEV_NONE)
-               ap->ops->sff_dev_select(ap, 0);
-
-       /* if no devices were detected, disable this port */
-       if ((device[0].class == ATA_DEV_NONE) &&
-           (device[1].class == ATA_DEV_NONE))
-               goto err_out;
-
-       if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
-               /* set up device control for ATA_FLAG_SATA_RESET */
-               iowrite8(ap->ctl, ioaddr->ctl_addr);
-               ap->last_ctl = ap->ctl;
-       }
-
-       DPRINTK("EXIT\n");
-       return;
-
-err_out:
-       ata_port_printk(ap, KERN_ERR, "disabling port\n");
-       ata_port_disable(ap);
-
-       DPRINTK("EXIT\n");
-}
-EXPORT_SYMBOL_GPL(ata_bus_reset);
-
-#ifdef CONFIG_PCI
-
-/**
- *     ata_pci_bmdma_clear_simplex -   attempt to kick device out of simplex
- *     @pdev: PCI device
- *
- *     Some PCI ATA devices report simplex mode but in fact can be told to
- *     enter non simplex mode. This implements the necessary logic to
- *     perform the task on such devices. Calling it on other devices will
- *     have -undefined- behaviour.
- */
-int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev)
-{
-       unsigned long bmdma = pci_resource_start(pdev, 4);
-       u8 simplex;
-
-       if (bmdma == 0)
-               return -ENOENT;
-
-       simplex = inb(bmdma + 0x02);
-       outb(simplex & 0x60, bmdma + 0x02);
-       simplex = inb(bmdma + 0x02);
-       if (simplex & 0x80)
-               return -EOPNOTSUPP;
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_pci_bmdma_clear_simplex);
-
-/**
- *     ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
- *     @host: target ATA host
- *
- *     Acquire PCI BMDMA resources and initialize @host accordingly.
- *
- *     LOCKING:
- *     Inherited from calling layer (may sleep).
- *
- *     RETURNS:
- *     0 on success, -errno otherwise.
- */
-int ata_pci_bmdma_init(struct ata_host *host)
-{
-       struct device *gdev = host->dev;
-       struct pci_dev *pdev = to_pci_dev(gdev);
-       int i, rc;
-
-       /* No BAR4 allocation: No DMA */
-       if (pci_resource_start(pdev, 4) == 0)
-               return 0;
-
-       /* TODO: If we get no DMA mask we should fall back to PIO */
-       rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
-       if (rc)
-               return rc;
-       rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
-       if (rc)
-               return rc;
-
-       /* request and iomap DMA region */
-       rc = pcim_iomap_regions(pdev, 1 << 4, dev_driver_string(gdev));
-       if (rc) {
-               dev_printk(KERN_ERR, gdev, "failed to request/iomap BAR4\n");
-               return -ENOMEM;
-       }
-       host->iomap = pcim_iomap_table(pdev);
-
-       for (i = 0; i < 2; i++) {
-               struct ata_port *ap = host->ports[i];
-               void __iomem *bmdma = host->iomap[4] + 8 * i;
-
-               if (ata_port_is_dummy(ap))
-                       continue;
-
-               ap->ioaddr.bmdma_addr = bmdma;
-               if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) &&
-                   (ioread8(bmdma + 2) & 0x80))
-                       host->flags |= ATA_HOST_SIMPLEX;
-
-               ata_port_desc(ap, "bmdma 0x%llx",
-                   (unsigned long long)pci_resource_start(pdev, 4) + 8 * i);
-       }
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_pci_bmdma_init);
-
-static int ata_resources_present(struct pci_dev *pdev, int port)
-{
-       int i;
-
-       /* Check the PCI resources for this channel are enabled */
-       port = port * 2;
-       for (i = 0; i < 2; i++) {
-               if (pci_resource_start(pdev, port + i) == 0 ||
-                   pci_resource_len(pdev, port + i) == 0)
-                       return 0;
-       }
-       return 1;
-}
-
-/**
- *     ata_pci_sff_init_host - acquire native PCI ATA resources and init host
- *     @host: target ATA host
- *
- *     Acquire native PCI ATA resources for @host and initialize the
- *     first two ports of @host accordingly.  Ports marked dummy are
- *     skipped and allocation failure makes the port dummy.
- *
- *     Note that native PCI resources are valid even for legacy hosts
- *     as we fix up pdev resources array early in boot, so this
- *     function can be used for both native and legacy SFF hosts.
- *
- *     LOCKING:
- *     Inherited from calling layer (may sleep).
- *
- *     RETURNS:
- *     0 if at least one port is initialized, -ENODEV if no port is
- *     available.
- */
-int ata_pci_sff_init_host(struct ata_host *host)
-{
-       struct device *gdev = host->dev;
-       struct pci_dev *pdev = to_pci_dev(gdev);
-       unsigned int mask = 0;
-       int i, rc;
-
-       /* request, iomap BARs and init port addresses accordingly */
-       for (i = 0; i < 2; i++) {
-               struct ata_port *ap = host->ports[i];
-               int base = i * 2;
-               void __iomem * const *iomap;
-
-               if (ata_port_is_dummy(ap))
-                       continue;
-
-               /* Discard disabled ports.  Some controllers show
-                * their unused channels this way.  Disabled ports are
-                * made dummy.
-                */
-               if (!ata_resources_present(pdev, i)) {
-                       ap->ops = &ata_dummy_port_ops;
-                       continue;
-               }
-
-               rc = pcim_iomap_regions(pdev, 0x3 << base,
-                                       dev_driver_string(gdev));
-               if (rc) {
-                       dev_printk(KERN_WARNING, gdev,
-                                  "failed to request/iomap BARs for port %d "
-                                  "(errno=%d)\n", i, rc);
-                       if (rc == -EBUSY)
-                               pcim_pin_device(pdev);
-                       ap->ops = &ata_dummy_port_ops;
-                       continue;
-               }
-               host->iomap = iomap = pcim_iomap_table(pdev);
-
-               ap->ioaddr.cmd_addr = iomap[base];
-               ap->ioaddr.altstatus_addr =
-               ap->ioaddr.ctl_addr = (void __iomem *)
-                       ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
-               ata_sff_std_ports(&ap->ioaddr);
-
-               ata_port_desc(ap, "cmd 0x%llx ctl 0x%llx",
-                       (unsigned long long)pci_resource_start(pdev, base),
-                       (unsigned long long)pci_resource_start(pdev, base + 1));
-
-               mask |= 1 << i;
-       }
-
-       if (!mask) {
-               dev_printk(KERN_ERR, gdev, "no available native port\n");
-               return -ENODEV;
-       }
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ata_pci_sff_init_host);
-
-/**
- *     ata_pci_sff_prepare_host - helper to prepare native PCI ATA host
- *     @pdev: target PCI device
- *     @ppi: array of port_info, must be enough for two ports
- *     @r_host: out argument for the initialized ATA host
- *
- *     Helper to allocate ATA host for @pdev, acquire all native PCI
- *     resources and initialize it accordingly in one go.
- *
- *     LOCKING:
- *     Inherited from calling layer (may sleep).
- *
- *     RETURNS:
- *     0 on success, -errno otherwise.
- */
-int ata_pci_sff_prepare_host(struct pci_dev *pdev,
-                            const struct ata_port_info * const *ppi,
-                            struct ata_host **r_host)
-{
-       struct ata_host *host;
-       int rc;
-
-       if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
-               return -ENOMEM;
-
-       host = ata_host_alloc_pinfo(&pdev->dev, ppi, 2);
-       if (!host) {
-               dev_printk(KERN_ERR, &pdev->dev,
-                          "failed to allocate ATA host\n");
-               rc = -ENOMEM;
-               goto err_out;
-       }
-
-       rc = ata_pci_sff_init_host(host);
-       if (rc)
-               goto err_out;
-
-       /* init DMA related stuff */
-       rc = ata_pci_bmdma_init(host);
-       if (rc)
-               goto err_bmdma;
-
-       devres_remove_group(&pdev->dev, NULL);
-       *r_host = host;
-       return 0;
-
-err_bmdma:
-       /* This is necessary because PCI and iomap resources are
-        * merged and releasing the top group won't release the
-        * acquired resources if some of those have been acquired
-        * before entering this function.
-        */
-       pcim_iounmap_regions(pdev, 0xf);
 err_out:
        devres_release_group(&pdev->dev, NULL);
        return rc;
@@ -3135,3 +2570,609 @@ out:
 EXPORT_SYMBOL_GPL(ata_pci_sff_init_one);
 
 #endif /* CONFIG_PCI */
+
+const struct ata_port_operations ata_bmdma_port_ops = {
+       .inherits               = &ata_sff_port_ops,
+
+       .error_handler          = ata_bmdma_error_handler,
+       .post_internal_cmd      = ata_bmdma_post_internal_cmd,
+
+       .qc_prep                = ata_bmdma_qc_prep,
+       .qc_issue               = ata_bmdma_qc_issue,
+
+       .bmdma_setup            = ata_bmdma_setup,
+       .bmdma_start            = ata_bmdma_start,
+       .bmdma_stop             = ata_bmdma_stop,
+       .bmdma_status           = ata_bmdma_status,
+
+       .port_start             = ata_bmdma_port_start,
+};
+EXPORT_SYMBOL_GPL(ata_bmdma_port_ops);
+
+const struct ata_port_operations ata_bmdma32_port_ops = {
+       .inherits               = &ata_bmdma_port_ops,
+
+       .sff_data_xfer          = ata_sff_data_xfer32,
+       .port_start             = ata_bmdma_port_start32,
+};
+EXPORT_SYMBOL_GPL(ata_bmdma32_port_ops);
+
+/**
+ *     ata_bmdma_fill_sg - Fill PCI IDE PRD table
+ *     @qc: Metadata associated with taskfile to be transferred
+ *
+ *     Fill PCI IDE PRD (scatter-gather) table with segments
+ *     associated with the current disk command.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ */
+static void ata_bmdma_fill_sg(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       struct ata_bmdma_prd *prd = ap->bmdma_prd;
+       struct scatterlist *sg;
+       unsigned int si, pi;
+
+       pi = 0;
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
+               u32 addr, offset;
+               u32 sg_len, len;
+
+               /* determine if physical DMA addr spans 64K boundary.
+                * Note h/w doesn't support 64-bit, so we unconditionally
+                * truncate dma_addr_t to u32.
+                */
+               addr = (u32) sg_dma_address(sg);
+               sg_len = sg_dma_len(sg);
+
+               while (sg_len) {
+                       offset = addr & 0xffff;
+                       len = sg_len;
+                       if ((offset + sg_len) > 0x10000)
+                               len = 0x10000 - offset;
+
+                       prd[pi].addr = cpu_to_le32(addr);
+                       prd[pi].flags_len = cpu_to_le32(len & 0xffff);
+                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
+
+                       pi++;
+                       sg_len -= len;
+                       addr += len;
+               }
+       }
+
+       prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+}
+
+/**
+ *     ata_bmdma_fill_sg_dumb - Fill PCI IDE PRD table
+ *     @qc: Metadata associated with taskfile to be transferred
+ *
+ *     Fill PCI IDE PRD (scatter-gather) table with segments
+ *     associated with the current disk command. Perform the fill
+ *     so that we avoid writing any length 64K records for
+ *     controllers that don't follow the spec.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ */
+static void ata_bmdma_fill_sg_dumb(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       struct ata_bmdma_prd *prd = ap->bmdma_prd;
+       struct scatterlist *sg;
+       unsigned int si, pi;
+
+       pi = 0;
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
+               u32 addr, offset;
+               u32 sg_len, len, blen;
+
+               /* determine if physical DMA addr spans 64K boundary.
+                * Note h/w doesn't support 64-bit, so we unconditionally
+                * truncate dma_addr_t to u32.
+                */
+               addr = (u32) sg_dma_address(sg);
+               sg_len = sg_dma_len(sg);
+
+               while (sg_len) {
+                       offset = addr & 0xffff;
+                       len = sg_len;
+                       if ((offset + sg_len) > 0x10000)
+                               len = 0x10000 - offset;
+
+                       blen = len & 0xffff;
+                       prd[pi].addr = cpu_to_le32(addr);
+                       if (blen == 0) {
+                               /* Some PATA chipsets like the CS5530 can't
+                                  cope with 0x0000 meaning 64K as the spec
+                                  says */
+                               prd[pi].flags_len = cpu_to_le32(0x8000);
+                               blen = 0x8000;
+                               prd[++pi].addr = cpu_to_le32(addr + 0x8000);
+                       }
+                       prd[pi].flags_len = cpu_to_le32(blen);
+                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
+
+                       pi++;
+                       sg_len -= len;
+                       addr += len;
+               }
+       }
+
+       prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+}
+
+/**
+ *     ata_bmdma_qc_prep - Prepare taskfile for submission
+ *     @qc: Metadata associated with taskfile to be prepared
+ *
+ *     Prepare ATA taskfile for submission.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_bmdma_qc_prep(struct ata_queued_cmd *qc)
+{
+       if (!(qc->flags & ATA_QCFLAG_DMAMAP))
+               return;
+
+       ata_bmdma_fill_sg(qc);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_qc_prep);
+
+/**
+ *     ata_bmdma_dumb_qc_prep - Prepare taskfile for submission
+ *     @qc: Metadata associated with taskfile to be prepared
+ *
+ *     Prepare ATA taskfile for submission.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc)
+{
+       if (!(qc->flags & ATA_QCFLAG_DMAMAP))
+               return;
+
+       ata_bmdma_fill_sg_dumb(qc);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_dumb_qc_prep);
+
+/**
+ *     ata_bmdma_qc_issue - issue taskfile to a BMDMA controller
+ *     @qc: command to issue to device
+ *
+ *     This function issues a PIO, NODATA or DMA command to a
+ *     SFF/BMDMA controller.  PIO and NODATA are handled by
+ *     ata_sff_qc_issue().
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ *     RETURNS:
+ *     Zero on success, AC_ERR_* mask on failure
+ */
+unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+
+       /* see ata_dma_blacklisted() */
+       BUG_ON((ap->flags & ATA_FLAG_PIO_POLLING) &&
+              qc->tf.protocol == ATAPI_PROT_DMA);
+
+       /* defer PIO handling to sff_qc_issue */
+       if (!ata_is_dma(qc->tf.protocol))
+               return ata_sff_qc_issue(qc);
+
+       /* select the device */
+       ata_dev_select(ap, qc->dev->devno, 1, 0);
+
+       /* start the command */
+       switch (qc->tf.protocol) {
+       case ATA_PROT_DMA:
+               WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING);
+
+               ap->ops->sff_tf_load(ap, &qc->tf);  /* load tf registers */
+               ap->ops->bmdma_setup(qc);           /* set up bmdma */
+               ap->ops->bmdma_start(qc);           /* initiate bmdma */
+               ap->hsm_task_state = HSM_ST_LAST;
+               break;
+
+       case ATAPI_PROT_DMA:
+               WARN_ON_ONCE(qc->tf.flags & ATA_TFLAG_POLLING);
+
+               ap->ops->sff_tf_load(ap, &qc->tf);  /* load tf registers */
+               ap->ops->bmdma_setup(qc);           /* set up bmdma */
+               ap->hsm_task_state = HSM_ST_FIRST;
+
+               /* send cdb by polling if no cdb interrupt */
+               if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
+                       ata_sff_queue_pio_task(ap, 0);
+               break;
+
+       default:
+               WARN_ON(1);
+               return AC_ERR_SYSTEM;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_qc_issue);
+
+/**
+ *     ata_bmdma_error_handler - Stock error handler for BMDMA controller
+ *     @ap: port to handle error for
+ *
+ *     Stock error handler for BMDMA controller.  It can handle both
+ *     PATA and SATA controllers.  Most BMDMA controllers should be
+ *     able to use this EH as-is or with some added handling before
+ *     and after.
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep)
+ */
+void ata_bmdma_error_handler(struct ata_port *ap)
+{
+       struct ata_queued_cmd *qc;
+       unsigned long flags;
+       bool thaw = false;
+
+       qc = __ata_qc_from_tag(ap, ap->link.active_tag);
+       if (qc && !(qc->flags & ATA_QCFLAG_FAILED))
+               qc = NULL;
+
+       /* reset PIO HSM and stop DMA engine */
+       spin_lock_irqsave(ap->lock, flags);
+
+       if (qc && ata_is_dma(qc->tf.protocol)) {
+               u8 host_stat;
+
+               host_stat = ap->ops->bmdma_status(ap);
+
+               /* BMDMA controllers indicate host bus error by
+                * setting DMA_ERR bit and timing out.  As it wasn't
+                * really a timeout event, adjust error mask and
+                * cancel frozen state.
+                */
+               if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) {
+                       qc->err_mask = AC_ERR_HOST_BUS;
+                       thaw = true;
+               }
+
+               ap->ops->bmdma_stop(qc);
+
+               /* if we're gonna thaw, make sure IRQ is clear */
+               if (thaw) {
+                       ap->ops->sff_check_status(ap);
+                       ap->ops->sff_irq_clear(ap);
+               }
+       }
+
+       spin_unlock_irqrestore(ap->lock, flags);
+
+       if (thaw)
+               ata_eh_thaw_port(ap);
+
+       ata_sff_error_handler(ap);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_error_handler);
+
+/**
+ *     ata_bmdma_post_internal_cmd - Stock post_internal_cmd for BMDMA
+ *     @qc: internal command to clean up
+ *
+ *     LOCKING:
+ *     Kernel thread context (may sleep)
+ */
+void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       unsigned long flags;
+
+       if (ata_is_dma(qc->tf.protocol)) {
+               spin_lock_irqsave(ap->lock, flags);
+               ap->ops->bmdma_stop(qc);
+               spin_unlock_irqrestore(ap->lock, flags);
+       }
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd);
+
+/**
+ *     ata_bmdma_setup - Set up PCI IDE BMDMA transaction
+ *     @qc: Info associated with this ATA transaction.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_bmdma_setup(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
+       u8 dmactl;
+
+       /* load PRD table addr. */
+       mb();   /* make sure PRD table writes are visible to controller */
+       iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
+
+       /* specify data direction, triple-check start bit is clear */
+       dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+       dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
+       if (!rw)
+               dmactl |= ATA_DMA_WR;
+       iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+
+       /* issue r/w command */
+       ap->ops->sff_exec_command(ap, &qc->tf);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_setup);
+
+/**
+ *     ata_bmdma_start - Start a PCI IDE BMDMA transaction
+ *     @qc: Info associated with this ATA transaction.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_bmdma_start(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       u8 dmactl;
+
+       /* start host DMA transaction */
+       dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+       iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+
+       /* Strictly, one may wish to issue an ioread8() here, to
+        * flush the mmio write.  However, control also passes
+        * to the hardware at this point, and it will interrupt
+        * us when we are to resume control.  So, in effect,
+        * we don't care when the mmio write flushes.
+        * Further, a read of the DMA status register _immediately_
+        * following the write may not be what certain flaky hardware
+        * is expected, so I think it is best to not add a readb()
+        * without first all the MMIO ATA cards/mobos.
+        * Or maybe I'm just being paranoid.
+        *
+        * FIXME: The posting of this write means I/O starts are
+        * unneccessarily delayed for MMIO
+        */
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_start);
+
+/**
+ *     ata_bmdma_stop - Stop PCI IDE BMDMA transfer
+ *     @qc: Command we are ending DMA for
+ *
+ *     Clears the ATA_DMA_START flag in the dma control register
+ *
+ *     May be used as the bmdma_stop() entry in ata_port_operations.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_bmdma_stop(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       void __iomem *mmio = ap->ioaddr.bmdma_addr;
+
+       /* clear start/stop bit */
+       iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
+                mmio + ATA_DMA_CMD);
+
+       /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
+       ata_sff_dma_pause(ap);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_stop);
+
+/**
+ *     ata_bmdma_status - Read PCI IDE BMDMA status
+ *     @ap: Port associated with this ATA transaction.
+ *
+ *     Read and return BMDMA status register.
+ *
+ *     May be used as the bmdma_status() entry in ata_port_operations.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+u8 ata_bmdma_status(struct ata_port *ap)
+{
+       return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_status);
+
+
+/**
+ *     ata_bmdma_port_start - Set port up for bmdma.
+ *     @ap: Port to initialize
+ *
+ *     Called just after data structures for each port are
+ *     initialized.  Allocates space for PRD table.
+ *
+ *     May be used as the port_start() entry in ata_port_operations.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+int ata_bmdma_port_start(struct ata_port *ap)
+{
+       if (ap->mwdma_mask || ap->udma_mask) {
+               ap->bmdma_prd =
+                       dmam_alloc_coherent(ap->host->dev, ATA_PRD_TBL_SZ,
+                                           &ap->bmdma_prd_dma, GFP_KERNEL);
+               if (!ap->bmdma_prd)
+                       return -ENOMEM;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_port_start);
+
+/**
+ *     ata_bmdma_port_start32 - Set port up for dma.
+ *     @ap: Port to initialize
+ *
+ *     Called just after data structures for each port are
+ *     initialized.  Enables 32bit PIO and allocates space for PRD
+ *     table.
+ *
+ *     May be used as the port_start() entry in ata_port_operations for
+ *     devices that are capable of 32bit PIO.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+int ata_bmdma_port_start32(struct ata_port *ap)
+{
+       ap->pflags |= ATA_PFLAG_PIO32 | ATA_PFLAG_PIO32CHANGE;
+       return ata_bmdma_port_start(ap);
+}
+EXPORT_SYMBOL_GPL(ata_bmdma_port_start32);
+
+#ifdef CONFIG_PCI
+
+/**
+ *     ata_pci_bmdma_clear_simplex -   attempt to kick device out of simplex
+ *     @pdev: PCI device
+ *
+ *     Some PCI ATA devices report simplex mode but in fact can be told to
+ *     enter non simplex mode. This implements the necessary logic to
+ *     perform the task on such devices. Calling it on other devices will
+ *     have -undefined- behaviour.
+ */
+int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev)
+{
+       unsigned long bmdma = pci_resource_start(pdev, 4);
+       u8 simplex;
+
+       if (bmdma == 0)
+               return -ENOENT;
+
+       simplex = inb(bmdma + 0x02);
+       outb(simplex & 0x60, bmdma + 0x02);
+       simplex = inb(bmdma + 0x02);
+       if (simplex & 0x80)
+               return -EOPNOTSUPP;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ata_pci_bmdma_clear_simplex);
+
+static void ata_bmdma_nodma(struct ata_host *host, const char *reason)
+{
+       int i;
+
+       dev_printk(KERN_ERR, host->dev, "BMDMA: %s, falling back to PIO\n",
+                  reason);
+
+       for (i = 0; i < 2; i++) {
+               host->ports[i]->mwdma_mask = 0;
+               host->ports[i]->udma_mask = 0;
+       }
+}
+
+/**
+ *     ata_pci_bmdma_init - acquire PCI BMDMA resources and init ATA host
+ *     @host: target ATA host
+ *
+ *     Acquire PCI BMDMA resources and initialize @host accordingly.
+ *
+ *     LOCKING:
+ *     Inherited from calling layer (may sleep).
+ */
+void ata_pci_bmdma_init(struct ata_host *host)
+{
+       struct device *gdev = host->dev;
+       struct pci_dev *pdev = to_pci_dev(gdev);
+       int i, rc;
+
+       /* No BAR4 allocation: No DMA */
+       if (pci_resource_start(pdev, 4) == 0) {
+               ata_bmdma_nodma(host, "BAR4 is zero");
+               return;
+       }
+
+       /*
+        * Some controllers require BMDMA region to be initialized
+        * even if DMA is not in use to clear IRQ status via
+        * ->sff_irq_clear method.  Try to initialize bmdma_addr
+        * regardless of dma masks.
+        */
+       rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
+       if (rc)
+               ata_bmdma_nodma(host, "failed to set dma mask");
+       if (!rc) {
+               rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
+               if (rc)
+                       ata_bmdma_nodma(host,
+                                       "failed to set consistent dma mask");
+       }
+
+       /* request and iomap DMA region */
+       rc = pcim_iomap_regions(pdev, 1 << 4, dev_driver_string(gdev));
+       if (rc) {
+               ata_bmdma_nodma(host, "failed to request/iomap BAR4");
+               return;
+       }
+       host->iomap = pcim_iomap_table(pdev);
+
+       for (i = 0; i < 2; i++) {
+               struct ata_port *ap = host->ports[i];
+               void __iomem *bmdma = host->iomap[4] + 8 * i;
+
+               if (ata_port_is_dummy(ap))
+                       continue;
+
+               ap->ioaddr.bmdma_addr = bmdma;
+               if ((!(ap->flags & ATA_FLAG_IGN_SIMPLEX)) &&
+                   (ioread8(bmdma + 2) & 0x80))
+                       host->flags |= ATA_HOST_SIMPLEX;
+
+               ata_port_desc(ap, "bmdma 0x%llx",
+                   (unsigned long long)pci_resource_start(pdev, 4) + 8 * i);
+       }
+}
+EXPORT_SYMBOL_GPL(ata_pci_bmdma_init);
+
+#endif /* CONFIG_PCI */
+
+/**
+ *     ata_sff_port_init - Initialize SFF/BMDMA ATA port
+ *     @ap: Port to initialize
+ *
+ *     Called on port allocation to initialize SFF/BMDMA specific
+ *     fields.
+ *
+ *     LOCKING:
+ *     None.
+ */
+void ata_sff_port_init(struct ata_port *ap)
+{
+       INIT_DELAYED_WORK(&ap->sff_pio_task, ata_sff_pio_task);
+       ap->ctl = ATA_DEVCTL_OBS;
+       ap->last_ctl = 0xFF;
+}
+
+int __init ata_sff_init(void)
+{
+       /*
+        * FIXME: In UP case, there is only one workqueue thread and if you
+        * have more than one PIO device, latency is bloody awful, with
+        * occasional multi-second "hiccups" as one PIO device waits for
+        * another.  It's an ugly wart that users DO occasionally complain
+        * about; luckily most users have at most one PIO polled device.
+        */
+       ata_sff_wq = create_workqueue("ata_sff");
+       if (!ata_sff_wq)
+               return -ENOMEM;
+
+       return 0;
+}
+
+void __exit ata_sff_exit(void)
+{
+       destroy_workqueue(ata_sff_wq);
+}
index 823e630..4b84ed6 100644 (file)
@@ -38,17 +38,6 @@ struct ata_scsi_args {
        void                    (*done)(struct scsi_cmnd *);
 };
 
-static inline int ata_is_builtin_hardreset(ata_reset_fn_t reset)
-{
-       if (reset == sata_std_hardreset)
-               return 1;
-#ifdef CONFIG_ATA_SFF
-       if (reset == sata_sff_hardreset)
-               return 1;
-#endif
-       return 0;
-}
-
 /* libata-core.c */
 enum {
        /* flags for ata_dev_read_id() */
@@ -79,7 +68,6 @@ extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
                           u64 block, u32 n_block, unsigned int tf_flags,
                           unsigned int tag);
 extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev);
-extern void ata_port_flush_task(struct ata_port *ap);
 extern unsigned ata_exec_internal(struct ata_device *dev,
                                  struct ata_taskfile *tf, const u8 *cdb,
                                  int dma_dir, void *buf, unsigned int buflen,
@@ -202,10 +190,19 @@ static inline int sata_pmp_attach(struct ata_device *dev)
 
 /* libata-sff.c */
 #ifdef CONFIG_ATA_SFF
-extern void ata_dev_select(struct ata_port *ap, unsigned int device,
-                           unsigned int wait, unsigned int can_sleep);
-extern u8 ata_irq_on(struct ata_port *ap);
-extern void ata_pio_task(struct work_struct *work);
+extern void ata_sff_flush_pio_task(struct ata_port *ap);
+extern void ata_sff_port_init(struct ata_port *ap);
+extern int ata_sff_init(void);
+extern void ata_sff_exit(void);
+#else /* CONFIG_ATA_SFF */
+static inline void ata_sff_flush_pio_task(struct ata_port *ap)
+{ }
+static inline void ata_sff_port_init(struct ata_port *ap)
+{ }
+static inline int ata_sff_init(void)
+{ return 0; }
+static inline void ata_sff_exit(void)
+{ }
 #endif /* CONFIG_ATA_SFF */
 
 #endif /* __LIBATA_H__ */
index 1ea2be0..066b9f3 100644 (file)
@@ -101,7 +101,7 @@ static unsigned long pacpi_discover_modes(struct ata_port *ap, struct ata_device
 static unsigned long pacpi_mode_filter(struct ata_device *adev, unsigned long mask)
 {
        struct pata_acpi *acpi = adev->link->ap->private_data;
-       return ata_bmdma_mode_filter(adev, mask & acpi->mask[adev->devno]);
+       return mask & acpi->mask[adev->devno];
 }
 
 /**
@@ -172,7 +172,7 @@ static unsigned int pacpi_qc_issue(struct ata_queued_cmd *qc)
        struct pata_acpi *acpi = ap->private_data;
 
        if (acpi->gtm.flags & 0x10)
-               return ata_sff_qc_issue(qc);
+               return ata_bmdma_qc_issue(qc);
 
        if (adev != acpi->last) {
                pacpi_set_piomode(ap, adev);
@@ -180,7 +180,7 @@ static unsigned int pacpi_qc_issue(struct ata_queued_cmd *qc)
                        pacpi_set_dmamode(ap, adev);
                acpi->last = adev;
        }
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 /**
@@ -205,7 +205,7 @@ static int pacpi_port_start(struct ata_port *ap)
                return -ENOMEM;
        acpi->mask[0] = pacpi_discover_modes(ap, &ap->link.device[0]);
        acpi->mask[1] = pacpi_discover_modes(ap, &ap->link.device[1]);
-       ret = ata_sff_port_start(ap);
+       ret = ata_bmdma_port_start(ap);
        if (ret < 0)
                return ret;
 
index dc61b72..f306e10 100644 (file)
@@ -124,7 +124,7 @@ static unsigned long ali_20_filter(struct ata_device *adev, unsigned long mask)
        ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
        if (strstr(model_num, "WDC"))
                return mask &= ~ATA_MASK_UDMA;
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
index c6a946a..0da0dcc 100644 (file)
@@ -202,7 +202,6 @@ static struct ata_port_operations pata_at91_port_ops = {
        .sff_data_xfer  = pata_at91_data_xfer_noirq,
        .set_piomode    = pata_at91_set_piomode,
        .cable_detect   = ata_cable_40wire,
-       .port_start     = ATA_OP_NULL,
 };
 
 static int __devinit pata_at91_probe(struct platform_device *pdev)
index cbaf2ed..44d88b3 100644 (file)
@@ -217,7 +217,7 @@ static struct scsi_host_template atiixp_sht = {
 static struct ata_port_operations atiixp_port_ops = {
        .inherits       = &ata_bmdma_port_ops,
 
-       .qc_prep        = ata_sff_dumb_qc_prep,
+       .qc_prep        = ata_bmdma_dumb_qc_prep,
        .bmdma_start    = atiixp_bmdma_start,
        .bmdma_stop     = atiixp_bmdma_stop,
 
index 02c81f1..6422cfd 100644 (file)
@@ -820,6 +820,18 @@ static void bfin_dev_select(struct ata_port *ap, unsigned int device)
        ata_sff_pause(ap);
 }
 
+/**
+ *     bfin_set_devctl - Write device control reg
+ *     @ap: port where the device is
+ *     @ctl: value to write
+ */
+
+static u8 bfin_set_devctl(struct ata_port *ap, u8 ctl)
+{
+       void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
+       write_atapi_register(base, ATA_REG_CTRL, ctl);
+}
+
 /**
  *     bfin_bmdma_setup - Set up IDE DMA transaction
  *     @qc: Info associated with this ATA transaction.
@@ -1215,56 +1227,6 @@ static void bfin_irq_clear(struct ata_port *ap)
                | MULTI_TERM_INT | UDMAIN_TERM_INT | UDMAOUT_TERM_INT);
 }
 
-/**
- *     bfin_irq_on - Enable interrupts on a port.
- *     @ap: Port on which interrupts are enabled.
- *
- *     Note: Original code is ata_sff_irq_on().
- */
-
-static unsigned char bfin_irq_on(struct ata_port *ap)
-{
-       void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
-       u8 tmp;
-
-       dev_dbg(ap->dev, "in atapi irq on\n");
-       ap->ctl &= ~ATA_NIEN;
-       ap->last_ctl = ap->ctl;
-
-       write_atapi_register(base, ATA_REG_CTRL, ap->ctl);
-       tmp = ata_wait_idle(ap);
-
-       bfin_irq_clear(ap);
-
-       return tmp;
-}
-
-/**
- *     bfin_freeze - Freeze DMA controller port
- *     @ap: port to freeze
- *
- *     Note: Original code is ata_sff_freeze().
- */
-
-static void bfin_freeze(struct ata_port *ap)
-{
-       void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
-
-       dev_dbg(ap->dev, "in atapi dma freeze\n");
-       ap->ctl |= ATA_NIEN;
-       ap->last_ctl = ap->ctl;
-
-       write_atapi_register(base, ATA_REG_CTRL, ap->ctl);
-
-       /* Under certain circumstances, some controllers raise IRQ on
-        * ATA_NIEN manipulation.  Also, many controllers fail to mask
-        * previously pending IRQ on ATA_NIEN assertion.  Clear it.
-        */
-       ap->ops->sff_check_status(ap);
-
-       bfin_irq_clear(ap);
-}
-
 /**
  *     bfin_thaw - Thaw DMA controller port
  *     @ap: port to thaw
@@ -1276,7 +1238,7 @@ void bfin_thaw(struct ata_port *ap)
 {
        dev_dbg(ap->dev, "in atapi dma thaw\n");
        bfin_check_status(ap);
-       bfin_irq_on(ap);
+       ata_sff_irq_on(ap);
 }
 
 /**
@@ -1293,7 +1255,7 @@ static void bfin_postreset(struct ata_link *link, unsigned int *classes)
        void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
 
        /* re-enable interrupts */
-       bfin_irq_on(ap);
+       ata_sff_irq_on(ap);
 
        /* is double-select really necessary? */
        if (classes[0] != ATA_DEV_NONE)
@@ -1438,18 +1400,12 @@ static irqreturn_t bfin_ata_interrupt(int irq, void *dev_instance)
        spin_lock_irqsave(&host->lock, flags);
 
        for (i = 0; i < host->n_ports; i++) {
-               struct ata_port *ap;
+               struct ata_port *ap = host->ports[i];
+               struct ata_queued_cmd *qc;
 
-               ap = host->ports[i];
-               if (ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
-                       struct ata_queued_cmd *qc;
-
-                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
-                       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
-                           (qc->flags & ATA_QCFLAG_ACTIVE))
-                               handled |= bfin_ata_host_intr(ap, qc);
-               }
+               qc = ata_qc_from_tag(ap, ap->link.active_tag);
+               if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
+                       handled |= bfin_ata_host_intr(ap, qc);
        }
 
        spin_unlock_irqrestore(&host->lock, flags);
@@ -1465,7 +1421,7 @@ static struct scsi_host_template bfin_sht = {
 };
 
 static struct ata_port_operations bfin_pata_ops = {
-       .inherits               = &ata_sff_port_ops,
+       .inherits               = &ata_bmdma_port_ops,
 
        .set_piomode            = bfin_set_piomode,
        .set_dmamode            = bfin_set_dmamode,
@@ -1476,6 +1432,7 @@ static struct ata_port_operations bfin_pata_ops = {
        .sff_check_status       = bfin_check_status,
        .sff_check_altstatus    = bfin_check_altstatus,
        .sff_dev_select         = bfin_dev_select,
+       .sff_set_devctl         = bfin_set_devctl,
 
        .bmdma_setup            = bfin_bmdma_setup,
        .bmdma_start            = bfin_bmdma_start,
@@ -1485,13 +1442,11 @@ static struct ata_port_operations bfin_pata_ops = {
 
        .qc_prep                = ata_noop_qc_prep,
 
-       .freeze                 = bfin_freeze,
        .thaw                   = bfin_thaw,
        .softreset              = bfin_softreset,
        .postreset              = bfin_postreset,
 
        .sff_irq_clear          = bfin_irq_clear,
-       .sff_irq_on             = bfin_irq_on,
 
        .port_start             = bfin_port_start,
        .port_stop              = bfin_port_stop,
index 45896b3..e5f289f 100644 (file)
@@ -153,24 +153,20 @@ static int cmd640_port_start(struct ata_port *ap)
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
        struct cmd640_reg *timing;
 
-       int ret = ata_sff_port_start(ap);
-       if (ret < 0)
-               return ret;
-
        timing = devm_kzalloc(&pdev->dev, sizeof(struct cmd640_reg), GFP_KERNEL);
        if (timing == NULL)
                return -ENOMEM;
        timing->last = -1;      /* Force a load */
        ap->private_data = timing;
-       return ret;
+       return 0;
 }
 
 static struct scsi_host_template cmd640_sht = {
-       ATA_BMDMA_SHT(DRV_NAME),
+       ATA_PIO_SHT(DRV_NAME),
 };
 
 static struct ata_port_operations cmd640_port_ops = {
-       .inherits       = &ata_bmdma_port_ops,
+       .inherits       = &ata_sff_port_ops,
        /* In theory xfer_noirq is not needed once we kill the prefetcher */
        .sff_data_xfer  = ata_sff_data_xfer_noirq,
        .qc_issue       = cmd640_qc_issue,
@@ -181,13 +177,10 @@ static struct ata_port_operations cmd640_port_ops = {
 
 static void cmd640_hardware_init(struct pci_dev *pdev)
 {
-       u8 r;
        u8 ctrl;
 
        /* CMD640 detected, commiserations */
        pci_write_config_byte(pdev, 0x5B, 0x00);
-       /* Get version info */
-       pci_read_config_byte(pdev, CFR, &r);
        /* PIO0 command cycles */
        pci_write_config_byte(pdev, CMDTIM, 0);
        /* 512 byte bursts (sector) */
index 95ebdac..17c5f34 100644 (file)
@@ -110,7 +110,7 @@ static struct scsi_host_template cs5520_sht = {
 
 static struct ata_port_operations cs5520_port_ops = {
        .inherits               = &ata_bmdma_port_ops,
-       .qc_prep                = ata_sff_dumb_qc_prep,
+       .qc_prep                = ata_bmdma_dumb_qc_prep,
        .cable_detect           = ata_cable_40wire,
        .set_piomode            = cs5520_set_piomode,
 };
index 738ad2e..e809a42 100644 (file)
@@ -156,7 +156,7 @@ static unsigned int cs5530_qc_issue(struct ata_queued_cmd *qc)
                        cs5530_set_dmamode(ap, adev);
        }
 
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 static struct scsi_host_template cs5530_sht = {
@@ -167,7 +167,7 @@ static struct scsi_host_template cs5530_sht = {
 static struct ata_port_operations cs5530_port_ops = {
        .inherits       = &ata_bmdma_port_ops,
 
-       .qc_prep        = ata_sff_dumb_qc_prep,
+       .qc_prep        = ata_bmdma_dumb_qc_prep,
        .qc_issue       = cs5530_qc_issue,
 
        .cable_detect   = ata_cable_40wire,
index af49bfb..8580eb3 100644 (file)
@@ -182,7 +182,7 @@ static unsigned long hpt366_filter(struct ata_device *adev, unsigned long mask)
        } else if (adev->class == ATA_DEV_ATAPI)
                mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
 
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 static int hpt36x_cable_detect(struct ata_port *ap)
index 8839307..98b498b 100644 (file)
@@ -282,7 +282,7 @@ static unsigned long hpt370_filter(struct ata_device *adev, unsigned long mask)
                if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
                        mask &= ~(0xE0 << ATA_SHIFT_UDMA);
        }
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
@@ -298,7 +298,7 @@ static unsigned long hpt370a_filter(struct ata_device *adev, unsigned long mask)
                if (hpt_dma_blacklisted(adev, "UDMA100", bad_ata100_5))
                        mask &= ~(0xE0 << ATA_SHIFT_UDMA);
        }
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
index 01457b2..8b95aeb 100644 (file)
@@ -320,7 +320,7 @@ static unsigned int hpt3x2n_qc_issue(struct ata_queued_cmd *qc)
 
                hpt3x2n_set_clock(ap, dpll ? 0x21 : 0x23);
        }
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 static struct scsi_host_template hpt3x2n_sht = {
index fa812e2..b56e8f7 100644 (file)
@@ -321,7 +321,7 @@ static void pata_icside_postreset(struct ata_link *link, unsigned int *classes)
 }
 
 static struct ata_port_operations pata_icside_port_ops = {
-       .inherits               = &ata_sff_port_ops,
+       .inherits               = &ata_bmdma_port_ops,
        /* no need to build any PRD tables for DMA */
        .qc_prep                = ata_noop_qc_prep,
        .sff_data_xfer          = ata_sff_data_xfer_noirq,
@@ -333,7 +333,8 @@ static struct ata_port_operations pata_icside_port_ops = {
        .cable_detect           = ata_cable_40wire,
        .set_dmamode            = pata_icside_set_dmamode,
        .postreset              = pata_icside_postreset,
-       .post_internal_cmd      = pata_icside_bmdma_stop,
+
+       .port_start             = ATA_OP_NULL,  /* don't need PRD table */
 };
 
 static void __devinit
index 5cb286f..2bd2b00 100644 (file)
@@ -430,7 +430,7 @@ static unsigned int it821x_smart_qc_issue(struct ata_queued_cmd *qc)
                case 0xFC:      /* Internal 'report rebuild state' */
                /* Arguably should just no-op this one */
                case ATA_CMD_SET_FEATURES:
-                       return ata_sff_qc_issue(qc);
+                       return ata_bmdma_qc_issue(qc);
        }
        printk(KERN_DEBUG "it821x: can't process command 0x%02X\n", qc->tf.command);
        return AC_ERR_DEV;
@@ -448,7 +448,7 @@ static unsigned int it821x_smart_qc_issue(struct ata_queued_cmd *qc)
 static unsigned int it821x_passthru_qc_issue(struct ata_queued_cmd *qc)
 {
        it821x_passthru_dev_select(qc->ap, qc->dev->devno);
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 /**
@@ -739,7 +739,7 @@ static int it821x_port_start(struct ata_port *ap)
        struct it821x_dev *itdev;
        u8 conf;
 
-       int ret = ata_sff_port_start(ap);
+       int ret = ata_bmdma_port_start(ap);
        if (ret < 0)
                return ret;
 
index 211b643..25df50f 100644 (file)
@@ -720,6 +720,8 @@ static int pata_macio_port_start(struct ata_port *ap)
        if (priv->dma_table_cpu == NULL) {
                dev_err(priv->dev, "Unable to allocate DMA command list\n");
                ap->ioaddr.bmdma_addr = NULL;
+               ap->mwdma_mask = 0;
+               ap->udma_mask = 0;
        }
        return 0;
 }
@@ -917,7 +919,7 @@ static struct scsi_host_template pata_macio_sht = {
 };
 
 static struct ata_port_operations pata_macio_ops = {
-       .inherits               = &ata_sff_port_ops,
+       .inherits               = &ata_bmdma_port_ops,
 
        .freeze                 = pata_macio_freeze,
        .set_piomode            = pata_macio_set_timings,
@@ -925,7 +927,6 @@ static struct ata_port_operations pata_macio_ops = {
        .cable_detect           = pata_macio_cable_detect,
        .sff_dev_select         = pata_macio_dev_select,
        .qc_prep                = pata_macio_qc_prep,
-       .mode_filter            = ata_bmdma_mode_filter,
        .bmdma_setup            = pata_macio_bmdma_setup,
        .bmdma_start            = pata_macio_bmdma_start,
        .bmdma_stop             = pata_macio_bmdma_stop,
index 9f5b053..96b11b6 100644 (file)
@@ -64,13 +64,13 @@ struct mpc52xx_ata_priv {
 
 
 /* ATAPI-4 PIO specs (in ns) */
-static const int ataspec_t0[5]    = {600, 383, 240, 180, 120};
-static const int ataspec_t1[5]    = { 70,  50,  30,  30,  25};
-static const int ataspec_t2_8[5]  = {290, 290, 290,  80,  70};
-static const int ataspec_t2_16[5] = {165, 125, 100,  80,  70};
-static const int ataspec_t2i[5]   = {  0,   0,   0,  70,  25};
-static const int ataspec_t4[5]    = { 30,  20,  15,  10,  10};
-static const int ataspec_ta[5]    = { 35,  35,  35,  35,  35};
+static const u16 ataspec_t0[5]         = {600, 383, 240, 180, 120};
+static const u16 ataspec_t1[5]         = { 70,  50,  30,  30,  25};
+static const u16 ataspec_t2_8[5]       = {290, 290, 290,  80,  70};
+static const u16 ataspec_t2_16[5]      = {165, 125, 100,  80,  70};
+static const u16 ataspec_t2i[5]                = {  0,   0,   0,  70,  25};
+static const u16 ataspec_t4[5]         = { 30,  20,  15,  10,  10};
+static const u16 ataspec_ta[5]         = { 35,  35,  35,  35,  35};
 
 #define CALC_CLKCYC(c,v) ((((v)+(c)-1)/(c)))
 
@@ -78,13 +78,13 @@ static const int ataspec_ta[5]    = { 35,  35,  35,  35,  35};
 
 /* ATAPI-4 MDMA specs (in clocks) */
 struct mdmaspec {
-       u32 t0M;
-       u32 td;
-       u32 th;
-       u32 tj;
-       u32 tkw;
-       u32 tm;
-       u32 tn;
+       u8 t0M;
+       u8 td;
+       u8 th;
+       u8 tj;
+       u8 tkw;
+       u8 tm;
+       u8 tn;
 };
 
 static const struct mdmaspec mdmaspec66[3] = {
@@ -101,23 +101,23 @@ static const struct mdmaspec mdmaspec132[3] = {
 
 /* ATAPI-4 UDMA specs (in clocks) */
 struct udmaspec {
-       u32 tcyc;
-       u32 t2cyc;
-       u32 tds;
-       u32 tdh;
-       u32 tdvs;
-       u32 tdvh;
-       u32 tfs;
-       u32 tli;
-       u32 tmli;
-       u32 taz;
-       u32 tzah;
-       u32 tenv;
-       u32 tsr;
-       u32 trfs;
-       u32 trp;
-       u32 tack;
-       u32 tss;
+       u8 tcyc;
+       u8 t2cyc;
+       u8 tds;
+       u8 tdh;
+       u8 tdvs;
+       u8 tdvh;
+       u8 tfs;
+       u8 tli;
+       u8 tmli;
+       u8 taz;
+       u8 tzah;
+       u8 tenv;
+       u8 tsr;
+       u8 trfs;
+       u8 trp;
+       u8 tack;
+       u8 tss;
 };
 
 static const struct udmaspec udmaspec66[6] = {
@@ -270,7 +270,7 @@ mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio)
 {
        struct mpc52xx_ata_timings *timing = &priv->timings[dev];
        unsigned int ipb_period = priv->ipb_period;
-       unsigned int t0, t1, t2_8, t2_16, t2i, t4, ta;
+       u32 t0, t1, t2_8, t2_16, t2i, t4, ta;
 
        if ((pio < 0) || (pio > 4))
                return -EINVAL;
@@ -299,8 +299,8 @@ mpc52xx_ata_compute_mdma_timings(struct mpc52xx_ata_priv *priv, int dev,
        if (speed < 0 || speed > 2)
                return -EINVAL;
 
-       t->mdma1 = (s->t0M << 24) | (s->td << 16) | (s->tkw << 8) | (s->tm);
-       t->mdma2 = (s->th << 24) | (s->tj << 16) | (s->tn << 8);
+       t->mdma1 = ((u32)s->t0M << 24) | ((u32)s->td << 16) | ((u32)s->tkw << 8) | s->tm;
+       t->mdma2 = ((u32)s->th << 24) | ((u32)s->tj << 16) | ((u32)s->tn << 8);
        t->using_udma = 0;
 
        return 0;
@@ -316,11 +316,11 @@ mpc52xx_ata_compute_udma_timings(struct mpc52xx_ata_priv *priv, int dev,
        if (speed < 0 || speed > 2)
                return -EINVAL;
 
-       t->udma1 = (s->t2cyc << 24) | (s->tcyc << 16) | (s->tds << 8) | s->tdh;
-       t->udma2 = (s->tdvs << 24) | (s->tdvh << 16) | (s->tfs << 8) | s->tli;
-       t->udma3 = (s->tmli << 24) | (s->taz << 16) | (s->tenv << 8) | s->tsr;
-       t->udma4 = (s->tss << 24) | (s->trfs << 16) | (s->trp << 8) | s->tack;
-       t->udma5 = (s->tzah << 24);
+       t->udma1 = ((u32)s->t2cyc << 24) | ((u32)s->tcyc << 16) | ((u32)s->tds << 8) | s->tdh;
+       t->udma2 = ((u32)s->tdvs << 24) | ((u32)s->tdvh << 16) | ((u32)s->tfs << 8) | s->tli;
+       t->udma3 = ((u32)s->tmli << 24) | ((u32)s->taz << 16) | ((u32)s->tenv << 8) | s->tsr;
+       t->udma4 = ((u32)s->tss << 24) | ((u32)s->trfs << 16) | ((u32)s->trp << 8) | s->tack;
+       t->udma5 = (u32)s->tzah << 24;
        t->using_udma = 1;
 
        return 0;
index 830431f..fdbba2d 100644 (file)
@@ -126,7 +126,7 @@ static void ns87415_bmdma_setup(struct ata_queued_cmd *qc)
 
        /* load PRD table addr. */
        mb();   /* make sure PRD table writes are visible to controller */
-       iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
+       iowrite32(ap->bmdma_prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
 
        /* specify data direction, triple-check start bit is clear */
        dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
index 005a444..3001109 100644 (file)
@@ -489,9 +489,8 @@ static void octeon_cf_exec_command16(struct ata_port *ap,
        ata_wait_idle(ap);
 }
 
-static u8 octeon_cf_irq_on(struct ata_port *ap)
+static void octeon_cf_irq_on(struct ata_port *ap)
 {
-       return 0;
 }
 
 static void octeon_cf_irq_clear(struct ata_port *ap)
@@ -655,9 +654,6 @@ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance)
                ap = host->ports[i];
                ocd = ap->dev->platform_data;
 
-               if (ap->flags & ATA_FLAG_DISABLED)
-                       continue;
-
                ocd = ap->dev->platform_data;
                cf_port = ap->private_data;
                dma_int.u64 =
@@ -667,8 +663,7 @@ static irqreturn_t octeon_cf_interrupt(int irq, void *dev_instance)
 
                qc = ata_qc_from_tag(ap, ap->link.active_tag);
 
-               if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
-                   (qc->flags & ATA_QCFLAG_ACTIVE)) {
+               if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING)) {
                        if (dma_int.s.done && !dma_cfg.s.en) {
                                if (!sg_is_last(qc->cursg)) {
                                        qc->cursg = sg_next(qc->cursg);
@@ -738,8 +733,7 @@ static void octeon_cf_delayed_finish(struct work_struct *work)
                goto out;
        }
        qc = ata_qc_from_tag(ap, ap->link.active_tag);
-       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)) &&
-           (qc->flags & ATA_QCFLAG_ACTIVE))
+       if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING))
                octeon_cf_dma_finished(ap, qc);
 out:
        spin_unlock_irqrestore(&host->lock, flags);
index 5f6aba7..988ef26 100644 (file)
@@ -200,7 +200,7 @@ static unsigned int oldpiix_qc_issue(struct ata_queued_cmd *qc)
                if (ata_dma_enabled(adev))
                        oldpiix_set_dmamode(ap, adev);
        }
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 
index d94b8f0..118c28e 100644 (file)
 #define DRV_NAME "pata_pcmcia"
 #define DRV_VERSION "0.3.5"
 
-/*
- *     Private data structure to glue stuff together
- */
-
-struct ata_pcmcia_info {
-       struct pcmcia_device *pdev;
-       int             ndev;
-       dev_node_t      node;
-};
-
 /**
  *     pcmcia_set_mode -       PCMCIA specific mode setup
  *     @link: link
@@ -175,7 +165,7 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
        .sff_data_xfer  = ata_data_xfer_8bit,
        .cable_detect   = ata_cable_40wire,
        .set_mode       = pcmcia_set_mode_8bit,
-       .drain_fifo     = pcmcia_8bit_drain_fifo,
+       .sff_drain_fifo = pcmcia_8bit_drain_fifo,
 };
 
 
@@ -248,7 +238,6 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
 {
        struct ata_host *host;
        struct ata_port *ap;
-       struct ata_pcmcia_info *info;
        struct pcmcia_config_check *stk = NULL;
        int is_kme = 0, ret = -ENOMEM, p;
        unsigned long io_base, ctl_base;
@@ -256,19 +245,10 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        int n_ports = 1;
        struct ata_port_operations *ops = &pcmcia_port_ops;
 
-       info = kzalloc(sizeof(*info), GFP_KERNEL);
-       if (info == NULL)
-               return -ENOMEM;
-
-       /* Glue stuff together. FIXME: We may be able to get rid of info with care */
-       info->pdev = pdev;
-       pdev->priv = info;
-
        /* Set up attributes in order to probe card and get resources */
        pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        pdev->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
        pdev->io.IOAddrLines = 3;
-       pdev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
        pdev->conf.Attributes = CONF_ENABLE_IRQ;
        pdev->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -293,8 +273,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        }
        io_base = pdev->io.BasePort1;
        ctl_base = stk->ctl_base;
-       ret = pcmcia_request_irq(pdev, &pdev->irq);
-       if (ret)
+       if (!pdev->irq)
                goto failed;
 
        ret = pcmcia_request_configuration(pdev, &pdev->conf);
@@ -344,21 +323,19 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        }
 
        /* activate */
-       ret = ata_host_activate(host, pdev->irq.AssignedIRQ, ata_sff_interrupt,
+       ret = ata_host_activate(host, pdev->irq, ata_sff_interrupt,
                                IRQF_SHARED, &pcmcia_sht);
        if (ret)
                goto failed;
 
-       info->ndev = 1;
+       pdev->priv = host;
        kfree(stk);
        return 0;
 
 failed:
        kfree(stk);
-       info->ndev = 0;
        pcmcia_disable_device(pdev);
 out1:
-       kfree(info);
        return ret;
 }
 
@@ -372,20 +349,12 @@ out1:
 
 static void pcmcia_remove_one(struct pcmcia_device *pdev)
 {
-       struct ata_pcmcia_info *info = pdev->priv;
-       struct device *dev = &pdev->dev;
-
-       if (info != NULL) {
-               /* If we have attached the device to the ATA layer, detach it */
-               if (info->ndev) {
-                       struct ata_host *host = dev_get_drvdata(dev);
-                       ata_host_detach(host);
-               }
-               info->ndev = 0;
-               pdev->priv = NULL;
-       }
+       struct ata_host *host = pdev->priv;
+
+       if (host)
+               ata_host_detach(host);
+
        pcmcia_disable_device(pdev);
-       kfree(info);
 }
 
 static struct pcmcia_device_id pcmcia_devices[] = {
index ca5cad0..09f1f22 100644 (file)
@@ -265,7 +265,7 @@ static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long
        struct ata_device *pair = ata_dev_pair(adev);
 
        if (adev->class != ATA_DEV_ATA || adev->devno == 0 || pair == NULL)
-               return ata_bmdma_mode_filter(adev, mask);
+               return mask;
 
        /* Check for slave of a Maxtor at UDMA6 */
        ata_id_c_string(pair->id, model_num, ATA_ID_PROD,
@@ -274,7 +274,7 @@ static unsigned long pdc2027x_mode_filter(struct ata_device *adev, unsigned long
        if (strstr(model_num, "Maxtor") == NULL && pair->dma_mode == XFER_UDMA_6)
                mask &= ~ (1 << (6 + ATA_SHIFT_UDMA));
 
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
index 9ac0897..fa1e2f3 100644 (file)
@@ -249,7 +249,7 @@ static int pdc2026x_port_start(struct ata_port *ap)
                u8 burst = ioread8(bmdma + 0x1f);
                iowrite8(burst | 0x01, bmdma + 0x1f);
        }
-       return ata_sff_port_start(ap);
+       return ata_bmdma_port_start(ap);
 }
 
 /**
index 3f6ebc6..50400fa 100644 (file)
@@ -53,7 +53,6 @@ static struct ata_port_operations pata_platform_port_ops = {
        .sff_data_xfer          = ata_sff_data_xfer_noirq,
        .cable_detect           = ata_cable_unknown,
        .set_mode               = pata_platform_set_mode,
-       .port_start             = ATA_OP_NULL,
 };
 
 static void pata_platform_setup_port(struct ata_ioports *ioaddr,
index fc96022..a5fa388 100644 (file)
@@ -179,7 +179,7 @@ static unsigned int radisys_qc_issue(struct ata_queued_cmd *qc)
                                radisys_set_piomode(ap, adev);
                }
        }
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 
index dfecc6f..6b5b63a 100644 (file)
@@ -174,7 +174,7 @@ static unsigned int sc1200_qc_issue(struct ata_queued_cmd *qc)
                        sc1200_set_dmamode(ap, adev);
        }
 
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 /**
@@ -209,7 +209,7 @@ static struct scsi_host_template sc1200_sht = {
 
 static struct ata_port_operations sc1200_port_ops = {
        .inherits       = &ata_bmdma_port_ops,
-       .qc_prep        = ata_sff_dumb_qc_prep,
+       .qc_prep        = ata_bmdma_dumb_qc_prep,
        .qc_issue       = sc1200_qc_issue,
        .qc_defer       = sc1200_qc_defer,
        .cable_detect   = ata_cable_40wire,
index 4257d6b..6f6193b 100644 (file)
@@ -265,7 +265,7 @@ unsigned long scc_mode_filter(struct ata_device *adev, unsigned long mask)
                printk(KERN_INFO "%s: limit ATAPI UDMA to UDMA4\n", DRV_NAME);
                mask &= ~(0xE0 << ATA_SHIFT_UDMA);
        }
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
@@ -415,6 +415,17 @@ static void scc_dev_select (struct ata_port *ap, unsigned int device)
        ata_sff_pause(ap);
 }
 
+/**
+ *     scc_set_devctl - Write device control reg
+ *     @ap: port where the device is
+ *     @ctl: value to write
+ */
+
+static void scc_set_devctl(struct ata_port *ap, u8 ctl)
+{
+       out_be32(ap->ioaddr.ctl_addr, ctl);
+}
+
 /**
  *     scc_bmdma_setup - Set up PCI IDE BMDMA transaction
  *     @qc: Info associated with this ATA transaction.
@@ -430,7 +441,7 @@ static void scc_bmdma_setup (struct ata_queued_cmd *qc)
        void __iomem *mmio = ap->ioaddr.bmdma_addr;
 
        /* load PRD table addr */
-       out_be32(mmio + SCC_DMA_TABLE_OFS, ap->prd_dma);
+       out_be32(mmio + SCC_DMA_TABLE_OFS, ap->bmdma_prd_dma);
 
        /* specify data direction, triple-check start bit is clear */
        dmactl = in_be32(mmio + SCC_DMA_CMD);
@@ -501,8 +512,8 @@ static unsigned int scc_devchk (struct ata_port *ap,
  *     Note: Original code is ata_sff_wait_after_reset
  */
 
-int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
-                        unsigned long deadline)
+static int scc_wait_after_reset(struct ata_link *link, unsigned int devmask,
+                               unsigned long deadline)
 {
        struct ata_port *ap = link->ap;
        struct ata_ioports *ioaddr = &ap->ioaddr;
@@ -816,54 +827,6 @@ static unsigned int scc_data_xfer (struct ata_device *dev, unsigned char *buf,
        return words << 1;
 }
 
-/**
- *     scc_irq_on - Enable interrupts on a port.
- *     @ap: Port on which interrupts are enabled.
- *
- *     Note: Original code is ata_sff_irq_on().
- */
-
-static u8 scc_irq_on (struct ata_port *ap)
-{
-       struct ata_ioports *ioaddr = &ap->ioaddr;
-       u8 tmp;
-
-       ap->ctl &= ~ATA_NIEN;
-       ap->last_ctl = ap->ctl;
-
-       out_be32(ioaddr->ctl_addr, ap->ctl);
-       tmp = ata_wait_idle(ap);
-
-       ap->ops->sff_irq_clear(ap);
-
-       return tmp;
-}
-
-/**
- *     scc_freeze - Freeze BMDMA controller port
- *     @ap: port to freeze
- *
- *     Note: Original code is ata_sff_freeze().
- */
-
-static void scc_freeze (struct ata_port *ap)
-{
-       struct ata_ioports *ioaddr = &ap->ioaddr;
-
-       ap->ctl |= ATA_NIEN;
-       ap->last_ctl = ap->ctl;
-
-       out_be32(ioaddr->ctl_addr, ap->ctl);
-
-       /* Under certain circumstances, some controllers raise IRQ on
-        * ATA_NIEN manipulation.  Also, many controllers fail to mask
-        * previously pending IRQ on ATA_NIEN assertion.  Clear it.
-        */
-       ap->ops->sff_check_status(ap);
-
-       ap->ops->sff_irq_clear(ap);
-}
-
 /**
  *     scc_pata_prereset - prepare for reset
  *     @ap: ATA port to be reset
@@ -903,8 +866,7 @@ static void scc_postreset(struct ata_link *link, unsigned int *classes)
        }
 
        /* set up device control */
-       if (ap->ioaddr.ctl_addr)
-               out_be32(ap->ioaddr.ctl_addr, ap->ctl);
+       out_be32(ap->ioaddr.ctl_addr, ap->ctl);
 
        DPRINTK("EXIT\n");
 }
@@ -930,7 +892,7 @@ static void scc_irq_clear (struct ata_port *ap)
  *     scc_port_start - Set port up for dma.
  *     @ap: Port to initialize
  *
- *     Allocate space for PRD table using ata_port_start().
+ *     Allocate space for PRD table using ata_bmdma_port_start().
  *     Set PRD table address for PTERADD. (PRD Transfer End Read)
  */
 
@@ -939,11 +901,11 @@ static int scc_port_start (struct ata_port *ap)
        void __iomem *mmio = ap->ioaddr.bmdma_addr;
        int rc;
 
-       rc = ata_port_start(ap);
+       rc = ata_bmdma_port_start(ap);
        if (rc)
                return rc;
 
-       out_be32(mmio + SCC_DMA_PTERADD, ap->prd_dma);
+       out_be32(mmio + SCC_DMA_PTERADD, ap->bmdma_prd_dma);
        return 0;
 }
 
@@ -978,6 +940,7 @@ static struct ata_port_operations scc_pata_ops = {
        .sff_check_status       = scc_check_status,
        .sff_check_altstatus    = scc_check_altstatus,
        .sff_dev_select         = scc_dev_select,
+       .sff_set_devctl         = scc_set_devctl,
 
        .bmdma_setup            = scc_bmdma_setup,
        .bmdma_start            = scc_bmdma_start,
@@ -985,14 +948,11 @@ static struct ata_port_operations scc_pata_ops = {
        .bmdma_status           = scc_bmdma_status,
        .sff_data_xfer          = scc_data_xfer,
 
-       .freeze                 = scc_freeze,
        .prereset               = scc_pata_prereset,
        .softreset              = scc_softreset,
        .postreset              = scc_postreset,
-       .post_internal_cmd      = scc_bmdma_stop,
 
        .sff_irq_clear          = scc_irq_clear,
-       .sff_irq_on             = scc_irq_on,
 
        .port_start             = scc_port_start,
        .port_stop              = scc_port_stop,
index 99cceb4..86b3d01 100644 (file)
@@ -174,22 +174,12 @@ static int __devinit sch_init_one(struct pci_dev *pdev,
 {
        static int printed_version;
        const struct ata_port_info *ppi[] = { &sch_port_info, NULL };
-       struct ata_host *host;
-       int rc;
 
        if (!printed_version++)
                dev_printk(KERN_DEBUG, &pdev->dev,
                           "version " DRV_VERSION "\n");
 
-       /* enable device and prepare host */
-       rc = pcim_enable_device(pdev);
-       if (rc)
-               return rc;
-       rc = ata_pci_sff_prepare_host(pdev, ppi, &host);
-       if (rc)
-               return rc;
-       pci_set_master(pdev);
-       return ata_pci_sff_activate_host(host, ata_sff_interrupt, &sch_sht);
+       return ata_pci_sff_init_one(pdev, ppi, &sch_sht, NULL, 0);
 }
 
 static int __init sch_init(void)
index 9524d54..43ea389 100644 (file)
@@ -198,7 +198,7 @@ static unsigned long serverworks_osb4_filter(struct ata_device *adev, unsigned l
 {
        if (adev->class == ATA_DEV_ATA)
                mask &= ~ATA_MASK_UDMA;
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 
@@ -218,7 +218,7 @@ static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned lo
 
        /* Disk, UDMA */
        if (adev->class != ATA_DEV_ATA)
-               return ata_bmdma_mode_filter(adev, mask);
+               return mask;
 
        /* Actually do need to check */
        ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
@@ -227,7 +227,7 @@ static unsigned long serverworks_csb_filter(struct ata_device *adev, unsigned lo
                if (!strcmp(p, model_num))
                        mask &= ~(0xE0 << ATA_SHIFT_UDMA);
        }
-       return ata_bmdma_mode_filter(adev, mask);
+       return mask;
 }
 
 /**
index c6c589c..43faf10 100644 (file)
@@ -190,15 +190,37 @@ static void sil680_set_dmamode(struct ata_port *ap, struct ata_device *adev)
        pci_write_config_word(pdev, ua, ultra);
 }
 
+/**
+ *     sil680_sff_exec_command - issue ATA command to host controller
+ *     @ap: port to which command is being issued
+ *     @tf: ATA taskfile register set
+ *
+ *     Issues ATA command, with proper synchronization with interrupt
+ *     handler / other threads. Use our MMIO space for PCI posting to avoid
+ *     a hideously slow cycle all the way to the device.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void sil680_sff_exec_command(struct ata_port *ap,
+                                       const struct ata_taskfile *tf)
+{
+       DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
+       iowrite8(tf->command, ap->ioaddr.command_addr);
+       ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
+}
+
 static struct scsi_host_template sil680_sht = {
        ATA_BMDMA_SHT(DRV_NAME),
 };
 
+
 static struct ata_port_operations sil680_port_ops = {
-       .inherits       = &ata_bmdma32_port_ops,
-       .cable_detect   = sil680_cable_detect,
-       .set_piomode    = sil680_set_piomode,
-       .set_dmamode    = sil680_set_dmamode,
+       .inherits               = &ata_bmdma32_port_ops,
+       .sff_exec_command       = sil680_sff_exec_command,
+       .cable_detect           = sil680_cable_detect,
+       .set_piomode            = sil680_set_piomode,
+       .set_dmamode            = sil680_set_dmamode,
 };
 
 /**
index 741e7cb..7e3e0a5 100644 (file)
@@ -355,7 +355,7 @@ static unsigned long via_mode_filter(struct ata_device *dev, unsigned long mask)
                        mask &= ~ ATA_MASK_UDMA;
                }
        }
-       return ata_bmdma_mode_filter(dev, mask);
+       return mask;
 }
 
 /**
@@ -417,8 +417,6 @@ static void via_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
                        tf->lbam,
                        tf->lbah);
        }
-
-       ata_wait_idle(ap);
 }
 
 static int via_port_start(struct ata_port *ap)
@@ -426,7 +424,7 @@ static int via_port_start(struct ata_port *ap)
        struct via_port *vp;
        struct pci_dev *pdev = to_pci_dev(ap->host->dev);
 
-       int ret = ata_sff_port_start(ap);
+       int ret = ata_bmdma_port_start(ap);
        if (ret < 0)
                return ret;
 
index 5904cfd..adbe042 100644 (file)
@@ -324,10 +324,8 @@ static void adma_qc_prep(struct ata_queued_cmd *qc)
        VPRINTK("ENTER\n");
 
        adma_enter_reg_mode(qc->ap);
-       if (qc->tf.protocol != ATA_PROT_DMA) {
-               ata_sff_qc_prep(qc);
+       if (qc->tf.protocol != ATA_PROT_DMA)
                return;
-       }
 
        buf[i++] = 0;   /* Response flags */
        buf[i++] = 0;   /* reserved */
@@ -442,8 +440,6 @@ static inline unsigned int adma_intr_pkt(struct ata_host *host)
                        continue;
                handled = 1;
                adma_enter_reg_mode(ap);
-               if (ap->flags & ATA_FLAG_DISABLED)
-                       continue;
                pp = ap->private_data;
                if (!pp || pp->state != adma_state_pkt)
                        continue;
@@ -484,42 +480,38 @@ static inline unsigned int adma_intr_mmio(struct ata_host *host)
        unsigned int handled = 0, port_no;
 
        for (port_no = 0; port_no < host->n_ports; ++port_no) {
-               struct ata_port *ap;
-               ap = host->ports[port_no];
-               if (ap && (!(ap->flags & ATA_FLAG_DISABLED))) {
-                       struct ata_queued_cmd *qc;
-                       struct adma_port_priv *pp = ap->private_data;
-                       if (!pp || pp->state != adma_state_mmio)
+               struct ata_port *ap = host->ports[port_no];
+               struct adma_port_priv *pp = ap->private_data;
+               struct ata_queued_cmd *qc;
+
+               if (!pp || pp->state != adma_state_mmio)
+                       continue;
+               qc = ata_qc_from_tag(ap, ap->link.active_tag);
+               if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
+
+                       /* check main status, clearing INTRQ */
+                       u8 status = ata_sff_check_status(ap);
+                       if ((status & ATA_BUSY))
                                continue;
-                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
-                       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
-
-                               /* check main status, clearing INTRQ */
-                               u8 status = ata_sff_check_status(ap);
-                               if ((status & ATA_BUSY))
-                                       continue;
-                               DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
-                                       ap->print_id, qc->tf.protocol, status);
-
-                               /* complete taskfile transaction */
-                               pp->state = adma_state_idle;
-                               qc->err_mask |= ac_err_mask(status);
-                               if (!qc->err_mask)
-                                       ata_qc_complete(qc);
-                               else {
-                                       struct ata_eh_info *ehi =
-                                               &ap->link.eh_info;
-                                       ata_ehi_clear_desc(ehi);
-                                       ata_ehi_push_desc(ehi,
-                                               "status 0x%02X", status);
-
-                                       if (qc->err_mask == AC_ERR_DEV)
-                                               ata_port_abort(ap);
-                                       else
-                                               ata_port_freeze(ap);
-                               }
-                               handled = 1;
+                       DPRINTK("ata%u: protocol %d (dev_stat 0x%X)\n",
+                               ap->print_id, qc->tf.protocol, status);
+
+                       /* complete taskfile transaction */
+                       pp->state = adma_state_idle;
+                       qc->err_mask |= ac_err_mask(status);
+                       if (!qc->err_mask)
+                               ata_qc_complete(qc);
+                       else {
+                               struct ata_eh_info *ehi = &ap->link.eh_info;
+                               ata_ehi_clear_desc(ehi);
+                               ata_ehi_push_desc(ehi, "status 0x%02X", status);
+
+                               if (qc->err_mask == AC_ERR_DEV)
+                                       ata_port_abort(ap);
+                               else
+                                       ata_port_freeze(ap);
                        }
+                       handled = 1;
                }
        }
        return handled;
@@ -562,11 +554,7 @@ static int adma_port_start(struct ata_port *ap)
 {
        struct device *dev = ap->host->dev;
        struct adma_port_priv *pp;
-       int rc;
 
-       rc = ata_port_start(ap);
-       if (rc)
-               return rc;
        adma_enter_reg_mode(ap);
        pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
        if (!pp)
index 27dc6c8..a36149e 100644 (file)
@@ -415,22 +415,11 @@ static irqreturn_t inic_interrupt(int irq, void *dev_instance)
 
        spin_lock(&host->lock);
 
-       for (i = 0; i < NR_PORTS; i++) {
-               struct ata_port *ap = host->ports[i];
-
-               if (!(host_irq_stat & (HIRQ_PORT0 << i)))
-                       continue;
-
-               if (likely(ap && !(ap->flags & ATA_FLAG_DISABLED))) {
-                       inic_host_intr(ap);
+       for (i = 0; i < NR_PORTS; i++)
+               if (host_irq_stat & (HIRQ_PORT0 << i)) {
+                       inic_host_intr(host->ports[i]);
                        handled++;
-               } else {
-                       if (ata_ratelimit())
-                               dev_printk(KERN_ERR, host->dev, "interrupt "
-                                          "from disabled port %d (0x%x)\n",
-                                          i, host_irq_stat);
                }
-       }
 
        spin_unlock(&host->lock);
 
@@ -679,8 +668,7 @@ static void init_port(struct ata_port *ap)
        memset(pp->pkt, 0, sizeof(struct inic_pkt));
        memset(pp->cpb_tbl, 0, IDMA_CPB_TBL_SIZE);
 
-       /* setup PRD and CPB lookup table addresses */
-       writel(ap->prd_dma, port_base + PORT_PRD_ADDR);
+       /* setup CPB lookup table addresses */
        writel(pp->cpb_tbl_dma, port_base + PORT_CPB_CPBLAR);
 }
 
@@ -694,7 +682,6 @@ static int inic_port_start(struct ata_port *ap)
 {
        struct device *dev = ap->host->dev;
        struct inic_port_priv *pp;
-       int rc;
 
        /* alloc and initialize private data */
        pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
@@ -703,10 +690,6 @@ static int inic_port_start(struct ata_port *ap)
        ap->private_data = pp;
 
        /* Alloc resources */
-       rc = ata_port_start(ap);
-       if (rc)
-               return rc;
-
        pp->pkt = dmam_alloc_coherent(dev, sizeof(struct inic_pkt),
                                      &pp->pkt_dma, GFP_KERNEL);
        if (!pp->pkt)
index 71cc0d4..f3471bc 100644 (file)
@@ -686,16 +686,27 @@ static struct ata_port_operations mv5_ops = {
 };
 
 static struct ata_port_operations mv6_ops = {
-       .inherits               = &mv5_ops,
+       .inherits               = &ata_bmdma_port_ops,
+
+       .lost_interrupt         = ATA_OP_NULL,
+
+       .qc_defer               = mv_qc_defer,
+       .qc_prep                = mv_qc_prep,
+       .qc_issue               = mv_qc_issue,
+
        .dev_config             = mv6_dev_config,
-       .scr_read               = mv_scr_read,
-       .scr_write              = mv_scr_write,
 
+       .freeze                 = mv_eh_freeze,
+       .thaw                   = mv_eh_thaw,
+       .hardreset              = mv_hardreset,
+       .softreset              = mv_softreset,
        .pmp_hardreset          = mv_pmp_hardreset,
        .pmp_softreset          = mv_softreset,
-       .softreset              = mv_softreset,
        .error_handler          = mv_pmp_error_handler,
 
+       .scr_read               = mv_scr_read,
+       .scr_write              = mv_scr_write,
+
        .sff_check_status       = mv_sff_check_status,
        .sff_irq_clear          = mv_sff_irq_clear,
        .check_atapi_dma        = mv_check_atapi_dma,
@@ -703,6 +714,9 @@ static struct ata_port_operations mv6_ops = {
        .bmdma_start            = mv_bmdma_start,
        .bmdma_stop             = mv_bmdma_stop,
        .bmdma_status           = mv_bmdma_status,
+
+       .port_start             = mv_port_start,
+       .port_stop              = mv_port_stop,
 };
 
 static struct ata_port_operations mv_iie_ops = {
@@ -2248,7 +2262,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
        }
 
        if (qc->tf.flags & ATA_TFLAG_POLLING)
-               ata_pio_queue_task(ap, qc, 0);
+               ata_sff_queue_pio_task(ap, 0);
        return 0;
 }
 
@@ -2344,7 +2358,7 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
                if (IS_GEN_II(hpriv))
                        return mv_qc_issue_fis(qc);
        }
-       return ata_sff_qc_issue(qc);
+       return ata_bmdma_qc_issue(qc);
 }
 
 static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
@@ -2355,13 +2369,9 @@ static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
        if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
                return NULL;
        qc = ata_qc_from_tag(ap, ap->link.active_tag);
-       if (qc) {
-               if (qc->tf.flags & ATA_TFLAG_POLLING)
-                       qc = NULL;
-               else if (!(qc->flags & ATA_QCFLAG_ACTIVE))
-                       qc = NULL;
-       }
-       return qc;
+       if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING))
+               return qc;
+       return NULL;
 }
 
 static void mv_pmp_error_handler(struct ata_port *ap)
@@ -2546,9 +2556,7 @@ static void mv_unexpected_intr(struct ata_port *ap, int edma_was_enabled)
        char *when = "idle";
 
        ata_ehi_clear_desc(ehi);
-       if (ap->flags & ATA_FLAG_DISABLED) {
-               when = "disabled";
-       } else if (edma_was_enabled) {
+       if (edma_was_enabled) {
                when = "EDMA enabled";
        } else {
                struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
@@ -2782,10 +2790,6 @@ static void mv_port_intr(struct ata_port *ap, u32 port_cause)
        struct mv_port_priv *pp;
        int edma_was_enabled;
 
-       if (ap->flags & ATA_FLAG_DISABLED) {
-               mv_unexpected_intr(ap, 0);
-               return;
-       }
        /*
         * Grab a snapshot of the EDMA_EN flag setting,
         * so that we have a consistent view for this port,
@@ -3656,9 +3660,6 @@ static void mv_port_init(struct ata_ioports *port,  void __iomem *port_mmio)
        /* special case: control/altstatus doesn't have ATA_REG_ address */
        port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST;
 
-       /* unused: */
-       port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
-
        /* Clear any currently outstanding port interrupt conditions */
        serr = port_mmio + mv_scr_offset(SCR_ERROR);
        writelfl(readl(serr), serr);
index 2a98b09..baa8f0d 100644 (file)
@@ -272,7 +272,7 @@ enum ncq_saw_flag_list {
 };
 
 struct nv_swncq_port_priv {
-       struct ata_prd  *prd;    /* our SG list */
+       struct ata_bmdma_prd *prd;       /* our SG list */
        dma_addr_t      prd_dma; /* and its DMA mapping */
        void __iomem    *sactive_block;
        void __iomem    *irq_block;
@@ -933,107 +933,108 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
 
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
+               struct nv_adma_port_priv *pp = ap->private_data;
+               void __iomem *mmio = pp->ctl_block;
+               u16 status;
+               u32 gen_ctl;
+               u32 notifier, notifier_error;
+
                notifier_clears[i] = 0;
 
-               if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
-                       struct nv_adma_port_priv *pp = ap->private_data;
-                       void __iomem *mmio = pp->ctl_block;
-                       u16 status;
-                       u32 gen_ctl;
-                       u32 notifier, notifier_error;
-
-                       /* if ADMA is disabled, use standard ata interrupt handler */
-                       if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) {
-                               u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
-                                       >> (NV_INT_PORT_SHIFT * i);
-                               handled += nv_host_intr(ap, irq_stat);
-                               continue;
-                       }
+               /* if ADMA is disabled, use standard ata interrupt handler */
+               if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) {
+                       u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
+                               >> (NV_INT_PORT_SHIFT * i);
+                       handled += nv_host_intr(ap, irq_stat);
+                       continue;
+               }
 
-                       /* if in ATA register mode, check for standard interrupts */
-                       if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
-                               u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
-                                       >> (NV_INT_PORT_SHIFT * i);
-                               if (ata_tag_valid(ap->link.active_tag))
-                                       /** NV_INT_DEV indication seems unreliable at times
-                                           at least in ADMA mode. Force it on always when a
-                                           command is active, to prevent losing interrupts. */
-                                       irq_stat |= NV_INT_DEV;
-                               handled += nv_host_intr(ap, irq_stat);
-                       }
+               /* if in ATA register mode, check for standard interrupts */
+               if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
+                       u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
+                               >> (NV_INT_PORT_SHIFT * i);
+                       if (ata_tag_valid(ap->link.active_tag))
+                               /** NV_INT_DEV indication seems unreliable
+                                   at times at least in ADMA mode. Force it
+                                   on always when a command is active, to
+                                   prevent losing interrupts. */
+                               irq_stat |= NV_INT_DEV;
+                       handled += nv_host_intr(ap, irq_stat);
+               }
+
+               notifier = readl(mmio + NV_ADMA_NOTIFIER);
+               notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
+               notifier_clears[i] = notifier | notifier_error;
+
+               gen_ctl = readl(pp->gen_block + NV_ADMA_GEN_CTL);
+
+               if (!NV_ADMA_CHECK_INTR(gen_ctl, ap->port_no) && !notifier &&
+                   !notifier_error)
+                       /* Nothing to do */
+                       continue;
+
+               status = readw(mmio + NV_ADMA_STAT);
+
+               /*
+                * Clear status. Ensure the controller sees the
+                * clearing before we start looking at any of the CPB
+                * statuses, so that any CPB completions after this
+                * point in the handler will raise another interrupt.
+                */
+               writew(status, mmio + NV_ADMA_STAT);
+               readw(mmio + NV_ADMA_STAT); /* flush posted write */
+               rmb();
+
+               handled++; /* irq handled if we got here */
 
-                       notifier = readl(mmio + NV_ADMA_NOTIFIER);
-                       notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
-                       notifier_clears[i] = notifier | notifier_error;
-
-                       gen_ctl = readl(pp->gen_block + NV_ADMA_GEN_CTL);
-
-                       if (!NV_ADMA_CHECK_INTR(gen_ctl, ap->port_no) && !notifier &&
-                           !notifier_error)
-                               /* Nothing to do */
-                               continue;
-
-                       status = readw(mmio + NV_ADMA_STAT);
-
-                       /* Clear status. Ensure the controller sees the clearing before we start
-                          looking at any of the CPB statuses, so that any CPB completions after
-                          this point in the handler will raise another interrupt. */
-                       writew(status, mmio + NV_ADMA_STAT);
-                       readw(mmio + NV_ADMA_STAT); /* flush posted write */
-                       rmb();
-
-                       handled++; /* irq handled if we got here */
-
-                       /* freeze if hotplugged or controller error */
-                       if (unlikely(status & (NV_ADMA_STAT_HOTPLUG |
-                                              NV_ADMA_STAT_HOTUNPLUG |
-                                              NV_ADMA_STAT_TIMEOUT |
-                                              NV_ADMA_STAT_SERROR))) {
-                               struct ata_eh_info *ehi = &ap->link.eh_info;
-
-                               ata_ehi_clear_desc(ehi);
-                               __ata_ehi_push_desc(ehi, "ADMA status 0x%08x: ", status);
-                               if (status & NV_ADMA_STAT_TIMEOUT) {
-                                       ehi->err_mask |= AC_ERR_SYSTEM;
-                                       ata_ehi_push_desc(ehi, "timeout");
-                               } else if (status & NV_ADMA_STAT_HOTPLUG) {
-                                       ata_ehi_hotplugged(ehi);
-                                       ata_ehi_push_desc(ehi, "hotplug");
-                               } else if (status & NV_ADMA_STAT_HOTUNPLUG) {
-                                       ata_ehi_hotplugged(ehi);
-                                       ata_ehi_push_desc(ehi, "hot unplug");
-                               } else if (status & NV_ADMA_STAT_SERROR) {
-                                       /* let libata analyze SError and figure out the cause */
-                                       ata_ehi_push_desc(ehi, "SError");
-                               } else
-                                       ata_ehi_push_desc(ehi, "unknown");
-                               ata_port_freeze(ap);
-                               continue;
+               /* freeze if hotplugged or controller error */
+               if (unlikely(status & (NV_ADMA_STAT_HOTPLUG |
+                                      NV_ADMA_STAT_HOTUNPLUG |
+                                      NV_ADMA_STAT_TIMEOUT |
+                                      NV_ADMA_STAT_SERROR))) {
+                       struct ata_eh_info *ehi = &ap->link.eh_info;
+
+                       ata_ehi_clear_desc(ehi);
+                       __ata_ehi_push_desc(ehi, "ADMA status 0x%08x: ", status);
+                       if (status & NV_ADMA_STAT_TIMEOUT) {
+                               ehi->err_mask |= AC_ERR_SYSTEM;
+                               ata_ehi_push_desc(ehi, "timeout");
+                       } else if (status & NV_ADMA_STAT_HOTPLUG) {
+                               ata_ehi_hotplugged(ehi);
+                               ata_ehi_push_desc(ehi, "hotplug");
+                       } else if (status & NV_ADMA_STAT_HOTUNPLUG) {
+                               ata_ehi_hotplugged(ehi);
+                               ata_ehi_push_desc(ehi, "hot unplug");
+                       } else if (status & NV_ADMA_STAT_SERROR) {
+                               /* let EH analyze SError and figure out cause */
+                               ata_ehi_push_desc(ehi, "SError");
+                       } else
+                               ata_ehi_push_desc(ehi, "unknown");
+                       ata_port_freeze(ap);
+                       continue;
+               }
+
+               if (status & (NV_ADMA_STAT_DONE |
+                             NV_ADMA_STAT_CPBERR |
+                             NV_ADMA_STAT_CMD_COMPLETE)) {
+                       u32 check_commands = notifier_clears[i];
+                       int pos, error = 0;
+
+                       if (status & NV_ADMA_STAT_CPBERR) {
+                               /* check all active commands */
+                               if (ata_tag_valid(ap->link.active_tag))
+                                       check_commands = 1 <<
+                                               ap->link.active_tag;
+                               else
+                                       check_commands = ap->link.sactive;
                        }
 
-                       if (status & (NV_ADMA_STAT_DONE |
-                                     NV_ADMA_STAT_CPBERR |
-                                     NV_ADMA_STAT_CMD_COMPLETE)) {
-                               u32 check_commands = notifier_clears[i];
-                               int pos, error = 0;
-
-                               if (status & NV_ADMA_STAT_CPBERR) {
-                                       /* Check all active commands */
-                                       if (ata_tag_valid(ap->link.active_tag))
-                                               check_commands = 1 <<
-                                                       ap->link.active_tag;
-                                       else
-                                               check_commands = ap->
-                                                       link.sactive;
-                               }
-
-                               /** Check CPBs for completed commands */
-                               while ((pos = ffs(check_commands)) && !error) {
-                                       pos--;
-                                       error = nv_adma_check_cpb(ap, pos,
+                       /* check CPBs for completed commands */
+                       while ((pos = ffs(check_commands)) && !error) {
+                               pos--;
+                               error = nv_adma_check_cpb(ap, pos,
                                                notifier_error & (1 << pos));
-                                       check_commands &= ~(1 << pos);
-                               }
+                               check_commands &= ~(1 << pos);
                        }
                }
        }
@@ -1130,7 +1131,7 @@ static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc)
        struct nv_adma_port_priv *pp = qc->ap->private_data;
 
        if (pp->flags & NV_ADMA_PORT_REGISTER_MODE)
-               ata_sff_post_internal_cmd(qc);
+               ata_bmdma_post_internal_cmd(qc);
 }
 
 static int nv_adma_port_start(struct ata_port *ap)
@@ -1155,7 +1156,8 @@ static int nv_adma_port_start(struct ata_port *ap)
        if (rc)
                return rc;
 
-       rc = ata_port_start(ap);
+       /* we might fallback to bmdma, allocate bmdma resources */
+       rc = ata_bmdma_port_start(ap);
        if (rc)
                return rc;
 
@@ -1407,7 +1409,7 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
                BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
                        (qc->flags & ATA_QCFLAG_DMAMAP));
                nv_adma_register_mode(qc->ap);
-               ata_sff_qc_prep(qc);
+               ata_bmdma_qc_prep(qc);
                return;
        }
 
@@ -1466,7 +1468,7 @@ static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
                BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
                        (qc->flags & ATA_QCFLAG_DMAMAP));
                nv_adma_register_mode(qc->ap);
-               return ata_sff_qc_issue(qc);
+               return ata_bmdma_qc_issue(qc);
        } else
                nv_adma_mode(qc->ap);
 
@@ -1498,22 +1500,19 @@ static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance)
        spin_lock_irqsave(&host->lock, flags);
 
        for (i = 0; i < host->n_ports; i++) {
-               struct ata_port *ap;
-
-               ap = host->ports[i];
-               if (ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
-                       struct ata_queued_cmd *qc;
+               struct ata_port *ap = host->ports[i];
+               struct ata_queued_cmd *qc;
 
-                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
-                       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING)))
-                               handled += ata_sff_host_intr(ap, qc);
-                       else
-                               // No request pending?  Clear interrupt status
-                               // anyway, in case there's one pending.
-                               ap->ops->sff_check_status(ap);
+               qc = ata_qc_from_tag(ap, ap->link.active_tag);
+               if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
+                       handled += ata_sff_host_intr(ap, qc);
+               } else {
+                       /*
+                        * No request pending?  Clear interrupt status
+                        * anyway, in case there's one pending.
+                        */
+                       ap->ops->sff_check_status(ap);
                }
-
        }
 
        spin_unlock_irqrestore(&host->lock, flags);
@@ -1526,11 +1525,7 @@ static irqreturn_t nv_do_interrupt(struct ata_host *host, u8 irq_stat)
        int i, handled = 0;
 
        for (i = 0; i < host->n_ports; i++) {
-               struct ata_port *ap = host->ports[i];
-
-               if (ap && !(ap->flags & ATA_FLAG_DISABLED))
-                       handled += nv_host_intr(ap, irq_stat);
-
+               handled += nv_host_intr(host->ports[i], irq_stat);
                irq_stat >>= NV_INT_PORT_SHIFT;
        }
 
@@ -1744,7 +1739,7 @@ static void nv_adma_error_handler(struct ata_port *ap)
                readw(mmio + NV_ADMA_CTL);      /* flush posted write */
        }
 
-       ata_sff_error_handler(ap);
+       ata_bmdma_error_handler(ap);
 }
 
 static void nv_swncq_qc_to_dq(struct ata_port *ap, struct ata_queued_cmd *qc)
@@ -1870,7 +1865,7 @@ static void nv_swncq_error_handler(struct ata_port *ap)
                ehc->i.action |= ATA_EH_RESET;
        }
 
-       ata_sff_error_handler(ap);
+       ata_bmdma_error_handler(ap);
 }
 
 #ifdef CONFIG_PM
@@ -1991,7 +1986,8 @@ static int nv_swncq_port_start(struct ata_port *ap)
        struct nv_swncq_port_priv *pp;
        int rc;
 
-       rc = ata_port_start(ap);
+       /* we might fallback to bmdma, allocate bmdma resources */
+       rc = ata_bmdma_port_start(ap);
        if (rc)
                return rc;
 
@@ -2016,7 +2012,7 @@ static int nv_swncq_port_start(struct ata_port *ap)
 static void nv_swncq_qc_prep(struct ata_queued_cmd *qc)
 {
        if (qc->tf.protocol != ATA_PROT_NCQ) {
-               ata_sff_qc_prep(qc);
+               ata_bmdma_qc_prep(qc);
                return;
        }
 
@@ -2031,7 +2027,7 @@ static void nv_swncq_fill_sg(struct ata_queued_cmd *qc)
        struct ata_port *ap = qc->ap;
        struct scatterlist *sg;
        struct nv_swncq_port_priv *pp = ap->private_data;
-       struct ata_prd *prd;
+       struct ata_bmdma_prd *prd;
        unsigned int si, idx;
 
        prd = pp->prd + ATA_MAX_PRD * qc->tag;
@@ -2092,7 +2088,7 @@ static unsigned int nv_swncq_qc_issue(struct ata_queued_cmd *qc)
        struct nv_swncq_port_priv *pp = ap->private_data;
 
        if (qc->tf.protocol != ATA_PROT_NCQ)
-               return ata_sff_qc_issue(qc);
+               return ata_bmdma_qc_issue(qc);
 
        DPRINTK("Enter\n");
 
@@ -2380,16 +2376,14 @@ static irqreturn_t nv_swncq_interrupt(int irq, void *dev_instance)
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
 
-               if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
-                       if (ap->link.sactive) {
-                               nv_swncq_host_interrupt(ap, (u16)irq_stat);
-                               handled = 1;
-                       } else {
-                               if (irq_stat)   /* reserve Hotplug */
-                                       nv_swncq_irq_clear(ap, 0xfff0);
+               if (ap->link.sactive) {
+                       nv_swncq_host_interrupt(ap, (u16)irq_stat);
+                       handled = 1;
+               } else {
+                       if (irq_stat)   /* reserve Hotplug */
+                               nv_swncq_irq_clear(ap, 0xfff0);
 
-                               handled += nv_host_intr(ap, (u8)irq_stat);
-                       }
+                       handled += nv_host_intr(ap, (u8)irq_stat);
                }
                irq_stat >>= NV_INT_PORT_SHIFT_MCP55;
        }
@@ -2479,8 +2473,7 @@ static int nv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        }
 
        pci_set_master(pdev);
-       return ata_host_activate(host, pdev->irq, ipriv->irq_handler,
-                                IRQF_SHARED, ipriv->sht);
+       return ata_pci_sff_activate_host(host, ipriv->irq_handler, ipriv->sht);
 }
 
 #ifdef CONFIG_PM
index 5356ec0..f03ad48 100644 (file)
@@ -333,7 +333,8 @@ static int pdc_common_port_start(struct ata_port *ap)
        struct pdc_port_priv *pp;
        int rc;
 
-       rc = ata_port_start(ap);
+       /* we use the same prd table as bmdma, allocate it */
+       rc = ata_bmdma_port_start(ap);
        if (rc)
                return rc;
 
@@ -499,7 +500,7 @@ static int pdc_sata_scr_write(struct ata_link *link,
 static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
-       dma_addr_t sg_table = ap->prd_dma;
+       dma_addr_t sg_table = ap->bmdma_prd_dma;
        unsigned int cdb_len = qc->dev->cdb_len;
        u8 *cdb = qc->cdb;
        struct pdc_port_priv *pp = ap->private_data;
@@ -587,6 +588,7 @@ static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
 static void pdc_fill_sg(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
+       struct ata_bmdma_prd *prd = ap->bmdma_prd;
        struct scatterlist *sg;
        const u32 SG_COUNT_ASIC_BUG = 41*4;
        unsigned int si, idx;
@@ -613,8 +615,8 @@ static void pdc_fill_sg(struct ata_queued_cmd *qc)
                        if ((offset + sg_len) > 0x10000)
                                len = 0x10000 - offset;
 
-                       ap->prd[idx].addr = cpu_to_le32(addr);
-                       ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff);
+                       prd[idx].addr = cpu_to_le32(addr);
+                       prd[idx].flags_len = cpu_to_le32(len & 0xffff);
                        VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
 
                        idx++;
@@ -623,27 +625,27 @@ static void pdc_fill_sg(struct ata_queued_cmd *qc)
                }
        }
 
-       len = le32_to_cpu(ap->prd[idx - 1].flags_len);
+       len = le32_to_cpu(prd[idx - 1].flags_len);
 
        if (len > SG_COUNT_ASIC_BUG) {
                u32 addr;
 
                VPRINTK("Splitting last PRD.\n");
 
-               addr = le32_to_cpu(ap->prd[idx - 1].addr);
-               ap->prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
+               addr = le32_to_cpu(prd[idx - 1].addr);
+               prd[idx - 1].flags_len = cpu_to_le32(len - SG_COUNT_ASIC_BUG);
                VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx - 1, addr, SG_COUNT_ASIC_BUG);
 
                addr = addr + len - SG_COUNT_ASIC_BUG;
                len = SG_COUNT_ASIC_BUG;
-               ap->prd[idx].addr = cpu_to_le32(addr);
-               ap->prd[idx].flags_len = cpu_to_le32(len);
+               prd[idx].addr = cpu_to_le32(addr);
+               prd[idx].flags_len = cpu_to_le32(len);
                VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
 
                idx++;
        }
 
-       ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+       prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
 }
 
 static void pdc_qc_prep(struct ata_queued_cmd *qc)
@@ -658,7 +660,7 @@ static void pdc_qc_prep(struct ata_queued_cmd *qc)
                pdc_fill_sg(qc);
                /*FALLTHROUGH*/
        case ATA_PROT_NODATA:
-               i = pdc_pkt_header(&qc->tf, qc->ap->prd_dma,
+               i = pdc_pkt_header(&qc->tf, qc->ap->bmdma_prd_dma,
                                   qc->dev->devno, pp->pkt);
                if (qc->tf.flags & ATA_TFLAG_LBA48)
                        i = pdc_prep_lba48(&qc->tf, pp->pkt, i);
@@ -838,7 +840,7 @@ static void pdc_error_handler(struct ata_port *ap)
        if (!(ap->pflags & ATA_PFLAG_FROZEN))
                pdc_reset_port(ap);
 
-       ata_std_error_handler(ap);
+       ata_sff_error_handler(ap);
 }
 
 static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
@@ -984,8 +986,7 @@ static irqreturn_t pdc_interrupt(int irq, void *dev_instance)
                /* check for a plug or unplug event */
                ata_no = pdc_port_no_to_ata_no(i, is_sataii_tx4);
                tmp = hotplug_status & (0x11 << ata_no);
-               if (tmp && ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
+               if (tmp) {
                        struct ata_eh_info *ehi = &ap->link.eh_info;
                        ata_ehi_clear_desc(ehi);
                        ata_ehi_hotplugged(ehi);
@@ -997,8 +998,7 @@ static irqreturn_t pdc_interrupt(int irq, void *dev_instance)
 
                /* check for a packet interrupt */
                tmp = mask & (1 << (i + 1));
-               if (tmp && ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
+               if (tmp) {
                        struct ata_queued_cmd *qc;
 
                        qc = ata_qc_from_tag(ap, ap->link.active_tag);
index 92ba45e..d533b3d 100644 (file)
@@ -147,7 +147,6 @@ static struct ata_port_operations qs_ata_ops = {
        .prereset               = qs_prereset,
        .softreset              = ATA_OP_NULL,
        .error_handler          = qs_error_handler,
-       .post_internal_cmd      = ATA_OP_NULL,
        .lost_interrupt         = ATA_OP_NULL,
 
        .scr_read               = qs_scr_read,
@@ -255,7 +254,7 @@ static int qs_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val)
 static void qs_error_handler(struct ata_port *ap)
 {
        qs_enter_reg_mode(ap);
-       ata_std_error_handler(ap);
+       ata_sff_error_handler(ap);
 }
 
 static int qs_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
@@ -304,10 +303,8 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
        VPRINTK("ENTER\n");
 
        qs_enter_reg_mode(qc->ap);
-       if (qc->tf.protocol != ATA_PROT_DMA) {
-               ata_sff_qc_prep(qc);
+       if (qc->tf.protocol != ATA_PROT_DMA)
                return;
-       }
 
        nelem = qs_fill_sg(qc);
 
@@ -404,26 +401,24 @@ static inline unsigned int qs_intr_pkt(struct ata_host *host)
                        u8 sHST = sff1 & 0x3f;  /* host status */
                        unsigned int port_no = (sff1 >> 8) & 0x03;
                        struct ata_port *ap = host->ports[port_no];
+                       struct qs_port_priv *pp = ap->private_data;
+                       struct ata_queued_cmd *qc;
 
                        DPRINTK("SFF=%08x%08x: sCHAN=%u sHST=%d sDST=%02x\n",
                                        sff1, sff0, port_no, sHST, sDST);
                        handled = 1;
-                       if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
-                               struct ata_queued_cmd *qc;
-                               struct qs_port_priv *pp = ap->private_data;
-                               if (!pp || pp->state != qs_state_pkt)
-                                       continue;
-                               qc = ata_qc_from_tag(ap, ap->link.active_tag);
-                               if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
-                                       switch (sHST) {
-                                       case 0: /* successful CPB */
-                                       case 3: /* device error */
-                                               qs_enter_reg_mode(qc->ap);
-                                               qs_do_or_die(qc, sDST);
-                                               break;
-                                       default:
-                                               break;
-                                       }
+                       if (!pp || pp->state != qs_state_pkt)
+                               continue;
+                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
+                       if (qc && (!(qc->tf.flags & ATA_TFLAG_POLLING))) {
+                               switch (sHST) {
+                               case 0: /* successful CPB */
+                               case 3: /* device error */
+                                       qs_enter_reg_mode(qc->ap);
+                                       qs_do_or_die(qc, sDST);
+                                       break;
+                               default:
+                                       break;
                                }
                        }
                }
@@ -436,33 +431,30 @@ static inline unsigned int qs_intr_mmio(struct ata_host *host)
        unsigned int handled = 0, port_no;
 
        for (port_no = 0; port_no < host->n_ports; ++port_no) {
-               struct ata_port *ap;
-               ap = host->ports[port_no];
-               if (ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
-                       struct ata_queued_cmd *qc;
-                       struct qs_port_priv *pp;
-                       qc = ata_qc_from_tag(ap, ap->link.active_tag);
-                       if (!qc || !(qc->flags & ATA_QCFLAG_ACTIVE)) {
-                               /*
-                                * The qstor hardware generates spurious
-                                * interrupts from time to time when switching
-                                * in and out of packet mode.
-                                * There's no obvious way to know if we're
-                                * here now due to that, so just ack the irq
-                                * and pretend we knew it was ours.. (ugh).
-                                * This does not affect packet mode.
-                                */
-                               ata_sff_check_status(ap);
-                               handled = 1;
-                               continue;
-                       }
-                       pp = ap->private_data;
-                       if (!pp || pp->state != qs_state_mmio)
-                               continue;
-                       if (!(qc->tf.flags & ATA_TFLAG_POLLING))
-                               handled |= ata_sff_host_intr(ap, qc);
+               struct ata_port *ap = host->ports[port_no];
+               struct qs_port_priv *pp = ap->private_data;
+               struct ata_queued_cmd *qc;
+
+               qc = ata_qc_from_tag(ap, ap->link.active_tag);
+               if (!qc) {
+                       /*
+                        * The qstor hardware generates spurious
+                        * interrupts from time to time when switching
+                        * in and out of packet mode.  There's no
+                        * obvious way to know if we're here now due
+                        * to that, so just ack the irq and pretend we
+                        * knew it was ours.. (ugh).  This does not
+                        * affect packet mode.
+                        */
+                       ata_sff_check_status(ap);
+                       handled = 1;
+                       continue;
                }
+
+               if (!pp || pp->state != qs_state_mmio)
+                       continue;
+               if (!(qc->tf.flags & ATA_TFLAG_POLLING))
+                       handled |= ata_sff_host_intr(ap, qc);
        }
        return handled;
 }
@@ -509,11 +501,7 @@ static int qs_port_start(struct ata_port *ap)
        void __iomem *mmio_base = qs_mmio_base(ap->host);
        void __iomem *chan = mmio_base + (ap->port_no * 0x4000);
        u64 addr;
-       int rc;
 
-       rc = ata_port_start(ap);
-       if (rc)
-               return rc;
        pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
        if (!pp)
                return -ENOMEM;
index 3cb69d5..2dda312 100644 (file)
@@ -284,7 +284,7 @@ static void sil_bmdma_setup(struct ata_queued_cmd *qc)
        void __iomem *bmdma = ap->ioaddr.bmdma_addr;
 
        /* load PRD table addr. */
-       iowrite32(ap->prd_dma, bmdma + ATA_DMA_TABLE_OFS);
+       iowrite32(ap->bmdma_prd_dma, bmdma + ATA_DMA_TABLE_OFS);
 
        /* issue r/w command */
        ap->ops->sff_exec_command(ap, &qc->tf);
@@ -311,10 +311,10 @@ static void sil_fill_sg(struct ata_queued_cmd *qc)
 {
        struct scatterlist *sg;
        struct ata_port *ap = qc->ap;
-       struct ata_prd *prd, *last_prd = NULL;
+       struct ata_bmdma_prd *prd, *last_prd = NULL;
        unsigned int si;
 
-       prd = &ap->prd[0];
+       prd = &ap->bmdma_prd[0];
        for_each_sg(qc->sg, sg, qc->n_elem, si) {
                /* Note h/w doesn't support 64-bit, so we unconditionally
                 * truncate dma_addr_t to u32.
@@ -532,9 +532,6 @@ static irqreturn_t sil_interrupt(int irq, void *dev_instance)
                struct ata_port *ap = host->ports[i];
                u32 bmdma2 = readl(mmio_base + sil_port[ap->port_no].bmdma2);
 
-               if (unlikely(ap->flags & ATA_FLAG_DISABLED))
-                       continue;
-
                /* turn off SATA_IRQ if not supported */
                if (ap->flags & SIL_FLAG_NO_SATA_IRQ)
                        bmdma2 &= ~SIL_DMA_SATA_IRQ;
index 433b6b8..e925051 100644 (file)
@@ -1160,13 +1160,8 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance)
 
        for (i = 0; i < host->n_ports; i++)
                if (status & (1 << i)) {
-                       struct ata_port *ap = host->ports[i];
-                       if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
-                               sil24_host_intr(ap);
-                               handled++;
-                       } else
-                               printk(KERN_ERR DRV_NAME
-                                      ": interrupt from disabled port %d\n", i);
+                       sil24_host_intr(host->ports[i]);
+                       handled++;
                }
 
        spin_unlock(&host->lock);
index 7257f2d..101fd6a 100644 (file)
@@ -224,7 +224,7 @@ static void k2_bmdma_setup_mmio(struct ata_queued_cmd *qc)
 
        /* load PRD table addr. */
        mb();   /* make sure PRD table writes are visible to controller */
-       writel(ap->prd_dma, mmio + ATA_DMA_TABLE_OFS);
+       writel(ap->bmdma_prd_dma, mmio + ATA_DMA_TABLE_OFS);
 
        /* specify data direction, triple-check start bit is clear */
        dmactl = readb(mmio + ATA_DMA_CMD);
index 232468f..bedd518 100644 (file)
@@ -302,11 +302,6 @@ static int pdc_port_start(struct ata_port *ap)
 {
        struct device *dev = ap->host->dev;
        struct pdc_port_priv *pp;
-       int rc;
-
-       rc = ata_port_start(ap);
-       if (rc)
-               return rc;
 
        pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
        if (!pp)
@@ -840,8 +835,7 @@ static irqreturn_t pdc20621_interrupt(int irq, void *dev_instance)
                        ap = host->ports[port_no];
                tmp = mask & (1 << i);
                VPRINTK("seq %u, port_no %u, ap %p, tmp %x\n", i, port_no, ap, tmp);
-               if (tmp && ap &&
-                   !(ap->flags & ATA_FLAG_DISABLED)) {
+               if (tmp && ap) {
                        struct ata_queued_cmd *qc;
 
                        qc = ata_qc_from_tag(ap, ap->link.active_tag);
@@ -927,7 +921,7 @@ static void pdc_error_handler(struct ata_port *ap)
        if (!(ap->pflags & ATA_PFLAG_FROZEN))
                pdc_reset_port(ap);
 
-       ata_std_error_handler(ap);
+       ata_sff_error_handler(ap);
 }
 
 static void pdc_post_internal_cmd(struct ata_queued_cmd *qc)
index 011e098..d8dac17 100644 (file)
@@ -181,9 +181,7 @@ static int uli_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (rc)
                return rc;
 
-       rc = ata_pci_bmdma_init(host);
-       if (rc)
-               return rc;
+       ata_pci_bmdma_init(host);
 
        iomap = host->iomap;
 
index 8b2a278..2107952 100644 (file)
@@ -284,14 +284,8 @@ static irqreturn_t vsc_sata_interrupt(int irq, void *dev_instance)
        for (i = 0; i < host->n_ports; i++) {
                u8 port_status = (status >> (8 * i)) & 0xff;
                if (port_status) {
-                       struct ata_port *ap = host->ports[i];
-
-                       if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
-                               vsc_port_intr(port_status, ap);
-                               handled++;
-                       } else
-                               dev_printk(KERN_ERR, host->dev,
-                                       "interrupt from disabled port %d\n", i);
+                       vsc_port_intr(port_status, host->ports[i]);
+                       handled++;
                }
        }
 
index 8ad4ffe..6e6b6a1 100644 (file)
@@ -80,20 +80,6 @@ void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
 }
 EXPORT_SYMBOL_GPL(iommu_detach_device);
 
-int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
-                   phys_addr_t paddr, size_t size, int prot)
-{
-       return iommu_ops->map(domain, iova, paddr, size, prot);
-}
-EXPORT_SYMBOL_GPL(iommu_map_range);
-
-void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
-                     size_t size)
-{
-       iommu_ops->unmap(domain, iova, size);
-}
-EXPORT_SYMBOL_GPL(iommu_unmap_range);
-
 phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
                               unsigned long iova)
 {
@@ -107,3 +93,32 @@ int iommu_domain_has_cap(struct iommu_domain *domain,
        return iommu_ops->domain_has_cap(domain, cap);
 }
 EXPORT_SYMBOL_GPL(iommu_domain_has_cap);
+
+int iommu_map(struct iommu_domain *domain, unsigned long iova,
+             phys_addr_t paddr, int gfp_order, int prot)
+{
+       unsigned long invalid_mask;
+       size_t size;
+
+       size         = 0x1000UL << gfp_order;
+       invalid_mask = size - 1;
+
+       BUG_ON((iova | paddr) & invalid_mask);
+
+       return iommu_ops->map(domain, iova, paddr, gfp_order, prot);
+}
+EXPORT_SYMBOL_GPL(iommu_map);
+
+int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order)
+{
+       unsigned long invalid_mask;
+       size_t size;
+
+       size         = 0x1000UL << gfp_order;
+       invalid_mask = size - 1;
+
+       BUG_ON(iova & invalid_mask);
+
+       return iommu_ops->unmap(domain, iova, gfp_order);
+}
+EXPORT_SYMBOL_GPL(iommu_unmap);
index 4b4b565..ada6397 100644 (file)
@@ -187,7 +187,7 @@ EXPORT_SYMBOL_GPL(platform_device_alloc);
  * released.
  */
 int platform_device_add_resources(struct platform_device *pdev,
-                                 struct resource *res, unsigned int num)
+                                 const struct resource *res, unsigned int num)
 {
        struct resource *r;
 
@@ -367,7 +367,7 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
  */
 struct platform_device *platform_device_register_simple(const char *name,
                                                        int id,
-                                                       struct resource *res,
+                                                       const struct resource *res,
                                                        unsigned int num)
 {
        struct platform_device *pdev;
@@ -967,17 +967,17 @@ static int platform_pm_restore_noirq(struct device *dev)
 
 int __weak platform_pm_runtime_suspend(struct device *dev)
 {
-       return -ENOSYS;
+       return pm_generic_runtime_suspend(dev);
 };
 
 int __weak platform_pm_runtime_resume(struct device *dev)
 {
-       return -ENOSYS;
+       return pm_generic_runtime_resume(dev);
 };
 
 int __weak platform_pm_runtime_idle(struct device *dev)
 {
-       return -ENOSYS;
+       return pm_generic_runtime_idle(dev);
 };
 
 #else /* !CONFIG_PM_RUNTIME */
@@ -1254,6 +1254,26 @@ static int __init early_platform_driver_probe_id(char *class_str,
                }
 
                if (match) {
+                       /*
+                        * Set up a sensible init_name to enable
+                        * dev_name() and others to be used before the
+                        * rest of the driver core is initialized.
+                        */
+                       if (!match->dev.init_name && slab_is_available()) {
+                               if (match->id != -1)
+                                       match->dev.init_name =
+                                               kasprintf(GFP_KERNEL, "%s.%d",
+                                                         match->name,
+                                                         match->id);
+                               else
+                                       match->dev.init_name =
+                                               kasprintf(GFP_KERNEL, "%s",
+                                                         match->name);
+
+                               if (!match->dev.init_name)
+                                       return -ENOMEM;
+                       }
+
                        if (epdrv->pdrv->probe(match))
                                pr_warning("%s: unable to probe %s early.\n",
                                           class_str, match->name);
index 626dd14..b0ec0e9 100644 (file)
@@ -229,14 +229,16 @@ int __pm_runtime_suspend(struct device *dev, bool from_wq)
 
        if (retval) {
                dev->power.runtime_status = RPM_ACTIVE;
-               pm_runtime_cancel_pending(dev);
-
                if (retval == -EAGAIN || retval == -EBUSY) {
-                       notify = true;
+                       if (dev->power.timer_expires == 0)
+                               notify = true;
                        dev->power.runtime_error = 0;
+               } else {
+                       pm_runtime_cancel_pending(dev);
                }
        } else {
                dev->power.runtime_status = RPM_SUSPENDED;
+               pm_runtime_deactivate_timer(dev);
 
                if (dev->parent) {
                        parent = dev->parent;
@@ -659,8 +661,6 @@ int pm_schedule_suspend(struct device *dev, unsigned int delay)
 
        if (dev->power.runtime_status == RPM_SUSPENDED)
                retval = 1;
-       else if (dev->power.runtime_status == RPM_SUSPENDING)
-               retval = -EINPROGRESS;
        else if (atomic_read(&dev->power.usage_count) > 0
            || dev->power.disable_depth > 0)
                retval = -EAGAIN;
index 86fd937..a4c33bc 100644 (file)
@@ -5,6 +5,7 @@
 #include <linux/device.h>
 #include <linux/string.h>
 #include <linux/pm_runtime.h>
+#include <asm/atomic.h>
 #include "power.h"
 
 /*
@@ -143,7 +144,59 @@ wake_store(struct device * dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
 
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
+#ifdef CONFIG_PM_RUNTIME
+
+static ssize_t rtpm_usagecount_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", atomic_read(&dev->power.usage_count));
+}
+
+static ssize_t rtpm_children_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", dev->power.ignore_children ?
+               0 : atomic_read(&dev->power.child_count));
+}
+
+static ssize_t rtpm_enabled_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       if ((dev->power.disable_depth) && (dev->power.runtime_auto == false))
+               return sprintf(buf, "disabled & forbidden\n");
+       else if (dev->power.disable_depth)
+               return sprintf(buf, "disabled\n");
+       else if (dev->power.runtime_auto == false)
+               return sprintf(buf, "forbidden\n");
+       return sprintf(buf, "enabled\n");
+}
+
+static ssize_t rtpm_status_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
+{
+       if (dev->power.runtime_error)
+               return sprintf(buf, "error\n");
+       switch (dev->power.runtime_status) {
+       case RPM_SUSPENDED:
+               return sprintf(buf, "suspended\n");
+       case RPM_SUSPENDING:
+               return sprintf(buf, "suspending\n");
+       case RPM_RESUMING:
+               return sprintf(buf, "resuming\n");
+       case RPM_ACTIVE:
+               return sprintf(buf, "active\n");
+       }
+       return -EIO;
+}
+
+static DEVICE_ATTR(runtime_usage, 0444, rtpm_usagecount_show, NULL);
+static DEVICE_ATTR(runtime_active_kids, 0444, rtpm_children_show, NULL);
+static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
+static DEVICE_ATTR(runtime_enabled, 0444, rtpm_enabled_show, NULL);
+
+#endif
+
 static ssize_t async_show(struct device *dev, struct device_attribute *attr,
                          char *buf)
 {
@@ -170,15 +223,21 @@ static ssize_t async_store(struct device *dev, struct device_attribute *attr,
 }
 
 static DEVICE_ATTR(async, 0644, async_show, async_store);
-#endif /* CONFIG_PM_SLEEP_ADVANCED_DEBUG */
+#endif /* CONFIG_PM_ADVANCED_DEBUG */
 
 static struct attribute * power_attrs[] = {
 #ifdef CONFIG_PM_RUNTIME
        &dev_attr_control.attr,
 #endif
        &dev_attr_wakeup.attr,
-#ifdef CONFIG_PM_SLEEP_ADVANCED_DEBUG
+#ifdef CONFIG_PM_ADVANCED_DEBUG
        &dev_attr_async.attr,
+#ifdef CONFIG_PM_RUNTIME
+       &dev_attr_runtime_usage.attr,
+       &dev_attr_runtime_active_kids.attr,
+       &dev_attr_runtime_status.attr,
+       &dev_attr_runtime_enabled.attr,
+#endif
 #endif
        NULL,
 };
index 0182a22..832798a 100644 (file)
@@ -66,6 +66,7 @@
 #include <linux/blkdev.h>
 #include <linux/elevator.h>
 #include <linux/interrupt.h>
+#include <linux/platform_device.h>
 
 #include <asm/setup.h>
 #include <asm/uaccess.h>
@@ -1696,34 +1697,18 @@ static struct kobject *floppy_find(dev_t dev, int *part, void *data)
        return get_disk(unit[drive].gendisk);
 }
 
-static int __init amiga_floppy_init(void)
+static int __init amiga_floppy_probe(struct platform_device *pdev)
 {
        int i, ret;
 
-       if (!MACH_IS_AMIGA)
-               return -ENODEV;
-
-       if (!AMIGAHW_PRESENT(AMI_FLOPPY))
-               return -ENODEV;
-
        if (register_blkdev(FLOPPY_MAJOR,"fd"))
                return -EBUSY;
 
-       /*
-        *  We request DSKPTR, DSKLEN and DSKDATA only, because the other
-        *  floppy registers are too spreaded over the custom register space
-        */
-       ret = -EBUSY;
-       if (!request_mem_region(CUSTOM_PHYSADDR+0x20, 8, "amiflop [Paula]")) {
-               printk("fd: cannot get floppy registers\n");
-               goto out_blkdev;
-       }
-
        ret = -ENOMEM;
        if ((raw_buf = (char *)amiga_chip_alloc (RAW_BUF_SIZE, "Floppy")) ==
            NULL) {
                printk("fd: cannot get chip mem buffer\n");
-               goto out_memregion;
+               goto out_blkdev;
        }
 
        ret = -EBUSY;
@@ -1792,18 +1777,13 @@ out_irq2:
        free_irq(IRQ_AMIGA_DSKBLK, NULL);
 out_irq:
        amiga_chip_free(raw_buf);
-out_memregion:
-       release_mem_region(CUSTOM_PHYSADDR+0x20, 8);
 out_blkdev:
        unregister_blkdev(FLOPPY_MAJOR,"fd");
        return ret;
 }
 
-module_init(amiga_floppy_init);
-#ifdef MODULE
-
 #if 0 /* not safe to unload */
-void cleanup_module(void)
+static int __exit amiga_floppy_remove(struct platform_device *pdev)
 {
        int i;
 
@@ -1820,12 +1800,25 @@ void cleanup_module(void)
        custom.dmacon = DMAF_DISK; /* disable DMA */
        amiga_chip_free(raw_buf);
        blk_cleanup_queue(floppy_queue);
-       release_mem_region(CUSTOM_PHYSADDR+0x20, 8);
        unregister_blkdev(FLOPPY_MAJOR, "fd");
 }
 #endif
 
-#else
+static struct platform_driver amiga_floppy_driver = {
+       .driver   = {
+               .name   = "amiga-floppy",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init amiga_floppy_init(void)
+{
+       return platform_driver_probe(&amiga_floppy_driver, amiga_floppy_probe);
+}
+
+module_init(amiga_floppy_init);
+
+#ifndef MODULE
 static int __init amiga_floppy_setup (char *str)
 {
        int n;
@@ -1840,3 +1833,5 @@ static int __init amiga_floppy_setup (char *str)
 
 __setup("floppy=", amiga_floppy_setup);
 #endif
+
+MODULE_ALIAS("platform:amiga-floppy");
index eb5ff05..51ceaee 100644 (file)
@@ -1588,7 +1588,6 @@ static int cciss_ioctl(struct block_device *bdev, fmode_t mode,
 
                        c->Request = ioc->Request;
                        if (ioc->buf_size > 0) {
-                               int i;
                                for (i = 0; i < sg_used; i++) {
                                        temp64.val =
                                            pci_map_single(host->pdev, buff[i],
@@ -2434,7 +2433,7 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
 
        /* if it was the last disk, find the new hightest lun */
        if (clear_all && recalculate_highest_lun) {
-               int i, newhighest = -1;
+               int newhighest = -1;
                for (i = 0; i <= h->highest_lun; i++) {
                        /* if the disk has size > 0, it is available */
                        if (h->drv[i] && h->drv[i]->heads)
index 034e6df..81c78b3 100644 (file)
@@ -164,12 +164,12 @@ unsigned long read_timer(void)
        unsigned long t, flags;
        int i;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
        t = jiffies * 11932;
        outb_p(0, 0x43);
        i = inb_p(0x40);
        i |= inb(0x40) << 8;
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
        return(t - i);
 }
 #endif
index d9bf87c..6f907eb 100644 (file)
@@ -65,7 +65,6 @@ MODULE_LICENSE("GPL");
 
 typedef struct bluecard_info_t {
        struct pcmcia_device *p_dev;
-       dev_node_t node;
 
        struct hci_dev *hdev;
 
@@ -869,9 +868,6 @@ static int bluecard_probe(struct pcmcia_device *link)
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
-       link->irq.Handler = bluecard_interrupt;
 
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
@@ -908,9 +904,9 @@ static int bluecard_config(struct pcmcia_device *link)
        if (i != 0)
                goto failed;
 
-       i = pcmcia_request_irq(link, &link->irq);
+       i = pcmcia_request_irq(link, bluecard_interrupt);
        if (i != 0)
-               link->irq.AssignedIRQ = 0;
+               goto failed;
 
        i = pcmcia_request_configuration(link, &link->conf);
        if (i != 0)
@@ -919,9 +915,6 @@ static int bluecard_config(struct pcmcia_device *link)
        if (bluecard_open(info) != 0)
                goto failed;
 
-       strcpy(info->node.dev_name, info->hdev->name);
-       link->dev_node = &info->node;
-
        return 0;
 
 failed:
index 027cb8b..21e05fd 100644 (file)
@@ -72,7 +72,6 @@ MODULE_FIRMWARE("BT3CPCC.bin");
 
 typedef struct bt3c_info_t {
        struct pcmcia_device *p_dev;
-       dev_node_t node;
 
        struct hci_dev *hdev;
 
@@ -661,9 +660,6 @@ static int bt3c_probe(struct pcmcia_device *link)
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
-       link->irq.Handler = bt3c_interrupt;
 
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
@@ -743,9 +739,9 @@ static int bt3c_config(struct pcmcia_device *link)
        goto failed;
 
 found_port:
-       i = pcmcia_request_irq(link, &link->irq);
+       i = pcmcia_request_irq(link, &bt3c_interrupt);
        if (i != 0)
-               link->irq.AssignedIRQ = 0;
+               goto failed;
 
        i = pcmcia_request_configuration(link, &link->conf);
        if (i != 0)
@@ -754,9 +750,6 @@ found_port:
        if (bt3c_open(info) != 0)
                goto failed;
 
-       strcpy(info->node.dev_name, info->hdev->name);
-       link->dev_node = &info->node;
-
        return 0;
 
 failed:
index 60c0953..4ed7288 100644 (file)
@@ -67,7 +67,6 @@ MODULE_LICENSE("GPL");
 
 typedef struct btuart_info_t {
        struct pcmcia_device *p_dev;
-       dev_node_t node;
 
        struct hci_dev *hdev;
 
@@ -590,9 +589,6 @@ static int btuart_probe(struct pcmcia_device *link)
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
-       link->irq.Handler = btuart_interrupt;
 
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
@@ -672,9 +668,9 @@ static int btuart_config(struct pcmcia_device *link)
        goto failed;
 
 found_port:
-       i = pcmcia_request_irq(link, &link->irq);
+       i = pcmcia_request_irq(link, btuart_interrupt);
        if (i != 0)
-               link->irq.AssignedIRQ = 0;
+               goto failed;
 
        i = pcmcia_request_configuration(link, &link->conf);
        if (i != 0)
@@ -683,9 +679,6 @@ found_port:
        if (btuart_open(info) != 0)
                goto failed;
 
-       strcpy(info->node.dev_name, info->hdev->name);
-       link->dev_node = &info->node;
-
        return 0;
 
 failed:
index 1778831..ef044d5 100644 (file)
@@ -67,7 +67,6 @@ MODULE_LICENSE("GPL");
 
 typedef struct dtl1_info_t {
        struct pcmcia_device *p_dev;
-       dev_node_t node;
 
        struct hci_dev *hdev;
 
@@ -575,9 +574,6 @@ static int dtl1_probe(struct pcmcia_device *link)
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
-       link->irq.Handler = dtl1_interrupt;
 
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
@@ -621,9 +617,9 @@ static int dtl1_config(struct pcmcia_device *link)
        if (pcmcia_loop_config(link, dtl1_confcheck, NULL) < 0)
                goto failed;
 
-       i = pcmcia_request_irq(link, &link->irq);
+       i = pcmcia_request_irq(link, dtl1_interrupt);
        if (i != 0)
-               link->irq.AssignedIRQ = 0;
+               goto failed;
 
        i = pcmcia_request_configuration(link, &link->conf);
        if (i != 0)
@@ -632,9 +628,6 @@ static int dtl1_config(struct pcmcia_device *link)
        if (dtl1_open(info) != 0)
                goto failed;
 
-       strcpy(info->node.dev_name, info->hdev->name);
-       link->dev_node = &info->node;
-
        return 0;
 
 failed:
index fb86708..4b51982 100644 (file)
@@ -1214,7 +1214,7 @@ struct agp_memory *agp_generic_alloc_user(size_t page_count, int type)
                return NULL;
 
        for (i = 0; i < page_count; i++)
-               new->pages[i] = 0;
+               new->pages[i] = NULL;
        new->page_count = 0;
        new->type = type;
        new->num_scratch_pages = pages;
index 7fef305..89d871e 100644 (file)
@@ -253,7 +253,7 @@ static int bsr_add_node(struct device_node *bn)
 
                cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev,
                                                cur, cur->bsr_name);
-               if (!cur->bsr_device) {
+               if (IS_ERR(cur->bsr_device)) {
                        printk(KERN_ERR "device_create failed for %s\n",
                               cur->bsr_name);
                        cdev_del(&cur->bsr_cdev);
index fc8cf7a..4cd8b22 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/seq_file.h>
 #include <linux/dmi.h>
 #include <linux/capability.h>
+#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
@@ -82,8 +83,7 @@ module_param(fan_mult, int, 0);
 MODULE_PARM_DESC(fan_mult, "Factor to multiply fan speed with");
 
 static int i8k_open_fs(struct inode *inode, struct file *file);
-static int i8k_ioctl(struct inode *, struct file *, unsigned int,
-                    unsigned long);
+static long i8k_ioctl(struct file *, unsigned int, unsigned long);
 
 static const struct file_operations i8k_fops = {
        .owner          = THIS_MODULE,
@@ -91,7 +91,7 @@ static const struct file_operations i8k_fops = {
        .read           = seq_read,
        .llseek         = seq_lseek,
        .release        = single_release,
-       .ioctl          = i8k_ioctl,
+       .unlocked_ioctl = i8k_ioctl,
 };
 
 struct smm_regs {
@@ -307,8 +307,8 @@ static int i8k_get_dell_signature(int req_fn)
        return regs.eax == 1145651527 && regs.edx == 1145392204 ? 0 : -1;
 }
 
-static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
-                    unsigned long arg)
+static int
+i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
 {
        int val = 0;
        int speed;
@@ -395,6 +395,17 @@ static int i8k_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
        return 0;
 }
 
+static long i8k_ioctl(struct file *fp, unsigned int cmd, unsigned long arg)
+{
+       long ret;
+
+       lock_kernel();
+       ret = i8k_ioctl_unlocked(fp, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
+
 /*
  * Print the information for /proc/i8k.
  */
index 90b199f..e7956ac 100644 (file)
@@ -106,7 +106,6 @@ static int major;           /* major number we get from the kernel */
 
 struct cm4000_dev {
        struct pcmcia_device *p_dev;
-       dev_node_t node;                /* OS node (major,minor) */
 
        unsigned char atr[MAX_ATR];
        unsigned char rbuf[512];
@@ -884,8 +883,7 @@ static void monitor_card(unsigned long p)
                /* slow down warning, but prompt immediately after insertion */
                if (dev->cwarn == 0 || dev->cwarn == 10) {
                        set_bit(IS_BAD_CARD, &dev->flags);
-                       printk(KERN_WARNING MODULE_NAME ": device %s: ",
-                              dev->node.dev_name);
+                       dev_warn(&dev->p_dev->dev, MODULE_NAME ": ");
                        if (test_bit(IS_BAD_CSUM, &dev->flags)) {
                                DEBUGP(4, dev, "ATR checksum (0x%.2x, should "
                                       "be zero) failed\n", dev->atr_csum);
@@ -1781,11 +1779,6 @@ static int cm4000_config(struct pcmcia_device * link, int devno)
                goto cs_release;
 
        dev = link->priv;
-       sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
-       dev->node.major = major;
-       dev->node.minor = devno;
-       dev->node.next = NULL;
-       link->dev_node = &dev->node;
 
        return 0;
 
index a6a70e4..c0775c8 100644 (file)
@@ -72,7 +72,6 @@ static struct class *cmx_class;
 
 struct reader_dev {
        struct pcmcia_device    *p_dev;
-       dev_node_t              node;
        wait_queue_head_t       devq;
        wait_queue_head_t       poll_wait;
        wait_queue_head_t       read_wait;
@@ -568,10 +567,6 @@ static int reader_config(struct pcmcia_device *link, int devno)
        }
 
        dev = link->priv;
-       sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
-       dev->node.major = major;
-       dev->node.minor = devno;
-       dev->node.next = &dev->node;
 
        DEBUGP(2, dev, "device " DEVICE_NAME "%d at 0x%.4x-0x%.4x\n", devno,
              link->io.BasePort1, link->io.BasePort1+link->io.NumPorts1);
index dff24da..63c32e3 100644 (file)
@@ -195,9 +195,6 @@ static int config_ipwireless(struct ipw_dev *ipw)
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = ipwireless_interrupt;
-
        INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
 
        ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
@@ -205,8 +202,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                                    ipw->is_v2_card, signalled_reboot_callback,
                                    ipw);
 
-       ret = pcmcia_request_irq(link, &link->irq);
-
+       ret = pcmcia_request_irq(link, ipwireless_interrupt);
        if (ret != 0)
                goto exit;
 
@@ -217,7 +213,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                        (unsigned int) link->io.BasePort1,
                        (unsigned int) (link->io.BasePort1 +
                                link->io.NumPorts1 - 1),
-                       (unsigned int) link->irq.AssignedIRQ);
+                       (unsigned int) link->irq);
        if (ipw->attr_memory && ipw->common_memory)
                printk(KERN_INFO IPWIRELESS_PCCARD_NAME
                        ": attr memory 0x%08lx-0x%08lx, common memory 0x%08lx-0x%08lx\n",
@@ -232,8 +228,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
        if (!ipw->network)
                goto exit;
 
-       ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
-                       ipw->nodes);
+       ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network);
        if (!ipw->tty)
                goto exit;
 
@@ -248,8 +243,6 @@ static int config_ipwireless(struct ipw_dev *ipw)
        if (ret != 0)
                goto exit;
 
-       link->dev_node = &ipw->nodes[0];
-
        return 0;
 
 exit:
@@ -271,8 +264,6 @@ exit:
 
 static void release_ipwireless(struct ipw_dev *ipw)
 {
-       pcmcia_disable_device(ipw->link);
-
        if (ipw->common_memory) {
                release_mem_region(ipw->request_common_memory.Base,
                                ipw->request_common_memory.Size);
@@ -288,7 +279,6 @@ static void release_ipwireless(struct ipw_dev *ipw)
        if (ipw->attr_memory)
                pcmcia_release_window(ipw->link, ipw->handle_attr_memory);
 
-       /* Break the link with Card Services */
        pcmcia_disable_device(ipw->link);
 }
 
@@ -313,9 +303,6 @@ static int ipwireless_attach(struct pcmcia_device *link)
        ipw->link = link;
        link->priv = ipw;
 
-       /* Link this device into our device list. */
-       link->dev_node = &ipw->nodes[0];
-
        ipw->hardware = ipwireless_hardware_create();
        if (!ipw->hardware) {
                kfree(ipw);
index 0e0363a..96d0ef3 100644 (file)
@@ -54,7 +54,6 @@ struct ipw_dev {
        void __iomem *common_memory;
        win_req_t request_common_memory;
 
-       dev_node_t nodes[2];
        /* Reference to attribute memory, containing CIS data */
        void *attribute_memory;
 
index 2bb7874..1a2c2c3 100644 (file)
@@ -487,7 +487,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
        return tty_mode_ioctl(linux_tty, file, cmd , arg);
 }
 
-static int add_tty(dev_node_t *nodesp, int j,
+static int add_tty(int j,
                    struct ipw_hardware *hardware,
                    struct ipw_network *network, int channel_idx,
                    int secondary_channel_idx, int tty_type)
@@ -510,19 +510,13 @@ static int add_tty(dev_node_t *nodesp, int j,
                ipwireless_associate_network_tty(network,
                                                 secondary_channel_idx,
                                                 ttys[j]);
-       if (nodesp != NULL) {
-               sprintf(nodesp->dev_name, "ttyIPWp%d", j);
-               nodesp->major = ipw_tty_driver->major;
-               nodesp->minor = j + ipw_tty_driver->minor_start;
-       }
        if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
                report_registering(ttys[j]);
        return 0;
 }
 
 struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
-                                     struct ipw_network *network,
-                                     dev_node_t *nodes)
+                                     struct ipw_network *network)
 {
        int i, j;
 
@@ -539,26 +533,23 @@ struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
                if (allfree) {
                        j = i;
 
-                       if (add_tty(&nodes[0], j, hardware, network,
+                       if (add_tty(j, hardware, network,
                                        IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
                                        TTYTYPE_MODEM))
                                return NULL;
 
                        j += IPWIRELESS_PCMCIA_MINOR_RANGE;
-                       if (add_tty(&nodes[1], j, hardware, network,
+                       if (add_tty(j, hardware, network,
                                        IPW_CHANNEL_DIALLER, -1,
                                        TTYTYPE_MONITOR))
                                return NULL;
 
                        j += IPWIRELESS_PCMCIA_MINOR_RANGE;
-                       if (add_tty(NULL, j, hardware, network,
+                       if (add_tty(j, hardware, network,
                                        IPW_CHANNEL_RAS, -1,
                                        TTYTYPE_RAS_RAW))
                                return NULL;
 
-                       nodes[0].next = &nodes[1];
-                       nodes[1].next = NULL;
-
                        return ttys[i];
                }
        }
index b0deb91..4da6c20 100644 (file)
@@ -34,8 +34,7 @@ int ipwireless_tty_init(void);
 void ipwireless_tty_release(void);
 
 struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hw,
-                                     struct ipw_network *net,
-                                     dev_node_t *nodes);
+                                     struct ipw_network *net);
 void ipwireless_tty_free(struct ipw_tty *tty);
 void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
                             unsigned int length);
index c31a0d9..308903e 100644 (file)
@@ -220,7 +220,6 @@ typedef struct _mgslpc_info {
 
        /* PCMCIA support */
        struct pcmcia_device    *p_dev;
-       dev_node_t            node;
        int                   stop;
 
        /* SPPP/Cisco HDLC device parts */
@@ -552,10 +551,6 @@ static int mgslpc_probe(struct pcmcia_device *link)
 
     /* Initialize the struct pcmcia_device structure */
 
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = NULL;
-
     link->conf.Attributes = 0;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -608,9 +603,7 @@ static int mgslpc_config(struct pcmcia_device *link)
     link->conf.ConfigIndex = 8;
     link->conf.Present = PRESENT_OPTION;
 
-    link->irq.Handler     = mgslpc_isr;
-
-    ret = pcmcia_request_irq(link, &link->irq);
+    ret = pcmcia_request_irq(link, mgslpc_isr);
     if (ret)
            goto failed;
     ret = pcmcia_request_configuration(link, &link->conf);
@@ -618,17 +611,12 @@ static int mgslpc_config(struct pcmcia_device *link)
            goto failed;
 
     info->io_base = link->io.BasePort1;
-    info->irq_level = link->irq.AssignedIRQ;
-
-    /* add to linked list of devices */
-    sprintf(info->node.dev_name, "mgslpc0");
-    info->node.major = info->node.minor = 0;
-    link->dev_node = &info->node;
+    info->irq_level = link->irq;
 
-    printk(KERN_INFO "%s: index 0x%02x:",
-          info->node.dev_name, link->conf.ConfigIndex);
+    dev_info(&link->dev, "index 0x%02x:",
+           link->conf.ConfigIndex);
     if (link->conf.Attributes & CONF_ENABLE_IRQ)
-           printk(", irq %d", link->irq.AssignedIRQ);
+           printk(", irq %d", link->irq);
     if (link->io.NumPorts1)
            printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                   link->io.BasePort1+link->io.NumPorts1-1);
index 8dfd247..78a62eb 100644 (file)
@@ -627,7 +627,6 @@ static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
        char data;
        int char_count;
        int save_cnt;
-       int len;
 
        /* determine the channel and change to that context */
        channel = (u_short) (base_addr[CyLICR] >> 2);
@@ -1528,7 +1527,6 @@ static int
 cy_ioctl(struct tty_struct *tty, struct file *file,
         unsigned int cmd, unsigned long arg)
 {
-       unsigned long val;
        struct cyclades_port *info = tty->driver_data;
        int ret_val = 0;
        void __user *argp = (void __user *)arg;
index 193f9c2..5d15630 100644 (file)
@@ -293,7 +293,7 @@ static struct sysrq_key_op sysrq_showstate_blocked_op = {
 
 static void sysrq_ftrace_dump(int key, struct tty_struct *tty)
 {
-       ftrace_dump();
+       ftrace_dump(DUMP_ALL);
 }
 static struct sysrq_key_op sysrq_ftrace_dump_op = {
        .handler        = sysrq_ftrace_dump,
index f5fc64f..4dc338f 100644 (file)
@@ -17,14 +17,16 @@ menuconfig TCG_TPM
          obtained at: <http://sourceforge.net/projects/trousers>.  To 
          compile this driver as a module, choose M here; the module 
          will be called tpm. If unsure, say N.
-         Note: For more TPM drivers enable CONFIG_PNP, CONFIG_ACPI
+         Notes:
+         1) For more TPM drivers enable CONFIG_PNP, CONFIG_ACPI
          and CONFIG_PNPACPI.
+         2) Without ACPI enabled, the BIOS event log won't be accessible,
+         which is required to validate the PCR 0-7 values.
 
 if TCG_TPM
 
 config TCG_TIS
        tristate "TPM Interface Specification 1.2 Interface"
-       depends on PNP
        ---help---
          If you have a TPM security chip that is compliant with the
          TCG TIS 1.2 TPM specification say Yes and it will be accessible
index 068c816..05ad4a1 100644 (file)
@@ -1068,6 +1068,27 @@ void tpm_remove_hardware(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(tpm_remove_hardware);
 
+#define TPM_ORD_SAVESTATE cpu_to_be32(152)
+#define SAVESTATE_RESULT_SIZE 10
+
+static struct tpm_input_header savestate_header = {
+       .tag = TPM_TAG_RQU_COMMAND,
+       .length = cpu_to_be32(10),
+       .ordinal = TPM_ORD_SAVESTATE
+};
+
+/* Bug workaround - some TPM's don't flush the most
+ * recently changed pcr on suspend, so force the flush
+ * with an extend to the selected _unused_ non-volatile pcr.
+ */
+static int tpm_suspend_pcr;
+static int __init tpm_suspend_setup(char *str)
+{
+       get_option(&str, &tpm_suspend_pcr);
+       return 1;
+}
+__setup("tpm_suspend_pcr=", tpm_suspend_setup);
+
 /*
  * We are about to suspend. Save the TPM state
  * so that it can be restored.
@@ -1075,17 +1096,29 @@ EXPORT_SYMBOL_GPL(tpm_remove_hardware);
 int tpm_pm_suspend(struct device *dev, pm_message_t pm_state)
 {
        struct tpm_chip *chip = dev_get_drvdata(dev);
-       u8 savestate[] = {
-               0, 193,         /* TPM_TAG_RQU_COMMAND */
-               0, 0, 0, 10,    /* blob length (in bytes) */
-               0, 0, 0, 152    /* TPM_ORD_SaveState */
-       };
+       struct tpm_cmd_t cmd;
+       int rc;
+
+       u8 dummy_hash[TPM_DIGEST_SIZE] = { 0 };
 
        if (chip == NULL)
                return -ENODEV;
 
-       tpm_transmit(chip, savestate, sizeof(savestate));
-       return 0;
+       /* for buggy tpm, flush pcrs with extend to selected dummy */
+       if (tpm_suspend_pcr) {
+               cmd.header.in = pcrextend_header;
+               cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(tpm_suspend_pcr);
+               memcpy(cmd.params.pcrextend_in.hash, dummy_hash,
+                      TPM_DIGEST_SIZE);
+               rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
+                                 "extending dummy pcr before suspend");
+       }
+
+       /* now do the actual savestate */
+       cmd.header.in = savestate_header;
+       rc = transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE,
+                         "sending savestate before suspend");
+       return rc;
 }
 EXPORT_SYMBOL_GPL(tpm_pm_suspend);
 
index 9434599..24314a9 100644 (file)
@@ -598,7 +598,7 @@ out_err:
        tpm_remove_hardware(chip->dev);
        return rc;
 }
-
+#ifdef CONFIG_PNP
 static int __devinit tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
                                      const struct pnp_device_id *pnp_id)
 {
@@ -663,7 +663,7 @@ static struct pnp_driver tis_pnp_driver = {
 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
                    sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
-
+#endif
 static int tpm_tis_suspend(struct platform_device *dev, pm_message_t msg)
 {
        return tpm_pm_suspend(&dev->dev, msg);
@@ -690,21 +690,21 @@ MODULE_PARM_DESC(force, "Force device probe rather than using ACPI entry");
 static int __init init_tis(void)
 {
        int rc;
+#ifdef CONFIG_PNP
+       if (!force)
+               return pnp_register_driver(&tis_pnp_driver);
+#endif
 
-       if (force) {
-               rc = platform_driver_register(&tis_drv);
-               if (rc < 0)
-                       return rc;
-               if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
-                       return PTR_ERR(pdev);
-               if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
-                       platform_device_unregister(pdev);
-                       platform_driver_unregister(&tis_drv);
-               }
+       rc = platform_driver_register(&tis_drv);
+       if (rc < 0)
                return rc;
+       if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
+               return PTR_ERR(pdev);
+       if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
+               platform_device_unregister(pdev);
+               platform_driver_unregister(&tis_drv);
        }
-
-       return pnp_register_driver(&tis_pnp_driver);
+       return rc;
 }
 
 static void __exit cleanup_tis(void)
@@ -728,12 +728,14 @@ static void __exit cleanup_tis(void)
                list_del(&i->list);
        }
        spin_unlock(&tis_lock);
-
-       if (force) {
-               platform_device_unregister(pdev);
-               platform_driver_unregister(&tis_drv);
-       } else
+#ifdef CONFIG_PNP
+       if (!force) {
                pnp_unregister_driver(&tis_pnp_driver);
+               return;
+       }
+#endif
+       platform_device_unregister(pdev);
+       platform_driver_unregister(&tis_drv);
 }
 
 module_init(init_tis);
index b314a99..d7be69f 100644 (file)
@@ -154,14 +154,14 @@ static int __init cs5535_mfgpt_init(void)
        if (cs5535_mfgpt_setup_irq(timer, MFGPT_CMP2, &timer_irq)) {
                printk(KERN_ERR DRV_NAME ": Could not set up IRQ %d\n",
                                timer_irq);
-               return -EIO;
+               goto err_timer;
        }
 
        /* And register it with the kernel */
        ret = setup_irq(timer_irq, &mfgptirq);
        if (ret) {
                printk(KERN_ERR DRV_NAME ": Unable to set up the interrupt.\n");
-               goto err;
+               goto err_irq;
        }
 
        /* Set the clock scale and enable the event mode for CMP2 */
@@ -184,8 +184,10 @@ static int __init cs5535_mfgpt_init(void)
 
        return 0;
 
-err:
+err_irq:
        cs5535_mfgpt_release_irq(cs5535_event_clock, MFGPT_CMP2, &timer_irq);
+err_timer:
+       cs5535_mfgpt_free_timer(cs5535_event_clock);
        printk(KERN_ERR DRV_NAME ": Unable to set up the MFGPT clock source\n");
        return -EIO;
 }
index 744f748..f6677cb 100644 (file)
@@ -150,13 +150,12 @@ static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
 
 static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
 {
-       struct sh_timer_config *cfg = p->pdev->dev.platform_data;
        int ret;
 
        /* enable clock */
        ret = clk_enable(p->clk);
        if (ret) {
-               pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk);
+               dev_err(&p->pdev->dev, "cannot enable clock\n");
                return ret;
        }
 
@@ -279,7 +278,7 @@ static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
                        delay = 1;
 
                if (!delay)
-                       pr_warning("sh_cmt: too long delay\n");
+                       dev_warn(&p->pdev->dev, "too long delay\n");
 
        } while (delay);
 }
@@ -289,7 +288,7 @@ static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
        unsigned long flags;
 
        if (delta > p->max_match_value)
-               pr_warning("sh_cmt: delta out of range\n");
+               dev_warn(&p->pdev->dev, "delta out of range\n");
 
        spin_lock_irqsave(&p->lock, flags);
        p->next_match_value = delta;
@@ -451,7 +450,7 @@ static int sh_cmt_register_clocksource(struct sh_cmt_priv *p,
        cs->resume = sh_cmt_clocksource_resume;
        cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8);
        cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
-       pr_info("sh_cmt: %s used as clock source\n", cs->name);
+       dev_info(&p->pdev->dev, "used as clock source\n");
        clocksource_register(cs);
        return 0;
 }
@@ -497,13 +496,11 @@ static void sh_cmt_clock_event_mode(enum clock_event_mode mode,
 
        switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
-               pr_info("sh_cmt: %s used for periodic clock events\n",
-                       ced->name);
+               dev_info(&p->pdev->dev, "used for periodic clock events\n");
                sh_cmt_clock_event_start(p, 1);
                break;
        case CLOCK_EVT_MODE_ONESHOT:
-               pr_info("sh_cmt: %s used for oneshot clock events\n",
-                       ced->name);
+               dev_info(&p->pdev->dev, "used for oneshot clock events\n");
                sh_cmt_clock_event_start(p, 0);
                break;
        case CLOCK_EVT_MODE_SHUTDOWN:
@@ -544,7 +541,7 @@ static void sh_cmt_register_clockevent(struct sh_cmt_priv *p,
        ced->set_next_event = sh_cmt_clock_event_next;
        ced->set_mode = sh_cmt_clock_event_mode;
 
-       pr_info("sh_cmt: %s used for clock events\n", ced->name);
+       dev_info(&p->pdev->dev, "used for clock events\n");
        clockevents_register_device(ced);
 }
 
@@ -601,22 +598,27 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
        /* map memory, let mapbase point to our channel */
        p->mapbase = ioremap_nocache(res->start, resource_size(res));
        if (p->mapbase == NULL) {
-               pr_err("sh_cmt: failed to remap I/O memory\n");
+               dev_err(&p->pdev->dev, "failed to remap I/O memory\n");
                goto err0;
        }
 
        /* request irq using setup_irq() (too early for request_irq()) */
-       p->irqaction.name = cfg->name;
+       p->irqaction.name = dev_name(&p->pdev->dev);
        p->irqaction.handler = sh_cmt_interrupt;
        p->irqaction.dev_id = p;
-       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
+       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | \
+                            IRQF_IRQPOLL  | IRQF_NOBALANCING;
 
        /* get hold of clock */
-       p->clk = clk_get(&p->pdev->dev, cfg->clk);
+       p->clk = clk_get(&p->pdev->dev, "cmt_fck");
        if (IS_ERR(p->clk)) {
-               pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk);
-               ret = PTR_ERR(p->clk);
-               goto err1;
+               dev_warn(&p->pdev->dev, "using deprecated clock lookup\n");
+               p->clk = clk_get(&p->pdev->dev, cfg->clk);
+               if (IS_ERR(p->clk)) {
+                       dev_err(&p->pdev->dev, "cannot get clock\n");
+                       ret = PTR_ERR(p->clk);
+                       goto err1;
+               }
        }
 
        if (resource_size(res) == 6) {
@@ -629,17 +631,17 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
                p->clear_bits = ~0xc000;
        }
 
-       ret = sh_cmt_register(p, cfg->name,
+       ret = sh_cmt_register(p, (char *)dev_name(&p->pdev->dev),
                              cfg->clockevent_rating,
                              cfg->clocksource_rating);
        if (ret) {
-               pr_err("sh_cmt: registration failed\n");
+               dev_err(&p->pdev->dev, "registration failed\n");
                goto err1;
        }
 
        ret = setup_irq(irq, &p->irqaction);
        if (ret) {
-               pr_err("sh_cmt: failed to request irq %d\n", irq);
+               dev_err(&p->pdev->dev, "failed to request irq %d\n", irq);
                goto err1;
        }
 
@@ -654,11 +656,10 @@ err0:
 static int __devinit sh_cmt_probe(struct platform_device *pdev)
 {
        struct sh_cmt_priv *p = platform_get_drvdata(pdev);
-       struct sh_timer_config *cfg = pdev->dev.platform_data;
        int ret;
 
        if (p) {
-               pr_info("sh_cmt: %s kept as earlytimer\n", cfg->name);
+               dev_info(&pdev->dev, "kept as earlytimer\n");
                return 0;
        }
 
index 5fb78bf..ef7a5be 100644 (file)
@@ -119,13 +119,12 @@ static void sh_mtu2_start_stop_ch(struct sh_mtu2_priv *p, int start)
 
 static int sh_mtu2_enable(struct sh_mtu2_priv *p)
 {
-       struct sh_timer_config *cfg = p->pdev->dev.platform_data;
        int ret;
 
        /* enable clock */
        ret = clk_enable(p->clk);
        if (ret) {
-               pr_err("sh_mtu2: cannot enable clock \"%s\"\n", cfg->clk);
+               dev_err(&p->pdev->dev, "cannot enable clock\n");
                return ret;
        }
 
@@ -194,8 +193,7 @@ static void sh_mtu2_clock_event_mode(enum clock_event_mode mode,
 
        switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
-               pr_info("sh_mtu2: %s used for periodic clock events\n",
-                       ced->name);
+               dev_info(&p->pdev->dev, "used for periodic clock events\n");
                sh_mtu2_enable(p);
                break;
        case CLOCK_EVT_MODE_UNUSED:
@@ -222,13 +220,13 @@ static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p,
        ced->cpumask = cpumask_of(0);
        ced->set_mode = sh_mtu2_clock_event_mode;
 
-       pr_info("sh_mtu2: %s used for clock events\n", ced->name);
+       dev_info(&p->pdev->dev, "used for clock events\n");
        clockevents_register_device(ced);
 
        ret = setup_irq(p->irqaction.irq, &p->irqaction);
        if (ret) {
-               pr_err("sh_mtu2: failed to request irq %d\n",
-                      p->irqaction.irq);
+               dev_err(&p->pdev->dev, "failed to request irq %d\n",
+                       p->irqaction.irq);
                return;
        }
 }
@@ -274,26 +272,32 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
        /* map memory, let mapbase point to our channel */
        p->mapbase = ioremap_nocache(res->start, resource_size(res));
        if (p->mapbase == NULL) {
-               pr_err("sh_mtu2: failed to remap I/O memory\n");
+               dev_err(&p->pdev->dev, "failed to remap I/O memory\n");
                goto err0;
        }
 
        /* setup data for setup_irq() (too early for request_irq()) */
-       p->irqaction.name = cfg->name;
+       p->irqaction.name = dev_name(&p->pdev->dev);
        p->irqaction.handler = sh_mtu2_interrupt;
        p->irqaction.dev_id = p;
        p->irqaction.irq = irq;
-       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
+       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | \
+                            IRQF_IRQPOLL  | IRQF_NOBALANCING;
 
        /* get hold of clock */
-       p->clk = clk_get(&p->pdev->dev, cfg->clk);
+       p->clk = clk_get(&p->pdev->dev, "mtu2_fck");
        if (IS_ERR(p->clk)) {
-               pr_err("sh_mtu2: cannot get clock \"%s\"\n", cfg->clk);
-               ret = PTR_ERR(p->clk);
-               goto err1;
+               dev_warn(&p->pdev->dev, "using deprecated clock lookup\n");
+               p->clk = clk_get(&p->pdev->dev, cfg->clk);
+               if (IS_ERR(p->clk)) {
+                       dev_err(&p->pdev->dev, "cannot get clock\n");
+                       ret = PTR_ERR(p->clk);
+                       goto err1;
+               }
        }
 
-       return sh_mtu2_register(p, cfg->name, cfg->clockevent_rating);
+       return sh_mtu2_register(p, (char *)dev_name(&p->pdev->dev),
+                               cfg->clockevent_rating);
  err1:
        iounmap(p->mapbase);
  err0:
@@ -303,11 +307,10 @@ static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
 static int __devinit sh_mtu2_probe(struct platform_device *pdev)
 {
        struct sh_mtu2_priv *p = platform_get_drvdata(pdev);
-       struct sh_timer_config *cfg = pdev->dev.platform_data;
        int ret;
 
        if (p) {
-               pr_info("sh_mtu2: %s kept as earlytimer\n", cfg->name);
+               dev_info(&pdev->dev, "kept as earlytimer\n");
                return 0;
        }
 
index fc9ff1e..8e44e14 100644 (file)
@@ -107,13 +107,12 @@ static void sh_tmu_start_stop_ch(struct sh_tmu_priv *p, int start)
 
 static int sh_tmu_enable(struct sh_tmu_priv *p)
 {
-       struct sh_timer_config *cfg = p->pdev->dev.platform_data;
        int ret;
 
        /* enable clock */
        ret = clk_enable(p->clk);
        if (ret) {
-               pr_err("sh_tmu: cannot enable clock \"%s\"\n", cfg->clk);
+               dev_err(&p->pdev->dev, "cannot enable clock\n");
                return ret;
        }
 
@@ -229,7 +228,7 @@ static int sh_tmu_register_clocksource(struct sh_tmu_priv *p,
        cs->disable = sh_tmu_clocksource_disable;
        cs->mask = CLOCKSOURCE_MASK(32);
        cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
-       pr_info("sh_tmu: %s used as clock source\n", cs->name);
+       dev_info(&p->pdev->dev, "used as clock source\n");
        clocksource_register(cs);
        return 0;
 }
@@ -277,13 +276,11 @@ static void sh_tmu_clock_event_mode(enum clock_event_mode mode,
 
        switch (mode) {
        case CLOCK_EVT_MODE_PERIODIC:
-               pr_info("sh_tmu: %s used for periodic clock events\n",
-                       ced->name);
+               dev_info(&p->pdev->dev, "used for periodic clock events\n");
                sh_tmu_clock_event_start(p, 1);
                break;
        case CLOCK_EVT_MODE_ONESHOT:
-               pr_info("sh_tmu: %s used for oneshot clock events\n",
-                       ced->name);
+               dev_info(&p->pdev->dev, "used for oneshot clock events\n");
                sh_tmu_clock_event_start(p, 0);
                break;
        case CLOCK_EVT_MODE_UNUSED:
@@ -324,13 +321,13 @@ static void sh_tmu_register_clockevent(struct sh_tmu_priv *p,
        ced->set_next_event = sh_tmu_clock_event_next;
        ced->set_mode = sh_tmu_clock_event_mode;
 
-       pr_info("sh_tmu: %s used for clock events\n", ced->name);
+       dev_info(&p->pdev->dev, "used for clock events\n");
        clockevents_register_device(ced);
 
        ret = setup_irq(p->irqaction.irq, &p->irqaction);
        if (ret) {
-               pr_err("sh_tmu: failed to request irq %d\n",
-                      p->irqaction.irq);
+               dev_err(&p->pdev->dev, "failed to request irq %d\n",
+                       p->irqaction.irq);
                return;
        }
 }
@@ -379,26 +376,31 @@ static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev)
        /* map memory, let mapbase point to our channel */
        p->mapbase = ioremap_nocache(res->start, resource_size(res));
        if (p->mapbase == NULL) {
-               pr_err("sh_tmu: failed to remap I/O memory\n");
+               dev_err(&p->pdev->dev, "failed to remap I/O memory\n");
                goto err0;
        }
 
        /* setup data for setup_irq() (too early for request_irq()) */
-       p->irqaction.name = cfg->name;
+       p->irqaction.name = dev_name(&p->pdev->dev);
        p->irqaction.handler = sh_tmu_interrupt;
        p->irqaction.dev_id = p;
        p->irqaction.irq = irq;
-       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
+       p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | \
+                            IRQF_IRQPOLL  | IRQF_NOBALANCING;
 
        /* get hold of clock */
-       p->clk = clk_get(&p->pdev->dev, cfg->clk);
+       p->clk = clk_get(&p->pdev->dev, "tmu_fck");
        if (IS_ERR(p->clk)) {
-               pr_err("sh_tmu: cannot get clock \"%s\"\n", cfg->clk);
-               ret = PTR_ERR(p->clk);
-               goto err1;
+               dev_warn(&p->pdev->dev, "using deprecated clock lookup\n");
+               p->clk = clk_get(&p->pdev->dev, cfg->clk);
+               if (IS_ERR(p->clk)) {
+                       dev_err(&p->pdev->dev, "cannot get clock\n");
+                       ret = PTR_ERR(p->clk);
+                       goto err1;
+               }
        }
 
-       return sh_tmu_register(p, cfg->name,
+       return sh_tmu_register(p, (char *)dev_name(&p->pdev->dev),
                               cfg->clockevent_rating,
                               cfg->clocksource_rating);
  err1:
@@ -410,11 +412,10 @@ static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev)
 static int __devinit sh_tmu_probe(struct platform_device *pdev)
 {
        struct sh_tmu_priv *p = platform_get_drvdata(pdev);
-       struct sh_timer_config *cfg = pdev->dev.platform_data;
        int ret;
 
        if (p) {
-               pr_info("sh_tmu: %s kept as earlytimer\n", cfg->name);
+               dev_info(&pdev->dev, "kept as earlytimer\n");
                return 0;
        }
 
index 75d293e..063b218 100644 (file)
@@ -662,32 +662,20 @@ static ssize_t show_bios_limit(struct cpufreq_policy *policy, char *buf)
        return sprintf(buf, "%u\n", policy->cpuinfo.max_freq);
 }
 
-#define define_one_ro(_name) \
-static struct freq_attr _name = \
-__ATTR(_name, 0444, show_##_name, NULL)
-
-#define define_one_ro0400(_name) \
-static struct freq_attr _name = \
-__ATTR(_name, 0400, show_##_name, NULL)
-
-#define define_one_rw(_name) \
-static struct freq_attr _name = \
-__ATTR(_name, 0644, show_##_name, store_##_name)
-
-define_one_ro0400(cpuinfo_cur_freq);
-define_one_ro(cpuinfo_min_freq);
-define_one_ro(cpuinfo_max_freq);
-define_one_ro(cpuinfo_transition_latency);
-define_one_ro(scaling_available_governors);
-define_one_ro(scaling_driver);
-define_one_ro(scaling_cur_freq);
-define_one_ro(bios_limit);
-define_one_ro(related_cpus);
-define_one_ro(affected_cpus);
-define_one_rw(scaling_min_freq);
-define_one_rw(scaling_max_freq);
-define_one_rw(scaling_governor);
-define_one_rw(scaling_setspeed);
+cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400);
+cpufreq_freq_attr_ro(cpuinfo_min_freq);
+cpufreq_freq_attr_ro(cpuinfo_max_freq);
+cpufreq_freq_attr_ro(cpuinfo_transition_latency);
+cpufreq_freq_attr_ro(scaling_available_governors);
+cpufreq_freq_attr_ro(scaling_driver);
+cpufreq_freq_attr_ro(scaling_cur_freq);
+cpufreq_freq_attr_ro(bios_limit);
+cpufreq_freq_attr_ro(related_cpus);
+cpufreq_freq_attr_ro(affected_cpus);
+cpufreq_freq_attr_rw(scaling_min_freq);
+cpufreq_freq_attr_rw(scaling_max_freq);
+cpufreq_freq_attr_rw(scaling_governor);
+cpufreq_freq_attr_rw(scaling_setspeed);
 
 static struct attribute *default_attrs[] = {
        &cpuinfo_min_freq.attr,
index 3a14787..526bfbf 100644 (file)
@@ -178,12 +178,8 @@ static ssize_t show_sampling_rate_min(struct kobject *kobj,
        return sprintf(buf, "%u\n", min_sampling_rate);
 }
 
-#define define_one_ro(_name)           \
-static struct global_attr _name =      \
-__ATTR(_name, 0444, show_##_name, NULL)
-
-define_one_ro(sampling_rate_max);
-define_one_ro(sampling_rate_min);
+define_one_global_ro(sampling_rate_max);
+define_one_global_ro(sampling_rate_min);
 
 /* cpufreq_conservative Governor Tunables */
 #define show_one(file_name, object)                                    \
@@ -221,12 +217,8 @@ show_one_old(freq_step);
 show_one_old(sampling_rate_min);
 show_one_old(sampling_rate_max);
 
-#define define_one_ro_old(object, _name)       \
-static struct freq_attr object =               \
-__ATTR(_name, 0444, show_##_name##_old, NULL)
-
-define_one_ro_old(sampling_rate_min_old, sampling_rate_min);
-define_one_ro_old(sampling_rate_max_old, sampling_rate_max);
+cpufreq_freq_attr_ro_old(sampling_rate_min);
+cpufreq_freq_attr_ro_old(sampling_rate_max);
 
 /*** delete after deprecation time ***/
 
@@ -364,16 +356,12 @@ static ssize_t store_freq_step(struct kobject *a, struct attribute *b,
        return count;
 }
 
-#define define_one_rw(_name) \
-static struct global_attr _name = \
-__ATTR(_name, 0644, show_##_name, store_##_name)
-
-define_one_rw(sampling_rate);
-define_one_rw(sampling_down_factor);
-define_one_rw(up_threshold);
-define_one_rw(down_threshold);
-define_one_rw(ignore_nice_load);
-define_one_rw(freq_step);
+define_one_global_rw(sampling_rate);
+define_one_global_rw(sampling_down_factor);
+define_one_global_rw(up_threshold);
+define_one_global_rw(down_threshold);
+define_one_global_rw(ignore_nice_load);
+define_one_global_rw(freq_step);
 
 static struct attribute *dbs_attributes[] = {
        &sampling_rate_max.attr,
@@ -409,16 +397,12 @@ write_one_old(down_threshold);
 write_one_old(ignore_nice_load);
 write_one_old(freq_step);
 
-#define define_one_rw_old(object, _name)       \
-static struct freq_attr object =               \
-__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
-
-define_one_rw_old(sampling_rate_old, sampling_rate);
-define_one_rw_old(sampling_down_factor_old, sampling_down_factor);
-define_one_rw_old(up_threshold_old, up_threshold);
-define_one_rw_old(down_threshold_old, down_threshold);
-define_one_rw_old(ignore_nice_load_old, ignore_nice_load);
-define_one_rw_old(freq_step_old, freq_step);
+cpufreq_freq_attr_rw_old(sampling_rate);
+cpufreq_freq_attr_rw_old(sampling_down_factor);
+cpufreq_freq_attr_rw_old(up_threshold);
+cpufreq_freq_attr_rw_old(down_threshold);
+cpufreq_freq_attr_rw_old(ignore_nice_load);
+cpufreq_freq_attr_rw_old(freq_step);
 
 static struct attribute *dbs_attributes_old[] = {
        &sampling_rate_max_old.attr,
index bd444dc..e131421 100644 (file)
@@ -73,6 +73,7 @@ enum {DBS_NORMAL_SAMPLE, DBS_SUB_SAMPLE};
 
 struct cpu_dbs_info_s {
        cputime64_t prev_cpu_idle;
+       cputime64_t prev_cpu_iowait;
        cputime64_t prev_cpu_wall;
        cputime64_t prev_cpu_nice;
        struct cpufreq_policy *cur_policy;
@@ -108,6 +109,7 @@ static struct dbs_tuners {
        unsigned int down_differential;
        unsigned int ignore_nice;
        unsigned int powersave_bias;
+       unsigned int io_is_busy;
 } dbs_tuners_ins = {
        .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
        .down_differential = DEF_FREQUENCY_DOWN_DIFFERENTIAL,
@@ -148,6 +150,16 @@ static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
        return idle_time;
 }
 
+static inline cputime64_t get_cpu_iowait_time(unsigned int cpu, cputime64_t *wall)
+{
+       u64 iowait_time = get_cpu_iowait_time_us(cpu, wall);
+
+       if (iowait_time == -1ULL)
+               return 0;
+
+       return iowait_time;
+}
+
 /*
  * Find right freq to be set now with powersave_bias on.
  * Returns the freq_hi to be used right now and will set freq_hi_jiffies,
@@ -234,12 +246,8 @@ static ssize_t show_sampling_rate_min(struct kobject *kobj,
        return sprintf(buf, "%u\n", min_sampling_rate);
 }
 
-#define define_one_ro(_name)           \
-static struct global_attr _name =      \
-__ATTR(_name, 0444, show_##_name, NULL)
-
-define_one_ro(sampling_rate_max);
-define_one_ro(sampling_rate_min);
+define_one_global_ro(sampling_rate_max);
+define_one_global_ro(sampling_rate_min);
 
 /* cpufreq_ondemand Governor Tunables */
 #define show_one(file_name, object)                                    \
@@ -249,6 +257,7 @@ static ssize_t show_##file_name                                             \
        return sprintf(buf, "%u\n", dbs_tuners_ins.object);             \
 }
 show_one(sampling_rate, sampling_rate);
+show_one(io_is_busy, io_is_busy);
 show_one(up_threshold, up_threshold);
 show_one(ignore_nice_load, ignore_nice);
 show_one(powersave_bias, powersave_bias);
@@ -274,12 +283,8 @@ show_one_old(powersave_bias);
 show_one_old(sampling_rate_min);
 show_one_old(sampling_rate_max);
 
-#define define_one_ro_old(object, _name)       \
-static struct freq_attr object =               \
-__ATTR(_name, 0444, show_##_name##_old, NULL)
-
-define_one_ro_old(sampling_rate_min_old, sampling_rate_min);
-define_one_ro_old(sampling_rate_max_old, sampling_rate_max);
+cpufreq_freq_attr_ro_old(sampling_rate_min);
+cpufreq_freq_attr_ro_old(sampling_rate_max);
 
 /*** delete after deprecation time ***/
 
@@ -299,6 +304,23 @@ static ssize_t store_sampling_rate(struct kobject *a, struct attribute *b,
        return count;
 }
 
+static ssize_t store_io_is_busy(struct kobject *a, struct attribute *b,
+                                  const char *buf, size_t count)
+{
+       unsigned int input;
+       int ret;
+
+       ret = sscanf(buf, "%u", &input);
+       if (ret != 1)
+               return -EINVAL;
+
+       mutex_lock(&dbs_mutex);
+       dbs_tuners_ins.io_is_busy = !!input;
+       mutex_unlock(&dbs_mutex);
+
+       return count;
+}
+
 static ssize_t store_up_threshold(struct kobject *a, struct attribute *b,
                                  const char *buf, size_t count)
 {
@@ -376,14 +398,11 @@ static ssize_t store_powersave_bias(struct kobject *a, struct attribute *b,
        return count;
 }
 
-#define define_one_rw(_name) \
-static struct global_attr _name = \
-__ATTR(_name, 0644, show_##_name, store_##_name)
-
-define_one_rw(sampling_rate);
-define_one_rw(up_threshold);
-define_one_rw(ignore_nice_load);
-define_one_rw(powersave_bias);
+define_one_global_rw(sampling_rate);
+define_one_global_rw(io_is_busy);
+define_one_global_rw(up_threshold);
+define_one_global_rw(ignore_nice_load);
+define_one_global_rw(powersave_bias);
 
 static struct attribute *dbs_attributes[] = {
        &sampling_rate_max.attr,
@@ -392,6 +411,7 @@ static struct attribute *dbs_attributes[] = {
        &up_threshold.attr,
        &ignore_nice_load.attr,
        &powersave_bias.attr,
+       &io_is_busy.attr,
        NULL
 };
 
@@ -415,14 +435,10 @@ write_one_old(up_threshold);
 write_one_old(ignore_nice_load);
 write_one_old(powersave_bias);
 
-#define define_one_rw_old(object, _name)       \
-static struct freq_attr object =               \
-__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
-
-define_one_rw_old(sampling_rate_old, sampling_rate);
-define_one_rw_old(up_threshold_old, up_threshold);
-define_one_rw_old(ignore_nice_load_old, ignore_nice_load);
-define_one_rw_old(powersave_bias_old, powersave_bias);
+cpufreq_freq_attr_rw_old(sampling_rate);
+cpufreq_freq_attr_rw_old(up_threshold);
+cpufreq_freq_attr_rw_old(ignore_nice_load);
+cpufreq_freq_attr_rw_old(powersave_bias);
 
 static struct attribute *dbs_attributes_old[] = {
        &sampling_rate_max_old.attr,
@@ -470,14 +486,15 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
 
        for_each_cpu(j, policy->cpus) {
                struct cpu_dbs_info_s *j_dbs_info;
-               cputime64_t cur_wall_time, cur_idle_time;
-               unsigned int idle_time, wall_time;
+               cputime64_t cur_wall_time, cur_idle_time, cur_iowait_time;
+               unsigned int idle_time, wall_time, iowait_time;
                unsigned int load, load_freq;
                int freq_avg;
 
                j_dbs_info = &per_cpu(od_cpu_dbs_info, j);
 
                cur_idle_time = get_cpu_idle_time(j, &cur_wall_time);
+               cur_iowait_time = get_cpu_iowait_time(j, &cur_wall_time);
 
                wall_time = (unsigned int) cputime64_sub(cur_wall_time,
                                j_dbs_info->prev_cpu_wall);
@@ -487,6 +504,10 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
                                j_dbs_info->prev_cpu_idle);
                j_dbs_info->prev_cpu_idle = cur_idle_time;
 
+               iowait_time = (unsigned int) cputime64_sub(cur_iowait_time,
+                               j_dbs_info->prev_cpu_iowait);
+               j_dbs_info->prev_cpu_iowait = cur_iowait_time;
+
                if (dbs_tuners_ins.ignore_nice) {
                        cputime64_t cur_nice;
                        unsigned long cur_nice_jiffies;
@@ -504,6 +525,16 @@ static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
                        idle_time += jiffies_to_usecs(cur_nice_jiffies);
                }
 
+               /*
+                * For the purpose of ondemand, waiting for disk IO is an
+                * indication that you're performance critical, and not that
+                * the system is actually idle. So subtract the iowait time
+                * from the cpu idle time.
+                */
+
+               if (dbs_tuners_ins.io_is_busy && idle_time >= iowait_time)
+                       idle_time -= iowait_time;
+
                if (unlikely(!wall_time || wall_time < idle_time))
                        continue;
 
@@ -617,6 +648,29 @@ static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
        cancel_delayed_work_sync(&dbs_info->work);
 }
 
+/*
+ * Not all CPUs want IO time to be accounted as busy; this dependson how
+ * efficient idling at a higher frequency/voltage is.
+ * Pavel Machek says this is not so for various generations of AMD and old
+ * Intel systems.
+ * Mike Chan (androidlcom) calis this is also not true for ARM.
+ * Because of this, whitelist specific known (series) of CPUs by default, and
+ * leave all others up to the user.
+ */
+static int should_io_be_busy(void)
+{
+#if defined(CONFIG_X86)
+       /*
+        * For Intel, Core 2 (model 15) andl later have an efficient idle.
+        */
+       if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
+           boot_cpu_data.x86 == 6 &&
+           boot_cpu_data.x86_model >= 15)
+               return 1;
+#endif
+       return 0;
+}
+
 static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                                   unsigned int event)
 {
@@ -679,6 +733,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
                        dbs_tuners_ins.sampling_rate =
                                max(min_sampling_rate,
                                    latency * LATENCY_MULTIPLIER);
+                       dbs_tuners_ins.io_is_busy = should_io_be_busy();
                }
                mutex_unlock(&dbs_mutex);
 
index 1c1ceb4..12c9890 100644 (file)
@@ -67,7 +67,7 @@ static int ladder_select_state(struct cpuidle_device *dev)
        struct ladder_device *ldev = &__get_cpu_var(ladder_devices);
        struct ladder_device_state *last_state;
        int last_residency, last_idx = ldev->last_state_idx;
-       int latency_req = pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY);
+       int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
 
        /* Special case when user has set very strict latency requirement */
        if (unlikely(latency_req == 0)) {
index f8e57c6..b81ad9c 100644 (file)
@@ -182,7 +182,7 @@ static u64 div_round64(u64 dividend, u32 divisor)
 static int menu_select(struct cpuidle_device *dev)
 {
        struct menu_device *data = &__get_cpu_var(menu_devices);
-       int latency_req = pm_qos_requirement(PM_QOS_CPU_DMA_LATENCY);
+       int latency_req = pm_qos_request(PM_QOS_CPU_DMA_LATENCY);
        int i;
        int multiplier;
 
index 6f25a20..323afef 100644 (file)
@@ -26,8 +26,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
-
-#include <asm/dmaengine.h>
+#include <linux/sh_dma.h>
 
 #include "shdma.h"
 
@@ -45,7 +44,7 @@ enum sh_dmae_desc_status {
 #define LOG2_DEFAULT_XFER_SIZE 2
 
 /* A bitmask with bits enough for enum sh_dmae_slave_chan_id */
-static unsigned long sh_dmae_slave_used[BITS_TO_LONGS(SHDMA_SLAVE_NUMBER)];
+static unsigned long sh_dmae_slave_used[BITS_TO_LONGS(SH_DMA_SLAVE_NUMBER)];
 
 static void sh_dmae_chan_ld_cleanup(struct sh_dmae_chan *sh_chan, bool all);
 
@@ -190,7 +189,7 @@ static int dmae_set_dmars(struct sh_dmae_chan *sh_chan, u16 val)
        struct sh_dmae_device *shdev = container_of(sh_chan->common.device,
                                                struct sh_dmae_device, common);
        struct sh_dmae_pdata *pdata = shdev->pdata;
-       struct sh_dmae_channel *chan_pdata = &pdata->channel[sh_chan->id];
+       const struct sh_dmae_channel *chan_pdata = &pdata->channel[sh_chan->id];
        u16 __iomem *addr = shdev->dmars + chan_pdata->dmars / sizeof(u16);
        int shift = chan_pdata->dmars_bit;
 
@@ -266,8 +265,8 @@ static struct sh_desc *sh_dmae_get_desc(struct sh_dmae_chan *sh_chan)
        return NULL;
 }
 
-static struct sh_dmae_slave_config *sh_dmae_find_slave(
-       struct sh_dmae_chan *sh_chan, enum sh_dmae_slave_chan_id slave_id)
+static const struct sh_dmae_slave_config *sh_dmae_find_slave(
+       struct sh_dmae_chan *sh_chan, struct sh_dmae_slave *param)
 {
        struct dma_device *dma_dev = sh_chan->common.device;
        struct sh_dmae_device *shdev = container_of(dma_dev,
@@ -275,11 +274,11 @@ static struct sh_dmae_slave_config *sh_dmae_find_slave(
        struct sh_dmae_pdata *pdata = shdev->pdata;
        int i;
 
-       if ((unsigned)slave_id >= SHDMA_SLAVE_NUMBER)
+       if (param->slave_id >= SH_DMA_SLAVE_NUMBER)
                return NULL;
 
        for (i = 0; i < pdata->slave_num; i++)
-               if (pdata->slave[i].slave_id == slave_id)
+               if (pdata->slave[i].slave_id == param->slave_id)
                        return pdata->slave + i;
 
        return NULL;
@@ -299,9 +298,9 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
         * never runs concurrently with itself or free_chan_resources.
         */
        if (param) {
-               struct sh_dmae_slave_config *cfg;
+               const struct sh_dmae_slave_config *cfg;
 
-               cfg = sh_dmae_find_slave(sh_chan, param->slave_id);
+               cfg = sh_dmae_find_slave(sh_chan, param);
                if (!cfg) {
                        ret = -EINVAL;
                        goto efindslave;
@@ -574,12 +573,14 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg(
 {
        struct sh_dmae_slave *param;
        struct sh_dmae_chan *sh_chan;
+       dma_addr_t slave_addr;
 
        if (!chan)
                return NULL;
 
        sh_chan = to_sh_chan(chan);
        param = chan->private;
+       slave_addr = param->config->addr;
 
        /* Someone calling slave DMA on a public channel? */
        if (!param || !sg_len) {
@@ -592,7 +593,7 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_slave_sg(
         * if (param != NULL), this is a successfully requested slave channel,
         * therefore param->config != NULL too.
         */
-       return sh_dmae_prep_sg(sh_chan, sgl, sg_len, &param->config->addr,
+       return sh_dmae_prep_sg(sh_chan, sgl, sg_len, &slave_addr,
                               direction, flags);
 }
 
@@ -873,7 +874,7 @@ static int __devinit sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
                                        int irq, unsigned long flags)
 {
        int err;
-       struct sh_dmae_channel *chan_pdata = &shdev->pdata->channel[id];
+       const struct sh_dmae_channel *chan_pdata = &shdev->pdata->channel[id];
        struct platform_device *pdev = to_platform_device(shdev->common.dev);
        struct sh_dmae_chan *new_sh_chan;
 
index 153609a..4021275 100644 (file)
@@ -17,8 +17,8 @@
 #include <linux/interrupt.h>
 #include <linux/list.h>
 
-#include <asm/dmaengine.h>
-
+#define SH_DMAC_MAX_CHANNELS 6
+#define SH_DMA_SLAVE_NUMBER 256
 #define SH_DMA_TCR_MAX 0x00FFFFFF      /* 16MB */
 
 struct device;
index 94b16e0..a3b083a 100644 (file)
@@ -1351,7 +1351,7 @@ static void bus_reset_tasklet(unsigned long data)
         * was set up before this reset, the old one is now no longer
         * in use and we can free it. Update the config rom pointers
         * to point to the current config rom and clear the
-        * next_config_rom pointer so a new udpate can take place.
+        * next_config_rom pointer so a new update can take place.
         */
 
        if (ohci->next_config_rom != NULL) {
index 7607cc6..2ac9a16 100644 (file)
@@ -81,6 +81,18 @@ static void wm8994_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
        wm8994_set_bits(wm8994, WM8994_GPIO_1 + offset, WM8994_GPN_LVL, value);
 }
 
+static int wm8994_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
+{
+       struct wm8994_gpio *wm8994_gpio = to_wm8994_gpio(chip);
+       struct wm8994 *wm8994 = wm8994_gpio->wm8994;
+
+       if (!wm8994->irq_base)
+               return -EINVAL;
+
+       return wm8994->irq_base + offset;
+}
+
+
 #ifdef CONFIG_DEBUG_FS
 static void wm8994_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip)
 {
index f7ba82e..2092e7b 100644 (file)
@@ -961,7 +961,7 @@ int drm_addbufs_pci(struct drm_device * dev, struct drm_buf_desc * request)
                dma->buflist[i + dma->buf_count] = &entry->buflist[i];
        }
 
-       /* No allocations failed, so now we can replace the orginal pagelist
+       /* No allocations failed, so now we can replace the original pagelist
         * with the new one.
         */
        if (dma->page_count) {
index c7502b6..f27e370 100644 (file)
@@ -905,9 +905,9 @@ intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
 
        memset(best_clock, 0, sizeof(*best_clock));
        max_n = limit->n.max;
-       /* based on hardware requriment prefer smaller n to precision */
+       /* based on hardware requirement, prefer smaller n to precision */
        for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
-               /* based on hardware requirment prefere larger m1,m2 */
+               /* based on hardware requirement, prefere larger m1,m2 */
                for (clock.m1 = limit->m1.max;
                     clock.m1 >= limit->m1.min; clock.m1--) {
                        for (clock.m2 = limit->m2.max;
index 27e2c71..5319d9e 100644 (file)
@@ -3780,7 +3780,7 @@ typedef struct _ATOM_ASIC_SS_ASSIGNMENT
        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.
+//Define ucClockIndication, SW uses the IDs below to search if the SS is required/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
@@ -5895,7 +5895,7 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO
       UCHAR  ucPadding;                   // For proper alignment and size.
       USHORT usVDDC;                      // For the 780, use: None, Low, High, Variable
       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.
+      UCHAR  ucMinHTLinkWidth;            // From SBIOS - {2, 4, 8, 16}. Effective only if CDLW enabled. Minimum down stream width could be bigger as display BW requirement.
       USHORT usHTLinkFreq;                // See definition ATOM_PPLIB_RS780_HTLINKFREQ_xxx or in MHz(>=200).
       ULONG  ulFlags; 
 } ATOM_PPLIB_RS780_CLOCK_INFO;
index 9c6170c..87ab056 100644 (file)
@@ -564,7 +564,7 @@ config I2C_STU300
 
 config I2C_VERSATILE
        tristate "ARM Versatile/Realview I2C bus support"
-       depends on ARCH_VERSATILE || ARCH_REALVIEW
+       depends on ARCH_VERSATILE || ARCH_REALVIEW || ARCH_VEXPRESS
        select I2C_ALGOBIT
        help
          Say yes if you want to support the I2C serial bus on ARMs Versatile
index f1e14dd..fb26e5c 100644 (file)
@@ -25,8 +25,6 @@
 #include <asm/portmux.h>
 #include <asm/irq.h>
 
-#define POLL_TIMEOUT       (2 * HZ)
-
 /* SMBus mode*/
 #define TWI_I2C_MODE_STANDARD          1
 #define TWI_I2C_MODE_STANDARDSUB       2
@@ -44,8 +42,6 @@ struct bfin_twi_iface {
        int                     cur_mode;
        int                     manual_stop;
        int                     result;
-       int                     timeout_count;
-       struct timer_list       timeout_timer;
        struct i2c_adapter      adap;
        struct completion       complete;
        struct i2c_msg          *pmsg;
@@ -85,14 +81,15 @@ static const u16 pin_req[2][3] = {
        {P_TWI1_SCL, P_TWI1_SDA, 0},
 };
 
-static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
+static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface,
+                                       unsigned short twi_int_status)
 {
-       unsigned short twi_int_status = read_INT_STAT(iface);
        unsigned short mast_stat = read_MASTER_STAT(iface);
 
        if (twi_int_status & XMTSERV) {
                /* Transmit next data */
                if (iface->writeNum > 0) {
+                       SSYNC();
                        write_XMT_DATA8(iface, *(iface->transPtr++));
                        iface->writeNum--;
                }
@@ -114,10 +111,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                                write_MASTER_CTL(iface,
                                        (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
                }
-               SSYNC();
-               /* Clear status */
-               write_INT_STAT(iface, XMTSERV);
-               SSYNC();
        }
        if (twi_int_status & RCVSERV) {
                if (iface->readNum > 0) {
@@ -139,7 +132,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                } else if (iface->manual_stop) {
                        write_MASTER_CTL(iface,
                                read_MASTER_CTL(iface) | STOP);
-                       SSYNC();
                } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
                           iface->cur_msg + 1 < iface->msg_num) {
                        if (iface->pmsg[iface->cur_msg + 1].flags & I2C_M_RD)
@@ -148,44 +140,37 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                        else
                                write_MASTER_CTL(iface,
                                        (read_MASTER_CTL(iface) | RSTART) & ~MDIR);
-                       SSYNC();
                }
-               /* Clear interrupt source */
-               write_INT_STAT(iface, RCVSERV);
-               SSYNC();
        }
        if (twi_int_status & MERR) {
-               write_INT_STAT(iface, MERR);
                write_INT_MASK(iface, 0);
                write_MASTER_STAT(iface, 0x3e);
                write_MASTER_CTL(iface, 0);
-               SSYNC();
                iface->result = -EIO;
-               /* if both err and complete int stats are set, return proper
-                * results.
+
+               if (mast_stat & LOSTARB)
+                       dev_dbg(&iface->adap.dev, "Lost Arbitration\n");
+               if (mast_stat & ANAK)
+                       dev_dbg(&iface->adap.dev, "Address Not Acknowledged\n");
+               if (mast_stat & DNAK)
+                       dev_dbg(&iface->adap.dev, "Data Not Acknowledged\n");
+               if (mast_stat & BUFRDERR)
+                       dev_dbg(&iface->adap.dev, "Buffer Read Error\n");
+               if (mast_stat & BUFWRERR)
+                       dev_dbg(&iface->adap.dev, "Buffer Write Error\n");
+
+               /* If it is a quick transfer, only address without data,
+                * not an err, return 1.
                 */
-               if (twi_int_status & MCOMP) {
-                       write_INT_STAT(iface, MCOMP);
-                       write_INT_MASK(iface, 0);
-                       write_MASTER_CTL(iface, 0);
-                       SSYNC();
-                       /* If it is a quick transfer, only address bug no data,
-                        * not an err, return 1.
-                        */
-                       if (iface->writeNum == 0 && (mast_stat & BUFRDERR))
-                               iface->result = 1;
-                       /* If address not acknowledged return -1,
-                        * else return 0.
-                        */
-                       else if (!(mast_stat & ANAK))
-                               iface->result = 0;
-               }
+               if (iface->cur_mode == TWI_I2C_MODE_STANDARD &&
+                       iface->transPtr == NULL &&
+                       (twi_int_status & MCOMP) && (mast_stat & DNAK))
+                       iface->result = 1;
+
                complete(&iface->complete);
                return;
        }
        if (twi_int_status & MCOMP) {
-               write_INT_STAT(iface, MCOMP);
-               SSYNC();
                if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
                        if (iface->readNum == 0) {
                                /* set the read number to 1 and ask for manual
@@ -207,7 +192,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                        /* remove restart bit and enable master receive */
                        write_MASTER_CTL(iface,
                                read_MASTER_CTL(iface) & ~RSTART);
-                       SSYNC();
                } else if (iface->cur_mode == TWI_I2C_MODE_REPEAT &&
                                iface->cur_msg+1 < iface->msg_num) {
                        iface->cur_msg++;
@@ -226,7 +210,6 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                                        write_XMT_DATA8(iface,
                                                *(iface->transPtr++));
                                        iface->writeNum--;
-                                       SSYNC();
                                }
                        }
 
@@ -244,15 +227,13 @@ static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
                        /* remove restart bit and enable master receive */
                        write_MASTER_CTL(iface,
                                read_MASTER_CTL(iface) & ~RSTART);
-                       SSYNC();
                } else {
                        iface->result = 1;
                        write_INT_MASK(iface, 0);
                        write_MASTER_CTL(iface, 0);
-                       SSYNC();
-                       complete(&iface->complete);
                }
        }
+       complete(&iface->complete);
 }
 
 /* Interrupt handler */
@@ -260,38 +241,26 @@ static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
 {
        struct bfin_twi_iface *iface = dev_id;
        unsigned long flags;
+       unsigned short twi_int_status;
 
        spin_lock_irqsave(&iface->lock, flags);
-       del_timer(&iface->timeout_timer);
-       bfin_twi_handle_interrupt(iface);
-       spin_unlock_irqrestore(&iface->lock, flags);
-       return IRQ_HANDLED;
-}
-
-static void bfin_twi_timeout(unsigned long data)
-{
-       struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data;
-       unsigned long flags;
-
-       spin_lock_irqsave(&iface->lock, flags);
-       bfin_twi_handle_interrupt(iface);
-       if (iface->result == 0) {
-               iface->timeout_count--;
-               if (iface->timeout_count > 0) {
-                       iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
-                       add_timer(&iface->timeout_timer);
-               } else {
-                       iface->result = -1;
-                       complete(&iface->complete);
-               }
+       while (1) {
+               twi_int_status = read_INT_STAT(iface);
+               if (!twi_int_status)
+                       break;
+               /* Clear interrupt status */
+               write_INT_STAT(iface, twi_int_status);
+               bfin_twi_handle_interrupt(iface, twi_int_status);
+               SSYNC();
        }
        spin_unlock_irqrestore(&iface->lock, flags);
+       return IRQ_HANDLED;
 }
 
 /*
- * Generic i2c master transfer entrypoint
+ * One i2c master transfer
  */
-static int bfin_twi_master_xfer(struct i2c_adapter *adap,
+static int bfin_twi_do_master_xfer(struct i2c_adapter *adap,
                                struct i2c_msg *msgs, int num)
 {
        struct bfin_twi_iface *iface = adap->algo_data;
@@ -319,7 +288,6 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap,
        iface->transPtr = pmsg->buf;
        iface->writeNum = iface->readNum = pmsg->len;
        iface->result = 0;
-       iface->timeout_count = 10;
        init_completion(&(iface->complete));
        /* Set Transmit device address */
        write_MASTER_ADDR(iface, pmsg->addr);
@@ -358,30 +326,41 @@ static int bfin_twi_master_xfer(struct i2c_adapter *adap,
                iface->manual_stop = 1;
        }
 
-       iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
-       add_timer(&iface->timeout_timer);
-
        /* Master enable */
        write_MASTER_CTL(iface, read_MASTER_CTL(iface) | MEN |
                ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
                ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
        SSYNC();
 
-       wait_for_completion(&iface->complete);
-
-       rc = iface->result;
+       while (!iface->result) {
+               if (!wait_for_completion_timeout(&iface->complete,
+                       adap->timeout)) {
+                       iface->result = -1;
+                       dev_err(&adap->dev, "master transfer timeout\n");
+               }
+       }
 
-       if (rc == 1)
-               return num;
+       if (iface->result == 1)
+               rc = iface->cur_msg + 1;
        else
-               return rc;
+               rc = iface->result;
+
+       return rc;
 }
 
 /*
- * SMBus type transfer entrypoint
+ * Generic i2c master transfer entrypoint
  */
+static int bfin_twi_master_xfer(struct i2c_adapter *adap,
+                               struct i2c_msg *msgs, int num)
+{
+       return bfin_twi_do_master_xfer(adap, msgs, num);
+}
 
-int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
+/*
+ * One I2C SMBus transfer
+ */
+int bfin_twi_do_smbus_xfer(struct i2c_adapter *adap, u16 addr,
                        unsigned short flags, char read_write,
                        u8 command, int size, union i2c_smbus_data *data)
 {
@@ -469,7 +448,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
        iface->manual_stop = 0;
        iface->read_write = read_write;
        iface->command = command;
-       iface->timeout_count = 10;
        init_completion(&(iface->complete));
 
        /* FIFO Initiation. Data in FIFO should be discarded before
@@ -486,9 +464,6 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
        write_MASTER_ADDR(iface, addr);
        SSYNC();
 
-       iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
-       add_timer(&iface->timeout_timer);
-
        switch (iface->cur_mode) {
        case TWI_I2C_MODE_STANDARDSUB:
                write_XMT_DATA8(iface, iface->command);
@@ -550,10 +525,8 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
                                else if (iface->readNum > 255) {
                                        write_MASTER_CTL(iface, 0xff << 6);
                                        iface->manual_stop = 1;
-                               } else {
-                                       del_timer(&iface->timeout_timer);
+                               } else
                                        break;
-                               }
                        }
                }
                write_INT_MASK(iface, MCOMP | MERR |
@@ -569,13 +542,30 @@ int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
        }
        SSYNC();
 
-       wait_for_completion(&iface->complete);
+       while (!iface->result) {
+               if (!wait_for_completion_timeout(&iface->complete,
+                       adap->timeout)) {
+                       iface->result = -1;
+                       dev_err(&adap->dev, "smbus transfer timeout\n");
+               }
+       }
 
        rc = (iface->result >= 0) ? 0 : -1;
 
        return rc;
 }
 
+/*
+ * Generic I2C SMBus transfer entrypoint
+ */
+int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
+                       unsigned short flags, char read_write,
+                       u8 command, int size, union i2c_smbus_data *data)
+{
+       return bfin_twi_do_smbus_xfer(adap, addr, flags,
+                       read_write, command, size, data);
+}
+
 /*
  * Return what the adapter supports
  */
@@ -667,10 +657,6 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
                goto out_error_no_irq;
        }
 
-       init_timer(&(iface->timeout_timer));
-       iface->timeout_timer.function = bfin_twi_timeout;
-       iface->timeout_timer.data = (unsigned long)iface;
-
        p_adap = &iface->adap;
        p_adap->nr = pdev->id;
        strlcpy(p_adap->name, pdev->name, sizeof(p_adap->name));
@@ -678,6 +664,8 @@ static int i2c_bfin_twi_probe(struct platform_device *pdev)
        p_adap->algo_data = iface;
        p_adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
        p_adap->dev.parent = &pdev->dev;
+       p_adap->timeout = 5 * HZ;
+       p_adap->retries = 3;
 
        rc = peripheral_request_list(pin_req[pdev->id], "i2c-bfin-twi");
        if (rc) {
index 9c2e100..16948db 100644 (file)
@@ -441,7 +441,7 @@ static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
        init_waitqueue_head(&cpm->i2c_wait);
 
        cpm->irq = of_irq_to_resource(ofdev->node, 0, NULL);
-       if (cpm->irq == NO_IRQ)
+       if (!cpm->irq)
                return -EINVAL;
 
        /* Install interrupt handler. */
index ce87a90..3df1bc8 100644 (file)
@@ -282,7 +282,6 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
                                  union i2c_smbus_data *data)
 {
        struct highlander_i2c_dev *dev = i2c_get_adapdata(adap);
-       int read = read_write & I2C_SMBUS_READ;
        u16 tmp;
 
        init_completion(&dev->cmd_complete);
@@ -337,11 +336,11 @@ static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
        highlander_i2c_done(dev);
 
        /* Set slave address */
-       iowrite16((addr << 1) | read, dev->base + SMSMADR);
+       iowrite16((addr << 1) | read_write, dev->base + SMSMADR);
 
        highlander_i2c_command(dev, command, dev->buf_len);
 
-       if (read)
+       if (read_write == I2C_SMBUS_READ)
                return highlander_i2c_read(dev);
        else
                return highlander_i2c_write(dev);
index b1bc6e2..2bef534 100644 (file)
@@ -668,12 +668,12 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
        int irq;
 
        if (iic_force_poll)
-               return NO_IRQ;
+               return 0;
 
        irq = irq_of_parse_and_map(np, 0);
-       if (irq == NO_IRQ) {
+       if (!irq) {
                dev_err(&ofdev->dev, "irq_of_parse_and_map failed\n");
-               return NO_IRQ;
+               return 0;
        }
 
        /* Disable interrupts until we finish initialization, assumes
@@ -683,7 +683,7 @@ static int __devinit iic_request_irq(struct of_device *ofdev,
        if (request_irq(irq, iic_handler, 0, "IBM IIC", dev)) {
                dev_err(&ofdev->dev, "request_irq %d failed\n", irq);
                /* Fallback to the polling mode */
-               return NO_IRQ;
+               return 0;
        }
 
        return irq;
@@ -719,7 +719,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
        init_waitqueue_head(&dev->wq);
 
        dev->irq = iic_request_irq(ofdev, dev);
-       if (dev->irq == NO_IRQ)
+       if (!dev->irq)
                dev_warn(&ofdev->dev, "using polling mode\n");
 
        /* Board specific settings */
@@ -766,7 +766,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
        return 0;
 
 error_cleanup:
-       if (dev->irq != NO_IRQ) {
+       if (dev->irq) {
                iic_interrupt_mode(dev, 0);
                free_irq(dev->irq, dev);
        }
@@ -790,7 +790,7 @@ static int __devexit iic_remove(struct of_device *ofdev)
 
        i2c_del_adapter(&dev->adap);
 
-       if (dev->irq != NO_IRQ) {
+       if (dev->irq) {
                iic_interrupt_mode(dev, 0);
                free_irq(dev->irq, dev);
        }
index f1321f7..e86cef3 100644 (file)
@@ -118,7 +118,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
        u32 x;
        int result = 0;
 
-       if (i2c->irq == NO_IRQ) {
+       if (!i2c->irq) {
                while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) {
                        schedule();
                        if (time_after(jiffies, orig_jiffies + timeout)) {
@@ -568,7 +568,7 @@ static int __devinit fsl_i2c_probe(struct of_device *op,
        }
 
        i2c->irq = irq_of_parse_and_map(op->node, 0);
-       if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
+       if (i2c->irq) { /* no i2c->irq implies polling */
                result = request_irq(i2c->irq, mpc_i2c_isr,
                                     IRQF_SHARED, "i2c-mpc", i2c);
                if (result < 0) {
@@ -627,7 +627,7 @@ static int __devexit fsl_i2c_remove(struct of_device *op)
        i2c_del_adapter(&i2c->adap);
        dev_set_drvdata(&op->dev, NULL);
 
-       if (i2c->irq != NO_IRQ)
+       if (i2c->irq)
                free_irq(i2c->irq, i2c);
 
        irq_dispose_mapping(i2c->irq);
index a4f8d33..73de8ad 100644 (file)
@@ -704,7 +704,8 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg)
        case I2C_IT_MTD:
        case I2C_IT_MTDWS:
                if (dev->cli.operation == I2C_READ) {
-                       while (!readl(dev->virtbase + I2C_RISR) & I2C_IT_RXFE) {
+                       while (!(readl(dev->virtbase + I2C_RISR)
+                                & I2C_IT_RXFE)) {
                                if (dev->cli.count == 0)
                                        break;
                                *dev->cli.buffer =
@@ -914,6 +915,7 @@ static int __devinit nmk_i2c_probe(struct platform_device *pdev)
 
 static int __devexit nmk_i2c_remove(struct platform_device *pdev)
 {
+       struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        struct nmk_i2c_dev *dev = platform_get_drvdata(pdev);
 
        i2c_del_adapter(&dev->adap);
@@ -924,6 +926,8 @@ static int __devexit nmk_i2c_remove(struct platform_device *pdev)
        i2c_clr_bit(dev->virtbase + I2C_CR, I2C_CR_PE);
        free_irq(dev->irq, dev);
        iounmap(dev->virtbase);
+       if (res)
+               release_mem_region(res->start, resource_size(res));
        clk_disable(dev->clk);
        clk_put(dev->clk);
        platform_set_drvdata(pdev, NULL);
index 389ac60..7674efb 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/i2c-omap.h>
 
 /* I2C controller revisions */
 #define OMAP_I2C_REV_2                 0x20
 /* I2C controller revisions present on specific hardware */
 #define OMAP_I2C_REV_ON_2430           0x36
 #define OMAP_I2C_REV_ON_3430           0x3C
+#define OMAP_I2C_REV_ON_4430           0x40
 
 /* timeout waiting for the controller to respond */
 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
 
-#define OMAP_I2C_REV_REG               0x00
-#define OMAP_I2C_IE_REG                        0x01
-#define OMAP_I2C_STAT_REG              0x02
-#define OMAP_I2C_IV_REG                        0x03
 /* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */
-#define OMAP_I2C_WE_REG                        0x03
-#define OMAP_I2C_SYSS_REG              0x04
-#define OMAP_I2C_BUF_REG               0x05
-#define OMAP_I2C_CNT_REG               0x06
-#define OMAP_I2C_DATA_REG              0x07
-#define OMAP_I2C_SYSC_REG              0x08
-#define OMAP_I2C_CON_REG               0x09
-#define OMAP_I2C_OA_REG                        0x0a
-#define OMAP_I2C_SA_REG                        0x0b
-#define OMAP_I2C_PSC_REG               0x0c
-#define OMAP_I2C_SCLL_REG              0x0d
-#define OMAP_I2C_SCLH_REG              0x0e
-#define OMAP_I2C_SYSTEST_REG           0x0f
-#define OMAP_I2C_BUFSTAT_REG           0x10
+enum {
+       OMAP_I2C_REV_REG = 0,
+       OMAP_I2C_IE_REG,
+       OMAP_I2C_STAT_REG,
+       OMAP_I2C_IV_REG,
+       OMAP_I2C_WE_REG,
+       OMAP_I2C_SYSS_REG,
+       OMAP_I2C_BUF_REG,
+       OMAP_I2C_CNT_REG,
+       OMAP_I2C_DATA_REG,
+       OMAP_I2C_SYSC_REG,
+       OMAP_I2C_CON_REG,
+       OMAP_I2C_OA_REG,
+       OMAP_I2C_SA_REG,
+       OMAP_I2C_PSC_REG,
+       OMAP_I2C_SCLL_REG,
+       OMAP_I2C_SCLH_REG,
+       OMAP_I2C_SYSTEST_REG,
+       OMAP_I2C_BUFSTAT_REG,
+       OMAP_I2C_REVNB_LO,
+       OMAP_I2C_REVNB_HI,
+       OMAP_I2C_IRQSTATUS_RAW,
+       OMAP_I2C_IRQENABLE_SET,
+       OMAP_I2C_IRQENABLE_CLR,
+};
 
 /* I2C Interrupt Enable Register (OMAP_I2C_IE): */
 #define OMAP_I2C_IE_XDR                (1 << 14)       /* TX Buffer drain int enable */
 #define SYSC_IDLEMODE_SMART            0x2
 #define SYSC_CLOCKACTIVITY_FCLK                0x2
 
+/* Errata definitions */
+#define I2C_OMAP_ERRATA_I207           (1 << 0)
+#define I2C_OMAP3_1P153                        (1 << 1)
 
 struct omap_i2c_dev {
        struct device           *dev;
@@ -167,9 +179,13 @@ struct omap_i2c_dev {
        struct clk              *fclk;          /* Functional clock */
        struct completion       cmd_complete;
        struct resource         *ioarea;
+       u32                     latency;        /* maximum mpu wkup latency */
+       void                    (*set_mpu_wkup_lat)(struct device *dev,
+                                                   long latency);
        u32                     speed;          /* Speed of bus in Khz */
        u16                     cmd_err;
        u8                      *buf;
+       u8                      *regs;
        size_t                  buf_len;
        struct i2c_adapter      adapter;
        u8                      fifo_size;      /* use as flag and value
@@ -186,17 +202,67 @@ struct omap_i2c_dev {
        u16                     bufstate;
        u16                     syscstate;
        u16                     westate;
+       u16                     errata;
+};
+
+const static u8 reg_map[] = {
+       [OMAP_I2C_REV_REG] = 0x00,
+       [OMAP_I2C_IE_REG] = 0x01,
+       [OMAP_I2C_STAT_REG] = 0x02,
+       [OMAP_I2C_IV_REG] = 0x03,
+       [OMAP_I2C_WE_REG] = 0x03,
+       [OMAP_I2C_SYSS_REG] = 0x04,
+       [OMAP_I2C_BUF_REG] = 0x05,
+       [OMAP_I2C_CNT_REG] = 0x06,
+       [OMAP_I2C_DATA_REG] = 0x07,
+       [OMAP_I2C_SYSC_REG] = 0x08,
+       [OMAP_I2C_CON_REG] = 0x09,
+       [OMAP_I2C_OA_REG] = 0x0a,
+       [OMAP_I2C_SA_REG] = 0x0b,
+       [OMAP_I2C_PSC_REG] = 0x0c,
+       [OMAP_I2C_SCLL_REG] = 0x0d,
+       [OMAP_I2C_SCLH_REG] = 0x0e,
+       [OMAP_I2C_SYSTEST_REG] = 0x0f,
+       [OMAP_I2C_BUFSTAT_REG] = 0x10,
+};
+
+const static u8 omap4_reg_map[] = {
+       [OMAP_I2C_REV_REG] = 0x04,
+       [OMAP_I2C_IE_REG] = 0x2c,
+       [OMAP_I2C_STAT_REG] = 0x28,
+       [OMAP_I2C_IV_REG] = 0x34,
+       [OMAP_I2C_WE_REG] = 0x34,
+       [OMAP_I2C_SYSS_REG] = 0x90,
+       [OMAP_I2C_BUF_REG] = 0x94,
+       [OMAP_I2C_CNT_REG] = 0x98,
+       [OMAP_I2C_DATA_REG] = 0x9c,
+       [OMAP_I2C_SYSC_REG] = 0x20,
+       [OMAP_I2C_CON_REG] = 0xa4,
+       [OMAP_I2C_OA_REG] = 0xa8,
+       [OMAP_I2C_SA_REG] = 0xac,
+       [OMAP_I2C_PSC_REG] = 0xb0,
+       [OMAP_I2C_SCLL_REG] = 0xb4,
+       [OMAP_I2C_SCLH_REG] = 0xb8,
+       [OMAP_I2C_SYSTEST_REG] = 0xbC,
+       [OMAP_I2C_BUFSTAT_REG] = 0xc0,
+       [OMAP_I2C_REVNB_LO] = 0x00,
+       [OMAP_I2C_REVNB_HI] = 0x04,
+       [OMAP_I2C_IRQSTATUS_RAW] = 0x24,
+       [OMAP_I2C_IRQENABLE_SET] = 0x2c,
+       [OMAP_I2C_IRQENABLE_CLR] = 0x30,
 };
 
 static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
                                      int reg, u16 val)
 {
-       __raw_writew(val, i2c_dev->base + (reg << i2c_dev->reg_shift));
+       __raw_writew(val, i2c_dev->base +
+                       (i2c_dev->regs[reg] << i2c_dev->reg_shift));
 }
 
 static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
 {
-       return __raw_readw(i2c_dev->base + (reg << i2c_dev->reg_shift));
+       return __raw_readw(i2c_dev->base +
+                               (i2c_dev->regs[reg] << i2c_dev->reg_shift));
 }
 
 static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev)
@@ -265,7 +331,11 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
        WARN_ON(dev->idle);
 
        dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
-       omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
+       if (dev->rev >= OMAP_I2C_REV_ON_4430)
+               omap_i2c_write_reg(dev, OMAP_I2C_IRQENABLE_CLR, 1);
+       else
+               omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
+
        if (dev->rev < OMAP_I2C_REV_2) {
                iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
        } else {
@@ -330,7 +400,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
                         * REVISIT: Some wkup sources might not be needed.
                         */
                        dev->westate = OMAP_I2C_WE_ALL;
-                       omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate);
+                       if (dev->rev < OMAP_I2C_REV_ON_4430)
+                               omap_i2c_write_reg(dev, OMAP_I2C_WE_REG,
+                                                               dev->westate);
                }
        }
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
@@ -357,7 +429,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
                        psc = fclk_rate / 12000000;
        }
 
-       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+       if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
 
                /*
                 * HSI2C controller internal clk rate should be 19.2 Mhz for
@@ -430,6 +502,11 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
        /* Take the I2C module out of reset: */
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
 
+       dev->errata = 0;
+
+       if (cpu_is_omap2430() || cpu_is_omap34xx())
+               dev->errata |= I2C_OMAP_ERRATA_I207;
+
        /* Enable interrupts */
        dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
                        OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
@@ -539,8 +616,12 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
         * REVISIT: We should abort the transfer on signals, but the bus goes
         * into arbitration and we're currently unable to recover from it.
         */
+       if (dev->set_mpu_wkup_lat != NULL)
+               dev->set_mpu_wkup_lat(dev->dev, dev->latency);
        r = wait_for_completion_timeout(&dev->cmd_complete,
                                        OMAP_I2C_TIMEOUT);
+       if (dev->set_mpu_wkup_lat != NULL)
+               dev->set_mpu_wkup_lat(dev->dev, -1);
        dev->buf_len = 0;
        if (r < 0)
                return r;
@@ -623,6 +704,34 @@ omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
        omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
 }
 
+static inline void i2c_omap_errata_i207(struct omap_i2c_dev *dev, u16 stat)
+{
+       /*
+        * I2C Errata(Errata Nos. OMAP2: 1.67, OMAP3: 1.8)
+        * Not applicable for OMAP4.
+        * Under certain rare conditions, RDR could be set again
+        * when the bus is busy, then ignore the interrupt and
+        * clear the interrupt.
+        */
+       if (stat & OMAP_I2C_STAT_RDR) {
+               /* Step 1: If RDR is set, clear it */
+               omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
+
+               /* Step 2: */
+               if (!(omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG)
+                                               & OMAP_I2C_STAT_BB)) {
+
+                       /* Step 3: */
+                       if (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG)
+                                               & OMAP_I2C_STAT_RDR) {
+                               omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
+                               dev_dbg(dev->dev, "RDR when bus is busy.\n");
+                       }
+
+               }
+       }
+}
+
 /* rev1 devices are apparently only on some 15xx */
 #ifdef CONFIG_ARCH_OMAP15XX
 
@@ -684,6 +793,35 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id)
 #define omap_i2c_rev1_isr              NULL
 #endif
 
+/*
+ * OMAP3430 Errata 1.153: When an XRDY/XDR is hit, wait for XUDF before writing
+ * data to DATA_REG. Otherwise some data bytes can be lost while transferring
+ * them from the memory to the I2C interface.
+ */
+static int errata_omap3_1p153(struct omap_i2c_dev *dev, u16 *stat, int *err)
+{
+       unsigned long timeout = 10000;
+
+       while (--timeout && !(*stat & OMAP_I2C_STAT_XUDF)) {
+               if (*stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
+                       omap_i2c_ack_stat(dev, *stat & (OMAP_I2C_STAT_XRDY |
+                                                       OMAP_I2C_STAT_XDR));
+                       *err |= OMAP_I2C_STAT_XUDF;
+                       return -ETIMEDOUT;
+               }
+
+               cpu_relax();
+               *stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
+       }
+
+       if (!timeout) {
+               dev_err(dev->dev, "timeout waiting on XUDF bit\n");
+               return 0;
+       }
+
+       return 0;
+}
+
 static irqreturn_t
 omap_i2c_isr(int this_irq, void *dev_id)
 {
@@ -733,6 +871,10 @@ complete:
                }
                if (stat & (OMAP_I2C_STAT_RRDY | OMAP_I2C_STAT_RDR)) {
                        u8 num_bytes = 1;
+
+                       if (dev->errata & I2C_OMAP_ERRATA_I207)
+                               i2c_omap_errata_i207(dev, stat);
+
                        if (dev->fifo_size) {
                                if (stat & OMAP_I2C_STAT_RRDY)
                                        num_bytes = dev->fifo_size;
@@ -747,9 +889,12 @@ complete:
                                if (dev->buf_len) {
                                        *dev->buf++ = w;
                                        dev->buf_len--;
-                                       /* Data reg from 2430 is 8 bit wide */
-                                       if (!cpu_is_omap2430() &&
-                                                       !cpu_is_omap34xx()) {
+                                       /*
+                                        * Data reg in 2430, omap3 and
+                                        * omap4 is 8 bit wide
+                                        */
+                                       if (cpu_class_is_omap1() ||
+                                                       cpu_is_omap2420()) {
                                                if (dev->buf_len) {
                                                        *dev->buf++ = w >> 8;
                                                        dev->buf_len--;
@@ -787,9 +932,12 @@ complete:
                                if (dev->buf_len) {
                                        w = *dev->buf++;
                                        dev->buf_len--;
-                                       /* Data reg from  2430 is 8 bit wide */
-                                       if (!cpu_is_omap2430() &&
-                                                       !cpu_is_omap34xx()) {
+                                       /*
+                                        * Data reg in 2430, omap3 and
+                                        * omap4 is 8 bit wide
+                                        */
+                                       if (cpu_class_is_omap1() ||
+                                                       cpu_is_omap2420()) {
                                                if (dev->buf_len) {
                                                        w |= *dev->buf++ << 8;
                                                        dev->buf_len--;
@@ -807,25 +955,9 @@ complete:
                                        break;
                                }
 
-                               /*
-                                * OMAP3430 Errata 1.153: When an XRDY/XDR
-                                * is hit, wait for XUDF before writing data
-                                * to DATA_REG. Otherwise some data bytes can
-                                * be lost while transferring them from the
-                                * memory to the I2C interface.
-                                */
-
-                               if (dev->rev <= OMAP_I2C_REV_ON_3430) {
-                                               while (!(stat & OMAP_I2C_STAT_XUDF)) {
-                                                       if (stat & (OMAP_I2C_STAT_NACK | OMAP_I2C_STAT_AL)) {
-                                                               omap_i2c_ack_stat(dev, stat & (OMAP_I2C_STAT_XRDY | OMAP_I2C_STAT_XDR));
-                                                               err |= OMAP_I2C_STAT_XUDF;
-                                                               goto complete;
-                                                       }
-                                                       cpu_relax();
-                                                       stat = omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG);
-                                               }
-                               }
+                               if ((dev->errata & I2C_OMAP3_1P153) &&
+                                   errata_omap3_1p153(dev, &stat, &err))
+                                       goto complete;
 
                                omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
                        }
@@ -857,6 +989,7 @@ omap_i2c_probe(struct platform_device *pdev)
        struct omap_i2c_dev     *dev;
        struct i2c_adapter      *adap;
        struct resource         *mem, *irq, *ioarea;
+       struct omap_i2c_bus_platform_data *pdata = pdev->dev.platform_data;
        irq_handler_t isr;
        int r;
        u32 speed = 0;
@@ -886,10 +1019,13 @@ omap_i2c_probe(struct platform_device *pdev)
                goto err_release_region;
        }
 
-       if (pdev->dev.platform_data != NULL)
-               speed = *(u32 *)pdev->dev.platform_data;
-       else
-               speed = 100;    /* Defualt speed */
+       if (pdata != NULL) {
+               speed = pdata->clkrate;
+               dev->set_mpu_wkup_lat = pdata->set_mpu_wkup_lat;
+       } else {
+               speed = 100;    /* Default speed */
+               dev->set_mpu_wkup_lat = NULL;
+       }
 
        dev->speed = speed;
        dev->idle = 1;
@@ -905,17 +1041,27 @@ omap_i2c_probe(struct platform_device *pdev)
 
        if (cpu_is_omap7xx())
                dev->reg_shift = 1;
+       else if (cpu_is_omap44xx())
+               dev->reg_shift = 0;
        else
                dev->reg_shift = 2;
 
        if ((r = omap_i2c_get_clocks(dev)) != 0)
                goto err_iounmap;
 
+       if (cpu_is_omap44xx())
+               dev->regs = (u8 *) omap4_reg_map;
+       else
+               dev->regs = (u8 *) reg_map;
+
        omap_i2c_unidle(dev);
 
        dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
 
-       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
+       if (dev->rev <= OMAP_I2C_REV_ON_3430)
+               dev->errata |= I2C_OMAP3_1P153;
+
+       if (!(cpu_class_is_omap1() || cpu_is_omap2420())) {
                u16 s;
 
                /* Set up the fifo size - Get total size */
@@ -927,8 +1073,17 @@ omap_i2c_probe(struct platform_device *pdev)
                 * size. This is to ensure that we can handle the status on int
                 * call back latencies.
                 */
-               dev->fifo_size = (dev->fifo_size / 2);
-               dev->b_hw = 1; /* Enable hardware fixes */
+               if (dev->rev >= OMAP_I2C_REV_ON_4430) {
+                       dev->fifo_size = 0;
+                       dev->b_hw = 0; /* Disable hardware fixes */
+               } else {
+                       dev->fifo_size = (dev->fifo_size / 2);
+                       dev->b_hw = 1; /* Enable hardware fixes */
+               }
+               /* calculate wakeup latency constraint for MPU */
+               if (dev->set_mpu_wkup_lat != NULL)
+                       dev->latency = (1000000 * dev->fifo_size) /
+                                      (1000 * speed / 8);
        }
 
        /* reset ASAP, clearing any IRQs */
index 14d249f..fbde6f6 100644 (file)
@@ -209,18 +209,6 @@ static void i2c_pxa_show_state(struct pxa_i2c *i2c, int lno, const char *fname)
 }
 
 #define show_state(i2c) i2c_pxa_show_state(i2c, __LINE__, __func__)
-#else
-#define i2c_debug      0
-
-#define show_state(i2c) do { } while (0)
-#define decode_ISR(val) do { } while (0)
-#define decode_ICR(val) do { } while (0)
-#endif
-
-#define eedbg(lvl, x...) do { if ((lvl) < 1) { printk(KERN_DEBUG "" x); } } while(0)
-
-static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
-static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
 
 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
 {
@@ -236,6 +224,20 @@ static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
        printk("\n");
 }
 
+#else /* ifdef DEBUG */
+
+#define i2c_debug      0
+
+#define show_state(i2c) do { } while (0)
+#define decode_ISR(val) do { } while (0)
+#define decode_ICR(val) do { } while (0)
+#define i2c_pxa_scream_blue_murder(i2c, why) do { } while (0)
+
+#endif /* ifdef DEBUG / else */
+
+static void i2c_pxa_master_complete(struct pxa_i2c *i2c, int ret);
+static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
+
 static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
 {
        return !(readl(_ICR(i2c)) & ICR_SCLE);
index d27072b..ec3256c 100644 (file)
@@ -482,7 +482,8 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c)
 static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
                              struct i2c_msg *msgs, int num)
 {
-       unsigned long timeout;
+       unsigned long iicstat, timeout;
+       int spins = 20;
        int ret;
 
        if (i2c->suspended)
@@ -521,7 +522,21 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
 
        /* ensure the stop has been through the bus */
 
-       msleep(1);
+       dev_dbg(i2c->dev, "waiting for bus idle\n");
+
+       /* first, try busy waiting briefly */
+       do {
+               iicstat = readl(i2c->regs + S3C2410_IICSTAT);
+       } while ((iicstat & S3C2410_IICSTAT_START) && --spins);
+
+       /* if that timed out sleep */
+       if (!spins) {
+               msleep(1);
+               iicstat = readl(i2c->regs + S3C2410_IICSTAT);
+       }
+
+       if (iicstat & S3C2410_IICSTAT_START)
+               dev_warn(i2c->dev, "timeout waiting for bus idle\n");
 
  out:
        return ret;
index c2258a5..7c469a6 100644 (file)
@@ -159,107 +159,131 @@ static void i2c_device_shutdown(struct device *dev)
                driver->shutdown(client);
 }
 
-#ifdef CONFIG_SUSPEND
-static int i2c_device_pm_suspend(struct device *dev)
+#ifdef CONFIG_PM_SLEEP
+static int i2c_legacy_suspend(struct device *dev, pm_message_t mesg)
 {
-       const struct dev_pm_ops *pm;
+       struct i2c_client *client = i2c_verify_client(dev);
+       struct i2c_driver *driver;
 
-       if (!dev->driver)
+       if (!client || !dev->driver)
                return 0;
-       pm = dev->driver->pm;
-       if (!pm || !pm->suspend)
+       driver = to_i2c_driver(dev->driver);
+       if (!driver->suspend)
                return 0;
-       return pm->suspend(dev);
+       return driver->suspend(client, mesg);
 }
 
-static int i2c_device_pm_resume(struct device *dev)
+static int i2c_legacy_resume(struct device *dev)
 {
-       const struct dev_pm_ops *pm;
+       struct i2c_client *client = i2c_verify_client(dev);
+       struct i2c_driver *driver;
 
-       if (!dev->driver)
+       if (!client || !dev->driver)
                return 0;
-       pm = dev->driver->pm;
-       if (!pm || !pm->resume)
+       driver = to_i2c_driver(dev->driver);
+       if (!driver->resume)
                return 0;
-       return pm->resume(dev);
+       return driver->resume(client);
 }
-#else
-#define i2c_device_pm_suspend  NULL
-#define i2c_device_pm_resume   NULL
-#endif
 
-#ifdef CONFIG_PM_RUNTIME
-static int i2c_device_runtime_suspend(struct device *dev)
+static int i2c_device_pm_suspend(struct device *dev)
 {
-       const struct dev_pm_ops *pm;
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-       if (!dev->driver)
-               return 0;
-       pm = dev->driver->pm;
-       if (!pm || !pm->runtime_suspend)
+       if (pm_runtime_suspended(dev))
                return 0;
-       return pm->runtime_suspend(dev);
-}
 
-static int i2c_device_runtime_resume(struct device *dev)
-{
-       const struct dev_pm_ops *pm;
+       if (pm)
+               return pm->suspend ? pm->suspend(dev) : 0;
 
-       if (!dev->driver)
-               return 0;
-       pm = dev->driver->pm;
-       if (!pm || !pm->runtime_resume)
-               return 0;
-       return pm->runtime_resume(dev);
+       return i2c_legacy_suspend(dev, PMSG_SUSPEND);
 }
 
-static int i2c_device_runtime_idle(struct device *dev)
+static int i2c_device_pm_resume(struct device *dev)
 {
-       const struct dev_pm_ops *pm = NULL;
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
        int ret;
 
-       if (dev->driver)
-               pm = dev->driver->pm;
-       if (pm && pm->runtime_idle) {
-               ret = pm->runtime_idle(dev);
-               if (ret)
-                       return ret;
+       if (pm)
+               ret = pm->resume ? pm->resume(dev) : 0;
+       else
+               ret = i2c_legacy_resume(dev);
+
+       if (!ret) {
+               pm_runtime_disable(dev);
+               pm_runtime_set_active(dev);
+               pm_runtime_enable(dev);
        }
 
-       return pm_runtime_suspend(dev);
+       return ret;
 }
-#else
-#define i2c_device_runtime_suspend     NULL
-#define i2c_device_runtime_resume      NULL
-#define i2c_device_runtime_idle                NULL
-#endif
 
-static int i2c_device_suspend(struct device *dev, pm_message_t mesg)
+static int i2c_device_pm_freeze(struct device *dev)
 {
-       struct i2c_client *client = i2c_verify_client(dev);
-       struct i2c_driver *driver;
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-       if (!client || !dev->driver)
+       if (pm_runtime_suspended(dev))
                return 0;
-       driver = to_i2c_driver(dev->driver);
-       if (!driver->suspend)
-               return 0;
-       return driver->suspend(client, mesg);
+
+       if (pm)
+               return pm->freeze ? pm->freeze(dev) : 0;
+
+       return i2c_legacy_suspend(dev, PMSG_FREEZE);
 }
 
-static int i2c_device_resume(struct device *dev)
+static int i2c_device_pm_thaw(struct device *dev)
 {
-       struct i2c_client *client = i2c_verify_client(dev);
-       struct i2c_driver *driver;
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
 
-       if (!client || !dev->driver)
+       if (pm_runtime_suspended(dev))
                return 0;
-       driver = to_i2c_driver(dev->driver);
-       if (!driver->resume)
+
+       if (pm)
+               return pm->thaw ? pm->thaw(dev) : 0;
+
+       return i2c_legacy_resume(dev);
+}
+
+static int i2c_device_pm_poweroff(struct device *dev)
+{
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
+
+       if (pm_runtime_suspended(dev))
                return 0;
-       return driver->resume(client);
+
+       if (pm)
+               return pm->poweroff ? pm->poweroff(dev) : 0;
+
+       return i2c_legacy_suspend(dev, PMSG_HIBERNATE);
 }
 
+static int i2c_device_pm_restore(struct device *dev)
+{
+       const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
+       int ret;
+
+       if (pm)
+               ret = pm->restore ? pm->restore(dev) : 0;
+       else
+               ret = i2c_legacy_resume(dev);
+
+       if (!ret) {
+               pm_runtime_disable(dev);
+               pm_runtime_set_active(dev);
+               pm_runtime_enable(dev);
+       }
+
+       return ret;
+}
+#else /* !CONFIG_PM_SLEEP */
+#define i2c_device_pm_suspend  NULL
+#define i2c_device_pm_resume   NULL
+#define i2c_device_pm_freeze   NULL
+#define i2c_device_pm_thaw     NULL
+#define i2c_device_pm_poweroff NULL
+#define i2c_device_pm_restore  NULL
+#endif /* !CONFIG_PM_SLEEP */
+
 static void i2c_client_dev_release(struct device *dev)
 {
        kfree(to_i2c_client(dev));
@@ -301,9 +325,15 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
 static const struct dev_pm_ops i2c_device_pm_ops = {
        .suspend = i2c_device_pm_suspend,
        .resume = i2c_device_pm_resume,
-       .runtime_suspend = i2c_device_runtime_suspend,
-       .runtime_resume = i2c_device_runtime_resume,
-       .runtime_idle = i2c_device_runtime_idle,
+       .freeze = i2c_device_pm_freeze,
+       .thaw = i2c_device_pm_thaw,
+       .poweroff = i2c_device_pm_poweroff,
+       .restore = i2c_device_pm_restore,
+       SET_RUNTIME_PM_OPS(
+               pm_generic_runtime_suspend,
+               pm_generic_runtime_resume,
+               pm_generic_runtime_idle
+       )
 };
 
 struct bus_type i2c_bus_type = {
@@ -312,8 +342,6 @@ struct bus_type i2c_bus_type = {
        .probe          = i2c_device_probe,
        .remove         = i2c_device_remove,
        .shutdown       = i2c_device_shutdown,
-       .suspend        = i2c_device_suspend,
-       .resume         = i2c_device_resume,
        .pm             = &i2c_device_pm_ops,
 };
 EXPORT_SYMBOL_GPL(i2c_bus_type);
index b854508..0b7815d 100644 (file)
@@ -65,8 +65,7 @@ MODULE_LICENSE("Dual MPL/GPL");
 typedef struct ide_info_t {
        struct pcmcia_device    *p_dev;
        struct ide_host         *host;
-    int                ndev;
-    dev_node_t node;
+       int                     ndev;
 } ide_info_t;
 
 static void ide_release(struct pcmcia_device *);
@@ -102,7 +101,6 @@ static int ide_probe(struct pcmcia_device *link)
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
     link->io.IOAddrLines = 3;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -285,8 +283,7 @@ static int ide_config(struct pcmcia_device *link)
     io_base = link->io.BasePort1;
     ctl_base = stk->ctl_base;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
@@ -299,24 +296,21 @@ static int ide_config(struct pcmcia_device *link)
     if (is_kme)
        outb(0x81, ctl_base+1);
 
-     host = idecs_register(io_base, ctl_base, link->irq.AssignedIRQ, link);
+     host = idecs_register(io_base, ctl_base, link->irq, link);
      if (host == NULL && link->io.NumPorts1 == 0x20) {
            outb(0x02, ctl_base + 0x10);
            host = idecs_register(io_base + 0x10, ctl_base + 0x10,
-                                 link->irq.AssignedIRQ, link);
+                                 link->irq, link);
     }
 
     if (host == NULL)
        goto failed;
 
     info->ndev = 1;
-    sprintf(info->node.dev_name, "hd%c", 'a' + host->ports[0]->index * 2);
-    info->node.major = host->ports[0]->major;
-    info->node.minor = 0;
     info->host = host;
-    link->dev_node = &info->node;
-    printk(KERN_INFO "ide-cs: %s: Vpp = %d.%d\n",
-          info->node.dev_name, link->conf.Vpp / 10, link->conf.Vpp % 10);
+    dev_info(&link->dev, "ide-cs: hd%c: Vpp = %d.%d\n",
+           'a' + host->ports[0]->index * 2,
+           link->conf.Vpp / 10, link->conf.Vpp % 10);
 
     kfree(stk);
     return 0;
index 975adce..330d2a4 100644 (file)
@@ -46,6 +46,7 @@ source "drivers/infiniband/hw/ipath/Kconfig"
 source "drivers/infiniband/hw/ehca/Kconfig"
 source "drivers/infiniband/hw/amso1100/Kconfig"
 source "drivers/infiniband/hw/cxgb3/Kconfig"
+source "drivers/infiniband/hw/cxgb4/Kconfig"
 source "drivers/infiniband/hw/mlx4/Kconfig"
 source "drivers/infiniband/hw/nes/Kconfig"
 
index ed35e44..0c4e589 100644 (file)
@@ -4,6 +4,7 @@ obj-$(CONFIG_INFINIBAND_IPATH)          += hw/ipath/
 obj-$(CONFIG_INFINIBAND_EHCA)          += hw/ehca/
 obj-$(CONFIG_INFINIBAND_AMSO1100)      += hw/amso1100/
 obj-$(CONFIG_INFINIBAND_CXGB3)         += hw/cxgb3/
+obj-$(CONFIG_INFINIBAND_CXGB4)         += hw/cxgb4/
 obj-$(CONFIG_MLX4_INFINIBAND)          += hw/mlx4/
 obj-$(CONFIG_INFINIBAND_NES)           += hw/nes/
 obj-$(CONFIG_INFINIBAND_IPOIB)         += ulp/ipoib/
index 6d77706..b930b81 100644 (file)
@@ -79,7 +79,6 @@ static DEFINE_IDR(sdp_ps);
 static DEFINE_IDR(tcp_ps);
 static DEFINE_IDR(udp_ps);
 static DEFINE_IDR(ipoib_ps);
-static int next_port;
 
 struct cma_device {
        struct list_head        list;
@@ -1677,13 +1676,13 @@ int rdma_set_ib_paths(struct rdma_cm_id *id,
        if (!cma_comp_exch(id_priv, CMA_ADDR_RESOLVED, CMA_ROUTE_RESOLVED))
                return -EINVAL;
 
-       id->route.path_rec = kmalloc(sizeof *path_rec * num_paths, GFP_KERNEL);
+       id->route.path_rec = kmemdup(path_rec, sizeof *path_rec * num_paths,
+                                    GFP_KERNEL);
        if (!id->route.path_rec) {
                ret = -ENOMEM;
                goto err;
        }
 
-       memcpy(id->route.path_rec, path_rec, sizeof *path_rec * num_paths);
        id->route.num_paths = num_paths;
        return 0;
 err:
@@ -1970,47 +1969,33 @@ err1:
 
 static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
 {
-       struct rdma_bind_list *bind_list;
-       int port, ret, low, high;
-
-       bind_list = kzalloc(sizeof *bind_list, GFP_KERNEL);
-       if (!bind_list)
-               return -ENOMEM;
-
-retry:
-       /* FIXME: add proper port randomization per like inet_csk_get_port */
-       do {
-               ret = idr_get_new_above(ps, bind_list, next_port, &port);
-       } while ((ret == -EAGAIN) && idr_pre_get(ps, GFP_KERNEL));
-
-       if (ret)
-               goto err1;
+       static unsigned int last_used_port;
+       int low, high, remaining;
+       unsigned int rover;
 
        inet_get_local_port_range(&low, &high);
-       if (port > high) {
-               if (next_port != low) {
-                       idr_remove(ps, port);
-                       next_port = low;
-                       goto retry;
-               }
-               ret = -EADDRNOTAVAIL;
-               goto err2;
+       remaining = (high - low) + 1;
+       rover = net_random() % remaining + low;
+retry:
+       if (last_used_port != rover &&
+           !idr_find(ps, (unsigned short) rover)) {
+               int ret = cma_alloc_port(ps, id_priv, rover);
+               /*
+                * Remember previously used port number in order to avoid
+                * re-using same port immediately after it is closed.
+                */
+               if (!ret)
+                       last_used_port = rover;
+               if (ret != -EADDRNOTAVAIL)
+                       return ret;
        }
-
-       if (port == high)
-               next_port = low;
-       else
-               next_port = port + 1;
-
-       bind_list->ps = ps;
-       bind_list->port = (unsigned short) port;
-       cma_bind_port(bind_list, id_priv);
-       return 0;
-err2:
-       idr_remove(ps, port);
-err1:
-       kfree(bind_list);
-       return ret;
+       if (--remaining) {
+               rover++;
+               if ((rover < low) || (rover > high))
+                       rover = low;
+               goto retry;
+       }
+       return -EADDRNOTAVAIL;
 }
 
 static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv)
@@ -2995,12 +2980,7 @@ static void cma_remove_one(struct ib_device *device)
 
 static int __init cma_init(void)
 {
-       int ret, low, high, remaining;
-
-       get_random_bytes(&next_port, sizeof next_port);
-       inet_get_local_port_range(&low, &high);
-       remaining = (high - low) + 1;
-       next_port = ((unsigned int) next_port % remaining) + low;
+       int ret;
 
        cma_wq = create_singlethread_workqueue("rdma_cm");
        if (!cma_wq)
index 1df1194..6dc7b77 100644 (file)
@@ -291,13 +291,11 @@ struct ib_mad_agent *ib_register_mad_agent(struct ib_device *device,
        }
 
        if (mad_reg_req) {
-               reg_req = kmalloc(sizeof *reg_req, GFP_KERNEL);
+               reg_req = kmemdup(mad_reg_req, sizeof *reg_req, GFP_KERNEL);
                if (!reg_req) {
                        ret = ERR_PTR(-ENOMEM);
                        goto error3;
                }
-               /* Make a copy of the MAD registration request */
-               memcpy(reg_req, mad_reg_req, sizeof *reg_req);
        }
 
        /* Now, fill in the various structures */
index 512b1c4..4647484 100644 (file)
@@ -1181,7 +1181,7 @@ static int ib_ucm_open(struct inode *inode, struct file *filp)
        file->filp = filp;
        file->device = container_of(inode->i_cdev, struct ib_ucm_device, cdev);
 
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 static int ib_ucm_close(struct inode *inode, struct file *filp)
@@ -1229,6 +1229,7 @@ static const struct file_operations ucm_fops = {
        .release = ib_ucm_close,
        .write   = ib_ucm_write,
        .poll    = ib_ucm_poll,
+       .llseek  = no_llseek,
 };
 
 static ssize_t show_ibdev(struct device *dev, struct device_attribute *attr,
index 4618508..ac7edc2 100644 (file)
@@ -1220,7 +1220,8 @@ static int ucma_open(struct inode *inode, struct file *filp)
 
        filp->private_data = file;
        file->filp = filp;
-       return 0;
+
+       return nonseekable_open(inode, filp);
 }
 
 static int ucma_close(struct inode *inode, struct file *filp)
@@ -1250,6 +1251,7 @@ static const struct file_operations ucma_fops = {
        .release = ucma_close,
        .write   = ucma_write,
        .poll    = ucma_poll,
+       .llseek  = no_llseek,
 };
 
 static struct miscdevice ucma_misc = {
index e7db054..6babb72 100644 (file)
@@ -781,7 +781,7 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
 {
        struct ib_umad_port *port;
        struct ib_umad_file *file;
-       int ret = 0;
+       int ret;
 
        port = container_of(inode->i_cdev, struct ib_umad_port, cdev);
        if (port)
@@ -814,6 +814,8 @@ static int ib_umad_open(struct inode *inode, struct file *filp)
 
        list_add_tail(&file->port_list, &port->file_list);
 
+       ret = nonseekable_open(inode, filp);
+
 out:
        mutex_unlock(&port->file_mutex);
        return ret;
@@ -866,7 +868,8 @@ static const struct file_operations umad_fops = {
        .compat_ioctl   = ib_umad_compat_ioctl,
 #endif
        .open           = ib_umad_open,
-       .release        = ib_umad_close
+       .release        = ib_umad_close,
+       .llseek         = no_llseek,
 };
 
 static int ib_umad_sm_open(struct inode *inode, struct file *filp)
@@ -903,7 +906,7 @@ static int ib_umad_sm_open(struct inode *inode, struct file *filp)
 
        filp->private_data = port;
 
-       return 0;
+       return nonseekable_open(inode, filp);
 
 fail:
        kref_put(&port->umad_dev->ref, ib_umad_release_dev);
@@ -933,7 +936,8 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
 static const struct file_operations umad_sm_fops = {
        .owner   = THIS_MODULE,
        .open    = ib_umad_sm_open,
-       .release = ib_umad_sm_close
+       .release = ib_umad_sm_close,
+       .llseek  = no_llseek,
 };
 
 static struct ib_client umad_client = {
index fb35262..ec83e9f 100644 (file)
@@ -369,7 +369,8 @@ static const struct file_operations uverbs_event_fops = {
        .read    = ib_uverbs_event_read,
        .poll    = ib_uverbs_event_poll,
        .release = ib_uverbs_event_close,
-       .fasync  = ib_uverbs_event_fasync
+       .fasync  = ib_uverbs_event_fasync,
+       .llseek  = no_llseek,
 };
 
 void ib_uverbs_comp_handler(struct ib_cq *cq, void *cq_context)
@@ -623,7 +624,7 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
 
        filp->private_data = file;
 
-       return 0;
+       return nonseekable_open(inode, filp);
 
 err_module:
        module_put(dev->ib_dev->owner);
@@ -651,7 +652,8 @@ static const struct file_operations uverbs_fops = {
        .owner   = THIS_MODULE,
        .write   = ib_uverbs_write,
        .open    = ib_uverbs_open,
-       .release = ib_uverbs_close
+       .release = ib_uverbs_close,
+       .llseek  = no_llseek,
 };
 
 static const struct file_operations uverbs_mmap_fops = {
@@ -659,7 +661,8 @@ static const struct file_operations uverbs_mmap_fops = {
        .write   = ib_uverbs_write,
        .mmap    = ib_uverbs_mmap,
        .open    = ib_uverbs_open,
-       .release = ib_uverbs_close
+       .release = ib_uverbs_close,
+       .llseek  = no_llseek,
 };
 
 static struct ib_client uverbs_client = {
index f7ff66f..6ae698e 100644 (file)
@@ -250,7 +250,7 @@ struct c2_array {
 struct sp_chunk {
        struct sp_chunk *next;
        dma_addr_t dma_addr;
-       DECLARE_PCI_UNMAP_ADDR(mapping);
+       DEFINE_DMA_UNMAP_ADDR(mapping);
        u16 head;
        u16 shared_ptr[0];
 };
index d4f5f5d..78d247e 100644 (file)
@@ -49,7 +49,7 @@ static int c2_alloc_mqsp_chunk(struct c2_dev *c2dev, gfp_t gfp_mask,
                return -ENOMEM;
 
        new_head->dma_addr = dma_addr;
-       pci_unmap_addr_set(new_head, mapping, new_head->dma_addr);
+       dma_unmap_addr_set(new_head, mapping, new_head->dma_addr);
 
        new_head->next = NULL;
        new_head->head = 0;
@@ -81,7 +81,7 @@ void c2_free_mqsp_pool(struct c2_dev *c2dev, struct sp_chunk *root)
        while (root) {
                next = root->next;
                dma_free_coherent(&c2dev->pcidev->dev, PAGE_SIZE, root,
-                                 pci_unmap_addr(root, mapping));
+                                 dma_unmap_addr(root, mapping));
                root = next;
        }
 }
index f7b0fc2..49e0e85 100644 (file)
@@ -257,7 +257,7 @@ int c2_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags)
 static void c2_free_cq_buf(struct c2_dev *c2dev, struct c2_mq *mq)
 {
        dma_free_coherent(&c2dev->pcidev->dev, mq->q_size * mq->msg_size,
-                         mq->msg_pool.host, pci_unmap_addr(mq, mapping));
+                         mq->msg_pool.host, dma_unmap_addr(mq, mapping));
 }
 
 static int c2_alloc_cq_buf(struct c2_dev *c2dev, struct c2_mq *mq, int q_size,
@@ -278,7 +278,7 @@ static int c2_alloc_cq_buf(struct c2_dev *c2dev, struct c2_mq *mq, int q_size,
                       NULL,    /* peer (currently unknown) */
                       C2_MQ_HOST_TARGET);
 
-       pci_unmap_addr_set(mq, mapping, mq->host_dma);
+       dma_unmap_addr_set(mq, mapping, mq->host_dma);
 
        return 0;
 }
index acede00..fc1b9a7 100644 (file)
@@ -71,7 +71,7 @@ struct c2_mq {
                u8 __iomem *adapter;
        } msg_pool;
        dma_addr_t host_dma;
-       DECLARE_PCI_UNMAP_ADDR(mapping);
+       DEFINE_DMA_UNMAP_ADDR(mapping);
        u16 hint_count;
        u16 priv;
        struct c2_mq_shared __iomem *peer;
index 1076df2..bf18998 100644 (file)
@@ -50,7 +50,7 @@
 
 struct c2_buf_list {
        void *buf;
-        DECLARE_PCI_UNMAP_ADDR(mapping)
+       DEFINE_DMA_UNMAP_ADDR(mapping);
 };
 
 
index 78c4bcc..85cfae4 100644 (file)
@@ -524,7 +524,7 @@ int __devinit c2_rnic_init(struct c2_dev *c2dev)
                err = -ENOMEM;
                goto bail1;
        }
-       pci_unmap_addr_set(&c2dev->rep_vq, mapping, c2dev->rep_vq.host_dma);
+       dma_unmap_addr_set(&c2dev->rep_vq, mapping, c2dev->rep_vq.host_dma);
        pr_debug("%s rep_vq va %p dma %llx\n", __func__, q1_pages,
                 (unsigned long long) c2dev->rep_vq.host_dma);
        c2_mq_rep_init(&c2dev->rep_vq,
@@ -545,7 +545,7 @@ int __devinit c2_rnic_init(struct c2_dev *c2dev)
                err = -ENOMEM;
                goto bail2;
        }
-       pci_unmap_addr_set(&c2dev->aeq, mapping, c2dev->aeq.host_dma);
+       dma_unmap_addr_set(&c2dev->aeq, mapping, c2dev->aeq.host_dma);
        pr_debug("%s aeq va %p dma %llx\n", __func__, q2_pages,
                 (unsigned long long) c2dev->aeq.host_dma);
        c2_mq_rep_init(&c2dev->aeq,
@@ -596,11 +596,11 @@ int __devinit c2_rnic_init(struct c2_dev *c2dev)
       bail3:
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->aeq.q_size * c2dev->aeq.msg_size,
-                         q2_pages, pci_unmap_addr(&c2dev->aeq, mapping));
+                         q2_pages, dma_unmap_addr(&c2dev->aeq, mapping));
       bail2:
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->rep_vq.q_size * c2dev->rep_vq.msg_size,
-                         q1_pages, pci_unmap_addr(&c2dev->rep_vq, mapping));
+                         q1_pages, dma_unmap_addr(&c2dev->rep_vq, mapping));
       bail1:
        c2_free_mqsp_pool(c2dev, c2dev->kern_mqsp_pool);
       bail0:
@@ -637,13 +637,13 @@ void __devexit c2_rnic_term(struct c2_dev *c2dev)
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->aeq.q_size * c2dev->aeq.msg_size,
                          c2dev->aeq.msg_pool.host,
-                         pci_unmap_addr(&c2dev->aeq, mapping));
+                         dma_unmap_addr(&c2dev->aeq, mapping));
 
        /* Free the verbs reply queue */
        dma_free_coherent(&c2dev->pcidev->dev,
                          c2dev->rep_vq.q_size * c2dev->rep_vq.msg_size,
                          c2dev->rep_vq.msg_pool.host,
-                         pci_unmap_addr(&c2dev->rep_vq, mapping));
+                         dma_unmap_addr(&c2dev->rep_vq, mapping));
 
        /* Free the MQ shared pointer pool */
        c2_free_mqsp_pool(c2dev, c2dev->kern_mqsp_pool);
index 35f286f..005b7b5 100644 (file)
@@ -174,7 +174,7 @@ int cxio_create_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq, int kernel)
                kfree(cq->sw_queue);
                return -ENOMEM;
        }
-       pci_unmap_addr_set(cq, mapping, cq->dma_addr);
+       dma_unmap_addr_set(cq, mapping, cq->dma_addr);
        memset(cq->queue, 0, size);
        setup.id = cq->cqid;
        setup.base_addr = (u64) (cq->dma_addr);
@@ -297,7 +297,7 @@ int cxio_create_qp(struct cxio_rdev *rdev_p, u32 kernel_domain,
                goto err4;
 
        memset(wq->queue, 0, depth * sizeof(union t3_wr));
-       pci_unmap_addr_set(wq, mapping, wq->dma_addr);
+       dma_unmap_addr_set(wq, mapping, wq->dma_addr);
        wq->doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr;
        if (!kernel_domain)
                wq->udb = (u64)rdev_p->rnic_info.udbell_physbase +
@@ -325,7 +325,7 @@ int cxio_destroy_cq(struct cxio_rdev *rdev_p, struct t3_cq *cq)
        dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
                          (1UL << (cq->size_log2))
                          * sizeof(struct t3_cqe), cq->queue,
-                         pci_unmap_addr(cq, mapping));
+                         dma_unmap_addr(cq, mapping));
        cxio_hal_put_cqid(rdev_p->rscp, cq->cqid);
        return err;
 }
@@ -336,7 +336,7 @@ int cxio_destroy_qp(struct cxio_rdev *rdev_p, struct t3_wq *wq,
        dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
                          (1UL << (wq->size_log2))
                          * sizeof(union t3_wr), wq->queue,
-                         pci_unmap_addr(wq, mapping));
+                         dma_unmap_addr(wq, mapping));
        kfree(wq->sq);
        cxio_hal_rqtpool_free(rdev_p, wq->rq_addr, (1UL << wq->rq_size_log2));
        kfree(wq->rq);
@@ -537,7 +537,7 @@ static int cxio_hal_init_ctrl_qp(struct cxio_rdev *rdev_p)
                err = -ENOMEM;
                goto err;
        }
-       pci_unmap_addr_set(&rdev_p->ctrl_qp, mapping,
+       dma_unmap_addr_set(&rdev_p->ctrl_qp, mapping,
                           rdev_p->ctrl_qp.dma_addr);
        rdev_p->ctrl_qp.doorbell = (void __iomem *)rdev_p->rnic_info.kdb_addr;
        memset(rdev_p->ctrl_qp.workq, 0,
@@ -583,7 +583,7 @@ static int cxio_hal_destroy_ctrl_qp(struct cxio_rdev *rdev_p)
        dma_free_coherent(&(rdev_p->rnic_info.pdev->dev),
                          (1UL << T3_CTRL_QP_SIZE_LOG2)
                          * sizeof(union t3_wr), rdev_p->ctrl_qp.workq,
-                         pci_unmap_addr(&rdev_p->ctrl_qp, mapping));
+                         dma_unmap_addr(&rdev_p->ctrl_qp, mapping));
        return cxio_hal_clear_qp_ctx(rdev_p, T3_CTRL_QP_ID);
 }
 
index 073373c..8f0caf7 100644 (file)
@@ -71,7 +71,7 @@ struct cxio_hal_ctrl_qp {
        wait_queue_head_t waitq;/* wait for RspQ/CQE msg */
        union t3_wr *workq;     /* the work request queue */
        dma_addr_t dma_addr;    /* pci bus address of the workq */
-       DECLARE_PCI_UNMAP_ADDR(mapping)
+       DEFINE_DMA_UNMAP_ADDR(mapping);
        void __iomem *doorbell;
 };
 
index 15073b2..e5ddb63 100644 (file)
@@ -691,7 +691,7 @@ struct t3_swrq {
 struct t3_wq {
        union t3_wr *queue;             /* DMA accessable memory */
        dma_addr_t dma_addr;            /* DMA address for HW */
-       DECLARE_PCI_UNMAP_ADDR(mapping) /* unmap kruft */
+       DEFINE_DMA_UNMAP_ADDR(mapping); /* unmap kruft */
        u32 error;                      /* 1 once we go to ERROR */
        u32 qpid;
        u32 wptr;                       /* idx to next available WR slot */
@@ -718,7 +718,7 @@ struct t3_cq {
        u32 wptr;
        u32 size_log2;
        dma_addr_t dma_addr;
-       DECLARE_PCI_UNMAP_ADDR(mapping)
+       DEFINE_DMA_UNMAP_ADDR(mapping);
        struct t3_cqe *queue;
        struct t3_cqe *sw_queue;
        u32 sw_rptr;
index 63f975f..8e77dc5 100644 (file)
@@ -47,8 +47,6 @@ MODULE_DESCRIPTION("Chelsio T3 RDMA Driver");
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_VERSION(DRV_VERSION);
 
-cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS];
-
 static void open_rnic_dev(struct t3cdev *);
 static void close_rnic_dev(struct t3cdev *);
 static void iwch_event_handler(struct t3cdev *, u32, u32);
index 4fef032..ebfb117 100644 (file)
@@ -102,12 +102,9 @@ static unsigned int cong_flavor = 1;
 module_param(cong_flavor, uint, 0644);
 MODULE_PARM_DESC(cong_flavor, "TCP Congestion control flavor (default=1)");
 
-static void process_work(struct work_struct *work);
 static struct workqueue_struct *workq;
-static DECLARE_WORK(skb_work, process_work);
 
 static struct sk_buff_head rxq;
-static cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS];
 
 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
 static void ep_timeout(unsigned long arg);
@@ -151,7 +148,7 @@ int iwch_l2t_send(struct t3cdev *tdev, struct sk_buff *skb, struct l2t_entry *l2
                return -EIO;
        }
        error = l2t_send(tdev, skb, l2e);
-       if (error)
+       if (error < 0)
                kfree_skb(skb);
        return error;
 }
@@ -167,7 +164,7 @@ int iwch_cxgb3_ofld_send(struct t3cdev *tdev, struct sk_buff *skb)
                return -EIO;
        }
        error = cxgb3_ofld_send(tdev, skb);
-       if (error)
+       if (error < 0)
                kfree_skb(skb);
        return error;
 }
@@ -302,27 +299,6 @@ static void release_ep_resources(struct iwch_ep *ep)
        put_ep(&ep->com);
 }
 
-static void process_work(struct work_struct *work)
-{
-       struct sk_buff *skb = NULL;
-       void *ep;
-       struct t3cdev *tdev;
-       int ret;
-
-       while ((skb = skb_dequeue(&rxq))) {
-               ep = *((void **) (skb->cb));
-               tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
-               ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
-               if (ret & CPL_RET_BUF_DONE)
-                       kfree_skb(skb);
-
-               /*
-                * ep was referenced in sched(), and is freed here.
-                */
-               put_ep((struct iwch_ep_common *)ep);
-       }
-}
-
 static int status2errno(int status)
 {
        switch (status) {
@@ -2157,7 +2133,49 @@ int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
 
 /*
  * All the CM events are handled on a work queue to have a safe context.
+ * These are the real handlers that are called from the work queue.
  */
+static const cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS] = {
+       [CPL_ACT_ESTABLISH]     = act_establish,
+       [CPL_ACT_OPEN_RPL]      = act_open_rpl,
+       [CPL_RX_DATA]           = rx_data,
+       [CPL_TX_DMA_ACK]        = tx_ack,
+       [CPL_ABORT_RPL_RSS]     = abort_rpl,
+       [CPL_ABORT_RPL]         = abort_rpl,
+       [CPL_PASS_OPEN_RPL]     = pass_open_rpl,
+       [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
+       [CPL_PASS_ACCEPT_REQ]   = pass_accept_req,
+       [CPL_PASS_ESTABLISH]    = pass_establish,
+       [CPL_PEER_CLOSE]        = peer_close,
+       [CPL_ABORT_REQ_RSS]     = peer_abort,
+       [CPL_CLOSE_CON_RPL]     = close_con_rpl,
+       [CPL_RDMA_TERMINATE]    = terminate,
+       [CPL_RDMA_EC_STATUS]    = ec_status,
+};
+
+static void process_work(struct work_struct *work)
+{
+       struct sk_buff *skb = NULL;
+       void *ep;
+       struct t3cdev *tdev;
+       int ret;
+
+       while ((skb = skb_dequeue(&rxq))) {
+               ep = *((void **) (skb->cb));
+               tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
+               ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
+               if (ret & CPL_RET_BUF_DONE)
+                       kfree_skb(skb);
+
+               /*
+                * ep was referenced in sched(), and is freed here.
+                */
+               put_ep((struct iwch_ep_common *)ep);
+       }
+}
+
+static DECLARE_WORK(skb_work, process_work);
+
 static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
 {
        struct iwch_ep_common *epc = ctx;
@@ -2189,6 +2207,29 @@ static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
        return CPL_RET_BUF_DONE;
 }
 
+/*
+ * All upcalls from the T3 Core go to sched() to schedule the
+ * processing on a work queue.
+ */
+cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS] = {
+       [CPL_ACT_ESTABLISH]     = sched,
+       [CPL_ACT_OPEN_RPL]      = sched,
+       [CPL_RX_DATA]           = sched,
+       [CPL_TX_DMA_ACK]        = sched,
+       [CPL_ABORT_RPL_RSS]     = sched,
+       [CPL_ABORT_RPL]         = sched,
+       [CPL_PASS_OPEN_RPL]     = sched,
+       [CPL_CLOSE_LISTSRV_RPL] = sched,
+       [CPL_PASS_ACCEPT_REQ]   = sched,
+       [CPL_PASS_ESTABLISH]    = sched,
+       [CPL_PEER_CLOSE]        = sched,
+       [CPL_CLOSE_CON_RPL]     = sched,
+       [CPL_ABORT_REQ_RSS]     = sched,
+       [CPL_RDMA_TERMINATE]    = sched,
+       [CPL_RDMA_EC_STATUS]    = sched,
+       [CPL_SET_TCB_RPL]       = set_tcb_rpl,
+};
+
 int __init iwch_cm_init(void)
 {
        skb_queue_head_init(&rxq);
@@ -2197,46 +2238,6 @@ int __init iwch_cm_init(void)
        if (!workq)
                return -ENOMEM;
 
-       /*
-        * All upcalls from the T3 Core go to sched() to
-        * schedule the processing on a work queue.
-        */
-       t3c_handlers[CPL_ACT_ESTABLISH] = sched;
-       t3c_handlers[CPL_ACT_OPEN_RPL] = sched;
-       t3c_handlers[CPL_RX_DATA] = sched;
-       t3c_handlers[CPL_TX_DMA_ACK] = sched;
-       t3c_handlers[CPL_ABORT_RPL_RSS] = sched;
-       t3c_handlers[CPL_ABORT_RPL] = sched;
-       t3c_handlers[CPL_PASS_OPEN_RPL] = sched;
-       t3c_handlers[CPL_CLOSE_LISTSRV_RPL] = sched;
-       t3c_handlers[CPL_PASS_ACCEPT_REQ] = sched;
-       t3c_handlers[CPL_PASS_ESTABLISH] = sched;
-       t3c_handlers[CPL_PEER_CLOSE] = sched;
-       t3c_handlers[CPL_CLOSE_CON_RPL] = sched;
-       t3c_handlers[CPL_ABORT_REQ_RSS] = sched;
-       t3c_handlers[CPL_RDMA_TERMINATE] = sched;
-       t3c_handlers[CPL_RDMA_EC_STATUS] = sched;
-       t3c_handlers[CPL_SET_TCB_RPL] = set_tcb_rpl;
-
-       /*
-        * These are the real handlers that are called from a
-        * work queue.
-        */
-       work_handlers[CPL_ACT_ESTABLISH] = act_establish;
-       work_handlers[CPL_ACT_OPEN_RPL] = act_open_rpl;
-       work_handlers[CPL_RX_DATA] = rx_data;
-       work_handlers[CPL_TX_DMA_ACK] = tx_ack;
-       work_handlers[CPL_ABORT_RPL_RSS] = abort_rpl;
-       work_handlers[CPL_ABORT_RPL] = abort_rpl;
-       work_handlers[CPL_PASS_OPEN_RPL] = pass_open_rpl;
-       work_handlers[CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl;
-       work_handlers[CPL_PASS_ACCEPT_REQ] = pass_accept_req;
-       work_handlers[CPL_PASS_ESTABLISH] = pass_establish;
-       work_handlers[CPL_PEER_CLOSE] = peer_close;
-       work_handlers[CPL_ABORT_REQ_RSS] = peer_abort;
-       work_handlers[CPL_CLOSE_CON_RPL] = close_con_rpl;
-       work_handlers[CPL_RDMA_TERMINATE] = terminate;
-       work_handlers[CPL_RDMA_EC_STATUS] = ec_status;
        return 0;
 }
 
diff --git a/drivers/infiniband/hw/cxgb4/Kconfig b/drivers/infiniband/hw/cxgb4/Kconfig
new file mode 100644 (file)
index 0000000..ccb85ea
--- /dev/null
@@ -0,0 +1,18 @@
+config INFINIBAND_CXGB4
+       tristate "Chelsio T4 RDMA Driver"
+       depends on CHELSIO_T4 && INET
+       select GENERIC_ALLOCATOR
+       ---help---
+         This is an iWARP/RDMA driver for the Chelsio T4 1GbE and
+         10GbE adapters.
+
+         For general information about Chelsio and our products, visit
+         our website at <http://www.chelsio.com>.
+
+         For customer support, please visit our customer support page at
+         <http://www.chelsio.com/support.htm>.
+
+         Please send feedback to <linux-bugs@chelsio.com>.
+
+         To compile this driver as a module, choose M here: the module
+         will be called iw_cxgb4.
diff --git a/drivers/infiniband/hw/cxgb4/Makefile b/drivers/infiniband/hw/cxgb4/Makefile
new file mode 100644 (file)
index 0000000..e31a499
--- /dev/null
@@ -0,0 +1,5 @@
+EXTRA_CFLAGS += -Idrivers/net/cxgb4
+
+obj-$(CONFIG_INFINIBAND_CXGB4) += iw_cxgb4.o
+
+iw_cxgb4-y :=  device.o cm.o provider.o mem.o cq.o qp.o resource.o ev.o
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
new file mode 100644 (file)
index 0000000..30ce0a8
--- /dev/null
@@ -0,0 +1,2374 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials
+ *       provided with the distribution.
+ *
+ * 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.
+ */
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/workqueue.h>
+#include <linux/skbuff.h>
+#include <linux/timer.h>
+#include <linux/notifier.h>
+#include <linux/inetdevice.h>
+#include <linux/ip.h>
+#include <linux/tcp.h>
+
+#include <net/neighbour.h>
+#include <net/netevent.h>
+#include <net/route.h>
+
+#include "iw_cxgb4.h"
+
+static char *states[] = {
+       "idle",
+       "listen",
+       "connecting",
+       "mpa_wait_req",
+       "mpa_req_sent",
+       "mpa_req_rcvd",
+       "mpa_rep_sent",
+       "fpdu_mode",
+       "aborting",
+       "closing",
+       "moribund",
+       "dead",
+       NULL,
+};
+
+int c4iw_max_read_depth = 8;
+module_param(c4iw_max_read_depth, int, 0644);
+MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
+
+static int enable_tcp_timestamps;
+module_param(enable_tcp_timestamps, int, 0644);
+MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
+
+static int enable_tcp_sack;
+module_param(enable_tcp_sack, int, 0644);
+MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
+
+static int enable_tcp_window_scaling = 1;
+module_param(enable_tcp_window_scaling, int, 0644);
+MODULE_PARM_DESC(enable_tcp_window_scaling,
+                "Enable tcp window scaling (default=1)");
+
+int c4iw_debug;
+module_param(c4iw_debug, int, 0644);
+MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
+
+static int peer2peer;
+module_param(peer2peer, int, 0644);
+MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
+
+static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
+module_param(p2p_type, int, 0644);
+MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
+                          "1=RDMA_READ 0=RDMA_WRITE (default 1)");
+
+static int ep_timeout_secs = 60;
+module_param(ep_timeout_secs, int, 0644);
+MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
+                                  "in seconds (default=60)");
+
+static int mpa_rev = 1;
+module_param(mpa_rev, int, 0644);
+MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
+                "1 is spec compliant. (default=1)");
+
+static int markers_enabled;
+module_param(markers_enabled, int, 0644);
+MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
+
+static int crc_enabled = 1;
+module_param(crc_enabled, int, 0644);
+MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
+
+static int rcv_win = 256 * 1024;
+module_param(rcv_win, int, 0644);
+MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
+
+static int snd_win = 32 * 1024;
+module_param(snd_win, int, 0644);
+MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=32KB)");
+
+static struct workqueue_struct *workq;
+
+static struct sk_buff_head rxq;
+
+static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
+static void ep_timeout(unsigned long arg);
+static void connect_reply_upcall(struct c4iw_ep *ep, int status);
+
+static LIST_HEAD(timeout_list);
+static spinlock_t timeout_lock;
+
+static void start_ep_timer(struct c4iw_ep *ep)
+{
+       PDBG("%s ep %p\n", __func__, ep);
+       if (timer_pending(&ep->timer)) {
+               PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
+               del_timer_sync(&ep->timer);
+       } else
+               c4iw_get_ep(&ep->com);
+       ep->timer.expires = jiffies + ep_timeout_secs * HZ;
+       ep->timer.data = (unsigned long)ep;
+       ep->timer.function = ep_timeout;
+       add_timer(&ep->timer);
+}
+
+static void stop_ep_timer(struct c4iw_ep *ep)
+{
+       PDBG("%s ep %p\n", __func__, ep);
+       if (!timer_pending(&ep->timer)) {
+               printk(KERN_ERR "%s timer stopped when its not running! "
+                      "ep %p state %u\n", __func__, ep, ep->com.state);
+               WARN_ON(1);
+               return;
+       }
+       del_timer_sync(&ep->timer);
+       c4iw_put_ep(&ep->com);
+}
+
+static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
+                 struct l2t_entry *l2e)
+{
+       int     error = 0;
+
+       if (c4iw_fatal_error(rdev)) {
+               kfree_skb(skb);
+               PDBG("%s - device in error state - dropping\n", __func__);
+               return -EIO;
+       }
+       error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
+       if (error < 0)
+               kfree_skb(skb);
+       return error;
+}
+
+int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
+{
+       int     error = 0;
+
+       if (c4iw_fatal_error(rdev)) {
+               kfree_skb(skb);
+               PDBG("%s - device in error state - dropping\n", __func__);
+               return -EIO;
+       }
+       error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
+       if (error < 0)
+               kfree_skb(skb);
+       return error;
+}
+
+static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
+{
+       struct cpl_tid_release *req;
+
+       skb = get_skb(skb, sizeof *req, GFP_KERNEL);
+       if (!skb)
+               return;
+       req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
+       INIT_TP_WR(req, hwtid);
+       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
+       set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
+       c4iw_ofld_send(rdev, skb);
+       return;
+}
+
+static void set_emss(struct c4iw_ep *ep, u16 opt)
+{
+       ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
+       ep->mss = ep->emss;
+       if (GET_TCPOPT_TSTAMP(opt))
+               ep->emss -= 12;
+       if (ep->emss < 128)
+               ep->emss = 128;
+       PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
+            ep->mss, ep->emss);
+}
+
+static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
+{
+       unsigned long flags;
+       enum c4iw_ep_state state;
+
+       spin_lock_irqsave(&epc->lock, flags);
+       state = epc->state;
+       spin_unlock_irqrestore(&epc->lock, flags);
+       return state;
+}
+
+static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
+{
+       epc->state = new;
+}
+
+static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&epc->lock, flags);
+       PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
+       __state_set(epc, new);
+       spin_unlock_irqrestore(&epc->lock, flags);
+       return;
+}
+
+static void *alloc_ep(int size, gfp_t gfp)
+{
+       struct c4iw_ep_common *epc;
+
+       epc = kzalloc(size, gfp);
+       if (epc) {
+               kref_init(&epc->kref);
+               spin_lock_init(&epc->lock);
+               init_waitqueue_head(&epc->waitq);
+       }
+       PDBG("%s alloc ep %p\n", __func__, epc);
+       return epc;
+}
+
+void _c4iw_free_ep(struct kref *kref)
+{
+       struct c4iw_ep *ep;
+
+       ep = container_of(kref, struct c4iw_ep, com.kref);
+       PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
+       if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
+               cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
+               dst_release(ep->dst);
+               cxgb4_l2t_release(ep->l2t);
+       }
+       kfree(ep);
+}
+
+static void release_ep_resources(struct c4iw_ep *ep)
+{
+       set_bit(RELEASE_RESOURCES, &ep->com.flags);
+       c4iw_put_ep(&ep->com);
+}
+
+static int status2errno(int status)
+{
+       switch (status) {
+       case CPL_ERR_NONE:
+               return 0;
+       case CPL_ERR_CONN_RESET:
+               return -ECONNRESET;
+       case CPL_ERR_ARP_MISS:
+               return -EHOSTUNREACH;
+       case CPL_ERR_CONN_TIMEDOUT:
+               return -ETIMEDOUT;
+       case CPL_ERR_TCAM_FULL:
+               return -ENOMEM;
+       case CPL_ERR_CONN_EXIST:
+               return -EADDRINUSE;
+       default:
+               return -EIO;
+       }
+}
+
+/*
+ * Try and reuse skbs already allocated...
+ */
+static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
+{
+       if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
+               skb_trim(skb, 0);
+               skb_get(skb);
+               skb_reset_transport_header(skb);
+       } else {
+               skb = alloc_skb(len, gfp);
+       }
+       return skb;
+}
+
+static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
+                                __be32 peer_ip, __be16 local_port,
+                                __be16 peer_port, u8 tos)
+{
+       struct rtable *rt;
+       struct flowi fl = {
+               .oif = 0,
+               .nl_u = {
+                        .ip4_u = {
+                                  .daddr = peer_ip,
+                                  .saddr = local_ip,
+                                  .tos = tos}
+                        },
+               .proto = IPPROTO_TCP,
+               .uli_u = {
+                         .ports = {
+                                   .sport = local_port,
+                                   .dport = peer_port}
+                         }
+       };
+
+       if (ip_route_output_flow(&init_net, &rt, &fl, NULL, 0))
+               return NULL;
+       return rt;
+}
+
+static void arp_failure_discard(void *handle, struct sk_buff *skb)
+{
+       PDBG("%s c4iw_dev %p\n", __func__, handle);
+       kfree_skb(skb);
+}
+
+/*
+ * Handle an ARP failure for an active open.
+ */
+static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
+{
+       printk(KERN_ERR MOD "ARP failure duing connect\n");
+       kfree_skb(skb);
+}
+
+/*
+ * Handle an ARP failure for a CPL_ABORT_REQ.  Change it into a no RST variant
+ * and send it along.
+ */
+static void abort_arp_failure(void *handle, struct sk_buff *skb)
+{
+       struct c4iw_rdev *rdev = handle;
+       struct cpl_abort_req *req = cplhdr(skb);
+
+       PDBG("%s rdev %p\n", __func__, rdev);
+       req->cmd = CPL_ABORT_NO_RST;
+       c4iw_ofld_send(rdev, skb);
+}
+
+static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
+{
+       unsigned int flowclen = 80;
+       struct fw_flowc_wr *flowc;
+       int i;
+
+       skb = get_skb(skb, flowclen, GFP_KERNEL);
+       flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
+
+       flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
+                                          FW_FLOWC_WR_NPARAMS(8));
+       flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
+                                         16)) | FW_WR_FLOWID(ep->hwtid));
+
+       flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
+       flowc->mnemval[0].val = cpu_to_be32(0);
+       flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
+       flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
+       flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
+       flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
+       flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
+       flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
+       flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
+       flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
+       flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
+       flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
+       flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
+       flowc->mnemval[6].val = cpu_to_be32(snd_win);
+       flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
+       flowc->mnemval[7].val = cpu_to_be32(ep->emss);
+       /* Pad WR to 16 byte boundary */
+       flowc->mnemval[8].mnemonic = 0;
+       flowc->mnemval[8].val = 0;
+       for (i = 0; i < 9; i++) {
+               flowc->mnemval[i].r4[0] = 0;
+               flowc->mnemval[i].r4[1] = 0;
+               flowc->mnemval[i].r4[2] = 0;
+       }
+
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+       c4iw_ofld_send(&ep->com.dev->rdev, skb);
+}
+
+static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
+{
+       struct cpl_close_con_req *req;
+       struct sk_buff *skb;
+       int wrlen = roundup(sizeof *req, 16);
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       skb = get_skb(NULL, wrlen, gfp);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+       t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
+       req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       INIT_TP_WR(req, ep->hwtid);
+       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
+                                                   ep->hwtid));
+       return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+}
+
+static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
+{
+       struct cpl_abort_req *req;
+       int wrlen = roundup(sizeof *req, 16);
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       skb = get_skb(skb, wrlen, gfp);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
+                      __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+       t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
+       req = (struct cpl_abort_req *) skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       INIT_TP_WR(req, ep->hwtid);
+       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
+       req->cmd = CPL_ABORT_SEND_RST;
+       return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+}
+
+static int send_connect(struct c4iw_ep *ep)
+{
+       struct cpl_act_open_req *req;
+       struct sk_buff *skb;
+       u64 opt0;
+       u32 opt2;
+       unsigned int mtu_idx;
+       int wscale;
+       int wrlen = roundup(sizeof *req, 16);
+
+       PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
+
+       skb = get_skb(NULL, wrlen, GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
+                      __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->txq_idx);
+
+       cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
+       wscale = compute_wscale(rcv_win);
+       opt0 = KEEP_ALIVE(1) |
+              WND_SCALE(wscale) |
+              MSS_IDX(mtu_idx) |
+              L2T_IDX(ep->l2t->idx) |
+              TX_CHAN(ep->tx_chan) |
+              SMAC_SEL(ep->smac_idx) |
+              DSCP(ep->tos) |
+              RCV_BUFSIZ(rcv_win>>10);
+       opt2 = RX_CHANNEL(0) |
+              RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
+       if (enable_tcp_timestamps)
+               opt2 |= TSTAMPS_EN(1);
+       if (enable_tcp_sack)
+               opt2 |= SACK_EN(1);
+       if (wscale && enable_tcp_window_scaling)
+               opt2 |= WND_SCALE_EN(1);
+       t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
+
+       req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
+       INIT_TP_WR(req, 0);
+       OPCODE_TID(req) = cpu_to_be32(
+               MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
+       req->local_port = ep->com.local_addr.sin_port;
+       req->peer_port = ep->com.remote_addr.sin_port;
+       req->local_ip = ep->com.local_addr.sin_addr.s_addr;
+       req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
+       req->opt0 = cpu_to_be64(opt0);
+       req->params = 0;
+       req->opt2 = cpu_to_be32(opt2);
+       return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+}
+
+static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb)
+{
+       int mpalen, wrlen;
+       struct fw_ofld_tx_data_wr *req;
+       struct mpa_message *mpa;
+
+       PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
+
+       BUG_ON(skb_cloned(skb));
+
+       mpalen = sizeof(*mpa) + ep->plen;
+       wrlen = roundup(mpalen + sizeof *req, 16);
+       skb = get_skb(skb, wrlen, GFP_KERNEL);
+       if (!skb) {
+               connect_reply_upcall(ep, -ENOMEM);
+               return;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+
+       req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       req->op_to_immdlen = cpu_to_be32(
+               FW_WR_OP(FW_OFLD_TX_DATA_WR) |
+               FW_WR_COMPL(1) |
+               FW_WR_IMMDLEN(mpalen));
+       req->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(ep->hwtid) |
+               FW_WR_LEN16(wrlen >> 4));
+       req->plen = cpu_to_be32(mpalen);
+       req->tunnel_to_proxy = cpu_to_be32(
+               FW_OFLD_TX_DATA_WR_FLUSH(1) |
+               FW_OFLD_TX_DATA_WR_SHOVE(1));
+
+       mpa = (struct mpa_message *)(req + 1);
+       memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
+       mpa->flags = (crc_enabled ? MPA_CRC : 0) |
+                    (markers_enabled ? MPA_MARKERS : 0);
+       mpa->private_data_size = htons(ep->plen);
+       mpa->revision = mpa_rev;
+
+       if (ep->plen)
+               memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
+
+       /*
+        * Reference the mpa skb.  This ensures the data area
+        * will remain in memory until the hw acks the tx.
+        * Function fw4_ack() will deref it.
+        */
+       skb_get(skb);
+       t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
+       BUG_ON(ep->mpa_skb);
+       ep->mpa_skb = skb;
+       c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+       start_ep_timer(ep);
+       state_set(&ep->com, MPA_REQ_SENT);
+       ep->mpa_attr.initiator = 1;
+       return;
+}
+
+static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
+{
+       int mpalen, wrlen;
+       struct fw_ofld_tx_data_wr *req;
+       struct mpa_message *mpa;
+       struct sk_buff *skb;
+
+       PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
+
+       mpalen = sizeof(*mpa) + plen;
+       wrlen = roundup(mpalen + sizeof *req, 16);
+
+       skb = get_skb(NULL, wrlen, GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+
+       req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       req->op_to_immdlen = cpu_to_be32(
+               FW_WR_OP(FW_OFLD_TX_DATA_WR) |
+               FW_WR_COMPL(1) |
+               FW_WR_IMMDLEN(mpalen));
+       req->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(ep->hwtid) |
+               FW_WR_LEN16(wrlen >> 4));
+       req->plen = cpu_to_be32(mpalen);
+       req->tunnel_to_proxy = cpu_to_be32(
+               FW_OFLD_TX_DATA_WR_FLUSH(1) |
+               FW_OFLD_TX_DATA_WR_SHOVE(1));
+
+       mpa = (struct mpa_message *)(req + 1);
+       memset(mpa, 0, sizeof(*mpa));
+       memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
+       mpa->flags = MPA_REJECT;
+       mpa->revision = mpa_rev;
+       mpa->private_data_size = htons(plen);
+       if (plen)
+               memcpy(mpa->private_data, pdata, plen);
+
+       /*
+        * Reference the mpa skb again.  This ensures the data area
+        * will remain in memory until the hw acks the tx.
+        * Function fw4_ack() will deref it.
+        */
+       skb_get(skb);
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+       t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
+       BUG_ON(ep->mpa_skb);
+       ep->mpa_skb = skb;
+       return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+}
+
+static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
+{
+       int mpalen, wrlen;
+       struct fw_ofld_tx_data_wr *req;
+       struct mpa_message *mpa;
+       struct sk_buff *skb;
+
+       PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
+
+       mpalen = sizeof(*mpa) + plen;
+       wrlen = roundup(mpalen + sizeof *req, 16);
+
+       skb = get_skb(NULL, wrlen, GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+
+       req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       req->op_to_immdlen = cpu_to_be32(
+               FW_WR_OP(FW_OFLD_TX_DATA_WR) |
+               FW_WR_COMPL(1) |
+               FW_WR_IMMDLEN(mpalen));
+       req->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(ep->hwtid) |
+               FW_WR_LEN16(wrlen >> 4));
+       req->plen = cpu_to_be32(mpalen);
+       req->tunnel_to_proxy = cpu_to_be32(
+               FW_OFLD_TX_DATA_WR_FLUSH(1) |
+               FW_OFLD_TX_DATA_WR_SHOVE(1));
+
+       mpa = (struct mpa_message *)(req + 1);
+       memset(mpa, 0, sizeof(*mpa));
+       memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
+       mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
+                    (markers_enabled ? MPA_MARKERS : 0);
+       mpa->revision = mpa_rev;
+       mpa->private_data_size = htons(plen);
+       if (plen)
+               memcpy(mpa->private_data, pdata, plen);
+
+       /*
+        * Reference the mpa skb.  This ensures the data area
+        * will remain in memory until the hw acks the tx.
+        * Function fw4_ack() will deref it.
+        */
+       skb_get(skb);
+       t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
+       ep->mpa_skb = skb;
+       state_set(&ep->com, MPA_REP_SENT);
+       return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+}
+
+static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_act_establish *req = cplhdr(skb);
+       unsigned int tid = GET_TID(req);
+       unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
+       struct tid_info *t = dev->rdev.lldi.tids;
+
+       ep = lookup_atid(t, atid);
+
+       PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
+            be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
+
+       dst_confirm(ep->dst);
+
+       /* setup the hwtid for this connection */
+       ep->hwtid = tid;
+       cxgb4_insert_tid(t, ep, tid);
+
+       ep->snd_seq = be32_to_cpu(req->snd_isn);
+       ep->rcv_seq = be32_to_cpu(req->rcv_isn);
+
+       set_emss(ep, ntohs(req->tcp_opt));
+
+       /* dealloc the atid */
+       cxgb4_free_atid(t, atid);
+
+       /* start MPA negotiation */
+       send_flowc(ep, NULL);
+       send_mpa_req(ep, skb);
+
+       return 0;
+}
+
+static void close_complete_upcall(struct c4iw_ep *ep)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_CLOSE;
+       if (ep->com.cm_id) {
+               PDBG("close complete delivered ep %p cm_id %p tid %u\n",
+                    ep, ep->com.cm_id, ep->hwtid);
+               ep->com.cm_id->event_handler(ep->com.cm_id, &event);
+               ep->com.cm_id->rem_ref(ep->com.cm_id);
+               ep->com.cm_id = NULL;
+               ep->com.qp = NULL;
+       }
+}
+
+static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
+{
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       close_complete_upcall(ep);
+       state_set(&ep->com, ABORTING);
+       return send_abort(ep, skb, gfp);
+}
+
+static void peer_close_upcall(struct c4iw_ep *ep)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_DISCONNECT;
+       if (ep->com.cm_id) {
+               PDBG("peer close delivered ep %p cm_id %p tid %u\n",
+                    ep, ep->com.cm_id, ep->hwtid);
+               ep->com.cm_id->event_handler(ep->com.cm_id, &event);
+       }
+}
+
+static void peer_abort_upcall(struct c4iw_ep *ep)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_CLOSE;
+       event.status = -ECONNRESET;
+       if (ep->com.cm_id) {
+               PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
+                    ep->com.cm_id, ep->hwtid);
+               ep->com.cm_id->event_handler(ep->com.cm_id, &event);
+               ep->com.cm_id->rem_ref(ep->com.cm_id);
+               ep->com.cm_id = NULL;
+               ep->com.qp = NULL;
+       }
+}
+
+static void connect_reply_upcall(struct c4iw_ep *ep, int status)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_CONNECT_REPLY;
+       event.status = status;
+       event.local_addr = ep->com.local_addr;
+       event.remote_addr = ep->com.remote_addr;
+
+       if ((status == 0) || (status == -ECONNREFUSED)) {
+               event.private_data_len = ep->plen;
+               event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
+       }
+       if (ep->com.cm_id) {
+               PDBG("%s ep %p tid %u status %d\n", __func__, ep,
+                    ep->hwtid, status);
+               ep->com.cm_id->event_handler(ep->com.cm_id, &event);
+       }
+       if (status < 0) {
+               ep->com.cm_id->rem_ref(ep->com.cm_id);
+               ep->com.cm_id = NULL;
+               ep->com.qp = NULL;
+       }
+}
+
+static void connect_request_upcall(struct c4iw_ep *ep)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_CONNECT_REQUEST;
+       event.local_addr = ep->com.local_addr;
+       event.remote_addr = ep->com.remote_addr;
+       event.private_data_len = ep->plen;
+       event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
+       event.provider_data = ep;
+       if (state_read(&ep->parent_ep->com) != DEAD) {
+               c4iw_get_ep(&ep->com);
+               ep->parent_ep->com.cm_id->event_handler(
+                                               ep->parent_ep->com.cm_id,
+                                               &event);
+       }
+       c4iw_put_ep(&ep->parent_ep->com);
+       ep->parent_ep = NULL;
+}
+
+static void established_upcall(struct c4iw_ep *ep)
+{
+       struct iw_cm_event event;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       memset(&event, 0, sizeof(event));
+       event.event = IW_CM_EVENT_ESTABLISHED;
+       if (ep->com.cm_id) {
+               PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+               ep->com.cm_id->event_handler(ep->com.cm_id, &event);
+       }
+}
+
+static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
+{
+       struct cpl_rx_data_ack *req;
+       struct sk_buff *skb;
+       int wrlen = roundup(sizeof *req, 16);
+
+       PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
+       skb = get_skb(NULL, wrlen, GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
+               return 0;
+       }
+
+       req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
+       memset(req, 0, wrlen);
+       INIT_TP_WR(req, ep->hwtid);
+       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
+                                                   ep->hwtid));
+       req->credit_dack = cpu_to_be32(credits);
+       set_wr_txq(skb, CPL_PRIORITY_ACK, ep->txq_idx);
+       c4iw_ofld_send(&ep->com.dev->rdev, skb);
+       return credits;
+}
+
+static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
+{
+       struct mpa_message *mpa;
+       u16 plen;
+       struct c4iw_qp_attributes attrs;
+       enum c4iw_qp_attr_mask mask;
+       int err;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+
+       /*
+        * Stop mpa timer.  If it expired, then the state has
+        * changed and we bail since ep_timeout already aborted
+        * the connection.
+        */
+       stop_ep_timer(ep);
+       if (state_read(&ep->com) != MPA_REQ_SENT)
+               return;
+
+       /*
+        * If we get more than the supported amount of private data
+        * then we must fail this connection.
+        */
+       if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
+               err = -EINVAL;
+               goto err;
+       }
+
+       /*
+        * copy the new data into our accumulation buffer.
+        */
+       skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
+                                 skb->len);
+       ep->mpa_pkt_len += skb->len;
+
+       /*
+        * if we don't even have the mpa message, then bail.
+        */
+       if (ep->mpa_pkt_len < sizeof(*mpa))
+               return;
+       mpa = (struct mpa_message *) ep->mpa_pkt;
+
+       /* Validate MPA header. */
+       if (mpa->revision != mpa_rev) {
+               err = -EPROTO;
+               goto err;
+       }
+       if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
+               err = -EPROTO;
+               goto err;
+       }
+
+       plen = ntohs(mpa->private_data_size);
+
+       /*
+        * Fail if there's too much private data.
+        */
+       if (plen > MPA_MAX_PRIVATE_DATA) {
+               err = -EPROTO;
+               goto err;
+       }
+
+       /*
+        * If plen does not account for pkt size
+        */
+       if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
+               err = -EPROTO;
+               goto err;
+       }
+
+       ep->plen = (u8) plen;
+
+       /*
+        * If we don't have all the pdata yet, then bail.
+        * We'll continue process when more data arrives.
+        */
+       if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
+               return;
+
+       if (mpa->flags & MPA_REJECT) {
+               err = -ECONNREFUSED;
+               goto err;
+       }
+
+       /*
+        * If we get here we have accumulated the entire mpa
+        * start reply message including private data. And
+        * the MPA header is valid.
+        */
+       state_set(&ep->com, FPDU_MODE);
+       ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
+       ep->mpa_attr.recv_marker_enabled = markers_enabled;
+       ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
+       ep->mpa_attr.version = mpa_rev;
+       ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
+                                           FW_RI_INIT_P2PTYPE_DISABLED;
+       PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
+            "xmit_marker_enabled=%d, version=%d\n", __func__,
+            ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
+            ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
+
+       attrs.mpa_attr = ep->mpa_attr;
+       attrs.max_ird = ep->ird;
+       attrs.max_ord = ep->ord;
+       attrs.llp_stream_handle = ep;
+       attrs.next_state = C4IW_QP_STATE_RTS;
+
+       mask = C4IW_QP_ATTR_NEXT_STATE |
+           C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
+           C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
+
+       /* bind QP and TID with INIT_WR */
+       err = c4iw_modify_qp(ep->com.qp->rhp,
+                            ep->com.qp, mask, &attrs, 1);
+       if (err)
+               goto err;
+       goto out;
+err:
+       abort_connection(ep, skb, GFP_KERNEL);
+out:
+       connect_reply_upcall(ep, err);
+       return;
+}
+
+static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
+{
+       struct mpa_message *mpa;
+       u16 plen;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+
+       if (state_read(&ep->com) != MPA_REQ_WAIT)
+               return;
+
+       /*
+        * If we get more than the supported amount of private data
+        * then we must fail this connection.
+        */
+       if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
+               stop_ep_timer(ep);
+               abort_connection(ep, skb, GFP_KERNEL);
+               return;
+       }
+
+       PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
+
+       /*
+        * Copy the new data into our accumulation buffer.
+        */
+       skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
+                                 skb->len);
+       ep->mpa_pkt_len += skb->len;
+
+       /*
+        * If we don't even have the mpa message, then bail.
+        * We'll continue process when more data arrives.
+        */
+       if (ep->mpa_pkt_len < sizeof(*mpa))
+               return;
+
+       PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
+       stop_ep_timer(ep);
+       mpa = (struct mpa_message *) ep->mpa_pkt;
+
+       /*
+        * Validate MPA Header.
+        */
+       if (mpa->revision != mpa_rev) {
+               abort_connection(ep, skb, GFP_KERNEL);
+               return;
+       }
+
+       if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
+               abort_connection(ep, skb, GFP_KERNEL);
+               return;
+       }
+
+       plen = ntohs(mpa->private_data_size);
+
+       /*
+        * Fail if there's too much private data.
+        */
+       if (plen > MPA_MAX_PRIVATE_DATA) {
+               abort_connection(ep, skb, GFP_KERNEL);
+               return;
+       }
+
+       /*
+        * If plen does not account for pkt size
+        */
+       if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
+               abort_connection(ep, skb, GFP_KERNEL);
+               return;
+       }
+       ep->plen = (u8) plen;
+
+       /*
+        * If we don't have all the pdata yet, then bail.
+        */
+       if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
+               return;
+
+       /*
+        * If we get here we have accumulated the entire mpa
+        * start reply message including private data.
+        */
+       ep->mpa_attr.initiator = 0;
+       ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
+       ep->mpa_attr.recv_marker_enabled = markers_enabled;
+       ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
+       ep->mpa_attr.version = mpa_rev;
+       ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
+                                           FW_RI_INIT_P2PTYPE_DISABLED;
+       PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
+            "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
+            ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
+            ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
+            ep->mpa_attr.p2p_type);
+
+       state_set(&ep->com, MPA_REQ_RCVD);
+
+       /* drive upcall */
+       connect_request_upcall(ep);
+       return;
+}
+
+static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_rx_data *hdr = cplhdr(skb);
+       unsigned int dlen = ntohs(hdr->len);
+       unsigned int tid = GET_TID(hdr);
+       struct tid_info *t = dev->rdev.lldi.tids;
+
+       ep = lookup_tid(t, tid);
+       PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
+       skb_pull(skb, sizeof(*hdr));
+       skb_trim(skb, dlen);
+
+       ep->rcv_seq += dlen;
+       BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
+
+       /* update RX credits */
+       update_rx_credits(ep, dlen);
+
+       switch (state_read(&ep->com)) {
+       case MPA_REQ_SENT:
+               process_mpa_reply(ep, skb);
+               break;
+       case MPA_REQ_WAIT:
+               process_mpa_request(ep, skb);
+               break;
+       case MPA_REP_SENT:
+               break;
+       default:
+               printk(KERN_ERR MOD "%s Unexpected streaming data."
+                      " ep %p state %d tid %u\n",
+                      __func__, ep, state_read(&ep->com), ep->hwtid);
+
+               /*
+                * The ep will timeout and inform the ULP of the failure.
+                * See ep_timeout().
+                */
+               break;
+       }
+       return 0;
+}
+
+static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
+       unsigned long flags;
+       int release = 0;
+       unsigned int tid = GET_TID(rpl);
+       struct tid_info *t = dev->rdev.lldi.tids;
+
+       ep = lookup_tid(t, tid);
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       BUG_ON(!ep);
+       spin_lock_irqsave(&ep->com.lock, flags);
+       switch (ep->com.state) {
+       case ABORTING:
+               __state_set(&ep->com, DEAD);
+               release = 1;
+               break;
+       default:
+               printk(KERN_ERR "%s ep %p state %d\n",
+                    __func__, ep, ep->com.state);
+               break;
+       }
+       spin_unlock_irqrestore(&ep->com.lock, flags);
+
+       if (release)
+               release_ep_resources(ep);
+       return 0;
+}
+
+/*
+ * Return whether a failed active open has allocated a TID
+ */
+static inline int act_open_has_tid(int status)
+{
+       return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
+              status != CPL_ERR_ARP_MISS;
+}
+
+static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_act_open_rpl *rpl = cplhdr(skb);
+       unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
+                                       ntohl(rpl->atid_status)));
+       struct tid_info *t = dev->rdev.lldi.tids;
+       int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
+
+       ep = lookup_atid(t, atid);
+
+       PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
+            status, status2errno(status));
+
+       if (status == CPL_ERR_RTX_NEG_ADVICE) {
+               printk(KERN_WARNING MOD "Connection problems for atid %u\n",
+                       atid);
+               return 0;
+       }
+
+       connect_reply_upcall(ep, status2errno(status));
+       state_set(&ep->com, DEAD);
+
+       if (status && act_open_has_tid(status))
+               cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
+
+       cxgb4_free_atid(t, atid);
+       dst_release(ep->dst);
+       cxgb4_l2t_release(ep->l2t);
+       c4iw_put_ep(&ep->com);
+
+       return 0;
+}
+
+static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_pass_open_rpl *rpl = cplhdr(skb);
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int stid = GET_TID(rpl);
+       struct c4iw_listen_ep *ep = lookup_stid(t, stid);
+
+       if (!ep) {
+               printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
+               return 0;
+       }
+       PDBG("%s ep %p status %d error %d\n", __func__, ep,
+            rpl->status, status2errno(rpl->status));
+       ep->com.rpl_err = status2errno(rpl->status);
+       ep->com.rpl_done = 1;
+       wake_up(&ep->com.waitq);
+
+       return 0;
+}
+
+static int listen_stop(struct c4iw_listen_ep *ep)
+{
+       struct sk_buff *skb;
+       struct cpl_close_listsvr_req *req;
+
+       PDBG("%s ep %p\n", __func__, ep);
+       skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
+               return -ENOMEM;
+       }
+       req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
+       INIT_TP_WR(req, 0);
+       OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
+                                                   ep->stid));
+       req->reply_ctrl = cpu_to_be16(
+                         QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
+       set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
+       return c4iw_ofld_send(&ep->com.dev->rdev, skb);
+}
+
+static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int stid = GET_TID(rpl);
+       struct c4iw_listen_ep *ep = lookup_stid(t, stid);
+
+       PDBG("%s ep %p\n", __func__, ep);
+       ep->com.rpl_err = status2errno(rpl->status);
+       ep->com.rpl_done = 1;
+       wake_up(&ep->com.waitq);
+       return 0;
+}
+
+static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
+                     struct cpl_pass_accept_req *req)
+{
+       struct cpl_pass_accept_rpl *rpl;
+       unsigned int mtu_idx;
+       u64 opt0;
+       u32 opt2;
+       int wscale;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       BUG_ON(skb_cloned(skb));
+       skb_trim(skb, sizeof(*rpl));
+       skb_get(skb);
+       cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
+       wscale = compute_wscale(rcv_win);
+       opt0 = KEEP_ALIVE(1) |
+              WND_SCALE(wscale) |
+              MSS_IDX(mtu_idx) |
+              L2T_IDX(ep->l2t->idx) |
+              TX_CHAN(ep->tx_chan) |
+              SMAC_SEL(ep->smac_idx) |
+              DSCP(ep->tos) |
+              RCV_BUFSIZ(rcv_win>>10);
+       opt2 = RX_CHANNEL(0) |
+              RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
+
+       if (enable_tcp_timestamps && req->tcpopt.tstamp)
+               opt2 |= TSTAMPS_EN(1);
+       if (enable_tcp_sack && req->tcpopt.sack)
+               opt2 |= SACK_EN(1);
+       if (wscale && enable_tcp_window_scaling)
+               opt2 |= WND_SCALE_EN(1);
+
+       rpl = cplhdr(skb);
+       INIT_TP_WR(rpl, ep->hwtid);
+       OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
+                                     ep->hwtid));
+       rpl->opt0 = cpu_to_be64(opt0);
+       rpl->opt2 = cpu_to_be32(opt2);
+       set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->txq_idx);
+       c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
+
+       return;
+}
+
+static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
+                     struct sk_buff *skb)
+{
+       PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
+            peer_ip);
+       BUG_ON(skb_cloned(skb));
+       skb_trim(skb, sizeof(struct cpl_tid_release));
+       skb_get(skb);
+       release_tid(&dev->rdev, hwtid, skb);
+       return;
+}
+
+static void get_4tuple(struct cpl_pass_accept_req *req,
+                      __be32 *local_ip, __be32 *peer_ip,
+                      __be16 *local_port, __be16 *peer_port)
+{
+       int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
+       int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
+       struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
+       struct tcphdr *tcp = (struct tcphdr *)
+                            ((u8 *)(req + 1) + eth_len + ip_len);
+
+       PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
+            ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
+            ntohs(tcp->dest));
+
+       *peer_ip = ip->saddr;
+       *local_ip = ip->daddr;
+       *peer_port = tcp->source;
+       *local_port = tcp->dest;
+
+       return;
+}
+
+static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *child_ep, *parent_ep;
+       struct cpl_pass_accept_req *req = cplhdr(skb);
+       unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int hwtid = GET_TID(req);
+       struct dst_entry *dst;
+       struct l2t_entry *l2t;
+       struct rtable *rt;
+       __be32 local_ip, peer_ip;
+       __be16 local_port, peer_port;
+       struct net_device *pdev;
+       u32 tx_chan, smac_idx;
+       u16 rss_qid;
+       u32 mtu;
+       int step;
+       int txq_idx;
+
+       parent_ep = lookup_stid(t, stid);
+       PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
+
+       get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
+
+       if (state_read(&parent_ep->com) != LISTEN) {
+               printk(KERN_ERR "%s - listening ep not in LISTEN\n",
+                      __func__);
+               goto reject;
+       }
+
+       /* Find output route */
+       rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
+                       GET_POPEN_TOS(ntohl(req->tos_stid)));
+       if (!rt) {
+               printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
+                      __func__);
+               goto reject;
+       }
+       dst = &rt->u.dst;
+       if (dst->neighbour->dev->flags & IFF_LOOPBACK) {
+               pdev = ip_dev_find(&init_net, peer_ip);
+               BUG_ON(!pdev);
+               l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
+                                   pdev, 0);
+               mtu = pdev->mtu;
+               tx_chan = cxgb4_port_chan(pdev);
+               smac_idx = tx_chan << 1;
+               step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
+               txq_idx = cxgb4_port_idx(pdev) * step;
+               step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
+               rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
+               dev_put(pdev);
+       } else {
+               l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
+                                       dst->neighbour->dev, 0);
+               mtu = dst_mtu(dst);
+               tx_chan = cxgb4_port_chan(dst->neighbour->dev);
+               smac_idx = tx_chan << 1;
+               step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
+               txq_idx = cxgb4_port_idx(dst->neighbour->dev) * step;
+               step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
+               rss_qid = dev->rdev.lldi.rxq_ids[
+                         cxgb4_port_idx(dst->neighbour->dev) * step];
+       }
+       if (!l2t) {
+               printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
+                      __func__);
+               dst_release(dst);
+               goto reject;
+       }
+
+       child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
+       if (!child_ep) {
+               printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
+                      __func__);
+               cxgb4_l2t_release(l2t);
+               dst_release(dst);
+               goto reject;
+       }
+       state_set(&child_ep->com, CONNECTING);
+       child_ep->com.dev = dev;
+       child_ep->com.cm_id = NULL;
+       child_ep->com.local_addr.sin_family = PF_INET;
+       child_ep->com.local_addr.sin_port = local_port;
+       child_ep->com.local_addr.sin_addr.s_addr = local_ip;
+       child_ep->com.remote_addr.sin_family = PF_INET;
+       child_ep->com.remote_addr.sin_port = peer_port;
+       child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
+       c4iw_get_ep(&parent_ep->com);
+       child_ep->parent_ep = parent_ep;
+       child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
+       child_ep->l2t = l2t;
+       child_ep->dst = dst;
+       child_ep->hwtid = hwtid;
+       child_ep->tx_chan = tx_chan;
+       child_ep->smac_idx = smac_idx;
+       child_ep->rss_qid = rss_qid;
+       child_ep->mtu = mtu;
+       child_ep->txq_idx = txq_idx;
+
+       PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
+            tx_chan, smac_idx, rss_qid);
+
+       init_timer(&child_ep->timer);
+       cxgb4_insert_tid(t, child_ep, hwtid);
+       accept_cr(child_ep, peer_ip, skb, req);
+       goto out;
+reject:
+       reject_cr(dev, hwtid, peer_ip, skb);
+out:
+       return 0;
+}
+
+static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_pass_establish *req = cplhdr(skb);
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int tid = GET_TID(req);
+
+       ep = lookup_tid(t, tid);
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       ep->snd_seq = be32_to_cpu(req->snd_isn);
+       ep->rcv_seq = be32_to_cpu(req->rcv_isn);
+
+       set_emss(ep, ntohs(req->tcp_opt));
+
+       dst_confirm(ep->dst);
+       state_set(&ep->com, MPA_REQ_WAIT);
+       start_ep_timer(ep);
+       send_flowc(ep, skb);
+
+       return 0;
+}
+
+static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_peer_close *hdr = cplhdr(skb);
+       struct c4iw_ep *ep;
+       struct c4iw_qp_attributes attrs;
+       unsigned long flags;
+       int disconnect = 1;
+       int release = 0;
+       int closing = 0;
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int tid = GET_TID(hdr);
+       int start_timer = 0;
+       int stop_timer = 0;
+
+       ep = lookup_tid(t, tid);
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       dst_confirm(ep->dst);
+
+       spin_lock_irqsave(&ep->com.lock, flags);
+       switch (ep->com.state) {
+       case MPA_REQ_WAIT:
+               __state_set(&ep->com, CLOSING);
+               break;
+       case MPA_REQ_SENT:
+               __state_set(&ep->com, CLOSING);
+               connect_reply_upcall(ep, -ECONNRESET);
+               break;
+       case MPA_REQ_RCVD:
+
+               /*
+                * We're gonna mark this puppy DEAD, but keep
+                * the reference on it until the ULP accepts or
+                * rejects the CR. Also wake up anyone waiting
+                * in rdma connection migration (see c4iw_accept_cr()).
+                */
+               __state_set(&ep->com, CLOSING);
+               ep->com.rpl_done = 1;
+               ep->com.rpl_err = -ECONNRESET;
+               PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
+               wake_up(&ep->com.waitq);
+               break;
+       case MPA_REP_SENT:
+               __state_set(&ep->com, CLOSING);
+               ep->com.rpl_done = 1;
+               ep->com.rpl_err = -ECONNRESET;
+               PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
+               wake_up(&ep->com.waitq);
+               break;
+       case FPDU_MODE:
+               start_timer = 1;
+               __state_set(&ep->com, CLOSING);
+               closing = 1;
+               peer_close_upcall(ep);
+               break;
+       case ABORTING:
+               disconnect = 0;
+               break;
+       case CLOSING:
+               __state_set(&ep->com, MORIBUND);
+               disconnect = 0;
+               break;
+       case MORIBUND:
+               stop_timer = 1;
+               if (ep->com.cm_id && ep->com.qp) {
+                       attrs.next_state = C4IW_QP_STATE_IDLE;
+                       c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
+                                      C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
+               }
+               close_complete_upcall(ep);
+               __state_set(&ep->com, DEAD);
+               release = 1;
+               disconnect = 0;
+               break;
+       case DEAD:
+               disconnect = 0;
+               break;
+       default:
+               BUG_ON(1);
+       }
+       spin_unlock_irqrestore(&ep->com.lock, flags);
+       if (closing) {
+               attrs.next_state = C4IW_QP_STATE_CLOSING;
+               c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
+                              C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
+       }
+       if (start_timer)
+               start_ep_timer(ep);
+       if (stop_timer)
+               stop_ep_timer(ep);
+       if (disconnect)
+               c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
+       if (release)
+               release_ep_resources(ep);
+       return 0;
+}
+
+/*
+ * Returns whether an ABORT_REQ_RSS message is a negative advice.
+ */
+static int is_neg_adv_abort(unsigned int status)
+{
+       return status == CPL_ERR_RTX_NEG_ADVICE ||
+              status == CPL_ERR_PERSIST_NEG_ADVICE;
+}
+
+static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_abort_req_rss *req = cplhdr(skb);
+       struct c4iw_ep *ep;
+       struct cpl_abort_rpl *rpl;
+       struct sk_buff *rpl_skb;
+       struct c4iw_qp_attributes attrs;
+       int ret;
+       int release = 0;
+       unsigned long flags;
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int tid = GET_TID(req);
+       int stop_timer = 0;
+
+       ep = lookup_tid(t, tid);
+       if (is_neg_adv_abort(req->status)) {
+               PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
+                    ep->hwtid);
+               return 0;
+       }
+       spin_lock_irqsave(&ep->com.lock, flags);
+       PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
+            ep->com.state);
+       switch (ep->com.state) {
+       case CONNECTING:
+               break;
+       case MPA_REQ_WAIT:
+               stop_timer = 1;
+               break;
+       case MPA_REQ_SENT:
+               stop_timer = 1;
+               connect_reply_upcall(ep, -ECONNRESET);
+               break;
+       case MPA_REP_SENT:
+               ep->com.rpl_done = 1;
+               ep->com.rpl_err = -ECONNRESET;
+               PDBG("waking up ep %p\n", ep);
+               wake_up(&ep->com.waitq);
+               break;
+       case MPA_REQ_RCVD:
+
+               /*
+                * We're gonna mark this puppy DEAD, but keep
+                * the reference on it until the ULP accepts or
+                * rejects the CR. Also wake up anyone waiting
+                * in rdma connection migration (see c4iw_accept_cr()).
+                */
+               ep->com.rpl_done = 1;
+               ep->com.rpl_err = -ECONNRESET;
+               PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
+               wake_up(&ep->com.waitq);
+               break;
+       case MORIBUND:
+       case CLOSING:
+               stop_timer = 1;
+               /*FALLTHROUGH*/
+       case FPDU_MODE:
+               if (ep->com.cm_id && ep->com.qp) {
+                       attrs.next_state = C4IW_QP_STATE_ERROR;
+                       ret = c4iw_modify_qp(ep->com.qp->rhp,
+                                    ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
+                                    &attrs, 1);
+                       if (ret)
+                               printk(KERN_ERR MOD
+                                      "%s - qp <- error failed!\n",
+                                      __func__);
+               }
+               peer_abort_upcall(ep);
+               break;
+       case ABORTING:
+               break;
+       case DEAD:
+               PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
+               spin_unlock_irqrestore(&ep->com.lock, flags);
+               return 0;
+       default:
+               BUG_ON(1);
+               break;
+       }
+       dst_confirm(ep->dst);
+       if (ep->com.state != ABORTING) {
+               __state_set(&ep->com, DEAD);
+               release = 1;
+       }
+       spin_unlock_irqrestore(&ep->com.lock, flags);
+
+       rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
+       if (!rpl_skb) {
+               printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
+                      __func__);
+               release = 1;
+               goto out;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
+       rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
+       INIT_TP_WR(rpl, ep->hwtid);
+       OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
+       rpl->cmd = CPL_ABORT_NO_RST;
+       c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
+out:
+       if (stop_timer)
+               stop_ep_timer(ep);
+       if (release)
+               release_ep_resources(ep);
+       return 0;
+}
+
+static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct c4iw_qp_attributes attrs;
+       struct cpl_close_con_rpl *rpl = cplhdr(skb);
+       unsigned long flags;
+       int release = 0;
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int tid = GET_TID(rpl);
+       int stop_timer = 0;
+
+       ep = lookup_tid(t, tid);
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       BUG_ON(!ep);
+
+       /* The cm_id may be null if we failed to connect */
+       spin_lock_irqsave(&ep->com.lock, flags);
+       switch (ep->com.state) {
+       case CLOSING:
+               __state_set(&ep->com, MORIBUND);
+               break;
+       case MORIBUND:
+               stop_timer = 1;
+               if ((ep->com.cm_id) && (ep->com.qp)) {
+                       attrs.next_state = C4IW_QP_STATE_IDLE;
+                       c4iw_modify_qp(ep->com.qp->rhp,
+                                            ep->com.qp,
+                                            C4IW_QP_ATTR_NEXT_STATE,
+                                            &attrs, 1);
+               }
+               close_complete_upcall(ep);
+               __state_set(&ep->com, DEAD);
+               release = 1;
+               break;
+       case ABORTING:
+       case DEAD:
+               break;
+       default:
+               BUG_ON(1);
+               break;
+       }
+       spin_unlock_irqrestore(&ep->com.lock, flags);
+       if (stop_timer)
+               stop_ep_timer(ep);
+       if (release)
+               release_ep_resources(ep);
+       return 0;
+}
+
+static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_rdma_terminate *term = cplhdr(skb);
+       struct tid_info *t = dev->rdev.lldi.tids;
+       unsigned int tid = GET_TID(term);
+
+       ep = lookup_tid(t, tid);
+
+       if (state_read(&ep->com) != FPDU_MODE)
+               return 0;
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       skb_pull(skb, sizeof *term);
+       PDBG("%s saving %d bytes of term msg\n", __func__, skb->len);
+       skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
+                                 skb->len);
+       ep->com.qp->attr.terminate_msg_len = skb->len;
+       ep->com.qp->attr.is_terminate_local = 0;
+       return 0;
+}
+
+/*
+ * Upcall from the adapter indicating data has been transmitted.
+ * For us its just the single MPA request or reply.  We can now free
+ * the skb holding the mpa message.
+ */
+static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct c4iw_ep *ep;
+       struct cpl_fw4_ack *hdr = cplhdr(skb);
+       u8 credits = hdr->credits;
+       unsigned int tid = GET_TID(hdr);
+       struct tid_info *t = dev->rdev.lldi.tids;
+
+
+       ep = lookup_tid(t, tid);
+       PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
+       if (credits == 0) {
+               PDBG(KERN_ERR "%s 0 credit ack ep %p tid %u state %u\n",
+                       __func__, ep, ep->hwtid, state_read(&ep->com));
+               return 0;
+       }
+
+       dst_confirm(ep->dst);
+       if (ep->mpa_skb) {
+               PDBG("%s last streaming msg ack ep %p tid %u state %u "
+                    "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
+                    state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
+               kfree_skb(ep->mpa_skb);
+               ep->mpa_skb = NULL;
+       }
+       return 0;
+}
+
+int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
+{
+       int err;
+       struct c4iw_ep *ep = to_ep(cm_id);
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+
+       if (state_read(&ep->com) == DEAD) {
+               c4iw_put_ep(&ep->com);
+               return -ECONNRESET;
+       }
+       BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
+       if (mpa_rev == 0)
+               abort_connection(ep, NULL, GFP_KERNEL);
+       else {
+               err = send_mpa_reject(ep, pdata, pdata_len);
+               err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
+       }
+       c4iw_put_ep(&ep->com);
+       return 0;
+}
+
+int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
+{
+       int err;
+       struct c4iw_qp_attributes attrs;
+       enum c4iw_qp_attr_mask mask;
+       struct c4iw_ep *ep = to_ep(cm_id);
+       struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
+       struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
+
+       PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
+       if (state_read(&ep->com) == DEAD) {
+               err = -ECONNRESET;
+               goto err;
+       }
+
+       BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
+       BUG_ON(!qp);
+
+       if ((conn_param->ord > c4iw_max_read_depth) ||
+           (conn_param->ird > c4iw_max_read_depth)) {
+               abort_connection(ep, NULL, GFP_KERNEL);
+               err = -EINVAL;
+               goto err;
+       }
+
+       cm_id->add_ref(cm_id);
+       ep->com.cm_id = cm_id;
+       ep->com.qp = qp;
+
+       ep->ird = conn_param->ird;
+       ep->ord = conn_param->ord;
+
+       if (peer2peer && ep->ird == 0)
+               ep->ird = 1;
+
+       PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
+
+       /* bind QP to EP and move to RTS */
+       attrs.mpa_attr = ep->mpa_attr;
+       attrs.max_ird = ep->ird;
+       attrs.max_ord = ep->ord;
+       attrs.llp_stream_handle = ep;
+       attrs.next_state = C4IW_QP_STATE_RTS;
+
+       /* bind QP and TID with INIT_WR */
+       mask = C4IW_QP_ATTR_NEXT_STATE |
+                            C4IW_QP_ATTR_LLP_STREAM_HANDLE |
+                            C4IW_QP_ATTR_MPA_ATTR |
+                            C4IW_QP_ATTR_MAX_IRD |
+                            C4IW_QP_ATTR_MAX_ORD;
+
+       err = c4iw_modify_qp(ep->com.qp->rhp,
+                            ep->com.qp, mask, &attrs, 1);
+       if (err)
+               goto err1;
+       err = send_mpa_reply(ep, conn_param->private_data,
+                            conn_param->private_data_len);
+       if (err)
+               goto err1;
+
+       state_set(&ep->com, FPDU_MODE);
+       established_upcall(ep);
+       c4iw_put_ep(&ep->com);
+       return 0;
+err1:
+       ep->com.cm_id = NULL;
+       ep->com.qp = NULL;
+       cm_id->rem_ref(cm_id);
+err:
+       c4iw_put_ep(&ep->com);
+       return err;
+}
+
+int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
+{
+       int err = 0;
+       struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
+       struct c4iw_ep *ep;
+       struct rtable *rt;
+       struct net_device *pdev;
+       int step;
+
+       if ((conn_param->ord > c4iw_max_read_depth) ||
+           (conn_param->ird > c4iw_max_read_depth)) {
+               err = -EINVAL;
+               goto out;
+       }
+       ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
+       if (!ep) {
+               printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
+               err = -ENOMEM;
+               goto out;
+       }
+       init_timer(&ep->timer);
+       ep->plen = conn_param->private_data_len;
+       if (ep->plen)
+               memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
+                      conn_param->private_data, ep->plen);
+       ep->ird = conn_param->ird;
+       ep->ord = conn_param->ord;
+
+       if (peer2peer && ep->ord == 0)
+               ep->ord = 1;
+
+       cm_id->add_ref(cm_id);
+       ep->com.dev = dev;
+       ep->com.cm_id = cm_id;
+       ep->com.qp = get_qhp(dev, conn_param->qpn);
+       BUG_ON(!ep->com.qp);
+       PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
+            ep->com.qp, cm_id);
+
+       /*
+        * Allocate an active TID to initiate a TCP connection.
+        */
+       ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
+       if (ep->atid == -1) {
+               printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
+               err = -ENOMEM;
+               goto fail2;
+       }
+
+       PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
+            ntohl(cm_id->local_addr.sin_addr.s_addr),
+            ntohs(cm_id->local_addr.sin_port),
+            ntohl(cm_id->remote_addr.sin_addr.s_addr),
+            ntohs(cm_id->remote_addr.sin_port));
+
+       /* find a route */
+       rt = find_route(dev,
+                       cm_id->local_addr.sin_addr.s_addr,
+                       cm_id->remote_addr.sin_addr.s_addr,
+                       cm_id->local_addr.sin_port,
+                       cm_id->remote_addr.sin_port, 0);
+       if (!rt) {
+               printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
+               err = -EHOSTUNREACH;
+               goto fail3;
+       }
+       ep->dst = &rt->u.dst;
+
+       /* get a l2t entry */
+       if (ep->dst->neighbour->dev->flags & IFF_LOOPBACK) {
+               PDBG("%s LOOPBACK\n", __func__);
+               pdev = ip_dev_find(&init_net,
+                                  cm_id->remote_addr.sin_addr.s_addr);
+               ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
+                                       ep->dst->neighbour,
+                                       pdev, 0);
+               ep->mtu = pdev->mtu;
+               ep->tx_chan = cxgb4_port_chan(pdev);
+               ep->smac_idx = ep->tx_chan << 1;
+               step = ep->com.dev->rdev.lldi.ntxq /
+                      ep->com.dev->rdev.lldi.nchan;
+               ep->txq_idx = cxgb4_port_idx(pdev) * step;
+               step = ep->com.dev->rdev.lldi.nrxq /
+                      ep->com.dev->rdev.lldi.nchan;
+               ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
+                             cxgb4_port_idx(pdev) * step];
+               dev_put(pdev);
+       } else {
+               ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
+                                       ep->dst->neighbour,
+                                       ep->dst->neighbour->dev, 0);
+               ep->mtu = dst_mtu(ep->dst);
+               ep->tx_chan = cxgb4_port_chan(ep->dst->neighbour->dev);
+               ep->smac_idx = ep->tx_chan << 1;
+               step = ep->com.dev->rdev.lldi.ntxq /
+                      ep->com.dev->rdev.lldi.nchan;
+               ep->txq_idx = cxgb4_port_idx(ep->dst->neighbour->dev) * step;
+               step = ep->com.dev->rdev.lldi.nrxq /
+                      ep->com.dev->rdev.lldi.nchan;
+               ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
+                             cxgb4_port_idx(ep->dst->neighbour->dev) * step];
+       }
+       if (!ep->l2t) {
+               printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
+               err = -ENOMEM;
+               goto fail4;
+       }
+
+       PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
+               __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
+               ep->l2t->idx);
+
+       state_set(&ep->com, CONNECTING);
+       ep->tos = 0;
+       ep->com.local_addr = cm_id->local_addr;
+       ep->com.remote_addr = cm_id->remote_addr;
+
+       /* send connect request to rnic */
+       err = send_connect(ep);
+       if (!err)
+               goto out;
+
+       cxgb4_l2t_release(ep->l2t);
+fail4:
+       dst_release(ep->dst);
+fail3:
+       cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
+fail2:
+       cm_id->rem_ref(cm_id);
+       c4iw_put_ep(&ep->com);
+out:
+       return err;
+}
+
+int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
+{
+       int err = 0;
+       struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
+       struct c4iw_listen_ep *ep;
+
+
+       might_sleep();
+
+       ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
+       if (!ep) {
+               printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
+               err = -ENOMEM;
+               goto fail1;
+       }
+       PDBG("%s ep %p\n", __func__, ep);
+       cm_id->add_ref(cm_id);
+       ep->com.cm_id = cm_id;
+       ep->com.dev = dev;
+       ep->backlog = backlog;
+       ep->com.local_addr = cm_id->local_addr;
+
+       /*
+        * Allocate a server TID.
+        */
+       ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
+       if (ep->stid == -1) {
+               printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
+               err = -ENOMEM;
+               goto fail2;
+       }
+
+       state_set(&ep->com, LISTEN);
+       err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
+                                 ep->com.local_addr.sin_addr.s_addr,
+                                 ep->com.local_addr.sin_port,
+                                 ep->com.dev->rdev.lldi.rxq_ids[0]);
+       if (err)
+               goto fail3;
+
+       /* wait for pass_open_rpl */
+       wait_event(ep->com.waitq, ep->com.rpl_done);
+       err = ep->com.rpl_err;
+       if (!err) {
+               cm_id->provider_data = ep;
+               goto out;
+       }
+fail3:
+       cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
+fail2:
+       cm_id->rem_ref(cm_id);
+       c4iw_put_ep(&ep->com);
+fail1:
+out:
+       return err;
+}
+
+int c4iw_destroy_listen(struct iw_cm_id *cm_id)
+{
+       int err;
+       struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
+
+       PDBG("%s ep %p\n", __func__, ep);
+
+       might_sleep();
+       state_set(&ep->com, DEAD);
+       ep->com.rpl_done = 0;
+       ep->com.rpl_err = 0;
+       err = listen_stop(ep);
+       if (err)
+               goto done;
+       wait_event(ep->com.waitq, ep->com.rpl_done);
+       cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
+done:
+       err = ep->com.rpl_err;
+       cm_id->rem_ref(cm_id);
+       c4iw_put_ep(&ep->com);
+       return err;
+}
+
+int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
+{
+       int ret = 0;
+       unsigned long flags;
+       int close = 0;
+       int fatal = 0;
+       struct c4iw_rdev *rdev;
+       int start_timer = 0;
+       int stop_timer = 0;
+
+       spin_lock_irqsave(&ep->com.lock, flags);
+
+       PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
+            states[ep->com.state], abrupt);
+
+       rdev = &ep->com.dev->rdev;
+       if (c4iw_fatal_error(rdev)) {
+               fatal = 1;
+               close_complete_upcall(ep);
+               ep->com.state = DEAD;
+       }
+       switch (ep->com.state) {
+       case MPA_REQ_WAIT:
+       case MPA_REQ_SENT:
+       case MPA_REQ_RCVD:
+       case MPA_REP_SENT:
+       case FPDU_MODE:
+               close = 1;
+               if (abrupt)
+                       ep->com.state = ABORTING;
+               else {
+                       ep->com.state = CLOSING;
+                       start_timer = 1;
+               }
+               set_bit(CLOSE_SENT, &ep->com.flags);
+               break;
+       case CLOSING:
+               if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
+                       close = 1;
+                       if (abrupt) {
+                               stop_timer = 1;
+                               ep->com.state = ABORTING;
+                       } else
+                               ep->com.state = MORIBUND;
+               }
+               break;
+       case MORIBUND:
+       case ABORTING:
+       case DEAD:
+               PDBG("%s ignoring disconnect ep %p state %u\n",
+                    __func__, ep, ep->com.state);
+               break;
+       default:
+               BUG();
+               break;
+       }
+
+       spin_unlock_irqrestore(&ep->com.lock, flags);
+       if (start_timer)
+               start_ep_timer(ep);
+       if (stop_timer)
+               stop_ep_timer(ep);
+       if (close) {
+               if (abrupt)
+                       ret = abort_connection(ep, NULL, gfp);
+               else
+                       ret = send_halfclose(ep, gfp);
+               if (ret)
+                       fatal = 1;
+       }
+       if (fatal)
+               release_ep_resources(ep);
+       return ret;
+}
+
+/*
+ * These are the real handlers that are called from a
+ * work queue.
+ */
+static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
+       [CPL_ACT_ESTABLISH] = act_establish,
+       [CPL_ACT_OPEN_RPL] = act_open_rpl,
+       [CPL_RX_DATA] = rx_data,
+       [CPL_ABORT_RPL_RSS] = abort_rpl,
+       [CPL_ABORT_RPL] = abort_rpl,
+       [CPL_PASS_OPEN_RPL] = pass_open_rpl,
+       [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
+       [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
+       [CPL_PASS_ESTABLISH] = pass_establish,
+       [CPL_PEER_CLOSE] = peer_close,
+       [CPL_ABORT_REQ_RSS] = peer_abort,
+       [CPL_CLOSE_CON_RPL] = close_con_rpl,
+       [CPL_RDMA_TERMINATE] = terminate,
+       [CPL_FW4_ACK] = fw4_ack
+};
+
+static void process_timeout(struct c4iw_ep *ep)
+{
+       struct c4iw_qp_attributes attrs;
+       int abort = 1;
+
+       spin_lock_irq(&ep->com.lock);
+       PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
+            ep->com.state);
+       switch (ep->com.state) {
+       case MPA_REQ_SENT:
+               __state_set(&ep->com, ABORTING);
+               connect_reply_upcall(ep, -ETIMEDOUT);
+               break;
+       case MPA_REQ_WAIT:
+               __state_set(&ep->com, ABORTING);
+               break;
+       case CLOSING:
+       case MORIBUND:
+               if (ep->com.cm_id && ep->com.qp) {
+                       attrs.next_state = C4IW_QP_STATE_ERROR;
+                       c4iw_modify_qp(ep->com.qp->rhp,
+                                    ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
+                                    &attrs, 1);
+               }
+               __state_set(&ep->com, ABORTING);
+               break;
+       default:
+               printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
+                       __func__, ep, ep->hwtid, ep->com.state);
+               WARN_ON(1);
+               abort = 0;
+       }
+       spin_unlock_irq(&ep->com.lock);
+       if (abort)
+               abort_connection(ep, NULL, GFP_KERNEL);
+       c4iw_put_ep(&ep->com);
+}
+
+static void process_timedout_eps(void)
+{
+       struct c4iw_ep *ep;
+
+       spin_lock_irq(&timeout_lock);
+       while (!list_empty(&timeout_list)) {
+               struct list_head *tmp;
+
+               tmp = timeout_list.next;
+               list_del(tmp);
+               spin_unlock_irq(&timeout_lock);
+               ep = list_entry(tmp, struct c4iw_ep, entry);
+               process_timeout(ep);
+               spin_lock_irq(&timeout_lock);
+       }
+       spin_unlock_irq(&timeout_lock);
+}
+
+static void process_work(struct work_struct *work)
+{
+       struct sk_buff *skb = NULL;
+       struct c4iw_dev *dev;
+       struct cpl_act_establish *rpl = cplhdr(skb);
+       unsigned int opcode;
+       int ret;
+
+       while ((skb = skb_dequeue(&rxq))) {
+               rpl = cplhdr(skb);
+               dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
+               opcode = rpl->ot.opcode;
+
+               BUG_ON(!work_handlers[opcode]);
+               ret = work_handlers[opcode](dev, skb);
+               if (!ret)
+                       kfree_skb(skb);
+       }
+       process_timedout_eps();
+}
+
+static DECLARE_WORK(skb_work, process_work);
+
+static void ep_timeout(unsigned long arg)
+{
+       struct c4iw_ep *ep = (struct c4iw_ep *)arg;
+
+       spin_lock(&timeout_lock);
+       list_add_tail(&ep->entry, &timeout_list);
+       spin_unlock(&timeout_lock);
+       queue_work(workq, &skb_work);
+}
+
+/*
+ * All the CM events are handled on a work queue to have a safe context.
+ */
+static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+
+       /*
+        * Save dev in the skb->cb area.
+        */
+       *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
+
+       /*
+        * Queue the skb and schedule the worker thread.
+        */
+       skb_queue_tail(&rxq, skb);
+       queue_work(workq, &skb_work);
+       return 0;
+}
+
+static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
+
+       if (rpl->status != CPL_ERR_NONE) {
+               printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
+                      "for tid %u\n", rpl->status, GET_TID(rpl));
+       }
+       return 0;
+}
+
+static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
+{
+       struct cpl_fw6_msg *rpl = cplhdr(skb);
+       struct c4iw_wr_wait *wr_waitp;
+       int ret;
+
+       PDBG("%s type %u\n", __func__, rpl->type);
+
+       switch (rpl->type) {
+       case 1:
+               ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
+               wr_waitp = (__force struct c4iw_wr_wait *)rpl->data[1];
+               PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
+               if (wr_waitp) {
+                       wr_waitp->ret = ret;
+                       wr_waitp->done = 1;
+                       wake_up(&wr_waitp->wait);
+               }
+               break;
+       case 2:
+               c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
+               break;
+       default:
+               printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
+                      rpl->type);
+               break;
+       }
+       return 0;
+}
+
+/*
+ * Most upcalls from the T4 Core go to sched() to
+ * schedule the processing on a work queue.
+ */
+c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
+       [CPL_ACT_ESTABLISH] = sched,
+       [CPL_ACT_OPEN_RPL] = sched,
+       [CPL_RX_DATA] = sched,
+       [CPL_ABORT_RPL_RSS] = sched,
+       [CPL_ABORT_RPL] = sched,
+       [CPL_PASS_OPEN_RPL] = sched,
+       [CPL_CLOSE_LISTSRV_RPL] = sched,
+       [CPL_PASS_ACCEPT_REQ] = sched,
+       [CPL_PASS_ESTABLISH] = sched,
+       [CPL_PEER_CLOSE] = sched,
+       [CPL_CLOSE_CON_RPL] = sched,
+       [CPL_ABORT_REQ_RSS] = sched,
+       [CPL_RDMA_TERMINATE] = sched,
+       [CPL_FW4_ACK] = sched,
+       [CPL_SET_TCB_RPL] = set_tcb_rpl,
+       [CPL_FW6_MSG] = fw6_msg
+};
+
+int __init c4iw_cm_init(void)
+{
+       spin_lock_init(&timeout_lock);
+       skb_queue_head_init(&rxq);
+
+       workq = create_singlethread_workqueue("iw_cxgb4");
+       if (!workq)
+               return -ENOMEM;
+
+       return 0;
+}
+
+void __exit c4iw_cm_term(void)
+{
+       WARN_ON(!list_empty(&timeout_list));
+       flush_workqueue(workq);
+       destroy_workqueue(workq);
+}
diff --git a/drivers/infiniband/hw/cxgb4/cq.c b/drivers/infiniband/hw/cxgb4/cq.c
new file mode 100644 (file)
index 0000000..fb1aafc
--- /dev/null
@@ -0,0 +1,882 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials
+ *       provided with the distribution.
+ *
+ * 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.
+ */
+
+#include "iw_cxgb4.h"
+
+static int destroy_cq(struct c4iw_rdev *rdev, struct t4_cq *cq,
+                     struct c4iw_dev_ucontext *uctx)
+{
+       struct fw_ri_res_wr *res_wr;
+       struct fw_ri_res *res;
+       int wr_len;
+       struct c4iw_wr_wait wr_wait;
+       struct sk_buff *skb;
+       int ret;
+
+       wr_len = sizeof *res_wr + sizeof *res;
+       skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
+       if (!skb)
+               return -ENOMEM;
+       set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
+
+       res_wr = (struct fw_ri_res_wr *)__skb_put(skb, wr_len);
+       memset(res_wr, 0, wr_len);
+       res_wr->op_nres = cpu_to_be32(
+                       FW_WR_OP(FW_RI_RES_WR) |
+                       V_FW_RI_RES_WR_NRES(1) |
+                       FW_WR_COMPL(1));
+       res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
+       res_wr->cookie = (u64)&wr_wait;
+       res = res_wr->res;
+       res->u.cq.restype = FW_RI_RES_TYPE_CQ;
+       res->u.cq.op = FW_RI_RES_OP_RESET;
+       res->u.cq.iqid = cpu_to_be32(cq->cqid);
+
+       c4iw_init_wr_wait(&wr_wait);
+       ret = c4iw_ofld_send(rdev, skb);
+       if (!ret) {
+               wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+               if (!wr_wait.done) {
+                       printk(KERN_ERR MOD "Device %s not responding!\n",
+                              pci_name(rdev->lldi.pdev));
+                       rdev->flags = T4_FATAL_ERROR;
+                       ret = -EIO;
+               } else
+                       ret = wr_wait.ret;
+       }
+
+       kfree(cq->sw_queue);
+       dma_free_coherent(&(rdev->lldi.pdev->dev),
+                         cq->memsize, cq->queue,
+                         pci_unmap_addr(cq, mapping));
+       c4iw_put_cqid(rdev, cq->cqid, uctx);
+       return ret;
+}
+
+static int create_cq(struct c4iw_rdev *rdev, struct t4_cq *cq,
+                    struct c4iw_dev_ucontext *uctx)
+{
+       struct fw_ri_res_wr *res_wr;
+       struct fw_ri_res *res;
+       int wr_len;
+       int user = (uctx != &rdev->uctx);
+       struct c4iw_wr_wait wr_wait;
+       int ret;
+       struct sk_buff *skb;
+
+       cq->cqid = c4iw_get_cqid(rdev, uctx);
+       if (!cq->cqid) {
+               ret = -ENOMEM;
+               goto err1;
+       }
+
+       if (!user) {
+               cq->sw_queue = kzalloc(cq->memsize, GFP_KERNEL);
+               if (!cq->sw_queue) {
+                       ret = -ENOMEM;
+                       goto err2;
+               }
+       }
+       cq->queue = dma_alloc_coherent(&rdev->lldi.pdev->dev, cq->memsize,
+                                      &cq->dma_addr, GFP_KERNEL);
+       if (!cq->queue) {
+               ret = -ENOMEM;
+               goto err3;
+       }
+       pci_unmap_addr_set(cq, mapping, cq->dma_addr);
+       memset(cq->queue, 0, cq->memsize);
+
+       /* build fw_ri_res_wr */
+       wr_len = sizeof *res_wr + sizeof *res;
+
+       skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
+       if (!skb) {
+               ret = -ENOMEM;
+               goto err4;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
+
+       res_wr = (struct fw_ri_res_wr *)__skb_put(skb, wr_len);
+       memset(res_wr, 0, wr_len);
+       res_wr->op_nres = cpu_to_be32(
+                       FW_WR_OP(FW_RI_RES_WR) |
+                       V_FW_RI_RES_WR_NRES(1) |
+                       FW_WR_COMPL(1));
+       res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
+       res_wr->cookie = (u64)&wr_wait;
+       res = res_wr->res;
+       res->u.cq.restype = FW_RI_RES_TYPE_CQ;
+       res->u.cq.op = FW_RI_RES_OP_WRITE;
+       res->u.cq.iqid = cpu_to_be32(cq->cqid);
+       res->u.cq.iqandst_to_iqandstindex = cpu_to_be32(
+                       V_FW_RI_RES_WR_IQANUS(0) |
+                       V_FW_RI_RES_WR_IQANUD(1) |
+                       F_FW_RI_RES_WR_IQANDST |
+                       V_FW_RI_RES_WR_IQANDSTINDEX(*rdev->lldi.rxq_ids));
+       res->u.cq.iqdroprss_to_iqesize = cpu_to_be16(
+                       F_FW_RI_RES_WR_IQDROPRSS |
+                       V_FW_RI_RES_WR_IQPCIECH(2) |
+                       V_FW_RI_RES_WR_IQINTCNTTHRESH(0) |
+                       F_FW_RI_RES_WR_IQO |
+                       V_FW_RI_RES_WR_IQESIZE(1));
+       res->u.cq.iqsize = cpu_to_be16(cq->size);
+       res->u.cq.iqaddr = cpu_to_be64(cq->dma_addr);
+
+       c4iw_init_wr_wait(&wr_wait);
+
+       ret = c4iw_ofld_send(rdev, skb);
+       if (ret)
+               goto err4;
+       PDBG("%s wait_event wr_wait %p\n", __func__, &wr_wait);
+       wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+       if (!wr_wait.done) {
+               printk(KERN_ERR MOD "Device %s not responding!\n",
+                      pci_name(rdev->lldi.pdev));
+               rdev->flags = T4_FATAL_ERROR;
+               ret = -EIO;
+       } else
+               ret = wr_wait.ret;
+       if (ret)
+               goto err4;
+
+       cq->gen = 1;
+       cq->gts = rdev->lldi.gts_reg;
+       cq->rdev = rdev;
+       if (user) {
+               cq->ugts = (u64)pci_resource_start(rdev->lldi.pdev, 2) +
+                                       (cq->cqid << rdev->cqshift);
+               cq->ugts &= PAGE_MASK;
+       }
+       return 0;
+err4:
+       dma_free_coherent(&rdev->lldi.pdev->dev, cq->memsize, cq->queue,
+                         pci_unmap_addr(cq, mapping));
+err3:
+       kfree(cq->sw_queue);
+err2:
+       c4iw_put_cqid(rdev, cq->cqid, uctx);
+err1:
+       return ret;
+}
+
+static void insert_recv_cqe(struct t4_wq *wq, struct t4_cq *cq)
+{
+       struct t4_cqe cqe;
+
+       PDBG("%s wq %p cq %p sw_cidx %u sw_pidx %u\n", __func__,
+            wq, cq, cq->sw_cidx, cq->sw_pidx);
+       memset(&cqe, 0, sizeof(cqe));
+       cqe.header = cpu_to_be32(V_CQE_STATUS(T4_ERR_SWFLUSH) |
+                                V_CQE_OPCODE(FW_RI_SEND) |
+                                V_CQE_TYPE(0) |
+                                V_CQE_SWCQE(1) |
+                                V_CQE_QPID(wq->rq.qid));
+       cqe.bits_type_ts = cpu_to_be64(V_CQE_GENBIT((u64)cq->gen));
+       cq->sw_queue[cq->sw_pidx] = cqe;
+       t4_swcq_produce(cq);
+}
+
+int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count)
+{
+       int flushed = 0;
+       int in_use = wq->rq.in_use - count;
+
+       BUG_ON(in_use < 0);
+       PDBG("%s wq %p cq %p rq.in_use %u skip count %u\n", __func__,
+            wq, cq, wq->rq.in_use, count);
+       while (in_use--) {
+               insert_recv_cqe(wq, cq);
+               flushed++;
+       }
+       return flushed;
+}
+
+static void insert_sq_cqe(struct t4_wq *wq, struct t4_cq *cq,
+                         struct t4_swsqe *swcqe)
+{
+       struct t4_cqe cqe;
+
+       PDBG("%s wq %p cq %p sw_cidx %u sw_pidx %u\n", __func__,
+            wq, cq, cq->sw_cidx, cq->sw_pidx);
+       memset(&cqe, 0, sizeof(cqe));
+       cqe.header = cpu_to_be32(V_CQE_STATUS(T4_ERR_SWFLUSH) |
+                                V_CQE_OPCODE(swcqe->opcode) |
+                                V_CQE_TYPE(1) |
+                                V_CQE_SWCQE(1) |
+                                V_CQE_QPID(wq->sq.qid));
+       CQE_WRID_SQ_IDX(&cqe) = swcqe->idx;
+       cqe.bits_type_ts = cpu_to_be64(V_CQE_GENBIT((u64)cq->gen));
+       cq->sw_queue[cq->sw_pidx] = cqe;
+       t4_swcq_produce(cq);
+}
+
+int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count)
+{
+       int flushed = 0;
+       struct t4_swsqe *swsqe = &wq->sq.sw_sq[wq->sq.cidx + count];
+       int in_use = wq->sq.in_use - count;
+
+       BUG_ON(in_use < 0);
+       while (in_use--) {
+               swsqe->signaled = 0;
+               insert_sq_cqe(wq, cq, swsqe);
+               swsqe++;
+               if (swsqe == (wq->sq.sw_sq + wq->sq.size))
+                       swsqe = wq->sq.sw_sq;
+               flushed++;
+       }
+       return flushed;
+}
+
+/*
+ * Move all CQEs from the HWCQ into the SWCQ.
+ */
+void c4iw_flush_hw_cq(struct t4_cq *cq)
+{
+       struct t4_cqe *cqe = NULL, *swcqe;
+       int ret;
+
+       PDBG("%s cq %p cqid 0x%x\n", __func__, cq, cq->cqid);
+       ret = t4_next_hw_cqe(cq, &cqe);
+       while (!ret) {
+               PDBG("%s flushing hwcq cidx 0x%x swcq pidx 0x%x\n",
+                    __func__, cq->cidx, cq->sw_pidx);
+               swcqe = &cq->sw_queue[cq->sw_pidx];
+               *swcqe = *cqe;
+               swcqe->header |= cpu_to_be32(V_CQE_SWCQE(1));
+               t4_swcq_produce(cq);
+               t4_hwcq_consume(cq);
+               ret = t4_next_hw_cqe(cq, &cqe);
+       }
+}
+
+static int cqe_completes_wr(struct t4_cqe *cqe, struct t4_wq *wq)
+{
+       if (CQE_OPCODE(cqe) == FW_RI_TERMINATE)
+               return 0;
+
+       if ((CQE_OPCODE(cqe) == FW_RI_RDMA_WRITE) && RQ_TYPE(cqe))
+               return 0;
+
+       if ((CQE_OPCODE(cqe) == FW_RI_READ_RESP) && SQ_TYPE(cqe))
+               return 0;
+
+       if (CQE_SEND_OPCODE(cqe) && RQ_TYPE(cqe) && t4_rq_empty(wq))
+               return 0;
+       return 1;
+}
+
+void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count)
+{
+       struct t4_cqe *cqe;
+       u32 ptr;
+
+       *count = 0;
+       ptr = cq->sw_cidx;
+       while (ptr != cq->sw_pidx) {
+               cqe = &cq->sw_queue[ptr];
+               if ((SQ_TYPE(cqe) || ((CQE_OPCODE(cqe) == FW_RI_READ_RESP) &&
+                                     wq->sq.oldest_read)) &&
+                   (CQE_QPID(cqe) == wq->sq.qid))
+                       (*count)++;
+               if (++ptr == cq->size)
+                       ptr = 0;
+       }
+       PDBG("%s cq %p count %d\n", __func__, cq, *count);
+}
+
+void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count)
+{
+       struct t4_cqe *cqe;
+       u32 ptr;
+
+       *count = 0;
+       PDBG("%s count zero %d\n", __func__, *count);
+       ptr = cq->sw_cidx;
+       while (ptr != cq->sw_pidx) {
+               cqe = &cq->sw_queue[ptr];
+               if (RQ_TYPE(cqe) && (CQE_OPCODE(cqe) != FW_RI_READ_RESP) &&
+                   (CQE_QPID(cqe) == wq->rq.qid) && cqe_completes_wr(cqe, wq))
+                       (*count)++;
+               if (++ptr == cq->size)
+                       ptr = 0;
+       }
+       PDBG("%s cq %p count %d\n", __func__, cq, *count);
+}
+
+static void flush_completed_wrs(struct t4_wq *wq, struct t4_cq *cq)
+{
+       struct t4_swsqe *swsqe;
+       u16 ptr = wq->sq.cidx;
+       int count = wq->sq.in_use;
+       int unsignaled = 0;
+
+       swsqe = &wq->sq.sw_sq[ptr];
+       while (count--)
+               if (!swsqe->signaled) {
+                       if (++ptr == wq->sq.size)
+                               ptr = 0;
+                       swsqe = &wq->sq.sw_sq[ptr];
+                       unsignaled++;
+               } else if (swsqe->complete) {
+
+                       /*
+                        * Insert this completed cqe into the swcq.
+                        */
+                       PDBG("%s moving cqe into swcq sq idx %u cq idx %u\n",
+                            __func__, ptr, cq->sw_pidx);
+                       swsqe->cqe.header |= htonl(V_CQE_SWCQE(1));
+                       cq->sw_queue[cq->sw_pidx] = swsqe->cqe;
+                       t4_swcq_produce(cq);
+                       swsqe->signaled = 0;
+                       wq->sq.in_use -= unsignaled;
+                       break;
+               } else
+                       break;
+}
+
+static void create_read_req_cqe(struct t4_wq *wq, struct t4_cqe *hw_cqe,
+                               struct t4_cqe *read_cqe)
+{
+       read_cqe->u.scqe.cidx = wq->sq.oldest_read->idx;
+       read_cqe->len = cpu_to_be32(wq->sq.oldest_read->read_len);
+       read_cqe->header = htonl(V_CQE_QPID(CQE_QPID(hw_cqe)) |
+                                V_CQE_SWCQE(SW_CQE(hw_cqe)) |
+                                V_CQE_OPCODE(FW_RI_READ_REQ) |
+                                V_CQE_TYPE(1));
+}
+
+/*
+ * Return a ptr to the next read wr in the SWSQ or NULL.
+ */
+static void advance_oldest_read(struct t4_wq *wq)
+{
+
+       u32 rptr = wq->sq.oldest_read - wq->sq.sw_sq + 1;
+
+       if (rptr == wq->sq.size)
+               rptr = 0;
+       while (rptr != wq->sq.pidx) {
+               wq->sq.oldest_read = &wq->sq.sw_sq[rptr];
+
+               if (wq->sq.oldest_read->opcode == FW_RI_READ_REQ)
+                       return;
+               if (++rptr == wq->sq.size)
+                       rptr = 0;
+       }
+       wq->sq.oldest_read = NULL;
+}
+
+/*
+ * poll_cq
+ *
+ * Caller must:
+ *     check the validity of the first CQE,
+ *     supply the wq assicated with the qpid.
+ *
+ * credit: cq credit to return to sge.
+ * cqe_flushed: 1 iff the CQE is flushed.
+ * cqe: copy of the polled CQE.
+ *
+ * return value:
+ *    0                    CQE returned ok.
+ *    -EAGAIN       CQE skipped, try again.
+ *    -EOVERFLOW    CQ overflow detected.
+ */
+static int poll_cq(struct t4_wq *wq, struct t4_cq *cq, struct t4_cqe *cqe,
+                  u8 *cqe_flushed, u64 *cookie, u32 *credit)
+{
+       int ret = 0;
+       struct t4_cqe *hw_cqe, read_cqe;
+
+       *cqe_flushed = 0;
+       *credit = 0;
+       ret = t4_next_cqe(cq, &hw_cqe);
+       if (ret)
+               return ret;
+
+       PDBG("%s CQE OVF %u qpid 0x%0x genbit %u type %u status 0x%0x"
+            " opcode 0x%0x len 0x%0x wrid_hi_stag 0x%x wrid_low_msn 0x%x\n",
+            __func__, CQE_OVFBIT(hw_cqe), CQE_QPID(hw_cqe),
+            CQE_GENBIT(hw_cqe), CQE_TYPE(hw_cqe), CQE_STATUS(hw_cqe),
+            CQE_OPCODE(hw_cqe), CQE_LEN(hw_cqe), CQE_WRID_HI(hw_cqe),
+            CQE_WRID_LOW(hw_cqe));
+
+       /*
+        * skip cqe's not affiliated with a QP.
+        */
+       if (wq == NULL) {
+               ret = -EAGAIN;
+               goto skip_cqe;
+       }
+
+       /*
+        * Gotta tweak READ completions:
+        *      1) the cqe doesn't contain the sq_wptr from the wr.
+        *      2) opcode not reflected from the wr.
+        *      3) read_len not reflected from the wr.
+        *      4) cq_type is RQ_TYPE not SQ_TYPE.
+        */
+       if (RQ_TYPE(hw_cqe) && (CQE_OPCODE(hw_cqe) == FW_RI_READ_RESP)) {
+
+               /*
+                * If this is an unsolicited read response, then the read
+                * was generated by the kernel driver as part of peer-2-peer
+                * connection setup.  So ignore the completion.
+                */
+               if (!wq->sq.oldest_read) {
+                       if (CQE_STATUS(hw_cqe))
+                               t4_set_wq_in_error(wq);
+                       ret = -EAGAIN;
+                       goto skip_cqe;
+               }
+
+               /*
+                * Don't write to the HWCQ, so create a new read req CQE
+                * in local memory.
+                */
+               create_read_req_cqe(wq, hw_cqe, &read_cqe);
+               hw_cqe = &read_cqe;
+               advance_oldest_read(wq);
+       }
+
+       if (CQE_STATUS(hw_cqe) || t4_wq_in_error(wq)) {
+               *cqe_flushed = t4_wq_in_error(wq);
+               t4_set_wq_in_error(wq);
+               goto proc_cqe;
+       }
+
+       /*
+        * RECV completion.
+        */
+       if (RQ_TYPE(hw_cqe)) {
+
+               /*
+                * HW only validates 4 bits of MSN.  So we must validate that
+                * the MSN in the SEND is the next expected MSN.  If its not,
+                * then we complete this with T4_ERR_MSN and mark the wq in
+                * error.
+                */
+
+               if (t4_rq_empty(wq)) {
+                       t4_set_wq_in_error(wq);
+                       ret = -EAGAIN;
+                       goto skip_cqe;
+               }
+               if (unlikely((CQE_WRID_MSN(hw_cqe) != (wq->rq.msn)))) {
+                       t4_set_wq_in_error(wq);
+                       hw_cqe->header |= htonl(V_CQE_STATUS(T4_ERR_MSN));
+                       goto proc_cqe;
+               }
+               goto proc_cqe;
+       }
+
+       /*
+        * If we get here its a send completion.
+        *
+        * Handle out of order completion. These get stuffed
+        * in the SW SQ. Then the SW SQ is walked to move any
+        * now in-order completions into the SW CQ.  This handles
+        * 2 cases:
+        *      1) reaping unsignaled WRs when the first subsequent
+        *         signaled WR is completed.
+        *      2) out of order read completions.
+        */
+       if (!SW_CQE(hw_cqe) && (CQE_WRID_SQ_IDX(hw_cqe) != wq->sq.cidx)) {
+               struct t4_swsqe *swsqe;
+
+               PDBG("%s out of order completion going in sw_sq at idx %u\n",
+                    __func__, CQE_WRID_SQ_IDX(hw_cqe));
+               swsqe = &wq->sq.sw_sq[CQE_WRID_SQ_IDX(hw_cqe)];
+               swsqe->cqe = *hw_cqe;
+               swsqe->complete = 1;
+               ret = -EAGAIN;
+               goto flush_wq;
+       }
+
+proc_cqe:
+       *cqe = *hw_cqe;
+
+       /*
+        * Reap the associated WR(s) that are freed up with this
+        * completion.
+        */
+       if (SQ_TYPE(hw_cqe)) {
+               wq->sq.cidx = CQE_WRID_SQ_IDX(hw_cqe);
+               PDBG("%s completing sq idx %u\n", __func__, wq->sq.cidx);
+               *cookie = wq->sq.sw_sq[wq->sq.cidx].wr_id;
+               t4_sq_consume(wq);
+       } else {
+               PDBG("%s completing rq idx %u\n", __func__, wq->rq.cidx);
+               *cookie = wq->rq.sw_rq[wq->rq.cidx].wr_id;
+               BUG_ON(t4_rq_empty(wq));
+               t4_rq_consume(wq);
+       }
+
+flush_wq:
+       /*
+        * Flush any completed cqes that are now in-order.
+        */
+       flush_completed_wrs(wq, cq);
+
+skip_cqe:
+       if (SW_CQE(hw_cqe)) {
+               PDBG("%s cq %p cqid 0x%x skip sw cqe cidx %u\n",
+                    __func__, cq, cq->cqid, cq->sw_cidx);
+               t4_swcq_consume(cq);
+       } else {
+               PDBG("%s cq %p cqid 0x%x skip hw cqe cidx %u\n",
+                    __func__, cq, cq->cqid, cq->cidx);
+               t4_hwcq_consume(cq);
+       }
+       return ret;
+}
+
+/*
+ * Get one cq entry from c4iw and map it to openib.
+ *
+ * Returns:
+ *     0                       cqe returned
+ *     -ENODATA                EMPTY;
+ *     -EAGAIN                 caller must try again
+ *     any other -errno        fatal error
+ */
+static int c4iw_poll_cq_one(struct c4iw_cq *chp, struct ib_wc *wc)
+{
+       struct c4iw_qp *qhp = NULL;
+       struct t4_cqe cqe = {0, 0}, *rd_cqe;
+       struct t4_wq *wq;
+       u32 credit = 0;
+       u8 cqe_flushed;
+       u64 cookie = 0;
+       int ret;
+
+       ret = t4_next_cqe(&chp->cq, &rd_cqe);
+
+       if (ret)
+               return ret;
+
+       qhp = get_qhp(chp->rhp, CQE_QPID(rd_cqe));
+       if (!qhp)
+               wq = NULL;
+       else {
+               spin_lock(&qhp->lock);
+               wq = &(qhp->wq);
+       }
+       ret = poll_cq(wq, &(chp->cq), &cqe, &cqe_flushed, &cookie, &credit);
+       if (ret)
+               goto out;
+
+       wc->wr_id = cookie;
+       wc->qp = &qhp->ibqp;
+       wc->vendor_err = CQE_STATUS(&cqe);
+       wc->wc_flags = 0;
+
+       PDBG("%s qpid 0x%x type %d opcode %d status 0x%x len %u wrid hi 0x%x "
+            "lo 0x%x cookie 0x%llx\n", __func__, CQE_QPID(&cqe),
+            CQE_TYPE(&cqe), CQE_OPCODE(&cqe), CQE_STATUS(&cqe), CQE_LEN(&cqe),
+            CQE_WRID_HI(&cqe), CQE_WRID_LOW(&cqe), (unsigned long long)cookie);
+
+       if (CQE_TYPE(&cqe) == 0) {
+               if (!CQE_STATUS(&cqe))
+                       wc->byte_len = CQE_LEN(&cqe);
+               else
+                       wc->byte_len = 0;
+               wc->opcode = IB_WC_RECV;
+               if (CQE_OPCODE(&cqe) == FW_RI_SEND_WITH_INV ||
+                   CQE_OPCODE(&cqe) == FW_RI_SEND_WITH_SE_INV) {
+                       wc->ex.invalidate_rkey = CQE_WRID_STAG(&cqe);
+                       wc->wc_flags |= IB_WC_WITH_INVALIDATE;
+               }
+       } else {
+               switch (CQE_OPCODE(&cqe)) {
+               case FW_RI_RDMA_WRITE:
+                       wc->opcode = IB_WC_RDMA_WRITE;
+                       break;
+               case FW_RI_READ_REQ:
+                       wc->opcode = IB_WC_RDMA_READ;
+                       wc->byte_len = CQE_LEN(&cqe);
+                       break;
+               case FW_RI_SEND_WITH_INV:
+               case FW_RI_SEND_WITH_SE_INV:
+                       wc->opcode = IB_WC_SEND;
+                       wc->wc_flags |= IB_WC_WITH_INVALIDATE;
+                       break;
+               case FW_RI_SEND:
+               case FW_RI_SEND_WITH_SE:
+                       wc->opcode = IB_WC_SEND;
+                       break;
+               case FW_RI_BIND_MW:
+                       wc->opcode = IB_WC_BIND_MW;
+                       break;
+
+               case FW_RI_LOCAL_INV:
+                       wc->opcode = IB_WC_LOCAL_INV;
+                       break;
+               case FW_RI_FAST_REGISTER:
+                       wc->opcode = IB_WC_FAST_REG_MR;
+                       break;
+               default:
+                       printk(KERN_ERR MOD "Unexpected opcode %d "
+                              "in the CQE received for QPID=0x%0x\n",
+                              CQE_OPCODE(&cqe), CQE_QPID(&cqe));
+                       ret = -EINVAL;
+                       goto out;
+               }
+       }
+
+       if (cqe_flushed)
+               wc->status = IB_WC_WR_FLUSH_ERR;
+       else {
+
+               switch (CQE_STATUS(&cqe)) {
+               case T4_ERR_SUCCESS:
+                       wc->status = IB_WC_SUCCESS;
+                       break;
+               case T4_ERR_STAG:
+                       wc->status = IB_WC_LOC_ACCESS_ERR;
+                       break;
+               case T4_ERR_PDID:
+                       wc->status = IB_WC_LOC_PROT_ERR;
+                       break;
+               case T4_ERR_QPID:
+               case T4_ERR_ACCESS:
+                       wc->status = IB_WC_LOC_ACCESS_ERR;
+                       break;
+               case T4_ERR_WRAP:
+                       wc->status = IB_WC_GENERAL_ERR;
+                       break;
+               case T4_ERR_BOUND:
+                       wc->status = IB_WC_LOC_LEN_ERR;
+                       break;
+               case T4_ERR_INVALIDATE_SHARED_MR:
+               case T4_ERR_INVALIDATE_MR_WITH_MW_BOUND:
+                       wc->status = IB_WC_MW_BIND_ERR;
+                       break;
+               case T4_ERR_CRC:
+               case T4_ERR_MARKER:
+               case T4_ERR_PDU_LEN_ERR:
+               case T4_ERR_OUT_OF_RQE:
+               case T4_ERR_DDP_VERSION:
+               case T4_ERR_RDMA_VERSION:
+               case T4_ERR_DDP_QUEUE_NUM:
+               case T4_ERR_MSN:
+               case T4_ERR_TBIT:
+               case T4_ERR_MO:
+               case T4_ERR_MSN_RANGE:
+               case T4_ERR_IRD_OVERFLOW:
+               case T4_ERR_OPCODE:
+                       wc->status = IB_WC_FATAL_ERR;
+                       break;
+               case T4_ERR_SWFLUSH:
+                       wc->status = IB_WC_WR_FLUSH_ERR;
+                       break;
+               default:
+                       printk(KERN_ERR MOD
+                              "Unexpected cqe_status 0x%x for QPID=0x%0x\n",
+                              CQE_STATUS(&cqe), CQE_QPID(&cqe));
+                       ret = -EINVAL;
+               }
+       }
+out:
+       if (wq)
+               spin_unlock(&qhp->lock);
+       return ret;
+}
+
+int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
+{
+       struct c4iw_cq *chp;
+       unsigned long flags;
+       int npolled;
+       int err = 0;
+
+       chp = to_c4iw_cq(ibcq);
+
+       spin_lock_irqsave(&chp->lock, flags);
+       for (npolled = 0; npolled < num_entries; ++npolled) {
+               do {
+                       err = c4iw_poll_cq_one(chp, wc + npolled);
+               } while (err == -EAGAIN);
+               if (err)
+                       break;
+       }
+       spin_unlock_irqrestore(&chp->lock, flags);
+       return !err || err == -ENODATA ? npolled : err;
+}
+
+int c4iw_destroy_cq(struct ib_cq *ib_cq)
+{
+       struct c4iw_cq *chp;
+       struct c4iw_ucontext *ucontext;
+
+       PDBG("%s ib_cq %p\n", __func__, ib_cq);
+       chp = to_c4iw_cq(ib_cq);
+
+       remove_handle(chp->rhp, &chp->rhp->cqidr, chp->cq.cqid);
+       atomic_dec(&chp->refcnt);
+       wait_event(chp->wait, !atomic_read(&chp->refcnt));
+
+       ucontext = ib_cq->uobject ? to_c4iw_ucontext(ib_cq->uobject->context)
+                                 : NULL;
+       destroy_cq(&chp->rhp->rdev, &chp->cq,
+                  ucontext ? &ucontext->uctx : &chp->cq.rdev->uctx);
+       kfree(chp);
+       return 0;
+}
+
+struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
+                            int vector, struct ib_ucontext *ib_context,
+                            struct ib_udata *udata)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_cq *chp;
+       struct c4iw_create_cq_resp uresp;
+       struct c4iw_ucontext *ucontext = NULL;
+       int ret;
+       size_t memsize;
+       struct c4iw_mm_entry *mm, *mm2;
+
+       PDBG("%s ib_dev %p entries %d\n", __func__, ibdev, entries);
+
+       rhp = to_c4iw_dev(ibdev);
+
+       chp = kzalloc(sizeof(*chp), GFP_KERNEL);
+       if (!chp)
+               return ERR_PTR(-ENOMEM);
+
+       if (ib_context)
+               ucontext = to_c4iw_ucontext(ib_context);
+
+       /* account for the status page. */
+       entries++;
+
+       /*
+        * entries must be multiple of 16 for HW.
+        */
+       entries = roundup(entries, 16);
+       memsize = entries * sizeof *chp->cq.queue;
+
+       /*
+        * memsize must be a multiple of the page size if its a user cq.
+        */
+       if (ucontext)
+               memsize = roundup(memsize, PAGE_SIZE);
+       chp->cq.size = entries;
+       chp->cq.memsize = memsize;
+
+       ret = create_cq(&rhp->rdev, &chp->cq,
+                       ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
+       if (ret)
+               goto err1;
+
+       chp->rhp = rhp;
+       chp->cq.size--;                         /* status page */
+       chp->ibcq.cqe = chp->cq.size;
+       spin_lock_init(&chp->lock);
+       atomic_set(&chp->refcnt, 1);
+       init_waitqueue_head(&chp->wait);
+       ret = insert_handle(rhp, &rhp->cqidr, chp, chp->cq.cqid);
+       if (ret)
+               goto err2;
+
+       if (ucontext) {
+               mm = kmalloc(sizeof *mm, GFP_KERNEL);
+               if (!mm)
+                       goto err3;
+               mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
+               if (!mm2)
+                       goto err4;
+
+               uresp.qid_mask = rhp->rdev.cqmask;
+               uresp.cqid = chp->cq.cqid;
+               uresp.size = chp->cq.size;
+               uresp.memsize = chp->cq.memsize;
+               spin_lock(&ucontext->mmap_lock);
+               uresp.key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               uresp.gts_key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               spin_unlock(&ucontext->mmap_lock);
+               ret = ib_copy_to_udata(udata, &uresp, sizeof uresp);
+               if (ret)
+                       goto err5;
+
+               mm->key = uresp.key;
+               mm->addr = virt_to_phys(chp->cq.queue);
+               mm->len = chp->cq.memsize;
+               insert_mmap(ucontext, mm);
+
+               mm2->key = uresp.gts_key;
+               mm2->addr = chp->cq.ugts;
+               mm2->len = PAGE_SIZE;
+               insert_mmap(ucontext, mm2);
+       }
+       PDBG("%s cqid 0x%0x chp %p size %u memsize %zu, dma_addr 0x%0llx\n",
+            __func__, chp->cq.cqid, chp, chp->cq.size,
+            chp->cq.memsize,
+            (unsigned long long) chp->cq.dma_addr);
+       return &chp->ibcq;
+err5:
+       kfree(mm2);
+err4:
+       kfree(mm);
+err3:
+       remove_handle(rhp, &rhp->cqidr, chp->cq.cqid);
+err2:
+       destroy_cq(&chp->rhp->rdev, &chp->cq,
+                  ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
+err1:
+       kfree(chp);
+       return ERR_PTR(ret);
+}
+
+int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata)
+{
+       return -ENOSYS;
+}
+
+int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
+{
+       struct c4iw_cq *chp;
+       int ret;
+       unsigned long flag;
+
+       chp = to_c4iw_cq(ibcq);
+       spin_lock_irqsave(&chp->lock, flag);
+       ret = t4_arm_cq(&chp->cq,
+                       (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED);
+       spin_unlock_irqrestore(&chp->lock, flag);
+       if (ret && !(flags & IB_CQ_REPORT_MISSED_EVENTS))
+               ret = 0;
+       return ret;
+}
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
new file mode 100644 (file)
index 0000000..be23b5e
--- /dev/null
@@ -0,0 +1,520 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials
+ *       provided with the distribution.
+ *
+ * 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.
+ */
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/debugfs.h>
+
+#include <rdma/ib_verbs.h>
+
+#include "iw_cxgb4.h"
+
+#define DRV_VERSION "0.1"
+
+MODULE_AUTHOR("Steve Wise");
+MODULE_DESCRIPTION("Chelsio T4 RDMA Driver");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_VERSION(DRV_VERSION);
+
+static LIST_HEAD(dev_list);
+static DEFINE_MUTEX(dev_mutex);
+
+static struct dentry *c4iw_debugfs_root;
+
+struct debugfs_qp_data {
+       struct c4iw_dev *devp;
+       char *buf;
+       int bufsize;
+       int pos;
+};
+
+static int count_qps(int id, void *p, void *data)
+{
+       struct c4iw_qp *qp = p;
+       int *countp = data;
+
+       if (id != qp->wq.sq.qid)
+               return 0;
+
+       *countp = *countp + 1;
+       return 0;
+}
+
+static int dump_qps(int id, void *p, void *data)
+{
+       struct c4iw_qp *qp = p;
+       struct debugfs_qp_data *qpd = data;
+       int space;
+       int cc;
+
+       if (id != qp->wq.sq.qid)
+               return 0;
+
+       space = qpd->bufsize - qpd->pos - 1;
+       if (space == 0)
+               return 1;
+
+       if (qp->ep)
+               cc = snprintf(qpd->buf + qpd->pos, space, "qp id %u state %u "
+                            "ep tid %u state %u %pI4:%u->%pI4:%u\n",
+                            qp->wq.sq.qid, (int)qp->attr.state,
+                            qp->ep->hwtid, (int)qp->ep->com.state,
+                            &qp->ep->com.local_addr.sin_addr.s_addr,
+                            ntohs(qp->ep->com.local_addr.sin_port),
+                            &qp->ep->com.remote_addr.sin_addr.s_addr,
+                            ntohs(qp->ep->com.remote_addr.sin_port));
+       else
+               cc = snprintf(qpd->buf + qpd->pos, space, "qp id %u state %u\n",
+                             qp->wq.sq.qid, (int)qp->attr.state);
+       if (cc < space)
+               qpd->pos += cc;
+       return 0;
+}
+
+static int qp_release(struct inode *inode, struct file *file)
+{
+       struct debugfs_qp_data *qpd = file->private_data;
+       if (!qpd) {
+               printk(KERN_INFO "%s null qpd?\n", __func__);
+               return 0;
+       }
+       kfree(qpd->buf);
+       kfree(qpd);
+       return 0;
+}
+
+static int qp_open(struct inode *inode, struct file *file)
+{
+       struct debugfs_qp_data *qpd;
+       int ret = 0;
+       int count = 1;
+
+       qpd = kmalloc(sizeof *qpd, GFP_KERNEL);
+       if (!qpd) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       qpd->devp = inode->i_private;
+       qpd->pos = 0;
+
+       spin_lock_irq(&qpd->devp->lock);
+       idr_for_each(&qpd->devp->qpidr, count_qps, &count);
+       spin_unlock_irq(&qpd->devp->lock);
+
+       qpd->bufsize = count * 128;
+       qpd->buf = kmalloc(qpd->bufsize, GFP_KERNEL);
+       if (!qpd->buf) {
+               ret = -ENOMEM;
+               goto err1;
+       }
+
+       spin_lock_irq(&qpd->devp->lock);
+       idr_for_each(&qpd->devp->qpidr, dump_qps, qpd);
+       spin_unlock_irq(&qpd->devp->lock);
+
+       qpd->buf[qpd->pos++] = 0;
+       file->private_data = qpd;
+       goto out;
+err1:
+       kfree(qpd);
+out:
+       return ret;
+}
+
+static ssize_t qp_read(struct file *file, char __user *buf, size_t count,
+                       loff_t *ppos)
+{
+       struct debugfs_qp_data *qpd = file->private_data;
+       loff_t pos = *ppos;
+       loff_t avail = qpd->pos;
+
+       if (pos < 0)
+               return -EINVAL;
+       if (pos >= avail)
+               return 0;
+       if (count > avail - pos)
+               count = avail - pos;
+
+       while (count) {
+               size_t len = 0;
+
+               len = min((int)count, (int)qpd->pos - (int)pos);
+               if (copy_to_user(buf, qpd->buf + pos, len))
+                       return -EFAULT;
+               if (len == 0)
+                       return -EINVAL;
+
+               buf += len;
+               pos += len;
+               count -= len;
+       }
+       count = pos - *ppos;
+       *ppos = pos;
+       return count;
+}
+
+static const struct file_operations qp_debugfs_fops = {
+       .owner   = THIS_MODULE,
+       .open    = qp_open,
+       .release = qp_release,
+       .read    = qp_read,
+};
+
+static int setup_debugfs(struct c4iw_dev *devp)
+{
+       struct dentry *de;
+
+       if (!devp->debugfs_root)
+               return -1;
+
+       de = debugfs_create_file("qps", S_IWUSR, devp->debugfs_root,
+                                (void *)devp, &qp_debugfs_fops);
+       if (de && de->d_inode)
+               de->d_inode->i_size = 4096;
+       return 0;
+}
+
+void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
+                              struct c4iw_dev_ucontext *uctx)
+{
+       struct list_head *pos, *nxt;
+       struct c4iw_qid_list *entry;
+
+       mutex_lock(&uctx->lock);
+       list_for_each_safe(pos, nxt, &uctx->qpids) {
+               entry = list_entry(pos, struct c4iw_qid_list, entry);
+               list_del_init(&entry->entry);
+               if (!(entry->qid & rdev->qpmask))
+                       c4iw_put_resource(&rdev->resource.qid_fifo, entry->qid,
+                                         &rdev->resource.qid_fifo_lock);
+               kfree(entry);
+       }
+
+       list_for_each_safe(pos, nxt, &uctx->qpids) {
+               entry = list_entry(pos, struct c4iw_qid_list, entry);
+               list_del_init(&entry->entry);
+               kfree(entry);
+       }
+       mutex_unlock(&uctx->lock);
+}
+
+void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
+                           struct c4iw_dev_ucontext *uctx)
+{
+       INIT_LIST_HEAD(&uctx->qpids);
+       INIT_LIST_HEAD(&uctx->cqids);
+       mutex_init(&uctx->lock);
+}
+
+/* Caller takes care of locking if needed */
+static int c4iw_rdev_open(struct c4iw_rdev *rdev)
+{
+       int err;
+
+       c4iw_init_dev_ucontext(rdev, &rdev->uctx);
+
+       /*
+        * qpshift is the number of bits to shift the qpid left in order
+        * to get the correct address of the doorbell for that qp.
+        */
+       rdev->qpshift = PAGE_SHIFT - ilog2(rdev->lldi.udb_density);
+       rdev->qpmask = rdev->lldi.udb_density - 1;
+       rdev->cqshift = PAGE_SHIFT - ilog2(rdev->lldi.ucq_density);
+       rdev->cqmask = rdev->lldi.ucq_density - 1;
+       PDBG("%s dev %s stag start 0x%0x size 0x%0x num stags %d "
+            "pbl start 0x%0x size 0x%0x rq start 0x%0x size 0x%0x\n",
+            __func__, pci_name(rdev->lldi.pdev), rdev->lldi.vr->stag.start,
+            rdev->lldi.vr->stag.size, c4iw_num_stags(rdev),
+            rdev->lldi.vr->pbl.start,
+            rdev->lldi.vr->pbl.size, rdev->lldi.vr->rq.start,
+            rdev->lldi.vr->rq.size);
+       PDBG("udb len 0x%x udb base %p db_reg %p gts_reg %p qpshift %lu "
+            "qpmask 0x%x cqshift %lu cqmask 0x%x\n",
+            (unsigned)pci_resource_len(rdev->lldi.pdev, 2),
+            (void *)pci_resource_start(rdev->lldi.pdev, 2),
+            rdev->lldi.db_reg,
+            rdev->lldi.gts_reg,
+            rdev->qpshift, rdev->qpmask,
+            rdev->cqshift, rdev->cqmask);
+
+       if (c4iw_num_stags(rdev) == 0) {
+               err = -EINVAL;
+               goto err1;
+       }
+
+       err = c4iw_init_resource(rdev, c4iw_num_stags(rdev), T4_MAX_NUM_PD);
+       if (err) {
+               printk(KERN_ERR MOD "error %d initializing resources\n", err);
+               goto err1;
+       }
+       err = c4iw_pblpool_create(rdev);
+       if (err) {
+               printk(KERN_ERR MOD "error %d initializing pbl pool\n", err);
+               goto err2;
+       }
+       err = c4iw_rqtpool_create(rdev);
+       if (err) {
+               printk(KERN_ERR MOD "error %d initializing rqt pool\n", err);
+               goto err3;
+       }
+       return 0;
+err3:
+       c4iw_pblpool_destroy(rdev);
+err2:
+       c4iw_destroy_resource(&rdev->resource);
+err1:
+       return err;
+}
+
+static void c4iw_rdev_close(struct c4iw_rdev *rdev)
+{
+       c4iw_pblpool_destroy(rdev);
+       c4iw_rqtpool_destroy(rdev);
+       c4iw_destroy_resource(&rdev->resource);
+}
+
+static void c4iw_remove(struct c4iw_dev *dev)
+{
+       PDBG("%s c4iw_dev %p\n", __func__,  dev);
+       cancel_delayed_work_sync(&dev->db_drop_task);
+       list_del(&dev->entry);
+       c4iw_unregister_device(dev);
+       c4iw_rdev_close(&dev->rdev);
+       idr_destroy(&dev->cqidr);
+       idr_destroy(&dev->qpidr);
+       idr_destroy(&dev->mmidr);
+       ib_dealloc_device(&dev->ibdev);
+}
+
+static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop)
+{
+       struct c4iw_dev *devp;
+       int ret;
+
+       devp = (struct c4iw_dev *)ib_alloc_device(sizeof(*devp));
+       if (!devp) {
+               printk(KERN_ERR MOD "Cannot allocate ib device\n");
+               return NULL;
+       }
+       devp->rdev.lldi = *infop;
+
+       mutex_lock(&dev_mutex);
+
+       ret = c4iw_rdev_open(&devp->rdev);
+       if (ret) {
+               mutex_unlock(&dev_mutex);
+               printk(KERN_ERR MOD "Unable to open CXIO rdev err %d\n", ret);
+               ib_dealloc_device(&devp->ibdev);
+               return NULL;
+       }
+
+       idr_init(&devp->cqidr);
+       idr_init(&devp->qpidr);
+       idr_init(&devp->mmidr);
+       spin_lock_init(&devp->lock);
+       list_add_tail(&devp->entry, &dev_list);
+       mutex_unlock(&dev_mutex);
+
+       if (c4iw_register_device(devp)) {
+               printk(KERN_ERR MOD "Unable to register device\n");
+               mutex_lock(&dev_mutex);
+               c4iw_remove(devp);
+               mutex_unlock(&dev_mutex);
+       }
+       if (c4iw_debugfs_root) {
+               devp->debugfs_root = debugfs_create_dir(
+                                       pci_name(devp->rdev.lldi.pdev),
+                                       c4iw_debugfs_root);
+               setup_debugfs(devp);
+       }
+       return devp;
+}
+
+static void *c4iw_uld_add(const struct cxgb4_lld_info *infop)
+{
+       struct c4iw_dev *dev;
+       static int vers_printed;
+       int i;
+
+       if (!vers_printed++)
+               printk(KERN_INFO MOD "Chelsio T4 RDMA Driver - version %s\n",
+                      DRV_VERSION);
+
+       dev = c4iw_alloc(infop);
+       if (!dev)
+               goto out;
+
+       PDBG("%s found device %s nchan %u nrxq %u ntxq %u nports %u\n",
+            __func__, pci_name(dev->rdev.lldi.pdev),
+            dev->rdev.lldi.nchan, dev->rdev.lldi.nrxq,
+            dev->rdev.lldi.ntxq, dev->rdev.lldi.nports);
+
+       for (i = 0; i < dev->rdev.lldi.nrxq; i++)
+               PDBG("rxqid[%u] %u\n", i, dev->rdev.lldi.rxq_ids[i]);
+
+       printk(KERN_INFO MOD "Initialized device %s\n",
+              pci_name(dev->rdev.lldi.pdev));
+out:
+       return dev;
+}
+
+static struct sk_buff *t4_pktgl_to_skb(const struct pkt_gl *gl,
+                                      unsigned int skb_len,
+                                      unsigned int pull_len)
+{
+       struct sk_buff *skb;
+       struct skb_shared_info *ssi;
+
+       if (gl->tot_len <= 512) {
+               skb = alloc_skb(gl->tot_len, GFP_ATOMIC);
+               if (unlikely(!skb))
+                       goto out;
+               __skb_put(skb, gl->tot_len);
+               skb_copy_to_linear_data(skb, gl->va, gl->tot_len);
+       } else {
+               skb = alloc_skb(skb_len, GFP_ATOMIC);
+               if (unlikely(!skb))
+                       goto out;
+               __skb_put(skb, pull_len);
+               skb_copy_to_linear_data(skb, gl->va, pull_len);
+
+               ssi = skb_shinfo(skb);
+               ssi->frags[0].page = gl->frags[0].page;
+               ssi->frags[0].page_offset = gl->frags[0].page_offset + pull_len;
+               ssi->frags[0].size = gl->frags[0].size - pull_len;
+               if (gl->nfrags > 1)
+                       memcpy(&ssi->frags[1], &gl->frags[1],
+                              (gl->nfrags - 1) * sizeof(skb_frag_t));
+               ssi->nr_frags = gl->nfrags;
+
+               skb->len = gl->tot_len;
+               skb->data_len = skb->len - pull_len;
+               skb->truesize += skb->data_len;
+
+               /* Get a reference for the last page, we don't own it */
+               get_page(gl->frags[gl->nfrags - 1].page);
+       }
+out:
+       return skb;
+}
+
+static int c4iw_uld_rx_handler(void *handle, const __be64 *rsp,
+                       const struct pkt_gl *gl)
+{
+       struct c4iw_dev *dev = handle;
+       struct sk_buff *skb;
+       const struct cpl_act_establish *rpl;
+       unsigned int opcode;
+
+       if (gl == NULL) {
+               /* omit RSS and rsp_ctrl at end of descriptor */
+               unsigned int len = 64 - sizeof(struct rsp_ctrl) - 8;
+
+               skb = alloc_skb(256, GFP_ATOMIC);
+               if (!skb)
+                       goto nomem;
+               __skb_put(skb, len);
+               skb_copy_to_linear_data(skb, &rsp[1], len);
+       } else if (gl == CXGB4_MSG_AN) {
+               const struct rsp_ctrl *rc = (void *)rsp;
+
+               u32 qid = be32_to_cpu(rc->pldbuflen_qid);
+               c4iw_ev_handler(dev, qid);
+               return 0;
+       } else {
+               skb = t4_pktgl_to_skb(gl, 128, 128);
+               if (unlikely(!skb))
+                       goto nomem;
+       }
+
+       rpl = cplhdr(skb);
+       opcode = rpl->ot.opcode;
+
+       if (c4iw_handlers[opcode])
+               c4iw_handlers[opcode](dev, skb);
+       else
+               printk(KERN_INFO "%s no handler opcode 0x%x...\n", __func__,
+                      opcode);
+
+       return 0;
+nomem:
+       return -1;
+}
+
+static int c4iw_uld_state_change(void *handle, enum cxgb4_state new_state)
+{
+       PDBG("%s new_state %u\n", __func__, new_state);
+       return 0;
+}
+
+static struct cxgb4_uld_info c4iw_uld_info = {
+       .name = DRV_NAME,
+       .add = c4iw_uld_add,
+       .rx_handler = c4iw_uld_rx_handler,
+       .state_change = c4iw_uld_state_change,
+};
+
+static int __init c4iw_init_module(void)
+{
+       int err;
+
+       err = c4iw_cm_init();
+       if (err)
+               return err;
+
+       c4iw_debugfs_root = debugfs_create_dir(DRV_NAME, NULL);
+       if (!c4iw_debugfs_root)
+               printk(KERN_WARNING MOD
+                      "could not create debugfs entry, continuing\n");
+
+       cxgb4_register_uld(CXGB4_ULD_RDMA, &c4iw_uld_info);
+
+       return 0;
+}
+
+static void __exit c4iw_exit_module(void)
+{
+       struct c4iw_dev *dev, *tmp;
+
+       cxgb4_unregister_uld(CXGB4_ULD_RDMA);
+
+       mutex_lock(&dev_mutex);
+       list_for_each_entry_safe(dev, tmp, &dev_list, entry) {
+               c4iw_remove(dev);
+       }
+       mutex_unlock(&dev_mutex);
+
+       c4iw_cm_term();
+       debugfs_remove_recursive(c4iw_debugfs_root);
+}
+
+module_init(c4iw_init_module);
+module_exit(c4iw_exit_module);
diff --git a/drivers/infiniband/hw/cxgb4/ev.c b/drivers/infiniband/hw/cxgb4/ev.c
new file mode 100644 (file)
index 0000000..491e76a
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#include <linux/slab.h>
+#include <linux/mman.h>
+#include <net/sock.h>
+
+#include "iw_cxgb4.h"
+
+static void post_qp_event(struct c4iw_dev *dev, struct c4iw_cq *chp,
+                         struct c4iw_qp *qhp,
+                         struct t4_cqe *err_cqe,
+                         enum ib_event_type ib_event)
+{
+       struct ib_event event;
+       struct c4iw_qp_attributes attrs;
+
+       if ((qhp->attr.state == C4IW_QP_STATE_ERROR) ||
+           (qhp->attr.state == C4IW_QP_STATE_TERMINATE)) {
+               PDBG("%s AE received after RTS - "
+                    "qp state %d qpid 0x%x status 0x%x\n", __func__,
+                    qhp->attr.state, qhp->wq.sq.qid, CQE_STATUS(err_cqe));
+               return;
+       }
+
+       printk(KERN_ERR MOD "AE qpid 0x%x opcode %d status 0x%x "
+              "type %d wrid.hi 0x%x wrid.lo 0x%x\n",
+              CQE_QPID(err_cqe), CQE_OPCODE(err_cqe),
+              CQE_STATUS(err_cqe), CQE_TYPE(err_cqe),
+              CQE_WRID_HI(err_cqe), CQE_WRID_LOW(err_cqe));
+
+       if (qhp->attr.state == C4IW_QP_STATE_RTS) {
+               attrs.next_state = C4IW_QP_STATE_TERMINATE;
+               c4iw_modify_qp(qhp->rhp, qhp, C4IW_QP_ATTR_NEXT_STATE,
+                              &attrs, 1);
+       }
+
+       event.event = ib_event;
+       event.device = chp->ibcq.device;
+       if (ib_event == IB_EVENT_CQ_ERR)
+               event.element.cq = &chp->ibcq;
+       else
+               event.element.qp = &qhp->ibqp;
+       if (qhp->ibqp.event_handler)
+               (*qhp->ibqp.event_handler)(&event, qhp->ibqp.qp_context);
+
+       (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
+}
+
+void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe)
+{
+       struct c4iw_cq *chp;
+       struct c4iw_qp *qhp;
+       u32 cqid;
+
+       spin_lock(&dev->lock);
+       qhp = get_qhp(dev, CQE_QPID(err_cqe));
+       if (!qhp) {
+               printk(KERN_ERR MOD "BAD AE qpid 0x%x opcode %d "
+                      "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x\n",
+                      CQE_QPID(err_cqe),
+                      CQE_OPCODE(err_cqe), CQE_STATUS(err_cqe),
+                      CQE_TYPE(err_cqe), CQE_WRID_HI(err_cqe),
+                      CQE_WRID_LOW(err_cqe));
+               spin_unlock(&dev->lock);
+               goto out;
+       }
+
+       if (SQ_TYPE(err_cqe))
+               cqid = qhp->attr.scq;
+       else
+               cqid = qhp->attr.rcq;
+       chp = get_chp(dev, cqid);
+       if (!chp) {
+               printk(KERN_ERR MOD "BAD AE cqid 0x%x qpid 0x%x opcode %d "
+                      "status 0x%x type %d wrid.hi 0x%x wrid.lo 0x%x\n",
+                      cqid, CQE_QPID(err_cqe),
+                      CQE_OPCODE(err_cqe), CQE_STATUS(err_cqe),
+                      CQE_TYPE(err_cqe), CQE_WRID_HI(err_cqe),
+                      CQE_WRID_LOW(err_cqe));
+               spin_unlock(&dev->lock);
+               goto out;
+       }
+
+       c4iw_qp_add_ref(&qhp->ibqp);
+       atomic_inc(&chp->refcnt);
+       spin_unlock(&dev->lock);
+
+       /* Bad incoming write */
+       if (RQ_TYPE(err_cqe) &&
+           (CQE_OPCODE(err_cqe) == FW_RI_RDMA_WRITE)) {
+               post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_REQ_ERR);
+               goto done;
+       }
+
+       switch (CQE_STATUS(err_cqe)) {
+
+       /* Completion Events */
+       case T4_ERR_SUCCESS:
+               printk(KERN_ERR MOD "AE with status 0!\n");
+               break;
+
+       case T4_ERR_STAG:
+       case T4_ERR_PDID:
+       case T4_ERR_QPID:
+       case T4_ERR_ACCESS:
+       case T4_ERR_WRAP:
+       case T4_ERR_BOUND:
+       case T4_ERR_INVALIDATE_SHARED_MR:
+       case T4_ERR_INVALIDATE_MR_WITH_MW_BOUND:
+               post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_ACCESS_ERR);
+               break;
+
+       /* Device Fatal Errors */
+       case T4_ERR_ECC:
+       case T4_ERR_ECC_PSTAG:
+       case T4_ERR_INTERNAL_ERR:
+               post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_DEVICE_FATAL);
+               break;
+
+       /* QP Fatal Errors */
+       case T4_ERR_OUT_OF_RQE:
+       case T4_ERR_PBL_ADDR_BOUND:
+       case T4_ERR_CRC:
+       case T4_ERR_MARKER:
+       case T4_ERR_PDU_LEN_ERR:
+       case T4_ERR_DDP_VERSION:
+       case T4_ERR_RDMA_VERSION:
+       case T4_ERR_OPCODE:
+       case T4_ERR_DDP_QUEUE_NUM:
+       case T4_ERR_MSN:
+       case T4_ERR_TBIT:
+       case T4_ERR_MO:
+       case T4_ERR_MSN_GAP:
+       case T4_ERR_MSN_RANGE:
+       case T4_ERR_RQE_ADDR_BOUND:
+       case T4_ERR_IRD_OVERFLOW:
+               post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_FATAL);
+               break;
+
+       default:
+               printk(KERN_ERR MOD "Unknown T4 status 0x%x QPID 0x%x\n",
+                      CQE_STATUS(err_cqe), qhp->wq.sq.qid);
+               post_qp_event(dev, chp, qhp, err_cqe, IB_EVENT_QP_FATAL);
+               break;
+       }
+done:
+       if (atomic_dec_and_test(&chp->refcnt))
+               wake_up(&chp->wait);
+       c4iw_qp_rem_ref(&qhp->ibqp);
+out:
+       return;
+}
+
+int c4iw_ev_handler(struct c4iw_dev *dev, u32 qid)
+{
+       struct c4iw_cq *chp;
+
+       chp = get_chp(dev, qid);
+       if (chp)
+               (*chp->ibcq.comp_handler)(&chp->ibcq, chp->ibcq.cq_context);
+       else
+               PDBG("%s unknown cqid 0x%x\n", __func__, qid);
+       return 0;
+}
diff --git a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h
new file mode 100644 (file)
index 0000000..a626998
--- /dev/null
@@ -0,0 +1,745 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer.
+ *      - Redistributions in binary form must reproduce the above
+ *       copyright notice, this list of conditions and the following
+ *       disclaimer in the documentation and/or other materials
+ *       provided with the distribution.
+ *
+ * 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.
+ */
+#ifndef __IW_CXGB4_H__
+#define __IW_CXGB4_H__
+
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/idr.h>
+#include <linux/workqueue.h>
+#include <linux/netdevice.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/inet.h>
+#include <linux/wait.h>
+#include <linux/kref.h>
+#include <linux/timer.h>
+#include <linux/io.h>
+#include <linux/kfifo.h>
+
+#include <asm/byteorder.h>
+
+#include <net/net_namespace.h>
+
+#include <rdma/ib_verbs.h>
+#include <rdma/iw_cm.h>
+
+#include "cxgb4.h"
+#include "cxgb4_uld.h"
+#include "l2t.h"
+#include "user.h"
+
+#define DRV_NAME "iw_cxgb4"
+#define MOD DRV_NAME ":"
+
+extern int c4iw_debug;
+#define PDBG(fmt, args...) \
+do { \
+       if (c4iw_debug) \
+               printk(MOD fmt, ## args); \
+} while (0)
+
+#include "t4.h"
+
+#define PBL_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->pbl.start)
+#define RQT_OFF(rdev_p, a) ((a) - (rdev_p)->lldi.vr->rq.start)
+
+static inline void *cplhdr(struct sk_buff *skb)
+{
+       return skb->data;
+}
+
+#define C4IW_WR_TO (10*HZ)
+
+struct c4iw_wr_wait {
+       wait_queue_head_t wait;
+       int done;
+       int ret;
+};
+
+static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp)
+{
+       wr_waitp->ret = 0;
+       wr_waitp->done = 0;
+       init_waitqueue_head(&wr_waitp->wait);
+}
+
+struct c4iw_resource {
+       struct kfifo tpt_fifo;
+       spinlock_t tpt_fifo_lock;
+       struct kfifo qid_fifo;
+       spinlock_t qid_fifo_lock;
+       struct kfifo pdid_fifo;
+       spinlock_t pdid_fifo_lock;
+};
+
+struct c4iw_qid_list {
+       struct list_head entry;
+       u32 qid;
+};
+
+struct c4iw_dev_ucontext {
+       struct list_head qpids;
+       struct list_head cqids;
+       struct mutex lock;
+};
+
+enum c4iw_rdev_flags {
+       T4_FATAL_ERROR = (1<<0),
+};
+
+struct c4iw_rdev {
+       struct c4iw_resource resource;
+       unsigned long qpshift;
+       u32 qpmask;
+       unsigned long cqshift;
+       u32 cqmask;
+       struct c4iw_dev_ucontext uctx;
+       struct gen_pool *pbl_pool;
+       struct gen_pool *rqt_pool;
+       u32 flags;
+       struct cxgb4_lld_info lldi;
+};
+
+static inline int c4iw_fatal_error(struct c4iw_rdev *rdev)
+{
+       return rdev->flags & T4_FATAL_ERROR;
+}
+
+static inline int c4iw_num_stags(struct c4iw_rdev *rdev)
+{
+       return min((int)T4_MAX_NUM_STAG, (int)(rdev->lldi.vr->stag.size >> 5));
+}
+
+struct c4iw_dev {
+       struct ib_device ibdev;
+       struct c4iw_rdev rdev;
+       u32 device_cap_flags;
+       struct idr cqidr;
+       struct idr qpidr;
+       struct idr mmidr;
+       spinlock_t lock;
+       struct list_head entry;
+       struct delayed_work db_drop_task;
+       struct dentry *debugfs_root;
+};
+
+static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev)
+{
+       return container_of(ibdev, struct c4iw_dev, ibdev);
+}
+
+static inline struct c4iw_dev *rdev_to_c4iw_dev(struct c4iw_rdev *rdev)
+{
+       return container_of(rdev, struct c4iw_dev, rdev);
+}
+
+static inline struct c4iw_cq *get_chp(struct c4iw_dev *rhp, u32 cqid)
+{
+       return idr_find(&rhp->cqidr, cqid);
+}
+
+static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qpid)
+{
+       return idr_find(&rhp->qpidr, qpid);
+}
+
+static inline struct c4iw_mr *get_mhp(struct c4iw_dev *rhp, u32 mmid)
+{
+       return idr_find(&rhp->mmidr, mmid);
+}
+
+static inline int insert_handle(struct c4iw_dev *rhp, struct idr *idr,
+                               void *handle, u32 id)
+{
+       int ret;
+       int newid;
+
+       do {
+               if (!idr_pre_get(idr, GFP_KERNEL))
+                       return -ENOMEM;
+               spin_lock_irq(&rhp->lock);
+               ret = idr_get_new_above(idr, handle, id, &newid);
+               BUG_ON(newid != id);
+               spin_unlock_irq(&rhp->lock);
+       } while (ret == -EAGAIN);
+
+       return ret;
+}
+
+static inline void remove_handle(struct c4iw_dev *rhp, struct idr *idr, u32 id)
+{
+       spin_lock_irq(&rhp->lock);
+       idr_remove(idr, id);
+       spin_unlock_irq(&rhp->lock);
+}
+
+struct c4iw_pd {
+       struct ib_pd ibpd;
+       u32 pdid;
+       struct c4iw_dev *rhp;
+};
+
+static inline struct c4iw_pd *to_c4iw_pd(struct ib_pd *ibpd)
+{
+       return container_of(ibpd, struct c4iw_pd, ibpd);
+}
+
+struct tpt_attributes {
+       u64 len;
+       u64 va_fbo;
+       enum fw_ri_mem_perms perms;
+       u32 stag;
+       u32 pdid;
+       u32 qpid;
+       u32 pbl_addr;
+       u32 pbl_size;
+       u32 state:1;
+       u32 type:2;
+       u32 rsvd:1;
+       u32 remote_invaliate_disable:1;
+       u32 zbva:1;
+       u32 mw_bind_enable:1;
+       u32 page_size:5;
+};
+
+struct c4iw_mr {
+       struct ib_mr ibmr;
+       struct ib_umem *umem;
+       struct c4iw_dev *rhp;
+       u64 kva;
+       struct tpt_attributes attr;
+};
+
+static inline struct c4iw_mr *to_c4iw_mr(struct ib_mr *ibmr)
+{
+       return container_of(ibmr, struct c4iw_mr, ibmr);
+}
+
+struct c4iw_mw {
+       struct ib_mw ibmw;
+       struct c4iw_dev *rhp;
+       u64 kva;
+       struct tpt_attributes attr;
+};
+
+static inline struct c4iw_mw *to_c4iw_mw(struct ib_mw *ibmw)
+{
+       return container_of(ibmw, struct c4iw_mw, ibmw);
+}
+
+struct c4iw_fr_page_list {
+       struct ib_fast_reg_page_list ibpl;
+       DECLARE_PCI_UNMAP_ADDR(mapping);
+       dma_addr_t dma_addr;
+       struct c4iw_dev *dev;
+       int size;
+};
+
+static inline struct c4iw_fr_page_list *to_c4iw_fr_page_list(
+                                       struct ib_fast_reg_page_list *ibpl)
+{
+       return container_of(ibpl, struct c4iw_fr_page_list, ibpl);
+}
+
+struct c4iw_cq {
+       struct ib_cq ibcq;
+       struct c4iw_dev *rhp;
+       struct t4_cq cq;
+       spinlock_t lock;
+       atomic_t refcnt;
+       wait_queue_head_t wait;
+};
+
+static inline struct c4iw_cq *to_c4iw_cq(struct ib_cq *ibcq)
+{
+       return container_of(ibcq, struct c4iw_cq, ibcq);
+}
+
+struct c4iw_mpa_attributes {
+       u8 initiator;
+       u8 recv_marker_enabled;
+       u8 xmit_marker_enabled;
+       u8 crc_enabled;
+       u8 version;
+       u8 p2p_type;
+};
+
+struct c4iw_qp_attributes {
+       u32 scq;
+       u32 rcq;
+       u32 sq_num_entries;
+       u32 rq_num_entries;
+       u32 sq_max_sges;
+       u32 sq_max_sges_rdma_write;
+       u32 rq_max_sges;
+       u32 state;
+       u8 enable_rdma_read;
+       u8 enable_rdma_write;
+       u8 enable_bind;
+       u8 enable_mmid0_fastreg;
+       u32 max_ord;
+       u32 max_ird;
+       u32 pd;
+       u32 next_state;
+       char terminate_buffer[52];
+       u32 terminate_msg_len;
+       u8 is_terminate_local;
+       struct c4iw_mpa_attributes mpa_attr;
+       struct c4iw_ep *llp_stream_handle;
+};
+
+struct c4iw_qp {
+       struct ib_qp ibqp;
+       struct c4iw_dev *rhp;
+       struct c4iw_ep *ep;
+       struct c4iw_qp_attributes attr;
+       struct t4_wq wq;
+       spinlock_t lock;
+       atomic_t refcnt;
+       wait_queue_head_t wait;
+       struct timer_list timer;
+};
+
+static inline struct c4iw_qp *to_c4iw_qp(struct ib_qp *ibqp)
+{
+       return container_of(ibqp, struct c4iw_qp, ibqp);
+}
+
+struct c4iw_ucontext {
+       struct ib_ucontext ibucontext;
+       struct c4iw_dev_ucontext uctx;
+       u32 key;
+       spinlock_t mmap_lock;
+       struct list_head mmaps;
+};
+
+static inline struct c4iw_ucontext *to_c4iw_ucontext(struct ib_ucontext *c)
+{
+       return container_of(c, struct c4iw_ucontext, ibucontext);
+}
+
+struct c4iw_mm_entry {
+       struct list_head entry;
+       u64 addr;
+       u32 key;
+       unsigned len;
+};
+
+static inline struct c4iw_mm_entry *remove_mmap(struct c4iw_ucontext *ucontext,
+                                               u32 key, unsigned len)
+{
+       struct list_head *pos, *nxt;
+       struct c4iw_mm_entry *mm;
+
+       spin_lock(&ucontext->mmap_lock);
+       list_for_each_safe(pos, nxt, &ucontext->mmaps) {
+
+               mm = list_entry(pos, struct c4iw_mm_entry, entry);
+               if (mm->key == key && mm->len == len) {
+                       list_del_init(&mm->entry);
+                       spin_unlock(&ucontext->mmap_lock);
+                       PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
+                            key, (unsigned long long) mm->addr, mm->len);
+                       return mm;
+               }
+       }
+       spin_unlock(&ucontext->mmap_lock);
+       return NULL;
+}
+
+static inline void insert_mmap(struct c4iw_ucontext *ucontext,
+                              struct c4iw_mm_entry *mm)
+{
+       spin_lock(&ucontext->mmap_lock);
+       PDBG("%s key 0x%x addr 0x%llx len %d\n", __func__,
+            mm->key, (unsigned long long) mm->addr, mm->len);
+       list_add_tail(&mm->entry, &ucontext->mmaps);
+       spin_unlock(&ucontext->mmap_lock);
+}
+
+enum c4iw_qp_attr_mask {
+       C4IW_QP_ATTR_NEXT_STATE = 1 << 0,
+       C4IW_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
+       C4IW_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
+       C4IW_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
+       C4IW_QP_ATTR_MAX_ORD = 1 << 11,
+       C4IW_QP_ATTR_MAX_IRD = 1 << 12,
+       C4IW_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
+       C4IW_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
+       C4IW_QP_ATTR_MPA_ATTR = 1 << 24,
+       C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
+       C4IW_QP_ATTR_VALID_MODIFY = (C4IW_QP_ATTR_ENABLE_RDMA_READ |
+                                    C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
+                                    C4IW_QP_ATTR_MAX_ORD |
+                                    C4IW_QP_ATTR_MAX_IRD |
+                                    C4IW_QP_ATTR_LLP_STREAM_HANDLE |
+                                    C4IW_QP_ATTR_STREAM_MSG_BUFFER |
+                                    C4IW_QP_ATTR_MPA_ATTR |
+                                    C4IW_QP_ATTR_QP_CONTEXT_ACTIVATE)
+};
+
+int c4iw_modify_qp(struct c4iw_dev *rhp,
+                               struct c4iw_qp *qhp,
+                               enum c4iw_qp_attr_mask mask,
+                               struct c4iw_qp_attributes *attrs,
+                               int internal);
+
+enum c4iw_qp_state {
+       C4IW_QP_STATE_IDLE,
+       C4IW_QP_STATE_RTS,
+       C4IW_QP_STATE_ERROR,
+       C4IW_QP_STATE_TERMINATE,
+       C4IW_QP_STATE_CLOSING,
+       C4IW_QP_STATE_TOT
+};
+
+static inline int c4iw_convert_state(enum ib_qp_state ib_state)
+{
+       switch (ib_state) {
+       case IB_QPS_RESET:
+       case IB_QPS_INIT:
+               return C4IW_QP_STATE_IDLE;
+       case IB_QPS_RTS:
+               return C4IW_QP_STATE_RTS;
+       case IB_QPS_SQD:
+               return C4IW_QP_STATE_CLOSING;
+       case IB_QPS_SQE:
+               return C4IW_QP_STATE_TERMINATE;
+       case IB_QPS_ERR:
+               return C4IW_QP_STATE_ERROR;
+       default:
+               return -1;
+       }
+}
+
+static inline u32 c4iw_ib_to_tpt_access(int a)
+{
+       return (a & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
+              (a & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0) |
+              (a & IB_ACCESS_LOCAL_WRITE ? FW_RI_MEM_ACCESS_LOCAL_WRITE : 0) |
+              FW_RI_MEM_ACCESS_LOCAL_READ;
+}
+
+static inline u32 c4iw_ib_to_tpt_bind_access(int acc)
+{
+       return (acc & IB_ACCESS_REMOTE_WRITE ? FW_RI_MEM_ACCESS_REM_WRITE : 0) |
+              (acc & IB_ACCESS_REMOTE_READ ? FW_RI_MEM_ACCESS_REM_READ : 0);
+}
+
+enum c4iw_mmid_state {
+       C4IW_STAG_STATE_VALID,
+       C4IW_STAG_STATE_INVALID
+};
+
+#define C4IW_NODE_DESC "cxgb4 Chelsio Communications"
+
+#define MPA_KEY_REQ "MPA ID Req Frame"
+#define MPA_KEY_REP "MPA ID Rep Frame"
+
+#define MPA_MAX_PRIVATE_DATA   256
+#define MPA_REJECT             0x20
+#define MPA_CRC                        0x40
+#define MPA_MARKERS            0x80
+#define MPA_FLAGS_MASK         0xE0
+
+#define c4iw_put_ep(ep) { \
+       PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__,  \
+            ep, atomic_read(&((ep)->kref.refcount))); \
+       WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
+       kref_put(&((ep)->kref), _c4iw_free_ep); \
+}
+
+#define c4iw_get_ep(ep) { \
+       PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
+            ep, atomic_read(&((ep)->kref.refcount))); \
+       kref_get(&((ep)->kref));  \
+}
+void _c4iw_free_ep(struct kref *kref);
+
+struct mpa_message {
+       u8 key[16];
+       u8 flags;
+       u8 revision;
+       __be16 private_data_size;
+       u8 private_data[0];
+};
+
+struct terminate_message {
+       u8 layer_etype;
+       u8 ecode;
+       __be16 hdrct_rsvd;
+       u8 len_hdrs[0];
+};
+
+#define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
+
+enum c4iw_layers_types {
+       LAYER_RDMAP             = 0x00,
+       LAYER_DDP               = 0x10,
+       LAYER_MPA               = 0x20,
+       RDMAP_LOCAL_CATA        = 0x00,
+       RDMAP_REMOTE_PROT       = 0x01,
+       RDMAP_REMOTE_OP         = 0x02,
+       DDP_LOCAL_CATA          = 0x00,
+       DDP_TAGGED_ERR          = 0x01,
+       DDP_UNTAGGED_ERR        = 0x02,
+       DDP_LLP                 = 0x03
+};
+
+enum c4iw_rdma_ecodes {
+       RDMAP_INV_STAG          = 0x00,
+       RDMAP_BASE_BOUNDS       = 0x01,
+       RDMAP_ACC_VIOL          = 0x02,
+       RDMAP_STAG_NOT_ASSOC    = 0x03,
+       RDMAP_TO_WRAP           = 0x04,
+       RDMAP_INV_VERS          = 0x05,
+       RDMAP_INV_OPCODE        = 0x06,
+       RDMAP_STREAM_CATA       = 0x07,
+       RDMAP_GLOBAL_CATA       = 0x08,
+       RDMAP_CANT_INV_STAG     = 0x09,
+       RDMAP_UNSPECIFIED       = 0xff
+};
+
+enum c4iw_ddp_ecodes {
+       DDPT_INV_STAG           = 0x00,
+       DDPT_BASE_BOUNDS        = 0x01,
+       DDPT_STAG_NOT_ASSOC     = 0x02,
+       DDPT_TO_WRAP            = 0x03,
+       DDPT_INV_VERS           = 0x04,
+       DDPU_INV_QN             = 0x01,
+       DDPU_INV_MSN_NOBUF      = 0x02,
+       DDPU_INV_MSN_RANGE      = 0x03,
+       DDPU_INV_MO             = 0x04,
+       DDPU_MSG_TOOBIG         = 0x05,
+       DDPU_INV_VERS           = 0x06
+};
+
+enum c4iw_mpa_ecodes {
+       MPA_CRC_ERR             = 0x02,
+       MPA_MARKER_ERR          = 0x03
+};
+
+enum c4iw_ep_state {
+       IDLE = 0,
+       LISTEN,
+       CONNECTING,
+       MPA_REQ_WAIT,
+       MPA_REQ_SENT,
+       MPA_REQ_RCVD,
+       MPA_REP_SENT,
+       FPDU_MODE,
+       ABORTING,
+       CLOSING,
+       MORIBUND,
+       DEAD,
+};
+
+enum c4iw_ep_flags {
+       PEER_ABORT_IN_PROGRESS  = 0,
+       ABORT_REQ_IN_PROGRESS   = 1,
+       RELEASE_RESOURCES       = 2,
+       CLOSE_SENT              = 3,
+};
+
+struct c4iw_ep_common {
+       struct iw_cm_id *cm_id;
+       struct c4iw_qp *qp;
+       struct c4iw_dev *dev;
+       enum c4iw_ep_state state;
+       struct kref kref;
+       spinlock_t lock;
+       struct sockaddr_in local_addr;
+       struct sockaddr_in remote_addr;
+       wait_queue_head_t waitq;
+       int rpl_done;
+       int rpl_err;
+       unsigned long flags;
+};
+
+struct c4iw_listen_ep {
+       struct c4iw_ep_common com;
+       unsigned int stid;
+       int backlog;
+};
+
+struct c4iw_ep {
+       struct c4iw_ep_common com;
+       struct c4iw_ep *parent_ep;
+       struct timer_list timer;
+       struct list_head entry;
+       unsigned int atid;
+       u32 hwtid;
+       u32 snd_seq;
+       u32 rcv_seq;
+       struct l2t_entry *l2t;
+       struct dst_entry *dst;
+       struct sk_buff *mpa_skb;
+       struct c4iw_mpa_attributes mpa_attr;
+       u8 mpa_pkt[sizeof(struct mpa_message) + MPA_MAX_PRIVATE_DATA];
+       unsigned int mpa_pkt_len;
+       u32 ird;
+       u32 ord;
+       u32 smac_idx;
+       u32 tx_chan;
+       u32 mtu;
+       u16 mss;
+       u16 emss;
+       u16 plen;
+       u16 rss_qid;
+       u16 txq_idx;
+       u8 tos;
+};
+
+static inline struct c4iw_ep *to_ep(struct iw_cm_id *cm_id)
+{
+       return cm_id->provider_data;
+}
+
+static inline struct c4iw_listen_ep *to_listen_ep(struct iw_cm_id *cm_id)
+{
+       return cm_id->provider_data;
+}
+
+static inline int compute_wscale(int win)
+{
+       int wscale = 0;
+
+       while (wscale < 14 && (65535<<wscale) < win)
+               wscale++;
+       return wscale;
+}
+
+typedef int (*c4iw_handler_func)(struct c4iw_dev *dev, struct sk_buff *skb);
+
+int c4iw_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
+                    struct l2t_entry *l2t);
+void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qpid,
+                  struct c4iw_dev_ucontext *uctx);
+u32 c4iw_get_resource(struct kfifo *fifo, spinlock_t *lock);
+void c4iw_put_resource(struct kfifo *fifo, u32 entry, spinlock_t *lock);
+int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid);
+int c4iw_init_ctrl_qp(struct c4iw_rdev *rdev);
+int c4iw_pblpool_create(struct c4iw_rdev *rdev);
+int c4iw_rqtpool_create(struct c4iw_rdev *rdev);
+void c4iw_pblpool_destroy(struct c4iw_rdev *rdev);
+void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev);
+void c4iw_destroy_resource(struct c4iw_resource *rscp);
+int c4iw_destroy_ctrl_qp(struct c4iw_rdev *rdev);
+int c4iw_register_device(struct c4iw_dev *dev);
+void c4iw_unregister_device(struct c4iw_dev *dev);
+int __init c4iw_cm_init(void);
+void __exit c4iw_cm_term(void);
+void c4iw_release_dev_ucontext(struct c4iw_rdev *rdev,
+                              struct c4iw_dev_ucontext *uctx);
+void c4iw_init_dev_ucontext(struct c4iw_rdev *rdev,
+                           struct c4iw_dev_ucontext *uctx);
+int c4iw_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
+int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
+                     struct ib_send_wr **bad_wr);
+int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
+                     struct ib_recv_wr **bad_wr);
+int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw,
+                struct ib_mw_bind *mw_bind);
+int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
+int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog);
+int c4iw_destroy_listen(struct iw_cm_id *cm_id);
+int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param);
+int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len);
+void c4iw_qp_add_ref(struct ib_qp *qp);
+void c4iw_qp_rem_ref(struct ib_qp *qp);
+void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *page_list);
+struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(
+                                       struct ib_device *device,
+                                       int page_list_len);
+struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth);
+int c4iw_dealloc_mw(struct ib_mw *mw);
+struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd);
+struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start,
+                                          u64 length, u64 virt, int acc,
+                                          struct ib_udata *udata);
+struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc);
+struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
+                                       struct ib_phys_buf *buffer_list,
+                                       int num_phys_buf,
+                                       int acc,
+                                       u64 *iova_start);
+int c4iw_reregister_phys_mem(struct ib_mr *mr,
+                                    int mr_rereg_mask,
+                                    struct ib_pd *pd,
+                                    struct ib_phys_buf *buffer_list,
+                                    int num_phys_buf,
+                                    int acc, u64 *iova_start);
+int c4iw_dereg_mr(struct ib_mr *ib_mr);
+int c4iw_destroy_cq(struct ib_cq *ib_cq);
+struct ib_cq *c4iw_create_cq(struct ib_device *ibdev, int entries,
+                                       int vector,
+                                       struct ib_ucontext *ib_context,
+                                       struct ib_udata *udata);
+int c4iw_resize_cq(struct ib_cq *cq, int cqe, struct ib_udata *udata);
+int c4iw_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
+int c4iw_destroy_qp(struct ib_qp *ib_qp);
+struct ib_qp *c4iw_create_qp(struct ib_pd *pd,
+                            struct ib_qp_init_attr *attrs,
+                            struct ib_udata *udata);
+int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+                                int attr_mask, struct ib_udata *udata);
+struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn);
+u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size);
+void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
+u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size);
+void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size);
+int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb);
+void c4iw_flush_hw_cq(struct t4_cq *cq);
+void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
+void c4iw_count_scqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
+int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp);
+int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
+int c4iw_flush_sq(struct t4_wq *wq, struct t4_cq *cq, int count);
+int c4iw_ev_handler(struct c4iw_dev *rnicp, u32 qid);
+u16 c4iw_rqes_posted(struct c4iw_qp *qhp);
+int c4iw_post_zb_read(struct c4iw_qp *qhp);
+int c4iw_post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe);
+u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
+void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
+               struct c4iw_dev_ucontext *uctx);
+u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx);
+void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
+               struct c4iw_dev_ucontext *uctx);
+void c4iw_ev_dispatch(struct c4iw_dev *dev, struct t4_cqe *err_cqe);
+
+extern struct cxgb4_client t4c_client;
+extern c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS];
+extern int c4iw_max_read_depth;
+
+#endif
diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
new file mode 100644 (file)
index 0000000..e54ff6d
--- /dev/null
@@ -0,0 +1,811 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+
+#include <rdma/ib_umem.h>
+#include <asm/atomic.h>
+
+#include "iw_cxgb4.h"
+
+#define T4_ULPTX_MIN_IO 32
+#define C4IW_MAX_INLINE_SIZE 96
+
+static int write_adapter_mem(struct c4iw_rdev *rdev, u32 addr, u32 len,
+                            void *data)
+{
+       struct sk_buff *skb;
+       struct ulp_mem_io *req;
+       struct ulptx_idata *sc;
+       u8 wr_len, *to_dp, *from_dp;
+       int copy_len, num_wqe, i, ret = 0;
+       struct c4iw_wr_wait wr_wait;
+
+       addr &= 0x7FFFFFF;
+       PDBG("%s addr 0x%x len %u\n", __func__, addr, len);
+       num_wqe = DIV_ROUND_UP(len, C4IW_MAX_INLINE_SIZE);
+       c4iw_init_wr_wait(&wr_wait);
+       for (i = 0; i < num_wqe; i++) {
+
+               copy_len = len > C4IW_MAX_INLINE_SIZE ? C4IW_MAX_INLINE_SIZE :
+                          len;
+               wr_len = roundup(sizeof *req + sizeof *sc +
+                                roundup(copy_len, T4_ULPTX_MIN_IO), 16);
+
+               skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
+               if (!skb)
+                       return -ENOMEM;
+               set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
+
+               req = (struct ulp_mem_io *)__skb_put(skb, wr_len);
+               memset(req, 0, wr_len);
+               INIT_ULPTX_WR(req, wr_len, 0, 0);
+
+               if (i == (num_wqe-1)) {
+                       req->wr.wr_hi = cpu_to_be32(FW_WR_OP(FW_ULPTX_WR) |
+                                                   FW_WR_COMPL(1));
+                       req->wr.wr_lo = (__force __be64)&wr_wait;
+               } else
+                       req->wr.wr_hi = cpu_to_be32(FW_WR_OP(FW_ULPTX_WR));
+               req->wr.wr_mid = cpu_to_be32(
+                                      FW_WR_LEN16(DIV_ROUND_UP(wr_len, 16)));
+
+               req->cmd = cpu_to_be32(ULPTX_CMD(ULP_TX_MEM_WRITE) | (1<<23));
+               req->dlen = cpu_to_be32(ULP_MEMIO_DATA_LEN(
+                               DIV_ROUND_UP(copy_len, T4_ULPTX_MIN_IO)));
+               req->len16 = cpu_to_be32(DIV_ROUND_UP(wr_len-sizeof(req->wr),
+                                                     16));
+               req->lock_addr = cpu_to_be32(ULP_MEMIO_ADDR(addr + i * 3));
+
+               sc = (struct ulptx_idata *)(req + 1);
+               sc->cmd_more = cpu_to_be32(ULPTX_CMD(ULP_TX_SC_IMM));
+               sc->len = cpu_to_be32(roundup(copy_len, T4_ULPTX_MIN_IO));
+
+               to_dp = (u8 *)(sc + 1);
+               from_dp = (u8 *)data + i * C4IW_MAX_INLINE_SIZE;
+               if (data)
+                       memcpy(to_dp, from_dp, copy_len);
+               else
+                       memset(to_dp, 0, copy_len);
+               if (copy_len % T4_ULPTX_MIN_IO)
+                       memset(to_dp + copy_len, 0, T4_ULPTX_MIN_IO -
+                              (copy_len % T4_ULPTX_MIN_IO));
+               ret = c4iw_ofld_send(rdev, skb);
+               if (ret)
+                       return ret;
+               len -= C4IW_MAX_INLINE_SIZE;
+       }
+
+       wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+       if (!wr_wait.done) {
+               printk(KERN_ERR MOD "Device %s not responding!\n",
+                      pci_name(rdev->lldi.pdev));
+               rdev->flags = T4_FATAL_ERROR;
+               ret = -EIO;
+       } else
+               ret = wr_wait.ret;
+       return ret;
+}
+
+/*
+ * Build and write a TPT entry.
+ * IN: stag key, pdid, perm, bind_enabled, zbva, to, len, page_size,
+ *     pbl_size and pbl_addr
+ * OUT: stag index
+ */
+static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
+                          u32 *stag, u8 stag_state, u32 pdid,
+                          enum fw_ri_stag_type type, enum fw_ri_mem_perms perm,
+                          int bind_enabled, u32 zbva, u64 to,
+                          u64 len, u8 page_size, u32 pbl_size, u32 pbl_addr)
+{
+       int err;
+       struct fw_ri_tpte tpt;
+       u32 stag_idx;
+       static atomic_t key;
+
+       if (c4iw_fatal_error(rdev))
+               return -EIO;
+
+       stag_state = stag_state > 0;
+       stag_idx = (*stag) >> 8;
+
+       if ((!reset_tpt_entry) && (*stag == T4_STAG_UNSET)) {
+               stag_idx = c4iw_get_resource(&rdev->resource.tpt_fifo,
+                                            &rdev->resource.tpt_fifo_lock);
+               if (!stag_idx)
+                       return -ENOMEM;
+               *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
+       }
+       PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
+            __func__, stag_state, type, pdid, stag_idx);
+
+       /* write TPT entry */
+       if (reset_tpt_entry)
+               memset(&tpt, 0, sizeof(tpt));
+       else {
+               tpt.valid_to_pdid = cpu_to_be32(F_FW_RI_TPTE_VALID |
+                       V_FW_RI_TPTE_STAGKEY((*stag & M_FW_RI_TPTE_STAGKEY)) |
+                       V_FW_RI_TPTE_STAGSTATE(stag_state) |
+                       V_FW_RI_TPTE_STAGTYPE(type) | V_FW_RI_TPTE_PDID(pdid));
+               tpt.locread_to_qpid = cpu_to_be32(V_FW_RI_TPTE_PERM(perm) |
+                       (bind_enabled ? F_FW_RI_TPTE_MWBINDEN : 0) |
+                       V_FW_RI_TPTE_ADDRTYPE((zbva ? FW_RI_ZERO_BASED_TO :
+                                                     FW_RI_VA_BASED_TO))|
+                       V_FW_RI_TPTE_PS(page_size));
+               tpt.nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32(
+                       V_FW_RI_TPTE_PBLADDR(PBL_OFF(rdev, pbl_addr)>>3));
+               tpt.len_lo = cpu_to_be32((u32)(len & 0xffffffffUL));
+               tpt.va_hi = cpu_to_be32((u32)(to >> 32));
+               tpt.va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL));
+               tpt.dca_mwbcnt_pstag = cpu_to_be32(0);
+               tpt.len_hi = cpu_to_be32((u32)(len >> 32));
+       }
+       err = write_adapter_mem(rdev, stag_idx +
+                               (rdev->lldi.vr->stag.start >> 5),
+                               sizeof(tpt), &tpt);
+
+       if (reset_tpt_entry)
+               c4iw_put_resource(&rdev->resource.tpt_fifo, stag_idx,
+                                 &rdev->resource.tpt_fifo_lock);
+       return err;
+}
+
+static int write_pbl(struct c4iw_rdev *rdev, __be64 *pbl,
+                    u32 pbl_addr, u32 pbl_size)
+{
+       int err;
+
+       PDBG("%s *pdb_addr 0x%x, pbl_base 0x%x, pbl_size %d\n",
+            __func__, pbl_addr, rdev->lldi.vr->pbl.start,
+            pbl_size);
+
+       err = write_adapter_mem(rdev, pbl_addr >> 5, pbl_size << 3, pbl);
+       return err;
+}
+
+static int dereg_mem(struct c4iw_rdev *rdev, u32 stag, u32 pbl_size,
+                    u32 pbl_addr)
+{
+       return write_tpt_entry(rdev, 1, &stag, 0, 0, 0, 0, 0, 0, 0UL, 0, 0,
+                              pbl_size, pbl_addr);
+}
+
+static int allocate_window(struct c4iw_rdev *rdev, u32 * stag, u32 pdid)
+{
+       *stag = T4_STAG_UNSET;
+       return write_tpt_entry(rdev, 0, stag, 0, pdid, FW_RI_STAG_MW, 0, 0, 0,
+                              0UL, 0, 0, 0, 0);
+}
+
+static int deallocate_window(struct c4iw_rdev *rdev, u32 stag)
+{
+       return write_tpt_entry(rdev, 1, &stag, 0, 0, 0, 0, 0, 0, 0UL, 0, 0, 0,
+                              0);
+}
+
+static int allocate_stag(struct c4iw_rdev *rdev, u32 *stag, u32 pdid,
+                        u32 pbl_size, u32 pbl_addr)
+{
+       *stag = T4_STAG_UNSET;
+       return write_tpt_entry(rdev, 0, stag, 0, pdid, FW_RI_STAG_NSMR, 0, 0, 0,
+                              0UL, 0, 0, pbl_size, pbl_addr);
+}
+
+static int finish_mem_reg(struct c4iw_mr *mhp, u32 stag)
+{
+       u32 mmid;
+
+       mhp->attr.state = 1;
+       mhp->attr.stag = stag;
+       mmid = stag >> 8;
+       mhp->ibmr.rkey = mhp->ibmr.lkey = stag;
+       PDBG("%s mmid 0x%x mhp %p\n", __func__, mmid, mhp);
+       return insert_handle(mhp->rhp, &mhp->rhp->mmidr, mhp, mmid);
+}
+
+static int register_mem(struct c4iw_dev *rhp, struct c4iw_pd *php,
+                     struct c4iw_mr *mhp, int shift)
+{
+       u32 stag = T4_STAG_UNSET;
+       int ret;
+
+       ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, mhp->attr.pdid,
+                             FW_RI_STAG_NSMR, mhp->attr.perms,
+                             mhp->attr.mw_bind_enable, mhp->attr.zbva,
+                             mhp->attr.va_fbo, mhp->attr.len, shift - 12,
+                             mhp->attr.pbl_size, mhp->attr.pbl_addr);
+       if (ret)
+               return ret;
+
+       ret = finish_mem_reg(mhp, stag);
+       if (ret)
+               dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
+                      mhp->attr.pbl_addr);
+       return ret;
+}
+
+static int reregister_mem(struct c4iw_dev *rhp, struct c4iw_pd *php,
+                         struct c4iw_mr *mhp, int shift, int npages)
+{
+       u32 stag;
+       int ret;
+
+       if (npages > mhp->attr.pbl_size)
+               return -ENOMEM;
+
+       stag = mhp->attr.stag;
+       ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, mhp->attr.pdid,
+                             FW_RI_STAG_NSMR, mhp->attr.perms,
+                             mhp->attr.mw_bind_enable, mhp->attr.zbva,
+                             mhp->attr.va_fbo, mhp->attr.len, shift - 12,
+                             mhp->attr.pbl_size, mhp->attr.pbl_addr);
+       if (ret)
+               return ret;
+
+       ret = finish_mem_reg(mhp, stag);
+       if (ret)
+               dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
+                      mhp->attr.pbl_addr);
+
+       return ret;
+}
+
+static int alloc_pbl(struct c4iw_mr *mhp, int npages)
+{
+       mhp->attr.pbl_addr = c4iw_pblpool_alloc(&mhp->rhp->rdev,
+                                                   npages << 3);
+
+       if (!mhp->attr.pbl_addr)
+               return -ENOMEM;
+
+       mhp->attr.pbl_size = npages;
+
+       return 0;
+}
+
+static int build_phys_page_list(struct ib_phys_buf *buffer_list,
+                               int num_phys_buf, u64 *iova_start,
+                               u64 *total_size, int *npages,
+                               int *shift, __be64 **page_list)
+{
+       u64 mask;
+       int i, j, n;
+
+       mask = 0;
+       *total_size = 0;
+       for (i = 0; i < num_phys_buf; ++i) {
+               if (i != 0 && buffer_list[i].addr & ~PAGE_MASK)
+                       return -EINVAL;
+               if (i != 0 && i != num_phys_buf - 1 &&
+                   (buffer_list[i].size & ~PAGE_MASK))
+                       return -EINVAL;
+               *total_size += buffer_list[i].size;
+               if (i > 0)
+                       mask |= buffer_list[i].addr;
+               else
+                       mask |= buffer_list[i].addr & PAGE_MASK;
+               if (i != num_phys_buf - 1)
+                       mask |= buffer_list[i].addr + buffer_list[i].size;
+               else
+                       mask |= (buffer_list[i].addr + buffer_list[i].size +
+                               PAGE_SIZE - 1) & PAGE_MASK;
+       }
+
+       if (*total_size > 0xFFFFFFFFULL)
+               return -ENOMEM;
+
+       /* Find largest page shift we can use to cover buffers */
+       for (*shift = PAGE_SHIFT; *shift < 27; ++(*shift))
+               if ((1ULL << *shift) & mask)
+                       break;
+
+       buffer_list[0].size += buffer_list[0].addr & ((1ULL << *shift) - 1);
+       buffer_list[0].addr &= ~0ull << *shift;
+
+       *npages = 0;
+       for (i = 0; i < num_phys_buf; ++i)
+               *npages += (buffer_list[i].size +
+                       (1ULL << *shift) - 1) >> *shift;
+
+       if (!*npages)
+               return -EINVAL;
+
+       *page_list = kmalloc(sizeof(u64) * *npages, GFP_KERNEL);
+       if (!*page_list)
+               return -ENOMEM;
+
+       n = 0;
+       for (i = 0; i < num_phys_buf; ++i)
+               for (j = 0;
+                    j < (buffer_list[i].size + (1ULL << *shift) - 1) >> *shift;
+                    ++j)
+                       (*page_list)[n++] = cpu_to_be64(buffer_list[i].addr +
+                           ((u64) j << *shift));
+
+       PDBG("%s va 0x%llx mask 0x%llx shift %d len %lld pbl_size %d\n",
+            __func__, (unsigned long long)*iova_start,
+            (unsigned long long)mask, *shift, (unsigned long long)*total_size,
+            *npages);
+
+       return 0;
+
+}
+
+int c4iw_reregister_phys_mem(struct ib_mr *mr, int mr_rereg_mask,
+                            struct ib_pd *pd, struct ib_phys_buf *buffer_list,
+                            int num_phys_buf, int acc, u64 *iova_start)
+{
+
+       struct c4iw_mr mh, *mhp;
+       struct c4iw_pd *php;
+       struct c4iw_dev *rhp;
+       __be64 *page_list = NULL;
+       int shift = 0;
+       u64 total_size;
+       int npages;
+       int ret;
+
+       PDBG("%s ib_mr %p ib_pd %p\n", __func__, mr, pd);
+
+       /* There can be no memory windows */
+       if (atomic_read(&mr->usecnt))
+               return -EINVAL;
+
+       mhp = to_c4iw_mr(mr);
+       rhp = mhp->rhp;
+       php = to_c4iw_pd(mr->pd);
+
+       /* make sure we are on the same adapter */
+       if (rhp != php->rhp)
+               return -EINVAL;
+
+       memcpy(&mh, mhp, sizeof *mhp);
+
+       if (mr_rereg_mask & IB_MR_REREG_PD)
+               php = to_c4iw_pd(pd);
+       if (mr_rereg_mask & IB_MR_REREG_ACCESS) {
+               mh.attr.perms = c4iw_ib_to_tpt_access(acc);
+               mh.attr.mw_bind_enable = (acc & IB_ACCESS_MW_BIND) ==
+                                        IB_ACCESS_MW_BIND;
+       }
+       if (mr_rereg_mask & IB_MR_REREG_TRANS) {
+               ret = build_phys_page_list(buffer_list, num_phys_buf,
+                                               iova_start,
+                                               &total_size, &npages,
+                                               &shift, &page_list);
+               if (ret)
+                       return ret;
+       }
+
+       ret = reregister_mem(rhp, php, &mh, shift, npages);
+       kfree(page_list);
+       if (ret)
+               return ret;
+       if (mr_rereg_mask & IB_MR_REREG_PD)
+               mhp->attr.pdid = php->pdid;
+       if (mr_rereg_mask & IB_MR_REREG_ACCESS)
+               mhp->attr.perms = c4iw_ib_to_tpt_access(acc);
+       if (mr_rereg_mask & IB_MR_REREG_TRANS) {
+               mhp->attr.zbva = 0;
+               mhp->attr.va_fbo = *iova_start;
+               mhp->attr.page_size = shift - 12;
+               mhp->attr.len = (u32) total_size;
+               mhp->attr.pbl_size = npages;
+       }
+
+       return 0;
+}
+
+struct ib_mr *c4iw_register_phys_mem(struct ib_pd *pd,
+                                    struct ib_phys_buf *buffer_list,
+                                    int num_phys_buf, int acc, u64 *iova_start)
+{
+       __be64 *page_list;
+       int shift;
+       u64 total_size;
+       int npages;
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+       struct c4iw_mr *mhp;
+       int ret;
+
+       PDBG("%s ib_pd %p\n", __func__, pd);
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+
+       mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
+       if (!mhp)
+               return ERR_PTR(-ENOMEM);
+
+       mhp->rhp = rhp;
+
+       /* First check that we have enough alignment */
+       if ((*iova_start & ~PAGE_MASK) != (buffer_list[0].addr & ~PAGE_MASK)) {
+               ret = -EINVAL;
+               goto err;
+       }
+
+       if (num_phys_buf > 1 &&
+           ((buffer_list[0].addr + buffer_list[0].size) & ~PAGE_MASK)) {
+               ret = -EINVAL;
+               goto err;
+       }
+
+       ret = build_phys_page_list(buffer_list, num_phys_buf, iova_start,
+                                       &total_size, &npages, &shift,
+                                       &page_list);
+       if (ret)
+               goto err;
+
+       ret = alloc_pbl(mhp, npages);
+       if (ret) {
+               kfree(page_list);
+               goto err_pbl;
+       }
+
+       ret = write_pbl(&mhp->rhp->rdev, page_list, mhp->attr.pbl_addr,
+                            npages);
+       kfree(page_list);
+       if (ret)
+               goto err_pbl;
+
+       mhp->attr.pdid = php->pdid;
+       mhp->attr.zbva = 0;
+
+       mhp->attr.perms = c4iw_ib_to_tpt_access(acc);
+       mhp->attr.va_fbo = *iova_start;
+       mhp->attr.page_size = shift - 12;
+
+       mhp->attr.len = (u32) total_size;
+       mhp->attr.pbl_size = npages;
+       ret = register_mem(rhp, php, mhp, shift);
+       if (ret)
+               goto err_pbl;
+
+       return &mhp->ibmr;
+
+err_pbl:
+       c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr,
+                             mhp->attr.pbl_size << 3);
+
+err:
+       kfree(mhp);
+       return ERR_PTR(ret);
+
+}
+
+struct ib_mr *c4iw_get_dma_mr(struct ib_pd *pd, int acc)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+       struct c4iw_mr *mhp;
+       int ret;
+       u32 stag = T4_STAG_UNSET;
+
+       PDBG("%s ib_pd %p\n", __func__, pd);
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+
+       mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
+       if (!mhp)
+               return ERR_PTR(-ENOMEM);
+
+       mhp->rhp = rhp;
+       mhp->attr.pdid = php->pdid;
+       mhp->attr.perms = c4iw_ib_to_tpt_access(acc);
+       mhp->attr.mw_bind_enable = (acc&IB_ACCESS_MW_BIND) == IB_ACCESS_MW_BIND;
+       mhp->attr.zbva = 0;
+       mhp->attr.va_fbo = 0;
+       mhp->attr.page_size = 0;
+       mhp->attr.len = ~0UL;
+       mhp->attr.pbl_size = 0;
+
+       ret = write_tpt_entry(&rhp->rdev, 0, &stag, 1, php->pdid,
+                             FW_RI_STAG_NSMR, mhp->attr.perms,
+                             mhp->attr.mw_bind_enable, 0, 0, ~0UL, 0, 0, 0);
+       if (ret)
+               goto err1;
+
+       ret = finish_mem_reg(mhp, stag);
+       if (ret)
+               goto err2;
+       return &mhp->ibmr;
+err2:
+       dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
+                 mhp->attr.pbl_addr);
+err1:
+       kfree(mhp);
+       return ERR_PTR(ret);
+}
+
+struct ib_mr *c4iw_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
+                              u64 virt, int acc, struct ib_udata *udata)
+{
+       __be64 *pages;
+       int shift, n, len;
+       int i, j, k;
+       int err = 0;
+       struct ib_umem_chunk *chunk;
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+       struct c4iw_mr *mhp;
+
+       PDBG("%s ib_pd %p\n", __func__, pd);
+
+       if (length == ~0ULL)
+               return ERR_PTR(-EINVAL);
+
+       if ((length + start) < start)
+               return ERR_PTR(-EINVAL);
+
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+       mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
+       if (!mhp)
+               return ERR_PTR(-ENOMEM);
+
+       mhp->rhp = rhp;
+
+       mhp->umem = ib_umem_get(pd->uobject->context, start, length, acc, 0);
+       if (IS_ERR(mhp->umem)) {
+               err = PTR_ERR(mhp->umem);
+               kfree(mhp);
+               return ERR_PTR(err);
+       }
+
+       shift = ffs(mhp->umem->page_size) - 1;
+
+       n = 0;
+       list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
+               n += chunk->nents;
+
+       err = alloc_pbl(mhp, n);
+       if (err)
+               goto err;
+
+       pages = (__be64 *) __get_free_page(GFP_KERNEL);
+       if (!pages) {
+               err = -ENOMEM;
+               goto err_pbl;
+       }
+
+       i = n = 0;
+
+       list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
+               for (j = 0; j < chunk->nmap; ++j) {
+                       len = sg_dma_len(&chunk->page_list[j]) >> shift;
+                       for (k = 0; k < len; ++k) {
+                               pages[i++] = cpu_to_be64(sg_dma_address(
+                                       &chunk->page_list[j]) +
+                                       mhp->umem->page_size * k);
+                               if (i == PAGE_SIZE / sizeof *pages) {
+                                       err = write_pbl(&mhp->rhp->rdev,
+                                             pages,
+                                             mhp->attr.pbl_addr + (n << 3), i);
+                                       if (err)
+                                               goto pbl_done;
+                                       n += i;
+                                       i = 0;
+                               }
+                       }
+               }
+
+       if (i)
+               err = write_pbl(&mhp->rhp->rdev, pages,
+                                    mhp->attr.pbl_addr + (n << 3), i);
+
+pbl_done:
+       free_page((unsigned long) pages);
+       if (err)
+               goto err_pbl;
+
+       mhp->attr.pdid = php->pdid;
+       mhp->attr.zbva = 0;
+       mhp->attr.perms = c4iw_ib_to_tpt_access(acc);
+       mhp->attr.va_fbo = virt;
+       mhp->attr.page_size = shift - 12;
+       mhp->attr.len = (u32) length;
+
+       err = register_mem(rhp, php, mhp, shift);
+       if (err)
+               goto err_pbl;
+
+       return &mhp->ibmr;
+
+err_pbl:
+       c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr,
+                             mhp->attr.pbl_size << 3);
+
+err:
+       ib_umem_release(mhp->umem);
+       kfree(mhp);
+       return ERR_PTR(err);
+}
+
+struct ib_mw *c4iw_alloc_mw(struct ib_pd *pd)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+       struct c4iw_mw *mhp;
+       u32 mmid;
+       u32 stag = 0;
+       int ret;
+
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+       mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
+       if (!mhp)
+               return ERR_PTR(-ENOMEM);
+       ret = allocate_window(&rhp->rdev, &stag, php->pdid);
+       if (ret) {
+               kfree(mhp);
+               return ERR_PTR(ret);
+       }
+       mhp->rhp = rhp;
+       mhp->attr.pdid = php->pdid;
+       mhp->attr.type = FW_RI_STAG_MW;
+       mhp->attr.stag = stag;
+       mmid = (stag) >> 8;
+       mhp->ibmw.rkey = stag;
+       if (insert_handle(rhp, &rhp->mmidr, mhp, mmid)) {
+               deallocate_window(&rhp->rdev, mhp->attr.stag);
+               kfree(mhp);
+               return ERR_PTR(-ENOMEM);
+       }
+       PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__, mmid, mhp, stag);
+       return &(mhp->ibmw);
+}
+
+int c4iw_dealloc_mw(struct ib_mw *mw)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_mw *mhp;
+       u32 mmid;
+
+       mhp = to_c4iw_mw(mw);
+       rhp = mhp->rhp;
+       mmid = (mw->rkey) >> 8;
+       deallocate_window(&rhp->rdev, mhp->attr.stag);
+       remove_handle(rhp, &rhp->mmidr, mmid);
+       kfree(mhp);
+       PDBG("%s ib_mw %p mmid 0x%x ptr %p\n", __func__, mw, mmid, mhp);
+       return 0;
+}
+
+struct ib_mr *c4iw_alloc_fast_reg_mr(struct ib_pd *pd, int pbl_depth)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+       struct c4iw_mr *mhp;
+       u32 mmid;
+       u32 stag = 0;
+       int ret = 0;
+
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+       mhp = kzalloc(sizeof(*mhp), GFP_KERNEL);
+       if (!mhp)
+               goto err;
+
+       mhp->rhp = rhp;
+       ret = alloc_pbl(mhp, pbl_depth);
+       if (ret)
+               goto err1;
+       mhp->attr.pbl_size = pbl_depth;
+       ret = allocate_stag(&rhp->rdev, &stag, php->pdid,
+                                mhp->attr.pbl_size, mhp->attr.pbl_addr);
+       if (ret)
+               goto err2;
+       mhp->attr.pdid = php->pdid;
+       mhp->attr.type = FW_RI_STAG_NSMR;
+       mhp->attr.stag = stag;
+       mhp->attr.state = 1;
+       mmid = (stag) >> 8;
+       mhp->ibmr.rkey = mhp->ibmr.lkey = stag;
+       if (insert_handle(rhp, &rhp->mmidr, mhp, mmid))
+               goto err3;
+
+       PDBG("%s mmid 0x%x mhp %p stag 0x%x\n", __func__, mmid, mhp, stag);
+       return &(mhp->ibmr);
+err3:
+       dereg_mem(&rhp->rdev, stag, mhp->attr.pbl_size,
+                      mhp->attr.pbl_addr);
+err2:
+       c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr,
+                             mhp->attr.pbl_size << 3);
+err1:
+       kfree(mhp);
+err:
+       return ERR_PTR(ret);
+}
+
+struct ib_fast_reg_page_list *c4iw_alloc_fastreg_pbl(struct ib_device *device,
+                                                    int page_list_len)
+{
+       struct c4iw_fr_page_list *c4pl;
+       struct c4iw_dev *dev = to_c4iw_dev(device);
+       dma_addr_t dma_addr;
+       int size = sizeof *c4pl + page_list_len * sizeof(u64);
+
+       if (page_list_len > T4_MAX_FR_DEPTH)
+               return ERR_PTR(-EINVAL);
+
+       c4pl = dma_alloc_coherent(&dev->rdev.lldi.pdev->dev, size,
+                                 &dma_addr, GFP_KERNEL);
+       if (!c4pl)
+               return ERR_PTR(-ENOMEM);
+
+       pci_unmap_addr_set(c4pl, mapping, dma_addr);
+       c4pl->dma_addr = dma_addr;
+       c4pl->dev = dev;
+       c4pl->size = size;
+       c4pl->ibpl.page_list = (u64 *)(c4pl + 1);
+       c4pl->ibpl.max_page_list_len = page_list_len;
+
+       return &c4pl->ibpl;
+}
+
+void c4iw_free_fastreg_pbl(struct ib_fast_reg_page_list *ibpl)
+{
+       struct c4iw_fr_page_list *c4pl = to_c4iw_fr_page_list(ibpl);
+
+       dma_free_coherent(&c4pl->dev->rdev.lldi.pdev->dev, c4pl->size,
+                         c4pl, pci_unmap_addr(c4pl, mapping));
+}
+
+int c4iw_dereg_mr(struct ib_mr *ib_mr)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_mr *mhp;
+       u32 mmid;
+
+       PDBG("%s ib_mr %p\n", __func__, ib_mr);
+       /* There can be no memory windows */
+       if (atomic_read(&ib_mr->usecnt))
+               return -EINVAL;
+
+       mhp = to_c4iw_mr(ib_mr);
+       rhp = mhp->rhp;
+       mmid = mhp->attr.stag >> 8;
+       dereg_mem(&rhp->rdev, mhp->attr.stag, mhp->attr.pbl_size,
+                      mhp->attr.pbl_addr);
+       if (mhp->attr.pbl_size)
+               c4iw_pblpool_free(&mhp->rhp->rdev, mhp->attr.pbl_addr,
+                                 mhp->attr.pbl_size << 3);
+       remove_handle(rhp, &rhp->mmidr, mmid);
+       if (mhp->kva)
+               kfree((void *) (unsigned long) mhp->kva);
+       if (mhp->umem)
+               ib_umem_release(mhp->umem);
+       PDBG("%s mmid 0x%x ptr %p\n", __func__, mmid, mhp);
+       kfree(mhp);
+       return 0;
+}
diff --git a/drivers/infiniband/hw/cxgb4/provider.c b/drivers/infiniband/hw/cxgb4/provider.c
new file mode 100644 (file)
index 0000000..dfc4902
--- /dev/null
@@ -0,0 +1,518 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/device.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+#include <linux/ethtool.h>
+#include <linux/rtnetlink.h>
+#include <linux/inetdevice.h>
+#include <linux/io.h>
+
+#include <asm/irq.h>
+#include <asm/byteorder.h>
+
+#include <rdma/iw_cm.h>
+#include <rdma/ib_verbs.h>
+#include <rdma/ib_smi.h>
+#include <rdma/ib_umem.h>
+#include <rdma/ib_user_verbs.h>
+
+#include "iw_cxgb4.h"
+
+static int fastreg_support;
+module_param(fastreg_support, int, 0644);
+MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=0)");
+
+static int c4iw_modify_port(struct ib_device *ibdev,
+                           u8 port, int port_modify_mask,
+                           struct ib_port_modify *props)
+{
+       return -ENOSYS;
+}
+
+static struct ib_ah *c4iw_ah_create(struct ib_pd *pd,
+                                   struct ib_ah_attr *ah_attr)
+{
+       return ERR_PTR(-ENOSYS);
+}
+
+static int c4iw_ah_destroy(struct ib_ah *ah)
+{
+       return -ENOSYS;
+}
+
+static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
+{
+       return -ENOSYS;
+}
+
+static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
+{
+       return -ENOSYS;
+}
+
+static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
+                           u8 port_num, struct ib_wc *in_wc,
+                           struct ib_grh *in_grh, struct ib_mad *in_mad,
+                           struct ib_mad *out_mad)
+{
+       return -ENOSYS;
+}
+
+static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
+{
+       struct c4iw_dev *rhp = to_c4iw_dev(context->device);
+       struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
+       struct c4iw_mm_entry *mm, *tmp;
+
+       PDBG("%s context %p\n", __func__, context);
+       list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
+               kfree(mm);
+       c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
+       kfree(ucontext);
+       return 0;
+}
+
+static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
+                                              struct ib_udata *udata)
+{
+       struct c4iw_ucontext *context;
+       struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
+
+       PDBG("%s ibdev %p\n", __func__, ibdev);
+       context = kzalloc(sizeof(*context), GFP_KERNEL);
+       if (!context)
+               return ERR_PTR(-ENOMEM);
+       c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
+       INIT_LIST_HEAD(&context->mmaps);
+       spin_lock_init(&context->mmap_lock);
+       return &context->ibucontext;
+}
+
+static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
+{
+       int len = vma->vm_end - vma->vm_start;
+       u32 key = vma->vm_pgoff << PAGE_SHIFT;
+       struct c4iw_rdev *rdev;
+       int ret = 0;
+       struct c4iw_mm_entry *mm;
+       struct c4iw_ucontext *ucontext;
+       u64 addr;
+
+       PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff,
+            key, len);
+
+       if (vma->vm_start & (PAGE_SIZE-1))
+               return -EINVAL;
+
+       rdev = &(to_c4iw_dev(context->device)->rdev);
+       ucontext = to_c4iw_ucontext(context);
+
+       mm = remove_mmap(ucontext, key, len);
+       if (!mm)
+               return -EINVAL;
+       addr = mm->addr;
+       kfree(mm);
+
+       if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
+           (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
+                      pci_resource_len(rdev->lldi.pdev, 2)))) {
+
+               /*
+                * Map T4 DB register.
+                */
+               if (vma->vm_flags & VM_READ)
+                       return -EPERM;
+
+               vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
+               vma->vm_flags |= VM_DONTCOPY | VM_DONTEXPAND;
+               vma->vm_flags &= ~VM_MAYREAD;
+               ret = io_remap_pfn_range(vma, vma->vm_start,
+                                        addr >> PAGE_SHIFT,
+                                        len, vma->vm_page_prot);
+       } else {
+
+               /*
+                * Map WQ or CQ contig dma memory...
+                */
+               ret = remap_pfn_range(vma, vma->vm_start,
+                                     addr >> PAGE_SHIFT,
+                                     len, vma->vm_page_prot);
+       }
+
+       return ret;
+}
+
+static int c4iw_deallocate_pd(struct ib_pd *pd)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_pd *php;
+
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+       PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
+       c4iw_put_resource(&rhp->rdev.resource.pdid_fifo, php->pdid,
+                         &rhp->rdev.resource.pdid_fifo_lock);
+       kfree(php);
+       return 0;
+}
+
+static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
+                                     struct ib_ucontext *context,
+                                     struct ib_udata *udata)
+{
+       struct c4iw_pd *php;
+       u32 pdid;
+       struct c4iw_dev *rhp;
+
+       PDBG("%s ibdev %p\n", __func__, ibdev);
+       rhp = (struct c4iw_dev *) ibdev;
+       pdid =  c4iw_get_resource(&rhp->rdev.resource.pdid_fifo,
+                                 &rhp->rdev.resource.pdid_fifo_lock);
+       if (!pdid)
+               return ERR_PTR(-EINVAL);
+       php = kzalloc(sizeof(*php), GFP_KERNEL);
+       if (!php) {
+               c4iw_put_resource(&rhp->rdev.resource.pdid_fifo, pdid,
+                                 &rhp->rdev.resource.pdid_fifo_lock);
+               return ERR_PTR(-ENOMEM);
+       }
+       php->pdid = pdid;
+       php->rhp = rhp;
+       if (context) {
+               if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
+                       c4iw_deallocate_pd(&php->ibpd);
+                       return ERR_PTR(-EFAULT);
+               }
+       }
+       PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
+       return &php->ibpd;
+}
+
+static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
+                          u16 *pkey)
+{
+       PDBG("%s ibdev %p\n", __func__, ibdev);
+       *pkey = 0;
+       return 0;
+}
+
+static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
+                         union ib_gid *gid)
+{
+       struct c4iw_dev *dev;
+
+       PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
+              __func__, ibdev, port, index, gid);
+       dev = to_c4iw_dev(ibdev);
+       BUG_ON(port == 0);
+       memset(&(gid->raw[0]), 0, sizeof(gid->raw));
+       memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
+       return 0;
+}
+
+static int c4iw_query_device(struct ib_device *ibdev,
+                            struct ib_device_attr *props)
+{
+
+       struct c4iw_dev *dev;
+       PDBG("%s ibdev %p\n", __func__, ibdev);
+
+       dev = to_c4iw_dev(ibdev);
+       memset(props, 0, sizeof *props);
+       memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
+       props->hw_ver = dev->rdev.lldi.adapter_type;
+       props->fw_ver = dev->rdev.lldi.fw_vers;
+       props->device_cap_flags = dev->device_cap_flags;
+       props->page_size_cap = T4_PAGESIZE_MASK;
+       props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
+       props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
+       props->max_mr_size = T4_MAX_MR_SIZE;
+       props->max_qp = T4_MAX_NUM_QP;
+       props->max_qp_wr = T4_MAX_QP_DEPTH;
+       props->max_sge = T4_MAX_RECV_SGE;
+       props->max_sge_rd = 1;
+       props->max_qp_rd_atom = c4iw_max_read_depth;
+       props->max_qp_init_rd_atom = c4iw_max_read_depth;
+       props->max_cq = T4_MAX_NUM_CQ;
+       props->max_cqe = T4_MAX_CQ_DEPTH;
+       props->max_mr = c4iw_num_stags(&dev->rdev);
+       props->max_pd = T4_MAX_NUM_PD;
+       props->local_ca_ack_delay = 0;
+       props->max_fast_reg_page_list_len = T4_MAX_FR_DEPTH;
+
+       return 0;
+}
+
+static int c4iw_query_port(struct ib_device *ibdev, u8 port,
+                          struct ib_port_attr *props)
+{
+       struct c4iw_dev *dev;
+       struct net_device *netdev;
+       struct in_device *inetdev;
+
+       PDBG("%s ibdev %p\n", __func__, ibdev);
+
+       dev = to_c4iw_dev(ibdev);
+       netdev = dev->rdev.lldi.ports[port-1];
+
+       memset(props, 0, sizeof(struct ib_port_attr));
+       props->max_mtu = IB_MTU_4096;
+       if (netdev->mtu >= 4096)
+               props->active_mtu = IB_MTU_4096;
+       else if (netdev->mtu >= 2048)
+               props->active_mtu = IB_MTU_2048;
+       else if (netdev->mtu >= 1024)
+               props->active_mtu = IB_MTU_1024;
+       else if (netdev->mtu >= 512)
+               props->active_mtu = IB_MTU_512;
+       else
+               props->active_mtu = IB_MTU_256;
+
+       if (!netif_carrier_ok(netdev))
+               props->state = IB_PORT_DOWN;
+       else {
+               inetdev = in_dev_get(netdev);
+               if (inetdev) {
+                       if (inetdev->ifa_list)
+                               props->state = IB_PORT_ACTIVE;
+                       else
+                               props->state = IB_PORT_INIT;
+                       in_dev_put(inetdev);
+               } else
+                       props->state = IB_PORT_INIT;
+       }
+
+       props->port_cap_flags =
+           IB_PORT_CM_SUP |
+           IB_PORT_SNMP_TUNNEL_SUP |
+           IB_PORT_REINIT_SUP |
+           IB_PORT_DEVICE_MGMT_SUP |
+           IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
+       props->gid_tbl_len = 1;
+       props->pkey_tbl_len = 1;
+       props->active_width = 2;
+       props->active_speed = 2;
+       props->max_msg_sz = -1;
+
+       return 0;
+}
+
+static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
+                       char *buf)
+{
+       struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
+                                                ibdev.dev);
+       PDBG("%s dev 0x%p\n", __func__, dev);
+       return sprintf(buf, "%d\n", c4iw_dev->rdev.lldi.adapter_type);
+}
+
+static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
+                          char *buf)
+{
+       struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
+                                                ibdev.dev);
+       PDBG("%s dev 0x%p\n", __func__, dev);
+
+       return sprintf(buf, "%u.%u.%u.%u\n",
+                       FW_HDR_FW_VER_MAJOR_GET(c4iw_dev->rdev.lldi.fw_vers),
+                       FW_HDR_FW_VER_MINOR_GET(c4iw_dev->rdev.lldi.fw_vers),
+                       FW_HDR_FW_VER_MICRO_GET(c4iw_dev->rdev.lldi.fw_vers),
+                       FW_HDR_FW_VER_BUILD_GET(c4iw_dev->rdev.lldi.fw_vers));
+}
+
+static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
+                       char *buf)
+{
+       struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
+                                                ibdev.dev);
+       struct ethtool_drvinfo info;
+       struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
+
+       PDBG("%s dev 0x%p\n", __func__, dev);
+       lldev->ethtool_ops->get_drvinfo(lldev, &info);
+       return sprintf(buf, "%s\n", info.driver);
+}
+
+static ssize_t show_board(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
+                                                ibdev.dev);
+       PDBG("%s dev 0x%p\n", __func__, dev);
+       return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
+                      c4iw_dev->rdev.lldi.pdev->device);
+}
+
+static int c4iw_get_mib(struct ib_device *ibdev,
+                       union rdma_protocol_stats *stats)
+{
+       return -ENOSYS;
+}
+
+static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
+static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
+static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
+static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
+
+static struct device_attribute *c4iw_class_attributes[] = {
+       &dev_attr_hw_rev,
+       &dev_attr_fw_ver,
+       &dev_attr_hca_type,
+       &dev_attr_board_id,
+};
+
+int c4iw_register_device(struct c4iw_dev *dev)
+{
+       int ret;
+       int i;
+
+       PDBG("%s c4iw_dev %p\n", __func__, dev);
+       BUG_ON(!dev->rdev.lldi.ports[0]);
+       strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
+       memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
+       memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
+       dev->ibdev.owner = THIS_MODULE;
+       dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
+       if (fastreg_support)
+               dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
+       dev->ibdev.local_dma_lkey = 0;
+       dev->ibdev.uverbs_cmd_mask =
+           (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
+           (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
+           (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
+           (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
+           (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
+           (1ull << IB_USER_VERBS_CMD_REG_MR) |
+           (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
+           (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
+           (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
+           (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
+           (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
+           (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
+           (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
+           (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
+           (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
+           (1ull << IB_USER_VERBS_CMD_POST_SEND) |
+           (1ull << IB_USER_VERBS_CMD_POST_RECV);
+       dev->ibdev.node_type = RDMA_NODE_RNIC;
+       memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
+       dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
+       dev->ibdev.num_comp_vectors = 1;
+       dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev);
+       dev->ibdev.query_device = c4iw_query_device;
+       dev->ibdev.query_port = c4iw_query_port;
+       dev->ibdev.modify_port = c4iw_modify_port;
+       dev->ibdev.query_pkey = c4iw_query_pkey;
+       dev->ibdev.query_gid = c4iw_query_gid;
+       dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
+       dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
+       dev->ibdev.mmap = c4iw_mmap;
+       dev->ibdev.alloc_pd = c4iw_allocate_pd;
+       dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
+       dev->ibdev.create_ah = c4iw_ah_create;
+       dev->ibdev.destroy_ah = c4iw_ah_destroy;
+       dev->ibdev.create_qp = c4iw_create_qp;
+       dev->ibdev.modify_qp = c4iw_ib_modify_qp;
+       dev->ibdev.destroy_qp = c4iw_destroy_qp;
+       dev->ibdev.create_cq = c4iw_create_cq;
+       dev->ibdev.destroy_cq = c4iw_destroy_cq;
+       dev->ibdev.resize_cq = c4iw_resize_cq;
+       dev->ibdev.poll_cq = c4iw_poll_cq;
+       dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
+       dev->ibdev.reg_phys_mr = c4iw_register_phys_mem;
+       dev->ibdev.rereg_phys_mr = c4iw_reregister_phys_mem;
+       dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
+       dev->ibdev.dereg_mr = c4iw_dereg_mr;
+       dev->ibdev.alloc_mw = c4iw_alloc_mw;
+       dev->ibdev.bind_mw = c4iw_bind_mw;
+       dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
+       dev->ibdev.alloc_fast_reg_mr = c4iw_alloc_fast_reg_mr;
+       dev->ibdev.alloc_fast_reg_page_list = c4iw_alloc_fastreg_pbl;
+       dev->ibdev.free_fast_reg_page_list = c4iw_free_fastreg_pbl;
+       dev->ibdev.attach_mcast = c4iw_multicast_attach;
+       dev->ibdev.detach_mcast = c4iw_multicast_detach;
+       dev->ibdev.process_mad = c4iw_process_mad;
+       dev->ibdev.req_notify_cq = c4iw_arm_cq;
+       dev->ibdev.post_send = c4iw_post_send;
+       dev->ibdev.post_recv = c4iw_post_receive;
+       dev->ibdev.get_protocol_stats = c4iw_get_mib;
+
+       dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
+       if (!dev->ibdev.iwcm)
+               return -ENOMEM;
+
+       dev->ibdev.iwcm->connect = c4iw_connect;
+       dev->ibdev.iwcm->accept = c4iw_accept_cr;
+       dev->ibdev.iwcm->reject = c4iw_reject_cr;
+       dev->ibdev.iwcm->create_listen = c4iw_create_listen;
+       dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
+       dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
+       dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
+       dev->ibdev.iwcm->get_qp = c4iw_get_qp;
+
+       ret = ib_register_device(&dev->ibdev);
+       if (ret)
+               goto bail1;
+
+       for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
+               ret = device_create_file(&dev->ibdev.dev,
+                                        c4iw_class_attributes[i]);
+               if (ret)
+                       goto bail2;
+       }
+       return 0;
+bail2:
+       ib_unregister_device(&dev->ibdev);
+bail1:
+       kfree(dev->ibdev.iwcm);
+       return ret;
+}
+
+void c4iw_unregister_device(struct c4iw_dev *dev)
+{
+       int i;
+
+       PDBG("%s c4iw_dev %p\n", __func__, dev);
+       for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
+               device_remove_file(&dev->ibdev.dev,
+                                  c4iw_class_attributes[i]);
+       ib_unregister_device(&dev->ibdev);
+       kfree(dev->ibdev.iwcm);
+       return;
+}
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
new file mode 100644 (file)
index 0000000..83a01dc
--- /dev/null
@@ -0,0 +1,1577 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#include "iw_cxgb4.h"
+
+static int destroy_qp(struct c4iw_rdev *rdev, struct t4_wq *wq,
+                     struct c4iw_dev_ucontext *uctx)
+{
+       /*
+        * uP clears EQ contexts when the connection exits rdma mode,
+        * so no need to post a RESET WR for these EQs.
+        */
+       dma_free_coherent(&(rdev->lldi.pdev->dev),
+                         wq->rq.memsize, wq->rq.queue,
+                         pci_unmap_addr(&wq->rq, mapping));
+       dma_free_coherent(&(rdev->lldi.pdev->dev),
+                         wq->sq.memsize, wq->sq.queue,
+                         pci_unmap_addr(&wq->sq, mapping));
+       c4iw_rqtpool_free(rdev, wq->rq.rqt_hwaddr, wq->rq.rqt_size);
+       kfree(wq->rq.sw_rq);
+       kfree(wq->sq.sw_sq);
+       c4iw_put_qpid(rdev, wq->rq.qid, uctx);
+       c4iw_put_qpid(rdev, wq->sq.qid, uctx);
+       return 0;
+}
+
+static int create_qp(struct c4iw_rdev *rdev, struct t4_wq *wq,
+                    struct t4_cq *rcq, struct t4_cq *scq,
+                    struct c4iw_dev_ucontext *uctx)
+{
+       int user = (uctx != &rdev->uctx);
+       struct fw_ri_res_wr *res_wr;
+       struct fw_ri_res *res;
+       int wr_len;
+       struct c4iw_wr_wait wr_wait;
+       struct sk_buff *skb;
+       int ret;
+       int eqsize;
+
+       wq->sq.qid = c4iw_get_qpid(rdev, uctx);
+       if (!wq->sq.qid)
+               return -ENOMEM;
+
+       wq->rq.qid = c4iw_get_qpid(rdev, uctx);
+       if (!wq->rq.qid)
+               goto err1;
+
+       if (!user) {
+               wq->sq.sw_sq = kzalloc(wq->sq.size * sizeof *wq->sq.sw_sq,
+                                GFP_KERNEL);
+               if (!wq->sq.sw_sq)
+                       goto err2;
+
+               wq->rq.sw_rq = kzalloc(wq->rq.size * sizeof *wq->rq.sw_rq,
+                                GFP_KERNEL);
+               if (!wq->rq.sw_rq)
+                       goto err3;
+       }
+
+       /*
+        * RQT must be a power of 2.
+        */
+       wq->rq.rqt_size = roundup_pow_of_two(wq->rq.size);
+       wq->rq.rqt_hwaddr = c4iw_rqtpool_alloc(rdev, wq->rq.rqt_size);
+       if (!wq->rq.rqt_hwaddr)
+               goto err4;
+
+       wq->sq.queue = dma_alloc_coherent(&(rdev->lldi.pdev->dev),
+                                         wq->sq.memsize, &(wq->sq.dma_addr),
+                                         GFP_KERNEL);
+       if (!wq->sq.queue)
+               goto err5;
+       memset(wq->sq.queue, 0, wq->sq.memsize);
+       pci_unmap_addr_set(&wq->sq, mapping, wq->sq.dma_addr);
+
+       wq->rq.queue = dma_alloc_coherent(&(rdev->lldi.pdev->dev),
+                                         wq->rq.memsize, &(wq->rq.dma_addr),
+                                         GFP_KERNEL);
+       if (!wq->rq.queue)
+               goto err6;
+       PDBG("%s sq base va 0x%p pa 0x%llx rq base va 0x%p pa 0x%llx\n",
+               __func__, wq->sq.queue,
+               (unsigned long long)virt_to_phys(wq->sq.queue),
+               wq->rq.queue,
+               (unsigned long long)virt_to_phys(wq->rq.queue));
+       memset(wq->rq.queue, 0, wq->rq.memsize);
+       pci_unmap_addr_set(&wq->rq, mapping, wq->rq.dma_addr);
+
+       wq->db = rdev->lldi.db_reg;
+       wq->gts = rdev->lldi.gts_reg;
+       if (user) {
+               wq->sq.udb = (u64)pci_resource_start(rdev->lldi.pdev, 2) +
+                                       (wq->sq.qid << rdev->qpshift);
+               wq->sq.udb &= PAGE_MASK;
+               wq->rq.udb = (u64)pci_resource_start(rdev->lldi.pdev, 2) +
+                                       (wq->rq.qid << rdev->qpshift);
+               wq->rq.udb &= PAGE_MASK;
+       }
+       wq->rdev = rdev;
+       wq->rq.msn = 1;
+
+       /* build fw_ri_res_wr */
+       wr_len = sizeof *res_wr + 2 * sizeof *res;
+
+       skb = alloc_skb(wr_len, GFP_KERNEL | __GFP_NOFAIL);
+       if (!skb) {
+               ret = -ENOMEM;
+               goto err7;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_CONTROL, 0);
+
+       res_wr = (struct fw_ri_res_wr *)__skb_put(skb, wr_len);
+       memset(res_wr, 0, wr_len);
+       res_wr->op_nres = cpu_to_be32(
+                       FW_WR_OP(FW_RI_RES_WR) |
+                       V_FW_RI_RES_WR_NRES(2) |
+                       FW_WR_COMPL(1));
+       res_wr->len16_pkd = cpu_to_be32(DIV_ROUND_UP(wr_len, 16));
+       res_wr->cookie = (u64)&wr_wait;
+       res = res_wr->res;
+       res->u.sqrq.restype = FW_RI_RES_TYPE_SQ;
+       res->u.sqrq.op = FW_RI_RES_OP_WRITE;
+
+       /*
+        * eqsize is the number of 64B entries plus the status page size.
+        */
+       eqsize = wq->sq.size * T4_SQ_NUM_SLOTS + T4_EQ_STATUS_ENTRIES;
+
+       res->u.sqrq.fetchszm_to_iqid = cpu_to_be32(
+               V_FW_RI_RES_WR_HOSTFCMODE(0) |  /* no host cidx updates */
+               V_FW_RI_RES_WR_CPRIO(0) |       /* don't keep in chip cache */
+               V_FW_RI_RES_WR_PCIECHN(0) |     /* set by uP at ri_init time */
+               V_FW_RI_RES_WR_IQID(scq->cqid));
+       res->u.sqrq.dcaen_to_eqsize = cpu_to_be32(
+               V_FW_RI_RES_WR_DCAEN(0) |
+               V_FW_RI_RES_WR_DCACPU(0) |
+               V_FW_RI_RES_WR_FBMIN(3) |
+               V_FW_RI_RES_WR_FBMAX(3) |
+               V_FW_RI_RES_WR_CIDXFTHRESHO(0) |
+               V_FW_RI_RES_WR_CIDXFTHRESH(0) |
+               V_FW_RI_RES_WR_EQSIZE(eqsize));
+       res->u.sqrq.eqid = cpu_to_be32(wq->sq.qid);
+       res->u.sqrq.eqaddr = cpu_to_be64(wq->sq.dma_addr);
+       res++;
+       res->u.sqrq.restype = FW_RI_RES_TYPE_RQ;
+       res->u.sqrq.op = FW_RI_RES_OP_WRITE;
+
+       /*
+        * eqsize is the number of 64B entries plus the status page size.
+        */
+       eqsize = wq->rq.size * T4_RQ_NUM_SLOTS + T4_EQ_STATUS_ENTRIES;
+       res->u.sqrq.fetchszm_to_iqid = cpu_to_be32(
+               V_FW_RI_RES_WR_HOSTFCMODE(0) |  /* no host cidx updates */
+               V_FW_RI_RES_WR_CPRIO(0) |       /* don't keep in chip cache */
+               V_FW_RI_RES_WR_PCIECHN(0) |     /* set by uP at ri_init time */
+               V_FW_RI_RES_WR_IQID(rcq->cqid));
+       res->u.sqrq.dcaen_to_eqsize = cpu_to_be32(
+               V_FW_RI_RES_WR_DCAEN(0) |
+               V_FW_RI_RES_WR_DCACPU(0) |
+               V_FW_RI_RES_WR_FBMIN(3) |
+               V_FW_RI_RES_WR_FBMAX(3) |
+               V_FW_RI_RES_WR_CIDXFTHRESHO(0) |
+               V_FW_RI_RES_WR_CIDXFTHRESH(0) |
+               V_FW_RI_RES_WR_EQSIZE(eqsize));
+       res->u.sqrq.eqid = cpu_to_be32(wq->rq.qid);
+       res->u.sqrq.eqaddr = cpu_to_be64(wq->rq.dma_addr);
+
+       c4iw_init_wr_wait(&wr_wait);
+
+       ret = c4iw_ofld_send(rdev, skb);
+       if (ret)
+               goto err7;
+       wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+       if (!wr_wait.done) {
+               printk(KERN_ERR MOD "Device %s not responding!\n",
+                      pci_name(rdev->lldi.pdev));
+               rdev->flags = T4_FATAL_ERROR;
+               ret = -EIO;
+       } else
+               ret = wr_wait.ret;
+       if (ret)
+               goto err7;
+
+       PDBG("%s sqid 0x%x rqid 0x%x kdb 0x%p squdb 0x%llx rqudb 0x%llx\n",
+            __func__, wq->sq.qid, wq->rq.qid, wq->db,
+            (unsigned long long)wq->sq.udb, (unsigned long long)wq->rq.udb);
+
+       return 0;
+err7:
+       dma_free_coherent(&(rdev->lldi.pdev->dev),
+                         wq->rq.memsize, wq->rq.queue,
+                         pci_unmap_addr(&wq->rq, mapping));
+err6:
+       dma_free_coherent(&(rdev->lldi.pdev->dev),
+                         wq->sq.memsize, wq->sq.queue,
+                         pci_unmap_addr(&wq->sq, mapping));
+err5:
+       c4iw_rqtpool_free(rdev, wq->rq.rqt_hwaddr, wq->rq.rqt_size);
+err4:
+       kfree(wq->rq.sw_rq);
+err3:
+       kfree(wq->sq.sw_sq);
+err2:
+       c4iw_put_qpid(rdev, wq->rq.qid, uctx);
+err1:
+       c4iw_put_qpid(rdev, wq->sq.qid, uctx);
+       return -ENOMEM;
+}
+
+static int build_rdma_send(union t4_wr *wqe, struct ib_send_wr *wr, u8 *len16)
+{
+       int i;
+       u32 plen;
+       int size;
+       u8 *datap;
+
+       if (wr->num_sge > T4_MAX_SEND_SGE)
+               return -EINVAL;
+       switch (wr->opcode) {
+       case IB_WR_SEND:
+               if (wr->send_flags & IB_SEND_SOLICITED)
+                       wqe->send.sendop_pkd = cpu_to_be32(
+                               V_FW_RI_SEND_WR_SENDOP(FW_RI_SEND_WITH_SE));
+               else
+                       wqe->send.sendop_pkd = cpu_to_be32(
+                               V_FW_RI_SEND_WR_SENDOP(FW_RI_SEND));
+               wqe->send.stag_inv = 0;
+               break;
+       case IB_WR_SEND_WITH_INV:
+               if (wr->send_flags & IB_SEND_SOLICITED)
+                       wqe->send.sendop_pkd = cpu_to_be32(
+                               V_FW_RI_SEND_WR_SENDOP(FW_RI_SEND_WITH_SE_INV));
+               else
+                       wqe->send.sendop_pkd = cpu_to_be32(
+                               V_FW_RI_SEND_WR_SENDOP(FW_RI_SEND_WITH_INV));
+               wqe->send.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+       plen = 0;
+       if (wr->num_sge) {
+               if (wr->send_flags & IB_SEND_INLINE) {
+                       datap = (u8 *)wqe->send.u.immd_src[0].data;
+                       for (i = 0; i < wr->num_sge; i++) {
+                               if ((plen + wr->sg_list[i].length) >
+                                   T4_MAX_SEND_INLINE) {
+                                       return -EMSGSIZE;
+                               }
+                               plen += wr->sg_list[i].length;
+                               memcpy(datap,
+                                    (void *)(unsigned long)wr->sg_list[i].addr,
+                                    wr->sg_list[i].length);
+                               datap += wr->sg_list[i].length;
+                       }
+                       wqe->send.u.immd_src[0].op = FW_RI_DATA_IMMD;
+                       wqe->send.u.immd_src[0].r1 = 0;
+                       wqe->send.u.immd_src[0].r2 = 0;
+                       wqe->send.u.immd_src[0].immdlen = cpu_to_be32(plen);
+                       size = sizeof wqe->send + sizeof(struct fw_ri_immd) +
+                              plen;
+               } else {
+                       for (i = 0; i < wr->num_sge; i++) {
+                               if ((plen + wr->sg_list[i].length) < plen)
+                                       return -EMSGSIZE;
+                               plen += wr->sg_list[i].length;
+                               wqe->send.u.isgl_src[0].sge[i].stag =
+                                       cpu_to_be32(wr->sg_list[i].lkey);
+                               wqe->send.u.isgl_src[0].sge[i].len =
+                                       cpu_to_be32(wr->sg_list[i].length);
+                               wqe->send.u.isgl_src[0].sge[i].to =
+                                       cpu_to_be64(wr->sg_list[i].addr);
+                       }
+                       wqe->send.u.isgl_src[0].op = FW_RI_DATA_ISGL;
+                       wqe->send.u.isgl_src[0].r1 = 0;
+                       wqe->send.u.isgl_src[0].nsge = cpu_to_be16(wr->num_sge);
+                       wqe->send.u.isgl_src[0].r2 = 0;
+                       size = sizeof wqe->send + sizeof(struct fw_ri_isgl) +
+                              wr->num_sge * sizeof(struct fw_ri_sge);
+               }
+       } else {
+               wqe->send.u.immd_src[0].op = FW_RI_DATA_IMMD;
+               wqe->send.u.immd_src[0].r1 = 0;
+               wqe->send.u.immd_src[0].r2 = 0;
+               wqe->send.u.immd_src[0].immdlen = 0;
+               size = sizeof wqe->send + sizeof(struct fw_ri_immd);
+       }
+       *len16 = DIV_ROUND_UP(size, 16);
+       wqe->send.plen = cpu_to_be32(plen);
+       return 0;
+}
+
+static int build_rdma_write(union t4_wr *wqe, struct ib_send_wr *wr, u8 *len16)
+{
+       int i;
+       u32 plen;
+       int size;
+       u8 *datap;
+
+       if (wr->num_sge > T4_MAX_WRITE_SGE)
+               return -EINVAL;
+       wqe->write.r2 = 0;
+       wqe->write.stag_sink = cpu_to_be32(wr->wr.rdma.rkey);
+       wqe->write.to_sink = cpu_to_be64(wr->wr.rdma.remote_addr);
+       plen = 0;
+       if (wr->num_sge) {
+               if (wr->send_flags & IB_SEND_INLINE) {
+                       datap = (u8 *)wqe->write.u.immd_src[0].data;
+                       for (i = 0; i < wr->num_sge; i++) {
+                               if ((plen + wr->sg_list[i].length) >
+                                   T4_MAX_WRITE_INLINE) {
+                                       return -EMSGSIZE;
+                               }
+                               plen += wr->sg_list[i].length;
+                               memcpy(datap,
+                                    (void *)(unsigned long)wr->sg_list[i].addr,
+                                    wr->sg_list[i].length);
+                               datap += wr->sg_list[i].length;
+                       }
+                       wqe->write.u.immd_src[0].op = FW_RI_DATA_IMMD;
+                       wqe->write.u.immd_src[0].r1 = 0;
+                       wqe->write.u.immd_src[0].r2 = 0;
+                       wqe->write.u.immd_src[0].immdlen = cpu_to_be32(plen);
+                       size = sizeof wqe->write + sizeof(struct fw_ri_immd) +
+                              plen;
+               } else {
+                       for (i = 0; i < wr->num_sge; i++) {
+                               if ((plen + wr->sg_list[i].length) < plen)
+                                       return -EMSGSIZE;
+                               plen += wr->sg_list[i].length;
+                               wqe->write.u.isgl_src[0].sge[i].stag =
+                                       cpu_to_be32(wr->sg_list[i].lkey);
+                               wqe->write.u.isgl_src[0].sge[i].len =
+                                       cpu_to_be32(wr->sg_list[i].length);
+                               wqe->write.u.isgl_src[0].sge[i].to =
+                                       cpu_to_be64(wr->sg_list[i].addr);
+                       }
+                       wqe->write.u.isgl_src[0].op = FW_RI_DATA_ISGL;
+                       wqe->write.u.isgl_src[0].r1 = 0;
+                       wqe->write.u.isgl_src[0].nsge =
+                                                      cpu_to_be16(wr->num_sge);
+                       wqe->write.u.isgl_src[0].r2 = 0;
+                       size = sizeof wqe->write + sizeof(struct fw_ri_isgl) +
+                              wr->num_sge * sizeof(struct fw_ri_sge);
+               }
+       } else {
+               wqe->write.u.immd_src[0].op = FW_RI_DATA_IMMD;
+               wqe->write.u.immd_src[0].r1 = 0;
+               wqe->write.u.immd_src[0].r2 = 0;
+               wqe->write.u.immd_src[0].immdlen = 0;
+               size = sizeof wqe->write + sizeof(struct fw_ri_immd);
+       }
+       *len16 = DIV_ROUND_UP(size, 16);
+       wqe->write.plen = cpu_to_be32(plen);
+       return 0;
+}
+
+static int build_rdma_read(union t4_wr *wqe, struct ib_send_wr *wr, u8 *len16)
+{
+       if (wr->num_sge > 1)
+               return -EINVAL;
+       if (wr->num_sge) {
+               wqe->read.stag_src = cpu_to_be32(wr->wr.rdma.rkey);
+               wqe->read.to_src_hi = cpu_to_be32((u32)(wr->wr.rdma.remote_addr
+                                                       >> 32));
+               wqe->read.to_src_lo = cpu_to_be32((u32)wr->wr.rdma.remote_addr);
+               wqe->read.stag_sink = cpu_to_be32(wr->sg_list[0].lkey);
+               wqe->read.plen = cpu_to_be32(wr->sg_list[0].length);
+               wqe->read.to_sink_hi = cpu_to_be32((u32)(wr->sg_list[0].addr
+                                                        >> 32));
+               wqe->read.to_sink_lo = cpu_to_be32((u32)(wr->sg_list[0].addr));
+       } else {
+               wqe->read.stag_src = cpu_to_be32(2);
+               wqe->read.to_src_hi = 0;
+               wqe->read.to_src_lo = 0;
+               wqe->read.stag_sink = cpu_to_be32(2);
+               wqe->read.plen = 0;
+               wqe->read.to_sink_hi = 0;
+               wqe->read.to_sink_lo = 0;
+       }
+       wqe->read.r2 = 0;
+       wqe->read.r5 = 0;
+       *len16 = DIV_ROUND_UP(sizeof wqe->read, 16);
+       return 0;
+}
+
+static int build_rdma_recv(struct c4iw_qp *qhp, union t4_recv_wr *wqe,
+                          struct ib_recv_wr *wr, u8 *len16)
+{
+       int i;
+       int plen = 0;
+
+       for (i = 0; i < wr->num_sge; i++) {
+               if ((plen + wr->sg_list[i].length) < plen)
+                       return -EMSGSIZE;
+               plen += wr->sg_list[i].length;
+               wqe->recv.isgl.sge[i].stag =
+                       cpu_to_be32(wr->sg_list[i].lkey);
+               wqe->recv.isgl.sge[i].len =
+                       cpu_to_be32(wr->sg_list[i].length);
+               wqe->recv.isgl.sge[i].to =
+                       cpu_to_be64(wr->sg_list[i].addr);
+       }
+       for (; i < T4_MAX_RECV_SGE; i++) {
+               wqe->recv.isgl.sge[i].stag = 0;
+               wqe->recv.isgl.sge[i].len = 0;
+               wqe->recv.isgl.sge[i].to = 0;
+       }
+       wqe->recv.isgl.op = FW_RI_DATA_ISGL;
+       wqe->recv.isgl.r1 = 0;
+       wqe->recv.isgl.nsge = cpu_to_be16(wr->num_sge);
+       wqe->recv.isgl.r2 = 0;
+       *len16 = DIV_ROUND_UP(sizeof wqe->recv +
+                             wr->num_sge * sizeof(struct fw_ri_sge), 16);
+       return 0;
+}
+
+static int build_fastreg(union t4_wr *wqe, struct ib_send_wr *wr, u8 *len16)
+{
+
+       struct fw_ri_immd *imdp;
+       __be64 *p;
+       int i;
+       int pbllen = roundup(wr->wr.fast_reg.page_list_len * sizeof(u64), 32);
+
+       if (wr->wr.fast_reg.page_list_len > T4_MAX_FR_DEPTH)
+               return -EINVAL;
+
+       wqe->fr.qpbinde_to_dcacpu = 0;
+       wqe->fr.pgsz_shift = wr->wr.fast_reg.page_shift - 12;
+       wqe->fr.addr_type = FW_RI_VA_BASED_TO;
+       wqe->fr.mem_perms = c4iw_ib_to_tpt_access(wr->wr.fast_reg.access_flags);
+       wqe->fr.len_hi = 0;
+       wqe->fr.len_lo = cpu_to_be32(wr->wr.fast_reg.length);
+       wqe->fr.stag = cpu_to_be32(wr->wr.fast_reg.rkey);
+       wqe->fr.va_hi = cpu_to_be32(wr->wr.fast_reg.iova_start >> 32);
+       wqe->fr.va_lo_fbo = cpu_to_be32(wr->wr.fast_reg.iova_start &
+                                       0xffffffff);
+       if (pbllen > T4_MAX_FR_IMMD) {
+               struct c4iw_fr_page_list *c4pl =
+                               to_c4iw_fr_page_list(wr->wr.fast_reg.page_list);
+               struct fw_ri_dsgl *sglp;
+
+               sglp = (struct fw_ri_dsgl *)(&wqe->fr + 1);
+               sglp->op = FW_RI_DATA_DSGL;
+               sglp->r1 = 0;
+               sglp->nsge = cpu_to_be16(1);
+               sglp->addr0 = cpu_to_be64(c4pl->dma_addr);
+               sglp->len0 = cpu_to_be32(pbllen);
+
+               *len16 = DIV_ROUND_UP(sizeof wqe->fr + sizeof *sglp, 16);
+       } else {
+               imdp = (struct fw_ri_immd *)(&wqe->fr + 1);
+               imdp->op = FW_RI_DATA_IMMD;
+               imdp->r1 = 0;
+               imdp->r2 = 0;
+               imdp->immdlen = cpu_to_be32(pbllen);
+               p = (__be64 *)(imdp + 1);
+               for (i = 0; i < wr->wr.fast_reg.page_list_len; i++, p++)
+                       *p = cpu_to_be64(
+                               (u64)wr->wr.fast_reg.page_list->page_list[i]);
+               *len16 = DIV_ROUND_UP(sizeof wqe->fr + sizeof *imdp + pbllen,
+                                     16);
+       }
+       return 0;
+}
+
+static int build_inv_stag(union t4_wr *wqe, struct ib_send_wr *wr,
+                         u8 *len16)
+{
+       wqe->inv.stag_inv = cpu_to_be32(wr->ex.invalidate_rkey);
+       wqe->inv.r2 = 0;
+       *len16 = DIV_ROUND_UP(sizeof wqe->inv, 16);
+       return 0;
+}
+
+void c4iw_qp_add_ref(struct ib_qp *qp)
+{
+       PDBG("%s ib_qp %p\n", __func__, qp);
+       atomic_inc(&(to_c4iw_qp(qp)->refcnt));
+}
+
+void c4iw_qp_rem_ref(struct ib_qp *qp)
+{
+       PDBG("%s ib_qp %p\n", __func__, qp);
+       if (atomic_dec_and_test(&(to_c4iw_qp(qp)->refcnt)))
+               wake_up(&(to_c4iw_qp(qp)->wait));
+}
+
+int c4iw_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
+                  struct ib_send_wr **bad_wr)
+{
+       int err = 0;
+       u8 len16 = 0;
+       enum fw_wr_opcodes fw_opcode = 0;
+       enum fw_ri_wr_flags fw_flags;
+       struct c4iw_qp *qhp;
+       union t4_wr *wqe;
+       u32 num_wrs;
+       struct t4_swsqe *swsqe;
+       unsigned long flag;
+       u16 idx = 0;
+
+       qhp = to_c4iw_qp(ibqp);
+       spin_lock_irqsave(&qhp->lock, flag);
+       if (t4_wq_in_error(&qhp->wq)) {
+               spin_unlock_irqrestore(&qhp->lock, flag);
+               return -EINVAL;
+       }
+       num_wrs = t4_sq_avail(&qhp->wq);
+       if (num_wrs == 0) {
+               spin_unlock_irqrestore(&qhp->lock, flag);
+               return -ENOMEM;
+       }
+       while (wr) {
+               if (num_wrs == 0) {
+                       err = -ENOMEM;
+                       *bad_wr = wr;
+                       break;
+               }
+               wqe = &qhp->wq.sq.queue[qhp->wq.sq.pidx];
+               fw_flags = 0;
+               if (wr->send_flags & IB_SEND_SOLICITED)
+                       fw_flags |= FW_RI_SOLICITED_EVENT_FLAG;
+               if (wr->send_flags & IB_SEND_SIGNALED)
+                       fw_flags |= FW_RI_COMPLETION_FLAG;
+               swsqe = &qhp->wq.sq.sw_sq[qhp->wq.sq.pidx];
+               switch (wr->opcode) {
+               case IB_WR_SEND_WITH_INV:
+               case IB_WR_SEND:
+                       if (wr->send_flags & IB_SEND_FENCE)
+                               fw_flags |= FW_RI_READ_FENCE_FLAG;
+                       fw_opcode = FW_RI_SEND_WR;
+                       if (wr->opcode == IB_WR_SEND)
+                               swsqe->opcode = FW_RI_SEND;
+                       else
+                               swsqe->opcode = FW_RI_SEND_WITH_INV;
+                       err = build_rdma_send(wqe, wr, &len16);
+                       break;
+               case IB_WR_RDMA_WRITE:
+                       fw_opcode = FW_RI_RDMA_WRITE_WR;
+                       swsqe->opcode = FW_RI_RDMA_WRITE;
+                       err = build_rdma_write(wqe, wr, &len16);
+                       break;
+               case IB_WR_RDMA_READ:
+                       fw_opcode = FW_RI_RDMA_READ_WR;
+                       swsqe->opcode = FW_RI_READ_REQ;
+                       fw_flags = 0;
+                       err = build_rdma_read(wqe, wr, &len16);
+                       if (err)
+                               break;
+                       swsqe->read_len = wr->sg_list[0].length;
+                       if (!qhp->wq.sq.oldest_read)
+                               qhp->wq.sq.oldest_read = swsqe;
+                       break;
+               case IB_WR_FAST_REG_MR:
+                       fw_opcode = FW_RI_FR_NSMR_WR;
+                       swsqe->opcode = FW_RI_FAST_REGISTER;
+                       err = build_fastreg(wqe, wr, &len16);
+                       break;
+               case IB_WR_LOCAL_INV:
+                       fw_opcode = FW_RI_INV_LSTAG_WR;
+                       swsqe->opcode = FW_RI_LOCAL_INV;
+                       err = build_inv_stag(wqe, wr, &len16);
+                       break;
+               default:
+                       PDBG("%s post of type=%d TBD!\n", __func__,
+                            wr->opcode);
+                       err = -EINVAL;
+               }
+               if (err) {
+                       *bad_wr = wr;
+                       break;
+               }
+               swsqe->idx = qhp->wq.sq.pidx;
+               swsqe->complete = 0;
+               swsqe->signaled = (wr->send_flags & IB_SEND_SIGNALED);
+               swsqe->wr_id = wr->wr_id;
+
+               init_wr_hdr(wqe, qhp->wq.sq.pidx, fw_opcode, fw_flags, len16);
+
+               PDBG("%s cookie 0x%llx pidx 0x%x opcode 0x%x read_len %u\n",
+                    __func__, (unsigned long long)wr->wr_id, qhp->wq.sq.pidx,
+                    swsqe->opcode, swsqe->read_len);
+               wr = wr->next;
+               num_wrs--;
+               t4_sq_produce(&qhp->wq);
+               idx++;
+       }
+       if (t4_wq_db_enabled(&qhp->wq))
+               t4_ring_sq_db(&qhp->wq, idx);
+       spin_unlock_irqrestore(&qhp->lock, flag);
+       return err;
+}
+
+int c4iw_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
+                     struct ib_recv_wr **bad_wr)
+{
+       int err = 0;
+       struct c4iw_qp *qhp;
+       union t4_recv_wr *wqe;
+       u32 num_wrs;
+       u8 len16 = 0;
+       unsigned long flag;
+       u16 idx = 0;
+
+       qhp = to_c4iw_qp(ibqp);
+       spin_lock_irqsave(&qhp->lock, flag);
+       if (t4_wq_in_error(&qhp->wq)) {
+               spin_unlock_irqrestore(&qhp->lock, flag);
+               return -EINVAL;
+       }
+       num_wrs = t4_rq_avail(&qhp->wq);
+       if (num_wrs == 0) {
+               spin_unlock_irqrestore(&qhp->lock, flag);
+               return -ENOMEM;
+       }
+       while (wr) {
+               if (wr->num_sge > T4_MAX_RECV_SGE) {
+                       err = -EINVAL;
+                       *bad_wr = wr;
+                       break;
+               }
+               wqe = &qhp->wq.rq.queue[qhp->wq.rq.pidx];
+               if (num_wrs)
+                       err = build_rdma_recv(qhp, wqe, wr, &len16);
+               else
+                       err = -ENOMEM;
+               if (err) {
+                       *bad_wr = wr;
+                       break;
+               }
+
+               qhp->wq.rq.sw_rq[qhp->wq.rq.pidx].wr_id = wr->wr_id;
+
+               wqe->recv.opcode = FW_RI_RECV_WR;
+               wqe->recv.r1 = 0;
+               wqe->recv.wrid = qhp->wq.rq.pidx;
+               wqe->recv.r2[0] = 0;
+               wqe->recv.r2[1] = 0;
+               wqe->recv.r2[2] = 0;
+               wqe->recv.len16 = len16;
+               if (len16 < 5)
+                       wqe->flits[8] = 0;
+
+               PDBG("%s cookie 0x%llx pidx %u\n", __func__,
+                    (unsigned long long) wr->wr_id, qhp->wq.rq.pidx);
+               t4_rq_produce(&qhp->wq);
+               wr = wr->next;
+               num_wrs--;
+               idx++;
+       }
+       if (t4_wq_db_enabled(&qhp->wq))
+               t4_ring_rq_db(&qhp->wq, idx);
+       spin_unlock_irqrestore(&qhp->lock, flag);
+       return err;
+}
+
+int c4iw_bind_mw(struct ib_qp *qp, struct ib_mw *mw, struct ib_mw_bind *mw_bind)
+{
+       return -ENOSYS;
+}
+
+static inline void build_term_codes(struct t4_cqe *err_cqe, u8 *layer_type,
+                                   u8 *ecode)
+{
+       int status;
+       int tagged;
+       int opcode;
+       int rqtype;
+       int send_inv;
+
+       if (!err_cqe) {
+               *layer_type = LAYER_RDMAP|DDP_LOCAL_CATA;
+               *ecode = 0;
+               return;
+       }
+
+       status = CQE_STATUS(err_cqe);
+       opcode = CQE_OPCODE(err_cqe);
+       rqtype = RQ_TYPE(err_cqe);
+       send_inv = (opcode == FW_RI_SEND_WITH_INV) ||
+                  (opcode == FW_RI_SEND_WITH_SE_INV);
+       tagged = (opcode == FW_RI_RDMA_WRITE) ||
+                (rqtype && (opcode == FW_RI_READ_RESP));
+
+       switch (status) {
+       case T4_ERR_STAG:
+               if (send_inv) {
+                       *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP;
+                       *ecode = RDMAP_CANT_INV_STAG;
+               } else {
+                       *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+                       *ecode = RDMAP_INV_STAG;
+               }
+               break;
+       case T4_ERR_PDID:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+               if ((opcode == FW_RI_SEND_WITH_INV) ||
+                   (opcode == FW_RI_SEND_WITH_SE_INV))
+                       *ecode = RDMAP_CANT_INV_STAG;
+               else
+                       *ecode = RDMAP_STAG_NOT_ASSOC;
+               break;
+       case T4_ERR_QPID:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+               *ecode = RDMAP_STAG_NOT_ASSOC;
+               break;
+       case T4_ERR_ACCESS:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+               *ecode = RDMAP_ACC_VIOL;
+               break;
+       case T4_ERR_WRAP:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+               *ecode = RDMAP_TO_WRAP;
+               break;
+       case T4_ERR_BOUND:
+               if (tagged) {
+                       *layer_type = LAYER_DDP|DDP_TAGGED_ERR;
+                       *ecode = DDPT_BASE_BOUNDS;
+               } else {
+                       *layer_type = LAYER_RDMAP|RDMAP_REMOTE_PROT;
+                       *ecode = RDMAP_BASE_BOUNDS;
+               }
+               break;
+       case T4_ERR_INVALIDATE_SHARED_MR:
+       case T4_ERR_INVALIDATE_MR_WITH_MW_BOUND:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP;
+               *ecode = RDMAP_CANT_INV_STAG;
+               break;
+       case T4_ERR_ECC:
+       case T4_ERR_ECC_PSTAG:
+       case T4_ERR_INTERNAL_ERR:
+               *layer_type = LAYER_RDMAP|RDMAP_LOCAL_CATA;
+               *ecode = 0;
+               break;
+       case T4_ERR_OUT_OF_RQE:
+               *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+               *ecode = DDPU_INV_MSN_NOBUF;
+               break;
+       case T4_ERR_PBL_ADDR_BOUND:
+               *layer_type = LAYER_DDP|DDP_TAGGED_ERR;
+               *ecode = DDPT_BASE_BOUNDS;
+               break;
+       case T4_ERR_CRC:
+               *layer_type = LAYER_MPA|DDP_LLP;
+               *ecode = MPA_CRC_ERR;
+               break;
+       case T4_ERR_MARKER:
+               *layer_type = LAYER_MPA|DDP_LLP;
+               *ecode = MPA_MARKER_ERR;
+               break;
+       case T4_ERR_PDU_LEN_ERR:
+               *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+               *ecode = DDPU_MSG_TOOBIG;
+               break;
+       case T4_ERR_DDP_VERSION:
+               if (tagged) {
+                       *layer_type = LAYER_DDP|DDP_TAGGED_ERR;
+                       *ecode = DDPT_INV_VERS;
+               } else {
+                       *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+                       *ecode = DDPU_INV_VERS;
+               }
+               break;
+       case T4_ERR_RDMA_VERSION:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP;
+               *ecode = RDMAP_INV_VERS;
+               break;
+       case T4_ERR_OPCODE:
+               *layer_type = LAYER_RDMAP|RDMAP_REMOTE_OP;
+               *ecode = RDMAP_INV_OPCODE;
+               break;
+       case T4_ERR_DDP_QUEUE_NUM:
+               *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+               *ecode = DDPU_INV_QN;
+               break;
+       case T4_ERR_MSN:
+       case T4_ERR_MSN_GAP:
+       case T4_ERR_MSN_RANGE:
+       case T4_ERR_IRD_OVERFLOW:
+               *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+               *ecode = DDPU_INV_MSN_RANGE;
+               break;
+       case T4_ERR_TBIT:
+               *layer_type = LAYER_DDP|DDP_LOCAL_CATA;
+               *ecode = 0;
+               break;
+       case T4_ERR_MO:
+               *layer_type = LAYER_DDP|DDP_UNTAGGED_ERR;
+               *ecode = DDPU_INV_MO;
+               break;
+       default:
+               *layer_type = LAYER_RDMAP|DDP_LOCAL_CATA;
+               *ecode = 0;
+               break;
+       }
+}
+
+int c4iw_post_zb_read(struct c4iw_qp *qhp)
+{
+       union t4_wr *wqe;
+       struct sk_buff *skb;
+       u8 len16;
+
+       PDBG("%s enter\n", __func__);
+       skb = alloc_skb(40, GFP_KERNEL);
+       if (!skb) {
+               printk(KERN_ERR "%s cannot send zb_read!!\n", __func__);
+               return -ENOMEM;
+       }
+       set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx);
+
+       wqe = (union t4_wr *)skb_put(skb, sizeof wqe->read);
+       memset(wqe, 0, sizeof wqe->read);
+       wqe->read.r2 = cpu_to_be64(0);
+       wqe->read.stag_sink = cpu_to_be32(1);
+       wqe->read.to_sink_hi = cpu_to_be32(0);
+       wqe->read.to_sink_lo = cpu_to_be32(1);
+       wqe->read.stag_src = cpu_to_be32(1);
+       wqe->read.plen = cpu_to_be32(0);
+       wqe->read.to_src_hi = cpu_to_be32(0);
+       wqe->read.to_src_lo = cpu_to_be32(1);
+       len16 = DIV_ROUND_UP(sizeof wqe->read, 16);
+       init_wr_hdr(wqe, 0, FW_RI_RDMA_READ_WR, FW_RI_COMPLETION_FLAG, len16);
+
+       return c4iw_ofld_send(&qhp->rhp->rdev, skb);
+}
+
+static void post_terminate(struct c4iw_qp *qhp, struct t4_cqe *err_cqe,
+                          gfp_t gfp)
+{
+       struct fw_ri_wr *wqe;
+       struct sk_buff *skb;
+       struct terminate_message *term;
+
+       PDBG("%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->wq.sq.qid,
+            qhp->ep->hwtid);
+
+       skb = alloc_skb(sizeof *wqe, gfp);
+       if (!skb)
+               return;
+       set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx);
+
+       wqe = (struct fw_ri_wr *)__skb_put(skb, sizeof(*wqe));
+       memset(wqe, 0, sizeof *wqe);
+       wqe->op_compl = cpu_to_be32(FW_WR_OP(FW_RI_INIT_WR));
+       wqe->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(qhp->ep->hwtid) |
+               FW_WR_LEN16(DIV_ROUND_UP(sizeof *wqe, 16)));
+
+       wqe->u.terminate.type = FW_RI_TYPE_TERMINATE;
+       wqe->u.terminate.immdlen = cpu_to_be32(sizeof *term);
+       term = (struct terminate_message *)wqe->u.terminate.termmsg;
+       build_term_codes(err_cqe, &term->layer_etype, &term->ecode);
+       c4iw_ofld_send(&qhp->rhp->rdev, skb);
+}
+
+/*
+ * Assumes qhp lock is held.
+ */
+static void __flush_qp(struct c4iw_qp *qhp, struct c4iw_cq *rchp,
+                      struct c4iw_cq *schp, unsigned long *flag)
+{
+       int count;
+       int flushed;
+
+       PDBG("%s qhp %p rchp %p schp %p\n", __func__, qhp, rchp, schp);
+       /* take a ref on the qhp since we must release the lock */
+       atomic_inc(&qhp->refcnt);
+       spin_unlock_irqrestore(&qhp->lock, *flag);
+
+       /* locking heirarchy: cq lock first, then qp lock. */
+       spin_lock_irqsave(&rchp->lock, *flag);
+       spin_lock(&qhp->lock);
+       c4iw_flush_hw_cq(&rchp->cq);
+       c4iw_count_rcqes(&rchp->cq, &qhp->wq, &count);
+       flushed = c4iw_flush_rq(&qhp->wq, &rchp->cq, count);
+       spin_unlock(&qhp->lock);
+       spin_unlock_irqrestore(&rchp->lock, *flag);
+       if (flushed)
+               (*rchp->ibcq.comp_handler)(&rchp->ibcq, rchp->ibcq.cq_context);
+
+       /* locking heirarchy: cq lock first, then qp lock. */
+       spin_lock_irqsave(&schp->lock, *flag);
+       spin_lock(&qhp->lock);
+       c4iw_flush_hw_cq(&schp->cq);
+       c4iw_count_scqes(&schp->cq, &qhp->wq, &count);
+       flushed = c4iw_flush_sq(&qhp->wq, &schp->cq, count);
+       spin_unlock(&qhp->lock);
+       spin_unlock_irqrestore(&schp->lock, *flag);
+       if (flushed)
+               (*schp->ibcq.comp_handler)(&schp->ibcq, schp->ibcq.cq_context);
+
+       /* deref */
+       if (atomic_dec_and_test(&qhp->refcnt))
+               wake_up(&qhp->wait);
+
+       spin_lock_irqsave(&qhp->lock, *flag);
+}
+
+static void flush_qp(struct c4iw_qp *qhp, unsigned long *flag)
+{
+       struct c4iw_cq *rchp, *schp;
+
+       rchp = get_chp(qhp->rhp, qhp->attr.rcq);
+       schp = get_chp(qhp->rhp, qhp->attr.scq);
+
+       if (qhp->ibqp.uobject) {
+               t4_set_wq_in_error(&qhp->wq);
+               t4_set_cq_in_error(&rchp->cq);
+               if (schp != rchp)
+                       t4_set_cq_in_error(&schp->cq);
+               return;
+       }
+       __flush_qp(qhp, rchp, schp, flag);
+}
+
+static int rdma_fini(struct c4iw_dev *rhp, struct c4iw_qp *qhp)
+{
+       struct fw_ri_wr *wqe;
+       int ret;
+       struct c4iw_wr_wait wr_wait;
+       struct sk_buff *skb;
+
+       PDBG("%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->wq.sq.qid,
+            qhp->ep->hwtid);
+
+       skb = alloc_skb(sizeof *wqe, GFP_KERNEL | __GFP_NOFAIL);
+       if (!skb)
+               return -ENOMEM;
+       set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx);
+
+       wqe = (struct fw_ri_wr *)__skb_put(skb, sizeof(*wqe));
+       memset(wqe, 0, sizeof *wqe);
+       wqe->op_compl = cpu_to_be32(
+               FW_WR_OP(FW_RI_INIT_WR) |
+               FW_WR_COMPL(1));
+       wqe->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(qhp->ep->hwtid) |
+               FW_WR_LEN16(DIV_ROUND_UP(sizeof *wqe, 16)));
+       wqe->cookie = (u64)&wr_wait;
+
+       wqe->u.fini.type = FW_RI_TYPE_FINI;
+       c4iw_init_wr_wait(&wr_wait);
+       ret = c4iw_ofld_send(&rhp->rdev, skb);
+       if (ret)
+               goto out;
+
+       wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+       if (!wr_wait.done) {
+               printk(KERN_ERR MOD "Device %s not responding!\n",
+                      pci_name(rhp->rdev.lldi.pdev));
+               rhp->rdev.flags = T4_FATAL_ERROR;
+               ret = -EIO;
+       } else {
+               ret = wr_wait.ret;
+               if (ret)
+                       printk(KERN_WARNING MOD
+                              "%s: Abnormal close qpid %d ret %u\n",
+                              pci_name(rhp->rdev.lldi.pdev), qhp->wq.sq.qid,
+                              ret);
+       }
+out:
+       PDBG("%s ret %d\n", __func__, ret);
+       return ret;
+}
+
+static void build_rtr_msg(u8 p2p_type, struct fw_ri_init *init)
+{
+       memset(&init->u, 0, sizeof init->u);
+       switch (p2p_type) {
+       case FW_RI_INIT_P2PTYPE_RDMA_WRITE:
+               init->u.write.opcode = FW_RI_RDMA_WRITE_WR;
+               init->u.write.stag_sink = cpu_to_be32(1);
+               init->u.write.to_sink = cpu_to_be64(1);
+               init->u.write.u.immd_src[0].op = FW_RI_DATA_IMMD;
+               init->u.write.len16 = DIV_ROUND_UP(sizeof init->u.write +
+                                                  sizeof(struct fw_ri_immd),
+                                                  16);
+               break;
+       case FW_RI_INIT_P2PTYPE_READ_REQ:
+               init->u.write.opcode = FW_RI_RDMA_READ_WR;
+               init->u.read.stag_src = cpu_to_be32(1);
+               init->u.read.to_src_lo = cpu_to_be32(1);
+               init->u.read.stag_sink = cpu_to_be32(1);
+               init->u.read.to_sink_lo = cpu_to_be32(1);
+               init->u.read.len16 = DIV_ROUND_UP(sizeof init->u.read, 16);
+               break;
+       }
+}
+
+static int rdma_init(struct c4iw_dev *rhp, struct c4iw_qp *qhp)
+{
+       struct fw_ri_wr *wqe;
+       int ret;
+       struct c4iw_wr_wait wr_wait;
+       struct sk_buff *skb;
+
+       PDBG("%s qhp %p qid 0x%x tid %u\n", __func__, qhp, qhp->wq.sq.qid,
+            qhp->ep->hwtid);
+
+       skb = alloc_skb(sizeof *wqe, GFP_KERNEL | __GFP_NOFAIL);
+       if (!skb)
+               return -ENOMEM;
+       set_wr_txq(skb, CPL_PRIORITY_DATA, qhp->ep->txq_idx);
+
+       wqe = (struct fw_ri_wr *)__skb_put(skb, sizeof(*wqe));
+       memset(wqe, 0, sizeof *wqe);
+       wqe->op_compl = cpu_to_be32(
+               FW_WR_OP(FW_RI_INIT_WR) |
+               FW_WR_COMPL(1));
+       wqe->flowid_len16 = cpu_to_be32(
+               FW_WR_FLOWID(qhp->ep->hwtid) |
+               FW_WR_LEN16(DIV_ROUND_UP(sizeof *wqe, 16)));
+
+       wqe->cookie = (u64)&wr_wait;
+
+       wqe->u.init.type = FW_RI_TYPE_INIT;
+       wqe->u.init.mpareqbit_p2ptype =
+               V_FW_RI_WR_MPAREQBIT(qhp->attr.mpa_attr.initiator) |
+               V_FW_RI_WR_P2PTYPE(qhp->attr.mpa_attr.p2p_type);
+       wqe->u.init.mpa_attrs = FW_RI_MPA_IETF_ENABLE;
+       if (qhp->attr.mpa_attr.recv_marker_enabled)
+               wqe->u.init.mpa_attrs |= FW_RI_MPA_RX_MARKER_ENABLE;
+       if (qhp->attr.mpa_attr.xmit_marker_enabled)
+               wqe->u.init.mpa_attrs |= FW_RI_MPA_TX_MARKER_ENABLE;
+       if (qhp->attr.mpa_attr.crc_enabled)
+               wqe->u.init.mpa_attrs |= FW_RI_MPA_CRC_ENABLE;
+
+       wqe->u.init.qp_caps = FW_RI_QP_RDMA_READ_ENABLE |
+                           FW_RI_QP_RDMA_WRITE_ENABLE |
+                           FW_RI_QP_BIND_ENABLE;
+       if (!qhp->ibqp.uobject)
+               wqe->u.init.qp_caps |= FW_RI_QP_FAST_REGISTER_ENABLE |
+                                    FW_RI_QP_STAG0_ENABLE;
+       wqe->u.init.nrqe = cpu_to_be16(t4_rqes_posted(&qhp->wq));
+       wqe->u.init.pdid = cpu_to_be32(qhp->attr.pd);
+       wqe->u.init.qpid = cpu_to_be32(qhp->wq.sq.qid);
+       wqe->u.init.sq_eqid = cpu_to_be32(qhp->wq.sq.qid);
+       wqe->u.init.rq_eqid = cpu_to_be32(qhp->wq.rq.qid);
+       wqe->u.init.scqid = cpu_to_be32(qhp->attr.scq);
+       wqe->u.init.rcqid = cpu_to_be32(qhp->attr.rcq);
+       wqe->u.init.ord_max = cpu_to_be32(qhp->attr.max_ord);
+       wqe->u.init.ird_max = cpu_to_be32(qhp->attr.max_ird);
+       wqe->u.init.iss = cpu_to_be32(qhp->ep->snd_seq);
+       wqe->u.init.irs = cpu_to_be32(qhp->ep->rcv_seq);
+       wqe->u.init.hwrqsize = cpu_to_be32(qhp->wq.rq.rqt_size);
+       wqe->u.init.hwrqaddr = cpu_to_be32(qhp->wq.rq.rqt_hwaddr -
+                                        rhp->rdev.lldi.vr->rq.start);
+       if (qhp->attr.mpa_attr.initiator)
+               build_rtr_msg(qhp->attr.mpa_attr.p2p_type, &wqe->u.init);
+
+       c4iw_init_wr_wait(&wr_wait);
+       ret = c4iw_ofld_send(&rhp->rdev, skb);
+       if (ret)
+               goto out;
+
+       wait_event_timeout(wr_wait.wait, wr_wait.done, C4IW_WR_TO);
+       if (!wr_wait.done) {
+               printk(KERN_ERR MOD "Device %s not responding!\n",
+                      pci_name(rhp->rdev.lldi.pdev));
+               rhp->rdev.flags = T4_FATAL_ERROR;
+               ret = -EIO;
+       } else
+               ret = wr_wait.ret;
+out:
+       PDBG("%s ret %d\n", __func__, ret);
+       return ret;
+}
+
+int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp,
+                  enum c4iw_qp_attr_mask mask,
+                  struct c4iw_qp_attributes *attrs,
+                  int internal)
+{
+       int ret = 0;
+       struct c4iw_qp_attributes newattr = qhp->attr;
+       unsigned long flag;
+       int disconnect = 0;
+       int terminate = 0;
+       int abort = 0;
+       int free = 0;
+       struct c4iw_ep *ep = NULL;
+
+       PDBG("%s qhp %p sqid 0x%x rqid 0x%x ep %p state %d -> %d\n", __func__,
+            qhp, qhp->wq.sq.qid, qhp->wq.rq.qid, qhp->ep, qhp->attr.state,
+            (mask & C4IW_QP_ATTR_NEXT_STATE) ? attrs->next_state : -1);
+
+       spin_lock_irqsave(&qhp->lock, flag);
+
+       /* Process attr changes if in IDLE */
+       if (mask & C4IW_QP_ATTR_VALID_MODIFY) {
+               if (qhp->attr.state != C4IW_QP_STATE_IDLE) {
+                       ret = -EIO;
+                       goto out;
+               }
+               if (mask & C4IW_QP_ATTR_ENABLE_RDMA_READ)
+                       newattr.enable_rdma_read = attrs->enable_rdma_read;
+               if (mask & C4IW_QP_ATTR_ENABLE_RDMA_WRITE)
+                       newattr.enable_rdma_write = attrs->enable_rdma_write;
+               if (mask & C4IW_QP_ATTR_ENABLE_RDMA_BIND)
+                       newattr.enable_bind = attrs->enable_bind;
+               if (mask & C4IW_QP_ATTR_MAX_ORD) {
+                       if (attrs->max_ord > c4iw_max_read_depth) {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       newattr.max_ord = attrs->max_ord;
+               }
+               if (mask & C4IW_QP_ATTR_MAX_IRD) {
+                       if (attrs->max_ird > c4iw_max_read_depth) {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       newattr.max_ird = attrs->max_ird;
+               }
+               qhp->attr = newattr;
+       }
+
+       if (!(mask & C4IW_QP_ATTR_NEXT_STATE))
+               goto out;
+       if (qhp->attr.state == attrs->next_state)
+               goto out;
+
+       switch (qhp->attr.state) {
+       case C4IW_QP_STATE_IDLE:
+               switch (attrs->next_state) {
+               case C4IW_QP_STATE_RTS:
+                       if (!(mask & C4IW_QP_ATTR_LLP_STREAM_HANDLE)) {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       if (!(mask & C4IW_QP_ATTR_MPA_ATTR)) {
+                               ret = -EINVAL;
+                               goto out;
+                       }
+                       qhp->attr.mpa_attr = attrs->mpa_attr;
+                       qhp->attr.llp_stream_handle = attrs->llp_stream_handle;
+                       qhp->ep = qhp->attr.llp_stream_handle;
+                       qhp->attr.state = C4IW_QP_STATE_RTS;
+
+                       /*
+                        * Ref the endpoint here and deref when we
+                        * disassociate the endpoint from the QP.  This
+                        * happens in CLOSING->IDLE transition or *->ERROR
+                        * transition.
+                        */
+                       c4iw_get_ep(&qhp->ep->com);
+                       spin_unlock_irqrestore(&qhp->lock, flag);
+                       ret = rdma_init(rhp, qhp);
+                       spin_lock_irqsave(&qhp->lock, flag);
+                       if (ret)
+                               goto err;
+                       break;
+               case C4IW_QP_STATE_ERROR:
+                       qhp->attr.state = C4IW_QP_STATE_ERROR;
+                       flush_qp(qhp, &flag);
+                       break;
+               default:
+                       ret = -EINVAL;
+                       goto out;
+               }
+               break;
+       case C4IW_QP_STATE_RTS:
+               switch (attrs->next_state) {
+               case C4IW_QP_STATE_CLOSING:
+                       BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2);
+                       qhp->attr.state = C4IW_QP_STATE_CLOSING;
+                       if (!internal) {
+                               abort = 0;
+                               disconnect = 1;
+                               ep = qhp->ep;
+                               c4iw_get_ep(&ep->com);
+                       }
+                       spin_unlock_irqrestore(&qhp->lock, flag);
+                       ret = rdma_fini(rhp, qhp);
+                       spin_lock_irqsave(&qhp->lock, flag);
+                       if (ret) {
+                               ep = qhp->ep;
+                               c4iw_get_ep(&ep->com);
+                               disconnect = abort = 1;
+                               goto err;
+                       }
+                       break;
+               case C4IW_QP_STATE_TERMINATE:
+                       qhp->attr.state = C4IW_QP_STATE_TERMINATE;
+                       if (qhp->ibqp.uobject)
+                               t4_set_wq_in_error(&qhp->wq);
+                       ep = qhp->ep;
+                       c4iw_get_ep(&ep->com);
+                       terminate = 1;
+                       disconnect = 1;
+                       break;
+               case C4IW_QP_STATE_ERROR:
+                       qhp->attr.state = C4IW_QP_STATE_ERROR;
+                       if (!internal) {
+                               abort = 1;
+                               disconnect = 1;
+                               ep = qhp->ep;
+                               c4iw_get_ep(&ep->com);
+                       }
+                       goto err;
+                       break;
+               default:
+                       ret = -EINVAL;
+                       goto out;
+               }
+               break;
+       case C4IW_QP_STATE_CLOSING:
+               if (!internal) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               switch (attrs->next_state) {
+               case C4IW_QP_STATE_IDLE:
+                       flush_qp(qhp, &flag);
+                       qhp->attr.state = C4IW_QP_STATE_IDLE;
+                       qhp->attr.llp_stream_handle = NULL;
+                       c4iw_put_ep(&qhp->ep->com);
+                       qhp->ep = NULL;
+                       wake_up(&qhp->wait);
+                       break;
+               case C4IW_QP_STATE_ERROR:
+                       goto err;
+               default:
+                       ret = -EINVAL;
+                       goto err;
+               }
+               break;
+       case C4IW_QP_STATE_ERROR:
+               if (attrs->next_state != C4IW_QP_STATE_IDLE) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               if (!t4_sq_empty(&qhp->wq) || !t4_rq_empty(&qhp->wq)) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               qhp->attr.state = C4IW_QP_STATE_IDLE;
+               break;
+       case C4IW_QP_STATE_TERMINATE:
+               if (!internal) {
+                       ret = -EINVAL;
+                       goto out;
+               }
+               goto err;
+               break;
+       default:
+               printk(KERN_ERR "%s in a bad state %d\n",
+                      __func__, qhp->attr.state);
+               ret = -EINVAL;
+               goto err;
+               break;
+       }
+       goto out;
+err:
+       PDBG("%s disassociating ep %p qpid 0x%x\n", __func__, qhp->ep,
+            qhp->wq.sq.qid);
+
+       /* disassociate the LLP connection */
+       qhp->attr.llp_stream_handle = NULL;
+       ep = qhp->ep;
+       qhp->ep = NULL;
+       qhp->attr.state = C4IW_QP_STATE_ERROR;
+       free = 1;
+       wake_up(&qhp->wait);
+       BUG_ON(!ep);
+       flush_qp(qhp, &flag);
+out:
+       spin_unlock_irqrestore(&qhp->lock, flag);
+
+       if (terminate)
+               post_terminate(qhp, NULL, internal ? GFP_ATOMIC : GFP_KERNEL);
+
+       /*
+        * If disconnect is 1, then we need to initiate a disconnect
+        * on the EP.  This can be a normal close (RTS->CLOSING) or
+        * an abnormal close (RTS/CLOSING->ERROR).
+        */
+       if (disconnect) {
+               c4iw_ep_disconnect(ep, abort, internal ? GFP_ATOMIC :
+                                                        GFP_KERNEL);
+               c4iw_put_ep(&ep->com);
+       }
+
+       /*
+        * If free is 1, then we've disassociated the EP from the QP
+        * and we need to dereference the EP.
+        */
+       if (free)
+               c4iw_put_ep(&ep->com);
+
+       PDBG("%s exit state %d\n", __func__, qhp->attr.state);
+       return ret;
+}
+
+int c4iw_destroy_qp(struct ib_qp *ib_qp)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_qp *qhp;
+       struct c4iw_qp_attributes attrs;
+       struct c4iw_ucontext *ucontext;
+
+       qhp = to_c4iw_qp(ib_qp);
+       rhp = qhp->rhp;
+
+       attrs.next_state = C4IW_QP_STATE_ERROR;
+       c4iw_modify_qp(rhp, qhp, C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
+       wait_event(qhp->wait, !qhp->ep);
+
+       remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
+       remove_handle(rhp, &rhp->qpidr, qhp->wq.rq.qid);
+       atomic_dec(&qhp->refcnt);
+       wait_event(qhp->wait, !atomic_read(&qhp->refcnt));
+
+       ucontext = ib_qp->uobject ?
+                  to_c4iw_ucontext(ib_qp->uobject->context) : NULL;
+       destroy_qp(&rhp->rdev, &qhp->wq,
+                  ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
+
+       PDBG("%s ib_qp %p qpid 0x%0x\n", __func__, ib_qp, qhp->wq.sq.qid);
+       kfree(qhp);
+       return 0;
+}
+
+struct ib_qp *c4iw_create_qp(struct ib_pd *pd, struct ib_qp_init_attr *attrs,
+                            struct ib_udata *udata)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_qp *qhp;
+       struct c4iw_pd *php;
+       struct c4iw_cq *schp;
+       struct c4iw_cq *rchp;
+       struct c4iw_create_qp_resp uresp;
+       int sqsize, rqsize;
+       struct c4iw_ucontext *ucontext;
+       int ret;
+       struct c4iw_mm_entry *mm1, *mm2, *mm3, *mm4;
+
+       PDBG("%s ib_pd %p\n", __func__, pd);
+
+       if (attrs->qp_type != IB_QPT_RC)
+               return ERR_PTR(-EINVAL);
+
+       php = to_c4iw_pd(pd);
+       rhp = php->rhp;
+       schp = get_chp(rhp, ((struct c4iw_cq *)attrs->send_cq)->cq.cqid);
+       rchp = get_chp(rhp, ((struct c4iw_cq *)attrs->recv_cq)->cq.cqid);
+       if (!schp || !rchp)
+               return ERR_PTR(-EINVAL);
+
+       if (attrs->cap.max_inline_data > T4_MAX_SEND_INLINE)
+               return ERR_PTR(-EINVAL);
+
+       rqsize = roundup(attrs->cap.max_recv_wr + 1, 16);
+       if (rqsize > T4_MAX_RQ_SIZE)
+               return ERR_PTR(-E2BIG);
+
+       sqsize = roundup(attrs->cap.max_send_wr + 1, 16);
+       if (sqsize > T4_MAX_SQ_SIZE)
+               return ERR_PTR(-E2BIG);
+
+       ucontext = pd->uobject ? to_c4iw_ucontext(pd->uobject->context) : NULL;
+
+
+       qhp = kzalloc(sizeof(*qhp), GFP_KERNEL);
+       if (!qhp)
+               return ERR_PTR(-ENOMEM);
+       qhp->wq.sq.size = sqsize;
+       qhp->wq.sq.memsize = (sqsize + 1) * sizeof *qhp->wq.sq.queue;
+       qhp->wq.rq.size = rqsize;
+       qhp->wq.rq.memsize = (rqsize + 1) * sizeof *qhp->wq.rq.queue;
+
+       if (ucontext) {
+               qhp->wq.sq.memsize = roundup(qhp->wq.sq.memsize, PAGE_SIZE);
+               qhp->wq.rq.memsize = roundup(qhp->wq.rq.memsize, PAGE_SIZE);
+       }
+
+       PDBG("%s sqsize %u sqmemsize %zu rqsize %u rqmemsize %zu\n",
+            __func__, sqsize, qhp->wq.sq.memsize, rqsize, qhp->wq.rq.memsize);
+
+       ret = create_qp(&rhp->rdev, &qhp->wq, &schp->cq, &rchp->cq,
+                       ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
+       if (ret)
+               goto err1;
+
+       attrs->cap.max_recv_wr = rqsize - 1;
+       attrs->cap.max_send_wr = sqsize - 1;
+       attrs->cap.max_inline_data = T4_MAX_SEND_INLINE;
+
+       qhp->rhp = rhp;
+       qhp->attr.pd = php->pdid;
+       qhp->attr.scq = ((struct c4iw_cq *) attrs->send_cq)->cq.cqid;
+       qhp->attr.rcq = ((struct c4iw_cq *) attrs->recv_cq)->cq.cqid;
+       qhp->attr.sq_num_entries = attrs->cap.max_send_wr;
+       qhp->attr.rq_num_entries = attrs->cap.max_recv_wr;
+       qhp->attr.sq_max_sges = attrs->cap.max_send_sge;
+       qhp->attr.sq_max_sges_rdma_write = attrs->cap.max_send_sge;
+       qhp->attr.rq_max_sges = attrs->cap.max_recv_sge;
+       qhp->attr.state = C4IW_QP_STATE_IDLE;
+       qhp->attr.next_state = C4IW_QP_STATE_IDLE;
+       qhp->attr.enable_rdma_read = 1;
+       qhp->attr.enable_rdma_write = 1;
+       qhp->attr.enable_bind = 1;
+       qhp->attr.max_ord = 1;
+       qhp->attr.max_ird = 1;
+       spin_lock_init(&qhp->lock);
+       init_waitqueue_head(&qhp->wait);
+       atomic_set(&qhp->refcnt, 1);
+
+       ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.sq.qid);
+       if (ret)
+               goto err2;
+
+       ret = insert_handle(rhp, &rhp->qpidr, qhp, qhp->wq.rq.qid);
+       if (ret)
+               goto err3;
+
+       if (udata) {
+               mm1 = kmalloc(sizeof *mm1, GFP_KERNEL);
+               if (!mm1) {
+                       ret = -ENOMEM;
+                       goto err4;
+               }
+               mm2 = kmalloc(sizeof *mm2, GFP_KERNEL);
+               if (!mm2) {
+                       ret = -ENOMEM;
+                       goto err5;
+               }
+               mm3 = kmalloc(sizeof *mm3, GFP_KERNEL);
+               if (!mm3) {
+                       ret = -ENOMEM;
+                       goto err6;
+               }
+               mm4 = kmalloc(sizeof *mm4, GFP_KERNEL);
+               if (!mm4) {
+                       ret = -ENOMEM;
+                       goto err7;
+               }
+
+               uresp.qid_mask = rhp->rdev.qpmask;
+               uresp.sqid = qhp->wq.sq.qid;
+               uresp.sq_size = qhp->wq.sq.size;
+               uresp.sq_memsize = qhp->wq.sq.memsize;
+               uresp.rqid = qhp->wq.rq.qid;
+               uresp.rq_size = qhp->wq.rq.size;
+               uresp.rq_memsize = qhp->wq.rq.memsize;
+               spin_lock(&ucontext->mmap_lock);
+               uresp.sq_key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               uresp.rq_key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               uresp.sq_db_gts_key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               uresp.rq_db_gts_key = ucontext->key;
+               ucontext->key += PAGE_SIZE;
+               spin_unlock(&ucontext->mmap_lock);
+               ret = ib_copy_to_udata(udata, &uresp, sizeof uresp);
+               if (ret)
+                       goto err8;
+               mm1->key = uresp.sq_key;
+               mm1->addr = virt_to_phys(qhp->wq.sq.queue);
+               mm1->len = PAGE_ALIGN(qhp->wq.sq.memsize);
+               insert_mmap(ucontext, mm1);
+               mm2->key = uresp.rq_key;
+               mm2->addr = virt_to_phys(qhp->wq.rq.queue);
+               mm2->len = PAGE_ALIGN(qhp->wq.rq.memsize);
+               insert_mmap(ucontext, mm2);
+               mm3->key = uresp.sq_db_gts_key;
+               mm3->addr = qhp->wq.sq.udb;
+               mm3->len = PAGE_SIZE;
+               insert_mmap(ucontext, mm3);
+               mm4->key = uresp.rq_db_gts_key;
+               mm4->addr = qhp->wq.rq.udb;
+               mm4->len = PAGE_SIZE;
+               insert_mmap(ucontext, mm4);
+       }
+       qhp->ibqp.qp_num = qhp->wq.sq.qid;
+       init_timer(&(qhp->timer));
+       PDBG("%s qhp %p sq_num_entries %d, rq_num_entries %d qpid 0x%0x\n",
+            __func__, qhp, qhp->attr.sq_num_entries, qhp->attr.rq_num_entries,
+            qhp->wq.sq.qid);
+       return &qhp->ibqp;
+err8:
+       kfree(mm4);
+err7:
+       kfree(mm3);
+err6:
+       kfree(mm2);
+err5:
+       kfree(mm1);
+err4:
+       remove_handle(rhp, &rhp->qpidr, qhp->wq.rq.qid);
+err3:
+       remove_handle(rhp, &rhp->qpidr, qhp->wq.sq.qid);
+err2:
+       destroy_qp(&rhp->rdev, &qhp->wq,
+                  ucontext ? &ucontext->uctx : &rhp->rdev.uctx);
+err1:
+       kfree(qhp);
+       return ERR_PTR(ret);
+}
+
+int c4iw_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
+                     int attr_mask, struct ib_udata *udata)
+{
+       struct c4iw_dev *rhp;
+       struct c4iw_qp *qhp;
+       enum c4iw_qp_attr_mask mask = 0;
+       struct c4iw_qp_attributes attrs;
+
+       PDBG("%s ib_qp %p\n", __func__, ibqp);
+
+       /* iwarp does not support the RTR state */
+       if ((attr_mask & IB_QP_STATE) && (attr->qp_state == IB_QPS_RTR))
+               attr_mask &= ~IB_QP_STATE;
+
+       /* Make sure we still have something left to do */
+       if (!attr_mask)
+               return 0;
+
+       memset(&attrs, 0, sizeof attrs);
+       qhp = to_c4iw_qp(ibqp);
+       rhp = qhp->rhp;
+
+       attrs.next_state = c4iw_convert_state(attr->qp_state);
+       attrs.enable_rdma_read = (attr->qp_access_flags &
+                              IB_ACCESS_REMOTE_READ) ?  1 : 0;
+       attrs.enable_rdma_write = (attr->qp_access_flags &
+                               IB_ACCESS_REMOTE_WRITE) ? 1 : 0;
+       attrs.enable_bind = (attr->qp_access_flags & IB_ACCESS_MW_BIND) ? 1 : 0;
+
+
+       mask |= (attr_mask & IB_QP_STATE) ? C4IW_QP_ATTR_NEXT_STATE : 0;
+       mask |= (attr_mask & IB_QP_ACCESS_FLAGS) ?
+                       (C4IW_QP_ATTR_ENABLE_RDMA_READ |
+                        C4IW_QP_ATTR_ENABLE_RDMA_WRITE |
+                        C4IW_QP_ATTR_ENABLE_RDMA_BIND) : 0;
+
+       return c4iw_modify_qp(rhp, qhp, mask, &attrs, 0);
+}
+
+struct ib_qp *c4iw_get_qp(struct ib_device *dev, int qpn)
+{
+       PDBG("%s ib_dev %p qpn 0x%x\n", __func__, dev, qpn);
+       return (struct ib_qp *)get_qhp(to_c4iw_dev(dev), qpn);
+}
diff --git a/drivers/infiniband/hw/cxgb4/resource.c b/drivers/infiniband/hw/cxgb4/resource.c
new file mode 100644 (file)
index 0000000..fb195d1
--- /dev/null
@@ -0,0 +1,417 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+/* Crude resource management */
+#include <linux/kernel.h>
+#include <linux/random.h>
+#include <linux/slab.h>
+#include <linux/kfifo.h>
+#include <linux/spinlock.h>
+#include <linux/errno.h>
+#include <linux/genalloc.h>
+#include "iw_cxgb4.h"
+
+#define RANDOM_SIZE 16
+
+static int __c4iw_init_resource_fifo(struct kfifo *fifo,
+                                  spinlock_t *fifo_lock,
+                                  u32 nr, u32 skip_low,
+                                  u32 skip_high,
+                                  int random)
+{
+       u32 i, j, entry = 0, idx;
+       u32 random_bytes;
+       u32 rarray[16];
+       spin_lock_init(fifo_lock);
+
+       if (kfifo_alloc(fifo, nr * sizeof(u32), GFP_KERNEL))
+               return -ENOMEM;
+
+       for (i = 0; i < skip_low + skip_high; i++)
+               kfifo_in(fifo, (unsigned char *) &entry, sizeof(u32));
+       if (random) {
+               j = 0;
+               random_bytes = random32();
+               for (i = 0; i < RANDOM_SIZE; i++)
+                       rarray[i] = i + skip_low;
+               for (i = skip_low + RANDOM_SIZE; i < nr - skip_high; i++) {
+                       if (j >= RANDOM_SIZE) {
+                               j = 0;
+                               random_bytes = random32();
+                       }
+                       idx = (random_bytes >> (j * 2)) & 0xF;
+                       kfifo_in(fifo,
+                               (unsigned char *) &rarray[idx],
+                               sizeof(u32));
+                       rarray[idx] = i;
+                       j++;
+               }
+               for (i = 0; i < RANDOM_SIZE; i++)
+                       kfifo_in(fifo,
+                               (unsigned char *) &rarray[i],
+                               sizeof(u32));
+       } else
+               for (i = skip_low; i < nr - skip_high; i++)
+                       kfifo_in(fifo, (unsigned char *) &i, sizeof(u32));
+
+       for (i = 0; i < skip_low + skip_high; i++)
+               if (kfifo_out_locked(fifo, (unsigned char *) &entry,
+                                    sizeof(u32), fifo_lock))
+                       break;
+       return 0;
+}
+
+static int c4iw_init_resource_fifo(struct kfifo *fifo, spinlock_t * fifo_lock,
+                                  u32 nr, u32 skip_low, u32 skip_high)
+{
+       return __c4iw_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
+                                         skip_high, 0);
+}
+
+static int c4iw_init_resource_fifo_random(struct kfifo *fifo,
+                                  spinlock_t *fifo_lock,
+                                  u32 nr, u32 skip_low, u32 skip_high)
+{
+       return __c4iw_init_resource_fifo(fifo, fifo_lock, nr, skip_low,
+                                         skip_high, 1);
+}
+
+static int c4iw_init_qid_fifo(struct c4iw_rdev *rdev)
+{
+       u32 i;
+
+       spin_lock_init(&rdev->resource.qid_fifo_lock);
+
+       if (kfifo_alloc(&rdev->resource.qid_fifo, T4_MAX_QIDS * sizeof(u32),
+                       GFP_KERNEL))
+               return -ENOMEM;
+
+       for (i = T4_QID_BASE; i < T4_QID_BASE + T4_MAX_QIDS; i++)
+               if (!(i & rdev->qpmask))
+                       kfifo_in(&rdev->resource.qid_fifo,
+                                   (unsigned char *) &i, sizeof(u32));
+       return 0;
+}
+
+/* nr_* must be power of 2 */
+int c4iw_init_resource(struct c4iw_rdev *rdev, u32 nr_tpt, u32 nr_pdid)
+{
+       int err = 0;
+       err = c4iw_init_resource_fifo_random(&rdev->resource.tpt_fifo,
+                                            &rdev->resource.tpt_fifo_lock,
+                                            nr_tpt, 1, 0);
+       if (err)
+               goto tpt_err;
+       err = c4iw_init_qid_fifo(rdev);
+       if (err)
+               goto qid_err;
+       err = c4iw_init_resource_fifo(&rdev->resource.pdid_fifo,
+                                     &rdev->resource.pdid_fifo_lock,
+                                     nr_pdid, 1, 0);
+       if (err)
+               goto pdid_err;
+       return 0;
+pdid_err:
+       kfifo_free(&rdev->resource.qid_fifo);
+qid_err:
+       kfifo_free(&rdev->resource.tpt_fifo);
+tpt_err:
+       return -ENOMEM;
+}
+
+/*
+ * returns 0 if no resource available
+ */
+u32 c4iw_get_resource(struct kfifo *fifo, spinlock_t *lock)
+{
+       u32 entry;
+       if (kfifo_out_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock))
+               return entry;
+       else
+               return 0;
+}
+
+void c4iw_put_resource(struct kfifo *fifo, u32 entry, spinlock_t *lock)
+{
+       PDBG("%s entry 0x%x\n", __func__, entry);
+       kfifo_in_locked(fifo, (unsigned char *) &entry, sizeof(u32), lock);
+}
+
+u32 c4iw_get_cqid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
+{
+       struct c4iw_qid_list *entry;
+       u32 qid;
+       int i;
+
+       mutex_lock(&uctx->lock);
+       if (!list_empty(&uctx->cqids)) {
+               entry = list_entry(uctx->cqids.next, struct c4iw_qid_list,
+                                  entry);
+               list_del(&entry->entry);
+               qid = entry->qid;
+               kfree(entry);
+       } else {
+               qid = c4iw_get_resource(&rdev->resource.qid_fifo,
+                                       &rdev->resource.qid_fifo_lock);
+               if (!qid)
+                       goto out;
+               for (i = qid+1; i & rdev->qpmask; i++) {
+                       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+                       if (!entry)
+                               goto out;
+                       entry->qid = i;
+                       list_add_tail(&entry->entry, &uctx->cqids);
+               }
+
+               /*
+                * now put the same ids on the qp list since they all
+                * map to the same db/gts page.
+                */
+               entry = kmalloc(sizeof *entry, GFP_KERNEL);
+               if (!entry)
+                       goto out;
+               entry->qid = qid;
+               list_add_tail(&entry->entry, &uctx->qpids);
+               for (i = qid+1; i & rdev->qpmask; i++) {
+                       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+                       if (!entry)
+                               goto out;
+                       entry->qid = i;
+                       list_add_tail(&entry->entry, &uctx->qpids);
+               }
+       }
+out:
+       mutex_unlock(&uctx->lock);
+       PDBG("%s qid 0x%x\n", __func__, qid);
+       return qid;
+}
+
+void c4iw_put_cqid(struct c4iw_rdev *rdev, u32 qid,
+                  struct c4iw_dev_ucontext *uctx)
+{
+       struct c4iw_qid_list *entry;
+
+       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+       if (!entry)
+               return;
+       PDBG("%s qid 0x%x\n", __func__, qid);
+       entry->qid = qid;
+       mutex_lock(&uctx->lock);
+       list_add_tail(&entry->entry, &uctx->cqids);
+       mutex_unlock(&uctx->lock);
+}
+
+u32 c4iw_get_qpid(struct c4iw_rdev *rdev, struct c4iw_dev_ucontext *uctx)
+{
+       struct c4iw_qid_list *entry;
+       u32 qid;
+       int i;
+
+       mutex_lock(&uctx->lock);
+       if (!list_empty(&uctx->qpids)) {
+               entry = list_entry(uctx->qpids.next, struct c4iw_qid_list,
+                                  entry);
+               list_del(&entry->entry);
+               qid = entry->qid;
+               kfree(entry);
+       } else {
+               qid = c4iw_get_resource(&rdev->resource.qid_fifo,
+                                       &rdev->resource.qid_fifo_lock);
+               if (!qid)
+                       goto out;
+               for (i = qid+1; i & rdev->qpmask; i++) {
+                       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+                       if (!entry)
+                               goto out;
+                       entry->qid = i;
+                       list_add_tail(&entry->entry, &uctx->qpids);
+               }
+
+               /*
+                * now put the same ids on the cq list since they all
+                * map to the same db/gts page.
+                */
+               entry = kmalloc(sizeof *entry, GFP_KERNEL);
+               if (!entry)
+                       goto out;
+               entry->qid = qid;
+               list_add_tail(&entry->entry, &uctx->cqids);
+               for (i = qid; i & rdev->qpmask; i++) {
+                       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+                       if (!entry)
+                               goto out;
+                       entry->qid = i;
+                       list_add_tail(&entry->entry, &uctx->cqids);
+               }
+       }
+out:
+       mutex_unlock(&uctx->lock);
+       PDBG("%s qid 0x%x\n", __func__, qid);
+       return qid;
+}
+
+void c4iw_put_qpid(struct c4iw_rdev *rdev, u32 qid,
+                  struct c4iw_dev_ucontext *uctx)
+{
+       struct c4iw_qid_list *entry;
+
+       entry = kmalloc(sizeof *entry, GFP_KERNEL);
+       if (!entry)
+               return;
+       PDBG("%s qid 0x%x\n", __func__, qid);
+       entry->qid = qid;
+       mutex_lock(&uctx->lock);
+       list_add_tail(&entry->entry, &uctx->qpids);
+       mutex_unlock(&uctx->lock);
+}
+
+void c4iw_destroy_resource(struct c4iw_resource *rscp)
+{
+       kfifo_free(&rscp->tpt_fifo);
+       kfifo_free(&rscp->qid_fifo);
+       kfifo_free(&rscp->pdid_fifo);
+}
+
+/*
+ * PBL Memory Manager.  Uses Linux generic allocator.
+ */
+
+#define MIN_PBL_SHIFT 8                        /* 256B == min PBL size (32 entries) */
+
+u32 c4iw_pblpool_alloc(struct c4iw_rdev *rdev, int size)
+{
+       unsigned long addr = gen_pool_alloc(rdev->pbl_pool, size);
+       PDBG("%s addr 0x%x size %d\n", __func__, (u32)addr, size);
+       return (u32)addr;
+}
+
+void c4iw_pblpool_free(struct c4iw_rdev *rdev, u32 addr, int size)
+{
+       PDBG("%s addr 0x%x size %d\n", __func__, addr, size);
+       gen_pool_free(rdev->pbl_pool, (unsigned long)addr, size);
+}
+
+int c4iw_pblpool_create(struct c4iw_rdev *rdev)
+{
+       unsigned pbl_start, pbl_chunk, pbl_top;
+
+       rdev->pbl_pool = gen_pool_create(MIN_PBL_SHIFT, -1);
+       if (!rdev->pbl_pool)
+               return -ENOMEM;
+
+       pbl_start = rdev->lldi.vr->pbl.start;
+       pbl_chunk = rdev->lldi.vr->pbl.size;
+       pbl_top = pbl_start + pbl_chunk;
+
+       while (pbl_start < pbl_top) {
+               pbl_chunk = min(pbl_top - pbl_start + 1, pbl_chunk);
+               if (gen_pool_add(rdev->pbl_pool, pbl_start, pbl_chunk, -1)) {
+                       PDBG("%s failed to add PBL chunk (%x/%x)\n",
+                            __func__, pbl_start, pbl_chunk);
+                       if (pbl_chunk <= 1024 << MIN_PBL_SHIFT) {
+                               printk(KERN_WARNING MOD
+                                      "Failed to add all PBL chunks (%x/%x)\n",
+                                      pbl_start,
+                                      pbl_top - pbl_start);
+                               return 0;
+                       }
+                       pbl_chunk >>= 1;
+               } else {
+                       PDBG("%s added PBL chunk (%x/%x)\n",
+                            __func__, pbl_start, pbl_chunk);
+                       pbl_start += pbl_chunk;
+               }
+       }
+
+       return 0;
+}
+
+void c4iw_pblpool_destroy(struct c4iw_rdev *rdev)
+{
+       gen_pool_destroy(rdev->pbl_pool);
+}
+
+/*
+ * RQT Memory Manager.  Uses Linux generic allocator.
+ */
+
+#define MIN_RQT_SHIFT 10       /* 1KB == min RQT size (16 entries) */
+
+u32 c4iw_rqtpool_alloc(struct c4iw_rdev *rdev, int size)
+{
+       unsigned long addr = gen_pool_alloc(rdev->rqt_pool, size << 6);
+       PDBG("%s addr 0x%x size %d\n", __func__, (u32)addr, size << 6);
+       return (u32)addr;
+}
+
+void c4iw_rqtpool_free(struct c4iw_rdev *rdev, u32 addr, int size)
+{
+       PDBG("%s addr 0x%x size %d\n", __func__, addr, size << 6);
+       gen_pool_free(rdev->rqt_pool, (unsigned long)addr, size << 6);
+}
+
+int c4iw_rqtpool_create(struct c4iw_rdev *rdev)
+{
+       unsigned rqt_start, rqt_chunk, rqt_top;
+
+       rdev->rqt_pool = gen_pool_create(MIN_RQT_SHIFT, -1);
+       if (!rdev->rqt_pool)
+               return -ENOMEM;
+
+       rqt_start = rdev->lldi.vr->rq.start;
+       rqt_chunk = rdev->lldi.vr->rq.size;
+       rqt_top = rqt_start + rqt_chunk;
+
+       while (rqt_start < rqt_top) {
+               rqt_chunk = min(rqt_top - rqt_start + 1, rqt_chunk);
+               if (gen_pool_add(rdev->rqt_pool, rqt_start, rqt_chunk, -1)) {
+                       PDBG("%s failed to add RQT chunk (%x/%x)\n",
+                            __func__, rqt_start, rqt_chunk);
+                       if (rqt_chunk <= 1024 << MIN_RQT_SHIFT) {
+                               printk(KERN_WARNING MOD
+                                      "Failed to add all RQT chunks (%x/%x)\n",
+                                      rqt_start, rqt_top - rqt_start);
+                               return 0;
+                       }
+                       rqt_chunk >>= 1;
+               } else {
+                       PDBG("%s added RQT chunk (%x/%x)\n",
+                            __func__, rqt_start, rqt_chunk);
+                       rqt_start += rqt_chunk;
+               }
+       }
+       return 0;
+}
+
+void c4iw_rqtpool_destroy(struct c4iw_rdev *rdev)
+{
+       gen_pool_destroy(rdev->rqt_pool);
+}
diff --git a/drivers/infiniband/hw/cxgb4/t4.h b/drivers/infiniband/hw/cxgb4/t4.h
new file mode 100644 (file)
index 0000000..d0e8af3
--- /dev/null
@@ -0,0 +1,550 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#ifndef __T4_H__
+#define __T4_H__
+
+#include "t4_hw.h"
+#include "t4_regs.h"
+#include "t4_msg.h"
+#include "t4fw_ri_api.h"
+
+#define T4_QID_BASE 1024
+#define T4_MAX_QIDS 256
+#define T4_MAX_NUM_QP (1<<16)
+#define T4_MAX_NUM_CQ (1<<15)
+#define T4_MAX_NUM_PD (1<<15)
+#define T4_MAX_PBL_SIZE 256
+#define T4_MAX_RQ_SIZE 1024
+#define T4_MAX_SQ_SIZE 1024
+#define T4_MAX_QP_DEPTH (T4_MAX_RQ_SIZE-1)
+#define T4_MAX_CQ_DEPTH 8192
+#define T4_MAX_NUM_STAG (1<<15)
+#define T4_MAX_MR_SIZE (~0ULL - 1)
+#define T4_PAGESIZE_MASK 0xffff000  /* 4KB-128MB */
+#define T4_STAG_UNSET 0xffffffff
+#define T4_FW_MAJ 0
+#define T4_EQ_STATUS_ENTRIES (L1_CACHE_BYTES > 64 ? 2 : 1)
+
+struct t4_status_page {
+       __be32 rsvd1;   /* flit 0 - hw owns */
+       __be16 rsvd2;
+       __be16 qid;
+       __be16 cidx;
+       __be16 pidx;
+       u8 qp_err;      /* flit 1 - sw owns */
+       u8 db_off;
+};
+
+#define T4_EQ_SIZE 64
+
+#define T4_SQ_NUM_SLOTS 4
+#define T4_SQ_NUM_BYTES (T4_EQ_SIZE * T4_SQ_NUM_SLOTS)
+#define T4_MAX_SEND_SGE ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_send_wr) - \
+                       sizeof(struct fw_ri_isgl)) / sizeof(struct fw_ri_sge))
+#define T4_MAX_SEND_INLINE ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_send_wr) - \
+                       sizeof(struct fw_ri_immd)))
+#define T4_MAX_WRITE_INLINE ((T4_SQ_NUM_BYTES - \
+                       sizeof(struct fw_ri_rdma_write_wr) - \
+                       sizeof(struct fw_ri_immd)))
+#define T4_MAX_WRITE_SGE ((T4_SQ_NUM_BYTES - \
+                       sizeof(struct fw_ri_rdma_write_wr) - \
+                       sizeof(struct fw_ri_isgl)) / sizeof(struct fw_ri_sge))
+#define T4_MAX_FR_IMMD ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_fr_nsmr_wr) - \
+                       sizeof(struct fw_ri_immd)))
+#define T4_MAX_FR_DEPTH 255
+
+#define T4_RQ_NUM_SLOTS 2
+#define T4_RQ_NUM_BYTES (T4_EQ_SIZE * T4_RQ_NUM_SLOTS)
+#define T4_MAX_RECV_SGE ((T4_RQ_NUM_BYTES - sizeof(struct fw_ri_recv_wr) - \
+                       sizeof(struct fw_ri_isgl)) / sizeof(struct fw_ri_sge))
+
+union t4_wr {
+       struct fw_ri_res_wr res;
+       struct fw_ri_wr ri;
+       struct fw_ri_rdma_write_wr write;
+       struct fw_ri_send_wr send;
+       struct fw_ri_rdma_read_wr read;
+       struct fw_ri_bind_mw_wr bind;
+       struct fw_ri_fr_nsmr_wr fr;
+       struct fw_ri_inv_lstag_wr inv;
+       struct t4_status_page status;
+       __be64 flits[T4_EQ_SIZE / sizeof(__be64) * T4_SQ_NUM_SLOTS];
+};
+
+union t4_recv_wr {
+       struct fw_ri_recv_wr recv;
+       struct t4_status_page status;
+       __be64 flits[T4_EQ_SIZE / sizeof(__be64) * T4_RQ_NUM_SLOTS];
+};
+
+static inline void init_wr_hdr(union t4_wr *wqe, u16 wrid,
+                              enum fw_wr_opcodes opcode, u8 flags, u8 len16)
+{
+       int slots_used;
+
+       wqe->send.opcode = (u8)opcode;
+       wqe->send.flags = flags;
+       wqe->send.wrid = wrid;
+       wqe->send.r1[0] = 0;
+       wqe->send.r1[1] = 0;
+       wqe->send.r1[2] = 0;
+       wqe->send.len16 = len16;
+
+       slots_used = DIV_ROUND_UP(len16*16, T4_EQ_SIZE);
+       while (slots_used < T4_SQ_NUM_SLOTS) {
+               wqe->flits[slots_used * T4_EQ_SIZE / sizeof(__be64)] = 0;
+               slots_used++;
+       }
+}
+
+/* CQE/AE status codes */
+#define T4_ERR_SUCCESS                     0x0
+#define T4_ERR_STAG                        0x1 /* STAG invalid: either the */
+                                               /* STAG is offlimt, being 0, */
+                                               /* or STAG_key mismatch */
+#define T4_ERR_PDID                        0x2 /* PDID mismatch */
+#define T4_ERR_QPID                        0x3 /* QPID mismatch */
+#define T4_ERR_ACCESS                      0x4 /* Invalid access right */
+#define T4_ERR_WRAP                        0x5 /* Wrap error */
+#define T4_ERR_BOUND                       0x6 /* base and bounds voilation */
+#define T4_ERR_INVALIDATE_SHARED_MR        0x7 /* attempt to invalidate a  */
+                                               /* shared memory region */
+#define T4_ERR_INVALIDATE_MR_WITH_MW_BOUND 0x8 /* attempt to invalidate a  */
+                                               /* shared memory region */
+#define T4_ERR_ECC                         0x9 /* ECC error detected */
+#define T4_ERR_ECC_PSTAG                   0xA /* ECC error detected when  */
+                                               /* reading PSTAG for a MW  */
+                                               /* Invalidate */
+#define T4_ERR_PBL_ADDR_BOUND              0xB /* pbl addr out of bounds:  */
+                                               /* software error */
+#define T4_ERR_SWFLUSH                    0xC  /* SW FLUSHED */
+#define T4_ERR_CRC                         0x10 /* CRC error */
+#define T4_ERR_MARKER                      0x11 /* Marker error */
+#define T4_ERR_PDU_LEN_ERR                 0x12 /* invalid PDU length */
+#define T4_ERR_OUT_OF_RQE                  0x13 /* out of RQE */
+#define T4_ERR_DDP_VERSION                 0x14 /* wrong DDP version */
+#define T4_ERR_RDMA_VERSION                0x15 /* wrong RDMA version */
+#define T4_ERR_OPCODE                      0x16 /* invalid rdma opcode */
+#define T4_ERR_DDP_QUEUE_NUM               0x17 /* invalid ddp queue number */
+#define T4_ERR_MSN                         0x18 /* MSN error */
+#define T4_ERR_TBIT                        0x19 /* tag bit not set correctly */
+#define T4_ERR_MO                          0x1A /* MO not 0 for TERMINATE  */
+                                               /* or READ_REQ */
+#define T4_ERR_MSN_GAP                     0x1B
+#define T4_ERR_MSN_RANGE                   0x1C
+#define T4_ERR_IRD_OVERFLOW                0x1D
+#define T4_ERR_RQE_ADDR_BOUND              0x1E /* RQE addr out of bounds:  */
+                                               /* software error */
+#define T4_ERR_INTERNAL_ERR                0x1F /* internal error (opcode  */
+                                               /* mismatch) */
+/*
+ * CQE defs
+ */
+struct t4_cqe {
+       __be32 header;
+       __be32 len;
+       union {
+               struct {
+                       __be32 stag;
+                       __be32 msn;
+               } rcqe;
+               struct {
+                       u32 nada1;
+                       u16 nada2;
+                       u16 cidx;
+               } scqe;
+               struct {
+                       __be32 wrid_hi;
+                       __be32 wrid_low;
+               } gen;
+       } u;
+       __be64 reserved;
+       __be64 bits_type_ts;
+};
+
+/* macros for flit 0 of the cqe */
+
+#define S_CQE_QPID        12
+#define M_CQE_QPID        0xFFFFF
+#define G_CQE_QPID(x)     ((((x) >> S_CQE_QPID)) & M_CQE_QPID)
+#define V_CQE_QPID(x)    ((x)<<S_CQE_QPID)
+
+#define S_CQE_SWCQE       11
+#define M_CQE_SWCQE       0x1
+#define G_CQE_SWCQE(x)    ((((x) >> S_CQE_SWCQE)) & M_CQE_SWCQE)
+#define V_CQE_SWCQE(x)   ((x)<<S_CQE_SWCQE)
+
+#define S_CQE_STATUS      5
+#define M_CQE_STATUS      0x1F
+#define G_CQE_STATUS(x)   ((((x) >> S_CQE_STATUS)) & M_CQE_STATUS)
+#define V_CQE_STATUS(x)   ((x)<<S_CQE_STATUS)
+
+#define S_CQE_TYPE        4
+#define M_CQE_TYPE        0x1
+#define G_CQE_TYPE(x)     ((((x) >> S_CQE_TYPE)) & M_CQE_TYPE)
+#define V_CQE_TYPE(x)     ((x)<<S_CQE_TYPE)
+
+#define S_CQE_OPCODE      0
+#define M_CQE_OPCODE      0xF
+#define G_CQE_OPCODE(x)   ((((x) >> S_CQE_OPCODE)) & M_CQE_OPCODE)
+#define V_CQE_OPCODE(x)   ((x)<<S_CQE_OPCODE)
+
+#define SW_CQE(x)         (G_CQE_SWCQE(be32_to_cpu((x)->header)))
+#define CQE_QPID(x)       (G_CQE_QPID(be32_to_cpu((x)->header)))
+#define CQE_TYPE(x)       (G_CQE_TYPE(be32_to_cpu((x)->header)))
+#define SQ_TYPE(x)       (CQE_TYPE((x)))
+#define RQ_TYPE(x)       (!CQE_TYPE((x)))
+#define CQE_STATUS(x)     (G_CQE_STATUS(be32_to_cpu((x)->header)))
+#define CQE_OPCODE(x)     (G_CQE_OPCODE(be32_to_cpu((x)->header)))
+
+#define CQE_SEND_OPCODE(x)( \
+       (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND) || \
+       (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_SE) || \
+       (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_INV) || \
+       (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_SE_INV))
+
+#define CQE_LEN(x)        (be32_to_cpu((x)->len))
+
+/* used for RQ completion processing */
+#define CQE_WRID_STAG(x)  (be32_to_cpu((x)->u.rcqe.stag))
+#define CQE_WRID_MSN(x)   (be32_to_cpu((x)->u.rcqe.msn))
+
+/* used for SQ completion processing */
+#define CQE_WRID_SQ_IDX(x)     ((x)->u.scqe.cidx)
+
+/* generic accessor macros */
+#define CQE_WRID_HI(x)         ((x)->u.gen.wrid_hi)
+#define CQE_WRID_LOW(x)                ((x)->u.gen.wrid_low)
+
+/* macros for flit 3 of the cqe */
+#define S_CQE_GENBIT   63
+#define M_CQE_GENBIT   0x1
+#define G_CQE_GENBIT(x)        (((x) >> S_CQE_GENBIT) & M_CQE_GENBIT)
+#define V_CQE_GENBIT(x) ((x)<<S_CQE_GENBIT)
+
+#define S_CQE_OVFBIT   62
+#define M_CQE_OVFBIT   0x1
+#define G_CQE_OVFBIT(x)        ((((x) >> S_CQE_OVFBIT)) & M_CQE_OVFBIT)
+
+#define S_CQE_IQTYPE   60
+#define M_CQE_IQTYPE   0x3
+#define G_CQE_IQTYPE(x)        ((((x) >> S_CQE_IQTYPE)) & M_CQE_IQTYPE)
+
+#define M_CQE_TS       0x0fffffffffffffffULL
+#define G_CQE_TS(x)    ((x) & M_CQE_TS)
+
+#define CQE_OVFBIT(x)  ((unsigned)G_CQE_OVFBIT(be64_to_cpu((x)->bits_type_ts)))
+#define CQE_GENBIT(x)  ((unsigned)G_CQE_GENBIT(be64_to_cpu((x)->bits_type_ts)))
+#define CQE_TS(x)      (G_CQE_TS(be64_to_cpu((x)->bits_type_ts)))
+
+struct t4_swsqe {
+       u64                     wr_id;
+       struct t4_cqe           cqe;
+       int                     read_len;
+       int                     opcode;
+       int                     complete;
+       int                     signaled;
+       u16                     idx;
+};
+
+struct t4_sq {
+       union t4_wr *queue;
+       dma_addr_t dma_addr;
+       DECLARE_PCI_UNMAP_ADDR(mapping);
+       struct t4_swsqe *sw_sq;
+       struct t4_swsqe *oldest_read;
+       u64 udb;
+       size_t memsize;
+       u32 qid;
+       u16 in_use;
+       u16 size;
+       u16 cidx;
+       u16 pidx;
+};
+
+struct t4_swrqe {
+       u64 wr_id;
+};
+
+struct t4_rq {
+       union  t4_recv_wr *queue;
+       dma_addr_t dma_addr;
+       DECLARE_PCI_UNMAP_ADDR(mapping);
+       struct t4_swrqe *sw_rq;
+       u64 udb;
+       size_t memsize;
+       u32 qid;
+       u32 msn;
+       u32 rqt_hwaddr;
+       u16 rqt_size;
+       u16 in_use;
+       u16 size;
+       u16 cidx;
+       u16 pidx;
+};
+
+struct t4_wq {
+       struct t4_sq sq;
+       struct t4_rq rq;
+       void __iomem *db;
+       void __iomem *gts;
+       struct c4iw_rdev *rdev;
+};
+
+static inline int t4_rqes_posted(struct t4_wq *wq)
+{
+       return wq->rq.in_use;
+}
+
+static inline int t4_rq_empty(struct t4_wq *wq)
+{
+       return wq->rq.in_use == 0;
+}
+
+static inline int t4_rq_full(struct t4_wq *wq)
+{
+       return wq->rq.in_use == (wq->rq.size - 1);
+}
+
+static inline u32 t4_rq_avail(struct t4_wq *wq)
+{
+       return wq->rq.size - 1 - wq->rq.in_use;
+}
+
+static inline void t4_rq_produce(struct t4_wq *wq)
+{
+       wq->rq.in_use++;
+       if (++wq->rq.pidx == wq->rq.size)
+               wq->rq.pidx = 0;
+}
+
+static inline void t4_rq_consume(struct t4_wq *wq)
+{
+       wq->rq.in_use--;
+       wq->rq.msn++;
+       if (++wq->rq.cidx == wq->rq.size)
+               wq->rq.cidx = 0;
+}
+
+static inline int t4_sq_empty(struct t4_wq *wq)
+{
+       return wq->sq.in_use == 0;
+}
+
+static inline int t4_sq_full(struct t4_wq *wq)
+{
+       return wq->sq.in_use == (wq->sq.size - 1);
+}
+
+static inline u32 t4_sq_avail(struct t4_wq *wq)
+{
+       return wq->sq.size - 1 - wq->sq.in_use;
+}
+
+static inline void t4_sq_produce(struct t4_wq *wq)
+{
+       wq->sq.in_use++;
+       if (++wq->sq.pidx == wq->sq.size)
+               wq->sq.pidx = 0;
+}
+
+static inline void t4_sq_consume(struct t4_wq *wq)
+{
+       wq->sq.in_use--;
+       if (++wq->sq.cidx == wq->sq.size)
+               wq->sq.cidx = 0;
+}
+
+static inline void t4_ring_sq_db(struct t4_wq *wq, u16 inc)
+{
+       inc *= T4_SQ_NUM_SLOTS;
+       wmb();
+       writel(QID(wq->sq.qid) | PIDX(inc), wq->db);
+}
+
+static inline void t4_ring_rq_db(struct t4_wq *wq, u16 inc)
+{
+       inc *= T4_RQ_NUM_SLOTS;
+       wmb();
+       writel(QID(wq->rq.qid) | PIDX(inc), wq->db);
+}
+
+static inline int t4_wq_in_error(struct t4_wq *wq)
+{
+       return wq->sq.queue[wq->sq.size].status.qp_err;
+}
+
+static inline void t4_set_wq_in_error(struct t4_wq *wq)
+{
+       wq->sq.queue[wq->sq.size].status.qp_err = 1;
+       wq->rq.queue[wq->rq.size].status.qp_err = 1;
+}
+
+static inline void t4_disable_wq_db(struct t4_wq *wq)
+{
+       wq->sq.queue[wq->sq.size].status.db_off = 1;
+       wq->rq.queue[wq->rq.size].status.db_off = 1;
+}
+
+static inline void t4_enable_wq_db(struct t4_wq *wq)
+{
+       wq->sq.queue[wq->sq.size].status.db_off = 0;
+       wq->rq.queue[wq->rq.size].status.db_off = 0;
+}
+
+static inline int t4_wq_db_enabled(struct t4_wq *wq)
+{
+       return !wq->sq.queue[wq->sq.size].status.db_off;
+}
+
+struct t4_cq {
+       struct t4_cqe *queue;
+       dma_addr_t dma_addr;
+       DECLARE_PCI_UNMAP_ADDR(mapping);
+       struct t4_cqe *sw_queue;
+       void __iomem *gts;
+       struct c4iw_rdev *rdev;
+       u64 ugts;
+       size_t memsize;
+       u64 timestamp;
+       u32 cqid;
+       u16 size; /* including status page */
+       u16 cidx;
+       u16 sw_pidx;
+       u16 sw_cidx;
+       u16 sw_in_use;
+       u16 cidx_inc;
+       u8 gen;
+       u8 error;
+};
+
+static inline int t4_arm_cq(struct t4_cq *cq, int se)
+{
+       u32 val;
+       u16 inc;
+
+       do {
+               /*
+                * inc must be less the both the max update value -and-
+                * the size of the CQ.
+                */
+               inc = cq->cidx_inc <= CIDXINC_MASK ? cq->cidx_inc :
+                                                    CIDXINC_MASK;
+               inc = inc <= (cq->size - 1) ? inc : (cq->size - 1);
+               if (inc == cq->cidx_inc)
+                       val = SEINTARM(se) | CIDXINC(inc) | TIMERREG(6) |
+                             INGRESSQID(cq->cqid);
+               else
+                       val = SEINTARM(0) | CIDXINC(inc) | TIMERREG(7) |
+                             INGRESSQID(cq->cqid);
+               cq->cidx_inc -= inc;
+               writel(val, cq->gts);
+       } while (cq->cidx_inc);
+       return 0;
+}
+
+static inline void t4_swcq_produce(struct t4_cq *cq)
+{
+       cq->sw_in_use++;
+       if (++cq->sw_pidx == cq->size)
+               cq->sw_pidx = 0;
+}
+
+static inline void t4_swcq_consume(struct t4_cq *cq)
+{
+       cq->sw_in_use--;
+       if (++cq->sw_cidx == cq->size)
+               cq->sw_cidx = 0;
+}
+
+static inline void t4_hwcq_consume(struct t4_cq *cq)
+{
+       cq->cidx_inc++;
+       if (++cq->cidx == cq->size) {
+               cq->cidx = 0;
+               cq->gen ^= 1;
+       }
+}
+
+static inline int t4_valid_cqe(struct t4_cq *cq, struct t4_cqe *cqe)
+{
+       return (CQE_GENBIT(cqe) == cq->gen);
+}
+
+static inline int t4_next_hw_cqe(struct t4_cq *cq, struct t4_cqe **cqe)
+{
+       int ret = 0;
+       u64 bits_type_ts = be64_to_cpu(cq->queue[cq->cidx].bits_type_ts);
+
+       if (G_CQE_GENBIT(bits_type_ts) == cq->gen) {
+               *cqe = &cq->queue[cq->cidx];
+               cq->timestamp = G_CQE_TS(bits_type_ts);
+       } else if (G_CQE_TS(bits_type_ts) > cq->timestamp)
+               ret = -EOVERFLOW;
+       else
+               ret = -ENODATA;
+       if (ret == -EOVERFLOW) {
+               printk(KERN_ERR MOD "cq overflow cqid %u\n", cq->cqid);
+               cq->error = 1;
+       }
+       return ret;
+}
+
+static inline struct t4_cqe *t4_next_sw_cqe(struct t4_cq *cq)
+{
+       if (cq->sw_in_use)
+               return &cq->sw_queue[cq->sw_cidx];
+       return NULL;
+}
+
+static inline int t4_next_cqe(struct t4_cq *cq, struct t4_cqe **cqe)
+{
+       int ret = 0;
+
+       if (cq->error)
+               ret = -ENODATA;
+       else if (cq->sw_in_use)
+               *cqe = &cq->sw_queue[cq->sw_cidx];
+       else
+               ret = t4_next_hw_cqe(cq, cqe);
+       return ret;
+}
+
+static inline int t4_cq_in_error(struct t4_cq *cq)
+{
+       return ((struct t4_status_page *)&cq->queue[cq->size])->qp_err;
+}
+
+static inline void t4_set_cq_in_error(struct t4_cq *cq)
+{
+       ((struct t4_status_page *)&cq->queue[cq->size])->qp_err = 1;
+}
+#endif
diff --git a/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h b/drivers/infiniband/hw/cxgb4/t4fw_ri_api.h
new file mode 100644 (file)
index 0000000..fc706bd
--- /dev/null
@@ -0,0 +1,829 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#ifndef _T4FW_RI_API_H_
+#define _T4FW_RI_API_H_
+
+#include "t4fw_api.h"
+
+enum fw_ri_wr_opcode {
+       FW_RI_RDMA_WRITE                = 0x0,  /* IETF RDMAP v1.0 ... */
+       FW_RI_READ_REQ                  = 0x1,
+       FW_RI_READ_RESP                 = 0x2,
+       FW_RI_SEND                      = 0x3,
+       FW_RI_SEND_WITH_INV             = 0x4,
+       FW_RI_SEND_WITH_SE              = 0x5,
+       FW_RI_SEND_WITH_SE_INV          = 0x6,
+       FW_RI_TERMINATE                 = 0x7,
+       FW_RI_RDMA_INIT                 = 0x8,  /* CHELSIO RI specific ... */
+       FW_RI_BIND_MW                   = 0x9,
+       FW_RI_FAST_REGISTER             = 0xa,
+       FW_RI_LOCAL_INV                 = 0xb,
+       FW_RI_QP_MODIFY                 = 0xc,
+       FW_RI_BYPASS                    = 0xd,
+       FW_RI_RECEIVE                   = 0xe,
+
+       FW_RI_SGE_EC_CR_RETURN          = 0xf
+};
+
+enum fw_ri_wr_flags {
+       FW_RI_COMPLETION_FLAG           = 0x01,
+       FW_RI_NOTIFICATION_FLAG         = 0x02,
+       FW_RI_SOLICITED_EVENT_FLAG      = 0x04,
+       FW_RI_READ_FENCE_FLAG           = 0x08,
+       FW_RI_LOCAL_FENCE_FLAG          = 0x10,
+       FW_RI_RDMA_READ_INVALIDATE      = 0x20
+};
+
+enum fw_ri_mpa_attrs {
+       FW_RI_MPA_RX_MARKER_ENABLE      = 0x01,
+       FW_RI_MPA_TX_MARKER_ENABLE      = 0x02,
+       FW_RI_MPA_CRC_ENABLE            = 0x04,
+       FW_RI_MPA_IETF_ENABLE           = 0x08
+};
+
+enum fw_ri_qp_caps {
+       FW_RI_QP_RDMA_READ_ENABLE       = 0x01,
+       FW_RI_QP_RDMA_WRITE_ENABLE      = 0x02,
+       FW_RI_QP_BIND_ENABLE            = 0x04,
+       FW_RI_QP_FAST_REGISTER_ENABLE   = 0x08,
+       FW_RI_QP_STAG0_ENABLE           = 0x10
+};
+
+enum fw_ri_addr_type {
+       FW_RI_ZERO_BASED_TO             = 0x00,
+       FW_RI_VA_BASED_TO               = 0x01
+};
+
+enum fw_ri_mem_perms {
+       FW_RI_MEM_ACCESS_REM_WRITE      = 0x01,
+       FW_RI_MEM_ACCESS_REM_READ       = 0x02,
+       FW_RI_MEM_ACCESS_REM            = 0x03,
+       FW_RI_MEM_ACCESS_LOCAL_WRITE    = 0x04,
+       FW_RI_MEM_ACCESS_LOCAL_READ     = 0x08,
+       FW_RI_MEM_ACCESS_LOCAL          = 0x0C
+};
+
+enum fw_ri_stag_type {
+       FW_RI_STAG_NSMR                 = 0x00,
+       FW_RI_STAG_SMR                  = 0x01,
+       FW_RI_STAG_MW                   = 0x02,
+       FW_RI_STAG_MW_RELAXED           = 0x03
+};
+
+enum fw_ri_data_op {
+       FW_RI_DATA_IMMD                 = 0x81,
+       FW_RI_DATA_DSGL                 = 0x82,
+       FW_RI_DATA_ISGL                 = 0x83
+};
+
+enum fw_ri_sgl_depth {
+       FW_RI_SGL_DEPTH_MAX_SQ          = 16,
+       FW_RI_SGL_DEPTH_MAX_RQ          = 4
+};
+
+struct fw_ri_dsge_pair {
+       __be32  len[2];
+       __be64  addr[2];
+};
+
+struct fw_ri_dsgl {
+       __u8    op;
+       __u8    r1;
+       __be16  nsge;
+       __be32  len0;
+       __be64  addr0;
+#ifndef C99_NOT_SUPPORTED
+       struct fw_ri_dsge_pair sge[0];
+#endif
+};
+
+struct fw_ri_sge {
+       __be32 stag;
+       __be32 len;
+       __be64 to;
+};
+
+struct fw_ri_isgl {
+       __u8    op;
+       __u8    r1;
+       __be16  nsge;
+       __be32  r2;
+#ifndef C99_NOT_SUPPORTED
+       struct fw_ri_sge sge[0];
+#endif
+};
+
+struct fw_ri_immd {
+       __u8    op;
+       __u8    r1;
+       __be16  r2;
+       __be32  immdlen;
+#ifndef C99_NOT_SUPPORTED
+       __u8    data[0];
+#endif
+};
+
+struct fw_ri_tpte {
+       __be32 valid_to_pdid;
+       __be32 locread_to_qpid;
+       __be32 nosnoop_pbladdr;
+       __be32 len_lo;
+       __be32 va_hi;
+       __be32 va_lo_fbo;
+       __be32 dca_mwbcnt_pstag;
+       __be32 len_hi;
+};
+
+#define S_FW_RI_TPTE_VALID             31
+#define M_FW_RI_TPTE_VALID             0x1
+#define V_FW_RI_TPTE_VALID(x)          ((x) << S_FW_RI_TPTE_VALID)
+#define G_FW_RI_TPTE_VALID(x)          \
+    (((x) >> S_FW_RI_TPTE_VALID) & M_FW_RI_TPTE_VALID)
+#define F_FW_RI_TPTE_VALID             V_FW_RI_TPTE_VALID(1U)
+
+#define S_FW_RI_TPTE_STAGKEY           23
+#define M_FW_RI_TPTE_STAGKEY           0xff
+#define V_FW_RI_TPTE_STAGKEY(x)                ((x) << S_FW_RI_TPTE_STAGKEY)
+#define G_FW_RI_TPTE_STAGKEY(x)                \
+    (((x) >> S_FW_RI_TPTE_STAGKEY) & M_FW_RI_TPTE_STAGKEY)
+
+#define S_FW_RI_TPTE_STAGSTATE         22
+#define M_FW_RI_TPTE_STAGSTATE         0x1
+#define V_FW_RI_TPTE_STAGSTATE(x)      ((x) << S_FW_RI_TPTE_STAGSTATE)
+#define G_FW_RI_TPTE_STAGSTATE(x)      \
+    (((x) >> S_FW_RI_TPTE_STAGSTATE) & M_FW_RI_TPTE_STAGSTATE)
+#define F_FW_RI_TPTE_STAGSTATE         V_FW_RI_TPTE_STAGSTATE(1U)
+
+#define S_FW_RI_TPTE_STAGTYPE          20
+#define M_FW_RI_TPTE_STAGTYPE          0x3
+#define V_FW_RI_TPTE_STAGTYPE(x)       ((x) << S_FW_RI_TPTE_STAGTYPE)
+#define G_FW_RI_TPTE_STAGTYPE(x)       \
+    (((x) >> S_FW_RI_TPTE_STAGTYPE) & M_FW_RI_TPTE_STAGTYPE)
+
+#define S_FW_RI_TPTE_PDID              0
+#define M_FW_RI_TPTE_PDID              0xfffff
+#define V_FW_RI_TPTE_PDID(x)           ((x) << S_FW_RI_TPTE_PDID)
+#define G_FW_RI_TPTE_PDID(x)           \
+    (((x) >> S_FW_RI_TPTE_PDID) & M_FW_RI_TPTE_PDID)
+
+#define S_FW_RI_TPTE_PERM              28
+#define M_FW_RI_TPTE_PERM              0xf
+#define V_FW_RI_TPTE_PERM(x)           ((x) << S_FW_RI_TPTE_PERM)
+#define G_FW_RI_TPTE_PERM(x)           \
+    (((x) >> S_FW_RI_TPTE_PERM) & M_FW_RI_TPTE_PERM)
+
+#define S_FW_RI_TPTE_REMINVDIS         27
+#define M_FW_RI_TPTE_REMINVDIS         0x1
+#define V_FW_RI_TPTE_REMINVDIS(x)      ((x) << S_FW_RI_TPTE_REMINVDIS)
+#define G_FW_RI_TPTE_REMINVDIS(x)      \
+    (((x) >> S_FW_RI_TPTE_REMINVDIS) & M_FW_RI_TPTE_REMINVDIS)
+#define F_FW_RI_TPTE_REMINVDIS         V_FW_RI_TPTE_REMINVDIS(1U)
+
+#define S_FW_RI_TPTE_ADDRTYPE          26
+#define M_FW_RI_TPTE_ADDRTYPE          1
+#define V_FW_RI_TPTE_ADDRTYPE(x)       ((x) << S_FW_RI_TPTE_ADDRTYPE)
+#define G_FW_RI_TPTE_ADDRTYPE(x)       \
+    (((x) >> S_FW_RI_TPTE_ADDRTYPE) & M_FW_RI_TPTE_ADDRTYPE)
+#define F_FW_RI_TPTE_ADDRTYPE          V_FW_RI_TPTE_ADDRTYPE(1U)
+
+#define S_FW_RI_TPTE_MWBINDEN          25
+#define M_FW_RI_TPTE_MWBINDEN          0x1
+#define V_FW_RI_TPTE_MWBINDEN(x)       ((x) << S_FW_RI_TPTE_MWBINDEN)
+#define G_FW_RI_TPTE_MWBINDEN(x)       \
+    (((x) >> S_FW_RI_TPTE_MWBINDEN) & M_FW_RI_TPTE_MWBINDEN)
+#define F_FW_RI_TPTE_MWBINDEN          V_FW_RI_TPTE_MWBINDEN(1U)
+
+#define S_FW_RI_TPTE_PS                        20
+#define M_FW_RI_TPTE_PS                        0x1f
+#define V_FW_RI_TPTE_PS(x)             ((x) << S_FW_RI_TPTE_PS)
+#define G_FW_RI_TPTE_PS(x)             \
+    (((x) >> S_FW_RI_TPTE_PS) & M_FW_RI_TPTE_PS)
+
+#define S_FW_RI_TPTE_QPID              0
+#define M_FW_RI_TPTE_QPID              0xfffff
+#define V_FW_RI_TPTE_QPID(x)           ((x) << S_FW_RI_TPTE_QPID)
+#define G_FW_RI_TPTE_QPID(x)           \
+    (((x) >> S_FW_RI_TPTE_QPID) & M_FW_RI_TPTE_QPID)
+
+#define S_FW_RI_TPTE_NOSNOOP           30
+#define M_FW_RI_TPTE_NOSNOOP           0x1
+#define V_FW_RI_TPTE_NOSNOOP(x)                ((x) << S_FW_RI_TPTE_NOSNOOP)
+#define G_FW_RI_TPTE_NOSNOOP(x)                \
+    (((x) >> S_FW_RI_TPTE_NOSNOOP) & M_FW_RI_TPTE_NOSNOOP)
+#define F_FW_RI_TPTE_NOSNOOP           V_FW_RI_TPTE_NOSNOOP(1U)
+
+#define S_FW_RI_TPTE_PBLADDR           0
+#define M_FW_RI_TPTE_PBLADDR           0x1fffffff
+#define V_FW_RI_TPTE_PBLADDR(x)                ((x) << S_FW_RI_TPTE_PBLADDR)
+#define G_FW_RI_TPTE_PBLADDR(x)                \
+    (((x) >> S_FW_RI_TPTE_PBLADDR) & M_FW_RI_TPTE_PBLADDR)
+
+#define S_FW_RI_TPTE_DCA               24
+#define M_FW_RI_TPTE_DCA               0x1f
+#define V_FW_RI_TPTE_DCA(x)            ((x) << S_FW_RI_TPTE_DCA)
+#define G_FW_RI_TPTE_DCA(x)            \
+    (((x) >> S_FW_RI_TPTE_DCA) & M_FW_RI_TPTE_DCA)
+
+#define S_FW_RI_TPTE_MWBCNT_PSTAG      0
+#define M_FW_RI_TPTE_MWBCNT_PSTAG      0xffffff
+#define V_FW_RI_TPTE_MWBCNT_PSTAT(x)   \
+    ((x) << S_FW_RI_TPTE_MWBCNT_PSTAG)
+#define G_FW_RI_TPTE_MWBCNT_PSTAG(x)   \
+    (((x) >> S_FW_RI_TPTE_MWBCNT_PSTAG) & M_FW_RI_TPTE_MWBCNT_PSTAG)
+
+enum fw_ri_res_type {
+       FW_RI_RES_TYPE_SQ,
+       FW_RI_RES_TYPE_RQ,
+       FW_RI_RES_TYPE_CQ,
+};
+
+enum fw_ri_res_op {
+       FW_RI_RES_OP_WRITE,
+       FW_RI_RES_OP_RESET,
+};
+
+struct fw_ri_res {
+       union fw_ri_restype {
+               struct fw_ri_res_sqrq {
+                       __u8   restype;
+                       __u8   op;
+                       __be16 r3;
+                       __be32 eqid;
+                       __be32 r4[2];
+                       __be32 fetchszm_to_iqid;
+                       __be32 dcaen_to_eqsize;
+                       __be64 eqaddr;
+               } sqrq;
+               struct fw_ri_res_cq {
+                       __u8   restype;
+                       __u8   op;
+                       __be16 r3;
+                       __be32 iqid;
+                       __be32 r4[2];
+                       __be32 iqandst_to_iqandstindex;
+                       __be16 iqdroprss_to_iqesize;
+                       __be16 iqsize;
+                       __be64 iqaddr;
+                       __be32 iqns_iqro;
+                       __be32 r6_lo;
+                       __be64 r7;
+               } cq;
+       } u;
+};
+
+struct fw_ri_res_wr {
+       __be32 op_nres;
+       __be32 len16_pkd;
+       __u64  cookie;
+#ifndef C99_NOT_SUPPORTED
+       struct fw_ri_res res[0];
+#endif
+};
+
+#define S_FW_RI_RES_WR_NRES    0
+#define M_FW_RI_RES_WR_NRES    0xff
+#define V_FW_RI_RES_WR_NRES(x) ((x) << S_FW_RI_RES_WR_NRES)
+#define G_FW_RI_RES_WR_NRES(x) \
+    (((x) >> S_FW_RI_RES_WR_NRES) & M_FW_RI_RES_WR_NRES)
+
+#define S_FW_RI_RES_WR_FETCHSZM                26
+#define M_FW_RI_RES_WR_FETCHSZM                0x1
+#define V_FW_RI_RES_WR_FETCHSZM(x)     ((x) << S_FW_RI_RES_WR_FETCHSZM)
+#define G_FW_RI_RES_WR_FETCHSZM(x)     \
+    (((x) >> S_FW_RI_RES_WR_FETCHSZM) & M_FW_RI_RES_WR_FETCHSZM)
+#define F_FW_RI_RES_WR_FETCHSZM        V_FW_RI_RES_WR_FETCHSZM(1U)
+
+#define S_FW_RI_RES_WR_STATUSPGNS      25
+#define M_FW_RI_RES_WR_STATUSPGNS      0x1
+#define V_FW_RI_RES_WR_STATUSPGNS(x)   ((x) << S_FW_RI_RES_WR_STATUSPGNS)
+#define G_FW_RI_RES_WR_STATUSPGNS(x)   \
+    (((x) >> S_FW_RI_RES_WR_STATUSPGNS) & M_FW_RI_RES_WR_STATUSPGNS)
+#define F_FW_RI_RES_WR_STATUSPGNS      V_FW_RI_RES_WR_STATUSPGNS(1U)
+
+#define S_FW_RI_RES_WR_STATUSPGRO      24
+#define M_FW_RI_RES_WR_STATUSPGRO      0x1
+#define V_FW_RI_RES_WR_STATUSPGRO(x)   ((x) << S_FW_RI_RES_WR_STATUSPGRO)
+#define G_FW_RI_RES_WR_STATUSPGRO(x)   \
+    (((x) >> S_FW_RI_RES_WR_STATUSPGRO) & M_FW_RI_RES_WR_STATUSPGRO)
+#define F_FW_RI_RES_WR_STATUSPGRO      V_FW_RI_RES_WR_STATUSPGRO(1U)
+
+#define S_FW_RI_RES_WR_FETCHNS         23
+#define M_FW_RI_RES_WR_FETCHNS         0x1
+#define V_FW_RI_RES_WR_FETCHNS(x)      ((x) << S_FW_RI_RES_WR_FETCHNS)
+#define G_FW_RI_RES_WR_FETCHNS(x)      \
+    (((x) >> S_FW_RI_RES_WR_FETCHNS) & M_FW_RI_RES_WR_FETCHNS)
+#define F_FW_RI_RES_WR_FETCHNS V_FW_RI_RES_WR_FETCHNS(1U)
+
+#define S_FW_RI_RES_WR_FETCHRO         22
+#define M_FW_RI_RES_WR_FETCHRO         0x1
+#define V_FW_RI_RES_WR_FETCHRO(x)      ((x) << S_FW_RI_RES_WR_FETCHRO)
+#define G_FW_RI_RES_WR_FETCHRO(x)      \
+    (((x) >> S_FW_RI_RES_WR_FETCHRO) & M_FW_RI_RES_WR_FETCHRO)
+#define F_FW_RI_RES_WR_FETCHRO V_FW_RI_RES_WR_FETCHRO(1U)
+
+#define S_FW_RI_RES_WR_HOSTFCMODE      20
+#define M_FW_RI_RES_WR_HOSTFCMODE      0x3
+#define V_FW_RI_RES_WR_HOSTFCMODE(x)   ((x) << S_FW_RI_RES_WR_HOSTFCMODE)
+#define G_FW_RI_RES_WR_HOSTFCMODE(x)   \
+    (((x) >> S_FW_RI_RES_WR_HOSTFCMODE) & M_FW_RI_RES_WR_HOSTFCMODE)
+
+#define S_FW_RI_RES_WR_CPRIO   19
+#define M_FW_RI_RES_WR_CPRIO   0x1
+#define V_FW_RI_RES_WR_CPRIO(x)        ((x) << S_FW_RI_RES_WR_CPRIO)
+#define G_FW_RI_RES_WR_CPRIO(x)        \
+    (((x) >> S_FW_RI_RES_WR_CPRIO) & M_FW_RI_RES_WR_CPRIO)
+#define F_FW_RI_RES_WR_CPRIO   V_FW_RI_RES_WR_CPRIO(1U)
+
+#define S_FW_RI_RES_WR_ONCHIP          18
+#define M_FW_RI_RES_WR_ONCHIP          0x1
+#define V_FW_RI_RES_WR_ONCHIP(x)       ((x) << S_FW_RI_RES_WR_ONCHIP)
+#define G_FW_RI_RES_WR_ONCHIP(x)       \
+    (((x) >> S_FW_RI_RES_WR_ONCHIP) & M_FW_RI_RES_WR_ONCHIP)
+#define F_FW_RI_RES_WR_ONCHIP  V_FW_RI_RES_WR_ONCHIP(1U)
+
+#define S_FW_RI_RES_WR_PCIECHN         16
+#define M_FW_RI_RES_WR_PCIECHN         0x3
+#define V_FW_RI_RES_WR_PCIECHN(x)      ((x) << S_FW_RI_RES_WR_PCIECHN)
+#define G_FW_RI_RES_WR_PCIECHN(x)      \
+    (((x) >> S_FW_RI_RES_WR_PCIECHN) & M_FW_RI_RES_WR_PCIECHN)
+
+#define S_FW_RI_RES_WR_IQID    0
+#define M_FW_RI_RES_WR_IQID    0xffff
+#define V_FW_RI_RES_WR_IQID(x) ((x) << S_FW_RI_RES_WR_IQID)
+#define G_FW_RI_RES_WR_IQID(x) \
+    (((x) >> S_FW_RI_RES_WR_IQID) & M_FW_RI_RES_WR_IQID)
+
+#define S_FW_RI_RES_WR_DCAEN   31
+#define M_FW_RI_RES_WR_DCAEN   0x1
+#define V_FW_RI_RES_WR_DCAEN(x)        ((x) << S_FW_RI_RES_WR_DCAEN)
+#define G_FW_RI_RES_WR_DCAEN(x)        \
+    (((x) >> S_FW_RI_RES_WR_DCAEN) & M_FW_RI_RES_WR_DCAEN)
+#define F_FW_RI_RES_WR_DCAEN   V_FW_RI_RES_WR_DCAEN(1U)
+
+#define S_FW_RI_RES_WR_DCACPU          26
+#define M_FW_RI_RES_WR_DCACPU          0x1f
+#define V_FW_RI_RES_WR_DCACPU(x)       ((x) << S_FW_RI_RES_WR_DCACPU)
+#define G_FW_RI_RES_WR_DCACPU(x)       \
+    (((x) >> S_FW_RI_RES_WR_DCACPU) & M_FW_RI_RES_WR_DCACPU)
+
+#define S_FW_RI_RES_WR_FBMIN   23
+#define M_FW_RI_RES_WR_FBMIN   0x7
+#define V_FW_RI_RES_WR_FBMIN(x)        ((x) << S_FW_RI_RES_WR_FBMIN)
+#define G_FW_RI_RES_WR_FBMIN(x)        \
+    (((x) >> S_FW_RI_RES_WR_FBMIN) & M_FW_RI_RES_WR_FBMIN)
+
+#define S_FW_RI_RES_WR_FBMAX   20
+#define M_FW_RI_RES_WR_FBMAX   0x7
+#define V_FW_RI_RES_WR_FBMAX(x)        ((x) << S_FW_RI_RES_WR_FBMAX)
+#define G_FW_RI_RES_WR_FBMAX(x)        \
+    (((x) >> S_FW_RI_RES_WR_FBMAX) & M_FW_RI_RES_WR_FBMAX)
+
+#define S_FW_RI_RES_WR_CIDXFTHRESHO    19
+#define M_FW_RI_RES_WR_CIDXFTHRESHO    0x1
+#define V_FW_RI_RES_WR_CIDXFTHRESHO(x) ((x) << S_FW_RI_RES_WR_CIDXFTHRESHO)
+#define G_FW_RI_RES_WR_CIDXFTHRESHO(x) \
+    (((x) >> S_FW_RI_RES_WR_CIDXFTHRESHO) & M_FW_RI_RES_WR_CIDXFTHRESHO)
+#define F_FW_RI_RES_WR_CIDXFTHRESHO    V_FW_RI_RES_WR_CIDXFTHRESHO(1U)
+
+#define S_FW_RI_RES_WR_CIDXFTHRESH     16
+#define M_FW_RI_RES_WR_CIDXFTHRESH     0x7
+#define V_FW_RI_RES_WR_CIDXFTHRESH(x)  ((x) << S_FW_RI_RES_WR_CIDXFTHRESH)
+#define G_FW_RI_RES_WR_CIDXFTHRESH(x)  \
+    (((x) >> S_FW_RI_RES_WR_CIDXFTHRESH) & M_FW_RI_RES_WR_CIDXFTHRESH)
+
+#define S_FW_RI_RES_WR_EQSIZE          0
+#define M_FW_RI_RES_WR_EQSIZE          0xffff
+#define V_FW_RI_RES_WR_EQSIZE(x)       ((x) << S_FW_RI_RES_WR_EQSIZE)
+#define G_FW_RI_RES_WR_EQSIZE(x)       \
+    (((x) >> S_FW_RI_RES_WR_EQSIZE) & M_FW_RI_RES_WR_EQSIZE)
+
+#define S_FW_RI_RES_WR_IQANDST         15
+#define M_FW_RI_RES_WR_IQANDST         0x1
+#define V_FW_RI_RES_WR_IQANDST(x)      ((x) << S_FW_RI_RES_WR_IQANDST)
+#define G_FW_RI_RES_WR_IQANDST(x)      \
+    (((x) >> S_FW_RI_RES_WR_IQANDST) & M_FW_RI_RES_WR_IQANDST)
+#define F_FW_RI_RES_WR_IQANDST V_FW_RI_RES_WR_IQANDST(1U)
+
+#define S_FW_RI_RES_WR_IQANUS          14
+#define M_FW_RI_RES_WR_IQANUS          0x1
+#define V_FW_RI_RES_WR_IQANUS(x)       ((x) << S_FW_RI_RES_WR_IQANUS)
+#define G_FW_RI_RES_WR_IQANUS(x)       \
+    (((x) >> S_FW_RI_RES_WR_IQANUS) & M_FW_RI_RES_WR_IQANUS)
+#define F_FW_RI_RES_WR_IQANUS  V_FW_RI_RES_WR_IQANUS(1U)
+
+#define S_FW_RI_RES_WR_IQANUD          12
+#define M_FW_RI_RES_WR_IQANUD          0x3
+#define V_FW_RI_RES_WR_IQANUD(x)       ((x) << S_FW_RI_RES_WR_IQANUD)
+#define G_FW_RI_RES_WR_IQANUD(x)       \
+    (((x) >> S_FW_RI_RES_WR_IQANUD) & M_FW_RI_RES_WR_IQANUD)
+
+#define S_FW_RI_RES_WR_IQANDSTINDEX    0
+#define M_FW_RI_RES_WR_IQANDSTINDEX    0xfff
+#define V_FW_RI_RES_WR_IQANDSTINDEX(x) ((x) << S_FW_RI_RES_WR_IQANDSTINDEX)
+#define G_FW_RI_RES_WR_IQANDSTINDEX(x) \
+    (((x) >> S_FW_RI_RES_WR_IQANDSTINDEX) & M_FW_RI_RES_WR_IQANDSTINDEX)
+
+#define S_FW_RI_RES_WR_IQDROPRSS       15
+#define M_FW_RI_RES_WR_IQDROPRSS       0x1
+#define V_FW_RI_RES_WR_IQDROPRSS(x)    ((x) << S_FW_RI_RES_WR_IQDROPRSS)
+#define G_FW_RI_RES_WR_IQDROPRSS(x)    \
+    (((x) >> S_FW_RI_RES_WR_IQDROPRSS) & M_FW_RI_RES_WR_IQDROPRSS)
+#define F_FW_RI_RES_WR_IQDROPRSS       V_FW_RI_RES_WR_IQDROPRSS(1U)
+
+#define S_FW_RI_RES_WR_IQGTSMODE       14
+#define M_FW_RI_RES_WR_IQGTSMODE       0x1
+#define V_FW_RI_RES_WR_IQGTSMODE(x)    ((x) << S_FW_RI_RES_WR_IQGTSMODE)
+#define G_FW_RI_RES_WR_IQGTSMODE(x)    \
+    (((x) >> S_FW_RI_RES_WR_IQGTSMODE) & M_FW_RI_RES_WR_IQGTSMODE)
+#define F_FW_RI_RES_WR_IQGTSMODE       V_FW_RI_RES_WR_IQGTSMODE(1U)
+
+#define S_FW_RI_RES_WR_IQPCIECH                12
+#define M_FW_RI_RES_WR_IQPCIECH                0x3
+#define V_FW_RI_RES_WR_IQPCIECH(x)     ((x) << S_FW_RI_RES_WR_IQPCIECH)
+#define G_FW_RI_RES_WR_IQPCIECH(x)     \
+    (((x) >> S_FW_RI_RES_WR_IQPCIECH) & M_FW_RI_RES_WR_IQPCIECH)
+
+#define S_FW_RI_RES_WR_IQDCAEN         11
+#define M_FW_RI_RES_WR_IQDCAEN         0x1
+#define V_FW_RI_RES_WR_IQDCAEN(x)      ((x) << S_FW_RI_RES_WR_IQDCAEN)
+#define G_FW_RI_RES_WR_IQDCAEN(x)      \
+    (((x) >> S_FW_RI_RES_WR_IQDCAEN) & M_FW_RI_RES_WR_IQDCAEN)
+#define F_FW_RI_RES_WR_IQDCAEN V_FW_RI_RES_WR_IQDCAEN(1U)
+
+#define S_FW_RI_RES_WR_IQDCACPU                6
+#define M_FW_RI_RES_WR_IQDCACPU                0x1f
+#define V_FW_RI_RES_WR_IQDCACPU(x)     ((x) << S_FW_RI_RES_WR_IQDCACPU)
+#define G_FW_RI_RES_WR_IQDCACPU(x)     \
+    (((x) >> S_FW_RI_RES_WR_IQDCACPU) & M_FW_RI_RES_WR_IQDCACPU)
+
+#define S_FW_RI_RES_WR_IQINTCNTTHRESH          4
+#define M_FW_RI_RES_WR_IQINTCNTTHRESH          0x3
+#define V_FW_RI_RES_WR_IQINTCNTTHRESH(x)       \
+    ((x) << S_FW_RI_RES_WR_IQINTCNTTHRESH)
+#define G_FW_RI_RES_WR_IQINTCNTTHRESH(x)       \
+    (((x) >> S_FW_RI_RES_WR_IQINTCNTTHRESH) & M_FW_RI_RES_WR_IQINTCNTTHRESH)
+
+#define S_FW_RI_RES_WR_IQO     3
+#define M_FW_RI_RES_WR_IQO     0x1
+#define V_FW_RI_RES_WR_IQO(x)  ((x) << S_FW_RI_RES_WR_IQO)
+#define G_FW_RI_RES_WR_IQO(x)  \
+    (((x) >> S_FW_RI_RES_WR_IQO) & M_FW_RI_RES_WR_IQO)
+#define F_FW_RI_RES_WR_IQO     V_FW_RI_RES_WR_IQO(1U)
+
+#define S_FW_RI_RES_WR_IQCPRIO         2
+#define M_FW_RI_RES_WR_IQCPRIO         0x1
+#define V_FW_RI_RES_WR_IQCPRIO(x)      ((x) << S_FW_RI_RES_WR_IQCPRIO)
+#define G_FW_RI_RES_WR_IQCPRIO(x)      \
+    (((x) >> S_FW_RI_RES_WR_IQCPRIO) & M_FW_RI_RES_WR_IQCPRIO)
+#define F_FW_RI_RES_WR_IQCPRIO V_FW_RI_RES_WR_IQCPRIO(1U)
+
+#define S_FW_RI_RES_WR_IQESIZE         0
+#define M_FW_RI_RES_WR_IQESIZE         0x3
+#define V_FW_RI_RES_WR_IQESIZE(x)      ((x) << S_FW_RI_RES_WR_IQESIZE)
+#define G_FW_RI_RES_WR_IQESIZE(x)      \
+    (((x) >> S_FW_RI_RES_WR_IQESIZE) & M_FW_RI_RES_WR_IQESIZE)
+
+#define S_FW_RI_RES_WR_IQNS    31
+#define M_FW_RI_RES_WR_IQNS    0x1
+#define V_FW_RI_RES_WR_IQNS(x) ((x) << S_FW_RI_RES_WR_IQNS)
+#define G_FW_RI_RES_WR_IQNS(x) \
+    (((x) >> S_FW_RI_RES_WR_IQNS) & M_FW_RI_RES_WR_IQNS)
+#define F_FW_RI_RES_WR_IQNS    V_FW_RI_RES_WR_IQNS(1U)
+
+#define S_FW_RI_RES_WR_IQRO    30
+#define M_FW_RI_RES_WR_IQRO    0x1
+#define V_FW_RI_RES_WR_IQRO(x) ((x) << S_FW_RI_RES_WR_IQRO)
+#define G_FW_RI_RES_WR_IQRO(x) \
+    (((x) >> S_FW_RI_RES_WR_IQRO) & M_FW_RI_RES_WR_IQRO)
+#define F_FW_RI_RES_WR_IQRO    V_FW_RI_RES_WR_IQRO(1U)
+
+struct fw_ri_rdma_write_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __be64 r2;
+       __be32 plen;
+       __be32 stag_sink;
+       __be64 to_sink;
+#ifndef C99_NOT_SUPPORTED
+       union {
+               struct fw_ri_immd immd_src[0];
+               struct fw_ri_isgl isgl_src[0];
+       } u;
+#endif
+};
+
+struct fw_ri_send_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __be32 sendop_pkd;
+       __be32 stag_inv;
+       __be32 plen;
+       __be32 r3;
+       __be64 r4;
+#ifndef C99_NOT_SUPPORTED
+       union {
+               struct fw_ri_immd immd_src[0];
+               struct fw_ri_isgl isgl_src[0];
+       } u;
+#endif
+};
+
+#define S_FW_RI_SEND_WR_SENDOP         0
+#define M_FW_RI_SEND_WR_SENDOP         0xf
+#define V_FW_RI_SEND_WR_SENDOP(x)      ((x) << S_FW_RI_SEND_WR_SENDOP)
+#define G_FW_RI_SEND_WR_SENDOP(x)      \
+    (((x) >> S_FW_RI_SEND_WR_SENDOP) & M_FW_RI_SEND_WR_SENDOP)
+
+struct fw_ri_rdma_read_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __be64 r2;
+       __be32 stag_sink;
+       __be32 to_sink_hi;
+       __be32 to_sink_lo;
+       __be32 plen;
+       __be32 stag_src;
+       __be32 to_src_hi;
+       __be32 to_src_lo;
+       __be32 r5;
+};
+
+struct fw_ri_recv_wr {
+       __u8   opcode;
+       __u8   r1;
+       __u16  wrid;
+       __u8   r2[3];
+       __u8   len16;
+       struct fw_ri_isgl isgl;
+};
+
+struct fw_ri_bind_mw_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __u8   qpbinde_to_dcacpu;
+       __u8   pgsz_shift;
+       __u8   addr_type;
+       __u8   mem_perms;
+       __be32 stag_mr;
+       __be32 stag_mw;
+       __be32 r3;
+       __be64 len_mw;
+       __be64 va_fbo;
+       __be64 r4;
+};
+
+#define S_FW_RI_BIND_MW_WR_QPBINDE     6
+#define M_FW_RI_BIND_MW_WR_QPBINDE     0x1
+#define V_FW_RI_BIND_MW_WR_QPBINDE(x)  ((x) << S_FW_RI_BIND_MW_WR_QPBINDE)
+#define G_FW_RI_BIND_MW_WR_QPBINDE(x)  \
+    (((x) >> S_FW_RI_BIND_MW_WR_QPBINDE) & M_FW_RI_BIND_MW_WR_QPBINDE)
+#define F_FW_RI_BIND_MW_WR_QPBINDE     V_FW_RI_BIND_MW_WR_QPBINDE(1U)
+
+#define S_FW_RI_BIND_MW_WR_NS          5
+#define M_FW_RI_BIND_MW_WR_NS          0x1
+#define V_FW_RI_BIND_MW_WR_NS(x)       ((x) << S_FW_RI_BIND_MW_WR_NS)
+#define G_FW_RI_BIND_MW_WR_NS(x)       \
+    (((x) >> S_FW_RI_BIND_MW_WR_NS) & M_FW_RI_BIND_MW_WR_NS)
+#define F_FW_RI_BIND_MW_WR_NS  V_FW_RI_BIND_MW_WR_NS(1U)
+
+#define S_FW_RI_BIND_MW_WR_DCACPU      0
+#define M_FW_RI_BIND_MW_WR_DCACPU      0x1f
+#define V_FW_RI_BIND_MW_WR_DCACPU(x)   ((x) << S_FW_RI_BIND_MW_WR_DCACPU)
+#define G_FW_RI_BIND_MW_WR_DCACPU(x)   \
+    (((x) >> S_FW_RI_BIND_MW_WR_DCACPU) & M_FW_RI_BIND_MW_WR_DCACPU)
+
+struct fw_ri_fr_nsmr_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __u8   qpbinde_to_dcacpu;
+       __u8   pgsz_shift;
+       __u8   addr_type;
+       __u8   mem_perms;
+       __be32 stag;
+       __be32 len_hi;
+       __be32 len_lo;
+       __be32 va_hi;
+       __be32 va_lo_fbo;
+};
+
+#define S_FW_RI_FR_NSMR_WR_QPBINDE     6
+#define M_FW_RI_FR_NSMR_WR_QPBINDE     0x1
+#define V_FW_RI_FR_NSMR_WR_QPBINDE(x)  ((x) << S_FW_RI_FR_NSMR_WR_QPBINDE)
+#define G_FW_RI_FR_NSMR_WR_QPBINDE(x)  \
+    (((x) >> S_FW_RI_FR_NSMR_WR_QPBINDE) & M_FW_RI_FR_NSMR_WR_QPBINDE)
+#define F_FW_RI_FR_NSMR_WR_QPBINDE     V_FW_RI_FR_NSMR_WR_QPBINDE(1U)
+
+#define S_FW_RI_FR_NSMR_WR_NS          5
+#define M_FW_RI_FR_NSMR_WR_NS          0x1
+#define V_FW_RI_FR_NSMR_WR_NS(x)       ((x) << S_FW_RI_FR_NSMR_WR_NS)
+#define G_FW_RI_FR_NSMR_WR_NS(x)       \
+    (((x) >> S_FW_RI_FR_NSMR_WR_NS) & M_FW_RI_FR_NSMR_WR_NS)
+#define F_FW_RI_FR_NSMR_WR_NS  V_FW_RI_FR_NSMR_WR_NS(1U)
+
+#define S_FW_RI_FR_NSMR_WR_DCACPU      0
+#define M_FW_RI_FR_NSMR_WR_DCACPU      0x1f
+#define V_FW_RI_FR_NSMR_WR_DCACPU(x)   ((x) << S_FW_RI_FR_NSMR_WR_DCACPU)
+#define G_FW_RI_FR_NSMR_WR_DCACPU(x)   \
+    (((x) >> S_FW_RI_FR_NSMR_WR_DCACPU) & M_FW_RI_FR_NSMR_WR_DCACPU)
+
+struct fw_ri_inv_lstag_wr {
+       __u8   opcode;
+       __u8   flags;
+       __u16  wrid;
+       __u8   r1[3];
+       __u8   len16;
+       __be32 r2;
+       __be32 stag_inv;
+};
+
+enum fw_ri_type {
+       FW_RI_TYPE_INIT,
+       FW_RI_TYPE_FINI,
+       FW_RI_TYPE_TERMINATE
+};
+
+enum fw_ri_init_p2ptype {
+       FW_RI_INIT_P2PTYPE_RDMA_WRITE           = FW_RI_RDMA_WRITE,
+       FW_RI_INIT_P2PTYPE_READ_REQ             = FW_RI_READ_REQ,
+       FW_RI_INIT_P2PTYPE_SEND                 = FW_RI_SEND,
+       FW_RI_INIT_P2PTYPE_SEND_WITH_INV        = FW_RI_SEND_WITH_INV,
+       FW_RI_INIT_P2PTYPE_SEND_WITH_SE         = FW_RI_SEND_WITH_SE,
+       FW_RI_INIT_P2PTYPE_SEND_WITH_SE_INV     = FW_RI_SEND_WITH_SE_INV,
+       FW_RI_INIT_P2PTYPE_DISABLED             = 0xf,
+};
+
+struct fw_ri_wr {
+       __be32 op_compl;
+       __be32 flowid_len16;
+       __u64  cookie;
+       union fw_ri {
+               struct fw_ri_init {
+                       __u8   type;
+                       __u8   mpareqbit_p2ptype;
+                       __u8   r4[2];
+                       __u8   mpa_attrs;
+                       __u8   qp_caps;
+                       __be16 nrqe;
+                       __be32 pdid;
+                       __be32 qpid;
+                       __be32 sq_eqid;
+                       __be32 rq_eqid;
+                       __be32 scqid;
+                       __be32 rcqid;
+                       __be32 ord_max;
+                       __be32 ird_max;
+                       __be32 iss;
+                       __be32 irs;
+                       __be32 hwrqsize;
+                       __be32 hwrqaddr;
+                       __be64 r5;
+                       union fw_ri_init_p2p {
+                               struct fw_ri_rdma_write_wr write;
+                               struct fw_ri_rdma_read_wr read;
+                               struct fw_ri_send_wr send;
+                       } u;
+               } init;
+               struct fw_ri_fini {
+                       __u8   type;
+                       __u8   r3[7];
+                       __be64 r4;
+               } fini;
+               struct fw_ri_terminate {
+                       __u8   type;
+                       __u8   r3[3];
+                       __be32 immdlen;
+                       __u8   termmsg[40];
+               } terminate;
+       } u;
+};
+
+#define S_FW_RI_WR_MPAREQBIT   7
+#define M_FW_RI_WR_MPAREQBIT   0x1
+#define V_FW_RI_WR_MPAREQBIT(x)        ((x) << S_FW_RI_WR_MPAREQBIT)
+#define G_FW_RI_WR_MPAREQBIT(x)        \
+    (((x) >> S_FW_RI_WR_MPAREQBIT) & M_FW_RI_WR_MPAREQBIT)
+#define F_FW_RI_WR_MPAREQBIT   V_FW_RI_WR_MPAREQBIT(1U)
+
+#define S_FW_RI_WR_P2PTYPE     0
+#define M_FW_RI_WR_P2PTYPE     0xf
+#define V_FW_RI_WR_P2PTYPE(x)  ((x) << S_FW_RI_WR_P2PTYPE)
+#define G_FW_RI_WR_P2PTYPE(x)  \
+    (((x) >> S_FW_RI_WR_P2PTYPE) & M_FW_RI_WR_P2PTYPE)
+
+struct tcp_options {
+       __be16 mss;
+       __u8 wsf;
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       __u8:4;
+       __u8 unknown:1;
+       __u8:1;
+       __u8 sack:1;
+       __u8 tstamp:1;
+#else
+       __u8 tstamp:1;
+       __u8 sack:1;
+       __u8:1;
+       __u8 unknown:1;
+       __u8:4;
+#endif
+};
+
+struct cpl_pass_accept_req {
+       union opcode_tid ot;
+       __be16 rsvd;
+       __be16 len;
+       __be32 hdr_len;
+       __be16 vlan;
+       __be16 l2info;
+       __be32 tos_stid;
+       struct tcp_options tcpopt;
+};
+
+/* cpl_pass_accept_req.hdr_len fields */
+#define S_SYN_RX_CHAN    0
+#define M_SYN_RX_CHAN    0xF
+#define V_SYN_RX_CHAN(x) ((x) << S_SYN_RX_CHAN)
+#define G_SYN_RX_CHAN(x) (((x) >> S_SYN_RX_CHAN) & M_SYN_RX_CHAN)
+
+#define S_TCP_HDR_LEN    10
+#define M_TCP_HDR_LEN    0x3F
+#define V_TCP_HDR_LEN(x) ((x) << S_TCP_HDR_LEN)
+#define G_TCP_HDR_LEN(x) (((x) >> S_TCP_HDR_LEN) & M_TCP_HDR_LEN)
+
+#define S_IP_HDR_LEN    16
+#define M_IP_HDR_LEN    0x3FF
+#define V_IP_HDR_LEN(x) ((x) << S_IP_HDR_LEN)
+#define G_IP_HDR_LEN(x) (((x) >> S_IP_HDR_LEN) & M_IP_HDR_LEN)
+
+#define S_ETH_HDR_LEN    26
+#define M_ETH_HDR_LEN    0x1F
+#define V_ETH_HDR_LEN(x) ((x) << S_ETH_HDR_LEN)
+#define G_ETH_HDR_LEN(x) (((x) >> S_ETH_HDR_LEN) & M_ETH_HDR_LEN)
+
+/* cpl_pass_accept_req.l2info fields */
+#define S_SYN_MAC_IDX    0
+#define M_SYN_MAC_IDX    0x1FF
+#define V_SYN_MAC_IDX(x) ((x) << S_SYN_MAC_IDX)
+#define G_SYN_MAC_IDX(x) (((x) >> S_SYN_MAC_IDX) & M_SYN_MAC_IDX)
+
+#define S_SYN_XACT_MATCH    9
+#define V_SYN_XACT_MATCH(x) ((x) << S_SYN_XACT_MATCH)
+#define F_SYN_XACT_MATCH    V_SYN_XACT_MATCH(1U)
+
+#define S_SYN_INTF    12
+#define M_SYN_INTF    0xF
+#define V_SYN_INTF(x) ((x) << S_SYN_INTF)
+#define G_SYN_INTF(x) (((x) >> S_SYN_INTF) & M_SYN_INTF)
+
+struct ulptx_idata {
+       __be32 cmd_more;
+       __be32 len;
+};
+
+#define S_ULPTX_NSGE    0
+#define M_ULPTX_NSGE    0xFFFF
+#define V_ULPTX_NSGE(x) ((x) << S_ULPTX_NSGE)
+#endif /* _T4FW_RI_API_H_ */
diff --git a/drivers/infiniband/hw/cxgb4/user.h b/drivers/infiniband/hw/cxgb4/user.h
new file mode 100644 (file)
index 0000000..ed6414a
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * 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.
+ */
+#ifndef __C4IW_USER_H__
+#define __C4IW_USER_H__
+
+#define C4IW_UVERBS_ABI_VERSION        1
+
+/*
+ * Make sure that all structs defined in this file remain laid out so
+ * that they pack the same way on 32-bit and 64-bit architectures (to
+ * avoid incompatibility between 32-bit userspace and 64-bit kernels).
+ * In particular do not use pointer types -- pass pointers in __u64
+ * instead.
+ */
+struct c4iw_create_cq_resp {
+       __u64 key;
+       __u64 gts_key;
+       __u64 memsize;
+       __u32 cqid;
+       __u32 size;
+       __u32 qid_mask;
+};
+
+struct c4iw_create_qp_resp {
+       __u64 sq_key;
+       __u64 rq_key;
+       __u64 sq_db_gts_key;
+       __u64 rq_db_gts_key;
+       __u64 sq_memsize;
+       __u64 rq_memsize;
+       __u32 sqid;
+       __u32 rqid;
+       __u32 sq_size;
+       __u32 rq_size;
+       __u32 qid_mask;
+};
+#endif
index 37d12e5..1d7aea1 100644 (file)
@@ -1474,7 +1474,7 @@ static void ipath_ht_quiet_serdes(struct ipath_devdata *dd)
 /**
  * ipath_pe_put_tid - write a TID in chip
  * @dd: the infinipath device
- * @tidptr: pointer to the expected TID (in chip) to udpate
+ * @tidptr: pointer to the expected TID (in chip) to update
  * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  *
index fbf8c53..4b4a30b 100644 (file)
@@ -1328,7 +1328,7 @@ bail:
 /**
  * ipath_pe_put_tid - write a TID in chip
  * @dd: the infinipath device
- * @tidptr: pointer to the expected TID (in chip) to udpate
+ * @tidptr: pointer to the expected TID (in chip) to update
  * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  *
@@ -1394,7 +1394,7 @@ static void ipath_pe_put_tid(struct ipath_devdata *dd, u64 __iomem *tidptr,
 /**
  * ipath_pe_put_tid_2 - write a TID in chip, Revision 2 or higher
  * @dd: the infinipath device
- * @tidptr: pointer to the expected TID (in chip) to udpate
+ * @tidptr: pointer to the expected TID (in chip) to update
  * @tidtype: RCVHQ_RCV_TYPE_EAGER (1) for eager, RCVHQ_RCV_TYPE_EXPECTED (0) for expected
  * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  *
index a805402..34b778e 100644 (file)
@@ -1738,7 +1738,7 @@ bail:
 /**
  * ipath_7220_put_tid - write a TID to the chip
  * @dd: the infinipath device
- * @tidptr: pointer to the expected TID (in chip) to udpate
+ * @tidptr: pointer to the expected TID (in chip) to update
  * @tidtype: 0 for eager, 1 for expected
  * @pa: physical address of in memory buffer; ipath_tidinvalid if freeing
  *
index cc2ddd2..5a219a2 100644 (file)
@@ -661,6 +661,14 @@ repoll:
                        wc->opcode    = IB_WC_FETCH_ADD;
                        wc->byte_len  = 8;
                        break;
+               case MLX4_OPCODE_MASKED_ATOMIC_CS:
+                       wc->opcode    = IB_WC_MASKED_COMP_SWAP;
+                       wc->byte_len  = 8;
+                       break;
+               case MLX4_OPCODE_MASKED_ATOMIC_FA:
+                       wc->opcode    = IB_WC_MASKED_FETCH_ADD;
+                       wc->byte_len  = 8;
+                       break;
                case MLX4_OPCODE_BIND_MW:
                        wc->opcode    = IB_WC_BIND_MW;
                        break;
index 01f2a3f..3905141 100644 (file)
@@ -139,6 +139,7 @@ static int mlx4_ib_query_device(struct ib_device *ibdev,
        props->local_ca_ack_delay  = dev->dev->caps.local_ca_ack_delay;
        props->atomic_cap          = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ?
                IB_ATOMIC_HCA : IB_ATOMIC_NONE;
+       props->masked_atomic_cap   = IB_ATOMIC_HCA;
        props->max_pkeys           = dev->dev->caps.pkey_table_len[1];
        props->max_mcast_grp       = dev->dev->caps.num_mgms + dev->dev->caps.num_amgms;
        props->max_mcast_qp_attach = dev->dev->caps.num_qp_per_mgm;
index 5643f4a..6a60827 100644 (file)
@@ -74,17 +74,19 @@ enum {
 };
 
 static const __be32 mlx4_ib_opcode[] = {
-       [IB_WR_SEND]                    = cpu_to_be32(MLX4_OPCODE_SEND),
-       [IB_WR_LSO]                     = cpu_to_be32(MLX4_OPCODE_LSO),
-       [IB_WR_SEND_WITH_IMM]           = cpu_to_be32(MLX4_OPCODE_SEND_IMM),
-       [IB_WR_RDMA_WRITE]              = cpu_to_be32(MLX4_OPCODE_RDMA_WRITE),
-       [IB_WR_RDMA_WRITE_WITH_IMM]     = cpu_to_be32(MLX4_OPCODE_RDMA_WRITE_IMM),
-       [IB_WR_RDMA_READ]               = cpu_to_be32(MLX4_OPCODE_RDMA_READ),
-       [IB_WR_ATOMIC_CMP_AND_SWP]      = cpu_to_be32(MLX4_OPCODE_ATOMIC_CS),
-       [IB_WR_ATOMIC_FETCH_AND_ADD]    = cpu_to_be32(MLX4_OPCODE_ATOMIC_FA),
-       [IB_WR_SEND_WITH_INV]           = cpu_to_be32(MLX4_OPCODE_SEND_INVAL),
-       [IB_WR_LOCAL_INV]               = cpu_to_be32(MLX4_OPCODE_LOCAL_INVAL),
-       [IB_WR_FAST_REG_MR]             = cpu_to_be32(MLX4_OPCODE_FMR),
+       [IB_WR_SEND]                            = cpu_to_be32(MLX4_OPCODE_SEND),
+       [IB_WR_LSO]                             = cpu_to_be32(MLX4_OPCODE_LSO),
+       [IB_WR_SEND_WITH_IMM]                   = cpu_to_be32(MLX4_OPCODE_SEND_IMM),
+       [IB_WR_RDMA_WRITE]                      = cpu_to_be32(MLX4_OPCODE_RDMA_WRITE),
+       [IB_WR_RDMA_WRITE_WITH_IMM]             = cpu_to_be32(MLX4_OPCODE_RDMA_WRITE_IMM),
+       [IB_WR_RDMA_READ]                       = cpu_to_be32(MLX4_OPCODE_RDMA_READ),
+       [IB_WR_ATOMIC_CMP_AND_SWP]              = cpu_to_be32(MLX4_OPCODE_ATOMIC_CS),
+       [IB_WR_ATOMIC_FETCH_AND_ADD]            = cpu_to_be32(MLX4_OPCODE_ATOMIC_FA),
+       [IB_WR_SEND_WITH_INV]                   = cpu_to_be32(MLX4_OPCODE_SEND_INVAL),
+       [IB_WR_LOCAL_INV]                       = cpu_to_be32(MLX4_OPCODE_LOCAL_INVAL),
+       [IB_WR_FAST_REG_MR]                     = cpu_to_be32(MLX4_OPCODE_FMR),
+       [IB_WR_MASKED_ATOMIC_CMP_AND_SWP]       = cpu_to_be32(MLX4_OPCODE_MASKED_ATOMIC_CS),
+       [IB_WR_MASKED_ATOMIC_FETCH_AND_ADD]     = cpu_to_be32(MLX4_OPCODE_MASKED_ATOMIC_FA),
 };
 
 static struct mlx4_ib_sqp *to_msqp(struct mlx4_ib_qp *mqp)
@@ -1407,6 +1409,9 @@ static void set_atomic_seg(struct mlx4_wqe_atomic_seg *aseg, struct ib_send_wr *
        if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
                aseg->swap_add = cpu_to_be64(wr->wr.atomic.swap);
                aseg->compare  = cpu_to_be64(wr->wr.atomic.compare_add);
+       } else if (wr->opcode == IB_WR_MASKED_ATOMIC_FETCH_AND_ADD) {
+               aseg->swap_add = cpu_to_be64(wr->wr.atomic.compare_add);
+               aseg->compare  = cpu_to_be64(wr->wr.atomic.compare_add_mask);
        } else {
                aseg->swap_add = cpu_to_be64(wr->wr.atomic.compare_add);
                aseg->compare  = 0;
@@ -1414,6 +1419,15 @@ static void set_atomic_seg(struct mlx4_wqe_atomic_seg *aseg, struct ib_send_wr *
 
 }
 
+static void set_masked_atomic_seg(struct mlx4_wqe_masked_atomic_seg *aseg,
+                                 struct ib_send_wr *wr)
+{
+       aseg->swap_add          = cpu_to_be64(wr->wr.atomic.swap);
+       aseg->swap_add_mask     = cpu_to_be64(wr->wr.atomic.swap_mask);
+       aseg->compare           = cpu_to_be64(wr->wr.atomic.compare_add);
+       aseg->compare_mask      = cpu_to_be64(wr->wr.atomic.compare_add_mask);
+}
+
 static void set_datagram_seg(struct mlx4_wqe_datagram_seg *dseg,
                             struct ib_send_wr *wr)
 {
@@ -1567,6 +1581,7 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
                        switch (wr->opcode) {
                        case IB_WR_ATOMIC_CMP_AND_SWP:
                        case IB_WR_ATOMIC_FETCH_AND_ADD:
+                       case IB_WR_MASKED_ATOMIC_FETCH_AND_ADD:
                                set_raddr_seg(wqe, wr->wr.atomic.remote_addr,
                                              wr->wr.atomic.rkey);
                                wqe  += sizeof (struct mlx4_wqe_raddr_seg);
@@ -1579,6 +1594,19 @@ int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
 
                                break;
 
+                       case IB_WR_MASKED_ATOMIC_CMP_AND_SWP:
+                               set_raddr_seg(wqe, wr->wr.atomic.remote_addr,
+                                             wr->wr.atomic.rkey);
+                               wqe  += sizeof (struct mlx4_wqe_raddr_seg);
+
+                               set_masked_atomic_seg(wqe, wr);
+                               wqe  += sizeof (struct mlx4_wqe_masked_atomic_seg);
+
+                               size += (sizeof (struct mlx4_wqe_raddr_seg) +
+                                        sizeof (struct mlx4_wqe_masked_atomic_seg)) / 16;
+
+                               break;
+
                        case IB_WR_RDMA_READ:
                        case IB_WR_RDMA_WRITE:
                        case IB_WR_RDMA_WRITE_WITH_IMM:
index c5ccc2d..b4e0cf4 100644 (file)
@@ -211,7 +211,7 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
                if (!buf->direct.buf)
                        return -ENOMEM;
 
-               pci_unmap_addr_set(&buf->direct, mapping, t);
+               dma_unmap_addr_set(&buf->direct, mapping, t);
 
                memset(buf->direct.buf, 0, size);
 
@@ -251,7 +251,7 @@ int mthca_buf_alloc(struct mthca_dev *dev, int size, int max_direct,
                                goto err_free;
 
                        dma_list[i] = t;
-                       pci_unmap_addr_set(&buf->page_list[i], mapping, t);
+                       dma_unmap_addr_set(&buf->page_list[i], mapping, t);
 
                        clear_page(buf->page_list[i].buf);
                }
@@ -289,12 +289,12 @@ void mthca_buf_free(struct mthca_dev *dev, int size, union mthca_buf *buf,
 
        if (is_direct)
                dma_free_coherent(&dev->pdev->dev, size, buf->direct.buf,
-                                 pci_unmap_addr(&buf->direct, mapping));
+                                 dma_unmap_addr(&buf->direct, mapping));
        else {
                for (i = 0; i < (size + PAGE_SIZE - 1) / PAGE_SIZE; ++i)
                        dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
                                          buf->page_list[i].buf,
-                                         pci_unmap_addr(&buf->page_list[i],
+                                         dma_unmap_addr(&buf->page_list[i],
                                                         mapping));
                kfree(buf->page_list);
        }
index 9388164..8e8c728 100644 (file)
@@ -504,7 +504,7 @@ static int mthca_create_eq(struct mthca_dev *dev,
                        goto err_out_free_pages;
 
                dma_list[i] = t;
-               pci_unmap_addr_set(&eq->page_list[i], mapping, t);
+               dma_unmap_addr_set(&eq->page_list[i], mapping, t);
 
                clear_page(eq->page_list[i].buf);
        }
@@ -579,7 +579,7 @@ static int mthca_create_eq(struct mthca_dev *dev,
                if (eq->page_list[i].buf)
                        dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
                                          eq->page_list[i].buf,
-                                         pci_unmap_addr(&eq->page_list[i],
+                                         dma_unmap_addr(&eq->page_list[i],
                                                         mapping));
 
        mthca_free_mailbox(dev, mailbox);
@@ -629,7 +629,7 @@ static void mthca_free_eq(struct mthca_dev *dev,
        for (i = 0; i < npages; ++i)
                pci_free_consistent(dev->pdev, PAGE_SIZE,
                                    eq->page_list[i].buf,
-                                   pci_unmap_addr(&eq->page_list[i], mapping));
+                                   dma_unmap_addr(&eq->page_list[i], mapping));
 
        kfree(eq->page_list);
        mthca_free_mailbox(dev, mailbox);
index 90f4c4d..596acc4 100644 (file)
@@ -46,7 +46,7 @@
 
 struct mthca_buf_list {
        void *buf;
-       DECLARE_PCI_UNMAP_ADDR(mapping)
+       DEFINE_DMA_UNMAP_ADDR(mapping);
 };
 
 union mthca_buf {
index c36a3f5..86acb7d 100644 (file)
@@ -1297,7 +1297,7 @@ int nes_destroy_cqp(struct nes_device *nesdev)
 /**
  * nes_init_1g_phy
  */
-int nes_init_1g_phy(struct nes_device *nesdev, u8 phy_type, u8 phy_index)
+static int nes_init_1g_phy(struct nes_device *nesdev, u8 phy_type, u8 phy_index)
 {
        u32 counter = 0;
        u16 phy_data;
@@ -1351,7 +1351,7 @@ int nes_init_1g_phy(struct nes_device *nesdev, u8 phy_type, u8 phy_index)
 /**
  * nes_init_2025_phy
  */
-int nes_init_2025_phy(struct nes_device *nesdev, u8 phy_type, u8 phy_index)
+static int nes_init_2025_phy(struct nes_device *nesdev, u8 phy_type, u8 phy_index)
 {
        u32 temp_phy_data = 0;
        u32 temp_phy_data2 = 0;
@@ -2458,7 +2458,6 @@ static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
                return;
        }
        nesadapter->mac_sw_state[mac_number] = NES_MAC_SW_INTERRUPT;
-       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
 
        /* ack the MAC interrupt */
        mac_status = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (mac_index * 0x200));
@@ -2469,11 +2468,9 @@ static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
 
        if (mac_status & (NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT)) {
                nesdev->link_status_interrupts++;
-               if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS))) {
-                       spin_lock_irqsave(&nesadapter->phy_lock, flags);
+               if (0 == (++nesadapter->link_interrupt_count[mac_index] % ((u16)NES_MAX_LINK_INTERRUPTS)))
                        nes_reset_link(nesdev, mac_index);
-                       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
-               }
+
                /* read the PHY interrupt status register */
                if ((nesadapter->OneG_Mode) &&
                (nesadapter->phy_type[mac_index] != NES_PHY_TYPE_PUMA_1G)) {
@@ -2587,6 +2584,7 @@ static void nes_process_mac_intr(struct nes_device *nesdev, u32 mac_number)
                                break;
                        }
                }
+               spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
 
                if (phy_data & 0x0004) {
                        if (wide_ppm_offset &&
index b7c813f..9f4cadf 100644 (file)
@@ -1461,11 +1461,14 @@ static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd
                        et_cmd->transceiver = XCVR_INTERNAL;
                        et_cmd->phy_address = mac_index;
                } else {
+                       unsigned long flags;
                        et_cmd->supported   = SUPPORTED_1000baseT_Full
                                            | SUPPORTED_Autoneg;
                        et_cmd->advertising = ADVERTISED_1000baseT_Full
                                            | ADVERTISED_Autoneg;
+                       spin_lock_irqsave(&nesadapter->phy_lock, flags);
                        nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
+                       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
                        if (phy_data & 0x1000)
                                et_cmd->autoneg = AUTONEG_ENABLE;
                        else
@@ -1503,12 +1506,15 @@ static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd
        struct nes_vnic *nesvnic = netdev_priv(netdev);
        struct nes_device *nesdev = nesvnic->nesdev;
        struct nes_adapter *nesadapter = nesdev->nesadapter;
-       u16 phy_data;
 
        if ((nesadapter->OneG_Mode) &&
            (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
-               nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
-                               &phy_data);
+               unsigned long flags;
+               u16 phy_data;
+               u8 phy_index = nesadapter->phy_index[nesdev->mac_index];
+
+               spin_lock_irqsave(&nesadapter->phy_lock, flags);
+               nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
                if (et_cmd->autoneg) {
                        /* Turn on Full duplex, Autoneg, and restart autonegotiation */
                        phy_data |= 0x1300;
@@ -1516,8 +1522,8 @@ static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd
                        /* Turn off autoneg */
                        phy_data &= ~0x1000;
                }
-               nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
-                               phy_data);
+               nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data);
+               spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
        }
 
        return 0;
index 186623d..a9f5dd2 100644 (file)
@@ -381,12 +381,8 @@ static u16 nes_read16_eeprom(void __iomem *addr, u16 offset)
  */
 void nes_write_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u16 data)
 {
-       struct nes_adapter *nesadapter = nesdev->nesadapter;
        u32 u32temp;
        u32 counter;
-       unsigned long flags;
-
-       spin_lock_irqsave(&nesadapter->phy_lock, flags);
 
        nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
                        0x50020000 | data | ((u32)phy_reg << 18) | ((u32)phy_addr << 23));
@@ -402,8 +398,6 @@ void nes_write_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u1
        if (!(u32temp & 1))
                nes_debug(NES_DBG_PHY, "Phy is not responding. interrupt status = 0x%X.\n",
                                u32temp);
-
-       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
 }
 
 
@@ -414,14 +408,11 @@ void nes_write_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u1
  */
 void nes_read_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u16 *data)
 {
-       struct nes_adapter *nesadapter = nesdev->nesadapter;
        u32 u32temp;
        u32 counter;
-       unsigned long flags;
 
        /* nes_debug(NES_DBG_PHY, "phy addr = %d, mac_index = %d\n",
                        phy_addr, nesdev->mac_index); */
-       spin_lock_irqsave(&nesadapter->phy_lock, flags);
 
        nes_write_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL,
                        0x60020000 | ((u32)phy_reg << 18) | ((u32)phy_addr << 23));
@@ -441,7 +432,6 @@ void nes_read_1G_phy_reg(struct nes_device *nesdev, u8 phy_reg, u8 phy_addr, u16
        } else {
                *data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
        }
-       spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
 }
 
 
index e54f312..925e1f2 100644 (file)
@@ -374,7 +374,7 @@ static int alloc_fast_reg_mr(struct nes_device *nesdev, struct nes_pd *nespd,
 /*
  * nes_alloc_fast_reg_mr
  */
-struct ib_mr *nes_alloc_fast_reg_mr(struct ib_pd *ibpd, int max_page_list_len)
+static struct ib_mr *nes_alloc_fast_reg_mr(struct ib_pd *ibpd, int max_page_list_len)
 {
        struct nes_pd *nespd = to_nespd(ibpd);
        struct nes_vnic *nesvnic = to_nesvnic(ibpd->device);
index d10b4ec..40e8584 100644 (file)
@@ -49,6 +49,25 @@ static u32 ipoib_get_rx_csum(struct net_device *dev)
                !test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags);
 }
 
+static int ipoib_set_tso(struct net_device *dev, u32 data)
+{
+       struct ipoib_dev_priv *priv = netdev_priv(dev);
+
+       if (data) {
+               if (!test_bit(IPOIB_FLAG_ADMIN_CM, &priv->flags) &&
+                   (dev->features & NETIF_F_SG) &&
+                   (priv->hca_caps & IB_DEVICE_UD_TSO)) {
+                       dev->features |= NETIF_F_TSO;
+               } else {
+                       ipoib_warn(priv, "can't set TSO on\n");
+                       return -EOPNOTSUPP;
+               }
+       } else
+               dev->features &= ~NETIF_F_TSO;
+
+       return 0;
+}
+
 static int ipoib_get_coalesce(struct net_device *dev,
                              struct ethtool_coalesce *coal)
 {
@@ -131,6 +150,7 @@ static void ipoib_get_ethtool_stats(struct net_device *dev,
 static const struct ethtool_ops ipoib_ethtool_ops = {
        .get_drvinfo            = ipoib_get_drvinfo,
        .get_rx_csum            = ipoib_get_rx_csum,
+       .set_tso                = ipoib_set_tso,
        .get_coalesce           = ipoib_get_coalesce,
        .set_coalesce           = ipoib_set_coalesce,
        .get_flags              = ethtool_op_get_flags,
index 93399df..7b2fc98 100644 (file)
@@ -325,7 +325,7 @@ iscsi_iser_conn_destroy(struct iscsi_cls_conn *cls_conn)
         */
        if (ib_conn) {
                ib_conn->iser_conn = NULL;
-               iser_conn_put(ib_conn);
+               iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
        }
 }
 
@@ -357,11 +357,12 @@ iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,
        /* binds the iSER connection retrieved from the previously
         * connected ep_handle to the iSCSI layer connection. exchanges
         * connection pointers */
-       iser_err("binding iscsi conn %p to iser_conn %p\n",conn,ib_conn);
+       iser_err("binding iscsi/iser conn %p %p to ib_conn %p\n",
+                                       conn, conn->dd_data, ib_conn);
        iser_conn = conn->dd_data;
        ib_conn->iser_conn = iser_conn;
        iser_conn->ib_conn  = ib_conn;
-       iser_conn_get(ib_conn);
+       iser_conn_get(ib_conn); /* ref iscsi/ib conn binding */
        return 0;
 }
 
@@ -382,7 +383,7 @@ iscsi_iser_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
                 * There is no unbind event so the stop callback
                 * must release the ref from the bind.
                 */
-               iser_conn_put(ib_conn);
+               iser_conn_put(ib_conn, 1); /* deref iscsi/ib conn unbinding */
        }
        iser_conn->ib_conn = NULL;
 }
index 036934c..f1df015 100644 (file)
@@ -232,6 +232,7 @@ struct iser_device {
        struct ib_cq                 *tx_cq;
        struct ib_mr                 *mr;
        struct tasklet_struct        cq_tasklet;
+       struct ib_event_handler      event_handler;
        struct list_head             ig_list; /* entry in ig devices list */
        int                          refcount;
 };
@@ -246,7 +247,6 @@ struct iser_conn {
        struct rdma_cm_id            *cma_id;       /* CMA ID                  */
        struct ib_qp                 *qp;           /* QP                      */
        struct ib_fmr_pool           *fmr_pool;     /* pool of IB FMRs         */
-       int                          disc_evt_flag; /* disconn event delivered */
        wait_queue_head_t            wait;          /* waitq for conn/disconn  */
        int                          post_recv_buf_count; /* posted rx count  */
        atomic_t                     post_send_buf_count; /* posted tx count   */
@@ -320,7 +320,7 @@ void iser_conn_init(struct iser_conn *ib_conn);
 
 void iser_conn_get(struct iser_conn *ib_conn);
 
-void iser_conn_put(struct iser_conn *ib_conn);
+int iser_conn_put(struct iser_conn *ib_conn, int destroy_cma_id_allowed);
 
 void iser_conn_terminate(struct iser_conn *ib_conn);
 
index b89d76b..9876865 100644 (file)
@@ -54,6 +54,13 @@ static void iser_qp_event_callback(struct ib_event *cause, void *context)
        iser_err("got qp event %d\n",cause->event);
 }
 
+static void iser_event_handler(struct ib_event_handler *handler,
+                               struct ib_event *event)
+{
+       iser_err("async event %d on device %s port %d\n", event->event,
+               event->device->name, event->element.port_num);
+}
+
 /**
  * iser_create_device_ib_res - creates Protection Domain (PD), Completion
  * Queue (CQ), DMA Memory Region (DMA MR) with the device associated with
@@ -96,8 +103,15 @@ static int iser_create_device_ib_res(struct iser_device *device)
        if (IS_ERR(device->mr))
                goto dma_mr_err;
 
+       INIT_IB_EVENT_HANDLER(&device->event_handler, device->ib_device,
+                               iser_event_handler);
+       if (ib_register_event_handler(&device->event_handler))
+               goto handler_err;
+
        return 0;
 
+handler_err:
+       ib_dereg_mr(device->mr);
 dma_mr_err:
        tasklet_kill(&device->cq_tasklet);
 cq_arm_err:
@@ -120,7 +134,7 @@ static void iser_free_device_ib_res(struct iser_device *device)
        BUG_ON(device->mr == NULL);
 
        tasklet_kill(&device->cq_tasklet);
-
+       (void)ib_unregister_event_handler(&device->event_handler);
        (void)ib_dereg_mr(device->mr);
        (void)ib_destroy_cq(device->tx_cq);
        (void)ib_destroy_cq(device->rx_cq);
@@ -149,10 +163,8 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
        device = ib_conn->device;
 
        ib_conn->login_buf = kmalloc(ISER_RX_LOGIN_SIZE, GFP_KERNEL);
-       if (!ib_conn->login_buf) {
-               goto alloc_err;
-               ret = -ENOMEM;
-       }
+       if (!ib_conn->login_buf)
+               goto out_err;
 
        ib_conn->login_dma = ib_dma_map_single(ib_conn->device->ib_device,
                                (void *)ib_conn->login_buf, ISER_RX_LOGIN_SIZE,
@@ -161,10 +173,9 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
        ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) +
                                    (sizeof(u64) * (ISCSI_ISER_SG_TABLESIZE +1)),
                                    GFP_KERNEL);
-       if (!ib_conn->page_vec) {
-               ret = -ENOMEM;
-               goto alloc_err;
-       }
+       if (!ib_conn->page_vec)
+               goto out_err;
+
        ib_conn->page_vec->pages = (u64 *) (ib_conn->page_vec + 1);
 
        params.page_shift        = SHIFT_4K;
@@ -184,7 +195,8 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
        ib_conn->fmr_pool = ib_create_fmr_pool(device->pd, &params);
        if (IS_ERR(ib_conn->fmr_pool)) {
                ret = PTR_ERR(ib_conn->fmr_pool);
-               goto fmr_pool_err;
+               ib_conn->fmr_pool = NULL;
+               goto out_err;
        }
 
        memset(&init_attr, 0, sizeof init_attr);
@@ -202,7 +214,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
 
        ret = rdma_create_qp(ib_conn->cma_id, device->pd, &init_attr);
        if (ret)
-               goto qp_err;
+               goto out_err;
 
        ib_conn->qp = ib_conn->cma_id->qp;
        iser_err("setting conn %p cma_id %p: fmr_pool %p qp %p\n",
@@ -210,12 +222,7 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
                 ib_conn->fmr_pool, ib_conn->cma_id->qp);
        return ret;
 
-qp_err:
-       (void)ib_destroy_fmr_pool(ib_conn->fmr_pool);
-fmr_pool_err:
-       kfree(ib_conn->page_vec);
-       kfree(ib_conn->login_buf);
-alloc_err:
+out_err:
        iser_err("unable to alloc mem or create resource, err %d\n", ret);
        return ret;
 }
@@ -224,7 +231,7 @@ alloc_err:
  * releases the FMR pool, QP and CMA ID objects, returns 0 on success,
  * -1 on failure
  */
-static int iser_free_ib_conn_res(struct iser_conn *ib_conn)
+static int iser_free_ib_conn_res(struct iser_conn *ib_conn, int can_destroy_id)
 {
        BUG_ON(ib_conn == NULL);
 
@@ -239,7 +246,8 @@ static int iser_free_ib_conn_res(struct iser_conn *ib_conn)
        if (ib_conn->qp != NULL)
                rdma_destroy_qp(ib_conn->cma_id);
 
-       if (ib_conn->cma_id != NULL)
+       /* if cma handler context, the caller acts s.t the cma destroy the id */
+       if (ib_conn->cma_id != NULL && can_destroy_id)
                rdma_destroy_id(ib_conn->cma_id);
 
        ib_conn->fmr_pool = NULL;
@@ -317,7 +325,7 @@ static int iser_conn_state_comp_exch(struct iser_conn *ib_conn,
 /**
  * Frees all conn objects and deallocs conn descriptor
  */
-static void iser_conn_release(struct iser_conn *ib_conn)
+static void iser_conn_release(struct iser_conn *ib_conn, int can_destroy_id)
 {
        struct iser_device  *device = ib_conn->device;
 
@@ -327,13 +335,11 @@ static void iser_conn_release(struct iser_conn *ib_conn)
        list_del(&ib_conn->conn_list);
        mutex_unlock(&ig.connlist_mutex);
        iser_free_rx_descriptors(ib_conn);
-       iser_free_ib_conn_res(ib_conn);
+       iser_free_ib_conn_res(ib_conn, can_destroy_id);
        ib_conn->device = NULL;
        /* on EVENT_ADDR_ERROR there's no device yet for this conn */
        if (device != NULL)
                iser_device_try_release(device);
-       if (ib_conn->iser_conn)
-               ib_conn->iser_conn->ib_conn = NULL;
        iscsi_destroy_endpoint(ib_conn->ep);
 }
 
@@ -342,10 +348,13 @@ void iser_conn_get(struct iser_conn *ib_conn)
        atomic_inc(&ib_conn->refcount);
 }
 
-void iser_conn_put(struct iser_conn *ib_conn)
+int iser_conn_put(struct iser_conn *ib_conn, int can_destroy_id)
 {
-       if (atomic_dec_and_test(&ib_conn->refcount))
-               iser_conn_release(ib_conn);
+       if (atomic_dec_and_test(&ib_conn->refcount)) {
+               iser_conn_release(ib_conn, can_destroy_id);
+               return 1;
+       }
+       return 0;
 }
 
 /**
@@ -369,19 +378,20 @@ void iser_conn_terminate(struct iser_conn *ib_conn)
        wait_event_interruptible(ib_conn->wait,
                                 ib_conn->state == ISER_CONN_DOWN);
 
-       iser_conn_put(ib_conn);
+       iser_conn_put(ib_conn, 1); /* deref ib conn deallocate */
 }
 
-static void iser_connect_error(struct rdma_cm_id *cma_id)
+static int iser_connect_error(struct rdma_cm_id *cma_id)
 {
        struct iser_conn *ib_conn;
        ib_conn = (struct iser_conn *)cma_id->context;
 
        ib_conn->state = ISER_CONN_DOWN;
        wake_up_interruptible(&ib_conn->wait);
+       return iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */
 }
 
-static void iser_addr_handler(struct rdma_cm_id *cma_id)
+static int iser_addr_handler(struct rdma_cm_id *cma_id)
 {
        struct iser_device *device;
        struct iser_conn   *ib_conn;
@@ -390,8 +400,7 @@ static void iser_addr_handler(struct rdma_cm_id *cma_id)
        device = iser_device_find_by_ib_device(cma_id);
        if (!device) {
                iser_err("device lookup/creation failed\n");
-               iser_connect_error(cma_id);
-               return;
+               return iser_connect_error(cma_id);
        }
 
        ib_conn = (struct iser_conn *)cma_id->context;
@@ -400,11 +409,13 @@ static void iser_addr_handler(struct rdma_cm_id *cma_id)
        ret = rdma_resolve_route(cma_id, 1000);
        if (ret) {
                iser_err("resolve route failed: %d\n", ret);
-               iser_connect_error(cma_id);
+               return iser_connect_error(cma_id);
        }
+
+       return 0;
 }
 
-static void iser_route_handler(struct rdma_cm_id *cma_id)
+static int iser_route_handler(struct rdma_cm_id *cma_id)
 {
        struct rdma_conn_param conn_param;
        int    ret;
@@ -425,9 +436,9 @@ static void iser_route_handler(struct rdma_cm_id *cma_id)
                goto failure;
        }
 
-       return;
+       return 0;
 failure:
-       iser_connect_error(cma_id);
+       return iser_connect_error(cma_id);
 }
 
 static void iser_connected_handler(struct rdma_cm_id *cma_id)
@@ -439,12 +450,12 @@ static void iser_connected_handler(struct rdma_cm_id *cma_id)
        wake_up_interruptible(&ib_conn->wait);
 }
 
-static void iser_disconnected_handler(struct rdma_cm_id *cma_id)
+static int iser_disconnected_handler(struct rdma_cm_id *cma_id)
 {
        struct iser_conn *ib_conn;
+       int ret;
 
        ib_conn = (struct iser_conn *)cma_id->context;
-       ib_conn->disc_evt_flag = 1;
 
        /* getting here when the state is UP means that the conn is being *
         * terminated asynchronously from the iSCSI layer's perspective.  */
@@ -459,20 +470,24 @@ static void iser_disconnected_handler(struct rdma_cm_id *cma_id)
                ib_conn->state = ISER_CONN_DOWN;
                wake_up_interruptible(&ib_conn->wait);
        }
+
+       ret = iser_conn_put(ib_conn, 0); /* deref ib conn's cma id */
+       return ret;
 }
 
 static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
 {
        int ret = 0;
 
-       iser_err("event %d conn %p id %p\n",event->event,cma_id->context,cma_id);
+       iser_err("event %d status %d conn %p id %p\n",
+               event->event, event->status, cma_id->context, cma_id);
 
        switch (event->event) {
        case RDMA_CM_EVENT_ADDR_RESOLVED:
-               iser_addr_handler(cma_id);
+               ret = iser_addr_handler(cma_id);
                break;
        case RDMA_CM_EVENT_ROUTE_RESOLVED:
-               iser_route_handler(cma_id);
+               ret = iser_route_handler(cma_id);
                break;
        case RDMA_CM_EVENT_ESTABLISHED:
                iser_connected_handler(cma_id);
@@ -482,13 +497,12 @@ static int iser_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *eve
        case RDMA_CM_EVENT_CONNECT_ERROR:
        case RDMA_CM_EVENT_UNREACHABLE:
        case RDMA_CM_EVENT_REJECTED:
-               iser_err("event: %d, error: %d\n", event->event, event->status);
-               iser_connect_error(cma_id);
+               ret = iser_connect_error(cma_id);
                break;
        case RDMA_CM_EVENT_DISCONNECTED:
        case RDMA_CM_EVENT_DEVICE_REMOVAL:
        case RDMA_CM_EVENT_ADDR_CHANGE:
-               iser_disconnected_handler(cma_id);
+               ret = iser_disconnected_handler(cma_id);
                break;
        default:
                iser_err("Unexpected RDMA CM event (%d)\n", event->event);
@@ -503,7 +517,7 @@ void iser_conn_init(struct iser_conn *ib_conn)
        init_waitqueue_head(&ib_conn->wait);
        ib_conn->post_recv_buf_count = 0;
        atomic_set(&ib_conn->post_send_buf_count, 0);
-       atomic_set(&ib_conn->refcount, 1);
+       atomic_set(&ib_conn->refcount, 1); /* ref ib conn allocation */
        INIT_LIST_HEAD(&ib_conn->conn_list);
        spin_lock_init(&ib_conn->lock);
 }
@@ -531,6 +545,7 @@ int iser_connect(struct iser_conn   *ib_conn,
 
        ib_conn->state = ISER_CONN_PENDING;
 
+       iser_conn_get(ib_conn); /* ref ib conn's cma id */
        ib_conn->cma_id = rdma_create_id(iser_cma_handler,
                                             (void *)ib_conn,
                                             RDMA_PS_TCP);
@@ -568,7 +583,7 @@ id_failure:
 addr_failure:
        ib_conn->state = ISER_CONN_DOWN;
 connect_failure:
-       iser_conn_release(ib_conn);
+       iser_conn_release(ib_conn, 1);
        return err;
 }
 
@@ -737,12 +752,10 @@ static void iser_handle_comp_error(struct iser_tx_desc *desc,
                        iscsi_conn_failure(ib_conn->iser_conn->iscsi_conn,
                                           ISCSI_ERR_CONN_FAILED);
 
-               /* complete the termination process if disconnect event was delivered *
-                * note there are no more non completed posts to the QP               */
-               if (ib_conn->disc_evt_flag) {
-                       ib_conn->state = ISER_CONN_DOWN;
-                       wake_up_interruptible(&ib_conn->wait);
-               }
+               /* no more non completed posts to the QP, complete the
+                * termination process w.o worrying on disconnect event */
+               ib_conn->state = ISER_CONN_DOWN;
+               wake_up_interruptible(&ib_conn->wait);
        }
 }
 
index 7e18bcf..46239e4 100644 (file)
@@ -59,11 +59,11 @@ static unsigned int get_time_pit(void)
        unsigned long flags;
        unsigned int count;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
        outb_p(0x00, 0x43);
        count = inb_p(0x40);
        count |= inb_p(0x40) << 8;
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 
        return count;
 }
index 1c0b529..4afe0a3 100644 (file)
@@ -146,11 +146,11 @@ static unsigned int get_time_pit(void)
         unsigned long flags;
         unsigned int count;
 
-        spin_lock_irqsave(&i8253_lock, flags);
+        raw_spin_lock_irqsave(&i8253_lock, flags);
         outb_p(0x00, 0x43);
         count = inb_p(0x40);
         count |= inb_p(0x40) << 8;
-        spin_unlock_irqrestore(&i8253_lock, flags);
+        raw_spin_unlock_irqrestore(&i8253_lock, flags);
 
         return count;
 }
index ea4e1fd..f080dd3 100644 (file)
@@ -30,7 +30,7 @@ MODULE_ALIAS("platform:pcspkr");
 #include <asm/i8253.h>
 #else
 #include <asm/8253pit.h>
-static DEFINE_SPINLOCK(i8253_lock);
+static DEFINE_RAW_SPINLOCK(i8253_lock);
 #endif
 
 static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
@@ -50,7 +50,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
        if (value > 20 && value < 32767)
                count = PIT_TICK_RATE / value;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
 
        if (count) {
                /* set command for counter 2, 2 byte write */
@@ -65,7 +65,7 @@ static int pcspkr_event(struct input_dev *dev, unsigned int type, unsigned int c
                outb(inb_p(0x61) & 0xFC, 0x61);
        }
 
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 
        return 0;
 }
index cc47198..b9f58ca 100644 (file)
@@ -154,8 +154,8 @@ config TOUCHSCREEN_FUJITSU
          module will be called fujitsu-ts.
 
 config TOUCHSCREEN_S3C2410
-       tristate "Samsung S3C2410 touchscreen input driver"
-       depends on ARCH_S3C2410
+       tristate "Samsung S3C2410/generic touchscreen input driver"
+       depends on ARCH_S3C2410 || SAMSUNG_DEV_TS
        select S3C24XX_ADC
        help
          Say Y here if you have the s3c2410 touchscreen.
index 98a7d12..e0b7c83 100644 (file)
@@ -37,9 +37,7 @@
 
 #include <plat/adc.h>
 #include <plat/regs-adc.h>
-
-#include <mach/regs-gpio.h>
-#include <mach/ts.h>
+#include <plat/ts.h>
 
 #define TSC_SLEEP  (S3C2410_ADCTSC_PULL_UP_DISABLE | S3C2410_ADCTSC_XY_PST(0))
 
@@ -57,6 +55,8 @@
                         S3C2410_ADCTSC_AUTO_PST | \
                         S3C2410_ADCTSC_XY_PST(0))
 
+#define FEAT_PEN_IRQ   (1 << 0)        /* HAS ADCCLRINTPNDNUP */
+
 /* Per-touchscreen data. */
 
 /**
@@ -71,6 +71,7 @@
  * @irq_tc: The interrupt number for pen up/down interrupt
  * @count: The number of samples collected.
  * @shift: The log2 of the maximum count to read in one go.
+ * @features: The features supported by the TSADC MOdule.
  */
 struct s3c2410ts {
        struct s3c_adc_client *client;
@@ -83,25 +84,11 @@ struct s3c2410ts {
        int irq_tc;
        int count;
        int shift;
+       int features;
 };
 
 static struct s3c2410ts ts;
 
-/**
- * s3c2410_ts_connect - configure gpio for s3c2410 systems
- *
- * Configure the GPIO for the S3C2410 system, where we have external FETs
- * connected to the device (later systems such as the S3C2440 integrate
- * these into the device).
-*/
-static inline void s3c2410_ts_connect(void)
-{
-       s3c2410_gpio_cfgpin(S3C2410_GPG(12), S3C2410_GPG12_XMON);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(13), S3C2410_GPG13_nXPON);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(14), S3C2410_GPG14_YMON);
-       s3c2410_gpio_cfgpin(S3C2410_GPG(15), S3C2410_GPG15_nYPON);
-}
-
 /**
  * get_down - return the down state of the pen
  * @data0: The data read from ADCDAT0 register.
@@ -188,6 +175,11 @@ static irqreturn_t stylus_irq(int irq, void *dev_id)
        else
                dev_info(ts.dev, "%s: count=%d\n", __func__, ts.count);
 
+       if (ts.features & FEAT_PEN_IRQ) {
+               /* Clear pen down/up interrupt */
+               writel(0x0, ts.io + S3C64XX_ADCCLRINTPNDNUP);
+       }
+
        return IRQ_HANDLED;
 }
 
@@ -296,9 +288,9 @@ static int __devinit s3c2410ts_probe(struct platform_device *pdev)
                goto err_clk;
        }
 
-       /* Configure the touchscreen external FETs on the S3C2410 */
-       if (!platform_get_device_id(pdev)->driver_data)
-               s3c2410_ts_connect();
+       /* inititalise the gpio */
+       if (info->cfg_gpio)
+               info->cfg_gpio(to_platform_device(ts.dev));
 
        ts.client = s3c_adc_register(pdev, s3c24xx_ts_select,
                                     s3c24xx_ts_conversion, 1);
@@ -334,6 +326,7 @@ static int __devinit s3c2410ts_probe(struct platform_device *pdev)
        ts.input->id.version = 0x0102;
 
        ts.shift = info->oversampling_shift;
+       ts.features = platform_get_device_id(pdev)->driver_data;
 
        ret = request_irq(ts.irq_tc, stylus_irq, IRQF_DISABLED,
                          "s3c2410_ts_pen", ts.input);
@@ -420,15 +413,14 @@ static struct dev_pm_ops s3c_ts_pmops = {
 #endif
 
 static struct platform_device_id s3cts_driver_ids[] = {
-       { "s3c2410-ts", 0 },
-       { "s3c2440-ts", 1 },
+       { "s3c64xx-ts", FEAT_PEN_IRQ },
        { }
 };
 MODULE_DEVICE_TABLE(platform, s3cts_driver_ids);
 
 static struct platform_driver s3c_ts_driver = {
        .driver         = {
-               .name   = "s3c24xx-ts",
+               .name   = "samsung-ts",
                .owner  = THIS_MODULE,
 #ifdef CONFIG_PM
                .pm     = &s3c_ts_pmops,
index 9f49d90..c53e241 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/sched.h>
 #include <linux/isdnif.h>
 #include <net/net_namespace.h>
+#include <linux/smp_lock.h>
 #include "isdn_divert.h"
 
 
@@ -177,9 +178,7 @@ isdn_divert_close(struct inode *ino, struct file *filep)
 /*********/
 /* IOCTL */
 /*********/
-static int
-isdn_divert_ioctl(struct inode *inode, struct file *file,
-                 uint cmd, ulong arg)
+static int isdn_divert_ioctl_unlocked(struct file *file, uint cmd, ulong arg)
 {
        divert_ioctl dioctl;
        int i;
@@ -258,6 +257,17 @@ isdn_divert_ioctl(struct inode *inode, struct file *file,
        return copy_to_user((void __user *)arg, &dioctl, sizeof(dioctl)) ? -EFAULT : 0;
 }                              /* isdn_divert_ioctl */
 
+static long isdn_divert_ioctl(struct file *file, uint cmd, ulong arg)
+{
+       long ret;
+
+       lock_kernel();
+       ret = isdn_divert_ioctl_unlocked(file, cmd, arg);
+       unlock_kernel();
+
+       return ret;
+}
+
 static const struct file_operations isdn_fops =
 {
        .owner          = THIS_MODULE,
@@ -265,7 +275,7 @@ static const struct file_operations isdn_fops =
        .read           = isdn_divert_read,
        .write          = isdn_divert_write,
        .poll           = isdn_divert_poll,
-       .ioctl          = isdn_divert_ioctl,
+       .unlocked_ioctl = isdn_divert_ioctl,
        .open           = isdn_divert_open,
        .release        = isdn_divert_close,                                      
 };
index 94b796d..f410d0e 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/ptrace.h>
-#include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/tty.h>
 #include <linux/serial.h>
@@ -61,31 +60,6 @@ static void avmcs_release(struct pcmcia_device *link);
 
 static void avmcs_detach(struct pcmcia_device *p_dev);
 
-/*
-   A linked list of "instances" of the skeleton device.  Each actual
-   PCMCIA card corresponds to one device instance, and is described
-   by one struct pcmcia_device structure (defined in ds.h).
-
-   You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of struct pcmcia_device pointers, where minor
-   device numbers are used to derive the corresponding array index.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally can't be allocated dynamically.
-*/
-   
-typedef struct local_info_t {
-    dev_node_t node;
-} local_info_t;
-
 /*======================================================================
 
     avmcs_attach() creates an "instance" of the driver, allocating
@@ -100,32 +74,19 @@ typedef struct local_info_t {
 
 static int avmcs_probe(struct pcmcia_device *p_dev)
 {
-    local_info_t *local;
 
     /* The io structure describes IO port mapping */
     p_dev->io.NumPorts1 = 16;
     p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
     p_dev->io.NumPorts2 = 0;
 
-    /* Interrupt setup */
-    p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
     /* General socket configuration */
     p_dev->conf.Attributes = CONF_ENABLE_IRQ;
     p_dev->conf.IntType = INT_MEMORY_AND_IO;
     p_dev->conf.ConfigIndex = 1;
     p_dev->conf.Present = PRESENT_OPTION;
 
-    /* Allocate space for private device-specific data */
-    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
-    if (!local)
-        goto err;
-    p_dev->priv = local;
-
     return avmcs_config(p_dev);
-
- err:
-    return -ENOMEM;
 } /* avmcs_attach */
 
 /*======================================================================
@@ -140,7 +101,6 @@ static int avmcs_probe(struct pcmcia_device *p_dev)
 static void avmcs_detach(struct pcmcia_device *link)
 {
        avmcs_release(link);
-       kfree(link->priv);
 } /* avmcs_detach */
 
 /*======================================================================
@@ -171,14 +131,11 @@ static int avmcs_configcheck(struct pcmcia_device *p_dev,
 
 static int avmcs_config(struct pcmcia_device *link)
 {
-    local_info_t *dev;
-    int i;
+    int i = -1;
     char devname[128];
     int cardtype;
     int (*addcard)(unsigned int port, unsigned irq);
 
-    dev = link->priv;
-
     devname[0] = 0;
     if (link->prod_id[1])
            strlcpy(devname, link->prod_id[1], sizeof(devname));
@@ -190,11 +147,7 @@ static int avmcs_config(struct pcmcia_device *link)
            return -ENODEV;
 
     do {
-       /*
-        * allocate an interrupt line
-        */
-       i = pcmcia_request_irq(link, &link->irq);
-       if (i != 0) {
+       if (!link->irq) {
            /* undo */
            pcmcia_disable_device(link);
            break;
@@ -211,15 +164,11 @@ static int avmcs_config(struct pcmcia_device *link)
 
     } while (0);
 
-    /* At this point, the dev_node_t structure(s) should be
-       initialized and arranged in a linked list at link->dev. */
-
     if (devname[0]) {
        char *s = strrchr(devname, ' ');
        if (!s)
           s = devname;
        else s++;
-       strcpy(dev->node.dev_name, s);
         if (strcmp("M1", s) == 0) {
            cardtype = AVM_CARDTYPE_M1;
         } else if (strcmp("M2", s) == 0) {
@@ -227,14 +176,8 @@ static int avmcs_config(struct pcmcia_device *link)
        } else {
            cardtype = AVM_CARDTYPE_B1;
        }
-    } else {
-        strcpy(dev->node.dev_name, "b1");
+    } else
         cardtype = AVM_CARDTYPE_B1;
-    }
-
-    dev->node.major = 64;
-    dev->node.minor = 0;
-    link->dev_node = &dev->node;
 
     /* If any step failed, release any partially configured state */
     if (i != 0) {
@@ -249,13 +192,12 @@ static int avmcs_config(struct pcmcia_device *link)
        default:
         case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
     }
-    if ((i = (*addcard)(link->io.BasePort1, link->irq.AssignedIRQ)) < 0) {
-        printk(KERN_ERR "avm_cs: failed to add AVM-%s-Controller at i/o %#x, irq %d\n",
-               dev->node.dev_name, link->io.BasePort1, link->irq.AssignedIRQ);
-       avmcs_release(link);
-       return -ENODEV;
+    if ((i = (*addcard)(link->io.BasePort1, link->irq)) < 0) {
+           dev_err(&link->dev, "avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
+                   link->io.BasePort1, link->irq);
+           avmcs_release(link);
+           return -ENODEV;
     }
-    dev->node.minor = i;
     return 0;
 
 } /* avmcs_config */
@@ -270,7 +212,7 @@ static int avmcs_config(struct pcmcia_device *link)
 
 static void avmcs_release(struct pcmcia_device *link)
 {
-       b1pcmcia_delcard(link->io.BasePort1, link->irq.AssignedIRQ);
+       b1pcmcia_delcard(link->io.BasePort1, link->irq);
        pcmcia_disable_device(link);
 } /* avmcs_release */
 
index 75e71b5..095ed76 100644 (file)
  *     NOTE: only one mode value must be given for every card.
  *     -> See hfc_multi.h for HFC_IO_MODE_* values
  *     By default, the IO mode is pci memory IO (MEMIO).
- *     Some cards requre specific IO mode, so it cannot be changed.
+ *     Some cards require specific IO mode, so it cannot be changed.
  *     It may be usefull to set IO mode to register io (REGIO) to solve
  *     PCI bridge problems.
  *     If unsure, don't give this parameter.
index 8d1d63a..a80a761 100644 (file)
@@ -62,31 +62,6 @@ static void avma1cs_release(struct pcmcia_device *link);
 static void avma1cs_detach(struct pcmcia_device *p_dev) __devexit ;
 
 
-/*
-   A linked list of "instances" of the skeleton device.  Each actual
-   PCMCIA card corresponds to one device instance, and is described
-   by one struct pcmcia_device structure (defined in ds.h).
-
-   You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of struct pcmcia_device pointers, where minor
-   device numbers are used to derive the corresponding array index.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally can't be allocated dynamically.
-*/
-   
-typedef struct local_info_t {
-    dev_node_t node;
-} local_info_t;
-
 /*======================================================================
 
     avma1cs_attach() creates an "instance" of the driver, allocating
@@ -101,17 +76,8 @@ typedef struct local_info_t {
 
 static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
 {
-    local_info_t *local;
-
     dev_dbg(&p_dev->dev, "avma1cs_attach()\n");
 
-    /* Allocate space for private device-specific data */
-    local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
-    if (!local)
-       return -ENOMEM;
-
-    p_dev->priv = local;
-
     /* The io structure describes IO port mapping */
     p_dev->io.NumPorts1 = 16;
     p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -119,9 +85,6 @@ static int __devinit avma1cs_probe(struct pcmcia_device *p_dev)
     p_dev->io.Attributes2 = IO_DATA_PATH_WIDTH_16;
     p_dev->io.IOAddrLines = 5;
 
-    /* Interrupt setup */
-    p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-
     /* General socket configuration */
     p_dev->conf.Attributes = CONF_ENABLE_IRQ;
     p_dev->conf.IntType = INT_MEMORY_AND_IO;
@@ -176,14 +139,11 @@ static int avma1cs_configcheck(struct pcmcia_device *p_dev,
 
 static int __devinit avma1cs_config(struct pcmcia_device *link)
 {
-    local_info_t *dev;
-    int i;
+    int i = -1;
     char devname[128];
     IsdnCard_t icard;
     int busy = 0;
 
-    dev = link->priv;
-
     dev_dbg(&link->dev, "avma1cs_config(0x%p)\n", link);
 
     devname[0] = 0;
@@ -197,8 +157,7 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
        /*
         * allocate an interrupt line
         */
-       i = pcmcia_request_irq(link, &link->irq);
-       if (i != 0) {
+       if (!link->irq) {
            /* undo */
            pcmcia_disable_device(link);
            break;
@@ -215,14 +174,6 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
 
     } while (0);
 
-    /* At this point, the dev_node_t structure(s) should be
-       initialized and arranged in a linked list at link->dev. */
-
-    strcpy(dev->node.dev_name, "A1");
-    dev->node.major = 45;
-    dev->node.minor = 0;
-    link->dev_node = &dev->node;
-
     /* If any step failed, release any partially configured state */
     if (i != 0) {
        avma1cs_release(link);
@@ -230,9 +181,9 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
     }
 
     printk(KERN_NOTICE "avma1_cs: checking at i/o %#x, irq %d\n",
-                               link->io.BasePort1, link->irq.AssignedIRQ);
+                               link->io.BasePort1, link->irq);
 
-    icard.para[0] = link->irq.AssignedIRQ;
+    icard.para[0] = link->irq;
     icard.para[1] = link->io.BasePort1;
     icard.protocol = isdnprot;
     icard.typ = ISDN_CTYPE_A1_PCMCIA;
@@ -243,7 +194,7 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
        avma1cs_release(link);
        return -ENODEV;
     }
-    dev->node.minor = i;
+    link->priv = (void *) (unsigned long) i;
 
     return 0;
 } /* avma1cs_config */
@@ -258,12 +209,12 @@ static int __devinit avma1cs_config(struct pcmcia_device *link)
 
 static void avma1cs_release(struct pcmcia_device *link)
 {
-       local_info_t *local = link->priv;
+       unsigned long minor = (unsigned long) link->priv;
 
        dev_dbg(&link->dev, "avma1cs_release(0x%p)\n", link);
 
        /* now unregister function with hisax */
-       HiSax_closecard(local->node.minor);
+       HiSax_closecard(minor);
 
        pcmcia_disable_device(link);
 } /* avma1cs_release */
index c9f2279..218927e 100644 (file)
@@ -87,24 +87,8 @@ static void elsa_cs_release(struct pcmcia_device *link);
 
 static void elsa_cs_detach(struct pcmcia_device *p_dev) __devexit;
 
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally shouldn't be allocated dynamically.
-   In this case, we also provide a flag to indicate if a device is
-   "stopped" due to a power management event, or card ejection.  The
-   device IO routines can use a flag like this to throttle IO to a
-   card that is not ready to accept it.
-*/
-
 typedef struct local_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t          node;
     int                 busy;
     int                        cardnr;
 } local_info_t;
@@ -136,10 +120,6 @@ static int __devinit elsa_cs_probe(struct pcmcia_device *link)
 
     local->cardnr = -1;
 
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = NULL;
-
     /*
       General socket configuration defaults can go here.  In this
       client, we assume very little, and rely on the CIS for almost
@@ -223,28 +203,18 @@ static int __devinit elsa_cs_config(struct pcmcia_device *link)
     if (i != 0)
        goto failed;
 
-    i = pcmcia_request_irq(link, &link->irq);
-    if (i != 0) {
-        link->irq.AssignedIRQ = 0;
+    if (!link->irq)
        goto failed;
-    }
 
     i = pcmcia_request_configuration(link, &link->conf);
     if (i != 0)
        goto failed;
 
-    /* At this point, the dev_node_t structure(s) should be
-       initialized and arranged in a linked list at link->dev. *//*  */
-    sprintf(dev->node.dev_name, "elsa");
-    dev->node.major = dev->node.minor = 0x0;
-
-    link->dev_node = &dev->node;
-
     /* Finally, report what we've done */
-    printk(KERN_INFO "%s: index 0x%02x: ",
-           dev->node.dev_name, link->conf.ConfigIndex);
+    dev_info(&link->dev, "index 0x%02x: ",
+           link->conf.ConfigIndex);
     if (link->conf.Attributes & CONF_ENABLE_IRQ)
-        printk(", irq %d", link->irq.AssignedIRQ);
+       printk(", irq %d", link->irq);
     if (link->io.NumPorts1)
         printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                link->io.BasePort1+link->io.NumPorts1-1);
@@ -253,7 +223,7 @@ static int __devinit elsa_cs_config(struct pcmcia_device *link)
                link->io.BasePort2+link->io.NumPorts2-1);
     printk("\n");
 
-    icard.para[0] = link->irq.AssignedIRQ;
+    icard.para[0] = link->irq;
     icard.para[1] = link->io.BasePort1;
     icard.protocol = protocol;
     icard.typ = ISDN_CTYPE_ELSA_PCMCIA;
index 051b44e..384d511 100644 (file)
@@ -310,7 +310,7 @@ wait_busy(hfc4s8s_hw * a)
 
 /******************************************************/
 /* function to read critical counter registers that   */
-/* may be udpated by the chip during read             */
+/* may be updated by the chip during read             */
 /******************************************************/
 static u_char
 Read_hfc8_stable(hfc4s8s_hw * hw, int reg)
index 71b3dde..1f4feaa 100644 (file)
@@ -87,32 +87,8 @@ static void sedlbauer_release(struct pcmcia_device *link);
 
 static void sedlbauer_detach(struct pcmcia_device *p_dev) __devexit;
 
-/*
-   You'll also need to prototype all the functions that will actually
-   be used to talk to your device.  See 'memory_cs' for a good example
-   of a fully self-sufficient driver; the other drivers rely more or
-   less on other parts of the kernel.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally shouldn't be allocated dynamically.
-
-   In this case, we also provide a flag to indicate if a device is
-   "stopped" due to a power management event, or card ejection.  The
-   device IO routines can use a flag like this to throttle IO to a
-   card that is not ready to accept it.
-*/
-   
 typedef struct local_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t         node;
     int                        stop;
     int                        cardnr;
 } local_info_t;
@@ -143,10 +119,6 @@ static int __devinit sedlbauer_probe(struct pcmcia_device *link)
     local->p_dev = link;
     link->priv = local;
 
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = NULL;
-
     /*
       General socket configuration defaults can go here.  In this
       client, we assume very little, and rely on the CIS for almost
@@ -227,9 +199,7 @@ static int sedlbauer_config_check(struct pcmcia_device *p_dev,
        else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
                p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
 
-       /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -285,7 +255,6 @@ static int sedlbauer_config_check(struct pcmcia_device *p_dev,
 
 static int __devinit sedlbauer_config(struct pcmcia_device *link)
 {
-    local_info_t *dev = link->priv;
     win_req_t *req;
     int ret;
     IsdnCard_t  icard;
@@ -312,17 +281,6 @@ static int __devinit sedlbauer_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    /*
-       Allocate an interrupt line.  Note that this does not assign a
-       handler to the interrupt, unless the 'Handler' member of the
-       irq structure is initialized.
-    */
-    if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-           ret = pcmcia_request_irq(link, &link->irq);
-           if (ret)
-                   goto failed;
-    }
-       
     /*
        This actually configures the PCMCIA socket -- setting up
        the I/O windows and the interrupt mapping, and putting the
@@ -332,21 +290,13 @@ static int __devinit sedlbauer_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    /*
-      At this point, the dev_node_t structure(s) need to be
-      initialized and arranged in a linked list at link->dev.
-    */
-    sprintf(dev->node.dev_name, "sedlbauer");
-    dev->node.major = dev->node.minor = 0;
-    link->dev_node = &dev->node;
-
     /* Finally, report what we've done */
-    printk(KERN_INFO "%s: index 0x%02x:",
-          dev->node.dev_name, link->conf.ConfigIndex);
+    dev_info(&link->dev, "index 0x%02x:",
+          link->conf.ConfigIndex);
     if (link->conf.Vpp)
        printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
     if (link->conf.Attributes & CONF_ENABLE_IRQ)
-       printk(", irq %d", link->irq.AssignedIRQ);
+       printk(", irq %d", link->irq);
     if (link->io.NumPorts1)
        printk(", io 0x%04x-0x%04x", link->io.BasePort1,
               link->io.BasePort1+link->io.NumPorts1-1);
@@ -358,7 +308,7 @@ static int __devinit sedlbauer_config(struct pcmcia_device *link)
               req->Base+req->Size-1);
     printk("\n");
 
-    icard.para[0] = link->irq.AssignedIRQ;
+    icard.para[0] = link->irq;
     icard.para[1] = link->io.BasePort1;
     icard.protocol = protocol;
     icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
index d010a0d..5771955 100644 (file)
@@ -68,34 +68,8 @@ static void teles_cs_release(struct pcmcia_device *link);
 
 static void teles_detach(struct pcmcia_device *p_dev) __devexit ;
 
-/*
-   A linked list of "instances" of the teles_cs device.  Each actual
-   PCMCIA card corresponds to one device instance, and is described
-   by one struct pcmcia_device structure (defined in ds.h).
-
-   You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of struct pcmcia_device pointers, where minor
-   device numbers are used to derive the corresponding array index.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally shouldn't be allocated dynamically.
-   In this case, we also provide a flag to indicate if a device is
-   "stopped" due to a power management event, or card ejection.  The
-   device IO routines can use a flag like this to throttle IO to a
-   card that is not ready to accept it.
-*/
-
 typedef struct local_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t          node;
     int                 busy;
     int                        cardnr;
 } local_info_t;
@@ -126,10 +100,6 @@ static int __devinit teles_probe(struct pcmcia_device *link)
     local->p_dev = link;
     link->priv = local;
 
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = NULL;
-
     /*
       General socket configuration defaults can go here.  In this
       client, we assume very little, and rely on the CIS for almost
@@ -213,28 +183,18 @@ static int __devinit teles_cs_config(struct pcmcia_device *link)
     if (i != 0)
        goto cs_failed;
 
-    i = pcmcia_request_irq(link, &link->irq);
-    if (i != 0) {
-        link->irq.AssignedIRQ = 0;
+    if (!link->irq)
         goto cs_failed;
-    }
 
     i = pcmcia_request_configuration(link, &link->conf);
     if (i != 0)
       goto cs_failed;
 
-    /* At this point, the dev_node_t structure(s) should be
-       initialized and arranged in a linked list at link->dev. *//*  */
-    sprintf(dev->node.dev_name, "teles");
-    dev->node.major = dev->node.minor = 0x0;
-
-    link->dev_node = &dev->node;
-
     /* Finally, report what we've done */
-    printk(KERN_INFO "%s: index 0x%02x:",
-           dev->node.dev_name, link->conf.ConfigIndex);
+    dev_info(&link->dev, "index 0x%02x:",
+           link->conf.ConfigIndex);
     if (link->conf.Attributes & CONF_ENABLE_IRQ)
-        printk(", irq %d", link->irq.AssignedIRQ);
+           printk(", irq %d", link->irq);
     if (link->io.NumPorts1)
         printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                link->io.BasePort1+link->io.NumPorts1-1);
@@ -243,7 +203,7 @@ static int __devinit teles_cs_config(struct pcmcia_device *link)
                link->io.BasePort2+link->io.NumPorts2-1);
     printk("\n");
 
-    icard.para[0] = link->irq.AssignedIRQ;
+    icard.para[0] = link->irq;
     icard.para[1] = link->io.BasePort1;
     icard.protocol = protocol;
     icard.typ = ISDN_CTYPE_TELESPCMCIA;
index 565d5b2..129cda7 100644 (file)
@@ -188,7 +188,7 @@ struct wf_smu_sys_fans_state {
 };
 
 /*
- * Configs for SMU Sytem Fan control loop
+ * Configs for SMU System Fan control loop
  */
 static struct wf_smu_sys_fans_param wf_smu_sys_all_params[] = {
        /* Model ID 2 */
index 4dde7d1..195c6cf 100644 (file)
@@ -7,3 +7,62 @@ config VIDEO_IR
        tristate
        depends on IR_CORE
        default IR_CORE
+
+source "drivers/media/IR/keymaps/Kconfig"
+
+config IR_NEC_DECODER
+       tristate "Enable IR raw decoder for the NEC protocol"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          Enable this option if you have IR with NEC protocol, and
+          if the IR is decoded in software
+
+config IR_RC5_DECODER
+       tristate "Enable IR raw decoder for the RC-5 protocol"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          Enable this option if you have IR with RC-5 protocol, and
+          if the IR is decoded in software
+
+config IR_RC6_DECODER
+       tristate "Enable IR raw decoder for the RC6 protocol"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          Enable this option if you have an infrared remote control which
+          uses the RC6 protocol, and you need software decoding support.
+
+config IR_JVC_DECODER
+       tristate "Enable IR raw decoder for the JVC protocol"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          Enable this option if you have an infrared remote control which
+          uses the JVC protocol, and you need software decoding support.
+
+config IR_SONY_DECODER
+       tristate "Enable IR raw decoder for the Sony protocol"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          Enable this option if you have an infrared remote control which
+          uses the Sony protocol, and you need software decoding support.
+
+config IR_IMON
+       tristate "SoundGraph iMON Receiver and Display"
+       depends on USB_ARCH_HAS_HCD
+       depends on IR_CORE
+       select USB
+       ---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.
index 171890e..b998fcc 100644 (file)
@@ -1,5 +1,15 @@
-ir-common-objs  := ir-functions.o ir-keymaps.o
-ir-core-objs   := ir-keytable.o ir-sysfs.o
+ir-common-objs  := ir-functions.o
+ir-core-objs   := ir-keytable.o ir-sysfs.o ir-raw-event.o rc-map.o
+
+obj-y += keymaps/
 
 obj-$(CONFIG_IR_CORE) += ir-core.o
 obj-$(CONFIG_VIDEO_IR) += ir-common.o
+obj-$(CONFIG_IR_NEC_DECODER) += ir-nec-decoder.o
+obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
+obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
+obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o
+obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
+
+# stand-alone IR receivers/transmitters
+obj-$(CONFIG_IR_IMON) += imon.o
diff --git a/drivers/media/IR/imon.c b/drivers/media/IR/imon.c
new file mode 100644 (file)
index 0000000..5e20456
--- /dev/null
@@ -0,0 +1,2396 @@
+/*
+ *   imon.c:   input and display driver for SoundGraph iMON IR/VFD/LCD
+ *
+ *   Copyright(C) 2009  Jarod Wilson <jarod@wilsonet.com>
+ *   Portions based on the original lirc_imon driver,
+ *     Copyright(C) 2004  Venky Raju(dev@venky.ws)
+ *
+ *   Huge thanks to R. Geoff Newbury for invaluable debugging on the
+ *   0xffdc iMON devices, and for sending me one to hack on, without
+ *   which the support for them wouldn't be nearly as good. Thanks
+ *   also to the numerous 0xffdc device owners that tested auto-config
+ *   support for me and provided debug dumps from their devices.
+ *
+ *   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 <linux/errno.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+
+#include <linux/input.h>
+#include <linux/usb.h>
+#include <linux/usb/input.h>
+#include <media/ir-core.h>
+
+#include <linux/time.h>
+#include <linux/timer.h>
+
+#define MOD_AUTHOR     "Jarod Wilson <jarod@wilsonet.com>"
+#define MOD_DESC       "Driver for SoundGraph iMON MultiMedia IR/Display"
+#define MOD_NAME       "imon"
+#define MOD_VERSION    "0.9.1"
+
+#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
+
+/*** 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 ir_dev_props *props;
+       struct ir_input_dev *ir;
+       /* Newer devices have two interfaces */
+       struct usb_device *usbdev_intf0;
+       struct usb_device *usbdev_intf1;
+
+       bool display_supported;         /* not all controllers do */
+       bool display_isopen;            /* display port has been opened */
+       bool rf_isassociating;          /* RF remote associating */
+       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 */
+
+       struct input_dev *idev;         /* input device for remote */
+       struct input_dev *touch;        /* input device for touchscreen */
+
+       u32 kc;                         /* current input keycode */
+       u32 last_keycode;               /* last reported input keycode */
+       u64 ir_type;                    /* iMON or MCE (RC6) IR protocol? */
+       u8 mce_toggle_bit;              /* last mce toggle bit */
+       bool release_code;              /* some keys send a release code */
+
+       u8 display_type;                /* store the display type */
+       bool pad_mouse;                 /* toggle kbd(0)/mouse(1) mode */
+
+       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 */
+       int touch_x;                    /* x coordinate on touchscreen */
+       int touch_y;                    /* y coordinate on touchscreen */
+};
+
+#define TOUCH_TIMEOUT  (HZ/30)
+
+/* 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_KEY_IMON   = 0,
+       IMON_KEY_MCE    = 1,
+       IMON_KEY_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) },
+       {}
+};
+
+/* 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,
+};
+
+/* imon receiver front panel/knob key table */
+static const struct {
+       u64 hw_code;
+       u32 keycode;
+} imon_panel_key_table[] = {
+       { 0x000000000f00ffeell, KEY_PROG1 }, /* Go */
+       { 0x000000001f00ffeell, KEY_AUDIO },
+       { 0x000000002000ffeell, KEY_VIDEO },
+       { 0x000000002100ffeell, KEY_CAMERA },
+       { 0x000000002700ffeell, KEY_DVD },
+       { 0x000000002300ffeell, KEY_TV },
+       { 0x000000000500ffeell, KEY_PREVIOUS },
+       { 0x000000000700ffeell, KEY_REWIND },
+       { 0x000000000400ffeell, KEY_STOP },
+       { 0x000000003c00ffeell, KEY_PLAYPAUSE },
+       { 0x000000000800ffeell, KEY_FASTFORWARD },
+       { 0x000000000600ffeell, KEY_NEXT },
+       { 0x000000010000ffeell, KEY_RIGHT },
+       { 0x000001000000ffeell, KEY_LEFT },
+       { 0x000000003d00ffeell, KEY_SELECT },
+       { 0x000100000000ffeell, KEY_VOLUMEUP },
+       { 0x010000000000ffeell, KEY_VOLUMEDOWN },
+       { 0x000000000100ffeell, KEY_MUTE },
+       /* iMON Knob values */
+       { 0x000100ffffffffeell, KEY_VOLUMEUP },
+       { 0x010000ffffffffeell, KEY_VOLUMEDOWN },
+       { 0x000008ffffffffeell, 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)");
+
+static int pad_stabilize = 1;
+module_param(pad_stabilize, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(pad_stabilize, "Apply stabilization algorithm to iMON PAD "
+                "presses in arrow key mode. 0=disable, 1=enable (default).");
+
+/*
+ * 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;
+       unsigned long timeout;
+       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);
+
+       /*
+        * Induce a mandatory 5ms delay before returning, as otherwise,
+        * send_packet can get called so rapidly as to overwhelm the device,
+        * particularly on faster systems and/or those with quirky usb.
+        */
+       timeout = msecs_to_jiffies(5);
+       set_current_state(TASK_UNINTERRUPTIBLE);
+       schedule_timeout(timeout);
+
+       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->rf_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->rf_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.
+ */
+int imon_ir_change_protocol(void *priv, u64 ir_type)
+{
+       int retval;
+       struct imon_context *ictx = priv;
+       struct device *dev = ictx->dev;
+       bool pad_mouse;
+       unsigned char ir_proto_packet[] = {
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
+
+       if (ir_type && !(ir_type & ictx->props->allowed_protos))
+               dev_warn(dev, "Looks like you're trying to use an IR protocol "
+                        "this device does not support\n");
+
+       switch (ir_type) {
+       case IR_TYPE_RC6:
+               dev_dbg(dev, "Configuring IR receiver for MCE protocol\n");
+               ir_proto_packet[0] = 0x01;
+               pad_mouse = false;
+               init_timer(&ictx->itimer);
+               ictx->itimer.data = (unsigned long)ictx;
+               ictx->itimer.function = imon_mce_timeout;
+               break;
+       case IR_TYPE_UNKNOWN:
+       case IR_TYPE_OTHER:
+               dev_dbg(dev, "Configuring IR receiver for iMON protocol\n");
+               if (pad_stabilize)
+                       pad_mouse = true;
+               else {
+                       dev_dbg(dev, "PAD stabilize functionality disabled\n");
+                       pad_mouse = false;
+               }
+               /* ir_proto_packet[0] = 0x00; // already the default */
+               ir_type = IR_TYPE_OTHER;
+               break;
+       default:
+               dev_warn(dev, "Unsupported IR protocol specified, overriding "
+                        "to iMON IR protocol\n");
+               if (pad_stabilize)
+                       pad_mouse = true;
+               else {
+                       dev_dbg(dev, "PAD stabilize functionality disabled\n");
+                       pad_mouse = false;
+               }
+               /* ir_proto_packet[0] = 0x00; // already the default */
+               ir_type = IR_TYPE_OTHER;
+               break;
+       }
+
+       memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet));
+
+       retval = send_packet(ictx);
+       if (retval)
+               goto out;
+
+       ictx->ir_type = ir_type;
+       ictx->pad_mouse = pad_mouse;
+
+out:
+       return retval;
+}
+
+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 u32 imon_remote_key_lookup(struct imon_context *ictx, u32 hw_code)
+{
+       u32 scancode = be32_to_cpu(hw_code);
+       u32 keycode;
+       u32 release;
+       bool is_release_code = false;
+
+       /* Look for the initial press of a button */
+       keycode = ir_g_keycode_from_table(ictx->idev, scancode);
+
+       /* Look for the release of a button */
+       if (keycode == KEY_RESERVED) {
+               release = scancode & ~0x4000;
+               keycode = ir_g_keycode_from_table(ictx->idev, release);
+               if (keycode != KEY_RESERVED)
+                       is_release_code = true;
+       }
+
+       ictx->release_code = is_release_code;
+
+       return keycode;
+}
+
+static u32 imon_mce_key_lookup(struct imon_context *ictx, u32 hw_code)
+{
+       u32 scancode = be32_to_cpu(hw_code);
+       u32 keycode;
+
+#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 ((scancode >> 24) & 0x80)
+               scancode = scancode | MCE_KEY_MASK | MCE_TOGGLE_BIT;
+
+       keycode = ir_g_keycode_from_table(ictx->idev, scancode);
+
+       return keycode;
+}
+
+static u32 imon_panel_key_lookup(u64 hw_code)
+{
+       int i;
+       u64 code = be64_to_cpu(hw_code);
+       u32 keycode = KEY_RESERVED;
+
+       for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
+               if (imon_panel_key_table[i].hw_code == (code | 0xffee)) {
+                       keycode = imon_panel_key_table[i].keycode;
+                       break;
+               }
+       }
+
+       return keycode;
+}
+
+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 dir = 0;
+       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_type == IR_TYPE_OTHER && pad_stabilize) {
+                       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);
+                               ictx->kc = imon_remote_key_lookup(ictx,
+                                                                 remote_key);
+                       }
+               } 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_type == IR_TYPE_OTHER && pad_stabilize) {
+                       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);
+                       ictx->kc = imon_remote_key_lookup(ictx, remote_key);
+               } 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;
+                       }
+               }
+       }
+}
+
+static int imon_parse_press_type(struct imon_context *ictx,
+                                unsigned char *buf, u8 ktype)
+{
+       int press_type = 0;
+       int rep_delay = ictx->idev->rep[REP_DELAY];
+       int rep_period = ictx->idev->rep[REP_PERIOD];
+
+       /* key release of 0x02XXXXXX key */
+       if (ictx->kc == KEY_RESERVED && buf[0] == 0x02 && buf[3] == 0x00)
+               ictx->kc = ictx->last_keycode;
+
+       /* mouse button release on (some) 0xffdc devices */
+       else if (ictx->kc == KEY_RESERVED && 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->kc == KEY_RESERVED && buf[0] == 0x01 && buf[1] == 0x00 &&
+                buf[2] == 0x81 && buf[3] == 0xb7)
+               ictx->kc = ictx->last_keycode;
+
+       /* mce-specific button handling */
+       else if (ktype == IMON_KEY_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(rep_delay));
+               /* repeat */
+               } else {
+                       press_type = 2;
+                       mod_timer(&ictx->itimer,
+                                 jiffies + msecs_to_jiffies(rep_period));
+               }
+
+       /* incoherent or irrelevant data */
+       } else if (ictx->kc == KEY_RESERVED)
+               press_type = -EINVAL;
+
+       /* key release of 0xXXXXXXb7 key */
+       else if (ictx->release_code)
+               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;
+       u32 kc;
+       bool norelease = 0;
+       int i;
+       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 ktype = IMON_KEY_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) {
+               ktype = IMON_KEY_PANEL;
+               panel_key = le64_to_cpu(temp_key);
+               kc = imon_panel_key_lookup(panel_key);
+       } else {
+               remote_key = (u32) (le64_to_cpu(temp_key) & 0xffffffff);
+               if (ictx->ir_type == IR_TYPE_RC6) {
+                       if (buf[0] == 0x80)
+                               ktype = IMON_KEY_MCE;
+                       kc = imon_mce_key_lookup(ictx, remote_key);
+               } else
+                       kc = imon_remote_key_lookup(ictx, remote_key);
+       }
+
+       /* keyboard/mouse mode toggle button */
+       if (kc == KEY_KEYBOARD && !ictx->release_code) {
+               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->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, ktype);
+       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 || ktype == IMON_KEY_MCE)) {
+               do_gettimeofday(&t);
+               msec = tv2int(&t, &prev_time);
+               prev_time = t;
+               if (msec < idev->rep[REP_DELAY])
+                       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->rf_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;
+       struct ir_dev_props *props;
+       struct ir_input_dev *ir;
+       int ret, i;
+
+       idev = input_allocate_device();
+       if (!idev) {
+               dev_err(ictx->dev, "remote input dev allocation failed\n");
+               goto idev_alloc_failed;
+       }
+
+       props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
+       if (!props) {
+               dev_err(ictx->dev, "remote ir dev props allocation failed\n");
+               goto props_alloc_failed;
+       }
+
+       ir = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
+       if (!ir) {
+               dev_err(ictx->dev, "remote ir input dev allocation failed\n");
+               goto ir_dev_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_REP) | 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);
+
+       /* panel and/or knob code support */
+       for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) {
+               u32 kc = imon_panel_key_table[i].keycode;
+               __set_bit(kc, idev->keybit);
+       }
+
+       props->priv = ictx;
+       props->driver_type = RC_DRIVER_SCANCODE;
+       /* IR_TYPE_OTHER maps to iMON PAD remote, IR_TYPE_RC6 to MCE remote */
+       props->allowed_protos = IR_TYPE_OTHER | IR_TYPE_RC6;
+       props->change_protocol = imon_ir_change_protocol;
+       ictx->props = props;
+
+       ictx->ir = ir;
+       memcpy(&ir->dev, ictx->dev, sizeof(struct device));
+
+       usb_to_input_id(ictx->usbdev_intf0, &idev->id);
+       idev->dev.parent = ictx->dev;
+
+       input_set_drvdata(idev, ir);
+
+       ret = ir_input_register(idev, RC_MAP_IMON_PAD, props, MOD_NAME);
+       if (ret < 0) {
+               dev_err(ictx->dev, "remote input dev register failed\n");
+               goto idev_register_failed;
+       }
+
+       return idev;
+
+idev_register_failed:
+       kfree(ir);
+ir_dev_alloc_failed:
+       kfree(props);
+props_alloc_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);
+
+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 = true;
+
+       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 = -ENOMEM;
+
+       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);
+
+       ret = -ENODEV;
+       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:
+       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 = -ENOMEM;
+
+       rx_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (!rx_urb) {
+               err("%s: usb_alloc_urb failed for IR urb", __func__);
+               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;
+
+       ret = -ENODEV;
+       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;
+}
+
+/*
+ * The 0x15c2:0xffdc device ID was used for umpteen different imon
+ * devices, and all of them constantly spew interrupts, even when there
+ * is no actual data to report. However, byte 6 of this buffer looks like
+ * its unique across device variants, so we're trying to key off that to
+ * figure out which display type (if any) and what IR protocol the device
+ * actually supports. These devices have their IR protocol hard-coded into
+ * their firmware, they can't be changed on the fly like the newer hardware.
+ */
+static void imon_get_ffdc_type(struct imon_context *ictx)
+{
+       u8 ffdc_cfg_byte = ictx->usb_rx_buf[6];
+       u8 detected_display_type = IMON_DISPLAY_TYPE_NONE;
+       u64 allowed_protos = IR_TYPE_OTHER;
+
+       switch (ffdc_cfg_byte) {
+       /* iMON Knob, no display, iMON IR + vol knob */
+       case 0x21:
+               dev_info(ictx->dev, "0xffdc iMON Knob, iMON IR");
+               ictx->display_supported = false;
+               break;
+       /* iMON VFD, no IR (does have vol knob tho) */
+       case 0x35:
+               dev_info(ictx->dev, "0xffdc iMON VFD + knob, no IR");
+               detected_display_type = IMON_DISPLAY_TYPE_VFD;
+               break;
+       /* iMON VFD, iMON IR */
+       case 0x24:
+       case 0x85:
+               dev_info(ictx->dev, "0xffdc iMON VFD, iMON IR");
+               detected_display_type = IMON_DISPLAY_TYPE_VFD;
+               break;
+       /* iMON LCD, MCE IR */
+       case 0x9f:
+               dev_info(ictx->dev, "0xffdc iMON LCD, MCE IR");
+               detected_display_type = IMON_DISPLAY_TYPE_LCD;
+               allowed_protos = IR_TYPE_RC6;
+               break;
+       default:
+               dev_info(ictx->dev, "Unknown 0xffdc device, "
+                        "defaulting to VFD and iMON IR");
+               detected_display_type = IMON_DISPLAY_TYPE_VFD;
+               break;
+       }
+
+       printk(KERN_CONT " (id 0x%02x)\n", ffdc_cfg_byte);
+
+       ictx->display_type = detected_display_type;
+       ictx->props->allowed_protos = allowed_protos;
+       ictx->ir_type = allowed_protos;
+}
+
+static void imon_set_display_type(struct imon_context *ictx,
+                                 struct usb_interface *intf)
+{
+       u8 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) {
+               switch (ictx->product) {
+               case 0xffdc:
+                       /* set in imon_get_ffdc_type() */
+                       configured_display_type = ictx->display_type;
+                       break;
+               case 0x0034:
+               case 0x0035:
+                       configured_display_type = IMON_DISPLAY_TYPE_VGA;
+                       break;
+               case 0x0038:
+               case 0x0039:
+               case 0x0045:
+                       configured_display_type = IMON_DISPLAY_TYPE_LCD;
+                       break;
+               case 0x003c:
+               case 0x0041:
+               case 0x0042:
+               case 0x0043:
+                       configured_display_type = IMON_DISPLAY_TYPE_NONE;
+                       ictx->display_supported = false;
+                       break;
+               case 0x0036:
+               case 0x0044:
+               default:
+                       configured_display_type = IMON_DISPLAY_TYPE_VFD;
+                       break;
+               }
+       } else {
+               configured_display_type = display_type;
+               if (display_type == IMON_DISPLAY_TYPE_NONE)
+                       ictx->display_supported = false;
+               else
+                       ictx->display_supported = true;
+               dev_info(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;
+
+       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");
+
+}
+
+/**
+ * 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;
+       const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00,
+                                           0x00, 0x00, 0x00, 0x88 };
+
+       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;
+               }
+
+               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);
+
+       if (ifnum == 0) {
+               /* 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(dev, "failed to enable panel buttons "
+                                "and/or knobs\n");
+
+               if (product == 0xffdc)
+                       imon_get_ffdc_type(ictx);
+
+               imon_set_display_type(ictx, interface);
+
+               if (ictx->display_supported)
+                       imon_init_display(ictx, interface);
+       }
+
+       /* set IR protocol/remote type */
+       ret = imon_ir_change_protocol(ictx, ictx->ir_type);
+       if (ret) {
+               dev_warn(dev, "%s: failed to set IR protocol, falling back "
+                        "to standard iMON protocol mode\n", __func__);
+               ictx->ir_type = IR_TYPE_OTHER;
+       }
+
+       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);
+               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_type == IR_TYPE_RC6)
+                       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/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h
new file mode 100644 (file)
index 0000000..9a5e65a
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * Remote Controller core raw events header
+ *
+ * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
+ *
+ *  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.
+ */
+
+#ifndef _IR_RAW_EVENT
+#define _IR_RAW_EVENT
+
+#include <linux/slab.h>
+#include <media/ir-core.h>
+
+struct ir_raw_handler {
+       struct list_head list;
+
+       int (*decode)(struct input_dev *input_dev, struct ir_raw_event event);
+       int (*raw_register)(struct input_dev *input_dev);
+       int (*raw_unregister)(struct input_dev *input_dev);
+};
+
+struct ir_raw_event_ctrl {
+       struct work_struct              rx_work;        /* for the rx decoding workqueue */
+       struct kfifo                    kfifo;          /* fifo for the pulse/space durations */
+       ktime_t                         last_event;     /* when last event occurred */
+       enum raw_event_type             last_type;      /* last event type */
+       struct input_dev                *input_dev;     /* pointer to the parent input_dev */
+};
+
+/* macros for IR decoders */
+static inline bool geq_margin(unsigned d1, unsigned d2, unsigned margin)
+{
+       return d1 > (d2 - margin);
+}
+
+static inline bool eq_margin(unsigned d1, unsigned d2, unsigned margin)
+{
+       return ((d1 > (d2 - margin)) && (d1 < (d2 + margin)));
+}
+
+static inline bool is_transition(struct ir_raw_event *x, struct ir_raw_event *y)
+{
+       return x->pulse != y->pulse;
+}
+
+static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration)
+{
+       if (duration > ev->duration)
+               ev->duration = 0;
+       else
+               ev->duration -= duration;
+}
+
+#define TO_US(duration)                        (((duration) + 500) / 1000)
+#define TO_STR(is_pulse)               ((is_pulse) ? "pulse" : "space")
+#define IS_RESET(ev)                   (ev.duration == 0)
+
+/*
+ * Routines from ir-sysfs.c - Meant to be called only internally inside
+ * ir-core
+ */
+
+int ir_register_class(struct input_dev *input_dev);
+void ir_unregister_class(struct input_dev *input_dev);
+
+/*
+ * Routines from ir-raw-event.c to be used internally and by decoders
+ */
+int ir_raw_event_register(struct input_dev *input_dev);
+void ir_raw_event_unregister(struct input_dev *input_dev);
+int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
+void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
+void ir_raw_init(void);
+
+
+/*
+ * Decoder initialization code
+ *
+ * Those load logic are called during ir-core init, and automatically
+ * loads the compiled decoders for their usage with IR raw events
+ */
+
+/* from ir-nec-decoder.c */
+#ifdef CONFIG_IR_NEC_DECODER_MODULE
+#define load_nec_decode()      request_module("ir-nec-decoder")
+#else
+#define load_nec_decode()      0
+#endif
+
+/* from ir-rc5-decoder.c */
+#ifdef CONFIG_IR_RC5_DECODER_MODULE
+#define load_rc5_decode()      request_module("ir-rc5-decoder")
+#else
+#define load_rc5_decode()      0
+#endif
+
+/* from ir-rc6-decoder.c */
+#ifdef CONFIG_IR_RC6_DECODER_MODULE
+#define load_rc6_decode()      request_module("ir-rc6-decoder")
+#else
+#define load_rc6_decode()      0
+#endif
+
+/* from ir-jvc-decoder.c */
+#ifdef CONFIG_IR_JVC_DECODER_MODULE
+#define load_jvc_decode()      request_module("ir-jvc-decoder")
+#else
+#define load_jvc_decode()      0
+#endif
+
+/* from ir-sony-decoder.c */
+#ifdef CONFIG_IR_SONY_DECODER_MODULE
+#define load_sony_decode()     request_module("ir-sony-decoder")
+#else
+#define load_sony_decode()     0
+#endif
+
+#endif /* _IR_RAW_EVENT */
index ab06919..db591e4 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/string.h>
 #include <linux/jiffies.h>
 #include <media/ir-common.h>
+#include "ir-core-priv.h"
 
 /* -------------------------------------------------------------------------- */
 
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c
new file mode 100644 (file)
index 0000000..0b80494
--- /dev/null
@@ -0,0 +1,320 @@
+/* ir-jvc-decoder.c - handle JVC IR Pulse/Space protocol
+ *
+ * Copyright (C) 2010 by David Härdeman <david@hardeman.nu>
+ *
+ * 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 of the License.
+ *
+ * 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.
+ */
+
+#include <linux/bitrev.h>
+#include "ir-core-priv.h"
+
+#define JVC_NBITS              16              /* dev(8) + func(8) */
+#define JVC_UNIT               525000          /* ns */
+#define JVC_HEADER_PULSE       (16 * JVC_UNIT) /* lack of header -> repeat */
+#define JVC_HEADER_SPACE       (8  * JVC_UNIT)
+#define JVC_BIT_PULSE          (1  * JVC_UNIT)
+#define JVC_BIT_0_SPACE                (1  * JVC_UNIT)
+#define JVC_BIT_1_SPACE                (3  * JVC_UNIT)
+#define JVC_TRAILER_PULSE      (1  * JVC_UNIT)
+#define        JVC_TRAILER_SPACE       (35 * JVC_UNIT)
+
+/* Used to register jvc_decoder clients */
+static LIST_HEAD(decoder_list);
+DEFINE_SPINLOCK(decoder_lock);
+
+enum jvc_state {
+       STATE_INACTIVE,
+       STATE_HEADER_SPACE,
+       STATE_BIT_PULSE,
+       STATE_BIT_SPACE,
+       STATE_TRAILER_PULSE,
+       STATE_TRAILER_SPACE,
+};
+
+struct decoder_data {
+       struct list_head        list;
+       struct ir_input_dev     *ir_dev;
+       int                     enabled:1;
+
+       /* State machine control */
+       enum jvc_state          state;
+       u16                     jvc_bits;
+       u16                     jvc_old_bits;
+       unsigned                count;
+       bool                    first;
+       bool                    toggle;
+};
+
+
+/**
+ * get_decoder_data()  - gets decoder data
+ * @input_dev: input device
+ *
+ * Returns the struct decoder_data that corresponds to a device
+ */
+static struct decoder_data *get_decoder_data(struct  ir_input_dev *ir_dev)
+{
+       struct decoder_data *data = NULL;
+
+       spin_lock(&decoder_lock);
+       list_for_each_entry(data, &decoder_list, list) {
+               if (data->ir_dev == ir_dev)
+                       break;
+       }
+       spin_unlock(&decoder_lock);
+       return data;
+}
+
+static ssize_t store_enabled(struct device *d,
+                            struct device_attribute *mattr,
+                            const char *buf,
+                            size_t len)
+{
+       unsigned long value;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (strict_strtoul(buf, 10, &value) || value > 1)
+               return -EINVAL;
+
+       data->enabled = value;
+
+       return len;
+}
+
+static ssize_t show_enabled(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->enabled)
+               return sprintf(buf, "1\n");
+       else
+       return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
+
+static struct attribute *decoder_attributes[] = {
+       &dev_attr_enabled.attr,
+       NULL
+};
+
+static struct attribute_group decoder_attribute_group = {
+       .name   = "jvc_decoder",
+       .attrs  = decoder_attributes,
+};
+
+/**
+ * ir_jvc_decode() - Decode one JVC pulse or space
+ * @input_dev: the struct input_dev descriptor of the device
+ * @duration:   the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
+{
+       struct decoder_data *data;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return -EINVAL;
+
+       if (!data->enabled)
+               return 0;
+
+       if (IS_RESET(ev)) {
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       if (!geq_margin(ev.duration, JVC_UNIT, JVC_UNIT / 2))
+               goto out;
+
+       IR_dprintk(2, "JVC decode started at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+
+       switch (data->state) {
+
+       case STATE_INACTIVE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, JVC_HEADER_PULSE, JVC_UNIT / 2))
+                       break;
+
+               data->count = 0;
+               data->first = true;
+               data->toggle = !data->toggle;
+               data->state = STATE_HEADER_SPACE;
+               return 0;
+
+       case STATE_HEADER_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, JVC_HEADER_SPACE, JVC_UNIT / 2))
+                       break;
+
+               data->state = STATE_BIT_PULSE;
+               return 0;
+
+       case STATE_BIT_PULSE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, JVC_BIT_PULSE, JVC_UNIT / 2))
+                       break;
+
+               data->state = STATE_BIT_SPACE;
+               return 0;
+
+       case STATE_BIT_SPACE:
+               if (ev.pulse)
+                       break;
+
+               data->jvc_bits <<= 1;
+               if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) {
+                       data->jvc_bits |= 1;
+                       decrease_duration(&ev, JVC_BIT_1_SPACE);
+               } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2))
+                       decrease_duration(&ev, JVC_BIT_0_SPACE);
+               else
+                       break;
+               data->count++;
+
+               if (data->count == JVC_NBITS)
+                       data->state = STATE_TRAILER_PULSE;
+               else
+                       data->state = STATE_BIT_PULSE;
+               return 0;
+
+       case STATE_TRAILER_PULSE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, JVC_TRAILER_PULSE, JVC_UNIT / 2))
+                       break;
+
+               data->state = STATE_TRAILER_SPACE;
+               return 0;
+
+       case STATE_TRAILER_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!geq_margin(ev.duration, JVC_TRAILER_SPACE, JVC_UNIT / 2))
+                       break;
+
+               if (data->first) {
+                       u32 scancode;
+                       scancode = (bitrev8((data->jvc_bits >> 8) & 0xff) << 8) |
+                                  (bitrev8((data->jvc_bits >> 0) & 0xff) << 0);
+                       IR_dprintk(1, "JVC scancode 0x%04x\n", scancode);
+                       ir_keydown(input_dev, scancode, data->toggle);
+                       data->first = false;
+                       data->jvc_old_bits = data->jvc_bits;
+               } else if (data->jvc_bits == data->jvc_old_bits) {
+                       IR_dprintk(1, "JVC repeat\n");
+                       ir_repeat(input_dev);
+               } else {
+                       IR_dprintk(1, "JVC invalid repeat msg\n");
+                       break;
+               }
+
+               data->count = 0;
+               data->state = STATE_BIT_PULSE;
+               return 0;
+       }
+
+out:
+       IR_dprintk(1, "JVC decode failed at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+       data->state = STATE_INACTIVE;
+       return -EINVAL;
+}
+
+static int ir_jvc_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       struct decoder_data *data;
+       int rc;
+
+       rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+       if (rc < 0)
+               return rc;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+               return -ENOMEM;
+       }
+
+       data->ir_dev = ir_dev;
+       data->enabled = 1;
+
+       spin_lock(&decoder_lock);
+       list_add_tail(&data->list, &decoder_list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static int ir_jvc_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       static struct decoder_data *data;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return 0;
+
+       sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+
+       spin_lock(&decoder_lock);
+       list_del(&data->list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static struct ir_raw_handler jvc_handler = {
+       .decode         = ir_jvc_decode,
+       .raw_register   = ir_jvc_register,
+       .raw_unregister = ir_jvc_unregister,
+};
+
+static int __init ir_jvc_decode_init(void)
+{
+       ir_raw_handler_register(&jvc_handler);
+
+       printk(KERN_INFO "IR JVC protocol handler initialized\n");
+       return 0;
+}
+
+static void __exit ir_jvc_decode_exit(void)
+{
+       ir_raw_handler_unregister(&jvc_handler);
+}
+
+module_init(ir_jvc_decode_init);
+module_exit(ir_jvc_decode_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
+MODULE_DESCRIPTION("JVC IR protocol decoder");
diff --git a/drivers/media/IR/ir-keymaps.c b/drivers/media/IR/ir-keymaps.c
deleted file mode 100644 (file)
index 0efdefe..0000000
+++ /dev/null
@@ -1,3494 +0,0 @@
-/*
-    Keytables for supported remote controls, used on drivers/media
-    devices.
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-/*
- * NOTICE FOR DEVELOPERS:
- *   The IR mappings should be as close as possible to what's
- *   specified at:
- *      http://linuxtv.org/wiki/index.php/Remote_Controllers
- */
-#include <linux/module.h>
-
-#include <linux/input.h>
-#include <media/ir-common.h>
-
-/* empty keytable, can be used as placeholder for not-yet created keytables */
-static struct ir_scancode ir_codes_empty[] = {
-       { 0x2a, KEY_COFFEE },
-};
-
-struct ir_scancode_table ir_codes_empty_table = {
-       .scan = ir_codes_empty,
-       .size = ARRAY_SIZE(ir_codes_empty),
-};
-EXPORT_SYMBOL_GPL(ir_codes_empty_table);
-
-/* Michal Majchrowicz <mmajchrowicz@gmail.com> */
-static struct ir_scancode ir_codes_proteus_2309[] = {
-       /* numeric */
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x5c, KEY_POWER },            /* power       */
-       { 0x20, KEY_ZOOM },             /* full screen */
-       { 0x0f, KEY_BACKSPACE },        /* recall      */
-       { 0x1b, KEY_ENTER },            /* mute        */
-       { 0x41, KEY_RECORD },           /* record      */
-       { 0x43, KEY_STOP },             /* stop        */
-       { 0x16, KEY_S },
-       { 0x1a, KEY_POWER2 },           /* off         */
-       { 0x2e, KEY_RED },
-       { 0x1f, KEY_CHANNELDOWN },      /* channel -   */
-       { 0x1c, KEY_CHANNELUP },        /* channel +   */
-       { 0x10, KEY_VOLUMEDOWN },       /* volume -    */
-       { 0x1e, KEY_VOLUMEUP },         /* volume +    */
-       { 0x14, KEY_F1 },
-};
-
-struct ir_scancode_table ir_codes_proteus_2309_table = {
-       .scan = ir_codes_proteus_2309,
-       .size = ARRAY_SIZE(ir_codes_proteus_2309),
-};
-EXPORT_SYMBOL_GPL(ir_codes_proteus_2309_table);
-
-/* Matt Jesson <dvb@jesson.eclipse.co.uk */
-static struct ir_scancode ir_codes_avermedia_dvbt[] = {
-       { 0x28, KEY_0 },                /* '0' / 'enter' */
-       { 0x22, KEY_1 },                /* '1' */
-       { 0x12, KEY_2 },                /* '2' / 'up arrow' */
-       { 0x32, KEY_3 },                /* '3' */
-       { 0x24, KEY_4 },                /* '4' / 'left arrow' */
-       { 0x14, KEY_5 },                /* '5' */
-       { 0x34, KEY_6 },                /* '6' / 'right arrow' */
-       { 0x26, KEY_7 },                /* '7' */
-       { 0x16, KEY_8 },                /* '8' / 'down arrow' */
-       { 0x36, KEY_9 },                /* '9' */
-
-       { 0x20, KEY_LIST },             /* 'source' */
-       { 0x10, KEY_TEXT },             /* 'teletext' */
-       { 0x00, KEY_POWER },            /* 'power' */
-       { 0x04, KEY_AUDIO },            /* 'audio' */
-       { 0x06, KEY_ZOOM },             /* 'full screen' */
-       { 0x18, KEY_VIDEO },            /* 'display' */
-       { 0x38, KEY_SEARCH },           /* 'loop' */
-       { 0x08, KEY_INFO },             /* 'preview' */
-       { 0x2a, KEY_REWIND },           /* 'backward <<' */
-       { 0x1a, KEY_FASTFORWARD },      /* 'forward >>' */
-       { 0x3a, KEY_RECORD },           /* 'capture' */
-       { 0x0a, KEY_MUTE },             /* 'mute' */
-       { 0x2c, KEY_RECORD },           /* 'record' */
-       { 0x1c, KEY_PAUSE },            /* 'pause' */
-       { 0x3c, KEY_STOP },             /* 'stop' */
-       { 0x0c, KEY_PLAY },             /* 'play' */
-       { 0x2e, KEY_RED },              /* 'red' */
-       { 0x01, KEY_BLUE },             /* 'blue' / 'cancel' */
-       { 0x0e, KEY_YELLOW },           /* 'yellow' / 'ok' */
-       { 0x21, KEY_GREEN },            /* 'green' */
-       { 0x11, KEY_CHANNELDOWN },      /* 'channel -' */
-       { 0x31, KEY_CHANNELUP },        /* 'channel +' */
-       { 0x1e, KEY_VOLUMEDOWN },       /* 'volume -' */
-       { 0x3e, KEY_VOLUMEUP },         /* 'volume +' */
-};
-
-struct ir_scancode_table ir_codes_avermedia_dvbt_table = {
-       .scan = ir_codes_avermedia_dvbt,
-       .size = ARRAY_SIZE(ir_codes_avermedia_dvbt),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avermedia_dvbt_table);
-
-/* Mauro Carvalho Chehab <mchehab@infradead.org> */
-static struct ir_scancode ir_codes_avermedia_m135a[] = {
-       { 0x00, KEY_POWER2 },
-       { 0x2e, KEY_DOT },              /* '.' */
-       { 0x01, KEY_MODE },             /* TV/FM */
-
-       { 0x05, KEY_1 },
-       { 0x06, KEY_2 },
-       { 0x07, KEY_3 },
-       { 0x09, KEY_4 },
-       { 0x0a, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x0d, KEY_7 },
-       { 0x0e, KEY_8 },
-       { 0x0f, KEY_9 },
-       { 0x11, KEY_0 },
-
-       { 0x13, KEY_RIGHT },            /* -> */
-       { 0x12, KEY_LEFT },             /* <- */
-
-       { 0x17, KEY_SLEEP },            /* Capturar Imagem */
-       { 0x10, KEY_SHUFFLE },          /* Amostra */
-
-       /* FIXME: The keys bellow aren't ok */
-
-       { 0x43, KEY_CHANNELUP },
-       { 0x42, KEY_CHANNELDOWN },
-       { 0x1f, KEY_VOLUMEUP },
-       { 0x1e, KEY_VOLUMEDOWN },
-       { 0x0c, KEY_ENTER },
-
-       { 0x14, KEY_MUTE },
-       { 0x08, KEY_AUDIO },
-
-       { 0x03, KEY_TEXT },
-       { 0x04, KEY_EPG },
-       { 0x2b, KEY_TV2 },              /* TV2 */
-
-       { 0x1d, KEY_RED },
-       { 0x1c, KEY_YELLOW },
-       { 0x41, KEY_GREEN },
-       { 0x40, KEY_BLUE },
-
-       { 0x1a, KEY_PLAYPAUSE },
-       { 0x19, KEY_RECORD },
-       { 0x18, KEY_PLAY },
-       { 0x1b, KEY_STOP },
-};
-
-struct ir_scancode_table ir_codes_avermedia_m135a_table = {
-       .scan = ir_codes_avermedia_m135a,
-       .size = ARRAY_SIZE(ir_codes_avermedia_m135a),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avermedia_m135a_table);
-
-/* Oldrich Jedlicka <oldium.pro@seznam.cz> */
-static struct ir_scancode ir_codes_avermedia_cardbus[] = {
-       { 0x00, KEY_POWER },
-       { 0x01, KEY_TUNER },            /* TV/FM */
-       { 0x03, KEY_TEXT },             /* Teletext */
-       { 0x04, KEY_EPG },
-       { 0x05, KEY_1 },
-       { 0x06, KEY_2 },
-       { 0x07, KEY_3 },
-       { 0x08, KEY_AUDIO },
-       { 0x09, KEY_4 },
-       { 0x0a, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x0c, KEY_ZOOM },             /* Full screen */
-       { 0x0d, KEY_7 },
-       { 0x0e, KEY_8 },
-       { 0x0f, KEY_9 },
-       { 0x10, KEY_PAGEUP },           /* 16-CH PREV */
-       { 0x11, KEY_0 },
-       { 0x12, KEY_INFO },
-       { 0x13, KEY_AGAIN },            /* CH RTN - channel return */
-       { 0x14, KEY_MUTE },
-       { 0x15, KEY_EDIT },             /* Autoscan */
-       { 0x17, KEY_SAVE },             /* Screenshot */
-       { 0x18, KEY_PLAYPAUSE },
-       { 0x19, KEY_RECORD },
-       { 0x1a, KEY_PLAY },
-       { 0x1b, KEY_STOP },
-       { 0x1c, KEY_FASTFORWARD },
-       { 0x1d, KEY_REWIND },
-       { 0x1e, KEY_VOLUMEDOWN },
-       { 0x1f, KEY_VOLUMEUP },
-       { 0x22, KEY_SLEEP },            /* Sleep */
-       { 0x23, KEY_ZOOM },             /* Aspect */
-       { 0x26, KEY_SCREEN },           /* Pos */
-       { 0x27, KEY_ANGLE },            /* Size */
-       { 0x28, KEY_SELECT },           /* Select */
-       { 0x29, KEY_BLUE },             /* Blue/Picture */
-       { 0x2a, KEY_BACKSPACE },        /* Back */
-       { 0x2b, KEY_MEDIA },            /* PIP (Picture-in-picture) */
-       { 0x2c, KEY_DOWN },
-       { 0x2e, KEY_DOT },
-       { 0x2f, KEY_TV },               /* Live TV */
-       { 0x32, KEY_LEFT },
-       { 0x33, KEY_CLEAR },            /* Clear */
-       { 0x35, KEY_RED },              /* Red/TV */
-       { 0x36, KEY_UP },
-       { 0x37, KEY_HOME },             /* Home */
-       { 0x39, KEY_GREEN },            /* Green/Video */
-       { 0x3d, KEY_YELLOW },           /* Yellow/Music */
-       { 0x3e, KEY_OK },               /* Ok */
-       { 0x3f, KEY_RIGHT },
-       { 0x40, KEY_NEXT },             /* Next */
-       { 0x41, KEY_PREVIOUS },         /* Previous */
-       { 0x42, KEY_CHANNELDOWN },      /* Channel down */
-       { 0x43, KEY_CHANNELUP },        /* Channel up */
-};
-
-struct ir_scancode_table ir_codes_avermedia_cardbus_table = {
-       .scan = ir_codes_avermedia_cardbus,
-       .size = ARRAY_SIZE(ir_codes_avermedia_cardbus),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avermedia_cardbus_table);
-
-/* Attila Kondoros <attila.kondoros@chello.hu> */
-static struct ir_scancode ir_codes_apac_viewcomp[] = {
-
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-       { 0x00, KEY_0 },
-       { 0x17, KEY_LAST },             /* +100 */
-       { 0x0a, KEY_LIST },             /* recall */
-
-
-       { 0x1c, KEY_TUNER },            /* TV/FM */
-       { 0x15, KEY_SEARCH },           /* scan */
-       { 0x12, KEY_POWER },            /* power */
-       { 0x1f, KEY_VOLUMEDOWN },       /* vol up */
-       { 0x1b, KEY_VOLUMEUP },         /* vol down */
-       { 0x1e, KEY_CHANNELDOWN },      /* chn up */
-       { 0x1a, KEY_CHANNELUP },        /* chn down */
-
-       { 0x11, KEY_VIDEO },            /* video */
-       { 0x0f, KEY_ZOOM },             /* full screen */
-       { 0x13, KEY_MUTE },             /* mute/unmute */
-       { 0x10, KEY_TEXT },             /* min */
-
-       { 0x0d, KEY_STOP },             /* freeze */
-       { 0x0e, KEY_RECORD },           /* record */
-       { 0x1d, KEY_PLAYPAUSE },        /* stop */
-       { 0x19, KEY_PLAY },             /* play */
-
-       { 0x16, KEY_GOTO },             /* osd */
-       { 0x14, KEY_REFRESH },          /* default */
-       { 0x0c, KEY_KPPLUS },           /* fine tune >>>> */
-       { 0x18, KEY_KPMINUS },          /* fine tune <<<< */
-};
-
-struct ir_scancode_table ir_codes_apac_viewcomp_table = {
-       .scan = ir_codes_apac_viewcomp,
-       .size = ARRAY_SIZE(ir_codes_apac_viewcomp),
-};
-EXPORT_SYMBOL_GPL(ir_codes_apac_viewcomp_table);
-
-/* ---------------------------------------------------------------------- */
-
-static struct ir_scancode ir_codes_pixelview[] = {
-
-       { 0x1e, KEY_POWER },    /* power */
-       { 0x07, KEY_MEDIA },    /* source */
-       { 0x1c, KEY_SEARCH },   /* scan */
-
-
-       { 0x03, KEY_TUNER },            /* TV/FM */
-
-       { 0x00, KEY_RECORD },
-       { 0x08, KEY_STOP },
-       { 0x11, KEY_PLAY },
-
-       { 0x1a, KEY_PLAYPAUSE },        /* freeze */
-       { 0x19, KEY_ZOOM },             /* zoom */
-       { 0x0f, KEY_TEXT },             /* min */
-
-       { 0x01, KEY_1 },
-       { 0x0b, KEY_2 },
-       { 0x1b, KEY_3 },
-       { 0x05, KEY_4 },
-       { 0x09, KEY_5 },
-       { 0x15, KEY_6 },
-       { 0x06, KEY_7 },
-       { 0x0a, KEY_8 },
-       { 0x12, KEY_9 },
-       { 0x02, KEY_0 },
-       { 0x10, KEY_LAST },             /* +100 */
-       { 0x13, KEY_LIST },             /* recall */
-
-       { 0x1f, KEY_CHANNELUP },        /* chn down */
-       { 0x17, KEY_CHANNELDOWN },      /* chn up */
-       { 0x16, KEY_VOLUMEUP },         /* vol down */
-       { 0x14, KEY_VOLUMEDOWN },       /* vol up */
-
-       { 0x04, KEY_KPMINUS },          /* <<< */
-       { 0x0e, KEY_SETUP },            /* function */
-       { 0x0c, KEY_KPPLUS },           /* >>> */
-
-       { 0x0d, KEY_GOTO },             /* mts */
-       { 0x1d, KEY_REFRESH },          /* reset */
-       { 0x18, KEY_MUTE },             /* mute/unmute */
-};
-
-struct ir_scancode_table ir_codes_pixelview_table = {
-       .scan = ir_codes_pixelview,
-       .size = ARRAY_SIZE(ir_codes_pixelview),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pixelview_table);
-
-/*
-   Mauro Carvalho Chehab <mchehab@infradead.org>
-   present on PV MPEG 8000GT
- */
-static struct ir_scancode ir_codes_pixelview_new[] = {
-       { 0x3c, KEY_TIME },             /* Timeshift */
-       { 0x12, KEY_POWER },
-
-       { 0x3d, KEY_1 },
-       { 0x38, KEY_2 },
-       { 0x18, KEY_3 },
-       { 0x35, KEY_4 },
-       { 0x39, KEY_5 },
-       { 0x15, KEY_6 },
-       { 0x36, KEY_7 },
-       { 0x3a, KEY_8 },
-       { 0x1e, KEY_9 },
-       { 0x3e, KEY_0 },
-
-       { 0x1c, KEY_AGAIN },            /* LOOP */
-       { 0x3f, KEY_MEDIA },            /* Source */
-       { 0x1f, KEY_LAST },             /* +100 */
-       { 0x1b, KEY_MUTE },
-
-       { 0x17, KEY_CHANNELDOWN },
-       { 0x16, KEY_CHANNELUP },
-       { 0x10, KEY_VOLUMEUP },
-       { 0x14, KEY_VOLUMEDOWN },
-       { 0x13, KEY_ZOOM },
-
-       { 0x19, KEY_CAMERA },           /* SNAPSHOT */
-       { 0x1a, KEY_SEARCH },           /* scan */
-
-       { 0x37, KEY_REWIND },           /* << */
-       { 0x32, KEY_RECORD },           /* o (red) */
-       { 0x33, KEY_FORWARD },          /* >> */
-       { 0x11, KEY_STOP },             /* square */
-       { 0x3b, KEY_PLAY },             /* > */
-       { 0x30, KEY_PLAYPAUSE },        /* || */
-
-       { 0x31, KEY_TV },
-       { 0x34, KEY_RADIO },
-};
-
-struct ir_scancode_table ir_codes_pixelview_new_table = {
-       .scan = ir_codes_pixelview_new,
-       .size = ARRAY_SIZE(ir_codes_pixelview_new),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pixelview_new_table);
-
-static struct ir_scancode ir_codes_nebula[] = {
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-       { 0x0a, KEY_TV },
-       { 0x0b, KEY_AUX },
-       { 0x0c, KEY_DVD },
-       { 0x0d, KEY_POWER },
-       { 0x0e, KEY_MHP },      /* labelled 'Picture' */
-       { 0x0f, KEY_AUDIO },
-       { 0x10, KEY_INFO },
-       { 0x11, KEY_F13 },      /* 16:9 */
-       { 0x12, KEY_F14 },      /* 14:9 */
-       { 0x13, KEY_EPG },
-       { 0x14, KEY_EXIT },
-       { 0x15, KEY_MENU },
-       { 0x16, KEY_UP },
-       { 0x17, KEY_DOWN },
-       { 0x18, KEY_LEFT },
-       { 0x19, KEY_RIGHT },
-       { 0x1a, KEY_ENTER },
-       { 0x1b, KEY_CHANNELUP },
-       { 0x1c, KEY_CHANNELDOWN },
-       { 0x1d, KEY_VOLUMEUP },
-       { 0x1e, KEY_VOLUMEDOWN },
-       { 0x1f, KEY_RED },
-       { 0x20, KEY_GREEN },
-       { 0x21, KEY_YELLOW },
-       { 0x22, KEY_BLUE },
-       { 0x23, KEY_SUBTITLE },
-       { 0x24, KEY_F15 },      /* AD */
-       { 0x25, KEY_TEXT },
-       { 0x26, KEY_MUTE },
-       { 0x27, KEY_REWIND },
-       { 0x28, KEY_STOP },
-       { 0x29, KEY_PLAY },
-       { 0x2a, KEY_FASTFORWARD },
-       { 0x2b, KEY_F16 },      /* chapter */
-       { 0x2c, KEY_PAUSE },
-       { 0x2d, KEY_PLAY },
-       { 0x2e, KEY_RECORD },
-       { 0x2f, KEY_F17 },      /* picture in picture */
-       { 0x30, KEY_KPPLUS },   /* zoom in */
-       { 0x31, KEY_KPMINUS },  /* zoom out */
-       { 0x32, KEY_F18 },      /* capture */
-       { 0x33, KEY_F19 },      /* web */
-       { 0x34, KEY_EMAIL },
-       { 0x35, KEY_PHONE },
-       { 0x36, KEY_PC },
-};
-
-struct ir_scancode_table ir_codes_nebula_table = {
-       .scan = ir_codes_nebula,
-       .size = ARRAY_SIZE(ir_codes_nebula),
-};
-EXPORT_SYMBOL_GPL(ir_codes_nebula_table);
-
-/* DigitalNow DNTV Live DVB-T Remote */
-static struct ir_scancode ir_codes_dntv_live_dvb_t[] = {
-       { 0x00, KEY_ESC },              /* 'go up a level?' */
-       /* Keys 0 to 9 */
-       { 0x0a, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0b, KEY_TUNER },            /* tv/fm */
-       { 0x0c, KEY_SEARCH },           /* scan */
-       { 0x0d, KEY_STOP },
-       { 0x0e, KEY_PAUSE },
-       { 0x0f, KEY_LIST },             /* source */
-
-       { 0x10, KEY_MUTE },
-       { 0x11, KEY_REWIND },           /* backward << */
-       { 0x12, KEY_POWER },
-       { 0x13, KEY_CAMERA },           /* snap */
-       { 0x14, KEY_AUDIO },            /* stereo */
-       { 0x15, KEY_CLEAR },            /* reset */
-       { 0x16, KEY_PLAY },
-       { 0x17, KEY_ENTER },
-       { 0x18, KEY_ZOOM },             /* full screen */
-       { 0x19, KEY_FASTFORWARD },      /* forward >> */
-       { 0x1a, KEY_CHANNELUP },
-       { 0x1b, KEY_VOLUMEUP },
-       { 0x1c, KEY_INFO },             /* preview */
-       { 0x1d, KEY_RECORD },           /* record */
-       { 0x1e, KEY_CHANNELDOWN },
-       { 0x1f, KEY_VOLUMEDOWN },
-};
-
-struct ir_scancode_table ir_codes_dntv_live_dvb_t_table = {
-       .scan = ir_codes_dntv_live_dvb_t,
-       .size = ARRAY_SIZE(ir_codes_dntv_live_dvb_t),
-};
-EXPORT_SYMBOL_GPL(ir_codes_dntv_live_dvb_t_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* IO-DATA BCTV7E Remote */
-static struct ir_scancode ir_codes_iodata_bctv7e[] = {
-       { 0x40, KEY_TV },
-       { 0x20, KEY_RADIO },            /* FM */
-       { 0x60, KEY_EPG },
-       { 0x00, KEY_POWER },
-
-       /* Keys 0 to 9 */
-       { 0x44, KEY_0 },                /* 10 */
-       { 0x50, KEY_1 },
-       { 0x30, KEY_2 },
-       { 0x70, KEY_3 },
-       { 0x48, KEY_4 },
-       { 0x28, KEY_5 },
-       { 0x68, KEY_6 },
-       { 0x58, KEY_7 },
-       { 0x38, KEY_8 },
-       { 0x78, KEY_9 },
-
-       { 0x10, KEY_L },                /* Live */
-       { 0x08, KEY_TIME },             /* Time Shift */
-
-       { 0x18, KEY_PLAYPAUSE },        /* Play */
-
-       { 0x24, KEY_ENTER },            /* 11 */
-       { 0x64, KEY_ESC },              /* 12 */
-       { 0x04, KEY_M },                /* Multi */
-
-       { 0x54, KEY_VIDEO },
-       { 0x34, KEY_CHANNELUP },
-       { 0x74, KEY_VOLUMEUP },
-       { 0x14, KEY_MUTE },
-
-       { 0x4c, KEY_VCR },              /* SVIDEO */
-       { 0x2c, KEY_CHANNELDOWN },
-       { 0x6c, KEY_VOLUMEDOWN },
-       { 0x0c, KEY_ZOOM },
-
-       { 0x5c, KEY_PAUSE },
-       { 0x3c, KEY_RED },              /* || (red) */
-       { 0x7c, KEY_RECORD },           /* recording */
-       { 0x1c, KEY_STOP },
-
-       { 0x41, KEY_REWIND },           /* backward << */
-       { 0x21, KEY_PLAY },
-       { 0x61, KEY_FASTFORWARD },      /* forward >> */
-       { 0x01, KEY_NEXT },             /* skip >| */
-};
-
-struct ir_scancode_table ir_codes_iodata_bctv7e_table = {
-       .scan = ir_codes_iodata_bctv7e,
-       .size = ARRAY_SIZE(ir_codes_iodata_bctv7e),
-};
-EXPORT_SYMBOL_GPL(ir_codes_iodata_bctv7e_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* ADS Tech Instant TV DVB-T PCI Remote */
-static struct ir_scancode ir_codes_adstech_dvb_t_pci[] = {
-       /* Keys 0 to 9 */
-       { 0x4d, KEY_0 },
-       { 0x57, KEY_1 },
-       { 0x4f, KEY_2 },
-       { 0x53, KEY_3 },
-       { 0x56, KEY_4 },
-       { 0x4e, KEY_5 },
-       { 0x5e, KEY_6 },
-       { 0x54, KEY_7 },
-       { 0x4c, KEY_8 },
-       { 0x5c, KEY_9 },
-
-       { 0x5b, KEY_POWER },
-       { 0x5f, KEY_MUTE },
-       { 0x55, KEY_GOTO },
-       { 0x5d, KEY_SEARCH },
-       { 0x17, KEY_EPG },              /* Guide */
-       { 0x1f, KEY_MENU },
-       { 0x0f, KEY_UP },
-       { 0x46, KEY_DOWN },
-       { 0x16, KEY_LEFT },
-       { 0x1e, KEY_RIGHT },
-       { 0x0e, KEY_SELECT },           /* Enter */
-       { 0x5a, KEY_INFO },
-       { 0x52, KEY_EXIT },
-       { 0x59, KEY_PREVIOUS },
-       { 0x51, KEY_NEXT },
-       { 0x58, KEY_REWIND },
-       { 0x50, KEY_FORWARD },
-       { 0x44, KEY_PLAYPAUSE },
-       { 0x07, KEY_STOP },
-       { 0x1b, KEY_RECORD },
-       { 0x13, KEY_TUNER },            /* Live */
-       { 0x0a, KEY_A },
-       { 0x12, KEY_B },
-       { 0x03, KEY_PROG1 },            /* 1 */
-       { 0x01, KEY_PROG2 },            /* 2 */
-       { 0x00, KEY_PROG3 },            /* 3 */
-       { 0x06, KEY_DVD },
-       { 0x48, KEY_AUX },              /* Photo */
-       { 0x40, KEY_VIDEO },
-       { 0x19, KEY_AUDIO },            /* Music */
-       { 0x0b, KEY_CHANNELUP },
-       { 0x08, KEY_CHANNELDOWN },
-       { 0x15, KEY_VOLUMEUP },
-       { 0x1c, KEY_VOLUMEDOWN },
-};
-
-struct ir_scancode_table ir_codes_adstech_dvb_t_pci_table = {
-       .scan = ir_codes_adstech_dvb_t_pci,
-       .size = ARRAY_SIZE(ir_codes_adstech_dvb_t_pci),
-};
-EXPORT_SYMBOL_GPL(ir_codes_adstech_dvb_t_pci_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* MSI TV@nywhere MASTER remote */
-
-static struct ir_scancode ir_codes_msi_tvanywhere[] = {
-       /* Keys 0 to 9 */
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0c, KEY_MUTE },
-       { 0x0f, KEY_SCREEN },           /* Full Screen */
-       { 0x10, KEY_FN },               /* Funtion */
-       { 0x11, KEY_TIME },             /* Time shift */
-       { 0x12, KEY_POWER },
-       { 0x13, KEY_MEDIA },            /* MTS */
-       { 0x14, KEY_SLOW },
-       { 0x16, KEY_REWIND },           /* backward << */
-       { 0x17, KEY_ENTER },            /* Return */
-       { 0x18, KEY_FASTFORWARD },      /* forward >> */
-       { 0x1a, KEY_CHANNELUP },
-       { 0x1b, KEY_VOLUMEUP },
-       { 0x1e, KEY_CHANNELDOWN },
-       { 0x1f, KEY_VOLUMEDOWN },
-};
-
-struct ir_scancode_table ir_codes_msi_tvanywhere_table = {
-       .scan = ir_codes_msi_tvanywhere,
-       .size = ARRAY_SIZE(ir_codes_msi_tvanywhere),
-};
-EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere_table);
-
-/* ---------------------------------------------------------------------- */
-
-/*
-  Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card
-  is marked "KS003". The controller is I2C at address 0x30, but does not seem
-  to respond to probes until a read is performed from a valid device.
-  I don't know why...
-
-  Note: This remote may be of similar or identical design to the
-  Pixelview remote (?).  The raw codes and duplicate button codes
-  appear to be the same.
-
-  Henry Wong <henry@stuffedcow.net>
-  Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com>
-
-*/
-
-static struct ir_scancode ir_codes_msi_tvanywhere_plus[] = {
-
-/*  ---- Remote Button Layout ----
-
-    POWER   SOURCE  SCAN    MUTE
-    TV/FM   1       2       3
-    |>      4       5       6
-    <|      7       8       9
-    ^^UP    0       +       RECALL
-    vvDN    RECORD  STOP    PLAY
-
-       MINIMIZE          ZOOM
-
-                 CH+
-      VOL-                   VOL+
-                 CH-
-
-       SNAPSHOT           MTS
-
-     <<      FUNC    >>     RESET
-*/
-
-       { 0x01, KEY_1 },                /* 1 */
-       { 0x0b, KEY_2 },                /* 2 */
-       { 0x1b, KEY_3 },                /* 3 */
-       { 0x05, KEY_4 },                /* 4 */
-       { 0x09, KEY_5 },                /* 5 */
-       { 0x15, KEY_6 },                /* 6 */
-       { 0x06, KEY_7 },                /* 7 */
-       { 0x0a, KEY_8 },                /* 8 */
-       { 0x12, KEY_9 },                /* 9 */
-       { 0x02, KEY_0 },                /* 0 */
-       { 0x10, KEY_KPPLUS },           /* + */
-       { 0x13, KEY_AGAIN },            /* Recall */
-
-       { 0x1e, KEY_POWER },            /* Power */
-       { 0x07, KEY_TUNER },            /* Source */
-       { 0x1c, KEY_SEARCH },           /* Scan */
-       { 0x18, KEY_MUTE },             /* Mute */
-
-       { 0x03, KEY_RADIO },            /* TV/FM */
-       /* The next four keys are duplicates that appear to send the
-          same IR code as Ch+, Ch-, >>, and << .  The raw code assigned
-          to them is the actual code + 0x20 - they will never be
-          detected as such unless some way is discovered to distinguish
-          these buttons from those that have the same code. */
-       { 0x3f, KEY_RIGHT },            /* |> and Ch+ */
-       { 0x37, KEY_LEFT },             /* <| and Ch- */
-       { 0x2c, KEY_UP },               /* ^^Up and >> */
-       { 0x24, KEY_DOWN },             /* vvDn and << */
-
-       { 0x00, KEY_RECORD },           /* Record */
-       { 0x08, KEY_STOP },             /* Stop */
-       { 0x11, KEY_PLAY },             /* Play */
-
-       { 0x0f, KEY_CLOSE },            /* Minimize */
-       { 0x19, KEY_ZOOM },             /* Zoom */
-       { 0x1a, KEY_CAMERA },           /* Snapshot */
-       { 0x0d, KEY_LANGUAGE },         /* MTS */
-
-       { 0x14, KEY_VOLUMEDOWN },       /* Vol- */
-       { 0x16, KEY_VOLUMEUP },         /* Vol+ */
-       { 0x17, KEY_CHANNELDOWN },      /* Ch- */
-       { 0x1f, KEY_CHANNELUP },        /* Ch+ */
-
-       { 0x04, KEY_REWIND },           /* << */
-       { 0x0e, KEY_MENU },             /* Function */
-       { 0x0c, KEY_FASTFORWARD },      /* >> */
-       { 0x1d, KEY_RESTART },          /* Reset */
-};
-
-struct ir_scancode_table ir_codes_msi_tvanywhere_plus_table = {
-       .scan = ir_codes_msi_tvanywhere_plus,
-       .size = ARRAY_SIZE(ir_codes_msi_tvanywhere_plus),
-};
-EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere_plus_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* Cinergy 1400 DVB-T */
-static struct ir_scancode ir_codes_cinergy_1400[] = {
-       { 0x01, KEY_POWER },
-       { 0x02, KEY_1 },
-       { 0x03, KEY_2 },
-       { 0x04, KEY_3 },
-       { 0x05, KEY_4 },
-       { 0x06, KEY_5 },
-       { 0x07, KEY_6 },
-       { 0x08, KEY_7 },
-       { 0x09, KEY_8 },
-       { 0x0a, KEY_9 },
-       { 0x0c, KEY_0 },
-
-       { 0x0b, KEY_VIDEO },
-       { 0x0d, KEY_REFRESH },
-       { 0x0e, KEY_SELECT },
-       { 0x0f, KEY_EPG },
-       { 0x10, KEY_UP },
-       { 0x11, KEY_LEFT },
-       { 0x12, KEY_OK },
-       { 0x13, KEY_RIGHT },
-       { 0x14, KEY_DOWN },
-       { 0x15, KEY_TEXT },
-       { 0x16, KEY_INFO },
-
-       { 0x17, KEY_RED },
-       { 0x18, KEY_GREEN },
-       { 0x19, KEY_YELLOW },
-       { 0x1a, KEY_BLUE },
-
-       { 0x1b, KEY_CHANNELUP },
-       { 0x1c, KEY_VOLUMEUP },
-       { 0x1d, KEY_MUTE },
-       { 0x1e, KEY_VOLUMEDOWN },
-       { 0x1f, KEY_CHANNELDOWN },
-
-       { 0x40, KEY_PAUSE },
-       { 0x4c, KEY_PLAY },
-       { 0x58, KEY_RECORD },
-       { 0x54, KEY_PREVIOUS },
-       { 0x48, KEY_STOP },
-       { 0x5c, KEY_NEXT },
-};
-
-struct ir_scancode_table ir_codes_cinergy_1400_table = {
-       .scan = ir_codes_cinergy_1400,
-       .size = ARRAY_SIZE(ir_codes_cinergy_1400),
-};
-EXPORT_SYMBOL_GPL(ir_codes_cinergy_1400_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* AVERTV STUDIO 303 Remote */
-static struct ir_scancode ir_codes_avertv_303[] = {
-       { 0x2a, KEY_1 },
-       { 0x32, KEY_2 },
-       { 0x3a, KEY_3 },
-       { 0x4a, KEY_4 },
-       { 0x52, KEY_5 },
-       { 0x5a, KEY_6 },
-       { 0x6a, KEY_7 },
-       { 0x72, KEY_8 },
-       { 0x7a, KEY_9 },
-       { 0x0e, KEY_0 },
-
-       { 0x02, KEY_POWER },
-       { 0x22, KEY_VIDEO },
-       { 0x42, KEY_AUDIO },
-       { 0x62, KEY_ZOOM },
-       { 0x0a, KEY_TV },
-       { 0x12, KEY_CD },
-       { 0x1a, KEY_TEXT },
-
-       { 0x16, KEY_SUBTITLE },
-       { 0x1e, KEY_REWIND },
-       { 0x06, KEY_PRINT },
-
-       { 0x2e, KEY_SEARCH },
-       { 0x36, KEY_SLEEP },
-       { 0x3e, KEY_SHUFFLE },
-       { 0x26, KEY_MUTE },
-
-       { 0x4e, KEY_RECORD },
-       { 0x56, KEY_PAUSE },
-       { 0x5e, KEY_STOP },
-       { 0x46, KEY_PLAY },
-
-       { 0x6e, KEY_RED },
-       { 0x0b, KEY_GREEN },
-       { 0x66, KEY_YELLOW },
-       { 0x03, KEY_BLUE },
-
-       { 0x76, KEY_LEFT },
-       { 0x7e, KEY_RIGHT },
-       { 0x13, KEY_DOWN },
-       { 0x1b, KEY_UP },
-};
-
-struct ir_scancode_table ir_codes_avertv_303_table = {
-       .scan = ir_codes_avertv_303,
-       .size = ARRAY_SIZE(ir_codes_avertv_303),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avertv_303_table);
-
-/* ---------------------------------------------------------------------- */
-
-/* DigitalNow DNTV Live! DVB-T Pro Remote */
-static struct ir_scancode ir_codes_dntv_live_dvbt_pro[] = {
-       { 0x16, KEY_POWER },
-       { 0x5b, KEY_HOME },
-
-       { 0x55, KEY_TV },               /* live tv */
-       { 0x58, KEY_TUNER },            /* digital Radio */
-       { 0x5a, KEY_RADIO },            /* FM radio */
-       { 0x59, KEY_DVD },              /* dvd menu */
-       { 0x03, KEY_1 },
-       { 0x01, KEY_2 },
-       { 0x06, KEY_3 },
-       { 0x09, KEY_4 },
-       { 0x1d, KEY_5 },
-       { 0x1f, KEY_6 },
-       { 0x0d, KEY_7 },
-       { 0x19, KEY_8 },
-       { 0x1b, KEY_9 },
-       { 0x0c, KEY_CANCEL },
-       { 0x15, KEY_0 },
-       { 0x4a, KEY_CLEAR },
-       { 0x13, KEY_BACK },
-       { 0x00, KEY_TAB },
-       { 0x4b, KEY_UP },
-       { 0x4e, KEY_LEFT },
-       { 0x4f, KEY_OK },
-       { 0x52, KEY_RIGHT },
-       { 0x51, KEY_DOWN },
-       { 0x1e, KEY_VOLUMEUP },
-       { 0x0a, KEY_VOLUMEDOWN },
-       { 0x02, KEY_CHANNELDOWN },
-       { 0x05, KEY_CHANNELUP },
-       { 0x11, KEY_RECORD },
-       { 0x14, KEY_PLAY },
-       { 0x4c, KEY_PAUSE },
-       { 0x1a, KEY_STOP },
-       { 0x40, KEY_REWIND },
-       { 0x12, KEY_FASTFORWARD },
-       { 0x41, KEY_PREVIOUSSONG },     /* replay |< */
-       { 0x42, KEY_NEXTSONG },         /* skip >| */
-       { 0x54, KEY_CAMERA },           /* capture */
-       { 0x50, KEY_LANGUAGE },         /* sap */
-       { 0x47, KEY_TV2 },              /* pip */
-       { 0x4d, KEY_SCREEN },
-       { 0x43, KEY_SUBTITLE },
-       { 0x10, KEY_MUTE },
-       { 0x49, KEY_AUDIO },            /* l/r */
-       { 0x07, KEY_SLEEP },
-       { 0x08, KEY_VIDEO },            /* a/v */
-       { 0x0e, KEY_PREVIOUS },         /* recall */
-       { 0x45, KEY_ZOOM },             /* zoom + */
-       { 0x46, KEY_ANGLE },            /* zoom - */
-       { 0x56, KEY_RED },
-       { 0x57, KEY_GREEN },
-       { 0x5c, KEY_YELLOW },
-       { 0x5d, KEY_BLUE },
-};
-
-struct ir_scancode_table ir_codes_dntv_live_dvbt_pro_table = {
-       .scan = ir_codes_dntv_live_dvbt_pro,
-       .size = ARRAY_SIZE(ir_codes_dntv_live_dvbt_pro),
-};
-EXPORT_SYMBOL_GPL(ir_codes_dntv_live_dvbt_pro_table);
-
-static struct ir_scancode ir_codes_em_terratec[] = {
-       { 0x01, KEY_CHANNEL },
-       { 0x02, KEY_SELECT },
-       { 0x03, KEY_MUTE },
-       { 0x04, KEY_POWER },
-       { 0x05, KEY_1 },
-       { 0x06, KEY_2 },
-       { 0x07, KEY_3 },
-       { 0x08, KEY_CHANNELUP },
-       { 0x09, KEY_4 },
-       { 0x0a, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x0c, KEY_CHANNELDOWN },
-       { 0x0d, KEY_7 },
-       { 0x0e, KEY_8 },
-       { 0x0f, KEY_9 },
-       { 0x10, KEY_VOLUMEUP },
-       { 0x11, KEY_0 },
-       { 0x12, KEY_MENU },
-       { 0x13, KEY_PRINT },
-       { 0x14, KEY_VOLUMEDOWN },
-       { 0x16, KEY_PAUSE },
-       { 0x18, KEY_RECORD },
-       { 0x19, KEY_REWIND },
-       { 0x1a, KEY_PLAY },
-       { 0x1b, KEY_FORWARD },
-       { 0x1c, KEY_BACKSPACE },
-       { 0x1e, KEY_STOP },
-       { 0x40, KEY_ZOOM },
-};
-
-struct ir_scancode_table ir_codes_em_terratec_table = {
-       .scan = ir_codes_em_terratec,
-       .size = ARRAY_SIZE(ir_codes_em_terratec),
-};
-EXPORT_SYMBOL_GPL(ir_codes_em_terratec_table);
-
-static struct ir_scancode ir_codes_pinnacle_grey[] = {
-       { 0x3a, KEY_0 },
-       { 0x31, KEY_1 },
-       { 0x32, KEY_2 },
-       { 0x33, KEY_3 },
-       { 0x34, KEY_4 },
-       { 0x35, KEY_5 },
-       { 0x36, KEY_6 },
-       { 0x37, KEY_7 },
-       { 0x38, KEY_8 },
-       { 0x39, KEY_9 },
-
-       { 0x2f, KEY_POWER },
-
-       { 0x2e, KEY_P },
-       { 0x1f, KEY_L },
-       { 0x2b, KEY_I },
-
-       { 0x2d, KEY_SCREEN },
-       { 0x1e, KEY_ZOOM },
-       { 0x1b, KEY_VOLUMEUP },
-       { 0x0f, KEY_VOLUMEDOWN },
-       { 0x17, KEY_CHANNELUP },
-       { 0x1c, KEY_CHANNELDOWN },
-       { 0x25, KEY_INFO },
-
-       { 0x3c, KEY_MUTE },
-
-       { 0x3d, KEY_LEFT },
-       { 0x3b, KEY_RIGHT },
-
-       { 0x3f, KEY_UP },
-       { 0x3e, KEY_DOWN },
-       { 0x1a, KEY_ENTER },
-
-       { 0x1d, KEY_MENU },
-       { 0x19, KEY_AGAIN },
-       { 0x16, KEY_PREVIOUSSONG },
-       { 0x13, KEY_NEXTSONG },
-       { 0x15, KEY_PAUSE },
-       { 0x0e, KEY_REWIND },
-       { 0x0d, KEY_PLAY },
-       { 0x0b, KEY_STOP },
-       { 0x07, KEY_FORWARD },
-       { 0x27, KEY_RECORD },
-       { 0x26, KEY_TUNER },
-       { 0x29, KEY_TEXT },
-       { 0x2a, KEY_MEDIA },
-       { 0x18, KEY_EPG },
-};
-
-struct ir_scancode_table ir_codes_pinnacle_grey_table = {
-       .scan = ir_codes_pinnacle_grey,
-       .size = ARRAY_SIZE(ir_codes_pinnacle_grey),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pinnacle_grey_table);
-
-static struct ir_scancode ir_codes_flyvideo[] = {
-       { 0x0f, KEY_0 },
-       { 0x03, KEY_1 },
-       { 0x04, KEY_2 },
-       { 0x05, KEY_3 },
-       { 0x07, KEY_4 },
-       { 0x08, KEY_5 },
-       { 0x09, KEY_6 },
-       { 0x0b, KEY_7 },
-       { 0x0c, KEY_8 },
-       { 0x0d, KEY_9 },
-
-       { 0x0e, KEY_MODE },     /* Air/Cable */
-       { 0x11, KEY_VIDEO },    /* Video */
-       { 0x15, KEY_AUDIO },    /* Audio */
-       { 0x00, KEY_POWER },    /* Power */
-       { 0x18, KEY_TUNER },    /* AV Source */
-       { 0x02, KEY_ZOOM },     /* Fullscreen */
-       { 0x1a, KEY_LANGUAGE }, /* Stereo */
-       { 0x1b, KEY_MUTE },     /* Mute */
-       { 0x14, KEY_VOLUMEUP }, /* Volume + */
-       { 0x17, KEY_VOLUMEDOWN },/* Volume - */
-       { 0x12, KEY_CHANNELUP },/* Channel + */
-       { 0x13, KEY_CHANNELDOWN },/* Channel - */
-       { 0x06, KEY_AGAIN },    /* Recall */
-       { 0x10, KEY_ENTER },    /* Enter */
-
-       { 0x19, KEY_BACK },     /* Rewind  ( <<< ) */
-       { 0x1f, KEY_FORWARD },  /* Forward ( >>> ) */
-       { 0x0a, KEY_ANGLE },    /* no label, may be used as the PAUSE button */
-};
-
-struct ir_scancode_table ir_codes_flyvideo_table = {
-       .scan = ir_codes_flyvideo,
-       .size = ARRAY_SIZE(ir_codes_flyvideo),
-};
-EXPORT_SYMBOL_GPL(ir_codes_flyvideo_table);
-
-static struct ir_scancode ir_codes_flydvb[] = {
-       { 0x01, KEY_ZOOM },             /* Full Screen */
-       { 0x00, KEY_POWER },            /* Power */
-
-       { 0x03, KEY_1 },
-       { 0x04, KEY_2 },
-       { 0x05, KEY_3 },
-       { 0x07, KEY_4 },
-       { 0x08, KEY_5 },
-       { 0x09, KEY_6 },
-       { 0x0b, KEY_7 },
-       { 0x0c, KEY_8 },
-       { 0x0d, KEY_9 },
-       { 0x06, KEY_AGAIN },            /* Recall */
-       { 0x0f, KEY_0 },
-       { 0x10, KEY_MUTE },             /* Mute */
-       { 0x02, KEY_RADIO },            /* TV/Radio */
-       { 0x1b, KEY_LANGUAGE },         /* SAP (Second Audio Program) */
-
-       { 0x14, KEY_VOLUMEUP },         /* VOL+ */
-       { 0x17, KEY_VOLUMEDOWN },       /* VOL- */
-       { 0x12, KEY_CHANNELUP },        /* CH+ */
-       { 0x13, KEY_CHANNELDOWN },      /* CH- */
-       { 0x1d, KEY_ENTER },            /* Enter */
-
-       { 0x1a, KEY_MODE },             /* PIP */
-       { 0x18, KEY_TUNER },            /* Source */
-
-       { 0x1e, KEY_RECORD },           /* Record/Pause */
-       { 0x15, KEY_ANGLE },            /* Swap (no label on key) */
-       { 0x1c, KEY_PAUSE },            /* Timeshift/Pause */
-       { 0x19, KEY_BACK },             /* Rewind << */
-       { 0x0a, KEY_PLAYPAUSE },        /* Play/Pause */
-       { 0x1f, KEY_FORWARD },          /* Forward >> */
-       { 0x16, KEY_PREVIOUS },         /* Back |<< */
-       { 0x11, KEY_STOP },             /* Stop */
-       { 0x0e, KEY_NEXT },             /* End >>| */
-};
-
-struct ir_scancode_table ir_codes_flydvb_table = {
-       .scan = ir_codes_flydvb,
-       .size = ARRAY_SIZE(ir_codes_flydvb),
-};
-EXPORT_SYMBOL_GPL(ir_codes_flydvb_table);
-
-static struct ir_scancode ir_codes_cinergy[] = {
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0a, KEY_POWER },
-       { 0x0b, KEY_PROG1 },            /* app */
-       { 0x0c, KEY_ZOOM },             /* zoom/fullscreen */
-       { 0x0d, KEY_CHANNELUP },        /* channel */
-       { 0x0e, KEY_CHANNELDOWN },      /* channel- */
-       { 0x0f, KEY_VOLUMEUP },
-       { 0x10, KEY_VOLUMEDOWN },
-       { 0x11, KEY_TUNER },            /* AV */
-       { 0x12, KEY_NUMLOCK },          /* -/-- */
-       { 0x13, KEY_AUDIO },            /* audio */
-       { 0x14, KEY_MUTE },
-       { 0x15, KEY_UP },
-       { 0x16, KEY_DOWN },
-       { 0x17, KEY_LEFT },
-       { 0x18, KEY_RIGHT },
-       { 0x19, BTN_LEFT, },
-       { 0x1a, BTN_RIGHT, },
-       { 0x1b, KEY_WWW },              /* text */
-       { 0x1c, KEY_REWIND },
-       { 0x1d, KEY_FORWARD },
-       { 0x1e, KEY_RECORD },
-       { 0x1f, KEY_PLAY },
-       { 0x20, KEY_PREVIOUSSONG },
-       { 0x21, KEY_NEXTSONG },
-       { 0x22, KEY_PAUSE },
-       { 0x23, KEY_STOP },
-};
-
-struct ir_scancode_table ir_codes_cinergy_table = {
-       .scan = ir_codes_cinergy,
-       .size = ARRAY_SIZE(ir_codes_cinergy),
-};
-EXPORT_SYMBOL_GPL(ir_codes_cinergy_table);
-
-/* Alfons Geser <a.geser@cox.net>
- * updates from Job D. R. Borges <jobdrb@ig.com.br> */
-static struct ir_scancode ir_codes_eztv[] = {
-       { 0x12, KEY_POWER },
-       { 0x01, KEY_TV },       /* DVR */
-       { 0x15, KEY_DVD },      /* DVD */
-       { 0x17, KEY_AUDIO },    /* music */
-                               /* DVR mode / DVD mode / music mode */
-
-       { 0x1b, KEY_MUTE },     /* mute */
-       { 0x02, KEY_LANGUAGE }, /* MTS/SAP / audio / autoseek */
-       { 0x1e, KEY_SUBTITLE }, /* closed captioning / subtitle / seek */
-       { 0x16, KEY_ZOOM },     /* full screen */
-       { 0x1c, KEY_VIDEO },    /* video source / eject / delall */
-       { 0x1d, KEY_RESTART },  /* playback / angle / del */
-       { 0x2f, KEY_SEARCH },   /* scan / menu / playlist */
-       { 0x30, KEY_CHANNEL },  /* CH surfing / bookmark / memo */
-
-       { 0x31, KEY_HELP },     /* help */
-       { 0x32, KEY_MODE },     /* num/memo */
-       { 0x33, KEY_ESC },      /* cancel */
-
-       { 0x0c, KEY_UP },       /* up */
-       { 0x10, KEY_DOWN },     /* down */
-       { 0x08, KEY_LEFT },     /* left */
-       { 0x04, KEY_RIGHT },    /* right */
-       { 0x03, KEY_SELECT },   /* select */
-
-       { 0x1f, KEY_REWIND },   /* rewind */
-       { 0x20, KEY_PLAYPAUSE },/* play/pause */
-       { 0x29, KEY_FORWARD },  /* forward */
-       { 0x14, KEY_AGAIN },    /* repeat */
-       { 0x2b, KEY_RECORD },   /* recording */
-       { 0x2c, KEY_STOP },     /* stop */
-       { 0x2d, KEY_PLAY },     /* play */
-       { 0x2e, KEY_CAMERA },   /* snapshot / shuffle */
-
-       { 0x00, KEY_0 },
-       { 0x05, KEY_1 },
-       { 0x06, KEY_2 },
-       { 0x07, KEY_3 },
-       { 0x09, KEY_4 },
-       { 0x0a, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x0d, KEY_7 },
-       { 0x0e, KEY_8 },
-       { 0x0f, KEY_9 },
-
-       { 0x2a, KEY_VOLUMEUP },
-       { 0x11, KEY_VOLUMEDOWN },
-       { 0x18, KEY_CHANNELUP },/* CH.tracking up */
-       { 0x19, KEY_CHANNELDOWN },/* CH.tracking down */
-
-       { 0x13, KEY_ENTER },    /* enter */
-       { 0x21, KEY_DOT },      /* . (decimal dot) */
-};
-
-struct ir_scancode_table ir_codes_eztv_table = {
-       .scan = ir_codes_eztv,
-       .size = ARRAY_SIZE(ir_codes_eztv),
-};
-EXPORT_SYMBOL_GPL(ir_codes_eztv_table);
-
-/* Alex Hermann <gaaf@gmx.net> */
-static struct ir_scancode ir_codes_avermedia[] = {
-       { 0x28, KEY_1 },
-       { 0x18, KEY_2 },
-       { 0x38, KEY_3 },
-       { 0x24, KEY_4 },
-       { 0x14, KEY_5 },
-       { 0x34, KEY_6 },
-       { 0x2c, KEY_7 },
-       { 0x1c, KEY_8 },
-       { 0x3c, KEY_9 },
-       { 0x22, KEY_0 },
-
-       { 0x20, KEY_TV },               /* TV/FM */
-       { 0x10, KEY_CD },               /* CD */
-       { 0x30, KEY_TEXT },             /* TELETEXT */
-       { 0x00, KEY_POWER },            /* POWER */
-
-       { 0x08, KEY_VIDEO },            /* VIDEO */
-       { 0x04, KEY_AUDIO },            /* AUDIO */
-       { 0x0c, KEY_ZOOM },             /* FULL SCREEN */
-
-       { 0x12, KEY_SUBTITLE },         /* DISPLAY */
-       { 0x32, KEY_REWIND },           /* LOOP */
-       { 0x02, KEY_PRINT },            /* PREVIEW */
-
-       { 0x2a, KEY_SEARCH },           /* AUTOSCAN */
-       { 0x1a, KEY_SLEEP },            /* FREEZE */
-       { 0x3a, KEY_CAMERA },           /* SNAPSHOT */
-       { 0x0a, KEY_MUTE },             /* MUTE */
-
-       { 0x26, KEY_RECORD },           /* RECORD */
-       { 0x16, KEY_PAUSE },            /* PAUSE */
-       { 0x36, KEY_STOP },             /* STOP */
-       { 0x06, KEY_PLAY },             /* PLAY */
-
-       { 0x2e, KEY_RED },              /* RED */
-       { 0x21, KEY_GREEN },            /* GREEN */
-       { 0x0e, KEY_YELLOW },           /* YELLOW */
-       { 0x01, KEY_BLUE },             /* BLUE */
-
-       { 0x1e, KEY_VOLUMEDOWN },       /* VOLUME- */
-       { 0x3e, KEY_VOLUMEUP },         /* VOLUME+ */
-       { 0x11, KEY_CHANNELDOWN },      /* CHANNEL/PAGE- */
-       { 0x31, KEY_CHANNELUP }         /* CHANNEL/PAGE+ */
-};
-
-struct ir_scancode_table ir_codes_avermedia_table = {
-       .scan = ir_codes_avermedia,
-       .size = ARRAY_SIZE(ir_codes_avermedia),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avermedia_table);
-
-static struct ir_scancode ir_codes_videomate_tv_pvr[] = {
-       { 0x14, KEY_MUTE },
-       { 0x24, KEY_ZOOM },
-
-       { 0x01, KEY_DVD },
-       { 0x23, KEY_RADIO },
-       { 0x00, KEY_TV },
-
-       { 0x0a, KEY_REWIND },
-       { 0x08, KEY_PLAYPAUSE },
-       { 0x0f, KEY_FORWARD },
-
-       { 0x02, KEY_PREVIOUS },
-       { 0x07, KEY_STOP },
-       { 0x06, KEY_NEXT },
-
-       { 0x0c, KEY_UP },
-       { 0x0e, KEY_DOWN },
-       { 0x0b, KEY_LEFT },
-       { 0x0d, KEY_RIGHT },
-       { 0x11, KEY_OK },
-
-       { 0x03, KEY_MENU },
-       { 0x09, KEY_SETUP },
-       { 0x05, KEY_VIDEO },
-       { 0x22, KEY_CHANNEL },
-
-       { 0x12, KEY_VOLUMEUP },
-       { 0x15, KEY_VOLUMEDOWN },
-       { 0x10, KEY_CHANNELUP },
-       { 0x13, KEY_CHANNELDOWN },
-
-       { 0x04, KEY_RECORD },
-
-       { 0x16, KEY_1 },
-       { 0x17, KEY_2 },
-       { 0x18, KEY_3 },
-       { 0x19, KEY_4 },
-       { 0x1a, KEY_5 },
-       { 0x1b, KEY_6 },
-       { 0x1c, KEY_7 },
-       { 0x1d, KEY_8 },
-       { 0x1e, KEY_9 },
-       { 0x1f, KEY_0 },
-
-       { 0x20, KEY_LANGUAGE },
-       { 0x21, KEY_SLEEP },
-};
-
-struct ir_scancode_table ir_codes_videomate_tv_pvr_table = {
-       .scan = ir_codes_videomate_tv_pvr,
-       .size = ARRAY_SIZE(ir_codes_videomate_tv_pvr),
-};
-EXPORT_SYMBOL_GPL(ir_codes_videomate_tv_pvr_table);
-
-/* Michael Tokarev <mjt@tls.msk.ru>
-   http://www.corpit.ru/mjt/beholdTV/remote_control.jpg
-   keytable is used by MANLI MTV00[0x0c] and BeholdTV 40[13] at
-   least, and probably other cards too.
-   The "ascii-art picture" below (in comments, first row
-   is the keycode in hex, and subsequent row(s) shows
-   the button labels (several variants when appropriate)
-   helps to descide which keycodes to assign to the buttons.
- */
-static struct ir_scancode ir_codes_manli[] = {
-
-       /*  0x1c            0x12  *
-        * FUNCTION         POWER *
-        *   FM              (|)  *
-        *                        */
-       { 0x1c, KEY_RADIO },    /*XXX*/
-       { 0x12, KEY_POWER },
-
-       /*  0x01    0x02    0x03  *
-        *   1       2       3    *
-        *                        *
-        *  0x04    0x05    0x06  *
-        *   4       5       6    *
-        *                        *
-        *  0x07    0x08    0x09  *
-        *   7       8       9    *
-        *                        */
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       /*  0x0a    0x00    0x17  *
-        * RECALL    0      +100  *
-        *                  PLUS  *
-        *                        */
-       { 0x0a, KEY_AGAIN },    /*XXX KEY_REWIND? */
-       { 0x00, KEY_0 },
-       { 0x17, KEY_DIGITS },   /*XXX*/
-
-       /*  0x14            0x10  *
-        *  MENU            INFO  *
-        *  OSD                   */
-       { 0x14, KEY_MENU },
-       { 0x10, KEY_INFO },
-
-       /*          0x0b          *
-        *           Up           *
-        *                        *
-        *  0x18    0x16    0x0c  *
-        *  Left     Ok     Right *
-        *                        *
-        *         0x015          *
-        *         Down           *
-        *                        */
-       { 0x0b, KEY_UP },
-       { 0x18, KEY_LEFT },
-       { 0x16, KEY_OK },       /*XXX KEY_SELECT? KEY_ENTER? */
-       { 0x0c, KEY_RIGHT },
-       { 0x15, KEY_DOWN },
-
-       /*  0x11            0x0d  *
-        *  TV/AV           MODE  *
-        *  SOURCE         STEREO *
-        *                        */
-       { 0x11, KEY_TV },       /*XXX*/
-       { 0x0d, KEY_MODE },     /*XXX there's no KEY_STEREO     */
-
-       /*  0x0f    0x1b    0x1a  *
-        *  AUDIO   Vol+    Chan+ *
-        *        TIMESHIFT???    *
-        *                        *
-        *  0x0e    0x1f    0x1e  *
-        *  SLEEP   Vol-    Chan- *
-        *                        */
-       { 0x0f, KEY_AUDIO },
-       { 0x1b, KEY_VOLUMEUP },
-       { 0x1a, KEY_CHANNELUP },
-       { 0x0e, KEY_TIME },
-       { 0x1f, KEY_VOLUMEDOWN },
-       { 0x1e, KEY_CHANNELDOWN },
-
-       /*         0x13     0x19  *
-        *         MUTE   SNAPSHOT*
-        *                        */
-       { 0x13, KEY_MUTE },
-       { 0x19, KEY_CAMERA },
-
-       /* 0x1d unused ? */
-};
-
-struct ir_scancode_table ir_codes_manli_table = {
-       .scan = ir_codes_manli,
-       .size = ARRAY_SIZE(ir_codes_manli),
-};
-EXPORT_SYMBOL_GPL(ir_codes_manli_table);
-
-/* Mike Baikov <mike@baikov.com> */
-static struct ir_scancode ir_codes_gotview7135[] = {
-
-       { 0x11, KEY_POWER },
-       { 0x35, KEY_TV },
-       { 0x1b, KEY_0 },
-       { 0x29, KEY_1 },
-       { 0x19, KEY_2 },
-       { 0x39, KEY_3 },
-       { 0x1f, KEY_4 },
-       { 0x2c, KEY_5 },
-       { 0x21, KEY_6 },
-       { 0x24, KEY_7 },
-       { 0x18, KEY_8 },
-       { 0x2b, KEY_9 },
-       { 0x3b, KEY_AGAIN },    /* LOOP */
-       { 0x06, KEY_AUDIO },
-       { 0x31, KEY_PRINT },    /* PREVIEW */
-       { 0x3e, KEY_VIDEO },
-       { 0x10, KEY_CHANNELUP },
-       { 0x20, KEY_CHANNELDOWN },
-       { 0x0c, KEY_VOLUMEDOWN },
-       { 0x28, KEY_VOLUMEUP },
-       { 0x08, KEY_MUTE },
-       { 0x26, KEY_SEARCH },   /* SCAN */
-       { 0x3f, KEY_CAMERA },   /* SNAPSHOT */
-       { 0x12, KEY_RECORD },
-       { 0x32, KEY_STOP },
-       { 0x3c, KEY_PLAY },
-       { 0x1d, KEY_REWIND },
-       { 0x2d, KEY_PAUSE },
-       { 0x0d, KEY_FORWARD },
-       { 0x05, KEY_ZOOM },     /*FULL*/
-
-       { 0x2a, KEY_F21 },      /* LIVE TIMESHIFT */
-       { 0x0e, KEY_F22 },      /* MIN TIMESHIFT */
-       { 0x1e, KEY_TIME },     /* TIMESHIFT */
-       { 0x38, KEY_F24 },      /* NORMAL TIMESHIFT */
-};
-
-struct ir_scancode_table ir_codes_gotview7135_table = {
-       .scan = ir_codes_gotview7135,
-       .size = ARRAY_SIZE(ir_codes_gotview7135),
-};
-EXPORT_SYMBOL_GPL(ir_codes_gotview7135_table);
-
-static struct ir_scancode ir_codes_purpletv[] = {
-       { 0x03, KEY_POWER },
-       { 0x6f, KEY_MUTE },
-       { 0x10, KEY_BACKSPACE },        /* Recall */
-
-       { 0x11, KEY_0 },
-       { 0x04, KEY_1 },
-       { 0x05, KEY_2 },
-       { 0x06, KEY_3 },
-       { 0x08, KEY_4 },
-       { 0x09, KEY_5 },
-       { 0x0a, KEY_6 },
-       { 0x0c, KEY_7 },
-       { 0x0d, KEY_8 },
-       { 0x0e, KEY_9 },
-       { 0x12, KEY_DOT },      /* 100+ */
-
-       { 0x07, KEY_VOLUMEUP },
-       { 0x0b, KEY_VOLUMEDOWN },
-       { 0x1a, KEY_KPPLUS },
-       { 0x18, KEY_KPMINUS },
-       { 0x15, KEY_UP },
-       { 0x1d, KEY_DOWN },
-       { 0x0f, KEY_CHANNELUP },
-       { 0x13, KEY_CHANNELDOWN },
-       { 0x48, KEY_ZOOM },
-
-       { 0x1b, KEY_VIDEO },    /* Video source */
-       { 0x1f, KEY_CAMERA },   /* Snapshot */
-       { 0x49, KEY_LANGUAGE }, /* MTS Select */
-       { 0x19, KEY_SEARCH },   /* Auto Scan */
-
-       { 0x4b, KEY_RECORD },
-       { 0x46, KEY_PLAY },
-       { 0x45, KEY_PAUSE },    /* Pause */
-       { 0x44, KEY_STOP },
-       { 0x43, KEY_TIME },     /* Time Shift */
-       { 0x17, KEY_CHANNEL },  /* SURF CH */
-       { 0x40, KEY_FORWARD },  /* Forward ? */
-       { 0x42, KEY_REWIND },   /* Backward ? */
-
-};
-
-struct ir_scancode_table ir_codes_purpletv_table = {
-       .scan = ir_codes_purpletv,
-       .size = ARRAY_SIZE(ir_codes_purpletv),
-};
-EXPORT_SYMBOL_GPL(ir_codes_purpletv_table);
-
-/* Mapping for the 28 key remote control as seen at
-   http://www.sednacomputer.com/photo/cardbus-tv.jpg
-   Pavel Mihaylov <bin@bash.info>
-   Also for the remote bundled with Kozumi KTV-01C card */
-static struct ir_scancode ir_codes_pctv_sedna[] = {
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0a, KEY_AGAIN },    /* Recall */
-       { 0x0b, KEY_CHANNELUP },
-       { 0x0c, KEY_VOLUMEUP },
-       { 0x0d, KEY_MODE },     /* Stereo */
-       { 0x0e, KEY_STOP },
-       { 0x0f, KEY_PREVIOUSSONG },
-       { 0x10, KEY_ZOOM },
-       { 0x11, KEY_TUNER },    /* Source */
-       { 0x12, KEY_POWER },
-       { 0x13, KEY_MUTE },
-       { 0x15, KEY_CHANNELDOWN },
-       { 0x18, KEY_VOLUMEDOWN },
-       { 0x19, KEY_CAMERA },   /* Snapshot */
-       { 0x1a, KEY_NEXTSONG },
-       { 0x1b, KEY_TIME },     /* Time Shift */
-       { 0x1c, KEY_RADIO },    /* FM Radio */
-       { 0x1d, KEY_RECORD },
-       { 0x1e, KEY_PAUSE },
-       /* additional codes for Kozumi's remote */
-       { 0x14, KEY_INFO },     /* OSD */
-       { 0x16, KEY_OK },       /* OK */
-       { 0x17, KEY_DIGITS },   /* Plus */
-       { 0x1f, KEY_PLAY },     /* Play */
-};
-
-struct ir_scancode_table ir_codes_pctv_sedna_table = {
-       .scan = ir_codes_pctv_sedna,
-       .size = ARRAY_SIZE(ir_codes_pctv_sedna),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pctv_sedna_table);
-
-/* Mark Phalan <phalanm@o2.ie> */
-static struct ir_scancode ir_codes_pv951[] = {
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x12, KEY_POWER },
-       { 0x10, KEY_MUTE },
-       { 0x1f, KEY_VOLUMEDOWN },
-       { 0x1b, KEY_VOLUMEUP },
-       { 0x1a, KEY_CHANNELUP },
-       { 0x1e, KEY_CHANNELDOWN },
-       { 0x0e, KEY_PAGEUP },
-       { 0x1d, KEY_PAGEDOWN },
-       { 0x13, KEY_SOUND },
-
-       { 0x18, KEY_KPPLUSMINUS },      /* CH +/- */
-       { 0x16, KEY_SUBTITLE },         /* CC */
-       { 0x0d, KEY_TEXT },             /* TTX */
-       { 0x0b, KEY_TV },               /* AIR/CBL */
-       { 0x11, KEY_PC },               /* PC/TV */
-       { 0x17, KEY_OK },               /* CH RTN */
-       { 0x19, KEY_MODE },             /* FUNC */
-       { 0x0c, KEY_SEARCH },           /* AUTOSCAN */
-
-       /* Not sure what to do with these ones! */
-       { 0x0f, KEY_SELECT },           /* SOURCE */
-       { 0x0a, KEY_KPPLUS },           /* +100 */
-       { 0x14, KEY_EQUAL },            /* SYNC */
-       { 0x1c, KEY_MEDIA },            /* PC/TV */
-};
-
-struct ir_scancode_table ir_codes_pv951_table = {
-       .scan = ir_codes_pv951,
-       .size = ARRAY_SIZE(ir_codes_pv951),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pv951_table);
-
-/* generic RC5 keytable                                          */
-/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
-/* used by old (black) Hauppauge remotes                         */
-static struct ir_scancode ir_codes_rc5_tv[] = {
-       /* Keys 0 to 9 */
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0b, KEY_CHANNEL },          /* channel / program (japan: 11) */
-       { 0x0c, KEY_POWER },            /* standby */
-       { 0x0d, KEY_MUTE },             /* mute / demute */
-       { 0x0f, KEY_TV },               /* display */
-       { 0x10, KEY_VOLUMEUP },
-       { 0x11, KEY_VOLUMEDOWN },
-       { 0x12, KEY_BRIGHTNESSUP },
-       { 0x13, KEY_BRIGHTNESSDOWN },
-       { 0x1e, KEY_SEARCH },           /* search + */
-       { 0x20, KEY_CHANNELUP },        /* channel / program + */
-       { 0x21, KEY_CHANNELDOWN },      /* channel / program - */
-       { 0x22, KEY_CHANNEL },          /* alt / channel */
-       { 0x23, KEY_LANGUAGE },         /* 1st / 2nd language */
-       { 0x26, KEY_SLEEP },            /* sleeptimer */
-       { 0x2e, KEY_MENU },             /* 2nd controls (USA: menu) */
-       { 0x30, KEY_PAUSE },
-       { 0x32, KEY_REWIND },
-       { 0x33, KEY_GOTO },
-       { 0x35, KEY_PLAY },
-       { 0x36, KEY_STOP },
-       { 0x37, KEY_RECORD },           /* recording */
-       { 0x3c, KEY_TEXT },             /* teletext submode (Japan: 12) */
-       { 0x3d, KEY_SUSPEND },          /* system standby */
-
-};
-
-struct ir_scancode_table ir_codes_rc5_tv_table = {
-       .scan = ir_codes_rc5_tv,
-       .size = ARRAY_SIZE(ir_codes_rc5_tv),
-};
-EXPORT_SYMBOL_GPL(ir_codes_rc5_tv_table);
-
-/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
-static struct ir_scancode ir_codes_winfast[] = {
-       /* Keys 0 to 9 */
-       { 0x12, KEY_0 },
-       { 0x05, KEY_1 },
-       { 0x06, KEY_2 },
-       { 0x07, KEY_3 },
-       { 0x09, KEY_4 },
-       { 0x0a, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x0d, KEY_7 },
-       { 0x0e, KEY_8 },
-       { 0x0f, KEY_9 },
-
-       { 0x00, KEY_POWER },
-       { 0x1b, KEY_AUDIO },            /* Audio Source */
-       { 0x02, KEY_TUNER },            /* TV/FM, not on Y0400052 */
-       { 0x1e, KEY_VIDEO },            /* Video Source */
-       { 0x16, KEY_INFO },             /* Display information */
-       { 0x04, KEY_VOLUMEUP },
-       { 0x08, KEY_VOLUMEDOWN },
-       { 0x0c, KEY_CHANNELUP },
-       { 0x10, KEY_CHANNELDOWN },
-       { 0x03, KEY_ZOOM },             /* fullscreen */
-       { 0x1f, KEY_TEXT },             /* closed caption/teletext */
-       { 0x20, KEY_SLEEP },
-       { 0x29, KEY_CLEAR },            /* boss key */
-       { 0x14, KEY_MUTE },
-       { 0x2b, KEY_RED },
-       { 0x2c, KEY_GREEN },
-       { 0x2d, KEY_YELLOW },
-       { 0x2e, KEY_BLUE },
-       { 0x18, KEY_KPPLUS },           /* fine tune + , not on Y040052 */
-       { 0x19, KEY_KPMINUS },          /* fine tune - , not on Y040052 */
-       { 0x2a, KEY_MEDIA },            /* PIP (Picture in picture */
-       { 0x21, KEY_DOT },
-       { 0x13, KEY_ENTER },
-       { 0x11, KEY_LAST },             /* Recall (last channel */
-       { 0x22, KEY_PREVIOUS },
-       { 0x23, KEY_PLAYPAUSE },
-       { 0x24, KEY_NEXT },
-       { 0x25, KEY_TIME },             /* Time Shifting */
-       { 0x26, KEY_STOP },
-       { 0x27, KEY_RECORD },
-       { 0x28, KEY_SAVE },             /* Screenshot */
-       { 0x2f, KEY_MENU },
-       { 0x30, KEY_CANCEL },
-       { 0x31, KEY_CHANNEL },          /* Channel Surf */
-       { 0x32, KEY_SUBTITLE },
-       { 0x33, KEY_LANGUAGE },
-       { 0x34, KEY_REWIND },
-       { 0x35, KEY_FASTFORWARD },
-       { 0x36, KEY_TV },
-       { 0x37, KEY_RADIO },            /* FM */
-       { 0x38, KEY_DVD },
-
-       { 0x1a, KEY_MODE},              /* change to MCE mode on Y04G0051 */
-       { 0x3e, KEY_F21 },              /* MCE +VOL, on Y04G0033 */
-       { 0x3a, KEY_F22 },              /* MCE -VOL, on Y04G0033 */
-       { 0x3b, KEY_F23 },              /* MCE +CH,  on Y04G0033 */
-       { 0x3f, KEY_F24 }               /* MCE -CH,  on Y04G0033 */
-};
-
-struct ir_scancode_table ir_codes_winfast_table = {
-       .scan = ir_codes_winfast,
-       .size = ARRAY_SIZE(ir_codes_winfast),
-};
-EXPORT_SYMBOL_GPL(ir_codes_winfast_table);
-
-static struct ir_scancode ir_codes_pinnacle_color[] = {
-       { 0x59, KEY_MUTE },
-       { 0x4a, KEY_POWER },
-
-       { 0x18, KEY_TEXT },
-       { 0x26, KEY_TV },
-       { 0x3d, KEY_PRINT },
-
-       { 0x48, KEY_RED },
-       { 0x04, KEY_GREEN },
-       { 0x11, KEY_YELLOW },
-       { 0x00, KEY_BLUE },
-
-       { 0x2d, KEY_VOLUMEUP },
-       { 0x1e, KEY_VOLUMEDOWN },
-
-       { 0x49, KEY_MENU },
-
-       { 0x16, KEY_CHANNELUP },
-       { 0x17, KEY_CHANNELDOWN },
-
-       { 0x20, KEY_UP },
-       { 0x21, KEY_DOWN },
-       { 0x22, KEY_LEFT },
-       { 0x23, KEY_RIGHT },
-       { 0x0d, KEY_SELECT },
-
-       { 0x08, KEY_BACK },
-       { 0x07, KEY_REFRESH },
-
-       { 0x2f, KEY_ZOOM },
-       { 0x29, KEY_RECORD },
-
-       { 0x4b, KEY_PAUSE },
-       { 0x4d, KEY_REWIND },
-       { 0x2e, KEY_PLAY },
-       { 0x4e, KEY_FORWARD },
-       { 0x53, KEY_PREVIOUS },
-       { 0x4c, KEY_STOP },
-       { 0x54, KEY_NEXT },
-
-       { 0x69, KEY_0 },
-       { 0x6a, KEY_1 },
-       { 0x6b, KEY_2 },
-       { 0x6c, KEY_3 },
-       { 0x6d, KEY_4 },
-       { 0x6e, KEY_5 },
-       { 0x6f, KEY_6 },
-       { 0x70, KEY_7 },
-       { 0x71, KEY_8 },
-       { 0x72, KEY_9 },
-
-       { 0x74, KEY_CHANNEL },
-       { 0x0a, KEY_BACKSPACE },
-};
-
-struct ir_scancode_table ir_codes_pinnacle_color_table = {
-       .scan = ir_codes_pinnacle_color,
-       .size = ARRAY_SIZE(ir_codes_pinnacle_color),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pinnacle_color_table);
-
-/* Hauppauge: the newer, gray remotes (seems there are multiple
- * slightly different versions), shipped with cx88+ivtv cards.
- * almost rc5 coding, but some non-standard keys */
-static struct ir_scancode ir_codes_hauppauge_new[] = {
-       /* Keys 0 to 9 */
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       { 0x0a, KEY_TEXT },             /* keypad asterisk as well */
-       { 0x0b, KEY_RED },              /* red button */
-       { 0x0c, KEY_RADIO },
-       { 0x0d, KEY_MENU },
-       { 0x0e, KEY_SUBTITLE },         /* also the # key */
-       { 0x0f, KEY_MUTE },
-       { 0x10, KEY_VOLUMEUP },
-       { 0x11, KEY_VOLUMEDOWN },
-       { 0x12, KEY_PREVIOUS },         /* previous channel */
-       { 0x14, KEY_UP },
-       { 0x15, KEY_DOWN },
-       { 0x16, KEY_LEFT },
-       { 0x17, KEY_RIGHT },
-       { 0x18, KEY_VIDEO },            /* Videos */
-       { 0x19, KEY_AUDIO },            /* Music */
-       /* 0x1a: Pictures - presume this means
-          "Multimedia Home Platform" -
-          no "PICTURES" key in input.h
-        */
-       { 0x1a, KEY_MHP },
-
-       { 0x1b, KEY_EPG },              /* Guide */
-       { 0x1c, KEY_TV },
-       { 0x1e, KEY_NEXTSONG },         /* skip >| */
-       { 0x1f, KEY_EXIT },             /* back/exit */
-       { 0x20, KEY_CHANNELUP },        /* channel / program + */
-       { 0x21, KEY_CHANNELDOWN },      /* channel / program - */
-       { 0x22, KEY_CHANNEL },          /* source (old black remote) */
-       { 0x24, KEY_PREVIOUSSONG },     /* replay |< */
-       { 0x25, KEY_ENTER },            /* OK */
-       { 0x26, KEY_SLEEP },            /* minimize (old black remote) */
-       { 0x29, KEY_BLUE },             /* blue key */
-       { 0x2e, KEY_GREEN },            /* green button */
-       { 0x30, KEY_PAUSE },            /* pause */
-       { 0x32, KEY_REWIND },           /* backward << */
-       { 0x34, KEY_FASTFORWARD },      /* forward >> */
-       { 0x35, KEY_PLAY },
-       { 0x36, KEY_STOP },
-       { 0x37, KEY_RECORD },           /* recording */
-       { 0x38, KEY_YELLOW },           /* yellow key */
-       { 0x3b, KEY_SELECT },           /* top right button */
-       { 0x3c, KEY_ZOOM },             /* full */
-       { 0x3d, KEY_POWER },            /* system power (green button) */
-};
-
-struct ir_scancode_table ir_codes_hauppauge_new_table = {
-       .scan = ir_codes_hauppauge_new,
-       .size = ARRAY_SIZE(ir_codes_hauppauge_new),
-};
-EXPORT_SYMBOL_GPL(ir_codes_hauppauge_new_table);
-
-static struct ir_scancode ir_codes_npgtech[] = {
-       { 0x1d, KEY_SWITCHVIDEOMODE },  /* switch inputs */
-       { 0x2a, KEY_FRONT },
-
-       { 0x3e, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x06, KEY_3 },
-       { 0x0a, KEY_4 },
-       { 0x0e, KEY_5 },
-       { 0x12, KEY_6 },
-       { 0x16, KEY_7 },
-       { 0x1a, KEY_8 },
-       { 0x1e, KEY_9 },
-       { 0x3a, KEY_0 },
-       { 0x22, KEY_NUMLOCK },          /* -/-- */
-       { 0x20, KEY_REFRESH },
-
-       { 0x03, KEY_BRIGHTNESSDOWN },
-       { 0x28, KEY_AUDIO },
-       { 0x3c, KEY_CHANNELUP },
-       { 0x3f, KEY_VOLUMEDOWN },
-       { 0x2e, KEY_MUTE },
-       { 0x3b, KEY_VOLUMEUP },
-       { 0x00, KEY_CHANNELDOWN },
-       { 0x07, KEY_BRIGHTNESSUP },
-       { 0x2c, KEY_TEXT },
-
-       { 0x37, KEY_RECORD },
-       { 0x17, KEY_PLAY },
-       { 0x13, KEY_PAUSE },
-       { 0x26, KEY_STOP },
-       { 0x18, KEY_FASTFORWARD },
-       { 0x14, KEY_REWIND },
-       { 0x33, KEY_ZOOM },
-       { 0x32, KEY_KEYBOARD },
-       { 0x30, KEY_GOTO },             /* Pointing arrow */
-       { 0x36, KEY_MACRO },            /* Maximize/Minimize (yellow) */
-       { 0x0b, KEY_RADIO },
-       { 0x10, KEY_POWER },
-
-};
-
-struct ir_scancode_table ir_codes_npgtech_table = {
-       .scan = ir_codes_npgtech,
-       .size = ARRAY_SIZE(ir_codes_npgtech),
-};
-EXPORT_SYMBOL_GPL(ir_codes_npgtech_table);
-
-/* Norwood Micro (non-Pro) TV Tuner
-   By Peter Naulls <peter@chocky.org>
-   Key comments are the functions given in the manual */
-static struct ir_scancode ir_codes_norwood[] = {
-       /* Keys 0 to 9 */
-       { 0x20, KEY_0 },
-       { 0x21, KEY_1 },
-       { 0x22, KEY_2 },
-       { 0x23, KEY_3 },
-       { 0x24, KEY_4 },
-       { 0x25, KEY_5 },
-       { 0x26, KEY_6 },
-       { 0x27, KEY_7 },
-       { 0x28, KEY_8 },
-       { 0x29, KEY_9 },
-
-       { 0x78, KEY_TUNER },            /* Video Source        */
-       { 0x2c, KEY_EXIT },             /* Open/Close software */
-       { 0x2a, KEY_SELECT },           /* 2 Digit Select      */
-       { 0x69, KEY_AGAIN },            /* Recall              */
-
-       { 0x32, KEY_BRIGHTNESSUP },     /* Brightness increase */
-       { 0x33, KEY_BRIGHTNESSDOWN },   /* Brightness decrease */
-       { 0x6b, KEY_KPPLUS },           /* (not named >>>>>)   */
-       { 0x6c, KEY_KPMINUS },          /* (not named <<<<<)   */
-
-       { 0x2d, KEY_MUTE },             /* Mute                */
-       { 0x30, KEY_VOLUMEUP },         /* Volume up           */
-       { 0x31, KEY_VOLUMEDOWN },       /* Volume down         */
-       { 0x60, KEY_CHANNELUP },        /* Channel up          */
-       { 0x61, KEY_CHANNELDOWN },      /* Channel down        */
-
-       { 0x3f, KEY_RECORD },           /* Record              */
-       { 0x37, KEY_PLAY },             /* Play                */
-       { 0x36, KEY_PAUSE },            /* Pause               */
-       { 0x2b, KEY_STOP },             /* Stop                */
-       { 0x67, KEY_FASTFORWARD },      /* Foward              */
-       { 0x66, KEY_REWIND },           /* Rewind              */
-       { 0x3e, KEY_SEARCH },           /* Auto Scan           */
-       { 0x2e, KEY_CAMERA },           /* Capture Video       */
-       { 0x6d, KEY_MENU },             /* Show/Hide Control   */
-       { 0x2f, KEY_ZOOM },             /* Full Screen         */
-       { 0x34, KEY_RADIO },            /* FM                  */
-       { 0x65, KEY_POWER },            /* Computer power      */
-};
-
-struct ir_scancode_table ir_codes_norwood_table = {
-       .scan = ir_codes_norwood,
-       .size = ARRAY_SIZE(ir_codes_norwood),
-};
-EXPORT_SYMBOL_GPL(ir_codes_norwood_table);
-
-/* From reading the following remotes:
- * Zenith Universal 7 / TV Mode 807 / VCR Mode 837
- * Hauppauge (from NOVA-CI-s box product)
- * This is a "middle of the road" approach, differences are noted
- */
-static struct ir_scancode ir_codes_budget_ci_old[] = {
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-       { 0x0a, KEY_ENTER },
-       { 0x0b, KEY_RED },
-       { 0x0c, KEY_POWER },            /* RADIO on Hauppauge */
-       { 0x0d, KEY_MUTE },
-       { 0x0f, KEY_A },                /* TV on Hauppauge */
-       { 0x10, KEY_VOLUMEUP },
-       { 0x11, KEY_VOLUMEDOWN },
-       { 0x14, KEY_B },
-       { 0x1c, KEY_UP },
-       { 0x1d, KEY_DOWN },
-       { 0x1e, KEY_OPTION },           /* RESERVED on Hauppauge */
-       { 0x1f, KEY_BREAK },
-       { 0x20, KEY_CHANNELUP },
-       { 0x21, KEY_CHANNELDOWN },
-       { 0x22, KEY_PREVIOUS },         /* Prev Ch on Zenith, SOURCE on Hauppauge */
-       { 0x24, KEY_RESTART },
-       { 0x25, KEY_OK },
-       { 0x26, KEY_CYCLEWINDOWS },     /* MINIMIZE on Hauppauge */
-       { 0x28, KEY_ENTER },            /* VCR mode on Zenith */
-       { 0x29, KEY_PAUSE },
-       { 0x2b, KEY_RIGHT },
-       { 0x2c, KEY_LEFT },
-       { 0x2e, KEY_MENU },             /* FULL SCREEN on Hauppauge */
-       { 0x30, KEY_SLOW },
-       { 0x31, KEY_PREVIOUS },         /* VCR mode on Zenith */
-       { 0x32, KEY_REWIND },
-       { 0x34, KEY_FASTFORWARD },
-       { 0x35, KEY_PLAY },
-       { 0x36, KEY_STOP },
-       { 0x37, KEY_RECORD },
-       { 0x38, KEY_TUNER },            /* TV/VCR on Zenith */
-       { 0x3a, KEY_C },
-       { 0x3c, KEY_EXIT },
-       { 0x3d, KEY_POWER2 },
-       { 0x3e, KEY_TUNER },
-};
-
-struct ir_scancode_table ir_codes_budget_ci_old_table = {
-       .scan = ir_codes_budget_ci_old,
-       .size = ARRAY_SIZE(ir_codes_budget_ci_old),
-};
-EXPORT_SYMBOL_GPL(ir_codes_budget_ci_old_table);
-
-/*
- * Marc Fargas <telenieko@telenieko.com>
- * this is the remote control that comes with the asus p7131
- * which has a label saying is "Model PC-39"
- */
-static struct ir_scancode ir_codes_asus_pc39[] = {
-       /* Keys 0 to 9 */
-       { 0x15, KEY_0 },
-       { 0x29, KEY_1 },
-       { 0x2d, KEY_2 },
-       { 0x2b, KEY_3 },
-       { 0x09, KEY_4 },
-       { 0x0d, KEY_5 },
-       { 0x0b, KEY_6 },
-       { 0x31, KEY_7 },
-       { 0x35, KEY_8 },
-       { 0x33, KEY_9 },
-
-       { 0x3e, KEY_RADIO },            /* radio */
-       { 0x03, KEY_MENU },             /* dvd/menu */
-       { 0x2a, KEY_VOLUMEUP },
-       { 0x19, KEY_VOLUMEDOWN },
-       { 0x37, KEY_UP },
-       { 0x3b, KEY_DOWN },
-       { 0x27, KEY_LEFT },
-       { 0x2f, KEY_RIGHT },
-       { 0x25, KEY_VIDEO },            /* video */
-       { 0x39, KEY_AUDIO },            /* music */
-
-       { 0x21, KEY_TV },               /* tv */
-       { 0x1d, KEY_EXIT },             /* back */
-       { 0x0a, KEY_CHANNELUP },        /* channel / program + */
-       { 0x1b, KEY_CHANNELDOWN },      /* channel / program - */
-       { 0x1a, KEY_ENTER },            /* enter */
-
-       { 0x06, KEY_PAUSE },            /* play/pause */
-       { 0x1e, KEY_PREVIOUS },         /* rew */
-       { 0x26, KEY_NEXT },             /* forward */
-       { 0x0e, KEY_REWIND },           /* backward << */
-       { 0x3a, KEY_FASTFORWARD },      /* forward >> */
-       { 0x36, KEY_STOP },
-       { 0x2e, KEY_RECORD },           /* recording */
-       { 0x16, KEY_POWER },            /* the button that reads "close" */
-
-       { 0x11, KEY_ZOOM },             /* full screen */
-       { 0x13, KEY_MACRO },            /* recall */
-       { 0x23, KEY_HOME },             /* home */
-       { 0x05, KEY_PVR },              /* picture */
-       { 0x3d, KEY_MUTE },             /* mute */
-       { 0x01, KEY_DVD },              /* dvd */
-};
-
-struct ir_scancode_table ir_codes_asus_pc39_table = {
-       .scan = ir_codes_asus_pc39,
-       .size = ARRAY_SIZE(ir_codes_asus_pc39),
-};
-EXPORT_SYMBOL_GPL(ir_codes_asus_pc39_table);
-
-
-/* Encore ENLTV-FM  - black plastic, white front cover with white glowing buttons
-    Juan Pablo Sormani <sorman@gmail.com> */
-static struct ir_scancode ir_codes_encore_enltv[] = {
-
-       /* Power button does nothing, neither in Windows app,
-        although it sends data (used for BIOS wakeup?) */
-       { 0x0d, KEY_MUTE },
-
-       { 0x1e, KEY_TV },
-       { 0x00, KEY_VIDEO },
-       { 0x01, KEY_AUDIO },            /* music */
-       { 0x02, KEY_MHP },              /* picture */
-
-       { 0x1f, KEY_1 },
-       { 0x03, KEY_2 },
-       { 0x04, KEY_3 },
-       { 0x05, KEY_4 },
-       { 0x1c, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x1d, KEY_9 },
-       { 0x0a, KEY_0 },
-
-       { 0x09, KEY_LIST },             /* -/-- */
-       { 0x0b, KEY_LAST },             /* recall */
-
-       { 0x14, KEY_HOME },             /* win start menu */
-       { 0x15, KEY_EXIT },             /* exit */
-       { 0x16, KEY_CHANNELUP },        /* UP */
-       { 0x12, KEY_CHANNELDOWN },      /* DOWN */
-       { 0x0c, KEY_VOLUMEUP },         /* RIGHT */
-       { 0x17, KEY_VOLUMEDOWN },       /* LEFT */
-
-       { 0x18, KEY_ENTER },            /* OK */
-
-       { 0x0e, KEY_ESC },
-       { 0x13, KEY_CYCLEWINDOWS },     /* desktop */
-       { 0x11, KEY_TAB },
-       { 0x19, KEY_SWITCHVIDEOMODE },  /* switch */
-
-       { 0x1a, KEY_MENU },
-       { 0x1b, KEY_ZOOM },             /* fullscreen */
-       { 0x44, KEY_TIME },             /* time shift */
-       { 0x40, KEY_MODE },             /* source */
-
-       { 0x5a, KEY_RECORD },
-       { 0x42, KEY_PLAY },             /* play/pause */
-       { 0x45, KEY_STOP },
-       { 0x43, KEY_CAMERA },           /* camera icon */
-
-       { 0x48, KEY_REWIND },
-       { 0x4a, KEY_FASTFORWARD },
-       { 0x49, KEY_PREVIOUS },
-       { 0x4b, KEY_NEXT },
-
-       { 0x4c, KEY_FAVORITES },        /* tv wall */
-       { 0x4d, KEY_SOUND },            /* DVD sound */
-       { 0x4e, KEY_LANGUAGE },         /* DVD lang */
-       { 0x4f, KEY_TEXT },             /* DVD text */
-
-       { 0x50, KEY_SLEEP },            /* shutdown */
-       { 0x51, KEY_MODE },             /* stereo > main */
-       { 0x52, KEY_SELECT },           /* stereo > sap */
-       { 0x53, KEY_PROG1 },            /* teletext */
-
-
-       { 0x59, KEY_RED },              /* AP1 */
-       { 0x41, KEY_GREEN },            /* AP2 */
-       { 0x47, KEY_YELLOW },           /* AP3 */
-       { 0x57, KEY_BLUE },             /* AP4 */
-};
-
-struct ir_scancode_table ir_codes_encore_enltv_table = {
-       .scan = ir_codes_encore_enltv,
-       .size = ARRAY_SIZE(ir_codes_encore_enltv),
-};
-EXPORT_SYMBOL_GPL(ir_codes_encore_enltv_table);
-
-/* Encore ENLTV2-FM  - silver plastic - "Wand Media" written at the botton
-    Mauro Carvalho Chehab <mchehab@infradead.org> */
-static struct ir_scancode ir_codes_encore_enltv2[] = {
-       { 0x4c, KEY_POWER2 },
-       { 0x4a, KEY_TUNER },
-       { 0x40, KEY_1 },
-       { 0x60, KEY_2 },
-       { 0x50, KEY_3 },
-       { 0x70, KEY_4 },
-       { 0x48, KEY_5 },
-       { 0x68, KEY_6 },
-       { 0x58, KEY_7 },
-       { 0x78, KEY_8 },
-       { 0x44, KEY_9 },
-       { 0x54, KEY_0 },
-
-       { 0x64, KEY_LAST },             /* +100 */
-       { 0x4e, KEY_AGAIN },            /* Recall */
-
-       { 0x6c, KEY_SWITCHVIDEOMODE },  /* Video Source */
-       { 0x5e, KEY_MENU },
-       { 0x56, KEY_SCREEN },
-       { 0x7a, KEY_SETUP },
-
-       { 0x46, KEY_MUTE },
-       { 0x5c, KEY_MODE },             /* Stereo */
-       { 0x74, KEY_INFO },
-       { 0x7c, KEY_CLEAR },
-
-       { 0x55, KEY_UP },
-       { 0x49, KEY_DOWN },
-       { 0x7e, KEY_LEFT },
-       { 0x59, KEY_RIGHT },
-       { 0x6a, KEY_ENTER },
-
-       { 0x42, KEY_VOLUMEUP },
-       { 0x62, KEY_VOLUMEDOWN },
-       { 0x52, KEY_CHANNELUP },
-       { 0x72, KEY_CHANNELDOWN },
-
-       { 0x41, KEY_RECORD },
-       { 0x51, KEY_CAMERA },           /* Snapshot */
-       { 0x75, KEY_TIME },             /* Timeshift */
-       { 0x71, KEY_TV2 },              /* PIP */
-
-       { 0x45, KEY_REWIND },
-       { 0x6f, KEY_PAUSE },
-       { 0x7d, KEY_FORWARD },
-       { 0x79, KEY_STOP },
-};
-
-struct ir_scancode_table ir_codes_encore_enltv2_table = {
-       .scan = ir_codes_encore_enltv2,
-       .size = ARRAY_SIZE(ir_codes_encore_enltv2),
-};
-EXPORT_SYMBOL_GPL(ir_codes_encore_enltv2_table);
-
-/* for the Technotrend 1500 bundled remotes (grey and black): */
-static struct ir_scancode ir_codes_tt_1500[] = {
-       { 0x01, KEY_POWER },
-       { 0x02, KEY_SHUFFLE },          /* ? double-arrow key */
-       { 0x03, KEY_1 },
-       { 0x04, KEY_2 },
-       { 0x05, KEY_3 },
-       { 0x06, KEY_4 },
-       { 0x07, KEY_5 },
-       { 0x08, KEY_6 },
-       { 0x09, KEY_7 },
-       { 0x0a, KEY_8 },
-       { 0x0b, KEY_9 },
-       { 0x0c, KEY_0 },
-       { 0x0d, KEY_UP },
-       { 0x0e, KEY_LEFT },
-       { 0x0f, KEY_OK },
-       { 0x10, KEY_RIGHT },
-       { 0x11, KEY_DOWN },
-       { 0x12, KEY_INFO },
-       { 0x13, KEY_EXIT },
-       { 0x14, KEY_RED },
-       { 0x15, KEY_GREEN },
-       { 0x16, KEY_YELLOW },
-       { 0x17, KEY_BLUE },
-       { 0x18, KEY_MUTE },
-       { 0x19, KEY_TEXT },
-       { 0x1a, KEY_MODE },             /* ? TV/Radio */
-       { 0x21, KEY_OPTION },
-       { 0x22, KEY_EPG },
-       { 0x23, KEY_CHANNELUP },
-       { 0x24, KEY_CHANNELDOWN },
-       { 0x25, KEY_VOLUMEUP },
-       { 0x26, KEY_VOLUMEDOWN },
-       { 0x27, KEY_SETUP },
-       { 0x3a, KEY_RECORD },           /* these keys are only in the black remote */
-       { 0x3b, KEY_PLAY },
-       { 0x3c, KEY_STOP },
-       { 0x3d, KEY_REWIND },
-       { 0x3e, KEY_PAUSE },
-       { 0x3f, KEY_FORWARD },
-};
-
-struct ir_scancode_table ir_codes_tt_1500_table = {
-       .scan = ir_codes_tt_1500,
-       .size = ARRAY_SIZE(ir_codes_tt_1500),
-};
-EXPORT_SYMBOL_GPL(ir_codes_tt_1500_table);
-
-/* DViCO FUSION HDTV MCE remote */
-static struct ir_scancode ir_codes_fusionhdtv_mce[] = {
-
-       { 0x0b, KEY_1 },
-       { 0x17, KEY_2 },
-       { 0x1b, KEY_3 },
-       { 0x07, KEY_4 },
-       { 0x50, KEY_5 },
-       { 0x54, KEY_6 },
-       { 0x48, KEY_7 },
-       { 0x4c, KEY_8 },
-       { 0x58, KEY_9 },
-       { 0x03, KEY_0 },
-
-       { 0x5e, KEY_OK },
-       { 0x51, KEY_UP },
-       { 0x53, KEY_DOWN },
-       { 0x5b, KEY_LEFT },
-       { 0x5f, KEY_RIGHT },
-
-       { 0x02, KEY_TV },               /* Labeled DTV on remote */
-       { 0x0e, KEY_MP3 },
-       { 0x1a, KEY_DVD },
-       { 0x1e, KEY_FAVORITES },        /* Labeled CPF on remote */
-       { 0x16, KEY_SETUP },
-       { 0x46, KEY_POWER2 },           /* TV On/Off button on remote */
-       { 0x0a, KEY_EPG },              /* Labeled Guide on remote */
-
-       { 0x49, KEY_BACK },
-       { 0x59, KEY_INFO },             /* Labeled MORE on remote */
-       { 0x4d, KEY_MENU },             /* Labeled DVDMENU on remote */
-       { 0x55, KEY_CYCLEWINDOWS },     /* Labeled ALT-TAB on remote */
-
-       { 0x0f, KEY_PREVIOUSSONG },     /* Labeled |<< REPLAY on remote */
-       { 0x12, KEY_NEXTSONG },         /* Labeled >>| SKIP on remote */
-       { 0x42, KEY_ENTER },            /* Labeled START with a green
-                                          MS windows logo on remote */
-
-       { 0x15, KEY_VOLUMEUP },
-       { 0x05, KEY_VOLUMEDOWN },
-       { 0x11, KEY_CHANNELUP },
-       { 0x09, KEY_CHANNELDOWN },
-
-       { 0x52, KEY_CAMERA },
-       { 0x5a, KEY_TUNER },
-       { 0x19, KEY_OPEN },
-
-       { 0x13, KEY_MODE },             /* 4:3 16:9 select */
-       { 0x1f, KEY_ZOOM },
-
-       { 0x43, KEY_REWIND },
-       { 0x47, KEY_PLAYPAUSE },
-       { 0x4f, KEY_FASTFORWARD },
-       { 0x57, KEY_MUTE },
-       { 0x0d, KEY_STOP },
-       { 0x01, KEY_RECORD },
-       { 0x4e, KEY_POWER },
-};
-
-struct ir_scancode_table ir_codes_fusionhdtv_mce_table = {
-       .scan = ir_codes_fusionhdtv_mce,
-       .size = ARRAY_SIZE(ir_codes_fusionhdtv_mce),
-};
-EXPORT_SYMBOL_GPL(ir_codes_fusionhdtv_mce_table);
-
-/* Pinnacle PCTV HD 800i mini remote */
-static struct ir_scancode ir_codes_pinnacle_pctv_hd[] = {
-
-       { 0x0f, KEY_1 },
-       { 0x15, KEY_2 },
-       { 0x10, KEY_3 },
-       { 0x18, KEY_4 },
-       { 0x1b, KEY_5 },
-       { 0x1e, KEY_6 },
-       { 0x11, KEY_7 },
-       { 0x21, KEY_8 },
-       { 0x12, KEY_9 },
-       { 0x27, KEY_0 },
-
-       { 0x24, KEY_ZOOM },
-       { 0x2a, KEY_SUBTITLE },
-
-       { 0x00, KEY_MUTE },
-       { 0x01, KEY_ENTER },    /* Pinnacle Logo */
-       { 0x39, KEY_POWER },
-
-       { 0x03, KEY_VOLUMEUP },
-       { 0x09, KEY_VOLUMEDOWN },
-       { 0x06, KEY_CHANNELUP },
-       { 0x0c, KEY_CHANNELDOWN },
-
-       { 0x2d, KEY_REWIND },
-       { 0x30, KEY_PLAYPAUSE },
-       { 0x33, KEY_FASTFORWARD },
-       { 0x3c, KEY_STOP },
-       { 0x36, KEY_RECORD },
-       { 0x3f, KEY_EPG },      /* Labeled "?" */
-};
-
-struct ir_scancode_table ir_codes_pinnacle_pctv_hd_table = {
-       .scan = ir_codes_pinnacle_pctv_hd,
-       .size = ARRAY_SIZE(ir_codes_pinnacle_pctv_hd),
-};
-EXPORT_SYMBOL_GPL(ir_codes_pinnacle_pctv_hd_table);
-
-/*
- * Igor Kuznetsov <igk72@ya.ru>
- * Andrey J. Melnikov <temnota@kmv.ru>
- *
- * Keytable is used by BeholdTV 60x series, M6 series at
- * least, and probably other cards too.
- * The "ascii-art picture" below (in comments, first row
- * is the keycode in hex, and subsequent row(s) shows
- * the button labels (several variants when appropriate)
- * helps to descide which keycodes to assign to the buttons.
- */
-static struct ir_scancode ir_codes_behold[] = {
-
-       /*  0x1c            0x12  *
-        *  TV/FM          POWER  *
-        *                        */
-       { 0x1c, KEY_TUNER },    /* XXX KEY_TV / KEY_RADIO */
-       { 0x12, KEY_POWER },
-
-       /*  0x01    0x02    0x03  *
-        *   1       2       3    *
-        *                        *
-        *  0x04    0x05    0x06  *
-        *   4       5       6    *
-        *                        *
-        *  0x07    0x08    0x09  *
-        *   7       8       9    *
-        *                        */
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-
-       /*  0x0a    0x00    0x17  *
-        * RECALL    0      MODE  *
-        *                        */
-       { 0x0a, KEY_AGAIN },
-       { 0x00, KEY_0 },
-       { 0x17, KEY_MODE },
-
-       /*  0x14          0x10    *
-        * ASPECT      FULLSCREEN *
-        *                        */
-       { 0x14, KEY_SCREEN },
-       { 0x10, KEY_ZOOM },
-
-       /*          0x0b          *
-        *           Up           *
-        *                        *
-        *  0x18    0x16    0x0c  *
-        *  Left     Ok     Right *
-        *                        *
-        *         0x015          *
-        *         Down           *
-        *                        */
-       { 0x0b, KEY_CHANNELUP },
-       { 0x18, KEY_VOLUMEDOWN },
-       { 0x16, KEY_OK },               /* XXX KEY_ENTER */
-       { 0x0c, KEY_VOLUMEUP },
-       { 0x15, KEY_CHANNELDOWN },
-
-       /*  0x11            0x0d  *
-        *  MUTE            INFO  *
-        *                        */
-       { 0x11, KEY_MUTE },
-       { 0x0d, KEY_INFO },
-
-       /*  0x0f    0x1b    0x1a  *
-        * RECORD PLAY/PAUSE STOP *
-        *                        *
-        *  0x0e    0x1f    0x1e  *
-        *TELETEXT  AUDIO  SOURCE *
-        *           RED   YELLOW *
-        *                        */
-       { 0x0f, KEY_RECORD },
-       { 0x1b, KEY_PLAYPAUSE },
-       { 0x1a, KEY_STOP },
-       { 0x0e, KEY_TEXT },
-       { 0x1f, KEY_RED },      /*XXX KEY_AUDIO */
-       { 0x1e, KEY_YELLOW },   /*XXX KEY_SOURCE        */
-
-       /*  0x1d   0x13     0x19  *
-        * SLEEP  PREVIEW   DVB   *
-        *         GREEN    BLUE  *
-        *                        */
-       { 0x1d, KEY_SLEEP },
-       { 0x13, KEY_GREEN },
-       { 0x19, KEY_BLUE },     /* XXX KEY_SAT  */
-
-       /*  0x58           0x5c   *
-        * FREEZE        SNAPSHOT *
-        *                        */
-       { 0x58, KEY_SLOW },
-       { 0x5c, KEY_CAMERA },
-
-};
-
-struct ir_scancode_table ir_codes_behold_table = {
-       .scan = ir_codes_behold,
-       .size = ARRAY_SIZE(ir_codes_behold),
-};
-EXPORT_SYMBOL_GPL(ir_codes_behold_table);
-
-/* Beholder Intl. Ltd. 2008
- * Dmitry Belimov d.belimov@google.com
- * Keytable is used by BeholdTV Columbus
- * The "ascii-art picture" below (in comments, first row
- * is the keycode in hex, and subsequent row(s) shows
- * the button labels (several variants when appropriate)
- * helps to descide which keycodes to assign to the buttons.
- */
-static struct ir_scancode ir_codes_behold_columbus[] = {
-
-       /*  0x13   0x11   0x1C   0x12  *
-        *  Mute  Source  TV/FM  Power *
-        *                             */
-
-       { 0x13, KEY_MUTE },
-       { 0x11, KEY_PROPS },
-       { 0x1C, KEY_TUNER },    /* KEY_TV/KEY_RADIO     */
-       { 0x12, KEY_POWER },
-
-       /*  0x01    0x02    0x03  0x0D    *
-        *   1       2       3   Stereo   *
-        *                                *
-        *  0x04    0x05    0x06  0x19    *
-        *   4       5       6   Snapshot *
-        *                                *
-        *  0x07    0x08    0x09  0x10    *
-        *   7       8       9    Zoom    *
-        *                                */
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x0D, KEY_SETUP },      /* Setup key */
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x19, KEY_CAMERA },   /* Snapshot key */
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-       { 0x10, KEY_ZOOM },
-
-       /*  0x0A    0x00    0x0B       0x0C   *
-        * RECALL    0    ChannelUp  VolumeUp *
-        *                                    */
-       { 0x0A, KEY_AGAIN },
-       { 0x00, KEY_0 },
-       { 0x0B, KEY_CHANNELUP },
-       { 0x0C, KEY_VOLUMEUP },
-
-       /*   0x1B      0x1D      0x15        0x18     *
-        * Timeshift  Record  ChannelDown  VolumeDown *
-        *                                            */
-
-       { 0x1B, KEY_TIME },
-       { 0x1D, KEY_RECORD },
-       { 0x15, KEY_CHANNELDOWN },
-       { 0x18, KEY_VOLUMEDOWN },
-
-       /*   0x0E   0x1E     0x0F     0x1A  *
-        *   Stop   Pause  Previouse  Next  *
-        *                                  */
-
-       { 0x0E, KEY_STOP },
-       { 0x1E, KEY_PAUSE },
-       { 0x0F, KEY_PREVIOUS },
-       { 0x1A, KEY_NEXT },
-
-};
-
-struct ir_scancode_table ir_codes_behold_columbus_table = {
-       .scan = ir_codes_behold_columbus,
-       .size = ARRAY_SIZE(ir_codes_behold_columbus),
-};
-EXPORT_SYMBOL_GPL(ir_codes_behold_columbus_table);
-
-/*
- * Remote control for the Genius TVGO A11MCE
- * Adrian Pardini <pardo.bsso@gmail.com>
- */
-static struct ir_scancode ir_codes_genius_tvgo_a11mce[] = {
-       /* Keys 0 to 9 */
-       { 0x48, KEY_0 },
-       { 0x09, KEY_1 },
-       { 0x1d, KEY_2 },
-       { 0x1f, KEY_3 },
-       { 0x19, KEY_4 },
-       { 0x1b, KEY_5 },
-       { 0x11, KEY_6 },
-       { 0x17, KEY_7 },
-       { 0x12, KEY_8 },
-       { 0x16, KEY_9 },
-
-       { 0x54, KEY_RECORD },           /* recording */
-       { 0x06, KEY_MUTE },             /* mute */
-       { 0x10, KEY_POWER },
-       { 0x40, KEY_LAST },             /* recall */
-       { 0x4c, KEY_CHANNELUP },        /* channel / program + */
-       { 0x00, KEY_CHANNELDOWN },      /* channel / program - */
-       { 0x0d, KEY_VOLUMEUP },
-       { 0x15, KEY_VOLUMEDOWN },
-       { 0x4d, KEY_OK },               /* also labeled as Pause */
-       { 0x1c, KEY_ZOOM },             /* full screen and Stop*/
-       { 0x02, KEY_MODE },             /* AV Source or Rewind*/
-       { 0x04, KEY_LIST },             /* -/-- */
-       /* small arrows above numbers */
-       { 0x1a, KEY_NEXT },             /* also Fast Forward */
-       { 0x0e, KEY_PREVIOUS },         /* also Rewind */
-       /* these are in a rather non standard layout and have
-       an alternate name written */
-       { 0x1e, KEY_UP },               /* Video Setting */
-       { 0x0a, KEY_DOWN },             /* Video Default */
-       { 0x05, KEY_CAMERA },           /* Snapshot */
-       { 0x0c, KEY_RIGHT },            /* Hide Panel */
-       /* Four buttons without label */
-       { 0x49, KEY_RED },
-       { 0x0b, KEY_GREEN },
-       { 0x13, KEY_YELLOW },
-       { 0x50, KEY_BLUE },
-};
-
-struct ir_scancode_table ir_codes_genius_tvgo_a11mce_table = {
-       .scan = ir_codes_genius_tvgo_a11mce,
-       .size = ARRAY_SIZE(ir_codes_genius_tvgo_a11mce),
-};
-EXPORT_SYMBOL_GPL(ir_codes_genius_tvgo_a11mce_table);
-
-/*
- * Remote control for Powercolor Real Angel 330
- * Daniel Fraga <fragabr@gmail.com>
- */
-static struct ir_scancode ir_codes_powercolor_real_angel[] = {
-       { 0x38, KEY_SWITCHVIDEOMODE },  /* switch inputs */
-       { 0x0c, KEY_MEDIA },            /* Turn ON/OFF App */
-       { 0x00, KEY_0 },
-       { 0x01, KEY_1 },
-       { 0x02, KEY_2 },
-       { 0x03, KEY_3 },
-       { 0x04, KEY_4 },
-       { 0x05, KEY_5 },
-       { 0x06, KEY_6 },
-       { 0x07, KEY_7 },
-       { 0x08, KEY_8 },
-       { 0x09, KEY_9 },
-       { 0x0a, KEY_DIGITS },           /* single, double, tripple digit */
-       { 0x29, KEY_PREVIOUS },         /* previous channel */
-       { 0x12, KEY_BRIGHTNESSUP },
-       { 0x13, KEY_BRIGHTNESSDOWN },
-       { 0x2b, KEY_MODE },             /* stereo/mono */
-       { 0x2c, KEY_TEXT },             /* teletext */
-       { 0x20, KEY_CHANNELUP },        /* channel up */
-       { 0x21, KEY_CHANNELDOWN },      /* channel down */
-       { 0x10, KEY_VOLUMEUP },         /* volume up */
-       { 0x11, KEY_VOLUMEDOWN },       /* volume down */
-       { 0x0d, KEY_MUTE },
-       { 0x1f, KEY_RECORD },
-       { 0x17, KEY_PLAY },
-       { 0x16, KEY_PAUSE },
-       { 0x0b, KEY_STOP },
-       { 0x27, KEY_FASTFORWARD },
-       { 0x26, KEY_REWIND },
-       { 0x1e, KEY_SEARCH },           /* autoscan */
-       { 0x0e, KEY_CAMERA },           /* snapshot */
-       { 0x2d, KEY_SETUP },
-       { 0x0f, KEY_SCREEN },           /* full screen */
-       { 0x14, KEY_RADIO },            /* FM radio */
-       { 0x25, KEY_POWER },            /* power */
-};
-
-struct ir_scancode_table ir_codes_powercolor_real_angel_table = {
-       .scan = ir_codes_powercolor_real_angel,
-       .size = ARRAY_SIZE(ir_codes_powercolor_real_angel),
-};
-EXPORT_SYMBOL_GPL(ir_codes_powercolor_real_angel_table);
-
-/* Kworld Plus TV Analog Lite PCI IR
-   Mauro Carvalho Chehab <mchehab@infradead.org>
- */
-static struct ir_scancode ir_codes_kworld_plus_tv_analog[] = {
-       { 0x0c, KEY_PROG1 },            /* Kworld key */
-       { 0x16, KEY_CLOSECD },          /* -> ) */
-       { 0x1d, KEY_POWER2 },
-
-       { 0x00, KEY_1 },
-       { 0x01, KEY_2 },
-       { 0x02, KEY_3 },                /* Two keys have the same code: 3 and left */
-       { 0x03, KEY_4 },                /* Two keys have the same code: 3 and right */
-       { 0x04, KEY_5 },
-       { 0x05, KEY_6 },
-       { 0x06, KEY_7 },
-       { 0x07, KEY_8 },
-       { 0x08, KEY_9 },
-       { 0x0a, KEY_0 },
-
-       { 0x09, KEY_AGAIN },
-       { 0x14, KEY_MUTE },
-
-       { 0x20, KEY_UP },
-       { 0x21, KEY_DOWN },
-       { 0x0b, KEY_ENTER },
-
-       { 0x10, KEY_CHANNELUP },
-       { 0x11, KEY_CHANNELDOWN },
-
-       /* Couldn't map key left/key right since those
-          conflict with '3' and '4' scancodes
-          I dunno what the original driver does
-        */
-
-       { 0x13, KEY_VOLUMEUP },
-       { 0x12, KEY_VOLUMEDOWN },
-
-       /* The lower part of the IR
-          There are several duplicated keycodes there.
-          Most of them conflict with digits.
-          Add mappings just to the unused scancodes.
-          Somehow, the original driver has a way to know,
-          but this doesn't seem to be on some GPIO.
-          Also, it is not related to the time between keyup
-          and keydown.
-        */
-       { 0x19, KEY_TIME},              /* Timeshift */
-       { 0x1a, KEY_STOP},
-       { 0x1b, KEY_RECORD},
-
-       { 0x22, KEY_TEXT},
-
-       { 0x15, KEY_AUDIO},             /* ((*)) */
-       { 0x0f, KEY_ZOOM},
-       { 0x1c, KEY_CAMERA},            /* snapshot */
-
-       { 0x18, KEY_RED},               /* B */
-       { 0x23, KEY_GREEN},             /* C */
-};
-struct ir_scancode_table ir_codes_kworld_plus_tv_analog_table = {
-       .scan = ir_codes_kworld_plus_tv_analog,
-       .size = ARRAY_SIZE(ir_codes_kworld_plus_tv_analog),
-};
-EXPORT_SYMBOL_GPL(ir_codes_kworld_plus_tv_analog_table);
-
-/* Kaiomy TVnPC U2
-   Mauro Carvalho Chehab <mchehab@infradead.org>
- */
-static struct ir_scancode ir_codes_kaiomy[] = {
-       { 0x43, KEY_POWER2},
-       { 0x01, KEY_LIST},
-       { 0x0b, KEY_ZOOM},
-       { 0x03, KEY_POWER},
-
-       { 0x04, KEY_1},
-       { 0x08, KEY_2},
-       { 0x02, KEY_3},
-
-       { 0x0f, KEY_4},
-       { 0x05, KEY_5},
-       { 0x06, KEY_6},
-
-       { 0x0c, KEY_7},
-       { 0x0d, KEY_8},
-       { 0x0a, KEY_9},
-
-       { 0x11, KEY_0},
-
-       { 0x09, KEY_CHANNELUP},
-       { 0x07, KEY_CHANNELDOWN},
-
-       { 0x0e, KEY_VOLUMEUP},
-       { 0x13, KEY_VOLUMEDOWN},
-
-       { 0x10, KEY_HOME},
-       { 0x12, KEY_ENTER},
-
-       { 0x14, KEY_RECORD},
-       { 0x15, KEY_STOP},
-       { 0x16, KEY_PLAY},
-       { 0x17, KEY_MUTE},
-
-       { 0x18, KEY_UP},
-       { 0x19, KEY_DOWN},
-       { 0x1a, KEY_LEFT},
-       { 0x1b, KEY_RIGHT},
-
-       { 0x1c, KEY_RED},
-       { 0x1d, KEY_GREEN},
-       { 0x1e, KEY_YELLOW},
-       { 0x1f, KEY_BLUE},
-};
-struct ir_scancode_table ir_codes_kaiomy_table = {
-       .scan = ir_codes_kaiomy,
-       .size = ARRAY_SIZE(ir_codes_kaiomy),
-};
-EXPORT_SYMBOL_GPL(ir_codes_kaiomy_table);
-
-static struct ir_scancode ir_codes_avermedia_a16d[] = {
-       { 0x20, KEY_LIST},
-       { 0x00, KEY_POWER},
-       { 0x28, KEY_1},
-       { 0x18, KEY_2},
-       { 0x38, KEY_3},
-       { 0x24, KEY_4},
-       { 0x14, KEY_5},
-       { 0x34, KEY_6},
-       { 0x2c, KEY_7},
-       { 0x1c, KEY_8},
-       { 0x3c, KEY_9},
-       { 0x12, KEY_SUBTITLE},
-       { 0x22, KEY_0},
-       { 0x32, KEY_REWIND},
-       { 0x3a, KEY_SHUFFLE},
-       { 0x02, KEY_PRINT},
-       { 0x11, KEY_CHANNELDOWN},
-       { 0x31, KEY_CHANNELUP},
-       { 0x0c, KEY_ZOOM},
-       { 0x1e, KEY_VOLUMEDOWN},
-       { 0x3e, KEY_VOLUMEUP},
-       { 0x0a, KEY_MUTE},
-       { 0x04, KEY_AUDIO},
-       { 0x26, KEY_RECORD},
-       { 0x06, KEY_PLAY},
-       { 0x36, KEY_STOP},
-       { 0x16, KEY_PAUSE},
-       { 0x2e, KEY_REWIND},
-       { 0x0e, KEY_FASTFORWARD},
-       { 0x30, KEY_TEXT},
-       { 0x21, KEY_GREEN},
-       { 0x01, KEY_BLUE},
-       { 0x08, KEY_EPG},
-       { 0x2a, KEY_MENU},
-};
-struct ir_scancode_table ir_codes_avermedia_a16d_table = {
-       .scan = ir_codes_avermedia_a16d,
-       .size = ARRAY_SIZE(ir_codes_avermedia_a16d),
-};
-EXPORT_SYMBOL_GPL(ir_codes_avermedia_a16d_table);
-
-/* Encore ENLTV-FM v5.3
-   Mauro Carvalho Chehab <mchehab@infradead.org>
- */
-static struct ir_scancode ir_codes_encore_enltv_fm53[] = {
-       { 0x10, KEY_POWER2},
-       { 0x06, KEY_MUTE},
-
-       { 0x09, KEY_1},
-       { 0x1d, KEY_2},
-       { 0x1f, KEY_3},
-       { 0x19, KEY_4},
-       { 0x1b, KEY_5},
-       { 0x11, KEY_6},
-       { 0x17, KEY_7},
-       { 0x12, KEY_8},
-       { 0x16, KEY_9},
-       { 0x48, KEY_0},
-
-       { 0x04, KEY_LIST},              /* -/-- */
-       { 0x40, KEY_LAST},              /* recall */
-
-       { 0x02, KEY_MODE},              /* TV/AV */
-       { 0x05, KEY_CAMERA},            /* SNAPSHOT */
-
-       { 0x4c, KEY_CHANNELUP},         /* UP */
-       { 0x00, KEY_CHANNELDOWN},       /* DOWN */
-       { 0x0d, KEY_VOLUMEUP},          /* RIGHT */
-       { 0x15, KEY_VOLUMEDOWN},        /* LEFT */
-       { 0x49, KEY_ENTER},             /* OK */
-
-       { 0x54, KEY_RECORD},
-       { 0x4d, KEY_PLAY},              /* pause */
-
-       { 0x1e, KEY_MENU},              /* video setting */
-       { 0x0e, KEY_RIGHT},             /* <- */
-       { 0x1a, KEY_LEFT},              /* -> */
-
-       { 0x0a, KEY_CLEAR},             /* video default */
-       { 0x0c, KEY_ZOOM},              /* hide pannel */
-       { 0x47, KEY_SLEEP},             /* shutdown */
-};
-struct ir_scancode_table ir_codes_encore_enltv_fm53_table = {
-       .scan = ir_codes_encore_enltv_fm53,
-       .size = ARRAY_SIZE(ir_codes_encore_enltv_fm53),
-};
-EXPORT_SYMBOL_GPL(ir_codes_encore_enltv_fm53_table);
-
-/* Zogis Real Audio 220 - 32 keys IR */
-static struct ir_scancode ir_codes_real_audio_220_32_keys[] = {
-       { 0x1c, KEY_RADIO},
-       { 0x12, KEY_POWER2},
-
-       { 0x01, KEY_1},
-       { 0x02, KEY_2},
-       { 0x03, KEY_3},
-       { 0x04, KEY_4},
-       { 0x05, KEY_5},
-       { 0x06, KEY_6},
-       { 0x07, KEY_7},
-       { 0x08, KEY_8},
-       { 0x09, KEY_9},
-       { 0x00, KEY_0},
-
-       { 0x0c, KEY_VOLUMEUP},
-       { 0x18, KEY_VOLUMEDOWN},
-       { 0x0b, KEY_CHANNELUP},
-       { 0x15, KEY_CHANNELDOWN},
-       { 0x16, KEY_ENTER},
-
-       { 0x11, KEY_LIST},              /* Source */
-       { 0x0d, KEY_AUDIO},             /* stereo */
-
-       { 0x0f, KEY_PREVIOUS},          /* Prev */
-       { 0x1b, KEY_TIME},              /* Timeshift */
-       { 0x1a, KEY_NEXT},              /* Next */
-
-       { 0x0e, KEY_STOP},
-       { 0x1f, KEY_PLAY},
-       { 0x1e, KEY_PLAYPAUSE},         /* Pause */
-
-       { 0x1d, KEY_RECORD},
-       { 0x13, KEY_MUTE},
-       { 0x19, KEY_CAMERA},            /* Snapshot */
-
-};
-struct ir_scancode_table ir_codes_real_audio_220_32_keys_table = {
-       .scan = ir_codes_real_audio_220_32_keys,
-       .size = ARRAY_SIZE(ir_codes_real_audio_220_32_keys),
-};
-EXPORT_SYMBOL_GPL(ir_codes_real_audio_220_32_keys_table);
-
-/* ATI TV Wonder HD 600 USB
-   Devin Heitmueller <devin.heitmueller@gmail.com>
- */
-static struct ir_scancode ir_codes_ati_tv_wonder_hd_600[] = {
-       { 0x00, KEY_RECORD},            /* Row 1 */
-       { 0x01, KEY_PLAYPAUSE},
-       { 0x02, KEY_STOP},
-       { 0x03, KEY_POWER},
-       { 0x04, KEY_PREVIOUS},  /* Row 2 */
-       { 0x05, KEY_REWIND},
-       { 0x06, KEY_FORWARD},
-       { 0x07, KEY_NEXT},
-       { 0x08, KEY_EPG},               /* Row 3 */
-       { 0x09, KEY_HOME},
-       { 0x0a, KEY_MENU},
-       { 0x0b, KEY_CHANNELUP},
-       { 0x0c, KEY_BACK},              /* Row 4 */
-       { 0x0d, KEY_UP},
-       { 0x0e, KEY_INFO},
-       { 0x0f, KEY_CHANNELDOWN},
-       { 0x10, KEY_LEFT},              /* Row 5 */
-       { 0x11, KEY_SELECT},
-       { 0x12, KEY_RIGHT},
-       { 0x13, KEY_VOLUMEUP},
-       { 0x14, KEY_LAST},              /* Row 6 */
-       { 0x15, KEY_DOWN},
-       { 0x16, KEY_MUTE},
-       { 0x17, KEY_VOLUMEDOWN},
-};
-struct ir_scancode_table ir_codes_ati_tv_wonder_hd_600_table = {
-       .scan = ir_codes_ati_tv_wonder_hd_600,
-       .size = ARRAY_SIZE(ir_codes_ati_tv_wonder_hd_600),
-};
-EXPORT_SYMBOL_GPL(ir_codes_ati_tv_wonder_hd_600_table);
-
-/* DVBWorld remotes
-   Igor M. Liplianin <liplianin@me.by>
- */
-static struct ir_scancode ir_codes_dm1105_nec[] = {
-       { 0x0a, KEY_POWER2},            /* power */
-       { 0x0c, KEY_MUTE},              /* mute */
-       { 0x11, KEY_1},
-       { 0x12, KEY_2},
-       { 0x13, KEY_3},
-       { 0x14, KEY_4},
-       { 0x15, KEY_5},
-       { 0x16, KEY_6},
-       { 0x17, KEY_7},
-       { 0x18, KEY_8},
-       { 0x19, KEY_9},
-       { 0x10, KEY_0},
-       { 0x1c, KEY_CHANNELUP},         /* ch+ */
-       { 0x0f, KEY_CHANNELDOWN},       /* ch- */
-       { 0x1a, KEY_VOLUMEUP},          /* vol+ */
-       { 0x0e, KEY_VOLUMEDOWN},        /* vol- */
-       { 0x04, KEY_RECORD},            /* rec */
-       { 0x09, KEY_CHANNEL},           /* fav */
-       { 0x08, KEY_BACKSPACE},         /* rewind */
-       { 0x07, KEY_FASTFORWARD},       /* fast */
-       { 0x0b, KEY_PAUSE},             /* pause */
-       { 0x02, KEY_ESC},               /* cancel */
-       { 0x03, KEY_TAB},               /* tab */
-       { 0x00, KEY_UP},                /* up */
-       { 0x1f, KEY_ENTER},             /* ok */
-       { 0x01, KEY_DOWN},              /* down */
-       { 0x05, KEY_RECORD},            /* cap */
-       { 0x06, KEY_STOP},              /* stop */
-       { 0x40, KEY_ZOOM},              /* full */
-       { 0x1e, KEY_TV},                /* tvmode */
-       { 0x1b, KEY_B},                 /* recall */
-};
-struct ir_scancode_table ir_codes_dm1105_nec_table = {
-       .scan = ir_codes_dm1105_nec,
-       .size = ARRAY_SIZE(ir_codes_dm1105_nec),
-};
-EXPORT_SYMBOL_GPL(ir_codes_dm1105_nec_table);
-
-static struct ir_scancode ir_codes_tevii_nec[] = {
-       { 0x0a, KEY_POWER2},
-       { 0x0c, KEY_MUTE},
-       { 0x11, KEY_1},
-       { 0x12, KEY_2},
-       { 0x13, KEY_3},
-       { 0x14, KEY_4},
-       { 0x15, KEY_5},
-       { 0x16, KEY_6},
-       { 0x17, KEY_7},
-       { 0x18, KEY_8},
-       { 0x19, KEY_9},
-       { 0x10, KEY_0},
-       { 0x1c, KEY_MENU},
-       { 0x0f, KEY_VOLUMEDOWN},
-       { 0x1a, KEY_LAST},
-       { 0x0e, KEY_OPEN},
-       { 0x04, KEY_RECORD},
-       { 0x09, KEY_VOLUMEUP},
-       { 0x08, KEY_CHANNELUP},
-       { 0x07, KEY_PVR},
-       { 0x0b, KEY_TIME},
-       { 0x02, KEY_RIGHT},
-       { 0x03, KEY_LEFT},
-       { 0x00, KEY_UP},
-       { 0x1f, KEY_OK},
-       { 0x01, KEY_DOWN},
-       { 0x05, KEY_TUNER},
-       { 0x06, KEY_CHANNELDOWN},
-       { 0x40, KEY_PLAYPAUSE},
-       { 0x1e, KEY_REWIND},
-       { 0x1b, KEY_FAVORITES},
-       { 0x1d, KEY_BACK},
-       { 0x4d, KEY_FASTFORWARD},
-       { 0x44, KEY_EPG},
-       { 0x4c, KEY_INFO},
-       { 0x41, KEY_AB},
-       { 0x43, KEY_AUDIO},
-       { 0x45, KEY_SUBTITLE},
-       { 0x4a, KEY_LIST},
-       { 0x46, KEY_F1},
-       { 0x47, KEY_F2},
-       { 0x5e, KEY_F3},
-       { 0x5c, KEY_F4},
-       { 0x52, KEY_F5},
-       { 0x5a, KEY_F6},
-       { 0x56, KEY_MODE},
-       { 0x58, KEY_SWITCHVIDEOMODE},
-};
-struct ir_scancode_table ir_codes_tevii_nec_table = {
-       .scan = ir_codes_tevii_nec,
-       .size = ARRAY_SIZE(ir_codes_tevii_nec),
-};
-EXPORT_SYMBOL_GPL(ir_codes_tevii_nec_table);
-
-static struct ir_scancode ir_codes_tbs_nec[] = {
-       { 0x04, KEY_POWER2},    /*power*/
-       { 0x14, KEY_MUTE},      /*mute*/
-       { 0x07, KEY_1},
-       { 0x06, KEY_2},
-       { 0x05, KEY_3},
-       { 0x0b, KEY_4},
-       { 0x0a, KEY_5},
-       { 0x09, KEY_6},
-       { 0x0f, KEY_7},
-       { 0x0e, KEY_8},
-       { 0x0d, KEY_9},
-       { 0x12, KEY_0},
-       { 0x16, KEY_CHANNELUP}, /*ch+*/
-       { 0x11, KEY_CHANNELDOWN},/*ch-*/
-       { 0x13, KEY_VOLUMEUP},  /*vol+*/
-       { 0x0c, KEY_VOLUMEDOWN},/*vol-*/
-       { 0x03, KEY_RECORD},    /*rec*/
-       { 0x18, KEY_PAUSE},     /*pause*/
-       { 0x19, KEY_OK},        /*ok*/
-       { 0x1a, KEY_CAMERA},    /* snapshot */
-       { 0x01, KEY_UP},
-       { 0x10, KEY_LEFT},
-       { 0x02, KEY_RIGHT},
-       { 0x08, KEY_DOWN},
-       { 0x15, KEY_FAVORITES},
-       { 0x17, KEY_SUBTITLE},
-       { 0x1d, KEY_ZOOM},
-       { 0x1f, KEY_EXIT},
-       { 0x1e, KEY_MENU},
-       { 0x1c, KEY_EPG},
-       { 0x00, KEY_PREVIOUS},
-       { 0x1b, KEY_MODE},
-};
-struct ir_scancode_table ir_codes_tbs_nec_table = {
-       .scan = ir_codes_tbs_nec,
-       .size = ARRAY_SIZE(ir_codes_tbs_nec),
-};
-EXPORT_SYMBOL_GPL(ir_codes_tbs_nec_table);
-
-/* Terratec Cinergy Hybrid T USB XS
-   Devin Heitmueller <dheitmueller@linuxtv.org>
- */
-static struct ir_scancode ir_codes_terratec_cinergy_xs[] = {
-       { 0x41, KEY_HOME},
-       { 0x01, KEY_POWER},
-       { 0x42, KEY_MENU},
-       { 0x02, KEY_1},
-       { 0x03, KEY_2},
-       { 0x04, KEY_3},
-       { 0x43, KEY_SUBTITLE},
-       { 0x05, KEY_4},
-       { 0x06, KEY_5},
-       { 0x07, KEY_6},
-       { 0x44, KEY_TEXT},
-       { 0x08, KEY_7},
-       { 0x09, KEY_8},
-       { 0x0a, KEY_9},
-       { 0x45, KEY_DELETE},
-       { 0x0b, KEY_TUNER},
-       { 0x0c, KEY_0},
-       { 0x0d, KEY_MODE},
-       { 0x46, KEY_TV},
-       { 0x47, KEY_DVD},
-       { 0x49, KEY_VIDEO},
-       { 0x4b, KEY_AUX},
-       { 0x10, KEY_UP},
-       { 0x11, KEY_LEFT},
-       { 0x12, KEY_OK},
-       { 0x13, KEY_RIGHT},
-       { 0x14, KEY_DOWN},
-       { 0x0f, KEY_EPG},
-       { 0x16, KEY_INFO},
-       { 0x4d, KEY_BACKSPACE},
-       { 0x1c, KEY_VOLUMEUP},
-       { 0x4c, KEY_PLAY},
-       { 0x1b, KEY_CHANNELUP},
-       { 0x1e, KEY_VOLUMEDOWN},
-       { 0x1d, KEY_MUTE},
-       { 0x1f, KEY_CHANNELDOWN},
-       { 0x17, KEY_RED},
-       { 0x18, KEY_GREEN},
-       { 0x19, KEY_YELLOW},
-       { 0x1a, KEY_BLUE},
-       { 0x58, KEY_RECORD},
-       { 0x48, KEY_STOP},
-       { 0x40, KEY_PAUSE},
-       { 0x54, KEY_LAST},
-       { 0x4e, KEY_REWIND},
-       { 0x4f, KEY_FASTFORWARD},
-       { 0x5c, KEY_NEXT},
-};
-struct ir_scancode_table ir_codes_terratec_cinergy_xs_table = {
-       .scan = ir_codes_terratec_cinergy_xs,
-       .size = ARRAY_SIZE(ir_codes_terratec_cinergy_xs),
-};
-EXPORT_SYMBOL_GPL(ir_codes_terratec_cinergy_xs_table);
-
-/* EVGA inDtube
-   Devin Heitmueller <devin.heitmueller@gmail.com>
- */
-static struct ir_scancode ir_codes_evga_indtube[] = {
-       { 0x12, KEY_POWER},
-       { 0x02, KEY_MODE},      /* TV */
-       { 0x14, KEY_MUTE},
-       { 0x1a, KEY_CHANNELUP},
-       { 0x16, KEY_TV2},       /* PIP */
-       { 0x1d, KEY_VOLUMEUP},
-       { 0x05, KEY_CHANNELDOWN},
-       { 0x0f, KEY_PLAYPAUSE},
-       { 0x19, KEY_VOLUMEDOWN},
-       { 0x1c, KEY_REWIND},
-       { 0x0d, KEY_RECORD},
-       { 0x18, KEY_FORWARD},
-       { 0x1e, KEY_PREVIOUS},
-       { 0x1b, KEY_STOP},
-       { 0x1f, KEY_NEXT},
-       { 0x13, KEY_CAMERA},
-};
-struct ir_scancode_table ir_codes_evga_indtube_table = {
-       .scan = ir_codes_evga_indtube,
-       .size = ARRAY_SIZE(ir_codes_evga_indtube),
-};
-EXPORT_SYMBOL_GPL(ir_codes_evga_indtube_table);
-
-static struct ir_scancode ir_codes_videomate_s350[] = {
-       { 0x00, KEY_TV},
-       { 0x01, KEY_DVD},
-       { 0x04, KEY_RECORD},
-       { 0x05, KEY_VIDEO},     /* TV/Video */
-       { 0x07, KEY_STOP},
-       { 0x08, KEY_PLAYPAUSE},
-       { 0x0a, KEY_REWIND},
-       { 0x0f, KEY_FASTFORWARD},
-       { 0x10, KEY_CHANNELUP},
-       { 0x12, KEY_VOLUMEUP},
-       { 0x13, KEY_CHANNELDOWN},
-       { 0x14, KEY_MUTE},
-       { 0x15, KEY_VOLUMEDOWN},
-       { 0x16, KEY_1},
-       { 0x17, KEY_2},
-       { 0x18, KEY_3},
-       { 0x19, KEY_4},
-       { 0x1a, KEY_5},
-       { 0x1b, KEY_6},
-       { 0x1c, KEY_7},
-       { 0x1d, KEY_8},
-       { 0x1e, KEY_9},
-       { 0x1f, KEY_0},
-       { 0x21, KEY_SLEEP},
-       { 0x24, KEY_ZOOM},
-       { 0x25, KEY_LAST},      /* Recall */
-       { 0x26, KEY_SUBTITLE},  /* CC */
-       { 0x27, KEY_LANGUAGE},  /* MTS */
-       { 0x29, KEY_CHANNEL},   /* SURF */
-       { 0x2b, KEY_A},
-       { 0x2c, KEY_B},
-       { 0x2f, KEY_CAMERA},    /* Snapshot */
-       { 0x23, KEY_RADIO},
-       { 0x02, KEY_PREVIOUSSONG},
-       { 0x06, KEY_NEXTSONG},
-       { 0x03, KEY_EPG},
-       { 0x09, KEY_SETUP},
-       { 0x22, KEY_BACKSPACE},
-       { 0x0c, KEY_UP},
-       { 0x0e, KEY_DOWN},
-       { 0x0b, KEY_LEFT},
-       { 0x0d, KEY_RIGHT},
-       { 0x11, KEY_ENTER},
-       { 0x20, KEY_TEXT},
-};
-struct ir_scancode_table ir_codes_videomate_s350_table = {
-       .scan = ir_codes_videomate_s350,
-       .size = ARRAY_SIZE(ir_codes_videomate_s350),
-};
-EXPORT_SYMBOL_GPL(ir_codes_videomate_s350_table);
-
-/* GADMEI UTV330+ RM008Z remote
-   Shine Liu <shinel@foxmail.com>
- */
-static struct ir_scancode ir_codes_gadmei_rm008z[] = {
-       { 0x14, KEY_POWER2},            /* POWER OFF */
-       { 0x0c, KEY_MUTE},              /* MUTE */
-
-       { 0x18, KEY_TV},                /* TV */
-       { 0x0e, KEY_VIDEO},             /* AV */
-       { 0x0b, KEY_AUDIO},             /* SV */
-       { 0x0f, KEY_RADIO},             /* FM */
-
-       { 0x00, KEY_1},
-       { 0x01, KEY_2},
-       { 0x02, KEY_3},
-       { 0x03, KEY_4},
-       { 0x04, KEY_5},
-       { 0x05, KEY_6},
-       { 0x06, KEY_7},
-       { 0x07, KEY_8},
-       { 0x08, KEY_9},
-       { 0x09, KEY_0},
-       { 0x0a, KEY_INFO},              /* OSD */
-       { 0x1c, KEY_BACKSPACE},         /* LAST */
-
-       { 0x0d, KEY_PLAY},              /* PLAY */
-       { 0x1e, KEY_CAMERA},            /* SNAPSHOT */
-       { 0x1a, KEY_RECORD},            /* RECORD */
-       { 0x17, KEY_STOP},              /* STOP */
-
-       { 0x1f, KEY_UP},                /* UP */
-       { 0x44, KEY_DOWN},              /* DOWN */
-       { 0x46, KEY_TAB},               /* BACK */
-       { 0x4a, KEY_ZOOM},              /* FULLSECREEN */
-
-       { 0x10, KEY_VOLUMEUP},          /* VOLUMEUP */
-       { 0x11, KEY_VOLUMEDOWN},        /* VOLUMEDOWN */
-       { 0x12, KEY_CHANNELUP},         /* CHANNELUP */
-       { 0x13, KEY_CHANNELDOWN},       /* CHANNELDOWN */
-       { 0x15, KEY_ENTER},             /* OK */
-};
-struct ir_scancode_table ir_codes_gadmei_rm008z_table = {
-       .scan = ir_codes_gadmei_rm008z,
-       .size = ARRAY_SIZE(ir_codes_gadmei_rm008z),
-};
-EXPORT_SYMBOL_GPL(ir_codes_gadmei_rm008z_table);
-
-/*************************************************************
- *             COMPLETE SCANCODE TABLES
- * Instead of just a partial scancode, the tables bellow
- * contains the complete scancode and the receiver protocol
- *************************************************************/
-
-/*
- * Hauppauge:the newer, gray remotes (seems there are multiple
- * slightly different versions), shipped with cx88+ivtv cards.
- *
- * This table contains the complete RC5 code, instead of just the data part
- */
-static struct ir_scancode ir_codes_rc5_hauppauge_new[] = {
-       /* Keys 0 to 9 */
-       { 0x1e00, KEY_0 },
-       { 0x1e01, KEY_1 },
-       { 0x1e02, KEY_2 },
-       { 0x1e03, KEY_3 },
-       { 0x1e04, KEY_4 },
-       { 0x1e05, KEY_5 },
-       { 0x1e06, KEY_6 },
-       { 0x1e07, KEY_7 },
-       { 0x1e08, KEY_8 },
-       { 0x1e09, KEY_9 },
-
-       { 0x1e0a, KEY_TEXT },           /* keypad asterisk as well */
-       { 0x1e0b, KEY_RED },            /* red button */
-       { 0x1e0c, KEY_RADIO },
-       { 0x1e0d, KEY_MENU },
-       { 0x1e0e, KEY_SUBTITLE },               /* also the # key */
-       { 0x1e0f, KEY_MUTE },
-       { 0x1e10, KEY_VOLUMEUP },
-       { 0x1e11, KEY_VOLUMEDOWN },
-       { 0x1e12, KEY_PREVIOUS },               /* previous channel */
-       { 0x1e14, KEY_UP },
-       { 0x1e15, KEY_DOWN },
-       { 0x1e16, KEY_LEFT },
-       { 0x1e17, KEY_RIGHT },
-       { 0x1e18, KEY_VIDEO },          /* Videos */
-       { 0x1e19, KEY_AUDIO },          /* Music */
-       /* 0x1e1a: Pictures - presume this means
-          "Multimedia Home Platform" -
-          no "PICTURES" key in input.h
-        */
-       { 0x1e1a, KEY_MHP },
-
-       { 0x1e1b, KEY_EPG },            /* Guide */
-       { 0x1e1c, KEY_TV },
-       { 0x1e1e, KEY_NEXTSONG },               /* skip >| */
-       { 0x1e1f, KEY_EXIT },           /* back/exit */
-       { 0x1e20, KEY_CHANNELUP },      /* channel / program + */
-       { 0x1e21, KEY_CHANNELDOWN },    /* channel / program - */
-       { 0x1e22, KEY_CHANNEL },                /* source (old black remote) */
-       { 0x1e24, KEY_PREVIOUSSONG },   /* replay |< */
-       { 0x1e25, KEY_ENTER },          /* OK */
-       { 0x1e26, KEY_SLEEP },          /* minimize (old black remote) */
-       { 0x1e29, KEY_BLUE },           /* blue key */
-       { 0x1e2e, KEY_GREEN },          /* green button */
-       { 0x1e30, KEY_PAUSE },          /* pause */
-       { 0x1e32, KEY_REWIND },         /* backward << */
-       { 0x1e34, KEY_FASTFORWARD },    /* forward >> */
-       { 0x1e35, KEY_PLAY },
-       { 0x1e36, KEY_STOP },
-       { 0x1e37, KEY_RECORD },         /* recording */
-       { 0x1e38, KEY_YELLOW },         /* yellow key */
-       { 0x1e3b, KEY_SELECT },         /* top right button */
-       { 0x1e3c, KEY_ZOOM },           /* full */
-       { 0x1e3d, KEY_POWER },          /* system power (green button) */
-};
-
-struct ir_scancode_table ir_codes_rc5_hauppauge_new_table = {
-       .scan = ir_codes_rc5_hauppauge_new,
-       .size = ARRAY_SIZE(ir_codes_rc5_hauppauge_new),
-       .ir_type = IR_TYPE_RC5,
-};
-EXPORT_SYMBOL_GPL(ir_codes_rc5_hauppauge_new_table);
-
-/* Terratec Cinergy Hybrid T USB XS FM
-   Mauro Carvalho Chehab <mchehab@redhat.com>
- */
-static struct ir_scancode ir_codes_nec_terratec_cinergy_xs[] = {
-       { 0x1441, KEY_HOME},
-       { 0x1401, KEY_POWER2},
-
-       { 0x1442, KEY_MENU},            /* DVD menu */
-       { 0x1443, KEY_SUBTITLE},
-       { 0x1444, KEY_TEXT},            /* Teletext */
-       { 0x1445, KEY_DELETE},
-
-       { 0x1402, KEY_1},
-       { 0x1403, KEY_2},
-       { 0x1404, KEY_3},
-       { 0x1405, KEY_4},
-       { 0x1406, KEY_5},
-       { 0x1407, KEY_6},
-       { 0x1408, KEY_7},
-       { 0x1409, KEY_8},
-       { 0x140a, KEY_9},
-       { 0x140c, KEY_0},
-
-       { 0x140b, KEY_TUNER},           /* AV */
-       { 0x140d, KEY_MODE},            /* A.B */
-
-       { 0x1446, KEY_TV},
-       { 0x1447, KEY_DVD},
-       { 0x1449, KEY_VIDEO},
-       { 0x144a, KEY_RADIO},           /* Music */
-       { 0x144b, KEY_CAMERA},          /* PIC */
-
-       { 0x1410, KEY_UP},
-       { 0x1411, KEY_LEFT},
-       { 0x1412, KEY_OK},
-       { 0x1413, KEY_RIGHT},
-       { 0x1414, KEY_DOWN},
-
-       { 0x140f, KEY_EPG},
-       { 0x1416, KEY_INFO},
-       { 0x144d, KEY_BACKSPACE},
-
-       { 0x141c, KEY_VOLUMEUP},
-       { 0x141e, KEY_VOLUMEDOWN},
-
-       { 0x144c, KEY_PLAY},
-       { 0x141d, KEY_MUTE},
-
-       { 0x141b, KEY_CHANNELUP},
-       { 0x141f, KEY_CHANNELDOWN},
-
-       { 0x1417, KEY_RED},
-       { 0x1418, KEY_GREEN},
-       { 0x1419, KEY_YELLOW},
-       { 0x141a, KEY_BLUE},
-
-       { 0x1458, KEY_RECORD},
-       { 0x1448, KEY_STOP},
-       { 0x1440, KEY_PAUSE},
-
-       { 0x1454, KEY_LAST},
-       { 0x144e, KEY_REWIND},
-       { 0x144f, KEY_FASTFORWARD},
-       { 0x145c, KEY_NEXT},
-};
-struct ir_scancode_table ir_codes_nec_terratec_cinergy_xs_table = {
-       .scan = ir_codes_nec_terratec_cinergy_xs,
-       .size = ARRAY_SIZE(ir_codes_nec_terratec_cinergy_xs),
-       .ir_type = IR_TYPE_NEC,
-};
-EXPORT_SYMBOL_GPL(ir_codes_nec_terratec_cinergy_xs_table);
-
-
-/* Leadtek Winfast TV USB II Deluxe remote
-   Magnus Alm <magnus.alm@gmail.com>
- */
-static struct ir_scancode ir_codes_winfast_usbii_deluxe[] = {
-       { 0x62, KEY_0},
-       { 0x75, KEY_1},
-       { 0x76, KEY_2},
-       { 0x77, KEY_3},
-       { 0x79, KEY_4},
-       { 0x7a, KEY_5},
-       { 0x7b, KEY_6},
-       { 0x7d, KEY_7},
-       { 0x7e, KEY_8},
-       { 0x7f, KEY_9},
-
-       { 0x38, KEY_CAMERA},            /* SNAPSHOT */
-       { 0x37, KEY_RECORD},            /* RECORD */
-       { 0x35, KEY_TIME},              /* TIMESHIFT */
-
-       { 0x74, KEY_VOLUMEUP},          /* VOLUMEUP */
-       { 0x78, KEY_VOLUMEDOWN},        /* VOLUMEDOWN */
-       { 0x64, KEY_MUTE},              /* MUTE */
-
-       { 0x21, KEY_CHANNEL},           /* SURF */
-       { 0x7c, KEY_CHANNELUP},         /* CHANNELUP */
-       { 0x60, KEY_CHANNELDOWN},       /* CHANNELDOWN */
-       { 0x61, KEY_LAST},              /* LAST CHANNEL (RECALL) */
-
-       { 0x72, KEY_VIDEO},             /* INPUT MODES (TV/FM) */
-
-       { 0x70, KEY_POWER2},            /* TV ON/OFF */
-
-       { 0x39, KEY_CYCLEWINDOWS},      /* MINIMIZE (BOSS) */
-       { 0x3a, KEY_NEW},               /* PIP */
-       { 0x73, KEY_ZOOM},              /* FULLSECREEN */
-
-       { 0x66, KEY_INFO},              /* OSD (DISPLAY) */
-
-       { 0x31, KEY_DOT},               /* '.' */
-       { 0x63, KEY_ENTER},             /* ENTER */
-
-};
-struct ir_scancode_table ir_codes_winfast_usbii_deluxe_table = {
-       .scan = ir_codes_winfast_usbii_deluxe,
-       .size = ARRAY_SIZE(ir_codes_winfast_usbii_deluxe),
-};
-EXPORT_SYMBOL_GPL(ir_codes_winfast_usbii_deluxe_table);
-
-/* Kworld 315U
- */
-static struct ir_scancode ir_codes_kworld_315u[] = {
-       { 0x6143, KEY_POWER },
-       { 0x6101, KEY_TUNER },          /* source */
-       { 0x610b, KEY_ZOOM },
-       { 0x6103, KEY_POWER2 },         /* shutdown */
-
-       { 0x6104, KEY_1 },
-       { 0x6108, KEY_2 },
-       { 0x6102, KEY_3 },
-       { 0x6109, KEY_CHANNELUP },
-
-       { 0x610f, KEY_4 },
-       { 0x6105, KEY_5 },
-       { 0x6106, KEY_6 },
-       { 0x6107, KEY_CHANNELDOWN },
-
-       { 0x610c, KEY_7 },
-       { 0x610d, KEY_8 },
-       { 0x610a, KEY_9 },
-       { 0x610e, KEY_VOLUMEUP },
-
-       { 0x6110, KEY_LAST },
-       { 0x6111, KEY_0 },
-       { 0x6112, KEY_ENTER },
-       { 0x6113, KEY_VOLUMEDOWN },
-
-       { 0x6114, KEY_RECORD },
-       { 0x6115, KEY_STOP },
-       { 0x6116, KEY_PLAY },
-       { 0x6117, KEY_MUTE },
-
-       { 0x6118, KEY_UP },
-       { 0x6119, KEY_DOWN },
-       { 0x611a, KEY_LEFT },
-       { 0x611b, KEY_RIGHT },
-
-       { 0x611c, KEY_RED },
-       { 0x611d, KEY_GREEN },
-       { 0x611e, KEY_YELLOW },
-       { 0x611f, KEY_BLUE },
-};
-
-struct ir_scancode_table ir_codes_kworld_315u_table = {
-       .scan = ir_codes_kworld_315u,
-       .size = ARRAY_SIZE(ir_codes_kworld_315u),
-       .ir_type = IR_TYPE_NEC,
-};
-EXPORT_SYMBOL_GPL(ir_codes_kworld_315u_table);
index bfca26d..9374a00 100644 (file)
@@ -1,4 +1,4 @@
-/* ir-register.c - handle IR scancode->keycode tables
+/* ir-keytable.c - handle IR scancode->keycode tables
  *
  * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
  *
 
 #include <linux/input.h>
 #include <linux/slab.h>
-#include <media/ir-common.h>
+#include "ir-core-priv.h"
 
-#define IR_TAB_MIN_SIZE        32
-#define IR_TAB_MAX_SIZE        1024
+/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
+#define IR_TAB_MIN_SIZE        256
+#define IR_TAB_MAX_SIZE        8192
+
+/* FIXME: IR_KEYPRESS_TIMEOUT should be protocol specific */
+#define IR_KEYPRESS_TIMEOUT 250
 
 /**
- * ir_seek_table() - returns the element order on the table
- * @rc_tab:    the ir_scancode_table with the keymap to be used
- * @scancode:  the scancode that we're seeking
+ * ir_resize_table() - resizes a scancode table if necessary
+ * @rc_tab:    the ir_scancode_table to resize
+ * @return:    zero on success or a negative error code
  *
- * This routine is used by the input routines when a key is pressed at the
- * IR. The scancode is received and needs to be converted into a keycode.
- * If the key is not found, it returns KEY_UNKNOWN. Otherwise, returns the
- * corresponding keycode from the table.
+ * This routine will shrink the ir_scancode_table if it has lots of
+ * unused entries and grow it if it is full.
  */
-static int ir_seek_table(struct ir_scancode_table *rc_tab, u32 scancode)
+static int ir_resize_table(struct ir_scancode_table *rc_tab)
 {
-       int rc;
-       unsigned long flags;
-       struct ir_scancode *keymap = rc_tab->scan;
+       unsigned int oldalloc = rc_tab->alloc;
+       unsigned int newalloc = oldalloc;
+       struct ir_scancode *oldscan = rc_tab->scan;
+       struct ir_scancode *newscan;
+
+       if (rc_tab->size == rc_tab->len) {
+               /* All entries in use -> grow keytable */
+               if (rc_tab->alloc >= IR_TAB_MAX_SIZE)
+                       return -ENOMEM;
 
-       spin_lock_irqsave(&rc_tab->lock, flags);
+               newalloc *= 2;
+               IR_dprintk(1, "Growing table to %u bytes\n", newalloc);
+       }
 
-       /* FIXME: replace it by a binary search */
+       if ((rc_tab->len * 3 < rc_tab->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
+               /* Less than 1/3 of entries in use -> shrink keytable */
+               newalloc /= 2;
+               IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc);
+       }
 
-       for (rc = 0; rc < rc_tab->size; rc++)
-               if (keymap[rc].scancode == scancode)
-                       goto exit;
+       if (newalloc == oldalloc)
+               return 0;
 
-       /* Not found */
-       rc = -EINVAL;
+       newscan = kmalloc(newalloc, GFP_ATOMIC);
+       if (!newscan) {
+               IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
+               return -ENOMEM;
+       }
 
-exit:
-       spin_unlock_irqrestore(&rc_tab->lock, flags);
-       return rc;
+       memcpy(newscan, rc_tab->scan, rc_tab->len * sizeof(struct ir_scancode));
+       rc_tab->scan = newscan;
+       rc_tab->alloc = newalloc;
+       rc_tab->size = rc_tab->alloc / sizeof(struct ir_scancode);
+       kfree(oldscan);
+       return 0;
 }
 
 /**
- * ir_roundup_tablesize() - gets an optimum value for the table size
- * @n_elems:           minimum number of entries to store keycodes
- *
- * This routine is used to choose the keycode table size.
+ * ir_do_setkeycode() - internal function to set a keycode in the
+ *                     scancode->keycode table
+ * @dev:       the struct input_dev device descriptor
+ * @rc_tab:    the struct ir_scancode_table to set the keycode in
+ * @scancode:  the scancode for the ir command
+ * @keycode:   the keycode for the ir command
+ * @resize:    whether the keytable may be shrunk
+ * @return:    -EINVAL if the keycode could not be inserted, otherwise zero.
  *
- * In order to have some empty space for new keycodes,
- * and knowing in advance that kmalloc allocates only power of two
- * segments, it optimizes the allocated space to have some spare space
- * for those new keycodes by using the maximum number of entries that
- * will be effectively be allocated by kmalloc.
- * In order to reduce the quantity of table resizes, it has a minimum
- * table size of IR_TAB_MIN_SIZE.
+ * This routine is used internally to manipulate the scancode->keycode table.
+ * The caller has to hold @rc_tab->lock.
  */
-static int ir_roundup_tablesize(int n_elems)
+static int ir_do_setkeycode(struct input_dev *dev,
+                           struct ir_scancode_table *rc_tab,
+                           unsigned scancode, unsigned keycode,
+                           bool resize)
 {
-       size_t size;
-
-       if (n_elems < IR_TAB_MIN_SIZE)
-               n_elems = IR_TAB_MIN_SIZE;
+       unsigned int i;
+       int old_keycode = KEY_RESERVED;
+       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
 
        /*
-        * As kmalloc only allocates sizes of power of two, get as
-        * much entries as possible for the allocated memory segment
+        * Unfortunately, some hardware-based IR decoders don't provide
+        * all bits for the complete IR code. In general, they provide only
+        * the command part of the IR code. Yet, as it is possible to replace
+        * the provided IR with another one, it is needed to allow loading
+        * IR tables from other remotes. So,
         */
-       size = roundup_pow_of_two(n_elems * sizeof(struct ir_scancode));
-       n_elems = size / sizeof(struct ir_scancode);
+       if (ir_dev->props && ir_dev->props->scanmask) {
+               scancode &= ir_dev->props->scanmask;
+       }
 
-       return n_elems;
+       /* First check if we already have a mapping for this ir command */
+       for (i = 0; i < rc_tab->len; i++) {
+               /* Keytable is sorted from lowest to highest scancode */
+               if (rc_tab->scan[i].scancode > scancode)
+                       break;
+               else if (rc_tab->scan[i].scancode < scancode)
+                       continue;
+
+               old_keycode = rc_tab->scan[i].keycode;
+               rc_tab->scan[i].keycode = keycode;
+
+               /* Did the user wish to remove the mapping? */
+               if (keycode == KEY_RESERVED || keycode == KEY_UNKNOWN) {
+                       IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
+                                  i, scancode);
+                       rc_tab->len--;
+                       memmove(&rc_tab->scan[i], &rc_tab->scan[i + 1],
+                               (rc_tab->len - i) * sizeof(struct ir_scancode));
+               }
+
+               /* Possibly shrink the keytable, failure is not a problem */
+               ir_resize_table(rc_tab);
+               break;
+       }
+
+       if (old_keycode == KEY_RESERVED && keycode != KEY_RESERVED) {
+               /* No previous mapping found, we might need to grow the table */
+               if (resize && ir_resize_table(rc_tab))
+                       return -ENOMEM;
+
+               IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n",
+                          i, scancode, keycode);
+
+               /* i is the proper index to insert our new keycode */
+               memmove(&rc_tab->scan[i + 1], &rc_tab->scan[i],
+                       (rc_tab->len - i) * sizeof(struct ir_scancode));
+               rc_tab->scan[i].scancode = scancode;
+               rc_tab->scan[i].keycode = keycode;
+               rc_tab->len++;
+               set_bit(keycode, dev->keybit);
+       } else {
+               IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n",
+                          i, scancode, keycode);
+               /* A previous mapping was updated... */
+               clear_bit(old_keycode, dev->keybit);
+               /* ...but another scancode might use the same keycode */
+               for (i = 0; i < rc_tab->len; i++) {
+                       if (rc_tab->scan[i].keycode == old_keycode) {
+                               set_bit(old_keycode, dev->keybit);
+                               break;
+                       }
+               }
+       }
+
+       return 0;
 }
 
 /**
- * ir_copy_table() - copies a keytable, discarding the unused entries
- * @destin:    destin table
- * @origin:    origin table
+ * ir_setkeycode() - set a keycode in the scancode->keycode table
+ * @dev:       the struct input_dev device descriptor
+ * @scancode:  the desired scancode
+ * @keycode:   result
+ * @return:    -EINVAL if the keycode could not be inserted, otherwise zero.
  *
- * Copies all entries where the keycode is not KEY_UNKNOWN/KEY_RESERVED
- * Also copies table size and table protocol.
- * NOTE: It shouldn't copy the lock field
+ * This routine is used to handle evdev EVIOCSKEY ioctl.
  */
-
-static int ir_copy_table(struct ir_scancode_table *destin,
-                const struct ir_scancode_table *origin)
+static int ir_setkeycode(struct input_dev *dev,
+                        unsigned int scancode, unsigned int keycode)
 {
-       int i, j = 0;
-
-       for (i = 0; i < origin->size; i++) {
-               if (origin->scan[i].keycode == KEY_UNKNOWN ||
-                  origin->scan[i].keycode == KEY_RESERVED)
-                       continue;
+       int rc;
+       unsigned long flags;
+       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
+       struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
 
-               memcpy(&destin->scan[j], &origin->scan[i], sizeof(struct ir_scancode));
-               j++;
-       }
-       destin->size = j;
-       destin->ir_type = origin->ir_type;
+       spin_lock_irqsave(&rc_tab->lock, flags);
+       rc = ir_do_setkeycode(dev, rc_tab, scancode, keycode, true);
+       spin_unlock_irqrestore(&rc_tab->lock, flags);
+       return rc;
+}
 
-       IR_dprintk(1, "Copied %d scancodes to the new keycode table\n", destin->size);
+/**
+ * ir_setkeytable() - sets several entries in the scancode->keycode table
+ * @dev:       the struct input_dev device descriptor
+ * @to:                the struct ir_scancode_table to copy entries to
+ * @from:      the struct ir_scancode_table to copy entries from
+ * @return:    -EINVAL if all keycodes could not be inserted, otherwise zero.
+ *
+ * This routine is used to handle table initialization.
+ */
+static int ir_setkeytable(struct input_dev *dev,
+                         struct ir_scancode_table *to,
+                         const struct ir_scancode_table *from)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
+       struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
+       unsigned long flags;
+       unsigned int i;
+       int rc = 0;
 
-       return 0;
+       spin_lock_irqsave(&rc_tab->lock, flags);
+       for (i = 0; i < from->size; i++) {
+               rc = ir_do_setkeycode(dev, to, from->scan[i].scancode,
+                                     from->scan[i].keycode, false);
+               if (rc)
+                       break;
+       }
+       spin_unlock_irqrestore(&rc_tab->lock, flags);
+       return rc;
 }
 
 /**
- * ir_getkeycode() - get a keycode at the evdev scancode ->keycode table
+ * ir_getkeycode() - get a keycode from the scancode->keycode table
  * @dev:       the struct input_dev device descriptor
  * @scancode:  the desired scancode
- * @keycode:   the keycode to be retorned.
+ * @keycode:   used to return the keycode, if found, or KEY_RESERVED
+ * @return:    always returns zero.
  *
  * This routine is used to handle evdev EVIOCGKEY ioctl.
- * If the key is not found, returns -EINVAL, otherwise, returns 0.
  */
 static int ir_getkeycode(struct input_dev *dev,
                         unsigned int scancode, unsigned int *keycode)
 {
-       int elem;
+       int start, end, mid;
+       unsigned long flags;
+       int key = KEY_RESERVED;
        struct ir_input_dev *ir_dev = input_get_drvdata(dev);
        struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
 
-       elem = ir_seek_table(rc_tab, scancode);
-       if (elem >= 0) {
-               *keycode = rc_tab->scan[elem].keycode;
-               return 0;
+       spin_lock_irqsave(&rc_tab->lock, flags);
+       start = 0;
+       end = rc_tab->len - 1;
+       while (start <= end) {
+               mid = (start + end) / 2;
+               if (rc_tab->scan[mid].scancode < scancode)
+                       start = mid + 1;
+               else if (rc_tab->scan[mid].scancode > scancode)
+                       end = mid - 1;
+               else {
+                       key = rc_tab->scan[mid].keycode;
+                       break;
+               }
        }
+       spin_unlock_irqrestore(&rc_tab->lock, flags);
 
-       /*
-        * Scancode not found and table can't be expanded
-        */
-       if (elem < 0 && rc_tab->size == IR_TAB_MAX_SIZE)
-               return -EINVAL;
+       if (key == KEY_RESERVED)
+               IR_dprintk(1, "unknown key for scancode 0x%04x\n",
+                          scancode);
 
-       /*
-        * If is there extra space, returns KEY_RESERVED,
-        * otherwise, input core won't let ir_setkeycode to work
-        */
-       *keycode = KEY_RESERVED;
+       *keycode = key;
        return 0;
 }
 
 /**
- * ir_is_resize_needed() - Check if the table needs rezise
- * @table:             keycode table that may need to resize
- * @n_elems:           minimum number of entries to store keycodes
- *
- * Considering that kmalloc uses power of two storage areas, this
- * routine detects if the real alloced size will change. If not, it
- * just returns without doing nothing. Otherwise, it will extend or
- * reduce the table size to meet the new needs.
+ * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode
+ * @input_dev: the struct input_dev descriptor of the device
+ * @scancode:  the scancode that we're seeking
  *
- * It returns 0 if no resize is needed, 1 otherwise.
+ * This routine is used by the input routines when a key is pressed at the
+ * IR. The scancode is received and needs to be converted into a keycode.
+ * If the key is not found, it returns KEY_RESERVED. Otherwise, returns the
+ * corresponding keycode from the table.
  */
-static int ir_is_resize_needed(struct ir_scancode_table *table, int n_elems)
+u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
 {
-       int cur_size = ir_roundup_tablesize(table->size);
-       int new_size = ir_roundup_tablesize(n_elems);
-
-       if (cur_size == new_size)
-               return 0;
+       int keycode;
 
-       /* Resize is needed */
-       return 1;
+       ir_getkeycode(dev, scancode, &keycode);
+       if (keycode != KEY_RESERVED)
+               IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
+                          dev->name, scancode, keycode);
+       return keycode;
 }
+EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
 
 /**
- * ir_delete_key() - remove a keycode from the table
- * @rc_tab:            keycode table
- * @elem:              element to be removed
+ * ir_keyup() - generates input event to cleanup a key press
+ * @ir:         the struct ir_input_dev descriptor of the device
  *
+ * This routine is used to signal that a key has been released on the
+ * remote control. It reports a keyup input event via input_report_key().
  */
-static void ir_delete_key(struct ir_scancode_table *rc_tab, int elem)
+static void ir_keyup(struct ir_input_dev *ir)
 {
-       unsigned long flags = 0;
-       int newsize = rc_tab->size - 1;
-       int resize = ir_is_resize_needed(rc_tab, newsize);
-       struct ir_scancode *oldkeymap = rc_tab->scan;
-       struct ir_scancode *newkeymap = NULL;
-
-       if (resize)
-               newkeymap = kzalloc(ir_roundup_tablesize(newsize) *
-                                   sizeof(*newkeymap), GFP_ATOMIC);
-
-       /* There's no memory for resize. Keep the old table */
-       if (!resize || !newkeymap) {
-               newkeymap = oldkeymap;
-
-               /* We'll modify the live table. Lock it */
-               spin_lock_irqsave(&rc_tab->lock, flags);
-       }
+       if (!ir->keypressed)
+               return;
 
-       /*
-        * Copy the elements before the one that will be deleted
-        * if (!resize), both oldkeymap and newkeymap points
-        * to the same place, so, there's no need to copy
-        */
-       if (resize && elem > 0)
-               memcpy(newkeymap, oldkeymap,
-                      elem * sizeof(*newkeymap));
+       IR_dprintk(1, "keyup key 0x%04x\n", ir->last_keycode);
+       input_report_key(ir->input_dev, ir->last_keycode, 0);
+       input_sync(ir->input_dev);
+       ir->keypressed = false;
+}
+
+/**
+ * ir_timer_keyup() - generates a keyup event after a timeout
+ * @cookie:     a pointer to struct ir_input_dev passed to setup_timer()
+ *
+ * This routine will generate a keyup event some time after a keydown event
+ * is generated when no further activity has been detected.
+ */
+static void ir_timer_keyup(unsigned long cookie)
+{
+       struct ir_input_dev *ir = (struct ir_input_dev *)cookie;
+       unsigned long flags;
 
        /*
-        * Copy the other elements overwriting the element to be removed
-        * This operation applies to both resize and non-resize case
+        * ir->keyup_jiffies is used to prevent a race condition if a
+        * hardware interrupt occurs at this point and the keyup timer
+        * event is moved further into the future as a result.
+        *
+        * The timer will then be reactivated and this function called
+        * again in the future. We need to exit gracefully in that case
+        * to allow the input subsystem to do its auto-repeat magic or
+        * a keyup event might follow immediately after the keydown.
         */
-       if (elem < newsize)
-               memcpy(&newkeymap[elem], &oldkeymap[elem + 1],
-                      (newsize - elem) * sizeof(*newkeymap));
-
-       if (resize) {
-               /*
-                * As the copy happened to a temporary table, only here
-                * it needs to lock while replacing the table pointers
-                * to use the new table
-                */
-               spin_lock_irqsave(&rc_tab->lock, flags);
-               rc_tab->size = newsize;
-               rc_tab->scan = newkeymap;
-               spin_unlock_irqrestore(&rc_tab->lock, flags);
-
-               /* Frees the old keytable */
-               kfree(oldkeymap);
-       } else {
-               rc_tab->size = newsize;
-               spin_unlock_irqrestore(&rc_tab->lock, flags);
-       }
+       spin_lock_irqsave(&ir->keylock, flags);
+       if (time_is_after_eq_jiffies(ir->keyup_jiffies))
+               ir_keyup(ir);
+       spin_unlock_irqrestore(&ir->keylock, flags);
 }
 
 /**
- * ir_insert_key() - insert a keycode at the table
- * @rc_tab:            keycode table
- * @scancode:  the desired scancode
- * @keycode:   the keycode to be retorned.
+ * ir_repeat() - notifies the IR core that a key is still pressed
+ * @dev:        the struct input_dev descriptor of the device
  *
+ * This routine is used by IR decoders when a repeat message which does
+ * not include the necessary bits to reproduce the scancode has been
+ * received.
  */
-static int ir_insert_key(struct ir_scancode_table *rc_tab,
-                         int scancode, int keycode)
+void ir_repeat(struct input_dev *dev)
 {
        unsigned long flags;
-       int elem = rc_tab->size;
-       int newsize = rc_tab->size + 1;
-       int resize = ir_is_resize_needed(rc_tab, newsize);
-       struct ir_scancode *oldkeymap = rc_tab->scan;
-       struct ir_scancode *newkeymap;
-
-       if (resize) {
-               newkeymap = kzalloc(ir_roundup_tablesize(newsize) *
-                                   sizeof(*newkeymap), GFP_ATOMIC);
-               if (!newkeymap)
-                       return -ENOMEM;
+       struct ir_input_dev *ir = input_get_drvdata(dev);
 
-               memcpy(newkeymap, oldkeymap,
-                      rc_tab->size * sizeof(*newkeymap));
-       } else
-               newkeymap  = oldkeymap;
+       spin_lock_irqsave(&ir->keylock, flags);
 
-       /* Stores the new code at the table */
-       IR_dprintk(1, "#%d: New scan 0x%04x with key 0x%04x\n",
-                  rc_tab->size, scancode, keycode);
+       if (!ir->keypressed)
+               goto out;
 
-       spin_lock_irqsave(&rc_tab->lock, flags);
-       rc_tab->size = newsize;
-       if (resize) {
-               rc_tab->scan = newkeymap;
-               kfree(oldkeymap);
-       }
-       newkeymap[elem].scancode = scancode;
-       newkeymap[elem].keycode  = keycode;
-       spin_unlock_irqrestore(&rc_tab->lock, flags);
+       ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
+       mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
 
-       return 0;
+out:
+       spin_unlock_irqrestore(&ir->keylock, flags);
 }
+EXPORT_SYMBOL_GPL(ir_repeat);
 
 /**
- * ir_setkeycode() - set a keycode at the evdev scancode ->keycode table
- * @dev:       the struct input_dev device descriptor
- * @scancode:  the desired scancode
- * @keycode:   the keycode to be retorned.
+ * ir_keydown() - generates input event for a key press
+ * @dev:        the struct input_dev descriptor of the device
+ * @scancode:   the scancode that we're seeking
+ * @toggle:     the toggle value (protocol dependent, if the protocol doesn't
+ *              support toggle values, this should be set to zero)
  *
- * This routine is used to handle evdev EVIOCSKEY ioctl.
- * There's one caveat here: how can we increase the size of the table?
- * If the key is not found, returns -EINVAL, otherwise, returns 0.
+ * This routine is used by the input routines when a key is pressed at the
+ * IR. It gets the keycode for a scancode and reports an input event via
+ * input_report_key().
  */
-static int ir_setkeycode(struct input_dev *dev,
-                        unsigned int scancode, unsigned int keycode)
+void ir_keydown(struct input_dev *dev, int scancode, u8 toggle)
 {
-       int rc = 0;
-       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
-       struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
-       struct ir_scancode *keymap = rc_tab->scan;
        unsigned long flags;
+       struct ir_input_dev *ir = input_get_drvdata(dev);
 
-       /*
-        * Handle keycode table deletions
-        *
-        * If userspace is adding a KEY_UNKNOWN or KEY_RESERVED,
-        * deal as a trial to remove an existing scancode attribution
-        * if table become too big, reduce it to save space
-        */
-       if (keycode == KEY_UNKNOWN || keycode == KEY_RESERVED) {
-               rc = ir_seek_table(rc_tab, scancode);
-               if (rc < 0)
-                       return 0;
-
-               IR_dprintk(1, "#%d: Deleting scan 0x%04x\n", rc, scancode);
-               clear_bit(keymap[rc].keycode, dev->keybit);
-               ir_delete_key(rc_tab, rc);
-
-               return 0;
-       }
+       u32 keycode = ir_g_keycode_from_table(dev, scancode);
 
-       /*
-        * Handle keycode replacements
-        *
-        * If the scancode exists, just replace by the new value
-        */
-       rc = ir_seek_table(rc_tab, scancode);
-       if (rc >= 0) {
-               IR_dprintk(1, "#%d: Replacing scan 0x%04x with key 0x%04x\n",
-                       rc, scancode, keycode);
+       spin_lock_irqsave(&ir->keylock, flags);
 
-               clear_bit(keymap[rc].keycode, dev->keybit);
+       /* Repeat event? */
+       if (ir->keypressed &&
+           ir->last_scancode == scancode &&
+           ir->last_toggle == toggle)
+               goto set_timer;
 
-               spin_lock_irqsave(&rc_tab->lock, flags);
-               keymap[rc].keycode = keycode;
-               spin_unlock_irqrestore(&rc_tab->lock, flags);
+       /* Release old keypress */
+       ir_keyup(ir);
 
-               set_bit(keycode, dev->keybit);
+       ir->last_scancode = scancode;
+       ir->last_toggle = toggle;
+       ir->last_keycode = keycode;
 
-               return 0;
-       }
+       if (keycode == KEY_RESERVED)
+               goto out;
 
-       /*
-        * Handle new scancode inserts
-        *
-        * reallocate table if needed and insert a new keycode
-        */
+       /* Register a keypress */
+       ir->keypressed = true;
+       IR_dprintk(1, "%s: key down event, key 0x%04x, scancode 0x%04x\n",
+                  dev->name, keycode, scancode);
+       input_report_key(dev, ir->last_keycode, 1);
+       input_sync(dev);
 
-       /* Avoid growing the table indefinitely */
-       if (rc_tab->size + 1 > IR_TAB_MAX_SIZE)
-               return -EINVAL;
-
-       rc = ir_insert_key(rc_tab, scancode, keycode);
-       if (rc < 0)
-               return rc;
-       set_bit(keycode, dev->keybit);
-
-       return 0;
+set_timer:
+       ir->keyup_jiffies = jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT);
+       mod_timer(&ir->timer_keyup, ir->keyup_jiffies);
+out:
+       spin_unlock_irqrestore(&ir->keylock, flags);
 }
+EXPORT_SYMBOL_GPL(ir_keydown);
 
-/**
- * ir_g_keycode_from_table() - gets the keycode that corresponds to a scancode
- * @input_dev: the struct input_dev descriptor of the device
- * @scancode:  the scancode that we're seeking
- *
- * This routine is used by the input routines when a key is pressed at the
- * IR. The scancode is received and needs to be converted into a keycode.
- * If the key is not found, it returns KEY_UNKNOWN. Otherwise, returns the
- * corresponding keycode from the table.
- */
-u32 ir_g_keycode_from_table(struct input_dev *dev, u32 scancode)
+static int ir_open(struct input_dev *input_dev)
 {
-       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
-       struct ir_scancode_table *rc_tab = &ir_dev->rc_tab;
-       struct ir_scancode *keymap = rc_tab->scan;
-       int elem;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
 
-       elem = ir_seek_table(rc_tab, scancode);
-       if (elem >= 0) {
-               IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
-                          dev->name, scancode, keymap[elem].keycode);
-
-               return rc_tab->scan[elem].keycode;
-       }
+       return ir_dev->props->open(ir_dev->props->priv);
+}
 
-       printk(KERN_INFO "%s: unknown key for scancode 0x%04x\n",
-              dev->name, scancode);
+static void ir_close(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
 
-       /* Reports userspace that an unknown keycode were got */
-       return KEY_RESERVED;
+       ir_dev->props->close(ir_dev->props->priv);
 }
-EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
 
 /**
- * ir_input_register() - sets the IR keycode table and add the handlers
+ * __ir_input_register() - sets the IR keycode table and add the handlers
  *                         for keymap table get/set
  * @input_dev: the struct input_dev descriptor of the device
  * @rc_tab:    the struct ir_scancode_table table of scancode/keymap
@@ -402,13 +426,13 @@ EXPORT_SYMBOL_GPL(ir_g_keycode_from_table);
  * It will register the input/evdev interface for the device and
  * register the syfs code for IR class
  */
-int ir_input_register(struct input_dev *input_dev,
+int __ir_input_register(struct input_dev *input_dev,
                      const struct ir_scancode_table *rc_tab,
-                     const struct ir_dev_props *props)
+                     const struct ir_dev_props *props,
+                     const char *driver_name)
 {
        struct ir_input_dev *ir_dev;
-       struct ir_scancode  *keymap    = rc_tab->scan;
-       int i, rc;
+       int rc;
 
        if (rc_tab->scan == NULL || !rc_tab->size)
                return -EINVAL;
@@ -417,57 +441,77 @@ int ir_input_register(struct input_dev *input_dev,
        if (!ir_dev)
                return -ENOMEM;
 
-       spin_lock_init(&ir_dev->rc_tab.lock);
-
-       ir_dev->rc_tab.size = ir_roundup_tablesize(rc_tab->size);
-       ir_dev->rc_tab.scan = kzalloc(ir_dev->rc_tab.size *
-                                   sizeof(struct ir_scancode), GFP_KERNEL);
-       if (!ir_dev->rc_tab.scan) {
-               kfree(ir_dev);
-               return -ENOMEM;
+       ir_dev->driver_name = kasprintf(GFP_KERNEL, "%s", driver_name);
+       if (!ir_dev->driver_name) {
+               rc = -ENOMEM;
+               goto out_dev;
        }
 
-       IR_dprintk(1, "Allocated space for %d keycode entries (%zd bytes)\n",
-               ir_dev->rc_tab.size,
-               ir_dev->rc_tab.size * sizeof(ir_dev->rc_tab.scan));
+       input_dev->getkeycode = ir_getkeycode;
+       input_dev->setkeycode = ir_setkeycode;
+       input_set_drvdata(input_dev, ir_dev);
+       ir_dev->input_dev = input_dev;
 
-       ir_copy_table(&ir_dev->rc_tab, rc_tab);
-       ir_dev->props = props;
+       spin_lock_init(&ir_dev->rc_tab.lock);
+       spin_lock_init(&ir_dev->keylock);
+       setup_timer(&ir_dev->timer_keyup, ir_timer_keyup, (unsigned long)ir_dev);
+
+       ir_dev->rc_tab.name = rc_tab->name;
+       ir_dev->rc_tab.ir_type = rc_tab->ir_type;
+       ir_dev->rc_tab.alloc = roundup_pow_of_two(rc_tab->size *
+                                                 sizeof(struct ir_scancode));
+       ir_dev->rc_tab.scan = kmalloc(ir_dev->rc_tab.alloc, GFP_KERNEL);
+       ir_dev->rc_tab.size = ir_dev->rc_tab.alloc / sizeof(struct ir_scancode);
+       if (props) {
+               ir_dev->props = props;
+               if (props->open)
+                       input_dev->open = ir_open;
+               if (props->close)
+                       input_dev->close = ir_close;
+       }
 
-       /* set the bits for the keys */
-       IR_dprintk(1, "key map size: %d\n", rc_tab->size);
-       for (i = 0; i < rc_tab->size; i++) {
-               IR_dprintk(1, "#%d: setting bit for keycode 0x%04x\n",
-                       i, keymap[i].keycode);
-               set_bit(keymap[i].keycode, input_dev->keybit);
+       if (!ir_dev->rc_tab.scan) {
+               rc = -ENOMEM;
+               goto out_name;
        }
-       clear_bit(0, input_dev->keybit);
+
+       IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
+                  ir_dev->rc_tab.size, ir_dev->rc_tab.alloc);
 
        set_bit(EV_KEY, input_dev->evbit);
+       set_bit(EV_REP, input_dev->evbit);
 
-       input_dev->getkeycode = ir_getkeycode;
-       input_dev->setkeycode = ir_setkeycode;
-       input_set_drvdata(input_dev, ir_dev);
+       if (ir_setkeytable(input_dev, &ir_dev->rc_tab, rc_tab)) {
+               rc = -ENOMEM;
+               goto out_table;
+       }
 
-       rc = input_register_device(input_dev);
+       rc = ir_register_class(input_dev);
        if (rc < 0)
-               goto err;
+               goto out_table;
 
-       rc = ir_register_class(input_dev);
-       if (rc < 0) {
-               input_unregister_device(input_dev);
-               goto err;
+       if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW) {
+               rc = ir_raw_event_register(input_dev);
+               if (rc < 0)
+                       goto out_event;
        }
 
+       IR_dprintk(1, "Registered input device on %s for %s remote.\n",
+                  driver_name, rc_tab->name);
+
        return 0;
 
-err:
-       kfree(rc_tab->scan);
+out_event:
+       ir_unregister_class(input_dev);
+out_table:
+       kfree(ir_dev->rc_tab.scan);
+out_name:
+       kfree(ir_dev->driver_name);
+out_dev:
        kfree(ir_dev);
-       input_set_drvdata(input_dev, NULL);
        return rc;
 }
-EXPORT_SYMBOL_GPL(ir_input_register);
+EXPORT_SYMBOL_GPL(__ir_input_register);
 
 /**
  * ir_input_unregister() - unregisters IR and frees resources
@@ -475,9 +519,9 @@ EXPORT_SYMBOL_GPL(ir_input_register);
 
  * This routine is used to free memory and de-register interfaces.
  */
-void ir_input_unregister(struct input_dev *dev)
+void ir_input_unregister(struct input_dev *input_dev)
 {
-       struct ir_input_dev *ir_dev = input_get_drvdata(dev);
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
        struct ir_scancode_table *rc_tab;
 
        if (!ir_dev)
@@ -485,15 +529,18 @@ void ir_input_unregister(struct input_dev *dev)
 
        IR_dprintk(1, "Freed keycode table\n");
 
+       del_timer_sync(&ir_dev->timer_keyup);
+       if (ir_dev->props->driver_type == RC_DRIVER_IR_RAW)
+               ir_raw_event_unregister(input_dev);
        rc_tab = &ir_dev->rc_tab;
        rc_tab->size = 0;
        kfree(rc_tab->scan);
        rc_tab->scan = NULL;
 
-       ir_unregister_class(dev);
+       ir_unregister_class(input_dev);
 
+       kfree(ir_dev->driver_name);
        kfree(ir_dev);
-       input_unregister_device(dev);
 }
 EXPORT_SYMBOL_GPL(ir_input_unregister);
 
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c
new file mode 100644 (file)
index 0000000..ba79233
--- /dev/null
@@ -0,0 +1,328 @@
+/* ir-nec-decoder.c - handle NEC IR Pulse/Space protocol
+ *
+ * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
+ *
+ *  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.
+ */
+
+#include <linux/bitrev.h>
+#include "ir-core-priv.h"
+
+#define NEC_NBITS              32
+#define NEC_UNIT               562500  /* ns */
+#define NEC_HEADER_PULSE       (16 * NEC_UNIT)
+#define NECX_HEADER_PULSE      (8  * NEC_UNIT) /* Less common NEC variant */
+#define NEC_HEADER_SPACE       (8  * NEC_UNIT)
+#define NEC_REPEAT_SPACE       (8  * NEC_UNIT)
+#define NEC_BIT_PULSE          (1  * NEC_UNIT)
+#define NEC_BIT_0_SPACE                (1  * NEC_UNIT)
+#define NEC_BIT_1_SPACE                (3  * NEC_UNIT)
+#define        NEC_TRAILER_PULSE       (1  * NEC_UNIT)
+#define        NEC_TRAILER_SPACE       (10 * NEC_UNIT) /* even longer in reality */
+
+/* Used to register nec_decoder clients */
+static LIST_HEAD(decoder_list);
+static DEFINE_SPINLOCK(decoder_lock);
+
+enum nec_state {
+       STATE_INACTIVE,
+       STATE_HEADER_SPACE,
+       STATE_BIT_PULSE,
+       STATE_BIT_SPACE,
+       STATE_TRAILER_PULSE,
+       STATE_TRAILER_SPACE,
+};
+
+struct decoder_data {
+       struct list_head        list;
+       struct ir_input_dev     *ir_dev;
+       int                     enabled:1;
+
+       /* State machine control */
+       enum nec_state          state;
+       u32                     nec_bits;
+       unsigned                count;
+};
+
+
+/**
+ * get_decoder_data()  - gets decoder data
+ * @input_dev: input device
+ *
+ * Returns the struct decoder_data that corresponds to a device
+ */
+static struct decoder_data *get_decoder_data(struct  ir_input_dev *ir_dev)
+{
+       struct decoder_data *data = NULL;
+
+       spin_lock(&decoder_lock);
+       list_for_each_entry(data, &decoder_list, list) {
+               if (data->ir_dev == ir_dev)
+                       break;
+       }
+       spin_unlock(&decoder_lock);
+       return data;
+}
+
+static ssize_t store_enabled(struct device *d,
+                            struct device_attribute *mattr,
+                            const char *buf,
+                            size_t len)
+{
+       unsigned long value;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (strict_strtoul(buf, 10, &value) || value > 1)
+               return -EINVAL;
+
+       data->enabled = value;
+
+       return len;
+}
+
+static ssize_t show_enabled(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->enabled)
+               return sprintf(buf, "1\n");
+       else
+       return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
+
+static struct attribute *decoder_attributes[] = {
+       &dev_attr_enabled.attr,
+       NULL
+};
+
+static struct attribute_group decoder_attribute_group = {
+       .name   = "nec_decoder",
+       .attrs  = decoder_attributes,
+};
+
+/**
+ * ir_nec_decode() - Decode one NEC pulse or space
+ * @input_dev: the struct input_dev descriptor of the device
+ * @duration:  the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev)
+{
+       struct decoder_data *data;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       u32 scancode;
+       u8 address, not_address, command, not_command;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return -EINVAL;
+
+       if (!data->enabled)
+               return 0;
+
+       if (IS_RESET(ev)) {
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       IR_dprintk(2, "NEC decode started at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+
+       switch (data->state) {
+
+       case STATE_INACTIVE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, NEC_HEADER_PULSE, NEC_UNIT / 2) &&
+                   !eq_margin(ev.duration, NECX_HEADER_PULSE, NEC_UNIT / 2))
+                       break;
+
+               data->count = 0;
+               data->state = STATE_HEADER_SPACE;
+               return 0;
+
+       case STATE_HEADER_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (eq_margin(ev.duration, NEC_HEADER_SPACE, NEC_UNIT / 2)) {
+                       data->state = STATE_BIT_PULSE;
+                       return 0;
+               } else if (eq_margin(ev.duration, NEC_REPEAT_SPACE, NEC_UNIT / 2)) {
+                       ir_repeat(input_dev);
+                       IR_dprintk(1, "Repeat last key\n");
+                       data->state = STATE_TRAILER_PULSE;
+                       return 0;
+               }
+
+               break;
+
+       case STATE_BIT_PULSE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, NEC_BIT_PULSE, NEC_UNIT / 2))
+                       break;
+
+               data->state = STATE_BIT_SPACE;
+               return 0;
+
+       case STATE_BIT_SPACE:
+               if (ev.pulse)
+                       break;
+
+               data->nec_bits <<= 1;
+               if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2))
+                       data->nec_bits |= 1;
+               else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2))
+                       break;
+               data->count++;
+
+               if (data->count == NEC_NBITS)
+                       data->state = STATE_TRAILER_PULSE;
+               else
+                       data->state = STATE_BIT_PULSE;
+
+               return 0;
+
+       case STATE_TRAILER_PULSE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, NEC_TRAILER_PULSE, NEC_UNIT / 2))
+                       break;
+
+               data->state = STATE_TRAILER_SPACE;
+               return 0;
+
+       case STATE_TRAILER_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2))
+                       break;
+
+               address     = bitrev8((data->nec_bits >> 24) & 0xff);
+               not_address = bitrev8((data->nec_bits >> 16) & 0xff);
+               command     = bitrev8((data->nec_bits >>  8) & 0xff);
+               not_command = bitrev8((data->nec_bits >>  0) & 0xff);
+
+               if ((command ^ not_command) != 0xff) {
+                       IR_dprintk(1, "NEC checksum error: received 0x%08x\n",
+                                  data->nec_bits);
+                       break;
+               }
+
+               if ((address ^ not_address) != 0xff) {
+                       /* Extended NEC */
+                       scancode = address     << 16 |
+                                  not_address <<  8 |
+                                  command;
+                       IR_dprintk(1, "NEC (Ext) scancode 0x%06x\n", scancode);
+               } else {
+                       /* Normal NEC */
+                       scancode = address << 8 | command;
+                       IR_dprintk(1, "NEC scancode 0x%04x\n", scancode);
+               }
+
+               ir_keydown(input_dev, scancode, 0);
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       IR_dprintk(1, "NEC decode failed at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+       data->state = STATE_INACTIVE;
+       return -EINVAL;
+}
+
+static int ir_nec_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       struct decoder_data *data;
+       int rc;
+
+       rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+       if (rc < 0)
+               return rc;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+               return -ENOMEM;
+       }
+
+       data->ir_dev = ir_dev;
+       data->enabled = 1;
+
+       spin_lock(&decoder_lock);
+       list_add_tail(&data->list, &decoder_list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static int ir_nec_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       static struct decoder_data *data;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return 0;
+
+       sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+
+       spin_lock(&decoder_lock);
+       list_del(&data->list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static struct ir_raw_handler nec_handler = {
+       .decode         = ir_nec_decode,
+       .raw_register   = ir_nec_register,
+       .raw_unregister = ir_nec_unregister,
+};
+
+static int __init ir_nec_decode_init(void)
+{
+       ir_raw_handler_register(&nec_handler);
+
+       printk(KERN_INFO "IR NEC protocol handler initialized\n");
+       return 0;
+}
+
+static void __exit ir_nec_decode_exit(void)
+{
+       ir_raw_handler_unregister(&nec_handler);
+}
+
+module_init(ir_nec_decode_init);
+module_exit(ir_nec_decode_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
+MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
+MODULE_DESCRIPTION("NEC IR protocol decoder");
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c
new file mode 100644 (file)
index 0000000..ea68a3f
--- /dev/null
@@ -0,0 +1,251 @@
+/* ir-raw-event.c - handle IR Pulse/Space event
+ *
+ * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
+ *
+ *  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.
+ */
+
+#include <linux/workqueue.h>
+#include <linux/spinlock.h>
+#include <linux/sched.h>
+#include "ir-core-priv.h"
+
+/* Define the max number of pulse/space transitions to buffer */
+#define MAX_IR_EVENT_SIZE      512
+
+/* Used to handle IR raw handler extensions */
+static LIST_HEAD(ir_raw_handler_list);
+static DEFINE_SPINLOCK(ir_raw_handler_lock);
+
+/**
+ * RUN_DECODER()       - runs an operation on all IR decoders
+ * @ops:       IR raw handler operation to be called
+ * @arg:       arguments to be passed to the callback
+ *
+ * Calls ir_raw_handler::ops for all registered IR handlers. It prevents
+ * new decode addition/removal while running, by locking ir_raw_handler_lock
+ * mutex. If an error occurs, it stops the ops. Otherwise, it returns a sum
+ * of the return codes.
+ */
+#define RUN_DECODER(ops, ...) ({                                           \
+       struct ir_raw_handler           *_ir_raw_handler;                   \
+       int _sumrc = 0, _rc;                                                \
+       spin_lock(&ir_raw_handler_lock);                                    \
+       list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) {  \
+               if (_ir_raw_handler->ops) {                                 \
+                       _rc = _ir_raw_handler->ops(__VA_ARGS__);            \
+                       if (_rc < 0)                                        \
+                               break;                                      \
+                       _sumrc += _rc;                                      \
+               }                                                           \
+       }                                                                   \
+       spin_unlock(&ir_raw_handler_lock);                                  \
+       _sumrc;                                                             \
+})
+
+#ifdef MODULE
+/* Used to load the decoders */
+static struct work_struct wq_load;
+#endif
+
+static void ir_raw_event_work(struct work_struct *work)
+{
+       struct ir_raw_event ev;
+       struct ir_raw_event_ctrl *raw =
+               container_of(work, struct ir_raw_event_ctrl, rx_work);
+
+       while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev))
+               RUN_DECODER(decode, raw->input_dev, ev);
+}
+
+int ir_raw_event_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir = input_get_drvdata(input_dev);
+       int rc;
+
+       ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL);
+       if (!ir->raw)
+               return -ENOMEM;
+
+       ir->raw->input_dev = input_dev;
+       INIT_WORK(&ir->raw->rx_work, ir_raw_event_work);
+
+       rc = kfifo_alloc(&ir->raw->kfifo, sizeof(s64) * MAX_IR_EVENT_SIZE,
+                        GFP_KERNEL);
+       if (rc < 0) {
+               kfree(ir->raw);
+               ir->raw = NULL;
+               return rc;
+       }
+
+       rc = RUN_DECODER(raw_register, input_dev);
+       if (rc < 0) {
+               kfifo_free(&ir->raw->kfifo);
+               kfree(ir->raw);
+               ir->raw = NULL;
+               return rc;
+       }
+
+       return rc;
+}
+
+void ir_raw_event_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir = input_get_drvdata(input_dev);
+
+       if (!ir->raw)
+               return;
+
+       cancel_work_sync(&ir->raw->rx_work);
+       RUN_DECODER(raw_unregister, input_dev);
+
+       kfifo_free(&ir->raw->kfifo);
+       kfree(ir->raw);
+       ir->raw = NULL;
+}
+
+/**
+ * ir_raw_event_store() - pass a pulse/space duration to the raw ir decoders
+ * @input_dev: the struct input_dev device descriptor
+ * @ev:                the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This routine (which may be called from an interrupt context) stores a
+ * pulse/space duration for the raw ir decoding state machines. Pulses are
+ * signalled as positive values and spaces as negative values. A zero value
+ * will reset the decoding state machines.
+ */
+int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev)
+{
+       struct ir_input_dev *ir = input_get_drvdata(input_dev);
+
+       if (!ir->raw)
+               return -EINVAL;
+
+       if (kfifo_in(&ir->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev))
+               return -ENOMEM;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ir_raw_event_store);
+
+/**
+ * ir_raw_event_store_edge() - notify raw ir decoders of the start of a pulse/space
+ * @input_dev: the struct input_dev device descriptor
+ * @type:      the type of the event that has occurred
+ *
+ * This routine (which may be called from an interrupt context) is used to
+ * store the beginning of an ir pulse or space (or the start/end of ir
+ * reception) for the raw ir decoding state machines. This is used by
+ * hardware which does not provide durations directly but only interrupts
+ * (or similar events) on state change.
+ */
+int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type)
+{
+       struct ir_input_dev     *ir = input_get_drvdata(input_dev);
+       ktime_t                 now;
+       s64                     delta; /* ns */
+       struct ir_raw_event     ev;
+       int                     rc = 0;
+
+       if (!ir->raw)
+               return -EINVAL;
+
+       now = ktime_get();
+       delta = ktime_to_ns(ktime_sub(now, ir->raw->last_event));
+
+       /* Check for a long duration since last event or if we're
+        * being called for the first time, note that delta can't
+        * possibly be negative.
+        */
+       ev.duration = 0;
+       if (delta > IR_MAX_DURATION || !ir->raw->last_type)
+               type |= IR_START_EVENT;
+       else
+               ev.duration = delta;
+
+       if (type & IR_START_EVENT)
+               ir_raw_event_reset(input_dev);
+       else if (ir->raw->last_type & IR_SPACE) {
+               ev.pulse = false;
+               rc = ir_raw_event_store(input_dev, &ev);
+       } else if (ir->raw->last_type & IR_PULSE) {
+               ev.pulse = true;
+               rc = ir_raw_event_store(input_dev, &ev);
+       } else
+               return 0;
+
+       ir->raw->last_event = now;
+       ir->raw->last_type = type;
+       return rc;
+}
+EXPORT_SYMBOL_GPL(ir_raw_event_store_edge);
+
+/**
+ * ir_raw_event_handle() - schedules the decoding of stored ir data
+ * @input_dev: the struct input_dev device descriptor
+ *
+ * This routine will signal the workqueue to start decoding stored ir data.
+ */
+void ir_raw_event_handle(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir = input_get_drvdata(input_dev);
+
+       if (!ir->raw)
+               return;
+
+       schedule_work(&ir->raw->rx_work);
+}
+EXPORT_SYMBOL_GPL(ir_raw_event_handle);
+
+/*
+ * Extension interface - used to register the IR decoders
+ */
+
+int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler)
+{
+       spin_lock(&ir_raw_handler_lock);
+       list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list);
+       spin_unlock(&ir_raw_handler_lock);
+       return 0;
+}
+EXPORT_SYMBOL(ir_raw_handler_register);
+
+void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler)
+{
+       spin_lock(&ir_raw_handler_lock);
+       list_del(&ir_raw_handler->list);
+       spin_unlock(&ir_raw_handler_lock);
+}
+EXPORT_SYMBOL(ir_raw_handler_unregister);
+
+#ifdef MODULE
+static void init_decoders(struct work_struct *work)
+{
+       /* Load the decoder modules */
+
+       load_nec_decode();
+       load_rc5_decode();
+       load_rc6_decode();
+       load_jvc_decode();
+       load_sony_decode();
+
+       /* If needed, we may later add some init code. In this case,
+          it is needed to change the CONFIG_MODULE test at ir-core.h
+        */
+}
+#endif
+
+void ir_raw_init(void)
+{
+#ifdef MODULE
+       INIT_WORK(&wq_load, init_decoders);
+       schedule_work(&wq_load);
+#endif
+}
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c
new file mode 100644 (file)
index 0000000..23cdb1b
--- /dev/null
@@ -0,0 +1,324 @@
+/* ir-rc5-decoder.c - handle RC5(x) IR Pulse/Space protocol
+ *
+ * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
+ *
+ *  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.
+ */
+
+/*
+ * This code handles 14 bits RC5 protocols and 20 bits RC5x protocols.
+ * There are other variants that use a different number of bits.
+ * This is currently unsupported.
+ * It considers a carrier of 36 kHz, with a total of 14/20 bits, where
+ * the first two bits are start bits, and a third one is a filing bit
+ */
+
+#include "ir-core-priv.h"
+
+#define RC5_NBITS              14
+#define RC5X_NBITS             20
+#define CHECK_RC5X_NBITS       8
+#define RC5_UNIT               888888 /* ns */
+#define RC5_BIT_START          (1 * RC5_UNIT)
+#define RC5_BIT_END            (1 * RC5_UNIT)
+#define RC5X_SPACE             (4 * RC5_UNIT)
+
+/* Used to register rc5_decoder clients */
+static LIST_HEAD(decoder_list);
+static DEFINE_SPINLOCK(decoder_lock);
+
+enum rc5_state {
+       STATE_INACTIVE,
+       STATE_BIT_START,
+       STATE_BIT_END,
+       STATE_CHECK_RC5X,
+       STATE_FINISHED,
+};
+
+struct decoder_data {
+       struct list_head        list;
+       struct ir_input_dev     *ir_dev;
+       int                     enabled:1;
+
+       /* State machine control */
+       enum rc5_state          state;
+       u32                     rc5_bits;
+       struct ir_raw_event     prev_ev;
+       unsigned                count;
+       unsigned                wanted_bits;
+};
+
+
+/**
+ * get_decoder_data()  - gets decoder data
+ * @input_dev: input device
+ *
+ * Returns the struct decoder_data that corresponds to a device
+ */
+
+static struct decoder_data *get_decoder_data(struct  ir_input_dev *ir_dev)
+{
+       struct decoder_data *data = NULL;
+
+       spin_lock(&decoder_lock);
+       list_for_each_entry(data, &decoder_list, list) {
+               if (data->ir_dev == ir_dev)
+                       break;
+       }
+       spin_unlock(&decoder_lock);
+       return data;
+}
+
+static ssize_t store_enabled(struct device *d,
+                            struct device_attribute *mattr,
+                            const char *buf,
+                            size_t len)
+{
+       unsigned long value;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (strict_strtoul(buf, 10, &value) || value > 1)
+               return -EINVAL;
+
+       data->enabled = value;
+
+       return len;
+}
+
+static ssize_t show_enabled(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->enabled)
+               return sprintf(buf, "1\n");
+       else
+       return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
+
+static struct attribute *decoder_attributes[] = {
+       &dev_attr_enabled.attr,
+       NULL
+};
+
+static struct attribute_group decoder_attribute_group = {
+       .name   = "rc5_decoder",
+       .attrs  = decoder_attributes,
+};
+
+/**
+ * ir_rc5_decode() - Decode one RC-5 pulse or space
+ * @input_dev: the struct input_dev descriptor of the device
+ * @ev:                the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev)
+{
+       struct decoder_data *data;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       u8 toggle;
+       u32 scancode;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return -EINVAL;
+
+       if (!data->enabled)
+               return 0;
+
+       if (IS_RESET(ev)) {
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2))
+               goto out;
+
+again:
+       IR_dprintk(2, "RC5(x) decode started at state %i (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+
+       if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2))
+               return 0;
+
+       switch (data->state) {
+
+       case STATE_INACTIVE:
+               if (!ev.pulse)
+                       break;
+
+               data->state = STATE_BIT_START;
+               data->count = 1;
+               /* We just need enough bits to get to STATE_CHECK_RC5X */
+               data->wanted_bits = RC5X_NBITS;
+               decrease_duration(&ev, RC5_BIT_START);
+               goto again;
+
+       case STATE_BIT_START:
+               if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2))
+                       break;
+
+               data->rc5_bits <<= 1;
+               if (!ev.pulse)
+                       data->rc5_bits |= 1;
+               data->count++;
+               data->prev_ev = ev;
+               data->state = STATE_BIT_END;
+               return 0;
+
+       case STATE_BIT_END:
+               if (!is_transition(&ev, &data->prev_ev))
+                       break;
+
+               if (data->count == data->wanted_bits)
+                       data->state = STATE_FINISHED;
+               else if (data->count == CHECK_RC5X_NBITS)
+                       data->state = STATE_CHECK_RC5X;
+               else
+                       data->state = STATE_BIT_START;
+
+               decrease_duration(&ev, RC5_BIT_END);
+               goto again;
+
+       case STATE_CHECK_RC5X:
+               if (!ev.pulse && geq_margin(ev.duration, RC5X_SPACE, RC5_UNIT / 2)) {
+                       /* RC5X */
+                       data->wanted_bits = RC5X_NBITS;
+                       decrease_duration(&ev, RC5X_SPACE);
+               } else {
+                       /* RC5 */
+                       data->wanted_bits = RC5_NBITS;
+               }
+               data->state = STATE_BIT_START;
+               goto again;
+
+       case STATE_FINISHED:
+               if (ev.pulse)
+                       break;
+
+               if (data->wanted_bits == RC5X_NBITS) {
+                       /* RC5X */
+                       u8 xdata, command, system;
+                       xdata    = (data->rc5_bits & 0x0003F) >> 0;
+                       command  = (data->rc5_bits & 0x00FC0) >> 6;
+                       system   = (data->rc5_bits & 0x1F000) >> 12;
+                       toggle   = (data->rc5_bits & 0x20000) ? 1 : 0;
+                       command += (data->rc5_bits & 0x01000) ? 0 : 0x40;
+                       scancode = system << 16 | command << 8 | xdata;
+
+                       IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n",
+                                  scancode, toggle);
+
+               } else {
+                       /* RC5 */
+                       u8 command, system;
+                       command  = (data->rc5_bits & 0x0003F) >> 0;
+                       system   = (data->rc5_bits & 0x007C0) >> 6;
+                       toggle   = (data->rc5_bits & 0x00800) ? 1 : 0;
+                       command += (data->rc5_bits & 0x01000) ? 0 : 0x40;
+                       scancode = system << 8 | command;
+
+                       IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n",
+                                  scancode, toggle);
+               }
+
+               ir_keydown(input_dev, scancode, toggle);
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+out:
+       IR_dprintk(1, "RC5(x) decode failed at state %i (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+       data->state = STATE_INACTIVE;
+       return -EINVAL;
+}
+
+static int ir_rc5_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       struct decoder_data *data;
+       int rc;
+
+       rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+       if (rc < 0)
+               return rc;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+               return -ENOMEM;
+       }
+
+       data->ir_dev = ir_dev;
+       data->enabled = 1;
+
+       spin_lock(&decoder_lock);
+       list_add_tail(&data->list, &decoder_list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static int ir_rc5_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       static struct decoder_data *data;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return 0;
+
+       sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+
+       spin_lock(&decoder_lock);
+       list_del(&data->list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static struct ir_raw_handler rc5_handler = {
+       .decode         = ir_rc5_decode,
+       .raw_register   = ir_rc5_register,
+       .raw_unregister = ir_rc5_unregister,
+};
+
+static int __init ir_rc5_decode_init(void)
+{
+       ir_raw_handler_register(&rc5_handler);
+
+       printk(KERN_INFO "IR RC5(x) protocol handler initialized\n");
+       return 0;
+}
+
+static void __exit ir_rc5_decode_exit(void)
+{
+       ir_raw_handler_unregister(&rc5_handler);
+}
+
+module_init(ir_rc5_decode_init);
+module_exit(ir_rc5_decode_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
+MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
+MODULE_DESCRIPTION("RC5(x) IR protocol decoder");
diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/IR/ir-rc6-decoder.c
new file mode 100644 (file)
index 0000000..2bf479f
--- /dev/null
@@ -0,0 +1,419 @@
+/* ir-rc6-decoder.c - A decoder for the RC6 IR protocol
+ *
+ * Copyright (C) 2010 by David Härdeman <david@hardeman.nu>
+ *
+ * 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 of the License.
+ *
+ * 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.
+ */
+
+#include "ir-core-priv.h"
+
+/*
+ * This decoder currently supports:
+ * RC6-0-16    (standard toggle bit in header)
+ * RC6-6A-24   (no toggle bit)
+ * RC6-6A-32   (MCE version with toggle bit in body)
+ */
+
+#define RC6_UNIT               444444  /* us */
+#define RC6_HEADER_NBITS       4       /* not including toggle bit */
+#define RC6_0_NBITS            16
+#define RC6_6A_SMALL_NBITS     24
+#define RC6_6A_LARGE_NBITS     32
+#define RC6_PREFIX_PULSE       (6 * RC6_UNIT)
+#define RC6_PREFIX_SPACE       (2 * RC6_UNIT)
+#define RC6_BIT_START          (1 * RC6_UNIT)
+#define RC6_BIT_END            (1 * RC6_UNIT)
+#define RC6_TOGGLE_START       (2 * RC6_UNIT)
+#define RC6_TOGGLE_END         (2 * RC6_UNIT)
+#define RC6_MODE_MASK          0x07    /* for the header bits */
+#define RC6_STARTBIT_MASK      0x08    /* for the header bits */
+#define RC6_6A_MCE_TOGGLE_MASK 0x8000  /* for the body bits */
+
+/* Used to register rc6_decoder clients */
+static LIST_HEAD(decoder_list);
+static DEFINE_SPINLOCK(decoder_lock);
+
+enum rc6_mode {
+       RC6_MODE_0,
+       RC6_MODE_6A,
+       RC6_MODE_UNKNOWN,
+};
+
+enum rc6_state {
+       STATE_INACTIVE,
+       STATE_PREFIX_SPACE,
+       STATE_HEADER_BIT_START,
+       STATE_HEADER_BIT_END,
+       STATE_TOGGLE_START,
+       STATE_TOGGLE_END,
+       STATE_BODY_BIT_START,
+       STATE_BODY_BIT_END,
+       STATE_FINISHED,
+};
+
+struct decoder_data {
+       struct list_head        list;
+       struct ir_input_dev     *ir_dev;
+       int                     enabled:1;
+
+       /* State machine control */
+       enum rc6_state          state;
+       u8                      header;
+       u32                     body;
+       struct ir_raw_event     prev_ev;
+       bool                    toggle;
+       unsigned                count;
+       unsigned                wanted_bits;
+};
+
+
+/**
+ * get_decoder_data()  - gets decoder data
+ * @input_dev: input device
+ *
+ * Returns the struct decoder_data that corresponds to a device
+ */
+static struct decoder_data *get_decoder_data(struct  ir_input_dev *ir_dev)
+{
+       struct decoder_data *data = NULL;
+
+       spin_lock(&decoder_lock);
+       list_for_each_entry(data, &decoder_list, list) {
+               if (data->ir_dev == ir_dev)
+                       break;
+       }
+       spin_unlock(&decoder_lock);
+       return data;
+}
+
+static ssize_t store_enabled(struct device *d,
+                            struct device_attribute *mattr,
+                            const char *buf,
+                            size_t len)
+{
+       unsigned long value;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (strict_strtoul(buf, 10, &value) || value > 1)
+               return -EINVAL;
+
+       data->enabled = value;
+
+       return len;
+}
+
+static ssize_t show_enabled(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->enabled)
+               return sprintf(buf, "1\n");
+       else
+       return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
+
+static struct attribute *decoder_attributes[] = {
+       &dev_attr_enabled.attr,
+       NULL
+};
+
+static struct attribute_group decoder_attribute_group = {
+       .name   = "rc6_decoder",
+       .attrs  = decoder_attributes,
+};
+
+static enum rc6_mode rc6_mode(struct decoder_data *data) {
+       switch (data->header & RC6_MODE_MASK) {
+       case 0:
+               return RC6_MODE_0;
+       case 6:
+               if (!data->toggle)
+                       return RC6_MODE_6A;
+               /* fall through */
+       default:
+               return RC6_MODE_UNKNOWN;
+       }
+}
+
+/**
+ * ir_rc6_decode() - Decode one RC6 pulse or space
+ * @input_dev: the struct input_dev descriptor of the device
+ * @ev:                the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev)
+{
+       struct decoder_data *data;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       u32 scancode;
+       u8 toggle;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return -EINVAL;
+
+       if (!data->enabled)
+               return 0;
+
+       if (IS_RESET(ev)) {
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       if (!geq_margin(ev.duration, RC6_UNIT, RC6_UNIT / 2))
+               goto out;
+
+again:
+       IR_dprintk(2, "RC6 decode started at state %i (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+
+       if (!geq_margin(ev.duration, RC6_UNIT, RC6_UNIT / 2))
+               return 0;
+
+       switch (data->state) {
+
+       case STATE_INACTIVE:
+               if (!ev.pulse)
+                       break;
+
+               /* Note: larger margin on first pulse since each RC6_UNIT
+                  is quite short and some hardware takes some time to
+                  adjust to the signal */
+               if (!eq_margin(ev.duration, RC6_PREFIX_PULSE, RC6_UNIT))
+                       break;
+
+               data->state = STATE_PREFIX_SPACE;
+               data->count = 0;
+               return 0;
+
+       case STATE_PREFIX_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, RC6_PREFIX_SPACE, RC6_UNIT / 2))
+                       break;
+
+               data->state = STATE_HEADER_BIT_START;
+               return 0;
+
+       case STATE_HEADER_BIT_START:
+               if (!eq_margin(ev.duration, RC6_BIT_START, RC6_UNIT / 2))
+                       break;
+
+               data->header <<= 1;
+               if (ev.pulse)
+                       data->header |= 1;
+               data->count++;
+               data->prev_ev = ev;
+               data->state = STATE_HEADER_BIT_END;
+               return 0;
+
+       case STATE_HEADER_BIT_END:
+               if (!is_transition(&ev, &data->prev_ev))
+                       break;
+
+               if (data->count == RC6_HEADER_NBITS)
+                       data->state = STATE_TOGGLE_START;
+               else
+                       data->state = STATE_HEADER_BIT_START;
+
+               decrease_duration(&ev, RC6_BIT_END);
+               goto again;
+
+       case STATE_TOGGLE_START:
+               if (!eq_margin(ev.duration, RC6_TOGGLE_START, RC6_UNIT / 2))
+                       break;
+
+               data->toggle = ev.pulse;
+               data->prev_ev = ev;
+               data->state = STATE_TOGGLE_END;
+               return 0;
+
+       case STATE_TOGGLE_END:
+               if (!is_transition(&ev, &data->prev_ev) ||
+                   !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2))
+                       break;
+
+               if (!(data->header & RC6_STARTBIT_MASK)) {
+                       IR_dprintk(1, "RC6 invalid start bit\n");
+                       break;
+               }
+
+               data->state = STATE_BODY_BIT_START;
+               data->prev_ev = ev;
+               decrease_duration(&ev, RC6_TOGGLE_END);
+               data->count = 0;
+
+               switch (rc6_mode(data)) {
+               case RC6_MODE_0:
+                       data->wanted_bits = RC6_0_NBITS;
+                       break;
+               case RC6_MODE_6A:
+                       /* This might look weird, but we basically
+                          check the value of the first body bit to
+                          determine the number of bits in mode 6A */
+                       if ((!ev.pulse && !geq_margin(ev.duration, RC6_UNIT, RC6_UNIT / 2)) ||
+                           geq_margin(ev.duration, RC6_UNIT, RC6_UNIT / 2))
+                               data->wanted_bits = RC6_6A_LARGE_NBITS;
+                       else
+                               data->wanted_bits = RC6_6A_SMALL_NBITS;
+                       break;
+               default:
+                       IR_dprintk(1, "RC6 unknown mode\n");
+                       goto out;
+               }
+               goto again;
+
+       case STATE_BODY_BIT_START:
+               if (!eq_margin(ev.duration, RC6_BIT_START, RC6_UNIT / 2))
+                       break;
+
+               data->body <<= 1;
+               if (ev.pulse)
+                       data->body |= 1;
+               data->count++;
+               data->prev_ev = ev;
+
+               data->state = STATE_BODY_BIT_END;
+               return 0;
+
+       case STATE_BODY_BIT_END:
+               if (!is_transition(&ev, &data->prev_ev))
+                       break;
+
+               if (data->count == data->wanted_bits)
+                       data->state = STATE_FINISHED;
+               else
+                       data->state = STATE_BODY_BIT_START;
+
+               decrease_duration(&ev, RC6_BIT_END);
+               goto again;
+
+       case STATE_FINISHED:
+               if (ev.pulse)
+                       break;
+
+               switch (rc6_mode(data)) {
+               case RC6_MODE_0:
+                       scancode = data->body & 0xffff;
+                       toggle = data->toggle;
+                       IR_dprintk(1, "RC6(0) scancode 0x%04x (toggle: %u)\n",
+                                  scancode, toggle);
+                       break;
+               case RC6_MODE_6A:
+                       if (data->wanted_bits == RC6_6A_LARGE_NBITS) {
+                               toggle = data->body & RC6_6A_MCE_TOGGLE_MASK ? 1 : 0;
+                               scancode = data->body & ~RC6_6A_MCE_TOGGLE_MASK;
+                       } else {
+                               toggle = 0;
+                               scancode = data->body & 0xffffff;
+                       }
+
+                       IR_dprintk(1, "RC6(6A) scancode 0x%08x (toggle: %u)\n",
+                                  scancode, toggle);
+                       break;
+               default:
+                       IR_dprintk(1, "RC6 unknown mode\n");
+                       goto out;
+               }
+
+               ir_keydown(input_dev, scancode, toggle);
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+out:
+       IR_dprintk(1, "RC6 decode failed at state %i (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+       data->state = STATE_INACTIVE;
+       return -EINVAL;
+}
+
+static int ir_rc6_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       struct decoder_data *data;
+       int rc;
+
+       rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+       if (rc < 0)
+               return rc;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+               return -ENOMEM;
+       }
+
+       data->ir_dev = ir_dev;
+       data->enabled = 1;
+
+       spin_lock(&decoder_lock);
+       list_add_tail(&data->list, &decoder_list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static int ir_rc6_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       static struct decoder_data *data;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return 0;
+
+       sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+
+       spin_lock(&decoder_lock);
+       list_del(&data->list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static struct ir_raw_handler rc6_handler = {
+       .decode         = ir_rc6_decode,
+       .raw_register   = ir_rc6_register,
+       .raw_unregister = ir_rc6_unregister,
+};
+
+static int __init ir_rc6_decode_init(void)
+{
+       ir_raw_handler_register(&rc6_handler);
+
+       printk(KERN_INFO "IR RC6 protocol handler initialized\n");
+       return 0;
+}
+
+static void __exit ir_rc6_decode_exit(void)
+{
+       ir_raw_handler_unregister(&rc6_handler);
+}
+
+module_init(ir_rc6_decode_init);
+module_exit(ir_rc6_decode_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
+MODULE_DESCRIPTION("RC6 IR protocol decoder");
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c
new file mode 100644 (file)
index 0000000..9f440c5
--- /dev/null
@@ -0,0 +1,312 @@
+/* ir-sony-decoder.c - handle Sony IR Pulse/Space protocol
+ *
+ * Copyright (C) 2010 by David Härdeman <david@hardeman.nu>
+ *
+ * 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 of the License.
+ *
+ * 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.
+ */
+
+#include <linux/bitrev.h>
+#include "ir-core-priv.h"
+
+#define SONY_UNIT              600000 /* ns */
+#define SONY_HEADER_PULSE      (4 * SONY_UNIT)
+#define        SONY_HEADER_SPACE       (1 * SONY_UNIT)
+#define SONY_BIT_0_PULSE       (1 * SONY_UNIT)
+#define SONY_BIT_1_PULSE       (2 * SONY_UNIT)
+#define SONY_BIT_SPACE         (1 * SONY_UNIT)
+#define SONY_TRAILER_SPACE     (10 * SONY_UNIT) /* minimum */
+
+/* Used to register sony_decoder clients */
+static LIST_HEAD(decoder_list);
+static DEFINE_SPINLOCK(decoder_lock);
+
+enum sony_state {
+       STATE_INACTIVE,
+       STATE_HEADER_SPACE,
+       STATE_BIT_PULSE,
+       STATE_BIT_SPACE,
+       STATE_FINISHED,
+};
+
+struct decoder_data {
+       struct list_head        list;
+       struct ir_input_dev     *ir_dev;
+       int                     enabled:1;
+
+       /* State machine control */
+       enum sony_state         state;
+       u32                     sony_bits;
+       unsigned                count;
+};
+
+
+/**
+ * get_decoder_data()  - gets decoder data
+ * @input_dev: input device
+ *
+ * Returns the struct decoder_data that corresponds to a device
+ */
+static struct decoder_data *get_decoder_data(struct  ir_input_dev *ir_dev)
+{
+       struct decoder_data *data = NULL;
+
+       spin_lock(&decoder_lock);
+       list_for_each_entry(data, &decoder_list, list) {
+               if (data->ir_dev == ir_dev)
+                       break;
+       }
+       spin_unlock(&decoder_lock);
+       return data;
+}
+
+static ssize_t store_enabled(struct device *d,
+                            struct device_attribute *mattr,
+                            const char *buf,
+                            size_t len)
+{
+       unsigned long value;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (strict_strtoul(buf, 10, &value) || value > 1)
+               return -EINVAL;
+
+       data->enabled = value;
+
+       return len;
+}
+
+static ssize_t show_enabled(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+       struct decoder_data *data = get_decoder_data(ir_dev);
+
+       if (!data)
+               return -EINVAL;
+
+       if (data->enabled)
+               return sprintf(buf, "1\n");
+       else
+       return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(enabled, S_IRUGO | S_IWUSR, show_enabled, store_enabled);
+
+static struct attribute *decoder_attributes[] = {
+       &dev_attr_enabled.attr,
+       NULL
+};
+
+static struct attribute_group decoder_attribute_group = {
+       .name   = "sony_decoder",
+       .attrs  = decoder_attributes,
+};
+
+/**
+ * ir_sony_decode() - Decode one Sony pulse or space
+ * @input_dev: the struct input_dev descriptor of the device
+ * @ev:         the struct ir_raw_event descriptor of the pulse/space
+ *
+ * This function returns -EINVAL if the pulse violates the state machine
+ */
+static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
+{
+       struct decoder_data *data;
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       u32 scancode;
+       u8 device, subdevice, function;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return -EINVAL;
+
+       if (!data->enabled)
+               return 0;
+
+       if (IS_RESET(ev)) {
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+       if (!geq_margin(ev.duration, SONY_UNIT, SONY_UNIT / 2))
+               goto out;
+
+       IR_dprintk(2, "Sony decode started at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+
+       switch (data->state) {
+
+       case STATE_INACTIVE:
+               if (!ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, SONY_HEADER_PULSE, SONY_UNIT / 2))
+                       break;
+
+               data->count = 0;
+               data->state = STATE_HEADER_SPACE;
+               return 0;
+
+       case STATE_HEADER_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!eq_margin(ev.duration, SONY_HEADER_SPACE, SONY_UNIT / 2))
+                       break;
+
+               data->state = STATE_BIT_PULSE;
+               return 0;
+
+       case STATE_BIT_PULSE:
+               if (!ev.pulse)
+                       break;
+
+               data->sony_bits <<= 1;
+               if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2))
+                       data->sony_bits |= 1;
+               else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2))
+                       break;
+
+               data->count++;
+               data->state = STATE_BIT_SPACE;
+               return 0;
+
+       case STATE_BIT_SPACE:
+               if (ev.pulse)
+                       break;
+
+               if (!geq_margin(ev.duration, SONY_BIT_SPACE, SONY_UNIT / 2))
+                       break;
+
+               decrease_duration(&ev, SONY_BIT_SPACE);
+
+               if (!geq_margin(ev.duration, SONY_UNIT, SONY_UNIT / 2)) {
+                       data->state = STATE_BIT_PULSE;
+                       return 0;
+               }
+
+               data->state = STATE_FINISHED;
+               /* Fall through */
+
+       case STATE_FINISHED:
+               if (ev.pulse)
+                       break;
+
+               if (!geq_margin(ev.duration, SONY_TRAILER_SPACE, SONY_UNIT / 2))
+                       break;
+
+               switch (data->count) {
+               case 12:
+                       device    = bitrev8((data->sony_bits <<  3) & 0xF8);
+                       subdevice = 0;
+                       function  = bitrev8((data->sony_bits >>  4) & 0xFE);
+                       break;
+               case 15:
+                       device    = bitrev8((data->sony_bits >>  0) & 0xFF);
+                       subdevice = 0;
+                       function  = bitrev8((data->sony_bits >>  7) & 0xFD);
+                       break;
+               case 20:
+                       device    = bitrev8((data->sony_bits >>  5) & 0xF8);
+                       subdevice = bitrev8((data->sony_bits >>  0) & 0xFF);
+                       function  = bitrev8((data->sony_bits >> 12) & 0xFE);
+                       break;
+               default:
+                       IR_dprintk(1, "Sony invalid bitcount %u\n", data->count);
+                       goto out;
+               }
+
+               scancode = device << 16 | subdevice << 8 | function;
+               IR_dprintk(1, "Sony(%u) scancode 0x%05x\n", data->count, scancode);
+               ir_keydown(input_dev, scancode, 0);
+               data->state = STATE_INACTIVE;
+               return 0;
+       }
+
+out:
+       IR_dprintk(1, "Sony decode failed at state %d (%uus %s)\n",
+                  data->state, TO_US(ev.duration), TO_STR(ev.pulse));
+       data->state = STATE_INACTIVE;
+       return -EINVAL;
+}
+
+static int ir_sony_register(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       struct decoder_data *data;
+       int rc;
+
+       rc = sysfs_create_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+       if (rc < 0)
+               return rc;
+
+       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       if (!data) {
+               sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+               return -ENOMEM;
+       }
+
+       data->ir_dev = ir_dev;
+       data->enabled = 1;
+
+       spin_lock(&decoder_lock);
+       list_add_tail(&data->list, &decoder_list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static int ir_sony_unregister(struct input_dev *input_dev)
+{
+       struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
+       static struct decoder_data *data;
+
+       data = get_decoder_data(ir_dev);
+       if (!data)
+               return 0;
+
+       sysfs_remove_group(&ir_dev->dev.kobj, &decoder_attribute_group);
+
+       spin_lock(&decoder_lock);
+       list_del(&data->list);
+       spin_unlock(&decoder_lock);
+
+       return 0;
+}
+
+static struct ir_raw_handler sony_handler = {
+       .decode         = ir_sony_decode,
+       .raw_register   = ir_sony_register,
+       .raw_unregister = ir_sony_unregister,
+};
+
+static int __init ir_sony_decode_init(void)
+{
+       ir_raw_handler_register(&sony_handler);
+
+       printk(KERN_INFO "IR Sony protocol handler initialized\n");
+       return 0;
+}
+
+static void __exit ir_sony_decode_exit(void)
+{
+       ir_raw_handler_unregister(&sony_handler);
+}
+
+module_init(ir_sony_decode_init);
+module_exit(ir_sony_decode_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Härdeman <david@hardeman.nu>");
+MODULE_DESCRIPTION("Sony IR protocol decoder");
index e14e6c4..d7da63e 100644 (file)
@@ -1,6 +1,6 @@
-/* ir-register.c - handle IR scancode->keycode tables
+/* ir-sysfs.c - sysfs interface for RC devices (/sys/class/rc)
  *
- * Copyright (C) 2009 by Mauro Carvalho Chehab <mchehab@redhat.com>
+ * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.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
 #include <linux/slab.h>
 #include <linux/input.h>
 #include <linux/device.h>
-#include <media/ir-core.h>
+#include "ir-core-priv.h"
 
 #define IRRCV_NUM_DEVICES      256
 
 /* bit array to represent IR sysfs device number */
 static unsigned long ir_core_dev_number;
 
-/* class for /sys/class/irrcv */
-static struct class *ir_input_class;
+/* class for /sys/class/rc */
+static char *ir_devnode(struct device *dev, mode_t *mode)
+{
+       return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev));
+}
+
+static struct class ir_input_class = {
+       .name           = "rc",
+       .devnode        = ir_devnode,
+};
 
 /**
  * show_protocol() - shows the current IR protocol
@@ -32,7 +40,7 @@ static struct class *ir_input_class;
  * @buf:       a pointer to the output buffer
  *
  * This routine is a callback routine for input read the IR protocol type.
- * it is trigged by reading /sys/class/irrcv/irrcv?/current_protocol.
+ * it is trigged by reading /sys/class/rc/rc?/current_protocol.
  * It returns the protocol name, as understood by the driver.
  */
 static ssize_t show_protocol(struct device *d,
@@ -48,13 +56,17 @@ static ssize_t show_protocol(struct device *d,
        if (ir_type == IR_TYPE_UNKNOWN)
                s = "Unknown";
        else if (ir_type == IR_TYPE_RC5)
-               s = "RC-5";
-       else if (ir_type == IR_TYPE_PD)
-               s = "Pulse/distance";
+               s = "rc-5";
        else if (ir_type == IR_TYPE_NEC)
-               s = "NEC";
+               s = "nec";
+       else if (ir_type == IR_TYPE_RC6)
+               s = "rc6";
+       else if (ir_type == IR_TYPE_JVC)
+               s = "jvc";
+       else if (ir_type == IR_TYPE_SONY)
+               s = "sony";
        else
-               s = "Other";
+               s = "other";
 
        return sprintf(buf, "%s\n", s);
 }
@@ -67,7 +79,7 @@ static ssize_t show_protocol(struct device *d,
  * @len:       length of the input buffer
  *
  * This routine is a callback routine for changing the IR protocol type.
- * it is trigged by reading /sys/class/irrcv/irrcv?/current_protocol.
+ * it is trigged by reading /sys/class/rc/rc?/current_protocol.
  * It changes the IR the protocol name, if the IR type is recognized
  * by the driver.
  * If an unknown protocol name is used, returns -EINVAL.
@@ -78,23 +90,24 @@ static ssize_t store_protocol(struct device *d,
                              size_t len)
 {
        struct ir_input_dev *ir_dev = dev_get_drvdata(d);
-       u64 ir_type = IR_TYPE_UNKNOWN;
+       u64 ir_type = 0;
        int rc = -EINVAL;
        unsigned long flags;
        char *buf;
 
-       buf = strsep((char **) &data, "\n");
-
-       if (!strcasecmp(buf, "rc-5"))
-               ir_type = IR_TYPE_RC5;
-       else if (!strcasecmp(buf, "pd"))
-               ir_type = IR_TYPE_PD;
-       else if (!strcasecmp(buf, "nec"))
-               ir_type = IR_TYPE_NEC;
+       while ((buf = strsep((char **) &data, " \n")) != NULL) {
+               if (!strcasecmp(buf, "rc-5") || !strcasecmp(buf, "rc5"))
+                       ir_type |= IR_TYPE_RC5;
+               if (!strcasecmp(buf, "nec"))
+                       ir_type |= IR_TYPE_NEC;
+               if (!strcasecmp(buf, "jvc"))
+                       ir_type |= IR_TYPE_JVC;
+               if (!strcasecmp(buf, "sony"))
+                       ir_type |= IR_TYPE_SONY;
+       }
 
-       if (ir_type == IR_TYPE_UNKNOWN) {
-               IR_dprintk(1, "Error setting protocol to %lld\n",
-                          (long long)ir_type);
+       if (!ir_type) {
+               IR_dprintk(1, "Unknown protocol\n");
                return -EINVAL;
        }
 
@@ -112,25 +125,87 @@ static ssize_t store_protocol(struct device *d,
        ir_dev->rc_tab.ir_type = ir_type;
        spin_unlock_irqrestore(&ir_dev->rc_tab.lock, flags);
 
-       IR_dprintk(1, "Current protocol is %lld\n",
+       IR_dprintk(1, "Current protocol(s) is(are) %lld\n",
                   (long long)ir_type);
 
        return len;
 }
 
+static ssize_t show_supported_protocols(struct device *d,
+                            struct device_attribute *mattr, char *buf)
+{
+       char *orgbuf = buf;
+       struct ir_input_dev *ir_dev = dev_get_drvdata(d);
+
+       /* FIXME: doesn't support multiple protocols at the same time */
+       if (ir_dev->props->allowed_protos == IR_TYPE_UNKNOWN)
+               buf += sprintf(buf, "unknown ");
+       if (ir_dev->props->allowed_protos & IR_TYPE_RC5)
+               buf += sprintf(buf, "rc-5 ");
+       if (ir_dev->props->allowed_protos & IR_TYPE_NEC)
+               buf += sprintf(buf, "nec ");
+       if (buf == orgbuf)
+               buf += sprintf(buf, "other ");
+
+       buf += sprintf(buf - 1, "\n");
+
+       return buf - orgbuf;
+}
+
+#define ADD_HOTPLUG_VAR(fmt, val...)                                   \
+       do {                                                            \
+               int err = add_uevent_var(env, fmt, val);                \
+               if (err)                                                \
+                       return err;                                     \
+       } while (0)
+
+static int ir_dev_uevent(struct device *device, struct kobj_uevent_env *env)
+{
+       struct ir_input_dev *ir_dev = dev_get_drvdata(device);
+
+       if (ir_dev->rc_tab.name)
+               ADD_HOTPLUG_VAR("NAME=%s", ir_dev->rc_tab.name);
+       if (ir_dev->driver_name)
+               ADD_HOTPLUG_VAR("DRV_NAME=%s", ir_dev->driver_name);
+
+       return 0;
+}
+
 /*
  * Static device attribute struct with the sysfs attributes for IR's
  */
-static DEVICE_ATTR(current_protocol, S_IRUGO | S_IWUSR,
+static DEVICE_ATTR(protocol, S_IRUGO | S_IWUSR,
                   show_protocol, store_protocol);
 
-static struct attribute *ir_dev_attrs[] = {
-       &dev_attr_current_protocol.attr,
+static DEVICE_ATTR(supported_protocols, S_IRUGO | S_IWUSR,
+                  show_supported_protocols, NULL);
+
+static struct attribute *ir_hw_dev_attrs[] = {
+       &dev_attr_protocol.attr,
+       &dev_attr_supported_protocols.attr,
        NULL,
 };
 
+static struct attribute_group ir_hw_dev_attr_grp = {
+       .attrs  = ir_hw_dev_attrs,
+};
+
+static const struct attribute_group *ir_hw_dev_attr_groups[] = {
+       &ir_hw_dev_attr_grp,
+       NULL
+};
+
+static struct device_type rc_dev_type = {
+       .groups         = ir_hw_dev_attr_groups,
+       .uevent         = ir_dev_uevent,
+};
+
+static struct device_type ir_raw_dev_type = {
+       .uevent         = ir_dev_uevent,
+};
+
 /**
- * ir_register_class() - creates the sysfs for /sys/class/irrcv/irrcv?
+ * ir_register_class() - creates the sysfs for /sys/class/rc/rc?
  * @input_dev: the struct input_dev descriptor of the device
  *
  * This routine is used to register the syfs code for IR class
@@ -138,8 +213,7 @@ static struct attribute *ir_dev_attrs[] = {
 int ir_register_class(struct input_dev *input_dev)
 {
        int rc;
-       struct kobject *kobj;
-
+       const char *path;
        struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
        int devno = find_first_zero_bit(&ir_core_dev_number,
                                        IRRCV_NUM_DEVICES);
@@ -147,19 +221,36 @@ int ir_register_class(struct input_dev *input_dev)
        if (unlikely(devno < 0))
                return devno;
 
-       ir_dev->attr.attrs = ir_dev_attrs;
-       ir_dev->class_dev = device_create(ir_input_class, NULL,
-                                         input_dev->dev.devt, ir_dev,
-                                         "irrcv%d", devno);
-       kobj = &ir_dev->class_dev->kobj;
-
-       printk(KERN_WARNING "Creating IR device %s\n", kobject_name(kobj));
-       rc = sysfs_create_group(kobj, &ir_dev->attr);
-       if (unlikely(rc < 0)) {
-               device_destroy(ir_input_class, input_dev->dev.devt);
-               return -ENOMEM;
+       if (ir_dev->props->driver_type == RC_DRIVER_SCANCODE)
+               ir_dev->dev.type = &rc_dev_type;
+       else
+               ir_dev->dev.type = &ir_raw_dev_type;
+
+       ir_dev->dev.class = &ir_input_class;
+       ir_dev->dev.parent = input_dev->dev.parent;
+       dev_set_name(&ir_dev->dev, "rc%d", devno);
+       dev_set_drvdata(&ir_dev->dev, ir_dev);
+       rc = device_register(&ir_dev->dev);
+       if (rc)
+               return rc;
+
+
+       input_dev->dev.parent = &ir_dev->dev;
+       rc = input_register_device(input_dev);
+       if (rc < 0) {
+               device_del(&ir_dev->dev);
+               return rc;
        }
 
+       __module_get(THIS_MODULE);
+
+       path = kobject_get_path(&ir_dev->dev.kobj, GFP_KERNEL);
+       printk(KERN_INFO "%s: %s as %s\n",
+               dev_name(&ir_dev->dev),
+               input_dev->name ? input_dev->name : "Unspecified device",
+               path ? path : "N/A");
+       kfree(path);
+
        ir_dev->devno = devno;
        set_bit(devno, &ir_core_dev_number);
 
@@ -168,7 +259,7 @@ int ir_register_class(struct input_dev *input_dev)
 
 /**
  * ir_unregister_class() - removes the sysfs for sysfs for
- *                        /sys/class/irrcv/irrcv?
+ *                        /sys/class/rc/rc?
  * @input_dev: the struct input_dev descriptor of the device
  *
  * This routine is used to unregister the syfs code for IR class
@@ -176,36 +267,35 @@ int ir_register_class(struct input_dev *input_dev)
 void ir_unregister_class(struct input_dev *input_dev)
 {
        struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
-       struct kobject *kobj;
 
        clear_bit(ir_dev->devno, &ir_core_dev_number);
+       input_unregister_device(input_dev);
+       device_del(&ir_dev->dev);
 
-       kobj = &ir_dev->class_dev->kobj;
-
-       sysfs_remove_group(kobj, &ir_dev->attr);
-       device_destroy(ir_input_class, input_dev->dev.devt);
-
-       kfree(ir_dev->attr.name);
+       module_put(THIS_MODULE);
 }
 
 /*
- * Init/exit code for the module. Basically, creates/removes /sys/class/irrcv
+ * Init/exit code for the module. Basically, creates/removes /sys/class/rc
  */
 
 static int __init ir_core_init(void)
 {
-       ir_input_class = class_create(THIS_MODULE, "irrcv");
-       if (IS_ERR(ir_input_class)) {
-               printk(KERN_ERR "ir_core: unable to register irrcv class\n");
-               return PTR_ERR(ir_input_class);
+       int rc = class_register(&ir_input_class);
+       if (rc) {
+               printk(KERN_ERR "ir_core: unable to register rc class\n");
+               return rc;
        }
 
+       /* Initialize/load the decoders/keymap code that will be used */
+       ir_raw_init();
+
        return 0;
 }
 
 static void __exit ir_core_exit(void)
 {
-       class_destroy(ir_input_class);
+       class_unregister(&ir_input_class);
 }
 
 module_init(ir_core_init);
diff --git a/drivers/media/IR/keymaps/Kconfig b/drivers/media/IR/keymaps/Kconfig
new file mode 100644 (file)
index 0000000..14b22f5
--- /dev/null
@@ -0,0 +1,15 @@
+config RC_MAP
+       tristate "Compile Remote Controller keymap modules"
+       depends on IR_CORE
+       default y
+
+       ---help---
+          This option enables the compilation of lots of Remote
+          Controller tables. They are short tables, but if you
+          don't use a remote controller, or prefer to load the
+          tables on userspace, you should disable it.
+
+          The ir-keytable program, available at v4l-utils package
+          provide the tool and the same RC maps for load from
+          userspace. Its available at
+                       http://git.linuxtv.org/v4l-utils
diff --git a/drivers/media/IR/keymaps/Makefile b/drivers/media/IR/keymaps/Makefile
new file mode 100644 (file)
index 0000000..ec25258
--- /dev/null
@@ -0,0 +1,67 @@
+obj-$(CONFIG_RC_MAP) += rc-adstech-dvb-t-pci.o \
+                       rc-apac-viewcomp.o \
+                       rc-asus-pc39.o \
+                       rc-ati-tv-wonder-hd-600.o \
+                       rc-avermedia-a16d.o \
+                       rc-avermedia.o \
+                       rc-avermedia-cardbus.o \
+                       rc-avermedia-dvbt.o \
+                       rc-avermedia-m135a-rm-jx.o \
+                       rc-avertv-303.o \
+                       rc-behold.o \
+                       rc-behold-columbus.o \
+                       rc-budget-ci-old.o \
+                       rc-cinergy-1400.o \
+                       rc-cinergy.o \
+                       rc-dm1105-nec.o \
+                       rc-dntv-live-dvb-t.o \
+                       rc-dntv-live-dvbt-pro.o \
+                       rc-empty.o \
+                       rc-em-terratec.o \
+                       rc-encore-enltv2.o \
+                       rc-encore-enltv.o \
+                       rc-encore-enltv-fm53.o \
+                       rc-evga-indtube.o \
+                       rc-eztv.o \
+                       rc-flydvb.o \
+                       rc-flyvideo.o \
+                       rc-fusionhdtv-mce.o \
+                       rc-gadmei-rm008z.o \
+                       rc-genius-tvgo-a11mce.o \
+                       rc-gotview7135.o \
+                       rc-hauppauge-new.o \
+                       rc-imon-mce.o \
+                       rc-imon-pad.o \
+                       rc-iodata-bctv7e.o \
+                       rc-kaiomy.o \
+                       rc-kworld-315u.o \
+                       rc-kworld-plus-tv-analog.o \
+                       rc-manli.o \
+                       rc-msi-tvanywhere.o \
+                       rc-msi-tvanywhere-plus.o \
+                       rc-nebula.o \
+                       rc-nec-terratec-cinergy-xs.o \
+                       rc-norwood.o \
+                       rc-npgtech.o \
+                       rc-pctv-sedna.o \
+                       rc-pinnacle-color.o \
+                       rc-pinnacle-grey.o \
+                       rc-pinnacle-pctv-hd.o \
+                       rc-pixelview.o \
+                       rc-pixelview-mk12.o \
+                       rc-pixelview-new.o \
+                       rc-powercolor-real-angel.o \
+                       rc-proteus-2309.o \
+                       rc-purpletv.o \
+                       rc-pv951.o \
+                       rc-rc5-hauppauge-new.o \
+                       rc-rc5-tv.o \
+                       rc-real-audio-220-32-keys.o \
+                       rc-tbs-nec.o \
+                       rc-terratec-cinergy-xs.o \
+                       rc-tevii-nec.o \
+                       rc-tt-1500.o \
+                       rc-videomate-s350.o \
+                       rc-videomate-tv-pvr.o \
+                       rc-winfast.o \
+                       rc-winfast-usbii-deluxe.o
diff --git a/drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c b/drivers/media/IR/keymaps/rc-adstech-dvb-t-pci.c
new file mode 100644 (file)
index 0000000..b172831
--- /dev/null
@@ -0,0 +1,89 @@
+/* adstech-dvb-t-pci.h - Keytable for adstech_dvb_t_pci Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* ADS Tech Instant TV DVB-T PCI Remote */
+
+static struct ir_scancode adstech_dvb_t_pci[] = {
+       /* Keys 0 to 9 */
+       { 0x4d, KEY_0 },
+       { 0x57, KEY_1 },
+       { 0x4f, KEY_2 },
+       { 0x53, KEY_3 },
+       { 0x56, KEY_4 },
+       { 0x4e, KEY_5 },
+       { 0x5e, KEY_6 },
+       { 0x54, KEY_7 },
+       { 0x4c, KEY_8 },
+       { 0x5c, KEY_9 },
+
+       { 0x5b, KEY_POWER },
+       { 0x5f, KEY_MUTE },
+       { 0x55, KEY_GOTO },
+       { 0x5d, KEY_SEARCH },
+       { 0x17, KEY_EPG },              /* Guide */
+       { 0x1f, KEY_MENU },
+       { 0x0f, KEY_UP },
+       { 0x46, KEY_DOWN },
+       { 0x16, KEY_LEFT },
+       { 0x1e, KEY_RIGHT },
+       { 0x0e, KEY_SELECT },           /* Enter */
+       { 0x5a, KEY_INFO },
+       { 0x52, KEY_EXIT },
+       { 0x59, KEY_PREVIOUS },
+       { 0x51, KEY_NEXT },
+       { 0x58, KEY_REWIND },
+       { 0x50, KEY_FORWARD },
+       { 0x44, KEY_PLAYPAUSE },
+       { 0x07, KEY_STOP },
+       { 0x1b, KEY_RECORD },
+       { 0x13, KEY_TUNER },            /* Live */
+       { 0x0a, KEY_A },
+       { 0x12, KEY_B },
+       { 0x03, KEY_PROG1 },            /* 1 */
+       { 0x01, KEY_PROG2 },            /* 2 */
+       { 0x00, KEY_PROG3 },            /* 3 */
+       { 0x06, KEY_DVD },
+       { 0x48, KEY_AUX },              /* Photo */
+       { 0x40, KEY_VIDEO },
+       { 0x19, KEY_AUDIO },            /* Music */
+       { 0x0b, KEY_CHANNELUP },
+       { 0x08, KEY_CHANNELDOWN },
+       { 0x15, KEY_VOLUMEUP },
+       { 0x1c, KEY_VOLUMEDOWN },
+};
+
+static struct rc_keymap adstech_dvb_t_pci_map = {
+       .map = {
+               .scan    = adstech_dvb_t_pci,
+               .size    = ARRAY_SIZE(adstech_dvb_t_pci),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ADSTECH_DVB_T_PCI,
+       }
+};
+
+static int __init init_rc_map_adstech_dvb_t_pci(void)
+{
+       return ir_register_map(&adstech_dvb_t_pci_map);
+}
+
+static void __exit exit_rc_map_adstech_dvb_t_pci(void)
+{
+       ir_unregister_map(&adstech_dvb_t_pci_map);
+}
+
+module_init(init_rc_map_adstech_dvb_t_pci)
+module_exit(exit_rc_map_adstech_dvb_t_pci)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-apac-viewcomp.c b/drivers/media/IR/keymaps/rc-apac-viewcomp.c
new file mode 100644 (file)
index 0000000..0ef2b56
--- /dev/null
@@ -0,0 +1,80 @@
+/* apac-viewcomp.h - Keytable for apac_viewcomp Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Attila Kondoros <attila.kondoros@chello.hu> */
+
+static struct ir_scancode apac_viewcomp[] = {
+
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+       { 0x00, KEY_0 },
+       { 0x17, KEY_LAST },             /* +100 */
+       { 0x0a, KEY_LIST },             /* recall */
+
+
+       { 0x1c, KEY_TUNER },            /* TV/FM */
+       { 0x15, KEY_SEARCH },           /* scan */
+       { 0x12, KEY_POWER },            /* power */
+       { 0x1f, KEY_VOLUMEDOWN },       /* vol up */
+       { 0x1b, KEY_VOLUMEUP },         /* vol down */
+       { 0x1e, KEY_CHANNELDOWN },      /* chn up */
+       { 0x1a, KEY_CHANNELUP },        /* chn down */
+
+       { 0x11, KEY_VIDEO },            /* video */
+       { 0x0f, KEY_ZOOM },             /* full screen */
+       { 0x13, KEY_MUTE },             /* mute/unmute */
+       { 0x10, KEY_TEXT },             /* min */
+
+       { 0x0d, KEY_STOP },             /* freeze */
+       { 0x0e, KEY_RECORD },           /* record */
+       { 0x1d, KEY_PLAYPAUSE },        /* stop */
+       { 0x19, KEY_PLAY },             /* play */
+
+       { 0x16, KEY_GOTO },             /* osd */
+       { 0x14, KEY_REFRESH },          /* default */
+       { 0x0c, KEY_KPPLUS },           /* fine tune >>>> */
+       { 0x18, KEY_KPMINUS },          /* fine tune <<<< */
+};
+
+static struct rc_keymap apac_viewcomp_map = {
+       .map = {
+               .scan    = apac_viewcomp,
+               .size    = ARRAY_SIZE(apac_viewcomp),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_APAC_VIEWCOMP,
+       }
+};
+
+static int __init init_rc_map_apac_viewcomp(void)
+{
+       return ir_register_map(&apac_viewcomp_map);
+}
+
+static void __exit exit_rc_map_apac_viewcomp(void)
+{
+       ir_unregister_map(&apac_viewcomp_map);
+}
+
+module_init(init_rc_map_apac_viewcomp)
+module_exit(exit_rc_map_apac_viewcomp)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-asus-pc39.c b/drivers/media/IR/keymaps/rc-asus-pc39.c
new file mode 100644 (file)
index 0000000..2aa068c
--- /dev/null
@@ -0,0 +1,91 @@
+/* asus-pc39.h - Keytable for asus_pc39 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Marc Fargas <telenieko@telenieko.com>
+ * this is the remote control that comes with the asus p7131
+ * which has a label saying is "Model PC-39"
+ */
+
+static struct ir_scancode asus_pc39[] = {
+       /* Keys 0 to 9 */
+       { 0x15, KEY_0 },
+       { 0x29, KEY_1 },
+       { 0x2d, KEY_2 },
+       { 0x2b, KEY_3 },
+       { 0x09, KEY_4 },
+       { 0x0d, KEY_5 },
+       { 0x0b, KEY_6 },
+       { 0x31, KEY_7 },
+       { 0x35, KEY_8 },
+       { 0x33, KEY_9 },
+
+       { 0x3e, KEY_RADIO },            /* radio */
+       { 0x03, KEY_MENU },             /* dvd/menu */
+       { 0x2a, KEY_VOLUMEUP },
+       { 0x19, KEY_VOLUMEDOWN },
+       { 0x37, KEY_UP },
+       { 0x3b, KEY_DOWN },
+       { 0x27, KEY_LEFT },
+       { 0x2f, KEY_RIGHT },
+       { 0x25, KEY_VIDEO },            /* video */
+       { 0x39, KEY_AUDIO },            /* music */
+
+       { 0x21, KEY_TV },               /* tv */
+       { 0x1d, KEY_EXIT },             /* back */
+       { 0x0a, KEY_CHANNELUP },        /* channel / program + */
+       { 0x1b, KEY_CHANNELDOWN },      /* channel / program - */
+       { 0x1a, KEY_ENTER },            /* enter */
+
+       { 0x06, KEY_PAUSE },            /* play/pause */
+       { 0x1e, KEY_PREVIOUS },         /* rew */
+       { 0x26, KEY_NEXT },             /* forward */
+       { 0x0e, KEY_REWIND },           /* backward << */
+       { 0x3a, KEY_FASTFORWARD },      /* forward >> */
+       { 0x36, KEY_STOP },
+       { 0x2e, KEY_RECORD },           /* recording */
+       { 0x16, KEY_POWER },            /* the button that reads "close" */
+
+       { 0x11, KEY_ZOOM },             /* full screen */
+       { 0x13, KEY_MACRO },            /* recall */
+       { 0x23, KEY_HOME },             /* home */
+       { 0x05, KEY_PVR },              /* picture */
+       { 0x3d, KEY_MUTE },             /* mute */
+       { 0x01, KEY_DVD },              /* dvd */
+};
+
+static struct rc_keymap asus_pc39_map = {
+       .map = {
+               .scan    = asus_pc39,
+               .size    = ARRAY_SIZE(asus_pc39),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ASUS_PC39,
+       }
+};
+
+static int __init init_rc_map_asus_pc39(void)
+{
+       return ir_register_map(&asus_pc39_map);
+}
+
+static void __exit exit_rc_map_asus_pc39(void)
+{
+       ir_unregister_map(&asus_pc39_map);
+}
+
+module_init(init_rc_map_asus_pc39)
+module_exit(exit_rc_map_asus_pc39)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c b/drivers/media/IR/keymaps/rc-ati-tv-wonder-hd-600.c
new file mode 100644 (file)
index 0000000..8edfd29
--- /dev/null
@@ -0,0 +1,69 @@
+/* ati-tv-wonder-hd-600.h - Keytable for ati_tv_wonder_hd_600 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* ATI TV Wonder HD 600 USB
+   Devin Heitmueller <devin.heitmueller@gmail.com>
+ */
+
+static struct ir_scancode ati_tv_wonder_hd_600[] = {
+       { 0x00, KEY_RECORD},            /* Row 1 */
+       { 0x01, KEY_PLAYPAUSE},
+       { 0x02, KEY_STOP},
+       { 0x03, KEY_POWER},
+       { 0x04, KEY_PREVIOUS},  /* Row 2 */
+       { 0x05, KEY_REWIND},
+       { 0x06, KEY_FORWARD},
+       { 0x07, KEY_NEXT},
+       { 0x08, KEY_EPG},               /* Row 3 */
+       { 0x09, KEY_HOME},
+       { 0x0a, KEY_MENU},
+       { 0x0b, KEY_CHANNELUP},
+       { 0x0c, KEY_BACK},              /* Row 4 */
+       { 0x0d, KEY_UP},
+       { 0x0e, KEY_INFO},
+       { 0x0f, KEY_CHANNELDOWN},
+       { 0x10, KEY_LEFT},              /* Row 5 */
+       { 0x11, KEY_SELECT},
+       { 0x12, KEY_RIGHT},
+       { 0x13, KEY_VOLUMEUP},
+       { 0x14, KEY_LAST},              /* Row 6 */
+       { 0x15, KEY_DOWN},
+       { 0x16, KEY_MUTE},
+       { 0x17, KEY_VOLUMEDOWN},
+};
+
+static struct rc_keymap ati_tv_wonder_hd_600_map = {
+       .map = {
+               .scan    = ati_tv_wonder_hd_600,
+               .size    = ARRAY_SIZE(ati_tv_wonder_hd_600),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ATI_TV_WONDER_HD_600,
+       }
+};
+
+static int __init init_rc_map_ati_tv_wonder_hd_600(void)
+{
+       return ir_register_map(&ati_tv_wonder_hd_600_map);
+}
+
+static void __exit exit_rc_map_ati_tv_wonder_hd_600(void)
+{
+       ir_unregister_map(&ati_tv_wonder_hd_600_map);
+}
+
+module_init(init_rc_map_ati_tv_wonder_hd_600)
+module_exit(exit_rc_map_ati_tv_wonder_hd_600)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avermedia-a16d.c b/drivers/media/IR/keymaps/rc-avermedia-a16d.c
new file mode 100644 (file)
index 0000000..12f0435
--- /dev/null
@@ -0,0 +1,75 @@
+/* avermedia-a16d.h - Keytable for avermedia_a16d Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode avermedia_a16d[] = {
+       { 0x20, KEY_LIST},
+       { 0x00, KEY_POWER},
+       { 0x28, KEY_1},
+       { 0x18, KEY_2},
+       { 0x38, KEY_3},
+       { 0x24, KEY_4},
+       { 0x14, KEY_5},
+       { 0x34, KEY_6},
+       { 0x2c, KEY_7},
+       { 0x1c, KEY_8},
+       { 0x3c, KEY_9},
+       { 0x12, KEY_SUBTITLE},
+       { 0x22, KEY_0},
+       { 0x32, KEY_REWIND},
+       { 0x3a, KEY_SHUFFLE},
+       { 0x02, KEY_PRINT},
+       { 0x11, KEY_CHANNELDOWN},
+       { 0x31, KEY_CHANNELUP},
+       { 0x0c, KEY_ZOOM},
+       { 0x1e, KEY_VOLUMEDOWN},
+       { 0x3e, KEY_VOLUMEUP},
+       { 0x0a, KEY_MUTE},
+       { 0x04, KEY_AUDIO},
+       { 0x26, KEY_RECORD},
+       { 0x06, KEY_PLAY},
+       { 0x36, KEY_STOP},
+       { 0x16, KEY_PAUSE},
+       { 0x2e, KEY_REWIND},
+       { 0x0e, KEY_FASTFORWARD},
+       { 0x30, KEY_TEXT},
+       { 0x21, KEY_GREEN},
+       { 0x01, KEY_BLUE},
+       { 0x08, KEY_EPG},
+       { 0x2a, KEY_MENU},
+};
+
+static struct rc_keymap avermedia_a16d_map = {
+       .map = {
+               .scan    = avermedia_a16d,
+               .size    = ARRAY_SIZE(avermedia_a16d),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_AVERMEDIA_A16D,
+       }
+};
+
+static int __init init_rc_map_avermedia_a16d(void)
+{
+       return ir_register_map(&avermedia_a16d_map);
+}
+
+static void __exit exit_rc_map_avermedia_a16d(void)
+{
+       ir_unregister_map(&avermedia_a16d_map);
+}
+
+module_init(init_rc_map_avermedia_a16d)
+module_exit(exit_rc_map_avermedia_a16d)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avermedia-cardbus.c b/drivers/media/IR/keymaps/rc-avermedia-cardbus.c
new file mode 100644 (file)
index 0000000..2a945b0
--- /dev/null
@@ -0,0 +1,97 @@
+/* avermedia-cardbus.h - Keytable for avermedia_cardbus Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Oldrich Jedlicka <oldium.pro@seznam.cz> */
+
+static struct ir_scancode avermedia_cardbus[] = {
+       { 0x00, KEY_POWER },
+       { 0x01, KEY_TUNER },            /* TV/FM */
+       { 0x03, KEY_TEXT },             /* Teletext */
+       { 0x04, KEY_EPG },
+       { 0x05, KEY_1 },
+       { 0x06, KEY_2 },
+       { 0x07, KEY_3 },
+       { 0x08, KEY_AUDIO },
+       { 0x09, KEY_4 },
+       { 0x0a, KEY_5 },
+       { 0x0b, KEY_6 },
+       { 0x0c, KEY_ZOOM },             /* Full screen */
+       { 0x0d, KEY_7 },
+       { 0x0e, KEY_8 },
+       { 0x0f, KEY_9 },
+       { 0x10, KEY_PAGEUP },           /* 16-CH PREV */
+       { 0x11, KEY_0 },
+       { 0x12, KEY_INFO },
+       { 0x13, KEY_AGAIN },            /* CH RTN - channel return */
+       { 0x14, KEY_MUTE },
+       { 0x15, KEY_EDIT },             /* Autoscan */
+       { 0x17, KEY_SAVE },             /* Screenshot */
+       { 0x18, KEY_PLAYPAUSE },
+       { 0x19, KEY_RECORD },
+       { 0x1a, KEY_PLAY },
+       { 0x1b, KEY_STOP },
+       { 0x1c, KEY_FASTFORWARD },
+       { 0x1d, KEY_REWIND },
+       { 0x1e, KEY_VOLUMEDOWN },
+       { 0x1f, KEY_VOLUMEUP },
+       { 0x22, KEY_SLEEP },            /* Sleep */
+       { 0x23, KEY_ZOOM },             /* Aspect */
+       { 0x26, KEY_SCREEN },           /* Pos */
+       { 0x27, KEY_ANGLE },            /* Size */
+       { 0x28, KEY_SELECT },           /* Select */
+       { 0x29, KEY_BLUE },             /* Blue/Picture */
+       { 0x2a, KEY_BACKSPACE },        /* Back */
+       { 0x2b, KEY_MEDIA },            /* PIP (Picture-in-picture) */
+       { 0x2c, KEY_DOWN },
+       { 0x2e, KEY_DOT },
+       { 0x2f, KEY_TV },               /* Live TV */
+       { 0x32, KEY_LEFT },
+       { 0x33, KEY_CLEAR },            /* Clear */
+       { 0x35, KEY_RED },              /* Red/TV */
+       { 0x36, KEY_UP },
+       { 0x37, KEY_HOME },             /* Home */
+       { 0x39, KEY_GREEN },            /* Green/Video */
+       { 0x3d, KEY_YELLOW },           /* Yellow/Music */
+       { 0x3e, KEY_OK },               /* Ok */
+       { 0x3f, KEY_RIGHT },
+       { 0x40, KEY_NEXT },             /* Next */
+       { 0x41, KEY_PREVIOUS },         /* Previous */
+       { 0x42, KEY_CHANNELDOWN },      /* Channel down */
+       { 0x43, KEY_CHANNELUP },        /* Channel up */
+};
+
+static struct rc_keymap avermedia_cardbus_map = {
+       .map = {
+               .scan    = avermedia_cardbus,
+               .size    = ARRAY_SIZE(avermedia_cardbus),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_AVERMEDIA_CARDBUS,
+       }
+};
+
+static int __init init_rc_map_avermedia_cardbus(void)
+{
+       return ir_register_map(&avermedia_cardbus_map);
+}
+
+static void __exit exit_rc_map_avermedia_cardbus(void)
+{
+       ir_unregister_map(&avermedia_cardbus_map);
+}
+
+module_init(init_rc_map_avermedia_cardbus)
+module_exit(exit_rc_map_avermedia_cardbus)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avermedia-dvbt.c b/drivers/media/IR/keymaps/rc-avermedia-dvbt.c
new file mode 100644 (file)
index 0000000..39dde62
--- /dev/null
@@ -0,0 +1,78 @@
+/* avermedia-dvbt.h - Keytable for avermedia_dvbt Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Matt Jesson <dvb@jesson.eclipse.co.uk */
+
+static struct ir_scancode avermedia_dvbt[] = {
+       { 0x28, KEY_0 },                /* '0' / 'enter' */
+       { 0x22, KEY_1 },                /* '1' */
+       { 0x12, KEY_2 },                /* '2' / 'up arrow' */
+       { 0x32, KEY_3 },                /* '3' */
+       { 0x24, KEY_4 },                /* '4' / 'left arrow' */
+       { 0x14, KEY_5 },                /* '5' */
+       { 0x34, KEY_6 },                /* '6' / 'right arrow' */
+       { 0x26, KEY_7 },                /* '7' */
+       { 0x16, KEY_8 },                /* '8' / 'down arrow' */
+       { 0x36, KEY_9 },                /* '9' */
+
+       { 0x20, KEY_LIST },             /* 'source' */
+       { 0x10, KEY_TEXT },             /* 'teletext' */
+       { 0x00, KEY_POWER },            /* 'power' */
+       { 0x04, KEY_AUDIO },            /* 'audio' */
+       { 0x06, KEY_ZOOM },             /* 'full screen' */
+       { 0x18, KEY_VIDEO },            /* 'display' */
+       { 0x38, KEY_SEARCH },           /* 'loop' */
+       { 0x08, KEY_INFO },             /* 'preview' */
+       { 0x2a, KEY_REWIND },           /* 'backward <<' */
+       { 0x1a, KEY_FASTFORWARD },      /* 'forward >>' */
+       { 0x3a, KEY_RECORD },           /* 'capture' */
+       { 0x0a, KEY_MUTE },             /* 'mute' */
+       { 0x2c, KEY_RECORD },           /* 'record' */
+       { 0x1c, KEY_PAUSE },            /* 'pause' */
+       { 0x3c, KEY_STOP },             /* 'stop' */
+       { 0x0c, KEY_PLAY },             /* 'play' */
+       { 0x2e, KEY_RED },              /* 'red' */
+       { 0x01, KEY_BLUE },             /* 'blue' / 'cancel' */
+       { 0x0e, KEY_YELLOW },           /* 'yellow' / 'ok' */
+       { 0x21, KEY_GREEN },            /* 'green' */
+       { 0x11, KEY_CHANNELDOWN },      /* 'channel -' */
+       { 0x31, KEY_CHANNELUP },        /* 'channel +' */
+       { 0x1e, KEY_VOLUMEDOWN },       /* 'volume -' */
+       { 0x3e, KEY_VOLUMEUP },         /* 'volume +' */
+};
+
+static struct rc_keymap avermedia_dvbt_map = {
+       .map = {
+               .scan    = avermedia_dvbt,
+               .size    = ARRAY_SIZE(avermedia_dvbt),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_AVERMEDIA_DVBT,
+       }
+};
+
+static int __init init_rc_map_avermedia_dvbt(void)
+{
+       return ir_register_map(&avermedia_dvbt_map);
+}
+
+static void __exit exit_rc_map_avermedia_dvbt(void)
+{
+       ir_unregister_map(&avermedia_dvbt_map);
+}
+
+module_init(init_rc_map_avermedia_dvbt)
+module_exit(exit_rc_map_avermedia_dvbt)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avermedia-m135a-rm-jx.c b/drivers/media/IR/keymaps/rc-avermedia-m135a-rm-jx.c
new file mode 100644 (file)
index 0000000..101e7ea
--- /dev/null
@@ -0,0 +1,90 @@
+/* avermedia-m135a-rm-jx.h - Keytable for avermedia_m135a_rm_jx Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Avermedia M135A with IR model RM-JX
+ * The same codes exist on both Positivo (BR) and original IR
+ * Mauro Carvalho Chehab <mchehab@infradead.org>
+ */
+
+static struct ir_scancode avermedia_m135a_rm_jx[] = {
+       { 0x0200, KEY_POWER2 },
+       { 0x022e, KEY_DOT },            /* '.' */
+       { 0x0201, KEY_MODE },           /* TV/FM or SOURCE */
+
+       { 0x0205, KEY_1 },
+       { 0x0206, KEY_2 },
+       { 0x0207, KEY_3 },
+       { 0x0209, KEY_4 },
+       { 0x020a, KEY_5 },
+       { 0x020b, KEY_6 },
+       { 0x020d, KEY_7 },
+       { 0x020e, KEY_8 },
+       { 0x020f, KEY_9 },
+       { 0x0211, KEY_0 },
+
+       { 0x0213, KEY_RIGHT },          /* -> or L */
+       { 0x0212, KEY_LEFT },           /* <- or R */
+
+       { 0x0217, KEY_SLEEP },          /* Capturar Imagem or Snapshot */
+       { 0x0210, KEY_SHUFFLE },        /* Amostra or 16 chan prev */
+
+       { 0x0303, KEY_CHANNELUP },
+       { 0x0302, KEY_CHANNELDOWN },
+       { 0x021f, KEY_VOLUMEUP },
+       { 0x021e, KEY_VOLUMEDOWN },
+       { 0x020c, KEY_ENTER },          /* Full Screen */
+
+       { 0x0214, KEY_MUTE },
+       { 0x0208, KEY_AUDIO },
+
+       { 0x0203, KEY_TEXT },           /* Teletext */
+       { 0x0204, KEY_EPG },
+       { 0x022b, KEY_TV2 },            /* TV2 or PIP */
+
+       { 0x021d, KEY_RED },
+       { 0x021c, KEY_YELLOW },
+       { 0x0301, KEY_GREEN },
+       { 0x0300, KEY_BLUE },
+
+       { 0x021a, KEY_PLAYPAUSE },
+       { 0x0219, KEY_RECORD },
+       { 0x0218, KEY_PLAY },
+       { 0x021b, KEY_STOP },
+};
+
+static struct rc_keymap avermedia_m135a_rm_jx_map = {
+       .map = {
+               .scan    = avermedia_m135a_rm_jx,
+               .size    = ARRAY_SIZE(avermedia_m135a_rm_jx),
+               .ir_type = IR_TYPE_NEC,
+               .name    = RC_MAP_AVERMEDIA_M135A_RM_JX,
+       }
+};
+
+static int __init init_rc_map_avermedia_m135a_rm_jx(void)
+{
+       return ir_register_map(&avermedia_m135a_rm_jx_map);
+}
+
+static void __exit exit_rc_map_avermedia_m135a_rm_jx(void)
+{
+       ir_unregister_map(&avermedia_m135a_rm_jx_map);
+}
+
+module_init(init_rc_map_avermedia_m135a_rm_jx)
+module_exit(exit_rc_map_avermedia_m135a_rm_jx)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avermedia.c b/drivers/media/IR/keymaps/rc-avermedia.c
new file mode 100644 (file)
index 0000000..21effd5
--- /dev/null
@@ -0,0 +1,86 @@
+/* avermedia.h - Keytable for avermedia Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Alex Hermann <gaaf@gmx.net> */
+
+static struct ir_scancode avermedia[] = {
+       { 0x28, KEY_1 },
+       { 0x18, KEY_2 },
+       { 0x38, KEY_3 },
+       { 0x24, KEY_4 },
+       { 0x14, KEY_5 },
+       { 0x34, KEY_6 },
+       { 0x2c, KEY_7 },
+       { 0x1c, KEY_8 },
+       { 0x3c, KEY_9 },
+       { 0x22, KEY_0 },
+
+       { 0x20, KEY_TV },               /* TV/FM */
+       { 0x10, KEY_CD },               /* CD */
+       { 0x30, KEY_TEXT },             /* TELETEXT */
+       { 0x00, KEY_POWER },            /* POWER */
+
+       { 0x08, KEY_VIDEO },            /* VIDEO */
+       { 0x04, KEY_AUDIO },            /* AUDIO */
+       { 0x0c, KEY_ZOOM },             /* FULL SCREEN */
+
+       { 0x12, KEY_SUBTITLE },         /* DISPLAY */
+       { 0x32, KEY_REWIND },           /* LOOP */
+       { 0x02, KEY_PRINT },            /* PREVIEW */
+
+       { 0x2a, KEY_SEARCH },           /* AUTOSCAN */
+       { 0x1a, KEY_SLEEP },            /* FREEZE */
+       { 0x3a, KEY_CAMERA },           /* SNAPSHOT */
+       { 0x0a, KEY_MUTE },             /* MUTE */
+
+       { 0x26, KEY_RECORD },           /* RECORD */
+       { 0x16, KEY_PAUSE },            /* PAUSE */
+       { 0x36, KEY_STOP },             /* STOP */
+       { 0x06, KEY_PLAY },             /* PLAY */
+
+       { 0x2e, KEY_RED },              /* RED */
+       { 0x21, KEY_GREEN },            /* GREEN */
+       { 0x0e, KEY_YELLOW },           /* YELLOW */
+       { 0x01, KEY_BLUE },             /* BLUE */
+
+       { 0x1e, KEY_VOLUMEDOWN },       /* VOLUME- */
+       { 0x3e, KEY_VOLUMEUP },         /* VOLUME+ */
+       { 0x11, KEY_CHANNELDOWN },      /* CHANNEL/PAGE- */
+       { 0x31, KEY_CHANNELUP }         /* CHANNEL/PAGE+ */
+};
+
+static struct rc_keymap avermedia_map = {
+       .map = {
+               .scan    = avermedia,
+               .size    = ARRAY_SIZE(avermedia),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_AVERMEDIA,
+       }
+};
+
+static int __init init_rc_map_avermedia(void)
+{
+       return ir_register_map(&avermedia_map);
+}
+
+static void __exit exit_rc_map_avermedia(void)
+{
+       ir_unregister_map(&avermedia_map);
+}
+
+module_init(init_rc_map_avermedia)
+module_exit(exit_rc_map_avermedia)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-avertv-303.c b/drivers/media/IR/keymaps/rc-avertv-303.c
new file mode 100644 (file)
index 0000000..971c59d
--- /dev/null
@@ -0,0 +1,85 @@
+/* avertv-303.h - Keytable for avertv_303 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* AVERTV STUDIO 303 Remote */
+
+static struct ir_scancode avertv_303[] = {
+       { 0x2a, KEY_1 },
+       { 0x32, KEY_2 },
+       { 0x3a, KEY_3 },
+       { 0x4a, KEY_4 },
+       { 0x52, KEY_5 },
+       { 0x5a, KEY_6 },
+       { 0x6a, KEY_7 },
+       { 0x72, KEY_8 },
+       { 0x7a, KEY_9 },
+       { 0x0e, KEY_0 },
+
+       { 0x02, KEY_POWER },
+       { 0x22, KEY_VIDEO },
+       { 0x42, KEY_AUDIO },
+       { 0x62, KEY_ZOOM },
+       { 0x0a, KEY_TV },
+       { 0x12, KEY_CD },
+       { 0x1a, KEY_TEXT },
+
+       { 0x16, KEY_SUBTITLE },
+       { 0x1e, KEY_REWIND },
+       { 0x06, KEY_PRINT },
+
+       { 0x2e, KEY_SEARCH },
+       { 0x36, KEY_SLEEP },
+       { 0x3e, KEY_SHUFFLE },
+       { 0x26, KEY_MUTE },
+
+       { 0x4e, KEY_RECORD },
+       { 0x56, KEY_PAUSE },
+       { 0x5e, KEY_STOP },
+       { 0x46, KEY_PLAY },
+
+       { 0x6e, KEY_RED },
+       { 0x0b, KEY_GREEN },
+       { 0x66, KEY_YELLOW },
+       { 0x03, KEY_BLUE },
+
+       { 0x76, KEY_LEFT },
+       { 0x7e, KEY_RIGHT },
+       { 0x13, KEY_DOWN },
+       { 0x1b, KEY_UP },
+};
+
+static struct rc_keymap avertv_303_map = {
+       .map = {
+               .scan    = avertv_303,
+               .size    = ARRAY_SIZE(avertv_303),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_AVERTV_303,
+       }
+};
+
+static int __init init_rc_map_avertv_303(void)
+{
+       return ir_register_map(&avertv_303_map);
+}
+
+static void __exit exit_rc_map_avertv_303(void)
+{
+       ir_unregister_map(&avertv_303_map);
+}
+
+module_init(init_rc_map_avertv_303)
+module_exit(exit_rc_map_avertv_303)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-behold-columbus.c b/drivers/media/IR/keymaps/rc-behold-columbus.c
new file mode 100644 (file)
index 0000000..9f56c98
--- /dev/null
@@ -0,0 +1,108 @@
+/* behold-columbus.h - Keytable for behold_columbus Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Beholder Intl. Ltd. 2008
+ * Dmitry Belimov d.belimov@google.com
+ * Keytable is used by BeholdTV Columbus
+ * The "ascii-art picture" below (in comments, first row
+ * is the keycode in hex, and subsequent row(s) shows
+ * the button labels (several variants when appropriate)
+ * helps to descide which keycodes to assign to the buttons.
+ */
+
+static struct ir_scancode behold_columbus[] = {
+
+       /*  0x13   0x11   0x1C   0x12  *
+        *  Mute  Source  TV/FM  Power *
+        *                             */
+
+       { 0x13, KEY_MUTE },
+       { 0x11, KEY_PROPS },
+       { 0x1C, KEY_TUNER },    /* KEY_TV/KEY_RADIO     */
+       { 0x12, KEY_POWER },
+
+       /*  0x01    0x02    0x03  0x0D    *
+        *   1       2       3   Stereo   *
+        *                                *
+        *  0x04    0x05    0x06  0x19    *
+        *   4       5       6   Snapshot *
+        *                                *
+        *  0x07    0x08    0x09  0x10    *
+        *   7       8       9    Zoom    *
+        *                                */
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x0D, KEY_SETUP },      /* Setup key */
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x19, KEY_CAMERA },   /* Snapshot key */
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+       { 0x10, KEY_ZOOM },
+
+       /*  0x0A    0x00    0x0B       0x0C   *
+        * RECALL    0    ChannelUp  VolumeUp *
+        *                                    */
+       { 0x0A, KEY_AGAIN },
+       { 0x00, KEY_0 },
+       { 0x0B, KEY_CHANNELUP },
+       { 0x0C, KEY_VOLUMEUP },
+
+       /*   0x1B      0x1D      0x15        0x18     *
+        * Timeshift  Record  ChannelDown  VolumeDown *
+        *                                            */
+
+       { 0x1B, KEY_TIME },
+       { 0x1D, KEY_RECORD },
+       { 0x15, KEY_CHANNELDOWN },
+       { 0x18, KEY_VOLUMEDOWN },
+
+       /*   0x0E   0x1E     0x0F     0x1A  *
+        *   Stop   Pause  Previouse  Next  *
+        *                                  */
+
+       { 0x0E, KEY_STOP },
+       { 0x1E, KEY_PAUSE },
+       { 0x0F, KEY_PREVIOUS },
+       { 0x1A, KEY_NEXT },
+
+};
+
+static struct rc_keymap behold_columbus_map = {
+       .map = {
+               .scan    = behold_columbus,
+               .size    = ARRAY_SIZE(behold_columbus),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_BEHOLD_COLUMBUS,
+       }
+};
+
+static int __init init_rc_map_behold_columbus(void)
+{
+       return ir_register_map(&behold_columbus_map);
+}
+
+static void __exit exit_rc_map_behold_columbus(void)
+{
+       ir_unregister_map(&behold_columbus_map);
+}
+
+module_init(init_rc_map_behold_columbus)
+module_exit(exit_rc_map_behold_columbus)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-behold.c b/drivers/media/IR/keymaps/rc-behold.c
new file mode 100644 (file)
index 0000000..abc140b
--- /dev/null
@@ -0,0 +1,141 @@
+/* behold.h - Keytable for behold Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Igor Kuznetsov <igk72@ya.ru>
+ * Andrey J. Melnikov <temnota@kmv.ru>
+ *
+ * Keytable is used by BeholdTV 60x series, M6 series at
+ * least, and probably other cards too.
+ * The "ascii-art picture" below (in comments, first row
+ * is the keycode in hex, and subsequent row(s) shows
+ * the button labels (several variants when appropriate)
+ * helps to descide which keycodes to assign to the buttons.
+ */
+
+static struct ir_scancode behold[] = {
+
+       /*  0x1c            0x12  *
+        *  TV/FM          POWER  *
+        *                        */
+       { 0x1c, KEY_TUNER },    /* XXX KEY_TV / KEY_RADIO */
+       { 0x12, KEY_POWER },
+
+       /*  0x01    0x02    0x03  *
+        *   1       2       3    *
+        *                        *
+        *  0x04    0x05    0x06  *
+        *   4       5       6    *
+        *                        *
+        *  0x07    0x08    0x09  *
+        *   7       8       9    *
+        *                        */
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       /*  0x0a    0x00    0x17  *
+        * RECALL    0      MODE  *
+        *                        */
+       { 0x0a, KEY_AGAIN },
+       { 0x00, KEY_0 },
+       { 0x17, KEY_MODE },
+
+       /*  0x14          0x10    *
+        * ASPECT      FULLSCREEN *
+        *                        */
+       { 0x14, KEY_SCREEN },
+       { 0x10, KEY_ZOOM },
+
+       /*          0x0b          *
+        *           Up           *
+        *                        *
+        *  0x18    0x16    0x0c  *
+        *  Left     Ok     Right *
+        *                        *
+        *         0x015          *
+        *         Down           *
+        *                        */
+       { 0x0b, KEY_CHANNELUP },
+       { 0x18, KEY_VOLUMEDOWN },
+       { 0x16, KEY_OK },               /* XXX KEY_ENTER */
+       { 0x0c, KEY_VOLUMEUP },
+       { 0x15, KEY_CHANNELDOWN },
+
+       /*  0x11            0x0d  *
+        *  MUTE            INFO  *
+        *                        */
+       { 0x11, KEY_MUTE },
+       { 0x0d, KEY_INFO },
+
+       /*  0x0f    0x1b    0x1a  *
+        * RECORD PLAY/PAUSE STOP *
+        *                        *
+        *  0x0e    0x1f    0x1e  *
+        *TELETEXT  AUDIO  SOURCE *
+        *           RED   YELLOW *
+        *                        */
+       { 0x0f, KEY_RECORD },
+       { 0x1b, KEY_PLAYPAUSE },
+       { 0x1a, KEY_STOP },
+       { 0x0e, KEY_TEXT },
+       { 0x1f, KEY_RED },      /*XXX KEY_AUDIO */
+       { 0x1e, KEY_YELLOW },   /*XXX KEY_SOURCE        */
+
+       /*  0x1d   0x13     0x19  *
+        * SLEEP  PREVIEW   DVB   *
+        *         GREEN    BLUE  *
+        *                        */
+       { 0x1d, KEY_SLEEP },
+       { 0x13, KEY_GREEN },
+       { 0x19, KEY_BLUE },     /* XXX KEY_SAT  */
+
+       /*  0x58           0x5c   *
+        * FREEZE        SNAPSHOT *
+        *                        */
+       { 0x58, KEY_SLOW },
+       { 0x5c, KEY_CAMERA },
+
+};
+
+static struct rc_keymap behold_map = {
+       .map = {
+               .scan    = behold,
+               .size    = ARRAY_SIZE(behold),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_BEHOLD,
+       }
+};
+
+static int __init init_rc_map_behold(void)
+{
+       return ir_register_map(&behold_map);
+}
+
+static void __exit exit_rc_map_behold(void)
+{
+       ir_unregister_map(&behold_map);
+}
+
+module_init(init_rc_map_behold)
+module_exit(exit_rc_map_behold)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-budget-ci-old.c b/drivers/media/IR/keymaps/rc-budget-ci-old.c
new file mode 100644 (file)
index 0000000..64c2ac9
--- /dev/null
@@ -0,0 +1,92 @@
+/* budget-ci-old.h - Keytable for budget_ci_old Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* From reading the following remotes:
+ * Zenith Universal 7 / TV Mode 807 / VCR Mode 837
+ * Hauppauge (from NOVA-CI-s box product)
+ * This is a "middle of the road" approach, differences are noted
+ */
+
+static struct ir_scancode budget_ci_old[] = {
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+       { 0x0a, KEY_ENTER },
+       { 0x0b, KEY_RED },
+       { 0x0c, KEY_POWER },            /* RADIO on Hauppauge */
+       { 0x0d, KEY_MUTE },
+       { 0x0f, KEY_A },                /* TV on Hauppauge */
+       { 0x10, KEY_VOLUMEUP },
+       { 0x11, KEY_VOLUMEDOWN },
+       { 0x14, KEY_B },
+       { 0x1c, KEY_UP },
+       { 0x1d, KEY_DOWN },
+       { 0x1e, KEY_OPTION },           /* RESERVED on Hauppauge */
+       { 0x1f, KEY_BREAK },
+       { 0x20, KEY_CHANNELUP },
+       { 0x21, KEY_CHANNELDOWN },
+       { 0x22, KEY_PREVIOUS },         /* Prev Ch on Zenith, SOURCE on Hauppauge */
+       { 0x24, KEY_RESTART },
+       { 0x25, KEY_OK },
+       { 0x26, KEY_CYCLEWINDOWS },     /* MINIMIZE on Hauppauge */
+       { 0x28, KEY_ENTER },            /* VCR mode on Zenith */
+       { 0x29, KEY_PAUSE },
+       { 0x2b, KEY_RIGHT },
+       { 0x2c, KEY_LEFT },
+       { 0x2e, KEY_MENU },             /* FULL SCREEN on Hauppauge */
+       { 0x30, KEY_SLOW },
+       { 0x31, KEY_PREVIOUS },         /* VCR mode on Zenith */
+       { 0x32, KEY_REWIND },
+       { 0x34, KEY_FASTFORWARD },
+       { 0x35, KEY_PLAY },
+       { 0x36, KEY_STOP },
+       { 0x37, KEY_RECORD },
+       { 0x38, KEY_TUNER },            /* TV/VCR on Zenith */
+       { 0x3a, KEY_C },
+       { 0x3c, KEY_EXIT },
+       { 0x3d, KEY_POWER2 },
+       { 0x3e, KEY_TUNER },
+};
+
+static struct rc_keymap budget_ci_old_map = {
+       .map = {
+               .scan    = budget_ci_old,
+               .size    = ARRAY_SIZE(budget_ci_old),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_BUDGET_CI_OLD,
+       }
+};
+
+static int __init init_rc_map_budget_ci_old(void)
+{
+       return ir_register_map(&budget_ci_old_map);
+}
+
+static void __exit exit_rc_map_budget_ci_old(void)
+{
+       ir_unregister_map(&budget_ci_old_map);
+}
+
+module_init(init_rc_map_budget_ci_old)
+module_exit(exit_rc_map_budget_ci_old)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-cinergy-1400.c b/drivers/media/IR/keymaps/rc-cinergy-1400.c
new file mode 100644 (file)
index 0000000..074f2c2
--- /dev/null
@@ -0,0 +1,84 @@
+/* cinergy-1400.h - Keytable for cinergy_1400 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Cinergy 1400 DVB-T */
+
+static struct ir_scancode cinergy_1400[] = {
+       { 0x01, KEY_POWER },
+       { 0x02, KEY_1 },
+       { 0x03, KEY_2 },
+       { 0x04, KEY_3 },
+       { 0x05, KEY_4 },
+       { 0x06, KEY_5 },
+       { 0x07, KEY_6 },
+       { 0x08, KEY_7 },
+       { 0x09, KEY_8 },
+       { 0x0a, KEY_9 },
+       { 0x0c, KEY_0 },
+
+       { 0x0b, KEY_VIDEO },
+       { 0x0d, KEY_REFRESH },
+       { 0x0e, KEY_SELECT },
+       { 0x0f, KEY_EPG },
+       { 0x10, KEY_UP },
+       { 0x11, KEY_LEFT },
+       { 0x12, KEY_OK },
+       { 0x13, KEY_RIGHT },
+       { 0x14, KEY_DOWN },
+       { 0x15, KEY_TEXT },
+       { 0x16, KEY_INFO },
+
+       { 0x17, KEY_RED },
+       { 0x18, KEY_GREEN },
+       { 0x19, KEY_YELLOW },
+       { 0x1a, KEY_BLUE },
+
+       { 0x1b, KEY_CHANNELUP },
+       { 0x1c, KEY_VOLUMEUP },
+       { 0x1d, KEY_MUTE },
+       { 0x1e, KEY_VOLUMEDOWN },
+       { 0x1f, KEY_CHANNELDOWN },
+
+       { 0x40, KEY_PAUSE },
+       { 0x4c, KEY_PLAY },
+       { 0x58, KEY_RECORD },
+       { 0x54, KEY_PREVIOUS },
+       { 0x48, KEY_STOP },
+       { 0x5c, KEY_NEXT },
+};
+
+static struct rc_keymap cinergy_1400_map = {
+       .map = {
+               .scan    = cinergy_1400,
+               .size    = ARRAY_SIZE(cinergy_1400),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_CINERGY_1400,
+       }
+};
+
+static int __init init_rc_map_cinergy_1400(void)
+{
+       return ir_register_map(&cinergy_1400_map);
+}
+
+static void __exit exit_rc_map_cinergy_1400(void)
+{
+       ir_unregister_map(&cinergy_1400_map);
+}
+
+module_init(init_rc_map_cinergy_1400)
+module_exit(exit_rc_map_cinergy_1400)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-cinergy.c b/drivers/media/IR/keymaps/rc-cinergy.c
new file mode 100644 (file)
index 0000000..cf84c3d
--- /dev/null
@@ -0,0 +1,78 @@
+/* cinergy.h - Keytable for cinergy Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode cinergy[] = {
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0a, KEY_POWER },
+       { 0x0b, KEY_PROG1 },            /* app */
+       { 0x0c, KEY_ZOOM },             /* zoom/fullscreen */
+       { 0x0d, KEY_CHANNELUP },        /* channel */
+       { 0x0e, KEY_CHANNELDOWN },      /* channel- */
+       { 0x0f, KEY_VOLUMEUP },
+       { 0x10, KEY_VOLUMEDOWN },
+       { 0x11, KEY_TUNER },            /* AV */
+       { 0x12, KEY_NUMLOCK },          /* -/-- */
+       { 0x13, KEY_AUDIO },            /* audio */
+       { 0x14, KEY_MUTE },
+       { 0x15, KEY_UP },
+       { 0x16, KEY_DOWN },
+       { 0x17, KEY_LEFT },
+       { 0x18, KEY_RIGHT },
+       { 0x19, BTN_LEFT, },
+       { 0x1a, BTN_RIGHT, },
+       { 0x1b, KEY_WWW },              /* text */
+       { 0x1c, KEY_REWIND },
+       { 0x1d, KEY_FORWARD },
+       { 0x1e, KEY_RECORD },
+       { 0x1f, KEY_PLAY },
+       { 0x20, KEY_PREVIOUSSONG },
+       { 0x21, KEY_NEXTSONG },
+       { 0x22, KEY_PAUSE },
+       { 0x23, KEY_STOP },
+};
+
+static struct rc_keymap cinergy_map = {
+       .map = {
+               .scan    = cinergy,
+               .size    = ARRAY_SIZE(cinergy),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_CINERGY,
+       }
+};
+
+static int __init init_rc_map_cinergy(void)
+{
+       return ir_register_map(&cinergy_map);
+}
+
+static void __exit exit_rc_map_cinergy(void)
+{
+       ir_unregister_map(&cinergy_map);
+}
+
+module_init(init_rc_map_cinergy)
+module_exit(exit_rc_map_cinergy)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-dm1105-nec.c b/drivers/media/IR/keymaps/rc-dm1105-nec.c
new file mode 100644 (file)
index 0000000..90684d0
--- /dev/null
@@ -0,0 +1,76 @@
+/* dm1105-nec.h - Keytable for dm1105_nec Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* DVBWorld remotes
+   Igor M. Liplianin <liplianin@me.by>
+ */
+
+static struct ir_scancode dm1105_nec[] = {
+       { 0x0a, KEY_POWER2},            /* power */
+       { 0x0c, KEY_MUTE},              /* mute */
+       { 0x11, KEY_1},
+       { 0x12, KEY_2},
+       { 0x13, KEY_3},
+       { 0x14, KEY_4},
+       { 0x15, KEY_5},
+       { 0x16, KEY_6},
+       { 0x17, KEY_7},
+       { 0x18, KEY_8},
+       { 0x19, KEY_9},
+       { 0x10, KEY_0},
+       { 0x1c, KEY_CHANNELUP},         /* ch+ */
+       { 0x0f, KEY_CHANNELDOWN},       /* ch- */
+       { 0x1a, KEY_VOLUMEUP},          /* vol+ */
+       { 0x0e, KEY_VOLUMEDOWN},        /* vol- */
+       { 0x04, KEY_RECORD},            /* rec */
+       { 0x09, KEY_CHANNEL},           /* fav */
+       { 0x08, KEY_BACKSPACE},         /* rewind */
+       { 0x07, KEY_FASTFORWARD},       /* fast */
+       { 0x0b, KEY_PAUSE},             /* pause */
+       { 0x02, KEY_ESC},               /* cancel */
+       { 0x03, KEY_TAB},               /* tab */
+       { 0x00, KEY_UP},                /* up */
+       { 0x1f, KEY_ENTER},             /* ok */
+       { 0x01, KEY_DOWN},              /* down */
+       { 0x05, KEY_RECORD},            /* cap */
+       { 0x06, KEY_STOP},              /* stop */
+       { 0x40, KEY_ZOOM},              /* full */
+       { 0x1e, KEY_TV},                /* tvmode */
+       { 0x1b, KEY_B},                 /* recall */
+};
+
+static struct rc_keymap dm1105_nec_map = {
+       .map = {
+               .scan    = dm1105_nec,
+               .size    = ARRAY_SIZE(dm1105_nec),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_DM1105_NEC,
+       }
+};
+
+static int __init init_rc_map_dm1105_nec(void)
+{
+       return ir_register_map(&dm1105_nec_map);
+}
+
+static void __exit exit_rc_map_dm1105_nec(void)
+{
+       ir_unregister_map(&dm1105_nec_map);
+}
+
+module_init(init_rc_map_dm1105_nec)
+module_exit(exit_rc_map_dm1105_nec)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c b/drivers/media/IR/keymaps/rc-dntv-live-dvb-t.c
new file mode 100644 (file)
index 0000000..8a4027a
--- /dev/null
@@ -0,0 +1,78 @@
+/* dntv-live-dvb-t.h - Keytable for dntv_live_dvb_t Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* DigitalNow DNTV Live DVB-T Remote */
+
+static struct ir_scancode dntv_live_dvb_t[] = {
+       { 0x00, KEY_ESC },              /* 'go up a level?' */
+       /* Keys 0 to 9 */
+       { 0x0a, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0b, KEY_TUNER },            /* tv/fm */
+       { 0x0c, KEY_SEARCH },           /* scan */
+       { 0x0d, KEY_STOP },
+       { 0x0e, KEY_PAUSE },
+       { 0x0f, KEY_LIST },             /* source */
+
+       { 0x10, KEY_MUTE },
+       { 0x11, KEY_REWIND },           /* backward << */
+       { 0x12, KEY_POWER },
+       { 0x13, KEY_CAMERA },           /* snap */
+       { 0x14, KEY_AUDIO },            /* stereo */
+       { 0x15, KEY_CLEAR },            /* reset */
+       { 0x16, KEY_PLAY },
+       { 0x17, KEY_ENTER },
+       { 0x18, KEY_ZOOM },             /* full screen */
+       { 0x19, KEY_FASTFORWARD },      /* forward >> */
+       { 0x1a, KEY_CHANNELUP },
+       { 0x1b, KEY_VOLUMEUP },
+       { 0x1c, KEY_INFO },             /* preview */
+       { 0x1d, KEY_RECORD },           /* record */
+       { 0x1e, KEY_CHANNELDOWN },
+       { 0x1f, KEY_VOLUMEDOWN },
+};
+
+static struct rc_keymap dntv_live_dvb_t_map = {
+       .map = {
+               .scan    = dntv_live_dvb_t,
+               .size    = ARRAY_SIZE(dntv_live_dvb_t),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_DNTV_LIVE_DVB_T,
+       }
+};
+
+static int __init init_rc_map_dntv_live_dvb_t(void)
+{
+       return ir_register_map(&dntv_live_dvb_t_map);
+}
+
+static void __exit exit_rc_map_dntv_live_dvb_t(void)
+{
+       ir_unregister_map(&dntv_live_dvb_t_map);
+}
+
+module_init(init_rc_map_dntv_live_dvb_t)
+module_exit(exit_rc_map_dntv_live_dvb_t)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c b/drivers/media/IR/keymaps/rc-dntv-live-dvbt-pro.c
new file mode 100644 (file)
index 0000000..6f4d607
--- /dev/null
@@ -0,0 +1,97 @@
+/* dntv-live-dvbt-pro.h - Keytable for dntv_live_dvbt_pro Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* DigitalNow DNTV Live! DVB-T Pro Remote */
+
+static struct ir_scancode dntv_live_dvbt_pro[] = {
+       { 0x16, KEY_POWER },
+       { 0x5b, KEY_HOME },
+
+       { 0x55, KEY_TV },               /* live tv */
+       { 0x58, KEY_TUNER },            /* digital Radio */
+       { 0x5a, KEY_RADIO },            /* FM radio */
+       { 0x59, KEY_DVD },              /* dvd menu */
+       { 0x03, KEY_1 },
+       { 0x01, KEY_2 },
+       { 0x06, KEY_3 },
+       { 0x09, KEY_4 },
+       { 0x1d, KEY_5 },
+       { 0x1f, KEY_6 },
+       { 0x0d, KEY_7 },
+       { 0x19, KEY_8 },
+       { 0x1b, KEY_9 },
+       { 0x0c, KEY_CANCEL },
+       { 0x15, KEY_0 },
+       { 0x4a, KEY_CLEAR },
+       { 0x13, KEY_BACK },
+       { 0x00, KEY_TAB },
+       { 0x4b, KEY_UP },
+       { 0x4e, KEY_LEFT },
+       { 0x4f, KEY_OK },
+       { 0x52, KEY_RIGHT },
+       { 0x51, KEY_DOWN },
+       { 0x1e, KEY_VOLUMEUP },
+       { 0x0a, KEY_VOLUMEDOWN },
+       { 0x02, KEY_CHANNELDOWN },
+       { 0x05, KEY_CHANNELUP },
+       { 0x11, KEY_RECORD },
+       { 0x14, KEY_PLAY },
+       { 0x4c, KEY_PAUSE },
+       { 0x1a, KEY_STOP },
+       { 0x40, KEY_REWIND },
+       { 0x12, KEY_FASTFORWARD },
+       { 0x41, KEY_PREVIOUSSONG },     /* replay |< */
+       { 0x42, KEY_NEXTSONG },         /* skip >| */
+       { 0x54, KEY_CAMERA },           /* capture */
+       { 0x50, KEY_LANGUAGE },         /* sap */
+       { 0x47, KEY_TV2 },              /* pip */
+       { 0x4d, KEY_SCREEN },
+       { 0x43, KEY_SUBTITLE },
+       { 0x10, KEY_MUTE },
+       { 0x49, KEY_AUDIO },            /* l/r */
+       { 0x07, KEY_SLEEP },
+       { 0x08, KEY_VIDEO },            /* a/v */
+       { 0x0e, KEY_PREVIOUS },         /* recall */
+       { 0x45, KEY_ZOOM },             /* zoom + */
+       { 0x46, KEY_ANGLE },            /* zoom - */
+       { 0x56, KEY_RED },
+       { 0x57, KEY_GREEN },
+       { 0x5c, KEY_YELLOW },
+       { 0x5d, KEY_BLUE },
+};
+
+static struct rc_keymap dntv_live_dvbt_pro_map = {
+       .map = {
+               .scan    = dntv_live_dvbt_pro,
+               .size    = ARRAY_SIZE(dntv_live_dvbt_pro),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_DNTV_LIVE_DVBT_PRO,
+       }
+};
+
+static int __init init_rc_map_dntv_live_dvbt_pro(void)
+{
+       return ir_register_map(&dntv_live_dvbt_pro_map);
+}
+
+static void __exit exit_rc_map_dntv_live_dvbt_pro(void)
+{
+       ir_unregister_map(&dntv_live_dvbt_pro_map);
+}
+
+module_init(init_rc_map_dntv_live_dvbt_pro)
+module_exit(exit_rc_map_dntv_live_dvbt_pro)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-em-terratec.c b/drivers/media/IR/keymaps/rc-em-terratec.c
new file mode 100644 (file)
index 0000000..3130c9c
--- /dev/null
@@ -0,0 +1,69 @@
+/* em-terratec.h - Keytable for em_terratec Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode em_terratec[] = {
+       { 0x01, KEY_CHANNEL },
+       { 0x02, KEY_SELECT },
+       { 0x03, KEY_MUTE },
+       { 0x04, KEY_POWER },
+       { 0x05, KEY_1 },
+       { 0x06, KEY_2 },
+       { 0x07, KEY_3 },
+       { 0x08, KEY_CHANNELUP },
+       { 0x09, KEY_4 },
+       { 0x0a, KEY_5 },
+       { 0x0b, KEY_6 },
+       { 0x0c, KEY_CHANNELDOWN },
+       { 0x0d, KEY_7 },
+       { 0x0e, KEY_8 },
+       { 0x0f, KEY_9 },
+       { 0x10, KEY_VOLUMEUP },
+       { 0x11, KEY_0 },
+       { 0x12, KEY_MENU },
+       { 0x13, KEY_PRINT },
+       { 0x14, KEY_VOLUMEDOWN },
+       { 0x16, KEY_PAUSE },
+       { 0x18, KEY_RECORD },
+       { 0x19, KEY_REWIND },
+       { 0x1a, KEY_PLAY },
+       { 0x1b, KEY_FORWARD },
+       { 0x1c, KEY_BACKSPACE },
+       { 0x1e, KEY_STOP },
+       { 0x40, KEY_ZOOM },
+};
+
+static struct rc_keymap em_terratec_map = {
+       .map = {
+               .scan    = em_terratec,
+               .size    = ARRAY_SIZE(em_terratec),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_EM_TERRATEC,
+       }
+};
+
+static int __init init_rc_map_em_terratec(void)
+{
+       return ir_register_map(&em_terratec_map);
+}
+
+static void __exit exit_rc_map_em_terratec(void)
+{
+       ir_unregister_map(&em_terratec_map);
+}
+
+module_init(init_rc_map_em_terratec)
+module_exit(exit_rc_map_em_terratec)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-empty.c b/drivers/media/IR/keymaps/rc-empty.c
new file mode 100644 (file)
index 0000000..3b338d8
--- /dev/null
@@ -0,0 +1,44 @@
+/* empty.h - Keytable for empty Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* empty keytable, can be used as placeholder for not-yet created keytables */
+
+static struct ir_scancode empty[] = {
+       { 0x2a, KEY_COFFEE },
+};
+
+static struct rc_keymap empty_map = {
+       .map = {
+               .scan    = empty,
+               .size    = ARRAY_SIZE(empty),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_EMPTY,
+       }
+};
+
+static int __init init_rc_map_empty(void)
+{
+       return ir_register_map(&empty_map);
+}
+
+static void __exit exit_rc_map_empty(void)
+{
+       ir_unregister_map(&empty_map);
+}
+
+module_init(init_rc_map_empty)
+module_exit(exit_rc_map_empty)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv-fm53.c b/drivers/media/IR/keymaps/rc-encore-enltv-fm53.c
new file mode 100644 (file)
index 0000000..4b81696
--- /dev/null
@@ -0,0 +1,81 @@
+/* encore-enltv-fm53.h - Keytable for encore_enltv_fm53 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Encore ENLTV-FM v5.3
+   Mauro Carvalho Chehab <mchehab@infradead.org>
+ */
+
+static struct ir_scancode encore_enltv_fm53[] = {
+       { 0x10, KEY_POWER2},
+       { 0x06, KEY_MUTE},
+
+       { 0x09, KEY_1},
+       { 0x1d, KEY_2},
+       { 0x1f, KEY_3},
+       { 0x19, KEY_4},
+       { 0x1b, KEY_5},
+       { 0x11, KEY_6},
+       { 0x17, KEY_7},
+       { 0x12, KEY_8},
+       { 0x16, KEY_9},
+       { 0x48, KEY_0},
+
+       { 0x04, KEY_LIST},              /* -/-- */
+       { 0x40, KEY_LAST},              /* recall */
+
+       { 0x02, KEY_MODE},              /* TV/AV */
+       { 0x05, KEY_CAMERA},            /* SNAPSHOT */
+
+       { 0x4c, KEY_CHANNELUP},         /* UP */
+       { 0x00, KEY_CHANNELDOWN},       /* DOWN */
+       { 0x0d, KEY_VOLUMEUP},          /* RIGHT */
+       { 0x15, KEY_VOLUMEDOWN},        /* LEFT */
+       { 0x49, KEY_ENTER},             /* OK */
+
+       { 0x54, KEY_RECORD},
+       { 0x4d, KEY_PLAY},              /* pause */
+
+       { 0x1e, KEY_MENU},              /* video setting */
+       { 0x0e, KEY_RIGHT},             /* <- */
+       { 0x1a, KEY_LEFT},              /* -> */
+
+       { 0x0a, KEY_CLEAR},             /* video default */
+       { 0x0c, KEY_ZOOM},              /* hide pannel */
+       { 0x47, KEY_SLEEP},             /* shutdown */
+};
+
+static struct rc_keymap encore_enltv_fm53_map = {
+       .map = {
+               .scan    = encore_enltv_fm53,
+               .size    = ARRAY_SIZE(encore_enltv_fm53),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ENCORE_ENLTV_FM53,
+       }
+};
+
+static int __init init_rc_map_encore_enltv_fm53(void)
+{
+       return ir_register_map(&encore_enltv_fm53_map);
+}
+
+static void __exit exit_rc_map_encore_enltv_fm53(void)
+{
+       ir_unregister_map(&encore_enltv_fm53_map);
+}
+
+module_init(init_rc_map_encore_enltv_fm53)
+module_exit(exit_rc_map_encore_enltv_fm53)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv.c b/drivers/media/IR/keymaps/rc-encore-enltv.c
new file mode 100644 (file)
index 0000000..9fabffd
--- /dev/null
@@ -0,0 +1,112 @@
+/* encore-enltv.h - Keytable for encore_enltv Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Encore ENLTV-FM  - black plastic, white front cover with white glowing buttons
+    Juan Pablo Sormani <sorman@gmail.com> */
+
+static struct ir_scancode encore_enltv[] = {
+
+       /* Power button does nothing, neither in Windows app,
+        although it sends data (used for BIOS wakeup?) */
+       { 0x0d, KEY_MUTE },
+
+       { 0x1e, KEY_TV },
+       { 0x00, KEY_VIDEO },
+       { 0x01, KEY_AUDIO },            /* music */
+       { 0x02, KEY_MHP },              /* picture */
+
+       { 0x1f, KEY_1 },
+       { 0x03, KEY_2 },
+       { 0x04, KEY_3 },
+       { 0x05, KEY_4 },
+       { 0x1c, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x1d, KEY_9 },
+       { 0x0a, KEY_0 },
+
+       { 0x09, KEY_LIST },             /* -/-- */
+       { 0x0b, KEY_LAST },             /* recall */
+
+       { 0x14, KEY_HOME },             /* win start menu */
+       { 0x15, KEY_EXIT },             /* exit */
+       { 0x16, KEY_CHANNELUP },        /* UP */
+       { 0x12, KEY_CHANNELDOWN },      /* DOWN */
+       { 0x0c, KEY_VOLUMEUP },         /* RIGHT */
+       { 0x17, KEY_VOLUMEDOWN },       /* LEFT */
+
+       { 0x18, KEY_ENTER },            /* OK */
+
+       { 0x0e, KEY_ESC },
+       { 0x13, KEY_CYCLEWINDOWS },     /* desktop */
+       { 0x11, KEY_TAB },
+       { 0x19, KEY_SWITCHVIDEOMODE },  /* switch */
+
+       { 0x1a, KEY_MENU },
+       { 0x1b, KEY_ZOOM },             /* fullscreen */
+       { 0x44, KEY_TIME },             /* time shift */
+       { 0x40, KEY_MODE },             /* source */
+
+       { 0x5a, KEY_RECORD },
+       { 0x42, KEY_PLAY },             /* play/pause */
+       { 0x45, KEY_STOP },
+       { 0x43, KEY_CAMERA },           /* camera icon */
+
+       { 0x48, KEY_REWIND },
+       { 0x4a, KEY_FASTFORWARD },
+       { 0x49, KEY_PREVIOUS },
+       { 0x4b, KEY_NEXT },
+
+       { 0x4c, KEY_FAVORITES },        /* tv wall */
+       { 0x4d, KEY_SOUND },            /* DVD sound */
+       { 0x4e, KEY_LANGUAGE },         /* DVD lang */
+       { 0x4f, KEY_TEXT },             /* DVD text */
+
+       { 0x50, KEY_SLEEP },            /* shutdown */
+       { 0x51, KEY_MODE },             /* stereo > main */
+       { 0x52, KEY_SELECT },           /* stereo > sap */
+       { 0x53, KEY_PROG1 },            /* teletext */
+
+
+       { 0x59, KEY_RED },              /* AP1 */
+       { 0x41, KEY_GREEN },            /* AP2 */
+       { 0x47, KEY_YELLOW },           /* AP3 */
+       { 0x57, KEY_BLUE },             /* AP4 */
+};
+
+static struct rc_keymap encore_enltv_map = {
+       .map = {
+               .scan    = encore_enltv,
+               .size    = ARRAY_SIZE(encore_enltv),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ENCORE_ENLTV,
+       }
+};
+
+static int __init init_rc_map_encore_enltv(void)
+{
+       return ir_register_map(&encore_enltv_map);
+}
+
+static void __exit exit_rc_map_encore_enltv(void)
+{
+       ir_unregister_map(&encore_enltv_map);
+}
+
+module_init(init_rc_map_encore_enltv)
+module_exit(exit_rc_map_encore_enltv)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-encore-enltv2.c b/drivers/media/IR/keymaps/rc-encore-enltv2.c
new file mode 100644 (file)
index 0000000..efefd51
--- /dev/null
@@ -0,0 +1,90 @@
+/* encore-enltv2.h - Keytable for encore_enltv2 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Encore ENLTV2-FM  - silver plastic - "Wand Media" written at the botton
+    Mauro Carvalho Chehab <mchehab@infradead.org> */
+
+static struct ir_scancode encore_enltv2[] = {
+       { 0x4c, KEY_POWER2 },
+       { 0x4a, KEY_TUNER },
+       { 0x40, KEY_1 },
+       { 0x60, KEY_2 },
+       { 0x50, KEY_3 },
+       { 0x70, KEY_4 },
+       { 0x48, KEY_5 },
+       { 0x68, KEY_6 },
+       { 0x58, KEY_7 },
+       { 0x78, KEY_8 },
+       { 0x44, KEY_9 },
+       { 0x54, KEY_0 },
+
+       { 0x64, KEY_LAST },             /* +100 */
+       { 0x4e, KEY_AGAIN },            /* Recall */
+
+       { 0x6c, KEY_SWITCHVIDEOMODE },  /* Video Source */
+       { 0x5e, KEY_MENU },
+       { 0x56, KEY_SCREEN },
+       { 0x7a, KEY_SETUP },
+
+       { 0x46, KEY_MUTE },
+       { 0x5c, KEY_MODE },             /* Stereo */
+       { 0x74, KEY_INFO },
+       { 0x7c, KEY_CLEAR },
+
+       { 0x55, KEY_UP },
+       { 0x49, KEY_DOWN },
+       { 0x7e, KEY_LEFT },
+       { 0x59, KEY_RIGHT },
+       { 0x6a, KEY_ENTER },
+
+       { 0x42, KEY_VOLUMEUP },
+       { 0x62, KEY_VOLUMEDOWN },
+       { 0x52, KEY_CHANNELUP },
+       { 0x72, KEY_CHANNELDOWN },
+
+       { 0x41, KEY_RECORD },
+       { 0x51, KEY_CAMERA },           /* Snapshot */
+       { 0x75, KEY_TIME },             /* Timeshift */
+       { 0x71, KEY_TV2 },              /* PIP */
+
+       { 0x45, KEY_REWIND },
+       { 0x6f, KEY_PAUSE },
+       { 0x7d, KEY_FORWARD },
+       { 0x79, KEY_STOP },
+};
+
+static struct rc_keymap encore_enltv2_map = {
+       .map = {
+               .scan    = encore_enltv2,
+               .size    = ARRAY_SIZE(encore_enltv2),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_ENCORE_ENLTV2,
+       }
+};
+
+static int __init init_rc_map_encore_enltv2(void)
+{
+       return ir_register_map(&encore_enltv2_map);
+}
+
+static void __exit exit_rc_map_encore_enltv2(void)
+{
+       ir_unregister_map(&encore_enltv2_map);
+}
+
+module_init(init_rc_map_encore_enltv2)
+module_exit(exit_rc_map_encore_enltv2)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-evga-indtube.c b/drivers/media/IR/keymaps/rc-evga-indtube.c
new file mode 100644 (file)
index 0000000..3f3fb13
--- /dev/null
@@ -0,0 +1,61 @@
+/* evga-indtube.h - Keytable for evga_indtube Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* EVGA inDtube
+   Devin Heitmueller <devin.heitmueller@gmail.com>
+ */
+
+static struct ir_scancode evga_indtube[] = {
+       { 0x12, KEY_POWER},
+       { 0x02, KEY_MODE},      /* TV */
+       { 0x14, KEY_MUTE},
+       { 0x1a, KEY_CHANNELUP},
+       { 0x16, KEY_TV2},       /* PIP */
+       { 0x1d, KEY_VOLUMEUP},
+       { 0x05, KEY_CHANNELDOWN},
+       { 0x0f, KEY_PLAYPAUSE},
+       { 0x19, KEY_VOLUMEDOWN},
+       { 0x1c, KEY_REWIND},
+       { 0x0d, KEY_RECORD},
+       { 0x18, KEY_FORWARD},
+       { 0x1e, KEY_PREVIOUS},
+       { 0x1b, KEY_STOP},
+       { 0x1f, KEY_NEXT},
+       { 0x13, KEY_CAMERA},
+};
+
+static struct rc_keymap evga_indtube_map = {
+       .map = {
+               .scan    = evga_indtube,
+               .size    = ARRAY_SIZE(evga_indtube),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_EVGA_INDTUBE,
+       }
+};
+
+static int __init init_rc_map_evga_indtube(void)
+{
+       return ir_register_map(&evga_indtube_map);
+}
+
+static void __exit exit_rc_map_evga_indtube(void)
+{
+       ir_unregister_map(&evga_indtube_map);
+}
+
+module_init(init_rc_map_evga_indtube)
+module_exit(exit_rc_map_evga_indtube)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-eztv.c b/drivers/media/IR/keymaps/rc-eztv.c
new file mode 100644 (file)
index 0000000..660907a
--- /dev/null
@@ -0,0 +1,96 @@
+/* eztv.h - Keytable for eztv Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Alfons Geser <a.geser@cox.net>
+ * updates from Job D. R. Borges <jobdrb@ig.com.br> */
+
+static struct ir_scancode eztv[] = {
+       { 0x12, KEY_POWER },
+       { 0x01, KEY_TV },       /* DVR */
+       { 0x15, KEY_DVD },      /* DVD */
+       { 0x17, KEY_AUDIO },    /* music */
+                               /* DVR mode / DVD mode / music mode */
+
+       { 0x1b, KEY_MUTE },     /* mute */
+       { 0x02, KEY_LANGUAGE }, /* MTS/SAP / audio / autoseek */
+       { 0x1e, KEY_SUBTITLE }, /* closed captioning / subtitle / seek */
+       { 0x16, KEY_ZOOM },     /* full screen */
+       { 0x1c, KEY_VIDEO },    /* video source / eject / delall */
+       { 0x1d, KEY_RESTART },  /* playback / angle / del */
+       { 0x2f, KEY_SEARCH },   /* scan / menu / playlist */
+       { 0x30, KEY_CHANNEL },  /* CH surfing / bookmark / memo */
+
+       { 0x31, KEY_HELP },     /* help */
+       { 0x32, KEY_MODE },     /* num/memo */
+       { 0x33, KEY_ESC },      /* cancel */
+
+       { 0x0c, KEY_UP },       /* up */
+       { 0x10, KEY_DOWN },     /* down */
+       { 0x08, KEY_LEFT },     /* left */
+       { 0x04, KEY_RIGHT },    /* right */
+       { 0x03, KEY_SELECT },   /* select */
+
+       { 0x1f, KEY_REWIND },   /* rewind */
+       { 0x20, KEY_PLAYPAUSE },/* play/pause */
+       { 0x29, KEY_FORWARD },  /* forward */
+       { 0x14, KEY_AGAIN },    /* repeat */
+       { 0x2b, KEY_RECORD },   /* recording */
+       { 0x2c, KEY_STOP },     /* stop */
+       { 0x2d, KEY_PLAY },     /* play */
+       { 0x2e, KEY_CAMERA },   /* snapshot / shuffle */
+
+       { 0x00, KEY_0 },
+       { 0x05, KEY_1 },
+       { 0x06, KEY_2 },
+       { 0x07, KEY_3 },
+       { 0x09, KEY_4 },
+       { 0x0a, KEY_5 },
+       { 0x0b, KEY_6 },
+       { 0x0d, KEY_7 },
+       { 0x0e, KEY_8 },
+       { 0x0f, KEY_9 },
+
+       { 0x2a, KEY_VOLUMEUP },
+       { 0x11, KEY_VOLUMEDOWN },
+       { 0x18, KEY_CHANNELUP },/* CH.tracking up */
+       { 0x19, KEY_CHANNELDOWN },/* CH.tracking down */
+
+       { 0x13, KEY_ENTER },    /* enter */
+       { 0x21, KEY_DOT },      /* . (decimal dot) */
+};
+
+static struct rc_keymap eztv_map = {
+       .map = {
+               .scan    = eztv,
+               .size    = ARRAY_SIZE(eztv),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_EZTV,
+       }
+};
+
+static int __init init_rc_map_eztv(void)
+{
+       return ir_register_map(&eztv_map);
+}
+
+static void __exit exit_rc_map_eztv(void)
+{
+       ir_unregister_map(&eztv_map);
+}
+
+module_init(init_rc_map_eztv)
+module_exit(exit_rc_map_eztv)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-flydvb.c b/drivers/media/IR/keymaps/rc-flydvb.c
new file mode 100644 (file)
index 0000000..a173c81
--- /dev/null
@@ -0,0 +1,77 @@
+/* flydvb.h - Keytable for flydvb Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode flydvb[] = {
+       { 0x01, KEY_ZOOM },             /* Full Screen */
+       { 0x00, KEY_POWER },            /* Power */
+
+       { 0x03, KEY_1 },
+       { 0x04, KEY_2 },
+       { 0x05, KEY_3 },
+       { 0x07, KEY_4 },
+       { 0x08, KEY_5 },
+       { 0x09, KEY_6 },
+       { 0x0b, KEY_7 },
+       { 0x0c, KEY_8 },
+       { 0x0d, KEY_9 },
+       { 0x06, KEY_AGAIN },            /* Recall */
+       { 0x0f, KEY_0 },
+       { 0x10, KEY_MUTE },             /* Mute */
+       { 0x02, KEY_RADIO },            /* TV/Radio */
+       { 0x1b, KEY_LANGUAGE },         /* SAP (Second Audio Program) */
+
+       { 0x14, KEY_VOLUMEUP },         /* VOL+ */
+       { 0x17, KEY_VOLUMEDOWN },       /* VOL- */
+       { 0x12, KEY_CHANNELUP },        /* CH+ */
+       { 0x13, KEY_CHANNELDOWN },      /* CH- */
+       { 0x1d, KEY_ENTER },            /* Enter */
+
+       { 0x1a, KEY_MODE },             /* PIP */
+       { 0x18, KEY_TUNER },            /* Source */
+
+       { 0x1e, KEY_RECORD },           /* Record/Pause */
+       { 0x15, KEY_ANGLE },            /* Swap (no label on key) */
+       { 0x1c, KEY_PAUSE },            /* Timeshift/Pause */
+       { 0x19, KEY_BACK },             /* Rewind << */
+       { 0x0a, KEY_PLAYPAUSE },        /* Play/Pause */
+       { 0x1f, KEY_FORWARD },          /* Forward >> */
+       { 0x16, KEY_PREVIOUS },         /* Back |<< */
+       { 0x11, KEY_STOP },             /* Stop */
+       { 0x0e, KEY_NEXT },             /* End >>| */
+};
+
+static struct rc_keymap flydvb_map = {
+       .map = {
+               .scan    = flydvb,
+               .size    = ARRAY_SIZE(flydvb),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_FLYDVB,
+       }
+};
+
+static int __init init_rc_map_flydvb(void)
+{
+       return ir_register_map(&flydvb_map);
+}
+
+static void __exit exit_rc_map_flydvb(void)
+{
+       ir_unregister_map(&flydvb_map);
+}
+
+module_init(init_rc_map_flydvb)
+module_exit(exit_rc_map_flydvb)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-flyvideo.c b/drivers/media/IR/keymaps/rc-flyvideo.c
new file mode 100644 (file)
index 0000000..9c73043
--- /dev/null
@@ -0,0 +1,70 @@
+/* flyvideo.h - Keytable for flyvideo Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode flyvideo[] = {
+       { 0x0f, KEY_0 },
+       { 0x03, KEY_1 },
+       { 0x04, KEY_2 },
+       { 0x05, KEY_3 },
+       { 0x07, KEY_4 },
+       { 0x08, KEY_5 },
+       { 0x09, KEY_6 },
+       { 0x0b, KEY_7 },
+       { 0x0c, KEY_8 },
+       { 0x0d, KEY_9 },
+
+       { 0x0e, KEY_MODE },     /* Air/Cable */
+       { 0x11, KEY_VIDEO },    /* Video */
+       { 0x15, KEY_AUDIO },    /* Audio */
+       { 0x00, KEY_POWER },    /* Power */
+       { 0x18, KEY_TUNER },    /* AV Source */
+       { 0x02, KEY_ZOOM },     /* Fullscreen */
+       { 0x1a, KEY_LANGUAGE }, /* Stereo */
+       { 0x1b, KEY_MUTE },     /* Mute */
+       { 0x14, KEY_VOLUMEUP }, /* Volume + */
+       { 0x17, KEY_VOLUMEDOWN },/* Volume - */
+       { 0x12, KEY_CHANNELUP },/* Channel + */
+       { 0x13, KEY_CHANNELDOWN },/* Channel - */
+       { 0x06, KEY_AGAIN },    /* Recall */
+       { 0x10, KEY_ENTER },    /* Enter */
+
+       { 0x19, KEY_BACK },     /* Rewind  ( <<< ) */
+       { 0x1f, KEY_FORWARD },  /* Forward ( >>> ) */
+       { 0x0a, KEY_ANGLE },    /* no label, may be used as the PAUSE button */
+};
+
+static struct rc_keymap flyvideo_map = {
+       .map = {
+               .scan    = flyvideo,
+               .size    = ARRAY_SIZE(flyvideo),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_FLYVIDEO,
+       }
+};
+
+static int __init init_rc_map_flyvideo(void)
+{
+       return ir_register_map(&flyvideo_map);
+}
+
+static void __exit exit_rc_map_flyvideo(void)
+{
+       ir_unregister_map(&flyvideo_map);
+}
+
+module_init(init_rc_map_flyvideo)
+module_exit(exit_rc_map_flyvideo)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-fusionhdtv-mce.c b/drivers/media/IR/keymaps/rc-fusionhdtv-mce.c
new file mode 100644 (file)
index 0000000..cdb1038
--- /dev/null
@@ -0,0 +1,98 @@
+/* fusionhdtv-mce.h - Keytable for fusionhdtv_mce Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* DViCO FUSION HDTV MCE remote */
+
+static struct ir_scancode fusionhdtv_mce[] = {
+
+       { 0x0b, KEY_1 },
+       { 0x17, KEY_2 },
+       { 0x1b, KEY_3 },
+       { 0x07, KEY_4 },
+       { 0x50, KEY_5 },
+       { 0x54, KEY_6 },
+       { 0x48, KEY_7 },
+       { 0x4c, KEY_8 },
+       { 0x58, KEY_9 },
+       { 0x03, KEY_0 },
+
+       { 0x5e, KEY_OK },
+       { 0x51, KEY_UP },
+       { 0x53, KEY_DOWN },
+       { 0x5b, KEY_LEFT },
+       { 0x5f, KEY_RIGHT },
+
+       { 0x02, KEY_TV },               /* Labeled DTV on remote */
+       { 0x0e, KEY_MP3 },
+       { 0x1a, KEY_DVD },
+       { 0x1e, KEY_FAVORITES },        /* Labeled CPF on remote */
+       { 0x16, KEY_SETUP },
+       { 0x46, KEY_POWER2 },           /* TV On/Off button on remote */
+       { 0x0a, KEY_EPG },              /* Labeled Guide on remote */
+
+       { 0x49, KEY_BACK },
+       { 0x59, KEY_INFO },             /* Labeled MORE on remote */
+       { 0x4d, KEY_MENU },             /* Labeled DVDMENU on remote */
+       { 0x55, KEY_CYCLEWINDOWS },     /* Labeled ALT-TAB on remote */
+
+       { 0x0f, KEY_PREVIOUSSONG },     /* Labeled |<< REPLAY on remote */
+       { 0x12, KEY_NEXTSONG },         /* Labeled >>| SKIP on remote */
+       { 0x42, KEY_ENTER },            /* Labeled START with a green
+                                          MS windows logo on remote */
+
+       { 0x15, KEY_VOLUMEUP },
+       { 0x05, KEY_VOLUMEDOWN },
+       { 0x11, KEY_CHANNELUP },
+       { 0x09, KEY_CHANNELDOWN },
+
+       { 0x52, KEY_CAMERA },
+       { 0x5a, KEY_TUNER },
+       { 0x19, KEY_OPEN },
+
+       { 0x13, KEY_MODE },             /* 4:3 16:9 select */
+       { 0x1f, KEY_ZOOM },
+
+       { 0x43, KEY_REWIND },
+       { 0x47, KEY_PLAYPAUSE },
+       { 0x4f, KEY_FASTFORWARD },
+       { 0x57, KEY_MUTE },
+       { 0x0d, KEY_STOP },
+       { 0x01, KEY_RECORD },
+       { 0x4e, KEY_POWER },
+};
+
+static struct rc_keymap fusionhdtv_mce_map = {
+       .map = {
+               .scan    = fusionhdtv_mce,
+               .size    = ARRAY_SIZE(fusionhdtv_mce),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_FUSIONHDTV_MCE,
+       }
+};
+
+static int __init init_rc_map_fusionhdtv_mce(void)
+{
+       return ir_register_map(&fusionhdtv_mce_map);
+}
+
+static void __exit exit_rc_map_fusionhdtv_mce(void)
+{
+       ir_unregister_map(&fusionhdtv_mce_map);
+}
+
+module_init(init_rc_map_fusionhdtv_mce)
+module_exit(exit_rc_map_fusionhdtv_mce)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-gadmei-rm008z.c b/drivers/media/IR/keymaps/rc-gadmei-rm008z.c
new file mode 100644 (file)
index 0000000..c16c0d1
--- /dev/null
@@ -0,0 +1,81 @@
+/* gadmei-rm008z.h - Keytable for gadmei_rm008z Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* GADMEI UTV330+ RM008Z remote
+   Shine Liu <shinel@foxmail.com>
+ */
+
+static struct ir_scancode gadmei_rm008z[] = {
+       { 0x14, KEY_POWER2},            /* POWER OFF */
+       { 0x0c, KEY_MUTE},              /* MUTE */
+
+       { 0x18, KEY_TV},                /* TV */
+       { 0x0e, KEY_VIDEO},             /* AV */
+       { 0x0b, KEY_AUDIO},             /* SV */
+       { 0x0f, KEY_RADIO},             /* FM */
+
+       { 0x00, KEY_1},
+       { 0x01, KEY_2},
+       { 0x02, KEY_3},
+       { 0x03, KEY_4},
+       { 0x04, KEY_5},
+       { 0x05, KEY_6},
+       { 0x06, KEY_7},
+       { 0x07, KEY_8},
+       { 0x08, KEY_9},
+       { 0x09, KEY_0},
+       { 0x0a, KEY_INFO},              /* OSD */
+       { 0x1c, KEY_BACKSPACE},         /* LAST */
+
+       { 0x0d, KEY_PLAY},              /* PLAY */
+       { 0x1e, KEY_CAMERA},            /* SNAPSHOT */
+       { 0x1a, KEY_RECORD},            /* RECORD */
+       { 0x17, KEY_STOP},              /* STOP */
+
+       { 0x1f, KEY_UP},                /* UP */
+       { 0x44, KEY_DOWN},              /* DOWN */
+       { 0x46, KEY_TAB},               /* BACK */
+       { 0x4a, KEY_ZOOM},              /* FULLSECREEN */
+
+       { 0x10, KEY_VOLUMEUP},          /* VOLUMEUP */
+       { 0x11, KEY_VOLUMEDOWN},        /* VOLUMEDOWN */
+       { 0x12, KEY_CHANNELUP},         /* CHANNELUP */
+       { 0x13, KEY_CHANNELDOWN},       /* CHANNELDOWN */
+       { 0x15, KEY_ENTER},             /* OK */
+};
+
+static struct rc_keymap gadmei_rm008z_map = {
+       .map = {
+               .scan    = gadmei_rm008z,
+               .size    = ARRAY_SIZE(gadmei_rm008z),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_GADMEI_RM008Z,
+       }
+};
+
+static int __init init_rc_map_gadmei_rm008z(void)
+{
+       return ir_register_map(&gadmei_rm008z_map);
+}
+
+static void __exit exit_rc_map_gadmei_rm008z(void)
+{
+       ir_unregister_map(&gadmei_rm008z_map);
+}
+
+module_init(init_rc_map_gadmei_rm008z)
+module_exit(exit_rc_map_gadmei_rm008z)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c b/drivers/media/IR/keymaps/rc-genius-tvgo-a11mce.c
new file mode 100644 (file)
index 0000000..89f8e38
--- /dev/null
@@ -0,0 +1,84 @@
+/* genius-tvgo-a11mce.h - Keytable for genius_tvgo_a11mce Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Remote control for the Genius TVGO A11MCE
+ * Adrian Pardini <pardo.bsso@gmail.com>
+ */
+
+static struct ir_scancode genius_tvgo_a11mce[] = {
+       /* Keys 0 to 9 */
+       { 0x48, KEY_0 },
+       { 0x09, KEY_1 },
+       { 0x1d, KEY_2 },
+       { 0x1f, KEY_3 },
+       { 0x19, KEY_4 },
+       { 0x1b, KEY_5 },
+       { 0x11, KEY_6 },
+       { 0x17, KEY_7 },
+       { 0x12, KEY_8 },
+       { 0x16, KEY_9 },
+
+       { 0x54, KEY_RECORD },           /* recording */
+       { 0x06, KEY_MUTE },             /* mute */
+       { 0x10, KEY_POWER },
+       { 0x40, KEY_LAST },             /* recall */
+       { 0x4c, KEY_CHANNELUP },        /* channel / program + */
+       { 0x00, KEY_CHANNELDOWN },      /* channel / program - */
+       { 0x0d, KEY_VOLUMEUP },
+       { 0x15, KEY_VOLUMEDOWN },
+       { 0x4d, KEY_OK },               /* also labeled as Pause */
+       { 0x1c, KEY_ZOOM },             /* full screen and Stop*/
+       { 0x02, KEY_MODE },             /* AV Source or Rewind*/
+       { 0x04, KEY_LIST },             /* -/-- */
+       /* small arrows above numbers */
+       { 0x1a, KEY_NEXT },             /* also Fast Forward */
+       { 0x0e, KEY_PREVIOUS },         /* also Rewind */
+       /* these are in a rather non standard layout and have
+       an alternate name written */
+       { 0x1e, KEY_UP },               /* Video Setting */
+       { 0x0a, KEY_DOWN },             /* Video Default */
+       { 0x05, KEY_CAMERA },           /* Snapshot */
+       { 0x0c, KEY_RIGHT },            /* Hide Panel */
+       /* Four buttons without label */
+       { 0x49, KEY_RED },
+       { 0x0b, KEY_GREEN },
+       { 0x13, KEY_YELLOW },
+       { 0x50, KEY_BLUE },
+};
+
+static struct rc_keymap genius_tvgo_a11mce_map = {
+       .map = {
+               .scan    = genius_tvgo_a11mce,
+               .size    = ARRAY_SIZE(genius_tvgo_a11mce),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_GENIUS_TVGO_A11MCE,
+       }
+};
+
+static int __init init_rc_map_genius_tvgo_a11mce(void)
+{
+       return ir_register_map(&genius_tvgo_a11mce_map);
+}
+
+static void __exit exit_rc_map_genius_tvgo_a11mce(void)
+{
+       ir_unregister_map(&genius_tvgo_a11mce_map);
+}
+
+module_init(init_rc_map_genius_tvgo_a11mce)
+module_exit(exit_rc_map_genius_tvgo_a11mce)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-gotview7135.c b/drivers/media/IR/keymaps/rc-gotview7135.c
new file mode 100644 (file)
index 0000000..52f025b
--- /dev/null
@@ -0,0 +1,79 @@
+/* gotview7135.h - Keytable for gotview7135 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Mike Baikov <mike@baikov.com> */
+
+static struct ir_scancode gotview7135[] = {
+
+       { 0x11, KEY_POWER },
+       { 0x35, KEY_TV },
+       { 0x1b, KEY_0 },
+       { 0x29, KEY_1 },
+       { 0x19, KEY_2 },
+       { 0x39, KEY_3 },
+       { 0x1f, KEY_4 },
+       { 0x2c, KEY_5 },
+       { 0x21, KEY_6 },
+       { 0x24, KEY_7 },
+       { 0x18, KEY_8 },
+       { 0x2b, KEY_9 },
+       { 0x3b, KEY_AGAIN },    /* LOOP */
+       { 0x06, KEY_AUDIO },
+       { 0x31, KEY_PRINT },    /* PREVIEW */
+       { 0x3e, KEY_VIDEO },
+       { 0x10, KEY_CHANNELUP },
+       { 0x20, KEY_CHANNELDOWN },
+       { 0x0c, KEY_VOLUMEDOWN },
+       { 0x28, KEY_VOLUMEUP },
+       { 0x08, KEY_MUTE },
+       { 0x26, KEY_SEARCH },   /* SCAN */
+       { 0x3f, KEY_CAMERA },   /* SNAPSHOT */
+       { 0x12, KEY_RECORD },
+       { 0x32, KEY_STOP },
+       { 0x3c, KEY_PLAY },
+       { 0x1d, KEY_REWIND },
+       { 0x2d, KEY_PAUSE },
+       { 0x0d, KEY_FORWARD },
+       { 0x05, KEY_ZOOM },     /*FULL*/
+
+       { 0x2a, KEY_F21 },      /* LIVE TIMESHIFT */
+       { 0x0e, KEY_F22 },      /* MIN TIMESHIFT */
+       { 0x1e, KEY_TIME },     /* TIMESHIFT */
+       { 0x38, KEY_F24 },      /* NORMAL TIMESHIFT */
+};
+
+static struct rc_keymap gotview7135_map = {
+       .map = {
+               .scan    = gotview7135,
+               .size    = ARRAY_SIZE(gotview7135),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_GOTVIEW7135,
+       }
+};
+
+static int __init init_rc_map_gotview7135(void)
+{
+       return ir_register_map(&gotview7135_map);
+}
+
+static void __exit exit_rc_map_gotview7135(void)
+{
+       ir_unregister_map(&gotview7135_map);
+}
+
+module_init(init_rc_map_gotview7135)
+module_exit(exit_rc_map_gotview7135)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-hauppauge-new.c b/drivers/media/IR/keymaps/rc-hauppauge-new.c
new file mode 100644 (file)
index 0000000..c6f8cd7
--- /dev/null
@@ -0,0 +1,100 @@
+/* hauppauge-new.h - Keytable for hauppauge_new Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Hauppauge: the newer, gray remotes (seems there are multiple
+ * slightly different versions), shipped with cx88+ivtv cards.
+ * almost rc5 coding, but some non-standard keys */
+
+static struct ir_scancode hauppauge_new[] = {
+       /* Keys 0 to 9 */
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0a, KEY_TEXT },             /* keypad asterisk as well */
+       { 0x0b, KEY_RED },              /* red button */
+       { 0x0c, KEY_RADIO },
+       { 0x0d, KEY_MENU },
+       { 0x0e, KEY_SUBTITLE },         /* also the # key */
+       { 0x0f, KEY_MUTE },
+       { 0x10, KEY_VOLUMEUP },
+       { 0x11, KEY_VOLUMEDOWN },
+       { 0x12, KEY_PREVIOUS },         /* previous channel */
+       { 0x14, KEY_UP },
+       { 0x15, KEY_DOWN },
+       { 0x16, KEY_LEFT },
+       { 0x17, KEY_RIGHT },
+       { 0x18, KEY_VIDEO },            /* Videos */
+       { 0x19, KEY_AUDIO },            /* Music */
+       /* 0x1a: Pictures - presume this means
+          "Multimedia Home Platform" -
+          no "PICTURES" key in input.h
+        */
+       { 0x1a, KEY_MHP },
+
+       { 0x1b, KEY_EPG },              /* Guide */
+       { 0x1c, KEY_TV },
+       { 0x1e, KEY_NEXTSONG },         /* skip >| */
+       { 0x1f, KEY_EXIT },             /* back/exit */
+       { 0x20, KEY_CHANNELUP },        /* channel / program + */
+       { 0x21, KEY_CHANNELDOWN },      /* channel / program - */
+       { 0x22, KEY_CHANNEL },          /* source (old black remote) */
+       { 0x24, KEY_PREVIOUSSONG },     /* replay |< */
+       { 0x25, KEY_ENTER },            /* OK */
+       { 0x26, KEY_SLEEP },            /* minimize (old black remote) */
+       { 0x29, KEY_BLUE },             /* blue key */
+       { 0x2e, KEY_GREEN },            /* green button */
+       { 0x30, KEY_PAUSE },            /* pause */
+       { 0x32, KEY_REWIND },           /* backward << */
+       { 0x34, KEY_FASTFORWARD },      /* forward >> */
+       { 0x35, KEY_PLAY },
+       { 0x36, KEY_STOP },
+       { 0x37, KEY_RECORD },           /* recording */
+       { 0x38, KEY_YELLOW },           /* yellow key */
+       { 0x3b, KEY_SELECT },           /* top right button */
+       { 0x3c, KEY_ZOOM },             /* full */
+       { 0x3d, KEY_POWER },            /* system power (green button) */
+};
+
+static struct rc_keymap hauppauge_new_map = {
+       .map = {
+               .scan    = hauppauge_new,
+               .size    = ARRAY_SIZE(hauppauge_new),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_HAUPPAUGE_NEW,
+       }
+};
+
+static int __init init_rc_map_hauppauge_new(void)
+{
+       return ir_register_map(&hauppauge_new_map);
+}
+
+static void __exit exit_rc_map_hauppauge_new(void)
+{
+       ir_unregister_map(&hauppauge_new_map);
+}
+
+module_init(init_rc_map_hauppauge_new)
+module_exit(exit_rc_map_hauppauge_new)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-imon-mce.c b/drivers/media/IR/keymaps/rc-imon-mce.c
new file mode 100644 (file)
index 0000000..e49f350
--- /dev/null
@@ -0,0 +1,142 @@
+/* rc5-imon-mce.c - Keytable for Windows Media Center RC-6 remotes for use
+ * with the SoundGraph iMON/Antec Veris hardware IR decoder
+ *
+ * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* mce-mode imon mce remote key table */
+static struct ir_scancode imon_mce[] = {
+       /* keys sorted mostly by frequency of use to optimize lookups */
+       { 0x800ff415, KEY_REWIND },
+       { 0x800ff414, KEY_FASTFORWARD },
+       { 0x800ff41b, KEY_PREVIOUS },
+       { 0x800ff41a, KEY_NEXT },
+
+       { 0x800ff416, KEY_PLAY },
+       { 0x800ff418, KEY_PAUSE },
+       { 0x800ff419, KEY_STOP },
+       { 0x800ff417, KEY_RECORD },
+
+       { 0x02000052, KEY_UP },
+       { 0x02000051, KEY_DOWN },
+       { 0x02000050, KEY_LEFT },
+       { 0x0200004f, KEY_RIGHT },
+
+       { 0x800ff41e, KEY_UP },
+       { 0x800ff41f, KEY_DOWN },
+       { 0x800ff420, KEY_LEFT },
+       { 0x800ff421, KEY_RIGHT },
+
+       /* 0x800ff40b also KEY_NUMERIC_POUND on some receivers */
+       { 0x800ff40b, KEY_ENTER },
+       { 0x02000028, KEY_ENTER },
+/* the OK and Enter buttons decode to the same value on some remotes
+       { 0x02000028, KEY_OK }, */
+       { 0x800ff422, KEY_OK },
+       { 0x0200002a, KEY_EXIT },
+       { 0x800ff423, KEY_EXIT },
+       { 0x02000029, KEY_DELETE },
+       /* 0x800ff40a also KEY_NUMERIC_STAR on some receivers */
+       { 0x800ff40a, KEY_DELETE },
+
+       { 0x800ff40e, KEY_MUTE },
+       { 0x800ff410, KEY_VOLUMEUP },
+       { 0x800ff411, KEY_VOLUMEDOWN },
+       { 0x800ff412, KEY_CHANNELUP },
+       { 0x800ff413, KEY_CHANNELDOWN },
+
+       { 0x0200001e, KEY_NUMERIC_1 },
+       { 0x0200001f, KEY_NUMERIC_2 },
+       { 0x02000020, KEY_NUMERIC_3 },
+       { 0x02000021, KEY_NUMERIC_4 },
+       { 0x02000022, KEY_NUMERIC_5 },
+       { 0x02000023, KEY_NUMERIC_6 },
+       { 0x02000024, KEY_NUMERIC_7 },
+       { 0x02000025, KEY_NUMERIC_8 },
+       { 0x02000026, KEY_NUMERIC_9 },
+       { 0x02000027, KEY_NUMERIC_0 },
+
+       { 0x800ff401, KEY_NUMERIC_1 },
+       { 0x800ff402, KEY_NUMERIC_2 },
+       { 0x800ff403, KEY_NUMERIC_3 },
+       { 0x800ff404, KEY_NUMERIC_4 },
+       { 0x800ff405, KEY_NUMERIC_5 },
+       { 0x800ff406, KEY_NUMERIC_6 },
+       { 0x800ff407, KEY_NUMERIC_7 },
+       { 0x800ff408, KEY_NUMERIC_8 },
+       { 0x800ff409, KEY_NUMERIC_9 },
+       { 0x800ff400, KEY_NUMERIC_0 },
+
+       { 0x02200025, KEY_NUMERIC_STAR },
+       { 0x02200020, KEY_NUMERIC_POUND },
+       /* 0x800ff41d also KEY_BLUE on some receivers */
+       { 0x800ff41d, KEY_NUMERIC_STAR },
+       /* 0x800ff41c also KEY_PREVIOUS on some receivers */
+       { 0x800ff41c, KEY_NUMERIC_POUND },
+
+       { 0x800ff446, KEY_TV },
+       { 0x800ff447, KEY_AUDIO }, /* My Music */
+       { 0x800ff448, KEY_PVR }, /* RecordedTV */
+       { 0x800ff449, KEY_CAMERA },
+       { 0x800ff44a, KEY_VIDEO },
+       /* 0x800ff424 also KEY_MENU on some receivers */
+       { 0x800ff424, KEY_DVD },
+       /* 0x800ff425 also KEY_GREEN on some receivers */
+       { 0x800ff425, KEY_TUNER }, /* LiveTV */
+       { 0x800ff450, KEY_RADIO },
+
+       { 0x800ff44c, KEY_LANGUAGE },
+       { 0x800ff427, KEY_ZOOM }, /* Aspect */
+
+       { 0x800ff45b, KEY_RED },
+       { 0x800ff45c, KEY_GREEN },
+       { 0x800ff45d, KEY_YELLOW },
+       { 0x800ff45e, KEY_BLUE },
+
+       { 0x800ff466, KEY_RED },
+       /* { 0x800ff425, KEY_GREEN }, */
+       { 0x800ff468, KEY_YELLOW },
+       /* { 0x800ff41d, KEY_BLUE }, */
+
+       { 0x800ff40f, KEY_INFO },
+       { 0x800ff426, KEY_EPG }, /* Guide */
+       { 0x800ff45a, KEY_SUBTITLE }, /* Caption/Teletext */
+       { 0x800ff44d, KEY_TITLE },
+
+       { 0x800ff40c, KEY_POWER },
+       { 0x800ff40d, KEY_PROG1 }, /* Windows MCE button */
+
+};
+
+static struct rc_keymap imon_mce_map = {
+       .map = {
+               .scan    = imon_mce,
+               .size    = ARRAY_SIZE(imon_mce),
+               /* its RC6, but w/a hardware decoder */
+               .ir_type = IR_TYPE_RC6,
+               .name    = RC_MAP_IMON_MCE,
+       }
+};
+
+static int __init init_rc_map_imon_mce(void)
+{
+       return ir_register_map(&imon_mce_map);
+}
+
+static void __exit exit_rc_map_imon_mce(void)
+{
+       ir_unregister_map(&imon_mce_map);
+}
+
+module_init(init_rc_map_imon_mce)
+module_exit(exit_rc_map_imon_mce)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-imon-pad.c b/drivers/media/IR/keymaps/rc-imon-pad.c
new file mode 100644 (file)
index 0000000..bc4db72
--- /dev/null
@@ -0,0 +1,156 @@
+/* rc5-imon-pad.c - Keytable for SoundGraph iMON PAD and Antec Veris
+ * RM-200 Remote Control
+ *
+ * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * 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, and the silkscreened names
+ * vary a bit between the SoundGraph and Antec remotes... ugh.
+ */
+static struct ir_scancode imon_pad[] = {
+       /* keys sorted mostly by frequency of use to optimize lookups */
+       { 0x2a8195b7, KEY_REWIND },
+       { 0x298315b7, KEY_REWIND },
+       { 0x2b8115b7, KEY_FASTFORWARD },
+       { 0x2b8315b7, KEY_FASTFORWARD },
+       { 0x2b9115b7, KEY_PREVIOUS },
+       { 0x298195b7, KEY_NEXT },
+
+       { 0x2a8115b7, KEY_PLAY },
+       { 0x2a8315b7, KEY_PLAY },
+       { 0x2a9115b7, KEY_PAUSE },
+       { 0x2b9715b7, KEY_STOP },
+       { 0x298115b7, KEY_RECORD },
+
+       { 0x01008000, KEY_UP },
+       { 0x01007f00, KEY_DOWN },
+       { 0x01000080, KEY_LEFT },
+       { 0x0100007f, KEY_RIGHT },
+
+       { 0x2aa515b7, KEY_UP },
+       { 0x289515b7, KEY_DOWN },
+       { 0x29a515b7, KEY_LEFT },
+       { 0x2ba515b7, KEY_RIGHT },
+
+       { 0x0200002c, KEY_SPACE }, /* Select/Space */
+       { 0x2a9315b7, KEY_SPACE }, /* Select/Space */
+       { 0x02000028, KEY_ENTER },
+       { 0x28a195b7, KEY_ENTER },
+       { 0x288195b7, KEY_EXIT },
+       { 0x02000029, KEY_ESC },
+       { 0x2bb715b7, KEY_ESC },
+       { 0x0200002a, KEY_BACKSPACE },
+       { 0x28a115b7, KEY_BACKSPACE },
+
+       { 0x2b9595b7, KEY_MUTE },
+       { 0x28a395b7, KEY_VOLUMEUP },
+       { 0x28a595b7, KEY_VOLUMEDOWN },
+       { 0x289395b7, KEY_CHANNELUP },
+       { 0x288795b7, KEY_CHANNELDOWN },
+
+       { 0x0200001e, KEY_NUMERIC_1 },
+       { 0x0200001f, KEY_NUMERIC_2 },
+       { 0x02000020, KEY_NUMERIC_3 },
+       { 0x02000021, KEY_NUMERIC_4 },
+       { 0x02000022, KEY_NUMERIC_5 },
+       { 0x02000023, KEY_NUMERIC_6 },
+       { 0x02000024, KEY_NUMERIC_7 },
+       { 0x02000025, KEY_NUMERIC_8 },
+       { 0x02000026, KEY_NUMERIC_9 },
+       { 0x02000027, KEY_NUMERIC_0 },
+
+       { 0x28b595b7, KEY_NUMERIC_1 },
+       { 0x2bb195b7, KEY_NUMERIC_2 },
+       { 0x28b195b7, KEY_NUMERIC_3 },
+       { 0x2a8595b7, KEY_NUMERIC_4 },
+       { 0x299595b7, KEY_NUMERIC_5 },
+       { 0x2aa595b7, KEY_NUMERIC_6 },
+       { 0x2b9395b7, KEY_NUMERIC_7 },
+       { 0x2a8515b7, KEY_NUMERIC_8 },
+       { 0x2aa115b7, KEY_NUMERIC_9 },
+       { 0x2ba595b7, KEY_NUMERIC_0 },
+
+       { 0x02200025, KEY_NUMERIC_STAR },
+       { 0x28b515b7, KEY_NUMERIC_STAR },
+       { 0x02200020, KEY_NUMERIC_POUND },
+       { 0x29a115b7, KEY_NUMERIC_POUND },
+
+       { 0x2b8515b7, KEY_VIDEO },
+       { 0x299195b7, KEY_AUDIO },
+       { 0x2ba115b7, KEY_CAMERA },
+       { 0x28a515b7, KEY_TV },
+       { 0x29a395b7, KEY_DVD },
+       { 0x29a295b7, KEY_DVD },
+
+       /* the Menu key between DVD and Subtitle on the RM-200... */
+       { 0x2ba385b7, KEY_MENU },
+       { 0x2ba395b7, KEY_MENU },
+
+       { 0x288515b7, KEY_BOOKMARKS },
+       { 0x2ab715b7, KEY_MEDIA }, /* Thumbnail */
+       { 0x298595b7, KEY_SUBTITLE },
+       { 0x2b8595b7, KEY_LANGUAGE },
+
+       { 0x29a595b7, KEY_ZOOM },
+       { 0x2aa395b7, KEY_SCREEN }, /* FullScreen */
+
+       { 0x299115b7, KEY_KEYBOARD },
+       { 0x299135b7, KEY_KEYBOARD },
+
+       { 0x01010000, BTN_LEFT },
+       { 0x01020000, BTN_RIGHT },
+       { 0x01010080, BTN_LEFT },
+       { 0x01020080, BTN_RIGHT },
+       { 0x688301b7, BTN_LEFT },
+       { 0x688481b7, BTN_RIGHT },
+
+       { 0x2a9395b7, KEY_CYCLEWINDOWS }, /* TaskSwitcher */
+       { 0x2b8395b7, KEY_TIME }, /* Timer */
+
+       { 0x289115b7, KEY_POWER },
+       { 0x29b195b7, KEY_EJECTCD }, /* the one next to play */
+       { 0x299395b7, KEY_EJECTCLOSECD }, /* eject (by TaskSw) */
+
+       { 0x02800000, KEY_CONTEXT_MENU }, /* Left Menu */
+       { 0x2b8195b7, KEY_CONTEXT_MENU }, /* Left Menu*/
+       { 0x02000065, KEY_COMPOSE }, /* RightMenu */
+       { 0x28b715b7, KEY_COMPOSE }, /* RightMenu */
+       { 0x2ab195b7, KEY_PROG1 }, /* Go or MultiMon */
+       { 0x29b715b7, KEY_DASHBOARD }, /* AppLauncher */
+};
+
+static struct rc_keymap imon_pad_map = {
+       .map = {
+               .scan    = imon_pad,
+               .size    = ARRAY_SIZE(imon_pad),
+               /* actual protocol details unknown, hardware decoder */
+               .ir_type = IR_TYPE_OTHER,
+               .name    = RC_MAP_IMON_PAD,
+       }
+};
+
+static int __init init_rc_map_imon_pad(void)
+{
+       return ir_register_map(&imon_pad_map);
+}
+
+static void __exit exit_rc_map_imon_pad(void)
+{
+       ir_unregister_map(&imon_pad_map);
+}
+
+module_init(init_rc_map_imon_pad)
+module_exit(exit_rc_map_imon_pad)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Jarod Wilson <jarod@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-iodata-bctv7e.c b/drivers/media/IR/keymaps/rc-iodata-bctv7e.c
new file mode 100644 (file)
index 0000000..ef66002
--- /dev/null
@@ -0,0 +1,88 @@
+/* iodata-bctv7e.h - Keytable for iodata_bctv7e Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* IO-DATA BCTV7E Remote */
+
+static struct ir_scancode iodata_bctv7e[] = {
+       { 0x40, KEY_TV },
+       { 0x20, KEY_RADIO },            /* FM */
+       { 0x60, KEY_EPG },
+       { 0x00, KEY_POWER },
+
+       /* Keys 0 to 9 */
+       { 0x44, KEY_0 },                /* 10 */
+       { 0x50, KEY_1 },
+       { 0x30, KEY_2 },
+       { 0x70, KEY_3 },
+       { 0x48, KEY_4 },
+       { 0x28, KEY_5 },
+       { 0x68, KEY_6 },
+       { 0x58, KEY_7 },
+       { 0x38, KEY_8 },
+       { 0x78, KEY_9 },
+
+       { 0x10, KEY_L },                /* Live */
+       { 0x08, KEY_TIME },             /* Time Shift */
+
+       { 0x18, KEY_PLAYPAUSE },        /* Play */
+
+       { 0x24, KEY_ENTER },            /* 11 */
+       { 0x64, KEY_ESC },              /* 12 */
+       { 0x04, KEY_M },                /* Multi */
+
+       { 0x54, KEY_VIDEO },
+       { 0x34, KEY_CHANNELUP },
+       { 0x74, KEY_VOLUMEUP },
+       { 0x14, KEY_MUTE },
+
+       { 0x4c, KEY_VCR },              /* SVIDEO */
+       { 0x2c, KEY_CHANNELDOWN },
+       { 0x6c, KEY_VOLUMEDOWN },
+       { 0x0c, KEY_ZOOM },
+
+       { 0x5c, KEY_PAUSE },
+       { 0x3c, KEY_RED },              /* || (red) */
+       { 0x7c, KEY_RECORD },           /* recording */
+       { 0x1c, KEY_STOP },
+
+       { 0x41, KEY_REWIND },           /* backward << */
+       { 0x21, KEY_PLAY },
+       { 0x61, KEY_FASTFORWARD },      /* forward >> */
+       { 0x01, KEY_NEXT },             /* skip >| */
+};
+
+static struct rc_keymap iodata_bctv7e_map = {
+       .map = {
+               .scan    = iodata_bctv7e,
+               .size    = ARRAY_SIZE(iodata_bctv7e),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_IODATA_BCTV7E,
+       }
+};
+
+static int __init init_rc_map_iodata_bctv7e(void)
+{
+       return ir_register_map(&iodata_bctv7e_map);
+}
+
+static void __exit exit_rc_map_iodata_bctv7e(void)
+{
+       ir_unregister_map(&iodata_bctv7e_map);
+}
+
+module_init(init_rc_map_iodata_bctv7e)
+module_exit(exit_rc_map_iodata_bctv7e)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-kaiomy.c b/drivers/media/IR/keymaps/rc-kaiomy.c
new file mode 100644 (file)
index 0000000..4c7883b
--- /dev/null
@@ -0,0 +1,87 @@
+/* kaiomy.h - Keytable for kaiomy Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Kaiomy TVnPC U2
+   Mauro Carvalho Chehab <mchehab@infradead.org>
+ */
+
+static struct ir_scancode kaiomy[] = {
+       { 0x43, KEY_POWER2},
+       { 0x01, KEY_LIST},
+       { 0x0b, KEY_ZOOM},
+       { 0x03, KEY_POWER},
+
+       { 0x04, KEY_1},
+       { 0x08, KEY_2},
+       { 0x02, KEY_3},
+
+       { 0x0f, KEY_4},
+       { 0x05, KEY_5},
+       { 0x06, KEY_6},
+
+       { 0x0c, KEY_7},
+       { 0x0d, KEY_8},
+       { 0x0a, KEY_9},
+
+       { 0x11, KEY_0},
+
+       { 0x09, KEY_CHANNELUP},
+       { 0x07, KEY_CHANNELDOWN},
+
+       { 0x0e, KEY_VOLUMEUP},
+       { 0x13, KEY_VOLUMEDOWN},
+
+       { 0x10, KEY_HOME},
+       { 0x12, KEY_ENTER},
+
+       { 0x14, KEY_RECORD},
+       { 0x15, KEY_STOP},
+       { 0x16, KEY_PLAY},
+       { 0x17, KEY_MUTE},
+
+       { 0x18, KEY_UP},
+       { 0x19, KEY_DOWN},
+       { 0x1a, KEY_LEFT},
+       { 0x1b, KEY_RIGHT},
+
+       { 0x1c, KEY_RED},
+       { 0x1d, KEY_GREEN},
+       { 0x1e, KEY_YELLOW},
+       { 0x1f, KEY_BLUE},
+};
+
+static struct rc_keymap kaiomy_map = {
+       .map = {
+               .scan    = kaiomy,
+               .size    = ARRAY_SIZE(kaiomy),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_KAIOMY,
+       }
+};
+
+static int __init init_rc_map_kaiomy(void)
+{
+       return ir_register_map(&kaiomy_map);
+}
+
+static void __exit exit_rc_map_kaiomy(void)
+{
+       ir_unregister_map(&kaiomy_map);
+}
+
+module_init(init_rc_map_kaiomy)
+module_exit(exit_rc_map_kaiomy)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-kworld-315u.c b/drivers/media/IR/keymaps/rc-kworld-315u.c
new file mode 100644 (file)
index 0000000..618c817
--- /dev/null
@@ -0,0 +1,83 @@
+/* kworld-315u.h - Keytable for kworld_315u Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Kworld 315U
+ */
+
+static struct ir_scancode kworld_315u[] = {
+       { 0x6143, KEY_POWER },
+       { 0x6101, KEY_TUNER },          /* source */
+       { 0x610b, KEY_ZOOM },
+       { 0x6103, KEY_POWER2 },         /* shutdown */
+
+       { 0x6104, KEY_1 },
+       { 0x6108, KEY_2 },
+       { 0x6102, KEY_3 },
+       { 0x6109, KEY_CHANNELUP },
+
+       { 0x610f, KEY_4 },
+       { 0x6105, KEY_5 },
+       { 0x6106, KEY_6 },
+       { 0x6107, KEY_CHANNELDOWN },
+
+       { 0x610c, KEY_7 },
+       { 0x610d, KEY_8 },
+       { 0x610a, KEY_9 },
+       { 0x610e, KEY_VOLUMEUP },
+
+       { 0x6110, KEY_LAST },
+       { 0x6111, KEY_0 },
+       { 0x6112, KEY_ENTER },
+       { 0x6113, KEY_VOLUMEDOWN },
+
+       { 0x6114, KEY_RECORD },
+       { 0x6115, KEY_STOP },
+       { 0x6116, KEY_PLAY },
+       { 0x6117, KEY_MUTE },
+
+       { 0x6118, KEY_UP },
+       { 0x6119, KEY_DOWN },
+       { 0x611a, KEY_LEFT },
+       { 0x611b, KEY_RIGHT },
+
+       { 0x611c, KEY_RED },
+       { 0x611d, KEY_GREEN },
+       { 0x611e, KEY_YELLOW },
+       { 0x611f, KEY_BLUE },
+};
+
+static struct rc_keymap kworld_315u_map = {
+       .map = {
+               .scan    = kworld_315u,
+               .size    = ARRAY_SIZE(kworld_315u),
+               .ir_type = IR_TYPE_NEC,
+               .name    = RC_MAP_KWORLD_315U,
+       }
+};
+
+static int __init init_rc_map_kworld_315u(void)
+{
+       return ir_register_map(&kworld_315u_map);
+}
+
+static void __exit exit_rc_map_kworld_315u(void)
+{
+       ir_unregister_map(&kworld_315u_map);
+}
+
+module_init(init_rc_map_kworld_315u)
+module_exit(exit_rc_map_kworld_315u)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c b/drivers/media/IR/keymaps/rc-kworld-plus-tv-analog.c
new file mode 100644 (file)
index 0000000..366732f
--- /dev/null
@@ -0,0 +1,99 @@
+/* kworld-plus-tv-analog.h - Keytable for kworld_plus_tv_analog Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Kworld Plus TV Analog Lite PCI IR
+   Mauro Carvalho Chehab <mchehab@infradead.org>
+ */
+
+static struct ir_scancode kworld_plus_tv_analog[] = {
+       { 0x0c, KEY_PROG1 },            /* Kworld key */
+       { 0x16, KEY_CLOSECD },          /* -> ) */
+       { 0x1d, KEY_POWER2 },
+
+       { 0x00, KEY_1 },
+       { 0x01, KEY_2 },
+       { 0x02, KEY_3 },                /* Two keys have the same code: 3 and left */
+       { 0x03, KEY_4 },                /* Two keys have the same code: 3 and right */
+       { 0x04, KEY_5 },
+       { 0x05, KEY_6 },
+       { 0x06, KEY_7 },
+       { 0x07, KEY_8 },
+       { 0x08, KEY_9 },
+       { 0x0a, KEY_0 },
+
+       { 0x09, KEY_AGAIN },
+       { 0x14, KEY_MUTE },
+
+       { 0x20, KEY_UP },
+       { 0x21, KEY_DOWN },
+       { 0x0b, KEY_ENTER },
+
+       { 0x10, KEY_CHANNELUP },
+       { 0x11, KEY_CHANNELDOWN },
+
+       /* Couldn't map key left/key right since those
+          conflict with '3' and '4' scancodes
+          I dunno what the original driver does
+        */
+
+       { 0x13, KEY_VOLUMEUP },
+       { 0x12, KEY_VOLUMEDOWN },
+
+       /* The lower part of the IR
+          There are several duplicated keycodes there.
+          Most of them conflict with digits.
+          Add mappings just to the unused scancodes.
+          Somehow, the original driver has a way to know,
+          but this doesn't seem to be on some GPIO.
+          Also, it is not related to the time between keyup
+          and keydown.
+        */
+       { 0x19, KEY_TIME},              /* Timeshift */
+       { 0x1a, KEY_STOP},
+       { 0x1b, KEY_RECORD},
+
+       { 0x22, KEY_TEXT},
+
+       { 0x15, KEY_AUDIO},             /* ((*)) */
+       { 0x0f, KEY_ZOOM},
+       { 0x1c, KEY_CAMERA},            /* snapshot */
+
+       { 0x18, KEY_RED},               /* B */
+       { 0x23, KEY_GREEN},             /* C */
+};
+
+static struct rc_keymap kworld_plus_tv_analog_map = {
+       .map = {
+               .scan    = kworld_plus_tv_analog,
+               .size    = ARRAY_SIZE(kworld_plus_tv_analog),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_KWORLD_PLUS_TV_ANALOG,
+       }
+};
+
+static int __init init_rc_map_kworld_plus_tv_analog(void)
+{
+       return ir_register_map(&kworld_plus_tv_analog_map);
+}
+
+static void __exit exit_rc_map_kworld_plus_tv_analog(void)
+{
+       ir_unregister_map(&kworld_plus_tv_analog_map);
+}
+
+module_init(init_rc_map_kworld_plus_tv_analog)
+module_exit(exit_rc_map_kworld_plus_tv_analog)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-manli.c b/drivers/media/IR/keymaps/rc-manli.c
new file mode 100644 (file)
index 0000000..1e9fbfa
--- /dev/null
@@ -0,0 +1,135 @@
+/* manli.h - Keytable for manli Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Michael Tokarev <mjt@tls.msk.ru>
+   http://www.corpit.ru/mjt/beholdTV/remote_control.jpg
+   keytable is used by MANLI MTV00[0x0c] and BeholdTV 40[13] at
+   least, and probably other cards too.
+   The "ascii-art picture" below (in comments, first row
+   is the keycode in hex, and subsequent row(s) shows
+   the button labels (several variants when appropriate)
+   helps to descide which keycodes to assign to the buttons.
+ */
+
+static struct ir_scancode manli[] = {
+
+       /*  0x1c            0x12  *
+        * FUNCTION         POWER *
+        *   FM              (|)  *
+        *                        */
+       { 0x1c, KEY_RADIO },    /*XXX*/
+       { 0x12, KEY_POWER },
+
+       /*  0x01    0x02    0x03  *
+        *   1       2       3    *
+        *                        *
+        *  0x04    0x05    0x06  *
+        *   4       5       6    *
+        *                        *
+        *  0x07    0x08    0x09  *
+        *   7       8       9    *
+        *                        */
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       /*  0x0a    0x00    0x17  *
+        * RECALL    0      +100  *
+        *                  PLUS  *
+        *                        */
+       { 0x0a, KEY_AGAIN },    /*XXX KEY_REWIND? */
+       { 0x00, KEY_0 },
+       { 0x17, KEY_DIGITS },   /*XXX*/
+
+       /*  0x14            0x10  *
+        *  MENU            INFO  *
+        *  OSD                   */
+       { 0x14, KEY_MENU },
+       { 0x10, KEY_INFO },
+
+       /*          0x0b          *
+        *           Up           *
+        *                        *
+        *  0x18    0x16    0x0c  *
+        *  Left     Ok     Right *
+        *                        *
+        *         0x015          *
+        *         Down           *
+        *                        */
+       { 0x0b, KEY_UP },
+       { 0x18, KEY_LEFT },
+       { 0x16, KEY_OK },       /*XXX KEY_SELECT? KEY_ENTER? */
+       { 0x0c, KEY_RIGHT },
+       { 0x15, KEY_DOWN },
+
+       /*  0x11            0x0d  *
+        *  TV/AV           MODE  *
+        *  SOURCE         STEREO *
+        *                        */
+       { 0x11, KEY_TV },       /*XXX*/
+       { 0x0d, KEY_MODE },     /*XXX there's no KEY_STEREO     */
+
+       /*  0x0f    0x1b    0x1a  *
+        *  AUDIO   Vol+    Chan+ *
+        *        TIMESHIFT???    *
+        *                        *
+        *  0x0e    0x1f    0x1e  *
+        *  SLEEP   Vol-    Chan- *
+        *                        */
+       { 0x0f, KEY_AUDIO },
+       { 0x1b, KEY_VOLUMEUP },
+       { 0x1a, KEY_CHANNELUP },
+       { 0x0e, KEY_TIME },
+       { 0x1f, KEY_VOLUMEDOWN },
+       { 0x1e, KEY_CHANNELDOWN },
+
+       /*         0x13     0x19  *
+        *         MUTE   SNAPSHOT*
+        *                        */
+       { 0x13, KEY_MUTE },
+       { 0x19, KEY_CAMERA },
+
+       /* 0x1d unused ? */
+};
+
+static struct rc_keymap manli_map = {
+       .map = {
+               .scan    = manli,
+               .size    = ARRAY_SIZE(manli),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_MANLI,
+       }
+};
+
+static int __init init_rc_map_manli(void)
+{
+       return ir_register_map(&manli_map);
+}
+
+static void __exit exit_rc_map_manli(void)
+{
+       ir_unregister_map(&manli_map);
+}
+
+module_init(init_rc_map_manli)
+module_exit(exit_rc_map_manli)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c b/drivers/media/IR/keymaps/rc-msi-tvanywhere-plus.c
new file mode 100644 (file)
index 0000000..eb8e42c
--- /dev/null
@@ -0,0 +1,123 @@
+/* msi-tvanywhere-plus.h - Keytable for msi_tvanywhere_plus Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+  Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card
+  is marked "KS003". The controller is I2C at address 0x30, but does not seem
+  to respond to probes until a read is performed from a valid device.
+  I don't know why...
+
+  Note: This remote may be of similar or identical design to the
+  Pixelview remote (?).  The raw codes and duplicate button codes
+  appear to be the same.
+
+  Henry Wong <henry@stuffedcow.net>
+  Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com>
+*/
+
+static struct ir_scancode msi_tvanywhere_plus[] = {
+
+/*  ---- Remote Button Layout ----
+
+    POWER   SOURCE  SCAN    MUTE
+    TV/FM   1       2       3
+    |>      4       5       6
+    <|      7       8       9
+    ^^UP    0       +       RECALL
+    vvDN    RECORD  STOP    PLAY
+
+       MINIMIZE          ZOOM
+
+                 CH+
+      VOL-                   VOL+
+                 CH-
+
+       SNAPSHOT           MTS
+
+     <<      FUNC    >>     RESET
+*/
+
+       { 0x01, KEY_1 },                /* 1 */
+       { 0x0b, KEY_2 },                /* 2 */
+       { 0x1b, KEY_3 },                /* 3 */
+       { 0x05, KEY_4 },                /* 4 */
+       { 0x09, KEY_5 },                /* 5 */
+       { 0x15, KEY_6 },                /* 6 */
+       { 0x06, KEY_7 },                /* 7 */
+       { 0x0a, KEY_8 },                /* 8 */
+       { 0x12, KEY_9 },                /* 9 */
+       { 0x02, KEY_0 },                /* 0 */
+       { 0x10, KEY_KPPLUS },           /* + */
+       { 0x13, KEY_AGAIN },            /* Recall */
+
+       { 0x1e, KEY_POWER },            /* Power */
+       { 0x07, KEY_TUNER },            /* Source */
+       { 0x1c, KEY_SEARCH },           /* Scan */
+       { 0x18, KEY_MUTE },             /* Mute */
+
+       { 0x03, KEY_RADIO },            /* TV/FM */
+       /* The next four keys are duplicates that appear to send the
+          same IR code as Ch+, Ch-, >>, and << .  The raw code assigned
+          to them is the actual code + 0x20 - they will never be
+          detected as such unless some way is discovered to distinguish
+          these buttons from those that have the same code. */
+       { 0x3f, KEY_RIGHT },            /* |> and Ch+ */
+       { 0x37, KEY_LEFT },             /* <| and Ch- */
+       { 0x2c, KEY_UP },               /* ^^Up and >> */
+       { 0x24, KEY_DOWN },             /* vvDn and << */
+
+       { 0x00, KEY_RECORD },           /* Record */
+       { 0x08, KEY_STOP },             /* Stop */
+       { 0x11, KEY_PLAY },             /* Play */
+
+       { 0x0f, KEY_CLOSE },            /* Minimize */
+       { 0x19, KEY_ZOOM },             /* Zoom */
+       { 0x1a, KEY_CAMERA },           /* Snapshot */
+       { 0x0d, KEY_LANGUAGE },         /* MTS */
+
+       { 0x14, KEY_VOLUMEDOWN },       /* Vol- */
+       { 0x16, KEY_VOLUMEUP },         /* Vol+ */
+       { 0x17, KEY_CHANNELDOWN },      /* Ch- */
+       { 0x1f, KEY_CHANNELUP },        /* Ch+ */
+
+       { 0x04, KEY_REWIND },           /* << */
+       { 0x0e, KEY_MENU },             /* Function */
+       { 0x0c, KEY_FASTFORWARD },      /* >> */
+       { 0x1d, KEY_RESTART },          /* Reset */
+};
+
+static struct rc_keymap msi_tvanywhere_plus_map = {
+       .map = {
+               .scan    = msi_tvanywhere_plus,
+               .size    = ARRAY_SIZE(msi_tvanywhere_plus),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_MSI_TVANYWHERE_PLUS,
+       }
+};
+
+static int __init init_rc_map_msi_tvanywhere_plus(void)
+{
+       return ir_register_map(&msi_tvanywhere_plus_map);
+}
+
+static void __exit exit_rc_map_msi_tvanywhere_plus(void)
+{
+       ir_unregister_map(&msi_tvanywhere_plus_map);
+}
+
+module_init(init_rc_map_msi_tvanywhere_plus)
+module_exit(exit_rc_map_msi_tvanywhere_plus)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-msi-tvanywhere.c b/drivers/media/IR/keymaps/rc-msi-tvanywhere.c
new file mode 100644 (file)
index 0000000..ef41185
--- /dev/null
@@ -0,0 +1,69 @@
+/* msi-tvanywhere.h - Keytable for msi_tvanywhere Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* MSI TV@nywhere MASTER remote */
+
+static struct ir_scancode msi_tvanywhere[] = {
+       /* Keys 0 to 9 */
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0c, KEY_MUTE },
+       { 0x0f, KEY_SCREEN },           /* Full Screen */
+       { 0x10, KEY_FN },               /* Funtion */
+       { 0x11, KEY_TIME },             /* Time shift */
+       { 0x12, KEY_POWER },
+       { 0x13, KEY_MEDIA },            /* MTS */
+       { 0x14, KEY_SLOW },
+       { 0x16, KEY_REWIND },           /* backward << */
+       { 0x17, KEY_ENTER },            /* Return */
+       { 0x18, KEY_FASTFORWARD },      /* forward >> */
+       { 0x1a, KEY_CHANNELUP },
+       { 0x1b, KEY_VOLUMEUP },
+       { 0x1e, KEY_CHANNELDOWN },
+       { 0x1f, KEY_VOLUMEDOWN },
+};
+
+static struct rc_keymap msi_tvanywhere_map = {
+       .map = {
+               .scan    = msi_tvanywhere,
+               .size    = ARRAY_SIZE(msi_tvanywhere),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_MSI_TVANYWHERE,
+       }
+};
+
+static int __init init_rc_map_msi_tvanywhere(void)
+{
+       return ir_register_map(&msi_tvanywhere_map);
+}
+
+static void __exit exit_rc_map_msi_tvanywhere(void)
+{
+       ir_unregister_map(&msi_tvanywhere_map);
+}
+
+module_init(init_rc_map_msi_tvanywhere)
+module_exit(exit_rc_map_msi_tvanywhere)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-nebula.c b/drivers/media/IR/keymaps/rc-nebula.c
new file mode 100644 (file)
index 0000000..ccc50eb
--- /dev/null
@@ -0,0 +1,96 @@
+/* nebula.h - Keytable for nebula Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode nebula[] = {
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+       { 0x0a, KEY_TV },
+       { 0x0b, KEY_AUX },
+       { 0x0c, KEY_DVD },
+       { 0x0d, KEY_POWER },
+       { 0x0e, KEY_MHP },      /* labelled 'Picture' */
+       { 0x0f, KEY_AUDIO },
+       { 0x10, KEY_INFO },
+       { 0x11, KEY_F13 },      /* 16:9 */
+       { 0x12, KEY_F14 },      /* 14:9 */
+       { 0x13, KEY_EPG },
+       { 0x14, KEY_EXIT },
+       { 0x15, KEY_MENU },
+       { 0x16, KEY_UP },
+       { 0x17, KEY_DOWN },
+       { 0x18, KEY_LEFT },
+       { 0x19, KEY_RIGHT },
+       { 0x1a, KEY_ENTER },
+       { 0x1b, KEY_CHANNELUP },
+       { 0x1c, KEY_CHANNELDOWN },
+       { 0x1d, KEY_VOLUMEUP },
+       { 0x1e, KEY_VOLUMEDOWN },
+       { 0x1f, KEY_RED },
+       { 0x20, KEY_GREEN },
+       { 0x21, KEY_YELLOW },
+       { 0x22, KEY_BLUE },
+       { 0x23, KEY_SUBTITLE },
+       { 0x24, KEY_F15 },      /* AD */
+       { 0x25, KEY_TEXT },
+       { 0x26, KEY_MUTE },
+       { 0x27, KEY_REWIND },
+       { 0x28, KEY_STOP },
+       { 0x29, KEY_PLAY },
+       { 0x2a, KEY_FASTFORWARD },
+       { 0x2b, KEY_F16 },      /* chapter */
+       { 0x2c, KEY_PAUSE },
+       { 0x2d, KEY_PLAY },
+       { 0x2e, KEY_RECORD },
+       { 0x2f, KEY_F17 },      /* picture in picture */
+       { 0x30, KEY_KPPLUS },   /* zoom in */
+       { 0x31, KEY_KPMINUS },  /* zoom out */
+       { 0x32, KEY_F18 },      /* capture */
+       { 0x33, KEY_F19 },      /* web */
+       { 0x34, KEY_EMAIL },
+       { 0x35, KEY_PHONE },
+       { 0x36, KEY_PC },
+};
+
+static struct rc_keymap nebula_map = {
+       .map = {
+               .scan    = nebula,
+               .size    = ARRAY_SIZE(nebula),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_NEBULA,
+       }
+};
+
+static int __init init_rc_map_nebula(void)
+{
+       return ir_register_map(&nebula_map);
+}
+
+static void __exit exit_rc_map_nebula(void)
+{
+       ir_unregister_map(&nebula_map);
+}
+
+module_init(init_rc_map_nebula)
+module_exit(exit_rc_map_nebula)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c b/drivers/media/IR/keymaps/rc-nec-terratec-cinergy-xs.c
new file mode 100644 (file)
index 0000000..e1b54d2
--- /dev/null
@@ -0,0 +1,105 @@
+/* nec-terratec-cinergy-xs.h - Keytable for nec_terratec_cinergy_xs Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Terratec Cinergy Hybrid T USB XS FM
+   Mauro Carvalho Chehab <mchehab@redhat.com>
+ */
+
+static struct ir_scancode nec_terratec_cinergy_xs[] = {
+       { 0x1441, KEY_HOME},
+       { 0x1401, KEY_POWER2},
+
+       { 0x1442, KEY_MENU},            /* DVD menu */
+       { 0x1443, KEY_SUBTITLE},
+       { 0x1444, KEY_TEXT},            /* Teletext */
+       { 0x1445, KEY_DELETE},
+
+       { 0x1402, KEY_1},
+       { 0x1403, KEY_2},
+       { 0x1404, KEY_3},
+       { 0x1405, KEY_4},
+       { 0x1406, KEY_5},
+       { 0x1407, KEY_6},
+       { 0x1408, KEY_7},
+       { 0x1409, KEY_8},
+       { 0x140a, KEY_9},
+       { 0x140c, KEY_0},
+
+       { 0x140b, KEY_TUNER},           /* AV */
+       { 0x140d, KEY_MODE},            /* A.B */
+
+       { 0x1446, KEY_TV},
+       { 0x1447, KEY_DVD},
+       { 0x1449, KEY_VIDEO},
+       { 0x144a, KEY_RADIO},           /* Music */
+       { 0x144b, KEY_CAMERA},          /* PIC */
+
+       { 0x1410, KEY_UP},
+       { 0x1411, KEY_LEFT},
+       { 0x1412, KEY_OK},
+       { 0x1413, KEY_RIGHT},
+       { 0x1414, KEY_DOWN},
+
+       { 0x140f, KEY_EPG},
+       { 0x1416, KEY_INFO},
+       { 0x144d, KEY_BACKSPACE},
+
+       { 0x141c, KEY_VOLUMEUP},
+       { 0x141e, KEY_VOLUMEDOWN},
+
+       { 0x144c, KEY_PLAY},
+       { 0x141d, KEY_MUTE},
+
+       { 0x141b, KEY_CHANNELUP},
+       { 0x141f, KEY_CHANNELDOWN},
+
+       { 0x1417, KEY_RED},
+       { 0x1418, KEY_GREEN},
+       { 0x1419, KEY_YELLOW},
+       { 0x141a, KEY_BLUE},
+
+       { 0x1458, KEY_RECORD},
+       { 0x1448, KEY_STOP},
+       { 0x1440, KEY_PAUSE},
+
+       { 0x1454, KEY_LAST},
+       { 0x144e, KEY_REWIND},
+       { 0x144f, KEY_FASTFORWARD},
+       { 0x145c, KEY_NEXT},
+};
+
+static struct rc_keymap nec_terratec_cinergy_xs_map = {
+       .map = {
+               .scan    = nec_terratec_cinergy_xs,
+               .size    = ARRAY_SIZE(nec_terratec_cinergy_xs),
+               .ir_type = IR_TYPE_NEC,
+               .name    = RC_MAP_NEC_TERRATEC_CINERGY_XS,
+       }
+};
+
+static int __init init_rc_map_nec_terratec_cinergy_xs(void)
+{
+       return ir_register_map(&nec_terratec_cinergy_xs_map);
+}
+
+static void __exit exit_rc_map_nec_terratec_cinergy_xs(void)
+{
+       ir_unregister_map(&nec_terratec_cinergy_xs_map);
+}
+
+module_init(init_rc_map_nec_terratec_cinergy_xs)
+module_exit(exit_rc_map_nec_terratec_cinergy_xs)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-norwood.c b/drivers/media/IR/keymaps/rc-norwood.c
new file mode 100644 (file)
index 0000000..e5849a6
--- /dev/null
@@ -0,0 +1,85 @@
+/* norwood.h - Keytable for norwood Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Norwood Micro (non-Pro) TV Tuner
+   By Peter Naulls <peter@chocky.org>
+   Key comments are the functions given in the manual */
+
+static struct ir_scancode norwood[] = {
+       /* Keys 0 to 9 */
+       { 0x20, KEY_0 },
+       { 0x21, KEY_1 },
+       { 0x22, KEY_2 },
+       { 0x23, KEY_3 },
+       { 0x24, KEY_4 },
+       { 0x25, KEY_5 },
+       { 0x26, KEY_6 },
+       { 0x27, KEY_7 },
+       { 0x28, KEY_8 },
+       { 0x29, KEY_9 },
+
+       { 0x78, KEY_TUNER },            /* Video Source        */
+       { 0x2c, KEY_EXIT },             /* Open/Close software */
+       { 0x2a, KEY_SELECT },           /* 2 Digit Select      */
+       { 0x69, KEY_AGAIN },            /* Recall              */
+
+       { 0x32, KEY_BRIGHTNESSUP },     /* Brightness increase */
+       { 0x33, KEY_BRIGHTNESSDOWN },   /* Brightness decrease */
+       { 0x6b, KEY_KPPLUS },           /* (not named >>>>>)   */
+       { 0x6c, KEY_KPMINUS },          /* (not named <<<<<)   */
+
+       { 0x2d, KEY_MUTE },             /* Mute                */
+       { 0x30, KEY_VOLUMEUP },         /* Volume up           */
+       { 0x31, KEY_VOLUMEDOWN },       /* Volume down         */
+       { 0x60, KEY_CHANNELUP },        /* Channel up          */
+       { 0x61, KEY_CHANNELDOWN },      /* Channel down        */
+
+       { 0x3f, KEY_RECORD },           /* Record              */
+       { 0x37, KEY_PLAY },             /* Play                */
+       { 0x36, KEY_PAUSE },            /* Pause               */
+       { 0x2b, KEY_STOP },             /* Stop                */
+       { 0x67, KEY_FASTFORWARD },      /* Foward              */
+       { 0x66, KEY_REWIND },           /* Rewind              */
+       { 0x3e, KEY_SEARCH },           /* Auto Scan           */
+       { 0x2e, KEY_CAMERA },           /* Capture Video       */
+       { 0x6d, KEY_MENU },             /* Show/Hide Control   */
+       { 0x2f, KEY_ZOOM },             /* Full Screen         */
+       { 0x34, KEY_RADIO },            /* FM                  */
+       { 0x65, KEY_POWER },            /* Computer power      */
+};
+
+static struct rc_keymap norwood_map = {
+       .map = {
+               .scan    = norwood,
+               .size    = ARRAY_SIZE(norwood),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_NORWOOD,
+       }
+};
+
+static int __init init_rc_map_norwood(void)
+{
+       return ir_register_map(&norwood_map);
+}
+
+static void __exit exit_rc_map_norwood(void)
+{
+       ir_unregister_map(&norwood_map);
+}
+
+module_init(init_rc_map_norwood)
+module_exit(exit_rc_map_norwood)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-npgtech.c b/drivers/media/IR/keymaps/rc-npgtech.c
new file mode 100644 (file)
index 0000000..b9ece1e
--- /dev/null
@@ -0,0 +1,80 @@
+/* npgtech.h - Keytable for npgtech Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode npgtech[] = {
+       { 0x1d, KEY_SWITCHVIDEOMODE },  /* switch inputs */
+       { 0x2a, KEY_FRONT },
+
+       { 0x3e, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x06, KEY_3 },
+       { 0x0a, KEY_4 },
+       { 0x0e, KEY_5 },
+       { 0x12, KEY_6 },
+       { 0x16, KEY_7 },
+       { 0x1a, KEY_8 },
+       { 0x1e, KEY_9 },
+       { 0x3a, KEY_0 },
+       { 0x22, KEY_NUMLOCK },          /* -/-- */
+       { 0x20, KEY_REFRESH },
+
+       { 0x03, KEY_BRIGHTNESSDOWN },
+       { 0x28, KEY_AUDIO },
+       { 0x3c, KEY_CHANNELUP },
+       { 0x3f, KEY_VOLUMEDOWN },
+       { 0x2e, KEY_MUTE },
+       { 0x3b, KEY_VOLUMEUP },
+       { 0x00, KEY_CHANNELDOWN },
+       { 0x07, KEY_BRIGHTNESSUP },
+       { 0x2c, KEY_TEXT },
+
+       { 0x37, KEY_RECORD },
+       { 0x17, KEY_PLAY },
+       { 0x13, KEY_PAUSE },
+       { 0x26, KEY_STOP },
+       { 0x18, KEY_FASTFORWARD },
+       { 0x14, KEY_REWIND },
+       { 0x33, KEY_ZOOM },
+       { 0x32, KEY_KEYBOARD },
+       { 0x30, KEY_GOTO },             /* Pointing arrow */
+       { 0x36, KEY_MACRO },            /* Maximize/Minimize (yellow) */
+       { 0x0b, KEY_RADIO },
+       { 0x10, KEY_POWER },
+
+};
+
+static struct rc_keymap npgtech_map = {
+       .map = {
+               .scan    = npgtech,
+               .size    = ARRAY_SIZE(npgtech),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_NPGTECH,
+       }
+};
+
+static int __init init_rc_map_npgtech(void)
+{
+       return ir_register_map(&npgtech_map);
+}
+
+static void __exit exit_rc_map_npgtech(void)
+{
+       ir_unregister_map(&npgtech_map);
+}
+
+module_init(init_rc_map_npgtech)
+module_exit(exit_rc_map_npgtech)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pctv-sedna.c b/drivers/media/IR/keymaps/rc-pctv-sedna.c
new file mode 100644 (file)
index 0000000..4129bb4
--- /dev/null
@@ -0,0 +1,80 @@
+/* pctv-sedna.h - Keytable for pctv_sedna Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Mapping for the 28 key remote control as seen at
+   http://www.sednacomputer.com/photo/cardbus-tv.jpg
+   Pavel Mihaylov <bin@bash.info>
+   Also for the remote bundled with Kozumi KTV-01C card */
+
+static struct ir_scancode pctv_sedna[] = {
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0a, KEY_AGAIN },    /* Recall */
+       { 0x0b, KEY_CHANNELUP },
+       { 0x0c, KEY_VOLUMEUP },
+       { 0x0d, KEY_MODE },     /* Stereo */
+       { 0x0e, KEY_STOP },
+       { 0x0f, KEY_PREVIOUSSONG },
+       { 0x10, KEY_ZOOM },
+       { 0x11, KEY_TUNER },    /* Source */
+       { 0x12, KEY_POWER },
+       { 0x13, KEY_MUTE },
+       { 0x15, KEY_CHANNELDOWN },
+       { 0x18, KEY_VOLUMEDOWN },
+       { 0x19, KEY_CAMERA },   /* Snapshot */
+       { 0x1a, KEY_NEXTSONG },
+       { 0x1b, KEY_TIME },     /* Time Shift */
+       { 0x1c, KEY_RADIO },    /* FM Radio */
+       { 0x1d, KEY_RECORD },
+       { 0x1e, KEY_PAUSE },
+       /* additional codes for Kozumi's remote */
+       { 0x14, KEY_INFO },     /* OSD */
+       { 0x16, KEY_OK },       /* OK */
+       { 0x17, KEY_DIGITS },   /* Plus */
+       { 0x1f, KEY_PLAY },     /* Play */
+};
+
+static struct rc_keymap pctv_sedna_map = {
+       .map = {
+               .scan    = pctv_sedna,
+               .size    = ARRAY_SIZE(pctv_sedna),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PCTV_SEDNA,
+       }
+};
+
+static int __init init_rc_map_pctv_sedna(void)
+{
+       return ir_register_map(&pctv_sedna_map);
+}
+
+static void __exit exit_rc_map_pctv_sedna(void)
+{
+       ir_unregister_map(&pctv_sedna_map);
+}
+
+module_init(init_rc_map_pctv_sedna)
+module_exit(exit_rc_map_pctv_sedna)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-color.c b/drivers/media/IR/keymaps/rc-pinnacle-color.c
new file mode 100644 (file)
index 0000000..326e023
--- /dev/null
@@ -0,0 +1,94 @@
+/* pinnacle-color.h - Keytable for pinnacle_color Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode pinnacle_color[] = {
+       { 0x59, KEY_MUTE },
+       { 0x4a, KEY_POWER },
+
+       { 0x18, KEY_TEXT },
+       { 0x26, KEY_TV },
+       { 0x3d, KEY_PRINT },
+
+       { 0x48, KEY_RED },
+       { 0x04, KEY_GREEN },
+       { 0x11, KEY_YELLOW },
+       { 0x00, KEY_BLUE },
+
+       { 0x2d, KEY_VOLUMEUP },
+       { 0x1e, KEY_VOLUMEDOWN },
+
+       { 0x49, KEY_MENU },
+
+       { 0x16, KEY_CHANNELUP },
+       { 0x17, KEY_CHANNELDOWN },
+
+       { 0x20, KEY_UP },
+       { 0x21, KEY_DOWN },
+       { 0x22, KEY_LEFT },
+       { 0x23, KEY_RIGHT },
+       { 0x0d, KEY_SELECT },
+
+       { 0x08, KEY_BACK },
+       { 0x07, KEY_REFRESH },
+
+       { 0x2f, KEY_ZOOM },
+       { 0x29, KEY_RECORD },
+
+       { 0x4b, KEY_PAUSE },
+       { 0x4d, KEY_REWIND },
+       { 0x2e, KEY_PLAY },
+       { 0x4e, KEY_FORWARD },
+       { 0x53, KEY_PREVIOUS },
+       { 0x4c, KEY_STOP },
+       { 0x54, KEY_NEXT },
+
+       { 0x69, KEY_0 },
+       { 0x6a, KEY_1 },
+       { 0x6b, KEY_2 },
+       { 0x6c, KEY_3 },
+       { 0x6d, KEY_4 },
+       { 0x6e, KEY_5 },
+       { 0x6f, KEY_6 },
+       { 0x70, KEY_7 },
+       { 0x71, KEY_8 },
+       { 0x72, KEY_9 },
+
+       { 0x74, KEY_CHANNEL },
+       { 0x0a, KEY_BACKSPACE },
+};
+
+static struct rc_keymap pinnacle_color_map = {
+       .map = {
+               .scan    = pinnacle_color,
+               .size    = ARRAY_SIZE(pinnacle_color),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PINNACLE_COLOR,
+       }
+};
+
+static int __init init_rc_map_pinnacle_color(void)
+{
+       return ir_register_map(&pinnacle_color_map);
+}
+
+static void __exit exit_rc_map_pinnacle_color(void)
+{
+       ir_unregister_map(&pinnacle_color_map);
+}
+
+module_init(init_rc_map_pinnacle_color)
+module_exit(exit_rc_map_pinnacle_color)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-grey.c b/drivers/media/IR/keymaps/rc-pinnacle-grey.c
new file mode 100644 (file)
index 0000000..14cb772
--- /dev/null
@@ -0,0 +1,89 @@
+/* pinnacle-grey.h - Keytable for pinnacle_grey Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode pinnacle_grey[] = {
+       { 0x3a, KEY_0 },
+       { 0x31, KEY_1 },
+       { 0x32, KEY_2 },
+       { 0x33, KEY_3 },
+       { 0x34, KEY_4 },
+       { 0x35, KEY_5 },
+       { 0x36, KEY_6 },
+       { 0x37, KEY_7 },
+       { 0x38, KEY_8 },
+       { 0x39, KEY_9 },
+
+       { 0x2f, KEY_POWER },
+
+       { 0x2e, KEY_P },
+       { 0x1f, KEY_L },
+       { 0x2b, KEY_I },
+
+       { 0x2d, KEY_SCREEN },
+       { 0x1e, KEY_ZOOM },
+       { 0x1b, KEY_VOLUMEUP },
+       { 0x0f, KEY_VOLUMEDOWN },
+       { 0x17, KEY_CHANNELUP },
+       { 0x1c, KEY_CHANNELDOWN },
+       { 0x25, KEY_INFO },
+
+       { 0x3c, KEY_MUTE },
+
+       { 0x3d, KEY_LEFT },
+       { 0x3b, KEY_RIGHT },
+
+       { 0x3f, KEY_UP },
+       { 0x3e, KEY_DOWN },
+       { 0x1a, KEY_ENTER },
+
+       { 0x1d, KEY_MENU },
+       { 0x19, KEY_AGAIN },
+       { 0x16, KEY_PREVIOUSSONG },
+       { 0x13, KEY_NEXTSONG },
+       { 0x15, KEY_PAUSE },
+       { 0x0e, KEY_REWIND },
+       { 0x0d, KEY_PLAY },
+       { 0x0b, KEY_STOP },
+       { 0x07, KEY_FORWARD },
+       { 0x27, KEY_RECORD },
+       { 0x26, KEY_TUNER },
+       { 0x29, KEY_TEXT },
+       { 0x2a, KEY_MEDIA },
+       { 0x18, KEY_EPG },
+};
+
+static struct rc_keymap pinnacle_grey_map = {
+       .map = {
+               .scan    = pinnacle_grey,
+               .size    = ARRAY_SIZE(pinnacle_grey),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PINNACLE_GREY,
+       }
+};
+
+static int __init init_rc_map_pinnacle_grey(void)
+{
+       return ir_register_map(&pinnacle_grey_map);
+}
+
+static void __exit exit_rc_map_pinnacle_grey(void)
+{
+       ir_unregister_map(&pinnacle_grey_map);
+}
+
+module_init(init_rc_map_pinnacle_grey)
+module_exit(exit_rc_map_pinnacle_grey)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c b/drivers/media/IR/keymaps/rc-pinnacle-pctv-hd.c
new file mode 100644 (file)
index 0000000..835bf4e
--- /dev/null
@@ -0,0 +1,73 @@
+/* pinnacle-pctv-hd.h - Keytable for pinnacle_pctv_hd Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Pinnacle PCTV HD 800i mini remote */
+
+static struct ir_scancode pinnacle_pctv_hd[] = {
+
+       { 0x0f, KEY_1 },
+       { 0x15, KEY_2 },
+       { 0x10, KEY_3 },
+       { 0x18, KEY_4 },
+       { 0x1b, KEY_5 },
+       { 0x1e, KEY_6 },
+       { 0x11, KEY_7 },
+       { 0x21, KEY_8 },
+       { 0x12, KEY_9 },
+       { 0x27, KEY_0 },
+
+       { 0x24, KEY_ZOOM },
+       { 0x2a, KEY_SUBTITLE },
+
+       { 0x00, KEY_MUTE },
+       { 0x01, KEY_ENTER },    /* Pinnacle Logo */
+       { 0x39, KEY_POWER },
+
+       { 0x03, KEY_VOLUMEUP },
+       { 0x09, KEY_VOLUMEDOWN },
+       { 0x06, KEY_CHANNELUP },
+       { 0x0c, KEY_CHANNELDOWN },
+
+       { 0x2d, KEY_REWIND },
+       { 0x30, KEY_PLAYPAUSE },
+       { 0x33, KEY_FASTFORWARD },
+       { 0x3c, KEY_STOP },
+       { 0x36, KEY_RECORD },
+       { 0x3f, KEY_EPG },      /* Labeled "?" */
+};
+
+static struct rc_keymap pinnacle_pctv_hd_map = {
+       .map = {
+               .scan    = pinnacle_pctv_hd,
+               .size    = ARRAY_SIZE(pinnacle_pctv_hd),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PINNACLE_PCTV_HD,
+       }
+};
+
+static int __init init_rc_map_pinnacle_pctv_hd(void)
+{
+       return ir_register_map(&pinnacle_pctv_hd_map);
+}
+
+static void __exit exit_rc_map_pinnacle_pctv_hd(void)
+{
+       ir_unregister_map(&pinnacle_pctv_hd_map);
+}
+
+module_init(init_rc_map_pinnacle_pctv_hd)
+module_exit(exit_rc_map_pinnacle_pctv_hd)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pixelview-mk12.c b/drivers/media/IR/keymaps/rc-pixelview-mk12.c
new file mode 100644 (file)
index 0000000..5a735d5
--- /dev/null
@@ -0,0 +1,83 @@
+/* rc-pixelview-mk12.h - Keytable for pixelview Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Keytable for MK-F12 IR remote provided together with Pixelview
+ * Ultra Pro Remote Controller. Uses NEC extended format.
+ */
+static struct ir_scancode pixelview_mk12[] = {
+       { 0x866b03, KEY_TUNER },        /* Timeshift */
+       { 0x866b1e, KEY_POWER2 },       /* power */
+
+       { 0x866b01, KEY_1 },
+       { 0x866b0b, KEY_2 },
+       { 0x866b1b, KEY_3 },
+       { 0x866b05, KEY_4 },
+       { 0x866b09, KEY_5 },
+       { 0x866b15, KEY_6 },
+       { 0x866b06, KEY_7 },
+       { 0x866b0a, KEY_8 },
+       { 0x866b12, KEY_9 },
+       { 0x866b02, KEY_0 },
+
+       { 0x866b13, KEY_AGAIN },        /* loop */
+       { 0x866b10, KEY_DIGITS },       /* +100 */
+
+       { 0x866b00, KEY_MEDIA },        /* source */
+       { 0x866b18, KEY_MUTE },         /* mute */
+       { 0x866b19, KEY_CAMERA },       /* snapshot */
+       { 0x866b1a, KEY_SEARCH },       /* scan */
+
+       { 0x866b16, KEY_CHANNELUP },    /* chn + */
+       { 0x866b14, KEY_CHANNELDOWN },  /* chn - */
+       { 0x866b1f, KEY_VOLUMEUP },     /* vol + */
+       { 0x866b17, KEY_VOLUMEDOWN },   /* vol - */
+       { 0x866b1c, KEY_ZOOM },         /* zoom */
+
+       { 0x866b04, KEY_REWIND },
+       { 0x866b0e, KEY_RECORD },
+       { 0x866b0c, KEY_FORWARD },
+
+       { 0x866b1d, KEY_STOP },
+       { 0x866b08, KEY_PLAY },
+       { 0x866b0f, KEY_PAUSE },
+
+       { 0x866b0d, KEY_TV },
+       { 0x866b07, KEY_RADIO },        /* FM */
+};
+
+static struct rc_keymap pixelview_map = {
+       .map = {
+               .scan    = pixelview_mk12,
+               .size    = ARRAY_SIZE(pixelview_mk12),
+               .ir_type = IR_TYPE_NEC,
+               .name    = RC_MAP_PIXELVIEW_MK12,
+       }
+};
+
+static int __init init_rc_map_pixelview(void)
+{
+       return ir_register_map(&pixelview_map);
+}
+
+static void __exit exit_rc_map_pixelview(void)
+{
+       ir_unregister_map(&pixelview_map);
+}
+
+module_init(init_rc_map_pixelview)
+module_exit(exit_rc_map_pixelview)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pixelview-new.c b/drivers/media/IR/keymaps/rc-pixelview-new.c
new file mode 100644 (file)
index 0000000..7bbbbf5
--- /dev/null
@@ -0,0 +1,83 @@
+/* pixelview-new.h - Keytable for pixelview_new Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+   Mauro Carvalho Chehab <mchehab@infradead.org>
+   present on PV MPEG 8000GT
+ */
+
+static struct ir_scancode pixelview_new[] = {
+       { 0x3c, KEY_TIME },             /* Timeshift */
+       { 0x12, KEY_POWER },
+
+       { 0x3d, KEY_1 },
+       { 0x38, KEY_2 },
+       { 0x18, KEY_3 },
+       { 0x35, KEY_4 },
+       { 0x39, KEY_5 },
+       { 0x15, KEY_6 },
+       { 0x36, KEY_7 },
+       { 0x3a, KEY_8 },
+       { 0x1e, KEY_9 },
+       { 0x3e, KEY_0 },
+
+       { 0x1c, KEY_AGAIN },            /* LOOP */
+       { 0x3f, KEY_MEDIA },            /* Source */
+       { 0x1f, KEY_LAST },             /* +100 */
+       { 0x1b, KEY_MUTE },
+
+       { 0x17, KEY_CHANNELDOWN },
+       { 0x16, KEY_CHANNELUP },
+       { 0x10, KEY_VOLUMEUP },
+       { 0x14, KEY_VOLUMEDOWN },
+       { 0x13, KEY_ZOOM },
+
+       { 0x19, KEY_CAMERA },           /* SNAPSHOT */
+       { 0x1a, KEY_SEARCH },           /* scan */
+
+       { 0x37, KEY_REWIND },           /* << */
+       { 0x32, KEY_RECORD },           /* o (red) */
+       { 0x33, KEY_FORWARD },          /* >> */
+       { 0x11, KEY_STOP },             /* square */
+       { 0x3b, KEY_PLAY },             /* > */
+       { 0x30, KEY_PLAYPAUSE },        /* || */
+
+       { 0x31, KEY_TV },
+       { 0x34, KEY_RADIO },
+};
+
+static struct rc_keymap pixelview_new_map = {
+       .map = {
+               .scan    = pixelview_new,
+               .size    = ARRAY_SIZE(pixelview_new),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PIXELVIEW_NEW,
+       }
+};
+
+static int __init init_rc_map_pixelview_new(void)
+{
+       return ir_register_map(&pixelview_new_map);
+}
+
+static void __exit exit_rc_map_pixelview_new(void)
+{
+       ir_unregister_map(&pixelview_new_map);
+}
+
+module_init(init_rc_map_pixelview_new)
+module_exit(exit_rc_map_pixelview_new)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pixelview.c b/drivers/media/IR/keymaps/rc-pixelview.c
new file mode 100644 (file)
index 0000000..82ff12e
--- /dev/null
@@ -0,0 +1,82 @@
+/* pixelview.h - Keytable for pixelview Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode pixelview[] = {
+
+       { 0x1e, KEY_POWER },    /* power */
+       { 0x07, KEY_MEDIA },    /* source */
+       { 0x1c, KEY_SEARCH },   /* scan */
+
+
+       { 0x03, KEY_TUNER },            /* TV/FM */
+
+       { 0x00, KEY_RECORD },
+       { 0x08, KEY_STOP },
+       { 0x11, KEY_PLAY },
+
+       { 0x1a, KEY_PLAYPAUSE },        /* freeze */
+       { 0x19, KEY_ZOOM },             /* zoom */
+       { 0x0f, KEY_TEXT },             /* min */
+
+       { 0x01, KEY_1 },
+       { 0x0b, KEY_2 },
+       { 0x1b, KEY_3 },
+       { 0x05, KEY_4 },
+       { 0x09, KEY_5 },
+       { 0x15, KEY_6 },
+       { 0x06, KEY_7 },
+       { 0x0a, KEY_8 },
+       { 0x12, KEY_9 },
+       { 0x02, KEY_0 },
+       { 0x10, KEY_LAST },             /* +100 */
+       { 0x13, KEY_LIST },             /* recall */
+
+       { 0x1f, KEY_CHANNELUP },        /* chn down */
+       { 0x17, KEY_CHANNELDOWN },      /* chn up */
+       { 0x16, KEY_VOLUMEUP },         /* vol down */
+       { 0x14, KEY_VOLUMEDOWN },       /* vol up */
+
+       { 0x04, KEY_KPMINUS },          /* <<< */
+       { 0x0e, KEY_SETUP },            /* function */
+       { 0x0c, KEY_KPPLUS },           /* >>> */
+
+       { 0x0d, KEY_GOTO },             /* mts */
+       { 0x1d, KEY_REFRESH },          /* reset */
+       { 0x18, KEY_MUTE },             /* mute/unmute */
+};
+
+static struct rc_keymap pixelview_map = {
+       .map = {
+               .scan    = pixelview,
+               .size    = ARRAY_SIZE(pixelview),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PIXELVIEW,
+       }
+};
+
+static int __init init_rc_map_pixelview(void)
+{
+       return ir_register_map(&pixelview_map);
+}
+
+static void __exit exit_rc_map_pixelview(void)
+{
+       ir_unregister_map(&pixelview_map);
+}
+
+module_init(init_rc_map_pixelview)
+module_exit(exit_rc_map_pixelview)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-powercolor-real-angel.c b/drivers/media/IR/keymaps/rc-powercolor-real-angel.c
new file mode 100644 (file)
index 0000000..7cef819
--- /dev/null
@@ -0,0 +1,81 @@
+/* powercolor-real-angel.h - Keytable for powercolor_real_angel Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Remote control for Powercolor Real Angel 330
+ * Daniel Fraga <fragabr@gmail.com>
+ */
+
+static struct ir_scancode powercolor_real_angel[] = {
+       { 0x38, KEY_SWITCHVIDEOMODE },  /* switch inputs */
+       { 0x0c, KEY_MEDIA },            /* Turn ON/OFF App */
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+       { 0x0a, KEY_DIGITS },           /* single, double, tripple digit */
+       { 0x29, KEY_PREVIOUS },         /* previous channel */
+       { 0x12, KEY_BRIGHTNESSUP },
+       { 0x13, KEY_BRIGHTNESSDOWN },
+       { 0x2b, KEY_MODE },             /* stereo/mono */
+       { 0x2c, KEY_TEXT },             /* teletext */
+       { 0x20, KEY_CHANNELUP },        /* channel up */
+       { 0x21, KEY_CHANNELDOWN },      /* channel down */
+       { 0x10, KEY_VOLUMEUP },         /* volume up */
+       { 0x11, KEY_VOLUMEDOWN },       /* volume down */
+       { 0x0d, KEY_MUTE },
+       { 0x1f, KEY_RECORD },
+       { 0x17, KEY_PLAY },
+       { 0x16, KEY_PAUSE },
+       { 0x0b, KEY_STOP },
+       { 0x27, KEY_FASTFORWARD },
+       { 0x26, KEY_REWIND },
+       { 0x1e, KEY_SEARCH },           /* autoscan */
+       { 0x0e, KEY_CAMERA },           /* snapshot */
+       { 0x2d, KEY_SETUP },
+       { 0x0f, KEY_SCREEN },           /* full screen */
+       { 0x14, KEY_RADIO },            /* FM radio */
+       { 0x25, KEY_POWER },            /* power */
+};
+
+static struct rc_keymap powercolor_real_angel_map = {
+       .map = {
+               .scan    = powercolor_real_angel,
+               .size    = ARRAY_SIZE(powercolor_real_angel),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_POWERCOLOR_REAL_ANGEL,
+       }
+};
+
+static int __init init_rc_map_powercolor_real_angel(void)
+{
+       return ir_register_map(&powercolor_real_angel_map);
+}
+
+static void __exit exit_rc_map_powercolor_real_angel(void)
+{
+       ir_unregister_map(&powercolor_real_angel_map);
+}
+
+module_init(init_rc_map_powercolor_real_angel)
+module_exit(exit_rc_map_powercolor_real_angel)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-proteus-2309.c b/drivers/media/IR/keymaps/rc-proteus-2309.c
new file mode 100644 (file)
index 0000000..22e92d3
--- /dev/null
@@ -0,0 +1,69 @@
+/* proteus-2309.h - Keytable for proteus_2309 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Michal Majchrowicz <mmajchrowicz@gmail.com> */
+
+static struct ir_scancode proteus_2309[] = {
+       /* numeric */
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x5c, KEY_POWER },            /* power       */
+       { 0x20, KEY_ZOOM },             /* full screen */
+       { 0x0f, KEY_BACKSPACE },        /* recall      */
+       { 0x1b, KEY_ENTER },            /* mute        */
+       { 0x41, KEY_RECORD },           /* record      */
+       { 0x43, KEY_STOP },             /* stop        */
+       { 0x16, KEY_S },
+       { 0x1a, KEY_POWER2 },           /* off         */
+       { 0x2e, KEY_RED },
+       { 0x1f, KEY_CHANNELDOWN },      /* channel -   */
+       { 0x1c, KEY_CHANNELUP },        /* channel +   */
+       { 0x10, KEY_VOLUMEDOWN },       /* volume -    */
+       { 0x1e, KEY_VOLUMEUP },         /* volume +    */
+       { 0x14, KEY_F1 },
+};
+
+static struct rc_keymap proteus_2309_map = {
+       .map = {
+               .scan    = proteus_2309,
+               .size    = ARRAY_SIZE(proteus_2309),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PROTEUS_2309,
+       }
+};
+
+static int __init init_rc_map_proteus_2309(void)
+{
+       return ir_register_map(&proteus_2309_map);
+}
+
+static void __exit exit_rc_map_proteus_2309(void)
+{
+       ir_unregister_map(&proteus_2309_map);
+}
+
+module_init(init_rc_map_proteus_2309)
+module_exit(exit_rc_map_proteus_2309)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-purpletv.c b/drivers/media/IR/keymaps/rc-purpletv.c
new file mode 100644 (file)
index 0000000..4e20fc2
--- /dev/null
@@ -0,0 +1,81 @@
+/* purpletv.h - Keytable for purpletv Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode purpletv[] = {
+       { 0x03, KEY_POWER },
+       { 0x6f, KEY_MUTE },
+       { 0x10, KEY_BACKSPACE },        /* Recall */
+
+       { 0x11, KEY_0 },
+       { 0x04, KEY_1 },
+       { 0x05, KEY_2 },
+       { 0x06, KEY_3 },
+       { 0x08, KEY_4 },
+       { 0x09, KEY_5 },
+       { 0x0a, KEY_6 },
+       { 0x0c, KEY_7 },
+       { 0x0d, KEY_8 },
+       { 0x0e, KEY_9 },
+       { 0x12, KEY_DOT },      /* 100+ */
+
+       { 0x07, KEY_VOLUMEUP },
+       { 0x0b, KEY_VOLUMEDOWN },
+       { 0x1a, KEY_KPPLUS },
+       { 0x18, KEY_KPMINUS },
+       { 0x15, KEY_UP },
+       { 0x1d, KEY_DOWN },
+       { 0x0f, KEY_CHANNELUP },
+       { 0x13, KEY_CHANNELDOWN },
+       { 0x48, KEY_ZOOM },
+
+       { 0x1b, KEY_VIDEO },    /* Video source */
+       { 0x1f, KEY_CAMERA },   /* Snapshot */
+       { 0x49, KEY_LANGUAGE }, /* MTS Select */
+       { 0x19, KEY_SEARCH },   /* Auto Scan */
+
+       { 0x4b, KEY_RECORD },
+       { 0x46, KEY_PLAY },
+       { 0x45, KEY_PAUSE },    /* Pause */
+       { 0x44, KEY_STOP },
+       { 0x43, KEY_TIME },     /* Time Shift */
+       { 0x17, KEY_CHANNEL },  /* SURF CH */
+       { 0x40, KEY_FORWARD },  /* Forward ? */
+       { 0x42, KEY_REWIND },   /* Backward ? */
+
+};
+
+static struct rc_keymap purpletv_map = {
+       .map = {
+               .scan    = purpletv,
+               .size    = ARRAY_SIZE(purpletv),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PURPLETV,
+       }
+};
+
+static int __init init_rc_map_purpletv(void)
+{
+       return ir_register_map(&purpletv_map);
+}
+
+static void __exit exit_rc_map_purpletv(void)
+{
+       ir_unregister_map(&purpletv_map);
+}
+
+module_init(init_rc_map_purpletv)
+module_exit(exit_rc_map_purpletv)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-pv951.c b/drivers/media/IR/keymaps/rc-pv951.c
new file mode 100644 (file)
index 0000000..36679e7
--- /dev/null
@@ -0,0 +1,78 @@
+/* pv951.h - Keytable for pv951 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Mark Phalan <phalanm@o2.ie> */
+
+static struct ir_scancode pv951[] = {
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x12, KEY_POWER },
+       { 0x10, KEY_MUTE },
+       { 0x1f, KEY_VOLUMEDOWN },
+       { 0x1b, KEY_VOLUMEUP },
+       { 0x1a, KEY_CHANNELUP },
+       { 0x1e, KEY_CHANNELDOWN },
+       { 0x0e, KEY_PAGEUP },
+       { 0x1d, KEY_PAGEDOWN },
+       { 0x13, KEY_SOUND },
+
+       { 0x18, KEY_KPPLUSMINUS },      /* CH +/- */
+       { 0x16, KEY_SUBTITLE },         /* CC */
+       { 0x0d, KEY_TEXT },             /* TTX */
+       { 0x0b, KEY_TV },               /* AIR/CBL */
+       { 0x11, KEY_PC },               /* PC/TV */
+       { 0x17, KEY_OK },               /* CH RTN */
+       { 0x19, KEY_MODE },             /* FUNC */
+       { 0x0c, KEY_SEARCH },           /* AUTOSCAN */
+
+       /* Not sure what to do with these ones! */
+       { 0x0f, KEY_SELECT },           /* SOURCE */
+       { 0x0a, KEY_KPPLUS },           /* +100 */
+       { 0x14, KEY_EQUAL },            /* SYNC */
+       { 0x1c, KEY_MEDIA },            /* PC/TV */
+};
+
+static struct rc_keymap pv951_map = {
+       .map = {
+               .scan    = pv951,
+               .size    = ARRAY_SIZE(pv951),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_PV951,
+       }
+};
+
+static int __init init_rc_map_pv951(void)
+{
+       return ir_register_map(&pv951_map);
+}
+
+static void __exit exit_rc_map_pv951(void)
+{
+       ir_unregister_map(&pv951_map);
+}
+
+module_init(init_rc_map_pv951)
+module_exit(exit_rc_map_pv951)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c b/drivers/media/IR/keymaps/rc-rc5-hauppauge-new.c
new file mode 100644 (file)
index 0000000..cc6b8f5
--- /dev/null
@@ -0,0 +1,103 @@
+/* rc5-hauppauge-new.h - Keytable for rc5_hauppauge_new Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/*
+ * Hauppauge:the newer, gray remotes (seems there are multiple
+ * slightly different versions), shipped with cx88+ivtv cards.
+ *
+ * This table contains the complete RC5 code, instead of just the data part
+ */
+
+static struct ir_scancode rc5_hauppauge_new[] = {
+       /* Keys 0 to 9 */
+       { 0x1e00, KEY_0 },
+       { 0x1e01, KEY_1 },
+       { 0x1e02, KEY_2 },
+       { 0x1e03, KEY_3 },
+       { 0x1e04, KEY_4 },
+       { 0x1e05, KEY_5 },
+       { 0x1e06, KEY_6 },
+       { 0x1e07, KEY_7 },
+       { 0x1e08, KEY_8 },
+       { 0x1e09, KEY_9 },
+
+       { 0x1e0a, KEY_TEXT },           /* keypad asterisk as well */
+       { 0x1e0b, KEY_RED },            /* red button */
+       { 0x1e0c, KEY_RADIO },
+       { 0x1e0d, KEY_MENU },
+       { 0x1e0e, KEY_SUBTITLE },               /* also the # key */
+       { 0x1e0f, KEY_MUTE },
+       { 0x1e10, KEY_VOLUMEUP },
+       { 0x1e11, KEY_VOLUMEDOWN },
+       { 0x1e12, KEY_PREVIOUS },               /* previous channel */
+       { 0x1e14, KEY_UP },
+       { 0x1e15, KEY_DOWN },
+       { 0x1e16, KEY_LEFT },
+       { 0x1e17, KEY_RIGHT },
+       { 0x1e18, KEY_VIDEO },          /* Videos */
+       { 0x1e19, KEY_AUDIO },          /* Music */
+       /* 0x1e1a: Pictures - presume this means
+          "Multimedia Home Platform" -
+          no "PICTURES" key in input.h
+        */
+       { 0x1e1a, KEY_MHP },
+
+       { 0x1e1b, KEY_EPG },            /* Guide */
+       { 0x1e1c, KEY_TV },
+       { 0x1e1e, KEY_NEXTSONG },               /* skip >| */
+       { 0x1e1f, KEY_EXIT },           /* back/exit */
+       { 0x1e20, KEY_CHANNELUP },      /* channel / program + */
+       { 0x1e21, KEY_CHANNELDOWN },    /* channel / program - */
+       { 0x1e22, KEY_CHANNEL },                /* source (old black remote) */
+       { 0x1e24, KEY_PREVIOUSSONG },   /* replay |< */
+       { 0x1e25, KEY_ENTER },          /* OK */
+       { 0x1e26, KEY_SLEEP },          /* minimize (old black remote) */
+       { 0x1e29, KEY_BLUE },           /* blue key */
+       { 0x1e2e, KEY_GREEN },          /* green button */
+       { 0x1e30, KEY_PAUSE },          /* pause */
+       { 0x1e32, KEY_REWIND },         /* backward << */
+       { 0x1e34, KEY_FASTFORWARD },    /* forward >> */
+       { 0x1e35, KEY_PLAY },
+       { 0x1e36, KEY_STOP },
+       { 0x1e37, KEY_RECORD },         /* recording */
+       { 0x1e38, KEY_YELLOW },         /* yellow key */
+       { 0x1e3b, KEY_SELECT },         /* top right button */
+       { 0x1e3c, KEY_ZOOM },           /* full */
+       { 0x1e3d, KEY_POWER },          /* system power (green button) */
+};
+
+static struct rc_keymap rc5_hauppauge_new_map = {
+       .map = {
+               .scan    = rc5_hauppauge_new,
+               .size    = ARRAY_SIZE(rc5_hauppauge_new),
+               .ir_type = IR_TYPE_RC5,
+               .name    = RC_MAP_RC5_HAUPPAUGE_NEW,
+       }
+};
+
+static int __init init_rc_map_rc5_hauppauge_new(void)
+{
+       return ir_register_map(&rc5_hauppauge_new_map);
+}
+
+static void __exit exit_rc_map_rc5_hauppauge_new(void)
+{
+       ir_unregister_map(&rc5_hauppauge_new_map);
+}
+
+module_init(init_rc_map_rc5_hauppauge_new)
+module_exit(exit_rc_map_rc5_hauppauge_new)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-rc5-tv.c b/drivers/media/IR/keymaps/rc-rc5-tv.c
new file mode 100644 (file)
index 0000000..73cce2f
--- /dev/null
@@ -0,0 +1,81 @@
+/* rc5-tv.h - Keytable for rc5_tv Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* generic RC5 keytable                                          */
+/* see http://users.pandora.be/nenya/electronics/rc5/codes00.htm */
+/* used by old (black) Hauppauge remotes                         */
+
+static struct ir_scancode rc5_tv[] = {
+       /* Keys 0 to 9 */
+       { 0x00, KEY_0 },
+       { 0x01, KEY_1 },
+       { 0x02, KEY_2 },
+       { 0x03, KEY_3 },
+       { 0x04, KEY_4 },
+       { 0x05, KEY_5 },
+       { 0x06, KEY_6 },
+       { 0x07, KEY_7 },
+       { 0x08, KEY_8 },
+       { 0x09, KEY_9 },
+
+       { 0x0b, KEY_CHANNEL },          /* channel / program (japan: 11) */
+       { 0x0c, KEY_POWER },            /* standby */
+       { 0x0d, KEY_MUTE },             /* mute / demute */
+       { 0x0f, KEY_TV },               /* display */
+       { 0x10, KEY_VOLUMEUP },
+       { 0x11, KEY_VOLUMEDOWN },
+       { 0x12, KEY_BRIGHTNESSUP },
+       { 0x13, KEY_BRIGHTNESSDOWN },
+       { 0x1e, KEY_SEARCH },           /* search + */
+       { 0x20, KEY_CHANNELUP },        /* channel / program + */
+       { 0x21, KEY_CHANNELDOWN },      /* channel / program - */
+       { 0x22, KEY_CHANNEL },          /* alt / channel */
+       { 0x23, KEY_LANGUAGE },         /* 1st / 2nd language */
+       { 0x26, KEY_SLEEP },            /* sleeptimer */
+       { 0x2e, KEY_MENU },             /* 2nd controls (USA: menu) */
+       { 0x30, KEY_PAUSE },
+       { 0x32, KEY_REWIND },
+       { 0x33, KEY_GOTO },
+       { 0x35, KEY_PLAY },
+       { 0x36, KEY_STOP },
+       { 0x37, KEY_RECORD },           /* recording */
+       { 0x3c, KEY_TEXT },             /* teletext submode (Japan: 12) */
+       { 0x3d, KEY_SUSPEND },          /* system standby */
+
+};
+
+static struct rc_keymap rc5_tv_map = {
+       .map = {
+               .scan    = rc5_tv,
+               .size    = ARRAY_SIZE(rc5_tv),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_RC5_TV,
+       }
+};
+
+static int __init init_rc_map_rc5_tv(void)
+{
+       return ir_register_map(&rc5_tv_map);
+}
+
+static void __exit exit_rc_map_rc5_tv(void)
+{
+       ir_unregister_map(&rc5_tv_map);
+}
+
+module_init(init_rc_map_rc5_tv)
+module_exit(exit_rc_map_rc5_tv)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c b/drivers/media/IR/keymaps/rc-real-audio-220-32-keys.c
new file mode 100644 (file)
index 0000000..ab1a6d2
--- /dev/null
@@ -0,0 +1,78 @@
+/* real-audio-220-32-keys.h - Keytable for real_audio_220_32_keys Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Zogis Real Audio 220 - 32 keys IR */
+
+static struct ir_scancode real_audio_220_32_keys[] = {
+       { 0x1c, KEY_RADIO},
+       { 0x12, KEY_POWER2},
+
+       { 0x01, KEY_1},
+       { 0x02, KEY_2},
+       { 0x03, KEY_3},
+       { 0x04, KEY_4},
+       { 0x05, KEY_5},
+       { 0x06, KEY_6},
+       { 0x07, KEY_7},
+       { 0x08, KEY_8},
+       { 0x09, KEY_9},
+       { 0x00, KEY_0},
+
+       { 0x0c, KEY_VOLUMEUP},
+       { 0x18, KEY_VOLUMEDOWN},
+       { 0x0b, KEY_CHANNELUP},
+       { 0x15, KEY_CHANNELDOWN},
+       { 0x16, KEY_ENTER},
+
+       { 0x11, KEY_LIST},              /* Source */
+       { 0x0d, KEY_AUDIO},             /* stereo */
+
+       { 0x0f, KEY_PREVIOUS},          /* Prev */
+       { 0x1b, KEY_TIME},              /* Timeshift */
+       { 0x1a, KEY_NEXT},              /* Next */
+
+       { 0x0e, KEY_STOP},
+       { 0x1f, KEY_PLAY},
+       { 0x1e, KEY_PLAYPAUSE},         /* Pause */
+
+       { 0x1d, KEY_RECORD},
+       { 0x13, KEY_MUTE},
+       { 0x19, KEY_CAMERA},            /* Snapshot */
+
+};
+
+static struct rc_keymap real_audio_220_32_keys_map = {
+       .map = {
+               .scan    = real_audio_220_32_keys,
+               .size    = ARRAY_SIZE(real_audio_220_32_keys),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_REAL_AUDIO_220_32_KEYS,
+       }
+};
+
+static int __init init_rc_map_real_audio_220_32_keys(void)
+{
+       return ir_register_map(&real_audio_220_32_keys_map);
+}
+
+static void __exit exit_rc_map_real_audio_220_32_keys(void)
+{
+       ir_unregister_map(&real_audio_220_32_keys_map);
+}
+
+module_init(init_rc_map_real_audio_220_32_keys)
+module_exit(exit_rc_map_real_audio_220_32_keys)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-tbs-nec.c b/drivers/media/IR/keymaps/rc-tbs-nec.c
new file mode 100644 (file)
index 0000000..3309631
--- /dev/null
@@ -0,0 +1,73 @@
+/* tbs-nec.h - Keytable for tbs_nec Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode tbs_nec[] = {
+       { 0x04, KEY_POWER2},    /*power*/
+       { 0x14, KEY_MUTE},      /*mute*/
+       { 0x07, KEY_1},
+       { 0x06, KEY_2},
+       { 0x05, KEY_3},
+       { 0x0b, KEY_4},
+       { 0x0a, KEY_5},
+       { 0x09, KEY_6},
+       { 0x0f, KEY_7},
+       { 0x0e, KEY_8},
+       { 0x0d, KEY_9},
+       { 0x12, KEY_0},
+       { 0x16, KEY_CHANNELUP}, /*ch+*/
+       { 0x11, KEY_CHANNELDOWN},/*ch-*/
+       { 0x13, KEY_VOLUMEUP},  /*vol+*/
+       { 0x0c, KEY_VOLUMEDOWN},/*vol-*/
+       { 0x03, KEY_RECORD},    /*rec*/
+       { 0x18, KEY_PAUSE},     /*pause*/
+       { 0x19, KEY_OK},        /*ok*/
+       { 0x1a, KEY_CAMERA},    /* snapshot */
+       { 0x01, KEY_UP},
+       { 0x10, KEY_LEFT},
+       { 0x02, KEY_RIGHT},
+       { 0x08, KEY_DOWN},
+       { 0x15, KEY_FAVORITES},
+       { 0x17, KEY_SUBTITLE},
+       { 0x1d, KEY_ZOOM},
+       { 0x1f, KEY_EXIT},
+       { 0x1e, KEY_MENU},
+       { 0x1c, KEY_EPG},
+       { 0x00, KEY_PREVIOUS},
+       { 0x1b, KEY_MODE},
+};
+
+static struct rc_keymap tbs_nec_map = {
+       .map = {
+               .scan    = tbs_nec,
+               .size    = ARRAY_SIZE(tbs_nec),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_TBS_NEC,
+       }
+};
+
+static int __init init_rc_map_tbs_nec(void)
+{
+       return ir_register_map(&tbs_nec_map);
+}
+
+static void __exit exit_rc_map_tbs_nec(void)
+{
+       ir_unregister_map(&tbs_nec_map);
+}
+
+module_init(init_rc_map_tbs_nec)
+module_exit(exit_rc_map_tbs_nec)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c b/drivers/media/IR/keymaps/rc-terratec-cinergy-xs.c
new file mode 100644 (file)
index 0000000..5326a0b
--- /dev/null
@@ -0,0 +1,92 @@
+/* terratec-cinergy-xs.h - Keytable for terratec_cinergy_xs Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Terratec Cinergy Hybrid T USB XS
+   Devin Heitmueller <dheitmueller@linuxtv.org>
+ */
+
+static struct ir_scancode terratec_cinergy_xs[] = {
+       { 0x41, KEY_HOME},
+       { 0x01, KEY_POWER},
+       { 0x42, KEY_MENU},
+       { 0x02, KEY_1},
+       { 0x03, KEY_2},
+       { 0x04, KEY_3},
+       { 0x43, KEY_SUBTITLE},
+       { 0x05, KEY_4},
+       { 0x06, KEY_5},
+       { 0x07, KEY_6},
+       { 0x44, KEY_TEXT},
+       { 0x08, KEY_7},
+       { 0x09, KEY_8},
+       { 0x0a, KEY_9},
+       { 0x45, KEY_DELETE},
+       { 0x0b, KEY_TUNER},
+       { 0x0c, KEY_0},
+       { 0x0d, KEY_MODE},
+       { 0x46, KEY_TV},
+       { 0x47, KEY_DVD},
+       { 0x49, KEY_VIDEO},
+       { 0x4b, KEY_AUX},
+       { 0x10, KEY_UP},
+       { 0x11, KEY_LEFT},
+       { 0x12, KEY_OK},
+       { 0x13, KEY_RIGHT},
+       { 0x14, KEY_DOWN},
+       { 0x0f, KEY_EPG},
+       { 0x16, KEY_INFO},
+       { 0x4d, KEY_BACKSPACE},
+       { 0x1c, KEY_VOLUMEUP},
+       { 0x4c, KEY_PLAY},
+       { 0x1b, KEY_CHANNELUP},
+       { 0x1e, KEY_VOLUMEDOWN},
+       { 0x1d, KEY_MUTE},
+       { 0x1f, KEY_CHANNELDOWN},
+       { 0x17, KEY_RED},
+       { 0x18, KEY_GREEN},
+       { 0x19, KEY_YELLOW},
+       { 0x1a, KEY_BLUE},
+       { 0x58, KEY_RECORD},
+       { 0x48, KEY_STOP},
+       { 0x40, KEY_PAUSE},
+       { 0x54, KEY_LAST},
+       { 0x4e, KEY_REWIND},
+       { 0x4f, KEY_FASTFORWARD},
+       { 0x5c, KEY_NEXT},
+};
+
+static struct rc_keymap terratec_cinergy_xs_map = {
+       .map = {
+               .scan    = terratec_cinergy_xs,
+               .size    = ARRAY_SIZE(terratec_cinergy_xs),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_TERRATEC_CINERGY_XS,
+       }
+};
+
+static int __init init_rc_map_terratec_cinergy_xs(void)
+{
+       return ir_register_map(&terratec_cinergy_xs_map);
+}
+
+static void __exit exit_rc_map_terratec_cinergy_xs(void)
+{
+       ir_unregister_map(&terratec_cinergy_xs_map);
+}
+
+module_init(init_rc_map_terratec_cinergy_xs)
+module_exit(exit_rc_map_terratec_cinergy_xs)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-tevii-nec.c b/drivers/media/IR/keymaps/rc-tevii-nec.c
new file mode 100644 (file)
index 0000000..e30d411
--- /dev/null
@@ -0,0 +1,88 @@
+/* tevii-nec.h - Keytable for tevii_nec Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode tevii_nec[] = {
+       { 0x0a, KEY_POWER2},
+       { 0x0c, KEY_MUTE},
+       { 0x11, KEY_1},
+       { 0x12, KEY_2},
+       { 0x13, KEY_3},
+       { 0x14, KEY_4},
+       { 0x15, KEY_5},
+       { 0x16, KEY_6},
+       { 0x17, KEY_7},
+       { 0x18, KEY_8},
+       { 0x19, KEY_9},
+       { 0x10, KEY_0},
+       { 0x1c, KEY_MENU},
+       { 0x0f, KEY_VOLUMEDOWN},
+       { 0x1a, KEY_LAST},
+       { 0x0e, KEY_OPEN},
+       { 0x04, KEY_RECORD},
+       { 0x09, KEY_VOLUMEUP},
+       { 0x08, KEY_CHANNELUP},
+       { 0x07, KEY_PVR},
+       { 0x0b, KEY_TIME},
+       { 0x02, KEY_RIGHT},
+       { 0x03, KEY_LEFT},
+       { 0x00, KEY_UP},
+       { 0x1f, KEY_OK},
+       { 0x01, KEY_DOWN},
+       { 0x05, KEY_TUNER},
+       { 0x06, KEY_CHANNELDOWN},
+       { 0x40, KEY_PLAYPAUSE},
+       { 0x1e, KEY_REWIND},
+       { 0x1b, KEY_FAVORITES},
+       { 0x1d, KEY_BACK},
+       { 0x4d, KEY_FASTFORWARD},
+       { 0x44, KEY_EPG},
+       { 0x4c, KEY_INFO},
+       { 0x41, KEY_AB},
+       { 0x43, KEY_AUDIO},
+       { 0x45, KEY_SUBTITLE},
+       { 0x4a, KEY_LIST},
+       { 0x46, KEY_F1},
+       { 0x47, KEY_F2},
+       { 0x5e, KEY_F3},
+       { 0x5c, KEY_F4},
+       { 0x52, KEY_F5},
+       { 0x5a, KEY_F6},
+       { 0x56, KEY_MODE},
+       { 0x58, KEY_SWITCHVIDEOMODE},
+};
+
+static struct rc_keymap tevii_nec_map = {
+       .map = {
+               .scan    = tevii_nec,
+               .size    = ARRAY_SIZE(tevii_nec),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_TEVII_NEC,
+       }
+};
+
+static int __init init_rc_map_tevii_nec(void)
+{
+       return ir_register_map(&tevii_nec_map);
+}
+
+static void __exit exit_rc_map_tevii_nec(void)
+{
+       ir_unregister_map(&tevii_nec_map);
+}
+
+module_init(init_rc_map_tevii_nec)
+module_exit(exit_rc_map_tevii_nec)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-tt-1500.c b/drivers/media/IR/keymaps/rc-tt-1500.c
new file mode 100644 (file)
index 0000000..bc88de0
--- /dev/null
@@ -0,0 +1,82 @@
+/* tt-1500.h - Keytable for tt_1500 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* for the Technotrend 1500 bundled remotes (grey and black): */
+
+static struct ir_scancode tt_1500[] = {
+       { 0x01, KEY_POWER },
+       { 0x02, KEY_SHUFFLE },          /* ? double-arrow key */
+       { 0x03, KEY_1 },
+       { 0x04, KEY_2 },
+       { 0x05, KEY_3 },
+       { 0x06, KEY_4 },
+       { 0x07, KEY_5 },
+       { 0x08, KEY_6 },
+       { 0x09, KEY_7 },
+       { 0x0a, KEY_8 },
+       { 0x0b, KEY_9 },
+       { 0x0c, KEY_0 },
+       { 0x0d, KEY_UP },
+       { 0x0e, KEY_LEFT },
+       { 0x0f, KEY_OK },
+       { 0x10, KEY_RIGHT },
+       { 0x11, KEY_DOWN },
+       { 0x12, KEY_INFO },
+       { 0x13, KEY_EXIT },
+       { 0x14, KEY_RED },
+       { 0x15, KEY_GREEN },
+       { 0x16, KEY_YELLOW },
+       { 0x17, KEY_BLUE },
+       { 0x18, KEY_MUTE },
+       { 0x19, KEY_TEXT },
+       { 0x1a, KEY_MODE },             /* ? TV/Radio */
+       { 0x21, KEY_OPTION },
+       { 0x22, KEY_EPG },
+       { 0x23, KEY_CHANNELUP },
+       { 0x24, KEY_CHANNELDOWN },
+       { 0x25, KEY_VOLUMEUP },
+       { 0x26, KEY_VOLUMEDOWN },
+       { 0x27, KEY_SETUP },
+       { 0x3a, KEY_RECORD },           /* these keys are only in the black remote */
+       { 0x3b, KEY_PLAY },
+       { 0x3c, KEY_STOP },
+       { 0x3d, KEY_REWIND },
+       { 0x3e, KEY_PAUSE },
+       { 0x3f, KEY_FORWARD },
+};
+
+static struct rc_keymap tt_1500_map = {
+       .map = {
+               .scan    = tt_1500,
+               .size    = ARRAY_SIZE(tt_1500),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_TT_1500,
+       }
+};
+
+static int __init init_rc_map_tt_1500(void)
+{
+       return ir_register_map(&tt_1500_map);
+}
+
+static void __exit exit_rc_map_tt_1500(void)
+{
+       ir_unregister_map(&tt_1500_map);
+}
+
+module_init(init_rc_map_tt_1500)
+module_exit(exit_rc_map_tt_1500)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-videomate-s350.c b/drivers/media/IR/keymaps/rc-videomate-s350.c
new file mode 100644 (file)
index 0000000..4df7fcd
--- /dev/null
@@ -0,0 +1,85 @@
+/* videomate-s350.h - Keytable for videomate_s350 Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode videomate_s350[] = {
+       { 0x00, KEY_TV},
+       { 0x01, KEY_DVD},
+       { 0x04, KEY_RECORD},
+       { 0x05, KEY_VIDEO},     /* TV/Video */
+       { 0x07, KEY_STOP},
+       { 0x08, KEY_PLAYPAUSE},
+       { 0x0a, KEY_REWIND},
+       { 0x0f, KEY_FASTFORWARD},
+       { 0x10, KEY_CHANNELUP},
+       { 0x12, KEY_VOLUMEUP},
+       { 0x13, KEY_CHANNELDOWN},
+       { 0x14, KEY_MUTE},
+       { 0x15, KEY_VOLUMEDOWN},
+       { 0x16, KEY_1},
+       { 0x17, KEY_2},
+       { 0x18, KEY_3},
+       { 0x19, KEY_4},
+       { 0x1a, KEY_5},
+       { 0x1b, KEY_6},
+       { 0x1c, KEY_7},
+       { 0x1d, KEY_8},
+       { 0x1e, KEY_9},
+       { 0x1f, KEY_0},
+       { 0x21, KEY_SLEEP},
+       { 0x24, KEY_ZOOM},
+       { 0x25, KEY_LAST},      /* Recall */
+       { 0x26, KEY_SUBTITLE},  /* CC */
+       { 0x27, KEY_LANGUAGE},  /* MTS */
+       { 0x29, KEY_CHANNEL},   /* SURF */
+       { 0x2b, KEY_A},
+       { 0x2c, KEY_B},
+       { 0x2f, KEY_CAMERA},    /* Snapshot */
+       { 0x23, KEY_RADIO},
+       { 0x02, KEY_PREVIOUSSONG},
+       { 0x06, KEY_NEXTSONG},
+       { 0x03, KEY_EPG},
+       { 0x09, KEY_SETUP},
+       { 0x22, KEY_BACKSPACE},
+       { 0x0c, KEY_UP},
+       { 0x0e, KEY_DOWN},
+       { 0x0b, KEY_LEFT},
+       { 0x0d, KEY_RIGHT},
+       { 0x11, KEY_ENTER},
+       { 0x20, KEY_TEXT},
+};
+
+static struct rc_keymap videomate_s350_map = {
+       .map = {
+               .scan    = videomate_s350,
+               .size    = ARRAY_SIZE(videomate_s350),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_VIDEOMATE_S350,
+       }
+};
+
+static int __init init_rc_map_videomate_s350(void)
+{
+       return ir_register_map(&videomate_s350_map);
+}
+
+static void __exit exit_rc_map_videomate_s350(void)
+{
+       ir_unregister_map(&videomate_s350_map);
+}
+
+module_init(init_rc_map_videomate_s350)
+module_exit(exit_rc_map_videomate_s350)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-videomate-tv-pvr.c b/drivers/media/IR/keymaps/rc-videomate-tv-pvr.c
new file mode 100644 (file)
index 0000000..776b0a6
--- /dev/null
@@ -0,0 +1,87 @@
+/* videomate-tv-pvr.h - Keytable for videomate_tv_pvr Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+static struct ir_scancode videomate_tv_pvr[] = {
+       { 0x14, KEY_MUTE },
+       { 0x24, KEY_ZOOM },
+
+       { 0x01, KEY_DVD },
+       { 0x23, KEY_RADIO },
+       { 0x00, KEY_TV },
+
+       { 0x0a, KEY_REWIND },
+       { 0x08, KEY_PLAYPAUSE },
+       { 0x0f, KEY_FORWARD },
+
+       { 0x02, KEY_PREVIOUS },
+       { 0x07, KEY_STOP },
+       { 0x06, KEY_NEXT },
+
+       { 0x0c, KEY_UP },
+       { 0x0e, KEY_DOWN },
+       { 0x0b, KEY_LEFT },
+       { 0x0d, KEY_RIGHT },
+       { 0x11, KEY_OK },
+
+       { 0x03, KEY_MENU },
+       { 0x09, KEY_SETUP },
+       { 0x05, KEY_VIDEO },
+       { 0x22, KEY_CHANNEL },
+
+       { 0x12, KEY_VOLUMEUP },
+       { 0x15, KEY_VOLUMEDOWN },
+       { 0x10, KEY_CHANNELUP },
+       { 0x13, KEY_CHANNELDOWN },
+
+       { 0x04, KEY_RECORD },
+
+       { 0x16, KEY_1 },
+       { 0x17, KEY_2 },
+       { 0x18, KEY_3 },
+       { 0x19, KEY_4 },
+       { 0x1a, KEY_5 },
+       { 0x1b, KEY_6 },
+       { 0x1c, KEY_7 },
+       { 0x1d, KEY_8 },
+       { 0x1e, KEY_9 },
+       { 0x1f, KEY_0 },
+
+       { 0x20, KEY_LANGUAGE },
+       { 0x21, KEY_SLEEP },
+};
+
+static struct rc_keymap videomate_tv_pvr_map = {
+       .map = {
+               .scan    = videomate_tv_pvr,
+               .size    = ARRAY_SIZE(videomate_tv_pvr),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_VIDEOMATE_TV_PVR,
+       }
+};
+
+static int __init init_rc_map_videomate_tv_pvr(void)
+{
+       return ir_register_map(&videomate_tv_pvr_map);
+}
+
+static void __exit exit_rc_map_videomate_tv_pvr(void)
+{
+       ir_unregister_map(&videomate_tv_pvr_map);
+}
+
+module_init(init_rc_map_videomate_tv_pvr)
+module_exit(exit_rc_map_videomate_tv_pvr)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c b/drivers/media/IR/keymaps/rc-winfast-usbii-deluxe.c
new file mode 100644 (file)
index 0000000..9d2d550
--- /dev/null
@@ -0,0 +1,82 @@
+/* winfast-usbii-deluxe.h - Keytable for winfast_usbii_deluxe Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Leadtek Winfast TV USB II Deluxe remote
+   Magnus Alm <magnus.alm@gmail.com>
+ */
+
+static struct ir_scancode winfast_usbii_deluxe[] = {
+       { 0x62, KEY_0},
+       { 0x75, KEY_1},
+       { 0x76, KEY_2},
+       { 0x77, KEY_3},
+       { 0x79, KEY_4},
+       { 0x7a, KEY_5},
+       { 0x7b, KEY_6},
+       { 0x7d, KEY_7},
+       { 0x7e, KEY_8},
+       { 0x7f, KEY_9},
+
+       { 0x38, KEY_CAMERA},            /* SNAPSHOT */
+       { 0x37, KEY_RECORD},            /* RECORD */
+       { 0x35, KEY_TIME},              /* TIMESHIFT */
+
+       { 0x74, KEY_VOLUMEUP},          /* VOLUMEUP */
+       { 0x78, KEY_VOLUMEDOWN},        /* VOLUMEDOWN */
+       { 0x64, KEY_MUTE},              /* MUTE */
+
+       { 0x21, KEY_CHANNEL},           /* SURF */
+       { 0x7c, KEY_CHANNELUP},         /* CHANNELUP */
+       { 0x60, KEY_CHANNELDOWN},       /* CHANNELDOWN */
+       { 0x61, KEY_LAST},              /* LAST CHANNEL (RECALL) */
+
+       { 0x72, KEY_VIDEO},             /* INPUT MODES (TV/FM) */
+
+       { 0x70, KEY_POWER2},            /* TV ON/OFF */
+
+       { 0x39, KEY_CYCLEWINDOWS},      /* MINIMIZE (BOSS) */
+       { 0x3a, KEY_NEW},               /* PIP */
+       { 0x73, KEY_ZOOM},              /* FULLSECREEN */
+
+       { 0x66, KEY_INFO},              /* OSD (DISPLAY) */
+
+       { 0x31, KEY_DOT},               /* '.' */
+       { 0x63, KEY_ENTER},             /* ENTER */
+
+};
+
+static struct rc_keymap winfast_usbii_deluxe_map = {
+       .map = {
+               .scan    = winfast_usbii_deluxe,
+               .size    = ARRAY_SIZE(winfast_usbii_deluxe),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_WINFAST_USBII_DELUXE,
+       }
+};
+
+static int __init init_rc_map_winfast_usbii_deluxe(void)
+{
+       return ir_register_map(&winfast_usbii_deluxe_map);
+}
+
+static void __exit exit_rc_map_winfast_usbii_deluxe(void)
+{
+       ir_unregister_map(&winfast_usbii_deluxe_map);
+}
+
+module_init(init_rc_map_winfast_usbii_deluxe)
+module_exit(exit_rc_map_winfast_usbii_deluxe)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/keymaps/rc-winfast.c b/drivers/media/IR/keymaps/rc-winfast.c
new file mode 100644 (file)
index 0000000..0e90a3b
--- /dev/null
@@ -0,0 +1,102 @@
+/* winfast.h - Keytable for winfast Remote Controller
+ *
+ * keymap imported from ir-keymaps.c
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <media/rc-map.h>
+
+/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
+
+static struct ir_scancode winfast[] = {
+       /* Keys 0 to 9 */
+       { 0x12, KEY_0 },
+       { 0x05, KEY_1 },
+       { 0x06, KEY_2 },
+       { 0x07, KEY_3 },
+       { 0x09, KEY_4 },
+       { 0x0a, KEY_5 },
+       { 0x0b, KEY_6 },
+       { 0x0d, KEY_7 },
+       { 0x0e, KEY_8 },
+       { 0x0f, KEY_9 },
+
+       { 0x00, KEY_POWER },
+       { 0x1b, KEY_AUDIO },            /* Audio Source */
+       { 0x02, KEY_TUNER },            /* TV/FM, not on Y0400052 */
+       { 0x1e, KEY_VIDEO },            /* Video Source */
+       { 0x16, KEY_INFO },             /* Display information */
+       { 0x04, KEY_VOLUMEUP },
+       { 0x08, KEY_VOLUMEDOWN },
+       { 0x0c, KEY_CHANNELUP },
+       { 0x10, KEY_CHANNELDOWN },
+       { 0x03, KEY_ZOOM },             /* fullscreen */
+       { 0x1f, KEY_TEXT },             /* closed caption/teletext */
+       { 0x20, KEY_SLEEP },
+       { 0x29, KEY_CLEAR },            /* boss key */
+       { 0x14, KEY_MUTE },
+       { 0x2b, KEY_RED },
+       { 0x2c, KEY_GREEN },
+       { 0x2d, KEY_YELLOW },
+       { 0x2e, KEY_BLUE },
+       { 0x18, KEY_KPPLUS },           /* fine tune + , not on Y040052 */
+       { 0x19, KEY_KPMINUS },          /* fine tune - , not on Y040052 */
+       { 0x2a, KEY_MEDIA },            /* PIP (Picture in picture */
+       { 0x21, KEY_DOT },
+       { 0x13, KEY_ENTER },
+       { 0x11, KEY_LAST },             /* Recall (last channel */
+       { 0x22, KEY_PREVIOUS },
+       { 0x23, KEY_PLAYPAUSE },
+       { 0x24, KEY_NEXT },
+       { 0x25, KEY_TIME },             /* Time Shifting */
+       { 0x26, KEY_STOP },
+       { 0x27, KEY_RECORD },
+       { 0x28, KEY_SAVE },             /* Screenshot */
+       { 0x2f, KEY_MENU },
+       { 0x30, KEY_CANCEL },
+       { 0x31, KEY_CHANNEL },          /* Channel Surf */
+       { 0x32, KEY_SUBTITLE },
+       { 0x33, KEY_LANGUAGE },
+       { 0x34, KEY_REWIND },
+       { 0x35, KEY_FASTFORWARD },
+       { 0x36, KEY_TV },
+       { 0x37, KEY_RADIO },            /* FM */
+       { 0x38, KEY_DVD },
+
+       { 0x1a, KEY_MODE},              /* change to MCE mode on Y04G0051 */
+       { 0x3e, KEY_F21 },              /* MCE +VOL, on Y04G0033 */
+       { 0x3a, KEY_F22 },              /* MCE -VOL, on Y04G0033 */
+       { 0x3b, KEY_F23 },              /* MCE +CH,  on Y04G0033 */
+       { 0x3f, KEY_F24 }               /* MCE -CH,  on Y04G0033 */
+};
+
+static struct rc_keymap winfast_map = {
+       .map = {
+               .scan    = winfast,
+               .size    = ARRAY_SIZE(winfast),
+               .ir_type = IR_TYPE_UNKNOWN,     /* Legacy IR type */
+               .name    = RC_MAP_WINFAST,
+       }
+};
+
+static int __init init_rc_map_winfast(void)
+{
+       return ir_register_map(&winfast_map);
+}
+
+static void __exit exit_rc_map_winfast(void)
+{
+       ir_unregister_map(&winfast_map);
+}
+
+module_init(init_rc_map_winfast)
+module_exit(exit_rc_map_winfast)
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
diff --git a/drivers/media/IR/rc-map.c b/drivers/media/IR/rc-map.c
new file mode 100644 (file)
index 0000000..46a8f15
--- /dev/null
@@ -0,0 +1,84 @@
+/* ir-raw-event.c - handle IR Pulse/Space event
+ *
+ * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
+ *
+ *  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.
+ */
+
+#include <media/ir-core.h>
+#include <linux/spinlock.h>
+#include <linux/delay.h>
+
+/* Used to handle IR raw handler extensions */
+static LIST_HEAD(rc_map_list);
+static DEFINE_SPINLOCK(rc_map_lock);
+
+static struct rc_keymap *seek_rc_map(const char *name)
+{
+       struct rc_keymap *map = NULL;
+
+       spin_lock(&rc_map_lock);
+       list_for_each_entry(map, &rc_map_list, list) {
+               if (!strcmp(name, map->map.name)) {
+                       spin_unlock(&rc_map_lock);
+                       return map;
+               }
+       }
+       spin_unlock(&rc_map_lock);
+
+       return NULL;
+}
+
+struct ir_scancode_table *get_rc_map(const char *name)
+{
+
+       struct rc_keymap *map;
+
+       map = seek_rc_map(name);
+#ifdef MODULE
+       if (!map) {
+               int rc = request_module(name);
+               if (rc < 0) {
+                       printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
+                       return NULL;
+               }
+               msleep(20);     /* Give some time for IR to register */
+
+               map = seek_rc_map(name);
+       }
+#endif
+       if (!map) {
+               printk(KERN_ERR "IR keymap %s not found\n", name);
+               return NULL;
+       }
+
+       printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
+
+       return &map->map;
+}
+EXPORT_SYMBOL_GPL(get_rc_map);
+
+int ir_register_map(struct rc_keymap *map)
+{
+       spin_lock(&rc_map_lock);
+       list_add_tail(&map->list, &rc_map_list);
+       spin_unlock(&rc_map_lock);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ir_register_map);
+
+void ir_unregister_map(struct rc_keymap *map)
+{
+       spin_lock(&rc_map_lock);
+       list_del(&map->list);
+       spin_unlock(&rc_map_lock);
+}
+EXPORT_SYMBOL_GPL(ir_unregister_map);
+
index 96d6170..b6ce528 100644 (file)
@@ -100,6 +100,8 @@ struct xc2028_data {
        if (size != _rc)                                                \
                tuner_info("i2c output error: rc = %d (should be %d)\n",\
                           _rc, (int)size);                             \
+       if (priv->ctrl.msleep)                                          \
+               msleep(priv->ctrl.msleep);                              \
        _rc;                                                            \
 })
 
@@ -119,6 +121,8 @@ struct xc2028_data {
        if (isize != _rc)                                               \
                tuner_err("i2c input error: rc = %d (should be %d)\n",  \
                           _rc, (int)isize);                            \
+       if (priv->ctrl.msleep)                                          \
+               msleep(priv->ctrl.msleep);                              \
        _rc;                                                            \
 })
 
@@ -129,8 +133,8 @@ struct xc2028_data {
                        (_rc = tuner_i2c_xfer_send(&priv->i2c_props,    \
                                                _val, sizeof(_val)))) { \
                tuner_err("Error on line %d: %d\n", __LINE__, _rc);     \
-       } else                                                          \
-               msleep(10);                                             \
+       } else if (priv->ctrl.msleep)                                   \
+               msleep(priv->ctrl.msleep);                              \
        _rc;                                                            \
 })
 
@@ -809,10 +813,20 @@ check_device:
                  hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
                  (version & 0xf0) >> 4, version & 0xf);
 
+
+       if (priv->ctrl.read_not_reliable)
+               goto read_not_reliable;
+
        /* Check firmware version against what we downloaded. */
        if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
-               tuner_err("Incorrect readback of firmware version.\n");
-               goto fail;
+               if (!priv->ctrl.read_not_reliable) {
+                       tuner_err("Incorrect readback of firmware version.\n");
+                       goto fail;
+               } else {
+                       tuner_err("Returned an incorrect version. However, "
+                                 "read is not reliable enough. Ignoring it.\n");
+                       hwmodel = 3028;
+               }
        }
 
        /* Check that the tuner hardware model remains consistent over time. */
@@ -826,6 +840,7 @@ check_device:
                goto fail;
        }
 
+read_not_reliable:
        memcpy(&priv->cur_fw, &new_fw, sizeof(priv->cur_fw));
 
        /*
@@ -996,6 +1011,8 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
           The reset CLK is needed only with tm6000.
           Driver should work fine even if this fails.
         */
+       if (priv->ctrl.msleep)
+               msleep(priv->ctrl.msleep);
        do_tuner_callback(fe, XC2028_RESET_CLK, 1);
 
        msleep(10);
index a90c35d..9778c96 100644 (file)
@@ -33,12 +33,14 @@ enum firmware_type {
 struct xc2028_ctrl {
        char                    *fname;
        int                     max_len;
+       int                     msleep;
        unsigned int            scode_table;
        unsigned int            mts   :1;
        unsigned int            input1:1;
        unsigned int            vhfbw7:1;
        unsigned int            uhfbw8:1;
        unsigned int            disable_power_mgmt:1;
+       unsigned int            read_not_reliable:1;
        unsigned int            demod;
        enum firmware_type      type:2;
 };
index 8b0cde3..248a2a9 100644 (file)
@@ -930,7 +930,6 @@ static int dst_fw_ver(struct dst_state *state)
                dprintk(verbose, DST_INFO, 1, "Unsupported Command");
                return -1;
        }
-       memset(&state->fw_version, '\0', 8);
        memcpy(&state->fw_version, &state->rxbuffer, 8);
        dprintk(verbose, DST_ERROR, 1, "Firmware Ver = %x.%x Build = %02x, on %x:%x, %x-%x-20%02x",
                state->fw_version[0] >> 4, state->fw_version[0] & 0x0f,
@@ -1053,7 +1052,6 @@ static int dst_get_tuner_info(struct dst_state *state)
                        goto force;
                }
        }
-       memset(&state->board_info, '\0', 8);
        memcpy(&state->board_info, &state->rxbuffer, 8);
        if (state->type_flags & DST_TYPE_HAS_MULTI_FE) {
                dprintk(verbose, DST_ERROR, 1, "DST type has TS=188");
index b6d4696..b762e56 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/input.h>
 #include <linux/slab.h>
-#include <media/ir-common.h>
+#include <media/ir-core.h>
 
 #include "demux.h"
 #include "dmxdev.h"
@@ -46,6 +46,8 @@
 #include "z0194a.h"
 #include "ds3000.h"
 
+#define MODULE_NAME "dm1105"
+
 #define UNSET (-1U)
 
 #define DM1105_BOARD_NOAUTO            UNSET
@@ -265,7 +267,6 @@ static void dm1105_card_list(struct pci_dev *pci)
 /* infrared remote control */
 struct infrared {
        struct input_dev        *input_dev;
-       struct ir_input_state   ir;
        char                    input_phys[32];
        struct work_struct      work;
        u32                     ir_command;
@@ -531,8 +532,7 @@ static void dm1105_emit_key(struct work_struct *work)
 
        data = (ircom >> 8) & 0x7f;
 
-       ir_input_keydown(ir->input_dev, &ir->ir, data);
-       ir_input_nokey(ir->input_dev, &ir->ir);
+       ir_keydown(ir->input_dev, data, 0);
 }
 
 /* work handler */
@@ -594,8 +594,7 @@ static irqreturn_t dm1105_irq(int irq, void *dev_id)
 int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
 {
        struct input_dev *input_dev;
-       struct ir_scancode_table *ir_codes = &ir_codes_dm1105_nec_table;
-       u64 ir_type = IR_TYPE_OTHER;
+       char *ir_codes = NULL;
        int err = -ENOMEM;
 
        input_dev = input_allocate_device();
@@ -606,12 +605,6 @@ int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
        snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
                "pci-%s/ir0", pci_name(dm1105->pdev));
 
-       err = ir_input_init(input_dev, &dm1105->ir.ir, ir_type);
-       if (err < 0) {
-               input_free_device(input_dev);
-               return err;
-       }
-
        input_dev->name = "DVB on-card IR receiver";
        input_dev->phys = dm1105->ir.input_phys;
        input_dev->id.bustype = BUS_PCI;
@@ -628,9 +621,13 @@ int __devinit dm1105_ir_init(struct dm1105_dev *dm1105)
 
        INIT_WORK(&dm1105->ir.work, dm1105_emit_key);
 
-       err = ir_input_register(input_dev, ir_codes, NULL);
+       err = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME);
+       if (err < 0) {
+               input_free_device(input_dev);
+               return err;
+       }
 
-       return err;
+       return 0;
 }
 
 void __devexit dm1105_ir_exit(struct dm1105_dev *dm1105)
index 67f189b..977ddba 100644 (file)
@@ -426,7 +426,7 @@ static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
                };
        };
 
-       if (demux->cnt_storage) {
+       if (demux->cnt_storage && dvb_demux_tscheck) {
                /* check pkt counter */
                if (pid < MAX_PID) {
                        if (buf[1] & 0x80)
@@ -1248,12 +1248,9 @@ int dvb_dmx_init(struct dvb_demux *dvbdemux)
                dvbdemux->feed[i].index = i;
        }
 
-       if (dvb_demux_tscheck) {
-               dvbdemux->cnt_storage = vmalloc(MAX_PID + 1);
-
-               if (!dvbdemux->cnt_storage)
-                       printk(KERN_WARNING "Couldn't allocate memory for TS/TEI check. Disabling it\n");
-       }
+       dvbdemux->cnt_storage = vmalloc(MAX_PID + 1);
+       if (!dvbdemux->cnt_storage)
+               printk(KERN_WARNING "Couldn't allocate memory for TS/TEI check. Disabling it\n");
 
        INIT_LIST_HEAD(&dvbdemux->frontend_list);
 
index 55ea260..6932def 100644 (file)
@@ -95,6 +95,10 @@ MODULE_PARM_DESC(dvb_mfe_wait_time, "Wait up to <mfe_wait_time> seconds on open(
  * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
  */
 
+#define DVB_FE_NO_EXIT 0
+#define DVB_FE_NORMAL_EXIT     1
+#define DVB_FE_DEVICE_REMOVED  2
+
 static DEFINE_MUTEX(frontend_mutex);
 
 struct dvb_frontend_private {
@@ -497,7 +501,7 @@ static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
 {
        struct dvb_frontend_private *fepriv = fe->frontend_priv;
 
-       if (fepriv->exit)
+       if (fepriv->exit != DVB_FE_NO_EXIT)
                return 1;
 
        if (fepriv->dvbdev->writers == 1)
@@ -559,7 +563,7 @@ restart:
 
                if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
                        /* got signal or quitting */
-                       fepriv->exit = 1;
+                       fepriv->exit = DVB_FE_NORMAL_EXIT;
                        break;
                }
 
@@ -673,7 +677,10 @@ restart:
        }
 
        fepriv->thread = NULL;
-       fepriv->exit = 0;
+       if (kthread_should_stop())
+               fepriv->exit = DVB_FE_DEVICE_REMOVED;
+       else
+               fepriv->exit = DVB_FE_NO_EXIT;
        mb();
 
        dvb_frontend_wakeup(fe);
@@ -686,7 +693,7 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
 
        dprintk ("%s\n", __func__);
 
-       fepriv->exit = 1;
+       fepriv->exit = DVB_FE_NORMAL_EXIT;
        mb();
 
        if (!fepriv->thread)
@@ -755,7 +762,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
        dprintk ("%s\n", __func__);
 
        if (fepriv->thread) {
-               if (!fepriv->exit)
+               if (fepriv->exit == DVB_FE_NO_EXIT)
                        return 0;
                else
                        dvb_frontend_stop (fe);
@@ -767,7 +774,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
                return -EINTR;
 
        fepriv->state = FESTATE_IDLE;
-       fepriv->exit = 0;
+       fepriv->exit = DVB_FE_NO_EXIT;
        fepriv->thread = NULL;
        mb();
 
@@ -1490,7 +1497,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
 
        dprintk("%s (%d)\n", __func__, _IOC_NR(cmd));
 
-       if (fepriv->exit)
+       if (fepriv->exit != DVB_FE_NO_EXIT)
                return -ENODEV;
 
        if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
@@ -1916,6 +1923,8 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
        int ret;
 
        dprintk ("%s\n", __func__);
+       if (fepriv->exit == DVB_FE_DEVICE_REMOVED)
+               return -ENODEV;
 
        if (adapter->mfe_shared) {
                mutex_lock (&adapter->mfe_lock);
@@ -2008,7 +2017,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
        ret = dvb_generic_release (inode, file);
 
        if (dvbdev->users == -1) {
-               if (fepriv->exit == 1) {
+               if (fepriv->exit != DVB_FE_NO_EXIT) {
                        fops_put(file->f_op);
                        file->f_op = NULL;
                        wake_up(&dvbdev->wait_queue);
index 6247239..b6cbb1d 100644 (file)
@@ -37,7 +37,7 @@ static int a800_identify_state(struct usb_device *udev, struct dvb_usb_device_pr
        return 0;
 }
 
-static struct dvb_usb_rc_key a800_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_a800_table[] = {
        { 0x0201, KEY_PROG1 },       /* SOURCE */
        { 0x0200, KEY_POWER },       /* POWER */
        { 0x0205, KEY_1 },           /* 1 */
@@ -147,8 +147,8 @@ static struct dvb_usb_device_properties a800_properties = {
        .identify_state   = a800_identify_state,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = a800_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(a800_rc_keys),
+       .rc_key_map       = ir_codes_a800_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_a800_table),
        .rc_query         = a800_rc_query,
 
        .i2c_algo         = &dibusb_i2c_algo,
index f4379c6..b41fa87 100644 (file)
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(debug,
 
 #define deb_decode(args...)   dprintk(dvb_usb_af9005_remote_debug,0x01,args)
 
-struct dvb_usb_rc_key af9005_rc_keys[] = {
+struct dvb_usb_rc_key ir_codes_af9005_table[] = {
 
        {0x01b7, KEY_POWER},
        {0x01a7, KEY_VOLUMEUP},
@@ -74,7 +74,7 @@ struct dvb_usb_rc_key af9005_rc_keys[] = {
        {0x00d5, KEY_GOTO},     /* marked jump on the remote */
 };
 
-int af9005_rc_keys_size = ARRAY_SIZE(af9005_rc_keys);
+int ir_codes_af9005_table_size = ARRAY_SIZE(ir_codes_af9005_table);
 
 static int repeatable_keys[] = {
        KEY_VOLUMEUP,
@@ -130,10 +130,10 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
                                deb_decode("code != inverted code\n");
                                return 0;
                        }
-                       for (i = 0; i < af9005_rc_keys_size; i++) {
-                               if (rc5_custom(&af9005_rc_keys[i]) == cust
-                                   && rc5_data(&af9005_rc_keys[i]) == dat) {
-                                       *event = af9005_rc_keys[i].event;
+                       for (i = 0; i < ir_codes_af9005_table_size; i++) {
+                               if (rc5_custom(&ir_codes_af9005_table[i]) == cust
+                                   && rc5_data(&ir_codes_af9005_table[i]) == dat) {
+                                       *event = ir_codes_af9005_table[i].event;
                                        *state = REMOTE_KEY_PRESSED;
                                        deb_decode
                                            ("key pressed, event %x\n", *event);
@@ -146,8 +146,8 @@ int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len, u32 * event,
        return 0;
 }
 
-EXPORT_SYMBOL(af9005_rc_keys);
-EXPORT_SYMBOL(af9005_rc_keys_size);
+EXPORT_SYMBOL(ir_codes_af9005_table);
+EXPORT_SYMBOL(ir_codes_af9005_table_size);
 EXPORT_SYMBOL(af9005_rc_decode);
 
 MODULE_AUTHOR("Luca Olivetti <luca@ventoso.org>");
index ca5a0a4..cfd6107 100644 (file)
@@ -1109,8 +1109,8 @@ static int __init af9005_usb_module_init(void)
                return result;
        }
        rc_decode = symbol_request(af9005_rc_decode);
-       rc_keys = symbol_request(af9005_rc_keys);
-       rc_keys_size = symbol_request(af9005_rc_keys_size);
+       rc_keys = symbol_request(ir_codes_af9005_table);
+       rc_keys_size = symbol_request(ir_codes_af9005_table_size);
        if (rc_decode == NULL || rc_keys == NULL || rc_keys_size == NULL) {
                err("af9005_rc_decode function not found, disabling remote");
                af9005_properties.rc_query = NULL;
@@ -1128,9 +1128,9 @@ static void __exit af9005_usb_module_exit(void)
        if (rc_decode != NULL)
                symbol_put(af9005_rc_decode);
        if (rc_keys != NULL)
-               symbol_put(af9005_rc_keys);
+               symbol_put(ir_codes_af9005_table);
        if (rc_keys_size != NULL)
-               symbol_put(af9005_rc_keys_size);
+               symbol_put(ir_codes_af9005_table_size);
        /* deregister this driver from the USB subsystem */
        usb_deregister(&af9005_usb_driver);
 }
index 0bc48a0..088e708 100644 (file)
@@ -3490,7 +3490,7 @@ extern u8 regmask[8];
 /* remote control decoder */
 extern int af9005_rc_decode(struct dvb_usb_device *d, u8 * data, int len,
                            u32 * event, int *state);
-extern struct dvb_usb_rc_key af9005_rc_keys[];
-extern int af9005_rc_keys_size;
+extern struct dvb_usb_rc_key ir_codes_af9005_table[];
+extern int ir_codes_af9005_table_size;
 
 #endif
index 74d94e4..66c7c3e 100644 (file)
@@ -752,19 +752,19 @@ static const struct af9015_setup *af9015_setup_match(unsigned int id,
 
 static const struct af9015_setup af9015_setup_modparam[] = {
        { AF9015_REMOTE_A_LINK_DTU_M,
-               af9015_rc_keys_a_link, ARRAY_SIZE(af9015_rc_keys_a_link),
+               ir_codes_af9015_table_a_link, ARRAY_SIZE(ir_codes_af9015_table_a_link),
                af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) },
        { AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
-               af9015_rc_keys_msi, ARRAY_SIZE(af9015_rc_keys_msi),
+               ir_codes_af9015_table_msi, ARRAY_SIZE(ir_codes_af9015_table_msi),
                af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) },
        { AF9015_REMOTE_MYGICTV_U718,
-               af9015_rc_keys_mygictv, ARRAY_SIZE(af9015_rc_keys_mygictv),
+               ir_codes_af9015_table_mygictv, ARRAY_SIZE(ir_codes_af9015_table_mygictv),
                af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) },
        { AF9015_REMOTE_DIGITTRADE_DVB_T,
-               af9015_rc_keys_digittrade, ARRAY_SIZE(af9015_rc_keys_digittrade),
+               ir_codes_af9015_table_digittrade, ARRAY_SIZE(ir_codes_af9015_table_digittrade),
                af9015_ir_table_digittrade, ARRAY_SIZE(af9015_ir_table_digittrade) },
        { AF9015_REMOTE_AVERMEDIA_KS,
-               af9015_rc_keys_avermedia, ARRAY_SIZE(af9015_rc_keys_avermedia),
+               ir_codes_af9015_table_avermedia, ARRAY_SIZE(ir_codes_af9015_table_avermedia),
                af9015_ir_table_avermedia_ks, ARRAY_SIZE(af9015_ir_table_avermedia_ks) },
        { }
 };
@@ -772,32 +772,32 @@ static const struct af9015_setup af9015_setup_modparam[] = {
 /* don't add new entries here anymore, use hashes instead */
 static const struct af9015_setup af9015_setup_usbids[] = {
        { USB_VID_LEADTEK,
-               af9015_rc_keys_leadtek, ARRAY_SIZE(af9015_rc_keys_leadtek),
+               ir_codes_af9015_table_leadtek, ARRAY_SIZE(ir_codes_af9015_table_leadtek),
                af9015_ir_table_leadtek, ARRAY_SIZE(af9015_ir_table_leadtek) },
        { USB_VID_VISIONPLUS,
-               af9015_rc_keys_twinhan, ARRAY_SIZE(af9015_rc_keys_twinhan),
+               ir_codes_af9015_table_twinhan, ARRAY_SIZE(ir_codes_af9015_table_twinhan),
                af9015_ir_table_twinhan, ARRAY_SIZE(af9015_ir_table_twinhan) },
        { USB_VID_KWORLD_2, /* TODO: use correct rc keys */
-               af9015_rc_keys_twinhan, ARRAY_SIZE(af9015_rc_keys_twinhan),
+               ir_codes_af9015_table_twinhan, ARRAY_SIZE(ir_codes_af9015_table_twinhan),
                af9015_ir_table_kworld, ARRAY_SIZE(af9015_ir_table_kworld) },
        { USB_VID_AVERMEDIA,
-               af9015_rc_keys_avermedia, ARRAY_SIZE(af9015_rc_keys_avermedia),
+               ir_codes_af9015_table_avermedia, ARRAY_SIZE(ir_codes_af9015_table_avermedia),
                af9015_ir_table_avermedia, ARRAY_SIZE(af9015_ir_table_avermedia) },
        { USB_VID_MSI_2,
-               af9015_rc_keys_msi_digivox_iii, ARRAY_SIZE(af9015_rc_keys_msi_digivox_iii),
+               ir_codes_af9015_table_msi_digivox_iii, ARRAY_SIZE(ir_codes_af9015_table_msi_digivox_iii),
                af9015_ir_table_msi_digivox_iii, ARRAY_SIZE(af9015_ir_table_msi_digivox_iii) },
        { }
 };
 
 static const struct af9015_setup af9015_setup_hashes[] = {
        { 0xb8feb708,
-               af9015_rc_keys_msi, ARRAY_SIZE(af9015_rc_keys_msi),
+               ir_codes_af9015_table_msi, ARRAY_SIZE(ir_codes_af9015_table_msi),
                af9015_ir_table_msi, ARRAY_SIZE(af9015_ir_table_msi) },
        { 0xa3703d00,
-               af9015_rc_keys_a_link, ARRAY_SIZE(af9015_rc_keys_a_link),
+               ir_codes_af9015_table_a_link, ARRAY_SIZE(ir_codes_af9015_table_a_link),
                af9015_ir_table_a_link, ARRAY_SIZE(af9015_ir_table_a_link) },
        { 0x9b7dc64e,
-               af9015_rc_keys_mygictv, ARRAY_SIZE(af9015_rc_keys_mygictv),
+               ir_codes_af9015_table_mygictv, ARRAY_SIZE(ir_codes_af9015_table_mygictv),
                af9015_ir_table_mygictv, ARRAY_SIZE(af9015_ir_table_mygictv) },
        { }
 };
@@ -836,8 +836,8 @@ static void af9015_set_remote_config(struct usb_device *udev,
                        } else if (udev->descriptor.idProduct ==
                                cpu_to_le16(USB_PID_TREKSTOR_DVBT)) {
                                table = &(const struct af9015_setup){ 0,
-                                       af9015_rc_keys_trekstor,
-                                       ARRAY_SIZE(af9015_rc_keys_trekstor),
+                                       ir_codes_af9015_table_trekstor,
+                                       ARRAY_SIZE(ir_codes_af9015_table_trekstor),
                                        af9015_ir_table_trekstor,
                                        ARRAY_SIZE(af9015_ir_table_trekstor)
                                };
@@ -1297,6 +1297,8 @@ static struct usb_device_id af9015_usb_table[] = {
        {USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_SVEON_STV20)},
        {USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_TINYTWIN_2)},
        {USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV2000DS)},
+/* 30 */{USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_KWORLD_UB383_T)},
+       {USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_KWORLD_395U_4)},
        {0},
 };
 MODULE_DEVICE_TABLE(usb, af9015_usb_table);
@@ -1500,7 +1502,8 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                        "(VS-DVB-T 395U)",
                                .cold_ids = {&af9015_usb_table[16],
                                             &af9015_usb_table[17],
-                                            &af9015_usb_table[18], NULL},
+                                            &af9015_usb_table[18],
+                                            &af9015_usb_table[31], NULL},
                                .warm_ids = {NULL},
                        },
                        {
@@ -1569,7 +1572,7 @@ static struct dvb_usb_device_properties af9015_properties[] = {
 
                .i2c_algo = &af9015_i2c_algo,
 
-               .num_device_descs = 7, /* max 9 */
+               .num_device_descs = 8, /* max 9 */
                .devices = {
                        {
                                .name = "AverMedia AVerTV Volar GPS 805 (A805)",
@@ -1608,6 +1611,12 @@ static struct dvb_usb_device_properties af9015_properties[] = {
                                .cold_ids = {&af9015_usb_table[29], NULL},
                                .warm_ids = {NULL},
                        },
+                       {
+                               .name = "KWorld USB DVB-T Stick Mobile " \
+                                       "(UB383-T)",
+                               .cold_ids = {&af9015_usb_table[30], NULL},
+                               .warm_ids = {NULL},
+                       },
                }
        },
 };
index ef36b18..63b2a49 100644 (file)
@@ -123,7 +123,7 @@ enum af9015_remote {
 
 /* LeadTek - Y04G0051 */
 /* Leadtek WinFast DTV Dongle Gold */
-static struct dvb_usb_rc_key af9015_rc_keys_leadtek[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_leadtek[] = {
        { 0x001e, KEY_1 },
        { 0x001f, KEY_2 },
        { 0x0020, KEY_3 },
@@ -227,7 +227,7 @@ static u8 af9015_ir_table_leadtek[] = {
 };
 
 /* TwinHan AzureWave AD-TU700(704J) */
-static struct dvb_usb_rc_key af9015_rc_keys_twinhan[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_twinhan[] = {
        { 0x053f, KEY_POWER },
        { 0x0019, KEY_FAVORITES },    /* Favorite List */
        { 0x0004, KEY_TEXT },         /* Teletext */
@@ -338,7 +338,7 @@ static u8 af9015_ir_table_twinhan[] = {
 };
 
 /* A-Link DTU(m) */
-static struct dvb_usb_rc_key af9015_rc_keys_a_link[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_a_link[] = {
        { 0x001e, KEY_1 },
        { 0x001f, KEY_2 },
        { 0x0020, KEY_3 },
@@ -381,7 +381,7 @@ static u8 af9015_ir_table_a_link[] = {
 };
 
 /* MSI DIGIVOX mini II V3.0 */
-static struct dvb_usb_rc_key af9015_rc_keys_msi[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_msi[] = {
        { 0x001e, KEY_1 },
        { 0x001f, KEY_2 },
        { 0x0020, KEY_3 },
@@ -424,7 +424,7 @@ static u8 af9015_ir_table_msi[] = {
 };
 
 /* MYGICTV U718 */
-static struct dvb_usb_rc_key af9015_rc_keys_mygictv[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_mygictv[] = {
        { 0x003d, KEY_SWITCHVIDEOMODE },
                                          /* TV / AV */
        { 0x0545, KEY_POWER },
@@ -550,7 +550,7 @@ static u8 af9015_ir_table_kworld[] = {
 };
 
 /* AverMedia Volar X */
-static struct dvb_usb_rc_key af9015_rc_keys_avermedia[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_avermedia[] = {
        { 0x053d, KEY_PROG1 },       /* SOURCE */
        { 0x0512, KEY_POWER },       /* POWER */
        { 0x051e, KEY_1 },           /* 1 */
@@ -656,7 +656,7 @@ static u8 af9015_ir_table_avermedia_ks[] = {
 };
 
 /* Digittrade DVB-T USB Stick */
-static struct dvb_usb_rc_key af9015_rc_keys_digittrade[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_digittrade[] = {
        { 0x010f, KEY_LAST },   /* RETURN */
        { 0x0517, KEY_TEXT },   /* TELETEXT */
        { 0x0108, KEY_EPG },    /* EPG */
@@ -719,7 +719,7 @@ static u8 af9015_ir_table_digittrade[] = {
 };
 
 /* TREKSTOR DVB-T USB Stick */
-static struct dvb_usb_rc_key af9015_rc_keys_trekstor[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_trekstor[] = {
        { 0x0704, KEY_AGAIN },          /* Home */
        { 0x0705, KEY_MUTE },           /* Mute */
        { 0x0706, KEY_UP },                     /* Up */
@@ -782,7 +782,7 @@ static u8 af9015_ir_table_trekstor[] = {
 };
 
 /* MSI DIGIVOX mini III */
-static struct dvb_usb_rc_key af9015_rc_keys_msi_digivox_iii[] = {
+static struct dvb_usb_rc_key ir_codes_af9015_table_msi_digivox_iii[] = {
        { 0x0713, KEY_POWER },       /* [red power button] */
        { 0x073b, KEY_VIDEO },       /* Source */
        { 0x073e, KEY_ZOOM },        /* Zoom */
index bb69f37..faca1ad 100644 (file)
@@ -399,7 +399,7 @@ static int anysee_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
        return 0;
 }
 
-static struct dvb_usb_rc_key anysee_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_anysee_table[] = {
        { 0x0100, KEY_0 },
        { 0x0101, KEY_1 },
        { 0x0102, KEY_2 },
@@ -518,8 +518,8 @@ static struct dvb_usb_device_properties anysee_properties = {
                }
        },
 
-       .rc_key_map       = anysee_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(anysee_rc_keys),
+       .rc_key_map       = ir_codes_anysee_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_anysee_table),
        .rc_query         = anysee_rc_query,
        .rc_interval      = 200,  /* windows driver uses 500ms */
 
index d7290b2..6681ac1 100644 (file)
@@ -125,12 +125,12 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
        { STB0899_RCOMPC                , 0xc9 },
        { STB0899_AGC1CN                , 0x01 },
        { STB0899_AGC1REF               , 0x10 },
-       { STB0899_RTC                   , 0x23 },
+       { STB0899_RTC                   , 0x23 },
        { STB0899_TMGCFG                , 0x4e },
        { STB0899_AGC2REF               , 0x34 },
        { STB0899_TLSR                  , 0x84 },
        { STB0899_CFD                   , 0xf7 },
-       { STB0899_ACLC                  , 0x87 },
+       { STB0899_ACLC                  , 0x87 },
        { STB0899_BCLC                  , 0x94 },
        { STB0899_EQON                  , 0x41 },
        { STB0899_LDT                   , 0xf1 },
@@ -183,10 +183,10 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
        { STB0899_ECNT3M                , 0x0a },
        { STB0899_ECNT3L                , 0xad },
        { STB0899_FECAUTO1              , 0x06 },
-       { STB0899_FECM                  , 0x01 },
+       { STB0899_FECM                  , 0x01 },
        { STB0899_VTH12                 , 0xb0 },
        { STB0899_VTH23                 , 0x7a },
-       { STB0899_VTH34                 , 0x58 },
+       { STB0899_VTH34                 , 0x58 },
        { STB0899_VTH56                 , 0x38 },
        { STB0899_VTH67                 , 0x34 },
        { STB0899_VTH78                 , 0x24 },
@@ -195,7 +195,7 @@ static const struct stb0899_s1_reg az6027_stb0899_s1_init_3[] = {
        { STB0899_RSULC                 , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
        { STB0899_TSULC                 , 0x42 },
        { STB0899_RSLLC                 , 0x41 },
-       { STB0899_TSLPL                 , 0x12 },
+       { STB0899_TSLPL                 , 0x12 },
        { STB0899_TSCFGH                , 0x0c },
        { STB0899_TSCFGM                , 0x00 },
        { STB0899_TSCFGL                , 0x00 },
@@ -386,7 +386,7 @@ static int az6027_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 }
 
 /* keys for the enclosed remote control */
-static struct dvb_usb_rc_key az6027_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_az6027_table[] = {
        { 0x01, KEY_1 },
        { 0x02, KEY_2 },
 };
@@ -417,11 +417,15 @@ static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
        u16 value;
        u16 index;
        int blen;
-       u8 b[12];
+       u8 *b;
 
        if (slot != 0)
                return -EINVAL;
 
+       b = kmalloc(12, GFP_KERNEL);
+       if (!b)
+               return -ENOMEM;
+
        mutex_lock(&state->ca_mutex);
 
        req = 0xC1;
@@ -438,6 +442,7 @@ static int az6027_ci_read_attribute_mem(struct dvb_ca_en50221 *ca,
        }
 
        mutex_unlock(&state->ca_mutex);
+       kfree(b);
        return ret;
 }
 
@@ -485,11 +490,15 @@ static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca,
        u16 value;
        u16 index;
        int blen;
-       u8 b[12];
+       u8 *b;
 
        if (slot != 0)
                return -EINVAL;
 
+       b = kmalloc(12, GFP_KERNEL);
+       if (!b)
+               return -ENOMEM;
+
        mutex_lock(&state->ca_mutex);
 
        req = 0xC3;
@@ -510,6 +519,7 @@ static int az6027_ci_read_cam_control(struct dvb_ca_en50221 *ca,
        }
 
        mutex_unlock(&state->ca_mutex);
+       kfree(b);
        return ret;
 }
 
@@ -556,7 +566,11 @@ static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot)
        u16 value;
        u16 index;
        int blen;
-       u8 b[12];
+       u8 *b;
+
+       b = kmalloc(12, GFP_KERNEL);
+       if (!b)
+               return -ENOMEM;
 
        req = 0xC8;
        value = 0;
@@ -570,6 +584,7 @@ static int CI_CamReady(struct dvb_ca_en50221 *ca, int slot)
        } else{
                ret = b[0];
        }
+       kfree(b);
        return ret;
 }
 
@@ -667,8 +682,11 @@ static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int o
        u16 value;
        u16 index;
        int blen;
-       u8 b[12];
+       u8 *b;
 
+       b = kmalloc(12, GFP_KERNEL);
+       if (!b)
+               return -ENOMEM;
        mutex_lock(&state->ca_mutex);
 
        req = 0xC5;
@@ -683,15 +701,13 @@ static int az6027_ci_poll_slot_status(struct dvb_ca_en50221 *ca, int slot, int o
        } else
                ret = 0;
 
-       if (b[0] == 0) {
-               ret = 0;
-
-       } else if (b[0] == 1) {
+       if (!ret && b[0] == 1) {
                ret = DVB_CA_EN50221_POLL_CAM_PRESENT |
                      DVB_CA_EN50221_POLL_CAM_READY;
        }
 
        mutex_unlock(&state->ca_mutex);
+       kfree(b);
        return ret;
 }
 
@@ -943,10 +959,16 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
        u16 value;
        int length;
        u8 req;
-       u8 data[256];
+       u8 *data;
 
-       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+       data = kmalloc(256, GFP_KERNEL);
+       if (!data)
+               return -ENOMEM;
+
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0) {
+               kfree(data);
                return -EAGAIN;
+       }
 
        if (num > 2)
                warn("more than 2 i2c messages at a time is not handled yet. TODO.");
@@ -976,17 +998,14 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
                                i++;
                        } else {
 
-                               if (msg[i].addr == 0xd0) {
-                                       /* demod 16bit addr */
-                                       req = 0xBD;
-                                       index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
-                                       value = msg[i].addr + (2 << 8);
-                                       length = msg[i].len - 2;
-                                       len = msg[i].len - 2;
-                                       for (j = 0; j < len; j++)
-                                               data[j] = msg[i].buf[j + 2];
-
-                               }
+                               /* demod 16bit addr */
+                               req = 0xBD;
+                               index = (((msg[i].buf[0] << 8) & 0xff00) | (msg[i].buf[1] & 0x00ff));
+                               value = msg[i].addr + (2 << 8);
+                               length = msg[i].len - 2;
+                               len = msg[i].len - 2;
+                               for (j = 0; j < len; j++)
+                                       data[j] = msg[i].buf[j + 2];
                                az6027_usb_out_op(d, req, value, index, data, length);
                        }
                }
@@ -1019,6 +1038,7 @@ static int az6027_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int n
                }
        }
        mutex_unlock(&d->i2c_mutex);
+       kfree(data);
 
        return i;
 }
@@ -1039,8 +1059,14 @@ int az6027_identify_state(struct usb_device *udev,
                          struct dvb_usb_device_description **desc,
                          int *cold)
 {
-       u8 b[16];
-       s16 ret = usb_control_msg(udev,
+       u8 *b;
+       s16 ret;
+
+       b = kmalloc(16, GFP_KERNEL);
+       if (!b)
+               return -ENOMEM;
+
+       ret = usb_control_msg(udev,
                                  usb_rcvctrlpipe(udev, 0),
                                  0xb7,
                                  USB_TYPE_VENDOR | USB_DIR_IN,
@@ -1051,7 +1077,7 @@ int az6027_identify_state(struct usb_device *udev,
                                  USB_CTRL_GET_TIMEOUT);
 
        *cold = ret <= 0;
-
+       kfree(b);
        deb_info("cold: %d\n", *cold);
        return 0;
 }
@@ -1059,8 +1085,10 @@ int az6027_identify_state(struct usb_device *udev,
 
 static struct usb_device_id az6027_usb_table[] = {
        { USB_DEVICE(USB_VID_AZUREWAVE, USB_PID_AZUREWAVE_AZ6027) },
-       { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_DVBS2CI) },
-       { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI) },
+       { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_DVBS2CI_V1) },
+       { USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_DVBS2CI_V2) },
+       { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V1) },
+       { USB_DEVICE(USB_VID_TECHNISAT, USB_PID_TECHNISAT_USB2_HDCI_V2) },
        { },
 };
 
@@ -1097,18 +1125,34 @@ static struct dvb_usb_device_properties az6027_properties = {
        .power_ctrl       = az6027_power_ctrl,
        .read_mac_address = az6027_read_mac_addr,
  */
-       .rc_key_map       = az6027_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(az6027_rc_keys),
+       .rc_key_map       = ir_codes_az6027_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_az6027_table),
        .rc_interval      = 400,
        .rc_query         = az6027_rc_query,
        .i2c_algo         = &az6027_i2c_algo,
 
-       .num_device_descs = 1,
+       .num_device_descs = 5,
        .devices = {
                {
                        .name = "AZUREWAVE DVB-S/S2 USB2.0 (AZ6027)",
                        .cold_ids = { &az6027_usb_table[0], NULL },
                        .warm_ids = { NULL },
+               }, {
+                       .name = "TERRATEC S7",
+                       .cold_ids = { &az6027_usb_table[1], NULL },
+                       .warm_ids = { NULL },
+               }, {
+                       .name = "TERRATEC S7 MKII",
+                       .cold_ids = { &az6027_usb_table[2], NULL },
+                       .warm_ids = { NULL },
+               }, {
+                       .name = "Technisat SkyStar USB 2 HD CI",
+                       .cold_ids = { &az6027_usb_table[3], NULL },
+                       .warm_ids = { NULL },
+               }, {
+                       .name = "Technisat SkyStar USB 2 HD CI",
+                       .cold_ids = { &az6027_usb_table[4], NULL },
+                       .warm_ids = { NULL },
                },
                { NULL },
        }
index e37ac4d..5a9c14b 100644 (file)
@@ -84,7 +84,7 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
-static struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_cinergyt2_table[] = {
        { 0x0401, KEY_POWER },
        { 0x0402, KEY_1 },
        { 0x0403, KEY_2 },
@@ -218,8 +218,8 @@ static struct dvb_usb_device_properties cinergyt2_properties = {
        .power_ctrl       = cinergyt2_power_ctrl,
 
        .rc_interval      = 50,
-       .rc_key_map       = cinergyt2_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(cinergyt2_rc_keys),
+       .rc_key_map       = ir_codes_cinergyt2_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_cinergyt2_table),
        .rc_query         = cinergyt2_rc_query,
 
        .generic_bulk_ctrl_endpoint = 1,
index 960376d..0eb4908 100644 (file)
@@ -461,7 +461,7 @@ static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
        return 0;
 }
 
-static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_dvico_mce_table[] = {
        { 0xfe02, KEY_TV },
        { 0xfe0e, KEY_MP3 },
        { 0xfe1a, KEY_DVD },
@@ -509,7 +509,7 @@ static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
        { 0xfe4e, KEY_POWER },
 };
 
-static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_dvico_portable_table[] = {
        { 0xfc02, KEY_SETUP },       /* Profile */
        { 0xfc43, KEY_POWER2 },
        { 0xfc06, KEY_EPG },
@@ -548,7 +548,7 @@ static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
        { 0xfc00, KEY_UNKNOWN },    /* HD */
 };
 
-static struct dvb_usb_rc_key d680_dmb_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_d680_dmb_table[] = {
        { 0x0038, KEY_UNKNOWN },        /* TV/AV */
        { 0x080c, KEY_ZOOM },
        { 0x0800, KEY_0 },
@@ -1025,8 +1025,9 @@ static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
 
        cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
 
-       dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
-                                &cxusb_dualdig4_rev2_config);
+       if (dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
+                                &cxusb_dualdig4_rev2_config) < 0)
+               return -ENODEV;
 
        adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
                              &cxusb_dualdig4_rev2_config);
@@ -1449,8 +1450,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgh064f_properties = {
        .i2c_algo         = &cxusb_i2c_algo,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_key_map       = ir_codes_dvico_portable_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_portable_table),
        .rc_query         = cxusb_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -1500,8 +1501,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties = {
        .i2c_algo         = &cxusb_i2c_algo,
 
        .rc_interval      = 150,
-       .rc_key_map       = dvico_mce_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
+       .rc_key_map       = ir_codes_dvico_mce_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_mce_table),
        .rc_query         = cxusb_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -1559,8 +1560,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties = {
        .i2c_algo         = &cxusb_i2c_algo,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_key_map       = ir_codes_dvico_portable_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_portable_table),
        .rc_query         = cxusb_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -1609,8 +1610,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties = {
        .i2c_algo         = &cxusb_i2c_algo,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_key_map       = ir_codes_dvico_portable_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_portable_table),
        .rc_query         = cxusb_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -1658,8 +1659,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties = {
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_mce_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
+       .rc_key_map       = ir_codes_dvico_mce_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_mce_table),
        .rc_query         = cxusb_bluebird2_rc_query,
 
        .num_device_descs = 1,
@@ -1706,8 +1707,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties = {
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_key_map       = ir_codes_dvico_portable_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_portable_table),
        .rc_query         = cxusb_bluebird2_rc_query,
 
        .num_device_descs = 1,
@@ -1756,8 +1757,8 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_portable_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_portable_rc_keys),
+       .rc_key_map       = ir_codes_dvico_portable_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_portable_table),
        .rc_query         = cxusb_rc_query,
 
        .num_device_descs = 1,
@@ -1847,8 +1848,8 @@ struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = dvico_mce_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
+       .rc_key_map       = ir_codes_dvico_mce_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_dvico_mce_table),
        .rc_query         = cxusb_rc_query,
 
        .num_device_descs = 1,
@@ -1895,8 +1896,8 @@ static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = d680_dmb_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(d680_dmb_rc_keys),
+       .rc_key_map       = ir_codes_d680_dmb_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_d680_dmb_table),
        .rc_query         = cxusb_d680_dmb_rc_query,
 
        .num_device_descs = 1,
@@ -1944,8 +1945,8 @@ static struct dvb_usb_device_properties cxusb_mygica_d689_properties = {
        .generic_bulk_ctrl_endpoint = 0x01,
 
        .rc_interval      = 100,
-       .rc_key_map       = d680_dmb_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(d680_dmb_rc_keys),
+       .rc_key_map       = ir_codes_d680_dmb_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_d680_dmb_table),
        .rc_query         = cxusb_d680_dmb_rc_query,
 
        .num_device_descs = 1,
index 34eab05..800800a 100644 (file)
@@ -562,7 +562,7 @@ static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
        return 0;
 }
 
-static struct dvb_usb_rc_key dib0700_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_dib0700_table[] = {
        /* Key codes for the tiny Pinnacle remote*/
        { 0x0700, KEY_MUTE },
        { 0x0701, KEY_MENU }, /* Pinnacle logo */
@@ -794,6 +794,43 @@ static struct dvb_usb_rc_key dib0700_rc_keys[] = {
        { 0x7a13, KEY_VOLUMEDOWN },
        { 0x7a40, KEY_POWER },
        { 0x7a41, KEY_MUTE },
+
+       /* Key codes for the Elgato EyeTV Diversity silver remote,
+          set dvb_usb_dib0700_ir_proto=0 */
+       { 0x4501, KEY_POWER },
+       { 0x4502, KEY_MUTE },
+       { 0x4503, KEY_1 },
+       { 0x4504, KEY_2 },
+       { 0x4505, KEY_3 },
+       { 0x4506, KEY_4 },
+       { 0x4507, KEY_5 },
+       { 0x4508, KEY_6 },
+       { 0x4509, KEY_7 },
+       { 0x450a, KEY_8 },
+       { 0x450b, KEY_9 },
+       { 0x450c, KEY_LAST },
+       { 0x450d, KEY_0 },
+       { 0x450e, KEY_ENTER },
+       { 0x450f, KEY_RED },
+       { 0x4510, KEY_CHANNELUP },
+       { 0x4511, KEY_GREEN },
+       { 0x4512, KEY_VOLUMEDOWN },
+       { 0x4513, KEY_OK },
+       { 0x4514, KEY_VOLUMEUP },
+       { 0x4515, KEY_YELLOW },
+       { 0x4516, KEY_CHANNELDOWN },
+       { 0x4517, KEY_BLUE },
+       { 0x4518, KEY_LEFT }, /* Skip backwards */
+       { 0x4519, KEY_PLAYPAUSE },
+       { 0x451a, KEY_RIGHT }, /* Skip forward */
+       { 0x451b, KEY_REWIND },
+       { 0x451c, KEY_L }, /* Live */
+       { 0x451d, KEY_FASTFORWARD },
+       { 0x451e, KEY_STOP }, /* 'Reveal' for Teletext */
+       { 0x451f, KEY_MENU }, /* KEY_TEXT for Teletext */
+       { 0x4540, KEY_RECORD }, /* Font 'Size' for Teletext */
+       { 0x4541, KEY_SCREEN }, /*  Full screen toggle, 'Hold' for Teletext */
+       { 0x4542, KEY_SELECT }, /* Select video input, 'Select' for Teletext */
 };
 
 /* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
@@ -2049,6 +2086,7 @@ struct usb_device_id dib0700_usb_id_table[] = {
 /* 65 */{ USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV73ESE) },
        { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV282E) },
        { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK8096GP) },
+       { USB_DEVICE(USB_VID_ELGATO,    USB_PID_ELGATO_EYETV_DIVERSITY) },
        { 0 }           /* Terminating entry */
 };
 MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -2131,8 +2169,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
 
@@ -2160,8 +2198,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
 
@@ -2214,8 +2252,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
 
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -2251,8 +2289,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
 
@@ -2321,8 +2359,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
 
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -2360,8 +2398,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
 
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -2393,7 +2431,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        }
                },
 
-               .num_device_descs = 6,
+               .num_device_descs = 7,
                .devices = {
                        {   "DiBcom STK7070PD reference design",
                                { &dib0700_usb_id_table[17], NULL },
@@ -2419,11 +2457,15 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        {  "Sony PlayTV",
                                { &dib0700_usb_id_table[44], NULL },
                                { NULL },
-                       }
+                       },
+                       {   "Elgato EyeTV Diversity",
+                               { &dib0700_usb_id_table[68], NULL },
+                               { NULL },
+                       },
                },
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
 
@@ -2484,8 +2526,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        },
                },
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
                .num_adapters = 1,
@@ -2513,8 +2555,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        },
                },
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
                .num_adapters = 1,
@@ -2574,8 +2616,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        },
                },
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
                .num_adapters = 1,
@@ -2612,8 +2654,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
 
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
@@ -2656,8 +2698,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
                .num_adapters = 1,
@@ -2687,8 +2729,8 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                },
 
                .rc_interval      = DEFAULT_RC_INTERVAL,
-               .rc_key_map       = dib0700_rc_keys,
-               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_key_map       = ir_codes_dib0700_table,
+               .rc_key_map_size  = ARRAY_SIZE(ir_codes_dib0700_table),
                .rc_query         = dib0700_rc_query
        },
 };
index 9143b56..bc08bc0 100644 (file)
@@ -327,7 +327,7 @@ EXPORT_SYMBOL(dibusb_dib3000mc_tuner_attach);
 /*
  * common remote control stuff
  */
-struct dvb_usb_rc_key dibusb_rc_keys[] = {
+struct dvb_usb_rc_key ir_codes_dibusb_table[] = {
        /* Key codes for the little Artec T1/Twinhan/HAMA/ remote. */
        { 0x0016, KEY_POWER },
        { 0x0010, KEY_MUTE },
@@ -456,7 +456,7 @@ struct dvb_usb_rc_key dibusb_rc_keys[] = {
        { 0x804e, KEY_ENTER },
        { 0x804f, KEY_VOLUMEDOWN },
 };
-EXPORT_SYMBOL(dibusb_rc_keys);
+EXPORT_SYMBOL(ir_codes_dibusb_table);
 
 int dibusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
index 5c0126d..eb2e6f0 100644 (file)
@@ -212,7 +212,7 @@ static struct dvb_usb_device_properties dibusb1_1_properties = {
        .power_ctrl       = dibusb_power_ctrl,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = dibusb_rc_keys,
+       .rc_key_map       = ir_codes_dibusb_table,
        .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
        .rc_query         = dibusb_rc_query,
 
@@ -296,7 +296,7 @@ static struct dvb_usb_device_properties dibusb1_1_an2235_properties = {
        .power_ctrl       = dibusb_power_ctrl,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = dibusb_rc_keys,
+       .rc_key_map       = ir_codes_dibusb_table,
        .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
        .rc_query         = dibusb_rc_query,
 
@@ -360,7 +360,7 @@ static struct dvb_usb_device_properties dibusb2_0b_properties = {
        .power_ctrl       = dibusb2_0_power_ctrl,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = dibusb_rc_keys,
+       .rc_key_map       = ir_codes_dibusb_table,
        .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
        .rc_query         = dibusb_rc_query,
 
@@ -417,7 +417,7 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties = {
        .power_ctrl       = dibusb2_0_power_ctrl,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = dibusb_rc_keys,
+       .rc_key_map       = ir_codes_dibusb_table,
        .rc_key_map_size  = 111, /* wow, that is ugly ... I want to load it to the driver dynamically */
        .rc_query         = dibusb_rc_query,
 
index a05b9f8..588308e 100644 (file)
@@ -82,7 +82,7 @@ static struct dvb_usb_device_properties dibusb_mc_properties = {
        .power_ctrl       = dibusb2_0_power_ctrl,
 
        .rc_interval      = DEFAULT_RC_INTERVAL,
-       .rc_key_map       = dibusb_rc_keys,
+       .rc_key_map       = ir_codes_dibusb_table,
        .rc_key_map_size  = 111, /* FIXME */
        .rc_query         = dibusb_rc_query,
 
index 8e847aa..3d50ac5 100644 (file)
@@ -124,7 +124,7 @@ extern int dibusb2_0_power_ctrl(struct dvb_usb_device *, int);
 #define DEFAULT_RC_INTERVAL 150
 //#define DEFAULT_RC_INTERVAL 100000
 
-extern struct dvb_usb_rc_key dibusb_rc_keys[];
+extern struct dvb_usb_rc_key ir_codes_dibusb_table[];
 extern int dibusb_rc_query(struct dvb_usb_device *, u32 *, int *);
 extern int dibusb_read_eeprom_byte(struct dvb_usb_device *, u8, u8 *);
 
index 955147d..e826077 100644 (file)
@@ -161,7 +161,7 @@ static int digitv_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
-static struct dvb_usb_rc_key digitv_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_digitv_table[] = {
        { 0x5f55, KEY_0 },
        { 0x6f55, KEY_1 },
        { 0x9f55, KEY_2 },
@@ -311,8 +311,8 @@ static struct dvb_usb_device_properties digitv_properties = {
        .identify_state   = digitv_identify_state,
 
        .rc_interval      = 1000,
-       .rc_key_map       = digitv_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(digitv_rc_keys),
+       .rc_key_map       = ir_codes_digitv_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_digitv_table),
        .rc_query         = digitv_rc_query,
 
        .i2c_algo         = &digitv_i2c_algo,
index a1b12b0..f57e590 100644 (file)
@@ -57,7 +57,7 @@ static int dtt200u_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
 
 /* remote control */
 /* key list for the tiny remote control (Yakumo, don't know about the others) */
-static struct dvb_usb_rc_key dtt200u_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_dtt200u_table[] = {
        { 0x8001, KEY_MUTE },
        { 0x8002, KEY_CHANNELDOWN },
        { 0x8003, KEY_VOLUMEDOWN },
@@ -162,8 +162,8 @@ static struct dvb_usb_device_properties dtt200u_properties = {
        .power_ctrl      = dtt200u_power_ctrl,
 
        .rc_interval     = 300,
-       .rc_key_map      = dtt200u_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
+       .rc_key_map      = ir_codes_dtt200u_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
        .rc_query        = dtt200u_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -207,8 +207,8 @@ static struct dvb_usb_device_properties wt220u_properties = {
        .power_ctrl      = dtt200u_power_ctrl,
 
        .rc_interval     = 300,
-       .rc_key_map      = dtt200u_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
+       .rc_key_map      = ir_codes_dtt200u_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
        .rc_query        = dtt200u_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -252,8 +252,8 @@ static struct dvb_usb_device_properties wt220u_fc_properties = {
        .power_ctrl      = dtt200u_power_ctrl,
 
        .rc_interval     = 300,
-       .rc_key_map      = dtt200u_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
+       .rc_key_map      = ir_codes_dtt200u_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
        .rc_query        = dtt200u_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
@@ -297,8 +297,8 @@ static struct dvb_usb_device_properties wt220u_zl0353_properties = {
        .power_ctrl      = dtt200u_power_ctrl,
 
        .rc_interval     = 300,
-       .rc_key_map      = dtt200u_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dtt200u_rc_keys),
+       .rc_key_map      = ir_codes_dtt200u_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dtt200u_table),
        .rc_query        = dtt200u_rc_query,
 
        .generic_bulk_ctrl_endpoint = 0x01,
index ae8b57a..085c4e4 100644 (file)
 #define USB_PID_KWORLD_395U                            0xe396
 #define USB_PID_KWORLD_395U_2                          0xe39b
 #define USB_PID_KWORLD_395U_3                          0xe395
+#define USB_PID_KWORLD_395U_4                          0xe39a
 #define USB_PID_KWORLD_MC810                           0xc810
 #define USB_PID_KWORLD_PC160_2T                                0xc160
 #define USB_PID_KWORLD_PC160_T                         0xc161
+#define USB_PID_KWORLD_UB383_T                         0xe383
 #define USB_PID_KWORLD_VSTREAM_COLD                    0x17de
 #define USB_PID_KWORLD_VSTREAM_WARM                    0x17df
 #define USB_PID_TERRATEC_CINERGY_T_USB_XE              0x0055
 #define USB_PID_MSI_DIGI_VOX_MINI_III                   0x8807
 #define USB_PID_SONY_PLAYTV                            0x0003
 #define USB_PID_MYGICA_D689                            0xd811
+#define USB_PID_ELGATO_EYETV_DIVERSITY                 0x0011
 #define USB_PID_ELGATO_EYETV_DTT                       0x0021
 #define USB_PID_ELGATO_EYETV_DTT_Dlx                   0x0020
 #define USB_PID_DVB_T_USB_STICK_HIGH_SPEED_COLD                0x5000
 #define USB_PID_TVWAY_PLUS                             0x0002
 #define USB_PID_SVEON_STV20                            0xe39d
 #define USB_PID_AZUREWAVE_AZ6027                       0x3275
-#define USB_PID_TERRATEC_DVBS2CI                       0x3275
-#define USB_PID_TECHNISAT_USB2_HDCI                    0x0002
+#define USB_PID_TERRATEC_DVBS2CI_V1                    0x10a4
+#define USB_PID_TERRATEC_DVBS2CI_V2                    0x10ac
+#define USB_PID_TECHNISAT_USB2_HDCI_V1                 0x0001
+#define USB_PID_TECHNISAT_USB2_HDCI_V2                 0x0002
 #endif
index 6fe71c6..bb46ba6 100644 (file)
@@ -42,6 +42,8 @@ int dvb_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen, u8 *rbuf,
                        msleep(delay_ms);
 
                ret = usb_bulk_msg(d->udev,usb_rcvbulkpipe(d->udev,
+                               d->props.generic_bulk_ctrl_endpoint_response ?
+                               d->props.generic_bulk_ctrl_endpoint_response :
                                d->props.generic_bulk_ctrl_endpoint),rbuf,rlen,&actlen,
                                2000);
 
index 0143aef..4a9f676 100644 (file)
@@ -198,6 +198,12 @@ struct dvb_usb_adapter_properties {
  *  is non-zero, one can use dvb_usb_generic_rw and dvb_usb_generic_write-
  *  helper functions.
  *
+ * @generic_bulk_ctrl_endpoint_response: some DVB USB devices use a separate
+ *  endpoint for responses to control messages sent with bulk transfers via
+ *  the generic_bulk_ctrl_endpoint. When this is non-zero, this will be used
+ *  instead of the generic_bulk_ctrl_endpoint when reading usb responses in
+ *  the dvb_usb_generic_rw helper function.
+ *
  * @num_device_descs: number of struct dvb_usb_device_description in @devices
  * @devices: array of struct dvb_usb_device_description compatibles with these
  *  properties.
@@ -239,6 +245,7 @@ struct dvb_usb_device_properties {
        struct i2c_algorithm *i2c_algo;
 
        int generic_bulk_ctrl_endpoint;
+       int generic_bulk_ctrl_endpoint_response;
 
        int num_device_descs;
        struct dvb_usb_device_description devices[12];
index accc655..e8fb853 100644 (file)
@@ -73,7 +73,7 @@
                "Please see linux/Documentation/dvb/ for more details " \
                "on firmware-problems."
 
-struct dvb_usb_rc_keys_table {
+struct ir_codes_dvb_usb_table_table {
        struct dvb_usb_rc_key *rc_keys;
        int rc_keys_size;
 };
@@ -948,7 +948,7 @@ static int dw3101_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
-static struct dvb_usb_rc_key dw210x_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_dw210x_table[] = {
        { 0xf80a, KEY_Q },              /*power*/
        { 0xf80c, KEY_M },              /*mute*/
        { 0xf811, KEY_1 },
@@ -982,7 +982,7 @@ static struct dvb_usb_rc_key dw210x_rc_keys[] = {
        { 0xf81b, KEY_B },              /*recall*/
 };
 
-static struct dvb_usb_rc_key tevii_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_tevii_table[] = {
        { 0xf80a, KEY_POWER },
        { 0xf80c, KEY_MUTE },
        { 0xf811, KEY_1 },
@@ -1032,7 +1032,7 @@ static struct dvb_usb_rc_key tevii_rc_keys[] = {
        { 0xf858, KEY_SWITCHVIDEOMODE },
 };
 
-static struct dvb_usb_rc_key tbs_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_tbs_table[] = {
        { 0xf884, KEY_POWER },
        { 0xf894, KEY_MUTE },
        { 0xf887, KEY_1 },
@@ -1067,10 +1067,10 @@ static struct dvb_usb_rc_key tbs_rc_keys[] = {
        { 0xf89b, KEY_MODE }
 };
 
-static struct dvb_usb_rc_keys_table keys_tables[] = {
-       { dw210x_rc_keys, ARRAY_SIZE(dw210x_rc_keys) },
-       { tevii_rc_keys, ARRAY_SIZE(tevii_rc_keys) },
-       { tbs_rc_keys, ARRAY_SIZE(tbs_rc_keys) },
+static struct ir_codes_dvb_usb_table_table keys_tables[] = {
+       { ir_codes_dw210x_table, ARRAY_SIZE(ir_codes_dw210x_table) },
+       { ir_codes_tevii_table, ARRAY_SIZE(ir_codes_tevii_table) },
+       { ir_codes_tbs_table, ARRAY_SIZE(ir_codes_tbs_table) },
 };
 
 static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
@@ -1185,14 +1185,14 @@ static int dw2102_load_firmware(struct usb_device *dev,
                /* init registers */
                switch (dev->descriptor.idProduct) {
                case USB_PID_PROF_1100:
-                       s6x0_properties.rc_key_map = tbs_rc_keys;
+                       s6x0_properties.rc_key_map = ir_codes_tbs_table;
                        s6x0_properties.rc_key_map_size =
-                                       ARRAY_SIZE(tbs_rc_keys);
+                                       ARRAY_SIZE(ir_codes_tbs_table);
                        break;
                case USB_PID_TEVII_S650:
-                       dw2104_properties.rc_key_map = tevii_rc_keys;
+                       dw2104_properties.rc_key_map = ir_codes_tevii_table;
                        dw2104_properties.rc_key_map_size =
-                                       ARRAY_SIZE(tevii_rc_keys);
+                                       ARRAY_SIZE(ir_codes_tevii_table);
                case USB_PID_DW2104:
                        reset = 1;
                        dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
@@ -1255,8 +1255,8 @@ static struct dvb_usb_device_properties dw2102_properties = {
        .no_reconnect = 1,
 
        .i2c_algo = &dw2102_serit_i2c_algo,
-       .rc_key_map = dw210x_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
+       .rc_key_map = ir_codes_dw210x_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
        .rc_interval = 150,
        .rc_query = dw2102_rc_query,
 
@@ -1306,8 +1306,8 @@ static struct dvb_usb_device_properties dw2104_properties = {
        .no_reconnect = 1,
 
        .i2c_algo = &dw2104_i2c_algo,
-       .rc_key_map = dw210x_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
+       .rc_key_map = ir_codes_dw210x_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
        .rc_interval = 150,
        .rc_query = dw2102_rc_query,
 
@@ -1353,8 +1353,8 @@ static struct dvb_usb_device_properties dw3101_properties = {
        .no_reconnect = 1,
 
        .i2c_algo = &dw3101_i2c_algo,
-       .rc_key_map = dw210x_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
+       .rc_key_map = ir_codes_dw210x_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_dw210x_table),
        .rc_interval = 150,
        .rc_query = dw2102_rc_query,
 
@@ -1396,8 +1396,8 @@ static struct dvb_usb_device_properties s6x0_properties = {
        .no_reconnect = 1,
 
        .i2c_algo = &s6x0_i2c_algo,
-       .rc_key_map = tevii_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(tevii_rc_keys),
+       .rc_key_map = ir_codes_tevii_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_tevii_table),
        .rc_interval = 150,
        .rc_query = dw2102_rc_query,
 
@@ -1459,8 +1459,8 @@ static int dw2102_probe(struct usb_interface *intf,
        /* fill only different fields */
        p7500->firmware = "dvb-usb-p7500.fw";
        p7500->devices[0] = d7500;
-       p7500->rc_key_map = tbs_rc_keys;
-       p7500->rc_key_map_size = ARRAY_SIZE(tbs_rc_keys);
+       p7500->rc_key_map = ir_codes_tbs_table;
+       p7500->rc_key_map_size = ARRAY_SIZE(ir_codes_tbs_table);
        p7500->adapter->frontend_attach = prof_7500_frontend_attach;
 
        if (0 == dvb_usb_device_init(intf, &dw2102_properties,
index d14bd22..93c21dd 100644 (file)
@@ -300,7 +300,7 @@ static int jdvbt90502_set_frontend(struct dvb_frontend *fe,
                                   struct dvb_frontend_parameters *p)
 {
        /**
-        * NOTE: ignore all the paramters except frequency.
+        * NOTE: ignore all the parameters except frequency.
         *       others should be fixed to the proper value for ISDB-T,
         *       but don't check here.
         */
index afb444d..45106ac 100644 (file)
@@ -105,6 +105,10 @@ static int gp8psk_load_bcm4500fw(struct dvb_usb_device *d)
 
        ptr = fw->data;
        buf = kmalloc(64, GFP_KERNEL | GFP_DMA);
+       if (!buf) {
+               ret = -ENOMEM;
+               goto out_rel_fw;
+       }
 
        while (ptr[0] != 0xff) {
                u16 buflen = ptr[0] + 4;
index 737ffa3..c211fef 100644 (file)
@@ -589,7 +589,7 @@ static struct m920x_inits pinnacle310e_init[] = {
 };
 
 /* ir keymaps */
-static struct dvb_usb_rc_key megasky_rc_keys [] = {
+static struct dvb_usb_rc_key ir_codes_megasky_table [] = {
        { 0x0012, KEY_POWER },
        { 0x001e, KEY_CYCLEWINDOWS }, /* min/max */
        { 0x0002, KEY_CHANNELUP },
@@ -608,7 +608,7 @@ static struct dvb_usb_rc_key megasky_rc_keys [] = {
        { 0x000e, KEY_COFFEE }, /* "MTS" */
 };
 
-static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
+static struct dvb_usb_rc_key ir_codes_tvwalkertwin_table [] = {
        { 0x0001, KEY_ZOOM }, /* Full Screen */
        { 0x0002, KEY_CAMERA }, /* snapshot */
        { 0x0003, KEY_MUTE },
@@ -628,7 +628,7 @@ static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
        { 0x001e, KEY_VOLUMEUP },
 };
 
-static struct dvb_usb_rc_key pinnacle310e_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_pinnacle310e_table[] = {
        { 0x16, KEY_POWER },
        { 0x17, KEY_FAVORITES },
        { 0x0f, KEY_TEXT },
@@ -785,8 +785,8 @@ static struct dvb_usb_device_properties megasky_properties = {
        .download_firmware = m920x_firmware_download,
 
        .rc_interval      = 100,
-       .rc_key_map       = megasky_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(megasky_rc_keys),
+       .rc_key_map       = ir_codes_megasky_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_megasky_table),
        .rc_query         = m920x_rc_query,
 
        .size_of_priv     = sizeof(struct m920x_state),
@@ -886,8 +886,8 @@ static struct dvb_usb_device_properties tvwalkertwin_properties = {
        .download_firmware = m920x_firmware_download,
 
        .rc_interval      = 100,
-       .rc_key_map       = tvwalkertwin_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(tvwalkertwin_rc_keys),
+       .rc_key_map       = ir_codes_tvwalkertwin_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_tvwalkertwin_table),
        .rc_query         = m920x_rc_query,
 
        .size_of_priv     = sizeof(struct m920x_state),
@@ -993,8 +993,8 @@ static struct dvb_usb_device_properties pinnacle_pctv310e_properties = {
        .download_firmware = NULL,
 
        .rc_interval      = 100,
-       .rc_key_map       = pinnacle310e_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(pinnacle310e_rc_keys),
+       .rc_key_map       = ir_codes_pinnacle310e_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_pinnacle310e_table),
        .rc_query         = m920x_rc_query,
 
        .size_of_priv     = sizeof(struct m920x_state),
index b41d66e..d195a58 100644 (file)
@@ -21,7 +21,7 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 #define deb_ee(args...) dprintk(debug,0x02,args)
 
 /* Hauppauge NOVA-T USB2 keys */
-static struct dvb_usb_rc_key haupp_rc_keys [] = {
+static struct dvb_usb_rc_key ir_codes_haupp_table [] = {
        { 0x1e00, KEY_0 },
        { 0x1e01, KEY_1 },
        { 0x1e02, KEY_2 },
@@ -91,14 +91,14 @@ static int nova_t_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 
                        deb_rc("raw key code 0x%02x, 0x%02x, 0x%02x to c: %02x d: %02x toggle: %d\n",key[1],key[2],key[3],custom,data,toggle);
 
-                       for (i = 0; i < ARRAY_SIZE(haupp_rc_keys); i++) {
-                               if (rc5_data(&haupp_rc_keys[i]) == data &&
-                                       rc5_custom(&haupp_rc_keys[i]) == custom) {
+                       for (i = 0; i < ARRAY_SIZE(ir_codes_haupp_table); i++) {
+                               if (rc5_data(&ir_codes_haupp_table[i]) == data &&
+                                       rc5_custom(&ir_codes_haupp_table[i]) == custom) {
 
-                                       deb_rc("c: %x, d: %x\n", rc5_data(&haupp_rc_keys[i]),
-                                                                rc5_custom(&haupp_rc_keys[i]));
+                                       deb_rc("c: %x, d: %x\n", rc5_data(&ir_codes_haupp_table[i]),
+                                                                rc5_custom(&ir_codes_haupp_table[i]));
 
-                                       *event = haupp_rc_keys[i].event;
+                                       *event = ir_codes_haupp_table[i].event;
                                        *state = REMOTE_KEY_PRESSED;
                                        if (st->old_toggle == toggle) {
                                                if (st->last_repeat_count++ < 2)
@@ -196,8 +196,8 @@ static struct dvb_usb_device_properties nova_t_properties = {
        .read_mac_address = nova_t_read_mac_address,
 
        .rc_interval      = 100,
-       .rc_key_map       = haupp_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(haupp_rc_keys),
+       .rc_key_map       = ir_codes_haupp_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_haupp_table),
        .rc_query         = nova_t_rc_query,
 
        .i2c_algo         = &dibusb_i2c_algo,
index 8305576..dfb81ff 100644 (file)
@@ -35,7 +35,7 @@
 struct opera1_state {
        u32 last_key_pressed;
 };
-struct opera_rc_keys {
+struct ir_codes_opera_table {
        u32 keycode;
        u32 event;
 };
@@ -331,7 +331,7 @@ static int opera1_pid_filter_control(struct dvb_usb_adapter *adap, int onoff)
        return 0;
 }
 
-static struct dvb_usb_rc_key opera1_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_opera1_table[] = {
        {0x5fa0, KEY_1},
        {0x51af, KEY_2},
        {0x5da2, KEY_3},
@@ -404,12 +404,12 @@ static int opera1_rc_query(struct dvb_usb_device *dev, u32 * event, int *state)
 
                send_key = (send_key & 0xffff) | 0x0100;
 
-               for (i = 0; i < ARRAY_SIZE(opera1_rc_keys); i++) {
-                       if (rc5_scan(&opera1_rc_keys[i]) == (send_key & 0xffff)) {
+               for (i = 0; i < ARRAY_SIZE(ir_codes_opera1_table); i++) {
+                       if (rc5_scan(&ir_codes_opera1_table[i]) == (send_key & 0xffff)) {
                                *state = REMOTE_KEY_PRESSED;
-                               *event = opera1_rc_keys[i].event;
+                               *event = ir_codes_opera1_table[i].event;
                                opst->last_key_pressed =
-                                       opera1_rc_keys[i].event;
+                                       ir_codes_opera1_table[i].event;
                                break;
                        }
                        opst->last_key_pressed = 0;
@@ -498,8 +498,8 @@ static struct dvb_usb_device_properties opera1_properties = {
        .power_ctrl = opera1_power_ctrl,
        .i2c_algo = &opera1_i2c_algo,
 
-       .rc_key_map = opera1_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(opera1_rc_keys),
+       .rc_key_map = ir_codes_opera1_table,
+       .rc_key_map_size = ARRAY_SIZE(ir_codes_opera1_table),
        .rc_interval = 200,
        .rc_query = opera1_rc_query,
        .read_mac_address = opera1_read_mac_address,
index ef4e37d..4d33245 100644 (file)
@@ -174,7 +174,7 @@ static int vp702x_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 }
 
 /* keys for the enclosed remote control */
-static struct dvb_usb_rc_key vp702x_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_vp702x_table[] = {
        { 0x0001, KEY_1 },
        { 0x0002, KEY_2 },
 };
@@ -197,10 +197,10 @@ static int vp702x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
                return 0;
        }
 
-       for (i = 0; i < ARRAY_SIZE(vp702x_rc_keys); i++)
-               if (rc5_custom(&vp702x_rc_keys[i]) == key[1]) {
+       for (i = 0; i < ARRAY_SIZE(ir_codes_vp702x_table); i++)
+               if (rc5_custom(&ir_codes_vp702x_table[i]) == key[1]) {
                        *state = REMOTE_KEY_PRESSED;
-                       *event = vp702x_rc_keys[i].event;
+                       *event = ir_codes_vp702x_table[i].event;
                        break;
                }
        return 0;
@@ -283,8 +283,8 @@ static struct dvb_usb_device_properties vp702x_properties = {
        },
        .read_mac_address = vp702x_read_mac_addr,
 
-       .rc_key_map       = vp702x_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(vp702x_rc_keys),
+       .rc_key_map       = ir_codes_vp702x_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_vp702x_table),
        .rc_interval      = 400,
        .rc_query         = vp702x_rc_query,
 
index a59faa2..036893f 100644 (file)
@@ -99,7 +99,7 @@ static int vp7045_power_ctrl(struct dvb_usb_device *d, int onoff)
 
 /* The keymapping struct. Somehow this should be loaded to the driver, but
  * currently it is hardcoded. */
-static struct dvb_usb_rc_key vp7045_rc_keys[] = {
+static struct dvb_usb_rc_key ir_codes_vp7045_table[] = {
        { 0x0016, KEY_POWER },
        { 0x0010, KEY_MUTE },
        { 0x0003, KEY_1 },
@@ -165,10 +165,10 @@ static int vp7045_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
                return 0;
        }
 
-       for (i = 0; i < ARRAY_SIZE(vp7045_rc_keys); i++)
-               if (rc5_data(&vp7045_rc_keys[i]) == key) {
+       for (i = 0; i < ARRAY_SIZE(ir_codes_vp7045_table); i++)
+               if (rc5_data(&ir_codes_vp7045_table[i]) == key) {
                        *state = REMOTE_KEY_PRESSED;
-                       *event = vp7045_rc_keys[i].event;
+                       *event = ir_codes_vp7045_table[i].event;
                        break;
                }
        return 0;
@@ -260,8 +260,8 @@ static struct dvb_usb_device_properties vp7045_properties = {
        .read_mac_address = vp7045_read_mac_addr,
 
        .rc_interval      = 400,
-       .rc_key_map       = vp7045_rc_keys,
-       .rc_key_map_size  = ARRAY_SIZE(vp7045_rc_keys),
+       .rc_key_map       = ir_codes_vp7045_table,
+       .rc_key_map_size  = ARRAY_SIZE(ir_codes_vp7045_table),
        .rc_query         = vp7045_rc_query,
 
        .num_device_descs = 2,
index 1b31beb..28294af 100644 (file)
@@ -1096,7 +1096,7 @@ int avc_ca_pmt(struct firedtv *fdtv, char *msg, int length)
 
        c->operand[15] = msg[1]; /* Program number */
        c->operand[16] = msg[2];
-       c->operand[17] = 0x01; /* Version number=0 + current/next=1 */
+       c->operand[17] = msg[3]; /* Version number and current/next */
        c->operand[18] = 0x00; /* Section number=0 */
        c->operand[19] = 0x00; /* Last section number=0 */
        c->operand[20] = 0x1f; /* PCR_PID=1FFF */
index ce960f7..d460058 100644 (file)
@@ -18,7 +18,7 @@
  *    along with this program; if not, write to the Free Software
  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
+
 #ifndef __ATBM8830_PRIV_H
 #define __ATBM8830_PRIV_H
 
index 24268ef..68dba3a 100644 (file)
@@ -664,6 +664,13 @@ static int au8522_reset(struct v4l2_subdev *sd, u32 val)
 {
        struct au8522_state *state = to_state(sd);
 
+       state->operational_mode = AU8522_ANALOG_MODE;
+
+       /* Clear out any state associated with the digital side of the
+          chip, so that when it gets powered back up it won't think
+          that it is already tuned */
+       state->current_frequency = 0;
+
        au8522_writereg(state, 0xa4, 1 << 5);
 
        return 0;
index a1fed0f..65f6a36 100644 (file)
@@ -84,6 +84,14 @@ static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
 
        dprintk("%s(%d)\n", __func__, enable);
 
+       if (state->operational_mode == AU8522_ANALOG_MODE) {
+               /* We're being asked to manage the gate even though we're
+                  not in digital mode.  This can occur if we get switched
+                  over to analog mode before the dvb_frontend kernel thread
+                  has completely shutdown */
+               return 0;
+       }
+
        if (enable)
                return au8522_writereg(state, 0x106, 1);
        else
@@ -608,6 +616,13 @@ int au8522_init(struct dvb_frontend *fe)
        struct au8522_state *state = fe->demodulator_priv;
        dprintk("%s()\n", __func__);
 
+       state->operational_mode = AU8522_DIGITAL_MODE;
+
+       /* Clear out any state associated with the digital side of the
+          chip, so that when it gets powered back up it won't think
+          that it is already tuned */
+       state->current_frequency = 0;
+
        au8522_writereg(state, 0xa4, 1 << 5);
 
        au8522_i2c_gate_ctrl(fe, 1);
@@ -704,6 +719,15 @@ int au8522_sleep(struct dvb_frontend *fe)
        struct au8522_state *state = fe->demodulator_priv;
        dprintk("%s()\n", __func__);
 
+       /* Only power down if the digital side is currently using the chip */
+       if (state->operational_mode == AU8522_ANALOG_MODE) {
+               /* We're not in one of the expected power modes, which means
+                  that the DVB thread is probably telling us to go to sleep
+                  even though the analog frontend has already started using
+                  the chip.  So ignore the request */
+               return 0;
+       }
+
        /* turn off led */
        au8522_led_ctrl(state, 0);
 
@@ -932,6 +956,8 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config,
        /* setup the state */
        state->config = config;
        state->i2c = i2c;
+       state->operational_mode = AU8522_DIGITAL_MODE;
+
        /* create dvb_frontend */
        memcpy(&state->frontend.ops, &au8522_ops,
               sizeof(struct dvb_frontend_ops));
index c74c4e7..609cf04 100644 (file)
 #include "au8522.h"
 #include "tuner-i2c.h"
 
+#define AU8522_ANALOG_MODE 0
+#define AU8522_DIGITAL_MODE 1
+
 struct au8522_state {
        struct i2c_client *c;
        struct i2c_adapter *i2c;
 
+       u8 operational_mode;
+
        /* Used for sharing of the state between analog and digital mode */
        struct tuner_i2c_props i2c_props;
        struct list_head hybrid_tuner_instance_list;
index 40a0998..afad252 100644 (file)
@@ -814,42 +814,51 @@ EXPORT_SYMBOL(dib3000mc_set_config);
 
 int dib3000mc_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib3000mc_config cfg[])
 {
-       struct dib3000mc_state st = { .i2c_adap = i2c };
+       struct dib3000mc_state *dmcst;
        int k;
        u8 new_addr;
 
        static u8 DIB3000MC_I2C_ADDRESS[] = {20,22,24,26};
 
+       dmcst = kzalloc(sizeof(struct dib3000mc_state), GFP_KERNEL);
+       if (dmcst == NULL)
+               return -ENODEV;
+
+       dmcst->i2c_adap = i2c;
+
        for (k = no_of_demods-1; k >= 0; k--) {
-               st.cfg = &cfg[k];
+               dmcst->cfg = &cfg[k];
 
                /* designated i2c address */
                new_addr          = DIB3000MC_I2C_ADDRESS[k];
-               st.i2c_addr = new_addr;
-               if (dib3000mc_identify(&st) != 0) {
-                       st.i2c_addr = default_addr;
-                       if (dib3000mc_identify(&st) != 0) {
+               dmcst->i2c_addr = new_addr;
+               if (dib3000mc_identify(dmcst) != 0) {
+                       dmcst->i2c_addr = default_addr;
+                       if (dib3000mc_identify(dmcst) != 0) {
                                dprintk("-E-  DiB3000P/MC #%d: not identified\n", k);
+                               kfree(dmcst);
                                return -ENODEV;
                        }
                }
 
-               dib3000mc_set_output_mode(&st, OUTMODE_MPEG2_PAR_CONT_CLK);
+               dib3000mc_set_output_mode(dmcst, OUTMODE_MPEG2_PAR_CONT_CLK);
 
                // set new i2c address and force divstr (Bit 1) to value 0 (Bit 0)
-               dib3000mc_write_word(&st, 1024, (new_addr << 3) | 0x1);
-               st.i2c_addr = new_addr;
+               dib3000mc_write_word(dmcst, 1024, (new_addr << 3) | 0x1);
+               dmcst->i2c_addr = new_addr;
        }
 
        for (k = 0; k < no_of_demods; k++) {
-               st.cfg = &cfg[k];
-               st.i2c_addr = DIB3000MC_I2C_ADDRESS[k];
+               dmcst->cfg = &cfg[k];
+               dmcst->i2c_addr = DIB3000MC_I2C_ADDRESS[k];
 
-               dib3000mc_write_word(&st, 1024, st.i2c_addr << 3);
+               dib3000mc_write_word(dmcst, 1024, dmcst->i2c_addr << 3);
 
                /* turn off data output */
-               dib3000mc_set_output_mode(&st, OUTMODE_HIGH_Z);
+               dib3000mc_set_output_mode(dmcst, OUTMODE_HIGH_Z);
        }
+
+       kfree(dmcst);
        return 0;
 }
 EXPORT_SYMBOL(dib3000mc_i2c_enumeration);
index 85468a4..2e28b97 100644 (file)
@@ -1324,46 +1324,54 @@ EXPORT_SYMBOL(dib7000p_pid_filter);
 
 int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[])
 {
-       struct dib7000p_state st = { .i2c_adap = i2c };
+       struct dib7000p_state *dpst;
        int k = 0;
        u8 new_addr = 0;
 
+       dpst = kzalloc(sizeof(struct dib7000p_state), GFP_KERNEL);
+       if (!dpst)
+               return -ENOMEM;
+
+       dpst->i2c_adap = i2c;
+
        for (k = no_of_demods-1; k >= 0; k--) {
-               st.cfg = cfg[k];
+               dpst->cfg = cfg[k];
 
                /* designated i2c address */
                new_addr          = (0x40 + k) << 1;
-               st.i2c_addr = new_addr;
-               dib7000p_write_word(&st, 1287, 0x0003); /* sram lead in, rdy */
-               if (dib7000p_identify(&st) != 0) {
-                       st.i2c_addr = default_addr;
-                       dib7000p_write_word(&st, 1287, 0x0003); /* sram lead in, rdy */
-                       if (dib7000p_identify(&st) != 0) {
+               dpst->i2c_addr = new_addr;
+               dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
+               if (dib7000p_identify(dpst) != 0) {
+                       dpst->i2c_addr = default_addr;
+                       dib7000p_write_word(dpst, 1287, 0x0003); /* sram lead in, rdy */
+                       if (dib7000p_identify(dpst) != 0) {
                                dprintk("DiB7000P #%d: not identified\n", k);
+                               kfree(dpst);
                                return -EIO;
                        }
                }
 
                /* start diversity to pull_down div_str - just for i2c-enumeration */
-               dib7000p_set_output_mode(&st, OUTMODE_DIVERSITY);
+               dib7000p_set_output_mode(dpst, OUTMODE_DIVERSITY);
 
                /* set new i2c address and force divstart */
-               dib7000p_write_word(&st, 1285, (new_addr << 2) | 0x2);
+               dib7000p_write_word(dpst, 1285, (new_addr << 2) | 0x2);
 
                dprintk("IC %d initialized (to i2c_address 0x%x)", k, new_addr);
        }
 
        for (k = 0; k < no_of_demods; k++) {
-               st.cfg = cfg[k];
-               st.i2c_addr = (0x40 + k) << 1;
+               dpst->cfg = cfg[k];
+               dpst->i2c_addr = (0x40 + k) << 1;
 
                // unforce divstr
-               dib7000p_write_word(&st, 1285, st.i2c_addr << 2);
+               dib7000p_write_word(dpst, 1285, dpst->i2c_addr << 2);
 
                /* deactivate div - it was just for i2c-enumeration */
-               dib7000p_set_output_mode(&st, OUTMODE_HIGH_Z);
+               dib7000p_set_output_mode(dpst, OUTMODE_HIGH_Z);
        }
 
+       kfree(dpst);
        return 0;
 }
 EXPORT_SYMBOL(dib7000p_i2c_enumeration);
index b1ee207..e0a9ded 100644 (file)
@@ -109,6 +109,7 @@ static inline void dib8000_pwm_agc_reset(struct dvb_frontend *fe)
 static inline s32 dib8000_get_adc_power(struct dvb_frontend *fe, u8 mode)
 {
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return 0;
 }
 #endif
 
index cff3535..78001e8 100644 (file)
@@ -719,7 +719,7 @@ static int ds3000_read_snr(struct dvb_frontend *fe, u16 *snr)
                                (ds3000_readreg(state, 0x8d) << 4);
                dvbs2_signal_reading = ds3000_readreg(state, 0x8e);
                tmp = dvbs2_signal_reading * dvbs2_signal_reading >> 1;
-               if (dvbs2_signal_reading == 0) {
+               if (tmp == 0) {
                        *snr = 0x0000;
                        return 0;
                }
index 01f8f1f..4f5e7d3 100644 (file)
@@ -1583,7 +1583,7 @@ static enum dvbfe_search stv0900_search(struct dvb_frontend *fe,
        struct dtv_frontend_properties *c = &fe->dtv_property_cache;
 
        struct stv0900_search_params p_search;
-       struct stv0900_signal_info p_result;
+       struct stv0900_signal_info p_result = intp->result[demod];
 
        enum fe_stv0900_error error = STV0900_NO_ERROR;
 
@@ -1842,6 +1842,19 @@ static void stv0900_release(struct dvb_frontend *fe)
        kfree(state);
 }
 
+static int stv0900_get_frontend(struct dvb_frontend *fe,
+                               struct dvb_frontend_parameters *p)
+{
+       struct stv0900_state *state = fe->demodulator_priv;
+       struct stv0900_internal *intp = state->internal;
+       enum fe_stv0900_demod_num demod = state->demod;
+       struct stv0900_signal_info p_result = intp->result[demod];
+
+       p->frequency = p_result.locked ? p_result.frequency : 0;
+       p->u.qpsk.symbol_rate = p_result.locked ? p_result.symbol_rate : 0;
+       return 0;
+}
+
 static struct dvb_frontend_ops stv0900_ops = {
 
        .info = {
@@ -1862,6 +1875,7 @@ static struct dvb_frontend_ops stv0900_ops = {
        },
        .release                        = stv0900_release,
        .init                           = stv0900_init,
+       .get_frontend                   = stv0900_get_frontend,
        .get_frontend_algo              = stv0900_frontend_algo,
        .i2c_gate_ctrl                  = stv0900_i2c_gate_ctrl,
        .diseqc_send_master_cmd         = stv0900_send_master_cmd,
index 9697280..425e7a4 100644 (file)
@@ -754,11 +754,19 @@ static int stv090x_write_reg(struct stv090x_state *state, unsigned int reg, u8 d
        return stv090x_write_regs(state, reg, &data, 1);
 }
 
-static int stv090x_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
+static int stv090x_i2c_gate_ctrl(struct stv090x_state *state, int enable)
 {
-       struct stv090x_state *state = fe->demodulator_priv;
        u32 reg;
 
+       /*
+        * NOTE! A lock is used as a FSM to control the state in which
+        * access is serialized between two tuners on the same demod.
+        * This has nothing to do with a lock to protect a critical section
+        * which may in some other cases be confused with protecting I/O
+        * access to the demodulator gate.
+        * In case of any error, the lock is unlocked and exit within the
+        * relevant operations themselves.
+        */
        if (enable)
                mutex_lock(&state->internal->tuner_lock);
 
@@ -1778,7 +1786,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
                                freq -= cur_step * car_step;
 
                        /* Setup tuner */
-                       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+                       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                                goto err;
 
                        if (state->config->tuner_set_frequency) {
@@ -1791,12 +1799,12 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
                                        goto err_gateoff;
                        }
 
-                       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+                       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                                goto err;
 
                        msleep(50);
 
-                       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+                       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                                goto err;
 
                        if (state->config->tuner_get_status) {
@@ -1809,7 +1817,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
                        else
                                dprintk(FE_DEBUG, 1, "Tuner unlocked");
 
-                       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+                       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                                goto err;
 
                }
@@ -1822,7 +1830,7 @@ static u32 stv090x_srate_srch_coarse(struct stv090x_state *state)
        return srate_coarse;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -2167,7 +2175,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
                                                freq -= cur_step * car_step;
 
                                        /* Setup tuner */
-                                       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+                                       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                                                goto err;
 
                                        if (state->config->tuner_set_frequency) {
@@ -2180,12 +2188,12 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
                                                        goto err_gateoff;
                                        }
 
-                                       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+                                       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                                                goto err;
 
                                        msleep(50);
 
-                                       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+                                       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                                                goto err;
 
                                        if (state->config->tuner_get_status) {
@@ -2198,7 +2206,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
                                        else
                                                dprintk(FE_DEBUG, 1, "Tuner unlocked");
 
-                                       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+                                       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                                                goto err;
 
                                        STV090x_WRITE_DEMOD(state, DMDISTATE, 0x1c);
@@ -2222,7 +2230,7 @@ static int stv090x_get_coldlock(struct stv090x_state *state, s32 timeout_dmd)
        return lock;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -2591,7 +2599,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
        }
        state->delsys = stv090x_get_std(state);
 
-       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                goto err;
 
        if (state->config->tuner_get_frequency) {
@@ -2599,7 +2607,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
                        goto err_gateoff;
        }
 
-       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                goto err;
 
        offst_freq = stv090x_get_car_freq(state, state->internal->mclk) / 1000;
@@ -2619,7 +2627,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
 
        if ((state->algo == STV090x_BLIND_SEARCH) || (state->srate < 10000000)) {
 
-               if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+               if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                        goto err;
 
                if (state->config->tuner_get_frequency) {
@@ -2627,7 +2635,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
                                goto err_gateoff;
                }
 
-               if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+               if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                        goto err;
 
                if (abs(offst_freq) <= ((state->search_range / 2000) + 500))
@@ -2646,7 +2654,7 @@ static enum stv090x_signal_state stv090x_get_sig_params(struct stv090x_state *st
        return STV090x_OUTOFRANGE;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -3000,7 +3008,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
 
                        if (state->algo != STV090x_WARM_SEARCH) {
 
-                               if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+                               if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                                        goto err;
 
                                if (state->config->tuner_set_bandwidth) {
@@ -3008,7 +3016,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
                                                goto err_gateoff;
                                }
 
-                               if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+                               if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                                        goto err;
 
                        }
@@ -3059,7 +3067,7 @@ static int stv090x_optimize_track(struct stv090x_state *state)
        return 0;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -3235,7 +3243,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
        }
 
        /* Setup tuner */
-       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                goto err;
 
        if (state->config->tuner_set_bbgain) {
@@ -3256,17 +3264,17 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
                        goto err_gateoff;
        }
 
-       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                goto err;
 
        msleep(50);
 
        if (state->config->tuner_get_status) {
-               if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+               if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                        goto err;
                if (state->config->tuner_get_status(fe, &reg) < 0)
                        goto err_gateoff;
-               if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+               if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                        goto err;
 
                if (reg)
@@ -3400,7 +3408,7 @@ static enum stv090x_signal_state stv090x_algo(struct stv090x_state *state)
        return signal_state;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -3839,6 +3847,17 @@ static int stv090x_sleep(struct dvb_frontend *fe)
        struct stv090x_state *state = fe->demodulator_priv;
        u32 reg;
 
+       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
+               goto err;
+
+       if (state->config->tuner_sleep) {
+               if (state->config->tuner_sleep(fe) < 0)
+                       goto err_gateoff;
+       }
+
+       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
+               goto err;
+
        dprintk(FE_DEBUG, 1, "Set %s to sleep",
                state->device == STV0900 ? "STV0900" : "STV0903");
 
@@ -3853,6 +3872,9 @@ static int stv090x_sleep(struct dvb_frontend *fe)
                goto err;
 
        return 0;
+
+err_gateoff:
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -4311,6 +4333,20 @@ static int stv090x_init(struct dvb_frontend *fe)
        u32 reg;
 
        if (state->internal->mclk == 0) {
+               /* call tuner init to configure the tuner's clock output
+                  divider directly before setting up the master clock of
+                  the stv090x. */
+               if (stv090x_i2c_gate_ctrl(state, 1) < 0)
+                       goto err;
+
+               if (config->tuner_init) {
+                       if (config->tuner_init(fe) < 0)
+                               goto err_gateoff;
+               }
+
+               if (stv090x_i2c_gate_ctrl(state, 0) < 0)
+                       goto err;
+
                stv090x_set_mclk(state, 135000000, config->xtal); /* 135 Mhz */
                msleep(5);
                if (stv090x_write_reg(state, STV090x_SYNTCTRL,
@@ -4336,7 +4372,7 @@ static int stv090x_init(struct dvb_frontend *fe)
        if (STV090x_WRITE_DEMOD(state, DEMOD, reg) < 0)
                goto err;
 
-       if (stv090x_i2c_gate_ctrl(fe, 1) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 1) < 0)
                goto err;
 
        if (config->tuner_set_mode) {
@@ -4349,7 +4385,7 @@ static int stv090x_init(struct dvb_frontend *fe)
                        goto err_gateoff;
        }
 
-       if (stv090x_i2c_gate_ctrl(fe, 0) < 0)
+       if (stv090x_i2c_gate_ctrl(state, 0) < 0)
                goto err;
 
        if (stv090x_set_tspath(state) < 0)
@@ -4358,7 +4394,7 @@ static int stv090x_init(struct dvb_frontend *fe)
        return 0;
 
 err_gateoff:
-       stv090x_i2c_gate_ctrl(fe, 0);
+       stv090x_i2c_gate_ctrl(state, 0);
 err:
        dprintk(FE_ERROR, 1, "I/O error");
        return -1;
@@ -4503,8 +4539,6 @@ static struct dvb_frontend_ops stv090x_ops = {
        .sleep                          = stv090x_sleep,
        .get_frontend_algo              = stv090x_frontend_algo,
 
-       .i2c_gate_ctrl                  = stv090x_i2c_gate_ctrl,
-
        .diseqc_send_master_cmd         = stv090x_send_diseqc_msg,
        .diseqc_send_burst              = stv090x_send_diseqc_burst,
        .diseqc_recv_slave_reply        = stv090x_recv_slave_reply,
index 30f01a6..dd1b93a 100644 (file)
@@ -87,6 +87,7 @@ struct stv090x_config {
        bool diseqc_envelope_mode;
 
        int (*tuner_init) (struct dvb_frontend *fe);
+       int (*tuner_sleep) (struct dvb_frontend *fe);
        int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode);
        int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency);
        int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency);
index dea4245..42591ce 100644 (file)
@@ -338,14 +338,12 @@ static struct dvb_tuner_ops stv6110x_ops = {
                .frequency_max  = 2150000,
                .frequency_step = 0,
        },
-
-       .init                   = stv6110x_init,
-       .sleep                  = stv6110x_sleep,
        .release                = stv6110x_release
 };
 
 static struct stv6110x_devctl stv6110x_ctl = {
        .tuner_init             = stv6110x_init,
+       .tuner_sleep            = stv6110x_sleep,
        .tuner_set_mode         = stv6110x_set_mode,
        .tuner_set_frequency    = stv6110x_set_frequency,
        .tuner_get_frequency    = stv6110x_get_frequency,
@@ -363,11 +361,10 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
 {
        struct stv6110x_state *stv6110x;
        u8 default_regs[] = {0x07, 0x11, 0xdc, 0x85, 0x17, 0x01, 0xe6, 0x1e};
-       int ret;
 
        stv6110x = kzalloc(sizeof (struct stv6110x_state), GFP_KERNEL);
-       if (stv6110x == NULL)
-               goto error;
+       if (!stv6110x)
+               return NULL;
 
        stv6110x->i2c           = i2c;
        stv6110x->config        = config;
@@ -392,34 +389,11 @@ struct stv6110x_devctl *stv6110x_attach(struct dvb_frontend *fe,
                break;
        }
 
-       if (fe->ops.i2c_gate_ctrl) {
-               ret = fe->ops.i2c_gate_ctrl(fe, 1);
-               if (ret < 0)
-                       goto error;
-       }
-
-       ret = stv6110x_write_regs(stv6110x, 0, stv6110x->regs,
-                                 ARRAY_SIZE(stv6110x->regs));
-       if (ret < 0) {
-               dprintk(FE_ERROR, 1, "Initialization failed");
-               goto error;
-       }
-
-       if (fe->ops.i2c_gate_ctrl) {
-               ret = fe->ops.i2c_gate_ctrl(fe, 0);
-               if (ret < 0)
-                       goto error;
-       }
-
        fe->tuner_priv          = stv6110x;
        fe->ops.tuner_ops       = stv6110x_ops;
 
-       printk("%s: Attaching STV6110x \n", __func__);
+       printk(KERN_INFO "%s: Attaching STV6110x\n", __func__);
        return stv6110x->devctl;
-
-error:
-       kfree(stv6110x);
-       return NULL;
 }
 EXPORT_SYMBOL(stv6110x_attach);
 
index 2429ae6..4751675 100644 (file)
@@ -40,6 +40,7 @@ enum tuner_status {
 
 struct stv6110x_devctl {
        int (*tuner_init) (struct dvb_frontend *fe);
+       int (*tuner_sleep) (struct dvb_frontend *fe);
        int (*tuner_set_mode) (struct dvb_frontend *fe, enum tuner_mode mode);
        int (*tuner_set_frequency) (struct dvb_frontend *fe, u32 frequency);
        int (*tuner_get_frequency) (struct dvb_frontend *fe, u32 *frequency);
index 4675a3b..3d4e466 100644 (file)
@@ -32,6 +32,8 @@
 #include "mantis_reg.h"
 #include "mantis_uart.h"
 
+#define MODULE_NAME "mantis_core"
+
 static struct ir_scancode mantis_ir_table[] = {
        { 0x29, KEY_POWER       },
        { 0x28, KEY_FAVORITES   },
@@ -126,7 +128,7 @@ int mantis_input_init(struct mantis_pci *mantis)
        rc->id.version  = 1;
        rc->dev         = mantis->pdev->dev;
 
-       err = ir_input_register(rc, &ir_mantis, NULL);
+       err = __ir_input_register(rc, &ir_mantis, NULL, MODULE_NAME);
        if (err) {
                dprintk(MANTIS_ERROR, 1, "IR device registration failed, ret = %d", err);
                input_free_device(rc);
index 515346d..d1aa2bc 100644 (file)
@@ -136,12 +136,12 @@ static const struct stb0899_s1_reg vp1041_stb0899_s1_init_3[] = {
        { STB0899_RCOMPC                , 0xc9 },
        { STB0899_AGC1CN                , 0x01 },
        { STB0899_AGC1REF               , 0x10 },
-       { STB0899_RTC                   , 0x23 },
+       { STB0899_RTC                   , 0x23 },
        { STB0899_TMGCFG                , 0x4e },
        { STB0899_AGC2REF               , 0x34 },
        { STB0899_TLSR                  , 0x84 },
        { STB0899_CFD                   , 0xf7 },
-       { STB0899_ACLC                  , 0x87 },
+       { STB0899_ACLC                  , 0x87 },
        { STB0899_BCLC                  , 0x94 },
        { STB0899_EQON                  , 0x41 },
        { STB0899_LDT                   , 0xf1 },
@@ -194,10 +194,10 @@ static const struct stb0899_s1_reg vp1041_stb0899_s1_init_3[] = {
        { STB0899_ECNT3M                , 0x0a },
        { STB0899_ECNT3L                , 0xad },
        { STB0899_FECAUTO1              , 0x06 },
-       { STB0899_FECM                  , 0x01 },
+       { STB0899_FECM                  , 0x01 },
        { STB0899_VTH12                 , 0xb0 },
        { STB0899_VTH23                 , 0x7a },
-       { STB0899_VTH34                 , 0x58 },
+       { STB0899_VTH34                 , 0x58 },
        { STB0899_VTH56                 , 0x38 },
        { STB0899_VTH67                 , 0x34 },
        { STB0899_VTH78                 , 0x24 },
@@ -206,7 +206,7 @@ static const struct stb0899_s1_reg vp1041_stb0899_s1_init_3[] = {
        { STB0899_RSULC                 , 0xb1 }, /* DVB = 0xb1, DSS = 0xa1 */
        { STB0899_TSULC                 , 0x42 },
        { STB0899_RSLLC                 , 0x41 },
-       { STB0899_TSLPL                 , 0x12 },
+       { STB0899_TSLPL                 , 0x12 },
        { STB0899_TSCFGH                , 0x0c },
        { STB0899_TSCFGM                , 0x00 },
        { STB0899_TSCFGL                , 0x00 },
index 3ec8e6f..cec242b 100644 (file)
@@ -4,6 +4,8 @@ config DVB_NGENE
        select DVB_LNBP21 if !DVB_FE_CUSTOMISE
        select DVB_STV6110x if !DVB_FE_CUSTOMISE
        select DVB_STV090x if !DVB_FE_CUSTOMISE
+       select DVB_LGDT330X if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMISE
        ---help---
          Support for Micronas PCI express cards with nGene bridge.
 
index 40435ca..0608aab 100644 (file)
@@ -2,10 +2,10 @@
 # Makefile for the nGene device driver
 #
 
-ngene-objs := ngene-core.o
+ngene-objs := ngene-core.o ngene-i2c.o ngene-cards.o ngene-dvb.o
 
 obj-$(CONFIG_DVB_NGENE) += ngene.o
 
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
 EXTRA_CFLAGS += -Idrivers/media/dvb/frontends/
-
+EXTRA_CFLAGS += -Idrivers/media/common/tuners/
diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
new file mode 100644 (file)
index 0000000..692c3e2
--- /dev/null
@@ -0,0 +1,328 @@
+/*
+ * ngene-cards.c: nGene PCIe bridge driver - card specific info
+ *
+ * Copyright (C) 2005-2007 Micronas
+ *
+ * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Modifications for new nGene firmware,
+ *                         support for EEPROM-copying,
+ *                         support for new dual DVB-S2 card prototype
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/pci_ids.h>
+
+#include "ngene.h"
+
+/* demods/tuners */
+#include "stv6110x.h"
+#include "stv090x.h"
+#include "lnbh24.h"
+#include "lgdt330x.h"
+#include "mt2131.h"
+
+
+/****************************************************************************/
+/* Demod/tuner attachment ***************************************************/
+/****************************************************************************/
+
+static int tuner_attach_stv6110(struct ngene_channel *chan)
+{
+       struct stv090x_config *feconf = (struct stv090x_config *)
+               chan->dev->card_info->fe_config[chan->number];
+       struct stv6110x_config *tunerconf = (struct stv6110x_config *)
+               chan->dev->card_info->tuner_config[chan->number];
+       struct stv6110x_devctl *ctl;
+
+       ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf,
+                        &chan->i2c_adapter);
+       if (ctl == NULL) {
+               printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
+               return -ENODEV;
+       }
+
+       feconf->tuner_init          = ctl->tuner_init;
+       feconf->tuner_set_mode      = ctl->tuner_set_mode;
+       feconf->tuner_set_frequency = ctl->tuner_set_frequency;
+       feconf->tuner_get_frequency = ctl->tuner_get_frequency;
+       feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
+       feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
+       feconf->tuner_set_bbgain    = ctl->tuner_set_bbgain;
+       feconf->tuner_get_bbgain    = ctl->tuner_get_bbgain;
+       feconf->tuner_set_refclk    = ctl->tuner_set_refclk;
+       feconf->tuner_get_status    = ctl->tuner_get_status;
+
+       return 0;
+}
+
+
+static int demod_attach_stv0900(struct ngene_channel *chan)
+{
+       struct stv090x_config *feconf = (struct stv090x_config *)
+               chan->dev->card_info->fe_config[chan->number];
+
+       chan->fe = dvb_attach(stv090x_attach,
+                       feconf,
+                       &chan->i2c_adapter,
+                       chan->number == 0 ? STV090x_DEMODULATOR_0 :
+                                           STV090x_DEMODULATOR_1);
+       if (chan->fe == NULL) {
+               printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
+               return -ENODEV;
+       }
+
+       if (!dvb_attach(lnbh24_attach, chan->fe, &chan->i2c_adapter, 0,
+                       0, chan->dev->card_info->lnb[chan->number])) {
+               printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
+               dvb_frontend_detach(chan->fe);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
+static struct lgdt330x_config aver_m780 = {
+       .demod_address = 0xb2 >> 1,
+       .demod_chip    = LGDT3303,
+       .serial_mpeg   = 0x00, /* PARALLEL */
+       .clock_polarity_flip = 1,
+};
+
+static struct mt2131_config m780_tunerconfig = {
+       0xc0 >> 1
+};
+
+/* A single func to attach the demo and tuner, rather than
+ * use two sep funcs like the current design mandates.
+ */
+static int demod_attach_lg330x(struct ngene_channel *chan)
+{
+       chan->fe = dvb_attach(lgdt330x_attach, &aver_m780, &chan->i2c_adapter);
+       if (chan->fe == NULL) {
+               printk(KERN_ERR DEVICE_NAME ": No LGDT330x found!\n");
+               return -ENODEV;
+       }
+
+       dvb_attach(mt2131_attach, chan->fe, &chan->i2c_adapter,
+                  &m780_tunerconfig, 0);
+
+       return (chan->fe) ? 0 : -ENODEV;
+}
+
+/****************************************************************************/
+/* Switch control (I2C gates, etc.) *****************************************/
+/****************************************************************************/
+
+
+static struct stv090x_config fe_cineS2 = {
+       .device         = STV0900,
+       .demod_mode     = STV090x_DUAL,
+       .clk_mode       = STV090x_CLK_EXT,
+
+       .xtal           = 27000000,
+       .address        = 0x68,
+
+       .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
+       .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
+
+       .repeater_level = STV090x_RPTLEVEL_16,
+
+       .adc1_range     = STV090x_ADC_1Vpp,
+       .adc2_range     = STV090x_ADC_1Vpp,
+
+       .diseqc_envelope_mode = true,
+};
+
+static struct stv6110x_config tuner_cineS2_0 = {
+       .addr   = 0x60,
+       .refclk = 27000000,
+       .clk_div = 1,
+};
+
+static struct stv6110x_config tuner_cineS2_1 = {
+       .addr   = 0x63,
+       .refclk = 27000000,
+       .clk_div = 1,
+};
+
+static struct ngene_info ngene_info_cineS2 = {
+       .type           = NGENE_SIDEWINDER,
+       .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner",
+       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
+       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
+       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
+       .fe_config      = {&fe_cineS2, &fe_cineS2},
+       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
+       .lnb            = {0x0b, 0x08},
+       .tsf            = {3, 3},
+       .fw_version     = 15,
+};
+
+static struct ngene_info ngene_info_satixS2 = {
+       .type           = NGENE_SIDEWINDER,
+       .name           = "Mystique SaTiX-S2 Dual",
+       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
+       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
+       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
+       .fe_config      = {&fe_cineS2, &fe_cineS2},
+       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
+       .lnb            = {0x0b, 0x08},
+       .tsf            = {3, 3},
+       .fw_version     = 15,
+};
+
+static struct ngene_info ngene_info_satixS2v2 = {
+       .type           = NGENE_SIDEWINDER,
+       .name           = "Mystique SaTiX-S2 Dual (v2)",
+       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
+       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
+       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
+       .fe_config      = {&fe_cineS2, &fe_cineS2},
+       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
+       .lnb            = {0x0a, 0x08},
+       .tsf            = {3, 3},
+       .fw_version     = 15,
+};
+
+static struct ngene_info ngene_info_cineS2v5 = {
+       .type           = NGENE_SIDEWINDER,
+       .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner (v5)",
+       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
+       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
+       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
+       .fe_config      = {&fe_cineS2, &fe_cineS2},
+       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
+       .lnb            = {0x0a, 0x08},
+       .tsf            = {3, 3},
+       .fw_version     = 15,
+};
+
+static struct ngene_info ngene_info_m780 = {
+       .type           = NGENE_APP,
+       .name           = "Aver M780 ATSC/QAM-B",
+
+       /* Channel 0 is analog, which is currently unsupported */
+       .io_type        = { NGENE_IO_NONE, NGENE_IO_TSIN },
+       .demod_attach   = { NULL, demod_attach_lg330x },
+
+       /* Ensure these are NULL else the frame will call them (as funcs) */
+       .tuner_attach   = { 0, 0, 0, 0 },
+       .fe_config      = { NULL, &aver_m780 },
+       .avf            = { 0 },
+
+       /* A custom electrical interface config for the demod to bridge */
+       .tsf            = { 4, 4 },
+       .fw_version     = 15,
+};
+
+/****************************************************************************/
+
+
+
+/****************************************************************************/
+/* PCI Subsystem ID *********************************************************/
+/****************************************************************************/
+
+#define NGENE_ID(_subvend, _subdev, _driverdata) { \
+       .vendor = NGENE_VID, .device = NGENE_PID, \
+       .subvendor = _subvend, .subdevice = _subdev, \
+       .driver_data = (unsigned long) &_driverdata }
+
+/****************************************************************************/
+
+static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
+       NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
+       NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
+       NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
+       NGENE_ID(0x18c3, 0xdb02, ngene_info_satixS2v2),
+       NGENE_ID(0x18c3, 0xdd00, ngene_info_cineS2v5),
+       NGENE_ID(0x1461, 0x062e, ngene_info_m780),
+       {0}
+};
+MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
+
+/****************************************************************************/
+/* Init/Exit ****************************************************************/
+/****************************************************************************/
+
+static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
+                                            enum pci_channel_state state)
+{
+       printk(KERN_ERR DEVICE_NAME ": PCI error\n");
+       if (state == pci_channel_io_perm_failure)
+               return PCI_ERS_RESULT_DISCONNECT;
+       if (state == pci_channel_io_frozen)
+               return PCI_ERS_RESULT_NEED_RESET;
+       return PCI_ERS_RESULT_CAN_RECOVER;
+}
+
+static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
+{
+       printk(KERN_INFO DEVICE_NAME ": link reset\n");
+       return 0;
+}
+
+static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
+{
+       printk(KERN_INFO DEVICE_NAME ": slot reset\n");
+       return 0;
+}
+
+static void ngene_resume(struct pci_dev *dev)
+{
+       printk(KERN_INFO DEVICE_NAME ": resume\n");
+}
+
+static struct pci_error_handlers ngene_errors = {
+       .error_detected = ngene_error_detected,
+       .link_reset = ngene_link_reset,
+       .slot_reset = ngene_slot_reset,
+       .resume = ngene_resume,
+};
+
+static struct pci_driver ngene_pci_driver = {
+       .name        = "ngene",
+       .id_table    = ngene_id_tbl,
+       .probe       = ngene_probe,
+       .remove      = __devexit_p(ngene_remove),
+       .err_handler = &ngene_errors,
+};
+
+static __init int module_init_ngene(void)
+{
+       printk(KERN_INFO
+              "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
+       return pci_register_driver(&ngene_pci_driver);
+}
+
+static __exit void module_exit_ngene(void)
+{
+       pci_unregister_driver(&ngene_pci_driver);
+}
+
+module_init(module_init_ngene);
+module_exit(module_exit_ngene);
+
+MODULE_DESCRIPTION("nGene");
+MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
+MODULE_LICENSE("GPL");
index 645e8b8..c8b4dfa 100644 (file)
 #include <linux/io.h>
 #include <asm/div64.h>
 #include <linux/pci.h>
-#include <linux/pci_ids.h>
 #include <linux/smp_lock.h>
 #include <linux/timer.h>
-#include <linux/version.h>
 #include <linux/byteorder/generic.h>
 #include <linux/firmware.h>
 #include <linux/vmalloc.h>
 
 #include "ngene.h"
 
-#include "stv6110x.h"
-#include "stv090x.h"
-#include "lnbh24.h"
-
 static int one_adapter = 1;
 module_param(one_adapter, int, 0444);
 MODULE_PARM_DESC(one_adapter, "Use only one adapter.");
@@ -63,8 +57,6 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 #define dprintk        if (debug) printk
 
-#define DEVICE_NAME "ngene"
-
 #define ngwriteb(dat, adr)         writeb((dat), (char *)(dev->iomem + (adr)))
 #define ngwritel(dat, adr)         writel((dat), (char *)(dev->iomem + (adr)))
 #define ngwriteb(dat, adr)         writeb((dat), (char *)(dev->iomem + (adr)))
@@ -352,7 +344,7 @@ static int ngene_command_mutex(struct ngene *dev, struct ngene_command *com)
        return 0;
 }
 
-static int ngene_command(struct ngene *dev, struct ngene_command *com)
+int ngene_command(struct ngene *dev, struct ngene_command *com)
 {
        int result;
 
@@ -363,55 +355,6 @@ static int ngene_command(struct ngene *dev, struct ngene_command *com)
 }
 
 
-static int ngene_command_i2c_read(struct ngene *dev, u8 adr,
-                          u8 *out, u8 outlen, u8 *in, u8 inlen, int flag)
-{
-       struct ngene_command com;
-
-       com.cmd.hdr.Opcode = CMD_I2C_READ;
-       com.cmd.hdr.Length = outlen + 3;
-       com.cmd.I2CRead.Device = adr << 1;
-       memcpy(com.cmd.I2CRead.Data, out, outlen);
-       com.cmd.I2CRead.Data[outlen] = inlen;
-       com.cmd.I2CRead.Data[outlen + 1] = 0;
-       com.in_len = outlen + 3;
-       com.out_len = inlen + 1;
-
-       if (ngene_command(dev, &com) < 0)
-               return -EIO;
-
-       if ((com.cmd.raw8[0] >> 1) != adr)
-               return -EIO;
-
-       if (flag)
-               memcpy(in, com.cmd.raw8, inlen + 1);
-       else
-               memcpy(in, com.cmd.raw8 + 1, inlen);
-       return 0;
-}
-
-static int ngene_command_i2c_write(struct ngene *dev, u8 adr,
-                                  u8 *out, u8 outlen)
-{
-       struct ngene_command com;
-
-
-       com.cmd.hdr.Opcode = CMD_I2C_WRITE;
-       com.cmd.hdr.Length = outlen + 1;
-       com.cmd.I2CRead.Device = adr << 1;
-       memcpy(com.cmd.I2CRead.Data, out, outlen);
-       com.in_len = outlen + 1;
-       com.out_len = 1;
-
-       if (ngene_command(dev, &com) < 0)
-               return -EIO;
-
-       if (com.cmd.raw8[0] == 1)
-               return -EIO;
-
-       return 0;
-}
-
 static int ngene_command_load_firmware(struct ngene *dev,
                                       u8 *ngene_fw, u32 size)
 {
@@ -477,7 +420,7 @@ static int ngene_command_config_free_buf(struct ngene *dev, u8 *config)
        return 0;
 }
 
-static int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level)
+int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level)
 {
        struct ngene_command com;
 
@@ -514,11 +457,12 @@ static int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level)
 
 /****************************************************************************/
 
-static u8 TSFeatureDecoderSetup[8 * 4] = {
+static u8 TSFeatureDecoderSetup[8 * 5] = {
        0x42, 0x00, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00,
        0x40, 0x06, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* DRXH */
        0x71, 0x07, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* DRXHser */
        0x72, 0x06, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* S2ser */
+       0x40, 0x07, 0x00, 0x02, 0x02, 0xbc, 0x00, 0x00, /* LGDT3303 */
 };
 
 /* Set NGENE I2S Config to 16 bit packed */
@@ -559,7 +503,7 @@ static u8 ITUFeatureDecoderSetup[8] = {
        0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x04, 0x00
 };
 
-static void FillTSBuffer(void *Buffer, int Length, u32 Flags)
+void FillTSBuffer(void *Buffer, int Length, u32 Flags)
 {
        u32 *ptr = Buffer;
 
@@ -772,144 +716,7 @@ static int ngene_command_stream_control(struct ngene *dev, u8 stream,
        return 0;
 }
 
-
-/****************************************************************************/
-/* I2C **********************************************************************/
-/****************************************************************************/
-
-static void ngene_i2c_set_bus(struct ngene *dev, int bus)
-{
-       if (!(dev->card_info->i2c_access & 2))
-               return;
-       if (dev->i2c_current_bus == bus)
-               return;
-
-       switch (bus) {
-       case 0:
-               ngene_command_gpio_set(dev, 3, 0);
-               ngene_command_gpio_set(dev, 2, 1);
-               break;
-
-       case 1:
-               ngene_command_gpio_set(dev, 2, 0);
-               ngene_command_gpio_set(dev, 3, 1);
-               break;
-       }
-       dev->i2c_current_bus = bus;
-}
-
-static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
-                                struct i2c_msg msg[], int num)
-{
-       struct ngene_channel *chan =
-               (struct ngene_channel *)i2c_get_adapdata(adapter);
-       struct ngene *dev = chan->dev;
-
-       down(&dev->i2c_switch_mutex);
-       ngene_i2c_set_bus(dev, chan->number);
-
-       if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD))
-               if (!ngene_command_i2c_read(dev, msg[0].addr,
-                                           msg[0].buf, msg[0].len,
-                                           msg[1].buf, msg[1].len, 0))
-                       goto done;
-
-       if (num == 1 && !(msg[0].flags & I2C_M_RD))
-               if (!ngene_command_i2c_write(dev, msg[0].addr,
-                                            msg[0].buf, msg[0].len))
-                       goto done;
-       if (num == 1 && (msg[0].flags & I2C_M_RD))
-               if (!ngene_command_i2c_read(dev, msg[0].addr, 0, 0,
-                                           msg[0].buf, msg[0].len, 0))
-                       goto done;
-
-       up(&dev->i2c_switch_mutex);
-       return -EIO;
-
-done:
-       up(&dev->i2c_switch_mutex);
-       return num;
-}
-
-
-static u32 ngene_i2c_functionality(struct i2c_adapter *adap)
-{
-       return I2C_FUNC_SMBUS_EMUL;
-}
-
-static struct i2c_algorithm ngene_i2c_algo = {
-       .master_xfer = ngene_i2c_master_xfer,
-       .functionality = ngene_i2c_functionality,
-};
-
-static int ngene_i2c_init(struct ngene *dev, int dev_nr)
-{
-       struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter);
-
-       i2c_set_adapdata(adap, &(dev->channel[dev_nr]));
-       adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG;
-
-       strcpy(adap->name, "nGene");
-
-       adap->algo = &ngene_i2c_algo;
-       adap->algo_data = (void *)&(dev->channel[dev_nr]);
-       adap->dev.parent = &dev->pci_dev->dev;
-
-       return i2c_add_adapter(adap);
-}
-
-
-/****************************************************************************/
-/* DVB functions and API interface ******************************************/
-/****************************************************************************/
-
-static void swap_buffer(u32 *p, u32 len)
-{
-       while (len) {
-               *p = swab32(*p);
-               p++;
-               len -= 4;
-       }
-}
-
-
-static void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
-{
-       struct ngene_channel *chan = priv;
-
-
-#ifdef COMMAND_TIMEOUT_WORKAROUND
-       if (chan->users > 0)
-#endif
-               dvb_dmx_swfilter(&chan->demux, buf, len);
-       return 0;
-}
-
-u8 fill_ts[188] = { 0x47, 0x1f, 0xff, 0x10 };
-
-static void *tsout_exchange(void *priv, void *buf, u32 len,
-                           u32 clock, u32 flags)
-{
-       struct ngene_channel *chan = priv;
-       struct ngene *dev = chan->dev;
-       u32 alen;
-
-       alen = dvb_ringbuffer_avail(&dev->tsout_rbuf);
-       alen -= alen % 188;
-
-       if (alen < len)
-               FillTSBuffer(buf + alen, len - alen, flags);
-       else
-               alen = len;
-       dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen);
-       if (flags & DF_SWAP32)
-               swap_buffer((u32 *)buf, alen);
-       wake_up_interruptible(&dev->tsout_rbuf.queue);
-       return buf;
-}
-
-
-static void set_transfer(struct ngene_channel *chan, int state)
+void set_transfer(struct ngene_channel *chan, int state)
 {
        u8 control = 0, mode = 0, flags = 0;
        struct ngene *dev = chan->dev;
@@ -970,85 +777,12 @@ static void set_transfer(struct ngene_channel *chan, int state)
                       state);
        if (!state) {
                spin_lock_irq(&chan->state_lock);
-               chan->pBufferExchange = 0;
+               chan->pBufferExchange = NULL;
                dvb_ringbuffer_flush(&dev->tsout_rbuf);
                spin_unlock_irq(&chan->state_lock);
        }
 }
 
-static int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed)
-{
-       struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
-       struct ngene_channel *chan = dvbdmx->priv;
-
-       if (chan->users == 0) {
-#ifdef COMMAND_TIMEOUT_WORKAROUND
-               if (!chan->running)
-#endif
-                       set_transfer(chan, 1);
-               /* msleep(10); */
-       }
-
-       return ++chan->users;
-}
-
-static int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
-{
-       struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
-       struct ngene_channel *chan = dvbdmx->priv;
-
-       if (--chan->users)
-               return chan->users;
-
-#ifndef COMMAND_TIMEOUT_WORKAROUND
-       set_transfer(chan, 0);
-#endif
-
-       return 0;
-}
-
-
-
-static int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
-                                  int (*start_feed)(struct dvb_demux_feed *),
-                                  int (*stop_feed)(struct dvb_demux_feed *),
-                                  void *priv)
-{
-       dvbdemux->priv = priv;
-
-       dvbdemux->filternum = 256;
-       dvbdemux->feednum = 256;
-       dvbdemux->start_feed = start_feed;
-       dvbdemux->stop_feed = stop_feed;
-       dvbdemux->write_to_decoder = 0;
-       dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
-                                     DMX_SECTION_FILTERING |
-                                     DMX_MEMORY_BASED_FILTERING);
-       return dvb_dmx_init(dvbdemux);
-}
-
-static int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
-                                     struct dvb_demux *dvbdemux,
-                                     struct dmx_frontend *hw_frontend,
-                                     struct dmx_frontend *mem_frontend,
-                                     struct dvb_adapter *dvb_adapter)
-{
-       int ret;
-
-       dmxdev->filternum = 256;
-       dmxdev->demux = &dvbdemux->dmx;
-       dmxdev->capabilities = 0;
-       ret = dvb_dmxdev_init(dmxdev, dvb_adapter);
-       if (ret < 0)
-               return ret;
-
-       hw_frontend->source = DMX_FRONTEND_0;
-       dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend);
-       mem_frontend->source = DMX_MEMORY_FE;
-       dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend);
-       return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend);
-}
-
 
 /****************************************************************************/
 /* nGene hardware init and release functions ********************************/
@@ -1094,8 +828,8 @@ static void free_idlebuffer(struct ngene *dev,
                return;
        free_ringbuffer(dev, rb);
        for (j = 0; j < tb->NumBuffers; j++, Cur = Cur->Next) {
-               Cur->Buffer2 = 0;
-               Cur->scList2 = 0;
+               Cur->Buffer2 = NULL;
+               Cur->scList2 = NULL;
                Cur->ngeneBuffer.Address_of_first_entry_2 = 0;
                Cur->ngeneBuffer.Number_of_entries_2 = 0;
        }
@@ -1141,7 +875,7 @@ static int create_ring_buffer(struct pci_dev *pci_dev,
        u64 PARingBufferNext;
        struct SBufferHeader *Cur, *Next;
 
-       descr->Head = 0;
+       descr->Head = NULL;
        descr->MemSize = 0;
        descr->PAHead = 0;
        descr->NumBuffers = 0;
@@ -1633,69 +1367,6 @@ fail:
 
 
 
-/****************************************************************************/
-/* Switch control (I2C gates, etc.) *****************************************/
-/****************************************************************************/
-
-
-/****************************************************************************/
-/* Demod/tuner attachment ***************************************************/
-/****************************************************************************/
-
-static int tuner_attach_stv6110(struct ngene_channel *chan)
-{
-       struct stv090x_config *feconf = (struct stv090x_config *)
-               chan->dev->card_info->fe_config[chan->number];
-       struct stv6110x_config *tunerconf = (struct stv6110x_config *)
-               chan->dev->card_info->tuner_config[chan->number];
-       struct stv6110x_devctl *ctl;
-
-       ctl = dvb_attach(stv6110x_attach, chan->fe, tunerconf,
-                        &chan->i2c_adapter);
-       if (ctl == NULL) {
-               printk(KERN_ERR DEVICE_NAME ": No STV6110X found!\n");
-               return -ENODEV;
-       }
-
-       feconf->tuner_init          = ctl->tuner_init;
-       feconf->tuner_set_mode      = ctl->tuner_set_mode;
-       feconf->tuner_set_frequency = ctl->tuner_set_frequency;
-       feconf->tuner_get_frequency = ctl->tuner_get_frequency;
-       feconf->tuner_set_bandwidth = ctl->tuner_set_bandwidth;
-       feconf->tuner_get_bandwidth = ctl->tuner_get_bandwidth;
-       feconf->tuner_set_bbgain    = ctl->tuner_set_bbgain;
-       feconf->tuner_get_bbgain    = ctl->tuner_get_bbgain;
-       feconf->tuner_set_refclk    = ctl->tuner_set_refclk;
-       feconf->tuner_get_status    = ctl->tuner_get_status;
-
-       return 0;
-}
-
-
-static int demod_attach_stv0900(struct ngene_channel *chan)
-{
-       struct stv090x_config *feconf = (struct stv090x_config *)
-               chan->dev->card_info->fe_config[chan->number];
-
-       chan->fe = dvb_attach(stv090x_attach,
-                       feconf,
-                       &chan->i2c_adapter,
-                       chan->number == 0 ? STV090x_DEMODULATOR_0 :
-                                           STV090x_DEMODULATOR_1);
-       if (chan->fe == NULL) {
-               printk(KERN_ERR DEVICE_NAME ": No STV0900 found!\n");
-               return -ENODEV;
-       }
-
-       if (!dvb_attach(lnbh24_attach, chan->fe, &chan->i2c_adapter, 0,
-                       0, chan->dev->card_info->lnb[chan->number])) {
-               printk(KERN_ERR DEVICE_NAME ": No LNBH24 found!\n");
-               dvb_frontend_detach(chan->fe);
-               return -ENODEV;
-       }
-
-       return 0;
-}
 
 /****************************************************************************/
 /****************************************************************************/
@@ -1719,7 +1390,7 @@ static void release_channel(struct ngene_channel *chan)
                if (chan->fe) {
                        dvb_unregister_frontend(chan->fe);
                        dvb_frontend_detach(chan->fe);
-                       chan->fe = 0;
+                       chan->fe = NULL;
                }
                dvbdemux->dmx.close(&dvbdemux->dmx);
                dvbdemux->dmx.remove_frontend(&dvbdemux->dmx,
@@ -1751,7 +1422,7 @@ static int init_channel(struct ngene_channel *chan)
        if (io & (NGENE_IO_TSIN | NGENE_IO_TSOUT)) {
                if (nr >= STREAM_AUDIOIN1)
                        chan->DataFormatFlags = DF_SWAP32;
-               if (nr == 0 || !one_adapter) {
+               if (nr == 0 || !one_adapter || dev->first_adapter == NULL) {
                        adapter = &dev->adapter[nr];
                        ret = dvb_register_adapter(adapter, "nGene",
                                                   THIS_MODULE,
@@ -1759,8 +1430,10 @@ static int init_channel(struct ngene_channel *chan)
                                                   adapter_nr);
                        if (ret < 0)
                                return ret;
+                       if (dev->first_adapter == NULL)
+                               dev->first_adapter = adapter;
                } else {
-                       adapter = &dev->adapter[0];
+                       adapter = dev->first_adapter;
                }
 
                ret = my_dvb_dmx_ts_card_init(dvbdemux, "SW demux",
@@ -1797,6 +1470,7 @@ static int init_channels(struct ngene *dev)
        int i, j;
 
        for (i = 0; i < MAX_STREAM; i++) {
+               dev->channel[i].number = i;
                if (init_channel(&dev->channel[i]) < 0) {
                        for (j = i - 1; j >= 0; j--)
                                release_channel(&dev->channel[j]);
@@ -1810,7 +1484,7 @@ static int init_channels(struct ngene *dev)
 /* device probe/remove calls ************************************************/
 /****************************************************************************/
 
-static void __devexit ngene_remove(struct pci_dev *pdev)
+void __devexit ngene_remove(struct pci_dev *pdev)
 {
        struct ngene *dev = (struct ngene *)pci_get_drvdata(pdev);
        int i;
@@ -1820,12 +1494,12 @@ static void __devexit ngene_remove(struct pci_dev *pdev)
                release_channel(&dev->channel[i]);
        ngene_stop(dev);
        ngene_release_buffers(dev);
-       pci_set_drvdata(pdev, 0);
+       pci_set_drvdata(pdev, NULL);
        pci_disable_device(pdev);
 }
 
-static int __devinit ngene_probe(struct pci_dev *pci_dev,
-                                const struct pci_device_id *id)
+int __devinit ngene_probe(struct pci_dev *pci_dev,
+                         const struct pci_device_id *id)
 {
        struct ngene *dev;
        int stat = 0;
@@ -1868,156 +1542,6 @@ fail1:
        ngene_release_buffers(dev);
 fail0:
        pci_disable_device(pci_dev);
-       pci_set_drvdata(pci_dev, 0);
+       pci_set_drvdata(pci_dev, NULL);
        return stat;
 }
-
-/****************************************************************************/
-/* Card configs *************************************************************/
-/****************************************************************************/
-
-static struct stv090x_config fe_cineS2 = {
-       .device         = STV0900,
-       .demod_mode     = STV090x_DUAL,
-       .clk_mode       = STV090x_CLK_EXT,
-
-       .xtal           = 27000000,
-       .address        = 0x68,
-
-       .ts1_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
-       .ts2_mode       = STV090x_TSMODE_SERIAL_PUNCTURED,
-
-       .repeater_level = STV090x_RPTLEVEL_16,
-
-       .adc1_range     = STV090x_ADC_1Vpp,
-       .adc2_range     = STV090x_ADC_1Vpp,
-
-       .diseqc_envelope_mode = true,
-};
-
-static struct stv6110x_config tuner_cineS2_0 = {
-       .addr   = 0x60,
-       .refclk = 27000000,
-       .clk_div = 1,
-};
-
-static struct stv6110x_config tuner_cineS2_1 = {
-       .addr   = 0x63,
-       .refclk = 27000000,
-       .clk_div = 1,
-};
-
-static struct ngene_info ngene_info_cineS2 = {
-       .type           = NGENE_SIDEWINDER,
-       .name           = "Linux4Media cineS2 DVB-S2 Twin Tuner",
-       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
-       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
-       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
-       .fe_config      = {&fe_cineS2, &fe_cineS2},
-       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
-       .lnb            = {0x0b, 0x08},
-       .tsf            = {3, 3},
-       .fw_version     = 15,
-};
-
-static struct ngene_info ngene_info_satixs2 = {
-       .type           = NGENE_SIDEWINDER,
-       .name           = "Mystique SaTiX-S2 Dual",
-       .io_type        = {NGENE_IO_TSIN, NGENE_IO_TSIN},
-       .demod_attach   = {demod_attach_stv0900, demod_attach_stv0900},
-       .tuner_attach   = {tuner_attach_stv6110, tuner_attach_stv6110},
-       .fe_config      = {&fe_cineS2, &fe_cineS2},
-       .tuner_config   = {&tuner_cineS2_0, &tuner_cineS2_1},
-       .lnb            = {0x0b, 0x08},
-       .tsf            = {3, 3},
-       .fw_version     = 15,
-};
-
-/****************************************************************************/
-
-
-
-/****************************************************************************/
-/* PCI Subsystem ID *********************************************************/
-/****************************************************************************/
-
-#define NGENE_ID(_subvend, _subdev, _driverdata) { \
-       .vendor = NGENE_VID, .device = NGENE_PID, \
-       .subvendor = _subvend, .subdevice = _subdev, \
-       .driver_data = (unsigned long) &_driverdata }
-
-/****************************************************************************/
-
-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
-       NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
-       NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
-       NGENE_ID(0x18c3, 0xdb01, ngene_info_satixs2),
-       {0}
-};
-MODULE_DEVICE_TABLE(pci, ngene_id_tbl);
-
-/****************************************************************************/
-/* Init/Exit ****************************************************************/
-/****************************************************************************/
-
-static pci_ers_result_t ngene_error_detected(struct pci_dev *dev,
-                                            enum pci_channel_state state)
-{
-       printk(KERN_ERR DEVICE_NAME ": PCI error\n");
-       if (state == pci_channel_io_perm_failure)
-               return PCI_ERS_RESULT_DISCONNECT;
-       if (state == pci_channel_io_frozen)
-               return PCI_ERS_RESULT_NEED_RESET;
-       return PCI_ERS_RESULT_CAN_RECOVER;
-}
-
-static pci_ers_result_t ngene_link_reset(struct pci_dev *dev)
-{
-       printk(KERN_INFO DEVICE_NAME ": link reset\n");
-       return 0;
-}
-
-static pci_ers_result_t ngene_slot_reset(struct pci_dev *dev)
-{
-       printk(KERN_INFO DEVICE_NAME ": slot reset\n");
-       return 0;
-}
-
-static void ngene_resume(struct pci_dev *dev)
-{
-       printk(KERN_INFO DEVICE_NAME ": resume\n");
-}
-
-static struct pci_error_handlers ngene_errors = {
-       .error_detected = ngene_error_detected,
-       .link_reset = ngene_link_reset,
-       .slot_reset = ngene_slot_reset,
-       .resume = ngene_resume,
-};
-
-static struct pci_driver ngene_pci_driver = {
-       .name        = "ngene",
-       .id_table    = ngene_id_tbl,
-       .probe       = ngene_probe,
-       .remove      = __devexit_p(ngene_remove),
-       .err_handler = &ngene_errors,
-};
-
-static __init int module_init_ngene(void)
-{
-       printk(KERN_INFO
-              "nGene PCIE bridge driver, Copyright (C) 2005-2007 Micronas\n");
-       return pci_register_driver(&ngene_pci_driver);
-}
-
-static __exit void module_exit_ngene(void)
-{
-       pci_unregister_driver(&ngene_pci_driver);
-}
-
-module_init(module_init_ngene);
-module_exit(module_exit_ngene);
-
-MODULE_DESCRIPTION("nGene");
-MODULE_AUTHOR("Micronas, Ralph Metzler, Manfred Voelkel");
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/ngene/ngene-dvb.c b/drivers/media/dvb/ngene/ngene-dvb.c
new file mode 100644 (file)
index 0000000..96013eb
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * ngene-dvb.c: nGene PCIe bridge driver - DVB functions
+ *
+ * Copyright (C) 2005-2007 Micronas
+ *
+ * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Modifications for new nGene firmware,
+ *                         support for EEPROM-copying,
+ *                         support for new dual DVB-S2 card prototype
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/io.h>
+#include <asm/div64.h>
+#include <linux/pci.h>
+#include <linux/smp_lock.h>
+#include <linux/timer.h>
+#include <linux/version.h>
+#include <linux/byteorder/generic.h>
+#include <linux/firmware.h>
+#include <linux/vmalloc.h>
+
+#include "ngene.h"
+
+#define COMMAND_TIMEOUT_WORKAROUND
+
+
+/****************************************************************************/
+/* COMMAND API interface ****************************************************/
+/****************************************************************************/
+
+/****************************************************************************/
+/* DVB functions and API interface ******************************************/
+/****************************************************************************/
+
+static void swap_buffer(u32 *p, u32 len)
+{
+       while (len) {
+               *p = swab32(*p);
+               p++;
+               len -= 4;
+       }
+}
+
+void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
+{
+       struct ngene_channel *chan = priv;
+
+
+#ifdef COMMAND_TIMEOUT_WORKAROUND
+       if (chan->users > 0)
+#endif
+               dvb_dmx_swfilter(&chan->demux, buf, len);
+       return NULL;
+}
+
+u8 fill_ts[188] = { 0x47, 0x1f, 0xff, 0x10 };
+
+void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags)
+{
+       struct ngene_channel *chan = priv;
+       struct ngene *dev = chan->dev;
+       u32 alen;
+
+       alen = dvb_ringbuffer_avail(&dev->tsout_rbuf);
+       alen -= alen % 188;
+
+       if (alen < len)
+               FillTSBuffer(buf + alen, len - alen, flags);
+       else
+               alen = len;
+       dvb_ringbuffer_read(&dev->tsout_rbuf, buf, alen);
+       if (flags & DF_SWAP32)
+               swap_buffer((u32 *)buf, alen);
+       wake_up_interruptible(&dev->tsout_rbuf.queue);
+       return buf;
+}
+
+
+
+int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed)
+{
+       struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
+       struct ngene_channel *chan = dvbdmx->priv;
+
+       if (chan->users == 0) {
+#ifdef COMMAND_TIMEOUT_WORKAROUND
+               if (!chan->running)
+#endif
+                       set_transfer(chan, 1);
+               /* msleep(10); */
+       }
+
+       return ++chan->users;
+}
+
+int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
+{
+       struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
+       struct ngene_channel *chan = dvbdmx->priv;
+
+       if (--chan->users)
+               return chan->users;
+
+#ifndef COMMAND_TIMEOUT_WORKAROUND
+       set_transfer(chan, 0);
+#endif
+
+       return 0;
+}
+
+int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
+                           int (*start_feed)(struct dvb_demux_feed *),
+                           int (*stop_feed)(struct dvb_demux_feed *),
+                           void *priv)
+{
+       dvbdemux->priv = priv;
+
+       dvbdemux->filternum = 256;
+       dvbdemux->feednum = 256;
+       dvbdemux->start_feed = start_feed;
+       dvbdemux->stop_feed = stop_feed;
+       dvbdemux->write_to_decoder = NULL;
+       dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
+                                     DMX_SECTION_FILTERING |
+                                     DMX_MEMORY_BASED_FILTERING);
+       return dvb_dmx_init(dvbdemux);
+}
+
+int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
+                              struct dvb_demux *dvbdemux,
+                              struct dmx_frontend *hw_frontend,
+                              struct dmx_frontend *mem_frontend,
+                              struct dvb_adapter *dvb_adapter)
+{
+       int ret;
+
+       dmxdev->filternum = 256;
+       dmxdev->demux = &dvbdemux->dmx;
+       dmxdev->capabilities = 0;
+       ret = dvb_dmxdev_init(dmxdev, dvb_adapter);
+       if (ret < 0)
+               return ret;
+
+       hw_frontend->source = DMX_FRONTEND_0;
+       dvbdemux->dmx.add_frontend(&dvbdemux->dmx, hw_frontend);
+       mem_frontend->source = DMX_MEMORY_FE;
+       dvbdemux->dmx.add_frontend(&dvbdemux->dmx, mem_frontend);
+       return dvbdemux->dmx.connect_frontend(&dvbdemux->dmx, hw_frontend);
+}
diff --git a/drivers/media/dvb/ngene/ngene-i2c.c b/drivers/media/dvb/ngene/ngene-i2c.c
new file mode 100644 (file)
index 0000000..2ef54ca
--- /dev/null
@@ -0,0 +1,179 @@
+/*
+ * ngene-i2c.c: nGene PCIe bridge driver i2c functions
+ *
+ * Copyright (C) 2005-2007 Micronas
+ *
+ * Copyright (C) 2008-2009 Ralph Metzler <rjkm@metzlerbros.de>
+ *                         Modifications for new nGene firmware,
+ *                         support for EEPROM-copying,
+ *                         support for new dual DVB-S2 card prototype
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 only, as published by the Free Software Foundation.
+ *
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ */
+
+/* FIXME - some of these can probably be removed */
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/io.h>
+#include <asm/div64.h>
+#include <linux/pci.h>
+#include <linux/pci_ids.h>
+#include <linux/smp_lock.h>
+#include <linux/timer.h>
+#include <linux/version.h>
+#include <linux/byteorder/generic.h>
+#include <linux/firmware.h>
+#include <linux/vmalloc.h>
+
+#include "ngene.h"
+
+/* Firmware command for i2c operations */
+static int ngene_command_i2c_read(struct ngene *dev, u8 adr,
+                          u8 *out, u8 outlen, u8 *in, u8 inlen, int flag)
+{
+       struct ngene_command com;
+
+       com.cmd.hdr.Opcode = CMD_I2C_READ;
+       com.cmd.hdr.Length = outlen + 3;
+       com.cmd.I2CRead.Device = adr << 1;
+       memcpy(com.cmd.I2CRead.Data, out, outlen);
+       com.cmd.I2CRead.Data[outlen] = inlen;
+       com.cmd.I2CRead.Data[outlen + 1] = 0;
+       com.in_len = outlen + 3;
+       com.out_len = inlen + 1;
+
+       if (ngene_command(dev, &com) < 0)
+               return -EIO;
+
+       if ((com.cmd.raw8[0] >> 1) != adr)
+               return -EIO;
+
+       if (flag)
+               memcpy(in, com.cmd.raw8, inlen + 1);
+       else
+               memcpy(in, com.cmd.raw8 + 1, inlen);
+       return 0;
+}
+
+static int ngene_command_i2c_write(struct ngene *dev, u8 adr,
+                                  u8 *out, u8 outlen)
+{
+       struct ngene_command com;
+
+
+       com.cmd.hdr.Opcode = CMD_I2C_WRITE;
+       com.cmd.hdr.Length = outlen + 1;
+       com.cmd.I2CRead.Device = adr << 1;
+       memcpy(com.cmd.I2CRead.Data, out, outlen);
+       com.in_len = outlen + 1;
+       com.out_len = 1;
+
+       if (ngene_command(dev, &com) < 0)
+               return -EIO;
+
+       if (com.cmd.raw8[0] == 1)
+               return -EIO;
+
+       return 0;
+}
+
+static void ngene_i2c_set_bus(struct ngene *dev, int bus)
+{
+       if (!(dev->card_info->i2c_access & 2))
+               return;
+       if (dev->i2c_current_bus == bus)
+               return;
+
+       switch (bus) {
+       case 0:
+               ngene_command_gpio_set(dev, 3, 0);
+               ngene_command_gpio_set(dev, 2, 1);
+               break;
+
+       case 1:
+               ngene_command_gpio_set(dev, 2, 0);
+               ngene_command_gpio_set(dev, 3, 1);
+               break;
+       }
+       dev->i2c_current_bus = bus;
+}
+
+static int ngene_i2c_master_xfer(struct i2c_adapter *adapter,
+                                struct i2c_msg msg[], int num)
+{
+       struct ngene_channel *chan =
+               (struct ngene_channel *)i2c_get_adapdata(adapter);
+       struct ngene *dev = chan->dev;
+
+       down(&dev->i2c_switch_mutex);
+       ngene_i2c_set_bus(dev, chan->number);
+
+       if (num == 2 && msg[1].flags & I2C_M_RD && !(msg[0].flags & I2C_M_RD))
+               if (!ngene_command_i2c_read(dev, msg[0].addr,
+                                           msg[0].buf, msg[0].len,
+                                           msg[1].buf, msg[1].len, 0))
+                       goto done;
+
+       if (num == 1 && !(msg[0].flags & I2C_M_RD))
+               if (!ngene_command_i2c_write(dev, msg[0].addr,
+                                            msg[0].buf, msg[0].len))
+                       goto done;
+       if (num == 1 && (msg[0].flags & I2C_M_RD))
+               if (!ngene_command_i2c_read(dev, msg[0].addr, NULL, 0,
+                                           msg[0].buf, msg[0].len, 0))
+                       goto done;
+
+       up(&dev->i2c_switch_mutex);
+       return -EIO;
+
+done:
+       up(&dev->i2c_switch_mutex);
+       return num;
+}
+
+
+static u32 ngene_i2c_functionality(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_SMBUS_EMUL;
+}
+
+static struct i2c_algorithm ngene_i2c_algo = {
+       .master_xfer = ngene_i2c_master_xfer,
+       .functionality = ngene_i2c_functionality,
+};
+
+int ngene_i2c_init(struct ngene *dev, int dev_nr)
+{
+       struct i2c_adapter *adap = &(dev->channel[dev_nr].i2c_adapter);
+
+       i2c_set_adapdata(adap, &(dev->channel[dev_nr]));
+       adap->class = I2C_CLASS_TV_DIGITAL | I2C_CLASS_TV_ANALOG;
+
+       strcpy(adap->name, "nGene");
+
+       adap->algo = &ngene_i2c_algo;
+       adap->algo_data = (void *)&(dev->channel[dev_nr]);
+       adap->dev.parent = &dev->pci_dev->dev;
+
+       return i2c_add_adapter(adap);
+}
+
index a7eb298..676fcbb 100644 (file)
@@ -39,6 +39,8 @@
 #include "dvb_frontend.h"
 #include "dvb_ringbuffer.h"
 
+#define DEVICE_NAME "ngene"
+
 #define NGENE_VID       0x18c3
 #define NGENE_PID       0x0720
 
@@ -752,6 +754,7 @@ struct ngene {
        spinlock_t            cmd_lock;
 
        struct dvb_adapter    adapter[MAX_STREAM];
+       struct dvb_adapter    *first_adapter; /* "one_adapter" modprobe opt */
        struct ngene_channel  channel[MAX_STREAM];
 
        struct ngene_info    *card_info;
@@ -853,6 +856,33 @@ struct ngene_buffer {
 #endif
 
 
+/* Provided by ngene-core.c */
+int __devinit ngene_probe(struct pci_dev *pci_dev,
+                         const struct pci_device_id *id);
+void __devexit ngene_remove(struct pci_dev *pdev);
+int ngene_command(struct ngene *dev, struct ngene_command *com);
+int ngene_command_gpio_set(struct ngene *dev, u8 select, u8 level);
+void set_transfer(struct ngene_channel *chan, int state);
+void FillTSBuffer(void *Buffer, int Length, u32 Flags);
+
+/* Provided by ngene-i2c.c */
+int ngene_i2c_init(struct ngene *dev, int dev_nr);
+
+/* Provided by ngene-dvb.c */
+void *tsout_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
+void *tsin_exchange(void *priv, void *buf, u32 len, u32 clock, u32 flags);
+int ngene_start_feed(struct dvb_demux_feed *dvbdmxfeed);
+int ngene_stop_feed(struct dvb_demux_feed *dvbdmxfeed);
+int my_dvb_dmx_ts_card_init(struct dvb_demux *dvbdemux, char *id,
+                           int (*start_feed)(struct dvb_demux_feed *),
+                           int (*stop_feed)(struct dvb_demux_feed *),
+                           void *priv);
+int my_dvb_dmxdev_ts_card_init(struct dmxdev *dmxdev,
+                              struct dvb_demux *dvbdemux,
+                              struct dmx_frontend *hw_frontend,
+                              struct dmx_frontend *mem_frontend,
+                              struct dvb_adapter *dvb_adapter);
+
 #endif
 
 /*  LocalWords:  Endif
index 6aded23..69ad949 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * driver for Earthsoft PT1
+ * driver for Earthsoft PT1/PT2
  *
  * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
  *
@@ -77,6 +77,10 @@ struct pt1 {
        struct pt1_adapter *adaps[PT1_NR_ADAPS];
        struct pt1_table *tables;
        struct task_struct *kthread;
+
+       struct mutex lock;
+       int power;
+       int reset;
 };
 
 struct pt1_adapter {
@@ -95,6 +99,11 @@ struct pt1_adapter {
        struct dvb_frontend *fe;
        int (*orig_set_voltage)(struct dvb_frontend *fe,
                                fe_sec_voltage_t voltage);
+       int (*orig_sleep)(struct dvb_frontend *fe);
+       int (*orig_init)(struct dvb_frontend *fe);
+
+       fe_sec_voltage_t voltage;
+       int sleep;
 };
 
 #define pt1_printk(level, pt1, format, arg...) \
@@ -219,8 +228,10 @@ static int pt1_do_enable_ram(struct pt1 *pt1)
 static int pt1_enable_ram(struct pt1 *pt1)
 {
        int i, ret;
+       int phase;
        schedule_timeout_uninterruptible((HZ + 999) / 1000);
-       for (i = 0; i < 10; i++) {
+       phase = pt1->pdev->device == 0x211a ? 128 : 166;
+       for (i = 0; i < phase; i++) {
                ret = pt1_do_enable_ram(pt1);
                if (ret < 0)
                        return ret;
@@ -485,33 +496,47 @@ static int pt1_stop_feed(struct dvb_demux_feed *feed)
 }
 
 static void
-pt1_set_power(struct pt1 *pt1, int power, int lnb, int reset)
+pt1_update_power(struct pt1 *pt1)
 {
-       pt1_write_reg(pt1, 1, power | lnb << 1 | !reset << 3);
+       int bits;
+       int i;
+       struct pt1_adapter *adap;
+       static const int sleep_bits[] = {
+               1 << 4,
+               1 << 6 | 1 << 7,
+               1 << 5,
+               1 << 6 | 1 << 8,
+       };
+
+       bits = pt1->power | !pt1->reset << 3;
+       mutex_lock(&pt1->lock);
+       for (i = 0; i < PT1_NR_ADAPS; i++) {
+               adap = pt1->adaps[i];
+               switch (adap->voltage) {
+               case SEC_VOLTAGE_13: /* actually 11V */
+                       bits |= 1 << 1;
+                       break;
+               case SEC_VOLTAGE_18: /* actually 15V */
+                       bits |= 1 << 1 | 1 << 2;
+                       break;
+               default:
+                       break;
+               }
+
+               /* XXX: The bits should be changed depending on adap->sleep. */
+               bits |= sleep_bits[i];
+       }
+       pt1_write_reg(pt1, 1, bits);
+       mutex_unlock(&pt1->lock);
 }
 
 static int pt1_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
 {
        struct pt1_adapter *adap;
-       int lnb;
 
        adap = container_of(fe->dvb, struct pt1_adapter, adap);
-
-       switch (voltage) {
-       case SEC_VOLTAGE_13: /* actually 11V */
-               lnb = 2;
-               break;
-       case SEC_VOLTAGE_18: /* actually 15V */
-               lnb = 3;
-               break;
-       case SEC_VOLTAGE_OFF:
-               lnb = 0;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       pt1_set_power(adap->pt1, 1, lnb, 0);
+       adap->voltage = voltage;
+       pt1_update_power(adap->pt1);
 
        if (adap->orig_set_voltage)
                return adap->orig_set_voltage(fe, voltage);
@@ -519,9 +544,37 @@ static int pt1_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
                return 0;
 }
 
+static int pt1_sleep(struct dvb_frontend *fe)
+{
+       struct pt1_adapter *adap;
+
+       adap = container_of(fe->dvb, struct pt1_adapter, adap);
+       adap->sleep = 1;
+       pt1_update_power(adap->pt1);
+
+       if (adap->orig_sleep)
+               return adap->orig_sleep(fe);
+       else
+               return 0;
+}
+
+static int pt1_wakeup(struct dvb_frontend *fe)
+{
+       struct pt1_adapter *adap;
+
+       adap = container_of(fe->dvb, struct pt1_adapter, adap);
+       adap->sleep = 0;
+       pt1_update_power(adap->pt1);
+       schedule_timeout_uninterruptible((HZ + 999) / 1000);
+
+       if (adap->orig_init)
+               return adap->orig_init(fe);
+       else
+               return 0;
+}
+
 static void pt1_free_adapter(struct pt1_adapter *adap)
 {
-       dvb_unregister_frontend(adap->fe);
        dvb_net_release(&adap->net);
        adap->demux.dmx.close(&adap->demux.dmx);
        dvb_dmxdev_release(&adap->dmxdev);
@@ -534,7 +587,7 @@ static void pt1_free_adapter(struct pt1_adapter *adap)
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static struct pt1_adapter *
-pt1_alloc_adapter(struct pt1 *pt1, struct dvb_frontend *fe)
+pt1_alloc_adapter(struct pt1 *pt1)
 {
        struct pt1_adapter *adap;
        void *buf;
@@ -551,8 +604,8 @@ pt1_alloc_adapter(struct pt1 *pt1, struct dvb_frontend *fe)
 
        adap->pt1 = pt1;
 
-       adap->orig_set_voltage = fe->ops.set_voltage;
-       fe->ops.set_voltage = pt1_set_voltage;
+       adap->voltage = SEC_VOLTAGE_OFF;
+       adap->sleep = 1;
 
        buf = (u8 *)__get_free_page(GFP_KERNEL);
        if (!buf) {
@@ -593,17 +646,8 @@ pt1_alloc_adapter(struct pt1 *pt1, struct dvb_frontend *fe)
 
        dvb_net_init(dvb_adap, &adap->net, &demux->dmx);
 
-       ret = dvb_register_frontend(dvb_adap, fe);
-       if (ret < 0)
-               goto err_net_release;
-       adap->fe = fe;
-
        return adap;
 
-err_net_release:
-       dvb_net_release(&adap->net);
-       adap->demux.dmx.close(&adap->demux.dmx);
-       dvb_dmxdev_release(&adap->dmxdev);
 err_dmx_release:
        dvb_dmx_release(demux);
 err_unregister_adapter:
@@ -623,6 +667,62 @@ static void pt1_cleanup_adapters(struct pt1 *pt1)
                pt1_free_adapter(pt1->adaps[i]);
 }
 
+static int pt1_init_adapters(struct pt1 *pt1)
+{
+       int i;
+       struct pt1_adapter *adap;
+       int ret;
+
+       for (i = 0; i < PT1_NR_ADAPS; i++) {
+               adap = pt1_alloc_adapter(pt1);
+               if (IS_ERR(adap)) {
+                       ret = PTR_ERR(adap);
+                       goto err;
+               }
+
+               adap->index = i;
+               pt1->adaps[i] = adap;
+       }
+       return 0;
+
+err:
+       while (i--)
+               pt1_free_adapter(pt1->adaps[i]);
+
+       return ret;
+}
+
+static void pt1_cleanup_frontend(struct pt1_adapter *adap)
+{
+       dvb_unregister_frontend(adap->fe);
+}
+
+static int pt1_init_frontend(struct pt1_adapter *adap, struct dvb_frontend *fe)
+{
+       int ret;
+
+       adap->orig_set_voltage = fe->ops.set_voltage;
+       adap->orig_sleep = fe->ops.sleep;
+       adap->orig_init = fe->ops.init;
+       fe->ops.set_voltage = pt1_set_voltage;
+       fe->ops.sleep = pt1_sleep;
+       fe->ops.init = pt1_wakeup;
+
+       ret = dvb_register_frontend(&adap->adap, fe);
+       if (ret < 0)
+               return ret;
+
+       adap->fe = fe;
+       return 0;
+}
+
+static void pt1_cleanup_frontends(struct pt1 *pt1)
+{
+       int i;
+       for (i = 0; i < PT1_NR_ADAPS; i++)
+               pt1_cleanup_frontend(pt1->adaps[i]);
+}
+
 struct pt1_config {
        struct va1j5jf8007s_config va1j5jf8007s_config;
        struct va1j5jf8007t_config va1j5jf8007t_config;
@@ -630,29 +730,63 @@ struct pt1_config {
 
 static const struct pt1_config pt1_configs[2] = {
        {
-               { .demod_address = 0x1b },
-               { .demod_address = 0x1a },
+               {
+                       .demod_address = 0x1b,
+                       .frequency = VA1J5JF8007S_20MHZ,
+               },
+               {
+                       .demod_address = 0x1a,
+                       .frequency = VA1J5JF8007T_20MHZ,
+               },
        }, {
-               { .demod_address = 0x19 },
-               { .demod_address = 0x18 },
+               {
+                       .demod_address = 0x19,
+                       .frequency = VA1J5JF8007S_20MHZ,
+               },
+               {
+                       .demod_address = 0x18,
+                       .frequency = VA1J5JF8007T_20MHZ,
+               },
        },
 };
 
-static int pt1_init_adapters(struct pt1 *pt1)
+static const struct pt1_config pt2_configs[2] = {
+       {
+               {
+                       .demod_address = 0x1b,
+                       .frequency = VA1J5JF8007S_25MHZ,
+               },
+               {
+                       .demod_address = 0x1a,
+                       .frequency = VA1J5JF8007T_25MHZ,
+               },
+       }, {
+               {
+                       .demod_address = 0x19,
+                       .frequency = VA1J5JF8007S_25MHZ,
+               },
+               {
+                       .demod_address = 0x18,
+                       .frequency = VA1J5JF8007T_25MHZ,
+               },
+       },
+};
+
+static int pt1_init_frontends(struct pt1 *pt1)
 {
        int i, j;
        struct i2c_adapter *i2c_adap;
-       const struct pt1_config *config;
+       const struct pt1_config *configs, *config;
        struct dvb_frontend *fe[4];
-       struct pt1_adapter *adap;
        int ret;
 
        i = 0;
        j = 0;
 
        i2c_adap = &pt1->i2c_adap;
+       configs = pt1->pdev->device == 0x211a ? pt1_configs : pt2_configs;
        do {
-               config = &pt1_configs[i / 2];
+               config = &configs[i / 2];
 
                fe[i] = va1j5jf8007s_attach(&config->va1j5jf8007s_config,
                                            i2c_adap);
@@ -681,11 +815,9 @@ static int pt1_init_adapters(struct pt1 *pt1)
        } while (i < 4);
 
        do {
-               adap = pt1_alloc_adapter(pt1, fe[j]);
-               if (IS_ERR(adap))
+               ret = pt1_init_frontend(pt1->adaps[j], fe[j]);
+               if (ret < 0)
                        goto err;
-               adap->index = j;
-               pt1->adaps[j] = adap;
        } while (++j < 4);
 
        return 0;
@@ -695,7 +827,7 @@ err:
                fe[i]->ops.release(fe[i]);
 
        while (j--)
-               pt1_free_adapter(pt1->adaps[j]);
+               dvb_unregister_frontend(fe[j]);
 
        return ret;
 }
@@ -890,9 +1022,12 @@ static void __devexit pt1_remove(struct pci_dev *pdev)
 
        kthread_stop(pt1->kthread);
        pt1_cleanup_tables(pt1);
-       pt1_cleanup_adapters(pt1);
+       pt1_cleanup_frontends(pt1);
        pt1_disable_ram(pt1);
-       pt1_set_power(pt1, 0, 0, 1);
+       pt1->power = 0;
+       pt1->reset = 1;
+       pt1_update_power(pt1);
+       pt1_cleanup_adapters(pt1);
        i2c_del_adapter(&pt1->i2c_adap);
        pci_set_drvdata(pdev, NULL);
        kfree(pt1);
@@ -936,10 +1071,21 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_pci_iounmap;
        }
 
+       mutex_init(&pt1->lock);
        pt1->pdev = pdev;
        pt1->regs = regs;
        pci_set_drvdata(pdev, pt1);
 
+       ret = pt1_init_adapters(pt1);
+       if (ret < 0)
+               goto err_kfree;
+
+       mutex_init(&pt1->lock);
+
+       pt1->power = 0;
+       pt1->reset = 1;
+       pt1_update_power(pt1);
+
        i2c_adap = &pt1->i2c_adap;
        i2c_adap->class = I2C_CLASS_TV_DIGITAL;
        i2c_adap->algo = &pt1_i2c_algo;
@@ -948,9 +1094,7 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        i2c_set_adapdata(i2c_adap, pt1);
        ret = i2c_add_adapter(i2c_adap);
        if (ret < 0)
-               goto err_kfree;
-
-       pt1_set_power(pt1, 0, 0, 1);
+               goto err_pt1_cleanup_adapters;
 
        pt1_i2c_init(pt1);
        pt1_i2c_wait(pt1);
@@ -979,19 +1123,21 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        pt1_init_streams(pt1);
 
-       pt1_set_power(pt1, 1, 0, 1);
+       pt1->power = 1;
+       pt1_update_power(pt1);
        schedule_timeout_uninterruptible((HZ + 49) / 50);
 
-       pt1_set_power(pt1, 1, 0, 0);
+       pt1->reset = 0;
+       pt1_update_power(pt1);
        schedule_timeout_uninterruptible((HZ + 999) / 1000);
 
-       ret = pt1_init_adapters(pt1);
+       ret = pt1_init_frontends(pt1);
        if (ret < 0)
                goto err_pt1_disable_ram;
 
        ret = pt1_init_tables(pt1);
        if (ret < 0)
-               goto err_pt1_cleanup_adapters;
+               goto err_pt1_cleanup_frontends;
 
        kthread = kthread_run(pt1_thread, pt1, "pt1");
        if (IS_ERR(kthread)) {
@@ -1004,11 +1150,15 @@ pt1_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
 err_pt1_cleanup_tables:
        pt1_cleanup_tables(pt1);
-err_pt1_cleanup_adapters:
-       pt1_cleanup_adapters(pt1);
+err_pt1_cleanup_frontends:
+       pt1_cleanup_frontends(pt1);
 err_pt1_disable_ram:
        pt1_disable_ram(pt1);
-       pt1_set_power(pt1, 0, 0, 1);
+       pt1->power = 0;
+       pt1->reset = 1;
+       pt1_update_power(pt1);
+err_pt1_cleanup_adapters:
+       pt1_cleanup_adapters(pt1);
 err_i2c_del_adapter:
        i2c_del_adapter(i2c_adap);
 err_kfree:
@@ -1027,6 +1177,7 @@ err:
 
 static struct pci_device_id pt1_id_table[] = {
        { PCI_DEVICE(0x10ee, 0x211a) },
+       { PCI_DEVICE(0x10ee, 0x222a) },
        { },
 };
 MODULE_DEVICE_TABLE(pci, pt1_id_table);
@@ -1054,5 +1205,5 @@ module_init(pt1_init);
 module_exit(pt1_cleanup);
 
 MODULE_AUTHOR("Takahito HIRANO <hiranotaka@zng.info>");
-MODULE_DESCRIPTION("Earthsoft PT1 Driver");
+MODULE_DESCRIPTION("Earthsoft PT1/PT2 Driver");
 MODULE_LICENSE("GPL");
index fc65949..451641c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ISDB-S driver for VA1J5JF8007
+ * ISDB-S driver for VA1J5JF8007/VA1J5JF8011
  *
  * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
  *
@@ -580,7 +580,7 @@ static void va1j5jf8007s_release(struct dvb_frontend *fe)
 
 static struct dvb_frontend_ops va1j5jf8007s_ops = {
        .info = {
-               .name = "VA1J5JF8007 ISDB-S",
+               .name = "VA1J5JF8007/VA1J5JF8011 ISDB-S",
                .type = FE_QPSK,
                .frequency_min = 950000,
                .frequency_max = 2150000,
@@ -628,28 +628,50 @@ static int va1j5jf8007s_prepare_1(struct va1j5jf8007s_state *state)
        return 0;
 }
 
-static const u8 va1j5jf8007s_prepare_bufs[][2] = {
+static const u8 va1j5jf8007s_20mhz_prepare_bufs[][2] = {
        {0x04, 0x02}, {0x0d, 0x55}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01},
        {0x1c, 0x0a}, {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0},
        {0x52, 0x89}, {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69},
        {0x87, 0x04}, {0x8e, 0x02}, {0xa3, 0xf7}, {0xa5, 0xc0},
 };
 
+static const u8 va1j5jf8007s_25mhz_prepare_bufs[][2] = {
+       {0x04, 0x02}, {0x11, 0x40}, {0x13, 0x80}, {0x17, 0x01}, {0x1c, 0x0a},
+       {0x1d, 0xaa}, {0x1e, 0x20}, {0x1f, 0x88}, {0x51, 0xb0}, {0x52, 0x89},
+       {0x53, 0xb3}, {0x5a, 0x2d}, {0x5b, 0xd3}, {0x85, 0x69}, {0x87, 0x04},
+       {0x8e, 0x26}, {0xa3, 0xf7}, {0xa5, 0xc0},
+};
+
 static int va1j5jf8007s_prepare_2(struct va1j5jf8007s_state *state)
 {
+       const u8 (*bufs)[2];
+       int size;
        u8 addr;
        u8 buf[2];
        struct i2c_msg msg;
        int i;
 
+       switch (state->config->frequency) {
+       case VA1J5JF8007S_20MHZ:
+               bufs = va1j5jf8007s_20mhz_prepare_bufs;
+               size = ARRAY_SIZE(va1j5jf8007s_20mhz_prepare_bufs);
+               break;
+       case VA1J5JF8007S_25MHZ:
+               bufs = va1j5jf8007s_25mhz_prepare_bufs;
+               size = ARRAY_SIZE(va1j5jf8007s_25mhz_prepare_bufs);
+               break;
+       default:
+               return -EINVAL;
+       }
+
        addr = state->config->demod_address;
 
        msg.addr = addr;
        msg.flags = 0;
        msg.len = 2;
        msg.buf = buf;
-       for (i = 0; i < ARRAY_SIZE(va1j5jf8007s_prepare_bufs); i++) {
-               memcpy(buf, va1j5jf8007s_prepare_bufs[i], sizeof(buf));
+       for (i = 0; i < size; i++) {
+               memcpy(buf, bufs[i], sizeof(buf));
                if (i2c_transfer(state->adap, &msg, 1) != 1)
                        return -EREMOTEIO;
        }
index aa228a8..b7d6f05 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ISDB-S driver for VA1J5JF8007
+ * ISDB-S driver for VA1J5JF8007/VA1J5JF8011
  *
  * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
  *
 #ifndef VA1J5JF8007S_H
 #define VA1J5JF8007S_H
 
+enum va1j5jf8007s_frequency {
+       VA1J5JF8007S_20MHZ,
+       VA1J5JF8007S_25MHZ,
+};
+
 struct va1j5jf8007s_config {
        u8 demod_address;
+       enum va1j5jf8007s_frequency frequency;
 };
 
 struct i2c_adapter;
index 3db4f3e..0f085c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ISDB-T driver for VA1J5JF8007
+ * ISDB-T driver for VA1J5JF8007/VA1J5JF8011
  *
  * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
  *
@@ -429,7 +429,7 @@ static void va1j5jf8007t_release(struct dvb_frontend *fe)
 
 static struct dvb_frontend_ops va1j5jf8007t_ops = {
        .info = {
-               .name = "VA1J5JF8007 ISDB-T",
+               .name = "VA1J5JF8007/VA1J5JF8011 ISDB-T",
                .type = FE_OFDM,
                .frequency_min = 90000000,
                .frequency_max = 770000000,
@@ -448,29 +448,50 @@ static struct dvb_frontend_ops va1j5jf8007t_ops = {
        .release = va1j5jf8007t_release,
 };
 
-static const u8 va1j5jf8007t_prepare_bufs[][2] = {
+static const u8 va1j5jf8007t_20mhz_prepare_bufs[][2] = {
        {0x03, 0x90}, {0x14, 0x8f}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2},
        {0x22, 0x83}, {0x31, 0x0d}, {0x32, 0xe0}, {0x39, 0xd3}, {0x3a, 0x00},
        {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x02}, {0x76, 0x4e}, {0x77, 0x03},
        {0xef, 0x01}
 };
 
+static const u8 va1j5jf8007t_25mhz_prepare_bufs[][2] = {
+       {0x03, 0x90}, {0x1c, 0x2a}, {0x1d, 0xa8}, {0x1e, 0xa2}, {0x22, 0x83},
+       {0x3a, 0x00}, {0x5c, 0x40}, {0x5f, 0x80}, {0x75, 0x0a}, {0x76, 0x4c},
+       {0x77, 0x03}, {0xef, 0x01}
+};
+
 int va1j5jf8007t_prepare(struct dvb_frontend *fe)
 {
        struct va1j5jf8007t_state *state;
+       const u8 (*bufs)[2];
+       int size;
        u8 buf[2];
        struct i2c_msg msg;
        int i;
 
        state = fe->demodulator_priv;
 
+       switch (state->config->frequency) {
+       case VA1J5JF8007T_20MHZ:
+               bufs = va1j5jf8007t_20mhz_prepare_bufs;
+               size = ARRAY_SIZE(va1j5jf8007t_20mhz_prepare_bufs);
+               break;
+       case VA1J5JF8007T_25MHZ:
+               bufs = va1j5jf8007t_25mhz_prepare_bufs;
+               size = ARRAY_SIZE(va1j5jf8007t_25mhz_prepare_bufs);
+               break;
+       default:
+               return -EINVAL;
+       }
+
        msg.addr = state->config->demod_address;
        msg.flags = 0;
        msg.len = sizeof(buf);
        msg.buf = buf;
 
-       for (i = 0; i < ARRAY_SIZE(va1j5jf8007t_prepare_bufs); i++) {
-               memcpy(buf, va1j5jf8007t_prepare_bufs[i], sizeof(buf));
+       for (i = 0; i < size; i++) {
+               memcpy(buf, bufs[i], sizeof(buf));
                if (i2c_transfer(state->adap, &msg, 1) != 1)
                        return -EREMOTEIO;
        }
index ed49906..2903be5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * ISDB-T driver for VA1J5JF8007
+ * ISDB-T driver for VA1J5JF8007/VA1J5JF8011
  *
  * Copyright (C) 2009 HIRANO Takahito <hiranotaka@zng.info>
  *
 #ifndef VA1J5JF8007T_H
 #define VA1J5JF8007T_H
 
+enum va1j5jf8007t_frequency {
+       VA1J5JF8007T_20MHZ,
+       VA1J5JF8007T_25MHZ,
+};
+
 struct va1j5jf8007t_config {
        u8 demod_address;
+       enum va1j5jf8007t_frequency frequency;
 };
 
 struct i2c_adapter;
index 49c2a81..4617143 100644 (file)
@@ -35,7 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/input.h>
 #include <linux/spinlock.h>
-#include <media/ir-common.h>
+#include <media/ir-core.h>
 
 #include "budget.h"
 
@@ -54,6 +54,8 @@
 #include "tda1002x.h"
 #include "tda827x.h"
 
+#define MODULE_NAME "budget_ci"
+
 /*
  * Regarding DEBIADDR_IR:
  * Some CI modules hang if random addresses are read.
 #define SLOTSTATUS_READY       8
 #define SLOTSTATUS_OCCUPIED    (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
 
-/*
- * Milliseconds during which a key is regarded as pressed.
- * If an identical command arrives within this time, the timer will start over.
- */
-#define IR_KEYPRESS_TIMEOUT    250
-
 /* RC5 device wildcard */
 #define IR_DEVICE_ANY          255
 
@@ -102,12 +98,9 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 struct budget_ci_ir {
        struct input_dev *dev;
        struct tasklet_struct msp430_irq_tasklet;
-       struct timer_list timer_keyup;
        char name[72]; /* 40 + 32 for (struct saa7146_dev).name */
        char phys[32];
-       struct ir_input_state state;
        int rc5_device;
-       u32 last_raw;
        u32 ir_key;
        bool have_command;
 };
@@ -122,18 +115,11 @@ struct budget_ci {
        u8 tuner_pll_address; /* used for philips_tdm1316l configs */
 };
 
-static void msp430_ir_keyup(unsigned long data)
-{
-       struct budget_ci_ir *ir = (struct budget_ci_ir *) data;
-       ir_input_nokey(ir->dev, &ir->state);
-}
-
 static void msp430_ir_interrupt(unsigned long data)
 {
        struct budget_ci *budget_ci = (struct budget_ci *) data;
        struct input_dev *dev = budget_ci->ir.dev;
        u32 command = ttpci_budget_debiread(&budget_ci->budget, DEBINOSWAP, DEBIADDR_IR, 2, 1, 0) >> 8;
-       u32 raw;
 
        /*
         * The msp430 chip can generate two different bytes, command and device
@@ -169,20 +155,12 @@ static void msp430_ir_interrupt(unsigned long data)
                return;
        budget_ci->ir.have_command = false;
 
+       /* FIXME: We should generate complete scancodes with device info */
        if (budget_ci->ir.rc5_device != IR_DEVICE_ANY &&
            budget_ci->ir.rc5_device != (command & 0x1f))
                return;
 
-       /* Is this a repeated key sequence? (same device, command, toggle) */
-       raw = budget_ci->ir.ir_key | (command << 8);
-       if (budget_ci->ir.last_raw != raw || !timer_pending(&budget_ci->ir.timer_keyup)) {
-               ir_input_nokey(dev, &budget_ci->ir.state);
-               ir_input_keydown(dev, &budget_ci->ir.state,
-                                budget_ci->ir.ir_key);
-               budget_ci->ir.last_raw = raw;
-       }
-
-       mod_timer(&budget_ci->ir.timer_keyup, jiffies + msecs_to_jiffies(IR_KEYPRESS_TIMEOUT));
+       ir_keydown(dev, budget_ci->ir.ir_key, (command & 0x20) ? 1 : 0);
 }
 
 static int msp430_ir_init(struct budget_ci *budget_ci)
@@ -190,7 +168,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
        struct saa7146_dev *saa = budget_ci->budget.dev;
        struct input_dev *input_dev = budget_ci->ir.dev;
        int error;
-       struct ir_scancode_table *ir_codes;
+       char *ir_codes = NULL;
 
 
        budget_ci->ir.dev = input_dev = input_allocate_device();
@@ -230,7 +208,7 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
        case 0x1011:
        case 0x1012:
                /* The hauppauge keymap is a superset of these remotes */
-               ir_codes = &ir_codes_hauppauge_new_table;
+               ir_codes = RC_MAP_HAUPPAUGE_NEW;
 
                if (rc5_device < 0)
                        budget_ci->ir.rc5_device = 0x1f;
@@ -239,22 +217,15 @@ static int msp430_ir_init(struct budget_ci *budget_ci)
        case 0x1017:
        case 0x101a:
                /* for the Technotrend 1500 bundled remote */
-               ir_codes = &ir_codes_tt_1500_table;
+               ir_codes = RC_MAP_TT_1500;
                break;
        default:
                /* unknown remote */
-               ir_codes = &ir_codes_budget_ci_old_table;
+               ir_codes = RC_MAP_BUDGET_CI_OLD;
                break;
        }
 
-       ir_input_init(input_dev, &budget_ci->ir.state, IR_TYPE_RC5);
-
-       /* initialise the key-up timeout handler */
-       init_timer(&budget_ci->ir.timer_keyup);
-       budget_ci->ir.timer_keyup.function = msp430_ir_keyup;
-       budget_ci->ir.timer_keyup.data = (unsigned long) &budget_ci->ir;
-       budget_ci->ir.last_raw = 0xffff; /* An impossible value */
-       error = ir_input_register(input_dev, ir_codes, NULL);
+       error = ir_input_register(input_dev, ir_codes, NULL, MODULE_NAME);
        if (error) {
                printk(KERN_ERR "budget_ci: could not init driver for IR device (code %d)\n", error);
                return error;
@@ -282,9 +253,6 @@ static void msp430_ir_deinit(struct budget_ci *budget_ci)
        saa7146_setgpio(saa, 3, SAA7146_GPIO_INPUT);
        tasklet_kill(&budget_ci->ir.msp430_irq_tasklet);
 
-       del_timer_sync(&dev->timer);
-       ir_input_nokey(dev, &budget_ci->ir.state);
-
        ir_input_unregister(dev);
 }
 
index 1500210..874a10a 100644 (file)
@@ -442,6 +442,7 @@ static struct stv090x_config tt1600_stv090x_config = {
        .repeater_level         = STV090x_RPTLEVEL_16,
 
        .tuner_init             = NULL,
+       .tuner_sleep            = NULL,
        .tuner_set_mode         = NULL,
        .tuner_set_frequency    = NULL,
        .tuner_get_frequency    = NULL,
@@ -627,22 +628,36 @@ static void frontend_init(struct budget *budget)
                                                 &tt1600_stv6110x_config,
                                                 &budget->i2c_adap);
 
-                               tt1600_stv090x_config.tuner_init          = ctl->tuner_init;
-                               tt1600_stv090x_config.tuner_set_mode      = ctl->tuner_set_mode;
-                               tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
-                               tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
-                               tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
-                               tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
-                               tt1600_stv090x_config.tuner_set_bbgain    = ctl->tuner_set_bbgain;
-                               tt1600_stv090x_config.tuner_get_bbgain    = ctl->tuner_get_bbgain;
-                               tt1600_stv090x_config.tuner_set_refclk    = ctl->tuner_set_refclk;
-                               tt1600_stv090x_config.tuner_get_status    = ctl->tuner_get_status;
-
-                               dvb_attach(isl6423_attach,
-                                       budget->dvb_frontend,
-                                       &budget->i2c_adap,
-                                       &tt1600_isl6423_config);
-
+                               if (ctl) {
+                                       tt1600_stv090x_config.tuner_init          = ctl->tuner_init;
+                                       tt1600_stv090x_config.tuner_sleep         = ctl->tuner_sleep;
+                                       tt1600_stv090x_config.tuner_set_mode      = ctl->tuner_set_mode;
+                                       tt1600_stv090x_config.tuner_set_frequency = ctl->tuner_set_frequency;
+                                       tt1600_stv090x_config.tuner_get_frequency = ctl->tuner_get_frequency;
+                                       tt1600_stv090x_config.tuner_set_bandwidth = ctl->tuner_set_bandwidth;
+                                       tt1600_stv090x_config.tuner_get_bandwidth = ctl->tuner_get_bandwidth;
+                                       tt1600_stv090x_config.tuner_set_bbgain    = ctl->tuner_set_bbgain;
+                                       tt1600_stv090x_config.tuner_get_bbgain    = ctl->tuner_get_bbgain;
+                                       tt1600_stv090x_config.tuner_set_refclk    = ctl->tuner_set_refclk;
+                                       tt1600_stv090x_config.tuner_get_status    = ctl->tuner_get_status;
+
+                                       /* call the init function once to initialize
+                                          tuner's clock output divider and demod's
+                                          master clock */
+                                       if (budget->dvb_frontend->ops.init)
+                                               budget->dvb_frontend->ops.init(budget->dvb_frontend);
+
+                                       if (dvb_attach(isl6423_attach,
+                                                      budget->dvb_frontend,
+                                                      &budget->i2c_adap,
+                                                      &tt1600_isl6423_config) == NULL) {
+                                               printk(KERN_ERR "%s: No Intersil ISL6423 found!\n", __func__);
+                                               goto error_out;
+                                       }
+                               } else {
+                                       printk(KERN_ERR "%s: No STV6110(A) Silicon Tuner found!\n", __func__);
+                                       goto error_out;
+                               }
                        }
                }
                break;
index 02a9cef..353b828 100644 (file)
@@ -144,7 +144,10 @@ struct amradio_device {
        int initialized;
 };
 
-#define vdev_to_amradio(r) container_of(r, struct amradio_device, videodev)
+static inline struct amradio_device *to_amradio_dev(struct v4l2_device *v4l2_dev)
+{
+       return container_of(v4l2_dev, struct amradio_device, v4l2_dev);
+}
 
 /* USB Device ID List */
 static struct usb_device_id usb_amradio_device_table[] = {
@@ -284,13 +287,12 @@ static int amradio_set_stereo(struct amradio_device *radio, char argument)
  */
 static void usb_amradio_disconnect(struct usb_interface *intf)
 {
-       struct amradio_device *radio = usb_get_intfdata(intf);
+       struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
        mutex_lock(&radio->lock);
        radio->usbdev = NULL;
        mutex_unlock(&radio->lock);
 
-       usb_set_intfdata(intf, NULL);
        v4l2_device_disconnect(&radio->v4l2_dev);
        video_unregister_device(&radio->videodev);
 }
@@ -500,7 +502,7 @@ out:
 /* open device - amradio_start() and amradio_setfreq() */
 static int usb_amradio_open(struct file *file)
 {
-       struct amradio_device *radio = vdev_to_amradio(video_devdata(file));
+       struct amradio_device *radio = video_drvdata(file);
        int retval = 0;
 
        mutex_lock(&radio->lock);
@@ -566,7 +568,7 @@ unlock:
 /* Suspend device - stop device. Need to be checked and fixed */
 static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
 {
-       struct amradio_device *radio = usb_get_intfdata(intf);
+       struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
        mutex_lock(&radio->lock);
 
@@ -584,7 +586,7 @@ static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
 /* Resume device - start device. Need to be checked and fixed */
 static int usb_amradio_resume(struct usb_interface *intf)
 {
-       struct amradio_device *radio = usb_get_intfdata(intf);
+       struct amradio_device *radio = to_amradio_dev(usb_get_intfdata(intf));
 
        mutex_lock(&radio->lock);
 
@@ -633,9 +635,7 @@ static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = {
 
 static void usb_amradio_video_device_release(struct video_device *videodev)
 {
-       struct amradio_device *radio = vdev_to_amradio(videodev);
-
-       v4l2_device_unregister(&radio->v4l2_dev);
+       struct amradio_device *radio = video_get_drvdata(videodev);
 
        /* free rest memory */
        kfree(radio->buffer);
@@ -693,7 +693,6 @@ static int usb_amradio_probe(struct usb_interface *intf,
                goto err_vdev;
        }
 
-       usb_set_intfdata(intf, radio);
        return 0;
 
 err_vdev:
index 9644cf7..ad9e6f9 100644 (file)
@@ -45,6 +45,10 @@ config VIDEO_TUNER
        tristate
        depends on MEDIA_TUNER
 
+config V4L2_MEM2MEM_DEV
+       tristate
+       depends on VIDEOBUF_GEN
+
 #
 # Multimedia Video device configuration
 #
@@ -480,6 +484,12 @@ config VIDEO_ADV7343
          To compile this driver as a module, choose M here: the
          module will be called adv7343.
 
+config VIDEO_AK881X
+       tristate "AK8813/AK8814 video encoders"
+       depends on I2C
+       help
+         Video output driver for AKM AK8813 and AK8814 TV encoders
+
 comment "Video improvement chips"
 
 config VIDEO_UPD64031A
@@ -520,6 +530,13 @@ config DISPLAY_DAVINCI_DM646X_EVM
          To compile this driver as a module, choose M here: the
          module will be called vpif_display.
 
+config VIDEO_SH_VOU
+       tristate "SuperH VOU video output driver"
+       depends on VIDEO_DEV && ARCH_SHMOBILE
+       select VIDEOBUF_DMA_CONTIG
+       help
+         Support for the Video Output Unit (VOU) on SuperH SoCs.
+
 config CAPTURE_DAVINCI_DM646X_EVM
        tristate "DM646x EVM Video Capture"
        depends on VIDEO_DEV && MACH_DAVINCI_DM6467_EVM
@@ -542,7 +559,8 @@ config VIDEO_DAVINCI_VPIF
 
 config VIDEO_VIVI
        tristate "Virtual Video Driver"
-       depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64
+       depends on VIDEO_DEV && VIDEO_V4L2 && !SPARC32 && !SPARC64 && FONTS
+       select FONT_8x16
        select VIDEOBUF_VMALLOC
        default n
        ---help---
@@ -613,6 +631,8 @@ config VIDEO_ISIF
           To compile this driver as a module, choose M here: the
           module will be called vpfe.
 
+source "drivers/media/video/omap/Kconfig"
+
 source "drivers/media/video/bt8xx/Kconfig"
 
 config VIDEO_PMS
@@ -647,7 +667,7 @@ config VIDEO_CQCAM
 
 config VIDEO_W9966
        tristate "W9966CF Webcam (FlyCam Supra and others) Video For Linux"
-       depends on PARPORT_1284 && PARPORT && VIDEO_V4L1
+       depends on PARPORT_1284 && PARPORT && VIDEO_V4L2
        help
          Video4linux driver for Winbond's w9966 based Webcams.
          Currently tested with the LifeView FlyCam Supra.
@@ -740,7 +760,7 @@ source "drivers/media/video/zoran/Kconfig"
 
 config VIDEO_MEYE
        tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
-       depends on PCI && SONY_LAPTOP && VIDEO_V4L1
+       depends on PCI && SONY_LAPTOP && VIDEO_V4L2
        ---help---
          This is the video4linux driver for the Motion Eye camera found
          in the Vaio Picturebook laptops. Please read the material in
@@ -807,7 +827,7 @@ source "drivers/media/video/saa7164/Kconfig"
 
 config VIDEO_M32R_AR
        tristate "AR devices"
-       depends on M32R && VIDEO_V4L1
+       depends on M32R && VIDEO_V4L2
        ---help---
          This is a video4linux driver for the Renesas AR (Artificial Retina)
          camera module.
@@ -1107,3 +1127,27 @@ config USB_S2255
 
 endif # V4L_USB_DRIVERS
 endif # VIDEO_CAPTURE_DRIVERS
+
+menuconfig V4L_MEM2MEM_DRIVERS
+       bool "Memory-to-memory multimedia devices"
+       depends on VIDEO_V4L2
+       default n
+       ---help---
+         Say Y here to enable selecting drivers for V4L devices that
+         use system memory for both source and destination buffers, as opposed
+         to capture and output drivers, which use memory buffers for just
+         one of those.
+
+if V4L_MEM2MEM_DRIVERS
+
+config VIDEO_MEM2MEM_TESTDEV
+       tristate "Virtual test device for mem2mem framework"
+       depends on VIDEO_DEV && VIDEO_V4L2
+       select VIDEOBUF_VMALLOC
+       select V4L2_MEM2MEM_DEV
+       default n
+       ---help---
+         This is a virtual test device for the memory-to-memory driver
+         framework.
+
+endif # V4L_MEM2MEM_DRIVERS
index c51c386..cc93859 100644 (file)
@@ -10,7 +10,8 @@ stkwebcam-objs        :=      stk-webcam.o stk-sensor.o
 
 omap2cam-objs  :=      omap24xxcam.o omap24xxcam-dma.o
 
-videodev-objs  :=      v4l2-dev.o v4l2-ioctl.o v4l2-device.o
+videodev-objs  :=      v4l2-dev.o v4l2-ioctl.o v4l2-device.o v4l2-fh.o \
+                       v4l2-event.o
 
 # V4L2 core modules
 
@@ -117,6 +118,8 @@ obj-$(CONFIG_VIDEOBUF_VMALLOC) += videobuf-vmalloc.o
 obj-$(CONFIG_VIDEOBUF_DVB) += videobuf-dvb.o
 obj-$(CONFIG_VIDEO_BTCX)  += btcx-risc.o
 
+obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o
+
 obj-$(CONFIG_VIDEO_M32R_AR_M64278) += arv.o
 
 obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
@@ -149,8 +152,11 @@ obj-$(CONFIG_VIDEO_IVTV) += ivtv/
 obj-$(CONFIG_VIDEO_CX18) += cx18/
 
 obj-$(CONFIG_VIDEO_VIVI) += vivi.o
+obj-$(CONFIG_VIDEO_MEM2MEM_TESTDEV) += mem2mem_testdev.o
 obj-$(CONFIG_VIDEO_CX23885) += cx23885/
 
+obj-$(CONFIG_VIDEO_AK881X)             += ak881x.o
+
 obj-$(CONFIG_VIDEO_OMAP2)              += omap2cam.o
 obj-$(CONFIG_SOC_CAMERA)               += soc_camera.o soc_mediabus.o
 obj-$(CONFIG_SOC_CAMERA_PLATFORM)      += soc_camera_platform.o
@@ -160,6 +166,10 @@ obj-$(CONFIG_VIDEO_MX3)                    += mx3_camera.o
 obj-$(CONFIG_VIDEO_PXA27x)             += pxa_camera.o
 obj-$(CONFIG_VIDEO_SH_MOBILE_CEU)      += sh_mobile_ceu_camera.o
 
+obj-$(CONFIG_ARCH_DAVINCI)             += davinci/
+
+obj-$(CONFIG_VIDEO_SH_VOU)             += sh_vou.o
+
 obj-$(CONFIG_VIDEO_AU0828) += au0828/
 
 obj-$(CONFIG_USB_VIDEO_CLASS)  += uvc/
@@ -169,6 +179,8 @@ obj-$(CONFIG_VIDEO_IR_I2C)  += ir-kbd-i2c.o
 
 obj-$(CONFIG_ARCH_DAVINCI)     += davinci/
 
+obj-$(CONFIG_ARCH_OMAP)        += omap/
+
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
 EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
 EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/video/ak881x.c b/drivers/media/video/ak881x.c
new file mode 100644 (file)
index 0000000..35390d4
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+ * Driver for AK8813 / AK8814 TV-ecoders from Asahi Kasei Microsystems Co., Ltd. (AKM)
+ *
+ * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/videodev2.h>
+
+#include <media/ak881x.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
+
+#define AK881X_INTERFACE_MODE  0
+#define AK881X_VIDEO_PROCESS1  1
+#define AK881X_VIDEO_PROCESS2  2
+#define AK881X_VIDEO_PROCESS3  3
+#define AK881X_DAC_MODE                5
+#define AK881X_STATUS          0x24
+#define AK881X_DEVICE_ID       0x25
+#define AK881X_DEVICE_REVISION 0x26
+
+struct ak881x {
+       struct v4l2_subdev subdev;
+       struct ak881x_pdata *pdata;
+       unsigned int lines;
+       int id; /* DEVICE_ID code V4L2_IDENT_AK881X code from v4l2-chip-ident.h */
+       char revision;  /* DEVICE_REVISION content */
+};
+
+static int reg_read(struct i2c_client *client, const u8 reg)
+{
+       return i2c_smbus_read_byte_data(client, reg);
+}
+
+static int reg_write(struct i2c_client *client, const u8 reg,
+                    const u8 data)
+{
+       return i2c_smbus_write_byte_data(client, reg, data);
+}
+
+static int reg_set(struct i2c_client *client, const u8 reg,
+                  const u8 data, u8 mask)
+{
+       int ret = reg_read(client, reg);
+       if (ret < 0)
+               return ret;
+       return reg_write(client, reg, (ret & ~mask) | (data & mask));
+}
+
+static struct ak881x *to_ak881x(const struct i2c_client *client)
+{
+       return container_of(i2c_get_clientdata(client), struct ak881x, subdev);
+}
+
+static int ak881x_g_chip_ident(struct v4l2_subdev *sd,
+                              struct v4l2_dbg_chip_ident *id)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct ak881x *ak881x = to_ak881x(client);
+
+       if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
+               return -EINVAL;
+
+       if (id->match.addr != client->addr)
+               return -ENODEV;
+
+       id->ident       = ak881x->id;
+       id->revision    = ak881x->revision;
+
+       return 0;
+}
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int ak881x_g_register(struct v4l2_subdev *sd,
+                            struct v4l2_dbg_register *reg)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+
+       if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x26)
+               return -EINVAL;
+
+       if (reg->match.addr != client->addr)
+               return -ENODEV;
+
+       reg->val = reg_read(client, reg->reg);
+
+       if (reg->val > 0xffff)
+               return -EIO;
+
+       return 0;
+}
+
+static int ak881x_s_register(struct v4l2_subdev *sd,
+                            struct v4l2_dbg_register *reg)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+
+       if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x26)
+               return -EINVAL;
+
+       if (reg->match.addr != client->addr)
+               return -ENODEV;
+
+       if (reg_write(client, reg->reg, reg->val) < 0)
+               return -EIO;
+
+       return 0;
+}
+#endif
+
+static int ak881x_try_g_mbus_fmt(struct v4l2_subdev *sd,
+                                struct v4l2_mbus_framefmt *mf)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct ak881x *ak881x = to_ak881x(client);
+
+       v4l_bound_align_image(&mf->width, 0, 720, 2,
+                             &mf->height, 0, ak881x->lines, 1, 0);
+       mf->field       = V4L2_FIELD_INTERLACED;
+       mf->code        = V4L2_MBUS_FMT_YUYV8_2X8_LE;
+       mf->colorspace  = V4L2_COLORSPACE_SMPTE170M;
+
+       return 0;
+}
+
+static int ak881x_s_mbus_fmt(struct v4l2_subdev *sd,
+                            struct v4l2_mbus_framefmt *mf)
+{
+       if (mf->field != V4L2_FIELD_INTERLACED ||
+           mf->code != V4L2_MBUS_FMT_YUYV8_2X8_LE)
+               return -EINVAL;
+
+       return ak881x_try_g_mbus_fmt(sd, mf);
+}
+
+static int ak881x_enum_mbus_fmt(struct v4l2_subdev *sd, int index,
+                               enum v4l2_mbus_pixelcode *code)
+{
+       if (index)
+               return -EINVAL;
+
+       *code = V4L2_MBUS_FMT_YUYV8_2X8_LE;
+       return 0;
+}
+
+static int ak881x_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct ak881x *ak881x = to_ak881x(client);
+
+       a->bounds.left                  = 0;
+       a->bounds.top                   = 0;
+       a->bounds.width                 = 720;
+       a->bounds.height                = ak881x->lines;
+       a->defrect                      = a->bounds;
+       a->type                         = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       a->pixelaspect.numerator        = 1;
+       a->pixelaspect.denominator      = 1;
+
+       return 0;
+}
+
+static int ak881x_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct ak881x *ak881x = to_ak881x(client);
+       u8 vp1;
+
+       if (std == V4L2_STD_NTSC_443) {
+               vp1 = 3;
+               ak881x->lines = 480;
+       } else if (std == V4L2_STD_PAL_M) {
+               vp1 = 5;
+               ak881x->lines = 480;
+       } else if (std == V4L2_STD_PAL_60) {
+               vp1 = 7;
+               ak881x->lines = 480;
+       } else if (std && !(std & ~V4L2_STD_PAL)) {
+               vp1 = 0xf;
+               ak881x->lines = 576;
+       } else if (std && !(std & ~V4L2_STD_NTSC)) {
+               vp1 = 0;
+               ak881x->lines = 480;
+       } else {
+               /* No SECAM or PAL_N/Nc supported */
+               return -EINVAL;
+       }
+
+       reg_set(client, AK881X_VIDEO_PROCESS1, vp1, 0xf);
+
+       return 0;
+}
+
+static int ak881x_s_stream(struct v4l2_subdev *sd, int enable)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct ak881x *ak881x = to_ak881x(client);
+
+       if (enable) {
+               u8 dac;
+               /* For colour-bar testing set bit 6 of AK881X_VIDEO_PROCESS1 */
+               /* Default: composite output */
+               if (ak881x->pdata->flags & AK881X_COMPONENT)
+                       dac = 3;
+               else
+                       dac = 4;
+               /* Turn on the DAC(s) */
+               reg_write(client, AK881X_DAC_MODE, dac);
+               dev_dbg(&client->dev, "chip status 0x%x\n",
+                       reg_read(client, AK881X_STATUS));
+       } else {
+               /* ...and clear bit 6 of AK881X_VIDEO_PROCESS1 here */
+               reg_write(client, AK881X_DAC_MODE, 0);
+               dev_dbg(&client->dev, "chip status 0x%x\n",
+                       reg_read(client, AK881X_STATUS));
+       }
+
+       return 0;
+}
+
+static struct v4l2_subdev_core_ops ak881x_subdev_core_ops = {
+       .g_chip_ident   = ak881x_g_chip_ident,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       .g_register     = ak881x_g_register,
+       .s_register     = ak881x_s_register,
+#endif
+};
+
+static struct v4l2_subdev_video_ops ak881x_subdev_video_ops = {
+       .s_mbus_fmt     = ak881x_s_mbus_fmt,
+       .g_mbus_fmt     = ak881x_try_g_mbus_fmt,
+       .try_mbus_fmt   = ak881x_try_g_mbus_fmt,
+       .cropcap        = ak881x_cropcap,
+       .enum_mbus_fmt  = ak881x_enum_mbus_fmt,
+       .s_std_output   = ak881x_s_std_output,
+       .s_stream       = ak881x_s_stream,
+};
+
+static struct v4l2_subdev_ops ak881x_subdev_ops = {
+       .core   = &ak881x_subdev_core_ops,
+       .video  = &ak881x_subdev_video_ops,
+};
+
+static int ak881x_probe(struct i2c_client *client,
+                       const struct i2c_device_id *did)
+{
+       struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
+       struct ak881x *ak881x;
+       u8 ifmode, data;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+               dev_warn(&adapter->dev,
+                        "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
+               return -EIO;
+       }
+
+       ak881x = kzalloc(sizeof(struct ak881x), GFP_KERNEL);
+       if (!ak881x)
+               return -ENOMEM;
+
+       v4l2_i2c_subdev_init(&ak881x->subdev, client, &ak881x_subdev_ops);
+
+       data = reg_read(client, AK881X_DEVICE_ID);
+
+       switch (data) {
+       case 0x13:
+               ak881x->id = V4L2_IDENT_AK8813;
+               break;
+       case 0x14:
+               ak881x->id = V4L2_IDENT_AK8814;
+               break;
+       default:
+               dev_err(&client->dev,
+                       "No ak881x chip detected, register read %x\n", data);
+               kfree(ak881x);
+               return -ENODEV;
+       }
+
+       ak881x->revision = reg_read(client, AK881X_DEVICE_REVISION);
+       ak881x->pdata = client->dev.platform_data;
+
+       if (ak881x->pdata) {
+               if (ak881x->pdata->flags & AK881X_FIELD)
+                       ifmode = 4;
+               else
+                       ifmode = 0;
+
+               switch (ak881x->pdata->flags & AK881X_IF_MODE_MASK) {
+               case AK881X_IF_MODE_BT656:
+                       ifmode |= 1;
+                       break;
+               case AK881X_IF_MODE_MASTER:
+                       ifmode |= 2;
+                       break;
+               case AK881X_IF_MODE_SLAVE:
+               default:
+                       break;
+               }
+
+               dev_dbg(&client->dev, "IF mode %x\n", ifmode);
+
+               /*
+                * "Line Blanking No." seems to be the same as the number of
+                * "black" lines on, e.g., SuperH VOU, whose default value of 20
+                * "incidentally" matches ak881x' default
+                */
+               reg_write(client, AK881X_INTERFACE_MODE, ifmode | (20 << 3));
+       }
+
+       /* Hardware default: NTSC-M */
+       ak881x->lines = 480;
+
+       dev_info(&client->dev, "Detected an ak881x chip ID %x, revision %x\n",
+                data, ak881x->revision);
+
+       return 0;
+}
+
+static int ak881x_remove(struct i2c_client *client)
+{
+       struct ak881x *ak881x = to_ak881x(client);
+
+       v4l2_device_unregister_subdev(&ak881x->subdev);
+       kfree(ak881x);
+
+       return 0;
+}
+
+static const struct i2c_device_id ak881x_id[] = {
+       { "ak8813", 0 },
+       { "ak8814", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, ak881x_id);
+
+static struct i2c_driver ak881x_i2c_driver = {
+       .driver = {
+               .name = "ak881x",
+       },
+       .probe          = ak881x_probe,
+       .remove         = ak881x_remove,
+       .id_table       = ak881x_id,
+};
+
+static int __init ak881x_module_init(void)
+{
+       return i2c_add_driver(&ak881x_i2c_driver);
+}
+
+static void __exit ak881x_module_exit(void)
+{
+       i2c_del_driver(&ak881x_i2c_driver);
+}
+
+module_init(ak881x_module_init);
+module_exit(ak881x_module_exit);
+
+MODULE_DESCRIPTION("TV-output driver for ak8813/ak8814");
+MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
+MODULE_LICENSE("GPL v2");
index a356d6b..31e7a12 100644 (file)
 #include <linux/slab.h>
 #include <linux/mm.h>
 #include <linux/sched.h>
-#include <linux/videodev.h>
+#include <linux/version.h>
+#include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <linux/mutex.h>
 
@@ -39,7 +41,7 @@
 #include <asm/byteorder.h>
 
 #if 0
-#define DEBUG(n, args...) printk(args)
+#define DEBUG(n, args...) printk(KERN_INFO args)
 #define CHECK_LOST     1
 #else
 #define DEBUG(n, args...)
  */
 #define USE_INT                0       /* Don't modify */
 
-#define VERSION        "0.03"
+#define VERSION        "0.04"
 
 #define ar_inl(addr)           inl((unsigned long)(addr))
-#define ar_outl(val, addr)     outl((unsigned long)(val),(unsigned long)(addr))
+#define ar_outl(val, addr)     outl((unsigned long)(val), (unsigned long)(addr))
 
 extern struct cpuinfo_m32r     boot_cpu_data;
 
@@ -79,7 +81,7 @@ extern struct cpuinfo_m32r    boot_cpu_data;
 
 /* bits & bytes per pixel */
 #define AR_BITS_PER_PIXEL      16
-#define AR_BYTES_PER_PIXEL     (AR_BITS_PER_PIXEL/8)
+#define AR_BYTES_PER_PIXEL     (AR_BITS_PER_PIXEL / 8)
 
 /* line buffer size */
 #define AR_LINE_BYTES_VGA      (AR_WIDTH_VGA * AR_BYTES_PER_PIXEL)
@@ -104,8 +106,9 @@ extern struct cpuinfo_m32r  boot_cpu_data;
 #define AR_MODE_INTERLACE      0
 #define AR_MODE_NORMAL         1
 
-struct ar_device {
-       struct video_device *vdev;
+struct ar {
+       struct v4l2_device v4l2_dev;
+       struct video_device vdev;
        unsigned int start_capture;     /* duaring capture in INT. mode. */
 #if USE_INT
        unsigned char *line_buff;       /* DMA line buffer */
@@ -116,12 +119,13 @@ struct ar_device {
        int width, height;
        int frame_bytes, line_bytes;
        wait_queue_head_t wait;
-       unsigned long in_use;
        struct mutex lock;
 };
 
+static struct ar ardev;
+
 static int video_nr = -1;      /* video device number (first free) */
-static unsigned char   yuv[MAX_AR_FRAME_BYTES];
+static unsigned char yuv[MAX_AR_FRAME_BYTES];
 
 /* module parameters */
 /* default frequency */
@@ -133,9 +137,7 @@ module_param(freq, int, 0);
 module_param(vga, int, 0);
 module_param(vga_interlace, int, 0);
 
-static int ar_initialize(struct video_device *dev);
-
-static inline void wait_for_vsync(void)
+static void wait_for_vsync(void)
 {
        while (ar_inl(ARVCR0) & ARVCR0_VDS)     /* wait for VSYNC */
                cpu_relax();
@@ -143,7 +145,7 @@ static inline void wait_for_vsync(void)
                cpu_relax();
 }
 
-static inline void wait_acknowledge(void)
+static void wait_acknowledge(void)
 {
        int i;
 
@@ -156,7 +158,7 @@ static inline void wait_acknowledge(void)
 /*******************************************************************
  * I2C functions
  *******************************************************************/
-void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
+static void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
         unsigned long data3)
 {
        int i;
@@ -200,7 +202,7 @@ void iic(int n, unsigned long addr, unsigned long data1, unsigned long data2,
 }
 
 
-void init_iic(void)
+static void init_iic(void)
 {
        DEBUG(1, "init_iic:\n");
 
@@ -214,13 +216,12 @@ void init_iic(void)
 
        /* I2C CLK */
        /* 50MH-100k */
-       if (freq == 75) {
+       if (freq == 75)
                ar_outl(369, PLDI2CFREQ);       /* BCLK = 75MHz */
-       } else if (freq == 50) {
+       else if (freq == 50)
                ar_outl(244, PLDI2CFREQ);       /* BCLK = 50MHz */
-       } else {
+       else
                ar_outl(244, PLDI2CFREQ);       /* default: BCLK = 50MHz */
-       }
        ar_outl(0x1, PLDI2CCR);         /* I2CCR Enable */
 }
 
@@ -245,7 +246,7 @@ static inline void clear_dma_status(void)
        ar_outl(0x8000, M32R_DMAEDET_PORTL);    /* clear status */
 }
 
-static inline void wait_for_vertical_sync(int exp_line)
+static void wait_for_vertical_sync(struct ar *ar, int exp_line)
 {
 #if CHECK_LOST
        int tmout = 10000;      /* FIXME */
@@ -260,7 +261,7 @@ static inline void wait_for_vertical_sync(int exp_line)
                        break;
        }
        if (tmout < 0)
-               printk("arv: lost %d -> %d\n", exp_line, l);
+               v4l2_err(&ar->v4l2_dev, "lost %d -> %d\n", exp_line, l);
 #else
        while (ar_inl(ARVHCOUNT) != exp_line)
                cpu_relax();
@@ -269,15 +270,14 @@ static inline void wait_for_vertical_sync(int exp_line)
 
 static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
 {
-       struct video_device *v = video_devdata(file);
-       struct ar_device *ar = video_get_drvdata(v);
+       struct ar *ar = video_drvdata(file);
        long ret = ar->frame_bytes;             /* return read bytes */
        unsigned long arvcr1 = 0;
        unsigned long flags;
        unsigned char *p;
        int h, w;
        unsigned char *py, *pu, *pv;
-#if ! USE_INT
+#if !USE_INT
        int l;
 #endif
 
@@ -305,7 +305,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
        ar_outl(ar->line_bytes, M32R_DMA0RBCUT_PORTL);  /* reload count (bytes) */
 
        /*
-        * Okey , kicks AR LSI to invoke an interrupt
+        * Okay, kick AR LSI to invoke an interrupt
         */
        ar->start_capture = 0;
        ar_outl(arvcr1 | ARVCR1_HIEN, ARVCR1);
@@ -313,7 +313,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
        /* .... AR interrupts .... */
        interruptible_sleep_on(&ar->wait);
        if (signal_pending(current)) {
-               printk("arv: interrupted while get frame data.\n");
+               printk(KERN_ERR "arv: interrupted while get frame data.\n");
                ret = -EINTR;
                goto out_up;
        }
@@ -334,7 +334,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
                cpu_relax();
        if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) {
                for (h = 0; h < ar->height; h++) {
-                       wait_for_vertical_sync(h);
+                       wait_for_vertical_sync(ar, h);
                        if (h < (AR_HEIGHT_VGA/2))
                                l = h << 1;
                        else
@@ -349,7 +349,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
                }
        } else {
                for (h = 0; h < ar->height; h++) {
-                       wait_for_vertical_sync(h);
+                       wait_for_vertical_sync(ar, h);
                        ar_outl(virt_to_phys(ar->frame[h]), M32R_DMA0CDA_PORTL);
                        enable_dma();
                        while (!(ar_inl(M32R_DMAEDET_PORTL) & 0x8000))
@@ -386,7 +386,7 @@ static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
                }
        }
        if (copy_to_user(buf, yuv, ar->frame_bytes)) {
-               printk("arv: failed while copy_to_user yuv.\n");
+               v4l2_err(&ar->v4l2_dev, "failed while copy_to_user yuv.\n");
                ret = -EFAULT;
                goto out_up;
        }
@@ -396,153 +396,127 @@ out_up:
        return ret;
 }
 
-static long ar_do_ioctl(struct file *file, unsigned int cmd, void *arg)
+static int ar_querycap(struct file *file, void  *priv,
+                                       struct v4l2_capability *vcap)
 {
-       struct video_device *dev = video_devdata(file);
-       struct ar_device *ar = video_get_drvdata(dev);
-
-       DEBUG(1, "ar_ioctl()\n");
-       switch(cmd) {
-       case VIDIOCGCAP:
-       {
-               struct video_capability *b = arg;
-               DEBUG(1, "VIDIOCGCAP:\n");
-               strcpy(b->name, ar->vdev->name);
-               b->type = VID_TYPE_CAPTURE;
-               b->channels = 0;
-               b->audios = 0;
-               b->maxwidth = MAX_AR_WIDTH;
-               b->maxheight = MAX_AR_HEIGHT;
-               b->minwidth = MIN_AR_WIDTH;
-               b->minheight = MIN_AR_HEIGHT;
-               return 0;
-       }
-       case VIDIOCGCHAN:
-               DEBUG(1, "VIDIOCGCHAN:\n");
-               return 0;
-       case VIDIOCSCHAN:
-               DEBUG(1, "VIDIOCSCHAN:\n");
-               return 0;
-       case VIDIOCGTUNER:
-               DEBUG(1, "VIDIOCGTUNER:\n");
-               return 0;
-       case VIDIOCSTUNER:
-               DEBUG(1, "VIDIOCSTUNER:\n");
-               return 0;
-       case VIDIOCGPICT:
-               DEBUG(1, "VIDIOCGPICT:\n");
-               return 0;
-       case VIDIOCSPICT:
-               DEBUG(1, "VIDIOCSPICT:\n");
-               return 0;
-       case VIDIOCCAPTURE:
-               DEBUG(1, "VIDIOCCAPTURE:\n");
+       struct ar *ar = video_drvdata(file);
+
+       strlcpy(vcap->driver, ar->vdev.name, sizeof(vcap->driver));
+       strlcpy(vcap->card, "Colour AR VGA", sizeof(vcap->card));
+       strlcpy(vcap->bus_info, "Platform", sizeof(vcap->bus_info));
+       vcap->version = KERNEL_VERSION(0, 0, 4);
+       vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
+       return 0;
+}
+
+static int ar_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
+{
+       if (vin->index > 0)
                return -EINVAL;
-       case VIDIOCGWIN:
-       {
-               struct video_window *w = arg;
-               DEBUG(1, "VIDIOCGWIN:\n");
-               memset(w, 0, sizeof(*w));
-               w->width = ar->width;
-               w->height = ar->height;
-               return 0;
+       strlcpy(vin->name, "Camera", sizeof(vin->name));
+       vin->type = V4L2_INPUT_TYPE_CAMERA;
+       vin->audioset = 0;
+       vin->tuner = 0;
+       vin->std = V4L2_STD_ALL;
+       vin->status = 0;
+       return 0;
+}
+
+static int ar_g_input(struct file *file, void *fh, unsigned int *inp)
+{
+       *inp = 0;
+       return 0;
+}
+
+static int ar_s_input(struct file *file, void *fh, unsigned int inp)
+{
+       return inp ? -EINVAL : 0;
+}
+
+static int ar_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+       struct ar *ar = video_drvdata(file);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+
+       pix->width = ar->width;
+       pix->height = ar->height;
+       pix->pixelformat = V4L2_PIX_FMT_YUV422P;
+       pix->field = (ar->mode == AR_MODE_NORMAL) ? V4L2_FIELD_NONE : V4L2_FIELD_INTERLACED;
+       pix->bytesperline = ar->width;
+       pix->sizeimage = 2 * ar->width * ar->height;
+       /* Just a guess */
+       pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
+       return 0;
+}
+
+static int ar_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+       struct ar *ar = video_drvdata(file);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+
+       if (pix->height <= AR_HEIGHT_QVGA || pix->width <= AR_WIDTH_QVGA) {
+               pix->height = AR_HEIGHT_QVGA;
+               pix->width = AR_WIDTH_QVGA;
+               pix->field = V4L2_FIELD_INTERLACED;
+       } else {
+               pix->height = AR_HEIGHT_VGA;
+               pix->width = AR_WIDTH_VGA;
+               pix->field = vga_interlace ? V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE;
        }
-       case VIDIOCSWIN:
-       {
-               struct video_window *w = arg;
-               DEBUG(1, "VIDIOCSWIN:\n");
-               if ((w->width != AR_WIDTH_VGA || w->height != AR_HEIGHT_VGA) &&
-                   (w->width != AR_WIDTH_QVGA || w->height != AR_HEIGHT_QVGA))
-                               return -EINVAL;
-
-               mutex_lock(&ar->lock);
-               ar->width = w->width;
-               ar->height = w->height;
-               if (ar->width == AR_WIDTH_VGA) {
-                       ar->size = AR_SIZE_VGA;
-                       ar->frame_bytes = AR_FRAME_BYTES_VGA;
-                       ar->line_bytes = AR_LINE_BYTES_VGA;
-                       if (vga_interlace)
-                               ar->mode = AR_MODE_INTERLACE;
-                       else
-                               ar->mode = AR_MODE_NORMAL;
-               } else {
-                       ar->size = AR_SIZE_QVGA;
-                       ar->frame_bytes = AR_FRAME_BYTES_QVGA;
-                       ar->line_bytes = AR_LINE_BYTES_QVGA;
+       pix->pixelformat = V4L2_PIX_FMT_YUV422P;
+       pix->bytesperline = ar->width;
+       pix->sizeimage = 2 * ar->width * ar->height;
+       /* Just a guess */
+       pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
+       return 0;
+}
+
+static int ar_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+       struct ar *ar = video_drvdata(file);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+       int ret = ar_try_fmt_vid_cap(file, fh, fmt);
+
+       if (ret)
+               return ret;
+       mutex_lock(&ar->lock);
+       ar->width = pix->width;
+       ar->height = pix->height;
+       if (ar->width == AR_WIDTH_VGA) {
+               ar->size = AR_SIZE_VGA;
+               ar->frame_bytes = AR_FRAME_BYTES_VGA;
+               ar->line_bytes = AR_LINE_BYTES_VGA;
+               if (vga_interlace)
                        ar->mode = AR_MODE_INTERLACE;
-               }
-               mutex_unlock(&ar->lock);
-               return 0;
-       }
-       case VIDIOCGFBUF:
-               DEBUG(1, "VIDIOCGFBUF:\n");
-               return -EINVAL;
-       case VIDIOCSFBUF:
-               DEBUG(1, "VIDIOCSFBUF:\n");
-               return -EINVAL;
-       case VIDIOCKEY:
-               DEBUG(1, "VIDIOCKEY:\n");
-               return 0;
-       case VIDIOCGFREQ:
-               DEBUG(1, "VIDIOCGFREQ:\n");
-               return -EINVAL;
-       case VIDIOCSFREQ:
-               DEBUG(1, "VIDIOCSFREQ:\n");
-               return -EINVAL;
-       case VIDIOCGAUDIO:
-               DEBUG(1, "VIDIOCGAUDIO:\n");
-               return -EINVAL;
-       case VIDIOCSAUDIO:
-               DEBUG(1, "VIDIOCSAUDIO:\n");
-               return -EINVAL;
-       case VIDIOCSYNC:
-               DEBUG(1, "VIDIOCSYNC:\n");
-               return -EINVAL;
-       case VIDIOCMCAPTURE:
-               DEBUG(1, "VIDIOCMCAPTURE:\n");
-               return -EINVAL;
-       case VIDIOCGMBUF:
-               DEBUG(1, "VIDIOCGMBUF:\n");
-               return -EINVAL;
-       case VIDIOCGUNIT:
-               DEBUG(1, "VIDIOCGUNIT:\n");
-               return -EINVAL;
-       case VIDIOCGCAPTURE:
-               DEBUG(1, "VIDIOCGCAPTURE:\n");
-               return -EINVAL;
-       case VIDIOCSCAPTURE:
-               DEBUG(1, "VIDIOCSCAPTURE:\n");
-               return -EINVAL;
-       case VIDIOCSPLAYMODE:
-               DEBUG(1, "VIDIOCSPLAYMODE:\n");
-               return -EINVAL;
-       case VIDIOCSWRITEMODE:
-               DEBUG(1, "VIDIOCSWRITEMODE:\n");
-               return -EINVAL;
-       case VIDIOCGPLAYINFO:
-               DEBUG(1, "VIDIOCGPLAYINFO:\n");
-               return -EINVAL;
-       case VIDIOCSMICROCODE:
-               DEBUG(1, "VIDIOCSMICROCODE:\n");
-               return -EINVAL;
-       case VIDIOCGVBIFMT:
-               DEBUG(1, "VIDIOCGVBIFMT:\n");
-               return -EINVAL;
-       case VIDIOCSVBIFMT:
-               DEBUG(1, "VIDIOCSVBIFMT:\n");
-               return -EINVAL;
-       default:
-               DEBUG(1, "Unknown ioctl(0x%08x)\n", cmd);
-               return -ENOIOCTLCMD;
+               else
+                       ar->mode = AR_MODE_NORMAL;
+       } else {
+               ar->size = AR_SIZE_QVGA;
+               ar->frame_bytes = AR_FRAME_BYTES_QVGA;
+               ar->line_bytes = AR_LINE_BYTES_QVGA;
+               ar->mode = AR_MODE_INTERLACE;
        }
+       /* Ok we figured out what to use from our wide choice */
+       mutex_unlock(&ar->lock);
        return 0;
 }
 
-static long ar_ioctl(struct file *file, unsigned int cmd,
-                   unsigned long arg)
+static int ar_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
 {
-       return video_usercopy(file, cmd, arg, ar_do_ioctl);
+       static struct v4l2_fmtdesc formats[] = {
+               { 0, 0, 0,
+                 "YUV 4:2:2 Planar", V4L2_PIX_FMT_YUV422P,
+                 { 0, 0, 0, 0 }
+               },
+       };
+       enum v4l2_buf_type type = fmt->type;
+
+       if (fmt->index > 0)
+               return -EINVAL;
+
+       *fmt = formats[fmt->index];
+       fmt->type = type;
+       return 0;
 }
 
 #if USE_INT
@@ -551,7 +525,7 @@ static long ar_ioctl(struct file *file, unsigned int cmd,
  */
 static void ar_interrupt(int irq, void *dev)
 {
-       struct ar_device *ar = dev;
+       struct ar *ar = dev;
        unsigned int line_count;
        unsigned int line_number;
        unsigned int arvcr1;
@@ -559,11 +533,11 @@ static void ar_interrupt(int irq, void *dev)
        line_count = ar_inl(ARVHCOUNT);                 /* line number */
        if (ar->mode == AR_MODE_INTERLACE && ar->size == AR_SIZE_VGA) {
                /* operations for interlace mode */
-               if ( line_count < (AR_HEIGHT_VGA/2) )   /* even line */
+               if (line_count < (AR_HEIGHT_VGA / 2))   /* even line */
                        line_number = (line_count << 1);
                else                                    /* odd line */
                        line_number =
-                       (((line_count - (AR_HEIGHT_VGA/2)) << 1) + 1);
+                       (((line_count - (AR_HEIGHT_VGA / 2)) << 1) + 1);
        } else {
                line_number = line_count;
        }
@@ -623,11 +597,10 @@ static void ar_interrupt(int irq, void *dev)
  *     0 is returned in success.
  *
  */
-static int ar_initialize(struct video_device *dev)
+static int ar_initialize(struct ar *ar)
 {
-       struct ar_device *ar = video_get_drvdata(dev);
        unsigned long cr = 0;
-       int i,found=0;
+       int i, found = 0;
 
        DEBUG(1, "ar_initialize:\n");
 
@@ -666,129 +639,119 @@ static int ar_initialize(struct video_device *dev)
        if (found == 0)
                return -ENODEV;
 
-       printk("arv: Initializing ");
-
-       iic(2,0x78,0x11,0x01,0x00);     /* start */
-       iic(3,0x78,0x12,0x00,0x06);
-       iic(3,0x78,0x12,0x12,0x30);
-       iic(3,0x78,0x12,0x15,0x58);
-       iic(3,0x78,0x12,0x17,0x30);
-       printk(".");
-       iic(3,0x78,0x12,0x1a,0x97);
-       iic(3,0x78,0x12,0x1b,0xff);
-       iic(3,0x78,0x12,0x1c,0xff);
-       iic(3,0x78,0x12,0x26,0x10);
-       iic(3,0x78,0x12,0x27,0x00);
-       printk(".");
-       iic(2,0x78,0x34,0x02,0x00);
-       iic(2,0x78,0x7a,0x10,0x00);
-       iic(2,0x78,0x80,0x39,0x00);
-       iic(2,0x78,0x81,0xe6,0x00);
-       iic(2,0x78,0x8d,0x00,0x00);
-       printk(".");
-       iic(2,0x78,0x8e,0x0c,0x00);
-       iic(2,0x78,0x8f,0x00,0x00);
+       v4l2_info(&ar->v4l2_dev, "Initializing ");
+
+       iic(2, 0x78, 0x11, 0x01, 0x00); /* start */
+       iic(3, 0x78, 0x12, 0x00, 0x06);
+       iic(3, 0x78, 0x12, 0x12, 0x30);
+       iic(3, 0x78, 0x12, 0x15, 0x58);
+       iic(3, 0x78, 0x12, 0x17, 0x30);
+       printk(KERN_CONT ".");
+       iic(3, 0x78, 0x12, 0x1a, 0x97);
+       iic(3, 0x78, 0x12, 0x1b, 0xff);
+       iic(3, 0x78, 0x12, 0x1c, 0xff);
+       iic(3, 0x78, 0x12, 0x26, 0x10);
+       iic(3, 0x78, 0x12, 0x27, 0x00);
+       printk(KERN_CONT ".");
+       iic(2, 0x78, 0x34, 0x02, 0x00);
+       iic(2, 0x78, 0x7a, 0x10, 0x00);
+       iic(2, 0x78, 0x80, 0x39, 0x00);
+       iic(2, 0x78, 0x81, 0xe6, 0x00);
+       iic(2, 0x78, 0x8d, 0x00, 0x00);
+       printk(KERN_CONT ".");
+       iic(2, 0x78, 0x8e, 0x0c, 0x00);
+       iic(2, 0x78, 0x8f, 0x00, 0x00);
 #if 0
-       iic(2,0x78,0x90,0x00,0x00);     /* AWB on=1 off=0 */
+       iic(2, 0x78, 0x90, 0x00, 0x00); /* AWB on=1 off=0 */
 #endif
-       iic(2,0x78,0x93,0x01,0x00);
-       iic(2,0x78,0x94,0xcd,0x00);
-       iic(2,0x78,0x95,0x00,0x00);
-       printk(".");
-       iic(2,0x78,0x96,0xa0,0x00);
-       iic(2,0x78,0x97,0x00,0x00);
-       iic(2,0x78,0x98,0x60,0x00);
-       iic(2,0x78,0x99,0x01,0x00);
-       iic(2,0x78,0x9a,0x19,0x00);
-       printk(".");
-       iic(2,0x78,0x9b,0x02,0x00);
-       iic(2,0x78,0x9c,0xe8,0x00);
-       iic(2,0x78,0x9d,0x02,0x00);
-       iic(2,0x78,0x9e,0x2e,0x00);
-       iic(2,0x78,0xb8,0x78,0x00);
-       iic(2,0x78,0xba,0x05,0x00);
+       iic(2, 0x78, 0x93, 0x01, 0x00);
+       iic(2, 0x78, 0x94, 0xcd, 0x00);
+       iic(2, 0x78, 0x95, 0x00, 0x00);
+       printk(KERN_CONT ".");
+       iic(2, 0x78, 0x96, 0xa0, 0x00);
+       iic(2, 0x78, 0x97, 0x00, 0x00);
+       iic(2, 0x78, 0x98, 0x60, 0x00);
+       iic(2, 0x78, 0x99, 0x01, 0x00);
+       iic(2, 0x78, 0x9a, 0x19, 0x00);
+       printk(KERN_CONT ".");
+       iic(2, 0x78, 0x9b, 0x02, 0x00);
+       iic(2, 0x78, 0x9c, 0xe8, 0x00);
+       iic(2, 0x78, 0x9d, 0x02, 0x00);
+       iic(2, 0x78, 0x9e, 0x2e, 0x00);
+       iic(2, 0x78, 0xb8, 0x78, 0x00);
+       iic(2, 0x78, 0xba, 0x05, 0x00);
 #if 0
-       iic(2,0x78,0x83,0x8c,0x00);     /* brightness */
+       iic(2, 0x78, 0x83, 0x8c, 0x00); /* brightness */
 #endif
-       printk(".");
+       printk(KERN_CONT ".");
 
        /* color correction */
-       iic(3,0x78,0x49,0x00,0x95);     /* a            */
-       iic(3,0x78,0x49,0x01,0x96);     /* b            */
-       iic(3,0x78,0x49,0x03,0x85);     /* c            */
-       iic(3,0x78,0x49,0x04,0x97);     /* d            */
-       iic(3,0x78,0x49,0x02,0x7e);     /* e(Lo)        */
-       iic(3,0x78,0x49,0x05,0xa4);     /* f(Lo)        */
-       iic(3,0x78,0x49,0x06,0x04);     /* e(Hi)        */
-       iic(3,0x78,0x49,0x07,0x04);     /* e(Hi)        */
-       iic(2,0x78,0x48,0x01,0x00);     /* on=1 off=0   */
-
-       printk(".");
-       iic(2,0x78,0x11,0x00,0x00);     /* end */
-       printk(" done\n");
+       iic(3, 0x78, 0x49, 0x00, 0x95); /* a            */
+       iic(3, 0x78, 0x49, 0x01, 0x96); /* b            */
+       iic(3, 0x78, 0x49, 0x03, 0x85); /* c            */
+       iic(3, 0x78, 0x49, 0x04, 0x97); /* d            */
+       iic(3, 0x78, 0x49, 0x02, 0x7e); /* e(Lo)        */
+       iic(3, 0x78, 0x49, 0x05, 0xa4); /* f(Lo)        */
+       iic(3, 0x78, 0x49, 0x06, 0x04); /* e(Hi)        */
+       iic(3, 0x78, 0x49, 0x07, 0x04); /* e(Hi)        */
+       iic(2, 0x78, 0x48, 0x01, 0x00); /* on=1 off=0   */
+
+       printk(KERN_CONT ".");
+       iic(2, 0x78, 0x11, 0x00, 0x00); /* end */
+       printk(KERN_CONT " done\n");
        return 0;
 }
 
 
-void ar_release(struct video_device *vfd)
-{
-       struct ar_device *ar = video_get_drvdata(vfd);
-       mutex_lock(&ar->lock);
-       video_device_release(vfd);
-}
-
 /****************************************************************************
  *
  * Video4Linux Module functions
  *
  ****************************************************************************/
-static struct ar_device ardev;
-
-static int ar_exclusive_open(struct file *file)
-{
-       return test_and_set_bit(0, &ardev.in_use) ? -EBUSY : 0;
-}
-
-static int ar_exclusive_release(struct file *file)
-{
-       clear_bit(0, &ardev.in_use);
-       return 0;
-}
 
 static const struct v4l2_file_operations ar_fops = {
        .owner          = THIS_MODULE,
-       .open           = ar_exclusive_open,
-       .release        = ar_exclusive_release,
        .read           = ar_read,
-       .ioctl          = ar_ioctl,
+       .ioctl          = video_ioctl2,
 };
 
-static struct video_device ar_template = {
-       .name           = "Colour AR VGA",
-       .fops           = &ar_fops,
-       .release        = ar_release,
+static const struct v4l2_ioctl_ops ar_ioctl_ops = {
+       .vidioc_querycap                    = ar_querycap,
+       .vidioc_g_input                     = ar_g_input,
+       .vidioc_s_input                     = ar_s_input,
+       .vidioc_enum_input                  = ar_enum_input,
+       .vidioc_enum_fmt_vid_cap            = ar_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap               = ar_g_fmt_vid_cap,
+       .vidioc_s_fmt_vid_cap               = ar_s_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap             = ar_try_fmt_vid_cap,
 };
 
 #define ALIGN4(x)      ((((int)(x)) & 0x3) == 0)
 
 static int __init ar_init(void)
 {
-       struct ar_device *ar;
+       struct ar *ar;
+       struct v4l2_device *v4l2_dev;
        int ret;
        int i;
 
-       DEBUG(1, "ar_init:\n");
-       ret = -EIO;
-       printk(KERN_INFO "arv: Colour AR VGA driver %s\n", VERSION);
-
        ar = &ardev;
-       memset(ar, 0, sizeof(struct ar_device));
+       v4l2_dev = &ar->v4l2_dev;
+       strlcpy(v4l2_dev->name, "arv", sizeof(v4l2_dev->name));
+       v4l2_info(v4l2_dev, "Colour AR VGA driver %s\n", VERSION);
+
+       ret = v4l2_device_register(NULL, v4l2_dev);
+       if (ret < 0) {
+               v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
+               return ret;
+       }
+       ret = -EIO;
 
 #if USE_INT
        /* allocate a DMA buffer for 1 line.  */
        ar->line_buff = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL | GFP_DMA);
-       if (ar->line_buff == NULL || ! ALIGN4(ar->line_buff)) {
-               printk("arv: buffer allocation failed for DMA.\n");
+       if (ar->line_buff == NULL || !ALIGN4(ar->line_buff)) {
+               v4l2_err(v4l2_dev, "buffer allocation failed for DMA.\n");
                ret = -ENOMEM;
                goto out_end;
        }
@@ -796,20 +759,19 @@ static int __init ar_init(void)
        /* allocate buffers for a frame */
        for (i = 0; i < MAX_AR_HEIGHT; i++) {
                ar->frame[i] = kmalloc(MAX_AR_LINE_BYTES, GFP_KERNEL);
-               if (ar->frame[i] == NULL || ! ALIGN4(ar->frame[i])) {
-                       printk("arv: buffer allocation failed for frame.\n");
+               if (ar->frame[i] == NULL || !ALIGN4(ar->frame[i])) {
+                       v4l2_err(v4l2_dev, "buffer allocation failed for frame.\n");
                        ret = -ENOMEM;
                        goto out_line_buff;
                }
        }
 
-       ar->vdev = video_device_alloc();
-       if (!ar->vdev) {
-               printk(KERN_ERR "arv: video_device_alloc() failed\n");
-               return -ENOMEM;
-       }
-       memcpy(ar->vdev, &ar_template, sizeof(ar_template));
-       video_set_drvdata(ar->vdev, ar);
+       strlcpy(ar->vdev.name, "Colour AR VGA", sizeof(ar->vdev.name));
+       ar->vdev.v4l2_dev = v4l2_dev;
+       ar->vdev.fops = &ar_fops;
+       ar->vdev.ioctl_ops = &ar_ioctl_ops;
+       ar->vdev.release = video_device_release_empty;
+       video_set_drvdata(&ar->vdev, ar);
 
        if (vga) {
                ar->width       = AR_WIDTH_VGA;
@@ -834,14 +796,14 @@ static int __init ar_init(void)
 
 #if USE_INT
        if (request_irq(M32R_IRQ_INT3, ar_interrupt, 0, "arv", ar)) {
-               printk("arv: request_irq(%d) failed.\n", M32R_IRQ_INT3);
+               v4l2_err("request_irq(%d) failed.\n", M32R_IRQ_INT3);
                ret = -EIO;
                goto out_irq;
        }
 #endif
 
-       if (ar_initialize(ar->vdev) != 0) {
-               printk("arv: M64278 not found.\n");
+       if (ar_initialize(ar) != 0) {
+               v4l2_err(v4l2_dev, "M64278 not found.\n");
                ret = -ENODEV;
                goto out_dev;
        }
@@ -852,15 +814,15 @@ static int __init ar_init(void)
         * device is named "video[0-64]".
         * video_register_device() initializes h/w using ar_initialize().
         */
-       if (video_register_device(ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) {
+       if (video_register_device(&ar->vdev, VFL_TYPE_GRABBER, video_nr) != 0) {
                /* return -1, -ENFILE(full) or others */
-               printk("arv: register video (Colour AR) failed.\n");
+               v4l2_err(v4l2_dev, "register video (Colour AR) failed.\n");
                ret = -ENODEV;
                goto out_dev;
        }
 
-       printk("%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
-               video_device_node_name(ar->vdev), M32R_IRQ_INT3, freq);
+       v4l2_info(v4l2_dev, "%s: Found M64278 VGA (IRQ %d, Freq %dMHz).\n",
+               video_device_node_name(&ar->vdev), M32R_IRQ_INT3, freq);
 
        return 0;
 
@@ -879,6 +841,7 @@ out_line_buff:
 
 out_end:
 #endif
+       v4l2_device_unregister(&ar->v4l2_dev);
        return ret;
 }
 
@@ -886,7 +849,7 @@ out_end:
 static int __init ar_init_module(void)
 {
        freq = (boot_cpu_data.bus_clock / 1000000);
-       printk("arv: Bus clock %d\n", freq);
+       printk(KERN_INFO "arv: Bus clock %d\n", freq);
        if (freq != 50 && freq != 75)
                freq = DEFAULT_FREQ;
        return ar_init();
@@ -894,11 +857,11 @@ static int __init ar_init_module(void)
 
 static void __exit ar_cleanup_module(void)
 {
-       struct ar_device *ar;
+       struct ar *ar;
        int i;
 
        ar = &ardev;
-       video_unregister_device(ar->vdev);
+       video_unregister_device(&ar->vdev);
 #if USE_INT
        free_irq(M32R_IRQ_INT3, ar);
 #endif
@@ -907,6 +870,7 @@ static void __exit ar_cleanup_module(void)
 #if USE_INT
        kfree(ar->line_buff);
 #endif
+       v4l2_device_unregister(&ar->v4l2_dev);
 }
 
 module_init(ar_init_module);
index 8c140c0..6615021 100644 (file)
@@ -1105,7 +1105,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
 
        tmp = input->index;
 
-       if (tmp > AU0828_MAX_INPUT)
+       if (tmp >= AU0828_MAX_INPUT)
                return -EINVAL;
        if (AUVI_INPUT(tmp).type == 0)
                return -EINVAL;
index 716870a..7af56cd 100644 (file)
@@ -241,6 +241,10 @@ static struct CARD {
        { 0xa1550101, BTTV_BOARD_IVC200,        "IVC-200G" },
        { 0xa1550102, BTTV_BOARD_IVC200,        "IVC-200G" },
        { 0xa1550103, BTTV_BOARD_IVC200,        "IVC-200G" },
+       { 0xa1550800, BTTV_BOARD_IVC200,        "IVC-200"  },
+       { 0xa1550801, BTTV_BOARD_IVC200,        "IVC-200"  },
+       { 0xa1550802, BTTV_BOARD_IVC200,        "IVC-200"  },
+       { 0xa1550803, BTTV_BOARD_IVC200,        "IVC-200"  },
        { 0xa182ff00, BTTV_BOARD_IVC120,        "IVC-120G" },
        { 0xa182ff01, BTTV_BOARD_IVC120,        "IVC-120G" },
        { 0xa182ff02, BTTV_BOARD_IVC120,        "IVC-120G" },
index f4860f0..38c7f78 100644 (file)
@@ -1525,7 +1525,7 @@ static int bttv_s_ctrl(struct file *file, void *f,
        struct bttv_fh *fh = f;
        struct bttv *btv = fh->btv;
 
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
+       err = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -1806,8 +1806,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
        *size = fh->fmt->depth*fh->width*fh->height >> 3;
        if (0 == *count)
                *count = gbuffers;
-       while (*size * *count > gbuffers * gbufsize)
-               (*count)--;
+       if (*size * *count > gbuffers * gbufsize)
+               *count = (gbuffers * gbufsize) / *size;
        return 0;
 }
 
@@ -1859,7 +1859,7 @@ static int bttv_s_std(struct file *file, void *priv, v4l2_std_id *id)
        unsigned int i;
        int err;
 
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
+       err = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -1941,7 +1941,7 @@ static int bttv_s_input(struct file *file, void *priv, unsigned int i)
 
        int err;
 
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
+       err = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -1961,7 +1961,7 @@ static int bttv_s_tuner(struct file *file, void *priv,
        struct bttv *btv = fh->btv;
        int err;
 
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
+       err = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -1987,11 +1987,6 @@ static int bttv_g_frequency(struct file *file, void *priv,
 {
        struct bttv_fh *fh  = priv;
        struct bttv *btv = fh->btv;
-       int err;
-
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
-       if (0 != err)
-               return err;
 
        f->type = btv->radio_user ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV;
        f->frequency = btv->freq;
@@ -2006,7 +2001,7 @@ static int bttv_s_frequency(struct file *file, void *priv,
        struct bttv *btv = fh->btv;
        int err;
 
-       err = v4l2_prio_check(&btv->prio, &fh->prio);
+       err = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -3029,7 +3024,7 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
            crop->type != V4L2_BUF_TYPE_VIDEO_OVERLAY)
                return -EINVAL;
 
-       retval = v4l2_prio_check(&btv->prio, &fh->prio);
+       retval = v4l2_prio_check(&btv->prio, fh->prio);
        if (0 != retval)
                return retval;
 
@@ -3241,7 +3236,7 @@ static int bttv_open(struct file *file)
        *fh = btv->init;
        fh->type = type;
        fh->ov.setup_ok = 0;
-       v4l2_prio_open(&btv->prio,&fh->prio);
+       v4l2_prio_open(&btv->prio, &fh->prio);
 
        videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
                            &btv->c.pci->dev, &btv->s_lock,
@@ -3312,7 +3307,7 @@ static int bttv_release(struct file *file)
        /* free stuff */
        videobuf_mmap_free(&fh->cap);
        videobuf_mmap_free(&fh->vbi);
-       v4l2_prio_close(&btv->prio,&fh->prio);
+       v4l2_prio_close(&btv->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -3449,7 +3444,7 @@ static int radio_release(struct file *file)
        struct bttv *btv = fh->btv;
        struct rds_command cmd;
 
-       v4l2_prio_close(&btv->prio,&fh->prio);
+       v4l2_prio_close(&btv->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
index aa153a9..f68717a 100644 (file)
@@ -49,6 +49,8 @@ module_param(ir_rc5_key_timeout, int, 0644);
 
 #define DEVNAME "bttv-input"
 
+#define MODULE_NAME "bttv"
+
 /* ---------------------------------------------------------------------- */
 
 static void ir_handle_key(struct bttv *btv)
@@ -246,7 +248,7 @@ static void bttv_ir_stop(struct bttv *btv)
 int bttv_input_init(struct bttv *btv)
 {
        struct card_ir *ir;
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        struct input_dev *input_dev;
        u64 ir_type = IR_TYPE_OTHER;
        int err = -ENOMEM;
@@ -264,7 +266,7 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_AVERMEDIA:
        case BTTV_BOARD_AVPHONE98:
        case BTTV_BOARD_AVERMEDIA98:
-               ir_codes         = &ir_codes_avermedia_table;
+               ir_codes         = RC_MAP_AVERMEDIA;
                ir->mask_keycode = 0xf88000;
                ir->mask_keydown = 0x010000;
                ir->polling      = 50; // ms
@@ -272,14 +274,14 @@ int bttv_input_init(struct bttv *btv)
 
        case BTTV_BOARD_AVDVBT_761:
        case BTTV_BOARD_AVDVBT_771:
-               ir_codes         = &ir_codes_avermedia_dvbt_table;
+               ir_codes         = RC_MAP_AVERMEDIA_DVBT;
                ir->mask_keycode = 0x0f00c0;
                ir->mask_keydown = 0x000020;
                ir->polling      = 50; // ms
                break;
 
        case BTTV_BOARD_PXELVWPLTVPAK:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x003e00;
                ir->mask_keyup   = 0x010000;
                ir->polling      = 50; // ms
@@ -287,24 +289,24 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_PV_M4900:
        case BTTV_BOARD_PV_BT878P_9B:
        case BTTV_BOARD_PV_BT878P_PLUS:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x008000;
                ir->polling      = 50; // ms
                break;
 
        case BTTV_BOARD_WINFAST2000:
-               ir_codes         = &ir_codes_winfast_table;
+               ir_codes         = RC_MAP_WINFAST;
                ir->mask_keycode = 0x1f8;
                break;
        case BTTV_BOARD_MAGICTVIEW061:
        case BTTV_BOARD_MAGICTVIEW063:
-               ir_codes         = &ir_codes_winfast_table;
+               ir_codes         = RC_MAP_WINFAST;
                ir->mask_keycode = 0x0008e000;
                ir->mask_keydown = 0x00200000;
                break;
        case BTTV_BOARD_APAC_VIEWCOMP:
-               ir_codes         = &ir_codes_apac_viewcomp_table;
+               ir_codes         = RC_MAP_APAC_VIEWCOMP;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x008000;
                ir->polling      = 50; // ms
@@ -312,30 +314,30 @@ int bttv_input_init(struct bttv *btv)
        case BTTV_BOARD_ASKEY_CPH03X:
        case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
        case BTTV_BOARD_CONTVFMI:
-               ir_codes         = &ir_codes_pixelview_table;
+               ir_codes         = RC_MAP_PIXELVIEW;
                ir->mask_keycode = 0x001F00;
                ir->mask_keyup   = 0x006000;
                ir->polling      = 50; // ms
                break;
        case BTTV_BOARD_NEBULA_DIGITV:
-               ir_codes = &ir_codes_nebula_table;
+               ir_codes = RC_MAP_NEBULA;
                btv->custom_irq = bttv_rc5_irq;
                ir->rc5_gpio = 1;
                break;
        case BTTV_BOARD_MACHTV_MAGICTV:
-               ir_codes         = &ir_codes_apac_viewcomp_table;
+               ir_codes         = RC_MAP_APAC_VIEWCOMP;
                ir->mask_keycode = 0x001F00;
                ir->mask_keyup   = 0x004000;
                ir->polling      = 50; /* ms */
                break;
        case BTTV_BOARD_KOZUMI_KTV_01C:
-               ir_codes         = &ir_codes_pctv_sedna_table;
+               ir_codes         = RC_MAP_PCTV_SEDNA;
                ir->mask_keycode = 0x001f00;
                ir->mask_keyup   = 0x006000;
                ir->polling      = 50; /* ms */
                break;
        case BTTV_BOARD_ENLTV_FM_2:
-               ir_codes         = &ir_codes_encore_enltv2_table;
+               ir_codes         = RC_MAP_ENCORE_ENLTV2;
                ir->mask_keycode = 0x00fd00;
                ir->mask_keyup   = 0x000080;
                ir->polling      = 1; /* ms */
@@ -390,7 +392,7 @@ int bttv_input_init(struct bttv *btv)
        bttv_ir_start(btv, ir);
 
        /* all done */
-       err = ir_input_register(btv->remote->dev, ir_codes, NULL);
+       err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME);
        if (err)
                goto err_out_stop;
 
index 9e39bc5..3c9e754 100644 (file)
@@ -80,8 +80,8 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 #include "bw-qcam.h"
 
-static unsigned int maxpoll=250;   /* Maximum busy-loop count for qcam I/O */
-static unsigned int yieldlines=4;  /* Yield after this many during capture */
+static unsigned int maxpoll = 250;   /* Maximum busy-loop count for qcam I/O */
+static unsigned int yieldlines = 4;  /* Yield after this many during capture */
 static int video_nr = -1;
 static unsigned int force_init;                /* Whether to probe aggressively */
 
@@ -156,7 +156,7 @@ static int qc_calibrate(struct qcam_device *q)
                mdelay(1);
                schedule();
                count++;
-       } while (value == 0xff && count<2048);
+       } while (value == 0xff && count < 2048);
 
        q->whitebal = value;
        return value;
@@ -170,16 +170,15 @@ static struct qcam_device *qcam_init(struct parport *port)
        struct qcam_device *q;
 
        q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
-       if(q==NULL)
+       if (q == NULL)
                return NULL;
 
        q->pport = port;
        q->pdev = parport_register_device(port, "bw-qcam", NULL, NULL,
-                                         NULL, 0, NULL);
-       if (q->pdev == NULL)
-       {
+                       NULL, 0, NULL);
+       if (q->pdev == NULL) {
                printk(KERN_ERR "bw-qcam: couldn't register for %s.\n",
-                      port->name);
+                               port->name);
                kfree(q);
                return NULL;
        }
@@ -247,12 +246,10 @@ static int qc_readparam(struct qcam_device *q)
 static int qc_waithand(struct qcam_device *q, int val)
 {
        int status;
-       int runs=0;
+       int runs = 0;
 
-       if (val)
-       {
-               while (!((status = read_lpstatus(q)) & 8))
-               {
+       if (val) {
+               while (!((status = read_lpstatus(q)) & 8)) {
                        /* 1000 is enough spins on the I/O for all normal
                           cases, at that point we start to poll slowly
                           until the camera wakes up. However, we are
@@ -260,18 +257,13 @@ static int qc_waithand(struct qcam_device *q, int val)
                           setting it lower is much better for interactive
                           response. */
 
-                       if(runs++>maxpoll)
-                       {
+                       if (runs++ > maxpoll)
                                msleep_interruptible(5);
-                       }
-                       if(runs>(maxpoll+1000)) /* 5 seconds */
+                       if (runs > (maxpoll + 1000)) /* 5 seconds */
                                return -1;
                }
-       }
-       else
-       {
-               while (((status = read_lpstatus(q)) & 8))
-               {
+       } else {
+               while (((status = read_lpstatus(q)) & 8)) {
                        /* 1000 is enough spins on the I/O for all normal
                           cases, at that point we start to poll slowly
                           until the camera wakes up. However, we are
@@ -279,11 +271,9 @@ static int qc_waithand(struct qcam_device *q, int val)
                           setting it lower is much better for interactive
                           response. */
 
-                       if(runs++>maxpoll)
-                       {
+                       if (runs++ > maxpoll)
                                msleep_interruptible(5);
-                       }
-                       if(runs++>(maxpoll+1000)) /* 5 seconds */
+                       if (runs++ > (maxpoll + 1000)) /* 5 seconds */
                                return -1;
                }
        }
@@ -299,10 +289,9 @@ static int qc_waithand(struct qcam_device *q, int val)
 static unsigned int qc_waithand2(struct qcam_device *q, int val)
 {
        unsigned int status;
-       int runs=0;
+       int runs = 0;
 
-       do
-       {
+       do {
                status = read_lpdata(q);
                /* 1000 is enough spins on the I/O for all normal
                   cases, at that point we start to poll slowly
@@ -311,14 +300,11 @@ static unsigned int qc_waithand2(struct qcam_device *q, int val)
                   setting it lower is much better for interactive
                   response. */
 
-               if(runs++>maxpoll)
-               {
+               if (runs++ > maxpoll)
                        msleep_interruptible(5);
-               }
-               if(runs++>(maxpoll+1000)) /* 5 seconds */
+               if (runs++ > (maxpoll + 1000)) /* 5 seconds */
                        return 0;
-       }
-       while ((status & 1) != val);
+       } while ((status & 1) != val);
 
        return status;
 }
@@ -342,8 +328,7 @@ static int qc_detect(struct qcam_device *q)
 
        lastreg = reg = read_lpstatus(q) & 0xf0;
 
-       for (i = 0; i < 500; i++)
-       {
+       for (i = 0; i < 500; i++) {
                reg = read_lpstatus(q) & 0xf0;
                if (reg != lastreg)
                        count++;
@@ -357,7 +342,7 @@ static int qc_detect(struct qcam_device *q)
           won't be flashing these bits. Possibly unloading the module
           in the middle of a grab? Or some timeout condition?
           I've seen this parameter as low as 19 on my 450Mhz box - mpc */
-       printk("Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count);
+       printk(KERN_DEBUG "Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count);
        return 1;
 #endif
 
@@ -367,7 +352,7 @@ static int qc_detect(struct qcam_device *q)
                return 1;       /* found */
        } else {
                printk(KERN_ERR "No Quickcam found on port %s\n",
-                       q->pport->name);
+                               q->pport->name);
                printk(KERN_DEBUG "Quickcam detection counter: %u\n", count);
                return 0;       /* not found */
        }
@@ -381,26 +366,24 @@ static int qc_detect(struct qcam_device *q)
 
 static void qc_reset(struct qcam_device *q)
 {
-       switch (q->port_mode & QC_FORCE_MASK)
-       {
-               case QC_FORCE_UNIDIR:
-                       q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
-                       break;
+       switch (q->port_mode & QC_FORCE_MASK) {
+       case QC_FORCE_UNIDIR:
+               q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
+               break;
 
-               case QC_FORCE_BIDIR:
-                       q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
-                       break;
+       case QC_FORCE_BIDIR:
+               q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
+               break;
 
-               case QC_ANY:
-                       write_lpcontrol(q, 0x20);
-                       write_lpdata(q, 0x75);
+       case QC_ANY:
+               write_lpcontrol(q, 0x20);
+               write_lpdata(q, 0x75);
 
-                       if (read_lpdata(q) != 0x75) {
-                               q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
-                       } else {
-                               q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
-                       }
-                       break;
+               if (read_lpdata(q) != 0x75)
+                       q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
+               else
+                       q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
+               break;
        }
 
        write_lpcontrol(q, 0xb);
@@ -423,36 +406,33 @@ static int qc_setscanmode(struct qcam_device *q)
 {
        int old_mode = q->mode;
 
-       switch (q->transfer_scale)
-       {
-               case 1:
-                       q->mode = 0;
-                       break;
-               case 2:
-                       q->mode = 4;
-                       break;
-               case 4:
-                       q->mode = 8;
-                       break;
+       switch (q->transfer_scale) {
+       case 1:
+               q->mode = 0;
+               break;
+       case 2:
+               q->mode = 4;
+               break;
+       case 4:
+               q->mode = 8;
+               break;
        }
 
-       switch (q->bpp)
-       {
-               case 4:
-                       break;
-               case 6:
-                       q->mode += 2;
-                       break;
+       switch (q->bpp) {
+       case 4:
+               break;
+       case 6:
+               q->mode += 2;
+               break;
        }
 
-       switch (q->port_mode & QC_MODE_MASK)
-       {
-               case QC_BIDIR:
-                       q->mode += 1;
-                       break;
-               case QC_NOTSET:
-               case QC_UNIDIR:
-                       break;
+       switch (q->port_mode & QC_MODE_MASK) {
+       case QC_BIDIR:
+               q->mode += 1;
+               break;
+       case QC_NOTSET:
+       case QC_UNIDIR:
+               break;
        }
 
        if (q->mode != old_mode)
@@ -493,7 +473,7 @@ static void qc_set(struct qcam_device *q)
        } else {
                val = q->width * q->bpp;
                val2 = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
-                   q->transfer_scale;
+                       q->transfer_scale;
        }
        val = DIV_ROUND_UP(val, val2);
        qc_command(q, 0x13);
@@ -521,85 +501,80 @@ static void qc_set(struct qcam_device *q)
 
 static inline int qc_readbytes(struct qcam_device *q, char buffer[])
 {
-       int ret=1;
+       int ret = 1;
        unsigned int hi, lo;
        unsigned int hi2, lo2;
        static int state;
 
-       if (buffer == NULL)
-       {
+       if (buffer == NULL) {
                state = 0;
                return 0;
        }
 
-       switch (q->port_mode & QC_MODE_MASK)
-       {
-               case QC_BIDIR:          /* Bi-directional Port */
-                       write_lpcontrol(q, 0x26);
-                       lo = (qc_waithand2(q, 1) >> 1);
-                       hi = (read_lpstatus(q) >> 3) & 0x1f;
-                       write_lpcontrol(q, 0x2e);
-                       lo2 = (qc_waithand2(q, 0) >> 1);
-                       hi2 = (read_lpstatus(q) >> 3) & 0x1f;
-                       switch (q->bpp)
-                       {
-                               case 4:
-                                       buffer[0] = lo & 0xf;
-                                       buffer[1] = ((lo & 0x70) >> 4) | ((hi & 1) << 3);
-                                       buffer[2] = (hi & 0x1e) >> 1;
-                                       buffer[3] = lo2 & 0xf;
-                                       buffer[4] = ((lo2 & 0x70) >> 4) | ((hi2 & 1) << 3);
-                                       buffer[5] = (hi2 & 0x1e) >> 1;
-                                       ret = 6;
-                                       break;
-                               case 6:
-                                       buffer[0] = lo & 0x3f;
-                                       buffer[1] = ((lo & 0x40) >> 6) | (hi << 1);
-                                       buffer[2] = lo2 & 0x3f;
-                                       buffer[3] = ((lo2 & 0x40) >> 6) | (hi2 << 1);
-                                       ret = 4;
-                                       break;
-                       }
+       switch (q->port_mode & QC_MODE_MASK) {
+       case QC_BIDIR:          /* Bi-directional Port */
+               write_lpcontrol(q, 0x26);
+               lo = (qc_waithand2(q, 1) >> 1);
+               hi = (read_lpstatus(q) >> 3) & 0x1f;
+               write_lpcontrol(q, 0x2e);
+               lo2 = (qc_waithand2(q, 0) >> 1);
+               hi2 = (read_lpstatus(q) >> 3) & 0x1f;
+               switch (q->bpp) {
+               case 4:
+                       buffer[0] = lo & 0xf;
+                       buffer[1] = ((lo & 0x70) >> 4) | ((hi & 1) << 3);
+                       buffer[2] = (hi & 0x1e) >> 1;
+                       buffer[3] = lo2 & 0xf;
+                       buffer[4] = ((lo2 & 0x70) >> 4) | ((hi2 & 1) << 3);
+                       buffer[5] = (hi2 & 0x1e) >> 1;
+                       ret = 6;
+                       break;
+               case 6:
+                       buffer[0] = lo & 0x3f;
+                       buffer[1] = ((lo & 0x40) >> 6) | (hi << 1);
+                       buffer[2] = lo2 & 0x3f;
+                       buffer[3] = ((lo2 & 0x40) >> 6) | (hi2 << 1);
+                       ret = 4;
                        break;
+               }
+               break;
+
+       case QC_UNIDIR: /* Unidirectional Port */
+               write_lpcontrol(q, 6);
+               lo = (qc_waithand(q, 1) & 0xf0) >> 4;
+               write_lpcontrol(q, 0xe);
+               hi = (qc_waithand(q, 0) & 0xf0) >> 4;
 
-               case QC_UNIDIR: /* Unidirectional Port */
-                       write_lpcontrol(q, 6);
-                       lo = (qc_waithand(q, 1) & 0xf0) >> 4;
-                       write_lpcontrol(q, 0xe);
-                       hi = (qc_waithand(q, 0) & 0xf0) >> 4;
-
-                       switch (q->bpp)
-                       {
-                               case 4:
-                                       buffer[0] = lo;
-                                       buffer[1] = hi;
-                                       ret = 2;
-                                       break;
-                               case 6:
-                                       switch (state)
-                                       {
-                                               case 0:
-                                                       buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
-                                                       q->saved_bits = (hi & 3) << 4;
-                                                       state = 1;
-                                                       ret = 1;
-                                                       break;
-                                               case 1:
-                                                       buffer[0] = lo | q->saved_bits;
-                                                       q->saved_bits = hi << 2;
-                                                       state = 2;
-                                                       ret = 1;
-                                                       break;
-                                               case 2:
-                                                       buffer[0] = ((lo & 0xc) >> 2) | q->saved_bits;
-                                                       buffer[1] = ((lo & 3) << 4) | hi;
-                                                       state = 0;
-                                                       ret = 2;
-                                                       break;
-                                       }
-                                       break;
+               switch (q->bpp) {
+               case 4:
+                       buffer[0] = lo;
+                       buffer[1] = hi;
+                       ret = 2;
+                       break;
+               case 6:
+                       switch (state) {
+                       case 0:
+                               buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
+                               q->saved_bits = (hi & 3) << 4;
+                               state = 1;
+                               ret = 1;
+                               break;
+                       case 1:
+                               buffer[0] = lo | q->saved_bits;
+                               q->saved_bits = hi << 2;
+                               state = 2;
+                               ret = 1;
+                               break;
+                       case 2:
+                               buffer[0] = ((lo & 0xc) >> 2) | q->saved_bits;
+                               buffer[1] = ((lo & 3) << 4) | hi;
+                               state = 0;
+                               ret = 2;
+                               break;
                        }
                        break;
+               }
+               break;
        }
        return ret;
 }
@@ -615,7 +590,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
  * n=2^(bit depth)-1.  Ask me for more details if you don't understand
  * this. */
 
-static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long len)
+static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long len)
 {
        int i, j, k, yield;
        int bytes;
@@ -623,9 +598,9 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
        int divisor;
        int pixels_per_line;
        int pixels_read = 0;
-       int got=0;
+       int got = 0;
        char buffer[6];
-       int  shift=8-q->bpp;
+       int  shift = 8 - q->bpp;
        char invert;
 
        if (q->mode == -1)
@@ -634,13 +609,12 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
        qc_command(q, 0x7);
        qc_command(q, q->mode);
 
-       if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
-       {
+       if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
                write_lpcontrol(q, 0x2e);       /* turn port around */
                write_lpcontrol(q, 0x26);
-               (void) qc_waithand(q, 1);
+               qc_waithand(q, 1);
                write_lpcontrol(q, 0x2e);
-               (void) qc_waithand(q, 0);
+               qc_waithand(q, 0);
        }
 
        /* strange -- should be 15:63 below, but 4bpp is odd */
@@ -650,33 +624,28 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
        pixels_per_line = q->width / q->transfer_scale;
        transperline = q->width * q->bpp;
        divisor = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
-           q->transfer_scale;
+               q->transfer_scale;
        transperline = DIV_ROUND_UP(transperline, divisor);
 
-       for (i = 0, yield = yieldlines; i < linestotrans; i++)
-       {
-               for (pixels_read = j = 0; j < transperline; j++)
-               {
+       for (i = 0, yield = yieldlines; i < linestotrans; i++) {
+               for (pixels_read = j = 0; j < transperline; j++) {
                        bytes = qc_readbytes(q, buffer);
-                       for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++)
-                       {
+                       for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++) {
                                int o;
-                               if (buffer[k] == 0 && invert == 16)
-                               {
+                               if (buffer[k] == 0 && invert == 16) {
                                        /* 4bpp is odd (again) -- inverter is 16, not 15, but output
                                           must be 0-15 -- bls */
                                        buffer[k] = 16;
                                }
-                               o=i*pixels_per_line + pixels_read + k;
-                               if(o<len)
-                               {
+                               o = i * pixels_per_line + pixels_read + k;
+                               if (o < len) {
                                        got++;
-                                       put_user((invert - buffer[k])<<shift, buf+o);
+                                       put_user((invert - buffer[k]) << shift, buf + o);
                                }
                        }
                        pixels_read += bytes;
                }
-               (void) qc_readbytes(q, NULL);   /* reset state machine */
+               qc_readbytes(q, NULL);  /* reset state machine */
 
                /* Grabbing an entire frame from the quickcam is a lengthy
                   process. We don't (usually) want to busy-block the
@@ -690,14 +659,13 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
                }
        }
 
-       if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR)
-       {
+       if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
                write_lpcontrol(q, 2);
                write_lpcontrol(q, 6);
                udelay(3);
                write_lpcontrol(q, 0xe);
        }
-       if(got<len)
+       if (got < len)
                return got;
        return len;
 }
@@ -709,11 +677,10 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
 static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 {
        struct video_device *dev = video_devdata(file);
-       struct qcam_device *qcam=(struct qcam_device *)dev;
+       struct qcam_device *qcam = (struct qcam_device *)dev;
 
-       switch(cmd)
-       {
-               case VIDIOCGCAP:
+       switch (cmd) {
+       case VIDIOCGCAP:
                {
                        struct video_capability *b = arg;
                        strcpy(b->name, "Quickcam");
@@ -726,73 +693,73 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                        b->minheight = 60;
                        return 0;
                }
-               case VIDIOCGCHAN:
+       case VIDIOCGCHAN:
                {
                        struct video_channel *v = arg;
-                       if(v->channel!=0)
+                       if (v->channel != 0)
                                return -EINVAL;
-                       v->flags=0;
-                       v->tuners=0;
+                       v->flags = 0;
+                       v->tuners = 0;
                        /* Good question.. its composite or SVHS so.. */
                        v->type = VIDEO_TYPE_CAMERA;
                        strcpy(v->name, "Camera");
                        return 0;
                }
-               case VIDIOCSCHAN:
+       case VIDIOCSCHAN:
                {
                        struct video_channel *v = arg;
-                       if(v->channel!=0)
+                       if (v->channel != 0)
                                return -EINVAL;
                        return 0;
                }
-               case VIDIOCGTUNER:
+       case VIDIOCGTUNER:
                {
                        struct video_tuner *v = arg;
-                       if(v->tuner)
+                       if (v->tuner)
                                return -EINVAL;
                        strcpy(v->name, "Format");
-                       v->rangelow=0;
-                       v->rangehigh=0;
-                       v->flags= 0;
+                       v->rangelow = 0;
+                       v->rangehigh = 0;
+                       v->flags = 0;
                        v->mode = VIDEO_MODE_AUTO;
                        return 0;
                }
-               case VIDIOCSTUNER:
+       case VIDIOCSTUNER:
                {
                        struct video_tuner *v = arg;
-                       if(v->tuner)
+                       if (v->tuner)
                                return -EINVAL;
-                       if(v->mode!=VIDEO_MODE_AUTO)
+                       if (v->mode != VIDEO_MODE_AUTO)
                                return -EINVAL;
                        return 0;
                }
-               case VIDIOCGPICT:
+       case VIDIOCGPICT:
                {
                        struct video_picture *p = arg;
-                       p->colour=0x8000;
-                       p->hue=0x8000;
-                       p->brightness=qcam->brightness<<8;
-                       p->contrast=qcam->contrast<<8;
-                       p->whiteness=qcam->whitebal<<8;
-                       p->depth=qcam->bpp;
-                       p->palette=VIDEO_PALETTE_GREY;
+                       p->colour = 0x8000;
+                       p->hue = 0x8000;
+                       p->brightness = qcam->brightness << 8;
+                       p->contrast = qcam->contrast << 8;
+                       p->whiteness = qcam->whitebal << 8;
+                       p->depth = qcam->bpp;
+                       p->palette = VIDEO_PALETTE_GREY;
                        return 0;
                }
-               case VIDIOCSPICT:
+       case VIDIOCSPICT:
                {
                        struct video_picture *p = arg;
-                       if(p->palette!=VIDEO_PALETTE_GREY)
+                       if (p->palette != VIDEO_PALETTE_GREY)
                                return -EINVAL;
-                       if(p->depth!=4 && p->depth!=6)
+                       if (p->depth != 4 && p->depth != 6)
                                return -EINVAL;
 
                        /*
                         *      Now load the camera.
                         */
 
-                       qcam->brightness = p->brightness>>8;
-                       qcam->contrast = p->contrast>>8;
-                       qcam->whitebal = p->whiteness>>8;
+                       qcam->brightness = p->brightness >> 8;
+                       qcam->contrast = p->contrast >> 8;
+                       qcam->whitebal = p->whiteness >> 8;
                        qcam->bpp = p->depth;
 
                        mutex_lock(&qcam->lock);
@@ -802,28 +769,25 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
                        return 0;
                }
-               case VIDIOCSWIN:
+       case VIDIOCSWIN:
                {
                        struct video_window *vw = arg;
-                       if(vw->flags)
+                       if (vw->flags)
                                return -EINVAL;
-                       if(vw->clipcount)
+                       if (vw->clipcount)
                                return -EINVAL;
-                       if(vw->height<60||vw->height>240)
+                       if (vw->height < 60 || vw->height > 240)
                                return -EINVAL;
-                       if(vw->width<80||vw->width>320)
+                       if (vw->width < 80 || vw->width > 320)
                                return -EINVAL;
 
                        qcam->width = 320;
                        qcam->height = 240;
                        qcam->transfer_scale = 4;
 
-                       if(vw->width>=160 && vw->height>=120)
-                       {
+                       if (vw->width >= 160 && vw->height >= 120)
                                qcam->transfer_scale = 2;
-                       }
-                       if(vw->width>=320 && vw->height>=240)
-                       {
+                       if (vw->width >= 320 && vw->height >= 240) {
                                qcam->width = 320;
                                qcam->height = 240;
                                qcam->transfer_scale = 1;
@@ -839,41 +803,42 @@ static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
                        /* Ok we figured out what to use from our wide choice */
                        return 0;
                }
-               case VIDIOCGWIN:
+       case VIDIOCGWIN:
                {
                        struct video_window *vw = arg;
+
                        memset(vw, 0, sizeof(*vw));
-                       vw->width=qcam->width/qcam->transfer_scale;
-                       vw->height=qcam->height/qcam->transfer_scale;
+                       vw->width = qcam->width / qcam->transfer_scale;
+                       vw->height = qcam->height / qcam->transfer_scale;
                        return 0;
                }
-               case VIDIOCKEY:
-                       return 0;
-               case VIDIOCCAPTURE:
-               case VIDIOCGFBUF:
-               case VIDIOCSFBUF:
-               case VIDIOCGFREQ:
-               case VIDIOCSFREQ:
-               case VIDIOCGAUDIO:
-               case VIDIOCSAUDIO:
-                       return -EINVAL;
-               default:
-                       return -ENOIOCTLCMD;
+       case VIDIOCKEY:
+               return 0;
+       case VIDIOCCAPTURE:
+       case VIDIOCGFBUF:
+       case VIDIOCSFBUF:
+       case VIDIOCGFREQ:
+       case VIDIOCSFREQ:
+       case VIDIOCGAUDIO:
+       case VIDIOCSAUDIO:
+               return -EINVAL;
+       default:
+               return -ENOIOCTLCMD;
        }
        return 0;
 }
 
 static long qcam_ioctl(struct file *file,
-                    unsigned int cmd, unsigned long arg)
+               unsigned int cmd, unsigned long arg)
 {
        return video_usercopy(file, cmd, arg, qcam_do_ioctl);
 }
 
 static ssize_t qcam_read(struct file *file, char __user *buf,
-                        size_t count, loff_t *ppos)
+               size_t count, loff_t *ppos)
 {
        struct video_device *v = video_devdata(file);
-       struct qcam_device *qcam=(struct qcam_device *)v;
+       struct qcam_device *qcam = (struct qcam_device *)v;
        int len;
        parport_claim_or_block(qcam->pdev);
 
@@ -885,7 +850,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
        if (qcam->status & QC_PARAM_CHANGE)
                qc_set(qcam);
 
-       len=qc_capture(qcam, buf,count);
+       len = qc_capture(qcam, buf, count);
 
        mutex_unlock(&qcam->lock);
 
@@ -917,8 +882,7 @@ static const struct v4l2_file_operations qcam_fops = {
        .ioctl          = qcam_ioctl,
        .read           = qcam_read,
 };
-static struct video_device qcam_template=
-{
+static struct video_device qcam_template = {
        .name           = "Connectix Quickcam",
        .fops           = &qcam_fops,
        .release        = video_device_release_empty,
@@ -932,22 +896,20 @@ static int init_bwqcam(struct parport *port)
 {
        struct qcam_device *qcam;
 
-       if (num_cams == MAX_CAMS)
-       {
+       if (num_cams == MAX_CAMS) {
                printk(KERN_ERR "Too many Quickcams (max %d)\n", MAX_CAMS);
                return -ENOSPC;
        }
 
-       qcam=qcam_init(port);
-       if(qcam==NULL)
+       qcam = qcam_init(port);
+       if (qcam == NULL)
                return -ENODEV;
 
        parport_claim_or_block(qcam->pdev);
 
        qc_reset(qcam);
 
-       if(qc_detect(qcam)==0)
-       {
+       if (qc_detect(qcam) == 0) {
                parport_release(qcam->pdev);
                parport_unregister_device(qcam->pdev);
                kfree(qcam);
@@ -1045,12 +1007,12 @@ static int __init init_bw_qcams(void)
 #ifdef MODULE
        /* Do some sanity checks on the module parameters. */
        if (maxpoll > 5000) {
-               printk("Connectix Quickcam max-poll was above 5000. Using 5000.\n");
+               printk(KERN_INFO "Connectix Quickcam max-poll was above 5000. Using 5000.\n");
                maxpoll = 5000;
        }
 
        if (yieldlines < 1) {
-               printk("Connectix Quickcam yieldlines was less than 1. Using 1.\n");
+               printk(KERN_INFO "Connectix Quickcam yieldlines was less than 1. Using 1.\n");
                yieldlines = 1;
        }
 #endif
index e2cbeba..8f1dd88 100644 (file)
@@ -79,17 +79,17 @@ static inline void qcam_set_ack(struct qcam_device *qcam, unsigned int i)
 {
        /* note: the QC specs refer to the PCAck pin by voltage, not
           software level.  PC ports have builtin inverters. */
-       parport_frob_control(qcam->pport, 8, i?8:0);
+       parport_frob_control(qcam->pport, 8, i ? 8 : 0);
 }
 
 static inline unsigned int qcam_ready1(struct qcam_device *qcam)
 {
-       return (parport_read_status(qcam->pport) & 0x8)?1:0;
+       return (parport_read_status(qcam->pport) & 0x8) ? 1 : 0;
 }
 
 static inline unsigned int qcam_ready2(struct qcam_device *qcam)
 {
-       return (parport_read_data(qcam->pport) & 0x1)?1:0;
+       return (parport_read_data(qcam->pport) & 0x1) ? 1 : 0;
 }
 
 static unsigned int qcam_await_ready1(struct qcam_device *qcam,
@@ -99,14 +99,13 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam,
        unsigned int i;
 
        for (oldjiffies = jiffies;
-            time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); )
+            time_before(jiffies, oldjiffies + msecs_to_jiffies(40));)
                if (qcam_ready1(qcam) == value)
                        return 0;
 
        /* If the camera didn't respond within 1/25 second, poll slowly
           for a while. */
-       for (i = 0; i < 50; i++)
-       {
+       for (i = 0; i < 50; i++) {
                if (qcam_ready1(qcam) == value)
                        return 0;
                msleep_interruptible(100);
@@ -125,14 +124,13 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
        unsigned int i;
 
        for (oldjiffies = jiffies;
-            time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); )
+            time_before(jiffies, oldjiffies + msecs_to_jiffies(40));)
                if (qcam_ready2(qcam) == value)
                        return 0;
 
        /* If the camera didn't respond within 1/25 second, poll slowly
           for a while. */
-       for (i = 0; i < 50; i++)
-       {
+       for (i = 0; i < 50; i++) {
                if (qcam_ready2(qcam) == value)
                        return 0;
                msleep_interruptible(100);
@@ -149,22 +147,25 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
 static int qcam_read_data(struct qcam_device *qcam)
 {
        unsigned int idata;
+
        qcam_set_ack(qcam, 0);
-       if (qcam_await_ready1(qcam, 1)) return -1;
+       if (qcam_await_ready1(qcam, 1))
+               return -1;
        idata = parport_read_status(qcam->pport) & 0xf0;
        qcam_set_ack(qcam, 1);
-       if (qcam_await_ready1(qcam, 0)) return -1;
-       idata |= (parport_read_status(qcam->pport) >> 4);
+       if (qcam_await_ready1(qcam, 0))
+               return -1;
+       idata |= parport_read_status(qcam->pport) >> 4;
        return idata;
 }
 
 static int qcam_write_data(struct qcam_device *qcam, unsigned int data)
 {
        unsigned int idata;
+
        parport_write_data(qcam->pport, data);
        idata = qcam_read_data(qcam);
-       if (data != idata)
-       {
+       if (data != idata) {
                printk(KERN_WARNING "cqcam: sent %x but received %x\n", data,
                       idata);
                return 1;
@@ -212,13 +213,12 @@ static int qc_detect(struct qcam_device *qcam)
 
        /* look for a heartbeat */
        ostat = stat = parport_read_status(qcam->pport);
-       for (i=0; i<250; i++)
-       {
+       for (i = 0; i < 250; i++) {
                mdelay(1);
                stat = parport_read_status(qcam->pport);
-               if (ostat != stat)
-               {
-                       if (++count >= 3) return 1;
+               if (ostat != stat) {
+                       if (++count >= 3)
+                               return 1;
                        ostat = stat;
                }
        }
@@ -232,13 +232,12 @@ static int qc_detect(struct qcam_device *qcam)
        count = 0;
 
        ostat = stat = parport_read_status(qcam->pport);
-       for (i=0; i<250; i++)
-       {
+       for (i = 0; i < 250; i++) {
                mdelay(1);
                stat = parport_read_status(qcam->pport);
-               if (ostat != stat)
-               {
-                       if (++count >= 3) return 1;
+               if (ostat != stat) {
+                       if (++count >= 3)
+                               return 1;
                        ostat = stat;
                }
        }
@@ -263,7 +262,7 @@ static void qc_setup(struct qcam_device *q)
 {
        qc_reset(q);
 
-       /* Set the brightness.  */
+       /* Set the brightness. */
        qcam_set(q, 11, q->brightness);
 
        /* Set the height and width.  These refer to the actual
@@ -292,25 +291,25 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u
        unsigned int bytes = 0;
 
        qcam_set_ack(q, 0);
-       if (q->bidirectional)
-       {
+       if (q->bidirectional) {
                /* It's a bidirectional port */
-               while (bytes < nbytes)
-               {
+               while (bytes < nbytes) {
                        unsigned int lo1, hi1, lo2, hi2;
                        unsigned char r, g, b;
 
-                       if (qcam_await_ready2(q, 1)) return bytes;
+                       if (qcam_await_ready2(q, 1))
+                               return bytes;
                        lo1 = parport_read_data(q->pport) >> 1;
                        hi1 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
                        qcam_set_ack(q, 1);
-                       if (qcam_await_ready2(q, 0)) return bytes;
+                       if (qcam_await_ready2(q, 0))
+                               return bytes;
                        lo2 = parport_read_data(q->pport) >> 1;
                        hi2 = ((parport_read_status(q->pport) >> 3) & 0x1f) ^ 0x10;
                        qcam_set_ack(q, 0);
-                       r = (lo1 | ((hi1 & 1)<<7));
-                       g = ((hi1 & 0x1e)<<3) | ((hi2 & 0x1e)>>1);
-                       b = (lo2 | ((hi2 & 1)<<7));
+                       r = lo1 | ((hi1 & 1) << 7);
+                       g = ((hi1 & 0x1e) << 3) | ((hi2 & 0x1e) >> 1);
+                       b = lo2 | ((hi2 & 1) << 7);
                        if (force_rgb) {
                                buf[bytes++] = r;
                                buf[bytes++] = g;
@@ -321,21 +320,20 @@ static unsigned int qcam_read_bytes(struct qcam_device *q, unsigned char *buf, u
                                buf[bytes++] = r;
                        }
                }
-       }
-       else
-       {
+       } else {
                /* It's a unidirectional port */
                int i = 0, n = bytes;
                unsigned char rgb[3];
 
-               while (bytes < nbytes)
-               {
+               while (bytes < nbytes) {
                        unsigned int hi, lo;
 
-                       if (qcam_await_ready1(q, 1)) return bytes;
+                       if (qcam_await_ready1(q, 1))
+                               return bytes;
                        hi = (parport_read_status(q->pport) & 0xf0);
                        qcam_set_ack(q, 1);
-                       if (qcam_await_ready1(q, 0)) return bytes;
+                       if (qcam_await_ready1(q, 0))
+                               return bytes;
                        lo = (parport_read_status(q->pport) & 0xf0);
                        qcam_set_ack(q, 0);
                        /* flip some bits */
@@ -374,28 +372,26 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
                return -EFAULT;
 
        /* Wait for camera to become ready */
-       for (;;)
-       {
+       for (;;) {
                int i = qcam_get(q, 41);
+
                if (i == -1) {
                        qc_setup(q);
                        return -EIO;
                }
                if ((i & 0x80) == 0)
                        break;
-               else
-                       schedule();
+               schedule();
        }
 
-       if (qcam_set(q, 7, (q->mode | (is_bi_dir?1:0)) + 1))
+       if (qcam_set(q, 7, (q->mode | (is_bi_dir ? 1 : 0)) + 1))
                return -EIO;
 
        lines = q->height;
        pixelsperline = q->width;
        bitsperxfer = (is_bi_dir) ? 24 : 8;
 
-       if (is_bi_dir)
-       {
+       if (is_bi_dir) {
                /* Turn the port around */
                parport_data_reverse(q->pport);
                mdelay(3);
@@ -413,16 +409,17 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
 
        wantlen = lines * pixelsperline * 24 / 8;
 
-       while (wantlen)
-       {
+       while (wantlen) {
                size_t t, s;
-               s = (wantlen > BUFSZ)?BUFSZ:wantlen;
+
+               s = (wantlen > BUFSZ) ? BUFSZ : wantlen;
                t = qcam_read_bytes(q, tmpbuf, s);
-               if (outptr < len)
-               {
+               if (outptr < len) {
                        size_t sz = len - outptr;
-                       if (sz > t) sz = t;
-                       if (__copy_to_user(buf+outptr, tmpbuf, sz))
+
+                       if (sz > t)
+                               sz = t;
+                       if (__copy_to_user(buf + outptr, tmpbuf, sz))
                                break;
                        outptr += sz;
                }
@@ -434,33 +431,31 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
 
        len = outptr;
 
-       if (wantlen)
-       {
-               printk("qcam: short read.\n");
+       if (wantlen) {
+               printk(KERN_ERR "qcam: short read.\n");
                if (is_bi_dir)
                        parport_data_forward(q->pport);
                qc_setup(q);
                return len;
        }
 
-       if (is_bi_dir)
-       {
+       if (is_bi_dir) {
                int l;
+
                do {
                        l = qcam_read_bytes(q, tmpbuf, 3);
                        cond_resched();
                } while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e));
                if (force_rgb) {
                        if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
-                               printk("qcam: bad EOF\n");
+                               printk(KERN_ERR "qcam: bad EOF\n");
                } else {
                        if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
-                               printk("qcam: bad EOF\n");
+                               printk(KERN_ERR "qcam: bad EOF\n");
                }
                qcam_set_ack(q, 0);
-               if (qcam_await_ready1(q, 1))
-               {
-                       printk("qcam: no ack after EOF\n");
+               if (qcam_await_ready1(q, 1)) {
+                       printk(KERN_ERR "qcam: no ack after EOF\n");
                        parport_data_forward(q->pport);
                        qc_setup(q);
                        return len;
@@ -468,27 +463,25 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
                parport_data_forward(q->pport);
                mdelay(3);
                qcam_set_ack(q, 1);
-               if (qcam_await_ready1(q, 0))
-               {
-                       printk("qcam: no ack to port turnaround\n");
+               if (qcam_await_ready1(q, 0)) {
+                       printk(KERN_ERR "qcam: no ack to port turnaround\n");
                        qc_setup(q);
                        return len;
                }
-       }
-       else
-       {
+       } else {
                int l;
+
                do {
                        l = qcam_read_bytes(q, tmpbuf, 1);
                        cond_resched();
                } while (l && tmpbuf[0] == 0x7e);
-               l = qcam_read_bytes(q, tmpbuf+1, 2);
+               l = qcam_read_bytes(q, tmpbuf + 1, 2);
                if (force_rgb) {
                        if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
-                               printk("qcam: bad EOF\n");
+                               printk(KERN_ERR "qcam: bad EOF\n");
                } else {
                        if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
-                               printk("qcam: bad EOF\n");
+                               printk(KERN_ERR "qcam: bad EOF\n");
                }
        }
 
@@ -503,164 +496,166 @@ static long qc_capture(struct qcam_device *q, char __user *buf, unsigned long le
 static long qcam_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 {
        struct video_device *dev = video_devdata(file);
-       struct qcam_device *qcam=(struct qcam_device *)dev;
+       struct qcam_device *qcam = (struct qcam_device *)dev;
 
-       switch(cmd)
+       switch (cmd) {
+       case VIDIOCGCAP:
        {
-               case VIDIOCGCAP:
-               {
-                       struct video_capability *b = arg;
-                       strcpy(b->name, "Quickcam");
-                       b->type = VID_TYPE_CAPTURE|VID_TYPE_SCALES;
-                       b->channels = 1;
-                       b->audios = 0;
-                       b->maxwidth = 320;
-                       b->maxheight = 240;
-                       b->minwidth = 80;
-                       b->minheight = 60;
-                       return 0;
-               }
-               case VIDIOCGCHAN:
-               {
-                       struct video_channel *v = arg;
-                       if(v->channel!=0)
-                               return -EINVAL;
-                       v->flags=0;
-                       v->tuners=0;
-                       /* Good question.. its composite or SVHS so.. */
-                       v->type = VIDEO_TYPE_CAMERA;
-                       strcpy(v->name, "Camera");
-                       return 0;
-               }
-               case VIDIOCSCHAN:
-               {
-                       struct video_channel *v = arg;
-                       if(v->channel!=0)
-                               return -EINVAL;
-                       return 0;
-               }
-               case VIDIOCGTUNER:
-               {
-                       struct video_tuner *v = arg;
-                       if(v->tuner)
-                               return -EINVAL;
-                       memset(v,0,sizeof(*v));
-                       strcpy(v->name, "Format");
-                       v->mode = VIDEO_MODE_AUTO;
-                       return 0;
-               }
-               case VIDIOCSTUNER:
-               {
-                       struct video_tuner *v = arg;
-                       if(v->tuner)
-                               return -EINVAL;
-                       if(v->mode!=VIDEO_MODE_AUTO)
-                               return -EINVAL;
-                       return 0;
-               }
-               case VIDIOCGPICT:
-               {
-                       struct video_picture *p = arg;
-                       p->colour=0x8000;
-                       p->hue=0x8000;
-                       p->brightness=qcam->brightness<<8;
-                       p->contrast=qcam->contrast<<8;
-                       p->whiteness=qcam->whitebal<<8;
-                       p->depth=24;
-                       p->palette=VIDEO_PALETTE_RGB24;
-                       return 0;
+               struct video_capability *b = arg;
+
+               strcpy(b->name, "Quickcam");
+               b->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
+               b->channels = 1;
+               b->audios = 0;
+               b->maxwidth = 320;
+               b->maxheight = 240;
+               b->minwidth = 80;
+               b->minheight = 60;
+               return 0;
+       }
+       case VIDIOCGCHAN:
+       {
+               struct video_channel *v = arg;
+
+               if (v->channel != 0)
+                       return -EINVAL;
+               v->flags = 0;
+               v->tuners = 0;
+               /* Good question.. its composite or SVHS so.. */
+               v->type = VIDEO_TYPE_CAMERA;
+               strcpy(v->name, "Camera");
+               return 0;
+       }
+       case VIDIOCSCHAN:
+       {
+               struct video_channel *v = arg;
+
+               if (v->channel != 0)
+                       return -EINVAL;
+               return 0;
+       }
+       case VIDIOCGTUNER:
+       {
+               struct video_tuner *v = arg;
+
+               if (v->tuner)
+                       return -EINVAL;
+               memset(v, 0, sizeof(*v));
+               strcpy(v->name, "Format");
+               v->mode = VIDEO_MODE_AUTO;
+               return 0;
+       }
+       case VIDIOCSTUNER:
+       {
+               struct video_tuner *v = arg;
+
+               if (v->tuner)
+                       return -EINVAL;
+               if (v->mode != VIDEO_MODE_AUTO)
+                       return -EINVAL;
+               return 0;
+       }
+       case VIDIOCGPICT:
+       {
+               struct video_picture *p = arg;
+
+               p->colour = 0x8000;
+               p->hue = 0x8000;
+               p->brightness = qcam->brightness << 8;
+               p->contrast = qcam->contrast << 8;
+               p->whiteness = qcam->whitebal << 8;
+               p->depth = 24;
+               p->palette = VIDEO_PALETTE_RGB24;
+               return 0;
+       }
+       case VIDIOCSPICT:
+       {
+               struct video_picture *p = arg;
+
+               /*
+                *      Sanity check args
+                */
+               if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24)
+                       return -EINVAL;
+
+               /*
+                *      Now load the camera.
+                */
+               qcam->brightness = p->brightness >> 8;
+               qcam->contrast = p->contrast >> 8;
+               qcam->whitebal = p->whiteness >> 8;
+
+               mutex_lock(&qcam->lock);
+               parport_claim_or_block(qcam->pdev);
+               qc_setup(qcam);
+               parport_release(qcam->pdev);
+               mutex_unlock(&qcam->lock);
+               return 0;
+       }
+       case VIDIOCSWIN:
+       {
+               struct video_window *vw = arg;
+
+               if (vw->flags)
+                       return -EINVAL;
+               if (vw->clipcount)
+                       return -EINVAL;
+               if (vw->height < 60 || vw->height > 240)
+                       return -EINVAL;
+               if (vw->width < 80 || vw->width > 320)
+                       return -EINVAL;
+
+               qcam->width = 80;
+               qcam->height = 60;
+               qcam->mode = QC_DECIMATION_4;
+
+               if (vw->width >= 160 && vw->height >= 120) {
+                       qcam->width = 160;
+                       qcam->height = 120;
+                       qcam->mode = QC_DECIMATION_2;
                }
-               case VIDIOCSPICT:
-               {
-                       struct video_picture *p = arg;
-
-                       /*
-                        *      Sanity check args
-                        */
-                       if (p->depth != 24 || p->palette != VIDEO_PALETTE_RGB24)
-                               return -EINVAL;
-
-                       /*
-                        *      Now load the camera.
-                        */
-                       qcam->brightness = p->brightness>>8;
-                       qcam->contrast = p->contrast>>8;
-                       qcam->whitebal = p->whiteness>>8;
-
-                       mutex_lock(&qcam->lock);
-                       parport_claim_or_block(qcam->pdev);
-                       qc_setup(qcam);
-                       parport_release(qcam->pdev);
-                       mutex_unlock(&qcam->lock);
-                       return 0;
+               if (vw->width >= 320 && vw->height >= 240) {
+                       qcam->width = 320;
+                       qcam->height = 240;
+                       qcam->mode = QC_DECIMATION_1;
                }
-               case VIDIOCSWIN:
-               {
-                       struct video_window *vw = arg;
-
-                       if(vw->flags)
-                               return -EINVAL;
-                       if(vw->clipcount)
-                               return -EINVAL;
-                       if(vw->height<60||vw->height>240)
-                               return -EINVAL;
-                       if(vw->width<80||vw->width>320)
-                               return -EINVAL;
-
-                       qcam->width = 80;
-                       qcam->height = 60;
-                       qcam->mode = QC_DECIMATION_4;
-
-                       if(vw->width>=160 && vw->height>=120)
-                       {
-                               qcam->width = 160;
-                               qcam->height = 120;
-                               qcam->mode = QC_DECIMATION_2;
-                       }
-                       if(vw->width>=320 && vw->height>=240)
-                       {
-                               qcam->width = 320;
-                               qcam->height = 240;
-                               qcam->mode = QC_DECIMATION_1;
-                       }
-                       qcam->mode |= QC_MILLIONS;
+               qcam->mode |= QC_MILLIONS;
 #if 0
-                       if(vw->width>=640 && vw->height>=480)
-                       {
-                               qcam->width = 640;
-                               qcam->height = 480;
-                               qcam->mode = QC_BILLIONS | QC_DECIMATION_1;
-                       }
-#endif
-                       /* Ok we figured out what to use from our
-                          wide choice */
-                       mutex_lock(&qcam->lock);
-                       parport_claim_or_block(qcam->pdev);
-                       qc_setup(qcam);
-                       parport_release(qcam->pdev);
-                       mutex_unlock(&qcam->lock);
-                       return 0;
-               }
-               case VIDIOCGWIN:
-               {
-                       struct video_window *vw = arg;
-                       memset(vw, 0, sizeof(*vw));
-                       vw->width=qcam->width;
-                       vw->height=qcam->height;
-                       return 0;
+               if (vw->width >= 640 && vw->height >= 480) {
+                       qcam->width = 640;
+                       qcam->height = 480;
+                       qcam->mode = QC_BILLIONS | QC_DECIMATION_1;
                }
-               case VIDIOCKEY:
-                       return 0;
-               case VIDIOCCAPTURE:
-               case VIDIOCGFBUF:
-               case VIDIOCSFBUF:
-               case VIDIOCGFREQ:
-               case VIDIOCSFREQ:
-               case VIDIOCGAUDIO:
-               case VIDIOCSAUDIO:
-                       return -EINVAL;
-               default:
-                       return -ENOIOCTLCMD;
+#endif
+               /* Ok we figured out what to use from our
+                  wide choice */
+               mutex_lock(&qcam->lock);
+               parport_claim_or_block(qcam->pdev);
+               qc_setup(qcam);
+               parport_release(qcam->pdev);
+               mutex_unlock(&qcam->lock);
+               return 0;
+       }
+       case VIDIOCGWIN:
+       {
+               struct video_window *vw = arg;
+               memset(vw, 0, sizeof(*vw));
+               vw->width = qcam->width;
+               vw->height = qcam->height;
+               return 0;
+       }
+       case VIDIOCKEY:
+               return 0;
+       case VIDIOCCAPTURE:
+       case VIDIOCGFBUF:
+       case VIDIOCSFBUF:
+       case VIDIOCGFREQ:
+       case VIDIOCSFREQ:
+       case VIDIOCGAUDIO:
+       case VIDIOCSAUDIO:
+               return -EINVAL;
+       default:
+               return -ENOIOCTLCMD;
        }
        return 0;
 }
@@ -675,13 +670,13 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
                         size_t count, loff_t *ppos)
 {
        struct video_device *v = video_devdata(file);
-       struct qcam_device *qcam=(struct qcam_device *)v;
+       struct qcam_device *qcam = (struct qcam_device *)v;
        int len;
 
        mutex_lock(&qcam->lock);
        parport_claim_or_block(qcam->pdev);
        /* Probably should have a semaphore against multiple users */
-       len = qc_capture(qcam, buf,count);
+       len = qc_capture(qcam, buf, count);
        parport_release(qcam->pdev);
        mutex_unlock(&qcam->lock);
        return len;
@@ -713,8 +708,7 @@ static const struct v4l2_file_operations qcam_fops = {
        .read           = qcam_read,
 };
 
-static struct video_device qcam_template=
-{
+static struct video_device qcam_template = {
        .name           = "Colour QuickCam",
        .fops           = &qcam_fops,
        .release        = video_device_release_empty,
@@ -727,17 +721,16 @@ static struct qcam_device *qcam_init(struct parport *port)
        struct qcam_device *q;
 
        q = kmalloc(sizeof(struct qcam_device), GFP_KERNEL);
-       if(q==NULL)
+       if (q == NULL)
                return NULL;
 
        q->pport = port;
        q->pdev = parport_register_device(port, "c-qcam", NULL, NULL,
                                          NULL, 0, NULL);
 
-       q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE)?1:0;
+       q->bidirectional = (q->pport->modes & PARPORT_MODE_TRISTATE) ? 1 : 0;
 
-       if (q->pdev == NULL)
-       {
+       if (q->pdev == NULL) {
                printk(KERN_ERR "c-qcam: couldn't register for %s.\n",
                       port->name);
                kfree(q);
@@ -765,12 +758,11 @@ static int init_cqcam(struct parport *port)
 {
        struct qcam_device *qcam;
 
-       if (parport[0] != -1)
-       {
+       if (parport[0] != -1) {
                /* The user gave specific instructions */
                int i, found = 0;
-               for (i = 0; i < MAX_CAMS && parport[i] != -1; i++)
-               {
+
+               for (i = 0; i < MAX_CAMS && parport[i] != -1; i++) {
                        if (parport[0] == port->number)
                                found = 1;
                }
@@ -782,15 +774,14 @@ static int init_cqcam(struct parport *port)
                return -ENOSPC;
 
        qcam = qcam_init(port);
-       if (qcam==NULL)
+       if (qcam == NULL)
                return -ENODEV;
 
        parport_claim_or_block(qcam->pdev);
 
        qc_reset(qcam);
 
-       if (probe && qc_detect(qcam)==0)
-       {
+       if (probe && qc_detect(qcam) == 0) {
                parport_release(qcam->pdev);
                parport_unregister_device(qcam->pdev);
                kfree(qcam);
@@ -840,14 +831,14 @@ static struct parport_driver cqcam_driver = {
        .detach = cq_detach,
 };
 
-static int __init cqcam_init (void)
+static int __init cqcam_init(void)
 {
        printk(BANNER "\n");
 
        return parport_register_driver(&cqcam_driver);
 }
 
-static void __exit cqcam_cleanup (void)
+static void __exit cqcam_cleanup(void)
 {
        unsigned int i;
 
@@ -862,9 +853,9 @@ MODULE_DESCRIPTION(BANNER);
 MODULE_LICENSE("GPL");
 
 /* FIXME: parport=auto would never have worked, surely? --RR */
-MODULE_PARM_DESC(parport ,"parport=<auto|n[,n]...> for port detection method\n\
-probe=<0|1|2> for camera detection method\n\
-force_rgb=<0|1> for RGB data format (default BGR)");
+MODULE_PARM_DESC(parport, "parport=<auto|n[,n]...> for port detection method\n"
+                         "probe=<0|1|2> for camera detection method\n"
+                         "force_rgb=<0|1> for RGB data format (default BGR)");
 module_param_array(parport, int, NULL, 0);
 module_param(probe, int, 0);
 module_param(force_rgb, bool, 0);
index 6f91415..5520789 100644 (file)
@@ -324,7 +324,7 @@ static int cpia2_close(struct file *file)
        {
                if(fh->mmapped)
                        cam->mmapped = 0;
-               v4l2_prio_close(&cam->prio,&fh->prio);
+               v4l2_prio_close(&cam->prio, fh->prio);
                file->private_data = NULL;
                kfree(fh);
        }
@@ -1592,7 +1592,7 @@ static long cpia2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
        case VIDIOC_S_FMT:
        {
                struct cpia2_fh *fh = file->private_data;
-               retval = v4l2_prio_check(&cam->prio, &fh->prio);
+               retval = v4l2_prio_check(&cam->prio, fh->prio);
                if(retval) {
                        mutex_unlock(&cam->busy_lock);
                        return retval;
index 4392c76..0e5006b 100644 (file)
@@ -579,6 +579,7 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
 
        u8 afe_mux_cfg;
        u8 adc2_cfg;
+       u8 input_mode;
        u32 afe_cfg;
        int i;
 
@@ -589,6 +590,30 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
            vid_input <= CX18_AV_COMPOSITE8) {
                afe_mux_cfg = 0xf0 + (vid_input - CX18_AV_COMPOSITE1);
                ch[0] = CVBS;
+               input_mode = 0x0;
+       } else if (vid_input >= CX18_AV_COMPONENT_LUMA1) {
+               int luma = vid_input & 0xf000;
+               int r_chroma = vid_input & 0xf0000;
+               int b_chroma = vid_input & 0xf00000;
+
+               if ((vid_input & ~0xfff000) ||
+                   luma < CX18_AV_COMPONENT_LUMA1 ||
+                   luma > CX18_AV_COMPONENT_LUMA8 ||
+                   r_chroma < CX18_AV_COMPONENT_R_CHROMA4 ||
+                   r_chroma > CX18_AV_COMPONENT_R_CHROMA6 ||
+                   b_chroma < CX18_AV_COMPONENT_B_CHROMA7 ||
+                   b_chroma > CX18_AV_COMPONENT_B_CHROMA8) {
+                       CX18_ERR_DEV(sd, "0x%06x is not a valid video input!\n",
+                                    vid_input);
+                       return -EINVAL;
+               }
+               afe_mux_cfg = (luma - CX18_AV_COMPONENT_LUMA1) >> 12;
+               ch[0] = Y;
+               afe_mux_cfg |= (r_chroma - CX18_AV_COMPONENT_R_CHROMA4) >> 12;
+               ch[1] = Pr;
+               afe_mux_cfg |= (b_chroma - CX18_AV_COMPONENT_B_CHROMA7) >> 14;
+               ch[2] = Pb;
+               input_mode = 0x6;
        } else {
                int luma = vid_input & 0xf0;
                int chroma = vid_input & 0xf00;
@@ -598,7 +623,7 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
                    luma > CX18_AV_SVIDEO_LUMA8 ||
                    chroma < CX18_AV_SVIDEO_CHROMA4 ||
                    chroma > CX18_AV_SVIDEO_CHROMA8) {
-                       CX18_ERR_DEV(sd, "0x%04x is not a valid video input!\n",
+                       CX18_ERR_DEV(sd, "0x%06x is not a valid video input!\n",
                                     vid_input);
                        return -EINVAL;
                }
@@ -613,8 +638,8 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
                        afe_mux_cfg |= (chroma - CX18_AV_SVIDEO_CHROMA4) >> 4;
                        ch[1] = C;
                }
+               input_mode = 0x2;
        }
-       /* TODO: LeadTek WinFast DVR3100 H & WinFast PVR2100 can do Y/Pb/Pr */
 
        switch (aud_input) {
        case CX18_AV_AUDIO_SERIAL1:
@@ -650,8 +675,8 @@ static int set_input(struct cx18 *cx, enum cx18_av_video_input vid_input,
 
        /* Set up analog front end multiplexers */
        cx18_av_write_expect(cx, 0x103, afe_mux_cfg, afe_mux_cfg, 0xf7);
-       /* Set INPUT_MODE to Composite (0) or S-Video (1) */
-       cx18_av_and_or(cx, 0x401, ~0x6, ch[0] == CVBS ? 0 : 0x02);
+       /* Set INPUT_MODE to Composite, S-Video, or Component */
+       cx18_av_and_or(cx, 0x401, ~0x6, input_mode);
 
        /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */
        adc2_cfg = cx18_av_read(cx, 0x102);
@@ -998,9 +1023,9 @@ static int cx18_av_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
 
 static int cx18_av_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
 {
-       struct cx18 *cx = v4l2_get_subdevdata(sd);
-
-       return cx18_av_vbi_g_fmt(cx, fmt);
+       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+               return -EINVAL;
+       return cx18_av_g_sliced_fmt(sd, &fmt->fmt.sliced);
 }
 
 static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
@@ -1073,12 +1098,6 @@ static int cx18_av_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
                cx18_av_write(cx, 0x41e, 0x8 | filter);
                break;
 
-       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               return cx18_av_vbi_s_fmt(cx, fmt);
-
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               return cx18_av_vbi_s_fmt(cx, fmt);
-
        default:
                return -EINVAL;
        }
@@ -1378,17 +1397,24 @@ static const struct v4l2_subdev_audio_ops cx18_av_audio_ops = {
 
 static const struct v4l2_subdev_video_ops cx18_av_video_ops = {
        .s_routing = cx18_av_s_video_routing,
-       .decode_vbi_line = cx18_av_decode_vbi_line,
        .s_stream = cx18_av_s_stream,
        .g_fmt = cx18_av_g_fmt,
        .s_fmt = cx18_av_s_fmt,
 };
 
+static const struct v4l2_subdev_vbi_ops cx18_av_vbi_ops = {
+       .decode_vbi_line = cx18_av_decode_vbi_line,
+       .g_sliced_fmt = cx18_av_g_sliced_fmt,
+       .s_sliced_fmt = cx18_av_s_sliced_fmt,
+       .s_raw_fmt = cx18_av_s_raw_fmt,
+};
+
 static const struct v4l2_subdev_ops cx18_av_ops = {
        .core = &cx18_av_general_ops,
        .tuner = &cx18_av_tuner_ops,
        .audio = &cx18_av_audio_ops,
        .video = &cx18_av_video_ops,
+       .vbi = &cx18_av_vbi_ops,
 };
 
 int cx18_av_probe(struct cx18 *cx)
index cafb7e9..c106967 100644 (file)
@@ -61,6 +61,25 @@ enum cx18_av_video_input {
        CX18_AV_SVIDEO2 = 0x620,
        CX18_AV_SVIDEO3 = 0x730,
        CX18_AV_SVIDEO4 = 0x840,
+
+       /* Component Video inputs consist of one luma input (In1-In8) ORed
+          with a red chroma (In4-In6) and blue chroma input (In7-In8) */
+       CX18_AV_COMPONENT_LUMA1 = 0x1000,
+       CX18_AV_COMPONENT_LUMA2 = 0x2000,
+       CX18_AV_COMPONENT_LUMA3 = 0x3000,
+       CX18_AV_COMPONENT_LUMA4 = 0x4000,
+       CX18_AV_COMPONENT_LUMA5 = 0x5000,
+       CX18_AV_COMPONENT_LUMA6 = 0x6000,
+       CX18_AV_COMPONENT_LUMA7 = 0x7000,
+       CX18_AV_COMPONENT_LUMA8 = 0x8000,
+       CX18_AV_COMPONENT_R_CHROMA4 = 0x40000,
+       CX18_AV_COMPONENT_R_CHROMA5 = 0x50000,
+       CX18_AV_COMPONENT_R_CHROMA6 = 0x60000,
+       CX18_AV_COMPONENT_B_CHROMA7 = 0x700000,
+       CX18_AV_COMPONENT_B_CHROMA8 = 0x800000,
+
+       /* Component Video aliases for common combinations */
+       CX18_AV_COMPONENT1 = 0x861000,
 };
 
 enum cx18_av_audio_input {
@@ -359,7 +378,8 @@ void cx18_av_audio_set_path(struct cx18 *cx);
 /* cx18_av-vbi.c                                                           */
 int cx18_av_decode_vbi_line(struct v4l2_subdev *sd,
                           struct v4l2_decode_vbi_line *vbi);
-int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt);
-int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt);
+int cx18_av_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
+int cx18_av_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
+int cx18_av_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
 
 #endif
index a51732b..baa36fb 100644 (file)
@@ -129,10 +129,10 @@ static int decode_vps(u8 *dst, u8 *p)
        return err & 0xf0;
 }
 
-int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt)
+int cx18_av_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
 {
+       struct cx18 *cx = v4l2_get_subdevdata(sd);
        struct cx18_av_state *state = &cx->av_state;
-       struct v4l2_sliced_vbi_format *svbi;
        static const u16 lcr2vbi[] = {
                0, V4L2_SLICED_TELETEXT_B, 0,   /* 1 */
                0, V4L2_SLICED_WSS_625, 0,      /* 4 */
@@ -143,9 +143,6 @@ int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt)
        int is_pal = !(state->std & V4L2_STD_525_60);
        int i;
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
-               return -EINVAL;
-       svbi = &fmt->fmt.sliced;
        memset(svbi, 0, sizeof(*svbi));
        /* we're done if raw VBI is active */
        if ((cx18_av_read(cx, 0x404) & 0x10) == 0)
@@ -173,30 +170,27 @@ int cx18_av_vbi_g_fmt(struct cx18 *cx, struct v4l2_format *fmt)
        return 0;
 }
 
-int cx18_av_vbi_s_fmt(struct cx18 *cx, struct v4l2_format *fmt)
+int cx18_av_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
 {
+       struct cx18 *cx = v4l2_get_subdevdata(sd);
        struct cx18_av_state *state = &cx->av_state;
-       struct v4l2_sliced_vbi_format *svbi;
-       int is_pal = !(state->std & V4L2_STD_525_60);
-       int i, x;
-       u8 lcr[24];
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
-                       fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
-               return -EINVAL;
-       svbi = &fmt->fmt.sliced;
-       if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-               /* raw VBI */
-               memset(svbi, 0, sizeof(*svbi));
+       /* Setup standard */
+       cx18_av_std_setup(cx);
 
-               /* Setup standard */
-               cx18_av_std_setup(cx);
+       /* VBI Offset */
+       cx18_av_write(cx, 0x47f, state->slicer_line_delay);
+       cx18_av_write(cx, 0x404, 0x2e);
+       return 0;
+}
 
-               /* VBI Offset */
-               cx18_av_write(cx, 0x47f, state->slicer_line_delay);
-               cx18_av_write(cx, 0x404, 0x2e);
-               return 0;
-       }
+int cx18_av_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
+{
+       struct cx18 *cx = v4l2_get_subdevdata(sd);
+       struct cx18_av_state *state = &cx->av_state;
+       int is_pal = !(state->std & V4L2_STD_525_60);
+       int i, x;
+       u8 lcr[24];
 
        for (x = 0; x <= 23; x++)
                lcr[x] = 0x00;
index f808fb6..74e122b 100644 (file)
@@ -370,6 +370,7 @@ static const struct cx18_card cx18_card_leadtek_pvr2100 = {
                { CX18_CARD_INPUT_SVIDEO1,    1,
                        CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
                { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE7 },
+               { CX18_CARD_INPUT_COMPONENT1, 1, CX18_AV_COMPONENT1 },
        },
        .audio_inputs = {
                { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
@@ -422,6 +423,7 @@ static const struct cx18_card cx18_card_leadtek_dvr3100h = {
                { CX18_CARD_INPUT_SVIDEO1,    1,
                        CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
                { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE7 },
+               { CX18_CARD_INPUT_COMPONENT1, 1, CX18_AV_COMPONENT1 },
        },
        .audio_inputs = {
                { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
@@ -480,7 +482,7 @@ int cx18_get_input(struct cx18 *cx, u16 index, struct v4l2_input *input)
                "S-Video 2",
                "Composite 1",
                "Composite 2",
-               "Composite 3"
+               "Component 1"
        };
 
        memset(input, 0, sizeof(*input));
index af3d716..796e517 100644 (file)
@@ -43,7 +43,7 @@
 #define        CX18_CARD_INPUT_SVIDEO2         3
 #define        CX18_CARD_INPUT_COMPOSITE1      4
 #define        CX18_CARD_INPUT_COMPOSITE2      5
-#define        CX18_CARD_INPUT_COMPOSITE3      6
+#define        CX18_CARD_INPUT_COMPONENT1      6
 
 /* audio inputs */
 #define        CX18_CARD_INPUT_AUD_TUNER       1
@@ -62,7 +62,7 @@
 struct cx18_card_video_input {
        u8  video_type;         /* video input type */
        u8  audio_index;        /* index in cx18_card_audio_input array */
-       u16 video_input;        /* hardware video input */
+       u32 video_input;        /* hardware video input */
 };
 
 struct cx18_card_audio_input {
index 7fa5892..4b4b465 100644 (file)
@@ -263,7 +263,7 @@ int cx18_s_ext_ctrls(struct file *file, void *fh, struct v4l2_ext_controls *c)
        int ret;
        struct v4l2_control ctrl;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
index 863ce77..e12a150 100644 (file)
@@ -700,7 +700,7 @@ int cx18_v4l2_close(struct file *filp)
 
        CX18_DEBUG_IOCTL("close() of %s\n", s->name);
 
-       v4l2_prio_close(&cx->prio, &id->prio);
+       v4l2_prio_close(&cx->prio, id->prio);
 
        /* Easy case first: this stream was never claimed by us */
        if (s->id != id->open_id) {
index eecf29a..cfa1f28 100644 (file)
@@ -109,7 +109,7 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw,
        /* Our default information for ir-kbd-i2c.c to use */
        switch (hw) {
        case CX18_HW_Z8F0811_IR_RX_HAUP:
-               init_data->ir_codes = &ir_codes_hauppauge_new_table;
+               init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
                init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
                init_data->type = IR_TYPE_RC5;
                init_data->name = cx->card_name;
index b81dd0e..2530fc5 100644 (file)
@@ -208,7 +208,7 @@ static int cx18_g_fmt_sliced_vbi_cap(struct file *file, void *fh,
         * digitizer/slicer.  Note, cx18_av_vbi() wipes the passed in
         * fmt->fmt.sliced under valid calling conditions
         */
-       if (v4l2_subdev_call(cx->sd_av, video, g_fmt, fmt))
+       if (v4l2_subdev_call(cx->sd_av, vbi, g_sliced_fmt, &fmt->fmt.sliced))
                return -EINVAL;
 
        /* Ensure V4L2 spec compliant output */
@@ -277,7 +277,7 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
        int ret;
        int w, h;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -306,7 +306,7 @@ static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -322,7 +322,7 @@ static int cx18_s_fmt_vbi_cap(struct file *file, void *fh,
         * Note cx18_av_vbi_wipes out alot of the passed in fmt under valid
         * calling conditions
         */
-       ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
+       ret = v4l2_subdev_call(cx->sd_av, vbi, s_raw_fmt, &fmt->fmt.vbi);
        if (ret)
                return ret;
 
@@ -341,7 +341,7 @@ static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
        int ret;
        struct v4l2_sliced_vbi_format *vbifmt = &fmt->fmt.sliced;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -359,7 +359,7 @@ static int cx18_s_fmt_sliced_vbi_cap(struct file *file, void *fh,
         * Note, cx18_av_vbi() wipes some "impossible" service lines in the
         * passed in fmt->fmt.sliced under valid calling conditions
         */
-       ret = v4l2_subdev_call(cx->sd_av, video, s_fmt, fmt);
+       ret = v4l2_subdev_call(cx->sd_av, vbi, s_sliced_fmt, &fmt->fmt.sliced);
        if (ret)
                return ret;
        /* Store our current v4l2 sliced VBI settings */
@@ -549,7 +549,7 @@ static int cx18_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -601,7 +601,7 @@ int cx18_s_input(struct file *file, void *fh, unsigned int inp)
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -647,7 +647,7 @@ int cx18_s_frequency(struct file *file, void *fh, struct v4l2_frequency *vf)
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -675,7 +675,7 @@ int cx18_s_std(struct file *file, void *fh, v4l2_std_id *std)
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
@@ -715,7 +715,7 @@ static int cx18_s_tuner(struct file *file, void *fh, struct v4l2_tuner *vt)
        struct cx18 *cx = id->cx;
        int ret;
 
-       ret = v4l2_prio_check(&cx->prio, &id->prio);
+       ret = v4l2_prio_check(&cx->prio, id->prio);
        if (ret)
                return ret;
 
index 054450f..f5c9126 100644 (file)
@@ -374,7 +374,10 @@ static void cx18_vbi_setup(struct cx18_stream *s)
        }
 
        /* setup VBI registers */
-       v4l2_subdev_call(cx->sd_av, video, s_fmt, &cx->vbi.in);
+       if (raw)
+               v4l2_subdev_call(cx->sd_av, vbi, s_raw_fmt, &cx->vbi.in.fmt.vbi);
+       else
+               v4l2_subdev_call(cx->sd_av, vbi, s_sliced_fmt, &cx->vbi.in.fmt.sliced);
 
        /*
         * Send the CX18_CPU_SET_RAW_VBI_PARAM API command to setup Encoder Raw
index 574c1c6..5822275 100644 (file)
@@ -174,7 +174,7 @@ static u32 compress_sliced_buf(struct cx18 *cx, u8 *buf, u32 size,
                     p[3] != sliced_vbi_eav_rp[1]))
                        continue;
                vbi.p = p + 4;
-               v4l2_subdev_call(cx->sd_av, video, decode_vbi_line, &vbi);
+               v4l2_subdev_call(cx->sd_av, vbi, decode_vbi_line, &vbi);
                if (vbi.type) {
                        cx->vbi.sliced_data[line].id = vbi.type;
                        cx->vbi.sliced_data[line].field = vbi.is_second_field;
index 7793d60..7cae95a 100644 (file)
@@ -495,7 +495,7 @@ static int cx231xx_audio_init(struct cx231xx *dev)
        pcm->info_flags = 0;
        pcm->private_data = dev;
        strcpy(pcm->name, "Conexant cx231xx Capture");
-       strcpy(card->driver, "Conexant cx231xx Audio");
+       strcpy(card->driver, "Cx231xx-Audio");
        strcpy(card->shortname, "Cx231xx Audio");
        strcpy(card->longname, "Conexant cx231xx Audio");
 
index b24eee1..f5e1a23 100644 (file)
@@ -96,10 +96,9 @@ int cx231xx_register_extension(struct cx231xx_ops *ops)
        mutex_lock(&cx231xx_devlist_mutex);
        mutex_lock(&cx231xx_extension_devlist_lock);
        list_add_tail(&ops->next, &cx231xx_extension_devlist);
-       list_for_each_entry(dev, &cx231xx_devlist, devlist) {
-               if (dev)
-                       ops->init(dev);
-       }
+       list_for_each_entry(dev, &cx231xx_devlist, devlist)
+               ops->init(dev);
+
        printk(KERN_INFO DRIVER_NAME ": %s initialized\n", ops->name);
        mutex_unlock(&cx231xx_extension_devlist_lock);
        mutex_unlock(&cx231xx_devlist_mutex);
@@ -112,10 +111,8 @@ void cx231xx_unregister_extension(struct cx231xx_ops *ops)
        struct cx231xx *dev = NULL;
 
        mutex_lock(&cx231xx_devlist_mutex);
-       list_for_each_entry(dev, &cx231xx_devlist, devlist) {
-               if (dev)
-                       ops->fini(dev);
-       }
+       list_for_each_entry(dev, &cx231xx_devlist, devlist)
+               ops->fini(dev);
 
        mutex_lock(&cx231xx_extension_devlist_lock);
        printk(KERN_INFO DRIVER_NAME ": %s removed\n", ops->name);
index b473cd8..fd09915 100644 (file)
@@ -35,6 +35,8 @@ static unsigned int ir_debug;
 module_param(ir_debug, int, 0644);
 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
 
+#define MODULE_NAME "cx231xx"
+
 #define i2cdprintk(fmt, arg...) \
        if (ir_debug) { \
                printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
@@ -59,7 +61,6 @@ struct cx231xx_ir_poll_result {
 struct cx231xx_IR {
        struct cx231xx *dev;
        struct input_dev *input;
-       struct ir_input_state ir;
        char name[32];
        char phys[32];
 
@@ -67,9 +68,7 @@ struct cx231xx_IR {
        int polling;
        struct work_struct work;
        struct timer_list timer;
-       unsigned int last_toggle:1;
        unsigned int last_readcount;
-       unsigned int repeat_interval;
 
        int (*get_key) (struct cx231xx_IR *, struct cx231xx_ir_poll_result *);
 };
@@ -81,7 +80,6 @@ struct cx231xx_IR {
 static void cx231xx_ir_handle_key(struct cx231xx_IR *ir)
 {
        int result;
-       int do_sendkey = 0;
        struct cx231xx_ir_poll_result poll_result;
 
        /* read the registers containing the IR status */
@@ -95,44 +93,23 @@ static void cx231xx_ir_handle_key(struct cx231xx_IR *ir)
                poll_result.toggle_bit, poll_result.read_count,
                ir->last_readcount, poll_result.rc_data[0]);
 
-       if (ir->dev->chip_id == CHIP_ID_EM2874) {
+       if (poll_result.read_count > 0 &&
+           poll_result.read_count != ir->last_readcount)
+               ir_keydown(ir->input,
+                          poll_result.rc_data[0],
+                          poll_result.toggle_bit);
+
+       if (ir->dev->chip_id == CHIP_ID_EM2874)
                /* The em2874 clears the readcount field every time the
                   register is read.  The em2860/2880 datasheet says that it
                   is supposed to clear the readcount, but it doesn't.  So with
                   the em2874, we are looking for a non-zero read count as
                   opposed to a readcount that is incrementing */
                ir->last_readcount = 0;
-       }
-
-       if (poll_result.read_count == 0) {
-               /* The button has not been pressed since the last read */
-       } else if (ir->last_toggle != poll_result.toggle_bit) {
-               /* A button has been pressed */
-               dprintk("button has been pressed\n");
-               ir->last_toggle = poll_result.toggle_bit;
-               ir->repeat_interval = 0;
-               do_sendkey = 1;
-       } else if (poll_result.toggle_bit == ir->last_toggle &&
-                  poll_result.read_count > 0 &&
-                  poll_result.read_count != ir->last_readcount) {
-               /* The button is still being held down */
-               dprintk("button being held down\n");
-
-               /* Debouncer for first keypress */
-               if (ir->repeat_interval++ > 9) {
-                       /* Start repeating after 1 second */
-                       do_sendkey = 1;
-               }
-       }
+       else
+               ir->last_readcount = poll_result.read_count;
 
-       if (do_sendkey) {
-               dprintk("sending keypress\n");
-               ir_input_keydown(ir->input, &ir->ir, poll_result.rc_data[0]);
-               ir_input_nokey(ir->input, &ir->ir);
        }
-
-       ir->last_readcount = poll_result.read_count;
-       return;
 }
 
 static void ir_timer(unsigned long data)
@@ -198,10 +175,6 @@ int cx231xx_ir_init(struct cx231xx *dev)
        usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
        strlcat(ir->phys, "/input0", sizeof(ir->phys));
 
-       err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
-       if (err < 0)
-               goto err_out_free;
-
        input_dev->name = ir->name;
        input_dev->phys = ir->phys;
        input_dev->id.bustype = BUS_USB;
@@ -217,7 +190,8 @@ int cx231xx_ir_init(struct cx231xx *dev)
        cx231xx_ir_start(ir);
 
        /* all done */
-       err = ir_input_register(ir->input, dev->board.ir_codes, NULL);
+       err = __ir_input_register(ir->input, dev->board.ir_codes,
+                               NULL, MODULE_NAME);
        if (err)
                goto err_out_stop;
 
index 16a73ea..2782709 100644 (file)
@@ -1669,7 +1669,7 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
 
        f->fmt.sliced.service_set = 0;
 
-       call_all(dev, video, g_fmt, f);
+       call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
 
        if (f->fmt.sliced.service_set == 0)
                rc = -EINVAL;
@@ -1690,7 +1690,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-       call_all(dev, video, g_fmt, f);
+       call_all(dev, vbi, g_sliced_fmt, &f->fmt.sliced);
        mutex_unlock(&dev->lock);
 
        if (f->fmt.sliced.service_set == 0)
@@ -1902,9 +1902,12 @@ static int radio_queryctrl(struct file *file, void *priv,
        if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1)
                return -EINVAL;
        if (c->id == V4L2_CID_AUDIO_MUTE) {
-               for (i = 0; i < CX231XX_CTLS; i++)
+               for (i = 0; i < CX231XX_CTLS; i++) {
                        if (cx231xx_ctls[i].v.id == c->id)
                                break;
+               }
+               if (i == CX231XX_CTLS)
+                       return -EINVAL;
                *c = cx231xx_ctls[i].v;
        } else
                *c = no_ctl;
index 17d4d1a..38d4171 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <media/videobuf-vmalloc.h>
 #include <media/v4l2-device.h>
-#include <media/ir-kbd-i2c.h>
+#include <media/ir-core.h>
 #if defined(CONFIG_VIDEO_CX231XX_DVB) || \
        defined(CONFIG_VIDEO_CX231XX_DVB_MODULE)
 #include <media/videobuf-dvb.h>
index 4c8e958..022b480 100644 (file)
@@ -1000,20 +1000,6 @@ int cx2341x_update(void *priv, cx2341x_mbox_func func,
                                  h, w);
                if (err) return err;
        }
-
-       if (new->width != 720 || new->height != (new->is_50hz ? 576 : 480)) {
-               /* Adjust temporal filter if necessary. The problem with the
-                  temporal filter is that it works well with full resolution
-                  capturing, but not when the capture window is scaled (the
-                  filter introduces a ghosting effect). So if the capture
-                  window is scaled, then force the filter to 0.
-
-                  For full resolution the filter really improves the video
-                  quality, especially if the original video quality is
-                  suboptimal. */
-               temporal = 0;
-       }
-
        if (force || NEQ(stream_type)) {
                err = cx2341x_api(priv, func, CX2341X_ENC_SET_STREAM_TYPE, 1,
                                  mpeg_stream_type[new->stream_type]);
index d4a9d2c..c95e7bc 100644 (file)
@@ -60,12 +60,18 @@ static unsigned int ci_dbg;
 module_param(ci_dbg, int, 0644);
 MODULE_PARM_DESC(ci_dbg, "Enable CI debugging");
 
+static unsigned int ci_irq_enable;
+module_param(ci_irq_enable, int, 0644);
+MODULE_PARM_DESC(ci_irq_enable, "Enable IRQ from CAM");
+
 #define ci_dbg_print(args...) \
        do { \
                if (ci_dbg) \
                        printk(KERN_DEBUG args); \
        } while (0)
 
+#define ci_irq_flags() (ci_irq_enable ? NETUP_IRQ_IRQAM : 0)
+
 /* stores all private variables for communication with CI */
 struct netup_ci_state {
        struct dvb_ca_en50221 ca;
@@ -392,7 +398,7 @@ int netup_poll_ci_slot_status(struct dvb_ca_en50221 *en50221, int slot, int open
        if (0 != slot)
                return -EINVAL;
 
-       netup_ci_set_irq(en50221, open ? (NETUP_IRQ_DETAM | NETUP_IRQ_IRQAM)
+       netup_ci_set_irq(en50221, open ? (NETUP_IRQ_DETAM | ci_irq_flags())
                        : NETUP_IRQ_DETAM);
 
        return state->status;
@@ -429,7 +435,7 @@ int netup_ci_init(struct cx23885_tsport *port)
                0x01, /* power on (use it like store place) */
                0x00, /* RFU */
                0x00, /* int status read only */
-               NETUP_IRQ_IRQAM | NETUP_IRQ_DETAM, /* DETAM, IRQAM unmasked */
+               ci_irq_flags() | NETUP_IRQ_DETAM, /* DETAM, IRQAM unmasked */
                0x05, /* EXTINT=active-high, INT=push-pull */
                0x00, /* USCG1 */
                0x04, /* ack active low */
@@ -470,7 +476,7 @@ int netup_ci_init(struct cx23885_tsport *port)
        state->ca.poll_slot_status = netup_poll_ci_slot_status;
        state->ca.data = state;
        state->priv = port;
-       state->current_irq_mode = NETUP_IRQ_IRQAM | NETUP_IRQ_DETAM;
+       state->current_irq_mode = ci_irq_flags() | NETUP_IRQ_DETAM;
 
        ret = netup_write_i2c(state->i2c_adap, state->ci_i2c_addr,
                                                0, &cimax_init[0], 34);
index a8ddc22..abd64e8 100644 (file)
@@ -1356,7 +1356,7 @@ static int vidioc_querycap(struct file *file, void  *priv,
        struct cx23885_dev *dev = fh->dev;
        struct cx23885_tsport  *tsport = &dev->ts1;
 
-       strcpy(cap->driver, dev->name);
+       strlcpy(cap->driver, dev->name, sizeof(cap->driver));
        strlcpy(cap->card, cx23885_boards[tsport->dev->board].name,
                sizeof(cap->card));
        sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
index 939079d..9e14608 100644 (file)
@@ -1006,6 +1006,22 @@ static int dvb_register(struct cx23885_tsport *port)
                netup_ci_init(port);
                break;
                }
+       case CX23885_BOARD_TEVII_S470: {
+               u8 eeprom[256]; /* 24C02 i2c eeprom */
+
+               if (port->nr != 1)
+                       break;
+
+               /* Read entire EEPROM */
+               dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
+               tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
+               printk(KERN_INFO "TeVii S470 MAC= "
+                               "%02X:%02X:%02X:%02X:%02X:%02X\n",
+                               eeprom[0xa0], eeprom[0xa1], eeprom[0xa2],
+                               eeprom[0xa3], eeprom[0xa4], eeprom[0xa5]);
+               memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
+               break;
+               }
        }
 
        return ret;
index 8e9d990..8d306d8 100644 (file)
@@ -51,6 +51,8 @@
 
 #define RC5_EXTENDED_COMMAND_OFFSET    64
 
+#define MODULE_NAME "cx23885"
+
 static inline unsigned int rc5_command(u32 rc5_baseband)
 {
        return RC5_INSTR(rc5_baseband) +
@@ -338,7 +340,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
 {
        struct card_ir *ir;
        struct input_dev *input_dev;
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        int ir_type, ir_addr, ir_start;
        int ret;
 
@@ -353,7 +355,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1850:
        case CX23885_BOARD_HAUPPAUGE_HVR1290:
                /* Parameters for the grey Hauppauge remote for the HVR-1850 */
-               ir_codes = &ir_codes_hauppauge_new_table;
+               ir_codes = RC_MAP_HAUPPAUGE_NEW;
                ir_type = IR_TYPE_RC5;
                ir_addr = 0x1e; /* RC-5 system bits emitted by the remote */
                ir_start = RC5_START_BITS_NORMAL; /* A basic RC-5 remote */
@@ -398,7 +400,7 @@ int cx23885_input_init(struct cx23885_dev *dev)
        dev->ir_input = ir;
        cx23885_input_ir_start(dev);
 
-       ret = ir_input_register(ir->dev, ir_codes, NULL);
+       ret = ir_input_register(ir->dev, ir_codes, NULL, MODULE_NAME);
        if (ret)
                goto err_out_stop;
 
index 2d3ac8b..543b854 100644 (file)
@@ -514,8 +514,8 @@ static int buffer_setup(struct videobuf_queue *q, unsigned int *count,
        *size = fh->fmt->depth*fh->width*fh->height >> 3;
        if (0 == *count)
                *count = 32;
-       while (*size * *count > vid_limit * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > vid_limit * 1024 * 1024)
+               *count = (vid_limit * 1024 * 1024) / *size;
        return 0;
 }
 
index f2461cd..8b6fb35 100644 (file)
@@ -1018,7 +1018,7 @@ static int cx25840_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
 {
        switch (fmt->type) {
        case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               return cx25840_vbi_g_fmt(sd, fmt);
+               return cx25840_g_sliced_fmt(sd, &fmt->fmt.sliced);
        default:
                return -EINVAL;
        }
@@ -1079,12 +1079,6 @@ static int cx25840_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
                cx25840_write(client, 0x41e, 0x8 | filter);
                break;
 
-       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
-               return cx25840_vbi_s_fmt(sd, fmt);
-
-       case V4L2_BUF_TYPE_VBI_CAPTURE:
-               return cx25840_vbi_s_fmt(sd, fmt);
-
        default:
                return -EINVAL;
        }
@@ -1635,15 +1629,22 @@ static const struct v4l2_subdev_video_ops cx25840_video_ops = {
        .s_routing = cx25840_s_video_routing,
        .g_fmt = cx25840_g_fmt,
        .s_fmt = cx25840_s_fmt,
-       .decode_vbi_line = cx25840_decode_vbi_line,
        .s_stream = cx25840_s_stream,
 };
 
+static const struct v4l2_subdev_vbi_ops cx25840_vbi_ops = {
+       .decode_vbi_line = cx25840_decode_vbi_line,
+       .s_raw_fmt = cx25840_s_raw_fmt,
+       .s_sliced_fmt = cx25840_s_sliced_fmt,
+       .g_sliced_fmt = cx25840_g_sliced_fmt,
+};
+
 static const struct v4l2_subdev_ops cx25840_ops = {
        .core = &cx25840_core_ops,
        .tuner = &cx25840_tuner_ops,
        .audio = &cx25840_audio_ops,
        .video = &cx25840_video_ops,
+       .vbi = &cx25840_vbi_ops,
 };
 
 /* ----------------------------------------------------------------------- */
index 5534544..04393b9 100644 (file)
@@ -99,8 +99,9 @@ int cx25840_audio_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl);
 
 /* ----------------------------------------------------------------------- */
 /* cx25850-vbi.c                                                           */
-int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
-int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt);
+int cx25840_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
+int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
+int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
 int cx25840_decode_vbi_line(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi);
 
 #endif
index 35f6592..64a4004 100644 (file)
@@ -82,11 +82,10 @@ static int decode_vps(u8 * dst, u8 * p)
        return err & 0xf0;
 }
 
-int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+int cx25840_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
 {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct cx25840_state *state = to_state(sd);
-       struct v4l2_sliced_vbi_format *svbi;
        static const u16 lcr2vbi[] = {
                0, V4L2_SLICED_TELETEXT_B, 0,   /* 1 */
                0, V4L2_SLICED_WSS_625, 0,      /* 4 */
@@ -97,9 +96,6 @@ int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        int is_pal = !(state->std & V4L2_STD_525_60);
        int i;
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
-               return -EINVAL;
-       svbi = &fmt->fmt.sliced;
        memset(svbi, 0, sizeof(*svbi));
        /* we're done if raw VBI is active */
        if ((cx25840_read(client, 0x404) & 0x10) == 0)
@@ -127,32 +123,30 @@ int cx25840_vbi_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        return 0;
 }
 
-int cx25840_vbi_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+int cx25840_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
 {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct cx25840_state *state = to_state(sd);
-       struct v4l2_sliced_vbi_format *svbi;
        int is_pal = !(state->std & V4L2_STD_525_60);
        int vbi_offset = is_pal ? 1 : 0;
-       int i, x;
-       u8 lcr[24];
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
-                       fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
-               return -EINVAL;
-       svbi = &fmt->fmt.sliced;
-       if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-               /* raw VBI */
-               memset(svbi, 0, sizeof(*svbi));
+       /* Setup standard */
+       cx25840_std_setup(client);
 
-               /* Setup standard */
-               cx25840_std_setup(client);
+       /* VBI Offset */
+       cx25840_write(client, 0x47f, vbi_offset);
+       cx25840_write(client, 0x404, 0x2e);
+       return 0;
+}
 
-               /* VBI Offset */
-               cx25840_write(client, 0x47f, vbi_offset);
-               cx25840_write(client, 0x404, 0x2e);
-               return 0;
-       }
+int cx25840_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct cx25840_state *state = to_state(sd);
+       int is_pal = !(state->std & V4L2_STD_525_60);
+       int vbi_offset = is_pal ? 1 : 0;
+       int i, x;
+       u8 lcr[24];
 
        for (x = 0; x <= 23; x++)
                lcr[x] = 0x00;
index b354111..8b21457 100644 (file)
@@ -847,7 +847,8 @@ static int set_tvaudio(struct cx88_core *core)
 {
        v4l2_std_id norm = core->tvnorm;
 
-       if (CX88_VMUX_TELEVISION != INPUT(core->input).type)
+       if (CX88_VMUX_TELEVISION != INPUT(core->input).type &&
+           CX88_VMUX_CABLE != INPUT(core->input).type)
                return 0;
 
        if (V4L2_STD_PAL_BG & norm) {
index 94ab862..faa8e81 100644 (file)
@@ -1231,7 +1231,7 @@ static int dvb_register(struct cx8802_dev *dev)
                                fe->ops.tuner_ops.set_config(fe, &ctl);
                }
                break;
-        case CX88_BOARD_PINNACLE_HYBRID_PCTV:
+       case CX88_BOARD_PINNACLE_HYBRID_PCTV:
        case CX88_BOARD_WINFAST_DTV1800H:
                fe0->dvb.frontend = dvb_attach(zl10353_attach,
                                               &cx88_pinnacle_hybrid_pctv,
index 6b6abf0..e185289 100644 (file)
 #include "cx88.h"
 #include <media/ir-common.h>
 
+#define MODULE_NAME "cx88xx"
+
 /* ---------------------------------------------------------------------- */
 
 struct cx88_IR {
        struct cx88_core *core;
        struct input_dev *input;
        struct ir_input_state ir;
+       struct ir_dev_props props;
+
+       int users;
+
        char name[32];
        char phys[32];
 
@@ -159,8 +165,16 @@ static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
        return HRTIMER_RESTART;
 }
 
-void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
+static int __cx88_ir_start(void *priv)
 {
+       struct cx88_core *core = priv;
+       struct cx88_IR *ir;
+
+       if (!core || !core->ir)
+               return -EINVAL;
+
+       ir = core->ir;
+
        if (ir->polling) {
                hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
                ir->timer.function = cx88_ir_work;
@@ -173,10 +187,18 @@ void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir)
                cx_write(MO_DDS_IO, 0xa80a80);  /* 4 kHz sample rate */
                cx_write(MO_DDSCFG_IO, 0x5);    /* enable */
        }
+       return 0;
 }
 
-void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
+static void __cx88_ir_stop(void *priv)
 {
+       struct cx88_core *core = priv;
+       struct cx88_IR *ir;
+
+       if (!core || !core->ir)
+               return;
+
+       ir = core->ir;
        if (ir->sampling) {
                cx_write(MO_DDSCFG_IO, 0x0);
                core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
@@ -186,15 +208,49 @@ void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir)
                hrtimer_cancel(&ir->timer);
 }
 
+int cx88_ir_start(struct cx88_core *core)
+{
+       if (core->ir->users)
+               return __cx88_ir_start(core);
+
+       return 0;
+}
+
+void cx88_ir_stop(struct cx88_core *core)
+{
+       if (core->ir->users)
+               __cx88_ir_stop(core);
+}
+
+static int cx88_ir_open(void *priv)
+{
+       struct cx88_core *core = priv;
+
+       core->ir->users++;
+       return __cx88_ir_start(core);
+}
+
+static void cx88_ir_close(void *priv)
+{
+       struct cx88_core *core = priv;
+
+       core->ir->users--;
+       if (!core->ir->users)
+               __cx88_ir_stop(core);
+}
+
 /* ---------------------------------------------------------------------- */
 
 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
 {
        struct cx88_IR *ir;
        struct input_dev *input_dev;
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        u64 ir_type = IR_TYPE_OTHER;
        int err = -ENOMEM;
+       u32 hardware_mask = 0;  /* For devices with a hardware mask, when
+                                * used with a full-code IR table
+                                */
 
        ir = kzalloc(sizeof(*ir), GFP_KERNEL);
        input_dev = input_allocate_device();
@@ -208,15 +264,15 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_DNTV_LIVE_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T:
        case CX88_BOARD_KWORLD_DVB_T_CX22702:
-               ir_codes = &ir_codes_dntv_live_dvb_t_table;
+               ir_codes = RC_MAP_DNTV_LIVE_DVB_T;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x60;
                ir->polling = 50; /* ms */
                break;
        case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
-               ir_codes = &ir_codes_cinergy_1400_table;
-               ir_type = IR_TYPE_PD;
+               ir_codes = RC_MAP_CINERGY_1400;
+               ir_type = IR_TYPE_NEC;
                ir->sampling = 0xeb04; /* address */
                break;
        case CX88_BOARD_HAUPPAUGE:
@@ -230,14 +286,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_PCHDTV_HD3000:
        case CX88_BOARD_PCHDTV_HD5500:
        case CX88_BOARD_HAUPPAUGE_IRONLY:
-               ir_codes = &ir_codes_hauppauge_new_table;
+               ir_codes = RC_MAP_HAUPPAUGE_NEW;
                ir_type = IR_TYPE_RC5;
                ir->sampling = 1;
                break;
        case CX88_BOARD_WINFAST_DTV2000H:
        case CX88_BOARD_WINFAST_DTV2000H_J:
        case CX88_BOARD_WINFAST_DTV1800H:
-               ir_codes = &ir_codes_winfast_table;
+               ir_codes = RC_MAP_WINFAST;
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0x8f8;
                ir->mask_keyup = 0x100;
@@ -246,14 +302,14 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_WINFAST2000XP_EXPERT:
        case CX88_BOARD_WINFAST_DTV1000:
        case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
-               ir_codes = &ir_codes_winfast_table;
+               ir_codes = RC_MAP_WINFAST;
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0x8f8;
                ir->mask_keyup = 0x100;
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_IODATA_GVBCTV7E:
-               ir_codes = &ir_codes_iodata_bctv7e_table;
+               ir_codes = RC_MAP_IODATA_BCTV7E;
                ir->gpio_addr = MO_GP0_IO;
                ir->mask_keycode = 0xfd;
                ir->mask_keydown = 0x02;
@@ -261,36 +317,43 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                break;
        case CX88_BOARD_PROLINK_PLAYTVPVR:
        case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
-               ir_codes = &ir_codes_pixelview_table;
+               /*
+                * It seems that this hardware is paired with NEC extended
+                * address 0x866b. So, unfortunately, its usage with other
+                * IR's with different address won't work. Still, there are
+                * other IR's from the same manufacturer that works, like the
+                * 002-T mini RC, provided with newer PV hardware
+                */
+               ir_codes = RC_MAP_PIXELVIEW_MK12;
                ir->gpio_addr = MO_GP1_IO;
-               ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x80;
-               ir->polling = 1; /* ms */
+               ir->polling = 10; /* ms */
+               hardware_mask = 0x3f;   /* Hardware returns only 6 bits from command part */
                break;
        case CX88_BOARD_PROLINK_PV_8000GT:
        case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
-               ir_codes = &ir_codes_pixelview_new_table;
+               ir_codes = RC_MAP_PIXELVIEW_NEW;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x3f;
                ir->mask_keyup = 0x80;
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_KWORLD_LTV883:
-               ir_codes = &ir_codes_pixelview_table;
+               ir_codes = RC_MAP_PIXELVIEW;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x60;
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_ADSTECH_DVB_T_PCI:
-               ir_codes = &ir_codes_adstech_dvb_t_pci_table;
+               ir_codes = RC_MAP_ADSTECH_DVB_T_PCI;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0xbf;
                ir->mask_keyup = 0x40;
                ir->polling = 50; /* ms */
                break;
        case CX88_BOARD_MSI_TVANYWHERE_MASTER:
-               ir_codes = &ir_codes_msi_tvanywhere_table;
+               ir_codes = RC_MAP_MSI_TVANYWHERE;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x1f;
                ir->mask_keyup = 0x40;
@@ -298,7 +361,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                break;
        case CX88_BOARD_AVERTV_303:
        case CX88_BOARD_AVERTV_STUDIO_303:
-               ir_codes         = &ir_codes_avertv_303_table;
+               ir_codes         = RC_MAP_AVERTV_303;
                ir->gpio_addr    = MO_GP2_IO;
                ir->mask_keycode = 0xfb;
                ir->mask_keydown = 0x02;
@@ -311,41 +374,41 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_PROF_7300:
        case CX88_BOARD_PROF_7301:
        case CX88_BOARD_PROF_6200:
-               ir_codes = &ir_codes_tbs_nec_table;
-               ir_type = IR_TYPE_PD;
+               ir_codes = RC_MAP_TBS_NEC;
+               ir_type = IR_TYPE_NEC;
                ir->sampling = 0xff00; /* address */
                break;
        case CX88_BOARD_TEVII_S460:
        case CX88_BOARD_TEVII_S420:
-               ir_codes = &ir_codes_tevii_nec_table;
-               ir_type = IR_TYPE_PD;
+               ir_codes = RC_MAP_TEVII_NEC;
+               ir_type = IR_TYPE_NEC;
                ir->sampling = 0xff00; /* address */
                break;
        case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
-               ir_codes         = &ir_codes_dntv_live_dvbt_pro_table;
-               ir_type          = IR_TYPE_PD;
+               ir_codes         = RC_MAP_DNTV_LIVE_DVBT_PRO;
+               ir_type          = IR_TYPE_NEC;
                ir->sampling     = 0xff00; /* address */
                break;
        case CX88_BOARD_NORWOOD_MICRO:
-               ir_codes         = &ir_codes_norwood_table;
+               ir_codes         = RC_MAP_NORWOOD;
                ir->gpio_addr    = MO_GP1_IO;
                ir->mask_keycode = 0x0e;
                ir->mask_keyup   = 0x80;
                ir->polling      = 50; /* ms */
                break;
        case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
-               ir_codes         = &ir_codes_npgtech_table;
+               ir_codes         = RC_MAP_NPGTECH;
                ir->gpio_addr    = MO_GP0_IO;
                ir->mask_keycode = 0xfa;
                ir->polling      = 50; /* ms */
                break;
        case CX88_BOARD_PINNACLE_PCTV_HD_800i:
-               ir_codes         = &ir_codes_pinnacle_pctv_hd_table;
+               ir_codes         = RC_MAP_PINNACLE_PCTV_HD;
                ir_type          = IR_TYPE_RC5;
                ir->sampling     = 1;
                break;
        case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
-               ir_codes         = &ir_codes_powercolor_real_angel_table;
+               ir_codes         = RC_MAP_POWERCOLOR_REAL_ANGEL;
                ir->gpio_addr    = MO_GP2_IO;
                ir->mask_keycode = 0x7e;
                ir->polling      = 100; /* ms */
@@ -357,6 +420,21 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                goto err_out_free;
        }
 
+       /*
+        * The usage of mask_keycode were very convenient, due to several
+        * reasons. Among others, the scancode tables were using the scancode
+        * as the index elements. So, the less bits it was used, the smaller
+        * the table were stored. After the input changes, the better is to use
+        * the full scancodes, since it allows replacing the IR remote by
+        * another one. Unfortunately, there are still some hardware, like
+        * Pixelview Ultra Pro, where only part of the scancode is sent via
+        * GPIO. So, there's no way to get the full scancode. Due to that,
+        * hardware_mask were introduced here: it represents those hardware
+        * that has such limits.
+        */
+       if (hardware_mask && !ir->mask_keycode)
+               ir->mask_keycode = hardware_mask;
+
        /* init input device */
        snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
        snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
@@ -381,19 +459,20 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        ir->core = core;
        core->ir = ir;
 
-       cx88_ir_start(core, ir);
+       ir->props.priv = core;
+       ir->props.open = cx88_ir_open;
+       ir->props.close = cx88_ir_close;
+       ir->props.scanmask = hardware_mask;
 
        /* all done */
-       err = ir_input_register(ir->input, ir_codes, NULL);
+       err = ir_input_register(ir->input, ir_codes, &ir->props, MODULE_NAME);
        if (err)
-               goto err_out_stop;
+               goto err_out_free;
 
        return 0;
 
- err_out_stop:
-       cx88_ir_stop(core, ir);
-       core->ir = NULL;
  err_out_free:
+       core->ir = NULL;
        kfree(ir);
        return err;
 }
@@ -406,7 +485,7 @@ int cx88_ir_fini(struct cx88_core *core)
        if (NULL == ir)
                return 0;
 
-       cx88_ir_stop(core, ir);
+       cx88_ir_stop(core);
        ir_input_unregister(ir->input);
        kfree(ir);
 
index 6aba7af..499f8d5 100644 (file)
@@ -599,13 +599,22 @@ struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board
 static int cx8802_request_acquire(struct cx8802_driver *drv)
 {
        struct cx88_core *core = drv->core;
+       unsigned int    i;
 
        /* Fail a request for hardware if the device is busy. */
        if (core->active_type_id != CX88_BOARD_NONE &&
            core->active_type_id != drv->type_id)
                return -EBUSY;
 
-       core->input = CX88_VMUX_DVB;
+       core->input = 0;
+       for (i = 0;
+            i < (sizeof(core->board.input) / sizeof(struct cx88_input));
+            i++) {
+               if (core->board.input[i].type == CX88_VMUX_DVB) {
+                       core->input = i;
+                       break;
+               }
+       }
 
        if (drv->advise_acquire)
        {
index 48c450f..0fab65c 100644 (file)
@@ -426,12 +426,13 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
                if (core->board.audio_chip &&
                    core->board.audio_chip == V4L2_IDENT_WM8775) {
                        call_all(core, audio, s_routing,
-                                       INPUT(input).audioroute, 0, 0);
+                                INPUT(input).audioroute, 0, 0);
                }
                /* cx2388's C-ADC is connected to the tuner only.
                   When used with S-Video, that ADC is busy dealing with
                   chroma, so an external must be used for baseband audio */
-               if (INPUT(input).type != CX88_VMUX_TELEVISION ) {
+               if (INPUT(input).type != CX88_VMUX_TELEVISION &&
+                   INPUT(input).type != CX88_VMUX_CABLE) {
                        /* "I2S ADC mode" */
                        core->tvaudio = WW_I2SADC;
                        cx88_set_tvaudio(core);
@@ -561,8 +562,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
        *size = fh->fmt->depth*fh->width*fh->height >> 3;
        if (0 == *count)
                *count = 32;
-       while (*size * *count > vid_limit * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > vid_limit * 1024 * 1024)
+               *count = (vid_limit * 1024 * 1024) / *size;
        return 0;
 }
 
@@ -1537,9 +1538,12 @@ static int radio_queryctrl (struct file *file, void *priv,
                c->id >= V4L2_CID_LASTP1)
                return -EINVAL;
        if (c->id == V4L2_CID_AUDIO_MUTE) {
-               for (i = 0; i < CX8800_CTLS; i++)
+               for (i = 0; i < CX8800_CTLS; i++) {
                        if (cx8800_ctls[i].v.id == c->id)
                                break;
+               }
+               if (i == CX8800_CTLS)
+                       return -EINVAL;
                *c = cx8800_ctls[i].v;
        } else
                *c = no_ctl;
@@ -1977,7 +1981,7 @@ static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
        }
 
        if (core->ir)
-               cx88_ir_stop(core, core->ir);
+               cx88_ir_stop(core);
 
        cx88_shutdown(core); /* FIXME */
        pci_disable_device(pci_dev);
@@ -2015,7 +2019,7 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
        spin_unlock(&dev->slock);
 
        if (core->ir)
-               cx88_ir_stop(core, core->ir);
+               cx88_ir_stop(core);
        /* FIXME -- shutdown device */
        cx88_shutdown(core);
 
@@ -2056,7 +2060,7 @@ static int cx8800_resume(struct pci_dev *pci_dev)
        /* FIXME: re-initialize hardware */
        cx88_reset(core);
        if (core->ir)
-               cx88_ir_start(core, core->ir);
+               cx88_ir_start(core);
 
        cx_set(MO_PCI_INTMSK, core->pci_irqmask);
 
index 48b6c04..bdb03d3 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <linux/version.h>
 #include <linux/mutex.h>
-#define CX88_VERSION_CODE KERNEL_VERSION(0,0,7)
+#define CX88_VERSION_CODE KERNEL_VERSION(0, 0, 8)
 
 #define UNSET (-1U)
 
@@ -290,7 +290,7 @@ struct cx88_subid {
 #define RESOURCE_VIDEO         2
 #define RESOURCE_VBI           4
 
-#define BUFFER_TIMEOUT     msecs_to_jiffies(500)  /* 0.5 seconds */
+#define BUFFER_TIMEOUT     msecs_to_jiffies(2000)
 
 /* buffer for one video frame */
 struct cx88_buffer {
@@ -683,8 +683,8 @@ s32 cx88_dsp_detect_stereo_sap(struct cx88_core *core);
 int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci);
 int cx88_ir_fini(struct cx88_core *core);
 void cx88_ir_irq(struct cx88_core *core);
-void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir);
-void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir);
+int cx88_ir_start(struct cx88_core *core);
+void cx88_ir_stop(struct cx88_core *core);
 
 /* ----------------------------------------------------------- */
 /* cx88-mpeg.c                                                 */
index b4cc96d..490aafb 100644 (file)
@@ -101,6 +101,9 @@ static u32 ccdc_raw_bayer_pix_formats[] =
 static u32 ccdc_raw_yuv_pix_formats[] =
        {V4L2_PIX_FMT_UYVY, V4L2_PIX_FMT_YUYV};
 
+/* CCDC Save/Restore context */
+static u32 ccdc_ctx[CCDC_REG_END / sizeof(u32)];
+
 /* register access routines */
 static inline u32 regr(u32 offset)
 {
@@ -400,7 +403,11 @@ void ccdc_config_ycbcr(void)
                 * configure the FID, VD, HD pin polarity,
                 * fld,hd pol positive, vd negative, 8-bit data
                 */
-               syn_mode |= CCDC_SYN_MODE_VD_POL_NEGATIVE | CCDC_SYN_MODE_8BITS;
+               syn_mode |= CCDC_SYN_MODE_VD_POL_NEGATIVE;
+               if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
+                       syn_mode |= CCDC_SYN_MODE_10BITS;
+               else
+                       syn_mode |= CCDC_SYN_MODE_8BITS;
        } else {
                /* y/c external sync mode */
                syn_mode |= (((params->fid_pol & CCDC_FID_POL_MASK) <<
@@ -419,8 +426,13 @@ void ccdc_config_ycbcr(void)
         * configure the order of y cb cr in SDRAM, and disable latch
         * internal register on vsync
         */
-       regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
-                CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
+       if (ccdc_cfg.if_type == VPFE_BT656_10BIT)
+               regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
+                       CCDC_LATCH_ON_VSYNC_DISABLE | CCDC_CCDCFG_BW656_10BIT,
+                       CCDC_CCDCFG);
+       else
+               regw((params->pix_order << CCDC_CCDCFG_Y8POS_SHIFT) |
+                       CCDC_LATCH_ON_VSYNC_DISABLE, CCDC_CCDCFG);
 
        /*
         * configure the horizontal line offset. This should be a
@@ -435,7 +447,6 @@ void ccdc_config_ycbcr(void)
 
        ccdc_sbl_reset();
        dev_dbg(ccdc_cfg.dev, "\nEnd of ccdc_config_ycbcr...\n");
-       ccdc_readregs();
 }
 
 static void ccdc_config_black_clamp(struct ccdc_black_clamp *bclamp)
@@ -827,6 +838,7 @@ static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
        case VPFE_BT656:
        case VPFE_YCBCR_SYNC_16:
        case VPFE_YCBCR_SYNC_8:
+       case VPFE_BT656_10BIT:
                ccdc_cfg.ycbcr.vd_pol = params->vdpol;
                ccdc_cfg.ycbcr.hd_pol = params->hdpol;
                break;
@@ -837,6 +849,87 @@ static int ccdc_set_hw_if_params(struct vpfe_hw_if_param *params)
        return 0;
 }
 
+static void ccdc_save_context(void)
+{
+       ccdc_ctx[CCDC_PCR >> 2] = regr(CCDC_PCR);
+       ccdc_ctx[CCDC_SYN_MODE >> 2] = regr(CCDC_SYN_MODE);
+       ccdc_ctx[CCDC_HD_VD_WID >> 2] = regr(CCDC_HD_VD_WID);
+       ccdc_ctx[CCDC_PIX_LINES >> 2] = regr(CCDC_PIX_LINES);
+       ccdc_ctx[CCDC_HORZ_INFO >> 2] = regr(CCDC_HORZ_INFO);
+       ccdc_ctx[CCDC_VERT_START >> 2] = regr(CCDC_VERT_START);
+       ccdc_ctx[CCDC_VERT_LINES >> 2] = regr(CCDC_VERT_LINES);
+       ccdc_ctx[CCDC_CULLING >> 2] = regr(CCDC_CULLING);
+       ccdc_ctx[CCDC_HSIZE_OFF >> 2] = regr(CCDC_HSIZE_OFF);
+       ccdc_ctx[CCDC_SDOFST >> 2] = regr(CCDC_SDOFST);
+       ccdc_ctx[CCDC_SDR_ADDR >> 2] = regr(CCDC_SDR_ADDR);
+       ccdc_ctx[CCDC_CLAMP >> 2] = regr(CCDC_CLAMP);
+       ccdc_ctx[CCDC_DCSUB >> 2] = regr(CCDC_DCSUB);
+       ccdc_ctx[CCDC_COLPTN >> 2] = regr(CCDC_COLPTN);
+       ccdc_ctx[CCDC_BLKCMP >> 2] = regr(CCDC_BLKCMP);
+       ccdc_ctx[CCDC_FPC >> 2] = regr(CCDC_FPC);
+       ccdc_ctx[CCDC_FPC_ADDR >> 2] = regr(CCDC_FPC_ADDR);
+       ccdc_ctx[CCDC_VDINT >> 2] = regr(CCDC_VDINT);
+       ccdc_ctx[CCDC_ALAW >> 2] = regr(CCDC_ALAW);
+       ccdc_ctx[CCDC_REC656IF >> 2] = regr(CCDC_REC656IF);
+       ccdc_ctx[CCDC_CCDCFG >> 2] = regr(CCDC_CCDCFG);
+       ccdc_ctx[CCDC_FMTCFG >> 2] = regr(CCDC_FMTCFG);
+       ccdc_ctx[CCDC_FMT_HORZ >> 2] = regr(CCDC_FMT_HORZ);
+       ccdc_ctx[CCDC_FMT_VERT >> 2] = regr(CCDC_FMT_VERT);
+       ccdc_ctx[CCDC_FMT_ADDR0 >> 2] = regr(CCDC_FMT_ADDR0);
+       ccdc_ctx[CCDC_FMT_ADDR1 >> 2] = regr(CCDC_FMT_ADDR1);
+       ccdc_ctx[CCDC_FMT_ADDR2 >> 2] = regr(CCDC_FMT_ADDR2);
+       ccdc_ctx[CCDC_FMT_ADDR3 >> 2] = regr(CCDC_FMT_ADDR3);
+       ccdc_ctx[CCDC_FMT_ADDR4 >> 2] = regr(CCDC_FMT_ADDR4);
+       ccdc_ctx[CCDC_FMT_ADDR5 >> 2] = regr(CCDC_FMT_ADDR5);
+       ccdc_ctx[CCDC_FMT_ADDR6 >> 2] = regr(CCDC_FMT_ADDR6);
+       ccdc_ctx[CCDC_FMT_ADDR7 >> 2] = regr(CCDC_FMT_ADDR7);
+       ccdc_ctx[CCDC_PRGEVEN_0 >> 2] = regr(CCDC_PRGEVEN_0);
+       ccdc_ctx[CCDC_PRGEVEN_1 >> 2] = regr(CCDC_PRGEVEN_1);
+       ccdc_ctx[CCDC_PRGODD_0 >> 2] = regr(CCDC_PRGODD_0);
+       ccdc_ctx[CCDC_PRGODD_1 >> 2] = regr(CCDC_PRGODD_1);
+       ccdc_ctx[CCDC_VP_OUT >> 2] = regr(CCDC_VP_OUT);
+}
+
+static void ccdc_restore_context(void)
+{
+       regw(ccdc_ctx[CCDC_SYN_MODE >> 2], CCDC_SYN_MODE);
+       regw(ccdc_ctx[CCDC_HD_VD_WID >> 2], CCDC_HD_VD_WID);
+       regw(ccdc_ctx[CCDC_PIX_LINES >> 2], CCDC_PIX_LINES);
+       regw(ccdc_ctx[CCDC_HORZ_INFO >> 2], CCDC_HORZ_INFO);
+       regw(ccdc_ctx[CCDC_VERT_START >> 2], CCDC_VERT_START);
+       regw(ccdc_ctx[CCDC_VERT_LINES >> 2], CCDC_VERT_LINES);
+       regw(ccdc_ctx[CCDC_CULLING >> 2], CCDC_CULLING);
+       regw(ccdc_ctx[CCDC_HSIZE_OFF >> 2], CCDC_HSIZE_OFF);
+       regw(ccdc_ctx[CCDC_SDOFST >> 2], CCDC_SDOFST);
+       regw(ccdc_ctx[CCDC_SDR_ADDR >> 2], CCDC_SDR_ADDR);
+       regw(ccdc_ctx[CCDC_CLAMP >> 2], CCDC_CLAMP);
+       regw(ccdc_ctx[CCDC_DCSUB >> 2], CCDC_DCSUB);
+       regw(ccdc_ctx[CCDC_COLPTN >> 2], CCDC_COLPTN);
+       regw(ccdc_ctx[CCDC_BLKCMP >> 2], CCDC_BLKCMP);
+       regw(ccdc_ctx[CCDC_FPC >> 2], CCDC_FPC);
+       regw(ccdc_ctx[CCDC_FPC_ADDR >> 2], CCDC_FPC_ADDR);
+       regw(ccdc_ctx[CCDC_VDINT >> 2], CCDC_VDINT);
+       regw(ccdc_ctx[CCDC_ALAW >> 2], CCDC_ALAW);
+       regw(ccdc_ctx[CCDC_REC656IF >> 2], CCDC_REC656IF);
+       regw(ccdc_ctx[CCDC_CCDCFG >> 2], CCDC_CCDCFG);
+       regw(ccdc_ctx[CCDC_FMTCFG >> 2], CCDC_FMTCFG);
+       regw(ccdc_ctx[CCDC_FMT_HORZ >> 2], CCDC_FMT_HORZ);
+       regw(ccdc_ctx[CCDC_FMT_VERT >> 2], CCDC_FMT_VERT);
+       regw(ccdc_ctx[CCDC_FMT_ADDR0 >> 2], CCDC_FMT_ADDR0);
+       regw(ccdc_ctx[CCDC_FMT_ADDR1 >> 2], CCDC_FMT_ADDR1);
+       regw(ccdc_ctx[CCDC_FMT_ADDR2 >> 2], CCDC_FMT_ADDR2);
+       regw(ccdc_ctx[CCDC_FMT_ADDR3 >> 2], CCDC_FMT_ADDR3);
+       regw(ccdc_ctx[CCDC_FMT_ADDR4 >> 2], CCDC_FMT_ADDR4);
+       regw(ccdc_ctx[CCDC_FMT_ADDR5 >> 2], CCDC_FMT_ADDR5);
+       regw(ccdc_ctx[CCDC_FMT_ADDR6 >> 2], CCDC_FMT_ADDR6);
+       regw(ccdc_ctx[CCDC_FMT_ADDR7 >> 2], CCDC_FMT_ADDR7);
+       regw(ccdc_ctx[CCDC_PRGEVEN_0 >> 2], CCDC_PRGEVEN_0);
+       regw(ccdc_ctx[CCDC_PRGEVEN_1 >> 2], CCDC_PRGEVEN_1);
+       regw(ccdc_ctx[CCDC_PRGODD_0 >> 2], CCDC_PRGODD_0);
+       regw(ccdc_ctx[CCDC_PRGODD_1 >> 2], CCDC_PRGODD_1);
+       regw(ccdc_ctx[CCDC_VP_OUT >> 2], CCDC_VP_OUT);
+       regw(ccdc_ctx[CCDC_PCR >> 2], CCDC_PCR);
+}
 static struct ccdc_hw_device ccdc_hw_dev = {
        .name = "DM6446 CCDC",
        .owner = THIS_MODULE,
@@ -945,10 +1038,40 @@ static int dm644x_ccdc_remove(struct platform_device *pdev)
        return 0;
 }
 
+static int dm644x_ccdc_suspend(struct device *dev)
+{
+       /* Save CCDC context */
+       ccdc_save_context();
+       /* Disable CCDC */
+       ccdc_enable(0);
+       /* Disable both master and slave clock */
+       clk_disable(ccdc_cfg.mclk);
+       clk_disable(ccdc_cfg.sclk);
+
+       return 0;
+}
+
+static int dm644x_ccdc_resume(struct device *dev)
+{
+       /* Enable both master and slave clock */
+       clk_enable(ccdc_cfg.mclk);
+       clk_enable(ccdc_cfg.sclk);
+       /* Restore CCDC context */
+       ccdc_restore_context();
+
+       return 0;
+}
+
+static const struct dev_pm_ops dm644x_ccdc_pm_ops = {
+       .suspend = dm644x_ccdc_suspend,
+       .resume = dm644x_ccdc_resume,
+};
+
 static struct platform_driver dm644x_ccdc_driver = {
        .driver = {
                .name   = "dm644x_ccdc",
                .owner = THIS_MODULE,
+               .pm = &dm644x_ccdc_pm_ops,
        },
        .remove = __devexit_p(dm644x_ccdc_remove),
        .probe = dm644x_ccdc_probe,
index 6e5d053..90370e4 100644 (file)
@@ -59,7 +59,7 @@
 #define CCDC_PRGODD_0                          0x8c
 #define CCDC_PRGODD_1                          0x90
 #define CCDC_VP_OUT                            0x94
-
+#define CCDC_REG_END                           0x98
 
 /***************************************************************
 *      Define for various register bit mask and shifts for CCDC
 #define CCDC_SYN_MODE_INPMOD_SHIFT             12
 #define CCDC_SYN_MODE_INPMOD_MASK              3
 #define CCDC_SYN_MODE_8BITS                    (7 << 8)
+#define CCDC_SYN_MODE_10BITS                   (6 << 8)
+#define CCDC_SYN_MODE_11BITS                   (5 << 8)
+#define CCDC_SYN_MODE_12BITS                   (4 << 8)
+#define CCDC_SYN_MODE_13BITS                   (3 << 8)
+#define CCDC_SYN_MODE_14BITS                   (2 << 8)
+#define CCDC_SYN_MODE_15BITS                   (1 << 8)
+#define CCDC_SYN_MODE_16BITS                   (0 << 8)
 #define CCDC_SYN_FLDMODE_MASK                  1
 #define CCDC_SYN_FLDMODE_SHIFT                 7
 #define CCDC_REC656IF_BT656_EN                 3
 #define CCDC_SYN_MODE_VD_POL_NEGATIVE          (1 << 2)
 #define CCDC_CCDCFG_Y8POS_SHIFT                        11
+#define CCDC_CCDCFG_BW656_10BIT                (1 << 5)
 #define CCDC_SDOFST_FIELD_INTERLEAVED          0x249
 #define CCDC_NO_CULLING                                0xffff00ff
 #endif
index f7b8893..aa69a46 100644 (file)
 
 /* gain - offset masks */
 #define GAIN_INTEGER_SHIFT                     9
-#define OFFSET_MASK                            0xFFF
+#define OFFSET_MASK                            0xFFF
 #define GAIN_SDRAM_EN_SHIFT                    12
 #define GAIN_IPIPE_EN_SHIFT                    13
 #define GAIN_H3A_EN_SHIFT                      14
index 398dbe7..1c25882 100644 (file)
@@ -475,6 +475,11 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe_dev)
        ret = ccdc_dev->hw_ops.open(vpfe_dev->pdev);
        if (!ret)
                vpfe_dev->initialized = 1;
+
+       /* Clear all VPFE/CCDC interrupts */
+       if (vpfe_dev->cfg->clr_intr)
+               vpfe_dev->cfg->clr_intr(-1);
+
 unlock:
        mutex_unlock(&ccdc_lock);
        return ret;
@@ -534,6 +539,16 @@ static void vpfe_schedule_next_buffer(struct vpfe_device *vpfe_dev)
        list_del(&vpfe_dev->next_frm->queue);
        vpfe_dev->next_frm->state = VIDEOBUF_ACTIVE;
        addr = videobuf_to_dma_contig(vpfe_dev->next_frm);
+
+       ccdc_dev->hw_ops.setfbaddr(addr);
+}
+
+static void vpfe_schedule_bottom_field(struct vpfe_device *vpfe_dev)
+{
+       unsigned long addr;
+
+       addr = videobuf_to_dma_contig(vpfe_dev->cur_frm);
+       addr += vpfe_dev->field_off;
        ccdc_dev->hw_ops.setfbaddr(addr);
 }
 
@@ -554,7 +569,6 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
 {
        struct vpfe_device *vpfe_dev = dev_id;
        enum v4l2_field field;
-       unsigned long addr;
        int fid;
 
        v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "\nStarting vpfe_isr...\n");
@@ -562,7 +576,7 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
 
        /* if streaming not started, don't do anything */
        if (!vpfe_dev->started)
-               return IRQ_HANDLED;
+               goto clear_intr;
 
        /* only for 6446 this will be applicable */
        if (NULL != ccdc_dev->hw_ops.reset)
@@ -574,7 +588,7 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
                        "frame format is progressive...\n");
                if (vpfe_dev->cur_frm != vpfe_dev->next_frm)
                        vpfe_process_buffer_complete(vpfe_dev);
-               return IRQ_HANDLED;
+               goto clear_intr;
        }
 
        /* interlaced or TB capture check which field we are in hardware */
@@ -599,12 +613,9 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
                         * the CCDC memory address
                         */
                        if (field == V4L2_FIELD_SEQ_TB) {
-                               addr =
-                                 videobuf_to_dma_contig(vpfe_dev->cur_frm);
-                               addr += vpfe_dev->field_off;
-                               ccdc_dev->hw_ops.setfbaddr(addr);
+                               vpfe_schedule_bottom_field(vpfe_dev);
                        }
-                       return IRQ_HANDLED;
+                       goto clear_intr;
                }
                /*
                 * if one field is just being captured configure
@@ -624,6 +635,10 @@ static irqreturn_t vpfe_isr(int irq, void *dev_id)
                 */
                vpfe_dev->field_id = fid;
        }
+clear_intr:
+       if (vpfe_dev->cfg->clr_intr)
+               vpfe_dev->cfg->clr_intr(irq);
+
        return IRQ_HANDLED;
 }
 
@@ -635,8 +650,11 @@ static irqreturn_t vdint1_isr(int irq, void *dev_id)
        v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "\nInside vdint1_isr...\n");
 
        /* if streaming not started, don't do anything */
-       if (!vpfe_dev->started)
+       if (!vpfe_dev->started) {
+               if (vpfe_dev->cfg->clr_intr)
+                       vpfe_dev->cfg->clr_intr(irq);
                return IRQ_HANDLED;
+       }
 
        spin_lock(&vpfe_dev->dma_queue_lock);
        if ((vpfe_dev->fmt.fmt.pix.field == V4L2_FIELD_NONE) &&
@@ -644,6 +662,10 @@ static irqreturn_t vdint1_isr(int irq, void *dev_id)
            vpfe_dev->cur_frm == vpfe_dev->next_frm)
                vpfe_schedule_next_buffer(vpfe_dev);
        spin_unlock(&vpfe_dev->dma_queue_lock);
+
+       if (vpfe_dev->cfg->clr_intr)
+               vpfe_dev->cfg->clr_intr(irq);
+
        return IRQ_HANDLED;
 }
 
@@ -714,7 +736,7 @@ static int vpfe_release(struct file *file)
        /* Decrement device usrs counter */
        vpfe_dev->usrs--;
        /* Close the priority */
-       v4l2_prio_close(&vpfe_dev->prio, &fh->prio);
+       v4l2_prio_close(&vpfe_dev->prio, fh->prio);
        /* If this is the last file handle */
        if (!vpfe_dev->usrs) {
                vpfe_dev->initialized = 0;
@@ -1218,7 +1240,10 @@ static int vpfe_videobuf_setup(struct videobuf_queue *vq,
        struct vpfe_device *vpfe_dev = fh->vpfe_dev;
 
        v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_setup\n");
-       *size = config_params.device_bufsize;
+       *size = vpfe_dev->fmt.fmt.pix.sizeimage;
+       if (vpfe_dev->memory == V4L2_MEMORY_MMAP &&
+               vpfe_dev->fmt.fmt.pix.sizeimage > config_params.device_bufsize)
+               *size = config_params.device_bufsize;
 
        if (*count < config_params.min_numbuffers)
                *count = config_params.min_numbuffers;
@@ -1233,6 +1258,8 @@ static int vpfe_videobuf_prepare(struct videobuf_queue *vq,
 {
        struct vpfe_fh *fh = vq->priv_data;
        struct vpfe_device *vpfe_dev = fh->vpfe_dev;
+       unsigned long addr;
+       int ret;
 
        v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_buffer_prepare\n");
 
@@ -1242,8 +1269,18 @@ static int vpfe_videobuf_prepare(struct videobuf_queue *vq,
                vb->height = vpfe_dev->fmt.fmt.pix.height;
                vb->size = vpfe_dev->fmt.fmt.pix.sizeimage;
                vb->field = field;
+
+               ret = videobuf_iolock(vq, vb, NULL);;
+               if (ret < 0)
+                       return ret;
+
+               addr = videobuf_to_dma_contig(vb);
+               /* Make sure user addresses are aligned to 32 bytes */
+               if (!ALIGN(addr, 32))
+                       return -EINVAL;
+
+               vb->state = VIDEOBUF_PREPARED;
        }
-       vb->state = VIDEOBUF_PREPARED;
        return 0;
 }
 
@@ -1311,13 +1348,6 @@ static int vpfe_reqbufs(struct file *file, void *priv,
                return -EINVAL;
        }
 
-       if (V4L2_MEMORY_USERPTR == req_buf->memory) {
-               /* we don't support user ptr IO */
-               v4l2_dbg(1, debug, &vpfe_dev->v4l2_dev, "vpfe_reqbufs:"
-                        " USERPTR IO not supported\n");
-               return  -EINVAL;
-       }
-
        ret = mutex_lock_interruptible(&vpfe_dev->lock);
        if (ret)
                return ret;
@@ -1831,7 +1861,6 @@ static __init int vpfe_probe(struct platform_device *pdev)
                goto probe_free_dev_mem;
        }
 
-       mutex_lock(&ccdc_lock);
        /* Allocate memory for ccdc configuration */
        ccdc_cfg = kmalloc(sizeof(struct ccdc_config), GFP_KERNEL);
        if (NULL == ccdc_cfg) {
@@ -1840,6 +1869,8 @@ static __init int vpfe_probe(struct platform_device *pdev)
                goto probe_free_lock;
        }
 
+       mutex_lock(&ccdc_lock);
+
        strncpy(ccdc_cfg->name, vpfe_cfg->ccdc, 32);
        /* Get VINT0 irq resource */
        res1 = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -2015,18 +2046,14 @@ static int __devexit vpfe_remove(struct platform_device *pdev)
        return 0;
 }
 
-static int
-vpfe_suspend(struct device *dev)
+static int vpfe_suspend(struct device *dev)
 {
-       /* add suspend code here later */
-       return -1;
+       return 0;
 }
 
-static int
-vpfe_resume(struct device *dev)
+static int vpfe_resume(struct device *dev)
 {
-       /* add resume code here later */
-       return -1;
+       return 0;
 }
 
 static const struct dev_pm_ops vpfe_dev_pm_ops = {
index 2e5a7fb..a7f48b5 100644 (file)
@@ -869,7 +869,7 @@ static int vpif_release(struct file *filep)
        mutex_unlock(&common->lock);
 
        /* Close the priority */
-       v4l2_prio_close(&ch->prio, &fh->prio);
+       v4l2_prio_close(&ch->prio, fh->prio);
 
        if (fh->initialized)
                ch->initialized = 0;
@@ -1444,7 +1444,7 @@ static int vpif_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
                }
        }
 
-       ret = v4l2_prio_check(&ch->prio, &fh->prio);
+       ret = v4l2_prio_check(&ch->prio, fh->prio);
        if (0 != ret)
                return ret;
 
@@ -1554,7 +1554,7 @@ static int vpif_s_input(struct file *file, void *priv, unsigned int index)
                }
        }
 
-       ret = v4l2_prio_check(&ch->prio, &fh->prio);
+       ret = v4l2_prio_check(&ch->prio, fh->prio);
        if (0 != ret)
                return ret;
 
@@ -1710,7 +1710,7 @@ static int vpif_s_fmt_vid_cap(struct file *file, void *priv,
                }
        }
 
-       ret = v4l2_prio_check(&ch->prio, &fh->prio);
+       ret = v4l2_prio_check(&ch->prio, fh->prio);
        if (0 != ret)
                return ret;
 
index 13c3a1b..da07607 100644 (file)
@@ -384,7 +384,7 @@ static int vpif_get_std_info(struct channel_obj *ch)
        int index;
 
        std_info->stdid = vid_ch->stdid;
-       if (!std_info)
+       if (!std_info->stdid)
                return -1;
 
        for (index = 0; index < ARRAY_SIZE(ch_params); index++) {
@@ -671,7 +671,7 @@ static int vpif_release(struct file *filep)
                ch->initialized = 0;
 
        /* Close the priority */
-       v4l2_prio_close(&ch->prio, &fh->prio);
+       v4l2_prio_close(&ch->prio, fh->prio);
        filep->private_data = NULL;
        fh->initialized = 0;
        kfree(fh);
@@ -753,7 +753,7 @@ static int vpif_s_fmt_vid_out(struct file *file, void *priv,
                }
 
                /* Check for the priority */
-               ret = v4l2_prio_check(&ch->prio, &fh->prio);
+               ret = v4l2_prio_check(&ch->prio, fh->prio);
                if (0 != ret)
                        return ret;
                fh->initialized = 1;
index bd78338..e182abf 100644 (file)
@@ -491,7 +491,7 @@ static int em28xx_audio_init(struct em28xx *dev)
        strcpy(pcm->name, "Empia 28xx Capture");
 
        snd_card_set_dev(card, &dev->udev->dev);
-       strcpy(card->driver, "Empia Em28xx Audio");
+       strcpy(card->driver, "Em28xx-Audio");
        strcpy(card->shortname, "Em28xx Audio");
        strcpy(card->longname, "Empia Em28xx Audio");
 
index b0fb083..3a4fd85 100644 (file)
@@ -602,7 +602,7 @@ struct em28xx_board em28xx_boards[] = {
                .name         = "Gadmei UTV330+",
                .tuner_type   = TUNER_TNF_5335MF,
                .tda9887_conf = TDA9887_PRESENT,
-               .ir_codes     = &ir_codes_gadmei_rm008z_table,
+               .ir_codes     = RC_MAP_GADMEI_RM008Z,
                .decoder      = EM28XX_SAA711X,
                .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ,
                .input        = { {
@@ -681,6 +681,20 @@ struct em28xx_board em28xx_boards[] = {
                        .amux     = EM28XX_AMUX_LINE_IN,
                } },
        },
+       [EM2860_BOARD_TVP5150_REFERENCE_DESIGN] = {
+               .name          = "EM2860/TVP5150 Reference Design",
+               .tuner_type    = TUNER_ABSENT,  /* Capture only device */
+               .decoder       = EM28XX_TVP5150,
+               .input         = { {
+                       .type     = EM28XX_VMUX_COMPOSITE1,
+                       .vmux     = TVP5150_COMPOSITE1,
+                       .amux     = EM28XX_AMUX_LINE_IN,
+               }, {
+                       .type     = EM28XX_VMUX_SVIDEO,
+                       .vmux     = TVP5150_SVIDEO,
+                       .amux     = EM28XX_AMUX_LINE_IN,
+               } },
+       },
        [EM2861_BOARD_PLEXTOR_PX_TV100U] = {
                .name         = "Plextor ConvertX PX-TV100U",
                .tuner_type   = TUNER_TNF_5335MF,
@@ -777,7 +791,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware = 1,
                .has_dvb      = 1,
                .dvb_gpio     = hauppauge_wintv_hvr_900_digital,
-               .ir_codes     = &ir_codes_hauppauge_new_table,
+               .ir_codes     = RC_MAP_HAUPPAUGE_NEW,
                .decoder      = EM28XX_TVP5150,
                .input        = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -802,7 +816,7 @@ struct em28xx_board em28xx_boards[] = {
                .tuner_type   = TUNER_XC2028,
                .tuner_gpio   = default_tuner_gpio,
                .mts_firmware = 1,
-               .ir_codes     = &ir_codes_hauppauge_new_table,
+               .ir_codes     = RC_MAP_HAUPPAUGE_NEW,
                .decoder      = EM28XX_TVP5150,
                .input        = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -828,7 +842,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware   = 1,
                .has_dvb        = 1,
                .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
-               .ir_codes       = &ir_codes_hauppauge_new_table,
+               .ir_codes       = RC_MAP_HAUPPAUGE_NEW,
                .decoder        = EM28XX_TVP5150,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -854,7 +868,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware   = 1,
                .has_dvb        = 1,
                .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
-               .ir_codes       = &ir_codes_rc5_hauppauge_new_table,
+               .ir_codes       = RC_MAP_RC5_HAUPPAUGE_NEW,
                .decoder        = EM28XX_TVP5150,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -880,7 +894,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware   = 1,
                .has_dvb        = 1,
                .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
-               .ir_codes       = &ir_codes_pinnacle_pctv_hd_table,
+               .ir_codes       = RC_MAP_PINNACLE_PCTV_HD,
                .decoder        = EM28XX_TVP5150,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -906,7 +920,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware   = 1,
                .has_dvb        = 1,
                .dvb_gpio       = hauppauge_wintv_hvr_900_digital,
-               .ir_codes       = &ir_codes_ati_tv_wonder_hd_600_table,
+               .ir_codes       = RC_MAP_ATI_TV_WONDER_HD_600,
                .decoder        = EM28XX_TVP5150,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -932,7 +946,7 @@ struct em28xx_board em28xx_boards[] = {
                .decoder        = EM28XX_TVP5150,
                .has_dvb        = 1,
                .dvb_gpio       = default_digital,
-               .ir_codes       = &ir_codes_terratec_cinergy_xs_table,
+               .ir_codes       = RC_MAP_TERRATEC_CINERGY_XS,
                .xclk           = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -1282,7 +1296,7 @@ struct em28xx_board em28xx_boards[] = {
                .decoder        = EM28XX_SAA711X,
                .has_dvb        = 1,
                .dvb_gpio       = em2882_kworld_315u_digital,
-               .ir_codes       = &ir_codes_kworld_315u_table,
+               .ir_codes       = RC_MAP_KWORLD_315U,
                .xclk           = EM28XX_XCLK_FREQUENCY_12MHZ,
                .i2c_speed      = EM28XX_I2C_CLK_WAIT_ENABLE,
                /* Analog mode - still not ready */
@@ -1404,10 +1418,14 @@ struct em28xx_board em28xx_boards[] = {
        },
        [EM2882_BOARD_KWORLD_VS_DVBT] = {
                .name         = "Kworld VS-DVB-T 323UR",
-               .valid        = EM28XX_BOARD_NOT_VALIDATED,
                .tuner_type   = TUNER_XC2028,
                .tuner_gpio   = default_tuner_gpio,
                .decoder      = EM28XX_TVP5150,
+               .mts_firmware = 1,
+               .has_dvb      = 1,
+               .dvb_gpio     = kworld_330u_digital,
+               .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ, /* NEC IR */
+               .ir_codes     = RC_MAP_KWORLD_315U,
                .input        = { {
                        .type     = EM28XX_VMUX_TELEVISION,
                        .vmux     = TVP5150_COMPOSITE0,
@@ -1430,7 +1448,7 @@ struct em28xx_board em28xx_boards[] = {
                .decoder      = EM28XX_TVP5150,
                .has_dvb      = 1,
                .dvb_gpio     = hauppauge_wintv_hvr_900_digital,
-               .ir_codes     = &ir_codes_terratec_cinergy_xs_table,
+               .ir_codes     = RC_MAP_TERRATEC_CINERGY_XS,
                .xclk         = EM28XX_XCLK_FREQUENCY_12MHZ,
                .input        = { {
                        .type     = EM28XX_VMUX_TELEVISION,
@@ -1523,7 +1541,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware = 1,
                .decoder      = EM28XX_TVP5150,
                .tuner_gpio   = default_tuner_gpio,
-               .ir_codes     = &ir_codes_kaiomy_table,
+               .ir_codes     = RC_MAP_KAIOMY,
                .input          = { {
                        .type     = EM28XX_VMUX_TELEVISION,
                        .vmux     = TVP5150_COMPOSITE0,
@@ -1623,7 +1641,7 @@ struct em28xx_board em28xx_boards[] = {
                .mts_firmware = 1,
                .has_dvb      = 1,
                .dvb_gpio     = evga_indtube_digital,
-               .ir_codes     = &ir_codes_evga_indtube_table,
+               .ir_codes     = RC_MAP_EVGA_INDTUBE,
                .input        = { {
                        .type     = EM28XX_VMUX_TELEVISION,
                        .vmux     = TVP5150_COMPOSITE0,
@@ -1672,6 +1690,8 @@ struct usb_device_id em28xx_id_table[] = {
                        .driver_info = EM2820_BOARD_UNKNOWN },
        { USB_DEVICE(0xeb1a, 0x2862),
                        .driver_info = EM2820_BOARD_UNKNOWN },
+       { USB_DEVICE(0xeb1a, 0x2863),
+                       .driver_info = EM2820_BOARD_UNKNOWN },
        { USB_DEVICE(0xeb1a, 0x2870),
                        .driver_info = EM2820_BOARD_UNKNOWN },
        { USB_DEVICE(0xeb1a, 0x2881),
@@ -1792,6 +1812,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
        {0xb06a32c3, EM2800_BOARD_TERRATEC_CINERGY_200, TUNER_LG_PAL_NEW_TAPC},
        {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
        {0x1ba50080, EM2860_BOARD_SAA711X_REFERENCE_DESIGN, TUNER_ABSENT},
+       {0x77800080, EM2860_BOARD_TVP5150_REFERENCE_DESIGN, TUNER_ABSENT},
        {0xc51200e3, EM2820_BOARD_GADMEI_TVR200, TUNER_LG_PAL_NEW_TAPC},
        {0x4ba50080, EM2861_BOARD_GADMEI_UTV330PLUS, TUNER_TNF_5335MF},
 };
@@ -2138,6 +2159,7 @@ static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
                break;
        case EM2883_BOARD_KWORLD_HYBRID_330U:
        case EM2882_BOARD_DIKOM_DK300:
+       case EM2882_BOARD_KWORLD_VS_DVBT:
                ctl->demod = XC3028_FE_CHINA;
                ctl->fname = XC2028_DEFAULT_FIRMWARE;
                break;
@@ -2313,21 +2335,21 @@ void em28xx_register_i2c_ir(struct em28xx *dev)
        switch (dev->model) {
        case EM2800_BOARD_TERRATEC_CINERGY_200:
        case EM2820_BOARD_TERRATEC_CINERGY_250:
-               dev->init_data.ir_codes = &ir_codes_em_terratec_table;
+               dev->init_data.ir_codes = RC_MAP_EM_TERRATEC;
                dev->init_data.get_key = em28xx_get_key_terratec;
                dev->init_data.name = "i2c IR (EM28XX Terratec)";
                break;
        case EM2820_BOARD_PINNACLE_USB_2:
-               dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
+               dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
                dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
                dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
                break;
        case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
-               dev->init_data.ir_codes = &ir_codes_rc5_hauppauge_new_table;
+               dev->init_data.ir_codes = RC_MAP_RC5_HAUPPAUGE_NEW;
                dev->init_data.get_key = em28xx_get_key_em_haup;
                dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
        case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
-               dev->init_data.ir_codes = &ir_codes_winfast_usbii_deluxe_table;;
+               dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;;
                dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
                dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
                break;
index a41cc55..d3813ed 100644 (file)
@@ -782,11 +782,15 @@ int em28xx_resolution_set(struct em28xx *dev)
 
        em28xx_accumulator_set(dev, 1, (width - 4) >> 2, 1, (height - 4) >> 2);
 
-       /* If we don't set the start position to 4 in VBI mode, we end up
-          with line 21 being YUYV encoded instead of being in 8-bit
-          greyscale */
+       /* If we don't set the start position to 2 in VBI mode, we end up
+          with line 20/21 being YUYV encoded instead of being in 8-bit
+          greyscale.  The core of the issue is that line 21 (and line 23 for
+          PAL WSS) are inside of active video region, and as a result they
+          get the pixelformatting associated with that area.  So by cropping
+          it out, we end up with the same format as the rest of the VBI
+          region */
        if (em28xx_vbi_supported(dev) == 1)
-               em28xx_capture_area_set(dev, 0, 4, width >> 2, height >> 2);
+               em28xx_capture_area_set(dev, 0, 2, width >> 2, height >> 2);
        else
                em28xx_capture_area_set(dev, 0, 0, width >> 2, height >> 2);
 
@@ -1174,21 +1178,18 @@ void em28xx_add_into_devlist(struct em28xx *dev)
  */
 
 static LIST_HEAD(em28xx_extension_devlist);
-static DEFINE_MUTEX(em28xx_extension_devlist_lock);
 
 int em28xx_register_extension(struct em28xx_ops *ops)
 {
        struct em28xx *dev = NULL;
 
        mutex_lock(&em28xx_devlist_mutex);
-       mutex_lock(&em28xx_extension_devlist_lock);
        list_add_tail(&ops->next, &em28xx_extension_devlist);
        list_for_each_entry(dev, &em28xx_devlist, devlist) {
                if (dev)
                        ops->init(dev);
        }
        printk(KERN_INFO "Em28xx: Initialized (%s) extension\n", ops->name);
-       mutex_unlock(&em28xx_extension_devlist_lock);
        mutex_unlock(&em28xx_devlist_mutex);
        return 0;
 }
@@ -1204,10 +1205,8 @@ void em28xx_unregister_extension(struct em28xx_ops *ops)
                        ops->fini(dev);
        }
 
-       mutex_lock(&em28xx_extension_devlist_lock);
        printk(KERN_INFO "Em28xx: Removed (%s) extension\n", ops->name);
        list_del(&ops->next);
-       mutex_unlock(&em28xx_extension_devlist_lock);
        mutex_unlock(&em28xx_devlist_mutex);
 }
 EXPORT_SYMBOL(em28xx_unregister_extension);
@@ -1216,26 +1215,26 @@ void em28xx_init_extension(struct em28xx *dev)
 {
        struct em28xx_ops *ops = NULL;
 
-       mutex_lock(&em28xx_extension_devlist_lock);
+       mutex_lock(&em28xx_devlist_mutex);
        if (!list_empty(&em28xx_extension_devlist)) {
                list_for_each_entry(ops, &em28xx_extension_devlist, next) {
                        if (ops->init)
                                ops->init(dev);
                }
        }
-       mutex_unlock(&em28xx_extension_devlist_lock);
+       mutex_unlock(&em28xx_devlist_mutex);
 }
 
 void em28xx_close_extension(struct em28xx *dev)
 {
        struct em28xx_ops *ops = NULL;
 
-       mutex_lock(&em28xx_extension_devlist_lock);
+       mutex_lock(&em28xx_devlist_mutex);
        if (!list_empty(&em28xx_extension_devlist)) {
                list_for_each_entry(ops, &em28xx_extension_devlist, next) {
                        if (ops->fini)
                                ops->fini(dev);
                }
        }
-       mutex_unlock(&em28xx_extension_devlist_lock);
+       mutex_unlock(&em28xx_devlist_mutex);
 }
index bcd3c37..cf1d8c3 100644 (file)
@@ -467,6 +467,7 @@ static int dvb_init(struct em28xx *dev)
        }
        dev->dvb = dvb;
 
+       mutex_lock(&dev->lock);
        em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
        /* init frontend */
        switch (dev->model) {
@@ -506,6 +507,7 @@ static int dvb_init(struct em28xx *dev)
        case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
        case EM2881_BOARD_PINNACLE_HYBRID_PRO:
        case EM2882_BOARD_DIKOM_DK300:
+       case EM2882_BOARD_KWORLD_VS_DVBT:
                dvb->frontend = dvb_attach(zl10353_attach,
                                           &em28xx_zl10353_xc3028_no_i2c_gate,
                                           &dev->i2c_adap);
@@ -589,15 +591,16 @@ static int dvb_init(struct em28xx *dev)
        if (result < 0)
                goto out_free;
 
-       em28xx_set_mode(dev, EM28XX_SUSPEND);
        em28xx_info("Successfully loaded em28xx-dvb\n");
-       return 0;
+ret:
+       em28xx_set_mode(dev, EM28XX_SUSPEND);
+       mutex_unlock(&dev->lock);
+       return result;
 
 out_free:
-       em28xx_set_mode(dev, EM28XX_SUSPEND);
        kfree(dvb);
        dev->dvb = NULL;
-       return result;
+       goto ret;
 }
 
 static int dvb_fini(struct em28xx *dev)
index 20a0001..5c3fd94 100644 (file)
@@ -39,6 +39,8 @@ static unsigned int ir_debug;
 module_param(ir_debug, int, 0644);
 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
 
+#define MODULE_NAME "em28xx"
+
 #define i2cdprintk(fmt, arg...) \
        if (ir_debug) { \
                printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
@@ -360,14 +362,20 @@ static void em28xx_ir_work(struct work_struct *work)
        schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
 }
 
-static void em28xx_ir_start(struct em28xx_IR *ir)
+static int em28xx_ir_start(void *priv)
 {
+       struct em28xx_IR *ir = priv;
+
        INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
        schedule_delayed_work(&ir->work, 0);
+
+       return 0;
 }
 
-static void em28xx_ir_stop(struct em28xx_IR *ir)
+static void em28xx_ir_stop(void *priv)
 {
+       struct em28xx_IR *ir = priv;
+
        cancel_delayed_work_sync(&ir->work);
 }
 
@@ -380,7 +388,6 @@ int em28xx_ir_change_protocol(void *priv, u64 ir_type)
 
        /* Adjust xclk based o IR table for RC5/NEC tables */
 
-       dev->board.ir_codes->ir_type = IR_TYPE_OTHER;
        if (ir_type == IR_TYPE_RC5) {
                dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
                ir->full_code = 1;
@@ -388,11 +395,9 @@ int em28xx_ir_change_protocol(void *priv, u64 ir_type)
                dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
                ir_config = EM2874_IR_NEC;
                ir->full_code = 1;
-       } else
+       } else if (ir_type != IR_TYPE_UNKNOWN)
                rc = -EINVAL;
 
-       dev->board.ir_codes->ir_type = ir_type;
-
        em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
                              EM28XX_XCLK_IR_RC5_MODE);
 
@@ -443,6 +448,13 @@ int em28xx_ir_init(struct em28xx *dev)
        ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
        ir->props.priv = ir;
        ir->props.change_protocol = em28xx_ir_change_protocol;
+       ir->props.open = em28xx_ir_start;
+       ir->props.close = em28xx_ir_stop;
+
+       /* By default, keep protocol field untouched */
+       err = em28xx_ir_change_protocol(ir, IR_TYPE_UNKNOWN);
+       if (err)
+               goto err_out_free;
 
        /* This is how often we ask the chip for IR information */
        ir->polling = 100; /* ms */
@@ -455,7 +467,6 @@ int em28xx_ir_init(struct em28xx *dev)
        strlcat(ir->phys, "/input0", sizeof(ir->phys));
 
        /* Set IR protocol */
-       em28xx_ir_change_protocol(ir, dev->board.ir_codes->ir_type);
        err = ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER);
        if (err < 0)
                goto err_out_free;
@@ -470,17 +481,15 @@ int em28xx_ir_init(struct em28xx *dev)
        input_dev->dev.parent = &dev->udev->dev;
 
 
-       em28xx_ir_start(ir);
 
        /* all done */
        err = ir_input_register(ir->input, dev->board.ir_codes,
-                               &ir->props);
+                               &ir->props, MODULE_NAME);
        if (err)
                goto err_out_stop;
 
        return 0;
  err_out_stop:
-       em28xx_ir_stop(ir);
        dev->ir = NULL;
  err_out_free:
        kfree(ir);
index 0fe2011..20090e3 100644 (file)
@@ -203,12 +203,6 @@ static void em28xx_copy_video(struct em28xx *dev,
        if (dma_q->pos + len > buf->vb.size)
                len = buf->vb.size - dma_q->pos;
 
-       if (p[0] != 0x88 && p[0] != 0x22) {
-               em28xx_isocdbg("frame is not complete\n");
-               len += 4;
-       } else
-               p += 4;
-
        startread = p;
        remain = len;
 
@@ -309,14 +303,6 @@ static void em28xx_copy_vbi(struct em28xx *dev,
        if (dma_q->pos + len > buf->vb.size)
                len = buf->vb.size - dma_q->pos;
 
-       if ((p[0] == 0x33 && p[1] == 0x95) ||
-           (p[0] == 0x88 && p[1] == 0x88)) {
-               /* Header field, advance past it */
-               p += 4;
-       } else {
-               len += 4;
-       }
-
        startread = p;
 
        startwrite = outp + dma_q->pos;
@@ -507,8 +493,15 @@ static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
 
                        dma_q->pos = 0;
                }
-               if (buf != NULL)
+               if (buf != NULL) {
+                       if (p[0] != 0x88 && p[0] != 0x22) {
+                               em28xx_isocdbg("frame is not complete\n");
+                               len += 4;
+                       } else {
+                               p += 4;
+                       }
                        em28xx_copy_video(dev, dma_q, buf, p, outp, len);
+               }
        }
        return rc;
 }
@@ -555,8 +548,7 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
                                continue;
                }
 
-               len = urb->iso_frame_desc[i].actual_length - 4;
-
+               len = urb->iso_frame_desc[i].actual_length;
                if (urb->iso_frame_desc[i].actual_length <= 0) {
                        /* em28xx_isocdbg("packet %d is empty",i); - spammy */
                        continue;
@@ -577,6 +569,17 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
                        dev->vbi_read = 0;
                        em28xx_isocdbg("VBI START HEADER!!!\n");
                        dev->cur_field = p[2];
+                       p += 4;
+                       len -= 4;
+               } else if (p[0] == 0x88 && p[1] == 0x88 &&
+                          p[2] == 0x88 && p[3] == 0x88) {
+                       /* continuation */
+                       p += 4;
+                       len -= 4;
+               } else if (p[0] == 0x22 && p[1] == 0x5a) {
+                       /* start video */
+                       p += 4;
+                       len -= 4;
                }
 
                vbi_size = dev->vbi_width * dev->vbi_height;
@@ -631,9 +634,6 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
 
                if (dev->capture_type == 1) {
                        dev->capture_type = 2;
-                       em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
-                                      len, (p[2] & 1) ? "odd" : "even");
-
                        if (dev->progressive || !(dev->cur_field & 1)) {
                                if (buf != NULL)
                                        buffer_filled(dev, dma_q, buf);
@@ -652,8 +652,25 @@ static inline int em28xx_isoc_copy_vbi(struct em28xx *dev, struct urb *urb)
 
                        dma_q->pos = 0;
                }
-               if (buf != NULL && dev->capture_type == 2)
-                       em28xx_copy_video(dev, dma_q, buf, p, outp, len);
+
+               if (buf != NULL && dev->capture_type == 2) {
+                       if (len > 4 && p[0] == 0x88 && p[1] == 0x88 &&
+                           p[2] == 0x88 && p[3] == 0x88) {
+                               p += 4;
+                               len -= 4;
+                       }
+                       if (len > 4 && p[0] == 0x22 && p[1] == 0x5a) {
+                               em28xx_isocdbg("Video frame %d, len=%i, %s\n",
+                                              p[2], len, (p[2] & 1) ?
+                                              "odd" : "even");
+                               p += 4;
+                               len -= 4;
+                       }
+
+                       if (len > 0)
+                               em28xx_copy_video(dev, dma_q, buf, p, outp,
+                                                 len);
+               }
        }
        return rc;
 }
@@ -1483,6 +1500,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
                return -EINVAL;
 
        strcpy(t->name, "Tuner");
+       t->type = V4L2_TUNER_ANALOG_TV;
 
        mutex_lock(&dev->lock);
        v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t);
@@ -1814,7 +1832,7 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv,
        mutex_lock(&dev->lock);
 
        f->fmt.sliced.service_set = 0;
-       v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
 
        if (f->fmt.sliced.service_set == 0)
                rc = -EINVAL;
@@ -1836,7 +1854,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv,
                return rc;
 
        mutex_lock(&dev->lock);
-       v4l2_device_call_all(&dev->v4l2_dev, 0, video, g_fmt, f);
+       v4l2_device_call_all(&dev->v4l2_dev, 0, vbi, g_sliced_fmt, &f->fmt.sliced);
        mutex_unlock(&dev->lock);
 
        if (f->fmt.sliced.service_set == 0)
index ba6fe5d..b252d1b 100644 (file)
@@ -68,6 +68,7 @@
 #define EM2820_BOARD_HERCULES_SMART_TV_USB2      26
 #define EM2820_BOARD_PINNACLE_USB_2_FM1216ME     27
 #define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
+#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN    29
 #define EM2820_BOARD_VIDEOLOGY_20K14XUSB         30
 #define EM2821_BOARD_USBGEAR_VD204               31
 #define EM2821_BOARD_SUPERCOMP_USB_2             32
 #define EM28XX_NUM_BUFS 5
 
 /* number of packets for each buffer
-   windows requests only 40 packets .. so we better do the same
+   windows requests only 64 packets .. so we better do the same
    this is what I found out for all alternate numbers there!
  */
-#define EM28XX_NUM_PACKETS 40
+#define EM28XX_NUM_PACKETS 64
 
 #define EM28XX_INTERLACED_DEFAULT 1
 
@@ -411,7 +412,7 @@ struct em28xx_board {
 
        struct em28xx_input       input[MAX_EM28XX_INPUT];
        struct em28xx_input       radio;
-       struct ir_scancode_table  *ir_codes;
+       char                      *ir_codes;
 };
 
 struct em28xx_eeprom {
index e6c23d5..a5cfc76 100644 (file)
@@ -1713,7 +1713,7 @@ et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg)
        if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                return -EFAULT;
 
-       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
+       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) {
                if (ctrl.id == s->qctrl[i].id) {
                        if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
                                return -EINVAL;
@@ -1723,7 +1723,9 @@ et61x251_vidioc_s_ctrl(struct et61x251_device* cam, void __user * arg)
                        ctrl.value -= ctrl.value % s->qctrl[i].step;
                        break;
                }
-
+       }
+       if (i == ARRAY_SIZE(s->qctrl))
+               return -EINVAL;
        if ((err = s->set_ctrl(cam, &ctrl)))
                return err;
 
diff --git a/drivers/media/video/font.h b/drivers/media/video/font.h
deleted file mode 100644 (file)
index 8b1fecc..0000000
+++ /dev/null
@@ -1,407 +0,0 @@
-static unsigned char rom8x16_bits[] = {
-/* Character 0 (0x30):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |**   ** |
-   |**  *** |
-   |** **** |
-   |**** ** |
-   |***  ** |
-   |**   ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0xc6,
-0xce,
-0xde,
-0xf6,
-0xe6,
-0xc6,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 1 (0x31):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   |   **   |
-   | ****   |
-   |   **   |
-   |   **   |
-   |   **   |
-   |   **   |
-   |   **   |
-   |   **   |
-   |   **   |
-   | ****** |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x18,
-0x78,
-0x18,
-0x18,
-0x18,
-0x18,
-0x18,
-0x18,
-0x18,
-0x7e,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 2 (0x32):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |**   ** |
-   |     ** |
-   |    **  |
-   |   **   |
-   |  **    |
-   | **     |
-   |**   ** |
-   |******* |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0xc6,
-0x06,
-0x0c,
-0x18,
-0x30,
-0x60,
-0xc6,
-0xfe,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 3 (0x33):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |     ** |
-   |     ** |
-   |  ****  |
-   |     ** |
-   |     ** |
-   |     ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0x06,
-0x06,
-0x3c,
-0x06,
-0x06,
-0x06,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 4 (0x34):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   |    **  |
-   |   ***  |
-   |  ****  |
-   | ** **  |
-   |**  **  |
-   |**  **  |
-   |******* |
-   |    **  |
-   |    **  |
-   |   **** |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x0c,
-0x1c,
-0x3c,
-0x6c,
-0xcc,
-0xcc,
-0xfe,
-0x0c,
-0x0c,
-0x1e,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 5 (0x35):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   |******* |
-   |**      |
-   |**      |
-   |**      |
-   |******  |
-   |     ** |
-   |     ** |
-   |     ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0xfe,
-0xc0,
-0xc0,
-0xc0,
-0xfc,
-0x06,
-0x06,
-0x06,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 6 (0x36):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |**      |
-   |**      |
-   |******  |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0xc0,
-0xc0,
-0xfc,
-0xc6,
-0xc6,
-0xc6,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 7 (0x37):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   |******* |
-   |**   ** |
-   |     ** |
-   |    **  |
-   |   **   |
-   |  **    |
-   |  **    |
-   |  **    |
-   |  **    |
-   |  **    |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0xfe,
-0xc6,
-0x06,
-0x0c,
-0x18,
-0x30,
-0x30,
-0x30,
-0x30,
-0x30,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 8 (0x38):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   | *****  |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0xc6,
-0xc6,
-0x7c,
-0xc6,
-0xc6,
-0xc6,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-
-/* Character 9 (0x39):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   | *****  |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   |**   ** |
-   | ****** |
-   |     ** |
-   |     ** |
-   |**   ** |
-   | *****  |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x7c,
-0xc6,
-0xc6,
-0xc6,
-0xc6,
-0x7e,
-0x06,
-0x06,
-0xc6,
-0x7c,
-0x00,
-0x00,
-0x00,
-0x00,
-/* Character : (0x3a):
-   ht=16, width=8
-   +--------+
-   |        |
-   |        |
-   |        |
-   |        |
-   |        |
-   |    **  |
-   |    **  |
-   |        |
-   |        |
-   |    **  |
-   |    **  |
-   |        |
-   |        |
-   |        |
-   |        |
-   |        |
-   +--------+ */
-0x00,
-0x00,
-0x00,
-0x00,
-0x00,
-0x0c,
-0x0c,
-0x00,
-0x00,
-0x0c,
-0x0c,
-0x00,
-0x00,
-0x00,
-0x00,
-0x00,
-};
index e0060c1..5d920e5 100644 (file)
@@ -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
index 82945ed..58b696f 100644 (file)
@@ -374,7 +374,7 @@ 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[] = {
+static const struct ctrl sd_ctrls[] = {
        {
            {
                .id      = V4L2_CID_BRIGHTNESS,
@@ -861,7 +861,7 @@ static int save_camera_state(struct gspca_dev *gspca_dev)
        return do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0);
 }
 
-int command_setformat(struct gspca_dev *gspca_dev)
+static int command_setformat(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int ret;
@@ -878,7 +878,7 @@ int command_setformat(struct gspca_dev *gspca_dev)
                          sd->params.roi.rowStart, sd->params.roi.rowEnd);
 }
 
-int command_setcolourparams(struct gspca_dev *gspca_dev)
+static int command_setcolourparams(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        return do_command(gspca_dev, CPIA_COMMAND_SetColourParams,
@@ -887,7 +887,7 @@ int command_setcolourparams(struct gspca_dev *gspca_dev)
                          sd->params.colourParams.saturation, 0);
 }
 
-int command_setapcor(struct gspca_dev *gspca_dev)
+static int command_setapcor(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        return do_command(gspca_dev, CPIA_COMMAND_SetApcor,
@@ -897,7 +897,7 @@ int command_setapcor(struct gspca_dev *gspca_dev)
                          sd->params.apcor.gain8);
 }
 
-int command_setvloffset(struct gspca_dev *gspca_dev)
+static int command_setvloffset(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        return do_command(gspca_dev, CPIA_COMMAND_SetVLOffset,
@@ -907,7 +907,7 @@ int command_setvloffset(struct gspca_dev *gspca_dev)
                          sd->params.vlOffset.gain8);
 }
 
-int command_setexposure(struct gspca_dev *gspca_dev)
+static int command_setexposure(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int ret;
@@ -943,7 +943,7 @@ int command_setexposure(struct gspca_dev *gspca_dev)
        return ret;
 }
 
-int command_setcolourbalance(struct gspca_dev *gspca_dev)
+static int command_setcolourbalance(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -973,7 +973,7 @@ int command_setcolourbalance(struct gspca_dev *gspca_dev)
        return -EINVAL;
 }
 
-int command_setcompressiontarget(struct gspca_dev *gspca_dev)
+static int command_setcompressiontarget(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -983,7 +983,7 @@ int command_setcompressiontarget(struct gspca_dev *gspca_dev)
                          sd->params.compressionTarget.targetQ, 0);
 }
 
-int command_setyuvtresh(struct gspca_dev *gspca_dev)
+static int command_setyuvtresh(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -992,7 +992,7 @@ int command_setyuvtresh(struct gspca_dev *gspca_dev)
                          sd->params.yuvThreshold.uvThreshold, 0, 0);
 }
 
-int command_setcompressionparams(struct gspca_dev *gspca_dev)
+static int command_setcompressionparams(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1009,7 +1009,7 @@ int command_setcompressionparams(struct gspca_dev *gspca_dev)
                            sd->params.compressionParams.decimationThreshMod);
 }
 
-int command_setcompression(struct gspca_dev *gspca_dev)
+static int command_setcompression(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1018,7 +1018,7 @@ int command_setcompression(struct gspca_dev *gspca_dev)
                          sd->params.compression.decimation, 0, 0);
 }
 
-int command_setsensorfps(struct gspca_dev *gspca_dev)
+static int command_setsensorfps(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1027,7 +1027,7 @@ int command_setsensorfps(struct gspca_dev *gspca_dev)
                          sd->params.sensorFps.baserate, 0, 0);
 }
 
-int command_setflickerctrl(struct gspca_dev *gspca_dev)
+static int command_setflickerctrl(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1038,7 +1038,7 @@ int command_setflickerctrl(struct gspca_dev *gspca_dev)
                          0);
 }
 
-int command_setecptiming(struct gspca_dev *gspca_dev)
+static int command_setecptiming(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1046,12 +1046,12 @@ int command_setecptiming(struct gspca_dev *gspca_dev)
                          sd->params.ecpTiming, 0, 0, 0);
 }
 
-int command_pause(struct gspca_dev *gspca_dev)
+static 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)
+static int command_resume(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -1059,7 +1059,8 @@ int command_resume(struct gspca_dev *gspca_dev)
                          0, sd->params.streamStartLine, 0, 0);
 }
 
-int command_setlights(struct gspca_dev *gspca_dev)
+#if 0 /* Currently unused */
+static int command_setlights(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int ret, p1, p2;
@@ -1078,6 +1079,7 @@ int command_setlights(struct gspca_dev *gspca_dev)
        return do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 2, 0,
                          p1 | p2 | 0xE0, 0);
 }
+#endif
 
 static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply)
 {
index 222af47..efe6159 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Main USB camera driver
  *
- * Copyright (C) 2008-2009 Jean-Francois Moine (http://moinejf.free.fr)
+ * Copyright (C) 2008-2010 Jean-François Moine <http://moinejf.free.fr>
  *
  * Camera button input handling by Márton Németh
  * Copyright (C) 2009-2010 Márton Németh <nm127@freemail.hu>
 #include <linux/io.h>
 #include <asm/page.h>
 #include <linux/uaccess.h>
-#include <linux/jiffies.h>
+#include <linux/ktime.h>
 #include <media/v4l2-ioctl.h>
 
 #include "gspca.h"
 
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
 #include <linux/input.h>
 #include <linux/usb/input.h>
 #endif
@@ -51,7 +51,7 @@
 #error "DEF_NURBS too big"
 #endif
 
-MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
+MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA USB Camera Driver");
 MODULE_LICENSE("GPL");
 
@@ -115,7 +115,7 @@ static const struct vm_operations_struct gspca_vm_ops = {
 /*
  * Input and interrupt endpoint handling functions
  */
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
 static void int_irq(struct urb *urb)
 {
        struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
@@ -199,7 +199,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
        void *buffer = NULL;
        int ret = -EINVAL;
 
-       buffer_len = ep->wMaxPacketSize;
+       buffer_len = le16_to_cpu(ep->wMaxPacketSize);
        interval = ep->bInterval;
        PDEBUG(D_PROBE, "found int in endpoint: 0x%x, "
                "buffer_len=%u, interval=%u",
@@ -213,7 +213,7 @@ static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev,
                goto error;
        }
 
-       buffer = usb_buffer_alloc(dev, ep->wMaxPacketSize,
+       buffer = usb_buffer_alloc(dev, buffer_len,
                                GFP_KERNEL, &urb->transfer_dma);
        if (!buffer) {
                ret = -ENOMEM;
@@ -280,9 +280,18 @@ static void gspca_input_destroy_urb(struct gspca_dev *gspca_dev)
        }
 }
 #else
-#define gspca_input_connect(gspca_dev)         0
-#define gspca_input_create_urb(gspca_dev)
-#define gspca_input_destroy_urb(gspca_dev)
+static inline void gspca_input_destroy_urb(struct gspca_dev *gspca_dev)
+{
+}
+
+static inline void gspca_input_create_urb(struct gspca_dev *gspca_dev)
+{
+}
+
+static inline int gspca_input_connect(struct gspca_dev *dev)
+{
+       return 0;
+}
 #endif
 
 /* get the current input frame buffer */
@@ -442,8 +451,7 @@ void gspca_frame_add(struct gspca_dev *gspca_dev,
         * is not queued, discard the whole frame */
        if (packet_type == FIRST_PACKET) {
                frame->data_end = frame->data;
-               jiffies_to_timeval(get_jiffies_64(),
-                                  &frame->v4l2_buf.timestamp);
+               frame->v4l2_buf.timestamp = ktime_to_timeval(ktime_get());
                frame->v4l2_buf.sequence = ++gspca_dev->sequence;
        } else if (gspca_dev->last_packet_type == DISCARD_PACKET) {
                if (packet_type == LAST_PACKET)
@@ -605,6 +613,37 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
        }
 }
 
+static int gspca_set_alt0(struct gspca_dev *gspca_dev)
+{
+       int ret;
+
+       if (gspca_dev->alt == 0)
+               return 0;
+       ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0);
+       if (ret < 0)
+               PDEBUG(D_ERR|D_STREAM, "set alt 0 err %d", ret);
+       return ret;
+}
+
+/* Note: both the queue and the usb locks should be held when calling this */
+static void gspca_stream_off(struct gspca_dev *gspca_dev)
+{
+       gspca_dev->streaming = 0;
+       if (gspca_dev->present) {
+               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 */
+       if (gspca_dev->sd_desc->stop0)
+               gspca_dev->sd_desc->stop0(gspca_dev);
+       PDEBUG(D_STREAM, "stream off OK");
+}
+
 /*
  * look for an input transfer endpoint in an alternate setting
  */
@@ -830,8 +869,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
                }
                if (ret >= 0)
                        break;
-               gspca_dev->streaming = 0;
-               destroy_urbs(gspca_dev);
+               gspca_stream_off(gspca_dev);
                if (ret != -ENOSPC) {
                        PDEBUG(D_ERR|D_STREAM,
                                "usb_submit_urb alt %d err %d",
@@ -861,37 +899,6 @@ out:
        return ret;
 }
 
-static int gspca_set_alt0(struct gspca_dev *gspca_dev)
-{
-       int ret;
-
-       if (gspca_dev->alt == 0)
-               return 0;
-       ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0);
-       if (ret < 0)
-               PDEBUG(D_ERR|D_STREAM, "set alt 0 err %d", ret);
-       return ret;
-}
-
-/* Note: both the queue and the usb locks should be held when calling this */
-static void gspca_stream_off(struct gspca_dev *gspca_dev)
-{
-       gspca_dev->streaming = 0;
-       if (gspca_dev->present) {
-               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 */
-       if (gspca_dev->sd_desc->stop0)
-               gspca_dev->sd_desc->stop0(gspca_dev);
-       PDEBUG(D_STREAM, "stream off OK");
-}
-
 static void gspca_set_default_mode(struct gspca_dev *gspca_dev)
 {
        int i;
@@ -1495,7 +1502,7 @@ static int vidioc_reqbufs(struct file *file, void *priv,
                          struct v4l2_requestbuffers *rb)
 {
        struct gspca_dev *gspca_dev = priv;
-       int i, ret = 0;
+       int i, ret = 0, streaming;
 
        switch (rb->memory) {
        case GSPCA_MEMORY_READ:                 /* (internal call) */
@@ -1530,7 +1537,8 @@ static int vidioc_reqbufs(struct file *file, void *priv,
        }
 
        /* stop streaming */
-       if (gspca_dev->streaming) {
+       streaming = gspca_dev->streaming;
+       if (streaming) {
                mutex_lock(&gspca_dev->usb_lock);
                gspca_dev->usb_err = 0;
                gspca_stream_off(gspca_dev);
@@ -1549,6 +1557,8 @@ static int vidioc_reqbufs(struct file *file, void *priv,
        if (ret == 0) {
                rb->count = gspca_dev->nframes;
                gspca_dev->capt_file = file;
+               if (streaming)
+                       ret = gspca_init_transfer(gspca_dev);
        }
 out:
        mutex_unlock(&gspca_dev->queue_lock);
@@ -1582,6 +1592,12 @@ static int vidioc_streamon(struct file *file, void *priv,
        if (mutex_lock_interruptible(&gspca_dev->queue_lock))
                return -ERESTARTSYS;
 
+       /* check the capture file */
+       if (gspca_dev->capt_file != file) {
+               ret = -EBUSY;
+               goto out;
+       }
+
        if (gspca_dev->nframes == 0
            || !(gspca_dev->frame[0].v4l2_buf.flags & V4L2_BUF_FLAG_QUEUED)) {
                ret = -EINVAL;
@@ -1619,6 +1635,12 @@ static int vidioc_streamoff(struct file *file, void *priv,
        if (mutex_lock_interruptible(&gspca_dev->queue_lock))
                return -ERESTARTSYS;
 
+       /* check the capture file */
+       if (gspca_dev->capt_file != file) {
+               ret = -EBUSY;
+               goto out;
+       }
+
        /* stop streaming */
        if (mutex_lock_interruptible(&gspca_dev->usb_lock)) {
                ret = -ERESTARTSYS;
@@ -2124,7 +2146,7 @@ static ssize_t dev_read(struct file *file, char __user *data,
        }
 
        /* get a frame */
-       jiffies_to_timeval(get_jiffies_64(), &timestamp);
+       timestamp = ktime_to_timeval(ktime_get());
        timestamp.tv_sec--;
        n = 2;
        for (;;) {
@@ -2315,7 +2337,7 @@ int gspca_dev_probe(struct usb_interface *intf,
 
        return 0;
 out:
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        if (gspca_dev->input_dev)
                input_unregister_device(gspca_dev->input_dev);
 #endif
@@ -2334,7 +2356,7 @@ EXPORT_SYMBOL(gspca_dev_probe);
 void gspca_disconnect(struct usb_interface *intf)
 {
        struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        struct input_dev *input_dev;
 #endif
 
@@ -2348,7 +2370,7 @@ void gspca_disconnect(struct usb_interface *intf)
                wake_up_interruptible(&gspca_dev->wq);
        }
 
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        gspca_input_destroy_urb(gspca_dev);
        input_dev = gspca_dev->input_dev;
        if (input_dev) {
index 8bb242f..8b963df 100644 (file)
@@ -130,7 +130,7 @@ struct sd_desc {
        cam_reg_op get_register;
 #endif
        cam_ident_op get_chip_ident;
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        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 */
@@ -158,7 +158,7 @@ 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
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        struct input_dev *input_dev;
        char phys[64];                  /* physical device path */
 #endif
@@ -171,7 +171,7 @@ struct gspca_dev {
 #define USB_BUF_SZ 64
        __u8 *usb_buf;                          /* buffer for USB exchanges */
        struct urb *urb[MAX_NURBS];
-#ifdef CONFIG_INPUT
+#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
        struct urb *int_urb;
 #endif
 
index 957e05e..dc1e4ef 100644 (file)
@@ -10,8 +10,8 @@
  * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
  *
  * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
- * PS3 Eye camera, brightness, contrast, hue, AWB control added
- *     by Max Thrun <bear24rw@gmail.com>
+ * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
+ *                  added by Max Thrun <bear24rw@gmail.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
@@ -60,15 +60,13 @@ struct sd {
        u8 contrast;
        u8 gain;
        u8 exposure;
-       u8 redblc;
-       u8 blueblc;
-       u8 hue;
-       u8 autogain;
+       u8 agc;
        u8 awb;
+       u8 aec;
        s8 sharpness;
        u8 hflip;
        u8 vflip;
-
+       u8 freqfltr;
 };
 
 /* V4L2 controls supported by the driver */
@@ -76,197 +74,183 @@ 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_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);
 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_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);
 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 */
-       {
-               .id      = V4L2_CID_BRIGHTNESS,
-               .type    = V4L2_CTRL_TYPE_INTEGER,
-               .name    = "Brightness",
-               .minimum = 0,
-               .maximum = 255,
-               .step    = 1,
-#define BRIGHTNESS_DEF 20
-               .default_value = BRIGHTNESS_DEF,
+       {       /* 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,
+               },
+               .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,
-#define CONTRAST_DEF 37
-               .default_value = CONTRAST_DEF,
+       {       /* 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,
+               },
+               .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,
-       },
-       .set = sd_setexposure,
-       .get = sd_getexposure,
-    },
-    {                                                  /* 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,
+                       .default_value = EXPO_DEF,
+               },
+               .set = sd_setexposure,
+               .get = sd_getexposure,
        },
-       .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,
+       {       /* 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,
+               },
+               .set = sd_setagc,
+               .get = sd_getagc,
        },
-       .set = sd_setblueblc,
-       .get = sd_getblueblc,
-    },
-    {                                                  /* 6 */
-       {
-               .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,
+#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,
+#define AWB_DEF 1
+                       .default_value = AWB_DEF,
+               },
+               .set = sd_setawb,
+               .get = sd_getawb,
        },
-       .set = sd_sethue,
-       .get = sd_gethue,
-    },
-    {                                                  /* 7 */
-       {
-           .id      = V4L2_CID_AUTOGAIN,
-           .type    = V4L2_CTRL_TYPE_BOOLEAN,
-           .name    = "Autogain",
-           .minimum = 0,
-           .maximum = 1,
-           .step    = 1,
-#define AUTOGAIN_DEF 0
-           .default_value = AUTOGAIN_DEF,
+       {       /* 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,
        },
-       .set = sd_setautogain,
-       .get = sd_getautogain,
-    },
-#define AWB_IDX 8
-    {                                                  /* 8 */
-       {
-               .id      = V4L2_CID_AUTO_WHITE_BALANCE,
-               .type    = V4L2_CTRL_TYPE_BOOLEAN,
-               .name    = "Auto White Balance",
-               .minimum = 0,
-               .maximum = 1,
-               .step    = 1,
-#define AWB_DEF 0
-               .default_value = AWB_DEF,
-       },
-       .set = sd_setawb,
-       .get = sd_getawb,
-    },
-    {                                                  /* 9 */
-       {
-           .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,
-    },
-    {                                                  /* 10 */
-       {
-           .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,
-    },
-    {                                                  /* 11 */
-       {
-           .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,
+       },
+       {       /* 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,
        },
-       .set = sd_setvflip,
-       .get = sd_getvflip,
-    },
 };
 
 static const struct v4l2_pix_format ov772x_mode[] = {
@@ -675,14 +659,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)
@@ -690,6 +674,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:
@@ -717,55 +704,68 @@ 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);
 }
 
-static void setredblc(struct gspca_dev *gspca_dev)
+static void setagc(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;
+       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,
+                               sccb_reg_read(gspca_dev, 0x13) & ~0x04);
+               sccb_reg_write(gspca_dev, 0x64,
+                               sccb_reg_read(gspca_dev, 0x64) & ~0x03);
 
-       sccb_reg_write(gspca_dev, 0x01, sd->hue);
+               setgain(gspca_dev);
+       }
 }
 
-static void setautogain(struct gspca_dev *gspca_dev)
+static void setawb(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 */
-               sccb_reg_write(gspca_dev, 0x64,
-                               sccb_reg_read(gspca_dev, 0x64) | 0x03);
+       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, 0xf0); /* AGC,AEC,AWB OFF */
-               sccb_reg_write(gspca_dev, 0x64,
-                               sccb_reg_read(gspca_dev, 0x64) & 0xfc);
+               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 setawb(struct gspca_dev *gspca_dev)
+static void setaec(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->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)
@@ -774,8 +774,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)
@@ -787,7 +787,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)
@@ -799,9 +799,20 @@ 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);
 }
 
+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)
@@ -825,26 +836,17 @@ 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;
+#if AGC_DEF != 0
+       sd->agc = AGC_DEF;
 #else
        gspca_dev->ctrl_inac |= (1 << AWB_IDX);
 #endif
-#if AWB_DEF != 0
-       sd->awb = AWB_DEF
-#endif
-#if SHARPNESS_DEF != 0
+       sd->awb = AWB_DEF;
+       sd->aec = AEC_DEF;
        sd->sharpness = SHARPNESS_DEF;
-#endif
-#if HFLIP_DEF != 0
        sd->hflip = HFLIP_DEF;
-#endif
-#if VFLIP_DEF != 0
        sd->vflip = VFLIP_DEF;
-#endif
+       sd->freqfltr = FREQFLTR_DEF;
 
        return 0;
 }
@@ -904,18 +906,17 @@ static int sd_start(struct gspca_dev *gspca_dev)
        }
        set_frame_rate(gspca_dev);
 
-       setautogain(gspca_dev);
+       setagc(gspca_dev);
        setawb(gspca_dev);
+       setaec(gspca_dev);
        setgain(gspca_dev);
-       setredblc(gspca_dev);
-       setblueblc(gspca_dev);
-       sethue(gspca_dev);
        setexposure(gspca_dev);
        setbrightness(gspca_dev);
        setcontrast(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);
@@ -1092,65 +1093,11 @@ 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)
+static int sd_setagc(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;
-
-       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;
-
-       sd->autogain = val;
+       sd->agc = val;
 
        if (gspca_dev->streaming) {
 
@@ -1160,16 +1107,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;
 }
 
@@ -1191,6 +1138,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;
@@ -1245,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)
@@ -1296,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,
 };
index 0c87c34..a40f889 100644 (file)
@@ -99,7 +99,7 @@ static const struct ctrl sd_ctrls[] = {
            {
                .id = V4L2_CID_EXPOSURE,
                .type = V4L2_CTRL_TYPE_INTEGER,
-               .name = "exposure",
+               .name = "Exposure",
                .minimum = PAC207_EXPOSURE_MIN,
                .maximum = PAC207_EXPOSURE_MAX,
                .step = 1,
@@ -130,7 +130,7 @@ static const struct ctrl sd_ctrls[] = {
            {
                .id = V4L2_CID_GAIN,
                .type = V4L2_CTRL_TYPE_INTEGER,
-               .name = "gain",
+               .name = "Gain",
                .minimum = PAC207_GAIN_MIN,
                .maximum = PAC207_GAIN_MAX,
                .step = 1,
index dda5fd4..71d9447 100644 (file)
@@ -39,7 +39,7 @@ struct init_command {
 };
 
 /* V4L2 controls supported by the driver */
-static struct ctrl sd_ctrls[] = {
+static const struct ctrl sd_ctrls[] = {
 };
 
 /* How to change the resolution of any of the VGA cams is unknown */
index 3dee3e5..644a7fd 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV
-#include <linux/kthread.h>
-#include <linux/freezer.h>
-#include <linux/usb/input.h>
+#ifdef CONFIG_INPUT
 #include <linux/input.h>
 #include <linux/slab.h>
 #endif
@@ -30,6 +27,7 @@
 #include "jpeg.h"
 
 #include <media/v4l2-chip-ident.h>
+#include <linux/dmi.h>
 
 MODULE_AUTHOR("Brian Johnson <brijohn@gmail.com>, "
                "microdia project <microdia@googlegroups.com>");
@@ -52,9 +50,15 @@ 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 */
+#define HAS_NO_BUTTON  0x1
+#define LED_REVERSE    0x2 /* some cameras unset gpio to turn on leds */
+#define FLIP_DETECT    0x4
+
 /* specific webcam descriptor */
 struct sd {
        struct gspca_dev gspca_dev;
@@ -88,11 +92,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 {
@@ -130,6 +130,39 @@ 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")
+               }
+       },
+       {
+               .ident = "MSI MS-1635X",
+               .matches = {
+                       DMI_MATCH(DMI_BOARD_VENDOR, "MSI"),
+                       DMI_MATCH(DMI_BOARD_NAME, "MS-1635X")
+               }
+       },
+       {
+               .ident = "ASUSTeK W7J",
+               .matches = {
+                       DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer Inc."),
+                       DMI_MATCH(DMI_BOARD_NAME, "W7J       ")
+               }
+       },
+       {}
+};
+
 static const struct ctrl sd_ctrls[] = {
        {
 #define BRIGHTNESS_IDX 0
@@ -713,6 +746,7 @@ static u16 i2c_ident[] = {
        V4L2_IDENT_MT9V112,
        V4L2_IDENT_MT9M001C12ST,
        V4L2_IDENT_MT9M111,
+       V4L2_IDENT_MT9M112,
        V4L2_IDENT_HV7131R,
 };
 
@@ -735,7 +769,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) */
@@ -914,40 +949,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[] = {
@@ -971,29 +996,12 @@ static struct i2c_reg_u16 mt9v112_init[] = {
 
 static struct i2c_reg_u16 mt9v111_init[] = {
        {0x01, 0x0004}, {0x0d, 0x0001}, {0x0d, 0x0000},
-       {0x01, 0x0001}, {0x02, 0x0016}, {0x03, 0x01e1},
-       {0x04, 0x0281}, {0x05, 0x0004}, {0x07, 0x3002},
-       {0x21, 0x0000}, {0x25, 0x4024}, {0x26, 0xff03},
-       {0x27, 0xff10}, {0x2b, 0x7828}, {0x2c, 0xb43c},
-       {0x2d, 0xf0a0}, {0x2e, 0x0c64}, {0x2f, 0x0064},
-       {0x67, 0x4010}, {0x06, 0x301e}, {0x08, 0x0480},
-       {0x01, 0x0004}, {0x02, 0x0016}, {0x03, 0x01e6},
-       {0x04, 0x0286}, {0x05, 0x0004}, {0x06, 0x0000},
-       {0x07, 0x3002}, {0x08, 0x0008}, {0x0c, 0x0000},
-       {0x0d, 0x0000}, {0x0e, 0x0000}, {0x0f, 0x0000},
-       {0x10, 0x0000}, {0x11, 0x0000}, {0x12, 0x00b0},
-       {0x13, 0x007c}, {0x14, 0x0000}, {0x15, 0x0000},
-       {0x16, 0x0000}, {0x17, 0x0000}, {0x18, 0x0000},
-       {0x19, 0x0000}, {0x1a, 0x0000}, {0x1b, 0x0000},
-       {0x1c, 0x0000}, {0x1d, 0x0000}, {0x30, 0x0000},
-       {0x30, 0x0005}, {0x31, 0x0000}, {0x02, 0x0016},
-       {0x03, 0x01e1}, {0x04, 0x0281}, {0x05, 0x0004},
-       {0x06, 0x0000}, {0x07, 0x3002}, {0x06, 0x002d},
-       {0x05, 0x0004}, {0x09, 0x0064}, {0x2b, 0x00a0},
-       {0x2c, 0x00a0}, {0x2d, 0x00a0}, {0x2e, 0x00a0},
-       {0x02, 0x0016}, {0x03, 0x01e1}, {0x04, 0x0281},
-       {0x05, 0x0004}, {0x06, 0x002d}, {0x07, 0x3002},
-       {0x0e, 0x0008}, {0x06, 0x002d}, {0x05, 0x0004},
+       {0x01, 0x0001}, {0x05, 0x0004}, {0x2d, 0xe0a0},
+       {0x2e, 0x0c64}, {0x2f, 0x0064}, {0x06, 0x600e},
+       {0x08, 0x0480}, {0x01, 0x0004}, {0x02, 0x0016},
+       {0x03, 0x01e7}, {0x04, 0x0287}, {0x05, 0x0004},
+       {0x06, 0x002d}, {0x07, 0x3002}, {0x08, 0x0008},
+       {0x0e, 0x0008}, {0x20, 0x0000}
 };
 
 static struct i2c_reg_u16 mt9v011_init[] = {
@@ -1043,6 +1051,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},
@@ -1240,8 +1255,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;
 }
 
@@ -1337,6 +1352,7 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev)
                                return -ENODEV;
                        }
                }
+               gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) | (1 << GAIN_IDX);
                sd->hstart = 2;
                sd->vstart = 2;
                sd->sensor = SENSOR_MT9V111;
@@ -1369,6 +1385,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;
@@ -1421,87 +1454,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_ONSTACK(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;
@@ -1579,17 +1531,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;
                }
@@ -1600,28 +1561,29 @@ 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;
+       case SENSOR_MT9M112:
        case SENSOR_MT9M111:
        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;
@@ -1645,7 +1607,6 @@ static int set_exposure(struct gspca_dev *gspca_dev)
                break;
        case SENSOR_MT9M001:
        case SENSOR_MT9V112:
-       case SENSOR_MT9V111:
        case SENSOR_MT9V011:
                exp[0] |= (3 << 4);
                exp[2] = 0x09;
@@ -1655,9 +1616,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;
@@ -1680,7 +1641,6 @@ static int set_gain(struct gspca_dev *gspca_dev)
                gain[3] = ov_gain[sd->gain];
                break;
        case SENSOR_MT9V011:
-       case SENSOR_MT9V111:
                gain[0] |= (3 << 4);
                gain[2] = 0x35;
                gain[3] = micron1_gain[sd->gain] >> 8;
@@ -1931,7 +1891,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 *)&reg->val) < 0)
                                return -EINVAL;
                } else {
@@ -1960,7 +1920,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 {
@@ -2005,8 +1965,10 @@ 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_MT9M112:
        case SENSOR_MT9M111:
        case SENSOR_OV9650:
        case SENSOR_SOI968:
@@ -2039,11 +2001,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;
 }
 
@@ -2063,6 +2020,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;
@@ -2103,6 +2065,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;
@@ -2162,6 +2129,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);
@@ -2243,6 +2211,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;
@@ -2250,6 +2220,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);
 }
@@ -2343,6 +2315,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_NO_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 */
@@ -2409,6 +2399,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,
@@ -2417,8 +2410,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 & 0xff) << 16) \
                        | (SENSOR_ ## sensor << 8) \
                        | (i2c_addr)
 
@@ -2426,8 +2419,10 @@ 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, 0x624f), SN9C20X(OV9650, 0x30, 0)},
+       {USB_DEVICE(0x0c45, 0x624c), SN9C20X(MT9M112, 0x5d, 0)},
+       {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, LED_REVERSE)},
+       {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30,
+                                            (FLIP_DETECT | HAS_NO_BUTTON))},
        {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)},
        {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)},
        {USB_DEVICE(0x0c45, 0x6260), SN9C20X(OV7670, 0x21, 0)},
@@ -2438,6 +2433,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, 0)},
+       {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)},
@@ -2448,6 +2444,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)},
@@ -2467,22 +2465,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,
index 1d61b92..bb923ef 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
  *
- * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
+ * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
  * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
  *
  * This program is free software; you can redistribute it and/or modify
@@ -28,7 +28,7 @@
 
 #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
 
-MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
+MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
 MODULE_LICENSE("GPL");
 
@@ -67,20 +67,25 @@ 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_GC0307,
+       SENSOR_HV7131R,
+       SENSOR_MI0360,
+       SENSOR_MO4000,
+       SENSOR_MT9V111,
+       SENSOR_OM6802,
+       SENSOR_OV7630,
+       SENSOR_OV7648,
+       SENSOR_OV7660,
+       SENSOR_PO1030,
+       SENSOR_PO2030N,
+       SENSOR_SOI768,
+       SENSOR_SP80708,
+} sensors;
        u8 i2c_addr;
 
-       u8 *jpeg_hdr;
+       u8 jpeg_hdr[JPEG_HDR_SZ];
 };
 
 /* V4L2 controls supported by the driver */
@@ -281,29 +286,60 @@ 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_GC0307] =      (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_PO2030N] =     (1 << AUTOGAIN_IDX) |
+                       (1 << INFRARED_IDX) |
+                       (1 << VFLIP_IDX) |
+                       (1 << FREQ_IDX),
+[SENSOR_SOI768] =      (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[] = {
@@ -343,7 +379,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,
@@ -401,7 +447,7 @@ static const u8 sn_om6802[0x1c] = {
 
 static const u8 sn_ov7630[0x1c] = {
 /*     reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
-       0x00,   0x21,   0x40,   0x00,   0x1a,   0x20,   0x1f,   0x20,
+       0x00,   0x21,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
 /*     reg8    reg9    rega    regb    regc    regd    rege    regf */
        0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
 /*     reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
@@ -443,6 +489,28 @@ 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_soi768[0x1c] = {
+/*     reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
+       0x00,   0x21,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
+/*     reg8    reg9    rega    regb    regc    regd    rege    regf */
+       0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
+/*     reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
+       0x03,   0x00,   0x00,   0x01,   0x08,   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,
@@ -456,17 +524,20 @@ 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_GC0307] =      sn_gc0307,
+[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_PO2030N] =     sn_po2030n,
+[SENSOR_SOI768] =      sn_soi768,
+[SENSOR_SP80708] =     sn_sp80708,
 };
 
 /* default gamma table */
@@ -484,8 +555,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
 };
@@ -533,6 +609,58 @@ 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},
+       {}
+};
+
 static const u8 hv7131r_sensor_init[][8] = {
        {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
        {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
@@ -767,7 +895,9 @@ static const u8 ov7630_sensor_init[][8] = {
        {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
        {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
        {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
-/* */
+       {}
+};
+static const u8 ov7630_sensor_param1[][8] = {
        {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
        {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
 /*fixme: + 0x12, 0x04*/
@@ -984,6 +1114,113 @@ 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 soi768_sensor_init[][8] = {
+       {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
+       {0xdd, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
+       {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
+       {}
+};
+static const u8 soi768_sensor_param1[][8] = {
+       {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
+       {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
+       {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
+/* */
+/*     {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
+/*     {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
+       {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
+/*     {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
+       {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
+/* the next sequence should be used for auto gain */
+       {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
+                       /* global gain ? : 07 - change with 0x15 at the end */
+       {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
+       {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
+       {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
+                       /* exposure ? : 0200 - change with 0x1e at the end */
+       {}
+};
+
 static const u8 sp80708_sensor_init[][8] = {
        {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
        {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
@@ -1069,18 +1306,21 @@ 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_GC0307] =      gc0307_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_PO2030N] =     po2030n_sensor_init,
+[SENSOR_SOI768] =      soi768_sensor_init,
+[SENSOR_SP80708] =     sp80708_sensor_init,
 };
 
 /* read <len> bytes to gspca_dev->usb_buf */
@@ -1146,10 +1386,11 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
-       PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
+       PDEBUG(D_USBO, "i2c_w1 [%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) */
@@ -1177,6 +1418,8 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
 static void i2c_w8(struct gspca_dev *gspca_dev,
                   const u8 *buffer)
 {
+       PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
+               buffer[2], buffer[3]);
        memcpy(gspca_dev->usb_buf, buffer, 8);
        usb_control_msg(gspca_dev->dev,
                        usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -1196,7 +1439,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) */
@@ -1300,39 +1544,100 @@ static void mi0360_probe(struct gspca_dev *gspca_dev)
        }
 }
 
-static void ov7648_probe(struct gspca_dev *gspca_dev)
+static void ov7630_probe(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
+       u16 val;
 
        /* check ov76xx */
        reg_w1(gspca_dev, 0x17, 0x62);
        reg_w1(gspca_dev, 0x01, 0x08);
        sd->i2c_addr = 0x21;
        i2c_r(gspca_dev, 0x0a, 2);
-       if (gspca_dev->usb_buf[3] == 0x76) {    /* ov76xx */
-               PDEBUG(D_PROBE, "Sensor ov%02x%02x",
-                       gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
+       val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
+       reg_w1(gspca_dev, 0x01, 0x29);
+       reg_w1(gspca_dev, 0x17, 0x42);
+       if (val == 0x7628) {                    /* soi768 */
+               sd->sensor = SENSOR_SOI768;
+/*fixme: only valid for 0c45:613e?*/
+               gspca_dev->cam.input_flags =
+                               V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
+               PDEBUG(D_PROBE, "Sensor soi768");
                return;
        }
+       PDEBUG(D_PROBE, "Sensor ov%04x", val);
+}
 
-       /* reset */
+static void ov7648_probe(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u16 val;
+
+       /* check ov76xx */
+       reg_w1(gspca_dev, 0x17, 0x62);
+       reg_w1(gspca_dev, 0x01, 0x08);
+       sd->i2c_addr = 0x21;
+       i2c_r(gspca_dev, 0x0a, 2);
+       val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
        reg_w1(gspca_dev, 0x01, 0x29);
        reg_w1(gspca_dev, 0x17, 0x42);
+       if ((val & 0xff00) == 0x7600) {         /* ov76xx */
+               PDEBUG(D_PROBE, "Sensor ov%04x", val);
+               return;
+       }
 
        /* check po1030 */
        reg_w1(gspca_dev, 0x17, 0x62);
        reg_w1(gspca_dev, 0x01, 0x08);
        sd->i2c_addr = 0x6e;
        i2c_r(gspca_dev, 0x00, 2);
-       if (gspca_dev->usb_buf[3] == 0x10       /* po1030 */
-           && gspca_dev->usb_buf[4] == 0x30) {
+       val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
+       reg_w1(gspca_dev, 0x01, 0x29);
+       reg_w1(gspca_dev, 0x17, 0x42);
+       if (val == 0x1030) {                    /* po1030 */
                PDEBUG(D_PROBE, "Sensor po1030");
                sd->sensor = SENSOR_PO1030;
                return;
        }
 
-       PDEBUG(D_PROBE, "Unknown sensor %02x%02x",
-               gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
+       PDEBUG(D_PROBE, "Unknown sensor %04x", val);
+}
+
+/* 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;
+       u16 val;
+
+       /* 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);
+       val = gspca_dev->usb_buf[4];
+       reg_w1(gspca_dev, 0x01, 0x29);          /* reset */
+       reg_w1(gspca_dev, 0x17, 0x42);
+       if (val == 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);
+       val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
+       reg_w1(gspca_dev, 0x01, 0x29);
+       reg_w1(gspca_dev, 0x17, 0x42);
+       if (val == 0x2030) {
+               PDEBUG(D_PROBE, "Sensor po2030n");
+/*             sd->sensor = SENSOR_PO2030N; */
+       } else {
+               PDEBUG(D_PROBE, "Unknown sensor ID %04x", val);
+       }
 }
 
 static void bridge_init(struct gspca_dev *gspca_dev,
@@ -1355,8 +1660,11 @@ 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_SOI768:
        case SENSOR_SP80708:
                reg9a = reg9a_spec;
                break;
@@ -1377,6 +1685,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);
@@ -1414,11 +1730,18 @@ static void bridge_init(struct gspca_dev *gspca_dev,
                reg_w1(gspca_dev, 0x01, 0x42);
                break;
        case SENSOR_PO1030:
+       case SENSOR_SOI768:
                reg_w1(gspca_dev, 0x01, 0x61);
                reg_w1(gspca_dev, 0x17, 0x20);
                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:
@@ -1523,9 +1846,15 @@ static int sd_init(struct gspca_dev *gspca_dev)
                case SENSOR_MI0360:
                        mi0360_probe(gspca_dev);
                        break;
+               case SENSOR_OV7630:
+                       ov7630_probe(gspca_dev);
+                       break;
                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);
@@ -1558,6 +1887,18 @@ static u32 setexposure(struct gspca_dev *gspca_dev,
        struct sd *sd = (struct sd *) gspca_dev;
 
        switch (sd->sensor) {
+       case SENSOR_GC0307: {
+               int a, b;
+
+               /* expo = 0..255 -> a = 19..43 */
+               a = 19 + expo * 25 / 256;
+               i2c_w1(gspca_dev, 0x68, a);
+               a -= 12;
+               b = a * a * 4;                  /* heuristic */
+               i2c_w1(gspca_dev, 0x03, b >> 8);
+               i2c_w1(gspca_dev, 0x04, b);
+               break;
+           }
        case SENSOR_HV7131R: {
                u8 Expodoit[] =
                        { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
@@ -1668,6 +2009,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
                expo = sd->brightness >> 4;
                sd->exposure = setexposure(gspca_dev, expo);
                break;
+       case SENSOR_GC0307:
        case SENSOR_MT9V111:
                expo = sd->brightness >> 8;
                sd->exposure = setexposure(gspca_dev, expo);
@@ -1703,7 +2045,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 */
        };
@@ -1744,9 +2086,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;
@@ -1937,14 +2282,17 @@ 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);
-       if (!sd->jpeg_hdr)
-               return -ENOMEM;
        jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
                        0x21);          /* JPEG 422 */
        jpeg_set_qual(sd->jpeg_hdr, sd->quality);
@@ -1996,6 +2344,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;
@@ -2007,9 +2358,11 @@ static int sd_start(struct gspca_dev *gspca_dev)
                reg17 = 0x20;
                break;
        case SENSOR_OV7660:
+       case SENSOR_SOI768:
                reg17 = 0xa0;
                break;
        case SENSOR_PO1030:
+       case SENSOR_PO2030N:
                reg17 = 0xa0;
                break;
        default:
@@ -2034,12 +2387,18 @@ 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_OV7630:
        case SENSOR_OV7648:
                reg_w1(gspca_dev, 0x9a, 0x0a);
                break;
+       case SENSOR_PO2030N:
+       case SENSOR_SOI768:
+               reg_w1(gspca_dev, 0x9a, 0x06);
+               break;
        default:
                reg_w1(gspca_dev, 0x9a, 0x08);
                break;
@@ -2064,6 +2423,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 */
@@ -2087,6 +2451,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
                reg17 = 0x64;           /* 640 MCKSIZE */
                break;
        case SENSOR_OV7630:
+               init = ov7630_sensor_param1;
                reg17 = 0xe2;
                reg1 = 0x44;
                break;
@@ -2113,6 +2478,16 @@ 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;
+       case SENSOR_SOI768:
+               init = soi768_sensor_param1;
+               reg1 = 0x44;
+               reg17 = 0xa2;
+               break;
        default:
 /*     case SENSOR_SP80708: */
                init = sp80708_sensor_param1;
@@ -2132,17 +2507,33 @@ 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:
+       case SENSOR_SOI768:
                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:
        case SENSOR_OV7648:
        case SENSOR_OV7660:
+       case SENSOR_SOI768:
                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} */
@@ -2161,6 +2552,7 @@ static int sd_start(struct gspca_dev *gspca_dev)
        setvflip(sd);
        setbrightness(gspca_dev);
        setcontrast(gspca_dev);
+       setcolors(gspca_dev);
        setautogain(gspca_dev);
        setfreq(gspca_dev);
        return 0;
@@ -2175,11 +2567,16 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
                { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
        static const u8 stopov7648[] =
                { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
+       static const u8 stopsoi768[] =
+               { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
        u8 data;
        const u8 *sn9c1xx;
 
        data = 0x0b;
        switch (sd->sensor) {
+       case SENSOR_GC0307:
+               data = 0x29;
+               break;
        case SENSOR_HV7131R:
                i2c_w8(gspca_dev, stophv7131);
                data = 0x2b;
@@ -2196,6 +2593,10 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        case SENSOR_PO1030:
                data = 0x29;
                break;
+       case SENSOR_SOI768:
+               i2c_w8(gspca_dev, stopsoi768);
+               data = 0x29;
+               break;
        }
        sn9c1xx = sn_tb[sd->sensor];
        reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
@@ -2206,13 +2607,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
        /* reg_w1(gspca_dev, 0xf1, 0x01); */
 }
 
-static void sd_stop0(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-
-       kfree(sd->jpeg_hdr);
-}
-
 static void do_autogain(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
@@ -2233,6 +2627,14 @@ static void do_autogain(struct gspca_dev *gspca_dev)
        if (delta < luma_mean - luma_delta ||
            delta > luma_mean + luma_delta) {
                switch (sd->sensor) {
+               case SENSOR_GC0307:
+                       expotimes = sd->exposure;
+                       expotimes += (luma_mean - delta) >> 6;
+                       if (expotimes < 0)
+                               expotimes = 0;
+                       sd->exposure = setexposure(gspca_dev,
+                                                  (unsigned int) expotimes);
+                       break;
                case SENSOR_HV7131R:
                        expotimes = sd->exposure >> 8;
                        expotimes += (luma_mean - delta) >> 4;
@@ -2584,7 +2986,6 @@ static const struct sd_desc sd_desc = {
        .init = sd_init,
        .start = sd_start,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
        .dq_callback = do_autogain,
        .get_jcomp = sd_get_jcomp,
@@ -2656,7 +3057,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*/
index b9c80e2..7bb2355 100644 (file)
@@ -22,6 +22,7 @@
 
 #define MODULE_NAME "spca561"
 
+#include <linux/input.h>
 #include "gspca.h"
 
 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
@@ -249,9 +250,9 @@ static const __u16 Pb100_2map8300[][2] = {
 };
 
 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 */
@@ -263,15 +264,11 @@ static const __u16 spca561_161rev12A_data2[][2] = {
        {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},
@@ -302,6 +299,9 @@ static const __u16 spca561_161rev12A_data2[][2] = {
        {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},
        {}
 };
 
@@ -645,6 +645,9 @@ static int sd_start_12a(struct gspca_dev *gspca_dev)
        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)
@@ -691,26 +694,14 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
 
        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;
@@ -788,6 +779,23 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        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);
@@ -1028,8 +1036,10 @@ static const struct sd_desc sd_desc_12a = {
        .init = sd_init_12a,
        .start = sd_start_12a,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .pkt_scan = sd_pkt_scan,
+#ifdef CONFIG_INPUT
+       .other_input = 1,
+#endif
 };
 static const struct sd_desc sd_desc_72a = {
        .name = MODULE_NAME,
@@ -1039,9 +1049,11 @@ static const struct sd_desc sd_desc_72a = {
        .init = sd_init_72a,
        .start = sd_start_72a,
        .stopN = sd_stopN,
-       .stop0 = sd_stop0,
        .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,
index 668a753..6301437 100644 (file)
@@ -44,7 +44,10 @@ struct sd {
        u8 gamma;
        u8 sharpness;
        u8 freq;
-       u8 whitebalance;
+       u8 red_balance; /* split balance */
+       u8 blue_balance;
+       u8 global_gain; /* aka gain */
+       u8 whitebalance; /* set default r/g/b and activate */
        u8 mirror;
        u8 effect;
 
@@ -70,8 +73,17 @@ 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_setfreq(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
+
+
 static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
+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 int sd_setglobal_gain(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getglobal_gain(struct gspca_dev *gspca_dev, __s32 *val);
+
 static int sd_setflip(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getflip(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_seteffect(struct gspca_dev *gspca_dev, __s32 val);
@@ -79,6 +91,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 const struct ctrl sd_ctrls[] = {
        {
         {
@@ -139,7 +152,7 @@ static const struct ctrl sd_ctrls[] = {
         },
        {
         {
-         .id = V4L2_CID_GAIN,  /* here, i activate only the lowlight,
+         .id = V4L2_CID_BACKLIGHT_COMPENSATION, /* Activa lowlight,
                                 * some apps dont bring up the
                                 * backligth_compensation control) */
          .type = V4L2_CTRL_TYPE_INTEGER,
@@ -183,7 +196,7 @@ static const struct ctrl sd_ctrls[] = {
 
        {
         {
-         .id = V4L2_CID_WHITE_BALANCE_TEMPERATURE,
+         .id =  V4L2_CID_AUTO_WHITE_BALANCE,
          .type = V4L2_CTRL_TYPE_INTEGER,
          .name = "White Balance",
          .minimum = 0,
@@ -223,6 +236,48 @@ static const struct ctrl sd_ctrls[] = {
         .set = sd_seteffect,
         .get = sd_geteffect
        },
+       {
+        {
+           .id      = V4L2_CID_BLUE_BALANCE,
+           .type    = V4L2_CTRL_TYPE_INTEGER,
+           .name    = "Blue Balance",
+           .minimum = 0x10,
+           .maximum = 0x40,
+           .step    = 1,
+#define BLUE_BALANCE_DEF 0x20
+           .default_value = BLUE_BALANCE_DEF,
+        },
+       .set = sd_setblue_balance,
+       .get = sd_getblue_balance,
+       },
+       {
+        {
+           .id      = V4L2_CID_RED_BALANCE,
+           .type    = V4L2_CTRL_TYPE_INTEGER,
+           .name    = "Red Balance",
+           .minimum = 0x10,
+           .maximum = 0x40,
+           .step    = 1,
+#define RED_BALANCE_DEF 0x20
+           .default_value = RED_BALANCE_DEF,
+        },
+       .set = sd_setred_balance,
+       .get = sd_getred_balance,
+       },
+       {
+        {
+           .id      = V4L2_CID_GAIN,
+           .type    = V4L2_CTRL_TYPE_INTEGER,
+           .name    = "Gain",
+           .minimum = 0x10,
+           .maximum = 0x40,
+           .step    = 1,
+#define global_gain_DEF  0x20
+           .default_value = global_gain_DEF,
+        },
+       .set = sd_setglobal_gain,
+       .get = sd_getglobal_gain,
+       },
 };
 
 static char *effects_control[] = {
@@ -523,6 +578,10 @@ static void reg_w_buf(struct gspca_dev *gspca_dev,
                u8 *tmpbuf;
 
                tmpbuf = kmalloc(len, GFP_KERNEL);
+               if (!tmpbuf) {
+                       err("Out of memory");
+                       return;
+               }
                memcpy(tmpbuf, buffer, len);
                usb_control_msg(gspca_dev->dev,
                                usb_sndctrlpipe(gspca_dev->dev, 0),
@@ -542,10 +601,15 @@ static void reg_w_ixbuf(struct gspca_dev *gspca_dev,
        int i;
        u8 *p, *tmpbuf;
 
-       if (len * 2 <= USB_BUF_SZ)
+       if (len * 2 <= USB_BUF_SZ) {
                p = tmpbuf = gspca_dev->usb_buf;
-       else
+       } else {
                p = tmpbuf = kmalloc(len * 2, GFP_KERNEL);
+               if (!tmpbuf) {
+                       err("Out of memory");
+                       return;
+               }
+       }
        i = len;
        while (--i >= 0) {
                *p++ = reg++;
@@ -642,6 +706,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
        sd->whitebalance = WHITE_BALANCE_DEF;
        sd->sharpness = SHARPNESS_DEF;
        sd->effect = EFFECTS_DEF;
+       sd->red_balance = RED_BALANCE_DEF;
+       sd->blue_balance = BLUE_BALANCE_DEF;
+       sd->global_gain = global_gain_DEF;
+
        return 0;
 }
 
@@ -693,18 +761,40 @@ static void setgamma(struct gspca_dev *gspca_dev)
        reg_w_ixbuf(gspca_dev, 0x90,
                gamma_table[sd->gamma], sizeof gamma_table[0]);
 }
+static void setglobalgain(struct gspca_dev *gspca_dev)
+{
 
-static void setwhitebalance(struct gspca_dev *gspca_dev)
+       struct sd *sd = (struct sd *) gspca_dev;
+       reg_w(gspca_dev, (sd->red_balance  << 8) + 0x87);
+       reg_w(gspca_dev, (sd->blue_balance << 8) + 0x88);
+       reg_w(gspca_dev, (sd->global_gain  << 8) + 0x89);
+}
+
+/* Generic fnc for r/b balance, exposure and whitebalance */
+static void setbalance(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
-       u8 white_balance[8] =
-               {0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38};
+       /* on whitebalance leave defaults values */
+       if (sd->whitebalance) {
+               reg_w(gspca_dev, 0x3c80);
+       } else {
+               reg_w(gspca_dev, 0x3880);
+               /* shoud we wait here.. */
+               /* update and reset 'global gain' with webcam parameters */
+               sd->red_balance = reg_r(gspca_dev, 0x0087);
+               sd->blue_balance = reg_r(gspca_dev, 0x0088);
+               sd->global_gain = reg_r(gspca_dev, 0x0089);
+               setglobalgain(gspca_dev);
+       }
+
+}
+
 
-       if (sd->whitebalance)
-               white_balance[7] = 0x3c;
 
-       reg_w_buf(gspca_dev, white_balance, sizeof white_balance);
+static void setwhitebalance(struct gspca_dev *gspca_dev)
+{
+       setbalance(gspca_dev);
 }
 
 static void setsharpness(struct gspca_dev *gspca_dev)
@@ -1018,6 +1108,66 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
        gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
 }
 
+
+static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       sd->blue_balance = val;
+       if (gspca_dev->streaming)
+               reg_w(gspca_dev, (val << 8) + 0x88);
+       return 0;
+}
+
+static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       *val = sd->blue_balance;
+       return 0;
+}
+
+static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       sd->red_balance = val;
+       if (gspca_dev->streaming)
+               reg_w(gspca_dev, (val << 8) + 0x87);
+
+       return 0;
+}
+
+static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       *val = sd->red_balance;
+       return 0;
+}
+
+
+
+static int sd_setglobal_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       sd->global_gain = val;
+       if (gspca_dev->streaming)
+               setglobalgain(gspca_dev);
+
+       return 0;
+}
+
+static int sd_getglobal_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       *val = sd->global_gain;
+       return 0;
+}
+
+
 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
 {
        struct sd *sd = (struct sd *) gspca_dev;
index 4989f9a..732c3df 100644 (file)
@@ -1,9 +1,9 @@
 /*
- *             Z-star vc0321 library
- *             Copyright (C) 2006 Koninski Artur takeshi87@o2.pl
- *             Copyright (C) 2006 Michel Xhaard
+ * Z-star vc0321 library
  *
- * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
+ * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
+ * Copyright (C) 2006 Koninski Artur takeshi87@o2.pl
+ * Copyright (C) 2006 Michel Xhaard
  *
  * 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
@@ -24,7 +24,7 @@
 
 #include "gspca.h"
 
-MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
+MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA/VC032X USB Camera Driver");
 MODULE_LICENSE("GPL");
 
@@ -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;
 }
index 7d7814c..d02aa5c 100644 (file)
@@ -40,7 +40,6 @@ 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;
@@ -80,8 +79,6 @@ 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_setautogain(struct gspca_dev *gspca_dev, __s32 val);
@@ -94,21 +91,6 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
 
 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,
-       },
        {
            {
                .id      = V4L2_CID_CONTRAST,
@@ -150,7 +132,7 @@ static const struct ctrl sd_ctrls[] = {
            .set = sd_setautogain,
            .get = sd_getautogain,
        },
-#define LIGHTFREQ_IDX 4
+#define LIGHTFREQ_IDX 3
        {
            {
                .id      = V4L2_CID_POWER_LINE_FREQUENCY,
@@ -6004,33 +5986,6 @@ static void setmatrix(struct gspca_dev *gspca_dev)
                reg_w(gspca_dev->dev, matrix[i], 0x010a + i);
 }
 
-static void setbrightness(struct gspca_dev *gspca_dev)
-{
-       struct sd *sd = (struct sd *) gspca_dev;
-       u8 brightness;
-
-       switch (sd->sensor) {
-       case SENSOR_GC0305:
-       case SENSOR_OV7620:
-       case SENSOR_PAS202B:
-       case SENSOR_PO2030:
-               return;
-       }
-/*fixme: is it really write to 011d and 018d for all other sensors? */
-       brightness = sd->brightness;
-       reg_w(gspca_dev->dev, brightness, 0x011d);
-       switch (sd->sensor) {
-       case SENSOR_ADCM2700:
-       case SENSOR_HV7131B:
-               return;
-       }
-       if (brightness < 0x70)
-               brightness += 0x10;
-       else
-               brightness = 0x80;
-       reg_w(gspca_dev->dev, brightness, 0x018d);
-}
-
 static void setsharpness(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
@@ -6059,8 +6014,8 @@ static void setcontrast(struct gspca_dev *gspca_dev)
        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};
+               {0x2c, 0x1a, 0x12, 0x0c, 0x0a, 0x06, 0x06, 0x06,
+                0x04, 0x06, 0x04, 0x04, 0x03, 0x03, 0x02, 0x02};
        static const u8 gamma_tb[6][16] = {
                {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f,
                 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff},
@@ -6082,11 +6037,11 @@ static void setcontrast(struct gspca_dev *gspca_dev)
        adj = 0;
        gp = 0;
        for (i = 0; i < 16; i++) {
-               g = Tgamma[i] - delta_tb[i] * k / 128 - adj / 2;
+               g = Tgamma[i] - delta_tb[i] * k / 256 - adj / 2;
                if (g > 0xff)
                        g = 0xff;
-               else if (g <= 0)
-                       g = 1;
+               else if (g < 0)
+                       g = 0;
                reg_w(dev, g, 0x0120 + i);      /* gamma */
                if (k > 0)
                        adj--;
@@ -6203,13 +6158,13 @@ static int setlightfreq(struct gspca_dev *gspca_dev)
                 pas106b_50HZ, pas106b_50HZ,
                 pas106b_60HZ, pas106b_60HZ},
 /* SENSOR_PAS202B 13 */
-               {pas202b_NoFlikerScale, pas202b_NoFliker,
-                pas202b_50HZScale, pas202b_50HZ,
-                pas202b_60HZScale, pas202b_60HZ},
+               {pas202b_NoFliker, pas202b_NoFlikerScale,
+                pas202b_50HZ, pas202b_50HZScale,
+                pas202b_60HZ, pas202b_60HZScale},
 /* SENSOR_PB0330 14 */
-               {pb0330_NoFlikerScale, pb0330_NoFliker,
-                pb0330_50HZScale, pb0330_50HZ,
-                pb0330_60HZScale, pb0330_60HZ},
+               {pb0330_NoFliker, pb0330_NoFlikerScale,
+                pb0330_50HZ, pb0330_50HZScale,
+                pb0330_60HZ, pb0330_60HZScale},
 /* SENSOR_PO2030 15 */
                {po2030_NoFliker, po2030_NoFliker,
                 po2030_50HZ, po2030_50HZ,
@@ -6789,7 +6744,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
                cam->nmodes = ARRAY_SIZE(broken_vga_mode);
                break;
        }
-       sd->brightness = BRIGHTNESS_DEF;
        sd->contrast = CONTRAST_DEF;
        sd->gamma = gamma[sd->sensor];
        sd->autogain = AUTOGAIN_DEF;
@@ -6797,12 +6751,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
        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;
        case SENSOR_HV7131B:
        case SENSOR_HV7131C:
        case SENSOR_OV7630C:
@@ -6893,7 +6841,6 @@ static int sd_start(struct gspca_dev *gspca_dev)
        }
 
        setmatrix(gspca_dev);
-       setbrightness(gspca_dev);
        switch (sd->sensor) {
        case SENSOR_ADCM2700:
        case SENSOR_OV7620:
@@ -7015,24 +6962,6 @@ 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;
index 2fc9865..830d47b 100644 (file)
@@ -373,9 +373,6 @@ static int hdpvr_probe(struct usb_interface *interface,
        }
 #endif /* CONFIG_I2C */
 
-       /* save our data pointer in this interface device */
-       usb_set_intfdata(interface, dev);
-
        /* let the user know what node this device is now attached to */
        v4l2_info(&dev->v4l2_dev, "device now attached to %s\n",
                  video_device_node_name(dev->video_dev));
@@ -391,44 +388,24 @@ error:
 
 static void hdpvr_disconnect(struct usb_interface *interface)
 {
-       struct hdpvr_device *dev;
-
-       dev = usb_get_intfdata(interface);
-       usb_set_intfdata(interface, NULL);
+       struct hdpvr_device *dev = to_hdpvr_dev(usb_get_intfdata(interface));
 
+       v4l2_info(&dev->v4l2_dev, "device %s disconnected\n",
+                 video_device_node_name(dev->video_dev));
        /* prevent more I/O from starting and stop any ongoing */
        mutex_lock(&dev->io_mutex);
        dev->status = STATUS_DISCONNECTED;
-       v4l2_device_disconnect(&dev->v4l2_dev);
-       video_unregister_device(dev->video_dev);
        wake_up_interruptible(&dev->wait_data);
        wake_up_interruptible(&dev->wait_buffer);
        mutex_unlock(&dev->io_mutex);
+       v4l2_device_disconnect(&dev->v4l2_dev);
        msleep(100);
        flush_workqueue(dev->workqueue);
        mutex_lock(&dev->io_mutex);
        hdpvr_cancel_queue(dev);
-       destroy_workqueue(dev->workqueue);
        mutex_unlock(&dev->io_mutex);
-
-       /* deregister I2C adapter */
-#ifdef CONFIG_I2C
-       mutex_lock(&dev->i2c_mutex);
-       if (dev->i2c_adapter)
-               i2c_del_adapter(dev->i2c_adapter);
-       kfree(dev->i2c_adapter);
-       dev->i2c_adapter = NULL;
-       mutex_unlock(&dev->i2c_mutex);
-#endif /* CONFIG_I2C */
-
+       video_unregister_device(dev->video_dev);
        atomic_dec(&dev_nr);
-
-       v4l2_info(&dev->v4l2_dev, "device %s disconnected\n",
-                 video_device_node_name(dev->video_dev));
-
-       v4l2_device_unregister(&dev->v4l2_dev);
-       kfree(dev->usbc_buf);
-       kfree(dev);
 }
 
 
index 196f82d..d2f0ee2 100644 (file)
@@ -1214,6 +1214,24 @@ static void hdpvr_device_release(struct video_device *vdev)
        struct hdpvr_device *dev = video_get_drvdata(vdev);
 
        hdpvr_delete(dev);
+       mutex_lock(&dev->io_mutex);
+       destroy_workqueue(dev->workqueue);
+       mutex_unlock(&dev->io_mutex);
+
+       v4l2_device_unregister(&dev->v4l2_dev);
+
+       /* deregister I2C adapter */
+#ifdef CONFIG_I2C
+       mutex_lock(&dev->i2c_mutex);
+       if (dev->i2c_adapter)
+               i2c_del_adapter(dev->i2c_adapter);
+       kfree(dev->i2c_adapter);
+       dev->i2c_adapter = NULL;
+       mutex_unlock(&dev->i2c_mutex);
+#endif /* CONFIG_I2C */
+
+       kfree(dev->usbc_buf);
+       kfree(dev);
 }
 
 static const struct video_device hdpvr_video_template = {
index 49ae25d..b0f046d 100644 (file)
@@ -111,6 +111,11 @@ struct hdpvr_device {
        u8                      *usbc_buf;
 };
 
+static inline struct hdpvr_device *to_hdpvr_dev(struct v4l2_device *v4l2_dev)
+{
+       return container_of(v4l2_dev, struct hdpvr_device, v4l2_dev);
+}
+
 
 /* buffer one bulk urb of data */
 struct hdpvr_buffer {
index da18d69..29d4397 100644 (file)
@@ -61,9 +61,9 @@ module_param(hauppauge, int, 0644);    /* Choose Hauppauge remote */
 MODULE_PARM_DESC(hauppauge, "Specify Hauppauge remote: 0=black, 1=grey (defaults to 0)");
 
 
-#define DEVNAME "ir-kbd-i2c"
+#define MODULE_NAME "ir-kbd-i2c"
 #define dprintk(level, fmt, arg...)    if (debug >= level) \
-       printk(KERN_DEBUG DEVNAME ": " fmt , ## arg)
+       printk(KERN_DEBUG MODULE_NAME ": " fmt , ## arg)
 
 /* ----------------------------------------------------------------------- */
 
@@ -297,7 +297,7 @@ static void ir_work(struct work_struct *work)
 
 static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        const char *name = NULL;
        u64 ir_type = 0;
        struct IR_i2c *ir;
@@ -322,13 +322,13 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
                name        = "Pixelview";
                ir->get_key = get_key_pixelview;
                ir_type     = IR_TYPE_OTHER;
-               ir_codes    = &ir_codes_empty_table;
+               ir_codes    = RC_MAP_EMPTY;
                break;
        case 0x4b:
                name        = "PV951";
                ir->get_key = get_key_pv951;
                ir_type     = IR_TYPE_OTHER;
-               ir_codes    = &ir_codes_pv951_table;
+               ir_codes    = RC_MAP_PV951;
                break;
        case 0x18:
        case 0x1f:
@@ -337,22 +337,22 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
                ir->get_key = get_key_haup;
                ir_type     = IR_TYPE_RC5;
                if (hauppauge == 1) {
-                       ir_codes    = &ir_codes_hauppauge_new_table;
+                       ir_codes    = RC_MAP_HAUPPAUGE_NEW;
                } else {
-                       ir_codes    = &ir_codes_rc5_tv_table;
+                       ir_codes    = RC_MAP_RC5_TV;
                }
                break;
        case 0x30:
                name        = "KNC One";
                ir->get_key = get_key_knc1;
                ir_type     = IR_TYPE_OTHER;
-               ir_codes    = &ir_codes_empty_table;
+               ir_codes    = RC_MAP_EMPTY;
                break;
        case 0x6b:
                name        = "FusionHDTV";
                ir->get_key = get_key_fusionhdtv;
                ir_type     = IR_TYPE_RC5;
-               ir_codes    = &ir_codes_fusionhdtv_mce_table;
+               ir_codes    = RC_MAP_FUSIONHDTV_MCE;
                break;
        case 0x0b:
        case 0x47:
@@ -365,9 +365,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
                        ir_type     = IR_TYPE_RC5;
                        ir->get_key = get_key_haup_xvr;
                        if (hauppauge == 1) {
-                               ir_codes    = &ir_codes_hauppauge_new_table;
+                               ir_codes    = RC_MAP_HAUPPAUGE_NEW;
                        } else {
-                               ir_codes    = &ir_codes_rc5_tv_table;
+                               ir_codes    = RC_MAP_RC5_TV;
                        }
                } else {
                        /* Handled by saa7134-input */
@@ -379,7 +379,7 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
                name        = "AVerMedia Cardbus remote";
                ir->get_key = get_key_avermedia_cardbus;
                ir_type     = IR_TYPE_OTHER;
-               ir_codes    = &ir_codes_avermedia_cardbus_table;
+               ir_codes    = RC_MAP_AVERMEDIA_CARDBUS;
                break;
        }
 
@@ -447,11 +447,11 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
        input_dev->name       = ir->name;
        input_dev->phys       = ir->phys;
 
-       err = ir_input_register(ir->input, ir->ir_codes, NULL);
+       err = ir_input_register(ir->input, ir->ir_codes, NULL, MODULE_NAME);
        if (err)
                goto err_out_free;
 
-       printk(DEVNAME ": %s detected at %s [%s]\n",
+       printk(MODULE_NAME ": %s detected at %s [%s]\n",
               ir->input->name, ir->input->phys, adap->name);
 
        /* start polling via eventd */
index 9a25054..1b79475 100644 (file)
@@ -1293,7 +1293,6 @@ int ivtv_init_on_first_open(struct ivtv *itv)
                ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_stream, 1);
                ivtv_init_mpeg_decoder(itv);
        }
-       ivtv_s_std(NULL, &fh, &itv->tuner_std);
 
        /* On a cx23416 this seems to be able to enable DMA to the chip? */
        if (!itv->has_cx23415)
@@ -1310,6 +1309,10 @@ int ivtv_init_on_first_open(struct ivtv *itv)
        }
        else
                ivtv_clear_irq_mask(itv, IVTV_IRQ_MASK_INIT);
+
+       /* For cards with video out, this call needs interrupts enabled */
+       ivtv_s_std(NULL, &fh, &itv->tuner_std);
+
        return 0;
 }
 
index 5028e31..5b45fd2 100644 (file)
@@ -63,6 +63,7 @@
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-device.h>
+#include <media/v4l2-fh.h>
 #include <media/tuner.h>
 #include <media/cx2341x.h>
 #include <media/ir-kbd-i2c.h>
 #define IVTV_REG_VPU                   (0x9058)
 #define IVTV_REG_APU                   (0xA064)
 
+/* Other registers */
+#define IVTV_REG_DEC_LINE_FIELD                (0x28C0)
+
 /* debugging */
 extern int ivtv_debug;
 
@@ -372,6 +376,7 @@ struct ivtv_stream {
 };
 
 struct ivtv_open_id {
+       struct v4l2_fh fh;
        u32 open_id;                    /* unique ID for this file descriptor */
        int type;                       /* stream type */
        int yuv_frames;                 /* 1: started OUT_UDMA_YUV output mode */
@@ -379,6 +384,11 @@ struct ivtv_open_id {
        struct ivtv *itv;
 };
 
+static inline struct ivtv_open_id *fh2id(struct v4l2_fh *fh)
+{
+       return container_of(fh, struct ivtv_open_id, fh);
+}
+
 struct yuv_frame_info
 {
        u32 update;
index babcabd..abf4109 100644 (file)
@@ -32,6 +32,7 @@
 #include "ivtv-yuv.h"
 #include "ivtv-ioctl.h"
 #include "ivtv-cards.h"
+#include <media/v4l2-event.h>
 #include <media/saa7115.h>
 
 /* This function tries to claim the stream for a specific file descriptor.
@@ -506,7 +507,7 @@ int ivtv_start_capture(struct ivtv_open_id *id)
 
 ssize_t ivtv_v4l2_read(struct file * filp, char __user *buf, size_t count, loff_t * pos)
 {
-       struct ivtv_open_id *id = filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
        int rc;
@@ -541,7 +542,7 @@ int ivtv_start_decoding(struct ivtv_open_id *id, int speed)
 
 ssize_t ivtv_v4l2_write(struct file *filp, const char __user *user_buf, size_t count, loff_t *pos)
 {
-       struct ivtv_open_id *id = filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
        struct yuv_playback_info *yi = &itv->yuv_info;
@@ -711,19 +712,31 @@ retry:
 
 unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
 {
-       struct ivtv_open_id *id = filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
        int res = 0;
 
        /* add stream's waitq to the poll list */
        IVTV_DEBUG_HI_FILE("Decoder poll\n");
-       poll_wait(filp, &s->waitq, wait);
 
-       set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
-       if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) ||
-           test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
-               res = POLLPRI;
+       /* If there are subscribed events, then only use the new event
+          API instead of the old video.h based API. */
+       if (!list_empty(&id->fh.events->subscribed)) {
+               poll_wait(filp, &id->fh.events->wait, wait);
+               /* Turn off the old-style vsync events */
+               clear_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
+               if (v4l2_event_pending(&id->fh))
+                       res = POLLPRI;
+       } else {
+               /* This is the old-style API which is here only for backwards
+                  compatibility. */
+               poll_wait(filp, &s->waitq, wait);
+               set_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags);
+               if (test_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags) ||
+                   test_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags))
+                       res = POLLPRI;
+       }
 
        /* Allow write if buffers are available for writing */
        if (s->q_free.buffers)
@@ -733,7 +746,7 @@ unsigned int ivtv_v4l2_dec_poll(struct file *filp, poll_table *wait)
 
 unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
 {
-       struct ivtv_open_id *id = filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
        int eof = test_bit(IVTV_F_S_STREAMOFF, &s->s_flags);
@@ -833,13 +846,16 @@ static void ivtv_stop_decoding(struct ivtv_open_id *id, int flags, u64 pts)
 
 int ivtv_v4l2_close(struct file *filp)
 {
-       struct ivtv_open_id *id = filp->private_data;
+       struct v4l2_fh *fh = filp->private_data;
+       struct ivtv_open_id *id = fh2id(fh);
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[id->type];
 
        IVTV_DEBUG_FILE("close %s\n", s->name);
 
-       v4l2_prio_close(&itv->prio, &id->prio);
+       v4l2_prio_close(&itv->prio, id->prio);
+       v4l2_fh_del(fh);
+       v4l2_fh_exit(fh);
 
        /* Easy case first: this stream was never claimed by us */
        if (s->id != id->open_id) {
@@ -895,6 +911,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
 {
        struct ivtv *itv = s->itv;
        struct ivtv_open_id *item;
+       int res = 0;
 
        IVTV_DEBUG_FILE("open %s\n", s->name);
 
@@ -915,17 +932,27 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
        }
 
        /* Allocate memory */
-       item = kmalloc(sizeof(struct ivtv_open_id), GFP_KERNEL);
+       item = kzalloc(sizeof(struct ivtv_open_id), GFP_KERNEL);
        if (NULL == item) {
                IVTV_DEBUG_WARN("nomem on v4l2 open\n");
                return -ENOMEM;
        }
+       v4l2_fh_init(&item->fh, s->vdev);
+       if (s->type == IVTV_DEC_STREAM_TYPE_YUV ||
+           s->type == IVTV_DEC_STREAM_TYPE_MPG) {
+               res = v4l2_event_alloc(&item->fh, 60);
+       }
+       if (res < 0) {
+               v4l2_fh_exit(&item->fh);
+               kfree(item);
+               return res;
+       }
        item->itv = itv;
        item->type = s->type;
        v4l2_prio_open(&itv->prio, &item->prio);
 
        item->open_id = itv->open_id++;
-       filp->private_data = item;
+       filp->private_data = &item->fh;
 
        if (item->type == IVTV_ENC_STREAM_TYPE_RAD) {
                /* Try to claim this stream */
@@ -940,6 +967,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
                                /* switching to radio while capture is
                                   in progress is not polite */
                                ivtv_release_stream(s);
+                               v4l2_fh_exit(&item->fh);
                                kfree(item);
                                return -EBUSY;
                        }
@@ -970,6 +998,7 @@ static int ivtv_serialized_open(struct ivtv_stream *s, struct file *filp)
                                1080 * ((itv->yuv_info.v4l2_src_h + 31) & ~31);
                itv->yuv_info.stream_size = 0;
        }
+       v4l2_fh_add(&item->fh);
        return 0;
 }
 
index 2ee03c2..a5b92d1 100644 (file)
@@ -193,7 +193,7 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
        /* Our default information for ir-kbd-i2c.c to use */
        switch (hw) {
        case IVTV_HW_I2C_IR_RX_AVER:
-               init_data->ir_codes = &ir_codes_avermedia_cardbus_table;
+               init_data->ir_codes = RC_MAP_AVERMEDIA_CARDBUS;
                init_data->internal_get_key_func =
                                        IR_KBD_GET_KEY_AVERMEDIA_CARDBUS;
                init_data->type = IR_TYPE_OTHER;
@@ -202,14 +202,14 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr)
        case IVTV_HW_I2C_IR_RX_HAUP_EXT:
        case IVTV_HW_I2C_IR_RX_HAUP_INT:
                /* Default to old black remote */
-               init_data->ir_codes = &ir_codes_rc5_tv_table;
+               init_data->ir_codes = RC_MAP_RC5_TV;
                init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP;
                init_data->type = IR_TYPE_RC5;
                init_data->name = itv->card_name;
                break;
        case IVTV_HW_Z8F0811_IR_RX_HAUP:
                /* Default to grey remote */
-               init_data->ir_codes = &ir_codes_hauppauge_new_table;
+               init_data->ir_codes = RC_MAP_HAUPPAUGE_NEW;
                init_data->internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
                init_data->type = IR_TYPE_RC5;
                init_data->name = itv->card_name;
index 99f3c39..fa9f0d9 100644 (file)
@@ -35,6 +35,7 @@
 #include <media/saa7127.h>
 #include <media/tveeprom.h>
 #include <media/v4l2-chip-ident.h>
+#include <media/v4l2-event.h>
 #include <linux/dvb/audio.h>
 #include <linux/i2c-id.h>
 
@@ -391,7 +392,7 @@ static int ivtv_g_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
                return 0;
        }
 
-       v4l2_subdev_call(itv->sd_video, video, g_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, g_sliced_fmt, vbifmt);
        vbifmt->service_set = ivtv_get_service_set(vbifmt);
        return 0;
 }
@@ -597,7 +598,7 @@ static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f
                return -EBUSY;
        itv->vbi.sliced_in->service_set = 0;
        itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
-       v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, s_raw_fmt, &fmt->fmt.vbi);
        return ivtv_g_fmt_vbi_cap(file, fh, fmt);
 }
 
@@ -615,7 +616,7 @@ static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
        if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
                return -EBUSY;
        itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
-       v4l2_subdev_call(itv->sd_video, video, s_fmt, fmt);
+       v4l2_subdev_call(itv->sd_video, vbi, s_sliced_fmt, vbifmt);
        memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
        return 0;
 }
@@ -1087,8 +1088,10 @@ static int ivtv_g_std(struct file *file, void *fh, v4l2_std_id *std)
 
 int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
 {
+       DEFINE_WAIT(wait);
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
        struct yuv_playback_info *yi = &itv->yuv_info;
+       int f;
 
        if ((*std & V4L2_STD_ALL) == 0)
                return -EINVAL;
@@ -1128,6 +1131,25 @@ int ivtv_s_std(struct file *file, void *fh, v4l2_std_id *std)
                itv->is_out_60hz = itv->is_60hz;
                itv->is_out_50hz = itv->is_50hz;
                ivtv_call_all(itv, video, s_std_output, itv->std_out);
+
+               /*
+                * The next firmware call is time sensitive. Time it to
+                * avoid risk of a hard lock, by trying to ensure the call
+                * happens within the first 100 lines of the top field.
+                * Make 4 attempts to sync to the decoder before giving up.
+                */
+               for (f = 0; f < 4; f++) {
+                       prepare_to_wait(&itv->vsync_waitq, &wait,
+                                       TASK_UNINTERRUPTIBLE);
+                       if ((read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16) < 100)
+                               break;
+                       schedule_timeout(msecs_to_jiffies(25));
+               }
+               finish_wait(&itv->vsync_waitq, &wait);
+
+               if (f == 4)
+                       IVTV_WARN("Mode change failed to sync to decoder\n");
+
                ivtv_vapi(itv, CX2341X_DEC_SET_STANDARD, 1, itv->is_out_50hz);
                itv->main_rect.left = itv->main_rect.top = 0;
                itv->main_rect.width = 720;
@@ -1431,6 +1453,18 @@ static int ivtv_overlay(struct file *file, void *fh, unsigned int on)
        return 0;
 }
 
+static int ivtv_subscribe_event(struct v4l2_fh *fh, struct v4l2_event_subscription *sub)
+{
+       switch (sub->type) {
+       case V4L2_EVENT_VSYNC:
+       case V4L2_EVENT_EOS:
+               break;
+       default:
+               return -EINVAL;
+       }
+       return v4l2_event_subscribe(fh, sub);
+}
+
 static int ivtv_log_status(struct file *file, void *fh)
 {
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
@@ -1539,10 +1573,11 @@ static int ivtv_log_status(struct file *file, void *fh)
 
 static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
 {
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        int nonblocking = filp->f_flags & O_NONBLOCK;
        struct ivtv_stream *s = &itv->streams[id->type];
+       unsigned long iarg = (unsigned long)arg;
 
        switch (cmd) {
        case IVTV_IOC_DMA_FRAME: {
@@ -1724,6 +1759,33 @@ static int ivtv_decoder_ioctls(struct file *filp, unsigned int cmd, void *arg)
                break;
        }
 
+       case VIDEO_SELECT_SOURCE:
+               IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
+               if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
+                       return -EINVAL;
+               return ivtv_passthrough_mode(itv, iarg == VIDEO_SOURCE_DEMUX);
+
+       case AUDIO_SET_MUTE:
+               IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
+               itv->speed_mute_audio = iarg;
+               return 0;
+
+       case AUDIO_CHANNEL_SELECT:
+               IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
+               if (iarg > AUDIO_STEREO_SWAPPED)
+                       return -EINVAL;
+               itv->audio_stereo_mode = iarg;
+               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
+               return 0;
+
+       case AUDIO_BILINGUAL_CHANNEL_SELECT:
+               IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
+               if (iarg > AUDIO_STEREO_SWAPPED)
+                       return -EINVAL;
+               itv->audio_bilingual_mode = iarg;
+               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
+               return 0;
+
        default:
                return -EINVAL;
        }
@@ -1755,6 +1817,10 @@ static long ivtv_default(struct file *file, void *fh, int cmd, void *arg)
        case VIDEO_CONTINUE:
        case VIDEO_COMMAND:
        case VIDEO_TRY_COMMAND:
+       case VIDEO_SELECT_SOURCE:
+       case AUDIO_SET_MUTE:
+       case AUDIO_CHANNEL_SELECT:
+       case AUDIO_BILINGUAL_CHANNEL_SELECT:
                return ivtv_decoder_ioctls(file, cmd, (void *)arg);
 
        default:
@@ -1767,42 +1833,9 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
                unsigned int cmd, unsigned long arg)
 {
        struct video_device *vfd = video_devdata(filp);
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        long ret;
 
-       /* Filter dvb ioctls that cannot be handled by the v4l ioctl framework */
-       switch (cmd) {
-       case VIDEO_SELECT_SOURCE:
-               IVTV_DEBUG_IOCTL("VIDEO_SELECT_SOURCE\n");
-               if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
-                       return -EINVAL;
-               return ivtv_passthrough_mode(itv, arg == VIDEO_SOURCE_DEMUX);
-
-       case AUDIO_SET_MUTE:
-               IVTV_DEBUG_IOCTL("AUDIO_SET_MUTE\n");
-               itv->speed_mute_audio = arg;
-               return 0;
-
-       case AUDIO_CHANNEL_SELECT:
-               IVTV_DEBUG_IOCTL("AUDIO_CHANNEL_SELECT\n");
-               if (arg > AUDIO_STEREO_SWAPPED)
-                       return -EINVAL;
-               itv->audio_stereo_mode = arg;
-               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
-               return 0;
-
-       case AUDIO_BILINGUAL_CHANNEL_SELECT:
-               IVTV_DEBUG_IOCTL("AUDIO_BILINGUAL_CHANNEL_SELECT\n");
-               if (arg > AUDIO_STEREO_SWAPPED)
-                       return -EINVAL;
-               itv->audio_bilingual_mode = arg;
-               ivtv_vapi(itv, CX2341X_DEC_SET_AUDIO_MODE, 2, itv->audio_bilingual_mode, itv->audio_stereo_mode);
-               return 0;
-
-       default:
-               break;
-       }
-
        /* check priority */
        switch (cmd) {
        case VIDIOC_S_CTRL:
@@ -1817,8 +1850,9 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
        case VIDIOC_S_AUDOUT:
        case VIDIOC_S_EXT_CTRLS:
        case VIDIOC_S_FBUF:
+       case VIDIOC_S_PRIORITY:
        case VIDIOC_OVERLAY:
-               ret = v4l2_prio_check(&itv->prio, &id->prio);
+               ret = v4l2_prio_check(&itv->prio, id->prio);
                if (ret)
                        return ret;
        }
@@ -1832,10 +1866,13 @@ static long ivtv_serialized_ioctl(struct ivtv *itv, struct file *filp,
 
 long ivtv_v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
-       struct ivtv_open_id *id = (struct ivtv_open_id *)filp->private_data;
+       struct ivtv_open_id *id = fh2id(filp->private_data);
        struct ivtv *itv = id->itv;
        long res;
 
+       /* DQEVENT can block, so this should not run with the serialize lock */
+       if (cmd == VIDIOC_DQEVENT)
+               return ivtv_serialized_ioctl(itv, filp, cmd, arg);
        mutex_lock(&itv->serialize_lock);
        res = ivtv_serialized_ioctl(itv, filp, cmd, arg);
        mutex_unlock(&itv->serialize_lock);
@@ -1906,6 +1943,8 @@ static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
        .vidioc_g_ext_ctrls                 = ivtv_g_ext_ctrls,
        .vidioc_s_ext_ctrls                 = ivtv_s_ext_ctrls,
        .vidioc_try_ext_ctrls               = ivtv_try_ext_ctrls,
+       .vidioc_subscribe_event             = ivtv_subscribe_event,
+       .vidioc_unsubscribe_event           = v4l2_event_unsubscribe,
 };
 
 void ivtv_set_funcs(struct video_device *vdev)
index 12d36ca..fea1ec3 100644 (file)
@@ -25,6 +25,7 @@
 #include "ivtv-mailbox.h"
 #include "ivtv-vbi.h"
 #include "ivtv-yuv.h"
+#include <media/v4l2-event.h>
 
 #define DMA_MAGIC_COOKIE 0x000001fe
 
@@ -752,7 +753,7 @@ static void ivtv_irq_vsync(struct ivtv *itv)
         * to determine the line being displayed and ensure we handle
         * one vsync per frame.
         */
-       unsigned int frame = read_reg(0x28c0) & 1;
+       unsigned int frame = read_reg(IVTV_REG_DEC_LINE_FIELD) & 1;
        struct yuv_playback_info *yi = &itv->yuv_info;
        int last_dma_frame = atomic_read(&yi->next_dma_frame);
        struct yuv_frame_info *f = &yi->new_frame_info[last_dma_frame];
@@ -778,6 +779,14 @@ static void ivtv_irq_vsync(struct ivtv *itv)
                }
        }
        if (frame != (itv->last_vsync_field & 1)) {
+               static const struct v4l2_event evtop = {
+                       .type = V4L2_EVENT_VSYNC,
+                       .u.vsync.field = V4L2_FIELD_TOP,
+               };
+               static const struct v4l2_event evbottom = {
+                       .type = V4L2_EVENT_VSYNC,
+                       .u.vsync.field = V4L2_FIELD_BOTTOM,
+               };
                struct ivtv_stream *s = ivtv_get_output_stream(itv);
 
                itv->last_vsync_field += 1;
@@ -791,10 +800,12 @@ static void ivtv_irq_vsync(struct ivtv *itv)
                if (test_bit(IVTV_F_I_EV_VSYNC_ENABLED, &itv->i_flags)) {
                        set_bit(IVTV_F_I_EV_VSYNC, &itv->i_flags);
                        wake_up(&itv->event_waitq);
+                       if (s)
+                               wake_up(&s->waitq);
                }
+               if (s && s->vdev)
+                       v4l2_event_queue(s->vdev, frame ? &evtop : &evbottom);
                wake_up(&itv->vsync_waitq);
-               if (s)
-                       wake_up(&s->waitq);
 
                /* Send VBI to saa7127 */
                if (frame && (itv->output_mode == OUT_PASSTHROUGH ||
@@ -852,9 +863,11 @@ irqreturn_t ivtv_irq_handler(int irq, void *dev_id)
                 */
                if (~itv->irqmask & IVTV_IRQ_DEC_VSYNC) {
                        /* vsync is enabled, see if we're in a new field */
-                       if ((itv->last_vsync_field & 1) != (read_reg(0x28c0) & 1)) {
+                       if ((itv->last_vsync_field & 1) !=
+                           (read_reg(IVTV_REG_DEC_LINE_FIELD) & 1)) {
                                /* New field, looks like we missed it */
-                               IVTV_DEBUG_YUV("VSync interrupt missed %d\n",read_reg(0x28c0)>>16);
+                               IVTV_DEBUG_YUV("VSync interrupt missed %d\n",
+                                      read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16);
                                vsync_force = 1;
                        }
                }
index 1f9387f..de4288c 100644 (file)
@@ -42,6 +42,7 @@
 #include "ivtv-yuv.h"
 #include "ivtv-cards.h"
 #include "ivtv-streams.h"
+#include <media/v4l2-event.h>
 
 static const struct v4l2_file_operations ivtv_v4l2_enc_fops = {
        .owner = THIS_MODULE,
@@ -343,7 +344,10 @@ static void ivtv_vbi_setup(struct ivtv *itv)
        ivtv_vapi(itv, CX2341X_ENC_SET_VBI_LINE, 5, 0xffff , 0, 0, 0, 0);
 
        /* setup VBI registers */
-       v4l2_subdev_call(itv->sd_video, video, s_fmt, &itv->vbi.in);
+       if (raw)
+               v4l2_subdev_call(itv->sd_video, vbi, s_raw_fmt, &itv->vbi.in.fmt.vbi);
+       else
+               v4l2_subdev_call(itv->sd_video, vbi, s_sliced_fmt, &itv->vbi.in.fmt.sliced);
 
        /* determine number of lines and total number of VBI bytes.
           A raw line takes 1443 bytes: 2 * 720 + 4 byte frame header - 1
@@ -581,10 +585,9 @@ int ivtv_start_v4l2_encode_stream(struct ivtv_stream *s)
                v4l2_subdev_call(itv->sd_audio, audio, s_stream, 1);
                /* Avoid unpredictable PCI bus hang - disable video clocks */
                v4l2_subdev_call(itv->sd_video, video, s_stream, 0);
-               ivtv_msleep_timeout(150, 1);
+               ivtv_msleep_timeout(300, 1);
                ivtv_vapi(itv, CX2341X_ENC_INITIALIZE_INPUT, 0);
                v4l2_subdev_call(itv->sd_video, video, s_stream, 1);
-               ivtv_msleep_timeout(150, 1);
        }
 
        /* begin_capture */
@@ -830,6 +833,10 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
                ivtv_set_irq_mask(itv, IVTV_IRQ_ENC_VIM_RST);
        }
 
+       /* Raw-passthrough is implied on start. Make sure it's stopped so
+          the encoder will re-initialize when next started */
+       ivtv_vapi(itv, CX2341X_ENC_STOP_CAPTURE, 3, 1, 2, 7);
+
        wake_up(&s->waitq);
 
        return 0;
@@ -837,6 +844,9 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
 
 int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
 {
+       static const struct v4l2_event ev = {
+               .type = V4L2_EVENT_EOS,
+       };
        struct ivtv *itv = s->itv;
 
        if (s->vdev == NULL)
@@ -888,6 +898,7 @@ int ivtv_stop_v4l2_decode_stream(struct ivtv_stream *s, int flags, u64 pts)
 
        set_bit(IVTV_F_I_EV_DEC_STOPPED, &itv->i_flags);
        wake_up(&itv->event_waitq);
+       v4l2_event_queue(s->vdev, &ev);
 
        /* wake up wait queues */
        wake_up(&s->waitq);
index f420d31..e1c347e 100644 (file)
@@ -38,7 +38,7 @@ static void ivtv_set_vps(struct ivtv *itv, int enabled)
        data.data[9] = itv->vbi.vps_payload.data[2];
        data.data[10] = itv->vbi.vps_payload.data[3];
        data.data[11] = itv->vbi.vps_payload.data[4];
-       ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
+       ivtv_call_hw(itv, IVTV_HW_SAA7127, vbi, s_vbi_data, &data);
 }
 
 static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc)
@@ -52,12 +52,12 @@ static void ivtv_set_cc(struct ivtv *itv, int mode, const struct vbi_cc *cc)
        data.line = (mode & 1) ? 21 : 0;
        data.data[0] = cc->odd[0];
        data.data[1] = cc->odd[1];
-       ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
+       ivtv_call_hw(itv, IVTV_HW_SAA7127, vbi, s_vbi_data, &data);
        data.field = 1;
        data.line = (mode & 2) ? 21 : 0;
        data.data[0] = cc->even[0];
        data.data[1] = cc->even[1];
-       ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
+       ivtv_call_hw(itv, IVTV_HW_SAA7127, vbi, s_vbi_data, &data);
 }
 
 static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
@@ -80,7 +80,7 @@ static void ivtv_set_wss(struct ivtv *itv, int enabled, int mode)
        data.line = enabled ? 23 : 0;
        data.data[0] = mode & 0xff;
        data.data[1] = (mode >> 8) & 0xff;
-       ivtv_call_hw(itv, IVTV_HW_SAA7127, video, s_vbi_data, &data);
+       ivtv_call_hw(itv, IVTV_HW_SAA7127, vbi, s_vbi_data, &data);
 }
 
 static int odd_parity(u8 c)
@@ -134,7 +134,7 @@ void ivtv_write_vbi(struct ivtv *itv, const struct v4l2_sliced_vbi_data *sliced,
                        }
                }
        }
-       if (found_cc && vi->cc_payload_idx < sizeof(vi->cc_payload)) {
+       if (found_cc && vi->cc_payload_idx < ARRAY_SIZE(vi->cc_payload)) {
                vi->cc_payload[vi->cc_payload_idx++] = cc;
                set_bit(IVTV_F_I_UPDATE_CC, &itv->i_flags);
        }
@@ -316,7 +316,7 @@ static u32 compress_sliced_buf(struct ivtv *itv, u32 line, u8 *buf, u32 size, u8
                        continue;
                }
                vbi.p = p + 4;
-               v4l2_subdev_call(itv->sd_video, video, decode_vbi_line, &vbi);
+               v4l2_subdev_call(itv->sd_video, vbi, decode_vbi_line, &vbi);
                if (vbi.type && !(lines & (1 << vbi.line))) {
                        lines |= 1 << vbi.line;
                        itv->vbi.sliced_data[line].id = vbi.type;
@@ -440,7 +440,7 @@ void ivtv_vbi_work_handler(struct ivtv *itv)
                        data.id = V4L2_SLICED_WSS_625;
                        data.field = 0;
 
-                       if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
+                       if (v4l2_subdev_call(itv->sd_video, vbi, g_vbi_data, &data) == 0) {
                                ivtv_set_wss(itv, 1, data.data[0] & 0xf);
                                vi->wss_missing_cnt = 0;
                        } else if (vi->wss_missing_cnt == 4) {
@@ -454,13 +454,13 @@ void ivtv_vbi_work_handler(struct ivtv *itv)
 
                        data.id = V4L2_SLICED_CAPTION_525;
                        data.field = 0;
-                       if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
+                       if (v4l2_subdev_call(itv->sd_video, vbi, g_vbi_data, &data) == 0) {
                                mode |= 1;
                                cc.odd[0] = data.data[0];
                                cc.odd[1] = data.data[1];
                        }
                        data.field = 1;
-                       if (v4l2_subdev_call(itv->sd_video, video, g_vbi_data, &data) == 0) {
+                       if (v4l2_subdev_call(itv->sd_video, vbi, g_vbi_data, &data) == 0) {
                                mode |= 2;
                                cc.even[0] = data.data[0];
                                cc.even[1] = data.data[1];
index de2ff1c..49e1a28 100644 (file)
@@ -460,7 +460,7 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
 
                        vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
                                        FB_VBLANK_HAVE_VSYNC;
-                       trace = read_reg(0x028c0) >> 16;
+                       trace = read_reg(IVTV_REG_DEC_LINE_FIELD) >> 16;
                        if (itv->is_50hz && trace > 312)
                                trace -= 312;
                        else if (itv->is_60hz && trace > 262)
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
new file mode 100644 (file)
index 0000000..554eaf1
--- /dev/null
@@ -0,0 +1,1052 @@
+/*
+ * A virtual v4l2-mem2mem example device.
+ *
+ * This is a virtual device driver for testing mem-to-mem videobuf framework.
+ * It simulates a device that uses memory buffers for both source and
+ * destination, processes the data and issues an "irq" (simulated by a timer).
+ * The device is capable of multi-instance, multi-buffer-per-transaction
+ * operation (via the mem2mem framework).
+ *
+ * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
+ * Pawel Osciak, <p.osciak@samsung.com>
+ * Marek Szyprowski, <m.szyprowski@samsung.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
+ */
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/fs.h>
+#include <linux/version.h>
+#include <linux/timer.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include <linux/platform_device.h>
+#include <media/v4l2-mem2mem.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/videobuf-vmalloc.h>
+
+#define MEM2MEM_TEST_MODULE_NAME "mem2mem-testdev"
+
+MODULE_DESCRIPTION("Virtual device for mem2mem framework testing");
+MODULE_AUTHOR("Pawel Osciak, <p.osciak@samsung.com>");
+MODULE_LICENSE("GPL");
+
+
+#define MIN_W 32
+#define MIN_H 32
+#define MAX_W 640
+#define MAX_H 480
+#define DIM_ALIGN_MASK 0x08 /* 8-alignment for dimensions */
+
+/* Flags that indicate a format can be used for capture/output */
+#define MEM2MEM_CAPTURE        (1 << 0)
+#define MEM2MEM_OUTPUT (1 << 1)
+
+#define MEM2MEM_NAME           "m2m-testdev"
+
+/* Per queue */
+#define MEM2MEM_DEF_NUM_BUFS   VIDEO_MAX_FRAME
+/* In bytes, per queue */
+#define MEM2MEM_VID_MEM_LIMIT  (16 * 1024 * 1024)
+
+/* Default transaction time in msec */
+#define MEM2MEM_DEF_TRANSTIME  1000
+/* Default number of buffers per transaction */
+#define MEM2MEM_DEF_TRANSLEN   1
+#define MEM2MEM_COLOR_STEP     (0xff >> 4)
+#define MEM2MEM_NUM_TILES      8
+
+#define dprintk(dev, fmt, arg...) \
+       v4l2_dbg(1, 1, &dev->v4l2_dev, "%s: " fmt, __func__, ## arg)
+
+
+void m2mtest_dev_release(struct device *dev)
+{}
+
+static struct platform_device m2mtest_pdev = {
+       .name           = MEM2MEM_NAME,
+       .dev.release    = m2mtest_dev_release,
+};
+
+struct m2mtest_fmt {
+       char    *name;
+       u32     fourcc;
+       int     depth;
+       /* Types the format can be used for */
+       u32     types;
+};
+
+static struct m2mtest_fmt formats[] = {
+       {
+               .name   = "RGB565 (BE)",
+               .fourcc = V4L2_PIX_FMT_RGB565X, /* rrrrrggg gggbbbbb */
+               .depth  = 16,
+               /* Both capture and output format */
+               .types  = MEM2MEM_CAPTURE | MEM2MEM_OUTPUT,
+       },
+       {
+               .name   = "4:2:2, packed, YUYV",
+               .fourcc = V4L2_PIX_FMT_YUYV,
+               .depth  = 16,
+               /* Output-only format */
+               .types  = MEM2MEM_OUTPUT,
+       },
+};
+
+/* Per-queue, driver-specific private data */
+struct m2mtest_q_data {
+       unsigned int            width;
+       unsigned int            height;
+       unsigned int            sizeimage;
+       struct m2mtest_fmt      *fmt;
+};
+
+enum {
+       V4L2_M2M_SRC = 0,
+       V4L2_M2M_DST = 1,
+};
+
+/* Source and destination queue data */
+static struct m2mtest_q_data q_data[2];
+
+static struct m2mtest_q_data *get_q_data(enum v4l2_buf_type type)
+{
+       switch (type) {
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+               return &q_data[V4L2_M2M_SRC];
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               return &q_data[V4L2_M2M_DST];
+       default:
+               BUG();
+       }
+       return NULL;
+}
+
+#define V4L2_CID_TRANS_TIME_MSEC       V4L2_CID_PRIVATE_BASE
+#define V4L2_CID_TRANS_NUM_BUFS                (V4L2_CID_PRIVATE_BASE + 1)
+
+static struct v4l2_queryctrl m2mtest_ctrls[] = {
+       {
+               .id             = V4L2_CID_TRANS_TIME_MSEC,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Transaction time (msec)",
+               .minimum        = 1,
+               .maximum        = 10000,
+               .step           = 100,
+               .default_value  = 1000,
+               .flags          = 0,
+       }, {
+               .id             = V4L2_CID_TRANS_NUM_BUFS,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Buffers per transaction",
+               .minimum        = 1,
+               .maximum        = MEM2MEM_DEF_NUM_BUFS,
+               .step           = 1,
+               .default_value  = 1,
+               .flags          = 0,
+       },
+};
+
+#define NUM_FORMATS ARRAY_SIZE(formats)
+
+static struct m2mtest_fmt *find_format(struct v4l2_format *f)
+{
+       struct m2mtest_fmt *fmt;
+       unsigned int k;
+
+       for (k = 0; k < NUM_FORMATS; k++) {
+               fmt = &formats[k];
+               if (fmt->fourcc == f->fmt.pix.pixelformat)
+                       break;
+       }
+
+       if (k == NUM_FORMATS)
+               return NULL;
+
+       return &formats[k];
+}
+
+struct m2mtest_dev {
+       struct v4l2_device      v4l2_dev;
+       struct video_device     *vfd;
+
+       atomic_t                num_inst;
+       struct mutex            dev_mutex;
+       spinlock_t              irqlock;
+
+       struct timer_list       timer;
+
+       struct v4l2_m2m_dev     *m2m_dev;
+};
+
+struct m2mtest_ctx {
+       struct m2mtest_dev      *dev;
+
+       /* Processed buffers in this transaction */
+       u8                      num_processed;
+
+       /* Transaction length (i.e. how many buffers per transaction) */
+       u32                     translen;
+       /* Transaction time (i.e. simulated processing time) in milliseconds */
+       u32                     transtime;
+
+       /* Abort requested by m2m */
+       int                     aborting;
+
+       struct v4l2_m2m_ctx     *m2m_ctx;
+};
+
+struct m2mtest_buffer {
+       /* vb must be first! */
+       struct videobuf_buffer  vb;
+};
+
+static struct v4l2_queryctrl *get_ctrl(int id)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(m2mtest_ctrls); ++i) {
+               if (id == m2mtest_ctrls[i].id)
+                       return &m2mtest_ctrls[i];
+       }
+
+       return NULL;
+}
+
+static int device_process(struct m2mtest_ctx *ctx,
+                         struct m2mtest_buffer *in_buf,
+                         struct m2mtest_buffer *out_buf)
+{
+       struct m2mtest_dev *dev = ctx->dev;
+       u8 *p_in, *p_out;
+       int x, y, t, w;
+       int tile_w, bytes_left;
+       struct videobuf_queue *src_q;
+       struct videobuf_queue *dst_q;
+
+       src_q = v4l2_m2m_get_src_vq(ctx->m2m_ctx);
+       dst_q = v4l2_m2m_get_dst_vq(ctx->m2m_ctx);
+       p_in = videobuf_queue_to_vaddr(src_q, &in_buf->vb);
+       p_out = videobuf_queue_to_vaddr(dst_q, &out_buf->vb);
+       if (!p_in || !p_out) {
+               v4l2_err(&dev->v4l2_dev,
+                        "Acquiring kernel pointers to buffers failed\n");
+               return -EFAULT;
+       }
+
+       if (in_buf->vb.size < out_buf->vb.size) {
+               v4l2_err(&dev->v4l2_dev, "Output buffer is too small\n");
+               return -EINVAL;
+       }
+
+       tile_w = (in_buf->vb.width * (q_data[V4L2_M2M_DST].fmt->depth >> 3))
+               / MEM2MEM_NUM_TILES;
+       bytes_left = in_buf->vb.bytesperline - tile_w * MEM2MEM_NUM_TILES;
+       w = 0;
+
+       for (y = 0; y < in_buf->vb.height; ++y) {
+               for (t = 0; t < MEM2MEM_NUM_TILES; ++t) {
+                       if (w & 0x1) {
+                               for (x = 0; x < tile_w; ++x)
+                                       *p_out++ = *p_in++ + MEM2MEM_COLOR_STEP;
+                       } else {
+                               for (x = 0; x < tile_w; ++x)
+                                       *p_out++ = *p_in++ - MEM2MEM_COLOR_STEP;
+                       }
+                       ++w;
+               }
+               p_in += bytes_left;
+               p_out += bytes_left;
+       }
+
+       return 0;
+}
+
+static void schedule_irq(struct m2mtest_dev *dev, int msec_timeout)
+{
+       dprintk(dev, "Scheduling a simulated irq\n");
+       mod_timer(&dev->timer, jiffies + msecs_to_jiffies(msec_timeout));
+}
+
+/*
+ * mem2mem callbacks
+ */
+
+/**
+ * job_ready() - check whether an instance is ready to be scheduled to run
+ */
+static int job_ready(void *priv)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < ctx->translen
+           || v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) < ctx->translen) {
+               dprintk(ctx->dev, "Not enough buffers available\n");
+               return 0;
+       }
+
+       return 1;
+}
+
+static void job_abort(void *priv)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       /* Will cancel the transaction in the next interrupt handler */
+       ctx->aborting = 1;
+}
+
+/* device_run() - prepares and starts the device
+ *
+ * This simulates all the immediate preparations required before starting
+ * a device. This will be called by the framework when it decides to schedule
+ * a particular instance.
+ */
+static void device_run(void *priv)
+{
+       struct m2mtest_ctx *ctx = priv;
+       struct m2mtest_dev *dev = ctx->dev;
+       struct m2mtest_buffer *src_buf, *dst_buf;
+
+       src_buf = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
+       dst_buf = v4l2_m2m_next_dst_buf(ctx->m2m_ctx);
+
+       device_process(ctx, src_buf, dst_buf);
+
+       /* Run a timer, which simulates a hardware irq  */
+       schedule_irq(dev, ctx->transtime);
+}
+
+
+static void device_isr(unsigned long priv)
+{
+       struct m2mtest_dev *m2mtest_dev = (struct m2mtest_dev *)priv;
+       struct m2mtest_ctx *curr_ctx;
+       struct m2mtest_buffer *src_buf, *dst_buf;
+       unsigned long flags;
+
+       curr_ctx = v4l2_m2m_get_curr_priv(m2mtest_dev->m2m_dev);
+
+       if (NULL == curr_ctx) {
+               printk(KERN_ERR
+                       "Instance released before the end of transaction\n");
+               return;
+       }
+
+       src_buf = v4l2_m2m_src_buf_remove(curr_ctx->m2m_ctx);
+       dst_buf = v4l2_m2m_dst_buf_remove(curr_ctx->m2m_ctx);
+       curr_ctx->num_processed++;
+
+       if (curr_ctx->num_processed == curr_ctx->translen
+           || curr_ctx->aborting) {
+               dprintk(curr_ctx->dev, "Finishing transaction\n");
+               curr_ctx->num_processed = 0;
+               spin_lock_irqsave(&m2mtest_dev->irqlock, flags);
+               src_buf->vb.state = dst_buf->vb.state = VIDEOBUF_DONE;
+               wake_up(&src_buf->vb.done);
+               wake_up(&dst_buf->vb.done);
+               spin_unlock_irqrestore(&m2mtest_dev->irqlock, flags);
+               v4l2_m2m_job_finish(m2mtest_dev->m2m_dev, curr_ctx->m2m_ctx);
+       } else {
+               spin_lock_irqsave(&m2mtest_dev->irqlock, flags);
+               src_buf->vb.state = dst_buf->vb.state = VIDEOBUF_DONE;
+               wake_up(&src_buf->vb.done);
+               wake_up(&dst_buf->vb.done);
+               spin_unlock_irqrestore(&m2mtest_dev->irqlock, flags);
+               device_run(curr_ctx);
+       }
+}
+
+
+/*
+ * video ioctls
+ */
+static int vidioc_querycap(struct file *file, void *priv,
+                          struct v4l2_capability *cap)
+{
+       strncpy(cap->driver, MEM2MEM_NAME, sizeof(cap->driver) - 1);
+       strncpy(cap->card, MEM2MEM_NAME, sizeof(cap->card) - 1);
+       cap->bus_info[0] = 0;
+       cap->version = KERNEL_VERSION(0, 1, 0);
+       cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OUTPUT
+                         | V4L2_CAP_STREAMING;
+
+       return 0;
+}
+
+static int enum_fmt(struct v4l2_fmtdesc *f, u32 type)
+{
+       int i, num;
+       struct m2mtest_fmt *fmt;
+
+       num = 0;
+
+       for (i = 0; i < NUM_FORMATS; ++i) {
+               if (formats[i].types & type) {
+                       /* index-th format of type type found ? */
+                       if (num == f->index)
+                               break;
+                       /* Correct type but haven't reached our index yet,
+                        * just increment per-type index */
+                       ++num;
+               }
+       }
+
+       if (i < NUM_FORMATS) {
+               /* Format found */
+               fmt = &formats[i];
+               strncpy(f->description, fmt->name, sizeof(f->description) - 1);
+               f->pixelformat = fmt->fourcc;
+               return 0;
+       }
+
+       /* Format not found */
+       return -EINVAL;
+}
+
+static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
+                                  struct v4l2_fmtdesc *f)
+{
+       return enum_fmt(f, MEM2MEM_CAPTURE);
+}
+
+static int vidioc_enum_fmt_vid_out(struct file *file, void *priv,
+                                  struct v4l2_fmtdesc *f)
+{
+       return enum_fmt(f, MEM2MEM_OUTPUT);
+}
+
+static int vidioc_g_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
+{
+       struct videobuf_queue *vq;
+       struct m2mtest_q_data *q_data;
+
+       vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
+       if (!vq)
+               return -EINVAL;
+
+       q_data = get_q_data(f->type);
+
+       f->fmt.pix.width        = q_data->width;
+       f->fmt.pix.height       = q_data->height;
+       f->fmt.pix.field        = vq->field;
+       f->fmt.pix.pixelformat  = q_data->fmt->fourcc;
+       f->fmt.pix.bytesperline = (q_data->width * q_data->fmt->depth) >> 3;
+       f->fmt.pix.sizeimage    = q_data->sizeimage;
+
+       return 0;
+}
+
+static int vidioc_g_fmt_vid_out(struct file *file, void *priv,
+                               struct v4l2_format *f)
+{
+       return vidioc_g_fmt(priv, f);
+}
+
+static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
+                               struct v4l2_format *f)
+{
+       return vidioc_g_fmt(priv, f);
+}
+
+static int vidioc_try_fmt(struct v4l2_format *f, struct m2mtest_fmt *fmt)
+{
+       enum v4l2_field field;
+
+       field = f->fmt.pix.field;
+
+       if (field == V4L2_FIELD_ANY)
+               field = V4L2_FIELD_NONE;
+       else if (V4L2_FIELD_NONE != field)
+               return -EINVAL;
+
+       /* V4L2 specification suggests the driver corrects the format struct
+        * if any of the dimensions is unsupported */
+       f->fmt.pix.field = field;
+
+       if (f->fmt.pix.height < MIN_H)
+               f->fmt.pix.height = MIN_H;
+       else if (f->fmt.pix.height > MAX_H)
+               f->fmt.pix.height = MAX_H;
+
+       if (f->fmt.pix.width < MIN_W)
+               f->fmt.pix.width = MIN_W;
+       else if (f->fmt.pix.width > MAX_W)
+               f->fmt.pix.width = MAX_W;
+
+       f->fmt.pix.width &= ~DIM_ALIGN_MASK;
+       f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
+       f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+
+       return 0;
+}
+
+static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
+                                 struct v4l2_format *f)
+{
+       struct m2mtest_fmt *fmt;
+       struct m2mtest_ctx *ctx = priv;
+
+       fmt = find_format(f);
+       if (!fmt || !(fmt->types & MEM2MEM_CAPTURE)) {
+               v4l2_err(&ctx->dev->v4l2_dev,
+                        "Fourcc format (0x%08x) invalid.\n",
+                        f->fmt.pix.pixelformat);
+               return -EINVAL;
+       }
+
+       return vidioc_try_fmt(f, fmt);
+}
+
+static int vidioc_try_fmt_vid_out(struct file *file, void *priv,
+                                 struct v4l2_format *f)
+{
+       struct m2mtest_fmt *fmt;
+       struct m2mtest_ctx *ctx = priv;
+
+       fmt = find_format(f);
+       if (!fmt || !(fmt->types & MEM2MEM_OUTPUT)) {
+               v4l2_err(&ctx->dev->v4l2_dev,
+                        "Fourcc format (0x%08x) invalid.\n",
+                        f->fmt.pix.pixelformat);
+               return -EINVAL;
+       }
+
+       return vidioc_try_fmt(f, fmt);
+}
+
+static int vidioc_s_fmt(struct m2mtest_ctx *ctx, struct v4l2_format *f)
+{
+       struct m2mtest_q_data *q_data;
+       struct videobuf_queue *vq;
+       int ret = 0;
+
+       vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type);
+       if (!vq)
+               return -EINVAL;
+
+       q_data = get_q_data(f->type);
+       if (!q_data)
+               return -EINVAL;
+
+       mutex_lock(&vq->vb_lock);
+
+       if (videobuf_queue_is_busy(vq)) {
+               v4l2_err(&ctx->dev->v4l2_dev, "%s queue busy\n", __func__);
+               ret = -EBUSY;
+               goto out;
+       }
+
+       q_data->fmt             = find_format(f);
+       q_data->width           = f->fmt.pix.width;
+       q_data->height          = f->fmt.pix.height;
+       q_data->sizeimage       = q_data->width * q_data->height
+                               * q_data->fmt->depth >> 3;
+       vq->field               = f->fmt.pix.field;
+
+       dprintk(ctx->dev,
+               "Setting format for type %d, wxh: %dx%d, fmt: %d\n",
+               f->type, q_data->width, q_data->height, q_data->fmt->fourcc);
+
+out:
+       mutex_unlock(&vq->vb_lock);
+       return ret;
+}
+
+static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
+                               struct v4l2_format *f)
+{
+       int ret;
+
+       ret = vidioc_try_fmt_vid_cap(file, priv, f);
+       if (ret)
+               return ret;
+
+       return vidioc_s_fmt(priv, f);
+}
+
+static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
+                               struct v4l2_format *f)
+{
+       int ret;
+
+       ret = vidioc_try_fmt_vid_out(file, priv, f);
+       if (ret)
+               return ret;
+
+       return vidioc_s_fmt(priv, f);
+}
+
+static int vidioc_reqbufs(struct file *file, void *priv,
+                         struct v4l2_requestbuffers *reqbufs)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
+}
+
+static int vidioc_querybuf(struct file *file, void *priv,
+                          struct v4l2_buffer *buf)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
+}
+
+static int vidioc_streamon(struct file *file, void *priv,
+                          enum v4l2_buf_type type)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
+}
+
+static int vidioc_streamoff(struct file *file, void *priv,
+                           enum v4l2_buf_type type)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
+}
+
+static int vidioc_queryctrl(struct file *file, void *priv,
+                           struct v4l2_queryctrl *qc)
+{
+       struct v4l2_queryctrl *c;
+
+       c = get_ctrl(qc->id);
+       if (!c)
+               return -EINVAL;
+
+       *qc = *c;
+       return 0;
+}
+
+static int vidioc_g_ctrl(struct file *file, void *priv,
+                        struct v4l2_control *ctrl)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       switch (ctrl->id) {
+       case V4L2_CID_TRANS_TIME_MSEC:
+               ctrl->value = ctx->transtime;
+               break;
+
+       case V4L2_CID_TRANS_NUM_BUFS:
+               ctrl->value = ctx->translen;
+               break;
+
+       default:
+               v4l2_err(&ctx->dev->v4l2_dev, "Invalid control\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int check_ctrl_val(struct m2mtest_ctx *ctx, struct v4l2_control *ctrl)
+{
+       struct v4l2_queryctrl *c;
+
+       c = get_ctrl(ctrl->id);
+       if (!c)
+               return -EINVAL;
+
+       if (ctrl->value < c->minimum || ctrl->value > c->maximum) {
+               v4l2_err(&ctx->dev->v4l2_dev, "Value out of range\n");
+               return -ERANGE;
+       }
+
+       return 0;
+}
+
+static int vidioc_s_ctrl(struct file *file, void *priv,
+                        struct v4l2_control *ctrl)
+{
+       struct m2mtest_ctx *ctx = priv;
+       int ret = 0;
+
+       ret = check_ctrl_val(ctx, ctrl);
+       if (ret != 0)
+               return ret;
+
+       switch (ctrl->id) {
+       case V4L2_CID_TRANS_TIME_MSEC:
+               ctx->transtime = ctrl->value;
+               break;
+
+       case V4L2_CID_TRANS_NUM_BUFS:
+               ctx->translen = ctrl->value;
+               break;
+
+       default:
+               v4l2_err(&ctx->dev->v4l2_dev, "Invalid control\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+
+static const struct v4l2_ioctl_ops m2mtest_ioctl_ops = {
+       .vidioc_querycap        = vidioc_querycap,
+
+       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap   = vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_s_fmt_vid_cap   = vidioc_s_fmt_vid_cap,
+
+       .vidioc_enum_fmt_vid_out = vidioc_enum_fmt_vid_out,
+       .vidioc_g_fmt_vid_out   = vidioc_g_fmt_vid_out,
+       .vidioc_try_fmt_vid_out = vidioc_try_fmt_vid_out,
+       .vidioc_s_fmt_vid_out   = vidioc_s_fmt_vid_out,
+
+       .vidioc_reqbufs         = vidioc_reqbufs,
+       .vidioc_querybuf        = vidioc_querybuf,
+
+       .vidioc_qbuf            = vidioc_qbuf,
+       .vidioc_dqbuf           = vidioc_dqbuf,
+
+       .vidioc_streamon        = vidioc_streamon,
+       .vidioc_streamoff       = vidioc_streamoff,
+
+       .vidioc_queryctrl       = vidioc_queryctrl,
+       .vidioc_g_ctrl          = vidioc_g_ctrl,
+       .vidioc_s_ctrl          = vidioc_s_ctrl,
+};
+
+
+/*
+ * Queue operations
+ */
+
+static void m2mtest_buf_release(struct videobuf_queue *vq,
+                               struct videobuf_buffer *vb)
+{
+       struct m2mtest_ctx *ctx = vq->priv_data;
+
+       dprintk(ctx->dev, "type: %d, index: %d, state: %d\n",
+               vq->type, vb->i, vb->state);
+
+       videobuf_vmalloc_free(vb);
+       vb->state = VIDEOBUF_NEEDS_INIT;
+}
+
+static int m2mtest_buf_setup(struct videobuf_queue *vq, unsigned int *count,
+                         unsigned int *size)
+{
+       struct m2mtest_ctx *ctx = vq->priv_data;
+       struct m2mtest_q_data *q_data;
+
+       q_data = get_q_data(vq->type);
+
+       *size = q_data->width * q_data->height * q_data->fmt->depth >> 3;
+       dprintk(ctx->dev, "size:%d, w/h %d/%d, depth: %d\n",
+               *size, q_data->width, q_data->height, q_data->fmt->depth);
+
+       if (0 == *count)
+               *count = MEM2MEM_DEF_NUM_BUFS;
+
+       while (*size * *count > MEM2MEM_VID_MEM_LIMIT)
+               (*count)--;
+
+       v4l2_info(&ctx->dev->v4l2_dev,
+                 "%d buffers of size %d set up.\n", *count, *size);
+
+       return 0;
+}
+
+static int m2mtest_buf_prepare(struct videobuf_queue *vq,
+                              struct videobuf_buffer *vb,
+                              enum v4l2_field field)
+{
+       struct m2mtest_ctx *ctx = vq->priv_data;
+       struct m2mtest_q_data *q_data;
+       int ret;
+
+       dprintk(ctx->dev, "type: %d, index: %d, state: %d\n",
+               vq->type, vb->i, vb->state);
+
+       q_data = get_q_data(vq->type);
+
+       if (vb->baddr) {
+               /* User-provided buffer */
+               if (vb->bsize < q_data->sizeimage) {
+                       /* Buffer too small to fit a frame */
+                       v4l2_err(&ctx->dev->v4l2_dev,
+                                "User-provided buffer too small\n");
+                       return -EINVAL;
+               }
+       } else if (vb->state != VIDEOBUF_NEEDS_INIT
+                       && vb->bsize < q_data->sizeimage) {
+               /* We provide the buffer, but it's already been initialized
+                * and is too small */
+               return -EINVAL;
+       }
+
+       vb->width       = q_data->width;
+       vb->height      = q_data->height;
+       vb->bytesperline = (q_data->width * q_data->fmt->depth) >> 3;
+       vb->size        = q_data->sizeimage;
+       vb->field       = field;
+
+       if (VIDEOBUF_NEEDS_INIT == vb->state) {
+               ret = videobuf_iolock(vq, vb, NULL);
+               if (ret) {
+                       v4l2_err(&ctx->dev->v4l2_dev,
+                                "Iolock failed\n");
+                       goto fail;
+               }
+       }
+
+       vb->state = VIDEOBUF_PREPARED;
+
+       return 0;
+fail:
+       m2mtest_buf_release(vq, vb);
+       return ret;
+}
+
+static void m2mtest_buf_queue(struct videobuf_queue *vq,
+                          struct videobuf_buffer *vb)
+{
+       struct m2mtest_ctx *ctx = vq->priv_data;
+
+       v4l2_m2m_buf_queue(ctx->m2m_ctx, vq, vb);
+}
+
+static struct videobuf_queue_ops m2mtest_qops = {
+       .buf_setup      = m2mtest_buf_setup,
+       .buf_prepare    = m2mtest_buf_prepare,
+       .buf_queue      = m2mtest_buf_queue,
+       .buf_release    = m2mtest_buf_release,
+};
+
+static void queue_init(void *priv, struct videobuf_queue *vq,
+                      enum v4l2_buf_type type)
+{
+       struct m2mtest_ctx *ctx = priv;
+
+       videobuf_queue_vmalloc_init(vq, &m2mtest_qops, ctx->dev->v4l2_dev.dev,
+                                   &ctx->dev->irqlock, type, V4L2_FIELD_NONE,
+                                   sizeof(struct m2mtest_buffer), priv);
+}
+
+
+/*
+ * File operations
+ */
+static int m2mtest_open(struct file *file)
+{
+       struct m2mtest_dev *dev = video_drvdata(file);
+       struct m2mtest_ctx *ctx = NULL;
+
+       ctx = kzalloc(sizeof *ctx, GFP_KERNEL);
+       if (!ctx)
+               return -ENOMEM;
+
+       file->private_data = ctx;
+       ctx->dev = dev;
+       ctx->translen = MEM2MEM_DEF_TRANSLEN;
+       ctx->transtime = MEM2MEM_DEF_TRANSTIME;
+       ctx->num_processed = 0;
+
+       ctx->m2m_ctx = v4l2_m2m_ctx_init(ctx, dev->m2m_dev, queue_init);
+       if (IS_ERR(ctx->m2m_ctx)) {
+               int ret = PTR_ERR(ctx->m2m_ctx);
+
+               kfree(ctx);
+               return ret;
+       }
+
+       atomic_inc(&dev->num_inst);
+
+       dprintk(dev, "Created instance %p, m2m_ctx: %p\n", ctx, ctx->m2m_ctx);
+
+       return 0;
+}
+
+static int m2mtest_release(struct file *file)
+{
+       struct m2mtest_dev *dev = video_drvdata(file);
+       struct m2mtest_ctx *ctx = file->private_data;
+
+       dprintk(dev, "Releasing instance %p\n", ctx);
+
+       v4l2_m2m_ctx_release(ctx->m2m_ctx);
+       kfree(ctx);
+
+       atomic_dec(&dev->num_inst);
+
+       return 0;
+}
+
+static unsigned int m2mtest_poll(struct file *file,
+                                struct poll_table_struct *wait)
+{
+       struct m2mtest_ctx *ctx = (struct m2mtest_ctx *)file->private_data;
+
+       return v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
+}
+
+static int m2mtest_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       struct m2mtest_ctx *ctx = (struct m2mtest_ctx *)file->private_data;
+
+       return v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
+}
+
+static const struct v4l2_file_operations m2mtest_fops = {
+       .owner          = THIS_MODULE,
+       .open           = m2mtest_open,
+       .release        = m2mtest_release,
+       .poll           = m2mtest_poll,
+       .ioctl          = video_ioctl2,
+       .mmap           = m2mtest_mmap,
+};
+
+static struct video_device m2mtest_videodev = {
+       .name           = MEM2MEM_NAME,
+       .fops           = &m2mtest_fops,
+       .ioctl_ops      = &m2mtest_ioctl_ops,
+       .minor          = -1,
+       .release        = video_device_release,
+};
+
+static struct v4l2_m2m_ops m2m_ops = {
+       .device_run     = device_run,
+       .job_ready      = job_ready,
+       .job_abort      = job_abort,
+};
+
+static int m2mtest_probe(struct platform_device *pdev)
+{
+       struct m2mtest_dev *dev;
+       struct video_device *vfd;
+       int ret;
+
+       dev = kzalloc(sizeof *dev, GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       spin_lock_init(&dev->irqlock);
+
+       ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
+       if (ret)
+               goto free_dev;
+
+       atomic_set(&dev->num_inst, 0);
+       mutex_init(&dev->dev_mutex);
+
+       vfd = video_device_alloc();
+       if (!vfd) {
+               v4l2_err(&dev->v4l2_dev, "Failed to allocate video device\n");
+               ret = -ENOMEM;
+               goto unreg_dev;
+       }
+
+       *vfd = m2mtest_videodev;
+
+       ret = video_register_device(vfd, VFL_TYPE_GRABBER, 0);
+       if (ret) {
+               v4l2_err(&dev->v4l2_dev, "Failed to register video device\n");
+               goto rel_vdev;
+       }
+
+       video_set_drvdata(vfd, dev);
+       snprintf(vfd->name, sizeof(vfd->name), "%s", m2mtest_videodev.name);
+       dev->vfd = vfd;
+       v4l2_info(&dev->v4l2_dev, MEM2MEM_TEST_MODULE_NAME
+                       "Device registered as /dev/video%d\n", vfd->num);
+
+       setup_timer(&dev->timer, device_isr, (long)dev);
+       platform_set_drvdata(pdev, dev);
+
+       dev->m2m_dev = v4l2_m2m_init(&m2m_ops);
+       if (IS_ERR(dev->m2m_dev)) {
+               v4l2_err(&dev->v4l2_dev, "Failed to init mem2mem device\n");
+               ret = PTR_ERR(dev->m2m_dev);
+               goto err_m2m;
+       }
+
+       return 0;
+
+err_m2m:
+       video_unregister_device(dev->vfd);
+rel_vdev:
+       video_device_release(vfd);
+unreg_dev:
+       v4l2_device_unregister(&dev->v4l2_dev);
+free_dev:
+       kfree(dev);
+
+       return ret;
+}
+
+static int m2mtest_remove(struct platform_device *pdev)
+{
+       struct m2mtest_dev *dev =
+               (struct m2mtest_dev *)platform_get_drvdata(pdev);
+
+       v4l2_info(&dev->v4l2_dev, "Removing " MEM2MEM_TEST_MODULE_NAME);
+       v4l2_m2m_release(dev->m2m_dev);
+       del_timer_sync(&dev->timer);
+       video_unregister_device(dev->vfd);
+       v4l2_device_unregister(&dev->v4l2_dev);
+       kfree(dev);
+
+       return 0;
+}
+
+static struct platform_driver m2mtest_pdrv = {
+       .probe          = m2mtest_probe,
+       .remove         = m2mtest_remove,
+       .driver         = {
+               .name   = MEM2MEM_NAME,
+               .owner  = THIS_MODULE,
+       },
+};
+
+static void __exit m2mtest_exit(void)
+{
+       platform_driver_unregister(&m2mtest_pdrv);
+       platform_device_unregister(&m2mtest_pdev);
+}
+
+static int __init m2mtest_init(void)
+{
+       int ret;
+
+       ret = platform_device_register(&m2mtest_pdev);
+       if (ret)
+               return ret;
+
+       ret = platform_driver_register(&m2mtest_pdrv);
+       if (ret)
+               platform_device_unregister(&m2mtest_pdev);
+
+       return 0;
+}
+
+module_init(m2mtest_init);
+module_exit(m2mtest_exit);
+
index 4404e5e..2be23bc 100644 (file)
 #include <linux/pci.h>
 #include <linux/sched.h>
 #include <linux/init.h>
-#include <linux/videodev.h>
 #include <linux/gfp.h>
+#include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -1168,22 +1169,22 @@ static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
        case V4L2_CID_BRIGHTNESS:
                sony_pic_camera_command(
                        SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value);
-               meye.picture.brightness = c->value << 10;
+               meye.brightness = c->value << 10;
                break;
        case V4L2_CID_HUE:
                sony_pic_camera_command(
                        SONY_PIC_COMMAND_SETCAMERAHUE, c->value);
-               meye.picture.hue = c->value << 10;
+               meye.hue = c->value << 10;
                break;
        case V4L2_CID_CONTRAST:
                sony_pic_camera_command(
                        SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value);
-               meye.picture.contrast = c->value << 10;
+               meye.contrast = c->value << 10;
                break;
        case V4L2_CID_SATURATION:
                sony_pic_camera_command(
                        SONY_PIC_COMMAND_SETCAMERACOLOR, c->value);
-               meye.picture.colour = c->value << 10;
+               meye.colour = c->value << 10;
                break;
        case V4L2_CID_AGC:
                sony_pic_camera_command(
@@ -1221,16 +1222,16 @@ static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
        mutex_lock(&meye.lock);
        switch (c->id) {
        case V4L2_CID_BRIGHTNESS:
-               c->value = meye.picture.brightness >> 10;
+               c->value = meye.brightness >> 10;
                break;
        case V4L2_CID_HUE:
-               c->value = meye.picture.hue >> 10;
+               c->value = meye.hue >> 10;
                break;
        case V4L2_CID_CONTRAST:
-               c->value = meye.picture.contrast >> 10;
+               c->value = meye.contrast >> 10;
                break;
        case V4L2_CID_SATURATION:
-               c->value = meye.picture.colour >> 10;
+               c->value = meye.colour >> 10;
                break;
        case V4L2_CID_AGC:
                c->value = meye.params.agc;
@@ -1729,6 +1730,7 @@ static int meye_resume(struct pci_dev *pdev)
 static int __devinit meye_probe(struct pci_dev *pcidev,
                                const struct pci_device_id *ent)
 {
+       struct v4l2_device *v4l2_dev = &meye.v4l2_dev;
        int ret = -EBUSY;
        unsigned long mchip_adr;
 
@@ -1737,70 +1739,75 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
                goto outnotdev;
        }
 
+       ret = v4l2_device_register(&pcidev->dev, v4l2_dev);
+       if (ret < 0) {
+               v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
+               return ret;
+       }
        ret = -ENOMEM;
        meye.mchip_dev = pcidev;
-       meye.video_dev = video_device_alloc();
-       if (!meye.video_dev) {
-               printk(KERN_ERR "meye: video_device_alloc() failed!\n");
+       meye.vdev = video_device_alloc();
+       if (!meye.vdev) {
+               v4l2_err(v4l2_dev, "video_device_alloc() failed!\n");
                goto outnotdev;
        }
 
        meye.grab_temp = vmalloc(MCHIP_NB_PAGES_MJPEG * PAGE_SIZE);
        if (!meye.grab_temp) {
-               printk(KERN_ERR "meye: grab buffer allocation failed\n");
+               v4l2_err(v4l2_dev, "grab buffer allocation failed\n");
                goto outvmalloc;
        }
 
        spin_lock_init(&meye.grabq_lock);
        if (kfifo_alloc(&meye.grabq, sizeof(int) * MEYE_MAX_BUFNBRS,
                                GFP_KERNEL)) {
-               printk(KERN_ERR "meye: fifo allocation failed\n");
+               v4l2_err(v4l2_dev, "fifo allocation failed\n");
                goto outkfifoalloc1;
        }
        spin_lock_init(&meye.doneq_lock);
        if (kfifo_alloc(&meye.doneq, sizeof(int) * MEYE_MAX_BUFNBRS,
                                GFP_KERNEL)) {
-               printk(KERN_ERR "meye: fifo allocation failed\n");
+               v4l2_err(v4l2_dev, "fifo allocation failed\n");
                goto outkfifoalloc2;
        }
 
-       memcpy(meye.video_dev, &meye_template, sizeof(meye_template));
-       meye.video_dev->parent = &meye.mchip_dev->dev;
+       memcpy(meye.vdev, &meye_template, sizeof(meye_template));
+       meye.vdev->v4l2_dev = &meye.v4l2_dev;
 
        ret = -EIO;
        if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) {
-               printk(KERN_ERR "meye: unable to power on the camera\n");
-               printk(KERN_ERR "meye: did you enable the camera in "
+               v4l2_err(v4l2_dev, "meye: unable to power on the camera\n");
+               v4l2_err(v4l2_dev, "meye: did you enable the camera in "
                                "sonypi using the module options ?\n");
                goto outsonypienable;
        }
 
        if ((ret = pci_enable_device(meye.mchip_dev))) {
-               printk(KERN_ERR "meye: pci_enable_device failed\n");
+               v4l2_err(v4l2_dev, "meye: pci_enable_device failed\n");
                goto outenabledev;
        }
 
        mchip_adr = pci_resource_start(meye.mchip_dev,0);
        if (!mchip_adr) {
-               printk(KERN_ERR "meye: mchip has no device base address\n");
+               v4l2_err(v4l2_dev, "meye: mchip has no device base address\n");
                goto outregions;
        }
        if (!request_mem_region(pci_resource_start(meye.mchip_dev, 0),
                                pci_resource_len(meye.mchip_dev, 0),
                                "meye")) {
-               printk(KERN_ERR "meye: request_mem_region failed\n");
+               v4l2_err(v4l2_dev, "meye: request_mem_region failed\n");
                goto outregions;
        }
        meye.mchip_mmregs = ioremap(mchip_adr, MCHIP_MM_REGS);
        if (!meye.mchip_mmregs) {
-               printk(KERN_ERR "meye: ioremap failed\n");
+               v4l2_err(v4l2_dev, "meye: ioremap failed\n");
                goto outremap;
        }
 
        meye.mchip_irq = pcidev->irq;
        if (request_irq(meye.mchip_irq, meye_irq,
                        IRQF_DISABLED | IRQF_SHARED, "meye", meye_irq)) {
-               printk(KERN_ERR "meye: request_irq failed\n");
+               v4l2_err(v4l2_dev, "request_irq failed\n");
                goto outreqirq;
        }
 
@@ -1824,21 +1831,18 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
        msleep(1);
        mchip_set(MCHIP_MM_INTA, MCHIP_MM_INTA_HIC_1_MASK);
 
-       if (video_register_device(meye.video_dev, VFL_TYPE_GRABBER,
+       if (video_register_device(meye.vdev, VFL_TYPE_GRABBER,
                                  video_nr) < 0) {
-               printk(KERN_ERR "meye: video_register_device failed\n");
+               v4l2_err(v4l2_dev, "video_register_device failed\n");
                goto outvideoreg;
        }
 
        mutex_init(&meye.lock);
        init_waitqueue_head(&meye.proc_list);
-       meye.picture.depth = 16;
-       meye.picture.palette = VIDEO_PALETTE_YUV422;
-       meye.picture.brightness = 32 << 10;
-       meye.picture.hue = 32 << 10;
-       meye.picture.colour = 32 << 10;
-       meye.picture.contrast = 32 << 10;
-       meye.picture.whiteness = 0;
+       meye.brightness = 32 << 10;
+       meye.hue = 32 << 10;
+       meye.colour = 32 << 10;
+       meye.contrast = 32 << 10;
        meye.params.subsample = 0;
        meye.params.quality = 8;
        meye.params.sharpness = 32;
@@ -1854,9 +1858,9 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
        sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE, 0);
        sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC, 48);
 
-       printk(KERN_INFO "meye: Motion Eye Camera Driver v%s.\n",
+       v4l2_info(v4l2_dev, "Motion Eye Camera Driver v%s.\n",
               MEYE_DRIVER_VERSION);
-       printk(KERN_INFO "meye: mchip KL5A72002 rev. %d, base %lx, irq %d\n",
+       v4l2_info(v4l2_dev, "mchip KL5A72002 rev. %d, base %lx, irq %d\n",
               meye.mchip_dev->revision, mchip_adr, meye.mchip_irq);
 
        return 0;
@@ -1879,14 +1883,14 @@ outkfifoalloc2:
 outkfifoalloc1:
        vfree(meye.grab_temp);
 outvmalloc:
-       video_device_release(meye.video_dev);
+       video_device_release(meye.vdev);
 outnotdev:
        return ret;
 }
 
 static void __devexit meye_remove(struct pci_dev *pcidev)
 {
-       video_unregister_device(meye.video_dev);
+       video_unregister_device(meye.vdev);
 
        mchip_hic_stop();
 
index 1321ad5..4bdeb03 100644 (file)
@@ -31,7 +31,7 @@
 #define _MEYE_PRIV_H_
 
 #define MEYE_DRIVER_MAJORVERSION        1
-#define MEYE_DRIVER_MINORVERSION       13
+#define MEYE_DRIVER_MINORVERSION       14
 
 #define MEYE_DRIVER_VERSION __stringify(MEYE_DRIVER_MAJORVERSION) "." \
                            __stringify(MEYE_DRIVER_MINORVERSION)
@@ -289,6 +289,7 @@ struct meye_grab_buffer {
 
 /* Motion Eye device structure */
 struct meye {
+       struct v4l2_device v4l2_dev;    /* Main v4l2_device struct */
        struct pci_dev *mchip_dev;      /* pci device */
        u8 mchip_irq;                   /* irq */
        u8 mchip_mode;                  /* actual mchip mode: HIC_MODE... */
@@ -308,8 +309,11 @@ struct meye {
        struct kfifo doneq;             /* queue for grabbed buffers */
        spinlock_t doneq_lock;          /* lock protecting the queue */
        wait_queue_head_t proc_list;    /* wait queue */
-       struct video_device *video_dev; /* video device parameters */
-       struct video_picture picture;   /* video picture parameters */
+       struct video_device *vdev;      /* video device parameters */
+       u16 brightness;
+       u16 hue;
+       u16 contrast;
+       u16 colour;
        struct meye_params params;      /* additional parameters */
        unsigned long in_use;           /* set to 1 if the device is in use */
 #ifdef CONFIG_PM
index a9061bf..78b4e09 100644 (file)
@@ -8,14 +8,16 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/videodev2.h>
-#include <linux/slab.h>
+#include <linux/device.h>
 #include <linux/i2c.h>
 #include <linux/log2.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/videodev2.h>
 
-#include <media/v4l2-subdev.h>
-#include <media/v4l2-chip-ident.h>
 #include <media/soc_camera.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-subdev.h>
 
 /*
  * mt9t031 i2c address 0x5d
@@ -680,6 +682,59 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
        return 0;
 }
 
+/*
+ * Power Management:
+ * This function does nothing for now but must be present for pm to work
+ */
+static int mt9t031_runtime_suspend(struct device *dev)
+{
+       return 0;
+}
+
+/*
+ * Power Management:
+ * COLUMN_ADDRESS_MODE and ROW_ADDRESS_MODE are not rewritten if unchanged
+ * they are however changed at reset if the platform hook is present
+ * thus we rewrite them with the values stored by the driver
+ */
+static int mt9t031_runtime_resume(struct device *dev)
+{
+       struct video_device *vdev = to_video_device(dev);
+       struct soc_camera_device *icd = container_of(vdev->parent,
+               struct soc_camera_device, dev);
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       struct i2c_client *client = sd->priv;
+       struct mt9t031 *mt9t031 = to_mt9t031(client);
+
+       int ret;
+       u16 xbin, ybin;
+
+       xbin = min(mt9t031->xskip, (u16)3);
+       ybin = min(mt9t031->yskip, (u16)3);
+
+       ret = reg_write(client, MT9T031_COLUMN_ADDRESS_MODE,
+               ((xbin - 1) << 4) | (mt9t031->xskip - 1));
+       if (ret < 0)
+               return ret;
+
+       ret = reg_write(client, MT9T031_ROW_ADDRESS_MODE,
+               ((ybin - 1) << 4) | (mt9t031->yskip - 1));
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static struct dev_pm_ops mt9t031_dev_pm_ops = {
+       .runtime_suspend        = mt9t031_runtime_suspend,
+       .runtime_resume         = mt9t031_runtime_resume,
+};
+
+static struct device_type mt9t031_dev_type = {
+       .name   = "MT9T031",
+       .pm     = &mt9t031_dev_pm_ops,
+};
+
 /*
  * Interface active, can use i2c. If it fails, it can indeed mean, that
  * this wasn't our capture interface, so, we wait for the right one
@@ -687,6 +742,7 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 static int mt9t031_video_probe(struct i2c_client *client)
 {
        struct mt9t031 *mt9t031 = to_mt9t031(client);
+       struct video_device *vdev = soc_camera_i2c_to_vdev(client);
        s32 data;
        int ret;
 
@@ -712,6 +768,8 @@ static int mt9t031_video_probe(struct i2c_client *client)
        ret = mt9t031_idle(client);
        if (ret < 0)
                dev_err(&client->dev, "Failed to initialise the camera\n");
+       else
+               vdev->dev.type = &mt9t031_dev_type;
 
        /* mt9t031_idle() has reset the chip to default. */
        mt9t031->exposure = 255;
index 1a34d29..e5bae4c 100644 (file)
@@ -325,7 +325,7 @@ static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
        if (ret < 0)
                return ret;
 
-       dev_dbg(&client->dev, "Frame %ux%u pixel\n", rect.width, rect.height);
+       dev_dbg(&client->dev, "Frame %dx%d pixel\n", rect.width, rect.height);
 
        mt9v022->rect = rect;
 
index 34a6601..5c17f9e 100644 (file)
@@ -139,8 +139,8 @@ static int mx1_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
        if (!*count)
                *count = 32;
 
-       while (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
+               *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size;
 
        dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
 
index bd297f5..d477e30 100644 (file)
@@ -796,7 +796,7 @@ static int acquire_dma_channel(struct mx3_camera_dev *mx3_cam)
  * FIXME: learn to use stride != width, then we can keep stride properly aligned
  * and support arbitrary (even) widths.
  */
-static inline void stride_align(__s32 *width)
+static inline void stride_align(__u32 *width)
 {
        if (((*width + 7) &  ~7) < 4096)
                *width = (*width + 7) &  ~7;
@@ -844,7 +844,7 @@ static int mx3_camera_set_crop(struct soc_camera_device *icd,
                 * So far only direct camera-to-memory is supported
                 */
                if (channel_change_requested(icd, rect)) {
-                       int ret = acquire_dma_channel(mx3_cam);
+                       ret = acquire_dma_channel(mx3_cam);
                        if (ret < 0)
                                return ret;
                }
diff --git a/drivers/media/video/omap/Kconfig b/drivers/media/video/omap/Kconfig
new file mode 100644 (file)
index 0000000..97c5394
--- /dev/null
@@ -0,0 +1,11 @@
+config VIDEO_OMAP2_VOUT
+       tristate "OMAP2/OMAP3 V4L2-Display driver"
+       depends on ARCH_OMAP24XX || ARCH_OMAP34XX
+       select VIDEOBUF_GEN
+       select VIDEOBUF_DMA_SG
+       select OMAP2_DSS
+       select OMAP2_VRAM
+       select OMAP2_VRFB
+       default n
+       ---help---
+         V4L2 Display driver support for OMAP2/3 based boards.
diff --git a/drivers/media/video/omap/Makefile b/drivers/media/video/omap/Makefile
new file mode 100644 (file)
index 0000000..b8bab00
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# Makefile for the omap video device drivers.
+#
+
+# OMAP2/3 Display driver
+omap-vout-mod-objs := omap_vout.o omap_voutlib.o
+obj-$(CONFIG_VIDEO_OMAP2_VOUT) += omap-vout-mod.o
diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
new file mode 100644 (file)
index 0000000..4c0ab49
--- /dev/null
@@ -0,0 +1,2643 @@
+/*
+ * omap_vout.c
+ *
+ * Copyright (C) 2005-2010 Texas Instruments.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ * Leveraged code from the OMAP2 camera driver
+ * Video-for-Linux (Version 2) camera capture driver for
+ * the OMAP24xx camera controller.
+ *
+ * Author: Andy Lowe (source@mvista.com)
+ *
+ * Copyright (C) 2004 MontaVista Software, Inc.
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ * History:
+ * 20-APR-2006 Khasim          Modified VRFB based Rotation,
+ *                             The image data is always read from 0 degree
+ *                             view and written
+ *                             to the virtual space of desired rotation angle
+ * 4-DEC-2006  Jian            Changed to support better memory management
+ *
+ * 17-Nov-2008 Hardik          Changed driver to use video_ioctl2
+ *
+ * 23-Feb-2010 Vaibhav H       Modified to use new DSS2 interface
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+#include <linux/sched.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
+#include <linux/irq.h>
+#include <linux/videodev2.h>
+
+#include <media/videobuf-dma-sg.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+
+#include <plat/dma.h>
+#include <plat/vram.h>
+#include <plat/vrfb.h>
+#include <plat/display.h>
+
+#include "omap_voutlib.h"
+#include "omap_voutdef.h"
+
+MODULE_AUTHOR("Texas Instruments");
+MODULE_DESCRIPTION("OMAP Video for Linux Video out driver");
+MODULE_LICENSE("GPL");
+
+
+/* Driver Configuration macros */
+#define VOUT_NAME              "omap_vout"
+
+enum omap_vout_channels {
+       OMAP_VIDEO1,
+       OMAP_VIDEO2,
+};
+
+enum dma_channel_state {
+       DMA_CHAN_NOT_ALLOTED,
+       DMA_CHAN_ALLOTED,
+};
+
+#define QQVGA_WIDTH            160
+#define QQVGA_HEIGHT           120
+
+/* Max Resolution supported by the driver */
+#define VID_MAX_WIDTH          1280    /* Largest width */
+#define VID_MAX_HEIGHT         720     /* Largest height */
+
+/* Mimimum requirement is 2x2 for DSS */
+#define VID_MIN_WIDTH          2
+#define VID_MIN_HEIGHT         2
+
+/* 2048 x 2048 is max res supported by OMAP display controller */
+#define MAX_PIXELS_PER_LINE     2048
+
+#define VRFB_TX_TIMEOUT         1000
+#define VRFB_NUM_BUFS          4
+
+/* Max buffer size tobe allocated during init */
+#define OMAP_VOUT_MAX_BUF_SIZE (VID_MAX_WIDTH*VID_MAX_HEIGHT*4)
+
+static struct videobuf_queue_ops video_vbq_ops;
+/* Variables configurable through module params*/
+static u32 video1_numbuffers = 3;
+static u32 video2_numbuffers = 3;
+static u32 video1_bufsize = OMAP_VOUT_MAX_BUF_SIZE;
+static u32 video2_bufsize = OMAP_VOUT_MAX_BUF_SIZE;
+static u32 vid1_static_vrfb_alloc;
+static u32 vid2_static_vrfb_alloc;
+static int debug;
+
+/* Module parameters */
+module_param(video1_numbuffers, uint, S_IRUGO);
+MODULE_PARM_DESC(video1_numbuffers,
+       "Number of buffers to be allocated at init time for Video1 device.");
+
+module_param(video2_numbuffers, uint, S_IRUGO);
+MODULE_PARM_DESC(video2_numbuffers,
+       "Number of buffers to be allocated at init time for Video2 device.");
+
+module_param(video1_bufsize, uint, S_IRUGO);
+MODULE_PARM_DESC(video1_bufsize,
+       "Size of the buffer to be allocated for video1 device");
+
+module_param(video2_bufsize, uint, S_IRUGO);
+MODULE_PARM_DESC(video2_bufsize,
+       "Size of the buffer to be allocated for video2 device");
+
+module_param(vid1_static_vrfb_alloc, bool, S_IRUGO);
+MODULE_PARM_DESC(vid1_static_vrfb_alloc,
+       "Static allocation of the VRFB buffer for video1 device");
+
+module_param(vid2_static_vrfb_alloc, bool, S_IRUGO);
+MODULE_PARM_DESC(vid2_static_vrfb_alloc,
+       "Static allocation of the VRFB buffer for video2 device");
+
+module_param(debug, bool, S_IRUGO);
+MODULE_PARM_DESC(debug, "Debug level (0-1)");
+
+/* list of image formats supported by OMAP2 video pipelines */
+const static struct v4l2_fmtdesc omap_formats[] = {
+       {
+               /* Note:  V4L2 defines RGB565 as:
+                *
+                *      Byte 0                    Byte 1
+                *      g2 g1 g0 r4 r3 r2 r1 r0   b4 b3 b2 b1 b0 g5 g4 g3
+                *
+                * We interpret RGB565 as:
+                *
+                *      Byte 0                    Byte 1
+                *      g2 g1 g0 b4 b3 b2 b1 b0   r4 r3 r2 r1 r0 g5 g4 g3
+                */
+               .description = "RGB565, le",
+               .pixelformat = V4L2_PIX_FMT_RGB565,
+       },
+       {
+               /* Note:  V4L2 defines RGB32 as: RGB-8-8-8-8  we use
+                *  this for RGB24 unpack mode, the last 8 bits are ignored
+                * */
+               .description = "RGB32, le",
+               .pixelformat = V4L2_PIX_FMT_RGB32,
+       },
+       {
+               /* Note:  V4L2 defines RGB24 as: RGB-8-8-8  we use
+                *        this for RGB24 packed mode
+                *
+                */
+               .description = "RGB24, le",
+               .pixelformat = V4L2_PIX_FMT_RGB24,
+       },
+       {
+               .description = "YUYV (YUV 4:2:2), packed",
+               .pixelformat = V4L2_PIX_FMT_YUYV,
+       },
+       {
+               .description = "UYVY, packed",
+               .pixelformat = V4L2_PIX_FMT_UYVY,
+       },
+};
+
+#define NUM_OUTPUT_FORMATS (ARRAY_SIZE(omap_formats))
+
+/*
+ * Allocate buffers
+ */
+static unsigned long omap_vout_alloc_buffer(u32 buf_size, u32 *phys_addr)
+{
+       u32 order, size;
+       unsigned long virt_addr, addr;
+
+       size = PAGE_ALIGN(buf_size);
+       order = get_order(size);
+       virt_addr = __get_free_pages(GFP_KERNEL | GFP_DMA, order);
+       addr = virt_addr;
+
+       if (virt_addr) {
+               while (size > 0) {
+                       SetPageReserved(virt_to_page(addr));
+                       addr += PAGE_SIZE;
+                       size -= PAGE_SIZE;
+               }
+       }
+       *phys_addr = (u32) virt_to_phys((void *) virt_addr);
+       return virt_addr;
+}
+
+/*
+ * Free buffers
+ */
+static void omap_vout_free_buffer(unsigned long virtaddr, u32 buf_size)
+{
+       u32 order, size;
+       unsigned long addr = virtaddr;
+
+       size = PAGE_ALIGN(buf_size);
+       order = get_order(size);
+
+       while (size > 0) {
+               ClearPageReserved(virt_to_page(addr));
+               addr += PAGE_SIZE;
+               size -= PAGE_SIZE;
+       }
+       free_pages((unsigned long) virtaddr, order);
+}
+
+/*
+ * Function for allocating video buffers
+ */
+static int omap_vout_allocate_vrfb_buffers(struct omap_vout_device *vout,
+               unsigned int *count, int startindex)
+{
+       int i, j;
+
+       for (i = 0; i < *count; i++) {
+               if (!vout->smsshado_virt_addr[i]) {
+                       vout->smsshado_virt_addr[i] =
+                               omap_vout_alloc_buffer(vout->smsshado_size,
+                                               &vout->smsshado_phy_addr[i]);
+               }
+               if (!vout->smsshado_virt_addr[i] && startindex != -1) {
+                       if (V4L2_MEMORY_MMAP == vout->memory && i >= startindex)
+                               break;
+               }
+               if (!vout->smsshado_virt_addr[i]) {
+                       for (j = 0; j < i; j++) {
+                               omap_vout_free_buffer(
+                                               vout->smsshado_virt_addr[j],
+                                               vout->smsshado_size);
+                               vout->smsshado_virt_addr[j] = 0;
+                               vout->smsshado_phy_addr[j] = 0;
+                       }
+                       *count = 0;
+                       return -ENOMEM;
+               }
+               memset((void *) vout->smsshado_virt_addr[i], 0,
+                               vout->smsshado_size);
+       }
+       return 0;
+}
+
+/*
+ * Try format
+ */
+static int omap_vout_try_format(struct v4l2_pix_format *pix)
+{
+       int ifmt, bpp = 0;
+
+       pix->height = clamp(pix->height, (u32)VID_MIN_HEIGHT,
+                                               (u32)VID_MAX_HEIGHT);
+       pix->width = clamp(pix->width, (u32)VID_MIN_WIDTH, (u32)VID_MAX_WIDTH);
+
+       for (ifmt = 0; ifmt < NUM_OUTPUT_FORMATS; ifmt++) {
+               if (pix->pixelformat == omap_formats[ifmt].pixelformat)
+                       break;
+       }
+
+       if (ifmt == NUM_OUTPUT_FORMATS)
+               ifmt = 0;
+
+       pix->pixelformat = omap_formats[ifmt].pixelformat;
+       pix->field = V4L2_FIELD_ANY;
+       pix->priv = 0;
+
+       switch (pix->pixelformat) {
+       case V4L2_PIX_FMT_YUYV:
+       case V4L2_PIX_FMT_UYVY:
+       default:
+               pix->colorspace = V4L2_COLORSPACE_JPEG;
+               bpp = YUYV_BPP;
+               break;
+       case V4L2_PIX_FMT_RGB565:
+       case V4L2_PIX_FMT_RGB565X:
+               pix->colorspace = V4L2_COLORSPACE_SRGB;
+               bpp = RGB565_BPP;
+               break;
+       case V4L2_PIX_FMT_RGB24:
+               pix->colorspace = V4L2_COLORSPACE_SRGB;
+               bpp = RGB24_BPP;
+               break;
+       case V4L2_PIX_FMT_RGB32:
+       case V4L2_PIX_FMT_BGR32:
+               pix->colorspace = V4L2_COLORSPACE_SRGB;
+               bpp = RGB32_BPP;
+               break;
+       }
+       pix->bytesperline = pix->width * bpp;
+       pix->sizeimage = pix->bytesperline * pix->height;
+
+       return bpp;
+}
+
+/*
+ * omap_vout_uservirt_to_phys: This inline function is used to convert user
+ * space virtual address to physical address.
+ */
+static u32 omap_vout_uservirt_to_phys(u32 virtp)
+{
+       unsigned long physp = 0;
+       struct vm_area_struct *vma;
+       struct mm_struct *mm = current->mm;
+
+       vma = find_vma(mm, virtp);
+       /* For kernel direct-mapped memory, take the easy way */
+       if (virtp >= PAGE_OFFSET) {
+               physp = virt_to_phys((void *) virtp);
+       } else if (vma && (vma->vm_flags & VM_IO) && vma->vm_pgoff) {
+               /* this will catch, kernel-allocated, mmaped-to-usermode
+                  addresses */
+               physp = (vma->vm_pgoff << PAGE_SHIFT) + (virtp - vma->vm_start);
+       } else {
+               /* otherwise, use get_user_pages() for general userland pages */
+               int res, nr_pages = 1;
+               struct page *pages;
+               down_read(&current->mm->mmap_sem);
+
+               res = get_user_pages(current, current->mm, virtp, nr_pages, 1,
+                               0, &pages, NULL);
+               up_read(&current->mm->mmap_sem);
+
+               if (res == nr_pages) {
+                       physp =  __pa(page_address(&pages[0]) +
+                                       (virtp & ~PAGE_MASK));
+               } else {
+                       printk(KERN_WARNING VOUT_NAME
+                                       "get_user_pages failed\n");
+                       return 0;
+               }
+       }
+
+       return physp;
+}
+
+/*
+ * Wakes up the application once the DMA transfer to VRFB space is completed.
+ */
+static void omap_vout_vrfb_dma_tx_callback(int lch, u16 ch_status, void *data)
+{
+       struct vid_vrfb_dma *t = (struct vid_vrfb_dma *) data;
+
+       t->tx_status = 1;
+       wake_up_interruptible(&t->wait);
+}
+
+/*
+ * Release the VRFB context once the module exits
+ */
+static void omap_vout_release_vrfb(struct omap_vout_device *vout)
+{
+       int i;
+
+       for (i = 0; i < VRFB_NUM_BUFS; i++)
+               omap_vrfb_release_ctx(&vout->vrfb_context[i]);
+
+       if (vout->vrfb_dma_tx.req_status == DMA_CHAN_ALLOTED) {
+               vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED;
+               omap_free_dma(vout->vrfb_dma_tx.dma_ch);
+       }
+}
+
+/*
+ * Return true if rotation is 90 or 270
+ */
+static inline int rotate_90_or_270(const struct omap_vout_device *vout)
+{
+       return (vout->rotation == dss_rotation_90_degree ||
+                       vout->rotation == dss_rotation_270_degree);
+}
+
+/*
+ * Return true if rotation is enabled
+ */
+static inline int rotation_enabled(const struct omap_vout_device *vout)
+{
+       return vout->rotation || vout->mirror;
+}
+
+/*
+ * Reverse the rotation degree if mirroring is enabled
+ */
+static inline int calc_rotation(const struct omap_vout_device *vout)
+{
+       if (!vout->mirror)
+               return vout->rotation;
+
+       switch (vout->rotation) {
+       case dss_rotation_90_degree:
+               return dss_rotation_270_degree;
+       case dss_rotation_270_degree:
+               return dss_rotation_90_degree;
+       case dss_rotation_180_degree:
+               return dss_rotation_0_degree;
+       default:
+               return dss_rotation_180_degree;
+       }
+}
+
+/*
+ * Free the V4L2 buffers
+ */
+static void omap_vout_free_buffers(struct omap_vout_device *vout)
+{
+       int i, numbuffers;
+
+       /* Allocate memory for the buffers */
+       numbuffers = (vout->vid) ?  video2_numbuffers : video1_numbuffers;
+       vout->buffer_size = (vout->vid) ? video2_bufsize : video1_bufsize;
+
+       for (i = 0; i < numbuffers; i++) {
+               omap_vout_free_buffer(vout->buf_virt_addr[i],
+                               vout->buffer_size);
+               vout->buf_phy_addr[i] = 0;
+               vout->buf_virt_addr[i] = 0;
+       }
+}
+
+/*
+ * Free VRFB buffers
+ */
+static void omap_vout_free_vrfb_buffers(struct omap_vout_device *vout)
+{
+       int j;
+
+       for (j = 0; j < VRFB_NUM_BUFS; j++) {
+               omap_vout_free_buffer(vout->smsshado_virt_addr[j],
+                               vout->smsshado_size);
+               vout->smsshado_virt_addr[j] = 0;
+               vout->smsshado_phy_addr[j] = 0;
+       }
+}
+
+/*
+ * Allocate the buffers for the VRFB space.  Data is copied from V4L2
+ * buffers to the VRFB buffers using the DMA engine.
+ */
+static int omap_vout_vrfb_buffer_setup(struct omap_vout_device *vout,
+                         unsigned int *count, unsigned int startindex)
+{
+       int i;
+       bool yuv_mode;
+
+       /* Allocate the VRFB buffers only if the buffers are not
+        * allocated during init time.
+        */
+       if ((rotation_enabled(vout)) && !vout->vrfb_static_allocation)
+               if (omap_vout_allocate_vrfb_buffers(vout, count, startindex))
+                       return -ENOMEM;
+
+       if (vout->dss_mode == OMAP_DSS_COLOR_YUV2 ||
+                       vout->dss_mode == OMAP_DSS_COLOR_UYVY)
+               yuv_mode = true;
+       else
+               yuv_mode = false;
+
+       for (i = 0; i < *count; i++)
+               omap_vrfb_setup(&vout->vrfb_context[i],
+                               vout->smsshado_phy_addr[i], vout->pix.width,
+                               vout->pix.height, vout->bpp, yuv_mode);
+
+       return 0;
+}
+
+/*
+ * Convert V4L2 rotation to DSS rotation
+ *     V4L2 understand 0, 90, 180, 270.
+ *     Convert to 0, 1, 2 and 3 repsectively for DSS
+ */
+static int v4l2_rot_to_dss_rot(int v4l2_rotation,
+                       enum dss_rotation *rotation, bool mirror)
+{
+       int ret = 0;
+
+       switch (v4l2_rotation) {
+       case 90:
+               *rotation = dss_rotation_90_degree;
+               break;
+       case 180:
+               *rotation = dss_rotation_180_degree;
+               break;
+       case 270:
+               *rotation = dss_rotation_270_degree;
+               break;
+       case 0:
+               *rotation = dss_rotation_0_degree;
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+/*
+ * Calculate the buffer offsets from which the streaming should
+ * start. This offset calculation is mainly required because of
+ * the VRFB 32 pixels alignment with rotation.
+ */
+static int omap_vout_calculate_offset(struct omap_vout_device *vout)
+{
+       struct omap_overlay *ovl;
+       enum dss_rotation rotation;
+       struct omapvideo_info *ovid;
+       bool mirroring = vout->mirror;
+       struct omap_dss_device *cur_display;
+       struct v4l2_rect *crop = &vout->crop;
+       struct v4l2_pix_format *pix = &vout->pix;
+       int *cropped_offset = &vout->cropped_offset;
+       int vr_ps = 1, ps = 2, temp_ps = 2;
+       int offset = 0, ctop = 0, cleft = 0, line_length = 0;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+       /* get the display device attached to the overlay */
+       if (!ovl->manager || !ovl->manager->device)
+               return -1;
+
+       cur_display = ovl->manager->device;
+       rotation = calc_rotation(vout);
+
+       if (V4L2_PIX_FMT_YUYV == pix->pixelformat ||
+                       V4L2_PIX_FMT_UYVY == pix->pixelformat) {
+               if (rotation_enabled(vout)) {
+                       /*
+                        * ps    - Actual pixel size for YUYV/UYVY for
+                        *         VRFB/Mirroring is 4 bytes
+                        * vr_ps - Virtually pixel size for YUYV/UYVY is
+                        *         2 bytes
+                        */
+                       ps = 4;
+                       vr_ps = 2;
+               } else {
+                       ps = 2; /* otherwise the pixel size is 2 byte */
+               }
+       } else if (V4L2_PIX_FMT_RGB32 == pix->pixelformat) {
+               ps = 4;
+       } else if (V4L2_PIX_FMT_RGB24 == pix->pixelformat) {
+               ps = 3;
+       }
+       vout->ps = ps;
+       vout->vr_ps = vr_ps;
+
+       if (rotation_enabled(vout)) {
+               line_length = MAX_PIXELS_PER_LINE;
+               ctop = (pix->height - crop->height) - crop->top;
+               cleft = (pix->width - crop->width) - crop->left;
+       } else {
+               line_length = pix->width;
+       }
+       vout->line_length = line_length;
+       switch (rotation) {
+       case dss_rotation_90_degree:
+               offset = vout->vrfb_context[0].yoffset *
+                       vout->vrfb_context[0].bytespp;
+               temp_ps = ps / vr_ps;
+               if (mirroring == 0) {
+                       *cropped_offset = offset + line_length *
+                               temp_ps * cleft + crop->top * temp_ps;
+               } else {
+                       *cropped_offset = offset + line_length * temp_ps *
+                               cleft + crop->top * temp_ps + (line_length *
+                               ((crop->width / (vr_ps)) - 1) * ps);
+               }
+               break;
+       case dss_rotation_180_degree:
+               offset = ((MAX_PIXELS_PER_LINE * vout->vrfb_context[0].yoffset *
+                       vout->vrfb_context[0].bytespp) +
+                       (vout->vrfb_context[0].xoffset *
+                       vout->vrfb_context[0].bytespp));
+               if (mirroring == 0) {
+                       *cropped_offset = offset + (line_length * ps * ctop) +
+                               (cleft / vr_ps) * ps;
+
+               } else {
+                       *cropped_offset = offset + (line_length * ps * ctop) +
+                               (cleft / vr_ps) * ps + (line_length *
+                               (crop->height - 1) * ps);
+               }
+               break;
+       case dss_rotation_270_degree:
+               offset = MAX_PIXELS_PER_LINE * vout->vrfb_context[0].xoffset *
+                       vout->vrfb_context[0].bytespp;
+               temp_ps = ps / vr_ps;
+               if (mirroring == 0) {
+                       *cropped_offset = offset + line_length *
+                           temp_ps * crop->left + ctop * ps;
+               } else {
+                       *cropped_offset = offset + line_length *
+                               temp_ps * crop->left + ctop * ps +
+                               (line_length * ((crop->width / vr_ps) - 1) *
+                                ps);
+               }
+               break;
+       case dss_rotation_0_degree:
+               if (mirroring == 0) {
+                       *cropped_offset = (line_length * ps) *
+                               crop->top + (crop->left / vr_ps) * ps;
+               } else {
+                       *cropped_offset = (line_length * ps) *
+                               crop->top + (crop->left / vr_ps) * ps +
+                               (line_length * (crop->height - 1) * ps);
+               }
+               break;
+       default:
+               *cropped_offset = (line_length * ps * crop->top) /
+                       vr_ps + (crop->left * ps) / vr_ps +
+                       ((crop->width / vr_ps) - 1) * ps;
+               break;
+       }
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "%s Offset:%x\n",
+                       __func__, *cropped_offset);
+       return 0;
+}
+
+/*
+ * Convert V4L2 pixel format to DSS pixel format
+ */
+static int video_mode_to_dss_mode(struct omap_vout_device *vout)
+{
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct v4l2_pix_format *pix = &vout->pix;
+       enum omap_color_mode mode;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       switch (pix->pixelformat) {
+       case 0:
+               break;
+       case V4L2_PIX_FMT_YUYV:
+               mode = OMAP_DSS_COLOR_YUV2;
+               break;
+       case V4L2_PIX_FMT_UYVY:
+               mode = OMAP_DSS_COLOR_UYVY;
+               break;
+       case V4L2_PIX_FMT_RGB565:
+               mode = OMAP_DSS_COLOR_RGB16;
+               break;
+       case V4L2_PIX_FMT_RGB24:
+               mode = OMAP_DSS_COLOR_RGB24P;
+               break;
+       case V4L2_PIX_FMT_RGB32:
+               mode = (ovl->id == OMAP_DSS_VIDEO1) ?
+                       OMAP_DSS_COLOR_RGB24U : OMAP_DSS_COLOR_ARGB32;
+               break;
+       case V4L2_PIX_FMT_BGR32:
+               mode = OMAP_DSS_COLOR_RGBX32;
+               break;
+       default:
+               mode = -EINVAL;
+       }
+       return mode;
+}
+
+/*
+ * Setup the overlay
+ */
+int omapvid_setup_overlay(struct omap_vout_device *vout,
+               struct omap_overlay *ovl, int posx, int posy, int outw,
+               int outh, u32 addr)
+{
+       int ret = 0;
+       struct omap_overlay_info info;
+       int cropheight, cropwidth, pixheight, pixwidth;
+
+       if ((ovl->caps & OMAP_DSS_OVL_CAP_SCALE) == 0 &&
+                       (outw != vout->pix.width || outh != vout->pix.height)) {
+               ret = -EINVAL;
+               goto setup_ovl_err;
+       }
+
+       vout->dss_mode = video_mode_to_dss_mode(vout);
+       if (vout->dss_mode == -EINVAL) {
+               ret = -EINVAL;
+               goto setup_ovl_err;
+       }
+
+       /* Setup the input plane parameters according to
+        * rotation value selected.
+        */
+       if (rotate_90_or_270(vout)) {
+               cropheight = vout->crop.width;
+               cropwidth = vout->crop.height;
+               pixheight = vout->pix.width;
+               pixwidth = vout->pix.height;
+       } else {
+               cropheight = vout->crop.height;
+               cropwidth = vout->crop.width;
+               pixheight = vout->pix.height;
+               pixwidth = vout->pix.width;
+       }
+
+       ovl->get_overlay_info(ovl, &info);
+       info.paddr = addr;
+       info.vaddr = NULL;
+       info.width = cropwidth;
+       info.height = cropheight;
+       info.color_mode = vout->dss_mode;
+       info.mirror = vout->mirror;
+       info.pos_x = posx;
+       info.pos_y = posy;
+       info.out_width = outw;
+       info.out_height = outh;
+       info.global_alpha = vout->win.global_alpha;
+       if (!rotation_enabled(vout)) {
+               info.rotation = 0;
+               info.rotation_type = OMAP_DSS_ROT_DMA;
+               info.screen_width = pixwidth;
+       } else {
+               info.rotation = vout->rotation;
+               info.rotation_type = OMAP_DSS_ROT_VRFB;
+               info.screen_width = 2048;
+       }
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
+               "%s enable=%d addr=%x width=%d\n height=%d color_mode=%d\n"
+               "rotation=%d mirror=%d posx=%d posy=%d out_width = %d \n"
+               "out_height=%d rotation_type=%d screen_width=%d\n",
+               __func__, info.enabled, info.paddr, info.width, info.height,
+               info.color_mode, info.rotation, info.mirror, info.pos_x,
+               info.pos_y, info.out_width, info.out_height, info.rotation_type,
+               info.screen_width);
+
+       ret = ovl->set_overlay_info(ovl, &info);
+       if (ret)
+               goto setup_ovl_err;
+
+       return 0;
+
+setup_ovl_err:
+       v4l2_warn(&vout->vid_dev->v4l2_dev, "setup_overlay failed\n");
+       return ret;
+}
+
+/*
+ * Initialize the overlay structure
+ */
+int omapvid_init(struct omap_vout_device *vout, u32 addr)
+{
+       int ret = 0, i;
+       struct v4l2_window *win;
+       struct omap_overlay *ovl;
+       int posx, posy, outw, outh, temp;
+       struct omap_video_timings *timing;
+       struct omapvideo_info *ovid = &vout->vid_info;
+
+       win = &vout->win;
+       for (i = 0; i < ovid->num_overlays; i++) {
+               ovl = ovid->overlays[i];
+               if (!ovl->manager || !ovl->manager->device)
+                       return -EINVAL;
+
+               timing = &ovl->manager->device->panel.timings;
+
+               outw = win->w.width;
+               outh = win->w.height;
+               switch (vout->rotation) {
+               case dss_rotation_90_degree:
+                       /* Invert the height and width for 90
+                        * and 270 degree rotation
+                        */
+                       temp = outw;
+                       outw = outh;
+                       outh = temp;
+                       posy = (timing->y_res - win->w.width) - win->w.left;
+                       posx = win->w.top;
+                       break;
+
+               case dss_rotation_180_degree:
+                       posx = (timing->x_res - win->w.width) - win->w.left;
+                       posy = (timing->y_res - win->w.height) - win->w.top;
+                       break;
+
+               case dss_rotation_270_degree:
+                       temp = outw;
+                       outw = outh;
+                       outh = temp;
+                       posy = win->w.left;
+                       posx = (timing->x_res - win->w.height) - win->w.top;
+                       break;
+
+               default:
+                       posx = win->w.left;
+                       posy = win->w.top;
+                       break;
+               }
+
+               ret = omapvid_setup_overlay(vout, ovl, posx, posy,
+                               outw, outh, addr);
+               if (ret)
+                       goto omapvid_init_err;
+       }
+       return 0;
+
+omapvid_init_err:
+       v4l2_warn(&vout->vid_dev->v4l2_dev, "apply_changes failed\n");
+       return ret;
+}
+
+/*
+ * Apply the changes set the go bit of DSS
+ */
+int omapvid_apply_changes(struct omap_vout_device *vout)
+{
+       int i;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid = &vout->vid_info;
+
+       for (i = 0; i < ovid->num_overlays; i++) {
+               ovl = ovid->overlays[i];
+               if (!ovl->manager || !ovl->manager->device)
+                       return -EINVAL;
+               ovl->manager->apply(ovl->manager);
+       }
+
+       return 0;
+}
+
+void omap_vout_isr(void *arg, unsigned int irqstatus)
+{
+       int ret;
+       u32 addr, fid;
+       struct omap_overlay *ovl;
+       struct timeval timevalue;
+       struct omapvideo_info *ovid;
+       struct omap_dss_device *cur_display;
+       struct omap_vout_device *vout = (struct omap_vout_device *)arg;
+
+       if (!vout->streaming)
+               return;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+       /* get the display device attached to the overlay */
+       if (!ovl->manager || !ovl->manager->device)
+               return;
+
+       cur_display = ovl->manager->device;
+
+       spin_lock(&vout->vbq_lock);
+       do_gettimeofday(&timevalue);
+       if (cur_display->type == OMAP_DISPLAY_TYPE_DPI) {
+               if (!(irqstatus & DISPC_IRQ_VSYNC))
+                       goto vout_isr_err;
+
+               if (!vout->first_int && (vout->cur_frm != vout->next_frm)) {
+                       vout->cur_frm->ts = timevalue;
+                       vout->cur_frm->state = VIDEOBUF_DONE;
+                       wake_up_interruptible(&vout->cur_frm->done);
+                       vout->cur_frm = vout->next_frm;
+               }
+               vout->first_int = 0;
+               if (list_empty(&vout->dma_queue))
+                       goto vout_isr_err;
+
+               vout->next_frm = list_entry(vout->dma_queue.next,
+                               struct videobuf_buffer, queue);
+               list_del(&vout->next_frm->queue);
+
+               vout->next_frm->state = VIDEOBUF_ACTIVE;
+
+               addr = (unsigned long) vout->queued_buf_addr[vout->next_frm->i]
+                       + vout->cropped_offset;
+
+               /* First save the configuration in ovelray structure */
+               ret = omapvid_init(vout, addr);
+               if (ret)
+                       printk(KERN_ERR VOUT_NAME
+                                       "failed to set overlay info\n");
+               /* Enable the pipeline and set the Go bit */
+               ret = omapvid_apply_changes(vout);
+               if (ret)
+                       printk(KERN_ERR VOUT_NAME "failed to change mode\n");
+       } else {
+
+               if (vout->first_int) {
+                       vout->first_int = 0;
+                       goto vout_isr_err;
+               }
+               if (irqstatus & DISPC_IRQ_EVSYNC_ODD)
+                       fid = 1;
+               else if (irqstatus & DISPC_IRQ_EVSYNC_EVEN)
+                       fid = 0;
+               else
+                       goto vout_isr_err;
+
+               vout->field_id ^= 1;
+               if (fid != vout->field_id) {
+                       if (0 == fid)
+                               vout->field_id = fid;
+
+                       goto vout_isr_err;
+               }
+               if (0 == fid) {
+                       if (vout->cur_frm == vout->next_frm)
+                               goto vout_isr_err;
+
+                       vout->cur_frm->ts = timevalue;
+                       vout->cur_frm->state = VIDEOBUF_DONE;
+                       wake_up_interruptible(&vout->cur_frm->done);
+                       vout->cur_frm = vout->next_frm;
+               } else if (1 == fid) {
+                       if (list_empty(&vout->dma_queue) ||
+                                       (vout->cur_frm != vout->next_frm))
+                               goto vout_isr_err;
+
+                       vout->next_frm = list_entry(vout->dma_queue.next,
+                                       struct videobuf_buffer, queue);
+                       list_del(&vout->next_frm->queue);
+
+                       vout->next_frm->state = VIDEOBUF_ACTIVE;
+                       addr = (unsigned long)
+                               vout->queued_buf_addr[vout->next_frm->i] +
+                               vout->cropped_offset;
+                       /* First save the configuration in ovelray structure */
+                       ret = omapvid_init(vout, addr);
+                       if (ret)
+                               printk(KERN_ERR VOUT_NAME
+                                               "failed to set overlay info\n");
+                       /* Enable the pipeline and set the Go bit */
+                       ret = omapvid_apply_changes(vout);
+                       if (ret)
+                               printk(KERN_ERR VOUT_NAME
+                                               "failed to change mode\n");
+               }
+
+       }
+
+vout_isr_err:
+       spin_unlock(&vout->vbq_lock);
+}
+
+
+/* Video buffer call backs */
+
+/*
+ * Buffer setup function is called by videobuf layer when REQBUF ioctl is
+ * called. This is used to setup buffers and return size and count of
+ * buffers allocated. After the call to this buffer, videobuf layer will
+ * setup buffer queue depending on the size and count of buffers
+ */
+static int omap_vout_buffer_setup(struct videobuf_queue *q, unsigned int *count,
+                         unsigned int *size)
+{
+       int startindex = 0, i, j;
+       u32 phy_addr = 0, virt_addr = 0;
+       struct omap_vout_device *vout = q->priv_data;
+
+       if (!vout)
+               return -EINVAL;
+
+       if (V4L2_BUF_TYPE_VIDEO_OUTPUT != q->type)
+               return -EINVAL;
+
+       startindex = (vout->vid == OMAP_VIDEO1) ?
+               video1_numbuffers : video2_numbuffers;
+       if (V4L2_MEMORY_MMAP == vout->memory && *count < startindex)
+               *count = startindex;
+
+       if ((rotation_enabled(vout)) && *count > VRFB_NUM_BUFS)
+               *count = VRFB_NUM_BUFS;
+
+       /* If rotation is enabled, allocate memory for VRFB space also */
+       if (rotation_enabled(vout))
+               if (omap_vout_vrfb_buffer_setup(vout, count, startindex))
+                       return -ENOMEM;
+
+       if (V4L2_MEMORY_MMAP != vout->memory)
+               return 0;
+
+       /* Now allocated the V4L2 buffers */
+       *size = PAGE_ALIGN(vout->pix.width * vout->pix.height * vout->bpp);
+       startindex = (vout->vid == OMAP_VIDEO1) ?
+               video1_numbuffers : video2_numbuffers;
+
+       for (i = startindex; i < *count; i++) {
+               vout->buffer_size = *size;
+
+               virt_addr = omap_vout_alloc_buffer(vout->buffer_size,
+                               &phy_addr);
+               if (!virt_addr) {
+                       if (!rotation_enabled(vout))
+                               break;
+                       /* Free the VRFB buffers if no space for V4L2 buffers */
+                       for (j = i; j < *count; j++) {
+                               omap_vout_free_buffer(
+                                               vout->smsshado_virt_addr[j],
+                                               vout->smsshado_size);
+                               vout->smsshado_virt_addr[j] = 0;
+                               vout->smsshado_phy_addr[j] = 0;
+                       }
+               }
+               vout->buf_virt_addr[i] = virt_addr;
+               vout->buf_phy_addr[i] = phy_addr;
+       }
+       *count = vout->buffer_allocated = i;
+
+       return 0;
+}
+
+/*
+ * Free the V4L2 buffers additionally allocated than default
+ * number of buffers and free all the VRFB buffers
+ */
+static void omap_vout_free_allbuffers(struct omap_vout_device *vout)
+{
+       int num_buffers = 0, i;
+
+       num_buffers = (vout->vid == OMAP_VIDEO1) ?
+               video1_numbuffers : video2_numbuffers;
+
+       for (i = num_buffers; i < vout->buffer_allocated; i++) {
+               if (vout->buf_virt_addr[i])
+                       omap_vout_free_buffer(vout->buf_virt_addr[i],
+                                       vout->buffer_size);
+
+               vout->buf_virt_addr[i] = 0;
+               vout->buf_phy_addr[i] = 0;
+       }
+       /* Free the VRFB buffers only if they are allocated
+        * during reqbufs.  Don't free if init time allocated
+        */
+       if (!vout->vrfb_static_allocation) {
+               for (i = 0; i < VRFB_NUM_BUFS; i++) {
+                       if (vout->smsshado_virt_addr[i]) {
+                               omap_vout_free_buffer(
+                                               vout->smsshado_virt_addr[i],
+                                               vout->smsshado_size);
+                               vout->smsshado_virt_addr[i] = 0;
+                               vout->smsshado_phy_addr[i] = 0;
+                       }
+               }
+       }
+       vout->buffer_allocated = num_buffers;
+}
+
+/*
+ * This function will be called when VIDIOC_QBUF ioctl is called.
+ * It prepare buffers before give out for the display. This function
+ * converts user space virtual address into physical address if userptr memory
+ * exchange mechanism is used. If rotation is enabled, it copies entire
+ * buffer into VRFB memory space before giving it to the DSS.
+ */
+static int omap_vout_buffer_prepare(struct videobuf_queue *q,
+                           struct videobuf_buffer *vb,
+                           enum v4l2_field field)
+{
+       struct vid_vrfb_dma *tx;
+       enum dss_rotation rotation;
+       struct videobuf_dmabuf *dmabuf = NULL;
+       struct omap_vout_device *vout = q->priv_data;
+       u32 dest_frame_index = 0, src_element_index = 0;
+       u32 dest_element_index = 0, src_frame_index = 0;
+       u32 elem_count = 0, frame_count = 0, pixsize = 2;
+
+       if (VIDEOBUF_NEEDS_INIT == vb->state) {
+               vb->width = vout->pix.width;
+               vb->height = vout->pix.height;
+               vb->size = vb->width * vb->height * vout->bpp;
+               vb->field = field;
+       }
+       vb->state = VIDEOBUF_PREPARED;
+       /* if user pointer memory mechanism is used, get the physical
+        * address of the buffer
+        */
+       if (V4L2_MEMORY_USERPTR == vb->memory) {
+               if (0 == vb->baddr)
+                       return -EINVAL;
+               /* Virtual address */
+               /* priv points to struct videobuf_pci_sg_memory. But we went
+                * pointer to videobuf_dmabuf, which is member of
+                * videobuf_pci_sg_memory */
+               dmabuf = videobuf_to_dma(q->bufs[vb->i]);
+               dmabuf->vmalloc = (void *) vb->baddr;
+
+               /* Physical address */
+               dmabuf->bus_addr =
+                       (dma_addr_t) omap_vout_uservirt_to_phys(vb->baddr);
+       }
+
+       if (!rotation_enabled(vout)) {
+               dmabuf = videobuf_to_dma(q->bufs[vb->i]);
+               vout->queued_buf_addr[vb->i] = (u8 *) dmabuf->bus_addr;
+               return 0;
+       }
+       dmabuf = videobuf_to_dma(q->bufs[vb->i]);
+       /* If rotation is enabled, copy input buffer into VRFB
+        * memory space using DMA. We are copying input buffer
+        * into VRFB memory space of desired angle and DSS will
+        * read image VRFB memory for 0 degree angle
+        */
+       pixsize = vout->bpp * vout->vrfb_bpp;
+       /*
+        * DMA transfer in double index mode
+        */
+
+       /* Frame index */
+       dest_frame_index = ((MAX_PIXELS_PER_LINE * pixsize) -
+                       (vout->pix.width * vout->bpp)) + 1;
+
+       /* Source and destination parameters */
+       src_element_index = 0;
+       src_frame_index = 0;
+       dest_element_index = 1;
+       /* Number of elements per frame */
+       elem_count = vout->pix.width * vout->bpp;
+       frame_count = vout->pix.height;
+       tx = &vout->vrfb_dma_tx;
+       tx->tx_status = 0;
+       omap_set_dma_transfer_params(tx->dma_ch, OMAP_DMA_DATA_TYPE_S32,
+                       (elem_count / 4), frame_count, OMAP_DMA_SYNC_ELEMENT,
+                       tx->dev_id, 0x0);
+       /* src_port required only for OMAP1 */
+       omap_set_dma_src_params(tx->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
+                       dmabuf->bus_addr, src_element_index, src_frame_index);
+       /*set dma source burst mode for VRFB */
+       omap_set_dma_src_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
+       rotation = calc_rotation(vout);
+
+       /* dest_port required only for OMAP1 */
+       omap_set_dma_dest_params(tx->dma_ch, 0, OMAP_DMA_AMODE_DOUBLE_IDX,
+                       vout->vrfb_context[vb->i].paddr[0], dest_element_index,
+                       dest_frame_index);
+       /*set dma dest burst mode for VRFB */
+       omap_set_dma_dest_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
+       omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE, 0x20, 0);
+
+       omap_start_dma(tx->dma_ch);
+       interruptible_sleep_on_timeout(&tx->wait, VRFB_TX_TIMEOUT);
+
+       if (tx->tx_status == 0) {
+               omap_stop_dma(tx->dma_ch);
+               return -EINVAL;
+       }
+       /* Store buffers physical address into an array. Addresses
+        * from this array will be used to configure DSS */
+       vout->queued_buf_addr[vb->i] = (u8 *)
+               vout->vrfb_context[vb->i].paddr[rotation];
+       return 0;
+}
+
+/*
+ * Buffer queue funtion will be called from the videobuf layer when _QBUF
+ * ioctl is called. It is used to enqueue buffer, which is ready to be
+ * displayed.
+ */
+static void omap_vout_buffer_queue(struct videobuf_queue *q,
+                         struct videobuf_buffer *vb)
+{
+       struct omap_vout_device *vout = q->priv_data;
+
+       /* Driver is also maintainig a queue. So enqueue buffer in the driver
+        * queue */
+       list_add_tail(&vb->queue, &vout->dma_queue);
+
+       vb->state = VIDEOBUF_QUEUED;
+}
+
+/*
+ * Buffer release function is called from videobuf layer to release buffer
+ * which are already allocated
+ */
+static void omap_vout_buffer_release(struct videobuf_queue *q,
+                           struct videobuf_buffer *vb)
+{
+       struct omap_vout_device *vout = q->priv_data;
+
+       vb->state = VIDEOBUF_NEEDS_INIT;
+
+       if (V4L2_MEMORY_MMAP != vout->memory)
+               return;
+}
+
+/*
+ *  File operations
+ */
+static void omap_vout_vm_open(struct vm_area_struct *vma)
+{
+       struct omap_vout_device *vout = vma->vm_private_data;
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
+               "vm_open [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end);
+       vout->mmap_count++;
+}
+
+static void omap_vout_vm_close(struct vm_area_struct *vma)
+{
+       struct omap_vout_device *vout = vma->vm_private_data;
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
+               "vm_close [vma=%08lx-%08lx]\n", vma->vm_start, vma->vm_end);
+       vout->mmap_count--;
+}
+
+static struct vm_operations_struct omap_vout_vm_ops = {
+       .open   = omap_vout_vm_open,
+       .close  = omap_vout_vm_close,
+};
+
+static int omap_vout_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       int i;
+       void *pos;
+       unsigned long start = vma->vm_start;
+       unsigned long size = (vma->vm_end - vma->vm_start);
+       struct videobuf_dmabuf *dmabuf = NULL;
+       struct omap_vout_device *vout = file->private_data;
+       struct videobuf_queue *q = &vout->vbq;
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
+                       " %s pgoff=0x%lx, start=0x%lx, end=0x%lx\n", __func__,
+                       vma->vm_pgoff, vma->vm_start, vma->vm_end);
+
+       /* look for the buffer to map */
+       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+               if (NULL == q->bufs[i])
+                       continue;
+               if (V4L2_MEMORY_MMAP != q->bufs[i]->memory)
+                       continue;
+               if (q->bufs[i]->boff == (vma->vm_pgoff << PAGE_SHIFT))
+                       break;
+       }
+
+       if (VIDEO_MAX_FRAME == i) {
+               v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev,
+                               "offset invalid [offset=0x%lx]\n",
+                               (vma->vm_pgoff << PAGE_SHIFT));
+               return -EINVAL;
+       }
+       q->bufs[i]->baddr = vma->vm_start;
+
+       vma->vm_flags |= VM_RESERVED;
+       vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
+       vma->vm_ops = &omap_vout_vm_ops;
+       vma->vm_private_data = (void *) vout;
+       dmabuf = videobuf_to_dma(q->bufs[i]);
+       pos = dmabuf->vmalloc;
+       vma->vm_pgoff = virt_to_phys((void *)pos) >> PAGE_SHIFT;
+       while (size > 0) {
+               unsigned long pfn;
+               pfn = virt_to_phys((void *) pos) >> PAGE_SHIFT;
+               if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED))
+                       return -EAGAIN;
+               start += PAGE_SIZE;
+               pos += PAGE_SIZE;
+               size -= PAGE_SIZE;
+       }
+       vout->mmap_count++;
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
+
+       return 0;
+}
+
+static int omap_vout_release(struct file *file)
+{
+       unsigned int ret, i;
+       struct videobuf_queue *q;
+       struct omapvideo_info *ovid;
+       struct omap_vout_device *vout = file->private_data;
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
+       ovid = &vout->vid_info;
+
+       if (!vout)
+               return 0;
+
+       q = &vout->vbq;
+       /* Disable all the overlay managers connected with this interface */
+       for (i = 0; i < ovid->num_overlays; i++) {
+               struct omap_overlay *ovl = ovid->overlays[i];
+               if (ovl->manager && ovl->manager->device) {
+                       struct omap_overlay_info info;
+                       ovl->get_overlay_info(ovl, &info);
+                       info.enabled = 0;
+                       ovl->set_overlay_info(ovl, &info);
+               }
+       }
+       /* Turn off the pipeline */
+       ret = omapvid_apply_changes(vout);
+       if (ret)
+               v4l2_warn(&vout->vid_dev->v4l2_dev,
+                               "Unable to apply changes\n");
+
+       /* Free all buffers */
+       omap_vout_free_allbuffers(vout);
+       videobuf_mmap_free(q);
+
+       /* Even if apply changes fails we should continue
+          freeing allocated memeory */
+       if (vout->streaming) {
+               u32 mask = 0;
+
+               mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN |
+                       DISPC_IRQ_EVSYNC_ODD;
+               omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
+               vout->streaming = 0;
+
+               videobuf_streamoff(q);
+               videobuf_queue_cancel(q);
+       }
+
+       if (vout->mmap_count != 0)
+               vout->mmap_count = 0;
+
+       vout->opened -= 1;
+       file->private_data = NULL;
+
+       if (vout->buffer_allocated)
+               videobuf_mmap_free(q);
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
+       return ret;
+}
+
+static int omap_vout_open(struct file *file)
+{
+       struct videobuf_queue *q;
+       struct omap_vout_device *vout = NULL;
+
+       vout = video_drvdata(file);
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
+
+       if (vout == NULL)
+               return -ENODEV;
+
+       /* for now, we only support single open */
+       if (vout->opened)
+               return -EBUSY;
+
+       vout->opened += 1;
+
+       file->private_data = vout;
+       vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+
+       q = &vout->vbq;
+       video_vbq_ops.buf_setup = omap_vout_buffer_setup;
+       video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
+       video_vbq_ops.buf_release = omap_vout_buffer_release;
+       video_vbq_ops.buf_queue = omap_vout_buffer_queue;
+       spin_lock_init(&vout->vbq_lock);
+
+       videobuf_queue_sg_init(q, &video_vbq_ops, NULL, &vout->vbq_lock,
+                       vout->type, V4L2_FIELD_NONE,
+                       sizeof(struct videobuf_buffer), vout);
+
+       v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Exiting %s\n", __func__);
+       return 0;
+}
+
+/*
+ * V4L2 ioctls
+ */
+static int vidioc_querycap(struct file *file, void *fh,
+               struct v4l2_capability *cap)
+{
+       struct omap_vout_device *vout = fh;
+
+       strlcpy(cap->driver, VOUT_NAME, sizeof(cap->driver));
+       strlcpy(cap->card, vout->vfd->name, sizeof(cap->card));
+       cap->bus_info[0] = '\0';
+       cap->capabilities = V4L2_CAP_STREAMING | V4L2_CAP_VIDEO_OUTPUT;
+
+       return 0;
+}
+
+static int vidioc_enum_fmt_vid_out(struct file *file, void *fh,
+                       struct v4l2_fmtdesc *fmt)
+{
+       int index = fmt->index;
+       enum v4l2_buf_type type = fmt->type;
+
+       fmt->index = index;
+       fmt->type = type;
+       if (index >= NUM_OUTPUT_FORMATS)
+               return -EINVAL;
+
+       fmt->flags = omap_formats[index].flags;
+       strlcpy(fmt->description, omap_formats[index].description,
+                       sizeof(fmt->description));
+       fmt->pixelformat = omap_formats[index].pixelformat;
+
+       return 0;
+}
+
+static int vidioc_g_fmt_vid_out(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       struct omap_vout_device *vout = fh;
+
+       f->fmt.pix = vout->pix;
+       return 0;
+
+}
+
+static int vidioc_try_fmt_vid_out(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_video_timings *timing;
+       struct omap_vout_device *vout = fh;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       if (!ovl->manager || !ovl->manager->device)
+               return -EINVAL;
+       /* get the display device attached to the overlay */
+       timing = &ovl->manager->device->panel.timings;
+
+       vout->fbuf.fmt.height = timing->y_res;
+       vout->fbuf.fmt.width = timing->x_res;
+
+       omap_vout_try_format(&f->fmt.pix);
+       return 0;
+}
+
+static int vidioc_s_fmt_vid_out(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       int ret, bpp;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_video_timings *timing;
+       struct omap_vout_device *vout = fh;
+
+       if (vout->streaming)
+               return -EBUSY;
+
+       mutex_lock(&vout->lock);
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       /* get the display device attached to the overlay */
+       if (!ovl->manager || !ovl->manager->device) {
+               ret = -EINVAL;
+               goto s_fmt_vid_out_exit;
+       }
+       timing = &ovl->manager->device->panel.timings;
+
+       /* We dont support RGB24-packed mode if vrfb rotation
+        * is enabled*/
+       if ((rotation_enabled(vout)) &&
+                       f->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24) {
+               ret = -EINVAL;
+               goto s_fmt_vid_out_exit;
+       }
+
+       /* get the framebuffer parameters */
+
+       if (rotate_90_or_270(vout)) {
+               vout->fbuf.fmt.height = timing->x_res;
+               vout->fbuf.fmt.width = timing->y_res;
+       } else {
+               vout->fbuf.fmt.height = timing->y_res;
+               vout->fbuf.fmt.width = timing->x_res;
+       }
+
+       /* change to samller size is OK */
+
+       bpp = omap_vout_try_format(&f->fmt.pix);
+       f->fmt.pix.sizeimage = f->fmt.pix.width * f->fmt.pix.height * bpp;
+
+       /* try & set the new output format */
+       vout->bpp = bpp;
+       vout->pix = f->fmt.pix;
+       vout->vrfb_bpp = 1;
+
+       /* If YUYV then vrfb bpp is 2, for  others its 1 */
+       if (V4L2_PIX_FMT_YUYV == vout->pix.pixelformat ||
+                       V4L2_PIX_FMT_UYVY == vout->pix.pixelformat)
+               vout->vrfb_bpp = 2;
+
+       /* set default crop and win */
+       omap_vout_new_format(&vout->pix, &vout->fbuf, &vout->crop, &vout->win);
+
+       /* Save the changes in the overlay strcuture */
+       ret = omapvid_init(vout, 0);
+       if (ret) {
+               v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n");
+               goto s_fmt_vid_out_exit;
+       }
+
+       ret = 0;
+
+s_fmt_vid_out_exit:
+       mutex_unlock(&vout->lock);
+       return ret;
+}
+
+static int vidioc_try_fmt_vid_overlay(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       int ret = 0;
+       struct omap_vout_device *vout = fh;
+       struct v4l2_window *win = &f->fmt.win;
+
+       ret = omap_vout_try_window(&vout->fbuf, win);
+
+       if (!ret) {
+               if (vout->vid == OMAP_VIDEO1)
+                       win->global_alpha = 255;
+               else
+                       win->global_alpha = f->fmt.win.global_alpha;
+       }
+
+       return ret;
+}
+
+static int vidioc_s_fmt_vid_overlay(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       int ret = 0;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_vout_device *vout = fh;
+       struct v4l2_window *win = &f->fmt.win;
+
+       mutex_lock(&vout->lock);
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       ret = omap_vout_new_window(&vout->crop, &vout->win, &vout->fbuf, win);
+       if (!ret) {
+               /* Video1 plane does not support global alpha */
+               if (ovl->id == OMAP_DSS_VIDEO1)
+                       vout->win.global_alpha = 255;
+               else
+                       vout->win.global_alpha = f->fmt.win.global_alpha;
+
+               vout->win.chromakey = f->fmt.win.chromakey;
+       }
+       mutex_unlock(&vout->lock);
+       return ret;
+}
+
+static int vidioc_enum_fmt_vid_overlay(struct file *file, void *fh,
+                       struct v4l2_fmtdesc *fmt)
+{
+       int index = fmt->index;
+       enum v4l2_buf_type type = fmt->type;
+
+       fmt->index = index;
+       fmt->type = type;
+       if (index >= NUM_OUTPUT_FORMATS)
+               return -EINVAL;
+
+       fmt->flags = omap_formats[index].flags;
+       strlcpy(fmt->description, omap_formats[index].description,
+                       sizeof(fmt->description));
+       fmt->pixelformat = omap_formats[index].pixelformat;
+       return 0;
+}
+
+static int vidioc_g_fmt_vid_overlay(struct file *file, void *fh,
+                       struct v4l2_format *f)
+{
+       u32 key_value =  0;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_vout_device *vout = fh;
+       struct omap_overlay_manager_info info;
+       struct v4l2_window *win = &f->fmt.win;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       win->w = vout->win.w;
+       win->field = vout->win.field;
+       win->global_alpha = vout->win.global_alpha;
+
+       if (ovl->manager && ovl->manager->get_manager_info) {
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               key_value = info.trans_key;
+       }
+       win->chromakey = key_value;
+       return 0;
+}
+
+static int vidioc_cropcap(struct file *file, void *fh,
+               struct v4l2_cropcap *cropcap)
+{
+       struct omap_vout_device *vout = fh;
+       struct v4l2_pix_format *pix = &vout->pix;
+
+       if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+
+       /* Width and height are always even */
+       cropcap->bounds.width = pix->width & ~1;
+       cropcap->bounds.height = pix->height & ~1;
+
+       omap_vout_default_crop(&vout->pix, &vout->fbuf, &cropcap->defrect);
+       cropcap->pixelaspect.numerator = 1;
+       cropcap->pixelaspect.denominator = 1;
+       return 0;
+}
+
+static int vidioc_g_crop(struct file *file, void *fh, struct v4l2_crop *crop)
+{
+       struct omap_vout_device *vout = fh;
+
+       if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+       crop->c = vout->crop;
+       return 0;
+}
+
+static int vidioc_s_crop(struct file *file, void *fh, struct v4l2_crop *crop)
+{
+       int ret = -EINVAL;
+       struct omap_vout_device *vout = fh;
+       struct omapvideo_info *ovid;
+       struct omap_overlay *ovl;
+       struct omap_video_timings *timing;
+
+       if (vout->streaming)
+               return -EBUSY;
+
+       mutex_lock(&vout->lock);
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       if (!ovl->manager || !ovl->manager->device) {
+               ret = -EINVAL;
+               goto s_crop_err;
+       }
+       /* get the display device attached to the overlay */
+       timing = &ovl->manager->device->panel.timings;
+
+       if (rotate_90_or_270(vout)) {
+               vout->fbuf.fmt.height = timing->x_res;
+               vout->fbuf.fmt.width = timing->y_res;
+       } else {
+               vout->fbuf.fmt.height = timing->y_res;
+               vout->fbuf.fmt.width = timing->x_res;
+       }
+
+       if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               ret = omap_vout_new_crop(&vout->pix, &vout->crop, &vout->win,
+                               &vout->fbuf, &crop->c);
+
+s_crop_err:
+       mutex_unlock(&vout->lock);
+       return ret;
+}
+
+static int vidioc_queryctrl(struct file *file, void *fh,
+               struct v4l2_queryctrl *ctrl)
+{
+       int ret = 0;
+
+       switch (ctrl->id) {
+       case V4L2_CID_ROTATE:
+               ret = v4l2_ctrl_query_fill(ctrl, 0, 270, 90, 0);
+               break;
+       case V4L2_CID_BG_COLOR:
+               ret = v4l2_ctrl_query_fill(ctrl, 0, 0xFFFFFF, 1, 0);
+               break;
+       case V4L2_CID_VFLIP:
+               ret = v4l2_ctrl_query_fill(ctrl, 0, 1, 1, 0);
+               break;
+       default:
+               ctrl->name[0] = '\0';
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *ctrl)
+{
+       int ret = 0;
+       struct omap_vout_device *vout = fh;
+
+       switch (ctrl->id) {
+       case V4L2_CID_ROTATE:
+               ctrl->value = vout->control[0].value;
+               break;
+       case V4L2_CID_BG_COLOR:
+       {
+               struct omap_overlay_manager_info info;
+               struct omap_overlay *ovl;
+
+               ovl = vout->vid_info.overlays[0];
+               if (!ovl->manager || !ovl->manager->get_manager_info) {
+                       ret = -EINVAL;
+                       break;
+               }
+
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               ctrl->value = info.default_color;
+               break;
+       }
+       case V4L2_CID_VFLIP:
+               ctrl->value = vout->control[2].value;
+               break;
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *a)
+{
+       int ret = 0;
+       struct omap_vout_device *vout = fh;
+
+       switch (a->id) {
+       case V4L2_CID_ROTATE:
+       {
+               int rotation = a->value;
+
+               mutex_lock(&vout->lock);
+
+               if (rotation && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
+                       mutex_unlock(&vout->lock);
+                       ret = -EINVAL;
+                       break;
+               }
+
+               if (v4l2_rot_to_dss_rot(rotation, &vout->rotation,
+                                                       vout->mirror)) {
+                       mutex_unlock(&vout->lock);
+                       ret = -EINVAL;
+                       break;
+               }
+
+               vout->control[0].value = rotation;
+               mutex_unlock(&vout->lock);
+               break;
+       }
+       case V4L2_CID_BG_COLOR:
+       {
+               struct omap_overlay *ovl;
+               unsigned int  color = a->value;
+               struct omap_overlay_manager_info info;
+
+               ovl = vout->vid_info.overlays[0];
+
+               mutex_lock(&vout->lock);
+               if (!ovl->manager || !ovl->manager->get_manager_info) {
+                       mutex_unlock(&vout->lock);
+                       ret = -EINVAL;
+                       break;
+               }
+
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               info.default_color = color;
+               if (ovl->manager->set_manager_info(ovl->manager, &info)) {
+                       mutex_unlock(&vout->lock);
+                       ret = -EINVAL;
+                       break;
+               }
+
+               vout->control[1].value = color;
+               mutex_unlock(&vout->lock);
+               break;
+       }
+       case V4L2_CID_VFLIP:
+       {
+               struct omap_overlay *ovl;
+               struct omapvideo_info *ovid;
+               unsigned int  mirror = a->value;
+
+               ovid = &vout->vid_info;
+               ovl = ovid->overlays[0];
+
+               mutex_lock(&vout->lock);
+
+               if (mirror  && vout->pix.pixelformat == V4L2_PIX_FMT_RGB24) {
+                       mutex_unlock(&vout->lock);
+                       ret = -EINVAL;
+                       break;
+               }
+               vout->mirror = mirror;
+               vout->control[2].value = mirror;
+               mutex_unlock(&vout->lock);
+               break;
+       }
+       default:
+               ret = -EINVAL;
+       }
+       return ret;
+}
+
+static int vidioc_reqbufs(struct file *file, void *fh,
+                       struct v4l2_requestbuffers *req)
+{
+       int ret = 0;
+       unsigned int i, num_buffers = 0;
+       struct omap_vout_device *vout = fh;
+       struct videobuf_queue *q = &vout->vbq;
+       struct videobuf_dmabuf *dmabuf = NULL;
+
+       if ((req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT) || (req->count < 0))
+               return -EINVAL;
+       /* if memory is not mmp or userptr
+          return error */
+       if ((V4L2_MEMORY_MMAP != req->memory) &&
+                       (V4L2_MEMORY_USERPTR != req->memory))
+               return -EINVAL;
+
+       mutex_lock(&vout->lock);
+       /* Cannot be requested when streaming is on */
+       if (vout->streaming) {
+               ret = -EBUSY;
+               goto reqbuf_err;
+       }
+
+       /* If buffers are already allocated free them */
+       if (q->bufs[0] && (V4L2_MEMORY_MMAP == q->bufs[0]->memory)) {
+               if (vout->mmap_count) {
+                       ret = -EBUSY;
+                       goto reqbuf_err;
+               }
+               num_buffers = (vout->vid == OMAP_VIDEO1) ?
+                       video1_numbuffers : video2_numbuffers;
+               for (i = num_buffers; i < vout->buffer_allocated; i++) {
+                       dmabuf = videobuf_to_dma(q->bufs[i]);
+                       omap_vout_free_buffer((u32)dmabuf->vmalloc,
+                                       vout->buffer_size);
+                       vout->buf_virt_addr[i] = 0;
+                       vout->buf_phy_addr[i] = 0;
+               }
+               vout->buffer_allocated = num_buffers;
+               videobuf_mmap_free(q);
+       } else if (q->bufs[0] && (V4L2_MEMORY_USERPTR == q->bufs[0]->memory)) {
+               if (vout->buffer_allocated) {
+                       videobuf_mmap_free(q);
+                       for (i = 0; i < vout->buffer_allocated; i++) {
+                               kfree(q->bufs[i]);
+                               q->bufs[i] = NULL;
+                       }
+                       vout->buffer_allocated = 0;
+               }
+       }
+
+       /*store the memory type in data structure */
+       vout->memory = req->memory;
+
+       INIT_LIST_HEAD(&vout->dma_queue);
+
+       /* call videobuf_reqbufs api */
+       ret = videobuf_reqbufs(q, req);
+       if (ret < 0)
+               goto reqbuf_err;
+
+       vout->buffer_allocated = req->count;
+       for (i = 0; i < req->count; i++) {
+               dmabuf = videobuf_to_dma(q->bufs[i]);
+               dmabuf->vmalloc = (void *) vout->buf_virt_addr[i];
+               dmabuf->bus_addr = (dma_addr_t) vout->buf_phy_addr[i];
+               dmabuf->sglen = 1;
+       }
+reqbuf_err:
+       mutex_unlock(&vout->lock);
+       return ret;
+}
+
+static int vidioc_querybuf(struct file *file, void *fh,
+                       struct v4l2_buffer *b)
+{
+       struct omap_vout_device *vout = fh;
+
+       return videobuf_querybuf(&vout->vbq, b);
+}
+
+static int vidioc_qbuf(struct file *file, void *fh,
+                       struct v4l2_buffer *buffer)
+{
+       struct omap_vout_device *vout = fh;
+       struct videobuf_queue *q = &vout->vbq;
+
+       if ((V4L2_BUF_TYPE_VIDEO_OUTPUT != buffer->type) ||
+                       (buffer->index >= vout->buffer_allocated) ||
+                       (q->bufs[buffer->index]->memory != buffer->memory)) {
+               return -EINVAL;
+       }
+       if (V4L2_MEMORY_USERPTR == buffer->memory) {
+               if ((buffer->length < vout->pix.sizeimage) ||
+                               (0 == buffer->m.userptr)) {
+                       return -EINVAL;
+               }
+       }
+
+       if ((rotation_enabled(vout)) &&
+                       vout->vrfb_dma_tx.req_status == DMA_CHAN_NOT_ALLOTED) {
+               v4l2_warn(&vout->vid_dev->v4l2_dev,
+                               "DMA Channel not allocated for Rotation\n");
+               return -EINVAL;
+       }
+
+       return videobuf_qbuf(q, buffer);
+}
+
+static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
+{
+       struct omap_vout_device *vout = fh;
+       struct videobuf_queue *q = &vout->vbq;
+
+       if (!vout->streaming)
+               return -EINVAL;
+
+       if (file->f_flags & O_NONBLOCK)
+               /* Call videobuf_dqbuf for non blocking mode */
+               return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 1);
+       else
+               /* Call videobuf_dqbuf for  blocking mode */
+               return videobuf_dqbuf(q, (struct v4l2_buffer *)b, 0);
+}
+
+static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
+{
+       int ret = 0, j;
+       u32 addr = 0, mask = 0;
+       struct omap_vout_device *vout = fh;
+       struct videobuf_queue *q = &vout->vbq;
+       struct omapvideo_info *ovid = &vout->vid_info;
+
+       mutex_lock(&vout->lock);
+
+       if (vout->streaming) {
+               ret = -EBUSY;
+               goto streamon_err;
+       }
+
+       ret = videobuf_streamon(q);
+       if (ret)
+               goto streamon_err;
+
+       if (list_empty(&vout->dma_queue)) {
+               ret = -EIO;
+               goto streamon_err1;
+       }
+
+       /* Get the next frame from the buffer queue */
+       vout->next_frm = vout->cur_frm = list_entry(vout->dma_queue.next,
+                       struct videobuf_buffer, queue);
+       /* Remove buffer from the buffer queue */
+       list_del(&vout->cur_frm->queue);
+       /* Mark state of the current frame to active */
+       vout->cur_frm->state = VIDEOBUF_ACTIVE;
+       /* Initialize field_id and started member */
+       vout->field_id = 0;
+
+       /* set flag here. Next QBUF will start DMA */
+       vout->streaming = 1;
+
+       vout->first_int = 1;
+
+       if (omap_vout_calculate_offset(vout)) {
+               ret = -EINVAL;
+               goto streamon_err1;
+       }
+       addr = (unsigned long) vout->queued_buf_addr[vout->cur_frm->i]
+               + vout->cropped_offset;
+
+       mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
+
+       omap_dispc_register_isr(omap_vout_isr, vout, mask);
+
+       for (j = 0; j < ovid->num_overlays; j++) {
+               struct omap_overlay *ovl = ovid->overlays[j];
+
+               if (ovl->manager && ovl->manager->device) {
+                       struct omap_overlay_info info;
+                       ovl->get_overlay_info(ovl, &info);
+                       info.enabled = 1;
+                       info.paddr = addr;
+                       if (ovl->set_overlay_info(ovl, &info)) {
+                               ret = -EINVAL;
+                               goto streamon_err1;
+                       }
+               }
+       }
+
+       /* First save the configuration in ovelray structure */
+       ret = omapvid_init(vout, addr);
+       if (ret)
+               v4l2_err(&vout->vid_dev->v4l2_dev,
+                               "failed to set overlay info\n");
+       /* Enable the pipeline and set the Go bit */
+       ret = omapvid_apply_changes(vout);
+       if (ret)
+               v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode\n");
+
+       ret = 0;
+
+streamon_err1:
+       if (ret)
+               ret = videobuf_streamoff(q);
+streamon_err:
+       mutex_unlock(&vout->lock);
+       return ret;
+}
+
+static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
+{
+       u32 mask = 0;
+       int ret = 0, j;
+       struct omap_vout_device *vout = fh;
+       struct omapvideo_info *ovid = &vout->vid_info;
+
+       if (!vout->streaming)
+               return -EINVAL;
+
+       vout->streaming = 0;
+       mask = DISPC_IRQ_VSYNC | DISPC_IRQ_EVSYNC_EVEN | DISPC_IRQ_EVSYNC_ODD;
+
+       omap_dispc_unregister_isr(omap_vout_isr, vout, mask);
+
+       for (j = 0; j < ovid->num_overlays; j++) {
+               struct omap_overlay *ovl = ovid->overlays[j];
+
+               if (ovl->manager && ovl->manager->device) {
+                       struct omap_overlay_info info;
+
+                       ovl->get_overlay_info(ovl, &info);
+                       info.enabled = 0;
+                       ret = ovl->set_overlay_info(ovl, &info);
+                       if (ret)
+                               v4l2_err(&vout->vid_dev->v4l2_dev,
+                               "failed to update overlay info in streamoff\n");
+               }
+       }
+
+       /* Turn of the pipeline */
+       ret = omapvid_apply_changes(vout);
+       if (ret)
+               v4l2_err(&vout->vid_dev->v4l2_dev, "failed to change mode in"
+                               " streamoff\n");
+
+       INIT_LIST_HEAD(&vout->dma_queue);
+       ret = videobuf_streamoff(&vout->vbq);
+
+       return ret;
+}
+
+static int vidioc_s_fbuf(struct file *file, void *fh,
+                               struct v4l2_framebuffer *a)
+{
+       int enable = 0;
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_vout_device *vout = fh;
+       struct omap_overlay_manager_info info;
+       enum omap_dss_trans_key_type key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       /* OMAP DSS doesn't support Source and Destination color
+          key together */
+       if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY) &&
+                       (a->flags & V4L2_FBUF_FLAG_CHROMAKEY))
+               return -EINVAL;
+       /* OMAP DSS Doesn't support the Destination color key
+          and alpha blending together */
+       if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY) &&
+                       (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA))
+               return -EINVAL;
+
+       if ((a->flags & V4L2_FBUF_FLAG_SRC_CHROMAKEY)) {
+               vout->fbuf.flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
+               key_type =  OMAP_DSS_COLOR_KEY_VID_SRC;
+       } else
+               vout->fbuf.flags &= ~V4L2_FBUF_FLAG_SRC_CHROMAKEY;
+
+       if ((a->flags & V4L2_FBUF_FLAG_CHROMAKEY)) {
+               vout->fbuf.flags |= V4L2_FBUF_FLAG_CHROMAKEY;
+               key_type =  OMAP_DSS_COLOR_KEY_GFX_DST;
+       } else
+               vout->fbuf.flags &=  ~V4L2_FBUF_FLAG_CHROMAKEY;
+
+       if (a->flags & (V4L2_FBUF_FLAG_CHROMAKEY |
+                               V4L2_FBUF_FLAG_SRC_CHROMAKEY))
+               enable = 1;
+       else
+               enable = 0;
+       if (ovl->manager && ovl->manager->get_manager_info &&
+                       ovl->manager->set_manager_info) {
+
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               info.trans_enabled = enable;
+               info.trans_key_type = key_type;
+               info.trans_key = vout->win.chromakey;
+
+               if (ovl->manager->set_manager_info(ovl->manager, &info))
+                       return -EINVAL;
+       }
+       if (a->flags & V4L2_FBUF_FLAG_LOCAL_ALPHA) {
+               vout->fbuf.flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
+               enable = 1;
+       } else {
+               vout->fbuf.flags &= ~V4L2_FBUF_FLAG_LOCAL_ALPHA;
+               enable = 0;
+       }
+       if (ovl->manager && ovl->manager->get_manager_info &&
+                       ovl->manager->set_manager_info) {
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               info.alpha_enabled = enable;
+               if (ovl->manager->set_manager_info(ovl->manager, &info))
+                       return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int vidioc_g_fbuf(struct file *file, void *fh,
+               struct v4l2_framebuffer *a)
+{
+       struct omap_overlay *ovl;
+       struct omapvideo_info *ovid;
+       struct omap_vout_device *vout = fh;
+       struct omap_overlay_manager_info info;
+
+       ovid = &vout->vid_info;
+       ovl = ovid->overlays[0];
+
+       a->flags = 0x0;
+       a->capability = V4L2_FBUF_CAP_LOCAL_ALPHA | V4L2_FBUF_CAP_CHROMAKEY
+               | V4L2_FBUF_CAP_SRC_CHROMAKEY;
+
+       if (ovl->manager && ovl->manager->get_manager_info) {
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               if (info.trans_key_type == OMAP_DSS_COLOR_KEY_VID_SRC)
+                       a->flags |= V4L2_FBUF_FLAG_SRC_CHROMAKEY;
+               if (info.trans_key_type == OMAP_DSS_COLOR_KEY_GFX_DST)
+                       a->flags |= V4L2_FBUF_FLAG_CHROMAKEY;
+       }
+       if (ovl->manager && ovl->manager->get_manager_info) {
+               ovl->manager->get_manager_info(ovl->manager, &info);
+               if (info.alpha_enabled)
+                       a->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
+       }
+
+       return 0;
+}
+
+static const struct v4l2_ioctl_ops vout_ioctl_ops = {
+       .vidioc_querycap                        = vidioc_querycap,
+       .vidioc_enum_fmt_vid_out                = vidioc_enum_fmt_vid_out,
+       .vidioc_g_fmt_vid_out                   = vidioc_g_fmt_vid_out,
+       .vidioc_try_fmt_vid_out                 = vidioc_try_fmt_vid_out,
+       .vidioc_s_fmt_vid_out                   = vidioc_s_fmt_vid_out,
+       .vidioc_queryctrl                       = vidioc_queryctrl,
+       .vidioc_g_ctrl                          = vidioc_g_ctrl,
+       .vidioc_s_fbuf                          = vidioc_s_fbuf,
+       .vidioc_g_fbuf                          = vidioc_g_fbuf,
+       .vidioc_s_ctrl                          = vidioc_s_ctrl,
+       .vidioc_try_fmt_vid_overlay             = vidioc_try_fmt_vid_overlay,
+       .vidioc_s_fmt_vid_overlay               = vidioc_s_fmt_vid_overlay,
+       .vidioc_enum_fmt_vid_overlay            = vidioc_enum_fmt_vid_overlay,
+       .vidioc_g_fmt_vid_overlay               = vidioc_g_fmt_vid_overlay,
+       .vidioc_cropcap                         = vidioc_cropcap,
+       .vidioc_g_crop                          = vidioc_g_crop,
+       .vidioc_s_crop                          = vidioc_s_crop,
+       .vidioc_reqbufs                         = vidioc_reqbufs,
+       .vidioc_querybuf                        = vidioc_querybuf,
+       .vidioc_qbuf                            = vidioc_qbuf,
+       .vidioc_dqbuf                           = vidioc_dqbuf,
+       .vidioc_streamon                        = vidioc_streamon,
+       .vidioc_streamoff                       = vidioc_streamoff,
+};
+
+static const struct v4l2_file_operations omap_vout_fops = {
+       .owner          = THIS_MODULE,
+       .unlocked_ioctl = video_ioctl2,
+       .mmap           = omap_vout_mmap,
+       .open           = omap_vout_open,
+       .release        = omap_vout_release,
+};
+
+/* Init functions used during driver initialization */
+/* Initial setup of video_data */
+static int __init omap_vout_setup_video_data(struct omap_vout_device *vout)
+{
+       struct video_device *vfd;
+       struct v4l2_pix_format *pix;
+       struct v4l2_control *control;
+       struct omap_dss_device *display =
+               vout->vid_info.overlays[0]->manager->device;
+
+       /* set the default pix */
+       pix = &vout->pix;
+
+       /* Set the default picture of QVGA  */
+       pix->width = QQVGA_WIDTH;
+       pix->height = QQVGA_HEIGHT;
+
+       /* Default pixel format is RGB 5-6-5 */
+       pix->pixelformat = V4L2_PIX_FMT_RGB565;
+       pix->field = V4L2_FIELD_ANY;
+       pix->bytesperline = pix->width * 2;
+       pix->sizeimage = pix->bytesperline * pix->height;
+       pix->priv = 0;
+       pix->colorspace = V4L2_COLORSPACE_JPEG;
+
+       vout->bpp = RGB565_BPP;
+       vout->fbuf.fmt.width  =  display->panel.timings.x_res;
+       vout->fbuf.fmt.height =  display->panel.timings.y_res;
+
+       /* Set the data structures for the overlay parameters*/
+       vout->win.global_alpha = 255;
+       vout->fbuf.flags = 0;
+       vout->fbuf.capability = V4L2_FBUF_CAP_LOCAL_ALPHA |
+               V4L2_FBUF_CAP_SRC_CHROMAKEY | V4L2_FBUF_CAP_CHROMAKEY;
+       vout->win.chromakey = 0;
+
+       omap_vout_new_format(pix, &vout->fbuf, &vout->crop, &vout->win);
+
+       /*Initialize the control variables for
+         rotation, flipping and background color. */
+       control = vout->control;
+       control[0].id = V4L2_CID_ROTATE;
+       control[0].value = 0;
+       vout->rotation = 0;
+       vout->mirror = 0;
+       vout->control[2].id = V4L2_CID_HFLIP;
+       vout->control[2].value = 0;
+       vout->vrfb_bpp = 2;
+
+       control[1].id = V4L2_CID_BG_COLOR;
+       control[1].value = 0;
+
+       /* initialize the video_device struct */
+       vfd = vout->vfd = video_device_alloc();
+
+       if (!vfd) {
+               printk(KERN_ERR VOUT_NAME ": could not allocate"
+                               " video device struct\n");
+               return -ENOMEM;
+       }
+       vfd->release = video_device_release;
+       vfd->ioctl_ops = &vout_ioctl_ops;
+
+       strlcpy(vfd->name, VOUT_NAME, sizeof(vfd->name));
+
+       /* need to register for a VID_HARDWARE_* ID in videodev.h */
+       vfd->fops = &omap_vout_fops;
+       vfd->v4l2_dev = &vout->vid_dev->v4l2_dev;
+       mutex_init(&vout->lock);
+
+       vfd->minor = -1;
+       return 0;
+
+}
+
+/* Setup video buffers */
+static int __init omap_vout_setup_video_bufs(struct platform_device *pdev,
+               int vid_num)
+{
+       u32 numbuffers;
+       int ret = 0, i, j;
+       int image_width, image_height;
+       struct video_device *vfd;
+       struct omap_vout_device *vout;
+       int static_vrfb_allocation = 0, vrfb_num_bufs = VRFB_NUM_BUFS;
+       struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+       struct omap2video_device *vid_dev =
+               container_of(v4l2_dev, struct omap2video_device, v4l2_dev);
+
+       vout = vid_dev->vouts[vid_num];
+       vfd = vout->vfd;
+
+       numbuffers = (vid_num == 0) ? video1_numbuffers : video2_numbuffers;
+       vout->buffer_size = (vid_num == 0) ? video1_bufsize : video2_bufsize;
+       dev_info(&pdev->dev, "Buffer Size = %d\n", vout->buffer_size);
+
+       for (i = 0; i < numbuffers; i++) {
+               vout->buf_virt_addr[i] =
+                       omap_vout_alloc_buffer(vout->buffer_size,
+                                       (u32 *) &vout->buf_phy_addr[i]);
+               if (!vout->buf_virt_addr[i]) {
+                       numbuffers = i;
+                       ret = -ENOMEM;
+                       goto free_buffers;
+               }
+       }
+
+       for (i = 0; i < VRFB_NUM_BUFS; i++) {
+               if (omap_vrfb_request_ctx(&vout->vrfb_context[i])) {
+                       dev_info(&pdev->dev, ": VRFB allocation failed\n");
+                       for (j = 0; j < i; j++)
+                               omap_vrfb_release_ctx(&vout->vrfb_context[j]);
+                       ret = -ENOMEM;
+                       goto free_buffers;
+               }
+       }
+       vout->cropped_offset = 0;
+
+       /* Calculate VRFB memory size */
+       /* allocate for worst case size */
+       image_width = VID_MAX_WIDTH / TILE_SIZE;
+       if (VID_MAX_WIDTH % TILE_SIZE)
+               image_width++;
+
+       image_width = image_width * TILE_SIZE;
+       image_height = VID_MAX_HEIGHT / TILE_SIZE;
+
+       if (VID_MAX_HEIGHT % TILE_SIZE)
+               image_height++;
+
+       image_height = image_height * TILE_SIZE;
+       vout->smsshado_size = PAGE_ALIGN(image_width * image_height * 2 * 2);
+
+       /*
+        * Request and Initialize DMA, for DMA based VRFB transfer
+        */
+       vout->vrfb_dma_tx.dev_id = OMAP_DMA_NO_DEVICE;
+       vout->vrfb_dma_tx.dma_ch = -1;
+       vout->vrfb_dma_tx.req_status = DMA_CHAN_ALLOTED;
+       ret = omap_request_dma(vout->vrfb_dma_tx.dev_id, "VRFB DMA TX",
+                       omap_vout_vrfb_dma_tx_callback,
+                       (void *) &vout->vrfb_dma_tx, &vout->vrfb_dma_tx.dma_ch);
+       if (ret < 0) {
+               vout->vrfb_dma_tx.req_status = DMA_CHAN_NOT_ALLOTED;
+               dev_info(&pdev->dev, ": failed to allocate DMA Channel for"
+                               " video%d\n", vfd->minor);
+       }
+       init_waitqueue_head(&vout->vrfb_dma_tx.wait);
+
+       /* Allocate VRFB buffers if selected through bootargs */
+       static_vrfb_allocation = (vid_num == 0) ?
+               vid1_static_vrfb_alloc : vid2_static_vrfb_alloc;
+
+       /* statically allocated the VRFB buffer is done through
+          commands line aruments */
+       if (static_vrfb_allocation) {
+               if (omap_vout_allocate_vrfb_buffers(vout, &vrfb_num_bufs, -1)) {
+                       ret =  -ENOMEM;
+                       goto release_vrfb_ctx;
+               }
+               vout->vrfb_static_allocation = 1;
+       }
+       return 0;
+
+release_vrfb_ctx:
+       for (j = 0; j < VRFB_NUM_BUFS; j++)
+               omap_vrfb_release_ctx(&vout->vrfb_context[j]);
+
+free_buffers:
+       for (i = 0; i < numbuffers; i++) {
+               omap_vout_free_buffer(vout->buf_virt_addr[i],
+                                               vout->buffer_size);
+               vout->buf_virt_addr[i] = 0;
+               vout->buf_phy_addr[i] = 0;
+       }
+       return ret;
+
+}
+
+/* Create video out devices */
+static int __init omap_vout_create_video_devices(struct platform_device *pdev)
+{
+       int ret = 0, k;
+       struct omap_vout_device *vout;
+       struct video_device *vfd = NULL;
+       struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+       struct omap2video_device *vid_dev = container_of(v4l2_dev,
+                       struct omap2video_device, v4l2_dev);
+
+       for (k = 0; k < pdev->num_resources; k++) {
+
+               vout = kmalloc(sizeof(struct omap_vout_device), GFP_KERNEL);
+               if (!vout) {
+                       dev_err(&pdev->dev, ": could not allocate memory\n");
+                       return -ENOMEM;
+               }
+               memset(vout, 0, sizeof(struct omap_vout_device));
+
+               vout->vid = k;
+               vid_dev->vouts[k] = vout;
+               vout->vid_dev = vid_dev;
+               /* Select video2 if only 1 overlay is controlled by V4L2 */
+               if (pdev->num_resources == 1)
+                       vout->vid_info.overlays[0] = vid_dev->overlays[k + 2];
+               else
+                       /* Else select video1 and video2 one by one. */
+                       vout->vid_info.overlays[0] = vid_dev->overlays[k + 1];
+               vout->vid_info.num_overlays = 1;
+               vout->vid_info.id = k + 1;
+
+               /* Setup the default configuration for the video devices
+                */
+               if (omap_vout_setup_video_data(vout) != 0) {
+                       ret = -ENOMEM;
+                       goto error;
+               }
+
+               /* Allocate default number of buffers for the video streaming
+                * and reserve the VRFB space for rotation
+                */
+               if (omap_vout_setup_video_bufs(pdev, k) != 0) {
+                       ret = -ENOMEM;
+                       goto error1;
+               }
+
+               /* Register the Video device with V4L2
+                */
+               vfd = vout->vfd;
+               if (video_register_device(vfd, VFL_TYPE_GRABBER, k + 1) < 0) {
+                       dev_err(&pdev->dev, ": Could not register "
+                                       "Video for Linux device\n");
+                       vfd->minor = -1;
+                       ret = -ENODEV;
+                       goto error2;
+               }
+               video_set_drvdata(vfd, vout);
+
+               /* Configure the overlay structure */
+               ret = omapvid_init(vid_dev->vouts[k], 0);
+               if (!ret)
+                       goto success;
+
+error2:
+               omap_vout_release_vrfb(vout);
+               omap_vout_free_buffers(vout);
+error1:
+               video_device_release(vfd);
+error:
+               kfree(vout);
+               return ret;
+
+success:
+               dev_info(&pdev->dev, ": registered and initialized"
+                               " video device %d\n", vfd->minor);
+               if (k == (pdev->num_resources - 1))
+                       return 0;
+       }
+
+       return -ENODEV;
+}
+/* Driver functions */
+static void omap_vout_cleanup_device(struct omap_vout_device *vout)
+{
+       struct video_device *vfd;
+
+       if (!vout)
+               return;
+
+       vfd = vout->vfd;
+       if (vfd) {
+               if (!video_is_registered(vfd)) {
+                       /*
+                        * The device was never registered, so release the
+                        * video_device struct directly.
+                        */
+                       video_device_release(vfd);
+               } else {
+                       /*
+                        * The unregister function will release the video_device
+                        * struct as well as unregistering it.
+                        */
+                       video_unregister_device(vfd);
+               }
+       }
+
+       omap_vout_release_vrfb(vout);
+       omap_vout_free_buffers(vout);
+       /* Free the VRFB buffer if allocated
+        * init time
+        */
+       if (vout->vrfb_static_allocation)
+               omap_vout_free_vrfb_buffers(vout);
+
+       kfree(vout);
+}
+
+static int omap_vout_remove(struct platform_device *pdev)
+{
+       int k;
+       struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+       struct omap2video_device *vid_dev = container_of(v4l2_dev, struct
+                       omap2video_device, v4l2_dev);
+
+       v4l2_device_unregister(v4l2_dev);
+       for (k = 0; k < pdev->num_resources; k++)
+               omap_vout_cleanup_device(vid_dev->vouts[k]);
+
+       for (k = 0; k < vid_dev->num_displays; k++) {
+               if (vid_dev->displays[k]->state != OMAP_DSS_DISPLAY_DISABLED)
+                       vid_dev->displays[k]->disable(vid_dev->displays[k]);
+
+               omap_dss_put_device(vid_dev->displays[k]);
+       }
+       kfree(vid_dev);
+       return 0;
+}
+
+static int __init omap_vout_probe(struct platform_device *pdev)
+{
+       int ret = 0, i;
+       struct omap_overlay *ovl;
+       struct omap_dss_device *dssdev = NULL;
+       struct omap_dss_device *def_display;
+       struct omap2video_device *vid_dev = NULL;
+
+       if (pdev->num_resources == 0) {
+               dev_err(&pdev->dev, "probed for an unknown device\n");
+               return -ENODEV;
+       }
+
+       vid_dev = kzalloc(sizeof(struct omap2video_device), GFP_KERNEL);
+       if (vid_dev == NULL)
+               return -ENOMEM;
+
+       vid_dev->num_displays = 0;
+       for_each_dss_dev(dssdev) {
+               omap_dss_get_device(dssdev);
+               vid_dev->displays[vid_dev->num_displays++] = dssdev;
+       }
+
+       if (vid_dev->num_displays == 0) {
+               dev_err(&pdev->dev, "no displays\n");
+               ret = -EINVAL;
+               goto probe_err0;
+       }
+
+       vid_dev->num_overlays = omap_dss_get_num_overlays();
+       for (i = 0; i < vid_dev->num_overlays; i++)
+               vid_dev->overlays[i] = omap_dss_get_overlay(i);
+
+       vid_dev->num_managers = omap_dss_get_num_overlay_managers();
+       for (i = 0; i < vid_dev->num_managers; i++)
+               vid_dev->managers[i] = omap_dss_get_overlay_manager(i);
+
+       /* Get the Video1 overlay and video2 overlay.
+        * Setup the Display attached to that overlays
+        */
+       for (i = 1; i < vid_dev->num_overlays; i++) {
+               ovl = omap_dss_get_overlay(i);
+               if (ovl->manager && ovl->manager->device) {
+                       def_display = ovl->manager->device;
+               } else {
+                       dev_warn(&pdev->dev, "cannot find display\n");
+                       def_display = NULL;
+               }
+               if (def_display) {
+                       ret = def_display->enable(def_display);
+                       if (ret) {
+                               /* Here we are not considering a error
+                                *  as display may be enabled by frame
+                                *  buffer driver
+                                */
+                               dev_warn(&pdev->dev,
+                                       "'%s' Display already enabled\n",
+                                       def_display->name);
+                       }
+                       /* set the update mode */
+                       if (def_display->caps &
+                                       OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE) {
+#ifdef CONFIG_FB_OMAP2_FORCE_AUTO_UPDATE
+                               if (def_display->enable_te)
+                                       def_display->enable_te(def_display, 1);
+                               if (def_display->set_update_mode)
+                                       def_display->set_update_mode(def_display,
+                                                       OMAP_DSS_UPDATE_AUTO);
+#else  /* MANUAL_UPDATE */
+                               if (def_display->enable_te)
+                                       def_display->enable_te(def_display, 0);
+                               if (def_display->set_update_mode)
+                                       def_display->set_update_mode(def_display,
+                                                       OMAP_DSS_UPDATE_MANUAL);
+#endif
+                       } else {
+                               if (def_display->set_update_mode)
+                                       def_display->set_update_mode(def_display,
+                                                       OMAP_DSS_UPDATE_AUTO);
+                       }
+               }
+       }
+
+       if (v4l2_device_register(&pdev->dev, &vid_dev->v4l2_dev) < 0) {
+               dev_err(&pdev->dev, "v4l2_device_register failed\n");
+               ret = -ENODEV;
+               goto probe_err1;
+       }
+
+       ret = omap_vout_create_video_devices(pdev);
+       if (ret)
+               goto probe_err2;
+
+       for (i = 0; i < vid_dev->num_displays; i++) {
+               struct omap_dss_device *display = vid_dev->displays[i];
+
+               if (display->update)
+                       display->update(display, 0, 0,
+                                       display->panel.timings.x_res,
+                                       display->panel.timings.y_res);
+       }
+       return 0;
+
+probe_err2:
+       v4l2_device_unregister(&vid_dev->v4l2_dev);
+probe_err1:
+       for (i = 1; i < vid_dev->num_overlays; i++) {
+               def_display = NULL;
+               ovl = omap_dss_get_overlay(i);
+               if (ovl->manager && ovl->manager->device)
+                       def_display = ovl->manager->device;
+
+               if (def_display)
+                       def_display->disable(def_display);
+       }
+probe_err0:
+       kfree(vid_dev);
+       return ret;
+}
+
+static struct platform_driver omap_vout_driver = {
+       .driver = {
+               .name = VOUT_NAME,
+       },
+       .probe = omap_vout_probe,
+       .remove = omap_vout_remove,
+};
+
+static int __init omap_vout_init(void)
+{
+       if (platform_driver_register(&omap_vout_driver) != 0) {
+               printk(KERN_ERR VOUT_NAME ":Could not register Video driver\n");
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static void omap_vout_cleanup(void)
+{
+       platform_driver_unregister(&omap_vout_driver);
+}
+
+late_initcall(omap_vout_init);
+module_exit(omap_vout_cleanup);
diff --git a/drivers/media/video/omap/omap_voutdef.h b/drivers/media/video/omap/omap_voutdef.h
new file mode 100644 (file)
index 0000000..ea3a047
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * omap_voutdef.h
+ *
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#ifndef OMAP_VOUTDEF_H
+#define OMAP_VOUTDEF_H
+
+#include <plat/display.h>
+
+#define YUYV_BPP        2
+#define RGB565_BPP      2
+#define RGB24_BPP       3
+#define RGB32_BPP       4
+#define TILE_SIZE       32
+#define YUYV_VRFB_BPP   2
+#define RGB_VRFB_BPP    1
+#define MAX_CID                3
+#define MAC_VRFB_CTXS  4
+#define MAX_VOUT_DEV   2
+#define MAX_OVLS       3
+#define MAX_DISPLAYS   3
+#define MAX_MANAGERS   3
+
+/* Enum for Rotation
+ * DSS understands rotation in 0, 1, 2, 3 context
+ * while V4L2 driver understands it as 0, 90, 180, 270
+ */
+enum dss_rotation {
+       dss_rotation_0_degree   = 0,
+       dss_rotation_90_degree  = 1,
+       dss_rotation_180_degree = 2,
+       dss_rotation_270_degree = 3,
+};
+/*
+ * This structure is used to store the DMA transfer parameters
+ * for VRFB hidden buffer
+ */
+struct vid_vrfb_dma {
+       int dev_id;
+       int dma_ch;
+       int req_status;
+       int tx_status;
+       wait_queue_head_t wait;
+};
+
+struct omapvideo_info {
+       int id;
+       int num_overlays;
+       struct omap_overlay *overlays[MAX_OVLS];
+};
+
+struct omap2video_device {
+       struct mutex  mtx;
+
+       int state;
+
+       struct v4l2_device v4l2_dev;
+       struct omap_vout_device *vouts[MAX_VOUT_DEV];
+
+       int num_displays;
+       struct omap_dss_device *displays[MAX_DISPLAYS];
+       int num_overlays;
+       struct omap_overlay *overlays[MAX_OVLS];
+       int num_managers;
+       struct omap_overlay_manager *managers[MAX_MANAGERS];
+};
+
+/* per-device data structure */
+struct omap_vout_device {
+
+       struct omapvideo_info vid_info;
+       struct video_device *vfd;
+       struct omap2video_device *vid_dev;
+       int vid;
+       int opened;
+
+       /* we don't allow to change image fmt/size once buffer has
+        * been allocated
+        */
+       int buffer_allocated;
+       /* allow to reuse previously allocated buffer which is big enough */
+       int buffer_size;
+       /* keep buffer info across opens */
+       unsigned long buf_virt_addr[VIDEO_MAX_FRAME];
+       unsigned long buf_phy_addr[VIDEO_MAX_FRAME];
+       enum omap_color_mode dss_mode;
+
+       /* we don't allow to request new buffer when old buffers are
+        * still mmaped
+        */
+       int mmap_count;
+
+       spinlock_t vbq_lock;            /* spinlock for videobuf queues */
+       unsigned long field_count;      /* field counter for videobuf_buffer */
+
+       /* non-NULL means streaming is in progress. */
+       bool streaming;
+
+       struct v4l2_pix_format pix;
+       struct v4l2_rect crop;
+       struct v4l2_window win;
+       struct v4l2_framebuffer fbuf;
+
+       /* Lock to protect the shared data structures in ioctl */
+       struct mutex lock;
+
+       /* V4L2 control structure for different control id */
+       struct v4l2_control control[MAX_CID];
+       enum dss_rotation rotation;
+       bool mirror;
+       int flicker_filter;
+       /* V4L2 control structure for different control id */
+
+       int bpp; /* bytes per pixel */
+       int vrfb_bpp; /* bytes per pixel with respect to VRFB */
+
+       struct vid_vrfb_dma vrfb_dma_tx;
+       unsigned int smsshado_phy_addr[MAC_VRFB_CTXS];
+       unsigned int smsshado_virt_addr[MAC_VRFB_CTXS];
+       struct vrfb vrfb_context[MAC_VRFB_CTXS];
+       bool vrfb_static_allocation;
+       unsigned int smsshado_size;
+       unsigned char pos;
+
+       int ps, vr_ps, line_length, first_int, field_id;
+       enum v4l2_memory memory;
+       struct videobuf_buffer *cur_frm, *next_frm;
+       struct list_head dma_queue;
+       u8 *queued_buf_addr[VIDEO_MAX_FRAME];
+       u32 cropped_offset;
+       s32 tv_field1_offset;
+       void *isr_handle;
+
+       /* Buffer queue variables */
+       struct omap_vout_device *vout;
+       enum v4l2_buf_type type;
+       struct videobuf_queue vbq;
+       int io_allowed;
+
+};
+#endif /* ifndef OMAP_VOUTDEF_H */
diff --git a/drivers/media/video/omap/omap_voutlib.c b/drivers/media/video/omap/omap_voutlib.c
new file mode 100644 (file)
index 0000000..b941c76
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ * omap_voutlib.c
+ *
+ * Copyright (C) 2005-2010 Texas Instruments.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ * Based on the OMAP2 camera driver
+ * Video-for-Linux (Version 2) camera capture driver for
+ * the OMAP24xx camera controller.
+ *
+ * Author: Andy Lowe (source@mvista.com)
+ *
+ * Copyright (C) 2004 MontaVista Software, Inc.
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/videodev2.h>
+
+#include <plat/cpu.h>
+
+MODULE_AUTHOR("Texas Instruments");
+MODULE_DESCRIPTION("OMAP Video library");
+MODULE_LICENSE("GPL");
+
+/* Return the default overlay cropping rectangle in crop given the image
+ * size in pix and the video display size in fbuf.  The default
+ * cropping rectangle is the largest rectangle no larger than the capture size
+ * that will fit on the display.  The default cropping rectangle is centered in
+ * the image.  All dimensions and offsets are rounded down to even numbers.
+ */
+void omap_vout_default_crop(struct v4l2_pix_format *pix,
+                 struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop)
+{
+       crop->width = (pix->width < fbuf->fmt.width) ?
+               pix->width : fbuf->fmt.width;
+       crop->height = (pix->height < fbuf->fmt.height) ?
+               pix->height : fbuf->fmt.height;
+       crop->width &= ~1;
+       crop->height &= ~1;
+       crop->left = ((pix->width - crop->width) >> 1) & ~1;
+       crop->top = ((pix->height - crop->height) >> 1) & ~1;
+}
+EXPORT_SYMBOL_GPL(omap_vout_default_crop);
+
+/* Given a new render window in new_win, adjust the window to the
+ * nearest supported configuration.  The adjusted window parameters are
+ * returned in new_win.
+ * Returns zero if succesful, or -EINVAL if the requested window is
+ * impossible and cannot reasonably be adjusted.
+ */
+int omap_vout_try_window(struct v4l2_framebuffer *fbuf,
+                       struct v4l2_window *new_win)
+{
+       struct v4l2_rect try_win;
+
+       /* make a working copy of the new_win rectangle */
+       try_win = new_win->w;
+
+       /* adjust the preview window so it fits on the display by clipping any
+        * offscreen areas
+        */
+       if (try_win.left < 0) {
+               try_win.width += try_win.left;
+               try_win.left = 0;
+       }
+       if (try_win.top < 0) {
+               try_win.height += try_win.top;
+               try_win.top = 0;
+       }
+       try_win.width = (try_win.width < fbuf->fmt.width) ?
+               try_win.width : fbuf->fmt.width;
+       try_win.height = (try_win.height < fbuf->fmt.height) ?
+               try_win.height : fbuf->fmt.height;
+       if (try_win.left + try_win.width > fbuf->fmt.width)
+               try_win.width = fbuf->fmt.width - try_win.left;
+       if (try_win.top + try_win.height > fbuf->fmt.height)
+               try_win.height = fbuf->fmt.height - try_win.top;
+       try_win.width &= ~1;
+       try_win.height &= ~1;
+
+       if (try_win.width <= 0 || try_win.height <= 0)
+               return -EINVAL;
+
+       /* We now have a valid preview window, so go with it */
+       new_win->w = try_win;
+       new_win->field = V4L2_FIELD_ANY;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(omap_vout_try_window);
+
+/* Given a new render window in new_win, adjust the window to the
+ * nearest supported configuration.  The image cropping window in crop
+ * will also be adjusted if necessary.  Preference is given to keeping the
+ * the window as close to the requested configuration as possible.  If
+ * successful, new_win, vout->win, and crop are updated.
+ * Returns zero if succesful, or -EINVAL if the requested preview window is
+ * impossible and cannot reasonably be adjusted.
+ */
+int omap_vout_new_window(struct v4l2_rect *crop,
+               struct v4l2_window *win, struct v4l2_framebuffer *fbuf,
+               struct v4l2_window *new_win)
+{
+       int err;
+
+       err = omap_vout_try_window(fbuf, new_win);
+       if (err)
+               return err;
+
+       /* update our preview window */
+       win->w = new_win->w;
+       win->field = new_win->field;
+       win->chromakey = new_win->chromakey;
+
+       /* Adjust the cropping window to allow for resizing limitation */
+       if (cpu_is_omap24xx()) {
+               /* For 24xx limit is 8x to 1/2x scaling. */
+               if ((crop->height/win->w.height) >= 2)
+                       crop->height = win->w.height * 2;
+
+               if ((crop->width/win->w.width) >= 2)
+                       crop->width = win->w.width * 2;
+
+               if (crop->width > 768) {
+                       /* The OMAP2420 vertical resizing line buffer is 768
+                        * pixels wide. If the cropped image is wider than
+                        * 768 pixels then it cannot be vertically resized.
+                        */
+                       if (crop->height != win->w.height)
+                               crop->width = 768;
+               }
+       } else if (cpu_is_omap34xx()) {
+               /* For 34xx limit is 8x to 1/4x scaling. */
+               if ((crop->height/win->w.height) >= 4)
+                       crop->height = win->w.height * 4;
+
+               if ((crop->width/win->w.width) >= 4)
+                       crop->width = win->w.width * 4;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(omap_vout_new_window);
+
+/* Given a new cropping rectangle in new_crop, adjust the cropping rectangle to
+ * the nearest supported configuration.  The image render window in win will
+ * also be adjusted if necessary.  The preview window is adjusted such that the
+ * horizontal and vertical rescaling ratios stay constant.  If the render
+ * window would fall outside the display boundaries, the cropping rectangle
+ * will also be adjusted to maintain the rescaling ratios.  If successful, crop
+ * and win are updated.
+ * Returns zero if succesful, or -EINVAL if the requested cropping rectangle is
+ * impossible and cannot reasonably be adjusted.
+ */
+int omap_vout_new_crop(struct v4l2_pix_format *pix,
+             struct v4l2_rect *crop, struct v4l2_window *win,
+             struct v4l2_framebuffer *fbuf, const struct v4l2_rect *new_crop)
+{
+       struct v4l2_rect try_crop;
+       unsigned long vresize, hresize;
+
+       /* make a working copy of the new_crop rectangle */
+       try_crop = *new_crop;
+
+       /* adjust the cropping rectangle so it fits in the image */
+       if (try_crop.left < 0) {
+               try_crop.width += try_crop.left;
+               try_crop.left = 0;
+       }
+       if (try_crop.top < 0) {
+               try_crop.height += try_crop.top;
+               try_crop.top = 0;
+       }
+       try_crop.width = (try_crop.width < pix->width) ?
+               try_crop.width : pix->width;
+       try_crop.height = (try_crop.height < pix->height) ?
+               try_crop.height : pix->height;
+       if (try_crop.left + try_crop.width > pix->width)
+               try_crop.width = pix->width - try_crop.left;
+       if (try_crop.top + try_crop.height > pix->height)
+               try_crop.height = pix->height - try_crop.top;
+
+       try_crop.width &= ~1;
+       try_crop.height &= ~1;
+
+       if (try_crop.width <= 0 || try_crop.height <= 0)
+               return -EINVAL;
+
+       if (cpu_is_omap24xx()) {
+               if (crop->height != win->w.height) {
+                       /* If we're resizing vertically, we can't support a
+                        * crop width wider than 768 pixels.
+                        */
+                       if (try_crop.width > 768)
+                               try_crop.width = 768;
+               }
+       }
+       /* vertical resizing */
+       vresize = (1024 * crop->height) / win->w.height;
+       if (cpu_is_omap24xx() && (vresize > 2048))
+               vresize = 2048;
+       else if (cpu_is_omap34xx() && (vresize > 4096))
+               vresize = 4096;
+
+       win->w.height = ((1024 * try_crop.height) / vresize) & ~1;
+       if (win->w.height == 0)
+               win->w.height = 2;
+       if (win->w.height + win->w.top > fbuf->fmt.height) {
+               /* We made the preview window extend below the bottom of the
+                * display, so clip it to the display boundary and resize the
+                * cropping height to maintain the vertical resizing ratio.
+                */
+               win->w.height = (fbuf->fmt.height - win->w.top) & ~1;
+               if (try_crop.height == 0)
+                       try_crop.height = 2;
+       }
+       /* horizontal resizing */
+       hresize = (1024 * crop->width) / win->w.width;
+       if (cpu_is_omap24xx() && (hresize > 2048))
+               hresize = 2048;
+       else if (cpu_is_omap34xx() && (hresize > 4096))
+               hresize = 4096;
+
+       win->w.width = ((1024 * try_crop.width) / hresize) & ~1;
+       if (win->w.width == 0)
+               win->w.width = 2;
+       if (win->w.width + win->w.left > fbuf->fmt.width) {
+               /* We made the preview window extend past the right side of the
+                * display, so clip it to the display boundary and resize the
+                * cropping width to maintain the horizontal resizing ratio.
+                */
+               win->w.width = (fbuf->fmt.width - win->w.left) & ~1;
+               if (try_crop.width == 0)
+                       try_crop.width = 2;
+       }
+       if (cpu_is_omap24xx()) {
+               if ((try_crop.height/win->w.height) >= 2)
+                       try_crop.height = win->w.height * 2;
+
+               if ((try_crop.width/win->w.width) >= 2)
+                       try_crop.width = win->w.width * 2;
+
+               if (try_crop.width > 768) {
+                       /* The OMAP2420 vertical resizing line buffer is
+                        * 768 pixels wide.  If the cropped image is wider
+                        * than 768 pixels then it cannot be vertically resized.
+                        */
+                       if (try_crop.height != win->w.height)
+                               try_crop.width = 768;
+               }
+       } else if (cpu_is_omap34xx()) {
+               if ((try_crop.height/win->w.height) >= 4)
+                       try_crop.height = win->w.height * 4;
+
+               if ((try_crop.width/win->w.width) >= 4)
+                       try_crop.width = win->w.width * 4;
+       }
+       /* update our cropping rectangle and we're done */
+       *crop = try_crop;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(omap_vout_new_crop);
+
+/* Given a new format in pix and fbuf,  crop and win
+ * structures are initialized to default values. crop
+ * is initialized to the largest window size that will fit on the display.  The
+ * crop window is centered in the image. win is initialized to
+ * the same size as crop and is centered on the display.
+ * All sizes and offsets are constrained to be even numbers.
+ */
+void omap_vout_new_format(struct v4l2_pix_format *pix,
+               struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop,
+               struct v4l2_window *win)
+{
+       /* crop defines the preview source window in the image capture
+        * buffer
+        */
+       omap_vout_default_crop(pix, fbuf, crop);
+
+       /* win defines the preview target window on the display */
+       win->w.width = crop->width;
+       win->w.height = crop->height;
+       win->w.left = ((fbuf->fmt.width - win->w.width) >> 1) & ~1;
+       win->w.top = ((fbuf->fmt.height - win->w.height) >> 1) & ~1;
+}
+EXPORT_SYMBOL_GPL(omap_vout_new_format);
+
diff --git a/drivers/media/video/omap/omap_voutlib.h b/drivers/media/video/omap/omap_voutlib.h
new file mode 100644 (file)
index 0000000..a60b16e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * omap_voutlib.h
+ *
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+
+#ifndef OMAP_VOUTLIB_H
+#define OMAP_VOUTLIB_H
+
+extern void omap_vout_default_crop(struct v4l2_pix_format *pix,
+               struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop);
+
+extern int omap_vout_new_crop(struct v4l2_pix_format *pix,
+               struct v4l2_rect *crop, struct v4l2_window *win,
+               struct v4l2_framebuffer *fbuf,
+               const struct v4l2_rect *new_crop);
+
+extern int omap_vout_try_window(struct v4l2_framebuffer *fbuf,
+               struct v4l2_window *new_win);
+
+extern int omap_vout_new_window(struct v4l2_rect *crop,
+               struct v4l2_window *win, struct v4l2_framebuffer *fbuf,
+               struct v4l2_window *new_win);
+
+extern void omap_vout_new_format(struct v4l2_pix_format *pix,
+               struct v4l2_framebuffer *fbuf, struct v4l2_rect *crop,
+               struct v4l2_window *win);
+#endif /* #ifndef OMAP_VOUTLIB_H */
+
index ce76d95..f85b2ed 100644 (file)
@@ -452,8 +452,8 @@ static int omap24xxcam_vbq_setup(struct videobuf_queue *vbq, unsigned int *cnt,
        *size = fh->pix.sizeimage;
 
        /* accessing fh->cam->capture_mem is ok, it's constant */
-       while (*size * *cnt > fh->cam->capture_mem)
-               (*cnt)--;
+       if (*size * *cnt > fh->cam->capture_mem)
+               *cnt = fh->cam->capture_mem / *size;
 
        return 0;
 }
index e0bce8d..a109120 100644 (file)
@@ -57,8 +57,8 @@
 #define DRIVER_VERSION "v1.64 for Linux 2.5"
 #define EMAIL "mark@alpha.dyndns.org"
 #define DRIVER_AUTHOR "Mark McClelland <mark@alpha.dyndns.org> & Bret Wallach \
-       & Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha \
-       <cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>"
+& Orion Sky Lawlor <olawlor@acm.org> & Kevin Moore & Charl P. Botha \
+<cpbotha@ieee.org> & Claudio Matsuoka <claudio@conectiva.com>"
 #define DRIVER_DESC "ov511 USB Camera Driver"
 
 #define OV511_I2C_RETRIES 3
@@ -5916,11 +5916,6 @@ ov51x_disconnect(struct usb_interface *intf)
        mutex_lock(&ov->lock);
        usb_set_intfdata (intf, NULL);
 
-       if (!ov) {
-               mutex_unlock(&ov->lock);
-               return;
-       }
-
        /* Free device number */
        ov511_devused &= ~(1 << ov->nr);
 
@@ -5945,7 +5940,7 @@ ov51x_disconnect(struct usb_interface *intf)
        ov->dev = NULL;
 
        /* Free the memory */
-       if (ov && !ov->user) {
+       if (!ov->user) {
                mutex_lock(&ov->cbuf_lock);
                kfree(ov->cbuf);
                ov->cbuf = NULL;
index aaa50f9..91c886a 100644 (file)
@@ -198,6 +198,7 @@ struct ov7670_info {
        struct ov7670_format_struct *fmt;  /* Current format */
        unsigned char sat;              /* Saturation value */
        int hue;                        /* Hue value */
+       u8 clkrc;                       /* Clock divider value */
 };
 
 static inline struct ov7670_info *to_state(struct v4l2_subdev *sd)
@@ -351,7 +352,7 @@ static struct regval_list ov7670_default_regs[] = {
 static struct regval_list ov7670_fmt_yuv422[] = {
        { REG_COM7, 0x0 },  /* Selects YUV mode */
        { REG_RGB444, 0 },      /* No RGB444 please */
-       { REG_COM1, 0 },
+       { REG_COM1, 0 },        /* CCIR601 */
        { REG_COM15, COM15_R00FF },
        { REG_COM9, 0x18 }, /* 4x gain ceiling; 0x8 is reserved bit */
        { 0x4f, 0x80 },         /* "matrix coefficient 1" */
@@ -367,7 +368,7 @@ static struct regval_list ov7670_fmt_yuv422[] = {
 static struct regval_list ov7670_fmt_rgb565[] = {
        { REG_COM7, COM7_RGB }, /* Selects RGB mode */
        { REG_RGB444, 0 },      /* No RGB444 please */
-       { REG_COM1, 0x0 },
+       { REG_COM1, 0x0 },      /* CCIR601 */
        { REG_COM15, COM15_RGB565 },
        { REG_COM9, 0x38 },     /* 16x gain ceiling; 0x8 is reserved bit */
        { 0x4f, 0xb3 },         /* "matrix coefficient 1" */
@@ -383,7 +384,7 @@ static struct regval_list ov7670_fmt_rgb565[] = {
 static struct regval_list ov7670_fmt_rgb444[] = {
        { REG_COM7, COM7_RGB }, /* Selects RGB mode */
        { REG_RGB444, R444_ENABLE },    /* Enable xxxxrrrr ggggbbbb */
-       { REG_COM1, 0x40 },     /* Magic reserved bit */
+       { REG_COM1, 0x0 },      /* CCIR601 */
        { REG_COM15, COM15_R01FE|COM15_RGB565 }, /* Data range needed? */
        { REG_COM9, 0x38 },     /* 16x gain ceiling; 0x8 is reserved bit */
        { 0x4f, 0xb3 },         /* "matrix coefficient 1" */
@@ -408,8 +409,13 @@ static struct regval_list ov7670_fmt_raw[] = {
 
 /*
  * Low-level register I/O.
+ *
+ * Note that there are two versions of these.  On the XO 1, the
+ * i2c controller only does SMBUS, so that's what we use.  The
+ * ov7670 is not really an SMBUS device, though, so the communication
+ * is not always entirely reliable.
  */
-
+#ifdef CONFIG_OLPC_XO_1
 static int ov7670_read(struct v4l2_subdev *sd, unsigned char reg,
                unsigned char *value)
 {
@@ -432,9 +438,67 @@ static int ov7670_write(struct v4l2_subdev *sd, unsigned char reg,
        int ret = i2c_smbus_write_byte_data(client, reg, value);
 
        if (reg == REG_COM7 && (value & COM7_RESET))
-               msleep(2);  /* Wait for reset to run */
+               msleep(5);  /* Wait for reset to run */
+       return ret;
+}
+
+#else /* ! CONFIG_OLPC_XO_1 */
+/*
+ * On most platforms, we'd rather do straight i2c I/O.
+ */
+static int ov7670_read(struct v4l2_subdev *sd, unsigned char reg,
+               unsigned char *value)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       u8 data = reg;
+       struct i2c_msg msg;
+       int ret;
+
+       /*
+        * Send out the register address...
+        */
+       msg.addr = client->addr;
+       msg.flags = 0;
+       msg.len = 1;
+       msg.buf = &data;
+       ret = i2c_transfer(client->adapter, &msg, 1);
+       if (ret < 0) {
+               printk(KERN_ERR "Error %d on register write\n", ret);
+               return ret;
+       }
+       /*
+        * ...then read back the result.
+        */
+       msg.flags = I2C_M_RD;
+       ret = i2c_transfer(client->adapter, &msg, 1);
+       if (ret >= 0) {
+               *value = data;
+               ret = 0;
+       }
+       return ret;
+}
+
+
+static int ov7670_write(struct v4l2_subdev *sd, unsigned char reg,
+               unsigned char value)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct i2c_msg msg;
+       unsigned char data[2] = { reg, value };
+       int ret;
+
+       msg.addr = client->addr;
+       msg.flags = 0;
+       msg.len = 2;
+       msg.buf = data;
+       ret = i2c_transfer(client->adapter, &msg, 1);
+       if (ret > 0)
+               ret = 0;
+       if (reg == REG_COM7 && (value & COM7_RESET))
+               msleep(5);  /* Wait for reset to run */
        return ret;
 }
+#endif /* CONFIG_OLPC_XO_1 */
 
 
 /*
@@ -744,21 +808,11 @@ static int ov7670_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        struct ov7670_format_struct *ovfmt;
        struct ov7670_win_size *wsize;
        struct ov7670_info *info = to_state(sd);
-       unsigned char com7, clkrc = 0;
+       unsigned char com7;
 
        ret = ov7670_try_fmt_internal(sd, fmt, &ovfmt, &wsize);
        if (ret)
                return ret;
-       /*
-        * HACK: if we're running rgb565 we need to grab then rewrite
-        * CLKRC.  If we're *not*, however, then rewriting clkrc hoses
-        * the colors.
-        */
-       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) {
-               ret = ov7670_read(sd, REG_CLKRC, &clkrc);
-               if (ret)
-                       return ret;
-       }
        /*
         * COM7 is a pain in the ass, it doesn't like to be read then
         * quickly written afterward.  But we have everything we need
@@ -779,8 +833,18 @@ static int ov7670_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
                ret = ov7670_write_array(sd, wsize->regs);
        info->fmt = ovfmt;
 
-       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0)
-               ret = ov7670_write(sd, REG_CLKRC, clkrc);
+       /*
+        * If we're running RGB565, we must rewrite clkrc after setting
+        * the other parameters or the image looks poor.  If we're *not*
+        * doing RGB565, we must not rewrite clkrc or the image looks
+        * *really* poor.
+        *
+        * (Update) Now that we retain clkrc state, we should be able
+        * to write it unconditionally, and that will make the frame
+        * rate persistent too.
+        */
+       if (ret == 0)
+               ret = ov7670_write(sd, REG_CLKRC, info->clkrc);
        return ret;
 }
 
@@ -791,20 +855,17 @@ static int ov7670_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
 static int ov7670_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
 {
        struct v4l2_captureparm *cp = &parms->parm.capture;
-       unsigned char clkrc;
-       int ret;
+       struct ov7670_info *info = to_state(sd);
 
        if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
-       ret = ov7670_read(sd, REG_CLKRC, &clkrc);
-       if (ret < 0)
-               return ret;
+
        memset(cp, 0, sizeof(struct v4l2_captureparm));
        cp->capability = V4L2_CAP_TIMEPERFRAME;
        cp->timeperframe.numerator = 1;
        cp->timeperframe.denominator = OV7670_FRAME_RATE;
-       if ((clkrc & CLK_EXT) == 0 && (clkrc & CLK_SCALE) > 1)
-               cp->timeperframe.denominator /= (clkrc & CLK_SCALE);
+       if ((info->clkrc & CLK_EXT) == 0 && (info->clkrc & CLK_SCALE) > 1)
+               cp->timeperframe.denominator /= (info->clkrc & CLK_SCALE);
        return 0;
 }
 
@@ -812,19 +873,14 @@ static int ov7670_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
 {
        struct v4l2_captureparm *cp = &parms->parm.capture;
        struct v4l2_fract *tpf = &cp->timeperframe;
-       unsigned char clkrc;
-       int ret, div;
+       struct ov7670_info *info = to_state(sd);
+       int div;
 
        if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
        if (cp->extendedmode != 0)
                return -EINVAL;
-       /*
-        * CLKRC has a reserved bit, so let's preserve it.
-        */
-       ret = ov7670_read(sd, REG_CLKRC, &clkrc);
-       if (ret < 0)
-               return ret;
+
        if (tpf->numerator == 0 || tpf->denominator == 0)
                div = 1;  /* Reset to full rate */
        else
@@ -833,10 +889,10 @@ static int ov7670_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms)
                div = 1;
        else if (div > CLK_SCALE)
                div = CLK_SCALE;
-       clkrc = (clkrc & 0x80) | div;
+       info->clkrc = (info->clkrc & 0x80) | div;
        tpf->numerator = 1;
        tpf->denominator = OV7670_FRAME_RATE/div;
-       return ov7670_write(sd, REG_CLKRC, clkrc);
+       return ov7670_write(sd, REG_CLKRC, info->clkrc);
 }
 
 
@@ -1115,6 +1171,140 @@ static int ov7670_s_vflip(struct v4l2_subdev *sd, int value)
        return ret;
 }
 
+/*
+ * GAIN is split between REG_GAIN and REG_VREF[7:6].  If one believes
+ * the data sheet, the VREF parts should be the most significant, but
+ * experience shows otherwise.  There seems to be little value in
+ * messing with the VREF bits, so we leave them alone.
+ */
+static int ov7670_g_gain(struct v4l2_subdev *sd, __s32 *value)
+{
+       int ret;
+       unsigned char gain;
+
+       ret = ov7670_read(sd, REG_GAIN, &gain);
+       *value = gain;
+       return ret;
+}
+
+static int ov7670_s_gain(struct v4l2_subdev *sd, int value)
+{
+       int ret;
+       unsigned char com8;
+
+       ret = ov7670_write(sd, REG_GAIN, value & 0xff);
+       /* Have to turn off AGC as well */
+       if (ret == 0) {
+               ret = ov7670_read(sd, REG_COM8, &com8);
+               ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AGC);
+       }
+       return ret;
+}
+
+/*
+ * Tweak autogain.
+ */
+static int ov7670_g_autogain(struct v4l2_subdev *sd, __s32 *value)
+{
+       int ret;
+       unsigned char com8;
+
+       ret = ov7670_read(sd, REG_COM8, &com8);
+       *value = (com8 & COM8_AGC) != 0;
+       return ret;
+}
+
+static int ov7670_s_autogain(struct v4l2_subdev *sd, int value)
+{
+       int ret;
+       unsigned char com8;
+
+       ret = ov7670_read(sd, REG_COM8, &com8);
+       if (ret == 0) {
+               if (value)
+                       com8 |= COM8_AGC;
+               else
+                       com8 &= ~COM8_AGC;
+               ret = ov7670_write(sd, REG_COM8, com8);
+       }
+       return ret;
+}
+
+/*
+ * Exposure is spread all over the place: top 6 bits in AECHH, middle
+ * 8 in AECH, and two stashed in COM1 just for the hell of it.
+ */
+static int ov7670_g_exp(struct v4l2_subdev *sd, __s32 *value)
+{
+       int ret;
+       unsigned char com1, aech, aechh;
+
+       ret = ov7670_read(sd, REG_COM1, &com1) +
+               ov7670_read(sd, REG_AECH, &aech) +
+               ov7670_read(sd, REG_AECHH, &aechh);
+       *value = ((aechh & 0x3f) << 10) | (aech << 2) | (com1 & 0x03);
+       return ret;
+}
+
+static int ov7670_s_exp(struct v4l2_subdev *sd, int value)
+{
+       int ret;
+       unsigned char com1, com8, aech, aechh;
+
+       ret = ov7670_read(sd, REG_COM1, &com1) +
+               ov7670_read(sd, REG_COM8, &com8);
+               ov7670_read(sd, REG_AECHH, &aechh);
+       if (ret)
+               return ret;
+
+       com1 = (com1 & 0xfc) | (value & 0x03);
+       aech = (value >> 2) & 0xff;
+       aechh = (aechh & 0xc0) | ((value >> 10) & 0x3f);
+       ret = ov7670_write(sd, REG_COM1, com1) +
+               ov7670_write(sd, REG_AECH, aech) +
+               ov7670_write(sd, REG_AECHH, aechh);
+       /* Have to turn off AEC as well */
+       if (ret == 0)
+               ret = ov7670_write(sd, REG_COM8, com8 & ~COM8_AEC);
+       return ret;
+}
+
+/*
+ * Tweak autoexposure.
+ */
+static int ov7670_g_autoexp(struct v4l2_subdev *sd, __s32 *value)
+{
+       int ret;
+       unsigned char com8;
+       enum v4l2_exposure_auto_type *atype = (enum v4l2_exposure_auto_type *) value;
+
+       ret = ov7670_read(sd, REG_COM8, &com8);
+       if (com8 & COM8_AEC)
+               *atype = V4L2_EXPOSURE_AUTO;
+       else
+               *atype = V4L2_EXPOSURE_MANUAL;
+       return ret;
+}
+
+static int ov7670_s_autoexp(struct v4l2_subdev *sd,
+               enum v4l2_exposure_auto_type value)
+{
+       int ret;
+       unsigned char com8;
+
+       ret = ov7670_read(sd, REG_COM8, &com8);
+       if (ret == 0) {
+               if (value == V4L2_EXPOSURE_AUTO)
+                       com8 |= COM8_AEC;
+               else
+                       com8 &= ~COM8_AEC;
+               ret = ov7670_write(sd, REG_COM8, com8);
+       }
+       return ret;
+}
+
+
+
 static int ov7670_queryctrl(struct v4l2_subdev *sd,
                struct v4l2_queryctrl *qc)
 {
@@ -1131,6 +1321,14 @@ static int ov7670_queryctrl(struct v4l2_subdev *sd,
                return v4l2_ctrl_query_fill(qc, 0, 256, 1, 128);
        case V4L2_CID_HUE:
                return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0);
+       case V4L2_CID_GAIN:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
+       case V4L2_CID_AUTOGAIN:
+               return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
+       case V4L2_CID_EXPOSURE:
+               return v4l2_ctrl_query_fill(qc, 0, 65535, 1, 500);
+       case V4L2_CID_EXPOSURE_AUTO:
+               return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0);
        }
        return -EINVAL;
 }
@@ -1150,6 +1348,14 @@ static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
                return ov7670_g_vflip(sd, &ctrl->value);
        case V4L2_CID_HFLIP:
                return ov7670_g_hflip(sd, &ctrl->value);
+       case V4L2_CID_GAIN:
+               return ov7670_g_gain(sd, &ctrl->value);
+       case V4L2_CID_AUTOGAIN:
+               return ov7670_g_autogain(sd, &ctrl->value);
+       case V4L2_CID_EXPOSURE:
+               return ov7670_g_exp(sd, &ctrl->value);
+       case V4L2_CID_EXPOSURE_AUTO:
+               return ov7670_g_autoexp(sd, &ctrl->value);
        }
        return -EINVAL;
 }
@@ -1169,6 +1375,15 @@ static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
                return ov7670_s_vflip(sd, ctrl->value);
        case V4L2_CID_HFLIP:
                return ov7670_s_hflip(sd, ctrl->value);
+       case V4L2_CID_GAIN:
+               return ov7670_s_gain(sd, ctrl->value);
+       case V4L2_CID_AUTOGAIN:
+               return ov7670_s_autogain(sd, ctrl->value);
+       case V4L2_CID_EXPOSURE:
+               return ov7670_s_exp(sd, ctrl->value);
+       case V4L2_CID_EXPOSURE_AUTO:
+               return ov7670_s_autoexp(sd,
+                               (enum v4l2_exposure_auto_type) ctrl->value);
        }
        return -EINVAL;
 }
@@ -1268,6 +1483,7 @@ static int ov7670_probe(struct i2c_client *client,
 
        info->fmt = &ov7670_formats[0];
        info->sat = 128;        /* Review this */
+       info->clkrc = 1;        /* 30fps */
 
        return 0;
 }
index 47bf60c..36599a6 100644 (file)
@@ -59,9 +59,9 @@ static const struct ov9640_reg ov9640_regs_dflt[] = {
  *             COM12 |= OV9640_COM12_YUV_AVG
  *
  *      for RGB, alter the following registers:
- *             COM7  |= OV9640_COM7_RGB
- *             COM13 |= OV9640_COM13_RGB_AVG
- *             COM15 |= proper RGB color encoding mode
+ *             COM7  |= OV9640_COM7_RGB
+ *             COM13 |= OV9640_COM13_RGB_AVG
+ *             COM15 |= proper RGB color encoding mode
  */
 static const struct ov9640_reg ov9640_regs_qqcif[] = {
        { OV9640_CLKRC, OV9640_CLKRC_DPLL_EN | OV9640_CLKRC_DIV(0x0f) },
index 0598bbd..7129b50 100644 (file)
@@ -61,7 +61,6 @@ struct pms {
        int depth;
        int input;
        s32 brightness, saturation, hue, contrast;
-       unsigned long in_use;
        struct mutex lock;
        int i2c_count;
        struct i2c_info i2cinfo[64];
@@ -931,25 +930,8 @@ static ssize_t pms_read(struct file *file, char __user *buf,
        return len;
 }
 
-static int pms_exclusive_open(struct file *file)
-{
-       struct pms *dev = video_drvdata(file);
-
-       return test_and_set_bit(0, &dev->in_use) ? -EBUSY : 0;
-}
-
-static int pms_exclusive_release(struct file *file)
-{
-       struct pms *dev = video_drvdata(file);
-
-       clear_bit(0, &dev->in_use);
-       return 0;
-}
-
 static const struct v4l2_file_operations pms_fops = {
        .owner          = THIS_MODULE,
-       .open           = pms_exclusive_open,
-       .release        = pms_exclusive_release,
        .ioctl          = video_ioctl2,
        .read           = pms_read,
 };
index 712b300..301ef19 100644 (file)
@@ -2028,7 +2028,7 @@ static void pvr2_hdw_cx25840_vbi_hack(struct pvr2_hdw *hdw)
        memset(&fmt, 0, sizeof(fmt));
        fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
        v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id,
-                            video, s_fmt, &fmt);
+                            vbi, s_sliced_fmt, &fmt.fmt.sliced);
 }
 
 
index bf1e0fe..5ffa0d2 100644 (file)
@@ -49,7 +49,7 @@ struct pvr2_v4l2_dev {
 
 struct pvr2_v4l2_fh {
        struct pvr2_channel channel;
-       struct pvr2_v4l2_dev *dev_info;
+       struct pvr2_v4l2_dev *pdi;
        enum v4l2_priority prio;
        struct pvr2_ioread *rhp;
        struct file *file;
@@ -162,7 +162,7 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 {
        struct pvr2_v4l2_fh *fh = file->private_data;
        struct pvr2_v4l2 *vp = fh->vhead;
-       struct pvr2_v4l2_dev *dev_info = fh->dev_info;
+       struct pvr2_v4l2_dev *pdi = fh->pdi;
        struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
        long ret = -EINVAL;
 
@@ -183,7 +183,7 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
        case VIDIOC_S_INPUT:
        case VIDIOC_S_TUNER:
        case VIDIOC_S_FREQUENCY:
-               ret = v4l2_prio_check(&vp->prio, &fh->prio);
+               ret = v4l2_prio_check(&vp->prio, fh->prio);
                if (ret)
                        return ret;
        }
@@ -564,14 +564,14 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
        case VIDIOC_STREAMON:
        {
-               if (!fh->dev_info->stream) {
+               if (!fh->pdi->stream) {
                        /* No stream defined for this node.  This means
                           that we're not currently allowed to stream from
                           this node. */
                        ret = -EPERM;
                        break;
                }
-               ret = pvr2_hdw_set_stream_type(hdw,dev_info->config);
+               ret = pvr2_hdw_set_stream_type(hdw,pdi->config);
                if (ret < 0) return ret;
                ret = pvr2_hdw_set_streaming(hdw,!0);
                break;
@@ -579,7 +579,7 @@ static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 
        case VIDIOC_STREAMOFF:
        {
-               if (!fh->dev_info->stream) {
+               if (!fh->pdi->stream) {
                        /* No stream defined for this node.  This means
                           that we're not currently allowed to stream from
                           this node. */
@@ -972,7 +972,7 @@ static int pvr2_v4l2_release(struct file *file)
                fhp->rhp = NULL;
        }
 
-       v4l2_prio_close(&vp->prio, &fhp->prio);
+       v4l2_prio_close(&vp->prio, fhp->prio);
        file->private_data = NULL;
 
        if (fhp->vnext) {
@@ -1032,7 +1032,7 @@ static int pvr2_v4l2_open(struct file *file)
        }
 
        init_waitqueue_head(&fhp->wait_data);
-       fhp->dev_info = dip;
+       fhp->pdi = dip;
 
        pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
        pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
@@ -1093,7 +1093,7 @@ static int pvr2_v4l2_open(struct file *file)
 
        fhp->file = file;
        file->private_data = fhp;
-       v4l2_prio_open(&vp->prio,&fhp->prio);
+       v4l2_prio_open(&vp->prio, &fhp->prio);
 
        fhp->fw_mode_flag = pvr2_hdw_cpufw_get_enabled(hdw);
 
@@ -1113,7 +1113,7 @@ static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
        struct pvr2_hdw *hdw;
        if (fh->rhp) return 0;
 
-       if (!fh->dev_info->stream) {
+       if (!fh->pdi->stream) {
                /* No stream defined for this node.  This means that we're
                   not currently allowed to stream from this node. */
                return -EPERM;
@@ -1122,21 +1122,21 @@ static int pvr2_v4l2_iosetup(struct pvr2_v4l2_fh *fh)
        /* First read() attempt.  Try to claim the stream and start
           it... */
        if ((ret = pvr2_channel_claim_stream(&fh->channel,
-                                            fh->dev_info->stream)) != 0) {
+                                            fh->pdi->stream)) != 0) {
                /* Someone else must already have it */
                return ret;
        }
 
-       fh->rhp = pvr2_channel_create_mpeg_stream(fh->dev_info->stream);
+       fh->rhp = pvr2_channel_create_mpeg_stream(fh->pdi->stream);
        if (!fh->rhp) {
                pvr2_channel_claim_stream(&fh->channel,NULL);
                return -ENOMEM;
        }
 
        hdw = fh->channel.mc_head->hdw;
-       sp = fh->dev_info->stream->stream;
+       sp = fh->pdi->stream->stream;
        pvr2_stream_set_callback(sp,(pvr2_stream_callback)pvr2_v4l2_notify,fh);
-       pvr2_hdw_set_stream_type(hdw,fh->dev_info->config);
+       pvr2_hdw_set_stream_type(hdw,fh->pdi->config);
        if ((ret = pvr2_hdw_set_streaming(hdw,!0)) < 0) return ret;
        return pvr2_ioread_set_enabled(fh->rhp,!0);
 }
index 340f954..11980db 100644 (file)
@@ -39,7 +39,7 @@ config USB_PWC_DEBUG
 config USB_PWC_INPUT_EVDEV
        bool "USB Philips Cameras input events device support"
        default y
-       depends on USB_PWC=INPUT || INPUT=y
+       depends on USB_PWC && (USB_PWC=INPUT || INPUT=y)
        ---help---
          This option makes USB Philips cameras register the snapshot button as
          an input device to report button events.
index 04bf5c1..7fe70e7 100644 (file)
@@ -253,8 +253,8 @@ static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
 
        if (0 == *count)
                *count = 32;
-       while (*size * *count > vid_limit * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > vid_limit * 1024 * 1024)
+               *count = (vid_limit * 1024 * 1024) / *size;
 
        return 0;
 }
index 9277194..bbd9c11 100644 (file)
@@ -555,15 +555,15 @@ static int rj54n1_commit(struct i2c_client *client)
        return ret;
 }
 
-static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h,
-                              u32 *out_w, u32 *out_h);
+static int rj54n1_sensor_scale(struct v4l2_subdev *sd, s32 *in_w, s32 *in_h,
+                              s32 *out_w, s32 *out_h);
 
 static int rj54n1_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
 {
        struct i2c_client *client = sd->priv;
        struct rj54n1 *rj54n1 = to_rj54n1(client);
        struct v4l2_rect *rect = &a->c;
-       unsigned int dummy = 0, output_w, output_h,
+       int dummy = 0, output_w, output_h,
                input_w = rect->width, input_h = rect->height;
        int ret;
 
@@ -577,7 +577,7 @@ static int rj54n1_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
        output_w = (input_w * 1024 + rj54n1->resize / 2) / rj54n1->resize;
        output_h = (input_h * 1024 + rj54n1->resize / 2) / rj54n1->resize;
 
-       dev_dbg(&client->dev, "Scaling for %ux%u : %u = %ux%u\n",
+       dev_dbg(&client->dev, "Scaling for %dx%d : %u = %dx%d\n",
                input_w, input_h, rj54n1->resize, output_w, output_h);
 
        ret = rj54n1_sensor_scale(sd, &input_w, &input_h, &output_w, &output_h);
@@ -638,8 +638,8 @@ static int rj54n1_g_fmt(struct v4l2_subdev *sd,
  * the output one, updates the window sizes and returns an error or the resize
  * coefficient on success. Note: we only use the "Fixed Scaling" on this camera.
  */
-static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h,
-                              u32 *out_w, u32 *out_h)
+static int rj54n1_sensor_scale(struct v4l2_subdev *sd, s32 *in_w, s32 *in_h,
+                              s32 *out_w, s32 *out_h)
 {
        struct i2c_client *client = sd->priv;
        struct rj54n1 *rj54n1 = to_rj54n1(client);
@@ -749,7 +749,7 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h,
         * improve the image quality or stability for larger frames (see comment
         * above), but I didn't check the framerate.
         */
-       skip = min(resize / 1024, (unsigned)15);
+       skip = min(resize / 1024, 15U);
 
        inc_sel = 1 << skip;
 
@@ -819,7 +819,7 @@ static int rj54n1_sensor_scale(struct v4l2_subdev *sd, u32 *in_w, u32 *in_h,
        *out_w = output_w;
        *out_h = output_h;
 
-       dev_dbg(&client->dev, "Scaled for %ux%u : %u = %ux%u, skip %u\n",
+       dev_dbg(&client->dev, "Scaled for %dx%d : %u = %ux%u, skip %u\n",
                *in_w, *in_h, resize, output_w, output_h, skip);
 
        return resize;
@@ -1017,7 +1017,7 @@ static int rj54n1_s_fmt(struct v4l2_subdev *sd,
        struct i2c_client *client = sd->priv;
        struct rj54n1 *rj54n1 = to_rj54n1(client);
        const struct rj54n1_datafmt *fmt;
-       unsigned int output_w, output_h, max_w, max_h,
+       int output_w, output_h, max_w, max_h,
                input_w = rj54n1->rect.width, input_h = rj54n1->rect.height;
        int ret;
 
index 3de914d..3c7a79f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  s2255drv.c - a driver for the Sensoray 2255 USB video capture device
  *
- *   Copyright (C) 2007-2008 by Sensoray Company Inc.
+ *   Copyright (C) 2007-2010 by Sensoray Company Inc.
  *                              Dean Anderson
  *
  * Some video buffer code based on vivi driver:
 #include <linux/smp_lock.h>
 #include <media/videobuf-vmalloc.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <linux/vmalloc.h>
 #include <linux/usb.h>
 
+#define S2255_MAJOR_VERSION    1
+#define S2255_MINOR_VERSION    20
+#define S2255_RELEASE          0
+#define S2255_VERSION          KERNEL_VERSION(S2255_MAJOR_VERSION, \
+                                              S2255_MINOR_VERSION, \
+                                              S2255_RELEASE)
 #define FIRMWARE_FILE_NAME "f2255usb.bin"
 
-
-
 /* default JPEG quality */
 #define S2255_DEF_JPEG_QUAL     50
 /* vendor request in */
 #define S2255_LOAD_TIMEOUT      (5000 + S2255_DSP_BOOTTIME)
 #define S2255_DEF_BUFS          16
 #define S2255_SETMODE_TIMEOUT   500
-#define MAX_CHANNELS           4
-#define S2255_MARKER_FRAME     0x2255DA4AL
-#define S2255_MARKER_RESPONSE  0x2255ACACL
-#define S2255_RESPONSE_SETMODE  0x01
-#define S2255_RESPONSE_FW       0x10
+#define S2255_VIDSTATUS_TIMEOUT 350
+#define S2255_MARKER_FRAME     cpu_to_le32(0x2255DA4AL)
+#define S2255_MARKER_RESPONSE  cpu_to_le32(0x2255ACACL)
+#define S2255_RESPONSE_SETMODE  cpu_to_le32(0x01)
+#define S2255_RESPONSE_FW       cpu_to_le32(0x10)
+#define S2255_RESPONSE_STATUS   cpu_to_le32(0x20)
 #define S2255_USB_XFER_SIZE    (16 * 1024)
 #define MAX_CHANNELS           4
-#define MAX_PIPE_BUFFERS       1
 #define SYS_FRAMES             4
 /* maximum size is PAL full size plus room for the marker header(s) */
 #define SYS_FRAMES_MAXSIZE     (720*288*2*2 + 4096)
 #define COLOR_YUVPK    2       /* YUV packed */
 #define COLOR_Y8       4       /* monochrome */
 #define COLOR_JPG       5       /* JPEG */
-#define MASK_COLOR      0xff
-#define MASK_JPG_QUALITY 0xff00
 
+#define MASK_COLOR       0x000000ff
+#define MASK_JPG_QUALITY 0x0000ff00
+#define MASK_INPUT_TYPE  0x000f0000
 /* frame decimation. Not implemented by V4L yet(experimental in V4L) */
 #define FDEC_1         1       /* capture every frame. default */
 #define FDEC_2         2       /* capture every 2nd frame */
 #define DEF_HUE                0
 
 /* usb config commands */
-#define IN_DATA_TOKEN  0x2255c0de
-#define CMD_2255       0xc2255000
-#define CMD_SET_MODE   (CMD_2255 | 0x10)
-#define CMD_START      (CMD_2255 | 0x20)
-#define CMD_STOP       (CMD_2255 | 0x30)
-#define CMD_STATUS     (CMD_2255 | 0x40)
+#define IN_DATA_TOKEN  cpu_to_le32(0x2255c0de)
+#define CMD_2255       cpu_to_le32(0xc2255000)
+#define CMD_SET_MODE   cpu_to_le32((CMD_2255 | 0x10))
+#define CMD_START      cpu_to_le32((CMD_2255 | 0x20))
+#define CMD_STOP       cpu_to_le32((CMD_2255 | 0x30))
+#define CMD_STATUS     cpu_to_le32((CMD_2255 | 0x40))
 
 struct s2255_mode {
        u32 format;     /* input video format (NTSC, PAL) */
@@ -194,7 +200,6 @@ struct s2255_dmaqueue {
 #define S2255_FW_SUCCESS       2
 #define S2255_FW_FAILED                3
 #define S2255_FW_DISCONNECTING  4
-
 #define S2255_FW_MARKER                cpu_to_le32(0x22552f2f)
 /* 2255 read states */
 #define S2255_READ_IDLE         0
@@ -223,8 +228,10 @@ struct s2255_pipeinfo {
 struct s2255_fmt; /*forward declaration */
 
 struct s2255_dev {
+       struct video_device     vdev[MAX_CHANNELS];
+       struct v4l2_device      v4l2_dev;
+       atomic_t                channels; /* number of channels registered */
        int                     frames;
-       int                     users[MAX_CHANNELS];
        struct mutex            lock;
        struct mutex            open_lock;
        int                     resources[MAX_CHANNELS];
@@ -233,11 +240,10 @@ struct s2255_dev {
        u8                      read_endpoint;
 
        struct s2255_dmaqueue   vidq[MAX_CHANNELS];
-       struct video_device     *vdev[MAX_CHANNELS];
        struct timer_list       timer;
        struct s2255_fw *fw_data;
-       struct s2255_pipeinfo   pipes[MAX_PIPE_BUFFERS];
-       struct s2255_bufferi            buffer[MAX_CHANNELS];
+       struct s2255_pipeinfo   pipe;
+       struct s2255_bufferi    buffer[MAX_CHANNELS];
        struct s2255_mode       mode[MAX_CHANNELS];
        /* jpeg compression */
        struct v4l2_jpegcompression jc[MAX_CHANNELS];
@@ -261,11 +267,21 @@ struct s2255_dev {
        int                     chn_configured[MAX_CHANNELS];
        wait_queue_head_t       wait_setmode[MAX_CHANNELS];
        int                     setmode_ready[MAX_CHANNELS];
+       /* video status items */
+       int                     vidstatus[MAX_CHANNELS];
+       wait_queue_head_t       wait_vidstatus[MAX_CHANNELS];
+       int                     vidstatus_ready[MAX_CHANNELS];
        int                     chn_ready;
-       struct kref             kref;
        spinlock_t              slock;
+       /* dsp firmware version (f2255usb.bin) */
+       int                     dsp_fw_ver;
+       u16                     pid; /* product id */
 };
-#define to_s2255_dev(d) container_of(d, struct s2255_dev, kref)
+
+static inline struct s2255_dev *to_s2255_dev(struct v4l2_device *v4l2_dev)
+{
+       return container_of(v4l2_dev, struct s2255_dev, v4l2_dev);
+}
 
 struct s2255_fmt {
        char *name;
@@ -296,17 +312,43 @@ struct s2255_fh {
 
 /* current cypress EEPROM firmware version */
 #define S2255_CUR_USB_FWVER    ((3 << 8) | 6)
-#define S2255_MAJOR_VERSION    1
-#define S2255_MINOR_VERSION    14
-#define S2255_RELEASE          0
-#define S2255_VERSION          KERNEL_VERSION(S2255_MAJOR_VERSION, \
-                                              S2255_MINOR_VERSION, \
-                                              S2255_RELEASE)
-
-/* vendor ids */
-#define USB_S2255_VENDOR_ID    0x1943
-#define USB_S2255_PRODUCT_ID   0x2255
+/* current DSP FW version */
+#define S2255_CUR_DSP_FWVER     8
+/* Need DSP version 5+ for video status feature */
+#define S2255_MIN_DSP_STATUS      5
+#define S2255_MIN_DSP_COLORFILTER 8
 #define S2255_NORMS            (V4L2_STD_PAL | V4L2_STD_NTSC)
+
+/* private V4L2 controls */
+
+/*
+ * The following chart displays how COLORFILTER should be set
+ *  =========================================================
+ *  =     fourcc              =     COLORFILTER             =
+ *  =                         ===============================
+ *  =                         =   0             =    1      =
+ *  =========================================================
+ *  =  V4L2_PIX_FMT_GREY(Y8)  = monochrome from = monochrome=
+ *  =                         = s-video or      = composite =
+ *  =                         = B/W camera      = input     =
+ *  =========================================================
+ *  =    other                = color, svideo   = color,    =
+ *  =                         =                 = composite =
+ *  =========================================================
+ *
+ * Notes:
+ *   channels 0-3 on 2255 are composite
+ *   channels 0-1 on 2257 are composite, 2-3 are s-video
+ * If COLORFILTER is 0 with a composite color camera connected,
+ * the output will appear monochrome but hatching
+ * will occur.
+ * COLORFILTER is different from "color killer" and "color effects"
+ * for reasons above.
+ */
+#define S2255_V4L2_YC_ON  1
+#define S2255_V4L2_YC_OFF 0
+#define V4L2_CID_PRIVATE_COLORFILTER (V4L2_CID_PRIVATE_BASE + 0)
+
 /* frame prefix size (sent once every frame) */
 #define PREFIX_SIZE            512
 
@@ -325,9 +367,8 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
 static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
                          struct s2255_mode *mode);
 static int s2255_board_shutdown(struct s2255_dev *dev);
-static void s2255_exit_v4l(struct s2255_dev *dev);
 static void s2255_fwload_start(struct s2255_dev *dev, int reset);
-static void s2255_destroy(struct kref *kref);
+static void s2255_destroy(struct s2255_dev *dev);
 static long s2255_vendor_req(struct s2255_dev *dev, unsigned char req,
                             u16 index, u16 value, void *buf,
                             s32 buf_len, int bOut);
@@ -347,7 +388,6 @@ static long s2255_vendor_req(struct s2255_dev *dev, unsigned char req,
 
 static struct usb_driver s2255_driver;
 
-
 /* Declare static vars that will be used as parameters */
 static unsigned int vid_limit = 16;    /* Video memory limit, in Mb */
 
@@ -362,58 +402,16 @@ module_param(video_nr, int, 0644);
 MODULE_PARM_DESC(video_nr, "start video minor(-1 default autodetect)");
 
 /* USB device table */
+#define USB_SENSORAY_VID       0x1943
 static struct usb_device_id s2255_table[] = {
-       {USB_DEVICE(USB_S2255_VENDOR_ID, USB_S2255_PRODUCT_ID)},
+       {USB_DEVICE(USB_SENSORAY_VID, 0x2255)},
+       {USB_DEVICE(USB_SENSORAY_VID, 0x2257)}, /*same family as 2255*/
        { }                     /* Terminating entry */
 };
 MODULE_DEVICE_TABLE(usb, s2255_table);
 
-
 #define BUFFER_TIMEOUT msecs_to_jiffies(400)
 
-/* supported controls */
-static struct v4l2_queryctrl s2255_qctrl[] = {
-       {
-       .id = V4L2_CID_BRIGHTNESS,
-       .type = V4L2_CTRL_TYPE_INTEGER,
-       .name = "Brightness",
-       .minimum = -127,
-       .maximum = 128,
-       .step = 1,
-       .default_value = 0,
-       .flags = 0,
-       }, {
-       .id = V4L2_CID_CONTRAST,
-       .type = V4L2_CTRL_TYPE_INTEGER,
-       .name = "Contrast",
-       .minimum = 0,
-       .maximum = 255,
-       .step = 0x1,
-       .default_value = DEF_CONTRAST,
-       .flags = 0,
-       }, {
-       .id = V4L2_CID_SATURATION,
-       .type = V4L2_CTRL_TYPE_INTEGER,
-       .name = "Saturation",
-       .minimum = 0,
-       .maximum = 255,
-       .step = 0x1,
-       .default_value = DEF_SATURATION,
-       .flags = 0,
-       }, {
-       .id = V4L2_CID_HUE,
-       .type = V4L2_CTRL_TYPE_INTEGER,
-       .name = "Hue",
-       .minimum = 0,
-       .maximum = 255,
-       .step = 0x1,
-       .default_value = DEF_HUE,
-       .flags = 0,
-       }
-};
-
-static int qctl_regs[ARRAY_SIZE(s2255_qctrl)];
-
 /* image formats.  */
 static const struct s2255_fmt formats[] = {
        {
@@ -505,7 +503,7 @@ static void s2255_reset_dsppower(struct s2255_dev *dev)
 static void s2255_timer(unsigned long user_data)
 {
        struct s2255_fw *data = (struct s2255_fw *)user_data;
-       dprintk(100, "s2255 timer\n");
+       dprintk(100, "%s\n", __func__);
        if (usb_submit_urb(data->fw_urb, GFP_ATOMIC) < 0) {
                printk(KERN_ERR "s2255: can't submit urb\n");
                atomic_set(&data->fw_state, S2255_FW_FAILED);
@@ -527,7 +525,7 @@ static void s2255_fwchunk_complete(struct urb *urb)
        struct s2255_fw *data = urb->context;
        struct usb_device *udev = urb->dev;
        int len;
-       dprintk(100, "udev %p urb %p", udev, urb);
+       dprintk(100, "%s: udev %p urb %p", __func__, udev, urb);
        if (urb->status) {
                dev_err(&udev->dev, "URB failed with status %d\n", urb->status);
                atomic_set(&data->fw_state, S2255_FW_FAILED);
@@ -573,8 +571,8 @@ static void s2255_fwchunk_complete(struct urb *urb)
                data->fw_loaded += len;
        } else {
                atomic_set(&data->fw_state, S2255_FW_LOADED_DSPWAIT);
+               dprintk(100, "%s: firmware upload complete\n", __func__);
        }
-       dprintk(100, "2255 complete done\n");
        return;
 
 }
@@ -585,9 +583,7 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize)
        struct s2255_buffer *buf;
        unsigned long flags = 0;
        int rc = 0;
-       dprintk(2, "wakeup: %p channel: %d\n", &dma_q, chn);
        spin_lock_irqsave(&dev->slock, flags);
-
        if (list_empty(&dma_q->active)) {
                dprintk(1, "No active queue to serve\n");
                rc = -1;
@@ -595,23 +591,19 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize)
        }
        buf = list_entry(dma_q->active.next,
                         struct s2255_buffer, vb.queue);
-
        list_del(&buf->vb.queue);
        do_gettimeofday(&buf->vb.ts);
-       dprintk(100, "[%p/%d] wakeup\n", buf, buf->vb.i);
        s2255_fillbuff(dev, buf, dma_q->channel, jpgsize);
        wake_up(&buf->vb.done);
-       dprintk(2, "wakeup [buf/i] [%p/%d]\n", buf, buf->vb.i);
+       dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i);
 unlock:
        spin_unlock_irqrestore(&dev->slock, flags);
        return 0;
 }
 
-
 static const struct s2255_fmt *format_by_fourcc(int fourcc)
 {
        unsigned int i;
-
        for (i = 0; i < ARRAY_SIZE(formats); i++) {
                if (-1 == formats[i].fourcc)
                        continue;
@@ -621,9 +613,6 @@ static const struct s2255_fmt *format_by_fourcc(int fourcc)
        return NULL;
 }
 
-
-
-
 /* video buffer vmalloc implementation based partly on VIVI driver which is
  *          Copyright (c) 2006 by
  *                  Mauro Carvalho Chehab <mchehab--a.t--infradead.org>
@@ -703,8 +692,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
        if (0 == *count)
                *count = S2255_DEF_BUFS;
 
-       while (*size * (*count) > vid_limit * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > vid_limit * 1024 * 1024)
+               *count = (vid_limit * 1024 * 1024) / *size;
 
        return 0;
 }
@@ -727,10 +716,10 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        if (fh->fmt == NULL)
                return -EINVAL;
 
-       if ((fh->width < norm_minw(fh->dev->vdev[fh->channel])) ||
-           (fh->width > norm_maxw(fh->dev->vdev[fh->channel])) ||
-           (fh->height < norm_minh(fh->dev->vdev[fh->channel])) ||
-           (fh->height > norm_maxh(fh->dev->vdev[fh->channel]))) {
+       if ((fh->width < norm_minw(&fh->dev->vdev[fh->channel])) ||
+           (fh->width > norm_maxw(&fh->dev->vdev[fh->channel])) ||
+           (fh->height < norm_minh(&fh->dev->vdev[fh->channel])) ||
+           (fh->height > norm_maxh(&fh->dev->vdev[fh->channel]))) {
                dprintk(4, "invalid buffer prepare\n");
                return -EINVAL;
        }
@@ -747,7 +736,6 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        buf->vb.height = fh->height;
        buf->vb.field = field;
 
-
        if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
                rc = videobuf_iolock(vq, &buf->vb, NULL);
                if (rc < 0)
@@ -767,9 +755,7 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
        struct s2255_fh *fh = vq->priv_data;
        struct s2255_dev *dev = fh->dev;
        struct s2255_dmaqueue *vidq = &dev->vidq[fh->channel];
-
        dprintk(1, "%s\n", __func__);
-
        buf->vb.state = VIDEOBUF_QUEUED;
        list_add_tail(&buf->vb.queue, &vidq->active);
 }
@@ -828,6 +814,27 @@ static void res_free(struct s2255_dev *dev, struct s2255_fh *fh)
        dprintk(1, "res: put\n");
 }
 
+static int vidioc_querymenu(struct file *file, void *priv,
+                           struct v4l2_querymenu *qmenu)
+{
+       static const char *colorfilter[] = {
+               "Off",
+               "On",
+               NULL
+       };
+       if (qmenu->id == V4L2_CID_PRIVATE_COLORFILTER) {
+               int i;
+               const char **menu_items = colorfilter;
+               for (i = 0; i < qmenu->index && menu_items[i]; i++)
+                       ; /* do nothing (from v4l2-common.c) */
+               if (menu_items[i] == NULL || menu_items[i][0] == '\0')
+                       return -EINVAL;
+               strlcpy(qmenu->name, menu_items[qmenu->index],
+                       sizeof(qmenu->name));
+               return 0;
+       }
+       return v4l2_ctrl_query_menu(qmenu, NULL, NULL);
+}
 
 static int vidioc_querycap(struct file *file, void *priv,
                           struct v4l2_capability *cap)
@@ -883,7 +890,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
        int is_ntsc;
 
        is_ntsc =
-           (dev->vdev[fh->channel]->current_norm & V4L2_STD_NTSC) ? 1 : 0;
+           (dev->vdev[fh->channel].current_norm & V4L2_STD_NTSC) ? 1 : 0;
 
        fmt = format_by_fourcc(f->fmt.pix.pixelformat);
 
@@ -894,10 +901,8 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
        if (field == V4L2_FIELD_ANY)
                b_any_field = 1;
 
-       dprintk(4, "try format %d \n", is_ntsc);
-       /* supports 3 sizes. see s2255drv.h */
-       dprintk(50, "width test %d, height %d\n",
-               f->fmt.pix.width, f->fmt.pix.height);
+       dprintk(50, "%s NTSC: %d suggested width: %d, height: %d\n",
+               __func__, is_ntsc, f->fmt.pix.width, f->fmt.pix.height);
        if (is_ntsc) {
                /* NTSC */
                if (f->fmt.pix.height >= NUM_LINES_1CIFS_NTSC * 2) {
@@ -952,29 +957,24 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                        }
                }
                if (f->fmt.pix.width >= LINE_SZ_4CIFS_PAL) {
-                       dprintk(50, "pal 704\n");
                        f->fmt.pix.width = LINE_SZ_4CIFS_PAL;
                        field = V4L2_FIELD_SEQ_TB;
                } else if (f->fmt.pix.width >= LINE_SZ_2CIFS_PAL) {
-                       dprintk(50, "pal 352A\n");
                        f->fmt.pix.width = LINE_SZ_2CIFS_PAL;
                        field = V4L2_FIELD_TOP;
                } else if (f->fmt.pix.width >= LINE_SZ_1CIFS_PAL) {
-                       dprintk(50, "pal 352B\n");
                        f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
                        field = V4L2_FIELD_TOP;
                } else {
-                       dprintk(50, "pal 352C\n");
                        f->fmt.pix.width = LINE_SZ_1CIFS_PAL;
                        field = V4L2_FIELD_TOP;
                }
        }
-
-       dprintk(50, "width %d height %d field %d \n", f->fmt.pix.width,
-               f->fmt.pix.height, f->fmt.pix.field);
        f->fmt.pix.field = field;
        f->fmt.pix.bytesperline = (f->fmt.pix.width * fmt->depth) >> 3;
        f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline;
+       dprintk(50, "%s: set width %d height %d field %d\n", __func__,
+               f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
        return 0;
 }
 
@@ -1006,7 +1006,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        }
 
        if (res_locked(fh->dev, fh)) {
-               dprintk(1, "can't change format after started\n");
+               dprintk(1, "%s: channel busy\n", __func__);
                ret = -EBUSY;
                goto out_s_fmt;
        }
@@ -1016,17 +1016,14 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->height = f->fmt.pix.height;
        fh->vb_vidq.field = f->fmt.pix.field;
        fh->type = f->type;
-       norm = norm_minw(fh->dev->vdev[fh->channel]);
-       if (fh->width > norm_minw(fh->dev->vdev[fh->channel])) {
-               if (fh->height > norm_minh(fh->dev->vdev[fh->channel])) {
+       norm = norm_minw(&fh->dev->vdev[fh->channel]);
+       if (fh->width > norm_minw(&fh->dev->vdev[fh->channel])) {
+               if (fh->height > norm_minh(&fh->dev->vdev[fh->channel])) {
                        if (fh->dev->cap_parm[fh->channel].capturemode &
-                           V4L2_MODE_HIGHQUALITY) {
+                           V4L2_MODE_HIGHQUALITY)
                                fh->mode.scale = SCALE_4CIFSI;
-                               dprintk(2, "scale 4CIFSI\n");
-                       } else {
+                       else
                                fh->mode.scale = SCALE_4CIFS;
-                               dprintk(2, "scale 4CIFS\n");
-                       }
                } else
                        fh->mode.scale = SCALE_2CIFS;
 
@@ -1037,19 +1034,23 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        /* color mode */
        switch (fh->fmt->fourcc) {
        case V4L2_PIX_FMT_GREY:
-               fh->mode.color = COLOR_Y8;
+               fh->mode.color &= ~MASK_COLOR;
+               fh->mode.color |= COLOR_Y8;
                break;
        case V4L2_PIX_FMT_JPEG:
-               fh->mode.color = COLOR_JPG |
-                       (fh->dev->jc[fh->channel].quality << 8);
+               fh->mode.color &= ~MASK_COLOR;
+               fh->mode.color |= COLOR_JPG;
+               fh->mode.color |= (fh->dev->jc[fh->channel].quality << 8);
                break;
        case V4L2_PIX_FMT_YUV422P:
-               fh->mode.color = COLOR_YUVPL;
+               fh->mode.color &= ~MASK_COLOR;
+               fh->mode.color |= COLOR_YUVPL;
                break;
        case V4L2_PIX_FMT_YUYV:
        case V4L2_PIX_FMT_UYVY:
        default:
-               fh->mode.color = COLOR_YUVPK;
+               fh->mode.color &= ~MASK_COLOR;
+               fh->mode.color |= COLOR_YUVPK;
                break;
        }
        ret = 0;
@@ -1178,19 +1179,13 @@ static u32 get_transfer_size(struct s2255_mode *mode)
        return usbInSize;
 }
 
-static void dump_verify_mode(struct s2255_dev *sdev, struct s2255_mode *mode)
+static void s2255_print_cfg(struct s2255_dev *sdev, struct s2255_mode *mode)
 {
        struct device *dev = &sdev->udev->dev;
        dev_info(dev, "------------------------------------------------\n");
-       dev_info(dev, "verify mode\n");
-       dev_info(dev, "format: %d\n", mode->format);
-       dev_info(dev, "scale: %d\n", mode->scale);
-       dev_info(dev, "fdec: %d\n", mode->fdec);
-       dev_info(dev, "color: %d\n", mode->color);
+       dev_info(dev, "format: %d\nscale %d\n", mode->format, mode->scale);
+       dev_info(dev, "fdec: %d\ncolor %d\n", mode->fdec, mode->color);
        dev_info(dev, "bright: 0x%x\n", mode->bright);
-       dev_info(dev, "restart: 0x%x\n", mode->restart);
-       dev_info(dev, "usb_block: 0x%x\n", mode->usb_block);
-       dev_info(dev, "single: 0x%x\n", mode->single);
        dev_info(dev, "------------------------------------------------\n");
 }
 
@@ -1206,44 +1201,38 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
                          struct s2255_mode *mode)
 {
        int res;
-       u32 *buffer;
+       __le32 *buffer;
        unsigned long chn_rev;
-
        mutex_lock(&dev->lock);
        chn_rev = G_chnmap[chn];
-       dprintk(3, "mode scale [%ld] %p %d\n", chn, mode, mode->scale);
-       dprintk(3, "mode scale [%ld] %p %d\n", chn, &dev->mode[chn],
-               dev->mode[chn].scale);
-       dprintk(2, "mode contrast %x\n", mode->contrast);
-
+       dprintk(3, "%s channel %lu\n", __func__, chn);
        /* if JPEG, set the quality */
-       if ((mode->color & MASK_COLOR) == COLOR_JPG)
-               mode->color = (dev->jc[chn].quality << 8) | COLOR_JPG;
-
+       if ((mode->color & MASK_COLOR) == COLOR_JPG) {
+               mode->color &= ~MASK_COLOR;
+               mode->color |= COLOR_JPG;
+               mode->color &= ~MASK_JPG_QUALITY;
+               mode->color |= (dev->jc[chn].quality << 8);
+       }
        /* save the mode */
        dev->mode[chn] = *mode;
        dev->req_image_size[chn] = get_transfer_size(mode);
-       dprintk(1, "transfer size %ld\n", dev->req_image_size[chn]);
-
+       dprintk(1, "%s: reqsize %ld\n", __func__, dev->req_image_size[chn]);
        buffer = kzalloc(512, GFP_KERNEL);
        if (buffer == NULL) {
                dev_err(&dev->udev->dev, "out of mem\n");
                mutex_unlock(&dev->lock);
                return -ENOMEM;
        }
-
        /* set the mode */
        buffer[0] = IN_DATA_TOKEN;
-       buffer[1] = (u32) chn_rev;
+       buffer[1] = (__le32) cpu_to_le32(chn_rev);
        buffer[2] = CMD_SET_MODE;
        memcpy(&buffer[3], &dev->mode[chn], sizeof(struct s2255_mode));
        dev->setmode_ready[chn] = 0;
        res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
        if (debug)
-               dump_verify_mode(dev, mode);
+               s2255_print_cfg(dev, mode);
        kfree(buffer);
-       dprintk(1, "set mode done chn %lu, %d\n", chn, res);
-
        /* wait at least 3 frames before continuing */
        if (mode->restart) {
                wait_event_timeout(dev->wait_setmode[chn],
@@ -1254,10 +1243,46 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
                        res = -EFAULT;
                }
        }
-
        /* clear the restart flag */
        dev->mode[chn].restart = 0;
        mutex_unlock(&dev->lock);
+       dprintk(1, "%s chn %lu, result: %d\n", __func__, chn, res);
+       return res;
+}
+
+static int s2255_cmd_status(struct s2255_dev *dev, unsigned long chn,
+                           u32 *pstatus)
+{
+       int res;
+       __le32 *buffer;
+       u32 chn_rev;
+       mutex_lock(&dev->lock);
+       chn_rev = G_chnmap[chn];
+       dprintk(4, "%s chan %lu\n", __func__, chn);
+       buffer = kzalloc(512, GFP_KERNEL);
+       if (buffer == NULL) {
+               dev_err(&dev->udev->dev, "out of mem\n");
+               mutex_unlock(&dev->lock);
+               return -ENOMEM;
+       }
+       /* form the get vid status command */
+       buffer[0] = IN_DATA_TOKEN;
+       buffer[1] = (__le32) cpu_to_le32(chn_rev);
+       buffer[2] = CMD_STATUS;
+       *pstatus = 0;
+       dev->vidstatus_ready[chn] = 0;
+       res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
+       kfree(buffer);
+       wait_event_timeout(dev->wait_vidstatus[chn],
+                          (dev->vidstatus_ready[chn] != 0),
+                          msecs_to_jiffies(S2255_VIDSTATUS_TIMEOUT));
+       if (dev->vidstatus_ready[chn] != 1) {
+               printk(KERN_DEBUG "s2255: no vidstatus response\n");
+               res = -EFAULT;
+       }
+       *pstatus = dev->vidstatus[chn];
+       dprintk(4, "%s, vid status %d\n", __func__, *pstatus);
+       mutex_unlock(&dev->lock);
        return res;
 }
 
@@ -1291,7 +1316,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
        new_mode = &fh->mode;
        old_mode = &fh->dev->mode[chn];
 
-       if (new_mode->color != old_mode->color)
+       if ((new_mode->color & MASK_COLOR) != (old_mode->color & MASK_COLOR))
                new_mode->restart = 1;
        else if (new_mode->scale != old_mode->scale)
                new_mode->restart = 1;
@@ -1302,7 +1327,6 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
        new_mode->restart = 0;
        *old_mode = *new_mode;
        dev->cur_fmt[chn] = fh->fmt;
-       dprintk(1, "%s[%d]\n", __func__, chn);
        dev->last_frame[chn] = -1;
        dev->bad_payload[chn] = 0;
        dev->cur_frame[chn] = 0;
@@ -1325,7 +1349,6 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 {
        struct s2255_fh *fh = priv;
        struct s2255_dev *dev = fh->dev;
-
        dprintk(4, "%s\n, channel: %d", __func__, fh->channel);
        if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
                printk(KERN_ERR "invalid fh type0\n");
@@ -1347,27 +1370,32 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
        struct s2255_mode *mode;
        struct videobuf_queue *q = &fh->vb_vidq;
        int ret = 0;
-
        mutex_lock(&q->vb_lock);
        if (videobuf_queue_is_busy(q)) {
                dprintk(1, "queue busy\n");
                ret = -EBUSY;
                goto out_s_std;
        }
-
        if (res_locked(fh->dev, fh)) {
                dprintk(1, "can't change standard after started\n");
                ret = -EBUSY;
                goto out_s_std;
        }
        mode = &fh->mode;
-
        if (*i & V4L2_STD_NTSC) {
-               dprintk(4, "vidioc_s_std NTSC\n");
-               mode->format = FORMAT_NTSC;
+               dprintk(4, "%s NTSC\n", __func__);
+               /* if changing format, reset frame decimation/intervals */
+               if (mode->format != FORMAT_NTSC) {
+                       mode->format = FORMAT_NTSC;
+                       mode->fdec = FDEC_1;
+               }
        } else if (*i & V4L2_STD_PAL) {
-               dprintk(4, "vidioc_s_std PAL\n");
+               dprintk(4, "%s PAL\n", __func__);
                mode->format = FORMAT_PAL;
+               if (mode->format != FORMAT_PAL) {
+                       mode->format = FORMAT_PAL;
+                       mode->fdec = FDEC_1;
+               }
        } else {
                ret = -EINVAL;
        }
@@ -1386,12 +1414,32 @@ out_s_std:
 static int vidioc_enum_input(struct file *file, void *priv,
                             struct v4l2_input *inp)
 {
+       struct s2255_fh *fh = priv;
+       struct s2255_dev *dev = fh->dev;
+       u32 status = 0;
        if (inp->index != 0)
                return -EINVAL;
-
        inp->type = V4L2_INPUT_TYPE_CAMERA;
        inp->std = S2255_NORMS;
-       strlcpy(inp->name, "Camera", sizeof(inp->name));
+       inp->status = 0;
+       if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) {
+               int rc;
+               rc = s2255_cmd_status(dev, fh->channel, &status);
+               dprintk(4, "s2255_cmd_status rc: %d status %x\n", rc, status);
+               if (rc == 0)
+                       inp->status =  (status & 0x01) ? 0
+                               : V4L2_IN_ST_NO_SIGNAL;
+       }
+       switch (dev->pid) {
+       case 0x2255:
+       default:
+               strlcpy(inp->name, "Composite", sizeof(inp->name));
+               break;
+       case 0x2257:
+               strlcpy(inp->name, (fh->channel < 2) ? "Composite" : "S-Video",
+                       sizeof(inp->name));
+               break;
+       }
        return 0;
 }
 
@@ -1411,74 +1459,113 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 static int vidioc_queryctrl(struct file *file, void *priv,
                            struct v4l2_queryctrl *qc)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++)
-               if (qc->id && qc->id == s2255_qctrl[i].id) {
-                       memcpy(qc, &(s2255_qctrl[i]), sizeof(*qc));
-                       return 0;
-               }
-
-       dprintk(4, "query_ctrl -EINVAL %d\n", qc->id);
-       return -EINVAL;
+       struct s2255_fh *fh = priv;
+       struct s2255_dev *dev = fh->dev;
+       switch (qc->id) {
+       case V4L2_CID_BRIGHTNESS:
+               v4l2_ctrl_query_fill(qc, -127, 127, 1, DEF_BRIGHT);
+               break;
+       case V4L2_CID_CONTRAST:
+               v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_CONTRAST);
+               break;
+       case V4L2_CID_SATURATION:
+               v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_SATURATION);
+               break;
+       case V4L2_CID_HUE:
+               v4l2_ctrl_query_fill(qc, 0, 255, 1, DEF_HUE);
+               break;
+       case V4L2_CID_PRIVATE_COLORFILTER:
+               if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
+                       return -EINVAL;
+               if ((dev->pid == 0x2257) && (fh->channel > 1))
+                       return -EINVAL;
+               strlcpy(qc->name, "Color Filter", sizeof(qc->name));
+               qc->type = V4L2_CTRL_TYPE_MENU;
+               qc->minimum = 0;
+               qc->maximum = 1;
+               qc->step = 1;
+               qc->default_value = 1;
+               qc->flags = 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+       dprintk(4, "%s, id %d\n", __func__, qc->id);
+       return 0;
 }
 
 static int vidioc_g_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctrl)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++)
-               if (ctrl->id == s2255_qctrl[i].id) {
-                       ctrl->value = qctl_regs[i];
-                       return 0;
-               }
-       dprintk(4, "g_ctrl -EINVAL\n");
-
-       return -EINVAL;
+       struct s2255_fh *fh = priv;
+       struct s2255_dev *dev = fh->dev;
+       switch (ctrl->id) {
+       case V4L2_CID_BRIGHTNESS:
+               ctrl->value = fh->mode.bright;
+               break;
+       case V4L2_CID_CONTRAST:
+               ctrl->value = fh->mode.contrast;
+               break;
+       case V4L2_CID_SATURATION:
+               ctrl->value = fh->mode.saturation;
+               break;
+       case V4L2_CID_HUE:
+               ctrl->value = fh->mode.hue;
+               break;
+       case V4L2_CID_PRIVATE_COLORFILTER:
+               if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
+                       return -EINVAL;
+               if ((dev->pid == 0x2257) && (fh->channel > 1))
+                       return -EINVAL;
+               ctrl->value = !((fh->mode.color & MASK_INPUT_TYPE) >> 16);
+               break;
+       default:
+               return -EINVAL;
+       }
+       dprintk(4, "%s, id %d val %d\n", __func__, ctrl->id, ctrl->value);
+       return 0;
 }
 
 static int vidioc_s_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctrl)
 {
-       int i;
        struct s2255_fh *fh = priv;
        struct s2255_dev *dev = fh->dev;
        struct s2255_mode *mode;
        mode = &fh->mode;
-       dprintk(4, "vidioc_s_ctrl\n");
-       for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++) {
-               if (ctrl->id == s2255_qctrl[i].id) {
-                       if (ctrl->value < s2255_qctrl[i].minimum ||
-                           ctrl->value > s2255_qctrl[i].maximum)
-                               return -ERANGE;
-
-                       qctl_regs[i] = ctrl->value;
-                       /* update the mode to the corresponding value */
-                       switch (ctrl->id) {
-                       case V4L2_CID_BRIGHTNESS:
-                               mode->bright = ctrl->value;
-                               break;
-                       case V4L2_CID_CONTRAST:
-                               mode->contrast = ctrl->value;
-                               break;
-                       case V4L2_CID_HUE:
-                               mode->hue = ctrl->value;
-                               break;
-                       case V4L2_CID_SATURATION:
-                               mode->saturation = ctrl->value;
-                               break;
-                       }
-                       mode->restart = 0;
-                       /* set mode here.  Note: stream does not need restarted.
-                          some V4L programs restart stream unnecessarily
-                          after a s_crtl.
-                        */
-                       s2255_set_mode(dev, fh->channel, mode);
-                       return 0;
-               }
+       dprintk(4, "%s\n", __func__);
+       /* update the mode to the corresponding value */
+       switch (ctrl->id) {
+       case V4L2_CID_BRIGHTNESS:
+               mode->bright = ctrl->value;
+               break;
+       case V4L2_CID_CONTRAST:
+               mode->contrast = ctrl->value;
+               break;
+       case V4L2_CID_HUE:
+               mode->hue = ctrl->value;
+               break;
+       case V4L2_CID_SATURATION:
+               mode->saturation = ctrl->value;
+               break;
+       case V4L2_CID_PRIVATE_COLORFILTER:
+               if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER)
+                       return -EINVAL;
+               if ((dev->pid == 0x2257) && (fh->channel > 1))
+                       return -EINVAL;
+               mode->color &= ~MASK_INPUT_TYPE;
+               mode->color |= ((ctrl->value ? 0 : 1) << 16);
+               break;
+       default:
+               return -EINVAL;
        }
-       return -EINVAL;
+       mode->restart = 0;
+       /* set mode here.  Note: stream does not need restarted.
+          some V4L programs restart stream unnecessarily
+          after a s_crtl.
+       */
+       s2255_set_mode(dev, fh->channel, mode);
+       return 0;
 }
 
 static int vidioc_g_jpegcomp(struct file *file, void *priv,
@@ -1487,7 +1574,7 @@ static int vidioc_g_jpegcomp(struct file *file, void *priv,
        struct s2255_fh *fh = priv;
        struct s2255_dev *dev = fh->dev;
        *jc = dev->jc[fh->channel];
-       dprintk(2, "getting jpegcompression, quality %d\n", jc->quality);
+       dprintk(2, "%s: quality %d\n", __func__, jc->quality);
        return 0;
 }
 
@@ -1499,7 +1586,7 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv,
        if (jc->quality < 0 || jc->quality > 100)
                return -EINVAL;
        dev->jc[fh->channel].quality = jc->quality;
-       dprintk(2, "setting jpeg quality %d\n", jc->quality);
+       dprintk(2, "%s: quality %d\n", __func__, jc->quality);
        return 0;
 }
 
@@ -1508,10 +1595,34 @@ static int vidioc_g_parm(struct file *file, void *priv,
 {
        struct s2255_fh *fh = priv;
        struct s2255_dev *dev = fh->dev;
+       __u32 def_num, def_dem;
        if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
+       memset(sp, 0, sizeof(struct v4l2_streamparm));
+       sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
        sp->parm.capture.capturemode = dev->cap_parm[fh->channel].capturemode;
-       dprintk(2, "getting parm %d\n", sp->parm.capture.capturemode);
+       def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000;
+       def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000;
+       sp->parm.capture.timeperframe.denominator = def_dem;
+       switch (fh->mode.fdec) {
+       default:
+       case FDEC_1:
+               sp->parm.capture.timeperframe.numerator = def_num;
+               break;
+       case FDEC_2:
+               sp->parm.capture.timeperframe.numerator = def_num * 2;
+               break;
+       case FDEC_3:
+               sp->parm.capture.timeperframe.numerator = def_num * 3;
+               break;
+       case FDEC_5:
+               sp->parm.capture.timeperframe.numerator = def_num * 5;
+               break;
+       }
+       dprintk(4, "%s capture mode, %d timeperframe %d/%d\n", __func__,
+               sp->parm.capture.capturemode,
+               sp->parm.capture.timeperframe.numerator,
+               sp->parm.capture.timeperframe.denominator);
        return 0;
 }
 
@@ -1520,15 +1631,79 @@ static int vidioc_s_parm(struct file *file, void *priv,
 {
        struct s2255_fh *fh = priv;
        struct s2255_dev *dev = fh->dev;
-
+       int fdec = FDEC_1;
+       __u32 def_num, def_dem;
        if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
+       /* high quality capture mode requires a stream restart */
+       if (dev->cap_parm[fh->channel].capturemode
+           != sp->parm.capture.capturemode && res_locked(fh->dev, fh))
+               return -EBUSY;
+       def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000;
+       def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000;
+       if (def_dem != sp->parm.capture.timeperframe.denominator)
+               sp->parm.capture.timeperframe.numerator = def_num;
+       else if (sp->parm.capture.timeperframe.numerator <= def_num)
+               sp->parm.capture.timeperframe.numerator = def_num;
+       else if (sp->parm.capture.timeperframe.numerator <= (def_num * 2)) {
+               sp->parm.capture.timeperframe.numerator = def_num * 2;
+               fdec = FDEC_2;
+       } else if (sp->parm.capture.timeperframe.numerator <= (def_num * 3)) {
+               sp->parm.capture.timeperframe.numerator = def_num * 3;
+               fdec = FDEC_3;
+       } else {
+               sp->parm.capture.timeperframe.numerator = def_num * 5;
+               fdec = FDEC_5;
+       }
+       fh->mode.fdec = fdec;
+       sp->parm.capture.timeperframe.denominator = def_dem;
+       s2255_set_mode(dev, fh->channel, &fh->mode);
+       dprintk(4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n",
+               __func__,
+               sp->parm.capture.capturemode,
+               sp->parm.capture.timeperframe.numerator,
+               sp->parm.capture.timeperframe.denominator, fdec);
+       return 0;
+}
 
-       dev->cap_parm[fh->channel].capturemode = sp->parm.capture.capturemode;
-       dprintk(2, "setting param capture mode %d\n",
-               sp->parm.capture.capturemode);
+static int vidioc_enum_frameintervals(struct file *file, void *priv,
+                           struct v4l2_frmivalenum *fe)
+{
+       int is_ntsc = 0;
+#define NUM_FRAME_ENUMS 4
+       int frm_dec[NUM_FRAME_ENUMS] = {1, 2, 3, 5};
+       if (fe->index < 0 || fe->index >= NUM_FRAME_ENUMS)
+               return -EINVAL;
+       switch (fe->width) {
+       case 640:
+               if (fe->height != 240 && fe->height != 480)
+                       return -EINVAL;
+               is_ntsc = 1;
+               break;
+       case 320:
+               if (fe->height != 240)
+                       return -EINVAL;
+               is_ntsc = 1;
+               break;
+       case 704:
+               if (fe->height != 288 && fe->height != 576)
+                       return -EINVAL;
+               break;
+       case 352:
+               if (fe->height != 288)
+                       return -EINVAL;
+               break;
+       default:
+               return -EINVAL;
+       }
+       fe->type = V4L2_FRMIVAL_TYPE_DISCRETE;
+       fe->discrete.denominator = is_ntsc ? 30000 : 25000;
+       fe->discrete.numerator = (is_ntsc ? 1001 : 1000) * frm_dec[fe->index];
+       dprintk(4, "%s discrete %d/%d\n", __func__, fe->discrete.numerator,
+               fe->discrete.denominator);
        return 0;
 }
+
 static int s2255_open(struct file *file)
 {
        struct video_device *vdev = video_devdata(file);
@@ -1538,31 +1713,29 @@ static int s2255_open(struct file *file)
        int i = 0;
        int cur_channel = -1;
        int state;
-
        dprintk(1, "s2255: open called (dev=%s)\n",
                video_device_node_name(vdev));
 
-       lock_kernel();
-
        for (i = 0; i < MAX_CHANNELS; i++) {
-               if (dev->vdev[i] == vdev) {
+               if (&dev->vdev[i] == vdev) {
                        cur_channel = i;
                        break;
                }
        }
-
-       if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_DISCONNECTING) {
-               unlock_kernel();
-               printk(KERN_INFO "disconnecting\n");
+       if (i == MAX_CHANNELS)
                return -ENODEV;
-       }
-       kref_get(&dev->kref);
-       mutex_lock(&dev->open_lock);
-
-       dev->users[cur_channel]++;
-       dprintk(4, "s2255: open_handles %d\n", dev->users[cur_channel]);
 
-       switch (atomic_read(&dev->fw_data->fw_state)) {
+       /*
+        * open lock necessary to prevent multiple instances
+        * of v4l-conf (or other programs) from simultaneously
+        * reloading firmware.
+        */
+       mutex_lock(&dev->open_lock);
+       state = atomic_read(&dev->fw_data->fw_state);
+       switch (state) {
+       case S2255_FW_DISCONNECTING:
+               mutex_unlock(&dev->open_lock);
+               return -ENODEV;
        case S2255_FW_FAILED:
                s2255_dev_err(&dev->udev->dev,
                        "firmware load failed. retrying.\n");
@@ -1573,6 +1746,8 @@ static int s2255_open(struct file *file)
                                    (atomic_read(&dev->fw_data->fw_state)
                                     == S2255_FW_DISCONNECTING)),
                                   msecs_to_jiffies(S2255_LOAD_TIMEOUT));
+               /* state may have changed, re-read */
+               state = atomic_read(&dev->fw_data->fw_state);
                break;
        case S2255_FW_NOTLOADED:
        case S2255_FW_LOADED_DSPWAIT:
@@ -1584,53 +1759,50 @@ static int s2255_open(struct file *file)
                                     == S2255_FW_SUCCESS) ||
                                    (atomic_read(&dev->fw_data->fw_state)
                                     == S2255_FW_DISCONNECTING)),
-                       msecs_to_jiffies(S2255_LOAD_TIMEOUT));
+                                  msecs_to_jiffies(S2255_LOAD_TIMEOUT));
+               /* state may have changed, re-read */
+               state = atomic_read(&dev->fw_data->fw_state);
                break;
        case S2255_FW_SUCCESS:
        default:
                break;
        }
-       state = atomic_read(&dev->fw_data->fw_state);
-       if (state != S2255_FW_SUCCESS) {
-               int rc;
-               switch (state) {
-               case S2255_FW_FAILED:
-                       printk(KERN_INFO "2255 FW load failed. %d\n", state);
-                       rc = -ENODEV;
-                       break;
-               case S2255_FW_DISCONNECTING:
-                       printk(KERN_INFO "%s: disconnecting\n", __func__);
-                       rc = -ENODEV;
-                       break;
-               case S2255_FW_LOADED_DSPWAIT:
-               case S2255_FW_NOTLOADED:
-                       printk(KERN_INFO "%s: firmware not loaded yet"
-                              "please try again later\n",
-                              __func__);
-                       rc = -EAGAIN;
-                       break;
-               default:
-                       printk(KERN_INFO "%s: unknown state\n", __func__);
-                       rc = -EFAULT;
-                       break;
-               }
-               dev->users[cur_channel]--;
+       /* state may have changed in above switch statement */
+       switch (state) {
+       case S2255_FW_SUCCESS:
+               break;
+       case S2255_FW_FAILED:
+               printk(KERN_INFO "2255 firmware load failed.\n");
+               mutex_unlock(&dev->open_lock);
+               return -ENODEV;
+       case S2255_FW_DISCONNECTING:
+               printk(KERN_INFO "%s: disconnecting\n", __func__);
                mutex_unlock(&dev->open_lock);
-               kref_put(&dev->kref, s2255_destroy);
-               unlock_kernel();
-               return rc;
+               return -ENODEV;
+       case S2255_FW_LOADED_DSPWAIT:
+       case S2255_FW_NOTLOADED:
+               printk(KERN_INFO "%s: firmware not loaded yet"
+                      "please try again later\n",
+                      __func__);
+               /*
+                * Timeout on firmware load means device unusable.
+                * Set firmware failure state.
+                * On next s2255_open the firmware will be reloaded.
+                */
+               atomic_set(&dev->fw_data->fw_state,
+                          S2255_FW_FAILED);
+               mutex_unlock(&dev->open_lock);
+               return -EAGAIN;
+       default:
+               printk(KERN_INFO "%s: unknown state\n", __func__);
+               mutex_unlock(&dev->open_lock);
+               return -EFAULT;
        }
-
+       mutex_unlock(&dev->open_lock);
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh), GFP_KERNEL);
-       if (NULL == fh) {
-               dev->users[cur_channel]--;
-               mutex_unlock(&dev->open_lock);
-               kref_put(&dev->kref, s2255_destroy);
-               unlock_kernel();
+       if (NULL == fh)
                return -ENOMEM;
-       }
-
        file->private_data = fh;
        fh->dev = dev;
        fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -1640,35 +1812,23 @@ static int s2255_open(struct file *file)
        fh->width = LINE_SZ_4CIFS_NTSC;
        fh->height = NUM_LINES_4CIFS_NTSC * 2;
        fh->channel = cur_channel;
-
        /* configure channel to default state */
        if (!dev->chn_configured[cur_channel]) {
                s2255_set_mode(dev, cur_channel, &fh->mode);
                dev->chn_configured[cur_channel] = 1;
        }
-
-
-       /* Put all controls at a sane state */
-       for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++)
-               qctl_regs[i] = s2255_qctrl[i].default_value;
-
-       dprintk(1, "s2255drv: open dev=%s type=%s users=%d\n",
-               video_device_node_name(vdev), v4l2_type_names[type],
-               dev->users[cur_channel]);
-       dprintk(2, "s2255drv: open: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n",
+       dprintk(1, "%s: dev=%s type=%s\n", __func__,
+               video_device_node_name(vdev), v4l2_type_names[type]);
+       dprintk(2, "%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__,
                (unsigned long)fh, (unsigned long)dev,
                (unsigned long)&dev->vidq[cur_channel]);
-       dprintk(4, "s2255drv: open: list_empty active=%d\n",
+       dprintk(4, "%s: list_empty active=%d\n", __func__,
                list_empty(&dev->vidq[cur_channel].active));
-
        videobuf_queue_vmalloc_init(&fh->vb_vidq, &s2255_video_qops,
                                    NULL, &dev->slock,
                                    fh->type,
                                    V4L2_FIELD_INTERLACED,
                                    sizeof(struct s2255_buffer), fh);
-
-       mutex_unlock(&dev->open_lock);
-       unlock_kernel();
        return 0;
 }
 
@@ -1679,39 +1839,19 @@ static unsigned int s2255_poll(struct file *file,
        struct s2255_fh *fh = file->private_data;
        int rc;
        dprintk(100, "%s\n", __func__);
-
        if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
                return POLLERR;
-
        rc = videobuf_poll_stream(file, &fh->vb_vidq, wait);
        return rc;
 }
 
-static void s2255_destroy(struct kref *kref)
+static void s2255_destroy(struct s2255_dev *dev)
 {
-       struct s2255_dev *dev = to_s2255_dev(kref);
-       int i;
-       if (!dev) {
-               printk(KERN_ERR "s2255drv: kref problem\n");
-               return;
-       }
-       atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
-       wake_up(&dev->fw_data->wait_fw);
-       for (i = 0; i < MAX_CHANNELS; i++) {
-               dev->setmode_ready[i] = 1;
-               wake_up(&dev->wait_setmode[i]);
-       }
-       mutex_lock(&dev->open_lock);
-       /* reset the DSP so firmware can be reload next time */
-       s2255_reset_dsppower(dev);
-       s2255_exit_v4l(dev);
        /* board shutdown stops the read pipe if it is running */
        s2255_board_shutdown(dev);
        /* make sure firmware still not trying to load */
        del_timer(&dev->timer);  /* only started in .probe and .open */
-
        if (dev->fw_data->fw_urb) {
-               dprintk(2, "kill fw_urb\n");
                usb_kill_urb(dev->fw_data->fw_urb);
                usb_free_urb(dev->fw_data->fw_urb);
                dev->fw_data->fw_urb = NULL;
@@ -1720,24 +1860,22 @@ static void s2255_destroy(struct kref *kref)
                release_firmware(dev->fw_data->fw);
        kfree(dev->fw_data->pfw_data);
        kfree(dev->fw_data);
+       /* reset the DSP so firmware can be reloaded next time */
+       s2255_reset_dsppower(dev);
+       mutex_destroy(&dev->open_lock);
+       mutex_destroy(&dev->lock);
        usb_put_dev(dev->udev);
        dprintk(1, "%s", __func__);
-
-       mutex_unlock(&dev->open_lock);
        kfree(dev);
 }
 
-static int s2255_close(struct file *file)
+static int s2255_release(struct file *file)
 {
        struct s2255_fh *fh = file->private_data;
        struct s2255_dev *dev = fh->dev;
        struct video_device *vdev = video_devdata(file);
-
        if (!dev)
                return -ENODEV;
-
-       mutex_lock(&dev->open_lock);
-
        /* turn off stream */
        if (res_check(fh)) {
                if (dev->b_acquire[fh->channel])
@@ -1745,15 +1883,8 @@ static int s2255_close(struct file *file)
                videobuf_streamoff(&fh->vb_vidq);
                res_free(dev, fh);
        }
-
        videobuf_mmap_free(&fh->vb_vidq);
-       dev->users[fh->channel]--;
-
-       mutex_unlock(&dev->open_lock);
-
-       kref_put(&dev->kref, s2255_destroy);
-       dprintk(1, "s2255: close called (dev=%s, users=%d)\n",
-               video_device_node_name(vdev), dev->users[fh->channel]);
+       dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev));
        kfree(fh);
        return 0;
 }
@@ -1765,27 +1896,25 @@ static int s2255_mmap_v4l(struct file *file, struct vm_area_struct *vma)
 
        if (!fh)
                return -ENODEV;
-       dprintk(4, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
-
+       dprintk(4, "%s, vma=0x%08lx\n", __func__, (unsigned long)vma);
        ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
-
-       dprintk(4, "vma start=0x%08lx, size=%ld, ret=%d\n",
+       dprintk(4, "%s vma start=0x%08lx, size=%ld, ret=%d\n", __func__,
                (unsigned long)vma->vm_start,
                (unsigned long)vma->vm_end - (unsigned long)vma->vm_start, ret);
-
        return ret;
 }
 
 static const struct v4l2_file_operations s2255_fops_v4l = {
        .owner = THIS_MODULE,
        .open = s2255_open,
-       .release = s2255_close,
+       .release = s2255_release,
        .poll = s2255_poll,
        .ioctl = video_ioctl2,  /* V4L2 ioctl handler */
        .mmap = s2255_mmap_v4l,
 };
 
 static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
+       .vidioc_querymenu = vidioc_querymenu,
        .vidioc_querycap = vidioc_querycap,
        .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
        .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1811,13 +1940,23 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
        .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
        .vidioc_s_parm = vidioc_s_parm,
        .vidioc_g_parm = vidioc_g_parm,
+       .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
 };
 
+static void s2255_video_device_release(struct video_device *vdev)
+{
+       struct s2255_dev *dev = video_get_drvdata(vdev);
+       dprintk(4, "%s, chnls: %d \n", __func__, atomic_read(&dev->channels));
+       if (atomic_dec_and_test(&dev->channels))
+               s2255_destroy(dev);
+       return;
+}
+
 static struct video_device template = {
        .name = "s2255v",
        .fops = &s2255_fops_v4l,
        .ioctl_ops = &s2255_ioctl_ops,
-       .release = video_device_release,
+       .release = s2255_video_device_release,
        .tvnorms = S2255_NORMS,
        .current_norm = V4L2_STD_NTSC_M,
 };
@@ -1827,7 +1966,9 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
        int ret;
        int i;
        int cur_nr = video_nr;
-
+       ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev);
+       if (ret)
+               return ret;
        /* initialize all video 4 linux */
        /* register 4 video devices */
        for (i = 0; i < MAX_CHANNELS; i++) {
@@ -1835,45 +1976,39 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
                dev->vidq[i].dev = dev;
                dev->vidq[i].channel = i;
                /* register 4 video devices */
-               dev->vdev[i] = video_device_alloc();
-               memcpy(dev->vdev[i], &template, sizeof(struct video_device));
-               dev->vdev[i]->parent = &dev->interface->dev;
-               video_set_drvdata(dev->vdev[i], dev);
+               memcpy(&dev->vdev[i], &template, sizeof(struct video_device));
+               dev->vdev[i].v4l2_dev = &dev->v4l2_dev;
+               video_set_drvdata(&dev->vdev[i], dev);
                if (video_nr == -1)
-                       ret = video_register_device(dev->vdev[i],
+                       ret = video_register_device(&dev->vdev[i],
                                                    VFL_TYPE_GRABBER,
                                                    video_nr);
                else
-                       ret = video_register_device(dev->vdev[i],
+                       ret = video_register_device(&dev->vdev[i],
                                                    VFL_TYPE_GRABBER,
                                                    cur_nr + i);
-               video_set_drvdata(dev->vdev[i], dev);
-
-               if (ret != 0) {
+               if (ret) {
                        dev_err(&dev->udev->dev,
                                "failed to register video device!\n");
-                       return ret;
+                       break;
                }
+               atomic_inc(&dev->channels);
+               v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n",
+                         video_device_node_name(&dev->vdev[i]));
+
        }
+
        printk(KERN_INFO "Sensoray 2255 V4L driver Revision: %d.%d\n",
               S2255_MAJOR_VERSION,
               S2255_MINOR_VERSION);
-       return ret;
-}
-
-static void s2255_exit_v4l(struct s2255_dev *dev)
-{
-
-       int i;
-       for (i = 0; i < MAX_CHANNELS; i++) {
-               if (video_is_registered(dev->vdev[i])) {
-                       video_unregister_device(dev->vdev[i]);
-                       printk(KERN_INFO "s2255 unregistered\n");
-               } else {
-                       video_device_release(dev->vdev[i]);
-                       printk(KERN_INFO "s2255 released\n");
-               }
+       /* if no channels registered, return error and probe will fail*/
+       if (atomic_read(&dev->channels) == 0) {
+               v4l2_device_unregister(&dev->v4l2_dev);
+               return ret;
        }
+       if (atomic_read(&dev->channels) != MAX_CHANNELS)
+               printk(KERN_WARNING "s2255: Not all channels available.\n");
+       return 0;
 }
 
 /* this function moves the usb stream read pipe data
@@ -1907,14 +2042,14 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
        if (frm->ulState == S2255_READ_IDLE) {
                int jj;
                unsigned int cc;
-               s32 *pdword;
+               __le32 *pdword; /*data from dsp is little endian */
                int payload;
                /* search for marker codes */
                pdata = (unsigned char *)pipe_info->transfer_buffer;
+               pdword = (__le32 *)pdata;
                for (jj = 0; jj < (pipe_info->cur_transfer_size - 12); jj++) {
-                       switch (*(s32 *) pdata) {
+                       switch (*pdword) {
                        case S2255_MARKER_FRAME:
-                               pdword = (s32 *)pdata;
                                dprintk(4, "found frame marker at offset:"
                                        " %d [%x %x]\n", jj, pdata[0],
                                        pdata[1]);
@@ -1938,7 +2073,6 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
                                dev->jpg_size[dev->cc] = pdword[4];
                                break;
                        case S2255_MARKER_RESPONSE:
-                               pdword = (s32 *)pdata;
                                pdata += DEF_USB_BLOCK;
                                jj += DEF_USB_BLOCK;
                                if (pdword[1] >= MAX_CHANNELS)
@@ -1955,7 +2089,6 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
                                        dprintk(5, "setmode ready %d\n", cc);
                                        break;
                                case S2255_RESPONSE_FW:
-
                                        dev->chn_ready |= (1 << cc);
                                        if ((dev->chn_ready & 0x0f) != 0x0f)
                                                break;
@@ -1965,6 +2098,13 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
                                                   S2255_FW_SUCCESS);
                                        wake_up(&dev->fw_data->wait_fw);
                                        break;
+                               case S2255_RESPONSE_STATUS:
+                                       dev->vidstatus[cc] = pdword[3];
+                                       dev->vidstatus_ready[cc] = 1;
+                                       wake_up(&dev->wait_vidstatus[cc]);
+                                       dprintk(5, "got vidstatus %x chan %d\n",
+                                               pdword[3], cc);
+                                       break;
                                default:
                                        printk(KERN_INFO "s2255 unknown resp\n");
                                }
@@ -2165,28 +2305,22 @@ static int s2255_release_sys_buffers(struct s2255_dev *dev,
 
 static int s2255_board_init(struct s2255_dev *dev)
 {
-       int j;
        struct s2255_mode mode_def = DEF_MODEI_NTSC_CONT;
        int fw_ver;
+       int j;
+       struct s2255_pipeinfo *pipe = &dev->pipe;
        dprintk(4, "board init: %p", dev);
-
-       for (j = 0; j < MAX_PIPE_BUFFERS; j++) {
-               struct s2255_pipeinfo *pipe = &dev->pipes[j];
-
-               memset(pipe, 0, sizeof(*pipe));
-               pipe->dev = dev;
-               pipe->cur_transfer_size = S2255_USB_XFER_SIZE;
-               pipe->max_transfer_size = S2255_USB_XFER_SIZE;
-
-               pipe->transfer_buffer = kzalloc(pipe->max_transfer_size,
-                                               GFP_KERNEL);
-               if (pipe->transfer_buffer == NULL) {
-                       dprintk(1, "out of memory!\n");
-                       return -ENOMEM;
-               }
-
+       memset(pipe, 0, sizeof(*pipe));
+       pipe->dev = dev;
+       pipe->cur_transfer_size = S2255_USB_XFER_SIZE;
+       pipe->max_transfer_size = S2255_USB_XFER_SIZE;
+
+       pipe->transfer_buffer = kzalloc(pipe->max_transfer_size,
+                                       GFP_KERNEL);
+       if (pipe->transfer_buffer == NULL) {
+               dprintk(1, "out of memory!\n");
+               return -ENOMEM;
        }
-
        /* query the firmware */
        fw_ver = s2255_get_fx2fw(dev);
 
@@ -2203,6 +2337,8 @@ static int s2255_board_init(struct s2255_dev *dev)
        for (j = 0; j < MAX_CHANNELS; j++) {
                dev->b_acquire[j] = 0;
                dev->mode[j] = mode_def;
+               if (dev->pid == 0x2257 && j > 1)
+                       dev->mode[j].color |= (1 << 16);
                dev->jc[j].quality = S2255_DEF_JPEG_QUAL;
                dev->cur_fmt[j] = &formats[0];
                dev->mode[j].restart = 1;
@@ -2213,16 +2349,14 @@ static int s2255_board_init(struct s2255_dev *dev)
        }
        /* start read pipe */
        s2255_start_readpipe(dev);
-
-       dprintk(1, "S2255: board initialized\n");
+       dprintk(1, "%s: success\n", __func__);
        return 0;
 }
 
 static int s2255_board_shutdown(struct s2255_dev *dev)
 {
        u32 i;
-
-       dprintk(1, "S2255: board shutdown: %p", dev);
+       dprintk(1, "%s: dev: %p", __func__,  dev);
 
        for (i = 0; i < MAX_CHANNELS; i++) {
                if (dev->b_acquire[i])
@@ -2233,12 +2367,8 @@ static int s2255_board_shutdown(struct s2255_dev *dev)
 
        for (i = 0; i < MAX_CHANNELS; i++)
                s2255_release_sys_buffers(dev, i);
-
-       /* release transfer buffers */
-       for (i = 0; i < MAX_PIPE_BUFFERS; i++) {
-               struct s2255_pipeinfo *pipe = &dev->pipes[i];
-               kfree(pipe->transfer_buffer);
-       }
+       /* release transfer buffer */
+       kfree(dev->pipe.transfer_buffer);
        return 0;
 }
 
@@ -2248,9 +2378,8 @@ static void read_pipe_completion(struct urb *purb)
        struct s2255_dev *dev;
        int status;
        int pipe;
-
        pipe_info = purb->context;
-       dprintk(100, "read pipe completion %p, status %d\n", purb,
+       dprintk(100, "%s: urb:%p, status %d\n", __func__, purb,
                purb->status);
        if (pipe_info == NULL) {
                dev_err(&purb->dev->dev, "no context!\n");
@@ -2265,13 +2394,13 @@ static void read_pipe_completion(struct urb *purb)
        status = purb->status;
        /* if shutting down, do not resubmit, exit immediately */
        if (status == -ESHUTDOWN) {
-               dprintk(2, "read_pipe_completion: err shutdown\n");
+               dprintk(2, "%s: err shutdown\n", __func__);
                pipe_info->err_count++;
                return;
        }
 
        if (pipe_info->state == 0) {
-               dprintk(2, "exiting USB pipe");
+               dprintk(2, "%s: exiting USB pipe", __func__);
                return;
        }
 
@@ -2279,7 +2408,7 @@ static void read_pipe_completion(struct urb *purb)
                s2255_read_video_callback(dev, pipe_info);
        else {
                pipe_info->err_count++;
-               dprintk(1, "s2255drv: failed URB %d\n", status);
+               dprintk(1, "%s: failed URB %d\n", __func__, status);
        }
 
        pipe = usb_rcvbulkpipe(dev->udev, dev->read_endpoint);
@@ -2295,7 +2424,7 @@ static void read_pipe_completion(struct urb *purb)
                        dev_err(&dev->udev->dev, "error submitting urb\n");
                }
        } else {
-               dprintk(2, "read pipe complete state 0\n");
+               dprintk(2, "%s :complete state 0\n", __func__);
        }
        return;
 }
@@ -2304,35 +2433,28 @@ static int s2255_start_readpipe(struct s2255_dev *dev)
 {
        int pipe;
        int retval;
-       int i;
-       struct s2255_pipeinfo *pipe_info = dev->pipes;
+       struct s2255_pipeinfo *pipe_info = &dev->pipe;
        pipe = usb_rcvbulkpipe(dev->udev, dev->read_endpoint);
-       dprintk(2, "start pipe IN %d\n", dev->read_endpoint);
-
-       for (i = 0; i < MAX_PIPE_BUFFERS; i++) {
-               pipe_info->state = 1;
-               pipe_info->err_count = 0;
-               pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
-               if (!pipe_info->stream_urb) {
-                       dev_err(&dev->udev->dev,
-                               "ReadStream: Unable to alloc URB\n");
-                       return -ENOMEM;
-               }
-               /* transfer buffer allocated in board_init */
-               usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev,
-                                 pipe,
-                                 pipe_info->transfer_buffer,
-                                 pipe_info->cur_transfer_size,
-                                 read_pipe_completion, pipe_info);
-
-               dprintk(4, "submitting URB %p\n", pipe_info->stream_urb);
-               retval = usb_submit_urb(pipe_info->stream_urb, GFP_KERNEL);
-               if (retval) {
-                       printk(KERN_ERR "s2255: start read pipe failed\n");
-                       return retval;
-               }
+       dprintk(2, "%s: IN %d\n", __func__, dev->read_endpoint);
+       pipe_info->state = 1;
+       pipe_info->err_count = 0;
+       pipe_info->stream_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (!pipe_info->stream_urb) {
+               dev_err(&dev->udev->dev,
+                       "ReadStream: Unable to alloc URB\n");
+               return -ENOMEM;
+       }
+       /* transfer buffer allocated in board_init */
+       usb_fill_bulk_urb(pipe_info->stream_urb, dev->udev,
+                         pipe,
+                         pipe_info->transfer_buffer,
+                         pipe_info->cur_transfer_size,
+                         read_pipe_completion, pipe_info);
+       retval = usb_submit_urb(pipe_info->stream_urb, GFP_KERNEL);
+       if (retval) {
+               printk(KERN_ERR "s2255: start read pipe failed\n");
+               return retval;
        }
-
        return 0;
 }
 
@@ -2347,10 +2469,7 @@ static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn)
                dprintk(2, "start acquire failed, bad channel %lu\n", chn);
                return -1;
        }
-
        chn_rev = G_chnmap[chn];
-       dprintk(1, "S2255: start acquire %lu \n", chn);
-
        buffer = kzalloc(512, GFP_KERNEL);
        if (buffer == NULL) {
                dev_err(&dev->udev->dev, "out of mem\n");
@@ -2366,9 +2485,9 @@ static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn)
        }
 
        /* send the start command */
-       *(u32 *) buffer = IN_DATA_TOKEN;
-       *((u32 *) buffer + 1) = (u32) chn_rev;
-       *((u32 *) buffer + 2) = (u32) CMD_START;
+       *(__le32 *) buffer = IN_DATA_TOKEN;
+       *((__le32 *) buffer + 1) = (__le32) cpu_to_le32(chn_rev);
+       *((__le32 *) buffer + 2) = CMD_START;
        res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
        if (res != 0)
                dev_err(&dev->udev->dev, "CMD_START error\n");
@@ -2383,65 +2502,41 @@ static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn)
        unsigned char *buffer;
        int res;
        unsigned long chn_rev;
-
        if (chn >= MAX_CHANNELS) {
                dprintk(2, "stop acquire failed, bad channel %lu\n", chn);
                return -1;
        }
        chn_rev = G_chnmap[chn];
-
        buffer = kzalloc(512, GFP_KERNEL);
        if (buffer == NULL) {
                dev_err(&dev->udev->dev, "out of mem\n");
                return -ENOMEM;
        }
-
        /* send the stop command */
-       dprintk(4, "stop acquire %lu\n", chn);
-       *(u32 *) buffer = IN_DATA_TOKEN;
-       *((u32 *) buffer + 1) = (u32) chn_rev;
-       *((u32 *) buffer + 2) = CMD_STOP;
+       *(__le32 *) buffer = IN_DATA_TOKEN;
+       *((__le32 *) buffer + 1) = (__le32) cpu_to_le32(chn_rev);
+       *((__le32 *) buffer + 2) = CMD_STOP;
        res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512);
-
        if (res != 0)
                dev_err(&dev->udev->dev, "CMD_STOP error\n");
-
-       dprintk(4, "stop acquire: releasing states \n");
-
        kfree(buffer);
        dev->b_acquire[chn] = 0;
-
+       dprintk(4, "%s: chn %lu, res %d\n", __func__, chn, res);
        return res;
 }
 
 static void s2255_stop_readpipe(struct s2255_dev *dev)
 {
-       int j;
-
-       if (dev == NULL) {
-               s2255_dev_err(&dev->udev->dev, "invalid device\n");
-               return;
-       }
-       dprintk(4, "stop read pipe\n");
-       for (j = 0; j < MAX_PIPE_BUFFERS; j++) {
-               struct s2255_pipeinfo *pipe_info = &dev->pipes[j];
-               if (pipe_info) {
-                       if (pipe_info->state == 0)
-                               continue;
-                       pipe_info->state = 0;
-               }
-       }
+       struct s2255_pipeinfo *pipe = &dev->pipe;
 
-       for (j = 0; j < MAX_PIPE_BUFFERS; j++) {
-               struct s2255_pipeinfo *pipe_info = &dev->pipes[j];
-               if (pipe_info->stream_urb) {
-                       /* cancel urb */
-                       usb_kill_urb(pipe_info->stream_urb);
-                       usb_free_urb(pipe_info->stream_urb);
-                       pipe_info->stream_urb = NULL;
-               }
+       pipe->state = 0;
+       if (pipe->stream_urb) {
+               /* cancel urb */
+               usb_kill_urb(pipe->stream_urb);
+               usb_free_urb(pipe->stream_urb);
+               pipe->stream_urb = NULL;
        }
-       dprintk(2, "s2255 stop read pipe: %d\n", j);
+       dprintk(4, "%s", __func__);
        return;
 }
 
@@ -2473,32 +2568,28 @@ static int s2255_probe(struct usb_interface *interface,
        int retval = -ENOMEM;
        __le32 *pdata;
        int fw_size;
-
-       dprintk(2, "s2255: probe\n");
-
+       dprintk(2, "%s\n", __func__);
        /* allocate memory for our device state and initialize it to zero */
        dev = kzalloc(sizeof(struct s2255_dev), GFP_KERNEL);
        if (dev == NULL) {
                s2255_dev_err(&interface->dev, "out of memory\n");
-               goto error;
+               return -ENOMEM;
        }
-
+       atomic_set(&dev->channels, 0);
+       dev->pid = id->idProduct;
        dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL);
        if (!dev->fw_data)
-               goto error;
-
+               goto errorFWDATA1;
        mutex_init(&dev->lock);
        mutex_init(&dev->open_lock);
-
        /* grab usb_device and save it */
        dev->udev = usb_get_dev(interface_to_usbdev(interface));
        if (dev->udev == NULL) {
                dev_err(&interface->dev, "null usb device\n");
                retval = -ENODEV;
-               goto error;
+               goto errorUDEV;
        }
-       kref_init(&dev->kref);
-       dprintk(1, "dev: %p, kref: %p udev %p interface %p\n", dev, &dev->kref,
+       dprintk(1, "dev: %p, udev %p interface %p\n", dev,
                dev->udev, interface);
        dev->interface = interface;
        /* set up the endpoint information  */
@@ -2514,39 +2605,33 @@ static int s2255_probe(struct usb_interface *interface,
 
        if (!dev->read_endpoint) {
                dev_err(&interface->dev, "Could not find bulk-in endpoint\n");
-               goto error;
+               goto errorEP;
        }
-
-       /* set intfdata */
-       usb_set_intfdata(interface, dev);
-
-       dprintk(100, "after intfdata %p\n", dev);
-
        init_timer(&dev->timer);
        dev->timer.function = s2255_timer;
        dev->timer.data = (unsigned long)dev->fw_data;
-
        init_waitqueue_head(&dev->fw_data->wait_fw);
-       for (i = 0; i < MAX_CHANNELS; i++)
+       for (i = 0; i < MAX_CHANNELS; i++) {
                init_waitqueue_head(&dev->wait_setmode[i]);
-
+               init_waitqueue_head(&dev->wait_vidstatus[i]);
+       }
 
        dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL);
-
        if (!dev->fw_data->fw_urb) {
                dev_err(&interface->dev, "out of memory!\n");
-               goto error;
+               goto errorFWURB;
        }
+
        dev->fw_data->pfw_data = kzalloc(CHUNK_SIZE, GFP_KERNEL);
        if (!dev->fw_data->pfw_data) {
                dev_err(&interface->dev, "out of memory!\n");
-               goto error;
+               goto errorFWDATA2;
        }
        /* load the first chunk */
        if (request_firmware(&dev->fw_data->fw,
                             FIRMWARE_FILE_NAME, &dev->udev->dev)) {
                printk(KERN_ERR "sensoray 2255 failed to get firmware\n");
-               goto error;
+               goto errorREQFW;
        }
        /* check the firmware is valid */
        fw_size = dev->fw_data->fw->size;
@@ -2555,59 +2640,80 @@ static int s2255_probe(struct usb_interface *interface,
        if (*pdata != S2255_FW_MARKER) {
                printk(KERN_INFO "Firmware invalid.\n");
                retval = -ENODEV;
-               goto error;
+               goto errorFWMARKER;
        } else {
                /* make sure firmware is the latest */
                __le32 *pRel;
                pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4];
                printk(KERN_INFO "s2255 dsp fw version %x\n", *pRel);
+               dev->dsp_fw_ver = *pRel;
+               if (*pRel < S2255_CUR_DSP_FWVER)
+                       printk(KERN_INFO "s2255: f2255usb.bin out of date.\n");
+               if (dev->pid == 0x2257 && *pRel < S2255_MIN_DSP_COLORFILTER)
+                       printk(KERN_WARNING "s2255: 2257 requires firmware %d"
+                              "or above.\n", S2255_MIN_DSP_COLORFILTER);
        }
-       /* loads v4l specific */
-       s2255_probe_v4l(dev);
        usb_reset_device(dev->udev);
        /* load 2255 board specific */
        retval = s2255_board_init(dev);
        if (retval)
-               goto error;
-
-       dprintk(4, "before probe done %p\n", dev);
+               goto errorBOARDINIT;
        spin_lock_init(&dev->slock);
-
        s2255_fwload_start(dev, 0);
+       /* loads v4l specific */
+       retval = s2255_probe_v4l(dev);
+       if (retval)
+               goto errorBOARDINIT;
        dev_info(&interface->dev, "Sensoray 2255 detected\n");
        return 0;
-error:
+errorBOARDINIT:
+       s2255_board_shutdown(dev);
+errorFWMARKER:
+       release_firmware(dev->fw_data->fw);
+errorREQFW:
+       kfree(dev->fw_data->pfw_data);
+errorFWDATA2:
+       usb_free_urb(dev->fw_data->fw_urb);
+errorFWURB:
+       del_timer(&dev->timer);
+errorEP:
+       usb_put_dev(dev->udev);
+errorUDEV:
+       kfree(dev->fw_data);
+       mutex_destroy(&dev->open_lock);
+       mutex_destroy(&dev->lock);
+errorFWDATA1:
+       kfree(dev);
+       printk(KERN_WARNING "Sensoray 2255 driver load failed: 0x%x\n", retval);
        return retval;
 }
 
 /* disconnect routine. when board is removed physically or with rmmod */
 static void s2255_disconnect(struct usb_interface *interface)
 {
-       struct s2255_dev *dev = NULL;
+       struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface));
        int i;
-       dprintk(1, "s2255: disconnect interface %p\n", interface);
-       dev = usb_get_intfdata(interface);
-
-       /*
-        * wake up any of the timers to allow open_lock to be
-        * acquired sooner
-        */
+       int channels = atomic_read(&dev->channels);
+       v4l2_device_unregister(&dev->v4l2_dev);
+       /*see comments in the uvc_driver.c usb disconnect function */
+       atomic_inc(&dev->channels);
+       /* unregister each video device. */
+       for (i = 0; i < channels; i++) {
+               if (video_is_registered(&dev->vdev[i]))
+                       video_unregister_device(&dev->vdev[i]);
+       }
+       /* wake up any of our timers */
        atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
        wake_up(&dev->fw_data->wait_fw);
        for (i = 0; i < MAX_CHANNELS; i++) {
                dev->setmode_ready[i] = 1;
                wake_up(&dev->wait_setmode[i]);
+               dev->vidstatus_ready[i] = 1;
+               wake_up(&dev->wait_vidstatus[i]);
        }
-
-       mutex_lock(&dev->open_lock);
-       usb_set_intfdata(interface, NULL);
-       mutex_unlock(&dev->open_lock);
-
-       if (dev) {
-               kref_put(&dev->kref, s2255_destroy);
-               dprintk(1, "s2255drv: disconnect\n");
-               dev_info(&interface->dev, "s2255usb now disconnected\n");
-       }
+       if (atomic_dec_and_test(&dev->channels))
+               s2255_destroy(dev);
+       dev_info(&interface->dev, "%s\n", __func__);
 }
 
 static struct usb_driver s2255_driver = {
@@ -2620,15 +2726,12 @@ static struct usb_driver s2255_driver = {
 static int __init usb_s2255_init(void)
 {
        int result;
-
        /* register this driver with the USB subsystem */
        result = usb_register(&s2255_driver);
-
        if (result)
                pr_err(KBUILD_MODNAME
-                       ": usb_register failed. Error number %d\n", result);
-
-       dprintk(2, "s2255_init: done\n");
+                      ": usb_register failed. Error number %d\n", result);
+       dprintk(2, "%s\n", __func__);
        return result;
 }
 
index c0a7f8a..53b6fcd 100644 (file)
@@ -74,6 +74,7 @@ struct saa711x_state {
        int contrast;
        int hue;
        int sat;
+       int chroma_agc;
        int width;
        int height;
        u32 ident;
@@ -592,7 +593,7 @@ static const unsigned char saa7115_init_misc[] = {
        R_5D_DID, 0xbd,
        R_5E_SDID, 0x35,
 
-       R_02_INPUT_CNTL_1, 0x84,                /* input tuner -> input 4, amplifier active */
+       R_02_INPUT_CNTL_1, 0xc4, /* input tuner -> input 4, amplifier active */
 
        R_80_GLOBAL_CNTL_1, 0x20,               /* enable task B */
        R_88_POWER_SAVE_ADC_PORT_CNTL, 0xd0,
@@ -743,6 +744,7 @@ static int saa711x_s_clock_freq(struct v4l2_subdev *sd, u32 freq)
 static int saa711x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 {
        struct saa711x_state *state = to_state(sd);
+       u8 val;
 
        switch (ctrl->id) {
        case V4L2_CID_BRIGHTNESS:
@@ -784,7 +786,21 @@ static int saa711x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
                state->hue = ctrl->value;
                saa711x_write(sd, R_0D_CHROMA_HUE_CNTL, state->hue);
                break;
-
+       case V4L2_CID_CHROMA_AGC:
+               val = saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL);
+               state->chroma_agc = ctrl->value;
+               if (ctrl->value)
+                       val &= 0x7f;
+               else
+                       val |= 0x80;
+               saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, val);
+               break;
+       case V4L2_CID_CHROMA_GAIN:
+               /* Chroma gain cannot be set when AGC is enabled */
+               if (state->chroma_agc == 1)
+                       return -EINVAL;
+               saa711x_write(sd, R_0F_CHROMA_GAIN_CNTL, ctrl->value | 0x80);
+               break;
        default:
                return -EINVAL;
        }
@@ -809,6 +825,12 @@ static int saa711x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
        case V4L2_CID_HUE:
                ctrl->value = state->hue;
                break;
+       case V4L2_CID_CHROMA_AGC:
+               ctrl->value = state->chroma_agc;
+               break;
+       case V4L2_CID_CHROMA_GAIN:
+               ctrl->value = saa711x_read(sd, R_0F_CHROMA_GAIN_CNTL) & 0x7f;
+               break;
        default:
                return -EINVAL;
        }
@@ -1069,7 +1091,7 @@ static void saa711x_set_lcr(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_forma
                                saa7115_cfg_vbi_off);
 }
 
-static int saa711x_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+static int saa711x_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *sliced)
 {
        static u16 lcr2vbi[] = {
                0, V4L2_SLICED_TELETEXT_B, 0,   /* 1 */
@@ -1078,11 +1100,8 @@ static int saa711x_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
                V4L2_SLICED_VPS, 0, 0, 0, 0,    /* 7 */
                0, 0, 0, 0
        };
-       struct v4l2_sliced_vbi_format *sliced = &fmt->fmt.sliced;
        int i;
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
-               return -EINVAL;
        memset(sliced, 0, sizeof(*sliced));
        /* done if using raw VBI */
        if (saa711x_read(sd, R_80_GLOBAL_CNTL_1) & 0x10)
@@ -1098,16 +1117,27 @@ static int saa711x_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        return 0;
 }
 
+static int saa711x_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+{
+       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+               return -EINVAL;
+       return saa711x_g_sliced_fmt(sd, &fmt->fmt.sliced);
+}
+
+static int saa711x_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
+{
+       saa711x_set_lcr(sd, NULL);
+       return 0;
+}
+
+static int saa711x_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt)
+{
+       saa711x_set_lcr(sd, fmt);
+       return 0;
+}
+
 static int saa711x_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
 {
-       if (fmt->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
-               saa711x_set_lcr(sd, &fmt->fmt.sliced);
-               return 0;
-       }
-       if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-               saa711x_set_lcr(sd, NULL);
-               return 0;
-       }
        if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
 
@@ -1209,6 +1239,10 @@ static int saa711x_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
                return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64);
        case V4L2_CID_HUE:
                return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
+       case V4L2_CID_CHROMA_AGC:
+               return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
+       case V4L2_CID_CHROMA_GAIN:
+               return v4l2_ctrl_query_fill(qc, 0, 127, 1, 48);
        default:
                return -EINVAL;
        }
@@ -1524,18 +1558,25 @@ static const struct v4l2_subdev_video_ops saa711x_video_ops = {
        .s_crystal_freq = saa711x_s_crystal_freq,
        .g_fmt = saa711x_g_fmt,
        .s_fmt = saa711x_s_fmt,
-       .g_vbi_data = saa711x_g_vbi_data,
-       .decode_vbi_line = saa711x_decode_vbi_line,
        .s_stream = saa711x_s_stream,
        .querystd = saa711x_querystd,
        .g_input_status = saa711x_g_input_status,
 };
 
+static const struct v4l2_subdev_vbi_ops saa711x_vbi_ops = {
+       .g_vbi_data = saa711x_g_vbi_data,
+       .decode_vbi_line = saa711x_decode_vbi_line,
+       .g_sliced_fmt = saa711x_g_sliced_fmt,
+       .s_sliced_fmt = saa711x_s_sliced_fmt,
+       .s_raw_fmt = saa711x_s_raw_fmt,
+};
+
 static const struct v4l2_subdev_ops saa711x_ops = {
        .core = &saa711x_core_ops,
        .tuner = &saa711x_tuner_ops,
        .audio = &saa711x_audio_ops,
        .video = &saa711x_video_ops,
+       .vbi = &saa711x_vbi_ops,
 };
 
 /* ----------------------------------------------------------------------- */
@@ -1593,6 +1634,7 @@ static int saa711x_probe(struct i2c_client *client,
        state->contrast = 64;
        state->hue = 0;
        state->sat = 64;
+       state->chroma_agc = 1;
        switch (chip_id) {
        case '1':
                state->ident = V4L2_IDENT_SAA7111;
index 250ef84..87986ad 100644 (file)
@@ -625,29 +625,33 @@ static int saa7127_s_stream(struct v4l2_subdev *sd, int enable)
        return saa7127_set_video_enable(sd, enable);
 }
 
-static int saa7127_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+static int saa7127_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt)
 {
        struct saa7127_state *state = to_state(sd);
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
-               return -EINVAL;
-
-       memset(&fmt->fmt.sliced, 0, sizeof(fmt->fmt.sliced));
+       memset(fmt, 0, sizeof(*fmt));
        if (state->vps_enable)
-               fmt->fmt.sliced.service_lines[0][16] = V4L2_SLICED_VPS;
+               fmt->service_lines[0][16] = V4L2_SLICED_VPS;
        if (state->wss_enable)
-               fmt->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
+               fmt->service_lines[0][23] = V4L2_SLICED_WSS_625;
        if (state->cc_enable) {
-               fmt->fmt.sliced.service_lines[0][21] = V4L2_SLICED_CAPTION_525;
-               fmt->fmt.sliced.service_lines[1][21] = V4L2_SLICED_CAPTION_525;
+               fmt->service_lines[0][21] = V4L2_SLICED_CAPTION_525;
+               fmt->service_lines[1][21] = V4L2_SLICED_CAPTION_525;
        }
-       fmt->fmt.sliced.service_set =
+       fmt->service_set =
                (state->vps_enable ? V4L2_SLICED_VPS : 0) |
                (state->wss_enable ? V4L2_SLICED_WSS_625 : 0) |
                (state->cc_enable ? V4L2_SLICED_CAPTION_525 : 0);
        return 0;
 }
 
+static int saa7127_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+{
+       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+               return -EINVAL;
+       return saa7127_g_sliced_fmt(sd, &fmt->fmt.sliced);
+}
+
 static int saa7127_s_vbi_data(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *data)
 {
        switch (data->id) {
@@ -727,16 +731,21 @@ static const struct v4l2_subdev_core_ops saa7127_core_ops = {
 };
 
 static const struct v4l2_subdev_video_ops saa7127_video_ops = {
-       .s_vbi_data = saa7127_s_vbi_data,
        .g_fmt = saa7127_g_fmt,
        .s_std_output = saa7127_s_std_output,
        .s_routing = saa7127_s_routing,
        .s_stream = saa7127_s_stream,
 };
 
+static const struct v4l2_subdev_vbi_ops saa7127_vbi_ops = {
+       .s_vbi_data = saa7127_s_vbi_data,
+       .g_sliced_fmt = saa7127_g_sliced_fmt,
+};
+
 static const struct v4l2_subdev_ops saa7127_ops = {
        .core = &saa7127_core_ops,
        .video = &saa7127_video_ops,
+       .vbi = &saa7127_vbi_ops,
 };
 
 /* ----------------------------------------------------------------------- */
index d48c450..d3bd82a 100644 (file)
@@ -1011,8 +1011,6 @@ static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip)
        unsigned int idx;
        int err, addr;
 
-       if (snd_BUG_ON(!chip))
-               return -EINVAL;
        strcpy(card->mixername, "SAA7134 Mixer");
 
        for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_volume_controls); idx++) {
index 297833f..72700d4 100644 (file)
@@ -5355,6 +5355,79 @@ struct saa7134_board saa7134_boards[] = {
                        .amux = LINE2,
                },
        },
+       [SAA7134_BOARD_HAWELL_HW_404M7] = {
+               /* Hawell HW-404M7 & Hawell HW-808M7  */
+               /* Bogoslovskiy Viktor <bogovic@bk.ru> */
+               .name         = "Hawell HW-404M7",
+               .audio_clock   = 0x00200000,
+               .tuner_type    = UNSET,
+               .radio_type    = UNSET,
+               .tuner_addr   = ADDR_UNSET,
+               .radio_addr   = ADDR_UNSET,
+               .gpiomask      = 0x389c00,
+               .inputs       = {{
+                       .name = name_comp1,
+                       .vmux = 3,
+                       .amux = LINE1,
+                       .gpio = 0x01fc00,
+               } },
+       },
+       [SAA7134_BOARD_BEHOLD_H7] = {
+               /* Beholder Intl. Ltd. Dmitry Belimov <d.belimov@gmail.com> */
+               .name           = "Beholder BeholdTV H7",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_XC5000,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .mpeg           = SAA7134_MPEG_DVB,
+               .ts_type        = SAA7134_MPEG_TS_PARALLEL,
+               .inputs         = { {
+                       .name = name_tv,
+                       .vmux = 2,
+                       .amux = TV,
+                       .tv   = 1,
+               }, {
+                       .name = name_comp1,
+                       .vmux = 0,
+                       .amux = LINE1,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 9,
+                       .amux = LINE1,
+               } },
+               .radio = {
+                       .name = name_radio,
+                       .amux = TV,
+               },
+       },
+       [SAA7134_BOARD_BEHOLD_A7] = {
+               /* Beholder Intl. Ltd. Dmitry Belimov <d.belimov@gmail.com> */
+               .name           = "Beholder BeholdTV A7",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_XC5000,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .inputs         = { {
+                       .name = name_tv,
+                       .vmux = 2,
+                       .amux = TV,
+                       .tv   = 1,
+               }, {
+                       .name = name_comp1,
+                       .vmux = 0,
+                       .amux = LINE1,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 9,
+                       .amux = LINE1,
+               } },
+               .radio = {
+                       .name = name_radio,
+                       .amux = TV,
+               },
+       },
 
 };
 
@@ -6549,6 +6622,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .subvendor    = PCI_ANY_ID,
                .subdevice    = PCI_ANY_ID,
                .driver_data  = SAA7134_BOARD_UNKNOWN,
+       }, {
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
+               .subvendor    = 0x5ace, /* Beholder Intl. Ltd. */
+               .subdevice    = 0x7190,
+               .driver_data  = SAA7134_BOARD_BEHOLD_H7,
+       }, {
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
+               .subvendor    = 0x5ace, /* Beholder Intl. Ltd. */
+               .subdevice    = 0x7090,
+               .driver_data  = SAA7134_BOARD_BEHOLD_A7,
        },{
                /* --- end of list --- */
        }
@@ -6602,6 +6687,8 @@ static int saa7134_xc5000_callback(struct saa7134_dev *dev,
 {
        switch (dev->board) {
        case SAA7134_BOARD_BEHOLD_X7:
+       case SAA7134_BOARD_BEHOLD_H7:
+       case SAA7134_BOARD_BEHOLD_A7:
                if (command == XC5000_TUNER_RESET) {
                /* Down and UP pheripherial RESET pin for reset all chips */
                        saa_writeb(SAA7134_SPECIAL_MODE, 0x00);
@@ -6973,6 +7060,8 @@ int saa7134_board_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_BEHOLD_M6_EXTRA:
        case SAA7134_BOARD_BEHOLD_H6:
        case SAA7134_BOARD_BEHOLD_X7:
+       case SAA7134_BOARD_BEHOLD_H7:
+       case SAA7134_BOARD_BEHOLD_A7:
                dev->has_remote = SAA7134_REMOTE_I2C;
                break;
        case SAA7134_BOARD_AVERMEDIA_A169_B:
@@ -7215,6 +7304,11 @@ int saa7134_board_init2(struct saa7134_dev *dev)
                       printk(KERN_INFO "%s: P7131 analog only, using "
                                                       "entry of %s\n",
                       dev->name, saa7134_boards[dev->board].name);
+
+                       /* IR init has already happened for other cards, so
+                        * we have to catch up. */
+                       dev->has_remote = SAA7134_REMOTE_GPIO;
+                       saa7134_input_init1(dev);
               }
               break;
        case SAA7134_BOARD_HAUPPAUGE_HVR1150:
@@ -7344,6 +7438,23 @@ int saa7134_board_init2(struct saa7134_dev *dev)
                }
                break;
        }
+       case SAA7134_BOARD_BEHOLD_H6:
+       {
+               u8 data[] = { 0x09, 0x9f, 0x86, 0x11};
+               struct i2c_msg msg = {.addr = 0x61, .flags = 0, .buf = data,
+                                                       .len = sizeof(data)};
+
+               /* The tuner TUNER_PHILIPS_FMD1216MEX_MK3 after hardware    */
+               /* start has disabled IF and enabled DVB-T. When saa7134    */
+               /* scan I2C devices it not detect IF tda9887 and can`t      */
+               /* watch TV without software reboot. For solve this problem */
+               /* switch the tuner to analog TV mode manually.             */
+               if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1)
+                               printk(KERN_WARNING
+                                     "%s: Unable to enable IF of the tuner.\n",
+                                      dev->name);
+               break;
+       }
        } /* switch() */
 
        /* initialize tuner */
index a7ad781..90f2318 100644 (file)
@@ -471,7 +471,7 @@ static char *irqbits[] = {
        "DONE_RA0", "DONE_RA1", "DONE_RA2", "DONE_RA3",
        "AR", "PE", "PWR_ON", "RDCAP", "INTL", "FIDT", "MMC",
        "TRIG_ERR", "CONF_ERR", "LOAD_ERR",
-       "GPIO16?", "GPIO18", "GPIO22", "GPIO23"
+       "GPIO16", "GPIO18", "GPIO22", "GPIO23"
 };
 #define IRQBITS ARRAY_SIZE(irqbits)
 
@@ -601,12 +601,14 @@ static irqreturn_t saa7134_irq(int irq, void *dev_id)
                        /* disable gpio16 IRQ */
                        printk(KERN_WARNING "%s/irq: looping -- "
                               "clearing GPIO16 enable bit\n",dev->name);
-                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16);
+                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_P);
+                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO16_N);
                } else if (report & SAA7134_IRQ_REPORT_GPIO18) {
                        /* disable gpio18 IRQs */
                        printk(KERN_WARNING "%s/irq: looping -- "
                               "clearing GPIO18 enable bit\n",dev->name);
-                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
+                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
+                       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_N);
                } else {
                        /* disable all irqs */
                        printk(KERN_WARNING "%s/irq: looping -- "
@@ -698,11 +700,13 @@ static int saa7134_hw_enable2(struct saa7134_dev *dev)
 
        if (dev->has_remote == SAA7134_REMOTE_GPIO && dev->remote) {
                if (dev->remote->mask_keydown & 0x10000)
-                       irq2_mask |= SAA7134_IRQ2_INTE_GPIO16;
-               else if (dev->remote->mask_keydown & 0x40000)
-                       irq2_mask |= SAA7134_IRQ2_INTE_GPIO18;
-               else if (dev->remote->mask_keyup & 0x40000)
-                       irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A;
+                       irq2_mask |= SAA7134_IRQ2_INTE_GPIO16_N;
+               else {          /* Allow enabling both IRQ edge triggers */
+                       if (dev->remote->mask_keydown & 0x40000)
+                               irq2_mask |= SAA7134_IRQ2_INTE_GPIO18_P;
+                       if (dev->remote->mask_keyup & 0x40000)
+                               irq2_mask |= SAA7134_IRQ2_INTE_GPIO18_N;
+               }
        }
 
        if (dev->has_remote == SAA7134_REMOTE_I2C) {
@@ -1227,7 +1231,7 @@ static int saa7134_resume(struct pci_dev *pci_dev)
        if (card_has_mpeg(dev))
                saa7134_ts_init_hw(dev);
        if (dev->remote)
-               saa7134_ir_start(dev, dev->remote);
+               saa7134_ir_start(dev);
        saa7134_hw_enable1(dev);
 
        msleep(100);
index 4ab4a98..31e82be 100644 (file)
@@ -1532,6 +1532,15 @@ static int dvb_init(struct saa7134_dev *dev)
                                   &dev->i2c_adap, &behold_x7_tunerconfig);
                }
                break;
+       case SAA7134_BOARD_BEHOLD_H7:
+               fe0->dvb.frontend = dvb_attach(zl10353_attach,
+                                               &behold_x7_config,
+                                               &dev->i2c_adap);
+               if (fe0->dvb.frontend) {
+                       dvb_attach(xc5000_attach, fe0->dvb.frontend,
+                                  &dev->i2c_adap, &behold_x7_tunerconfig);
+               }
+               break;
        case SAA7134_BOARD_AVERMEDIA_A700_PRO:
        case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
                /* Zarlink ZL10313 */
index 58a0cdc..e5565e2 100644 (file)
@@ -28,6 +28,8 @@
 #include "saa7134-reg.h"
 #include "saa7134.h"
 
+#define MODULE_NAME "saa7134"
+
 static unsigned int disable_ir;
 module_param(disable_ir, int, 0444);
 MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
@@ -66,6 +68,7 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
 /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
 static int saa7134_rc5_irq(struct saa7134_dev *dev);
 static int saa7134_nec_irq(struct saa7134_dev *dev);
+static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
 static void nec_task(unsigned long data);
 static void saa7134_nec_timer(unsigned long data);
 
@@ -397,14 +400,23 @@ static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
 
 void saa7134_input_irq(struct saa7134_dev *dev)
 {
-       struct card_ir *ir = dev->remote;
+       struct card_ir *ir;
+
+       if (!dev || !dev->remote)
+               return;
+
+       ir = dev->remote;
+       if (!ir->running)
+               return;
 
        if (ir->nec_gpio) {
                saa7134_nec_irq(dev);
-       } else if (!ir->polling && !ir->rc5_gpio) {
+       } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
                build_key(dev);
        } else if (ir->rc5_gpio) {
                saa7134_rc5_irq(dev);
+       } else if (ir->raw_decode) {
+               saa7134_raw_decode_irq(dev);
        }
 }
 
@@ -417,8 +429,32 @@ static void saa7134_input_timer(unsigned long data)
        mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
 }
 
-void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
+void ir_raw_decode_timer_end(unsigned long data)
+{
+       struct saa7134_dev *dev = (struct saa7134_dev *)data;
+       struct card_ir *ir = dev->remote;
+
+       ir_raw_event_handle(dev->remote->dev);
+
+       ir->active = 0;
+}
+
+static int __saa7134_ir_start(void *priv)
 {
+       struct saa7134_dev *dev = priv;
+       struct card_ir *ir;
+
+       if (!dev)
+               return -EINVAL;
+
+       ir  = dev->remote;
+       if (!ir)
+               return -EINVAL;
+
+       if (ir->running)
+               return 0;
+
+       ir->running = 1;
        if (ir->polling) {
                setup_timer(&ir->timer, saa7134_input_timer,
                            (unsigned long)dev);
@@ -441,26 +477,125 @@ void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
                setup_timer(&ir->timer_keyup, saa7134_nec_timer,
                            (unsigned long)dev);
                tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
+       } else if (ir->raw_decode) {
+               /* set timer_end for code completion */
+               init_timer(&ir->timer_end);
+               ir->timer_end.function = ir_raw_decode_timer_end;
+               ir->timer_end.data = (unsigned long)dev;
+               ir->active = 0;
        }
+
+       return 0;
 }
 
-void saa7134_ir_stop(struct saa7134_dev *dev)
+static void __saa7134_ir_stop(void *priv)
 {
+       struct saa7134_dev *dev = priv;
+       struct card_ir *ir;
+
+       if (!dev)
+               return;
+
+       ir  = dev->remote;
+       if (!ir)
+               return;
+
+       if (!ir->running)
+               return;
        if (dev->remote->polling)
                del_timer_sync(&dev->remote->timer);
+       else if (ir->rc5_gpio)
+               del_timer_sync(&ir->timer_end);
+       else if (ir->nec_gpio)
+               tasklet_kill(&ir->tlet);
+       else if (ir->raw_decode) {
+               del_timer_sync(&ir->timer_end);
+               ir->active = 0;
+       }
+
+       ir->running = 0;
+
+       return;
+}
+
+int saa7134_ir_start(struct saa7134_dev *dev)
+{
+       if (dev->remote->users)
+               return __saa7134_ir_start(dev);
+
+       return 0;
+}
+
+void saa7134_ir_stop(struct saa7134_dev *dev)
+{
+       if (dev->remote->users)
+               __saa7134_ir_stop(dev);
+}
+
+static int saa7134_ir_open(void *priv)
+{
+       struct saa7134_dev *dev = priv;
+
+       dev->remote->users++;
+       return __saa7134_ir_start(dev);
+}
+
+static void saa7134_ir_close(void *priv)
+{
+       struct saa7134_dev *dev = priv;
+
+       dev->remote->users--;
+       if (!dev->remote->users)
+               __saa7134_ir_stop(dev);
+}
+
+
+int saa7134_ir_change_protocol(void *priv, u64 ir_type)
+{
+       struct saa7134_dev *dev = priv;
+       struct card_ir *ir = dev->remote;
+       u32 nec_gpio, rc5_gpio;
+
+       if (ir_type == IR_TYPE_RC5) {
+               dprintk("Changing protocol to RC5\n");
+               nec_gpio = 0;
+               rc5_gpio = 1;
+       } else if (ir_type == IR_TYPE_NEC) {
+               dprintk("Changing protocol to NEC\n");
+               nec_gpio = 1;
+               rc5_gpio = 0;
+       } else {
+               dprintk("IR protocol type %ud is not supported\n",
+                       (unsigned)ir_type);
+               return -EINVAL;
+       }
+
+       if (ir->running) {
+               saa7134_ir_stop(dev);
+               ir->nec_gpio = nec_gpio;
+               ir->rc5_gpio = rc5_gpio;
+               saa7134_ir_start(dev);
+       } else {
+               ir->nec_gpio = nec_gpio;
+               ir->rc5_gpio = rc5_gpio;
+       }
+
+       return 0;
 }
 
 int saa7134_input_init1(struct saa7134_dev *dev)
 {
        struct card_ir *ir;
        struct input_dev *input_dev;
-       struct ir_scancode_table *ir_codes = NULL;
+       char *ir_codes = NULL;
        u32 mask_keycode = 0;
        u32 mask_keydown = 0;
        u32 mask_keyup   = 0;
        int polling      = 0;
        int rc5_gpio     = 0;
        int nec_gpio     = 0;
+       int raw_decode   = 0;
+       int allow_protocol_change = 0;
        u64 ir_type = IR_TYPE_OTHER;
        int err;
 
@@ -476,27 +611,27 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_FLYTVPLATINUM_FM:
        case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
        case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
-               ir_codes     = &ir_codes_flyvideo_table;
+               ir_codes     = RC_MAP_FLYVIDEO;
                mask_keycode = 0xEC00000;
                mask_keydown = 0x0040000;
                break;
        case SAA7134_BOARD_CINERGY400:
        case SAA7134_BOARD_CINERGY600:
        case SAA7134_BOARD_CINERGY600_MK3:
-               ir_codes     = &ir_codes_cinergy_table;
+               ir_codes     = RC_MAP_CINERGY;
                mask_keycode = 0x00003f;
                mask_keyup   = 0x040000;
                break;
        case SAA7134_BOARD_ECS_TVP3XP:
        case SAA7134_BOARD_ECS_TVP3XP_4CB5:
-               ir_codes     = &ir_codes_eztv_table;
+               ir_codes     = RC_MAP_EZTV;
                mask_keycode = 0x00017c;
                mask_keyup   = 0x000002;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_KWORLD_XPERT:
        case SAA7134_BOARD_AVACSSMARTTV:
-               ir_codes     = &ir_codes_pixelview_table;
+               ir_codes     = RC_MAP_PIXELVIEW;
                mask_keycode = 0x00001F;
                mask_keyup   = 0x000020;
                polling      = 50; // ms
@@ -513,7 +648,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
        case SAA7134_BOARD_AVERMEDIA_M102:
        case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
-               ir_codes     = &ir_codes_avermedia_table;
+               ir_codes     = RC_MAP_AVERMEDIA;
                mask_keycode = 0x0007C8;
                mask_keydown = 0x000010;
                polling      = 50; // ms
@@ -522,14 +657,15 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
                break;
        case SAA7134_BOARD_AVERMEDIA_M135A:
-               ir_codes     = &ir_codes_avermedia_m135a_table;
-               mask_keydown = 0x0040000;
-               mask_keycode = 0x00013f;
-               nec_gpio     = 1;
+               ir_codes     = RC_MAP_AVERMEDIA_M135A_RM_JX;
+               mask_keydown = 0x0040000;       /* Enable GPIO18 line on both edges */
+               mask_keyup   = 0x0040000;
+               mask_keycode = 0xffff;
+               raw_decode   = 1;
                break;
        case SAA7134_BOARD_AVERMEDIA_777:
        case SAA7134_BOARD_AVERMEDIA_A16AR:
-               ir_codes     = &ir_codes_avermedia_table;
+               ir_codes     = RC_MAP_AVERMEDIA;
                mask_keycode = 0x02F200;
                mask_keydown = 0x000400;
                polling      = 50; // ms
@@ -538,7 +674,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
                break;
        case SAA7134_BOARD_AVERMEDIA_A16D:
-               ir_codes     = &ir_codes_avermedia_a16d_table;
+               ir_codes     = RC_MAP_AVERMEDIA_A16D;
                mask_keycode = 0x02F200;
                mask_keydown = 0x000400;
                polling      = 50; /* ms */
@@ -547,14 +683,14 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
                break;
        case SAA7134_BOARD_KWORLD_TERMINATOR:
-               ir_codes     = &ir_codes_pixelview_table;
+               ir_codes     = RC_MAP_PIXELVIEW;
                mask_keycode = 0x00001f;
                mask_keyup   = 0x000060;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_MANLI_MTV001:
        case SAA7134_BOARD_MANLI_MTV002:
-               ir_codes     = &ir_codes_manli_table;
+               ir_codes     = RC_MAP_MANLI;
                mask_keycode = 0x001f00;
                mask_keyup   = 0x004000;
                polling      = 50; /* ms */
@@ -574,25 +710,25 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_BEHOLD_507_9FM:
        case SAA7134_BOARD_BEHOLD_507RDS_MK3:
        case SAA7134_BOARD_BEHOLD_507RDS_MK5:
-               ir_codes     = &ir_codes_manli_table;
+               ir_codes     = RC_MAP_MANLI;
                mask_keycode = 0x003f00;
                mask_keyup   = 0x004000;
                polling      = 50; /* ms */
                break;
        case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
-               ir_codes     = &ir_codes_behold_columbus_table;
+               ir_codes     = RC_MAP_BEHOLD_COLUMBUS;
                mask_keycode = 0x003f00;
                mask_keyup   = 0x004000;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
-               ir_codes     = &ir_codes_pctv_sedna_table;
+               ir_codes     = RC_MAP_PCTV_SEDNA;
                mask_keycode = 0x001f00;
                mask_keyup   = 0x004000;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_GOTVIEW_7135:
-               ir_codes     = &ir_codes_gotview7135_table;
+               ir_codes     = RC_MAP_GOTVIEW7135;
                mask_keycode = 0x0003CC;
                mask_keydown = 0x000010;
                polling      = 5; /* ms */
@@ -601,80 +737,80 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_VIDEOMATE_TV_PVR:
        case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
        case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
-               ir_codes     = &ir_codes_videomate_tv_pvr_table;
+               ir_codes     = RC_MAP_VIDEOMATE_TV_PVR;
                mask_keycode = 0x00003F;
                mask_keyup   = 0x400000;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_PROTEUS_2309:
-               ir_codes     = &ir_codes_proteus_2309_table;
+               ir_codes     = RC_MAP_PROTEUS_2309;
                mask_keycode = 0x00007F;
                mask_keyup   = 0x000080;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_VIDEOMATE_DVBT_300:
        case SAA7134_BOARD_VIDEOMATE_DVBT_200:
-               ir_codes     = &ir_codes_videomate_tv_pvr_table;
+               ir_codes     = RC_MAP_VIDEOMATE_TV_PVR;
                mask_keycode = 0x003F00;
                mask_keyup   = 0x040000;
                break;
        case SAA7134_BOARD_FLYDVBS_LR300:
        case SAA7134_BOARD_FLYDVBT_LR301:
        case SAA7134_BOARD_FLYDVBTDUO:
-               ir_codes     = &ir_codes_flydvb_table;
+               ir_codes     = RC_MAP_FLYDVB;
                mask_keycode = 0x0001F00;
                mask_keydown = 0x0040000;
                break;
        case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
        case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
        case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
-               ir_codes     = &ir_codes_asus_pc39_table;
+               ir_codes     = RC_MAP_ASUS_PC39;
                mask_keydown = 0x0040000;
                rc5_gpio = 1;
                break;
        case SAA7134_BOARD_ENCORE_ENLTV:
        case SAA7134_BOARD_ENCORE_ENLTV_FM:
-               ir_codes     = &ir_codes_encore_enltv_table;
+               ir_codes     = RC_MAP_ENCORE_ENLTV;
                mask_keycode = 0x00007f;
                mask_keyup   = 0x040000;
                polling      = 50; // ms
                break;
        case SAA7134_BOARD_ENCORE_ENLTV_FM53:
-               ir_codes     = &ir_codes_encore_enltv_fm53_table;
+               ir_codes     = RC_MAP_ENCORE_ENLTV_FM53;
                mask_keydown = 0x0040000;
                mask_keycode = 0x00007f;
                nec_gpio = 1;
                break;
        case SAA7134_BOARD_10MOONSTVMASTER3:
-               ir_codes     = &ir_codes_encore_enltv_table;
+               ir_codes     = RC_MAP_ENCORE_ENLTV;
                mask_keycode = 0x5f80000;
                mask_keyup   = 0x8000000;
                polling      = 50; //ms
                break;
        case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
-               ir_codes     = &ir_codes_genius_tvgo_a11mce_table;
+               ir_codes     = RC_MAP_GENIUS_TVGO_A11MCE;
                mask_keycode = 0xff;
                mask_keydown = 0xf00000;
                polling = 50; /* ms */
                break;
        case SAA7134_BOARD_REAL_ANGEL_220:
-               ir_codes     = &ir_codes_real_audio_220_32_keys_table;
+               ir_codes     = RC_MAP_REAL_AUDIO_220_32_KEYS;
                mask_keycode = 0x3f00;
                mask_keyup   = 0x4000;
                polling = 50; /* ms */
                break;
        case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
-               ir_codes     = &ir_codes_kworld_plus_tv_analog_table;
+               ir_codes     = RC_MAP_KWORLD_PLUS_TV_ANALOG;
                mask_keycode = 0x7f;
                polling = 40; /* ms */
                break;
        case SAA7134_BOARD_VIDEOMATE_S350:
-               ir_codes     = &ir_codes_videomate_s350_table;
+               ir_codes     = RC_MAP_VIDEOMATE_S350;
                mask_keycode = 0x003f00;
                mask_keydown = 0x040000;
                break;
        case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
-               ir_codes     = &ir_codes_winfast_table;
+               ir_codes     = RC_MAP_WINFAST;
                mask_keycode = 0x5f00;
                mask_keyup   = 0x020000;
                polling      = 50; /* ms */
@@ -695,6 +831,9 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        }
 
        ir->dev = input_dev;
+       dev->remote = ir;
+
+       ir->running = 0;
 
        /* init hardware-specific stuff */
        ir->mask_keycode = mask_keycode;
@@ -703,6 +842,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        ir->polling      = polling;
        ir->rc5_gpio     = rc5_gpio;
        ir->nec_gpio     = nec_gpio;
+       ir->raw_decode   = raw_decode;
 
        /* init input device */
        snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
@@ -710,6 +850,19 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
                 pci_name(dev->pci));
 
+
+       ir->props.priv = dev;
+       ir->props.open = saa7134_ir_open;
+       ir->props.close = saa7134_ir_close;
+
+       if (raw_decode)
+               ir->props.driver_type = RC_DRIVER_IR_RAW;
+
+       if (!raw_decode && allow_protocol_change) {
+               ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
+               ir->props.change_protocol = saa7134_ir_change_protocol;
+       }
+
        err = ir_input_init(input_dev, &ir->ir, ir_type);
        if (err < 0)
                goto err_out_free;
@@ -727,12 +880,9 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        }
        input_dev->dev.parent = &dev->pci->dev;
 
-       dev->remote = ir;
-       saa7134_ir_start(dev, ir);
-
-       err = ir_input_register(ir->dev, ir_codes, NULL);
+       err = ir_input_register(ir->dev, ir_codes, &ir->props, MODULE_NAME);
        if (err)
-               goto err_out_stop;
+               goto err_out_free;
 
        /* the remote isn't as bouncy as a keyboard */
        ir->dev->rep[REP_DELAY] = repeat_delay;
@@ -740,10 +890,8 @@ int saa7134_input_init1(struct saa7134_dev *dev)
 
        return 0;
 
- err_out_stop:
-       saa7134_ir_stop(dev);
+err_out_free:
        dev->remote = NULL;
- err_out_free:
        kfree(ir);
        return err;
 }
@@ -787,24 +935,24 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
                dev->init_data.name = "Pinnacle PCTV";
                if (pinnacle_remote == 0) {
                        dev->init_data.get_key = get_key_pinnacle_color;
-                       dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
+                       dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
                        info.addr = 0x47;
                } else {
                        dev->init_data.get_key = get_key_pinnacle_grey;
-                       dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
+                       dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
                        info.addr = 0x47;
                }
                break;
        case SAA7134_BOARD_UPMOST_PURPLE_TV:
                dev->init_data.name = "Purple TV";
                dev->init_data.get_key = get_key_purpletv;
-               dev->init_data.ir_codes = &ir_codes_purpletv_table;
+               dev->init_data.ir_codes = RC_MAP_PURPLETV;
                info.addr = 0x7a;
                break;
        case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
                dev->init_data.name = "MSI TV@nywhere Plus";
                dev->init_data.get_key = get_key_msi_tvanywhere_plus;
-               dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
+               dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
                info.addr = 0x30;
                /* MSI TV@nywhere Plus controller doesn't seem to
                   respond to probes unless we read something from
@@ -818,7 +966,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
        case SAA7134_BOARD_HAUPPAUGE_HVR1110:
                dev->init_data.name = "HVR 1110";
                dev->init_data.get_key = get_key_hvr1110;
-               dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
+               dev->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW;
                info.addr = 0x71;
                break;
        case SAA7134_BOARD_BEHOLD_607FM_MK3:
@@ -834,9 +982,12 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
        case SAA7134_BOARD_BEHOLD_M6_EXTRA:
        case SAA7134_BOARD_BEHOLD_H6:
        case SAA7134_BOARD_BEHOLD_X7:
+       case SAA7134_BOARD_BEHOLD_H7:
+       case SAA7134_BOARD_BEHOLD_A7:
                dev->init_data.name = "BeholdTV";
                dev->init_data.get_key = get_key_beholdm6xx;
-               dev->init_data.ir_codes = &ir_codes_behold_table;
+               dev->init_data.ir_codes = RC_MAP_BEHOLD;
+               dev->init_data.type = IR_TYPE_NEC;
                info.addr = 0x2d;
                break;
        case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
@@ -846,7 +997,7 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
        case SAA7134_BOARD_FLYDVB_TRIO:
                dev->init_data.name = "FlyDVB Trio";
                dev->init_data.get_key = get_key_flydvb_trio;
-               dev->init_data.ir_codes = &ir_codes_flydvb_table;
+               dev->init_data.ir_codes = RC_MAP_FLYDVB;
                info.addr = 0x0b;
                break;
        default:
@@ -859,6 +1010,33 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
        i2c_new_device(&dev->i2c_adap, &info);
 }
 
+static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
+{
+       struct card_ir  *ir = dev->remote;
+       unsigned long   timeout;
+       int space;
+
+       /* Generate initial event */
+       saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+       saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+       space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
+       ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
+
+
+       /*
+        * Wait 15 ms from the start of the first IR event before processing
+        * the event. This time is enough for NEC protocol. May need adjustments
+        * to work with other protocols.
+        */
+       if (!ir->active) {
+               timeout = jiffies + jiffies_to_msecs(15);
+               mod_timer(&ir->timer_end, timeout);
+               ir->active = 1;
+       }
+
+       return 1;
+}
+
 static int saa7134_rc5_irq(struct saa7134_dev *dev)
 {
        struct card_ir *ir = dev->remote;
@@ -901,7 +1079,6 @@ static int saa7134_rc5_irq(struct saa7134_dev *dev)
        return 1;
 }
 
-
 /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
    The first pulse (start) has 9 + 4.5 ms
  */
@@ -1011,14 +1188,14 @@ static void nec_task(unsigned long data)
        /* Keep repeating the last key */
        mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
 
-       saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
+       saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
 }
 
 static int saa7134_nec_irq(struct saa7134_dev *dev)
 {
        struct card_ir *ir = dev->remote;
 
-       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
+       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
        tasklet_schedule(&ir->tlet);
 
        return 1;
index cf89d96..e7e0af1 100644 (file)
 #define   SAA7134_IRQ1_INTE_RA0_0               (1 <<  0)
 
 #define SAA7134_IRQ2                            (0x2c8 >> 2)
-#define   SAA7134_IRQ2_INTE_GPIO23A             (1 << 17)
-#define   SAA7134_IRQ2_INTE_GPIO23              (1 << 16)
-#define   SAA7134_IRQ2_INTE_GPIO22A             (1 << 15)
-#define   SAA7134_IRQ2_INTE_GPIO22              (1 << 14)
-#define   SAA7134_IRQ2_INTE_GPIO18A             (1 << 13)
-#define   SAA7134_IRQ2_INTE_GPIO18              (1 << 12)
-#define   SAA7134_IRQ2_INTE_GPIO16              (1 << 11) /* not certain */
-#define   SAA7134_IRQ2_INTE_SC2                 (1 << 10)
-#define   SAA7134_IRQ2_INTE_SC1                 (1 <<  9)
-#define   SAA7134_IRQ2_INTE_SC0                 (1 <<  8)
-#define   SAA7134_IRQ2_INTE_DEC5                (1 <<  7)
+#define   SAA7134_IRQ2_INTE_GPIO23_N             (1 << 17)     /* negative edge */
+#define   SAA7134_IRQ2_INTE_GPIO23_P             (1 << 16)     /* positive edge */
+#define   SAA7134_IRQ2_INTE_GPIO22_N             (1 << 15)     /* negative edge */
+#define   SAA7134_IRQ2_INTE_GPIO22_P             (1 << 14)     /* positive edge */
+#define   SAA7134_IRQ2_INTE_GPIO18_N             (1 << 13)     /* negative edge */
+#define   SAA7134_IRQ2_INTE_GPIO18_P             (1 << 12)     /* positive edge */
+#define   SAA7134_IRQ2_INTE_GPIO16_N             (1 << 11)     /* negative edge */
+#define   SAA7134_IRQ2_INTE_GPIO16_P             (1 << 10)     /* positive edge */
+#define   SAA7134_IRQ2_INTE_SC2                 (1 <<  9)
+#define   SAA7134_IRQ2_INTE_SC1                 (1 <<  8)
+#define   SAA7134_IRQ2_INTE_SC0                 (1 <<  7)
 #define   SAA7134_IRQ2_INTE_DEC4                (1 <<  6)
 #define   SAA7134_IRQ2_INTE_DEC3                (1 <<  5)
 #define   SAA7134_IRQ2_INTE_DEC2                (1 <<  4)
 #define   SAA7134_IRQ_REPORT_GPIO23             (1 << 17)
 #define   SAA7134_IRQ_REPORT_GPIO22             (1 << 16)
 #define   SAA7134_IRQ_REPORT_GPIO18             (1 << 15)
-#define   SAA7134_IRQ_REPORT_GPIO16             (1 << 14) /* not certain */
+#define   SAA7134_IRQ_REPORT_GPIO16             (1 << 14)
 #define   SAA7134_IRQ_REPORT_LOAD_ERR           (1 << 13)
 #define   SAA7134_IRQ_REPORT_CONF_ERR           (1 << 12)
 #define   SAA7134_IRQ_REPORT_TRIG_ERR           (1 << 11)
index 31138d3..45f0ac8 100644 (file)
@@ -1180,7 +1180,7 @@ int saa7134_s_ctrl_internal(struct saa7134_dev *dev,  struct saa7134_fh *fh, str
           That needs to be fixed somehow, but for now this is
           good enough. */
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -1359,7 +1359,7 @@ static int video_open(struct file *file)
        fh->fmt      = format_by_fourcc(V4L2_PIX_FMT_BGR24);
        fh->width    = 720;
        fh->height   = 576;
-       v4l2_prio_open(&dev->prio,&fh->prio);
+       v4l2_prio_open(&dev->prio, &fh->prio);
 
        videobuf_queue_sg_init(&fh->cap, &video_qops,
                            &dev->pci->dev, &dev->slock,
@@ -1502,7 +1502,7 @@ static int video_release(struct file *file)
        saa7134_pgtable_free(dev->pci,&fh->pt_cap);
        saa7134_pgtable_free(dev->pci,&fh->pt_vbi);
 
-       v4l2_prio_close(&dev->prio,&fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
        return 0;
@@ -1632,8 +1632,15 @@ static int saa7134_try_fmt_vid_cap(struct file *file, void *priv,
        }
 
        f->fmt.pix.field = field;
-       v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
-                             &f->fmt.pix.height, 32, maxh, 0, 0);
+       if (f->fmt.pix.width  < 48)
+               f->fmt.pix.width  = 48;
+       if (f->fmt.pix.height < 32)
+               f->fmt.pix.height = 32;
+       if (f->fmt.pix.width > maxw)
+               f->fmt.pix.width = maxw;
+       if (f->fmt.pix.height > maxh)
+               f->fmt.pix.height = maxh;
+       f->fmt.pix.width &= ~0x03;
        f->fmt.pix.bytesperline =
                (f->fmt.pix.width * fmt->depth) >> 3;
        f->fmt.pix.sizeimage =
@@ -1778,7 +1785,7 @@ static int saa7134_s_input(struct file *file, void *priv, unsigned int i)
        struct saa7134_dev *dev = fh->dev;
        int err;
 
-       err = v4l2_prio_check(&dev->prio, &fh->prio);
+       err = v4l2_prio_check(&dev->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -1832,7 +1839,7 @@ int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_
           That needs to be fixed somehow, but for now this is
           good enough. */
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        } else if (res_locked(dev, RESOURCE_OVERLAY)) {
@@ -2016,7 +2023,7 @@ static int saa7134_s_tuner(struct file *file, void *priv,
        struct saa7134_dev *dev = fh->dev;
        int rx, mode, err;
 
-       err = v4l2_prio_check(&dev->prio, &fh->prio);
+       err = v4l2_prio_check(&dev->prio, fh->prio);
        if (0 != err)
                return err;
 
@@ -2050,7 +2057,7 @@ static int saa7134_s_frequency(struct file *file, void *priv,
        struct saa7134_dev *dev = fh->dev;
        int err;
 
-       err = v4l2_prio_check(&dev->prio, &fh->prio);
+       err = v4l2_prio_check(&dev->prio, fh->prio);
        if (0 != err)
                return err;
 
index bf13096..3962534 100644 (file)
@@ -20,7 +20,7 @@
  */
 
 #include <linux/version.h>
-#define SAA7134_VERSION_CODE KERNEL_VERSION(0,2,15)
+#define SAA7134_VERSION_CODE KERNEL_VERSION(0, 2, 16)
 
 #include <linux/pci.h>
 #include <linux/i2c.h>
@@ -300,6 +300,9 @@ struct saa7134_format {
 #define SAA7134_BOARD_ASUS_EUROPA_HYBRID       174
 #define SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S 175
 #define SAA7134_BOARD_BEHOLD_505RDS_MK3     176
+#define SAA7134_BOARD_HAWELL_HW_404M7          177
+#define SAA7134_BOARD_BEHOLD_H7             178
+#define SAA7134_BOARD_BEHOLD_A7             179
 
 #define SAA7134_MAXBOARDS 32
 #define SAA7134_INPUT_MAX 8
@@ -809,7 +812,7 @@ int  saa7134_input_init1(struct saa7134_dev *dev);
 void saa7134_input_fini(struct saa7134_dev *dev);
 void saa7134_input_irq(struct saa7134_dev *dev);
 void saa7134_probe_i2c_ir(struct saa7134_dev *dev);
-void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir);
+int saa7134_ir_start(struct saa7134_dev *dev);
 void saa7134_ir_stop(struct saa7134_dev *dev);
 
 
index 1ad980f..4ac3b48 100644 (file)
@@ -115,9 +115,20 @@ struct sh_mobile_ceu_dev {
 };
 
 struct sh_mobile_ceu_cam {
-       struct v4l2_rect ceu_rect;
-       unsigned int cam_width;
-       unsigned int cam_height;
+       /* CEU offsets within scaled by the CEU camera output */
+       unsigned int ceu_left;
+       unsigned int ceu_top;
+       /* Client output, as seen by the CEU */
+       unsigned int width;
+       unsigned int height;
+       /*
+        * User window from S_CROP / G_CROP, produced by client cropping and
+        * scaling, CEU scaling and CEU cropping, mapped back onto the client
+        * input window
+        */
+       struct v4l2_rect subrect;
+       /* Camera cropping rectangle */
+       struct v4l2_rect rect;
        const struct soc_mbus_pixelfmt *extra_fmt;
        enum v4l2_mbus_pixelcode code;
 };
@@ -213,8 +224,8 @@ static int sh_mobile_ceu_videobuf_setup(struct videobuf_queue *vq,
                *count = 2;
 
        if (pcdev->video_limit) {
-               while (PAGE_ALIGN(*size) * *count > pcdev->video_limit)
-                       (*count)--;
+               if (PAGE_ALIGN(*size) * *count > pcdev->video_limit)
+                       *count = pcdev->video_limit / PAGE_ALIGN(*size);
        }
 
        dev_dbg(icd->dev.parent, "count=%d, size=%d\n", *count, *size);
@@ -565,38 +576,36 @@ static u16 calc_scale(unsigned int src, unsigned int *dst)
 }
 
 /* rect is guaranteed to not exceed the scaled camera rectangle */
-static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd,
-                                  unsigned int out_width,
-                                  unsigned int out_height)
+static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
 {
        struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
        struct sh_mobile_ceu_cam *cam = icd->host_priv;
-       struct v4l2_rect *rect = &cam->ceu_rect;
        struct sh_mobile_ceu_dev *pcdev = ici->priv;
        unsigned int height, width, cdwdr_width, in_width, in_height;
        unsigned int left_offset, top_offset;
        u32 camor;
 
-       dev_dbg(icd->dev.parent, "Crop %ux%u@%u:%u\n",
-               rect->width, rect->height, rect->left, rect->top);
+       dev_geo(icd->dev.parent, "Crop %ux%u@%u:%u\n",
+               icd->user_width, icd->user_height, cam->ceu_left, cam->ceu_top);
 
-       left_offset     = rect->left;
-       top_offset      = rect->top;
+       left_offset     = cam->ceu_left;
+       top_offset      = cam->ceu_top;
 
+       /* CEU cropping (CFSZR) is applied _after_ the scaling filter (CFLCR) */
        if (pcdev->image_mode) {
-               in_width = rect->width;
+               in_width = cam->width;
                if (!pcdev->is_16bit) {
                        in_width *= 2;
                        left_offset *= 2;
                }
-               width = out_width;
-               cdwdr_width = out_width;
+               width = icd->user_width;
+               cdwdr_width = icd->user_width;
        } else {
-               int bytes_per_line = soc_mbus_bytes_per_line(out_width,
+               int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
                                                icd->current_fmt->host_fmt);
                unsigned int w_factor;
 
-               width = out_width;
+               width = icd->user_width;
 
                switch (icd->current_fmt->host_fmt->packing) {
                case SOC_MBUS_PACKING_2X8_PADHI:
@@ -606,17 +615,17 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd,
                        w_factor = 1;
                }
 
-               in_width = rect->width * w_factor;
+               in_width = cam->width * w_factor;
                left_offset = left_offset * w_factor;
 
                if (bytes_per_line < 0)
-                       cdwdr_width = out_width;
+                       cdwdr_width = icd->user_width;
                else
                        cdwdr_width = bytes_per_line;
        }
 
-       height = out_height;
-       in_height = rect->height;
+       height = icd->user_height;
+       in_height = cam->height;
        if (V4L2_FIELD_NONE != pcdev->field) {
                height /= 2;
                in_height /= 2;
@@ -775,9 +784,10 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
        }
        ceu_write(pcdev, CAIFR, value);
 
-       sh_mobile_ceu_set_rect(icd, icd->user_width, icd->user_height);
+       sh_mobile_ceu_set_rect(icd);
        mdelay(1);
 
+       dev_geo(icd->dev.parent, "CFLCR 0x%x\n", pcdev->cflcr);
        ceu_write(pcdev, CFLCR, pcdev->cflcr);
 
        /*
@@ -866,6 +876,8 @@ static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
                 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
 }
 
+static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
+
 static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
                                     struct soc_camera_format_xlate *xlate)
 {
@@ -894,10 +906,55 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, int idx,
                return 0;
 
        if (!icd->host_priv) {
+               struct v4l2_mbus_framefmt mf;
+               struct v4l2_rect rect;
+               struct device *dev = icd->dev.parent;
+               int shift = 0;
+
+               /* FIXME: subwindow is lost between close / open */
+
+               /* Cache current client geometry */
+               ret = client_g_rect(sd, &rect);
+               if (ret < 0)
+                       return ret;
+
+               /* First time */
+               ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
+               if (ret < 0)
+                       return ret;
+
+               while ((mf.width > 2560 || mf.height > 1920) && shift < 4) {
+                       /* Try 2560x1920, 1280x960, 640x480, 320x240 */
+                       mf.width        = 2560 >> shift;
+                       mf.height       = 1920 >> shift;
+                       ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
+                       if (ret < 0)
+                               return ret;
+                       shift++;
+               }
+
+               if (shift == 4) {
+                       dev_err(dev, "Failed to configure the client below %ux%x\n",
+                               mf.width, mf.height);
+                       return -EIO;
+               }
+
+               dev_geo(dev, "camera fmt %ux%u\n", mf.width, mf.height);
+
                cam = kzalloc(sizeof(*cam), GFP_KERNEL);
                if (!cam)
                        return -ENOMEM;
 
+               /* We are called with current camera crop, initialise subrect with it */
+               cam->rect       = rect;
+               cam->subrect    = rect;
+
+               cam->width      = mf.width;
+               cam->height     = mf.height;
+
+               cam->width      = mf.width;
+               cam->height     = mf.height;
+
                icd->host_priv = cam;
        } else {
                cam = icd->host_priv;
@@ -979,16 +1036,12 @@ static unsigned int scale_down(unsigned int size, unsigned int scale)
        return (size * 4096 + scale / 2) / scale;
 }
 
-static unsigned int scale_up(unsigned int size, unsigned int scale)
-{
-       return (size * scale + 2048) / 4096;
-}
-
 static unsigned int calc_generic_scale(unsigned int input, unsigned int output)
 {
        return (input * 4096 + output / 2) / output;
 }
 
+/* Get and store current client crop */
 static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect)
 {
        struct v4l2_crop crop;
@@ -1007,25 +1060,51 @@ static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect)
        cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
        ret = v4l2_subdev_call(sd, video, cropcap, &cap);
-       if (ret < 0)
-               return ret;
-
-       *rect = cap.defrect;
+       if (!ret)
+               *rect = cap.defrect;
 
        return ret;
 }
 
+/* Client crop has changed, update our sub-rectangle to remain within the area */
+static void update_subrect(struct sh_mobile_ceu_cam *cam)
+{
+       struct v4l2_rect *rect = &cam->rect, *subrect = &cam->subrect;
+
+       if (rect->width < subrect->width)
+               subrect->width = rect->width;
+
+       if (rect->height < subrect->height)
+               subrect->height = rect->height;
+
+       if (rect->left > subrect->left)
+               subrect->left = rect->left;
+       else if (rect->left + rect->width >
+                subrect->left + subrect->width)
+               subrect->left = rect->left + rect->width -
+                       subrect->width;
+
+       if (rect->top > subrect->top)
+               subrect->top = rect->top;
+       else if (rect->top + rect->height >
+                subrect->top + subrect->height)
+               subrect->top = rect->top + rect->height -
+                       subrect->height;
+}
+
 /*
  * The common for both scaling and cropping iterative approach is:
  * 1. try if the client can produce exactly what requested by the user
  * 2. if (1) failed, try to double the client image until we get one big enough
  * 3. if (2) failed, try to request the maximum image
  */
-static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
+static int client_s_crop(struct soc_camera_device *icd, struct v4l2_crop *crop,
                         struct v4l2_crop *cam_crop)
 {
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        struct v4l2_rect *rect = &crop->c, *cam_rect = &cam_crop->c;
        struct device *dev = sd->v4l2_dev->dev;
+       struct sh_mobile_ceu_cam *cam = icd->host_priv;
        struct v4l2_cropcap cap;
        int ret;
        unsigned int width, height;
@@ -1041,13 +1120,14 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
         */
        if (!memcmp(rect, cam_rect, sizeof(*rect))) {
                /* Even if camera S_CROP failed, but camera rectangle matches */
-               dev_dbg(dev, "Camera S_CROP successful for %ux%u@%u:%u\n",
+               dev_dbg(dev, "Camera S_CROP successful for %dx%d@%d:%d\n",
                        rect->width, rect->height, rect->left, rect->top);
+               cam->rect = *cam_rect;
                return 0;
        }
 
        /* Try to fix cropping, that camera hasn't managed to set */
-       dev_geo(dev, "Fix camera S_CROP for %ux%u@%u:%u to %ux%u@%u:%u\n",
+       dev_geo(dev, "Fix camera S_CROP for %dx%d@%d:%d to %dx%d@%d:%d\n",
                cam_rect->width, cam_rect->height,
                cam_rect->left, cam_rect->top,
                rect->width, rect->height, rect->left, rect->top);
@@ -1057,6 +1137,7 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
        if (ret < 0)
                return ret;
 
+       /* Put user requested rectangle within sensor bounds */
        soc_camera_limit_side(&rect->left, &rect->width, cap.bounds.left, 2,
                              cap.bounds.width);
        soc_camera_limit_side(&rect->top, &rect->height, cap.bounds.top, 4,
@@ -1069,6 +1150,10 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
        width = max(cam_rect->width, 2);
        height = max(cam_rect->height, 2);
 
+       /*
+        * Loop as long as sensor is not covering the requested rectangle and
+        * is still within its bounds
+        */
        while (!ret && (is_smaller(cam_rect, rect) ||
                        is_inside(cam_rect, rect)) &&
               (cap.bounds.width > width || cap.bounds.height > height)) {
@@ -1086,6 +1171,7 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
                 * target left, set it to the middle point between the current
                 * left and minimum left. But that would add too much
                 * complexity: we would have to iterate each border separately.
+                * Instead we just drop to the left and top bounds.
                 */
                if (cam_rect->left > rect->left)
                        cam_rect->left = cap.bounds.left;
@@ -1103,7 +1189,7 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
 
                v4l2_subdev_call(sd, video, s_crop, cam_crop);
                ret = client_g_rect(sd, cam_rect);
-               dev_geo(dev, "Camera S_CROP %d for %ux%u@%u:%u\n", ret,
+               dev_geo(dev, "Camera S_CROP %d for %dx%d@%d:%d\n", ret,
                        cam_rect->width, cam_rect->height,
                        cam_rect->left, cam_rect->top);
        }
@@ -1117,82 +1203,24 @@ static int client_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *crop,
                *cam_rect = cap.bounds;
                v4l2_subdev_call(sd, video, s_crop, cam_crop);
                ret = client_g_rect(sd, cam_rect);
-               dev_geo(dev, "Camera S_CROP %d for max %ux%u@%u:%u\n", ret,
+               dev_geo(dev, "Camera S_CROP %d for max %dx%d@%d:%d\n", ret,
                        cam_rect->width, cam_rect->height,
                        cam_rect->left, cam_rect->top);
        }
 
-       return ret;
-}
-
-static int get_camera_scales(struct v4l2_subdev *sd, struct v4l2_rect *rect,
-                            unsigned int *scale_h, unsigned int *scale_v)
-{
-       struct v4l2_mbus_framefmt mf;
-       int ret;
-
-       ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
-       if (ret < 0)
-               return ret;
-
-       *scale_h = calc_generic_scale(rect->width, mf.width);
-       *scale_v = calc_generic_scale(rect->height, mf.height);
-
-       return 0;
-}
-
-static int get_camera_subwin(struct soc_camera_device *icd,
-                            struct v4l2_rect *cam_subrect,
-                            unsigned int cam_hscale, unsigned int cam_vscale)
-{
-       struct sh_mobile_ceu_cam *cam = icd->host_priv;
-       struct v4l2_rect *ceu_rect = &cam->ceu_rect;
-
-       if (!ceu_rect->width) {
-               struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-               struct device *dev = icd->dev.parent;
-               struct v4l2_mbus_framefmt mf;
-               int ret;
-               /* First time */
-
-               ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
-               if (ret < 0)
-                       return ret;
-
-               dev_geo(dev, "camera fmt %ux%u\n", mf.width, mf.height);
-
-               if (mf.width > 2560) {
-                       ceu_rect->width  = 2560;
-                       ceu_rect->left   = (mf.width - 2560) / 2;
-               } else {
-                       ceu_rect->width  = mf.width;
-                       ceu_rect->left   = 0;
-               }
-
-               if (mf.height > 1920) {
-                       ceu_rect->height = 1920;
-                       ceu_rect->top    = (mf.height - 1920) / 2;
-               } else {
-                       ceu_rect->height = mf.height;
-                       ceu_rect->top    = 0;
-               }
-
-               dev_geo(dev, "initialised CEU rect %ux%u@%u:%u\n",
-                       ceu_rect->width, ceu_rect->height,
-                       ceu_rect->left, ceu_rect->top);
+       if (!ret) {
+               cam->rect = *cam_rect;
+               update_subrect(cam);
        }
 
-       cam_subrect->width      = scale_up(ceu_rect->width, cam_hscale);
-       cam_subrect->left       = scale_up(ceu_rect->left, cam_hscale);
-       cam_subrect->height     = scale_up(ceu_rect->height, cam_vscale);
-       cam_subrect->top        = scale_up(ceu_rect->top, cam_vscale);
-
-       return 0;
+       return ret;
 }
 
+/* Iterative s_mbus_fmt, also updates cached client crop on success */
 static int client_s_fmt(struct soc_camera_device *icd,
                        struct v4l2_mbus_framefmt *mf, bool ceu_can_scale)
 {
+       struct sh_mobile_ceu_cam *cam = icd->host_priv;
        struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        struct device *dev = icd->dev.parent;
        unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
@@ -1200,6 +1228,15 @@ static int client_s_fmt(struct soc_camera_device *icd,
        struct v4l2_cropcap cap;
        int ret;
 
+       ret = v4l2_subdev_call(sd, video, s_mbus_fmt, mf);
+       if (ret < 0)
+               return ret;
+
+       dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
+
+       if ((width == mf->width && height == mf->height) || !ceu_can_scale)
+               goto update_cache;
+
        cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
        ret = v4l2_subdev_call(sd, video, cropcap, &cap);
@@ -1209,15 +1246,6 @@ static int client_s_fmt(struct soc_camera_device *icd,
        max_width = min(cap.bounds.width, 2560);
        max_height = min(cap.bounds.height, 1920);
 
-       ret = v4l2_subdev_call(sd, video, s_mbus_fmt, mf);
-       if (ret < 0)
-               return ret;
-
-       dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
-
-       if ((width == mf->width && height == mf->height) || !ceu_can_scale)
-               return 0;
-
        /* Camera set a format, but geometry is not precise, try to improve */
        tmp_w = mf->width;
        tmp_h = mf->height;
@@ -1239,26 +1267,37 @@ static int client_s_fmt(struct soc_camera_device *icd,
                }
        }
 
+update_cache:
+       /* Update cache */
+       ret = client_g_rect(sd, &cam->rect);
+       if (ret < 0)
+               return ret;
+
+       update_subrect(cam);
+
        return 0;
 }
 
 /**
- * @rect       - camera cropped rectangle
- * @sub_rect   - CEU cropped rectangle, mapped back to camera input area
- * @ceu_rect   - on output calculated CEU crop rectangle
+ * @width      - on output: user width, mapped back to input
+ * @height     - on output: user height, mapped back to input
+ * @mf         - in- / output camera output window
  */
-static int client_scale(struct soc_camera_device *icd, struct v4l2_rect *rect,
-                       struct v4l2_rect *sub_rect, struct v4l2_rect *ceu_rect,
-                       struct v4l2_mbus_framefmt *mf, bool ceu_can_scale)
+static int client_scale(struct soc_camera_device *icd,
+                       struct v4l2_mbus_framefmt *mf,
+                       unsigned int *width, unsigned int *height,
+                       bool ceu_can_scale)
 {
-       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        struct sh_mobile_ceu_cam *cam = icd->host_priv;
        struct device *dev = icd->dev.parent;
        struct v4l2_mbus_framefmt mf_tmp = *mf;
        unsigned int scale_h, scale_v;
        int ret;
 
-       /* 5. Apply iterative camera S_FMT for camera user window. */
+       /*
+        * 5. Apply iterative camera S_FMT for camera user window (also updates
+        *    client crop cache and the imaginary sub-rectangle).
+        */
        ret = client_s_fmt(icd, &mf_tmp, ceu_can_scale);
        if (ret < 0)
                return ret;
@@ -1270,60 +1309,22 @@ static int client_scale(struct soc_camera_device *icd, struct v4l2_rect *rect,
 
        /* unneeded - it is already in "mf_tmp" */
 
-       /* 7. Calculate new camera scales. */
-       ret = get_camera_scales(sd, rect, &scale_h, &scale_v);
-       if (ret < 0)
-               return ret;
-
-       dev_geo(dev, "7: camera scales %u:%u\n", scale_h, scale_v);
+       /* 7. Calculate new client scales. */
+       scale_h = calc_generic_scale(cam->rect.width, mf_tmp.width);
+       scale_v = calc_generic_scale(cam->rect.height, mf_tmp.height);
 
-       cam->cam_width  = mf_tmp.width;
-       cam->cam_height = mf_tmp.height;
        mf->width       = mf_tmp.width;
        mf->height      = mf_tmp.height;
        mf->colorspace  = mf_tmp.colorspace;
 
        /*
         * 8. Calculate new CEU crop - apply camera scales to previously
-        *    calculated "effective" crop.
+        *    updated "effective" crop.
         */
-       ceu_rect->left = scale_down(sub_rect->left, scale_h);
-       ceu_rect->width = scale_down(sub_rect->width, scale_h);
-       ceu_rect->top = scale_down(sub_rect->top, scale_v);
-       ceu_rect->height = scale_down(sub_rect->height, scale_v);
+       *width = scale_down(cam->subrect.width, scale_h);
+       *height = scale_down(cam->subrect.height, scale_v);
 
-       dev_geo(dev, "8: new CEU rect %ux%u@%u:%u\n",
-               ceu_rect->width, ceu_rect->height,
-               ceu_rect->left, ceu_rect->top);
-
-       return 0;
-}
-
-/* Get combined scales */
-static int get_scales(struct soc_camera_device *icd,
-                     unsigned int *scale_h, unsigned int *scale_v)
-{
-       struct sh_mobile_ceu_cam *cam = icd->host_priv;
-       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
-       struct v4l2_crop cam_crop;
-       unsigned int width_in, height_in;
-       int ret;
-
-       cam_crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
-       ret = client_g_rect(sd, &cam_crop.c);
-       if (ret < 0)
-               return ret;
-
-       ret = get_camera_scales(sd, &cam_crop.c, scale_h, scale_v);
-       if (ret < 0)
-               return ret;
-
-       width_in = scale_up(cam->ceu_rect.width, *scale_h);
-       height_in = scale_up(cam->ceu_rect.height, *scale_v);
-
-       *scale_h = calc_generic_scale(width_in, icd->user_width);
-       *scale_v = calc_generic_scale(height_in, icd->user_height);
+       dev_geo(dev, "8: new client sub-window %ux%u\n", *width, *height);
 
        return 0;
 }
@@ -1342,115 +1343,165 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
        struct sh_mobile_ceu_dev *pcdev = ici->priv;
        struct v4l2_crop cam_crop;
        struct sh_mobile_ceu_cam *cam = icd->host_priv;
-       struct v4l2_rect *cam_rect = &cam_crop.c, *ceu_rect = &cam->ceu_rect;
+       struct v4l2_rect *cam_rect = &cam_crop.c;
        struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        struct device *dev = icd->dev.parent;
        struct v4l2_mbus_framefmt mf;
-       unsigned int scale_comb_h, scale_comb_v, scale_ceu_h, scale_ceu_v,
-               out_width, out_height;
+       unsigned int scale_cam_h, scale_cam_v, scale_ceu_h, scale_ceu_v,
+               out_width, out_height, scale_h, scale_v;
+       int interm_width, interm_height;
        u32 capsr, cflcr;
        int ret;
 
-       /* 1. Calculate current combined scales. */
-       ret = get_scales(icd, &scale_comb_h, &scale_comb_v);
-       if (ret < 0)
-               return ret;
+       dev_geo(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height,
+               rect->left, rect->top);
 
-       dev_geo(dev, "1: combined scales %u:%u\n", scale_comb_h, scale_comb_v);
+       /* During camera cropping its output window can change too, stop CEU */
+       capsr = capture_save_reset(pcdev);
+       dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);
 
-       /* 2. Apply iterative camera S_CROP for new input window. */
-       ret = client_s_crop(sd, a, &cam_crop);
+       /* 1. - 2. Apply iterative camera S_CROP for new input window. */
+       ret = client_s_crop(icd, a, &cam_crop);
        if (ret < 0)
                return ret;
 
-       dev_geo(dev, "2: camera cropped to %ux%u@%u:%u\n",
+       dev_geo(dev, "1-2: camera cropped to %ux%u@%u:%u\n",
                cam_rect->width, cam_rect->height,
                cam_rect->left, cam_rect->top);
 
        /* On success cam_crop contains current camera crop */
 
-       /*
-        * 3. If old combined scales applied to new crop produce an impossible
-        *    user window, adjust scales to produce nearest possible window.
-        */
-       out_width       = scale_down(rect->width, scale_comb_h);
-       out_height      = scale_down(rect->height, scale_comb_v);
-
-       if (out_width > 2560)
-               out_width = 2560;
-       else if (out_width < 2)
-               out_width = 2;
-
-       if (out_height > 1920)
-               out_height = 1920;
-       else if (out_height < 4)
-               out_height = 4;
-
-       dev_geo(dev, "3: Adjusted output %ux%u\n", out_width, out_height);
-
-       /* 4. Use G_CROP to retrieve actual input window: already in cam_crop */
-
-       /*
-        * 5. Using actual input window and calculated combined scales calculate
-        *    camera target output window.
-        */
-       mf.width        = scale_down(cam_rect->width, scale_comb_h);
-       mf.height       = scale_down(cam_rect->height, scale_comb_v);
-
-       dev_geo(dev, "5: camera target %ux%u\n", mf.width, mf.height);
-
-       /* 6. - 9. */
-       mf.code         = cam->code;
-       mf.field        = pcdev->field;
-
-       capsr = capture_save_reset(pcdev);
-       dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);
+       /* 3. Retrieve camera output window */
+       ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
+       if (ret < 0)
+               return ret;
 
-       /* Make relative to camera rectangle */
-       rect->left      -= cam_rect->left;
-       rect->top       -= cam_rect->top;
+       if (mf.width > 2560 || mf.height > 1920)
+               return -EINVAL;
 
-       ret = client_scale(icd, cam_rect, rect, ceu_rect, &mf,
-                          pcdev->image_mode &&
-                          V4L2_FIELD_NONE == pcdev->field);
+       /* Cache camera output window */
+       cam->width      = mf.width;
+       cam->height     = mf.height;
 
-       dev_geo(dev, "6-9: %d\n", ret);
+       /* 4. Calculate camera scales */
+       scale_cam_h     = calc_generic_scale(cam_rect->width, mf.width);
+       scale_cam_v     = calc_generic_scale(cam_rect->height, mf.height);
 
-       /* 10. Use CEU cropping to crop to the new window. */
-       sh_mobile_ceu_set_rect(icd, out_width, out_height);
+       /* Calculate intermediate window */
+       interm_width    = scale_down(rect->width, scale_cam_h);
+       interm_height   = scale_down(rect->height, scale_cam_v);
 
-       dev_geo(dev, "10: CEU cropped to %ux%u@%u:%u\n",
-               ceu_rect->width, ceu_rect->height,
-               ceu_rect->left, ceu_rect->top);
+       if (pcdev->image_mode) {
+               out_width       = min(interm_width, icd->user_width);
+               out_height      = min(interm_height, icd->user_height);
+       } else {
+               out_width       = interm_width;
+               out_height      = interm_height;
+       }
 
        /*
-        * 11. Calculate CEU scales from camera scales from results of (10) and
-        *     user window from (3)
+        * 5. Calculate CEU scales from camera scales from results of (5) and
+        *    the user window
         */
-       scale_ceu_h = calc_scale(ceu_rect->width, &out_width);
-       scale_ceu_v = calc_scale(ceu_rect->height, &out_height);
+       scale_ceu_h     = calc_scale(interm_width, &out_width);
+       scale_ceu_v     = calc_scale(interm_height, &out_height);
 
-       dev_geo(dev, "11: CEU scales %u:%u\n", scale_ceu_h, scale_ceu_v);
+       /* Calculate camera scales */
+       scale_h         = calc_generic_scale(cam_rect->width, out_width);
+       scale_v         = calc_generic_scale(cam_rect->height, out_height);
 
-       /* 12. Apply CEU scales. */
+       dev_geo(dev, "5: CEU scales %u:%u\n", scale_ceu_h, scale_ceu_v);
+
+       /* Apply CEU scales. */
        cflcr = scale_ceu_h | (scale_ceu_v << 16);
        if (cflcr != pcdev->cflcr) {
                pcdev->cflcr = cflcr;
                ceu_write(pcdev, CFLCR, cflcr);
        }
 
+       icd->user_width  = out_width;
+       icd->user_height = out_height;
+       cam->ceu_left    = scale_down(rect->left - cam_rect->left, scale_h) & ~1;
+       cam->ceu_top     = scale_down(rect->top - cam_rect->top, scale_v) & ~1;
+
+       /* 6. Use CEU cropping to crop to the new window. */
+       sh_mobile_ceu_set_rect(icd);
+
+       cam->subrect = *rect;
+
+       dev_geo(dev, "6: CEU cropped to %ux%u@%u:%u\n",
+               icd->user_width, icd->user_height,
+               cam->ceu_left, cam->ceu_top);
+
        /* Restore capture */
        if (pcdev->active)
                capsr |= 1;
        capture_restore(pcdev, capsr);
 
-       icd->user_width = out_width;
-       icd->user_height = out_height;
-
        /* Even if only camera cropping succeeded */
        return ret;
 }
 
+static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd,
+                                 struct v4l2_crop *a)
+{
+       struct sh_mobile_ceu_cam *cam = icd->host_priv;
+
+       a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       a->c = cam->subrect;
+
+       return 0;
+}
+
+/*
+ * Calculate real client output window by applying new scales to the current
+ * client crop. New scales are calculated from the requested output format and
+ * CEU crop, mapped backed onto the client input (subrect).
+ */
+static void calculate_client_output(struct soc_camera_device *icd,
+               struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
+{
+       struct sh_mobile_ceu_cam *cam = icd->host_priv;
+       struct device *dev = icd->dev.parent;
+       struct v4l2_rect *cam_subrect = &cam->subrect;
+       unsigned int scale_v, scale_h;
+
+       if (cam_subrect->width == cam->rect.width &&
+           cam_subrect->height == cam->rect.height) {
+               /* No sub-cropping */
+               mf->width       = pix->width;
+               mf->height      = pix->height;
+               return;
+       }
+
+       /* 1.-2. Current camera scales and subwin - cached. */
+
+       dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
+               cam_subrect->width, cam_subrect->height,
+               cam_subrect->left, cam_subrect->top);
+
+       /*
+        * 3. Calculate new combined scales from input sub-window to requested
+        *    user window.
+        */
+
+       /*
+        * TODO: CEU cannot scale images larger than VGA to smaller than SubQCIF
+        * (128x96) or larger than VGA
+        */
+       scale_h = calc_generic_scale(cam_subrect->width, pix->width);
+       scale_v = calc_generic_scale(cam_subrect->height, pix->height);
+
+       dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
+
+       /*
+        * 4. Calculate client output window by applying combined scales to real
+        *    input window.
+        */
+       mf->width       = scale_down(cam->rect.width, scale_h);
+       mf->height      = scale_down(cam->rect.height, scale_v);
+}
+
 /* Similar to set_crop multistage iterative algorithm */
 static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
                                 struct v4l2_format *f)
@@ -1460,18 +1511,17 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
        struct sh_mobile_ceu_cam *cam = icd->host_priv;
        struct v4l2_pix_format *pix = &f->fmt.pix;
        struct v4l2_mbus_framefmt mf;
-       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
        struct device *dev = icd->dev.parent;
        __u32 pixfmt = pix->pixelformat;
        const struct soc_camera_format_xlate *xlate;
-       struct v4l2_crop cam_crop;
-       struct v4l2_rect *cam_rect = &cam_crop.c, cam_subrect, ceu_rect;
-       unsigned int scale_cam_h, scale_cam_v;
+       unsigned int ceu_sub_width, ceu_sub_height;
        u16 scale_v, scale_h;
        int ret;
        bool image_mode;
        enum v4l2_field field;
 
+       dev_geo(dev, "S_FMT(pix=0x%x, %ux%u)\n", pixfmt, pix->width, pix->height);
+
        switch (pix->field) {
        default:
                pix->field = V4L2_FIELD_NONE;
@@ -1492,46 +1542,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
                return -EINVAL;
        }
 
-       /* 1. Calculate current camera scales. */
-       cam_crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
-       ret = client_g_rect(sd, cam_rect);
-       if (ret < 0)
-               return ret;
-
-       ret = get_camera_scales(sd, cam_rect, &scale_cam_h, &scale_cam_v);
-       if (ret < 0)
-               return ret;
-
-       dev_geo(dev, "1: camera scales %u:%u\n", scale_cam_h, scale_cam_v);
-
-       /*
-        * 2. Calculate "effective" input crop (sensor subwindow) - CEU crop
-        *    scaled back at current camera scales onto input window.
-        */
-       ret = get_camera_subwin(icd, &cam_subrect, scale_cam_h, scale_cam_v);
-       if (ret < 0)
-               return ret;
-
-       dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
-               cam_subrect.width, cam_subrect.height,
-               cam_subrect.left, cam_subrect.top);
-
-       /*
-        * 3. Calculate new combined scales from "effective" input window to
-        *    requested user window.
-        */
-       scale_h = calc_generic_scale(cam_subrect.width, pix->width);
-       scale_v = calc_generic_scale(cam_subrect.height, pix->height);
-
-       dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
-
-       /*
-        * 4. Calculate camera output window by applying combined scales to real
-        *    input window.
-        */
-       mf.width        = scale_down(cam_rect->width, scale_h);
-       mf.height       = scale_down(cam_rect->height, scale_v);
+       /* 1.-4. Calculate client output geometry */
+       calculate_client_output(icd, &f->fmt.pix, &mf);
        mf.field        = pix->field;
        mf.colorspace   = pix->colorspace;
        mf.code         = xlate->code;
@@ -1547,17 +1559,17 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
                image_mode = false;
        }
 
-       dev_geo(dev, "4: camera output %ux%u\n", mf.width, mf.height);
+       dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height);
 
        /* 5. - 9. */
-       ret = client_scale(icd, cam_rect, &cam_subrect, &ceu_rect, &mf,
+       ret = client_scale(icd, &mf, &ceu_sub_width, &ceu_sub_height,
                           image_mode && V4L2_FIELD_NONE == field);
 
-       dev_geo(dev, "5-9: client scale %d\n", ret);
+       dev_geo(dev, "5-9: client scale return %d\n", ret);
 
        /* Done with the camera. Now see if we can improve the result */
 
-       dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n",
+       dev_geo(dev, "Camera %d fmt %ux%u, requested %ux%u\n",
                ret, mf.width, mf.height, pix->width, pix->height);
        if (ret < 0)
                return ret;
@@ -1565,40 +1577,44 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
        if (mf.code != xlate->code)
                return -EINVAL;
 
+       /* 9. Prepare CEU crop */
+       cam->width = mf.width;
+       cam->height = mf.height;
+
        /* 10. Use CEU scaling to scale to the requested user window. */
 
        /* We cannot scale up */
-       if (pix->width > mf.width)
-               pix->width = mf.width;
-       if (pix->width > ceu_rect.width)
-               pix->width = ceu_rect.width;
+       if (pix->width > ceu_sub_width)
+               ceu_sub_width = pix->width;
 
-       if (pix->height > mf.height)
-               pix->height = mf.height;
-       if (pix->height > ceu_rect.height)
-               pix->height = ceu_rect.height;
+       if (pix->height > ceu_sub_height)
+               ceu_sub_height = pix->height;
 
        pix->colorspace = mf.colorspace;
 
        if (image_mode) {
                /* Scale pix->{width x height} down to width x height */
-               scale_h = calc_scale(ceu_rect.width, &pix->width);
-               scale_v = calc_scale(ceu_rect.height, &pix->height);
-
-               pcdev->cflcr = scale_h | (scale_v << 16);
+               scale_h         = calc_scale(ceu_sub_width, &pix->width);
+               scale_v         = calc_scale(ceu_sub_height, &pix->height);
        } else {
-               pix->width = ceu_rect.width;
-               pix->height = ceu_rect.height;
-               scale_h = scale_v = 0;
-               pcdev->cflcr = 0;
+               pix->width      = ceu_sub_width;
+               pix->height     = ceu_sub_height;
+               scale_h         = 0;
+               scale_v         = 0;
        }
 
+       pcdev->cflcr = scale_h | (scale_v << 16);
+
+       /*
+        * We have calculated CFLCR, the actual configuration will be performed
+        * in sh_mobile_ceu_set_bus_param()
+        */
+
        dev_geo(dev, "10: W: %u : 0x%x = %u, H: %u : 0x%x = %u\n",
-               ceu_rect.width, scale_h, pix->width,
-               ceu_rect.height, scale_v, pix->height);
+               ceu_sub_width, scale_h, pix->width,
+               ceu_sub_height, scale_v, pix->height);
 
        cam->code               = xlate->code;
-       cam->ceu_rect           = ceu_rect;
        icd->current_fmt        = xlate;
 
        pcdev->field = field;
@@ -1820,6 +1836,7 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
        .remove         = sh_mobile_ceu_remove_device,
        .get_formats    = sh_mobile_ceu_get_formats,
        .put_formats    = sh_mobile_ceu_put_formats,
+       .get_crop       = sh_mobile_ceu_get_crop,
        .set_crop       = sh_mobile_ceu_set_crop,
        .set_fmt        = sh_mobile_ceu_set_fmt,
        .try_fmt        = sh_mobile_ceu_try_fmt,
diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c
new file mode 100644 (file)
index 0000000..f5b892a
--- /dev/null
@@ -0,0 +1,1476 @@
+/*
+ * SuperH Video Output Unit (VOU) driver
+ *
+ * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/version.h>
+#include <linux/videodev2.h>
+
+#include <media/sh_vou.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-mediabus.h>
+#include <media/videobuf-dma-contig.h>
+
+/* Mirror addresses are not available for all registers */
+#define VOUER  0
+#define VOUCR  4
+#define VOUSTR 8
+#define VOUVCR 0xc
+#define VOUISR 0x10
+#define VOUBCR 0x14
+#define VOUDPR 0x18
+#define VOUDSR 0x1c
+#define VOUVPR 0x20
+#define VOUIR  0x24
+#define VOUSRR 0x28
+#define VOUMSR 0x2c
+#define VOUHIR 0x30
+#define VOUDFR 0x34
+#define VOUAD1R        0x38
+#define VOUAD2R        0x3c
+#define VOUAIR 0x40
+#define VOUSWR 0x44
+#define VOURCR 0x48
+#define VOURPR 0x50
+
+enum sh_vou_status {
+       SH_VOU_IDLE,
+       SH_VOU_INITIALISING,
+       SH_VOU_RUNNING,
+};
+
+#define VOU_MAX_IMAGE_WIDTH    720
+#define VOU_MAX_IMAGE_HEIGHT   480
+
+struct sh_vou_device {
+       struct v4l2_device v4l2_dev;
+       struct video_device *vdev;
+       atomic_t use_count;
+       struct sh_vou_pdata *pdata;
+       spinlock_t lock;
+       void __iomem *base;
+       /* State information */
+       struct v4l2_pix_format pix;
+       struct v4l2_rect rect;
+       struct list_head queue;
+       v4l2_std_id std;
+       int pix_idx;
+       struct videobuf_buffer *active;
+       enum sh_vou_status status;
+};
+
+struct sh_vou_file {
+       struct videobuf_queue vbq;
+};
+
+/* Register access routines for sides A, B and mirror addresses */
+static void sh_vou_reg_a_write(struct sh_vou_device *vou_dev, unsigned int reg,
+                              u32 value)
+{
+       __raw_writel(value, vou_dev->base + reg);
+}
+
+static void sh_vou_reg_ab_write(struct sh_vou_device *vou_dev, unsigned int reg,
+                               u32 value)
+{
+       __raw_writel(value, vou_dev->base + reg);
+       __raw_writel(value, vou_dev->base + reg + 0x1000);
+}
+
+static void sh_vou_reg_m_write(struct sh_vou_device *vou_dev, unsigned int reg,
+                              u32 value)
+{
+       __raw_writel(value, vou_dev->base + reg + 0x2000);
+}
+
+static u32 sh_vou_reg_a_read(struct sh_vou_device *vou_dev, unsigned int reg)
+{
+       return __raw_readl(vou_dev->base + reg);
+}
+
+static void sh_vou_reg_a_set(struct sh_vou_device *vou_dev, unsigned int reg,
+                            u32 value, u32 mask)
+{
+       u32 old = __raw_readl(vou_dev->base + reg);
+
+       value = (value & mask) | (old & ~mask);
+       __raw_writel(value, vou_dev->base + reg);
+}
+
+static void sh_vou_reg_b_set(struct sh_vou_device *vou_dev, unsigned int reg,
+                            u32 value, u32 mask)
+{
+       sh_vou_reg_a_set(vou_dev, reg + 0x1000, value, mask);
+}
+
+static void sh_vou_reg_ab_set(struct sh_vou_device *vou_dev, unsigned int reg,
+                             u32 value, u32 mask)
+{
+       sh_vou_reg_a_set(vou_dev, reg, value, mask);
+       sh_vou_reg_b_set(vou_dev, reg, value, mask);
+}
+
+struct sh_vou_fmt {
+       u32             pfmt;
+       char            *desc;
+       unsigned char   bpp;
+       unsigned char   rgb;
+       unsigned char   yf;
+       unsigned char   pkf;
+};
+
+/* Further pixel formats can be added */
+static struct sh_vou_fmt vou_fmt[] = {
+       {
+               .pfmt   = V4L2_PIX_FMT_NV12,
+               .bpp    = 12,
+               .desc   = "YVU420 planar",
+               .yf     = 0,
+               .rgb    = 0,
+       },
+       {
+               .pfmt   = V4L2_PIX_FMT_NV16,
+               .bpp    = 16,
+               .desc   = "YVYU planar",
+               .yf     = 1,
+               .rgb    = 0,
+       },
+       {
+               .pfmt   = V4L2_PIX_FMT_RGB24,
+               .bpp    = 24,
+               .desc   = "RGB24",
+               .pkf    = 2,
+               .rgb    = 1,
+       },
+       {
+               .pfmt   = V4L2_PIX_FMT_RGB565,
+               .bpp    = 16,
+               .desc   = "RGB565",
+               .pkf    = 3,
+               .rgb    = 1,
+       },
+       {
+               .pfmt   = V4L2_PIX_FMT_RGB565X,
+               .bpp    = 16,
+               .desc   = "RGB565 byteswapped",
+               .pkf    = 3,
+               .rgb    = 1,
+       },
+};
+
+static void sh_vou_schedule_next(struct sh_vou_device *vou_dev,
+                                struct videobuf_buffer *vb)
+{
+       dma_addr_t addr1, addr2;
+
+       addr1 = videobuf_to_dma_contig(vb);
+       switch (vou_dev->pix.pixelformat) {
+       case V4L2_PIX_FMT_NV12:
+       case V4L2_PIX_FMT_NV16:
+               addr2 = addr1 + vou_dev->pix.width * vou_dev->pix.height;
+               break;
+       default:
+               addr2 = 0;
+       }
+
+       sh_vou_reg_m_write(vou_dev, VOUAD1R, addr1);
+       sh_vou_reg_m_write(vou_dev, VOUAD2R, addr2);
+}
+
+static void sh_vou_stream_start(struct sh_vou_device *vou_dev,
+                               struct videobuf_buffer *vb)
+{
+       unsigned int row_coeff;
+#ifdef __LITTLE_ENDIAN
+       u32 dataswap = 7;
+#else
+       u32 dataswap = 0;
+#endif
+
+       switch (vou_dev->pix.pixelformat) {
+       case V4L2_PIX_FMT_NV12:
+       case V4L2_PIX_FMT_NV16:
+               row_coeff = 1;
+               break;
+       case V4L2_PIX_FMT_RGB565:
+               dataswap ^= 1;
+       case V4L2_PIX_FMT_RGB565X:
+               row_coeff = 2;
+               break;
+       case V4L2_PIX_FMT_RGB24:
+               row_coeff = 3;
+               break;
+       }
+
+       sh_vou_reg_a_write(vou_dev, VOUSWR, dataswap);
+       sh_vou_reg_ab_write(vou_dev, VOUAIR, vou_dev->pix.width * row_coeff);
+       sh_vou_schedule_next(vou_dev, vb);
+}
+
+static void free_buffer(struct videobuf_queue *vq, struct videobuf_buffer *vb)
+{
+       BUG_ON(in_interrupt());
+
+       /* Wait until this buffer is no longer in STATE_QUEUED or STATE_ACTIVE */
+       videobuf_waiton(vb, 0, 0);
+       videobuf_dma_contig_free(vq, vb);
+       vb->state = VIDEOBUF_NEEDS_INIT;
+}
+
+/* Locking: caller holds vq->vb_lock mutex */
+static int sh_vou_buf_setup(struct videobuf_queue *vq, unsigned int *count,
+                           unsigned int *size)
+{
+       struct video_device *vdev = vq->priv_data;
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       *size = vou_fmt[vou_dev->pix_idx].bpp * vou_dev->pix.width *
+               vou_dev->pix.height / 8;
+
+       if (*count < 2)
+               *count = 2;
+
+       /* Taking into account maximum frame size, *count will stay >= 2 */
+       if (PAGE_ALIGN(*size) * *count > 4 * 1024 * 1024)
+               *count = 4 * 1024 * 1024 / PAGE_ALIGN(*size);
+
+       dev_dbg(vq->dev, "%s(): count=%d, size=%d\n", __func__, *count, *size);
+
+       return 0;
+}
+
+/* Locking: caller holds vq->vb_lock mutex */
+static int sh_vou_buf_prepare(struct videobuf_queue *vq,
+                             struct videobuf_buffer *vb,
+                             enum v4l2_field field)
+{
+       struct video_device *vdev = vq->priv_data;
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct v4l2_pix_format *pix = &vou_dev->pix;
+       int bytes_per_line = vou_fmt[vou_dev->pix_idx].bpp * pix->width / 8;
+       int ret;
+
+       dev_dbg(vq->dev, "%s()\n", __func__);
+
+       if (vb->width   != pix->width ||
+           vb->height  != pix->height ||
+           vb->field   != pix->field) {
+               vb->width       = pix->width;
+               vb->height      = pix->height;
+               vb->field       = field;
+               if (vb->state != VIDEOBUF_NEEDS_INIT)
+                       free_buffer(vq, vb);
+       }
+
+       vb->size = vb->height * bytes_per_line;
+       if (vb->baddr && vb->bsize < vb->size) {
+               /* User buffer too small */
+               dev_warn(vq->dev, "User buffer too small: [%u] @ %lx\n",
+                        vb->bsize, vb->baddr);
+               return -EINVAL;
+       }
+
+       if (vb->state == VIDEOBUF_NEEDS_INIT) {
+               ret = videobuf_iolock(vq, vb, NULL);
+               if (ret < 0) {
+                       dev_warn(vq->dev, "IOLOCK buf-type %d: %d\n",
+                                vb->memory, ret);
+                       return ret;
+               }
+               vb->state = VIDEOBUF_PREPARED;
+       }
+
+       dev_dbg(vq->dev,
+               "%s(): fmt #%d, %u bytes per line, phys 0x%x, type %d, state %d\n",
+               __func__, vou_dev->pix_idx, bytes_per_line,
+               videobuf_to_dma_contig(vb), vb->memory, vb->state);
+
+       return 0;
+}
+
+/* Locking: caller holds vq->vb_lock mutex and vq->irqlock spinlock */
+static void sh_vou_buf_queue(struct videobuf_queue *vq,
+                            struct videobuf_buffer *vb)
+{
+       struct video_device *vdev = vq->priv_data;
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       dev_dbg(vq->dev, "%s()\n", __func__);
+
+       vb->state = VIDEOBUF_QUEUED;
+       list_add_tail(&vb->queue, &vou_dev->queue);
+
+       if (vou_dev->status == SH_VOU_RUNNING) {
+               return;
+       } else if (!vou_dev->active) {
+               vou_dev->active = vb;
+               /* Start from side A: we use mirror addresses, so, set B */
+               sh_vou_reg_a_write(vou_dev, VOURPR, 1);
+               dev_dbg(vq->dev, "%s: first buffer status 0x%x\n", __func__,
+                       sh_vou_reg_a_read(vou_dev, VOUSTR));
+               sh_vou_schedule_next(vou_dev, vb);
+               /* Only activate VOU after the second buffer */
+       } else if (vou_dev->active->queue.next == &vb->queue) {
+               /* Second buffer - initialise register side B */
+               sh_vou_reg_a_write(vou_dev, VOURPR, 0);
+               sh_vou_stream_start(vou_dev, vb);
+
+               /* Register side switching with frame VSYNC */
+               sh_vou_reg_a_write(vou_dev, VOURCR, 5);
+               dev_dbg(vq->dev, "%s: second buffer status 0x%x\n", __func__,
+                       sh_vou_reg_a_read(vou_dev, VOUSTR));
+
+               /* Enable End-of-Frame (VSYNC) interrupts */
+               sh_vou_reg_a_write(vou_dev, VOUIR, 0x10004);
+               /* Two buffers on the queue - activate the hardware */
+
+               vou_dev->status = SH_VOU_RUNNING;
+               sh_vou_reg_a_write(vou_dev, VOUER, 0x107);
+       }
+}
+
+static void sh_vou_buf_release(struct videobuf_queue *vq,
+                              struct videobuf_buffer *vb)
+{
+       struct video_device *vdev = vq->priv_data;
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       unsigned long flags;
+
+       dev_dbg(vq->dev, "%s()\n", __func__);
+
+       spin_lock_irqsave(&vou_dev->lock, flags);
+
+       if (vou_dev->active == vb) {
+               /* disable output */
+               sh_vou_reg_a_set(vou_dev, VOUER, 0, 1);
+               /* ...but the current frame will complete */
+               sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x30000);
+               vou_dev->active = NULL;
+       }
+
+       if ((vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED)) {
+               vb->state = VIDEOBUF_ERROR;
+               list_del(&vb->queue);
+       }
+
+       spin_unlock_irqrestore(&vou_dev->lock, flags);
+
+       free_buffer(vq, vb);
+}
+
+static struct videobuf_queue_ops sh_vou_video_qops = {
+       .buf_setup      = sh_vou_buf_setup,
+       .buf_prepare    = sh_vou_buf_prepare,
+       .buf_queue      = sh_vou_buf_queue,
+       .buf_release    = sh_vou_buf_release,
+};
+
+/* Video IOCTLs */
+static int sh_vou_querycap(struct file *file, void  *priv,
+                          struct v4l2_capability *cap)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       strlcpy(cap->card, "SuperH VOU", sizeof(cap->card));
+       cap->version = KERNEL_VERSION(0, 1, 0);
+       cap->capabilities = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_STREAMING;
+       return 0;
+}
+
+/* Enumerate formats, that the device can accept from the user */
+static int sh_vou_enum_fmt_vid_out(struct file *file, void  *priv,
+                                  struct v4l2_fmtdesc *fmt)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       if (fmt->index >= ARRAY_SIZE(vou_fmt))
+               return -EINVAL;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       strlcpy(fmt->description, vou_fmt[fmt->index].desc,
+               sizeof(fmt->description));
+       fmt->pixelformat = vou_fmt[fmt->index].pfmt;
+
+       return 0;
+}
+
+static int sh_vou_g_fmt_vid_out(struct file *file, void *priv,
+                               struct v4l2_format *fmt)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
+
+       fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       fmt->fmt.pix = vou_dev->pix;
+
+       return 0;
+}
+
+static const unsigned char vou_scale_h_num[] = {1, 9, 2, 9, 4};
+static const unsigned char vou_scale_h_den[] = {1, 8, 1, 4, 1};
+static const unsigned char vou_scale_h_fld[] = {0, 2, 1, 3};
+static const unsigned char vou_scale_v_num[] = {1, 2, 4};
+static const unsigned char vou_scale_v_den[] = {1, 1, 1};
+static const unsigned char vou_scale_v_fld[] = {0, 1};
+
+static void sh_vou_configure_geometry(struct sh_vou_device *vou_dev,
+                                     int pix_idx, int w_idx, int h_idx)
+{
+       struct sh_vou_fmt *fmt = vou_fmt + pix_idx;
+       unsigned int black_left, black_top, width_max, height_max,
+               frame_in_height, frame_out_height, frame_out_top;
+       struct v4l2_rect *rect = &vou_dev->rect;
+       struct v4l2_pix_format *pix = &vou_dev->pix;
+       u32 vouvcr = 0, dsr_h, dsr_v;
+
+       if (vou_dev->std & V4L2_STD_525_60) {
+               width_max = 858;
+               height_max = 262;
+       } else {
+               width_max = 864;
+               height_max = 312;
+       }
+
+       frame_in_height = pix->height / 2;
+       frame_out_height = rect->height / 2;
+       frame_out_top = rect->top / 2;
+
+       /*
+        * Cropping scheme: max useful image is 720x480, and the total video
+        * area is 858x525 (NTSC) or 864x625 (PAL). AK8813 / 8814 starts
+        * sampling data beginning with fixed 276th (NTSC) / 288th (PAL) clock,
+        * of which the first 33 / 25 clocks HSYNC must be held active. This
+        * has to be configured in CR[HW]. 1 pixel equals 2 clock periods.
+        * This gives CR[HW] = 16 / 12, VPR[HVP] = 138 / 144, which gives
+        * exactly 858 - 138 = 864 - 144 = 720! We call the out-of-display area,
+        * beyond DSR, specified on the left and top by the VPR register "black
+        * pixels" and out-of-image area (DPR) "background pixels." We fix VPR
+        * at 138 / 144 : 20, because that's the HSYNC timing, that our first
+        * client requires, and that's exactly what leaves us 720 pixels for the
+        * image; we leave VPR[VVP] at default 20 for now, because the client
+        * doesn't seem to have any special requirements for it. Otherwise we
+        * could also set it to max - 240 = 22 / 72. Thus VPR depends only on
+        * the selected standard, and DPR and DSR are selected according to
+        * cropping. Q: how does the client detect the first valid line? Does
+        * HSYNC stay inactive during invalid (black) lines?
+        */
+       black_left = width_max - VOU_MAX_IMAGE_WIDTH;
+       black_top = 20;
+
+       dsr_h = rect->width + rect->left;
+       dsr_v = frame_out_height + frame_out_top;
+
+       dev_dbg(vou_dev->v4l2_dev.dev,
+               "image %ux%u, black %u:%u, offset %u:%u, display %ux%u\n",
+               pix->width, frame_in_height, black_left, black_top,
+               rect->left, frame_out_top, dsr_h, dsr_v);
+
+       /* VOUISR height - half of a frame height in frame mode */
+       sh_vou_reg_ab_write(vou_dev, VOUISR, (pix->width << 16) | frame_in_height);
+       sh_vou_reg_ab_write(vou_dev, VOUVPR, (black_left << 16) | black_top);
+       sh_vou_reg_ab_write(vou_dev, VOUDPR, (rect->left << 16) | frame_out_top);
+       sh_vou_reg_ab_write(vou_dev, VOUDSR, (dsr_h << 16) | dsr_v);
+
+       /*
+        * if necessary, we could set VOUHIR to
+        * max(black_left + dsr_h, width_max) here
+        */
+
+       if (w_idx)
+               vouvcr |= (1 << 15) | (vou_scale_h_fld[w_idx - 1] << 4);
+       if (h_idx)
+               vouvcr |= (1 << 14) | vou_scale_v_fld[h_idx - 1];
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s: scaling 0x%x\n", fmt->desc, vouvcr);
+
+       /* To produce a colour bar for testing set bit 23 of VOUVCR */
+       sh_vou_reg_ab_write(vou_dev, VOUVCR, vouvcr);
+       sh_vou_reg_ab_write(vou_dev, VOUDFR,
+                           fmt->pkf | (fmt->yf << 8) | (fmt->rgb << 16));
+}
+
+struct sh_vou_geometry {
+       struct v4l2_rect output;
+       unsigned int in_width;
+       unsigned int in_height;
+       int scale_idx_h;
+       int scale_idx_v;
+};
+
+/*
+ * Find input geometry, that we can use to produce output, closest to the
+ * requested rectangle, using VOU scaling
+ */
+static void vou_adjust_input(struct sh_vou_geometry *geo, v4l2_std_id std)
+{
+       /* The compiler cannot know, that best and idx will indeed be set */
+       unsigned int best_err = UINT_MAX, best = 0, width_max, height_max;
+       int i, idx = 0;
+
+       if (std & V4L2_STD_525_60) {
+               width_max = 858;
+               height_max = 262;
+       } else {
+               width_max = 864;
+               height_max = 312;
+       }
+
+       /* Image width must be a multiple of 4 */
+       v4l_bound_align_image(&geo->in_width, 0, VOU_MAX_IMAGE_WIDTH, 2,
+                             &geo->in_height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0);
+
+       /* Select scales to come as close as possible to the output image */
+       for (i = ARRAY_SIZE(vou_scale_h_num) - 1; i >= 0; i--) {
+               unsigned int err;
+               unsigned int found = geo->output.width * vou_scale_h_den[i] /
+                       vou_scale_h_num[i];
+
+               if (found > VOU_MAX_IMAGE_WIDTH)
+                       /* scales increase */
+                       break;
+
+               err = abs(found - geo->in_width);
+               if (err < best_err) {
+                       best_err = err;
+                       idx = i;
+                       best = found;
+               }
+               if (!err)
+                       break;
+       }
+
+       geo->in_width = best;
+       geo->scale_idx_h = idx;
+
+       best_err = UINT_MAX;
+
+       /* This loop can be replaced with one division */
+       for (i = ARRAY_SIZE(vou_scale_v_num) - 1; i >= 0; i--) {
+               unsigned int err;
+               unsigned int found = geo->output.height * vou_scale_v_den[i] /
+                       vou_scale_v_num[i];
+
+               if (found > VOU_MAX_IMAGE_HEIGHT)
+                       /* scales increase */
+                       break;
+
+               err = abs(found - geo->in_height);
+               if (err < best_err) {
+                       best_err = err;
+                       idx = i;
+                       best = found;
+               }
+               if (!err)
+                       break;
+       }
+
+       geo->in_height = best;
+       geo->scale_idx_v = idx;
+}
+
+/*
+ * Find output geometry, that we can produce, using VOU scaling, closest to
+ * the requested rectangle
+ */
+static void vou_adjust_output(struct sh_vou_geometry *geo, v4l2_std_id std)
+{
+       unsigned int best_err = UINT_MAX, best, width_max, height_max;
+       int i, idx;
+
+       if (std & V4L2_STD_525_60) {
+               width_max = 858;
+               height_max = 262 * 2;
+       } else {
+               width_max = 864;
+               height_max = 312 * 2;
+       }
+
+       /* Select scales to come as close as possible to the output image */
+       for (i = 0; i < ARRAY_SIZE(vou_scale_h_num); i++) {
+               unsigned int err;
+               unsigned int found = geo->in_width * vou_scale_h_num[i] /
+                       vou_scale_h_den[i];
+
+               if (found > VOU_MAX_IMAGE_WIDTH)
+                       /* scales increase */
+                       break;
+
+               err = abs(found - geo->output.width);
+               if (err < best_err) {
+                       best_err = err;
+                       idx = i;
+                       best = found;
+               }
+               if (!err)
+                       break;
+       }
+
+       geo->output.width = best;
+       geo->scale_idx_h = idx;
+       if (geo->output.left + best > width_max)
+               geo->output.left = width_max - best;
+
+       pr_debug("%s(): W %u * %u/%u = %u\n", __func__, geo->in_width,
+                vou_scale_h_num[idx], vou_scale_h_den[idx], best);
+
+       best_err = UINT_MAX;
+
+       /* This loop can be replaced with one division */
+       for (i = 0; i < ARRAY_SIZE(vou_scale_v_num); i++) {
+               unsigned int err;
+               unsigned int found = geo->in_height * vou_scale_v_num[i] /
+                       vou_scale_v_den[i];
+
+               if (found > VOU_MAX_IMAGE_HEIGHT)
+                       /* scales increase */
+                       break;
+
+               err = abs(found - geo->output.height);
+               if (err < best_err) {
+                       best_err = err;
+                       idx = i;
+                       best = found;
+               }
+               if (!err)
+                       break;
+       }
+
+       geo->output.height = best;
+       geo->scale_idx_v = idx;
+       if (geo->output.top + best > height_max)
+               geo->output.top = height_max - best;
+
+       pr_debug("%s(): H %u * %u/%u = %u\n", __func__, geo->in_height,
+                vou_scale_v_num[idx], vou_scale_v_den[idx], best);
+}
+
+static int sh_vou_s_fmt_vid_out(struct file *file, void *priv,
+                               struct v4l2_format *fmt)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+       int pix_idx;
+       struct sh_vou_geometry geo;
+       struct v4l2_mbus_framefmt mbfmt = {
+               /* Revisit: is this the correct code? */
+               .code = V4L2_MBUS_FMT_YUYV8_2X8_LE,
+               .field = V4L2_FIELD_INTERLACED,
+               .colorspace = V4L2_COLORSPACE_SMPTE170M,
+       };
+       int ret;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__,
+               vou_dev->rect.width, vou_dev->rect.height,
+               pix->width, pix->height);
+
+       if (pix->field == V4L2_FIELD_ANY)
+               pix->field = V4L2_FIELD_NONE;
+
+       if (fmt->type != V4L2_BUF_TYPE_VIDEO_OUTPUT ||
+           pix->field != V4L2_FIELD_NONE)
+               return -EINVAL;
+
+       for (pix_idx = 0; pix_idx < ARRAY_SIZE(vou_fmt); pix_idx++)
+               if (vou_fmt[pix_idx].pfmt == pix->pixelformat)
+                       break;
+
+       if (pix_idx == ARRAY_SIZE(vou_fmt))
+               return -EINVAL;
+
+       /* Image width must be a multiple of 4 */
+       v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 2,
+                             &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0);
+
+       geo.in_width = pix->width;
+       geo.in_height = pix->height;
+       geo.output = vou_dev->rect;
+
+       vou_adjust_output(&geo, vou_dev->std);
+
+       mbfmt.width = geo.output.width;
+       mbfmt.height = geo.output.height;
+       ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
+                                        s_mbus_fmt, &mbfmt);
+       /* Must be implemented, so, don't check for -ENOIOCTLCMD */
+       if (ret < 0)
+               return ret;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u -> %ux%u\n", __func__,
+               geo.output.width, geo.output.height, mbfmt.width, mbfmt.height);
+
+       /* Sanity checks */
+       if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH ||
+           (unsigned)mbfmt.height > VOU_MAX_IMAGE_HEIGHT ||
+           mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8_LE)
+               return -EIO;
+
+       if (mbfmt.width != geo.output.width ||
+           mbfmt.height != geo.output.height) {
+               geo.output.width = mbfmt.width;
+               geo.output.height = mbfmt.height;
+
+               vou_adjust_input(&geo, vou_dev->std);
+       }
+
+       /* We tried to preserve output rectangle, but it could have changed */
+       vou_dev->rect = geo.output;
+       pix->width = geo.in_width;
+       pix->height = geo.in_height;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u\n", __func__,
+               pix->width, pix->height);
+
+       vou_dev->pix_idx = pix_idx;
+
+       vou_dev->pix = *pix;
+
+       sh_vou_configure_geometry(vou_dev, pix_idx,
+                                 geo.scale_idx_h, geo.scale_idx_v);
+
+       return 0;
+}
+
+static int sh_vou_try_fmt_vid_out(struct file *file, void *priv,
+                                 struct v4l2_format *fmt)
+{
+       struct sh_vou_file *vou_file = priv;
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+       int i;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       pix->field = V4L2_FIELD_NONE;
+
+       v4l_bound_align_image(&pix->width, 0, VOU_MAX_IMAGE_WIDTH, 1,
+                             &pix->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0);
+
+       for (i = 0; ARRAY_SIZE(vou_fmt); i++)
+               if (vou_fmt[i].pfmt == pix->pixelformat)
+                       return 0;
+
+       pix->pixelformat = vou_fmt[0].pfmt;
+
+       return 0;
+}
+
+static int sh_vou_reqbufs(struct file *file, void *priv,
+                         struct v4l2_requestbuffers *req)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       if (req->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+
+       return videobuf_reqbufs(&vou_file->vbq, req);
+}
+
+static int sh_vou_querybuf(struct file *file, void *priv,
+                          struct v4l2_buffer *b)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       return videobuf_querybuf(&vou_file->vbq, b);
+}
+
+static int sh_vou_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       return videobuf_qbuf(&vou_file->vbq, b);
+}
+
+static int sh_vou_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       return videobuf_dqbuf(&vou_file->vbq, b, file->f_flags & O_NONBLOCK);
+}
+
+static int sh_vou_streamon(struct file *file, void *priv,
+                          enum v4l2_buf_type buftype)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct sh_vou_file *vou_file = priv;
+       int ret;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0,
+                                        video, s_stream, 1);
+       if (ret < 0 && ret != -ENOIOCTLCMD)
+               return ret;
+
+       /* This calls our .buf_queue() (== sh_vou_buf_queue) */
+       return videobuf_streamon(&vou_file->vbq);
+}
+
+static int sh_vou_streamoff(struct file *file, void *priv,
+                           enum v4l2_buf_type buftype)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       /*
+        * This calls buf_release from host driver's videobuf_queue_ops for all
+        * remaining buffers. When the last buffer is freed, stop streaming
+        */
+       videobuf_streamoff(&vou_file->vbq);
+       v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video, s_stream, 0);
+
+       return 0;
+}
+
+static u32 sh_vou_ntsc_mode(enum sh_vou_bus_fmt bus_fmt)
+{
+       switch (bus_fmt) {
+       default:
+               pr_warning("%s(): Invalid bus-format code %d, using default 8-bit\n",
+                          __func__, bus_fmt);
+       case SH_VOU_BUS_8BIT:
+               return 1;
+       case SH_VOU_BUS_16BIT:
+               return 0;
+       case SH_VOU_BUS_BT656:
+               return 3;
+       }
+}
+
+static int sh_vou_s_std(struct file *file, void *priv, v4l2_std_id *std_id)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       int ret;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s(): 0x%llx\n", __func__, *std_id);
+
+       if (*std_id & ~vdev->tvnorms)
+               return -EINVAL;
+
+       ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
+                                        s_std_output, *std_id);
+       /* Shall we continue, if the subdev doesn't support .s_std_output()? */
+       if (ret < 0 && ret != -ENOIOCTLCMD)
+               return ret;
+
+       if (*std_id & V4L2_STD_525_60)
+               sh_vou_reg_ab_set(vou_dev, VOUCR,
+                       sh_vou_ntsc_mode(vou_dev->pdata->bus_fmt) << 29, 7 << 29);
+       else
+               sh_vou_reg_ab_set(vou_dev, VOUCR, 5 << 29, 7 << 29);
+
+       vou_dev->std = *std_id;
+
+       return 0;
+}
+
+static int sh_vou_g_std(struct file *file, void *priv, v4l2_std_id *std)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
+
+       *std = vou_dev->std;
+
+       return 0;
+}
+
+static int sh_vou_g_crop(struct file *file, void *fh, struct v4l2_crop *a)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
+
+       a->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       a->c = vou_dev->rect;
+
+       return 0;
+}
+
+/* Assume a dull encoder, do all the work ourselves. */
+static int sh_vou_s_crop(struct file *file, void *fh, struct v4l2_crop *a)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct v4l2_rect *rect = &a->c;
+       struct v4l2_crop sd_crop = {.type = V4L2_BUF_TYPE_VIDEO_OUTPUT};
+       struct v4l2_pix_format *pix = &vou_dev->pix;
+       struct sh_vou_geometry geo;
+       struct v4l2_mbus_framefmt mbfmt = {
+               /* Revisit: is this the correct code? */
+               .code = V4L2_MBUS_FMT_YUYV8_2X8_LE,
+               .field = V4L2_FIELD_INTERLACED,
+               .colorspace = V4L2_COLORSPACE_SMPTE170M,
+       };
+       int ret;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s(): %ux%u@%u:%u\n", __func__,
+               rect->width, rect->height, rect->left, rect->top);
+
+       if (a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
+               return -EINVAL;
+
+       v4l_bound_align_image(&rect->width, 0, VOU_MAX_IMAGE_WIDTH, 1,
+                             &rect->height, 0, VOU_MAX_IMAGE_HEIGHT, 1, 0);
+
+       if (rect->width + rect->left > VOU_MAX_IMAGE_WIDTH)
+               rect->left = VOU_MAX_IMAGE_WIDTH - rect->width;
+
+       if (rect->height + rect->top > VOU_MAX_IMAGE_HEIGHT)
+               rect->top = VOU_MAX_IMAGE_HEIGHT - rect->height;
+
+       geo.output = *rect;
+       geo.in_width = pix->width;
+       geo.in_height = pix->height;
+
+       /* Configure the encoder one-to-one, position at 0, ignore errors */
+       sd_crop.c.width = geo.output.width;
+       sd_crop.c.height = geo.output.height;
+       /*
+        * We first issue a S_CROP, so that the subsequent S_FMT delivers the
+        * final encoder configuration.
+        */
+       v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
+                                  s_crop, &sd_crop);
+       mbfmt.width = geo.output.width;
+       mbfmt.height = geo.output.height;
+       ret = v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, video,
+                                        s_mbus_fmt, &mbfmt);
+       /* Must be implemented, so, don't check for -ENOIOCTLCMD */
+       if (ret < 0)
+               return ret;
+
+       /* Sanity checks */
+       if ((unsigned)mbfmt.width > VOU_MAX_IMAGE_WIDTH ||
+           (unsigned)mbfmt.height > VOU_MAX_IMAGE_HEIGHT ||
+           mbfmt.code != V4L2_MBUS_FMT_YUYV8_2X8_LE)
+               return -EIO;
+
+       geo.output.width = mbfmt.width;
+       geo.output.height = mbfmt.height;
+
+       /*
+        * No down-scaling. According to the API, current call has precedence:
+        * http://v4l2spec.bytesex.org/spec/x1904.htm#AEN1954 paragraph two.
+        */
+       vou_adjust_input(&geo, vou_dev->std);
+
+       /* We tried to preserve output rectangle, but it could have changed */
+       vou_dev->rect = geo.output;
+       pix->width = geo.in_width;
+       pix->height = geo.in_height;
+
+       sh_vou_configure_geometry(vou_dev, vou_dev->pix_idx,
+                                 geo.scale_idx_h, geo.scale_idx_v);
+
+       return 0;
+}
+
+/*
+ * Total field: NTSC 858 x 2 * 262/263, PAL 864 x 2 * 312/313, default rectangle
+ * is the initial register values, height takes the interlaced format into
+ * account. The actual image can only go up to 720 x 2 * 240, So, VOUVPR can
+ * actually only meaningfully contain values <= 720 and <= 240 respectively, and
+ * not <= 864 and <= 312.
+ */
+static int sh_vou_cropcap(struct file *file, void *priv,
+                         struct v4l2_cropcap *a)
+{
+       struct sh_vou_file *vou_file = priv;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       a->type                         = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+       a->bounds.left                  = 0;
+       a->bounds.top                   = 0;
+       a->bounds.width                 = VOU_MAX_IMAGE_WIDTH;
+       a->bounds.height                = VOU_MAX_IMAGE_HEIGHT;
+       /* Default = max, set VOUDPR = 0, which is not hardware default */
+       a->defrect.left                 = 0;
+       a->defrect.top                  = 0;
+       a->defrect.width                = VOU_MAX_IMAGE_WIDTH;
+       a->defrect.height               = VOU_MAX_IMAGE_HEIGHT;
+       a->pixelaspect.numerator        = 1;
+       a->pixelaspect.denominator      = 1;
+
+       return 0;
+}
+
+static irqreturn_t sh_vou_isr(int irq, void *dev_id)
+{
+       struct sh_vou_device *vou_dev = dev_id;
+       static unsigned long j;
+       struct videobuf_buffer *vb;
+       static int cnt;
+       static int side;
+       u32 irq_status = sh_vou_reg_a_read(vou_dev, VOUIR), masked;
+       u32 vou_status = sh_vou_reg_a_read(vou_dev, VOUSTR);
+
+       if (!(irq_status & 0x300)) {
+               if (printk_timed_ratelimit(&j, 500))
+                       dev_warn(vou_dev->v4l2_dev.dev, "IRQ status 0x%x!\n",
+                                irq_status);
+               return IRQ_NONE;
+       }
+
+       spin_lock(&vou_dev->lock);
+       if (!vou_dev->active || list_empty(&vou_dev->queue)) {
+               if (printk_timed_ratelimit(&j, 500))
+                       dev_warn(vou_dev->v4l2_dev.dev,
+                                "IRQ without active buffer: %x!\n", irq_status);
+               /* Just ack: buf_release will disable further interrupts */
+               sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x300);
+               spin_unlock(&vou_dev->lock);
+               return IRQ_HANDLED;
+       }
+
+       masked = ~(0x300 & irq_status) & irq_status & 0x30304;
+       dev_dbg(vou_dev->v4l2_dev.dev,
+               "IRQ status 0x%x -> 0x%x, VOU status 0x%x, cnt %d\n",
+               irq_status, masked, vou_status, cnt);
+
+       cnt++;
+       side = vou_status & 0x10000;
+
+       /* Clear only set interrupts */
+       sh_vou_reg_a_write(vou_dev, VOUIR, masked);
+
+       vb = vou_dev->active;
+       list_del(&vb->queue);
+
+       vb->state = VIDEOBUF_DONE;
+       do_gettimeofday(&vb->ts);
+       vb->field_count++;
+       wake_up(&vb->done);
+
+       if (list_empty(&vou_dev->queue)) {
+               /* Stop VOU */
+               dev_dbg(vou_dev->v4l2_dev.dev, "%s: queue empty after %d\n",
+                       __func__, cnt);
+               sh_vou_reg_a_set(vou_dev, VOUER, 0, 1);
+               vou_dev->active = NULL;
+               vou_dev->status = SH_VOU_INITIALISING;
+               /* Disable End-of-Frame (VSYNC) interrupts */
+               sh_vou_reg_a_set(vou_dev, VOUIR, 0, 0x30000);
+               spin_unlock(&vou_dev->lock);
+               return IRQ_HANDLED;
+       }
+
+       vou_dev->active = list_entry(vou_dev->queue.next,
+                                    struct videobuf_buffer, queue);
+
+       if (vou_dev->active->queue.next != &vou_dev->queue) {
+               struct videobuf_buffer *new = list_entry(vou_dev->active->queue.next,
+                                               struct videobuf_buffer, queue);
+               sh_vou_schedule_next(vou_dev, new);
+       }
+
+       spin_unlock(&vou_dev->lock);
+
+       return IRQ_HANDLED;
+}
+
+static int sh_vou_hw_init(struct sh_vou_device *vou_dev)
+{
+       struct sh_vou_pdata *pdata = vou_dev->pdata;
+       u32 voucr = sh_vou_ntsc_mode(pdata->bus_fmt) << 29;
+       int i = 100;
+
+       /* Disable all IRQs */
+       sh_vou_reg_a_write(vou_dev, VOUIR, 0);
+
+       /* Reset VOU interfaces - registers unaffected */
+       sh_vou_reg_a_write(vou_dev, VOUSRR, 0x101);
+       while (--i && (sh_vou_reg_a_read(vou_dev, VOUSRR) & 0x101))
+               udelay(1);
+
+       if (!i)
+               return -ETIMEDOUT;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "Reset took %dus\n", 100 - i);
+
+       if (pdata->flags & SH_VOU_PCLK_FALLING)
+               voucr |= 1 << 28;
+       if (pdata->flags & SH_VOU_HSYNC_LOW)
+               voucr |= 1 << 27;
+       if (pdata->flags & SH_VOU_VSYNC_LOW)
+               voucr |= 1 << 26;
+       sh_vou_reg_ab_set(vou_dev, VOUCR, voucr, 0xfc000000);
+
+       /* Manual register side switching at first */
+       sh_vou_reg_a_write(vou_dev, VOURCR, 4);
+       /* Default - fixed HSYNC length, can be made configurable is required */
+       sh_vou_reg_ab_write(vou_dev, VOUMSR, 0x800000);
+
+       return 0;
+}
+
+/* File operations */
+static int sh_vou_open(struct file *file)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct sh_vou_file *vou_file = kzalloc(sizeof(struct sh_vou_file),
+                                              GFP_KERNEL);
+
+       if (!vou_file)
+               return -ENOMEM;
+
+       dev_dbg(vou_dev->v4l2_dev.dev, "%s()\n", __func__);
+
+       file->private_data = vou_file;
+
+       if (atomic_inc_return(&vou_dev->use_count) == 1) {
+               int ret;
+               /* First open */
+               vou_dev->status = SH_VOU_INITIALISING;
+               pm_runtime_get_sync(vdev->v4l2_dev->dev);
+               ret = sh_vou_hw_init(vou_dev);
+               if (ret < 0) {
+                       atomic_dec(&vou_dev->use_count);
+                       pm_runtime_put(vdev->v4l2_dev->dev);
+                       vou_dev->status = SH_VOU_IDLE;
+                       return ret;
+               }
+       }
+
+       videobuf_queue_dma_contig_init(&vou_file->vbq, &sh_vou_video_qops,
+                                      vou_dev->v4l2_dev.dev, &vou_dev->lock,
+                                      V4L2_BUF_TYPE_VIDEO_OUTPUT,
+                                      V4L2_FIELD_NONE,
+                                      sizeof(struct videobuf_buffer), vdev);
+
+       return 0;
+}
+
+static int sh_vou_release(struct file *file)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+       struct sh_vou_file *vou_file = file->private_data;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       if (!atomic_dec_return(&vou_dev->use_count)) {
+               /* Last close */
+               vou_dev->status = SH_VOU_IDLE;
+               sh_vou_reg_a_set(vou_dev, VOUER, 0, 0x101);
+               pm_runtime_put(vdev->v4l2_dev->dev);
+       }
+
+       file->private_data = NULL;
+       kfree(vou_file);
+
+       return 0;
+}
+
+static int sh_vou_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       struct sh_vou_file *vou_file = file->private_data;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       return videobuf_mmap_mapper(&vou_file->vbq, vma);
+}
+
+static unsigned int sh_vou_poll(struct file *file, poll_table *wait)
+{
+       struct sh_vou_file *vou_file = file->private_data;
+
+       dev_dbg(vou_file->vbq.dev, "%s()\n", __func__);
+
+       return videobuf_poll_stream(file, &vou_file->vbq, wait);
+}
+
+static int sh_vou_g_chip_ident(struct file *file, void *fh,
+                                  struct v4l2_dbg_chip_ident *id)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_chip_ident, id);
+}
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int sh_vou_g_register(struct file *file, void *fh,
+                                struct v4l2_dbg_register *reg)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, g_register, reg);
+}
+
+static int sh_vou_s_register(struct file *file, void *fh,
+                                struct v4l2_dbg_register *reg)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct sh_vou_device *vou_dev = video_get_drvdata(vdev);
+
+       return v4l2_device_call_until_err(&vou_dev->v4l2_dev, 0, core, s_register, reg);
+}
+#endif
+
+/* sh_vou display ioctl operations */
+static const struct v4l2_ioctl_ops sh_vou_ioctl_ops = {
+       .vidioc_querycap                = sh_vou_querycap,
+       .vidioc_enum_fmt_vid_out        = sh_vou_enum_fmt_vid_out,
+       .vidioc_g_fmt_vid_out           = sh_vou_g_fmt_vid_out,
+       .vidioc_s_fmt_vid_out           = sh_vou_s_fmt_vid_out,
+       .vidioc_try_fmt_vid_out         = sh_vou_try_fmt_vid_out,
+       .vidioc_reqbufs                 = sh_vou_reqbufs,
+       .vidioc_querybuf                = sh_vou_querybuf,
+       .vidioc_qbuf                    = sh_vou_qbuf,
+       .vidioc_dqbuf                   = sh_vou_dqbuf,
+       .vidioc_streamon                = sh_vou_streamon,
+       .vidioc_streamoff               = sh_vou_streamoff,
+       .vidioc_s_std                   = sh_vou_s_std,
+       .vidioc_g_std                   = sh_vou_g_std,
+       .vidioc_cropcap                 = sh_vou_cropcap,
+       .vidioc_g_crop                  = sh_vou_g_crop,
+       .vidioc_s_crop                  = sh_vou_s_crop,
+       .vidioc_g_chip_ident            = sh_vou_g_chip_ident,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       .vidioc_g_register              = sh_vou_g_register,
+       .vidioc_s_register              = sh_vou_s_register,
+#endif
+};
+
+static const struct v4l2_file_operations sh_vou_fops = {
+       .owner          = THIS_MODULE,
+       .open           = sh_vou_open,
+       .release        = sh_vou_release,
+       .ioctl          = video_ioctl2,
+       .mmap           = sh_vou_mmap,
+       .poll           = sh_vou_poll,
+};
+
+static const struct video_device sh_vou_video_template = {
+       .name           = "sh_vou",
+       .fops           = &sh_vou_fops,
+       .ioctl_ops      = &sh_vou_ioctl_ops,
+       .tvnorms        = V4L2_STD_525_60, /* PAL only supported in 8-bit non-bt656 mode */
+       .current_norm   = V4L2_STD_NTSC_M,
+};
+
+static int __devinit sh_vou_probe(struct platform_device *pdev)
+{
+       struct sh_vou_pdata *vou_pdata = pdev->dev.platform_data;
+       struct v4l2_rect *rect;
+       struct v4l2_pix_format *pix;
+       struct i2c_adapter *i2c_adap;
+       struct video_device *vdev;
+       struct sh_vou_device *vou_dev;
+       struct resource *reg_res, *region;
+       struct v4l2_subdev *subdev;
+       int irq, ret;
+
+       reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       irq = platform_get_irq(pdev, 0);
+
+       if (!vou_pdata || !reg_res || irq <= 0) {
+               dev_err(&pdev->dev, "Insufficient VOU platform information.\n");
+               return -ENODEV;
+       }
+
+       vou_dev = kzalloc(sizeof(*vou_dev), GFP_KERNEL);
+       if (!vou_dev)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&vou_dev->queue);
+       spin_lock_init(&vou_dev->lock);
+       atomic_set(&vou_dev->use_count, 0);
+       vou_dev->pdata = vou_pdata;
+       vou_dev->status = SH_VOU_IDLE;
+
+       rect = &vou_dev->rect;
+       pix = &vou_dev->pix;
+
+       /* Fill in defaults */
+       vou_dev->std            = sh_vou_video_template.current_norm;
+       rect->left              = 0;
+       rect->top               = 0;
+       rect->width             = VOU_MAX_IMAGE_WIDTH;
+       rect->height            = VOU_MAX_IMAGE_HEIGHT;
+       pix->width              = VOU_MAX_IMAGE_WIDTH;
+       pix->height             = VOU_MAX_IMAGE_HEIGHT;
+       pix->pixelformat        = V4L2_PIX_FMT_YVYU;
+       pix->field              = V4L2_FIELD_NONE;
+       pix->bytesperline       = VOU_MAX_IMAGE_WIDTH * 2;
+       pix->sizeimage          = VOU_MAX_IMAGE_WIDTH * 2 * VOU_MAX_IMAGE_HEIGHT;
+       pix->colorspace         = V4L2_COLORSPACE_SMPTE170M;
+
+       region = request_mem_region(reg_res->start, resource_size(reg_res),
+                                   pdev->name);
+       if (!region) {
+               dev_err(&pdev->dev, "VOU region already claimed\n");
+               ret = -EBUSY;
+               goto ereqmemreg;
+       }
+
+       vou_dev->base = ioremap(reg_res->start, resource_size(reg_res));
+       if (!vou_dev->base) {
+               ret = -ENOMEM;
+               goto emap;
+       }
+
+       ret = request_irq(irq, sh_vou_isr, 0, "vou", vou_dev);
+       if (ret < 0)
+               goto ereqirq;
+
+       ret = v4l2_device_register(&pdev->dev, &vou_dev->v4l2_dev);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "Error registering v4l2 device\n");
+               goto ev4l2devreg;
+       }
+
+       /* Allocate memory for video device */
+       vdev = video_device_alloc();
+       if (vdev == NULL) {
+               ret = -ENOMEM;
+               goto evdevalloc;
+       }
+
+       *vdev = sh_vou_video_template;
+       if (vou_pdata->bus_fmt == SH_VOU_BUS_8BIT)
+               vdev->tvnorms |= V4L2_STD_PAL;
+       vdev->v4l2_dev = &vou_dev->v4l2_dev;
+       vdev->release = video_device_release;
+
+       vou_dev->vdev = vdev;
+       video_set_drvdata(vdev, vou_dev);
+
+       pm_runtime_enable(&pdev->dev);
+       pm_runtime_resume(&pdev->dev);
+
+       i2c_adap = i2c_get_adapter(vou_pdata->i2c_adap);
+       if (!i2c_adap) {
+               ret = -ENODEV;
+               goto ei2cgadap;
+       }
+
+       ret = sh_vou_hw_init(vou_dev);
+       if (ret < 0)
+               goto ereset;
+
+       subdev = v4l2_i2c_new_subdev_board(&vou_dev->v4l2_dev, i2c_adap,
+                       vou_pdata->module_name, vou_pdata->board_info, NULL);
+       if (!subdev) {
+               ret = -ENOMEM;
+               goto ei2cnd;
+       }
+
+       ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
+       if (ret < 0)
+               goto evregdev;
+
+       return 0;
+
+evregdev:
+ei2cnd:
+ereset:
+       i2c_put_adapter(i2c_adap);
+ei2cgadap:
+       video_device_release(vdev);
+       pm_runtime_disable(&pdev->dev);
+evdevalloc:
+       v4l2_device_unregister(&vou_dev->v4l2_dev);
+ev4l2devreg:
+       free_irq(irq, vou_dev);
+ereqirq:
+       iounmap(vou_dev->base);
+emap:
+       release_mem_region(reg_res->start, resource_size(reg_res));
+ereqmemreg:
+       kfree(vou_dev);
+       return ret;
+}
+
+static int __devexit sh_vou_remove(struct platform_device *pdev)
+{
+       int irq = platform_get_irq(pdev, 0);
+       struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+       struct sh_vou_device *vou_dev = container_of(v4l2_dev,
+                                               struct sh_vou_device, v4l2_dev);
+       struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next,
+                                           struct v4l2_subdev, list);
+       struct i2c_client *client = v4l2_get_subdevdata(sd);
+       struct resource *reg_res;
+
+       if (irq > 0)
+               free_irq(irq, vou_dev);
+       pm_runtime_disable(&pdev->dev);
+       video_unregister_device(vou_dev->vdev);
+       i2c_put_adapter(client->adapter);
+       v4l2_device_unregister(&vou_dev->v4l2_dev);
+       iounmap(vou_dev->base);
+       reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (reg_res)
+               release_mem_region(reg_res->start, resource_size(reg_res));
+       kfree(vou_dev);
+       return 0;
+}
+
+static struct platform_driver __refdata sh_vou = {
+       .remove  = __devexit_p(sh_vou_remove),
+       .driver  = {
+               .name   = "sh-vou",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init sh_vou_init(void)
+{
+       return platform_driver_probe(&sh_vou, sh_vou_probe);
+}
+
+static void __exit sh_vou_exit(void)
+{
+       platform_driver_unregister(&sh_vou);
+}
+
+module_init(sh_vou_init);
+module_exit(sh_vou_exit);
+
+MODULE_DESCRIPTION("SuperH VOU driver");
+MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform:sh-vou");
index cbf8087..28e19da 100644 (file)
@@ -2295,7 +2295,7 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
        if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                return -EFAULT;
 
-       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
+       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) {
                if (ctrl.id == s->qctrl[i].id) {
                        if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
                                return -EINVAL;
@@ -2305,7 +2305,9 @@ sn9c102_vidioc_s_ctrl(struct sn9c102_device* cam, void __user * arg)
                        ctrl.value -= ctrl.value % s->qctrl[i].step;
                        break;
                }
-
+       }
+       if (i == ARRAY_SIZE(s->qctrl))
+               return -EINVAL;
        if ((err = s->set_ctrl(cam, &ctrl)))
                return err;
 
index cc40d6b..522ba3f 100644 (file)
@@ -40,12 +40,12 @@ struct sn9c102_device;
 
 static const struct usb_device_id sn9c102_id_table[] = {
        /* SN9C101 and SN9C102 */
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x6001, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x6005, BRIDGE_SN9C102), },
 #endif
        { SN9C102_USB_DEVICE(0x0c45, 0x6007, BRIDGE_SN9C102), },
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x6009, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x600d, BRIDGE_SN9C102), },
 /*     { SN9C102_USB_DEVICE(0x0c45, 0x6011, BRIDGE_SN9C102), }, OV6650 */
@@ -53,13 +53,13 @@ static const struct usb_device_id sn9c102_id_table[] = {
        { SN9C102_USB_DEVICE(0x0c45, 0x6019, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x6024, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x6025, BRIDGE_SN9C102), },
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x6028, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x6029, BRIDGE_SN9C102), },
 #endif
        { SN9C102_USB_DEVICE(0x0c45, 0x602a, BRIDGE_SN9C102), },
        { SN9C102_USB_DEVICE(0x0c45, 0x602b, BRIDGE_SN9C102), },
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x602c, BRIDGE_SN9C102), },
 /*     { SN9C102_USB_DEVICE(0x0c45, 0x602d, BRIDGE_SN9C102), }, HV7131R */
 #endif
@@ -74,7 +74,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
        { SN9C102_USB_DEVICE(0x0c45, 0x608b, BRIDGE_SN9C103), },
        { SN9C102_USB_DEVICE(0x0c45, 0x608c, BRIDGE_SN9C103), },
 /*     { SN9C102_USB_DEVICE(0x0c45, 0x608e, BRIDGE_SN9C103), }, CISVF10 */
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x608f, BRIDGE_SN9C103), },
 #endif
        { SN9C102_USB_DEVICE(0x0c45, 0x60a0, BRIDGE_SN9C103), },
@@ -86,7 +86,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
        { SN9C102_USB_DEVICE(0x0c45, 0x60ac, BRIDGE_SN9C103), },
        { SN9C102_USB_DEVICE(0x0c45, 0x60ae, BRIDGE_SN9C103), },
        { SN9C102_USB_DEVICE(0x0c45, 0x60af, BRIDGE_SN9C103), },
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXB && !defined CONFIG_USB_GSPCA_SONIXB_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x60b0, BRIDGE_SN9C103), },
 #endif
        { SN9C102_USB_DEVICE(0x0c45, 0x60b2, BRIDGE_SN9C103), },
@@ -97,7 +97,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
        { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), },
        { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), },
        /* SN9C105 */
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXJ && !defined CONFIG_USB_GSPCA_SONIXJ_MODULE
        { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), },
        { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), },
        { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), },
@@ -121,11 +121,11 @@ static const struct usb_device_id sn9c102_id_table[] = {
        { SN9C102_USB_DEVICE(0x0c45, 0x610f, BRIDGE_SN9C120), },
        { SN9C102_USB_DEVICE(0x0c45, 0x6130, BRIDGE_SN9C120), },
 /*     { SN9C102_USB_DEVICE(0x0c45, 0x6138, BRIDGE_SN9C120), }, MO8000 */
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXJ && !defined CONFIG_USB_GSPCA_SONIXJ_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x613a, BRIDGE_SN9C120), },
 #endif
        { SN9C102_USB_DEVICE(0x0c45, 0x613b, BRIDGE_SN9C120), },
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_SONIXJ && !defined CONFIG_USB_GSPCA_SONIXJ_MODULE
        { SN9C102_USB_DEVICE(0x0c45, 0x613c, BRIDGE_SN9C120), },
        { SN9C102_USB_DEVICE(0x0c45, 0x613e, BRIDGE_SN9C120), },
 #endif
index db24349..2dce5c9 100644 (file)
@@ -255,7 +255,7 @@ int sn9c102_probe_hv7131d(struct sn9c102_device* cam)
        if (err || r0 < 0 || r1 < 0)
                return -EIO;
 
-       if (r0 != 0x00 || r1 != 0x04)
+       if ((r0 != 0x00 && r0 != 0x01) || r1 != 0x04)
                return -ENODEV;
 
        sn9c102_attach_sensor(cam, &hv7131d);
index a24174d..db1ca0e 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 #include <linux/vmalloc.h>
 
 #include <media/soc_camera.h>
@@ -388,6 +389,11 @@ static int soc_camera_open(struct file *file)
                        goto eiciadd;
                }
 
+               pm_runtime_enable(&icd->vdev->dev);
+               ret = pm_runtime_resume(&icd->vdev->dev);
+               if (ret < 0 && ret != -ENOSYS)
+                       goto eresume;
+
                /*
                 * Try to configure with default parameters. Notice: this is the
                 * very first open, so, we cannot race against other calls,
@@ -409,10 +415,12 @@ static int soc_camera_open(struct file *file)
        return 0;
 
        /*
-        * First five errors are entered with the .video_lock held
+        * First four errors are entered with the .video_lock held
         * and use_count == 1
         */
 esfmt:
+       pm_runtime_disable(&icd->vdev->dev);
+eresume:
        ici->ops->remove(icd);
 eiciadd:
        if (icl->power)
@@ -437,7 +445,11 @@ static int soc_camera_close(struct file *file)
        if (!icd->use_count) {
                struct soc_camera_link *icl = to_soc_camera_link(icd);
 
+               pm_runtime_suspend(&icd->vdev->dev);
+               pm_runtime_disable(&icd->vdev->dev);
+
                ici->ops->remove(icd);
+
                if (icl->power)
                        icl->power(icd->pdev, 0);
        }
@@ -741,8 +753,7 @@ static int soc_camera_g_crop(struct file *file, void *fh,
 /*
  * According to the V4L2 API, drivers shall not update the struct v4l2_crop
  * argument with the actual geometry, instead, the user shall use G_CROP to
- * retrieve it. However, we expect camera host and client drivers to update
- * the argument, which we then use internally, but do not return to the user.
+ * retrieve it.
  */
 static int soc_camera_s_crop(struct file *file, void *fh,
                             struct v4l2_crop *a)
@@ -1319,6 +1330,7 @@ static int video_dev_create(struct soc_camera_device *icd)
  */
 static int soc_camera_video_start(struct soc_camera_device *icd)
 {
+       struct device_type *type = icd->vdev->dev.type;
        int ret;
 
        if (!icd->dev.parent)
@@ -1335,6 +1347,9 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
                return ret;
        }
 
+       /* Restore device type, possibly set by the subdevice driver */
+       icd->vdev->dev.type = type;
+
        return 0;
 }
 
index ebd9cb5..edd78f8 100644 (file)
@@ -97,15 +97,17 @@ open_out:
        return ret;
 }
 
+#ifdef CONFIG_PM
 static void poseidon_fe_release(struct dvb_frontend *fe)
 {
        struct poseidon *pd = fe->demodulator_priv;
 
-#ifdef CONFIG_PM
        pd->pm_suspend = NULL;
        pd->pm_resume  = NULL;
-#endif
 }
+#else
+#define poseidon_fe_release NULL
+#endif
 
 static s32 poseidon_fe_sleep(struct dvb_frontend *fe)
 {
index 2cf0ebf..c267e0c 100644 (file)
@@ -24,7 +24,6 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/version.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -55,8 +54,8 @@ int debug_mode;
 module_param(debug_mode, int, 0644);
 MODULE_PARM_DESC(debug_mode, "0 = disable, 1 = enable, 2 = verbose");
 
-const char *firmware_name = "tlg2300_firmware.bin";
-struct usb_driver poseidon_driver;
+static const char *firmware_name = "tlg2300_firmware.bin";
+static struct usb_driver poseidon_driver;
 static LIST_HEAD(pd_device_list);
 
 /*
@@ -501,7 +500,7 @@ static void poseidon_disconnect(struct usb_interface *interface)
        kref_put(&pd->kref, poseidon_delete);
 }
 
-struct usb_driver poseidon_driver = {
+static struct usb_driver poseidon_driver = {
        .name           = "poseidon",
        .probe          = poseidon_probe,
        .disconnect     = poseidon_disconnect,
index 755766b..fae84c2 100644 (file)
@@ -161,7 +161,8 @@ static const struct v4l2_file_operations poseidon_fm_fops = {
        .ioctl         = video_ioctl2,
 };
 
-int tlg_fm_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
+static int tlg_fm_vidioc_g_tuner(struct file *file, void *priv,
+                                struct v4l2_tuner *vt)
 {
        struct tuner_fm_sig_stat_s fm_stat = {};
        int ret, status, count = 5;
@@ -203,7 +204,8 @@ int tlg_fm_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *vt)
        return 0;
 }
 
-int fm_get_freq(struct file *file, void *priv, struct v4l2_frequency *argp)
+static int fm_get_freq(struct file *file, void *priv,
+                      struct v4l2_frequency *argp)
 {
        struct poseidon *p = file->private_data;
 
@@ -246,7 +248,8 @@ error:
        return ret;
 }
 
-int fm_set_freq(struct file *file, void *priv, struct v4l2_frequency *argp)
+static int fm_set_freq(struct file *file, void *priv,
+                      struct v4l2_frequency *argp)
 {
        struct poseidon *p = file->private_data;
 
@@ -258,13 +261,13 @@ int fm_set_freq(struct file *file, void *priv, struct v4l2_frequency *argp)
        return set_frequency(p, argp->frequency);
 }
 
-int tlg_fm_vidioc_g_ctrl(struct file *file, void *priv,
+static int tlg_fm_vidioc_g_ctrl(struct file *file, void *priv,
                struct v4l2_control *arg)
 {
        return 0;
 }
 
-int tlg_fm_vidioc_g_exts_ctrl(struct file *file, void *fh,
+static int tlg_fm_vidioc_g_exts_ctrl(struct file *file, void *fh,
                                struct v4l2_ext_controls *ctrls)
 {
        struct poseidon *p = file->private_data;
@@ -285,7 +288,7 @@ int tlg_fm_vidioc_g_exts_ctrl(struct file *file, void *fh,
        return 0;
 }
 
-int tlg_fm_vidioc_s_exts_ctrl(struct file *file, void *fh,
+static int tlg_fm_vidioc_s_exts_ctrl(struct file *file, void *fh,
                        struct v4l2_ext_controls *ctrls)
 {
        int i;
@@ -312,13 +315,13 @@ int tlg_fm_vidioc_s_exts_ctrl(struct file *file, void *fh,
        return 0;
 }
 
-int tlg_fm_vidioc_s_ctrl(struct file *file, void *priv,
+static int tlg_fm_vidioc_s_ctrl(struct file *file, void *priv,
                struct v4l2_control *ctrl)
 {
        return 0;
 }
 
-int tlg_fm_vidioc_queryctrl(struct file *file, void *priv,
+static int tlg_fm_vidioc_queryctrl(struct file *file, void *priv,
                struct v4l2_queryctrl *ctrl)
 {
        if (!(ctrl->id & V4L2_CTRL_FLAG_NEXT_CTRL))
@@ -337,7 +340,7 @@ int tlg_fm_vidioc_queryctrl(struct file *file, void *priv,
        return -EINVAL;
 }
 
-int tlg_fm_vidioc_querymenu(struct file *file, void *fh,
+static int tlg_fm_vidioc_querymenu(struct file *file, void *fh,
                                struct v4l2_querymenu *qmenu)
 {
        return v4l2_ctrl_query_menu(qmenu, NULL, NULL);
index cf8f18c..c750fd1 100644 (file)
 #include "pd-common.h"
 #include "vendorcmds.h"
 
+#ifdef CONFIG_PM
 static int pm_video_suspend(struct poseidon *pd);
 static int pm_video_resume(struct poseidon *pd);
+#endif
 static void iso_bubble_handler(struct work_struct *w);
 
-int usb_transfer_mode;
+static int usb_transfer_mode;
 module_param(usb_transfer_mode, int, 0644);
 MODULE_PARM_DESC(usb_transfer_mode, "0 = Bulk, 1 = Isochronous");
 
@@ -617,7 +619,7 @@ static int pd_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
        return 0;
 }
 
-int fire_all_urb(struct video_data *video)
+static int fire_all_urb(struct video_data *video)
 {
        int i, ret;
 
@@ -877,7 +879,7 @@ out:
        return ret;
 }
 
-int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *norm)
+static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id *norm)
 {
        struct front_face *front = fh;
        logs(front);
@@ -1020,7 +1022,7 @@ static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
        return 0;
 }
 
-int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
+static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
 {
        a->index = 0;
        a->capability = V4L2_AUDCAP_STEREO;
@@ -1029,7 +1031,7 @@ int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
        return 0;
 }
 
-int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
+static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
 {
        return (0 == a->index) ? 0 : -EINVAL;
 }
@@ -1189,7 +1191,7 @@ static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
 }
 
 /* Just stop the URBs, do not free the URBs */
-int usb_transfer_stop(struct video_data *video)
+static int usb_transfer_stop(struct video_data *video)
 {
        if (video->is_streaming) {
                int i;
@@ -1518,13 +1520,13 @@ static int pd_video_mmap(struct file *file, struct vm_area_struct *vma)
        return  videobuf_mmap_mapper(&front->q, vma);
 }
 
-unsigned int pd_video_poll(struct file *file, poll_table *table)
+static unsigned int pd_video_poll(struct file *file, poll_table *table)
 {
        struct front_face *front = file->private_data;
        return videobuf_poll_stream(file, &front->q, table);
 }
 
-ssize_t pd_video_read(struct file *file, char __user *buffer,
+static ssize_t pd_video_read(struct file *file, char __user *buffer,
                        size_t count, loff_t *ppos)
 {
        struct front_face *front = file->private_data;
index e4815a1..e826114 100644 (file)
@@ -79,6 +79,8 @@ struct tvp514x_std_info {
 };
 
 static struct tvp514x_reg tvp514x_reg_list_default[0x40];
+
+static int tvp514x_s_stream(struct v4l2_subdev *sd, int enable);
 /**
  * struct tvp514x_decoder - TVP5146/47 decoder object
  * @sd: Subdevice Slave handle
@@ -644,6 +646,17 @@ static int tvp514x_s_routing(struct v4l2_subdev *sd,
                /* Index out of bound */
                return -EINVAL;
 
+       /*
+        * For the sequence streamon -> streamoff and again s_input
+        * it fails to lock the signal, since streamoff puts TVP514x
+        * into power off state which leads to failure in sub-sequent s_input.
+        *
+        * So power up the TVP514x device here, since it is important to lock
+        * the signal at this stage.
+        */
+       if (!decoder->streaming)
+               tvp514x_s_stream(sd, 1);
+
        input_sel = input;
        output_sel = output;
 
index 908ffb6..47f0582 100644 (file)
@@ -891,29 +891,26 @@ static int tvp5150_s_routing(struct v4l2_subdev *sd,
        return 0;
 }
 
-static int tvp5150_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+static int tvp5150_s_raw_fmt(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt)
+{
+       /* this is for capturing 36 raw vbi lines
+          if there's a way to cut off the beginning 2 vbi lines
+          with the tvp5150 then the vbi line count could be lowered
+          to 17 lines/field again, although I couldn't find a register
+          which could do that cropping */
+       if (fmt->sample_format == V4L2_PIX_FMT_GREY)
+               tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
+       if (fmt->count[0] == 18 && fmt->count[1] == 18) {
+               tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
+               tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
+       }
+       return 0;
+}
+
+static int tvp5150_s_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
 {
-       struct v4l2_sliced_vbi_format *svbi;
        int i;
 
-       /* raw vbi */
-       if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
-               /* this is for capturing 36 raw vbi lines
-                  if there's a way to cut off the beginning 2 vbi lines
-                  with the tvp5150 then the vbi line count could be lowered
-                  to 17 lines/field again, although I couldn't find a register
-                  which could do that cropping */
-               if (fmt->fmt.vbi.sample_format == V4L2_PIX_FMT_GREY)
-                       tvp5150_write(sd, TVP5150_LUMA_PROC_CTL_1, 0x70);
-               if (fmt->fmt.vbi.count[0] == 18 && fmt->fmt.vbi.count[1] == 18) {
-                       tvp5150_write(sd, TVP5150_VERT_BLANKING_START, 0x00);
-                       tvp5150_write(sd, TVP5150_VERT_BLANKING_STOP, 0x01);
-               }
-               return 0;
-       }
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
-               return -EINVAL;
-       svbi = &fmt->fmt.sliced;
        if (svbi->service_set != 0) {
                for (i = 0; i <= 23; i++) {
                        svbi->service_lines[1][i] = 0;
@@ -937,14 +934,21 @@ static int tvp5150_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        return 0;
 }
 
-static int tvp5150_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+static int tvp5150_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
 {
-       struct v4l2_sliced_vbi_format *svbi;
-       int i, mask = 0;
+       switch (fmt->type) {
+       case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
+               return tvp5150_s_sliced_fmt(sd, &fmt->fmt.sliced);
 
-       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+       default:
                return -EINVAL;
-       svbi = &fmt->fmt.sliced;
+       }
+}
+
+static int tvp5150_g_sliced_fmt(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *svbi)
+{
+       int i, mask = 0;
+
        memset(svbi, 0, sizeof(*svbi));
 
        for (i = 0; i <= 23; i++) {
@@ -956,6 +960,12 @@ static int tvp5150_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
        return 0;
 }
 
+static int tvp5150_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt)
+{
+       if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+               return -EINVAL;
+       return tvp5150_g_sliced_fmt(sd, &fmt->fmt.sliced);
+}
 
 static int tvp5150_g_chip_ident(struct v4l2_subdev *sd,
                                struct v4l2_dbg_chip_ident *chip)
@@ -1046,13 +1056,20 @@ static const struct v4l2_subdev_video_ops tvp5150_video_ops = {
        .s_routing = tvp5150_s_routing,
        .g_fmt = tvp5150_g_fmt,
        .s_fmt = tvp5150_s_fmt,
+};
+
+static const struct v4l2_subdev_vbi_ops tvp5150_vbi_ops = {
        .g_sliced_vbi_cap = tvp5150_g_sliced_vbi_cap,
+       .g_sliced_fmt = tvp5150_g_sliced_fmt,
+       .s_sliced_fmt = tvp5150_s_sliced_fmt,
+       .s_raw_fmt = tvp5150_s_raw_fmt,
 };
 
 static const struct v4l2_subdev_ops tvp5150_ops = {
        .core = &tvp5150_core_ops,
        .tuner = &tvp5150_tuner_ops,
        .video = &tvp5150_video_ops,
+       .vbi = &tvp5150_vbi_ops,
 };
 
 
index 4a69bcc..8085ac3 100644 (file)
@@ -458,7 +458,7 @@ static inline struct tvp7002 *to_tvp7002(struct v4l2_subdev *sd)
 /*
  * tvp7002_read - Read a value from a register in an TVP7002
  * @sd: ptr to v4l2_subdev struct
- * @reg: TVP7002 register address
+ * @addr: TVP7002 register address
  * @dst: pointer to 8-bit destination
  *
  * Returns value read if successful, or non-zero (-1) otherwise.
@@ -488,7 +488,7 @@ static int tvp7002_read(struct v4l2_subdev *sd, u8 addr, u8 *dst)
  * @sd: pointer to standard V4L2 sub-device structure
  * @reg: destination register
  * @val: value to be read
- * @error: pointer to error value
+ * @err: pointer to error value
  *
  * Read a value in a register and save error value in pointer.
  * Also update the register table if successful
@@ -535,7 +535,7 @@ static int tvp7002_write(struct v4l2_subdev *sd, u8 addr, u8 value)
  * @sd: pointer to standard V4L2 sub-device structure
  * @reg: destination register
  * @val: value to be written
- * @error: pointer to error value
+ * @err: pointer to error value
  *
  * Write a value in a register and save error value in pointer.
  * Also update the register table if successful
@@ -596,7 +596,7 @@ static int tvp7002_write_inittab(struct v4l2_subdev *sd,
 /*
  * tvp7002_s_dv_preset() - Set digital video preset
  * @sd: ptr to v4l2_subdev struct
- * @std: ptr to v4l2_dv_preset struct
+ * @dv_preset: ptr to v4l2_dv_preset struct
  *
  * Set the digital video preset for a TVP7002 decoder device.
  * Returns zero when successful or -EINVAL if register access fails.
@@ -676,7 +676,7 @@ static int tvp7002_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
 /*
  * tvp7002_queryctrl() - Query a control
  * @sd: ptr to v4l2_subdev struct
- * @ctrl: ptr to v4l2_queryctrl struct
+ * @qc: ptr to v4l2_queryctrl struct
  *
  * Query a control of a TVP7002 decoder device.
  * Returns zero when successful or -EINVAL if register read fails.
@@ -776,7 +776,7 @@ static int tvp7002_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *f)
 /*
  * tvp7002_query_dv_preset() - query DV preset
  * @sd: pointer to standard V4L2 sub-device structure
- * @std_id: standard V4L2 v4l2_dv_preset
+ * @qpreset: standard V4L2 v4l2_dv_preset structure
  *
  * Returns the current DV preset by TVP7002. If no active input is
  * detected, returns -EINVAL
@@ -785,7 +785,6 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
                                                struct v4l2_dv_preset *qpreset)
 {
        const struct tvp7002_preset_definition *presets = tvp7002_presets;
-       struct v4l2_dv_enum_preset e_preset;
        struct tvp7002 *device;
        u8 progressive;
        u32 lpfr;
@@ -828,20 +827,18 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
                }
 
        if (index == NUM_PRESETS) {
-               v4l2_err(sd, "querystd error, lpf = %x, cpl = %x\n",
+               v4l2_dbg(1, debug, sd, "detection failed: lpf = %x, cpl = %x\n",
                                                                lpfr, cpln);
-               return -EINVAL;
+               /* Could not detect a signal, so return the 'invalid' preset */
+               qpreset->preset = V4L2_DV_INVALID;
+               return 0;
        }
 
-       if (v4l_fill_dv_preset_info(presets->preset, &e_preset))
-               return -EINVAL;
-
        /* Set values in found preset */
        qpreset->preset = presets->preset;
 
        /* Update lines per frame and clocks per line info */
-       v4l2_dbg(1, debug, sd, "Current preset: %d %d",
-                                       e_preset.width, e_preset.height);
+       v4l2_dbg(1, debug, sd, "detected preset: %d\n", presets->preset);
        return 0;
 }
 
@@ -849,7 +846,7 @@ static int tvp7002_query_dv_preset(struct v4l2_subdev *sd,
 /*
  * tvp7002_g_register() - Get the value of a register
  * @sd: ptr to v4l2_subdev struct
- * @vreg: ptr to v4l2_dbg_register struct
+ * @reg: ptr to v4l2_dbg_register struct
  *
  * Get the value of a TVP7002 decoder device register.
  * Returns zero when successful, -EINVAL if register read fails or
@@ -876,7 +873,7 @@ static int tvp7002_g_register(struct v4l2_subdev *sd,
 /*
  * tvp7002_s_register() - set a control
  * @sd: ptr to v4l2_subdev struct
- * @ctrl: ptr to v4l2_control struct
+ * @reg: ptr to v4l2_dbg_register struct
  *
  * Get the value of a TVP7002 decoder device register.
  * Returns zero when successful, -EINVAL if register read fails or
@@ -899,7 +896,7 @@ static int tvp7002_s_register(struct v4l2_subdev *sd,
 /*
  * tvp7002_enum_fmt() - Enum supported formats
  * @sd: pointer to standard V4L2 sub-device structure
- * @enable: pointer to format struct
+ * @fmtdesc: pointer to format struct
  *
  * Enumerate supported formats.
  */
@@ -994,6 +991,23 @@ static int tvp7002_log_status(struct v4l2_subdev *sd)
        return 0;
 }
 
+/*
+ * tvp7002_enum_dv_presets() - Enum supported digital video formats
+ * @sd: pointer to standard V4L2 sub-device structure
+ * @preset: pointer to format struct
+ *
+ * Enumerate supported digital video formats.
+ */
+static int tvp7002_enum_dv_presets(struct v4l2_subdev *sd,
+               struct v4l2_dv_enum_preset *preset)
+{
+       /* Check requested format index is within range */
+       if (preset->index >= NUM_PRESETS)
+               return -EINVAL;
+
+       return v4l_fill_dv_preset_info(tvp7002_presets[preset->index].preset, preset);
+}
+
 /* V4L2 core operation handlers */
 static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
        .g_chip_ident = tvp7002_g_chip_ident,
@@ -1009,6 +1023,7 @@ static const struct v4l2_subdev_core_ops tvp7002_core_ops = {
 
 /* Specific video subsystem operation handlers */
 static const struct v4l2_subdev_video_ops tvp7002_video_ops = {
+       .enum_dv_presets = tvp7002_enum_dv_presets,
        .s_dv_preset = tvp7002_s_dv_preset,
        .query_dv_preset = tvp7002_query_dv_preset,
        .s_stream = tvp7002_s_stream,
@@ -1042,8 +1057,8 @@ static struct tvp7002 tvp7002_dev = {
 
 /*
  * tvp7002_probe - Probe a TVP7002 device
- * @sd: ptr to v4l2_subdev struct
- * @ctrl: ptr to i2c_device_id struct
+ * @c: ptr to i2c_client struct
+ * @id: ptr to i2c_device_id struct
  *
  * Initialize the TVP7002 device
  * Returns zero when successful, -EINVAL if register read fails or
index fab48ec..fbd665f 100644 (file)
@@ -693,12 +693,13 @@ static int qcm_start_data(struct uvd *uvd)
 
 static void qcm_stop_data(struct uvd *uvd)
 {
-       struct qcm *cam = (struct qcm *) uvd->user_data;
+       struct qcm *cam;
        int i, j;
        int ret;
 
        if ((uvd == NULL) || (!uvd->streaming) || (uvd->dev == NULL))
                return;
+       cam = (struct qcm *) uvd->user_data;
 
        ret = qcm_camera_off(uvd);
        if (ret)
index 0837652..42ba287 100644 (file)
@@ -244,6 +244,9 @@ int usbvision_i2c_register(struct usb_usbvision *usbvision)
        switch (usbvision_device_data[usbvision->DevModel].Codec) {
        case CODEC_SAA7113:
        case CODEC_SAA7111:
+               /* Without this delay the detection of the saa711x is
+                  hit-and-miss. */
+               mdelay(10);
                v4l2_i2c_new_subdev(&usbvision->v4l2_dev,
                                &usbvision->i2c_adap, "saa7115",
                                "saa7115_auto", 0, saa711x_addrs);
index 7c17ec6..6248a63 100644 (file)
@@ -137,8 +137,6 @@ static int PowerOnAtOpen = 1;
 static int video_nr = -1;
 /* Sequential Number of Radio Device */
 static int radio_nr = -1;
-/* Sequential Number of VBI Device */
-static int vbi_nr = -1;
 
 /* Grab parameters for the device driver */
 
@@ -148,14 +146,12 @@ module_param(video_debug, int, 0444);
 module_param(PowerOnAtOpen, int, 0444);
 module_param(video_nr, int, 0444);
 module_param(radio_nr, int, 0444);
-module_param(vbi_nr, int, 0444);
 
 MODULE_PARM_DESC(isocMode, " Set the default format for ISOC endpoint.  Default: 0x60 (Compression On)");
 MODULE_PARM_DESC(video_debug, " Set the default Debug Mode of the device driver.  Default: 0 (Off)");
 MODULE_PARM_DESC(PowerOnAtOpen, " Set the default device to power on when device is opened.  Default: 1 (On)");
 MODULE_PARM_DESC(video_nr, "Set video device number (/dev/videoX).  Default: -1 (autodetect)");
 MODULE_PARM_DESC(radio_nr, "Set radio device number (/dev/radioX).  Default: -1 (autodetect)");
-MODULE_PARM_DESC(vbi_nr, "Set vbi device number (/dev/vbiX).  Default: -1 (autodetect)");
 
 
 // Misc stuff
@@ -1244,36 +1240,6 @@ static int usbvision_radio_close(struct file *file)
        return errCode;
 }
 
-/*
- * Here comes the stuff for vbi on usbvision based devices
- *
- */
-static int usbvision_vbi_open(struct file *file)
-{
-       /* TODO */
-       return -ENODEV;
-}
-
-static int usbvision_vbi_close(struct file *file)
-{
-       /* TODO */
-       return -ENODEV;
-}
-
-static long usbvision_do_vbi_ioctl(struct file *file,
-                                unsigned int cmd, void *arg)
-{
-       /* TODO */
-       return -ENOIOCTLCMD;
-}
-
-static long usbvision_vbi_ioctl(struct file *file,
-                      unsigned int cmd, unsigned long arg)
-{
-       return video_usercopy(file, cmd, arg, usbvision_do_vbi_ioctl);
-}
-
-
 //
 // Video registration stuff
 //
@@ -1367,21 +1333,6 @@ static struct video_device usbvision_radio_template = {
        .current_norm         = V4L2_STD_PAL
 };
 
-// vbi template
-static const struct v4l2_file_operations usbvision_vbi_fops = {
-       .owner             = THIS_MODULE,
-       .open           = usbvision_vbi_open,
-       .release        = usbvision_vbi_close,
-       .ioctl          = usbvision_vbi_ioctl,
-};
-
-static struct video_device usbvision_vbi_template=
-{
-       .fops           = &usbvision_vbi_fops,
-       .release        = video_device_release,
-       .name           = "usbvision-vbi",
-};
-
 
 static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
                                        struct video_device *vdev_template,
@@ -1410,18 +1361,6 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
 // unregister video4linux devices
 static void usbvision_unregister_video(struct usb_usbvision *usbvision)
 {
-       // vbi Device:
-       if (usbvision->vbi) {
-               PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
-                      video_device_node_name(usbvision->vbi));
-               if (video_is_registered(usbvision->vbi)) {
-                       video_unregister_device(usbvision->vbi);
-               } else {
-                       video_device_release(usbvision->vbi);
-               }
-               usbvision->vbi = NULL;
-       }
-
        // Radio Device:
        if (usbvision->rdev) {
                PDEBUG(DBG_PROBE, "unregister %s [v4l2]",
@@ -1482,22 +1421,6 @@ static int __devinit usbvision_register_video(struct usb_usbvision *usbvision)
                printk(KERN_INFO "USBVision[%d]: registered USBVision Radio device %s [v4l2]\n",
                       usbvision->nr, video_device_node_name(usbvision->rdev));
        }
-       // vbi Device:
-       if (usbvision_device_data[usbvision->DevModel].vbi) {
-               usbvision->vbi = usbvision_vdev_init(usbvision,
-                                                    &usbvision_vbi_template,
-                                                    "USBVision VBI");
-               if (usbvision->vbi == NULL) {
-                       goto err_exit;
-               }
-               if (video_register_device(usbvision->vbi,
-                                         VFL_TYPE_VBI,
-                                         vbi_nr)<0) {
-                       goto err_exit;
-               }
-               printk(KERN_INFO "USBVision[%d]: registered USBVision VBI device %s [v4l2] (Not Working Yet!)\n",
-                      usbvision->nr, video_device_node_name(usbvision->vbi));
-       }
        // all done
        return 0;
 
@@ -1726,8 +1649,6 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
        usbvision_configure_video(usbvision);
        mutex_unlock(&usbvision->lock);
 
-
-       usb_set_intfdata (intf, usbvision);
        usbvision_create_sysfs(usbvision->vdev);
 
        PDEBUG(DBG_PROBE, "success");
@@ -1745,7 +1666,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
  */
 static void __devexit usbvision_disconnect(struct usb_interface *intf)
 {
-       struct usb_usbvision *usbvision = usb_get_intfdata(intf);
+       struct usb_usbvision *usbvision = to_usbvision(usb_get_intfdata(intf));
 
        PDEBUG(DBG_PROBE, "");
 
@@ -1754,7 +1675,6 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
                        "%s: usb_get_intfdata() failed\n", __func__);
                return;
        }
-       usb_set_intfdata (intf, NULL);
 
        mutex_lock(&usbvision->lock);
 
index f8d7458..d1b3cc0 100644 (file)
@@ -360,7 +360,6 @@ struct usb_usbvision {
        struct v4l2_device v4l2_dev;
        struct video_device *vdev;                                      /* Video Device */
        struct video_device *rdev;                                      /* Radio Device */
-       struct video_device *vbi;                                       /* VBI Device   */
 
        /* i2c Declaration Section*/
        struct i2c_adapter i2c_adap;
@@ -463,6 +462,11 @@ struct usb_usbvision {
        int ComprBlockTypes[4];
 };
 
+static inline struct usb_usbvision *to_usbvision(struct v4l2_device *v4l2_dev)
+{
+       return container_of(v4l2_dev, struct usb_usbvision, v4l2_dev);
+}
+
 #define call_all(usbvision, o, f, args...) \
        v4l2_device_call_all(&usbvision->v4l2_dev, 0, o, f, ##args)
 
index 6d3850b..aa0720a 100644 (file)
@@ -217,8 +217,7 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_EXPOSURE_TIME_RELATIVE_CONTROL,
                .index          = 4,
                .size           = 1,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
-                               | UVC_CONTROL_RESTORE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_RESTORE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -233,8 +232,9 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_FOCUS_RELATIVE_CONTROL,
                .index          = 6,
                .size           = 2,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
-                               | UVC_CONTROL_AUTO_UPDATE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
+                               | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -249,8 +249,7 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_IRIS_RELATIVE_CONTROL,
                .index          = 8,
                .size           = 1,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
-                               | UVC_CONTROL_AUTO_UPDATE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_AUTO_UPDATE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -265,8 +264,9 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_ZOOM_RELATIVE_CONTROL,
                .index          = 10,
                .size           = 3,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
-                               | UVC_CONTROL_AUTO_UPDATE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
+                               | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -281,8 +281,9 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_PANTILT_RELATIVE_CONTROL,
                .index          = 12,
                .size           = 4,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
-                               | UVC_CONTROL_AUTO_UPDATE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
+                               | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -297,8 +298,9 @@ static struct uvc_control_info uvc_ctrls[] = {
                .selector       = UVC_CT_ROLL_RELATIVE_CONTROL,
                .index          = 14,
                .size           = 2,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
-                               | UVC_CONTROL_AUTO_UPDATE,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_MIN
+                               | UVC_CONTROL_GET_MAX | UVC_CONTROL_GET_RES
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_AUTO_UPDATE,
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
@@ -561,6 +563,26 @@ static struct uvc_control_mapping uvc_ctrl_mappings[] = {
                .v4l2_type      = V4L2_CTRL_TYPE_BOOLEAN,
                .data_type      = UVC_CTRL_DATA_TYPE_BOOLEAN,
        },
+       {
+               .id             = V4L2_CID_IRIS_ABSOLUTE,
+               .name           = "Iris, Absolute",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = UVC_CT_IRIS_ABSOLUTE_CONTROL,
+               .size           = 16,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_UNSIGNED,
+       },
+       {
+               .id             = V4L2_CID_IRIS_RELATIVE,
+               .name           = "Iris, Relative",
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = UVC_CT_IRIS_RELATIVE_CONTROL,
+               .size           = 8,
+               .offset         = 0,
+               .v4l2_type      = V4L2_CTRL_TYPE_INTEGER,
+               .data_type      = UVC_CTRL_DATA_TYPE_SIGNED,
+       },
        {
                .id             = V4L2_CID_ZOOM_ABSOLUTE,
                .name           = "Zoom, Absolute",
@@ -822,6 +844,8 @@ int uvc_query_v4l2_ctrl(struct uvc_video_chain *chain,
        strlcpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
        v4l2_ctrl->flags = 0;
 
+       if (!(ctrl->info->flags & UVC_CONTROL_GET_CUR))
+               v4l2_ctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
        if (!(ctrl->info->flags & UVC_CONTROL_SET_CUR))
                v4l2_ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
 
@@ -1047,6 +1071,8 @@ int uvc_ctrl_set(struct uvc_video_chain *chain,
                                   uvc_ctrl_data(ctrl, UVC_CTRL_DATA_MAX));
                step = mapping->get(mapping, UVC_GET_RES,
                                    uvc_ctrl_data(ctrl, UVC_CTRL_DATA_RES));
+               if (step == 0)
+                       step = 1;
 
                xctrl->value = min + (xctrl->value - min + step/2) / step * step;
                xctrl->value = clamp(xctrl->value, min, max);
index 86ff8c1..838b56f 100644 (file)
@@ -91,10 +91,15 @@ static struct uvc_format_desc uvc_fmts[] = {
                .fcc            = V4L2_PIX_FMT_UYVY,
        },
        {
-               .name           = "Greyscale",
+               .name           = "Greyscale (8-bit)",
                .guid           = UVC_GUID_FORMAT_Y800,
                .fcc            = V4L2_PIX_FMT_GREY,
        },
+       {
+               .name           = "Greyscale (16-bit)",
+               .guid           = UVC_GUID_FORMAT_Y16,
+               .fcc            = V4L2_PIX_FMT_Y16,
+       },
        {
                .name           = "RGB Bayer",
                .guid           = UVC_GUID_FORMAT_BY8,
@@ -2105,6 +2110,15 @@ static struct usb_device_id uvc_ids[] = {
          .bInterfaceSubClass   = 1,
          .bInterfaceProtocol   = 0,
          .driver_info          = UVC_QUIRK_STREAM_NO_FID },
+       /* Syntek (Packard Bell EasyNote MX52 */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x174f,
+         .idProduct            = 0x8a12,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_STREAM_NO_FID },
        /* Syntek (Asus F9SG) */
        { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                                | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -2169,6 +2183,15 @@ static struct usb_device_id uvc_ids[] = {
          .bInterfaceSubClass   = 1,
          .bInterfaceProtocol   = 0,
          .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Arkmicro unbranded */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x18ec,
+         .idProduct            = 0x3290,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_DEF },
        /* Bodelin ProScopeHR */
        { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                                | USB_DEVICE_ID_MATCH_DEV_HI
index 4a925a3..133c78d 100644 (file)
@@ -388,8 +388,12 @@ unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
 
        poll_wait(file, &buf->wait, wait);
        if (buf->state == UVC_BUF_STATE_DONE ||
-           buf->state == UVC_BUF_STATE_ERROR)
-               mask |= POLLIN | POLLRDNORM;
+           buf->state == UVC_BUF_STATE_ERROR) {
+               if (queue->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                       mask |= POLLIN | POLLRDNORM;
+               else
+                       mask |= POLLOUT | POLLWRNORM;
+       }
 
 done:
        mutex_unlock(&queue->mutex);
index 2bba059..d1f8840 100644 (file)
@@ -131,11 +131,13 @@ struct uvc_xu_control {
 #define UVC_GUID_FORMAT_Y800 \
        { 'Y',  '8',  '0',  '0', 0x00, 0x00, 0x10, 0x00, \
         0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
+#define UVC_GUID_FORMAT_Y16 \
+       { 'Y',  '1',  '6',  ' ', 0x00, 0x00, 0x10, 0x00, \
+        0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 #define UVC_GUID_FORMAT_BY8 \
        { 'B',  'Y',  '8',  ' ', 0x00, 0x00, 0x10, 0x00, \
         0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
 
-
 /* ------------------------------------------------------------------------
  * Driver specific constants.
  */
index 36b5cb8..4e53b0b 100644 (file)
@@ -51,6 +51,9 @@
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/i2c.h>
+#if defined(CONFIG_SPI)
+#include <linux/spi/spi.h>
+#endif
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <asm/pgtable.h>
@@ -85,10 +88,9 @@ MODULE_LICENSE("GPL");
                              val == V4L2_PRIORITY_INTERACTIVE  || \
                              val == V4L2_PRIORITY_RECORD)
 
-int v4l2_prio_init(struct v4l2_prio_state *global)
+void v4l2_prio_init(struct v4l2_prio_state *global)
 {
-       memset(global,0,sizeof(*global));
-       return 0;
+       memset(global, 0, sizeof(*global));
 }
 EXPORT_SYMBOL(v4l2_prio_init);
 
@@ -108,17 +110,16 @@ int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
 }
 EXPORT_SYMBOL(v4l2_prio_change);
 
-int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
+void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local)
 {
-       return v4l2_prio_change(global,local,V4L2_PRIORITY_DEFAULT);
+       v4l2_prio_change(global, local, V4L2_PRIORITY_DEFAULT);
 }
 EXPORT_SYMBOL(v4l2_prio_open);
 
-int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local)
+void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local)
 {
-       if (V4L2_PRIO_VALID(*local))
-               atomic_dec(&global->prios[*local]);
-       return 0;
+       if (V4L2_PRIO_VALID(local))
+               atomic_dec(&global->prios[local]);
 }
 EXPORT_SYMBOL(v4l2_prio_close);
 
@@ -134,11 +135,9 @@ enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global)
 }
 EXPORT_SYMBOL(v4l2_prio_max);
 
-int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local)
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local)
 {
-       if (*local < v4l2_prio_max(global))
-               return -EBUSY;
-       return 0;
+       return (local < v4l2_prio_max(global)) ? -EBUSY : 0;
 }
 EXPORT_SYMBOL(v4l2_prio_check);
 
@@ -340,6 +339,13 @@ const char **v4l2_ctrl_get_menu(u32 id)
                "None",
                "Black & White",
                "Sepia",
+               "Negative",
+               "Emboss",
+               "Sketch",
+               "Sky blue",
+               "Grass green",
+               "Skin whiten",
+               "Vivid",
                NULL
        };
        static const char *tune_preemphasis[] = {
@@ -429,10 +435,13 @@ const char *v4l2_ctrl_get_name(u32 id)
        case V4L2_CID_SHARPNESS:                return "Sharpness";
        case V4L2_CID_BACKLIGHT_COMPENSATION:   return "Backlight Compensation";
        case V4L2_CID_CHROMA_AGC:               return "Chroma AGC";
+       case V4L2_CID_CHROMA_GAIN:              return "Chroma Gain";
        case V4L2_CID_COLOR_KILLER:             return "Color Killer";
        case V4L2_CID_COLORFX:                  return "Color Effects";
+       case V4L2_CID_AUTOBRIGHTNESS:           return "Brightness, Automatic";
+       case V4L2_CID_BAND_STOP_FILTER:         return "Band-Stop Filter";
        case V4L2_CID_ROTATE:                   return "Rotate";
-       case V4L2_CID_BG_COLOR:                 return "Background color";
+       case V4L2_CID_BG_COLOR:                 return "Background Color";
 
        /* MPEG controls */
        case V4L2_CID_MPEG_CLASS:               return "MPEG Encoder Controls";
@@ -483,6 +492,8 @@ const char *v4l2_ctrl_get_name(u32 id)
        case V4L2_CID_FOCUS_ABSOLUTE:           return "Focus, Absolute";
        case V4L2_CID_FOCUS_RELATIVE:           return "Focus, Relative";
        case V4L2_CID_FOCUS_AUTO:               return "Focus, Automatic";
+       case V4L2_CID_IRIS_ABSOLUTE:            return "Iris, Absolute";
+       case V4L2_CID_IRIS_RELATIVE:            return "Iris, Relative";
        case V4L2_CID_ZOOM_ABSOLUTE:            return "Zoom, Absolute";
        case V4L2_CID_ZOOM_RELATIVE:            return "Zoom, Relative";
        case V4L2_CID_ZOOM_CONTINUOUS:          return "Zoom, Continuous";
@@ -620,6 +631,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
        case V4L2_CID_BLUE_BALANCE:
        case V4L2_CID_GAMMA:
        case V4L2_CID_SHARPNESS:
+       case V4L2_CID_CHROMA_GAIN:
        case V4L2_CID_RDS_TX_DEVIATION:
        case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
        case V4L2_CID_AUDIO_LIMITER_DEVIATION:
@@ -636,6 +648,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
        case V4L2_CID_PAN_RELATIVE:
        case V4L2_CID_TILT_RELATIVE:
        case V4L2_CID_FOCUS_RELATIVE:
+       case V4L2_CID_IRIS_RELATIVE:
        case V4L2_CID_ZOOM_RELATIVE:
                qctrl->flags |= V4L2_CTRL_FLAG_WRITE_ONLY;
                break;
@@ -951,6 +964,66 @@ EXPORT_SYMBOL_GPL(v4l2_i2c_tuner_addrs);
 
 #endif /* defined(CONFIG_I2C) */
 
+#if defined(CONFIG_SPI)
+
+/* Load a spi sub-device. */
+
+void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
+               const struct v4l2_subdev_ops *ops)
+{
+       v4l2_subdev_init(sd, ops);
+       sd->flags |= V4L2_SUBDEV_FL_IS_SPI;
+       /* the owner is the same as the spi_device's driver owner */
+       sd->owner = spi->dev.driver->owner;
+       /* spi_device and v4l2_subdev point to one another */
+       v4l2_set_subdevdata(sd, spi);
+       spi_set_drvdata(spi, sd);
+       /* initialize name */
+       strlcpy(sd->name, spi->dev.driver->name, sizeof(sd->name));
+}
+EXPORT_SYMBOL_GPL(v4l2_spi_subdev_init);
+
+struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
+               struct spi_master *master, struct spi_board_info *info)
+{
+       struct v4l2_subdev *sd = NULL;
+       struct spi_device *spi = NULL;
+
+       BUG_ON(!v4l2_dev);
+
+       if (info->modalias)
+               request_module(info->modalias);
+
+       spi = spi_new_device(master, info);
+
+       if (spi == NULL || spi->dev.driver == NULL)
+               goto error;
+
+       if (!try_module_get(spi->dev.driver->owner))
+               goto error;
+
+       sd = spi_get_drvdata(spi);
+
+       /* Register with the v4l2_device which increases the module's
+          use count as well. */
+       if (v4l2_device_register_subdev(v4l2_dev, sd))
+               sd = NULL;
+
+       /* Decrease the module use count to match the first try_module_get. */
+       module_put(spi->dev.driver->owner);
+
+error:
+       /* If we have a client but no subdev, then something went wrong and
+          we must unregister the client. */
+       if (spi && sd == NULL)
+               spi_unregister_device(spi);
+
+       return sd;
+}
+EXPORT_SYMBOL_GPL(v4l2_spi_new_subdev);
+
+#endif /* defined(CONFIG_SPI) */
+
 /* Clamp x to be between min and max, aligned to a multiple of 2^align.  min
  * and max don't have to be aligned, but there must be at least one valid
  * value.  E.g., min=17,max=31,align=4 is not allowed as there are no multiples
index f77f84b..9004a5f 100644 (file)
@@ -1086,6 +1086,9 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
        case VIDIOC_QUERY_DV_PRESET:
        case VIDIOC_S_DV_TIMINGS:
        case VIDIOC_G_DV_TIMINGS:
+       case VIDIOC_DQEVENT:
+       case VIDIOC_SUBSCRIBE_EVENT:
+       case VIDIOC_UNSUBSCRIBE_EVENT:
                ret = do_video_ioctl(file, cmd, arg);
                break;
 
index 7090699..0ca7ec9 100644 (file)
@@ -421,6 +421,10 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
        if (!vdev->release)
                return -EINVAL;
 
+       /* v4l2_fh support */
+       spin_lock_init(&vdev->fh_lock);
+       INIT_LIST_HEAD(&vdev->fh_list);
+
        /* Part 1: check device type */
        switch (type) {
        case VFL_TYPE_GRABBER:
@@ -596,9 +600,7 @@ void video_unregister_device(struct video_device *vdev)
        if (!vdev || !video_is_registered(vdev))
                return;
 
-       mutex_lock(&videodev_lock);
        clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
-       mutex_unlock(&videodev_lock);
        device_unregister(&vdev->dev);
 }
 EXPORT_SYMBOL(video_unregister_device);
index 0d06e7c..5a7dc4a 100644 (file)
@@ -21,6 +21,9 @@
 #include <linux/types.h>
 #include <linux/ioctl.h>
 #include <linux/i2c.h>
+#if defined(CONFIG_SPI)
+#include <linux/spi/spi.h>
+#endif
 #include <linux/videodev2.h>
 #include <media/v4l2-device.h>
 
@@ -96,6 +99,14 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
                        if (client)
                                i2c_unregister_device(client);
                }
+#endif
+#if defined(CONFIG_SPI)
+               if (sd->flags & V4L2_SUBDEV_FL_IS_SPI) {
+                       struct spi_device *spi = v4l2_get_subdevdata(sd);
+
+                       if (spi)
+                               spi_unregister_device(spi);
+               }
 #endif
        }
 }
diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c
new file mode 100644 (file)
index 0000000..de74ce0
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * v4l2-event.c
+ *
+ * V4L2 events.
+ *
+ * Copyright (C) 2009--2010 Nokia Corporation.
+ *
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <media/v4l2-dev.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-event.h>
+
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+int v4l2_event_init(struct v4l2_fh *fh)
+{
+       fh->events = kzalloc(sizeof(*fh->events), GFP_KERNEL);
+       if (fh->events == NULL)
+               return -ENOMEM;
+
+       init_waitqueue_head(&fh->events->wait);
+
+       INIT_LIST_HEAD(&fh->events->free);
+       INIT_LIST_HEAD(&fh->events->available);
+       INIT_LIST_HEAD(&fh->events->subscribed);
+
+       fh->events->sequence = -1;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_init);
+
+int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n)
+{
+       struct v4l2_events *events = fh->events;
+       unsigned long flags;
+
+       if (!events) {
+               WARN_ON(1);
+               return -ENOMEM;
+       }
+
+       while (events->nallocated < n) {
+               struct v4l2_kevent *kev;
+
+               kev = kzalloc(sizeof(*kev), GFP_KERNEL);
+               if (kev == NULL)
+                       return -ENOMEM;
+
+               spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+               list_add_tail(&kev->list, &events->free);
+               events->nallocated++;
+               spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_alloc);
+
+#define list_kfree(list, type, member)                         \
+       while (!list_empty(list)) {                             \
+               type *hi;                                       \
+               hi = list_first_entry(list, type, member);      \
+               list_del(&hi->member);                          \
+               kfree(hi);                                      \
+       }
+
+void v4l2_event_free(struct v4l2_fh *fh)
+{
+       struct v4l2_events *events = fh->events;
+
+       if (!events)
+               return;
+
+       list_kfree(&events->free, struct v4l2_kevent, list);
+       list_kfree(&events->available, struct v4l2_kevent, list);
+       list_kfree(&events->subscribed, struct v4l2_subscribed_event, list);
+
+       kfree(events);
+       fh->events = NULL;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_free);
+
+static int __v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event)
+{
+       struct v4l2_events *events = fh->events;
+       struct v4l2_kevent *kev;
+       unsigned long flags;
+
+       spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+
+       if (list_empty(&events->available)) {
+               spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+               return -ENOENT;
+       }
+
+       WARN_ON(events->navailable == 0);
+
+       kev = list_first_entry(&events->available, struct v4l2_kevent, list);
+       list_move(&kev->list, &events->free);
+       events->navailable--;
+
+       kev->event.pending = events->navailable;
+       *event = kev->event;
+
+       spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+
+       return 0;
+}
+
+int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
+                      int nonblocking)
+{
+       struct v4l2_events *events = fh->events;
+       int ret;
+
+       if (nonblocking)
+               return __v4l2_event_dequeue(fh, event);
+
+       do {
+               ret = wait_event_interruptible(events->wait,
+                                              events->navailable != 0);
+               if (ret < 0)
+                       return ret;
+
+               ret = __v4l2_event_dequeue(fh, event);
+       } while (ret == -ENOENT);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_dequeue);
+
+/* Caller must hold fh->event->lock! */
+static struct v4l2_subscribed_event *v4l2_event_subscribed(
+       struct v4l2_fh *fh, u32 type)
+{
+       struct v4l2_events *events = fh->events;
+       struct v4l2_subscribed_event *sev;
+
+       assert_spin_locked(&fh->vdev->fh_lock);
+
+       list_for_each_entry(sev, &events->subscribed, list) {
+               if (sev->type == type)
+                       return sev;
+       }
+
+       return NULL;
+}
+
+void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev)
+{
+       struct v4l2_fh *fh;
+       unsigned long flags;
+       struct timespec timestamp;
+
+       ktime_get_ts(&timestamp);
+
+       spin_lock_irqsave(&vdev->fh_lock, flags);
+
+       list_for_each_entry(fh, &vdev->fh_list, list) {
+               struct v4l2_events *events = fh->events;
+               struct v4l2_kevent *kev;
+
+               /* Are we subscribed? */
+               if (!v4l2_event_subscribed(fh, ev->type))
+                       continue;
+
+               /* Increase event sequence number on fh. */
+               events->sequence++;
+
+               /* Do we have any free events? */
+               if (list_empty(&events->free))
+                       continue;
+
+               /* Take one and fill it. */
+               kev = list_first_entry(&events->free, struct v4l2_kevent, list);
+               kev->event.type = ev->type;
+               kev->event.u = ev->u;
+               kev->event.timestamp = timestamp;
+               kev->event.sequence = events->sequence;
+               list_move_tail(&kev->list, &events->available);
+
+               events->navailable++;
+
+               wake_up_all(&events->wait);
+       }
+
+       spin_unlock_irqrestore(&vdev->fh_lock, flags);
+}
+EXPORT_SYMBOL_GPL(v4l2_event_queue);
+
+int v4l2_event_pending(struct v4l2_fh *fh)
+{
+       return fh->events->navailable;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_pending);
+
+int v4l2_event_subscribe(struct v4l2_fh *fh,
+                        struct v4l2_event_subscription *sub)
+{
+       struct v4l2_events *events = fh->events;
+       struct v4l2_subscribed_event *sev;
+       unsigned long flags;
+
+       if (fh->events == NULL) {
+               WARN_ON(1);
+               return -ENOMEM;
+       }
+
+       sev = kmalloc(sizeof(*sev), GFP_KERNEL);
+       if (!sev)
+               return -ENOMEM;
+
+       spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+
+       if (v4l2_event_subscribed(fh, sub->type) == NULL) {
+               INIT_LIST_HEAD(&sev->list);
+               sev->type = sub->type;
+
+               list_add(&sev->list, &events->subscribed);
+               sev = NULL;
+       }
+
+       spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+
+       kfree(sev);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_subscribe);
+
+static void v4l2_event_unsubscribe_all(struct v4l2_fh *fh)
+{
+       struct v4l2_events *events = fh->events;
+       struct v4l2_subscribed_event *sev;
+       unsigned long flags;
+
+       do {
+               sev = NULL;
+
+               spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+               if (!list_empty(&events->subscribed)) {
+                       sev = list_first_entry(&events->subscribed,
+                                      struct v4l2_subscribed_event, list);
+                       list_del(&sev->list);
+               }
+               spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+               kfree(sev);
+       } while (sev);
+}
+
+int v4l2_event_unsubscribe(struct v4l2_fh *fh,
+                          struct v4l2_event_subscription *sub)
+{
+       struct v4l2_subscribed_event *sev;
+       unsigned long flags;
+
+       if (sub->type == V4L2_EVENT_ALL) {
+               v4l2_event_unsubscribe_all(fh);
+               return 0;
+       }
+
+       spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+
+       sev = v4l2_event_subscribed(fh, sub->type);
+       if (sev != NULL)
+               list_del(&sev->list);
+
+       spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+
+       kfree(sev);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_event_unsubscribe);
diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c
new file mode 100644 (file)
index 0000000..d78f184
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * v4l2-fh.c
+ *
+ * V4L2 file handles.
+ *
+ * Copyright (C) 2009--2010 Nokia Corporation.
+ *
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <linux/bitops.h>
+#include <media/v4l2-dev.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-event.h>
+#include <media/v4l2-ioctl.h>
+
+int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev)
+{
+       fh->vdev = vdev;
+       INIT_LIST_HEAD(&fh->list);
+       set_bit(V4L2_FL_USES_V4L2_FH, &fh->vdev->flags);
+
+       /*
+        * fh->events only needs to be initialized if the driver
+        * supports the VIDIOC_SUBSCRIBE_EVENT ioctl.
+        */
+       if (vdev->ioctl_ops && vdev->ioctl_ops->vidioc_subscribe_event)
+               return v4l2_event_init(fh);
+
+       fh->events = NULL;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(v4l2_fh_init);
+
+void v4l2_fh_add(struct v4l2_fh *fh)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+       list_add(&fh->list, &fh->vdev->fh_list);
+       spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+}
+EXPORT_SYMBOL_GPL(v4l2_fh_add);
+
+void v4l2_fh_del(struct v4l2_fh *fh)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&fh->vdev->fh_lock, flags);
+       list_del_init(&fh->list);
+       spin_unlock_irqrestore(&fh->vdev->fh_lock, flags);
+}
+EXPORT_SYMBOL_GPL(v4l2_fh_del);
+
+void v4l2_fh_exit(struct v4l2_fh *fh)
+{
+       if (fh->vdev == NULL)
+               return;
+
+       fh->vdev = NULL;
+
+       v4l2_event_free(fh);
+}
+EXPORT_SYMBOL_GPL(v4l2_fh_exit);
index 7d59c10..0eeceae 100644 (file)
@@ -26,6 +26,8 @@
 #endif
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-event.h>
 #include <media/v4l2-chip-ident.h>
 
 #define dbgarg(cmd, fmt, arg...) \
@@ -291,6 +293,9 @@ static const char *v4l2_ioctls[] = {
        [_IOC_NR(VIDIOC_QUERY_DV_PRESET)]  = "VIDIOC_QUERY_DV_PRESET",
        [_IOC_NR(VIDIOC_S_DV_TIMINGS)]     = "VIDIOC_S_DV_TIMINGS",
        [_IOC_NR(VIDIOC_G_DV_TIMINGS)]     = "VIDIOC_G_DV_TIMINGS",
+       [_IOC_NR(VIDIOC_DQEVENT)]          = "VIDIOC_DQEVENT",
+       [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)]  = "VIDIOC_SUBSCRIBE_EVENT",
+       [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
 };
 #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
 
@@ -610,17 +615,33 @@ static long __video_do_ioctl(struct file *file,
        void *fh = file->private_data;
        long ret = -EINVAL;
 
+       if (ops == NULL) {
+               printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
+                               vfd->name);
+               return -EINVAL;
+       }
+
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       /********************************************************
+        All other V4L1 calls are handled by v4l1_compat module.
+        Those calls will be translated into V4L2 calls, and
+        __video_do_ioctl will be called again, with one or more
+        V4L2 ioctls.
+        ********************************************************/
+       if (_IOC_TYPE(cmd) == 'v' && cmd != VIDIOCGMBUF &&
+                               _IOC_NR(cmd) < BASE_VIDIOCPRIVATE) {
+               return v4l_compat_translate_ioctl(file, cmd, arg,
+                                               __video_do_ioctl);
+       }
+#endif
+
        if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
                                !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
                v4l_print_ioctl(vfd->name, cmd);
                printk(KERN_CONT "\n");
        }
 
-       if (ops == NULL) {
-               printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
-                               vfd->name);
-               return -EINVAL;
-       }
+       switch (cmd) {
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
        /***********************************************************
@@ -630,31 +651,21 @@ static long __video_do_ioctl(struct file *file,
         ***********************************************************/
 
        /* --- streaming capture ------------------------------------- */
-       if (cmd == VIDIOCGMBUF) {
+       case VIDIOCGMBUF:
+       {
                struct video_mbuf *p = arg;
 
                if (!ops->vidiocgmbuf)
-                       return ret;
+                       break;
                ret = ops->vidiocgmbuf(file, fh, p);
                if (!ret)
                        dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
                                                p->size, p->frames,
                                                (unsigned long)p->offsets);
-               return ret;
+               break;
        }
-
-       /********************************************************
-        All other V4L1 calls are handled by v4l1_compat module.
-        Those calls will be translated into V4L2 calls, and
-        __video_do_ioctl will be called again, with one or more
-        V4L2 ioctls.
-        ********************************************************/
-       if (_IOC_TYPE(cmd) == 'v' && _IOC_NR(cmd) < BASE_VIDIOCPRIVATE)
-               return v4l_compat_translate_ioctl(file, cmd, arg,
-                                               __video_do_ioctl);
 #endif
 
-       switch (cmd) {
        /* --- capabilities ------------------------------------------ */
        case VIDIOC_QUERYCAP:
        {
@@ -1072,7 +1083,7 @@ static long __video_do_ioctl(struct file *file,
                                id &= ~curr_id;
                }
                if (i <= index)
-                       return -EINVAL;
+                       break;
 
                v4l2_video_std_construct(p, curr_id, descr);
 
@@ -1597,7 +1608,7 @@ static long __video_do_ioctl(struct file *file,
                        v4l2_std_id std = vfd->current_norm;
 
                        if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-                               return -EINVAL;
+                               break;
 
                        ret = 0;
                        if (ops->vidioc_g_std)
@@ -1942,7 +1953,55 @@ static long __video_do_ioctl(struct file *file,
                }
                break;
        }
+       case VIDIOC_DQEVENT:
+       {
+               struct v4l2_event *ev = arg;
+
+               if (!ops->vidioc_subscribe_event)
+                       break;
 
+               ret = v4l2_event_dequeue(fh, ev, file->f_flags & O_NONBLOCK);
+               if (ret < 0) {
+                       dbgarg(cmd, "no pending events?");
+                       break;
+               }
+               dbgarg(cmd,
+                      "pending=%d, type=0x%8.8x, sequence=%d, "
+                      "timestamp=%lu.%9.9lu ",
+                      ev->pending, ev->type, ev->sequence,
+                      ev->timestamp.tv_sec, ev->timestamp.tv_nsec);
+               break;
+       }
+       case VIDIOC_SUBSCRIBE_EVENT:
+       {
+               struct v4l2_event_subscription *sub = arg;
+
+               if (!ops->vidioc_subscribe_event)
+                       break;
+
+               ret = ops->vidioc_subscribe_event(fh, sub);
+               if (ret < 0) {
+                       dbgarg(cmd, "failed, ret=%ld", ret);
+                       break;
+               }
+               dbgarg(cmd, "type=0x%8.8x", sub->type);
+               break;
+       }
+       case VIDIOC_UNSUBSCRIBE_EVENT:
+       {
+               struct v4l2_event_subscription *sub = arg;
+
+               if (!ops->vidioc_unsubscribe_event)
+                       break;
+
+               ret = ops->vidioc_unsubscribe_event(fh, sub);
+               if (ret < 0) {
+                       dbgarg(cmd, "failed, ret=%ld", ret);
+                       break;
+               }
+               dbgarg(cmd, "type=0x%8.8x", sub->type);
+               break;
+       }
        default:
        {
                if (!ops->vidioc_default)
@@ -2006,7 +2065,7 @@ long video_ioctl2(struct file *file,
 {
        char    sbuf[128];
        void    *mbuf = NULL;
-       void    *parg = NULL;
+       void    *parg = (void *)arg;
        long    err  = -EINVAL;
        int     is_ext_ctrl;
        size_t  ctrls_size = 0;
diff --git a/drivers/media/video/v4l2-mem2mem.c b/drivers/media/video/v4l2-mem2mem.c
new file mode 100644 (file)
index 0000000..f45f940
--- /dev/null
@@ -0,0 +1,633 @@
+/*
+ * Memory-to-memory device framework for Video for Linux 2 and videobuf.
+ *
+ * Helper functions for devices that use videobuf buffers for both their
+ * source and destination.
+ *
+ * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
+ * Pawel Osciak, <p.osciak@samsung.com>
+ * Marek Szyprowski, <m.szyprowski@samsung.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.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include <media/videobuf-core.h>
+#include <media/v4l2-mem2mem.h>
+
+MODULE_DESCRIPTION("Mem to mem device framework for videobuf");
+MODULE_AUTHOR("Pawel Osciak, <p.osciak@samsung.com>");
+MODULE_LICENSE("GPL");
+
+static bool debug;
+module_param(debug, bool, 0644);
+
+#define dprintk(fmt, arg...)                                           \
+       do {                                                            \
+               if (debug)                                              \
+                       printk(KERN_DEBUG "%s: " fmt, __func__, ## arg);\
+       } while (0)
+
+
+/* Instance is already queued on the job_queue */
+#define TRANS_QUEUED           (1 << 0)
+/* Instance is currently running in hardware */
+#define TRANS_RUNNING          (1 << 1)
+
+
+/* Offset base for buffers on the destination queue - used to distinguish
+ * between source and destination buffers when mmapping - they receive the same
+ * offsets but for different queues */
+#define DST_QUEUE_OFF_BASE     (1 << 30)
+
+
+/**
+ * struct v4l2_m2m_dev - per-device context
+ * @curr_ctx:          currently running instance
+ * @job_queue:         instances queued to run
+ * @job_spinlock:      protects job_queue
+ * @m2m_ops:           driver callbacks
+ */
+struct v4l2_m2m_dev {
+       struct v4l2_m2m_ctx     *curr_ctx;
+
+       struct list_head        job_queue;
+       spinlock_t              job_spinlock;
+
+       struct v4l2_m2m_ops     *m2m_ops;
+};
+
+static struct v4l2_m2m_queue_ctx *get_queue_ctx(struct v4l2_m2m_ctx *m2m_ctx,
+                                               enum v4l2_buf_type type)
+{
+       switch (type) {
+       case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               return &m2m_ctx->cap_q_ctx;
+       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+               return &m2m_ctx->out_q_ctx;
+       default:
+               printk(KERN_ERR "Invalid buffer type\n");
+               return NULL;
+       }
+}
+
+/**
+ * v4l2_m2m_get_vq() - return videobuf_queue for the given type
+ */
+struct videobuf_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
+                                      enum v4l2_buf_type type)
+{
+       struct v4l2_m2m_queue_ctx *q_ctx;
+
+       q_ctx = get_queue_ctx(m2m_ctx, type);
+       if (!q_ctx)
+               return NULL;
+
+       return &q_ctx->q;
+}
+EXPORT_SYMBOL(v4l2_m2m_get_vq);
+
+/**
+ * v4l2_m2m_next_buf() - return next buffer from the list of ready buffers
+ */
+void *v4l2_m2m_next_buf(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type)
+{
+       struct v4l2_m2m_queue_ctx *q_ctx;
+       struct videobuf_buffer *vb = NULL;
+       unsigned long flags;
+
+       q_ctx = get_queue_ctx(m2m_ctx, type);
+       if (!q_ctx)
+               return NULL;
+
+       spin_lock_irqsave(q_ctx->q.irqlock, flags);
+
+       if (list_empty(&q_ctx->rdy_queue))
+               goto end;
+
+       vb = list_entry(q_ctx->rdy_queue.next, struct videobuf_buffer, queue);
+       vb->state = VIDEOBUF_ACTIVE;
+
+end:
+       spin_unlock_irqrestore(q_ctx->q.irqlock, flags);
+       return vb;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_next_buf);
+
+/**
+ * v4l2_m2m_buf_remove() - take off a buffer from the list of ready buffers and
+ * return it
+ */
+void *v4l2_m2m_buf_remove(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type)
+{
+       struct v4l2_m2m_queue_ctx *q_ctx;
+       struct videobuf_buffer *vb = NULL;
+       unsigned long flags;
+
+       q_ctx = get_queue_ctx(m2m_ctx, type);
+       if (!q_ctx)
+               return NULL;
+
+       spin_lock_irqsave(q_ctx->q.irqlock, flags);
+       if (!list_empty(&q_ctx->rdy_queue)) {
+               vb = list_entry(q_ctx->rdy_queue.next, struct videobuf_buffer,
+                               queue);
+               list_del(&vb->queue);
+               q_ctx->num_rdy--;
+       }
+       spin_unlock_irqrestore(q_ctx->q.irqlock, flags);
+
+       return vb;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_buf_remove);
+
+/*
+ * Scheduling handlers
+ */
+
+/**
+ * v4l2_m2m_get_curr_priv() - return driver private data for the currently
+ * running instance or NULL if no instance is running
+ */
+void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev)
+{
+       unsigned long flags;
+       void *ret = NULL;
+
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+       if (m2m_dev->curr_ctx)
+               ret = m2m_dev->curr_ctx->priv;
+       spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(v4l2_m2m_get_curr_priv);
+
+/**
+ * v4l2_m2m_try_run() - select next job to perform and run it if possible
+ *
+ * Get next transaction (if present) from the waiting jobs list and run it.
+ */
+static void v4l2_m2m_try_run(struct v4l2_m2m_dev *m2m_dev)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+       if (NULL != m2m_dev->curr_ctx) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+               dprintk("Another instance is running, won't run now\n");
+               return;
+       }
+
+       if (list_empty(&m2m_dev->job_queue)) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+               dprintk("No job pending\n");
+               return;
+       }
+
+       m2m_dev->curr_ctx = list_entry(m2m_dev->job_queue.next,
+                                  struct v4l2_m2m_ctx, queue);
+       m2m_dev->curr_ctx->job_flags |= TRANS_RUNNING;
+       spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+
+       m2m_dev->m2m_ops->device_run(m2m_dev->curr_ctx->priv);
+}
+
+/**
+ * v4l2_m2m_try_schedule() - check whether an instance is ready to be added to
+ * the pending job queue and add it if so.
+ * @m2m_ctx:   m2m context assigned to the instance to be checked
+ *
+ * There are three basic requirements an instance has to meet to be able to run:
+ * 1) at least one source buffer has to be queued,
+ * 2) at least one destination buffer has to be queued,
+ * 3) streaming has to be on.
+ *
+ * There may also be additional, custom requirements. In such case the driver
+ * should supply a custom callback (job_ready in v4l2_m2m_ops) that should
+ * return 1 if the instance is ready.
+ * An example of the above could be an instance that requires more than one
+ * src/dst buffer per transaction.
+ */
+static void v4l2_m2m_try_schedule(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       struct v4l2_m2m_dev *m2m_dev;
+       unsigned long flags_job, flags;
+
+       m2m_dev = m2m_ctx->m2m_dev;
+       dprintk("Trying to schedule a job for m2m_ctx: %p\n", m2m_ctx);
+
+       if (!m2m_ctx->out_q_ctx.q.streaming
+           || !m2m_ctx->cap_q_ctx.q.streaming) {
+               dprintk("Streaming needs to be on for both queues\n");
+               return;
+       }
+
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags_job);
+       if (m2m_ctx->job_flags & TRANS_QUEUED) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+               dprintk("On job queue already\n");
+               return;
+       }
+
+       spin_lock_irqsave(m2m_ctx->out_q_ctx.q.irqlock, flags);
+       if (list_empty(&m2m_ctx->out_q_ctx.rdy_queue)) {
+               spin_unlock_irqrestore(m2m_ctx->out_q_ctx.q.irqlock, flags);
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+               dprintk("No input buffers available\n");
+               return;
+       }
+       if (list_empty(&m2m_ctx->cap_q_ctx.rdy_queue)) {
+               spin_unlock_irqrestore(m2m_ctx->out_q_ctx.q.irqlock, flags);
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+               dprintk("No output buffers available\n");
+               return;
+       }
+       spin_unlock_irqrestore(m2m_ctx->out_q_ctx.q.irqlock, flags);
+
+       if (m2m_dev->m2m_ops->job_ready
+               && (!m2m_dev->m2m_ops->job_ready(m2m_ctx->priv))) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+               dprintk("Driver not ready\n");
+               return;
+       }
+
+       list_add_tail(&m2m_ctx->queue, &m2m_dev->job_queue);
+       m2m_ctx->job_flags |= TRANS_QUEUED;
+
+       spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags_job);
+
+       v4l2_m2m_try_run(m2m_dev);
+}
+
+/**
+ * v4l2_m2m_job_finish() - inform the framework that a job has been finished
+ * and have it clean up
+ *
+ * Called by a driver to yield back the device after it has finished with it.
+ * Should be called as soon as possible after reaching a state which allows
+ * other instances to take control of the device.
+ *
+ * This function has to be called only after device_run() callback has been
+ * called on the driver. To prevent recursion, it should not be called directly
+ * from the device_run() callback though.
+ */
+void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
+                        struct v4l2_m2m_ctx *m2m_ctx)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+       if (!m2m_dev->curr_ctx || m2m_dev->curr_ctx != m2m_ctx) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+               dprintk("Called by an instance not currently running\n");
+               return;
+       }
+
+       list_del(&m2m_dev->curr_ctx->queue);
+       m2m_dev->curr_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
+       m2m_dev->curr_ctx = NULL;
+
+       spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+
+       /* This instance might have more buffers ready, but since we do not
+        * allow more than one job on the job_queue per instance, each has
+        * to be scheduled separately after the previous one finishes. */
+       v4l2_m2m_try_schedule(m2m_ctx);
+       v4l2_m2m_try_run(m2m_dev);
+}
+EXPORT_SYMBOL(v4l2_m2m_job_finish);
+
+/**
+ * v4l2_m2m_reqbufs() - multi-queue-aware REQBUFS multiplexer
+ */
+int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                    struct v4l2_requestbuffers *reqbufs)
+{
+       struct videobuf_queue *vq;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, reqbufs->type);
+       return videobuf_reqbufs(vq, reqbufs);
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_reqbufs);
+
+/**
+ * v4l2_m2m_querybuf() - multi-queue-aware QUERYBUF multiplexer
+ *
+ * See v4l2_m2m_mmap() documentation for details.
+ */
+int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                     struct v4l2_buffer *buf)
+{
+       struct videobuf_queue *vq;
+       int ret;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
+       ret = videobuf_querybuf(vq, buf);
+
+       if (buf->memory == V4L2_MEMORY_MMAP
+           && vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+               buf->m.offset += DST_QUEUE_OFF_BASE;
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_querybuf);
+
+/**
+ * v4l2_m2m_qbuf() - enqueue a source or destination buffer, depending on
+ * the type
+ */
+int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                 struct v4l2_buffer *buf)
+{
+       struct videobuf_queue *vq;
+       int ret;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
+       ret = videobuf_qbuf(vq, buf);
+       if (!ret)
+               v4l2_m2m_try_schedule(m2m_ctx);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_qbuf);
+
+/**
+ * v4l2_m2m_dqbuf() - dequeue a source or destination buffer, depending on
+ * the type
+ */
+int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                  struct v4l2_buffer *buf)
+{
+       struct videobuf_queue *vq;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, buf->type);
+       return videobuf_dqbuf(vq, buf, file->f_flags & O_NONBLOCK);
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_dqbuf);
+
+/**
+ * v4l2_m2m_streamon() - turn on streaming for a video queue
+ */
+int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                     enum v4l2_buf_type type)
+{
+       struct videobuf_queue *vq;
+       int ret;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, type);
+       ret = videobuf_streamon(vq);
+       if (!ret)
+               v4l2_m2m_try_schedule(m2m_ctx);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_streamon);
+
+/**
+ * v4l2_m2m_streamoff() - turn off streaming for a video queue
+ */
+int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                      enum v4l2_buf_type type)
+{
+       struct videobuf_queue *vq;
+
+       vq = v4l2_m2m_get_vq(m2m_ctx, type);
+       return videobuf_streamoff(vq);
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_streamoff);
+
+/**
+ * v4l2_m2m_poll() - poll replacement, for destination buffers only
+ *
+ * Call from the driver's poll() function. Will poll both queues. If a buffer
+ * is available to dequeue (with dqbuf) from the source queue, this will
+ * indicate that a non-blocking write can be performed, while read will be
+ * returned in case of the destination queue.
+ */
+unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                          struct poll_table_struct *wait)
+{
+       struct videobuf_queue *src_q, *dst_q;
+       struct videobuf_buffer *src_vb = NULL, *dst_vb = NULL;
+       unsigned int rc = 0;
+
+       src_q = v4l2_m2m_get_src_vq(m2m_ctx);
+       dst_q = v4l2_m2m_get_dst_vq(m2m_ctx);
+
+       mutex_lock(&src_q->vb_lock);
+       mutex_lock(&dst_q->vb_lock);
+
+       if (src_q->streaming && !list_empty(&src_q->stream))
+               src_vb = list_first_entry(&src_q->stream,
+                                         struct videobuf_buffer, stream);
+       if (dst_q->streaming && !list_empty(&dst_q->stream))
+               dst_vb = list_first_entry(&dst_q->stream,
+                                         struct videobuf_buffer, stream);
+
+       if (!src_vb && !dst_vb) {
+               rc = POLLERR;
+               goto end;
+       }
+
+       if (src_vb) {
+               poll_wait(file, &src_vb->done, wait);
+               if (src_vb->state == VIDEOBUF_DONE
+                   || src_vb->state == VIDEOBUF_ERROR)
+                       rc |= POLLOUT | POLLWRNORM;
+       }
+       if (dst_vb) {
+               poll_wait(file, &dst_vb->done, wait);
+               if (dst_vb->state == VIDEOBUF_DONE
+                   || dst_vb->state == VIDEOBUF_ERROR)
+                       rc |= POLLIN | POLLRDNORM;
+       }
+
+end:
+       mutex_unlock(&dst_q->vb_lock);
+       mutex_unlock(&src_q->vb_lock);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_poll);
+
+/**
+ * v4l2_m2m_mmap() - source and destination queues-aware mmap multiplexer
+ *
+ * Call from driver's mmap() function. Will handle mmap() for both queues
+ * seamlessly for videobuffer, which will receive normal per-queue offsets and
+ * proper videobuf queue pointers. The differentiation is made outside videobuf
+ * by adding a predefined offset to buffers from one of the queues and
+ * subtracting it before passing it back to videobuf. Only drivers (and
+ * thus applications) receive modified offsets.
+ */
+int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                        struct vm_area_struct *vma)
+{
+       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+       struct videobuf_queue *vq;
+
+       if (offset < DST_QUEUE_OFF_BASE) {
+               vq = v4l2_m2m_get_src_vq(m2m_ctx);
+       } else {
+               vq = v4l2_m2m_get_dst_vq(m2m_ctx);
+               vma->vm_pgoff -= (DST_QUEUE_OFF_BASE >> PAGE_SHIFT);
+       }
+
+       return videobuf_mmap_mapper(vq, vma);
+}
+EXPORT_SYMBOL(v4l2_m2m_mmap);
+
+/**
+ * v4l2_m2m_init() - initialize per-driver m2m data
+ *
+ * Usually called from driver's probe() function.
+ */
+struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops)
+{
+       struct v4l2_m2m_dev *m2m_dev;
+
+       if (!m2m_ops)
+               return ERR_PTR(-EINVAL);
+
+       BUG_ON(!m2m_ops->device_run);
+       BUG_ON(!m2m_ops->job_abort);
+
+       m2m_dev = kzalloc(sizeof *m2m_dev, GFP_KERNEL);
+       if (!m2m_dev)
+               return ERR_PTR(-ENOMEM);
+
+       m2m_dev->curr_ctx = NULL;
+       m2m_dev->m2m_ops = m2m_ops;
+       INIT_LIST_HEAD(&m2m_dev->job_queue);
+       spin_lock_init(&m2m_dev->job_spinlock);
+
+       return m2m_dev;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_init);
+
+/**
+ * v4l2_m2m_release() - cleans up and frees a m2m_dev structure
+ *
+ * Usually called from driver's remove() function.
+ */
+void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev)
+{
+       kfree(m2m_dev);
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_release);
+
+/**
+ * v4l2_m2m_ctx_init() - allocate and initialize a m2m context
+ * @priv - driver's instance private data
+ * @m2m_dev - a previously initialized m2m_dev struct
+ * @vq_init - a callback for queue type-specific initialization function to be
+ * used for initializing videobuf_queues
+ *
+ * Usually called from driver's open() function.
+ */
+struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(void *priv, struct v4l2_m2m_dev *m2m_dev,
+                       void (*vq_init)(void *priv, struct videobuf_queue *,
+                                       enum v4l2_buf_type))
+{
+       struct v4l2_m2m_ctx *m2m_ctx;
+       struct v4l2_m2m_queue_ctx *out_q_ctx, *cap_q_ctx;
+
+       if (!vq_init)
+               return ERR_PTR(-EINVAL);
+
+       m2m_ctx = kzalloc(sizeof *m2m_ctx, GFP_KERNEL);
+       if (!m2m_ctx)
+               return ERR_PTR(-ENOMEM);
+
+       m2m_ctx->priv = priv;
+       m2m_ctx->m2m_dev = m2m_dev;
+
+       out_q_ctx = get_queue_ctx(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+       cap_q_ctx = get_queue_ctx(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+
+       INIT_LIST_HEAD(&out_q_ctx->rdy_queue);
+       INIT_LIST_HEAD(&cap_q_ctx->rdy_queue);
+
+       INIT_LIST_HEAD(&m2m_ctx->queue);
+
+       vq_init(priv, &out_q_ctx->q, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+       vq_init(priv, &cap_q_ctx->q, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+       out_q_ctx->q.priv_data = cap_q_ctx->q.priv_data = priv;
+
+       return m2m_ctx;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_init);
+
+/**
+ * v4l2_m2m_ctx_release() - release m2m context
+ *
+ * Usually called from driver's release() function.
+ */
+void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       struct v4l2_m2m_dev *m2m_dev;
+       struct videobuf_buffer *vb;
+       unsigned long flags;
+
+       m2m_dev = m2m_ctx->m2m_dev;
+
+       spin_lock_irqsave(&m2m_dev->job_spinlock, flags);
+       if (m2m_ctx->job_flags & TRANS_RUNNING) {
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+               m2m_dev->m2m_ops->job_abort(m2m_ctx->priv);
+               dprintk("m2m_ctx %p running, will wait to complete", m2m_ctx);
+               vb = v4l2_m2m_next_dst_buf(m2m_ctx);
+               BUG_ON(NULL == vb);
+               wait_event(vb->done, vb->state != VIDEOBUF_ACTIVE
+                                    && vb->state != VIDEOBUF_QUEUED);
+       } else if (m2m_ctx->job_flags & TRANS_QUEUED) {
+               list_del(&m2m_ctx->queue);
+               m2m_ctx->job_flags &= ~(TRANS_QUEUED | TRANS_RUNNING);
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+               dprintk("m2m_ctx: %p had been on queue and was removed\n",
+                       m2m_ctx);
+       } else {
+               /* Do nothing, was not on queue/running */
+               spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags);
+       }
+
+       videobuf_stop(&m2m_ctx->cap_q_ctx.q);
+       videobuf_stop(&m2m_ctx->out_q_ctx.q);
+
+       videobuf_mmap_free(&m2m_ctx->cap_q_ctx.q);
+       videobuf_mmap_free(&m2m_ctx->out_q_ctx.q);
+
+       kfree(m2m_ctx);
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_ctx_release);
+
+/**
+ * v4l2_m2m_buf_queue() - add a buffer to the proper ready buffers list.
+ *
+ * Call from buf_queue(), videobuf_queue_ops callback.
+ *
+ * Locking: Caller holds q->irqlock (taken by videobuf before calling buf_queue
+ * callback in the driver).
+ */
+void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct videobuf_queue *vq,
+                       struct videobuf_buffer *vb)
+{
+       struct v4l2_m2m_queue_ctx *q_ctx;
+
+       q_ctx = get_queue_ctx(m2m_ctx, vq->type);
+       if (!q_ctx)
+               return;
+
+       list_add_tail(&vb->queue, &q_ctx->rdy_queue);
+       q_ctx->num_rdy++;
+
+       vb->state = VIDEOBUF_QUEUED;
+}
+EXPORT_SYMBOL_GPL(v4l2_m2m_buf_queue);
+
index bb0a1c8..7d33784 100644 (file)
 #include <media/videobuf-core.h>
 
 #define MAGIC_BUFFER 0x20070728
-#define MAGIC_CHECK(is, should) do {                                      \
-       if (unlikely((is) != (should))) {                                  \
-       printk(KERN_ERR "magic mismatch: %x (expected %x)\n", is, should); \
-       BUG(); } } while (0)
+#define MAGIC_CHECK(is, should)                                                \
+       do {                                                            \
+               if (unlikely((is) != (should))) {                       \
+                       printk(KERN_ERR                                 \
+                               "magic mismatch: %x (expected %x)\n",   \
+                                       is, should);                    \
+                       BUG();                                          \
+               }                                                       \
+       } while (0)
 
 static int debug;
 module_param(debug, int, 0644);
@@ -36,16 +41,18 @@ MODULE_DESCRIPTION("helper module to manage video4linux buffers");
 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
 MODULE_LICENSE("GPL");
 
-#define dprintk(level, fmt, arg...) do {                       \
-       if (debug >= level)                                     \
-       printk(KERN_DEBUG "vbuf: " fmt , ## arg); } while (0)
+#define dprintk(level, fmt, arg...)                                    \
+       do {                                                            \
+               if (debug >= level)                                     \
+                       printk(KERN_DEBUG "vbuf: " fmt, ## arg);        \
+       } while (0)
 
 /* --------------------------------------------------------------------- */
 
 #define CALL(q, f, arg...)                                             \
        ((q->int_ops->f) ? q->int_ops->f(arg) : 0)
 
-void *videobuf_alloc(struct videobuf_queue *q)
+struct videobuf_buffer *videobuf_alloc(struct videobuf_queue *q)
 {
        struct videobuf_buffer *vb;
 
@@ -57,14 +64,14 @@ void *videobuf_alloc(struct videobuf_queue *q)
        }
 
        vb = q->int_ops->alloc(q->msize);
-
        if (NULL != vb) {
                init_waitqueue_head(&vb->done);
-               vb->magic     = MAGIC_BUFFER;
+               vb->magic = MAGIC_BUFFER;
        }
 
        return vb;
 }
+EXPORT_SYMBOL_GPL(videobuf_alloc);
 
 #define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
                                vb->state != VIDEOBUF_QUEUED)
@@ -86,6 +93,7 @@ int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_waiton);
 
 int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
                    struct v4l2_framebuffer *fbuf)
@@ -95,16 +103,16 @@ int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
 
        return CALL(q, iolock, q, vb, fbuf);
 }
+EXPORT_SYMBOL_GPL(videobuf_iolock);
 
-void *videobuf_queue_to_vmalloc (struct videobuf_queue *q,
-                          struct videobuf_buffer *buf)
+void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
+                             struct videobuf_buffer *buf)
 {
-       if (q->int_ops->vmalloc)
-               return q->int_ops->vmalloc(buf);
-       else
-               return NULL;
+       if (q->int_ops->vaddr)
+               return q->int_ops->vaddr(buf);
+       return NULL;
 }
-EXPORT_SYMBOL_GPL(videobuf_queue_to_vmalloc);
+EXPORT_SYMBOL_GPL(videobuf_queue_to_vaddr);
 
 /* --------------------------------------------------------------------- */
 
@@ -146,6 +154,7 @@ void videobuf_queue_core_init(struct videobuf_queue *q,
        init_waitqueue_head(&q->wait);
        INIT_LIST_HEAD(&q->stream);
 }
+EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
 
 /* Locking: Only usage in bttv unsafe find way to remove */
 int videobuf_queue_is_busy(struct videobuf_queue *q)
@@ -184,6 +193,7 @@ int videobuf_queue_is_busy(struct videobuf_queue *q)
        }
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
 
 /* Locking: Caller holds q->vb_lock */
 void videobuf_queue_cancel(struct videobuf_queue *q)
@@ -216,6 +226,7 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
        }
        INIT_LIST_HEAD(&q->stream);
 }
+EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
 
 /* --------------------------------------------------------------------- */
 
@@ -237,6 +248,7 @@ enum v4l2_field videobuf_next_field(struct videobuf_queue *q)
        }
        return field;
 }
+EXPORT_SYMBOL_GPL(videobuf_next_field);
 
 /* Locking: Caller holds q->vb_lock */
 static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
@@ -273,8 +285,10 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
        case VIDEOBUF_ACTIVE:
                b->flags |= V4L2_BUF_FLAG_QUEUED;
                break;
-       case VIDEOBUF_DONE:
        case VIDEOBUF_ERROR:
+               b->flags |= V4L2_BUF_FLAG_ERROR;
+               /* fall through */
+       case VIDEOBUF_DONE:
                b->flags |= V4L2_BUF_FLAG_DONE;
                break;
        case VIDEOBUF_NEEDS_INIT:
@@ -298,20 +312,15 @@ static void videobuf_status(struct videobuf_queue *q, struct v4l2_buffer *b,
 static int __videobuf_mmap_free(struct videobuf_queue *q)
 {
        int i;
-       int rc;
 
        if (!q)
                return 0;
 
        MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
 
-
-       rc  = CALL(q, mmap_free, q);
-
-       q->is_mmapped = 0;
-
-       if (rc < 0)
-               return rc;
+       for (i = 0; i < VIDEO_MAX_FRAME; i++)
+               if (q->bufs[i] && q->bufs[i]->map)
+                       return -EBUSY;
 
        for (i = 0; i < VIDEO_MAX_FRAME; i++) {
                if (NULL == q->bufs[i])
@@ -321,7 +330,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
                q->bufs[i] = NULL;
        }
 
-       return rc;
+       return 0;
 }
 
 int videobuf_mmap_free(struct videobuf_queue *q)
@@ -332,6 +341,7 @@ int videobuf_mmap_free(struct videobuf_queue *q)
        mutex_unlock(&q->vb_lock);
        return ret;
 }
+EXPORT_SYMBOL_GPL(videobuf_mmap_free);
 
 /* Locking: Caller holds q->vb_lock */
 int __videobuf_mmap_setup(struct videobuf_queue *q,
@@ -351,7 +361,7 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
        for (i = 0; i < bcount; i++) {
                q->bufs[i] = videobuf_alloc(q);
 
-               if (q->bufs[i] == NULL)
+               if (NULL == q->bufs[i])
                        break;
 
                q->bufs[i]->i      = i;
@@ -372,11 +382,11 @@ int __videobuf_mmap_setup(struct videobuf_queue *q,
        if (!i)
                return -ENOMEM;
 
-       dprintk(1, "mmap setup: %d buffers, %d bytes each\n",
-               i, bsize);
+       dprintk(1, "mmap setup: %d buffers, %d bytes each\n", i, bsize);
 
        return i;
 }
+EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
 
 int videobuf_mmap_setup(struct videobuf_queue *q,
                        unsigned int bcount, unsigned int bsize,
@@ -388,6 +398,7 @@ int videobuf_mmap_setup(struct videobuf_queue *q,
        mutex_unlock(&q->vb_lock);
        return ret;
 }
+EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
 
 int videobuf_reqbufs(struct videobuf_queue *q,
                 struct v4l2_requestbuffers *req)
@@ -432,7 +443,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
        q->ops->buf_setup(q, &count, &size);
        dprintk(1, "reqbufs: bufs=%d, size=0x%x [%u pages total]\n",
                count, size,
-               (unsigned int)((count*PAGE_ALIGN(size))>>PAGE_SHIFT) );
+               (unsigned int)((count * PAGE_ALIGN(size)) >> PAGE_SHIFT));
 
        retval = __videobuf_mmap_setup(q, count, size, req->memory);
        if (retval < 0) {
@@ -447,6 +458,7 @@ int videobuf_reqbufs(struct videobuf_queue *q,
        mutex_unlock(&q->vb_lock);
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_reqbufs);
 
 int videobuf_querybuf(struct videobuf_queue *q, struct v4l2_buffer *b)
 {
@@ -473,9 +485,9 @@ done:
        mutex_unlock(&q->vb_lock);
        return ret;
 }
+EXPORT_SYMBOL_GPL(videobuf_querybuf);
 
-int videobuf_qbuf(struct videobuf_queue *q,
-             struct v4l2_buffer *b)
+int videobuf_qbuf(struct videobuf_queue *q, struct v4l2_buffer *b)
 {
        struct videobuf_buffer *buf;
        enum v4l2_field field;
@@ -534,6 +546,13 @@ int videobuf_qbuf(struct videobuf_queue *q,
                                   "but buffer addr is zero!\n");
                        goto done;
                }
+               if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT
+                   || q->type == V4L2_BUF_TYPE_VBI_OUTPUT
+                   || q->type == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT) {
+                       buf->size = b->bytesused;
+                       buf->field = b->field;
+                       buf->ts = b->timestamp;
+               }
                break;
        case V4L2_MEMORY_USERPTR:
                if (b->length < buf->bsize) {
@@ -567,11 +586,11 @@ int videobuf_qbuf(struct videobuf_queue *q,
                q->ops->buf_queue(q, buf);
                spin_unlock_irqrestore(q->irqlock, flags);
        }
-       dprintk(1, "qbuf: succeded\n");
+       dprintk(1, "qbuf: succeeded\n");
        retval = 0;
        wake_up_interruptible_sync(&q->wait);
 
- done:
+done:
        mutex_unlock(&q->vb_lock);
 
        if (b->memory == V4L2_MEMORY_MMAP)
@@ -579,7 +598,7 @@ int videobuf_qbuf(struct videobuf_queue *q,
 
        return retval;
 }
-
+EXPORT_SYMBOL_GPL(videobuf_qbuf);
 
 /* Locking: Caller holds q->vb_lock */
 static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
@@ -624,7 +643,6 @@ done:
        return retval;
 }
 
-
 /* Locking: Caller holds q->vb_lock */
 static int stream_next_buffer(struct videobuf_queue *q,
                        struct videobuf_buffer **vb, int nonblocking)
@@ -647,13 +665,14 @@ done:
 }
 
 int videobuf_dqbuf(struct videobuf_queue *q,
-              struct v4l2_buffer *b, int nonblocking)
+                  struct v4l2_buffer *b, int nonblocking)
 {
        struct videobuf_buffer *buf = NULL;
        int retval;
 
        MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
 
+       memset(b, 0, sizeof(*b));
        mutex_lock(&q->vb_lock);
 
        retval = stream_next_buffer(q, &buf, nonblocking);
@@ -665,28 +684,25 @@ int videobuf_dqbuf(struct videobuf_queue *q,
        switch (buf->state) {
        case VIDEOBUF_ERROR:
                dprintk(1, "dqbuf: state is error\n");
-               retval = -EIO;
-               CALL(q, sync, q, buf);
-               buf->state = VIDEOBUF_IDLE;
                break;
        case VIDEOBUF_DONE:
                dprintk(1, "dqbuf: state is done\n");
-               CALL(q, sync, q, buf);
-               buf->state = VIDEOBUF_IDLE;
                break;
        default:
                dprintk(1, "dqbuf: state invalid\n");
                retval = -EINVAL;
                goto done;
        }
-       list_del(&buf->stream);
-       memset(b, 0, sizeof(*b));
+       CALL(q, sync, q, buf);
        videobuf_status(q, b, buf, q->type);
-
- done:
+       list_del(&buf->stream);
+       buf->state = VIDEOBUF_IDLE;
+       b->flags &= ~V4L2_BUF_FLAG_DONE;
+done:
        mutex_unlock(&q->vb_lock);
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_dqbuf);
 
 int videobuf_streamon(struct videobuf_queue *q)
 {
@@ -709,10 +725,11 @@ int videobuf_streamon(struct videobuf_queue *q)
        spin_unlock_irqrestore(q->irqlock, flags);
 
        wake_up_interruptible_sync(&q->wait);
- done:
+done:
        mutex_unlock(&q->vb_lock);
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_streamon);
 
 /* Locking: Caller holds q->vb_lock */
 static int __videobuf_streamoff(struct videobuf_queue *q)
@@ -735,6 +752,7 @@ int videobuf_streamoff(struct videobuf_queue *q)
 
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_streamoff);
 
 /* Locking: Caller holds q->vb_lock */
 static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
@@ -774,7 +792,7 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
                        retval = q->read_buf->size;
        }
 
- done:
+done:
        /* cleanup */
        q->ops->buf_release(q, q->read_buf);
        kfree(q->read_buf);
@@ -782,6 +800,49 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
        return retval;
 }
 
+static int __videobuf_copy_to_user(struct videobuf_queue *q,
+                                  struct videobuf_buffer *buf,
+                                  char __user *data, size_t count,
+                                  int nonblocking)
+{
+       void *vaddr = CALL(q, vaddr, buf);
+
+       /* copy to userspace */
+       if (count > buf->size - q->read_off)
+               count = buf->size - q->read_off;
+
+       if (copy_to_user(data, vaddr + q->read_off, count))
+               return -EFAULT;
+
+       return count;
+}
+
+static int __videobuf_copy_stream(struct videobuf_queue *q,
+                                 struct videobuf_buffer *buf,
+                                 char __user *data, size_t count, size_t pos,
+                                 int vbihack, int nonblocking)
+{
+       unsigned int *fc = CALL(q, vaddr, buf);
+
+       if (vbihack) {
+               /* dirty, undocumented hack -- pass the frame counter
+                       * within the last four bytes of each vbi data block.
+                       * We need that one to maintain backward compatibility
+                       * to all vbi decoding software out there ... */
+               fc += (buf->size >> 2) - 1;
+               *fc = buf->field_count >> 1;
+               dprintk(1, "vbihack: %d\n", *fc);
+       }
+
+       /* copy stuff using the common method */
+       count = __videobuf_copy_to_user(q, buf, data, count, nonblocking);
+
+       if ((count == -EFAULT) && (pos == 0))
+               return -EFAULT;
+
+       return count;
+}
+
 ssize_t videobuf_read_one(struct videobuf_queue *q,
                          char __user *data, size_t count, loff_t *ppos,
                          int nonblocking)
@@ -850,7 +911,7 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
        }
 
        /* Copy to userspace */
-       retval = CALL(q, video_copy_to_user, q, data, count, nonblocking);
+       retval = __videobuf_copy_to_user(q, q->read_buf, data, count, nonblocking);
        if (retval < 0)
                goto done;
 
@@ -862,10 +923,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
                q->read_buf = NULL;
        }
 
- done:
+done:
        mutex_unlock(&q->vb_lock);
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_read_one);
 
 /* Locking: Caller holds q->vb_lock */
 static int __videobuf_read_start(struct videobuf_queue *q)
@@ -917,7 +979,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
                q->bufs[i] = NULL;
        }
        q->read_buf = NULL;
-
 }
 
 int videobuf_read_start(struct videobuf_queue *q)
@@ -930,6 +991,7 @@ int videobuf_read_start(struct videobuf_queue *q)
 
        return rc;
 }
+EXPORT_SYMBOL_GPL(videobuf_read_start);
 
 void videobuf_read_stop(struct videobuf_queue *q)
 {
@@ -937,6 +999,7 @@ void videobuf_read_stop(struct videobuf_queue *q)
        __videobuf_read_stop(q);
        mutex_unlock(&q->vb_lock);
 }
+EXPORT_SYMBOL_GPL(videobuf_read_stop);
 
 void videobuf_stop(struct videobuf_queue *q)
 {
@@ -950,7 +1013,7 @@ void videobuf_stop(struct videobuf_queue *q)
 
        mutex_unlock(&q->vb_lock);
 }
-
+EXPORT_SYMBOL_GPL(videobuf_stop);
 
 ssize_t videobuf_read_stream(struct videobuf_queue *q,
                             char __user *data, size_t count, loff_t *ppos,
@@ -990,7 +1053,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
                }
 
                if (q->read_buf->state == VIDEOBUF_DONE) {
-                       rc = CALL(q, copy_stream, q, data + retval, count,
+                       rc = __videobuf_copy_stream(q, q->read_buf, data + retval, count,
                                        retval, vbihack, nonblocking);
                        if (rc < 0) {
                                retval = rc;
@@ -1019,10 +1082,11 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
                        break;
        }
 
- done:
+done:
        mutex_unlock(&q->vb_lock);
        return retval;
 }
+EXPORT_SYMBOL_GPL(videobuf_read_stream);
 
 unsigned int videobuf_poll_stream(struct file *file,
                                  struct videobuf_queue *q,
@@ -1056,27 +1120,51 @@ unsigned int videobuf_poll_stream(struct file *file,
        if (0 == rc) {
                poll_wait(file, &buf->done, wait);
                if (buf->state == VIDEOBUF_DONE ||
-                   buf->state == VIDEOBUF_ERROR)
-                       rc = POLLIN|POLLRDNORM;
+                   buf->state == VIDEOBUF_ERROR) {
+                       switch (q->type) {
+                       case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       case V4L2_BUF_TYPE_VBI_OUTPUT:
+                       case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
+                               rc = POLLOUT | POLLWRNORM;
+                               break;
+                       default:
+                               rc = POLLIN | POLLRDNORM;
+                               break;
+                       }
+               }
        }
        mutex_unlock(&q->vb_lock);
        return rc;
 }
+EXPORT_SYMBOL_GPL(videobuf_poll_stream);
 
-int videobuf_mmap_mapper(struct videobuf_queue *q,
-                        struct vm_area_struct *vma)
+int videobuf_mmap_mapper(struct videobuf_queue *q, struct vm_area_struct *vma)
 {
-       int retval;
+       int rc = -EINVAL;
+       int i;
 
        MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
 
+       if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED)) {
+               dprintk(1, "mmap appl bug: PROT_WRITE and MAP_SHARED are required\n");
+               return -EINVAL;
+       }
+
        mutex_lock(&q->vb_lock);
-       retval = CALL(q, mmap_mapper, q, vma);
-       q->is_mmapped = 1;
+       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+               struct videobuf_buffer *buf = q->bufs[i];
+
+               if (buf && buf->memory == V4L2_MEMORY_MMAP &&
+                               buf->boff == (vma->vm_pgoff << PAGE_SHIFT)) {
+                       rc = CALL(q, mmap_mapper, q, buf, vma);
+                       break;
+               }
+       }
        mutex_unlock(&q->vb_lock);
 
-       return retval;
+       return rc;
 }
+EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 int videobuf_cgmbuf(struct videobuf_queue *q,
@@ -1107,33 +1195,3 @@ int videobuf_cgmbuf(struct videobuf_queue *q,
 EXPORT_SYMBOL_GPL(videobuf_cgmbuf);
 #endif
 
-/* --------------------------------------------------------------------- */
-
-EXPORT_SYMBOL_GPL(videobuf_waiton);
-EXPORT_SYMBOL_GPL(videobuf_iolock);
-
-EXPORT_SYMBOL_GPL(videobuf_alloc);
-
-EXPORT_SYMBOL_GPL(videobuf_queue_core_init);
-EXPORT_SYMBOL_GPL(videobuf_queue_cancel);
-EXPORT_SYMBOL_GPL(videobuf_queue_is_busy);
-
-EXPORT_SYMBOL_GPL(videobuf_next_field);
-EXPORT_SYMBOL_GPL(videobuf_reqbufs);
-EXPORT_SYMBOL_GPL(videobuf_querybuf);
-EXPORT_SYMBOL_GPL(videobuf_qbuf);
-EXPORT_SYMBOL_GPL(videobuf_dqbuf);
-EXPORT_SYMBOL_GPL(videobuf_streamon);
-EXPORT_SYMBOL_GPL(videobuf_streamoff);
-
-EXPORT_SYMBOL_GPL(videobuf_read_start);
-EXPORT_SYMBOL_GPL(videobuf_read_stop);
-EXPORT_SYMBOL_GPL(videobuf_stop);
-EXPORT_SYMBOL_GPL(videobuf_read_stream);
-EXPORT_SYMBOL_GPL(videobuf_read_one);
-EXPORT_SYMBOL_GPL(videobuf_poll_stream);
-
-EXPORT_SYMBOL_GPL(__videobuf_mmap_setup);
-EXPORT_SYMBOL_GPL(videobuf_mmap_setup);
-EXPORT_SYMBOL_GPL(videobuf_mmap_free);
-EXPORT_SYMBOL_GPL(videobuf_mmap_mapper);
index dce4f3a..74730c6 100644 (file)
@@ -55,14 +55,14 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
        struct videobuf_queue *q = map->q;
        int i;
 
-       dev_dbg(map->q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
+       dev_dbg(q->dev, "vm_close %p [count=%u,vma=%08lx-%08lx]\n",
                map, map->count, vma->vm_start, vma->vm_end);
 
        map->count--;
        if (0 == map->count) {
                struct videobuf_dma_contig_memory *mem;
 
-               dev_dbg(map->q->dev, "munmap %p q=%p\n", map, q);
+               dev_dbg(q->dev, "munmap %p q=%p\n", map, q);
                mutex_lock(&q->vb_lock);
 
                /* We need first to cancel streams, before unmapping */
@@ -89,7 +89,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
                                /* vfree is not atomic - can't be
                                   called with IRQ's disabled
                                 */
-                               dev_dbg(map->q->dev, "buf[%d] freeing %p\n",
+                               dev_dbg(q->dev, "buf[%d] freeing %p\n",
                                        i, mem->vaddr);
 
                                dma_free_coherent(q->dev, mem->size,
@@ -190,7 +190,7 @@ static int videobuf_dma_contig_user_get(struct videobuf_dma_contig_memory *mem,
        return ret;
 }
 
-static void *__videobuf_alloc(size_t size)
+static struct videobuf_buffer *__videobuf_alloc(size_t size)
 {
        struct videobuf_dma_contig_memory *mem;
        struct videobuf_buffer *vb;
@@ -204,7 +204,7 @@ static void *__videobuf_alloc(size_t size)
        return vb;
 }
 
-static void *__videobuf_to_vmalloc(struct videobuf_buffer *buf)
+static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
 {
        struct videobuf_dma_contig_memory *mem = buf->priv;
 
@@ -263,65 +263,34 @@ static int __videobuf_iolock(struct videobuf_queue *q,
        return 0;
 }
 
-static int __videobuf_mmap_free(struct videobuf_queue *q)
-{
-       unsigned int i;
-
-       dev_dbg(q->dev, "%s\n", __func__);
-       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
-               if (q->bufs[i] && q->bufs[i]->map)
-                       return -EBUSY;
-       }
-
-       return 0;
-}
-
 static int __videobuf_mmap_mapper(struct videobuf_queue *q,
+                                 struct videobuf_buffer *buf,
                                  struct vm_area_struct *vma)
 {
        struct videobuf_dma_contig_memory *mem;
        struct videobuf_mapping *map;
-       unsigned int first;
        int retval;
-       unsigned long size, offset = vma->vm_pgoff << PAGE_SHIFT;
+       unsigned long size;
 
        dev_dbg(q->dev, "%s\n", __func__);
-       if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
-               return -EINVAL;
-
-       /* look for first buffer to map */
-       for (first = 0; first < VIDEO_MAX_FRAME; first++) {
-               if (!q->bufs[first])
-                       continue;
-
-               if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
-                       continue;
-               if (q->bufs[first]->boff == offset)
-                       break;
-       }
-       if (VIDEO_MAX_FRAME == first) {
-               dev_dbg(q->dev, "invalid user space offset [offset=0x%lx]\n",
-                       offset);
-               return -EINVAL;
-       }
 
        /* create mapping + update buffer list */
        map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
        if (!map)
                return -ENOMEM;
 
-       q->bufs[first]->map = map;
+       buf->map = map;
        map->start = vma->vm_start;
        map->end = vma->vm_end;
        map->q = q;
 
-       q->bufs[first]->baddr = vma->vm_start;
+       buf->baddr = vma->vm_start;
 
-       mem = q->bufs[first]->priv;
+       mem = buf->priv;
        BUG_ON(!mem);
        MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
 
-       mem->size = PAGE_ALIGN(q->bufs[first]->bsize);
+       mem->size = PAGE_ALIGN(buf->bsize);
        mem->vaddr = dma_alloc_coherent(q->dev, mem->size,
                                        &mem->dma_handle, GFP_KERNEL);
        if (!mem->vaddr) {
@@ -354,8 +323,8 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
 
        dev_dbg(q->dev, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
                map, q, vma->vm_start, vma->vm_end,
-               (long int) q->bufs[first]->bsize,
-               vma->vm_pgoff, first);
+               (long int)buf->bsize,
+               vma->vm_pgoff, buf->i);
 
        videobuf_vm_open(vma);
 
@@ -366,69 +335,13 @@ error:
        return -ENOMEM;
 }
 
-static int __videobuf_copy_to_user(struct videobuf_queue *q,
-                                  char __user *data, size_t count,
-                                  int nonblocking)
-{
-       struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
-       void *vaddr;
-
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
-       BUG_ON(!mem->vaddr);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       vaddr = mem->vaddr;
-
-       if (copy_to_user(data, vaddr + q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream(struct videobuf_queue *q,
-                                 char __user *data, size_t count, size_t pos,
-                                 int vbihack, int nonblocking)
-{
-       unsigned int  *fc;
-       struct videobuf_dma_contig_memory *mem = q->read_buf->priv;
-
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic, MAGIC_DC_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                       * within the last four bytes of each vbi data block.
-                       * We need that one to maintain backward compatibility
-                       * to all vbi decoding software out there ... */
-               fc = (unsigned int *)mem->vaddr;
-               fc += (q->read_buf->size >> 2) - 1;
-               *fc = q->read_buf->field_count >> 1;
-               dev_dbg(q->dev, "vbihack: %d\n", *fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user(q, data, count, nonblocking);
-
-       if ((count == -EFAULT) && (pos == 0))
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops qops = {
        .magic        = MAGIC_QTYPE_OPS,
 
        .alloc        = __videobuf_alloc,
        .iolock       = __videobuf_iolock,
-       .mmap_free    = __videobuf_mmap_free,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
-       .vmalloc      = __videobuf_to_vmalloc,
+       .vaddr        = __videobuf_to_vaddr,
 };
 
 void videobuf_queue_dma_contig_init(struct videobuf_queue *q,
index fcd045e..8359e6b 100644 (file)
 #define MAGIC_DMABUF 0x19721112
 #define MAGIC_SG_MEM 0x17890714
 
-#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
-       { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
+#define MAGIC_CHECK(is, should)                                                \
+       if (unlikely((is) != (should))) {                               \
+               printk(KERN_ERR "magic mismatch: %x (expected %x)\n",   \
+                               is, should);                            \
+               BUG();                                                  \
+       }
 
 static int debug;
 module_param(debug, int, 0644);
@@ -47,13 +51,13 @@ MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
 MODULE_LICENSE("GPL");
 
-#define dprintk(level, fmt, arg...)    if (debug >= level) \
-       printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
+#define dprintk(level, fmt, arg...)                                    \
+       if (debug >= level)                                             \
+               printk(KERN_DEBUG "vbuf-sg: " fmt , ## arg)
 
 /* --------------------------------------------------------------------- */
 
-struct scatterlist*
-videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
+struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
 {
        struct scatterlist *sglist;
        struct page *pg;
@@ -73,13 +77,14 @@ videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages)
        }
        return sglist;
 
- err:
+err:
        vfree(sglist);
        return NULL;
 }
+EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
 
-struct scatterlist*
-videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
+struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
+                                        int offset)
 {
        struct scatterlist *sglist;
        int i;
@@ -104,20 +109,20 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
        }
        return sglist;
 
- nopage:
-       dprintk(2,"sgl: oops - no page\n");
+nopage:
+       dprintk(2, "sgl: oops - no page\n");
        vfree(sglist);
        return NULL;
 
- highmem:
-       dprintk(2,"sgl: oops - highmem page\n");
+highmem:
+       dprintk(2, "sgl: oops - highmem page\n");
        vfree(sglist);
        return NULL;
 }
 
 /* --------------------------------------------------------------------- */
 
-struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
+struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
 {
        struct videobuf_dma_sg_memory *mem = buf->priv;
        BUG_ON(!mem);
@@ -126,17 +131,19 @@ struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
 
        return &mem->dma;
 }
+EXPORT_SYMBOL_GPL(videobuf_to_dma);
 
 void videobuf_dma_init(struct videobuf_dmabuf *dma)
 {
-       memset(dma,0,sizeof(*dma));
+       memset(dma, 0, sizeof(*dma));
        dma->magic = MAGIC_DMABUF;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_init);
 
 static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
                        int direction, unsigned long data, unsigned long size)
 {
-       unsigned long first,last;
+       unsigned long first, last;
        int err, rw = 0;
 
        dma->direction = direction;
@@ -155,21 +162,21 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
        last  = ((data+size-1) & PAGE_MASK) >> PAGE_SHIFT;
        dma->offset   = data & ~PAGE_MASK;
        dma->nr_pages = last-first+1;
-       dma->pages = kmalloc(dma->nr_pages * sizeof(struct page*),
-                            GFP_KERNEL);
+       dma->pages = kmalloc(dma->nr_pages * sizeof(struct page *), GFP_KERNEL);
        if (NULL == dma->pages)
                return -ENOMEM;
-       dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
-               data,size,dma->nr_pages);
 
-       err = get_user_pages(current,current->mm,
+       dprintk(1, "init user [0x%lx+0x%lx => %d pages]\n",
+               data, size, dma->nr_pages);
+
+       err = get_user_pages(current, current->mm,
                             data & PAGE_MASK, dma->nr_pages,
                             rw == READ, 1, /* force */
                             dma->pages, NULL);
 
        if (err != dma->nr_pages) {
                dma->nr_pages = (err >= 0) ? err : 0;
-               dprintk(1,"get_user_pages: err=%d [%d]\n",err,dma->nr_pages);
+               dprintk(1, "get_user_pages: err=%d [%d]\n", err, dma->nr_pages);
                return err < 0 ? err : -EINVAL;
        }
        return 0;
@@ -179,48 +186,58 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
                           unsigned long data, unsigned long size)
 {
        int ret;
+
        down_read(&current->mm->mmap_sem);
        ret = videobuf_dma_init_user_locked(dma, direction, data, size);
        up_read(&current->mm->mmap_sem);
 
        return ret;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
 
 int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
                             int nr_pages)
 {
-       dprintk(1,"init kernel [%d pages]\n",nr_pages);
+       dprintk(1, "init kernel [%d pages]\n", nr_pages);
+
        dma->direction = direction;
        dma->vmalloc = vmalloc_32(nr_pages << PAGE_SHIFT);
        if (NULL == dma->vmalloc) {
-               dprintk(1,"vmalloc_32(%d pages) failed\n",nr_pages);
+               dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
                return -ENOMEM;
        }
-       dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n",
+
+       dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
                                (unsigned long)dma->vmalloc,
                                nr_pages << PAGE_SHIFT);
-       memset(dma->vmalloc,0,nr_pages << PAGE_SHIFT);
+
+       memset(dma->vmalloc, 0, nr_pages << PAGE_SHIFT);
        dma->nr_pages = nr_pages;
+
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
 
 int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
                              dma_addr_t addr, int nr_pages)
 {
-       dprintk(1,"init overlay [%d pages @ bus 0x%lx]\n",
-               nr_pages,(unsigned long)addr);
+       dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
+               nr_pages, (unsigned long)addr);
        dma->direction = direction;
+
        if (0 == addr)
                return -EINVAL;
 
        dma->bus_addr = addr;
        dma->nr_pages = nr_pages;
+
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
 
-int videobuf_dma_map(struct videobuf_queueq, struct videobuf_dmabuf *dma)
+int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
 {
-       MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
+       MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
        BUG_ON(0 == dma->nr_pages);
 
        if (dma->pages) {
@@ -228,20 +245,21 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
                                                   dma->offset);
        }
        if (dma->vmalloc) {
-               dma->sglist = videobuf_vmalloc_to_sg
-                                               (dma->vmalloc,dma->nr_pages);
+               dma->sglist = videobuf_vmalloc_to_sg(dma->vmalloc,
+                                                    dma->nr_pages);
        }
        if (dma->bus_addr) {
                dma->sglist = vmalloc(sizeof(*dma->sglist));
                if (NULL != dma->sglist) {
-                       dma->sglen  = 1;
-                       sg_dma_address(&dma->sglist[0]) = dma->bus_addr & PAGE_MASK;
-                       dma->sglist[0].offset           = dma->bus_addr & ~PAGE_MASK;
-                       sg_dma_len(&dma->sglist[0])     = dma->nr_pages * PAGE_SIZE;
+                       dma->sglen = 1;
+                       sg_dma_address(&dma->sglist[0]) = dma->bus_addr
+                                                       & PAGE_MASK;
+                       dma->sglist[0].offset = dma->bus_addr & ~PAGE_MASK;
+                       sg_dma_len(&dma->sglist[0]) = dma->nr_pages * PAGE_SIZE;
                }
        }
        if (NULL == dma->sglist) {
-               dprintk(1,"scatterlist is NULL\n");
+               dprintk(1, "scatterlist is NULL\n");
                return -ENOMEM;
        }
        if (!dma->bus_addr) {
@@ -249,47 +267,43 @@ int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
                                        dma->nr_pages, dma->direction);
                if (0 == dma->sglen) {
                        printk(KERN_WARNING
-                              "%s: videobuf_map_sg failed\n",__func__);
+                              "%s: videobuf_map_sg failed\n", __func__);
                        vfree(dma->sglist);
                        dma->sglist = NULL;
                        dma->sglen = 0;
                        return -ENOMEM;
                }
        }
-       return 0;
-}
-
-int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
-{
-       MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
-       BUG_ON(!dma->sglen);
 
-       dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_map);
 
-int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
+int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
 {
        MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
+
        if (!dma->sglen)
                return 0;
 
-       dma_unmap_sg(q->dev, dma->sglist, dma->nr_pages, dma->direction);
+       dma_unmap_sg(q->dev, dma->sglist, dma->sglen, dma->direction);
 
        vfree(dma->sglist);
        dma->sglist = NULL;
        dma->sglen = 0;
+
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
 
 int videobuf_dma_free(struct videobuf_dmabuf *dma)
 {
-       MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
+       int i;
+       MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
        BUG_ON(dma->sglen);
 
        if (dma->pages) {
-               int i;
-               for (i=0; i < dma->nr_pages; i++)
+               for (i = 0; i < dma->nr_pages; i++)
                        page_cache_release(dma->pages[i]);
                kfree(dma->pages);
                dma->pages = NULL;
@@ -298,12 +312,13 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
        vfree(dma->vmalloc);
        dma->vmalloc = NULL;
 
-       if (dma->bus_addr) {
+       if (dma->bus_addr)
                dma->bus_addr = 0;
-       }
        dma->direction = DMA_NONE;
+
        return 0;
 }
+EXPORT_SYMBOL_GPL(videobuf_dma_free);
 
 /* --------------------------------------------------------------------- */
 
@@ -315,6 +330,7 @@ int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
 
        return videobuf_dma_map(&q, dma);
 }
+EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
 
 int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
 {
@@ -324,49 +340,48 @@ int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
 
        return videobuf_dma_unmap(&q, dma);
 }
+EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
 
 /* --------------------------------------------------------------------- */
 
-static void
-videobuf_vm_open(struct vm_area_struct *vma)
+static void videobuf_vm_open(struct vm_area_struct *vma)
 {
        struct videobuf_mapping *map = vma->vm_private_data;
 
-       dprintk(2,"vm_open %p [count=%d,vma=%08lx-%08lx]\n",map,
-               map->count,vma->vm_start,vma->vm_end);
+       dprintk(2, "vm_open %p [count=%d,vma=%08lx-%08lx]\n", map,
+               map->count, vma->vm_start, vma->vm_end);
+
        map->count++;
 }
 
-static void
-videobuf_vm_close(struct vm_area_struct *vma)
+static void videobuf_vm_close(struct vm_area_struct *vma)
 {
        struct videobuf_mapping *map = vma->vm_private_data;
        struct videobuf_queue *q = map->q;
        struct videobuf_dma_sg_memory *mem;
        int i;
 
-       dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
-               map->count,vma->vm_start,vma->vm_end);
+       dprintk(2, "vm_close %p [count=%d,vma=%08lx-%08lx]\n", map,
+               map->count, vma->vm_start, vma->vm_end);
 
        map->count--;
        if (0 == map->count) {
-               dprintk(1,"munmap %p q=%p\n",map,q);
+               dprintk(1, "munmap %p q=%p\n", map, q);
                mutex_lock(&q->vb_lock);
                for (i = 0; i < VIDEO_MAX_FRAME; i++) {
                        if (NULL == q->bufs[i])
                                continue;
-                       mem=q->bufs[i]->priv;
-
+                       mem = q->bufs[i]->priv;
                        if (!mem)
                                continue;
 
-                       MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
+                       MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
 
                        if (q->bufs[i]->map != map)
                                continue;
                        q->bufs[i]->map   = NULL;
                        q->bufs[i]->baddr = 0;
-                       q->ops->buf_release(q,q->bufs[i]);
+                       q->ops->buf_release(q, q->bufs[i]);
                }
                mutex_unlock(&q->vb_lock);
                kfree(map);
@@ -380,26 +395,27 @@ videobuf_vm_close(struct vm_area_struct *vma)
  * now ...).  Bounce buffers don't work very well for the data rates
  * video capture has.
  */
-static int
-videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
+static int videobuf_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        struct page *page;
 
-       dprintk(3,"fault: fault @ %08lx [vma %08lx-%08lx]\n",
-               (unsigned long)vmf->virtual_address,vma->vm_start,vma->vm_end);
+       dprintk(3, "fault: fault @ %08lx [vma %08lx-%08lx]\n",
+               (unsigned long)vmf->virtual_address,
+               vma->vm_start, vma->vm_end);
+
        page = alloc_page(GFP_USER | __GFP_DMA32);
        if (!page)
                return VM_FAULT_OOM;
        clear_user_highpage(page, (unsigned long)vmf->virtual_address);
        vmf->page = page;
+
        return 0;
 }
 
-static const struct vm_operations_struct videobuf_vm_ops =
-{
-       .open     = videobuf_vm_open,
-       .close    = videobuf_vm_close,
-       .fault    = videobuf_vm_fault,
+static const struct vm_operations_struct videobuf_vm_ops = {
+       .open   = videobuf_vm_open,
+       .close  = videobuf_vm_close,
+       .fault  = videobuf_vm_fault,
 };
 
 /* ---------------------------------------------------------------------
@@ -412,28 +428,28 @@ static const struct vm_operations_struct videobuf_vm_ops =
        struct videobuf_dma_sg_memory
  */
 
-static void *__videobuf_alloc(size_t size)
+static struct videobuf_buffer *__videobuf_alloc(size_t size)
 {
        struct videobuf_dma_sg_memory *mem;
        struct videobuf_buffer *vb;
 
-       vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
+       vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
        if (!vb)
                return vb;
 
-       mem = vb->priv = ((char *)vb)+size;
-       mem->magic=MAGIC_SG_MEM;
+       mem = vb->priv = ((char *)vb) + size;
+       mem->magic = MAGIC_SG_MEM;
 
        videobuf_dma_init(&mem->dma);
 
-       dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
-               __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
-               mem,(long)sizeof(*mem));
+       dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
+               __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
+               mem, (long)sizeof(*mem));
 
        return vb;
 }
 
-static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf)
+static void *__videobuf_to_vaddr(struct videobuf_buffer *buf)
 {
        struct videobuf_dma_sg_memory *mem = buf->priv;
        BUG_ON(!mem);
@@ -443,11 +459,11 @@ static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf)
        return mem->dma.vmalloc;
 }
 
-static int __videobuf_iolock (struct videobuf_queue* q,
-                             struct videobuf_buffer *vb,
-                             struct v4l2_framebuffer *fbuf)
+static int __videobuf_iolock(struct videobuf_queue *q,
+                            struct videobuf_buffer *vb,
+                            struct v4l2_framebuffer *fbuf)
 {
-       int err,pages;
+       int err, pages;
        dma_addr_t bus;
        struct videobuf_dma_sg_memory *mem = vb->priv;
        BUG_ON(!mem);
@@ -460,16 +476,16 @@ static int __videobuf_iolock (struct videobuf_queue* q,
                if (0 == vb->baddr) {
                        /* no userspace addr -- kernel bounce buffer */
                        pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
-                       err = videobuf_dma_init_kernel( &mem->dma,
-                                                       DMA_FROM_DEVICE,
-                                                       pages );
+                       err = videobuf_dma_init_kernel(&mem->dma,
+                                                      DMA_FROM_DEVICE,
+                                                      pages);
                        if (0 != err)
                                return err;
                } else if (vb->memory == V4L2_MEMORY_USERPTR) {
                        /* dma directly to userspace */
-                       err = videobuf_dma_init_user( &mem->dma,
-                                                     DMA_FROM_DEVICE,
-                                                     vb->baddr,vb->bsize );
+                       err = videobuf_dma_init_user(&mem->dma,
+                                                    DMA_FROM_DEVICE,
+                                                    vb->baddr, vb->bsize);
                        if (0 != err)
                                return err;
                } else {
@@ -515,43 +531,27 @@ static int __videobuf_sync(struct videobuf_queue *q,
                           struct videobuf_buffer *buf)
 {
        struct videobuf_dma_sg_memory *mem = buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
+       BUG_ON(!mem || !mem->dma.sglen);
 
-       return  videobuf_dma_sync(q,&mem->dma);
-}
-
-static int __videobuf_mmap_free(struct videobuf_queue *q)
-{
-       int i;
+       MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
+       MAGIC_CHECK(mem->dma.magic, MAGIC_DMABUF);
 
-       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
-               if (q->bufs[i]) {
-                       if (q->bufs[i]->map)
-                               return -EBUSY;
-               }
-       }
+       dma_sync_sg_for_cpu(q->dev, mem->dma.sglist,
+                           mem->dma.sglen, mem->dma.direction);
 
        return 0;
 }
 
 static int __videobuf_mmap_mapper(struct videobuf_queue *q,
-                        struct vm_area_struct *vma)
+                                 struct videobuf_buffer *buf,
+                                 struct vm_area_struct *vma)
 {
-       struct videobuf_dma_sg_memory *mem;
+       struct videobuf_dma_sg_memory *mem = buf->priv;
        struct videobuf_mapping *map;
-       unsigned int first,last,size,i;
+       unsigned int first, last, size = 0, i;
        int retval;
 
        retval = -EINVAL;
-       if (!(vma->vm_flags & VM_WRITE)) {
-               dprintk(1,"mmap app bug: PROT_WRITE please\n");
-               goto done;
-       }
-       if (!(vma->vm_flags & VM_SHARED)) {
-               dprintk(1,"mmap app bug: MAP_SHARED please\n");
-               goto done;
-       }
 
        /* This function maintains backwards compatibility with V4L1 and will
         * map more than one buffer if the vma length is equal to the combined
@@ -561,48 +561,52 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
         * TODO: Allow drivers to specify if they support this mode
         */
 
+       BUG_ON(!mem);
+       MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
+
        /* look for first buffer to map */
        for (first = 0; first < VIDEO_MAX_FRAME; first++) {
-               if (NULL == q->bufs[first])
-                       continue;
-               mem=q->bufs[first]->priv;
-               BUG_ON(!mem);
-               MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
-
-               if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
-                       continue;
-               if (q->bufs[first]->boff == (vma->vm_pgoff << PAGE_SHIFT))
+               if (buf == q->bufs[first]) {
+                       size = PAGE_ALIGN(q->bufs[first]->bsize);
                        break;
+               }
        }
-       if (VIDEO_MAX_FRAME == first) {
-               dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
-                       (vma->vm_pgoff << PAGE_SHIFT));
+
+       /* paranoia, should never happen since buf is always valid. */
+       if (!size) {
+               dprintk(1, "mmap app bug: offset invalid [offset=0x%lx]\n",
+                               (vma->vm_pgoff << PAGE_SHIFT));
                goto done;
        }
 
-       /* look for last buffer to map */
-       for (size = 0, last = first; last < VIDEO_MAX_FRAME; last++) {
-               if (NULL == q->bufs[last])
-                       continue;
-               if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
-                       continue;
-               if (q->bufs[last]->map) {
-                       retval = -EBUSY;
+       last = first;
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       if (size != (vma->vm_end - vma->vm_start)) {
+               /* look for last buffer to map */
+               for (last = first + 1; last < VIDEO_MAX_FRAME; last++) {
+                       if (NULL == q->bufs[last])
+                               continue;
+                       if (V4L2_MEMORY_MMAP != q->bufs[last]->memory)
+                               continue;
+                       if (q->bufs[last]->map) {
+                               retval = -EBUSY;
+                               goto done;
+                       }
+                       size += PAGE_ALIGN(q->bufs[last]->bsize);
+                       if (size == (vma->vm_end - vma->vm_start))
+                               break;
+               }
+               if (VIDEO_MAX_FRAME == last) {
+                       dprintk(1, "mmap app bug: size invalid [size=0x%lx]\n",
+                                       (vma->vm_end - vma->vm_start));
                        goto done;
                }
-               size += PAGE_ALIGN(q->bufs[last]->bsize);
-               if (size == (vma->vm_end - vma->vm_start))
-                       break;
-       }
-       if (VIDEO_MAX_FRAME == last) {
-               dprintk(1,"mmap app bug: size invalid [size=0x%lx]\n",
-                       (vma->vm_end - vma->vm_start));
-               goto done;
        }
+#endif
 
        /* create mapping + update buffer list */
        retval = -ENOMEM;
-       map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
+       map = kmalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
        if (NULL == map)
                goto done;
 
@@ -623,72 +627,22 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
        vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
        vma->vm_flags &= ~VM_IO; /* using shared anonymous pages */
        vma->vm_private_data = map;
-       dprintk(1,"mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
-               map,q,vma->vm_start,vma->vm_end,vma->vm_pgoff,first,last);
+       dprintk(1, "mmap %p: q=%p %08lx-%08lx pgoff %08lx bufs %d-%d\n",
+               map, q, vma->vm_start, vma->vm_end, vma->vm_pgoff, first, last);
        retval = 0;
 
- done:
+done:
        return retval;
 }
 
-static int __videobuf_copy_to_user ( struct videobuf_queue *q,
-                               char __user *data, size_t count,
-                               int nonblocking )
-{
-       struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       if (copy_to_user(data, mem->dma.vmalloc+q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream ( struct videobuf_queue *q,
-                               char __user *data, size_t count, size_t pos,
-                               int vbihack, int nonblocking )
-{
-       unsigned int  *fc;
-       struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
-       BUG_ON(!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                       * within the last four bytes of each vbi data block.
-                       * We need that one to maintain backward compatibility
-                       * to all vbi decoding software out there ... */
-               fc  = (unsigned int*)mem->dma.vmalloc;
-               fc += (q->read_buf->size>>2) -1;
-               *fc = q->read_buf->field_count >> 1;
-               dprintk(1,"vbihack: %d\n",*fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user (q,data,count,nonblocking);
-
-       if ( (count==-EFAULT) && (0 == pos) )
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops sg_ops = {
        .magic        = MAGIC_QTYPE_OPS,
 
        .alloc        = __videobuf_alloc,
        .iolock       = __videobuf_iolock,
        .sync         = __videobuf_sync,
-       .mmap_free    = __videobuf_mmap_free,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
-       .vmalloc      = __videobuf_to_vmalloc,
+       .vaddr        = __videobuf_to_vaddr,
 };
 
 void *videobuf_sg_alloc(size_t size)
@@ -702,8 +656,9 @@ void *videobuf_sg_alloc(size_t size)
 
        return videobuf_alloc(&q);
 }
+EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
 
-void videobuf_queue_sg_init(struct videobuf_queueq,
+void videobuf_queue_sg_init(struct videobuf_queue *q,
                         const struct videobuf_queue_ops *ops,
                         struct device *dev,
                         spinlock_t *irqlock,
@@ -715,29 +670,5 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
        videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
                                 priv, &sg_ops);
 }
-
-/* --------------------------------------------------------------------- */
-
-EXPORT_SYMBOL_GPL(videobuf_vmalloc_to_sg);
-
-EXPORT_SYMBOL_GPL(videobuf_to_dma);
-EXPORT_SYMBOL_GPL(videobuf_dma_init);
-EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
-EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
-EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
-EXPORT_SYMBOL_GPL(videobuf_dma_map);
-EXPORT_SYMBOL_GPL(videobuf_dma_sync);
-EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
-EXPORT_SYMBOL_GPL(videobuf_dma_free);
-
-EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
-EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
-EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
-
 EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
 
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
index 0afb62e..3f76398 100644 (file)
@@ -67,7 +67,7 @@ static int videobuf_dvb_thread(void *data)
                try_to_freeze();
 
                /* feed buffer data to demux */
-               outp = videobuf_queue_to_vmalloc (&dvb->dvbq, buf);
+               outp = videobuf_queue_to_vaddr(&dvb->dvbq, buf);
 
                if (buf->state == VIDEOBUF_DONE)
                        dvb_dmx_swfilter(&dvb->demux, outp,
index 136e093..583728f 100644 (file)
 #define MAGIC_DMABUF   0x17760309
 #define MAGIC_VMAL_MEM 0x18221223
 
-#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
-       { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
+#define MAGIC_CHECK(is, should)                                                \
+       if (unlikely((is) != (should))) {                               \
+               printk(KERN_ERR "magic mismatch: %x (expected %x)\n",   \
+                               is, should);                            \
+               BUG();                                                  \
+       }
 
 static int debug;
 module_param(debug, int, 0644);
@@ -40,19 +44,19 @@ MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers");
 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
 MODULE_LICENSE("GPL");
 
-#define dprintk(level, fmt, arg...)    if (debug >= level) \
-       printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
+#define dprintk(level, fmt, arg...)                                    \
+       if (debug >= level)                                             \
+               printk(KERN_DEBUG "vbuf-vmalloc: " fmt , ## arg)
 
 
 /***************************************************************************/
 
-static void
-videobuf_vm_open(struct vm_area_struct *vma)
+static void videobuf_vm_open(struct vm_area_struct *vma)
 {
        struct videobuf_mapping *map = vma->vm_private_data;
 
-       dprintk(2,"vm_open %p [count=%u,vma=%08lx-%08lx]\n",map,
-               map->count,vma->vm_start,vma->vm_end);
+       dprintk(2, "vm_open %p [count=%u,vma=%08lx-%08lx]\n", map,
+               map->count, vma->vm_start, vma->vm_end);
 
        map->count++;
 }
@@ -63,7 +67,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
        struct videobuf_queue *q = map->q;
        int i;
 
-       dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
+       dprintk(2, "vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
                map->count, vma->vm_start, vma->vm_end);
 
        map->count--;
@@ -116,8 +120,7 @@ static void videobuf_vm_close(struct vm_area_struct *vma)
        return;
 }
 
-static const struct vm_operations_struct videobuf_vm_ops =
-{
+static const struct vm_operations_struct videobuf_vm_ops = {
        .open     = videobuf_vm_open,
        .close    = videobuf_vm_close,
 };
@@ -132,28 +135,28 @@ static const struct vm_operations_struct videobuf_vm_ops =
        struct videobuf_dma_sg_memory
  */
 
-static void *__videobuf_alloc(size_t size)
+static struct videobuf_buffer *__videobuf_alloc(size_t size)
 {
        struct videobuf_vmalloc_memory *mem;
        struct videobuf_buffer *vb;
 
-       vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
+       vb = kzalloc(size + sizeof(*mem), GFP_KERNEL);
        if (!vb)
                return vb;
 
-       mem = vb->priv = ((char *)vb)+size;
-       mem->magic=MAGIC_VMAL_MEM;
+       mem = vb->priv = ((char *)vb) + size;
+       mem->magic = MAGIC_VMAL_MEM;
 
-       dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
-               __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
-               mem,(long)sizeof(*mem));
+       dprintk(1, "%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
+               __func__, vb, (long)sizeof(*vb), (long)size - sizeof(*vb),
+               mem, (long)sizeof(*mem));
 
        return vb;
 }
 
-static int __videobuf_iolock (struct videobuf_queue* q,
-                             struct videobuf_buffer *vb,
-                             struct v4l2_framebuffer *fbuf)
+static int __videobuf_iolock(struct videobuf_queue *q,
+                            struct videobuf_buffer *vb,
+                            struct v4l2_framebuffer *fbuf)
 {
        struct videobuf_vmalloc_memory *mem = vb->priv;
        int pages;
@@ -177,15 +180,13 @@ static int __videobuf_iolock (struct videobuf_queue* q,
 
                dprintk(1, "%s memory method USERPTR\n", __func__);
 
-#if 1
                if (vb->baddr) {
                        printk(KERN_ERR "USERPTR is currently not supported\n");
                        return -EINVAL;
                }
-#endif
 
                /* The only USERPTR currently supported is the one needed for
-                  read() method.
+                * read() method.
                 */
 
                mem->vmalloc = vmalloc_user(pages);
@@ -210,7 +211,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
                /* Try to remap memory */
                rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0);
                if (rc < 0) {
-                       printk(KERN_ERR "mmap: remap failed with error %d", rc);
+                       printk(KERN_ERR "mmap: remap failed with error %d", rc);
                        return -ENOMEM;
                }
 #endif
@@ -228,69 +229,29 @@ static int __videobuf_iolock (struct videobuf_queue* q,
        return 0;
 }
 
-static int __videobuf_sync(struct videobuf_queue *q,
-                          struct videobuf_buffer *buf)
-{
-       return 0;
-}
-
-static int __videobuf_mmap_free(struct videobuf_queue *q)
-{
-       unsigned int i;
-
-       dprintk(1, "%s\n", __func__);
-       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
-               if (q->bufs[i]) {
-                       if (q->bufs[i]->map)
-                               return -EBUSY;
-               }
-       }
-
-       return 0;
-}
-
 static int __videobuf_mmap_mapper(struct videobuf_queue *q,
-                        struct vm_area_struct *vma)
+                                 struct videobuf_buffer *buf,
+                                 struct vm_area_struct *vma)
 {
        struct videobuf_vmalloc_memory *mem;
        struct videobuf_mapping *map;
-       unsigned int first;
        int retval, pages;
-       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
 
        dprintk(1, "%s\n", __func__);
-       if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
-               return -EINVAL;
-
-       /* look for first buffer to map */
-       for (first = 0; first < VIDEO_MAX_FRAME; first++) {
-               if (NULL == q->bufs[first])
-                       continue;
-
-               if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
-                       continue;
-               if (q->bufs[first]->boff == offset)
-                       break;
-       }
-       if (VIDEO_MAX_FRAME == first) {
-               dprintk(1,"mmap app bug: offset invalid [offset=0x%lx]\n",
-                       (vma->vm_pgoff << PAGE_SHIFT));
-               return -EINVAL;
-       }
 
        /* create mapping + update buffer list */
        map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
        if (NULL == map)
                return -ENOMEM;
 
-       q->bufs[first]->map = map;
+       buf->map = map;
        map->start = vma->vm_start;
        map->end   = vma->vm_end;
        map->q     = q;
 
-       q->bufs[first]->baddr = vma->vm_start;
+       buf->baddr = vma->vm_start;
 
-       mem = q->bufs[first]->priv;
+       mem = buf->priv;
        BUG_ON(!mem);
        MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
 
@@ -300,8 +261,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
                printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
                goto error;
        }
-       dprintk(1, "vmalloc is at addr %p (%d pages)\n",
-               mem->vmalloc, pages);
+       dprintk(1, "vmalloc is at addr %p (%d pages)\n", mem->vmalloc, pages);
 
        /* Try to remap memory */
        retval = remap_vmalloc_range(vma, mem->vmalloc, 0);
@@ -315,10 +275,10 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
        vma->vm_flags       |= VM_DONTEXPAND | VM_RESERVED;
        vma->vm_private_data = map;
 
-       dprintk(1,"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
+       dprintk(1, "mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
                map, q, vma->vm_start, vma->vm_end,
-               (long int) q->bufs[first]->bsize,
-               vma->vm_pgoff, first);
+               (long int)buf->bsize,
+               vma->vm_pgoff, buf->i);
 
        videobuf_vm_open(vma);
 
@@ -330,69 +290,16 @@ error:
        return -ENOMEM;
 }
 
-static int __videobuf_copy_to_user ( struct videobuf_queue *q,
-                               char __user *data, size_t count,
-                               int nonblocking )
-{
-       struct videobuf_vmalloc_memory *mem=q->read_buf->priv;
-       BUG_ON (!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
-
-       BUG_ON (!mem->vmalloc);
-
-       /* copy to userspace */
-       if (count > q->read_buf->size - q->read_off)
-               count = q->read_buf->size - q->read_off;
-
-       if (copy_to_user(data, mem->vmalloc+q->read_off, count))
-               return -EFAULT;
-
-       return count;
-}
-
-static int __videobuf_copy_stream ( struct videobuf_queue *q,
-                               char __user *data, size_t count, size_t pos,
-                               int vbihack, int nonblocking )
-{
-       unsigned int  *fc;
-       struct videobuf_vmalloc_memory *mem=q->read_buf->priv;
-       BUG_ON (!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
-
-       if (vbihack) {
-               /* dirty, undocumented hack -- pass the frame counter
-                       * within the last four bytes of each vbi data block.
-                       * We need that one to maintain backward compatibility
-                       * to all vbi decoding software out there ... */
-               fc  = (unsigned int*)mem->vmalloc;
-               fc += (q->read_buf->size>>2) -1;
-               *fc = q->read_buf->field_count >> 1;
-               dprintk(1,"vbihack: %d\n",*fc);
-       }
-
-       /* copy stuff using the common method */
-       count = __videobuf_copy_to_user (q,data,count,nonblocking);
-
-       if ( (count==-EFAULT) && (0 == pos) )
-               return -EFAULT;
-
-       return count;
-}
-
 static struct videobuf_qtype_ops qops = {
        .magic        = MAGIC_QTYPE_OPS,
 
        .alloc        = __videobuf_alloc,
        .iolock       = __videobuf_iolock,
-       .sync         = __videobuf_sync,
-       .mmap_free    = __videobuf_mmap_free,
        .mmap_mapper  = __videobuf_mmap_mapper,
-       .video_copy_to_user = __videobuf_copy_to_user,
-       .copy_stream  = __videobuf_copy_stream,
-       .vmalloc      = videobuf_to_vmalloc,
+       .vaddr        = videobuf_to_vmalloc,
 };
 
-void videobuf_queue_vmalloc_init(struct videobuf_queueq,
+void videobuf_queue_vmalloc_init(struct videobuf_queue *q,
                         const struct videobuf_queue_ops *ops,
                         struct device *dev,
                         spinlock_t *irqlock,
@@ -404,20 +311,19 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
        videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
                                 priv, &qops);
 }
-
 EXPORT_SYMBOL_GPL(videobuf_queue_vmalloc_init);
 
-void *videobuf_to_vmalloc (struct videobuf_buffer *buf)
+void *videobuf_to_vmalloc(struct videobuf_buffer *buf)
 {
-       struct videobuf_vmalloc_memory *mem=buf->priv;
-       BUG_ON (!mem);
-       MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM);
+       struct videobuf_vmalloc_memory *mem = buf->priv;
+       BUG_ON(!mem);
+       MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
 
        return mem->vmalloc;
 }
 EXPORT_SYMBOL_GPL(videobuf_to_vmalloc);
 
-void videobuf_vmalloc_free (struct videobuf_buffer *buf)
+void videobuf_vmalloc_free(struct videobuf_buffer *buf)
 {
        struct videobuf_vmalloc_memory *mem = buf->priv;
 
@@ -442,8 +348,3 @@ void videobuf_vmalloc_free (struct videobuf_buffer *buf)
 }
 EXPORT_SYMBOL_GPL(videobuf_vmalloc_free);
 
-/*
- * Local variables:
- * c-basic-offset: 8
- * End:
- */
index cdbe703..e17b6fe 100644 (file)
  * License, or (at your option) any later version
  */
 #include <linux/module.h>
-#include <linux/delay.h>
 #include <linux/errno.h>
-#include <linux/fs.h>
 #include <linux/kernel.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/ioport.h>
 #include <linux/init.h>
 #include <linux/sched.h>
-#include <linux/pci.h>
-#include <linux/random.h>
+#include <linux/slab.h>
+#include <linux/font.h>
 #include <linux/version.h>
 #include <linux/mutex.h>
 #include <linux/videodev2.h>
-#include <linux/dma-mapping.h>
-#include <linux/interrupt.h>
 #include <linux/kthread.h>
-#include <linux/highmem.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20)
 #include <linux/freezer.h>
+#endif
 #include <media/videobuf-vmalloc.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
-#include "font.h"
+#include <media/v4l2-common.h>
 
 #define VIVI_MODULE_NAME "vivi"
 
 #define WAKE_DENOMINATOR 1001
 #define BUFFER_TIMEOUT     msecs_to_jiffies(500)  /* 0.5 seconds */
 
+#define MAX_WIDTH 1920
+#define MAX_HEIGHT 1200
+
 #define VIVI_MAJOR_VERSION 0
-#define VIVI_MINOR_VERSION 6
+#define VIVI_MINOR_VERSION 7
 #define VIVI_RELEASE 0
 #define VIVI_VERSION \
        KERNEL_VERSION(VIVI_MAJOR_VERSION, VIVI_MINOR_VERSION, VIVI_RELEASE)
@@ -70,56 +67,8 @@ static unsigned int vid_limit = 16;
 module_param(vid_limit, uint, 0644);
 MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
 
-
-/* supported controls */
-static struct v4l2_queryctrl vivi_qctrl[] = {
-       {
-               .id            = V4L2_CID_AUDIO_VOLUME,
-               .name          = "Volume",
-               .minimum       = 0,
-               .maximum       = 65535,
-               .step          = 65535/100,
-               .default_value = 65535,
-               .flags         = V4L2_CTRL_FLAG_SLIDER,
-               .type          = V4L2_CTRL_TYPE_INTEGER,
-       }, {
-               .id            = V4L2_CID_BRIGHTNESS,
-               .type          = V4L2_CTRL_TYPE_INTEGER,
-               .name          = "Brightness",
-               .minimum       = 0,
-               .maximum       = 255,
-               .step          = 1,
-               .default_value = 127,
-               .flags         = V4L2_CTRL_FLAG_SLIDER,
-       }, {
-               .id            = V4L2_CID_CONTRAST,
-               .type          = V4L2_CTRL_TYPE_INTEGER,
-               .name          = "Contrast",
-               .minimum       = 0,
-               .maximum       = 255,
-               .step          = 0x1,
-               .default_value = 0x10,
-               .flags         = V4L2_CTRL_FLAG_SLIDER,
-       }, {
-               .id            = V4L2_CID_SATURATION,
-               .type          = V4L2_CTRL_TYPE_INTEGER,
-               .name          = "Saturation",
-               .minimum       = 0,
-               .maximum       = 255,
-               .step          = 0x1,
-               .default_value = 127,
-               .flags         = V4L2_CTRL_FLAG_SLIDER,
-       }, {
-               .id            = V4L2_CID_HUE,
-               .type          = V4L2_CTRL_TYPE_INTEGER,
-               .name          = "Hue",
-               .minimum       = -128,
-               .maximum       = 127,
-               .step          = 0x1,
-               .default_value = 0,
-               .flags         = V4L2_CTRL_FLAG_SLIDER,
-       }
-};
+/* Global font descriptor */
+static const u8 *font8x16;
 
 #define dprintk(dev, level, fmt, arg...) \
        v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ## arg)
@@ -214,41 +163,38 @@ struct vivi_dev {
        struct list_head           vivi_devlist;
        struct v4l2_device         v4l2_dev;
 
+       /* controls */
+       int                        brightness;
+       int                        contrast;
+       int                        saturation;
+       int                        hue;
+       int                        volume;
+
        spinlock_t                 slock;
        struct mutex               mutex;
 
-       int                        users;
-
        /* various device info */
        struct video_device        *vfd;
 
        struct vivi_dmaqueue       vidq;
 
        /* Several counters */
-       int                        h, m, s, ms;
+       unsigned                   ms;
        unsigned long              jiffies;
-       char                       timestr[13];
 
        int                        mv_count;    /* Controls bars movement */
 
        /* Input Number */
        int                        input;
 
-       /* Control 'registers' */
-       int                        qctl_regs[ARRAY_SIZE(vivi_qctrl)];
-};
-
-struct vivi_fh {
-       struct vivi_dev            *dev;
-
        /* video capture */
        struct vivi_fmt            *fmt;
        unsigned int               width, height;
        struct videobuf_queue      vb_vidq;
 
-       enum v4l2_buf_type         type;
-       unsigned char              bars[8][3];
-       int                        input;       /* Input Number on bars */
+       unsigned long              generating;
+       u8                         bars[9][3];
+       u8                         line[MAX_WIDTH * 4];
 };
 
 /* ------------------------------------------------------------------
@@ -259,19 +205,20 @@ struct vivi_fh {
 
 enum colors {
        WHITE,
-       AMBAR,
+       AMBER,
        CYAN,
        GREEN,
        MAGENTA,
        RED,
        BLUE,
        BLACK,
+       TEXT_BLACK,
 };
 
-       /* R   G   B */
+/* R   G   B */
 #define COLOR_WHITE    {204, 204, 204}
-#define COLOR_AMBAR    {208, 208,   0}
-#define COLOR_CIAN     {  0, 206, 206}
+#define COLOR_AMBER    {208, 208,   0}
+#define COLOR_CYAN     {  0, 206, 206}
 #define        COLOR_GREEN     {  0, 239,   0}
 #define COLOR_MAGENTA  {239,   0, 239}
 #define COLOR_RED      {205,   0,   0}
@@ -279,56 +226,24 @@ enum colors {
 #define COLOR_BLACK    {  0,   0,   0}
 
 struct bar_std {
-       u8 bar[8][3];
+       u8 bar[9][3];
 };
 
 /* Maximum number of bars are 10 - otherwise, the input print code
    should be modified */
 static struct bar_std bars[] = {
        {       /* Standard ITU-R color bar sequence */
-               {
-                       COLOR_WHITE,
-                       COLOR_AMBAR,
-                       COLOR_CIAN,
-                       COLOR_GREEN,
-                       COLOR_MAGENTA,
-                       COLOR_RED,
-                       COLOR_BLUE,
-                       COLOR_BLACK,
-               }
+               { COLOR_WHITE, COLOR_AMBER, COLOR_CYAN, COLOR_GREEN,
+                 COLOR_MAGENTA, COLOR_RED, COLOR_BLUE, COLOR_BLACK, COLOR_BLACK }
        }, {
-               {
-                       COLOR_WHITE,
-                       COLOR_AMBAR,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_AMBAR,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_AMBAR,
-               }
+               { COLOR_WHITE, COLOR_AMBER, COLOR_BLACK, COLOR_WHITE,
+                 COLOR_AMBER, COLOR_BLACK, COLOR_WHITE, COLOR_AMBER, COLOR_BLACK }
        }, {
-               {
-                       COLOR_WHITE,
-                       COLOR_CIAN,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_CIAN,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_CIAN,
-               }
+               { COLOR_WHITE, COLOR_CYAN, COLOR_BLACK, COLOR_WHITE,
+                 COLOR_CYAN, COLOR_BLACK, COLOR_WHITE, COLOR_CYAN, COLOR_BLACK }
        }, {
-               {
-                       COLOR_WHITE,
-                       COLOR_GREEN,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_GREEN,
-                       COLOR_BLACK,
-                       COLOR_WHITE,
-                       COLOR_GREEN,
-               }
+               { COLOR_WHITE, COLOR_GREEN, COLOR_BLACK, COLOR_WHITE,
+                 COLOR_GREEN, COLOR_BLACK, COLOR_WHITE, COLOR_GREEN, COLOR_BLACK }
        },
 };
 
@@ -344,21 +259,18 @@ static struct bar_std bars[] = {
        (((-9714 * r - 19070 * g + 28784 * b + 32768) >> 16) + 128)
 
 /* precalculate color bar values to speed up rendering */
-static void precalculate_bars(struct vivi_fh *fh)
+static void precalculate_bars(struct vivi_dev *dev)
 {
-       struct vivi_dev *dev = fh->dev;
-       unsigned char r, g, b;
+       u8 r, g, b;
        int k, is_yuv;
 
-       fh->input = dev->input;
-
-       for (k = 0; k < 8; k++) {
-               r = bars[fh->input].bar[k][0];
-               g = bars[fh->input].bar[k][1];
-               b = bars[fh->input].bar[k][2];
+       for (k = 0; k < 9; k++) {
+               r = bars[dev->input].bar[k][0];
+               g = bars[dev->input].bar[k][1];
+               b = bars[dev->input].bar[k][2];
                is_yuv = 0;
 
-               switch (fh->fmt->fourcc) {
+               switch (dev->fmt->fourcc) {
                case V4L2_PIX_FMT_YUYV:
                case V4L2_PIX_FMT_UYVY:
                        is_yuv = 1;
@@ -378,16 +290,15 @@ static void precalculate_bars(struct vivi_fh *fh)
                }
 
                if (is_yuv) {
-                       fh->bars[k][0] = TO_Y(r, g, b); /* Luma */
-                       fh->bars[k][1] = TO_U(r, g, b); /* Cb */
-                       fh->bars[k][2] = TO_V(r, g, b); /* Cr */
+                       dev->bars[k][0] = TO_Y(r, g, b);        /* Luma */
+                       dev->bars[k][1] = TO_U(r, g, b);        /* Cb */
+                       dev->bars[k][2] = TO_V(r, g, b);        /* Cr */
                } else {
-                       fh->bars[k][0] = r;
-                       fh->bars[k][1] = g;
-                       fh->bars[k][2] = b;
+                       dev->bars[k][0] = r;
+                       dev->bars[k][1] = g;
+                       dev->bars[k][2] = b;
                }
        }
-
 }
 
 #define TSTAMP_MIN_Y   24
@@ -395,20 +306,20 @@ static void precalculate_bars(struct vivi_fh *fh)
 #define TSTAMP_INPUT_X 10
 #define TSTAMP_MIN_X   (54 + TSTAMP_INPUT_X)
 
-static void gen_twopix(struct vivi_fh *fh, unsigned char *buf, int colorpos)
+static void gen_twopix(struct vivi_dev *dev, u8 *buf, int colorpos)
 {
-       unsigned char r_y, g_u, b_v;
-       unsigned char *p;
+       u8 r_y, g_u, b_v;
        int color;
+       u8 *p;
 
-       r_y = fh->bars[colorpos][0]; /* R or precalculated Y */
-       g_u = fh->bars[colorpos][1]; /* G or precalculated U */
-       b_v = fh->bars[colorpos][2]; /* B or precalculated V */
+       r_y = dev->bars[colorpos][0]; /* R or precalculated Y */
+       g_u = dev->bars[colorpos][1]; /* G or precalculated U */
+       b_v = dev->bars[colorpos][2]; /* B or precalculated V */
 
        for (color = 0; color < 4; color++) {
                p = buf + color;
 
-               switch (fh->fmt->fourcc) {
+               switch (dev->fmt->fourcc) {
                case V4L2_PIX_FMT_YUYV:
                        switch (color) {
                        case 0:
@@ -489,123 +400,88 @@ static void gen_twopix(struct vivi_fh *fh, unsigned char *buf, int colorpos)
        }
 }
 
-static void gen_line(struct vivi_fh *fh, char *basep, int inipos, int wmax,
-               int hmax, int line, int count, char *timestr)
+static void precalculate_line(struct vivi_dev *dev)
 {
-       int  w, i, j;
-       int pos = inipos;
-       char *s;
-       u8 chr;
-
-       /* We will just duplicate the second pixel at the packet */
-       wmax /= 2;
+       int w;
 
-       /* Generate a standard color bar pattern */
-       for (w = 0; w < wmax; w++) {
-               int colorpos = ((w + count) * 8/(wmax + 1)) % 8;
+       for (w = 0; w < dev->width * 2; w += 2) {
+               int colorpos = (w / (dev->width / 8) % 8);
 
-               gen_twopix(fh, basep + pos, colorpos);
-               pos += 4; /* only 16 bpp supported for now */
+               gen_twopix(dev, dev->line + w * 2, colorpos);
        }
+}
 
-       /* Prints input entry number */
-
-       /* Checks if it is possible to input number */
-       if (TSTAMP_MAX_Y >= hmax)
-               goto end;
-
-       if (TSTAMP_INPUT_X + strlen(timestr) >= wmax)
-               goto end;
-
-       if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
-               chr = rom8x16_bits[fh->input * 16 + line - TSTAMP_MIN_Y];
-               pos = TSTAMP_INPUT_X;
-               for (i = 0; i < 7; i++) {
-                       /* Draw white font on black background */
-                       if (chr & 1 << (7 - i))
-                               gen_twopix(fh, basep + pos, WHITE);
-                       else
-                               gen_twopix(fh, basep + pos, BLACK);
-                       pos += 2;
-               }
-       }
+static void gen_text(struct vivi_dev *dev, char *basep,
+                                       int y, int x, char *text)
+{
+       int line;
 
-       /* Checks if it is possible to show timestamp */
-       if (TSTAMP_MIN_X + strlen(timestr) >= wmax)
-               goto end;
+       /* Checks if it is possible to show string */
+       if (y + 16 >= dev->height || x + strlen(text) * 8 >= dev->width)
+               return;
 
        /* Print stream time */
-       if (line >= TSTAMP_MIN_Y && line <= TSTAMP_MAX_Y) {
-               j = TSTAMP_MIN_X;
-               for (s = timestr; *s; s++) {
-                       chr = rom8x16_bits[(*s-0x30)*16+line-TSTAMP_MIN_Y];
-                       for (i = 0; i < 7; i++) {
-                               pos = inipos + j * 2;
+       for (line = y; line < y + 16; line++) {
+               int j = 0;
+               char *pos = basep + line * dev->width * 2 + x * 2;
+               char *s;
+
+               for (s = text; *s; s++) {
+                       u8 chr = font8x16[*s * 16 + line - y];
+                       int i;
+
+                       for (i = 0; i < 7; i++, j++) {
                                /* Draw white font on black background */
-                               if (chr & 1 << (7 - i))
-                                       gen_twopix(fh, basep + pos, WHITE);
+                               if (chr & (1 << (7 - i)))
+                                       gen_twopix(dev, pos + j * 2, WHITE);
                                else
-                                       gen_twopix(fh, basep + pos, BLACK);
-                               j++;
+                                       gen_twopix(dev, pos + j * 2, TEXT_BLACK);
                        }
                }
        }
-
-end:
-       return;
 }
 
-static void vivi_fillbuff(struct vivi_fh *fh, struct vivi_buffer *buf)
+static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
 {
-       struct vivi_dev *dev = fh->dev;
-       int h , pos = 0;
-       int hmax  = buf->vb.height;
-       int wmax  = buf->vb.width;
+       int hmax = buf->vb.height;
+       int wmax = buf->vb.width;
        struct timeval ts;
-       char *tmpbuf;
        void *vbuf = videobuf_to_vmalloc(&buf->vb);
+       unsigned ms;
+       char str[100];
+       int h, line = 1;
 
        if (!vbuf)
                return;
 
-       tmpbuf = kmalloc(wmax * 2, GFP_ATOMIC);
-       if (!tmpbuf)
-               return;
-
-       for (h = 0; h < hmax; h++) {
-               gen_line(fh, tmpbuf, 0, wmax, hmax, h, dev->mv_count,
-                        dev->timestr);
-               memcpy(vbuf + pos, tmpbuf, wmax * 2);
-               pos += wmax*2;
-       }
-
-       dev->mv_count++;
-
-       kfree(tmpbuf);
+       for (h = 0; h < hmax; h++)
+               memcpy(vbuf + h * wmax * 2, dev->line + (dev->mv_count % wmax) * 2, wmax * 2);
 
        /* Updates stream time */
 
-       dev->ms += jiffies_to_msecs(jiffies-dev->jiffies);
+       dev->ms += jiffies_to_msecs(jiffies - dev->jiffies);
        dev->jiffies = jiffies;
-       if (dev->ms >= 1000) {
-               dev->ms -= 1000;
-               dev->s++;
-               if (dev->s >= 60) {
-                       dev->s -= 60;
-                       dev->m++;
-                       if (dev->m > 60) {
-                               dev->m -= 60;
-                               dev->h++;
-                               if (dev->h > 24)
-                                       dev->h -= 24;
-                       }
-               }
-       }
-       sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
-                       dev->h, dev->m, dev->s, dev->ms);
-
-       dprintk(dev, 2, "vivifill at %s: Buffer 0x%08lx size= %d\n",
-                       dev->timestr, (unsigned long)tmpbuf, pos);
+       ms = dev->ms;
+       snprintf(str, sizeof(str), " %02d:%02d:%02d:%03d ",
+                       (ms / (60 * 60 * 1000)) % 24,
+                       (ms / (60 * 1000)) % 60,
+                       (ms / 1000) % 60,
+                       ms % 1000);
+       gen_text(dev, vbuf, line++ * 16, 16, str);
+       snprintf(str, sizeof(str), " %dx%d, input %d ",
+                       dev->width, dev->height, dev->input);
+       gen_text(dev, vbuf, line++ * 16, 16, str);
+
+       snprintf(str, sizeof(str), " brightness %3d, contrast %3d, saturation %3d, hue %d ",
+                       dev->brightness,
+                       dev->contrast,
+                       dev->saturation,
+                       dev->hue);
+       gen_text(dev, vbuf, line++ * 16, 16, str);
+       snprintf(str, sizeof(str), " volume %3d ", dev->volume);
+       gen_text(dev, vbuf, line++ * 16, 16, str);
+
+       dev->mv_count += 2;
 
        /* Advice that buffer was filled */
        buf->vb.field_count++;
@@ -614,12 +490,10 @@ static void vivi_fillbuff(struct vivi_fh *fh, struct vivi_buffer *buf)
        buf->vb.state = VIDEOBUF_DONE;
 }
 
-static void vivi_thread_tick(struct vivi_fh *fh)
+static void vivi_thread_tick(struct vivi_dev *dev)
 {
-       struct vivi_buffer *buf;
-       struct vivi_dev *dev = fh->dev;
        struct vivi_dmaqueue *dma_q = &dev->vidq;
-
+       struct vivi_buffer *buf;
        unsigned long flags = 0;
 
        dprintk(dev, 1, "Thread tick\n");
@@ -642,22 +516,20 @@ static void vivi_thread_tick(struct vivi_fh *fh)
        do_gettimeofday(&buf->vb.ts);
 
        /* Fill buffer */
-       vivi_fillbuff(fh, buf);
+       vivi_fillbuff(dev, buf);
        dprintk(dev, 1, "filled buffer %p\n", buf);
 
        wake_up(&buf->vb.done);
        dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
 unlock:
        spin_unlock_irqrestore(&dev->slock, flags);
-       return;
 }
 
 #define frames_to_ms(frames)                                   \
        ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
 
-static void vivi_sleep(struct vivi_fh *fh)
+static void vivi_sleep(struct vivi_dev *dev)
 {
-       struct vivi_dev *dev = fh->dev;
        struct vivi_dmaqueue *dma_q = &dev->vidq;
        int timeout;
        DECLARE_WAITQUEUE(wait, current);
@@ -672,7 +544,7 @@ static void vivi_sleep(struct vivi_fh *fh)
        /* Calculate time to wake up */
        timeout = msecs_to_jiffies(frames_to_ms(1));
 
-       vivi_thread_tick(fh);
+       vivi_thread_tick(dev);
 
        schedule_timeout_interruptible(timeout);
 
@@ -683,15 +555,14 @@ stop_task:
 
 static int vivi_thread(void *data)
 {
-       struct vivi_fh  *fh = data;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = data;
 
        dprintk(dev, 1, "thread started\n");
 
        set_freezable();
 
        for (;;) {
-               vivi_sleep(fh);
+               vivi_sleep(dev);
 
                if (kthread_should_stop())
                        break;
@@ -700,39 +571,61 @@ static int vivi_thread(void *data)
        return 0;
 }
 
-static int vivi_start_thread(struct vivi_fh *fh)
+static void vivi_start_generating(struct file *file)
 {
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
        struct vivi_dmaqueue *dma_q = &dev->vidq;
 
-       dma_q->frame = 0;
-       dma_q->ini_jiffies = jiffies;
-
        dprintk(dev, 1, "%s\n", __func__);
 
-       dma_q->kthread = kthread_run(vivi_thread, fh, "vivi");
+       if (test_and_set_bit(0, &dev->generating))
+               return;
+       file->private_data = dev;
+
+       /* Resets frame counters */
+       dev->ms = 0;
+       dev->mv_count = 0;
+       dev->jiffies = jiffies;
+
+       dma_q->frame = 0;
+       dma_q->ini_jiffies = jiffies;
+       dma_q->kthread = kthread_run(vivi_thread, dev, dev->v4l2_dev.name);
 
        if (IS_ERR(dma_q->kthread)) {
                v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
-               return PTR_ERR(dma_q->kthread);
+               clear_bit(0, &dev->generating);
+               return;
        }
        /* Wakes thread */
        wake_up_interruptible(&dma_q->wq);
 
        dprintk(dev, 1, "returning from %s\n", __func__);
-       return 0;
 }
 
-static void vivi_stop_thread(struct vivi_dmaqueue  *dma_q)
+static void vivi_stop_generating(struct file *file)
 {
-       struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
+       struct vivi_dev *dev = video_drvdata(file);
+       struct vivi_dmaqueue *dma_q = &dev->vidq;
 
        dprintk(dev, 1, "%s\n", __func__);
+
+       if (!file->private_data)
+               return;
+       if (!test_and_clear_bit(0, &dev->generating))
+               return;
+
        /* shutdown control thread */
        if (dma_q->kthread) {
                kthread_stop(dma_q->kthread);
                dma_q->kthread = NULL;
        }
+       videobuf_stop(&dev->vb_vidq);
+       videobuf_mmap_free(&dev->vb_vidq);
+}
+
+static int vivi_is_generating(struct vivi_dev *dev)
+{
+       return test_bit(0, &dev->generating);
 }
 
 /* ------------------------------------------------------------------
@@ -741,10 +634,9 @@ static void vivi_stop_thread(struct vivi_dmaqueue  *dma_q)
 static int
 buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
 {
-       struct vivi_fh  *fh = vq->priv_data;
-       struct vivi_dev *dev  = fh->dev;
+       struct vivi_dev *dev = vq->priv_data;
 
-       *size = fh->width*fh->height*2;
+       *size = dev->width * dev->height * 2;
 
        if (0 == *count)
                *count = 32;
@@ -760,49 +652,43 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
 
 static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
 {
-       struct vivi_fh  *fh = vq->priv_data;
-       struct vivi_dev *dev  = fh->dev;
+       struct vivi_dev *dev = vq->priv_data;
 
        dprintk(dev, 1, "%s, state: %i\n", __func__, buf->vb.state);
 
-       if (in_interrupt())
-               BUG();
-
        videobuf_vmalloc_free(&buf->vb);
        dprintk(dev, 1, "free_buffer: freed\n");
        buf->vb.state = VIDEOBUF_NEEDS_INIT;
 }
 
-#define norm_maxw() 1024
-#define norm_maxh() 768
 static int
 buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
                                                enum v4l2_field field)
 {
-       struct vivi_fh     *fh  = vq->priv_data;
-       struct vivi_dev    *dev = fh->dev;
+       struct vivi_dev *dev = vq->priv_data;
        struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
        int rc;
 
        dprintk(dev, 1, "%s, field=%d\n", __func__, field);
 
-       BUG_ON(NULL == fh->fmt);
+       BUG_ON(NULL == dev->fmt);
 
-       if (fh->width  < 48 || fh->width  > norm_maxw() ||
-           fh->height < 32 || fh->height > norm_maxh())
+       if (dev->width  < 48 || dev->width  > MAX_WIDTH ||
+           dev->height < 32 || dev->height > MAX_HEIGHT)
                return -EINVAL;
 
-       buf->vb.size = fh->width*fh->height*2;
-       if (0 != buf->vb.baddr  &&  buf->vb.bsize < buf->vb.size)
+       buf->vb.size = dev->width * dev->height * 2;
+       if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
                return -EINVAL;
 
        /* These properties only change when queue is idle, see s_fmt */
-       buf->fmt       = fh->fmt;
-       buf->vb.width  = fh->width;
-       buf->vb.height = fh->height;
+       buf->fmt       = dev->fmt;
+       buf->vb.width  = dev->width;
+       buf->vb.height = dev->height;
        buf->vb.field  = field;
 
-       precalculate_bars(fh);
+       precalculate_bars(dev);
+       precalculate_line(dev);
 
        if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
                rc = videobuf_iolock(vq, &buf->vb, NULL);
@@ -811,7 +697,6 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
        }
 
        buf->vb.state = VIDEOBUF_PREPARED;
-
        return 0;
 
 fail:
@@ -822,9 +707,8 @@ fail:
 static void
 buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 {
-       struct vivi_buffer    *buf  = container_of(vb, struct vivi_buffer, vb);
-       struct vivi_fh        *fh   = vq->priv_data;
-       struct vivi_dev       *dev  = fh->dev;
+       struct vivi_dev *dev = vq->priv_data;
+       struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
        struct vivi_dmaqueue *vidq = &dev->vidq;
 
        dprintk(dev, 1, "%s\n", __func__);
@@ -836,9 +720,8 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 static void buffer_release(struct videobuf_queue *vq,
                           struct videobuf_buffer *vb)
 {
-       struct vivi_buffer   *buf  = container_of(vb, struct vivi_buffer, vb);
-       struct vivi_fh       *fh   = vq->priv_data;
-       struct vivi_dev      *dev  = (struct vivi_dev *)fh->dev;
+       struct vivi_dev *dev = vq->priv_data;
+       struct vivi_buffer *buf  = container_of(vb, struct vivi_buffer, vb);
 
        dprintk(dev, 1, "%s\n", __func__);
 
@@ -858,16 +741,14 @@ static struct videobuf_queue_ops vivi_video_qops = {
 static int vidioc_querycap(struct file *file, void  *priv,
                                        struct v4l2_capability *cap)
 {
-       struct vivi_fh  *fh  = priv;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
 
        strcpy(cap->driver, "vivi");
        strcpy(cap->card, "vivi");
        strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info));
        cap->version = VIVI_VERSION;
-       cap->capabilities =     V4L2_CAP_VIDEO_CAPTURE |
-                               V4L2_CAP_STREAMING     |
-                               V4L2_CAP_READWRITE;
+       cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | \
+                           V4L2_CAP_READWRITE;
        return 0;
 }
 
@@ -889,28 +770,25 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void  *priv,
 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
                                        struct v4l2_format *f)
 {
-       struct vivi_fh *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       f->fmt.pix.width        = fh->width;
-       f->fmt.pix.height       = fh->height;
-       f->fmt.pix.field        = fh->vb_vidq.field;
-       f->fmt.pix.pixelformat  = fh->fmt->fourcc;
+       f->fmt.pix.width        = dev->width;
+       f->fmt.pix.height       = dev->height;
+       f->fmt.pix.field        = dev->vb_vidq.field;
+       f->fmt.pix.pixelformat  = dev->fmt->fourcc;
        f->fmt.pix.bytesperline =
-               (f->fmt.pix.width * fh->fmt->depth) >> 3;
+               (f->fmt.pix.width * dev->fmt->depth) >> 3;
        f->fmt.pix.sizeimage =
                f->fmt.pix.height * f->fmt.pix.bytesperline;
-
-       return (0);
+       return 0;
 }
 
 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                        struct v4l2_format *f)
 {
-       struct vivi_fh  *fh  = priv;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
        struct vivi_fmt *fmt;
        enum v4l2_field field;
-       unsigned int maxw, maxh;
 
        fmt = get_format(f);
        if (!fmt) {
@@ -928,113 +806,109 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                return -EINVAL;
        }
 
-       maxw  = norm_maxw();
-       maxh  = norm_maxh();
-
        f->fmt.pix.field = field;
-       v4l_bound_align_image(&f->fmt.pix.width, 48, maxw, 2,
-                             &f->fmt.pix.height, 32, maxh, 0, 0);
+       v4l_bound_align_image(&f->fmt.pix.width, 48, MAX_WIDTH, 2,
+                             &f->fmt.pix.height, 32, MAX_HEIGHT, 0, 0);
        f->fmt.pix.bytesperline =
                (f->fmt.pix.width * fmt->depth) >> 3;
        f->fmt.pix.sizeimage =
                f->fmt.pix.height * f->fmt.pix.bytesperline;
-
        return 0;
 }
 
-/*FIXME: This seems to be generic enough to be at videodev2 */
 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
                                        struct v4l2_format *f)
 {
-       struct vivi_fh *fh = priv;
-       struct videobuf_queue *q = &fh->vb_vidq;
+       struct vivi_dev *dev = video_drvdata(file);
+       struct videobuf_queue *q = &dev->vb_vidq;
 
-       int ret = vidioc_try_fmt_vid_cap(file, fh, f);
+       int ret = vidioc_try_fmt_vid_cap(file, priv, f);
        if (ret < 0)
                return ret;
 
        mutex_lock(&q->vb_lock);
 
-       if (videobuf_queue_is_busy(&fh->vb_vidq)) {
-               dprintk(fh->dev, 1, "%s queue busy\n", __func__);
+       if (vivi_is_generating(dev)) {
+               dprintk(dev, 1, "%s device busy\n", __func__);
                ret = -EBUSY;
                goto out;
        }
 
-       fh->fmt           = get_format(f);
-       fh->width         = f->fmt.pix.width;
-       fh->height        = f->fmt.pix.height;
-       fh->vb_vidq.field = f->fmt.pix.field;
-       fh->type          = f->type;
-
+       dev->fmt = get_format(f);
+       dev->width = f->fmt.pix.width;
+       dev->height = f->fmt.pix.height;
+       dev->vb_vidq.field = f->fmt.pix.field;
        ret = 0;
 out:
        mutex_unlock(&q->vb_lock);
-
        return ret;
 }
 
 static int vidioc_reqbufs(struct file *file, void *priv,
                          struct v4l2_requestbuffers *p)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       return (videobuf_reqbufs(&fh->vb_vidq, p));
+       return videobuf_reqbufs(&dev->vb_vidq, p);
 }
 
 static int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       return (videobuf_querybuf(&fh->vb_vidq, p));
+       return videobuf_querybuf(&dev->vb_vidq, p);
 }
 
 static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
-       struct vivi_fh *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       return (videobuf_qbuf(&fh->vb_vidq, p));
+       return videobuf_qbuf(&dev->vb_vidq, p);
 }
 
 static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       return (videobuf_dqbuf(&fh->vb_vidq, p,
-                               file->f_flags & O_NONBLOCK));
+       return videobuf_dqbuf(&dev->vb_vidq, p,
+                               file->f_flags & O_NONBLOCK);
 }
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
 static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
+       return videobuf_cgmbuf(&dev->vb_vidq, mbuf, 8);
 }
 #endif
 
 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
+       int ret;
 
-       if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               return -EINVAL;
-       if (i != fh->type)
+       if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
+       ret = videobuf_streamon(&dev->vb_vidq);
+       if (ret)
+               return ret;
 
-       return videobuf_streamon(&fh->vb_vidq);
+       vivi_start_generating(file);
+       return 0;
 }
 
 static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 {
-       struct vivi_fh  *fh = priv;
+       struct vivi_dev *dev = video_drvdata(file);
+       int ret;
 
-       if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
-               return -EINVAL;
-       if (i != fh->type)
+       if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
-
-       return videobuf_streamoff(&fh->vb_vidq);
+       ret = videobuf_streamoff(&dev->vb_vidq);
+       if (!ret)
+               vivi_stop_generating(file);
+       return ret;
 }
 
 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
@@ -1052,80 +926,104 @@ static int vidioc_enum_input(struct file *file, void *priv,
        inp->type = V4L2_INPUT_TYPE_CAMERA;
        inp->std = V4L2_STD_525_60;
        sprintf(inp->name, "Camera %u", inp->index);
-
-       return (0);
+       return 0;
 }
 
 static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 {
-       struct vivi_fh *fh = priv;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
 
        *i = dev->input;
-
-       return (0);
+       return 0;
 }
+
 static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
-       struct vivi_fh *fh = priv;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
 
        if (i >= NUM_INPUTS)
                return -EINVAL;
 
        dev->input = i;
-       precalculate_bars(fh);
-
-       return (0);
+       precalculate_bars(dev);
+       precalculate_line(dev);
+       return 0;
 }
 
-       /* --- controls ---------------------------------------------- */
+/* --- controls ---------------------------------------------- */
 static int vidioc_queryctrl(struct file *file, void *priv,
                            struct v4l2_queryctrl *qc)
 {
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
-               if (qc->id && qc->id == vivi_qctrl[i].id) {
-                       memcpy(qc, &(vivi_qctrl[i]),
-                               sizeof(*qc));
-                       return (0);
-               }
-
+       switch (qc->id) {
+       case V4L2_CID_AUDIO_VOLUME:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 200);
+       case V4L2_CID_BRIGHTNESS:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 127);
+       case V4L2_CID_CONTRAST:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 16);
+       case V4L2_CID_SATURATION:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 127);
+       case V4L2_CID_HUE:
+               return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
+       }
        return -EINVAL;
 }
 
 static int vidioc_g_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctrl)
 {
-       struct vivi_fh *fh = priv;
-       struct vivi_dev *dev = fh->dev;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
-               if (ctrl->id == vivi_qctrl[i].id) {
-                       ctrl->value = dev->qctl_regs[i];
-                       return 0;
-               }
+       struct vivi_dev *dev = video_drvdata(file);
 
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_VOLUME:
+               ctrl->value = dev->volume;
+               return 0;
+       case V4L2_CID_BRIGHTNESS:
+               ctrl->value = dev->brightness;
+               return 0;
+       case V4L2_CID_CONTRAST:
+               ctrl->value = dev->contrast;
+               return 0;
+       case V4L2_CID_SATURATION:
+               ctrl->value = dev->saturation;
+               return 0;
+       case V4L2_CID_HUE:
+               ctrl->value = dev->hue;
+               return 0;
+       }
        return -EINVAL;
 }
+
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct vivi_fh *fh = priv;
-       struct vivi_dev *dev = fh->dev;
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
-               if (ctrl->id == vivi_qctrl[i].id) {
-                       if (ctrl->value < vivi_qctrl[i].minimum ||
-                           ctrl->value > vivi_qctrl[i].maximum) {
-                               return -ERANGE;
-                       }
-                       dev->qctl_regs[i] = ctrl->value;
-                       return 0;
-               }
+       struct vivi_dev *dev = video_drvdata(file);
+       struct v4l2_queryctrl qc;
+       int err;
+
+       qc.id = ctrl->id;
+       err = vidioc_queryctrl(file, priv, &qc);
+       if (err < 0)
+               return err;
+       if (ctrl->value < qc.minimum || ctrl->value > qc.maximum)
+               return -ERANGE;
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_VOLUME:
+               dev->volume = ctrl->value;
+               return 0;
+       case V4L2_CID_BRIGHTNESS:
+               dev->brightness = ctrl->value;
+               return 0;
+       case V4L2_CID_CONTRAST:
+               dev->contrast = ctrl->value;
+               return 0;
+       case V4L2_CID_SATURATION:
+               dev->saturation = ctrl->value;
+               return 0;
+       case V4L2_CID_HUE:
+               dev->hue = ctrl->value;
+               return 0;
+       }
        return -EINVAL;
 }
 
@@ -1133,134 +1031,58 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        File operations for the device
    ------------------------------------------------------------------*/
 
-static int vivi_open(struct file *file)
-{
-       struct vivi_dev *dev = video_drvdata(file);
-       struct vivi_fh *fh = NULL;
-       int retval = 0;
-
-       mutex_lock(&dev->mutex);
-       dev->users++;
-
-       if (dev->users > 1) {
-               dev->users--;
-               mutex_unlock(&dev->mutex);
-               return -EBUSY;
-       }
-
-       dprintk(dev, 1, "open %s type=%s users=%d\n",
-               video_device_node_name(dev->vfd),
-               v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
-
-       /* allocate + initialize per filehandle data */
-       fh = kzalloc(sizeof(*fh), GFP_KERNEL);
-       if (NULL == fh) {
-               dev->users--;
-               retval = -ENOMEM;
-       }
-       mutex_unlock(&dev->mutex);
-
-       if (retval)
-               return retval;
-
-       file->private_data = fh;
-       fh->dev      = dev;
-
-       fh->type     = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-       fh->fmt      = &formats[0];
-       fh->width    = 640;
-       fh->height   = 480;
-
-       /* Resets frame counters */
-       dev->h = 0;
-       dev->m = 0;
-       dev->s = 0;
-       dev->ms = 0;
-       dev->mv_count = 0;
-       dev->jiffies = jiffies;
-       sprintf(dev->timestr, "%02d:%02d:%02d:%03d",
-                       dev->h, dev->m, dev->s, dev->ms);
-
-       videobuf_queue_vmalloc_init(&fh->vb_vidq, &vivi_video_qops,
-                       NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
-                       sizeof(struct vivi_buffer), fh);
-
-       vivi_start_thread(fh);
-
-       return 0;
-}
-
 static ssize_t
 vivi_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
 {
-       struct vivi_fh *fh = file->private_data;
+       struct vivi_dev *dev = video_drvdata(file);
 
-       if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-               return videobuf_read_stream(&fh->vb_vidq, data, count, ppos, 0,
+       vivi_start_generating(file);
+       return videobuf_read_stream(&dev->vb_vidq, data, count, ppos, 0,
                                        file->f_flags & O_NONBLOCK);
-       }
-       return 0;
 }
 
 static unsigned int
 vivi_poll(struct file *file, struct poll_table_struct *wait)
 {
-       struct vivi_fh        *fh = file->private_data;
-       struct vivi_dev       *dev = fh->dev;
-       struct videobuf_queue *q = &fh->vb_vidq;
+       struct vivi_dev *dev = video_drvdata(file);
+       struct videobuf_queue *q = &dev->vb_vidq;
 
        dprintk(dev, 1, "%s\n", __func__);
 
-       if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
-               return POLLERR;
-
+       vivi_start_generating(file);
        return videobuf_poll_stream(file, q, wait);
 }
 
 static int vivi_close(struct file *file)
 {
-       struct vivi_fh         *fh = file->private_data;
-       struct vivi_dev *dev       = fh->dev;
-       struct vivi_dmaqueue *vidq = &dev->vidq;
        struct video_device  *vdev = video_devdata(file);
+       struct vivi_dev *dev = video_drvdata(file);
 
-       vivi_stop_thread(vidq);
-       videobuf_stop(&fh->vb_vidq);
-       videobuf_mmap_free(&fh->vb_vidq);
-
-       kfree(fh);
-
-       mutex_lock(&dev->mutex);
-       dev->users--;
-       mutex_unlock(&dev->mutex);
-
-       dprintk(dev, 1, "close called (dev=%s, users=%d)\n",
-               video_device_node_name(vdev), dev->users);
+       vivi_stop_generating(file);
 
+       dprintk(dev, 1, "close called (dev=%s)\n",
+               video_device_node_name(vdev));
        return 0;
 }
 
 static int vivi_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct vivi_fh  *fh = file->private_data;
-       struct vivi_dev *dev = fh->dev;
+       struct vivi_dev *dev = video_drvdata(file);
        int ret;
 
        dprintk(dev, 1, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
 
-       ret = videobuf_mmap_mapper(&fh->vb_vidq, vma);
+       ret = videobuf_mmap_mapper(&dev->vb_vidq, vma);
 
        dprintk(dev, 1, "vma start=0x%08lx, size=%ld, ret=%d\n",
                (unsigned long)vma->vm_start,
-               (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
+               (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
                ret);
-
        return ret;
 }
 
 static const struct v4l2_file_operations vivi_fops = {
        .owner          = THIS_MODULE,
-       .open           = vivi_open,
        .release        = vivi_close,
        .read           = vivi_read,
        .poll           = vivi_poll,
@@ -1282,11 +1104,11 @@ static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
        .vidioc_enum_input    = vidioc_enum_input,
        .vidioc_g_input       = vidioc_g_input,
        .vidioc_s_input       = vidioc_s_input,
+       .vidioc_streamon      = vidioc_streamon,
+       .vidioc_streamoff     = vidioc_streamoff,
        .vidioc_queryctrl     = vidioc_queryctrl,
        .vidioc_g_ctrl        = vidioc_g_ctrl,
        .vidioc_s_ctrl        = vidioc_s_ctrl,
-       .vidioc_streamon      = vidioc_streamon,
-       .vidioc_streamoff     = vidioc_streamoff,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
        .vidiocgmbuf          = vidiocgmbuf,
 #endif
@@ -1330,7 +1152,7 @@ static int __init vivi_create_instance(int inst)
 {
        struct vivi_dev *dev;
        struct video_device *vfd;
-       int ret, i;
+       int ret;
 
        dev = kzalloc(sizeof(*dev), GFP_KERNEL);
        if (!dev)
@@ -1342,6 +1164,20 @@ static int __init vivi_create_instance(int inst)
        if (ret)
                goto free_dev;
 
+       dev->fmt = &formats[0];
+       dev->width = 640;
+       dev->height = 480;
+       dev->volume = 200;
+       dev->brightness = 127;
+       dev->contrast = 16;
+       dev->saturation = 127;
+       dev->hue = 0;
+
+       videobuf_queue_vmalloc_init(&dev->vb_vidq, &vivi_video_qops,
+                       NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
+                       V4L2_FIELD_INTERLACED,
+                       sizeof(struct vivi_buffer), dev);
+
        /* init video dma queues */
        INIT_LIST_HEAD(&dev->vidq.active);
        init_waitqueue_head(&dev->vidq.wq);
@@ -1357,6 +1193,7 @@ static int __init vivi_create_instance(int inst)
 
        *vfd = vivi_template;
        vfd->debug = debug;
+       vfd->v4l2_dev = &dev->v4l2_dev;
 
        ret = video_register_device(vfd, VFL_TYPE_GRABBER, video_nr);
        if (ret < 0)
@@ -1364,10 +1201,6 @@ static int __init vivi_create_instance(int inst)
 
        video_set_drvdata(vfd, dev);
 
-       /* Set all controls to their default value. */
-       for (i = 0; i < ARRAY_SIZE(vivi_qctrl); i++)
-               dev->qctl_regs[i] = vivi_qctrl[i].default_value;
-
        /* Now that everything is fine, let's add it to device list */
        list_add_tail(&dev->vivi_devlist, &vivi_devlist);
 
@@ -1396,8 +1229,15 @@ free_dev:
  */
 static int __init vivi_init(void)
 {
+       const struct font_desc *font = find_font("VGA8x16");
        int ret = 0, i;
 
+       if (font == NULL) {
+               printk(KERN_ERR "vivi: could not find font\n");
+               return -ENODEV;
+       }
+       font8x16 = font->data;
+
        if (n_devs <= 0)
                n_devs = 1;
 
@@ -1412,7 +1252,7 @@ static int __init vivi_init(void)
        }
 
        if (ret < 0) {
-               printk(KERN_INFO "Error %d while loading vivi driver\n", ret);
+               printk(KERN_ERR "vivi: error %d while loading driver\n", ret);
                return ret;
        }
 
index bf9bf65..635420d 100644 (file)
@@ -1,7 +1,7 @@
 /*
        Winbond w9966cf Webcam parport driver.
 
-       Version 0.32
+       Version 0.33
 
        Copyright (C) 2001 Jakob Kemi <jakob.kemi@post.utfors.se>
 
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/delay.h>
-#include <linux/videodev.h>
+#include <linux/version.h>
+#include <linux/videodev2.h>
 #include <linux/slab.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
+#include <media/v4l2-device.h>
 #include <linux/parport.h>
 
 /*#define DEBUG*/                              /* Undef me for production */
  */
 
 #define W9966_DRIVERNAME       "W9966CF Webcam"
-#define W9966_MAXCAMS          4       // Maximum number of cameras
-#define W9966_RBUFFER          2048    // Read buffer (must be an even number)
-#define W9966_SRAMSIZE         131072  // 128kb
-#define W9966_SRAMID           0x02    // check w9966cf.pdf
+#define W9966_MAXCAMS          4       /* Maximum number of cameras */
+#define W9966_RBUFFER          2048    /* Read buffer (must be an even number) */
+#define W9966_SRAMSIZE         131072  /* 128kb */
+#define W9966_SRAMID           0x02    /* check w9966cf.pdf */
 
-// Empirically determined window limits
+/* Empirically determined window limits */
 #define W9966_WND_MIN_X                16
 #define W9966_WND_MIN_Y                14
 #define W9966_WND_MAX_X                705
@@ -89,7 +91,7 @@
 #define W9966_WND_MAX_W                (W9966_WND_MAX_X - W9966_WND_MIN_X)
 #define W9966_WND_MAX_H                (W9966_WND_MAX_Y - W9966_WND_MIN_Y)
 
-// Keep track of our current state
+/* Keep track of our current state */
 #define W9966_STATE_PDEV       0x01
 #define W9966_STATE_CLAIMED    0x02
 #define W9966_STATE_VDEV       0x04
 #define W9966_I2C_W_DATA       0x02
 #define W9966_I2C_W_CLOCK      0x01
 
-struct w9966_dev {
+struct w9966 {
+       struct v4l2_device v4l2_dev;
        unsigned char dev_state;
        unsigned char i2c_state;
        unsigned short ppmode;
-       struct parportpport;
-       struct pardevicepdev;
+       struct parport *pport;
+       struct pardevice *pdev;
        struct video_device vdev;
        unsigned short width;
        unsigned short height;
@@ -114,7 +117,7 @@ struct w9966_dev {
        signed char contrast;
        signed char color;
        signed char hue;
-       unsigned long in_use;
+       struct mutex lock;
 };
 
 /*
@@ -127,15 +130,15 @@ MODULE_LICENSE("GPL");
 
 
 #ifdef MODULE
-static const charpardev[] = {[0 ... W9966_MAXCAMS] = ""};
+static const char *pardev[] = {[0 ... W9966_MAXCAMS] = ""};
 #else
-static const charpardev[] = {[0 ... W9966_MAXCAMS] = "aggressive"};
+static const char *pardev[] = {[0 ... W9966_MAXCAMS] = "aggressive"};
 #endif
 module_param_array(pardev, charp, NULL, 0);
-MODULE_PARM_DESC(pardev, "pardev: where to search for\n\
-\teach camera. 'aggressive' means brute-force search.\n\
-\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n\
-\tcam 1 to parport3 and search every parport for cam 2 etc...");
+MODULE_PARM_DESC(pardev, "pardev: where to search for\n"
+               "\teach camera. 'aggressive' means brute-force search.\n"
+               "\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n"
+               "\tcam 1 to parport3 and search every parport for cam 2 etc...");
 
 static int parmode;
 module_param(parmode, int, 0);
@@ -144,117 +147,49 @@ MODULE_PARM_DESC(parmode, "parmode: transfer mode (0=auto, 1=ecp, 2=epp");
 static int video_nr = -1;
 module_param(video_nr, int, 0);
 
-/*
- *     Private data
- */
-
-static struct w9966_dev w9966_cams[W9966_MAXCAMS];
-
-/*
- *     Private function declares
- */
-
-static inline void w9966_setState(struct w9966_dev* cam, int mask, int val);
-static inline int  w9966_getState(struct w9966_dev* cam, int mask, int val);
-static inline void w9966_pdev_claim(struct w9966_dev *vdev);
-static inline void w9966_pdev_release(struct w9966_dev *vdev);
-
-static int w9966_rReg(struct w9966_dev* cam, int reg);
-static int w9966_wReg(struct w9966_dev* cam, int reg, int data);
-#if 0
-static int w9966_rReg_i2c(struct w9966_dev* cam, int reg);
-#endif
-static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data);
-static int w9966_findlen(int near, int size, int maxlen);
-static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor);
-static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, int w, int h);
-
-static int  w9966_init(struct w9966_dev* cam, struct parport* port);
-static void w9966_term(struct w9966_dev* cam);
-
-static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state);
-static inline int  w9966_i2c_setscl(struct w9966_dev* cam, int state);
-static inline int  w9966_i2c_getsda(struct w9966_dev* cam);
-static inline int  w9966_i2c_getscl(struct w9966_dev* cam);
-static int w9966_i2c_wbyte(struct w9966_dev* cam, int data);
-#if 0
-static int w9966_i2c_rbyte(struct w9966_dev* cam);
-#endif
-
-static long w9966_v4l_ioctl(struct file *file,
-                          unsigned int cmd, unsigned long arg);
-static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
-                             size_t count, loff_t *ppos);
-
-static int w9966_exclusive_open(struct file *file)
-{
-       struct w9966_dev *cam = video_drvdata(file);
-
-       return test_and_set_bit(0, &cam->in_use) ? -EBUSY : 0;
-}
-
-static int w9966_exclusive_release(struct file *file)
-{
-       struct w9966_dev *cam = video_drvdata(file);
-
-       clear_bit(0, &cam->in_use);
-       return 0;
-}
-
-static const struct v4l2_file_operations w9966_fops = {
-       .owner          = THIS_MODULE,
-       .open           = w9966_exclusive_open,
-       .release        = w9966_exclusive_release,
-       .ioctl          = w9966_v4l_ioctl,
-       .read           = w9966_v4l_read,
-};
-static struct video_device w9966_template = {
-       .name           = W9966_DRIVERNAME,
-       .fops           = &w9966_fops,
-       .release        = video_device_release_empty,
-};
+static struct w9966 w9966_cams[W9966_MAXCAMS];
 
 /*
  *     Private function defines
  */
 
 
-// Set camera phase flags, so we know what to uninit when terminating
-static inline void w9966_setState(struct w9966_dev* cam, int mask, int val)
+/* Set camera phase flags, so we know what to uninit when terminating */
+static inline void w9966_set_state(struct w9966 *cam, int mask, int val)
 {
        cam->dev_state = (cam->dev_state & ~mask) ^ val;
 }
 
-// Get camera phase flags
-static inline int w9966_getState(struct w9966_dev* cam, int mask, int val)
+/* Get camera phase flags */
+static inline int w9966_get_state(struct w9966 *cam, int mask, int val)
 {
        return ((cam->dev_state & mask) == val);
 }
 
-// Claim parport for ourself
-static inline void w9966_pdev_claim(struct w9966_dev* cam)
+/* Claim parport for ourself */
+static void w9966_pdev_claim(struct w9966 *cam)
 {
-       if (w9966_getState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED))
+       if (w9966_get_state(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED))
                return;
        parport_claim_or_block(cam->pdev);
-       w9966_setState(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED);
+       w9966_set_state(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED);
 }
 
-// Release parport for others to use
-static inline void w9966_pdev_release(struct w9966_dev* cam)
+/* Release parport for others to use */
+static void w9966_pdev_release(struct w9966 *cam)
 {
-       if (w9966_getState(cam, W9966_STATE_CLAIMED, 0))
+       if (w9966_get_state(cam, W9966_STATE_CLAIMED, 0))
                return;
        parport_release(cam->pdev);
-       w9966_setState(cam, W9966_STATE_CLAIMED, 0);
+       w9966_set_state(cam, W9966_STATE_CLAIMED, 0);
 }
 
-// Read register from W9966 interface-chip
-// Expects a claimed pdev
-// -1 on error, else register data (byte)
-static int w9966_rReg(struct w9966_dev* cam, int reg)
+/* Read register from W9966 interface-chip
+   Expects a claimed pdev
+   -1 on error, else register data (byte) */
+static int w9966_read_reg(struct w9966 *cam, int reg)
 {
-       // ECP, read, regtransfer, REG, REG, REG, REG, REG
+       /* ECP, read, regtransfer, REG, REG, REG, REG, REG */
        const unsigned char addr = 0x80 | (reg & 0x1f);
        unsigned char val;
 
@@ -270,12 +205,12 @@ static int w9966_rReg(struct w9966_dev* cam, int reg)
        return val;
 }
 
-// Write register to W9966 interface-chip
-// Expects a claimed pdev
-// -1 on error
-static int w9966_wReg(struct w9966_dev* cam, int reg, int data)
+/* Write register to W9966 interface-chip
+   Expects a claimed pdev
+   -1 on error */
+static int w9966_write_reg(struct w9966 *cam, int reg, int data)
 {
-       // ECP, write, regtransfer, REG, REG, REG, REG, REG
+       /* ECP, write, regtransfer, REG, REG, REG, REG, REG */
        const unsigned char addr = 0xc0 | (reg & 0x1f);
        const unsigned char val = data;
 
@@ -291,119 +226,186 @@ static int w9966_wReg(struct w9966_dev* cam, int reg, int data)
        return 0;
 }
 
-// Initialize camera device. Setup all internal flags, set a
-// default video mode, setup ccd-chip, register v4l device etc..
-// Also used for 'probing' of hardware.
-// -1 on error
-static int w9966_init(struct w9966_dev* cam, struct parport* port)
+/*
+ *     Ugly and primitive i2c protocol functions
+ */
+
+/* Sets the data line on the i2c bus.
+   Expects a claimed pdev. */
+static void w9966_i2c_setsda(struct w9966 *cam, int state)
 {
-       if (cam->dev_state != 0)
-               return -1;
+       if (state)
+               cam->i2c_state |= W9966_I2C_W_DATA;
+       else
+               cam->i2c_state &= ~W9966_I2C_W_DATA;
 
-       cam->pport = port;
-       cam->brightness = 128;
-       cam->contrast = 64;
-       cam->color = 64;
-       cam->hue = 0;
+       w9966_write_reg(cam, 0x18, cam->i2c_state);
+       udelay(5);
+}
 
-// Select requested transfer mode
-       switch(parmode)
-       {
-       default:        // Auto-detect (priority: hw-ecp, hw-epp, sw-ecp)
-       case 0:
-               if (port->modes & PARPORT_MODE_ECP)
-                       cam->ppmode = IEEE1284_MODE_ECP;
-               else if (port->modes & PARPORT_MODE_EPP)
-                       cam->ppmode = IEEE1284_MODE_EPP;
-               else
-                       cam->ppmode = IEEE1284_MODE_ECP;
-               break;
-       case 1:         // hw- or sw-ecp
-               cam->ppmode = IEEE1284_MODE_ECP;
-               break;
-       case 2:         // hw- or sw-epp
-               cam->ppmode = IEEE1284_MODE_EPP;
-       break;
+/* Get peripheral clock line
+   Expects a claimed pdev. */
+static int w9966_i2c_getscl(struct w9966 *cam)
+{
+       const unsigned char state = w9966_read_reg(cam, 0x18);
+       return ((state & W9966_I2C_R_CLOCK) > 0);
+}
+
+/* Sets the clock line on the i2c bus.
+   Expects a claimed pdev. -1 on error */
+static int w9966_i2c_setscl(struct w9966 *cam, int state)
+{
+       unsigned long timeout;
+
+       if (state)
+               cam->i2c_state |= W9966_I2C_W_CLOCK;
+       else
+               cam->i2c_state &= ~W9966_I2C_W_CLOCK;
+
+       w9966_write_reg(cam, 0x18, cam->i2c_state);
+       udelay(5);
+
+       /* we go to high, we also expect the peripheral to ack. */
+       if (state) {
+               timeout = jiffies + 100;
+               while (!w9966_i2c_getscl(cam)) {
+                       if (time_after(jiffies, timeout))
+                               return -1;
+               }
        }
+       return 0;
+}
 
-// Tell the parport driver that we exists
-       cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL);
-       if (cam->pdev == NULL) {
-               DPRINTF("parport_register_device() failed\n");
-               return -1;
+#if 0
+/* Get peripheral data line
+   Expects a claimed pdev. */
+static int w9966_i2c_getsda(struct w9966 *cam)
+{
+       const unsigned char state = w9966_read_reg(cam, 0x18);
+       return ((state & W9966_I2C_R_DATA) > 0);
+}
+#endif
+
+/* Write a byte with ack to the i2c bus.
+   Expects a claimed pdev. -1 on error */
+static int w9966_i2c_wbyte(struct w9966 *cam, int data)
+{
+       int i;
+
+       for (i = 7; i >= 0; i--) {
+               w9966_i2c_setsda(cam, (data >> i) & 0x01);
+
+               if (w9966_i2c_setscl(cam, 1) == -1)
+                       return -1;
+               w9966_i2c_setscl(cam, 0);
        }
-       w9966_setState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
 
-       w9966_pdev_claim(cam);
+       w9966_i2c_setsda(cam, 1);
 
-// Setup a default capture mode
-       if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
-               DPRINTF("w9966_setup() failed.\n");
+       if (w9966_i2c_setscl(cam, 1) == -1)
                return -1;
+       w9966_i2c_setscl(cam, 0);
+
+       return 0;
+}
+
+/* Read a data byte with ack from the i2c-bus
+   Expects a claimed pdev. -1 on error */
+#if 0
+static int w9966_i2c_rbyte(struct w9966 *cam)
+{
+       unsigned char data = 0x00;
+       int i;
+
+       w9966_i2c_setsda(cam, 1);
+
+       for (i = 0; i < 8; i++) {
+               if (w9966_i2c_setscl(cam, 1) == -1)
+                       return -1;
+               data = data << 1;
+               if (w9966_i2c_getsda(cam))
+                       data |= 0x01;
+
+               w9966_i2c_setscl(cam, 0);
        }
+       return data;
+}
+#endif
 
-       w9966_pdev_release(cam);
+/* Read a register from the i2c device.
+   Expects claimed pdev. -1 on error */
+#if 0
+static int w9966_read_reg_i2c(struct w9966 *cam, int reg)
+{
+       int data;
 
-// Fill in the video_device struct and register us to v4l
-       memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
-       video_set_drvdata(&cam->vdev, cam);
+       w9966_i2c_setsda(cam, 0);
+       w9966_i2c_setscl(cam, 0);
 
-       if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
+       if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
+           w9966_i2c_wbyte(cam, reg) == -1)
+               return -1;
+
+       w9966_i2c_setsda(cam, 1);
+       if (w9966_i2c_setscl(cam, 1) == -1)
                return -1;
+       w9966_i2c_setsda(cam, 0);
+       w9966_i2c_setscl(cam, 0);
 
-       w9966_setState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
+       if (w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1)
+               return -1;
+       data = w9966_i2c_rbyte(cam);
+       if (data == -1)
+               return -1;
 
-       // All ok
-       printk(
-               "w9966cf: Found and initialized a webcam on %s.\n",
-               cam->pport->name
-       );
-       return 0;
-}
+       w9966_i2c_setsda(cam, 0);
 
+       if (w9966_i2c_setscl(cam, 1) == -1)
+               return -1;
+       w9966_i2c_setsda(cam, 1);
 
-// Terminate everything gracefully
-static void w9966_term(struct w9966_dev* cam)
+       return data;
+}
+#endif
+
+/* Write a register to the i2c device.
+   Expects claimed pdev. -1 on error */
+static int w9966_write_reg_i2c(struct w9966 *cam, int reg, int data)
 {
-// Unregister from v4l
-       if (w9966_getState(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) {
-               video_unregister_device(&cam->vdev);
-               w9966_setState(cam, W9966_STATE_VDEV, 0);
-       }
+       w9966_i2c_setsda(cam, 0);
+       w9966_i2c_setscl(cam, 0);
 
-// Terminate from IEEE1284 mode and release pdev block
-       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
-               w9966_pdev_claim(cam);
-               parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT);
-               w9966_pdev_release(cam);
-       }
+       if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
+                       w9966_i2c_wbyte(cam, reg) == -1 ||
+                       w9966_i2c_wbyte(cam, data) == -1)
+               return -1;
 
-// Unregister from parport
-       if (w9966_getState(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
-               parport_unregister_device(cam->pdev);
-               w9966_setState(cam, W9966_STATE_PDEV, 0);
-       }
-}
+       w9966_i2c_setsda(cam, 0);
+       if (w9966_i2c_setscl(cam, 1) == -1)
+               return -1;
+
+       w9966_i2c_setsda(cam, 1);
 
+       return 0;
+}
 
-// Find a good length for capture window (used both for W and H)
-// A bit ugly but pretty functional. The capture length
-// have to match the downscale
+/* Find a good length for capture window (used both for W and H)
+   A bit ugly but pretty functional. The capture length
+   have to match the downscale */
 static int w9966_findlen(int near, int size, int maxlen)
 {
        int bestlen = size;
        int besterr = abs(near - bestlen);
        int len;
 
-       for(len = size+1;len < maxlen;len++)
-       {
+       for (len = size + 1; len < maxlen; len++) {
                int err;
-               if ( ((64*size) %len) != 0)
+               if (((64 * size) % len) != 0)
                        continue;
 
                err = abs(near - len);
 
-               // Only continue as long as we keep getting better values
+               /* Only continue as long as we keep getting better values */
                if (err > besterr)
                        break;
 
@@ -414,32 +416,32 @@ static int w9966_findlen(int near, int size, int maxlen)
        return bestlen;
 }
 
-// Modify capture window (if necessary)
-// and calculate downscaling
-// Return -1 on error
-static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsigned char* factor)
+/* Modify capture window (if necessary)
+   and calculate downscaling
+   Return -1 on error */
+static int w9966_calcscale(int size, int min, int max, int *beg, int *end, unsigned char *factor)
 {
        int maxlen = max - min;
        int len = *end - *beg + 1;
        int newlen = w9966_findlen(len, size, maxlen);
        int err = newlen - len;
 
-       // Check for bad format
+       /* Check for bad format */
        if (newlen > maxlen || newlen < size)
                return -1;
 
-       // Set factor (6 bit fixed)
-       *factor = (64*size) / newlen;
+       /* Set factor (6 bit fixed) */
+       *factor = (64 * size) / newlen;
        if (*factor == 64)
-               *factor = 0x00; // downscale is disabled
+               *factor = 0x00; /* downscale is disabled */
        else
-               *factor |= 0x80; // set downscale-enable bit
+               *factor |= 0x80; /* set downscale-enable bit */
 
-       // Modify old beginning and end
+       /* Modify old beginning and end */
        *beg -= err / 2;
        *end += err - (err / 2);
 
-       // Move window if outside borders
+       /* Move window if outside borders */
        if (*beg < min) {
                *end += min - *beg;
                *beg += min - *beg;
@@ -452,10 +454,10 @@ static int w9966_calcscale(int size, int min, int max, int* beg, int* end, unsig
        return 0;
 }
 
-// Setup the cameras capture window etc.
-// Expects a claimed pdev
-// return -1 on error
-static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, int w, int h)
+/* Setup the cameras capture window etc.
+   Expects a claimed pdev
+   return -1 on error */
+static int w9966_setup(struct w9966 *cam, int x1, int y1, int x2, int y2, int w, int h)
 {
        unsigned int i;
        unsigned int enh_s, enh_e;
@@ -469,443 +471,314 @@ static int w9966_setup(struct w9966_dev* cam, int x1, int y1, int x2, int y2, in
        };
 
 
-       if (w*h*2 > W9966_SRAMSIZE)
-       {
+       if (w * h * 2 > W9966_SRAMSIZE) {
                DPRINTF("capture window exceeds SRAM size!.\n");
-               w = 200; h = 160;       // Pick default values
+               w = 200; h = 160;       /* Pick default values */
        }
 
        w &= ~0x1;
-       if (w < 2) w = 2;
-       if (h < 1) h = 1;
-       if (w > W9966_WND_MAX_W) w = W9966_WND_MAX_W;
-       if (h > W9966_WND_MAX_H) h = W9966_WND_MAX_H;
+       if (w < 2)
+               w = 2;
+       if (h < 1)
+               h = 1;
+       if (w > W9966_WND_MAX_W)
+               w = W9966_WND_MAX_W;
+       if (h > W9966_WND_MAX_H)
+               h = W9966_WND_MAX_H;
 
        cam->width = w;
        cam->height = h;
 
        enh_s = 0;
-       enh_e = w*h*2;
-
-// Modify capture window if necessary and calculate downscaling
-       if (
-               w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 ||
-               w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, &scale_y) != 0
-       ) return -1;
-
-       DPRINTF(
-               "%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
-               w, h, x1, x2, y1, y2, scale_x&~0x80, scale_y&~0x80
-       );
-
-// Setup registers
-       regs[0x00] = 0x00;                      // Set normal operation
-       regs[0x01] = 0x18;                      // Capture mode
-       regs[0x02] = scale_y;                   // V-scaling
-       regs[0x03] = scale_x;                   // H-scaling
-
-       // Capture window
-       regs[0x04] = (x1 & 0x0ff);              // X-start (8 low bits)
-       regs[0x05] = (x1 & 0x300)>>8;           // X-start (2 high bits)
-       regs[0x06] = (y1 & 0x0ff);              // Y-start (8 low bits)
-       regs[0x07] = (y1 & 0x300)>>8;           // Y-start (2 high bits)
-       regs[0x08] = (x2 & 0x0ff);              // X-end (8 low bits)
-       regs[0x09] = (x2 & 0x300)>>8;           // X-end (2 high bits)
-       regs[0x0a] = (y2 & 0x0ff);              // Y-end (8 low bits)
-
-       regs[0x0c] = W9966_SRAMID;              // SRAM-banks (1x 128kb)
-
-       // Enhancement layer
-       regs[0x0d] = (enh_s& 0x000ff);          // Enh. start (0-7)
-       regs[0x0e] = (enh_s& 0x0ff00)>>8;       // Enh. start (8-15)
-       regs[0x0f] = (enh_s& 0x70000)>>16;      // Enh. start (16-17/18??)
-       regs[0x10] = (enh_e& 0x000ff);          // Enh. end (0-7)
-       regs[0x11] = (enh_e& 0x0ff00)>>8;       // Enh. end (8-15)
-       regs[0x12] = (enh_e& 0x70000)>>16;      // Enh. end (16-17/18??)
-
-       // Misc
-       regs[0x13] = 0x40;                      // VEE control (raw 4:2:2)
-       regs[0x17] = 0x00;                      // ???
-       regs[0x18] = cam->i2c_state = 0x00;     // Serial bus
-       regs[0x19] = 0xff;                      // I/O port direction control
-       regs[0x1a] = 0xff;                      // I/O port data register
-       regs[0x1b] = 0x10;                      // ???
-
-       // SAA7111 chip settings
+       enh_e = w * h * 2;
+
+       /* Modify capture window if necessary and calculate downscaling */
+       if (w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 ||
+                       w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, &scale_y) != 0)
+               return -1;
+
+       DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
+                       w, h, x1, x2, y1, y2, scale_x & ~0x80, scale_y & ~0x80);
+
+       /* Setup registers */
+       regs[0x00] = 0x00;                      /* Set normal operation */
+       regs[0x01] = 0x18;                      /* Capture mode */
+       regs[0x02] = scale_y;                   /* V-scaling */
+       regs[0x03] = scale_x;                   /* H-scaling */
+
+       /* Capture window */
+       regs[0x04] = (x1 & 0x0ff);              /* X-start (8 low bits) */
+       regs[0x05] = (x1 & 0x300)>>8;           /* X-start (2 high bits) */
+       regs[0x06] = (y1 & 0x0ff);              /* Y-start (8 low bits) */
+       regs[0x07] = (y1 & 0x300)>>8;           /* Y-start (2 high bits) */
+       regs[0x08] = (x2 & 0x0ff);              /* X-end (8 low bits) */
+       regs[0x09] = (x2 & 0x300)>>8;           /* X-end (2 high bits) */
+       regs[0x0a] = (y2 & 0x0ff);              /* Y-end (8 low bits) */
+
+       regs[0x0c] = W9966_SRAMID;              /* SRAM-banks (1x 128kb) */
+
+       /* Enhancement layer */
+       regs[0x0d] = (enh_s & 0x000ff);         /* Enh. start (0-7) */
+       regs[0x0e] = (enh_s & 0x0ff00) >> 8;    /* Enh. start (8-15) */
+       regs[0x0f] = (enh_s & 0x70000) >> 16;   /* Enh. start (16-17/18??) */
+       regs[0x10] = (enh_e & 0x000ff);         /* Enh. end (0-7) */
+       regs[0x11] = (enh_e & 0x0ff00) >> 8;    /* Enh. end (8-15) */
+       regs[0x12] = (enh_e & 0x70000) >> 16;   /* Enh. end (16-17/18??) */
+
+       /* Misc */
+       regs[0x13] = 0x40;                      /* VEE control (raw 4:2:2) */
+       regs[0x17] = 0x00;                      /* ??? */
+       regs[0x18] = cam->i2c_state = 0x00;     /* Serial bus */
+       regs[0x19] = 0xff;                      /* I/O port direction control */
+       regs[0x1a] = 0xff;                      /* I/O port data register */
+       regs[0x1b] = 0x10;                      /* ??? */
+
+       /* SAA7111 chip settings */
        saa7111_regs[0x0a] = cam->brightness;
        saa7111_regs[0x0b] = cam->contrast;
        saa7111_regs[0x0c] = cam->color;
        saa7111_regs[0x0d] = cam->hue;
 
-// Reset (ECP-fifo & serial-bus)
-       if (w9966_wReg(cam, 0x00, 0x03) == -1)
+       /* Reset (ECP-fifo & serial-bus) */
+       if (w9966_write_reg(cam, 0x00, 0x03) == -1)
                return -1;
 
-// Write regs to w9966cf chip
+       /* Write regs to w9966cf chip */
        for (i = 0; i < 0x1c; i++)
-               if (w9966_wReg(cam, i, regs[i]) == -1)
+               if (w9966_write_reg(cam, i, regs[i]) == -1)
                        return -1;
 
-// Write regs to saa7111 chip
+       /* Write regs to saa7111 chip */
        for (i = 0; i < 0x20; i++)
-               if (w9966_wReg_i2c(cam, i, saa7111_regs[i]) == -1)
+               if (w9966_write_reg_i2c(cam, i, saa7111_regs[i]) == -1)
                        return -1;
 
        return 0;
 }
 
 /*
- *     Ugly and primitive i2c protocol functions
+ *     Video4linux interfacing
  */
 
-// Sets the data line on the i2c bus.
-// Expects a claimed pdev.
-static inline void w9966_i2c_setsda(struct w9966_dev* cam, int state)
+static int cam_querycap(struct file *file, void  *priv,
+                                       struct v4l2_capability *vcap)
 {
-       if (state)
-               cam->i2c_state |= W9966_I2C_W_DATA;
-       else
-               cam->i2c_state &= ~W9966_I2C_W_DATA;
+       struct w9966 *cam = video_drvdata(file);
 
-       w9966_wReg(cam, 0x18, cam->i2c_state);
-       udelay(5);
+       strlcpy(vcap->driver, cam->v4l2_dev.name, sizeof(vcap->driver));
+       strlcpy(vcap->card, W9966_DRIVERNAME, sizeof(vcap->card));
+       strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info));
+       vcap->version = KERNEL_VERSION(0, 33, 0);
+       vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
+       return 0;
 }
 
-// Get peripheral clock line
-// Expects a claimed pdev.
-static inline int w9966_i2c_getscl(struct w9966_dev* cam)
+static int cam_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
 {
-       const unsigned char state = w9966_rReg(cam, 0x18);
-       return ((state & W9966_I2C_R_CLOCK) > 0);
+       if (vin->index > 0)
+               return -EINVAL;
+       strlcpy(vin->name, "Camera", sizeof(vin->name));
+       vin->type = V4L2_INPUT_TYPE_CAMERA;
+       vin->audioset = 0;
+       vin->tuner = 0;
+       vin->std = 0;
+       vin->status = 0;
+       return 0;
 }
 
-// Sets the clock line on the i2c bus.
-// Expects a claimed pdev. -1 on error
-static inline int w9966_i2c_setscl(struct w9966_dev* cam, int state)
+static int cam_g_input(struct file *file, void *fh, unsigned int *inp)
 {
-       unsigned long timeout;
-
-       if (state)
-               cam->i2c_state |= W9966_I2C_W_CLOCK;
-       else
-               cam->i2c_state &= ~W9966_I2C_W_CLOCK;
-
-       w9966_wReg(cam, 0x18, cam->i2c_state);
-       udelay(5);
-
-       // we go to high, we also expect the peripheral to ack.
-       if (state) {
-               timeout = jiffies + 100;
-               while (!w9966_i2c_getscl(cam)) {
-                       if (time_after(jiffies, timeout))
-                               return -1;
-               }
-       }
+       *inp = 0;
        return 0;
 }
 
-// Get peripheral data line
-// Expects a claimed pdev.
-static inline int w9966_i2c_getsda(struct w9966_dev* cam)
+static int cam_s_input(struct file *file, void *fh, unsigned int inp)
 {
-       const unsigned char state = w9966_rReg(cam, 0x18);
-       return ((state & W9966_I2C_R_DATA) > 0);
+       return (inp > 0) ? -EINVAL : 0;
 }
 
-// Write a byte with ack to the i2c bus.
-// Expects a claimed pdev. -1 on error
-static int w9966_i2c_wbyte(struct w9966_dev* cam, int data)
+static int cam_queryctrl(struct file *file, void *priv,
+                                       struct v4l2_queryctrl *qc)
 {
-       int i;
-       for (i = 7; i >= 0; i--)
-       {
-               w9966_i2c_setsda(cam, (data >> i) & 0x01);
-
-               if (w9966_i2c_setscl(cam, 1) == -1)
-                       return -1;
-               w9966_i2c_setscl(cam, 0);
+       switch (qc->id) {
+       case V4L2_CID_BRIGHTNESS:
+               return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128);
+       case V4L2_CID_CONTRAST:
+               return v4l2_ctrl_query_fill(qc, -64, 64, 1, 64);
+       case V4L2_CID_SATURATION:
+               return v4l2_ctrl_query_fill(qc, -64, 64, 1, 64);
+       case V4L2_CID_HUE:
+               return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0);
        }
-
-       w9966_i2c_setsda(cam, 1);
-
-       if (w9966_i2c_setscl(cam, 1) == -1)
-               return -1;
-       w9966_i2c_setscl(cam, 0);
-
-       return 0;
+       return -EINVAL;
 }
 
-// Read a data byte with ack from the i2c-bus
-// Expects a claimed pdev. -1 on error
-#if 0
-static int w9966_i2c_rbyte(struct w9966_dev* cam)
+static int cam_g_ctrl(struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
 {
-       unsigned char data = 0x00;
-       int i;
-
-       w9966_i2c_setsda(cam, 1);
+       struct w9966 *cam = video_drvdata(file);
+       int ret = 0;
 
-       for (i = 0; i < 8; i++)
-       {
-               if (w9966_i2c_setscl(cam, 1) == -1)
-                       return -1;
-               data = data << 1;
-               if (w9966_i2c_getsda(cam))
-                       data |= 0x01;
-
-               w9966_i2c_setscl(cam, 0);
+       switch (ctrl->id) {
+       case V4L2_CID_BRIGHTNESS:
+               ctrl->value = cam->brightness;
+               break;
+       case V4L2_CID_CONTRAST:
+               ctrl->value = cam->contrast;
+               break;
+       case V4L2_CID_SATURATION:
+               ctrl->value = cam->color;
+               break;
+       case V4L2_CID_HUE:
+               ctrl->value = cam->hue;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
        }
-       return data;
+       return ret;
 }
-#endif
 
-// Read a register from the i2c device.
-// Expects claimed pdev. -1 on error
-#if 0
-static int w9966_rReg_i2c(struct w9966_dev* cam, int reg)
+static int cam_s_ctrl(struct file *file, void *priv,
+                                       struct v4l2_control *ctrl)
 {
-       int data;
-
-       w9966_i2c_setsda(cam, 0);
-       w9966_i2c_setscl(cam, 0);
-
-       if (
-               w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
-               w9966_i2c_wbyte(cam, reg) == -1
-       )
-               return -1;
-
-       w9966_i2c_setsda(cam, 1);
-       if (w9966_i2c_setscl(cam, 1) == -1)
-               return -1;
-       w9966_i2c_setsda(cam, 0);
-       w9966_i2c_setscl(cam, 0);
+       struct w9966 *cam = video_drvdata(file);
+       int ret = 0;
 
-       if (
-               w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1 ||
-               (data = w9966_i2c_rbyte(cam)) == -1
-       )
-               return -1;
+       mutex_lock(&cam->lock);
+       switch (ctrl->id) {
+       case V4L2_CID_BRIGHTNESS:
+               cam->brightness = ctrl->value;
+               break;
+       case V4L2_CID_CONTRAST:
+               cam->contrast = ctrl->value;
+               break;
+       case V4L2_CID_SATURATION:
+               cam->color = ctrl->value;
+               break;
+       case V4L2_CID_HUE:
+               cam->hue = ctrl->value;
+               break;
+       default:
+               ret = -EINVAL;
+               break;
+       }
 
-       w9966_i2c_setsda(cam, 0);
+       if (ret == 0) {
+               w9966_pdev_claim(cam);
 
-       if (w9966_i2c_setscl(cam, 1) == -1)
-               return -1;
-       w9966_i2c_setsda(cam, 1);
+               if (w9966_write_reg_i2c(cam, 0x0a, cam->brightness) == -1 ||
+                   w9966_write_reg_i2c(cam, 0x0b, cam->contrast) == -1 ||
+                   w9966_write_reg_i2c(cam, 0x0c, cam->color) == -1 ||
+                   w9966_write_reg_i2c(cam, 0x0d, cam->hue) == -1) {
+                       ret = -EIO;
+               }
 
-       return data;
+               w9966_pdev_release(cam);
+       }
+       mutex_unlock(&cam->lock);
+       return ret;
 }
-#endif
 
-// Write a register to the i2c device.
-// Expects claimed pdev. -1 on error
-static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data)
+static int cam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
 {
-       w9966_i2c_setsda(cam, 0);
-       w9966_i2c_setscl(cam, 0);
-
-       if (
-               w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
-               w9966_i2c_wbyte(cam, reg) == -1 ||
-               w9966_i2c_wbyte(cam, data) == -1
-       )
-               return -1;
-
-       w9966_i2c_setsda(cam, 0);
-       if (w9966_i2c_setscl(cam, 1) == -1)
-               return -1;
-
-       w9966_i2c_setsda(cam, 1);
-
+       struct w9966 *cam = video_drvdata(file);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+
+       pix->width = cam->width;
+       pix->height = cam->height;
+       pix->pixelformat = V4L2_PIX_FMT_YUYV;
+       pix->field = V4L2_FIELD_NONE;
+       pix->bytesperline = 2 * cam->width;
+       pix->sizeimage = 2 * cam->width * cam->height;
+       /* Just a guess */
+       pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
        return 0;
 }
 
-/*
- *     Video4linux interfacing
- */
-
-static long w9966_v4l_do_ioctl(struct file *file, unsigned int cmd, void *arg)
-{
-       struct w9966_dev *cam = video_drvdata(file);
-
-       switch(cmd)
-       {
-       case VIDIOCGCAP:
-       {
-               static struct video_capability vcap = {
-                       .name      = W9966_DRIVERNAME,
-                       .type      = VID_TYPE_CAPTURE | VID_TYPE_SCALES,
-                       .channels  = 1,
-                       .maxwidth  = W9966_WND_MAX_W,
-                       .maxheight = W9966_WND_MAX_H,
-                       .minwidth  = 2,
-                       .minheight = 1,
-               };
-               struct video_capability *cap = arg;
-               *cap = vcap;
-               return 0;
-       }
-       case VIDIOCGCHAN:
-       {
-               struct video_channel *vch = arg;
-               if(vch->channel != 0)   // We only support one channel (#0)
-                       return -EINVAL;
-               memset(vch,0,sizeof(*vch));
-               strcpy(vch->name, "CCD-input");
-               vch->type = VIDEO_TYPE_CAMERA;
-               return 0;
-       }
-       case VIDIOCSCHAN:
-       {
-               struct video_channel *vch = arg;
-               if(vch->channel != 0)
-                       return -EINVAL;
-               return 0;
-       }
-       case VIDIOCGTUNER:
-       {
-               struct video_tuner *vtune = arg;
-               if(vtune->tuner != 0)
-                       return -EINVAL;
-               strcpy(vtune->name, "no tuner");
-               vtune->rangelow = 0;
-               vtune->rangehigh = 0;
-               vtune->flags = VIDEO_TUNER_NORM;
-               vtune->mode = VIDEO_MODE_AUTO;
-               vtune->signal = 0xffff;
-               return 0;
-       }
-       case VIDIOCSTUNER:
-       {
-               struct video_tuner *vtune = arg;
-               if (vtune->tuner != 0)
-                       return -EINVAL;
-               if (vtune->mode != VIDEO_MODE_AUTO)
-                       return -EINVAL;
-               return 0;
-       }
-       case VIDIOCGPICT:
-       {
-               struct video_picture vpic = {
-                       cam->brightness << 8,   // brightness
-                       (cam->hue + 128) << 8,  // hue
-                       cam->color << 9,        // color
-                       cam->contrast << 9,     // contrast
-                       0x8000,                 // whiteness
-                       16, VIDEO_PALETTE_YUV422// bpp, palette format
-               };
-               struct video_picture *pic = arg;
-               *pic = vpic;
-               return 0;
-       }
-       case VIDIOCSPICT:
-       {
-               struct video_picture *vpic = arg;
-               if (vpic->depth != 16 || (vpic->palette != VIDEO_PALETTE_YUV422 && vpic->palette != VIDEO_PALETTE_YUYV))
-                       return -EINVAL;
-
-               cam->brightness = vpic->brightness >> 8;
-               cam->hue = (vpic->hue >> 8) - 128;
-               cam->color = vpic->colour >> 9;
-               cam->contrast = vpic->contrast >> 9;
+static int cam_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+
+       if (pix->width < 2)
+               pix->width = 2;
+       if (pix->height < 1)
+               pix->height = 1;
+       if (pix->width > W9966_WND_MAX_W)
+               pix->width = W9966_WND_MAX_W;
+       if (pix->height > W9966_WND_MAX_H)
+               pix->height = W9966_WND_MAX_H;
+       pix->pixelformat = V4L2_PIX_FMT_YUYV;
+       pix->field = V4L2_FIELD_NONE;
+       pix->bytesperline = 2 * pix->width;
+       pix->sizeimage = 2 * pix->width * pix->height;
+       /* Just a guess */
+       pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
+       return 0;
+}
 
-               w9966_pdev_claim(cam);
+static int cam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
+{
+       struct w9966 *cam = video_drvdata(file);
+       struct v4l2_pix_format *pix = &fmt->fmt.pix;
+       int ret = cam_try_fmt_vid_cap(file, fh, fmt);
 
-               if (
-                       w9966_wReg_i2c(cam, 0x0a, cam->brightness) == -1 ||
-                       w9966_wReg_i2c(cam, 0x0b, cam->contrast) == -1 ||
-                       w9966_wReg_i2c(cam, 0x0c, cam->color) == -1 ||
-                       w9966_wReg_i2c(cam, 0x0d, cam->hue) == -1
-               ) {
-                       w9966_pdev_release(cam);
-                       return -EIO;
-               }
+       if (ret)
+               return ret;
 
-               w9966_pdev_release(cam);
-               return 0;
-       }
-       case VIDIOCSWIN:
-       {
-               int ret;
-               struct video_window *vwin = arg;
-
-               if (vwin->flags != 0)
-                       return -EINVAL;
-               if (vwin->clipcount != 0)
-                       return -EINVAL;
-               if (vwin->width < 2 || vwin->width > W9966_WND_MAX_W)
-                       return -EINVAL;
-               if (vwin->height < 1 || vwin->height > W9966_WND_MAX_H)
-                       return -EINVAL;
-
-               // Update camera regs
-               w9966_pdev_claim(cam);
-               ret = w9966_setup(cam, 0, 0, 1023, 1023, vwin->width, vwin->height);
-               w9966_pdev_release(cam);
+       mutex_lock(&cam->lock);
+       /* Update camera regs */
+       w9966_pdev_claim(cam);
+       ret = w9966_setup(cam, 0, 0, 1023, 1023, pix->width, pix->height);
+       w9966_pdev_release(cam);
+       mutex_unlock(&cam->lock);
+       return ret;
+}
 
-               if (ret != 0) {
-                       DPRINTF("VIDIOCSWIN: w9966_setup() failed.\n");
-                       return -EIO;
-               }
+static int cam_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
+{
+       static struct v4l2_fmtdesc formats[] = {
+               { 0, 0, 0,
+                 "YUV 4:2:2", V4L2_PIX_FMT_YUYV,
+                 { 0, 0, 0, 0 }
+               },
+       };
+       enum v4l2_buf_type type = fmt->type;
 
-               return 0;
-       }
-       case VIDIOCGWIN:
-       {
-               struct video_window *vwin = arg;
-               memset(vwin, 0, sizeof(*vwin));
-               vwin->width = cam->width;
-               vwin->height = cam->height;
-               return 0;
-       }
-       // Unimplemented
-       case VIDIOCCAPTURE:
-       case VIDIOCGFBUF:
-       case VIDIOCSFBUF:
-       case VIDIOCKEY:
-       case VIDIOCGFREQ:
-       case VIDIOCSFREQ:
-       case VIDIOCGAUDIO:
-       case VIDIOCSAUDIO:
+       if (fmt->index > 0)
                return -EINVAL;
-       default:
-               return -ENOIOCTLCMD;
-       }
-       return 0;
-}
 
-static long w9966_v4l_ioctl(struct file *file,
-                          unsigned int cmd, unsigned long arg)
-{
-       return video_usercopy(file, cmd, arg, w9966_v4l_do_ioctl);
+       *fmt = formats[fmt->index];
+       fmt->type = type;
+       return 0;
 }
 
-// Capture data
+/* Capture data */
 static ssize_t w9966_v4l_read(struct file *file, char  __user *buf,
-                             size_t count, loff_t *ppos)
+               size_t count, loff_t *ppos)
 {
-       struct w9966_dev *cam = video_drvdata(file);
-       unsigned char addr = 0xa0;      // ECP, read, CCD-transfer, 00000
+       struct w9966 *cam = video_drvdata(file);
+       unsigned char addr = 0xa0;      /* ECP, read, CCD-transfer, 00000 */
        unsigned char __user *dest = (unsigned char __user *)buf;
        unsigned long dleft = count;
        unsigned char *tbuf;
 
-       // Why would anyone want more than this??
+       /* Why would anyone want more than this?? */
        if (count > cam->width * cam->height * 2)
                return -EINVAL;
 
+       mutex_lock(&cam->lock);
        w9966_pdev_claim(cam);
-       w9966_wReg(cam, 0x00, 0x02);    // Reset ECP-FIFO buffer
-       w9966_wReg(cam, 0x00, 0x00);    // Return to normal operation
-       w9966_wReg(cam, 0x01, 0x98);    // Enable capture
-
-       // write special capture-addr and negotiate into data transfer
-       if (
-               (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0  )||
-               (parport_write(cam->pport, &addr, 1) != 1                                               )||
-               (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0  )
-       ) {
+       w9966_write_reg(cam, 0x00, 0x02);       /* Reset ECP-FIFO buffer */
+       w9966_write_reg(cam, 0x00, 0x00);       /* Return to normal operation */
+       w9966_write_reg(cam, 0x01, 0x98);       /* Enable capture */
+
+       /* write special capture-addr and negotiate into data transfer */
+       if ((parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0) ||
+                       (parport_write(cam->pport, &addr, 1) != 1) ||
+                       (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0)) {
                w9966_pdev_release(cam);
+               mutex_unlock(&cam->lock);
                return -EFAULT;
        }
 
@@ -915,8 +788,7 @@ static ssize_t w9966_v4l_read(struct file *file, char  __user *buf,
                goto out;
        }
 
-       while(dleft > 0)
-       {
+       while (dleft > 0) {
                unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft;
 
                if (parport_read(cam->pport, tbuf, tsize) < tsize) {
@@ -931,43 +803,167 @@ static ssize_t w9966_v4l_read(struct file *file, char  __user *buf,
                dleft -= tsize;
        }
 
-       w9966_wReg(cam, 0x01, 0x18);    // Disable capture
+       w9966_write_reg(cam, 0x01, 0x18);       /* Disable capture */
 
 out:
        kfree(tbuf);
        w9966_pdev_release(cam);
+       mutex_unlock(&cam->lock);
 
        return count;
 }
 
+static const struct v4l2_file_operations w9966_fops = {
+       .owner          = THIS_MODULE,
+       .ioctl          = video_ioctl2,
+       .read           = w9966_v4l_read,
+};
+
+static const struct v4l2_ioctl_ops w9966_ioctl_ops = {
+       .vidioc_querycap                    = cam_querycap,
+       .vidioc_g_input                     = cam_g_input,
+       .vidioc_s_input                     = cam_s_input,
+       .vidioc_enum_input                  = cam_enum_input,
+       .vidioc_queryctrl                   = cam_queryctrl,
+       .vidioc_g_ctrl                      = cam_g_ctrl,
+       .vidioc_s_ctrl                      = cam_s_ctrl,
+       .vidioc_enum_fmt_vid_cap            = cam_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap               = cam_g_fmt_vid_cap,
+       .vidioc_s_fmt_vid_cap               = cam_s_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap             = cam_try_fmt_vid_cap,
+};
+
 
-// Called once for every parport on init
+/* Initialize camera device. Setup all internal flags, set a
+   default video mode, setup ccd-chip, register v4l device etc..
+   Also used for 'probing' of hardware.
+   -1 on error */
+static int w9966_init(struct w9966 *cam, struct parport *port)
+{
+       struct v4l2_device *v4l2_dev = &cam->v4l2_dev;
+
+       if (cam->dev_state != 0)
+               return -1;
+
+       strlcpy(v4l2_dev->name, "w9966", sizeof(v4l2_dev->name));
+
+       if (v4l2_device_register(NULL, v4l2_dev) < 0) {
+               v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
+               return -1;
+       }
+       cam->pport = port;
+       cam->brightness = 128;
+       cam->contrast = 64;
+       cam->color = 64;
+       cam->hue = 0;
+
+       /* Select requested transfer mode */
+       switch (parmode) {
+       default:        /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */
+       case 0:
+               if (port->modes & PARPORT_MODE_ECP)
+                       cam->ppmode = IEEE1284_MODE_ECP;
+               else if (port->modes & PARPORT_MODE_EPP)
+                       cam->ppmode = IEEE1284_MODE_EPP;
+               else
+                       cam->ppmode = IEEE1284_MODE_ECP;
+               break;
+       case 1:         /* hw- or sw-ecp */
+               cam->ppmode = IEEE1284_MODE_ECP;
+               break;
+       case 2:         /* hw- or sw-epp */
+               cam->ppmode = IEEE1284_MODE_EPP;
+               break;
+       }
+
+       /* Tell the parport driver that we exists */
+       cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL);
+       if (cam->pdev == NULL) {
+               DPRINTF("parport_register_device() failed\n");
+               return -1;
+       }
+       w9966_set_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
+
+       w9966_pdev_claim(cam);
+
+       /* Setup a default capture mode */
+       if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
+               DPRINTF("w9966_setup() failed.\n");
+               return -1;
+       }
+
+       w9966_pdev_release(cam);
+
+       /* Fill in the video_device struct and register us to v4l */
+       strlcpy(cam->vdev.name, W9966_DRIVERNAME, sizeof(cam->vdev.name));
+       cam->vdev.v4l2_dev = v4l2_dev;
+       cam->vdev.fops = &w9966_fops;
+       cam->vdev.ioctl_ops = &w9966_ioctl_ops;
+       cam->vdev.release = video_device_release_empty;
+       video_set_drvdata(&cam->vdev, cam);
+
+       mutex_init(&cam->lock);
+
+       if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
+               return -1;
+
+       w9966_set_state(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
+
+       /* All ok */
+       v4l2_info(v4l2_dev, "Found and initialized a webcam on %s.\n",
+                       cam->pport->name);
+       return 0;
+}
+
+
+/* Terminate everything gracefully */
+static void w9966_term(struct w9966 *cam)
+{
+       /* Unregister from v4l */
+       if (w9966_get_state(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) {
+               video_unregister_device(&cam->vdev);
+               w9966_set_state(cam, W9966_STATE_VDEV, 0);
+       }
+
+       /* Terminate from IEEE1284 mode and release pdev block */
+       if (w9966_get_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
+               w9966_pdev_claim(cam);
+               parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT);
+               w9966_pdev_release(cam);
+       }
+
+       /* Unregister from parport */
+       if (w9966_get_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
+               parport_unregister_device(cam->pdev);
+               w9966_set_state(cam, W9966_STATE_PDEV, 0);
+       }
+}
+
+
+/* Called once for every parport on init */
 static void w9966_attach(struct parport *port)
 {
        int i;
 
-       for (i = 0; i < W9966_MAXCAMS; i++)
-       {
-               if (w9966_cams[i].dev_state != 0)       // Cam is already assigned
+       for (i = 0; i < W9966_MAXCAMS; i++) {
+               if (w9966_cams[i].dev_state != 0)       /* Cam is already assigned */
                        continue;
-               if (
-                       strcmp(pardev[i], "aggressive") == 0 ||
-                       strcmp(pardev[i], port->name) == 0
-               ) {
+               if (strcmp(pardev[i], "aggressive") == 0 || strcmp(pardev[i], port->name) == 0) {
                        if (w9966_init(&w9966_cams[i], port) != 0)
-                       w9966_term(&w9966_cams[i]);
-                       break;  // return
+                               w9966_term(&w9966_cams[i]);
+                       break;  /* return */
                }
        }
 }
 
-// Called once for every parport on termination
+/* Called once for every parport on termination */
 static void w9966_detach(struct parport *port)
 {
        int i;
+
        for (i = 0; i < W9966_MAXCAMS; i++)
-       if (w9966_cams[i].dev_state != 0 && w9966_cams[i].pport == port)
-               w9966_term(&w9966_cams[i]);
+               if (w9966_cams[i].dev_state != 0 && w9966_cams[i].pport == port)
+                       w9966_term(&w9966_cams[i]);
 }
 
 
@@ -977,17 +973,18 @@ static struct parport_driver w9966_ppd = {
        .detach = w9966_detach,
 };
 
-// Module entry point
+/* Module entry point */
 static int __init w9966_mod_init(void)
 {
        int i;
+
        for (i = 0; i < W9966_MAXCAMS; i++)
                w9966_cams[i].dev_state = 0;
 
        return parport_register_driver(&w9966_ppd);
 }
 
-// Module cleanup
+/* Module cleanup */
 static void __exit w9966_mod_term(void)
 {
        parport_unregister_driver(&w9966_ppd);
index e44e4b5..bb51cfb 100644 (file)
@@ -1153,7 +1153,7 @@ zc0301_vidioc_s_ctrl(struct zc0301_device* cam, void __user * arg)
        if (copy_from_user(&ctrl, arg, sizeof(ctrl)))
                return -EFAULT;
 
-       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++)
+       for (i = 0; i < ARRAY_SIZE(s->qctrl); i++) {
                if (ctrl.id == s->qctrl[i].id) {
                        if (s->qctrl[i].flags & V4L2_CTRL_FLAG_DISABLED)
                                return -EINVAL;
@@ -1163,7 +1163,9 @@ zc0301_vidioc_s_ctrl(struct zc0301_device* cam, void __user * arg)
                        ctrl.value -= ctrl.value % s->qctrl[i].step;
                        break;
                }
-
+       }
+       if (i == ARRAY_SIZE(s->qctrl))
+               return -EINVAL;
        if ((err = s->set_ctrl(cam, &ctrl)))
                return err;
 
index 3a408de..0be783c 100644 (file)
@@ -58,7 +58,7 @@ zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor);
        .idProduct = (prod),                                                  \
        .bInterfaceClass = (intclass)
 
-#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE
+#if !defined CONFIG_USB_GSPCA_ZC3XX && !defined CONFIG_USB_GSPCA_ZC3XX_MODULE
 #define ZC0301_ID_TABLE                                                       \
 static const struct usb_device_id zc0301_id_table[] =  {                      \
        { ZC0301_USB_DEVICE(0x046d, 0x08ae, 0xff), }, /* PAS202 */            \
index cb1de7e..8997add 100644 (file)
 
 #include <media/v4l2-device.h>
 
+#define ZORAN_VIDMODE_PAL      0
+#define ZORAN_VIDMODE_NTSC     1
+#define ZORAN_VIDMODE_SECAM    2
+
 struct zoran_requestbuffers {
        unsigned long count;    /* Number of buffers for MJPEG grabbing */
        unsigned long size;     /* Size PER BUFFER in bytes */
@@ -48,7 +52,7 @@ struct zoran_sync {
 struct zoran_status {
        int input;              /* Input channel, has to be set prior to BUZIOC_G_STATUS */
        int signal;             /* Returned: 1 if valid video signal detected */
-       int norm;               /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+       int norm;               /* Returned: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
        int color;              /* Returned: 1 if color signal detected */
 };
 
@@ -62,7 +66,7 @@ struct zoran_params {
        /* Main control parameters */
 
        int input;              /* Input channel: 0 = Composite, 1 = S-VHS */
-       int norm;               /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+       int norm;               /* Norm: ZORAN_VIDMODE_PAL or ZORAN_VIDMODE_NTSC */
        int decimation;         /* decimation of captured video,
                                 * enlargement of video played back.
                                 * Valid values are 1, 2, 4 or 0.
@@ -131,13 +135,13 @@ struct zoran_params {
 /*
 Private IOCTL to set up for displaying MJPEG
 */
-#define BUZIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct zoran_params)
-#define BUZIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct zoran_params)
-#define BUZIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct zoran_requestbuffers)
-#define BUZIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
-#define BUZIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
-#define BUZIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct zoran_sync)
-#define BUZIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct zoran_status)
+#define BUZIOC_G_PARAMS       _IOR ('v', BASE_VIDIOC_PRIVATE+0,  struct zoran_params)
+#define BUZIOC_S_PARAMS       _IOWR('v', BASE_VIDIOC_PRIVATE+1,  struct zoran_params)
+#define BUZIOC_REQBUFS        _IOWR('v', BASE_VIDIOC_PRIVATE+2,  struct zoran_requestbuffers)
+#define BUZIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOC_PRIVATE+3,  int)
+#define BUZIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOC_PRIVATE+4,  int)
+#define BUZIOC_SYNC           _IOR ('v', BASE_VIDIOC_PRIVATE+5,  struct zoran_sync)
+#define BUZIOC_G_STATUS       _IOWR('v', BASE_VIDIOC_PRIVATE+6,  struct zoran_status)
 
 
 #ifdef __KERNEL__
@@ -401,7 +405,7 @@ struct zoran {
        spinlock_t spinlock;    /* Spinlock */
 
        /* Video for Linux parameters */
-       int input;      /* card's norm and input - norm=VIDEO_MODE_* */
+       int input;      /* card's norm and input */
        v4l2_std_id norm;
 
        /* Current buffer params */
index ec41303..6f89d0a 100644 (file)
@@ -60,7 +60,7 @@
 
 #include <linux/spinlock.h>
 
-#include <linux/videodev.h>
+#include <linux/videodev2.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
 #include "videocodec.h"
@@ -1549,11 +1549,11 @@ static long zoran_default(struct file *file, void *__fh, int cmd, void *arg)
                mutex_lock(&zr->resource_lock);
 
                if (zr->norm & V4L2_STD_NTSC)
-                       bparams->norm = VIDEO_MODE_NTSC;
-               else if (zr->norm & V4L2_STD_PAL)
-                       bparams->norm = VIDEO_MODE_PAL;
+                       bparams->norm = ZORAN_VIDMODE_NTSC;
+               else if (zr->norm & V4L2_STD_SECAM)
+                       bparams->norm = ZORAN_VIDMODE_SECAM;
                else
-                       bparams->norm = VIDEO_MODE_SECAM;
+                       bparams->norm = ZORAN_VIDMODE_PAL;
 
                bparams->input = zr->input;
 
@@ -1789,11 +1789,11 @@ gstat_unlock_and_return:
                        bstat->signal =
                            (status & V4L2_IN_ST_NO_SIGNAL) ? 0 : 1;
                        if (norm & V4L2_STD_NTSC)
-                               bstat->norm = VIDEO_MODE_NTSC;
+                               bstat->norm = ZORAN_VIDMODE_NTSC;
                        else if (norm & V4L2_STD_SECAM)
-                               bstat->norm = VIDEO_MODE_SECAM;
+                               bstat->norm = ZORAN_VIDMODE_SECAM;
                        else
-                               bstat->norm = VIDEO_MODE_PAL;
+                               bstat->norm = ZORAN_VIDMODE_PAL;
 
                        bstat->color =
                            (status & V4L2_IN_ST_NO_COLOR) ? 0 : 1;
index 3d4bac2..a82b5bd 100644 (file)
@@ -376,8 +376,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count,
        if (*count == 0)
                *count = ZR364XX_DEF_BUFS;
 
-       while (*size * (*count) > ZR364XX_DEF_BUFS * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > ZR364XX_DEF_BUFS * 1024 * 1024)
+               *count = (ZR364XX_DEF_BUFS * 1024 * 1024) / *size;
 
        return 0;
 }
index 11073fa..d33693c 100644 (file)
@@ -314,22 +314,22 @@ static int i2o_cfg_swul(unsigned long arg)
        int ret = 0;
 
        if (copy_from_user(&kxfer, pxfer, sizeof(struct i2o_sw_xfer)))
-               goto return_fault;
+               return -EFAULT;
 
        if (get_user(swlen, kxfer.swlen) < 0)
-               goto return_fault;
+               return -EFAULT;
 
        if (get_user(maxfrag, kxfer.maxfrag) < 0)
-               goto return_fault;
+               return -EFAULT;
 
        if (get_user(curfrag, kxfer.curfrag) < 0)
-               goto return_fault;
+               return -EFAULT;
 
        if (curfrag == maxfrag)
                fragsize = swlen - (maxfrag - 1) * 8192;
 
        if (!kxfer.buf)
-               goto return_fault;
+               return -EFAULT;
 
        c = i2o_find_iop(kxfer.iop);
        if (!c)
@@ -373,12 +373,8 @@ static int i2o_cfg_swul(unsigned long arg)
 
        i2o_dma_free(&c->pdev->dev, &buffer);
 
-      return_ret:
        return ret;
-      return_fault:
-       ret = -EFAULT;
-       goto return_ret;
-};
+}
 
 static int i2o_cfg_swdel(unsigned long arg)
 {
index 2a5a0b7..de3e74c 100644 (file)
@@ -53,6 +53,10 @@ config MFD_SH_MOBILE_SDHI
          This driver supports the SDHI hardware block found in many
          SuperH Mobile SoCs.
 
+config MFD_DAVINCI_VOICECODEC
+       tristate
+       select MFD_CORE
+
 config MFD_DM355EVM_MSP
        bool "DaVinci DM355 EVM microcontroller"
        depends on I2C && MACH_DAVINCI_DM355_EVM
@@ -297,9 +301,9 @@ config MFD_WM8350_I2C
          selected to enable support for the functionality of the chip.
 
 config MFD_WM8994
-       tristate "Support Wolfson Microelectronics WM8994"
+       bool "Support Wolfson Microelectronics WM8994"
        select MFD_CORE
-       depends on I2C
+       depends on I2C=y && GENERIC_HARDIRQS
        help
          The WM8994 is a highly integrated hi-fi CODEC designed for
          smartphone applicatiosn.  As well as audio functionality it
index 22715ad..87935f9 100644 (file)
@@ -12,6 +12,7 @@ obj-$(CONFIG_HTC_EGPIO)               += htc-egpio.o
 obj-$(CONFIG_HTC_PASIC3)       += htc-pasic3.o
 obj-$(CONFIG_HTC_I2CPLD)       += htc-i2cpld.o
 
+obj-$(CONFIG_MFD_DAVINCI_VOICECODEC)   += davinci_voicecodec.o
 obj-$(CONFIG_MFD_DM355EVM_MSP) += dm355evm_msp.o
 
 obj-$(CONFIG_MFD_T7L66XB)      += t7l66xb.o tmio_core.o
@@ -25,7 +26,7 @@ wm8350-objs                   := wm8350-core.o wm8350-regmap.o wm8350-gpio.o
 wm8350-objs                    += wm8350-irq.o
 obj-$(CONFIG_MFD_WM8350)       += wm8350.o
 obj-$(CONFIG_MFD_WM8350_I2C)   += wm8350-i2c.o
-obj-$(CONFIG_MFD_WM8994)       += wm8994-core.o
+obj-$(CONFIG_MFD_WM8994)       += wm8994-core.o wm8994-irq.o
 
 obj-$(CONFIG_TPS65010)         += tps65010.o
 obj-$(CONFIG_MENELAUS)         += menelaus.o
diff --git a/drivers/mfd/davinci_voicecodec.c b/drivers/mfd/davinci_voicecodec.c
new file mode 100644 (file)
index 0000000..3e75f02
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * DaVinci Voice Codec Core Interface for TI platforms
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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 <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/clk.h>
+
+#include <sound/pcm.h>
+
+#include <linux/mfd/davinci_voicecodec.h>
+
+u32 davinci_vc_read(struct davinci_vc *davinci_vc, int reg)
+{
+       return __raw_readl(davinci_vc->base + reg);
+}
+
+void davinci_vc_write(struct davinci_vc *davinci_vc,
+                                          int reg, u32 val)
+{
+       __raw_writel(val, davinci_vc->base + reg);
+}
+
+static int __init davinci_vc_probe(struct platform_device *pdev)
+{
+       struct davinci_vc *davinci_vc;
+       struct resource *res, *mem;
+       struct mfd_cell *cell = NULL;
+       int ret;
+
+       davinci_vc = kzalloc(sizeof(struct davinci_vc), GFP_KERNEL);
+       if (!davinci_vc) {
+               dev_dbg(&pdev->dev,
+                           "could not allocate memory for private data\n");
+               return -ENOMEM;
+       }
+
+       davinci_vc->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(davinci_vc->clk)) {
+               dev_dbg(&pdev->dev,
+                           "could not get the clock for voice codec\n");
+               ret = -ENODEV;
+               goto fail1;
+       }
+       clk_enable(davinci_vc->clk);
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(&pdev->dev, "no mem resource\n");
+               ret = -ENODEV;
+               goto fail2;
+       }
+
+       davinci_vc->pbase = res->start;
+       davinci_vc->base_size = resource_size(res);
+
+       mem = request_mem_region(davinci_vc->pbase, davinci_vc->base_size,
+                                pdev->name);
+       if (!mem) {
+               dev_err(&pdev->dev, "VCIF region already claimed\n");
+               ret = -EBUSY;
+               goto fail2;
+       }
+
+       davinci_vc->base = ioremap(davinci_vc->pbase, davinci_vc->base_size);
+       if (!davinci_vc->base) {
+               dev_err(&pdev->dev, "can't ioremap mem resource.\n");
+               ret = -ENOMEM;
+               goto fail3;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+       if (!res) {
+               dev_err(&pdev->dev, "no DMA resource\n");
+               return -ENXIO;
+       }
+
+       davinci_vc->davinci_vcif.dma_tx_channel = res->start;
+       davinci_vc->davinci_vcif.dma_tx_addr =
+               (dma_addr_t)(io_v2p(davinci_vc->base) + DAVINCI_VC_WFIFO);
+
+       res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+       if (!res) {
+               dev_err(&pdev->dev, "no DMA resource\n");
+               return -ENXIO;
+       }
+
+       davinci_vc->davinci_vcif.dma_rx_channel = res->start;
+       davinci_vc->davinci_vcif.dma_rx_addr =
+               (dma_addr_t)(io_v2p(davinci_vc->base) + DAVINCI_VC_RFIFO);
+
+       davinci_vc->dev = &pdev->dev;
+       davinci_vc->pdev = pdev;
+
+       /* Voice codec interface client */
+       cell = &davinci_vc->cells[DAVINCI_VC_VCIF_CELL];
+       cell->name = "davinci_vcif";
+       cell->driver_data = davinci_vc;
+
+       /* Voice codec CQ93VC client */
+       cell = &davinci_vc->cells[DAVINCI_VC_CQ93VC_CELL];
+       cell->name = "cq93vc";
+       cell->driver_data = davinci_vc;
+
+       ret = mfd_add_devices(&pdev->dev, pdev->id, davinci_vc->cells,
+                             DAVINCI_VC_CELLS, NULL, 0);
+       if (ret != 0) {
+               dev_err(&pdev->dev, "fail to register client devices\n");
+               goto fail4;
+       }
+
+       return 0;
+
+fail4:
+       iounmap(davinci_vc->base);
+fail3:
+       release_mem_region(davinci_vc->pbase, davinci_vc->base_size);
+fail2:
+       clk_disable(davinci_vc->clk);
+       clk_put(davinci_vc->clk);
+       davinci_vc->clk = NULL;
+fail1:
+       kfree(davinci_vc);
+
+       return ret;
+}
+
+static int __devexit davinci_vc_remove(struct platform_device *pdev)
+{
+       struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
+
+       mfd_remove_devices(&pdev->dev);
+
+       iounmap(davinci_vc->base);
+       release_mem_region(davinci_vc->pbase, davinci_vc->base_size);
+
+       clk_disable(davinci_vc->clk);
+       clk_put(davinci_vc->clk);
+       davinci_vc->clk = NULL;
+
+       kfree(davinci_vc);
+
+       return 0;
+}
+
+static struct platform_driver davinci_vc_driver = {
+       .driver = {
+               .name = "davinci_voicecodec",
+               .owner = THIS_MODULE,
+       },
+       .remove = __devexit_p(davinci_vc_remove),
+};
+
+static int __init davinci_vc_init(void)
+{
+       return platform_driver_probe(&davinci_vc_driver, davinci_vc_probe);
+}
+module_init(davinci_vc_init);
+
+static void __exit davinci_vc_exit(void)
+{
+       platform_driver_unregister(&davinci_vc_driver);
+}
+module_exit(davinci_vc_exit);
+
+MODULE_AUTHOR("Miguel Aguilar");
+MODULE_DESCRIPTION("Texas Instruments DaVinci Voice Codec Core Interface");
+MODULE_LICENSE("GPL");
index 562cd49..720e099 100644 (file)
 #endif
 
 #if defined(CONFIG_TWL4030_CODEC) || defined(CONFIG_TWL4030_CODEC_MODULE) ||\
-       defined(CONFIG_SND_SOC_TWL6030) || defined(CONFIG_SND_SOC_TWL6030_MODULE)
+       defined(CONFIG_SND_SOC_TWL6040) || defined(CONFIG_SND_SOC_TWL6040_MODULE)
 #define twl_has_codec()        true
 #else
 #define twl_has_codec()        false
@@ -708,7 +708,7 @@ add_children(struct twl4030_platform_data *pdata, unsigned long features)
        /* Phoenix*/
        if (twl_has_codec() && pdata->codec && twl_class_is_6030()) {
                sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
-               child = add_child(sub_chip_id, "twl6030_codec",
+               child = add_child(sub_chip_id, "twl6040_codec",
                                pdata->codec, sizeof(*pdata->codec),
                                false, 0, 0);
                if (IS_ERR(child))
index 3013276..4c1122c 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <linux/mfd/wm831x/core.h>
 #include <linux/mfd/wm831x/pdata.h>
+#include <linux/mfd/wm831x/gpio.h>
 #include <linux/mfd/wm831x/irq.h>
 
 #include <linux/delay.h>
@@ -388,12 +389,41 @@ static void wm831x_irq_mask(unsigned int irq)
        wm831x->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask;
 }
 
+static int wm831x_irq_set_type(unsigned int irq, unsigned int type)
+{
+       struct wm831x *wm831x = get_irq_chip_data(irq);
+       int val;
+
+       irq = irq - wm831x->irq_base;
+
+       if (irq < WM831X_IRQ_GPIO_1 || irq > WM831X_IRQ_GPIO_11)
+               return -EINVAL;
+
+       switch (type) {
+       case IRQ_TYPE_EDGE_BOTH:
+               val = WM831X_GPN_INT_MODE;
+               break;
+       case IRQ_TYPE_EDGE_RISING:
+               val = WM831X_GPN_POL;
+               break;
+       case IRQ_TYPE_EDGE_FALLING:
+               val = 0;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return wm831x_set_bits(wm831x, WM831X_GPIO1_CONTROL + irq,
+                              WM831X_GPN_INT_MODE | WM831X_GPN_POL, val);
+}
+
 static struct irq_chip wm831x_irq_chip = {
        .name = "wm831x",
        .bus_lock = wm831x_irq_lock,
        .bus_sync_unlock = wm831x_irq_sync_unlock,
        .mask = wm831x_irq_mask,
        .unmask = wm831x_irq_unmask,
+       .set_type = wm831x_irq_set_type,
 };
 
 /* The processing of the primary interrupt occurs in a thread so that
index cc524df..ec71c93 100644 (file)
@@ -173,9 +173,34 @@ static struct mfd_cell wm8994_regulator_devs[] = {
        { .name = "wm8994-ldo", .id = 2 },
 };
 
+static struct resource wm8994_codec_resources[] = {
+       {
+               .start = WM8994_IRQ_TEMP_SHUT,
+               .end   = WM8994_IRQ_TEMP_WARN,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct resource wm8994_gpio_resources[] = {
+       {
+               .start = WM8994_IRQ_GPIO(1),
+               .end   = WM8994_IRQ_GPIO(11),
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
 static struct mfd_cell wm8994_devs[] = {
-       { .name = "wm8994-codec" },
-       { .name = "wm8994-gpio" },
+       {
+               .name = "wm8994-codec",
+               .num_resources = ARRAY_SIZE(wm8994_codec_resources),
+               .resources = wm8994_codec_resources,
+       },
+
+       {
+               .name = "wm8994-gpio",
+               .num_resources = ARRAY_SIZE(wm8994_gpio_resources),
+               .resources = wm8994_gpio_resources,
+       },
 };
 
 /*
@@ -236,6 +261,11 @@ static int wm8994_device_resume(struct device *dev)
                return ret;
        }
 
+       ret = wm8994_write(wm8994, WM8994_INTERRUPT_STATUS_1_MASK,
+                          WM8994_NUM_IRQ_REGS * 2, &wm8994->irq_masks_cur);
+       if (ret < 0)
+               dev_err(dev, "Failed to restore interrupt masks: %d\n", ret);
+
        ret = wm8994_write(wm8994, WM8994_LDO_1, WM8994_NUM_LDO_REGS * 2,
                           &wm8994->ldo_regs);
        if (ret < 0)
@@ -348,6 +378,7 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
 
 
        if (pdata) {
+               wm8994->irq_base = pdata->irq_base;
                wm8994->gpio_base = pdata->gpio_base;
 
                /* GPIO configuration is only applied if it's non-zero */
@@ -375,16 +406,20 @@ static int wm8994_device_init(struct wm8994 *wm8994, unsigned long id, int irq)
                                        WM8994_LDO1_DISCH, 0);
        }
 
+       wm8994_irq_init(wm8994);
+
        ret = mfd_add_devices(wm8994->dev, -1,
                              wm8994_devs, ARRAY_SIZE(wm8994_devs),
                              NULL, 0);
        if (ret != 0) {
                dev_err(wm8994->dev, "Failed to add children: %d\n", ret);
-               goto err_enable;
+               goto err_irq;
        }
 
        return 0;
 
+err_irq:
+       wm8994_irq_exit(wm8994);
 err_enable:
        regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies),
                               wm8994->supplies);
@@ -401,6 +436,7 @@ err:
 static void wm8994_device_exit(struct wm8994 *wm8994)
 {
        mfd_remove_devices(wm8994->dev);
+       wm8994_irq_exit(wm8994);
        regulator_bulk_disable(ARRAY_SIZE(wm8994_main_supplies),
                               wm8994->supplies);
        regulator_bulk_free(ARRAY_SIZE(wm8994_main_supplies), wm8994->supplies);
@@ -469,6 +505,7 @@ static int wm8994_i2c_probe(struct i2c_client *i2c,
        wm8994->control_data = i2c;
        wm8994->read_dev = wm8994_i2c_read_device;
        wm8994->write_dev = wm8994_i2c_write_device;
+       wm8994->irq = i2c->irq;
 
        return wm8994_device_init(wm8994, id->driver_data, i2c->irq);
 }
diff --git a/drivers/mfd/wm8994-irq.c b/drivers/mfd/wm8994-irq.c
new file mode 100644 (file)
index 0000000..8400eb1
--- /dev/null
@@ -0,0 +1,310 @@
+/*
+ * wm8994-irq.c  --  Interrupt controller support for Wolfson WM8994
+ *
+ * Copyright 2010 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.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.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/mfd/core.h>
+#include <linux/interrupt.h>
+
+#include <linux/mfd/wm8994/core.h>
+#include <linux/mfd/wm8994/registers.h>
+
+#include <linux/delay.h>
+
+struct wm8994_irq_data {
+       int reg;
+       int mask;
+};
+
+static struct wm8994_irq_data wm8994_irqs[] = {
+       [WM8994_IRQ_TEMP_SHUT] = {
+               .reg = 2,
+               .mask = WM8994_TEMP_SHUT_EINT,
+       },
+       [WM8994_IRQ_MIC1_DET] = {
+               .reg = 2,
+               .mask = WM8994_MIC1_DET_EINT,
+       },
+       [WM8994_IRQ_MIC1_SHRT] = {
+               .reg = 2,
+               .mask = WM8994_MIC1_SHRT_EINT,
+       },
+       [WM8994_IRQ_MIC2_DET] = {
+               .reg = 2,
+               .mask = WM8994_MIC2_DET_EINT,
+       },
+       [WM8994_IRQ_MIC2_SHRT] = {
+               .reg = 2,
+               .mask = WM8994_MIC2_SHRT_EINT,
+       },
+       [WM8994_IRQ_FLL1_LOCK] = {
+               .reg = 2,
+               .mask = WM8994_FLL1_LOCK_EINT,
+       },
+       [WM8994_IRQ_FLL2_LOCK] = {
+               .reg = 2,
+               .mask = WM8994_FLL2_LOCK_EINT,
+       },
+       [WM8994_IRQ_SRC1_LOCK] = {
+               .reg = 2,
+               .mask = WM8994_SRC1_LOCK_EINT,
+       },
+       [WM8994_IRQ_SRC2_LOCK] = {
+               .reg = 2,
+               .mask = WM8994_SRC2_LOCK_EINT,
+       },
+       [WM8994_IRQ_AIF1DRC1_SIG_DET] = {
+               .reg = 2,
+               .mask = WM8994_AIF1DRC1_SIG_DET,
+       },
+       [WM8994_IRQ_AIF1DRC2_SIG_DET] = {
+               .reg = 2,
+               .mask = WM8994_AIF1DRC2_SIG_DET_EINT,
+       },
+       [WM8994_IRQ_AIF2DRC_SIG_DET] = {
+               .reg = 2,
+               .mask = WM8994_AIF2DRC_SIG_DET_EINT,
+       },
+       [WM8994_IRQ_FIFOS_ERR] = {
+               .reg = 2,
+               .mask = WM8994_FIFOS_ERR_EINT,
+       },
+       [WM8994_IRQ_WSEQ_DONE] = {
+               .reg = 2,
+               .mask = WM8994_WSEQ_DONE_EINT,
+       },
+       [WM8994_IRQ_DCS_DONE] = {
+               .reg = 2,
+               .mask = WM8994_DCS_DONE_EINT,
+       },
+       [WM8994_IRQ_TEMP_WARN] = {
+               .reg = 2,
+               .mask = WM8994_TEMP_WARN_EINT,
+       },
+       [WM8994_IRQ_GPIO(1)] = {
+               .reg = 1,
+               .mask = WM8994_GP1_EINT,
+       },
+       [WM8994_IRQ_GPIO(2)] = {
+               .reg = 1,
+               .mask = WM8994_GP2_EINT,
+       },
+       [WM8994_IRQ_GPIO(3)] = {
+               .reg = 1,
+               .mask = WM8994_GP3_EINT,
+       },
+       [WM8994_IRQ_GPIO(4)] = {
+               .reg = 1,
+               .mask = WM8994_GP4_EINT,
+       },
+       [WM8994_IRQ_GPIO(5)] = {
+               .reg = 1,
+               .mask = WM8994_GP5_EINT,
+       },
+       [WM8994_IRQ_GPIO(6)] = {
+               .reg = 1,
+               .mask = WM8994_GP6_EINT,
+       },
+       [WM8994_IRQ_GPIO(7)] = {
+               .reg = 1,
+               .mask = WM8994_GP7_EINT,
+       },
+       [WM8994_IRQ_GPIO(8)] = {
+               .reg = 1,
+               .mask = WM8994_GP8_EINT,
+       },
+       [WM8994_IRQ_GPIO(9)] = {
+               .reg = 1,
+               .mask = WM8994_GP8_EINT,
+       },
+       [WM8994_IRQ_GPIO(10)] = {
+               .reg = 1,
+               .mask = WM8994_GP10_EINT,
+       },
+       [WM8994_IRQ_GPIO(11)] = {
+               .reg = 1,
+               .mask = WM8994_GP11_EINT,
+       },
+};
+
+static inline int irq_data_to_status_reg(struct wm8994_irq_data *irq_data)
+{
+       return WM8994_INTERRUPT_STATUS_1 - 1 + irq_data->reg;
+}
+
+static inline int irq_data_to_mask_reg(struct wm8994_irq_data *irq_data)
+{
+       return WM8994_INTERRUPT_STATUS_1_MASK - 1 + irq_data->reg;
+}
+
+static inline struct wm8994_irq_data *irq_to_wm8994_irq(struct wm8994 *wm8994,
+                                                       int irq)
+{
+       return &wm8994_irqs[irq - wm8994->irq_base];
+}
+
+static void wm8994_irq_lock(unsigned int irq)
+{
+       struct wm8994 *wm8994 = get_irq_chip_data(irq);
+
+       mutex_lock(&wm8994->irq_lock);
+}
+
+static void wm8994_irq_sync_unlock(unsigned int irq)
+{
+       struct wm8994 *wm8994 = get_irq_chip_data(irq);
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8994->irq_masks_cur); i++) {
+               /* If there's been a change in the mask write it back
+                * to the hardware. */
+               if (wm8994->irq_masks_cur[i] != wm8994->irq_masks_cache[i]) {
+                       wm8994->irq_masks_cache[i] = wm8994->irq_masks_cur[i];
+                       wm8994_reg_write(wm8994,
+                                        WM8994_INTERRUPT_STATUS_1_MASK + i,
+                                        wm8994->irq_masks_cur[i]);
+               }
+       }
+
+       mutex_unlock(&wm8994->irq_lock);
+}
+
+static void wm8994_irq_unmask(unsigned int irq)
+{
+       struct wm8994 *wm8994 = get_irq_chip_data(irq);
+       struct wm8994_irq_data *irq_data = irq_to_wm8994_irq(wm8994, irq);
+
+       wm8994->irq_masks_cur[irq_data->reg - 1] &= ~irq_data->mask;
+}
+
+static void wm8994_irq_mask(unsigned int irq)
+{
+       struct wm8994 *wm8994 = get_irq_chip_data(irq);
+       struct wm8994_irq_data *irq_data = irq_to_wm8994_irq(wm8994, irq);
+
+       wm8994->irq_masks_cur[irq_data->reg - 1] |= irq_data->mask;
+}
+
+static struct irq_chip wm8994_irq_chip = {
+       .name = "wm8994",
+       .bus_lock = wm8994_irq_lock,
+       .bus_sync_unlock = wm8994_irq_sync_unlock,
+       .mask = wm8994_irq_mask,
+       .unmask = wm8994_irq_unmask,
+};
+
+/* The processing of the primary interrupt occurs in a thread so that
+ * we can interact with the device over I2C or SPI. */
+static irqreturn_t wm8994_irq_thread(int irq, void *data)
+{
+       struct wm8994 *wm8994 = data;
+       unsigned int i;
+       u16 status[WM8994_NUM_IRQ_REGS];
+       int ret;
+
+       ret = wm8994_bulk_read(wm8994, WM8994_INTERRUPT_STATUS_1,
+                              WM8994_NUM_IRQ_REGS, status);
+       if (ret < 0) {
+               dev_err(wm8994->dev, "Failed to read interrupt status: %d\n",
+                       ret);
+               return IRQ_NONE;
+       }
+
+       /* Apply masking */
+       for (i = 0; i < WM8994_NUM_IRQ_REGS; i++)
+               status[i] &= ~wm8994->irq_masks_cur[i];
+
+       /* Report */
+       for (i = 0; i < ARRAY_SIZE(wm8994_irqs); i++) {
+               if (status[wm8994_irqs[i].reg - 1] & wm8994_irqs[i].mask)
+                       handle_nested_irq(wm8994->irq_base + i);
+       }
+
+       /* Ack any unmasked IRQs */
+       for (i = 0; i < ARRAY_SIZE(status); i++) {
+               if (status[i])
+                       wm8994_reg_write(wm8994, WM8994_INTERRUPT_STATUS_1 + i,
+                                        status[i]);
+       }
+
+       return IRQ_HANDLED;
+}
+
+int wm8994_irq_init(struct wm8994 *wm8994)
+{
+       int i, cur_irq, ret;
+
+       mutex_init(&wm8994->irq_lock);
+
+       /* Mask the individual interrupt sources */
+       for (i = 0; i < ARRAY_SIZE(wm8994->irq_masks_cur); i++) {
+               wm8994->irq_masks_cur[i] = 0xffff;
+               wm8994->irq_masks_cache[i] = 0xffff;
+               wm8994_reg_write(wm8994, WM8994_INTERRUPT_STATUS_1_MASK + i,
+                                0xffff);
+       }
+
+       if (!wm8994->irq) {
+               dev_warn(wm8994->dev,
+                        "No interrupt specified, no interrupts\n");
+               wm8994->irq_base = 0;
+               return 0;
+       }
+
+       if (!wm8994->irq_base) {
+               dev_err(wm8994->dev,
+                       "No interrupt base specified, no interrupts\n");
+               return 0;
+       }
+
+       /* Register them with genirq */
+       for (cur_irq = wm8994->irq_base;
+            cur_irq < ARRAY_SIZE(wm8994_irqs) + wm8994->irq_base;
+            cur_irq++) {
+               set_irq_chip_data(cur_irq, wm8994);
+               set_irq_chip_and_handler(cur_irq, &wm8994_irq_chip,
+                                        handle_edge_irq);
+               set_irq_nested_thread(cur_irq, 1);
+
+               /* ARM needs us to explicitly flag the IRQ as valid
+                * and will set them noprobe when we do so. */
+#ifdef CONFIG_ARM
+               set_irq_flags(cur_irq, IRQF_VALID);
+#else
+               set_irq_noprobe(cur_irq);
+#endif
+       }
+
+       ret = request_threaded_irq(wm8994->irq, NULL, wm8994_irq_thread,
+                                  IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+                                  "wm8994", wm8994);
+       if (ret != 0) {
+               dev_err(wm8994->dev, "Failed to request IRQ %d: %d\n",
+                       wm8994->irq, ret);
+               return ret;
+       }
+
+       /* Enable top level interrupt if it was masked */
+       wm8994_reg_write(wm8994, WM8994_INTERRUPT_CONTROL, 0);
+
+       return 0;
+}
+
+void wm8994_irq_exit(struct wm8994 *wm8994)
+{
+       if (wm8994->irq)
+               free_irq(wm8994->irq, wm8994);
+}
index f939ebc..e306a8c 100644 (file)
@@ -1,24 +1,20 @@
 /*
-    Copyright (C) 1998, 1999  Frodo Looijaard <frodol@dds.nl> and
-                              Philip Edelbrock <phil@netroedge.com>
-    Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
-    Copyright (C) 2003 IBM Corp.
-    Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
+ * Copyright (C) 1998, 1999  Frodo Looijaard <frodol@dds.nl> and
+ *                           Philip Edelbrock <phil@netroedge.com>
+ * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2003 IBM Corp.
+ * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
+ *
+ * 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.
+ */
 
 #include <linux/kernel.h>
 #include <linux/init.h>
index 15b1780..7b33de9 100644 (file)
@@ -1,27 +1,20 @@
 /*
-       Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
-       <http://rt2x00.serialmonkey.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.
- */
-
-/*
-       Module: eeprom_93cx6
-       Abstract: EEPROM reader routines for 93cx6 chipsets.
-       Supported chipsets: 93c46 & 93c66.
+ * Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
+ * <http://rt2x00.serialmonkey.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.
+ *
+ * Module: eeprom_93cx6
+ * Abstract: EEPROM reader routines for 93cx6 chipsets.
+ * Supported chipsets: 93c46 & 93c66.
  */
 
 #include <linux/kernel.h>
index 5a6b2bc..fe29092 100644 (file)
@@ -1,30 +1,30 @@
 /*
   max6875.c - driver for MAX6874/MAX6875
-
   Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
-
   Based on eeprom.c
-
   The MAX6875 has a bank of registers and two banks of EEPROM.
   Address ranges are defined as follows:
    * 0x0000 - 0x0046 = configuration registers
    * 0x8000 - 0x8046 = configuration EEPROM
    * 0x8100 - 0x82FF = user EEPROM
-
   This driver makes the user EEPROM available for read.
-
   The registers & config EEPROM should be accessed via i2c-dev.
-
   The MAX6875 ignores the lowest address bit, so each chip responds to
   two addresses - 0x50/0x51 and 0x52/0x53.
-
   Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
   address, so this driver is destructive if loaded for the wrong EEPROM chip.
-
   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 of the License.
-*/
* max6875.c - driver for MAX6874/MAX6875
+ *
* Copyright (C) 2005 Ben Gardner <bgardner@wabtec.com>
+ *
* Based on eeprom.c
+ *
* The MAX6875 has a bank of registers and two banks of EEPROM.
* Address ranges are defined as follows:
*  * 0x0000 - 0x0046 = configuration registers
*  * 0x8000 - 0x8046 = configuration EEPROM
*  * 0x8100 - 0x82FF = user EEPROM
+ *
* This driver makes the user EEPROM available for read.
+ *
* The registers & config EEPROM should be accessed via i2c-dev.
+ *
* The MAX6875 ignores the lowest address bit, so each chip responds to
* two addresses - 0x50/0x51 and 0x52/0x53.
+ *
* Note that the MAX6875 uses i2c_smbus_write_byte_data() to set the read
* address, so this driver is destructive if loaded for the wrong EEPROM chip.
+ *
* 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 of the License.
+ */
 
 #include <linux/kernel.h>
 #include <linux/init.h>
index e7161c4..db9cd02 100644 (file)
@@ -41,7 +41,7 @@
 #include <linux/workqueue.h>
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
-#include <asm/vmware.h>
+#include <asm/hypervisor.h>
 
 MODULE_AUTHOR("VMware, Inc.");
 MODULE_DESCRIPTION("VMware Memory Control (Balloon) Driver");
@@ -767,7 +767,7 @@ static int __init vmballoon_init(void)
         * Check if we are running on VMware's hypervisor and bail out
         * if we are not.
         */
-       if (!vmware_platform())
+       if (x86_hyper != &x86_hyper_vmware)
                return -ENODEV;
 
        vmballoon_wq = create_freezeable_workqueue("vmmemctl");
index 84c103a..ff115d9 100644 (file)
@@ -55,14 +55,16 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
                        host->cclk = host->mclk / (2 * (clk + 1));
                }
                if (host->hw_designer == AMBA_VENDOR_ST)
-                       clk |= MCI_FCEN; /* Bug fix in ST IP block */
+                       clk |= MCI_ST_FCEN; /* Bug fix in ST IP block */
                clk |= MCI_CLK_ENABLE;
                /* This hasn't proven to be worthwhile */
                /* clk |= MCI_CLK_PWRSAVE; */
        }
 
        if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_4)
-               clk |= MCI_WIDE_BUS;
+               clk |= MCI_4BIT_BUS;
+       if (host->mmc->ios.bus_width == MMC_BUS_WIDTH_8)
+               clk |= MCI_ST_8BIT_BUS;
 
        writel(clk, host->base + MMCICLOCK);
 }
@@ -629,7 +631,18 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
 
        mmc->ops = &mmci_ops;
        mmc->f_min = (host->mclk + 511) / 512;
-       mmc->f_max = min(host->mclk, fmax);
+       /*
+        * If the platform data supplies a maximum operating
+        * frequency, this takes precedence. Else, we fall back
+        * to using the module parameter, which has a (low)
+        * default value in case it is not specified. Either
+        * value must not exceed the clock rate into the block,
+        * of course.
+        */
+       if (plat->f_max)
+               mmc->f_max = min(host->mclk, plat->f_max);
+       else
+               mmc->f_max = min(host->mclk, fmax);
        dev_dbg(mmc_dev(mmc), "clocking block at %u Hz\n", mmc->f_max);
 
 #ifdef CONFIG_REGULATOR
index 1ceb9a9..d77062e 100644 (file)
 #define MCI_CLK_ENABLE         (1 << 8)
 #define MCI_CLK_PWRSAVE                (1 << 9)
 #define MCI_CLK_BYPASS         (1 << 10)
-#define MCI_WIDE_BUS           (1 << 11)
+#define MCI_4BIT_BUS           (1 << 11)
+/* 8bit wide buses supported in ST Micro versions */
+#define MCI_ST_8BIT_BUS                (1 << 12)
 /* HW flow control on the ST Micro version */
-#define MCI_FCEN               (1 << 13)
+#define MCI_ST_FCEN            (1 << 13)
 
 #define MMCIARGUMENT           0x008
 #define MMCICOMMAND            0x00c
index 0ed4895..e4f00e7 100644 (file)
@@ -544,7 +544,7 @@ static irqreturn_t pxamci_detect_irq(int irq, void *devid)
 {
        struct pxamci_host *host = mmc_priv(devid);
 
-       mmc_detect_change(devid, host->pdata->detect_delay);
+       mmc_detect_change(devid, msecs_to_jiffies(host->pdata->detect_delay_ms));
        return IRQ_HANDLED;
 }
 
index 689d6a7..87b2b8f 100644 (file)
@@ -52,7 +52,6 @@ static const int debug = 0;
 
 struct pcmciamtd_dev {
        struct pcmcia_device    *p_dev;
-       dev_node_t      node;           /* device node */
        caddr_t         win_base;       /* ioremapped address of PCMCIA window */
        unsigned int    win_size;       /* size of window */
        unsigned int    offset;         /* offset into card the window currently points at */
@@ -647,9 +646,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
                pcmciamtd_release(link);
                return -ENODEV;
        }
-       snprintf(dev->node.dev_name, sizeof(dev->node.dev_name), "mtd%d", mtd->index);
        info("mtd%d: %s", mtd->index, mtd->name);
-       link->dev_node = &dev->node;
        return 0;
 
  failed:
index ed5e974..a8f0512 100644 (file)
@@ -674,6 +674,7 @@ static struct zorro_device_id a2065_zorro_tbl[] __devinitdata = {
        { ZORRO_PROD_AMERISTAR_A2065 },
        { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, a2065_zorro_tbl);
 
 static struct zorro_driver a2065_driver = {
        .name           = "a2065",
index fa1a235..4b30a46 100644 (file)
@@ -145,6 +145,7 @@ static struct zorro_device_id ariadne_zorro_tbl[] __devinitdata = {
     { ZORRO_PROD_VILLAGE_TRONIC_ARIADNE },
     { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, ariadne_zorro_tbl);
 
 static struct zorro_driver ariadne_driver = {
     .name      = "ariadne",
index 7600693..fd1f29e 100644 (file)
@@ -683,7 +683,7 @@ struct drv_func_mb {
 #define DRV_MSG_CODE_GET_MANUF_KEY                     0x82000000
 #define DRV_MSG_CODE_LOAD_L2B_PRAM                     0x90000000
        /*
-        * The optic module verification commands requris bootcode
+        * The optic module verification commands require bootcode
         * v5.0.6 or later
         */
 #define DRV_MSG_CODE_VRFY_OPT_MDL                      0xa0000000
index dbf8178..d5d55c6 100644 (file)
@@ -2524,12 +2524,12 @@ static void e1000_configure_rx(struct e1000_adapter *adapter)
                         * excessive C-state transition latencies result in
                         * dropped transactions.
                         */
-                       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
-                                                 adapter->netdev->name, 55);
+                       pm_qos_update_request(
+                               adapter->netdev->pm_qos_req, 55);
                } else {
-                       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY,
-                                                 adapter->netdev->name,
-                                                 PM_QOS_DEFAULT_VALUE);
+                       pm_qos_update_request(
+                               adapter->netdev->pm_qos_req,
+                               PM_QOS_DEFAULT_VALUE);
                }
        }
 
@@ -2824,8 +2824,8 @@ int e1000e_up(struct e1000_adapter *adapter)
 
        /* DMA latency requirement to workaround early-receive/jumbo issue */
        if (adapter->flags & FLAG_HAS_ERT)
-               pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY,
-                                      adapter->netdev->name,
+               adapter->netdev->pm_qos_req =
+                       pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY,
                                       PM_QOS_DEFAULT_VALUE);
 
        /* hardware has been reset, we need to reload some things */
@@ -2887,9 +2887,11 @@ void e1000e_down(struct e1000_adapter *adapter)
        e1000_clean_tx_ring(adapter);
        e1000_clean_rx_ring(adapter);
 
-       if (adapter->flags & FLAG_HAS_ERT)
-               pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
-                                         adapter->netdev->name);
+       if (adapter->flags & FLAG_HAS_ERT) {
+               pm_qos_remove_request(
+                             adapter->netdev->pm_qos_req);
+               adapter->netdev->pm_qos_req = NULL;
+       }
 
        /*
         * TODO: for power management, we could drop the link and
index 24724b4..07d8e5b 100644 (file)
@@ -71,6 +71,7 @@ static struct zorro_device_id hydra_zorro_tbl[] __devinitdata = {
     { ZORRO_PROD_HYDRA_SYSTEMS_AMIGANET },
     { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, hydra_zorro_tbl);
 
 static struct zorro_driver hydra_driver = {
     .name      = "hydra",
index 1b1edad..f16e981 100644 (file)
@@ -48,6 +48,7 @@
 #define DRV_VERSION "1.0.0-k0"
 char igbvf_driver_name[] = "igbvf";
 const char igbvf_driver_version[] = DRV_VERSION;
+struct pm_qos_request_list *igbvf_driver_pm_qos_req;
 static const char igbvf_driver_string[] =
                                "Intel(R) Virtual Function Network Driver";
 static const char igbvf_copyright[] = "Copyright (c) 2009 Intel Corporation.";
@@ -2899,7 +2900,7 @@ static int __init igbvf_init_module(void)
        printk(KERN_INFO "%s\n", igbvf_copyright);
 
        ret = pci_register_driver(&igbvf_driver);
-       pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, igbvf_driver_name,
+       igbvf_driver_pm_qos_req = pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY,
                               PM_QOS_DEFAULT_VALUE);
 
        return ret;
@@ -2915,7 +2916,8 @@ module_init(igbvf_init_module);
 static void __exit igbvf_exit_module(void)
 {
        pci_unregister_driver(&igbvf_driver);
-       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, igbvf_driver_name);
+       pm_qos_remove_request(igbvf_driver_pm_qos_req);
+       igbvf_driver_pm_qos_req = NULL;
 }
 module_exit(igbvf_exit_module);
 
index 757f87b..30b7cf7 100644 (file)
@@ -93,7 +93,6 @@ earlier 3Com products.
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ciscode.h>
 #include <pcmcia/ds.h>
-#include <pcmcia/mem_op.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -200,7 +199,6 @@ enum Window4 {              /* Window 4: Xcvr/media bits. */
 
 struct el3_private {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
        u16 advertising, partner;               /* NWay media advertisement */
        unsigned char phys;                     /* MII device address */
        unsigned int autoselect:1, default_media:3;     /* Read from the EEPROM/Wn3_Config. */
@@ -283,8 +281,6 @@ static int tc574_probe(struct pcmcia_device *link)
        spin_lock_init(&lp->window_lock);
        link->io.NumPorts1 = 32;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = &el3_interrupt;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.ConfigIndex = 1;
@@ -311,8 +307,7 @@ static void tc574_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "3c574_detach()\n");
 
-       if (link->dev_node)
-               unregister_netdev(dev);
+       unregister_netdev(dev);
 
        tc574_release(link);
 
@@ -353,7 +348,7 @@ static int tc574_config(struct pcmcia_device *link)
        if (i != 0)
                goto failed;
 
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_irq(link, el3_interrupt);
        if (ret)
                goto failed;
 
@@ -361,7 +356,7 @@ static int tc574_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       dev->irq = link->irq.AssignedIRQ;
+       dev->irq = link->irq;
        dev->base_addr = link->io.BasePort1;
 
        ioaddr = dev->base_addr;
@@ -446,17 +441,13 @@ static int tc574_config(struct pcmcia_device *link)
                }
        }
 
-       link->dev_node = &lp->node;
        SET_NETDEV_DEV(dev, &link->dev);
 
        if (register_netdev(dev) != 0) {
                printk(KERN_NOTICE "3c574_cs: register_netdev() failed\n");
-               link->dev_node = NULL;
                goto failed;
        }
 
-       strcpy(lp->node.dev_name, dev->name);
-
        printk(KERN_INFO "%s: %s at io %#3lx, irq %d, "
               "hw_addr %pM.\n",
               dev->name, cardname, dev->base_addr, dev->irq,
index 091e0b0..5ab589d 100644 (file)
@@ -106,7 +106,6 @@ enum RxFilter {
 
 struct el3_private {
        struct pcmcia_device    *p_dev;
-    dev_node_t                 node;
     /* For transceiver monitoring */
     struct timer_list  media;
     u16                        media_status;
@@ -194,8 +193,7 @@ static int tc589_probe(struct pcmcia_device *link)
     spin_lock_init(&lp->lock);
     link->io.NumPorts1 = 16;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = &el3_interrupt;
+
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.ConfigIndex = 1;
@@ -223,8 +221,7 @@ static void tc589_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "3c589_detach\n");
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     tc589_release(link);
 
@@ -242,7 +239,6 @@ static void tc589_detach(struct pcmcia_device *link)
 static int tc589_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    struct el3_private *lp = netdev_priv(dev);
     __be16 *phys_addr;
     int ret, i, j, multi = 0, fifo;
     unsigned int ioaddr;
@@ -271,7 +267,7 @@ static int tc589_config(struct pcmcia_device *link)
     if (i != 0)
        goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
+    ret = pcmcia_request_irq(link, el3_interrupt);
     if (ret)
            goto failed;
 
@@ -279,7 +275,7 @@ static int tc589_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
        
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
     ioaddr = dev->base_addr;
     EL3WINDOW(0);
@@ -313,17 +309,13 @@ static int tc589_config(struct pcmcia_device *link)
     else
        printk(KERN_ERR "3c589_cs: invalid if_port requested\n");
     
-    link->dev_node = &lp->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if (register_netdev(dev) != 0) {
        printk(KERN_ERR "3c589_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(lp->node.dev_name, dev->name);
-
     printk(KERN_INFO "%s: 3Com 3c%s, io %#3lx, irq %d, "
           "hw_addr %pM\n",
           dev->name, (multi ? "562" : "589"), dev->base_addr, dev->irq,
index 9f3d593..59f6fa3 100644 (file)
@@ -113,7 +113,6 @@ static irqreturn_t ax_interrupt(int irq, void *dev_id);
 
 typedef struct axnet_dev_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t         node;
     caddr_t            base;
     struct timer_list  watchdog;
     int                        stale, fast_poll;
@@ -168,7 +167,6 @@ static int axnet_probe(struct pcmcia_device *link)
     info = PRIV(dev);
     info->p_dev = link;
     link->priv = dev;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -195,8 +193,7 @@ static void axnet_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "axnet_detach(0x%p)\n", link);
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     axnet_release(link);
 
@@ -265,12 +262,9 @@ static int try_io_port(struct pcmcia_device *link)
     int j, ret;
     if (link->io.NumPorts1 == 32) {
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-       if (link->io.NumPorts2 > 0) {
-           /* for master/slave multifunction cards */
+       /* for master/slave multifunction cards */
+       if (link->io.NumPorts2 > 0)
            link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
-           link->irq.Attributes =
-               IRQ_TYPE_DYNAMIC_SHARING;
-       }
     } else {
        /* This should be two 16-port windows */
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
@@ -336,8 +330,7 @@ static int axnet_config(struct pcmcia_device *link)
     if (ret != 0)
        goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
     
     if (link->io.NumPorts2 == 8) {
@@ -349,7 +342,7 @@ static int axnet_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
 
     if (!get_prom(link)) {
@@ -397,17 +390,13 @@ static int axnet_config(struct pcmcia_device *link)
     }
 
     info->phy_id = (i < 32) ? i : -1;
-    link->dev_node = &info->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if (register_netdev(dev) != 0) {
        printk(KERN_NOTICE "axnet_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(info->node.dev_name, dev->name);
-
     printk(KERN_INFO "%s: Asix AX88%d90: io %#3lx, irq %d, "
           "hw_addr %pM\n",
           dev->name, ((info->flags & IS_AX88790) ? 7 : 1),
index 21d9c9d..5643f94 100644 (file)
@@ -122,7 +122,6 @@ static void com20020_detach(struct pcmcia_device *p_dev);
 
 typedef struct com20020_dev_t {
     struct net_device       *dev;
-    dev_node_t          node;
 } com20020_dev_t;
 
 /*======================================================================
@@ -163,7 +162,6 @@ static int com20020_probe(struct pcmcia_device *p_dev)
     p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
     p_dev->io.NumPorts1 = 16;
     p_dev->io.IOAddrLines = 16;
-    p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
     p_dev->conf.Attributes = CONF_ENABLE_IRQ;
     p_dev->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -196,18 +194,16 @@ static void com20020_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "com20020_detach\n");
 
-    if (link->dev_node) {
-       dev_dbg(&link->dev, "unregister...\n");
+    dev_dbg(&link->dev, "unregister...\n");
 
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
-       /*
-        * this is necessary because we register our IRQ separately
-        * from card services.
-        */
-       if (dev->irq)
+    /*
+     * this is necessary because we register our IRQ separately
+     * from card services.
+     */
+    if (dev->irq)
            free_irq(dev->irq, dev);
-    }
 
     com20020_release(link);
 
@@ -275,15 +271,14 @@ static int com20020_config(struct pcmcia_device *link)
     dev_dbg(&link->dev, "got ioaddr %Xh\n", ioaddr);
 
     dev_dbg(&link->dev, "request IRQ %d\n",
-           link->irq.AssignedIRQ);
-    i = pcmcia_request_irq(link, &link->irq);
-    if (i != 0)
+           link->irq);
+    if (!link->irq)
     {
        dev_dbg(&link->dev, "requestIRQ failed totally!\n");
        goto failed;
     }
 
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
 
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
@@ -299,7 +294,6 @@ static int com20020_config(struct pcmcia_device *link)
     lp->card_name = "PCMCIA COM20020";
     lp->card_flags = ARC_CAN_10MBIT; /* pretend all of them can 10Mbit */
 
-    link->dev_node = &info->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     i = com20020_found(dev, 0);        /* calls register_netdev */
@@ -307,12 +301,9 @@ static int com20020_config(struct pcmcia_device *link)
     if (i != 0) {
        dev_printk(KERN_NOTICE, &link->dev,
                "com20020_cs: com20020_found() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(info->node.dev_name, dev->name);
-
     dev_dbg(&link->dev,KERN_INFO "%s: port %#3lx, irq %d\n",
            dev->name, dev->base_addr, dev->irq);
     return 0;
index b9dc80b..6580d78 100644 (file)
@@ -110,7 +110,6 @@ typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN,
 */
 typedef struct local_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t node;
     long open_time;
     uint tx_started:1;
     uint tx_queue;
@@ -254,10 +253,6 @@ static int fmvj18x_probe(struct pcmcia_device *link)
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.IOAddrLines = 5;
 
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = fjn_interrupt;
-
     /* General socket configuration */
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
@@ -278,8 +273,7 @@ static void fmvj18x_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "fmvj18x_detach\n");
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     fmvj18x_release(link);
 
@@ -425,8 +419,6 @@ static int fmvj18x_config(struct pcmcia_device *link)
     }
 
     if (link->io.NumPorts2 != 0) {
-       link->irq.Attributes =
-               IRQ_TYPE_DYNAMIC_SHARING;
        ret = mfc_try_io_port(link);
        if (ret != 0) goto failed;
     } else if (cardtype == UNGERMANN) {
@@ -437,14 +429,14 @@ static int fmvj18x_config(struct pcmcia_device *link)
            if (ret)
                    goto failed;
     }
-    ret = pcmcia_request_irq(link, &link->irq);
+    ret = pcmcia_request_irq(link, fjn_interrupt);
     if (ret)
            goto failed;
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
            goto failed;
 
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
 
     if (link->io.BasePort2 != 0) {
@@ -529,17 +521,13 @@ static int fmvj18x_config(struct pcmcia_device *link)
     }
 
     lp->cardtype = cardtype;
-    link->dev_node = &lp->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if (register_netdev(dev) != 0) {
        printk(KERN_NOTICE "fmvj18x_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(lp->node.dev_name, dev->name);
-
     /* print current configuration */
     printk(KERN_INFO "%s: %s, sram %s, port %#3lx, irq %d, "
           "hw_addr %pM\n",
index 37f4a6f..2e42d80 100644 (file)
@@ -104,7 +104,6 @@ static void ibmtr_detach(struct pcmcia_device *p_dev);
 typedef struct ibmtr_dev_t {
        struct pcmcia_device    *p_dev;
     struct net_device  *dev;
-    dev_node_t          node;
     window_handle_t     sram_win_handle;
     struct tok_info    *ti;
 } ibmtr_dev_t;
@@ -156,8 +155,6 @@ static int __devinit ibmtr_attach(struct pcmcia_device *link)
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
     link->io.NumPorts1 = 4;
     link->io.IOAddrLines = 16;
-    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-    link->irq.Handler = ibmtr_interrupt;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.Present = PRESENT_OPTION;
@@ -192,8 +189,7 @@ static void ibmtr_detach(struct pcmcia_device *link)
      */
     ti->sram_phys |= 1;
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
     
     del_timer_sync(&(ti->tr_timer));
 
@@ -238,11 +234,11 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
     }
     dev->base_addr = link->io.BasePort1;
 
-    ret = pcmcia_request_irq(link, &link->irq);
+    ret = pcmcia_request_exclusive_irq(link, ibmtr_interrupt);
     if (ret)
            goto failed;
-    dev->irq = link->irq.AssignedIRQ;
-    ti->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
+    ti->irq = link->irq;
     ti->global_int_enable=GLOBAL_INT_ENABLE+((dev->irq==9) ? 2 : dev->irq);
 
     /* Allocate the MMIO memory window */
@@ -291,18 +287,14 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
         Adapters Technical Reference"  SC30-3585 for this info.  */
     ibmtr_hw_setup(dev, mmiobase);
 
-    link->dev_node = &info->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     i = ibmtr_probe_card(dev);
     if (i != 0) {
        printk(KERN_NOTICE "ibmtr_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(info->node.dev_name, dev->name);
-
     printk(KERN_INFO
           "%s: port %#3lx, irq %d,  mmio %#5lx, sram %#5lx, hwaddr=%pM\n",
            dev->name, dev->base_addr, dev->irq,
index c717b14..d8a3b3c 100644 (file)
@@ -363,7 +363,6 @@ typedef struct _mace_statistics {
 
 typedef struct _mace_private {
        struct pcmcia_device    *p_dev;
-    dev_node_t node;
     struct net_device_stats linux_stats; /* Linux statistics counters */
     mace_statistics mace_stats; /* MACE chip statistics counters */
 
@@ -463,8 +462,6 @@ static int nmclan_probe(struct pcmcia_device *link)
     link->io.NumPorts1 = 32;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.IOAddrLines = 5;
-    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-    link->irq.Handler = mace_interrupt;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.ConfigIndex = 1;
@@ -493,8 +490,7 @@ static void nmclan_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "nmclan_detach\n");
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     nmclan_release(link);
 
@@ -652,14 +648,14 @@ static int nmclan_config(struct pcmcia_device *link)
   ret = pcmcia_request_io(link, &link->io);
   if (ret)
          goto failed;
-  ret = pcmcia_request_irq(link, &link->irq);
+  ret = pcmcia_request_exclusive_irq(link, mace_interrupt);
   if (ret)
          goto failed;
   ret = pcmcia_request_configuration(link, &link->conf);
   if (ret)
          goto failed;
 
-  dev->irq = link->irq.AssignedIRQ;
+  dev->irq = link->irq;
   dev->base_addr = link->io.BasePort1;
 
   ioaddr = dev->base_addr;
@@ -698,18 +694,14 @@ static int nmclan_config(struct pcmcia_device *link)
   else
     printk(KERN_NOTICE "nmclan_cs: invalid if_port requested\n");
 
-  link->dev_node = &lp->node;
   SET_NETDEV_DEV(dev, &link->dev);
 
   i = register_netdev(dev);
   if (i != 0) {
     printk(KERN_NOTICE "nmclan_cs: register_netdev() failed\n");
-    link->dev_node = NULL;
     goto failed;
   }
 
-  strcpy(lp->node.dev_name, dev->name);
-
   printk(KERN_INFO "%s: nmclan: port %#3lx, irq %d, %s port,"
         " hw_addr %pM\n",
         dev->name, dev->base_addr, dev->irq, if_names[dev->if_port],
index 4c0368d..6f77a76 100644 (file)
@@ -208,7 +208,6 @@ static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
 
 typedef struct pcnet_dev_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t         node;
     u_int              flags;
     void               __iomem *base;
     struct timer_list  watchdog;
@@ -264,7 +263,6 @@ static int pcnet_probe(struct pcmcia_device *link)
     info->p_dev = link;
     link->priv = dev;
 
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -288,8 +286,7 @@ static void pcnet_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "pcnet_detach\n");
 
-       if (link->dev_node)
-               unregister_netdev(dev);
+       unregister_netdev(dev);
 
        pcnet_release(link);
 
@@ -488,8 +485,6 @@ static int try_io_port(struct pcmcia_device *link)
        if (link->io.NumPorts2 > 0) {
            /* for master/slave multifunction cards */
            link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
-           link->irq.Attributes =
-               IRQ_TYPE_DYNAMIC_SHARING;
        }
     } else {
        /* This should be two 16-port windows */
@@ -559,8 +554,7 @@ static int pcnet_config(struct pcmcia_device *link)
     if (ret)
        goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
 
     if (link->io.NumPorts2 == 8) {
@@ -574,7 +568,7 @@ static int pcnet_config(struct pcmcia_device *link)
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
            goto failed;
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
     if (info->flags & HAS_MISC_REG) {
        if ((if_port == 1) || (if_port == 2))
@@ -643,17 +637,13 @@ static int pcnet_config(struct pcmcia_device *link)
     if (info->flags & (IS_DL10019|IS_DL10022))
        mii_phy_probe(dev);
 
-    link->dev_node = &info->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if (register_netdev(dev) != 0) {
        printk(KERN_NOTICE "pcnet_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto failed;
     }
 
-    strcpy(info->node.dev_name, dev->name);
-
     if (info->flags & (IS_DL10019|IS_DL10022)) {
        u_char id = inb(dev->base_addr + 0x1a);
        printk(KERN_INFO "%s: NE2000 (DL100%d rev %02x): ",
index ccc5537..59796e7 100644 (file)
@@ -103,7 +103,6 @@ struct smc_private {
     u_short                    manfid;
     u_short                    cardid;
 
-    dev_node_t                 node;
     struct sk_buff             *saved_skb;
     int                                packets_waiting;
     void                       __iomem *base;
@@ -323,14 +322,11 @@ static int smc91c92_probe(struct pcmcia_device *link)
        return -ENOMEM;
     smc = netdev_priv(dev);
     smc->p_dev = link;
-    link->priv = dev;
 
     spin_lock_init(&smc->lock);
     link->io.NumPorts1 = 16;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.IOAddrLines = 4;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = &smc_interrupt;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -363,8 +359,7 @@ static void smc91c92_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "smc91c92_detach\n");
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     smc91c92_release(link);
 
@@ -453,7 +448,6 @@ static int mhz_mfc_config(struct pcmcia_device *link)
 
     link->conf.Attributes |= CONF_ENABLE_SPKR;
     link->conf.Status = CCSR_AUDIO_ENA;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->io.IOAddrLines = 16;
     link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
     link->io.NumPorts2 = 8;
@@ -652,7 +646,6 @@ static int osi_config(struct pcmcia_device *link)
 
     link->conf.Attributes |= CONF_ENABLE_SPKR;
     link->conf.Status = CCSR_AUDIO_ENA;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->io.NumPorts1 = 64;
     link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
     link->io.NumPorts2 = 8;
@@ -877,7 +870,7 @@ static int smc91c92_config(struct pcmcia_device *link)
     if (i)
            goto config_failed;
 
-    i = pcmcia_request_irq(link, &link->irq);
+    i = pcmcia_request_irq(link, smc_interrupt);
     if (i)
            goto config_failed;
     i = pcmcia_request_configuration(link, &link->conf);
@@ -887,7 +880,7 @@ static int smc91c92_config(struct pcmcia_device *link)
     if (smc->manfid == MANFID_MOTOROLA)
        mot_config(link);
 
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
 
     if ((if_port >= 0) && (if_port <= 2))
        dev->if_port = if_port;
@@ -960,17 +953,13 @@ static int smc91c92_config(struct pcmcia_device *link)
        SMC_SELECT_BANK(0);
     }
 
-    link->dev_node = &smc->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if (register_netdev(dev) != 0) {
        printk(KERN_ERR "smc91c92_cs: register_netdev() failed\n");
-       link->dev_node = NULL;
        goto config_undo;
     }
 
-    strcpy(smc->node.dev_name, dev->name);
-
     printk(KERN_INFO "%s: smc91c%s rev %d: io %#3lx, irq %d, "
           "hw_addr %pM\n",
           dev->name, name, (rev & 0x0f), dev->base_addr, dev->irq,
index 4d1802e..5e6b62b 100644 (file)
@@ -297,31 +297,9 @@ static void xirc2ps_detach(struct pcmcia_device *p_dev);
 
 static irqreturn_t xirc2ps_interrupt(int irq, void *dev_id);
 
-/****************
- * A linked list of "instances" of the device.  Each actual
- * PCMCIA card corresponds to one device instance, and is described
- * by one struct pcmcia_device structure (defined in ds.h).
- *
- * You may not want to use a linked list for this -- for example, the
- * memory card driver uses an array of struct pcmcia_device pointers, where minor
- * device numbers are used to derive the corresponding array index.
- */
-
-/****************
- * A driver needs to provide a dev_node_t structure for each device
- * on a card.  In some cases, there is only one device per card (for
- * example, ethernet cards, modems).  In other cases, there may be
- * many actual or logical devices (SCSI adapters, memory cards with
- * multiple partitions).  The dev_node_t structures need to be kept
- * in a linked list starting at the 'dev' field of a struct pcmcia_device
- * structure.  We allocate them in the card's private data structure,
- * because they generally can't be allocated dynamically.
- */
-
 typedef struct local_info_t {
        struct net_device       *dev;
        struct pcmcia_device    *p_dev;
-    dev_node_t node;
 
     int card_type;
     int probe_port;
@@ -555,7 +533,6 @@ xirc2ps_probe(struct pcmcia_device *link)
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.ConfigIndex = 1;
-    link->irq.Handler = xirc2ps_interrupt;
 
     /* Fill in card specific entries */
     dev->netdev_ops = &netdev_ops;
@@ -580,8 +557,7 @@ xirc2ps_detach(struct pcmcia_device *link)
 
     dev_dbg(&link->dev, "detach\n");
 
-    if (link->dev_node)
-       unregister_netdev(dev);
+    unregister_netdev(dev);
 
     xirc2ps_release(link);
 
@@ -841,7 +817,6 @@ xirc2ps_config(struct pcmcia_device * link)
            link->conf.Attributes |= CONF_ENABLE_SPKR;
            link->conf.Status |= CCSR_AUDIO_ENA;
        }
-       link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
        link->io.NumPorts2 = 8;
        link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
        if (local->dingo) {
@@ -866,7 +841,6 @@ xirc2ps_config(struct pcmcia_device * link)
        }
        printk(KNOT_XIRC "no ports available\n");
     } else {
-       link->irq.Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
        link->io.NumPorts1 = 16;
        for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
            link->io.BasePort1 = ioaddr;
@@ -885,7 +859,7 @@ xirc2ps_config(struct pcmcia_device * link)
      * Now allocate an interrupt line. Note that this does not
      * actually assign a handler to the interrupt.
      */
-    if ((err=pcmcia_request_irq(link, &link->irq)))
+    if ((err=pcmcia_request_irq(link, xirc2ps_interrupt)))
        goto config_error;
 
     /****************
@@ -982,23 +956,19 @@ xirc2ps_config(struct pcmcia_device * link)
        printk(KNOT_XIRC "invalid if_port requested\n");
 
     /* we can now register the device with the net subsystem */
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
 
     if (local->dingo)
        do_reset(dev, 1); /* a kludge to make the cem56 work */
 
-    link->dev_node = &local->node;
     SET_NETDEV_DEV(dev, &link->dev);
 
     if ((err=register_netdev(dev))) {
        printk(KNOT_XIRC "register_netdev() failed\n");
-       link->dev_node = NULL;
        goto config_error;
     }
 
-    strcpy(local->node.dev_name, dev->name);
-
     /* give some infos about the hardware */
     printk(KERN_INFO "%s: %s: port %#3lx, irq %d, hwaddr %pM\n",
           dev->name, local->manf_str,(u_long)dev->base_addr, (int)dev->irq,
index f0be507..369a801 100644 (file)
@@ -96,7 +96,7 @@ static inline int precise_ie(void)
  * post_eurus_cmd helpers
  */
 struct eurus_cmd_arg_info {
-       int pre_arg; /* command requres arg1, arg2 at POST COMMAND */
+       int pre_arg; /* command requires arg1, arg2 at POST COMMAND */
        int post_arg; /* command requires arg1, arg2 at GET_RESULT */
 };
 
index cbf520d..ffbaa60 100644 (file)
@@ -736,7 +736,7 @@ static void smsc911x_phy_adjust_link(struct net_device *dev)
                        SMSC_TRACE(HW, "configuring for carrier OK");
                        if ((pdata->gpio_orig_setting & GPIO_CFG_LED1_EN_) &&
                            (!pdata->using_extphy)) {
-                               /* Restore orginal GPIO configuration */
+                               /* Restore original GPIO configuration */
                                pdata->gpio_setting = pdata->gpio_orig_setting;
                                smsc911x_reg_write(pdata, GPIO_CFG,
                                        pdata->gpio_setting);
@@ -750,7 +750,7 @@ static void smsc911x_phy_adjust_link(struct net_device *dev)
                        if ((pdata->gpio_setting & GPIO_CFG_LED1_EN_) &&
                            (!pdata->using_extphy)) {
                                /* Force 10/100 LED off, after saving
-                                * orginal GPIO configuration */
+                                * original GPIO configuration */
                                pdata->gpio_orig_setting = pdata->gpio_setting;
 
                                pdata->gpio_setting &= ~GPIO_CFG_LED1_EN_;
index f6036fb..33bdc6a 100644 (file)
@@ -75,42 +75,7 @@ static void airo_release(struct pcmcia_device *link);
 
 static void airo_detach(struct pcmcia_device *p_dev);
 
-/*
-   You'll also need to prototype all the functions that will actually
-   be used to talk to your device.  See 'pcmem_cs' for a good example
-   of a fully self-sufficient driver; the other drivers rely more or
-   less on other parts of the kernel.
-*/
-
-/*
-   A linked list of "instances" of the  aironet device.  Each actual
-   PCMCIA card corresponds to one device instance, and is described
-   by one struct pcmcia_device structure (defined in ds.h).
-
-   You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of struct pcmcia_device pointers,
-   where minor device numbers are used to derive the corresponding
-   array index.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally shouldn't be allocated dynamically.
-
-   In this case, we also provide a flag to indicate if a device is
-   "stopped" due to a power management event, or card ejection.  The
-   device IO routines can use a flag like this to throttle IO to a
-   card that is not ready to accept it.
-*/
-
 typedef struct local_info_t {
-       dev_node_t      node;
        struct net_device *eth_dev;
 } local_info_t;
 
@@ -132,10 +97,6 @@ static int airo_probe(struct pcmcia_device *p_dev)
 
        dev_dbg(&p_dev->dev, "airo_attach()\n");
 
-       /* Interrupt setup */
-       p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       p_dev->irq.Handler = NULL;
-
        /*
          General socket configuration defaults can go here.  In this
          client, we assume very little, and rely on the CIS for almost
@@ -212,9 +173,7 @@ static int airo_cs_config_check(struct pcmcia_device *p_dev,
        else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
                p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
 
-       /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -300,16 +259,8 @@ static int airo_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-         Allocate an interrupt line.  Note that this does not assign a
-         handler to the interrupt, unless the 'Handler' member of the
-         irq structure is initialized.
-       */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
 
        /*
          This actually configures the PCMCIA socket -- setting up
@@ -320,26 +271,17 @@ static int airo_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
        ((local_info_t *)link->priv)->eth_dev =
-               init_airo_card(link->irq.AssignedIRQ,
+               init_airo_card(link->irq,
                               link->io.BasePort1, 1, &link->dev);
        if (!((local_info_t *)link->priv)->eth_dev)
                goto failed;
 
-       /*
-         At this point, the dev_node_t structure(s) need to be
-         initialized and arranged in a linked list at link->dev_node.
-       */
-       strcpy(dev->node.dev_name, ((local_info_t *)link->priv)->eth_dev->name);
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x: ",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x: ",
+              link->conf.ConfigIndex);
        if (link->conf.Vpp)
                printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
-       if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %d", link->irq.AssignedIRQ);
+       printk(", irq %d", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1+link->io.NumPorts1-1);
index 3240791..c2746fc 100644 (file)
@@ -85,41 +85,7 @@ static void atmel_release(struct pcmcia_device *link);
 
 static void atmel_detach(struct pcmcia_device *p_dev);
 
-/*
-   You'll also need to prototype all the functions that will actually
-   be used to talk to your device.  See 'pcmem_cs' for a good example
-   of a fully self-sufficient driver; the other drivers rely more or
-   less on other parts of the kernel.
-*/
-
-/*
-   A linked list of "instances" of the  atmelnet device.  Each actual
-   PCMCIA card corresponds to one device instance, and is described
-   by one struct pcmcia_device structure (defined in ds.h).
-
-   You may not want to use a linked list for this -- for example, the
-   memory card driver uses an array of struct pcmcia_device pointers, where minor
-   device numbers are used to derive the corresponding array index.
-*/
-
-/*
-   A driver needs to provide a dev_node_t structure for each device
-   on a card.  In some cases, there is only one device per card (for
-   example, ethernet cards, modems).  In other cases, there may be
-   many actual or logical devices (SCSI adapters, memory cards with
-   multiple partitions).  The dev_node_t structures need to be kept
-   in a linked list starting at the 'dev' field of a struct pcmcia_device
-   structure.  We allocate them in the card's private data structure,
-   because they generally shouldn't be allocated dynamically.
-
-   In this case, we also provide a flag to indicate if a device is
-   "stopped" due to a power management event, or card ejection.  The
-   device IO routines can use a flag like this to throttle IO to a
-   card that is not ready to accept it.
-*/
-
 typedef struct local_info_t {
-       dev_node_t      node;
        struct net_device *eth_dev;
 } local_info_t;
 
@@ -141,10 +107,6 @@ static int atmel_probe(struct pcmcia_device *p_dev)
 
        dev_dbg(&p_dev->dev, "atmel_attach()\n");
 
-       /* Interrupt setup */
-       p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       p_dev->irq.Handler = NULL;
-
        /*
          General socket configuration defaults can go here.  In this
          client, we assume very little, and rely on the CIS for almost
@@ -226,9 +188,7 @@ static int atmel_config_check(struct pcmcia_device *p_dev,
        else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
                p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
 
-       /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -278,15 +238,9 @@ static int atmel_config(struct pcmcia_device *link)
        if (pcmcia_loop_config(link, atmel_config_check, NULL))
                goto failed;
 
-       /*
-         Allocate an interrupt line.  Note that this does not assign a
-         handler to the interrupt, unless the 'Handler' member of the
-         irq structure is initialized.
-       */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
+       if (!link->irq) {
+               dev_err(&link->dev, "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
+               goto failed;
        }
 
        /*
@@ -298,14 +252,8 @@ static int atmel_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       if (link->irq.AssignedIRQ == 0) {
-               printk(KERN_ALERT
-                      "atmel: cannot assign IRQ: check that CONFIG_ISA is set in kernel config.");
-               goto failed;
-       }
-
        ((local_info_t*)link->priv)->eth_dev =
-               init_atmel_card(link->irq.AssignedIRQ,
+               init_atmel_card(link->irq,
                                link->io.BasePort1,
                                did ? did->driver_info : ATMEL_FW_TYPE_NONE,
                                &link->dev,
@@ -315,14 +263,6 @@ static int atmel_config(struct pcmcia_device *link)
                        goto failed;
 
 
-       /*
-         At this point, the dev_node_t structure(s) need to be
-         initialized and arranged in a linked list at link->dev_node.
-       */
-       strcpy(dev->node.dev_name, ((local_info_t*)link->priv)->eth_dev->name );
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        return 0;
 
  failed:
index 609e705..0e99b63 100644 (file)
@@ -98,10 +98,7 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
        if (res != 0)
                goto err_disable;
 
-       dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       dev->irq.Handler = NULL; /* The handler is registered later. */
-       res = pcmcia_request_irq(dev, &dev->irq);
-       if (res != 0)
+       if (!dev->irq)
                goto err_disable;
 
        res = pcmcia_request_configuration(dev, &dev->conf);
index a36501d..db72461 100644 (file)
@@ -39,7 +39,6 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
 
 /* struct local_info::hw_priv */
 struct hostap_cs_priv {
-       dev_node_t node;
        struct pcmcia_device *link;
        int sandisk_connectplus;
 };
@@ -556,15 +555,7 @@ static int prism2_config_check(struct pcmcia_device *p_dev,
                p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
-       else if (!(p_dev->conf.Attributes & CONF_ENABLE_IRQ)) {
-               /* At least Compaq WL200 does not have IRQInfo1 set,
-                * but it does not work without interrupts.. */
-               printk(KERN_WARNING "Config has no IRQ info, but trying to "
-                      "enable IRQ anyway..\n");
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
-       }
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
@@ -633,21 +624,10 @@ static int prism2_config(struct pcmcia_device *link)
        local = iface->local;
        local->hw_priv = hw_priv;
        hw_priv->link = link;
-       strcpy(hw_priv->node.dev_name, dev->name);
-       link->dev_node = &hw_priv->node;
 
-       /*
-        * Allocate an interrupt line.  Note that this does not assign a
-        * handler to the interrupt, unless the 'Handler' member of the
-        * irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-               link->irq.Handler = prism2_interrupt;
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       ret = pcmcia_request_irq(link, prism2_interrupt);
+       if (ret)
+               goto failed;
 
        /*
         * This actually configures the PCMCIA socket -- setting up
@@ -658,7 +638,7 @@ static int prism2_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       dev->irq = link->irq.AssignedIRQ;
+       dev->irq = link->irq;
        dev->base_addr = link->io.BasePort1;
 
        /* Finally, report what we've done */
@@ -668,7 +648,7 @@ static int prism2_config(struct pcmcia_device *link)
                printk(", Vpp %d.%d", link->conf.Vpp / 10,
                       link->conf.Vpp % 10);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %d", link->irq.AssignedIRQ);
+               printk(", irq %d", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1+link->io.NumPorts1-1);
@@ -682,11 +662,9 @@ static int prism2_config(struct pcmcia_device *link)
        sandisk_enable_wireless(dev);
 
        ret = prism2_hw_config(dev, 1);
-       if (!ret) {
+       if (!ret)
                ret = hostap_hw_ready(dev);
-               if (ret == 0 && local->ddev)
-                       strcpy(hw_priv->node.dev_name, local->ddev->name);
-       }
+
        return ret;
 
  failed:
index 9b72c45..2b05fe5 100644 (file)
@@ -174,6 +174,8 @@ that only one external action is invoked at a time.
 #define DRV_DESCRIPTION        "Intel(R) PRO/Wireless 2100 Network Driver"
 #define DRV_COPYRIGHT  "Copyright(c) 2003-2006 Intel Corporation"
 
+struct pm_qos_request_list *ipw2100_pm_qos_req;
+
 /* Debugging stuff */
 #ifdef CONFIG_IPW2100_DEBUG
 #define IPW2100_RX_DEBUG       /* Reception debugging */
@@ -1739,7 +1741,7 @@ static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
        /* the ipw2100 hardware really doesn't want power management delays
         * longer than 175usec
         */
-       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100", 175);
+       pm_qos_update_request(ipw2100_pm_qos_req, 175);
 
        /* If the interrupt is enabled, turn it off... */
        spin_lock_irqsave(&priv->low_lock, flags);
@@ -1887,8 +1889,7 @@ static void ipw2100_down(struct ipw2100_priv *priv)
        ipw2100_disable_interrupts(priv);
        spin_unlock_irqrestore(&priv->low_lock, flags);
 
-       pm_qos_update_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
-                       PM_QOS_DEFAULT_VALUE);
+       pm_qos_update_request(ipw2100_pm_qos_req, PM_QOS_DEFAULT_VALUE);
 
        /* We have to signal any supplicant if we are disassociating */
        if (associated)
@@ -6669,7 +6670,7 @@ static int __init ipw2100_init(void)
        if (ret)
                goto out;
 
-       pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100",
+       ipw2100_pm_qos_req = pm_qos_add_request(PM_QOS_CPU_DMA_LATENCY,
                        PM_QOS_DEFAULT_VALUE);
 #ifdef CONFIG_IPW2100_DEBUG
        ipw2100_debug_level = debug;
@@ -6692,7 +6693,7 @@ static void __exit ipw2100_exit(void)
                           &driver_attr_debug_level);
 #endif
        pci_unregister_driver(&ipw2100_pci_driver);
-       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY, "ipw2100");
+       pm_qos_remove_request(ipw2100_pm_qos_req);
 }
 
 module_init(ipw2100_init);
index 6d55439..08e4e39 100644 (file)
@@ -777,7 +777,7 @@ static void if_cs_release(struct pcmcia_device *p_dev)
 
        lbs_deb_enter(LBS_DEB_CS);
 
-       free_irq(p_dev->irq.AssignedIRQ, card);
+       free_irq(p_dev->irq, card);
        pcmcia_disable_device(p_dev);
        if (card->iobase)
                ioport_unmap(card->iobase);
@@ -807,8 +807,7 @@ static int if_cs_ioprobe(struct pcmcia_device *p_dev,
        p_dev->io.NumPorts1 = cfg->io.win[0].len;
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        if (cfg->io.nwin != 1) {
@@ -837,9 +836,6 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
        card->p_dev = p_dev;
        p_dev->priv = card;
 
-       p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       p_dev->irq.Handler = NULL;
-
        p_dev->conf.Attributes = 0;
        p_dev->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -854,13 +850,8 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
         * a handler to the interrupt, unless the 'Handler' member of
         * the irq structure is initialized.
         */
-       if (p_dev->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(p_dev, &p_dev->irq);
-               if (ret) {
-                       lbs_pr_err("error in pcmcia_request_irq\n");
-                       goto out1;
-               }
-       }
+       if (!p_dev->irq)
+               goto out1;
 
        /* Initialize io access */
        card->iobase = ioport_map(p_dev->io.BasePort1, p_dev->io.NumPorts1);
@@ -883,7 +874,7 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
 
        /* Finally, report what we've done */
        lbs_deb_cs("irq %d, io 0x%04x-0x%04x\n",
-              p_dev->irq.AssignedIRQ, p_dev->io.BasePort1,
+              p_dev->irq, p_dev->io.BasePort1,
               p_dev->io.BasePort1 + p_dev->io.NumPorts1 - 1);
 
        /*
@@ -940,7 +931,7 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
        priv->fw_ready = 1;
 
        /* Now actually get the IRQ */
-       ret = request_irq(p_dev->irq.AssignedIRQ, if_cs_interrupt,
+       ret = request_irq(p_dev->irq, if_cs_interrupt,
                IRQF_SHARED, DRV_NAME, card);
        if (ret) {
                lbs_pr_err("error in request_irq\n");
index 1d4ada1..03056ab 100644 (file)
@@ -50,7 +50,6 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
  * struct orinoco_private */
 struct orinoco_pccard {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
 
        /* Used to handle hard reset */
        /* yuck, we need this hack to work around the insanity of the
@@ -119,10 +118,6 @@ orinoco_cs_probe(struct pcmcia_device *link)
        card->p_dev = link;
        link->priv = priv;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = orinoco_interrupt;
-
        /* General socket configuration defaults can go here.  In this
         * client, we assume very little, and rely on the CIS for
         * almost everything.  In most clients, many details (i.e.,
@@ -144,8 +139,7 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
 {
        struct orinoco_private *priv = link->priv;
 
-       if (link->dev_node)
-               orinoco_if_del(priv);
+       orinoco_if_del(priv);
 
        orinoco_cs_release(link);
 
@@ -230,7 +224,6 @@ static int
 orinoco_cs_config(struct pcmcia_device *link)
 {
        struct orinoco_private *priv = link->priv;
-       struct orinoco_pccard *card = priv->card;
        hermes_t *hw = &priv->hw;
        int ret;
        void __iomem *mem;
@@ -258,12 +251,7 @@ orinoco_cs_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-        * Allocate an interrupt line.  Note that this does not assign
-        * a handler to the interrupt, unless the 'Handler' member of
-        * the irq structure is initialized.
-        */
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_irq(link, orinoco_interrupt);
        if (ret)
                goto failed;
 
@@ -285,9 +273,6 @@ orinoco_cs_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /* Ok, we have the configuration, prepare to register the netdev */
-       card->node.major = card->node.minor = 0;
-
        /* Initialise the main driver */
        if (orinoco_init(priv) != 0) {
                printk(KERN_ERR PFX "orinoco_init() failed\n");
@@ -296,17 +281,11 @@ orinoco_cs_config(struct pcmcia_device *link)
 
        /* Register an interface with the stack */
        if (orinoco_if_add(priv, link->io.BasePort1,
-                          link->irq.AssignedIRQ) != 0) {
+                          link->irq) != 0) {
                printk(KERN_ERR PFX "orinoco_if_add() failed\n");
                goto failed;
        }
 
-       /* At this point, the dev_node_t structure(s) needs to be
-        * initialized and arranged in a linked list at link->dev_node. */
-       strcpy(card->node.dev_name, priv->ndev->name);
-       link->dev_node = &card->node; /* link->dev_node being non-NULL is also
-                                      * used to indicate that the
-                                      * net_device has been registered */
        return 0;
 
  failed:
index 59bda24..41b9ce4 100644 (file)
@@ -57,7 +57,6 @@ MODULE_PARM_DESC(ignore_cis_vcc, "Allow voltage mismatch between card and socket
  * struct orinoco_private */
 struct orinoco_pccard {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
 };
 
 /********************************************************************/
@@ -193,10 +192,6 @@ spectrum_cs_probe(struct pcmcia_device *link)
        card->p_dev = link;
        link->priv = priv;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = orinoco_interrupt;
-
        /* General socket configuration defaults can go here.  In this
         * client, we assume very little, and rely on the CIS for
         * almost everything.  In most clients, many details (i.e.,
@@ -218,8 +213,7 @@ static void spectrum_cs_detach(struct pcmcia_device *link)
 {
        struct orinoco_private *priv = link->priv;
 
-       if (link->dev_node)
-               orinoco_if_del(priv);
+       orinoco_if_del(priv);
 
        spectrum_cs_release(link);
 
@@ -304,7 +298,6 @@ static int
 spectrum_cs_config(struct pcmcia_device *link)
 {
        struct orinoco_private *priv = link->priv;
-       struct orinoco_pccard *card = priv->card;
        hermes_t *hw = &priv->hw;
        int ret;
        void __iomem *mem;
@@ -332,12 +325,7 @@ spectrum_cs_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-        * Allocate an interrupt line.  Note that this does not assign
-        * a handler to the interrupt, unless the 'Handler' member of
-        * the irq structure is initialized.
-        */
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_irq(link, orinoco_interrupt);
        if (ret)
                goto failed;
 
@@ -359,9 +347,6 @@ spectrum_cs_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /* Ok, we have the configuration, prepare to register the netdev */
-       card->node.major = card->node.minor = 0;
-
        /* Reset card */
        if (spectrum_cs_hard_reset(priv) != 0)
                goto failed;
@@ -374,17 +359,11 @@ spectrum_cs_config(struct pcmcia_device *link)
 
        /* Register an interface with the stack */
        if (orinoco_if_add(priv, link->io.BasePort1,
-                          link->irq.AssignedIRQ) != 0) {
+                          link->irq) != 0) {
                printk(KERN_ERR PFX "orinoco_if_add() failed\n");
                goto failed;
        }
 
-       /* At this point, the dev_node_t structure(s) needs to be
-        * initialized and arranged in a linked list at link->dev_node. */
-       strcpy(card->node.dev_name, priv->ndev->name);
-       link->dev_node = &card->node; /* link->dev_node being non-NULL is also
-                                      * used to indicate that the
-                                      * net_device has been registered */
        return 0;
 
  failed:
index 11865ea..f7d2a34 100644 (file)
@@ -51,7 +51,6 @@
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
-#include <pcmcia/mem_op.h>
 
 #include <linux/wireless.h>
 #include <net/iw_handler.h>
@@ -321,10 +320,6 @@ static int ray_probe(struct pcmcia_device *p_dev)
        p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        p_dev->io.IOAddrLines = 5;
 
-       /* Interrupt setup. For PCMCIA, driver takes what's given */
-       p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       p_dev->irq.Handler = &ray_interrupt;
-
        /* General socket configuration */
        p_dev->conf.Attributes = CONF_ENABLE_IRQ;
        p_dev->conf.IntType = INT_MEMORY_AND_IO;
@@ -383,8 +378,7 @@ static void ray_detach(struct pcmcia_device *link)
        del_timer(&local->timer);
 
        if (link->priv) {
-               if (link->dev_node)
-                       unregister_netdev(dev);
+               unregister_netdev(dev);
                free_netdev(dev);
        }
        dev_dbg(&link->dev, "ray_cs ray_detach ending\n");
@@ -417,10 +411,10 @@ static int ray_config(struct pcmcia_device *link)
        /* Now allocate an interrupt line.  Note that this does not
           actually assign a handler to the interrupt.
         */
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_irq(link, ray_interrupt);
        if (ret)
                goto failed;
-       dev->irq = link->irq.AssignedIRQ;
+       dev->irq = link->irq;
 
        /* This actually configures the PCMCIA socket -- setting up
           the I/O windows and the interrupt mapping.
@@ -493,9 +487,6 @@ static int ray_config(struct pcmcia_device *link)
                return i;
        }
 
-       strcpy(local->node.dev_name, dev->name);
-       link->dev_node = &local->node;
-
        printk(KERN_INFO "%s: RayLink, irq %d, hw_addr %pM\n",
               dev->name, dev->irq, dev->dev_addr);
 
index 1e23b7f..9f01ddb 100644 (file)
@@ -25,7 +25,6 @@ struct beacon_rx {
 typedef struct ray_dev_t {
     int card_status;
     int authentication_state;
-    dev_node_t  node;
     window_handle_t amem_handle;   /* handle to window for attribute memory  */
     window_handle_t rmem_handle;   /* handle to window for rx buffer on card */
     void __iomem *sram;            /* pointer to beginning of shared RAM     */
index 8bce1a5..8816e37 100644 (file)
@@ -610,7 +610,6 @@ struct wl3501_card {
        struct iw_statistics            wstats;
        struct iw_spy_data              spy_data;
        struct iw_public_data           wireless_data;
-       struct dev_node_t               node;
        struct pcmcia_device            *p_dev;
 };
 #endif
index 7b9621d..5e5d24c 100644 (file)
@@ -1451,6 +1451,8 @@ static void wl3501_detach(struct pcmcia_device *link)
        netif_device_detach(dev);
        wl3501_release(link);
 
+       unregister_netdev(dev);
+
        if (link->priv)
                free_netdev(link->priv);
 
@@ -1897,10 +1899,6 @@ static int wl3501_probe(struct pcmcia_device *p_dev)
        p_dev->io.Attributes1   = IO_DATA_PATH_WIDTH_8;
        p_dev->io.IOAddrLines   = 5;
 
-       /* Interrupt setup */
-       p_dev->irq.Attributes   = IRQ_TYPE_DYNAMIC_SHARING;
-       p_dev->irq.Handler = wl3501_interrupt;
-
        /* General socket configuration */
        p_dev->conf.Attributes  = CONF_ENABLE_IRQ;
        p_dev->conf.IntType     = INT_MEMORY_AND_IO;
@@ -1961,7 +1959,7 @@ static int wl3501_config(struct pcmcia_device *link)
        /* Now allocate an interrupt line. Note that this does not actually
         * assign a handler to the interrupt. */
 
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_irq(link, wl3501_interrupt);
        if (ret)
                goto failed;
 
@@ -1972,7 +1970,7 @@ static int wl3501_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       dev->irq = link->irq.AssignedIRQ;
+       dev->irq = link->irq;
        dev->base_addr = link->io.BasePort1;
        SET_NETDEV_DEV(dev, &link->dev);
        if (register_netdev(dev)) {
@@ -1981,20 +1979,15 @@ static int wl3501_config(struct pcmcia_device *link)
        }
 
        this = netdev_priv(dev);
-       /*
-        * At this point, the dev_node_t structure(s) should be initialized and
-        * arranged in a linked list at link->dev_node.
-        */
-       link->dev_node = &this->node;
 
        this->base_addr = dev->base_addr;
 
        if (!wl3501_get_flash_mac_addr(this)) {
                printk(KERN_WARNING "%s: Cant read MAC addr in flash ROM?\n",
                       dev->name);
+               unregister_netdev(dev);
                goto failed;
        }
-       strcpy(this->node.dev_name, dev->name);
 
        for (i = 0; i < 6; i++)
                dev->dev_addr[i] = ((char *)&this->mac_addr)[i];
@@ -2038,12 +2031,6 @@ failed:
  */
 static void wl3501_release(struct pcmcia_device *link)
 {
-       struct net_device *dev = link->priv;
-
-       /* Unlink the device chain */
-       if (link->dev_node)
-               unregister_netdev(dev);
-
        pcmcia_disable_device(link);
 }
 
index 81c753a..9548cbb 100644 (file)
@@ -102,6 +102,7 @@ static struct zorro_device_id zorro8390_zorro_tbl[] __devinitdata = {
     { ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF, },
     { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, zorro8390_zorro_tbl);
 
 static struct zorro_driver zorro8390_driver = {
     .name      = "zorro8390",
index 166b67e..219f79e 100644 (file)
 
 #define OP_BUFFER_FLAGS        0
 
-/*
- * Read and write access is using spin locking. Thus, writing to the
- * buffer by NMI handler (x86) could occur also during critical
- * sections when reading the buffer. To avoid this, there are 2
- * buffers for independent read and write access. Read access is in
- * process context only, write access only in the NMI handler. If the
- * read buffer runs empty, both buffers are swapped atomically. There
- * is potentially a small window during swapping where the buffers are
- * disabled and samples could be lost.
- *
- * Using 2 buffers is a little bit overhead, but the solution is clear
- * and does not require changes in the ring buffer implementation. It
- * can be changed to a single buffer solution when the ring buffer
- * access is implemented as non-locking atomic code.
- */
-static struct ring_buffer *op_ring_buffer_read;
-static struct ring_buffer *op_ring_buffer_write;
+static struct ring_buffer *op_ring_buffer;
 DEFINE_PER_CPU(struct oprofile_cpu_buffer, op_cpu_buffer);
 
 static void wq_sync_buffer(struct work_struct *work);
@@ -68,12 +52,9 @@ void oprofile_cpu_buffer_inc_smpl_lost(void)
 
 void free_cpu_buffers(void)
 {
-       if (op_ring_buffer_read)
-               ring_buffer_free(op_ring_buffer_read);
-       op_ring_buffer_read = NULL;
-       if (op_ring_buffer_write)
-               ring_buffer_free(op_ring_buffer_write);
-       op_ring_buffer_write = NULL;
+       if (op_ring_buffer)
+               ring_buffer_free(op_ring_buffer);
+       op_ring_buffer = NULL;
 }
 
 #define RB_EVENT_HDR_SIZE 4
@@ -86,11 +67,8 @@ int alloc_cpu_buffers(void)
        unsigned long byte_size = buffer_size * (sizeof(struct op_sample) +
                                                 RB_EVENT_HDR_SIZE);
 
-       op_ring_buffer_read = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
-       if (!op_ring_buffer_read)
-               goto fail;
-       op_ring_buffer_write = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
-       if (!op_ring_buffer_write)
+       op_ring_buffer = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
+       if (!op_ring_buffer)
                goto fail;
 
        for_each_possible_cpu(i) {
@@ -162,16 +140,11 @@ struct op_sample
 *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size)
 {
        entry->event = ring_buffer_lock_reserve
-               (op_ring_buffer_write, sizeof(struct op_sample) +
+               (op_ring_buffer, sizeof(struct op_sample) +
                 size * sizeof(entry->sample->data[0]));
-       if (entry->event)
-               entry->sample = ring_buffer_event_data(entry->event);
-       else
-               entry->sample = NULL;
-
-       if (!entry->sample)
+       if (!entry->event)
                return NULL;
-
+       entry->sample = ring_buffer_event_data(entry->event);
        entry->size = size;
        entry->data = entry->sample->data;
 
@@ -180,25 +153,16 @@ struct op_sample
 
 int op_cpu_buffer_write_commit(struct op_entry *entry)
 {
-       return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event);
+       return ring_buffer_unlock_commit(op_ring_buffer, entry->event);
 }
 
 struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu)
 {
        struct ring_buffer_event *e;
-       e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
-       if (e)
-               goto event;
-       if (ring_buffer_swap_cpu(op_ring_buffer_read,
-                                op_ring_buffer_write,
-                                cpu))
+       e = ring_buffer_consume(op_ring_buffer, cpu, NULL, NULL);
+       if (!e)
                return NULL;
-       e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
-       if (e)
-               goto event;
-       return NULL;
 
-event:
        entry->event = e;
        entry->sample = ring_buffer_event_data(e);
        entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample))
@@ -209,8 +173,7 @@ event:
 
 unsigned long op_cpu_buffer_entries(int cpu)
 {
-       return ring_buffer_entries_cpu(op_ring_buffer_read, cpu)
-               + ring_buffer_entries_cpu(op_ring_buffer_write, cpu);
+       return ring_buffer_entries_cpu(op_ring_buffer, cpu);
 }
 
 static int
@@ -356,8 +319,16 @@ void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
 
 void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
 {
-       int is_kernel = !user_mode(regs);
-       unsigned long pc = profile_pc(regs);
+       int is_kernel;
+       unsigned long pc;
+
+       if (likely(regs)) {
+               is_kernel = !user_mode(regs);
+               pc = profile_pc(regs);
+       } else {
+               is_kernel = 0;    /* This value will not be used */
+               pc = ESCAPE_CODE; /* as this causes an early return. */
+       }
 
        __oprofile_add_ext_sample(pc, regs, event, is_kernel);
 }
index dc8a042..b336cd9 100644 (file)
@@ -253,22 +253,26 @@ static int __init oprofile_init(void)
        int err;
 
        err = oprofile_arch_init(&oprofile_ops);
-
        if (err < 0 || timer) {
                printk(KERN_INFO "oprofile: using timer interrupt.\n");
-               oprofile_timer_init(&oprofile_ops);
+               err = oprofile_timer_init(&oprofile_ops);
+               if (err)
+                       goto out_arch;
        }
-
        err = oprofilefs_register();
        if (err)
-               oprofile_arch_exit();
+               goto out_arch;
+       return 0;
 
+out_arch:
+       oprofile_arch_exit();
        return err;
 }
 
 
 static void __exit oprofile_exit(void)
 {
+       oprofile_timer_exit();
        oprofilefs_unregister();
        oprofile_arch_exit();
 }
index cb92f5c..47e12cb 100644 (file)
@@ -34,7 +34,8 @@ struct super_block;
 struct dentry;
 
 void oprofile_create_files(struct super_block *sb, struct dentry *root);
-void oprofile_timer_init(struct oprofile_operations *ops);
+int oprofile_timer_init(struct oprofile_operations *ops);
+void oprofile_timer_exit(void);
 
 int oprofile_set_backtrace(unsigned long depth);
 int oprofile_set_timeout(unsigned long time);
index 333f915..dc0ae4d 100644 (file)
 #include <linux/oprofile.h>
 #include <linux/profile.h>
 #include <linux/init.h>
+#include <linux/cpu.h>
+#include <linux/hrtimer.h>
+#include <asm/irq_regs.h>
 #include <asm/ptrace.h>
 
 #include "oprof.h"
 
-static int timer_notify(struct pt_regs *regs)
+static DEFINE_PER_CPU(struct hrtimer, oprofile_hrtimer);
+
+static enum hrtimer_restart oprofile_hrtimer_notify(struct hrtimer *hrtimer)
+{
+       oprofile_add_sample(get_irq_regs(), 0);
+       hrtimer_forward_now(hrtimer, ns_to_ktime(TICK_NSEC));
+       return HRTIMER_RESTART;
+}
+
+static void __oprofile_hrtimer_start(void *unused)
+{
+       struct hrtimer *hrtimer = &__get_cpu_var(oprofile_hrtimer);
+
+       hrtimer_init(hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+       hrtimer->function = oprofile_hrtimer_notify;
+
+       hrtimer_start(hrtimer, ns_to_ktime(TICK_NSEC),
+                     HRTIMER_MODE_REL_PINNED);
+}
+
+static int oprofile_hrtimer_start(void)
 {
-       oprofile_add_sample(regs, 0);
+       on_each_cpu(__oprofile_hrtimer_start, NULL, 1);
        return 0;
 }
 
-static int timer_start(void)
+static void __oprofile_hrtimer_stop(int cpu)
 {
-       return register_timer_hook(timer_notify);
+       struct hrtimer *hrtimer = &per_cpu(oprofile_hrtimer, cpu);
+
+       hrtimer_cancel(hrtimer);
 }
 
+static void oprofile_hrtimer_stop(void)
+{
+       int cpu;
+
+       for_each_online_cpu(cpu)
+               __oprofile_hrtimer_stop(cpu);
+}
 
-static void timer_stop(void)
+static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
+                                        unsigned long action, void *hcpu)
 {
-       unregister_timer_hook(timer_notify);
+       long cpu = (long) hcpu;
+
+       switch (action) {
+       case CPU_ONLINE:
+       case CPU_ONLINE_FROZEN:
+               smp_call_function_single(cpu, __oprofile_hrtimer_start,
+                                        NULL, 1);
+               break;
+       case CPU_DEAD:
+       case CPU_DEAD_FROZEN:
+               __oprofile_hrtimer_stop(cpu);
+               break;
+       }
+       return NOTIFY_OK;
 }
 
+static struct notifier_block __refdata oprofile_cpu_notifier = {
+       .notifier_call = oprofile_cpu_notify,
+};
 
-void __init oprofile_timer_init(struct oprofile_operations *ops)
+int __init oprofile_timer_init(struct oprofile_operations *ops)
 {
+       int rc;
+
+       rc = register_hotcpu_notifier(&oprofile_cpu_notifier);
+       if (rc)
+               return rc;
        ops->create_files = NULL;
        ops->setup = NULL;
        ops->shutdown = NULL;
-       ops->start = timer_start;
-       ops->stop = timer_stop;
+       ops->start = oprofile_hrtimer_start;
+       ops->stop = oprofile_hrtimer_stop;
        ops->cpu_type = "timer";
+       return 0;
+}
+
+void __exit oprofile_timer_exit(void)
+{
+       unregister_hotcpu_notifier(&oprofile_cpu_notifier);
 }
index 7dd370f..fd8cfe9 100644 (file)
@@ -75,7 +75,6 @@ INT_MODULE_PARM(epp_mode, 1);
 typedef struct parport_info_t {
        struct pcmcia_device    *p_dev;
     int                        ndev;
-    dev_node_t         node;
     struct parport     *port;
 } parport_info_t;
 
@@ -105,7 +104,6 @@ static int parport_probe(struct pcmcia_device *link)
 
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
     link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -174,20 +172,19 @@ static int parport_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
            goto failed;
 
     p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2,
-                             link->irq.AssignedIRQ, PARPORT_DMA_NONE,
+                             link->irq, PARPORT_DMA_NONE,
                              &link->dev, IRQF_SHARED);
     if (p == NULL) {
        printk(KERN_NOTICE "parport_cs: parport_pc_probe_port() at "
               "0x%3x, irq %u failed\n", link->io.BasePort1,
-              link->irq.AssignedIRQ);
+              link->irq);
        goto failed;
     }
 
@@ -195,11 +192,7 @@ static int parport_config(struct pcmcia_device *link)
     if (epp_mode)
        p->modes |= PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP;
     info->ndev = 1;
-    info->node.major = LP_MAJOR;
-    info->node.minor = p->number;
     info->port = p;
-    strcpy(info->node.dev_name, p->name);
-    link->dev_node = &info->node;
 
     return 0;
 
index f184d1d..6644337 100644 (file)
@@ -848,7 +848,7 @@ static int cpqhpc_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
                goto err_disable_device;
        }
 
-       /* Check for the proper subsytem ID's
+       /* Check for the proper subsystem ID's
         * Intel uses a different SSID programming model than Compaq.
         * For Intel, each SSID bit identifies a PHP capability.
         * Also Intel HPC's may have RID=0.
index 4173125..371dc56 100644 (file)
@@ -3626,14 +3626,15 @@ static void intel_iommu_detach_device(struct iommu_domain *domain,
        domain_remove_one_dev_info(dmar_domain, pdev);
 }
 
-static int intel_iommu_map_range(struct iommu_domain *domain,
-                                unsigned long iova, phys_addr_t hpa,
-                                size_t size, int iommu_prot)
+static int intel_iommu_map(struct iommu_domain *domain,
+                          unsigned long iova, phys_addr_t hpa,
+                          int gfp_order, int iommu_prot)
 {
        struct dmar_domain *dmar_domain = domain->priv;
        u64 max_addr;
        int addr_width;
        int prot = 0;
+       size_t size;
        int ret;
 
        if (iommu_prot & IOMMU_READ)
@@ -3643,6 +3644,7 @@ static int intel_iommu_map_range(struct iommu_domain *domain,
        if ((iommu_prot & IOMMU_CACHE) && dmar_domain->iommu_snooping)
                prot |= DMA_PTE_SNP;
 
+       size     = PAGE_SIZE << gfp_order;
        max_addr = iova + size;
        if (dmar_domain->max_addr < max_addr) {
                int min_agaw;
@@ -3669,19 +3671,19 @@ static int intel_iommu_map_range(struct iommu_domain *domain,
        return ret;
 }
 
-static void intel_iommu_unmap_range(struct iommu_domain *domain,
-                                   unsigned long iova, size_t size)
+static int intel_iommu_unmap(struct iommu_domain *domain,
+                            unsigned long iova, int gfp_order)
 {
        struct dmar_domain *dmar_domain = domain->priv;
-
-       if (!size)
-               return;
+       size_t size = PAGE_SIZE << gfp_order;
 
        dma_pte_clear_range(dmar_domain, iova >> VTD_PAGE_SHIFT,
                            (iova + size - 1) >> VTD_PAGE_SHIFT);
 
        if (dmar_domain->max_addr == iova + size)
                dmar_domain->max_addr = iova;
+
+       return gfp_order;
 }
 
 static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
@@ -3714,8 +3716,8 @@ static struct iommu_ops intel_iommu_ops = {
        .domain_destroy = intel_iommu_domain_destroy,
        .attach_dev     = intel_iommu_attach_device,
        .detach_dev     = intel_iommu_detach_device,
-       .map            = intel_iommu_map_range,
-       .unmap          = intel_iommu_unmap_range,
+       .map            = intel_iommu_map,
+       .unmap          = intel_iommu_unmap,
        .iova_to_phys   = intel_iommu_iova_to_phys,
        .domain_has_cap = intel_iommu_domain_has_cap,
 };
index 3749912..1df7c50 100644 (file)
@@ -1503,7 +1503,7 @@ int pci_prepare_to_sleep(struct pci_dev *dev)
  * pci_back_from_sleep - turn PCI device on during system-wide transition into working state
  * @dev: Device to handle.
  *
- * Disable device's sytem wake-up capability and put it into D0.
+ * Disable device's system wake-up capability and put it into D0.
  */
 int pci_back_from_sleep(struct pci_dev *dev)
 {
index 4eb10f4..f8077b3 100644 (file)
@@ -244,7 +244,7 @@ struct pci_ats {
        int stu;        /* Smallest Translation Unit */
        int qdep;       /* Invalidate Queue Depth */
        int ref_cnt;    /* Physical Function reference count */
-       int is_enabled:1;       /* Enable bit is set */
+       unsigned int is_enabled:1;      /* Enable bit is set */
 };
 
 #ifdef CONFIG_PCI_IOV
index d189e47..d0f5ad3 100644 (file)
@@ -49,26 +49,6 @@ config PCMCIA_LOAD_CIS
 
          If unsure, say Y.
 
-config PCMCIA_IOCTL
-       bool "PCMCIA control ioctl (obsolete)"
-       depends on PCMCIA && ARM && !SMP && !PREEMPT
-       default y
-       help
-         If you say Y here, the deprecated ioctl interface to the PCMCIA
-         subsystem will be built. It is needed by the deprecated pcmcia-cs
-         tools (cardmgr, cardctl) to function properly.
-
-         You should use the new pcmciautils package instead (see
-         <file:Documentation/Changes> for location and details).
-
-         This config option will most likely be removed from kernel 2.6.35,
-         the associated code from kernel 2.6.36.
-
-         As the PCMCIA ioctl is not locking safe, it depends on !SMP and
-         !PREEMPT.
-
-         If unsure, say N.
-
 config CARDBUS
        bool "32-bit CardBus support"
        depends on PCI
@@ -234,7 +214,8 @@ config PCMCIA_PXA2XX
        depends on ARM && ARCH_PXA && PCMCIA
        depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \
                    || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \
-                   || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2)
+                   || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \
+                   || MACH_VPAC270)
        select PCMCIA_SOC_COMMON
        help
          Say Y here to include support for the PXA2xx PCMCIA controller
@@ -317,7 +298,7 @@ config ELECTRA_CF
          PA Semi Electra eval board.
 
 config PCCARD_NONSTATIC
-       tristate
+       bool
 
 config PCCARD_IODYN
        bool
index 381b031..d006e8b 100644 (file)
@@ -2,15 +2,18 @@
 # Makefile for the kernel pcmcia subsystem (c/o David Hinds)
 #
 
-pcmcia_core-y                                  += cs.o rsrc_mgr.o socket_sysfs.o
+pcmcia_core-y                                  += cs.o socket_sysfs.o
 pcmcia_core-$(CONFIG_CARDBUS)                  += cardbus.o
 obj-$(CONFIG_PCCARD)                           += pcmcia_core.o
 
-pcmcia-y                                       += ds.o pcmcia_resource.o cistpl.o
+pcmcia-y                                       += ds.o pcmcia_resource.o cistpl.o pcmcia_cis.o
 pcmcia-$(CONFIG_PCMCIA_IOCTL)                  += pcmcia_ioctl.o
 obj-$(CONFIG_PCMCIA)                           += pcmcia.o
 
-obj-$(CONFIG_PCCARD_NONSTATIC)                 += rsrc_nonstatic.o
+pcmcia_rsrc-y                                  += rsrc_mgr.o
+pcmcia_rsrc-$(CONFIG_PCCARD_NONSTATIC)         += rsrc_nonstatic.o
+pcmcia_rsrc-$(CONFIG_PCCARD_IODYN)             += rsrc_iodyn.o
+obj-$(CONFIG_PCCARD)                           += pcmcia_rsrc.o
 
 
 # socket drivers
@@ -66,6 +69,7 @@ pxa2xx-obj-$(CONFIG_MACH_PALMTC)              += pxa2xx_palmtc.o
 pxa2xx-obj-$(CONFIG_MACH_PALMLD)               += pxa2xx_palmld.o
 pxa2xx-obj-$(CONFIG_MACH_E740)                 += pxa2xx_e740.o
 pxa2xx-obj-$(CONFIG_MACH_STARGATE2)            += pxa2xx_stargate2.o
+pxa2xx-obj-$(CONFIG_MACH_VPAC270)              += pxa2xx_vpac270.o
 
 obj-$(CONFIG_PCMCIA_PXA2XX)                    += pxa2xx_base.o $(pxa2xx-obj-y)
 
index 9e84d03..eae9cbe 100644 (file)
@@ -113,7 +113,7 @@ static int bfin_cf_get_status(struct pcmcia_socket *s, u_int *sp)
 
        if (bfin_cf_present(cf->cd_pfx)) {
                *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
-               s->irq.AssignedIRQ = 0;
+               s->pcmcia_irq = 0;
                s->pci_irq = cf->irq;
 
        } else
index e6ab2a4..9a58862 100644 (file)
@@ -94,7 +94,6 @@ int __ref cb_alloc(struct pcmcia_socket *s)
        pci_enable_bridges(bus);
        pci_bus_add_devices(bus);
 
-       s->irq.AssignedIRQ = s->pci_irq;
        return 0;
 }
 
index 854959c..60d428b 100644 (file)
@@ -129,6 +129,8 @@ static void __iomem *set_cis_map(struct pcmcia_socket *s,
 
 /**
  * pcmcia_read_cis_mem() - low-level function to read CIS memory
+ *
+ * must be called with ops_mutex held
  */
 int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                 u_int len, void *ptr)
@@ -138,7 +140,6 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
 
        dev_dbg(&s->dev, "pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
 
-       mutex_lock(&s->ops_mutex);
        if (attr & IS_INDIRECT) {
                /* Indirect accesses use a bunch of special registers at fixed
                   locations in common memory */
@@ -153,7 +154,6 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                if (!sys) {
                        dev_dbg(&s->dev, "could not map memory\n");
                        memset(ptr, 0xff, len);
-                       mutex_unlock(&s->ops_mutex);
                        return -1;
                }
 
@@ -184,7 +184,6 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                        if (!sys) {
                                dev_dbg(&s->dev, "could not map memory\n");
                                memset(ptr, 0xff, len);
-                               mutex_unlock(&s->ops_mutex);
                                return -1;
                        }
                        end = sys + s->map_size;
@@ -198,7 +197,6 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                        addr = 0;
                }
        }
-       mutex_unlock(&s->ops_mutex);
        dev_dbg(&s->dev, "  %#2.2x %#2.2x %#2.2x %#2.2x ...\n",
                *(u_char *)(ptr+0), *(u_char *)(ptr+1),
                *(u_char *)(ptr+2), *(u_char *)(ptr+3));
@@ -209,7 +207,8 @@ int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
 /**
  * pcmcia_write_cis_mem() - low-level function to write CIS memory
  *
- * Probably only useful for writing one-byte registers.
+ * Probably only useful for writing one-byte registers. Must be called
+ * with ops_mutex held.
  */
 void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                   u_int len, void *ptr)
@@ -220,7 +219,6 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
        dev_dbg(&s->dev,
                "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
 
-       mutex_lock(&s->ops_mutex);
        if (attr & IS_INDIRECT) {
                /* Indirect accesses use a bunch of special registers at fixed
                   locations in common memory */
@@ -234,7 +232,6 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                                ((cis_width) ? MAP_16BIT : 0));
                if (!sys) {
                        dev_dbg(&s->dev, "could not map memory\n");
-                       mutex_unlock(&s->ops_mutex);
                        return; /* FIXME: Error */
                }
 
@@ -260,7 +257,6 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                        sys = set_cis_map(s, card_offset, flags);
                        if (!sys) {
                                dev_dbg(&s->dev, "could not map memory\n");
-                               mutex_unlock(&s->ops_mutex);
                                return; /* FIXME: error */
                        }
 
@@ -275,7 +271,6 @@ void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, u_int addr,
                        addr = 0;
                }
        }
-       mutex_unlock(&s->ops_mutex);
 }
 
 
@@ -314,7 +309,6 @@ static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
                        return 0;
                }
        }
-       mutex_unlock(&s->ops_mutex);
 
        ret = pcmcia_read_cis_mem(s, attr, addr, len, ptr);
 
@@ -326,11 +320,11 @@ static int read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
                        cis->len = len;
                        cis->attr = attr;
                        memcpy(cis->cache, ptr, len);
-                       mutex_lock(&s->ops_mutex);
                        list_add(&cis->node, &s->cis_cache);
-                       mutex_unlock(&s->ops_mutex);
                }
        }
+       mutex_unlock(&s->ops_mutex);
+
        return ret;
 }
 
@@ -386,6 +380,7 @@ int verify_cis_cache(struct pcmcia_socket *s)
                           "no memory for verifying CIS\n");
                return -ENOMEM;
        }
+       mutex_lock(&s->ops_mutex);
        list_for_each_entry(cis, &s->cis_cache, node) {
                int len = cis->len;
 
@@ -395,10 +390,12 @@ int verify_cis_cache(struct pcmcia_socket *s)
                ret = pcmcia_read_cis_mem(s, cis->attr, cis->addr, len, buf);
                if (ret || memcmp(buf, cis->cache, len) != 0) {
                        kfree(buf);
+                       mutex_unlock(&s->ops_mutex);
                        return -1;
                }
        }
        kfree(buf);
+       mutex_unlock(&s->ops_mutex);
        return 0;
 }
 
@@ -1361,106 +1358,6 @@ int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
 EXPORT_SYMBOL(pcmcia_parse_tuple);
 
 
-/**
- * pccard_read_tuple() - internal CIS tuple access
- * @s:         the struct pcmcia_socket where the card is inserted
- * @function:  the device function we loop for
- * @code:      which CIS code shall we look for?
- * @parse:     buffer where the tuple shall be parsed (or NULL, if no parse)
- *
- * pccard_read_tuple() reads out one tuple and attempts to parse it
- */
-int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
-               cisdata_t code, void *parse)
-{
-       tuple_t tuple;
-       cisdata_t *buf;
-       int ret;
-
-       buf = kmalloc(256, GFP_KERNEL);
-       if (buf == NULL) {
-               dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
-               return -ENOMEM;
-       }
-       tuple.DesiredTuple = code;
-       tuple.Attributes = 0;
-       if (function == BIND_FN_ALL)
-               tuple.Attributes = TUPLE_RETURN_COMMON;
-       ret = pccard_get_first_tuple(s, function, &tuple);
-       if (ret != 0)
-               goto done;
-       tuple.TupleData = buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       ret = pccard_get_tuple_data(s, &tuple);
-       if (ret != 0)
-               goto done;
-       ret = pcmcia_parse_tuple(&tuple, parse);
-done:
-       kfree(buf);
-       return ret;
-}
-
-
-/**
- * pccard_loop_tuple() - loop over tuples in the CIS
- * @s:         the struct pcmcia_socket where the card is inserted
- * @function:  the device function we loop for
- * @code:      which CIS code shall we look for?
- * @parse:     buffer where the tuple shall be parsed (or NULL, if no parse)
- * @priv_data: private data to be passed to the loop_tuple function.
- * @loop_tuple:        function to call for each CIS entry of type @function. IT
- *             gets passed the raw tuple, the paresed tuple (if @parse is
- *             set) and @priv_data.
- *
- * pccard_loop_tuple() loops over all CIS entries of type @function, and
- * calls the @loop_tuple function for each entry. If the call to @loop_tuple
- * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
- */
-int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
-                     cisdata_t code, cisparse_t *parse, void *priv_data,
-                     int (*loop_tuple) (tuple_t *tuple,
-                                        cisparse_t *parse,
-                                        void *priv_data))
-{
-       tuple_t tuple;
-       cisdata_t *buf;
-       int ret;
-
-       buf = kzalloc(256, GFP_KERNEL);
-       if (buf == NULL) {
-               dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
-               return -ENOMEM;
-       }
-
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = 255;
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = code;
-       tuple.Attributes = 0;
-
-       ret = pccard_get_first_tuple(s, function, &tuple);
-       while (!ret) {
-               if (pccard_get_tuple_data(s, &tuple))
-                       goto next_entry;
-
-               if (parse)
-                       if (pcmcia_parse_tuple(&tuple, parse))
-                               goto next_entry;
-
-               ret = loop_tuple(&tuple, parse, priv_data);
-               if (!ret)
-                       break;
-
-next_entry:
-               ret = pccard_get_next_tuple(s, function, &tuple);
-       }
-
-       kfree(buf);
-       return ret;
-}
-
-
 /**
  * pccard_validate_cis() - check whether card has a sensible CIS
  * @s:         the struct pcmcia_socket we are to check
index c338375..976d807 100644 (file)
@@ -337,7 +337,6 @@ static void socket_shutdown(struct pcmcia_socket *s)
        s->socket = dead_socket;
        s->ops->init(s);
        s->ops->set_socket(s, &s->socket);
-       s->irq.AssignedIRQ = s->irq.Config = 0;
        s->lock_count = 0;
        kfree(s->fake_cis);
        s->fake_cis = NULL;
index f95864c..4126a75 100644 (file)
@@ -52,13 +52,11 @@ struct cis_cache_entry {
 
 struct pccard_resource_ops {
        int     (*validate_mem)         (struct pcmcia_socket *s);
-       int     (*adjust_io_region)     (struct resource *res,
-                                        unsigned long r_start,
-                                        unsigned long r_end,
-                                        struct pcmcia_socket *s);
-       struct resource* (*find_io)     (unsigned long base, int num,
-                                        unsigned long align,
-                                        struct pcmcia_socket *s);
+       int     (*find_io)              (struct pcmcia_socket *s,
+                                        unsigned int attr,
+                                        unsigned int *base,
+                                        unsigned int num,
+                                        unsigned int align);
        struct resource* (*find_mem)    (unsigned long base, unsigned long num,
                                         unsigned long align, int low,
                                         struct pcmcia_socket *s);
@@ -88,6 +86,14 @@ struct pccard_resource_ops {
 #define SOCKET_CARDBUS_CONFIG  0x10000
 
 
+/*
+ * Stuff internal to module "pcmcia_rsrc":
+ */
+extern int static_init(struct pcmcia_socket *s);
+extern struct resource *pcmcia_make_resource(unsigned long start,
+                                       unsigned long end,
+                                       int flags, const char *name);
+
 /*
  * Stuff internal to module "pcmcia_core":
  */
@@ -149,6 +155,8 @@ extern struct resource *pcmcia_find_mem_region(u_long base,
                                               int low,
                                               struct pcmcia_socket *s);
 
+void pcmcia_cleanup_irq(struct pcmcia_socket *s);
+int pcmcia_setup_irq(struct pcmcia_device *p_dev);
 
 /* cistpl.c */
 extern struct bin_attribute pccard_cis_attr;
index 041eee4..7ef7ade 100644 (file)
@@ -371,8 +371,6 @@ static int pcmcia_device_remove(struct device *dev)
        if (p_drv->remove)
                p_drv->remove(p_dev);
 
-       p_dev->dev_node = NULL;
-
        /* check for proper unloading */
        if (p_dev->_irq || p_dev->_io || p_dev->_locked)
                dev_printk(KERN_INFO, dev,
@@ -479,15 +477,6 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
 }
 
 
-/* device_add_lock is needed to avoid double registration by cardmgr and kernel.
- * Serializes pcmcia_device_add; will most likely be removed in future.
- *
- * While it has the caveat that adding new PCMCIA devices inside(!) device_register()
- * won't work, this doesn't matter much at the moment: the driver core doesn't
- * support it either.
- */
-static DEFINE_MUTEX(device_add_lock);
-
 struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int function)
 {
        struct pcmcia_device *p_dev, *tmp_dev;
@@ -497,8 +486,6 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
        if (!s)
                return NULL;
 
-       mutex_lock(&device_add_lock);
-
        pr_debug("adding device to %d, function %d\n", s->sock, function);
 
        p_dev = kzalloc(sizeof(struct pcmcia_device), GFP_KERNEL);
@@ -538,8 +525,8 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
 
        /*
         * p_dev->function_config must be the same for all card functions.
-        * Note that this is serialized by the device_add_lock, so that
-        * only one such struct will be created.
+        * Note that this is serialized by ops_mutex, so that only one
+        * such struct will be created.
         */
        list_for_each_entry(tmp_dev, &s->devices_list, socket_device_list)
                if (p_dev->func == tmp_dev->func) {
@@ -552,28 +539,31 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
        /* Add to the list in pcmcia_bus_socket */
        list_add(&p_dev->socket_device_list, &s->devices_list);
 
-       mutex_unlock(&s->ops_mutex);
+       if (pcmcia_setup_irq(p_dev))
+               dev_warn(&p_dev->dev,
+                       "IRQ setup failed -- device might not work\n");
 
        if (!p_dev->function_config) {
                dev_dbg(&p_dev->dev, "creating config_t\n");
                p_dev->function_config = kzalloc(sizeof(struct config_t),
                                                 GFP_KERNEL);
-               if (!p_dev->function_config)
+               if (!p_dev->function_config) {
+                       mutex_unlock(&s->ops_mutex);
                        goto err_unreg;
+               }
                kref_init(&p_dev->function_config->ref);
        }
+       mutex_unlock(&s->ops_mutex);
 
        dev_printk(KERN_NOTICE, &p_dev->dev,
-                  "pcmcia: registering new device %s\n",
-                  p_dev->devname);
+                  "pcmcia: registering new device %s (IRQ: %d)\n",
+                  p_dev->devname, p_dev->irq);
 
        pcmcia_device_query(p_dev);
 
        if (device_register(&p_dev->dev))
                goto err_unreg;
 
-       mutex_unlock(&device_add_lock);
-
        return p_dev;
 
  err_unreg:
@@ -591,7 +581,6 @@ struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s, unsigned int fu
        kfree(p_dev->devname);
        kfree(p_dev);
  err_put:
-       mutex_unlock(&device_add_lock);
        pcmcia_put_socket(s);
 
        return NULL;
@@ -1258,6 +1247,7 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
                handle_event(skt, event);
                mutex_lock(&s->ops_mutex);
                destroy_cis_cache(s);
+               pcmcia_cleanup_irq(s);
                mutex_unlock(&s->ops_mutex);
                break;
 
index a7cfc79..0ad06a3 100644 (file)
@@ -117,7 +117,7 @@ static int omap_cf_get_status(struct pcmcia_socket *s, u_int *sp)
 
                *sp = SS_READY | SS_DETECT | SS_POWERON | SS_3VCARD;
                cf = container_of(s, struct omap_cf_socket, socket);
-               s->irq.AssignedIRQ = 0;
+               s->pcmcia_irq = 0;
                s->pci_irq = cf->irq;
        } else
                *sp = 0;
diff --git a/drivers/pcmcia/pcmcia_cis.c b/drivers/pcmcia/pcmcia_cis.c
new file mode 100644 (file)
index 0000000..4a65eaf
--- /dev/null
@@ -0,0 +1,356 @@
+/*
+ * PCMCIA high-level CIS access functions
+ *
+ * The initial developer of the original code is David A. Hinds
+ * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ *
+ * Copyright (C) 1999       David A. Hinds
+ * Copyright (C) 2004-2009   Dominik Brodowski
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/netdevice.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/ss.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/ds.h>
+#include "cs_internal.h"
+
+
+/**
+ * pccard_read_tuple() - internal CIS tuple access
+ * @s:         the struct pcmcia_socket where the card is inserted
+ * @function:  the device function we loop for
+ * @code:      which CIS code shall we look for?
+ * @parse:     buffer where the tuple shall be parsed (or NULL, if no parse)
+ *
+ * pccard_read_tuple() reads out one tuple and attempts to parse it
+ */
+int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
+               cisdata_t code, void *parse)
+{
+       tuple_t tuple;
+       cisdata_t *buf;
+       int ret;
+
+       buf = kmalloc(256, GFP_KERNEL);
+       if (buf == NULL) {
+               dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
+               return -ENOMEM;
+       }
+       tuple.DesiredTuple = code;
+       tuple.Attributes = 0;
+       if (function == BIND_FN_ALL)
+               tuple.Attributes = TUPLE_RETURN_COMMON;
+       ret = pccard_get_first_tuple(s, function, &tuple);
+       if (ret != 0)
+               goto done;
+       tuple.TupleData = buf;
+       tuple.TupleOffset = 0;
+       tuple.TupleDataMax = 255;
+       ret = pccard_get_tuple_data(s, &tuple);
+       if (ret != 0)
+               goto done;
+       ret = pcmcia_parse_tuple(&tuple, parse);
+done:
+       kfree(buf);
+       return ret;
+}
+
+
+/**
+ * pccard_loop_tuple() - loop over tuples in the CIS
+ * @s:         the struct pcmcia_socket where the card is inserted
+ * @function:  the device function we loop for
+ * @code:      which CIS code shall we look for?
+ * @parse:     buffer where the tuple shall be parsed (or NULL, if no parse)
+ * @priv_data: private data to be passed to the loop_tuple function.
+ * @loop_tuple:        function to call for each CIS entry of type @function. IT
+ *             gets passed the raw tuple, the paresed tuple (if @parse is
+ *             set) and @priv_data.
+ *
+ * pccard_loop_tuple() loops over all CIS entries of type @function, and
+ * calls the @loop_tuple function for each entry. If the call to @loop_tuple
+ * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
+ */
+int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
+                     cisdata_t code, cisparse_t *parse, void *priv_data,
+                     int (*loop_tuple) (tuple_t *tuple,
+                                        cisparse_t *parse,
+                                        void *priv_data))
+{
+       tuple_t tuple;
+       cisdata_t *buf;
+       int ret;
+
+       buf = kzalloc(256, GFP_KERNEL);
+       if (buf == NULL) {
+               dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
+               return -ENOMEM;
+       }
+
+       tuple.TupleData = buf;
+       tuple.TupleDataMax = 255;
+       tuple.TupleOffset = 0;
+       tuple.DesiredTuple = code;
+       tuple.Attributes = 0;
+
+       ret = pccard_get_first_tuple(s, function, &tuple);
+       while (!ret) {
+               if (pccard_get_tuple_data(s, &tuple))
+                       goto next_entry;
+
+               if (parse)
+                       if (pcmcia_parse_tuple(&tuple, parse))
+                               goto next_entry;
+
+               ret = loop_tuple(&tuple, parse, priv_data);
+               if (!ret)
+                       break;
+
+next_entry:
+               ret = pccard_get_next_tuple(s, function, &tuple);
+       }
+
+       kfree(buf);
+       return ret;
+}
+
+struct pcmcia_cfg_mem {
+       struct pcmcia_device *p_dev;
+       void *priv_data;
+       int (*conf_check) (struct pcmcia_device *p_dev,
+                          cistpl_cftable_entry_t *cfg,
+                          cistpl_cftable_entry_t *dflt,
+                          unsigned int vcc,
+                          void *priv_data);
+       cisparse_t parse;
+       cistpl_cftable_entry_t dflt;
+};
+
+/**
+ * pcmcia_do_loop_config() - internal helper for pcmcia_loop_config()
+ *
+ * pcmcia_do_loop_config() is the internal callback for the call from
+ * pcmcia_loop_config() to pccard_loop_tuple(). Data is transferred
+ * by a struct pcmcia_cfg_mem.
+ */
+static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
+{
+       cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
+       struct pcmcia_cfg_mem *cfg_mem = priv;
+
+       /* default values */
+       cfg_mem->p_dev->conf.ConfigIndex = cfg->index;
+       if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
+               cfg_mem->dflt = *cfg;
+
+       return cfg_mem->conf_check(cfg_mem->p_dev, cfg, &cfg_mem->dflt,
+                                  cfg_mem->p_dev->socket->socket.Vcc,
+                                  cfg_mem->priv_data);
+}
+
+/**
+ * pcmcia_loop_config() - loop over configuration options
+ * @p_dev:     the struct pcmcia_device which we need to loop for.
+ * @conf_check:        function to call for each configuration option.
+ *             It gets passed the struct pcmcia_device, the CIS data
+ *             describing the configuration option, and private data
+ *             being passed to pcmcia_loop_config()
+ * @priv_data: private data to be passed to the conf_check function.
+ *
+ * pcmcia_loop_config() loops over all configuration options, and calls
+ * the driver-specific conf_check() for each one, checking whether
+ * it is a valid one. Returns 0 on success or errorcode otherwise.
+ */
+int pcmcia_loop_config(struct pcmcia_device *p_dev,
+                      int      (*conf_check)   (struct pcmcia_device *p_dev,
+                                                cistpl_cftable_entry_t *cfg,
+                                                cistpl_cftable_entry_t *dflt,
+                                                unsigned int vcc,
+                                                void *priv_data),
+                      void *priv_data)
+{
+       struct pcmcia_cfg_mem *cfg_mem;
+       int ret;
+
+       cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
+       if (cfg_mem == NULL)
+               return -ENOMEM;
+
+       cfg_mem->p_dev = p_dev;
+       cfg_mem->conf_check = conf_check;
+       cfg_mem->priv_data = priv_data;
+
+       ret = pccard_loop_tuple(p_dev->socket, p_dev->func,
+                               CISTPL_CFTABLE_ENTRY, &cfg_mem->parse,
+                               cfg_mem, pcmcia_do_loop_config);
+
+       kfree(cfg_mem);
+       return ret;
+}
+EXPORT_SYMBOL(pcmcia_loop_config);
+
+
+struct pcmcia_loop_mem {
+       struct pcmcia_device *p_dev;
+       void *priv_data;
+       int (*loop_tuple) (struct pcmcia_device *p_dev,
+                          tuple_t *tuple,
+                          void *priv_data);
+};
+
+/**
+ * pcmcia_do_loop_tuple() - internal helper for pcmcia_loop_config()
+ *
+ * pcmcia_do_loop_tuple() is the internal callback for the call from
+ * pcmcia_loop_tuple() to pccard_loop_tuple(). Data is transferred
+ * by a struct pcmcia_cfg_mem.
+ */
+static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv)
+{
+       struct pcmcia_loop_mem *loop = priv;
+
+       return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
+};
+
+/**
+ * pcmcia_loop_tuple() - loop over tuples in the CIS
+ * @p_dev:     the struct pcmcia_device which we need to loop for.
+ * @code:      which CIS code shall we look for?
+ * @priv_data: private data to be passed to the loop_tuple function.
+ * @loop_tuple:        function to call for each CIS entry of type @function. IT
+ *             gets passed the raw tuple and @priv_data.
+ *
+ * pcmcia_loop_tuple() loops over all CIS entries of type @function, and
+ * calls the @loop_tuple function for each entry. If the call to @loop_tuple
+ * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
+ */
+int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
+                     int (*loop_tuple) (struct pcmcia_device *p_dev,
+                                        tuple_t *tuple,
+                                        void *priv_data),
+                     void *priv_data)
+{
+       struct pcmcia_loop_mem loop = {
+               .p_dev = p_dev,
+               .loop_tuple = loop_tuple,
+               .priv_data = priv_data};
+
+       return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL,
+                                &loop, pcmcia_do_loop_tuple);
+}
+EXPORT_SYMBOL(pcmcia_loop_tuple);
+
+
+struct pcmcia_loop_get {
+       size_t len;
+       cisdata_t **buf;
+};
+
+/**
+ * pcmcia_do_get_tuple() - internal helper for pcmcia_get_tuple()
+ *
+ * pcmcia_do_get_tuple() is the internal callback for the call from
+ * pcmcia_get_tuple() to pcmcia_loop_tuple(). As we're only interested in
+ * the first tuple, return 0 unconditionally. Create a memory buffer large
+ * enough to hold the content of the tuple, and fill it with the tuple data.
+ * The caller is responsible to free the buffer.
+ */
+static int pcmcia_do_get_tuple(struct pcmcia_device *p_dev, tuple_t *tuple,
+                              void *priv)
+{
+       struct pcmcia_loop_get *get = priv;
+
+       *get->buf = kzalloc(tuple->TupleDataLen, GFP_KERNEL);
+       if (*get->buf) {
+               get->len = tuple->TupleDataLen;
+               memcpy(*get->buf, tuple->TupleData, tuple->TupleDataLen);
+       } else
+               dev_dbg(&p_dev->dev, "do_get_tuple: out of memory\n");
+       return 0;
+}
+
+/**
+ * pcmcia_get_tuple() - get first tuple from CIS
+ * @p_dev:     the struct pcmcia_device which we need to loop for.
+ * @code:      which CIS code shall we look for?
+ * @buf:        pointer to store the buffer to.
+ *
+ * pcmcia_get_tuple() gets the content of the first CIS entry of type @code.
+ * It returns the buffer length (or zero). The caller is responsible to free
+ * the buffer passed in @buf.
+ */
+size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
+                       unsigned char **buf)
+{
+       struct pcmcia_loop_get get = {
+               .len = 0,
+               .buf = buf,
+       };
+
+       *get.buf = NULL;
+       pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &get);
+
+       return get.len;
+}
+EXPORT_SYMBOL(pcmcia_get_tuple);
+
+
+/**
+ * pcmcia_do_get_mac() - internal helper for pcmcia_get_mac_from_cis()
+ *
+ * pcmcia_do_get_mac() is the internal callback for the call from
+ * pcmcia_get_mac_from_cis() to pcmcia_loop_tuple(). We check whether the
+ * tuple contains a proper LAN_NODE_ID of length 6, and copy the data
+ * to struct net_device->dev_addr[i].
+ */
+static int pcmcia_do_get_mac(struct pcmcia_device *p_dev, tuple_t *tuple,
+                            void *priv)
+{
+       struct net_device *dev = priv;
+       int i;
+
+       if (tuple->TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID)
+               return -EINVAL;
+       if (tuple->TupleDataLen < ETH_ALEN + 2) {
+               dev_warn(&p_dev->dev, "Invalid CIS tuple length for "
+                       "LAN_NODE_ID\n");
+               return -EINVAL;
+       }
+
+       if (tuple->TupleData[1] != ETH_ALEN) {
+               dev_warn(&p_dev->dev, "Invalid header for LAN_NODE_ID\n");
+               return -EINVAL;
+       }
+       for (i = 0; i < 6; i++)
+               dev->dev_addr[i] = tuple->TupleData[i+2];
+       return 0;
+}
+
+/**
+ * pcmcia_get_mac_from_cis() - read out MAC address from CISTPL_FUNCE
+ * @p_dev:     the struct pcmcia_device for which we want the address.
+ * @dev:       a properly prepared struct net_device to store the info to.
+ *
+ * pcmcia_get_mac_from_cis() reads out the hardware MAC address from
+ * CISTPL_FUNCE and stores it into struct net_device *dev->dev_addr which
+ * must be set up properly by the driver (see examples!).
+ */
+int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, struct net_device *dev)
+{
+       return pcmcia_loop_tuple(p_dev, CISTPL_FUNCE, pcmcia_do_get_mac, dev);
+}
+EXPORT_SYMBOL(pcmcia_get_mac_from_cis);
+
index 7631faa..ef0c5f1 100644 (file)
@@ -301,7 +301,9 @@ static int pccard_get_status(struct pcmcia_socket *s,
            (c->IntType & (INT_MEMORY_AND_IO | INT_ZOOMED_VIDEO))) {
                u_char reg;
                if (c->CardValues & PRESENT_PIN_REPLACE) {
+                       mutex_lock(&s->ops_mutex);
                        pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_PRR)>>1, 1, &reg);
+                       mutex_unlock(&s->ops_mutex);
                        status->CardState |=
                                (reg & PRR_WP_STATUS) ? CS_EVENT_WRITE_PROTECT : 0;
                        status->CardState |=
@@ -315,7 +317,9 @@ static int pccard_get_status(struct pcmcia_socket *s,
                        status->CardState |= CS_EVENT_READY_CHANGE;
                }
                if (c->CardValues & PRESENT_EXT_STATUS) {
+                       mutex_lock(&s->ops_mutex);
                        pcmcia_read_cis_mem(s, 1, (c->ConfigBase+CISREG_ESR)>>1, 1, &reg);
+                       mutex_unlock(&s->ops_mutex);
                        status->CardState |=
                                (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
                }
@@ -351,7 +355,7 @@ static int pccard_get_configuration_info(struct pcmcia_socket *s,
                if (s->state & SOCKET_CARDBUS_CONFIG) {
                        config->Attributes = CONF_VALID_CLIENT;
                        config->IntType = INT_CARDBUS;
-                       config->AssignedIRQ = s->irq.AssignedIRQ;
+                       config->AssignedIRQ = s->pcmcia_irq;
                        if (config->AssignedIRQ)
                                config->Attributes |= CONF_ENABLE_IRQ;
                        if (s->io[0].res) {
@@ -391,7 +395,7 @@ static int pccard_get_configuration_info(struct pcmcia_socket *s,
        config->ExtStatus = c->ExtStatus;
        config->Present = config->CardValues = c->CardValues;
        config->IRQAttributes = c->irq.Attributes;
-       config->AssignedIRQ = s->irq.AssignedIRQ;
+       config->AssignedIRQ = s->pcmcia_irq;
        config->BasePort1 = c->io.BasePort1;
        config->NumPorts1 = c->io.NumPorts1;
        config->Attributes1 = c->io.Attributes1;
@@ -571,7 +575,6 @@ static struct pci_bus *pcmcia_lookup_bus(struct pcmcia_socket *s)
 
 static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int first)
 {
-       dev_node_t *node;
        struct pcmcia_device *p_dev;
        struct pcmcia_driver *p_drv;
        int ret = 0;
@@ -633,21 +636,13 @@ static int get_device_info(struct pcmcia_socket *s, bind_info_t *bind_info, int
                goto err_put;
        }
 
-       if (first)
-               node = p_dev->dev_node;
-       else
-               for (node = p_dev->dev_node; node; node = node->next)
-                       if (node == bind_info->next)
-                               break;
-       if (!node) {
+       if (!first) {
                ret = -ENODEV;
                goto err_put;
        }
 
-       strlcpy(bind_info->name, node->dev_name, DEV_NAME_LEN);
-       bind_info->major = node->major;
-       bind_info->minor = node->minor;
-       bind_info->next = node->next;
+       strlcpy(bind_info->name, dev_name(&p_dev->dev), DEV_NAME_LEN);
+       bind_info->next = NULL;
 
  err_put:
        pcmcia_put_dev(p_dev);
index 7c3d03b..29f91fa 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/netdevice.h>
 #include <linux/slab.h>
 
+#include <asm/irq.h>
+
 #include <pcmcia/cs_types.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cs.h>
@@ -38,29 +40,6 @@ static int io_speed;
 module_param(io_speed, int, 0444);
 
 
-#ifdef CONFIG_PCMCIA_PROBE
-#include <asm/irq.h>
-/* mask of IRQs already reserved by other cards, we should avoid using them */
-static u8 pcmcia_used_irq[NR_IRQS];
-#endif
-
-static int pcmcia_adjust_io_region(struct resource *res, unsigned long start,
-                                  unsigned long end, struct pcmcia_socket *s)
-{
-       if (s->resource_ops->adjust_io_region)
-               return s->resource_ops->adjust_io_region(res, start, end, s);
-       return -ENOMEM;
-}
-
-static struct resource *pcmcia_find_io_region(unsigned long base, int num,
-                                             unsigned long align,
-                                             struct pcmcia_socket *s)
-{
-       if (s->resource_ops->find_io)
-               return s->resource_ops->find_io(base, num, align, s);
-       return NULL;
-}
-
 int pcmcia_validate_mem(struct pcmcia_socket *s)
 {
        if (s->resource_ops->validate_mem)
@@ -86,8 +65,7 @@ struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
 static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
                          unsigned int *base, unsigned int num, u_int lines)
 {
-       int i;
-       unsigned int try, align;
+       unsigned int align;
 
        align = (*base) ? (lines ? 1<<lines : 0) : 1;
        if (align && (align < num)) {
@@ -104,50 +82,8 @@ static int alloc_io_space(struct pcmcia_socket *s, u_int attr,
                       *base, align);
                align = 0;
        }
-       if ((s->features & SS_CAP_STATIC_MAP) && s->io_offset) {
-               *base = s->io_offset | (*base & 0x0fff);
-               return 0;
-       }
-       /* Check for an already-allocated window that must conflict with
-        * what was asked for.  It is a hack because it does not catch all
-        * potential conflicts, just the most obvious ones.
-        */
-       for (i = 0; i < MAX_IO_WIN; i++)
-               if ((s->io[i].res) && *base &&
-                   ((s->io[i].res->start & (align-1)) == *base))
-                       return 1;
-       for (i = 0; i < MAX_IO_WIN; i++) {
-               if (!s->io[i].res) {
-                       s->io[i].res = pcmcia_find_io_region(*base, num, align, s);
-                       if (s->io[i].res) {
-                               *base = s->io[i].res->start;
-                               s->io[i].res->flags = (s->io[i].res->flags & ~IORESOURCE_BITS) | (attr & IORESOURCE_BITS);
-                               s->io[i].InUse = num;
-                               break;
-                       } else
-                               return 1;
-               } else if ((s->io[i].res->flags & IORESOURCE_BITS) != (attr & IORESOURCE_BITS))
-                       continue;
-               /* Try to extend top of window */
-               try = s->io[i].res->end + 1;
-               if ((*base == 0) || (*base == try))
-                       if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start,
-                                                   s->io[i].res->end + num, s) == 0) {
-                               *base = try;
-                               s->io[i].InUse += num;
-                               break;
-                       }
-               /* Try to extend bottom of window */
-               try = s->io[i].res->start - num;
-               if ((*base == 0) || (*base == try))
-                       if (pcmcia_adjust_io_region(s->io[i].res, s->io[i].res->start - num,
-                                                   s->io[i].res->end, s) == 0) {
-                               *base = try;
-                               s->io[i].InUse += num;
-                               break;
-                       }
-       }
-       return (i == MAX_IO_WIN);
+
+       return s->resource_ops->find_io(s, attr, base, num, align);
 } /* alloc_io_space */
 
 
@@ -187,6 +123,7 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
        config_t *c;
        int addr;
        u_char val;
+       int ret = 0;
 
        if (!p_dev || !p_dev->function_config)
                return -EINVAL;
@@ -203,11 +140,10 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
        }
 
        addr = (c->ConfigBase + reg->Offset) >> 1;
-       mutex_unlock(&s->ops_mutex);
 
        switch (reg->Action) {
        case CS_READ:
-               pcmcia_read_cis_mem(s, 1, addr, 1, &val);
+               ret = pcmcia_read_cis_mem(s, 1, addr, 1, &val);
                reg->Value = val;
                break;
        case CS_WRITE:
@@ -216,10 +152,11 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
                break;
        default:
                dev_dbg(&s->dev, "Invalid conf register request\n");
-               return -EINVAL;
+               ret = -EINVAL;
                break;
        }
-       return 0;
+       mutex_unlock(&s->ops_mutex);
+       return ret;
 } /* pcmcia_access_configuration_register */
 EXPORT_SYMBOL(pcmcia_access_configuration_register);
 
@@ -275,19 +212,9 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
                goto unlock;
        }
 
-       if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
-               if (mod->Attributes & CONF_ENABLE_IRQ) {
-                       c->Attributes |= CONF_ENABLE_IRQ;
-                       s->socket.io_irq = s->irq.AssignedIRQ;
-               } else {
-                       c->Attributes &= ~CONF_ENABLE_IRQ;
-                       s->socket.io_irq = 0;
-               }
-               s->ops->set_socket(s, &s->socket);
-       }
-
-       if (mod->Attributes & CONF_VCC_CHANGE_VALID) {
-               dev_dbg(&s->dev, "changing Vcc is not allowed at this time\n");
+       if (mod->Attributes & (CONF_IRQ_CHANGE_VALID | CONF_VCC_CHANGE_VALID)) {
+               dev_dbg(&s->dev,
+                       "changing Vcc or IRQ is not allowed at this time\n");
                ret = -EINVAL;
                goto unlock;
        }
@@ -422,52 +349,6 @@ out:
 } /* pcmcia_release_io */
 
 
-static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
-{
-       struct pcmcia_socket *s = p_dev->socket;
-       config_t *c;
-       int ret = -EINVAL;
-
-       mutex_lock(&s->ops_mutex);
-
-       c = p_dev->function_config;
-
-       if (!p_dev->_irq)
-               goto out;
-
-       p_dev->_irq = 0;
-
-       if (c->state & CONFIG_LOCKED)
-               goto out;
-
-       if (c->irq.Attributes != req->Attributes) {
-               dev_dbg(&s->dev, "IRQ attributes must match assigned ones\n");
-               goto out;
-       }
-       if (s->irq.AssignedIRQ != req->AssignedIRQ) {
-               dev_dbg(&s->dev, "IRQ must match assigned one\n");
-               goto out;
-       }
-       if (--s->irq.Config == 0) {
-               c->state &= ~CONFIG_IRQ_REQ;
-               s->irq.AssignedIRQ = 0;
-       }
-
-       if (req->Handler)
-               free_irq(req->AssignedIRQ, p_dev->priv);
-
-#ifdef CONFIG_PCMCIA_PROBE
-       pcmcia_used_irq[req->AssignedIRQ]--;
-#endif
-       ret = 0;
-
-out:
-       mutex_unlock(&s->ops_mutex);
-
-       return ret;
-} /* pcmcia_release_irq */
-
-
 int pcmcia_release_window(struct pcmcia_device *p_dev, window_handle_t wh)
 {
        struct pcmcia_socket *s = p_dev->socket;
@@ -551,12 +432,11 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
        if (req->Attributes & CONF_ENABLE_SPKR)
                s->socket.flags |= SS_SPKR_ENA;
        if (req->Attributes & CONF_ENABLE_IRQ)
-               s->socket.io_irq = s->irq.AssignedIRQ;
+               s->socket.io_irq = s->pcmcia_irq;
        else
                s->socket.io_irq = 0;
        s->ops->set_socket(s, &s->socket);
        s->lock_count++;
-       mutex_unlock(&s->ops_mutex);
 
        /* Set up CIS configuration registers */
        base = c->ConfigBase = req->ConfigBase;
@@ -574,9 +454,9 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
                        if (req->Present & PRESENT_IOBASE_0)
                                c->Option |= COR_ADDR_DECODE;
                }
-               if (c->state & CONFIG_IRQ_REQ)
-                       if (!(c->irq.Attributes & IRQ_FORCED_PULSE))
-                               c->Option |= COR_LEVEL_REQ;
+               if ((req->Attributes & CONF_ENABLE_IRQ) &&
+                       !(req->Attributes & CONF_ENABLE_PULSE_IRQ))
+                       c->Option |= COR_LEVEL_REQ;
                pcmcia_write_cis_mem(s, 1, (base + CISREG_COR)>>1, 1, &c->Option);
                mdelay(40);
        }
@@ -605,7 +485,6 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
 
        /* Configure I/O windows */
        if (c->state & CONFIG_IO_REQ) {
-               mutex_lock(&s->ops_mutex);
                iomap.speed = io_speed;
                for (i = 0; i < MAX_IO_WIN; i++)
                        if (s->io[i].res) {
@@ -624,11 +503,11 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
                                s->ops->set_io_map(s, &iomap);
                                s->io[i].Config++;
                        }
-               mutex_unlock(&s->ops_mutex);
        }
 
        c->state |= CONFIG_LOCKED;
        p_dev->_locked = 1;
+       mutex_unlock(&s->ops_mutex);
        return 0;
 } /* pcmcia_request_configuration */
 EXPORT_SYMBOL(pcmcia_request_configuration);
@@ -706,137 +585,176 @@ out:
 EXPORT_SYMBOL(pcmcia_request_io);
 
 
-/** pcmcia_request_irq
+/**
+ * pcmcia_request_irq() - attempt to request a IRQ for a PCMCIA device
  *
- * Request_irq() reserves an irq for this client.
+ * pcmcia_request_irq() is a wrapper around request_irq which will allow
+ * the PCMCIA core to clean up the registration in pcmcia_disable_device().
+ * Drivers are free to use request_irq() directly, but then they need to
+ * call free_irq themselfves, too. Also, only IRQF_SHARED capable IRQ
+ * handlers are allowed.
+ */
+int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
+                                   irq_handler_t handler)
+{
+       int ret;
+
+       if (!p_dev->irq)
+               return -EINVAL;
+
+       ret = request_irq(p_dev->irq, handler, IRQF_SHARED,
+                       p_dev->devname, p_dev->priv);
+       if (!ret)
+               p_dev->_irq = 1;
+
+       return ret;
+}
+EXPORT_SYMBOL(pcmcia_request_irq);
+
+
+/**
+ * pcmcia_request_exclusive_irq() - attempt to request an exclusive IRQ first
  *
- * Also, since Linux only reserves irq's when they are actually
- * hooked, we don't guarantee that an irq will still be available
- * when the configuration is locked.  Now that I think about it,
- * there might be a way to fix this using a dummy handler.
+ * pcmcia_request_exclusive_irq() is a wrapper around request_irq which
+ * attempts first to request an exclusive IRQ. If it fails, it also accepts
+ * a shared IRQ, but prints out a warning. PCMCIA drivers should allow for
+ * IRQ sharing and either use request_irq directly (then they need to call
+ * free_irq themselves, too), or the pcmcia_request_irq() function.
  */
+int __must_check
+__pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
+                       irq_handler_t handler)
+{
+       int ret;
+
+       if (!p_dev->irq)
+               return -EINVAL;
+
+       ret = request_irq(p_dev->irq, handler, 0, p_dev->devname, p_dev->priv);
+       if (ret) {
+               ret = pcmcia_request_irq(p_dev, handler);
+               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
+                       "request for exclusive IRQ could not be fulfilled.\n");
+               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
+                       "needs updating to supported shared IRQ lines.\n");
+       }
+       if (ret)
+               dev_printk(KERN_INFO, &p_dev->dev, "request_irq() failed\n");
+       else
+               p_dev->_irq = 1;
+
+       return ret;
+} /* pcmcia_request_exclusive_irq */
+EXPORT_SYMBOL(__pcmcia_request_exclusive_irq);
+
 
 #ifdef CONFIG_PCMCIA_PROBE
+
+/* mask of IRQs already reserved by other cards, we should avoid using them */
+static u8 pcmcia_used_irq[NR_IRQS];
+
 static irqreturn_t test_action(int cpl, void *dev_id)
 {
        return IRQ_NONE;
 }
-#endif
 
-int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
+/**
+ * pcmcia_setup_isa_irq() - determine whether an ISA IRQ can be used
+ * @p_dev - the associated PCMCIA device
+ *
+ * locking note: must be called with ops_mutex locked.
+ */
+static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
 {
        struct pcmcia_socket *s = p_dev->socket;
-       config_t *c;
-       int ret = -EINVAL, irq = 0;
-       int type;
+       unsigned int try, irq;
+       u32 mask = s->irq_mask;
+       int ret = -ENODEV;
 
-       mutex_lock(&s->ops_mutex);
+       for (try = 0; try < 64; try++) {
+               irq = try % 32;
 
-       if (!(s->state & SOCKET_PRESENT)) {
-               dev_dbg(&s->dev, "No card present\n");
-               goto out;
-       }
-       c = p_dev->function_config;
-       if (c->state & CONFIG_LOCKED) {
-               dev_dbg(&s->dev, "Configuration is locked\n");
-               goto out;
-       }
-       if (c->state & CONFIG_IRQ_REQ) {
-               dev_dbg(&s->dev, "IRQ already configured\n");
-               goto out;
+               /* marked as available by driver, not blocked by userspace? */
+               if (!((mask >> irq) & 1))
+                       continue;
+
+               /* avoid an IRQ which is already used by another PCMCIA card */
+               if ((try < 32) && pcmcia_used_irq[irq])
+                       continue;
+
+               /* register the correct driver, if possible, to check whether
+                * registering a dummy handle works, i.e. if the IRQ isn't
+                * marked as used by the kernel resource management core */
+               ret = request_irq(irq, test_action, type, p_dev->devname,
+                                 p_dev);
+               if (!ret) {
+                       free_irq(irq, p_dev);
+                       p_dev->irq = s->pcmcia_irq = irq;
+                       pcmcia_used_irq[irq]++;
+                       break;
+               }
        }
 
-       /* Decide what type of interrupt we are registering */
-       type = 0;
-       if (s->functions > 1)           /* All of this ought to be handled higher up */
-               type = IRQF_SHARED;
-       else if (req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)
-               type = IRQF_SHARED;
-       else
-               printk(KERN_WARNING "pcmcia: Driver needs updating to support IRQ sharing.\n");
+       return ret;
+}
 
-       /* If the interrupt is already assigned, it must be the same */
-       if (s->irq.AssignedIRQ != 0)
-               irq = s->irq.AssignedIRQ;
+void pcmcia_cleanup_irq(struct pcmcia_socket *s)
+{
+       pcmcia_used_irq[s->pcmcia_irq]--;
+       s->pcmcia_irq = 0;
+}
 
-#ifdef CONFIG_PCMCIA_PROBE
-       if (!irq) {
-               int try;
-               u32 mask = s->irq_mask;
-               void *data = p_dev; /* something unique to this device */
+#else /* CONFIG_PCMCIA_PROBE */
 
-               for (try = 0; try < 64; try++) {
-                       irq = try % 32;
+static int pcmcia_setup_isa_irq(struct pcmcia_device *p_dev, int type)
+{
+       return -EINVAL;
+}
 
-                       /* marked as available by driver, and not blocked by userspace? */
-                       if (!((mask >> irq) & 1))
-                               continue;
+void pcmcia_cleanup_irq(struct pcmcia_socket *s)
+{
+       s->pcmcia_irq = 0;
+       return;
+}
 
-                       /* avoid an IRQ which is already used by a PCMCIA card */
-                       if ((try < 32) && pcmcia_used_irq[irq])
-                               continue;
+#endif  /* CONFIG_PCMCIA_PROBE */
 
-                       /* register the correct driver, if possible, of check whether
-                        * registering a dummy handle works, i.e. if the IRQ isn't
-                        * marked as used by the kernel resource management core */
-                       ret = request_irq(irq,
-                                         (req->Handler) ? req->Handler : test_action,
-                                         type,
-                                         p_dev->devname,
-                                         (req->Handler) ? p_dev->priv : data);
-                       if (!ret) {
-                               if (!req->Handler)
-                                       free_irq(irq, data);
-                               break;
-                       }
-               }
-       }
-#endif
-       /* only assign PCI irq if no IRQ already assigned */
-       if (ret && !s->irq.AssignedIRQ) {
-               if (!s->pci_irq) {
-                       dev_printk(KERN_INFO, &s->dev, "no IRQ found\n");
-                       goto out;
-               }
-               type = IRQF_SHARED;
-               irq = s->pci_irq;
-       }
 
-       if (ret && req->Handler) {
-               ret = request_irq(irq, req->Handler, type,
-                                 p_dev->devname, p_dev->priv);
-               if (ret) {
-                       dev_printk(KERN_INFO, &s->dev,
-                               "request_irq() failed\n");
-                       goto out;
-               }
-       }
+/**
+ * pcmcia_setup_irq() - determine IRQ to be used for device
+ * @p_dev - the associated PCMCIA device
+ *
+ * locking note: must be called with ops_mutex locked.
+ */
+int pcmcia_setup_irq(struct pcmcia_device *p_dev)
+{
+       struct pcmcia_socket *s = p_dev->socket;
 
-       /* Make sure the fact the request type was overridden is passed back */
-       if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
-               req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
-               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
-                       "request for exclusive IRQ could not be fulfilled.\n");
-               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
-                       "needs updating to supported shared IRQ lines.\n");
+       if (p_dev->irq)
+               return 0;
+
+       /* already assigned? */
+       if (s->pcmcia_irq) {
+               p_dev->irq = s->pcmcia_irq;
+               return 0;
        }
-       c->irq.Attributes = req->Attributes;
-       s->irq.AssignedIRQ = req->AssignedIRQ = irq;
-       s->irq.Config++;
 
-       c->state |= CONFIG_IRQ_REQ;
-       p_dev->_irq = 1;
+       /* prefer an exclusive ISA irq */
+       if (!pcmcia_setup_isa_irq(p_dev, 0))
+               return 0;
 
-#ifdef CONFIG_PCMCIA_PROBE
-       pcmcia_used_irq[irq]++;
-#endif
+       /* but accept a shared ISA irq */
+       if (!pcmcia_setup_isa_irq(p_dev, IRQF_SHARED))
+               return 0;
 
-       ret = 0;
-out:
-       mutex_unlock(&s->ops_mutex);
-       return ret;
-} /* pcmcia_request_irq */
-EXPORT_SYMBOL(pcmcia_request_irq);
+       /* but use the PCI irq otherwise */
+       if (s->pci_irq) {
+               p_dev->irq = s->pcmcia_irq = s->pci_irq;
+               return 0;
+       }
+
+       return -EINVAL;
+}
 
 
 /** pcmcia_request_window
@@ -939,237 +857,9 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev)
 {
        pcmcia_release_configuration(p_dev);
        pcmcia_release_io(p_dev, &p_dev->io);
-       pcmcia_release_irq(p_dev, &p_dev->irq);
+       if (p_dev->_irq)
+               free_irq(p_dev->irq, p_dev->priv);
        if (p_dev->win)
                pcmcia_release_window(p_dev, p_dev->win);
 }
 EXPORT_SYMBOL(pcmcia_disable_device);
-
-
-struct pcmcia_cfg_mem {
-       struct pcmcia_device *p_dev;
-       void *priv_data;
-       int (*conf_check) (struct pcmcia_device *p_dev,
-                          cistpl_cftable_entry_t *cfg,
-                          cistpl_cftable_entry_t *dflt,
-                          unsigned int vcc,
-                          void *priv_data);
-       cisparse_t parse;
-       cistpl_cftable_entry_t dflt;
-};
-
-/**
- * pcmcia_do_loop_config() - internal helper for pcmcia_loop_config()
- *
- * pcmcia_do_loop_config() is the internal callback for the call from
- * pcmcia_loop_config() to pccard_loop_tuple(). Data is transferred
- * by a struct pcmcia_cfg_mem.
- */
-static int pcmcia_do_loop_config(tuple_t *tuple, cisparse_t *parse, void *priv)
-{
-       cistpl_cftable_entry_t *cfg = &parse->cftable_entry;
-       struct pcmcia_cfg_mem *cfg_mem = priv;
-
-       /* default values */
-       cfg_mem->p_dev->conf.ConfigIndex = cfg->index;
-       if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-               cfg_mem->dflt = *cfg;
-
-       return cfg_mem->conf_check(cfg_mem->p_dev, cfg, &cfg_mem->dflt,
-                                  cfg_mem->p_dev->socket->socket.Vcc,
-                                  cfg_mem->priv_data);
-}
-
-/**
- * pcmcia_loop_config() - loop over configuration options
- * @p_dev:     the struct pcmcia_device which we need to loop for.
- * @conf_check:        function to call for each configuration option.
- *             It gets passed the struct pcmcia_device, the CIS data
- *             describing the configuration option, and private data
- *             being passed to pcmcia_loop_config()
- * @priv_data: private data to be passed to the conf_check function.
- *
- * pcmcia_loop_config() loops over all configuration options, and calls
- * the driver-specific conf_check() for each one, checking whether
- * it is a valid one. Returns 0 on success or errorcode otherwise.
- */
-int pcmcia_loop_config(struct pcmcia_device *p_dev,
-                      int      (*conf_check)   (struct pcmcia_device *p_dev,
-                                                cistpl_cftable_entry_t *cfg,
-                                                cistpl_cftable_entry_t *dflt,
-                                                unsigned int vcc,
-                                                void *priv_data),
-                      void *priv_data)
-{
-       struct pcmcia_cfg_mem *cfg_mem;
-       int ret;
-
-       cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
-       if (cfg_mem == NULL)
-               return -ENOMEM;
-
-       cfg_mem->p_dev = p_dev;
-       cfg_mem->conf_check = conf_check;
-       cfg_mem->priv_data = priv_data;
-
-       ret = pccard_loop_tuple(p_dev->socket, p_dev->func,
-                               CISTPL_CFTABLE_ENTRY, &cfg_mem->parse,
-                               cfg_mem, pcmcia_do_loop_config);
-
-       kfree(cfg_mem);
-       return ret;
-}
-EXPORT_SYMBOL(pcmcia_loop_config);
-
-
-struct pcmcia_loop_mem {
-       struct pcmcia_device *p_dev;
-       void *priv_data;
-       int (*loop_tuple) (struct pcmcia_device *p_dev,
-                          tuple_t *tuple,
-                          void *priv_data);
-};
-
-/**
- * pcmcia_do_loop_tuple() - internal helper for pcmcia_loop_config()
- *
- * pcmcia_do_loop_tuple() is the internal callback for the call from
- * pcmcia_loop_tuple() to pccard_loop_tuple(). Data is transferred
- * by a struct pcmcia_cfg_mem.
- */
-static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv)
-{
-       struct pcmcia_loop_mem *loop = priv;
-
-       return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
-};
-
-/**
- * pcmcia_loop_tuple() - loop over tuples in the CIS
- * @p_dev:     the struct pcmcia_device which we need to loop for.
- * @code:      which CIS code shall we look for?
- * @priv_data: private data to be passed to the loop_tuple function.
- * @loop_tuple:        function to call for each CIS entry of type @function. IT
- *             gets passed the raw tuple and @priv_data.
- *
- * pcmcia_loop_tuple() loops over all CIS entries of type @function, and
- * calls the @loop_tuple function for each entry. If the call to @loop_tuple
- * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
- */
-int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
-                     int (*loop_tuple) (struct pcmcia_device *p_dev,
-                                        tuple_t *tuple,
-                                        void *priv_data),
-                     void *priv_data)
-{
-       struct pcmcia_loop_mem loop = {
-               .p_dev = p_dev,
-               .loop_tuple = loop_tuple,
-               .priv_data = priv_data};
-
-       return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL,
-                                &loop, pcmcia_do_loop_tuple);
-}
-EXPORT_SYMBOL(pcmcia_loop_tuple);
-
-
-struct pcmcia_loop_get {
-       size_t len;
-       cisdata_t **buf;
-};
-
-/**
- * pcmcia_do_get_tuple() - internal helper for pcmcia_get_tuple()
- *
- * pcmcia_do_get_tuple() is the internal callback for the call from
- * pcmcia_get_tuple() to pcmcia_loop_tuple(). As we're only interested in
- * the first tuple, return 0 unconditionally. Create a memory buffer large
- * enough to hold the content of the tuple, and fill it with the tuple data.
- * The caller is responsible to free the buffer.
- */
-static int pcmcia_do_get_tuple(struct pcmcia_device *p_dev, tuple_t *tuple,
-                              void *priv)
-{
-       struct pcmcia_loop_get *get = priv;
-
-       *get->buf = kzalloc(tuple->TupleDataLen, GFP_KERNEL);
-       if (*get->buf) {
-               get->len = tuple->TupleDataLen;
-               memcpy(*get->buf, tuple->TupleData, tuple->TupleDataLen);
-       } else
-               dev_dbg(&p_dev->dev, "do_get_tuple: out of memory\n");
-       return 0;
-}
-
-/**
- * pcmcia_get_tuple() - get first tuple from CIS
- * @p_dev:     the struct pcmcia_device which we need to loop for.
- * @code:      which CIS code shall we look for?
- * @buf:        pointer to store the buffer to.
- *
- * pcmcia_get_tuple() gets the content of the first CIS entry of type @code.
- * It returns the buffer length (or zero). The caller is responsible to free
- * the buffer passed in @buf.
- */
-size_t pcmcia_get_tuple(struct pcmcia_device *p_dev, cisdata_t code,
-                       unsigned char **buf)
-{
-       struct pcmcia_loop_get get = {
-               .len = 0,
-               .buf = buf,
-       };
-
-       *get.buf = NULL;
-       pcmcia_loop_tuple(p_dev, code, pcmcia_do_get_tuple, &get);
-
-       return get.len;
-}
-EXPORT_SYMBOL(pcmcia_get_tuple);
-
-
-/**
- * pcmcia_do_get_mac() - internal helper for pcmcia_get_mac_from_cis()
- *
- * pcmcia_do_get_mac() is the internal callback for the call from
- * pcmcia_get_mac_from_cis() to pcmcia_loop_tuple(). We check whether the
- * tuple contains a proper LAN_NODE_ID of length 6, and copy the data
- * to struct net_device->dev_addr[i].
- */
-static int pcmcia_do_get_mac(struct pcmcia_device *p_dev, tuple_t *tuple,
-                            void *priv)
-{
-       struct net_device *dev = priv;
-       int i;
-
-       if (tuple->TupleData[0] != CISTPL_FUNCE_LAN_NODE_ID)
-               return -EINVAL;
-       if (tuple->TupleDataLen < ETH_ALEN + 2) {
-               dev_warn(&p_dev->dev, "Invalid CIS tuple length for "
-                       "LAN_NODE_ID\n");
-               return -EINVAL;
-       }
-
-       if (tuple->TupleData[1] != ETH_ALEN) {
-               dev_warn(&p_dev->dev, "Invalid header for LAN_NODE_ID\n");
-               return -EINVAL;
-       }
-       for (i = 0; i < 6; i++)
-               dev->dev_addr[i] = tuple->TupleData[i+2];
-       return 0;
-}
-
-/**
- * pcmcia_get_mac_from_cis() - read out MAC address from CISTPL_FUNCE
- * @p_dev:     the struct pcmcia_device for which we want the address.
- * @dev:       a properly prepared struct net_device to store the info to.
- *
- * pcmcia_get_mac_from_cis() reads out the hardware MAC address from
- * CISTPL_FUNCE and stores it into struct net_device *dev->dev_addr which
- * must be set up properly by the driver (see examples!).
- */
-int pcmcia_get_mac_from_cis(struct pcmcia_device *p_dev, struct net_device *dev)
-{
-       return pcmcia_loop_tuple(p_dev, CISTPL_FUNCE, pcmcia_do_get_mac, dev);
-}
-EXPORT_SYMBOL(pcmcia_get_mac_from_cis);
-
diff --git a/drivers/pcmcia/pxa2xx_vpac270.c b/drivers/pcmcia/pxa2xx_vpac270.c
new file mode 100644 (file)
index 0000000..55627ec
--- /dev/null
@@ -0,0 +1,229 @@
+/*
+ * linux/drivers/pcmcia/pxa2xx_vpac270.c
+ *
+ * Driver for Voipac PXA270 PCMCIA and CF sockets
+ *
+ * Copyright (C) 2010
+ * Marek Vasut <marek.vasut@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+
+#include <asm/mach-types.h>
+
+#include <mach/gpio.h>
+#include <mach/vpac270.h>
+
+#include "soc_common.h"
+
+static struct pcmcia_irqs cd_irqs[] = {
+       {
+               .sock = 0,
+               .irq  = IRQ_GPIO(GPIO84_VPAC270_PCMCIA_CD),
+               .str  = "PCMCIA CD"
+       },
+       {
+               .sock = 1,
+               .irq  = IRQ_GPIO(GPIO17_VPAC270_CF_CD),
+               .str  = "CF CD"
+       },
+};
+
+static int vpac270_pcmcia_hw_init(struct soc_pcmcia_socket *skt)
+{
+       int ret;
+
+       if (skt->nr == 0) {
+               ret = gpio_request(GPIO84_VPAC270_PCMCIA_CD, "PCMCIA CD");
+               if (ret)
+                       goto err1;
+               ret = gpio_direction_input(GPIO84_VPAC270_PCMCIA_CD);
+               if (ret)
+                       goto err2;
+
+               ret = gpio_request(GPIO35_VPAC270_PCMCIA_RDY, "PCMCIA RDY");
+               if (ret)
+                       goto err2;
+               ret = gpio_direction_input(GPIO35_VPAC270_PCMCIA_RDY);
+               if (ret)
+                       goto err3;
+
+               ret = gpio_request(GPIO107_VPAC270_PCMCIA_PPEN, "PCMCIA PPEN");
+               if (ret)
+                       goto err3;
+               ret = gpio_direction_output(GPIO107_VPAC270_PCMCIA_PPEN, 0);
+               if (ret)
+                       goto err4;
+
+               ret = gpio_request(GPIO11_VPAC270_PCMCIA_RESET, "PCMCIA RESET");
+               if (ret)
+                       goto err4;
+               ret = gpio_direction_output(GPIO11_VPAC270_PCMCIA_RESET, 0);
+               if (ret)
+                       goto err5;
+
+               skt->socket.pci_irq = gpio_to_irq(GPIO35_VPAC270_PCMCIA_RDY);
+
+               return soc_pcmcia_request_irqs(skt, &cd_irqs[0], 1);
+
+err5:
+               gpio_free(GPIO11_VPAC270_PCMCIA_RESET);
+err4:
+               gpio_free(GPIO107_VPAC270_PCMCIA_PPEN);
+err3:
+               gpio_free(GPIO35_VPAC270_PCMCIA_RDY);
+err2:
+               gpio_free(GPIO84_VPAC270_PCMCIA_CD);
+err1:
+               return ret;
+
+       } else {
+               ret = gpio_request(GPIO17_VPAC270_CF_CD, "CF CD");
+               if (ret)
+                       goto err6;
+               ret = gpio_direction_input(GPIO17_VPAC270_CF_CD);
+               if (ret)
+                       goto err7;
+
+               ret = gpio_request(GPIO12_VPAC270_CF_RDY, "CF RDY");
+               if (ret)
+                       goto err7;
+               ret = gpio_direction_input(GPIO12_VPAC270_CF_RDY);
+               if (ret)
+                       goto err8;
+
+               ret = gpio_request(GPIO16_VPAC270_CF_RESET, "CF RESET");
+               if (ret)
+                       goto err8;
+               ret = gpio_direction_output(GPIO16_VPAC270_CF_RESET, 0);
+               if (ret)
+                       goto err9;
+
+               skt->socket.pci_irq = gpio_to_irq(GPIO12_VPAC270_CF_RDY);
+
+               return soc_pcmcia_request_irqs(skt, &cd_irqs[1], 1);
+
+err9:
+               gpio_free(GPIO16_VPAC270_CF_RESET);
+err8:
+               gpio_free(GPIO12_VPAC270_CF_RDY);
+err7:
+               gpio_free(GPIO17_VPAC270_CF_CD);
+err6:
+               return ret;
+
+       }
+}
+
+static void vpac270_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt)
+{
+       gpio_free(GPIO11_VPAC270_PCMCIA_RESET);
+       gpio_free(GPIO107_VPAC270_PCMCIA_PPEN);
+       gpio_free(GPIO35_VPAC270_PCMCIA_RDY);
+       gpio_free(GPIO84_VPAC270_PCMCIA_CD);
+       gpio_free(GPIO16_VPAC270_CF_RESET);
+       gpio_free(GPIO12_VPAC270_CF_RDY);
+       gpio_free(GPIO17_VPAC270_CF_CD);
+}
+
+static void vpac270_pcmcia_socket_state(struct soc_pcmcia_socket *skt,
+                                       struct pcmcia_state *state)
+{
+       if (skt->nr == 0) {
+               state->detect = !gpio_get_value(GPIO84_VPAC270_PCMCIA_CD);
+               state->ready  = !!gpio_get_value(GPIO35_VPAC270_PCMCIA_RDY);
+       } else {
+               state->detect = !gpio_get_value(GPIO17_VPAC270_CF_CD);
+               state->ready  = !!gpio_get_value(GPIO12_VPAC270_CF_RDY);
+       }
+       state->bvd1   = 1;
+       state->bvd2   = 1;
+       state->wrprot = 0;
+       state->vs_3v  = 1;
+       state->vs_Xv  = 0;
+}
+
+static int
+vpac270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt,
+                               const socket_state_t *state)
+{
+       if (skt->nr == 0) {
+               gpio_set_value(GPIO11_VPAC270_PCMCIA_RESET,
+                       (state->flags & SS_RESET));
+               gpio_set_value(GPIO107_VPAC270_PCMCIA_PPEN,
+                       !(state->Vcc == 33 || state->Vcc == 50));
+       } else {
+               gpio_set_value(GPIO16_VPAC270_CF_RESET,
+                       (state->flags & SS_RESET));
+       }
+
+       return 0;
+}
+
+static void vpac270_pcmcia_socket_init(struct soc_pcmcia_socket *skt)
+{
+}
+
+static void vpac270_pcmcia_socket_suspend(struct soc_pcmcia_socket *skt)
+{
+}
+
+static struct pcmcia_low_level vpac270_pcmcia_ops = {
+       .owner                  = THIS_MODULE,
+
+       .first                  = 0,
+       .nr                     = 2,
+
+       .hw_init                = vpac270_pcmcia_hw_init,
+       .hw_shutdown            = vpac270_pcmcia_hw_shutdown,
+
+       .socket_state           = vpac270_pcmcia_socket_state,
+       .configure_socket       = vpac270_pcmcia_configure_socket,
+
+       .socket_init            = vpac270_pcmcia_socket_init,
+       .socket_suspend         = vpac270_pcmcia_socket_suspend,
+};
+
+static struct platform_device *vpac270_pcmcia_device;
+
+static int __init vpac270_pcmcia_init(void)
+{
+       int ret;
+
+       if (!machine_is_vpac270())
+               return -ENODEV;
+
+       vpac270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1);
+       if (!vpac270_pcmcia_device)
+               return -ENOMEM;
+
+       ret = platform_device_add_data(vpac270_pcmcia_device,
+               &vpac270_pcmcia_ops, sizeof(vpac270_pcmcia_ops));
+
+       if (!ret)
+               ret = platform_device_add(vpac270_pcmcia_device);
+
+       if (ret)
+               platform_device_put(vpac270_pcmcia_device);
+
+       return ret;
+}
+
+static void __exit vpac270_pcmcia_exit(void)
+{
+       platform_device_unregister(vpac270_pcmcia_device);
+}
+
+module_init(vpac270_pcmcia_init);
+module_exit(vpac270_pcmcia_exit);
+
+MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
+MODULE_DESCRIPTION("PCMCIA support for Voipac PXA270");
+MODULE_ALIAS("platform:pxa2xx-pcmcia");
+MODULE_LICENSE("GPL");
diff --git a/drivers/pcmcia/rsrc_iodyn.c b/drivers/pcmcia/rsrc_iodyn.c
new file mode 100644 (file)
index 0000000..d0bf350
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * rsrc_iodyn.c -- Resource management routines for MEM-static sockets.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * The initial developer of the original code is David A. Hinds
+ * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
+ * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
+ *
+ * (C) 1999            David A. Hinds
+ */
+
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/ss.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include "cs_internal.h"
+
+
+struct pcmcia_align_data {
+       unsigned long   mask;
+       unsigned long   offset;
+};
+
+static resource_size_t pcmcia_align(void *align_data,
+                               const struct resource *res,
+                               resource_size_t size, resource_size_t align)
+{
+       struct pcmcia_align_data *data = align_data;
+       resource_size_t start;
+
+       start = (res->start & ~data->mask) + data->offset;
+       if (start < res->start)
+               start += data->mask + 1;
+
+#ifdef CONFIG_X86
+       if (res->flags & IORESOURCE_IO) {
+               if (start & 0x300)
+                       start = (start + 0x3ff) & ~0x3ff;
+       }
+#endif
+
+#ifdef CONFIG_M68K
+       if (res->flags & IORESOURCE_IO) {
+               if ((res->start + size - 1) >= 1024)
+                       start = res->end;
+       }
+#endif
+
+       return start;
+}
+
+
+static struct resource *__iodyn_find_io_region(struct pcmcia_socket *s,
+                                       unsigned long base, int num,
+                                       unsigned long align)
+{
+       struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_IO,
+                                               dev_name(&s->dev));
+       struct pcmcia_align_data data;
+       unsigned long min = base;
+       int ret;
+
+       data.mask = align - 1;
+       data.offset = base & data.mask;
+
+#ifdef CONFIG_PCI
+       if (s->cb_dev) {
+               ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
+                                            min, 0, pcmcia_align, &data);
+       } else
+#endif
+               ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
+                                       1, pcmcia_align, &data);
+
+       if (ret != 0) {
+               kfree(res);
+               res = NULL;
+       }
+       return res;
+}
+
+static int iodyn_find_io(struct pcmcia_socket *s, unsigned int attr,
+                       unsigned int *base, unsigned int num,
+                       unsigned int align)
+{
+       int i, ret = 0;
+
+       /* Check for an already-allocated window that must conflict with
+        * what was asked for.  It is a hack because it does not catch all
+        * potential conflicts, just the most obvious ones.
+        */
+       for (i = 0; i < MAX_IO_WIN; i++) {
+               if (!s->io[i].res)
+                       continue;
+
+               if (!*base)
+                       continue;
+
+               if ((s->io[i].res->start & (align-1)) == *base)
+                       return -EBUSY;
+       }
+
+       for (i = 0; i < MAX_IO_WIN; i++) {
+               struct resource *res = s->io[i].res;
+               unsigned int try;
+
+               if (res && (res->flags & IORESOURCE_BITS) !=
+                       (attr & IORESOURCE_BITS))
+                       continue;
+
+               if (!res) {
+                       if (align == 0)
+                               align = 0x10000;
+
+                       res = s->io[i].res = __iodyn_find_io_region(s, *base,
+                                                               num, align);
+                       if (!res)
+                               return -EINVAL;
+
+                       *base = res->start;
+                       s->io[i].res->flags =
+                               ((res->flags & ~IORESOURCE_BITS) |
+                                       (attr & IORESOURCE_BITS));
+                       s->io[i].InUse = num;
+                       return 0;
+               }
+
+               /* Try to extend top of window */
+               try = res->end + 1;
+               if ((*base == 0) || (*base == try)) {
+                       if (adjust_resource(s->io[i].res, res->start,
+                                       res->end - res->start + num + 1))
+                               continue;
+                       *base = try;
+                       s->io[i].InUse += num;
+                       return 0;
+               }
+
+               /* Try to extend bottom of window */
+               try = res->start - num;
+               if ((*base == 0) || (*base == try)) {
+                       if (adjust_resource(s->io[i].res,
+                                       res->start - num,
+                                       res->end - res->start + num + 1))
+                               continue;
+                       *base = try;
+                       s->io[i].InUse += num;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+
+struct pccard_resource_ops pccard_iodyn_ops = {
+       .validate_mem = NULL,
+       .find_io = iodyn_find_io,
+       .find_mem = NULL,
+       .add_io = NULL,
+       .add_mem = NULL,
+       .init = static_init,
+       .exit = NULL,
+};
+EXPORT_SYMBOL(pccard_iodyn_ops);
index ffa5f3c..142efac 100644 (file)
@@ -22,7 +22,7 @@
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
-static int static_init(struct pcmcia_socket *s)
+int static_init(struct pcmcia_socket *s)
 {
        /* the good thing about SS_CAP_STATIC_MAP sockets is
         * that they don't need a resource database */
@@ -32,118 +32,44 @@ static int static_init(struct pcmcia_socket *s)
        return 0;
 }
 
-
-struct pccard_resource_ops pccard_static_ops = {
-       .validate_mem = NULL,
-       .adjust_io_region = NULL,
-       .find_io = NULL,
-       .find_mem = NULL,
-       .add_io = NULL,
-       .add_mem = NULL,
-       .init = static_init,
-       .exit = NULL,
-};
-EXPORT_SYMBOL(pccard_static_ops);
-
-
-#ifdef CONFIG_PCCARD_IODYN
-
-static struct resource *
-make_resource(unsigned long b, unsigned long n, int flags, char *name)
+struct resource *pcmcia_make_resource(unsigned long start, unsigned long end,
+                               int flags, const char *name)
 {
        struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
 
        if (res) {
                res->name = name;
-               res->start = b;
-               res->end = b + n - 1;
+               res->start = start;
+               res->end = start + end - 1;
                res->flags = flags;
        }
        return res;
 }
 
-struct pcmcia_align_data {
-       unsigned long   mask;
-       unsigned long   offset;
-};
-
-static resource_size_t pcmcia_align(void *align_data,
-                               const struct resource *res,
-                               resource_size_t size, resource_size_t align)
+static int static_find_io(struct pcmcia_socket *s, unsigned int attr,
+                       unsigned int *base, unsigned int num,
+                       unsigned int align)
 {
-       struct pcmcia_align_data *data = align_data;
-       resource_size_t start;
+       if (!s->io_offset)
+               return -EINVAL;
+       *base = s->io_offset | (*base & 0x0fff);
 
-       start = (res->start & ~data->mask) + data->offset;
-       if (start < res->start)
-               start += data->mask + 1;
-
-#ifdef CONFIG_X86
-       if (res->flags & IORESOURCE_IO) {
-               if (start & 0x300)
-                       start = (start + 0x3ff) & ~0x3ff;
-       }
-#endif
-
-#ifdef CONFIG_M68K
-       if (res->flags & IORESOURCE_IO) {
-               if ((res->start + size - 1) >= 1024)
-                       start = res->end;
-       }
-#endif
-
-       return start;
-}
-
-
-static int iodyn_adjust_io_region(struct resource *res, unsigned long r_start,
-                                     unsigned long r_end, struct pcmcia_socket *s)
-{
-       return adjust_resource(res, r_start, r_end - r_start + 1);
+       return 0;
 }
 
 
-static struct resource *iodyn_find_io_region(unsigned long base, int num,
-               unsigned long align, struct pcmcia_socket *s)
-{
-       struct resource *res = make_resource(0, num, IORESOURCE_IO,
-                                            dev_name(&s->dev));
-       struct pcmcia_align_data data;
-       unsigned long min = base;
-       int ret;
-
-       if (align == 0)
-               align = 0x10000;
-
-       data.mask = align - 1;
-       data.offset = base & data.mask;
-
-#ifdef CONFIG_PCI
-       if (s->cb_dev) {
-               ret = pci_bus_alloc_resource(s->cb_dev->bus, res, num, 1,
-                                            min, 0, pcmcia_align, &data);
-       } else
-#endif
-               ret = allocate_resource(&ioport_resource, res, num, min, ~0UL,
-                                       1, pcmcia_align, &data);
-
-       if (ret != 0) {
-               kfree(res);
-               res = NULL;
-       }
-       return res;
-}
-
-struct pccard_resource_ops pccard_iodyn_ops = {
+struct pccard_resource_ops pccard_static_ops = {
        .validate_mem = NULL,
-       .adjust_io_region = iodyn_adjust_io_region,
-       .find_io = iodyn_find_io_region,
+       .find_io = static_find_io,
        .find_mem = NULL,
        .add_io = NULL,
        .add_mem = NULL,
        .init = static_init,
        .exit = NULL,
 };
-EXPORT_SYMBOL(pccard_iodyn_ops);
+EXPORT_SYMBOL(pccard_static_ops);
+
 
-#endif /* CONFIG_PCCARD_IODYN */
+MODULE_AUTHOR("David A. Hinds, Dominik Brodowski");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("rsrc_nonstatic");
index a6eb7b5..dcd1a4a 100644 (file)
 #include <pcmcia/cistpl.h>
 #include "cs_internal.h"
 
+/* moved to rsrc_mgr.c
 MODULE_AUTHOR("David A. Hinds, Dominik Brodowski");
 MODULE_LICENSE("GPL");
+*/
 
 /* Parameters that can be set with 'insmod' */
 
@@ -69,20 +71,6 @@ struct socket_data {
 
 ======================================================================*/
 
-static struct resource *
-make_resource(resource_size_t b, resource_size_t n, int flags, const char *name)
-{
-       struct resource *res = kzalloc(sizeof(*res), GFP_KERNEL);
-
-       if (res) {
-               res->name = name;
-               res->start = b;
-               res->end = b + n - 1;
-               res->flags = flags;
-       }
-       return res;
-}
-
 static struct resource *
 claim_region(struct pcmcia_socket *s, resource_size_t base,
                resource_size_t size, int type, char *name)
@@ -90,7 +78,7 @@ claim_region(struct pcmcia_socket *s, resource_size_t base,
        struct resource *res, *parent;
 
        parent = type & IORESOURCE_MEM ? &iomem_resource : &ioport_resource;
-       res = make_resource(base, size, type | IORESOURCE_BUSY, name);
+       res = pcmcia_make_resource(base, size, type | IORESOURCE_BUSY, name);
 
        if (res) {
 #ifdef CONFIG_PCI
@@ -661,8 +649,9 @@ pcmcia_align(void *align_data, const struct resource *res,
  * Adjust an existing IO region allocation, but making sure that we don't
  * encroach outside the resources which the user supplied.
  */
-static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_start,
-                                     unsigned long r_end, struct pcmcia_socket *s)
+static int __nonstatic_adjust_io_region(struct pcmcia_socket *s,
+                                       unsigned long r_start,
+                                       unsigned long r_end)
 {
        struct resource_map *m;
        struct socket_data *s_data = s->resource_data;
@@ -675,8 +664,7 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
                if (start > r_start || r_end > end)
                        continue;
 
-               ret = adjust_resource(res, r_start, r_end - r_start + 1);
-               break;
+               ret = 0;
        }
 
        return ret;
@@ -695,18 +683,17 @@ static int nonstatic_adjust_io_region(struct resource *res, unsigned long r_star
 
 ======================================================================*/
 
-static struct resource *nonstatic_find_io_region(unsigned long base, int num,
-                  unsigned long align, struct pcmcia_socket *s)
+static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s,
+                                               unsigned long base, int num,
+                                               unsigned long align)
 {
-       struct resource *res = make_resource(0, num, IORESOURCE_IO, dev_name(&s->dev));
+       struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_IO,
+                                               dev_name(&s->dev));
        struct socket_data *s_data = s->resource_data;
        struct pcmcia_align_data data;
        unsigned long min = base;
        int ret;
 
-       if (align == 0)
-               align = 0x10000;
-
        data.mask = align - 1;
        data.offset = base & data.mask;
        data.map = &s_data->io_db;
@@ -727,10 +714,97 @@ static struct resource *nonstatic_find_io_region(unsigned long base, int num,
        return res;
 }
 
+static int nonstatic_find_io(struct pcmcia_socket *s, unsigned int attr,
+                       unsigned int *base, unsigned int num,
+                       unsigned int align)
+{
+       int i, ret = 0;
+
+       /* Check for an already-allocated window that must conflict with
+        * what was asked for.  It is a hack because it does not catch all
+        * potential conflicts, just the most obvious ones.
+        */
+       for (i = 0; i < MAX_IO_WIN; i++) {
+               if (!s->io[i].res)
+                       continue;
+
+               if (!*base)
+                       continue;
+
+               if ((s->io[i].res->start & (align-1)) == *base)
+                       return -EBUSY;
+       }
+
+       for (i = 0; i < MAX_IO_WIN; i++) {
+               struct resource *res = s->io[i].res;
+               unsigned int try;
+
+               if (res && (res->flags & IORESOURCE_BITS) !=
+                       (attr & IORESOURCE_BITS))
+                       continue;
+
+               if (!res) {
+                       if (align == 0)
+                               align = 0x10000;
+
+                       res = s->io[i].res = __nonstatic_find_io_region(s,
+                                                               *base, num,
+                                                               align);
+                       if (!res)
+                               return -EINVAL;
+
+                       *base = res->start;
+                       s->io[i].res->flags =
+                               ((res->flags & ~IORESOURCE_BITS) |
+                                       (attr & IORESOURCE_BITS));
+                       s->io[i].InUse = num;
+                       return 0;
+               }
+
+               /* Try to extend top of window */
+               try = res->end + 1;
+               if ((*base == 0) || (*base == try)) {
+                       ret =  __nonstatic_adjust_io_region(s, res->start,
+                                                       res->end + num);
+                       if (!ret) {
+                               ret = adjust_resource(s->io[i].res, res->start,
+                                              res->end - res->start + num + 1);
+                               if (ret)
+                                       continue;
+                               *base = try;
+                               s->io[i].InUse += num;
+                               return 0;
+                       }
+               }
+
+               /* Try to extend bottom of window */
+               try = res->start - num;
+               if ((*base == 0) || (*base == try)) {
+                       ret =  __nonstatic_adjust_io_region(s,
+                                                       res->start - num,
+                                                       res->end);
+                       if (!ret) {
+                               ret = adjust_resource(s->io[i].res,
+                                              res->start - num,
+                                              res->end - res->start + num + 1);
+                               if (ret)
+                                       continue;
+                               *base = try;
+                               s->io[i].InUse += num;
+                               return 0;
+                       }
+               }
+       }
+
+       return -EINVAL;
+}
+
+
 static struct resource *nonstatic_find_mem_region(u_long base, u_long num,
                u_long align, int low, struct pcmcia_socket *s)
 {
-       struct resource *res = make_resource(0, num, IORESOURCE_MEM, dev_name(&s->dev));
+       struct resource *res = pcmcia_make_resource(0, num, IORESOURCE_MEM,
+                                               dev_name(&s->dev));
        struct socket_data *s_data = s->resource_data;
        struct pcmcia_align_data data;
        unsigned long min, max;
@@ -861,23 +935,42 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
                return -ENODEV;
 
 #if defined(CONFIG_X86)
-       /* If this is the root bus, the risk of hitting
-        * some strange system devices which aren't protected
-        * by either ACPI resource tables or properly requested
-        * resources is too big. Therefore, don't do auto-adding
-        * of resources at the moment.
+       /* If this is the root bus, the risk of hitting some strange
+        * system devices is too high: If a driver isn't loaded, the
+        * resources are not claimed; even if a driver is loaded, it
+        * may not request all resources or even the wrong one. We
+        * can neither trust the rest of the kernel nor ACPI/PNP and
+        * CRS parsing to get it right. Therefore, use several
+        * safeguards:
+        *
+        * - Do not auto-add resources if the CardBus bridge is on
+        *   the PCI root bus
+        *
+        * - Avoid any I/O ports < 0x100.
+        *
+        * - On PCI-PCI bridges, only use resources which are set up
+        *   exclusively for the secondary PCI bus: the risk of hitting
+        *   system devices is quite low, as they usually aren't
+        *   connected to the secondary PCI bus.
         */
        if (s->cb_dev->bus->number == 0)
                return -EINVAL;
-#endif
 
+       for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {
+               res = s->cb_dev->bus->resource[i];
+#else
        pci_bus_for_each_resource(s->cb_dev->bus, res, i) {
+#endif
                if (!res)
                        continue;
 
                if (res->flags & IORESOURCE_IO) {
+                       /* safeguard against the root resource, where the
+                        * risk of hitting any other device would be too
+                        * high */
                        if (res == &ioport_resource)
                                continue;
+
                        dev_printk(KERN_INFO, &s->cb_dev->dev,
                                   "pcmcia: parent PCI bridge window: %pR\n",
                                   res);
@@ -887,8 +980,12 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
                }
 
                if (res->flags & IORESOURCE_MEM) {
+                       /* safeguard against the root resource, where the
+                        * risk of hitting any other device would be too
+                        * high */
                        if (res == &iomem_resource)
                                continue;
+
                        dev_printk(KERN_INFO, &s->cb_dev->dev,
                                   "pcmcia: parent PCI bridge window: %pR\n",
                                   res);
@@ -956,8 +1053,7 @@ static void nonstatic_release_resource_db(struct pcmcia_socket *s)
 
 struct pccard_resource_ops pccard_nonstatic_ops = {
        .validate_mem = pcmcia_nonstatic_validate_mem,
-       .adjust_io_region = nonstatic_adjust_io_region,
-       .find_io = nonstatic_find_io_region,
+       .find_io = nonstatic_find_io,
        .find_mem = nonstatic_find_mem_region,
        .add_io = adjust_io,
        .add_mem = adjust_memory,
index 83ace27..424e576 100644 (file)
@@ -1303,13 +1303,6 @@ static int yenta_dev_suspend_noirq(struct device *dev)
        pci_read_config_dword(pdev, 17*4, &socket->saved_state[1]);
        pci_disable_device(pdev);
 
-       /*
-        * Some laptops (IBM T22) do not like us putting the Cardbus
-        * bridge into D3.  At a guess, some other laptop will
-        * probably require this, so leave it commented out for now.
-        */
-       /* pci_set_power_state(dev, 3); */
-
        return 0;
 }
 
index 3cbaf18..d37c445 100644 (file)
@@ -119,7 +119,7 @@ enum ps3_sys_manager_service_id {
  * enum ps3_sys_manager_attr - Notification attribute (bit position mask).
  * @PS3_SM_ATTR_POWER: Power button.
  * @PS3_SM_ATTR_RESET: Reset button, not available on retail console.
- * @PS3_SM_ATTR_THERMAL: Sytem thermal alert.
+ * @PS3_SM_ATTR_THERMAL: System thermal alert.
  * @PS3_SM_ATTR_CONTROLLER: Remote controller event.
  * @PS3_SM_ATTR_ALL: Logical OR of all.
  *
index 2b4e40d..51cf2bb 100644 (file)
@@ -1540,7 +1540,7 @@ EXPORT_SYMBOL_GPL(regulator_count_voltages);
  * Context: can sleep
  *
  * Returns a voltage that can be passed to @regulator_set_voltage(),
- * zero if this selector code can't be used on this sytem, or a
+ * zero if this selector code can't be used on this system, or a
  * negative errno.
  */
 int regulator_list_voltage(struct regulator *regulator, unsigned selector)
index 6a13037..50ac047 100644 (file)
@@ -620,6 +620,16 @@ config RTC_DRV_NUC900
 
 comment "on-CPU RTC drivers"
 
+config RTC_DRV_DAVINCI
+       tristate "TI DaVinci RTC"
+       depends on ARCH_DAVINCI_DM365
+       help
+         If you say yes here you get support for the RTC on the
+         DaVinci platforms (DM365).
+
+         This driver can also be built as a module. If so, the module
+         will be called rtc-davinci.
+
 config RTC_DRV_OMAP
        tristate "TI OMAP1"
        depends on ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 || ARCH_DAVINCI_DA8XX
index 44ef194..245311a 100644 (file)
@@ -27,6 +27,7 @@ obj-$(CONFIG_RTC_DRV_BQ32K)   += rtc-bq32k.o
 obj-$(CONFIG_RTC_DRV_BQ4802)   += rtc-bq4802.o
 obj-$(CONFIG_RTC_DRV_CMOS)     += rtc-cmos.o
 obj-$(CONFIG_RTC_DRV_COH901331)        += rtc-coh901331.o
+obj-$(CONFIG_RTC_DRV_DAVINCI)  += rtc-davinci.o
 obj-$(CONFIG_RTC_DRV_DM355EVM) += rtc-dm355evm.o
 obj-$(CONFIG_RTC_DRV_DS1216)   += rtc-ds1216.o
 obj-$(CONFIG_RTC_DRV_DS1286)   += rtc-ds1286.o
diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
new file mode 100644 (file)
index 0000000..92a8f6c
--- /dev/null
@@ -0,0 +1,673 @@
+/*
+ * DaVinci Power Management and Real Time Clock Driver for TI platforms
+ *
+ * Copyright (C) 2009 Texas Instruments, Inc
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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 <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/rtc.h>
+#include <linux/bcd.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+
+/*
+ * The DaVinci RTC is a simple RTC with the following
+ * Sec: 0 - 59 : BCD count
+ * Min: 0 - 59 : BCD count
+ * Hour: 0 - 23 : BCD count
+ * Day: 0 - 0x7FFF(32767) : Binary count ( Over 89 years )
+ */
+
+/* PRTC interface registers */
+#define DAVINCI_PRTCIF_PID             0x00
+#define PRTCIF_CTLR                    0x04
+#define PRTCIF_LDATA                   0x08
+#define PRTCIF_UDATA                   0x0C
+#define PRTCIF_INTEN                   0x10
+#define PRTCIF_INTFLG                  0x14
+
+/* PRTCIF_CTLR bit fields */
+#define PRTCIF_CTLR_BUSY               BIT(31)
+#define PRTCIF_CTLR_SIZE               BIT(25)
+#define PRTCIF_CTLR_DIR                        BIT(24)
+#define PRTCIF_CTLR_BENU_MSB           BIT(23)
+#define PRTCIF_CTLR_BENU_3RD_BYTE      BIT(22)
+#define PRTCIF_CTLR_BENU_2ND_BYTE      BIT(21)
+#define PRTCIF_CTLR_BENU_LSB           BIT(20)
+#define PRTCIF_CTLR_BENU_MASK          (0x00F00000)
+#define PRTCIF_CTLR_BENL_MSB           BIT(19)
+#define PRTCIF_CTLR_BENL_3RD_BYTE      BIT(18)
+#define PRTCIF_CTLR_BENL_2ND_BYTE      BIT(17)
+#define PRTCIF_CTLR_BENL_LSB           BIT(16)
+#define PRTCIF_CTLR_BENL_MASK          (0x000F0000)
+
+/* PRTCIF_INTEN bit fields */
+#define PRTCIF_INTEN_RTCSS             BIT(1)
+#define PRTCIF_INTEN_RTCIF             BIT(0)
+#define PRTCIF_INTEN_MASK              (PRTCIF_INTEN_RTCSS \
+                                       | PRTCIF_INTEN_RTCIF)
+
+/* PRTCIF_INTFLG bit fields */
+#define PRTCIF_INTFLG_RTCSS            BIT(1)
+#define PRTCIF_INTFLG_RTCIF            BIT(0)
+#define PRTCIF_INTFLG_MASK             (PRTCIF_INTFLG_RTCSS \
+                                       | PRTCIF_INTFLG_RTCIF)
+
+/* PRTC subsystem registers */
+#define PRTCSS_RTC_INTC_EXTENA1                (0x0C)
+#define PRTCSS_RTC_CTRL                        (0x10)
+#define PRTCSS_RTC_WDT                 (0x11)
+#define PRTCSS_RTC_TMR0                        (0x12)
+#define PRTCSS_RTC_TMR1                        (0x13)
+#define PRTCSS_RTC_CCTRL               (0x14)
+#define PRTCSS_RTC_SEC                 (0x15)
+#define PRTCSS_RTC_MIN                 (0x16)
+#define PRTCSS_RTC_HOUR                        (0x17)
+#define PRTCSS_RTC_DAY0                        (0x18)
+#define PRTCSS_RTC_DAY1                        (0x19)
+#define PRTCSS_RTC_AMIN                        (0x1A)
+#define PRTCSS_RTC_AHOUR               (0x1B)
+#define PRTCSS_RTC_ADAY0               (0x1C)
+#define PRTCSS_RTC_ADAY1               (0x1D)
+#define PRTCSS_RTC_CLKC_CNT            (0x20)
+
+/* PRTCSS_RTC_INTC_EXTENA1 */
+#define PRTCSS_RTC_INTC_EXTENA1_MASK   (0x07)
+
+/* PRTCSS_RTC_CTRL bit fields */
+#define PRTCSS_RTC_CTRL_WDTBUS         BIT(7)
+#define PRTCSS_RTC_CTRL_WEN            BIT(6)
+#define PRTCSS_RTC_CTRL_WDRT           BIT(5)
+#define PRTCSS_RTC_CTRL_WDTFLG         BIT(4)
+#define PRTCSS_RTC_CTRL_TE             BIT(3)
+#define PRTCSS_RTC_CTRL_TIEN           BIT(2)
+#define PRTCSS_RTC_CTRL_TMRFLG         BIT(1)
+#define PRTCSS_RTC_CTRL_TMMD           BIT(0)
+
+/* PRTCSS_RTC_CCTRL bit fields */
+#define PRTCSS_RTC_CCTRL_CALBUSY       BIT(7)
+#define PRTCSS_RTC_CCTRL_DAEN          BIT(5)
+#define PRTCSS_RTC_CCTRL_HAEN          BIT(4)
+#define PRTCSS_RTC_CCTRL_MAEN          BIT(3)
+#define PRTCSS_RTC_CCTRL_ALMFLG                BIT(2)
+#define PRTCSS_RTC_CCTRL_AIEN          BIT(1)
+#define PRTCSS_RTC_CCTRL_CAEN          BIT(0)
+
+static DEFINE_SPINLOCK(davinci_rtc_lock);
+
+struct davinci_rtc {
+       struct rtc_device               *rtc;
+       void __iomem                    *base;
+       resource_size_t                 pbase;
+       size_t                          base_size;
+       int                             irq;
+};
+
+static inline void rtcif_write(struct davinci_rtc *davinci_rtc,
+                              u32 val, u32 addr)
+{
+       writel(val, davinci_rtc->base + addr);
+}
+
+static inline u32 rtcif_read(struct davinci_rtc *davinci_rtc, u32 addr)
+{
+       return readl(davinci_rtc->base + addr);
+}
+
+static inline void rtcif_wait(struct davinci_rtc *davinci_rtc)
+{
+       while (rtcif_read(davinci_rtc, PRTCIF_CTLR) & PRTCIF_CTLR_BUSY)
+               cpu_relax();
+}
+
+static inline void rtcss_write(struct davinci_rtc *davinci_rtc,
+                              unsigned long val, u8 addr)
+{
+       rtcif_wait(davinci_rtc);
+
+       rtcif_write(davinci_rtc, PRTCIF_CTLR_BENL_LSB | addr, PRTCIF_CTLR);
+       rtcif_write(davinci_rtc, val, PRTCIF_LDATA);
+
+       rtcif_wait(davinci_rtc);
+}
+
+static inline u8 rtcss_read(struct davinci_rtc *davinci_rtc, u8 addr)
+{
+       rtcif_wait(davinci_rtc);
+
+       rtcif_write(davinci_rtc, PRTCIF_CTLR_DIR | PRTCIF_CTLR_BENL_LSB | addr,
+                   PRTCIF_CTLR);
+
+       rtcif_wait(davinci_rtc);
+
+       return rtcif_read(davinci_rtc, PRTCIF_LDATA);
+}
+
+static inline void davinci_rtcss_calendar_wait(struct davinci_rtc *davinci_rtc)
+{
+       while (rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL) &
+              PRTCSS_RTC_CCTRL_CALBUSY)
+               cpu_relax();
+}
+
+static irqreturn_t davinci_rtc_interrupt(int irq, void *class_dev)
+{
+       struct davinci_rtc *davinci_rtc = class_dev;
+       unsigned long events = 0;
+       u32 irq_flg;
+       u8 alm_irq, tmr_irq;
+       u8 rtc_ctrl, rtc_cctrl;
+       int ret = IRQ_NONE;
+
+       irq_flg = rtcif_read(davinci_rtc, PRTCIF_INTFLG) &
+                 PRTCIF_INTFLG_RTCSS;
+
+       alm_irq = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL) &
+                 PRTCSS_RTC_CCTRL_ALMFLG;
+
+       tmr_irq = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL) &
+                 PRTCSS_RTC_CTRL_TMRFLG;
+
+       if (irq_flg) {
+               if (alm_irq) {
+                       events |= RTC_IRQF | RTC_AF;
+                       rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
+                       rtc_cctrl |=  PRTCSS_RTC_CCTRL_ALMFLG;
+                       rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
+               } else if (tmr_irq) {
+                       events |= RTC_IRQF | RTC_PF;
+                       rtc_ctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL);
+                       rtc_ctrl |=  PRTCSS_RTC_CTRL_TMRFLG;
+                       rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
+               }
+
+               rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS,
+                                   PRTCIF_INTFLG);
+               rtc_update_irq(davinci_rtc->rtc, 1, events);
+
+               ret = IRQ_HANDLED;
+       }
+
+       return ret;
+}
+
+static int
+davinci_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       u8 rtc_ctrl;
+       unsigned long flags;
+       int ret = 0;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       rtc_ctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL);
+
+       switch (cmd) {
+       case RTC_WIE_ON:
+               rtc_ctrl |= PRTCSS_RTC_CTRL_WEN | PRTCSS_RTC_CTRL_WDTFLG;
+               break;
+       case RTC_WIE_OFF:
+               rtc_ctrl &= ~PRTCSS_RTC_CTRL_WEN;
+               break;
+       case RTC_UIE_OFF:
+       case RTC_UIE_ON:
+               ret = -ENOTTY;
+               break;
+       default:
+               ret = -ENOIOCTLCMD;
+       }
+
+       rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return ret;
+}
+
+static int convertfromdays(u16 days, struct rtc_time *tm)
+{
+       int tmp_days, year, mon;
+
+       for (year = 2000;; year++) {
+               tmp_days = rtc_year_days(1, 12, year);
+               if (days >= tmp_days)
+                       days -= tmp_days;
+               else {
+                       for (mon = 0;; mon++) {
+                               tmp_days = rtc_month_days(mon, year);
+                               if (days >= tmp_days) {
+                                       days -= tmp_days;
+                               } else {
+                                       tm->tm_year = year - 1900;
+                                       tm->tm_mon = mon;
+                                       tm->tm_mday = days + 1;
+                                       break;
+                               }
+                       }
+                       break;
+               }
+       }
+       return 0;
+}
+
+static int convert2days(u16 *days, struct rtc_time *tm)
+{
+       int i;
+       *days = 0;
+
+       /* epoch == 1900 */
+       if (tm->tm_year < 100 || tm->tm_year > 199)
+               return -EINVAL;
+
+       for (i = 2000; i < 1900 + tm->tm_year; i++)
+               *days += rtc_year_days(1, 12, i);
+
+       *days += rtc_year_days(tm->tm_mday, tm->tm_mon, 1900 + tm->tm_year);
+
+       return 0;
+}
+
+static int davinci_rtc_read_time(struct device *dev, struct rtc_time *tm)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       u16 days = 0;
+       u8 day0, day1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       tm->tm_sec = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_SEC));
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       tm->tm_min = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_MIN));
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       tm->tm_hour = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_HOUR));
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       day0 = rtcss_read(davinci_rtc, PRTCSS_RTC_DAY0);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       day1 = rtcss_read(davinci_rtc, PRTCSS_RTC_DAY1);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       days |= day1;
+       days <<= 8;
+       days |= day0;
+
+       if (convertfromdays(days, tm) < 0)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int davinci_rtc_set_time(struct device *dev, struct rtc_time *tm)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       u16 days;
+       u8 rtc_cctrl;
+       unsigned long flags;
+
+       if (convert2days(&days, tm) < 0)
+               return -EINVAL;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, bin2bcd(tm->tm_sec), PRTCSS_RTC_SEC);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, bin2bcd(tm->tm_min), PRTCSS_RTC_MIN);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, bin2bcd(tm->tm_hour), PRTCSS_RTC_HOUR);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, days & 0xFF, PRTCSS_RTC_DAY0);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, (days & 0xFF00) >> 8, PRTCSS_RTC_DAY1);
+
+       rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
+       rtc_cctrl |= PRTCSS_RTC_CCTRL_CAEN;
+       rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return 0;
+}
+
+static int davinci_rtc_alarm_irq_enable(struct device *dev,
+                                       unsigned int enabled)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       unsigned long flags;
+       u8 rtc_cctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CCTRL);
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       if (enabled)
+               rtc_cctrl |= PRTCSS_RTC_CCTRL_DAEN |
+                            PRTCSS_RTC_CCTRL_HAEN |
+                            PRTCSS_RTC_CCTRL_MAEN |
+                            PRTCSS_RTC_CCTRL_ALMFLG |
+                            PRTCSS_RTC_CCTRL_AIEN;
+       else
+               rtc_cctrl &= ~PRTCSS_RTC_CCTRL_AIEN;
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, rtc_cctrl, PRTCSS_RTC_CCTRL);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return 0;
+}
+
+static int davinci_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       u16 days = 0;
+       u8 day0, day1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       alm->time.tm_min = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_AMIN));
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       alm->time.tm_hour = bcd2bin(rtcss_read(davinci_rtc, PRTCSS_RTC_AHOUR));
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       day0 = rtcss_read(davinci_rtc, PRTCSS_RTC_ADAY0);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       day1 = rtcss_read(davinci_rtc, PRTCSS_RTC_ADAY1);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+       days |= day1;
+       days <<= 8;
+       days |= day0;
+
+       if (convertfromdays(days, &alm->time) < 0)
+               return -EINVAL;
+
+       alm->pending = !!(rtcss_read(davinci_rtc,
+                         PRTCSS_RTC_CCTRL) &
+                       PRTCSS_RTC_CCTRL_AIEN);
+       alm->enabled = alm->pending && device_may_wakeup(dev);
+
+       return 0;
+}
+
+static int davinci_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       unsigned long flags;
+       u16 days;
+
+       if (alm->time.tm_mday <= 0 && alm->time.tm_mon < 0
+           && alm->time.tm_year < 0) {
+               struct rtc_time tm;
+               unsigned long now, then;
+
+               davinci_rtc_read_time(dev, &tm);
+               rtc_tm_to_time(&tm, &now);
+
+               alm->time.tm_mday = tm.tm_mday;
+               alm->time.tm_mon = tm.tm_mon;
+               alm->time.tm_year = tm.tm_year;
+               rtc_tm_to_time(&alm->time, &then);
+
+               if (then < now) {
+                       rtc_time_to_tm(now + 24 * 60 * 60, &tm);
+                       alm->time.tm_mday = tm.tm_mday;
+                       alm->time.tm_mon = tm.tm_mon;
+                       alm->time.tm_year = tm.tm_year;
+               }
+       }
+
+       if (convert2days(&days, &alm->time) < 0)
+               return -EINVAL;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, bin2bcd(alm->time.tm_min), PRTCSS_RTC_AMIN);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, bin2bcd(alm->time.tm_hour), PRTCSS_RTC_AHOUR);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, days & 0xFF, PRTCSS_RTC_ADAY0);
+
+       davinci_rtcss_calendar_wait(davinci_rtc);
+       rtcss_write(davinci_rtc, (days & 0xFF00) >> 8, PRTCSS_RTC_ADAY1);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return 0;
+}
+
+static int davinci_rtc_irq_set_state(struct device *dev, int enabled)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       unsigned long flags;
+       u8 rtc_ctrl;
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       rtc_ctrl = rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL);
+
+       if (enabled) {
+               while (rtcss_read(davinci_rtc, PRTCSS_RTC_CTRL)
+                      & PRTCSS_RTC_CTRL_WDTBUS)
+                       cpu_relax();
+
+               rtc_ctrl |= PRTCSS_RTC_CTRL_TE;
+               rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
+
+               rtcss_write(davinci_rtc, 0x0, PRTCSS_RTC_CLKC_CNT);
+
+               rtc_ctrl |= PRTCSS_RTC_CTRL_TIEN |
+                           PRTCSS_RTC_CTRL_TMMD |
+                           PRTCSS_RTC_CTRL_TMRFLG;
+       } else
+               rtc_ctrl &= ~PRTCSS_RTC_CTRL_TIEN;
+
+       rtcss_write(davinci_rtc, rtc_ctrl, PRTCSS_RTC_CTRL);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return 0;
+}
+
+static int davinci_rtc_irq_set_freq(struct device *dev, int freq)
+{
+       struct davinci_rtc *davinci_rtc = dev_get_drvdata(dev);
+       unsigned long flags;
+       u16 tmr_counter = (0x8000 >> (ffs(freq) - 1));
+
+       spin_lock_irqsave(&davinci_rtc_lock, flags);
+
+       rtcss_write(davinci_rtc, tmr_counter & 0xFF, PRTCSS_RTC_TMR0);
+       rtcss_write(davinci_rtc, (tmr_counter & 0xFF00) >> 8, PRTCSS_RTC_TMR1);
+
+       spin_unlock_irqrestore(&davinci_rtc_lock, flags);
+
+       return 0;
+}
+
+static struct rtc_class_ops davinci_rtc_ops = {
+       .ioctl                  = davinci_rtc_ioctl,
+       .read_time              = davinci_rtc_read_time,
+       .set_time               = davinci_rtc_set_time,
+       .alarm_irq_enable       = davinci_rtc_alarm_irq_enable,
+       .read_alarm             = davinci_rtc_read_alarm,
+       .set_alarm              = davinci_rtc_set_alarm,
+       .irq_set_state          = davinci_rtc_irq_set_state,
+       .irq_set_freq           = davinci_rtc_irq_set_freq,
+};
+
+static int __init davinci_rtc_probe(struct platform_device *pdev)
+{
+       struct device *dev = &pdev->dev;
+       struct davinci_rtc *davinci_rtc;
+       struct resource *res, *mem;
+       int ret = 0;
+
+       davinci_rtc = kzalloc(sizeof(struct davinci_rtc), GFP_KERNEL);
+       if (!davinci_rtc) {
+               dev_dbg(dev, "could not allocate memory for private data\n");
+               return -ENOMEM;
+       }
+
+       davinci_rtc->irq = platform_get_irq(pdev, 0);
+       if (davinci_rtc->irq < 0) {
+               dev_err(dev, "no RTC irq\n");
+               ret = davinci_rtc->irq;
+               goto fail1;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               dev_err(dev, "no mem resource\n");
+               ret = -EINVAL;
+               goto fail1;
+       }
+
+       davinci_rtc->pbase = res->start;
+       davinci_rtc->base_size = resource_size(res);
+
+       mem = request_mem_region(davinci_rtc->pbase, davinci_rtc->base_size,
+                                pdev->name);
+       if (!mem) {
+               dev_err(dev, "RTC registers at %08x are not free\n",
+                       davinci_rtc->pbase);
+               ret = -EBUSY;
+               goto fail1;
+       }
+
+       davinci_rtc->base = ioremap(davinci_rtc->pbase, davinci_rtc->base_size);
+       if (!davinci_rtc->base) {
+               dev_err(dev, "unable to ioremap MEM resource\n");
+               ret = -ENOMEM;
+               goto fail2;
+       }
+
+       davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
+                                   &davinci_rtc_ops, THIS_MODULE);
+       if (IS_ERR(davinci_rtc->rtc)) {
+               dev_err(dev, "unable to register RTC device, err %ld\n",
+                               PTR_ERR(davinci_rtc->rtc));
+               goto fail3;
+       }
+
+       rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
+       rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
+       rtcss_write(davinci_rtc, 0, PRTCSS_RTC_INTC_EXTENA1);
+
+       rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CTRL);
+       rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CCTRL);
+
+       ret = request_irq(davinci_rtc->irq, davinci_rtc_interrupt,
+                         IRQF_DISABLED, "davinci_rtc", davinci_rtc);
+       if (ret < 0) {
+               dev_err(dev, "unable to register davinci RTC interrupt\n");
+               goto fail4;
+       }
+
+       /* Enable interrupts */
+       rtcif_write(davinci_rtc, PRTCIF_INTEN_RTCSS, PRTCIF_INTEN);
+       rtcss_write(davinci_rtc, PRTCSS_RTC_INTC_EXTENA1_MASK,
+                           PRTCSS_RTC_INTC_EXTENA1);
+
+       rtcss_write(davinci_rtc, PRTCSS_RTC_CCTRL_CAEN, PRTCSS_RTC_CCTRL);
+
+       platform_set_drvdata(pdev, davinci_rtc);
+
+       device_init_wakeup(&pdev->dev, 0);
+
+       return 0;
+
+fail4:
+       rtc_device_unregister(davinci_rtc->rtc);
+fail3:
+       iounmap(davinci_rtc->base);
+fail2:
+       release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);
+fail1:
+       kfree(davinci_rtc);
+
+       return ret;
+}
+
+static int __devexit davinci_rtc_remove(struct platform_device *pdev)
+{
+       struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
+
+       device_init_wakeup(&pdev->dev, 0);
+
+       rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
+
+       free_irq(davinci_rtc->irq, davinci_rtc);
+
+       rtc_device_unregister(davinci_rtc->rtc);
+
+       iounmap(davinci_rtc->base);
+       release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);
+
+       platform_set_drvdata(pdev, NULL);
+
+       kfree(davinci_rtc);
+
+       return 0;
+}
+
+static struct platform_driver davinci_rtc_driver = {
+       .probe          = davinci_rtc_probe,
+       .remove         = __devexit_p(davinci_rtc_remove),
+       .driver         = {
+               .name = "rtc_davinci",
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init rtc_init(void)
+{
+       return platform_driver_probe(&davinci_rtc_driver, davinci_rtc_probe);
+}
+module_init(rtc_init);
+
+static void __exit rtc_exit(void)
+{
+       platform_driver_unregister(&davinci_rtc_driver);
+}
+module_exit(rtc_exit);
+
+MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>");
+MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver");
+MODULE_LICENSE("GPL");
index c9522f3..9718aaa 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * An I2C driver for the Epson RX8581 RTC
  *
- * Author: Martyn Welch <martyn.welch@gefanuc.com>
- * Copyright 2008 GE Fanuc Intelligent Platforms Embedded Systems, Inc.
+ * Author: Martyn Welch <martyn.welch@ge.com>
+ * Copyright 2008 GE Intelligent Platforms Embedded Systems, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -272,7 +272,7 @@ static void __exit rx8581_exit(void)
        i2c_del_driver(&rx8581_driver);
 }
 
-MODULE_AUTHOR("Martyn Welch <martyn.welch@gefanuc.com>");
+MODULE_AUTHOR("Martyn Welch <martyn.welch@ge.com>");
 MODULE_DESCRIPTION("Epson RX-8581 RTC driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
index 875ba09..b53a001 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * A RTC driver for the Simtek STK17TA8
  *
- * By Thomas Hommel <thomas.hommel@gefanuc.com>
+ * By Thomas Hommel <thomas.hommel@ge.com>
  *
  * Based on the DS1553 driver from
  * Atsushi Nemoto <anemo@mba.ocn.ne.jp>
@@ -382,7 +382,7 @@ static __exit void stk17ta8_exit(void)
 module_init(stk17ta8_init);
 module_exit(stk17ta8_exit);
 
-MODULE_AUTHOR("Thomas Hommel <thomas.hommel@gefanuc.com>");
+MODULE_AUTHOR("Thomas Hommel <thomas.hommel@ge.com>");
 MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
index fa2339c..0e86247 100644 (file)
@@ -65,6 +65,7 @@ static void dasd_device_tasklet(struct dasd_device *);
 static void dasd_block_tasklet(struct dasd_block *);
 static void do_kick_device(struct work_struct *);
 static void do_restore_device(struct work_struct *);
+static void do_reload_device(struct work_struct *);
 static void dasd_return_cqr_cb(struct dasd_ccw_req *, void *);
 static void dasd_device_timeout(unsigned long);
 static void dasd_block_timeout(unsigned long);
@@ -115,6 +116,7 @@ struct dasd_device *dasd_alloc_device(void)
        device->timer.data = (unsigned long) device;
        INIT_WORK(&device->kick_work, do_kick_device);
        INIT_WORK(&device->restore_device, do_restore_device);
+       INIT_WORK(&device->reload_device, do_reload_device);
        device->state = DASD_STATE_NEW;
        device->target = DASD_STATE_NEW;
        mutex_init(&device->state_mutex);
@@ -520,6 +522,26 @@ void dasd_kick_device(struct dasd_device *device)
        schedule_work(&device->kick_work);
 }
 
+/*
+ * dasd_reload_device will schedule a call do do_reload_device to the kernel
+ * event daemon.
+ */
+static void do_reload_device(struct work_struct *work)
+{
+       struct dasd_device *device = container_of(work, struct dasd_device,
+                                                 reload_device);
+       device->discipline->reload(device);
+       dasd_put_device(device);
+}
+
+void dasd_reload_device(struct dasd_device *device)
+{
+       dasd_get_device(device);
+       /* queue call to dasd_reload_device to the kernel event daemon. */
+       schedule_work(&device->reload_device);
+}
+EXPORT_SYMBOL(dasd_reload_device);
+
 /*
  * dasd_restore_device will schedule a call do do_restore_device to the kernel
  * event daemon.
index 6632649..85bfd87 100644 (file)
@@ -1418,9 +1418,29 @@ static struct dasd_ccw_req *dasd_3990_erp_inspect_alias(
                                                struct dasd_ccw_req *erp)
 {
        struct dasd_ccw_req *cqr = erp->refers;
+       char *sense;
 
        if (cqr->block &&
            (cqr->block->base != cqr->startdev)) {
+
+               sense = dasd_get_sense(&erp->refers->irb);
+               /*
+                * dynamic pav may have changed base alias mapping
+                */
+               if (!test_bit(DASD_FLAG_OFFLINE, &cqr->startdev->flags) && sense
+                   && (sense[0] == 0x10) && (sense[7] == 0x0F)
+                   && (sense[8] == 0x67)) {
+                       /*
+                        * remove device from alias handling to prevent new
+                        * requests from being scheduled on the
+                        * wrong alias device
+                        */
+                       dasd_alias_remove_device(cqr->startdev);
+
+                       /* schedule worker to reload device */
+                       dasd_reload_device(cqr->startdev);
+               }
+
                if (cqr->startdev->features & DASD_FEATURE_ERPLOG) {
                        DBF_DEV_EVENT(DBF_ERR, cqr->startdev,
                                    "ERP on alias device for request %p,"
index 8c48142..4155805 100644 (file)
@@ -190,20 +190,21 @@ int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
        struct alias_server *server, *newserver;
        struct alias_lcu *lcu, *newlcu;
        int is_lcu_known;
-       struct dasd_uid *uid;
+       struct dasd_uid uid;
 
        private = (struct dasd_eckd_private *) device->private;
-       uid = &private->uid;
+
+       device->discipline->get_uid(device, &uid);
        spin_lock_irqsave(&aliastree.lock, flags);
        is_lcu_known = 1;
-       server = _find_server(uid);
+       server = _find_server(&uid);
        if (!server) {
                spin_unlock_irqrestore(&aliastree.lock, flags);
-               newserver = _allocate_server(uid);
+               newserver = _allocate_server(&uid);
                if (IS_ERR(newserver))
                        return PTR_ERR(newserver);
                spin_lock_irqsave(&aliastree.lock, flags);
-               server = _find_server(uid);
+               server = _find_server(&uid);
                if (!server) {
                        list_add(&newserver->server, &aliastree.serverlist);
                        server = newserver;
@@ -214,14 +215,14 @@ int dasd_alias_make_device_known_to_lcu(struct dasd_device *device)
                }
        }
 
-       lcu = _find_lcu(server, uid);
+       lcu = _find_lcu(server, &uid);
        if (!lcu) {
                spin_unlock_irqrestore(&aliastree.lock, flags);
-               newlcu = _allocate_lcu(uid);
+               newlcu = _allocate_lcu(&uid);
                if (IS_ERR(newlcu))
                        return PTR_ERR(newlcu);
                spin_lock_irqsave(&aliastree.lock, flags);
-               lcu = _find_lcu(server, uid);
+               lcu = _find_lcu(server, &uid);
                if (!lcu) {
                        list_add(&newlcu->lcu, &server->lculist);
                        lcu = newlcu;
@@ -256,20 +257,20 @@ void dasd_alias_lcu_setup_complete(struct dasd_device *device)
        unsigned long flags;
        struct alias_server *server;
        struct alias_lcu *lcu;
-       struct dasd_uid *uid;
+       struct dasd_uid uid;
 
        private = (struct dasd_eckd_private *) device->private;
-       uid = &private->uid;
+       device->discipline->get_uid(device, &uid);
        lcu = NULL;
        spin_lock_irqsave(&aliastree.lock, flags);
-       server = _find_server(uid);
+       server = _find_server(&uid);
        if (server)
-               lcu = _find_lcu(server, uid);
+               lcu = _find_lcu(server, &uid);
        spin_unlock_irqrestore(&aliastree.lock, flags);
        if (!lcu) {
                DBF_EVENT_DEVID(DBF_ERR, device->cdev,
                                "could not find lcu for %04x %02x",
-                               uid->ssid, uid->real_unit_addr);
+                               uid.ssid, uid.real_unit_addr);
                WARN_ON(1);
                return;
        }
@@ -282,20 +283,20 @@ void dasd_alias_wait_for_lcu_setup(struct dasd_device *device)
        unsigned long flags;
        struct alias_server *server;
        struct alias_lcu *lcu;
-       struct dasd_uid *uid;
+       struct dasd_uid uid;
 
        private = (struct dasd_eckd_private *) device->private;
-       uid = &private->uid;
+       device->discipline->get_uid(device, &uid);
        lcu = NULL;
        spin_lock_irqsave(&aliastree.lock, flags);
-       server = _find_server(uid);
+       server = _find_server(&uid);
        if (server)
-               lcu = _find_lcu(server, uid);
+               lcu = _find_lcu(server, &uid);
        spin_unlock_irqrestore(&aliastree.lock, flags);
        if (!lcu) {
                DBF_EVENT_DEVID(DBF_ERR, device->cdev,
                                "could not find lcu for %04x %02x",
-                               uid->ssid, uid->real_unit_addr);
+                               uid.ssid, uid.real_unit_addr);
                WARN_ON(1);
                return;
        }
@@ -314,9 +315,11 @@ void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
        struct alias_lcu *lcu;
        struct alias_server *server;
        int was_pending;
+       struct dasd_uid uid;
 
        private = (struct dasd_eckd_private *) device->private;
        lcu = private->lcu;
+       device->discipline->get_uid(device, &uid);
        spin_lock_irqsave(&lcu->lock, flags);
        list_del_init(&device->alias_list);
        /* make sure that the workers don't use this device */
@@ -353,7 +356,7 @@ void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
                        _schedule_lcu_update(lcu, NULL);
                spin_unlock(&lcu->lock);
        }
-       server = _find_server(&private->uid);
+       server = _find_server(&uid);
        if (server && list_empty(&server->lculist)) {
                list_del(&server->server);
                _free_server(server);
@@ -366,19 +369,30 @@ void dasd_alias_disconnect_device_from_lcu(struct dasd_device *device)
  * in the lcu is up to date and will update the device uid before
  * adding it to a pav group.
  */
+
 static int _add_device_to_lcu(struct alias_lcu *lcu,
-                             struct dasd_device *device)
+                             struct dasd_device *device,
+                             struct dasd_device *pos)
 {
 
        struct dasd_eckd_private *private;
        struct alias_pav_group *group;
-       struct dasd_uid *uid;
+       struct dasd_uid uid;
+       unsigned long flags;
 
        private = (struct dasd_eckd_private *) device->private;
-       uid = &private->uid;
-       uid->type = lcu->uac->unit[uid->real_unit_addr].ua_type;
-       uid->base_unit_addr = lcu->uac->unit[uid->real_unit_addr].base_ua;
-       dasd_set_uid(device->cdev, &private->uid);
+
+       /* only lock if not already locked */
+       if (device != pos)
+               spin_lock_irqsave_nested(get_ccwdev_lock(device->cdev), flags,
+                                        CDEV_NESTED_SECOND);
+       private->uid.type = lcu->uac->unit[private->uid.real_unit_addr].ua_type;
+       private->uid.base_unit_addr =
+               lcu->uac->unit[private->uid.real_unit_addr].base_ua;
+       uid = private->uid;
+
+       if (device != pos)
+               spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
 
        /* if we have no PAV anyway, we don't need to bother with PAV groups */
        if (lcu->pav == NO_PAV) {
@@ -386,25 +400,25 @@ static int _add_device_to_lcu(struct alias_lcu *lcu,
                return 0;
        }
 
-       group = _find_group(lcu, uid);
+       group = _find_group(lcu, &uid);
        if (!group) {
                group = kzalloc(sizeof(*group), GFP_ATOMIC);
                if (!group)
                        return -ENOMEM;
-               memcpy(group->uid.vendor, uid->vendor, sizeof(uid->vendor));
-               memcpy(group->uid.serial, uid->serial, sizeof(uid->serial));
-               group->uid.ssid = uid->ssid;
-               if (uid->type == UA_BASE_DEVICE)
-                       group->uid.base_unit_addr = uid->real_unit_addr;
+               memcpy(group->uid.vendor, uid.vendor, sizeof(uid.vendor));
+               memcpy(group->uid.serial, uid.serial, sizeof(uid.serial));
+               group->uid.ssid = uid.ssid;
+               if (uid.type == UA_BASE_DEVICE)
+                       group->uid.base_unit_addr = uid.real_unit_addr;
                else
-                       group->uid.base_unit_addr = uid->base_unit_addr;
-               memcpy(group->uid.vduit, uid->vduit, sizeof(uid->vduit));
+                       group->uid.base_unit_addr = uid.base_unit_addr;
+               memcpy(group->uid.vduit, uid.vduit, sizeof(uid.vduit));
                INIT_LIST_HEAD(&group->group);
                INIT_LIST_HEAD(&group->baselist);
                INIT_LIST_HEAD(&group->aliaslist);
                list_add(&group->group, &lcu->grouplist);
        }
-       if (uid->type == UA_BASE_DEVICE)
+       if (uid.type == UA_BASE_DEVICE)
                list_move(&device->alias_list, &group->baselist);
        else
                list_move(&device->alias_list, &group->aliaslist);
@@ -525,7 +539,10 @@ static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
        if (rc)
                return rc;
 
-       spin_lock_irqsave(&lcu->lock, flags);
+       /* need to take cdev lock before lcu lock */
+       spin_lock_irqsave_nested(get_ccwdev_lock(refdev->cdev), flags,
+                                CDEV_NESTED_FIRST);
+       spin_lock(&lcu->lock);
        lcu->pav = NO_PAV;
        for (i = 0; i < MAX_DEVICES_PER_LCU; ++i) {
                switch (lcu->uac->unit[i].ua_type) {
@@ -542,9 +559,10 @@ static int _lcu_update(struct dasd_device *refdev, struct alias_lcu *lcu)
 
        list_for_each_entry_safe(device, tempdev, &lcu->active_devices,
                                 alias_list) {
-               _add_device_to_lcu(lcu, device);
+               _add_device_to_lcu(lcu, device, refdev);
        }
-       spin_unlock_irqrestore(&lcu->lock, flags);
+       spin_unlock(&lcu->lock);
+       spin_unlock_irqrestore(get_ccwdev_lock(refdev->cdev), flags);
        return 0;
 }
 
@@ -628,9 +646,12 @@ int dasd_alias_add_device(struct dasd_device *device)
        private = (struct dasd_eckd_private *) device->private;
        lcu = private->lcu;
        rc = 0;
-       spin_lock_irqsave(&lcu->lock, flags);
+
+       /* need to take cdev lock before lcu lock */
+       spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
+       spin_lock(&lcu->lock);
        if (!(lcu->flags & UPDATE_PENDING)) {
-               rc = _add_device_to_lcu(lcu, device);
+               rc = _add_device_to_lcu(lcu, device, device);
                if (rc)
                        lcu->flags |= UPDATE_PENDING;
        }
@@ -638,10 +659,19 @@ int dasd_alias_add_device(struct dasd_device *device)
                list_move(&device->alias_list, &lcu->active_devices);
                _schedule_lcu_update(lcu, device);
        }
-       spin_unlock_irqrestore(&lcu->lock, flags);
+       spin_unlock(&lcu->lock);
+       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
        return rc;
 }
 
+int dasd_alias_update_add_device(struct dasd_device *device)
+{
+       struct dasd_eckd_private *private;
+       private = (struct dasd_eckd_private *) device->private;
+       private->lcu->flags |= UPDATE_PENDING;
+       return dasd_alias_add_device(device);
+}
+
 int dasd_alias_remove_device(struct dasd_device *device)
 {
        struct dasd_eckd_private *private;
@@ -740,19 +770,30 @@ static void _restart_all_base_devices_on_lcu(struct alias_lcu *lcu)
        struct alias_pav_group *pavgroup;
        struct dasd_device *device;
        struct dasd_eckd_private *private;
+       unsigned long flags;
 
        /* active and inactive list can contain alias as well as base devices */
        list_for_each_entry(device, &lcu->active_devices, alias_list) {
                private = (struct dasd_eckd_private *) device->private;
-               if (private->uid.type != UA_BASE_DEVICE)
+               spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
+               if (private->uid.type != UA_BASE_DEVICE) {
+                       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
+                                              flags);
                        continue;
+               }
+               spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
                dasd_schedule_block_bh(device->block);
                dasd_schedule_device_bh(device);
        }
        list_for_each_entry(device, &lcu->inactive_devices, alias_list) {
                private = (struct dasd_eckd_private *) device->private;
-               if (private->uid.type != UA_BASE_DEVICE)
+               spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
+               if (private->uid.type != UA_BASE_DEVICE) {
+                       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev),
+                                              flags);
                        continue;
+               }
+               spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
                dasd_schedule_block_bh(device->block);
                dasd_schedule_device_bh(device);
        }
index eff9c81..34d51dd 100644 (file)
@@ -49,7 +49,6 @@ struct dasd_devmap {
         unsigned int devindex;
         unsigned short features;
        struct dasd_device *device;
-       struct dasd_uid uid;
 };
 
 /*
@@ -936,42 +935,46 @@ dasd_device_status_show(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR(status, 0444, dasd_device_status_show, NULL);
 
-static ssize_t
-dasd_alias_show(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t dasd_alias_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
 {
-       struct dasd_devmap *devmap;
-       int alias;
+       struct dasd_device *device;
+       struct dasd_uid uid;
 
-       devmap = dasd_find_busid(dev_name(dev));
-       spin_lock(&dasd_devmap_lock);
-       if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) {
-               spin_unlock(&dasd_devmap_lock);
+       device = dasd_device_from_cdev(to_ccwdev(dev));
+       if (IS_ERR(device))
                return sprintf(buf, "0\n");
+
+       if (device->discipline && device->discipline->get_uid &&
+           !device->discipline->get_uid(device, &uid)) {
+               if (uid.type == UA_BASE_PAV_ALIAS ||
+                   uid.type == UA_HYPER_PAV_ALIAS)
+                       return sprintf(buf, "1\n");
        }
-       if (devmap->uid.type == UA_BASE_PAV_ALIAS ||
-           devmap->uid.type == UA_HYPER_PAV_ALIAS)
-               alias = 1;
-       else
-               alias = 0;
-       spin_unlock(&dasd_devmap_lock);
-       return sprintf(buf, alias ? "1\n" : "0\n");
+       dasd_put_device(device);
+
+       return sprintf(buf, "0\n");
 }
 
 static DEVICE_ATTR(alias, 0444, dasd_alias_show, NULL);
 
-static ssize_t
-dasd_vendor_show(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t dasd_vendor_show(struct device *dev,
+                               struct device_attribute *attr, char *buf)
 {
-       struct dasd_devmap *devmap;
+       struct dasd_device *device;
+       struct dasd_uid uid;
        char *vendor;
 
-       devmap = dasd_find_busid(dev_name(dev));
-       spin_lock(&dasd_devmap_lock);
-       if (!IS_ERR(devmap) && strlen(devmap->uid.vendor) > 0)
-               vendor = devmap->uid.vendor;
-       else
-               vendor = "";
-       spin_unlock(&dasd_devmap_lock);
+       device = dasd_device_from_cdev(to_ccwdev(dev));
+       vendor = "";
+       if (IS_ERR(device))
+               return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
+
+       if (device->discipline && device->discipline->get_uid &&
+           !device->discipline->get_uid(device, &uid))
+                       vendor = uid.vendor;
+
+       dasd_put_device(device);
 
        return snprintf(buf, PAGE_SIZE, "%s\n", vendor);
 }
@@ -985,48 +988,51 @@ static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
 static ssize_t
 dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct dasd_devmap *devmap;
+       struct dasd_device *device;
+       struct dasd_uid uid;
        char uid_string[UID_STRLEN];
        char ua_string[3];
-       struct dasd_uid *uid;
 
-       devmap = dasd_find_busid(dev_name(dev));
-       spin_lock(&dasd_devmap_lock);
-       if (IS_ERR(devmap) || strlen(devmap->uid.vendor) == 0) {
-               spin_unlock(&dasd_devmap_lock);
-               return sprintf(buf, "\n");
-       }
-       uid = &devmap->uid;
-       switch (uid->type) {
-       case UA_BASE_DEVICE:
-               sprintf(ua_string, "%02x", uid->real_unit_addr);
-               break;
-       case UA_BASE_PAV_ALIAS:
-               sprintf(ua_string, "%02x", uid->base_unit_addr);
-               break;
-       case UA_HYPER_PAV_ALIAS:
-               sprintf(ua_string, "xx");
-               break;
-       default:
-               /* should not happen, treat like base device */
-               sprintf(ua_string, "%02x", uid->real_unit_addr);
-               break;
+       device = dasd_device_from_cdev(to_ccwdev(dev));
+       uid_string[0] = 0;
+       if (IS_ERR(device))
+               return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
+
+       if (device->discipline && device->discipline->get_uid &&
+           !device->discipline->get_uid(device, &uid)) {
+               switch (uid.type) {
+               case UA_BASE_DEVICE:
+                       snprintf(ua_string, sizeof(ua_string), "%02x",
+                                uid.real_unit_addr);
+                       break;
+               case UA_BASE_PAV_ALIAS:
+                       snprintf(ua_string, sizeof(ua_string), "%02x",
+                                uid.base_unit_addr);
+                       break;
+               case UA_HYPER_PAV_ALIAS:
+                       snprintf(ua_string, sizeof(ua_string), "xx");
+                       break;
+               default:
+                       /* should not happen, treat like base device */
+                       snprintf(ua_string, sizeof(ua_string), "%02x",
+                                uid.real_unit_addr);
+                       break;
+               }
+
+               if (strlen(uid.vduit) > 0)
+                       snprintf(uid_string, sizeof(uid_string),
+                                "%s.%s.%04x.%s.%s",
+                                uid.vendor, uid.serial, uid.ssid, ua_string,
+                                uid.vduit);
+               else
+                       snprintf(uid_string, sizeof(uid_string),
+                                "%s.%s.%04x.%s",
+                                uid.vendor, uid.serial, uid.ssid, ua_string);
        }
-       if (strlen(uid->vduit) > 0)
-               snprintf(uid_string, sizeof(uid_string),
-                        "%s.%s.%04x.%s.%s",
-                        uid->vendor, uid->serial,
-                        uid->ssid, ua_string,
-                        uid->vduit);
-       else
-               snprintf(uid_string, sizeof(uid_string),
-                        "%s.%s.%04x.%s",
-                        uid->vendor, uid->serial,
-                        uid->ssid, ua_string);
-       spin_unlock(&dasd_devmap_lock);
+       dasd_put_device(device);
+
        return snprintf(buf, PAGE_SIZE, "%s\n", uid_string);
 }
-
 static DEVICE_ATTR(uid, 0444, dasd_uid_show, NULL);
 
 /*
@@ -1093,50 +1099,6 @@ static struct attribute_group dasd_attr_group = {
        .attrs = dasd_attrs,
 };
 
-/*
- * Return copy of the device unique identifier.
- */
-int
-dasd_get_uid(struct ccw_device *cdev, struct dasd_uid *uid)
-{
-       struct dasd_devmap *devmap;
-
-       devmap = dasd_find_busid(dev_name(&cdev->dev));
-       if (IS_ERR(devmap))
-               return PTR_ERR(devmap);
-       spin_lock(&dasd_devmap_lock);
-       *uid = devmap->uid;
-       spin_unlock(&dasd_devmap_lock);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(dasd_get_uid);
-
-/*
- * Register the given device unique identifier into devmap struct.
- * In addition check if the related storage server subsystem ID is already
- * contained in the dasd_server_ssid_list. If subsystem ID is not contained,
- * create new entry.
- * Return 0 if server was already in serverlist,
- *       1 if the server was added successful
- *      <0 in case of error.
- */
-int
-dasd_set_uid(struct ccw_device *cdev, struct dasd_uid *uid)
-{
-       struct dasd_devmap *devmap;
-
-       devmap = dasd_find_busid(dev_name(&cdev->dev));
-       if (IS_ERR(devmap))
-               return PTR_ERR(devmap);
-
-       spin_lock(&dasd_devmap_lock);
-       devmap->uid = *uid;
-       spin_unlock(&dasd_devmap_lock);
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(dasd_set_uid);
-
 /*
  * Return value of the specified feature.
  */
index 0cb2331..5b1cd8d 100644 (file)
@@ -692,18 +692,20 @@ dasd_eckd_cdl_reclen(int recid)
 /*
  * Generate device unique id that specifies the physical device.
  */
-static int dasd_eckd_generate_uid(struct dasd_device *device,
-                                 struct dasd_uid *uid)
+static int dasd_eckd_generate_uid(struct dasd_device *device)
 {
        struct dasd_eckd_private *private;
+       struct dasd_uid *uid;
        int count;
+       unsigned long flags;
 
        private = (struct dasd_eckd_private *) device->private;
        if (!private)
                return -ENODEV;
        if (!private->ned || !private->gneq)
                return -ENODEV;
-
+       uid = &private->uid;
+       spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
        memset(uid, 0, sizeof(struct dasd_uid));
        memcpy(uid->vendor, private->ned->HDA_manufacturer,
               sizeof(uid->vendor) - 1);
@@ -726,9 +728,25 @@ static int dasd_eckd_generate_uid(struct dasd_device *device,
                                private->vdsneq->uit[count]);
                }
        }
+       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
        return 0;
 }
 
+static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
+{
+       struct dasd_eckd_private *private;
+       unsigned long flags;
+
+       if (device->private) {
+               private = (struct dasd_eckd_private *)device->private;
+               spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
+               *uid = private->uid;
+               spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
+               return 0;
+       }
+       return -EINVAL;
+}
+
 static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
                                                    void *rcd_buffer,
                                                    struct ciw *ciw, __u8 lpm)
@@ -1088,6 +1106,7 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
 {
        struct dasd_eckd_private *private;
        struct dasd_block *block;
+       struct dasd_uid temp_uid;
        int is_known, rc;
        int readonly;
 
@@ -1124,13 +1143,13 @@ dasd_eckd_check_characteristics(struct dasd_device *device)
        if (rc)
                goto out_err1;
 
-       /* Generate device unique id and register in devmap */
-       rc = dasd_eckd_generate_uid(device, &private->uid);
+       /* Generate device unique id */
+       rc = dasd_eckd_generate_uid(device);
        if (rc)
                goto out_err1;
-       dasd_set_uid(device->cdev, &private->uid);
 
-       if (private->uid.type == UA_BASE_DEVICE) {
+       dasd_eckd_get_uid(device, &temp_uid);
+       if (temp_uid.type == UA_BASE_DEVICE) {
                block = dasd_alloc_block();
                if (IS_ERR(block)) {
                        DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
@@ -1451,6 +1470,7 @@ static int dasd_eckd_ready_to_online(struct dasd_device *device)
 
 static int dasd_eckd_online_to_ready(struct dasd_device *device)
 {
+       cancel_work_sync(&device->reload_device);
        return dasd_alias_remove_device(device);
 };
 
@@ -1709,10 +1729,27 @@ static void dasd_eckd_handle_unsolicited_interrupt(struct dasd_device *device,
 {
        char mask;
        char *sense = NULL;
+       struct dasd_eckd_private *private;
 
+       private = (struct dasd_eckd_private *) device->private;
        /* first of all check for state change pending interrupt */
        mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
        if ((scsw_dstat(&irb->scsw) & mask) == mask) {
+               /* for alias only and not in offline processing*/
+               if (!device->block && private->lcu &&
+                   !test_bit(DASD_FLAG_OFFLINE, &device->flags)) {
+                       /*
+                        * the state change could be caused by an alias
+                        * reassignment remove device from alias handling
+                        * to prevent new requests from being scheduled on
+                        * the wrong alias device
+                        */
+                       dasd_alias_remove_device(device);
+
+                       /* schedule worker to reload device */
+                       dasd_reload_device(device);
+               }
+
                dasd_generic_handle_state_change(device);
                return;
        }
@@ -3259,7 +3296,7 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
                dasd_eckd_dump_sense_ccw(device, req, irb);
 }
 
-int dasd_eckd_pm_freeze(struct dasd_device *device)
+static int dasd_eckd_pm_freeze(struct dasd_device *device)
 {
        /*
         * the device should be disconnected from our LCU structure
@@ -3272,7 +3309,7 @@ int dasd_eckd_pm_freeze(struct dasd_device *device)
        return 0;
 }
 
-int dasd_eckd_restore_device(struct dasd_device *device)
+static int dasd_eckd_restore_device(struct dasd_device *device)
 {
        struct dasd_eckd_private *private;
        struct dasd_eckd_characteristics temp_rdc_data;
@@ -3287,15 +3324,16 @@ int dasd_eckd_restore_device(struct dasd_device *device)
        if (rc)
                goto out_err;
 
-       /* Generate device unique id and register in devmap */
-       rc = dasd_eckd_generate_uid(device, &private->uid);
-       dasd_get_uid(device->cdev, &temp_uid);
+       dasd_eckd_get_uid(device, &temp_uid);
+       /* Generate device unique id */
+       rc = dasd_eckd_generate_uid(device);
+       spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
        if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
                dev_err(&device->cdev->dev, "The UID of the DASD has "
                        "changed\n");
+       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
        if (rc)
                goto out_err;
-       dasd_set_uid(device->cdev, &private->uid);
 
        /* register lcu with alias handling, enable PAV if this is a new lcu */
        is_known = dasd_alias_make_device_known_to_lcu(device);
@@ -3336,6 +3374,56 @@ out_err:
        return -1;
 }
 
+static int dasd_eckd_reload_device(struct dasd_device *device)
+{
+       struct dasd_eckd_private *private;
+       int rc, old_base;
+       char print_uid[60];
+       struct dasd_uid uid;
+       unsigned long flags;
+
+       private = (struct dasd_eckd_private *) device->private;
+
+       spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
+       old_base = private->uid.base_unit_addr;
+       spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
+
+       /* Read Configuration Data */
+       rc = dasd_eckd_read_conf(device);
+       if (rc)
+               goto out_err;
+
+       rc = dasd_eckd_generate_uid(device);
+       if (rc)
+               goto out_err;
+       /*
+        * update unit address configuration and
+        * add device to alias management
+        */
+       dasd_alias_update_add_device(device);
+
+       dasd_eckd_get_uid(device, &uid);
+
+       if (old_base != uid.base_unit_addr) {
+               if (strlen(uid.vduit) > 0)
+                       snprintf(print_uid, sizeof(print_uid),
+                                "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
+                                uid.ssid, uid.base_unit_addr, uid.vduit);
+               else
+                       snprintf(print_uid, sizeof(print_uid),
+                                "%s.%s.%04x.%02x", uid.vendor, uid.serial,
+                                uid.ssid, uid.base_unit_addr);
+
+               dev_info(&device->cdev->dev,
+                        "An Alias device was reassigned to a new base device "
+                        "with UID: %s\n", print_uid);
+       }
+       return 0;
+
+out_err:
+       return -1;
+}
+
 static struct ccw_driver dasd_eckd_driver = {
        .name        = "dasd-eckd",
        .owner       = THIS_MODULE,
@@ -3389,6 +3477,8 @@ static struct dasd_discipline dasd_eckd_discipline = {
        .ioctl = dasd_eckd_ioctl,
        .freeze = dasd_eckd_pm_freeze,
        .restore = dasd_eckd_restore_device,
+       .reload = dasd_eckd_reload_device,
+       .get_uid = dasd_eckd_get_uid,
 };
 
 static int __init
index 864d53c..dd6385a 100644 (file)
@@ -426,7 +426,6 @@ struct alias_pav_group {
        struct dasd_device *next;
 };
 
-
 struct dasd_eckd_private {
        struct dasd_eckd_characteristics rdc_data;
        u8 *conf_data;
@@ -463,4 +462,5 @@ void dasd_alias_handle_summary_unit_check(struct dasd_device *, struct irb *);
 void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *);
 void dasd_alias_lcu_setup_complete(struct dasd_device *);
 void dasd_alias_wait_for_lcu_setup(struct dasd_device *);
+int dasd_alias_update_add_device(struct dasd_device *);
 #endif                         /* DASD_ECKD_H */
index a91d4a9..32fac18 100644 (file)
@@ -81,6 +81,10 @@ struct dasd_block;
 #define DASD_SIM_MSG_TO_OP 0x03
 #define DASD_SIM_LOG 0x0C
 
+/* lock class for nested cdev lock */
+#define CDEV_NESTED_FIRST 1
+#define CDEV_NESTED_SECOND 2
+
 /*
  * SECTION: MACROs for klogd and s390 debug feature (dbf)
  */
@@ -228,6 +232,24 @@ struct dasd_ccw_req {
 /* Signature for error recovery functions. */
 typedef struct dasd_ccw_req *(*dasd_erp_fn_t) (struct dasd_ccw_req *);
 
+/*
+ * Unique identifier for dasd device.
+ */
+#define UA_NOT_CONFIGURED  0x00
+#define UA_BASE_DEVICE    0x01
+#define UA_BASE_PAV_ALIAS  0x02
+#define UA_HYPER_PAV_ALIAS 0x03
+
+struct dasd_uid {
+       __u8 type;
+       char vendor[4];
+       char serial[15];
+       __u16 ssid;
+       __u8 real_unit_addr;
+       __u8 base_unit_addr;
+       char vduit[33];
+};
+
 /*
  * the struct dasd_discipline is
  * sth like a table of virtual functions, if you think of dasd_eckd
@@ -312,28 +334,15 @@ struct dasd_discipline {
        /* suspend/resume functions */
        int (*freeze) (struct dasd_device *);
        int (*restore) (struct dasd_device *);
-};
 
-extern struct dasd_discipline *dasd_diag_discipline_pointer;
-
-/*
- * Unique identifier for dasd device.
- */
-#define UA_NOT_CONFIGURED  0x00
-#define UA_BASE_DEVICE    0x01
-#define UA_BASE_PAV_ALIAS  0x02
-#define UA_HYPER_PAV_ALIAS 0x03
+       /* reload device after state change */
+       int (*reload) (struct dasd_device *);
 
-struct dasd_uid {
-       __u8 type;
-       char vendor[4];
-       char serial[15];
-       __u16 ssid;
-       __u8 real_unit_addr;
-       __u8 base_unit_addr;
-       char vduit[33];
+       int (*get_uid) (struct dasd_device *, struct dasd_uid *);
 };
 
+extern struct dasd_discipline *dasd_diag_discipline_pointer;
+
 /*
  * Notification numbers for extended error reporting notifications:
  * The DASD_EER_DISABLE notification is sent before a dasd_device (and it's
@@ -386,6 +395,7 @@ struct dasd_device {
         struct tasklet_struct tasklet;
        struct work_struct kick_work;
        struct work_struct restore_device;
+       struct work_struct reload_device;
        struct timer_list timer;
 
        debug_info_t *debug_area;
@@ -582,6 +592,7 @@ void dasd_enable_device(struct dasd_device *);
 void dasd_set_target_state(struct dasd_device *, int);
 void dasd_kick_device(struct dasd_device *);
 void dasd_restore_device(struct dasd_device *);
+void dasd_reload_device(struct dasd_device *);
 
 void dasd_add_request_head(struct dasd_ccw_req *);
 void dasd_add_request_tail(struct dasd_ccw_req *);
@@ -629,8 +640,6 @@ void dasd_devmap_exit(void);
 struct dasd_device *dasd_create_device(struct ccw_device *);
 void dasd_delete_device(struct dasd_device *);
 
-int dasd_get_uid(struct ccw_device *, struct dasd_uid *);
-int dasd_set_uid(struct ccw_device *, struct dasd_uid *);
 int dasd_get_feature(struct ccw_device *, int);
 int dasd_set_feature(struct ccw_device *, int, int);
 
index 4e34d36..40834f1 100644 (file)
@@ -148,13 +148,12 @@ config VMLOGRDR
          This driver depends on the IUCV support driver.
 
 config VMCP
-       tristate "Support for the z/VM CP interface (VM only)"
+       bool "Support for the z/VM CP interface"
        depends on S390
        help
          Select this option if you want to be able to interact with the control
          program on z/VM
 
-
 config MONREADER
        tristate "API for reading z/VM monitor service records"
        depends on IUCV
index 0eabcca..857dfcb 100644 (file)
@@ -484,6 +484,7 @@ fs3270_open(struct inode *inode, struct file *filp)
                raw3270_del_view(&fp->view);
                goto out;
        }
+       nonseekable_open(inode, filp);
        filp->private_data = fp;
 out:
        mutex_unlock(&fs3270_mutex);
index cb6bffe..18d9a49 100644 (file)
@@ -49,7 +49,7 @@ static unsigned char ret_diacr[NR_DEAD] = {
 struct kbd_data *
 kbd_alloc(void) {
        struct kbd_data *kbd;
-       int i, len;
+       int i;
 
        kbd = kzalloc(sizeof(struct kbd_data), GFP_KERNEL);
        if (!kbd)
@@ -59,12 +59,11 @@ kbd_alloc(void) {
                goto out_kbd;
        for (i = 0; i < ARRAY_SIZE(key_maps); i++) {
                if (key_maps[i]) {
-                       kbd->key_maps[i] =
-                               kmalloc(sizeof(u_short)*NR_KEYS, GFP_KERNEL);
+                       kbd->key_maps[i] = kmemdup(key_maps[i],
+                                                  sizeof(u_short) * NR_KEYS,
+                                                  GFP_KERNEL);
                        if (!kbd->key_maps[i])
                                goto out_maps;
-                       memcpy(kbd->key_maps[i], key_maps[i],
-                              sizeof(u_short)*NR_KEYS);
                }
        }
        kbd->func_table = kzalloc(sizeof(func_table), GFP_KERNEL);
@@ -72,23 +71,21 @@ kbd_alloc(void) {
                goto out_maps;
        for (i = 0; i < ARRAY_SIZE(func_table); i++) {
                if (func_table[i]) {
-                       len = strlen(func_table[i]) + 1;
-                       kbd->func_table[i] = kmalloc(len, GFP_KERNEL);
+                       kbd->func_table[i] = kstrdup(func_table[i],
+                                                    GFP_KERNEL);
                        if (!kbd->func_table[i])
                                goto out_func;
-                       memcpy(kbd->func_table[i], func_table[i], len);
                }
        }
        kbd->fn_handler =
                kzalloc(sizeof(fn_handler_fn *) * NR_FN_HANDLER, GFP_KERNEL);
        if (!kbd->fn_handler)
                goto out_func;
-       kbd->accent_table =
-               kmalloc(sizeof(struct kbdiacruc)*MAX_DIACR, GFP_KERNEL);
+       kbd->accent_table = kmemdup(accent_table,
+                                   sizeof(struct kbdiacruc) * MAX_DIACR,
+                                   GFP_KERNEL);
        if (!kbd->accent_table)
                goto out_fn_handler;
-       memcpy(kbd->accent_table, accent_table,
-              sizeof(struct kbdiacruc)*MAX_DIACR);
        kbd->accent_table_size = accent_table_size;
        return kbd;
 
index 62c2647..4a51e3f 100644 (file)
@@ -102,7 +102,7 @@ static struct sclp_req *cpi_prepare_req(void)
        /* set system name */
        set_data(evb->system_name, system_name);
 
-       /* set sytem level */
+       /* set system level */
        evb->system_level = system_level;
 
        /* set sysplex name */
index 5bb59d3..04e532e 100644 (file)
@@ -1,24 +1,20 @@
 /*
- * Copyright IBM Corp. 2004,2007
+ * Copyright IBM Corp. 2004,2010
  * Interface implementation for communication with the z/VM control program
- * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
  *
+ * Author(s): Christian Borntraeger <borntraeger@de.ibm.com>
  *
  * z/VMs CP offers the possibility to issue commands via the diagnose code 8
  * this driver implements a character device that issues these commands and
  * returns the answer of CP.
-
+ *
  * The idea of this driver is based on cpint from Neale Ferguson and #CP in CMS
  */
 
-#define KMSG_COMPONENT "vmcp"
-#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
-
 #include <linux/fs.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/miscdevice.h>
-#include <linux/module.h>
 #include <linux/slab.h>
 #include <asm/compat.h>
 #include <asm/cpcmd.h>
 #include <asm/uaccess.h>
 #include "vmcp.h"
 
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Christian Borntraeger <borntraeger@de.ibm.com>");
-MODULE_DESCRIPTION("z/VM CP interface");
-
 static debug_info_t *vmcp_debug;
 
 static int vmcp_open(struct inode *inode, struct file *file)
@@ -197,11 +189,8 @@ static int __init vmcp_init(void)
 {
        int ret;
 
-       if (!MACHINE_IS_VM) {
-               pr_warning("The z/VM CP interface device driver cannot be "
-                          "loaded without z/VM\n");
-               return -ENODEV;
-       }
+       if (!MACHINE_IS_VM)
+               return 0;
 
        vmcp_debug = debug_register("vmcp", 1, 1, 240);
        if (!vmcp_debug)
@@ -214,19 +203,8 @@ static int __init vmcp_init(void)
        }
 
        ret = misc_register(&vmcp_dev);
-       if (ret) {
+       if (ret)
                debug_unregister(vmcp_debug);
-               return ret;
-       }
-
-       return 0;
-}
-
-static void __exit vmcp_exit(void)
-{
-       misc_deregister(&vmcp_dev);
-       debug_unregister(vmcp_debug);
+       return ret;
 }
-
-module_init(vmcp_init);
-module_exit(vmcp_exit);
+device_initcall(vmcp_init);
index 7217966..f5ea338 100644 (file)
@@ -445,7 +445,7 @@ static int zcore_memmap_open(struct inode *inode, struct file *filp)
        }
        kfree(chunk_array);
        filp->private_data = buf;
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 static int zcore_memmap_release(struct inode *inode, struct file *filp)
@@ -473,7 +473,7 @@ static ssize_t zcore_reipl_write(struct file *filp, const char __user *buf,
 
 static int zcore_reipl_open(struct inode *inode, struct file *filp)
 {
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 static int zcore_reipl_release(struct inode *inode, struct file *filp)
index 3b6f4ad..a83877c 100644 (file)
@@ -803,6 +803,7 @@ static long chsc_ioctl(struct file *filp, unsigned int cmd,
 
 static const struct file_operations chsc_fops = {
        .owner = THIS_MODULE,
+       .open = nonseekable_open,
        .unlocked_ioctl = chsc_ioctl,
        .compat_ioctl = chsc_ioctl,
 };
index 5feea1a..f4e6cf3 100644 (file)
@@ -616,7 +616,8 @@ void __irq_entry do_IRQ(struct pt_regs *regs)
        struct pt_regs *old_regs;
 
        old_regs = set_irq_regs(regs);
-       s390_idle_check();
+       s390_idle_check(regs, S390_lowcore.int_clock,
+                       S390_lowcore.async_enter_timer);
        irq_enter();
        __get_cpu_var(s390_idle).nohz_delay = 1;
        if (S390_lowcore.int_clock >= S390_lowcore.clock_comparator)
index 5116491..ac94ac7 100644 (file)
@@ -648,6 +648,8 @@ static void css_process_crw(struct crw *crw0, struct crw *crw1, int overflow)
 static void __init
 css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
 {
+       struct cpuid cpu_id;
+
        if (css_general_characteristics.mcss) {
                css->global_pgid.pgid_high.ext_cssid.version = 0x80;
                css->global_pgid.pgid_high.ext_cssid.cssid = css->cssid;
@@ -658,8 +660,9 @@ css_generate_pgid(struct channel_subsystem *css, u32 tod_high)
                css->global_pgid.pgid_high.cpu_addr = 0;
 #endif
        }
-       css->global_pgid.cpu_id = S390_lowcore.cpu_id.ident;
-       css->global_pgid.cpu_model = S390_lowcore.cpu_id.machine;
+       get_cpu_id(&cpu_id);
+       css->global_pgid.cpu_id = cpu_id.ident;
+       css->global_pgid.cpu_model = cpu_id.machine;
        css->global_pgid.tod_high = tod_high;
 
 }
@@ -1062,6 +1065,7 @@ static ssize_t cio_settle_write(struct file *file, const char __user *buf,
 }
 
 static const struct file_operations cio_settle_proc_fops = {
+       .open = nonseekable_open,
        .write = cio_settle_write,
 };
 
index 48aa064..f0037ee 100644 (file)
@@ -13,8 +13,8 @@
 #include <asm/debug.h>
 #include "chsc.h"
 
-#define QDIO_BUSY_BIT_PATIENCE         100     /* 100 microseconds */
-#define QDIO_INPUT_THRESHOLD           500     /* 500 microseconds */
+#define QDIO_BUSY_BIT_PATIENCE         (100 << 12)     /* 100 microseconds */
+#define QDIO_INPUT_THRESHOLD           (500 << 12)     /* 500 microseconds */
 
 /*
  * if an asynchronous HiperSockets queue runs full, the 10 seconds timer wait
@@ -296,10 +296,8 @@ struct qdio_q {
        struct qdio_irq *irq_ptr;
        struct sl *sl;
        /*
-        * Warning: Leave this member at the end so it won't be cleared in
-        * qdio_fill_qs. A page is allocated under this pointer and used for
-        * slib and sl. slib is 2048 bytes big and sl points to offset
-        * PAGE_SIZE / 2.
+        * A page is allocated under this pointer and used for slib and sl.
+        * slib is 2048 bytes big and sl points to offset PAGE_SIZE / 2.
         */
        struct slib *slib;
 } __attribute__ ((aligned(256)));
@@ -372,11 +370,6 @@ static inline int multicast_outbound(struct qdio_q *q)
               (q->nr == q->irq_ptr->nr_output_qs - 1);
 }
 
-static inline unsigned long long get_usecs(void)
-{
-       return monotonic_clock() >> 12;
-}
-
 #define pci_out_supported(q) \
        (q->irq_ptr->qib.ac & QIB_AC_OUTBOUND_PCI_SUPPORTED)
 #define is_qebsm(q)                    (q->irq_ptr->sch_token != 0)
index 88be7b9..00520f9 100644 (file)
@@ -336,10 +336,10 @@ again:
                WARN_ON(queue_type(q) != QDIO_IQDIO_QFMT || cc != 2);
 
                if (!start_time) {
-                       start_time = get_usecs();
+                       start_time = get_clock();
                        goto again;
                }
-               if ((get_usecs() - start_time) < QDIO_BUSY_BIT_PATIENCE)
+               if ((get_clock() - start_time) < QDIO_BUSY_BIT_PATIENCE)
                        goto again;
        }
        return cc;
@@ -536,7 +536,7 @@ static int qdio_inbound_q_moved(struct qdio_q *q)
        if ((bufnr != q->last_move) || q->qdio_error) {
                q->last_move = bufnr;
                if (!is_thinint_irq(q->irq_ptr) && MACHINE_IS_LPAR)
-                       q->u.in.timestamp = get_usecs();
+                       q->u.in.timestamp = get_clock();
                return 1;
        } else
                return 0;
@@ -567,7 +567,7 @@ static inline int qdio_inbound_q_done(struct qdio_q *q)
         * At this point we know, that inbound first_to_check
         * has (probably) not moved (see qdio_inbound_processing).
         */
-       if (get_usecs() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
+       if (get_clock() > q->u.in.timestamp + QDIO_INPUT_THRESHOLD) {
                DBF_DEV_EVENT(DBF_INFO, q->irq_ptr, "in done:%02x",
                              q->first_to_check);
                return 1;
@@ -606,7 +606,7 @@ static void qdio_kick_handler(struct qdio_q *q)
 static void __qdio_inbound_processing(struct qdio_q *q)
 {
        qperf_inc(q, tasklet_inbound);
-again:
+
        if (!qdio_inbound_q_moved(q))
                return;
 
@@ -615,7 +615,10 @@ again:
        if (!qdio_inbound_q_done(q)) {
                /* means poll time is not yet over */
                qperf_inc(q, tasklet_inbound_resched);
-               goto again;
+               if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED)) {
+                       tasklet_schedule(&q->tasklet);
+                       return;
+               }
        }
 
        qdio_stop_polling(q);
@@ -625,7 +628,8 @@ again:
         */
        if (!qdio_inbound_q_done(q)) {
                qperf_inc(q, tasklet_inbound_resched2);
-               goto again;
+               if (likely(q->irq_ptr->state != QDIO_IRQ_STATE_STOPPED))
+                       tasklet_schedule(&q->tasklet);
        }
 }
 
@@ -955,6 +959,9 @@ void qdio_int_handler(struct ccw_device *cdev, unsigned long intparm,
                return;
        }
 
+       if (irq_ptr->perf_stat_enabled)
+               irq_ptr->perf_stat.qdio_int++;
+
        if (IS_ERR(irb)) {
                switch (PTR_ERR(irb)) {
                case -EIO:
@@ -1016,30 +1023,6 @@ int qdio_get_ssqd_desc(struct ccw_device *cdev,
 }
 EXPORT_SYMBOL_GPL(qdio_get_ssqd_desc);
 
-/**
- * qdio_cleanup - shutdown queues and free data structures
- * @cdev: associated ccw device
- * @how: use halt or clear to shutdown
- *
- * This function calls qdio_shutdown() for @cdev with method @how.
- * and qdio_free(). The qdio_free() return value is ignored since
- * !irq_ptr is already checked.
- */
-int qdio_cleanup(struct ccw_device *cdev, int how)
-{
-       struct qdio_irq *irq_ptr = cdev->private->qdio_data;
-       int rc;
-
-       if (!irq_ptr)
-               return -ENODEV;
-
-       rc = qdio_shutdown(cdev, how);
-
-       qdio_free(cdev);
-       return rc;
-}
-EXPORT_SYMBOL_GPL(qdio_cleanup);
-
 static void qdio_shutdown_queues(struct ccw_device *cdev)
 {
        struct qdio_irq *irq_ptr = cdev->private->qdio_data;
@@ -1156,28 +1139,6 @@ int qdio_free(struct ccw_device *cdev)
 }
 EXPORT_SYMBOL_GPL(qdio_free);
 
-/**
- * qdio_initialize - allocate and establish queues for a qdio subchannel
- * @init_data: initialization data
- *
- * This function first allocates queues via qdio_allocate() and on success
- * establishes them via qdio_establish().
- */
-int qdio_initialize(struct qdio_initialize *init_data)
-{
-       int rc;
-
-       rc = qdio_allocate(init_data);
-       if (rc)
-               return rc;
-
-       rc = qdio_establish(init_data);
-       if (rc)
-               qdio_free(init_data->cdev);
-       return rc;
-}
-EXPORT_SYMBOL_GPL(qdio_initialize);
-
 /**
  * qdio_allocate - allocate qdio queues and associated data
  * @init_data: initialization data
index 7f4a754..6326b67 100644 (file)
@@ -106,10 +106,12 @@ int qdio_allocate_qs(struct qdio_irq *irq_ptr, int nr_input_qs, int nr_output_qs
 static void setup_queues_misc(struct qdio_q *q, struct qdio_irq *irq_ptr,
                              qdio_handler_t *handler, int i)
 {
-       /* must be cleared by every qdio_establish */
-       memset(q, 0, ((char *)&q->slib) - ((char *)q));
-       memset(q->slib, 0, PAGE_SIZE);
+       struct slib *slib = q->slib;
 
+       /* queue must be cleared for qdio_establish */
+       memset(q, 0, sizeof(*q));
+       memset(slib, 0, PAGE_SIZE);
+       q->slib = slib;
        q->irq_ptr = irq_ptr;
        q->mask = 1 << (31 - i);
        q->nr = i;
index ce5f891..8daf1b9 100644 (file)
@@ -95,7 +95,7 @@ void tiqdio_add_input_queues(struct qdio_irq *irq_ptr)
        for_each_input_queue(irq_ptr, q, i)
                list_add_rcu(&q->entry, &tiq_list);
        mutex_unlock(&tiq_list_lock);
-       xchg(irq_ptr->dsci, 1);
+       xchg(irq_ptr->dsci, 1 << 7);
 }
 
 void tiqdio_remove_input_queues(struct qdio_irq *irq_ptr)
@@ -173,7 +173,7 @@ static void tiqdio_thinint_handler(void *ind, void *drv_data)
 
                /* prevent racing */
                if (*tiqdio_alsi)
-                       xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1);
+                       xchg(&q_indicators[TIQDIO_SHARED_IND].ind, 1 << 7);
        }
 }
 
index 304caf5..41e0aae 100644 (file)
@@ -302,7 +302,7 @@ static ssize_t zcrypt_write(struct file *filp, const char __user *buf,
 static int zcrypt_open(struct inode *inode, struct file *filp)
 {
        atomic_inc(&zcrypt_open_count);
-       return 0;
+       return nonseekable_open(inode, filp);
 }
 
 /**
index 3ba738b..28f7134 100644 (file)
@@ -1292,13 +1292,14 @@ int qeth_qdio_clear_card(struct qeth_card *card, int use_halt)
                QETH_QDIO_CLEANING)) {
        case QETH_QDIO_ESTABLISHED:
                if (card->info.type == QETH_CARD_TYPE_IQD)
-                       rc = qdio_cleanup(CARD_DDEV(card),
+                       rc = qdio_shutdown(CARD_DDEV(card),
                                QDIO_FLAG_CLEANUP_USING_HALT);
                else
-                       rc = qdio_cleanup(CARD_DDEV(card),
+                       rc = qdio_shutdown(CARD_DDEV(card),
                                QDIO_FLAG_CLEANUP_USING_CLEAR);
                if (rc)
                        QETH_DBF_TEXT_(TRACE, 3, "1err%d", rc);
+               qdio_free(CARD_DDEV(card));
                atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
                break;
        case QETH_QDIO_CLEANING:
@@ -3810,10 +3811,18 @@ static int qeth_qdio_establish(struct qeth_card *card)
 
        if (atomic_cmpxchg(&card->qdio.state, QETH_QDIO_ALLOCATED,
                QETH_QDIO_ESTABLISHED) == QETH_QDIO_ALLOCATED) {
-               rc = qdio_initialize(&init_data);
-               if (rc)
+               rc = qdio_allocate(&init_data);
+               if (rc) {
+                       atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
+                       goto out;
+               }
+               rc = qdio_establish(&init_data);
+               if (rc) {
                        atomic_set(&card->qdio.state, QETH_QDIO_ALLOCATED);
+                       qdio_free(CARD_DDEV(card));
+               }
        }
+out:
        kfree(out_sbal_ptrs);
        kfree(in_sbal_ptrs);
        kfree(qib_param_field);
index 25d9e0a..1a2db0a 100644 (file)
@@ -254,6 +254,7 @@ static long zfcp_cfdc_dev_ioctl(struct file *file, unsigned int command,
 }
 
 static const struct file_operations zfcp_cfdc_fops = {
+       .open = nonseekable_open,
        .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl = zfcp_cfdc_dev_ioctl
index 19f255b..d3b62eb 100644 (file)
@@ -105,9 +105,9 @@ static ssize_t
 flash_read(struct file * file, char __user * buf,
           size_t count, loff_t *ppos)
 {
-       unsigned long p = file->f_pos;
+       loff_t p = *ppos;
        int i;
-       
+
        if (count > flash.read_size - p)
                count = flash.read_size - p;
 
@@ -118,7 +118,7 @@ flash_read(struct file * file, char __user * buf,
                buf++;
        }
 
-       file->f_pos += count;
+       *ppos += count;
        return count;
 }
 
index b0ac9ac..6eaf519 100644 (file)
@@ -50,7 +50,7 @@ struct bfa_cee_lldp_str_s {
 };
 
 
-/* LLDP paramters */
+/* LLDP parameters */
 struct bfa_cee_lldp_cfg_s {
        struct bfa_cee_lldp_str_s chassis_id;
        struct bfa_cee_lldp_str_s port_id;
index 4374494..ec78b4c 100644 (file)
@@ -223,9 +223,9 @@ enum bfa_status {
        BFA_STATUS_IM_PVID_NON_ZERO = 140, /*  Port VLAN ID (PVID) is Set to
                                            * Non-Zero Value */
        BFA_STATUS_IM_INETCFG_LOCK_FAILED = 141, /*  Acquiring Network
-                                                 * Subsytem Lock Failed.Please
+                                                 * Subsystem Lock Failed.Please
                                                  * try after some time */
-       BFA_STATUS_IM_GET_INETCFG_FAILED = 142, /*  Acquiring Network Subsytem
+       BFA_STATUS_IM_GET_INETCFG_FAILED = 142, /*  Acquiring Network Subsystem
                                                 * handle Failed. Please try
                                                 * after some time */
        BFA_STATUS_IM_NOT_BOUND = 143, /*  IM driver is not active */
index 520461b..b90c118 100644 (file)
@@ -4295,7 +4295,7 @@ static void ipr_slave_destroy(struct scsi_device *sdev)
        res = (struct ipr_resource_entry *) sdev->hostdata;
        if (res) {
                if (res->sata_port)
-                       ata_port_disable(res->sata_port->ap);
+                       res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
                sdev->hostdata = NULL;
                res->sdev = NULL;
                res->sata_port = NULL;
@@ -5751,13 +5751,13 @@ static void ipr_ata_phy_reset(struct ata_port *ap)
        rc = ipr_device_reset(ioa_cfg, res);
 
        if (rc) {
-               ata_port_disable(ap);
+               ap->link.device[0].class = ATA_DEV_NONE;
                goto out_unlock;
        }
 
        ap->link.device[0].class = res->ata_class;
        if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
-               ata_port_disable(ap);
+               ap->link.device[0].class = ATA_DEV_NONE;
 
 out_unlock:
        spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
index 8228350..b71b6d4 100644 (file)
@@ -818,7 +818,7 @@ void sas_slave_destroy(struct scsi_device *scsi_dev)
        struct domain_device *dev = sdev_to_domain_dev(scsi_dev);
 
        if (dev_is_sata(dev))
-               ata_port_disable(dev->sata_dev.ap);
+               dev->sata_dev.ap->link.device[0].class = ATA_DEV_NONE;
 }
 
 int sas_change_queue_depth(struct scsi_device *scsi_dev, int new_depth,
index 528733b..9d70aef 100644 (file)
@@ -80,7 +80,6 @@ MODULE_LICENSE("Dual MPL/GPL");
 
 typedef struct scsi_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t         node;
     struct Scsi_Host   *host;
 } scsi_info_t;
 
@@ -105,7 +104,6 @@ static int aha152x_probe(struct pcmcia_device *link)
     link->io.NumPorts1 = 0x20;
     link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
     link->io.IOAddrLines = 10;
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
     link->conf.Present = PRESENT_OPTION;
@@ -160,8 +158,7 @@ static int aha152x_config_cs(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
 
     ret = pcmcia_request_configuration(link, &link->conf);
@@ -172,7 +169,7 @@ static int aha152x_config_cs(struct pcmcia_device *link)
     memset(&s, 0, sizeof(s));
     s.conf        = "PCMCIA setup";
     s.io_port     = link->io.BasePort1;
-    s.irq         = link->irq.AssignedIRQ;
+    s.irq         = link->irq;
     s.scsiid      = host_id;
     s.reconnect   = reconnect;
     s.parity      = parity;
@@ -187,8 +184,6 @@ static int aha152x_config_cs(struct pcmcia_device *link)
        goto failed;
     }
 
-    sprintf(info->node.dev_name, "scsi%d", host->host_no);
-    link->dev_node = &info->node;
     info->host = host;
 
     return 0;
index 9140406..21b1411 100644 (file)
@@ -63,7 +63,6 @@ MODULE_LICENSE("Dual MPL/GPL");
 
 typedef struct scsi_info_t {
        struct pcmcia_device    *p_dev;
-    dev_node_t         node;
     struct Scsi_Host   *host;
 } scsi_info_t;
 
@@ -88,7 +87,6 @@ static int fdomain_probe(struct pcmcia_device *link)
        link->io.NumPorts1 = 0x10;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.IOAddrLines = 10;
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.Present = PRESENT_OPTION;
@@ -133,8 +131,7 @@ static int fdomain_config(struct pcmcia_device *link)
     if (ret)
            goto failed;
 
-    ret = pcmcia_request_irq(link, &link->irq);
-    if (ret)
+    if (!link->irq)
            goto failed;
     ret = pcmcia_request_configuration(link, &link->conf);
     if (ret)
@@ -144,7 +141,7 @@ static int fdomain_config(struct pcmcia_device *link)
     release_region(link->io.BasePort1, link->io.NumPorts1);
 
     /* Set configuration options for the fdomain driver */
-    sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
+    sprintf(str, "%d,%d", link->io.BasePort1, link->irq);
     fdomain_setup(str);
 
     host = __fdomain_16x0_detect(&fdomain_driver_template);
@@ -157,8 +154,6 @@ static int fdomain_config(struct pcmcia_device *link)
            goto failed;
     scsi_scan_host(host);
 
-    sprintf(info->node.dev_name, "scsi%d", host->host_no);
-    link->dev_node = &info->node;
     info->host = host;
 
     return 0;
index 0212464..0f0e112 100644 (file)
@@ -1563,13 +1563,6 @@ static int nsp_cs_probe(struct pcmcia_device *link)
        link->io.Attributes1     = IO_DATA_PATH_WIDTH_AUTO;
        link->io.IOAddrLines     = 10;  /* not used */
 
-       /* Interrupt setup */
-       link->irq.Attributes     = IRQ_TYPE_EXCLUSIVE;
-
-       /* Interrupt handler */
-       link->irq.Handler        = &nspintr;
-       link->irq.Attributes     |= IRQF_SHARED;
-
        /* General socket configuration */
        link->conf.Attributes    = CONF_ENABLE_IRQ;
        link->conf.IntType       = INT_MEMORY_AND_IO;
@@ -1646,8 +1639,7 @@ static int nsp_cs_config_check(struct pcmcia_device *p_dev,
                }
 
                /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-                       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
                /* IO window settings */
                p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -1720,10 +1712,8 @@ static int nsp_cs_config(struct pcmcia_device *link)
        if (ret)
                goto cs_failed;
 
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               if (pcmcia_request_irq(link, &link->irq))
-                       goto cs_failed;
-       }
+       if (pcmcia_request_irq(link, nspintr))
+               goto cs_failed;
 
        ret = pcmcia_request_configuration(link, &link->conf);
        if (ret)
@@ -1741,7 +1731,7 @@ static int nsp_cs_config(struct pcmcia_device *link)
        /* Set port and IRQ */
        data->BaseAddress = link->io.BasePort1;
        data->NumAddress  = link->io.NumPorts1;
-       data->IrqNumber   = link->irq.AssignedIRQ;
+       data->IrqNumber   = link->irq;
 
        nsp_dbg(NSP_DEBUG_INIT, "I/O[0x%x+0x%x] IRQ %d",
                data->BaseAddress, data->NumAddress, data->IrqNumber);
@@ -1764,8 +1754,6 @@ static int nsp_cs_config(struct pcmcia_device *link)
 
        scsi_scan_host(host);
 
-       snprintf(info->node.dev_name, sizeof(info->node.dev_name), "scsi%d", host->host_no);
-       link->dev_node  = &info->node;
        info->host = host;
 
        /* Finally, report what we've done */
@@ -1775,7 +1763,7 @@ static int nsp_cs_config(struct pcmcia_device *link)
                printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
        }
        if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               printk(", irq %d", link->irq.AssignedIRQ);
+               printk(", irq %d", link->irq);
        }
        if (link->io.NumPorts1) {
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
@@ -1823,7 +1811,6 @@ static void nsp_cs_release(struct pcmcia_device *link)
        if (info->host != NULL) {
                scsi_remove_host(info->host);
        }
-       link->dev_node = NULL;
 
        if (link->win) {
                if (data != NULL) {
index 8c61a4f..d68c9f2 100644 (file)
 typedef struct scsi_info_t {
        struct pcmcia_device    *p_dev;
        struct Scsi_Host      *host;
-       dev_node_t             node;
        int                    stop;
 } scsi_info_t;
 
index f85f094..f0fc6ba 100644 (file)
@@ -82,7 +82,6 @@ static struct scsi_host_template qlogicfas_driver_template = {
 
 typedef struct scsi_info_t {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
        struct Scsi_Host *host;
        unsigned short manf_id;
 } scsi_info_t;
@@ -161,7 +160,6 @@ static int qlogic_probe(struct pcmcia_device *link)
        link->io.NumPorts1 = 16;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.IOAddrLines = 10;
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.Present = PRESENT_OPTION;
@@ -209,8 +207,7 @@ static int qlogic_config(struct pcmcia_device * link)
        if (ret)
                goto failed;
 
-       ret = pcmcia_request_irq(link, &link->irq);
-       if (ret)
+       if (!link->irq)
                goto failed;
 
        ret = pcmcia_request_configuration(link, &link->conf);
@@ -227,18 +224,16 @@ static int qlogic_config(struct pcmcia_device * link)
        /* The KXL-810AN has a bigger IO port window */
        if (link->io.NumPorts1 == 32)
                host = qlogic_detect(&qlogicfas_driver_template, link,
-                       link->io.BasePort1 + 16, link->irq.AssignedIRQ);
+                       link->io.BasePort1 + 16, link->irq);
        else
                host = qlogic_detect(&qlogicfas_driver_template, link,
-                       link->io.BasePort1, link->irq.AssignedIRQ);
+                       link->io.BasePort1, link->irq);
        
        if (!host) {
                printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
                goto failed;
        }
 
-       sprintf(info->node.dev_name, "scsi%d", host->host_no);
-       link->dev_node = &info->node;
        info->host = host;
 
        return 0;
@@ -258,7 +253,7 @@ static void qlogic_release(struct pcmcia_device *link)
 
        scsi_remove_host(info->host);
 
-       free_irq(link->irq.AssignedIRQ, info->host);
+       free_irq(link->irq, info->host);
        pcmcia_disable_device(link);
 
        scsi_host_put(info->host);
index e7564d8..a511641 100644 (file)
 
 struct scsi_info_t {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
        struct Scsi_Host *host;
        unsigned short manf_id;
 };
@@ -719,8 +718,7 @@ SYM53C500_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       ret = pcmcia_request_irq(link, &link->irq);
-       if (ret)
+       if (!link->irq)
                goto failed;
 
        ret = pcmcia_request_configuration(link, &link->conf);
@@ -752,7 +750,7 @@ SYM53C500_config(struct pcmcia_device *link)
        *       0x320, 0x330, 0x340, 0x350
        */
        port_base = link->io.BasePort1;
-       irq_level = link->irq.AssignedIRQ;
+       irq_level = link->irq;
 
        DEB(printk("SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n",
            port_base, irq_level, USE_FAST_PIO);)
@@ -793,8 +791,6 @@ SYM53C500_config(struct pcmcia_device *link)
        */
        data->fast_pio = USE_FAST_PIO;
 
-       sprintf(info->node.dev_name, "scsi%d", host->host_no);
-       link->dev_node = &info->node;
        info->host = host;
 
        if (scsi_add_host(host, NULL))
@@ -866,7 +862,6 @@ SYM53C500_probe(struct pcmcia_device *link)
        link->io.NumPorts1 = 16;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.IOAddrLines = 10;
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
index 105449c..e17764d 100644 (file)
@@ -69,6 +69,7 @@ static struct zorro_device_id zorro7xx_zorro_tbl[] __devinitdata = {
        },
        { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, zorro7xx_zorro_tbl);
 
 static int __devinit zorro7xx_init_one(struct zorro_dev *z,
                                       const struct zorro_device_id *ent)
index f55c494..302836a 100644 (file)
@@ -518,12 +518,13 @@ config SERIAL_S3C2412
          Serial port support for the Samsung S3C2412 and S3C2413 SoC
 
 config SERIAL_S3C2440
-       tristate "Samsung S3C2440/S3C2442 Serial port support"
-       depends on SERIAL_SAMSUNG && (CPU_S3C2440 || CPU_S3C2442)
+       tristate "Samsung S3C2440/S3C2442/S3C2416 Serial port support"
+       depends on SERIAL_SAMSUNG && (CPU_S3C2440 || CPU_S3C2442 || CPU_S3C2416)
        default y if CPU_S3C2440
        default y if CPU_S3C2442
+       select SERIAL_SAMSUNG_UARTS_4 if CPU_S3C2416
        help
-         Serial port support for the Samsung S3C2440 and S3C2442 SoC
+         Serial port support for the Samsung S3C2440, S3C2416 and S3C2442 SoC
 
 config SERIAL_S3C24A0
        tristate "Samsung S3C24A0 Serial port support"
@@ -533,21 +534,13 @@ config SERIAL_S3C24A0
          Serial port support for the Samsung S3C24A0 SoC
 
 config SERIAL_S3C6400
-       tristate "Samsung S3C6400/S3C6410/S5P6440 Seria port support"
-       depends on SERIAL_SAMSUNG && (CPU_S3C6400 || CPU_S3C6410 || CPU_S5P6440)
+       tristate "Samsung S3C6400/S3C6410/S5P6440/S5PC100 Serial port support"
+       depends on SERIAL_SAMSUNG && (CPU_S3C6400 || CPU_S3C6410 || CPU_S5P6440 || CPU_S5PC100)
        select SERIAL_SAMSUNG_UARTS_4
        default y
        help
-         Serial port support for the Samsung S3C6400, S3C6410 and S5P6440
-         SoCs
-
-config SERIAL_S5PC100
-       tristate "Samsung S5PC100 Serial port support"
-       depends on SERIAL_SAMSUNG && CPU_S5PC100
-       select SERIAL_SAMSUNG_UARTS_4
-       default y
-       help
-         Serial port support for the Samsung S5PC100 SoCs
+         Serial port support for the Samsung S3C6400, S3C6410, S5P6440
+         and S5PC100 SoCs
 
 config SERIAL_S5PV210
        tristate "Samsung S5PV210 Serial port support"
index 6aa4723..328f107 100644 (file)
@@ -44,7 +44,6 @@ obj-$(CONFIG_SERIAL_S3C2412) += s3c2412.o
 obj-$(CONFIG_SERIAL_S3C2440) += s3c2440.o
 obj-$(CONFIG_SERIAL_S3C24A0) += s3c24a0.o
 obj-$(CONFIG_SERIAL_S3C6400) += s3c6400.o
-obj-$(CONFIG_SERIAL_S5PC100) += s3c6400.o
 obj-$(CONFIG_SERIAL_S5PV210) += s5pv210.o
 obj-$(CONFIG_SERIAL_MAX3100) += max3100.o
 obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
index 2c9bf9b..eed3c2d 100644 (file)
@@ -38,6 +38,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/atmel_pdc.h>
 #include <linux/atmel_serial.h>
+#include <linux/uaccess.h>
 
 #include <asm/io.h>
 
@@ -59,6 +60,9 @@
 
 #include <linux/serial_core.h>
 
+static void atmel_start_rx(struct uart_port *port);
+static void atmel_stop_rx(struct uart_port *port);
+
 #ifdef CONFIG_SERIAL_ATMEL_TTYAT
 
 /* Use device name ttyAT, major 204 and minor 154-169.  This is necessary if we
@@ -93,6 +97,7 @@
 #define UART_GET_BRGR(port)    __raw_readl((port)->membase + ATMEL_US_BRGR)
 #define UART_PUT_BRGR(port,v)  __raw_writel(v, (port)->membase + ATMEL_US_BRGR)
 #define UART_PUT_RTOR(port,v)  __raw_writel(v, (port)->membase + ATMEL_US_RTOR)
+#define UART_PUT_TTGR(port, v) __raw_writel(v, (port)->membase + ATMEL_US_TTGR)
 
  /* PDC registers */
 #define UART_PUT_PTCR(port,v)  __raw_writel(v, (port)->membase + ATMEL_PDC_PTCR)
@@ -147,6 +152,9 @@ struct atmel_uart_port {
        unsigned int            irq_status_prev;
 
        struct circ_buf         rx_ring;
+
+       struct serial_rs485     rs485;          /* rs485 settings */
+       unsigned int            tx_done_mask;
 };
 
 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
@@ -187,6 +195,46 @@ static bool atmel_use_dma_tx(struct uart_port *port)
 }
 #endif
 
+/* Enable or disable the rs485 support */
+void atmel_config_rs485(struct uart_port *port, struct serial_rs485 *rs485conf)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       unsigned int mode;
+
+       spin_lock(&port->lock);
+
+       /* Disable interrupts */
+       UART_PUT_IDR(port, atmel_port->tx_done_mask);
+
+       mode = UART_GET_MR(port);
+
+       /* Resetting serial mode to RS232 (0x0) */
+       mode &= ~ATMEL_US_USMODE;
+
+       atmel_port->rs485 = *rs485conf;
+
+       if (rs485conf->flags & SER_RS485_ENABLED) {
+               dev_dbg(port->dev, "Setting UART to RS485\n");
+               atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
+               UART_PUT_TTGR(port, rs485conf->delay_rts_before_send);
+               mode |= ATMEL_US_USMODE_RS485;
+       } else {
+               dev_dbg(port->dev, "Setting UART to RS232\n");
+               if (atmel_use_dma_tx(port))
+                       atmel_port->tx_done_mask = ATMEL_US_ENDTX |
+                               ATMEL_US_TXBUFE;
+               else
+                       atmel_port->tx_done_mask = ATMEL_US_TXRDY;
+       }
+       UART_PUT_MR(port, mode);
+
+       /* Enable interrupts */
+       UART_PUT_IER(port, atmel_port->tx_done_mask);
+
+       spin_unlock(&port->lock);
+
+}
+
 /*
  * Return TIOCSER_TEMT when transmitter FIFO and Shift register is empty.
  */
@@ -202,6 +250,7 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
 {
        unsigned int control = 0;
        unsigned int mode;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
 #ifdef CONFIG_ARCH_AT91RM9200
        if (cpu_is_at91rm9200()) {
@@ -236,6 +285,17 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
                mode |= ATMEL_US_CHMODE_LOC_LOOP;
        else
                mode |= ATMEL_US_CHMODE_NORMAL;
+
+       /* Resetting serial mode to RS232 (0x0) */
+       mode &= ~ATMEL_US_USMODE;
+
+       if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
+               dev_dbg(port->dev, "Setting UART to RS485\n");
+               UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send);
+               mode |= ATMEL_US_USMODE_RS485;
+       } else {
+               dev_dbg(port->dev, "Setting UART to RS232\n");
+       }
        UART_PUT_MR(port, mode);
 }
 
@@ -268,12 +328,17 @@ static u_int atmel_get_mctrl(struct uart_port *port)
  */
 static void atmel_stop_tx(struct uart_port *port)
 {
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
        if (atmel_use_dma_tx(port)) {
                /* disable PDC transmit */
                UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
-               UART_PUT_IDR(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
-       } else
-               UART_PUT_IDR(port, ATMEL_US_TXRDY);
+       }
+       /* Disable interrupts */
+       UART_PUT_IDR(port, atmel_port->tx_done_mask);
+
+       if (atmel_port->rs485.flags & SER_RS485_ENABLED)
+               atmel_start_rx(port);
 }
 
 /*
@@ -281,17 +346,39 @@ static void atmel_stop_tx(struct uart_port *port)
  */
 static void atmel_start_tx(struct uart_port *port)
 {
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
        if (atmel_use_dma_tx(port)) {
                if (UART_GET_PTSR(port) & ATMEL_PDC_TXTEN)
                        /* The transmitter is already running.  Yes, we
                           really need this.*/
                        return;
 
-               UART_PUT_IER(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+               if (atmel_port->rs485.flags & SER_RS485_ENABLED)
+                       atmel_stop_rx(port);
+
                /* re-enable PDC transmit */
                UART_PUT_PTCR(port, ATMEL_PDC_TXTEN);
-       } else
-               UART_PUT_IER(port, ATMEL_US_TXRDY);
+       }
+       /* Enable interrupts */
+       UART_PUT_IER(port, atmel_port->tx_done_mask);
+}
+
+/*
+ * start receiving - port is in process of being opened.
+ */
+static void atmel_start_rx(struct uart_port *port)
+{
+       UART_PUT_CR(port, ATMEL_US_RSTSTA);  /* reset status and receiver */
+
+       if (atmel_use_dma_rx(port)) {
+               /* enable PDC controller */
+               UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT |
+                       port->read_status_mask);
+               UART_PUT_PTCR(port, ATMEL_PDC_RXTEN);
+       } else {
+               UART_PUT_IER(port, ATMEL_US_RXRDY);
+       }
 }
 
 /*
@@ -302,9 +389,11 @@ static void atmel_stop_rx(struct uart_port *port)
        if (atmel_use_dma_rx(port)) {
                /* disable PDC receive */
                UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS);
-               UART_PUT_IDR(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT);
-       } else
+               UART_PUT_IDR(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT |
+                       port->read_status_mask);
+       } else {
                UART_PUT_IDR(port, ATMEL_US_RXRDY);
+       }
 }
 
 /*
@@ -428,8 +517,9 @@ static void atmel_rx_chars(struct uart_port *port)
 static void atmel_tx_chars(struct uart_port *port)
 {
        struct circ_buf *xmit = &port->state->xmit;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
-       if (port->x_char && UART_GET_CSR(port) & ATMEL_US_TXRDY) {
+       if (port->x_char && UART_GET_CSR(port) & atmel_port->tx_done_mask) {
                UART_PUT_CHAR(port, port->x_char);
                port->icount.tx++;
                port->x_char = 0;
@@ -437,7 +527,7 @@ static void atmel_tx_chars(struct uart_port *port)
        if (uart_circ_empty(xmit) || uart_tx_stopped(port))
                return;
 
-       while (UART_GET_CSR(port) & ATMEL_US_TXRDY) {
+       while (UART_GET_CSR(port) & atmel_port->tx_done_mask) {
                UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
                xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
                port->icount.tx++;
@@ -449,7 +539,8 @@ static void atmel_tx_chars(struct uart_port *port)
                uart_write_wakeup(port);
 
        if (!uart_circ_empty(xmit))
-               UART_PUT_IER(port, ATMEL_US_TXRDY);
+               /* Enable interrupts */
+               UART_PUT_IER(port, atmel_port->tx_done_mask);
 }
 
 /*
@@ -501,18 +592,10 @@ atmel_handle_transmit(struct uart_port *port, unsigned int pending)
 {
        struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
-       if (atmel_use_dma_tx(port)) {
-               /* PDC transmit */
-               if (pending & (ATMEL_US_ENDTX | ATMEL_US_TXBUFE)) {
-                       UART_PUT_IDR(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
-                       tasklet_schedule(&atmel_port->tasklet);
-               }
-       } else {
-               /* Interrupt transmit */
-               if (pending & ATMEL_US_TXRDY) {
-                       UART_PUT_IDR(port, ATMEL_US_TXRDY);
-                       tasklet_schedule(&atmel_port->tasklet);
-               }
+       if (pending & atmel_port->tx_done_mask) {
+               /* Either PDC or interrupt transmission */
+               UART_PUT_IDR(port, atmel_port->tx_done_mask);
+               tasklet_schedule(&atmel_port->tasklet);
        }
 }
 
@@ -590,9 +673,15 @@ static void atmel_tx_dma(struct uart_port *port)
 
                UART_PUT_TPR(port, pdc->dma_addr + xmit->tail);
                UART_PUT_TCR(port, count);
-               /* re-enable PDC transmit and interrupts */
+               /* re-enable PDC transmit */
                UART_PUT_PTCR(port, ATMEL_PDC_TXTEN);
-               UART_PUT_IER(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+               /* Enable interrupts */
+               UART_PUT_IER(port, atmel_port->tx_done_mask);
+       } else {
+               if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
+                       /* DMA done, stop TX, start RX for RS485 */
+                       atmel_start_rx(port);
+               }
        }
 
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
@@ -1017,6 +1106,7 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
 {
        unsigned long flags;
        unsigned int mode, imr, quot, baud;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        /* Get current mode register */
        mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL
@@ -1115,6 +1205,17 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
        /* disable receiver and transmitter */
        UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS);
 
+       /* Resetting serial mode to RS232 (0x0) */
+       mode &= ~ATMEL_US_USMODE;
+
+       if (atmel_port->rs485.flags & SER_RS485_ENABLED) {
+               dev_dbg(port->dev, "Setting UART to RS485\n");
+               UART_PUT_TTGR(port, atmel_port->rs485.delay_rts_before_send);
+               mode |= ATMEL_US_USMODE_RS485;
+       } else {
+               dev_dbg(port->dev, "Setting UART to RS232\n");
+       }
+
        /* set the parity, stop bits and data size */
        UART_PUT_MR(port, mode);
 
@@ -1231,6 +1332,35 @@ static void atmel_poll_put_char(struct uart_port *port, unsigned char ch)
 }
 #endif
 
+static int
+atmel_ioctl(struct uart_port *port, unsigned int cmd, unsigned long arg)
+{
+       struct serial_rs485 rs485conf;
+
+       switch (cmd) {
+       case TIOCSRS485:
+               if (copy_from_user(&rs485conf, (struct serial_rs485 *) arg,
+                                       sizeof(rs485conf)))
+                       return -EFAULT;
+
+               atmel_config_rs485(port, &rs485conf);
+               break;
+
+       case TIOCGRS485:
+               if (copy_to_user((struct serial_rs485 *) arg,
+                                       &(to_atmel_uart_port(port)->rs485),
+                                       sizeof(rs485conf)))
+                       return -EFAULT;
+               break;
+
+       default:
+               return -ENOIOCTLCMD;
+       }
+       return 0;
+}
+
+
+
 static struct uart_ops atmel_pops = {
        .tx_empty       = atmel_tx_empty,
        .set_mctrl      = atmel_set_mctrl,
@@ -1250,6 +1380,7 @@ static struct uart_ops atmel_pops = {
        .config_port    = atmel_config_port,
        .verify_port    = atmel_verify_port,
        .pm             = atmel_serial_pm,
+       .ioctl          = atmel_ioctl,
 #ifdef CONFIG_CONSOLE_POLL
        .poll_get_char  = atmel_poll_get_char,
        .poll_put_char  = atmel_poll_put_char,
@@ -1265,13 +1396,12 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
        struct uart_port *port = &atmel_port->uart;
        struct atmel_uart_data *data = pdev->dev.platform_data;
 
-       port->iotype    = UPIO_MEM;
-       port->flags     = UPF_BOOT_AUTOCONF;
-       port->ops       = &atmel_pops;
-       port->fifosize  = 1;
-       port->line      = pdev->id;
-       port->dev       = &pdev->dev;
-
+       port->iotype            = UPIO_MEM;
+       port->flags             = UPF_BOOT_AUTOCONF;
+       port->ops               = &atmel_pops;
+       port->fifosize          = 1;
+       port->line              = pdev->id;
+       port->dev               = &pdev->dev;
        port->mapbase   = pdev->resource[0].start;
        port->irq       = pdev->resource[1].start;
 
@@ -1299,8 +1429,16 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
 
        atmel_port->use_dma_rx = data->use_dma_rx;
        atmel_port->use_dma_tx = data->use_dma_tx;
-       if (atmel_use_dma_tx(port))
+       atmel_port->rs485       = data->rs485;
+       /* Use TXEMPTY for interrupt when rs485 else TXRDY or ENDTX|TXBUFE */
+       if (atmel_port->rs485.flags & SER_RS485_ENABLED)
+               atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
+       else if (atmel_use_dma_tx(port)) {
                port->fifosize = PDC_BUFFER_SIZE;
+               atmel_port->tx_done_mask = ATMEL_US_ENDTX | ATMEL_US_TXBUFE;
+       } else {
+               atmel_port->tx_done_mask = ATMEL_US_TXRDY;
+       }
 }
 
 /*
@@ -1334,6 +1472,7 @@ static void atmel_console_putchar(struct uart_port *port, int ch)
 static void atmel_console_write(struct console *co, const char *s, u_int count)
 {
        struct uart_port *port = &atmel_ports[co->index].uart;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        unsigned int status, imr;
        unsigned int pdc_tx;
 
@@ -1341,7 +1480,7 @@ static void atmel_console_write(struct console *co, const char *s, u_int count)
         * First, save IMR and then disable interrupts
         */
        imr = UART_GET_IMR(port);
-       UART_PUT_IDR(port, ATMEL_US_RXRDY | ATMEL_US_TXRDY);
+       UART_PUT_IDR(port, ATMEL_US_RXRDY | atmel_port->tx_done_mask);
 
        /* Store PDC transmit status and disable it */
        pdc_tx = UART_GET_PTSR(port) & ATMEL_PDC_TXTEN;
index 8cfa5b1..dadd686 100644 (file)
@@ -89,7 +89,6 @@ struct serial_info {
        int                     manfid;
        int                     prodid;
        int                     c950ctrl;
-       dev_node_t              node[4];
        int                     line[4];
        const struct serial_quirk *quirk;
 };
@@ -289,8 +288,6 @@ static void serial_remove(struct pcmcia_device *link)
        for (i = 0; i < info->ndev; i++)
                serial8250_unregister_port(info->line[i]);
 
-       info->p_dev->dev_node = NULL;
-
        if (!info->slave)
                pcmcia_disable_device(link);
 }
@@ -343,7 +340,6 @@ static int serial_probe(struct pcmcia_device *link)
 
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
        link->io.NumPorts1 = 8;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        if (do_sound) {
                link->conf.Attributes |= CONF_ENABLE_SPKR;
@@ -411,11 +407,6 @@ static int setup_serial(struct pcmcia_device *handle, struct serial_info * info,
        }
 
        info->line[info->ndev] = line;
-       sprintf(info->node[info->ndev].dev_name, "ttyS%d", line);
-       info->node[info->ndev].major = TTY_MAJOR;
-       info->node[info->ndev].minor = 0x40 + line;
-       if (info->ndev > 0)
-               info->node[info->ndev - 1].next = &info->node[info->ndev];
        info->ndev++;
 
        return 0;
@@ -486,7 +477,7 @@ static int simple_config(struct pcmcia_device *link)
                }
                if (info->slave) {
                        return setup_serial(link, info, port,
-                                           link->irq.AssignedIRQ);
+                                           link->irq);
                }
        }
 
@@ -507,10 +498,6 @@ static int simple_config(struct pcmcia_device *link)
        return -1;
 
 found_port:
-       i = pcmcia_request_irq(link, &link->irq);
-       if (i != 0)
-               link->irq.AssignedIRQ = 0;
-
        if (info->multi && (info->manfid == MANFID_3COM))
                link->conf.ConfigIndex &= ~(0x08);
 
@@ -523,7 +510,7 @@ found_port:
        i = pcmcia_request_configuration(link, &link->conf);
        if (i != 0)
                return -1;
-       return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
+       return setup_serial(link, info, link->io.BasePort1, link->irq);
 }
 
 static int multi_config_check(struct pcmcia_device *p_dev,
@@ -586,13 +573,9 @@ static int multi_config(struct pcmcia_device *link)
                }
        }
 
-       i = pcmcia_request_irq(link, &link->irq);
-       if (i != 0) {
-               /* FIXME: comment does not fit, error handling does not fit */
-               printk(KERN_NOTICE
-                      "serial_cs: no usable port range found, giving up\n");
-               link->irq.AssignedIRQ = 0;
-       }
+       if (!link->irq)
+               dev_warn(&link->dev,
+                       "serial_cs: no usable IRQ found, continuing...\n");
 
        /*
         * Apply any configuration quirks.
@@ -615,11 +598,11 @@ static int multi_config(struct pcmcia_device *link)
                if (link->conf.ConfigIndex == 1 ||
                    link->conf.ConfigIndex == 3) {
                        err = setup_serial(link, info, base2,
-                                       link->irq.AssignedIRQ);
+                                       link->irq);
                        base2 = link->io.BasePort1;
                } else {
                        err = setup_serial(link, info, link->io.BasePort1,
-                                       link->irq.AssignedIRQ);
+                                       link->irq);
                }
                info->c950ctrl = base2;
 
@@ -633,10 +616,10 @@ static int multi_config(struct pcmcia_device *link)
                return 0;
        }
 
-       setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
+       setup_serial(link, info, link->io.BasePort1, link->irq);
        for (i = 0; i < info->multi - 1; i++)
                setup_serial(link, info, base2 + (8 * i),
-                               link->irq.AssignedIRQ);
+                               link->irq);
        return 0;
 }
 
@@ -720,7 +703,6 @@ static int serial_config(struct pcmcia_device * link)
                if (info->quirk->post(link))
                        goto failed;
 
-       link->dev_node = &info->node[0];
        return 0;
 
 failed:
index 8eb094c..8d993c4 100644 (file)
@@ -83,16 +83,16 @@ struct sci_port {
 
        /* Interface clock */
        struct clk              *iclk;
-       /* Data clock */
-       struct clk              *dclk;
+       /* Function clock */
+       struct clk              *fclk;
 
        struct list_head        node;
        struct dma_chan                 *chan_tx;
        struct dma_chan                 *chan_rx;
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
        struct device                   *dma_dev;
-       enum sh_dmae_slave_chan_id      slave_tx;
-       enum sh_dmae_slave_chan_id      slave_rx;
+       unsigned int                    slave_tx;
+       unsigned int                    slave_rx;
        struct dma_async_tx_descriptor  *desc_tx;
        struct dma_async_tx_descriptor  *desc_rx[2];
        dma_cookie_t                    cookie_tx;
@@ -107,6 +107,7 @@ struct sci_port {
        struct work_struct              work_tx;
        struct work_struct              work_rx;
        struct timer_list               rx_timer;
+       unsigned int                    rx_timeout;
 #endif
 };
 
@@ -674,22 +675,22 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr)
        struct sci_port *s = to_sci_port(port);
 
        if (s->chan_rx) {
-               unsigned long tout;
                u16 scr = sci_in(port, SCSCR);
                u16 ssr = sci_in(port, SCxSR);
 
                /* Disable future Rx interrupts */
-               sci_out(port, SCSCR, scr & ~SCI_CTRL_FLAGS_RIE);
+               if (port->type == PORT_SCIFA) {
+                       disable_irq_nosync(irq);
+                       scr |= 0x4000;
+               } else {
+                       scr &= ~SCI_CTRL_FLAGS_RIE;
+               }
+               sci_out(port, SCSCR, scr);
                /* Clear current interrupt */
                sci_out(port, SCxSR, ssr & ~(1 | SCxSR_RDxF(port)));
-               /* Calculate delay for 1.5 DMA buffers */
-               tout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 /
-                       port->fifosize / 2;
-               dev_dbg(port->dev, "Rx IRQ: setup timeout in %lu ms\n",
-                       tout * 1000 / HZ);
-               if (tout < 2)
-                       tout = 2;
-               mod_timer(&s->rx_timer, jiffies + tout);
+               dev_dbg(port->dev, "Rx IRQ %lu: setup t-out in %u jiffies\n",
+                       jiffies, s->rx_timeout);
+               mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
 
                return IRQ_HANDLED;
        }
@@ -799,7 +800,7 @@ static int sci_notifier(struct notifier_block *self,
            (phase == CPUFREQ_RESUMECHANGE)) {
                spin_lock_irqsave(&priv->lock, flags);
                list_for_each_entry(sci_port, &priv->ports, node)
-                       sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
+                       sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
                spin_unlock_irqrestore(&priv->lock, flags);
        }
 
@@ -810,21 +811,17 @@ static void sci_clk_enable(struct uart_port *port)
 {
        struct sci_port *sci_port = to_sci_port(port);
 
-       clk_enable(sci_port->dclk);
-       sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
-
-       if (sci_port->iclk)
-               clk_enable(sci_port->iclk);
+       clk_enable(sci_port->iclk);
+       sci_port->port.uartclk = clk_get_rate(sci_port->iclk);
+       clk_enable(sci_port->fclk);
 }
 
 static void sci_clk_disable(struct uart_port *port)
 {
        struct sci_port *sci_port = to_sci_port(port);
 
-       if (sci_port->iclk)
-               clk_disable(sci_port->iclk);
-
-       clk_disable(sci_port->dclk);
+       clk_disable(sci_port->fclk);
+       clk_disable(sci_port->iclk);
 }
 
 static int sci_request_irq(struct sci_port *port)
@@ -913,22 +910,26 @@ static void sci_dma_tx_complete(void *arg)
 
        spin_lock_irqsave(&port->lock, flags);
 
-       xmit->tail += s->sg_tx.length;
+       xmit->tail += sg_dma_len(&s->sg_tx);
        xmit->tail &= UART_XMIT_SIZE - 1;
 
-       port->icount.tx += s->sg_tx.length;
+       port->icount.tx += sg_dma_len(&s->sg_tx);
 
        async_tx_ack(s->desc_tx);
        s->cookie_tx = -EINVAL;
        s->desc_tx = NULL;
 
-       spin_unlock_irqrestore(&port->lock, flags);
-
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
                uart_write_wakeup(port);
 
-       if (uart_circ_chars_pending(xmit))
+       if (!uart_circ_empty(xmit)) {
                schedule_work(&s->work_tx);
+       } else if (port->type == PORT_SCIFA) {
+               u16 ctrl = sci_in(port, SCSCR);
+               sci_out(port, SCSCR, ctrl & ~SCI_CTRL_FLAGS_TIE);
+       }
+
+       spin_unlock_irqrestore(&port->lock, flags);
 }
 
 /* Locking: called with port lock held */
@@ -972,13 +973,13 @@ static void sci_dma_rx_complete(void *arg)
        unsigned long flags;
        int count;
 
-       dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
+       dev_dbg(port->dev, "%s(%d) active #%d\n", __func__, port->line, s->active_rx);
 
        spin_lock_irqsave(&port->lock, flags);
 
        count = sci_dma_rx_push(s, tty, s->buf_len_rx);
 
-       mod_timer(&s->rx_timer, jiffies + msecs_to_jiffies(5));
+       mod_timer(&s->rx_timer, jiffies + s->rx_timeout);
 
        spin_unlock_irqrestore(&port->lock, flags);
 
@@ -1050,6 +1051,8 @@ static void sci_submit_rx(struct sci_port *s)
                        sci_rx_dma_release(s, true);
                        return;
                }
+               dev_dbg(s->port.dev, "%s(): cookie %d to #%d\n", __func__,
+                       s->cookie_rx[i], i);
        }
 
        s->active_rx = s->cookie_rx[0];
@@ -1107,10 +1110,10 @@ static void work_fn_rx(struct work_struct *work)
                return;
        }
 
-       dev_dbg(port->dev, "%s: cookie %d #%d\n", __func__,
-               s->cookie_rx[new], new);
-
        s->active_rx = s->cookie_rx[!new];
+
+       dev_dbg(port->dev, "%s: cookie %d #%d, new active #%d\n", __func__,
+               s->cookie_rx[new], new, s->active_rx);
 }
 
 static void work_fn_tx(struct work_struct *work)
@@ -1131,14 +1134,13 @@ static void work_fn_tx(struct work_struct *work)
         */
        spin_lock_irq(&port->lock);
        sg->offset = xmit->tail & (UART_XMIT_SIZE - 1);
-       sg->dma_address = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) +
+       sg_dma_address(sg) = (sg_dma_address(sg) & ~(UART_XMIT_SIZE - 1)) +
                sg->offset;
-       sg->length = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
+       sg_dma_len(sg) = min((int)CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE),
                CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE));
-       sg->dma_length = sg->length;
        spin_unlock_irq(&port->lock);
 
-       BUG_ON(!sg->length);
+       BUG_ON(!sg_dma_len(sg));
 
        desc = chan->device->device_prep_slave_sg(chan,
                        sg, s->sg_len_tx, DMA_TO_DEVICE,
@@ -1173,23 +1175,28 @@ static void work_fn_tx(struct work_struct *work)
 
 static void sci_start_tx(struct uart_port *port)
 {
+       struct sci_port *s = to_sci_port(port);
        unsigned short ctrl;
 
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
-       struct sci_port *s = to_sci_port(port);
-
-       if (s->chan_tx) {
-               if (!uart_circ_empty(&s->port.state->xmit) && s->cookie_tx < 0)
-                       schedule_work(&s->work_tx);
-
-               return;
+       if (port->type == PORT_SCIFA) {
+               u16 new, scr = sci_in(port, SCSCR);
+               if (s->chan_tx)
+                       new = scr | 0x8000;
+               else
+                       new = scr & ~0x8000;
+               if (new != scr)
+                       sci_out(port, SCSCR, new);
        }
+       if (s->chan_tx && !uart_circ_empty(&s->port.state->xmit) &&
+           s->cookie_tx < 0)
+               schedule_work(&s->work_tx);
 #endif
-
-       /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
-       ctrl = sci_in(port, SCSCR);
-       ctrl |= SCI_CTRL_FLAGS_TIE;
-       sci_out(port, SCSCR, ctrl);
+       if (!s->chan_tx || port->type == PORT_SCIFA) {
+               /* Set TIE (Transmit Interrupt Enable) bit in SCSCR */
+               ctrl = sci_in(port, SCSCR);
+               sci_out(port, SCSCR, ctrl | SCI_CTRL_FLAGS_TIE);
+       }
 }
 
 static void sci_stop_tx(struct uart_port *port)
@@ -1198,6 +1205,8 @@ static void sci_stop_tx(struct uart_port *port)
 
        /* Clear TIE (Transmit Interrupt Enable) bit in SCSCR */
        ctrl = sci_in(port, SCSCR);
+       if (port->type == PORT_SCIFA)
+               ctrl &= ~0x8000;
        ctrl &= ~SCI_CTRL_FLAGS_TIE;
        sci_out(port, SCSCR, ctrl);
 }
@@ -1208,6 +1217,8 @@ static void sci_start_rx(struct uart_port *port)
 
        /* Set RIE (Receive Interrupt Enable) bit in SCSCR */
        ctrl |= sci_in(port, SCSCR);
+       if (port->type == PORT_SCIFA)
+               ctrl &= ~0x4000;
        sci_out(port, SCSCR, ctrl);
 }
 
@@ -1217,6 +1228,8 @@ static void sci_stop_rx(struct uart_port *port)
 
        /* Clear RIE (Receive Interrupt Enable) bit in SCSCR */
        ctrl = sci_in(port, SCSCR);
+       if (port->type == PORT_SCIFA)
+               ctrl &= ~0x4000;
        ctrl &= ~(SCI_CTRL_FLAGS_RIE | SCI_CTRL_FLAGS_REIE);
        sci_out(port, SCSCR, ctrl);
 }
@@ -1251,8 +1264,12 @@ static void rx_timer_fn(unsigned long arg)
 {
        struct sci_port *s = (struct sci_port *)arg;
        struct uart_port *port = &s->port;
-
        u16 scr = sci_in(port, SCSCR);
+
+       if (port->type == PORT_SCIFA) {
+               scr &= ~0x4000;
+               enable_irq(s->irqs[1]);
+       }
        sci_out(port, SCSCR, scr | SCI_CTRL_FLAGS_RIE);
        dev_dbg(port->dev, "DMA Rx timed out\n");
        schedule_work(&s->work_rx);
@@ -1339,8 +1356,7 @@ static void sci_request_dma(struct uart_port *port)
                        sg_init_table(sg, 1);
                        sg_set_page(sg, virt_to_page(buf[i]), s->buf_len_rx,
                                    (int)buf[i] & ~PAGE_MASK);
-                       sg->dma_address = dma[i];
-                       sg->dma_length = sg->length;
+                       sg_dma_address(sg) = dma[i];
                }
 
                INIT_WORK(&s->work_rx, work_fn_rx);
@@ -1403,8 +1419,12 @@ static void sci_shutdown(struct uart_port *port)
 static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
                            struct ktermios *old)
 {
+#ifdef CONFIG_SERIAL_SH_SCI_DMA
+       struct sci_port *s = to_sci_port(port);
+#endif
        unsigned int status, baud, smr_val, max_baud;
        int t = -1;
+       u16 scfcr = 0;
 
        /*
         * earlyprintk comes here early on with port->uartclk set to zero.
@@ -1427,7 +1447,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
        sci_out(port, SCSCR, 0x00);     /* TE=0, RE=0, CKE1=0 */
 
        if (port->type != PORT_SCI)
-               sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
+               sci_out(port, SCFCR, scfcr | SCFCR_RFRST | SCFCR_TFRST);
 
        smr_val = sci_in(port, SCSMR) & 3;
        if ((termios->c_cflag & CSIZE) == CS7)
@@ -1458,10 +1478,32 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
        }
 
        sci_init_pins(port, termios->c_cflag);
-       sci_out(port, SCFCR, (termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0);
+       sci_out(port, SCFCR, scfcr | ((termios->c_cflag & CRTSCTS) ? SCFCR_MCE : 0));
 
        sci_out(port, SCSCR, SCSCR_INIT(port));
 
+#ifdef CONFIG_SERIAL_SH_SCI_DMA
+       /*
+        * Calculate delay for 1.5 DMA buffers: see
+        * drivers/serial/serial_core.c::uart_update_timeout(). With 10 bits
+        * (CS8), 250Hz, 115200 baud and 64 bytes FIFO, the above function
+        * calculates 1 jiffie for the data plus 5 jiffies for the "slop(e)."
+        * Then below we calculate 3 jiffies (12ms) for 1.5 DMA buffers (3 FIFO
+        * sizes), but it has been found out experimentally, that this is not
+        * enough: the driver too often needlessly runs on a DMA timeout. 20ms
+        * as a minimum seem to work perfectly.
+        */
+       if (s->chan_rx) {
+               s->rx_timeout = (port->timeout - HZ / 50) * s->buf_len_rx * 3 /
+                       port->fifosize / 2;
+               dev_dbg(port->dev,
+                       "DMA Rx t-out %ums, tty t-out %u jiffies\n",
+                       s->rx_timeout * 1000 / HZ, port->timeout);
+               if (s->rx_timeout < msecs_to_jiffies(20))
+                       s->rx_timeout = msecs_to_jiffies(20);
+       }
+#endif
+
        if ((termios->c_cflag & CREAD) != 0)
                sci_start_rx(port);
 }
@@ -1553,10 +1595,10 @@ static struct uart_ops sci_uart_ops = {
 #endif
 };
 
-static void __devinit sci_init_single(struct platform_device *dev,
-                                     struct sci_port *sci_port,
-                                     unsigned int index,
-                                     struct plat_sci_port *p)
+static int __devinit sci_init_single(struct platform_device *dev,
+                                    struct sci_port *sci_port,
+                                    unsigned int index,
+                                    struct plat_sci_port *p)
 {
        struct uart_port *port = &sci_port->port;
 
@@ -1577,8 +1619,23 @@ static void __devinit sci_init_single(struct platform_device *dev,
        }
 
        if (dev) {
-               sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
-               sci_port->dclk = clk_get(&dev->dev, "peripheral_clk");
+               sci_port->iclk = clk_get(&dev->dev, "sci_ick");
+               if (IS_ERR(sci_port->iclk)) {
+                       sci_port->iclk = clk_get(&dev->dev, "peripheral_clk");
+                       if (IS_ERR(sci_port->iclk)) {
+                               dev_err(&dev->dev, "can't get iclk\n");
+                               return PTR_ERR(sci_port->iclk);
+                       }
+               }
+
+               /*
+                * The function clock is optional, ignore it if we can't
+                * find it.
+                */
+               sci_port->fclk = clk_get(&dev->dev, "sci_fck");
+               if (IS_ERR(sci_port->fclk))
+                       sci_port->fclk = NULL;
+
                sci_port->enable = sci_clk_enable;
                sci_port->disable = sci_clk_disable;
                port->dev = &dev->dev;
@@ -1605,6 +1662,7 @@ static void __devinit sci_init_single(struct platform_device *dev,
 #endif
 
        memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
+       return 0;
 }
 
 #ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
@@ -1754,8 +1812,11 @@ static int sci_remove(struct platform_device *dev)
        cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
 
        spin_lock_irqsave(&priv->lock, flags);
-       list_for_each_entry(p, &priv->ports, node)
+       list_for_each_entry(p, &priv->ports, node) {
                uart_remove_one_port(&sci_uart_driver, &p->port);
+               clk_put(p->iclk);
+               clk_put(p->fclk);
+       }
        spin_unlock_irqrestore(&priv->lock, flags);
 
        kfree(priv);
@@ -1781,7 +1842,9 @@ static int __devinit sci_probe_single(struct platform_device *dev,
                return 0;
        }
 
-       sci_init_single(dev, sciport, index, p);
+       ret = sci_init_single(dev, sciport, index, p);
+       if (ret)
+               return ret;
 
        ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
        if (ret)
diff --git a/drivers/sh/Kconfig b/drivers/sh/Kconfig
new file mode 100644 (file)
index 0000000..a54de0b
--- /dev/null
@@ -0,0 +1,24 @@
+config INTC_USERIMASK
+       bool "Userspace interrupt masking support"
+       depends on ARCH_SHMOBILE || (SUPERH && CPU_SH4A)
+       help
+         This enables support for hardware-assisted userspace hardirq
+         masking.
+
+         SH-4A and newer interrupt blocks all support a special shadowed
+         page with all non-masking registers obscured when mapped in to
+         userspace. This is primarily for use by userspace device
+         drivers that are using special priority levels.
+
+         If in doubt, say N.
+
+config INTC_BALANCING
+       bool "Hardware IRQ balancing support"
+       depends on SMP && SUPERH && CPU_SUBTYPE_SH7786
+       help
+         This enables support for IRQ auto-distribution mode on SH-X3
+         SMP parts. All of the balancing and CPU wakeup decisions are
+         taken care of automatically by hardware for distributed
+         vectors.
+
+         If in doubt, say N.
index 4956bf1..78bb512 100644 (file)
@@ -4,4 +4,6 @@
 obj-$(CONFIG_SUPERHYWAY)       += superhyway/
 obj-$(CONFIG_MAPLE)            += maple/
 obj-$(CONFIG_GENERIC_GPIO)     += pfc.o
+obj-$(CONFIG_SUPERH)           += clk.o
+obj-$(CONFIG_SH_CLK_CPG)       += clk-cpg.o
 obj-y                          += intc.o
diff --git a/drivers/sh/clk-cpg.c b/drivers/sh/clk-cpg.c
new file mode 100644 (file)
index 0000000..f5c80ba
--- /dev/null
@@ -0,0 +1,298 @@
+#include <linux/clk.h>
+#include <linux/compiler.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/sh_clk.h>
+
+static int sh_clk_mstp32_enable(struct clk *clk)
+{
+       __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
+                    clk->enable_reg);
+       return 0;
+}
+
+static void sh_clk_mstp32_disable(struct clk *clk)
+{
+       __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
+                    clk->enable_reg);
+}
+
+static struct clk_ops sh_clk_mstp32_clk_ops = {
+       .enable         = sh_clk_mstp32_enable,
+       .disable        = sh_clk_mstp32_disable,
+       .recalc         = followparent_recalc,
+};
+
+int __init sh_clk_mstp32_register(struct clk *clks, int nr)
+{
+       struct clk *clkp;
+       int ret = 0;
+       int k;
+
+       for (k = 0; !ret && (k < nr); k++) {
+               clkp = clks + k;
+               clkp->ops = &sh_clk_mstp32_clk_ops;
+               ret |= clk_register(clkp);
+       }
+
+       return ret;
+}
+
+static long sh_clk_div_round_rate(struct clk *clk, unsigned long rate)
+{
+       return clk_rate_table_round(clk, clk->freq_table, rate);
+}
+
+static int sh_clk_div6_divisors[64] = {
+       1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
+       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
+       33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
+       49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
+};
+
+static struct clk_div_mult_table sh_clk_div6_table = {
+       .divisors = sh_clk_div6_divisors,
+       .nr_divisors = ARRAY_SIZE(sh_clk_div6_divisors),
+};
+
+static unsigned long sh_clk_div6_recalc(struct clk *clk)
+{
+       struct clk_div_mult_table *table = &sh_clk_div6_table;
+       unsigned int idx;
+
+       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
+                            table, NULL);
+
+       idx = __raw_readl(clk->enable_reg) & 0x003f;
+
+       return clk->freq_table[idx].frequency;
+}
+
+static int sh_clk_div6_set_rate(struct clk *clk,
+                               unsigned long rate, int algo_id)
+{
+       unsigned long value;
+       int idx;
+
+       idx = clk_rate_table_find(clk, clk->freq_table, rate);
+       if (idx < 0)
+               return idx;
+
+       value = __raw_readl(clk->enable_reg);
+       value &= ~0x3f;
+       value |= idx;
+       __raw_writel(value, clk->enable_reg);
+       return 0;
+}
+
+static int sh_clk_div6_enable(struct clk *clk)
+{
+       unsigned long value;
+       int ret;
+
+       ret = sh_clk_div6_set_rate(clk, clk->rate, 0);
+       if (ret == 0) {
+               value = __raw_readl(clk->enable_reg);
+               value &= ~0x100; /* clear stop bit to enable clock */
+               __raw_writel(value, clk->enable_reg);
+       }
+       return ret;
+}
+
+static void sh_clk_div6_disable(struct clk *clk)
+{
+       unsigned long value;
+
+       value = __raw_readl(clk->enable_reg);
+       value |= 0x100; /* stop clock */
+       value |= 0x3f; /* VDIV bits must be non-zero, overwrite divider */
+       __raw_writel(value, clk->enable_reg);
+}
+
+static struct clk_ops sh_clk_div6_clk_ops = {
+       .recalc         = sh_clk_div6_recalc,
+       .round_rate     = sh_clk_div_round_rate,
+       .set_rate       = sh_clk_div6_set_rate,
+       .enable         = sh_clk_div6_enable,
+       .disable        = sh_clk_div6_disable,
+};
+
+int __init sh_clk_div6_register(struct clk *clks, int nr)
+{
+       struct clk *clkp;
+       void *freq_table;
+       int nr_divs = sh_clk_div6_table.nr_divisors;
+       int freq_table_size = sizeof(struct cpufreq_frequency_table);
+       int ret = 0;
+       int k;
+
+       freq_table_size *= (nr_divs + 1);
+       freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
+       if (!freq_table) {
+               pr_err("sh_clk_div6_register: unable to alloc memory\n");
+               return -ENOMEM;
+       }
+
+       for (k = 0; !ret && (k < nr); k++) {
+               clkp = clks + k;
+
+               clkp->ops = &sh_clk_div6_clk_ops;
+               clkp->id = -1;
+               clkp->freq_table = freq_table + (k * freq_table_size);
+               clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
+
+               ret = clk_register(clkp);
+       }
+
+       return ret;
+}
+
+static unsigned long sh_clk_div4_recalc(struct clk *clk)
+{
+       struct clk_div4_table *d4t = clk->priv;
+       struct clk_div_mult_table *table = d4t->div_mult_table;
+       unsigned int idx;
+
+       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
+                            table, &clk->arch_flags);
+
+       idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
+
+       return clk->freq_table[idx].frequency;
+}
+
+static int sh_clk_div4_set_parent(struct clk *clk, struct clk *parent)
+{
+       struct clk_div4_table *d4t = clk->priv;
+       struct clk_div_mult_table *table = d4t->div_mult_table;
+       u32 value;
+       int ret;
+
+       /* we really need a better way to determine parent index, but for
+        * now assume internal parent comes with CLK_ENABLE_ON_INIT set,
+        * no CLK_ENABLE_ON_INIT means external clock...
+        */
+
+       if (parent->flags & CLK_ENABLE_ON_INIT)
+               value = __raw_readl(clk->enable_reg) & ~(1 << 7);
+       else
+               value = __raw_readl(clk->enable_reg) | (1 << 7);
+
+       ret = clk_reparent(clk, parent);
+       if (ret < 0)
+               return ret;
+
+       __raw_writel(value, clk->enable_reg);
+
+       /* Rebiuld the frequency table */
+       clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
+                            table, &clk->arch_flags);
+
+       return 0;
+}
+
+static int sh_clk_div4_set_rate(struct clk *clk, unsigned long rate, int algo_id)
+{
+       struct clk_div4_table *d4t = clk->priv;
+       unsigned long value;
+       int idx = clk_rate_table_find(clk, clk->freq_table, rate);
+       if (idx < 0)
+               return idx;
+
+       value = __raw_readl(clk->enable_reg);
+       value &= ~(0xf << clk->enable_bit);
+       value |= (idx << clk->enable_bit);
+       __raw_writel(value, clk->enable_reg);
+
+       if (d4t->kick)
+               d4t->kick(clk);
+
+       return 0;
+}
+
+static int sh_clk_div4_enable(struct clk *clk)
+{
+       __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << 8), clk->enable_reg);
+       return 0;
+}
+
+static void sh_clk_div4_disable(struct clk *clk)
+{
+       __raw_writel(__raw_readl(clk->enable_reg) | (1 << 8), clk->enable_reg);
+}
+
+static struct clk_ops sh_clk_div4_clk_ops = {
+       .recalc         = sh_clk_div4_recalc,
+       .set_rate       = sh_clk_div4_set_rate,
+       .round_rate     = sh_clk_div_round_rate,
+};
+
+static struct clk_ops sh_clk_div4_enable_clk_ops = {
+       .recalc         = sh_clk_div4_recalc,
+       .set_rate       = sh_clk_div4_set_rate,
+       .round_rate     = sh_clk_div_round_rate,
+       .enable         = sh_clk_div4_enable,
+       .disable        = sh_clk_div4_disable,
+};
+
+static struct clk_ops sh_clk_div4_reparent_clk_ops = {
+       .recalc         = sh_clk_div4_recalc,
+       .set_rate       = sh_clk_div4_set_rate,
+       .round_rate     = sh_clk_div_round_rate,
+       .enable         = sh_clk_div4_enable,
+       .disable        = sh_clk_div4_disable,
+       .set_parent     = sh_clk_div4_set_parent,
+};
+
+static int __init sh_clk_div4_register_ops(struct clk *clks, int nr,
+                       struct clk_div4_table *table, struct clk_ops *ops)
+{
+       struct clk *clkp;
+       void *freq_table;
+       int nr_divs = table->div_mult_table->nr_divisors;
+       int freq_table_size = sizeof(struct cpufreq_frequency_table);
+       int ret = 0;
+       int k;
+
+       freq_table_size *= (nr_divs + 1);
+       freq_table = kzalloc(freq_table_size * nr, GFP_KERNEL);
+       if (!freq_table) {
+               pr_err("sh_clk_div4_register: unable to alloc memory\n");
+               return -ENOMEM;
+       }
+
+       for (k = 0; !ret && (k < nr); k++) {
+               clkp = clks + k;
+
+               clkp->ops = ops;
+               clkp->id = -1;
+               clkp->priv = table;
+
+               clkp->freq_table = freq_table + (k * freq_table_size);
+               clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
+
+               ret = clk_register(clkp);
+       }
+
+       return ret;
+}
+
+int __init sh_clk_div4_register(struct clk *clks, int nr,
+                               struct clk_div4_table *table)
+{
+       return sh_clk_div4_register_ops(clks, nr, table, &sh_clk_div4_clk_ops);
+}
+
+int __init sh_clk_div4_enable_register(struct clk *clks, int nr,
+                               struct clk_div4_table *table)
+{
+       return sh_clk_div4_register_ops(clks, nr, table,
+                                       &sh_clk_div4_enable_clk_ops);
+}
+
+int __init sh_clk_div4_reparent_register(struct clk *clks, int nr,
+                               struct clk_div4_table *table)
+{
+       return sh_clk_div4_register_ops(clks, nr, table,
+                                       &sh_clk_div4_reparent_clk_ops);
+}
diff --git a/drivers/sh/clk.c b/drivers/sh/clk.c
new file mode 100644 (file)
index 0000000..5d84ada
--- /dev/null
@@ -0,0 +1,545 @@
+/*
+ * drivers/sh/clk.c - SuperH clock framework
+ *
+ *  Copyright (C) 2005 - 2009  Paul Mundt
+ *
+ * This clock framework is derived from the OMAP version by:
+ *
+ *     Copyright (C) 2004 - 2008 Nokia Corporation
+ *     Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
+ *
+ *  Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/kobject.h>
+#include <linux/sysdev.h>
+#include <linux/seq_file.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/debugfs.h>
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/sh_clk.h>
+
+static LIST_HEAD(clock_list);
+static DEFINE_SPINLOCK(clock_lock);
+static DEFINE_MUTEX(clock_list_sem);
+
+void clk_rate_table_build(struct clk *clk,
+                         struct cpufreq_frequency_table *freq_table,
+                         int nr_freqs,
+                         struct clk_div_mult_table *src_table,
+                         unsigned long *bitmap)
+{
+       unsigned long mult, div;
+       unsigned long freq;
+       int i;
+
+       for (i = 0; i < nr_freqs; i++) {
+               div = 1;
+               mult = 1;
+
+               if (src_table->divisors && i < src_table->nr_divisors)
+                       div = src_table->divisors[i];
+
+               if (src_table->multipliers && i < src_table->nr_multipliers)
+                       mult = src_table->multipliers[i];
+
+               if (!div || !mult || (bitmap && !test_bit(i, bitmap)))
+                       freq = CPUFREQ_ENTRY_INVALID;
+               else
+                       freq = clk->parent->rate * mult / div;
+
+               freq_table[i].index = i;
+               freq_table[i].frequency = freq;
+       }
+
+       /* Termination entry */
+       freq_table[i].index = i;
+       freq_table[i].frequency = CPUFREQ_TABLE_END;
+}
+
+long clk_rate_table_round(struct clk *clk,
+                         struct cpufreq_frequency_table *freq_table,
+                         unsigned long rate)
+{
+       unsigned long rate_error, rate_error_prev = ~0UL;
+       unsigned long rate_best_fit = rate;
+       unsigned long highest, lowest;
+       int i;
+
+       highest = lowest = 0;
+
+       for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
+               unsigned long freq = freq_table[i].frequency;
+
+               if (freq == CPUFREQ_ENTRY_INVALID)
+                       continue;
+
+               if (freq > highest)
+                       highest = freq;
+               if (freq < lowest)
+                       lowest = freq;
+
+               rate_error = abs(freq - rate);
+               if (rate_error < rate_error_prev) {
+                       rate_best_fit = freq;
+                       rate_error_prev = rate_error;
+               }
+
+               if (rate_error == 0)
+                       break;
+       }
+
+       if (rate >= highest)
+               rate_best_fit = highest;
+       if (rate <= lowest)
+               rate_best_fit = lowest;
+
+       return rate_best_fit;
+}
+
+int clk_rate_table_find(struct clk *clk,
+                       struct cpufreq_frequency_table *freq_table,
+                       unsigned long rate)
+{
+       int i;
+
+       for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
+               unsigned long freq = freq_table[i].frequency;
+
+               if (freq == CPUFREQ_ENTRY_INVALID)
+                       continue;
+
+               if (freq == rate)
+                       return i;
+       }
+
+       return -ENOENT;
+}
+
+/* Used for clocks that always have same value as the parent clock */
+unsigned long followparent_recalc(struct clk *clk)
+{
+       return clk->parent ? clk->parent->rate : 0;
+}
+
+int clk_reparent(struct clk *child, struct clk *parent)
+{
+       list_del_init(&child->sibling);
+       if (parent)
+               list_add(&child->sibling, &parent->children);
+       child->parent = parent;
+
+       /* now do the debugfs renaming to reattach the child
+          to the proper parent */
+
+       return 0;
+}
+
+/* Propagate rate to children */
+void propagate_rate(struct clk *tclk)
+{
+       struct clk *clkp;
+
+       list_for_each_entry(clkp, &tclk->children, sibling) {
+               if (clkp->ops && clkp->ops->recalc)
+                       clkp->rate = clkp->ops->recalc(clkp);
+
+               propagate_rate(clkp);
+       }
+}
+
+static void __clk_disable(struct clk *clk)
+{
+       if (WARN(!clk->usecount, "Trying to disable clock %s with 0 usecount\n",
+                clk->name))
+               return;
+
+       if (!(--clk->usecount)) {
+               if (likely(clk->ops && clk->ops->disable))
+                       clk->ops->disable(clk);
+               if (likely(clk->parent))
+                       __clk_disable(clk->parent);
+       }
+}
+
+void clk_disable(struct clk *clk)
+{
+       unsigned long flags;
+
+       if (!clk)
+               return;
+
+       spin_lock_irqsave(&clock_lock, flags);
+       __clk_disable(clk);
+       spin_unlock_irqrestore(&clock_lock, flags);
+}
+EXPORT_SYMBOL_GPL(clk_disable);
+
+static int __clk_enable(struct clk *clk)
+{
+       int ret = 0;
+
+       if (clk->usecount++ == 0) {
+               if (clk->parent) {
+                       ret = __clk_enable(clk->parent);
+                       if (unlikely(ret))
+                               goto err;
+               }
+
+               if (clk->ops && clk->ops->enable) {
+                       ret = clk->ops->enable(clk);
+                       if (ret) {
+                               if (clk->parent)
+                                       __clk_disable(clk->parent);
+                               goto err;
+                       }
+               }
+       }
+
+       return ret;
+err:
+       clk->usecount--;
+       return ret;
+}
+
+int clk_enable(struct clk *clk)
+{
+       unsigned long flags;
+       int ret;
+
+       if (!clk)
+               return -EINVAL;
+
+       spin_lock_irqsave(&clock_lock, flags);
+       ret = __clk_enable(clk);
+       spin_unlock_irqrestore(&clock_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(clk_enable);
+
+static LIST_HEAD(root_clks);
+
+/**
+ * recalculate_root_clocks - recalculate and propagate all root clocks
+ *
+ * Recalculates all root clocks (clocks with no parent), which if the
+ * clock's .recalc is set correctly, should also propagate their rates.
+ * Called at init.
+ */
+void recalculate_root_clocks(void)
+{
+       struct clk *clkp;
+
+       list_for_each_entry(clkp, &root_clks, sibling) {
+               if (clkp->ops && clkp->ops->recalc)
+                       clkp->rate = clkp->ops->recalc(clkp);
+               propagate_rate(clkp);
+       }
+}
+
+int clk_register(struct clk *clk)
+{
+       if (clk == NULL || IS_ERR(clk))
+               return -EINVAL;
+
+       /*
+        * trap out already registered clocks
+        */
+       if (clk->node.next || clk->node.prev)
+               return 0;
+
+       mutex_lock(&clock_list_sem);
+
+       INIT_LIST_HEAD(&clk->children);
+       clk->usecount = 0;
+
+       if (clk->parent)
+               list_add(&clk->sibling, &clk->parent->children);
+       else
+               list_add(&clk->sibling, &root_clks);
+
+       list_add(&clk->node, &clock_list);
+       if (clk->ops && clk->ops->init)
+               clk->ops->init(clk);
+       mutex_unlock(&clock_list_sem);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(clk_register);
+
+void clk_unregister(struct clk *clk)
+{
+       mutex_lock(&clock_list_sem);
+       list_del(&clk->sibling);
+       list_del(&clk->node);
+       mutex_unlock(&clock_list_sem);
+}
+EXPORT_SYMBOL_GPL(clk_unregister);
+
+void clk_enable_init_clocks(void)
+{
+       struct clk *clkp;
+
+       list_for_each_entry(clkp, &clock_list, node)
+               if (clkp->flags & CLK_ENABLE_ON_INIT)
+                       clk_enable(clkp);
+}
+
+unsigned long clk_get_rate(struct clk *clk)
+{
+       return clk->rate;
+}
+EXPORT_SYMBOL_GPL(clk_get_rate);
+
+int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       return clk_set_rate_ex(clk, rate, 0);
+}
+EXPORT_SYMBOL_GPL(clk_set_rate);
+
+int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)
+{
+       int ret = -EOPNOTSUPP;
+       unsigned long flags;
+
+       spin_lock_irqsave(&clock_lock, flags);
+
+       if (likely(clk->ops && clk->ops->set_rate)) {
+               ret = clk->ops->set_rate(clk, rate, algo_id);
+               if (ret != 0)
+                       goto out_unlock;
+       } else {
+               clk->rate = rate;
+               ret = 0;
+       }
+
+       if (clk->ops && clk->ops->recalc)
+               clk->rate = clk->ops->recalc(clk);
+
+       propagate_rate(clk);
+
+out_unlock:
+       spin_unlock_irqrestore(&clock_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(clk_set_rate_ex);
+
+int clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       unsigned long flags;
+       int ret = -EINVAL;
+
+       if (!parent || !clk)
+               return ret;
+       if (clk->parent == parent)
+               return 0;
+
+       spin_lock_irqsave(&clock_lock, flags);
+       if (clk->usecount == 0) {
+               if (clk->ops->set_parent)
+                       ret = clk->ops->set_parent(clk, parent);
+               else
+                       ret = clk_reparent(clk, parent);
+
+               if (ret == 0) {
+                       pr_debug("clock: set parent of %s to %s (new rate %ld)\n",
+                                clk->name, clk->parent->name, clk->rate);
+                       if (clk->ops->recalc)
+                               clk->rate = clk->ops->recalc(clk);
+                       propagate_rate(clk);
+               }
+       } else
+               ret = -EBUSY;
+       spin_unlock_irqrestore(&clock_lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(clk_set_parent);
+
+struct clk *clk_get_parent(struct clk *clk)
+{
+       return clk->parent;
+}
+EXPORT_SYMBOL_GPL(clk_get_parent);
+
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+       if (likely(clk->ops && clk->ops->round_rate)) {
+               unsigned long flags, rounded;
+
+               spin_lock_irqsave(&clock_lock, flags);
+               rounded = clk->ops->round_rate(clk, rate);
+               spin_unlock_irqrestore(&clock_lock, flags);
+
+               return rounded;
+       }
+
+       return clk_get_rate(clk);
+}
+EXPORT_SYMBOL_GPL(clk_round_rate);
+
+#ifdef CONFIG_PM
+static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
+{
+       static pm_message_t prev_state;
+       struct clk *clkp;
+
+       switch (state.event) {
+       case PM_EVENT_ON:
+               /* Resumeing from hibernation */
+               if (prev_state.event != PM_EVENT_FREEZE)
+                       break;
+
+               list_for_each_entry(clkp, &clock_list, node) {
+                       if (likely(clkp->ops)) {
+                               unsigned long rate = clkp->rate;
+
+                               if (likely(clkp->ops->set_parent))
+                                       clkp->ops->set_parent(clkp,
+                                               clkp->parent);
+                               if (likely(clkp->ops->set_rate))
+                                       clkp->ops->set_rate(clkp,
+                                               rate, NO_CHANGE);
+                               else if (likely(clkp->ops->recalc))
+                                       clkp->rate = clkp->ops->recalc(clkp);
+                       }
+               }
+               break;
+       case PM_EVENT_FREEZE:
+               break;
+       case PM_EVENT_SUSPEND:
+               break;
+       }
+
+       prev_state = state;
+       return 0;
+}
+
+static int clks_sysdev_resume(struct sys_device *dev)
+{
+       return clks_sysdev_suspend(dev, PMSG_ON);
+}
+
+static struct sysdev_class clks_sysdev_class = {
+       .name = "clks",
+};
+
+static struct sysdev_driver clks_sysdev_driver = {
+       .suspend = clks_sysdev_suspend,
+       .resume = clks_sysdev_resume,
+};
+
+static struct sys_device clks_sysdev_dev = {
+       .cls = &clks_sysdev_class,
+};
+
+static int __init clk_sysdev_init(void)
+{
+       sysdev_class_register(&clks_sysdev_class);
+       sysdev_driver_register(&clks_sysdev_class, &clks_sysdev_driver);
+       sysdev_register(&clks_sysdev_dev);
+
+       return 0;
+}
+subsys_initcall(clk_sysdev_init);
+#endif
+
+/*
+ *     debugfs support to trace clock tree hierarchy and attributes
+ */
+static struct dentry *clk_debugfs_root;
+
+static int clk_debugfs_register_one(struct clk *c)
+{
+       int err;
+       struct dentry *d, *child, *child_tmp;
+       struct clk *pa = c->parent;
+       char s[255];
+       char *p = s;
+
+       p += sprintf(p, "%s", c->name);
+       if (c->id >= 0)
+               sprintf(p, ":%d", c->id);
+       d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);
+       if (!d)
+               return -ENOMEM;
+       c->dentry = d;
+
+       d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);
+       if (!d) {
+               err = -ENOMEM;
+               goto err_out;
+       }
+       d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);
+       if (!d) {
+               err = -ENOMEM;
+               goto err_out;
+       }
+       d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);
+       if (!d) {
+               err = -ENOMEM;
+               goto err_out;
+       }
+       return 0;
+
+err_out:
+       d = c->dentry;
+       list_for_each_entry_safe(child, child_tmp, &d->d_subdirs, d_u.d_child)
+               debugfs_remove(child);
+       debugfs_remove(c->dentry);
+       return err;
+}
+
+static int clk_debugfs_register(struct clk *c)
+{
+       int err;
+       struct clk *pa = c->parent;
+
+       if (pa && !pa->dentry) {
+               err = clk_debugfs_register(pa);
+               if (err)
+                       return err;
+       }
+
+       if (!c->dentry && c->name) {
+               err = clk_debugfs_register_one(c);
+               if (err)
+                       return err;
+       }
+       return 0;
+}
+
+static int __init clk_debugfs_init(void)
+{
+       struct clk *c;
+       struct dentry *d;
+       int err;
+
+       d = debugfs_create_dir("clock", NULL);
+       if (!d)
+               return -ENOMEM;
+       clk_debugfs_root = d;
+
+       list_for_each_entry(c, &clock_list, node) {
+               err = clk_debugfs_register(c);
+               if (err)
+                       goto err_out;
+       }
+       return 0;
+err_out:
+       debugfs_remove_recursive(clk_debugfs_root);
+       return err;
+}
+late_initcall(clk_debugfs_init);
index 94ad6bd..c585574 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/topology.h>
 #include <linux/bitmap.h>
 #include <linux/cpumask.h>
+#include <asm/sizes.h>
 
 #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
        ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
@@ -45,6 +46,12 @@ struct intc_handle_int {
        unsigned long handle;
 };
 
+struct intc_window {
+       phys_addr_t phys;
+       void __iomem *virt;
+       unsigned long size;
+};
+
 struct intc_desc_int {
        struct list_head list;
        struct sys_device sysdev;
@@ -58,6 +65,8 @@ struct intc_desc_int {
        unsigned int nr_prio;
        struct intc_handle_int *sense;
        unsigned int nr_sense;
+       struct intc_window *window;
+       unsigned int nr_windows;
        struct irq_chip chip;
 };
 
@@ -87,8 +96,12 @@ static DEFINE_SPINLOCK(vector_lock);
 #define SMP_NR(d, x) 1
 #endif
 
-static unsigned int intc_prio_level[NR_IRQS]; /* for now */
+static unsigned int intc_prio_level[NR_IRQS];  /* for now */
+static unsigned int default_prio_level = 2;    /* 2 - 16 */
 static unsigned long ack_handle[NR_IRQS];
+#ifdef CONFIG_INTC_BALANCING
+static unsigned long dist_handle[NR_IRQS];
+#endif
 
 static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
 {
@@ -96,6 +109,47 @@ static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
        return container_of(chip, struct intc_desc_int, chip);
 }
 
+static unsigned long intc_phys_to_virt(struct intc_desc_int *d,
+                                      unsigned long address)
+{
+       struct intc_window *window;
+       int k;
+
+       /* scan through physical windows and convert address */
+       for (k = 0; k < d->nr_windows; k++) {
+               window = d->window + k;
+
+               if (address < window->phys)
+                       continue;
+
+               if (address >= (window->phys + window->size))
+                       continue;
+
+               address -= window->phys;
+               address += (unsigned long)window->virt;
+
+               return address;
+       }
+
+       /* no windows defined, register must be 1:1 mapped virt:phys */
+       return address;
+}
+
+static unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address)
+{
+       unsigned int k;
+
+       address = intc_phys_to_virt(d, address);
+
+       for (k = 0; k < d->nr_reg; k++) {
+               if (d->reg[k] == address)
+                       return k;
+       }
+
+       BUG();
+       return 0;
+}
+
 static inline unsigned int set_field(unsigned int value,
                                     unsigned int field_value,
                                     unsigned int handle)
@@ -229,6 +283,85 @@ static void (*intc_disable_fns[])(unsigned long addr,
        [MODE_PCLR_REG] = intc_mode_field,
 };
 
+#ifdef CONFIG_INTC_BALANCING
+static inline void intc_balancing_enable(unsigned int irq)
+{
+       struct intc_desc_int *d = get_intc_desc(irq);
+       unsigned long handle = dist_handle[irq];
+       unsigned long addr;
+
+       if (irq_balancing_disabled(irq) || !handle)
+               return;
+
+       addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
+       intc_reg_fns[_INTC_FN(handle)](addr, handle, 1);
+}
+
+static inline void intc_balancing_disable(unsigned int irq)
+{
+       struct intc_desc_int *d = get_intc_desc(irq);
+       unsigned long handle = dist_handle[irq];
+       unsigned long addr;
+
+       if (irq_balancing_disabled(irq) || !handle)
+               return;
+
+       addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
+       intc_reg_fns[_INTC_FN(handle)](addr, handle, 0);
+}
+
+static unsigned int intc_dist_data(struct intc_desc *desc,
+                                  struct intc_desc_int *d,
+                                  intc_enum enum_id)
+{
+       struct intc_mask_reg *mr = desc->hw.mask_regs;
+       unsigned int i, j, fn, mode;
+       unsigned long reg_e, reg_d;
+
+       for (i = 0; mr && enum_id && i < desc->hw.nr_mask_regs; i++) {
+               mr = desc->hw.mask_regs + i;
+
+               /*
+                * Skip this entry if there's no auto-distribution
+                * register associated with it.
+                */
+               if (!mr->dist_reg)
+                       continue;
+
+               for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
+                       if (mr->enum_ids[j] != enum_id)
+                               continue;
+
+                       fn = REG_FN_MODIFY_BASE;
+                       mode = MODE_ENABLE_REG;
+                       reg_e = mr->dist_reg;
+                       reg_d = mr->dist_reg;
+
+                       fn += (mr->reg_width >> 3) - 1;
+                       return _INTC_MK(fn, mode,
+                                       intc_get_reg(d, reg_e),
+                                       intc_get_reg(d, reg_d),
+                                       1,
+                                       (mr->reg_width - 1) - j);
+               }
+       }
+
+       /*
+        * It's possible we've gotten here with no distribution options
+        * available for the IRQ in question, so we just skip over those.
+        */
+       return 0;
+}
+#else
+static inline void intc_balancing_enable(unsigned int irq)
+{
+}
+
+static inline void intc_balancing_disable(unsigned int irq)
+{
+}
+#endif
+
 static inline void _intc_enable(unsigned int irq, unsigned long handle)
 {
        struct intc_desc_int *d = get_intc_desc(irq);
@@ -244,6 +377,8 @@ static inline void _intc_enable(unsigned int irq, unsigned long handle)
                intc_enable_fns[_INTC_MODE(handle)](addr, handle, intc_reg_fns\
                                                    [_INTC_FN(handle)], irq);
        }
+
+       intc_balancing_enable(irq);
 }
 
 static void intc_enable(unsigned int irq)
@@ -254,10 +389,12 @@ static void intc_enable(unsigned int irq)
 static void intc_disable(unsigned int irq)
 {
        struct intc_desc_int *d = get_intc_desc(irq);
-       unsigned long handle = (unsigned long) get_irq_chip_data(irq);
+       unsigned long handle = (unsigned long)get_irq_chip_data(irq);
        unsigned long addr;
        unsigned int cpu;
 
+       intc_balancing_disable(irq);
+
        for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
 #ifdef CONFIG_SMP
                if (!cpumask_test_cpu(cpu, irq_to_desc(irq)->affinity))
@@ -336,8 +473,7 @@ static void intc_mask_ack(unsigned int irq)
 
        intc_disable(irq);
 
-       /* read register and write zero only to the assocaited bit */
-
+       /* read register and write zero only to the associated bit */
        if (handle) {
                addr = INTC_REG(d, _INTC_ADDR_D(handle), 0);
                switch (_INTC_FN(handle)) {
@@ -366,7 +502,8 @@ static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
 {
        int i;
 
-       /* this doesn't scale well, but...
+       /*
+        * this doesn't scale well, but...
         *
         * this function should only be used for cerain uncommon
         * operations such as intc_set_priority() and intc_set_sense()
@@ -377,7 +514,6 @@ static struct intc_handle_int *intc_find_irq(struct intc_handle_int *hp,
         * memory footprint down is to make sure the array is sorted
         * and then perform a bisect to lookup the irq.
         */
-
        for (i = 0; i < nr_hp; i++) {
                if ((hp + i)->irq != irq)
                        continue;
@@ -408,7 +544,6 @@ int intc_set_priority(unsigned int irq, unsigned int prio)
                 * primary masking method is using intc_prio_level[irq]
                 * priority level will be set during next enable()
                 */
-
                if (_INTC_FN(ihp->handle) != REG_FN_ERR)
                        _intc_enable(irq, ihp->handle);
        }
@@ -447,20 +582,6 @@ static int intc_set_sense(unsigned int irq, unsigned int type)
        return 0;
 }
 
-static unsigned int __init intc_get_reg(struct intc_desc_int *d,
-                                unsigned long address)
-{
-       unsigned int k;
-
-       for (k = 0; k < d->nr_reg; k++) {
-               if (d->reg[k] == address)
-                       return k;
-       }
-
-       BUG();
-       return 0;
-}
-
 static intc_enum __init intc_grp_id(struct intc_desc *desc,
                                    intc_enum enum_id)
 {
@@ -718,13 +839,14 @@ static void __init intc_register_irq(struct intc_desc *desc,
         */
        set_bit(irq, intc_irq_map);
 
-       /* Prefer single interrupt source bitmap over other combinations:
+       /*
+        * Prefer single interrupt source bitmap over other combinations:
+        *
         * 1. bitmap, single interrupt source
         * 2. priority, single interrupt source
         * 3. bitmap, multiple interrupt sources (groups)
         * 4. priority, multiple interrupt sources (groups)
         */
-
        data[0] = intc_mask_data(desc, d, enum_id, 0);
        data[1] = intc_prio_data(desc, d, enum_id, 0);
 
@@ -749,10 +871,11 @@ static void __init intc_register_irq(struct intc_desc *desc,
                                      handle_level_irq, "level");
        set_irq_chip_data(irq, (void *)data[primary]);
 
-       /* set priority level
+       /*
+        * set priority level
         * - this needs to be at least 2 for 5-bit priorities on 7780
         */
-       intc_prio_level[irq] = 2;
+       intc_prio_level[irq] = default_prio_level;
 
        /* enable secondary masking method if present */
        if (data[!primary])
@@ -769,7 +892,6 @@ static void __init intc_register_irq(struct intc_desc *desc,
                         * only secondary priority should access registers, so
                         * set _INTC_FN(h) = REG_FN_ERR for intc_set_priority()
                         */
-
                        hp->handle &= ~_INTC_MK(0x0f, 0, 0, 0, 0, 0);
                        hp->handle |= _INTC_MK(REG_FN_ERR, 0, 0, 0, 0, 0);
                }
@@ -790,6 +912,11 @@ static void __init intc_register_irq(struct intc_desc *desc,
        if (desc->hw.ack_regs)
                ack_handle[irq] = intc_ack_data(desc, d, enum_id);
 
+#ifdef CONFIG_INTC_BALANCING
+       if (desc->hw.mask_regs)
+               dist_handle[irq] = intc_dist_data(desc, d, enum_id);
+#endif
+
 #ifdef CONFIG_ARM
        set_irq_flags(irq, IRQF_VALID); /* Enable IRQ on ARM systems */
 #endif
@@ -801,6 +928,8 @@ static unsigned int __init save_reg(struct intc_desc_int *d,
                                    unsigned int smp)
 {
        if (value) {
+               value = intc_phys_to_virt(d, value);
+
                d->reg[cnt] = value;
 #ifdef CONFIG_SMP
                d->smp[cnt] = smp;
@@ -816,25 +945,59 @@ static void intc_redirect_irq(unsigned int irq, struct irq_desc *desc)
        generic_handle_irq((unsigned int)get_irq_data(irq));
 }
 
-void __init register_intc_controller(struct intc_desc *desc)
+int __init register_intc_controller(struct intc_desc *desc)
 {
        unsigned int i, k, smp;
        struct intc_hw_desc *hw = &desc->hw;
        struct intc_desc_int *d;
+       struct resource *res;
+
+       pr_info("intc: Registered controller '%s' with %u IRQs\n",
+               desc->name, hw->nr_vectors);
 
        d = kzalloc(sizeof(*d), GFP_NOWAIT);
+       if (!d)
+               goto err0;
 
        INIT_LIST_HEAD(&d->list);
        list_add(&d->list, &intc_list);
 
+       if (desc->num_resources) {
+               d->nr_windows = desc->num_resources;
+               d->window = kzalloc(d->nr_windows * sizeof(*d->window),
+                                   GFP_NOWAIT);
+               if (!d->window)
+                       goto err1;
+
+               for (k = 0; k < d->nr_windows; k++) {
+                       res = desc->resource + k;
+                       WARN_ON(resource_type(res) != IORESOURCE_MEM);
+                       d->window[k].phys = res->start;
+                       d->window[k].size = resource_size(res);
+                       d->window[k].virt = ioremap_nocache(res->start,
+                                                        resource_size(res));
+                       if (!d->window[k].virt)
+                               goto err2;
+               }
+       }
+
        d->nr_reg = hw->mask_regs ? hw->nr_mask_regs * 2 : 0;
+#ifdef CONFIG_INTC_BALANCING
+       if (d->nr_reg)
+               d->nr_reg += hw->nr_mask_regs;
+#endif
        d->nr_reg += hw->prio_regs ? hw->nr_prio_regs * 2 : 0;
        d->nr_reg += hw->sense_regs ? hw->nr_sense_regs : 0;
        d->nr_reg += hw->ack_regs ? hw->nr_ack_regs : 0;
 
        d->reg = kzalloc(d->nr_reg * sizeof(*d->reg), GFP_NOWAIT);
+       if (!d->reg)
+               goto err2;
+
 #ifdef CONFIG_SMP
        d->smp = kzalloc(d->nr_reg * sizeof(*d->smp), GFP_NOWAIT);
+       if (!d->smp)
+               goto err3;
 #endif
        k = 0;
 
@@ -843,12 +1006,17 @@ void __init register_intc_controller(struct intc_desc *desc)
                        smp = IS_SMP(hw->mask_regs[i]);
                        k += save_reg(d, k, hw->mask_regs[i].set_reg, smp);
                        k += save_reg(d, k, hw->mask_regs[i].clr_reg, smp);
+#ifdef CONFIG_INTC_BALANCING
+                       k += save_reg(d, k, hw->mask_regs[i].dist_reg, 0);
+#endif
                }
        }
 
        if (hw->prio_regs) {
                d->prio = kzalloc(hw->nr_vectors * sizeof(*d->prio),
                                  GFP_NOWAIT);
+               if (!d->prio)
+                       goto err4;
 
                for (i = 0; i < hw->nr_prio_regs; i++) {
                        smp = IS_SMP(hw->prio_regs[i]);
@@ -860,6 +1028,8 @@ void __init register_intc_controller(struct intc_desc *desc)
        if (hw->sense_regs) {
                d->sense = kzalloc(hw->nr_vectors * sizeof(*d->sense),
                                   GFP_NOWAIT);
+               if (!d->sense)
+                       goto err5;
 
                for (i = 0; i < hw->nr_sense_regs; i++)
                        k += save_reg(d, k, hw->sense_regs[i].reg, 0);
@@ -906,7 +1076,7 @@ void __init register_intc_controller(struct intc_desc *desc)
 
                irq_desc = irq_to_desc_alloc_node(irq, numa_node_id());
                if (unlikely(!irq_desc)) {
-                       pr_info("can't get irq_desc for %d\n", irq);
+                       pr_err("can't get irq_desc for %d\n", irq);
                        continue;
                }
 
@@ -926,7 +1096,7 @@ void __init register_intc_controller(struct intc_desc *desc)
                         */
                        irq_desc = irq_to_desc_alloc_node(irq2, numa_node_id());
                        if (unlikely(!irq_desc)) {
-                               pr_info("can't get irq_desc for %d\n", irq2);
+                               pr_err("can't get irq_desc for %d\n", irq2);
                                continue;
                        }
 
@@ -942,8 +1112,100 @@ void __init register_intc_controller(struct intc_desc *desc)
        /* enable bits matching force_enable after registering irqs */
        if (desc->force_enable)
                intc_enable_disable_enum(desc, d, desc->force_enable, 1);
+
+       return 0;
+err5:
+       kfree(d->prio);
+err4:
+#ifdef CONFIG_SMP
+       kfree(d->smp);
+err3:
+#endif
+       kfree(d->reg);
+err2:
+       for (k = 0; k < d->nr_windows; k++)
+               if (d->window[k].virt)
+                       iounmap(d->window[k].virt);
+
+       kfree(d->window);
+err1:
+       kfree(d);
+err0:
+       pr_err("unable to allocate INTC memory\n");
+
+       return -ENOMEM;
+}
+
+#ifdef CONFIG_INTC_USERIMASK
+static void __iomem *uimask;
+
+int register_intc_userimask(unsigned long addr)
+{
+       if (unlikely(uimask))
+               return -EBUSY;
+
+       uimask = ioremap_nocache(addr, SZ_4K);
+       if (unlikely(!uimask))
+               return -ENOMEM;
+
+       pr_info("intc: userimask support registered for levels 0 -> %d\n",
+               default_prio_level - 1);
+
+       return 0;
+}
+
+static ssize_t
+show_intc_userimask(struct sysdev_class *cls,
+                   struct sysdev_class_attribute *attr, char *buf)
+{
+       return sprintf(buf, "%d\n", (__raw_readl(uimask) >> 4) & 0xf);
+}
+
+static ssize_t
+store_intc_userimask(struct sysdev_class *cls,
+                    struct sysdev_class_attribute *attr,
+                    const char *buf, size_t count)
+{
+       unsigned long level;
+
+       level = simple_strtoul(buf, NULL, 10);
+
+       /*
+        * Minimal acceptable IRQ levels are in the 2 - 16 range, but
+        * these are chomped so as to not interfere with normal IRQs.
+        *
+        * Level 1 is a special case on some CPUs in that it's not
+        * directly settable, but given that USERIMASK cuts off below a
+        * certain level, we don't care about this limitation here.
+        * Level 0 on the other hand equates to user masking disabled.
+        *
+        * We use default_prio_level as a cut off so that only special
+        * case opt-in IRQs can be mangled.
+        */
+       if (level >= default_prio_level)
+               return -EINVAL;
+
+       __raw_writel(0xa5 << 24 | level << 4, uimask);
+
+       return count;
 }
 
+static SYSDEV_CLASS_ATTR(userimask, S_IRUSR | S_IWUSR,
+                        show_intc_userimask, store_intc_userimask);
+#endif
+
+static ssize_t
+show_intc_name(struct sys_device *dev, struct sysdev_attribute *attr, char *buf)
+{
+       struct intc_desc_int *d;
+
+       d = container_of(dev, struct intc_desc_int, sysdev);
+
+       return sprintf(buf, "%s\n", d->chip.name);
+}
+
+static SYSDEV_ATTR(name, S_IRUGO, show_intc_name, NULL);
+
 static int intc_suspend(struct sys_device *dev, pm_message_t state)
 {
        struct intc_desc_int *d;
@@ -1003,19 +1265,28 @@ static int __init register_intc_sysdevs(void)
        int id = 0;
 
        error = sysdev_class_register(&intc_sysdev_class);
+#ifdef CONFIG_INTC_USERIMASK
+       if (!error && uimask)
+               error = sysdev_class_create_file(&intc_sysdev_class,
+                                                &attr_userimask);
+#endif
        if (!error) {
                list_for_each_entry(d, &intc_list, list) {
                        d->sysdev.id = id;
                        d->sysdev.cls = &intc_sysdev_class;
                        error = sysdev_register(&d->sysdev);
+                       if (error == 0)
+                               error = sysdev_create_file(&d->sysdev,
+                                                          &attr_name);
                        if (error)
                                break;
+
                        id++;
                }
        }
 
        if (error)
-               pr_warning("intc: sysdev registration error\n");
+               pr_err("intc: sysdev registration error\n");
 
        return error;
 }
@@ -1048,7 +1319,7 @@ unsigned int create_irq_nr(unsigned int irq_want, int node)
 
        desc = irq_to_desc_alloc_node(new, node);
        if (unlikely(!desc)) {
-               pr_info("can't get irq_desc for %d\n", new);
+               pr_err("can't get irq_desc for %d\n", new);
                goto out_unlock;
        }
 
index 3682835..e76b1af 100644 (file)
@@ -36,8 +36,7 @@
 #include <asm/delay.h>
 
 #include <mach/dma.h>
-#include <mach/regs-ssp.h>
-#include <mach/ssp.h>
+#include <plat/ssp.h>
 #include <mach/pxa2xx_spi.h>
 
 MODULE_AUTHOR("Stephen Street");
@@ -1318,14 +1317,14 @@ static int setup(struct spi_device *spi)
        /* NOTE:  PXA25x_SSP _could_ use external clocking ... */
        if (drv_data->ssp_type != PXA25x_SSP)
                dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
-                               clk_get_rate(ssp->clk)
-                                       / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
-                               chip->enable_dma ? "DMA" : "PIO");
+                       clk_get_rate(ssp->clk)
+                               / (1 + ((chip->cr0 & SSCR0_SCR(0xfff)) >> 8)),
+                       chip->enable_dma ? "DMA" : "PIO");
        else
                dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
-                               clk_get_rate(ssp->clk) / 2
-                                       / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
-                               chip->enable_dma ? "DMA" : "PIO");
+                       clk_get_rate(ssp->clk) / 2
+                               / (1 + ((chip->cr0 & SSCR0_SCR(0x0ff)) >> 8)),
+                       chip->enable_dma ? "DMA" : "PIO");
 
        if (spi->bits_per_word <= 8) {
                chip->n_bytes = 1;
@@ -1466,7 +1465,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
 
        platform_info = dev->platform_data;
 
-       ssp = ssp_request(pdev->id, pdev->name);
+       ssp = pxa_ssp_request(pdev->id, pdev->name);
        if (ssp == NULL) {
                dev_err(&pdev->dev, "failed to request SSP%d\n", pdev->id);
                return -ENODEV;
@@ -1476,7 +1475,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
        master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
        if (!master) {
                dev_err(&pdev->dev, "cannot alloc spi_master\n");
-               ssp_free(ssp);
+               pxa_ssp_free(ssp);
                return -ENOMEM;
        }
        drv_data = spi_master_get_devdata(master);
@@ -1558,7 +1557,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
        write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
                                SSCR1_TxTresh(TX_THRESH_DFLT),
                                drv_data->ioaddr);
-       write_SSCR0(SSCR0_SerClkDiv(2)
+       write_SSCR0(SSCR0_SCR(2)
                        | SSCR0_Motorola
                        | SSCR0_DataSize(8),
                        drv_data->ioaddr);
@@ -1605,7 +1604,7 @@ out_error_irq_alloc:
 
 out_error_master_alloc:
        spi_master_put(master);
-       ssp_free(ssp);
+       pxa_ssp_free(ssp);
        return status;
 }
 
@@ -1649,7 +1648,7 @@ static int pxa2xx_spi_remove(struct platform_device *pdev)
        free_irq(ssp->irq, drv_data);
 
        /* Release SSP */
-       ssp_free(ssp);
+       pxa_ssp_free(ssp);
 
        /* Disconnect from the SPI framework */
        spi_unregister_master(drv_data->master);
index 14d0523..e324627 100644 (file)
@@ -640,7 +640,7 @@ static int mpc8xxx_spi_setup(struct spi_device *spi)
        }
        mpc8xxx_spi = spi_master_get_devdata(spi->master);
 
-       hw_mode = cs->hw_mode; /* Save orginal settings */
+       hw_mode = cs->hw_mode; /* Save original settings */
        cs->hw_mode = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
        /* mask out bits we are going to set */
        cs->hw_mode &= ~(SPMODE_CP_BEGIN_EDGECLK | SPMODE_CI_INACTIVEHIGH
index 80ff7d9..bc9bdb2 100644 (file)
@@ -490,7 +490,7 @@ static int ssb_devices_register(struct ssb_bus *bus)
                        break;
                case SSB_BUSTYPE_PCMCIA:
 #ifdef CONFIG_SSB_PCMCIAHOST
-                       sdev->irq = bus->host_pcmcia->irq.AssignedIRQ;
+                       sdev->irq = bus->host_pcmcia->irq;
                        dev->parent = &bus->host_pcmcia->dev;
 #endif
                        break;
index 7696a66..5589616 100644 (file)
@@ -49,6 +49,8 @@ source "drivers/staging/go7007/Kconfig"
 
 source "drivers/staging/cx25821/Kconfig"
 
+source "drivers/staging/tm6000/Kconfig"
+
 source "drivers/staging/usbip/Kconfig"
 
 source "drivers/staging/winbond/Kconfig"
index ea2e70e..ec45d4b 100644 (file)
@@ -7,6 +7,7 @@ obj-$(CONFIG_ET131X)            += et131x/
 obj-$(CONFIG_SLICOSS)          += slicoss/
 obj-$(CONFIG_VIDEO_GO7007)     += go7007/
 obj-$(CONFIG_VIDEO_CX25821)    += cx25821/
+obj-$(CONFIG_VIDEO_TM6000)     += tm6000/
 obj-$(CONFIG_USB_IP_COMMON)    += usbip/
 obj-$(CONFIG_W35UND)           += winbond/
 obj-$(CONFIG_PRISM2_USB)       += wlan-ng/
index 5632991..30b522c 100644 (file)
@@ -180,12 +180,12 @@ static int das16cs_attach(struct comedi_device *dev,
        }
        printk("\n");
 
-       ret = request_irq(link->irq.AssignedIRQ, das16cs_interrupt,
+       ret = request_irq(link->irq, das16cs_interrupt,
                          IRQF_SHARED, "cb_das16_cs", dev);
        if (ret < 0) {
                return ret;
        }
-       dev->irq = link->irq.AssignedIRQ;
+       dev->irq = link->irq;
        printk("irq=%u ", dev->irq);
 
        dev->board_ptr = das16cs_probe(dev, link);
@@ -671,7 +671,6 @@ static dev_info_t dev_info = "cb_das16_cs";
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        struct bus_operations *bus;
 };
@@ -702,10 +701,6 @@ static int das16cs_pcmcia_attach(struct pcmcia_device *link)
        link->priv = local;
 
        /* Initialize the pcmcia_device structure */
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = NULL;
-
        link->conf.Attributes = 0;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -720,10 +715,8 @@ static void das16cs_pcmcia_detach(struct pcmcia_device *link)
 {
        dev_dbg(&link->dev, "das16cs_pcmcia_detach\n");
 
-       if (link->dev_node) {
-               ((struct local_info_t *)link->priv)->stop = 1;
-               das16cs_pcmcia_release(link);
-       }
+       ((struct local_info_t *)link->priv)->stop = 1;
+       das16cs_pcmcia_release(link);
        /* This points to the parent struct local_info_t struct */
        if (link->priv)
                kfree(link->priv);
@@ -740,8 +733,7 @@ static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev,
                return -EINVAL;
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -769,7 +761,6 @@ static int das16cs_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void das16cs_pcmcia_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        int ret;
 
        dev_dbg(&link->dev, "das16cs_pcmcia_config\n");
@@ -780,16 +771,9 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-          Allocate an interrupt line.  Note that this does not assign a
-          handler to the interrupt, unless the 'Handler' member of the
-          irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
+
        /*
           This actually configures the PCMCIA socket -- setting up
           the I/O windows and the interrupt mapping, and putting the
@@ -799,19 +783,10 @@ static void das16cs_pcmcia_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       sprintf(dev->node.dev_name, "cb_das16_cs");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %u", link->irq.AssignedIRQ);
+               printk(", irq %u", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index 9164ce1..896d25b 100644 (file)
@@ -142,7 +142,6 @@ static const dev_info_t dev_info = "pcm-das08";
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        struct bus_operations *bus;
 };
@@ -172,10 +171,6 @@ static int das08_pcmcia_attach(struct pcmcia_device *link)
        local->link = link;
        link->priv = local;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-       link->irq.Handler = NULL;
-
        /*
           General socket configuration defaults can go here.  In this
           client, we assume very little, and rely on the CIS for almost
@@ -207,10 +202,8 @@ static void das08_pcmcia_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "das08_pcmcia_detach\n");
 
-       if (link->dev_node) {
-               ((struct local_info_t *)link->priv)->stop = 1;
-               das08_pcmcia_release(link);
-       }
+       ((struct local_info_t *)link->priv)->stop = 1;
+       das08_pcmcia_release(link);
 
        /* This points to the parent struct local_info_t struct */
        if (link->priv)
@@ -229,8 +222,7 @@ static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
                return -ENODEV;
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -266,7 +258,6 @@ static int das08_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void das08_pcmcia_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        int ret;
 
        dev_dbg(&link->dev, "das08_pcmcia_config\n");
@@ -277,11 +268,8 @@ static void das08_pcmcia_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -292,19 +280,10 @@ static void das08_pcmcia_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       sprintf(dev->node.dev_name, "pcm-das08");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %u", link->irq.AssignedIRQ);
+               printk(", irq %u", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index 7ea6453..06dd44f 100644 (file)
@@ -380,7 +380,7 @@ static int dio700_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                        return -EIO;
                iobase = link->io.BasePort1;
 #ifdef incomplete
-               irq = link->irq.AssignedIRQ;
+               irq = link->irq;
 #endif
                break;
        default:
@@ -470,7 +470,6 @@ static const dev_info_t dev_info = "ni_daq_700";
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        struct bus_operations *bus;
 };
@@ -502,10 +501,6 @@ static int dio700_cs_attach(struct pcmcia_device *link)
        local->link = link;
        link->priv = local;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = NULL;
-
        /*
           General socket configuration defaults can go here.  In this
           client, we assume very little, and rely on the CIS for almost
@@ -539,10 +534,8 @@ static void dio700_cs_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "dio700_cs_detach\n");
 
-       if (link->dev_node) {
-               ((struct local_info_t *)link->priv)->stop = 1;
-               dio700_release(link);
-       }
+       ((struct local_info_t *)link->priv)->stop = 1;
+       dio700_release(link);
 
        /* This points to the parent struct local_info_t struct */
        if (link->priv)
@@ -577,8 +570,7 @@ static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev,
        }
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -625,7 +617,6 @@ static int dio700_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void dio700_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        win_req_t req;
        int ret;
 
@@ -639,16 +630,8 @@ static void dio700_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-          Allocate an interrupt line.  Note that this does not assign a
-          handler to the interrupt, unless the 'Handler' member of the
-          irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -659,19 +642,10 @@ static void dio700_config(struct pcmcia_device *link)
        if (ret != 0)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       sprintf(dev->node.dev_name, "ni_daq_700");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %d", link->irq.AssignedIRQ);
+               printk(", irq %d", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index ddc312b..7bfe08b 100644 (file)
@@ -131,7 +131,7 @@ static int dio24_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                        return -EIO;
                iobase = link->io.BasePort1;
 #ifdef incomplete
-               irq = link->irq.AssignedIRQ;
+               irq = link->irq;
 #endif
                break;
        default:
@@ -221,7 +221,6 @@ static const dev_info_t dev_info = "ni_daq_dio24";
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        struct bus_operations *bus;
 };
@@ -253,10 +252,6 @@ static int dio24_cs_attach(struct pcmcia_device *link)
        local->link = link;
        link->priv = local;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = NULL;
-
        /*
           General socket configuration defaults can go here.  In this
           client, we assume very little, and rely on the CIS for almost
@@ -290,10 +285,8 @@ static void dio24_cs_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "dio24_cs_detach\n");
 
-       if (link->dev_node) {
-               ((struct local_info_t *)link->priv)->stop = 1;
-               dio24_release(link);
-       }
+       ((struct local_info_t *)link->priv)->stop = 1;
+       dio24_release(link);
 
        /* This points to the parent local_info_t struct */
        if (link->priv)
@@ -328,8 +321,7 @@ static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
        }
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -376,7 +368,6 @@ static int dio24_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void dio24_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        int ret;
        win_req_t req;
 
@@ -390,16 +381,8 @@ static void dio24_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-          Allocate an interrupt line.  Note that this does not assign a
-          handler to the interrupt, unless the 'Handler' member of the
-          irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -410,19 +393,10 @@ static void dio24_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       sprintf(dev->node.dev_name, "ni_daq_dio24");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %d", link->irq.AssignedIRQ);
+               printk(", irq %d", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index 8ad1055..fd8d3e9 100644 (file)
@@ -144,7 +144,7 @@ static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
                if (!link)
                        return -EIO;
                iobase = link->io.BasePort1;
-               irq = link->irq.AssignedIRQ;
+               irq = link->irq;
                break;
        default:
                printk("bug! couldn't determine board type\n");
@@ -199,7 +199,6 @@ static const dev_info_t dev_info = "daqcard-1200";
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        struct bus_operations *bus;
 };
@@ -229,10 +228,6 @@ static int labpc_cs_attach(struct pcmcia_device *link)
        local->link = link;
        link->priv = local;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_FORCED_PULSE;
-       link->irq.Handler = NULL;
-
        /*
           General socket configuration defaults can go here.  In this
           client, we assume very little, and rely on the CIS for almost
@@ -269,10 +264,8 @@ static void labpc_cs_detach(struct pcmcia_device *link)
           the release() function is called, that will trigger a proper
           detach().
         */
-       if (link->dev_node) {
-               ((struct local_info_t *)link->priv)->stop = 1;
-               labpc_release(link);
-       }
+       ((struct local_info_t *)link->priv)->stop = 1;
+       labpc_release(link);
 
        /* This points to the parent local_info_t struct (may be null) */
        kfree(link->priv);
@@ -306,8 +299,7 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
        }
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -355,7 +347,6 @@ static int labpc_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void labpc_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        int ret;
        win_req_t req;
 
@@ -367,16 +358,8 @@ static void labpc_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-          Allocate an interrupt line.  Note that this does not assign a
-          handler to the interrupt, unless the 'Handler' member of the
-          irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       if (!link->irq)
+               goto failed;
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -387,19 +370,10 @@ static void labpc_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       sprintf(dev->node.dev_name, "daqcard-1200");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %d", link->irq.AssignedIRQ);
+               printk(", irq %d", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index dc4849a..1e8aeba 100644 (file)
@@ -262,17 +262,11 @@ static void cs_detach(struct pcmcia_device *);
 
 static struct pcmcia_device *cur_dev = NULL;
 static const dev_info_t dev_info = "ni_mio_cs";
-static dev_node_t dev_node = {
-       "ni_mio_cs",
-       COMEDI_MAJOR, 0,
-       NULL
-};
 
 static int cs_attach(struct pcmcia_device *link)
 {
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
        link->io.NumPorts1 = 16;
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
@@ -292,8 +286,7 @@ static void cs_detach(struct pcmcia_device *link)
 {
        DPRINTK("cs_detach(link=%p)\n", link);
 
-       if (link->dev_node)
-               cs_release(link);
+       cs_release(link);
 }
 
 static int mio_cs_suspend(struct pcmcia_device *link)
@@ -344,14 +337,10 @@ static void mio_cs_config(struct pcmcia_device *link)
                return;
        }
 
-       ret = pcmcia_request_irq(link, &link->irq);
-       if (ret) {
-               printk("pcmcia_request_irq() returned error: %i\n", ret);
-       }
+       if (!link->irq)
+               dev_info(&link->dev, "no IRQ available\n");
 
        ret = pcmcia_request_configuration(link, &link->conf);
-
-       link->dev_node = &dev_node;
 }
 
 static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it)
@@ -369,7 +358,7 @@ static int mio_cs_attach(struct comedi_device *dev, struct comedi_devconfig *it)
        dev->driver = &driver_ni_mio_cs;
        dev->iobase = link->io.BasePort1;
 
-       irq = link->irq.AssignedIRQ;
+       irq = link->irq;
 
        printk("comedi%d: %s: DAQCard: io 0x%04lx, irq %u, ",
               dev->minor, dev->driver->driver_name, dev->iobase, irq);
index 3325f24..1786db2 100644 (file)
@@ -60,7 +60,6 @@ Devices: [Quatech] DAQP-208 (daqp), DAQP-308
 
 struct local_info_t {
        struct pcmcia_device *link;
-       dev_node_t node;
        int stop;
        int table_index;
        char board_name[32];
@@ -1040,10 +1039,6 @@ static int daqp_cs_attach(struct pcmcia_device *link)
        local->link = link;
        link->priv = local;
 
-       /* Interrupt setup */
-       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-       link->irq.Handler = daqp_interrupt;
-
        /*
           General socket configuration defaults can go here.  In this
           client, we assume very little, and rely on the CIS for almost
@@ -1074,10 +1069,8 @@ static void daqp_cs_detach(struct pcmcia_device *link)
 
        dev_dbg(&link->dev, "daqp_cs_detach\n");
 
-       if (link->dev_node) {
-               dev->stop = 1;
-               daqp_cs_release(link);
-       }
+       dev->stop = 1;
+       daqp_cs_release(link);
 
        /* Unlink device structure, and free it */
        dev_table[dev->table_index] = NULL;
@@ -1105,8 +1098,7 @@ static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev,
                return -ENODEV;
 
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -1133,7 +1125,6 @@ static int daqp_pcmcia_config_loop(struct pcmcia_device *p_dev,
 
 static void daqp_cs_config(struct pcmcia_device *link)
 {
-       struct local_info_t *dev = link->priv;
        int ret;
 
        dev_dbg(&link->dev, "daqp_cs_config\n");
@@ -1144,16 +1135,9 @@ static void daqp_cs_config(struct pcmcia_device *link)
                goto failed;
        }
 
-       /*
-          Allocate an interrupt line.  Note that this does not assign a
-          handler to the interrupt, unless the 'Handler' member of the
-          irq structure is initialized.
-        */
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       }
+       ret = pcmcia_request_irq(link, daqp_interrupt);
+       if (ret)
+               goto failed;
 
        /*
           This actually configures the PCMCIA socket -- setting up
@@ -1164,23 +1148,10 @@ static void daqp_cs_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       /*
-          At this point, the dev_node_t structure(s) need to be
-          initialized and arranged in a linked list at link->dev.
-        */
-       /* Comedi's PCMCIA script uses this device name (extracted
-        * from /var/lib/pcmcia/stab) to pass to comedi_config
-        */
-       /* sprintf(dev->node.dev_name, "daqp%d", dev->table_index); */
-       sprintf(dev->node.dev_name, "quatech_daqp_cs");
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
        /* Finally, report what we've done */
-       printk(KERN_INFO "%s: index 0x%02x",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x", link->conf.ConfigIndex);
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
-               printk(", irq %u", link->irq.AssignedIRQ);
+               printk(", irq %u", link->irq);
        if (link->io.NumPorts1)
                printk(", io 0x%04x-0x%04x", link->io.BasePort1,
                       link->io.BasePort1 + link->io.NumPorts1 - 1);
index 061add3..1798975 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 
-#include <asm/delay.h>
+#include <linux/delay.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 
 #define AUDIO_SRAM_CHANNEL     SRAM_CH08
 
-#define dprintk(level,fmt, arg...)     if (debug >= level) \
+#define dprintk(level, fmt, arg...)    if (debug >= level) \
        printk(KERN_INFO "%s/1: " fmt, chip->dev->name , ## arg)
 
-#define dprintk_core(level,fmt, arg...)        if (debug >= level) \
+#define dprintk_core(level, fmt, arg...)       if (debug >= level) \
        printk(KERN_DEBUG "%s/1: " fmt, chip->dev->name , ## arg)
 
 /****************************************************************************
@@ -81,7 +81,6 @@ struct cx25821_audio_dev {
 
        struct snd_pcm_substream *substream;
 };
-typedef struct cx25821_audio_dev snd_cx25821_card_t;
 
 
 /****************************************************************************
@@ -90,7 +89,7 @@ typedef struct cx25821_audio_dev snd_cx25821_card_t;
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = { 1,[1 ... (SNDRV_CARDS - 1)] = 1 };
+static int enable[SNDRV_CARDS] = { 1, [1 ... (SNDRV_CARDS - 1)] = 1 };
 
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable cx25821 soundcard. default enabled.");
@@ -105,7 +104,7 @@ MODULE_PARM_DESC(index, "Index value for cx25821 capture interface(s).");
 MODULE_DESCRIPTION("ALSA driver module for cx25821 based capture cards");
 MODULE_AUTHOR("Hiep Huynh");
 MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{Conexant,25821}");  //"{{Conexant,23881},"
+MODULE_SUPPORTED_DEVICE("{{Conexant,25821}");  /* "{{Conexant,23881}," */
 
 static unsigned int debug;
 module_param(debug, int, 0644);
@@ -135,7 +134,7 @@ MODULE_PARM_DESC(debug, "enable debug messages");
  * BOARD Specific: Sets audio DMA
  */
 
-static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
+static int _cx25821_start_audio_dma(struct cx25821_audio_dev *chip)
 {
        struct cx25821_buffer *buf = chip->buf;
        struct cx25821_dev *dev = chip->dev;
@@ -143,7 +142,7 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
            &cx25821_sram_channels[AUDIO_SRAM_CHANNEL];
        u32 tmp = 0;
 
-       // enable output on the GPIO 0 for the MCLK ADC (Audio)
+       /* enable output on the GPIO 0 for the MCLK ADC (Audio) */
        cx25821_set_gpiopin_direction(chip->dev, 0, 0);
 
        /* Make sure RISC/FIFO are off before changing FIFO/RISC settings */
@@ -158,18 +157,23 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
        cx_write(AUD_A_LNGTH, buf->bpl);
 
        /* reset counter */
-       cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);      //GP_COUNT_CONTROL_RESET = 0x3
+       /* GP_COUNT_CONTROL_RESET = 0x3 */
+       cx_write(AUD_A_GPCNT_CTL, GP_COUNT_CONTROL_RESET);
        atomic_set(&chip->count, 0);
 
-       //Set the input mode to 16-bit
+       /* Set the input mode to 16-bit */
        tmp = cx_read(AUD_A_CFG);
        cx_write(AUD_A_CFG,
                 tmp | FLD_AUD_DST_PK_MODE | FLD_AUD_DST_ENABLE |
                 FLD_AUD_CLK_ENABLE);
 
-       //printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line, cmds_start(0x%x)= %d lines/FIFO, %d periods, %d "
-       //      "byte buffer\n", buf->bpl, audio_ch->cmds_start, cx_read(audio_ch->cmds_start + 12)>>1,
-       //      chip->num_periods, buf->bpl * chip->num_periods);
+       /* printk(KERN_INFO "DEBUG: Start audio DMA, %d B/line,"
+                               "cmds_start(0x%x)= %d lines/FIFO, %d periods, "
+                               "%d byte buffer\n", buf->bpl,
+                               audio_ch->cmds_start,
+                               cx_read(audio_ch->cmds_start + 12)>>1,
+                               chip->num_periods, buf->bpl *chip->num_periods);
+       */
 
        /* Enables corresponding bits at AUD_INT_STAT */
        cx_write(AUD_A_INT_MSK,
@@ -182,7 +186,7 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
        /* enable audio irqs */
        cx_set(PCI_INT_MSK, chip->dev->pci_irqmask | PCI_MSK_AUD_INT);
 
-       // Turn on audio downstream fifo and risc enable 0x101
+       /* Turn on audio downstream fifo and risc enable 0x101 */
        tmp = cx_read(AUD_INT_DMA_CTL);
        cx_set(AUD_INT_DMA_CTL,
               tmp | (FLD_AUD_DST_A_RISC_EN | FLD_AUD_DST_A_FIFO_EN));
@@ -194,7 +198,7 @@ static int _cx25821_start_audio_dma(snd_cx25821_card_t * chip)
 /*
  * BOARD Specific: Resets audio DMA
  */
-static int _cx25821_stop_audio_dma(snd_cx25821_card_t * chip)
+static int _cx25821_stop_audio_dma(struct cx25821_audio_dev *chip)
 {
        struct cx25821_dev *dev = chip->dev;
 
@@ -232,13 +236,13 @@ static char *cx25821_aud_irqs[32] = {
 /*
  * BOARD Specific: Threats IRQ audio specific calls
  */
-static void cx25821_aud_irq(snd_cx25821_card_t * chip, u32 status, u32 mask)
+static void cx25821_aud_irq(struct cx25821_audio_dev *chip, u32 status,
+                           u32 mask)
 {
        struct cx25821_dev *dev = chip->dev;
 
-       if (0 == (status & mask)) {
+       if (0 == (status & mask))
                return;
-       }
 
        cx_write(AUD_A_INT_STAT, status);
        if (debug > 1 || (status & mask & ~0xff))
@@ -277,7 +281,7 @@ static void cx25821_aud_irq(snd_cx25821_card_t * chip, u32 status, u32 mask)
  */
 static irqreturn_t cx25821_irq(int irq, void *dev_id)
 {
-       snd_cx25821_card_t *chip = dev_id;
+       struct cx25821_audio_dev *chip = dev_id;
        struct cx25821_dev *dev = chip->dev;
        u32 status, pci_status;
        u32 audint_status, audint_mask;
@@ -318,11 +322,11 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
        if (handled)
                cx_write(PCI_INT_STAT, pci_status);
 
-      out:
+out:
        return IRQ_RETVAL(handled);
 }
 
-static int dsp_buffer_free(snd_cx25821_card_t * chip)
+static int dsp_buffer_free(struct cx25821_audio_dev *chip)
 {
        BUG_ON(!chip->dma_size);
 
@@ -363,7 +367,8 @@ static struct snd_pcm_hardware snd_cx25821_digital_hw = {
        .period_bytes_max = DEFAULT_FIFO_SIZE / 3,
        .periods_min = 1,
        .periods_max = AUDIO_LINE_SIZE,
-       .buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE),        //128*128 = 16384 = 1024 * 16
+       /* 128 * 128 = 16384 = 1024 * 16 */
+       .buffer_bytes_max = (AUDIO_LINE_SIZE * AUDIO_LINE_SIZE),
 };
 
 /*
@@ -371,7 +376,7 @@ static struct snd_pcm_hardware snd_cx25821_digital_hw = {
  */
 static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
 {
-       snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
+       struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
        unsigned int bpl = 0;
@@ -393,18 +398,19 @@ static int snd_cx25821_pcm_open(struct snd_pcm_substream *substream)
 
        if (cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size !=
            DEFAULT_FIFO_SIZE) {
-               bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3;  //since there are 3 audio Clusters
+               /* since there are 3 audio Clusters */
+               bpl = cx25821_sram_channels[AUDIO_SRAM_CHANNEL].fifo_size / 3;
                bpl &= ~7;      /* must be multiple of 8 */
 
-               if (bpl > AUDIO_LINE_SIZE) {
+               if (bpl > AUDIO_LINE_SIZE)
                        bpl = AUDIO_LINE_SIZE;
-               }
+
                runtime->hw.period_bytes_min = bpl;
                runtime->hw.period_bytes_max = bpl;
        }
 
        return 0;
-      _error:
+_error:
        dprintk(1, "Error opening PCM!\n");
        return err;
 }
@@ -423,7 +429,7 @@ static int snd_cx25821_close(struct snd_pcm_substream *substream)
 static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
                                 struct snd_pcm_hw_params *hw_params)
 {
-       snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
+       struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
        struct videobuf_dmabuf *dma;
 
        struct cx25821_buffer *buf;
@@ -445,9 +451,8 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
        if (NULL == buf)
                return -ENOMEM;
 
-       if (chip->period_size > AUDIO_LINE_SIZE) {
+       if (chip->period_size > AUDIO_LINE_SIZE)
                chip->period_size = AUDIO_LINE_SIZE;
-       }
 
        buf->vb.memory = V4L2_MEMORY_MMAP;
        buf->vb.field = V4L2_FIELD_NONE;
@@ -474,7 +479,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
                                          buf->vb.width, buf->vb.height, 1);
        if (ret < 0) {
                printk(KERN_INFO
-                      "DEBUG: ERROR after cx25821_risc_databuffer_audio() \n");
+                       "DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
                goto error;
        }
 
@@ -494,7 +499,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
 
        return 0;
 
-      error:
+error:
        kfree(buf);
        return ret;
 }
@@ -504,7 +509,7 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
  */
 static int snd_cx25821_hw_free(struct snd_pcm_substream *substream)
 {
-       snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
+       struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
 
        if (substream->runtime->dma_area) {
                dsp_buffer_free(chip);
@@ -528,7 +533,7 @@ static int snd_cx25821_prepare(struct snd_pcm_substream *substream)
 static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream,
                                    int cmd)
 {
-       snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
+       struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
        int err = 0;
 
        /* Local interrupts are already disabled by ALSA */
@@ -557,7 +562,7 @@ static int snd_cx25821_card_trigger(struct snd_pcm_substream *substream,
 static snd_pcm_uframes_t snd_cx25821_pointer(struct snd_pcm_substream
                                             *substream)
 {
-       snd_cx25821_card_t *chip = snd_pcm_substream_chip(substream);
+       struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
        u16 count;
 
@@ -593,10 +598,11 @@ static struct snd_pcm_ops snd_cx25821_pcm_ops = {
 };
 
 /*
- * ALSA create a PCM device:  Called when initializing the board. Sets up the name and hooks up
- *  the callbacks
+ * ALSA create a PCM device:  Called when initializing the board.
+ * Sets up the name and hooks up the callbacks
  */
-static int snd_cx25821_pcm(snd_cx25821_card_t * chip, int device, char *name)
+static int snd_cx25821_pcm(struct cx25821_audio_dev *chip, int device,
+                          char *name)
 {
        struct snd_pcm *pcm;
        int err;
@@ -636,7 +642,7 @@ MODULE_DEVICE_TABLE(pci, cx25821_audio_pci_tbl);
  * from the file.
  */
 /*
-static int snd_cx25821_free(snd_cx25821_card_t *chip)
+static int snd_cx25821_free(struct cx25821_audio_dev *chip)
 {
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
@@ -653,9 +659,9 @@ static int snd_cx25821_free(snd_cx25821_card_t *chip)
  */
 static void snd_cx25821_dev_free(struct snd_card *card)
 {
-       snd_cx25821_card_t *chip = card->private_data;
+       struct cx25821_audio_dev *chip = card->private_data;
 
-       //snd_cx25821_free(chip);
+       /* snd_cx25821_free(chip); */
        snd_card_free(chip->card);
 }
 
@@ -665,23 +671,23 @@ static void snd_cx25821_dev_free(struct snd_card *card)
 static int cx25821_audio_initdev(struct cx25821_dev *dev)
 {
        struct snd_card *card;
-       snd_cx25821_card_t *chip;
+       struct cx25821_audio_dev *chip;
        int err;
 
        if (devno >= SNDRV_CARDS) {
                printk(KERN_INFO "DEBUG ERROR: devno >= SNDRV_CARDS %s\n",
                       __func__);
-               return (-ENODEV);
+               return -ENODEV;
        }
 
        if (!enable[devno]) {
                ++devno;
                printk(KERN_INFO "DEBUG ERROR: !enable[devno] %s\n", __func__);
-               return (-ENOENT);
+               return -ENOENT;
        }
 
        err = snd_card_create(index[devno], id[devno], THIS_MODULE,
-                        sizeof(snd_cx25821_card_t), &card);
+                        sizeof(struct cx25821_audio_dev), &card);
        if (err < 0) {
                printk(KERN_INFO
                       "DEBUG ERROR: cannot create snd_card_new in %s\n",
@@ -693,7 +699,7 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
 
        /* Card "creation" */
        card->private_free = snd_cx25821_dev_free;
-       chip = (snd_cx25821_card_t *) card->private_data;
+       chip = (struct cx25821_audio_dev *) card->private_data;
        spin_lock_init(&chip->reg_lock);
 
        chip->dev = dev;
@@ -712,7 +718,8 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
                goto error;
        }
 
-       if ((err = snd_cx25821_pcm(chip, 0, "cx25821 Digital")) < 0) {
+       err = snd_cx25821_pcm(chip, 0, "cx25821 Digital");
+       if (err < 0) {
                printk(KERN_INFO
                       "DEBUG ERROR: cannot create snd_cx25821_pcm %s\n",
                       __func__);
@@ -741,7 +748,7 @@ static int cx25821_audio_initdev(struct cx25821_dev *dev)
        devno++;
        return 0;
 
-      error:
+error:
        snd_card_free(card);
        return err;
 }
index 11c56bd..6a4e872 100644 (file)
@@ -33,7 +33,7 @@
 #include <linux/fcntl.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
 MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
@@ -62,9 +62,8 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
        cdt = ch->cdt;
        lines = ch->fifo_size / bpl;
 
-       if (lines > 3) {
+       if (lines > 3)
                lines = 3;
-       }
 
        BUG_ON(lines < 2);
 
@@ -84,7 +83,7 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
        cx_write(ch->cmds_start + 12, AUDIO_CDT_SIZE_QW);
        cx_write(ch->cmds_start + 16, ch->ctrl_start);
 
-       //IQ size
+       /* IQ size */
        cx_write(ch->cmds_start + 20, AUDIO_IQ_SIZE_DW);
 
        for (i = 24; i < 80; i += 4)
@@ -100,7 +99,7 @@ int cx25821_sram_channel_setup_upstream_audio(struct cx25821_dev *dev,
 }
 
 static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
-                                                __le32 * rp,
+                                                __le32 *rp,
                                                 dma_addr_t databuf_phys_addr,
                                                 unsigned int bpl,
                                                 int fifo_enable)
@@ -116,8 +115,10 @@ static __le32 *cx25821_risc_field_upstream_audio(struct cx25821_dev *dev,
                *(rp++) = cpu_to_le32(databuf_phys_addr + offset);
                *(rp++) = cpu_to_le32(0);       /* bits 63-32 */
 
-               // Check if we need to enable the FIFO after the first 3 lines
-               // For the upstream audio channel, the risc engine will enable the FIFO.
+               /* Check if we need to enable the FIFO
+                * after the first 3 lines.
+                * For the upstream audio channel,
+                * the risc engine will enable the FIFO */
                if (fifo_enable && line == 2) {
                        *(rp++) = RISC_WRITECR;
                        *(rp++) = sram_ch->dma_ctl;
@@ -160,7 +161,7 @@ int cx25821_risc_buffer_upstream_audio(struct cx25821_dev *dev,
                        risc_flag = RISC_CNT_INC;
                }
 
-               //Calculate physical jump address
+               /* Calculate physical jump address */
                if ((frame + 1) == NUM_AUDIO_FRAMES) {
                        risc_phys_jump_addr =
                            dev->_risc_phys_start_addr +
@@ -179,17 +180,17 @@ int cx25821_risc_buffer_upstream_audio(struct cx25821_dev *dev,
                                                       fifo_enable);
 
                if (USE_RISC_NOOP_AUDIO) {
-                       for (i = 0; i < NUM_NO_OPS; i++) {
+                       for (i = 0; i < NUM_NO_OPS; i++)
                                *(rp++) = cpu_to_le32(RISC_NOOP);
-                       }
                }
 
-               // Loop to (Nth)FrameRISC or to Start of Risc program & generate IRQ
+               /* Loop to (Nth)FrameRISC or to Start of Risc program &
+                * generate IRQ */
                *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
                *(rp++) = cpu_to_le32(risc_phys_jump_addr);
                *(rp++) = cpu_to_le32(0);
 
-               //Recalculate virtual address based on frame index
+               /* Recalculate virtual address based on frame index */
                rp = dev->_risc_virt_addr + RISC_SYNC_INSTRUCTION_SIZE / 4 +
                    (AUDIO_RISC_DMA_BUF_SIZE * (frame + 1) / 4);
        }
@@ -220,19 +221,19 @@ void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
        u32 tmp = 0;
 
        if (!dev->_audio_is_running) {
-               printk
-                   ("cx25821: No audio file is currently running so return!\n");
+               printk(KERN_DEBUG
+                   "cx25821: No audio file is currently running so return!\n");
                return;
        }
-       //Disable RISC interrupts
+       /* Disable RISC interrupts */
        cx_write(sram_ch->int_msk, 0);
 
-       //Turn OFF risc and fifo enable in AUD_DMA_CNTRL
+       /* Turn OFF risc and fifo enable in AUD_DMA_CNTRL */
        tmp = cx_read(sram_ch->dma_ctl);
        cx_write(sram_ch->dma_ctl,
                 tmp & ~(sram_ch->fld_aud_fifo_en | sram_ch->fld_aud_risc_en));
 
-       //Clear data buffer memory
+       /* Clear data buffer memory */
        if (dev->_audiodata_buf_virt_addr)
                memset(dev->_audiodata_buf_virt_addr, 0,
                       dev->_audiodata_buf_size);
@@ -253,9 +254,8 @@ void cx25821_stop_upstream_audio(struct cx25821_dev *dev)
 
 void cx25821_free_mem_upstream_audio(struct cx25821_dev *dev)
 {
-       if (dev->_audio_is_running) {
+       if (dev->_audio_is_running)
                cx25821_stop_upstream_audio(dev);
-       }
 
        cx25821_free_memory_audio(dev);
 }
@@ -282,7 +282,7 @@ int cx25821_get_audio_data(struct cx25821_dev *dev,
 
        if (IS_ERR(myfile)) {
                const int open_errno = -PTR_ERR(myfile);
-               printk("%s(): ERROR opening file(%s) with errno = %d! \n",
+               printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
                       __func__, dev->_audiofilename, open_errno);
                return PTR_ERR(myfile);
        } else {
@@ -294,7 +294,7 @@ int cx25821_get_audio_data(struct cx25821_dev *dev,
                }
 
                if (!myfile->f_op->read) {
-                       printk("%s: File has no READ operations registered! \n",
+                       printk("%s: File has no READ operations registered!\n",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
@@ -347,7 +347,7 @@ static void cx25821_audioups_handler(struct work_struct *work)
            container_of(work, struct cx25821_dev, _audio_work_entry);
 
        if (!dev) {
-               printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
+               printk(KERN_ERR "ERROR %s(): since container_of(work_struct) FAILED!\n",
                       __func__);
                return;
        }
@@ -373,19 +373,19 @@ int cx25821_openfile_audio(struct cx25821_dev *dev,
 
        if (IS_ERR(myfile)) {
                const int open_errno = -PTR_ERR(myfile);
-               printk("%s(): ERROR opening file(%s) with errno = %d! \n",
+               printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
                       __func__, dev->_audiofilename, open_errno);
                return PTR_ERR(myfile);
        } else {
                if (!(myfile->f_op)) {
-                       printk("%s: File has no file operations registered! \n",
+                       printk("%s: File has no file operations registered!\n",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
                }
 
                if (!myfile->f_op->read) {
-                       printk("%s: File has no READ operations registered! \n",
+                       printk("%s: File has no READ operations registered!\n",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
@@ -421,13 +421,11 @@ int cx25821_openfile_audio(struct cx25821_dev *dev,
                                }
                        }
 
-                       if (i > 0) {
+                       if (i > 0)
                                dev->_audioframe_count++;
-                       }
 
-                       if (vfs_read_retval < line_size) {
+                       if (vfs_read_retval < line_size)
                                break;
-                       }
                }
 
                dev->_audiofile_status =
@@ -460,14 +458,14 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
        dev->_audiorisc_size = dev->audio_upstream_riscbuf_size;
 
        if (!dev->_risc_virt_addr) {
-               printk
-                   ("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
+               printk(KERN_DEBUG
+                       "cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for RISC program! Returning.\n");
                return -ENOMEM;
        }
-       //Clear out memory at address
+       /* Clear out memory at address */
        memset(dev->_risc_virt_addr, 0, dev->_audiorisc_size);
 
-       //For Audio Data buffer allocation
+       /* For Audio Data buffer allocation */
        dev->_audiodata_buf_virt_addr =
            pci_alloc_consistent(dev->pci, dev->audio_upstream_databuf_size,
                                 &data_dma_addr);
@@ -475,30 +473,30 @@ static int cx25821_audio_upstream_buffer_prepare(struct cx25821_dev *dev,
        dev->_audiodata_buf_size = dev->audio_upstream_databuf_size;
 
        if (!dev->_audiodata_buf_virt_addr) {
-               printk
-                   ("cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning. \n");
+               printk(KERN_DEBUG
+                       "cx25821 ERROR: pci_alloc_consistent() FAILED to allocate memory for data buffer! Returning.\n");
                return -ENOMEM;
        }
-       //Clear out memory at address
+       /* Clear out memory at address */
        memset(dev->_audiodata_buf_virt_addr, 0, dev->_audiodata_buf_size);
 
        ret = cx25821_openfile_audio(dev, sram_ch);
        if (ret < 0)
                return ret;
 
-       //Creating RISC programs
+       /* Creating RISC programs */
        ret =
            cx25821_risc_buffer_upstream_audio(dev, dev->pci, bpl,
                                               dev->_audio_lines_count);
        if (ret < 0) {
                printk(KERN_DEBUG
-                      "cx25821 ERROR creating audio upstream RISC programs! \n");
+                     "cx25821 ERROR creating audio upstream RISC programs!\n");
                goto error;
        }
 
        return 0;
 
-      error:
+error:
        return ret;
 }
 
@@ -512,22 +510,22 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
        __le32 *rp;
 
        if (status & FLD_AUD_SRC_RISCI1) {
-               //Get interrupt_index of the program that interrupted
+               /* Get interrupt_index of the program that interrupted */
                u32 prog_cnt = cx_read(channel->gpcnt);
 
-               //Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers
+               /* Since we've identified our IRQ, clear our bits from the
+                * interrupt mask and interrupt status registers */
                cx_write(channel->int_msk, 0);
                cx_write(channel->int_stat, cx_read(channel->int_stat));
 
                spin_lock(&dev->slock);
 
                while (prog_cnt != dev->_last_index_irq) {
-                       //Update _last_index_irq
-                       if (dev->_last_index_irq < (NUMBER_OF_PROGRAMS - 1)) {
+                       /* Update _last_index_irq */
+                       if (dev->_last_index_irq < (NUMBER_OF_PROGRAMS - 1))
                                dev->_last_index_irq++;
-                       } else {
+                       else
                                dev->_last_index_irq = 0;
-                       }
 
                        dev->_audioframe_index = dev->_last_index_irq;
 
@@ -559,7 +557,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
                                                    cpu_to_le32(RISC_NOOP);
                                        }
                                }
-                               // Jump to 2nd Audio Frame
+                               /* Jump to 2nd Audio Frame */
                                *(rp++) =
                                    cpu_to_le32(RISC_JUMP | RISC_IRQ1 |
                                                RISC_CNT_RESET);
@@ -582,7 +580,8 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
                        printk("%s: Audio Received OpCode Error Interrupt!\n",
                               __func__);
 
-               // Read and write back the interrupt status register to clear our bits
+               /* Read and write back the interrupt status register to clear
+                * our bits */
                cx_write(channel->int_stat, cx_read(channel->int_stat));
        }
 
@@ -591,7 +590,7 @@ int cx25821_audio_upstream_irq(struct cx25821_dev *dev, int chan_num,
                       dev->_audioframe_count);
                return -1;
        }
-       //ElSE, set the interrupt mask register, re-enable irq.
+       /* ElSE, set the interrupt mask register, re-enable irq. */
        int_msk_tmp = cx_read(channel->int_msk);
        cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
 
@@ -613,7 +612,7 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
        msk_stat = cx_read(sram_ch->int_mstat);
        audio_status = cx_read(sram_ch->int_stat);
 
-       // Only deal with our interrupt
+       /* Only deal with our interrupt */
        if (audio_status) {
                handled =
                    cx25821_audio_upstream_irq(dev,
@@ -622,11 +621,10 @@ static irqreturn_t cx25821_upstream_irq_audio(int irq, void *dev_id)
                                               audio_status);
        }
 
-       if (handled < 0) {
+       if (handled < 0)
                cx25821_stop_upstream_audio(dev);
-       } else {
+       else
                handled += handled;
-       }
 
        return IRQ_RETVAL(handled);
 }
@@ -638,13 +636,14 @@ static void cx25821_wait_fifo_enable(struct cx25821_dev *dev,
        u32 tmp;
 
        do {
-               //Wait 10 microsecond before checking to see if the FIFO is turned ON.
+               /* Wait 10 microsecond before checking to see if the FIFO is
+                * turned ON. */
                udelay(10);
 
                tmp = cx_read(sram_ch->dma_ctl);
 
-               if (count++ > 1000)     //10 millisecond timeout
-               {
+               /* 10 millisecond timeout */
+               if (count++ > 1000) {
                        printk
                            ("cx25821 ERROR: %s() fifo is NOT turned on. Timeout!\n",
                             __func__);
@@ -661,31 +660,34 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
        u32 tmp = 0;
        int err = 0;
 
-       // Set the physical start address of the RISC program in the initial program counter(IPC) member of the CMDS.
+       /* Set the physical start address of the RISC program in the initial
+        * program counter(IPC) member of the CMDS. */
        cx_write(sram_ch->cmds_start + 0, dev->_risc_phys_addr);
-       cx_write(sram_ch->cmds_start + 4, 0);   /* Risc IPC High 64 bits 63-32 */
+       /* Risc IPC High 64 bits 63-32 */
+       cx_write(sram_ch->cmds_start + 4, 0);
 
        /* reset counter */
        cx_write(sram_ch->gpcnt_ctl, 3);
 
-       //Set the line length       (It looks like we do not need to set the line length)
+       /* Set the line length       (It looks like we do not need to set the
+        * line length) */
        cx_write(sram_ch->aud_length, AUDIO_LINE_SIZE & FLD_AUD_DST_LN_LNGTH);
 
-       //Set the input mode to 16-bit
+       /* Set the input mode to 16-bit */
        tmp = cx_read(sram_ch->aud_cfg);
        tmp |=
            FLD_AUD_SRC_ENABLE | FLD_AUD_DST_PK_MODE | FLD_AUD_CLK_ENABLE |
            FLD_AUD_MASTER_MODE | FLD_AUD_CLK_SELECT_PLL_D | FLD_AUD_SONY_MODE;
        cx_write(sram_ch->aud_cfg, tmp);
 
-       // Read and write back the interrupt status register to clear it
+       /* Read and write back the interrupt status register to clear it */
        tmp = cx_read(sram_ch->int_stat);
        cx_write(sram_ch->int_stat, tmp);
 
-       // Clear our bits from the interrupt status register.
+       /* Clear our bits from the interrupt status register. */
        cx_write(sram_ch->int_stat, _intr_msk);
 
-       //Set the interrupt mask register, enable irq.
+       /* Set the interrupt mask register, enable irq. */
        cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
        tmp = cx_read(sram_ch->int_msk);
        cx_write(sram_ch->int_msk, tmp |= _intr_msk);
@@ -699,19 +701,19 @@ int cx25821_start_audio_dma_upstream(struct cx25821_dev *dev,
                goto fail_irq;
        }
 
-       // Start the DMA  engine
+       /* Start the DMA  engine */
        tmp = cx_read(sram_ch->dma_ctl);
        cx_set(sram_ch->dma_ctl, tmp | sram_ch->fld_aud_risc_en);
 
        dev->_audio_is_running = 1;
        dev->_is_first_audio_frame = 1;
 
-       // The fifo_en bit turns on by the first Risc program
+       /* The fifo_en bit turns on by the first Risc program */
        cx25821_wait_fifo_enable(dev, sram_ch);
 
        return 0;
 
-      fail_irq:
+fail_irq:
        cx25821_dev_unregister(dev);
        return err;
 }
@@ -731,14 +733,14 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
        dev->_audio_upstream_channel_select = channel_select;
        sram_ch = &dev->sram_channels[channel_select];
 
-       //Work queue
+       /* Work queue */
        INIT_WORK(&dev->_audio_work_entry, cx25821_audioups_handler);
        dev->_irq_audio_queues =
            create_singlethread_workqueue("cx25821_audioworkqueue");
 
        if (!dev->_irq_audio_queues) {
-               printk
-                   ("cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n");
+               printk(KERN_DEBUG
+                       "cx25821 ERROR: create_singlethread_workqueue() for Audio FAILED!\n");
                return -ENOMEM;
        }
 
@@ -760,7 +762,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
                memcpy(dev->_audiofilename, dev->input_audiofilename,
                       str_length + 1);
 
-               //Default if filename is empty string
+               /* Default if filename is empty string */
                if (strcmp(dev->input_audiofilename, "") == 0) {
                        dev->_audiofilename = "/root/audioGOOD.wav";
                }
@@ -784,7 +786,7 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
            RISC_SYNC_INSTRUCTION_SIZE;
        dev->audio_upstream_databuf_size = AUDIO_DATA_BUF_SZ * NUM_AUDIO_PROGS;
 
-       //Allocating buffers and prepare RISC program
+       /* Allocating buffers and prepare RISC program */
        retval =
            cx25821_audio_upstream_buffer_prepare(dev, sram_ch, _line_size);
        if (retval < 0) {
@@ -793,12 +795,12 @@ int cx25821_audio_upstream_init(struct cx25821_dev *dev, int channel_select)
                       dev->name);
                goto error;
        }
-       //Start RISC engine
+       /* Start RISC engine */
        cx25821_start_audio_dma_upstream(dev, sram_ch);
 
        return 0;
 
-      error:
+error:
        cx25821_dev_unregister(dev);
 
        return err;
index e76451c..e49ead9 100644 (file)
@@ -88,10 +88,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -145,7 +145,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO11))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO11))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -163,7 +163,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO11)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -191,19 +191,19 @@ static int video_release(struct file *file)
        //cx_write(channel11->dma_ctl, 0);
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO11)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO11)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO11);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO11);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
 
        file->private_data = NULL;
        kfree(fh);
@@ -224,7 +224,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO11)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO11)))) {
                return -EBUSY;
        }
 
@@ -242,11 +242,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO11);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO11);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -258,13 +258,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -350,7 +350,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
 
        if (fh) {
                dev = fh->dev;
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -364,50 +364,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl_upstream11,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 4d0b9ea..da0f56d 100644 (file)
 #include "cx25821.h"
 #include "tuner-xc2028.h"
 
-// board config info
+/* board config info */
 
 struct cx25821_board cx25821_boards[] = {
        [UNKNOWN_BOARD] = {
                           .name = "UNKNOWN/GENERIC",
-                          // Ensure safe default for unknown boards
+                          /* Ensure safe default for unknown boards */
                           .clk_freq = 0,
                           },
 
index 9e9b8c3..d90abb3 100644 (file)
@@ -32,6 +32,7 @@ MODULE_AUTHOR("Shu Lin - Hiep Huynh");
 MODULE_LICENSE("GPL");
 
 struct list_head cx25821_devlist;
+EXPORT_SYMBOL(cx25821_devlist);
 
 static unsigned int debug;
 module_param(debug, int, 0644);
@@ -313,6 +314,7 @@ struct sram_channel cx25821_sram_channels[] = {
                       .irq_bit = 11,
                       },
 };
+EXPORT_SYMBOL(cx25821_sram_channels);
 
 struct sram_channel *channel0 = &cx25821_sram_channels[SRAM_CH00];
 struct sram_channel *channel1 = &cx25821_sram_channels[SRAM_CH01];
@@ -388,70 +390,74 @@ static void cx25821_registers_init(struct cx25821_dev *dev)
 {
        u32 tmp;
 
-       // enable RUN_RISC in Pecos
+       /* enable RUN_RISC in Pecos */
        cx_write(DEV_CNTRL2, 0x20);
 
-       // Set the master PCI interrupt masks to enable video, audio, MBIF, and GPIO interrupts
-       // I2C interrupt masking is handled by the I2C objects themselves.
+       /* Set the master PCI interrupt masks to enable video, audio, MBIF,
+        * and GPIO interrupts
+        * I2C interrupt masking is handled by the I2C objects themselves. */
        cx_write(PCI_INT_MSK, 0x2001FFFF);
 
        tmp = cx_read(RDR_TLCTL0);
-       tmp &= ~FLD_CFG_RCB_CK_EN;      // Clear the RCB_CK_EN bit
+       tmp &= ~FLD_CFG_RCB_CK_EN;      /* Clear the RCB_CK_EN bit */
        cx_write(RDR_TLCTL0, tmp);
 
-       // PLL-A setting for the Audio Master Clock
+       /* PLL-A setting for the Audio Master Clock */
        cx_write(PLL_A_INT_FRAC, 0x9807A58B);
 
-       // PLL_A_POST = 0x1C, PLL_A_OUT_TO_PIN = 0x1
+       /* PLL_A_POST = 0x1C, PLL_A_OUT_TO_PIN = 0x1 */
        cx_write(PLL_A_POST_STAT_BIST, 0x8000019C);
 
-       // clear reset bit [31]
+       /* clear reset bit [31] */
        tmp = cx_read(PLL_A_INT_FRAC);
        cx_write(PLL_A_INT_FRAC, tmp & 0x7FFFFFFF);
 
-       // PLL-B setting for Mobilygen Host Bus Interface
+       /* PLL-B setting for Mobilygen Host Bus Interface */
        cx_write(PLL_B_INT_FRAC, 0x9883A86F);
 
-       // PLL_B_POST = 0xD, PLL_B_OUT_TO_PIN = 0x0
+       /* PLL_B_POST = 0xD, PLL_B_OUT_TO_PIN = 0x0 */
        cx_write(PLL_B_POST_STAT_BIST, 0x8000018D);
 
-       // clear reset bit [31]
+       /* clear reset bit [31] */
        tmp = cx_read(PLL_B_INT_FRAC);
        cx_write(PLL_B_INT_FRAC, tmp & 0x7FFFFFFF);
 
-       // PLL-C setting for video upstream channel
+       /* PLL-C setting for video upstream channel */
        cx_write(PLL_C_INT_FRAC, 0x96A0EA3F);
 
-       // PLL_C_POST = 0x3, PLL_C_OUT_TO_PIN = 0x0
+       /* PLL_C_POST = 0x3, PLL_C_OUT_TO_PIN = 0x0 */
        cx_write(PLL_C_POST_STAT_BIST, 0x80000103);
 
-       // clear reset bit [31]
+       /* clear reset bit [31] */
        tmp = cx_read(PLL_C_INT_FRAC);
        cx_write(PLL_C_INT_FRAC, tmp & 0x7FFFFFFF);
 
-       // PLL-D setting for audio upstream channel
+       /* PLL-D setting for audio upstream channel */
        cx_write(PLL_D_INT_FRAC, 0x98757F5B);
 
-       // PLL_D_POST = 0x13, PLL_D_OUT_TO_PIN = 0x0
+       /* PLL_D_POST = 0x13, PLL_D_OUT_TO_PIN = 0x0 */
        cx_write(PLL_D_POST_STAT_BIST, 0x80000113);
 
-       // clear reset bit [31]
+       /* clear reset bit [31] */
        tmp = cx_read(PLL_D_INT_FRAC);
        cx_write(PLL_D_INT_FRAC, tmp & 0x7FFFFFFF);
 
-       // This selects the PLL C clock source for the video upstream channel I and J
+       /* This selects the PLL C clock source for the video upstream channel
+        * I and J */
        tmp = cx_read(VID_CH_CLK_SEL);
        cx_write(VID_CH_CLK_SEL, (tmp & 0x00FFFFFF) | 0x24000000);
 
-       // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
-       //select 656/VIP DST for downstream Channel A - C
+       /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
+        * channel A-C
+        * select 656/VIP DST for downstream Channel A - C */
        tmp = cx_read(VID_CH_MODE_SEL);
-       //cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF);
+       /* cx_write( VID_CH_MODE_SEL, tmp | 0x1B0001FF); */
        cx_write(VID_CH_MODE_SEL, tmp & 0xFFFFFE00);
 
-       // enables 656 port I and J as output
+       /* enables 656 port I and J as output */
        tmp = cx_read(CLK_RST);
-       tmp |= FLD_USE_ALT_PLL_REF;     // use external ALT_PLL_REF pin as its reference clock instead
+       /* use external ALT_PLL_REF pin as its reference clock instead */
+       tmp |= FLD_USE_ALT_PLL_REF;
        cx_write(CLK_RST, tmp & ~(FLD_VID_I_CLK_NOE | FLD_VID_J_CLK_NOE));
 
        mdelay(100);
@@ -476,9 +482,8 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
        cdt = ch->cdt;
        lines = ch->fifo_size / bpl;
 
-       if (lines > 4) {
+       if (lines > 4)
                lines = 4;
-       }
 
        BUG_ON(lines < 2);
 
@@ -494,16 +499,15 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
                cx_write(cdt + 16 * i + 12, 0);
        }
 
-       //init the first cdt buffer
+       /* init the first cdt buffer */
        for (i = 0; i < 128; i++)
                cx_write(ch->fifo_start + 4 * i, i);
 
        /* write CMDS */
-       if (ch->jumponly) {
+       if (ch->jumponly)
                cx_write(ch->cmds_start + 0, 8);
-       } else {
+       else
                cx_write(ch->cmds_start + 0, risc);
-       }
 
        cx_write(ch->cmds_start + 4, 0);        /* 64 bits 63-32 */
        cx_write(ch->cmds_start + 8, cdt);
@@ -526,6 +530,7 @@ int cx25821_sram_channel_setup(struct cx25821_dev *dev,
 
        return 0;
 }
+EXPORT_SYMBOL(cx25821_sram_channel_setup);
 
 int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
                                     struct sram_channel *ch,
@@ -546,9 +551,8 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
        cdt = ch->cdt;
        lines = ch->fifo_size / bpl;
 
-       if (lines > 3) {
-               lines = 3;      //for AUDIO
-       }
+       if (lines > 3)
+               lines = 3;      /* for AUDIO */
 
        BUG_ON(lines < 2);
 
@@ -565,25 +569,23 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
        }
 
        /* write CMDS */
-       if (ch->jumponly) {
+       if (ch->jumponly)
                cx_write(ch->cmds_start + 0, 8);
-       } else {
+       else
                cx_write(ch->cmds_start + 0, risc);
-       }
 
        cx_write(ch->cmds_start + 4, 0);        /* 64 bits 63-32 */
        cx_write(ch->cmds_start + 8, cdt);
        cx_write(ch->cmds_start + 12, (lines * 16) >> 3);
        cx_write(ch->cmds_start + 16, ch->ctrl_start);
 
-       //IQ size
-       if (ch->jumponly) {
+       /* IQ size */
+       if (ch->jumponly)
                cx_write(ch->cmds_start + 20, 0x80000000 | (64 >> 2));
-       } else {
+       else
                cx_write(ch->cmds_start + 20, 64 >> 2);
-       }
 
-       //zero out
+       /* zero out */
        for (i = 24; i < 80; i += 4)
                cx_write(ch->cmds_start + i, 0);
 
@@ -595,6 +597,7 @@ int cx25821_sram_channel_setup_audio(struct cx25821_dev *dev,
 
        return 0;
 }
+EXPORT_SYMBOL(cx25821_sram_channel_setup_audio);
 
 void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
 {
@@ -658,6 +661,7 @@ void cx25821_sram_channel_dump(struct cx25821_dev *dev, struct sram_channel *ch)
        printk(KERN_WARNING "        :   cnt2_reg: 0x%08x\n",
               cx_read(ch->cnt2_reg));
 }
+EXPORT_SYMBOL(cx25821_sram_channel_dump);
 
 void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
                                     struct sram_channel *ch)
@@ -731,7 +735,7 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
                printk(KERN_WARNING "instruction %d = 0x%x\n", i, risc);
        }
 
-       //read data from the first cdt buffer
+       /* read data from the first cdt buffer */
        risc = cx_read(AUD_A_CDT);
        printk(KERN_WARNING "\nread cdt loc=0x%x\n", risc);
        for (i = 0; i < 8; i++) {
@@ -741,31 +745,32 @@ void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
        printk(KERN_WARNING "\n\n");
 
        value = cx_read(CLK_RST);
-       CX25821_INFO(" CLK_RST = 0x%x \n\n", value);
+       CX25821_INFO(" CLK_RST = 0x%x\n\n", value);
 
        value = cx_read(PLL_A_POST_STAT_BIST);
-       CX25821_INFO(" PLL_A_POST_STAT_BIST = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_A_POST_STAT_BIST = 0x%x\n\n", value);
        value = cx_read(PLL_A_INT_FRAC);
-       CX25821_INFO(" PLL_A_INT_FRAC = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_A_INT_FRAC = 0x%x\n\n", value);
 
        value = cx_read(PLL_B_POST_STAT_BIST);
-       CX25821_INFO(" PLL_B_POST_STAT_BIST = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_B_POST_STAT_BIST = 0x%x\n\n", value);
        value = cx_read(PLL_B_INT_FRAC);
-       CX25821_INFO(" PLL_B_INT_FRAC = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_B_INT_FRAC = 0x%x\n\n", value);
 
        value = cx_read(PLL_C_POST_STAT_BIST);
-       CX25821_INFO(" PLL_C_POST_STAT_BIST = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_C_POST_STAT_BIST = 0x%x\n\n", value);
        value = cx_read(PLL_C_INT_FRAC);
-       CX25821_INFO(" PLL_C_INT_FRAC = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_C_INT_FRAC = 0x%x\n\n", value);
 
        value = cx_read(PLL_D_POST_STAT_BIST);
-       CX25821_INFO(" PLL_D_POST_STAT_BIST = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_D_POST_STAT_BIST = 0x%x\n\n", value);
        value = cx_read(PLL_D_INT_FRAC);
-       CX25821_INFO(" PLL_D_INT_FRAC = 0x%x \n\n", value);
+       CX25821_INFO(" PLL_D_INT_FRAC = 0x%x\n\n", value);
 
        value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
-       CX25821_INFO(" AFE_AB_DIAG_CTRL (0x10900090) = 0x%x \n\n", value);
+       CX25821_INFO(" AFE_AB_DIAG_CTRL (0x10900090) = 0x%x\n\n", value);
 }
+EXPORT_SYMBOL(cx25821_sram_channel_dump_audio);
 
 static void cx25821_shutdown(struct cx25821_dev *dev)
 {
@@ -835,8 +840,8 @@ static void cx25821_initialize(struct cx25821_dev *dev)
        cx_write(AUD_E_INT_STAT, 0xffffffff);
 
        cx_write(CLK_DELAY, cx_read(CLK_DELAY) & 0x80000000);
-       cx_write(PAD_CTRL, 0x12);       //for I2C
-       cx25821_registers_init(dev);    //init Pecos registers
+       cx_write(PAD_CTRL, 0x12);       /* for I2C */
+       cx25821_registers_init(dev);    /* init Pecos registers */
        mdelay(100);
 
        for (i = 0; i < VID_CHANNEL_NUM; i++) {
@@ -847,7 +852,7 @@ static void cx25821_initialize(struct cx25821_dev *dev)
                dev->use_cif_resolution[i] = FALSE;
        }
 
-       //Probably only affect Downstream
+       /* Probably only affect Downstream */
        for (i = VID_UPSTREAM_SRAM_CHANNEL_I; i <= VID_UPSTREAM_SRAM_CHANNEL_J;
             i++) {
                cx25821_set_vip_mode(dev, &dev->sram_channels[i]);
@@ -859,7 +864,7 @@ static void cx25821_initialize(struct cx25821_dev *dev)
        cx25821_gpio_init(dev);
 }
 
-static int get_resources(struct cx25821_dev *dev)
+static int cx25821_get_resources(struct cx25821_dev *dev)
 {
        if (request_mem_region
            (pci_resource_start(dev->pci, 0), pci_resource_len(dev->pci, 0),
@@ -944,12 +949,11 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
        dev->clk_freq = 28000000;
        dev->sram_channels = cx25821_sram_channels;
 
-       if (dev->nr > 1) {
+       if (dev->nr > 1)
                CX25821_INFO("dev->nr > 1!");
-       }
 
        /* board config */
-       dev->board = 1;         //card[dev->nr];
+       dev->board = 1;         /* card[dev->nr]; */
        dev->_max_num_decoders = MAX_DECODERS;
 
        dev->pci_bus = dev->pci->bus->number;
@@ -967,7 +971,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
        dev->i2c_bus[0].i2c_period = (0x07 << 24);      /* 1.95MHz */
 
 
-       if (get_resources(dev) < 0) {
+       if (cx25821_get_resources(dev) < 0) {
                printk(KERN_ERR "%s No more PCIe resources for "
                       "subsystem: %04x:%04x\n",
                       dev->name, dev->pci->subsystem_vendor,
@@ -1007,8 +1011,8 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
        cx25821_initialize(dev);
 
        cx25821_i2c_register(&dev->i2c_bus[0]);
-//  cx25821_i2c_register(&dev->i2c_bus[1]);
-//  cx25821_i2c_register(&dev->i2c_bus[2]);
+/*  cx25821_i2c_register(&dev->i2c_bus[1]);
+ *  cx25821_i2c_register(&dev->i2c_bus[2]); */
 
        CX25821_INFO("i2c register! bus->i2c_rc = %d\n",
                     dev->i2c_bus[0].i2c_rc);
@@ -1026,7 +1030,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
 
        for (i = VID_UPSTREAM_SRAM_CHANNEL_I;
             i <= AUDIO_UPSTREAM_SRAM_CHANNEL_B; i++) {
-               //Since we don't have template8 for Audio Downstream
+               /* Since we don't have template8 for Audio Downstream */
                if (cx25821_video_register(dev, i, video_template[i - 1]) < 0) {
                        printk(KERN_ERR
                               "%s() Failed to register analog video adapters for Upstream channel %d.\n",
@@ -1034,7 +1038,7 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
                }
        }
 
-       // register IOCTL device
+       /* register IOCTL device */
        dev->ioctl_dev =
            cx25821_vdev_init(dev, dev->pci, video_template[VIDEO_IOCTL_CH],
                              "video");
@@ -1112,6 +1116,7 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
        cx25821_i2c_unregister(&dev->i2c_bus[0]);
        cx25821_iounmap(dev);
 }
+EXPORT_SYMBOL(cx25821_dev_unregister);
 
 static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist,
                                  unsigned int offset, u32 sync_line,
@@ -1122,9 +1127,8 @@ static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist,
        unsigned int line, todo;
 
        /* sync instruction */
-       if (sync_line != NO_SYNC_LINE) {
+       if (sync_line != NO_SYNC_LINE)
                *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
-       }
 
        /* scan lines */
        sg = sglist;
@@ -1299,7 +1303,8 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
        instructions = 1 + (bpl * lines) / PAGE_SIZE + lines;
        instructions += 1;
 
-       if ((rc = btcx_riscmem_alloc(pci, risc, instructions * 12)) < 0)
+       rc = btcx_riscmem_alloc(pci, risc, instructions * 12);
+       if (rc < 0)
                return rc;
 
        /* write risc instructions */
@@ -1312,6 +1317,7 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
        BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size);
        return 0;
 }
+EXPORT_SYMBOL(cx25821_risc_databuffer_audio);
 
 int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
                         u32 reg, u32 mask, u32 value)
@@ -1375,7 +1381,7 @@ static irqreturn_t cx25821_irq(int irq, void *dev_id)
                }
        }
 
-      out:
+out:
        return IRQ_RETVAL(handled);
 }
 
@@ -1399,12 +1405,14 @@ void cx25821_print_irqbits(char *name, char *tag, char **strings,
        }
        printk("\n");
 }
+EXPORT_SYMBOL(cx25821_print_irqbits);
 
 struct cx25821_dev *cx25821_dev_get(struct pci_dev *pci)
 {
        struct cx25821_dev *dev = pci_get_drvdata(pci);
        return dev;
 }
+EXPORT_SYMBOL(cx25821_dev_get);
 
 static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
                                     const struct pci_device_id *pci_id)
@@ -1430,7 +1438,7 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
                goto fail_unregister_device;
        }
 
-       printk(KERN_INFO "cx25821 Athena pci enable ! \n");
+       printk(KERN_INFO "cx25821 Athena pci enable !\n");
 
        if (cx25821_dev_setup(dev) < 0) {
                err = -EINVAL;
@@ -1464,14 +1472,14 @@ static int __devinit cx25821_initdev(struct pci_dev *pci_dev,
 
        return 0;
 
-      fail_irq:
-       printk(KERN_INFO "cx25821 cx25821_initdev() can't get IRQ ! \n");
+fail_irq:
+       printk(KERN_INFO "cx25821 cx25821_initdev() can't get IRQ !\n");
        cx25821_dev_unregister(dev);
 
-      fail_unregister_device:
+fail_unregister_device:
        v4l2_device_unregister(&dev->v4l2_dev);
 
-      fail_free:
+fail_free:
        kfree(dev);
        return err;
 }
@@ -1536,16 +1544,6 @@ static void __exit cx25821_fini(void)
        pci_unregister_driver(&cx25821_pci_driver);
 }
 
-EXPORT_SYMBOL(cx25821_devlist);
-EXPORT_SYMBOL(cx25821_sram_channels);
-EXPORT_SYMBOL(cx25821_print_irqbits);
-EXPORT_SYMBOL(cx25821_dev_get);
-EXPORT_SYMBOL(cx25821_dev_unregister);
-EXPORT_SYMBOL(cx25821_sram_channel_setup);
-EXPORT_SYMBOL(cx25821_sram_channel_dump);
-EXPORT_SYMBOL(cx25821_sram_channel_setup_audio);
-EXPORT_SYMBOL(cx25821_sram_channel_dump_audio);
-EXPORT_SYMBOL(cx25821_risc_databuffer_audio);
 EXPORT_SYMBOL(cx25821_set_gpiopin_direction);
 
 module_init(cx25821_init);
index e8a37b4..2f154b3 100644 (file)
@@ -31,7 +31,7 @@ void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
        u32 gpio_register = 0;
        u32 value = 0;
 
-       // Check for valid pinNumber
+       /* Check for valid pinNumber */
        if (pin_number >= 47)
                return;
 
@@ -39,14 +39,14 @@ void cx25821_set_gpiopin_direction(struct cx25821_dev *dev,
                bit = pin_number - 31;
                gpio_oe_reg = GPIO_HI_OE;
        }
-       // Here we will make sure that the GPIOs 0 and 1 are output. keep the rest as is
+       /* Here we will make sure that the GPIOs 0 and 1 are output. keep the
+        * rest as is */
        gpio_register = cx_read(gpio_oe_reg);
 
-       if (pin_logic_value == 1) {
+       if (pin_logic_value == 1)
                value = gpio_register | Set_GPIO_Bit(bit);
-       } else {
+       else
                value = gpio_register & Clear_GPIO_Bit(bit);
-       }
 
        cx_write(gpio_oe_reg, value);
 }
@@ -58,11 +58,12 @@ static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
        u32 gpio_reg = GPIO_LO;
        u32 value = 0;
 
-       // Check for valid pinNumber
+       /* Check for valid pinNumber */
        if (pin_number >= 47)
                return;
 
-       cx25821_set_gpiopin_direction(dev, pin_number, 0);      // change to output direction
+       /* change to output direction */
+       cx25821_set_gpiopin_direction(dev, pin_number, 0);
 
        if (pin_number > 31) {
                bit = pin_number - 31;
@@ -71,25 +72,23 @@ static void cx25821_set_gpiopin_logicvalue(struct cx25821_dev *dev,
 
        value = cx_read(gpio_reg);
 
-       if (pin_logic_value == 0) {
+       if (pin_logic_value == 0)
                value &= Clear_GPIO_Bit(bit);
-       } else {
+       else
                value |= Set_GPIO_Bit(bit);
-       }
 
        cx_write(gpio_reg, value);
 }
 
 void cx25821_gpio_init(struct cx25821_dev *dev)
 {
-       if (dev == NULL) {
+       if (dev == NULL)
                return;
-       }
 
        switch (dev->board) {
        case CX25821_BOARD_CONEXANT_ATHENA10:
        default:
-               //set GPIO 5 to select the path for Medusa/Athena
+               /* set GPIO 5 to select the path for Medusa/Athena */
                cx25821_set_gpiopin_logicvalue(dev, 5, 1);
                mdelay(20);
                break;
index f4f2681..08f45b5 100644 (file)
@@ -28,7 +28,7 @@ static unsigned int i2c_debug;
 module_param(i2c_debug, int, 0644);
 MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
 
-static unsigned int i2c_scan = 0;
+static unsigned int i2c_scan;
 module_param(i2c_scan, int, 0444);
 MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
 
@@ -159,9 +159,9 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
 
        return msg->len;
 
-      eio:
+eio:
        retval = -EIO;
-      err:
+err:
        if (i2c_debug)
                printk(KERN_ERR " ERR: %d\n", retval);
        return retval;
@@ -223,9 +223,9 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
        }
 
        return msg->len;
-      eio:
+eio:
        retval = -EIO;
-      err:
+err:
        if (i2c_debug)
                printk(KERN_ERR " ERR: %d\n", retval);
        return retval;
@@ -266,7 +266,7 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
        }
        return num;
 
-      err:
+err:
        return retval;
 }
 
@@ -319,7 +319,7 @@ int cx25821_i2c_register(struct cx25821_i2c *bus)
 
        bus->i2c_client.adapter = &bus->i2c_adap;
 
-       //set up the I2c
+       /* set up the I2c */
        bus->i2c_client.addr = (0x88 >> 1);
 
        return bus->i2c_rc;
index d601620..34616dc 100644 (file)
 #include "cx25821-medusa-video.h"
 #include "cx25821-biffuncs.h"
 
-/////////////////////////////////////////////////////////////////////////////////////////
-//medusa_enable_bluefield_output()
-//
-// Enable the generation of blue filed output if no video
-//
+/*
+ * medusa_enable_bluefield_output()
+ *
+ * Enable the generation of blue filed output if no video
+ *
+ */
 static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel,
                                           int enable)
 {
@@ -73,15 +74,15 @@ static void medusa_enable_bluefield_output(struct cx25821_dev *dev, int channel,
        }
 
        value = cx25821_i2c_read(&dev->i2c_bus[0], out_ctrl, &tmp);
-       value &= 0xFFFFFF7F;    // clear BLUE_FIELD_EN
+       value &= 0xFFFFFF7F;    /* clear BLUE_FIELD_EN */
        if (enable)
-               value |= 0x00000080;    // set BLUE_FIELD_EN
+               value |= 0x00000080;    /* set BLUE_FIELD_EN */
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl, value);
 
        value = cx25821_i2c_read(&dev->i2c_bus[0], out_ctrl_ns, &tmp);
        value &= 0xFFFFFF7F;
        if (enable)
-               value |= 0x00000080;    // set BLUE_FIELD_EN
+               value |= 0x00000080;    /* set BLUE_FIELD_EN */
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], out_ctrl_ns, value);
 }
 
@@ -95,17 +96,18 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
        mutex_lock(&dev->lock);
 
        for (i = 0; i < MAX_DECODERS; i++) {
-               // set video format NTSC-M
+               /* set video format NTSC-M */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
                                     &tmp);
                value &= 0xFFFFFFF0;
-               value |= 0x10001;       // enable the fast locking mode bit[16]
+               /* enable the fast locking mode bit[16] */
+               value |= 0x10001;
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
                                      value);
 
-               // resolution NTSC 720x480
+               /* resolution NTSC 720x480 */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     HORIZ_TIM_CTRL + (0x200 * i), &tmp);
@@ -119,17 +121,17 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     VERT_TIM_CTRL + (0x200 * i), &tmp);
                value &= 0x00C00C00;
-               value |= 0x1C1E001A;    // vblank_cnt + 2 to get camera ID
+               value |= 0x1C1E001A;    /* vblank_cnt + 2 to get camera ID */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      VERT_TIM_CTRL + (0x200 * i), value);
 
-               // chroma subcarrier step size
+               /* chroma subcarrier step size */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      SC_STEP_SIZE + (0x200 * i), 0x43E00000);
 
-               // enable VIP optional active
+               /* enable VIP optional active */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     OUT_CTRL_NS + (0x200 * i), &tmp);
@@ -139,7 +141,7 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      OUT_CTRL_NS + (0x200 * i), value);
 
-               // enable VIP optional active (VIP_OPT_AL) for direct output.
+               /* enable VIP optional active (VIP_OPT_AL) for direct output. */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
                                     &tmp);
@@ -149,19 +151,21 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
                                      value);
 
-               // clear VPRES_VERT_EN bit, fixes the chroma run away problem
-               // when the input switching rate < 16 fields
-               //
+               /*
+                * clear VPRES_VERT_EN bit, fixes the chroma run away problem
+                * when the input switching rate < 16 fields
+               */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     MISC_TIM_CTRL + (0x200 * i), &tmp);
-               value = setBitAtPos(value, 14); // disable special play detection
+               /* disable special play detection */
+               value = setBitAtPos(value, 14);
                value = clearBitAtPos(value, 15);
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      MISC_TIM_CTRL + (0x200 * i), value);
 
-               // set vbi_gate_en to 0
+               /* set vbi_gate_en to 0 */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
                                     &tmp);
@@ -170,12 +174,12 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
                                      value);
 
-               // Enable the generation of blue field output if no video
+               /* Enable the generation of blue field output if no video */
                medusa_enable_bluefield_output(dev, i, 1);
        }
 
        for (i = 0; i < MAX_ENCODERS; i++) {
-               // NTSC hclock
+               /* NTSC hclock */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_1 + (0x100 * i), &tmp);
@@ -185,7 +189,7 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_1 + (0x100 * i), value);
 
-               // burst begin and burst end
+               /* burst begin and burst end */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_2 + (0x100 * i), &tmp);
@@ -204,7 +208,7 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_3 + (0x100 * i), value);
 
-               // set NTSC vblank, no phase alternation, 7.5 IRE pedestal
+               /* set NTSC vblank, no phase alternation, 7.5 IRE pedestal */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_4 + (0x100 * i), &tmp);
@@ -227,17 +231,19 @@ static int medusa_initialize_ntsc(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_6 + (0x100 * i), 0x009A89C1);
 
-               // Subcarrier Increment
+               /* Subcarrier Increment */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_7 + (0x100 * i), 0x21F07C1F);
        }
 
-       //set picture resolutions
-       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0);        //0 - 720
-       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0);        //0 - 480
+       /* set picture resolutions */
+       /* 0 - 720 */
+       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0);
+       /* 0 - 480 */
+       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0);
 
-       // set Bypass input format to NTSC 525 lines
+       /* set Bypass input format to NTSC 525 lines */
        value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp);
        value |= 0x00080200;
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
@@ -252,7 +258,7 @@ static int medusa_PALCombInit(struct cx25821_dev *dev, int dec)
        int ret_val = -1;
        u32 value = 0, tmp = 0;
 
-       // Setup for 2D threshold
+       /* Setup for 2D threshold */
        ret_val =
            cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_HFS_CFG + (0x200 * dec),
                              0x20002861);
@@ -263,7 +269,7 @@ static int medusa_PALCombInit(struct cx25821_dev *dev, int dec)
            cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_LF_CFG + (0x200 * dec),
                              0x200A1023);
 
-       // Setup flat chroma and luma thresholds
+       /* Setup flat chroma and luma thresholds */
        value =
            cx25821_i2c_read(&dev->i2c_bus[0],
                             COMB_FLAT_THRESH_CTRL + (0x200 * dec), &tmp);
@@ -272,12 +278,12 @@ static int medusa_PALCombInit(struct cx25821_dev *dev, int dec)
            cx25821_i2c_write(&dev->i2c_bus[0],
                              COMB_FLAT_THRESH_CTRL + (0x200 * dec), value);
 
-       // set comb 2D blend
+       /* set comb 2D blend */
        ret_val =
            cx25821_i2c_write(&dev->i2c_bus[0], COMB_2D_BLEND + (0x200 * dec),
                              0x210F0F0F);
 
-       // COMB MISC CONTROL
+       /* COMB MISC CONTROL */
        ret_val =
            cx25821_i2c_write(&dev->i2c_bus[0], COMB_MISC_CTRL + (0x200 * dec),
                              0x41120A7F);
@@ -295,17 +301,18 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
        mutex_lock(&dev->lock);
 
        for (i = 0; i < MAX_DECODERS; i++) {
-               // set video format PAL-BDGHI
+               /* set video format PAL-BDGHI */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
                                     &tmp);
                value &= 0xFFFFFFF0;
-               value |= 0x10004;       // enable the fast locking mode bit[16]
+               /* enable the fast locking mode bit[16] */
+               value |= 0x10004;
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0], MODE_CTRL + (0x200 * i),
                                      value);
 
-               // resolution PAL 720x576
+               /* resolution PAL 720x576 */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     HORIZ_TIM_CTRL + (0x200 * i), &tmp);
@@ -315,22 +322,22 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      HORIZ_TIM_CTRL + (0x200 * i), value);
 
-               // vblank656_cnt=x26, vactive_cnt=240h, vblank_cnt=x24
+               /* vblank656_cnt=x26, vactive_cnt=240h, vblank_cnt=x24 */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     VERT_TIM_CTRL + (0x200 * i), &tmp);
                value &= 0x00C00C00;
-               value |= 0x28240026;    // vblank_cnt + 2 to get camera ID
+               value |= 0x28240026;    /* vblank_cnt + 2 to get camera ID */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      VERT_TIM_CTRL + (0x200 * i), value);
 
-               // chroma subcarrier step size
+               /* chroma subcarrier step size */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      SC_STEP_SIZE + (0x200 * i), 0x5411E2D0);
 
-               // enable VIP optional active
+               /* enable VIP optional active */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     OUT_CTRL_NS + (0x200 * i), &tmp);
@@ -340,7 +347,7 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      OUT_CTRL_NS + (0x200 * i), value);
 
-               // enable VIP optional active (VIP_OPT_AL) for direct output.
+               /* enable VIP optional active (VIP_OPT_AL) for direct output. */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
                                     &tmp);
@@ -350,18 +357,21 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0], OUT_CTRL1 + (0x200 * i),
                                      value);
 
-               // clear VPRES_VERT_EN bit, fixes the chroma run away problem
-               // when the input switching rate < 16 fields
+               /*
+                * clear VPRES_VERT_EN bit, fixes the chroma run away problem
+                * when the input switching rate < 16 fields
+                */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     MISC_TIM_CTRL + (0x200 * i), &tmp);
-               value = setBitAtPos(value, 14); // disable special play detection
+               /* disable special play detection */
+               value = setBitAtPos(value, 14);
                value = clearBitAtPos(value, 15);
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      MISC_TIM_CTRL + (0x200 * i), value);
 
-               // set vbi_gate_en to 0
+               /* set vbi_gate_en to 0 */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0], DFE_CTRL1 + (0x200 * i),
                                     &tmp);
@@ -372,12 +382,12 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
 
                medusa_PALCombInit(dev, i);
 
-               // Enable the generation of blue field output if no video
+               /* Enable the generation of blue field output if no video */
                medusa_enable_bluefield_output(dev, i, 1);
        }
 
        for (i = 0; i < MAX_ENCODERS; i++) {
-               // PAL hclock
+               /* PAL hclock */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_1 + (0x100 * i), &tmp);
@@ -387,7 +397,7 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_1 + (0x100 * i), value);
 
-               // burst begin and burst end
+               /* burst begin and burst end */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_2 + (0x100 * i), &tmp);
@@ -397,7 +407,7 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_2 + (0x100 * i), value);
 
-               // hblank and vactive
+               /* hblank and vactive */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_3 + (0x100 * i), &tmp);
@@ -407,7 +417,7 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_3 + (0x100 * i), value);
 
-               // set PAL vblank, phase alternation, 0 IRE pedestal
+               /* set PAL vblank, phase alternation, 0 IRE pedestal */
                value =
                    cx25821_i2c_read(&dev->i2c_bus[0],
                                     DENC_A_REG_4 + (0x100 * i), &tmp);
@@ -430,17 +440,19 @@ static int medusa_initialize_pal(struct cx25821_dev *dev)
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_6 + (0x100 * i), 0x00A493CF);
 
-               // Subcarrier Increment
+               /* Subcarrier Increment */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      DENC_A_REG_7 + (0x100 * i), 0x2A098ACB);
        }
 
-       //set picture resolutions
-       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0);        //0 - 720
-       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0);        //0 - 576
+       /* set picture resolutions */
+       /* 0 - 720 */
+       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], HSCALE_CTRL, 0x0);
+       /* 0 - 576 */
+       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], VSCALE_CTRL, 0x0);
 
-       // set Bypass input format to PAL 625 lines
+       /* set Bypass input format to PAL 625 lines */
        value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp);
        value &= 0xFFF7FDFF;
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
@@ -455,18 +467,17 @@ int medusa_set_videostandard(struct cx25821_dev *dev)
        int status = STATUS_SUCCESS;
        u32 value = 0, tmp = 0;
 
-       if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK) {
+       if (dev->tvnorm & V4L2_STD_PAL_BG || dev->tvnorm & V4L2_STD_PAL_DK)
                status = medusa_initialize_pal(dev);
-       } else {
+       else
                status = medusa_initialize_ntsc(dev);
-       }
 
-       // Enable DENC_A output
+       /* Enable DENC_A output */
        value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_A_REG_4, &tmp);
        value = setBitAtPos(value, 4);
        status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_A_REG_4, value);
 
-       // Enable DENC_B output
+       /* Enable DENC_B output */
        value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_B_REG_4, &tmp);
        value = setBitAtPos(value, 4);
        status = cx25821_i2c_write(&dev->i2c_bus[0], DENC_B_REG_4, value);
@@ -486,10 +497,10 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
 
        mutex_lock(&dev->lock);
 
-       // validate the width - cannot be negative
+       /* validate the width - cannot be negative */
        if (width > MAX_WIDTH) {
                printk
-                   ("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH \n",
+                   ("cx25821 %s() : width %d > MAX_WIDTH %d ! resetting to MAX_WIDTH\n",
                     __func__, width, MAX_WIDTH);
                width = MAX_WIDTH;
        }
@@ -523,14 +534,14 @@ void medusa_set_resolution(struct cx25821_dev *dev, int width,
                vscale = 0x1E00;
                break;
 
-       default:                //720
+       default:                /* 720 */
                hscale = 0x0;
                vscale = 0x0;
                break;
        }
 
        for (; decoder < decoder_count; decoder++) {
-               // write scaling values for each decoder
+               /* write scaling values for each decoder */
                ret_val =
                    cx25821_i2c_write(&dev->i2c_bus[0],
                                      HSCALE_CTRL + (0x200 * decoder), hscale);
@@ -552,7 +563,7 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
 
        mutex_lock(&dev->lock);
 
-       // no support
+       /* no support */
        if (decoder < VDEC_A && decoder > VDEC_H) {
                mutex_unlock(&dev->lock);
                return;
@@ -577,11 +588,10 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
 
        _display_field_cnt[decoder] = duration;
 
-       // update hardware
+       /* update hardware */
        fld_cnt = cx25821_i2c_read(&dev->i2c_bus[0], disp_cnt_reg, &tmp);
 
-       if (!(decoder % 2))     // EVEN decoder
-       {
+       if (!(decoder % 2)) {   /* EVEN decoder */
                fld_cnt &= 0xFFFF0000;
                fld_cnt |= duration;
        } else {
@@ -594,8 +604,7 @@ static void medusa_set_decoderduration(struct cx25821_dev *dev, int decoder,
        mutex_unlock(&dev->lock);
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
-// Map to Medusa register setting
+/* Map to Medusa register setting */
 static int mapM(int srcMin,
                int srcMax, int srcVal, int dstMin, int dstMax, int *dstVal)
 {
@@ -603,20 +612,21 @@ static int mapM(int srcMin,
        int denominator;
        int quotient;
 
-       if ((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax)) {
+       if ((srcMin == srcMax) || (srcVal < srcMin) || (srcVal > srcMax))
                return -1;
-       }
-       // This is the overall expression used:
-       // *dstVal = (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin;
-       // but we need to account for rounding so below we use the modulus
-       // operator to find the remainder and increment if necessary.
+       /*
+        * This is the overall expression used:
+        * *dstVal =
+        *   (srcVal - srcMin)*(dstMax - dstMin) / (srcMax - srcMin) + dstMin;
+        * but we need to account for rounding so below we use the modulus
+        * operator to find the remainder and increment if necessary.
+        */
        numerator = (srcVal - srcMin) * (dstMax - dstMin);
        denominator = srcMax - srcMin;
        quotient = numerator / denominator;
 
-       if (2 * (numerator % denominator) >= denominator) {
+       if (2 * (numerator % denominator) >= denominator)
                quotient++;
-       }
 
        *dstVal = quotient + dstMin;
 
@@ -636,7 +646,6 @@ static unsigned long convert_to_twos(long numeric, unsigned long bits_len)
        }
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
 int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
 {
        int ret_val = 0;
@@ -665,7 +674,6 @@ int medusa_set_brightness(struct cx25821_dev *dev, int brightness, int decoder)
        return ret_val;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
 int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
 {
        int ret_val = 0;
@@ -695,7 +703,6 @@ int medusa_set_contrast(struct cx25821_dev *dev, int contrast, int decoder)
        return ret_val;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
 int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
 {
        int ret_val = 0;
@@ -727,7 +734,6 @@ int medusa_set_hue(struct cx25821_dev *dev, int hue, int decoder)
        return ret_val;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
 int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
 {
        int ret_val = 0;
@@ -768,98 +774,90 @@ int medusa_set_saturation(struct cx25821_dev *dev, int saturation, int decoder)
        return ret_val;
 }
 
-/////////////////////////////////////////////////////////////////////////////////////////
-// Program the display sequence and monitor output.
-//
+/* Program the display sequence and monitor output. */
+
 int medusa_video_init(struct cx25821_dev *dev)
 {
-       u32 value = 0, tmp = 0;
-       int ret_val = 0;
-       int i = 0;
+       u32 value, tmp = 0;
+       int ret_val;
+       int i;
 
        mutex_lock(&dev->lock);
 
        _num_decoders = dev->_max_num_decoders;
 
-       // disable Auto source selection on all video decoders
+       /* disable Auto source selection on all video decoders */
        value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
        value &= 0xFFFFF0FF;
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
+       if (ret_val < 0)
+               goto error;
 
-       if (ret_val < 0) {
-               mutex_unlock(&dev->lock);
-               return -EINVAL;
-       }
-       // Turn off Master source switch enable
+       /* Turn off Master source switch enable */
        value = cx25821_i2c_read(&dev->i2c_bus[0], MON_A_CTRL, &tmp);
        value &= 0xFFFFFFDF;
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], MON_A_CTRL, value);
-
        if (ret_val < 0)
-               return -EINVAL;
+               goto error;
 
        mutex_unlock(&dev->lock);
 
-       for (i = 0; i < _num_decoders; i++) {
+       for (i = 0; i < _num_decoders; i++)
                medusa_set_decoderduration(dev, i, _display_field_cnt[i]);
-       }
 
        mutex_lock(&dev->lock);
 
-       // Select monitor as DENC A input, power up the DAC
+       /* Select monitor as DENC A input, power up the DAC */
        value = cx25821_i2c_read(&dev->i2c_bus[0], DENC_AB_CTRL, &tmp);
        value &= 0xFF70FF70;
-       value |= 0x00090008;    // set en_active
+       value |= 0x00090008;    /* set en_active */
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], DENC_AB_CTRL, value);
+       if (ret_val < 0)
+               goto error;
 
-       if (ret_val < 0) {
-               mutex_unlock(&dev->lock);
-               return -EINVAL;
-       }
-       // enable input is VIP/656
+       /* enable input is VIP/656 */
        value = cx25821_i2c_read(&dev->i2c_bus[0], BYP_AB_CTRL, &tmp);
-       value |= 0x00040100;    // enable VIP
+       value |= 0x00040100;    /* enable VIP */
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], BYP_AB_CTRL, value);
 
-       if (ret_val < 0) {
-               mutex_unlock(&dev->lock);
-               return -EINVAL;
-       }
-       // select AFE clock to output mode
+       if (ret_val < 0)
+               goto error;
+
+       /* select AFE clock to output mode */
        value = cx25821_i2c_read(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL, &tmp);
        value &= 0x83FFFFFF;
-       ret_val =
-           cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL,
-                             value | 0x10000000);
+       ret_val = cx25821_i2c_write(&dev->i2c_bus[0], AFE_AB_DIAG_CTRL,
+                                   value | 0x10000000);
+       if (ret_val < 0)
+               goto error;
 
-       if (ret_val < 0) {
-               mutex_unlock(&dev->lock);
-               return -EINVAL;
-       }
-       // Turn on all of the data out and control output pins.
+       /* Turn on all of the data out and control output pins. */
        value = cx25821_i2c_read(&dev->i2c_bus[0], PIN_OE_CTRL, &tmp);
        value &= 0xFEF0FE00;
        if (_num_decoders == MAX_DECODERS) {
-               // Note: The octal board does not support control pins(bit16-19).
-               // These bits are ignored in the octal board.
-               value |= 0x010001F8;    // disable VDEC A-C port, default to Mobilygen Interface
+               /*
+                * Note: The octal board does not support control pins(bit16-19)
+                * These bits are ignored in the octal board.
+                *
+                * disable VDEC A-C port, default to Mobilygen Interface
+                */
+               value |= 0x010001F8;
        } else {
-               value |= 0x010F0108;    // disable VDEC A-C port, default to Mobilygen Interface
+               /* disable VDEC A-C port, default to Mobilygen Interface */
+               value |= 0x010F0108;
        }
 
        value |= 7;
        ret_val = cx25821_i2c_write(&dev->i2c_bus[0], PIN_OE_CTRL, value);
-       if (ret_val < 0) {
-               mutex_unlock(&dev->lock);
-               return -EINVAL;
-       }
+       if (ret_val < 0)
+               goto error;
 
        mutex_unlock(&dev->lock);
 
        ret_val = medusa_set_videostandard(dev);
+       return ret_val;
 
-       if (ret_val < 0)
-               return -EINVAL;
-
-       return 1;
+error:
+       mutex_unlock(&dev->lock);
+       return ret_val;
 }
index 6d48a1e..c842d8f 100644 (file)
@@ -32,7 +32,7 @@
 #include <linux/file.h>
 #include <linux/fcntl.h>
 #include <linux/slab.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 
 MODULE_DESCRIPTION("v4l2 driver module for cx25821 based TV cards");
 MODULE_AUTHOR("Hiep Huynh <hiep.huynh@conexant.com>");
@@ -60,9 +60,8 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
        cdt = ch->cdt;
        lines = ch->fifo_size / bpl;
 
-       if (lines > 4) {
+       if (lines > 4)
                lines = 4;
-       }
 
        BUG_ON(lines < 2);
 
@@ -97,7 +96,7 @@ int cx25821_sram_channel_setup_upstream(struct cx25821_dev *dev,
 }
 
 static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
-                                         __le32 * rp, unsigned int offset,
+                                         __le32 *rp, unsigned int offset,
                                          unsigned int bpl, u32 sync_line,
                                          unsigned int lines, int fifo_enable,
                                          int field_type)
@@ -108,9 +107,8 @@ static __le32 *cx25821_update_riscprogram(struct cx25821_dev *dev,
        *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
 
        if (USE_RISC_NOOP_VIDEO) {
-               for (i = 0; i < NUM_NO_OPS; i++) {
+               for (i = 0; i < NUM_NO_OPS; i++)
                        *(rp++) = cpu_to_le32(RISC_NOOP);
-               }
        }
 
        /* scan lines */
@@ -140,14 +138,12 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
        int dist_betwn_starts = bpl * 2;
 
        /* sync instruction */
-       if (sync_line != NO_SYNC_LINE) {
+       if (sync_line != NO_SYNC_LINE)
                *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
-       }
 
        if (USE_RISC_NOOP_VIDEO) {
-               for (i = 0; i < NUM_NO_OPS; i++) {
+               for (i = 0; i < NUM_NO_OPS; i++)
                        *(rp++) = cpu_to_le32(RISC_NOOP);
-               }
        }
 
        /* scan lines */
@@ -157,12 +153,13 @@ static __le32 *cx25821_risc_field_upstream(struct cx25821_dev *dev, __le32 * rp,
                *(rp++) = cpu_to_le32(0);       /* bits 63-32 */
 
                if ((lines <= NTSC_FIELD_HEIGHT)
-                   || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC)) {
-                       offset += dist_betwn_starts;    //to skip the other field line
-               }
+                   || (line < (NTSC_FIELD_HEIGHT - 1)) || !(dev->_isNTSC))
+                       /* to skip the other field line */
+                       offset += dist_betwn_starts;
 
-               // check if we need to enable the FIFO after the first 4 lines
-               // For the upstream video channel, the risc engine will enable the FIFO.
+               /* check if we need to enable the FIFO after the first 4 lines
+                * For the upstream video channel, the risc engine will enable
+                * the FIFO. */
                if (fifo_enable && line == 3) {
                        *(rp++) = RISC_WRITECR;
                        *(rp++) = sram_ch->dma_ctl;
@@ -181,7 +178,8 @@ int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
 {
        __le32 *rp;
        int fifo_enable = 0;
-       int singlefield_lines = lines >> 1;     //get line count for single field
+       /* get line count for single field */
+       int singlefield_lines = lines >> 1;
        int odd_num_lines = singlefield_lines;
        int frame = 0;
        int frame_size = 0;
@@ -225,7 +223,7 @@ int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
 
                fifo_enable = FIFO_DISABLE;
 
-               //Even Field
+               /* Even Field */
                rp = cx25821_risc_field_upstream(dev, rp,
                                                 dev->_data_buf_phys_addr +
                                                 databuf_offset, bottom_offset,
@@ -241,7 +239,9 @@ int cx25821_risc_buffer_upstream(struct cx25821_dev *dev,
                        risc_flag = RISC_CNT_INC;
                }
 
-               // Loop to 2ndFrameRISC or to Start of Risc program & generate IRQ
+               /* Loop to 2ndFrameRISC or to Start of Risc
+                * program & generate IRQ
+                */
                *(rp++) = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | risc_flag);
                *(rp++) = cpu_to_le32(risc_phys_jump_addr);
                *(rp++) = cpu_to_le32(0);
@@ -258,18 +258,18 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
 
        if (!dev->_is_running) {
                printk
-                   ("cx25821: No video file is currently running so return!\n");
+                  (KERN_INFO "cx25821: No video file is currently running so return!\n");
                return;
        }
-       //Disable RISC interrupts
+       /* Disable RISC interrupts */
        tmp = cx_read(sram_ch->int_msk);
        cx_write(sram_ch->int_msk, tmp & ~_intr_msk);
 
-       //Turn OFF risc and fifo enable
+       /* Turn OFF risc and fifo enable */
        tmp = cx_read(sram_ch->dma_ctl);
        cx_write(sram_ch->dma_ctl, tmp & ~(FLD_VID_FIFO_EN | FLD_VID_RISC_EN));
 
-       //Clear data buffer memory
+       /* Clear data buffer memory */
        if (dev->_data_buf_virt_addr)
                memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size);
 
@@ -292,9 +292,8 @@ void cx25821_stop_upstream_video_ch1(struct cx25821_dev *dev)
 
 void cx25821_free_mem_upstream_ch1(struct cx25821_dev *dev)
 {
-       if (dev->_is_running) {
+       if (dev->_is_running)
                cx25821_stop_upstream_video_ch1(dev);
-       }
 
        if (dev->_dma_virt_addr) {
                pci_free_consistent(dev->pci, dev->_risc_size,
@@ -347,19 +346,19 @@ int cx25821_get_frame(struct cx25821_dev *dev, struct sram_channel *sram_ch)
 
        if (IS_ERR(myfile)) {
                const int open_errno = -PTR_ERR(myfile);
-               printk("%s(): ERROR opening file(%s) with errno = %d! \n",
+               printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
                       __func__, dev->_filename, open_errno);
                return PTR_ERR(myfile);
        } else {
                if (!(myfile->f_op)) {
-                       printk("%s: File has no file operations registered!",
+                       printk(KERN_ERR "%s: File has no file operations registered!",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
                }
 
                if (!myfile->f_op->read) {
-                       printk("%s: File has no READ operations registered!",
+                       printk(KERN_ERR "%s: File has no READ operations registered!",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
@@ -412,7 +411,7 @@ static void cx25821_vidups_handler(struct work_struct *work)
            container_of(work, struct cx25821_dev, _irq_work_entry);
 
        if (!dev) {
-               printk("ERROR %s(): since container_of(work_struct) FAILED! \n",
+               printk(KERN_ERR "ERROR %s(): since container_of(work_struct) FAILED!\n",
                       __func__);
                return;
        }
@@ -438,12 +437,12 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
 
        if (IS_ERR(myfile)) {
                const int open_errno = -PTR_ERR(myfile);
-               printk("%s(): ERROR opening file(%s) with errno = %d! \n",
+               printk(KERN_ERR "%s(): ERROR opening file(%s) with errno = %d!\n",
                       __func__, dev->_filename, open_errno);
                return PTR_ERR(myfile);
        } else {
                if (!(myfile->f_op)) {
-                       printk("%s: File has no file operations registered!",
+                       printk(KERN_ERR "%s: File has no file operations registered!",
                               __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
@@ -451,7 +450,7 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
 
                if (!myfile->f_op->read) {
                        printk
-                           ("%s: File has no READ operations registered!  Returning.",
+                           (KERN_ERR "%s: File has no READ operations registered!  Returning.",
                             __func__);
                        filp_close(myfile, NULL);
                        return -EIO;
@@ -490,9 +489,8 @@ int cx25821_openfile(struct cx25821_dev *dev, struct sram_channel *sram_ch)
                        if (i > 0)
                                dev->_frame_count++;
 
-                       if (vfs_read_retval < line_size) {
+                       if (vfs_read_retval < line_size)
                                break;
-                       }
                }
 
                dev->_file_status =
@@ -528,11 +526,11 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
 
        if (!dev->_dma_virt_addr) {
                printk
-                   ("cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
+                   (KERN_ERR "cx25821: FAILED to allocate memory for Risc buffer! Returning.\n");
                return -ENOMEM;
        }
 
-       //Clear memory at address
+       /* Clear memory at address */
        memset(dev->_dma_virt_addr, 0, dev->_risc_size);
 
        if (dev->_data_buf_virt_addr != NULL) {
@@ -540,7 +538,7 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
                                    dev->_data_buf_virt_addr,
                                    dev->_data_buf_phys_addr);
        }
-       //For Video Data buffer allocation
+       /* For Video Data buffer allocation */
        dev->_data_buf_virt_addr =
            pci_alloc_consistent(dev->pci, dev->upstream_databuf_size,
                                 &data_dma_addr);
@@ -549,30 +547,30 @@ int cx25821_upstream_buffer_prepare(struct cx25821_dev *dev,
 
        if (!dev->_data_buf_virt_addr) {
                printk
-                   ("cx25821: FAILED to allocate memory for data buffer! Returning.\n");
+                   (KERN_ERR "cx25821: FAILED to allocate memory for data buffer! Returning.\n");
                return -ENOMEM;
        }
 
-       //Clear memory at address
+       /* Clear memory at address */
        memset(dev->_data_buf_virt_addr, 0, dev->_data_buf_size);
 
        ret = cx25821_openfile(dev, sram_ch);
        if (ret < 0)
                return ret;
 
-       //Create RISC programs
+       /* Create RISC programs */
        ret =
            cx25821_risc_buffer_upstream(dev, dev->pci, 0, bpl,
                                         dev->_lines_count);
        if (ret < 0) {
                printk(KERN_INFO
-                      "cx25821: Failed creating Video Upstream Risc programs! \n");
+                   "cx25821: Failed creating Video Upstream Risc programs!\n");
                goto error;
        }
 
        return 0;
 
-      error:
+error:
        return ret;
 }
 
@@ -588,10 +586,11 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
        __le32 *rp;
 
        if (status & FLD_VID_SRC_RISC1) {
-               // We should only process one program per call
+               /* We should only process one program per call */
                u32 prog_cnt = cx_read(channel->gpcnt);
 
-               //Since we've identified our IRQ, clear our bits from the interrupt mask and interrupt status registers
+               /* Since we've identified our IRQ, clear our bits from the
+                * interrupt mask and interrupt status registers */
                int_msk_tmp = cx_read(channel->int_msk);
                cx_write(channel->int_msk, int_msk_tmp & ~_intr_msk);
                cx_write(channel->int_stat, _intr_msk);
@@ -632,7 +631,7 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
                                                                FIFO_DISABLE,
                                                                ODD_FIELD);
 
-                               // Jump to Even Risc program of 1st Frame
+                               /* Jump to Even Risc program of 1st Frame */
                                *(rp++) = cpu_to_le32(RISC_JUMP);
                                *(rp++) = cpu_to_le32(risc_phys_jump_addr);
                                *(rp++) = cpu_to_le32(0);
@@ -643,24 +642,24 @@ int cx25821_video_upstream_irq(struct cx25821_dev *dev, int chan_num,
        } else {
                if (status & FLD_VID_SRC_UF)
                        printk
-                           ("%s: Video Received Underflow Error Interrupt!\n",
+                           (KERN_ERR "%s: Video Received Underflow Error Interrupt!\n",
                             __func__);
 
                if (status & FLD_VID_SRC_SYNC)
-                       printk("%s: Video Received Sync Error Interrupt!\n",
+                       printk(KERN_ERR "%s: Video Received Sync Error Interrupt!\n",
                               __func__);
 
                if (status & FLD_VID_SRC_OPC_ERR)
-                       printk("%s: Video Received OpCode Error Interrupt!\n",
+                       printk(KERN_ERR "%s: Video Received OpCode Error Interrupt!\n",
                               __func__);
        }
 
        if (dev->_file_status == END_OF_FILE) {
-               printk("cx25821: EOF Channel 1 Framecount = %d\n",
+               printk(KERN_ERR "cx25821: EOF Channel 1 Framecount = %d\n",
                       dev->_frame_count);
                return -1;
        }
-       //ElSE, set the interrupt mask register, re-enable irq.
+       /* ElSE, set the interrupt mask register, re-enable irq. */
        int_msk_tmp = cx_read(channel->int_msk);
        cx_write(channel->int_msk, int_msk_tmp |= _intr_msk);
 
@@ -685,17 +684,16 @@ static irqreturn_t cx25821_upstream_irq(int irq, void *dev_id)
        msk_stat = cx_read(sram_ch->int_mstat);
        vid_status = cx_read(sram_ch->int_stat);
 
-       // Only deal with our interrupt
+       /* Only deal with our interrupt */
        if (vid_status) {
                handled =
                    cx25821_video_upstream_irq(dev, channel_num, vid_status);
        }
 
-       if (handled < 0) {
+       if (handled < 0)
                cx25821_stop_upstream_video_ch1(dev);
-       } else {
+       else
                handled += handled;
-       }
 
        return IRQ_RETVAL(handled);
 }
@@ -714,19 +712,19 @@ void cx25821_set_pixelengine(struct cx25821_dev *dev, struct sram_channel *ch,
        value |= dev->_isNTSC ? 0 : 0x10;
        cx_write(ch->vid_fmt_ctl, value);
 
-       // set number of active pixels in each line. Default is 720 pixels in both NTSC and PAL format
+       /* set number of active pixels in each line.
+        * Default is 720 pixels in both NTSC and PAL format */
        cx_write(ch->vid_active_ctl1, width);
 
        num_lines = (height / 2) & 0x3FF;
        odd_num_lines = num_lines;
 
-       if (dev->_isNTSC) {
+       if (dev->_isNTSC)
                odd_num_lines += 1;
-       }
 
        value = (num_lines << 16) | odd_num_lines;
 
-       // set number of active lines in field 0 (top) and field 1 (bottom)
+       /* set number of active lines in field 0 (top) and field 1 (bottom) */
        cx_write(ch->vid_active_ctl2, value);
 
        cx_write(ch->vid_cdt_size, VID_CDT_SIZE >> 3);
@@ -738,21 +736,26 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
        u32 tmp = 0;
        int err = 0;
 
-       // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
+       /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
+        * channel A-C
+        */
        tmp = cx_read(VID_CH_MODE_SEL);
        cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
 
-       // Set the physical start address of the RISC program in the initial program counter(IPC) member of the cmds.
+       /* Set the physical start address of the RISC program in the initial
+        * program counter(IPC) member of the cmds.
+        */
        cx_write(sram_ch->cmds_start + 0, dev->_dma_phys_addr);
-       cx_write(sram_ch->cmds_start + 4, 0);   /* Risc IPC High 64 bits 63-32 */
+       /* Risc IPC High 64 bits 63-32 */
+       cx_write(sram_ch->cmds_start + 4, 0);
 
        /* reset counter */
        cx_write(sram_ch->gpcnt_ctl, 3);
 
-       // Clear our bits from the interrupt status register.
+       /* Clear our bits from the interrupt status register. */
        cx_write(sram_ch->int_stat, _intr_msk);
 
-       //Set the interrupt mask register, enable irq.
+       /* Set the interrupt mask register, enable irq. */
        cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << sram_ch->irq_bit));
        tmp = cx_read(sram_ch->int_msk);
        cx_write(sram_ch->int_msk, tmp |= _intr_msk);
@@ -766,7 +769,7 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
                goto fail_irq;
        }
 
-       // Start the DMA  engine
+       /* Start the DMA  engine */
        tmp = cx_read(sram_ch->dma_ctl);
        cx_set(sram_ch->dma_ctl, tmp | FLD_VID_RISC_EN);
 
@@ -775,7 +778,7 @@ int cx25821_start_video_dma_upstream(struct cx25821_dev *dev,
 
        return 0;
 
-      fail_irq:
+fail_irq:
        cx25821_dev_unregister(dev);
        return err;
 }
@@ -792,7 +795,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
        int str_length = 0;
 
        if (dev->_is_running) {
-               printk("Video Channel is still running so return!\n");
+               printk(KERN_INFO "Video Channel is still running so return!\n");
                return 0;
        }
 
@@ -804,10 +807,12 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
 
        if (!dev->_irq_queues) {
                printk
-                   ("cx25821: create_singlethread_workqueue() for Video FAILED!\n");
+                   (KERN_ERR "cx25821: create_singlethread_workqueue() for Video FAILED!\n");
                return -ENOMEM;
        }
-       // 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for channel A-C
+       /* 656/VIP SRC Upstream Channel I & J and 7 - Host Bus Interface for
+        * channel A-C
+        */
        tmp = cx_read(VID_CH_MODE_SEL);
        cx_write(VID_CH_MODE_SEL, tmp | 0x1B0001FF);
 
@@ -841,7 +846,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
                memcpy(dev->_filename, dev->_defaultname, str_length + 1);
        }
 
-       //Default if filename is empty string
+       /* Default if filename is empty string */
        if (strcmp(dev->input_filename, "") == 0) {
                if (dev->_isNTSC) {
                        dev->_filename =
@@ -875,7 +880,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
        dev->upstream_riscbuf_size = risc_buffer_size * 2;
        dev->upstream_databuf_size = data_frame_size * 2;
 
-       //Allocating buffers and prepare RISC program
+       /* Allocating buffers and prepare RISC program */
        retval = cx25821_upstream_buffer_prepare(dev, sram_ch, dev->_line_size);
        if (retval < 0) {
                printk(KERN_ERR
@@ -888,7 +893,7 @@ int cx25821_vidupstream_init_ch1(struct cx25821_dev *dev, int channel_select,
 
        return 0;
 
-      error:
+error:
        cx25821_dev_unregister(dev);
 
        return err;
index 8cd3986..791212c 100644 (file)
@@ -54,34 +54,34 @@ static void init_controls(struct cx25821_dev *dev, int chan_num);
 
 struct cx25821_fmt formats[] = {
        {
-        .name = "8 bpp, gray",
-        .fourcc = V4L2_PIX_FMT_GREY,
-        .depth = 8,
-        .flags = FORMAT_FLAGS_PACKED,
+               .name = "8 bpp, gray",
+               .fourcc = V4L2_PIX_FMT_GREY,
+               .depth = 8,
+               .flags = FORMAT_FLAGS_PACKED,
         }, {
-            .name = "4:1:1, packed, Y41P",
-            .fourcc = V4L2_PIX_FMT_Y41P,
-            .depth = 12,
-            .flags = FORMAT_FLAGS_PACKED,
-            }, {
-                .name = "4:2:2, packed, YUYV",
-                .fourcc = V4L2_PIX_FMT_YUYV,
-                .depth = 16,
-                .flags = FORMAT_FLAGS_PACKED,
-                }, {
-                    .name = "4:2:2, packed, UYVY",
-                    .fourcc = V4L2_PIX_FMT_UYVY,
-                    .depth = 16,
-                    .flags = FORMAT_FLAGS_PACKED,
-                    }, {
-                        .name = "4:2:0, YUV",
-                        .fourcc = V4L2_PIX_FMT_YUV420,
-                        .depth = 12,
-                        .flags = FORMAT_FLAGS_PACKED,
-                        },
+               .name = "4:1:1, packed, Y41P",
+               .fourcc = V4L2_PIX_FMT_Y41P,
+               .depth = 12,
+               .flags = FORMAT_FLAGS_PACKED,
+       }, {
+               .name = "4:2:2, packed, YUYV",
+               .fourcc = V4L2_PIX_FMT_YUYV,
+               .depth = 16,
+               .flags = FORMAT_FLAGS_PACKED,
+       }, {
+               .name = "4:2:2, packed, UYVY",
+               .fourcc = V4L2_PIX_FMT_UYVY,
+               .depth = 16,
+               .flags = FORMAT_FLAGS_PACKED,
+       }, {
+               .name = "4:2:0, YUV",
+               .fourcc = V4L2_PIX_FMT_YUV420,
+               .depth = 12,
+               .flags = FORMAT_FLAGS_PACKED,
+       },
 };
 
-int get_format_size(void)
+int cx25821_get_format_size(void)
 {
        return ARRAY_SIZE(formats);
 }
@@ -102,7 +102,7 @@ struct cx25821_fmt *format_by_fourcc(unsigned int fourcc)
        return NULL;
 }
 
-void dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q)
+void cx25821_dump_video_queue(struct cx25821_dev *dev, struct cx25821_dmaqueue *q)
 {
        struct cx25821_buffer *buf;
        struct list_head *item;
@@ -212,7 +212,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
 */
 
 // resource management
-int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
+int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
 {
        dprintk(1, "%s()\n", __func__);
        if (fh->resources & bit)
@@ -234,17 +234,17 @@ int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bit)
        return 1;
 }
 
-int res_check(struct cx25821_fh *fh, unsigned int bit)
+int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit)
 {
        return fh->resources & bit;
 }
 
-int res_locked(struct cx25821_dev *dev, unsigned int bit)
+int cx25821_res_locked(struct cx25821_dev *dev, unsigned int bit)
 {
        return dev->resources & bit;
 }
 
-void res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits)
+void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh, unsigned int bits)
 {
        BUG_ON((fh->resources & bits) != bits);
        dprintk(1, "%s()\n", __func__);
@@ -506,7 +506,7 @@ int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
        return err;
 }
 
-int buffer_setup(struct videobuf_queue *q, unsigned int *count,
+int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
                 unsigned int *size)
 {
        struct cx25821_fh *fh = q->priv_data;
@@ -516,13 +516,13 @@ int buffer_setup(struct videobuf_queue *q, unsigned int *count,
        if (0 == *count)
                *count = 32;
 
-       while (*size * *count > vid_limit * 1024 * 1024)
-               (*count)--;
+       if (*size * *count > vid_limit * 1024 * 1024)
+               *count = (vid_limit * 1024 * 1024) / *size;
 
        return 0;
 }
 
-int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
+int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
                   enum v4l2_field field)
 {
        struct cx25821_fh *fh = q->priv_data;
@@ -648,7 +648,7 @@ int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
        return rc;
 }
 
-void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
+void cx25821_buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
 {
        struct cx25821_buffer *buf =
            container_of(vb, struct cx25821_buffer, vb);
@@ -667,7 +667,7 @@ struct videobuf_queue *get_queue(struct cx25821_fh *fh)
        }
 }
 
-int get_resource(struct cx25821_fh *fh, int resource)
+int cx25821_get_resource(struct cx25821_fh *fh, int resource)
 {
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -678,7 +678,7 @@ int get_resource(struct cx25821_fh *fh, int resource)
        }
 }
 
-int video_mmap(struct file *file, struct vm_area_struct *vma)
+int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
 {
        struct cx25821_fh *fh = file->private_data;
 
@@ -686,7 +686,7 @@ int video_mmap(struct file *file, struct vm_area_struct *vma)
 }
 
 /* VIDEO IOCTLS                                                       */
-int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
+int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
 {
        struct cx25821_fh *fh = priv;
 
@@ -700,7 +700,7 @@ int vidioc_g_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
        return 0;
 }
 
-int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
+int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
 {
        struct cx25821_fmt *fmt;
        enum v4l2_field field;
@@ -746,7 +746,7 @@ int vidioc_try_fmt_vid_cap(struct file *file, void *priv, struct v4l2_format *f)
        return 0;
 }
 
-int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
+int cx25821_vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
 
@@ -761,7 +761,7 @@ int vidioc_querycap(struct file *file, void *priv, struct v4l2_capability *cap)
        return 0;
 }
 
-int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
+int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
                            struct v4l2_fmtdesc *f)
 {
        if (unlikely(f->index >= ARRAY_SIZE(formats)))
@@ -774,7 +774,7 @@ int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
 }
 
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
+int cx25821_vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
 {
        struct cx25821_fh *fh = priv;
        struct videobuf_queue *q;
@@ -801,25 +801,25 @@ int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
 }
 #endif
 
-int vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p)
+int cx25821_vidioc_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p)
 {
        struct cx25821_fh *fh = priv;
        return videobuf_reqbufs(get_queue(fh), p);
 }
 
-int vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
+int cx25821_vidioc_querybuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
        struct cx25821_fh *fh = priv;
        return videobuf_querybuf(get_queue(fh), p);
 }
 
-int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
+int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
 {
        struct cx25821_fh *fh = priv;
        return videobuf_qbuf(get_queue(fh), p);
 }
 
-int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
+int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
 
@@ -828,7 +828,7 @@ int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p)
        return 0;
 }
 
-int vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio)
+int cx25821_vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio)
 {
        struct cx25821_fh *fh = f;
        struct cx25821_dev *dev = ((struct cx25821_fh *)f)->dev;
@@ -837,7 +837,7 @@ int vidioc_s_priority(struct file *file, void *f, enum v4l2_priority prio)
 }
 
 #ifdef TUNER_FLAG
-int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
+int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
 {
        struct cx25821_fh *fh = priv;
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@@ -846,7 +846,7 @@ int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms)
        dprintk(1, "%s()\n", __func__);
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -891,14 +891,14 @@ int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i)
        return 0;
 }
 
-int vidioc_enum_input(struct file *file, void *priv, struct v4l2_input *i)
+int cx25821_vidioc_enum_input(struct file *file, void *priv, struct v4l2_input *i)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
        dprintk(1, "%s()\n", __func__);
        return cx25821_enum_input(dev, i);
 }
 
-int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
+int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
 
@@ -907,7 +907,7 @@ int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
        return 0;
 }
 
-int vidioc_s_input(struct file *file, void *priv, unsigned int i)
+int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
 {
        struct cx25821_fh *fh = priv;
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
@@ -916,7 +916,7 @@ int vidioc_s_input(struct file *file, void *priv, unsigned int i)
        dprintk(1, "%s(%d)\n", __func__, i);
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -933,7 +933,7 @@ int vidioc_s_input(struct file *file, void *priv, unsigned int i)
 }
 
 #ifdef TUNER_FLAG
-int vidioc_g_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
+int cx25821_vidioc_g_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
 {
        struct cx25821_fh *fh = priv;
        struct cx25821_dev *dev = fh->dev;
@@ -960,15 +960,14 @@ int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f)
        return 0;
 }
 
-int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
+int cx25821_vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
 {
        struct cx25821_fh *fh = priv;
        struct cx25821_dev *dev;
        int err;
 
        if (fh) {
-               dev = fh->dev;
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -978,7 +977,7 @@ int vidioc_s_frequency(struct file *file, void *priv, struct v4l2_frequency *f)
 #endif
 
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-int vidioc_g_register(struct file *file, void *fh,
+int cx25821_vidioc_g_register(struct file *file, void *fh,
                      struct v4l2_dbg_register *reg)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev;
@@ -991,7 +990,7 @@ int vidioc_g_register(struct file *file, void *fh,
        return 0;
 }
 
-int vidioc_s_register(struct file *file, void *fh,
+int cx25821_vidioc_s_register(struct file *file, void *fh,
                      struct v4l2_dbg_register *reg)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)fh)->dev;
@@ -1007,7 +1006,7 @@ int vidioc_s_register(struct file *file, void *fh,
 #endif
 
 #ifdef TUNER_FLAG
-int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
+int cx25821_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
 
@@ -1025,14 +1024,14 @@ int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
        return 0;
 }
 
-int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
+int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
        struct cx25821_fh *fh = priv;
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -1108,7 +1107,7 @@ static int cx25821_ctrl_query(struct v4l2_queryctrl *qctrl)
        return 0;
 }
 
-int vidioc_queryctrl(struct file *file, void *priv,
+int cx25821_vidioc_queryctrl(struct file *file, void *priv,
                     struct v4l2_queryctrl *qctrl)
 {
        return cx25821_ctrl_query(qctrl);
@@ -1127,7 +1126,7 @@ static const struct v4l2_queryctrl *ctrl_by_id(unsigned int id)
        return NULL;
 }
 
-int vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
+int cx25821_vidioc_g_ctrl(struct file *file, void *priv, struct v4l2_control *ctl)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
 
@@ -1216,7 +1215,7 @@ static void init_controls(struct cx25821_dev *dev, int chan_num)
        }
 }
 
-int vidioc_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cropcap)
+int cx25821_vidioc_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cropcap)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
 
@@ -1233,28 +1232,28 @@ int vidioc_cropcap(struct file *file, void *priv, struct v4l2_cropcap *cropcap)
        return 0;
 }
 
-int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
+int cx25821_vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop)
 {
        struct cx25821_dev *dev = ((struct cx25821_fh *)priv)->dev;
        struct cx25821_fh *fh = priv;
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
-       // vidioc_s_crop not supported
+       // cx25821_vidioc_s_crop not supported
        return -EINVAL;
 }
 
-int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
+int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop)
 {
-       // vidioc_g_crop not supported
+       // cx25821_vidioc_g_crop not supported
        return -EINVAL;
 }
 
-int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
+int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
 {
        // medusa does not support video standard sensing of current input
        *norm = CX25821_NORMS;
@@ -1262,7 +1261,7 @@ int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm)
        return 0;
 }
 
-int is_valid_width(u32 width, v4l2_std_id tvnorm)
+int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm)
 {
        if (tvnorm == V4L2_STD_PAL_BG) {
                if (width == 352 || width == 720)
@@ -1280,7 +1279,7 @@ int is_valid_width(u32 width, v4l2_std_id tvnorm)
        return 0;
 }
 
-int is_valid_height(u32 height, v4l2_std_id tvnorm)
+int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm)
 {
        if (tvnorm == V4L2_STD_PAL_BG) {
                if (height == 576 || height == 288)
index 4417ff5..0bddc02 100644 (file)
@@ -101,7 +101,7 @@ extern struct cx25821_fmt formats[];
 extern struct cx25821_fmt *format_by_fourcc(unsigned int fourcc);
 extern struct cx25821_data timeout_data[MAX_VID_CHANNEL_NUM];
 
-extern void dump_video_queue(struct cx25821_dev *dev,
+extern void cx25821_dump_video_queue(struct cx25821_dev *dev,
                             struct cx25821_dmaqueue *q);
 extern void cx25821_video_wakeup(struct cx25821_dev *dev,
                                 struct cx25821_dmaqueue *q, u32 count);
@@ -110,11 +110,11 @@ extern void cx25821_video_wakeup(struct cx25821_dev *dev,
 extern int cx25821_set_tvnorm(struct cx25821_dev *dev, v4l2_std_id norm);
 #endif
 
-extern int res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
+extern int cx25821_res_get(struct cx25821_dev *dev, struct cx25821_fh *fh,
                   unsigned int bit);
-extern int res_check(struct cx25821_fh *fh, unsigned int bit);
-extern int res_locked(struct cx25821_dev *dev, unsigned int bit);
-extern void res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
+extern int cx25821_res_check(struct cx25821_fh *fh, unsigned int bit);
+extern int cx25821_res_locked(struct cx25821_dev *dev, unsigned int bit);
+extern void cx25821_res_free(struct cx25821_dev *dev, struct cx25821_fh *fh,
                     unsigned int bits);
 extern int cx25821_video_mux(struct cx25821_dev *dev, unsigned int input);
 extern int cx25821_start_video_dma(struct cx25821_dev *dev,
@@ -128,67 +128,67 @@ extern int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status);
 extern void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num);
 extern int cx25821_video_register(struct cx25821_dev *dev, int chan_num,
                                  struct video_device *video_template);
-extern int get_format_size(void);
+extern int cx25821_get_format_size(void);
 
-extern int buffer_setup(struct videobuf_queue *q, unsigned int *count,
+extern int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count,
                        unsigned int *size);
-extern int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
+extern int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
                          enum v4l2_field field);
-extern void buffer_release(struct videobuf_queue *q,
+extern void cx25821_buffer_release(struct videobuf_queue *q,
                           struct videobuf_buffer *vb);
 extern struct videobuf_queue *get_queue(struct cx25821_fh *fh);
-extern int get_resource(struct cx25821_fh *fh, int resource);
-extern int video_mmap(struct file *file, struct vm_area_struct *vma);
-extern int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
+extern int cx25821_get_resource(struct cx25821_fh *fh, int resource);
+extern int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma);
+extern int cx25821_vidioc_try_fmt_vid_cap(struct file *file, void *priv,
                                  struct v4l2_format *f);
-extern int vidioc_querycap(struct file *file, void *priv,
+extern int cx25821_vidioc_querycap(struct file *file, void *priv,
                           struct v4l2_capability *cap);
-extern int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
+extern int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
                                   struct v4l2_fmtdesc *f);
-extern int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf);
-extern int vidioc_reqbufs(struct file *file, void *priv,
+extern int cx25821_vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf);
+extern int cx25821_vidioc_reqbufs(struct file *file, void *priv,
                          struct v4l2_requestbuffers *p);
-extern int vidioc_querybuf(struct file *file, void *priv,
+extern int cx25821_vidioc_querybuf(struct file *file, void *priv,
                           struct v4l2_buffer *p);
-extern int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
-extern int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms);
+extern int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p);
+extern int cx25821_vidioc_s_std(struct file *file, void *priv, v4l2_std_id * tvnorms);
 extern int cx25821_enum_input(struct cx25821_dev *dev, struct v4l2_input *i);
-extern int vidioc_enum_input(struct file *file, void *priv,
+extern int cx25821_vidioc_enum_input(struct file *file, void *priv,
                             struct v4l2_input *i);
-extern int vidioc_g_input(struct file *file, void *priv, unsigned int *i);
-extern int vidioc_s_input(struct file *file, void *priv, unsigned int i);
-extern int vidioc_g_ctrl(struct file *file, void *priv,
+extern int cx25821_vidioc_g_input(struct file *file, void *priv, unsigned int *i);
+extern int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i);
+extern int cx25821_vidioc_g_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctl);
-extern int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
+extern int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
                                struct v4l2_format *f);
-extern int vidioc_g_frequency(struct file *file, void *priv,
+extern int cx25821_vidioc_g_frequency(struct file *file, void *priv,
                              struct v4l2_frequency *f);
 extern int cx25821_set_freq(struct cx25821_dev *dev, struct v4l2_frequency *f);
-extern int vidioc_s_frequency(struct file *file, void *priv,
+extern int cx25821_vidioc_s_frequency(struct file *file, void *priv,
                              struct v4l2_frequency *f);
-extern int vidioc_g_register(struct file *file, void *fh,
+extern int cx25821_vidioc_g_register(struct file *file, void *fh,
                             struct v4l2_dbg_register *reg);
-extern int vidioc_s_register(struct file *file, void *fh,
+extern int cx25821_vidioc_s_register(struct file *file, void *fh,
                             struct v4l2_dbg_register *reg);
-extern int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
-extern int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
+extern int cx25821_vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
+extern int cx25821_vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t);
 
-extern int is_valid_width(u32 width, v4l2_std_id tvnorm);
-extern int is_valid_height(u32 height, v4l2_std_id tvnorm);
+extern int cx25821_is_valid_width(u32 width, v4l2_std_id tvnorm);
+extern int cx25821_is_valid_height(u32 height, v4l2_std_id tvnorm);
 
-extern int vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p);
-extern int vidioc_s_priority(struct file *file, void *f,
+extern int cx25821_vidioc_g_priority(struct file *file, void *f, enum v4l2_priority *p);
+extern int cx25821_vidioc_s_priority(struct file *file, void *f,
                             enum v4l2_priority prio);
 
-extern int vidioc_queryctrl(struct file *file, void *priv,
+extern int cx25821_vidioc_queryctrl(struct file *file, void *priv,
                            struct v4l2_queryctrl *qctrl);
 extern int cx25821_set_control(struct cx25821_dev *dev,
                               struct v4l2_control *ctrl, int chan_num);
 
-extern int vidioc_cropcap(struct file *file, void *fh,
+extern int cx25821_vidioc_cropcap(struct file *file, void *fh,
                          struct v4l2_cropcap *cropcap);
-extern int vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop);
-extern int vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop);
+extern int cx25821_vidioc_s_crop(struct file *file, void *priv, struct v4l2_crop *crop);
+extern int cx25821_vidioc_g_crop(struct file *file, void *priv, struct v4l2_crop *crop);
 
-extern int vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm);
+extern int cx25821_vidioc_querystd(struct file *file, void *priv, v4l2_std_id * norm);
 #endif
index ad7a691..0be2cc1 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO0))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO0))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO0)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,19 +207,19 @@ static int video_release(struct file *file)
        cx_write(channel0->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO0)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO0)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO0);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO0);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -239,7 +239,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO0)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO0)))) {
                return -EBUSY;
        }
 
@@ -257,11 +257,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO0);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO0);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,13 +274,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = PIXEL_FRMT_422;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -289,11 +289,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -363,7 +363,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -378,50 +378,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index e3f3c4a..b0bae62 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO1))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO1))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO1)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO1)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,19 +207,19 @@ static int video_release(struct file *file)
        cx_write(channel1->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO1)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO1)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO1);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO1);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -239,7 +239,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO1)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO1)))) {
                return -EBUSY;
        }
 
@@ -257,11 +257,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO1);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO1);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,13 +274,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -289,11 +289,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -363,7 +363,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -378,50 +378,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 36fb855..400cdb8 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO2))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO2))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO2)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO2)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,19 +207,19 @@ static int video_release(struct file *file)
        cx_write(channel2->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO2)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO2)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO2);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO2);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -239,7 +239,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO2)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO2)))) {
                return -EBUSY;
        }
 
@@ -257,11 +257,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO2);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO2);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,13 +274,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -289,11 +289,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -365,7 +365,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -380,50 +380,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 1e0f10a..3b216ed 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO3))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO3))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO3)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO3)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,19 +207,19 @@ static int video_release(struct file *file)
        cx_write(channel3->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO3)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO3)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO3);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO3);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -239,7 +239,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO3)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO3)))) {
                return -EBUSY;
        }
 
@@ -257,11 +257,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO3);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO3);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,13 +274,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -289,11 +289,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -364,7 +364,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -379,50 +379,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 0cbe7a7..f7b08c5 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -146,7 +146,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO4))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO4))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -164,7 +164,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO4)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO4)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -206,19 +206,19 @@ static int video_release(struct file *file)
        cx_write(channel4->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO4)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO4)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO4);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO4);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -238,7 +238,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO4)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO4)))) {
                return -EBUSY;
        }
 
@@ -256,11 +256,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO4);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO4);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,12 +274,12 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 
        // check priority
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -288,11 +288,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -363,7 +363,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -378,50 +378,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 5dc08ad..5937033 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO5))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO5))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO5)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO5)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,19 +207,19 @@ static int video_release(struct file *file)
        cx_write(channel5->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO5)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO5)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO5);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO5);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -239,7 +239,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO5)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO5)))) {
                return -EBUSY;
        }
 
@@ -257,11 +257,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO5);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO5);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -274,13 +274,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -289,11 +289,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -363,7 +363,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -378,50 +378,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 2938ad3..4db2eb8 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -147,7 +147,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO6))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO6))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -165,7 +165,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO6)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO6)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -207,18 +207,18 @@ static int video_release(struct file *file)
        cx_write(channel6->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO6)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO6)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO6);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO6);
        }
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -238,7 +238,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO6)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO6)))) {
                return -EBUSY;
        }
 
@@ -256,11 +256,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO6);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO6);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -273,13 +273,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -288,11 +288,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -363,7 +363,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -378,50 +378,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 458e525..5e4a769 100644 (file)
@@ -85,10 +85,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -146,7 +146,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO7))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO7))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -164,7 +164,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO7)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO7)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -206,19 +206,19 @@ static int video_release(struct file *file)
        cx_write(channel7->dma_ctl, 0); /* FIFO and RISC disable */
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO7)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO7)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO7);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO7);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
        file->private_data = NULL;
        kfree(fh);
 
@@ -238,7 +238,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO7)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO7)))) {
                return -EBUSY;
        }
 
@@ -256,11 +256,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO7);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO7);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -273,13 +273,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int pix_format = 0;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -288,11 +288,11 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        fh->vidq.field = f->fmt.pix.field;
 
        // check if width and height is valid based on set standard
-       if (is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
+       if (cx25821_is_valid_width(f->fmt.pix.width, dev->tvnorm)) {
                fh->width = f->fmt.pix.width;
        }
 
-       if (is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
+       if (cx25821_is_valid_height(f->fmt.pix.height, dev->tvnorm)) {
                fh->height = f->fmt.pix.height;
        }
 
@@ -362,7 +362,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -377,50 +377,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl2,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 1da52b5..d16807d 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -145,7 +145,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO_IOCTL))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO_IOCTL))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -163,7 +163,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO_IOCTL)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO_IOCTL)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -189,19 +189,19 @@ static int video_release(struct file *file)
        struct cx25821_dev *dev = fh->dev;
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO_IOCTL)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO_IOCTL)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO_IOCTL);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO_IOCTL);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
 
        file->private_data = NULL;
        kfree(fh);
@@ -222,7 +222,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO_IOCTL)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO_IOCTL)))) {
                return -EBUSY;
        }
 
@@ -240,11 +240,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO_IOCTL);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO_IOCTL);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -256,13 +256,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -409,7 +409,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -424,50 +424,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl_set,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index b76d9f6..c746a17 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -143,7 +143,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO10))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO10))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -161,7 +161,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO10)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO10)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -189,19 +189,19 @@ static int video_release(struct file *file)
        //cx_write(channel10->dma_ctl, 0);
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO10)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO10)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO10);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO10);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
 
        file->private_data = NULL;
        kfree(fh);
@@ -222,7 +222,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO10)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO10)))) {
                return -EBUSY;
        }
 
@@ -240,11 +240,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO10);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO10);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -299,13 +299,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -347,7 +347,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -362,50 +362,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl_upstream10,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 1580da3..466e0f3 100644 (file)
@@ -86,10 +86,10 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
 }
 
 static struct videobuf_queue_ops cx25821_video_qops = {
-       .buf_setup = buffer_setup,
-       .buf_prepare = buffer_prepare,
+       .buf_setup = cx25821_buffer_setup,
+       .buf_prepare = cx25821_buffer_prepare,
        .buf_queue = buffer_queue,
-       .buf_release = buffer_release,
+       .buf_release = cx25821_buffer_release,
 };
 
 static int video_open(struct file *file)
@@ -143,7 +143,7 @@ static ssize_t video_read(struct file *file, char __user * data, size_t count,
 
        switch (fh->type) {
        case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               if (res_locked(fh->dev, RESOURCE_VIDEO9))
+               if (cx25821_res_locked(fh->dev, RESOURCE_VIDEO9))
                        return -EBUSY;
 
                return videobuf_read_one(&fh->vidq, data, count, ppos,
@@ -161,7 +161,7 @@ static unsigned int video_poll(struct file *file,
        struct cx25821_fh *fh = file->private_data;
        struct cx25821_buffer *buf;
 
-       if (res_check(fh, RESOURCE_VIDEO9)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO9)) {
                /* streaming capture */
                if (list_empty(&fh->vidq.stream))
                        return POLLERR;
@@ -189,19 +189,19 @@ static int video_release(struct file *file)
        //cx_write(channel9->dma_ctl, 0);
 
        /* stop video capture */
-       if (res_check(fh, RESOURCE_VIDEO9)) {
+       if (cx25821_res_check(fh, RESOURCE_VIDEO9)) {
                videobuf_queue_cancel(&fh->vidq);
-               res_free(dev, fh, RESOURCE_VIDEO9);
+               cx25821_res_free(dev, fh, RESOURCE_VIDEO9);
        }
 
        if (fh->vidq.read_buf) {
-               buffer_release(&fh->vidq, fh->vidq.read_buf);
+               cx25821_buffer_release(&fh->vidq, fh->vidq.read_buf);
                kfree(fh->vidq.read_buf);
        }
 
        videobuf_mmap_free(&fh->vidq);
 
-       v4l2_prio_close(&dev->prio, &fh->prio);
+       v4l2_prio_close(&dev->prio, fh->prio);
 
        file->private_data = NULL;
        kfree(fh);
@@ -222,7 +222,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
                return -EINVAL;
        }
 
-       if (unlikely(!res_get(dev, fh, get_resource(fh, RESOURCE_VIDEO9)))) {
+       if (unlikely(!cx25821_res_get(dev, fh, cx25821_get_resource(fh, RESOURCE_VIDEO9)))) {
                return -EBUSY;
        }
 
@@ -240,11 +240,11 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
        if (i != fh->type)
                return -EINVAL;
 
-       res = get_resource(fh, RESOURCE_VIDEO9);
+       res = cx25821_get_resource(fh, RESOURCE_VIDEO9);
        err = videobuf_streamoff(get_queue(fh));
        if (err < 0)
                return err;
-       res_free(dev, fh, res);
+       cx25821_res_free(dev, fh, res);
        return 0;
 }
 
@@ -299,13 +299,13 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        int err;
 
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
 
        dprintk(2, "%s()\n", __func__);
-       err = vidioc_try_fmt_vid_cap(file, priv, f);
+       err = cx25821_vidioc_try_fmt_vid_cap(file, priv, f);
 
        if (0 != err)
                return err;
@@ -345,7 +345,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        struct cx25821_fh *fh = priv;
        int err;
        if (fh) {
-               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               err = v4l2_prio_check(&dev->prio, fh->prio);
                if (0 != err)
                        return err;
        }
@@ -360,50 +360,50 @@ static const struct v4l2_file_operations video_fops = {
        .release = video_release,
        .read = video_read,
        .poll = video_poll,
-       .mmap = video_mmap,
+       .mmap = cx25821_video_mmap,
        .ioctl = video_ioctl_upstream9,
 };
 
 static const struct v4l2_ioctl_ops video_ioctl_ops = {
-       .vidioc_querycap = vidioc_querycap,
-       .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
-       .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
-       .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
+       .vidioc_querycap = cx25821_vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap = cx25821_vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
        .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
-       .vidioc_reqbufs = vidioc_reqbufs,
-       .vidioc_querybuf = vidioc_querybuf,
-       .vidioc_qbuf = vidioc_qbuf,
+       .vidioc_reqbufs = cx25821_vidioc_reqbufs,
+       .vidioc_querybuf = cx25821_vidioc_querybuf,
+       .vidioc_qbuf = cx25821_vidioc_qbuf,
        .vidioc_dqbuf = vidioc_dqbuf,
 #ifdef TUNER_FLAG
-       .vidioc_s_std = vidioc_s_std,
-       .vidioc_querystd = vidioc_querystd,
+       .vidioc_s_std = cx25821_vidioc_s_std,
+       .vidioc_querystd = cx25821_vidioc_querystd,
 #endif
-       .vidioc_cropcap = vidioc_cropcap,
-       .vidioc_s_crop = vidioc_s_crop,
-       .vidioc_g_crop = vidioc_g_crop,
-       .vidioc_enum_input = vidioc_enum_input,
-       .vidioc_g_input = vidioc_g_input,
-       .vidioc_s_input = vidioc_s_input,
-       .vidioc_g_ctrl = vidioc_g_ctrl,
+       .vidioc_cropcap = cx25821_vidioc_cropcap,
+       .vidioc_s_crop = cx25821_vidioc_s_crop,
+       .vidioc_g_crop = cx25821_vidioc_g_crop,
+       .vidioc_enum_input = cx25821_vidioc_enum_input,
+       .vidioc_g_input = cx25821_vidioc_g_input,
+       .vidioc_s_input = cx25821_vidioc_s_input,
+       .vidioc_g_ctrl = cx25821_vidioc_g_ctrl,
        .vidioc_s_ctrl = vidioc_s_ctrl,
-       .vidioc_queryctrl = vidioc_queryctrl,
+       .vidioc_queryctrl = cx25821_vidioc_queryctrl,
        .vidioc_streamon = vidioc_streamon,
        .vidioc_streamoff = vidioc_streamoff,
        .vidioc_log_status = vidioc_log_status,
-       .vidioc_g_priority = vidioc_g_priority,
-       .vidioc_s_priority = vidioc_s_priority,
+       .vidioc_g_priority = cx25821_vidioc_g_priority,
+       .vidioc_s_priority = cx25821_vidioc_s_priority,
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
-       .vidiocgmbuf = vidiocgmbuf,
+       .vidiocgmbuf = cx25821_vidiocgmbuf,
 #endif
 #ifdef TUNER_FLAG
-       .vidioc_g_tuner = vidioc_g_tuner,
-       .vidioc_s_tuner = vidioc_s_tuner,
-       .vidioc_g_frequency = vidioc_g_frequency,
-       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_g_tuner = cx25821_vidioc_g_tuner,
+       .vidioc_s_tuner = cx25821_vidioc_s_tuner,
+       .vidioc_g_frequency = cx25821_vidioc_g_frequency,
+       .vidioc_s_frequency = cx25821_vidioc_s_frequency,
 #endif
 #ifdef CONFIG_VIDEO_ADV_DEBUG
-       .vidioc_g_register = vidioc_g_register,
-       .vidioc_s_register = vidioc_s_register,
+       .vidioc_g_register = cx25821_vidioc_g_register,
+       .vidioc_s_register = cx25821_vidioc_s_register,
 #endif
 };
 
index 3875a72..f1ee2cb 100644 (file)
@@ -61,7 +61,6 @@
 #include <pcmcia/cistpl.h>
 #include <pcmcia/cisreg.h>
 #include <pcmcia/ds.h>
-#include <pcmcia/mem_op.h>
 
 #include <asm/system.h>
 #include <asm/io.h>
@@ -382,10 +381,6 @@ static int netwave_probe(struct pcmcia_device *link)
        link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
     link->io.IOAddrLines = 5;
     
-    /* Interrupt setup */
-    link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-    link->irq.Handler = &netwave_interrupt;
-    
     /* General socket configuration */
     link->conf.Attributes = CONF_ENABLE_IRQ;
     link->conf.IntType = INT_MEMORY_AND_IO;
@@ -732,7 +727,7 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
      *  Now allocate an interrupt line.  Note that this does not
      *  actually assign a handler to the interrupt.
      */
-    ret = pcmcia_request_irq(link, &link->irq);
+    ret = pcmcia_request_irq(link, netwave_interrupt);
     if (ret)
            goto failed;
 
@@ -767,7 +762,7 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
     ramBase = ioremap(req.Base, 0x8000);
     priv->ramBase = ramBase;
 
-    dev->irq = link->irq.AssignedIRQ;
+    dev->irq = link->irq;
     dev->base_addr = link->io.BasePort1;
     SET_NETDEV_DEV(dev, &link->dev);
 
diff --git a/drivers/staging/tm6000/Kconfig b/drivers/staging/tm6000/Kconfig
new file mode 100644 (file)
index 0000000..5fe759c
--- /dev/null
@@ -0,0 +1,32 @@
+config VIDEO_TM6000
+       tristate "TV Master TM5600/6000/6010 driver"
+       depends on VIDEO_DEV && I2C && INPUT && USB && EXPERIMENTAL
+       select VIDEO_TUNER
+       select TUNER_XC2028
+       select VIDEOBUF_VMALLOC
+       help
+         Support for TM5600/TM6000/TM6010 USB Device
+
+         Since these cards have no MPEG decoder onboard, they transmit
+         only compressed MPEG data over the usb bus, so you need
+         an external software decoder to watch TV on your computer.
+
+         Say Y if you own such a device and want to use it.
+
+config VIDEO_TM6000_ALSA
+       tristate "TV Master TM5600/6000/6010 audio support"
+       depends on VIDEO_TM6000 && SND && EXPERIMENTAL
+       select SND_PCM
+       ---help---
+         This is a video4linux driver for direct (DMA) audio for
+         TM5600/TM6000/TM6010 USB Devices.
+
+         To compile this driver as a module, choose M here: the
+         module will be called tm6000-alsa.
+
+config VIDEO_TM6000_DVB
+       bool "DVB Support for tm6000 based TV cards"
+       depends on VIDEO_TM6000 && DVB_CORE && EXPERIMENTAL
+       select DVB_ZL10353
+       ---help---
+         This adds support for DVB cards based on the tm5600/tm6000 chip.
diff --git a/drivers/staging/tm6000/Makefile b/drivers/staging/tm6000/Makefile
new file mode 100644 (file)
index 0000000..93370fc
--- /dev/null
@@ -0,0 +1,17 @@
+tm6000-objs := tm6000-cards.o \
+                  tm6000-core.o  \
+                  tm6000-i2c.o   \
+                  tm6000-video.o \
+                  tm6000-stds.o
+
+ifeq ($(CONFIG_VIDEO_TM6000_DVB),y)
+tm6000-objs += tm6000-dvb.o
+endif
+
+obj-$(CONFIG_VIDEO_TM6000) += tm6000.o
+obj-$(CONFIG_VIDEO_TM6000_ALSA) += tm6000-alsa.o
+
+EXTRA_CFLAGS = -Idrivers/media/video
+EXTRA_CFLAGS += -Idrivers/media/common/tuners
+EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
+EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/staging/tm6000/README b/drivers/staging/tm6000/README
new file mode 100644 (file)
index 0000000..c340ebc
--- /dev/null
@@ -0,0 +1,22 @@
+Todo:
+       - Fix the loss of some blocks when receiving the video URB's
+       - Add a lock at tm6000_read_write_usb() to prevent two simultaneous access to the
+         URB control transfers
+       - Properly add the locks at tm6000-video
+       - Add audio support
+       - Add vbi support
+       - Add IR support
+       - Do several cleanups
+       - I think that frame1/frame0 are inverted. This causes a funny effect at the image.
+         the fix is trivial, but require some tests
+       - My tm6010 devices sometimes insist on stop working. I need to turn them off, removing
+         from my machine and wait for a while for it to work again. I'm starting to think that
+         it is an overheat issue - is there a workaround that we could do?
+       - Sometimes, tm6010 doesn't read eeprom at the proper time (hardware bug). So, the device
+         got miss-detected as a "generic" tm6000. This can be really bad if the tuner is the
+         Low Power one, as it may result on loading the high power firmware, that could damage
+         the device. Maybe we may read eeprom to double check, when the device is marked as "generic"
+       - Coding Style fixes
+       - sparse cleanups
+
+Please send patches to linux-media@vger.kernel.org
diff --git a/drivers/staging/tm6000/tm6000-alsa.c b/drivers/staging/tm6000/tm6000-alsa.c
new file mode 100644 (file)
index 0000000..bc89f9d
--- /dev/null
@@ -0,0 +1,414 @@
+/*
+ *
+ *  Support for audio capture for tm5600/6000/6010
+ *    (c) 2007-2008 Mauro Carvalho Chehab <mchehab@redhat.com>
+ *
+ *  Based on cx88-alsa.c
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/usb.h>
+
+#include <asm/delay.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/control.h>
+#include <sound/initval.h>
+
+
+#include "tm6000.h"
+#include "tm6000-regs.h"
+
+#undef dprintk
+
+#define dprintk(level, fmt, arg...) do {                                  \
+       if (debug >= level)                                                \
+               printk(KERN_INFO "%s/1: " fmt, chip->core->name , ## arg); \
+       } while (0)
+
+/****************************************************************************
+       Data type declarations - Can be moded to a header file later
+ ****************************************************************************/
+
+struct snd_tm6000_card {
+       struct snd_card            *card;
+
+       spinlock_t                 reg_lock;
+
+       atomic_t                   count;
+
+       unsigned int               period_size;
+       unsigned int               num_periods;
+
+       struct tm6000_core         *core;
+       struct tm6000_buffer       *buf;
+
+       int                        bufsize;
+
+       struct snd_pcm_substream *substream;
+};
+
+
+/****************************************************************************
+                       Module global static vars
+ ****************************************************************************/
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
+static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1};
+
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable tm6000x soundcard. default enabled.");
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for tm6000x capture interface(s).");
+
+
+/****************************************************************************
+                               Module macros
+ ****************************************************************************/
+
+MODULE_DESCRIPTION("ALSA driver module for tm5600/tm6000/tm6010 based TV cards");
+MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Trident,tm5600},"
+                       "{{Trident,tm6000},"
+                       "{{Trident,tm6010}");
+static unsigned int debug;
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "enable debug messages");
+
+/****************************************************************************
+                       Module specific funtions
+ ****************************************************************************/
+
+/*
+ * BOARD Specific: Sets audio DMA
+ */
+
+static int _tm6000_start_audio_dma(struct snd_tm6000_card *chip)
+{
+       struct tm6000_core *core = chip->core;
+       int val;
+
+       /* Enables audio */
+       val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
+       val |= 0x20;
+       tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+
+       tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0x80);
+
+       return 0;
+}
+
+/*
+ * BOARD Specific: Resets audio DMA
+ */
+static int _tm6000_stop_audio_dma(struct snd_tm6000_card *chip)
+{
+       struct tm6000_core *core = chip->core;
+       int val;
+       dprintk(1, "Stopping audio DMA\n");
+
+       /* Enables audio */
+       val = tm6000_get_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0x0);
+       val &= ~0x20;
+       tm6000_set_reg(core, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+
+       tm6000_set_reg(core, TM6010_REQ08_R01_A_INIT, 0);
+
+       return 0;
+}
+
+static int dsp_buffer_free(struct snd_tm6000_card *chip)
+{
+       BUG_ON(!chip->bufsize);
+
+       dprintk(2, "Freeing buffer\n");
+
+       /* FIXME: Frees buffer */
+
+       chip->bufsize = 0;
+
+       return 0;
+}
+
+/****************************************************************************
+                               ALSA PCM Interface
+ ****************************************************************************/
+
+/*
+ * Digital hardware definition
+ */
+#define DEFAULT_FIFO_SIZE      4096
+
+static struct snd_pcm_hardware snd_tm6000_digital_hw = {
+       .info = SNDRV_PCM_INFO_MMAP |
+               SNDRV_PCM_INFO_INTERLEAVED |
+               SNDRV_PCM_INFO_BLOCK_TRANSFER |
+               SNDRV_PCM_INFO_MMAP_VALID,
+       .formats = SNDRV_PCM_FMTBIT_S16_LE,
+
+       .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
+       .rate_min =             44100,
+       .rate_max =             48000,
+       .channels_min = 2,
+       .channels_max = 2,
+       .period_bytes_min = DEFAULT_FIFO_SIZE/4,
+       .period_bytes_max = DEFAULT_FIFO_SIZE/4,
+       .periods_min = 1,
+       .periods_max = 1024,
+       .buffer_bytes_max = (1024*1024),
+};
+
+/*
+ * audio pcm capture open callback
+ */
+static int snd_tm6000_pcm_open(struct snd_pcm_substream *substream)
+{
+       struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       int err;
+
+       err = snd_pcm_hw_constraint_pow2(runtime, 0,
+                                        SNDRV_PCM_HW_PARAM_PERIODS);
+       if (err < 0)
+               goto _error;
+
+       chip->substream = substream;
+
+       runtime->hw = snd_tm6000_digital_hw;
+
+       return 0;
+_error:
+       dprintk(1, "Error opening PCM!\n");
+       return err;
+}
+
+/*
+ * audio close callback
+ */
+static int snd_tm6000_close(struct snd_pcm_substream *substream)
+{
+       return 0;
+}
+
+/*
+ * hw_params callback
+ */
+static int snd_tm6000_hw_params(struct snd_pcm_substream *substream,
+                             struct snd_pcm_hw_params *hw_params)
+{
+       struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+
+       if (substream->runtime->dma_area) {
+               dsp_buffer_free(chip);
+               substream->runtime->dma_area = NULL;
+       }
+
+       chip->period_size = params_period_bytes(hw_params);
+       chip->num_periods = params_periods(hw_params);
+       chip->bufsize = chip->period_size * params_periods(hw_params);
+
+       BUG_ON(!chip->bufsize);
+
+       dprintk(1, "Setting buffer\n");
+
+       /* FIXME: Allocate buffer for audio */
+
+
+       return 0;
+}
+
+/*
+ * hw free callback
+ */
+static int snd_tm6000_hw_free(struct snd_pcm_substream *substream)
+{
+
+       struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+
+       if (substream->runtime->dma_area) {
+               dsp_buffer_free(chip);
+               substream->runtime->dma_area = NULL;
+       }
+
+       return 0;
+}
+
+/*
+ * prepare callback
+ */
+static int snd_tm6000_prepare(struct snd_pcm_substream *substream)
+{
+       return 0;
+}
+
+
+/*
+ * trigger callback
+ */
+static int snd_tm6000_card_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+       int err;
+
+       spin_lock(&chip->reg_lock);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               err = _tm6000_start_audio_dma(chip);
+               break;
+       case SNDRV_PCM_TRIGGER_STOP:
+               err = _tm6000_stop_audio_dma(chip);
+               break;
+       default:
+               err = -EINVAL;
+               break;
+       }
+
+       spin_unlock(&chip->reg_lock);
+
+       return err;
+}
+
+/*
+ * pointer callback
+ */
+static snd_pcm_uframes_t snd_tm6000_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_tm6000_card *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       u16 count;
+
+       count = atomic_read(&chip->count);
+
+       return runtime->period_size * (count & (runtime->periods-1));
+}
+
+/*
+ * operators
+ */
+static struct snd_pcm_ops snd_tm6000_pcm_ops = {
+       .open = snd_tm6000_pcm_open,
+       .close = snd_tm6000_close,
+       .ioctl = snd_pcm_lib_ioctl,
+       .hw_params = snd_tm6000_hw_params,
+       .hw_free = snd_tm6000_hw_free,
+       .prepare = snd_tm6000_prepare,
+       .trigger = snd_tm6000_card_trigger,
+       .pointer = snd_tm6000_pointer,
+};
+
+/*
+ * create a PCM device
+ */
+static int __devinit snd_tm6000_pcm(struct snd_tm6000_card *chip,
+                                   int device, char *name)
+{
+       int err;
+       struct snd_pcm *pcm;
+
+       err = snd_pcm_new(chip->card, name, device, 0, 1, &pcm);
+       if (err < 0)
+               return err;
+       pcm->private_data = chip;
+       strcpy(pcm->name, name);
+       snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_tm6000_pcm_ops);
+
+       return 0;
+}
+
+/* FIXME: Control interface - How to control volume/mute? */
+
+/****************************************************************************
+                       Basic Flow for Sound Devices
+ ****************************************************************************/
+
+/*
+ * Alsa Constructor - Component probe
+ */
+
+int tm6000_audio_init(struct tm6000_core *dev, int idx)
+{
+       struct snd_card         *card;
+       struct snd_tm6000_card  *chip;
+       int                     rc, len;
+       char                    component[14];
+
+       if (idx >= SNDRV_CARDS)
+               return -ENODEV;
+
+       if (!enable[idx])
+               return -ENOENT;
+
+       rc = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
+       if (rc < 0) {
+               snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
+               return rc;
+       }
+
+       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+       if (!chip) {
+               rc = -ENOMEM;
+               goto error;
+       }
+
+       chip->core = dev;
+       chip->card = card;
+
+       strcpy(card->driver, "tm6000-alsa");
+       sprintf(component, "USB%04x:%04x",
+               le16_to_cpu(dev->udev->descriptor.idVendor),
+               le16_to_cpu(dev->udev->descriptor.idProduct));
+       snd_component_add(card, component);
+
+       if (dev->udev->descriptor.iManufacturer)
+               len = usb_string(dev->udev,
+                                dev->udev->descriptor.iManufacturer,
+                                card->longname, sizeof(card->longname));
+       else
+               len = 0;
+
+       if (len > 0)
+               strlcat(card->longname, " ", sizeof(card->longname));
+
+       strlcat(card->longname, card->shortname, sizeof(card->longname));
+
+       len = strlcat(card->longname, " at ", sizeof(card->longname));
+
+       if (len < sizeof(card->longname))
+               usb_make_path(dev->udev, card->longname + len,
+                             sizeof(card->longname) - len);
+
+       strlcat(card->longname,
+               dev->udev->speed == USB_SPEED_LOW ? ", low speed" :
+               dev->udev->speed == USB_SPEED_FULL ? ", full speed" :
+                                                          ", high speed",
+               sizeof(card->longname));
+
+       rc = snd_tm6000_pcm(chip, 0, "tm6000 Digital");
+       if (rc < 0)
+               goto error;
+
+       rc = snd_card_register(card);
+       if (rc < 0)
+               goto error;
+
+
+       return 0;
+
+error:
+       snd_card_free(card);
+       return rc;
+}
+EXPORT_SYMBOL_GPL(tm6000_audio_init);
+
diff --git a/drivers/staging/tm6000/tm6000-cards.c b/drivers/staging/tm6000/tm6000-cards.c
new file mode 100644 (file)
index 0000000..6143e20
--- /dev/null
@@ -0,0 +1,973 @@
+/*
+   tm6000-cards.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   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
+
+   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 <linux/init.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/usb.h>
+#include <linux/version.h>
+#include <media/v4l2-common.h>
+#include <media/tuner.h>
+#include <media/tvaudio.h>
+#include <media/i2c-addr.h>
+
+#include "tm6000.h"
+#include "tm6000-regs.h"
+#include "tuner-xc2028.h"
+#include "xc5000.h"
+
+#define TM6000_BOARD_UNKNOWN                   0
+#define TM5600_BOARD_GENERIC                   1
+#define TM6000_BOARD_GENERIC                   2
+#define TM6010_BOARD_GENERIC                   3
+#define TM5600_BOARD_10MOONS_UT821             4
+#define TM5600_BOARD_10MOONS_UT330             5
+#define TM6000_BOARD_ADSTECH_DUAL_TV           6
+#define TM6000_BOARD_FREECOM_AND_SIMILAR       7
+#define TM6000_BOARD_ADSTECH_MINI_DUAL_TV      8
+#define TM6010_BOARD_HAUPPAUGE_900H            9
+#define TM6010_BOARD_BEHOLD_WANDER             10
+#define TM6010_BOARD_BEHOLD_VOYAGER            11
+#define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE        12
+#define TM6010_BOARD_TWINHAN_TU501             13
+
+#define TM6000_MAXBOARDS        16
+static unsigned int card[]     = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
+
+module_param_array(card,  int, NULL, 0444);
+
+static unsigned long tm6000_devused;
+
+
+struct tm6000_board {
+       char            *name;
+
+       struct tm6000_capabilities caps;
+
+       enum            tm6000_devtype type;    /* variant of the chipset */
+       int             tuner_type;     /* type of the tuner */
+       int             tuner_addr;     /* tuner address */
+       int             demod_addr;     /* demodulator address */
+
+       struct tm6000_gpio gpio;
+};
+
+struct tm6000_board tm6000_boards[] = {
+       [TM6000_BOARD_UNKNOWN] = {
+               .name         = "Unknown tm6000 video grabber",
+               .caps = {
+                       .has_tuner    = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_1,
+               },
+       },
+       [TM5600_BOARD_GENERIC] = {
+               .name         = "Generic tm5600 board",
+               .type         = TM5600,
+               .tuner_type   = TUNER_XC2028,
+               .tuner_addr   = 0xc2 >> 1,
+               .caps = {
+                       .has_tuner      = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_1,
+               },
+       },
+       [TM6000_BOARD_GENERIC] = {
+               .name         = "Generic tm6000 board",
+               .tuner_type   = TUNER_XC2028,
+               .tuner_addr   = 0xc2 >> 1,
+               .caps = {
+                       .has_tuner      = 1,
+                       .has_dvb        = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_1,
+               },
+       },
+       [TM6010_BOARD_GENERIC] = {
+               .name         = "Generic tm6010 board",
+               .type         = TM6010,
+               .tuner_type   = TUNER_XC2028,
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .caps = {
+                       .has_tuner      = 1,
+                       .has_dvb        = 1,
+                       .has_zl10353    = 1,
+                       .has_eeprom     = 1,
+                       .has_remote     = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_2,
+                       .tuner_on       = TM6010_GPIO_3,
+                       .demod_reset    = TM6010_GPIO_1,
+                       .demod_on       = TM6010_GPIO_4,
+                       .power_led      = TM6010_GPIO_7,
+                       .dvb_led        = TM6010_GPIO_5,
+                       .ir             = TM6010_GPIO_0,
+               },
+       },
+       [TM5600_BOARD_10MOONS_UT821] = {
+               .name         = "10Moons UT 821",
+               .tuner_type   = TUNER_XC2028,
+               .type         = TM5600,
+               .tuner_addr   = 0xc2 >> 1,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_eeprom   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_1,
+               },
+       },
+       [TM5600_BOARD_10MOONS_UT330] = {
+               .name         = "10Moons UT 330",
+               .tuner_type   = TUNER_PHILIPS_FQ1216AME_MK4,
+               .tuner_addr   = 0xc8 >> 1,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 0,
+                       .has_zl10353  = 0,
+                       .has_eeprom   = 1,
+               },
+       },
+       [TM6000_BOARD_ADSTECH_DUAL_TV] = {
+               .name         = "ADSTECH Dual TV USB",
+               .tuner_type   = TUNER_XC2028,
+               .tuner_addr   = 0xc8 >> 1,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_tda9874  = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 1,
+               },
+       },
+       [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
+               .name         = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
+               .tuner_type   = TUNER_XC2028, /* has a XC3028 */
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 0,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_4,
+               },
+       },
+       [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
+               .name         = "ADSTECH Mini Dual TV USB",
+               .tuner_type   = TUNER_XC2028, /* has a XC3028 */
+               .tuner_addr   = 0xc8 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 0,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6000_GPIO_4,
+               },
+       },
+       [TM6010_BOARD_HAUPPAUGE_900H] = {
+               .name         = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
+               .tuner_type   = TUNER_XC2028, /* has a XC3028 */
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .type         = TM6010,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 1,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_2,
+                       .tuner_on       = TM6010_GPIO_3,
+                       .demod_reset    = TM6010_GPIO_1,
+                       .demod_on       = TM6010_GPIO_4,
+                       .power_led      = TM6010_GPIO_7,
+                       .dvb_led        = TM6010_GPIO_5,
+                       .ir             = TM6010_GPIO_0,
+               },
+       },
+       [TM6010_BOARD_BEHOLD_WANDER] = {
+               .name         = "Beholder Wander DVB-T/TV/FM USB2.0",
+               .tuner_type   = TUNER_XC5000,
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .type         = TM6010,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 1,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_0,
+                       .demod_reset    = TM6010_GPIO_1,
+                       .power_led      = TM6010_GPIO_6,
+               },
+       },
+       [TM6010_BOARD_BEHOLD_VOYAGER] = {
+               .name         = "Beholder Voyager TV/FM USB2.0",
+               .tuner_type   = TUNER_XC5000,
+               .tuner_addr   = 0xc2 >> 1,
+               .type         = TM6010,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 0,
+                       .has_zl10353  = 0,
+                       .has_eeprom   = 1,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_0,
+                       .power_led      = TM6010_GPIO_6,
+               },
+       },
+       [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
+               .name         = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
+               .tuner_type   = TUNER_XC2028, /* has a XC3028 */
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .type         = TM6010,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 1,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_2,
+                       .tuner_on       = TM6010_GPIO_3,
+                       .demod_reset    = TM6010_GPIO_1,
+                       .demod_on       = TM6010_GPIO_4,
+                       .power_led      = TM6010_GPIO_7,
+                       .dvb_led        = TM6010_GPIO_5,
+                       .ir             = TM6010_GPIO_0,
+               },
+       },
+       [TM6010_BOARD_TWINHAN_TU501] = {
+               .name         = "Twinhan TU501(704D1)",
+               .tuner_type   = TUNER_XC2028, /* has a XC3028 */
+               .tuner_addr   = 0xc2 >> 1,
+               .demod_addr   = 0x1e >> 1,
+               .type         = TM6010,
+               .caps = {
+                       .has_tuner    = 1,
+                       .has_dvb      = 1,
+                       .has_zl10353  = 1,
+                       .has_eeprom   = 1,
+                       .has_remote   = 1,
+               },
+               .gpio = {
+                       .tuner_reset    = TM6010_GPIO_2,
+                       .tuner_on       = TM6010_GPIO_3,
+                       .demod_reset    = TM6010_GPIO_1,
+                       .demod_on       = TM6010_GPIO_4,
+                       .power_led      = TM6010_GPIO_7,
+                       .dvb_led        = TM6010_GPIO_5,
+                       .ir             = TM6010_GPIO_0,
+               },
+       }
+};
+
+/* table of devices that work with this driver */
+struct usb_device_id tm6000_id_table[] = {
+       { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_10MOONS_UT821 },
+       { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
+       { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
+       { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
+       { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
+       { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
+       { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
+       { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
+       { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
+       { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
+       { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
+       { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
+       { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
+       { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
+       { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
+       { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
+       { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
+       { },
+};
+
+/* Tuner callback to provide the proper gpio changes needed for xc5000 */
+int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
+{
+       int rc = 0;
+       struct tm6000_core *dev = ptr;
+
+       if (dev->tuner_type != TUNER_XC5000)
+               return 0;
+
+       switch (command) {
+       case XC5000_TUNER_RESET:
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                              dev->gpio.tuner_reset, 0x01);
+               msleep(15);
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                              dev->gpio.tuner_reset, 0x00);
+               msleep(15);
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                              dev->gpio.tuner_reset, 0x01);
+               break;
+       }
+       return (rc);
+}
+
+
+/* Tuner callback to provide the proper gpio changes needed for xc2028 */
+
+int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
+{
+       int rc = 0;
+       struct tm6000_core *dev = ptr;
+
+       if (dev->tuner_type != TUNER_XC2028)
+               return 0;
+
+       switch (command) {
+       case XC2028_RESET_CLK:
+               tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
+                                       0x02, arg);
+               msleep(10);
+               rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                       TM6000_GPIO_CLK, 0);
+               if (rc < 0)
+                       return rc;
+               msleep(10);
+               rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                       TM6000_GPIO_CLK, 1);
+               break;
+       case XC2028_TUNER_RESET:
+               /* Reset codes during load firmware */
+               switch (arg) {
+               case 0:
+                       /* newer tuner can faster reset */
+                       switch (dev->model) {
+                       case TM5600_BOARD_10MOONS_UT821:
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x01);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              0x300, 0x01);
+                               msleep(10);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x00);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              0x300, 0x00);
+                               msleep(10);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x01);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              0x300, 0x01);
+                               break;
+                       case TM6010_BOARD_HAUPPAUGE_900H:
+                       case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+                       case TM6010_BOARD_TWINHAN_TU501:
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x01);
+                               msleep(60);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x00);
+                               msleep(75);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x01);
+                               msleep(60);
+                               break;
+                       default:
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x00);
+                               msleep(130);
+                               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                              dev->gpio.tuner_reset, 0x01);
+                               msleep(130);
+                               break;
+                       }
+                       break;
+               case 1:
+                       tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
+                                               0x02, 0x01);
+                       msleep(10);
+                       break;
+
+               case 2:
+                       rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                               TM6000_GPIO_CLK, 0);
+                       if (rc < 0)
+                               return rc;
+                       msleep(100);
+                       rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                               TM6000_GPIO_CLK, 1);
+                       msleep(100);
+                       break;
+               }
+       }
+       return rc;
+}
+
+int tm6000_cards_setup(struct tm6000_core *dev)
+{
+       int i, rc;
+
+       /*
+        * Board-specific initialization sequence. Handles all GPIO
+        * initialization sequences that are board-specific.
+        * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
+        * Probably, they're all based on some reference device. Due to that,
+        * there's a common routine at the end to handle those GPIO's. Devices
+        * that use different pinups or init sequences can just return at
+        * the board-specific session.
+        */
+       switch (dev->model) {
+       case TM6010_BOARD_HAUPPAUGE_900H:
+       case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+       case TM6010_BOARD_TWINHAN_TU501:
+       case TM6010_BOARD_GENERIC:
+               /* Turn xceive 3028 on */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
+               msleep(15);
+               /* Turn zarlink zl10353 on */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
+               msleep(15);
+               /* Reset zarlink zl10353 */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
+               msleep(50);
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
+               msleep(15);
+               /* Turn zarlink zl10353 off */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
+               msleep(15);
+               /* ir ? */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
+               msleep(15);
+               /* Power led on (blue) */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
+               msleep(15);
+               /* DVB led off (orange) */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
+               msleep(15);
+               /* Turn zarlink zl10353 on */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
+               msleep(15);
+               break;
+       case TM6010_BOARD_BEHOLD_WANDER:
+               /* Power led on (blue) */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
+               msleep(15);
+               /* Reset zarlink zl10353 */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
+               msleep(50);
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
+               msleep(15);
+               break;
+       case TM6010_BOARD_BEHOLD_VOYAGER:
+               /* Power led on (blue) */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
+               msleep(15);
+               break;
+       default:
+               break;
+       }
+
+       /*
+        * Default initialization. Most of the devices seem to use GPIO1
+        * and GPIO4.on the same way, so, this handles the common sequence
+        * used by most devices.
+        * If a device uses a different sequence or different GPIO pins for
+        * reset, just add the code at the board-specific part
+        */
+
+       if (dev->gpio.tuner_reset) {
+               for (i = 0; i < 2; i++) {
+                       rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                               dev->gpio.tuner_reset, 0x00);
+                       if (rc < 0) {
+                               printk(KERN_ERR "Error %i doing tuner reset\n", rc);
+                               return rc;
+                       }
+
+                       msleep(10); /* Just to be conservative */
+                       rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
+                                               dev->gpio.tuner_reset, 0x01);
+                       if (rc < 0) {
+                               printk(KERN_ERR "Error %i doing tuner reset\n", rc);
+                               return rc;
+                       }
+                       msleep(10);
+
+                       if (!i) {
+                               rc = tm6000_get_reg32(dev, REQ_40_GET_VERSION, 0, 0);
+                               if (rc >= 0)
+                                       printk(KERN_DEBUG "board=0x%08x\n", rc);
+                       }
+               }
+       } else {
+               printk(KERN_ERR "Tuner reset is not configured\n");
+               return -1;
+       }
+
+       msleep(50);
+
+       return 0;
+};
+
+static void tm6000_config_tuner(struct tm6000_core *dev)
+{
+       struct tuner_setup tun_setup;
+
+       /* Load tuner module */
+       v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
+               "tuner", "tuner", dev->tuner_addr, NULL);
+
+       memset(&tun_setup, 0, sizeof(tun_setup));
+       tun_setup.type = dev->tuner_type;
+       tun_setup.addr = dev->tuner_addr;
+
+       tun_setup.mode_mask = 0;
+       if (dev->caps.has_tuner)
+               tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
+       if (dev->caps.has_dvb)
+               tun_setup.mode_mask |= T_DIGITAL_TV;
+
+       switch (dev->tuner_type) {
+       case TUNER_XC2028:
+               tun_setup.tuner_callback = tm6000_tuner_callback;;
+               break;
+       case TUNER_XC5000:
+               tun_setup.tuner_callback = tm6000_xc5000_callback;
+               break;
+       }
+
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
+
+       switch (dev->tuner_type) {
+       case TUNER_XC2028: {
+               struct v4l2_priv_tun_config xc2028_cfg;
+               struct xc2028_ctrl ctl;
+
+               memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
+               memset(&ctl, 0, sizeof(ctl));
+
+               ctl.input1 = 1;
+               ctl.read_not_reliable = 0;
+               ctl.msleep = 10;
+               ctl.demod = XC3028_FE_ZARLINK456;
+               ctl.vhfbw7 = 1;
+               ctl.uhfbw8 = 1;
+               xc2028_cfg.tuner = TUNER_XC2028;
+               xc2028_cfg.priv  = &ctl;
+
+               switch (dev->model) {
+               case TM6010_BOARD_HAUPPAUGE_900H:
+               case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
+               case TM6010_BOARD_TWINHAN_TU501:
+                       ctl.fname = "xc3028L-v36.fw";
+                       break;
+               default:
+                       if (dev->dev_type == TM6010)
+                               ctl.fname = "xc3028-v27.fw";
+                       else
+                               ctl.fname = "xc3028-v24.fw";
+               }
+
+               printk(KERN_INFO "Setting firmware parameters for xc2028\n");
+               v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
+                                    &xc2028_cfg);
+
+               }
+               break;
+       case TUNER_XC5000:
+               {
+               struct v4l2_priv_tun_config  xc5000_cfg;
+               struct xc5000_config ctl = {
+                       .i2c_address = dev->tuner_addr,
+                       .if_khz      = 4570,
+                       .radio_input = XC5000_RADIO_FM1,
+                       };
+
+               xc5000_cfg.tuner = TUNER_XC5000;
+               xc5000_cfg.priv  = &ctl;
+
+
+               v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
+                                    &xc5000_cfg);
+               }
+               break;
+       default:
+               printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
+               break;
+       }
+}
+
+static int tm6000_init_dev(struct tm6000_core *dev)
+{
+       struct v4l2_frequency f;
+       int rc = 0;
+
+       mutex_init(&dev->lock);
+
+       mutex_lock(&dev->lock);
+
+       /* Initializa board-specific data */
+       dev->dev_type   = tm6000_boards[dev->model].type;
+       dev->tuner_type = tm6000_boards[dev->model].tuner_type;
+       dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
+
+       dev->gpio = tm6000_boards[dev->model].gpio;
+
+       dev->demod_addr = tm6000_boards[dev->model].demod_addr;
+
+       dev->caps = tm6000_boards[dev->model].caps;
+
+       /* initialize hardware */
+       rc = tm6000_init(dev);
+       if (rc < 0)
+               goto err;
+
+       rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
+       if (rc < 0)
+               goto err;
+
+       /* register i2c bus */
+       rc = tm6000_i2c_register(dev);
+       if (rc < 0)
+               goto err;
+
+       /* Default values for STD and resolutions */
+       dev->width = 720;
+       dev->height = 480;
+       dev->norm = V4L2_STD_PAL_M;
+
+       /* Configure tuner */
+       tm6000_config_tuner(dev);
+
+       /* Set video standard */
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
+
+       /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
+       f.tuner = 0;
+       f.type = V4L2_TUNER_ANALOG_TV;
+       f.frequency = 3092;     /* 193.25 MHz */
+       dev->freq = f.frequency;
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
+
+       if (dev->caps.has_tda9874)
+               v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
+                       "tvaudio", "tvaudio", I2C_ADDR_TDA9874, NULL);
+
+       /* register and initialize V4L2 */
+       rc = tm6000_v4l2_register(dev);
+       if (rc < 0)
+               goto err;
+
+       if (dev->caps.has_dvb) {
+               dev->dvb = kzalloc(sizeof(*(dev->dvb)), GFP_KERNEL);
+               if (!dev->dvb) {
+                       rc = -ENOMEM;
+                       goto err2;
+               }
+
+#ifdef CONFIG_VIDEO_TM6000_DVB
+               rc = tm6000_dvb_register(dev);
+               if (rc < 0) {
+                       kfree(dev->dvb);
+                       dev->dvb = NULL;
+                       goto err2;
+               }
+#endif
+       }
+       mutex_unlock(&dev->lock);
+       return 0;
+
+err2:
+       v4l2_device_unregister(&dev->v4l2_dev);
+
+err:
+       mutex_unlock(&dev->lock);
+       return rc;
+}
+
+/* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
+#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
+
+static void get_max_endpoint(struct usb_device *udev,
+                            struct usb_host_interface *alt,
+                            char *msgtype,
+                            struct usb_host_endpoint *curr_e,
+                            struct tm6000_endpoint *tm_ep)
+{
+       u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
+       unsigned int size = tmp & 0x7ff;
+
+       if (udev->speed == USB_SPEED_HIGH)
+               size = size * hb_mult (tmp);
+
+       if (size > tm_ep->maxsize) {
+               tm_ep->endp = curr_e;
+               tm_ep->maxsize = size;
+               tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
+               tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
+
+               printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
+                                       msgtype, curr_e->desc.bEndpointAddress,
+                                       size);
+       }
+}
+
+/*
+ * tm6000_usb_probe()
+ * checks for supported devices
+ */
+static int tm6000_usb_probe(struct usb_interface *interface,
+                           const struct usb_device_id *id)
+{
+       struct usb_device *usbdev;
+       struct tm6000_core *dev = NULL;
+       int i, rc = 0;
+       int nr = 0;
+       char *speed;
+
+       usbdev = usb_get_dev(interface_to_usbdev(interface));
+
+       /* Selects the proper interface */
+       rc = usb_set_interface(usbdev, 0, 1);
+       if (rc < 0)
+               goto err;
+
+       /* Check to see next free device and mark as used */
+       nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
+       if (nr >= TM6000_MAXBOARDS) {
+               printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
+               usb_put_dev(usbdev);
+               return -ENOMEM;
+       }
+
+       /* Create and initialize dev struct */
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (dev == NULL) {
+               printk(KERN_ERR "tm6000" ": out of memory!\n");
+               usb_put_dev(usbdev);
+               return -ENOMEM;
+       }
+       spin_lock_init(&dev->slock);
+
+       /* Increment usage count */
+       tm6000_devused |= 1<<nr;
+       snprintf(dev->name, 29, "tm6000 #%d", nr);
+
+       dev->model = id->driver_info;
+       if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
+               dev->model = card[nr];
+
+       dev->udev = usbdev;
+       dev->devno = nr;
+
+       switch (usbdev->speed) {
+       case USB_SPEED_LOW:
+               speed = "1.5";
+               break;
+       case USB_SPEED_UNKNOWN:
+       case USB_SPEED_FULL:
+               speed = "12";
+               break;
+       case USB_SPEED_HIGH:
+               speed = "480";
+               break;
+       default:
+               speed = "unknown";
+       }
+
+
+
+       /* Get endpoints */
+       for (i = 0; i < interface->num_altsetting; i++) {
+               int ep;
+
+               for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
+                       struct usb_host_endpoint        *e;
+                       int dir_out;
+
+                       e = &interface->altsetting[i].endpoint[ep];
+
+                       dir_out = ((e->desc.bEndpointAddress &
+                                       USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
+
+                       printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
+                              i,
+                              interface->altsetting[i].desc.bInterfaceNumber,
+                              interface->altsetting[i].desc.bInterfaceClass);
+
+                       switch (e->desc.bmAttributes) {
+                       case USB_ENDPOINT_XFER_BULK:
+                               if (!dir_out) {
+                                       get_max_endpoint(usbdev,
+                                                        &interface->altsetting[i],
+                                                        "Bulk IN", e,
+                                                        &dev->bulk_in);
+                               } else {
+                                       get_max_endpoint(usbdev,
+                                                        &interface->altsetting[i],
+                                                        "Bulk OUT", e,
+                                                        &dev->bulk_out);
+                               }
+                               break;
+                       case USB_ENDPOINT_XFER_ISOC:
+                               if (!dir_out) {
+                                       get_max_endpoint(usbdev,
+                                                        &interface->altsetting[i],
+                                                        "ISOC IN", e,
+                                                        &dev->isoc_in);
+                               } else {
+                                       get_max_endpoint(usbdev,
+                                                        &interface->altsetting[i],
+                                                        "ISOC OUT", e,
+                                                        &dev->isoc_out);
+                               }
+                               break;
+                       }
+               }
+       }
+
+
+       printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
+               speed,
+               le16_to_cpu(dev->udev->descriptor.idVendor),
+               le16_to_cpu(dev->udev->descriptor.idProduct),
+               interface->altsetting->desc.bInterfaceNumber);
+
+/* check if the the device has the iso in endpoint at the correct place */
+       if (!dev->isoc_in.endp) {
+               printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
+               rc = -ENODEV;
+
+               goto err;
+       }
+
+       /* save our data pointer in this interface device */
+       usb_set_intfdata(interface, dev);
+
+       printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
+
+       rc = tm6000_init_dev(dev);
+
+       if (rc < 0)
+               goto err;
+
+       return 0;
+
+err:
+       printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
+
+       tm6000_devused &= ~(1<<nr);
+       usb_put_dev(usbdev);
+
+       kfree(dev);
+       return rc;
+}
+
+/*
+ * tm6000_usb_disconnect()
+ * called when the device gets diconencted
+ * video device will be unregistered on v4l2_close in case it is still open
+ */
+static void tm6000_usb_disconnect(struct usb_interface *interface)
+{
+       struct tm6000_core *dev = usb_get_intfdata(interface);
+       usb_set_intfdata(interface, NULL);
+
+       if (!dev)
+               return;
+
+       printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
+
+       mutex_lock(&dev->lock);
+
+#ifdef CONFIG_VIDEO_TM6000_DVB
+       if (dev->dvb) {
+               tm6000_dvb_unregister(dev);
+               kfree(dev->dvb);
+       }
+#endif
+
+       tm6000_v4l2_unregister(dev);
+
+       tm6000_i2c_unregister(dev);
+
+       v4l2_device_unregister(&dev->v4l2_dev);
+
+       dev->state |= DEV_DISCONNECTED;
+
+       usb_put_dev(dev->udev);
+
+       mutex_unlock(&dev->lock);
+       kfree(dev);
+}
+
+static struct usb_driver tm6000_usb_driver = {
+               .name = "tm6000",
+               .probe = tm6000_usb_probe,
+               .disconnect = tm6000_usb_disconnect,
+               .id_table = tm6000_id_table,
+};
+
+static int __init tm6000_module_init(void)
+{
+       int result;
+
+       printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
+              (TM6000_VERSION  >> 16) & 0xff,
+              (TM6000_VERSION  >> 8) & 0xff, TM6000_VERSION  & 0xff);
+
+       /* register this driver with the USB subsystem */
+       result = usb_register(&tm6000_usb_driver);
+       if (result)
+               printk(KERN_ERR "tm6000"
+                          " usb_register failed. Error number %d.\n", result);
+
+       return result;
+}
+
+static void __exit tm6000_module_exit(void)
+{
+       /* deregister at USB subsystem */
+       usb_deregister(&tm6000_usb_driver);
+}
+
+module_init(tm6000_module_init);
+module_exit(tm6000_module_exit);
+
+MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
+MODULE_AUTHOR("Mauro Carvalho Chehab");
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/tm6000/tm6000-core.c b/drivers/staging/tm6000/tm6000-core.c
new file mode 100644 (file)
index 0000000..bfbc53b
--- /dev/null
@@ -0,0 +1,602 @@
+/*
+   tm6000-core.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
+       - DVB-T 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 version 2
+
+   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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+#include <linux/i2c.h>
+#include "tm6000.h"
+#include "tm6000-regs.h"
+#include <media/v4l2-common.h>
+#include <media/tuner.h>
+
+#define USB_TIMEOUT    5*HZ /* ms */
+
+int tm6000_read_write_usb (struct tm6000_core *dev, u8 req_type, u8 req,
+                          u16 value, u16 index, u8 *buf, u16 len)
+{
+       int          ret, i;
+       unsigned int pipe;
+       static int   ini=0, last=0, n=0;
+       u8           *data=NULL;
+
+       if (len)
+               data = kzalloc(len, GFP_KERNEL);
+
+
+       if (req_type & USB_DIR_IN)
+               pipe=usb_rcvctrlpipe(dev->udev, 0);
+       else {
+               pipe=usb_sndctrlpipe(dev->udev, 0);
+               memcpy(data, buf, len);
+       }
+
+       if (tm6000_debug & V4L2_DEBUG_I2C) {
+               if (!ini)
+                       last=ini=jiffies;
+
+               printk("%06i (dev %p, pipe %08x): ", n, dev->udev, pipe);
+
+               printk( "%s: %06u ms %06u ms %02x %02x %02x %02x %02x %02x %02x %02x ",
+                       (req_type & USB_DIR_IN)?" IN":"OUT",
+                       jiffies_to_msecs(jiffies-last),
+                       jiffies_to_msecs(jiffies-ini),
+                       req_type, req,value&0xff,value>>8, index&0xff, index>>8,
+                       len&0xff, len>>8);
+               last=jiffies;
+               n++;
+
+               if ( !(req_type & USB_DIR_IN) ) {
+                       printk(">>> ");
+                       for (i=0;i<len;i++) {
+                               printk(" %02x",buf[i]);
+                       }
+               printk("\n");
+               }
+       }
+
+       ret = usb_control_msg(dev->udev, pipe, req, req_type, value, index, data,
+                             len, USB_TIMEOUT);
+
+       if (req_type &  USB_DIR_IN)
+               memcpy(buf, data, len);
+
+       if (tm6000_debug & V4L2_DEBUG_I2C) {
+               if (ret<0) {
+                       if (req_type &  USB_DIR_IN)
+                               printk("<<< (len=%d)\n",len);
+
+                       printk("%s: Error #%d\n", __FUNCTION__, ret);
+               } else if (req_type &  USB_DIR_IN) {
+                       printk("<<< ");
+                       for (i=0;i<len;i++) {
+                               printk(" %02x",buf[i]);
+                       }
+                       printk("\n");
+               }
+       }
+
+       kfree(data);
+
+       msleep(5);
+
+       return ret;
+}
+
+int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index)
+{
+       return
+               tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR,
+                                      req, value, index, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(tm6000_set_reg);
+
+int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index)
+{
+       int rc;
+       u8 buf[1];
+
+       rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
+                                      value, index, buf, 1);
+
+       if (rc<0)
+               return rc;
+
+       return *buf;
+}
+EXPORT_SYMBOL_GPL(tm6000_get_reg);
+
+int tm6000_get_reg16 (struct tm6000_core *dev, u8 req, u16 value, u16 index)
+{
+       int rc;
+       u8 buf[2];
+
+       rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
+                                      value, index, buf, 2);
+
+       if (rc<0)
+               return rc;
+
+       return buf[1]|buf[0]<<8;
+}
+
+int tm6000_get_reg32 (struct tm6000_core *dev, u8 req, u16 value, u16 index)
+{
+       int rc;
+       u8 buf[4];
+
+       rc=tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR, req,
+                                      value, index, buf, 4);
+
+       if (rc<0)
+               return rc;
+
+       return buf[3] | buf[2] << 8 | buf[1] << 16 | buf[0] << 24;
+}
+
+void tm6000_set_fourcc_format(struct tm6000_core *dev)
+{
+       if (dev->dev_type == TM6010) {
+               int val;
+
+               val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0) & 0xfc;
+               if (dev->fourcc == V4L2_PIX_FMT_UYVY)
+                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+               else
+                       tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val | 1);
+       } else {
+               if (dev->fourcc == V4L2_PIX_FMT_UYVY)
+                       tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0xd0);
+               else
+                       tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0x90);
+       }
+}
+
+int tm6000_init_analog_mode (struct tm6000_core *dev)
+{
+       if (dev->dev_type == TM6010) {
+               int val;
+
+               /* Enable video */
+               val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0);
+               val |= 0x60;
+               tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+               val = tm6000_get_reg(dev,
+                       TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0);
+               val &= ~0x40;
+               tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, val);
+
+               /* Init teletext */
+               tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x01);
+               tm6000_set_reg(dev, TM6010_REQ07_R41_TELETEXT_VBI_CODE1, 0x27);
+               tm6000_set_reg(dev, TM6010_REQ07_R42_VBI_DATA_HIGH_LEVEL, 0x55);
+               tm6000_set_reg(dev, TM6010_REQ07_R43_VBI_DATA_TYPE_LINE7, 0x66);
+               tm6000_set_reg(dev, TM6010_REQ07_R44_VBI_DATA_TYPE_LINE8, 0x66);
+               tm6000_set_reg(dev, TM6010_REQ07_R45_VBI_DATA_TYPE_LINE9, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R46_VBI_DATA_TYPE_LINE10, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R47_VBI_DATA_TYPE_LINE11, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R48_VBI_DATA_TYPE_LINE12, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R49_VBI_DATA_TYPE_LINE13, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4A_VBI_DATA_TYPE_LINE14, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4B_VBI_DATA_TYPE_LINE15, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4C_VBI_DATA_TYPE_LINE16, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4D_VBI_DATA_TYPE_LINE17, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4E_VBI_DATA_TYPE_LINE18, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R4F_VBI_DATA_TYPE_LINE19, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R50_VBI_DATA_TYPE_LINE20, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R51_VBI_DATA_TYPE_LINE21, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R52_VBI_DATA_TYPE_LINE22, 0x66);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R53_VBI_DATA_TYPE_LINE23, 0x00);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R54_VBI_DATA_TYPE_RLINES, 0x00);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R55_VBI_LOOP_FILTER_GAIN, 0x01);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R56_VBI_LOOP_FILTER_I_GAIN, 0x00);
+               tm6000_set_reg(dev,
+                       TM6010_REQ07_R57_VBI_LOOP_FILTER_P_GAIN, 0x02);
+               tm6000_set_reg(dev, TM6010_REQ07_R58_VBI_CAPTION_DTO1, 0x35);
+               tm6000_set_reg(dev, TM6010_REQ07_R59_VBI_CAPTION_DTO0, 0xa0);
+               tm6000_set_reg(dev, TM6010_REQ07_R5A_VBI_TELETEXT_DTO1, 0x11);
+               tm6000_set_reg(dev, TM6010_REQ07_R5B_VBI_TELETEXT_DTO0, 0x4c);
+               tm6000_set_reg(dev, TM6010_REQ07_R40_TELETEXT_VBI_CODE0, 0x01);
+               tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x00);
+
+
+               /* Init audio */
+               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R02_A_FIX_GAIN_CTRL, 0x04);
+               tm6000_set_reg(dev, TM6010_REQ08_R03_A_AUTO_GAIN_CTRL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R04_A_SIF_AMP_CTRL, 0xa0);
+               tm6000_set_reg(dev, TM6010_REQ08_R05_A_STANDARD_MOD, 0x05);
+               tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x06);
+               tm6000_set_reg(dev, TM6010_REQ08_R07_A_LEFT_VOL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R08_A_RIGHT_VOL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R09_A_MAIN_VOL, 0x08);
+               tm6000_set_reg(dev, TM6010_REQ08_R0A_A_I2S_MOD, 0x91);
+               tm6000_set_reg(dev, TM6010_REQ08_R0B_A_ASD_THRES1, 0x20);
+               tm6000_set_reg(dev, TM6010_REQ08_R0C_A_ASD_THRES2, 0x12);
+               tm6000_set_reg(dev, TM6010_REQ08_R0D_A_AMD_THRES, 0x20);
+               tm6000_set_reg(dev, TM6010_REQ08_R0E_A_MONO_THRES1, 0xf0);
+               tm6000_set_reg(dev, TM6010_REQ08_R0F_A_MONO_THRES2, 0x80);
+               tm6000_set_reg(dev, TM6010_REQ08_R10_A_MUTE_THRES1, 0xc0);
+               tm6000_set_reg(dev, TM6010_REQ08_R11_A_MUTE_THRES2, 0x80);
+               tm6000_set_reg(dev, TM6010_REQ08_R12_A_AGC_U, 0x12);
+               tm6000_set_reg(dev, TM6010_REQ08_R13_A_AGC_ERR_T, 0xfe);
+               tm6000_set_reg(dev, TM6010_REQ08_R14_A_AGC_GAIN_INIT, 0x20);
+               tm6000_set_reg(dev, TM6010_REQ08_R15_A_AGC_STEP_THR, 0x14);
+               tm6000_set_reg(dev, TM6010_REQ08_R16_A_AGC_GAIN_MAX, 0xfe);
+               tm6000_set_reg(dev, TM6010_REQ08_R17_A_AGC_GAIN_MIN, 0x01);
+               tm6000_set_reg(dev, TM6010_REQ08_R18_A_TR_CTRL, 0xa0);
+               tm6000_set_reg(dev, TM6010_REQ08_R19_A_FH_2FH_GAIN, 0x32);
+               tm6000_set_reg(dev, TM6010_REQ08_R1A_A_NICAM_SER_MAX, 0x64);
+               tm6000_set_reg(dev, TM6010_REQ08_R1B_A_NICAM_SER_MIN, 0x20);
+               tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1c, 0x00);
+               tm6000_set_reg(dev, REQ_08_SET_GET_AVREG_BIT, 0x1d, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT, 0x13);
+               tm6000_set_reg(dev, TM6010_REQ08_R1F_A_TEST_INTF_SEL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R20_A_TEST_PIN_SEL, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3);
+               tm6000_set_reg(dev, TM6010_REQ08_R06_A_SOUND_MOD, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ08_R01_A_INIT, 0x80);
+
+       } else {
+               /* Enables soft reset */
+               tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x01);
+
+               if (dev->scaler) {
+                       tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x20);
+               } else {
+                       /* Enable Hfilter and disable TS Drop err */
+                       tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x80);
+               }
+
+               tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x88);
+               tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0x23);
+               tm6000_set_reg(dev, TM6010_REQ07_RD1_ADDR_FOR_REQ1, 0xc0);
+               tm6000_set_reg(dev, TM6010_REQ07_RD2_ADDR_FOR_REQ2, 0xd8);
+               tm6000_set_reg(dev, TM6010_REQ07_RD6_ENDP_REQ1_REQ2, 0x06);
+               tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0x1f);
+
+               /* AP Software reset */
+               tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x08);
+               tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x00);
+
+               tm6000_set_fourcc_format(dev);
+
+               /* Disables soft reset */
+               tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x00);
+
+               /* E3: Select input 0 - TV tuner */
+               tm6000_set_reg(dev, TM6010_REQ07_RE3_OUT_SEL1, 0x00);
+               tm6000_set_reg(dev, REQ_07_SET_GET_AVREG, 0xeb, 0x60);
+
+               /* This controls input */
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, TM6000_GPIO_2, 0x0);
+               tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, TM6000_GPIO_3, 0x01);
+       }
+       msleep(20);
+
+       /* Tuner firmware can now be loaded */
+
+       /*FIXME: Hack!!! */
+       struct v4l2_frequency f;
+       mutex_lock(&dev->lock);
+       f.frequency=dev->freq;
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
+       mutex_unlock(&dev->lock);
+
+       msleep(100);
+       tm6000_set_standard (dev, &dev->norm);
+       tm6000_set_audio_bitrate (dev,48000);
+
+       return 0;
+}
+
+int tm6000_init_digital_mode (struct tm6000_core *dev)
+{
+       if (dev->dev_type == TM6010) {
+               int val;
+               u8 buf[2];
+
+               /* digital init */
+               val = tm6000_get_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0);
+               val &= ~0x60;
+               tm6000_set_reg(dev, TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, val);
+               val = tm6000_get_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0);
+               val |= 0x40;
+               tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, val);
+               tm6000_set_reg(dev, TM6010_REQ07_RFE_POWER_DOWN, 0x28);
+               tm6000_set_reg(dev, TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xfc);
+               tm6000_set_reg(dev, TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0xff);
+               tm6000_set_reg(dev, TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe);
+               tm6000_read_write_usb (dev, 0xc0, 0x0e, 0x00c2, 0x0008, buf, 2);
+               printk (KERN_INFO "buf %#x %#x \n", buf[0], buf[1]);
+
+
+       } else  {
+               tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x08);
+               tm6000_set_reg(dev, TM6010_REQ07_RFF_SOFT_RESET, 0x00);
+               tm6000_set_reg(dev, TM6010_REQ07_R3F_RESET, 0x01);
+               tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_PULSE_CNT0, 0x08);
+               tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c);
+               tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff);
+               tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0x00eb, 0xd8);
+               tm6000_set_reg(dev, TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x40);
+               tm6000_set_reg(dev, TM6010_REQ07_RC1_TRESHOLD, 0xd0);
+               tm6000_set_reg(dev, TM6010_REQ07_RC3_HSTART1, 0x09);
+               tm6000_set_reg(dev, TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0x37);
+               tm6000_set_reg(dev, TM6010_REQ07_RD1_ADDR_FOR_REQ1, 0xd8);
+               tm6000_set_reg(dev, TM6010_REQ07_RD2_ADDR_FOR_REQ2, 0xc0);
+               tm6000_set_reg(dev, TM6010_REQ07_RD6_ENDP_REQ1_REQ2, 0x60);
+
+               tm6000_set_reg(dev, TM6010_REQ07_RE2_OUT_SEL2, 0x0c);
+               tm6000_set_reg(dev, TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0xff);
+               tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0x00eb, 0x08);
+               msleep(50);
+
+               tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00);
+               msleep(50);
+               tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x01);
+               msleep(50);
+               tm6000_set_reg (dev, REQ_04_EN_DISABLE_MCU_INT, 0x0020, 0x00);
+               msleep(100);
+       }
+       return 0;
+}
+
+struct reg_init {
+       u8 req;
+       u8 reg;
+       u8 val;
+};
+
+/* The meaning of those initializations are unknown */
+struct reg_init tm6000_init_tab[] = {
+       /* REG  VALUE */
+       { TM6010_REQ07_RD8_IR_PULSE_CNT0, 0x1f },
+       { TM6010_REQ07_RFF_SOFT_RESET, 0x08 },
+       { TM6010_REQ07_RFF_SOFT_RESET, 0x00 },
+       { TM6010_REQ07_RD5_POWERSAVE, 0x4f },
+       { TM6010_REQ07_RD8_IR_WAKEUP_SEL, 0x23 },
+       { TM6010_REQ07_RD8_IR_WAKEUP_ADD, 0x08 },
+       { TM6010_REQ07_RE2_OUT_SEL2, 0x00 },
+       { TM6010_REQ07_RE3_OUT_SEL1, 0x10 },
+       { TM6010_REQ07_RE5_REMOTE_WAKEUP, 0x00 },
+       { TM6010_REQ07_RE8_TYPESEL_MOS_I2S, 0x00 },
+       { REQ_07_SET_GET_AVREG,  0xeb, 0x64 },          /* 48000 bits/sample, external input */
+       { REQ_07_SET_GET_AVREG,  0xee, 0xc2 },
+       { TM6010_REQ07_R3F_RESET, 0x01 },               /* Start of soft reset */
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x07 },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
+       { TM6010_REQ07_R05_NOISE_THRESHOLD, 0x64 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01 },
+       { TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0x82 },
+       { TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0x36 },
+       { TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0x50 },
+       { TM6010_REQ07_R0C_CHROMA_AGC_CONTROL, 0x6a },
+       { TM6010_REQ07_R11_AGC_PEAK_CONTROL, 0xc9 },
+       { TM6010_REQ07_R12_AGC_GATE_STARTH, 0x07 },
+       { TM6010_REQ07_R13_AGC_GATE_STARTL, 0x3b },
+       { TM6010_REQ07_R14_AGC_GATE_WIDTH, 0x47 },
+       { TM6010_REQ07_R15_AGC_BP_DELAY, 0x6f },
+       { TM6010_REQ07_R17_HLOOP_MAXSTATE, 0xcd },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R20_HSYNC_RISING_EDGE_TIME, 0x3c },
+       { TM6010_REQ07_R21_HSYNC_PHASE_OFFSET, 0x3c },
+       { TM6010_REQ07_R2D_CHROMA_BURST_END, 0x48 },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R32_VSYNC_HLOCK_MIN, 0x74 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
+       { TM6010_REQ07_R34_VSYNC_AGC_MIN, 0x74 },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R36_VSYNC_VBI_MIN, 0x7a },
+       { TM6010_REQ07_R37_VSYNC_VBI_MAX, 0x26 },
+       { TM6010_REQ07_R38_VSYNC_THRESHOLD, 0x40 },
+       { TM6010_REQ07_R39_VSYNC_TIME_CONSTANT, 0x0a },
+       { TM6010_REQ07_R42_VBI_DATA_HIGH_LEVEL, 0x55 },
+       { TM6010_REQ07_R51_VBI_DATA_TYPE_LINE21, 0x11 },
+       { TM6010_REQ07_R55_VBI_LOOP_FILTER_GAIN, 0x01 },
+       { TM6010_REQ07_R57_VBI_LOOP_FILTER_P_GAIN, 0x02 },
+       { TM6010_REQ07_R58_VBI_CAPTION_DTO1, 0x35 },
+       { TM6010_REQ07_R59_VBI_CAPTION_DTO0, 0xa0 },
+       { TM6010_REQ07_R80_COMB_FILTER_TRESHOLD, 0x15 },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_RC1_TRESHOLD, 0xd0 },
+       { TM6010_REQ07_RC3_HSTART1, 0x88 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },               /* End of the soft reset */
+       { TM6010_REQ05_R18_IMASK7, 0x00 },
+};
+
+struct reg_init tm6010_init_tab[] = {
+       { TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE, 0x00 },
+       { TM6010_REQ07_RC4_HSTART0, 0xa0 },
+       { TM6010_REQ07_RC6_HEND0, 0x40 },
+       { TM6010_REQ07_RCA_VEND0, 0x31 },
+       { TM6010_REQ07_RCC_ACTIVE_VIDEO_IF, 0xe1 },
+       { TM6010_REQ07_RE0_DVIDEO_SOURCE, 0x03 },
+       { TM6010_REQ07_RFE_POWER_DOWN, 0x7f },
+
+       { TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0 },
+       { TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4 },
+       { TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8 },
+       { TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00 },
+       { TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2 },
+       { TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0 },
+       { TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2 },
+       { TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60 },
+       { TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc },
+
+       { TM6010_REQ07_R3F_RESET, 0x01 },
+       { TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00 },
+       { TM6010_REQ07_R01_VIDEO_CONTROL1, 0x07 },
+       { TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f },
+       { TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00 },
+       { TM6010_REQ07_R05_NOISE_THRESHOLD, 0x64 },
+       { TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01 },
+       { TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0x82 },
+       { TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0x36 },
+       { TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0x50 },
+       { TM6010_REQ07_R0C_CHROMA_AGC_CONTROL, 0x6a },
+       { TM6010_REQ07_R11_AGC_PEAK_CONTROL, 0xc9 },
+       { TM6010_REQ07_R12_AGC_GATE_STARTH, 0x07 },
+       { TM6010_REQ07_R13_AGC_GATE_STARTL, 0x3b },
+       { TM6010_REQ07_R14_AGC_GATE_WIDTH, 0x47 },
+       { TM6010_REQ07_R15_AGC_BP_DELAY, 0x6f },
+       { TM6010_REQ07_R17_HLOOP_MAXSTATE, 0xcd },
+       { TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e },
+       { TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b },
+       { TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2 },
+       { TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9 },
+       { TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c },
+       { TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc },
+       { TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc },
+       { TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd },
+       { TM6010_REQ07_R20_HSYNC_RISING_EDGE_TIME, 0x3c },
+       { TM6010_REQ07_R21_HSYNC_PHASE_OFFSET, 0x3c },
+       { TM6010_REQ07_R2D_CHROMA_BURST_END, 0x48 },
+       { TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88 },
+       { TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22 },
+       { TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61 },
+       { TM6010_REQ07_R32_VSYNC_HLOCK_MIN, 0x74 },
+       { TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c },
+       { TM6010_REQ07_R34_VSYNC_AGC_MIN, 0x74 },
+       { TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c },
+       { TM6010_REQ07_R36_VSYNC_VBI_MIN, 0x7a },
+       { TM6010_REQ07_R37_VSYNC_VBI_MAX, 0x26 },
+       { TM6010_REQ07_R38_VSYNC_THRESHOLD, 0x40 },
+       { TM6010_REQ07_R39_VSYNC_TIME_CONSTANT, 0x0a },
+       { TM6010_REQ07_R42_VBI_DATA_HIGH_LEVEL, 0x55 },
+       { TM6010_REQ07_R51_VBI_DATA_TYPE_LINE21, 0x11 },
+       { TM6010_REQ07_R55_VBI_LOOP_FILTER_GAIN, 0x01 },
+       { TM6010_REQ07_R57_VBI_LOOP_FILTER_P_GAIN, 0x02 },
+       { TM6010_REQ07_R58_VBI_CAPTION_DTO1, 0x35 },
+       { TM6010_REQ07_R59_VBI_CAPTION_DTO0, 0xa0 },
+       { TM6010_REQ07_R80_COMB_FILTER_TRESHOLD, 0x15 },
+       { TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42 },
+       { TM6010_REQ07_RC1_TRESHOLD, 0xd0 },
+       { TM6010_REQ07_RC3_HSTART1, 0x88 },
+       { TM6010_REQ07_R3F_RESET, 0x00 },
+
+       { TM6010_REQ05_R18_IMASK7, 0x00 },
+
+       { TM6010_REQ07_RD8_IR_LEADER1, 0xaa },
+       { TM6010_REQ07_RD8_IR_LEADER0, 0x30 },
+       { TM6010_REQ07_RD8_IR_PULSE_CNT1, 0x20 },
+       { TM6010_REQ07_RD8_IR_PULSE_CNT0, 0xd0 },
+       { REQ_04_EN_DISABLE_MCU_INT, 0x02, 0x00 },
+       { TM6010_REQ07_RD8_IR, 0x2f },
+
+       /* set remote wakeup key:any key wakeup */
+       { TM6010_REQ07_RE5_REMOTE_WAKEUP,  0xfe },
+       { TM6010_REQ07_RD8_IR_WAKEUP_SEL,  0xff },
+};
+
+int tm6000_init (struct tm6000_core *dev)
+{
+       int board, rc=0, i, size;
+       struct reg_init *tab;
+
+       if (dev->dev_type == TM6010) {
+               tab = tm6010_init_tab;
+               size = ARRAY_SIZE(tm6010_init_tab);
+       } else {
+               tab = tm6000_init_tab;
+               size = ARRAY_SIZE(tm6000_init_tab);
+       }
+
+       /* Load board's initialization table */
+       for (i=0; i< size; i++) {
+               rc= tm6000_set_reg (dev, tab[i].req, tab[i].reg, tab[i].val);
+               if (rc<0) {
+                       printk (KERN_ERR "Error %i while setting req %d, "
+                                        "reg %d to value %d\n", rc,
+                                        tab[i].req,tab[i].reg, tab[i].val);
+                       return rc;
+               }
+       }
+
+       msleep(5); /* Just to be conservative */
+
+       /* Check board version - maybe 10Moons specific */
+       board=tm6000_get_reg32 (dev, REQ_40_GET_VERSION, 0, 0);
+       if (board >=0) {
+               printk (KERN_INFO "Board version = 0x%08x\n",board);
+       } else {
+               printk (KERN_ERR "Error %i while retrieving board version\n",board);
+       }
+
+       rc = tm6000_cards_setup(dev);
+
+       return rc;
+}
+
+int tm6000_set_audio_bitrate(struct tm6000_core *dev, int bitrate)
+{
+       int val;
+
+       val=tm6000_get_reg (dev, REQ_07_SET_GET_AVREG, 0xeb, 0x0);
+printk("Original value=%d\n",val);
+       if (val<0)
+               return val;
+
+       val &= 0x0f;            /* Preserve the audio input control bits */
+       switch (bitrate) {
+       case 44100:
+               val|=0xd0;
+               dev->audio_bitrate=bitrate;
+               break;
+       case 48000:
+               val|=0x60;
+               dev->audio_bitrate=bitrate;
+               break;
+       }
+       val=tm6000_set_reg (dev, REQ_07_SET_GET_AVREG, 0xeb, val);
+
+       return val;
+}
+EXPORT_SYMBOL_GPL(tm6000_set_audio_bitrate);
diff --git a/drivers/staging/tm6000/tm6000-dvb.c b/drivers/staging/tm6000/tm6000-dvb.c
new file mode 100644 (file)
index 0000000..eafc89c
--- /dev/null
@@ -0,0 +1,346 @@
+/*
+   tm6000-dvb.c - dvb-t support for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.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 version 2
+
+   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 <linux/kernel.h>
+#include <linux/usb.h>
+
+#include "tm6000.h"
+#include "tm6000-regs.h"
+
+#include "zl10353.h"
+
+#include <media/tuner.h>
+
+#include "tuner-xc2028.h"
+
+static void inline print_err_status (struct tm6000_core *dev,
+                                    int packet, int status)
+{
+       char *errmsg = "Unknown";
+
+       switch(status) {
+       case -ENOENT:
+               errmsg = "unlinked synchronuously";
+               break;
+       case -ECONNRESET:
+               errmsg = "unlinked asynchronuously";
+               break;
+       case -ENOSR:
+               errmsg = "Buffer error (overrun)";
+               break;
+       case -EPIPE:
+               errmsg = "Stalled (device not responding)";
+               break;
+       case -EOVERFLOW:
+               errmsg = "Babble (bad cable?)";
+               break;
+       case -EPROTO:
+               errmsg = "Bit-stuff error (bad cable?)";
+               break;
+       case -EILSEQ:
+               errmsg = "CRC/Timeout (could be anything)";
+               break;
+       case -ETIME:
+               errmsg = "Device does not respond";
+               break;
+       }
+       if (packet<0) {
+               dprintk(dev, 1, "URB status %d [%s].\n",
+                       status, errmsg);
+       } else {
+               dprintk(dev, 1, "URB packet %d, status %d [%s].\n",
+                       packet, status, errmsg);
+       }
+}
+
+static void tm6000_urb_received(struct urb *urb)
+{
+       int ret;
+       struct tm6000_core* dev = urb->context;
+
+       if(urb->status != 0) {
+               print_err_status (dev,0,urb->status);
+       }
+       else if(urb->actual_length>0){
+               dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
+                                                  urb->actual_length);
+       }
+
+       if(dev->dvb->streams > 0) {
+               ret = usb_submit_urb(urb, GFP_ATOMIC);
+               if(ret < 0) {
+                       printk(KERN_ERR "tm6000:  error %s\n", __FUNCTION__);
+                       kfree(urb->transfer_buffer);
+                       usb_free_urb(urb);
+               }
+       }
+}
+
+int tm6000_start_stream(struct tm6000_core *dev)
+{
+       int ret;
+       unsigned int pipe, size;
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       printk(KERN_INFO "tm6000: got start stream request %s\n",__FUNCTION__);
+
+       tm6000_init_digital_mode(dev);
+
+       dvb->bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if(dvb->bulk_urb == NULL) {
+               printk(KERN_ERR "tm6000: couldn't allocate urb\n");
+               return -ENOMEM;
+       }
+
+       pipe = usb_rcvbulkpipe(dev->udev, dev->bulk_in.endp->desc.bEndpointAddress
+                                                         & USB_ENDPOINT_NUMBER_MASK);
+
+       size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
+       size = size * 15; /* 512 x 8 or 12 or 15 */
+
+       dvb->bulk_urb->transfer_buffer = kzalloc(size, GFP_KERNEL);
+       if(dvb->bulk_urb->transfer_buffer == NULL) {
+               usb_free_urb(dvb->bulk_urb);
+               printk(KERN_ERR "tm6000: couldn't allocate transfer buffer!\n");
+               return -ENOMEM;
+       }
+
+       usb_fill_bulk_urb(dvb->bulk_urb, dev->udev, pipe,
+                                                dvb->bulk_urb->transfer_buffer,
+                                                size,
+                                                tm6000_urb_received, dev);
+
+       ret = usb_clear_halt(dev->udev, pipe);
+       if(ret < 0) {
+               printk(KERN_ERR "tm6000: error %i in %s during pipe reset\n",ret,__FUNCTION__);
+               return ret;
+       }
+       else {
+               printk(KERN_ERR "tm6000: pipe resetted\n");
+       }
+
+/*     mutex_lock(&tm6000_driver.open_close_mutex); */
+       ret = usb_submit_urb(dvb->bulk_urb, GFP_KERNEL);
+
+/*     mutex_unlock(&tm6000_driver.open_close_mutex); */
+       if (ret) {
+               printk(KERN_ERR "tm6000: submit of urb failed (error=%i)\n",ret);
+
+               kfree(dvb->bulk_urb->transfer_buffer);
+               usb_free_urb(dvb->bulk_urb);
+               return ret;
+       }
+
+       return 0;
+}
+
+void tm6000_stop_stream(struct tm6000_core *dev)
+{
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       if(dvb->bulk_urb) {
+               printk (KERN_INFO "urb killing\n");
+               usb_kill_urb(dvb->bulk_urb);
+               printk (KERN_INFO "urb buffer free\n");
+               kfree(dvb->bulk_urb->transfer_buffer);
+               usb_free_urb(dvb->bulk_urb);
+               dvb->bulk_urb = NULL;
+       }
+}
+
+int tm6000_start_feed(struct dvb_demux_feed *feed)
+{
+       struct dvb_demux *demux = feed->demux;
+       struct tm6000_core *dev = demux->priv;
+       struct tm6000_dvb *dvb = dev->dvb;
+       printk(KERN_INFO "tm6000: got start feed request %s\n",__FUNCTION__);
+
+       mutex_lock(&dvb->mutex);
+       if(dvb->streams == 0) {
+               dvb->streams = 1;
+/*             mutex_init(&tm6000_dev->streming_mutex); */
+               tm6000_start_stream(dev);
+       }
+       else {
+               ++(dvb->streams);
+       }
+       mutex_unlock(&dvb->mutex);
+
+       return 0;
+}
+
+int tm6000_stop_feed(struct dvb_demux_feed *feed) {
+       struct dvb_demux *demux = feed->demux;
+       struct tm6000_core *dev = demux->priv;
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       printk(KERN_INFO "tm6000: got stop feed request %s\n",__FUNCTION__);
+
+       mutex_lock(&dvb->mutex);
+
+       printk (KERN_INFO "stream %#x\n", dvb->streams);
+       --(dvb->streams);
+       if(dvb->streams == 0) {
+               printk (KERN_INFO "stop stream\n");
+               tm6000_stop_stream(dev);
+/*             mutex_destroy(&tm6000_dev->streaming_mutex); */
+       }
+       mutex_unlock(&dvb->mutex);
+/*     mutex_destroy(&tm6000_dev->streaming_mutex); */
+
+       return 0;
+}
+
+int tm6000_dvb_attach_frontend(struct tm6000_core *dev)
+{
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       if(dev->caps.has_zl10353) {
+               struct zl10353_config config =
+                                   {.demod_address = dev->demod_addr,
+                                    .no_tuner = 1,
+                                    .parallel_ts = 1,
+                                    .if2 = 45700,
+                                    .disable_i2c_gate_ctrl = 1,
+                                   };
+
+               dvb->frontend = dvb_attach(zl10353_attach, &config,
+                                                          &dev->i2c_adap);
+       }
+       else {
+               printk(KERN_ERR "tm6000: no frontend defined for the device!\n");
+               return -1;
+       }
+
+       return (!dvb->frontend) ? -1 : 0;
+}
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+int tm6000_dvb_register(struct tm6000_core *dev)
+{
+       int ret = -1;
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       mutex_init(&dvb->mutex);
+
+       dvb->streams = 0;
+
+       /* attach the frontend */
+       ret = tm6000_dvb_attach_frontend(dev);
+       if(ret < 0) {
+               printk(KERN_ERR "tm6000: couldn't attach the frontend!\n");
+               goto err;
+       }
+
+       ret = dvb_register_adapter(&dvb->adapter, "Trident TVMaster 6000 DVB-T",
+                                                         THIS_MODULE, &dev->udev->dev, adapter_nr);
+       dvb->adapter.priv = dev;
+
+       if (dvb->frontend) {
+               struct xc2028_config cfg = {
+                       .i2c_adap = &dev->i2c_adap,
+                       .i2c_addr = dev->tuner_addr,
+               };
+
+               dvb->frontend->callback = tm6000_tuner_callback;
+               ret = dvb_register_frontend(&dvb->adapter, dvb->frontend);
+               if (ret < 0) {
+                       printk(KERN_ERR
+                               "tm6000: couldn't register frontend\n");
+                       goto adapter_err;
+               }
+
+               if (!dvb_attach(xc2028_attach, dvb->frontend, &cfg)) {
+                       printk(KERN_ERR "tm6000: couldn't register "
+                                       "frontend (xc3028)\n");
+                       ret = -EINVAL;
+                       goto frontend_err;
+               }
+               printk(KERN_INFO "tm6000: XC2028/3028 asked to be "
+                                "attached to frontend!\n");
+       } else {
+               printk(KERN_ERR "tm6000: no frontend found\n");
+       }
+
+       dvb->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING
+                                                           | DMX_MEMORY_BASED_FILTERING;
+       dvb->demux.priv = dev;
+       dvb->demux.filternum = 8;
+       dvb->demux.feednum = 8;
+       dvb->demux.start_feed = tm6000_start_feed;
+       dvb->demux.stop_feed = tm6000_stop_feed;
+       dvb->demux.write_to_decoder = NULL;
+       ret = dvb_dmx_init(&dvb->demux);
+       if(ret < 0) {
+               printk("tm6000: dvb_dmx_init failed (errno = %d)\n", ret);
+               goto frontend_err;
+       }
+
+       dvb->dmxdev.filternum = dev->dvb->demux.filternum;
+       dvb->dmxdev.demux = &dev->dvb->demux.dmx;
+       dvb->dmxdev.capabilities = 0;
+
+       ret =  dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
+       if(ret < 0) {
+               printk("tm6000: dvb_dmxdev_init failed (errno = %d)\n", ret);
+               goto dvb_dmx_err;
+       }
+
+       return 0;
+
+dvb_dmx_err:
+       dvb_dmx_release(&dvb->demux);
+frontend_err:
+       if(dvb->frontend) {
+               dvb_frontend_detach(dvb->frontend);
+               dvb_unregister_frontend(dvb->frontend);
+       }
+adapter_err:
+       dvb_unregister_adapter(&dvb->adapter);
+err:
+       return ret;
+}
+
+void tm6000_dvb_unregister(struct tm6000_core *dev)
+{
+       struct tm6000_dvb *dvb = dev->dvb;
+
+       if(dvb->bulk_urb != NULL) {
+               struct urb *bulk_urb = dvb->bulk_urb;
+
+               kfree(bulk_urb->transfer_buffer);
+               bulk_urb->transfer_buffer = NULL;
+               usb_unlink_urb(bulk_urb);
+               usb_free_urb(bulk_urb);
+       }
+
+/*     mutex_lock(&tm6000_driver.open_close_mutex); */
+       if(dvb->frontend) {
+               dvb_frontend_detach(dvb->frontend);
+               dvb_unregister_frontend(dvb->frontend);
+       }
+
+       dvb_dmxdev_release(&dvb->dmxdev);
+       dvb_dmx_release(&dvb->demux);
+       dvb_unregister_adapter(&dvb->adapter);
+       mutex_destroy(&dvb->mutex);
+/*     mutex_unlock(&tm6000_driver.open_close_mutex); */
+
+}
diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
new file mode 100644 (file)
index 0000000..94ff489
--- /dev/null
@@ -0,0 +1,370 @@
+/*
+   tm6000-i2c.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
+       - Fix SMBus Read Byte command
+
+   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
+
+   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 <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/usb.h>
+#include <linux/i2c.h>
+
+#include "tm6000.h"
+#include "tm6000-regs.h"
+#include <media/v4l2-common.h>
+#include <media/tuner.h>
+#include "tuner-xc2028.h"
+
+
+/*FIXME: Hack to avoid needing to patch i2c-id.h */
+#define I2C_HW_B_TM6000 I2C_HW_B_EM28XX
+/* ----------------------------------------------------------- */
+
+static unsigned int i2c_debug = 0;
+module_param(i2c_debug, int, 0644);
+MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
+
+#define i2c_dprintk(lvl,fmt, args...) if (i2c_debug>=lvl) do{ \
+                       printk(KERN_DEBUG "%s at %s: " fmt, \
+                       dev->name, __FUNCTION__ , ##args); } while (0)
+
+static int tm6000_i2c_send_regs(struct tm6000_core *dev, unsigned char addr,
+                               __u8 reg, char *buf, int len)
+{
+       int rc;
+       unsigned int tsleep;
+       unsigned int i2c_packet_limit = 16;
+
+       if (dev->dev_type == TM6010)
+               i2c_packet_limit = 64;
+
+       if (!buf)
+               return -1;
+
+       if (len < 1 || len > i2c_packet_limit) {
+               printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
+                       len, i2c_packet_limit);
+               return -1;
+       }
+
+       /* capture mutex */
+       rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
+               USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN,
+               addr | reg << 8, 0, buf, len);
+
+       if (rc < 0) {
+               /* release mutex */
+               return rc;
+       }
+
+       /* Calculate delay time, 14000us for 64 bytes */
+       tsleep = ((len * 200) + 200 + 1000) / 1000;
+       msleep(tsleep);
+
+       /* release mutex */
+       return rc;
+}
+
+/* Generic read - doesn't work fine with 16bit registers */
+static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr,
+                               __u8 reg, char *buf, int len)
+{
+       int rc;
+       u8 b[2];
+       unsigned int i2c_packet_limit = 16;
+
+       if (dev->dev_type == TM6010)
+               i2c_packet_limit = 64;
+
+       if (!buf)
+               return -1;
+
+       if (len < 1 || len > i2c_packet_limit) {
+               printk(KERN_ERR "Incorrect length of i2c packet = %d, limit set to %d\n",
+                       len, i2c_packet_limit);
+               return -1;
+       }
+
+       /* capture mutex */
+       if ((dev->caps.has_zl10353) && (dev->demod_addr << 1 == addr) && (reg % 2 == 0)) {
+               /*
+                * Workaround an I2C bug when reading from zl10353
+                */
+               reg -= 1;
+               len += 1;
+
+               rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, b, len);
+
+               *buf = b[1];
+       } else {
+               rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                       REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len);
+       }
+
+       /* release mutex */
+       return rc;
+}
+
+/*
+ * read from a 16bit register
+ * for example xc2028, xc3028 or xc3028L
+ */
+static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr,
+                                 __u16 reg, char *buf, int len)
+{
+       int rc;
+       unsigned char ureg;
+
+       if (!buf || len != 2)
+               return -1;
+
+       /* capture mutex */
+       if (dev->dev_type == TM6010) {
+               ureg = reg & 0xFF;
+               rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR |
+                       USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN,
+                       addr | (reg & 0xFF00), 0, &ureg, 1);
+
+               if (rc < 0) {
+                       /* release mutex */
+                       return rc;
+               }
+
+               msleep(1400 / 1000);
+               rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
+                       USB_RECIP_DEVICE, REQ_35_AFTEK_TUNER_READ,
+                       reg, 0, buf, len);
+       } else {
+               rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR |
+                       USB_RECIP_DEVICE, REQ_14_SET_GET_I2C_WR2_RDN,
+                       addr, reg, buf, len);
+       }
+
+       /* release mutex */
+       return rc;
+}
+
+static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
+                          struct i2c_msg msgs[], int num)
+{
+       struct tm6000_core *dev = i2c_adap->algo_data;
+       int addr, rc, i, byte;
+
+       if (num <= 0)
+               return 0;
+       for (i = 0; i < num; i++) {
+               addr = (msgs[i].addr << 1) & 0xff;
+               i2c_dprintk(2,"%s %s addr=0x%x len=%d:",
+                        (msgs[i].flags & I2C_M_RD) ? "read" : "write",
+                        i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len);
+               if (msgs[i].flags & I2C_M_RD) {
+                       /* read request without preceding register selection */
+                       /*
+                        * The TM6000 only supports a read transaction
+                        * immediately after a 1 or 2 byte write to select
+                        * a register.  We cannot fulfil this request.
+                        */
+                       i2c_dprintk(2, " read without preceding write not"
+                                      " supported");
+                       rc = -EOPNOTSUPP;
+                       goto err;
+               } else if (i + 1 < num && msgs[i].len <= 2 &&
+                          (msgs[i + 1].flags & I2C_M_RD) &&
+                          msgs[i].addr == msgs[i + 1].addr) {
+                       /* 1 or 2 byte write followed by a read */
+                       if (i2c_debug >= 2)
+                               for (byte = 0; byte < msgs[i].len; byte++)
+                                       printk(" %02x", msgs[i].buf[byte]);
+                       i2c_dprintk(2, "; joined to read %s len=%d:",
+                                   i == num - 2 ? "stop" : "nonstop",
+                                   msgs[i + 1].len);
+
+                       if (msgs[i].len == 2) {
+                               rc = tm6000_i2c_recv_regs16(dev, addr,
+                                       msgs[i].buf[0] << 8 | msgs[i].buf[1],
+                                       msgs[i + 1].buf, msgs[i + 1].len);
+                       } else {
+                               rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0],
+                                       msgs[i + 1].buf, msgs[i + 1].len);
+                       }
+
+                       i++;
+
+                       if (addr == dev->tuner_addr << 1) {
+                               tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
+                               tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
+                       }
+                       if (i2c_debug >= 2)
+                               for (byte = 0; byte < msgs[i].len; byte++)
+                                       printk(" %02x", msgs[i].buf[byte]);
+               } else {
+                       /* write bytes */
+                       if (i2c_debug >= 2)
+                               for (byte = 0; byte < msgs[i].len; byte++)
+                                       printk(" %02x", msgs[i].buf[byte]);
+                       rc = tm6000_i2c_send_regs(dev, addr, msgs[i].buf[0],
+                               msgs[i].buf + 1, msgs[i].len - 1);
+
+                       if (addr == dev->tuner_addr  << 1) {
+                               tm6000_set_reg(dev, REQ_50_SET_START, 0, 0);
+                               tm6000_set_reg(dev, REQ_51_SET_STOP, 0, 0);
+                       }
+               }
+               if (i2c_debug >= 2)
+                       printk("\n");
+               if (rc < 0)
+                       goto err;
+       }
+
+       return num;
+err:
+       i2c_dprintk(2," ERROR: %i\n", rc);
+       return rc;
+}
+
+static int tm6000_i2c_eeprom(struct tm6000_core *dev,
+                            unsigned char *eedata, int len)
+{
+       int i, rc;
+       unsigned char *p = eedata;
+       unsigned char bytes[17];
+
+       dev->i2c_client.addr = 0xa0 >> 1;
+
+       bytes[16] = '\0';
+       for (i = 0; i < len; ) {
+       *p = i;
+       rc = tm6000_i2c_recv_regs(dev, 0xa0, i, p, 1);
+               if (rc < 1) {
+                       if (p == eedata)
+                               goto noeeprom;
+                       else {
+                               printk(KERN_WARNING
+                               "%s: i2c eeprom read error (err=%d)\n",
+                               dev->name, rc);
+                       }
+                       return -1;
+               }
+               p++;
+               if (0 == (i % 16))
+                       printk(KERN_INFO "%s: i2c eeprom %02x:", dev->name, i);
+               printk(" %02x", eedata[i]);
+               if ((eedata[i] >= ' ') && (eedata[i] <= 'z')) {
+                       bytes[i%16] = eedata[i];
+               } else {
+                       bytes[i%16]='.';
+               }
+
+               i++;
+
+               if (0 == (i % 16)) {
+                       bytes[16] = '\0';
+                       printk("  %s\n", bytes);
+               }
+       }
+       if (0 != (i%16)) {
+               bytes[i%16] = '\0';
+               for (i %= 16; i < 16; i++)
+                       printk("   ");
+       }
+       printk("  %s\n", bytes);
+
+       return 0;
+
+noeeprom:
+       printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
+                      dev->name, rc);
+       return rc;
+}
+
+/* ----------------------------------------------------------- */
+
+/*
+ * functionality()
+ */
+static u32 functionality(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_SMBUS_EMUL;
+}
+
+#define mass_write(addr, reg, data...)                                 \
+       { const static u8 _val[] = data;                                \
+       rc=tm6000_read_write_usb(dev,USB_DIR_OUT | USB_TYPE_VENDOR,     \
+       REQ_16_SET_GET_I2C_WR1_RDN,(reg<<8)+addr, 0x00, (u8 *) _val,    \
+       ARRAY_SIZE(_val));                                              \
+       if (rc<0) {                                                     \
+               printk(KERN_ERR "Error on line %d: %d\n",__LINE__,rc);  \
+               return rc;                                              \
+       }                                                               \
+       msleep (10);                                                    \
+       }
+
+static struct i2c_algorithm tm6000_algo = {
+       .master_xfer   = tm6000_i2c_xfer,
+       .functionality = functionality,
+};
+
+static struct i2c_adapter tm6000_adap_template = {
+       .owner = THIS_MODULE,
+       .class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
+       .name = "tm6000",
+       .id = I2C_HW_B_TM6000,
+       .algo = &tm6000_algo,
+};
+
+static struct i2c_client tm6000_client_template = {
+       .name = "tm6000 internal",
+};
+
+/* ----------------------------------------------------------- */
+
+/*
+ * tm6000_i2c_register()
+ * register i2c bus
+ */
+int tm6000_i2c_register(struct tm6000_core *dev)
+{
+       unsigned char eedata[256];
+
+       dev->i2c_adap = tm6000_adap_template;
+       dev->i2c_adap.dev.parent = &dev->udev->dev;
+       strcpy(dev->i2c_adap.name, dev->name);
+       dev->i2c_adap.algo_data = dev;
+       i2c_add_adapter(&dev->i2c_adap);
+
+       dev->i2c_client = tm6000_client_template;
+       dev->i2c_client.adapter = &dev->i2c_adap;
+
+       i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev);
+
+       tm6000_i2c_eeprom(dev, eedata, sizeof(eedata));
+
+       return 0;
+}
+
+/*
+ * tm6000_i2c_unregister()
+ * unregister i2c_bus
+ */
+int tm6000_i2c_unregister(struct tm6000_core *dev)
+{
+       i2c_del_adapter(&dev->i2c_adap);
+       return 0;
+}
diff --git a/drivers/staging/tm6000/tm6000-regs.h b/drivers/staging/tm6000/tm6000-regs.h
new file mode 100644 (file)
index 0000000..1c5289c
--- /dev/null
@@ -0,0 +1,541 @@
+/*
+   tm6000-regs.h - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   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
+
+   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.
+ */
+
+/*
+ * Define TV Master TM5600/TM6000/TM6010 Request codes
+ */
+#define REQ_00_SET_IR_VALUE            0
+#define REQ_01_SET_WAKEUP_IRCODE       1
+#define REQ_02_GET_IR_CODE             2
+#define REQ_03_SET_GET_MCU_PIN         3
+#define REQ_04_EN_DISABLE_MCU_INT      4
+#define REQ_05_SET_GET_USBREG          5
+       /* Write: RegNum, Value, 0 */
+       /* Read : RegNum, Value, 1, RegStatus */
+#define REQ_06_SET_GET_USBREG_BIT      6
+#define REQ_07_SET_GET_AVREG           7
+       /* Write: RegNum, Value, 0 */
+       /* Read : RegNum, Value, 1, RegStatus */
+#define REQ_08_SET_GET_AVREG_BIT       8
+#define REQ_09_SET_GET_TUNER_FQ                9
+#define REQ_10_SET_TUNER_SYSTEM                10
+#define REQ_11_SET_EEPROM_ADDR         11
+#define REQ_12_SET_GET_EEPROMBYTE      12
+#define REQ_13_GET_EEPROM_SEQREAD      13
+#define REQ_14_SET_GET_I2C_WR2_RDN     14
+#define REQ_15_SET_GET_I2CBYTE         15
+       /* Write: Subaddr, Slave Addr, value, 0 */
+       /* Read : Subaddr, Slave Addr, value, 1 */
+#define REQ_16_SET_GET_I2C_WR1_RDN     16
+       /* Subaddr, Slave Addr, 0, length */
+#define REQ_17_SET_GET_I2CFP           17
+       /* Write: Slave Addr, register, value */
+       /* Read : Slave Addr, register, 2, data */
+#define REQ_20_DATA_TRANSFER           20
+#define REQ_30_I2C_WRITE               30
+#define REQ_31_I2C_READ                        31
+#define REQ_35_AFTEK_TUNER_READ                35
+#define REQ_40_GET_VERSION             40
+#define REQ_50_SET_START               50
+#define REQ_51_SET_STOP                        51
+#define REQ_52_TRANSMIT_DATA           52
+#define REQ_53_SPI_INITIAL             53
+#define REQ_54_SPI_SETSTART            54
+#define REQ_55_SPI_INOUTDATA           55
+#define REQ_56_SPI_SETSTOP             56
+
+/*
+ * Define TV Master TM5600/TM6000/TM6010 GPIO lines
+ */
+
+#define TM6000_GPIO_CLK                0x101
+#define TM6000_GPIO_DATA       0x100
+
+#define TM6000_GPIO_1          0x102
+#define TM6000_GPIO_2          0x103
+#define TM6000_GPIO_3          0x104
+#define TM6000_GPIO_4          0x300
+#define TM6000_GPIO_5          0x301
+#define TM6000_GPIO_6          0x304
+#define TM6000_GPIO_7          0x305
+
+/* tm6010 defines GPIO with different values */
+#define TM6010_GPIO_0      0x0102
+#define TM6010_GPIO_1      0x0103
+#define TM6010_GPIO_2      0x0104
+#define TM6010_GPIO_3      0x0105
+#define TM6010_GPIO_4      0x0106
+#define TM6010_GPIO_5      0x0107
+#define TM6010_GPIO_6      0x0300
+#define TM6010_GPIO_7      0x0301
+#define TM6010_GPIO_9      0x0305
+/*
+ * Define TV Master TM5600/TM6000/TM6010 URB message codes and length
+ */
+
+enum {
+       TM6000_URB_MSG_VIDEO=1,
+       TM6000_URB_MSG_AUDIO,
+       TM6000_URB_MSG_VBI,
+       TM6000_URB_MSG_PTS,
+       TM6000_URB_MSG_ERR,
+};
+
+/* Define TM6000/TM6010 Video decoder registers */
+#define TM6010_REQ07_R00_VIDEO_CONTROL0                        0x07, 0x00
+#define TM6010_REQ07_R01_VIDEO_CONTROL1                        0x07, 0x01
+#define TM6010_REQ07_R02_VIDEO_CONTROL2                        0x07, 0x02
+#define TM6010_REQ07_R03_YC_SEP_CONTROL                        0x07, 0x03
+#define TM6010_REQ07_R04_LUMA_HAGC_CONTROL             0x07, 0x04
+#define TM6010_REQ07_R05_NOISE_THRESHOLD               0x07, 0x05
+#define TM6010_REQ07_R06_AGC_GATE_THRESHOLD            0x07, 0x06
+#define TM6010_REQ07_R07_OUTPUT_CONTROL                        0x07, 0x07
+#define TM6010_REQ07_R08_LUMA_CONTRAST_ADJ             0x07, 0x08
+#define TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ           0x07, 0x09
+#define TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ         0x07, 0x0a
+#define TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ          0x07, 0x0b
+#define TM6010_REQ07_R0C_CHROMA_AGC_CONTROL            0x07, 0x0c
+#define TM6010_REQ07_R0D_CHROMA_KILL_LEVEL             0x07, 0x0d
+#define TM6010_REQ07_R0F_CHROMA_AUTO_POSITION          0x07, 0x0f
+#define TM6010_REQ07_R10_AGC_PEAK_NOMINAL              0x07, 0x10
+#define TM6010_REQ07_R11_AGC_PEAK_CONTROL              0x07, 0x11
+#define TM6010_REQ07_R12_AGC_GATE_STARTH               0x07, 0x12
+#define TM6010_REQ07_R13_AGC_GATE_STARTL               0x07, 0x13
+#define TM6010_REQ07_R14_AGC_GATE_WIDTH                        0x07, 0x14
+#define TM6010_REQ07_R15_AGC_BP_DELAY                  0x07, 0x15
+#define TM6010_REQ07_R16_LOCK_COUNT                    0x07, 0x16
+#define TM6010_REQ07_R17_HLOOP_MAXSTATE                        0x07, 0x17
+#define TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3         0x07, 0x18
+#define TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2         0x07, 0x19
+#define TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1         0x07, 0x1a
+#define TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0         0x07, 0x1b
+#define TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3          0x07, 0x1c
+#define TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2          0x07, 0x1d
+#define TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1          0x07, 0x1e
+#define TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0          0x07, 0x1f
+#define TM6010_REQ07_R20_HSYNC_RISING_EDGE_TIME                0x07, 0x20
+#define TM6010_REQ07_R21_HSYNC_PHASE_OFFSET            0x07, 0x21
+#define TM6010_REQ07_R22_HSYNC_PLL_START_TIME          0x07, 0x22
+#define TM6010_REQ07_R23_HSYNC_PLL_END_TIME            0x07, 0x23
+#define TM6010_REQ07_R24_HSYNC_TIP_START_TIME          0x07, 0x24
+#define TM6010_REQ07_R25_HSYNC_TIP_END_TIME            0x07, 0x25
+#define TM6010_REQ07_R26_HSYNC_RISING_EDGE_START       0x07, 0x26
+#define TM6010_REQ07_R27_HSYNC_RISING_EDGE_END         0x07, 0x27
+#define TM6010_REQ07_R28_BACKPORCH_START               0x07, 0x28
+#define TM6010_REQ07_R29_BACKPORCH_END                 0x07, 0x29
+#define TM6010_REQ07_R2A_HSYNC_FILTER_START            0x07, 0x2a
+#define TM6010_REQ07_R2B_HSYNC_FILTER_END              0x07, 0x2b
+#define TM6010_REQ07_R2C_CHROMA_BURST_START            0x07, 0x2c
+#define TM6010_REQ07_R2D_CHROMA_BURST_END              0x07, 0x2d
+#define TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART           0x07, 0x2e
+#define TM6010_REQ07_R2F_ACTIVE_VIDEO_HWIDTH           0x07, 0x2f
+#define TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART           0x07, 0x30
+#define TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT           0x07, 0x31
+#define TM6010_REQ07_R32_VSYNC_HLOCK_MIN               0x07, 0x32
+#define TM6010_REQ07_R33_VSYNC_HLOCK_MAX               0x07, 0x33
+#define TM6010_REQ07_R34_VSYNC_AGC_MIN                 0x07, 0x34
+#define TM6010_REQ07_R35_VSYNC_AGC_MAX                 0x07, 0x35
+#define TM6010_REQ07_R36_VSYNC_VBI_MIN                 0x07, 0x36
+#define TM6010_REQ07_R37_VSYNC_VBI_MAX                 0x07, 0x37
+#define TM6010_REQ07_R38_VSYNC_THRESHOLD               0x07, 0x38
+#define TM6010_REQ07_R39_VSYNC_TIME_CONSTANT           0x07, 0x39
+#define TM6010_REQ07_R3A_STATUS1                       0x07, 0x3a
+#define TM6010_REQ07_R3B_STATUS2                       0x07, 0x3b
+#define TM6010_REQ07_R3C_STATUS3                       0x07, 0x3c
+#define TM6010_REQ07_R3F_RESET                         0x07, 0x3f
+#define TM6010_REQ07_R40_TELETEXT_VBI_CODE0            0x07, 0x40
+#define TM6010_REQ07_R41_TELETEXT_VBI_CODE1            0x07, 0x41
+#define TM6010_REQ07_R42_VBI_DATA_HIGH_LEVEL           0x07, 0x42
+#define TM6010_REQ07_R43_VBI_DATA_TYPE_LINE7           0x07, 0x43
+#define TM6010_REQ07_R44_VBI_DATA_TYPE_LINE8           0x07, 0x44
+#define TM6010_REQ07_R45_VBI_DATA_TYPE_LINE9           0x07, 0x45
+#define TM6010_REQ07_R46_VBI_DATA_TYPE_LINE10          0x07, 0x46
+#define TM6010_REQ07_R47_VBI_DATA_TYPE_LINE11          0x07, 0x47
+#define TM6010_REQ07_R48_VBI_DATA_TYPE_LINE12          0x07, 0x48
+#define TM6010_REQ07_R49_VBI_DATA_TYPE_LINE13          0x07, 0x49
+#define TM6010_REQ07_R4A_VBI_DATA_TYPE_LINE14          0x07, 0x4a
+#define TM6010_REQ07_R4B_VBI_DATA_TYPE_LINE15          0x07, 0x4b
+#define TM6010_REQ07_R4C_VBI_DATA_TYPE_LINE16          0x07, 0x4c
+#define TM6010_REQ07_R4D_VBI_DATA_TYPE_LINE17          0x07, 0x4d
+#define TM6010_REQ07_R4E_VBI_DATA_TYPE_LINE18          0x07, 0x4e
+#define TM6010_REQ07_R4F_VBI_DATA_TYPE_LINE19          0x07, 0x4f
+#define TM6010_REQ07_R50_VBI_DATA_TYPE_LINE20          0x07, 0x50
+#define TM6010_REQ07_R51_VBI_DATA_TYPE_LINE21          0x07, 0x51
+#define TM6010_REQ07_R52_VBI_DATA_TYPE_LINE22          0x07, 0x52
+#define TM6010_REQ07_R53_VBI_DATA_TYPE_LINE23          0x07, 0x53
+#define TM6010_REQ07_R54_VBI_DATA_TYPE_RLINES          0x07, 0x54
+#define TM6010_REQ07_R55_VBI_LOOP_FILTER_GAIN          0x07, 0x55
+#define TM6010_REQ07_R56_VBI_LOOP_FILTER_I_GAIN                0x07, 0x56
+#define TM6010_REQ07_R57_VBI_LOOP_FILTER_P_GAIN                0x07, 0x57
+#define TM6010_REQ07_R58_VBI_CAPTION_DTO1              0x07, 0x58
+#define TM6010_REQ07_R59_VBI_CAPTION_DTO0              0x07, 0x59
+#define TM6010_REQ07_R5A_VBI_TELETEXT_DTO1             0x07, 0x5a
+#define TM6010_REQ07_R5B_VBI_TELETEXT_DTO0             0x07, 0x5b
+#define TM6010_REQ07_R5C_VBI_WSS625_DTO1               0x07, 0x5c
+#define TM6010_REQ07_R5D_VBI_WSS625_DTO0               0x07, 0x5d
+#define TM6010_REQ07_R5E_VBI_CAPTION_FRAME_START       0x07, 0x5e
+#define TM6010_REQ07_R5F_VBI_WSS625_FRAME_START                0x07, 0x5f
+#define TM6010_REQ07_R60_TELETEXT_FRAME_START          0x07, 0x60
+#define TM6010_REQ07_R61_VBI_CCDATA1                   0x07, 0x61
+#define TM6010_REQ07_R62_VBI_CCDATA2                   0x07, 0x62
+#define TM6010_REQ07_R63_VBI_WSS625_DATA1              0x07, 0x63
+#define TM6010_REQ07_R64_VBI_WSS625_DATA2              0x07, 0x64
+#define TM6010_REQ07_R65_VBI_DATA_STATUS               0x07, 0x65
+#define TM6010_REQ07_R66_VBI_CAPTION_START             0x07, 0x66
+#define TM6010_REQ07_R67_VBI_WSS625_START              0x07, 0x67
+#define TM6010_REQ07_R68_VBI_TELETEXT_START            0x07, 0x68
+#define TM6010_REQ07_R70_HSYNC_DTO_INC_STATUS3         0x07, 0x70
+#define TM6010_REQ07_R71_HSYNC_DTO_INC_STATUS2         0x07, 0x71
+#define TM6010_REQ07_R72_HSYNC_DTO_INC_STATUS1         0x07, 0x72
+#define TM6010_REQ07_R73_HSYNC_DTO_INC_STATUS0         0x07, 0x73
+#define TM6010_REQ07_R74_CHROMA_DTO_INC_STATUS3                0x07, 0x74
+#define TM6010_REQ07_R75_CHROMA_DTO_INC_STATUS2                0x07, 0x75
+#define TM6010_REQ07_R76_CHROMA_DTO_INC_STATUS1                0x07, 0x76
+#define TM6010_REQ07_R77_CHROMA_DTO_INC_STATUS0                0x07, 0x77
+#define TM6010_REQ07_R78_AGC_AGAIN_STATUS              0x07, 0x78
+#define TM6010_REQ07_R79_AGC_DGAIN_STATUS              0x07, 0x79
+#define TM6010_REQ07_R7A_CHROMA_MAG_STATUS             0x07, 0x7a
+#define TM6010_REQ07_R7B_CHROMA_GAIN_STATUS1           0x07, 0x7b
+#define TM6010_REQ07_R7C_CHROMA_GAIN_STATUS0           0x07, 0x7c
+#define TM6010_REQ07_R7D_CORDIC_FREQ_STATUS            0x07, 0x7d
+#define TM6010_REQ07_R7F_STATUS_NOISE                  0x07, 0x7f
+#define TM6010_REQ07_R80_COMB_FILTER_TRESHOLD          0x07, 0x80
+#define TM6010_REQ07_R82_COMB_FILTER_CONFIG            0x07, 0x82
+#define TM6010_REQ07_R83_CHROMA_LOCK_CONFIG            0x07, 0x83
+#define TM6010_REQ07_R84_NOISE_NTSC_C                  0x07, 0x84
+#define TM6010_REQ07_R85_NOISE_PAL_C                   0x07, 0x85
+#define TM6010_REQ07_R86_NOISE_PHASE_C                 0x07, 0x86
+#define TM6010_REQ07_R87_NOISE_PHASE_Y                 0x07, 0x87
+#define TM6010_REQ07_R8A_CHROMA_LOOPFILTER_STATE       0x07, 0x8a
+#define TM6010_REQ07_R8B_CHROMA_HRESAMPLER             0x07, 0x8b
+#define TM6010_REQ07_R8D_CPUMP_DELAY_ADJ               0x07, 0x8d
+#define TM6010_REQ07_R8E_CPUMP_ADJ                     0x07, 0x8e
+#define TM6010_REQ07_R8F_CPUMP_DELAY                   0x07, 0x8f
+
+/* Define TM6000/TM6010 Miscellaneous registers */
+#define TM6010_REQ07_RC0_ACTIVE_VIDEO_SOURCE           0x07, 0xc0
+#define TM6010_REQ07_RC1_TRESHOLD                      0x07, 0xc1
+#define TM6010_REQ07_RC2_HSYNC_WIDTH                   0x07, 0xc2
+#define TM6010_REQ07_RC3_HSTART1                       0x07, 0xc3
+#define TM6010_REQ07_RC4_HSTART0                       0x07, 0xc4
+#define TM6010_REQ07_RC5_HEND1                         0x07, 0xc5
+#define TM6010_REQ07_RC6_HEND0                         0x07, 0xc6
+#define TM6010_REQ07_RC7_VSTART1                       0x07, 0xc7
+#define TM6010_REQ07_RC8_VSTART0                       0x07, 0xc8
+#define TM6010_REQ07_RC9_VEND1                         0x07, 0xc9
+#define TM6010_REQ07_RCA_VEND0                         0x07, 0xca
+#define TM6010_REQ07_RCB_DELAY                         0x07, 0xcb
+#define TM6010_REQ07_RCC_ACTIVE_VIDEO_IF               0x07, 0xcc
+#define TM6010_REQ07_RD0_USB_PERIPHERY_CONTROL         0x07, 0xd0
+#define TM6010_REQ07_RD1_ADDR_FOR_REQ1                 0x07, 0xd1
+#define TM6010_REQ07_RD2_ADDR_FOR_REQ2                 0x07, 0xd2
+#define TM6010_REQ07_RD3_ADDR_FOR_REQ3                 0x07, 0xd3
+#define TM6010_REQ07_RD4_ADDR_FOR_REQ4                 0x07, 0xd4
+#define TM6010_REQ07_RD5_POWERSAVE                     0x07, 0xd5
+#define TM6010_REQ07_RD6_ENDP_REQ1_REQ2                        0x07, 0xd6
+#define TM6010_REQ07_RD7_ENDP_REQ3_REQ4                        0x07, 0xd7
+#define TM6010_REQ07_RD8_IR                            0x07, 0xd8
+#define TM6010_REQ07_RD8_IR_BSIZE                      0x07, 0xd9
+#define TM6010_REQ07_RD8_IR_WAKEUP_SEL                 0x07, 0xda
+#define TM6010_REQ07_RD8_IR_WAKEUP_ADD                 0x07, 0xdb
+#define TM6010_REQ07_RD8_IR_LEADER1                    0x07, 0xdc
+#define TM6010_REQ07_RD8_IR_LEADER0                    0x07, 0xdd
+#define TM6010_REQ07_RD8_IR_PULSE_CNT1                 0x07, 0xde
+#define TM6010_REQ07_RD8_IR_PULSE_CNT0                 0x07, 0xdf
+#define TM6010_REQ07_RE0_DVIDEO_SOURCE                 0x07, 0xe0
+#define TM6010_REQ07_RE0_DVIDEO_SOURCE_IF              0x07, 0xe1
+#define TM6010_REQ07_RE2_OUT_SEL2                      0x07, 0xe2
+#define TM6010_REQ07_RE3_OUT_SEL1                      0x07, 0xe3
+#define TM6010_REQ07_RE4_OUT_SEL0                      0x07, 0xe4
+#define TM6010_REQ07_RE5_REMOTE_WAKEUP                 0x07, 0xe5
+#define TM6010_REQ07_RE7_PUB_GPIO                      0x07, 0xe7
+#define TM6010_REQ07_RE8_TYPESEL_MOS_I2S               0x07, 0xe8
+#define TM6010_REQ07_RE9_TYPESEL_MOS_TS                        0x07, 0xe9
+#define TM6010_REQ07_REA_TYPESEL_MOS_CCIR              0x07, 0xea
+#define TM6010_REQ07_RF0_BIST_CRC_RESULT0              0x07, 0xf0
+#define TM6010_REQ07_RF1_BIST_CRC_RESULT1              0x07, 0xf1
+#define TM6010_REQ07_RF2_BIST_CRC_RESULT2              0x07, 0xf2
+#define TM6010_REQ07_RF3_BIST_CRC_RESULT3              0x07, 0xf3
+#define TM6010_REQ07_RF4_BIST_ERR_VST2                 0x07, 0xf4
+#define TM6010_REQ07_RF5_BIST_ERR_VST1                 0x07, 0xf5
+#define TM6010_REQ07_RF6_BIST_ERR_VST0                 0x07, 0xf6
+#define TM6010_REQ07_RF7_BIST                          0x07, 0xf7
+#define TM6010_REQ07_RFE_POWER_DOWN                    0x07, 0xfe
+#define TM6010_REQ07_RFF_SOFT_RESET                    0x07, 0xff
+
+/* Define TM6000/TM6010 USB registers */
+#define TM6010_REQ05_R00_MAIN_CTRL             0x05, 0x00
+#define TM6010_REQ05_R01_DEVADDR               0x05, 0x01
+#define TM6010_REQ05_R02_TEST                  0x05, 0x02
+#define TM6010_REQ05_R04_SOFN0                 0x05, 0x04
+#define TM6010_REQ05_R05_SOFN1                 0x05, 0x05
+#define TM6010_REQ05_R06_SOFTM0                        0x05, 0x06
+#define TM6010_REQ05_R07_SOFTM1                        0x05, 0x07
+#define TM6010_REQ05_R08_PHY_TEST              0x05, 0x08
+#define TM6010_REQ05_R09_VCTL                  0x05, 0x09
+#define TM6010_REQ05_R0A_VSTA                  0x05, 0x0a
+#define TM6010_REQ05_R0B_CX_CFG                        0x05, 0x0b
+#define TM6010_REQ05_R0C_ENDP0_REG0            0x05, 0x0c
+#define TM6010_REQ05_R10_GMASK                 0x05, 0x10
+#define TM6010_REQ05_R11_IMASK0                        0x05, 0x11
+#define TM6010_REQ05_R12_IMASK1                        0x05, 0x12
+#define TM6010_REQ05_R13_IMASK2                        0x05, 0x13
+#define TM6010_REQ05_R14_IMASK3                        0x05, 0x14
+#define TM6010_REQ05_R15_IMASK4                        0x05, 0x15
+#define TM6010_REQ05_R16_IMASK5                        0x05, 0x16
+#define TM6010_REQ05_R17_IMASK6                        0x05, 0x17
+#define TM6010_REQ05_R18_IMASK7                        0x05, 0x18
+#define TM6010_REQ05_R19_ZEROP0                        0x05, 0x19
+#define TM6010_REQ05_R1A_ZEROP1                        0x05, 0x1a
+#define TM6010_REQ05_R1C_FIFO_EMP0             0x05, 0x1c
+#define TM6010_REQ05_R1D_FIFO_EMP1             0x05, 0x1d
+#define TM6010_REQ05_R20_IRQ_GROUP             0x05, 0x20
+#define TM6010_REQ05_R21_IRQ_SOURCE0           0x05, 0x21
+#define TM6010_REQ05_R22_IRQ_SOURCE1           0x05, 0x22
+#define TM6010_REQ05_R23_IRQ_SOURCE2           0x05, 0x23
+#define TM6010_REQ05_R24_IRQ_SOURCE3           0x05, 0x24
+#define TM6010_REQ05_R25_IRQ_SOURCE4           0x05, 0x25
+#define TM6010_REQ05_R26_IRQ_SOURCE5           0x05, 0x26
+#define TM6010_REQ05_R27_IRQ_SOURCE6           0x05, 0x27
+#define TM6010_REQ05_R28_IRQ_SOURCE7           0x05, 0x28
+#define TM6010_REQ05_R29_SEQ_ERR0              0x05, 0x29
+#define TM6010_REQ05_R2A_SEQ_ERR1              0x05, 0x2a
+#define TM6010_REQ05_R2B_SEQ_ABORT0            0x05, 0x2b
+#define TM6010_REQ05_R2C_SEQ_ABORT1            0x05, 0x2c
+#define TM6010_REQ05_R2D_TX_ZERO0              0x05, 0x2d
+#define TM6010_REQ05_R2E_TX_ZERO1              0x05, 0x2e
+#define TM6010_REQ05_R2F_IDLE_CNT              0x05, 0x2f
+#define TM6010_REQ05_R30_FNO_P1                        0x05, 0x30
+#define TM6010_REQ05_R31_FNO_P2                        0x05, 0x31
+#define TM6010_REQ05_R32_FNO_P3                        0x05, 0x32
+#define TM6010_REQ05_R33_FNO_P4                        0x05, 0x33
+#define TM6010_REQ05_R34_FNO_P5                        0x05, 0x34
+#define TM6010_REQ05_R35_FNO_P6                        0x05, 0x35
+#define TM6010_REQ05_R36_FNO_P7                        0x05, 0x36
+#define TM6010_REQ05_R37_FNO_P8                        0x05, 0x37
+#define TM6010_REQ05_R38_FNO_P9                        0x05, 0x38
+#define TM6010_REQ05_R30_FNO_P10               0x05, 0x39
+#define TM6010_REQ05_R30_FNO_P11               0x05, 0x3a
+#define TM6010_REQ05_R30_FNO_P12               0x05, 0x3b
+#define TM6010_REQ05_R30_FNO_P13               0x05, 0x3c
+#define TM6010_REQ05_R30_FNO_P14               0x05, 0x3d
+#define TM6010_REQ05_R30_FNO_P15               0x05, 0x3e
+#define TM6010_REQ05_R40_IN_MAXPS_LOW1         0x05, 0x40
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH1                0x05, 0x41
+#define TM6010_REQ05_R42_IN_MAXPS_LOW2         0x05, 0x42
+#define TM6010_REQ05_R43_IN_MAXPS_HIGH2                0x05, 0x43
+#define TM6010_REQ05_R44_IN_MAXPS_LOW3         0x05, 0x44
+#define TM6010_REQ05_R45_IN_MAXPS_HIGH3                0x05, 0x45
+#define TM6010_REQ05_R46_IN_MAXPS_LOW4         0x05, 0x46
+#define TM6010_REQ05_R47_IN_MAXPS_HIGH4                0x05, 0x47
+#define TM6010_REQ05_R48_IN_MAXPS_LOW5         0x05, 0x48
+#define TM6010_REQ05_R49_IN_MAXPS_HIGH5                0x05, 0x49
+#define TM6010_REQ05_R4A_IN_MAXPS_LOW6         0x05, 0x4a
+#define TM6010_REQ05_R4B_IN_MAXPS_HIGH6                0x05, 0x4b
+#define TM6010_REQ05_R4C_IN_MAXPS_LOW7         0x05, 0x4c
+#define TM6010_REQ05_R4D_IN_MAXPS_HIGH7                0x05, 0x4d
+#define TM6010_REQ05_R4E_IN_MAXPS_LOW8         0x05, 0x4e
+#define TM6010_REQ05_R4F_IN_MAXPS_HIGH8                0x05, 0x4f
+#define TM6010_REQ05_R50_IN_MAXPS_LOW9         0x05, 0x50
+#define TM6010_REQ05_R51_IN_MAXPS_HIGH9                0x05, 0x51
+#define TM6010_REQ05_R40_IN_MAXPS_LOW10                0x05, 0x52
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH10       0x05, 0x53
+#define TM6010_REQ05_R40_IN_MAXPS_LOW11                0x05, 0x54
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH11       0x05, 0x55
+#define TM6010_REQ05_R40_IN_MAXPS_LOW12                0x05, 0x56
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH12       0x05, 0x57
+#define TM6010_REQ05_R40_IN_MAXPS_LOW13                0x05, 0x58
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH13       0x05, 0x59
+#define TM6010_REQ05_R40_IN_MAXPS_LOW14                0x05, 0x5a
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH14       0x05, 0x5b
+#define TM6010_REQ05_R40_IN_MAXPS_LOW15                0x05, 0x5c
+#define TM6010_REQ05_R41_IN_MAXPS_HIGH15       0x05, 0x5d
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW1                0x05, 0x60
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH1       0x05, 0x61
+#define TM6010_REQ05_R62_OUT_MAXPS_LOW2                0x05, 0x62
+#define TM6010_REQ05_R63_OUT_MAXPS_HIGH2       0x05, 0x63
+#define TM6010_REQ05_R64_OUT_MAXPS_LOW3                0x05, 0x64
+#define TM6010_REQ05_R65_OUT_MAXPS_HIGH3       0x05, 0x65
+#define TM6010_REQ05_R66_OUT_MAXPS_LOW4                0x05, 0x66
+#define TM6010_REQ05_R67_OUT_MAXPS_HIGH4       0x05, 0x67
+#define TM6010_REQ05_R68_OUT_MAXPS_LOW5                0x05, 0x68
+#define TM6010_REQ05_R69_OUT_MAXPS_HIGH5       0x05, 0x69
+#define TM6010_REQ05_R6A_OUT_MAXPS_LOW6                0x05, 0x6a
+#define TM6010_REQ05_R6B_OUT_MAXPS_HIGH6       0x05, 0x6b
+#define TM6010_REQ05_R6C_OUT_MAXPS_LOW7                0x05, 0x6c
+#define TM6010_REQ05_R6D_OUT_MAXPS_HIGH7       0x05, 0x6d
+#define TM6010_REQ05_R6E_OUT_MAXPS_LOW8                0x05, 0x6e
+#define TM6010_REQ05_R6F_OUT_MAXPS_HIGH8       0x05, 0x6f
+#define TM6010_REQ05_R70_OUT_MAXPS_LOW9                0x05, 0x70
+#define TM6010_REQ05_R71_OUT_MAXPS_HIGH9       0x05, 0x71
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW10       0x05, 0x72
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH10      0x05, 0x73
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW11       0x05, 0x74
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH11      0x05, 0x75
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW12       0x05, 0x76
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH12      0x05, 0x77
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW13       0x05, 0x78
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH13      0x05, 0x79
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW14       0x05, 0x7a
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH14      0x05, 0x7b
+#define TM6010_REQ05_R60_OUT_MAXPS_LOW15       0x05, 0x7c
+#define TM6010_REQ05_R61_OUT_MAXPS_HIGH15      0x05, 0x7d
+#define TM6010_REQ05_R80_FIFO0                 0x05, 0x80
+#define TM6010_REQ05_R81_FIFO1                 0x05, 0x81
+#define TM6010_REQ05_R82_FIFO2                 0x05, 0x82
+#define TM6010_REQ05_R83_FIFO3                 0x05, 0x83
+#define TM6010_REQ05_R84_FIFO4                 0x05, 0x84
+#define TM6010_REQ05_R85_FIFO5                 0x05, 0x85
+#define TM6010_REQ05_R86_FIFO6                 0x05, 0x86
+#define TM6010_REQ05_R87_FIFO7                 0x05, 0x87
+#define TM6010_REQ05_R88_FIFO8                 0x05, 0x88
+#define TM6010_REQ05_R89_FIFO9                 0x05, 0x89
+#define TM6010_REQ05_R81_FIFO10                        0x05, 0x8a
+#define TM6010_REQ05_R81_FIFO11                        0x05, 0x8b
+#define TM6010_REQ05_R81_FIFO12                        0x05, 0x8c
+#define TM6010_REQ05_R81_FIFO13                        0x05, 0x8d
+#define TM6010_REQ05_R81_FIFO14                        0x05, 0x8e
+#define TM6010_REQ05_R81_FIFO15                        0x05, 0x8f
+#define TM6010_REQ05_R90_CFG_FIFO0             0x05, 0x90
+#define TM6010_REQ05_R91_CFG_FIFO1             0x05, 0x91
+#define TM6010_REQ05_R92_CFG_FIFO2             0x05, 0x92
+#define TM6010_REQ05_R93_CFG_FIFO3             0x05, 0x93
+#define TM6010_REQ05_R94_CFG_FIFO4             0x05, 0x94
+#define TM6010_REQ05_R95_CFG_FIFO5             0x05, 0x95
+#define TM6010_REQ05_R96_CFG_FIFO6             0x05, 0x96
+#define TM6010_REQ05_R97_CFG_FIFO7             0x05, 0x97
+#define TM6010_REQ05_R98_CFG_FIFO8             0x05, 0x98
+#define TM6010_REQ05_R99_CFG_FIFO9             0x05, 0x99
+#define TM6010_REQ05_R91_CFG_FIFO10            0x05, 0x9a
+#define TM6010_REQ05_R91_CFG_FIFO11            0x05, 0x9b
+#define TM6010_REQ05_R91_CFG_FIFO12            0x05, 0x9c
+#define TM6010_REQ05_R91_CFG_FIFO13            0x05, 0x9d
+#define TM6010_REQ05_R91_CFG_FIFO14            0x05, 0x9e
+#define TM6010_REQ05_R91_CFG_FIFO15            0x05, 0x9f
+#define TM6010_REQ05_RA0_CTL_FIFO0             0x05, 0xa0
+#define TM6010_REQ05_RA1_CTL_FIFO1             0x05, 0xa1
+#define TM6010_REQ05_RA2_CTL_FIFO2             0x05, 0xa2
+#define TM6010_REQ05_RA3_CTL_FIFO3             0x05, 0xa3
+#define TM6010_REQ05_RA4_CTL_FIFO4             0x05, 0xa4
+#define TM6010_REQ05_RA5_CTL_FIFO5             0x05, 0xa5
+#define TM6010_REQ05_RA6_CTL_FIFO6             0x05, 0xa6
+#define TM6010_REQ05_RA7_CTL_FIFO7             0x05, 0xa7
+#define TM6010_REQ05_RA8_CTL_FIFO8             0x05, 0xa8
+#define TM6010_REQ05_RA9_CTL_FIFO9             0x05, 0xa9
+#define TM6010_REQ05_RA1_CTL_FIFO10            0x05, 0xaa
+#define TM6010_REQ05_RA1_CTL_FIFO11            0x05, 0xab
+#define TM6010_REQ05_RA1_CTL_FIFO12            0x05, 0xac
+#define TM6010_REQ05_RA1_CTL_FIFO13            0x05, 0xad
+#define TM6010_REQ05_RA1_CTL_FIFO14            0x05, 0xae
+#define TM6010_REQ05_RA1_CTL_FIFO15            0x05, 0xaf
+#define TM6010_REQ05_RB0_BC_LOW_FIFO0          0x05, 0xb0
+#define TM6010_REQ05_RB1_BC_LOW_FIFO1          0x05, 0xb1
+#define TM6010_REQ05_RB2_BC_LOW_FIFO2          0x05, 0xb2
+#define TM6010_REQ05_RB3_BC_LOW_FIFO3          0x05, 0xb3
+#define TM6010_REQ05_RB4_BC_LOW_FIFO4          0x05, 0xb4
+#define TM6010_REQ05_RB5_BC_LOW_FIFO5          0x05, 0xb5
+#define TM6010_REQ05_RB6_BC_LOW_FIFO6          0x05, 0xb6
+#define TM6010_REQ05_RB7_BC_LOW_FIFO7          0x05, 0xb7
+#define TM6010_REQ05_RB8_BC_LOW_FIFO8          0x05, 0xb8
+#define TM6010_REQ05_RB9_BC_LOW_FIFO9          0x05, 0xb9
+#define TM6010_REQ05_RB1_BC_LOW_FIFO10         0x05, 0xba
+#define TM6010_REQ05_RB1_BC_LOW_FIFO11         0x05, 0xbb
+#define TM6010_REQ05_RB1_BC_LOW_FIFO12         0x05, 0xbc
+#define TM6010_REQ05_RB1_BC_LOW_FIFO13         0x05, 0xbd
+#define TM6010_REQ05_RB1_BC_LOW_FIFO14         0x05, 0xbe
+#define TM6010_REQ05_RB1_BC_LOW_FIFO15         0x05, 0xbf
+#define TM6010_REQ05_RC0_DATA_FIFO0            0x05, 0xc0
+#define TM6010_REQ05_RC4_DATA_FIFO1            0x05, 0xc4
+#define TM6010_REQ05_RC8_DATA_FIFO2            0x05, 0xc8
+#define TM6010_REQ05_RCC_DATA_FIFO3            0x05, 0xcc
+#define TM6010_REQ05_RD0_DATA_FIFO4            0x05, 0xd0
+#define TM6010_REQ05_RD4_DATA_FIFO5            0x05, 0xd4
+#define TM6010_REQ05_RD8_DATA_FIFO6            0x05, 0xd8
+#define TM6010_REQ05_RDC_DATA_FIFO7            0x05, 0xdc
+#define TM6010_REQ05_RE0_DATA_FIFO8            0x05, 0xe0
+#define TM6010_REQ05_RE4_DATA_FIFO9            0x05, 0xe4
+#define TM6010_REQ05_RC4_DATA_FIFO10           0x05, 0xe8
+#define TM6010_REQ05_RC4_DATA_FIFO11           0x05, 0xec
+#define TM6010_REQ05_RC4_DATA_FIFO12           0x05, 0xf0
+#define TM6010_REQ05_RC4_DATA_FIFO13           0x05, 0xf4
+#define TM6010_REQ05_RC4_DATA_FIFO14           0x05, 0xf8
+#define TM6010_REQ05_RC4_DATA_FIFO15           0x05, 0xfc
+
+/* Define TM6000/TM6010 Audio decoder registers */
+#define TM6010_REQ08_R00_A_VERSION             0x08, 0x00
+#define TM6010_REQ08_R01_A_INIT                        0x08, 0x01
+#define TM6010_REQ08_R02_A_FIX_GAIN_CTRL       0x08, 0x02
+#define TM6010_REQ08_R03_A_AUTO_GAIN_CTRL      0x08, 0x03
+#define TM6010_REQ08_R04_A_SIF_AMP_CTRL                0x08, 0x04
+#define TM6010_REQ08_R05_A_STANDARD_MOD                0x08, 0x05
+#define TM6010_REQ08_R06_A_SOUND_MOD           0x08, 0x06
+#define TM6010_REQ08_R07_A_LEFT_VOL            0x08, 0x07
+#define TM6010_REQ08_R08_A_RIGHT_VOL           0x08, 0x08
+#define TM6010_REQ08_R09_A_MAIN_VOL            0x08, 0x09
+#define TM6010_REQ08_R0A_A_I2S_MOD             0x08, 0x0a
+#define TM6010_REQ08_R0B_A_ASD_THRES1          0x08, 0x0b
+#define TM6010_REQ08_R0C_A_ASD_THRES2          0x08, 0x0c
+#define TM6010_REQ08_R0D_A_AMD_THRES           0x08, 0x0d
+#define TM6010_REQ08_R0E_A_MONO_THRES1         0x08, 0x0e
+#define TM6010_REQ08_R0F_A_MONO_THRES2         0x08, 0x0f
+#define TM6010_REQ08_R10_A_MUTE_THRES1         0x08, 0x10
+#define TM6010_REQ08_R11_A_MUTE_THRES2         0x08, 0x11
+#define TM6010_REQ08_R12_A_AGC_U               0x08, 0x12
+#define TM6010_REQ08_R13_A_AGC_ERR_T           0x08, 0x13
+#define TM6010_REQ08_R14_A_AGC_GAIN_INIT       0x08, 0x14
+#define TM6010_REQ08_R15_A_AGC_STEP_THR                0x08, 0x15
+#define TM6010_REQ08_R16_A_AGC_GAIN_MAX                0x08, 0x16
+#define TM6010_REQ08_R17_A_AGC_GAIN_MIN                0x08, 0x17
+#define TM6010_REQ08_R18_A_TR_CTRL             0x08, 0x18
+#define TM6010_REQ08_R19_A_FH_2FH_GAIN         0x08, 0x19
+#define TM6010_REQ08_R1A_A_NICAM_SER_MAX       0x08, 0x1a
+#define TM6010_REQ08_R1B_A_NICAM_SER_MIN       0x08, 0x1b
+#define TM6010_REQ08_R1E_A_GAIN_DEEMPH_OUT     0x08, 0x1e
+#define TM6010_REQ08_R1F_A_TEST_INTF_SEL       0x08, 0x1f
+#define TM6010_REQ08_R20_A_TEST_PIN_SEL                0x08, 0x20
+#define TM6010_REQ08_R21_A_AGC_ERR             0x08, 0x21
+#define TM6010_REQ08_R22_A_AGC_GAIN            0x08, 0x22
+#define TM6010_REQ08_R23_A_NICAM_INFO          0x08, 0x23
+#define TM6010_REQ08_R24_A_SER                 0x08, 0x24
+#define TM6010_REQ08_R25_A_C1_AMP              0x08, 0x25
+#define TM6010_REQ08_R26_A_C2_AMP              0x08, 0x26
+#define TM6010_REQ08_R27_A_NOISE_AMP           0x08, 0x27
+#define TM6010_REQ08_R28_A_AUDIO_MODE_RES      0x08, 0x28
+
+/* Define TM6000/TM6010 Video ADC registers */
+#define TM6010_REQ08_RE0_ADC_REF               0x08, 0xe0
+#define TM6010_REQ08_RE1_DAC_CLMP              0x08, 0xe1
+#define TM6010_REQ08_RE2_POWER_DOWN_CTRL1      0x08, 0xe2
+#define TM6010_REQ08_RE3_ADC_IN1_SEL           0x08, 0xe3
+#define TM6010_REQ08_RE4_ADC_IN2_SEL           0x08, 0xe4
+#define TM6010_REQ08_RE5_GAIN_PARAM            0x08, 0xe5
+#define TM6010_REQ08_RE6_POWER_DOWN_CTRL2      0x08, 0xe6
+#define TM6010_REQ08_RE7_REG_GAIN_Y            0x08, 0xe7
+#define TM6010_REQ08_RE8_REG_GAIN_C            0x08, 0xe8
+#define TM6010_REQ08_RE9_BIAS_CTRL             0x08, 0xe9
+#define TM6010_REQ08_REA_BUFF_DRV_CTRL         0x08, 0xea
+#define TM6010_REQ08_REB_SIF_GAIN_CTRL         0x08, 0xeb
+#define TM6010_REQ08_REC_REVERSE_YC_CTRL       0x08, 0xec
+#define TM6010_REQ08_RED_GAIN_SEL              0x08, 0xed
+
+/* Define TM6000/TM6010 Audio ADC registers */
+#define TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG   0x08, 0xf0
+#define TM6010_REQ08_RF1_AADC_POWER_DOWN       0x08, 0xf1
+#define TM6010_REQ08_RF2_LEFT_CHANNEL_VOL      0x08, 0xf2
+#define TM6010_REQ08_RF3_RIGHT_CHANNEL_VOL     0x08, 0xf3
diff --git a/drivers/staging/tm6000/tm6000-stds.c b/drivers/staging/tm6000/tm6000-stds.c
new file mode 100644 (file)
index 0000000..b3564f6
--- /dev/null
@@ -0,0 +1,873 @@
+/*
+   tm6000-stds.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2007 Mauro Carvalho Chehab <mchehab@redhat.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 version 2
+
+   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 <linux/module.h>
+#include <linux/kernel.h>
+#include "tm6000.h"
+#include "tm6000-regs.h"
+
+struct tm6000_reg_settings {
+       unsigned char req;
+       unsigned char reg;
+       unsigned char value;
+};
+
+struct tm6000_std_tv_settings {
+       v4l2_std_id id;
+       struct tm6000_reg_settings sif[12];
+       struct tm6000_reg_settings nosif[12];
+       struct tm6000_reg_settings common[25];
+};
+
+struct tm6000_std_settings {
+       v4l2_std_id id;
+       struct tm6000_reg_settings common[37];
+};
+
+static struct tm6000_std_tv_settings tv_stds[] = {
+       {
+               .id = V4L2_STD_PAL_M,
+               .sif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf2},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x08},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x62},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0xcb},
+                       {0, 0, 0},
+               },
+               .nosif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+                       {0, 0, 0},
+               },
+               .common = {
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x04},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x20},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_PAL_Nc,
+               .sif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf2},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x08},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x62},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0xcb},
+                       {0, 0, 0},
+               },
+               .nosif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+                       {0, 0, 0},
+               },
+               .common = {
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x36},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_PAL,
+               .sif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf2},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x08},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x62},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0xcb},
+                       {0, 0, 0}
+               },
+               .nosif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+                       {0, 0, 0},
+               },
+               .common = {
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x32},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_SECAM,
+               .sif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf2},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x08},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x62},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0xcb},
+                       {0, 0, 0},
+               },
+               .nosif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+                       {0, 0, 0},
+               },
+               .common = {
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x38},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xFF},
+
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_NTSC,
+               .sif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf2},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x08},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x62},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfe},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0xcb},
+                       {0, 0, 0},
+               },
+               .nosif = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf8},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x60},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+                       {0, 0, 0},
+               },
+               .common = {
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       },
+};
+
+static struct tm6000_std_settings composite_stds[] = {
+       {
+               .id = V4L2_STD_PAL_M,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x04},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x20},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+        }, {
+               .id = V4L2_STD_PAL_Nc,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x36},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_PAL,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x32},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+        }, {
+               .id = V4L2_STD_SECAM,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x38},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x02},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2c},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xFF},
+
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_NTSC,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xf4},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf3},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x0f},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf1},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xe0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe8},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8b},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x00},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x00},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       },
+};
+
+static struct tm6000_std_settings svideo_stds[] = {
+       {
+               .id = V4L2_STD_PAL_M,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe0},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8a},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x05},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x83},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x0a},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe0},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_PAL_Nc,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe0},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8a},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x37},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x91},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x1f},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x0c},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_PAL,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe0},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8a},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x33},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x04},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x00},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x25},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0xd5},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0x63},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0x50},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x0c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x52},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdc},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+        }, {
+               .id = V4L2_STD_SECAM,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe0},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8a},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x39},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0e},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x01},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x24},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x92},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xe8},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xed},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x8c},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x2a},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0xc1},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x2c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x18},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0xFF},
+
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       }, {
+               .id = V4L2_STD_NTSC,
+               .common = {
+                       {TM6010_REQ08_RE2_POWER_DOWN_CTRL1, 0xf0},
+                       {TM6010_REQ08_RE3_ADC_IN1_SEL, 0xfc},
+                       {TM6010_REQ08_RE4_ADC_IN2_SEL, 0xf8},
+                       {TM6010_REQ08_RE6_POWER_DOWN_CTRL2, 0x00},
+                       {TM6010_REQ08_REA_BUFF_DRV_CTRL, 0xf2},
+                       {TM6010_REQ08_REB_SIF_GAIN_CTRL, 0xf0},
+                       {TM6010_REQ08_REC_REVERSE_YC_CTRL, 0xc2},
+                       {TM6010_REQ08_RED_GAIN_SEL, 0xe0},
+                       {TM6010_REQ08_RF0_DAUDIO_INPUT_CONFIG, 0x68},
+                       {TM6010_REQ08_RF1_AADC_POWER_DOWN, 0xfc},
+                       {TM6010_REQ07_RFE_POWER_DOWN, 0x8a},
+
+                       {TM6010_REQ07_R3F_RESET, 0x01},
+                       {TM6010_REQ07_R00_VIDEO_CONTROL0, 0x01},
+                       {TM6010_REQ07_R01_VIDEO_CONTROL1, 0x0f},
+                       {TM6010_REQ07_R02_VIDEO_CONTROL2, 0x5f},
+                       {TM6010_REQ07_R03_YC_SEP_CONTROL, 0x03},
+                       {TM6010_REQ07_R07_OUTPUT_CONTROL, 0x00},
+                       {TM6010_REQ07_R17_HLOOP_MAXSTATE, 0x8b},
+                       {TM6010_REQ07_R18_CHROMA_DTO_INCREMENT3, 0x1e},
+                       {TM6010_REQ07_R19_CHROMA_DTO_INCREMENT2, 0x8b},
+                       {TM6010_REQ07_R1A_CHROMA_DTO_INCREMENT1, 0xa2},
+                       {TM6010_REQ07_R1B_CHROMA_DTO_INCREMENT0, 0xe9},
+                       {TM6010_REQ07_R1C_HSYNC_DTO_INCREMENT3, 0x1c},
+                       {TM6010_REQ07_R1D_HSYNC_DTO_INCREMENT2, 0xcc},
+                       {TM6010_REQ07_R1E_HSYNC_DTO_INCREMENT1, 0xcc},
+                       {TM6010_REQ07_R1F_HSYNC_DTO_INCREMENT0, 0xcd},
+                       {TM6010_REQ07_R2E_ACTIVE_VIDEO_HSTART, 0x88},
+                       {TM6010_REQ07_R30_ACTIVE_VIDEO_VSTART, 0x22},
+                       {TM6010_REQ07_R31_ACTIVE_VIDEO_VHIGHT, 0x61},
+                       {TM6010_REQ07_R33_VSYNC_HLOCK_MAX, 0x1c},
+                       {TM6010_REQ07_R35_VSYNC_AGC_MAX, 0x1c},
+                       {TM6010_REQ07_R82_COMB_FILTER_CONFIG, 0x42},
+                       {TM6010_REQ07_R83_CHROMA_LOCK_CONFIG, 0x6F},
+
+                       {TM6010_REQ07_R04_LUMA_HAGC_CONTROL, 0xdd},
+                       {TM6010_REQ07_R0D_CHROMA_KILL_LEVEL, 0x07},
+                       {TM6010_REQ07_R3F_RESET, 0x00},
+                       {0, 0, 0},
+               },
+       },
+};
+
+void tm6000_get_std_res(struct tm6000_core *dev)
+{
+       /* Currently, those are the only supported resoltions */
+       if (dev->norm & V4L2_STD_525_60) {
+               dev->height = 480;
+       } else {
+               dev->height = 576;
+       }
+       dev->width = 720;
+}
+
+static int tm6000_load_std(struct tm6000_core *dev,
+                          struct tm6000_reg_settings *set, int max_size)
+{
+       int i, rc;
+
+       /* Load board's initialization table */
+       for (i = 0; max_size; i++) {
+               if (!set[i].req)
+                       return 0;
+
+               if ((dev->dev_type != TM6010) &&
+                   (set[i].req == REQ_08_SET_GET_AVREG_BIT))
+                               continue;
+
+               rc = tm6000_set_reg(dev, set[i].req, set[i].reg, set[i].value);
+               if (rc < 0) {
+                       printk(KERN_ERR "Error %i while setting "
+                              "req %d, reg %d to value %d\n",
+                              rc, set[i].req, set[i].reg, set[i].value);
+                       return rc;
+               }
+       }
+
+       return 0;
+}
+
+static int tm6000_set_tv(struct tm6000_core *dev, int pos)
+{
+       int rc;
+
+       /* FIXME: This code is for tm6010 - not tested yet - doesn't work with
+          tm5600
+        */
+
+       /* FIXME: This is tuner-dependent */
+       int nosif = 0;
+
+       if (nosif) {
+               rc = tm6000_load_std(dev, tv_stds[pos].nosif,
+                                    sizeof(tv_stds[pos].nosif));
+       } else {
+               rc = tm6000_load_std(dev, tv_stds[pos].sif,
+                                    sizeof(tv_stds[pos].sif));
+       }
+       if (rc < 0)
+               return rc;
+       rc = tm6000_load_std(dev, tv_stds[pos].common,
+                            sizeof(tv_stds[pos].common));
+
+       return rc;
+}
+
+int tm6000_set_standard(struct tm6000_core *dev, v4l2_std_id * norm)
+{
+       int i, rc = 0;
+
+       dev->norm = *norm;
+       tm6000_get_std_res(dev);
+
+       switch (dev->input) {
+       case TM6000_INPUT_TV:
+               for (i = 0; i < ARRAY_SIZE(tv_stds); i++) {
+                       if (*norm & tv_stds[i].id) {
+                               rc = tm6000_set_tv(dev, i);
+                               goto ret;
+                       }
+               }
+               return -EINVAL;
+       case TM6000_INPUT_SVIDEO:
+               for (i = 0; i < ARRAY_SIZE(svideo_stds); i++) {
+                       if (*norm & svideo_stds[i].id) {
+                               rc = tm6000_load_std(dev, svideo_stds[i].common,
+                                                    sizeof(svideo_stds[i].
+                                                           common));
+                               goto ret;
+                       }
+               }
+               return -EINVAL;
+       case TM6000_INPUT_COMPOSITE:
+               for (i = 0; i < ARRAY_SIZE(composite_stds); i++) {
+                       if (*norm & composite_stds[i].id) {
+                               rc = tm6000_load_std(dev,
+                                                    composite_stds[i].common,
+                                                    sizeof(composite_stds[i].
+                                                           common));
+                               goto ret;
+                       }
+               }
+               return -EINVAL;
+       }
+
+ret:
+       if (rc < 0)
+               return rc;
+
+       msleep(40);
+
+
+       return 0;
+}
diff --git a/drivers/staging/tm6000/tm6000-usb-isoc.h b/drivers/staging/tm6000/tm6000-usb-isoc.h
new file mode 100644 (file)
index 0000000..5a5049a
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+   tm6000-buf.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   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
+
+   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 <linux/videodev2.h>
+
+#define TM6000_URB_MSG_LEN 180
+
+struct usb_isoc_ctl {
+               /* max packet size of isoc transaction */
+       int                             max_pkt_size;
+
+               /* number of allocated urbs */
+       int                             num_bufs;
+
+               /* urb for isoc transfers */
+       struct urb                      **urb;
+
+               /* transfer buffers for isoc transfer */
+       char                            **transfer_buffer;
+
+               /* Last buffer command and region */
+       u8                              cmd;
+       int                             pos, size, pktsize;
+
+               /* Last field: ODD or EVEN? */
+       int                             field;
+
+               /* Stores incomplete commands */
+       u32                             tmp_buf;
+       int                             tmp_buf_len;
+
+               /* Stores already requested buffers */
+       struct tm6000_buffer            *buf;
+
+               /* Stores the number of received fields */
+       int                             nfields;
+};
diff --git a/drivers/staging/tm6000/tm6000-video.c b/drivers/staging/tm6000/tm6000-video.c
new file mode 100644 (file)
index 0000000..f2b7fe4
--- /dev/null
@@ -0,0 +1,1557 @@
+/*
+   tm6000-video.c - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
+       - Fixed module load/unload
+
+   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
+
+   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 <linux/module.h>
+#include <linux/delay.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/kernel.h>
+#include <linux/slab.h>
+#include <linux/mm.h>
+#include <linux/ioport.h>
+#include <linux/init.h>
+#include <linux/sched.h>
+#include <linux/random.h>
+#include <linux/version.h>
+#include <linux/usb.h>
+#include <linux/videodev2.h>
+#include <media/v4l2-ioctl.h>
+#include <linux/interrupt.h>
+#include <linux/kthread.h>
+#include <linux/highmem.h>
+#include <linux/freezer.h>
+
+#include "tm6000-regs.h"
+#include "tm6000.h"
+
+#define BUFFER_TIMEOUT     msecs_to_jiffies(2000)  /* 2 seconds */
+
+/* Limits minimum and default number of buffers */
+#define TM6000_MIN_BUF 4
+#define TM6000_DEF_BUF 8
+
+#define TM6000_MAX_ISO_PACKETS 40      /* Max number of ISO packets */
+
+/* Declare static vars that will be used as parameters */
+static unsigned int vid_limit = 16;    /* Video memory limit, in Mb */
+static int video_nr = -1;              /* /dev/videoN, -1 for autodetect */
+
+/* Debug level */
+int tm6000_debug;
+
+/* supported controls */
+static struct v4l2_queryctrl tm6000_qctrl[] = {
+       {
+               .id            = V4L2_CID_BRIGHTNESS,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+               .name          = "Brightness",
+               .minimum       = 0,
+               .maximum       = 255,
+               .step          = 1,
+               .default_value = 54,
+               .flags         = 0,
+       }, {
+               .id            = V4L2_CID_CONTRAST,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+               .name          = "Contrast",
+               .minimum       = 0,
+               .maximum       = 255,
+               .step          = 0x1,
+               .default_value = 119,
+               .flags         = 0,
+       }, {
+               .id            = V4L2_CID_SATURATION,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+               .name          = "Saturation",
+               .minimum       = 0,
+               .maximum       = 255,
+               .step          = 0x1,
+               .default_value = 112,
+               .flags         = 0,
+       }, {
+               .id            = V4L2_CID_HUE,
+               .type          = V4L2_CTRL_TYPE_INTEGER,
+               .name          = "Hue",
+               .minimum       = -128,
+               .maximum       = 127,
+               .step          = 0x1,
+               .default_value = 0,
+               .flags         = 0,
+       }
+};
+
+static int qctl_regs[ARRAY_SIZE(tm6000_qctrl)];
+
+static struct tm6000_fmt format[] = {
+       {
+               .name     = "4:2:2, packed, YVY2",
+               .fourcc   = V4L2_PIX_FMT_YUYV,
+               .depth    = 16,
+       }, {
+               .name     = "4:2:2, packed, UYVY",
+               .fourcc   = V4L2_PIX_FMT_UYVY,
+               .depth    = 16,
+       }, {
+               .name     = "A/V + VBI mux packet",
+               .fourcc   = V4L2_PIX_FMT_TM6000,
+               .depth    = 16,
+       }
+};
+
+/* ------------------------------------------------------------------
+       DMA and thread functions
+   ------------------------------------------------------------------*/
+
+#define norm_maxw(a) 720
+#define norm_maxh(a) 576
+
+#define norm_minw(a) norm_maxw(a)
+#define norm_minh(a) norm_maxh(a)
+
+/*
+ * video-buf generic routine to get the next available buffer
+ */
+static inline void get_next_buf(struct tm6000_dmaqueue *dma_q,
+                              struct tm6000_buffer   **buf)
+{
+       struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
+       char *outp;
+
+       if (list_empty(&dma_q->active)) {
+               dprintk(dev, V4L2_DEBUG_QUEUE, "No active queue to serve\n");
+               *buf = NULL;
+               return;
+       }
+
+       *buf = list_entry(dma_q->active.next,
+                       struct tm6000_buffer, vb.queue);
+
+       if (!buf)
+               return;
+
+       /* Cleans up buffer - Usefull for testing for frame/URB loss */
+       outp = videobuf_to_vmalloc(&(*buf)->vb);
+//     if (outp)
+//             memset(outp, 0, (*buf)->vb.size);
+
+       return;
+}
+
+/*
+ * Announces that a buffer were filled and request the next
+ */
+static inline void buffer_filled(struct tm6000_core *dev,
+                                struct tm6000_dmaqueue *dma_q,
+                                struct tm6000_buffer *buf)
+{
+       /* Advice that buffer was filled */
+       dprintk(dev, V4L2_DEBUG_ISOC, "[%p/%d] wakeup\n", buf, buf->vb.i);
+       buf->vb.state = VIDEOBUF_DONE;
+       buf->vb.field_count++;
+       do_gettimeofday(&buf->vb.ts);
+
+       list_del(&buf->vb.queue);
+       wake_up(&buf->vb.done);
+}
+
+const char *tm6000_msg_type[] = {
+       "unknown(0)",   /* 0 */
+       "video",        /* 1 */
+       "audio",        /* 2 */
+       "vbi",          /* 3 */
+       "pts",          /* 4 */
+       "err",          /* 5 */
+       "unknown(6)",   /* 6 */
+       "unknown(7)",   /* 7 */
+};
+
+/*
+ * Identify the tm5600/6000 buffer header type and properly handles
+ */
+static int copy_packet(struct urb *urb, u32 header, u8 **ptr, u8 *endp,
+                       u8 *out_p, struct tm6000_buffer **buf)
+{
+       struct tm6000_dmaqueue  *dma_q = urb->context;
+       struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
+       u8 c;
+       unsigned int cmd, cpysize, pktsize, size, field, block, line, pos = 0;
+       int rc = 0;
+       /* FIXME: move to tm6000-isoc */
+       static int last_line = -2, start_line = -2, last_field = -2;
+
+       /* FIXME: this is the hardcoded window size
+        */
+       unsigned int linewidth = (*buf)->vb.width << 1;
+
+       if (!dev->isoc_ctl.cmd) {
+               c = (header >> 24) & 0xff;
+
+               /* split the header fields */
+               size  = (((header & 0x7e) << 1) -1) *4;
+               block = (header >> 7) & 0xf;
+               field = (header >> 11) & 0x1;
+               line  = (header >> 12) & 0x1ff;
+               cmd   = (header >> 21) & 0x7;
+
+               /* Validates header fields */
+               if(size > TM6000_URB_MSG_LEN)
+                       size = TM6000_URB_MSG_LEN;
+
+               if (cmd == TM6000_URB_MSG_VIDEO) {
+                       if ((block+1)*TM6000_URB_MSG_LEN>linewidth)
+                               cmd = TM6000_URB_MSG_ERR;
+
+                       /* FIXME: Mounts the image as field0+field1
+                        * It should, instead, check if the user selected
+                        * entrelaced or non-entrelaced mode
+                        */
+                       pos = ((line << 1) - field - 1) * linewidth +
+                               block * TM6000_URB_MSG_LEN;
+
+                       /* Don't allow to write out of the buffer */
+                       if (pos+TM6000_URB_MSG_LEN > (*buf)->vb.size) {
+                               dprintk(dev, V4L2_DEBUG_ISOC,
+                                       "ERR: size=%d, num=%d, line=%d, "
+                                       "field=%d\n",
+                                       size, block, line, field);
+
+                               cmd = TM6000_URB_MSG_ERR;
+                       }
+               } else {
+                       pos=0;
+               }
+
+               /* Prints debug info */
+               dprintk(dev, V4L2_DEBUG_ISOC, "size=%d, num=%d, "
+                               " line=%d, field=%d\n",
+                               size, block, line, field);
+
+               if ((last_line!=line)&&(last_line+1!=line) &&
+                   (cmd != TM6000_URB_MSG_ERR) )  {
+                       if (cmd != TM6000_URB_MSG_VIDEO)  {
+                               dprintk(dev, V4L2_DEBUG_ISOC,  "cmd=%d, "
+                                       "size=%d, num=%d, line=%d, field=%d\n",
+                                       cmd, size, block, line, field);
+                       }
+                       if (start_line<0)
+                               start_line=last_line;
+                       /* Prints debug info */
+                       dprintk(dev, V4L2_DEBUG_ISOC, "lines= %d-%d, "
+                                       "field=%d\n",
+                                       start_line, last_line, field);
+
+                       if ((start_line<6 && last_line>200) &&
+                               (last_field != field) ) {
+
+                               dev->isoc_ctl.nfields++;
+                               if (dev->isoc_ctl.nfields>=2) {
+                                       dev->isoc_ctl.nfields=0;
+
+                                       /* Announces that a new buffer were filled */
+                                       buffer_filled (dev, dma_q, *buf);
+                                       dprintk(dev, V4L2_DEBUG_ISOC,
+                                                       "new buffer filled\n");
+                                       get_next_buf (dma_q, buf);
+                                       if (!*buf)
+                                               return rc;
+                                       out_p = videobuf_to_vmalloc(&((*buf)->vb));
+                                       if (!out_p)
+                                               return rc;
+
+                                       pos = dev->isoc_ctl.pos = 0;
+                               }
+                       }
+
+                       start_line=line;
+                       last_field=field;
+               }
+               if (cmd == TM6000_URB_MSG_VIDEO)
+                       last_line = line;
+
+               pktsize = TM6000_URB_MSG_LEN;
+       } else {
+               /* Continue the last copy */
+               cmd = dev->isoc_ctl.cmd;
+               size= dev->isoc_ctl.size;
+               pos = dev->isoc_ctl.pos;
+               pktsize = dev->isoc_ctl.pktsize;
+       }
+
+       cpysize = (endp-(*ptr) > size) ? size : endp - *ptr;
+
+       if (cpysize) {
+               /* handles each different URB message */
+               switch(cmd) {
+               case TM6000_URB_MSG_VIDEO:
+                       /* Fills video buffer */
+                       memcpy(&out_p[pos], *ptr, cpysize);
+                       break;
+               case TM6000_URB_MSG_PTS:
+                       break;
+               case TM6000_URB_MSG_AUDIO:
+/* Need some code to process audio */
+printk ("%ld: cmd=%s, size=%d\n", jiffies,
+                               tm6000_msg_type[cmd],size);
+                       break;
+               default:
+                       dprintk (dev, V4L2_DEBUG_ISOC, "cmd=%s, size=%d\n",
+                                               tm6000_msg_type[cmd],size);
+               }
+       }
+       if (cpysize<size) {
+               /* End of URB packet, but cmd processing is not
+                * complete. Preserve the state for a next packet
+                */
+               dev->isoc_ctl.pos = pos+cpysize;
+               dev->isoc_ctl.size= size-cpysize;
+               dev->isoc_ctl.cmd = cmd;
+               dev->isoc_ctl.pktsize = pktsize-cpysize;
+               (*ptr)+=cpysize;
+       } else {
+               dev->isoc_ctl.cmd = 0;
+               (*ptr)+=pktsize;
+       }
+
+       return rc;
+}
+
+static int copy_streams(u8 *data, u8 *out_p, unsigned long len,
+                       struct urb *urb, struct tm6000_buffer **buf)
+{
+       struct tm6000_dmaqueue  *dma_q = urb->context;
+       struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
+       u8 *ptr=data, *endp=data+len;
+       unsigned long header=0;
+       int rc=0;
+
+       for (ptr=data; ptr<endp;) {
+               if (!dev->isoc_ctl.cmd) {
+                       u8 *p=(u8 *)&dev->isoc_ctl.tmp_buf;
+                       /* FIXME: This seems very complex
+                        * It just recovers up to 3 bytes of the header that
+                        * might be at the previous packet
+                        */
+                       if (dev->isoc_ctl.tmp_buf_len) {
+                               while (dev->isoc_ctl.tmp_buf_len) {
+                                       if ( *(ptr+3-dev->isoc_ctl.tmp_buf_len) == 0x47) {
+                                               break;
+                                       }
+                                       p++;
+                                       dev->isoc_ctl.tmp_buf_len--;
+                               }
+                               if (dev->isoc_ctl.tmp_buf_len) {
+                                       memcpy(&header, p,
+                                               dev->isoc_ctl.tmp_buf_len);
+                                       memcpy((u8 *)&header +
+                                               dev->isoc_ctl.tmp_buf_len,
+                                               ptr,
+                                               4 - dev->isoc_ctl.tmp_buf_len);
+                                       ptr += 4 - dev->isoc_ctl.tmp_buf_len;
+                                       goto HEADER;
+                               }
+                       }
+                       /* Seek for sync */
+                       for (;ptr<endp-3;ptr++) {
+                               if (*(ptr+3)==0x47)
+                                       break;
+                       }
+
+                       if (ptr+3>=endp) {
+                               dev->isoc_ctl.tmp_buf_len=endp-ptr;
+                               memcpy (&dev->isoc_ctl.tmp_buf,ptr,
+                                       dev->isoc_ctl.tmp_buf_len);
+                               dev->isoc_ctl.cmd=0;
+                               return rc;
+                       }
+
+                       /* Get message header */
+                       header=*(unsigned long *)ptr;
+                       ptr+=4;
+               }
+HEADER:
+               /* Copy or continue last copy */
+               rc=copy_packet(urb,header,&ptr,endp,out_p,buf);
+               if (rc<0) {
+                       buf=NULL;
+                       printk(KERN_ERR "tm6000: buffer underrun at %ld\n",
+                                       jiffies);
+                       return rc;
+               }
+               if (!*buf)
+                       return 0;
+       }
+
+       return 0;
+}
+/*
+ * Identify the tm5600/6000 buffer header type and properly handles
+ */
+static int copy_multiplexed(u8 *ptr, u8 *out_p, unsigned long len,
+                       struct urb *urb, struct tm6000_buffer **buf)
+{
+       struct tm6000_dmaqueue  *dma_q = urb->context;
+       struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
+       unsigned int pos=dev->isoc_ctl.pos,cpysize;
+       int rc=1;
+
+       while (len>0) {
+               cpysize=min(len,(*buf)->vb.size-pos);
+//printk("Copying %d bytes (max=%lu) from %p to %p[%u]\n",cpysize,(*buf)->vb.size,ptr,out_p,pos);
+               memcpy(&out_p[pos], ptr, cpysize);
+               pos+=cpysize;
+               ptr+=cpysize;
+               len-=cpysize;
+               if (pos >= (*buf)->vb.size) {
+                       pos=0;
+                       /* Announces that a new buffer were filled */
+                       buffer_filled (dev, dma_q, *buf);
+                       dprintk(dev, V4L2_DEBUG_ISOC, "new buffer filled\n");
+                       get_next_buf (dma_q, buf);
+                       if (!*buf)
+                               break;
+                       out_p = videobuf_to_vmalloc(&((*buf)->vb));
+                       if (!out_p)
+                               return rc;
+                       pos = 0;
+               }
+       }
+
+       dev->isoc_ctl.pos=pos;
+       return rc;
+}
+
+static void inline print_err_status (struct tm6000_core *dev,
+                                    int packet, int status)
+{
+       char *errmsg = "Unknown";
+
+       switch(status) {
+       case -ENOENT:
+               errmsg = "unlinked synchronuously";
+               break;
+       case -ECONNRESET:
+               errmsg = "unlinked asynchronuously";
+               break;
+       case -ENOSR:
+               errmsg = "Buffer error (overrun)";
+               break;
+       case -EPIPE:
+               errmsg = "Stalled (device not responding)";
+               break;
+       case -EOVERFLOW:
+               errmsg = "Babble (bad cable?)";
+               break;
+       case -EPROTO:
+               errmsg = "Bit-stuff error (bad cable?)";
+               break;
+       case -EILSEQ:
+               errmsg = "CRC/Timeout (could be anything)";
+               break;
+       case -ETIME:
+               errmsg = "Device does not respond";
+               break;
+       }
+       if (packet<0) {
+               dprintk(dev, V4L2_DEBUG_QUEUE, "URB status %d [%s].\n",
+                       status, errmsg);
+       } else {
+               dprintk(dev, V4L2_DEBUG_QUEUE, "URB packet %d, status %d [%s].\n",
+                       packet, status, errmsg);
+       }
+}
+
+
+/*
+ * Controls the isoc copy of each urb packet
+ */
+static inline int tm6000_isoc_copy(struct urb *urb)
+{
+       struct tm6000_dmaqueue  *dma_q = urb->context;
+       struct tm6000_core *dev= container_of(dma_q,struct tm6000_core,vidq);
+       struct tm6000_buffer *buf;
+       int i, len=0, rc=1;
+       int size;
+       char *outp = NULL, *p;
+       unsigned long copied;
+
+       get_next_buf(dma_q, &buf);
+       if (buf)
+               outp = videobuf_to_vmalloc(&buf->vb);
+
+       if (!outp)
+               return 0;
+
+       size = buf->vb.size;
+
+       copied=0;
+
+       if (urb->status<0) {
+               print_err_status (dev,-1,urb->status);
+               return 0;
+       }
+
+       for (i = 0; i < urb->number_of_packets; i++) {
+               int status = urb->iso_frame_desc[i].status;
+
+               if (status<0) {
+                       print_err_status (dev,i,status);
+                       continue;
+               }
+
+               len=urb->iso_frame_desc[i].actual_length;
+
+//             if (len>=TM6000_URB_MSG_LEN) {
+                       p=urb->transfer_buffer + urb->iso_frame_desc[i].offset;
+                       if (!urb->iso_frame_desc[i].status) {
+                               if ((buf->fmt->fourcc)==V4L2_PIX_FMT_TM6000) {
+                                       rc=copy_multiplexed(p, outp, len, urb, &buf);
+                                       if (rc<=0)
+                                               return rc;
+                               } else {
+                                       copy_streams(p, outp, len, urb, &buf);
+                               }
+                       }
+                       copied += len;
+                       if (copied >= size || !buf)
+                               break;
+//             }
+       }
+       return rc;
+}
+
+/* ------------------------------------------------------------------
+       URB control
+   ------------------------------------------------------------------*/
+
+/*
+ * IRQ callback, called by URB callback
+ */
+static void tm6000_irq_callback(struct urb *urb)
+{
+       struct tm6000_dmaqueue  *dma_q = urb->context;
+       struct tm6000_core *dev = container_of(dma_q, struct tm6000_core, vidq);
+       int i;
+
+       if (!dev)
+               return;
+
+       spin_lock(&dev->slock);
+       tm6000_isoc_copy(urb);
+       spin_unlock(&dev->slock);
+
+       /* Reset urb buffers */
+       for (i = 0; i < urb->number_of_packets; i++) {
+               urb->iso_frame_desc[i].status = 0;
+               urb->iso_frame_desc[i].actual_length = 0;
+       }
+
+       urb->status = usb_submit_urb(urb, GFP_ATOMIC);
+       if (urb->status)
+               tm6000_err("urb resubmit failed (error=%i)\n",
+                       urb->status);
+}
+
+/*
+ * Stop and Deallocate URBs
+ */
+static void tm6000_uninit_isoc(struct tm6000_core *dev)
+{
+       struct urb *urb;
+       int i;
+
+       dev->isoc_ctl.nfields = -1;
+       dev->isoc_ctl.buf = NULL;
+       for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
+               urb=dev->isoc_ctl.urb[i];
+               if (urb) {
+                       usb_kill_urb(urb);
+                       usb_unlink_urb(urb);
+                       if (dev->isoc_ctl.transfer_buffer[i]) {
+                               usb_free_coherent(dev->udev,
+                                               urb->transfer_buffer_length,
+                                               dev->isoc_ctl.transfer_buffer[i],
+                                               urb->transfer_dma);
+                       }
+                       usb_free_urb(urb);
+                       dev->isoc_ctl.urb[i] = NULL;
+               }
+               dev->isoc_ctl.transfer_buffer[i] = NULL;
+       }
+
+       kfree (dev->isoc_ctl.urb);
+       kfree (dev->isoc_ctl.transfer_buffer);
+
+       dev->isoc_ctl.urb=NULL;
+       dev->isoc_ctl.transfer_buffer=NULL;
+       dev->isoc_ctl.num_bufs = 0;
+
+       dev->isoc_ctl.num_bufs=0;
+}
+
+/*
+ * Allocate URBs and start IRQ
+ */
+static int tm6000_prepare_isoc(struct tm6000_core *dev, unsigned int framesize)
+{
+       struct tm6000_dmaqueue *dma_q = &dev->vidq;
+       int i, j, sb_size, pipe, size, max_packets, num_bufs = 5;
+       struct urb *urb;
+
+       /* De-allocates all pending stuff */
+       tm6000_uninit_isoc(dev);
+
+       usb_set_interface(dev->udev,
+                         dev->isoc_in.bInterfaceNumber,
+                         dev->isoc_in.bAlternateSetting);
+
+       pipe = usb_rcvisocpipe(dev->udev,
+                              dev->isoc_in.endp->desc.bEndpointAddress &
+                              USB_ENDPOINT_NUMBER_MASK);
+
+       size = usb_maxpacket(dev->udev, pipe, usb_pipeout(pipe));
+
+       if (size > dev->isoc_in.maxsize)
+               size = dev->isoc_in.maxsize;
+
+       dev->isoc_ctl.max_pkt_size = size;
+
+       max_packets = ( framesize + size - 1) / size;
+
+       if (max_packets > TM6000_MAX_ISO_PACKETS)
+               max_packets = TM6000_MAX_ISO_PACKETS;
+
+       sb_size = max_packets * size;
+
+       dev->isoc_ctl.num_bufs = num_bufs;
+
+       dev->isoc_ctl.urb = kmalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
+       if (!dev->isoc_ctl.urb) {
+               tm6000_err("cannot alloc memory for usb buffers\n");
+               return -ENOMEM;
+       }
+
+       dev->isoc_ctl.transfer_buffer = kmalloc(sizeof(void *)*num_bufs,
+                                  GFP_KERNEL);
+       if (!dev->isoc_ctl.transfer_buffer) {
+               tm6000_err("cannot allocate memory for usbtransfer\n");
+               kfree(dev->isoc_ctl.urb);
+               return -ENOMEM;
+       }
+
+       dprintk(dev, V4L2_DEBUG_QUEUE, "Allocating %d x %d packets"
+                   " (%d bytes) of %d bytes each to handle %u size\n",
+                   max_packets, num_bufs, sb_size,
+                   dev->isoc_in.maxsize, size);
+
+       /* allocate urbs and transfer buffers */
+       for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
+               urb = usb_alloc_urb(max_packets, GFP_KERNEL);
+               if (!urb) {
+                       tm6000_err("cannot alloc isoc_ctl.urb %i\n", i);
+                       tm6000_uninit_isoc(dev);
+                       usb_free_urb(urb);
+                       return -ENOMEM;
+               }
+               dev->isoc_ctl.urb[i] = urb;
+
+               dev->isoc_ctl.transfer_buffer[i] = usb_alloc_coherent(dev->udev,
+                       sb_size, GFP_KERNEL, &urb->transfer_dma);
+               if (!dev->isoc_ctl.transfer_buffer[i]) {
+                       tm6000_err ("unable to allocate %i bytes for transfer"
+                                       " buffer %i%s\n",
+                                       sb_size, i,
+                                       in_interrupt()?" while in int":"");
+                       tm6000_uninit_isoc(dev);
+                       return -ENOMEM;
+               }
+               memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
+
+               usb_fill_bulk_urb(urb, dev->udev, pipe,
+                                 dev->isoc_ctl.transfer_buffer[i], sb_size,
+                                 tm6000_irq_callback, dma_q);
+               urb->interval = dev->isoc_in.endp->desc.bInterval;
+               urb->number_of_packets = max_packets;
+               urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+
+               for (j = 0; j < max_packets; j++) {
+                       urb->iso_frame_desc[j].offset = size * j;
+                       urb->iso_frame_desc[j].length = size;
+               }
+       }
+
+       return 0;
+}
+
+static int tm6000_start_thread( struct tm6000_core *dev)
+{
+       struct tm6000_dmaqueue *dma_q = &dev->vidq;
+       int i;
+
+       dma_q->frame=0;
+       dma_q->ini_jiffies=jiffies;
+
+       init_waitqueue_head(&dma_q->wq);
+
+       /* submit urbs and enables IRQ */
+       for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
+               int rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
+               if (rc) {
+                       tm6000_err("submit of urb %i failed (error=%i)\n", i,
+                                  rc);
+                       tm6000_uninit_isoc(dev);
+                       return rc;
+               }
+       }
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------
+       Videobuf operations
+   ------------------------------------------------------------------*/
+
+static int
+buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
+{
+       struct tm6000_fh *fh = vq->priv_data;
+
+       *size = fh->fmt->depth * fh->width * fh->height >> 3;
+       if (0 == *count)
+               *count = TM6000_DEF_BUF;
+
+       if (*count < TM6000_MIN_BUF) {
+               *count=TM6000_MIN_BUF;
+       }
+
+       while (*size * *count > vid_limit * 1024 * 1024)
+               (*count)--;
+
+       return 0;
+}
+
+static void free_buffer(struct videobuf_queue *vq, struct tm6000_buffer *buf)
+{
+       struct tm6000_fh *fh = vq->priv_data;
+       struct tm6000_core   *dev = fh->dev;
+       unsigned long flags;
+
+       if (in_interrupt())
+               BUG();
+
+       /* We used to wait for the buffer to finish here, but this didn't work
+          because, as we were keeping the state as VIDEOBUF_QUEUED,
+          videobuf_queue_cancel marked it as finished for us.
+          (Also, it could wedge forever if the hardware was misconfigured.)
+
+          This should be safe; by the time we get here, the buffer isn't
+          queued anymore. If we ever start marking the buffers as
+          VIDEOBUF_ACTIVE, it won't be, though.
+       */
+       spin_lock_irqsave(&dev->slock, flags);
+       if (dev->isoc_ctl.buf == buf)
+               dev->isoc_ctl.buf = NULL;
+       spin_unlock_irqrestore(&dev->slock, flags);
+
+       videobuf_vmalloc_free(&buf->vb);
+       buf->vb.state = VIDEOBUF_NEEDS_INIT;
+}
+
+static int
+buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
+                                               enum v4l2_field field)
+{
+       struct tm6000_fh     *fh  = vq->priv_data;
+       struct tm6000_buffer *buf = container_of(vb,struct tm6000_buffer,vb);
+       struct tm6000_core   *dev = fh->dev;
+       int rc = 0, urb_init = 0;
+
+       BUG_ON(NULL == fh->fmt);
+
+
+       /* FIXME: It assumes depth=2 */
+       /* The only currently supported format is 16 bits/pixel */
+       buf->vb.size = fh->fmt->depth*fh->width*fh->height >> 3;
+       if (0 != buf->vb.baddr  &&  buf->vb.bsize < buf->vb.size)
+               return -EINVAL;
+
+       if (buf->fmt       != fh->fmt    ||
+           buf->vb.width  != fh->width  ||
+           buf->vb.height != fh->height ||
+           buf->vb.field  != field) {
+               buf->fmt       = fh->fmt;
+               buf->vb.width  = fh->width;
+               buf->vb.height = fh->height;
+               buf->vb.field  = field;
+               buf->vb.state = VIDEOBUF_NEEDS_INIT;
+       }
+
+       if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
+               if (0 != (rc = videobuf_iolock(vq, &buf->vb, NULL)))
+                       goto fail;
+               urb_init = 1;
+       }
+
+       if (!dev->isoc_ctl.num_bufs)
+               urb_init = 1;
+
+       if (urb_init) {
+               rc = tm6000_prepare_isoc(dev, buf->vb.size);
+               if (rc < 0)
+                       goto fail;
+
+               rc = tm6000_start_thread(dev);
+               if (rc < 0)
+                       goto fail;
+
+       }
+
+       buf->vb.state = VIDEOBUF_PREPARED;
+       return 0;
+
+fail:
+       free_buffer(vq, buf);
+       return rc;
+}
+
+static void
+buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
+{
+       struct tm6000_buffer    *buf     = container_of(vb,struct tm6000_buffer,vb);
+       struct tm6000_fh        *fh      = vq->priv_data;
+       struct tm6000_core      *dev     = fh->dev;
+       struct tm6000_dmaqueue  *vidq    = &dev->vidq;
+
+       buf->vb.state = VIDEOBUF_QUEUED;
+       list_add_tail(&buf->vb.queue, &vidq->active);
+}
+
+static void buffer_release(struct videobuf_queue *vq, struct videobuf_buffer *vb)
+{
+       struct tm6000_buffer   *buf  = container_of(vb,struct tm6000_buffer,vb);
+
+       free_buffer(vq,buf);
+}
+
+static struct videobuf_queue_ops tm6000_video_qops = {
+       .buf_setup      = buffer_setup,
+       .buf_prepare    = buffer_prepare,
+       .buf_queue      = buffer_queue,
+       .buf_release    = buffer_release,
+};
+
+/* ------------------------------------------------------------------
+       IOCTL handling
+   ------------------------------------------------------------------*/
+
+static int res_get(struct tm6000_core *dev, struct tm6000_fh *fh)
+{
+       /* is it free? */
+       mutex_lock(&dev->lock);
+       if (dev->resources) {
+               /* no, someone else uses it */
+               mutex_unlock(&dev->lock);
+               return 0;
+       }
+       /* it's free, grab it */
+       dev->resources =1;
+       dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: get\n");
+       mutex_unlock(&dev->lock);
+       return 1;
+}
+
+static int res_locked(struct tm6000_core *dev)
+{
+       return (dev->resources);
+}
+
+static void res_free(struct tm6000_core *dev, struct tm6000_fh *fh)
+{
+       mutex_lock(&dev->lock);
+       dev->resources = 0;
+       dprintk(dev, V4L2_DEBUG_RES_LOCK, "res: put\n");
+       mutex_unlock(&dev->lock);
+}
+
+/* ------------------------------------------------------------------
+       IOCTL vidioc handling
+   ------------------------------------------------------------------*/
+static int vidioc_querycap (struct file *file, void  *priv,
+                                       struct v4l2_capability *cap)
+{
+       //      struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
+
+       strlcpy(cap->driver, "tm6000", sizeof(cap->driver));
+       strlcpy(cap->card,"Trident TVMaster TM5600/6000/6010", sizeof(cap->card));
+       //      strlcpy(cap->bus_info, dev->udev->dev.bus_id, sizeof(cap->bus_info));
+       cap->version = TM6000_VERSION;
+       cap->capabilities =     V4L2_CAP_VIDEO_CAPTURE |
+                               V4L2_CAP_STREAMING     |
+                               V4L2_CAP_TUNER         |
+                               V4L2_CAP_READWRITE;
+       return 0;
+}
+
+static int vidioc_enum_fmt_vid_cap (struct file *file, void  *priv,
+                                       struct v4l2_fmtdesc *f)
+{
+       if (unlikely(f->index >= ARRAY_SIZE(format)))
+               return -EINVAL;
+
+       strlcpy(f->description,format[f->index].name,sizeof(f->description));
+       f->pixelformat = format[f->index].fourcc;
+       return 0;
+}
+
+static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
+                                       struct v4l2_format *f)
+{
+       struct tm6000_fh  *fh=priv;
+
+       f->fmt.pix.width        = fh->width;
+       f->fmt.pix.height       = fh->height;
+       f->fmt.pix.field        = fh->vb_vidq.field;
+       f->fmt.pix.pixelformat  = fh->fmt->fourcc;
+       f->fmt.pix.bytesperline =
+               (f->fmt.pix.width * fh->fmt->depth) >> 3;
+       f->fmt.pix.sizeimage =
+               f->fmt.pix.height * f->fmt.pix.bytesperline;
+
+       return (0);
+}
+
+static struct tm6000_fmt* format_by_fourcc(unsigned int fourcc)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(format); i++)
+               if (format[i].fourcc == fourcc)
+                       return format+i;
+       return NULL;
+}
+
+static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
+                       struct v4l2_format *f)
+{
+       struct tm6000_core *dev = ((struct tm6000_fh *)priv)->dev;
+       struct tm6000_fmt *fmt;
+       enum v4l2_field field;
+
+       fmt = format_by_fourcc(f->fmt.pix.pixelformat);
+       if (NULL == fmt) {
+               dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)"
+                               " invalid.\n", f->fmt.pix.pixelformat);
+               return -EINVAL;
+       }
+
+       field = f->fmt.pix.field;
+
+       if (field == V4L2_FIELD_ANY) {
+//             field=V4L2_FIELD_INTERLACED;
+               field=V4L2_FIELD_SEQ_TB;
+       } else if (V4L2_FIELD_INTERLACED != field) {
+               dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Field type invalid.\n");
+               return -EINVAL;
+       }
+
+       tm6000_get_std_res (dev);
+
+       f->fmt.pix.width  = dev->width;
+       f->fmt.pix.height = dev->height;
+
+       f->fmt.pix.width &= ~0x01;
+
+       f->fmt.pix.field = field;
+
+       f->fmt.pix.bytesperline =
+               (f->fmt.pix.width * fmt->depth) >> 3;
+       f->fmt.pix.sizeimage =
+               f->fmt.pix.height * f->fmt.pix.bytesperline;
+
+       return 0;
+}
+
+/*FIXME: This seems to be generic enough to be at videodev2 */
+static int vidioc_s_fmt_vid_cap (struct file *file, void *priv,
+                                       struct v4l2_format *f)
+{
+       struct tm6000_fh  *fh=priv;
+       struct tm6000_core *dev = fh->dev;
+       int ret = vidioc_try_fmt_vid_cap(file,fh,f);
+       if (ret < 0)
+               return (ret);
+
+       fh->fmt           = format_by_fourcc(f->fmt.pix.pixelformat);
+       fh->width         = f->fmt.pix.width;
+       fh->height        = f->fmt.pix.height;
+       fh->vb_vidq.field = f->fmt.pix.field;
+       fh->type          = f->type;
+
+       dev->fourcc       = f->fmt.pix.pixelformat;
+
+       tm6000_set_fourcc_format(dev);
+
+       return (0);
+}
+
+static int vidioc_reqbufs (struct file *file, void *priv,
+                          struct v4l2_requestbuffers *p)
+{
+       struct tm6000_fh  *fh=priv;
+
+       return (videobuf_reqbufs(&fh->vb_vidq, p));
+}
+
+static int vidioc_querybuf (struct file *file, void *priv,
+                           struct v4l2_buffer *p)
+{
+       struct tm6000_fh  *fh=priv;
+
+       return (videobuf_querybuf(&fh->vb_vidq, p));
+}
+
+static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *p)
+{
+       struct tm6000_fh  *fh=priv;
+
+       return (videobuf_qbuf(&fh->vb_vidq, p));
+}
+
+static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *p)
+{
+       struct tm6000_fh  *fh=priv;
+
+       return (videobuf_dqbuf(&fh->vb_vidq, p,
+                               file->f_flags & O_NONBLOCK));
+}
+
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+static int vidiocgmbuf (struct file *file, void *priv, struct video_mbuf *mbuf)
+{
+       struct tm6000_fh  *fh=priv;
+
+       return videobuf_cgmbuf (&fh->vb_vidq, mbuf, 8);
+}
+#endif
+
+static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
+{
+       struct tm6000_fh  *fh=priv;
+       struct tm6000_core *dev    = fh->dev;
+
+       if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+       if (i != fh->type)
+               return -EINVAL;
+
+       if (!res_get(dev,fh))
+               return -EBUSY;
+       return (videobuf_streamon(&fh->vb_vidq));
+}
+
+static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
+{
+       struct tm6000_fh  *fh=priv;
+       struct tm6000_core *dev    = fh->dev;
+
+       if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
+               return -EINVAL;
+       if (i != fh->type)
+               return -EINVAL;
+
+       videobuf_streamoff(&fh->vb_vidq);
+       res_free(dev,fh);
+
+       return (0);
+}
+
+static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *norm)
+{
+       int rc=0;
+       struct tm6000_fh   *fh=priv;
+       struct tm6000_core *dev = fh->dev;
+
+       rc=tm6000_set_standard (dev, norm);
+
+       fh->width  = dev->width;
+       fh->height = dev->height;
+
+       if (rc<0)
+               return rc;
+
+       v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
+
+       return 0;
+}
+
+static int vidioc_enum_input (struct file *file, void *priv,
+                               struct v4l2_input *inp)
+{
+       switch (inp->index) {
+       case TM6000_INPUT_TV:
+               inp->type = V4L2_INPUT_TYPE_TUNER;
+               strcpy(inp->name,"Television");
+               break;
+       case TM6000_INPUT_COMPOSITE:
+               inp->type = V4L2_INPUT_TYPE_CAMERA;
+               strcpy(inp->name,"Composite");
+               break;
+       case TM6000_INPUT_SVIDEO:
+               inp->type = V4L2_INPUT_TYPE_CAMERA;
+               strcpy(inp->name,"S-Video");
+               break;
+       default:
+               return -EINVAL;
+       }
+       inp->std = TM6000_STD;
+
+       return 0;
+}
+
+static int vidioc_g_input (struct file *file, void *priv, unsigned int *i)
+{
+       struct tm6000_fh   *fh=priv;
+       struct tm6000_core *dev = fh->dev;
+
+       *i=dev->input;
+
+       return 0;
+}
+static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
+{
+       struct tm6000_fh   *fh=priv;
+       struct tm6000_core *dev = fh->dev;
+       int rc=0;
+       char buf[1];
+
+       switch (i) {
+       case TM6000_INPUT_TV:
+               dev->input=i;
+               *buf=0;
+               break;
+       case TM6000_INPUT_COMPOSITE:
+       case TM6000_INPUT_SVIDEO:
+               dev->input=i;
+               *buf=1;
+               break;
+       default:
+               return -EINVAL;
+       }
+       rc=tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR,
+                              REQ_03_SET_GET_MCU_PIN, 0x03, 1, buf, 1);
+
+       if (!rc) {
+               dev->input=i;
+               rc=vidioc_s_std (file, priv, &dev->vfd->current_norm);
+       }
+
+       return (rc);
+}
+
+       /* --- controls ---------------------------------------------- */
+static int vidioc_queryctrl (struct file *file, void *priv,
+                               struct v4l2_queryctrl *qc)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
+               if (qc->id && qc->id == tm6000_qctrl[i].id) {
+                       memcpy(qc, &(tm6000_qctrl[i]),
+                               sizeof(*qc));
+                       return (0);
+               }
+
+       return -EINVAL;
+}
+
+static int vidioc_g_ctrl (struct file *file, void *priv,
+                               struct v4l2_control *ctrl)
+{
+       struct tm6000_fh  *fh=priv;
+       struct tm6000_core *dev    = fh->dev;
+       int  val;
+
+       /* FIXME: Probably, those won't work! Maybe we need shadow regs */
+       switch (ctrl->id) {
+       case V4L2_CID_CONTRAST:
+               val = tm6000_get_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, 0);
+               break;
+       case V4L2_CID_BRIGHTNESS:
+               val = tm6000_get_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, 0);
+               return 0;
+       case V4L2_CID_SATURATION:
+               val = tm6000_get_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, 0);
+               return 0;
+       case V4L2_CID_HUE:
+               val = tm6000_get_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, 0);
+               return 0;
+       default:
+               return -EINVAL;
+       }
+
+       if (val<0)
+               return val;
+
+       ctrl->value=val;
+
+       return 0;
+}
+static int vidioc_s_ctrl (struct file *file, void *priv,
+                               struct v4l2_control *ctrl)
+{
+       struct tm6000_fh   *fh  =priv;
+       struct tm6000_core *dev = fh->dev;
+       u8  val=ctrl->value;
+
+       switch (ctrl->id) {
+       case V4L2_CID_CONTRAST:
+  tm6000_set_reg(dev, TM6010_REQ07_R08_LUMA_CONTRAST_ADJ, val);
+               return 0;
+       case V4L2_CID_BRIGHTNESS:
+  tm6000_set_reg(dev, TM6010_REQ07_R09_LUMA_BRIGHTNESS_ADJ, val);
+               return 0;
+       case V4L2_CID_SATURATION:
+  tm6000_set_reg(dev, TM6010_REQ07_R0A_CHROMA_SATURATION_ADJ, val);
+               return 0;
+       case V4L2_CID_HUE:
+  tm6000_set_reg(dev, TM6010_REQ07_R0B_CHROMA_HUE_PHASE_ADJ, val);
+               return 0;
+       }
+       return -EINVAL;
+}
+
+static int vidioc_g_tuner (struct file *file, void *priv,
+                               struct v4l2_tuner *t)
+{
+       struct tm6000_fh   *fh  =priv;
+       struct tm6000_core *dev = fh->dev;
+
+       if (unlikely(UNSET == dev->tuner_type))
+               return -EINVAL;
+       if (0 != t->index)
+               return -EINVAL;
+
+       strcpy(t->name, "Television");
+       t->type       = V4L2_TUNER_ANALOG_TV;
+       t->capability = V4L2_TUNER_CAP_NORM;
+       t->rangehigh  = 0xffffffffUL;
+       t->rxsubchans = V4L2_TUNER_SUB_MONO;
+
+       return 0;
+}
+
+static int vidioc_s_tuner (struct file *file, void *priv,
+                               struct v4l2_tuner *t)
+{
+       struct tm6000_fh   *fh  =priv;
+       struct tm6000_core *dev = fh->dev;
+
+       if (UNSET == dev->tuner_type)
+               return -EINVAL;
+       if (0 != t->index)
+               return -EINVAL;
+
+       return 0;
+}
+
+static int vidioc_g_frequency (struct file *file, void *priv,
+                               struct v4l2_frequency *f)
+{
+       struct tm6000_fh   *fh  =priv;
+       struct tm6000_core *dev = fh->dev;
+
+       if (unlikely(UNSET == dev->tuner_type))
+               return -EINVAL;
+
+       f->type = V4L2_TUNER_ANALOG_TV;
+       f->frequency = dev->freq;
+
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_frequency, f);
+
+       return 0;
+}
+
+static int vidioc_s_frequency (struct file *file, void *priv,
+                               struct v4l2_frequency *f)
+{
+       struct tm6000_fh   *fh  =priv;
+       struct tm6000_core *dev = fh->dev;
+
+       if (unlikely(f->type != V4L2_TUNER_ANALOG_TV))
+               return -EINVAL;
+
+       if (unlikely(UNSET == dev->tuner_type))
+               return -EINVAL;
+       if (unlikely(f->tuner != 0))
+               return -EINVAL;
+
+//     mutex_lock(&dev->lock);
+       dev->freq = f->frequency;
+       v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, f);
+//     mutex_unlock(&dev->lock);
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------
+       File operations for the device
+   ------------------------------------------------------------------*/
+
+static int tm6000_open(struct file *file)
+{
+       struct video_device *vdev = video_devdata(file);
+       struct tm6000_core *dev = video_drvdata(file);
+       struct tm6000_fh *fh;
+       enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       int i,rc;
+
+       printk(KERN_INFO "tm6000: open called (dev=%s)\n",
+               video_device_node_name(vdev));
+
+       dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: open called (dev=%s)\n",
+               video_device_node_name(vdev));
+
+
+       /* If more than one user, mutex should be added */
+       dev->users++;
+
+       dprintk(dev, V4L2_DEBUG_OPEN, "open dev=%s type=%s users=%d\n",
+               video_device_node_name(vdev), v4l2_type_names[type],
+               dev->users);
+
+       /* allocate + initialize per filehandle data */
+       fh = kzalloc(sizeof(*fh),GFP_KERNEL);
+       if (NULL == fh) {
+               dev->users--;
+               return -ENOMEM;
+       }
+
+       file->private_data = fh;
+       fh->dev      = dev;
+
+       fh->type     = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       dev->fourcc  = format[0].fourcc;
+
+       fh->fmt      = format_by_fourcc(dev->fourcc);
+
+       tm6000_get_std_res (dev);
+
+       fh->width    = dev->width;
+       fh->height   = dev->height;
+
+       dprintk(dev, V4L2_DEBUG_OPEN, "Open: fh=0x%08lx, dev=0x%08lx, "
+                                               "dev->vidq=0x%08lx\n",
+               (unsigned long)fh,(unsigned long)dev,(unsigned long)&dev->vidq);
+       dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
+                               "queued=%d\n",list_empty(&dev->vidq.queued));
+       dprintk(dev, V4L2_DEBUG_OPEN, "Open: list_empty "
+                               "active=%d\n",list_empty(&dev->vidq.active));
+
+       /* initialize hardware on analog mode */
+       if (dev->mode!=TM6000_MODE_ANALOG) {
+               rc=tm6000_init_analog_mode (dev);
+               if (rc<0)
+                       return rc;
+
+               /* Put all controls at a sane state */
+               for (i = 0; i < ARRAY_SIZE(tm6000_qctrl); i++)
+                       qctl_regs[i] =tm6000_qctrl[i].default_value;
+
+               dev->mode=TM6000_MODE_ANALOG;
+       }
+
+       videobuf_queue_vmalloc_init(&fh->vb_vidq, &tm6000_video_qops,
+                       NULL, &dev->slock,
+                       fh->type,
+                       V4L2_FIELD_INTERLACED,
+                       sizeof(struct tm6000_buffer),fh);
+
+       return 0;
+}
+
+static ssize_t
+tm6000_read(struct file *file, char __user *data, size_t count, loff_t *pos)
+{
+       struct tm6000_fh        *fh = file->private_data;
+
+       if (fh->type==V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+               if (res_locked(fh->dev))
+                       return -EBUSY;
+
+               return videobuf_read_stream(&fh->vb_vidq, data, count, pos, 0,
+                                       file->f_flags & O_NONBLOCK);
+       }
+       return 0;
+}
+
+static unsigned int
+tm6000_poll(struct file *file, struct poll_table_struct *wait)
+{
+       struct tm6000_fh        *fh = file->private_data;
+       struct tm6000_buffer    *buf;
+
+       if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
+               return POLLERR;
+
+       if (res_get(fh->dev,fh)) {
+               /* streaming capture */
+               if (list_empty(&fh->vb_vidq.stream))
+                       return POLLERR;
+               buf = list_entry(fh->vb_vidq.stream.next,struct tm6000_buffer,vb.stream);
+       } else {
+               /* read() capture */
+               return videobuf_poll_stream(file, &fh->vb_vidq,
+                                           wait);
+       }
+       poll_wait(file, &buf->vb.done, wait);
+       if (buf->vb.state == VIDEOBUF_DONE ||
+           buf->vb.state == VIDEOBUF_ERROR)
+               return POLLIN|POLLRDNORM;
+       return 0;
+}
+
+static int tm6000_release(struct file *file)
+{
+       struct tm6000_fh         *fh = file->private_data;
+       struct tm6000_core      *dev = fh->dev;
+       struct video_device    *vdev = video_devdata(file);
+
+       dprintk(dev, V4L2_DEBUG_OPEN, "tm6000: close called (dev=%s, users=%d)\n",
+               video_device_node_name(vdev), dev->users);
+
+       dev->users--;
+
+       if (!dev->users) {
+               tm6000_uninit_isoc(dev);
+               videobuf_mmap_free(&fh->vb_vidq);
+       }
+
+       kfree (fh);
+
+       return 0;
+}
+
+static int tm6000_mmap(struct file *file, struct vm_area_struct * vma)
+{
+       struct tm6000_fh        *fh = file->private_data;
+       int ret;
+
+       ret=videobuf_mmap_mapper(&fh->vb_vidq, vma);
+
+       return ret;
+}
+
+static struct v4l2_file_operations tm6000_fops = {
+       .owner          = THIS_MODULE,
+       .open           = tm6000_open,
+       .release        = tm6000_release,
+       .ioctl          = video_ioctl2, /* V4L2 ioctl handler */
+       .read           = tm6000_read,
+       .poll           = tm6000_poll,
+       .mmap           = tm6000_mmap,
+};
+
+static const struct v4l2_ioctl_ops video_ioctl_ops = {
+       .vidioc_querycap          = vidioc_querycap,
+       .vidioc_enum_fmt_vid_cap  = vidioc_enum_fmt_vid_cap,
+       .vidioc_g_fmt_vid_cap     = vidioc_g_fmt_vid_cap,
+       .vidioc_try_fmt_vid_cap   = vidioc_try_fmt_vid_cap,
+       .vidioc_s_fmt_vid_cap     = vidioc_s_fmt_vid_cap,
+       .vidioc_s_std             = vidioc_s_std,
+       .vidioc_enum_input        = vidioc_enum_input,
+       .vidioc_g_input           = vidioc_g_input,
+       .vidioc_s_input           = vidioc_s_input,
+       .vidioc_queryctrl         = vidioc_queryctrl,
+       .vidioc_g_ctrl            = vidioc_g_ctrl,
+       .vidioc_s_ctrl            = vidioc_s_ctrl,
+       .vidioc_g_tuner           = vidioc_g_tuner,
+       .vidioc_s_tuner           = vidioc_s_tuner,
+       .vidioc_g_frequency       = vidioc_g_frequency,
+       .vidioc_s_frequency       = vidioc_s_frequency,
+       .vidioc_streamon          = vidioc_streamon,
+       .vidioc_streamoff         = vidioc_streamoff,
+       .vidioc_reqbufs           = vidioc_reqbufs,
+       .vidioc_querybuf          = vidioc_querybuf,
+       .vidioc_qbuf              = vidioc_qbuf,
+       .vidioc_dqbuf             = vidioc_dqbuf,
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       .vidiocgmbuf              = vidiocgmbuf,
+#endif
+};
+
+static struct video_device tm6000_template = {
+       .name           = "tm6000",
+       .fops           = &tm6000_fops,
+       .ioctl_ops      = &video_ioctl_ops,
+       .release        = video_device_release,
+       .tvnorms        = TM6000_STD,
+       .current_norm   = V4L2_STD_NTSC_M,
+};
+
+/* -----------------------------------------------------------------
+       Initialization and module stuff
+   ------------------------------------------------------------------*/
+
+int tm6000_v4l2_register(struct tm6000_core *dev)
+{
+       int ret = -1;
+       struct video_device *vfd;
+
+       vfd = video_device_alloc();
+       if(!vfd) {
+               return -ENOMEM;
+       }
+       dev->vfd = vfd;
+
+       /* init video dma queues */
+       INIT_LIST_HEAD(&dev->vidq.active);
+       INIT_LIST_HEAD(&dev->vidq.queued);
+
+       memcpy (dev->vfd, &tm6000_template, sizeof(*(dev->vfd)));
+       dev->vfd->debug=tm6000_debug;
+       vfd->v4l2_dev = &dev->v4l2_dev;
+       video_set_drvdata(vfd, dev);
+
+       ret = video_register_device(dev->vfd, VFL_TYPE_GRABBER, video_nr);
+       printk(KERN_INFO "Trident TVMaster TM5600/TM6000/TM6010 USB2 board (Load status: %d)\n", ret);
+       return ret;
+}
+
+int tm6000_v4l2_unregister(struct tm6000_core *dev)
+{
+       video_unregister_device(dev->vfd);
+
+       return 0;
+}
+
+int tm6000_v4l2_exit(void)
+{
+       return 0;
+}
+
+module_param(video_nr, int, 0);
+MODULE_PARM_DESC(video_nr,"Allow changing video device number");
+
+module_param_named (debug, tm6000_debug, int, 0444);
+MODULE_PARM_DESC(debug,"activates debug info");
+
+module_param(vid_limit,int,0644);
+MODULE_PARM_DESC(vid_limit,"capture memory limit in megabytes");
+
diff --git a/drivers/staging/tm6000/tm6000.h b/drivers/staging/tm6000/tm6000.h
new file mode 100644 (file)
index 0000000..6812d68
--- /dev/null
@@ -0,0 +1,301 @@
+/*
+   tm6000.h - driver for TM5600/TM6000/TM6010 USB video capture devices
+
+   Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
+
+   Copyright (C) 2007 Michel Ludwig <michel.ludwig@gmail.com>
+       - DVB-T 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 version 2
+
+   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.
+ */
+
+// Use the tm6000-hack, instead of the proper initialization code
+//#define HACK 1
+
+#include <linux/videodev2.h>
+#include <media/v4l2-common.h>
+#include <media/videobuf-vmalloc.h>
+#include "tm6000-usb-isoc.h"
+#include <linux/i2c.h>
+#include <linux/mutex.h>
+#include <media/v4l2-device.h>
+
+
+#include <linux/dvb/frontend.h>
+#include "dvb_demux.h"
+#include "dvb_frontend.h"
+#include "dmxdev.h"
+
+#define TM6000_VERSION KERNEL_VERSION(0, 0, 2)
+
+/* Inputs */
+
+enum tm6000_itype {
+       TM6000_INPUT_TV = 0,
+       TM6000_INPUT_COMPOSITE,
+       TM6000_INPUT_SVIDEO,
+};
+
+enum tm6000_devtype {
+       TM6000 = 0,
+       TM5600,
+       TM6010,
+};
+
+/* ------------------------------------------------------------------
+       Basic structures
+   ------------------------------------------------------------------*/
+
+struct tm6000_fmt {
+       char  *name;
+       u32   fourcc;          /* v4l2 format id */
+       int   depth;
+};
+
+/* buffer for one video frame */
+struct tm6000_buffer {
+       /* common v4l buffer stuff -- must be first */
+       struct videobuf_buffer vb;
+
+       struct tm6000_fmt      *fmt;
+};
+
+struct tm6000_dmaqueue {
+       struct list_head       active;
+       struct list_head       queued;
+
+       /* thread for generating video stream*/
+       struct task_struct         *kthread;
+       wait_queue_head_t          wq;
+       /* Counters to control fps rate */
+       int                        frame;
+       int                        ini_jiffies;
+};
+
+/* device states */
+enum tm6000_core_state {
+       DEV_INITIALIZED   = 0x01,
+       DEV_DISCONNECTED  = 0x02,
+       DEV_MISCONFIGURED = 0x04,
+};
+
+/* io methods */
+enum tm6000_io_method {
+       IO_NONE,
+       IO_READ,
+       IO_MMAP,
+};
+
+enum tm6000_mode {
+       TM6000_MODE_UNKNOWN=0,
+       TM6000_MODE_ANALOG,
+       TM6000_MODE_DIGITAL,
+};
+
+struct tm6000_gpio {
+       int             tuner_reset;
+       int             tuner_on;
+       int             demod_reset;
+       int             demod_on;
+       int             power_led;
+       int             dvb_led;
+       int             ir;
+};
+
+struct tm6000_capabilities {
+       unsigned int    has_tuner:1;
+       unsigned int    has_tda9874:1;
+       unsigned int    has_dvb:1;
+       unsigned int    has_zl10353:1;
+       unsigned int    has_eeprom:1;
+       unsigned int    has_remote:1;
+};
+
+struct tm6000_dvb {
+       struct dvb_adapter      adapter;
+       struct dvb_demux        demux;
+       struct dvb_frontend     *frontend;
+       struct dmxdev           dmxdev;
+       unsigned int            streams;
+       struct urb              *bulk_urb;
+       struct mutex            mutex;
+};
+
+struct tm6000_endpoint {
+       struct usb_host_endpoint        *endp;
+       __u8                            bInterfaceNumber;
+       __u8                            bAlternateSetting;
+       unsigned                        maxsize;
+};
+
+struct tm6000_core {
+       /* generic device properties */
+       char                            name[30];       /* name (including minor) of the device */
+       int                             model;          /* index in the device_data struct */
+       int                             devno;          /* marks the number of this device */
+       enum tm6000_devtype             dev_type;       /* type of device */
+
+       v4l2_std_id                     norm;           /* Current norm */
+       int                             width,height;   /* Selected resolution */
+
+       enum tm6000_core_state          state;
+
+       /* Device Capabilities*/
+       struct tm6000_capabilities      caps;
+
+       /* Tuner configuration */
+       int                             tuner_type;             /* type of the tuner */
+       int                             tuner_addr;             /* tuner address */
+
+       struct tm6000_gpio              gpio;
+
+       /* Demodulator configuration */
+       int                             demod_addr;     /* demodulator address */
+
+       int                             audio_bitrate;
+       /* i2c i/o */
+       struct i2c_adapter              i2c_adap;
+       struct i2c_client               i2c_client;
+
+       /* video for linux */
+       int                             users;
+
+       /* various device info */
+       unsigned int                    resources;
+       struct video_device             *vfd;
+       struct tm6000_dmaqueue          vidq;
+       struct v4l2_device              v4l2_dev;
+
+       int                             input;
+       int                             freq;
+       unsigned int                    fourcc;
+
+       enum tm6000_mode                mode;
+
+       /* DVB-T support */
+       struct tm6000_dvb               *dvb;
+
+       /* locks */
+       struct mutex                    lock;
+
+       /* usb transfer */
+       struct usb_device               *udev;          /* the usb device */
+
+       struct tm6000_endpoint          bulk_in, bulk_out, isoc_in, isoc_out;
+
+       /* scaler!=0 if scaler is active*/
+       int                             scaler;
+
+               /* Isoc control struct */
+       struct usb_isoc_ctl          isoc_ctl;
+
+       spinlock_t                   slock;
+};
+
+struct tm6000_fh {
+       struct tm6000_core           *dev;
+
+       /* video capture */
+       struct tm6000_fmt            *fmt;
+       unsigned int                 width,height;
+       struct videobuf_queue        vb_vidq;
+
+       enum v4l2_buf_type           type;
+};
+
+#define TM6000_STD     V4L2_STD_PAL|V4L2_STD_PAL_N|V4L2_STD_PAL_Nc|    \
+                       V4L2_STD_PAL_M|V4L2_STD_PAL_60|V4L2_STD_NTSC_M| \
+                       V4L2_STD_NTSC_M_JP|V4L2_STD_SECAM
+
+/* In tm6000-cards.c */
+
+int tm6000_tuner_callback (void *ptr, int component, int command, int arg);
+int tm6000_xc5000_callback (void *ptr, int component, int command, int arg);
+int tm6000_cards_setup(struct tm6000_core *dev);
+
+/* In tm6000-core.c */
+
+int tm6000_read_write_usb (struct tm6000_core *dev, u8 reqtype, u8 req,
+                          u16 value, u16 index, u8 *buf, u16 len);
+int tm6000_get_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
+int tm6000_get_reg16(struct tm6000_core *dev, u8 req, u16 value, u16 index);
+int tm6000_get_reg32(struct tm6000_core *dev, u8 req, u16 value, u16 index);
+int tm6000_set_reg (struct tm6000_core *dev, u8 req, u16 value, u16 index);
+int tm6000_init (struct tm6000_core *dev);
+
+int tm6000_init_analog_mode (struct tm6000_core *dev);
+int tm6000_init_digital_mode (struct tm6000_core *dev);
+int tm6000_set_audio_bitrate (struct tm6000_core *dev, int bitrate);
+
+int tm6000_dvb_register(struct tm6000_core *dev);
+void tm6000_dvb_unregister(struct tm6000_core *dev);
+
+int tm6000_v4l2_register(struct tm6000_core *dev);
+int tm6000_v4l2_unregister(struct tm6000_core *dev);
+int tm6000_v4l2_exit(void);
+void tm6000_set_fourcc_format(struct tm6000_core *dev);
+
+/* In tm6000-stds.c */
+void tm6000_get_std_res(struct tm6000_core *dev);
+int tm6000_set_standard (struct tm6000_core *dev, v4l2_std_id *norm);
+
+/* In tm6000-i2c.c */
+int tm6000_i2c_register(struct tm6000_core *dev);
+int tm6000_i2c_unregister(struct tm6000_core *dev);
+
+/* In tm6000-queue.c */
+
+int tm6000_v4l2_mmap(struct file *filp, struct vm_area_struct *vma);
+
+int tm6000_vidioc_streamon(struct file *file, void *priv,
+                          enum v4l2_buf_type i);
+int tm6000_vidioc_streamoff(struct file *file, void *priv,
+                           enum v4l2_buf_type i);
+int tm6000_vidioc_reqbufs (struct file *file, void *priv,
+                          struct v4l2_requestbuffers *rb);
+int tm6000_vidioc_querybuf (struct file *file, void *priv,
+                           struct v4l2_buffer *b);
+int tm6000_vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *b);
+int tm6000_vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *b);
+ssize_t tm6000_v4l2_read(struct file *filp, char __user * buf, size_t count,
+                        loff_t * f_pos);
+unsigned int tm6000_v4l2_poll(struct file *file,
+                             struct poll_table_struct *wait);
+int tm6000_queue_init(struct tm6000_core *dev);
+
+/* In tm6000-alsa.c */
+int tm6000_audio_init(struct tm6000_core *dev, int idx);
+
+
+/* Debug stuff */
+
+extern int tm6000_debug;
+
+#define dprintk(dev, level, fmt, arg...) do {\
+       if (tm6000_debug & level) \
+               printk(KERN_INFO "(%lu) %s %s :"fmt, jiffies,           \
+                        dev->name, __FUNCTION__ , ##arg); } while (0)
+
+#define V4L2_DEBUG_REG         0x0004
+#define V4L2_DEBUG_I2C         0x0008
+#define V4L2_DEBUG_QUEUE       0x0010
+#define V4L2_DEBUG_ISOC                0x0020
+#define V4L2_DEBUG_RES_LOCK    0x0040  /* Resource locking */
+#define V4L2_DEBUG_OPEN                0x0080  /* video open/close debug */
+
+#define tm6000_err(fmt, arg...) do {\
+       printk(KERN_ERR "tm6000 %s :"fmt, \
+               __FUNCTION__ , ##arg); } while (0)
+
+
index ed3070e..4fcc435 100644 (file)
  * Date: May 20, 2003
  *
  * Functions:
- *      s_vGenerateTxParameter - Generate tx dma requried parameter.
+ *      s_vGenerateTxParameter - Generate tx dma required parameter.
  *      vGenerateMACHeader - Translate 802.3 to 802.11 header
- *      cbGetFragCount - Caculate fragement number count
+ *      cbGetFragCount - Caculate fragment number count
  *      csBeacon_xmit - beacon tx function
  *      csMgmt_xmit - management tx function
  *      s_cbFillTxBufHead - fulfill tx dma buffer header
  *      s_uGetDataDuration - get tx data required duration
  *      s_uFillDataHead- fulfill tx data duration header
- *      s_uGetRTSCTSDuration- get rtx/cts requried duration
+ *      s_uGetRTSCTSDuration- get rtx/cts required duration
  *      s_uGetRTSCTSRsvTime- get rts/cts reserved time
  *      s_uGetTxRsvTime- get frame reserved time
  *      s_vFillCTSHead- fulfill CTS ctl header
- *      s_vFillFragParameter- Set fragement ctl parameter.
+ *      s_vFillFragParameter- Set fragment ctl parameter.
  *      s_vFillRTSHead- fulfill RTS ctl header
  *      s_vFillTxKey- fulfill tx encrypt key
  *      s_vSWencryption- Software encrypt header
@@ -877,7 +877,7 @@ s_vFillRTSHead (
     }
 
     // Note: So far RTSHead dosen't appear in ATIM & Beacom DMA, so we don't need to take them into account.
-    //       Otherwise, we need to modified codes for them.
+    //       Otherwise, we need to modify codes for them.
     if (byPktType == PK_TYPE_11GB || byPktType == PK_TYPE_11GA) {
         if (byFBOption == AUTO_FB_NONE) {
             PSRTS_g pBuf = (PSRTS_g)pvRTS;
@@ -1133,7 +1133,7 @@ s_vFillCTSHead (
  *
  * Parameters:
  *  In:
- *      pDevice         - Pointer to adpater
+ *      pDevice         - Pointer to adapter
  *      pTxDataHead     - Transmit Data Buffer
  *      pTxBufHead      - pTxBufHead
  *      pvRrvTime        - pvRrvTime
@@ -2252,7 +2252,7 @@ vGenerateFIFOHeader (
  *
  * Parameters:
  *  In:
- *      pDevice         - Pointer to adpater
+ *      pDevice         - Pointer to adapter
  *      dwTxBufferAddr  - Transmit Buffer
  *      pPacket         - Packet from upper layer
  *      cbPacketSize    - Transmit Data Length
index d9fa36c..a2ce6fa 100644 (file)
  * Date: May 20, 2003
  *
  * Functions:
- *      s_vGenerateTxParameter - Generate tx dma requried parameter.
+ *      s_vGenerateTxParameter - Generate tx dma required parameter.
  *      s_vGenerateMACHeader - Translate 802.3 to 802.11 header
  *      csBeacon_xmit - beacon tx function
  *      csMgmt_xmit - management tx function
  *      s_uGetDataDuration - get tx data required duration
  *      s_uFillDataHead- fulfill tx data duration header
- *      s_uGetRTSCTSDuration- get rtx/cts requried duration
+ *      s_uGetRTSCTSDuration- get rtx/cts required duration
  *      s_uGetRTSCTSRsvTime- get rts/cts reserved time
  *      s_uGetTxRsvTime- get frame reserved time
  *      s_vFillCTSHead- fulfill CTS ctl header
- *      s_vFillFragParameter- Set fragement ctl parameter.
+ *      s_vFillFragParameter- Set fragment ctl parameter.
  *      s_vFillRTSHead- fulfill RTS ctl header
  *      s_vFillTxKey- fulfill tx encrypt key
  *      s_vSWencryption- Software encrypt header
index 04f691d..37fa855 100644 (file)
@@ -3850,12 +3850,8 @@ wv_pcmcia_config(struct pcmcia_device *  link)
       if (i != 0)
          break;
 
-      /*
-       * Now allocate an interrupt line.  Note that this does not
-       * actually assign a handler to the interrupt.
-       */
-      i = pcmcia_request_irq(link, &link->irq);
-      if (i != 0)
+      i = pcmcia_request_interrupt(link, wavelan_interrupt);
+      if (!i)
          break;
 
       /*
@@ -3890,7 +3886,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
          break;
 
       /* Feed device with this info... */
-      dev->irq = link->irq.AssignedIRQ;
+      dev->irq = link->irq;
       dev->base_addr = link->io.BasePort1;
       netif_start_queue(dev);
 
@@ -4437,10 +4433,6 @@ wavelan_probe(struct pcmcia_device *p_dev)
   p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
   p_dev->io.IOAddrLines = 3;
 
-  /* Interrupt setup */
-  p_dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
-  p_dev->irq.Handler = wavelan_interrupt;
-
   /* General socket configuration */
   p_dev->conf.Attributes = CONF_ENABLE_IRQ;
   p_dev->conf.IntType = INT_MEMORY_AND_IO;
@@ -4487,7 +4479,6 @@ wavelan_probe(struct pcmcia_device *p_dev)
 
   ret = wv_hw_config(dev);
   if (ret) {
-         dev->irq = 0;
          pcmcia_disable_device(p_dev);
          return ret;
   }
index 9da42e6..c9d99d8 100644 (file)
@@ -156,15 +156,12 @@ static int wl_adapter_attach(struct pcmcia_device *link)
     link->io.NumPorts1      = HCF_NUM_IO_PORTS;
     link->io.Attributes1    = IO_DATA_PATH_WIDTH_16;
     link->io.IOAddrLines    = 6;
-    link->irq.Attributes    = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
-    link->irq.IRQInfo1      = IRQ_INFO2_VALID | IRQ_LEVEL_ID;
-    link->irq.Handler       = &wl_isr;
     link->conf.Attributes   = CONF_ENABLE_IRQ;
     link->conf.IntType      = INT_MEMORY_AND_IO;
     link->conf.ConfigIndex  = 5;
     link->conf.Present      = PRESENT_OPTION;
 
-    link->priv = link->irq.Instance = dev;
+    link->priv = dev;
     lp = wl_priv(dev);
     lp->link = link;
 
@@ -318,11 +315,11 @@ void wl_adapter_insert( struct pcmcia_device *link )
     link->conf.Attributes |= CONF_ENABLE_IRQ;
 
     CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
-    CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
+    CS_CHECK(RequestIRQ, pcmcia_request_irq(link, wl_isr));
     CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
 
 
-    dev->irq        = link->irq.AssignedIRQ;
+    dev->irq        = link->irq;
     dev->base_addr  = link->io.BasePort1;
 
     SET_NETDEV_DEV(dev, &handle_to_dev(link));
index d442fd3..99cb224 100644 (file)
@@ -22,7 +22,6 @@
 
 typedef struct ixj_info_t {
        int ndev;
-       dev_node_t node;
        struct ixj *port;
 } ixj_info_t;
 
@@ -155,8 +154,6 @@ static int ixj_config(struct pcmcia_device * link)
        j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
 
        info->ndev = 1;
-       info->node.major = PHONE_MAJOR;
-       link->dev_node = &info->node;
        ixj_get_serial(link, j);
        return 0;
 
index df1bae9..eaa79c8 100644 (file)
@@ -366,6 +366,13 @@ rescan:
        if (is_done)
                done(ep, req, 0);
        else if (ep->is_pingpong) {
+               /*
+                * One dummy read to delay the code because of a HW glitch:
+                * CSR returns bad RXCOUNT when read too soon after updating
+                * RX_DATA_BK flags.
+                */
+               csr = __raw_readl(creg);
+
                bufferspace -= count;
                buf += count;
                goto rescan;
index 40a8583..0cd6c77 100644 (file)
@@ -181,7 +181,7 @@ struct ehci_hcd_omap {
        void __iomem            *ehci_base;
 
        /* Regulators for USB PHYs.
-        * Each PHY can have a seperate regulator.
+        * Each PHY can have a separate regulator.
         */
        struct regulator        *regulator[OMAP3_HS_USB_PORTS];
 };
index 39d253e..58cb73c 100644 (file)
@@ -47,7 +47,6 @@ static const char driver_name[DEV_NAME_LEN]  = "sl811_cs";
 
 typedef struct local_info_t {
        struct pcmcia_device    *p_dev;
-       dev_node_t              node;
 } local_info_t;
 
 static void sl811_cs_release(struct pcmcia_device * link);
@@ -163,8 +162,7 @@ static int sl811_cs_config_check(struct pcmcia_device *p_dev,
                        dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
 
        /* we need an interrupt */
-       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
-               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
        /* IO window settings */
        p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
@@ -186,7 +184,6 @@ static int sl811_cs_config_check(struct pcmcia_device *p_dev,
 static int sl811_cs_config(struct pcmcia_device *link)
 {
        struct device           *parent = &link->dev;
-       local_info_t            *dev = link->priv;
        int                     ret;
 
        dev_dbg(&link->dev, "sl811_cs_config\n");
@@ -197,31 +194,24 @@ static int sl811_cs_config(struct pcmcia_device *link)
        /* require an IRQ and two registers */
        if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
                goto failed;
-       if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               ret = pcmcia_request_irq(link, &link->irq);
-               if (ret)
-                       goto failed;
-       } else
+
+       if (!link->irq)
                goto failed;
 
        ret = pcmcia_request_configuration(link, &link->conf);
        if (ret)
                goto failed;
 
-       sprintf(dev->node.dev_name, driver_name);
-       dev->node.major = dev->node.minor = 0;
-       link->dev_node = &dev->node;
-
-       printk(KERN_INFO "%s: index 0x%02x: ",
-              dev->node.dev_name, link->conf.ConfigIndex);
+       dev_info(&link->dev, "index 0x%02x: ",
+               link->conf.ConfigIndex);
        if (link->conf.Vpp)
                printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
-       printk(", irq %d", link->irq.AssignedIRQ);
+       printk(", irq %d", link->irq);
        printk(", io 0x%04x-0x%04x", link->io.BasePort1,
               link->io.BasePort1+link->io.NumPorts1-1);
        printk("\n");
 
-       if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
+       if (sl811_hc_init(parent, link->io.BasePort1, link->irq)
                        < 0) {
 failed:
                printk(KERN_WARNING "sl811_cs_config failed\n");
@@ -241,10 +231,6 @@ static int sl811_cs_probe(struct pcmcia_device *link)
        local->p_dev = link;
        link->priv = local;
 
-       /* Initialize */
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-       link->irq.Handler = NULL;
-
        link->conf.Attributes = 0;
        link->conf.IntType = INT_MEMORY_AND_IO;
 
index 112ef7e..608d61a 100644 (file)
@@ -76,7 +76,7 @@
  *     xfers-per-ripe, blocks-per-rpipe, rpipes-per-host), at the end
  *     we are going to have to rebuild all this based on an scheduler,
  *     to where we have a list of transactions to do and based on the
- *     availability of the different requried components (blocks,
+ *     availability of the different required components (blocks,
  *     rpipes, segment slots, etc), we go scheduling them. Painful.
  */
 #include <linux/init.h>
index dca48df..e5d6b56 100644 (file)
@@ -50,8 +50,9 @@
 #include <linux/fb.h>
 #include <linux/init.h>
 #include <linux/ioport.h>
-
+#include <linux/platform_device.h>
 #include <linux/uaccess.h>
+
 #include <asm/system.h>
 #include <asm/irq.h>
 #include <asm/amigahw.h>
@@ -1135,7 +1136,7 @@ static int amifb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg
         * Interface to the low level console driver
         */
 
-static void amifb_deinit(void);
+static void amifb_deinit(struct platform_device *pdev);
 
        /*
         * Internal routines
@@ -2246,7 +2247,7 @@ static inline void chipfree(void)
         * Initialisation
         */
 
-static int __init amifb_init(void)
+static int __init amifb_probe(struct platform_device *pdev)
 {
        int tag, i, err = 0;
        u_long chipptr;
@@ -2261,16 +2262,6 @@ static int __init amifb_init(void)
        }
        amifb_setup(option);
 #endif
-       if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_VIDEO))
-               return -ENODEV;
-
-       /*
-        * We request all registers starting from bplpt[0]
-        */
-       if (!request_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120,
-                               "amifb [Denise/Lisa]"))
-               return -EBUSY;
-
        custom.dmacon = DMAF_ALL | DMAF_MASTER;
 
        switch (amiga_chipset) {
@@ -2377,6 +2368,7 @@ default_chipset:
        fb_info.fbops = &amifb_ops;
        fb_info.par = &currentpar;
        fb_info.flags = FBINFO_DEFAULT;
+       fb_info.device = &pdev->dev;
 
        if (!fb_find_mode(&fb_info.var, &fb_info, mode_option, ami_modedb,
                          NUM_TOTAL_MODES, &ami_modedb[defmode], 4)) {
@@ -2451,18 +2443,18 @@ default_chipset:
        return 0;
 
 amifb_error:
-       amifb_deinit();
+       amifb_deinit(pdev);
        return err;
 }
 
-static void amifb_deinit(void)
+static void amifb_deinit(struct platform_device *pdev)
 {
        if (fb_info.cmap.len)
                fb_dealloc_cmap(&fb_info.cmap);
+       fb_dealloc_cmap(&fb_info.cmap);
        chipfree();
        if (videomemory)
                iounmap((void*)videomemory);
-       release_mem_region(CUSTOM_PHYSADDR+0xe0, 0x120);
        custom.dmacon = DMAF_ALL | DMAF_MASTER;
 }
 
@@ -3794,14 +3786,35 @@ static void ami_rebuild_copper(void)
        }
 }
 
-static void __exit amifb_exit(void)
+static int __exit amifb_remove(struct platform_device *pdev)
 {
        unregister_framebuffer(&fb_info);
-       amifb_deinit();
+       amifb_deinit(pdev);
        amifb_video_off();
+       return 0;
+}
+
+static struct platform_driver amifb_driver = {
+       .remove = __exit_p(amifb_remove),
+       .driver   = {
+               .name   = "amiga-video",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init amifb_init(void)
+{
+       return platform_driver_probe(&amifb_driver, amifb_probe);
 }
 
 module_init(amifb_init);
+
+static void __exit amifb_exit(void)
+{
+       platform_driver_unregister(&amifb_driver);
+}
+
 module_exit(amifb_exit);
 
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:amiga-video");
index 8d8dfda..6df7c54 100644 (file)
@@ -299,6 +299,7 @@ static const struct zorro_device_id cirrusfb_zorro_table[] = {
        },
        { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, cirrusfb_zorro_table);
 
 static const struct {
        zorro_id id2;
index 5eb61b5..42fe155 100644 (file)
@@ -123,7 +123,7 @@ static void lcd_clear(struct fb_info *info)
        lcd_write_control(info, LCD_RESET);
 }
 
-static struct fb_fix_screeninfo cobalt_lcdfb_fix __initdata = {
+static struct fb_fix_screeninfo cobalt_lcdfb_fix __devinitdata = {
        .id             = "cobalt-lcd",
        .type           = FB_TYPE_TEXT,
        .type_aux       = FB_AUX_TEXT_MDA,
index 6c91c61..1b0feb8 100644 (file)
@@ -219,6 +219,7 @@ static struct zorro_device_id fm2fb_devices[] __devinitdata = {
        { ZORRO_PROD_HELFRICH_RAINBOW_II },
        { 0 }
 };
+MODULE_DEVICE_TABLE(zorro, fm2fb_devices);
 
 static struct zorro_driver fm2fb_driver = {
        .name           = "fm2fb",
index 24747ae..95896f3 100644 (file)
@@ -655,7 +655,7 @@ static int __devinit virtio_pci_probe(struct pci_dev *pci_dev,
        /* we use the subsystem vendor/device id as the virtio vendor/device
         * id.  this allows us to use the same PCI vendor/device id for all
         * virtio devices and to identify the particular virtio driver by
-        * the subsytem ids */
+        * the subsystem ids */
        vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor;
        vp_dev->vdev.id.device = pci_dev->subsystem_device;
 
index a9efb16..d874b4f 100644 (file)
@@ -1,8 +1,8 @@
 menu "TI VLYNQ"
+       depends on AR7 && EXPERIMENTAL
 
 config VLYNQ
        bool "TI VLYNQ bus support"
-       depends on AR7 && EXPERIMENTAL
        help
          Support for Texas Instruments(R) VLYNQ bus.
          The VLYNQ bus is a high-speed, serial and packetized
index 2ac4440..8943b8c 100644 (file)
@@ -80,12 +80,6 @@ static void do_suspend(void)
 
        shutting_down = SHUTDOWN_SUSPEND;
 
-       err = stop_machine_create();
-       if (err) {
-               printk(KERN_ERR "xen suspend: failed to setup stop_machine %d\n", err);
-               goto out;
-       }
-
 #ifdef CONFIG_PREEMPT
        /* If the kernel is preemptible, we need to freeze all the processes
           to prevent them from being in the middle of a pagetable update
@@ -93,7 +87,7 @@ static void do_suspend(void)
        err = freeze_processes();
        if (err) {
                printk(KERN_ERR "xen suspend: freeze failed %d\n", err);
-               goto out_destroy_sm;
+               goto out;
        }
 #endif
 
@@ -136,12 +130,8 @@ out_resume:
 out_thaw:
 #ifdef CONFIG_PREEMPT
        thaw_processes();
-
-out_destroy_sm:
-#endif
-       stop_machine_destroy();
-
 out:
+#endif
        shutting_down = SHUTDOWN_INVALID;
 }
 #endif /* CONFIG_PM_SLEEP */
index d47c47f..3c7046d 100644 (file)
@@ -97,7 +97,7 @@ static void zorro_seq_stop(struct seq_file *m, void *v)
 
 static int zorro_seq_show(struct seq_file *m, void *v)
 {
-       u_int slot = *(loff_t *)v;
+       unsigned int slot = *(loff_t *)v;
        struct zorro_dev *z = &zorro_autocon[slot];
 
        seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
@@ -129,7 +129,7 @@ static const struct file_operations zorro_devices_proc_fops = {
 
 static struct proc_dir_entry *proc_bus_zorro_dir;
 
-static int __init zorro_proc_attach_device(u_int slot)
+static int __init zorro_proc_attach_device(unsigned int slot)
 {
        struct proc_dir_entry *entry;
        char name[4];
@@ -146,7 +146,7 @@ static int __init zorro_proc_attach_device(u_int slot)
 
 static int __init zorro_proc_init(void)
 {
-       u_int slot;
+       unsigned int slot;
 
        if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
                proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
index 53180a3..7ee2b6e 100644 (file)
@@ -137,10 +137,34 @@ static int zorro_bus_match(struct device *dev, struct device_driver *drv)
        return 0;
 }
 
+static int zorro_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+#ifdef CONFIG_HOTPLUG
+       struct zorro_dev *z;
+
+       if (!dev)
+               return -ENODEV;
+
+       z = to_zorro_dev(dev);
+       if (!z)
+               return -ENODEV;
+
+       if (add_uevent_var(env, "ZORRO_ID=%08X", z->id) ||
+           add_uevent_var(env, "ZORRO_SLOT_NAME=%s", dev_name(dev)) ||
+           add_uevent_var(env, "ZORRO_SLOT_ADDR=%04X", z->slotaddr) ||
+           add_uevent_var(env, "MODALIAS=" ZORRO_DEVICE_MODALIAS_FMT, z->id))
+               return -ENOMEM;
+
+       return 0;
+#else /* !CONFIG_HOTPLUG */
+       return -ENODEV;
+#endif /* !CONFIG_HOTPLUG */
+}
 
 struct bus_type zorro_bus_type = {
        .name   = "zorro",
        .match  = zorro_bus_match,
+       .uevent = zorro_uevent,
        .probe  = zorro_device_probe,
        .remove = zorro_device_remove,
 };
index 1d2a772..eb924e0 100644 (file)
@@ -77,6 +77,16 @@ static struct bin_attribute zorro_config_attr = {
        .read = zorro_read_config,
 };
 
+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
+                            char *buf)
+{
+       struct zorro_dev *z = to_zorro_dev(dev);
+
+       return sprintf(buf, ZORRO_DEVICE_MODALIAS_FMT "\n", z->id);
+}
+
+static DEVICE_ATTR(modalias, S_IRUGO, modalias_show, NULL);
+
 int zorro_create_sysfs_dev_files(struct zorro_dev *z)
 {
        struct device *dev = &z->dev;
@@ -89,6 +99,7 @@ int zorro_create_sysfs_dev_files(struct zorro_dev *z)
            (error = device_create_file(dev, &dev_attr_slotaddr)) ||
            (error = device_create_file(dev, &dev_attr_slotsize)) ||
            (error = device_create_file(dev, &dev_attr_resource)) ||
+           (error = device_create_file(dev, &dev_attr_modalias)) ||
            (error = sysfs_create_bin_file(&dev->kobj, &zorro_config_attr)))
                return error;
 
index d45fb34..6455f3a 100644 (file)
@@ -15,6 +15,8 @@
 #include <linux/zorro.h>
 #include <linux/bitops.h>
 #include <linux/string.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
 
 #include <asm/setup.h>
 #include <asm/amigahw.h>
      *  Zorro Expansion Devices
      */
 
-u_int zorro_num_autocon = 0;
+unsigned int zorro_num_autocon;
 struct zorro_dev zorro_autocon[ZORRO_NUM_AUTO];
 
 
     /*
-     *  Single Zorro bus
+     *  Zorro bus
      */
 
-struct zorro_bus zorro_bus = {\
-    .resources = {
-       /* Zorro II regions (on Zorro II/III) */
-       { .name = "Zorro II exp", .start = 0x00e80000, .end = 0x00efffff },
-       { .name = "Zorro II mem", .start = 0x00200000, .end = 0x009fffff },
-       /* Zorro III regions (on Zorro III only) */
-       { .name = "Zorro III exp", .start = 0xff000000, .end = 0xffffffff },
-       { .name = "Zorro III cfg", .start = 0x40000000, .end = 0x7fffffff }
-    },
-    .name = "Zorro bus"
+struct zorro_bus {
+       struct list_head devices;       /* list of devices on this bus */
+       struct device dev;
 };
 
 
@@ -53,18 +48,19 @@ struct zorro_bus zorro_bus = {\
 
 struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
 {
-    struct zorro_dev *z;
+       struct zorro_dev *z;
 
-    if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
-       return NULL;
+       if (!zorro_num_autocon)
+               return NULL;
 
-    for (z = from ? from+1 : &zorro_autocon[0];
-        z < zorro_autocon+zorro_num_autocon;
-        z++)
-       if (id == ZORRO_WILDCARD || id == z->id)
-           return z;
-    return NULL;
+       for (z = from ? from+1 : &zorro_autocon[0];
+            z < zorro_autocon+zorro_num_autocon;
+            z++)
+               if (id == ZORRO_WILDCARD || id == z->id)
+                       return z;
+       return NULL;
 }
+EXPORT_SYMBOL(zorro_find_device);
 
 
     /*
@@ -83,121 +79,138 @@ struct zorro_dev *zorro_find_device(zorro_id id, struct zorro_dev *from)
      */
 
 DECLARE_BITMAP(zorro_unused_z2ram, 128);
+EXPORT_SYMBOL(zorro_unused_z2ram);
 
 
 static void __init mark_region(unsigned long start, unsigned long end,
                               int flag)
 {
-    if (flag)
-       start += Z2RAM_CHUNKMASK;
-    else
-       end += Z2RAM_CHUNKMASK;
-    start &= ~Z2RAM_CHUNKMASK;
-    end &= ~Z2RAM_CHUNKMASK;
-
-    if (end <= Z2RAM_START || start >= Z2RAM_END)
-       return;
-    start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
-    end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
-    while (start < end) {
-       u32 chunk = start>>Z2RAM_CHUNKSHIFT;
        if (flag)
-           set_bit(chunk, zorro_unused_z2ram);
+               start += Z2RAM_CHUNKMASK;
        else
-           clear_bit(chunk, zorro_unused_z2ram);
-       start += Z2RAM_CHUNKSIZE;
-    }
+               end += Z2RAM_CHUNKMASK;
+       start &= ~Z2RAM_CHUNKMASK;
+       end &= ~Z2RAM_CHUNKMASK;
+
+       if (end <= Z2RAM_START || start >= Z2RAM_END)
+               return;
+       start = start < Z2RAM_START ? 0x00000000 : start-Z2RAM_START;
+       end = end > Z2RAM_END ? Z2RAM_SIZE : end-Z2RAM_START;
+       while (start < end) {
+               u32 chunk = start>>Z2RAM_CHUNKSHIFT;
+               if (flag)
+                       set_bit(chunk, zorro_unused_z2ram);
+               else
+                       clear_bit(chunk, zorro_unused_z2ram);
+               start += Z2RAM_CHUNKSIZE;
+       }
 }
 
 
-static struct resource __init *zorro_find_parent_resource(struct zorro_dev *z)
+static struct resource __init *zorro_find_parent_resource(
+       struct platform_device *bridge, struct zorro_dev *z)
 {
-    int i;
+       int i;
 
-    for (i = 0; i < zorro_bus.num_resources; i++)
-       if (zorro_resource_start(z) >= zorro_bus.resources[i].start &&
-           zorro_resource_end(z) <= zorro_bus.resources[i].end)
-               return &zorro_bus.resources[i];
-    return &iomem_resource;
+       for (i = 0; i < bridge->num_resources; i++) {
+               struct resource *r = &bridge->resource[i];
+               if (zorro_resource_start(z) >= r->start &&
+                   zorro_resource_end(z) <= r->end)
+                       return r;
+       }
+       return &iomem_resource;
 }
 
 
-    /*
-     *  Initialization
-     */
 
-static int __init zorro_init(void)
+static int __init amiga_zorro_probe(struct platform_device *pdev)
 {
-    struct zorro_dev *z;
-    unsigned int i;
-    int error;
-
-    if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(ZORRO))
-       return 0;
-
-    pr_info("Zorro: Probing AutoConfig expansion devices: %d device%s\n",
-          zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
-
-    /* Initialize the Zorro bus */
-    INIT_LIST_HEAD(&zorro_bus.devices);
-    dev_set_name(&zorro_bus.dev, "zorro");
-    error = device_register(&zorro_bus.dev);
-    if (error) {
-       pr_err("Zorro: Error registering zorro_bus\n");
-       return error;
-    }
-
-    /* Request the resources */
-    zorro_bus.num_resources = AMIGAHW_PRESENT(ZORRO3) ? 4 : 2;
-    for (i = 0; i < zorro_bus.num_resources; i++)
-       request_resource(&iomem_resource, &zorro_bus.resources[i]);
-
-    /* Register all devices */
-    for (i = 0; i < zorro_num_autocon; i++) {
-       z = &zorro_autocon[i];
-       z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
-       if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
-           /* GVP quirk */
-           unsigned long magic = zorro_resource_start(z)+0x8000;
-           z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
-       }
-       sprintf(z->name, "Zorro device %08x", z->id);
-       zorro_name_device(z);
-       z->resource.name = z->name;
-       if (request_resource(zorro_find_parent_resource(z), &z->resource))
-           pr_err("Zorro: Address space collision on device %s %pR\n",
-                  z->name, &z->resource);
-       dev_set_name(&z->dev, "%02x", i);
-       z->dev.parent = &zorro_bus.dev;
-       z->dev.bus = &zorro_bus_type;
-       error = device_register(&z->dev);
+       struct zorro_bus *bus;
+       struct zorro_dev *z;
+       struct resource *r;
+       unsigned int i;
+       int error;
+
+       /* Initialize the Zorro bus */
+       bus = kzalloc(sizeof(*bus), GFP_KERNEL);
+       if (!bus)
+               return -ENOMEM;
+
+       INIT_LIST_HEAD(&bus->devices);
+       bus->dev.parent = &pdev->dev;
+       dev_set_name(&bus->dev, "zorro");
+       error = device_register(&bus->dev);
        if (error) {
-           pr_err("Zorro: Error registering device %s\n", z->name);
-           continue;
+               pr_err("Zorro: Error registering zorro_bus\n");
+               kfree(bus);
+               return error;
        }
-       error = zorro_create_sysfs_dev_files(z);
-       if (error)
-           dev_err(&z->dev, "Error creating sysfs files\n");
-    }
-
-    /* Mark all available Zorro II memory */
-    zorro_for_each_dev(z) {
-       if (z->rom.er_Type & ERTF_MEMLIST)
-           mark_region(zorro_resource_start(z), zorro_resource_end(z)+1, 1);
-    }
-
-    /* Unmark all used Zorro II memory */
-    for (i = 0; i < m68k_num_memory; i++)
-       if (m68k_memory[i].addr < 16*1024*1024)
-           mark_region(m68k_memory[i].addr,
-                       m68k_memory[i].addr+m68k_memory[i].size, 0);
-
-    return 0;
+       platform_set_drvdata(pdev, bus);
+
+       /* Register all devices */
+       pr_info("Zorro: Probing AutoConfig expansion devices: %u device%s\n",
+                zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
+
+       for (i = 0; i < zorro_num_autocon; i++) {
+               z = &zorro_autocon[i];
+               z->id = (z->rom.er_Manufacturer<<16) | (z->rom.er_Product<<8);
+               if (z->id == ZORRO_PROD_GVP_EPC_BASE) {
+                       /* GVP quirk */
+                       unsigned long magic = zorro_resource_start(z)+0x8000;
+                       z->id |= *(u16 *)ZTWO_VADDR(magic) & GVP_PRODMASK;
+               }
+               sprintf(z->name, "Zorro device %08x", z->id);
+               zorro_name_device(z);
+               z->resource.name = z->name;
+               r = zorro_find_parent_resource(pdev, z);
+               error = request_resource(r, &z->resource);
+               if (error)
+                       dev_err(&bus->dev,
+                               "Address space collision on device %s %pR\n",
+                               z->name, &z->resource);
+               dev_set_name(&z->dev, "%02x", i);
+               z->dev.parent = &bus->dev;
+               z->dev.bus = &zorro_bus_type;
+               error = device_register(&z->dev);
+               if (error) {
+                       dev_err(&bus->dev, "Error registering device %s\n",
+                               z->name);
+                       continue;
+               }
+               error = zorro_create_sysfs_dev_files(z);
+               if (error)
+                       dev_err(&z->dev, "Error creating sysfs files\n");
+       }
+
+       /* Mark all available Zorro II memory */
+       zorro_for_each_dev(z) {
+               if (z->rom.er_Type & ERTF_MEMLIST)
+                       mark_region(zorro_resource_start(z),
+                                   zorro_resource_end(z)+1, 1);
+       }
+
+       /* Unmark all used Zorro II memory */
+       for (i = 0; i < m68k_num_memory; i++)
+               if (m68k_memory[i].addr < 16*1024*1024)
+                       mark_region(m68k_memory[i].addr,
+                                   m68k_memory[i].addr+m68k_memory[i].size,
+                                   0);
+
+       return 0;
 }
 
-subsys_initcall(zorro_init);
+static struct platform_driver amiga_zorro_driver = {
+       .driver   = {
+               .name   = "amiga-zorro",
+               .owner  = THIS_MODULE,
+       },
+};
 
-EXPORT_SYMBOL(zorro_find_device);
-EXPORT_SYMBOL(zorro_unused_z2ram);
+static int __init amiga_zorro_init(void)
+{
+       return platform_driver_probe(&amiga_zorro_driver, amiga_zorro_probe);
+}
+
+module_init(amiga_zorro_init);
 
 MODULE_LICENSE("GPL");
index a20bea5..cfd1ce3 100644 (file)
@@ -492,17 +492,13 @@ compare_oid(unsigned long *oid1, unsigned int oid1len,
 
 int
 decode_negTokenInit(unsigned char *security_blob, int length,
-                   enum securityEnum *secType)
+                   struct TCP_Server_Info *server)
 {
        struct asn1_ctx ctx;
        unsigned char *end;
        unsigned char *sequence_end;
        unsigned long *oid = NULL;
        unsigned int cls, con, tag, oidlen, rc;
-       bool use_ntlmssp = false;
-       bool use_kerberos = false;
-       bool use_kerberosu2u = false;
-       bool use_mskerberos = false;
 
        /* cifs_dump_mem(" Received SecBlob ", security_blob, length); */
 
@@ -510,11 +506,11 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 
        /* GSSAPI header */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding negTokenInit header"));
+               cFYI(1, "Error decoding negTokenInit header");
                return 0;
        } else if ((cls != ASN1_APL) || (con != ASN1_CON)
                   || (tag != ASN1_EOC)) {
-               cFYI(1, ("cls = %d con = %d tag = %d", cls, con, tag));
+               cFYI(1, "cls = %d con = %d tag = %d", cls, con, tag);
                return 0;
        }
 
@@ -535,56 +531,52 @@ decode_negTokenInit(unsigned char *security_blob, int length,
 
        /* SPNEGO OID not present or garbled -- bail out */
        if (!rc) {
-               cFYI(1, ("Error decoding negTokenInit header"));
+               cFYI(1, "Error decoding negTokenInit header");
                return 0;
        }
 
        /* SPNEGO */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding negTokenInit"));
+               cFYI(1, "Error decoding negTokenInit");
                return 0;
        } else if ((cls != ASN1_CTX) || (con != ASN1_CON)
                   || (tag != ASN1_EOC)) {
-               cFYI(1,
-                    ("cls = %d con = %d tag = %d end = %p (%d) exit 0",
-                     cls, con, tag, end, *end));
+               cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0",
+                    cls, con, tag, end, *end);
                return 0;
        }
 
        /* negTokenInit */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding negTokenInit"));
+               cFYI(1, "Error decoding negTokenInit");
                return 0;
        } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
                   || (tag != ASN1_SEQ)) {
-               cFYI(1,
-                    ("cls = %d con = %d tag = %d end = %p (%d) exit 1",
-                     cls, con, tag, end, *end));
+               cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1",
+                    cls, con, tag, end, *end);
                return 0;
        }
 
        /* sequence */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding 2nd part of negTokenInit"));
+               cFYI(1, "Error decoding 2nd part of negTokenInit");
                return 0;
        } else if ((cls != ASN1_CTX) || (con != ASN1_CON)
                   || (tag != ASN1_EOC)) {
-               cFYI(1,
-                    ("cls = %d con = %d tag = %d end = %p (%d) exit 0",
-                     cls, con, tag, end, *end));
+               cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 0",
+                    cls, con, tag, end, *end);
                return 0;
        }
 
        /* sequence of */
        if (asn1_header_decode
            (&ctx, &sequence_end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding 2nd part of negTokenInit"));
+               cFYI(1, "Error decoding 2nd part of negTokenInit");
                return 0;
        } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
                   || (tag != ASN1_SEQ)) {
-               cFYI(1,
-                    ("cls = %d con = %d tag = %d end = %p (%d) exit 1",
-                     cls, con, tag, end, *end));
+               cFYI(1, "cls = %d con = %d tag = %d end = %p (%d) exit 1",
+                    cls, con, tag, end, *end);
                return 0;
        }
 
@@ -592,37 +584,33 @@ decode_negTokenInit(unsigned char *security_blob, int length,
        while (!asn1_eoc_decode(&ctx, sequence_end)) {
                rc = asn1_header_decode(&ctx, &end, &cls, &con, &tag);
                if (!rc) {
-                       cFYI(1,
-                            ("Error decoding negTokenInit hdr exit2"));
+                       cFYI(1, "Error decoding negTokenInit hdr exit2");
                        return 0;
                }
                if ((tag == ASN1_OJI) && (con == ASN1_PRI)) {
                        if (asn1_oid_decode(&ctx, end, &oid, &oidlen)) {
 
-                               cFYI(1, ("OID len = %d oid = 0x%lx 0x%lx "
-                                        "0x%lx 0x%lx", oidlen, *oid,
-                                        *(oid + 1), *(oid + 2), *(oid + 3)));
+                               cFYI(1, "OID len = %d oid = 0x%lx 0x%lx "
+                                       "0x%lx 0x%lx", oidlen, *oid,
+                                       *(oid + 1), *(oid + 2), *(oid + 3));
 
                                if (compare_oid(oid, oidlen, MSKRB5_OID,
-                                               MSKRB5_OID_LEN) &&
-                                               !use_mskerberos)
-                                       use_mskerberos = true;
+                                               MSKRB5_OID_LEN))
+                                       server->sec_mskerberos = true;
                                else if (compare_oid(oid, oidlen, KRB5U2U_OID,
-                                                    KRB5U2U_OID_LEN) &&
-                                                    !use_kerberosu2u)
-                                       use_kerberosu2u = true;
+                                                    KRB5U2U_OID_LEN))
+                                       server->sec_kerberosu2u = true;
                                else if (compare_oid(oid, oidlen, KRB5_OID,
-                                                    KRB5_OID_LEN) &&
-                                                    !use_kerberos)
-                                       use_kerberos = true;
+                                                    KRB5_OID_LEN))
+                                       server->sec_kerberos = true;
                                else if (compare_oid(oid, oidlen, NTLMSSP_OID,
                                                     NTLMSSP_OID_LEN))
-                                       use_ntlmssp = true;
+                                       server->sec_ntlmssp = true;
 
                                kfree(oid);
                        }
                } else {
-                       cFYI(1, ("Should be an oid what is going on?"));
+                       cFYI(1, "Should be an oid what is going on?");
                }
        }
 
@@ -632,54 +620,47 @@ decode_negTokenInit(unsigned char *security_blob, int length,
                   no mechListMic (e.g. NTLMSSP instead of KRB5) */
                if (ctx.error == ASN1_ERR_DEC_EMPTY)
                        goto decode_negtoken_exit;
-               cFYI(1, ("Error decoding last part negTokenInit exit3"));
+               cFYI(1, "Error decoding last part negTokenInit exit3");
                return 0;
        } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
                /* tag = 3 indicating mechListMIC */
-               cFYI(1, ("Exit 4 cls = %d con = %d tag = %d end = %p (%d)",
-                        cls, con, tag, end, *end));
+               cFYI(1, "Exit 4 cls = %d con = %d tag = %d end = %p (%d)",
+                       cls, con, tag, end, *end);
                return 0;
        }
 
        /* sequence */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding last part negTokenInit exit5"));
+               cFYI(1, "Error decoding last part negTokenInit exit5");
                return 0;
        } else if ((cls != ASN1_UNI) || (con != ASN1_CON)
                   || (tag != ASN1_SEQ)) {
-               cFYI(1, ("cls = %d con = %d tag = %d end = %p (%d)",
-                       cls, con, tag, end, *end));
+               cFYI(1, "cls = %d con = %d tag = %d end = %p (%d)",
+                       cls, con, tag, end, *end);
        }
 
        /* sequence of */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding last part negTokenInit exit 7"));
+               cFYI(1, "Error decoding last part negTokenInit exit 7");
                return 0;
        } else if ((cls != ASN1_CTX) || (con != ASN1_CON)) {
-               cFYI(1, ("Exit 8 cls = %d con = %d tag = %d end = %p (%d)",
-                        cls, con, tag, end, *end));
+               cFYI(1, "Exit 8 cls = %d con = %d tag = %d end = %p (%d)",
+                       cls, con, tag, end, *end);
                return 0;
        }
 
        /* general string */
        if (asn1_header_decode(&ctx, &end, &cls, &con, &tag) == 0) {
-               cFYI(1, ("Error decoding last part negTokenInit exit9"));
+               cFYI(1, "Error decoding last part negTokenInit exit9");
                return 0;
        } else if ((cls != ASN1_UNI) || (con != ASN1_PRI)
                   || (tag != ASN1_GENSTR)) {
-               cFYI(1, ("Exit10 cls = %d con = %d tag = %d end = %p (%d)",
-                        cls, con, tag, end, *end));
+               cFYI(1, "Exit10 cls = %d con = %d tag = %d end = %p (%d)",
+                       cls, con, tag, end, *end);
                return 0;
        }
-       cFYI(1, ("Need to call asn1_octets_decode() function for %s",
-                ctx.pointer)); /* is this UTF-8 or ASCII? */
+       cFYI(1, "Need to call asn1_octets_decode() function for %s",
+               ctx.pointer);   /* is this UTF-8 or ASCII? */
 decode_negtoken_exit:
-       if (use_kerberos)
-               *secType = Kerberos;
-       else if (use_mskerberos)
-               *secType = MSKerberos;
-       else if (use_ntlmssp)
-               *secType = RawNTLMSSP;
-
        return 1;
 }
index 42cec2a..4fce6e6 100644 (file)
@@ -60,10 +60,10 @@ cifs_dump_mem(char *label, void *data, int length)
 #ifdef CONFIG_CIFS_DEBUG2
 void cifs_dump_detail(struct smb_hdr *smb)
 {
-       cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
+       cERROR(1, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
                  smb->Command, smb->Status.CifsError,
-                 smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
-       cERROR(1, ("smb buf %p len %d", smb, smbCalcSize_LE(smb)));
+                 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
+       cERROR(1, "smb buf %p len %d", smb, smbCalcSize_LE(smb));
 }
 
 
@@ -75,25 +75,25 @@ void cifs_dump_mids(struct TCP_Server_Info *server)
        if (server == NULL)
                return;
 
-       cERROR(1, ("Dump pending requests:"));
+       cERROR(1, "Dump pending requests:");
        spin_lock(&GlobalMid_Lock);
        list_for_each(tmp, &server->pending_mid_q) {
                mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
-               cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
+               cERROR(1, "State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
                        mid_entry->midState,
                        (int)mid_entry->command,
                        mid_entry->pid,
                        mid_entry->tsk,
-                       mid_entry->mid));
+                       mid_entry->mid);
 #ifdef CONFIG_CIFS_STATS2
-               cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
+               cERROR(1, "IsLarge: %d buf: %p time rcv: %ld now: %ld",
                        mid_entry->largeBuf,
                        mid_entry->resp_buf,
                        mid_entry->when_received,
-                       jiffies));
+                       jiffies);
 #endif /* STATS2 */
-               cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
-                         mid_entry->multiEnd));
+               cERROR(1, "IsMult: %d IsEnd: %d", mid_entry->multiRsp,
+                         mid_entry->multiEnd);
                if (mid_entry->resp_buf) {
                        cifs_dump_detail(mid_entry->resp_buf);
                        cifs_dump_mem("existing buf: ",
@@ -716,7 +716,7 @@ static const struct file_operations cifs_multiuser_mount_proc_fops = {
 
 static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
 {
-       seq_printf(m, "0x%x\n", extended_security);
+       seq_printf(m, "0x%x\n", global_secflags);
        return 0;
 }
 
@@ -744,13 +744,13 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
                /* single char or single char followed by null */
                c = flags_string[0];
                if (c == '0' || c == 'n' || c == 'N') {
-                       extended_security = CIFSSEC_DEF; /* default */
+                       global_secflags = CIFSSEC_DEF; /* default */
                        return count;
                } else if (c == '1' || c == 'y' || c == 'Y') {
-                       extended_security = CIFSSEC_MAX;
+                       global_secflags = CIFSSEC_MAX;
                        return count;
                } else if (!isdigit(c)) {
-                       cERROR(1, ("invalid flag %c", c));
+                       cERROR(1, "invalid flag %c", c);
                        return -EINVAL;
                }
        }
@@ -758,26 +758,26 @@ static ssize_t cifs_security_flags_proc_write(struct file *file,
 
        flags = simple_strtoul(flags_string, NULL, 0);
 
-       cFYI(1, ("sec flags 0x%x", flags));
+       cFYI(1, "sec flags 0x%x", flags);
 
        if (flags <= 0)  {
-               cERROR(1, ("invalid security flags %s", flags_string));
+               cERROR(1, "invalid security flags %s", flags_string);
                return -EINVAL;
        }
 
        if (flags & ~CIFSSEC_MASK) {
-               cERROR(1, ("attempt to set unsupported security flags 0x%x",
-                       flags & ~CIFSSEC_MASK));
+               cERROR(1, "attempt to set unsupported security flags 0x%x",
+                       flags & ~CIFSSEC_MASK);
                return -EINVAL;
        }
        /* flags look ok - update the global security flags for cifs module */
-       extended_security = flags;
-       if (extended_security & CIFSSEC_MUST_SIGN) {
+       global_secflags = flags;
+       if (global_secflags & CIFSSEC_MUST_SIGN) {
                /* requiring signing implies signing is allowed */
-               extended_security |= CIFSSEC_MAY_SIGN;
-               cFYI(1, ("packet signing now required"));
-       } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
-               cFYI(1, ("packet signing disabled"));
+               global_secflags |= CIFSSEC_MAY_SIGN;
+               cFYI(1, "packet signing now required");
+       } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
+               cFYI(1, "packet signing disabled");
        }
        /* BB should we turn on MAY flags for other MUST options? */
        return count;
index 5eb3b83..aa31689 100644 (file)
@@ -43,34 +43,54 @@ void dump_smb(struct smb_hdr *, int);
  */
 #ifdef CIFS_DEBUG
 
-
 /* information message: e.g., configuration, major event */
 extern int cifsFYI;
-#define cifsfyi(format,arg...) if (cifsFYI & CIFS_INFO) printk(KERN_DEBUG " " __FILE__ ": " format "\n" "" , ## arg)
+#define cifsfyi(fmt, arg...)                                           \
+do {                                                                   \
+       if (cifsFYI & CIFS_INFO)                                        \
+               printk(KERN_DEBUG "%s: " fmt "\n", __FILE__, ##arg);    \
+} while (0)
 
-#define cFYI(button,prspec) if (button) cifsfyi prspec
+#define cFYI(set, fmt, arg...)                 \
+do {                                           \
+       if (set)                                \
+               cifsfyi(fmt, ##arg);            \
+} while (0)
 
-#define cifswarn(format, arg...) printk(KERN_WARNING ": " format "\n" , ## arg)
+#define cifswarn(fmt, arg...)                  \
+       printk(KERN_WARNING fmt "\n", ##arg)
 
 /* debug event message: */
 extern int cifsERROR;
 
-#define cEVENT(format,arg...) if (cifsERROR) printk(KERN_EVENT __FILE__ ": " format "\n" , ## arg)
+#define cEVENT(fmt, arg...)                                            \
+do {                                                                   \
+       if (cifsERROR)                                                  \
+               printk(KERN_EVENT "%s: " fmt "\n", __FILE__, ##arg);    \
+} while (0)
 
 /* error event message: e.g., i/o error */
-#define cifserror(format,arg...) if (cifsERROR) printk(KERN_ERR " CIFS VFS: " format "\n" "" , ## arg)
+#define cifserror(fmt, arg...)                                 \
+do {                                                           \
+       if (cifsERROR)                                          \
+               printk(KERN_ERR "CIFS VFS: " fmt "\n", ##arg);  \
+} while (0)
 
-#define cERROR(button, prspec) if (button) cifserror prspec
+#define cERROR(set, fmt, arg...)               \
+do {                                           \
+       if (set)                                \
+               cifserror(fmt, ##arg);          \
+} while (0)
 
 /*
  *     debug OFF
  *     ---------
  */
 #else          /* _CIFS_DEBUG */
-#define cERROR(button, prspec)
-#define cEVENT(format, arg...)
-#define cFYI(button, prspec)
-#define cifserror(format, arg...)
+#define cERROR(set, fmt, arg...)
+#define cEVENT(fmt, arg...)
+#define cFYI(set, fmt, arg...)
+#define cifserror(fmt, arg...)
 #endif         /* _CIFS_DEBUG */
 
 #endif                         /* _H_CIFS_DEBUG */
index 78e4d2a..ac19a6f 100644 (file)
@@ -85,8 +85,8 @@ static char *cifs_get_share_name(const char *node_name)
        /* find server name end */
        pSep = memchr(UNC+2, '\\', len-2);
        if (!pSep) {
-               cERROR(1, ("%s: no server name end in node name: %s",
-                       __func__, node_name));
+               cERROR(1, "%s: no server name end in node name: %s",
+                       __func__, node_name);
                kfree(UNC);
                return ERR_PTR(-EINVAL);
        }
@@ -142,8 +142,8 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
 
        rc = dns_resolve_server_name_to_ip(*devname, &srvIP);
        if (rc != 0) {
-               cERROR(1, ("%s: Failed to resolve server part of %s to IP: %d",
-                         __func__, *devname, rc));
+               cERROR(1, "%s: Failed to resolve server part of %s to IP: %d",
+                         __func__, *devname, rc);
                goto compose_mount_options_err;
        }
        /* md_len = strlen(...) + 12 for 'sep+prefixpath='
@@ -217,8 +217,8 @@ char *cifs_compose_mount_options(const char *sb_mountdata,
                strcat(mountdata, fullpath + ref->path_consumed);
        }
 
-       /*cFYI(1,("%s: parent mountdata: %s", __func__,sb_mountdata));*/
-       /*cFYI(1, ("%s: submount mountdata: %s", __func__, mountdata ));*/
+       /*cFYI(1, "%s: parent mountdata: %s", __func__,sb_mountdata);*/
+       /*cFYI(1, "%s: submount mountdata: %s", __func__, mountdata );*/
 
 compose_mount_options_out:
        kfree(srvIP);
@@ -294,11 +294,11 @@ static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
 
 static void dump_referral(const struct dfs_info3_param *ref)
 {
-       cFYI(1, ("DFS: ref path: %s", ref->path_name));
-       cFYI(1, ("DFS: node path: %s", ref->node_name));
-       cFYI(1, ("DFS: fl: %hd, srv_type: %hd", ref->flags, ref->server_type));
-       cFYI(1, ("DFS: ref_flags: %hd, path_consumed: %hd", ref->ref_flag,
-                               ref->path_consumed));
+       cFYI(1, "DFS: ref path: %s", ref->path_name);
+       cFYI(1, "DFS: node path: %s", ref->node_name);
+       cFYI(1, "DFS: fl: %hd, srv_type: %hd", ref->flags, ref->server_type);
+       cFYI(1, "DFS: ref_flags: %hd, path_consumed: %hd", ref->ref_flag,
+                               ref->path_consumed);
 }
 
 
@@ -314,7 +314,7 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        int rc = 0;
        struct vfsmount *mnt = ERR_PTR(-ENOENT);
 
-       cFYI(1, ("in %s", __func__));
+       cFYI(1, "in %s", __func__);
        BUG_ON(IS_ROOT(dentry));
 
        xid = GetXid();
@@ -352,15 +352,15 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
                /* connect to a node */
                len = strlen(referrals[i].node_name);
                if (len < 2) {
-                       cERROR(1, ("%s: Net Address path too short: %s",
-                                       __func__, referrals[i].node_name));
+                       cERROR(1, "%s: Net Address path too short: %s",
+                                       __func__, referrals[i].node_name);
                        rc = -EINVAL;
                        goto out_err;
                }
                mnt = cifs_dfs_do_refmount(nd->path.mnt,
                                nd->path.dentry, referrals + i);
-               cFYI(1, ("%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__,
-                                       referrals[i].node_name, mnt));
+               cFYI(1, "%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__,
+                                       referrals[i].node_name, mnt);
 
                /* complete mount procedure if we accured submount */
                if (!IS_ERR(mnt))
@@ -378,7 +378,7 @@ out:
        FreeXid(xid);
        free_dfs_info_array(referrals, num_referrals);
        kfree(full_path);
-       cFYI(1, ("leaving %s" , __func__));
+       cFYI(1, "leaving %s" , __func__);
        return ERR_PTR(rc);
 out_err:
        path_put(&nd->path);
index 310d12f..379bd7d 100644 (file)
@@ -133,9 +133,9 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
        dp = description + strlen(description);
 
        /* for now, only sec=krb5 and sec=mskrb5 are valid */
-       if (server->secType == Kerberos)
+       if (server->sec_kerberos)
                sprintf(dp, ";sec=krb5");
-       else if (server->secType == MSKerberos)
+       else if (server->sec_mskerberos)
                sprintf(dp, ";sec=mskrb5");
        else
                goto out;
@@ -149,7 +149,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
        dp = description + strlen(description);
        sprintf(dp, ";pid=0x%x", current->pid);
 
-       cFYI(1, ("key description = %s", description));
+       cFYI(1, "key description = %s", description);
        spnego_key = request_key(&cifs_spnego_key_type, description, "");
 
 #ifdef CONFIG_CIFS_DEBUG2
index d07676b..430f510 100644 (file)
@@ -200,9 +200,8 @@ cifs_strtoUCS(__le16 *to, const char *from, int len,
                /* works for 2.4.0 kernel or later */
                charlen = codepage->char2uni(from, len, &wchar_to[i]);
                if (charlen < 1) {
-                       cERROR(1,
-                              ("strtoUCS: char2uni of %d returned %d",
-                               (int)*from, charlen));
+                       cERROR(1, "strtoUCS: char2uni of %d returned %d",
+                               (int)*from, charlen);
                        /* A question mark */
                        to[i] = cpu_to_le16(0x003f);
                        charlen = 1;
index 9b716d0..85d7cf7 100644 (file)
@@ -87,11 +87,11 @@ int match_sid(struct cifs_sid *ctsid)
                                continue; /* all sub_auth values do not match */
                }
 
-               cFYI(1, ("matching sid: %s\n", wksidarr[i].sidname));
+               cFYI(1, "matching sid: %s\n", wksidarr[i].sidname);
                return 0; /* sids compare/match */
        }
 
-       cFYI(1, ("No matching sid"));
+       cFYI(1, "No matching sid");
        return -1;
 }
 
@@ -208,14 +208,14 @@ static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode,
                        *pbits_to_set &= ~S_IXUGO;
                return;
        } else if (type != ACCESS_ALLOWED) {
-               cERROR(1, ("unknown access control type %d", type));
+               cERROR(1, "unknown access control type %d", type);
                return;
        }
        /* else ACCESS_ALLOWED type */
 
        if (flags & GENERIC_ALL) {
                *pmode |= (S_IRWXUGO & (*pbits_to_set));
-               cFYI(DBG2, ("all perms"));
+               cFYI(DBG2, "all perms");
                return;
        }
        if ((flags & GENERIC_WRITE) ||
@@ -228,7 +228,7 @@ static void access_flags_to_mode(__le32 ace_flags, int type, umode_t *pmode,
                        ((flags & FILE_EXEC_RIGHTS) == FILE_EXEC_RIGHTS))
                *pmode |= (S_IXUGO & (*pbits_to_set));
 
-       cFYI(DBG2, ("access flags 0x%x mode now 0x%x", flags, *pmode));
+       cFYI(DBG2, "access flags 0x%x mode now 0x%x", flags, *pmode);
        return;
 }
 
@@ -257,7 +257,7 @@ static void mode_to_access_flags(umode_t mode, umode_t bits_to_use,
        if (mode & S_IXUGO)
                *pace_flags |= SET_FILE_EXEC_RIGHTS;
 
-       cFYI(DBG2, ("mode: 0x%x, access flags now 0x%x", mode, *pace_flags));
+       cFYI(DBG2, "mode: 0x%x, access flags now 0x%x", mode, *pace_flags);
        return;
 }
 
@@ -297,24 +297,24 @@ static void dump_ace(struct cifs_ace *pace, char *end_of_acl)
        /* validate that we do not go past end of acl */
 
        if (le16_to_cpu(pace->size) < 16) {
-               cERROR(1, ("ACE too small, %d", le16_to_cpu(pace->size)));
+               cERROR(1, "ACE too small %d", le16_to_cpu(pace->size));
                return;
        }
 
        if (end_of_acl < (char *)pace + le16_to_cpu(pace->size)) {
-               cERROR(1, ("ACL too small to parse ACE"));
+               cERROR(1, "ACL too small to parse ACE");
                return;
        }
 
        num_subauth = pace->sid.num_subauth;
        if (num_subauth) {
                int i;
-               cFYI(1, ("ACE revision %d num_auth %d type %d flags %d size %d",
+               cFYI(1, "ACE revision %d num_auth %d type %d flags %d size %d",
                        pace->sid.revision, pace->sid.num_subauth, pace->type,
-                       pace->flags, le16_to_cpu(pace->size)));
+                       pace->flags, le16_to_cpu(pace->size));
                for (i = 0; i < num_subauth; ++i) {
-                       cFYI(1, ("ACE sub_auth[%d]: 0x%x", i,
-                               le32_to_cpu(pace->sid.sub_auth[i])));
+                       cFYI(1, "ACE sub_auth[%d]: 0x%x", i,
+                               le32_to_cpu(pace->sid.sub_auth[i]));
                }
 
                /* BB add length check to make sure that we do not have huge
@@ -347,13 +347,13 @@ static void parse_dacl(struct cifs_acl *pdacl, char *end_of_acl,
 
        /* validate that we do not go past end of acl */
        if (end_of_acl < (char *)pdacl + le16_to_cpu(pdacl->size)) {
-               cERROR(1, ("ACL too small to parse DACL"));
+               cERROR(1, "ACL too small to parse DACL");
                return;
        }
 
-       cFYI(DBG2, ("DACL revision %d size %d num aces %d",
+       cFYI(DBG2, "DACL revision %d size %d num aces %d",
                le16_to_cpu(pdacl->revision), le16_to_cpu(pdacl->size),
-               le32_to_cpu(pdacl->num_aces)));
+               le32_to_cpu(pdacl->num_aces));
 
        /* reset rwx permissions for user/group/other.
           Also, if num_aces is 0 i.e. DACL has no ACEs,
@@ -437,25 +437,25 @@ static int parse_sid(struct cifs_sid *psid, char *end_of_acl)
        /* validate that we do not go past end of ACL - sid must be at least 8
           bytes long (assuming no sub-auths - e.g. the null SID */
        if (end_of_acl < (char *)psid + 8) {
-               cERROR(1, ("ACL too small to parse SID %p", psid));
+               cERROR(1, "ACL too small to parse SID %p", psid);
                return -EINVAL;
        }
 
        if (psid->num_subauth) {
 #ifdef CONFIG_CIFS_DEBUG2
                int i;
-               cFYI(1, ("SID revision %d num_auth %d",
-                       psid->revision, psid->num_subauth));
+               cFYI(1, "SID revision %d num_auth %d",
+                       psid->revision, psid->num_subauth);
 
                for (i = 0; i < psid->num_subauth; i++) {
-                       cFYI(1, ("SID sub_auth[%d]: 0x%x ", i,
-                               le32_to_cpu(psid->sub_auth[i])));
+                       cFYI(1, "SID sub_auth[%d]: 0x%x ", i,
+                               le32_to_cpu(psid->sub_auth[i]));
                }
 
                /* BB add length check to make sure that we do not have huge
                        num auths and therefore go off the end */
-               cFYI(1, ("RID 0x%x",
-                       le32_to_cpu(psid->sub_auth[psid->num_subauth-1])));
+               cFYI(1, "RID 0x%x",
+                       le32_to_cpu(psid->sub_auth[psid->num_subauth-1]));
 #endif
        }
 
@@ -482,11 +482,11 @@ static int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len,
                                le32_to_cpu(pntsd->gsidoffset));
        dacloffset = le32_to_cpu(pntsd->dacloffset);
        dacl_ptr = (struct cifs_acl *)((char *)pntsd + dacloffset);
-       cFYI(DBG2, ("revision %d type 0x%x ooffset 0x%x goffset 0x%x "
+       cFYI(DBG2, "revision %d type 0x%x ooffset 0x%x goffset 0x%x "
                 "sacloffset 0x%x dacloffset 0x%x",
                 pntsd->revision, pntsd->type, le32_to_cpu(pntsd->osidoffset),
                 le32_to_cpu(pntsd->gsidoffset),
-                le32_to_cpu(pntsd->sacloffset), dacloffset));
+                le32_to_cpu(pntsd->sacloffset), dacloffset);
 /*     cifs_dump_mem("owner_sid: ", owner_sid_ptr, 64); */
        rc = parse_sid(owner_sid_ptr, end_of_acl);
        if (rc)
@@ -500,7 +500,7 @@ static int parse_sec_desc(struct cifs_ntsd *pntsd, int acl_len,
                parse_dacl(dacl_ptr, end_of_acl, owner_sid_ptr,
                           group_sid_ptr, fattr);
        else
-               cFYI(1, ("no ACL")); /* BB grant all or default perms? */
+               cFYI(1, "no ACL"); /* BB grant all or default perms? */
 
 /*     cifscred->uid = owner_sid_ptr->rid;
        cifscred->gid = group_sid_ptr->rid;
@@ -563,7 +563,7 @@ static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
        FreeXid(xid);
 
 
-       cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
+       cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen);
        return pntsd;
 }
 
@@ -581,12 +581,12 @@ static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
                         &fid, &oplock, NULL, cifs_sb->local_nls,
                         cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        if (rc) {
-               cERROR(1, ("Unable to open file to get ACL"));
+               cERROR(1, "Unable to open file to get ACL");
                goto out;
        }
 
        rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
-       cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
+       cFYI(1, "GetCIFSACL rc = %d ACL len %d", rc, *pacllen);
 
        CIFSSMBClose(xid, cifs_sb->tcon, fid);
  out:
@@ -621,7 +621,7 @@ static int set_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, __u16 fid,
        rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen);
        FreeXid(xid);
 
-       cFYI(DBG2, ("SetCIFSACL rc = %d", rc));
+       cFYI(DBG2, "SetCIFSACL rc = %d", rc);
        return rc;
 }
 
@@ -638,12 +638,12 @@ static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path,
                         &fid, &oplock, NULL, cifs_sb->local_nls,
                         cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        if (rc) {
-               cERROR(1, ("Unable to open file to set ACL"));
+               cERROR(1, "Unable to open file to set ACL");
                goto out;
        }
 
        rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen);
-       cFYI(DBG2, ("SetCIFSACL rc = %d", rc));
+       cFYI(DBG2, "SetCIFSACL rc = %d", rc);
 
        CIFSSMBClose(xid, cifs_sb->tcon, fid);
  out:
@@ -659,7 +659,7 @@ static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
        struct cifsFileInfo *open_file;
        int rc;
 
-       cFYI(DBG2, ("set ACL for %s from mode 0x%x", path, inode->i_mode));
+       cFYI(DBG2, "set ACL for %s from mode 0x%x", path, inode->i_mode);
 
        open_file = find_readable_file(CIFS_I(inode));
        if (!open_file)
@@ -679,7 +679,7 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
        u32 acllen = 0;
        int rc = 0;
 
-       cFYI(DBG2, ("converting ACL to mode for %s", path));
+       cFYI(DBG2, "converting ACL to mode for %s", path);
 
        if (pfid)
                pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen);
@@ -690,7 +690,7 @@ cifs_acl_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_fattr *fattr,
        if (pntsd)
                rc = parse_sec_desc(pntsd, acllen, fattr);
        if (rc)
-               cFYI(1, ("parse sec desc failed rc = %d", rc));
+               cFYI(1, "parse sec desc failed rc = %d", rc);
 
        kfree(pntsd);
        return;
@@ -704,7 +704,7 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
        struct cifs_ntsd *pntsd = NULL; /* acl obtained from server */
        struct cifs_ntsd *pnntsd = NULL; /* modified acl to be sent to server */
 
-       cFYI(DBG2, ("set ACL from mode for %s", path));
+       cFYI(DBG2, "set ACL from mode for %s", path);
 
        /* Get the security descriptor */
        pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen);
@@ -721,19 +721,19 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
                                        DEFSECDESCLEN : secdesclen;
                pnntsd = kmalloc(secdesclen, GFP_KERNEL);
                if (!pnntsd) {
-                       cERROR(1, ("Unable to allocate security descriptor"));
+                       cERROR(1, "Unable to allocate security descriptor");
                        kfree(pntsd);
                        return -ENOMEM;
                }
 
                rc = build_sec_desc(pntsd, pnntsd, inode, nmode);
 
-               cFYI(DBG2, ("build_sec_desc rc: %d", rc));
+               cFYI(DBG2, "build_sec_desc rc: %d", rc);
 
                if (!rc) {
                        /* Set the security descriptor */
                        rc = set_cifs_acl(pnntsd, secdesclen, inode, path);
-                       cFYI(DBG2, ("set_cifs_acl rc: %d", rc));
+                       cFYI(DBG2, "set_cifs_acl rc: %d", rc);
                }
 
                kfree(pnntsd);
index fbe9864..847628d 100644 (file)
@@ -103,7 +103,7 @@ static int cifs_calc_signature2(const struct kvec *iov, int n_vec,
                if (iov[i].iov_len == 0)
                        continue;
                if (iov[i].iov_base == NULL) {
-                       cERROR(1, ("null iovec entry"));
+                       cERROR(1, "null iovec entry");
                        return -EIO;
                }
                /* The first entry includes a length field (which does not get
@@ -181,8 +181,8 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu,
 
        /* Do not need to verify session setups with signature "BSRSPYL "  */
        if (memcmp(cifs_pdu->Signature.SecuritySignature, "BSRSPYL ", 8) == 0)
-               cFYI(1, ("dummy signature received for smb command 0x%x",
-                       cifs_pdu->Command));
+               cFYI(1, "dummy signature received for smb command 0x%x",
+                       cifs_pdu->Command);
 
        /* save off the origiginal signature so we can modify the smb and check
                its signature against what the server sent */
@@ -291,7 +291,7 @@ void calc_lanman_hash(const char *password, const char *cryptkey, bool encrypt,
        if (password)
                strncpy(password_with_pad, password, CIFS_ENCPWD_SIZE);
 
-       if (!encrypt && extended_security & CIFSSEC_MAY_PLNTXT) {
+       if (!encrypt && global_secflags & CIFSSEC_MAY_PLNTXT) {
                memset(lnm_session_key, 0, CIFS_SESS_KEY_SIZE);
                memcpy(lnm_session_key, password_with_pad,
                        CIFS_ENCPWD_SIZE);
@@ -398,7 +398,7 @@ void setup_ntlmv2_rsp(struct cifsSesInfo *ses, char *resp_buf,
        /* calculate buf->ntlmv2_hash */
        rc = calc_ntlmv2_hash(ses, nls_cp);
        if (rc)
-               cERROR(1, ("could not get v2 hash rc %d", rc));
+               cERROR(1, "could not get v2 hash rc %d", rc);
        CalcNTLMv2_response(ses, resp_buf);
 
        /* now calculate the MAC key for NTLMv2 */
index ad235d6..78c02eb 100644 (file)
 #include "cifs_spnego.h"
 #define CIFS_MAGIC_NUMBER 0xFF534D42   /* the first four bytes of SMB PDUs */
 
-#ifdef CONFIG_CIFS_QUOTA
-static const struct quotactl_ops cifs_quotactl_ops;
-#endif /* QUOTA */
-
 int cifsFYI = 0;
 int cifsERROR = 1;
 int traceSMB = 0;
@@ -61,7 +57,7 @@ unsigned int experimEnabled = 0;
 unsigned int linuxExtEnabled = 1;
 unsigned int lookupCacheEnabled = 1;
 unsigned int multiuser_mount = 0;
-unsigned int extended_security = CIFSSEC_DEF;
+unsigned int global_secflags = CIFSSEC_DEF;
 /* unsigned int ntlmv2_support = 0; */
 unsigned int sign_CIFS_PDUs = 1;
 static const struct super_operations cifs_super_ops;
@@ -86,8 +82,6 @@ extern mempool_t *cifs_sm_req_poolp;
 extern mempool_t *cifs_req_poolp;
 extern mempool_t *cifs_mid_poolp;
 
-extern struct kmem_cache *cifs_oplock_cachep;
-
 static int
 cifs_read_super(struct super_block *sb, void *data,
                const char *devname, int silent)
@@ -135,8 +129,7 @@ cifs_read_super(struct super_block *sb, void *data,
 
        if (rc) {
                if (!silent)
-                       cERROR(1,
-                              ("cifs_mount failed w/return code = %d", rc));
+                       cERROR(1, "cifs_mount failed w/return code = %d", rc);
                goto out_mount_failed;
        }
 
@@ -146,9 +139,6 @@ cifs_read_super(struct super_block *sb, void *data,
 /*     if (cifs_sb->tcon->ses->server->maxBuf > MAX_CIFS_HDR_SIZE + 512)
            sb->s_blocksize =
                cifs_sb->tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE; */
-#ifdef CONFIG_CIFS_QUOTA
-       sb->s_qcop = &cifs_quotactl_ops;
-#endif
        sb->s_blocksize = CIFS_MAX_MSGSIZE;
        sb->s_blocksize_bits = 14;      /* default 2**14 = CIFS_MAX_MSGSIZE */
        inode = cifs_root_iget(sb, ROOT_I);
@@ -168,7 +158,7 @@ cifs_read_super(struct super_block *sb, void *data,
 
 #ifdef CONFIG_CIFS_EXPERIMENTAL
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
-               cFYI(1, ("export ops supported"));
+               cFYI(1, "export ops supported");
                sb->s_export_op = &cifs_export_ops;
        }
 #endif /* EXPERIMENTAL */
@@ -176,7 +166,7 @@ cifs_read_super(struct super_block *sb, void *data,
        return 0;
 
 out_no_root:
-       cERROR(1, ("cifs_read_super: get root inode failed"));
+       cERROR(1, "cifs_read_super: get root inode failed");
        if (inode)
                iput(inode);
 
@@ -203,10 +193,10 @@ cifs_put_super(struct super_block *sb)
        int rc = 0;
        struct cifs_sb_info *cifs_sb;
 
-       cFYI(1, ("In cifs_put_super"));
+       cFYI(1, "In cifs_put_super");
        cifs_sb = CIFS_SB(sb);
        if (cifs_sb == NULL) {
-               cFYI(1, ("Empty cifs superblock info passed to unmount"));
+               cFYI(1, "Empty cifs superblock info passed to unmount");
                return;
        }
 
@@ -214,7 +204,7 @@ cifs_put_super(struct super_block *sb)
 
        rc = cifs_umount(sb, cifs_sb);
        if (rc)
-               cERROR(1, ("cifs_umount failed with return code %d", rc));
+               cERROR(1, "cifs_umount failed with return code %d", rc);
 #ifdef CONFIG_CIFS_DFS_UPCALL
        if (cifs_sb->mountdata) {
                kfree(cifs_sb->mountdata);
@@ -300,7 +290,6 @@ static int cifs_permission(struct inode *inode, int mask)
 static struct kmem_cache *cifs_inode_cachep;
 static struct kmem_cache *cifs_req_cachep;
 static struct kmem_cache *cifs_mid_cachep;
-struct kmem_cache *cifs_oplock_cachep;
 static struct kmem_cache *cifs_sm_req_cachep;
 mempool_t *cifs_sm_req_poolp;
 mempool_t *cifs_req_poolp;
@@ -432,106 +421,6 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m)
        return 0;
 }
 
-#ifdef CONFIG_CIFS_QUOTA
-int cifs_xquota_set(struct super_block *sb, int quota_type, qid_t qid,
-               struct fs_disk_quota *pdquota)
-{
-       int xid;
-       int rc = 0;
-       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
-       struct cifsTconInfo *pTcon;
-
-       if (cifs_sb)
-               pTcon = cifs_sb->tcon;
-       else
-               return -EIO;
-
-
-       xid = GetXid();
-       if (pTcon) {
-               cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
-       } else
-               rc = -EIO;
-
-       FreeXid(xid);
-       return rc;
-}
-
-int cifs_xquota_get(struct super_block *sb, int quota_type, qid_t qid,
-                   struct fs_disk_quota *pdquota)
-{
-       int xid;
-       int rc = 0;
-       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
-       struct cifsTconInfo *pTcon;
-
-       if (cifs_sb)
-               pTcon = cifs_sb->tcon;
-       else
-               return -EIO;
-
-       xid = GetXid();
-       if (pTcon) {
-               cFYI(1, ("set type: 0x%x id: %d", quota_type, qid));
-       } else
-               rc = -EIO;
-
-       FreeXid(xid);
-       return rc;
-}
-
-int cifs_xstate_set(struct super_block *sb, unsigned int flags, int operation)
-{
-       int xid;
-       int rc = 0;
-       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
-       struct cifsTconInfo *pTcon;
-
-       if (cifs_sb)
-               pTcon = cifs_sb->tcon;
-       else
-               return -EIO;
-
-       xid = GetXid();
-       if (pTcon) {
-               cFYI(1, ("flags: 0x%x operation: 0x%x", flags, operation));
-       } else
-               rc = -EIO;
-
-       FreeXid(xid);
-       return rc;
-}
-
-int cifs_xstate_get(struct super_block *sb, struct fs_quota_stat *qstats)
-{
-       int xid;
-       int rc = 0;
-       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
-       struct cifsTconInfo *pTcon;
-
-       if (cifs_sb)
-               pTcon = cifs_sb->tcon;
-       else
-               return -EIO;
-
-       xid = GetXid();
-       if (pTcon) {
-               cFYI(1, ("pqstats %p", qstats));
-       } else
-               rc = -EIO;
-
-       FreeXid(xid);
-       return rc;
-}
-
-static const struct quotactl_ops cifs_quotactl_ops = {
-       .set_xquota     = cifs_xquota_set,
-       .get_xquota     = cifs_xquota_get,
-       .set_xstate     = cifs_xstate_set,
-       .get_xstate     = cifs_xstate_get,
-};
-#endif
-
 static void cifs_umount_begin(struct super_block *sb)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
@@ -558,7 +447,7 @@ static void cifs_umount_begin(struct super_block *sb)
        /* cancel_brl_requests(tcon); */ /* BB mark all brl mids as exiting */
        /* cancel_notify_requests(tcon); */
        if (tcon->ses && tcon->ses->server) {
-               cFYI(1, ("wake up tasks now - umount begin not complete"));
+               cFYI(1, "wake up tasks now - umount begin not complete");
                wake_up_all(&tcon->ses->server->request_q);
                wake_up_all(&tcon->ses->server->response_q);
                msleep(1); /* yield */
@@ -609,7 +498,7 @@ cifs_get_sb(struct file_system_type *fs_type,
        int rc;
        struct super_block *sb = sget(fs_type, NULL, set_anon_super, NULL);
 
-       cFYI(1, ("Devname: %s flags: %d ", dev_name, flags));
+       cFYI(1, "Devname: %s flags: %d ", dev_name, flags);
 
        if (IS_ERR(sb))
                return PTR_ERR(sb);
@@ -656,7 +545,6 @@ static loff_t cifs_llseek(struct file *file, loff_t offset, int origin)
        return generic_file_llseek_unlocked(file, offset, origin);
 }
 
-#ifdef CONFIG_CIFS_EXPERIMENTAL
 static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
 {
        /* note that this is called by vfs setlease with the BKL held
@@ -685,7 +573,6 @@ static int cifs_setlease(struct file *file, long arg, struct file_lock **lease)
        else
                return -EAGAIN;
 }
-#endif
 
 struct file_system_type cifs_fs_type = {
        .owner = THIS_MODULE,
@@ -762,10 +649,7 @@ const struct file_operations cifs_file_ops = {
 #ifdef CONFIG_CIFS_POSIX
        .unlocked_ioctl = cifs_ioctl,
 #endif /* CONFIG_CIFS_POSIX */
-
-#ifdef CONFIG_CIFS_EXPERIMENTAL
        .setlease = cifs_setlease,
-#endif /* CONFIG_CIFS_EXPERIMENTAL */
 };
 
 const struct file_operations cifs_file_direct_ops = {
@@ -784,9 +668,7 @@ const struct file_operations cifs_file_direct_ops = {
        .unlocked_ioctl  = cifs_ioctl,
 #endif /* CONFIG_CIFS_POSIX */
        .llseek = cifs_llseek,
-#ifdef CONFIG_CIFS_EXPERIMENTAL
        .setlease = cifs_setlease,
-#endif /* CONFIG_CIFS_EXPERIMENTAL */
 };
 const struct file_operations cifs_file_nobrl_ops = {
        .read = do_sync_read,
@@ -803,10 +685,7 @@ const struct file_operations cifs_file_nobrl_ops = {
 #ifdef CONFIG_CIFS_POSIX
        .unlocked_ioctl = cifs_ioctl,
 #endif /* CONFIG_CIFS_POSIX */
-
-#ifdef CONFIG_CIFS_EXPERIMENTAL
        .setlease = cifs_setlease,
-#endif /* CONFIG_CIFS_EXPERIMENTAL */
 };
 
 const struct file_operations cifs_file_direct_nobrl_ops = {
@@ -824,9 +703,7 @@ const struct file_operations cifs_file_direct_nobrl_ops = {
        .unlocked_ioctl  = cifs_ioctl,
 #endif /* CONFIG_CIFS_POSIX */
        .llseek = cifs_llseek,
-#ifdef CONFIG_CIFS_EXPERIMENTAL
        .setlease = cifs_setlease,
-#endif /* CONFIG_CIFS_EXPERIMENTAL */
 };
 
 const struct file_operations cifs_dir_ops = {
@@ -878,7 +755,7 @@ cifs_init_request_bufs(void)
        } else {
                CIFSMaxBufSize &= 0x1FE00; /* Round size to even 512 byte mult*/
        }
-/*     cERROR(1,("CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize)); */
+/*     cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
        cifs_req_cachep = kmem_cache_create("cifs_request",
                                            CIFSMaxBufSize +
                                            MAX_CIFS_HDR_SIZE, 0,
@@ -890,7 +767,7 @@ cifs_init_request_bufs(void)
                cifs_min_rcv = 1;
        else if (cifs_min_rcv > 64) {
                cifs_min_rcv = 64;
-               cERROR(1, ("cifs_min_rcv set to maximum (64)"));
+               cERROR(1, "cifs_min_rcv set to maximum (64)");
        }
 
        cifs_req_poolp = mempool_create_slab_pool(cifs_min_rcv,
@@ -921,7 +798,7 @@ cifs_init_request_bufs(void)
                cifs_min_small = 2;
        else if (cifs_min_small > 256) {
                cifs_min_small = 256;
-               cFYI(1, ("cifs_min_small set to maximum (256)"));
+               cFYI(1, "cifs_min_small set to maximum (256)");
        }
 
        cifs_sm_req_poolp = mempool_create_slab_pool(cifs_min_small,
@@ -962,15 +839,6 @@ cifs_init_mids(void)
                return -ENOMEM;
        }
 
-       cifs_oplock_cachep = kmem_cache_create("cifs_oplock_structs",
-                                       sizeof(struct oplock_q_entry), 0,
-                                       SLAB_HWCACHE_ALIGN, NULL);
-       if (cifs_oplock_cachep == NULL) {
-               mempool_destroy(cifs_mid_poolp);
-               kmem_cache_destroy(cifs_mid_cachep);
-               return -ENOMEM;
-       }
-
        return 0;
 }
 
@@ -979,7 +847,6 @@ cifs_destroy_mids(void)
 {
        mempool_destroy(cifs_mid_poolp);
        kmem_cache_destroy(cifs_mid_cachep);
-       kmem_cache_destroy(cifs_oplock_cachep);
 }
 
 static int __init
@@ -1019,10 +886,10 @@ init_cifs(void)
 
        if (cifs_max_pending < 2) {
                cifs_max_pending = 2;
-               cFYI(1, ("cifs_max_pending set to min of 2"));
+               cFYI(1, "cifs_max_pending set to min of 2");
        } else if (cifs_max_pending > 256) {
                cifs_max_pending = 256;
-               cFYI(1, ("cifs_max_pending set to max of 256"));
+               cFYI(1, "cifs_max_pending set to max of 256");
        }
 
        rc = cifs_init_inodecache();
@@ -1080,7 +947,7 @@ init_cifs(void)
 static void __exit
 exit_cifs(void)
 {
-       cFYI(DBG2, ("exit_cifs"));
+       cFYI(DBG2, "exit_cifs");
        cifs_proc_clean();
 #ifdef CONFIG_CIFS_DFS_UPCALL
        cifs_dfs_release_automount_timer();
index 7aa57ec..0242ff9 100644 (file)
@@ -114,5 +114,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
 extern const struct export_operations cifs_export_ops;
 #endif /* EXPERIMENTAL */
 
-#define CIFS_VERSION   "1.62"
+#define CIFS_VERSION   "1.64"
 #endif                         /* _CIFSFS_H */
index 0c2fd17..a88479c 100644 (file)
@@ -87,7 +87,6 @@ enum securityEnum {
        RawNTLMSSP,             /* NTLMSSP without SPNEGO, NTLMv2 hash */
 /*     NTLMSSP, */ /* can use rawNTLMSSP instead of NTLMSSP via SPNEGO */
        Kerberos,               /* Kerberos via SPNEGO */
-       MSKerberos,             /* MS Kerberos via SPNEGO */
 };
 
 enum protocolEnum {
@@ -185,6 +184,12 @@ struct TCP_Server_Info {
        struct mac_key mac_signing_key;
        char ntlmv2_hash[16];
        unsigned long lstrp; /* when we got last response from this server */
+       u16 dialect; /* dialect index that server chose */
+       /* extended security flavors that server supports */
+       bool    sec_kerberos;           /* supports plain Kerberos */
+       bool    sec_mskerberos;         /* supports legacy MS Kerberos */
+       bool    sec_kerberosu2u;        /* supports U2U Kerberos */
+       bool    sec_ntlmssp;            /* supports NTLMSSP */
 };
 
 /*
@@ -718,7 +723,7 @@ GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions
 GLOBAL_EXTERN unsigned int oplockEnabled;
 GLOBAL_EXTERN unsigned int experimEnabled;
 GLOBAL_EXTERN unsigned int lookupCacheEnabled;
-GLOBAL_EXTERN unsigned int extended_security;  /* if on, session setup sent
+GLOBAL_EXTERN unsigned int global_secflags;    /* if on, session setup sent
                                with more secure ntlmssp2 challenge/resp */
 GLOBAL_EXTERN unsigned int sign_CIFS_PDUs;  /* enable smb packet signing */
 GLOBAL_EXTERN unsigned int linuxExtEnabled;/*enable Linux/Unix CIFS extensions*/
index 39e47f4..fb1657e 100644 (file)
@@ -39,8 +39,20 @@ extern int smb_send(struct TCP_Server_Info *, struct smb_hdr *,
                        unsigned int /* length */);
 extern unsigned int _GetXid(void);
 extern void _FreeXid(unsigned int);
-#define GetXid() (int)_GetXid(); cFYI(1,("CIFS VFS: in %s as Xid: %d with uid: %d",__func__, xid,current_fsuid()));
-#define FreeXid(curr_xid) {_FreeXid(curr_xid); cFYI(1,("CIFS VFS: leaving %s (xid = %d) rc = %d",__func__,curr_xid,(int)rc));}
+#define GetXid()                                               \
+({                                                             \
+       int __xid = (int)_GetXid();                             \
+       cFYI(1, "CIFS VFS: in %s as Xid: %d with uid: %d",      \
+            __func__, __xid, current_fsuid());                 \
+       __xid;                                                  \
+})
+
+#define FreeXid(curr_xid)                                      \
+do {                                                           \
+       _FreeXid(curr_xid);                                     \
+       cFYI(1, "CIFS VFS: leaving %s (xid = %d) rc = %d",      \
+            __func__, curr_xid, (int)rc);                      \
+} while (0)
 extern char *build_path_from_dentry(struct dentry *);
 extern char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb);
 extern char *build_wildcard_path_from_dentry(struct dentry *direntry);
@@ -73,7 +85,7 @@ extern struct cifsFileInfo *find_readable_file(struct cifsInodeInfo *);
 extern unsigned int smbCalcSize(struct smb_hdr *ptr);
 extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
 extern int decode_negTokenInit(unsigned char *security_blob, int length,
-                       enum securityEnum *secType);
+                       struct TCP_Server_Info *server);
 extern int cifs_convert_address(char *src, void *dst);
 extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
 extern void header_assemble(struct smb_hdr *, char /* command */ ,
@@ -83,7 +95,6 @@ extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
                                struct cifsSesInfo *ses,
                                void **request_buf);
 extern int CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
-                            const int stage,
                             const struct nls_table *nls_cp);
 extern __u16 GetNextMid(struct TCP_Server_Info *server);
 extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
@@ -95,8 +106,11 @@ extern struct cifsFileInfo *cifs_new_fileinfo(struct inode *newinode,
                                __u16 fileHandle, struct file *file,
                                struct vfsmount *mnt, unsigned int oflags);
 extern int cifs_posix_open(char *full_path, struct inode **pinode,
-                          struct vfsmount *mnt, int mode, int oflags,
-                          __u32 *poplock, __u16 *pnetfid, int xid);
+                               struct vfsmount *mnt,
+                               struct super_block *sb,
+                               int mode, int oflags,
+                               __u32 *poplock, __u16 *pnetfid, int xid);
+void cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr);
 extern void cifs_unix_basic_to_fattr(struct cifs_fattr *fattr,
                                     FILE_UNIX_BASIC_INFO *info,
                                     struct cifs_sb_info *cifs_sb);
@@ -125,7 +139,9 @@ extern void cifs_dfs_release_automount_timer(void);
 void cifs_proc_init(void);
 void cifs_proc_clean(void);
 
-extern int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
+extern int cifs_negotiate_protocol(unsigned int xid,
+                                 struct cifsSesInfo *ses);
+extern int cifs_setup_session(unsigned int xid, struct cifsSesInfo *ses,
                        struct nls_table *nls_info);
 extern int CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses);
 
index 5d3f29f..c65c341 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   fs/cifs/cifssmb.c
  *
- *   Copyright (C) International Business Machines  Corp., 2002,2009
+ *   Copyright (C) International Business Machines  Corp., 2002,2010
  *   Author(s): Steve French (sfrench@us.ibm.com)
  *
  *   Contains the routines for constructing the SMB PDUs themselves
@@ -130,8 +130,8 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
                if (smb_command != SMB_COM_WRITE_ANDX &&
                    smb_command != SMB_COM_OPEN_ANDX &&
                    smb_command != SMB_COM_TREE_DISCONNECT) {
-                       cFYI(1, ("can not send cmd %d while umounting",
-                               smb_command));
+                       cFYI(1, "can not send cmd %d while umounting",
+                               smb_command);
                        return -ENODEV;
                }
        }
@@ -157,7 +157,7 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
                 * back on-line
                 */
                if (!tcon->retry || ses->status == CifsExiting) {
-                       cFYI(1, ("gave up waiting on reconnect in smb_init"));
+                       cFYI(1, "gave up waiting on reconnect in smb_init");
                        return -EHOSTDOWN;
                }
        }
@@ -172,7 +172,8 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
         * reconnect the same SMB session
         */
        mutex_lock(&ses->session_mutex);
-       if (ses->need_reconnect)
+       rc = cifs_negotiate_protocol(0, ses);
+       if (rc == 0 && ses->need_reconnect)
                rc = cifs_setup_session(0, ses, nls_codepage);
 
        /* do we need to reconnect tcon? */
@@ -184,7 +185,7 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command)
        mark_open_files_invalid(tcon);
        rc = CIFSTCon(0, ses, tcon->treeName, tcon, nls_codepage);
        mutex_unlock(&ses->session_mutex);
-       cFYI(1, ("reconnect tcon rc = %d", rc));
+       cFYI(1, "reconnect tcon rc = %d", rc);
 
        if (rc)
                goto out;
@@ -355,7 +356,6 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        struct TCP_Server_Info *server;
        u16 count;
        unsigned int secFlags;
-       u16 dialect;
 
        if (ses->server)
                server = ses->server;
@@ -372,9 +372,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        if (ses->overrideSecFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL)))
                secFlags = ses->overrideSecFlg;  /* BB FIXME fix sign flags? */
        else /* if override flags set only sign/seal OR them with global auth */
-               secFlags = extended_security | ses->overrideSecFlg;
+               secFlags = global_secflags | ses->overrideSecFlg;
 
-       cFYI(1, ("secFlags 0x%x", secFlags));
+       cFYI(1, "secFlags 0x%x", secFlags);
 
        pSMB->hdr.Mid = GetNextMid(server);
        pSMB->hdr.Flags2 |= (SMBFLG2_UNICODE | SMBFLG2_ERR_STATUS);
@@ -382,14 +382,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        if ((secFlags & CIFSSEC_MUST_KRB5) == CIFSSEC_MUST_KRB5)
                pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
        else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_KRB5) {
-               cFYI(1, ("Kerberos only mechanism, enable extended security"));
+               cFYI(1, "Kerberos only mechanism, enable extended security");
                pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
        }
 #ifdef CONFIG_CIFS_EXPERIMENTAL
        else if ((secFlags & CIFSSEC_MUST_NTLMSSP) == CIFSSEC_MUST_NTLMSSP)
                pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
        else if ((secFlags & CIFSSEC_AUTH_MASK) == CIFSSEC_MAY_NTLMSSP) {
-               cFYI(1, ("NTLMSSP only mechanism, enable extended security"));
+               cFYI(1, "NTLMSSP only mechanism, enable extended security");
                pSMB->hdr.Flags2 |= SMBFLG2_EXT_SEC;
        }
 #endif
@@ -408,10 +408,10 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        if (rc != 0)
                goto neg_err_exit;
 
-       dialect = le16_to_cpu(pSMBr->DialectIndex);
-       cFYI(1, ("Dialect: %d", dialect));
+       server->dialect = le16_to_cpu(pSMBr->DialectIndex);
+       cFYI(1, "Dialect: %d", server->dialect);
        /* Check wct = 1 error case */
-       if ((pSMBr->hdr.WordCount < 13) || (dialect == BAD_PROT)) {
+       if ((pSMBr->hdr.WordCount < 13) || (server->dialect == BAD_PROT)) {
                /* core returns wct = 1, but we do not ask for core - otherwise
                small wct just comes when dialect index is -1 indicating we
                could not negotiate a common dialect */
@@ -419,8 +419,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                goto neg_err_exit;
 #ifdef CONFIG_CIFS_WEAK_PW_HASH
        } else if ((pSMBr->hdr.WordCount == 13)
-                       && ((dialect == LANMAN_PROT)
-                               || (dialect == LANMAN2_PROT))) {
+                       && ((server->dialect == LANMAN_PROT)
+                               || (server->dialect == LANMAN2_PROT))) {
                __s16 tmp;
                struct lanman_neg_rsp *rsp = (struct lanman_neg_rsp *)pSMBr;
 
@@ -428,8 +428,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        (secFlags & CIFSSEC_MAY_PLNTXT))
                        server->secType = LANMAN;
                else {
-                       cERROR(1, ("mount failed weak security disabled"
-                                  " in /proc/fs/cifs/SecurityFlags"));
+                       cERROR(1, "mount failed weak security disabled"
+                                  " in /proc/fs/cifs/SecurityFlags");
                        rc = -EOPNOTSUPP;
                        goto neg_err_exit;
                }
@@ -462,9 +462,9 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        utc = CURRENT_TIME;
                        ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
                                            rsp->SrvTime.Time, 0);
-                       cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d",
+                       cFYI(1, "SrvTime %d sec since 1970 (utc: %d) diff: %d",
                                (int)ts.tv_sec, (int)utc.tv_sec,
-                               (int)(utc.tv_sec - ts.tv_sec)));
+                               (int)(utc.tv_sec - ts.tv_sec));
                        val = (int)(utc.tv_sec - ts.tv_sec);
                        seconds = abs(val);
                        result = (seconds / MIN_TZ_ADJ) * MIN_TZ_ADJ;
@@ -478,7 +478,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        server->timeAdj = (int)tmp;
                        server->timeAdj *= 60; /* also in seconds */
                }
-               cFYI(1, ("server->timeAdj: %d seconds", server->timeAdj));
+               cFYI(1, "server->timeAdj: %d seconds", server->timeAdj);
 
 
                /* BB get server time for time conversions and add
@@ -493,14 +493,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        goto neg_err_exit;
                }
 
-               cFYI(1, ("LANMAN negotiated"));
+               cFYI(1, "LANMAN negotiated");
                /* we will not end up setting signing flags - as no signing
                was in LANMAN and server did not return the flags on */
                goto signing_check;
 #else /* weak security disabled */
        } else if (pSMBr->hdr.WordCount == 13) {
-               cERROR(1, ("mount failed, cifs module not built "
-                         "with CIFS_WEAK_PW_HASH support"));
+               cERROR(1, "mount failed, cifs module not built "
+                         "with CIFS_WEAK_PW_HASH support");
                rc = -EOPNOTSUPP;
 #endif /* WEAK_PW_HASH */
                goto neg_err_exit;
@@ -512,14 +512,14 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        /* else wct == 17 NTLM */
        server->secMode = pSMBr->SecurityMode;
        if ((server->secMode & SECMODE_USER) == 0)
-               cFYI(1, ("share mode security"));
+               cFYI(1, "share mode security");
 
        if ((server->secMode & SECMODE_PW_ENCRYPT) == 0)
 #ifdef CONFIG_CIFS_WEAK_PW_HASH
                if ((secFlags & CIFSSEC_MAY_PLNTXT) == 0)
 #endif /* CIFS_WEAK_PW_HASH */
-                       cERROR(1, ("Server requests plain text password"
-                                 " but client support disabled"));
+                       cERROR(1, "Server requests plain text password"
+                                 " but client support disabled");
 
        if ((secFlags & CIFSSEC_MUST_NTLMV2) == CIFSSEC_MUST_NTLMV2)
                server->secType = NTLMv2;
@@ -539,7 +539,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
 #endif */
        else {
                rc = -EOPNOTSUPP;
-               cERROR(1, ("Invalid security type"));
+               cERROR(1, "Invalid security type");
                goto neg_err_exit;
        }
        /* else ... any others ...? */
@@ -551,7 +551,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
        server->maxBuf = min(le32_to_cpu(pSMBr->MaxBufferSize),
                        (__u32) CIFSMaxBufSize + MAX_CIFS_HDR_SIZE);
        server->max_rw = le32_to_cpu(pSMBr->MaxRawSize);
-       cFYI(DBG2, ("Max buf = %d", ses->server->maxBuf));
+       cFYI(DBG2, "Max buf = %d", ses->server->maxBuf);
        GETU32(ses->server->sessid) = le32_to_cpu(pSMBr->SessionKey);
        server->capabilities = le32_to_cpu(pSMBr->Capabilities);
        server->timeAdj = (int)(__s16)le16_to_cpu(pSMBr->ServerTimeZone);
@@ -582,7 +582,7 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        if (memcmp(server->server_GUID,
                                   pSMBr->u.extended_response.
                                   GUID, 16) != 0) {
-                               cFYI(1, ("server UID changed"));
+                               cFYI(1, "server UID changed");
                                memcpy(server->server_GUID,
                                        pSMBr->u.extended_response.GUID,
                                        16);
@@ -597,13 +597,19 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
                        server->secType = RawNTLMSSP;
                } else {
                        rc = decode_negTokenInit(pSMBr->u.extended_response.
-                                                SecurityBlob,
-                                                count - 16,
-                                                &server->secType);
+                                                SecurityBlob, count - 16,
+                                                server);
                        if (rc == 1)
                                rc = 0;
                        else
                                rc = -EINVAL;
+
+                       if (server->sec_kerberos || server->sec_mskerberos)
+                               server->secType = Kerberos;
+                       else if (server->sec_ntlmssp)
+                               server->secType = RawNTLMSSP;
+                       else
+                               rc = -EOPNOTSUPP;
                }
        } else
                server->capabilities &= ~CAP_EXTENDED_SECURITY;
@@ -614,22 +620,21 @@ signing_check:
        if ((secFlags & CIFSSEC_MAY_SIGN) == 0) {
                /* MUST_SIGN already includes the MAY_SIGN FLAG
                   so if this is zero it means that signing is disabled */
-               cFYI(1, ("Signing disabled"));
+               cFYI(1, "Signing disabled");
                if (server->secMode & SECMODE_SIGN_REQUIRED) {
-                       cERROR(1, ("Server requires "
+                       cERROR(1, "Server requires "
                                   "packet signing to be enabled in "
-                                  "/proc/fs/cifs/SecurityFlags."));
+                                  "/proc/fs/cifs/SecurityFlags.");
                        rc = -EOPNOTSUPP;
                }
                server->secMode &=
                        ~(SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED);
        } else if ((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) {
                /* signing required */
-               cFYI(1, ("Must sign - secFlags 0x%x", secFlags));
+               cFYI(1, "Must sign - secFlags 0x%x", secFlags);
                if ((server->secMode &
                        (SECMODE_SIGN_ENABLED | SECMODE_SIGN_REQUIRED)) == 0) {
-                       cERROR(1,
-                               ("signing required but server lacks support"));
+                       cERROR(1, "signing required but server lacks support");
                        rc = -EOPNOTSUPP;
                } else
                        server->secMode |= SECMODE_SIGN_REQUIRED;
@@ -643,7 +648,7 @@ signing_check:
 neg_err_exit:
        cifs_buf_release(pSMB);
 
-       cFYI(1, ("negprot rc %d", rc));
+       cFYI(1, "negprot rc %d", rc);
        return rc;
 }
 
@@ -653,7 +658,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
        struct smb_hdr *smb_buffer;
        int rc = 0;
 
-       cFYI(1, ("In tree disconnect"));
+       cFYI(1, "In tree disconnect");
 
        /* BB: do we need to check this? These should never be NULL. */
        if ((tcon->ses == NULL) || (tcon->ses->server == NULL))
@@ -675,7 +680,7 @@ CIFSSMBTDis(const int xid, struct cifsTconInfo *tcon)
 
        rc = SendReceiveNoRsp(xid, tcon->ses, smb_buffer, 0);
        if (rc)
-               cFYI(1, ("Tree disconnect failed %d", rc));
+               cFYI(1, "Tree disconnect failed %d", rc);
 
        /* No need to return error on this operation if tid invalidated and
           closed on server already e.g. due to tcp session crashing */
@@ -691,7 +696,7 @@ CIFSSMBLogoff(const int xid, struct cifsSesInfo *ses)
        LOGOFF_ANDX_REQ *pSMB;
        int rc = 0;
 
-       cFYI(1, ("In SMBLogoff for session disconnect"));
+       cFYI(1, "In SMBLogoff for session disconnect");
 
        /*
         * BB: do we need to check validity of ses and server? They should
@@ -744,7 +749,7 @@ CIFSPOSIXDelFile(const int xid, struct cifsTconInfo *tcon, const char *fileName,
        int bytes_returned = 0;
        __u16 params, param_offset, offset, byte_count;
 
-       cFYI(1, ("In POSIX delete"));
+       cFYI(1, "In POSIX delete");
 PsxDelete:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -796,7 +801,7 @@ PsxDelete:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("Posix delete returned %d", rc));
+               cFYI(1, "Posix delete returned %d", rc);
        cifs_buf_release(pSMB);
 
        cifs_stats_inc(&tcon->num_deletes);
@@ -843,7 +848,7 @@ DelFileRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_deletes);
        if (rc)
-               cFYI(1, ("Error in RMFile = %d", rc));
+               cFYI(1, "Error in RMFile = %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -862,7 +867,7 @@ CIFSSMBRmDir(const int xid, struct cifsTconInfo *tcon, const char *dirName,
        int bytes_returned;
        int name_len;
 
-       cFYI(1, ("In CIFSSMBRmDir"));
+       cFYI(1, "In CIFSSMBRmDir");
 RmDirRetry:
        rc = smb_init(SMB_COM_DELETE_DIRECTORY, 0, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -887,7 +892,7 @@ RmDirRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_rmdirs);
        if (rc)
-               cFYI(1, ("Error in RMDir = %d", rc));
+               cFYI(1, "Error in RMDir = %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -905,7 +910,7 @@ CIFSSMBMkDir(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned;
        int name_len;
 
-       cFYI(1, ("In CIFSSMBMkDir"));
+       cFYI(1, "In CIFSSMBMkDir");
 MkDirRetry:
        rc = smb_init(SMB_COM_CREATE_DIRECTORY, 0, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -930,7 +935,7 @@ MkDirRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_mkdirs);
        if (rc)
-               cFYI(1, ("Error in Mkdir = %d", rc));
+               cFYI(1, "Error in Mkdir = %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -953,7 +958,7 @@ CIFSPOSIXCreate(const int xid, struct cifsTconInfo *tcon, __u32 posix_flags,
        OPEN_PSX_REQ *pdata;
        OPEN_PSX_RSP *psx_rsp;
 
-       cFYI(1, ("In POSIX Create"));
+       cFYI(1, "In POSIX Create");
 PsxCreat:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -1007,11 +1012,11 @@ PsxCreat:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Posix create returned %d", rc));
+               cFYI(1, "Posix create returned %d", rc);
                goto psx_create_err;
        }
 
-       cFYI(1, ("copying inode info"));
+       cFYI(1, "copying inode info");
        rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
        if (rc || (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP))) {
@@ -1033,11 +1038,11 @@ PsxCreat:
        /* check to make sure response data is there */
        if (psx_rsp->ReturnedLevel != cpu_to_le16(SMB_QUERY_FILE_UNIX_BASIC)) {
                pRetData->Type = cpu_to_le32(-1); /* unknown */
-               cFYI(DBG2, ("unknown type"));
+               cFYI(DBG2, "unknown type");
        } else {
                if (pSMBr->ByteCount < sizeof(OPEN_PSX_RSP)
                                        + sizeof(FILE_UNIX_BASIC_INFO)) {
-                       cERROR(1, ("Open response data too small"));
+                       cERROR(1, "Open response data too small");
                        pRetData->Type = cpu_to_le32(-1);
                        goto psx_create_err;
                }
@@ -1084,7 +1089,7 @@ static __u16 convert_disposition(int disposition)
                        ofun = SMBOPEN_OCREATE | SMBOPEN_OTRUNC;
                        break;
                default:
-                       cFYI(1, ("unknown disposition %d", disposition));
+                       cFYI(1, "unknown disposition %d", disposition);
                        ofun =  SMBOPEN_OAPPEND; /* regular open */
        }
        return ofun;
@@ -1175,7 +1180,7 @@ OldOpenRetry:
                        (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP);
        cifs_stats_inc(&tcon->num_opens);
        if (rc) {
-               cFYI(1, ("Error in Open = %d", rc));
+               cFYI(1, "Error in Open = %d", rc);
        } else {
        /* BB verify if wct == 15 */
 
@@ -1288,7 +1293,7 @@ openRetry:
                        (struct smb_hdr *)pSMBr, &bytes_returned, CIFS_LONG_OP);
        cifs_stats_inc(&tcon->num_opens);
        if (rc) {
-               cFYI(1, ("Error in Open = %d", rc));
+               cFYI(1, "Error in Open = %d", rc);
        } else {
                *pOplock = pSMBr->OplockLevel; /* 1 byte no need to le_to_cpu */
                *netfid = pSMBr->Fid;   /* cifs fid stays in le */
@@ -1326,7 +1331,7 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
        int resp_buf_type = 0;
        struct kvec iov[1];
 
-       cFYI(1, ("Reading %d bytes on fid %d", count, netfid));
+       cFYI(1, "Reading %d bytes on fid %d", count, netfid);
        if (tcon->ses->capabilities & CAP_LARGE_FILES)
                wct = 12;
        else {
@@ -1371,7 +1376,7 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
        cifs_stats_inc(&tcon->num_reads);
        pSMBr = (READ_RSP *)iov[0].iov_base;
        if (rc) {
-               cERROR(1, ("Send error in read = %d", rc));
+               cERROR(1, "Send error in read = %d", rc);
        } else {
                int data_length = le16_to_cpu(pSMBr->DataLengthHigh);
                data_length = data_length << 16;
@@ -1381,15 +1386,15 @@ CIFSSMBRead(const int xid, struct cifsTconInfo *tcon, const int netfid,
                /*check that DataLength would not go beyond end of SMB */
                if ((data_length > CIFSMaxBufSize)
                                || (data_length > count)) {
-                       cFYI(1, ("bad length %d for count %d",
-                                data_length, count));
+                       cFYI(1, "bad length %d for count %d",
+                                data_length, count);
                        rc = -EIO;
                        *nbytes = 0;
                } else {
                        pReadData = (char *) (&pSMBr->hdr.Protocol) +
                                        le16_to_cpu(pSMBr->DataOffset);
 /*                     if (rc = copy_to_user(buf, pReadData, data_length)) {
-                               cERROR(1,("Faulting on read rc = %d",rc));
+                               cERROR(1, "Faulting on read rc = %d",rc);
                                rc = -EFAULT;
                        }*/ /* can not use copy_to_user when using page cache*/
                        if (*buf)
@@ -1433,7 +1438,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
 
        *nbytes = 0;
 
-       /* cFYI(1, ("write at %lld %d bytes", offset, count));*/
+       /* cFYI(1, "write at %lld %d bytes", offset, count);*/
        if (tcon->ses == NULL)
                return -ECONNABORTED;
 
@@ -1514,7 +1519,7 @@ CIFSSMBWrite(const int xid, struct cifsTconInfo *tcon,
                         (struct smb_hdr *) pSMBr, &bytes_returned, long_op);
        cifs_stats_inc(&tcon->num_writes);
        if (rc) {
-               cFYI(1, ("Send error in write = %d", rc));
+               cFYI(1, "Send error in write = %d", rc);
        } else {
                *nbytes = le16_to_cpu(pSMBr->CountHigh);
                *nbytes = (*nbytes) << 16;
@@ -1551,7 +1556,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
 
        *nbytes = 0;
 
-       cFYI(1, ("write2 at %lld %d bytes", (long long)offset, count));
+       cFYI(1, "write2 at %lld %d bytes", (long long)offset, count);
 
        if (tcon->ses->capabilities & CAP_LARGE_FILES) {
                wct = 14;
@@ -1606,7 +1611,7 @@ CIFSSMBWrite2(const int xid, struct cifsTconInfo *tcon,
                          long_op);
        cifs_stats_inc(&tcon->num_writes);
        if (rc) {
-               cFYI(1, ("Send error Write2 = %d", rc));
+               cFYI(1, "Send error Write2 = %d", rc);
        } else if (resp_buf_type == 0) {
                /* presumably this can not happen, but best to be safe */
                rc = -EIO;
@@ -1651,7 +1656,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
        int timeout = 0;
        __u16 count;
 
-       cFYI(1, ("CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock));
+       cFYI(1, "CIFSSMBLock timeout %d numLock %d", (int)waitFlag, numLock);
        rc = small_smb_init(SMB_COM_LOCKING_ANDX, 8, tcon, (void **) &pSMB);
 
        if (rc)
@@ -1699,7 +1704,7 @@ CIFSSMBLock(const int xid, struct cifsTconInfo *tcon,
        }
        cifs_stats_inc(&tcon->num_locks);
        if (rc)
-               cFYI(1, ("Send error in Lock = %d", rc));
+               cFYI(1, "Send error in Lock = %d", rc);
 
        /* Note: On -EAGAIN error only caller can retry on handle based calls
        since file handle passed in no longer valid */
@@ -1722,7 +1727,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
        __u16 params, param_offset, offset, byte_count, count;
        struct kvec iov[1];
 
-       cFYI(1, ("Posix Lock"));
+       cFYI(1, "Posix Lock");
 
        if (pLockData == NULL)
                return -EINVAL;
@@ -1792,7 +1797,7 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon,
        }
 
        if (rc) {
-               cFYI(1, ("Send error in Posix Lock = %d", rc));
+               cFYI(1, "Send error in Posix Lock = %d", rc);
        } else if (get_flag) {
                /* lock structure can be returned on get */
                __u16 data_offset;
@@ -1849,7 +1854,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
 {
        int rc = 0;
        CLOSE_REQ *pSMB = NULL;
-       cFYI(1, ("In CIFSSMBClose"));
+       cFYI(1, "In CIFSSMBClose");
 
 /* do not retry on dead session on close */
        rc = small_smb_init(SMB_COM_CLOSE, 3, tcon, (void **) &pSMB);
@@ -1866,7 +1871,7 @@ CIFSSMBClose(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
        if (rc) {
                if (rc != -EINTR) {
                        /* EINTR is expected when user ctl-c to kill app */
-                       cERROR(1, ("Send error in Close = %d", rc));
+                       cERROR(1, "Send error in Close = %d", rc);
                }
        }
 
@@ -1882,7 +1887,7 @@ CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
 {
        int rc = 0;
        FLUSH_REQ *pSMB = NULL;
-       cFYI(1, ("In CIFSSMBFlush"));
+       cFYI(1, "In CIFSSMBFlush");
 
        rc = small_smb_init(SMB_COM_FLUSH, 1, tcon, (void **) &pSMB);
        if (rc)
@@ -1893,7 +1898,7 @@ CIFSSMBFlush(const int xid, struct cifsTconInfo *tcon, int smb_file_id)
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        cifs_stats_inc(&tcon->num_flushes);
        if (rc)
-               cERROR(1, ("Send error in Flush = %d", rc));
+               cERROR(1, "Send error in Flush = %d", rc);
 
        return rc;
 }
@@ -1910,7 +1915,7 @@ CIFSSMBRename(const int xid, struct cifsTconInfo *tcon,
        int name_len, name_len2;
        __u16 count;
 
-       cFYI(1, ("In CIFSSMBRename"));
+       cFYI(1, "In CIFSSMBRename");
 renameRetry:
        rc = smb_init(SMB_COM_RENAME, 1, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -1956,7 +1961,7 @@ renameRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_renames);
        if (rc)
-               cFYI(1, ("Send error in rename = %d", rc));
+               cFYI(1, "Send error in rename = %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -1980,7 +1985,7 @@ int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon,
        int len_of_str;
        __u16 params, param_offset, offset, count, byte_count;
 
-       cFYI(1, ("Rename to File by handle"));
+       cFYI(1, "Rename to File by handle");
        rc = smb_init(SMB_COM_TRANSACTION2, 15, pTcon, (void **) &pSMB,
                        (void **) &pSMBr);
        if (rc)
@@ -2035,7 +2040,7 @@ int CIFSSMBRenameOpenFile(const int xid, struct cifsTconInfo *pTcon,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&pTcon->num_t2renames);
        if (rc)
-               cFYI(1, ("Send error in Rename (by file handle) = %d", rc));
+               cFYI(1, "Send error in Rename (by file handle) = %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -2057,7 +2062,7 @@ CIFSSMBCopy(const int xid, struct cifsTconInfo *tcon, const char *fromName,
        int name_len, name_len2;
        __u16 count;
 
-       cFYI(1, ("In CIFSSMBCopy"));
+       cFYI(1, "In CIFSSMBCopy");
 copyRetry:
        rc = smb_init(SMB_COM_COPY, 1, tcon, (void **) &pSMB,
                        (void **) &pSMBr);
@@ -2102,8 +2107,8 @@ copyRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in copy = %d with %d files copied",
-                       rc, le16_to_cpu(pSMBr->CopyCount)));
+               cFYI(1, "Send error in copy = %d with %d files copied",
+                       rc, le16_to_cpu(pSMBr->CopyCount));
        }
        cifs_buf_release(pSMB);
 
@@ -2127,7 +2132,7 @@ CIFSUnixCreateSymLink(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned = 0;
        __u16 params, param_offset, offset, byte_count;
 
-       cFYI(1, ("In Symlink Unix style"));
+       cFYI(1, "In Symlink Unix style");
 createSymLinkRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -2192,7 +2197,7 @@ createSymLinkRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_symlinks);
        if (rc)
-               cFYI(1, ("Send error in SetPathInfo create symlink = %d", rc));
+               cFYI(1, "Send error in SetPathInfo create symlink = %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -2216,7 +2221,7 @@ CIFSUnixCreateHardLink(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned = 0;
        __u16 params, param_offset, offset, byte_count;
 
-       cFYI(1, ("In Create Hard link Unix style"));
+       cFYI(1, "In Create Hard link Unix style");
 createHardLinkRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -2278,7 +2283,7 @@ createHardLinkRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_hardlinks);
        if (rc)
-               cFYI(1, ("Send error in SetPathInfo (hard link) = %d", rc));
+               cFYI(1, "Send error in SetPathInfo (hard link) = %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -2299,7 +2304,7 @@ CIFSCreateHardLink(const int xid, struct cifsTconInfo *tcon,
        int name_len, name_len2;
        __u16 count;
 
-       cFYI(1, ("In CIFSCreateHardLink"));
+       cFYI(1, "In CIFSCreateHardLink");
 winCreateHardLinkRetry:
 
        rc = smb_init(SMB_COM_NT_RENAME, 4, tcon, (void **) &pSMB,
@@ -2350,7 +2355,7 @@ winCreateHardLinkRetry:
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_hardlinks);
        if (rc)
-               cFYI(1, ("Send error in hard link (NT rename) = %d", rc));
+               cFYI(1, "Send error in hard link (NT rename) = %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -2373,7 +2378,7 @@ CIFSSMBUnixQuerySymLink(const int xid, struct cifsTconInfo *tcon,
        __u16 params, byte_count;
        char *data_start;
 
-       cFYI(1, ("In QPathSymLinkInfo (Unix) for path %s", searchName));
+       cFYI(1, "In QPathSymLinkInfo (Unix) for path %s", searchName);
 
 querySymLinkRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -2420,7 +2425,7 @@ querySymLinkRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QuerySymLinkInfo = %d", rc));
+               cFYI(1, "Send error in QuerySymLinkInfo = %d", rc);
        } else {
                /* decode response */
 
@@ -2521,21 +2526,21 @@ validate_ntransact(char *buf, char **ppparm, char **ppdata,
 
        /* should we also check that parm and data areas do not overlap? */
        if (*ppparm > end_of_smb) {
-               cFYI(1, ("parms start after end of smb"));
+               cFYI(1, "parms start after end of smb");
                return -EINVAL;
        } else if (parm_count + *ppparm > end_of_smb) {
-               cFYI(1, ("parm end after end of smb"));
+               cFYI(1, "parm end after end of smb");
                return -EINVAL;
        } else if (*ppdata > end_of_smb) {
-               cFYI(1, ("data starts after end of smb"));
+               cFYI(1, "data starts after end of smb");
                return -EINVAL;
        } else if (data_count + *ppdata > end_of_smb) {
-               cFYI(1, ("data %p + count %d (%p) ends after end of smb %p start %p",
+               cFYI(1, "data %p + count %d (%p) past smb end %p start %p",
                        *ppdata, data_count, (data_count + *ppdata),
-                       end_of_smb, pSMBr));
+                       end_of_smb, pSMBr);
                return -EINVAL;
        } else if (parm_count + data_count > pSMBr->ByteCount) {
-               cFYI(1, ("parm count and data count larger than SMB"));
+               cFYI(1, "parm count and data count larger than SMB");
                return -EINVAL;
        }
        *pdatalen = data_count;
@@ -2554,7 +2559,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
        struct smb_com_transaction_ioctl_req *pSMB;
        struct smb_com_transaction_ioctl_rsp *pSMBr;
 
-       cFYI(1, ("In Windows reparse style QueryLink for path %s", searchName));
+       cFYI(1, "In Windows reparse style QueryLink for path %s", searchName);
        rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
        if (rc)
@@ -2583,7 +2588,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QueryReparseLinkInfo = %d", rc));
+               cFYI(1, "Send error in QueryReparseLinkInfo = %d", rc);
        } else {                /* decode response */
                __u32 data_offset = le32_to_cpu(pSMBr->DataOffset);
                __u32 data_count = le32_to_cpu(pSMBr->DataCount);
@@ -2607,7 +2612,7 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
                        if ((reparse_buf->LinkNamesBuf +
                                reparse_buf->TargetNameOffset +
                                reparse_buf->TargetNameLen) > end_of_smb) {
-                               cFYI(1, ("reparse buf beyond SMB"));
+                               cFYI(1, "reparse buf beyond SMB");
                                rc = -EIO;
                                goto qreparse_out;
                        }
@@ -2628,12 +2633,12 @@ CIFSSMBQueryReparseLinkInfo(const int xid, struct cifsTconInfo *tcon,
                        }
                } else {
                        rc = -EIO;
-                       cFYI(1, ("Invalid return data count on "
-                                "get reparse info ioctl"));
+                       cFYI(1, "Invalid return data count on "
+                                "get reparse info ioctl");
                }
                symlinkinfo[buflen] = 0; /* just in case so the caller
                                        does not go off the end of the buffer */
-               cFYI(1, ("readlink result - %s", symlinkinfo));
+               cFYI(1, "readlink result - %s", symlinkinfo);
        }
 
 qreparse_out:
@@ -2656,7 +2661,7 @@ static void cifs_convert_ace(posix_acl_xattr_entry *ace,
        ace->e_perm = cpu_to_le16(cifs_ace->cifs_e_perm);
        ace->e_tag  = cpu_to_le16(cifs_ace->cifs_e_tag);
        ace->e_id   = cpu_to_le32(le64_to_cpu(cifs_ace->cifs_uid));
-       /* cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id)); */
+       /* cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id); */
 
        return;
 }
@@ -2682,8 +2687,8 @@ static int cifs_copy_posix_acl(char *trgt, char *src, const int buflen,
                size += sizeof(struct cifs_posix_ace) * count;
                /* check if we would go beyond end of SMB */
                if (size_of_data_area < size) {
-                       cFYI(1, ("bad CIFS POSIX ACL size %d vs. %d",
-                               size_of_data_area, size));
+                       cFYI(1, "bad CIFS POSIX ACL size %d vs. %d",
+                               size_of_data_area, size);
                        return -EINVAL;
                }
        } else if (acl_type & ACL_TYPE_DEFAULT) {
@@ -2730,7 +2735,7 @@ static __u16 convert_ace_to_cifs_ace(struct cifs_posix_ace *cifs_ace,
                cifs_ace->cifs_uid = cpu_to_le64(-1);
        } else
                cifs_ace->cifs_uid = cpu_to_le64(le32_to_cpu(local_ace->e_id));
-       /*cFYI(1,("perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id));*/
+       /*cFYI(1, "perm %d tag %d id %d",ace->e_perm,ace->e_tag,ace->e_id);*/
        return rc;
 }
 
@@ -2748,12 +2753,12 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL,
                return 0;
 
        count = posix_acl_xattr_count((size_t)buflen);
-       cFYI(1, ("setting acl with %d entries from buf of length %d and "
+       cFYI(1, "setting acl with %d entries from buf of length %d and "
                "version of %d",
-               count, buflen, le32_to_cpu(local_acl->a_version)));
+               count, buflen, le32_to_cpu(local_acl->a_version));
        if (le32_to_cpu(local_acl->a_version) != 2) {
-               cFYI(1, ("unknown POSIX ACL version %d",
-                    le32_to_cpu(local_acl->a_version)));
+               cFYI(1, "unknown POSIX ACL version %d",
+                    le32_to_cpu(local_acl->a_version));
                return 0;
        }
        cifs_acl->version = cpu_to_le16(1);
@@ -2762,7 +2767,7 @@ static __u16 ACL_to_cifs_posix(char *parm_data, const char *pACL,
        else if (acl_type == ACL_TYPE_DEFAULT)
                cifs_acl->default_entry_count = cpu_to_le16(count);
        else {
-               cFYI(1, ("unknown ACL type %d", acl_type));
+               cFYI(1, "unknown ACL type %d", acl_type);
                return 0;
        }
        for (i = 0; i < count; i++) {
@@ -2795,7 +2800,7 @@ CIFSSMBGetPosixACL(const int xid, struct cifsTconInfo *tcon,
        int name_len;
        __u16 params, byte_count;
 
-       cFYI(1, ("In GetPosixACL (Unix) for path %s", searchName));
+       cFYI(1, "In GetPosixACL (Unix) for path %s", searchName);
 
 queryAclRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -2847,7 +2852,7 @@ queryAclRetry:
                (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        cifs_stats_inc(&tcon->num_acl_get);
        if (rc) {
-               cFYI(1, ("Send error in Query POSIX ACL = %d", rc));
+               cFYI(1, "Send error in Query POSIX ACL = %d", rc);
        } else {
                /* decode response */
 
@@ -2884,7 +2889,7 @@ CIFSSMBSetPosixACL(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned = 0;
        __u16 params, byte_count, data_count, param_offset, offset;
 
-       cFYI(1, ("In SetPosixACL (Unix) for path %s", fileName));
+       cFYI(1, "In SetPosixACL (Unix) for path %s", fileName);
 setAclRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -2939,7 +2944,7 @@ setAclRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("Set POSIX ACL returned %d", rc));
+               cFYI(1, "Set POSIX ACL returned %d", rc);
 
 setACLerrorExit:
        cifs_buf_release(pSMB);
@@ -2959,7 +2964,7 @@ CIFSGetExtAttr(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned;
        __u16 params, byte_count;
 
-       cFYI(1, ("In GetExtAttr"));
+       cFYI(1, "In GetExtAttr");
        if (tcon == NULL)
                return -ENODEV;
 
@@ -2998,7 +3003,7 @@ GetExtAttrRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("error %d in GetExtAttr", rc));
+               cFYI(1, "error %d in GetExtAttr", rc);
        } else {
                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
@@ -3013,7 +3018,7 @@ GetExtAttrRetry:
                        struct file_chattr_info *pfinfo;
                        /* BB Do we need a cast or hash here ? */
                        if (count != 16) {
-                               cFYI(1, ("Illegal size ret in GetExtAttr"));
+                               cFYI(1, "Illegal size ret in GetExtAttr");
                                rc = -EIO;
                                goto GetExtAttrOut;
                        }
@@ -3043,7 +3048,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
        QUERY_SEC_DESC_REQ *pSMB;
        struct kvec iov[1];
 
-       cFYI(1, ("GetCifsACL"));
+       cFYI(1, "GetCifsACL");
 
        *pbuflen = 0;
        *acl_inf = NULL;
@@ -3068,7 +3073,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
                         CIFS_STD_OP);
        cifs_stats_inc(&tcon->num_acl_get);
        if (rc) {
-               cFYI(1, ("Send error in QuerySecDesc = %d", rc));
+               cFYI(1, "Send error in QuerySecDesc = %d", rc);
        } else {                /* decode response */
                __le32 *parm;
                __u32 parm_len;
@@ -3083,7 +3088,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
                        goto qsec_out;
                pSMBr = (struct smb_com_ntransact_rsp *)iov[0].iov_base;
 
-               cFYI(1, ("smb %p parm %p data %p", pSMBr, parm, *acl_inf));
+               cFYI(1, "smb %p parm %p data %p", pSMBr, parm, *acl_inf);
 
                if (le32_to_cpu(pSMBr->ParameterCount) != 4) {
                        rc = -EIO;      /* bad smb */
@@ -3095,8 +3100,8 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
 
                acl_len = le32_to_cpu(*parm);
                if (acl_len != *pbuflen) {
-                       cERROR(1, ("acl length %d does not match %d",
-                                  acl_len, *pbuflen));
+                       cERROR(1, "acl length %d does not match %d",
+                                  acl_len, *pbuflen);
                        if (*pbuflen > acl_len)
                                *pbuflen = acl_len;
                }
@@ -3105,7 +3110,7 @@ CIFSSMBGetCIFSACL(const int xid, struct cifsTconInfo *tcon, __u16 fid,
                   header followed by the smallest SID */
                if ((*pbuflen < sizeof(struct cifs_ntsd) + 8) ||
                    (*pbuflen >= 64 * 1024)) {
-                       cERROR(1, ("bad acl length %d", *pbuflen));
+                       cERROR(1, "bad acl length %d", *pbuflen);
                        rc = -EINVAL;
                        *pbuflen = 0;
                } else {
@@ -3179,9 +3184,9 @@ setCifsAclRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                (struct smb_hdr *) pSMBr, &bytes_returned, 0);
 
-       cFYI(1, ("SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc));
+       cFYI(1, "SetCIFSACL bytes_returned: %d, rc: %d", bytes_returned, rc);
        if (rc)
-               cFYI(1, ("Set CIFS ACL returned %d", rc));
+               cFYI(1, "Set CIFS ACL returned %d", rc);
        cifs_buf_release(pSMB);
 
        if (rc == -EAGAIN)
@@ -3205,7 +3210,7 @@ int SMBQueryInformation(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned;
        int name_len;
 
-       cFYI(1, ("In SMBQPath path %s", searchName));
+       cFYI(1, "In SMBQPath path %s", searchName);
 QInfRetry:
        rc = smb_init(SMB_COM_QUERY_INFORMATION, 0, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -3231,7 +3236,7 @@ QInfRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QueryInfo = %d", rc));
+               cFYI(1, "Send error in QueryInfo = %d", rc);
        } else if (pFinfo) {
                struct timespec ts;
                __u32 time = le32_to_cpu(pSMBr->last_write_time);
@@ -3305,7 +3310,7 @@ QFileInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QPathInfo = %d", rc));
+               cFYI(1, "Send error in QPathInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -3343,7 +3348,7 @@ CIFSSMBQPathInfo(const int xid, struct cifsTconInfo *tcon,
        int name_len;
        __u16 params, byte_count;
 
-/* cFYI(1, ("In QPathInfo path %s", searchName)); */
+/* cFYI(1, "In QPathInfo path %s", searchName); */
 QPathInfoRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -3393,7 +3398,7 @@ QPathInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QPathInfo = %d", rc));
+               cFYI(1, "Send error in QPathInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -3473,14 +3478,14 @@ UnixQFileInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QPathInfo = %d", rc));
+               cFYI(1, "Send error in QPathInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
                if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) {
-                       cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n"
+                       cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
                                   "Unix Extensions can be disabled on mount "
-                                  "by specifying the nosfu mount option."));
+                                  "by specifying the nosfu mount option.");
                        rc = -EIO;      /* bad smb */
                } else {
                        __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -3512,7 +3517,7 @@ CIFSSMBUnixQPathInfo(const int xid, struct cifsTconInfo *tcon,
        int name_len;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QPathInfo (Unix) the path %s", searchName));
+       cFYI(1, "In QPathInfo (Unix) the path %s", searchName);
 UnixQPathInfoRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -3559,14 +3564,14 @@ UnixQPathInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QPathInfo = %d", rc));
+               cFYI(1, "Send error in QPathInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
                if (rc || (pSMBr->ByteCount < sizeof(FILE_UNIX_BASIC_INFO))) {
-                       cERROR(1, ("Malformed FILE_UNIX_BASIC_INFO response.\n"
+                       cERROR(1, "Malformed FILE_UNIX_BASIC_INFO response.\n"
                                   "Unix Extensions can be disabled on mount "
-                                  "by specifying the nosfu mount option."));
+                                  "by specifying the nosfu mount option.");
                        rc = -EIO;      /* bad smb */
                } else {
                        __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
@@ -3600,7 +3605,7 @@ CIFSFindFirst(const int xid, struct cifsTconInfo *tcon,
        int name_len;
        __u16 params, byte_count;
 
-       cFYI(1, ("In FindFirst for %s", searchName));
+       cFYI(1, "In FindFirst for %s", searchName);
 
 findFirstRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -3677,7 +3682,7 @@ findFirstRetry:
        if (rc) {/* BB add logic to retry regular search if Unix search
                        rejected unexpectedly by server */
                /* BB Add code to handle unsupported level rc */
-               cFYI(1, ("Error in FindFirst = %d", rc));
+               cFYI(1, "Error in FindFirst = %d", rc);
 
                cifs_buf_release(pSMB);
 
@@ -3716,7 +3721,7 @@ findFirstRetry:
                        lnoff = le16_to_cpu(parms->LastNameOffset);
                        if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE <
                              lnoff) {
-                               cERROR(1, ("ignoring corrupt resume name"));
+                               cERROR(1, "ignoring corrupt resume name");
                                psrch_inf->last_entry = NULL;
                                return rc;
                        }
@@ -3744,7 +3749,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned, name_len;
        __u16 params, byte_count;
 
-       cFYI(1, ("In FindNext"));
+       cFYI(1, "In FindNext");
 
        if (psrch_inf->endOfSearch)
                return -ENOENT;
@@ -3808,7 +3813,7 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
                        cifs_buf_release(pSMB);
                        rc = 0; /* search probably was closed at end of search*/
                } else
-                       cFYI(1, ("FindNext returned = %d", rc));
+                       cFYI(1, "FindNext returned = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -3844,15 +3849,15 @@ int CIFSFindNext(const int xid, struct cifsTconInfo *tcon,
                        lnoff = le16_to_cpu(parms->LastNameOffset);
                        if (tcon->ses->server->maxBuf - MAX_CIFS_HDR_SIZE <
                              lnoff) {
-                               cERROR(1, ("ignoring corrupt resume name"));
+                               cERROR(1, "ignoring corrupt resume name");
                                psrch_inf->last_entry = NULL;
                                return rc;
                        } else
                                psrch_inf->last_entry =
                                        psrch_inf->srch_entries_start + lnoff;
 
-/*  cFYI(1,("fnxt2 entries in buf %d index_of_last %d",
-           psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry)); */
+/*  cFYI(1, "fnxt2 entries in buf %d index_of_last %d",
+           psrch_inf->entries_in_buffer, psrch_inf->index_of_last_entry); */
 
                        /* BB fixme add unlock here */
                }
@@ -3877,7 +3882,7 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon,
        int rc = 0;
        FINDCLOSE_REQ *pSMB = NULL;
 
-       cFYI(1, ("In CIFSSMBFindClose"));
+       cFYI(1, "In CIFSSMBFindClose");
        rc = small_smb_init(SMB_COM_FIND_CLOSE2, 1, tcon, (void **)&pSMB);
 
        /* no sense returning error if session restarted
@@ -3891,7 +3896,7 @@ CIFSFindClose(const int xid, struct cifsTconInfo *tcon,
        pSMB->ByteCount = 0;
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        if (rc)
-               cERROR(1, ("Send error in FindClose = %d", rc));
+               cERROR(1, "Send error in FindClose = %d", rc);
 
        cifs_stats_inc(&tcon->num_fclose);
 
@@ -3914,7 +3919,7 @@ CIFSGetSrvInodeNumber(const int xid, struct cifsTconInfo *tcon,
        int name_len, bytes_returned;
        __u16 params, byte_count;
 
-       cFYI(1, ("In GetSrvInodeNum for %s", searchName));
+       cFYI(1, "In GetSrvInodeNum for %s", searchName);
        if (tcon == NULL)
                return -ENODEV;
 
@@ -3964,7 +3969,7 @@ GetInodeNumberRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("error %d in QueryInternalInfo", rc));
+               cFYI(1, "error %d in QueryInternalInfo", rc);
        } else {
                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
@@ -3979,7 +3984,7 @@ GetInodeNumberRetry:
                        struct file_internal_info *pfinfo;
                        /* BB Do we need a cast or hash here ? */
                        if (count < 8) {
-                               cFYI(1, ("Illegal size ret in QryIntrnlInf"));
+                               cFYI(1, "Illegal size ret in QryIntrnlInf");
                                rc = -EIO;
                                goto GetInodeNumOut;
                        }
@@ -4020,16 +4025,16 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
        *num_of_nodes = le16_to_cpu(pSMBr->NumberOfReferrals);
 
        if (*num_of_nodes < 1) {
-               cERROR(1, ("num_referrals: must be at least > 0,"
-                       "but we get num_referrals = %d\n", *num_of_nodes));
+               cERROR(1, "num_referrals: must be at least > 0,"
+                       "but we get num_referrals = %d\n", *num_of_nodes);
                rc = -EINVAL;
                goto parse_DFS_referrals_exit;
        }
 
        ref = (struct dfs_referral_level_3 *) &(pSMBr->referrals);
        if (ref->VersionNumber != cpu_to_le16(3)) {
-               cERROR(1, ("Referrals of V%d version are not supported,"
-                       "should be V3", le16_to_cpu(ref->VersionNumber)));
+               cERROR(1, "Referrals of V%d version are not supported,"
+                       "should be V3", le16_to_cpu(ref->VersionNumber));
                rc = -EINVAL;
                goto parse_DFS_referrals_exit;
        }
@@ -4038,14 +4043,14 @@ parse_DFS_referrals(TRANSACTION2_GET_DFS_REFER_RSP *pSMBr,
        data_end = (char *)(&(pSMBr->PathConsumed)) +
                                le16_to_cpu(pSMBr->t2.DataCount);
 
-       cFYI(1, ("num_referrals: %d dfs flags: 0x%x ... \n",
+       cFYI(1, "num_referrals: %d dfs flags: 0x%x ...\n",
                        *num_of_nodes,
-                       le32_to_cpu(pSMBr->DFSFlags)));
+                       le32_to_cpu(pSMBr->DFSFlags));
 
        *target_nodes = kzalloc(sizeof(struct dfs_info3_param) *
                        *num_of_nodes, GFP_KERNEL);
        if (*target_nodes == NULL) {
-               cERROR(1, ("Failed to allocate buffer for target_nodes\n"));
+               cERROR(1, "Failed to allocate buffer for target_nodes\n");
                rc = -ENOMEM;
                goto parse_DFS_referrals_exit;
        }
@@ -4121,7 +4126,7 @@ CIFSGetDFSRefer(const int xid, struct cifsSesInfo *ses,
        *num_of_nodes = 0;
        *target_nodes = NULL;
 
-       cFYI(1, ("In GetDFSRefer the path %s", searchName));
+       cFYI(1, "In GetDFSRefer the path %s", searchName);
        if (ses == NULL)
                return -ENODEV;
 getDFSRetry:
@@ -4188,7 +4193,7 @@ getDFSRetry:
        rc = SendReceive(xid, ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in GetDFSRefer = %d", rc));
+               cFYI(1, "Send error in GetDFSRefer = %d", rc);
                goto GetDFSRefExit;
        }
        rc = validate_t2((struct smb_t2_rsp *)pSMBr);
@@ -4199,9 +4204,9 @@ getDFSRetry:
                goto GetDFSRefExit;
        }
 
-       cFYI(1, ("Decoding GetDFSRefer response BCC: %d  Offset %d",
+       cFYI(1, "Decoding GetDFSRefer response BCC: %d  Offset %d",
                                pSMBr->ByteCount,
-                               le16_to_cpu(pSMBr->t2.DataOffset)));
+                               le16_to_cpu(pSMBr->t2.DataOffset));
 
        /* parse returned result into more usable form */
        rc = parse_DFS_referrals(pSMBr, num_of_nodes,
@@ -4229,7 +4234,7 @@ SMBOldQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData)
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("OldQFSInfo"));
+       cFYI(1, "OldQFSInfo");
 oldQFSInfoRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                (void **) &pSMBr);
@@ -4262,7 +4267,7 @@ oldQFSInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QFSInfo = %d", rc));
+               cFYI(1, "Send error in QFSInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4270,8 +4275,8 @@ oldQFSInfoRetry:
                        rc = -EIO;      /* bad smb */
                else {
                        __u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-                       cFYI(1, ("qfsinf resp BCC: %d  Offset %d",
-                                pSMBr->ByteCount, data_offset));
+                       cFYI(1, "qfsinf resp BCC: %d  Offset %d",
+                                pSMBr->ByteCount, data_offset);
 
                        response_data = (FILE_SYSTEM_ALLOC_INFO *)
                                (((char *) &pSMBr->hdr.Protocol) + data_offset);
@@ -4283,11 +4288,10 @@ oldQFSInfoRetry:
                               le32_to_cpu(response_data->TotalAllocationUnits);
                        FSData->f_bfree = FSData->f_bavail =
                                le32_to_cpu(response_data->FreeAllocationUnits);
-                       cFYI(1,
-                            ("Blocks: %lld  Free: %lld Block size %ld",
-                             (unsigned long long)FSData->f_blocks,
-                             (unsigned long long)FSData->f_bfree,
-                             FSData->f_bsize));
+                       cFYI(1, "Blocks: %lld  Free: %lld Block size %ld",
+                            (unsigned long long)FSData->f_blocks,
+                            (unsigned long long)FSData->f_bfree,
+                            FSData->f_bsize);
                }
        }
        cifs_buf_release(pSMB);
@@ -4309,7 +4313,7 @@ CIFSSMBQFSInfo(const int xid, struct cifsTconInfo *tcon, struct kstatfs *FSData)
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QFSInfo"));
+       cFYI(1, "In QFSInfo");
 QFSInfoRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4342,7 +4346,7 @@ QFSInfoRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QFSInfo = %d", rc));
+               cFYI(1, "Send error in QFSInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4363,11 +4367,10 @@ QFSInfoRetry:
                            le64_to_cpu(response_data->TotalAllocationUnits);
                        FSData->f_bfree = FSData->f_bavail =
                            le64_to_cpu(response_data->FreeAllocationUnits);
-                       cFYI(1,
-                            ("Blocks: %lld  Free: %lld Block size %ld",
-                             (unsigned long long)FSData->f_blocks,
-                             (unsigned long long)FSData->f_bfree,
-                             FSData->f_bsize));
+                       cFYI(1, "Blocks: %lld  Free: %lld Block size %ld",
+                            (unsigned long long)FSData->f_blocks,
+                            (unsigned long long)FSData->f_bfree,
+                            FSData->f_bsize);
                }
        }
        cifs_buf_release(pSMB);
@@ -4389,7 +4392,7 @@ CIFSSMBQFSAttributeInfo(const int xid, struct cifsTconInfo *tcon)
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QFSAttributeInfo"));
+       cFYI(1, "In QFSAttributeInfo");
 QFSAttributeRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4423,7 +4426,7 @@ QFSAttributeRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cERROR(1, ("Send error in QFSAttributeInfo = %d", rc));
+               cERROR(1, "Send error in QFSAttributeInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4459,7 +4462,7 @@ CIFSSMBQFSDeviceInfo(const int xid, struct cifsTconInfo *tcon)
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QFSDeviceInfo"));
+       cFYI(1, "In QFSDeviceInfo");
 QFSDeviceRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4494,7 +4497,7 @@ QFSDeviceRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QFSDeviceInfo = %d", rc));
+               cFYI(1, "Send error in QFSDeviceInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4529,7 +4532,7 @@ CIFSSMBQFSUnixInfo(const int xid, struct cifsTconInfo *tcon)
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QFSUnixInfo"));
+       cFYI(1, "In QFSUnixInfo");
 QFSUnixRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4563,7 +4566,7 @@ QFSUnixRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cERROR(1, ("Send error in QFSUnixInfo = %d", rc));
+               cERROR(1, "Send error in QFSUnixInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4598,7 +4601,7 @@ CIFSSMBSetFSUnixInfo(const int xid, struct cifsTconInfo *tcon, __u64 cap)
        int bytes_returned = 0;
        __u16 params, param_offset, offset, byte_count;
 
-       cFYI(1, ("In SETFSUnixInfo"));
+       cFYI(1, "In SETFSUnixInfo");
 SETFSUnixRetry:
        /* BB switch to small buf init to save memory */
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -4646,7 +4649,7 @@ SETFSUnixRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cERROR(1, ("Send error in SETFSUnixInfo = %d", rc));
+               cERROR(1, "Send error in SETFSUnixInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
                if (rc)
@@ -4674,7 +4677,7 @@ CIFSSMBQFSPosixInfo(const int xid, struct cifsTconInfo *tcon,
        int bytes_returned = 0;
        __u16 params, byte_count;
 
-       cFYI(1, ("In QFSPosixInfo"));
+       cFYI(1, "In QFSPosixInfo");
 QFSPosixRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4708,7 +4711,7 @@ QFSPosixRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QFSUnixInfo = %d", rc));
+               cFYI(1, "Send error in QFSUnixInfo = %d", rc);
        } else {                /* decode response */
                rc = validate_t2((struct smb_t2_rsp *)pSMBr);
 
@@ -4768,7 +4771,7 @@ CIFSSMBSetEOF(const int xid, struct cifsTconInfo *tcon, const char *fileName,
        int bytes_returned = 0;
        __u16 params, byte_count, data_count, param_offset, offset;
 
-       cFYI(1, ("In SetEOF"));
+       cFYI(1, "In SetEOF");
 SetEOFRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -4834,7 +4837,7 @@ SetEOFRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("SetPathInfo (file size) returned %d", rc));
+               cFYI(1, "SetPathInfo (file size) returned %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -4854,8 +4857,8 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
        int rc = 0;
        __u16 params, param_offset, offset, byte_count, count;
 
-       cFYI(1, ("SetFileSize (via SetFileInfo) %lld",
-                       (long long)size));
+       cFYI(1, "SetFileSize (via SetFileInfo) %lld",
+                       (long long)size);
        rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);
 
        if (rc)
@@ -4914,9 +4917,7 @@ CIFSSMBSetFileSize(const int xid, struct cifsTconInfo *tcon, __u64 size,
        pSMB->ByteCount = cpu_to_le16(byte_count);
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        if (rc) {
-               cFYI(1,
-                    ("Send error in SetFileInfo (SetFileSize) = %d",
-                     rc));
+               cFYI(1, "Send error in SetFileInfo (SetFileSize) = %d", rc);
        }
 
        /* Note: On -EAGAIN error only caller can retry on handle based calls
@@ -4940,7 +4941,7 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon,
        int rc = 0;
        __u16 params, param_offset, offset, byte_count, count;
 
-       cFYI(1, ("Set Times (via SetFileInfo)"));
+       cFYI(1, "Set Times (via SetFileInfo)");
        rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);
 
        if (rc)
@@ -4985,7 +4986,7 @@ CIFSSMBSetFileInfo(const int xid, struct cifsTconInfo *tcon,
        memcpy(data_offset, data, sizeof(FILE_BASIC_INFO));
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        if (rc)
-               cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc));
+               cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
 
        /* Note: On -EAGAIN error only caller can retry on handle based calls
                since file handle passed in no longer valid */
@@ -5002,7 +5003,7 @@ CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon,
        int rc = 0;
        __u16 params, param_offset, offset, byte_count, count;
 
-       cFYI(1, ("Set File Disposition (via SetFileInfo)"));
+       cFYI(1, "Set File Disposition (via SetFileInfo)");
        rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);
 
        if (rc)
@@ -5044,7 +5045,7 @@ CIFSSMBSetFileDisposition(const int xid, struct cifsTconInfo *tcon,
        *data_offset = delete_file ? 1 : 0;
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        if (rc)
-               cFYI(1, ("Send error in SetFileDisposition = %d", rc));
+               cFYI(1, "Send error in SetFileDisposition = %d", rc);
 
        return rc;
 }
@@ -5062,7 +5063,7 @@ CIFSSMBSetPathInfo(const int xid, struct cifsTconInfo *tcon,
        char *data_offset;
        __u16 params, param_offset, offset, byte_count, count;
 
-       cFYI(1, ("In SetTimes"));
+       cFYI(1, "In SetTimes");
 
 SetTimesRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
@@ -5118,7 +5119,7 @@ SetTimesRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("SetPathInfo (times) returned %d", rc));
+               cFYI(1, "SetPathInfo (times) returned %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -5143,7 +5144,7 @@ CIFSSMBSetAttrLegacy(int xid, struct cifsTconInfo *tcon, char *fileName,
        int bytes_returned;
        int name_len;
 
-       cFYI(1, ("In SetAttrLegacy"));
+       cFYI(1, "In SetAttrLegacy");
 
 SetAttrLgcyRetry:
        rc = smb_init(SMB_COM_SETATTR, 8, tcon, (void **) &pSMB,
@@ -5169,7 +5170,7 @@ SetAttrLgcyRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("Error in LegacySetAttr = %d", rc));
+               cFYI(1, "Error in LegacySetAttr = %d", rc);
 
        cifs_buf_release(pSMB);
 
@@ -5231,7 +5232,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon,
        int rc = 0;
        u16 params, param_offset, offset, byte_count, count;
 
-       cFYI(1, ("Set Unix Info (via SetFileInfo)"));
+       cFYI(1, "Set Unix Info (via SetFileInfo)");
        rc = small_smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB);
 
        if (rc)
@@ -5276,7 +5277,7 @@ CIFSSMBUnixSetFileInfo(const int xid, struct cifsTconInfo *tcon,
 
        rc = SendReceiveNoRsp(xid, tcon->ses, (struct smb_hdr *) pSMB, 0);
        if (rc)
-               cFYI(1, ("Send error in Set Time (SetFileInfo) = %d", rc));
+               cFYI(1, "Send error in Set Time (SetFileInfo) = %d", rc);
 
        /* Note: On -EAGAIN error only caller can retry on handle based calls
                since file handle passed in no longer valid */
@@ -5297,7 +5298,7 @@ CIFSSMBUnixSetPathInfo(const int xid, struct cifsTconInfo *tcon, char *fileName,
        FILE_UNIX_BASIC_INFO *data_offset;
        __u16 params, param_offset, offset, count, byte_count;
 
-       cFYI(1, ("In SetUID/GID/Mode"));
+       cFYI(1, "In SetUID/GID/Mode");
 setPermsRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -5353,7 +5354,7 @@ setPermsRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("SetPathInfo (perms) returned %d", rc));
+               cFYI(1, "SetPathInfo (perms) returned %d", rc);
 
        cifs_buf_release(pSMB);
        if (rc == -EAGAIN)
@@ -5372,7 +5373,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
        struct dir_notify_req *dnotify_req;
        int bytes_returned;
 
-       cFYI(1, ("In CIFSSMBNotify for file handle %d", (int)netfid));
+       cFYI(1, "In CIFSSMBNotify for file handle %d", (int)netfid);
        rc = smb_init(SMB_COM_NT_TRANSACT, 23, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
        if (rc)
@@ -5406,7 +5407,7 @@ int CIFSSMBNotify(const int xid, struct cifsTconInfo *tcon,
                         (struct smb_hdr *)pSMBr, &bytes_returned,
                         CIFS_ASYNC_OP);
        if (rc) {
-               cFYI(1, ("Error in Notify = %d", rc));
+               cFYI(1, "Error in Notify = %d", rc);
        } else {
                /* Add file to outstanding requests */
                /* BB change to kmem cache alloc */
@@ -5462,7 +5463,7 @@ CIFSSMBQAllEAs(const int xid, struct cifsTconInfo *tcon,
        char *end_of_smb;
        __u16 params, byte_count, data_offset;
 
-       cFYI(1, ("In Query All EAs path %s", searchName));
+       cFYI(1, "In Query All EAs path %s", searchName);
 QAllEAsRetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -5509,7 +5510,7 @@ QAllEAsRetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc) {
-               cFYI(1, ("Send error in QueryAllEAs = %d", rc));
+               cFYI(1, "Send error in QueryAllEAs = %d", rc);
                goto QAllEAsOut;
        }
 
@@ -5537,16 +5538,16 @@ QAllEAsRetry:
                                (((char *) &pSMBr->hdr.Protocol) + data_offset);
 
        list_len = le32_to_cpu(ea_response_data->list_len);
-       cFYI(1, ("ea length %d", list_len));
+       cFYI(1, "ea length %d", list_len);
        if (list_len <= 8) {
-               cFYI(1, ("empty EA list returned from server"));
+               cFYI(1, "empty EA list returned from server");
                goto QAllEAsOut;
        }
 
        /* make sure list_len doesn't go past end of SMB */
        end_of_smb = (char *)pByteArea(&pSMBr->hdr) + BCC(&pSMBr->hdr);
        if ((char *)ea_response_data + list_len > end_of_smb) {
-               cFYI(1, ("EA list appears to go beyond SMB"));
+               cFYI(1, "EA list appears to go beyond SMB");
                rc = -EIO;
                goto QAllEAsOut;
        }
@@ -5563,7 +5564,7 @@ QAllEAsRetry:
                temp_ptr += 4;
                /* make sure we can read name_len and value_len */
                if (list_len < 0) {
-                       cFYI(1, ("EA entry goes beyond length of list"));
+                       cFYI(1, "EA entry goes beyond length of list");
                        rc = -EIO;
                        goto QAllEAsOut;
                }
@@ -5572,7 +5573,7 @@ QAllEAsRetry:
                value_len = le16_to_cpu(temp_fea->value_len);
                list_len -= name_len + 1 + value_len;
                if (list_len < 0) {
-                       cFYI(1, ("EA entry goes beyond length of list"));
+                       cFYI(1, "EA entry goes beyond length of list");
                        rc = -EIO;
                        goto QAllEAsOut;
                }
@@ -5639,7 +5640,7 @@ CIFSSMBSetEA(const int xid, struct cifsTconInfo *tcon, const char *fileName,
        int bytes_returned = 0;
        __u16 params, param_offset, byte_count, offset, count;
 
-       cFYI(1, ("In SetEA"));
+       cFYI(1, "In SetEA");
 SetEARetry:
        rc = smb_init(SMB_COM_TRANSACTION2, 15, tcon, (void **) &pSMB,
                      (void **) &pSMBr);
@@ -5721,7 +5722,7 @@ SetEARetry:
        rc = SendReceive(xid, tcon->ses, (struct smb_hdr *) pSMB,
                         (struct smb_hdr *) pSMBr, &bytes_returned, 0);
        if (rc)
-               cFYI(1, ("SetPathInfo (EA) returned %d", rc));
+               cFYI(1, "SetPathInfo (EA) returned %d", rc);
 
        cifs_buf_release(pSMB);
 
index d9566bf..2208f06 100644 (file)
@@ -102,6 +102,7 @@ struct smb_vol {
        bool sockopt_tcp_nodelay:1;
        unsigned short int port;
        char *prepath;
+       struct nls_table *local_nls;
 };
 
 static int ipv4_connect(struct TCP_Server_Info *server);
@@ -135,7 +136,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
        spin_unlock(&GlobalMid_Lock);
        server->maxBuf = 0;
 
-       cFYI(1, ("Reconnecting tcp session"));
+       cFYI(1, "Reconnecting tcp session");
 
        /* before reconnecting the tcp session, mark the smb session (uid)
                and the tid bad so they are not used until reconnected */
@@ -153,12 +154,12 @@ cifs_reconnect(struct TCP_Server_Info *server)
        /* do not want to be sending data on a socket we are freeing */
        mutex_lock(&server->srv_mutex);
        if (server->ssocket) {
-               cFYI(1, ("State: 0x%x Flags: 0x%lx", server->ssocket->state,
-                       server->ssocket->flags));
+               cFYI(1, "State: 0x%x Flags: 0x%lx", server->ssocket->state,
+                       server->ssocket->flags);
                kernel_sock_shutdown(server->ssocket, SHUT_WR);
-               cFYI(1, ("Post shutdown state: 0x%x Flags: 0x%lx",
+               cFYI(1, "Post shutdown state: 0x%x Flags: 0x%lx",
                        server->ssocket->state,
-                       server->ssocket->flags));
+                       server->ssocket->flags);
                sock_release(server->ssocket);
                server->ssocket = NULL;
        }
@@ -187,7 +188,7 @@ cifs_reconnect(struct TCP_Server_Info *server)
                else
                        rc = ipv4_connect(server);
                if (rc) {
-                       cFYI(1, ("reconnect error %d", rc));
+                       cFYI(1, "reconnect error %d", rc);
                        msleep(3000);
                } else {
                        atomic_inc(&tcpSesReconnectCount);
@@ -223,7 +224,7 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
        /* check for plausible wct, bcc and t2 data and parm sizes */
        /* check for parm and data offset going beyond end of smb */
        if (pSMB->WordCount != 10) { /* coalesce_t2 depends on this */
-               cFYI(1, ("invalid transact2 word count"));
+               cFYI(1, "invalid transact2 word count");
                return -EINVAL;
        }
 
@@ -237,15 +238,15 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize)
        if (remaining == 0)
                return 0;
        else if (remaining < 0) {
-               cFYI(1, ("total data %d smaller than data in frame %d",
-                       total_data_size, data_in_this_rsp));
+               cFYI(1, "total data %d smaller than data in frame %d",
+                       total_data_size, data_in_this_rsp);
                return -EINVAL;
        } else {
-               cFYI(1, ("missing %d bytes from transact2, check next response",
-                       remaining));
+               cFYI(1, "missing %d bytes from transact2, check next response",
+                       remaining);
                if (total_data_size > maxBufSize) {
-                       cERROR(1, ("TotalDataSize %d is over maximum buffer %d",
-                               total_data_size, maxBufSize));
+                       cERROR(1, "TotalDataSize %d is over maximum buffer %d",
+                               total_data_size, maxBufSize);
                        return -EINVAL;
                }
                return remaining;
@@ -267,7 +268,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
        total_data_size = le16_to_cpu(pSMBt->t2_rsp.TotalDataCount);
 
        if (total_data_size != le16_to_cpu(pSMB2->t2_rsp.TotalDataCount)) {
-               cFYI(1, ("total data size of primary and secondary t2 differ"));
+               cFYI(1, "total data size of primary and secondary t2 differ");
        }
 
        total_in_buf = le16_to_cpu(pSMBt->t2_rsp.DataCount);
@@ -282,7 +283,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
 
        total_in_buf2 = le16_to_cpu(pSMB2->t2_rsp.DataCount);
        if (remaining < total_in_buf2) {
-               cFYI(1, ("transact2 2nd response contains too much data"));
+               cFYI(1, "transact2 2nd response contains too much data");
        }
 
        /* find end of first SMB data area */
@@ -311,7 +312,7 @@ static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB)
        pTargetSMB->smb_buf_length = byte_count;
 
        if (remaining == total_in_buf2) {
-               cFYI(1, ("found the last secondary response"));
+               cFYI(1, "found the last secondary response");
                return 0; /* we are done */
        } else /* more responses to go */
                return 1;
@@ -339,7 +340,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
        int reconnect;
 
        current->flags |= PF_MEMALLOC;
-       cFYI(1, ("Demultiplex PID: %d", task_pid_nr(current)));
+       cFYI(1, "Demultiplex PID: %d", task_pid_nr(current));
 
        length = atomic_inc_return(&tcpSesAllocCount);
        if (length > 1)
@@ -353,7 +354,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                if (bigbuf == NULL) {
                        bigbuf = cifs_buf_get();
                        if (!bigbuf) {
-                               cERROR(1, ("No memory for large SMB response"));
+                               cERROR(1, "No memory for large SMB response");
                                msleep(3000);
                                /* retry will check if exiting */
                                continue;
@@ -366,7 +367,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server)
                if (smallbuf == NULL) {
                        smallbuf = cifs_small_buf_get();
                        if (!smallbuf) {
-                               cERROR(1, ("No memory for SMB response"));
+                               cERROR(1, "No memory for SMB response");
                                msleep(1000);
                                /* retry will check if exiting */
                                continue;
@@ -391,9 +392,9 @@ incomplete_rcv:
                if (server->tcpStatus == CifsExiting) {
                        break;
                } else if (server->tcpStatus == CifsNeedReconnect) {
-                       cFYI(1, ("Reconnect after server stopped responding"));
+                       cFYI(1, "Reconnect after server stopped responding");
                        cifs_reconnect(server);
-                       cFYI(1, ("call to reconnect done"));
+                       cFYI(1, "call to reconnect done");
                        csocket = server->ssocket;
                        continue;
                } else if ((length == -ERESTARTSYS) || (length == -EAGAIN)) {
@@ -411,7 +412,7 @@ incomplete_rcv:
                                continue;
                } else if (length <= 0) {
                        if (server->tcpStatus == CifsNew) {
-                               cFYI(1, ("tcp session abend after SMBnegprot"));
+                               cFYI(1, "tcp session abend after SMBnegprot");
                                /* some servers kill the TCP session rather than
                                   returning an SMB negprot error, in which
                                   case reconnecting here is not going to help,
@@ -419,18 +420,18 @@ incomplete_rcv:
                                break;
                        }
                        if (!try_to_freeze() && (length == -EINTR)) {
-                               cFYI(1, ("cifsd thread killed"));
+                               cFYI(1, "cifsd thread killed");
                                break;
                        }
-                       cFYI(1, ("Reconnect after unexpected peek error %d",
-                               length));
+                       cFYI(1, "Reconnect after unexpected peek error %d",
+                               length);
                        cifs_reconnect(server);
                        csocket = server->ssocket;
                        wake_up(&server->response_q);
                        continue;
                } else if (length < pdu_length) {
-                       cFYI(1, ("requested %d bytes but only got %d bytes",
-                                 pdu_length, length));
+                       cFYI(1, "requested %d bytes but only got %d bytes",
+                                 pdu_length, length);
                        pdu_length -= length;
                        msleep(1);
                        goto incomplete_rcv;
@@ -450,18 +451,18 @@ incomplete_rcv:
                pdu_length = be32_to_cpu((__force __be32)smb_buffer->smb_buf_length);
                smb_buffer->smb_buf_length = pdu_length;
 
-               cFYI(1, ("rfc1002 length 0x%x", pdu_length+4));
+               cFYI(1, "rfc1002 length 0x%x", pdu_length+4);
 
                if (temp == (char) RFC1002_SESSION_KEEP_ALIVE) {
                        continue;
                } else if (temp == (char)RFC1002_POSITIVE_SESSION_RESPONSE) {
-                       cFYI(1, ("Good RFC 1002 session rsp"));
+                       cFYI(1, "Good RFC 1002 session rsp");
                        continue;
                } else if (temp == (char)RFC1002_NEGATIVE_SESSION_RESPONSE) {
                        /* we get this from Windows 98 instead of
                           an error on SMB negprot response */
-                       cFYI(1, ("Negative RFC1002 Session Response Error 0x%x)",
-                               pdu_length));
+                       cFYI(1, "Negative RFC1002 Session Response Error 0x%x)",
+                               pdu_length);
                        if (server->tcpStatus == CifsNew) {
                                /* if nack on negprot (rather than
                                ret of smb negprot error) reconnecting
@@ -484,7 +485,7 @@ incomplete_rcv:
                                continue;
                        }
                } else if (temp != (char) 0) {
-                       cERROR(1, ("Unknown RFC 1002 frame"));
+                       cERROR(1, "Unknown RFC 1002 frame");
                        cifs_dump_mem(" Received Data: ", (char *)smb_buffer,
                                      length);
                        cifs_reconnect(server);
@@ -495,8 +496,8 @@ incomplete_rcv:
                /* else we have an SMB response */
                if ((pdu_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) ||
                            (pdu_length < sizeof(struct smb_hdr) - 1 - 4)) {
-                       cERROR(1, ("Invalid size SMB length %d pdu_length %d",
-                                       length, pdu_length+4));
+                       cERROR(1, "Invalid size SMB length %d pdu_length %d",
+                                       length, pdu_length+4);
                        cifs_reconnect(server);
                        csocket = server->ssocket;
                        wake_up(&server->response_q);
@@ -539,8 +540,8 @@ incomplete_rcv:
                                length = 0;
                                continue;
                        } else if (length <= 0) {
-                               cERROR(1, ("Received no data, expecting %d",
-                                             pdu_length - total_read));
+                               cERROR(1, "Received no data, expecting %d",
+                                             pdu_length - total_read);
                                cifs_reconnect(server);
                                csocket = server->ssocket;
                                reconnect = 1;
@@ -588,7 +589,7 @@ incomplete_rcv:
                                                }
                                        } else {
                                                if (!isLargeBuf) {
-                                                       cERROR(1,("1st trans2 resp needs bigbuf"));
+                                                       cERROR(1, "1st trans2 resp needs bigbuf");
                                        /* BB maybe we can fix this up,  switch
                                           to already allocated large buffer? */
                                                } else {
@@ -630,8 +631,8 @@ multi_t2_fnd:
                        wake_up_process(task_to_wake);
                } else if (!is_valid_oplock_break(smb_buffer, server) &&
                           !isMultiRsp) {
-                       cERROR(1, ("No task to wake, unknown frame received! "
-                                  "NumMids %d", midCount.counter));
+                       cERROR(1, "No task to wake, unknown frame received! "
+                                  "NumMids %d", midCount.counter);
                        cifs_dump_mem("Received Data is: ", (char *)smb_buffer,
                                      sizeof(struct smb_hdr));
 #ifdef CONFIG_CIFS_DEBUG2
@@ -708,8 +709,8 @@ multi_t2_fnd:
                list_for_each(tmp, &server->pending_mid_q) {
                mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
                        if (mid_entry->midState == MID_REQUEST_SUBMITTED) {
-                               cFYI(1, ("Clearing Mid 0x%x - waking up ",
-                                        mid_entry->mid));
+                               cFYI(1, "Clearing Mid 0x%x - waking up ",
+                                        mid_entry->mid);
                                task_to_wake = mid_entry->tsk;
                                if (task_to_wake)
                                        wake_up_process(task_to_wake);
@@ -728,7 +729,7 @@ multi_t2_fnd:
                to wait at least 45 seconds before giving up
                on a request getting a response and going ahead
                and killing cifsd */
-               cFYI(1, ("Wait for exit from demultiplex thread"));
+               cFYI(1, "Wait for exit from demultiplex thread");
                msleep(46000);
                /* if threads still have not exited they are probably never
                coming home not much else we can do but free the memory */
@@ -849,7 +850,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                        separator[0] = options[4];
                        options += 5;
                } else {
-                       cFYI(1, ("Null separator not allowed"));
+                       cFYI(1, "Null separator not allowed");
                }
        }
 
@@ -974,7 +975,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                        }
                } else if (strnicmp(data, "sec", 3) == 0) {
                        if (!value || !*value) {
-                               cERROR(1, ("no security value specified"));
+                               cERROR(1, "no security value specified");
                                continue;
                        } else if (strnicmp(value, "krb5i", 5) == 0) {
                                vol->secFlg |= CIFSSEC_MAY_KRB5 |
@@ -982,7 +983,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                        } else if (strnicmp(value, "krb5p", 5) == 0) {
                                /* vol->secFlg |= CIFSSEC_MUST_SEAL |
                                        CIFSSEC_MAY_KRB5; */
-                               cERROR(1, ("Krb5 cifs privacy not supported"));
+                               cERROR(1, "Krb5 cifs privacy not supported");
                                return 1;
                        } else if (strnicmp(value, "krb5", 4) == 0) {
                                vol->secFlg |= CIFSSEC_MAY_KRB5;
@@ -1014,7 +1015,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                        } else if (strnicmp(value, "none", 4) == 0) {
                                vol->nullauth = 1;
                        } else {
-                               cERROR(1, ("bad security option: %s", value));
+                               cERROR(1, "bad security option: %s", value);
                                return 1;
                        }
                } else if ((strnicmp(data, "unc", 3) == 0)
@@ -1053,7 +1054,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                        a domain name and need special handling? */
                        if (strnlen(value, 256) < 256) {
                                vol->domainname = value;
-                               cFYI(1, ("Domain name set"));
+                               cFYI(1, "Domain name set");
                        } else {
                                printk(KERN_WARNING "CIFS: domain name too "
                                                    "long\n");
@@ -1076,7 +1077,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                                        strcpy(vol->prepath+1, value);
                                } else
                                        strcpy(vol->prepath, value);
-                               cFYI(1, ("prefix path %s", vol->prepath));
+                               cFYI(1, "prefix path %s", vol->prepath);
                        } else {
                                printk(KERN_WARNING "CIFS: prefix too long\n");
                                return 1;
@@ -1092,7 +1093,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                                        vol->iocharset = value;
                                /* if iocharset not set then load_nls_default
                                   is used by caller */
-                               cFYI(1, ("iocharset set to %s", value));
+                               cFYI(1, "iocharset set to %s", value);
                        } else {
                                printk(KERN_WARNING "CIFS: iocharset name "
                                                    "too long.\n");
@@ -1144,14 +1145,14 @@ cifs_parse_mount_options(char *options, const char *devname,
                        }
                } else if (strnicmp(data, "sockopt", 5) == 0) {
                        if (!value || !*value) {
-                               cERROR(1, ("no socket option specified"));
+                               cERROR(1, "no socket option specified");
                                continue;
                        } else if (strnicmp(value, "TCP_NODELAY", 11) == 0) {
                                vol->sockopt_tcp_nodelay = 1;
                        }
                } else if (strnicmp(data, "netbiosname", 4) == 0) {
                        if (!value || !*value || (*value == ' ')) {
-                               cFYI(1, ("invalid (empty) netbiosname"));
+                               cFYI(1, "invalid (empty) netbiosname");
                        } else {
                                memset(vol->source_rfc1001_name, 0x20, 15);
                                for (i = 0; i < 15; i++) {
@@ -1175,7 +1176,7 @@ cifs_parse_mount_options(char *options, const char *devname,
                } else if (strnicmp(data, "servern", 7) == 0) {
                        /* servernetbiosname specified override *SMBSERVER */
                        if (!value || !*value || (*value == ' ')) {
-                               cFYI(1, ("empty server netbiosname specified"));
+                               cFYI(1, "empty server netbiosname specified");
                        } else {
                                /* last byte, type, is 0x20 for servr type */
                                memset(vol->target_rfc1001_name, 0x20, 16);
@@ -1434,7 +1435,7 @@ cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port)
 
                ++server->srv_count;
                write_unlock(&cifs_tcp_ses_lock);
-               cFYI(1, ("Existing tcp session with server found"));
+               cFYI(1, "Existing tcp session with server found");
                return server;
        }
        write_unlock(&cifs_tcp_ses_lock);
@@ -1475,7 +1476,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
 
        memset(&addr, 0, sizeof(struct sockaddr_storage));
 
-       cFYI(1, ("UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip));
+       cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
 
        if (volume_info->UNCip && volume_info->UNC) {
                rc = cifs_convert_address(volume_info->UNCip, &addr);
@@ -1487,13 +1488,12 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
        } else if (volume_info->UNCip) {
                /* BB using ip addr as tcp_ses name to connect to the
                   DFS root below */
-               cERROR(1, ("Connecting to DFS root not implemented yet"));
+               cERROR(1, "Connecting to DFS root not implemented yet");
                rc = -EINVAL;
                goto out_err;
        } else /* which tcp_sess DFS root would we conect to */ {
-               cERROR(1,
-                      ("CIFS mount error: No UNC path (e.g. -o "
-                       "unc=//192.168.1.100/public) specified"));
+               cERROR(1, "CIFS mount error: No UNC path (e.g. -o "
+                       "unc=//192.168.1.100/public) specified");
                rc = -EINVAL;
                goto out_err;
        }
@@ -1540,7 +1540,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
        ++tcp_ses->srv_count;
 
        if (addr.ss_family == AF_INET6) {
-               cFYI(1, ("attempting ipv6 connect"));
+               cFYI(1, "attempting ipv6 connect");
                /* BB should we allow ipv6 on port 139? */
                /* other OS never observed in Wild doing 139 with v6 */
                sin_server6->sin6_port = htons(volume_info->port);
@@ -1554,7 +1554,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
                rc = ipv4_connect(tcp_ses);
        }
        if (rc < 0) {
-               cERROR(1, ("Error connecting to socket. Aborting operation"));
+               cERROR(1, "Error connecting to socket. Aborting operation");
                goto out_err;
        }
 
@@ -1567,7 +1567,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
                                  tcp_ses, "cifsd");
        if (IS_ERR(tcp_ses->tsk)) {
                rc = PTR_ERR(tcp_ses->tsk);
-               cERROR(1, ("error %d create cifsd thread", rc));
+               cERROR(1, "error %d create cifsd thread", rc);
                module_put(THIS_MODULE);
                goto out_err;
        }
@@ -1616,6 +1616,7 @@ cifs_put_smb_ses(struct cifsSesInfo *ses)
        int xid;
        struct TCP_Server_Info *server = ses->server;
 
+       cFYI(1, "%s: ses_count=%d\n", __func__, ses->ses_count);
        write_lock(&cifs_tcp_ses_lock);
        if (--ses->ses_count > 0) {
                write_unlock(&cifs_tcp_ses_lock);
@@ -1634,6 +1635,102 @@ cifs_put_smb_ses(struct cifsSesInfo *ses)
        cifs_put_tcp_session(server);
 }
 
+static struct cifsSesInfo *
+cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
+{
+       int rc = -ENOMEM, xid;
+       struct cifsSesInfo *ses;
+
+       xid = GetXid();
+
+       ses = cifs_find_smb_ses(server, volume_info->username);
+       if (ses) {
+               cFYI(1, "Existing smb sess found (status=%d)", ses->status);
+
+               /* existing SMB ses has a server reference already */
+               cifs_put_tcp_session(server);
+
+               mutex_lock(&ses->session_mutex);
+               rc = cifs_negotiate_protocol(xid, ses);
+               if (rc) {
+                       mutex_unlock(&ses->session_mutex);
+                       /* problem -- put our ses reference */
+                       cifs_put_smb_ses(ses);
+                       FreeXid(xid);
+                       return ERR_PTR(rc);
+               }
+               if (ses->need_reconnect) {
+                       cFYI(1, "Session needs reconnect");
+                       rc = cifs_setup_session(xid, ses,
+                                               volume_info->local_nls);
+                       if (rc) {
+                               mutex_unlock(&ses->session_mutex);
+                               /* problem -- put our reference */
+                               cifs_put_smb_ses(ses);
+                               FreeXid(xid);
+                               return ERR_PTR(rc);
+                       }
+               }
+               mutex_unlock(&ses->session_mutex);
+               FreeXid(xid);
+               return ses;
+       }
+
+       cFYI(1, "Existing smb sess not found");
+       ses = sesInfoAlloc();
+       if (ses == NULL)
+               goto get_ses_fail;
+
+       /* new SMB session uses our server ref */
+       ses->server = server;
+       if (server->addr.sockAddr6.sin6_family == AF_INET6)
+               sprintf(ses->serverName, "%pI6",
+                       &server->addr.sockAddr6.sin6_addr);
+       else
+               sprintf(ses->serverName, "%pI4",
+                       &server->addr.sockAddr.sin_addr.s_addr);
+
+       if (volume_info->username)
+               strncpy(ses->userName, volume_info->username,
+                       MAX_USERNAME_SIZE);
+
+       /* volume_info->password freed at unmount */
+       if (volume_info->password) {
+               ses->password = kstrdup(volume_info->password, GFP_KERNEL);
+               if (!ses->password)
+                       goto get_ses_fail;
+       }
+       if (volume_info->domainname) {
+               int len = strlen(volume_info->domainname);
+               ses->domainName = kmalloc(len + 1, GFP_KERNEL);
+               if (ses->domainName)
+                       strcpy(ses->domainName, volume_info->domainname);
+       }
+       ses->linux_uid = volume_info->linux_uid;
+       ses->overrideSecFlg = volume_info->secFlg;
+
+       mutex_lock(&ses->session_mutex);
+       rc = cifs_negotiate_protocol(xid, ses);
+       if (!rc)
+               rc = cifs_setup_session(xid, ses, volume_info->local_nls);
+       mutex_unlock(&ses->session_mutex);
+       if (rc)
+               goto get_ses_fail;
+
+       /* success, put it on the list */
+       write_lock(&cifs_tcp_ses_lock);
+       list_add(&ses->smb_ses_list, &server->smb_ses_list);
+       write_unlock(&cifs_tcp_ses_lock);
+
+       FreeXid(xid);
+       return ses;
+
+get_ses_fail:
+       sesInfoFree(ses);
+       FreeXid(xid);
+       return ERR_PTR(rc);
+}
+
 static struct cifsTconInfo *
 cifs_find_tcon(struct cifsSesInfo *ses, const char *unc)
 {
@@ -1662,6 +1759,7 @@ cifs_put_tcon(struct cifsTconInfo *tcon)
        int xid;
        struct cifsSesInfo *ses = tcon->ses;
 
+       cFYI(1, "%s: tc_count=%d\n", __func__, tcon->tc_count);
        write_lock(&cifs_tcp_ses_lock);
        if (--tcon->tc_count > 0) {
                write_unlock(&cifs_tcp_ses_lock);
@@ -1679,6 +1777,80 @@ cifs_put_tcon(struct cifsTconInfo *tcon)
        cifs_put_smb_ses(ses);
 }
 
+static struct cifsTconInfo *
+cifs_get_tcon(struct cifsSesInfo *ses, struct smb_vol *volume_info)
+{
+       int rc, xid;
+       struct cifsTconInfo *tcon;
+
+       tcon = cifs_find_tcon(ses, volume_info->UNC);
+       if (tcon) {
+               cFYI(1, "Found match on UNC path");
+               /* existing tcon already has a reference */
+               cifs_put_smb_ses(ses);
+               if (tcon->seal != volume_info->seal)
+                       cERROR(1, "transport encryption setting "
+                                  "conflicts with existing tid");
+               return tcon;
+       }
+
+       tcon = tconInfoAlloc();
+       if (tcon == NULL) {
+               rc = -ENOMEM;
+               goto out_fail;
+       }
+
+       tcon->ses = ses;
+       if (volume_info->password) {
+               tcon->password = kstrdup(volume_info->password, GFP_KERNEL);
+               if (!tcon->password) {
+                       rc = -ENOMEM;
+                       goto out_fail;
+               }
+       }
+
+       if (strchr(volume_info->UNC + 3, '\\') == NULL
+           && strchr(volume_info->UNC + 3, '/') == NULL) {
+               cERROR(1, "Missing share name");
+               rc = -ENODEV;
+               goto out_fail;
+       }
+
+       /* BB Do we need to wrap session_mutex around
+        * this TCon call and Unix SetFS as
+        * we do on SessSetup and reconnect? */
+       xid = GetXid();
+       rc = CIFSTCon(xid, ses, volume_info->UNC, tcon, volume_info->local_nls);
+       FreeXid(xid);
+       cFYI(1, "CIFS Tcon rc = %d", rc);
+       if (rc)
+               goto out_fail;
+
+       if (volume_info->nodfs) {
+               tcon->Flags &= ~SMB_SHARE_IS_IN_DFS;
+               cFYI(1, "DFS disabled (%d)", tcon->Flags);
+       }
+       tcon->seal = volume_info->seal;
+       /* we can have only one retry value for a connection
+          to a share so for resources mounted more than once
+          to the same server share the last value passed in
+          for the retry flag is used */
+       tcon->retry = volume_info->retry;
+       tcon->nocase = volume_info->nocase;
+       tcon->local_lease = volume_info->local_lease;
+
+       write_lock(&cifs_tcp_ses_lock);
+       list_add(&tcon->tcon_list, &ses->tcon_list);
+       write_unlock(&cifs_tcp_ses_lock);
+
+       return tcon;
+
+out_fail:
+       tconInfoFree(tcon);
+       return ERR_PTR(rc);
+}
+
+
 int
 get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
             const struct nls_table *nls_codepage, unsigned int *pnum_referrals,
@@ -1703,8 +1875,7 @@ get_dfs_path(int xid, struct cifsSesInfo *pSesInfo, const char *old_path,
                strcpy(temp_unc + 2, pSesInfo->serverName);
                strcpy(temp_unc + 2 + strlen(pSesInfo->serverName), "\\IPC$");
                rc = CIFSTCon(xid, pSesInfo, temp_unc, NULL, nls_codepage);
-               cFYI(1,
-                    ("CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid));
+               cFYI(1, "CIFS Tcon rc = %d ipc_tid = %d", rc, pSesInfo->ipc_tid);
                kfree(temp_unc);
        }
        if (rc == 0)
@@ -1777,12 +1948,12 @@ ipv4_connect(struct TCP_Server_Info *server)
                rc = sock_create_kern(PF_INET, SOCK_STREAM,
                                      IPPROTO_TCP, &socket);
                if (rc < 0) {
-                       cERROR(1, ("Error %d creating socket", rc));
+                       cERROR(1, "Error %d creating socket", rc);
                        return rc;
                }
 
                /* BB other socket options to set KEEPALIVE, NODELAY? */
-               cFYI(1, ("Socket created"));
+               cFYI(1, "Socket created");
                server->ssocket = socket;
                socket->sk->sk_allocation = GFP_NOFS;
                cifs_reclassify_socket4(socket);
@@ -1827,7 +1998,7 @@ ipv4_connect(struct TCP_Server_Info *server)
        if (!connected) {
                if (orig_port)
                        server->addr.sockAddr.sin_port = orig_port;
-               cFYI(1, ("Error %d connecting to server via ipv4", rc));
+               cFYI(1, "Error %d connecting to server via ipv4", rc);
                sock_release(socket);
                server->ssocket = NULL;
                return rc;
@@ -1855,12 +2026,12 @@ ipv4_connect(struct TCP_Server_Info *server)
                rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY,
                                (char *)&val, sizeof(val));
                if (rc)
-                       cFYI(1, ("set TCP_NODELAY socket option error %d", rc));
+                       cFYI(1, "set TCP_NODELAY socket option error %d", rc);
        }
 
-        cFYI(1, ("sndbuf %d rcvbuf %d rcvtimeo 0x%lx",
+        cFYI(1, "sndbuf %d rcvbuf %d rcvtimeo 0x%lx",
                 socket->sk->sk_sndbuf,
-                socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo));
+                socket->sk->sk_rcvbuf, socket->sk->sk_rcvtimeo);
 
        /* send RFC1001 sessinit */
        if (server->addr.sockAddr.sin_port == htons(RFC1001_PORT)) {
@@ -1938,13 +2109,13 @@ ipv6_connect(struct TCP_Server_Info *server)
                rc = sock_create_kern(PF_INET6, SOCK_STREAM,
                                      IPPROTO_TCP, &socket);
                if (rc < 0) {
-                       cERROR(1, ("Error %d creating ipv6 socket", rc));
+                       cERROR(1, "Error %d creating ipv6 socket", rc);
                        socket = NULL;
                        return rc;
                }
 
                /* BB other socket options to set KEEPALIVE, NODELAY? */
-               cFYI(1, ("ipv6 Socket created"));
+               cFYI(1, "ipv6 Socket created");
                server->ssocket = socket;
                socket->sk->sk_allocation = GFP_NOFS;
                cifs_reclassify_socket6(socket);
@@ -1988,7 +2159,7 @@ ipv6_connect(struct TCP_Server_Info *server)
        if (!connected) {
                if (orig_port)
                        server->addr.sockAddr6.sin6_port = orig_port;
-               cFYI(1, ("Error %d connecting to server via ipv6", rc));
+               cFYI(1, "Error %d connecting to server via ipv6", rc);
                sock_release(socket);
                server->ssocket = NULL;
                return rc;
@@ -2007,7 +2178,7 @@ ipv6_connect(struct TCP_Server_Info *server)
                rc = kernel_setsockopt(socket, SOL_TCP, TCP_NODELAY,
                                (char *)&val, sizeof(val));
                if (rc)
-                       cFYI(1, ("set TCP_NODELAY socket option error %d", rc));
+                       cFYI(1, "set TCP_NODELAY socket option error %d", rc);
        }
 
        server->ssocket = socket;
@@ -2032,13 +2203,13 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
        if (vol_info && vol_info->no_linux_ext) {
                tcon->fsUnixInfo.Capability = 0;
                tcon->unix_ext = 0; /* Unix Extensions disabled */
-               cFYI(1, ("Linux protocol extensions disabled"));
+               cFYI(1, "Linux protocol extensions disabled");
                return;
        } else if (vol_info)
                tcon->unix_ext = 1; /* Unix Extensions supported */
 
        if (tcon->unix_ext == 0) {
-               cFYI(1, ("Unix extensions disabled so not set on reconnect"));
+               cFYI(1, "Unix extensions disabled so not set on reconnect");
                return;
        }
 
@@ -2054,12 +2225,11 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
                                cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
                        if ((saved_cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) {
                                if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP)
-                                       cERROR(1, ("POSIXPATH support change"));
+                                       cERROR(1, "POSIXPATH support change");
                                cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
                        } else if ((cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) == 0) {
-                               cERROR(1, ("possible reconnect error"));
-                               cERROR(1,
-                                       ("server disabled POSIX path support"));
+                               cERROR(1, "possible reconnect error");
+                               cERROR(1, "server disabled POSIX path support");
                        }
                }
 
@@ -2067,7 +2237,7 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
                if (vol_info && vol_info->no_psx_acl)
                        cap &= ~CIFS_UNIX_POSIX_ACL_CAP;
                else if (CIFS_UNIX_POSIX_ACL_CAP & cap) {
-                       cFYI(1, ("negotiated posix acl support"));
+                       cFYI(1, "negotiated posix acl support");
                        if (sb)
                                sb->s_flags |= MS_POSIXACL;
                }
@@ -2075,7 +2245,7 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
                if (vol_info && vol_info->posix_paths == 0)
                        cap &= ~CIFS_UNIX_POSIX_PATHNAMES_CAP;
                else if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
-                       cFYI(1, ("negotiate posix pathnames"));
+                       cFYI(1, "negotiate posix pathnames");
                        if (sb)
                                CIFS_SB(sb)->mnt_cifs_flags |=
                                        CIFS_MOUNT_POSIX_PATHS;
@@ -2090,39 +2260,38 @@ void reset_cifs_unix_caps(int xid, struct cifsTconInfo *tcon,
                if (sb && (CIFS_SB(sb)->rsize > 127 * 1024)) {
                        if ((cap & CIFS_UNIX_LARGE_READ_CAP) == 0) {
                                CIFS_SB(sb)->rsize = 127 * 1024;
-                               cFYI(DBG2,
-                                       ("larger reads not supported by srv"));
+                               cFYI(DBG2, "larger reads not supported by srv");
                        }
                }
 
 
-               cFYI(1, ("Negotiate caps 0x%x", (int)cap));
+               cFYI(1, "Negotiate caps 0x%x", (int)cap);
 #ifdef CONFIG_CIFS_DEBUG2
                if (cap & CIFS_UNIX_FCNTL_CAP)
-                       cFYI(1, ("FCNTL cap"));
+                       cFYI(1, "FCNTL cap");
                if (cap & CIFS_UNIX_EXTATTR_CAP)
-                       cFYI(1, ("EXTATTR cap"));
+                       cFYI(1, "EXTATTR cap");
                if (cap & CIFS_UNIX_POSIX_PATHNAMES_CAP)
-                       cFYI(1, ("POSIX path cap"));
+                       cFYI(1, "POSIX path cap");
                if (cap & CIFS_UNIX_XATTR_CAP)
-                       cFYI(1, ("XATTR cap"));
+                       cFYI(1, "XATTR cap");
                if (cap & CIFS_UNIX_POSIX_ACL_CAP)
-                       cFYI(1, ("POSIX ACL cap"));
+                       cFYI(1, "POSIX ACL cap");
                if (cap & CIFS_UNIX_LARGE_READ_CAP)
-                       cFYI(1, ("very large read cap"));
+                       cFYI(1, "very large read cap");
                if (cap & CIFS_UNIX_LARGE_WRITE_CAP)
-                       cFYI(1, ("very large write cap"));
+                       cFYI(1, "very large write cap");
 #endif /* CIFS_DEBUG2 */
                if (CIFSSMBSetFSUnixInfo(xid, tcon, cap)) {
                        if (vol_info == NULL) {
-                               cFYI(1, ("resetting capabilities failed"));
+                               cFYI(1, "resetting capabilities failed");
                        } else
-                               cERROR(1, ("Negotiating Unix capabilities "
+                               cERROR(1, "Negotiating Unix capabilities "
                                           "with the server failed.  Consider "
                                           "mounting with the Unix Extensions\n"
                                           "disabled, if problems are found, "
                                           "by specifying the nounix mount "
-                                          "option."));
+                                          "option.");
 
                }
        }
@@ -2152,8 +2321,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
                          struct cifs_sb_info *cifs_sb)
 {
        if (pvolume_info->rsize > CIFSMaxBufSize) {
-               cERROR(1, ("rsize %d too large, using MaxBufSize",
-                       pvolume_info->rsize));
+               cERROR(1, "rsize %d too large, using MaxBufSize",
+                       pvolume_info->rsize);
                cifs_sb->rsize = CIFSMaxBufSize;
        } else if ((pvolume_info->rsize) &&
                        (pvolume_info->rsize <= CIFSMaxBufSize))
@@ -2162,8 +2331,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
                cifs_sb->rsize = CIFSMaxBufSize;
 
        if (pvolume_info->wsize > PAGEVEC_SIZE * PAGE_CACHE_SIZE) {
-               cERROR(1, ("wsize %d too large, using 4096 instead",
-                         pvolume_info->wsize));
+               cERROR(1, "wsize %d too large, using 4096 instead",
+                         pvolume_info->wsize);
                cifs_sb->wsize = 4096;
        } else if (pvolume_info->wsize)
                cifs_sb->wsize = pvolume_info->wsize;
@@ -2181,7 +2350,7 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
        if (cifs_sb->rsize < 2048) {
                cifs_sb->rsize = 2048;
                /* Windows ME may prefer this */
-               cFYI(1, ("readsize set to minimum: 2048"));
+               cFYI(1, "readsize set to minimum: 2048");
        }
        /* calculate prepath */
        cifs_sb->prepath = pvolume_info->prepath;
@@ -2199,8 +2368,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
        cifs_sb->mnt_gid = pvolume_info->linux_gid;
        cifs_sb->mnt_file_mode = pvolume_info->file_mode;
        cifs_sb->mnt_dir_mode = pvolume_info->dir_mode;
-       cFYI(1, ("file mode: 0x%x  dir mode: 0x%x",
-               cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode));
+       cFYI(1, "file mode: 0x%x  dir mode: 0x%x",
+               cifs_sb->mnt_file_mode, cifs_sb->mnt_dir_mode);
 
        if (pvolume_info->noperm)
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_NO_PERM;
@@ -2229,13 +2398,13 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
        if (pvolume_info->dynperm)
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
        if (pvolume_info->direct_io) {
-               cFYI(1, ("mounting share using direct i/o"));
+               cFYI(1, "mounting share using direct i/o");
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
        }
 
        if ((pvolume_info->cifs_acl) && (pvolume_info->dynperm))
-               cERROR(1, ("mount option dynperm ignored if cifsacl "
-                          "mount option supported"));
+               cERROR(1, "mount option dynperm ignored if cifsacl "
+                          "mount option supported");
 }
 
 static int
@@ -2262,7 +2431,7 @@ cleanup_volume_info(struct smb_vol **pvolume_info)
 {
        struct smb_vol *volume_info;
 
-       if (!pvolume_info && !*pvolume_info)
+       if (!pvolume_info || !*pvolume_info)
                return;
 
        volume_info = *pvolume_info;
@@ -2344,11 +2513,11 @@ try_mount_again:
        }
 
        if (volume_info->nullauth) {
-               cFYI(1, ("null user"));
+               cFYI(1, "null user");
                volume_info->username = "";
        } else if (volume_info->username) {
                /* BB fixme parse for domain name here */
-               cFYI(1, ("Username: %s", volume_info->username));
+               cFYI(1, "Username: %s", volume_info->username);
        } else {
                cifserror("No username specified");
        /* In userspace mount helper we can get user name from alternate
@@ -2357,20 +2526,20 @@ try_mount_again:
                goto out;
        }
 
-
        /* this is needed for ASCII cp to Unicode converts */
        if (volume_info->iocharset == NULL) {
-               cifs_sb->local_nls = load_nls_default();
-       /* load_nls_default can not return null */
+               /* load_nls_default cannot return null */
+               volume_info->local_nls = load_nls_default();
        } else {
-               cifs_sb->local_nls = load_nls(volume_info->iocharset);
-               if (cifs_sb->local_nls == NULL) {
-                       cERROR(1, ("CIFS mount error: iocharset %s not found",
-                                volume_info->iocharset));
+               volume_info->local_nls = load_nls(volume_info->iocharset);
+               if (volume_info->local_nls == NULL) {
+                       cERROR(1, "CIFS mount error: iocharset %s not found",
+                                volume_info->iocharset);
                        rc = -ELIBACC;
                        goto out;
                }
        }
+       cifs_sb->local_nls = volume_info->local_nls;
 
        /* get a reference to a tcp session */
        srvTcp = cifs_get_tcp_session(volume_info);
@@ -2379,148 +2548,30 @@ try_mount_again:
                goto out;
        }
 
-       pSesInfo = cifs_find_smb_ses(srvTcp, volume_info->username);
-       if (pSesInfo) {
-               cFYI(1, ("Existing smb sess found (status=%d)",
-                       pSesInfo->status));
-               /*
-                * The existing SMB session already has a reference to srvTcp,
-                * so we can put back the extra one we got before
-                */
-               cifs_put_tcp_session(srvTcp);
-
-               mutex_lock(&pSesInfo->session_mutex);
-               if (pSesInfo->need_reconnect) {
-                       cFYI(1, ("Session needs reconnect"));
-                       rc = cifs_setup_session(xid, pSesInfo,
-                                               cifs_sb->local_nls);
-               }
-               mutex_unlock(&pSesInfo->session_mutex);
-       } else if (!rc) {
-               cFYI(1, ("Existing smb sess not found"));
-               pSesInfo = sesInfoAlloc();
-               if (pSesInfo == NULL) {
-                       rc = -ENOMEM;
-                       goto mount_fail_check;
-               }
-
-               /* new SMB session uses our srvTcp ref */
-               pSesInfo->server = srvTcp;
-               if (srvTcp->addr.sockAddr6.sin6_family == AF_INET6)
-                       sprintf(pSesInfo->serverName, "%pI6",
-                               &srvTcp->addr.sockAddr6.sin6_addr);
-               else
-                       sprintf(pSesInfo->serverName, "%pI4",
-                               &srvTcp->addr.sockAddr.sin_addr.s_addr);
-
-               write_lock(&cifs_tcp_ses_lock);
-               list_add(&pSesInfo->smb_ses_list, &srvTcp->smb_ses_list);
-               write_unlock(&cifs_tcp_ses_lock);
-
-               /* volume_info->password freed at unmount */
-               if (volume_info->password) {
-                       pSesInfo->password = kstrdup(volume_info->password,
-                                                    GFP_KERNEL);
-                       if (!pSesInfo->password) {
-                               rc = -ENOMEM;
-                               goto mount_fail_check;
-                       }
-               }
-               if (volume_info->username)
-                       strncpy(pSesInfo->userName, volume_info->username,
-                               MAX_USERNAME_SIZE);
-               if (volume_info->domainname) {
-                       int len = strlen(volume_info->domainname);
-                       pSesInfo->domainName = kmalloc(len + 1, GFP_KERNEL);
-                       if (pSesInfo->domainName)
-                               strcpy(pSesInfo->domainName,
-                                       volume_info->domainname);
-               }
-               pSesInfo->linux_uid = volume_info->linux_uid;
-               pSesInfo->overrideSecFlg = volume_info->secFlg;
-               mutex_lock(&pSesInfo->session_mutex);
-
-               /* BB FIXME need to pass vol->secFlgs BB */
-               rc = cifs_setup_session(xid, pSesInfo,
-                                       cifs_sb->local_nls);
-               mutex_unlock(&pSesInfo->session_mutex);
+       /* get a reference to a SMB session */
+       pSesInfo = cifs_get_smb_ses(srvTcp, volume_info);
+       if (IS_ERR(pSesInfo)) {
+               rc = PTR_ERR(pSesInfo);
+               pSesInfo = NULL;
+               goto mount_fail_check;
        }
 
-       /* search for existing tcon to this server share */
-       if (!rc) {
-               setup_cifs_sb(volume_info, cifs_sb);
-
-               tcon = cifs_find_tcon(pSesInfo, volume_info->UNC);
-               if (tcon) {
-                       cFYI(1, ("Found match on UNC path"));
-                       /* existing tcon already has a reference */
-                       cifs_put_smb_ses(pSesInfo);
-                       if (tcon->seal != volume_info->seal)
-                               cERROR(1, ("transport encryption setting "
-                                          "conflicts with existing tid"));
-               } else {
-                       tcon = tconInfoAlloc();
-                       if (tcon == NULL) {
-                               rc = -ENOMEM;
-                               goto mount_fail_check;
-                       }
-
-                       tcon->ses = pSesInfo;
-                       if (volume_info->password) {
-                               tcon->password = kstrdup(volume_info->password,
-                                                        GFP_KERNEL);
-                               if (!tcon->password) {
-                                       rc = -ENOMEM;
-                                       goto mount_fail_check;
-                               }
-                       }
-
-                       if ((strchr(volume_info->UNC + 3, '\\') == NULL)
-                           && (strchr(volume_info->UNC + 3, '/') == NULL)) {
-                               cERROR(1, ("Missing share name"));
-                               rc = -ENODEV;
-                               goto mount_fail_check;
-                       } else {
-                               /* BB Do we need to wrap sesSem around
-                                * this TCon call and Unix SetFS as
-                                * we do on SessSetup and reconnect? */
-                               rc = CIFSTCon(xid, pSesInfo, volume_info->UNC,
-                                             tcon, cifs_sb->local_nls);
-                               cFYI(1, ("CIFS Tcon rc = %d", rc));
-                               if (volume_info->nodfs) {
-                                       tcon->Flags &= ~SMB_SHARE_IS_IN_DFS;
-                                       cFYI(1, ("DFS disabled (%d)",
-                                               tcon->Flags));
-                               }
-                       }
-                       if (rc)
-                               goto remote_path_check;
-                       tcon->seal = volume_info->seal;
-                       write_lock(&cifs_tcp_ses_lock);
-                       list_add(&tcon->tcon_list, &pSesInfo->tcon_list);
-                       write_unlock(&cifs_tcp_ses_lock);
-               }
-
-               /* we can have only one retry value for a connection
-                  to a share so for resources mounted more than once
-                  to the same server share the last value passed in
-                  for the retry flag is used */
-               tcon->retry = volume_info->retry;
-               tcon->nocase = volume_info->nocase;
-               tcon->local_lease = volume_info->local_lease;
-       }
-       if (pSesInfo) {
-               if (pSesInfo->capabilities & CAP_LARGE_FILES)
-                       sb->s_maxbytes = MAX_LFS_FILESIZE;
-               else
-                       sb->s_maxbytes = MAX_NON_LFS;
-       }
+       setup_cifs_sb(volume_info, cifs_sb);
+       if (pSesInfo->capabilities & CAP_LARGE_FILES)
+               sb->s_maxbytes = MAX_LFS_FILESIZE;
+       else
+               sb->s_maxbytes = MAX_NON_LFS;
 
        /* BB FIXME fix time_gran to be larger for LANMAN sessions */
        sb->s_time_gran = 100;
 
-       if (rc)
+       /* search for existing tcon to this server share */
+       tcon = cifs_get_tcon(pSesInfo, volume_info);
+       if (IS_ERR(tcon)) {
+               rc = PTR_ERR(tcon);
+               tcon = NULL;
                goto remote_path_check;
+       }
 
        cifs_sb->tcon = tcon;
 
@@ -2544,7 +2595,7 @@ try_mount_again:
 
        if ((tcon->unix_ext == 0) && (cifs_sb->rsize > (1024 * 127))) {
                cifs_sb->rsize = 1024 * 127;
-               cFYI(DBG2, ("no very large read support, rsize now 127K"));
+               cFYI(DBG2, "no very large read support, rsize now 127K");
        }
        if (!(tcon->ses->capabilities & CAP_LARGE_WRITE_X))
                cifs_sb->wsize = min(cifs_sb->wsize,
@@ -2593,7 +2644,7 @@ remote_path_check:
                        goto mount_fail_check;
                }
 
-               cFYI(1, ("Getting referral for: %s", full_path));
+               cFYI(1, "Getting referral for: %s", full_path);
                rc = get_dfs_path(xid, pSesInfo , full_path + 1,
                        cifs_sb->local_nls, &num_referrals, &referrals,
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
@@ -2707,7 +2758,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                   by Samba (not sure whether other servers allow
                   NTLMv2 password here) */
 #ifdef CONFIG_CIFS_WEAK_PW_HASH
-               if ((extended_security & CIFSSEC_MAY_LANMAN) &&
+               if ((global_secflags & CIFSSEC_MAY_LANMAN) &&
                    (ses->server->secType == LANMAN))
                        calc_lanman_hash(tcon->password, ses->server->cryptKey,
                                         ses->server->secMode &
@@ -2778,13 +2829,13 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                if (length == 3) {
                        if ((bcc_ptr[0] == 'I') && (bcc_ptr[1] == 'P') &&
                            (bcc_ptr[2] == 'C')) {
-                               cFYI(1, ("IPC connection"));
+                               cFYI(1, "IPC connection");
                                tcon->ipc = 1;
                        }
                } else if (length == 2) {
                        if ((bcc_ptr[0] == 'A') && (bcc_ptr[1] == ':')) {
                                /* the most common case */
-                               cFYI(1, ("disk share connection"));
+                               cFYI(1, "disk share connection");
                        }
                }
                bcc_ptr += length + 1;
@@ -2797,7 +2848,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                                                      bytes_left, is_unicode,
                                                      nls_codepage);
 
-               cFYI(1, ("nativeFileSystem=%s", tcon->nativeFileSystem));
+               cFYI(1, "nativeFileSystem=%s", tcon->nativeFileSystem);
 
                if ((smb_buffer_response->WordCount == 3) ||
                         (smb_buffer_response->WordCount == 7))
@@ -2805,7 +2856,7 @@ CIFSTCon(unsigned int xid, struct cifsSesInfo *ses,
                        tcon->Flags = le16_to_cpu(pSMBr->OptionalSupport);
                else
                        tcon->Flags = 0;
-               cFYI(1, ("Tcon flags: 0x%x ", tcon->Flags));
+               cFYI(1, "Tcon flags: 0x%x ", tcon->Flags);
        } else if ((rc == 0) && tcon == NULL) {
                /* all we need to save for IPC$ connection */
                ses->ipc_tid = smb_buffer_response->Tid;
@@ -2833,57 +2884,61 @@ cifs_umount(struct super_block *sb, struct cifs_sb_info *cifs_sb)
        return rc;
 }
 
-int cifs_setup_session(unsigned int xid, struct cifsSesInfo *pSesInfo,
-                                          struct nls_table *nls_info)
+int cifs_negotiate_protocol(unsigned int xid, struct cifsSesInfo *ses)
 {
        int rc = 0;
-       int first_time = 0;
-       struct TCP_Server_Info *server = pSesInfo->server;
-
-       /* what if server changes its buffer size after dropping the session? */
-       if (server->maxBuf == 0) /* no need to send on reconnect */ {
-               rc = CIFSSMBNegotiate(xid, pSesInfo);
-               if (rc == -EAGAIN) {
-                       /* retry only once on 1st time connection */
-                       rc = CIFSSMBNegotiate(xid, pSesInfo);
-                       if (rc == -EAGAIN)
-                               rc = -EHOSTDOWN;
-               }
-               if (rc == 0) {
-                       spin_lock(&GlobalMid_Lock);
-                       if (server->tcpStatus != CifsExiting)
-                               server->tcpStatus = CifsGood;
-                       else
-                               rc = -EHOSTDOWN;
-                       spin_unlock(&GlobalMid_Lock);
+       struct TCP_Server_Info *server = ses->server;
+
+       /* only send once per connect */
+       if (server->maxBuf != 0)
+               return 0;
+
+       rc = CIFSSMBNegotiate(xid, ses);
+       if (rc == -EAGAIN) {
+               /* retry only once on 1st time connection */
+               rc = CIFSSMBNegotiate(xid, ses);
+               if (rc == -EAGAIN)
+                       rc = -EHOSTDOWN;
+       }
+       if (rc == 0) {
+               spin_lock(&GlobalMid_Lock);
+               if (server->tcpStatus != CifsExiting)
+                       server->tcpStatus = CifsGood;
+               else
+                       rc = -EHOSTDOWN;
+               spin_unlock(&GlobalMid_Lock);
 
-               }
-               first_time = 1;
        }
 
-       if (rc)
-               goto ss_err_exit;
+       return rc;
+}
+
+
+int cifs_setup_session(unsigned int xid, struct cifsSesInfo *ses,
+                       struct nls_table *nls_info)
+{
+       int rc = 0;
+       struct TCP_Server_Info *server = ses->server;
 
-       pSesInfo->flags = 0;
-       pSesInfo->capabilities = server->capabilities;
+       ses->flags = 0;
+       ses->capabilities = server->capabilities;
        if (linuxExtEnabled == 0)
-               pSesInfo->capabilities &= (~CAP_UNIX);
+               ses->capabilities &= (~CAP_UNIX);
 
-       cFYI(1, ("Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
-                server->secMode, server->capabilities, server->timeAdj));
+       cFYI(1, "Security Mode: 0x%x Capabilities: 0x%x TimeAdjust: %d",
+                server->secMode, server->capabilities, server->timeAdj);
 
-       rc = CIFS_SessSetup(xid, pSesInfo, first_time, nls_info);
+       rc = CIFS_SessSetup(xid, ses, nls_info);
        if (rc) {
-               cERROR(1, ("Send error in SessSetup = %d", rc));
+               cERROR(1, "Send error in SessSetup = %d", rc);
        } else {
-               cFYI(1, ("CIFS Session Established successfully"));
+               cFYI(1, "CIFS Session Established successfully");
                spin_lock(&GlobalMid_Lock);
-               pSesInfo->status = CifsGood;
-               pSesInfo->need_reconnect = false;
+               ses->status = CifsGood;
+               ses->need_reconnect = false;
                spin_unlock(&GlobalMid_Lock);
        }
 
-ss_err_exit:
        return rc;
 }
 
index e9f7ecc..391816b 100644 (file)
@@ -73,7 +73,7 @@ cifs_bp_rename_retry:
                namelen += (1 + temp->d_name.len);
                temp = temp->d_parent;
                if (temp == NULL) {
-                       cERROR(1, ("corrupt dentry"));
+                       cERROR(1, "corrupt dentry");
                        return NULL;
                }
        }
@@ -90,19 +90,18 @@ cifs_bp_rename_retry:
                        full_path[namelen] = dirsep;
                        strncpy(full_path + namelen + 1, temp->d_name.name,
                                temp->d_name.len);
-                       cFYI(0, ("name: %s", full_path + namelen));
+                       cFYI(0, "name: %s", full_path + namelen);
                }
                temp = temp->d_parent;
                if (temp == NULL) {
-                       cERROR(1, ("corrupt dentry"));
+                       cERROR(1, "corrupt dentry");
                        kfree(full_path);
                        return NULL;
                }
        }
        if (namelen != pplen + dfsplen) {
-               cERROR(1,
-                      ("did not end path lookup where expected namelen is %d",
-                       namelen));
+               cERROR(1, "did not end path lookup where expected namelen is %d",
+                       namelen);
                /* presumably this is only possible if racing with a rename
                of one of the parent directories  (we can not lock the dentries
                above us to prevent this, but retrying should be harmless) */
@@ -130,6 +129,12 @@ cifs_bp_rename_retry:
        return full_path;
 }
 
+/*
+ * When called with struct file pointer set to NULL, there is no way we could
+ * update file->private_data, but getting it stuck on openFileList provides a
+ * way to access it from cifs_fill_filedata and thereby set file->private_data
+ * from cifs_open.
+ */
 struct cifsFileInfo *
 cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
                  struct file *file, struct vfsmount *mnt, unsigned int oflags)
@@ -173,7 +178,7 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
                if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
                        pCifsInode->clientCanCacheAll = true;
                        pCifsInode->clientCanCacheRead = true;
-                       cFYI(1, ("Exclusive Oplock inode %p", newinode));
+                       cFYI(1, "Exclusive Oplock inode %p", newinode);
                } else if ((oplock & 0xF) == OPLOCK_READ)
                                pCifsInode->clientCanCacheRead = true;
        }
@@ -183,16 +188,17 @@ cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
 }
 
 int cifs_posix_open(char *full_path, struct inode **pinode,
-                   struct vfsmount *mnt, int mode, int oflags,
-                   __u32 *poplock, __u16 *pnetfid, int xid)
+                       struct vfsmount *mnt, struct super_block *sb,
+                       int mode, int oflags,
+                       __u32 *poplock, __u16 *pnetfid, int xid)
 {
        int rc;
        FILE_UNIX_BASIC_INFO *presp_data;
        __u32 posix_flags = 0;
-       struct cifs_sb_info *cifs_sb = CIFS_SB(mnt->mnt_sb);
+       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
        struct cifs_fattr fattr;
 
-       cFYI(1, ("posix open %s", full_path));
+       cFYI(1, "posix open %s", full_path);
 
        presp_data = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
        if (presp_data == NULL)
@@ -242,7 +248,8 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
 
        /* get new inode and set it up */
        if (*pinode == NULL) {
-               *pinode = cifs_iget(mnt->mnt_sb, &fattr);
+               cifs_fill_uniqueid(sb, &fattr);
+               *pinode = cifs_iget(sb, &fattr);
                if (!*pinode) {
                        rc = -ENOMEM;
                        goto posix_open_ret;
@@ -251,7 +258,18 @@ int cifs_posix_open(char *full_path, struct inode **pinode,
                cifs_fattr_to_inode(*pinode, &fattr);
        }
 
-       cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt, oflags);
+       /*
+        * cifs_fill_filedata() takes care of setting cifsFileInfo pointer to
+        * file->private_data.
+        */
+       if (mnt) {
+               struct cifsFileInfo *pfile_info;
+
+               pfile_info = cifs_new_fileinfo(*pinode, *pnetfid, NULL, mnt,
+                                              oflags);
+               if (pfile_info == NULL)
+                       rc = -ENOMEM;
+       }
 
 posix_open_ret:
        kfree(presp_data);
@@ -315,13 +333,14 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
        if (nd && (nd->flags & LOOKUP_OPEN))
                oflags = nd->intent.open.flags;
        else
-               oflags = FMODE_READ;
+               oflags = FMODE_READ | SMB_O_CREAT;
 
        if (tcon->unix_ext && (tcon->ses->capabilities & CAP_UNIX) &&
            (CIFS_UNIX_POSIX_PATH_OPS_CAP &
                        le64_to_cpu(tcon->fsUnixInfo.Capability))) {
-               rc = cifs_posix_open(full_path, &newinode, nd->path.mnt,
-                                    mode, oflags, &oplock, &fileHandle, xid);
+               rc = cifs_posix_open(full_path, &newinode,
+                       nd ? nd->path.mnt : NULL,
+                       inode->i_sb, mode, oflags, &oplock, &fileHandle, xid);
                /* EIO could indicate that (posix open) operation is not
                   supported, despite what server claimed in capability
                   negotation.  EREMOTE indicates DFS junction, which is not
@@ -358,7 +377,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                else if ((oflags & O_CREAT) == O_CREAT)
                        disposition = FILE_OPEN_IF;
                else
-                       cFYI(1, ("Create flag not set in create function"));
+                       cFYI(1, "Create flag not set in create function");
        }
 
        /* BB add processing to set equivalent of mode - e.g. via CreateX with
@@ -394,7 +413,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        }
        if (rc) {
-               cFYI(1, ("cifs_create returned 0x%x", rc));
+               cFYI(1, "cifs_create returned 0x%x", rc);
                goto cifs_create_out;
        }
 
@@ -457,15 +476,22 @@ cifs_create_set_dentry:
        if (rc == 0)
                setup_cifs_dentry(tcon, direntry, newinode);
        else
-               cFYI(1, ("Create worked, get_inode_info failed rc = %d", rc));
+               cFYI(1, "Create worked, get_inode_info failed rc = %d", rc);
 
        /* nfsd case - nfs srv does not set nd */
        if ((nd == NULL) || (!(nd->flags & LOOKUP_OPEN))) {
                /* mknod case - do not leave file open */
                CIFSSMBClose(xid, tcon, fileHandle);
        } else if (!(posix_create) && (newinode)) {
-                       cifs_new_fileinfo(newinode, fileHandle, NULL,
-                                               nd->path.mnt, oflags);
+               struct cifsFileInfo *pfile_info;
+               /*
+                * cifs_fill_filedata() takes care of setting cifsFileInfo
+                * pointer to file->private_data.
+                */
+               pfile_info = cifs_new_fileinfo(newinode, fileHandle, NULL,
+                                              nd->path.mnt, oflags);
+               if (pfile_info == NULL)
+                       rc = -ENOMEM;
        }
 cifs_create_out:
        kfree(buf);
@@ -531,7 +557,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
                        u16 fileHandle;
                        FILE_ALL_INFO *buf;
 
-                       cFYI(1, ("sfu compat create special file"));
+                       cFYI(1, "sfu compat create special file");
 
                        buf = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
                        if (buf == NULL) {
@@ -616,8 +642,8 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
 
        xid = GetXid();
 
-       cFYI(1, ("parent inode = 0x%p name is: %s and dentry = 0x%p",
-             parent_dir_inode, direntry->d_name.name, direntry));
+       cFYI(1, "parent inode = 0x%p name is: %s and dentry = 0x%p",
+             parent_dir_inode, direntry->d_name.name, direntry);
 
        /* check whether path exists */
 
@@ -632,7 +658,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
                int i;
                for (i = 0; i < direntry->d_name.len; i++)
                        if (direntry->d_name.name[i] == '\\') {
-                               cFYI(1, ("Invalid file name"));
+                               cFYI(1, "Invalid file name");
                                FreeXid(xid);
                                return ERR_PTR(-EINVAL);
                        }
@@ -657,11 +683,11 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
        }
 
        if (direntry->d_inode != NULL) {
-               cFYI(1, ("non-NULL inode in lookup"));
+               cFYI(1, "non-NULL inode in lookup");
        } else {
-               cFYI(1, ("NULL inode in lookup"));
+               cFYI(1, "NULL inode in lookup");
        }
-       cFYI(1, ("Full path: %s inode = 0x%p", full_path, direntry->d_inode));
+       cFYI(1, "Full path: %s inode = 0x%p", full_path, direntry->d_inode);
 
        /* Posix open is only called (at lookup time) for file create now.
         * For opens (rather than creates), because we do not know if it
@@ -678,6 +704,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
                     (nd->flags & LOOKUP_OPEN) && !pTcon->broken_posix_open &&
                     (nd->intent.open.flags & O_CREAT)) {
                        rc = cifs_posix_open(full_path, &newInode, nd->path.mnt,
+                                       parent_dir_inode->i_sb,
                                        nd->intent.open.create_mode,
                                        nd->intent.open.flags, &oplock,
                                        &fileHandle, xid);
@@ -723,7 +750,7 @@ cifs_lookup(struct inode *parent_dir_inode, struct dentry *direntry,
        /*      if it was once a directory (but how can we tell?) we could do
                shrink_dcache_parent(direntry); */
        } else if (rc != -EACCES) {
-               cERROR(1, ("Unexpected lookup error %d", rc));
+               cERROR(1, "Unexpected lookup error %d", rc);
                /* We special case check for Access Denied - since that
                is a common return code */
        }
@@ -742,8 +769,8 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
                if (cifs_revalidate_dentry(direntry))
                        return 0;
        } else {
-               cFYI(1, ("neg dentry 0x%p name = %s",
-                        direntry, direntry->d_name.name));
+               cFYI(1, "neg dentry 0x%p name = %s",
+                        direntry, direntry->d_name.name);
                if (time_after(jiffies, direntry->d_time + HZ) ||
                        !lookupCacheEnabled) {
                        d_drop(direntry);
@@ -758,7 +785,7 @@ cifs_d_revalidate(struct dentry *direntry, struct nameidata *nd)
 {
        int rc = 0;
 
-       cFYI(1, ("In cifs d_delete, name = %s", direntry->d_name.name));
+       cFYI(1, "In cifs d_delete, name = %s", direntry->d_name.name);
 
        return rc;
 }     */
index 6f8a0e3..4db2c5e 100644 (file)
@@ -106,14 +106,14 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
        /* search for server name delimiter */
        len = strlen(unc);
        if (len < 3) {
-               cFYI(1, ("%s: unc is too short: %s", __func__, unc));
+               cFYI(1, "%s: unc is too short: %s", __func__, unc);
                return -EINVAL;
        }
        len -= 2;
        name = memchr(unc+2, '\\', len);
        if (!name) {
-               cFYI(1, ("%s: probably server name is whole unc: %s",
-                                       __func__, unc));
+               cFYI(1, "%s: probably server name is whole unc: %s",
+                                       __func__, unc);
        } else {
                len = (name - unc) - 2/* leading // */;
        }
@@ -127,8 +127,8 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
        name[len] = 0;
 
        if (is_ip(name)) {
-               cFYI(1, ("%s: it is IP, skipping dns upcall: %s",
-                                       __func__, name));
+               cFYI(1, "%s: it is IP, skipping dns upcall: %s",
+                                       __func__, name);
                data = name;
                goto skip_upcall;
        }
@@ -138,7 +138,7 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr)
                len = rkey->type_data.x[0];
                data = rkey->payload.data;
        } else {
-               cERROR(1, ("%s: unable to resolve: %s", __func__, name));
+               cERROR(1, "%s: unable to resolve: %s", __func__, name);
                goto out;
        }
 
@@ -148,10 +148,10 @@ skip_upcall:
                if (*ip_addr) {
                        memcpy(*ip_addr, data, len + 1);
                        if (!IS_ERR(rkey))
-                               cFYI(1, ("%s: resolved: %s to %s", __func__,
+                               cFYI(1, "%s: resolved: %s to %s", __func__,
                                                        name,
                                                        *ip_addr
-                                       ));
+                                       );
                        rc = 0;
                } else {
                        rc = -ENOMEM;
index 6177f7c..993f820 100644 (file)
@@ -49,7 +49,7 @@
 static struct dentry *cifs_get_parent(struct dentry *dentry)
 {
        /* BB need to add code here eventually to enable export via NFSD */
-       cFYI(1, ("get parent for %p", dentry));
+       cFYI(1, "get parent for %p", dentry);
        return ERR_PTR(-EACCES);
 }
 
index 9b11a8f..a83541e 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   vfs operations that deal with files
  *
- *   Copyright (C) International Business Machines  Corp., 2002,2007
+ *   Copyright (C) International Business Machines  Corp., 2002,2010
  *   Author(s): Steve French (sfrench@us.ibm.com)
  *              Jeremy Allison (jra@samba.org)
  *
@@ -108,8 +108,7 @@ static inline int cifs_get_disposition(unsigned int flags)
 /* all arguments to this function must be checked for validity in caller */
 static inline int
 cifs_posix_open_inode_helper(struct inode *inode, struct file *file,
-                            struct cifsInodeInfo *pCifsInode,
-                            struct cifsFileInfo *pCifsFile, __u32 oplock,
+                            struct cifsInodeInfo *pCifsInode, __u32 oplock,
                             u16 netfid)
 {
 
@@ -136,15 +135,15 @@ cifs_posix_open_inode_helper(struct inode *inode, struct file *file,
        if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
                           (file->f_path.dentry->d_inode->i_size ==
                            (loff_t)le64_to_cpu(buf->EndOfFile))) {
-               cFYI(1, ("inode unchanged on server"));
+               cFYI(1, "inode unchanged on server");
        } else {
                if (file->f_path.dentry->d_inode->i_mapping) {
                        rc = filemap_write_and_wait(file->f_path.dentry->d_inode->i_mapping);
                        if (rc != 0)
                                CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc;
                }
-               cFYI(1, ("invalidating remote inode since open detected it "
-                        "changed"));
+               cFYI(1, "invalidating remote inode since open detected it "
+                        "changed");
                invalidate_remote_inode(file->f_path.dentry->d_inode);
        } */
 
@@ -152,8 +151,8 @@ psx_client_can_cache:
        if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
                pCifsInode->clientCanCacheAll = true;
                pCifsInode->clientCanCacheRead = true;
-               cFYI(1, ("Exclusive Oplock granted on inode %p",
-                        file->f_path.dentry->d_inode));
+               cFYI(1, "Exclusive Oplock granted on inode %p",
+                        file->f_path.dentry->d_inode);
        } else if ((oplock & 0xF) == OPLOCK_READ)
                pCifsInode->clientCanCacheRead = true;
 
@@ -190,8 +189,8 @@ cifs_fill_filedata(struct file *file)
        if (file->private_data != NULL) {
                return pCifsFile;
        } else if ((file->f_flags & O_CREAT) && (file->f_flags & O_EXCL))
-                       cERROR(1, ("could not find file instance for "
-                                  "new file %p", file));
+                       cERROR(1, "could not find file instance for "
+                                  "new file %p", file);
        return NULL;
 }
 
@@ -217,7 +216,7 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
        if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
                           (file->f_path.dentry->d_inode->i_size ==
                            (loff_t)le64_to_cpu(buf->EndOfFile))) {
-               cFYI(1, ("inode unchanged on server"));
+               cFYI(1, "inode unchanged on server");
        } else {
                if (file->f_path.dentry->d_inode->i_mapping) {
                        /* BB no need to lock inode until after invalidate
@@ -226,8 +225,8 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
                        if (rc != 0)
                                CIFS_I(file->f_path.dentry->d_inode)->write_behind_rc = rc;
                }
-               cFYI(1, ("invalidating remote inode since open detected it "
-                        "changed"));
+               cFYI(1, "invalidating remote inode since open detected it "
+                        "changed");
                invalidate_remote_inode(file->f_path.dentry->d_inode);
        }
 
@@ -242,8 +241,8 @@ client_can_cache:
        if ((*oplock & 0xF) == OPLOCK_EXCLUSIVE) {
                pCifsInode->clientCanCacheAll = true;
                pCifsInode->clientCanCacheRead = true;
-               cFYI(1, ("Exclusive Oplock granted on inode %p",
-                        file->f_path.dentry->d_inode));
+               cFYI(1, "Exclusive Oplock granted on inode %p",
+                        file->f_path.dentry->d_inode);
        } else if ((*oplock & 0xF) == OPLOCK_READ)
                pCifsInode->clientCanCacheRead = true;
 
@@ -285,8 +284,8 @@ int cifs_open(struct inode *inode, struct file *file)
                return rc;
        }
 
-       cFYI(1, ("inode = 0x%p file flags are 0x%x for %s",
-                inode, file->f_flags, full_path));
+       cFYI(1, "inode = 0x%p file flags are 0x%x for %s",
+                inode, file->f_flags, full_path);
 
        if (oplockEnabled)
                oplock = REQ_OPLOCK;
@@ -298,27 +297,29 @@ int cifs_open(struct inode *inode, struct file *file)
            (CIFS_UNIX_POSIX_PATH_OPS_CAP &
                        le64_to_cpu(tcon->fsUnixInfo.Capability))) {
                int oflags = (int) cifs_posix_convert_flags(file->f_flags);
+               oflags |= SMB_O_CREAT;
                /* can not refresh inode info since size could be stale */
                rc = cifs_posix_open(full_path, &inode, file->f_path.mnt,
-                                    cifs_sb->mnt_file_mode /* ignored */,
-                                    oflags, &oplock, &netfid, xid);
+                               inode->i_sb,
+                               cifs_sb->mnt_file_mode /* ignored */,
+                               oflags, &oplock, &netfid, xid);
                if (rc == 0) {
-                       cFYI(1, ("posix open succeeded"));
+                       cFYI(1, "posix open succeeded");
                        /* no need for special case handling of setting mode
                           on read only files needed here */
 
                        pCifsFile = cifs_fill_filedata(file);
                        cifs_posix_open_inode_helper(inode, file, pCifsInode,
-                                                    pCifsFile, oplock, netfid);
+                                                    oplock, netfid);
                        goto out;
                } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
                        if (tcon->ses->serverNOS)
-                               cERROR(1, ("server %s of type %s returned"
+                               cERROR(1, "server %s of type %s returned"
                                           " unexpected error on SMB posix open"
                                           ", disabling posix open support."
                                           " Check if server update available.",
                                           tcon->ses->serverName,
-                                          tcon->ses->serverNOS));
+                                          tcon->ses->serverNOS);
                        tcon->broken_posix_open = true;
                } else if ((rc != -EIO) && (rc != -EREMOTE) &&
                         (rc != -EOPNOTSUPP)) /* path not found or net err */
@@ -386,7 +387,7 @@ int cifs_open(struct inode *inode, struct file *file)
                                & CIFS_MOUNT_MAP_SPECIAL_CHR);
        }
        if (rc) {
-               cFYI(1, ("cifs_open returned 0x%x", rc));
+               cFYI(1, "cifs_open returned 0x%x", rc);
                goto out;
        }
 
@@ -469,7 +470,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
        }
 
        if (file->f_path.dentry == NULL) {
-               cERROR(1, ("no valid name if dentry freed"));
+               cERROR(1, "no valid name if dentry freed");
                dump_stack();
                rc = -EBADF;
                goto reopen_error_exit;
@@ -477,7 +478,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
 
        inode = file->f_path.dentry->d_inode;
        if (inode == NULL) {
-               cERROR(1, ("inode not valid"));
+               cERROR(1, "inode not valid");
                dump_stack();
                rc = -EBADF;
                goto reopen_error_exit;
@@ -499,8 +500,8 @@ reopen_error_exit:
                return rc;
        }
 
-       cFYI(1, ("inode = 0x%p file flags 0x%x for %s",
-                inode, file->f_flags, full_path));
+       cFYI(1, "inode = 0x%p file flags 0x%x for %s",
+                inode, file->f_flags, full_path);
 
        if (oplockEnabled)
                oplock = REQ_OPLOCK;
@@ -513,10 +514,11 @@ reopen_error_exit:
                int oflags = (int) cifs_posix_convert_flags(file->f_flags);
                /* can not refresh inode info since size could be stale */
                rc = cifs_posix_open(full_path, NULL, file->f_path.mnt,
-                                    cifs_sb->mnt_file_mode /* ignored */,
-                                    oflags, &oplock, &netfid, xid);
+                               inode->i_sb,
+                               cifs_sb->mnt_file_mode /* ignored */,
+                               oflags, &oplock, &netfid, xid);
                if (rc == 0) {
-                       cFYI(1, ("posix reopen succeeded"));
+                       cFYI(1, "posix reopen succeeded");
                        goto reopen_success;
                }
                /* fallthrough to retry open the old way on errors, especially
@@ -537,8 +539,8 @@ reopen_error_exit:
                                CIFS_MOUNT_MAP_SPECIAL_CHR);
        if (rc) {
                mutex_unlock(&pCifsFile->fh_mutex);
-               cFYI(1, ("cifs_open returned 0x%x", rc));
-               cFYI(1, ("oplock: %d", oplock));
+               cFYI(1, "cifs_open returned 0x%x", rc);
+               cFYI(1, "oplock: %d", oplock);
        } else {
 reopen_success:
                pCifsFile->netfid = netfid;
@@ -570,8 +572,8 @@ reopen_success:
                        if ((oplock & 0xF) == OPLOCK_EXCLUSIVE) {
                                pCifsInode->clientCanCacheAll = true;
                                pCifsInode->clientCanCacheRead = true;
-                               cFYI(1, ("Exclusive Oplock granted on inode %p",
-                                        file->f_path.dentry->d_inode));
+                               cFYI(1, "Exclusive Oplock granted on inode %p",
+                                        file->f_path.dentry->d_inode);
                        } else if ((oplock & 0xF) == OPLOCK_READ) {
                                pCifsInode->clientCanCacheRead = true;
                                pCifsInode->clientCanCacheAll = false;
@@ -619,8 +621,7 @@ int cifs_close(struct inode *inode, struct file *file)
                                        the struct would be in each open file,
                                        but this should give enough time to
                                        clear the socket */
-                                       cFYI(DBG2,
-                                               ("close delay, write pending"));
+                                       cFYI(DBG2, "close delay, write pending");
                                        msleep(timeout);
                                        timeout *= 4;
                                }
@@ -653,7 +654,7 @@ int cifs_close(struct inode *inode, struct file *file)
 
        read_lock(&GlobalSMBSeslock);
        if (list_empty(&(CIFS_I(inode)->openFileList))) {
-               cFYI(1, ("closing last open instance for inode %p", inode));
+               cFYI(1, "closing last open instance for inode %p", inode);
                /* if the file is not open we do not know if we can cache info
                   on this inode, much less write behind and read ahead */
                CIFS_I(inode)->clientCanCacheRead = false;
@@ -674,7 +675,7 @@ int cifs_closedir(struct inode *inode, struct file *file)
            (struct cifsFileInfo *)file->private_data;
        char *ptmp;
 
-       cFYI(1, ("Closedir inode = 0x%p", inode));
+       cFYI(1, "Closedir inode = 0x%p", inode);
 
        xid = GetXid();
 
@@ -685,22 +686,22 @@ int cifs_closedir(struct inode *inode, struct file *file)
 
                pTcon = cifs_sb->tcon;
 
-               cFYI(1, ("Freeing private data in close dir"));
+               cFYI(1, "Freeing private data in close dir");
                write_lock(&GlobalSMBSeslock);
                if (!pCFileStruct->srch_inf.endOfSearch &&
                    !pCFileStruct->invalidHandle) {
                        pCFileStruct->invalidHandle = true;
                        write_unlock(&GlobalSMBSeslock);
                        rc = CIFSFindClose(xid, pTcon, pCFileStruct->netfid);
-                       cFYI(1, ("Closing uncompleted readdir with rc %d",
-                                rc));
+                       cFYI(1, "Closing uncompleted readdir with rc %d",
+                                rc);
                        /* not much we can do if it fails anyway, ignore rc */
                        rc = 0;
                } else
                        write_unlock(&GlobalSMBSeslock);
                ptmp = pCFileStruct->srch_inf.ntwrk_buf_start;
                if (ptmp) {
-                       cFYI(1, ("closedir free smb buf in srch struct"));
+                       cFYI(1, "closedir free smb buf in srch struct");
                        pCFileStruct->srch_inf.ntwrk_buf_start = NULL;
                        if (pCFileStruct->srch_inf.smallBuf)
                                cifs_small_buf_release(ptmp);
@@ -748,49 +749,49 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
        rc = -EACCES;
        xid = GetXid();
 
-       cFYI(1, ("Lock parm: 0x%x flockflags: "
+       cFYI(1, "Lock parm: 0x%x flockflags: "
                 "0x%x flocktype: 0x%x start: %lld end: %lld",
                cmd, pfLock->fl_flags, pfLock->fl_type, pfLock->fl_start,
-               pfLock->fl_end));
+               pfLock->fl_end);
 
        if (pfLock->fl_flags & FL_POSIX)
-               cFYI(1, ("Posix"));
+               cFYI(1, "Posix");
        if (pfLock->fl_flags & FL_FLOCK)
-               cFYI(1, ("Flock"));
+               cFYI(1, "Flock");
        if (pfLock->fl_flags & FL_SLEEP) {
-               cFYI(1, ("Blocking lock"));
+               cFYI(1, "Blocking lock");
                wait_flag = true;
        }
        if (pfLock->fl_flags & FL_ACCESS)
-               cFYI(1, ("Process suspended by mandatory locking - "
-                        "not implemented yet"));
+               cFYI(1, "Process suspended by mandatory locking - "
+                        "not implemented yet");
        if (pfLock->fl_flags & FL_LEASE)
-               cFYI(1, ("Lease on file - not implemented yet"));
+               cFYI(1, "Lease on file - not implemented yet");
        if (pfLock->fl_flags &
            (~(FL_POSIX | FL_FLOCK | FL_SLEEP | FL_ACCESS | FL_LEASE)))
-               cFYI(1, ("Unknown lock flags 0x%x", pfLock->fl_flags));
+               cFYI(1, "Unknown lock flags 0x%x", pfLock->fl_flags);
 
        if (pfLock->fl_type == F_WRLCK) {
-               cFYI(1, ("F_WRLCK "));
+               cFYI(1, "F_WRLCK ");
                numLock = 1;
        } else if (pfLock->fl_type == F_UNLCK) {
-               cFYI(1, ("F_UNLCK"));
+               cFYI(1, "F_UNLCK");
                numUnlock = 1;
                /* Check if unlock includes more than
                one lock range */
        } else if (pfLock->fl_type == F_RDLCK) {
-               cFYI(1, ("F_RDLCK"));
+               cFYI(1, "F_RDLCK");
                lockType |= LOCKING_ANDX_SHARED_LOCK;
                numLock = 1;
        } else if (pfLock->fl_type == F_EXLCK) {
-               cFYI(1, ("F_EXLCK"));
+               cFYI(1, "F_EXLCK");
                numLock = 1;
        } else if (pfLock->fl_type == F_SHLCK) {
-               cFYI(1, ("F_SHLCK"));
+               cFYI(1, "F_SHLCK");
                lockType |= LOCKING_ANDX_SHARED_LOCK;
                numLock = 1;
        } else
-               cFYI(1, ("Unknown type of lock"));
+               cFYI(1, "Unknown type of lock");
 
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        tcon = cifs_sb->tcon;
@@ -833,8 +834,8 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
                                         0 /* wait flag */ );
                        pfLock->fl_type = F_UNLCK;
                        if (rc != 0)
-                               cERROR(1, ("Error unlocking previously locked "
-                                          "range %d during test of lock", rc));
+                               cERROR(1, "Error unlocking previously locked "
+                                          "range %d during test of lock", rc);
                        rc = 0;
 
                } else {
@@ -856,9 +857,9 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
                                                0 /* wait flag */);
                                        pfLock->fl_type = F_RDLCK;
                                        if (rc != 0)
-                                               cERROR(1, ("Error unlocking "
+                                               cERROR(1, "Error unlocking "
                                                "previously locked range %d "
-                                               "during test of lock", rc));
+                                               "during test of lock", rc);
                                        rc = 0;
                                } else {
                                        pfLock->fl_type = F_WRLCK;
@@ -923,9 +924,10 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
                                                        1, 0, li->type, false);
                                        if (stored_rc)
                                                rc = stored_rc;
-
-                                       list_del(&li->llist);
-                                       kfree(li);
+                                       else {
+                                               list_del(&li->llist);
+                                               kfree(li);
+                                       }
                                }
                        }
                        mutex_unlock(&fid->lock_mutex);
@@ -988,9 +990,8 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
 
        pTcon = cifs_sb->tcon;
 
-       /* cFYI(1,
-          (" write %d bytes to offset %lld of %s", write_size,
-          *poffset, file->f_path.dentry->d_name.name)); */
+       /* cFYI(1, " write %d bytes to offset %lld of %s", write_size,
+          *poffset, file->f_path.dentry->d_name.name); */
 
        if (file->private_data == NULL)
                return -EBADF;
@@ -1091,8 +1092,8 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
 
        pTcon = cifs_sb->tcon;
 
-       cFYI(1, ("write %zd bytes to offset %lld of %s", write_size,
-          *poffset, file->f_path.dentry->d_name.name));
+       cFYI(1, "write %zd bytes to offset %lld of %s", write_size,
+          *poffset, file->f_path.dentry->d_name.name);
 
        if (file->private_data == NULL)
                return -EBADF;
@@ -1233,7 +1234,7 @@ struct cifsFileInfo *find_writable_file(struct cifsInodeInfo *cifs_inode)
        it being zero) during stress testcases so we need to check for it */
 
        if (cifs_inode == NULL) {
-               cERROR(1, ("Null inode passed to cifs_writeable_file"));
+               cERROR(1, "Null inode passed to cifs_writeable_file");
                dump_stack();
                return NULL;
        }
@@ -1277,7 +1278,7 @@ refind_writable:
                        again. Note that it would be bad
                        to hold up writepages here (rather than
                        in caller) with continuous retries */
-                       cFYI(1, ("wp failed on reopen file"));
+                       cFYI(1, "wp failed on reopen file");
                        read_lock(&GlobalSMBSeslock);
                        /* can not use this handle, no write
                           pending on this one after all */
@@ -1353,7 +1354,7 @@ static int cifs_partialpagewrite(struct page *page, unsigned from, unsigned to)
                else if (bytes_written < 0)
                        rc = bytes_written;
        } else {
-               cFYI(1, ("No writeable filehandles for inode"));
+               cFYI(1, "No writeable filehandles for inode");
                rc = -EIO;
        }
 
@@ -1525,7 +1526,7 @@ retry:
                         */
                        open_file = find_writable_file(CIFS_I(mapping->host));
                        if (!open_file) {
-                               cERROR(1, ("No writable handles for inode"));
+                               cERROR(1, "No writable handles for inode");
                                rc = -EBADF;
                        } else {
                                long_op = cifs_write_timeout(cifsi, offset);
@@ -1538,8 +1539,8 @@ retry:
                                cifs_update_eof(cifsi, offset, bytes_written);
 
                                if (rc || bytes_written < bytes_to_write) {
-                                       cERROR(1, ("Write2 ret %d, wrote %d",
-                                                 rc, bytes_written));
+                                       cERROR(1, "Write2 ret %d, wrote %d",
+                                                 rc, bytes_written);
                                        /* BB what if continued retry is
                                           requested via mount flags? */
                                        if (rc == -ENOSPC)
@@ -1600,7 +1601,7 @@ static int cifs_writepage(struct page *page, struct writeback_control *wbc)
 /* BB add check for wbc flags */
        page_cache_get(page);
        if (!PageUptodate(page))
-               cFYI(1, ("ppw - page not up to date"));
+               cFYI(1, "ppw - page not up to date");
 
        /*
         * Set the "writeback" flag, and clear "dirty" in the radix tree.
@@ -1629,8 +1630,8 @@ static int cifs_write_end(struct file *file, struct address_space *mapping,
        int rc;
        struct inode *inode = mapping->host;
 
-       cFYI(1, ("write_end for page %p from pos %lld with %d bytes",
-                page, pos, copied));
+       cFYI(1, "write_end for page %p from pos %lld with %d bytes",
+                page, pos, copied);
 
        if (PageChecked(page)) {
                if (copied == len)
@@ -1686,8 +1687,8 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
 
        xid = GetXid();
 
-       cFYI(1, ("Sync file - name: %s datasync: 0x%x",
-               dentry->d_name.name, datasync));
+       cFYI(1, "Sync file - name: %s datasync: 0x%x",
+               dentry->d_name.name, datasync);
 
        rc = filemap_write_and_wait(inode->i_mapping);
        if (rc == 0) {
@@ -1711,7 +1712,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
        unsigned int rpages = 0;
        int rc = 0;
 
-       cFYI(1, ("sync page %p",page));
+       cFYI(1, "sync page %p", page);
        mapping = page->mapping;
        if (!mapping)
                return 0;
@@ -1722,7 +1723,7 @@ int cifs_fsync(struct file *file, struct dentry *dentry, int datasync)
 /*     fill in rpages then
        result = cifs_pagein_inode(inode, index, rpages); */ /* BB finish */
 
-/*     cFYI(1, ("rpages is %d for sync page of Index %ld", rpages, index));
+/*     cFYI(1, "rpages is %d for sync page of Index %ld", rpages, index);
 
 #if 0
        if (rc < 0)
@@ -1756,7 +1757,7 @@ int cifs_flush(struct file *file, fl_owner_t id)
                CIFS_I(inode)->write_behind_rc = 0;
        }
 
-       cFYI(1, ("Flush inode %p file %p rc %d", inode, file, rc));
+       cFYI(1, "Flush inode %p file %p rc %d", inode, file, rc);
 
        return rc;
 }
@@ -1788,7 +1789,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
        open_file = (struct cifsFileInfo *)file->private_data;
 
        if ((file->f_flags & O_ACCMODE) == O_WRONLY)
-               cFYI(1, ("attempting read on write only file instance"));
+               cFYI(1, "attempting read on write only file instance");
 
        for (total_read = 0, current_offset = read_data;
             read_size > total_read;
@@ -1869,7 +1870,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
        open_file = (struct cifsFileInfo *)file->private_data;
 
        if ((file->f_flags & O_ACCMODE) == O_WRONLY)
-               cFYI(1, ("attempting read on write only file instance"));
+               cFYI(1, "attempting read on write only file instance");
 
        for (total_read = 0, current_offset = read_data;
             read_size > total_read;
@@ -1920,7 +1921,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
        xid = GetXid();
        rc = cifs_revalidate_file(file);
        if (rc) {
-               cFYI(1, ("Validation prior to mmap failed, error=%d", rc));
+               cFYI(1, "Validation prior to mmap failed, error=%d", rc);
                FreeXid(xid);
                return rc;
        }
@@ -1931,8 +1932,7 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma)
 
 
 static void cifs_copy_cache_pages(struct address_space *mapping,
-       struct list_head *pages, int bytes_read, char *data,
-       struct pagevec *plru_pvec)
+       struct list_head *pages, int bytes_read, char *data)
 {
        struct page *page;
        char *target;
@@ -1944,10 +1944,10 @@ static void cifs_copy_cache_pages(struct address_space *mapping,
                page = list_entry(pages->prev, struct page, lru);
                list_del(&page->lru);
 
-               if (add_to_page_cache(page, mapping, page->index,
+               if (add_to_page_cache_lru(page, mapping, page->index,
                                      GFP_KERNEL)) {
                        page_cache_release(page);
-                       cFYI(1, ("Add page cache failed"));
+                       cFYI(1, "Add page cache failed");
                        data += PAGE_CACHE_SIZE;
                        bytes_read -= PAGE_CACHE_SIZE;
                        continue;
@@ -1970,8 +1970,6 @@ static void cifs_copy_cache_pages(struct address_space *mapping,
                flush_dcache_page(page);
                SetPageUptodate(page);
                unlock_page(page);
-               if (!pagevec_add(plru_pvec, page))
-                       __pagevec_lru_add_file(plru_pvec);
                data += PAGE_CACHE_SIZE;
        }
        return;
@@ -1990,7 +1988,6 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
        unsigned int read_size, i;
        char *smb_read_data = NULL;
        struct smb_com_read_rsp *pSMBr;
-       struct pagevec lru_pvec;
        struct cifsFileInfo *open_file;
        int buf_type = CIFS_NO_BUFFER;
 
@@ -2004,8 +2001,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        pTcon = cifs_sb->tcon;
 
-       pagevec_init(&lru_pvec, 0);
-       cFYI(DBG2, ("rpages: num pages %d", num_pages));
+       cFYI(DBG2, "rpages: num pages %d", num_pages);
        for (i = 0; i < num_pages; ) {
                unsigned contig_pages;
                struct page *tmp_page;
@@ -2038,8 +2034,8 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                /* Read size needs to be in multiples of one page */
                read_size = min_t(const unsigned int, read_size,
                                  cifs_sb->rsize & PAGE_CACHE_MASK);
-               cFYI(DBG2, ("rpages: read size 0x%x  contiguous pages %d",
-                               read_size, contig_pages));
+               cFYI(DBG2, "rpages: read size 0x%x  contiguous pages %d",
+                               read_size, contig_pages);
                rc = -EAGAIN;
                while (rc == -EAGAIN) {
                        if ((open_file->invalidHandle) &&
@@ -2066,14 +2062,14 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                        }
                }
                if ((rc < 0) || (smb_read_data == NULL)) {
-                       cFYI(1, ("Read error in readpages: %d", rc));
+                       cFYI(1, "Read error in readpages: %d", rc);
                        break;
                } else if (bytes_read > 0) {
                        task_io_account_read(bytes_read);
                        pSMBr = (struct smb_com_read_rsp *)smb_read_data;
                        cifs_copy_cache_pages(mapping, page_list, bytes_read,
                                smb_read_data + 4 /* RFC1001 hdr */ +
-                               le16_to_cpu(pSMBr->DataOffset), &lru_pvec);
+                               le16_to_cpu(pSMBr->DataOffset));
 
                        i +=  bytes_read >> PAGE_CACHE_SHIFT;
                        cifs_stats_bytes_read(pTcon, bytes_read);
@@ -2089,9 +2085,9 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                                /* break; */
                        }
                } else {
-                       cFYI(1, ("No bytes read (%d) at offset %lld . "
-                                "Cleaning remaining pages from readahead list",
-                                bytes_read, offset));
+                       cFYI(1, "No bytes read (%d) at offset %lld . "
+                               "Cleaning remaining pages from readahead list",
+                               bytes_read, offset);
                        /* BB turn off caching and do new lookup on
                           file size at server? */
                        break;
@@ -2106,8 +2102,6 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                bytes_read = 0;
        }
 
-       pagevec_lru_add_file(&lru_pvec);
-
 /* need to free smb_read_data buf before exit */
        if (smb_read_data) {
                if (buf_type == CIFS_SMALL_BUFFER)
@@ -2136,7 +2130,7 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
        if (rc < 0)
                goto io_error;
        else
-               cFYI(1, ("Bytes read %d", rc));
+               cFYI(1, "Bytes read %d", rc);
 
        file->f_path.dentry->d_inode->i_atime =
                current_fs_time(file->f_path.dentry->d_inode->i_sb);
@@ -2168,8 +2162,8 @@ static int cifs_readpage(struct file *file, struct page *page)
                return rc;
        }
 
-       cFYI(1, ("readpage %p at offset %d 0x%x\n",
-                page, (int)offset, (int)offset));
+       cFYI(1, "readpage %p at offset %d 0x%x\n",
+                page, (int)offset, (int)offset);
 
        rc = cifs_readpage_worker(file, page, &offset);
 
@@ -2239,7 +2233,7 @@ static int cifs_write_begin(struct file *file, struct address_space *mapping,
        struct page *page;
        int rc = 0;
 
-       cFYI(1, ("write_begin from %lld len %d", (long long)pos, len));
+       cFYI(1, "write_begin from %lld len %d", (long long)pos, len);
 
        page = grab_cache_page_write_begin(mapping, index, flags);
        if (!page) {
@@ -2311,12 +2305,10 @@ cifs_oplock_break(struct slow_work *work)
        int rc, waitrc = 0;
 
        if (inode && S_ISREG(inode->i_mode)) {
-#ifdef CONFIG_CIFS_EXPERIMENTAL
-               if (cinode->clientCanCacheAll == 0)
+               if (cinode->clientCanCacheRead)
                        break_lease(inode, O_RDONLY);
-               else if (cinode->clientCanCacheRead == 0)
+               else
                        break_lease(inode, O_WRONLY);
-#endif
                rc = filemap_fdatawrite(inode->i_mapping);
                if (cinode->clientCanCacheRead == 0) {
                        waitrc = filemap_fdatawait(inode->i_mapping);
@@ -2326,7 +2318,7 @@ cifs_oplock_break(struct slow_work *work)
                        rc = waitrc;
                if (rc)
                        cinode->write_behind_rc = rc;
-               cFYI(1, ("Oplock flush inode %p rc %d", inode, rc));
+               cFYI(1, "Oplock flush inode %p rc %d", inode, rc);
        }
 
        /*
@@ -2338,7 +2330,7 @@ cifs_oplock_break(struct slow_work *work)
        if (!cfile->closePend && !cfile->oplock_break_cancelled) {
                rc = CIFSSMBLock(0, cifs_sb->tcon, cfile->netfid, 0, 0, 0, 0,
                                 LOCKING_ANDX_OPLOCK_RELEASE, false);
-               cFYI(1, ("Oplock release rc = %d", rc));
+               cFYI(1, "Oplock release rc = %d", rc);
        }
 }
 
index 29b9ea2..62b324f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   fs/cifs/inode.c
  *
- *   Copyright (C) International Business Machines  Corp., 2002,2008
+ *   Copyright (C) International Business Machines  Corp., 2002,2010
  *   Author(s): Steve French (sfrench@us.ibm.com)
  *
  *   This library is free software; you can redistribute it and/or modify
@@ -86,30 +86,30 @@ cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr)
 {
        struct cifsInodeInfo *cifs_i = CIFS_I(inode);
 
-       cFYI(1, ("%s: revalidating inode %llu", __func__, cifs_i->uniqueid));
+       cFYI(1, "%s: revalidating inode %llu", __func__, cifs_i->uniqueid);
 
        if (inode->i_state & I_NEW) {
-               cFYI(1, ("%s: inode %llu is new", __func__, cifs_i->uniqueid));
+               cFYI(1, "%s: inode %llu is new", __func__, cifs_i->uniqueid);
                return;
        }
 
        /* don't bother with revalidation if we have an oplock */
        if (cifs_i->clientCanCacheRead) {
-               cFYI(1, ("%s: inode %llu is oplocked", __func__,
-                        cifs_i->uniqueid));
+               cFYI(1, "%s: inode %llu is oplocked", __func__,
+                        cifs_i->uniqueid);
                return;
        }
 
         /* revalidate if mtime or size have changed */
        if (timespec_equal(&inode->i_mtime, &fattr->cf_mtime) &&
            cifs_i->server_eof == fattr->cf_eof) {
-               cFYI(1, ("%s: inode %llu is unchanged", __func__,
-                        cifs_i->uniqueid));
+               cFYI(1, "%s: inode %llu is unchanged", __func__,
+                        cifs_i->uniqueid);
                return;
        }
 
-       cFYI(1, ("%s: invalidating inode %llu mapping", __func__,
-                cifs_i->uniqueid));
+       cFYI(1, "%s: invalidating inode %llu mapping", __func__,
+                cifs_i->uniqueid);
        cifs_i->invalid_mapping = true;
 }
 
@@ -137,15 +137,14 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
                inode->i_mode = fattr->cf_mode;
 
        cifs_i->cifsAttrs = fattr->cf_cifsattrs;
-       cifs_i->uniqueid = fattr->cf_uniqueid;
 
        if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
                cifs_i->time = 0;
        else
                cifs_i->time = jiffies;
 
-       cFYI(1, ("inode 0x%p old_time=%ld new_time=%ld", inode,
-                oldtime, cifs_i->time));
+       cFYI(1, "inode 0x%p old_time=%ld new_time=%ld", inode,
+                oldtime, cifs_i->time);
 
        cifs_i->delete_pending = fattr->cf_flags & CIFS_FATTR_DELETE_PENDING;
 
@@ -170,6 +169,17 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
        cifs_set_ops(inode, fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL);
 }
 
+void
+cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr)
+{
+       struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
+
+       if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
+               return;
+
+       fattr->cf_uniqueid = iunique(sb, ROOT_I);
+}
+
 /* Fill a cifs_fattr struct with info from FILE_UNIX_BASIC_INFO. */
 void
 cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info,
@@ -227,7 +237,7 @@ cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info,
                /* safest to call it a file if we do not know */
                fattr->cf_mode |= S_IFREG;
                fattr->cf_dtype = DT_REG;
-               cFYI(1, ("unknown type %d", le32_to_cpu(info->Type)));
+               cFYI(1, "unknown type %d", le32_to_cpu(info->Type));
                break;
        }
 
@@ -256,7 +266,7 @@ cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
 {
        struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
 
-       cFYI(1, ("creating fake fattr for DFS referral"));
+       cFYI(1, "creating fake fattr for DFS referral");
 
        memset(fattr, 0, sizeof(*fattr));
        fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
@@ -305,7 +315,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
        struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
 
        tcon = cifs_sb->tcon;
-       cFYI(1, ("Getting info on %s", full_path));
+       cFYI(1, "Getting info on %s", full_path);
 
        /* could have done a find first instead but this returns more info */
        rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data,
@@ -323,6 +333,7 @@ int cifs_get_inode_info_unix(struct inode **pinode,
 
        if (*pinode == NULL) {
                /* get new inode */
+               cifs_fill_uniqueid(sb, &fattr);
                *pinode = cifs_iget(sb, &fattr);
                if (!*pinode)
                        rc = -ENOMEM;
@@ -373,7 +384,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
                                 &bytes_read, &pbuf, &buf_type);
                if ((rc == 0) && (bytes_read >= 8)) {
                        if (memcmp("IntxBLK", pbuf, 8) == 0) {
-                               cFYI(1, ("Block device"));
+                               cFYI(1, "Block device");
                                fattr->cf_mode |= S_IFBLK;
                                fattr->cf_dtype = DT_BLK;
                                if (bytes_read == 24) {
@@ -385,7 +396,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
                                        fattr->cf_rdev = MKDEV(mjr, mnr);
                                }
                        } else if (memcmp("IntxCHR", pbuf, 8) == 0) {
-                               cFYI(1, ("Char device"));
+                               cFYI(1, "Char device");
                                fattr->cf_mode |= S_IFCHR;
                                fattr->cf_dtype = DT_CHR;
                                if (bytes_read == 24) {
@@ -397,7 +408,7 @@ cifs_sfu_type(struct cifs_fattr *fattr, const unsigned char *path,
                                        fattr->cf_rdev = MKDEV(mjr, mnr);
                                }
                        } else if (memcmp("IntxLNK", pbuf, 7) == 0) {
-                               cFYI(1, ("Symlink"));
+                               cFYI(1, "Symlink");
                                fattr->cf_mode |= S_IFLNK;
                                fattr->cf_dtype = DT_LNK;
                        } else {
@@ -439,10 +450,10 @@ static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
        else if (rc > 3) {
                mode = le32_to_cpu(*((__le32 *)ea_value));
                fattr->cf_mode &= ~SFBITS_MASK;
-               cFYI(1, ("special bits 0%o org mode 0%o", mode,
-                        fattr->cf_mode));
+               cFYI(1, "special bits 0%o org mode 0%o", mode,
+                        fattr->cf_mode);
                fattr->cf_mode = (mode & SFBITS_MASK) | fattr->cf_mode;
-               cFYI(1, ("special mode bits 0%o", mode));
+               cFYI(1, "special mode bits 0%o", mode);
        }
 
        return 0;
@@ -548,11 +559,11 @@ int cifs_get_inode_info(struct inode **pinode,
        struct cifs_fattr fattr;
 
        pTcon = cifs_sb->tcon;
-       cFYI(1, ("Getting info on %s", full_path));
+       cFYI(1, "Getting info on %s", full_path);
 
        if ((pfindData == NULL) && (*pinode != NULL)) {
                if (CIFS_I(*pinode)->clientCanCacheRead) {
-                       cFYI(1, ("No need to revalidate cached inode sizes"));
+                       cFYI(1, "No need to revalidate cached inode sizes");
                        return rc;
                }
        }
@@ -618,7 +629,7 @@ int cifs_get_inode_info(struct inode **pinode,
                                        cifs_sb->mnt_cifs_flags &
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
                        if (rc1 || !fattr.cf_uniqueid) {
-                               cFYI(1, ("GetSrvInodeNum rc %d", rc1));
+                               cFYI(1, "GetSrvInodeNum rc %d", rc1);
                                fattr.cf_uniqueid = iunique(sb, ROOT_I);
                                cifs_autodisable_serverino(cifs_sb);
                        }
@@ -634,13 +645,13 @@ int cifs_get_inode_info(struct inode **pinode,
            cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
                tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid);
                if (tmprc)
-                       cFYI(1, ("cifs_sfu_type failed: %d", tmprc));
+                       cFYI(1, "cifs_sfu_type failed: %d", tmprc);
        }
 
 #ifdef CONFIG_CIFS_EXPERIMENTAL
        /* fill in 0777 bits from ACL */
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
-               cFYI(1, ("Getting mode bits from ACL"));
+               cFYI(1, "Getting mode bits from ACL");
                cifs_acl_to_fattr(cifs_sb, &fattr, *pinode, full_path, pfid);
        }
 #endif
@@ -745,7 +756,7 @@ cifs_iget(struct super_block *sb, struct cifs_fattr *fattr)
        struct inode *inode;
 
 retry_iget5_locked:
-       cFYI(1, ("looking for uniqueid=%llu", fattr->cf_uniqueid));
+       cFYI(1, "looking for uniqueid=%llu", fattr->cf_uniqueid);
 
        /* hash down to 32-bits on 32-bit arch */
        hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid);
@@ -797,7 +808,7 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
                return ERR_PTR(-ENOMEM);
 
        if (rc && cifs_sb->tcon->ipc) {
-               cFYI(1, ("ipc connection - fake read inode"));
+               cFYI(1, "ipc connection - fake read inode");
                inode->i_mode |= S_IFDIR;
                inode->i_nlink = 2;
                inode->i_op = &cifs_ipc_inode_ops;
@@ -859,7 +870,7 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid,
         * server times.
         */
        if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
-               cFYI(1, ("CIFS - CTIME changed"));
+               cFYI(1, "CIFS - CTIME changed");
                info_buf.ChangeTime =
                    cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
        } else
@@ -894,8 +905,8 @@ cifs_set_file_info(struct inode *inode, struct iattr *attrs, int xid,
                        goto out;
        }
 
-       cFYI(1, ("calling SetFileInfo since SetPathInfo for "
-                "times not supported by this server"));
+       cFYI(1, "calling SetFileInfo since SetPathInfo for "
+                "times not supported by this server");
        rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN,
                         SYNCHRONIZE | FILE_WRITE_ATTRIBUTES,
                         CREATE_NOT_DIR, &netfid, &oplock,
@@ -1053,7 +1064,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
        struct iattr *attrs = NULL;
        __u32 dosattr = 0, origattr = 0;
 
-       cFYI(1, ("cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry));
+       cFYI(1, "cifs_unlink, dir=0x%p, dentry=0x%p", dir, dentry);
 
        xid = GetXid();
 
@@ -1072,7 +1083,7 @@ int cifs_unlink(struct inode *dir, struct dentry *dentry)
                rc = CIFSPOSIXDelFile(xid, tcon, full_path,
                        SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls,
                        cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
-               cFYI(1, ("posix del rc %d", rc));
+               cFYI(1, "posix del rc %d", rc);
                if ((rc == 0) || (rc == -ENOENT))
                        goto psx_del_no_retry;
        }
@@ -1146,7 +1157,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
        struct inode *newinode = NULL;
        struct cifs_fattr fattr;
 
-       cFYI(1, ("In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode));
+       cFYI(1, "In cifs_mkdir, mode = 0x%x inode = 0x%p", mode, inode);
 
        xid = GetXid();
 
@@ -1181,7 +1192,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
                        kfree(pInfo);
                        goto mkdir_retry_old;
                } else if (rc) {
-                       cFYI(1, ("posix mkdir returned 0x%x", rc));
+                       cFYI(1, "posix mkdir returned 0x%x", rc);
                        d_drop(direntry);
                } else {
                        if (pInfo->Type == cpu_to_le32(-1)) {
@@ -1198,6 +1209,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
                                direntry->d_op = &cifs_dentry_ops;
 
                        cifs_unix_basic_to_fattr(&fattr, pInfo, cifs_sb);
+                       cifs_fill_uniqueid(inode->i_sb, &fattr);
                        newinode = cifs_iget(inode->i_sb, &fattr);
                        if (!newinode) {
                                kfree(pInfo);
@@ -1207,12 +1219,12 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
                        d_instantiate(direntry, newinode);
 
 #ifdef CONFIG_CIFS_DEBUG2
-                       cFYI(1, ("instantiated dentry %p %s to inode %p",
-                               direntry, direntry->d_name.name, newinode));
+                       cFYI(1, "instantiated dentry %p %s to inode %p",
+                               direntry, direntry->d_name.name, newinode);
 
                        if (newinode->i_nlink != 2)
-                               cFYI(1, ("unexpected number of links %d",
-                                       newinode->i_nlink));
+                               cFYI(1, "unexpected number of links %d",
+                                       newinode->i_nlink);
 #endif
                }
                kfree(pInfo);
@@ -1223,7 +1235,7 @@ mkdir_retry_old:
        rc = CIFSSMBMkDir(xid, pTcon, full_path, cifs_sb->local_nls,
                          cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
        if (rc) {
-               cFYI(1, ("cifs_mkdir returned 0x%x", rc));
+               cFYI(1, "cifs_mkdir returned 0x%x", rc);
                d_drop(direntry);
        } else {
 mkdir_get_info:
@@ -1326,7 +1338,7 @@ int cifs_rmdir(struct inode *inode, struct dentry *direntry)
        char *full_path = NULL;
        struct cifsInodeInfo *cifsInode;
 
-       cFYI(1, ("cifs_rmdir, inode = 0x%p", inode));
+       cFYI(1, "cifs_rmdir, inode = 0x%p", inode);
 
        xid = GetXid();
 
@@ -1528,6 +1540,11 @@ cifs_inode_needs_reval(struct inode *inode)
        if (time_after_eq(jiffies, cifs_i->time + HZ))
                return true;
 
+       /* hardlinked files w/ noserverino get "special" treatment */
+       if (!(CIFS_SB(inode->i_sb)->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) &&
+           S_ISREG(inode->i_mode) && inode->i_nlink != 1)
+               return true;
+
        return false;
 }
 
@@ -1594,9 +1611,9 @@ int cifs_revalidate_dentry(struct dentry *dentry)
                goto check_inval;
        }
 
-       cFYI(1, ("Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
+       cFYI(1, "Revalidate: %s inode 0x%p count %d dentry: 0x%p d_time %ld "
                 "jiffies %ld", full_path, inode, inode->i_count.counter,
-                dentry, dentry->d_time, jiffies));
+                dentry, dentry->d_time, jiffies);
 
        if (CIFS_SB(sb)->tcon->unix_ext)
                rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
@@ -1690,12 +1707,12 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
                rc = CIFSSMBSetFileSize(xid, pTcon, attrs->ia_size, nfid,
                                        npid, false);
                cifsFileInfo_put(open_file);
-               cFYI(1, ("SetFSize for attrs rc = %d", rc));
+               cFYI(1, "SetFSize for attrs rc = %d", rc);
                if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
                        unsigned int bytes_written;
                        rc = CIFSSMBWrite(xid, pTcon, nfid, 0, attrs->ia_size,
                                          &bytes_written, NULL, NULL, 1);
-                       cFYI(1, ("Wrt seteof rc %d", rc));
+                       cFYI(1, "Wrt seteof rc %d", rc);
                }
        } else
                rc = -EINVAL;
@@ -1709,7 +1726,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
                                   false, cifs_sb->local_nls,
                                   cifs_sb->mnt_cifs_flags &
                                        CIFS_MOUNT_MAP_SPECIAL_CHR);
-               cFYI(1, ("SetEOF by path (setattrs) rc = %d", rc));
+               cFYI(1, "SetEOF by path (setattrs) rc = %d", rc);
                if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
                        __u16 netfid;
                        int oplock = 0;
@@ -1726,7 +1743,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
                                                  attrs->ia_size,
                                                  &bytes_written, NULL,
                                                  NULL, 1);
-                               cFYI(1, ("wrt seteof rc %d", rc));
+                               cFYI(1, "wrt seteof rc %d", rc);
                                CIFSSMBClose(xid, pTcon, netfid);
                        }
                }
@@ -1754,8 +1771,8 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
        struct cifs_unix_set_info_args *args = NULL;
        struct cifsFileInfo *open_file;
 
-       cFYI(1, ("setattr_unix on file %s attrs->ia_valid=0x%x",
-                direntry->d_name.name, attrs->ia_valid));
+       cFYI(1, "setattr_unix on file %s attrs->ia_valid=0x%x",
+                direntry->d_name.name, attrs->ia_valid);
 
        xid = GetXid();
 
@@ -1885,8 +1902,8 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
 
        xid = GetXid();
 
-       cFYI(1, ("setattr on file %s attrs->iavalid 0x%x",
-                direntry->d_name.name, attrs->ia_valid));
+       cFYI(1, "setattr on file %s attrs->iavalid 0x%x",
+                direntry->d_name.name, attrs->ia_valid);
 
        if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM) == 0) {
                /* check if we have permission to change attrs */
@@ -1943,7 +1960,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
                attrs->ia_valid &= ~ATTR_MODE;
 
        if (attrs->ia_valid & ATTR_MODE) {
-               cFYI(1, ("Mode changed to 0%o", attrs->ia_mode));
+               cFYI(1, "Mode changed to 0%o", attrs->ia_mode);
                mode = attrs->ia_mode;
        }
 
@@ -2029,7 +2046,7 @@ cifs_setattr(struct dentry *direntry, struct iattr *attrs)
 #if 0
 void cifs_delete_inode(struct inode *inode)
 {
-       cFYI(1, ("In cifs_delete_inode, inode = 0x%p", inode));
+       cFYI(1, "In cifs_delete_inode, inode = 0x%p", inode);
        /* may have to add back in if and when safe distributed caching of
           directories added e.g. via FindNotify */
 }
index f946506..505926f 100644 (file)
@@ -47,7 +47,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
 
        xid = GetXid();
 
-       cFYI(1, ("ioctl file %p  cmd %u  arg %lu", filep, command, arg));
+       cFYI(1, "ioctl file %p  cmd %u  arg %lu", filep, command, arg);
 
        cifs_sb = CIFS_SB(inode->i_sb);
 
@@ -64,12 +64,12 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
 
        switch (command) {
                case CIFS_IOC_CHECKUMOUNT:
-                       cFYI(1, ("User unmount attempted"));
+                       cFYI(1, "User unmount attempted");
                        if (cifs_sb->mnt_uid == current_uid())
                                rc = 0;
                        else {
                                rc = -EACCES;
-                               cFYI(1, ("uids do not match"));
+                               cFYI(1, "uids do not match");
                        }
                        break;
 #ifdef CONFIG_CIFS_POSIX
@@ -97,11 +97,11 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
                                /* rc= CIFSGetExtAttr(xid,tcon,pSMBFile->netfid,
                                        extAttrBits, &ExtAttrMask);*/
                        }
-                       cFYI(1, ("set flags not implemented yet"));
+                       cFYI(1, "set flags not implemented yet");
                        break;
 #endif /* CONFIG_CIFS_POSIX */
                default:
-                       cFYI(1, ("unsupported ioctl"));
+                       cFYI(1, "unsupported ioctl");
                        break;
        }
 
index c1a9d42..473ca80 100644 (file)
@@ -139,7 +139,7 @@ cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
        if (!full_path)
                goto out;
 
-       cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode));
+       cFYI(1, "Full path: %s inode = 0x%p", full_path, inode);
 
        rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
                                     cifs_sb->local_nls);
@@ -178,8 +178,8 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
                return rc;
        }
 
-       cFYI(1, ("Full path: %s", full_path));
-       cFYI(1, ("symname is %s", symname));
+       cFYI(1, "Full path: %s", full_path);
+       cFYI(1, "symname is %s", symname);
 
        /* BB what if DFS and this volume is on different share? BB */
        if (pTcon->unix_ext)
@@ -198,8 +198,8 @@ cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
                                                 inode->i_sb, xid, NULL);
 
                if (rc != 0) {
-                       cFYI(1, ("Create symlink ok, getinodeinfo fail rc = %d",
-                             rc));
+                       cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d",
+                             rc);
                } else {
                        if (pTcon->nocase)
                                direntry->d_op = &cifs_ci_dentry_ops;
index d147499..1394aa3 100644 (file)
@@ -51,7 +51,7 @@ _GetXid(void)
        if (GlobalTotalActiveXid > GlobalMaxActiveXid)
                GlobalMaxActiveXid = GlobalTotalActiveXid;
        if (GlobalTotalActiveXid > 65000)
-               cFYI(1, ("warning: more than 65000 requests active"));
+               cFYI(1, "warning: more than 65000 requests active");
        xid = GlobalCurrentXid++;
        spin_unlock(&GlobalMid_Lock);
        return xid;
@@ -88,7 +88,7 @@ void
 sesInfoFree(struct cifsSesInfo *buf_to_free)
 {
        if (buf_to_free == NULL) {
-               cFYI(1, ("Null buffer passed to sesInfoFree"));
+               cFYI(1, "Null buffer passed to sesInfoFree");
                return;
        }
 
@@ -126,7 +126,7 @@ void
 tconInfoFree(struct cifsTconInfo *buf_to_free)
 {
        if (buf_to_free == NULL) {
-               cFYI(1, ("Null buffer passed to tconInfoFree"));
+               cFYI(1, "Null buffer passed to tconInfoFree");
                return;
        }
        atomic_dec(&tconInfoAllocCount);
@@ -166,7 +166,7 @@ void
 cifs_buf_release(void *buf_to_free)
 {
        if (buf_to_free == NULL) {
-               /* cFYI(1, ("Null buffer passed to cifs_buf_release"));*/
+               /* cFYI(1, "Null buffer passed to cifs_buf_release");*/
                return;
        }
        mempool_free(buf_to_free, cifs_req_poolp);
@@ -202,7 +202,7 @@ cifs_small_buf_release(void *buf_to_free)
 {
 
        if (buf_to_free == NULL) {
-               cFYI(1, ("Null buffer passed to cifs_small_buf_release"));
+               cFYI(1, "Null buffer passed to cifs_small_buf_release");
                return;
        }
        mempool_free(buf_to_free, cifs_sm_req_poolp);
@@ -345,19 +345,19 @@ header_assemble(struct smb_hdr *buffer, char smb_command /* command */ ,
                /*      with userid/password pairs found on the smb session   */
                /*      for other target tcp/ip addresses               BB    */
                                if (current_fsuid() != treeCon->ses->linux_uid) {
-                                       cFYI(1, ("Multiuser mode and UID "
-                                                "did not match tcon uid"));
+                                       cFYI(1, "Multiuser mode and UID "
+                                                "did not match tcon uid");
                                        read_lock(&cifs_tcp_ses_lock);
                                        list_for_each(temp_item, &treeCon->ses->server->smb_ses_list) {
                                                ses = list_entry(temp_item, struct cifsSesInfo, smb_ses_list);
                                                if (ses->linux_uid == current_fsuid()) {
                                                        if (ses->server == treeCon->ses->server) {
-                                                               cFYI(1, ("found matching uid substitute right smb_uid"));
+                                                               cFYI(1, "found matching uid substitute right smb_uid");
                                                                buffer->Uid = ses->Suid;
                                                                break;
                                                        } else {
                                /* BB eventually call cifs_setup_session here */
-                                                               cFYI(1, ("local UID found but no smb sess with this server exists"));
+                                                               cFYI(1, "local UID found but no smb sess with this server exists");
                                                        }
                                                }
                                        }
@@ -394,17 +394,16 @@ checkSMBhdr(struct smb_hdr *smb, __u16 mid)
                        if (smb->Command == SMB_COM_LOCKING_ANDX)
                                return 0;
                        else
-                               cERROR(1, ("Received Request not response"));
+                               cERROR(1, "Received Request not response");
                }
        } else { /* bad signature or mid */
                if (*(__le32 *) smb->Protocol != cpu_to_le32(0x424d53ff))
-                       cERROR(1,
-                              ("Bad protocol string signature header %x",
-                               *(unsigned int *) smb->Protocol));
+                       cERROR(1, "Bad protocol string signature header %x",
+                               *(unsigned int *) smb->Protocol);
                if (mid != smb->Mid)
-                       cERROR(1, ("Mids do not match"));
+                       cERROR(1, "Mids do not match");
        }
-       cERROR(1, ("bad smb detected. The Mid=%d", smb->Mid));
+       cERROR(1, "bad smb detected. The Mid=%d", smb->Mid);
        return 1;
 }
 
@@ -413,7 +412,7 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
 {
        __u32 len = smb->smb_buf_length;
        __u32 clc_len;  /* calculated length */
-       cFYI(0, ("checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len));
+       cFYI(0, "checkSMB Length: 0x%x, smb_buf_length: 0x%x", length, len);
 
        if (length < 2 + sizeof(struct smb_hdr)) {
                if ((length >= sizeof(struct smb_hdr) - 1)
@@ -437,15 +436,15 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
                                tmp[sizeof(struct smb_hdr)+1] = 0;
                                return 0;
                        }
-                       cERROR(1, ("rcvd invalid byte count (bcc)"));
+                       cERROR(1, "rcvd invalid byte count (bcc)");
                } else {
-                       cERROR(1, ("Length less than smb header size"));
+                       cERROR(1, "Length less than smb header size");
                }
                return 1;
        }
        if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
-               cERROR(1, ("smb length greater than MaxBufSize, mid=%d",
-                                  smb->Mid));
+               cERROR(1, "smb length greater than MaxBufSize, mid=%d",
+                                  smb->Mid);
                return 1;
        }
 
@@ -454,8 +453,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
        clc_len = smbCalcSize_LE(smb);
 
        if (4 + len != length) {
-               cERROR(1, ("Length read does not match RFC1001 length %d",
-                          len));
+               cERROR(1, "Length read does not match RFC1001 length %d",
+                          len);
                return 1;
        }
 
@@ -466,8 +465,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
                        if (((4 + len) & 0xFFFF) == (clc_len & 0xFFFF))
                                return 0; /* bcc wrapped */
                }
-               cFYI(1, ("Calculated size %d vs length %d mismatch for mid %d",
-                               clc_len, 4 + len, smb->Mid));
+               cFYI(1, "Calculated size %d vs length %d mismatch for mid %d",
+                               clc_len, 4 + len, smb->Mid);
                /* Windows XP can return a few bytes too much, presumably
                an illegal pad, at the end of byte range lock responses
                so we allow for that three byte pad, as long as actual
@@ -482,8 +481,8 @@ checkSMB(struct smb_hdr *smb, __u16 mid, unsigned int length)
                if ((4+len > clc_len) && (len <= clc_len + 512))
                        return 0;
                else {
-                       cERROR(1, ("RFC1001 size %d bigger than SMB for Mid=%d",
-                                       len, smb->Mid));
+                       cERROR(1, "RFC1001 size %d bigger than SMB for Mid=%d",
+                                       len, smb->Mid);
                        return 1;
                }
        }
@@ -501,7 +500,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
        struct cifsFileInfo *netfile;
        int rc;
 
-       cFYI(1, ("Checking for oplock break or dnotify response"));
+       cFYI(1, "Checking for oplock break or dnotify response");
        if ((pSMB->hdr.Command == SMB_COM_NT_TRANSACT) &&
           (pSMB->hdr.Flags & SMBFLG_RESPONSE)) {
                struct smb_com_transaction_change_notify_rsp *pSMBr =
@@ -513,15 +512,15 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
 
                        pnotify = (struct file_notify_information *)
                                ((char *)&pSMBr->hdr.Protocol + data_offset);
-                       cFYI(1, ("dnotify on %s Action: 0x%x",
-                                pnotify->FileName, pnotify->Action));
+                       cFYI(1, "dnotify on %s Action: 0x%x",
+                                pnotify->FileName, pnotify->Action);
                        /*   cifs_dump_mem("Rcvd notify Data: ",buf,
                                sizeof(struct smb_hdr)+60); */
                        return true;
                }
                if (pSMBr->hdr.Status.CifsError) {
-                       cFYI(1, ("notify err 0x%d",
-                               pSMBr->hdr.Status.CifsError));
+                       cFYI(1, "notify err 0x%d",
+                               pSMBr->hdr.Status.CifsError);
                        return true;
                }
                return false;
@@ -535,7 +534,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
                   large dirty files cached on the client */
                if ((NT_STATUS_INVALID_HANDLE) ==
                   le32_to_cpu(pSMB->hdr.Status.CifsError)) {
-                       cFYI(1, ("invalid handle on oplock break"));
+                       cFYI(1, "invalid handle on oplock break");
                        return true;
                } else if (ERRbadfid ==
                   le16_to_cpu(pSMB->hdr.Status.DosError.Error)) {
@@ -547,8 +546,8 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
        if (pSMB->hdr.WordCount != 8)
                return false;
 
-       cFYI(1, ("oplock type 0x%d level 0x%d",
-                pSMB->LockType, pSMB->OplockLevel));
+       cFYI(1, "oplock type 0x%d level 0x%d",
+                pSMB->LockType, pSMB->OplockLevel);
        if (!(pSMB->LockType & LOCKING_ANDX_OPLOCK_RELEASE))
                return false;
 
@@ -579,15 +578,15 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
                                        return true;
                                }
 
-                               cFYI(1, ("file id match, oplock break"));
+                               cFYI(1, "file id match, oplock break");
                                pCifsInode = CIFS_I(netfile->pInode);
                                pCifsInode->clientCanCacheAll = false;
                                if (pSMB->OplockLevel == 0)
                                        pCifsInode->clientCanCacheRead = false;
                                rc = slow_work_enqueue(&netfile->oplock_break);
                                if (rc) {
-                                       cERROR(1, ("failed to enqueue oplock "
-                                                  "break: %d\n", rc));
+                                       cERROR(1, "failed to enqueue oplock "
+                                                  "break: %d\n", rc);
                                } else {
                                        netfile->oplock_break_cancelled = false;
                                }
@@ -597,12 +596,12 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv)
                        }
                        read_unlock(&GlobalSMBSeslock);
                        read_unlock(&cifs_tcp_ses_lock);
-                       cFYI(1, ("No matching file for oplock break"));
+                       cFYI(1, "No matching file for oplock break");
                        return true;
                }
        }
        read_unlock(&cifs_tcp_ses_lock);
-       cFYI(1, ("Can not process oplock break for non-existent connection"));
+       cFYI(1, "Can not process oplock break for non-existent connection");
        return true;
 }
 
@@ -721,11 +720,11 @@ cifs_autodisable_serverino(struct cifs_sb_info *cifs_sb)
 {
        if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) {
                cifs_sb->mnt_cifs_flags &= ~CIFS_MOUNT_SERVER_INUM;
-               cERROR(1, ("Autodisabling the use of server inode numbers on "
+               cERROR(1, "Autodisabling the use of server inode numbers on "
                           "%s. This server doesn't seem to support them "
                           "properly. Hardlinks will not be recognized on this "
                           "mount. Consider mounting with the \"noserverino\" "
                           "option to silence this message.",
-                          cifs_sb->tcon->treeName));
+                          cifs_sb->tcon->treeName);
        }
 }
index bd6d689..d35d528 100644 (file)
@@ -149,7 +149,7 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
        else if (address_family == AF_INET6)
                ret = in6_pton(cp, -1 /* len */, dst , '\\', NULL);
 
-       cFYI(DBG2, ("address conversion returned %d for %s", ret, cp));
+       cFYI(DBG2, "address conversion returned %d for %s", ret, cp);
        if (ret > 0)
                ret = 1;
        return ret;
@@ -870,8 +870,8 @@ map_smb_to_linux_error(struct smb_hdr *smb, int logErr)
        }
        /* else ERRHRD class errors or junk  - return EIO */
 
-       cFYI(1, ("Mapping smb error code %d to POSIX err %d",
-                smberrcode, rc));
+       cFYI(1, "Mapping smb error code %d to POSIX err %d",
+                smberrcode, rc);
 
        /* generic corrective action e.g. reconnect SMB session on
         * ERRbaduid could be added */
@@ -940,20 +940,20 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
        SMB_TIME *st = (SMB_TIME *)&time;
        SMB_DATE *sd = (SMB_DATE *)&date;
 
-       cFYI(1, ("date %d time %d", date, time));
+       cFYI(1, "date %d time %d", date, time);
 
        sec = 2 * st->TwoSeconds;
        min = st->Minutes;
        if ((sec > 59) || (min > 59))
-               cERROR(1, ("illegal time min %d sec %d", min, sec));
+               cERROR(1, "illegal time min %d sec %d", min, sec);
        sec += (min * 60);
        sec += 60 * 60 * st->Hours;
        if (st->Hours > 24)
-               cERROR(1, ("illegal hours %d", st->Hours));
+               cERROR(1, "illegal hours %d", st->Hours);
        days = sd->Day;
        month = sd->Month;
        if ((days > 31) || (month > 12)) {
-               cERROR(1, ("illegal date, month %d day: %d", month, days));
+               cERROR(1, "illegal date, month %d day: %d", month, days);
                if (month > 12)
                        month = 12;
        }
@@ -979,7 +979,7 @@ struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
 
        ts.tv_sec = sec + offset;
 
-       /* cFYI(1,("sec after cnvrt dos to unix time %d",sec)); */
+       /* cFYI(1, "sec after cnvrt dos to unix time %d",sec); */
 
        ts.tv_nsec = 0;
        return ts;
index 18e0bc1..daf1753 100644 (file)
@@ -47,15 +47,15 @@ static void dump_cifs_file_struct(struct file *file, char *label)
        if (file) {
                cf = file->private_data;
                if (cf == NULL) {
-                       cFYI(1, ("empty cifs private file data"));
+                       cFYI(1, "empty cifs private file data");
                        return;
                }
                if (cf->invalidHandle)
-                       cFYI(1, ("invalid handle"));
+                       cFYI(1, "invalid handle");
                if (cf->srch_inf.endOfSearch)
-                       cFYI(1, ("end of search"));
+                       cFYI(1, "end of search");
                if (cf->srch_inf.emptyDir)
-                       cFYI(1, ("empty dir"));
+                       cFYI(1, "empty dir");
        }
 }
 #else
@@ -76,7 +76,7 @@ cifs_readdir_lookup(struct dentry *parent, struct qstr *name,
        struct inode *inode;
        struct super_block *sb = parent->d_inode->i_sb;
 
-       cFYI(1, ("For %s", name->name));
+       cFYI(1, "For %s", name->name);
 
        if (parent->d_op && parent->d_op->d_hash)
                parent->d_op->d_hash(parent, name);
@@ -214,7 +214,7 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
                                fid,
                                cifs_sb->local_nls);
                if (CIFSSMBClose(xid, ptcon, fid)) {
-                       cFYI(1, ("Error closing temporary reparsepoint open)"));
+                       cFYI(1, "Error closing temporary reparsepoint open");
                }
        }
 }
@@ -252,7 +252,7 @@ static int initiate_cifs_search(const int xid, struct file *file)
        if (full_path == NULL)
                return -ENOMEM;
 
-       cFYI(1, ("Full path: %s start at: %lld", full_path, file->f_pos));
+       cFYI(1, "Full path: %s start at: %lld", full_path, file->f_pos);
 
 ffirst_retry:
        /* test for Unix extensions */
@@ -297,7 +297,7 @@ static int cifs_unicode_bytelen(char *str)
                if (ustr[len] == 0)
                        return len << 1;
        }
-       cFYI(1, ("Unicode string longer than PATH_MAX found"));
+       cFYI(1, "Unicode string longer than PATH_MAX found");
        return len << 1;
 }
 
@@ -314,19 +314,18 @@ static char *nxt_dir_entry(char *old_entry, char *end_of_smb, int level)
                                pfData->FileNameLength;
        } else
                new_entry = old_entry + le32_to_cpu(pDirInfo->NextEntryOffset);
-       cFYI(1, ("new entry %p old entry %p", new_entry, old_entry));
+       cFYI(1, "new entry %p old entry %p", new_entry, old_entry);
        /* validate that new_entry is not past end of SMB */
        if (new_entry >= end_of_smb) {
-               cERROR(1,
-                     ("search entry %p began after end of SMB %p old entry %p",
-                       new_entry, end_of_smb, old_entry));
+               cERROR(1, "search entry %p began after end of SMB %p old entry %p",
+                       new_entry, end_of_smb, old_entry);
                return NULL;
        } else if (((level == SMB_FIND_FILE_INFO_STANDARD) &&
                    (new_entry + sizeof(FIND_FILE_STANDARD_INFO) > end_of_smb))
                  || ((level != SMB_FIND_FILE_INFO_STANDARD) &&
                   (new_entry + sizeof(FILE_DIRECTORY_INFO) > end_of_smb)))  {
-               cERROR(1, ("search entry %p extends after end of SMB %p",
-                       new_entry, end_of_smb));
+               cERROR(1, "search entry %p extends after end of SMB %p",
+                       new_entry, end_of_smb);
                return NULL;
        } else
                return new_entry;
@@ -380,8 +379,8 @@ static int cifs_entry_is_dot(char *current_entry, struct cifsFileInfo *cfile)
                filename = &pFindData->FileName[0];
                len = pFindData->FileNameLength;
        } else {
-               cFYI(1, ("Unknown findfirst level %d",
-                        cfile->srch_inf.info_level));
+               cFYI(1, "Unknown findfirst level %d",
+                        cfile->srch_inf.info_level);
        }
 
        if (filename) {
@@ -481,7 +480,7 @@ static int cifs_save_resume_key(const char *current_entry,
                len = (unsigned int)pFindData->FileNameLength;
                cifsFile->srch_inf.resume_key = pFindData->ResumeKey;
        } else {
-               cFYI(1, ("Unknown findfirst level %d", level));
+               cFYI(1, "Unknown findfirst level %d", level);
                return -EINVAL;
        }
        cifsFile->srch_inf.resume_name_len = len;
@@ -525,7 +524,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
             is_dir_changed(file)) ||
           (index_to_find < first_entry_in_buffer)) {
                /* close and restart search */
-               cFYI(1, ("search backing up - close and restart search"));
+               cFYI(1, "search backing up - close and restart search");
                write_lock(&GlobalSMBSeslock);
                if (!cifsFile->srch_inf.endOfSearch &&
                    !cifsFile->invalidHandle) {
@@ -535,7 +534,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                } else
                        write_unlock(&GlobalSMBSeslock);
                if (cifsFile->srch_inf.ntwrk_buf_start) {
-                       cFYI(1, ("freeing SMB ff cache buf on search rewind"));
+                       cFYI(1, "freeing SMB ff cache buf on search rewind");
                        if (cifsFile->srch_inf.smallBuf)
                                cifs_small_buf_release(cifsFile->srch_inf.
                                                ntwrk_buf_start);
@@ -546,8 +545,8 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                }
                rc = initiate_cifs_search(xid, file);
                if (rc) {
-                       cFYI(1, ("error %d reinitiating a search on rewind",
-                                rc));
+                       cFYI(1, "error %d reinitiating a search on rewind",
+                                rc);
                        return rc;
                }
                cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile);
@@ -555,7 +554,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
 
        while ((index_to_find >= cifsFile->srch_inf.index_of_last_entry) &&
              (rc == 0) && !cifsFile->srch_inf.endOfSearch) {
-               cFYI(1, ("calling findnext2"));
+               cFYI(1, "calling findnext2");
                rc = CIFSFindNext(xid, pTcon, cifsFile->netfid,
                                  &cifsFile->srch_inf);
                cifs_save_resume_key(cifsFile->srch_inf.last_entry, cifsFile);
@@ -575,7 +574,7 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                first_entry_in_buffer = cifsFile->srch_inf.index_of_last_entry
                                        - cifsFile->srch_inf.entries_in_buffer;
                pos_in_buf = index_to_find - first_entry_in_buffer;
-               cFYI(1, ("found entry - pos_in_buf %d", pos_in_buf));
+               cFYI(1, "found entry - pos_in_buf %d", pos_in_buf);
 
                for (i = 0; (i < (pos_in_buf)) && (current_entry != NULL); i++) {
                        /* go entry by entry figuring out which is first */
@@ -584,19 +583,19 @@ static int find_cifs_entry(const int xid, struct cifsTconInfo *pTcon,
                }
                if ((current_entry == NULL) && (i < pos_in_buf)) {
                        /* BB fixme - check if we should flag this error */
-                       cERROR(1, ("reached end of buf searching for pos in buf"
+                       cERROR(1, "reached end of buf searching for pos in buf"
                          " %d index to find %lld rc %d",
-                         pos_in_buf, index_to_find, rc));
+                         pos_in_buf, index_to_find, rc);
                }
                rc = 0;
                *ppCurrentEntry = current_entry;
        } else {
-               cFYI(1, ("index not in buffer - could not findnext into it"));
+               cFYI(1, "index not in buffer - could not findnext into it");
                return 0;
        }
 
        if (pos_in_buf >= cifsFile->srch_inf.entries_in_buffer) {
-               cFYI(1, ("can not return entries pos_in_buf beyond last"));
+               cFYI(1, "can not return entries pos_in_buf beyond last");
                *num_to_ret = 0;
        } else
                *num_to_ret = cifsFile->srch_inf.entries_in_buffer - pos_in_buf;
@@ -656,12 +655,12 @@ static int cifs_get_name_from_search_buf(struct qstr *pqst,
                /* one byte length, no name conversion */
                len = (unsigned int)pFindData->FileNameLength;
        } else {
-               cFYI(1, ("Unknown findfirst level %d", level));
+               cFYI(1, "Unknown findfirst level %d", level);
                return -EINVAL;
        }
 
        if (len > max_len) {
-               cERROR(1, ("bad search response length %d past smb end", len));
+               cERROR(1, "bad search response length %d past smb end", len);
                return -EINVAL;
        }
 
@@ -754,7 +753,7 @@ static int cifs_filldir(char *pfindEntry, struct file *file, filldir_t filldir,
         * case already. Why should we be clobbering other errors from it?
         */
        if (rc) {
-               cFYI(1, ("filldir rc = %d", rc));
+               cFYI(1, "filldir rc = %d", rc);
                rc = -EOVERFLOW;
        }
        dput(tmp_dentry);
@@ -786,7 +785,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
        case 0:
                if (filldir(direntry, ".", 1, file->f_pos,
                     file->f_path.dentry->d_inode->i_ino, DT_DIR) < 0) {
-                       cERROR(1, ("Filldir for current dir failed"));
+                       cERROR(1, "Filldir for current dir failed");
                        rc = -ENOMEM;
                        break;
                }
@@ -794,7 +793,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
        case 1:
                if (filldir(direntry, "..", 2, file->f_pos,
                     file->f_path.dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
-                       cERROR(1, ("Filldir for parent dir failed"));
+                       cERROR(1, "Filldir for parent dir failed");
                        rc = -ENOMEM;
                        break;
                }
@@ -807,7 +806,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
 
                if (file->private_data == NULL) {
                        rc = initiate_cifs_search(xid, file);
-                       cFYI(1, ("initiate cifs search rc %d", rc));
+                       cFYI(1, "initiate cifs search rc %d", rc);
                        if (rc) {
                                FreeXid(xid);
                                return rc;
@@ -821,7 +820,7 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                cifsFile = file->private_data;
                if (cifsFile->srch_inf.endOfSearch) {
                        if (cifsFile->srch_inf.emptyDir) {
-                               cFYI(1, ("End of search, empty dir"));
+                               cFYI(1, "End of search, empty dir");
                                rc = 0;
                                break;
                        }
@@ -833,16 +832,16 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                rc = find_cifs_entry(xid, pTcon, file,
                                &current_entry, &num_to_fill);
                if (rc) {
-                       cFYI(1, ("fce error %d", rc));
+                       cFYI(1, "fce error %d", rc);
                        goto rddir2_exit;
                } else if (current_entry != NULL) {
-                       cFYI(1, ("entry %lld found", file->f_pos));
+                       cFYI(1, "entry %lld found", file->f_pos);
                } else {
-                       cFYI(1, ("could not find entry"));
+                       cFYI(1, "could not find entry");
                        goto rddir2_exit;
                }
-               cFYI(1, ("loop through %d times filling dir for net buf %p",
-                       num_to_fill, cifsFile->srch_inf.ntwrk_buf_start));
+               cFYI(1, "loop through %d times filling dir for net buf %p",
+                       num_to_fill, cifsFile->srch_inf.ntwrk_buf_start);
                max_len = smbCalcSize((struct smb_hdr *)
                                cifsFile->srch_inf.ntwrk_buf_start);
                end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
@@ -851,8 +850,8 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                for (i = 0; (i < num_to_fill) && (rc == 0); i++) {
                        if (current_entry == NULL) {
                                /* evaluate whether this case is an error */
-                               cERROR(1, ("past SMB end,  num to fill %d i %d",
-                                         num_to_fill, i));
+                               cERROR(1, "past SMB end,  num to fill %d i %d",
+                                         num_to_fill, i);
                                break;
                        }
                        /* if buggy server returns . and .. late do
@@ -867,8 +866,8 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                        file->f_pos++;
                        if (file->f_pos ==
                                cifsFile->srch_inf.index_of_last_entry) {
-                               cFYI(1, ("last entry in buf at pos %lld %s",
-                                       file->f_pos, tmp_buf));
+                               cFYI(1, "last entry in buf at pos %lld %s",
+                                       file->f_pos, tmp_buf);
                                cifs_save_resume_key(current_entry, cifsFile);
                                break;
                        } else
index 7c3fd74..7707389 100644 (file)
 extern void SMBNTencrypt(unsigned char *passwd, unsigned char *c8,
                         unsigned char *p24);
 
-/* Checks if this is the first smb session to be reconnected after
-   the socket has been reestablished (so we know whether to use vc 0).
-   Called while holding the cifs_tcp_ses_lock, so do not block */
+/*
+ * Checks if this is the first smb session to be reconnected after
+ * the socket has been reestablished (so we know whether to use vc 0).
+ * Called while holding the cifs_tcp_ses_lock, so do not block
+ */
 static bool is_first_ses_reconnect(struct cifsSesInfo *ses)
 {
        struct list_head *tmp;
@@ -284,7 +286,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
        int len;
        char *data = *pbcc_area;
 
-       cFYI(1, ("bleft %d", bleft));
+       cFYI(1, "bleft %d", bleft);
 
        /*
         * Windows servers do not always double null terminate their final
@@ -301,7 +303,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
 
        kfree(ses->serverOS);
        ses->serverOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
-       cFYI(1, ("serverOS=%s", ses->serverOS));
+       cFYI(1, "serverOS=%s", ses->serverOS);
        len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
        data += len;
        bleft -= len;
@@ -310,7 +312,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
 
        kfree(ses->serverNOS);
        ses->serverNOS = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
-       cFYI(1, ("serverNOS=%s", ses->serverNOS));
+       cFYI(1, "serverNOS=%s", ses->serverNOS);
        len = (UniStrnlen((wchar_t *) data, bleft / 2) * 2) + 2;
        data += len;
        bleft -= len;
@@ -319,7 +321,7 @@ decode_unicode_ssetup(char **pbcc_area, int bleft, struct cifsSesInfo *ses,
 
        kfree(ses->serverDomain);
        ses->serverDomain = cifs_strndup_from_ucs(data, bleft, true, nls_cp);
-       cFYI(1, ("serverDomain=%s", ses->serverDomain));
+       cFYI(1, "serverDomain=%s", ses->serverDomain);
 
        return;
 }
@@ -332,7 +334,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft,
        int len;
        char *bcc_ptr = *pbcc_area;
 
-       cFYI(1, ("decode sessetup ascii. bleft %d", bleft));
+       cFYI(1, "decode sessetup ascii. bleft %d", bleft);
 
        len = strnlen(bcc_ptr, bleft);
        if (len >= bleft)
@@ -344,7 +346,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft,
        if (ses->serverOS)
                strncpy(ses->serverOS, bcc_ptr, len);
        if (strncmp(ses->serverOS, "OS/2", 4) == 0) {
-                       cFYI(1, ("OS/2 server"));
+                       cFYI(1, "OS/2 server");
                        ses->flags |= CIFS_SES_OS2;
        }
 
@@ -373,7 +375,7 @@ static int decode_ascii_ssetup(char **pbcc_area, int bleft,
        /* BB For newer servers which do not support Unicode,
           but thus do return domain here we could add parsing
           for it later, but it is not very important */
-       cFYI(1, ("ascii: bytes left %d", bleft));
+       cFYI(1, "ascii: bytes left %d", bleft);
 
        return rc;
 }
@@ -384,16 +386,16 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len,
        CHALLENGE_MESSAGE *pblob = (CHALLENGE_MESSAGE *)bcc_ptr;
 
        if (blob_len < sizeof(CHALLENGE_MESSAGE)) {
-               cERROR(1, ("challenge blob len %d too small", blob_len));
+               cERROR(1, "challenge blob len %d too small", blob_len);
                return -EINVAL;
        }
 
        if (memcmp(pblob->Signature, "NTLMSSP", 8)) {
-               cERROR(1, ("blob signature incorrect %s", pblob->Signature));
+               cERROR(1, "blob signature incorrect %s", pblob->Signature);
                return -EINVAL;
        }
        if (pblob->MessageType != NtLmChallenge) {
-               cERROR(1, ("Incorrect message type %d", pblob->MessageType));
+               cERROR(1, "Incorrect message type %d", pblob->MessageType);
                return -EINVAL;
        }
 
@@ -447,7 +449,7 @@ static void build_ntlmssp_negotiate_blob(unsigned char *pbuffer,
    This function returns the length of the data in the blob */
 static int build_ntlmssp_auth_blob(unsigned char *pbuffer,
                                   struct cifsSesInfo *ses,
-                                  const struct nls_table *nls_cp, int first)
+                                  const struct nls_table *nls_cp, bool first)
 {
        AUTHENTICATE_MESSAGE *sec_blob = (AUTHENTICATE_MESSAGE *)pbuffer;
        __u32 flags;
@@ -546,7 +548,7 @@ static void setup_ntlmssp_neg_req(SESSION_SETUP_ANDX *pSMB,
 
 static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB,
                                  struct cifsSesInfo *ses,
-                                 const struct nls_table *nls, int first_time)
+                                 const struct nls_table *nls, bool first_time)
 {
        int bloblen;
 
@@ -559,8 +561,8 @@ static int setup_ntlmssp_auth_req(SESSION_SETUP_ANDX *pSMB,
 #endif
 
 int
-CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
-               const struct nls_table *nls_cp)
+CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses,
+              const struct nls_table *nls_cp)
 {
        int rc = 0;
        int wct;
@@ -577,13 +579,18 @@ CIFS_SessSetup(unsigned int xid, struct cifsSesInfo *ses, int first_time,
        int bytes_remaining;
        struct key *spnego_key = NULL;
        __le32 phase = NtLmNegotiate; /* NTLMSSP, if needed, is multistage */
+       bool first_time;
 
        if (ses == NULL)
                return -EINVAL;
 
+       read_lock(&cifs_tcp_ses_lock);
+       first_time = is_first_ses_reconnect(ses);
+       read_unlock(&cifs_tcp_ses_lock);
+
        type = ses->server->secType;
 
-       cFYI(1, ("sess setup type %d", type));
+       cFYI(1, "sess setup type %d", type);
 ssetup_ntlmssp_authenticate:
        if (phase == NtLmChallenge)
                phase = NtLmAuthenticate; /* if ntlmssp, now final phase */
@@ -664,7 +671,7 @@ ssetup_ntlmssp_authenticate:
                changed to do higher than lanman dialect and
                we reconnected would we ever calc signing_key? */
 
-               cFYI(1, ("Negotiating LANMAN setting up strings"));
+               cFYI(1, "Negotiating LANMAN setting up strings");
                /* Unicode not allowed for LANMAN dialects */
                ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
 #endif
@@ -744,7 +751,7 @@ ssetup_ntlmssp_authenticate:
                        unicode_ssetup_strings(&bcc_ptr, ses, nls_cp);
                } else
                        ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
-       } else if (type == Kerberos || type == MSKerberos) {
+       } else if (type == Kerberos) {
 #ifdef CONFIG_CIFS_UPCALL
                struct cifs_spnego_msg *msg;
                spnego_key = cifs_get_spnego_key(ses);
@@ -758,17 +765,17 @@ ssetup_ntlmssp_authenticate:
                /* check version field to make sure that cifs.upcall is
                   sending us a response in an expected form */
                if (msg->version != CIFS_SPNEGO_UPCALL_VERSION) {
-                       cERROR(1, ("incorrect version of cifs.upcall (expected"
+                       cERROR(1, "incorrect version of cifs.upcall (expected"
                                   " %d but got %d)",
-                                  CIFS_SPNEGO_UPCALL_VERSION, msg->version));
+                                  CIFS_SPNEGO_UPCALL_VERSION, msg->version);
                        rc = -EKEYREJECTED;
                        goto ssetup_exit;
                }
                /* bail out if key is too long */
                if (msg->sesskey_len >
                    sizeof(ses->server->mac_signing_key.data.krb5)) {
-                       cERROR(1, ("Kerberos signing key too long (%u bytes)",
-                               msg->sesskey_len));
+                       cERROR(1, "Kerberos signing key too long (%u bytes)",
+                               msg->sesskey_len);
                        rc = -EOVERFLOW;
                        goto ssetup_exit;
                }
@@ -796,7 +803,7 @@ ssetup_ntlmssp_authenticate:
                /* BB: is this right? */
                        ascii_ssetup_strings(&bcc_ptr, ses, nls_cp);
 #else /* ! CONFIG_CIFS_UPCALL */
-               cERROR(1, ("Kerberos negotiated but upcall support disabled!"));
+               cERROR(1, "Kerberos negotiated but upcall support disabled!");
                rc = -ENOSYS;
                goto ssetup_exit;
 #endif /* CONFIG_CIFS_UPCALL */
@@ -804,12 +811,12 @@ ssetup_ntlmssp_authenticate:
 #ifdef CONFIG_CIFS_EXPERIMENTAL
                if (type == RawNTLMSSP) {
                        if ((pSMB->req.hdr.Flags2 & SMBFLG2_UNICODE) == 0) {
-                               cERROR(1, ("NTLMSSP requires Unicode support"));
+                               cERROR(1, "NTLMSSP requires Unicode support");
                                rc = -ENOSYS;
                                goto ssetup_exit;
                        }
 
-                       cFYI(1, ("ntlmssp session setup phase %d", phase));
+                       cFYI(1, "ntlmssp session setup phase %d", phase);
                        pSMB->req.hdr.Flags2 |= SMBFLG2_EXT_SEC;
                        capabilities |= CAP_EXTENDED_SECURITY;
                        pSMB->req.Capabilities |= cpu_to_le32(capabilities);
@@ -827,7 +834,7 @@ ssetup_ntlmssp_authenticate:
                                   on the response (challenge) */
                                smb_buf->Uid = ses->Suid;
                        } else {
-                               cERROR(1, ("invalid phase %d", phase));
+                               cERROR(1, "invalid phase %d", phase);
                                rc = -ENOSYS;
                                goto ssetup_exit;
                        }
@@ -839,12 +846,12 @@ ssetup_ntlmssp_authenticate:
                        }
                        unicode_oslm_strings(&bcc_ptr, nls_cp);
                } else {
-                       cERROR(1, ("secType %d not supported!", type));
+                       cERROR(1, "secType %d not supported!", type);
                        rc = -ENOSYS;
                        goto ssetup_exit;
                }
 #else
-               cERROR(1, ("secType %d not supported!", type));
+               cERROR(1, "secType %d not supported!", type);
                rc = -ENOSYS;
                goto ssetup_exit;
 #endif
@@ -862,7 +869,7 @@ ssetup_ntlmssp_authenticate:
                          CIFS_STD_OP /* not long */ | CIFS_LOG_ERROR);
        /* SMB request buf freed in SendReceive2 */
 
-       cFYI(1, ("ssetup rc from sendrecv2 is %d", rc));
+       cFYI(1, "ssetup rc from sendrecv2 is %d", rc);
 
        pSMB = (SESSION_SETUP_ANDX *)iov[0].iov_base;
        smb_buf = (struct smb_hdr *)iov[0].iov_base;
@@ -870,7 +877,7 @@ ssetup_ntlmssp_authenticate:
        if ((type == RawNTLMSSP) && (smb_buf->Status.CifsError ==
                        cpu_to_le32(NT_STATUS_MORE_PROCESSING_REQUIRED))) {
                if (phase != NtLmNegotiate) {
-                       cERROR(1, ("Unexpected more processing error"));
+                       cERROR(1, "Unexpected more processing error");
                        goto ssetup_exit;
                }
                /* NTLMSSP Negotiate sent now processing challenge (response) */
@@ -882,14 +889,14 @@ ssetup_ntlmssp_authenticate:
 
        if ((smb_buf->WordCount != 3) && (smb_buf->WordCount != 4)) {
                rc = -EIO;
-               cERROR(1, ("bad word count %d", smb_buf->WordCount));
+               cERROR(1, "bad word count %d", smb_buf->WordCount);
                goto ssetup_exit;
        }
        action = le16_to_cpu(pSMB->resp.Action);
        if (action & GUEST_LOGIN)
-               cFYI(1, ("Guest login")); /* BB mark SesInfo struct? */
+               cFYI(1, "Guest login"); /* BB mark SesInfo struct? */
        ses->Suid = smb_buf->Uid;   /* UID left in wire format (le) */
-       cFYI(1, ("UID = %d ", ses->Suid));
+       cFYI(1, "UID = %d ", ses->Suid);
        /* response can have either 3 or 4 word count - Samba sends 3 */
        /* and lanman response is 3 */
        bytes_remaining = BCC(smb_buf);
@@ -899,7 +906,7 @@ ssetup_ntlmssp_authenticate:
                __u16 blob_len;
                blob_len = le16_to_cpu(pSMB->resp.SecurityBlobLength);
                if (blob_len > bytes_remaining) {
-                       cERROR(1, ("bad security blob length %d", blob_len));
+                       cERROR(1, "bad security blob length %d", blob_len);
                        rc = -EINVAL;
                        goto ssetup_exit;
                }
@@ -933,7 +940,7 @@ ssetup_exit:
        }
        kfree(str_area);
        if (resp_buf_type == CIFS_SMALL_BUFFER) {
-               cFYI(1, ("ssetup freeing small buf %p", iov[0].iov_base));
+               cFYI(1, "ssetup freeing small buf %p", iov[0].iov_base);
                cifs_small_buf_release(iov[0].iov_base);
        } else if (resp_buf_type == CIFS_LARGE_BUFFER)
                cifs_buf_release(iov[0].iov_base);
index ad081fe..82f78c4 100644 (file)
@@ -35,7 +35,6 @@
 #include "cifs_debug.h"
 
 extern mempool_t *cifs_mid_poolp;
-extern struct kmem_cache *cifs_oplock_cachep;
 
 static struct mid_q_entry *
 AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
@@ -43,7 +42,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
        struct mid_q_entry *temp;
 
        if (server == NULL) {
-               cERROR(1, ("Null TCP session in AllocMidQEntry"));
+               cERROR(1, "Null TCP session in AllocMidQEntry");
                return NULL;
        }
 
@@ -55,7 +54,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
                temp->mid = smb_buffer->Mid;    /* always LE */
                temp->pid = current->pid;
                temp->command = smb_buffer->Command;
-               cFYI(1, ("For smb_command %d", temp->command));
+               cFYI(1, "For smb_command %d", temp->command);
        /*      do_gettimeofday(&temp->when_sent);*/ /* easier to use jiffies */
                /* when mid allocated can be before when sent */
                temp->when_alloc = jiffies;
@@ -140,7 +139,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
                total_len += iov[i].iov_len;
 
        smb_buffer->smb_buf_length = cpu_to_be32(smb_buffer->smb_buf_length);
-       cFYI(1, ("Sending smb:  total_len %d", total_len));
+       cFYI(1, "Sending smb:  total_len %d", total_len);
        dump_smb(smb_buffer, len);
 
        i = 0;
@@ -168,9 +167,8 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
                           reconnect which may clear the network problem.
                        */
                        if ((i >= 14) || (!server->noblocksnd && (i > 2))) {
-                               cERROR(1,
-                                  ("sends on sock %p stuck for 15 seconds",
-                                   ssocket));
+                               cERROR(1, "sends on sock %p stuck for 15 seconds",
+                                   ssocket);
                                rc = -EAGAIN;
                                break;
                        }
@@ -184,13 +182,13 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
                        total_len = 0;
                        break;
                } else if (rc > total_len) {
-                       cERROR(1, ("sent %d requested %d", rc, total_len));
+                       cERROR(1, "sent %d requested %d", rc, total_len);
                        break;
                }
                if (rc == 0) {
                        /* should never happen, letting socket clear before
                           retrying is our only obvious option here */
-                       cERROR(1, ("tcp sent no data"));
+                       cERROR(1, "tcp sent no data");
                        msleep(500);
                        continue;
                }
@@ -213,8 +211,8 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
        }
 
        if ((total_len > 0) && (total_len != smb_buf_length + 4)) {
-               cFYI(1, ("partial send (%d remaining), terminating session",
-                       total_len));
+               cFYI(1, "partial send (%d remaining), terminating session",
+                       total_len);
                /* If we have only sent part of an SMB then the next SMB
                   could be taken as the remainder of this one.  We need
                   to kill the socket so the server throws away the partial
@@ -223,7 +221,7 @@ smb_sendv(struct TCP_Server_Info *server, struct kvec *iov, int n_vec)
        }
 
        if (rc < 0) {
-               cERROR(1, ("Error %d sending data on socket to server", rc));
+               cERROR(1, "Error %d sending data on socket to server", rc);
        } else
                rc = 0;
 
@@ -296,7 +294,7 @@ static int allocate_mid(struct cifsSesInfo *ses, struct smb_hdr *in_buf,
        }
 
        if (ses->server->tcpStatus == CifsNeedReconnect) {
-               cFYI(1, ("tcp session dead - return to caller to retry"));
+               cFYI(1, "tcp session dead - return to caller to retry");
                return -EAGAIN;
        }
 
@@ -348,7 +346,7 @@ static int wait_for_response(struct cifsSesInfo *ses,
                        lrt += time_to_wait;
                        if (time_after(jiffies, lrt)) {
                                /* No replies for time_to_wait. */
-                               cERROR(1, ("server not responding"));
+                               cERROR(1, "server not responding");
                                return -1;
                        }
                } else {
@@ -379,7 +377,7 @@ SendReceiveNoRsp(const unsigned int xid, struct cifsSesInfo *ses,
        iov[0].iov_len = in_buf->smb_buf_length + 4;
        flags |= CIFS_NO_RESP;
        rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags);
-       cFYI(DBG2, ("SendRcvNoRsp flags %d rc %d", flags, rc));
+       cFYI(DBG2, "SendRcvNoRsp flags %d rc %d", flags, rc);
 
        return rc;
 }
@@ -402,7 +400,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
 
        if ((ses == NULL) || (ses->server == NULL)) {
                cifs_small_buf_release(in_buf);
-               cERROR(1, ("Null session"));
+               cERROR(1, "Null session");
                return -EIO;
        }
 
@@ -471,7 +469,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
        else if (long_op == CIFS_BLOCKING_OP)
                timeout = 0x7FFFFFFF; /*  large, but not so large as to wrap */
        else {
-               cERROR(1, ("unknown timeout flag %d", long_op));
+               cERROR(1, "unknown timeout flag %d", long_op);
                rc = -EIO;
                goto out;
        }
@@ -490,8 +488,8 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
        spin_lock(&GlobalMid_Lock);
 
        if (midQ->resp_buf == NULL) {
-               cERROR(1, ("No response to cmd %d mid %d",
-                       midQ->command, midQ->mid));
+               cERROR(1, "No response to cmd %d mid %d",
+                       midQ->command, midQ->mid);
                if (midQ->midState == MID_REQUEST_SUBMITTED) {
                        if (ses->server->tcpStatus == CifsExiting)
                                rc = -EHOSTDOWN;
@@ -504,7 +502,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
                if (rc != -EHOSTDOWN) {
                        if (midQ->midState == MID_RETRY_NEEDED) {
                                rc = -EAGAIN;
-                               cFYI(1, ("marking request for retry"));
+                               cFYI(1, "marking request for retry");
                        } else {
                                rc = -EIO;
                        }
@@ -521,8 +519,8 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
        receive_len = midQ->resp_buf->smb_buf_length;
 
        if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
-               cERROR(1, ("Frame too large received.  Length: %d  Xid: %d",
-                       receive_len, xid));
+               cERROR(1, "Frame too large received.  Length: %d  Xid: %d",
+                       receive_len, xid);
                rc = -EIO;
                goto out;
        }
@@ -548,7 +546,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
                                                &ses->server->mac_signing_key,
                                                midQ->sequence_number+1);
                        if (rc) {
-                               cERROR(1, ("Unexpected SMB signature"));
+                               cERROR(1, "Unexpected SMB signature");
                                /* BB FIXME add code to kill session */
                        }
                }
@@ -569,7 +567,7 @@ SendReceive2(const unsigned int xid, struct cifsSesInfo *ses,
                                                   DeleteMidQEntry */
        } else {
                rc = -EIO;
-               cFYI(1, ("Bad MID state?"));
+               cFYI(1, "Bad MID state?");
        }
 
 out:
@@ -591,11 +589,11 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
        struct mid_q_entry *midQ;
 
        if (ses == NULL) {
-               cERROR(1, ("Null smb session"));
+               cERROR(1, "Null smb session");
                return -EIO;
        }
        if (ses->server == NULL) {
-               cERROR(1, ("Null tcp session"));
+               cERROR(1, "Null tcp session");
                return -EIO;
        }
 
@@ -607,8 +605,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
           use ses->maxReq */
 
        if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
-               cERROR(1, ("Illegal length, greater than maximum frame, %d",
-                          in_buf->smb_buf_length));
+               cERROR(1, "Illegal length, greater than maximum frame, %d",
+                          in_buf->smb_buf_length);
                return -EIO;
        }
 
@@ -665,7 +663,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
        else if (long_op == CIFS_BLOCKING_OP)
                timeout = 0x7FFFFFFF; /* large but no so large as to wrap */
        else {
-               cERROR(1, ("unknown timeout flag %d", long_op));
+               cERROR(1, "unknown timeout flag %d", long_op);
                rc = -EIO;
                goto out;
        }
@@ -681,8 +679,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
 
        spin_lock(&GlobalMid_Lock);
        if (midQ->resp_buf == NULL) {
-               cERROR(1, ("No response for cmd %d mid %d",
-                         midQ->command, midQ->mid));
+               cERROR(1, "No response for cmd %d mid %d",
+                         midQ->command, midQ->mid);
                if (midQ->midState == MID_REQUEST_SUBMITTED) {
                        if (ses->server->tcpStatus == CifsExiting)
                                rc = -EHOSTDOWN;
@@ -695,7 +693,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
                if (rc != -EHOSTDOWN) {
                        if (midQ->midState == MID_RETRY_NEEDED) {
                                rc = -EAGAIN;
-                               cFYI(1, ("marking request for retry"));
+                               cFYI(1, "marking request for retry");
                        } else {
                                rc = -EIO;
                        }
@@ -712,8 +710,8 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
        receive_len = midQ->resp_buf->smb_buf_length;
 
        if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
-               cERROR(1, ("Frame too large received.  Length: %d  Xid: %d",
-                       receive_len, xid));
+               cERROR(1, "Frame too large received.  Length: %d  Xid: %d",
+                       receive_len, xid);
                rc = -EIO;
                goto out;
        }
@@ -736,7 +734,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
                                                &ses->server->mac_signing_key,
                                                midQ->sequence_number+1);
                        if (rc) {
-                               cERROR(1, ("Unexpected SMB signature"));
+                               cERROR(1, "Unexpected SMB signature");
                                /* BB FIXME add code to kill session */
                        }
                }
@@ -753,7 +751,7 @@ SendReceive(const unsigned int xid, struct cifsSesInfo *ses,
                        BCC(out_buf) = le16_to_cpu(BCC_LE(out_buf));
        } else {
                rc = -EIO;
-               cERROR(1, ("Bad MID state?"));
+               cERROR(1, "Bad MID state?");
        }
 
 out:
@@ -824,13 +822,13 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
        struct cifsSesInfo *ses;
 
        if (tcon == NULL || tcon->ses == NULL) {
-               cERROR(1, ("Null smb session"));
+               cERROR(1, "Null smb session");
                return -EIO;
        }
        ses = tcon->ses;
 
        if (ses->server == NULL) {
-               cERROR(1, ("Null tcp session"));
+               cERROR(1, "Null tcp session");
                return -EIO;
        }
 
@@ -842,8 +840,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
           use ses->maxReq */
 
        if (in_buf->smb_buf_length > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
-               cERROR(1, ("Illegal length, greater than maximum frame, %d",
-                          in_buf->smb_buf_length));
+               cERROR(1, "Illegal length, greater than maximum frame, %d",
+                          in_buf->smb_buf_length);
                return -EIO;
        }
 
@@ -933,8 +931,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
                spin_unlock(&GlobalMid_Lock);
                receive_len = midQ->resp_buf->smb_buf_length;
        } else {
-               cERROR(1, ("No response for cmd %d mid %d",
-                         midQ->command, midQ->mid));
+               cERROR(1, "No response for cmd %d mid %d",
+                         midQ->command, midQ->mid);
                if (midQ->midState == MID_REQUEST_SUBMITTED) {
                        if (ses->server->tcpStatus == CifsExiting)
                                rc = -EHOSTDOWN;
@@ -947,7 +945,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
                if (rc != -EHOSTDOWN) {
                        if (midQ->midState == MID_RETRY_NEEDED) {
                                rc = -EAGAIN;
-                               cFYI(1, ("marking request for retry"));
+                               cFYI(1, "marking request for retry");
                        } else {
                                rc = -EIO;
                        }
@@ -958,8 +956,8 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
        }
 
        if (receive_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE) {
-               cERROR(1, ("Frame too large received.  Length: %d  Xid: %d",
-                       receive_len, xid));
+               cERROR(1, "Frame too large received.  Length: %d  Xid: %d",
+                       receive_len, xid);
                rc = -EIO;
                goto out;
        }
@@ -968,7 +966,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
 
        if ((out_buf == NULL) || (midQ->midState != MID_RESPONSE_RECEIVED)) {
                rc = -EIO;
-               cERROR(1, ("Bad MID state?"));
+               cERROR(1, "Bad MID state?");
                goto out;
        }
 
@@ -986,7 +984,7 @@ SendReceiveBlockingLock(const unsigned int xid, struct cifsTconInfo *tcon,
                                           &ses->server->mac_signing_key,
                                           midQ->sequence_number+1);
                if (rc) {
-                       cERROR(1, ("Unexpected SMB signature"));
+                       cERROR(1, "Unexpected SMB signature");
                        /* BB FIXME add code to kill session */
                }
        }
index f555ce0..a150920 100644 (file)
@@ -70,12 +70,12 @@ int cifs_removexattr(struct dentry *direntry, const char *ea_name)
                return rc;
        }
        if (ea_name == NULL) {
-               cFYI(1, ("Null xattr names not supported"));
+               cFYI(1, "Null xattr names not supported");
        } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5)
                && (strncmp(ea_name, CIFS_XATTR_OS2_PREFIX, 4))) {
                cFYI(1,
-                   ("illegal xattr request %s (only user namespace supported)",
-                       ea_name));
+                    "illegal xattr request %s (only user namespace supported)",
+                    ea_name);
                /* BB what if no namespace prefix? */
                /* Should we just pass them to server, except for
                system and perhaps security prefixes? */
@@ -131,19 +131,19 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
                search server for EAs or streams to
                returns as xattrs */
        if (value_size > MAX_EA_VALUE_SIZE) {
-               cFYI(1, ("size of EA value too large"));
+               cFYI(1, "size of EA value too large");
                kfree(full_path);
                FreeXid(xid);
                return -EOPNOTSUPP;
        }
 
        if (ea_name == NULL) {
-               cFYI(1, ("Null xattr names not supported"));
+               cFYI(1, "Null xattr names not supported");
        } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
                        goto set_ea_exit;
                if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0)
-                       cFYI(1, ("attempt to set cifs inode metadata"));
+                       cFYI(1, "attempt to set cifs inode metadata");
 
                ea_name += 5; /* skip past user. prefix */
                rc = CIFSSMBSetEA(xid, pTcon, full_path, ea_name, ea_value,
@@ -169,9 +169,9 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
                                        ACL_TYPE_ACCESS, cifs_sb->local_nls,
                                        cifs_sb->mnt_cifs_flags &
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
-                       cFYI(1, ("set POSIX ACL rc %d", rc));
+                       cFYI(1, "set POSIX ACL rc %d", rc);
 #else
-                       cFYI(1, ("set POSIX ACL not supported"));
+                       cFYI(1, "set POSIX ACL not supported");
 #endif
                } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
                                   strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
@@ -182,13 +182,13 @@ int cifs_setxattr(struct dentry *direntry, const char *ea_name,
                                        ACL_TYPE_DEFAULT, cifs_sb->local_nls,
                                        cifs_sb->mnt_cifs_flags &
                                                CIFS_MOUNT_MAP_SPECIAL_CHR);
-                       cFYI(1, ("set POSIX default ACL rc %d", rc));
+                       cFYI(1, "set POSIX default ACL rc %d", rc);
 #else
-                       cFYI(1, ("set default POSIX ACL not supported"));
+                       cFYI(1, "set default POSIX ACL not supported");
 #endif
                } else {
-                       cFYI(1, ("illegal xattr request %s (only user namespace"
-                                " supported)", ea_name));
+                       cFYI(1, "illegal xattr request %s (only user namespace"
+                               " supported)", ea_name);
                  /* BB what if no namespace prefix? */
                  /* Should we just pass them to server, except for
                  system and perhaps security prefixes? */
@@ -235,13 +235,13 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
        /* return dos attributes as pseudo xattr */
        /* return alt name if available as pseudo attr */
        if (ea_name == NULL) {
-               cFYI(1, ("Null xattr names not supported"));
+               cFYI(1, "Null xattr names not supported");
        } else if (strncmp(ea_name, CIFS_XATTR_USER_PREFIX, 5) == 0) {
                if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_XATTR)
                        goto get_ea_exit;
 
                if (strncmp(ea_name, CIFS_XATTR_DOS_ATTRIB, 14) == 0) {
-                       cFYI(1, ("attempt to query cifs inode metadata"));
+                       cFYI(1, "attempt to query cifs inode metadata");
                        /* revalidate/getattr then populate from inode */
                } /* BB add else when above is implemented */
                ea_name += 5; /* skip past user. prefix */
@@ -287,7 +287,7 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
                }
 #endif /* EXPERIMENTAL */
 #else
-               cFYI(1, ("query POSIX ACL not supported yet"));
+               cFYI(1, "query POSIX ACL not supported yet");
 #endif /* CONFIG_CIFS_POSIX */
        } else if (strncmp(ea_name, POSIX_ACL_XATTR_DEFAULT,
                          strlen(POSIX_ACL_XATTR_DEFAULT)) == 0) {
@@ -299,18 +299,18 @@ ssize_t cifs_getxattr(struct dentry *direntry, const char *ea_name,
                                cifs_sb->mnt_cifs_flags &
                                        CIFS_MOUNT_MAP_SPECIAL_CHR);
 #else
-               cFYI(1, ("query POSIX default ACL not supported yet"));
+               cFYI(1, "query POSIX default ACL not supported yet");
 #endif
        } else if (strncmp(ea_name,
                  CIFS_XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) == 0) {
-               cFYI(1, ("Trusted xattr namespace not supported yet"));
+               cFYI(1, "Trusted xattr namespace not supported yet");
        } else if (strncmp(ea_name,
                  CIFS_XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) == 0) {
-               cFYI(1, ("Security xattr namespace not supported yet"));
+               cFYI(1, "Security xattr namespace not supported yet");
        } else
                cFYI(1,
-                   ("illegal xattr request %s (only user namespace supported)",
-                       ea_name));
+                   "illegal xattr request %s (only user namespace supported)",
+                    ea_name);
 
        /* We could add an additional check for streams ie
            if proc/fs/cifs/streamstoxattr is set then
index bd056a5..3817149 100644 (file)
@@ -1140,8 +1140,7 @@ retry:
                 * ep_poll_callback() when events will become available.
                 */
                init_waitqueue_entry(&wait, current);
-               wait.flags |= WQ_FLAG_EXCLUSIVE;
-               __add_wait_queue(&ep->wq, &wait);
+               __add_wait_queue_exclusive(&ep->wq, &wait);
 
                for (;;) {
                        /*
index 407bf39..258ec22 100644 (file)
@@ -1205,8 +1205,6 @@ void generic_delete_inode(struct inode *inode)
        inodes_stat.nr_inodes--;
        spin_unlock(&inode_lock);
 
-       security_inode_delete(inode);
-
        if (op->delete_inode) {
                void (*delete)(struct inode *) = op->delete_inode;
                /* Filesystems implementing their own
index c03d4dc..bc2ff59 100644 (file)
@@ -1889,7 +1889,7 @@ static struct kmem_cache *get_slab(size_t size)
        BUG_ON(i >= JBD2_MAX_SLABS);
        if (unlikely(i < 0))
                i = 0;
-       BUG_ON(jbd2_slab[i] == 0);
+       BUG_ON(jbd2_slab[i] == NULL);
        return jbd2_slab[i];
 }
 
index 9e2f6a7..c92ea3b 100644 (file)
@@ -2438,7 +2438,7 @@ dbAdjCtl(struct bmap * bmp, s64 blkno, int newval, int alloc, int level)
 
        /* check if this is a control page update for an allocation.
         * if so, update the leaf to reflect the new leaf value using
-        * dbSplit(); otherwise (deallocation), use dbJoin() to udpate
+        * dbSplit(); otherwise (deallocation), use dbJoin() to update
         * the leaf with the new value.  in addition to updating the
         * leaf, dbSplit() will also split the binary buddy system of
         * the leaves, if required, and bubble new values within the
index ea9a6cc..232bea4 100644 (file)
@@ -546,6 +546,40 @@ ssize_t simple_read_from_buffer(void __user *to, size_t count, loff_t *ppos,
        return count;
 }
 
+/**
+ * simple_write_to_buffer - copy data from user space to the buffer
+ * @to: the buffer to write to
+ * @available: the size of the buffer
+ * @ppos: the current position in the buffer
+ * @from: the user space buffer to read from
+ * @count: the maximum number of bytes to read
+ *
+ * The simple_write_to_buffer() function reads up to @count bytes from the user
+ * space address starting at @from into the buffer @to at offset @ppos.
+ *
+ * On success, the number of bytes written is returned and the offset @ppos is
+ * advanced by this number, or negative value is returned on error.
+ **/
+ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
+               const void __user *from, size_t count)
+{
+       loff_t pos = *ppos;
+       size_t res;
+
+       if (pos < 0)
+               return -EINVAL;
+       if (pos >= available || !count)
+               return 0;
+       if (count > available - pos)
+               count = available - pos;
+       res = copy_from_user(to + pos, from, count);
+       if (res == count)
+               return -EFAULT;
+       count -= res;
+       *ppos = pos + count;
+       return count;
+}
+
 /**
  * memory_read_from_buffer - copy data from the buffer
  * @to: the kernel space buffer to read to
@@ -864,6 +898,7 @@ EXPORT_SYMBOL(simple_statfs);
 EXPORT_SYMBOL(simple_sync_file);
 EXPORT_SYMBOL(simple_unlink);
 EXPORT_SYMBOL(simple_read_from_buffer);
+EXPORT_SYMBOL(simple_write_to_buffer);
 EXPORT_SYMBOL(memory_read_from_buffer);
 EXPORT_SYMBOL(simple_transaction_set);
 EXPORT_SYMBOL(simple_transaction_get);
index 243c000..9bd2ce2 100644 (file)
@@ -303,6 +303,11 @@ static void bdev_put_device(struct super_block *sb)
        close_bdev_exclusive(logfs_super(sb)->s_bdev, FMODE_READ|FMODE_WRITE);
 }
 
+static int bdev_can_write_buf(struct super_block *sb, u64 ofs)
+{
+       return 0;
+}
+
 static const struct logfs_device_ops bd_devops = {
        .find_first_sb  = bdev_find_first_sb,
        .find_last_sb   = bdev_find_last_sb,
@@ -310,6 +315,7 @@ static const struct logfs_device_ops bd_devops = {
        .readpage       = bdev_readpage,
        .writeseg       = bdev_writeseg,
        .erase          = bdev_erase,
+       .can_write_buf  = bdev_can_write_buf,
        .sync           = bdev_sync,
        .put_device     = bdev_put_device,
 };
index cafb6ef..a85d47d 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/completion.h>
 #include <linux/mount.h>
 #include <linux/sched.h>
+#include <linux/slab.h>
 
 #define PAGE_OFS(ofs) ((ofs) & (PAGE_SIZE-1))
 
@@ -126,7 +127,8 @@ static int mtd_readpage(void *_sb, struct page *page)
 
        err = mtd_read(sb, page->index << PAGE_SHIFT, PAGE_SIZE,
                        page_address(page));
-       if (err == -EUCLEAN) {
+       if (err == -EUCLEAN || err == -EBADMSG) {
+               /* -EBADMSG happens regularly on power failures */
                err = 0;
                /* FIXME: force GC this segment */
        }
@@ -233,12 +235,32 @@ static void mtd_put_device(struct super_block *sb)
        put_mtd_device(logfs_super(sb)->s_mtd);
 }
 
+static int mtd_can_write_buf(struct super_block *sb, u64 ofs)
+{
+       struct logfs_super *super = logfs_super(sb);
+       void *buf;
+       int err;
+
+       buf = kmalloc(super->s_writesize, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       err = mtd_read(sb, ofs, super->s_writesize, buf);
+       if (err)
+               goto out;
+       if (memchr_inv(buf, 0xff, super->s_writesize))
+               err = -EIO;
+       kfree(buf);
+out:
+       return err;
+}
+
 static const struct logfs_device_ops mtd_devops = {
        .find_first_sb  = mtd_find_first_sb,
        .find_last_sb   = mtd_find_last_sb,
        .readpage       = mtd_readpage,
        .writeseg       = mtd_writeseg,
        .erase          = mtd_erase,
+       .can_write_buf  = mtd_can_write_buf,
        .sync           = mtd_sync,
        .put_device     = mtd_put_device,
 };
@@ -250,5 +272,7 @@ int logfs_get_sb_mtd(struct file_system_type *type, int flags,
        const struct logfs_device_ops *devops = &mtd_devops;
 
        mtd = get_mtd_device(NULL, mtdnr);
+       if (IS_ERR(mtd))
+               return PTR_ERR(mtd);
        return logfs_get_sb_device(type, flags, mtd, NULL, devops, mnt);
 }
index 2396a85..72d1893 100644 (file)
@@ -12,7 +12,7 @@
  * Atomic dir operations
  *
  * Directory operations are by default not atomic.  Dentries and Inodes are
- * created/removed/altered in seperate operations.  Therefore we need to do
+ * created/removed/altered in separate operations.  Therefore we need to do
  * a small amount of journaling.
  *
  * Create, link, mkdir, mknod and symlink all share the same function to do
index 370f367..0de5240 100644 (file)
@@ -161,7 +161,17 @@ static int logfs_writepage(struct page *page, struct writeback_control *wbc)
 
 static void logfs_invalidatepage(struct page *page, unsigned long offset)
 {
-       move_page_to_btree(page);
+       struct logfs_block *block = logfs_block(page);
+
+       if (block->reserved_bytes) {
+               struct super_block *sb = page->mapping->host->i_sb;
+               struct logfs_super *super = logfs_super(sb);
+
+               super->s_dirty_pages -= block->reserved_bytes;
+               block->ops->free_block(sb, block);
+               BUG_ON(bitmap_weight(block->alias_map, LOGFS_BLOCK_FACTOR));
+       } else
+               move_page_to_btree(page);
        BUG_ON(PagePrivate(page) || page->private);
 }
 
@@ -212,10 +222,8 @@ int logfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 int logfs_fsync(struct file *file, struct dentry *dentry, int datasync)
 {
        struct super_block *sb = dentry->d_inode->i_sb;
-       struct logfs_super *super = logfs_super(sb);
 
-       /* FIXME: write anchor */
-       super->s_devops->sync(sb);
+       logfs_write_anchor(sb);
        return 0;
 }
 
index 76c242f..caa4419 100644 (file)
@@ -122,7 +122,7 @@ static void logfs_cleanse_block(struct super_block *sb, u64 ofs, u64 ino,
        logfs_safe_iput(inode, cookie);
 }
 
-static u32 logfs_gc_segment(struct super_block *sb, u32 segno, u8 dist)
+static u32 logfs_gc_segment(struct super_block *sb, u32 segno)
 {
        struct logfs_super *super = logfs_super(sb);
        struct logfs_segment_header sh;
@@ -401,7 +401,7 @@ static int __logfs_gc_once(struct super_block *sb, struct gc_candidate *cand)
                        segno, (u64)segno << super->s_segshift,
                        dist, no_free_segments(sb), valid,
                        super->s_free_bytes);
-       cleaned = logfs_gc_segment(sb, segno, dist);
+       cleaned = logfs_gc_segment(sb, segno);
        log_gc("GC segment #%02x complete - now %x valid\n", segno,
                        valid - cleaned);
        BUG_ON(cleaned != valid);
@@ -632,38 +632,31 @@ static int check_area(struct super_block *sb, int i)
 {
        struct logfs_super *super = logfs_super(sb);
        struct logfs_area *area = super->s_area[i];
-       struct logfs_object_header oh;
+       gc_level_t gc_level;
+       u32 cleaned, valid, ec;
        u32 segno = area->a_segno;
-       u32 ofs = area->a_used_bytes;
-       __be32 crc;
-       int err;
+       u64 ofs = dev_ofs(sb, area->a_segno, area->a_written_bytes);
 
        if (!area->a_is_open)
                return 0;
 
-       for (ofs = area->a_used_bytes;
-            ofs <= super->s_segsize - sizeof(oh);
-            ofs += (u32)be16_to_cpu(oh.len) + sizeof(oh)) {
-               err = wbuf_read(sb, dev_ofs(sb, segno, ofs), sizeof(oh), &oh);
-               if (err)
-                       return err;
-
-               if (!memchr_inv(&oh, 0xff, sizeof(oh)))
-                       break;
+       if (super->s_devops->can_write_buf(sb, ofs) == 0)
+               return 0;
 
-               crc = logfs_crc32(&oh, sizeof(oh) - 4, 4);
-               if (crc != oh.crc) {
-                       printk(KERN_INFO "interrupted header at %llx\n",
-                                       dev_ofs(sb, segno, ofs));
-                       return 0;
-               }
-       }
-       if (ofs != area->a_used_bytes) {
-               printk(KERN_INFO "%x bytes unaccounted data found at %llx\n",
-                               ofs - area->a_used_bytes,
-                               dev_ofs(sb, segno, area->a_used_bytes));
-               area->a_used_bytes = ofs;
-       }
+       printk(KERN_INFO"LogFS: Possibly incomplete write at %llx\n", ofs);
+       /*
+        * The device cannot write back the write buffer.  Most likely the
+        * wbuf was already written out and the system crashed at some point
+        * before the journal commit happened.  In that case we wouldn't have
+        * to do anything.  But if the crash happened before the wbuf was
+        * written out correctly, we must GC this segment.  So assume the
+        * worst and always do the GC run.
+        */
+       area->a_is_open = 0;
+       valid = logfs_valid_bytes(sb, segno, &ec, &gc_level);
+       cleaned = logfs_gc_segment(sb, segno);
+       if (cleaned != valid)
+               return -EIO;
        return 0;
 }
 
index 14ed272..755a92e 100644 (file)
@@ -193,6 +193,7 @@ static void logfs_init_inode(struct super_block *sb, struct inode *inode)
        inode->i_ctime  = CURRENT_TIME;
        inode->i_mtime  = CURRENT_TIME;
        inode->i_nlink  = 1;
+       li->li_refcount = 1;
        INIT_LIST_HEAD(&li->li_freeing_list);
 
        for (i = 0; i < LOGFS_EMBEDDED_FIELDS; i++)
@@ -326,7 +327,7 @@ static void logfs_set_ino_generation(struct super_block *sb,
        u64 ino;
 
        mutex_lock(&super->s_journal_mutex);
-       ino = logfs_seek_hole(super->s_master_inode, super->s_last_ino);
+       ino = logfs_seek_hole(super->s_master_inode, super->s_last_ino + 1);
        super->s_last_ino = ino;
        super->s_inos_till_wrap--;
        if (super->s_inos_till_wrap < 0) {
@@ -386,8 +387,7 @@ static void logfs_init_once(void *_li)
 
 static int logfs_sync_fs(struct super_block *sb, int wait)
 {
-       /* FIXME: write anchor */
-       logfs_super(sb)->s_devops->sync(sb);
+       logfs_write_anchor(sb);
        return 0;
 }
 
index fb0a613..4b0e061 100644 (file)
@@ -132,10 +132,9 @@ static int read_area(struct super_block *sb, struct logfs_je_area *a)
 
        ofs = dev_ofs(sb, area->a_segno, area->a_written_bytes);
        if (super->s_writesize > 1)
-               logfs_buf_recover(area, ofs, a + 1, super->s_writesize);
+               return logfs_buf_recover(area, ofs, a + 1, super->s_writesize);
        else
-               logfs_buf_recover(area, ofs, NULL, 0);
-       return 0;
+               return logfs_buf_recover(area, ofs, NULL, 0);
 }
 
 static void *unpack(void *from, void *to)
@@ -245,7 +244,7 @@ static int read_je(struct super_block *sb, u64 ofs)
                read_erasecount(sb, unpack(jh, scratch));
                break;
        case JE_AREA:
-               read_area(sb, unpack(jh, scratch));
+               err = read_area(sb, unpack(jh, scratch));
                break;
        case JE_OBJ_ALIAS:
                err = logfs_load_object_aliases(sb, unpack(jh, scratch),
index 0a3df1a..1a9db84 100644 (file)
@@ -144,6 +144,7 @@ struct logfs_area_ops {
  * @erase:                     erase one segment
  * @read:                      read from the device
  * @erase:                     erase part of the device
+ * @can_write_buf:             decide whether wbuf can be written to ofs
  */
 struct logfs_device_ops {
        struct page *(*find_first_sb)(struct super_block *sb, u64 *ofs);
@@ -153,6 +154,7 @@ struct logfs_device_ops {
        void (*writeseg)(struct super_block *sb, u64 ofs, size_t len);
        int (*erase)(struct super_block *sb, loff_t ofs, size_t len,
                        int ensure_write);
+       int (*can_write_buf)(struct super_block *sb, u64 ofs);
        void (*sync)(struct super_block *sb);
        void (*put_device)(struct super_block *sb);
 };
@@ -394,6 +396,7 @@ struct logfs_super {
        int      s_lock_count;
        mempool_t *s_block_pool;                /* struct logfs_block pool */
        mempool_t *s_shadow_pool;               /* struct logfs_shadow pool */
+       struct list_head s_writeback_list;      /* writeback pages */
        /*
         * Space accounting:
         * - s_used_bytes specifies space used to store valid data objects.
@@ -598,19 +601,19 @@ void freeseg(struct super_block *sb, u32 segno);
 int logfs_init_areas(struct super_block *sb);
 void logfs_cleanup_areas(struct super_block *sb);
 int logfs_open_area(struct logfs_area *area, size_t bytes);
-void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
+int __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
                int use_filler);
 
-static inline void logfs_buf_write(struct logfs_area *area, u64 ofs,
+static inline int logfs_buf_write(struct logfs_area *area, u64 ofs,
                void *buf, size_t len)
 {
-       __logfs_buf_write(area, ofs, buf, len, 0);
+       return __logfs_buf_write(area, ofs, buf, len, 0);
 }
 
-static inline void logfs_buf_recover(struct logfs_area *area, u64 ofs,
+static inline int logfs_buf_recover(struct logfs_area *area, u64 ofs,
                void *buf, size_t len)
 {
-       __logfs_buf_write(area, ofs, buf, len, 1);
+       return __logfs_buf_write(area, ofs, buf, len, 1);
 }
 
 /* super.c */
@@ -704,7 +707,7 @@ static inline gc_level_t expand_level(u64 ino, level_t __level)
        u8 level = (__force u8)__level;
 
        if (ino == LOGFS_INO_MASTER) {
-               /* ifile has seperate areas */
+               /* ifile has separate areas */
                level += LOGFS_MAX_LEVELS;
        }
        return (__force gc_level_t)level;
index f674725..ae96051 100644 (file)
@@ -50,9 +50,9 @@ static inline void check_##type(void)                         \
  * 12  - gc recycled blocks, long-lived data
  * 13  - replacement blocks, short-lived data
  *
- * Levels 1-11 are necessary for robust gc operations and help seperate
+ * Levels 1-11 are necessary for robust gc operations and help separate
  * short-lived metadata from longer-lived file data.  In the future,
- * file data should get seperated into several segments based on simple
+ * file data should get separated into several segments based on simple
  * heuristics.  Old data recycled during gc operation is expected to be
  * long-lived.  New data is of uncertain life expectancy.  New data
  * used to replace older blocks in existing files is expected to be
@@ -117,7 +117,7 @@ static inline void check_##type(void)                               \
 #define pure_ofs(ofs) (ofs & ~LOGFS_FULLY_POPULATED)
 
 /*
- * LogFS needs to seperate data into levels.  Each level is defined as the
+ * LogFS needs to separate data into levels.  Each level is defined as the
  * maximal possible distance from the master inode (inode of the inode file).
  * Data blocks reside on level 0, 1x indirect block on level 1, etc.
  * Inodes reside on level 6, indirect blocks for the inode file on levels 7-11.
@@ -204,7 +204,7 @@ SIZE_CHECK(logfs_segment_header, LOGFS_SEGMENT_HEADERSIZE);
  * @ds_crc:                    crc32 of structure starting with the next field
  * @ds_ifile_levels:           maximum number of levels for ifile
  * @ds_iblock_levels:          maximum number of levels for regular files
- * @ds_data_levels:            number of seperate levels for data
+ * @ds_data_levels:            number of separate levels for data
  * @pad0:                      reserved, must be 0
  * @ds_feature_incompat:       incompatible filesystem features
  * @ds_feature_ro_compat:      read-only compatible filesystem features
@@ -456,7 +456,7 @@ enum logfs_vim {
  * @vim:                       life expectancy of data
  *
  * "Areas" are segments currently being used for writing.  There is at least
- * one area per GC level.  Several may be used to seperate long-living from
+ * one area per GC level.  Several may be used to separate long-living from
  * short-living data.  If an area with unknown vim is encountered, it can
  * simply be closed.
  * The write buffer immediately follow this header.
index 3159db6..0718d11 100644 (file)
@@ -892,6 +892,8 @@ u64 logfs_seek_hole(struct inode *inode, u64 bix)
                return bix;
        else if (li->li_data[INDIRECT_INDEX] & LOGFS_FULLY_POPULATED)
                bix = maxbix(li->li_height);
+       else if (bix >= maxbix(li->li_height))
+               return bix;
        else {
                bix = seek_holedata_loop(inode, bix, 0);
                if (bix < maxbix(li->li_height))
@@ -1093,17 +1095,25 @@ static int logfs_reserve_bytes(struct inode *inode, int bytes)
 int get_page_reserve(struct inode *inode, struct page *page)
 {
        struct logfs_super *super = logfs_super(inode->i_sb);
+       struct logfs_block *block = logfs_block(page);
        int ret;
 
-       if (logfs_block(page) && logfs_block(page)->reserved_bytes)
+       if (block && block->reserved_bytes)
                return 0;
 
        logfs_get_wblocks(inode->i_sb, page, WF_LOCK);
-       ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE);
+       while ((ret = logfs_reserve_bytes(inode, 6 * LOGFS_MAX_OBJECTSIZE)) &&
+                       !list_empty(&super->s_writeback_list)) {
+               block = list_entry(super->s_writeback_list.next,
+                               struct logfs_block, alias_list);
+               block->ops->write_block(block);
+       }
        if (!ret) {
                alloc_data_block(inode, page);
-               logfs_block(page)->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE;
+               block = logfs_block(page);
+               block->reserved_bytes += 6 * LOGFS_MAX_OBJECTSIZE;
                super->s_dirty_pages += 6 * LOGFS_MAX_OBJECTSIZE;
+               list_move_tail(&block->alias_list, &super->s_writeback_list);
        }
        logfs_put_wblocks(inode->i_sb, page, WF_LOCK);
        return ret;
@@ -1861,7 +1871,7 @@ int logfs_truncate(struct inode *inode, u64 target)
                        size = target;
 
                logfs_get_wblocks(sb, NULL, 1);
-               err = __logfs_truncate(inode, target);
+               err = __logfs_truncate(inode, size);
                if (!err)
                        err = __logfs_write_inode(inode, 0);
                logfs_put_wblocks(sb, NULL, 1);
@@ -2249,6 +2259,7 @@ int logfs_init_rw(struct super_block *sb)
        int min_fill = 3 * super->s_no_blocks;
 
        INIT_LIST_HEAD(&super->s_object_alias);
+       INIT_LIST_HEAD(&super->s_writeback_list);
        mutex_init(&super->s_write_mutex);
        super->s_block_pool = mempool_create_kmalloc_pool(min_fill,
                        sizeof(struct logfs_block));
index f77ce2b..a9657af 100644 (file)
@@ -67,7 +67,7 @@ static struct page *get_mapping_page(struct super_block *sb, pgoff_t index,
        return page;
 }
 
-void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
+int __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
                int use_filler)
 {
        pgoff_t index = ofs >> PAGE_SHIFT;
@@ -81,8 +81,10 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
                copylen = min((ulong)len, PAGE_SIZE - offset);
 
                page = get_mapping_page(area->a_sb, index, use_filler);
-               SetPageUptodate(page);
+               if (IS_ERR(page))
+                       return PTR_ERR(page);
                BUG_ON(!page); /* FIXME: reserve a pool */
+               SetPageUptodate(page);
                memcpy(page_address(page) + offset, buf, copylen);
                SetPagePrivate(page);
                page_cache_release(page);
@@ -92,6 +94,7 @@ void __logfs_buf_write(struct logfs_area *area, u64 ofs, void *buf, size_t len,
                offset = 0;
                index++;
        } while (len);
+       return 0;
 }
 
 static void pad_partial_page(struct logfs_area *area)
index d7c23ed..d651e10 100644 (file)
@@ -138,10 +138,14 @@ static int logfs_sb_set(struct super_block *sb, void *_super)
        sb->s_fs_info = super;
        sb->s_mtd = super->s_mtd;
        sb->s_bdev = super->s_bdev;
+#ifdef CONFIG_BLOCK
        if (sb->s_bdev)
                sb->s_bdi = &bdev_get_queue(sb->s_bdev)->backing_dev_info;
+#endif
+#ifdef CONFIG_MTD
        if (sb->s_mtd)
                sb->s_bdi = sb->s_mtd->backing_dev_info;
+#endif
        return 0;
 }
 
@@ -382,7 +386,7 @@ static struct page *find_super_block(struct super_block *sb)
        if (!first || IS_ERR(first))
                return NULL;
        last = super->s_devops->find_last_sb(sb, &super->s_sb_ofs[1]);
-       if (!last || IS_ERR(first)) {
+       if (!last || IS_ERR(last)) {
                page_cache_release(first);
                return NULL;
        }
@@ -413,7 +417,7 @@ static int __logfs_read_sb(struct super_block *sb)
 
        page = find_super_block(sb);
        if (!page)
-               return -EIO;
+               return -EINVAL;
 
        ds = page_address(page);
        super->s_size = be64_to_cpu(ds->ds_filesystem_size);
index f20cb57..88058de 100644 (file)
@@ -628,7 +628,6 @@ repeat:
                mnt->mnt_pinned = 0;
                spin_unlock(&vfsmount_lock);
                acct_auto_close_mnt(mnt);
-               security_sb_umount_close(mnt);
                goto repeat;
        }
 }
@@ -1117,8 +1116,6 @@ static int do_umount(struct vfsmount *mnt, int flags)
                retval = 0;
        }
        spin_unlock(&vfsmount_lock);
-       if (retval)
-               security_sb_umount_busy(mnt);
        up_write(&namespace_sem);
        release_mounts(&umount_list);
        return retval;
@@ -1435,17 +1432,10 @@ static int graft_tree(struct vfsmount *mnt, struct path *path)
        if (cant_mount(path->dentry))
                goto out_unlock;
 
-       err = security_sb_check_sb(mnt, path);
-       if (err)
-               goto out_unlock;
-
-       err = -ENOENT;
        if (!d_unlinked(path->dentry))
                err = attach_recursive_mnt(mnt, path, NULL);
 out_unlock:
        mutex_unlock(&path->dentry->d_inode->i_mutex);
-       if (!err)
-               security_sb_post_addmount(mnt, path);
        return err;
 }
 
@@ -1581,8 +1571,6 @@ static int do_remount(struct path *path, int flags, int mnt_flags,
        }
        up_write(&sb->s_umount);
        if (!err) {
-               security_sb_post_remount(path->mnt, flags, data);
-
                spin_lock(&vfsmount_lock);
                touch_mnt_namespace(path->mnt->mnt_ns);
                spin_unlock(&vfsmount_lock);
@@ -2277,7 +2265,6 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
        touch_mnt_namespace(current->nsproxy->mnt_ns);
        spin_unlock(&vfsmount_lock);
        chroot_fs_refs(&root, &new);
-       security_sb_post_pivotroot(&root, &new);
        error = 0;
        path_put(&root_parent);
        path_put(&parent_path);
index acc9c49..7ec9b34 100644 (file)
@@ -934,7 +934,6 @@ static int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *mntfh, str
        }
 
        fsinfo.fattr = fattr;
-       nfs_fattr_init(fattr);
        error = clp->rpc_ops->fsinfo(server, mntfh, &fsinfo);
        if (error < 0)
                goto out_error;
@@ -1047,13 +1046,18 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
                                     struct nfs_fh *mntfh)
 {
        struct nfs_server *server;
-       struct nfs_fattr fattr;
+       struct nfs_fattr *fattr;
        int error;
 
        server = nfs_alloc_server();
        if (!server)
                return ERR_PTR(-ENOMEM);
 
+       error = -ENOMEM;
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto error;
+
        /* Get a client representation */
        error = nfs_init_server(server, data);
        if (error < 0)
@@ -1064,7 +1068,7 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
        BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
 
        /* Probe the root fh to retrieve its FSID */
-       error = nfs_probe_fsinfo(server, mntfh, &fattr);
+       error = nfs_probe_fsinfo(server, mntfh, fattr);
        if (error < 0)
                goto error;
        if (server->nfs_client->rpc_ops->version == 3) {
@@ -1077,14 +1081,14 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
                        server->namelen = NFS2_MAXNAMLEN;
        }
 
-       if (!(fattr.valid & NFS_ATTR_FATTR)) {
-               error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr);
+       if (!(fattr->valid & NFS_ATTR_FATTR)) {
+               error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
                if (error < 0) {
                        dprintk("nfs_create_server: getattr error = %d\n", -error);
                        goto error;
                }
        }
-       memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
+       memcpy(&server->fsid, &fattr->fsid, sizeof(server->fsid));
 
        dprintk("Server FSID: %llx:%llx\n",
                (unsigned long long) server->fsid.major,
@@ -1096,9 +1100,11 @@ struct nfs_server *nfs_create_server(const struct nfs_parsed_mount_data *data,
        spin_unlock(&nfs_client_lock);
 
        server->mount_time = jiffies;
+       nfs_free_fattr(fattr);
        return server;
 
 error:
+       nfs_free_fattr(fattr);
        nfs_free_server(server);
        return ERR_PTR(error);
 }
@@ -1340,7 +1346,7 @@ error:
 struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
                                      struct nfs_fh *mntfh)
 {
-       struct nfs_fattr fattr;
+       struct nfs_fattr *fattr;
        struct nfs_server *server;
        int error;
 
@@ -1350,6 +1356,11 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
        if (!server)
                return ERR_PTR(-ENOMEM);
 
+       error = -ENOMEM;
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto error;
+
        /* set up the general RPC client */
        error = nfs4_init_server(server, data);
        if (error < 0)
@@ -1364,7 +1375,7 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
                goto error;
 
        /* Probe the root fh to retrieve its FSID */
-       error = nfs4_path_walk(server, mntfh, data->nfs_server.export_path);
+       error = nfs4_get_rootfh(server, mntfh);
        if (error < 0)
                goto error;
 
@@ -1375,7 +1386,7 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
 
        nfs4_session_set_rwsize(server);
 
-       error = nfs_probe_fsinfo(server, mntfh, &fattr);
+       error = nfs_probe_fsinfo(server, mntfh, fattr);
        if (error < 0)
                goto error;
 
@@ -1389,9 +1400,11 @@ struct nfs_server *nfs4_create_server(const struct nfs_parsed_mount_data *data,
 
        server->mount_time = jiffies;
        dprintk("<-- nfs4_create_server() = %p\n", server);
+       nfs_free_fattr(fattr);
        return server;
 
 error:
+       nfs_free_fattr(fattr);
        nfs_free_server(server);
        dprintk("<-- nfs4_create_server() = error %d\n", error);
        return ERR_PTR(error);
@@ -1405,7 +1418,7 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
 {
        struct nfs_client *parent_client;
        struct nfs_server *server, *parent_server;
-       struct nfs_fattr fattr;
+       struct nfs_fattr *fattr;
        int error;
 
        dprintk("--> nfs4_create_referral_server()\n");
@@ -1414,6 +1427,11 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
        if (!server)
                return ERR_PTR(-ENOMEM);
 
+       error = -ENOMEM;
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto error;
+
        parent_server = NFS_SB(data->sb);
        parent_client = parent_server->nfs_client;
 
@@ -1443,12 +1461,12 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
        BUG_ON(!server->nfs_client->rpc_ops->file_inode_ops);
 
        /* Probe the root fh to retrieve its FSID and filehandle */
-       error = nfs4_path_walk(server, mntfh, data->mnt_path);
+       error = nfs4_get_rootfh(server, mntfh);
        if (error < 0)
                goto error;
 
        /* probe the filesystem info for this server filesystem */
-       error = nfs_probe_fsinfo(server, mntfh, &fattr);
+       error = nfs_probe_fsinfo(server, mntfh, fattr);
        if (error < 0)
                goto error;
 
@@ -1466,10 +1484,12 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data,
 
        server->mount_time = jiffies;
 
+       nfs_free_fattr(fattr);
        dprintk("<-- nfs_create_referral_server() = %p\n", server);
        return server;
 
 error:
+       nfs_free_fattr(fattr);
        nfs_free_server(server);
        dprintk("<-- nfs4_create_referral_server() = error %d\n", error);
        return ERR_PTR(error);
@@ -1485,7 +1505,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
                                    struct nfs_fattr *fattr)
 {
        struct nfs_server *server;
-       struct nfs_fattr fattr_fsinfo;
+       struct nfs_fattr *fattr_fsinfo;
        int error;
 
        dprintk("--> nfs_clone_server(,%llx:%llx,)\n",
@@ -1496,6 +1516,11 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
        if (!server)
                return ERR_PTR(-ENOMEM);
 
+       error = -ENOMEM;
+       fattr_fsinfo = nfs_alloc_fattr();
+       if (fattr_fsinfo == NULL)
+               goto out_free_server;
+
        /* Copy data from the source */
        server->nfs_client = source->nfs_client;
        atomic_inc(&server->nfs_client->cl_count);
@@ -1512,7 +1537,7 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
                nfs_init_server_aclclient(server);
 
        /* probe the filesystem info for this server filesystem */
-       error = nfs_probe_fsinfo(server, fh, &fattr_fsinfo);
+       error = nfs_probe_fsinfo(server, fh, fattr_fsinfo);
        if (error < 0)
                goto out_free_server;
 
@@ -1534,10 +1559,12 @@ struct nfs_server *nfs_clone_server(struct nfs_server *source,
 
        server->mount_time = jiffies;
 
+       nfs_free_fattr(fattr_fsinfo);
        dprintk("<-- nfs_clone_server() = %p\n", server);
        return server;
 
 out_free_server:
+       nfs_free_fattr(fattr_fsinfo);
        nfs_free_server(server);
        dprintk("<-- nfs_clone_server() = error %d\n", error);
        return ERR_PTR(error);
index ea61d26..3016345 100644 (file)
@@ -213,7 +213,7 @@ int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct
        struct nfs_delegation *freeme = NULL;
        int status = 0;
 
-       delegation = kmalloc(sizeof(*delegation), GFP_KERNEL);
+       delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
        if (delegation == NULL)
                return -ENOMEM;
        memcpy(delegation->stateid.data, res->delegation.data,
index a7bb5c6..ee9a179 100644 (file)
@@ -530,9 +530,7 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
        nfs_readdir_descriptor_t my_desc,
                        *desc = &my_desc;
        struct nfs_entry my_entry;
-       struct nfs_fh    fh;
-       struct nfs_fattr fattr;
-       long            res;
+       int res = -ENOMEM;
 
        dfprintk(FILE, "NFS: readdir(%s/%s) starting at cookie %llu\n",
                        dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -554,9 +552,11 @@ static int nfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
 
        my_entry.cookie = my_entry.prev_cookie = 0;
        my_entry.eof = 0;
-       my_entry.fh = &fh;
-       my_entry.fattr = &fattr;
-       nfs_fattr_init(&fattr);
+       my_entry.fh = nfs_alloc_fhandle();
+       my_entry.fattr = nfs_alloc_fattr();
+       if (my_entry.fh == NULL || my_entry.fattr == NULL)
+               goto out_alloc_failed;
+
        desc->entry = &my_entry;
 
        nfs_block_sillyrename(dentry);
@@ -598,7 +598,10 @@ out:
        nfs_unblock_sillyrename(dentry);
        if (res > 0)
                res = 0;
-       dfprintk(FILE, "NFS: readdir(%s/%s) returns %ld\n",
+out_alloc_failed:
+       nfs_free_fattr(my_entry.fattr);
+       nfs_free_fhandle(my_entry.fh);
+       dfprintk(FILE, "NFS: readdir(%s/%s) returns %d\n",
                        dentry->d_parent->d_name.name, dentry->d_name.name,
                        res);
        return res;
@@ -776,9 +779,9 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
        struct inode *dir;
        struct inode *inode;
        struct dentry *parent;
+       struct nfs_fh *fhandle = NULL;
+       struct nfs_fattr *fattr = NULL;
        int error;
-       struct nfs_fh fhandle;
-       struct nfs_fattr fattr;
 
        parent = dget_parent(dentry);
        dir = parent->d_inode;
@@ -811,14 +814,22 @@ static int nfs_lookup_revalidate(struct dentry * dentry, struct nameidata *nd)
        if (NFS_STALE(inode))
                goto out_bad;
 
-       error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr);
+       error = -ENOMEM;
+       fhandle = nfs_alloc_fhandle();
+       fattr = nfs_alloc_fattr();
+       if (fhandle == NULL || fattr == NULL)
+               goto out_error;
+
+       error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
        if (error)
                goto out_bad;
-       if (nfs_compare_fh(NFS_FH(inode), &fhandle))
+       if (nfs_compare_fh(NFS_FH(inode), fhandle))
                goto out_bad;
-       if ((error = nfs_refresh_inode(inode, &fattr)) != 0)
+       if ((error = nfs_refresh_inode(inode, fattr)) != 0)
                goto out_bad;
 
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fhandle);
 out_set_verifier:
        nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
  out_valid:
@@ -842,11 +853,21 @@ out_zap_parent:
                shrink_dcache_parent(dentry);
        }
        d_drop(dentry);
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fhandle);
        dput(parent);
        dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) is invalid\n",
                        __func__, dentry->d_parent->d_name.name,
                        dentry->d_name.name);
        return 0;
+out_error:
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fhandle);
+       dput(parent);
+       dfprintk(LOOKUPCACHE, "NFS: %s(%s/%s) lookup returned error %d\n",
+                       __func__, dentry->d_parent->d_name.name,
+                       dentry->d_name.name, error);
+       return error;
 }
 
 /*
@@ -911,9 +932,9 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
        struct dentry *res;
        struct dentry *parent;
        struct inode *inode = NULL;
+       struct nfs_fh *fhandle = NULL;
+       struct nfs_fattr *fattr = NULL;
        int error;
-       struct nfs_fh fhandle;
-       struct nfs_fattr fattr;
 
        dfprintk(VFS, "NFS: lookup(%s/%s)\n",
                dentry->d_parent->d_name.name, dentry->d_name.name);
@@ -923,7 +944,6 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
        if (dentry->d_name.len > NFS_SERVER(dir)->namelen)
                goto out;
 
-       res = ERR_PTR(-ENOMEM);
        dentry->d_op = NFS_PROTO(dir)->dentry_ops;
 
        /*
@@ -936,17 +956,23 @@ static struct dentry *nfs_lookup(struct inode *dir, struct dentry * dentry, stru
                goto out;
        }
 
+       res = ERR_PTR(-ENOMEM);
+       fhandle = nfs_alloc_fhandle();
+       fattr = nfs_alloc_fattr();
+       if (fhandle == NULL || fattr == NULL)
+               goto out;
+
        parent = dentry->d_parent;
        /* Protect against concurrent sillydeletes */
        nfs_block_sillyrename(parent);
-       error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, &fhandle, &fattr);
+       error = NFS_PROTO(dir)->lookup(dir, &dentry->d_name, fhandle, fattr);
        if (error == -ENOENT)
                goto no_entry;
        if (error < 0) {
                res = ERR_PTR(error);
                goto out_unblock_sillyrename;
        }
-       inode = nfs_fhget(dentry->d_sb, &fhandle, &fattr);
+       inode = nfs_fhget(dentry->d_sb, fhandle, fattr);
        res = (struct dentry *)inode;
        if (IS_ERR(res))
                goto out_unblock_sillyrename;
@@ -962,6 +988,8 @@ no_entry:
 out_unblock_sillyrename:
        nfs_unblock_sillyrename(parent);
 out:
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fhandle);
        return res;
 }
 
@@ -1669,28 +1697,33 @@ static void nfs_access_free_entry(struct nfs_access_entry *entry)
        smp_mb__after_atomic_dec();
 }
 
+static void nfs_access_free_list(struct list_head *head)
+{
+       struct nfs_access_entry *cache;
+
+       while (!list_empty(head)) {
+               cache = list_entry(head->next, struct nfs_access_entry, lru);
+               list_del(&cache->lru);
+               nfs_access_free_entry(cache);
+       }
+}
+
 int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask)
 {
        LIST_HEAD(head);
        struct nfs_inode *nfsi;
        struct nfs_access_entry *cache;
 
-restart:
+       if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
+               return (nr_to_scan == 0) ? 0 : -1;
+
        spin_lock(&nfs_access_lru_lock);
        list_for_each_entry(nfsi, &nfs_access_lru_list, access_cache_inode_lru) {
-               struct rw_semaphore *s_umount;
                struct inode *inode;
 
                if (nr_to_scan-- == 0)
                        break;
-               s_umount = &nfsi->vfs_inode.i_sb->s_umount;
-               if (!down_read_trylock(s_umount))
-                       continue;
-               inode = igrab(&nfsi->vfs_inode);
-               if (inode == NULL) {
-                       up_read(s_umount);
-                       continue;
-               }
+               inode = &nfsi->vfs_inode;
                spin_lock(&inode->i_lock);
                if (list_empty(&nfsi->access_cache_entry_lru))
                        goto remove_lru_entry;
@@ -1704,61 +1737,47 @@ restart:
                else {
 remove_lru_entry:
                        list_del_init(&nfsi->access_cache_inode_lru);
+                       smp_mb__before_clear_bit();
                        clear_bit(NFS_INO_ACL_LRU_SET, &nfsi->flags);
+                       smp_mb__after_clear_bit();
                }
-               spin_unlock(&inode->i_lock);
-               spin_unlock(&nfs_access_lru_lock);
-               iput(inode);
-               up_read(s_umount);
-               goto restart;
        }
        spin_unlock(&nfs_access_lru_lock);
-       while (!list_empty(&head)) {
-               cache = list_entry(head.next, struct nfs_access_entry, lru);
-               list_del(&cache->lru);
-               nfs_access_free_entry(cache);
-       }
+       nfs_access_free_list(&head);
        return (atomic_long_read(&nfs_access_nr_entries) / 100) * sysctl_vfs_cache_pressure;
 }
 
-static void __nfs_access_zap_cache(struct inode *inode)
+static void __nfs_access_zap_cache(struct nfs_inode *nfsi, struct list_head *head)
 {
-       struct nfs_inode *nfsi = NFS_I(inode);
        struct rb_root *root_node = &nfsi->access_cache;
-       struct rb_node *n, *dispose = NULL;
+       struct rb_node *n;
        struct nfs_access_entry *entry;
 
        /* Unhook entries from the cache */
        while ((n = rb_first(root_node)) != NULL) {
                entry = rb_entry(n, struct nfs_access_entry, rb_node);
                rb_erase(n, root_node);
-               list_del(&entry->lru);
-               n->rb_left = dispose;
-               dispose = n;
+               list_move(&entry->lru, head);
        }
        nfsi->cache_validity &= ~NFS_INO_INVALID_ACCESS;
-       spin_unlock(&inode->i_lock);
-
-       /* Now kill them all! */
-       while (dispose != NULL) {
-               n = dispose;
-               dispose = n->rb_left;
-               nfs_access_free_entry(rb_entry(n, struct nfs_access_entry, rb_node));
-       }
 }
 
 void nfs_access_zap_cache(struct inode *inode)
 {
+       LIST_HEAD(head);
+
+       if (test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags) == 0)
+               return;
        /* Remove from global LRU init */
-       if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) {
-               spin_lock(&nfs_access_lru_lock);
+       spin_lock(&nfs_access_lru_lock);
+       if (test_and_clear_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
                list_del_init(&NFS_I(inode)->access_cache_inode_lru);
-               spin_unlock(&nfs_access_lru_lock);
-       }
 
        spin_lock(&inode->i_lock);
-       /* This will release the spinlock */
-       __nfs_access_zap_cache(inode);
+       __nfs_access_zap_cache(NFS_I(inode), &head);
+       spin_unlock(&inode->i_lock);
+       spin_unlock(&nfs_access_lru_lock);
+       nfs_access_free_list(&head);
 }
 
 static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, struct rpc_cred *cred)
@@ -1809,8 +1828,8 @@ out_stale:
        nfs_access_free_entry(cache);
        return -ENOENT;
 out_zap:
-       /* This will release the spinlock */
-       __nfs_access_zap_cache(inode);
+       spin_unlock(&inode->i_lock);
+       nfs_access_zap_cache(inode);
        return -ENOENT;
 }
 
@@ -1865,9 +1884,11 @@ static void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *s
        smp_mb__after_atomic_inc();
 
        /* Add inode to global LRU list */
-       if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) {
+       if (!test_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags)) {
                spin_lock(&nfs_access_lru_lock);
-               list_add_tail(&NFS_I(inode)->access_cache_inode_lru, &nfs_access_lru_list);
+               if (!test_and_set_bit(NFS_INO_ACL_LRU_SET, &NFS_I(inode)->flags))
+                       list_add_tail(&NFS_I(inode)->access_cache_inode_lru,
+                                       &nfs_access_lru_list);
                spin_unlock(&nfs_access_lru_lock);
        }
 }
index 8d965bd..cac96bc 100644 (file)
@@ -161,14 +161,17 @@ static int nfs_revalidate_file_size(struct inode *inode, struct file *filp)
        struct nfs_server *server = NFS_SERVER(inode);
        struct nfs_inode *nfsi = NFS_I(inode);
 
-       if (server->flags & NFS_MOUNT_NOAC)
-               goto force_reval;
+       if (nfs_have_delegated_attributes(inode))
+               goto out_noreval;
+
        if (filp->f_flags & O_DIRECT)
                goto force_reval;
-       if (nfsi->npages != 0)
-               return 0;
-       if (!(nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) && !nfs_attribute_timeout(inode))
-               return 0;
+       if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
+               goto force_reval;
+       if (nfs_attribute_timeout(inode))
+               goto force_reval;
+out_noreval:
+       return 0;
 force_reval:
        return __nfs_revalidate_inode(server, inode);
 }
index a6b16ed..ce153a6 100644 (file)
@@ -467,7 +467,8 @@ int __nfs_readpages_from_fscache(struct nfs_open_context *ctx,
                                 struct list_head *pages,
                                 unsigned *nr_pages)
 {
-       int ret, npages = *nr_pages;
+       unsigned npages = *nr_pages;
+       int ret;
 
        dfprintk(FSCACHE, "NFS: nfs_getpages_from_fscache (0x%p/%u/0x%p)\n",
                 NFS_I(inode)->fscache, npages, inode);
index b35d2a6..7428f7d 100644 (file)
@@ -78,159 +78,94 @@ struct dentry *nfs_get_root(struct super_block *sb, struct nfs_fh *mntfh)
 {
        struct nfs_server *server = NFS_SB(sb);
        struct nfs_fsinfo fsinfo;
-       struct nfs_fattr fattr;
-       struct dentry *mntroot;
+       struct dentry *ret;
        struct inode *inode;
        int error;
 
        /* get the actual root for this mount */
-       fsinfo.fattr = &fattr;
+       fsinfo.fattr = nfs_alloc_fattr();
+       if (fsinfo.fattr == NULL)
+               return ERR_PTR(-ENOMEM);
 
        error = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
        if (error < 0) {
                dprintk("nfs_get_root: getattr error = %d\n", -error);
-               return ERR_PTR(error);
+               ret = ERR_PTR(error);
+               goto out;
        }
 
        inode = nfs_fhget(sb, mntfh, fsinfo.fattr);
        if (IS_ERR(inode)) {
                dprintk("nfs_get_root: get root inode failed\n");
-               return ERR_CAST(inode);
+               ret = ERR_CAST(inode);
+               goto out;
        }
 
        error = nfs_superblock_set_dummy_root(sb, inode);
-       if (error != 0)
-               return ERR_PTR(error);
+       if (error != 0) {
+               ret = ERR_PTR(error);
+               goto out;
+       }
 
        /* root dentries normally start off anonymous and get spliced in later
         * if the dentry tree reaches them; however if the dentry already
         * exists, we'll pick it up at this point and use it as the root
         */
-       mntroot = d_obtain_alias(inode);
-       if (IS_ERR(mntroot)) {
+       ret = d_obtain_alias(inode);
+       if (IS_ERR(ret)) {
                dprintk("nfs_get_root: get root dentry failed\n");
-               return mntroot;
+               goto out;
        }
 
-       security_d_instantiate(mntroot, inode);
-
-       if (!mntroot->d_op)
-               mntroot->d_op = server->nfs_client->rpc_ops->dentry_ops;
+       security_d_instantiate(ret, inode);
 
-       return mntroot;
+       if (ret->d_op == NULL)
+               ret->d_op = server->nfs_client->rpc_ops->dentry_ops;
+out:
+       nfs_free_fattr(fsinfo.fattr);
+       return ret;
 }
 
 #ifdef CONFIG_NFS_V4
 
-/*
- * Do a simple pathwalk from the root FH of the server to the nominated target
- * of the mountpoint
- * - give error on symlinks
- * - give error on ".." occurring in the path
- * - follow traversals
- */
-int nfs4_path_walk(struct nfs_server *server,
-                  struct nfs_fh *mntfh,
-                  const char *path)
+int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh)
 {
        struct nfs_fsinfo fsinfo;
-       struct nfs_fattr fattr;
-       struct nfs_fh lastfh;
-       struct qstr name;
-       int ret;
+       int ret = -ENOMEM;
 
-       dprintk("--> nfs4_path_walk(,,%s)\n", path);
+       dprintk("--> nfs4_get_rootfh()\n");
 
-       fsinfo.fattr = &fattr;
-       nfs_fattr_init(&fattr);
-
-       /* Eat leading slashes */
-       while (*path == '/')
-               path++;
+       fsinfo.fattr = nfs_alloc_fattr();
+       if (fsinfo.fattr == NULL)
+               goto out;
 
        /* Start by getting the root filehandle from the server */
        ret = server->nfs_client->rpc_ops->getroot(server, mntfh, &fsinfo);
        if (ret < 0) {
-               dprintk("nfs4_get_root: getroot error = %d\n", -ret);
-               return ret;
+               dprintk("nfs4_get_rootfh: getroot error = %d\n", -ret);
+               goto out;
        }
 
-       if (!S_ISDIR(fattr.mode)) {
-               printk(KERN_ERR "nfs4_get_root:"
+       if (!(fsinfo.fattr->valid & NFS_ATTR_FATTR_MODE)
+                       || !S_ISDIR(fsinfo.fattr->mode)) {
+               printk(KERN_ERR "nfs4_get_rootfh:"
                       " getroot encountered non-directory\n");
-               return -ENOTDIR;
+               ret = -ENOTDIR;
+               goto out;
        }
 
-       /* FIXME: It is quite valid for the server to return a referral here */
-       if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) {
-               printk(KERN_ERR "nfs4_get_root:"
+       if (fsinfo.fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) {
+               printk(KERN_ERR "nfs4_get_rootfh:"
                       " getroot obtained referral\n");
-               return -EREMOTE;
-       }
-
-next_component:
-       dprintk("Next: %s\n", path);
-
-       /* extract the next bit of the path */
-       if (!*path)
-               goto path_walk_complete;
-
-       name.name = path;
-       while (*path && *path != '/')
-               path++;
-       name.len = path - (const char *) name.name;
-
-       if (name.len > NFS4_MAXNAMLEN)
-               return -ENAMETOOLONG;
-
-eat_dot_dir:
-       while (*path == '/')
-               path++;
-
-       if (path[0] == '.' && (path[1] == '/' || !path[1])) {
-               path += 2;
-               goto eat_dot_dir;
-       }
-
-       /* FIXME: Why shouldn't the user be able to use ".." in the path? */
-       if (path[0] == '.' && path[1] == '.' && (path[2] == '/' || !path[2])
-           ) {
-               printk(KERN_ERR "nfs4_get_root:"
-                      " Mount path contains reference to \"..\"\n");
-               return -EINVAL;
+               ret = -EREMOTE;
+               goto out;
        }
 
-       /* lookup the next FH in the sequence */
-       memcpy(&lastfh, mntfh, sizeof(lastfh));
-
-       dprintk("LookupFH: %*.*s [%s]\n", name.len, name.len, name.name, path);
-
-       ret = server->nfs_client->rpc_ops->lookupfh(server, &lastfh, &name,
-                                                   mntfh, &fattr);
-       if (ret < 0) {
-               dprintk("nfs4_get_root: getroot error = %d\n", -ret);
-               return ret;
-       }
-
-       if (!S_ISDIR(fattr.mode)) {
-               printk(KERN_ERR "nfs4_get_root:"
-                      " lookupfh encountered non-directory\n");
-               return -ENOTDIR;
-       }
-
-       /* FIXME: Referrals are quite valid here too */
-       if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL) {
-               printk(KERN_ERR "nfs4_get_root:"
-                      " lookupfh obtained referral\n");
-               return -EREMOTE;
-       }
-
-       goto next_component;
-
-path_walk_complete:
-       memcpy(&server->fsid, &fattr.fsid, sizeof(server->fsid));
-       dprintk("<-- nfs4_path_walk() = 0\n");
-       return 0;
+       memcpy(&server->fsid, &fsinfo.fattr->fsid, sizeof(server->fsid));
+out:
+       nfs_free_fattr(fsinfo.fattr);
+       dprintk("<-- nfs4_get_rootfh() = %d\n", ret);
+       return ret;
 }
 
 /*
@@ -239,8 +174,8 @@ path_walk_complete:
 struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
 {
        struct nfs_server *server = NFS_SB(sb);
-       struct nfs_fattr fattr;
-       struct dentry *mntroot;
+       struct nfs_fattr *fattr = NULL;
+       struct dentry *ret;
        struct inode *inode;
        int error;
 
@@ -254,40 +189,50 @@ struct dentry *nfs4_get_root(struct super_block *sb, struct nfs_fh *mntfh)
                return ERR_PTR(error);
        }
 
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               return ERR_PTR(-ENOMEM);;
+
        /* get the actual root for this mount */
-       error = server->nfs_client->rpc_ops->getattr(server, mntfh, &fattr);
+       error = server->nfs_client->rpc_ops->getattr(server, mntfh, fattr);
        if (error < 0) {
                dprintk("nfs_get_root: getattr error = %d\n", -error);
-               return ERR_PTR(error);
+               ret = ERR_PTR(error);
+               goto out;
        }
 
-       inode = nfs_fhget(sb, mntfh, &fattr);
+       inode = nfs_fhget(sb, mntfh, fattr);
        if (IS_ERR(inode)) {
                dprintk("nfs_get_root: get root inode failed\n");
-               return ERR_CAST(inode);
+               ret = ERR_CAST(inode);
+               goto out;
        }
 
        error = nfs_superblock_set_dummy_root(sb, inode);
-       if (error != 0)
-               return ERR_PTR(error);
+       if (error != 0) {
+               ret = ERR_PTR(error);
+               goto out;
+       }
 
        /* root dentries normally start off anonymous and get spliced in later
         * if the dentry tree reaches them; however if the dentry already
         * exists, we'll pick it up at this point and use it as the root
         */
-       mntroot = d_obtain_alias(inode);
-       if (IS_ERR(mntroot)) {
+       ret = d_obtain_alias(inode);
+       if (IS_ERR(ret)) {
                dprintk("nfs_get_root: get root dentry failed\n");
-               return mntroot;
+               goto out;
        }
 
-       security_d_instantiate(mntroot, inode);
+       security_d_instantiate(ret, inode);
 
-       if (!mntroot->d_op)
-               mntroot->d_op = server->nfs_client->rpc_ops->dentry_ops;
+       if (ret->d_op == NULL)
+               ret->d_op = server->nfs_client->rpc_ops->dentry_ops;
 
+out:
+       nfs_free_fattr(fattr);
        dprintk("<-- nfs4_get_root()\n");
-       return mntroot;
+       return ret;
 }
 
 #endif /* CONFIG_NFS_V4 */
index 50a56ed..099b351 100644 (file)
@@ -393,8 +393,8 @@ int
 nfs_setattr(struct dentry *dentry, struct iattr *attr)
 {
        struct inode *inode = dentry->d_inode;
-       struct nfs_fattr fattr;
-       int error;
+       struct nfs_fattr *fattr;
+       int error = -ENOMEM;
 
        nfs_inc_stats(inode, NFSIOS_VFSSETATTR);
 
@@ -417,14 +417,20 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)
                filemap_write_and_wait(inode->i_mapping);
                nfs_wb_all(inode);
        }
+
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto out;
        /*
         * Return any delegations if we're going to change ACLs
         */
        if ((attr->ia_valid & (ATTR_MODE|ATTR_UID|ATTR_GID)) != 0)
                nfs_inode_return_delegation(inode);
-       error = NFS_PROTO(inode)->setattr(dentry, &fattr, attr);
+       error = NFS_PROTO(inode)->setattr(dentry, fattr, attr);
        if (error == 0)
-               nfs_refresh_inode(inode, &fattr);
+               nfs_refresh_inode(inode, fattr);
+       nfs_free_fattr(fattr);
+out:
        return error;
 }
 
@@ -682,7 +688,7 @@ int
 __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
 {
        int              status = -ESTALE;
-       struct nfs_fattr fattr;
+       struct nfs_fattr *fattr = NULL;
        struct nfs_inode *nfsi = NFS_I(inode);
 
        dfprintk(PAGECACHE, "NFS: revalidating (%s/%Ld)\n",
@@ -693,8 +699,13 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
        if (NFS_STALE(inode))
                goto out;
 
+       status = -ENOMEM;
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto out;
+
        nfs_inc_stats(inode, NFSIOS_INODEREVALIDATE);
-       status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), &fattr);
+       status = NFS_PROTO(inode)->getattr(server, NFS_FH(inode), fattr);
        if (status != 0) {
                dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) getattr failed, error=%d\n",
                         inode->i_sb->s_id,
@@ -707,7 +718,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                goto out;
        }
 
-       status = nfs_refresh_inode(inode, &fattr);
+       status = nfs_refresh_inode(inode, fattr);
        if (status) {
                dfprintk(PAGECACHE, "nfs_revalidate_inode: (%s/%Ld) refresh failed, error=%d\n",
                         inode->i_sb->s_id,
@@ -723,6 +734,7 @@ __nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
                (long long)NFS_FILEID(inode));
 
  out:
+       nfs_free_fattr(fattr);
        return status;
 }
 
@@ -730,9 +742,14 @@ int nfs_attribute_timeout(struct inode *inode)
 {
        struct nfs_inode *nfsi = NFS_I(inode);
 
+       return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
+}
+
+static int nfs_attribute_cache_expired(struct inode *inode)
+{
        if (nfs_have_delegated_attributes(inode))
                return 0;
-       return !time_in_range_open(jiffies, nfsi->read_cache_jiffies, nfsi->read_cache_jiffies + nfsi->attrtimeo);
+       return nfs_attribute_timeout(inode);
 }
 
 /**
@@ -745,7 +762,7 @@ int nfs_attribute_timeout(struct inode *inode)
 int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
 {
        if (!(NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATTR)
-                       && !nfs_attribute_timeout(inode))
+                       && !nfs_attribute_cache_expired(inode))
                return NFS_STALE(inode) ? -ESTALE : 0;
        return __nfs_revalidate_inode(server, inode);
 }
@@ -782,7 +799,8 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping)
        int ret = 0;
 
        if ((nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE)
-                       || nfs_attribute_timeout(inode) || NFS_STALE(inode)) {
+                       || nfs_attribute_cache_expired(inode)
+                       || NFS_STALE(inode)) {
                ret = __nfs_revalidate_inode(NFS_SERVER(inode), inode);
                if (ret < 0)
                        goto out;
@@ -916,6 +934,26 @@ void nfs_fattr_init(struct nfs_fattr *fattr)
        fattr->gencount = nfs_inc_attr_generation_counter();
 }
 
+struct nfs_fattr *nfs_alloc_fattr(void)
+{
+       struct nfs_fattr *fattr;
+
+       fattr = kmalloc(sizeof(*fattr), GFP_NOFS);
+       if (fattr != NULL)
+               nfs_fattr_init(fattr);
+       return fattr;
+}
+
+struct nfs_fh *nfs_alloc_fhandle(void)
+{
+       struct nfs_fh *fh;
+
+       fh = kmalloc(sizeof(struct nfs_fh), GFP_NOFS);
+       if (fh != NULL)
+               fh->size = 0;
+       return fh;
+}
+
 /**
  * nfs_inode_attrs_need_update - check if the inode attributes need updating
  * @inode - pointer to inode
index 11f82f0..d8bd619 100644 (file)
@@ -244,9 +244,7 @@ extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
 #ifdef CONFIG_NFS_V4
 extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
 
-extern int nfs4_path_walk(struct nfs_server *server,
-                         struct nfs_fh *mntfh,
-                         const char *path);
+extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
 #endif
 
 /* read.c */
index 1d8d5c8..c583248 100644 (file)
@@ -36,14 +36,14 @@ static inline void nfs_inc_stats(const struct inode *inode,
 
 static inline void nfs_add_server_stats(const struct nfs_server *server,
                                        enum nfs_stat_bytecounters stat,
-                                       unsigned long addend)
+                                       long addend)
 {
        this_cpu_add(server->io_stats->bytes[stat], addend);
 }
 
 static inline void nfs_add_stats(const struct inode *inode,
                                 enum nfs_stat_bytecounters stat,
-                                unsigned long addend)
+                                long addend)
 {
        nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
 }
@@ -51,7 +51,7 @@ static inline void nfs_add_stats(const struct inode *inode,
 #ifdef CONFIG_NFS_FSCACHE
 static inline void nfs_add_fscache_stats(struct inode *inode,
                                         enum nfs_stat_fscachecounters stat,
-                                        unsigned long addend)
+                                        long addend)
 {
        this_cpu_add(NFS_SERVER(inode)->io_stats->fscache[stat], addend);
 }
index 7888cf3..db6aa36 100644 (file)
@@ -105,8 +105,8 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        struct vfsmount *mnt;
        struct nfs_server *server = NFS_SERVER(dentry->d_inode);
        struct dentry *parent;
-       struct nfs_fh fh;
-       struct nfs_fattr fattr;
+       struct nfs_fh *fh = NULL;
+       struct nfs_fattr *fattr = NULL;
        int err;
 
        dprintk("--> nfs_follow_mountpoint()\n");
@@ -115,6 +115,12 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        if (IS_ROOT(dentry))
                goto out_err;
 
+       err = -ENOMEM;
+       fh = nfs_alloc_fhandle();
+       fattr = nfs_alloc_fattr();
+       if (fh == NULL || fattr == NULL)
+               goto out_err;
+
        dprintk("%s: enter\n", __func__);
        dput(nd->path.dentry);
        nd->path.dentry = dget(dentry);
@@ -123,16 +129,16 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        parent = dget_parent(nd->path.dentry);
        err = server->nfs_client->rpc_ops->lookup(parent->d_inode,
                                                  &nd->path.dentry->d_name,
-                                                 &fh, &fattr);
+                                                 fh, fattr);
        dput(parent);
        if (err != 0)
                goto out_err;
 
-       if (fattr.valid & NFS_ATTR_FATTR_V4_REFERRAL)
+       if (fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL)
                mnt = nfs_do_refmount(nd->path.mnt, nd->path.dentry);
        else
-               mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, &fh,
-                                     &fattr);
+               mnt = nfs_do_submount(nd->path.mnt, nd->path.dentry, fh,
+                                     fattr);
        err = PTR_ERR(mnt);
        if (IS_ERR(mnt))
                goto out_err;
@@ -151,6 +157,8 @@ static void * nfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
        nd->path.dentry = dget(mnt->mnt_root);
        schedule_delayed_work(&nfs_automount_task, nfs_mountpoint_expiry_timeout);
 out:
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fh);
        dprintk("%s: done, returned %d\n", __func__, err);
 
        dprintk("<-- nfs_follow_mountpoint() = %d\n", err);
index d150ae0..9f88c5f 100644 (file)
@@ -185,7 +185,6 @@ static void nfs3_cache_acls(struct inode *inode, struct posix_acl *acl,
 struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
 {
        struct nfs_server *server = NFS_SERVER(inode);
-       struct nfs_fattr fattr;
        struct page *pages[NFSACL_MAXPAGES] = { };
        struct nfs3_getaclargs args = {
                .fh = NFS_FH(inode),
@@ -193,7 +192,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
                .pages = pages,
        };
        struct nfs3_getaclres res = {
-               .fattr =        &fattr,
+               0
        };
        struct rpc_message msg = {
                .rpc_argp       = &args,
@@ -228,7 +227,10 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
 
        dprintk("NFS call getacl\n");
        msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_GETACL];
-       nfs_fattr_init(&fattr);
+       res.fattr = nfs_alloc_fattr();
+       if (res.fattr == NULL)
+               return ERR_PTR(-ENOMEM);
+
        status = rpc_call_sync(server->client_acl, &msg, 0);
        dprintk("NFS reply getacl: %d\n", status);
 
@@ -238,7 +240,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
 
        switch (status) {
                case 0:
-                       status = nfs_refresh_inode(inode, &fattr);
+                       status = nfs_refresh_inode(inode, res.fattr);
                        break;
                case -EPFNOSUPPORT:
                case -EPROTONOSUPPORT:
@@ -278,6 +280,7 @@ struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type)
 getout:
        posix_acl_release(res.acl_access);
        posix_acl_release(res.acl_default);
+       nfs_free_fattr(res.fattr);
 
        if (status != 0) {
                posix_acl_release(acl);
@@ -290,7 +293,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
                  struct posix_acl *dfacl)
 {
        struct nfs_server *server = NFS_SERVER(inode);
-       struct nfs_fattr fattr;
+       struct nfs_fattr *fattr;
        struct page *pages[NFSACL_MAXPAGES];
        struct nfs3_setaclargs args = {
                .inode = inode,
@@ -335,8 +338,13 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
        }
 
        dprintk("NFS call setacl\n");
+       status = -ENOMEM;
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto out_freepages;
+
        msg.rpc_proc = &server->client_acl->cl_procinfo[ACLPROC3_SETACL];
-       nfs_fattr_init(&fattr);
+       msg.rpc_resp = fattr;
        status = rpc_call_sync(server->client_acl, &msg, 0);
        nfs_access_zap_cache(inode);
        nfs_zap_acl_cache(inode);
@@ -344,7 +352,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
 
        switch (status) {
                case 0:
-                       status = nfs_refresh_inode(inode, &fattr);
+                       status = nfs_refresh_inode(inode, fattr);
                        nfs3_cache_acls(inode, acl, dfacl);
                        break;
                case -EPFNOSUPPORT:
@@ -355,6 +363,7 @@ static int nfs3_proc_setacls(struct inode *inode, struct posix_acl *acl,
                case -ENOTSUPP:
                        status = -EOPNOTSUPP;
        }
+       nfs_free_fattr(fattr);
 out_freepages:
        while (args.npages != 0) {
                args.npages--;
index e701002..fabb4f2 100644 (file)
@@ -144,14 +144,12 @@ static int
 nfs3_proc_lookup(struct inode *dir, struct qstr *name,
                 struct nfs_fh *fhandle, struct nfs_fattr *fattr)
 {
-       struct nfs_fattr        dir_attr;
        struct nfs3_diropargs   arg = {
                .fh             = NFS_FH(dir),
                .name           = name->name,
                .len            = name->len
        };
        struct nfs3_diropres    res = {
-               .dir_attr       = &dir_attr,
                .fh             = fhandle,
                .fattr          = fattr
        };
@@ -163,29 +161,30 @@ nfs3_proc_lookup(struct inode *dir, struct qstr *name,
        int                     status;
 
        dprintk("NFS call  lookup %s\n", name->name);
-       nfs_fattr_init(&dir_attr);
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.dir_attr == NULL)
+               return -ENOMEM;
+
        nfs_fattr_init(fattr);
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_refresh_inode(dir, res.dir_attr);
        if (status >= 0 && !(fattr->valid & NFS_ATTR_FATTR)) {
                msg.rpc_proc = &nfs3_procedures[NFS3PROC_GETATTR];
                msg.rpc_argp = fhandle;
                msg.rpc_resp = fattr;
                status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        }
+       nfs_free_fattr(res.dir_attr);
        dprintk("NFS reply lookup: %d\n", status);
        return status;
 }
 
 static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
 {
-       struct nfs_fattr        fattr;
        struct nfs3_accessargs  arg = {
                .fh             = NFS_FH(inode),
        };
-       struct nfs3_accessres   res = {
-               .fattr          = &fattr,
-       };
+       struct nfs3_accessres   res;
        struct rpc_message msg = {
                .rpc_proc       = &nfs3_procedures[NFS3PROC_ACCESS],
                .rpc_argp       = &arg,
@@ -193,7 +192,7 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
                .rpc_cred       = entry->cred,
        };
        int mode = entry->mask;
-       int status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  access\n");
 
@@ -210,9 +209,13 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
                if (mode & MAY_EXEC)
                        arg.access |= NFS3_ACCESS_EXECUTE;
        }
-       nfs_fattr_init(&fattr);
+
+       res.fattr = nfs_alloc_fattr();
+       if (res.fattr == NULL)
+               goto out;
+
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
-       nfs_refresh_inode(inode, &fattr);
+       nfs_refresh_inode(inode, res.fattr);
        if (status == 0) {
                entry->mask = 0;
                if (res.access & NFS3_ACCESS_READ)
@@ -222,6 +225,8 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
                if (res.access & (NFS3_ACCESS_LOOKUP|NFS3_ACCESS_EXECUTE))
                        entry->mask |= MAY_EXEC;
        }
+       nfs_free_fattr(res.fattr);
+out:
        dprintk("NFS reply access: %d\n", status);
        return status;
 }
@@ -229,7 +234,7 @@ static int nfs3_proc_access(struct inode *inode, struct nfs_access_entry *entry)
 static int nfs3_proc_readlink(struct inode *inode, struct page *page,
                unsigned int pgbase, unsigned int pglen)
 {
-       struct nfs_fattr        fattr;
+       struct nfs_fattr        *fattr;
        struct nfs3_readlinkargs args = {
                .fh             = NFS_FH(inode),
                .pgbase         = pgbase,
@@ -239,14 +244,19 @@ static int nfs3_proc_readlink(struct inode *inode, struct page *page,
        struct rpc_message msg = {
                .rpc_proc       = &nfs3_procedures[NFS3PROC_READLINK],
                .rpc_argp       = &args,
-               .rpc_resp       = &fattr,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  readlink\n");
-       nfs_fattr_init(&fattr);
+       fattr = nfs_alloc_fattr();
+       if (fattr == NULL)
+               goto out;
+       msg.rpc_resp = fattr;
+
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
-       nfs_refresh_inode(inode, &fattr);
+       nfs_refresh_inode(inode, fattr);
+       nfs_free_fattr(fattr);
+out:
        dprintk("NFS reply readlink: %d\n", status);
        return status;
 }
@@ -396,12 +406,17 @@ nfs3_proc_remove(struct inode *dir, struct qstr *name)
                .rpc_argp = &arg,
                .rpc_resp = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  remove %s\n", name->name);
-       nfs_fattr_init(&res.dir_attr);
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.dir_attr == NULL)
+               goto out;
+
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
-       nfs_post_op_update_inode(dir, &res.dir_attr);
+       nfs_post_op_update_inode(dir, res.dir_attr);
+       nfs_free_fattr(res.dir_attr);
+out:
        dprintk("NFS reply remove: %d\n", status);
        return status;
 }
@@ -419,7 +434,7 @@ nfs3_proc_unlink_done(struct rpc_task *task, struct inode *dir)
        if (nfs3_async_handle_jukebox(task, dir))
                return 0;
        res = task->tk_msg.rpc_resp;
-       nfs_post_op_update_inode(dir, &res->dir_attr);
+       nfs_post_op_update_inode(dir, res->dir_attr);
        return 1;
 }
 
@@ -427,7 +442,6 @@ static int
 nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
                 struct inode *new_dir, struct qstr *new_name)
 {
-       struct nfs_fattr        old_dir_attr, new_dir_attr;
        struct nfs3_renameargs  arg = {
                .fromfh         = NFS_FH(old_dir),
                .fromname       = old_name->name,
@@ -436,23 +450,27 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
                .toname         = new_name->name,
                .tolen          = new_name->len
        };
-       struct nfs3_renameres   res = {
-               .fromattr       = &old_dir_attr,
-               .toattr         = &new_dir_attr
-       };
+       struct nfs3_renameres res;
        struct rpc_message msg = {
                .rpc_proc       = &nfs3_procedures[NFS3PROC_RENAME],
                .rpc_argp       = &arg,
                .rpc_resp       = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  rename %s -> %s\n", old_name->name, new_name->name);
-       nfs_fattr_init(&old_dir_attr);
-       nfs_fattr_init(&new_dir_attr);
+
+       res.fromattr = nfs_alloc_fattr();
+       res.toattr = nfs_alloc_fattr();
+       if (res.fromattr == NULL || res.toattr == NULL)
+               goto out;
+
        status = rpc_call_sync(NFS_CLIENT(old_dir), &msg, 0);
-       nfs_post_op_update_inode(old_dir, &old_dir_attr);
-       nfs_post_op_update_inode(new_dir, &new_dir_attr);
+       nfs_post_op_update_inode(old_dir, res.fromattr);
+       nfs_post_op_update_inode(new_dir, res.toattr);
+out:
+       nfs_free_fattr(res.toattr);
+       nfs_free_fattr(res.fromattr);
        dprintk("NFS reply rename: %d\n", status);
        return status;
 }
@@ -460,30 +478,32 @@ nfs3_proc_rename(struct inode *old_dir, struct qstr *old_name,
 static int
 nfs3_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
 {
-       struct nfs_fattr        dir_attr, fattr;
        struct nfs3_linkargs    arg = {
                .fromfh         = NFS_FH(inode),
                .tofh           = NFS_FH(dir),
                .toname         = name->name,
                .tolen          = name->len
        };
-       struct nfs3_linkres     res = {
-               .dir_attr       = &dir_attr,
-               .fattr          = &fattr
-       };
+       struct nfs3_linkres     res;
        struct rpc_message msg = {
                .rpc_proc       = &nfs3_procedures[NFS3PROC_LINK],
                .rpc_argp       = &arg,
                .rpc_resp       = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  link %s\n", name->name);
-       nfs_fattr_init(&dir_attr);
-       nfs_fattr_init(&fattr);
+       res.fattr = nfs_alloc_fattr();
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.fattr == NULL || res.dir_attr == NULL)
+               goto out;
+
        status = rpc_call_sync(NFS_CLIENT(inode), &msg, 0);
-       nfs_post_op_update_inode(dir, &dir_attr);
-       nfs_post_op_update_inode(inode, &fattr);
+       nfs_post_op_update_inode(dir, res.dir_attr);
+       nfs_post_op_update_inode(inode, res.fattr);
+out:
+       nfs_free_fattr(res.dir_attr);
+       nfs_free_fattr(res.fattr);
        dprintk("NFS reply link: %d\n", status);
        return status;
 }
@@ -554,7 +574,7 @@ out:
 static int
 nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
 {
-       struct nfs_fattr        dir_attr;
+       struct nfs_fattr        *dir_attr;
        struct nfs3_diropargs   arg = {
                .fh             = NFS_FH(dir),
                .name           = name->name,
@@ -563,14 +583,19 @@ nfs3_proc_rmdir(struct inode *dir, struct qstr *name)
        struct rpc_message msg = {
                .rpc_proc       = &nfs3_procedures[NFS3PROC_RMDIR],
                .rpc_argp       = &arg,
-               .rpc_resp       = &dir_attr,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  rmdir %s\n", name->name);
-       nfs_fattr_init(&dir_attr);
+       dir_attr = nfs_alloc_fattr();
+       if (dir_attr == NULL)
+               goto out;
+
+       msg.rpc_resp = dir_attr;
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
-       nfs_post_op_update_inode(dir, &dir_attr);
+       nfs_post_op_update_inode(dir, dir_attr);
+       nfs_free_fattr(dir_attr);
+out:
        dprintk("NFS reply rmdir: %d\n", status);
        return status;
 }
@@ -589,7 +614,6 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
                  u64 cookie, struct page *page, unsigned int count, int plus)
 {
        struct inode            *dir = dentry->d_inode;
-       struct nfs_fattr        dir_attr;
        __be32                  *verf = NFS_COOKIEVERF(dir);
        struct nfs3_readdirargs arg = {
                .fh             = NFS_FH(dir),
@@ -600,7 +624,6 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
                .pages          = &page
        };
        struct nfs3_readdirres  res = {
-               .dir_attr       = &dir_attr,
                .verf           = verf,
                .plus           = plus
        };
@@ -610,7 +633,7 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
                .rpc_resp       = &res,
                .rpc_cred       = cred
        };
-       int                     status;
+       int status = -ENOMEM;
 
        if (plus)
                msg.rpc_proc = &nfs3_procedures[NFS3PROC_READDIRPLUS];
@@ -618,12 +641,17 @@ nfs3_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
        dprintk("NFS call  readdir%s %d\n",
                        plus? "plus" : "", (unsigned int) cookie);
 
-       nfs_fattr_init(&dir_attr);
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.dir_attr == NULL)
+               goto out;
+
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
 
        nfs_invalidate_atime(dir);
+       nfs_refresh_inode(dir, res.dir_attr);
 
-       nfs_refresh_inode(dir, &dir_attr);
+       nfs_free_fattr(res.dir_attr);
+out:
        dprintk("NFS reply readdir: %d\n", status);
        return status;
 }
index 56a86f6..75dcfc7 100644 (file)
@@ -762,7 +762,7 @@ nfs3_xdr_wccstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
 static int
 nfs3_xdr_removeres(struct rpc_rqst *req, __be32 *p, struct nfs_removeres *res)
 {
-       return nfs3_xdr_wccstat(req, p, &res->dir_attr);
+       return nfs3_xdr_wccstat(req, p, res->dir_attr);
 }
 
 /*
index a187200..c538c61 100644 (file)
@@ -206,14 +206,14 @@ extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
 
 
 /* nfs4proc.c */
-extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *);
-extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *);
+extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *, struct nfs4_setclientid_res *);
+extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct nfs4_setclientid_res *arg, struct rpc_cred *);
 extern int nfs4_proc_exchange_id(struct nfs_client *clp, struct rpc_cred *cred);
 extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *);
 extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *);
 extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
 extern int nfs41_init_clientid(struct nfs_client *, struct rpc_cred *);
-extern int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait);
+extern int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait);
 extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
 extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
 extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
@@ -286,7 +286,7 @@ extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
 extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
 extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
 
-extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
+extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask);
 extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
 extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
 extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
index f071d12..3c2a172 100644 (file)
@@ -115,6 +115,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
                                     char *page, char *page2,
                                     const struct nfs4_fs_location *location)
 {
+       const size_t addr_bufsize = sizeof(struct sockaddr_storage);
        struct vfsmount *mnt = ERR_PTR(-ENOENT);
        char *mnt_path;
        unsigned int maxbuflen;
@@ -126,9 +127,12 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
        mountdata->mnt_path = mnt_path;
        maxbuflen = mnt_path - 1 - page2;
 
+       mountdata->addr = kmalloc(addr_bufsize, GFP_KERNEL);
+       if (mountdata->addr == NULL)
+               return ERR_PTR(-ENOMEM);
+
        for (s = 0; s < location->nservers; s++) {
                const struct nfs4_string *buf = &location->servers[s];
-               struct sockaddr_storage addr;
 
                if (buf->len <= 0 || buf->len >= maxbuflen)
                        continue;
@@ -137,11 +141,10 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
                        continue;
 
                mountdata->addrlen = nfs_parse_server_name(buf->data, buf->len,
-                               (struct sockaddr *)&addr, sizeof(addr));
+                               mountdata->addr, addr_bufsize);
                if (mountdata->addrlen == 0)
                        continue;
 
-               mountdata->addr = (struct sockaddr *)&addr;
                rpc_set_port(mountdata->addr, NFS_PORT);
 
                memcpy(page2, buf->data, buf->len);
@@ -156,6 +159,7 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata,
                if (!IS_ERR(mnt))
                        break;
        }
+       kfree(mountdata->addr);
        return mnt;
 }
 
@@ -221,8 +225,8 @@ out:
 
 /*
  * nfs_do_refmount - handle crossing a referral on server
+ * @mnt_parent - mountpoint of referral
  * @dentry - dentry of referral
- * @nd - nameidata info
  *
  */
 struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
index 071fced..70015dd 100644 (file)
@@ -70,6 +70,9 @@ static int nfs4_do_fsinfo(struct nfs_server *, struct nfs_fh *, struct nfs_fsinf
 static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *, struct nfs4_state *);
 static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
 static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
+static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
+                           struct nfs_fattr *fattr, struct iattr *sattr,
+                           struct nfs4_state *state);
 
 /* Prevent leaks of NFSv4 errors into userland */
 static int nfs4_map_errors(int err)
@@ -714,17 +717,18 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p)
 
 static struct nfs4_opendata *nfs4_opendata_alloc(struct path *path,
                struct nfs4_state_owner *sp, fmode_t fmode, int flags,
-               const struct iattr *attrs)
+               const struct iattr *attrs,
+               gfp_t gfp_mask)
 {
        struct dentry *parent = dget_parent(path->dentry);
        struct inode *dir = parent->d_inode;
        struct nfs_server *server = NFS_SERVER(dir);
        struct nfs4_opendata *p;
 
-       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       p = kzalloc(sizeof(*p), gfp_mask);
        if (p == NULL)
                goto err;
-       p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
+       p->o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid, gfp_mask);
        if (p->o_arg.seqid == NULL)
                goto err_free;
        path_get(path);
@@ -1060,7 +1064,7 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
 {
        struct nfs4_opendata *opendata;
 
-       opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL);
+       opendata = nfs4_opendata_alloc(&ctx->path, state->owner, 0, 0, NULL, GFP_NOFS);
        if (opendata == NULL)
                return ERR_PTR(-ENOMEM);
        opendata->state = state;
@@ -1648,7 +1652,7 @@ static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, in
        if (path->dentry->d_inode != NULL)
                nfs4_return_incompatible_delegation(path->dentry->d_inode, fmode);
        status = -ENOMEM;
-       opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr);
+       opendata = nfs4_opendata_alloc(path, sp, fmode, flags, sattr, GFP_KERNEL);
        if (opendata == NULL)
                goto err_put_state_owner;
 
@@ -1659,15 +1663,24 @@ static int _nfs4_do_open(struct inode *dir, struct path *path, fmode_t fmode, in
        if (status != 0)
                goto err_opendata_put;
 
-       if (opendata->o_arg.open_flags & O_EXCL)
-               nfs4_exclusive_attrset(opendata, sattr);
-
        state = nfs4_opendata_to_nfs4_state(opendata);
        status = PTR_ERR(state);
        if (IS_ERR(state))
                goto err_opendata_put;
        if (server->caps & NFS_CAP_POSIX_LOCK)
                set_bit(NFS_STATE_POSIX_LOCKS, &state->flags);
+
+       if (opendata->o_arg.open_flags & O_EXCL) {
+               nfs4_exclusive_attrset(opendata, sattr);
+
+               nfs_fattr_init(opendata->o_res.f_attr);
+               status = nfs4_do_setattr(state->inode, cred,
+                               opendata->o_res.f_attr, sattr,
+                               state);
+               if (status == 0)
+                       nfs_setattr_update_inode(state->inode, sattr);
+               nfs_post_op_update_inode(state->inode, opendata->o_res.f_attr);
+       }
        nfs4_opendata_put(opendata);
        nfs4_put_state_owner(sp);
        *res = state;
@@ -1914,7 +1927,7 @@ static const struct rpc_call_ops nfs4_close_ops = {
  *
  * NOTE: Caller must be holding the sp->so_owner semaphore!
  */
-int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
+int nfs4_do_close(struct path *path, struct nfs4_state *state, gfp_t gfp_mask, int wait)
 {
        struct nfs_server *server = NFS_SERVER(state->inode);
        struct nfs4_closedata *calldata;
@@ -1933,7 +1946,7 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
        };
        int status = -ENOMEM;
 
-       calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
+       calldata = kzalloc(sizeof(*calldata), gfp_mask);
        if (calldata == NULL)
                goto out;
        calldata->inode = state->inode;
@@ -1941,7 +1954,7 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
        calldata->arg.fh = NFS_FH(state->inode);
        calldata->arg.stateid = &state->open_stateid;
        /* Serialization for the sequence id */
-       calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid);
+       calldata->arg.seqid = nfs_alloc_seqid(&state->owner->so_seqid, gfp_mask);
        if (calldata->arg.seqid == NULL)
                goto out_free_calldata;
        calldata->arg.fmode = 0;
@@ -2404,14 +2417,12 @@ static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh
 static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
 {
        struct nfs_server *server = NFS_SERVER(inode);
-       struct nfs_fattr fattr;
        struct nfs4_accessargs args = {
                .fh = NFS_FH(inode),
                .bitmask = server->attr_bitmask,
        };
        struct nfs4_accessres res = {
                .server = server,
-               .fattr = &fattr,
        };
        struct rpc_message msg = {
                .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ACCESS],
@@ -2438,7 +2449,11 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
                if (mode & MAY_EXEC)
                        args.access |= NFS4_ACCESS_EXECUTE;
        }
-       nfs_fattr_init(&fattr);
+
+       res.fattr = nfs_alloc_fattr();
+       if (res.fattr == NULL)
+               return -ENOMEM;
+
        status = nfs4_call_sync(server, &msg, &args, &res, 0);
        if (!status) {
                entry->mask = 0;
@@ -2448,8 +2463,9 @@ static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry
                        entry->mask |= MAY_WRITE;
                if (res.access & (NFS4_ACCESS_LOOKUP|NFS4_ACCESS_EXECUTE))
                        entry->mask |= MAY_EXEC;
-               nfs_refresh_inode(inode, &fattr);
+               nfs_refresh_inode(inode, res.fattr);
        }
+       nfs_free_fattr(res.fattr);
        return status;
 }
 
@@ -2562,13 +2578,6 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
        }
        d_add(dentry, igrab(state->inode));
        nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
-       if (flags & O_EXCL) {
-               struct nfs_fattr fattr;
-               status = nfs4_do_setattr(state->inode, cred, &fattr, sattr, state);
-               if (status == 0)
-                       nfs_setattr_update_inode(state->inode, sattr);
-               nfs_post_op_update_inode(state->inode, &fattr);
-       }
        if (status == 0 && (nd->flags & LOOKUP_OPEN) != 0)
                status = nfs4_intent_set_file(nd, &path, state, fmode);
        else
@@ -2596,14 +2605,19 @@ static int _nfs4_proc_remove(struct inode *dir, struct qstr *name)
                .rpc_argp = &args,
                .rpc_resp = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
+
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.dir_attr == NULL)
+               goto out;
 
-       nfs_fattr_init(&res.dir_attr);
        status = nfs4_call_sync(server, &msg, &args, &res, 1);
        if (status == 0) {
                update_changeattr(dir, &res.cinfo);
-               nfs_post_op_update_inode(dir, &res.dir_attr);
+               nfs_post_op_update_inode(dir, res.dir_attr);
        }
+       nfs_free_fattr(res.dir_attr);
+out:
        return status;
 }
 
@@ -2638,7 +2652,7 @@ static int nfs4_proc_unlink_done(struct rpc_task *task, struct inode *dir)
        if (nfs4_async_handle_error(task, res->server, NULL) == -EAGAIN)
                return 0;
        update_changeattr(dir, &res->cinfo);
-       nfs_post_op_update_inode(dir, &res->dir_attr);
+       nfs_post_op_update_inode(dir, res->dir_attr);
        return 1;
 }
 
@@ -2653,29 +2667,31 @@ static int _nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
                .new_name = new_name,
                .bitmask = server->attr_bitmask,
        };
-       struct nfs_fattr old_fattr, new_fattr;
        struct nfs4_rename_res res = {
                .server = server,
-               .old_fattr = &old_fattr,
-               .new_fattr = &new_fattr,
        };
        struct rpc_message msg = {
                .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_RENAME],
                .rpc_argp = &arg,
                .rpc_resp = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
        
-       nfs_fattr_init(res.old_fattr);
-       nfs_fattr_init(res.new_fattr);
-       status = nfs4_call_sync(server, &msg, &arg, &res, 1);
+       res.old_fattr = nfs_alloc_fattr();
+       res.new_fattr = nfs_alloc_fattr();
+       if (res.old_fattr == NULL || res.new_fattr == NULL)
+               goto out;
 
+       status = nfs4_call_sync(server, &msg, &arg, &res, 1);
        if (!status) {
                update_changeattr(old_dir, &res.old_cinfo);
                nfs_post_op_update_inode(old_dir, res.old_fattr);
                update_changeattr(new_dir, &res.new_cinfo);
                nfs_post_op_update_inode(new_dir, res.new_fattr);
        }
+out:
+       nfs_free_fattr(res.new_fattr);
+       nfs_free_fattr(res.old_fattr);
        return status;
 }
 
@@ -2702,28 +2718,30 @@ static int _nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *
                .name   = name,
                .bitmask = server->attr_bitmask,
        };
-       struct nfs_fattr fattr, dir_attr;
        struct nfs4_link_res res = {
                .server = server,
-               .fattr = &fattr,
-               .dir_attr = &dir_attr,
        };
        struct rpc_message msg = {
                .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LINK],
                .rpc_argp = &arg,
                .rpc_resp = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
+
+       res.fattr = nfs_alloc_fattr();
+       res.dir_attr = nfs_alloc_fattr();
+       if (res.fattr == NULL || res.dir_attr == NULL)
+               goto out;
 
-       nfs_fattr_init(res.fattr);
-       nfs_fattr_init(res.dir_attr);
        status = nfs4_call_sync(server, &msg, &arg, &res, 1);
        if (!status) {
                update_changeattr(dir, &res.cinfo);
                nfs_post_op_update_inode(dir, res.dir_attr);
                nfs_post_op_update_inode(inode, res.fattr);
        }
-
+out:
+       nfs_free_fattr(res.dir_attr);
+       nfs_free_fattr(res.fattr);
        return status;
 }
 
@@ -3146,23 +3164,31 @@ static void nfs4_proc_commit_setup(struct nfs_write_data *data, struct rpc_messa
        msg->rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COMMIT];
 }
 
+struct nfs4_renewdata {
+       struct nfs_client       *client;
+       unsigned long           timestamp;
+};
+
 /*
  * nfs4_proc_async_renew(): This is not one of the nfs_rpc_ops; it is a special
  * standalone procedure for queueing an asynchronous RENEW.
  */
-static void nfs4_renew_release(void *data)
+static void nfs4_renew_release(void *calldata)
 {
-       struct nfs_client *clp = data;
+       struct nfs4_renewdata *data = calldata;
+       struct nfs_client *clp = data->client;
 
        if (atomic_read(&clp->cl_count) > 1)
                nfs4_schedule_state_renewal(clp);
        nfs_put_client(clp);
+       kfree(data);
 }
 
-static void nfs4_renew_done(struct rpc_task *task, void *data)
+static void nfs4_renew_done(struct rpc_task *task, void *calldata)
 {
-       struct nfs_client *clp = data;
-       unsigned long timestamp = task->tk_start;
+       struct nfs4_renewdata *data = calldata;
+       struct nfs_client *clp = data->client;
+       unsigned long timestamp = data->timestamp;
 
        if (task->tk_status < 0) {
                /* Unless we're shutting down, schedule state recovery! */
@@ -3188,11 +3214,17 @@ int nfs4_proc_async_renew(struct nfs_client *clp, struct rpc_cred *cred)
                .rpc_argp       = clp,
                .rpc_cred       = cred,
        };
+       struct nfs4_renewdata *data;
 
        if (!atomic_inc_not_zero(&clp->cl_count))
                return -EIO;
+       data = kmalloc(sizeof(*data), GFP_KERNEL);
+       if (data == NULL)
+               return -ENOMEM;
+       data->client = clp;
+       data->timestamp = jiffies;
        return rpc_call_async(clp->cl_rpcclient, &msg, RPC_TASK_SOFT,
-                       &nfs4_renew_ops, clp);
+                       &nfs4_renew_ops, data);
 }
 
 int nfs4_proc_renew(struct nfs_client *clp, struct rpc_cred *cred)
@@ -3494,7 +3526,9 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
        return _nfs4_async_handle_error(task, server, server->nfs_client, state);
 }
 
-int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short port, struct rpc_cred *cred)
+int nfs4_proc_setclientid(struct nfs_client *clp, u32 program,
+               unsigned short port, struct rpc_cred *cred,
+               struct nfs4_setclientid_res *res)
 {
        nfs4_verifier sc_verifier;
        struct nfs4_setclientid setclientid = {
@@ -3504,7 +3538,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short po
        struct rpc_message msg = {
                .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID],
                .rpc_argp = &setclientid,
-               .rpc_resp = clp,
+               .rpc_resp = res,
                .rpc_cred = cred,
        };
        __be32 *p;
@@ -3547,12 +3581,14 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short po
        return status;
 }
 
-static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
+static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp,
+               struct nfs4_setclientid_res *arg,
+               struct rpc_cred *cred)
 {
        struct nfs_fsinfo fsinfo;
        struct rpc_message msg = {
                .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SETCLIENTID_CONFIRM],
-               .rpc_argp = clp,
+               .rpc_argp = arg,
                .rpc_resp = &fsinfo,
                .rpc_cred = cred,
        };
@@ -3570,12 +3606,14 @@ static int _nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cre
        return status;
 }
 
-int nfs4_proc_setclientid_confirm(struct nfs_client *clp, struct rpc_cred *cred)
+int nfs4_proc_setclientid_confirm(struct nfs_client *clp,
+               struct nfs4_setclientid_res *arg,
+               struct rpc_cred *cred)
 {
        long timeout = 0;
        int err;
        do {
-               err = _nfs4_proc_setclientid_confirm(clp, cred);
+               err = _nfs4_proc_setclientid_confirm(clp, arg, cred);
                switch (err) {
                        case 0:
                                return err;
@@ -3667,7 +3705,7 @@ static int _nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, co
        };
        int status = 0;
 
-       data = kzalloc(sizeof(*data), GFP_KERNEL);
+       data = kzalloc(sizeof(*data), GFP_NOFS);
        if (data == NULL)
                return -ENOMEM;
        data->args.fhandle = &data->fh;
@@ -3823,7 +3861,7 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
        struct nfs4_unlockdata *p;
        struct inode *inode = lsp->ls_state->inode;
 
-       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       p = kzalloc(sizeof(*p), GFP_NOFS);
        if (p == NULL)
                return NULL;
        p->arg.fh = NFS_FH(inode);
@@ -3961,7 +3999,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
        if (test_bit(NFS_DELEGATED_STATE, &state->flags))
                goto out;
        lsp = request->fl_u.nfs4_fl.owner;
-       seqid = nfs_alloc_seqid(&lsp->ls_seqid);
+       seqid = nfs_alloc_seqid(&lsp->ls_seqid, GFP_KERNEL);
        status = -ENOMEM;
        if (seqid == NULL)
                goto out;
@@ -3989,22 +4027,23 @@ struct nfs4_lockdata {
 };
 
 static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
-               struct nfs_open_context *ctx, struct nfs4_lock_state *lsp)
+               struct nfs_open_context *ctx, struct nfs4_lock_state *lsp,
+               gfp_t gfp_mask)
 {
        struct nfs4_lockdata *p;
        struct inode *inode = lsp->ls_state->inode;
        struct nfs_server *server = NFS_SERVER(inode);
 
-       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       p = kzalloc(sizeof(*p), gfp_mask);
        if (p == NULL)
                return NULL;
 
        p->arg.fh = NFS_FH(inode);
        p->arg.fl = &p->fl;
-       p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid);
+       p->arg.open_seqid = nfs_alloc_seqid(&lsp->ls_state->owner->so_seqid, gfp_mask);
        if (p->arg.open_seqid == NULL)
                goto out_free;
-       p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid);
+       p->arg.lock_seqid = nfs_alloc_seqid(&lsp->ls_seqid, gfp_mask);
        if (p->arg.lock_seqid == NULL)
                goto out_free_seqid;
        p->arg.lock_stateid = &lsp->ls_stateid;
@@ -4158,7 +4197,8 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
 
        dprintk("%s: begin!\n", __func__);
        data = nfs4_alloc_lockdata(fl, nfs_file_open_context(fl->fl_file),
-                       fl->fl_u.nfs4_fl.owner);
+                       fl->fl_u.nfs4_fl.owner,
+                       recovery_type == NFS_LOCK_NEW ? GFP_KERNEL : GFP_NOFS);
        if (data == NULL)
                return -ENOMEM;
        if (IS_SETLKW(cmd))
@@ -4647,7 +4687,7 @@ static int nfs4_reset_slot_table(struct nfs4_slot_table *tbl, u32 max_reqs,
        if (max_reqs != tbl->max_slots) {
                ret = -ENOMEM;
                new = kmalloc(max_reqs * sizeof(struct nfs4_slot),
-                             GFP_KERNEL);
+                             GFP_NOFS);
                if (!new)
                        goto out;
                ret = 0;
@@ -4712,7 +4752,7 @@ static int nfs4_init_slot_table(struct nfs4_slot_table *tbl,
 
        dprintk("--> %s: max_reqs=%u\n", __func__, max_slots);
 
-       slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_KERNEL);
+       slot = kcalloc(max_slots, sizeof(struct nfs4_slot), GFP_NOFS);
        if (!slot)
                goto out;
        ret = 0;
@@ -4761,7 +4801,7 @@ struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp)
        struct nfs4_session *session;
        struct nfs4_slot_table *tbl;
 
-       session = kzalloc(sizeof(struct nfs4_session), GFP_KERNEL);
+       session = kzalloc(sizeof(struct nfs4_session), GFP_NOFS);
        if (!session)
                return NULL;
 
@@ -5105,8 +5145,8 @@ static int nfs41_proc_async_sequence(struct nfs_client *clp,
 
        if (!atomic_inc_not_zero(&clp->cl_count))
                return -EIO;
-       args = kzalloc(sizeof(*args), GFP_KERNEL);
-       res = kzalloc(sizeof(*res), GFP_KERNEL);
+       args = kzalloc(sizeof(*args), GFP_NOFS);
+       res = kzalloc(sizeof(*res), GFP_NOFS);
        if (!args || !res) {
                kfree(args);
                kfree(res);
@@ -5207,7 +5247,7 @@ static int nfs41_proc_reclaim_complete(struct nfs_client *clp)
        int status = -ENOMEM;
 
        dprintk("--> %s\n", __func__);
-       calldata = kzalloc(sizeof(*calldata), GFP_KERNEL);
+       calldata = kzalloc(sizeof(*calldata), GFP_NOFS);
        if (calldata == NULL)
                goto out;
        calldata->clp = clp;
index 6c5ed51..34acf59 100644 (file)
@@ -62,6 +62,7 @@ static LIST_HEAD(nfs4_clientid_list);
 
 int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
 {
+       struct nfs4_setclientid_res clid;
        unsigned short port;
        int status;
 
@@ -69,11 +70,15 @@ int nfs4_init_clientid(struct nfs_client *clp, struct rpc_cred *cred)
        if (clp->cl_addr.ss_family == AF_INET6)
                port = nfs_callback_tcpport6;
 
-       status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred);
-       if (status == 0)
-               status = nfs4_proc_setclientid_confirm(clp, cred);
-       if (status == 0)
-               nfs4_schedule_state_renewal(clp);
+       status = nfs4_proc_setclientid(clp, NFS4_CALLBACK, port, cred, &clid);
+       if (status != 0)
+               goto out;
+       status = nfs4_proc_setclientid_confirm(clp, &clid, cred);
+       if (status != 0)
+               goto out;
+       clp->cl_clientid = clid.clientid;
+       nfs4_schedule_state_renewal(clp);
+out:
        return status;
 }
 
@@ -361,7 +366,7 @@ nfs4_alloc_state_owner(void)
 {
        struct nfs4_state_owner *sp;
 
-       sp = kzalloc(sizeof(*sp),GFP_KERNEL);
+       sp = kzalloc(sizeof(*sp),GFP_NOFS);
        if (!sp)
                return NULL;
        spin_lock_init(&sp->so_lock);
@@ -435,7 +440,7 @@ nfs4_alloc_open_state(void)
 {
        struct nfs4_state *state;
 
-       state = kzalloc(sizeof(*state), GFP_KERNEL);
+       state = kzalloc(sizeof(*state), GFP_NOFS);
        if (!state)
                return NULL;
        atomic_set(&state->count, 1);
@@ -537,7 +542,8 @@ void nfs4_put_open_state(struct nfs4_state *state)
 /*
  * Close the current file.
  */
-static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fmode, int wait)
+static void __nfs4_close(struct path *path, struct nfs4_state *state,
+               fmode_t fmode, gfp_t gfp_mask, int wait)
 {
        struct nfs4_state_owner *owner = state->owner;
        int call_close = 0;
@@ -578,17 +584,17 @@ static void __nfs4_close(struct path *path, struct nfs4_state *state, fmode_t fm
                nfs4_put_open_state(state);
                nfs4_put_state_owner(owner);
        } else
-               nfs4_do_close(path, state, wait);
+               nfs4_do_close(path, state, gfp_mask, wait);
 }
 
 void nfs4_close_state(struct path *path, struct nfs4_state *state, fmode_t fmode)
 {
-       __nfs4_close(path, state, fmode, 0);
+       __nfs4_close(path, state, fmode, GFP_NOFS, 0);
 }
 
 void nfs4_close_sync(struct path *path, struct nfs4_state *state, fmode_t fmode)
 {
-       __nfs4_close(path, state, fmode, 1);
+       __nfs4_close(path, state, fmode, GFP_KERNEL, 1);
 }
 
 /*
@@ -618,7 +624,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
        struct nfs4_lock_state *lsp;
        struct nfs_client *clp = state->owner->so_client;
 
-       lsp = kzalloc(sizeof(*lsp), GFP_KERNEL);
+       lsp = kzalloc(sizeof(*lsp), GFP_NOFS);
        if (lsp == NULL)
                return NULL;
        rpc_init_wait_queue(&lsp->ls_sequence.wait, "lock_seqid_waitqueue");
@@ -754,11 +760,11 @@ void nfs4_copy_stateid(nfs4_stateid *dst, struct nfs4_state *state, fl_owner_t f
        nfs4_put_lock_state(lsp);
 }
 
-struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter)
+struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter, gfp_t gfp_mask)
 {
        struct nfs_seqid *new;
 
-       new = kmalloc(sizeof(*new), GFP_KERNEL);
+       new = kmalloc(sizeof(*new), gfp_mask);
        if (new != NULL) {
                new->sequence = counter;
                INIT_LIST_HEAD(&new->list);
@@ -1347,7 +1353,7 @@ static int nfs4_recall_slot(struct nfs_client *clp)
 
        nfs4_begin_drain_session(clp);
        new = kmalloc(fc_tbl->target_max_slots * sizeof(struct nfs4_slot),
-                     GFP_KERNEL);
+                     GFP_NOFS);
         if (!new)
                return -ENOMEM;
 
index 38f3b58..6bdef28 100644 (file)
@@ -1504,14 +1504,14 @@ static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclie
        hdr->replen += decode_setclientid_maxsz;
 }
 
-static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs_client *client_state, struct compound_hdr *hdr)
+static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
 {
        __be32 *p;
 
        p = reserve_space(xdr, 12 + NFS4_VERIFIER_SIZE);
        *p++ = cpu_to_be32(OP_SETCLIENTID_CONFIRM);
-       p = xdr_encode_hyper(p, client_state->cl_clientid);
-       xdr_encode_opaque_fixed(p, client_state->cl_confirm.data, NFS4_VERIFIER_SIZE);
+       p = xdr_encode_hyper(p, arg->clientid);
+       xdr_encode_opaque_fixed(p, arg->confirm.data, NFS4_VERIFIER_SIZE);
        hdr->nops++;
        hdr->replen += decode_setclientid_confirm_maxsz;
 }
@@ -2324,7 +2324,7 @@ static int nfs4_xdr_enc_setclientid(struct rpc_rqst *req, __be32 *p, struct nfs4
 /*
  * a SETCLIENTID_CONFIRM request
  */
-static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs_client *clp)
+static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, struct nfs4_setclientid_res *arg)
 {
        struct xdr_stream xdr;
        struct compound_hdr hdr = {
@@ -2334,7 +2334,7 @@ static int nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req, __be32 *p, str
 
        xdr_init_encode(&xdr, &req->rq_snd_buf, p);
        encode_compound_hdr(&xdr, req, &hdr);
-       encode_setclientid_confirm(&xdr, clp, &hdr);
+       encode_setclientid_confirm(&xdr, arg, &hdr);
        encode_putrootfh(&xdr, &hdr);
        encode_fsinfo(&xdr, lease_bitmap, &hdr);
        encode_nops(&hdr);
@@ -4397,7 +4397,7 @@ out_overflow:
        return -EIO;
 }
 
-static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
+static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
 {
        __be32 *p;
        uint32_t opnum;
@@ -4417,8 +4417,8 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
                p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
                if (unlikely(!p))
                        goto out_overflow;
-               p = xdr_decode_hyper(p, &clp->cl_clientid);
-               memcpy(clp->cl_confirm.data, p, NFS4_VERIFIER_SIZE);
+               p = xdr_decode_hyper(p, &res->clientid);
+               memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
        } else if (nfserr == NFSERR_CLID_INUSE) {
                uint32_t len;
 
@@ -4815,7 +4815,7 @@ static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, __be32 *p, struct nfs_rem
                goto out;
        if ((status = decode_remove(&xdr, &res->cinfo)) != 0)
                goto out;
-       decode_getfattr(&xdr, &res->dir_attr, res->server,
+       decode_getfattr(&xdr, res->dir_attr, res->server,
                        !RPC_IS_ASYNC(rqstp->rq_task));
 out:
        return status;
@@ -5498,7 +5498,7 @@ static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, __be32 *p, void *dummy)
  * Decode SETCLIENTID response
  */
 static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
-               struct nfs_client *clp)
+               struct nfs4_setclientid_res *res)
 {
        struct xdr_stream xdr;
        struct compound_hdr hdr;
@@ -5507,7 +5507,7 @@ static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
        xdr_init_decode(&xdr, &req->rq_rcv_buf, p);
        status = decode_compound_hdr(&xdr, &hdr);
        if (!status)
-               status = decode_setclientid(&xdr, clp);
+               status = decode_setclientid(&xdr, res);
        return status;
 }
 
index 8c55b27..6bd19d8 100644 (file)
@@ -488,7 +488,6 @@ static int __init root_nfs_ports(void)
  */
 static int __init root_nfs_get_handle(void)
 {
-       struct nfs_fh fh;
        struct sockaddr_in sin;
        unsigned int auth_flav_len = 0;
        struct nfs_mount_request request = {
@@ -499,21 +498,24 @@ static int __init root_nfs_get_handle(void)
                                        NFS_MNT3_VERSION : NFS_MNT_VERSION,
                .protocol       = (nfs_data.flags & NFS_MOUNT_TCP) ?
                                        XPRT_TRANSPORT_TCP : XPRT_TRANSPORT_UDP,
-               .fh             = &fh,
                .auth_flav_len  = &auth_flav_len,
        };
-       int status;
+       int status = -ENOMEM;
 
+       request.fh = nfs_alloc_fhandle();
+       if (!request.fh)
+               goto out;
        set_sockaddr(&sin, servaddr, htons(mount_port));
        status = nfs_mount(&request);
        if (status < 0)
                printk(KERN_ERR "Root-NFS: Server returned error %d "
                                "while mounting %s\n", status, nfs_export_path);
        else {
-               nfs_data.root.size = fh.size;
-               memcpy(nfs_data.root.data, fh.data, fh.size);
+               nfs_data.root.size = request.fh->size;
+               memcpy(&nfs_data.root.data, request.fh->data, request.fh->size);
        }
-
+       nfs_free_fhandle(request.fh);
+out:
        return status;
 }
 
index 29d9d36..a3654e5 100644 (file)
@@ -60,16 +60,10 @@ nfs_create_request(struct nfs_open_context *ctx, struct inode *inode,
 {
        struct nfs_page         *req;
 
-       for (;;) {
-               /* try to allocate the request struct */
-               req = nfs_page_alloc();
-               if (req != NULL)
-                       break;
-
-               if (fatal_signal_pending(current))
-                       return ERR_PTR(-ERESTARTSYS);
-               yield();
-       }
+       /* try to allocate the request struct */
+       req = nfs_page_alloc();
+       if (req == NULL)
+               return ERR_PTR(-ENOMEM);
 
        /* Initialize the request struct. Initially, we assume a
         * long write-back delay. This will be adjusted in
index 0288be8..611bec2 100644 (file)
@@ -224,35 +224,60 @@ static int nfs_proc_readlink(struct inode *inode, struct page *page,
        return status;
 }
 
+struct nfs_createdata {
+       struct nfs_createargs arg;
+       struct nfs_diropok res;
+       struct nfs_fh fhandle;
+       struct nfs_fattr fattr;
+};
+
+static struct nfs_createdata *nfs_alloc_createdata(struct inode *dir,
+               struct dentry *dentry, struct iattr *sattr)
+{
+       struct nfs_createdata *data;
+
+       data = kmalloc(sizeof(*data), GFP_KERNEL);
+
+       if (data != NULL) {
+               data->arg.fh = NFS_FH(dir);
+               data->arg.name = dentry->d_name.name;
+               data->arg.len = dentry->d_name.len;
+               data->arg.sattr = sattr;
+               nfs_fattr_init(&data->fattr);
+               data->fhandle.size = 0;
+               data->res.fh = &data->fhandle;
+               data->res.fattr = &data->fattr;
+       }
+       return data;
+};
+
+static void nfs_free_createdata(const struct nfs_createdata *data)
+{
+       kfree(data);
+}
+
 static int
 nfs_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
                int flags, struct nameidata *nd)
 {
-       struct nfs_fh           fhandle;
-       struct nfs_fattr        fattr;
-       struct nfs_createargs   arg = {
-               .fh             = NFS_FH(dir),
-               .name           = dentry->d_name.name,
-               .len            = dentry->d_name.len,
-               .sattr          = sattr
-       };
-       struct nfs_diropok      res = {
-               .fh             = &fhandle,
-               .fattr          = &fattr
-       };
+       struct nfs_createdata *data;
        struct rpc_message msg = {
                .rpc_proc       = &nfs_procedures[NFSPROC_CREATE],
-               .rpc_argp       = &arg,
-               .rpc_resp       = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
 
-       nfs_fattr_init(&fattr);
        dprintk("NFS call  create %s\n", dentry->d_name.name);
+       data = nfs_alloc_createdata(dir, dentry, sattr);
+       if (data == NULL)
+               goto out;
+       msg.rpc_argp = &data->arg;
+       msg.rpc_resp = &data->res;
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        nfs_mark_for_revalidate(dir);
        if (status == 0)
-               status = nfs_instantiate(dentry, &fhandle, &fattr);
+               status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
+       nfs_free_createdata(data);
+out:
        dprintk("NFS reply create: %d\n", status);
        return status;
 }
@@ -264,24 +289,12 @@ static int
 nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
               dev_t rdev)
 {
-       struct nfs_fh fhandle;
-       struct nfs_fattr fattr;
-       struct nfs_createargs   arg = {
-               .fh             = NFS_FH(dir),
-               .name           = dentry->d_name.name,
-               .len            = dentry->d_name.len,
-               .sattr          = sattr
-       };
-       struct nfs_diropok      res = {
-               .fh             = &fhandle,
-               .fattr          = &fattr
-       };
+       struct nfs_createdata *data;
        struct rpc_message msg = {
                .rpc_proc       = &nfs_procedures[NFSPROC_CREATE],
-               .rpc_argp       = &arg,
-               .rpc_resp       = &res,
        };
-       int status, mode;
+       umode_t mode;
+       int status = -ENOMEM;
 
        dprintk("NFS call  mknod %s\n", dentry->d_name.name);
 
@@ -294,17 +307,24 @@ nfs_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
                sattr->ia_size = new_encode_dev(rdev);/* get out your barf bag */
        }
 
-       nfs_fattr_init(&fattr);
+       data = nfs_alloc_createdata(dir, dentry, sattr);
+       if (data == NULL)
+               goto out;
+       msg.rpc_argp = &data->arg;
+       msg.rpc_resp = &data->res;
+
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        nfs_mark_for_revalidate(dir);
 
        if (status == -EINVAL && S_ISFIFO(mode)) {
                sattr->ia_mode = mode;
-               nfs_fattr_init(&fattr);
+               nfs_fattr_init(data->res.fattr);
                status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        }
        if (status == 0)
-               status = nfs_instantiate(dentry, &fhandle, &fattr);
+               status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
+       nfs_free_createdata(data);
+out:
        dprintk("NFS reply mknod: %d\n", status);
        return status;
 }
@@ -398,8 +418,8 @@ static int
 nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
                 unsigned int len, struct iattr *sattr)
 {
-       struct nfs_fh fhandle;
-       struct nfs_fattr fattr;
+       struct nfs_fh *fh;
+       struct nfs_fattr *fattr;
        struct nfs_symlinkargs  arg = {
                .fromfh         = NFS_FH(dir),
                .fromname       = dentry->d_name.name,
@@ -412,12 +432,18 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
                .rpc_proc       = &nfs_procedures[NFSPROC_SYMLINK],
                .rpc_argp       = &arg,
        };
-       int                     status;
+       int status = -ENAMETOOLONG;
+
+       dprintk("NFS call  symlink %s\n", dentry->d_name.name);
 
        if (len > NFS2_MAXPATHLEN)
-               return -ENAMETOOLONG;
+               goto out;
 
-       dprintk("NFS call  symlink %s\n", dentry->d_name.name);
+       fh = nfs_alloc_fhandle();
+       fattr = nfs_alloc_fattr();
+       status = -ENOMEM;
+       if (fh == NULL || fattr == NULL)
+               goto out;
 
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        nfs_mark_for_revalidate(dir);
@@ -427,12 +453,12 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
         * filehandle size to zero indicates to nfs_instantiate that it
         * should fill in the data with a LOOKUP call on the wire.
         */
-       if (status == 0) {
-               nfs_fattr_init(&fattr);
-               fhandle.size = 0;
-               status = nfs_instantiate(dentry, &fhandle, &fattr);
-       }
+       if (status == 0)
+               status = nfs_instantiate(dentry, fh, fattr);
 
+       nfs_free_fattr(fattr);
+       nfs_free_fhandle(fh);
+out:
        dprintk("NFS reply symlink: %d\n", status);
        return status;
 }
@@ -440,31 +466,25 @@ nfs_proc_symlink(struct inode *dir, struct dentry *dentry, struct page *page,
 static int
 nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)
 {
-       struct nfs_fh fhandle;
-       struct nfs_fattr fattr;
-       struct nfs_createargs   arg = {
-               .fh             = NFS_FH(dir),
-               .name           = dentry->d_name.name,
-               .len            = dentry->d_name.len,
-               .sattr          = sattr
-       };
-       struct nfs_diropok      res = {
-               .fh             = &fhandle,
-               .fattr          = &fattr
-       };
+       struct nfs_createdata *data;
        struct rpc_message msg = {
                .rpc_proc       = &nfs_procedures[NFSPROC_MKDIR],
-               .rpc_argp       = &arg,
-               .rpc_resp       = &res,
        };
-       int                     status;
+       int status = -ENOMEM;
 
        dprintk("NFS call  mkdir %s\n", dentry->d_name.name);
-       nfs_fattr_init(&fattr);
+       data = nfs_alloc_createdata(dir, dentry, sattr);
+       if (data == NULL)
+               goto out;
+       msg.rpc_argp = &data->arg;
+       msg.rpc_resp = &data->res;
+
        status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0);
        nfs_mark_for_revalidate(dir);
        if (status == 0)
-               status = nfs_instantiate(dentry, &fhandle, &fattr);
+               status = nfs_instantiate(dentry, data->res.fh, data->res.fattr);
+       nfs_free_createdata(data);
+out:
        dprintk("NFS reply mkdir: %d\n", status);
        return status;
 }
index db9b360..6e2b06e 100644 (file)
@@ -40,7 +40,7 @@ static mempool_t *nfs_rdata_mempool;
 
 struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
 {
-       struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_NOFS);
+       struct nfs_read_data *p = mempool_alloc(nfs_rdata_mempool, GFP_KERNEL);
 
        if (p) {
                memset(p, 0, sizeof(*p));
@@ -50,7 +50,7 @@ struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
                if (pagecount <= ARRAY_SIZE(p->page_array))
                        p->pagevec = p->page_array;
                else {
-                       p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_NOFS);
+                       p->pagevec = kcalloc(pagecount, sizeof(struct page *), GFP_KERNEL);
                        if (!p->pagevec) {
                                mempool_free(p, nfs_rdata_mempool);
                                p = NULL;
index b4148fc..2f8b115 100644 (file)
@@ -141,7 +141,6 @@ static const match_table_t nfs_mount_option_tokens = {
        { Opt_resvport, "resvport" },
        { Opt_noresvport, "noresvport" },
        { Opt_fscache, "fsc" },
-       { Opt_fscache_uniq, "fsc=%s" },
        { Opt_nofscache, "nofsc" },
 
        { Opt_port, "port=%s" },
@@ -171,6 +170,7 @@ static const match_table_t nfs_mount_option_tokens = {
        { Opt_mountaddr, "mountaddr=%s" },
 
        { Opt_lookupcache, "lookupcache=%s" },
+       { Opt_fscache_uniq, "fsc=%s" },
 
        { Opt_err, NULL }
 };
@@ -423,15 +423,19 @@ static int nfs_statfs(struct dentry *dentry, struct kstatfs *buf)
        unsigned char blockbits;
        unsigned long blockres;
        struct nfs_fh *fh = NFS_FH(dentry->d_inode);
-       struct nfs_fattr fattr;
-       struct nfs_fsstat res = {
-                       .fattr = &fattr,
-       };
-       int error;
+       struct nfs_fsstat res;
+       int error = -ENOMEM;
+
+       res.fattr = nfs_alloc_fattr();
+       if (res.fattr == NULL)
+               goto out_err;
 
        error = server->nfs_client->rpc_ops->statfs(server, fh, &res);
+
+       nfs_free_fattr(res.fattr);
        if (error < 0)
                goto out_err;
+
        buf->f_type = NFS_SUPER_MAGIC;
 
        /*
@@ -1046,14 +1050,6 @@ static int nfs_parse_mount_options(char *raw,
                        kfree(mnt->fscache_uniq);
                        mnt->fscache_uniq = NULL;
                        break;
-               case Opt_fscache_uniq:
-                       string = match_strdup(args);
-                       if (!string)
-                               goto out_nomem;
-                       kfree(mnt->fscache_uniq);
-                       mnt->fscache_uniq = string;
-                       mnt->options |= NFS_OPTION_FSCACHE;
-                       break;
 
                /*
                 * options that take numeric values
@@ -1384,6 +1380,14 @@ static int nfs_parse_mount_options(char *raw,
                                        return 0;
                        };
                        break;
+               case Opt_fscache_uniq:
+                       string = match_strdup(args);
+                       if (string == NULL)
+                               goto out_nomem;
+                       kfree(mnt->fscache_uniq);
+                       mnt->fscache_uniq = string;
+                       mnt->options |= NFS_OPTION_FSCACHE;
+                       break;
 
                /*
                 * Special options
@@ -2172,7 +2176,7 @@ static int nfs_get_sb(struct file_system_type *fs_type,
        int error = -ENOMEM;
 
        data = nfs_alloc_parsed_mount_data(3);
-       mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
+       mntfh = nfs_alloc_fhandle();
        if (data == NULL || mntfh == NULL)
                goto out_free_fh;
 
@@ -2247,7 +2251,7 @@ out:
        kfree(data->fscache_uniq);
        security_free_mnt_opts(&data->lsm_opts);
 out_free_fh:
-       kfree(mntfh);
+       nfs_free_fhandle(mntfh);
        kfree(data);
        return error;
 
@@ -2556,7 +2560,7 @@ static int nfs4_remote_get_sb(struct file_system_type *fs_type,
        };
        int error = -ENOMEM;
 
-       mntfh = kzalloc(sizeof(*mntfh), GFP_KERNEL);
+       mntfh = nfs_alloc_fhandle();
        if (data == NULL || mntfh == NULL)
                goto out_free_fh;
 
@@ -2614,7 +2618,7 @@ static int nfs4_remote_get_sb(struct file_system_type *fs_type,
 out:
        security_free_mnt_opts(&data->lsm_opts);
 out_free_fh:
-       kfree(mntfh);
+       nfs_free_fhandle(mntfh);
        return error;
 
 out_free:
@@ -2669,41 +2673,120 @@ out_freepage:
        free_page((unsigned long)page);
 }
 
+struct nfs_referral_count {
+       struct list_head list;
+       const struct task_struct *task;
+       unsigned int referral_count;
+};
+
+static LIST_HEAD(nfs_referral_count_list);
+static DEFINE_SPINLOCK(nfs_referral_count_list_lock);
+
+static struct nfs_referral_count *nfs_find_referral_count(void)
+{
+       struct nfs_referral_count *p;
+
+       list_for_each_entry(p, &nfs_referral_count_list, list) {
+               if (p->task == current)
+                       return p;
+       }
+       return NULL;
+}
+
+#define NFS_MAX_NESTED_REFERRALS 2
+
+static int nfs_referral_loop_protect(void)
+{
+       struct nfs_referral_count *p, *new;
+       int ret = -ENOMEM;
+
+       new = kmalloc(sizeof(*new), GFP_KERNEL);
+       if (!new)
+               goto out;
+       new->task = current;
+       new->referral_count = 1;
+
+       ret = 0;
+       spin_lock(&nfs_referral_count_list_lock);
+       p = nfs_find_referral_count();
+       if (p != NULL) {
+               if (p->referral_count >= NFS_MAX_NESTED_REFERRALS)
+                       ret = -ELOOP;
+               else
+                       p->referral_count++;
+       } else {
+               list_add(&new->list, &nfs_referral_count_list);
+               new = NULL;
+       }
+       spin_unlock(&nfs_referral_count_list_lock);
+       kfree(new);
+out:
+       return ret;
+}
+
+static void nfs_referral_loop_unprotect(void)
+{
+       struct nfs_referral_count *p;
+
+       spin_lock(&nfs_referral_count_list_lock);
+       p = nfs_find_referral_count();
+       p->referral_count--;
+       if (p->referral_count == 0)
+               list_del(&p->list);
+       else
+               p = NULL;
+       spin_unlock(&nfs_referral_count_list_lock);
+       kfree(p);
+}
+
 static int nfs_follow_remote_path(struct vfsmount *root_mnt,
                const char *export_path, struct vfsmount *mnt_target)
 {
+       struct nameidata *nd = NULL;
        struct mnt_namespace *ns_private;
-       struct nameidata nd;
        struct super_block *s;
        int ret;
 
+       nd = kmalloc(sizeof(*nd), GFP_KERNEL);
+       if (nd == NULL)
+               return -ENOMEM;
+
        ns_private = create_mnt_ns(root_mnt);
        ret = PTR_ERR(ns_private);
        if (IS_ERR(ns_private))
                goto out_mntput;
 
+       ret = nfs_referral_loop_protect();
+       if (ret != 0)
+               goto out_put_mnt_ns;
+
        ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt,
-                       export_path, LOOKUP_FOLLOW, &nd);
+                       export_path, LOOKUP_FOLLOW, nd);
 
+       nfs_referral_loop_unprotect();
        put_mnt_ns(ns_private);
 
        if (ret != 0)
                goto out_err;
 
-       s = nd.path.mnt->mnt_sb;
+       s = nd->path.mnt->mnt_sb;
        atomic_inc(&s->s_active);
        mnt_target->mnt_sb = s;
-       mnt_target->mnt_root = dget(nd.path.dentry);
+       mnt_target->mnt_root = dget(nd->path.dentry);
 
        /* Correct the device pathname */
-       nfs_fix_devname(&nd.path, mnt_target);
+       nfs_fix_devname(&nd->path, mnt_target);
 
-       path_put(&nd.path);
+       path_put(&nd->path);
+       kfree(nd);
        down_write(&s->s_umount);
        return 0;
+out_put_mnt_ns:
+       put_mnt_ns(ns_private);
 out_mntput:
        mntput(root_mnt);
 out_err:
+       kfree(nd);
        return ret;
 }
 
@@ -2874,17 +2957,21 @@ static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
        struct super_block *s;
        struct nfs_server *server;
        struct dentry *mntroot;
-       struct nfs_fh mntfh;
+       struct nfs_fh *mntfh;
        int (*compare_super)(struct super_block *, void *) = nfs_compare_super;
        struct nfs_sb_mountdata sb_mntdata = {
                .mntflags = flags,
        };
-       int error;
+       int error = -ENOMEM;
 
        dprintk("--> nfs4_referral_get_sb()\n");
 
+       mntfh = nfs_alloc_fhandle();
+       if (mntfh == NULL)
+               goto out_err_nofh;
+
        /* create a new volume representation */
-       server = nfs4_create_referral_server(data, &mntfh);
+       server = nfs4_create_referral_server(data, mntfh);
        if (IS_ERR(server)) {
                error = PTR_ERR(server);
                goto out_err_noserver;
@@ -2916,7 +3003,7 @@ static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
                nfs_fscache_get_super_cookie(s, NULL, data);
        }
 
-       mntroot = nfs4_get_root(s, &mntfh);
+       mntroot = nfs4_get_root(s, mntfh);
        if (IS_ERR(mntroot)) {
                error = PTR_ERR(mntroot);
                goto error_splat_super;
@@ -2933,12 +3020,15 @@ static int nfs4_remote_referral_get_sb(struct file_system_type *fs_type,
 
        security_sb_clone_mnt_opts(data->sb, s);
 
+       nfs_free_fhandle(mntfh);
        dprintk("<-- nfs4_referral_get_sb() = 0\n");
        return 0;
 
 out_err_nosb:
        nfs_free_server(server);
 out_err_noserver:
+       nfs_free_fhandle(mntfh);
+out_err_nofh:
        dprintk("<-- nfs4_referral_get_sb() = %d [error]\n", error);
        return error;
 
@@ -2947,6 +3037,7 @@ error_splat_super:
                bdi_unregister(&server->backing_dev_info);
 error_splat_bdi:
        deactivate_locked_super(s);
+       nfs_free_fhandle(mntfh);
        dprintk("<-- nfs4_referral_get_sb() = %d [splat]\n", error);
        return error;
 }
index 6da3d3f..a2242af 100644 (file)
@@ -23,6 +23,7 @@ struct nfs_unlinkdata {
        struct nfs_removeres res;
        struct inode *dir;
        struct rpc_cred *cred;
+       struct nfs_fattr dir_attr;
 };
 
 /**
@@ -169,7 +170,7 @@ static int nfs_do_call_unlink(struct dentry *parent, struct inode *dir, struct n
        }
        nfs_sb_active(dir->i_sb);
        data->args.fh = NFS_FH(dir);
-       nfs_fattr_init(&data->res.dir_attr);
+       nfs_fattr_init(data->res.dir_attr);
 
        NFS_PROTO(dir)->unlink_setup(&msg, dir);
 
@@ -259,6 +260,7 @@ nfs_async_unlink(struct inode *dir, struct dentry *dentry)
                goto out_free;
        }
        data->res.seq_res.sr_slotid = NFS4_MAX_SLOT_TABLE;
+       data->res.dir_attr = &data->dir_attr;
 
        status = -EBUSY;
        spin_lock(&dentry->d_lock);
index 872a5ef..c2a4f71 100644 (file)
@@ -259,10 +259,9 @@ static struct cache_detail svc_expkey_cache = {
        .alloc          = expkey_alloc,
 };
 
-static struct svc_expkey *
-svc_expkey_lookup(struct svc_expkey *item)
+static int
+svc_expkey_hash(struct svc_expkey *item)
 {
-       struct cache_head *ch;
        int hash = item->ek_fsidtype;
        char * cp = (char*)item->ek_fsid;
        int len = key_len(item->ek_fsidtype);
@@ -270,6 +269,14 @@ svc_expkey_lookup(struct svc_expkey *item)
        hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
        hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
        hash &= EXPKEY_HASHMASK;
+       return hash;
+}
+
+static struct svc_expkey *
+svc_expkey_lookup(struct svc_expkey *item)
+{
+       struct cache_head *ch;
+       int hash = svc_expkey_hash(item);
 
        ch = sunrpc_cache_lookup(&svc_expkey_cache, &item->h,
                                 hash);
@@ -283,13 +290,7 @@ static struct svc_expkey *
 svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old)
 {
        struct cache_head *ch;
-       int hash = new->ek_fsidtype;
-       char * cp = (char*)new->ek_fsid;
-       int len = key_len(new->ek_fsidtype);
-
-       hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
-       hash ^= hash_ptr(new->ek_client, EXPKEY_HASHBITS);
-       hash &= EXPKEY_HASHMASK;
+       int hash = svc_expkey_hash(new);
 
        ch = sunrpc_cache_update(&svc_expkey_cache, &new->h,
                                 &old->h, hash);
@@ -738,14 +739,22 @@ struct cache_detail svc_export_cache = {
        .alloc          = svc_export_alloc,
 };
 
-static struct svc_export *
-svc_export_lookup(struct svc_export *exp)
+static int
+svc_export_hash(struct svc_export *exp)
 {
-       struct cache_head *ch;
        int hash;
+
        hash = hash_ptr(exp->ex_client, EXPORT_HASHBITS);
        hash ^= hash_ptr(exp->ex_path.dentry, EXPORT_HASHBITS);
        hash ^= hash_ptr(exp->ex_path.mnt, EXPORT_HASHBITS);
+       return hash;
+}
+
+static struct svc_export *
+svc_export_lookup(struct svc_export *exp)
+{
+       struct cache_head *ch;
+       int hash = svc_export_hash(exp);
 
        ch = sunrpc_cache_lookup(&svc_export_cache, &exp->h,
                                 hash);
@@ -759,10 +768,7 @@ static struct svc_export *
 svc_export_update(struct svc_export *new, struct svc_export *old)
 {
        struct cache_head *ch;
-       int hash;
-       hash = hash_ptr(old->ex_client, EXPORT_HASHBITS);
-       hash ^= hash_ptr(old->ex_path.dentry, EXPORT_HASHBITS);
-       hash ^= hash_ptr(old->ex_path.mnt, EXPORT_HASHBITS);
+       int hash = svc_export_hash(old);
 
        ch = sunrpc_cache_update(&svc_export_cache, &new->h,
                                 &old->h,
@@ -1071,9 +1077,9 @@ exp_export(struct nfsctl_export *nxp)
                err = 0;
 finish:
        kfree(new.ex_pathname);
-       if (exp)
+       if (!IS_ERR_OR_NULL(exp))
                exp_put(exp);
-       if (fsid_key && !IS_ERR(fsid_key))
+       if (!IS_ERR_OR_NULL(fsid_key))
                cache_put(&fsid_key->h, &svc_expkey_cache);
        path_put(&path);
 out_put_clp:
index 7e32bd3..eb78e7e 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <linux/sunrpc/clnt.h>
+#include <linux/sunrpc/svc_xprt.h>
 #include <linux/slab.h>
 #include "nfsd.h"
 #include "state.h"
@@ -79,11 +80,6 @@ enum nfs_cb_opnum4 {
                                        cb_sequence_dec_sz +            \
                                        op_dec_sz)
 
-struct nfs4_rpc_args {
-       void                            *args_op;
-       struct nfsd4_cb_sequence        args_seq;
-};
-
 /*
 * Generic encode routines from fs/nfs/nfs4xdr.c
 */
@@ -428,13 +424,19 @@ static struct rpc_procinfo     nfs4_cb_procedures[] = {
 };
 
 static struct rpc_version       nfs_cb_version4 = {
+/*
+ * Note on the callback rpc program version number: despite language in rfc
+ * 5661 section 18.36.3 requiring servers to use 4 in this field, the
+ * official xdr descriptions for both 4.0 and 4.1 specify version 1, and
+ * in practice that appears to be what implementations use.  The section
+ * 18.36.3 language is expected to be fixed in an erratum.
+ */
         .number                 = 1,
         .nrprocs                = ARRAY_SIZE(nfs4_cb_procedures),
         .procs                  = nfs4_cb_procedures
 };
 
 static struct rpc_version *    nfs_cb_version[] = {
-       NULL,
        &nfs_cb_version4,
 };
 
@@ -456,15 +458,14 @@ static struct rpc_program cb_program = {
 
 static int max_cb_time(void)
 {
-       return max(NFSD_LEASE_TIME/10, (time_t)1) * HZ;
+       return max(nfsd4_lease/10, (time_t)1) * HZ;
 }
 
 /* Reference counting, callback cleanup, etc., all look racy as heck.
- * And why is cb_set an atomic? */
+ * And why is cl_cb_set an atomic? */
 
-int setup_callback_client(struct nfs4_client *clp)
+int setup_callback_client(struct nfs4_client *clp, struct nfs4_cb_conn *cb)
 {
-       struct nfs4_cb_conn *cb = &clp->cl_cb_conn;
        struct rpc_timeout      timeparms = {
                .to_initval     = max_cb_time(),
                .to_retries     = 0,
@@ -476,7 +477,7 @@ int setup_callback_client(struct nfs4_client *clp)
                .timeout        = &timeparms,
                .program        = &cb_program,
                .prognumber     = cb->cb_prog,
-               .version        = nfs_cb_version[1]->number,
+               .version        = 0,
                .authflavor     = clp->cl_flavor,
                .flags          = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
                .client_name    = clp->cl_principal,
@@ -486,7 +487,7 @@ int setup_callback_client(struct nfs4_client *clp)
        if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5))
                return -EINVAL;
        if (cb->cb_minorversion) {
-               args.bc_xprt = clp->cl_cb_xprt;
+               args.bc_xprt = cb->cb_xprt;
                args.protocol = XPRT_TRANSPORT_BC_TCP;
        }
        /* Create RPC client */
@@ -496,7 +497,7 @@ int setup_callback_client(struct nfs4_client *clp)
                        PTR_ERR(client));
                return PTR_ERR(client);
        }
-       cb->cb_client = client;
+       nfsd4_set_callback_client(clp, client);
        return 0;
 
 }
@@ -514,8 +515,7 @@ static void nfsd4_cb_probe_done(struct rpc_task *task, void *calldata)
        if (task->tk_status)
                warn_no_callback_path(clp, task->tk_status);
        else
-               atomic_set(&clp->cl_cb_conn.cb_set, 1);
-       put_nfs4_client(clp);
+               atomic_set(&clp->cl_cb_set, 1);
 }
 
 static const struct rpc_call_ops nfsd4_cb_probe_ops = {
@@ -537,7 +537,6 @@ int set_callback_cred(void)
 
 void do_probe_callback(struct nfs4_client *clp)
 {
-       struct nfs4_cb_conn *cb = &clp->cl_cb_conn;
        struct rpc_message msg = {
                .rpc_proc       = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_NULL],
                .rpc_argp       = clp,
@@ -545,34 +544,27 @@ void do_probe_callback(struct nfs4_client *clp)
        };
        int status;
 
-       status = rpc_call_async(cb->cb_client, &msg,
+       status = rpc_call_async(clp->cl_cb_client, &msg,
                                RPC_TASK_SOFT | RPC_TASK_SOFTCONN,
                                &nfsd4_cb_probe_ops, (void *)clp);
-       if (status) {
+       if (status)
                warn_no_callback_path(clp, status);
-               put_nfs4_client(clp);
-       }
 }
 
 /*
  * Set up the callback client and put a NFSPROC4_CB_NULL on the wire...
  */
-void
-nfsd4_probe_callback(struct nfs4_client *clp)
+void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *cb)
 {
        int status;
 
-       BUG_ON(atomic_read(&clp->cl_cb_conn.cb_set));
+       BUG_ON(atomic_read(&clp->cl_cb_set));
 
-       status = setup_callback_client(clp);
+       status = setup_callback_client(clp, cb);
        if (status) {
                warn_no_callback_path(clp, status);
                return;
        }
-
-       /* the task holds a reference to the nfs4_client struct */
-       atomic_inc(&clp->cl_count);
-
        do_probe_callback(clp);
 }
 
@@ -658,18 +650,32 @@ static void nfsd4_cb_done(struct rpc_task *task, void *calldata)
        }
 }
 
+
 static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata)
 {
        struct nfs4_delegation *dp = calldata;
        struct nfs4_client *clp = dp->dl_client;
+       struct rpc_clnt *current_rpc_client = clp->cl_cb_client;
 
        nfsd4_cb_done(task, calldata);
 
+       if (current_rpc_client == NULL) {
+               /* We're shutting down; give up. */
+               /* XXX: err, or is it ok just to fall through
+                * and rpc_restart_call? */
+               return;
+       }
+
        switch (task->tk_status) {
        case -EIO:
                /* Network partition? */
-               atomic_set(&clp->cl_cb_conn.cb_set, 0);
+               atomic_set(&clp->cl_cb_set, 0);
                warn_no_callback_path(clp, task->tk_status);
+               if (current_rpc_client != task->tk_client) {
+                       /* queue a callback on the new connection: */
+                       nfsd4_cb_recall(dp);
+                       return;
+               }
        case -EBADHANDLE:
        case -NFS4ERR_BAD_STATEID:
                /* Race: client probably got cb_recall
@@ -677,7 +683,7 @@ static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata)
                break;
        default:
                /* success, or error we can't handle */
-               goto done;
+               return;
        }
        if (dp->dl_retries--) {
                rpc_delay(task, 2*HZ);
@@ -685,20 +691,16 @@ static void nfsd4_cb_recall_done(struct rpc_task *task, void *calldata)
                rpc_restart_call(task);
                return;
        } else {
-               atomic_set(&clp->cl_cb_conn.cb_set, 0);
+               atomic_set(&clp->cl_cb_set, 0);
                warn_no_callback_path(clp, task->tk_status);
        }
-done:
-       kfree(task->tk_msg.rpc_argp);
 }
 
 static void nfsd4_cb_recall_release(void *calldata)
 {
        struct nfs4_delegation *dp = calldata;
-       struct nfs4_client *clp = dp->dl_client;
 
        nfs4_put_delegation(dp);
-       put_nfs4_client(clp);
 }
 
 static const struct rpc_call_ops nfsd4_cb_recall_ops = {
@@ -707,33 +709,75 @@ static const struct rpc_call_ops nfsd4_cb_recall_ops = {
        .rpc_release = nfsd4_cb_recall_release,
 };
 
+static struct workqueue_struct *callback_wq;
+
+int nfsd4_create_callback_queue(void)
+{
+       callback_wq = create_singlethread_workqueue("nfsd4_callbacks");
+       if (!callback_wq)
+               return -ENOMEM;
+       return 0;
+}
+
+void nfsd4_destroy_callback_queue(void)
+{
+       destroy_workqueue(callback_wq);
+}
+
+/* must be called under the state lock */
+void nfsd4_set_callback_client(struct nfs4_client *clp, struct rpc_clnt *new)
+{
+       struct rpc_clnt *old = clp->cl_cb_client;
+
+       clp->cl_cb_client = new;
+       /*
+        * After this, any work that saw the old value of cl_cb_client will
+        * be gone:
+        */
+       flush_workqueue(callback_wq);
+       /* So we can safely shut it down: */
+       if (old)
+               rpc_shutdown_client(old);
+}
+
 /*
  * called with dp->dl_count inc'ed.
  */
-void
-nfsd4_cb_recall(struct nfs4_delegation *dp)
+static void _nfsd4_cb_recall(struct nfs4_delegation *dp)
 {
        struct nfs4_client *clp = dp->dl_client;
-       struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;
-       struct nfs4_rpc_args *args;
+       struct rpc_clnt *clnt = clp->cl_cb_client;
+       struct nfs4_rpc_args *args = &dp->dl_recall.cb_args;
        struct rpc_message msg = {
                .rpc_proc = &nfs4_cb_procedures[NFSPROC4_CLNT_CB_RECALL],
                .rpc_cred = callback_cred
        };
-       int status = -ENOMEM;
+       int status;
+
+       if (clnt == NULL)
+               return; /* Client is shutting down; give up. */
 
-       args = kzalloc(sizeof(*args), GFP_KERNEL);
-       if (!args)
-               goto out;
        args->args_op = dp;
        msg.rpc_argp = args;
        dp->dl_retries = 1;
        status = rpc_call_async(clnt, &msg, RPC_TASK_SOFT,
                                &nfsd4_cb_recall_ops, dp);
-out:
-       if (status) {
-               kfree(args);
-               put_nfs4_client(clp);
+       if (status)
                nfs4_put_delegation(dp);
-       }
+}
+
+void nfsd4_do_callback_rpc(struct work_struct *w)
+{
+       /* XXX: for now, just send off delegation recall. */
+       /* In future, generalize to handle any sort of callback. */
+       struct nfsd4_callback *c = container_of(w, struct nfsd4_callback, cb_work);
+       struct nfs4_delegation *dp = container_of(c, struct nfs4_delegation, dl_recall);
+
+       _nfsd4_cb_recall(dp);
+}
+
+
+void nfsd4_cb_recall(struct nfs4_delegation *dp)
+{
+       queue_work(callback_wq, &dp->dl_recall.cb_work);
 }
index 2ab9e85..59ec449 100644 (file)
@@ -969,20 +969,36 @@ static struct nfsd4_operation nfsd4_ops[];
 static const char *nfsd4_op_name(unsigned opnum);
 
 /*
- * Enforce NFSv4.1 COMPOUND ordering rules.
+ * Enforce NFSv4.1 COMPOUND ordering rules:
  *
- * TODO:
- * - enforce NFS4ERR_NOT_ONLY_OP,
- * - DESTROY_SESSION MUST be the final operation in the COMPOUND request.
+ * Also note, enforced elsewhere:
+ *     - SEQUENCE other than as first op results in
+ *       NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
+ *     - BIND_CONN_TO_SESSION must be the only op in its compound
+ *       (Will be enforced in nfsd4_bind_conn_to_session().)
+ *     - DESTROY_SESSION must be the final operation in a compound, if
+ *       sessionid's in SEQUENCE and DESTROY_SESSION are the same.
+ *       (Enforced in nfsd4_destroy_session().)
  */
-static bool nfs41_op_ordering_ok(struct nfsd4_compoundargs *args)
+static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
 {
-       if (args->minorversion && args->opcnt > 0) {
-               struct nfsd4_op *op = &args->ops[0];
-               return (op->status == nfserr_op_illegal) ||
-                      (nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP);
-       }
-       return true;
+       struct nfsd4_op *op = &args->ops[0];
+
+       /* These ordering requirements don't apply to NFSv4.0: */
+       if (args->minorversion == 0)
+               return nfs_ok;
+       /* This is weird, but OK, not our problem: */
+       if (args->opcnt == 0)
+               return nfs_ok;
+       if (op->status == nfserr_op_illegal)
+               return nfs_ok;
+       if (!(nfsd4_ops[op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
+               return nfserr_op_not_in_session;
+       if (op->opnum == OP_SEQUENCE)
+               return nfs_ok;
+       if (args->opcnt != 1)
+               return nfserr_not_only_op;
+       return nfs_ok;
 }
 
 /*
@@ -1012,6 +1028,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,
        resp->rqstp = rqstp;
        resp->cstate.minorversion = args->minorversion;
        resp->cstate.replay_owner = NULL;
+       resp->cstate.session = NULL;
        fh_init(&resp->cstate.current_fh, NFS4_FHSIZE);
        fh_init(&resp->cstate.save_fh, NFS4_FHSIZE);
        /* Use the deferral mechanism only for NFSv4.0 compounds */
@@ -1024,13 +1041,13 @@ nfsd4_proc_compound(struct svc_rqst *rqstp,
        if (args->minorversion > nfsd_supported_minorversion)
                goto out;
 
-       if (!nfs41_op_ordering_ok(args)) {
+       status = nfs41_check_op_ordering(args);
+       if (status) {
                op = &args->ops[0];
-               op->status = nfserr_sequence_pos;
+               op->status = status;
                goto encode_op;
        }
 
-       status = nfs_ok;
        while (!status && resp->opcnt < args->opcnt) {
                op = &args->ops[resp->opcnt++];
 
@@ -1295,6 +1312,11 @@ static struct nfsd4_operation nfsd4_ops[] = {
                .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
                .op_name = "OP_SEQUENCE",
        },
+       [OP_RECLAIM_COMPLETE] = {
+               .op_func = (nfsd4op_func)nfsd4_reclaim_complete,
+               .op_flags = ALLOWED_WITHOUT_FH,
+               .op_name = "OP_RECLAIM_COMPLETE",
+       },
 };
 
 static const char *nfsd4_op_name(unsigned opnum)
index 6a8feda..12f7109 100644 (file)
@@ -45,8 +45,8 @@
 #define NFSDDBG_FACILITY                NFSDDBG_PROC
 
 /* Globals */
-static time_t lease_time = 90;     /* default lease time */
-static time_t user_lease_time = 90;
+time_t nfsd4_lease = 90;     /* default lease time */
+time_t nfsd4_grace = 90;
 static time_t boot_time;
 static u32 current_ownerid = 1;
 static u32 current_fileid = 1;
@@ -190,7 +190,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
        dp->dl_vfs_file = stp->st_vfs_file;
        dp->dl_type = type;
        dp->dl_ident = cb->cb_ident;
-       dp->dl_stateid.si_boot = get_seconds();
+       dp->dl_stateid.si_boot = boot_time;
        dp->dl_stateid.si_stateownerid = current_delegid++;
        dp->dl_stateid.si_fileid = 0;
        dp->dl_stateid.si_generation = 0;
@@ -199,6 +199,7 @@ alloc_init_deleg(struct nfs4_client *clp, struct nfs4_stateid *stp, struct svc_f
        atomic_set(&dp->dl_count, 1);
        list_add(&dp->dl_perfile, &fp->fi_delegations);
        list_add(&dp->dl_perclnt, &clp->cl_delegations);
+       INIT_WORK(&dp->dl_recall.cb_work, nfsd4_do_callback_rpc);
        return dp;
 }
 
@@ -249,6 +250,9 @@ unhash_delegation(struct nfs4_delegation *dp)
  * SETCLIENTID state 
  */
 
+/* client_lock protects the client lru list and session hash table */
+static DEFINE_SPINLOCK(client_lock);
+
 /* Hash tables for nfs4_clientid state */
 #define CLIENT_HASH_BITS                 4
 #define CLIENT_HASH_SIZE                (1 << CLIENT_HASH_BITS)
@@ -367,7 +371,6 @@ static void release_openowner(struct nfs4_stateowner *sop)
        nfs4_put_stateowner(sop);
 }
 
-static DEFINE_SPINLOCK(sessionid_lock);
 #define SESSION_HASH_SIZE      512
 static struct list_head sessionid_hashtbl[SESSION_HASH_SIZE];
 
@@ -565,10 +568,10 @@ alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp,
 
        new->se_flags = cses->flags;
        kref_init(&new->se_ref);
-       spin_lock(&sessionid_lock);
+       spin_lock(&client_lock);
        list_add(&new->se_hash, &sessionid_hashtbl[idx]);
        list_add(&new->se_perclnt, &clp->cl_sessions);
-       spin_unlock(&sessionid_lock);
+       spin_unlock(&client_lock);
 
        status = nfs_ok;
 out:
@@ -579,7 +582,7 @@ out_free:
        goto out;
 }
 
-/* caller must hold sessionid_lock */
+/* caller must hold client_lock */
 static struct nfsd4_session *
 find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid)
 {
@@ -602,7 +605,7 @@ find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid)
        return NULL;
 }
 
-/* caller must hold sessionid_lock */
+/* caller must hold client_lock */
 static void
 unhash_session(struct nfsd4_session *ses)
 {
@@ -610,15 +613,6 @@ unhash_session(struct nfsd4_session *ses)
        list_del(&ses->se_perclnt);
 }
 
-static void
-release_session(struct nfsd4_session *ses)
-{
-       spin_lock(&sessionid_lock);
-       unhash_session(ses);
-       spin_unlock(&sessionid_lock);
-       nfsd4_put_session(ses);
-}
-
 void
 free_session(struct kref *kref)
 {
@@ -634,9 +628,18 @@ free_session(struct kref *kref)
        kfree(ses);
 }
 
+/* must be called under the client_lock */
 static inline void
-renew_client(struct nfs4_client *clp)
+renew_client_locked(struct nfs4_client *clp)
 {
+       if (is_client_expired(clp)) {
+               dprintk("%s: client (clientid %08x/%08x) already expired\n",
+                       __func__,
+                       clp->cl_clientid.cl_boot,
+                       clp->cl_clientid.cl_id);
+               return;
+       }
+
        /*
        * Move client to the end to the LRU list.
        */
@@ -647,6 +650,14 @@ renew_client(struct nfs4_client *clp)
        clp->cl_time = get_seconds();
 }
 
+static inline void
+renew_client(struct nfs4_client *clp)
+{
+       spin_lock(&client_lock);
+       renew_client_locked(clp);
+       spin_unlock(&client_lock);
+}
+
 /* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */
 static int
 STALE_CLIENTID(clientid_t *clid)
@@ -680,27 +691,9 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
        return clp;
 }
 
-static void
-shutdown_callback_client(struct nfs4_client *clp)
-{
-       struct rpc_clnt *clnt = clp->cl_cb_conn.cb_client;
-
-       if (clnt) {
-               /*
-                * Callback threads take a reference on the client, so there
-                * should be no outstanding callbacks at this point.
-                */
-               clp->cl_cb_conn.cb_client = NULL;
-               rpc_shutdown_client(clnt);
-       }
-}
-
 static inline void
 free_client(struct nfs4_client *clp)
 {
-       shutdown_callback_client(clp);
-       if (clp->cl_cb_xprt)
-               svc_xprt_put(clp->cl_cb_xprt);
        if (clp->cl_cred.cr_group_info)
                put_group_info(clp->cl_cred.cr_group_info);
        kfree(clp->cl_principal);
@@ -709,10 +702,34 @@ free_client(struct nfs4_client *clp)
 }
 
 void
-put_nfs4_client(struct nfs4_client *clp)
+release_session_client(struct nfsd4_session *session)
 {
-       if (atomic_dec_and_test(&clp->cl_count))
+       struct nfs4_client *clp = session->se_client;
+
+       if (!atomic_dec_and_lock(&clp->cl_refcount, &client_lock))
+               return;
+       if (is_client_expired(clp)) {
                free_client(clp);
+               session->se_client = NULL;
+       } else
+               renew_client_locked(clp);
+       spin_unlock(&client_lock);
+       nfsd4_put_session(session);
+}
+
+/* must be called under the client_lock */
+static inline void
+unhash_client_locked(struct nfs4_client *clp)
+{
+       mark_client_expired(clp);
+       list_del(&clp->cl_lru);
+       while (!list_empty(&clp->cl_sessions)) {
+               struct nfsd4_session  *ses;
+               ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
+                                se_perclnt);
+               unhash_session(ses);
+               nfsd4_put_session(ses);
+       }
 }
 
 static void
@@ -722,9 +739,6 @@ expire_client(struct nfs4_client *clp)
        struct nfs4_delegation *dp;
        struct list_head reaplist;
 
-       dprintk("NFSD: expire_client cl_count %d\n",
-                           atomic_read(&clp->cl_count));
-
        INIT_LIST_HEAD(&reaplist);
        spin_lock(&recall_lock);
        while (!list_empty(&clp->cl_delegations)) {
@@ -740,20 +754,20 @@ expire_client(struct nfs4_client *clp)
                list_del_init(&dp->dl_recall_lru);
                unhash_delegation(dp);
        }
-       list_del(&clp->cl_idhash);
-       list_del(&clp->cl_strhash);
-       list_del(&clp->cl_lru);
        while (!list_empty(&clp->cl_openowners)) {
                sop = list_entry(clp->cl_openowners.next, struct nfs4_stateowner, so_perclient);
                release_openowner(sop);
        }
-       while (!list_empty(&clp->cl_sessions)) {
-               struct nfsd4_session  *ses;
-               ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
-                                se_perclnt);
-               release_session(ses);
-       }
-       put_nfs4_client(clp);
+       nfsd4_set_callback_client(clp, NULL);
+       if (clp->cl_cb_conn.cb_xprt)
+               svc_xprt_put(clp->cl_cb_conn.cb_xprt);
+       list_del(&clp->cl_idhash);
+       list_del(&clp->cl_strhash);
+       spin_lock(&client_lock);
+       unhash_client_locked(clp);
+       if (atomic_read(&clp->cl_refcount) == 0)
+               free_client(clp);
+       spin_unlock(&client_lock);
 }
 
 static void copy_verf(struct nfs4_client *target, nfs4_verifier *source)
@@ -839,14 +853,15 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
        }
 
        memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
-       atomic_set(&clp->cl_count, 1);
-       atomic_set(&clp->cl_cb_conn.cb_set, 0);
+       atomic_set(&clp->cl_refcount, 0);
+       atomic_set(&clp->cl_cb_set, 0);
        INIT_LIST_HEAD(&clp->cl_idhash);
        INIT_LIST_HEAD(&clp->cl_strhash);
        INIT_LIST_HEAD(&clp->cl_openowners);
        INIT_LIST_HEAD(&clp->cl_delegations);
        INIT_LIST_HEAD(&clp->cl_sessions);
        INIT_LIST_HEAD(&clp->cl_lru);
+       clp->cl_time = get_seconds();
        clear_bit(0, &clp->cl_cb_slot_busy);
        rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
        copy_verf(clp, verf);
@@ -877,8 +892,7 @@ add_to_unconfirmed(struct nfs4_client *clp, unsigned int strhashval)
        list_add(&clp->cl_strhash, &unconf_str_hashtbl[strhashval]);
        idhashval = clientid_hashval(clp->cl_clientid.cl_id);
        list_add(&clp->cl_idhash, &unconf_id_hashtbl[idhashval]);
-       list_add_tail(&clp->cl_lru, &client_lru);
-       clp->cl_time = get_seconds();
+       renew_client(clp);
 }
 
 static void
@@ -888,10 +902,9 @@ move_to_confirmed(struct nfs4_client *clp)
        unsigned int strhashval;
 
        dprintk("NFSD: move_to_confirm nfs4_client %p\n", clp);
-       list_del_init(&clp->cl_strhash);
        list_move(&clp->cl_idhash, &conf_id_hashtbl[idhashval]);
        strhashval = clientstr_hashval(clp->cl_recdir);
-       list_add(&clp->cl_strhash, &conf_str_hashtbl[strhashval]);
+       list_move(&clp->cl_strhash, &conf_str_hashtbl[strhashval]);
        renew_client(clp);
 }
 
@@ -1327,15 +1340,9 @@ nfsd4_create_session(struct svc_rqst *rqstp,
                cs_slot->sl_seqid++; /* from 0 to 1 */
                move_to_confirmed(unconf);
 
-               /*
-                * We do not support RDMA or persistent sessions
-                */
-               cr_ses->flags &= ~SESSION4_PERSIST;
-               cr_ses->flags &= ~SESSION4_RDMA;
-
                if (cr_ses->flags & SESSION4_BACK_CHAN) {
-                       unconf->cl_cb_xprt = rqstp->rq_xprt;
-                       svc_xprt_get(unconf->cl_cb_xprt);
+                       unconf->cl_cb_conn.cb_xprt = rqstp->rq_xprt;
+                       svc_xprt_get(rqstp->rq_xprt);
                        rpc_copy_addr(
                                (struct sockaddr *)&unconf->cl_cb_conn.cb_addr,
                                sa);
@@ -1344,7 +1351,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
                                cstate->minorversion;
                        unconf->cl_cb_conn.cb_prog = cr_ses->callback_prog;
                        unconf->cl_cb_seq_nr = 1;
-                       nfsd4_probe_callback(unconf);
+                       nfsd4_probe_callback(unconf, &unconf->cl_cb_conn);
                }
                conf = unconf;
        } else {
@@ -1352,6 +1359,12 @@ nfsd4_create_session(struct svc_rqst *rqstp,
                goto out;
        }
 
+       /*
+        * We do not support RDMA or persistent sessions
+        */
+       cr_ses->flags &= ~SESSION4_PERSIST;
+       cr_ses->flags &= ~SESSION4_RDMA;
+
        status = alloc_init_session(rqstp, conf, cr_ses);
        if (status)
                goto out;
@@ -1369,6 +1382,21 @@ out:
        return status;
 }
 
+static bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
+{
+       struct nfsd4_compoundres *resp = rqstp->rq_resp;
+       struct nfsd4_compoundargs *argp = rqstp->rq_argp;
+
+       return argp->opcnt == resp->opcnt;
+}
+
+static bool nfsd4_compound_in_session(struct nfsd4_session *session, struct nfs4_sessionid *sid)
+{
+       if (!session)
+               return 0;
+       return !memcmp(sid, &session->se_sessionid, sizeof(*sid));
+}
+
 __be32
 nfsd4_destroy_session(struct svc_rqst *r,
                      struct nfsd4_compound_state *cstate,
@@ -1384,19 +1412,25 @@ nfsd4_destroy_session(struct svc_rqst *r,
         * - Do we need to clear any callback info from previous session?
         */
 
+       if (nfsd4_compound_in_session(cstate->session, &sessionid->sessionid)) {
+               if (!nfsd4_last_compound_op(r))
+                       return nfserr_not_only_op;
+       }
        dump_sessionid(__func__, &sessionid->sessionid);
-       spin_lock(&sessionid_lock);
+       spin_lock(&client_lock);
        ses = find_in_sessionid_hashtbl(&sessionid->sessionid);
        if (!ses) {
-               spin_unlock(&sessionid_lock);
+               spin_unlock(&client_lock);
                goto out;
        }
 
        unhash_session(ses);
-       spin_unlock(&sessionid_lock);
+       spin_unlock(&client_lock);
 
+       nfs4_lock_state();
        /* wait for callbacks */
-       shutdown_callback_client(ses->se_client);
+       nfsd4_set_callback_client(ses->se_client, NULL);
+       nfs4_unlock_state();
        nfsd4_put_session(ses);
        status = nfs_ok;
 out:
@@ -1417,7 +1451,7 @@ nfsd4_sequence(struct svc_rqst *rqstp,
        if (resp->opcnt != 1)
                return nfserr_sequence_pos;
 
-       spin_lock(&sessionid_lock);
+       spin_lock(&client_lock);
        status = nfserr_badsession;
        session = find_in_sessionid_hashtbl(&seq->sessionid);
        if (!session)
@@ -1456,22 +1490,46 @@ nfsd4_sequence(struct svc_rqst *rqstp,
        cstate->slot = slot;
        cstate->session = session;
 
-       /* Hold a session reference until done processing the compound:
-        * nfsd4_put_session called only if the cstate slot is set.
-        */
-       nfsd4_get_session(session);
 out:
-       spin_unlock(&sessionid_lock);
-       /* Renew the clientid on success and on replay */
+       /* Hold a session reference until done processing the compound. */
        if (cstate->session) {
-               nfs4_lock_state();
-               renew_client(session->se_client);
-               nfs4_unlock_state();
+               nfsd4_get_session(cstate->session);
+               atomic_inc(&session->se_client->cl_refcount);
        }
+       spin_unlock(&client_lock);
        dprintk("%s: return %d\n", __func__, ntohl(status));
        return status;
 }
 
+__be32
+nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc)
+{
+       if (rc->rca_one_fs) {
+               if (!cstate->current_fh.fh_dentry)
+                       return nfserr_nofilehandle;
+               /*
+                * We don't take advantage of the rca_one_fs case.
+                * That's OK, it's optional, we can safely ignore it.
+                */
+                return nfs_ok;
+       }
+       nfs4_lock_state();
+       if (is_client_expired(cstate->session->se_client)) {
+               nfs4_unlock_state();
+               /*
+                * The following error isn't really legal.
+                * But we only get here if the client just explicitly
+                * destroyed the client.  Surely it no longer cares what
+                * error it gets back on an operation for the dead
+                * client.
+                */
+               return nfserr_stale_clientid;
+       }
+       nfsd4_create_clid_dir(cstate->session->se_client);
+       nfs4_unlock_state();
+       return nfs_ok;
+}
+
 __be32
 nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                  struct nfsd4_setclientid *setclid)
@@ -1631,9 +1689,8 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                if (!same_creds(&conf->cl_cred, &unconf->cl_cred))
                        status = nfserr_clid_inuse;
                else {
-                       /* XXX: We just turn off callbacks until we can handle
-                         * change request correctly. */
-                       atomic_set(&conf->cl_cb_conn.cb_set, 0);
+                       atomic_set(&conf->cl_cb_set, 0);
+                       nfsd4_probe_callback(conf, &unconf->cl_cb_conn);
                        expire_client(unconf);
                        status = nfs_ok;
 
@@ -1667,7 +1724,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                        }
                        move_to_confirmed(unconf);
                        conf = unconf;
-                       nfsd4_probe_callback(conf);
+                       nfsd4_probe_callback(conf, &conf->cl_cb_conn);
                        status = nfs_ok;
                }
        } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm)))
@@ -1700,12 +1757,12 @@ alloc_init_file(struct inode *ino)
                INIT_LIST_HEAD(&fp->fi_hash);
                INIT_LIST_HEAD(&fp->fi_stateids);
                INIT_LIST_HEAD(&fp->fi_delegations);
-               spin_lock(&recall_lock);
-               list_add(&fp->fi_hash, &file_hashtbl[hashval]);
-               spin_unlock(&recall_lock);
                fp->fi_inode = igrab(ino);
                fp->fi_id = current_fileid++;
                fp->fi_had_conflict = false;
+               spin_lock(&recall_lock);
+               list_add(&fp->fi_hash, &file_hashtbl[hashval]);
+               spin_unlock(&recall_lock);
                return fp;
        }
        return NULL;
@@ -1827,7 +1884,7 @@ init_stateid(struct nfs4_stateid *stp, struct nfs4_file *fp, struct nfsd4_open *
        stp->st_stateowner = sop;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = get_seconds();
+       stp->st_stateid.si_boot = boot_time;
        stp->st_stateid.si_stateownerid = sop->so_id;
        stp->st_stateid.si_fileid = fp->fi_id;
        stp->st_stateid.si_generation = 0;
@@ -2028,7 +2085,6 @@ void nfsd_break_deleg_cb(struct file_lock *fl)
         * lock) we know the server hasn't removed the lease yet, we know
         * it's safe to take a reference: */
        atomic_inc(&dp->dl_count);
-       atomic_inc(&dp->dl_client->cl_count);
 
        spin_lock(&recall_lock);
        list_add_tail(&dp->dl_recall_lru, &del_recall_lru);
@@ -2347,7 +2403,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
 {
        struct nfs4_delegation *dp;
        struct nfs4_stateowner *sop = stp->st_stateowner;
-       struct nfs4_cb_conn *cb = &sop->so_client->cl_cb_conn;
+       int cb_up = atomic_read(&sop->so_client->cl_cb_set);
        struct file_lock fl, *flp = &fl;
        int status, flag = 0;
 
@@ -2355,7 +2411,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
        open->op_recall = 0;
        switch (open->op_claim_type) {
                case NFS4_OPEN_CLAIM_PREVIOUS:
-                       if (!atomic_read(&cb->cb_set))
+                       if (!cb_up)
                                open->op_recall = 1;
                        flag = open->op_delegate_type;
                        if (flag == NFS4_OPEN_DELEGATE_NONE)
@@ -2366,7 +2422,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
                         * had the chance to reclaim theirs.... */
                        if (locks_in_grace())
                                goto out;
-                       if (!atomic_read(&cb->cb_set) || !sop->so_confirmed)
+                       if (!cb_up || !sop->so_confirmed)
                                goto out;
                        if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
                                flag = NFS4_OPEN_DELEGATE_WRITE;
@@ -2483,10 +2539,8 @@ nfsd4_process_open2(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nf
        }
        memcpy(&open->op_stateid, &stp->st_stateid, sizeof(stateid_t));
 
-       if (nfsd4_has_session(&resp->cstate)) {
+       if (nfsd4_has_session(&resp->cstate))
                open->op_stateowner->so_confirmed = 1;
-               nfsd4_create_clid_dir(open->op_stateowner->so_client);
-       }
 
        /*
        * Attempt to hand out a delegation. No error return, because the
@@ -2537,7 +2591,7 @@ nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        renew_client(clp);
        status = nfserr_cb_path_down;
        if (!list_empty(&clp->cl_delegations)
-                       && !atomic_read(&clp->cl_cb_conn.cb_set))
+                       && !atomic_read(&clp->cl_cb_set))
                goto out;
        status = nfs_ok;
 out:
@@ -2554,6 +2608,12 @@ nfsd4_end_grace(void)
        dprintk("NFSD: end of grace period\n");
        nfsd4_recdir_purge_old();
        locks_end_grace(&nfsd4_manager);
+       /*
+        * Now that every NFSv4 client has had the chance to recover and
+        * to see the (possibly new, possibly shorter) lease time, we
+        * can safely set the next grace time to the current lease time:
+        */
+       nfsd4_grace = nfsd4_lease;
 }
 
 static time_t
@@ -2563,15 +2623,17 @@ nfs4_laundromat(void)
        struct nfs4_stateowner *sop;
        struct nfs4_delegation *dp;
        struct list_head *pos, *next, reaplist;
-       time_t cutoff = get_seconds() - NFSD_LEASE_TIME;
-       time_t t, clientid_val = NFSD_LEASE_TIME;
-       time_t u, test_val = NFSD_LEASE_TIME;
+       time_t cutoff = get_seconds() - nfsd4_lease;
+       time_t t, clientid_val = nfsd4_lease;
+       time_t u, test_val = nfsd4_lease;
 
        nfs4_lock_state();
 
        dprintk("NFSD: laundromat service - starting\n");
        if (locks_in_grace())
                nfsd4_end_grace();
+       INIT_LIST_HEAD(&reaplist);
+       spin_lock(&client_lock);
        list_for_each_safe(pos, next, &client_lru) {
                clp = list_entry(pos, struct nfs4_client, cl_lru);
                if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
@@ -2580,12 +2642,22 @@ nfs4_laundromat(void)
                                clientid_val = t;
                        break;
                }
+               if (atomic_read(&clp->cl_refcount)) {
+                       dprintk("NFSD: client in use (clientid %08x)\n",
+                               clp->cl_clientid.cl_id);
+                       continue;
+               }
+               unhash_client_locked(clp);
+               list_add(&clp->cl_lru, &reaplist);
+       }
+       spin_unlock(&client_lock);
+       list_for_each_safe(pos, next, &reaplist) {
+               clp = list_entry(pos, struct nfs4_client, cl_lru);
                dprintk("NFSD: purging unused client (clientid %08x)\n",
                        clp->cl_clientid.cl_id);
                nfsd4_remove_clid_dir(clp);
                expire_client(clp);
        }
-       INIT_LIST_HEAD(&reaplist);
        spin_lock(&recall_lock);
        list_for_each_safe(pos, next, &del_recall_lru) {
                dp = list_entry (pos, struct nfs4_delegation, dl_recall_lru);
@@ -2605,7 +2677,7 @@ nfs4_laundromat(void)
                list_del_init(&dp->dl_recall_lru);
                unhash_delegation(dp);
        }
-       test_val = NFSD_LEASE_TIME;
+       test_val = nfsd4_lease;
        list_for_each_safe(pos, next, &close_lru) {
                sop = list_entry(pos, struct nfs4_stateowner, so_close_lru);
                if (time_after((unsigned long)sop->so_time, (unsigned long)cutoff)) {
@@ -2661,39 +2733,11 @@ nfs4_check_fh(struct svc_fh *fhp, struct nfs4_stateid *stp)
 static int
 STALE_STATEID(stateid_t *stateid)
 {
-       if (time_after((unsigned long)boot_time,
-                       (unsigned long)stateid->si_boot)) {
-               dprintk("NFSD: stale stateid " STATEID_FMT "!\n",
-                       STATEID_VAL(stateid));
-               return 1;
-       }
-       return 0;
-}
-
-static int
-EXPIRED_STATEID(stateid_t *stateid)
-{
-       if (time_before((unsigned long)boot_time,
-                       ((unsigned long)stateid->si_boot)) &&
-           time_before((unsigned long)(stateid->si_boot + lease_time), get_seconds())) {
-               dprintk("NFSD: expired stateid " STATEID_FMT "!\n",
-                       STATEID_VAL(stateid));
-               return 1;
-       }
-       return 0;
-}
-
-static __be32
-stateid_error_map(stateid_t *stateid)
-{
-       if (STALE_STATEID(stateid))
-               return nfserr_stale_stateid;
-       if (EXPIRED_STATEID(stateid))
-               return nfserr_expired;
-
-       dprintk("NFSD: bad stateid " STATEID_FMT "!\n",
+       if (stateid->si_boot == boot_time)
+               return 0;
+       dprintk("NFSD: stale stateid " STATEID_FMT "!\n",
                STATEID_VAL(stateid));
-       return nfserr_bad_stateid;
+       return 1;
 }
 
 static inline int
@@ -2817,10 +2861,8 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
        status = nfserr_bad_stateid;
        if (is_delegation_stateid(stateid)) {
                dp = find_delegation_stateid(ino, stateid);
-               if (!dp) {
-                       status = stateid_error_map(stateid);
+               if (!dp)
                        goto out;
-               }
                status = check_stateid_generation(stateid, &dp->dl_stateid,
                                                  flags);
                if (status)
@@ -2833,10 +2875,8 @@ nfs4_preprocess_stateid_op(struct nfsd4_compound_state *cstate,
                        *filpp = dp->dl_vfs_file;
        } else { /* open or lock stateid */
                stp = find_stateid(stateid, flags);
-               if (!stp) {
-                       status = stateid_error_map(stateid);
+               if (!stp)
                        goto out;
-               }
                if (nfs4_check_fh(current_fh, stp))
                        goto out;
                if (!stp->st_stateowner->so_confirmed)
@@ -2908,7 +2948,7 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
                 */
                sop = search_close_lru(stateid->si_stateownerid, flags);
                if (sop == NULL)
-                       return stateid_error_map(stateid);
+                       return nfserr_bad_stateid;
                *sopp = sop;
                goto check_replay;
        }
@@ -3175,10 +3215,8 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        if (!is_delegation_stateid(stateid))
                goto out;
        dp = find_delegation_stateid(inode, stateid);
-       if (!dp) {
-               status = stateid_error_map(stateid);
+       if (!dp)
                goto out;
-       }
        status = check_stateid_generation(stateid, &dp->dl_stateid, flags);
        if (status)
                goto out;
@@ -3404,7 +3442,7 @@ alloc_init_lock_stateid(struct nfs4_stateowner *sop, struct nfs4_file *fp, struc
        stp->st_stateowner = sop;
        get_nfs4_file(fp);
        stp->st_file = fp;
-       stp->st_stateid.si_boot = get_seconds();
+       stp->st_stateid.si_boot = boot_time;
        stp->st_stateid.si_stateownerid = sop->so_id;
        stp->st_stateid.si_fileid = fp->fi_id;
        stp->st_stateid.si_generation = 0;
@@ -3976,12 +4014,6 @@ nfsd4_load_reboot_recovery_data(void)
                printk("NFSD: Failure reading reboot recovery data\n");
 }
 
-unsigned long
-get_nfs4_grace_period(void)
-{
-       return max(user_lease_time, lease_time) * HZ;
-}
-
 /*
  * Since the lifetime of a delegation isn't limited to that of an open, a
  * client may quite reasonably hang on to a delegation as long as it has
@@ -4008,20 +4040,27 @@ set_max_delegations(void)
 static int
 __nfs4_state_start(void)
 {
-       unsigned long grace_time;
+       int ret;
 
        boot_time = get_seconds();
-       grace_time = get_nfs4_grace_period();
-       lease_time = user_lease_time;
        locks_start_grace(&nfsd4_manager);
        printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
-              grace_time/HZ);
+              nfsd4_grace);
+       ret = set_callback_cred();
+       if (ret)
+               return -ENOMEM;
        laundry_wq = create_singlethread_workqueue("nfsd4");
        if (laundry_wq == NULL)
                return -ENOMEM;
-       queue_delayed_work(laundry_wq, &laundromat_work, grace_time);
+       ret = nfsd4_create_callback_queue();
+       if (ret)
+               goto out_free_laundry;
+       queue_delayed_work(laundry_wq, &laundromat_work, nfsd4_grace * HZ);
        set_max_delegations();
-       return set_callback_cred();
+       return 0;
+out_free_laundry:
+       destroy_workqueue(laundry_wq);
+       return ret;
 }
 
 int
@@ -4039,12 +4078,6 @@ nfs4_state_start(void)
        return 0;
 }
 
-time_t
-nfs4_lease_time(void)
-{
-       return lease_time;
-}
-
 static void
 __nfs4_state_shutdown(void)
 {
@@ -4089,6 +4122,7 @@ nfs4_state_shutdown(void)
        nfs4_lock_state();
        nfs4_release_reclaim();
        __nfs4_state_shutdown();
+       nfsd4_destroy_callback_queue();
        nfs4_unlock_state();
 }
 
@@ -4128,21 +4162,3 @@ nfs4_recoverydir(void)
 {
        return user_recovery_dirname;
 }
-
-/*
- * Called when leasetime is changed.
- *
- * The only way the protocol gives us to handle on-the-fly lease changes is to
- * simulate a reboot.  Instead of doing that, we just wait till the next time
- * we start to register any changes in lease time.  If the administrator
- * really wants to change the lease time *now*, they can go ahead and bring
- * nfsd down and then back up again after changing the lease time.
- *
- * user_lease_time is protected by nfsd_mutex since it's only really accessed
- * when nfsd is starting
- */
-void
-nfs4_reset_lease(time_t leasetime)
-{
-       user_lease_time = leasetime;
-}
index 34ccf81..ac17a70 100644 (file)
@@ -1234,6 +1234,16 @@ nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
        DECODE_TAIL;
 }
 
+static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
+{
+       DECODE_HEAD;
+
+       READ_BUF(4);
+       READ32(rc->rca_one_fs);
+
+       DECODE_TAIL;
+}
+
 static __be32
 nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
 {
@@ -1346,7 +1356,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
        [OP_TEST_STATEID]       = (nfsd4_dec)nfsd4_decode_notsupp,
        [OP_WANT_DELEGATION]    = (nfsd4_dec)nfsd4_decode_notsupp,
        [OP_DESTROY_CLIENTID]   = (nfsd4_dec)nfsd4_decode_notsupp,
-       [OP_RECLAIM_COMPLETE]   = (nfsd4_dec)nfsd4_decode_notsupp,
+       [OP_RECLAIM_COMPLETE]   = (nfsd4_dec)nfsd4_decode_reclaim_complete,
 };
 
 struct nfsd4_minorversion_ops {
@@ -1900,7 +1910,7 @@ nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
        if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
                if ((buflen -= 4) < 0)
                        goto out_resource;
-               WRITE32(NFSD_LEASE_TIME);
+               WRITE32(nfsd4_lease);
        }
        if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
                if ((buflen -= 4) < 0)
@@ -3307,11 +3317,14 @@ nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compo
                iov = &rqstp->rq_res.head[0];
        iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
        BUG_ON(iov->iov_len > PAGE_SIZE);
-       if (nfsd4_has_session(cs) && cs->status != nfserr_replay_cache) {
-               nfsd4_store_cache_entry(resp);
-               dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
-               resp->cstate.slot->sl_inuse = false;
-               nfsd4_put_session(resp->cstate.session);
+       if (nfsd4_has_session(cs)) {
+               if (cs->status != nfserr_replay_cache) {
+                       nfsd4_store_cache_entry(resp);
+                       dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
+                       cs->slot->sl_inuse = false;
+               }
+               /* Renew the clientid on success and on replay */
+               release_session_client(cs->session);
        }
        return 1;
 }
index e359107..bc3194e 100644 (file)
@@ -46,6 +46,7 @@ enum {
         */
 #ifdef CONFIG_NFSD_V4
        NFSD_Leasetime,
+       NFSD_Gracetime,
        NFSD_RecoveryDir,
 #endif
 };
@@ -70,6 +71,7 @@ static ssize_t write_ports(struct file *file, char *buf, size_t size);
 static ssize_t write_maxblksize(struct file *file, char *buf, size_t size);
 #ifdef CONFIG_NFSD_V4
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
+static ssize_t write_gracetime(struct file *file, char *buf, size_t size);
 static ssize_t write_recoverydir(struct file *file, char *buf, size_t size);
 #endif
 
@@ -91,6 +93,7 @@ static ssize_t (*write_op[])(struct file *, char *, size_t) = {
        [NFSD_MaxBlkSize] = write_maxblksize,
 #ifdef CONFIG_NFSD_V4
        [NFSD_Leasetime] = write_leasetime,
+       [NFSD_Gracetime] = write_gracetime,
        [NFSD_RecoveryDir] = write_recoverydir,
 #endif
 };
@@ -1204,29 +1207,45 @@ static ssize_t write_maxblksize(struct file *file, char *buf, size_t size)
 }
 
 #ifdef CONFIG_NFSD_V4
-extern time_t nfs4_leasetime(void);
-
-static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
+static ssize_t __nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
 {
-       /* if size > 10 seconds, call
-        * nfs4_reset_lease() then write out the new lease (seconds) as reply
-        */
        char *mesg = buf;
-       int rv, lease;
+       int rv, i;
 
        if (size > 0) {
                if (nfsd_serv)
                        return -EBUSY;
-               rv = get_int(&mesg, &lease);
+               rv = get_int(&mesg, &i);
                if (rv)
                        return rv;
-               if (lease < 10 || lease > 3600)
+               /*
+                * Some sanity checking.  We don't have a reason for
+                * these particular numbers, but problems with the
+                * extremes are:
+                *      - Too short: the briefest network outage may
+                *        cause clients to lose all their locks.  Also,
+                *        the frequent polling may be wasteful.
+                *      - Too long: do you really want reboot recovery
+                *        to take more than an hour?  Or to make other
+                *        clients wait an hour before being able to
+                *        revoke a dead client's locks?
+                */
+               if (i < 10 || i > 3600)
                        return -EINVAL;
-               nfs4_reset_lease(lease);
+               *time = i;
        }
 
-       return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n",
-                                                       nfs4_lease_time());
+       return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%ld\n", *time);
+}
+
+static ssize_t nfsd4_write_time(struct file *file, char *buf, size_t size, time_t *time)
+{
+       ssize_t rv;
+
+       mutex_lock(&nfsd_mutex);
+       rv = __nfsd4_write_time(file, buf, size, time);
+       mutex_unlock(&nfsd_mutex);
+       return rv;
 }
 
 /**
@@ -1252,12 +1271,22 @@ static ssize_t __write_leasetime(struct file *file, char *buf, size_t size)
  */
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size)
 {
-       ssize_t rv;
+       return nfsd4_write_time(file, buf, size, &nfsd4_lease);
+}
 
-       mutex_lock(&nfsd_mutex);
-       rv = __write_leasetime(file, buf, size);
-       mutex_unlock(&nfsd_mutex);
-       return rv;
+/**
+ * write_gracetime - Set or report current NFSv4 grace period time
+ *
+ * As above, but sets the time of the NFSv4 grace period.
+ *
+ * Note this should never be set to less than the *previous*
+ * lease-period time, but we don't try to enforce this.  (In the common
+ * case (a new boot), we don't know what the previous lease time was
+ * anyway.)
+ */
+static ssize_t write_gracetime(struct file *file, char *buf, size_t size)
+{
+       return nfsd4_write_time(file, buf, size, &nfsd4_grace);
 }
 
 extern char *nfs4_recoverydir(void);
@@ -1351,6 +1380,7 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent)
                [NFSD_MaxBlkSize] = {"max_block_size", &transaction_ops, S_IWUSR|S_IRUGO},
 #ifdef CONFIG_NFSD_V4
                [NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
+               [NFSD_Gracetime] = {"nfsv4gracetime", &transaction_ops, S_IWUSR|S_IRUSR},
                [NFSD_RecoveryDir] = {"nfsv4recoverydir", &transaction_ops, S_IWUSR|S_IRUSR},
 #endif
                /* last one */ {""}
index e942a1a..7237776 100644 (file)
@@ -82,7 +82,6 @@ int nfs4_state_init(void);
 void nfsd4_free_slabs(void);
 int nfs4_state_start(void);
 void nfs4_state_shutdown(void);
-time_t nfs4_lease_time(void);
 void nfs4_reset_lease(time_t leasetime);
 int nfs4_reset_recoverydir(char *recdir);
 #else
@@ -90,7 +89,6 @@ static inline int nfs4_state_init(void) { return 0; }
 static inline void nfsd4_free_slabs(void) { }
 static inline int nfs4_state_start(void) { return 0; }
 static inline void nfs4_state_shutdown(void) { }
-static inline time_t nfs4_lease_time(void) { return 0; }
 static inline void nfs4_reset_lease(time_t leasetime) { }
 static inline int nfs4_reset_recoverydir(char *recdir) { return 0; }
 #endif
@@ -229,6 +227,9 @@ extern struct timeval       nfssvc_boot;
 
 #ifdef CONFIG_NFSD_V4
 
+extern time_t nfsd4_lease;
+extern time_t nfsd4_grace;
+
 /* before processing a COMPOUND operation, we have to check that there
  * is enough space in the buffer for XDR encode to succeed.  otherwise,
  * we might process an operation with side effects, and be unable to
@@ -247,7 +248,6 @@ extern struct timeval       nfssvc_boot;
 #define        COMPOUND_SLACK_SPACE            140    /* OP_GETFH */
 #define COMPOUND_ERR_SLACK_SPACE       12     /* OP_SETATTR */
 
-#define NFSD_LEASE_TIME                 (nfs4_lease_time())
 #define NFSD_LAUNDROMAT_MINTIMEOUT      10   /* seconds */
 
 /*
index 171699e..06b2a26 100644 (file)
@@ -120,7 +120,7 @@ u32 nfsd_supported_minorversion;
 int nfsd_vers(int vers, enum vers_op change)
 {
        if (vers < NFSD_MINVERS || vers >= NFSD_NRVERS)
-               return -1;
+               return 0;
        switch(change) {
        case NFSD_SET:
                nfsd_versions[vers] = nfsd_version[vers];
index fefeae2..006c842 100644 (file)
@@ -70,6 +70,16 @@ struct nfsd4_cb_sequence {
        struct nfs4_client      *cbs_clp;
 };
 
+struct nfs4_rpc_args {
+       void                            *args_op;
+       struct nfsd4_cb_sequence        args_seq;
+};
+
+struct nfsd4_callback {
+       struct nfs4_rpc_args cb_args;
+       struct work_struct cb_work;
+};
+
 struct nfs4_delegation {
        struct list_head        dl_perfile;
        struct list_head        dl_perclnt;
@@ -86,6 +96,7 @@ struct nfs4_delegation {
        stateid_t               dl_stateid;
        struct knfsd_fh         dl_fh;
        int                     dl_retries;
+       struct nfsd4_callback   dl_recall;
 };
 
 /* client delegation callback info */
@@ -96,9 +107,7 @@ struct nfs4_cb_conn {
        u32                     cb_prog;
        u32                     cb_minorversion;
        u32                     cb_ident;       /* minorversion 0 only */
-       /* RPC client info */
-       atomic_t                cb_set;     /* successful CB_NULL call */
-       struct rpc_clnt *       cb_client;
+       struct svc_xprt         *cb_xprt;       /* minorversion 1 only */
 };
 
 /* Maximum number of slots per session. 160 is useful for long haul TCP */
@@ -157,7 +166,7 @@ struct nfsd4_session {
        struct list_head        se_hash;        /* hash by sessionid */
        struct list_head        se_perclnt;
        u32                     se_flags;
-       struct nfs4_client      *se_client;     /* for expire_client */
+       struct nfs4_client      *se_client;
        struct nfs4_sessionid   se_sessionid;
        struct nfsd4_channel_attrs se_fchannel;
        struct nfsd4_channel_attrs se_bchannel;
@@ -212,25 +221,41 @@ struct nfs4_client {
        struct svc_cred         cl_cred;        /* setclientid principal */
        clientid_t              cl_clientid;    /* generated by server */
        nfs4_verifier           cl_confirm;     /* generated by server */
-       struct nfs4_cb_conn     cl_cb_conn;     /* callback info */
-       atomic_t                cl_count;       /* ref count */
        u32                     cl_firststate;  /* recovery dir creation */
 
+       /* for v4.0 and v4.1 callbacks: */
+       struct nfs4_cb_conn     cl_cb_conn;
+       struct rpc_clnt         *cl_cb_client;
+       atomic_t                cl_cb_set;
+
        /* for nfs41 */
        struct list_head        cl_sessions;
        struct nfsd4_clid_slot  cl_cs_slot;     /* create_session slot */
        u32                     cl_exchange_flags;
        struct nfs4_sessionid   cl_sessionid;
+       /* number of rpc's in progress over an associated session: */
+       atomic_t                cl_refcount;
 
        /* for nfs41 callbacks */
        /* We currently support a single back channel with a single slot */
        unsigned long           cl_cb_slot_busy;
        u32                     cl_cb_seq_nr;
-       struct svc_xprt         *cl_cb_xprt;    /* 4.1 callback transport */
        struct rpc_wait_queue   cl_cb_waitq;    /* backchannel callers may */
                                                /* wait here for slots */
 };
 
+static inline void
+mark_client_expired(struct nfs4_client *clp)
+{
+       clp->cl_time = 0;
+}
+
+static inline bool
+is_client_expired(struct nfs4_client *clp)
+{
+       return clp->cl_time == 0;
+}
+
 /* struct nfs4_client_reset
  * one per old client. Populates reset_str_hashtbl. Filled from conf_id_hashtbl
  * upon lease reset, or from upcall to state_daemon (to read in state
@@ -377,11 +402,14 @@ extern void nfs4_lock_state(void);
 extern void nfs4_unlock_state(void);
 extern int nfs4_in_grace(void);
 extern __be32 nfs4_check_open_reclaim(clientid_t *clid);
-extern void put_nfs4_client(struct nfs4_client *clp);
 extern void nfs4_free_stateowner(struct kref *kref);
 extern int set_callback_cred(void);
-extern void nfsd4_probe_callback(struct nfs4_client *clp);
+extern void nfsd4_probe_callback(struct nfs4_client *clp, struct nfs4_cb_conn *);
+extern void nfsd4_do_callback_rpc(struct work_struct *);
 extern void nfsd4_cb_recall(struct nfs4_delegation *dp);
+extern int nfsd4_create_callback_queue(void);
+extern void nfsd4_destroy_callback_queue(void);
+extern void nfsd4_set_callback_client(struct nfs4_client *, struct rpc_clnt *);
 extern void nfs4_put_delegation(struct nfs4_delegation *dp);
 extern __be32 nfs4_make_rec_clidname(char *clidname, struct xdr_netobj *clname);
 extern void nfsd4_init_recdir(char *recdir_name);
@@ -392,6 +420,7 @@ extern int nfs4_has_reclaimed_state(const char *name, bool use_exchange_id);
 extern void nfsd4_recdir_purge_old(void);
 extern int nfsd4_create_clid_dir(struct nfs4_client *clp);
 extern void nfsd4_remove_clid_dir(struct nfs4_client *clp);
+extern void release_session_client(struct nfsd4_session *);
 
 static inline void
 nfs4_put_stateowner(struct nfs4_stateowner *so)
index 6dd5f19..23c06f7 100644 (file)
@@ -724,7 +724,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
        struct inode    *inode;
        int             flags = O_RDONLY|O_LARGEFILE;
        __be32          err;
-       int             host_err;
+       int             host_err = 0;
 
        validate_process_creds();
 
@@ -761,7 +761,8 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
         * Check to see if there are any leases on this file.
         * This may block while leases are broken.
         */
-       host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
+       if (!(access & NFSD_MAY_NOT_BREAK_LEASE))
+               host_err = break_lease(inode, O_NONBLOCK | ((access & NFSD_MAY_WRITE) ? O_WRONLY : 0));
        if (host_err == -EWOULDBLOCK)
                host_err = -ETIMEDOUT;
        if (host_err) /* NOMEM or WOULDBLOCK */
@@ -1169,7 +1170,8 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
                        goto out;
        }
 
-       err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_WRITE, &file);
+       err = nfsd_open(rqstp, fhp, S_IFREG,
+                       NFSD_MAY_WRITE|NFSD_MAY_NOT_BREAK_LEASE, &file);
        if (err)
                goto out;
        if (EX_ISSYNC(fhp->fh_export)) {
index 4b1de0a..217a62c 100644 (file)
@@ -20,6 +20,7 @@
 #define NFSD_MAY_OWNER_OVERRIDE        64
 #define NFSD_MAY_LOCAL_ACCESS  128 /* IRIX doing local access check on device special file*/
 #define NFSD_MAY_BYPASS_GSS_ON_ROOT 256
+#define NFSD_MAY_NOT_BREAK_LEASE 512
 
 #define NFSD_MAY_CREATE                (NFSD_MAY_EXEC|NFSD_MAY_WRITE)
 #define NFSD_MAY_REMOVE                (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
index efa3377..4d476ff 100644 (file)
@@ -381,6 +381,10 @@ struct nfsd4_destroy_session {
        struct nfs4_sessionid   sessionid;
 };
 
+struct nfsd4_reclaim_complete {
+       u32 rca_one_fs;
+};
+
 struct nfsd4_op {
        int                                     opnum;
        __be32                                  status;
@@ -421,6 +425,7 @@ struct nfsd4_op {
                struct nfsd4_create_session     create_session;
                struct nfsd4_destroy_session    destroy_session;
                struct nfsd4_sequence           sequence;
+               struct nfsd4_reclaim_complete   reclaim_complete;
        } u;
        struct nfs4_replay *                    replay;
 };
@@ -513,9 +518,8 @@ extern void nfsd4_store_cache_entry(struct nfsd4_compoundres *resp);
 extern __be32 nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,
                struct nfsd4_sequence *seq);
 extern __be32 nfsd4_exchange_id(struct svc_rqst *rqstp,
-               struct nfsd4_compound_state *,
-struct nfsd4_exchange_id *);
-               extern __be32 nfsd4_create_session(struct svc_rqst *,
+               struct nfsd4_compound_state *, struct nfsd4_exchange_id *);
+extern __be32 nfsd4_create_session(struct svc_rqst *,
                struct nfsd4_compound_state *,
                struct nfsd4_create_session *);
 extern __be32 nfsd4_sequence(struct svc_rqst *,
@@ -524,6 +528,7 @@ extern __be32 nfsd4_sequence(struct svc_rqst *,
 extern __be32 nfsd4_destroy_session(struct svc_rqst *,
                struct nfsd4_compound_state *,
                struct nfsd4_destroy_session *);
+__be32 nfsd4_reclaim_complete(struct svc_rqst *, struct nfsd4_compound_state *, struct nfsd4_reclaim_complete *);
 extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *,
                struct nfsd4_open *open);
 extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
index c82af6a..b44bb83 100644 (file)
@@ -3,7 +3,6 @@
  * Copyright (C) 2006 Bob Copeland <me@bobcopeland.com>
  * Released under GPL v2.
  */
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
index 8418fcc..c7f9f23 100644 (file)
@@ -730,6 +730,7 @@ out_no_task:
 
 static const struct file_operations proc_info_file_operations = {
        .read           = proc_info_read,
+       .llseek         = generic_file_llseek,
 };
 
 static int proc_single_show(struct seq_file *m, void *v)
@@ -987,6 +988,7 @@ out_no_task:
 
 static const struct file_operations proc_environ_operations = {
        .read           = environ_read,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t oom_adjust_read(struct file *file, char __user *buf,
@@ -1060,6 +1062,7 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
 static const struct file_operations proc_oom_adjust_operations = {
        .read           = oom_adjust_read,
        .write          = oom_adjust_write,
+       .llseek         = generic_file_llseek,
 };
 
 #ifdef CONFIG_AUDITSYSCALL
@@ -1131,6 +1134,7 @@ out_free_page:
 static const struct file_operations proc_loginuid_operations = {
        .read           = proc_loginuid_read,
        .write          = proc_loginuid_write,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t proc_sessionid_read(struct file * file, char __user * buf,
@@ -1151,6 +1155,7 @@ static ssize_t proc_sessionid_read(struct file * file, char __user * buf,
 
 static const struct file_operations proc_sessionid_operations = {
        .read           = proc_sessionid_read,
+       .llseek         = generic_file_llseek,
 };
 #endif
 
@@ -1202,6 +1207,7 @@ static ssize_t proc_fault_inject_write(struct file * file,
 static const struct file_operations proc_fault_inject_operations = {
        .read           = proc_fault_inject_read,
        .write          = proc_fault_inject_write,
+       .llseek         = generic_file_llseek,
 };
 #endif
 
@@ -1943,7 +1949,7 @@ static ssize_t proc_fdinfo_read(struct file *file, char __user *buf,
 }
 
 static const struct file_operations proc_fdinfo_file_operations = {
-       .open           = nonseekable_open,
+       .open           = nonseekable_open,
        .read           = proc_fdinfo_read,
 };
 
@@ -2227,6 +2233,7 @@ out_no_task:
 static const struct file_operations proc_pid_attr_operations = {
        .read           = proc_pid_attr_read,
        .write          = proc_pid_attr_write,
+       .llseek         = generic_file_llseek,
 };
 
 static const struct pid_entry attr_dir_stuff[] = {
@@ -2347,6 +2354,7 @@ static ssize_t proc_coredump_filter_write(struct file *file,
 static const struct file_operations proc_coredump_filter_operations = {
        .read           = proc_coredump_filter_read,
        .write          = proc_coredump_filter_write,
+       .llseek         = generic_file_llseek,
 };
 #endif
 
index d35b232..aea8502 100644 (file)
@@ -232,9 +232,9 @@ static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigne
                if (rv == -ENOIOCTLCMD)
                        rv = -EINVAL;
        } else if (ioctl) {
-               lock_kernel();
+               WARN_ONCE(1, "Procfs ioctl handlers must use unlocked_ioctl, "
+                         "%pf will be called without the Bkl held\n", ioctl);
                rv = ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
-               unlock_kernel();
        }
 
        pde_users_dec(pde);
index 19979a2..c837a77 100644 (file)
@@ -558,6 +558,7 @@ static int open_kcore(struct inode *inode, struct file *filp)
 static const struct file_operations proc_kcore_operations = {
        .read           = read_kcore,
        .open           = open_kcore,
+       .llseek         = generic_file_llseek,
 };
 
 #ifdef CONFIG_MEMORY_HOTPLUG
index cfe90a4..bd4b5a7 100644 (file)
@@ -53,6 +53,7 @@ static const struct file_operations proc_kmsg_operations = {
        .poll           = kmsg_poll,
        .open           = kmsg_open,
        .release        = kmsg_release,
+       .llseek         = generic_file_llseek,
 };
 
 static int __init proc_kmsg_init(void)
index 9fbc99e..91c817f 100644 (file)
@@ -163,6 +163,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
 
 static const struct file_operations proc_vmcore_operations = {
        .read           = read_vmcore,
+       .llseek         = generic_file_llseek,
 };
 
 static struct vmcore* __init get_new_element(void)
index 5b2e5e8..5958d78 100644 (file)
@@ -87,7 +87,7 @@
 #define AE_NO_GLOBAL_LOCK               (acpi_status) (0x0017 | AE_CODE_ENVIRONMENTAL)
 #define AE_ABORT_METHOD                 (acpi_status) (0x0018 | AE_CODE_ENVIRONMENTAL)
 #define AE_SAME_HANDLER                 (acpi_status) (0x0019 | AE_CODE_ENVIRONMENTAL)
-#define AE_WAKE_ONLY_GPE                (acpi_status) (0x001A | AE_CODE_ENVIRONMENTAL)
+#define AE_NO_HANDLER                   (acpi_status) (0x001A | AE_CODE_ENVIRONMENTAL)
 #define AE_OWNER_ID_LIMIT               (acpi_status) (0x001B | AE_CODE_ENVIRONMENTAL)
 
 #define AE_CODE_ENV_MAX                 0x001B
index d772668..5e95226 100644 (file)
 #define ACPI_WARNING(plist)             acpi_warning plist
 #define ACPI_EXCEPTION(plist)           acpi_exception plist
 #define ACPI_ERROR(plist)               acpi_error plist
+#define ACPI_DEBUG_OBJECT(obj,l,i)      acpi_ex_do_debug_object(obj,l,i)
 
 #else
 
 #define ACPI_WARNING(plist)
 #define ACPI_EXCEPTION(plist)
 #define ACPI_ERROR(plist)
+#define ACPI_DEBUG_OBJECT(obj,l,i)
 
 #endif                         /* ACPI_NO_ERROR_MESSAGES */
 
index b396854..29bf945 100644 (file)
@@ -233,8 +233,8 @@ acpi_os_write_pci_configuration(struct acpi_pci_id *pci_id,
  * Interim function needed for PCI IRQ routing
  */
 void
-acpi_os_derive_pci_id(acpi_handle rhandle,
-                     acpi_handle chandle, struct acpi_pci_id **pci_id);
+acpi_os_derive_pci_id(acpi_handle device,
+                     acpi_handle region, struct acpi_pci_id **pci_id);
 
 /*
  * Miscellaneous
index 4447a04..0e4ab1f 100644 (file)
@@ -47,7 +47,7 @@
 
 /* Current ACPICA subsystem version in YYYYMMDD format */
 
-#define ACPI_CA_VERSION                 0x20100121
+#define ACPI_CA_VERSION                 0x20100428
 
 #include "actypes.h"
 #include "actbl.h"
@@ -67,6 +67,8 @@ extern u8 acpi_gbl_leave_wake_gpes_disabled;
 extern u8 acpi_gbl_use_default_register_widths;
 extern acpi_name acpi_gbl_trace_method_name;
 extern u32 acpi_gbl_trace_flags;
+extern u8 acpi_gbl_enable_aml_debug_object;
+extern u8 acpi_gbl_copy_dsdt_locally;
 
 extern u32 acpi_current_gpe_count;
 extern struct acpi_table_fadt acpi_gbl_FADT;
@@ -164,7 +166,7 @@ acpi_get_devices(const char *HID,
                 void *context, void **return_value);
 
 acpi_status
-acpi_get_name(acpi_handle handle,
+acpi_get_name(acpi_handle object,
              u32 name_type, struct acpi_buffer *ret_path_ptr);
 
 acpi_status
@@ -172,14 +174,12 @@ acpi_get_handle(acpi_handle parent,
                acpi_string pathname, acpi_handle * ret_handle);
 
 acpi_status
-acpi_attach_data(acpi_handle obj_handle,
-                acpi_object_handler handler, void *data);
+acpi_attach_data(acpi_handle object, acpi_object_handler handler, void *data);
 
-acpi_status
-acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler);
+acpi_status acpi_detach_data(acpi_handle object, acpi_object_handler handler);
 
 acpi_status
-acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data);
+acpi_get_data(acpi_handle object, acpi_object_handler handler, void **data);
 
 acpi_status
 acpi_debug_trace(char *name, u32 debug_level, u32 debug_layer, u32 flags);
@@ -201,7 +201,7 @@ acpi_evaluate_object_typed(acpi_handle object,
                           acpi_object_type return_type);
 
 acpi_status
-acpi_get_object_info(acpi_handle handle,
+acpi_get_object_info(acpi_handle object,
                     struct acpi_device_info **return_buffer);
 
 acpi_status acpi_install_method(u8 *buffer);
@@ -283,16 +283,17 @@ acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status);
  */
 acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action);
 
-acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+acpi_status
+acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type);
 
-acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 type);
+acpi_status
+acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u8 gpe_type);
 
-acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags);
+acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number);
 
 acpi_status
 acpi_get_gpe_status(acpi_handle gpe_device,
-                   u32 gpe_number,
-                   u32 flags, acpi_event_status * event_status);
+                   u32 gpe_number, acpi_event_status *event_status);
 
 acpi_status acpi_disable_all_gpes(void);
 
@@ -315,33 +316,29 @@ acpi_status(*acpi_walk_resource_callback) (struct acpi_resource * resource,
                                           void *context);
 
 acpi_status
-acpi_get_vendor_resource(acpi_handle device_handle,
+acpi_get_vendor_resource(acpi_handle device,
                         char *name,
                         struct acpi_vendor_uuid *uuid,
                         struct acpi_buffer *ret_buffer);
 
 acpi_status
-acpi_get_current_resources(acpi_handle device_handle,
-                          struct acpi_buffer *ret_buffer);
+acpi_get_current_resources(acpi_handle device, struct acpi_buffer *ret_buffer);
 
 #ifdef ACPI_FUTURE_USAGE
 acpi_status
-acpi_get_possible_resources(acpi_handle device_handle,
-                           struct acpi_buffer *ret_buffer);
+acpi_get_possible_resources(acpi_handle device, struct acpi_buffer *ret_buffer);
 #endif
 
 acpi_status
-acpi_walk_resources(acpi_handle device_handle,
+acpi_walk_resources(acpi_handle device,
                    char *name,
                    acpi_walk_resource_callback user_function, void *context);
 
 acpi_status
-acpi_set_current_resources(acpi_handle device_handle,
-                          struct acpi_buffer *in_buffer);
+acpi_set_current_resources(acpi_handle device, struct acpi_buffer *in_buffer);
 
 acpi_status
-acpi_get_irq_routing_table(acpi_handle bus_device_handle,
-                          struct acpi_buffer *ret_buffer);
+acpi_get_irq_routing_table(acpi_handle device, struct acpi_buffer *ret_buffer);
 
 acpi_status
 acpi_resource_to_address64(struct acpi_resource *resource,
index 5b02e30..95f4d0e 100644 (file)
@@ -69,6 +69,7 @@
 #define ACPI_SIG_IBFT           "IBFT" /* i_sCSI Boot Firmware Table */
 #define ACPI_SIG_IVRS           "IVRS" /* I/O Virtualization Reporting Structure */
 #define ACPI_SIG_MCFG           "MCFG" /* PCI Memory Mapped Configuration table */
+#define ACPI_SIG_MCHI           "MCHI" /* Management Controller Host Interface table */
 #define ACPI_SIG_SLIC           "SLIC" /* Software Licensing Description Table */
 #define ACPI_SIG_SPCR           "SPCR" /* Serial Port Console Redirection table */
 #define ACPI_SIG_SPMI           "SPMI" /* Server Platform Management Interface table */
@@ -677,6 +678,32 @@ struct acpi_mcfg_allocation {
        u32 reserved;
 };
 
+/*******************************************************************************
+ *
+ * MCHI - Management Controller Host Interface Table
+ *        Version 1
+ *
+ * Conforms to "Management Component Transport Protocol (MCTP) Host
+ * Interface Specification", Revision 1.0.0a, October 13, 2009
+ *
+ ******************************************************************************/
+
+struct acpi_table_mchi {
+       struct acpi_table_header header;        /* Common ACPI table header */
+       u8 interface_type;
+       u8 protocol;
+       u64 protocol_data;
+       u8 interrupt_type;
+       u8 gpe;
+       u8 pci_device_flag;
+       u32 global_interrupt;
+       struct acpi_generic_address control_register;
+       u8 pci_segment;
+       u8 pci_bus;
+       u8 pci_device;
+       u8 pci_function;
+};
+
 /*******************************************************************************
  *
  * SPCR - Serial Port Console Redirection table
index 3f08e64..bade172 100644 (file)
@@ -663,44 +663,42 @@ typedef u32 acpi_event_status;
 #define ACPI_GPE_MAX                    0xFF
 #define ACPI_NUM_GPE                    256
 
+/* Actions for acpi_set_gpe */
+
 #define ACPI_GPE_ENABLE                 0
 #define ACPI_GPE_DISABLE                1
 
+/* gpe_types for acpi_enable_gpe and acpi_disable_gpe */
+
+#define ACPI_GPE_TYPE_WAKE              (u8) 0x01
+#define ACPI_GPE_TYPE_RUNTIME           (u8) 0x02
+#define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x03
+
 /*
  * GPE info flags - Per GPE
- * +-+-+-+---+-+-+-+
- * |7|6|5|4:3|2|1|0|
- * +-+-+-+---+-+-+-+
- *  | | |  |  | | |
- *  | | |  |  | | +--- Interrupt type: Edge or Level Triggered
- *  | | |  |  | +--- GPE can wake the system
- *  | | |  |  +--- Unused
- *  | | |  +--- Type of dispatch -- to method, handler, or none
- *  | | +--- Unused
- *  | +--- Unused
- *  +--- Unused
+ * +-------+---+-+-+
+ * |  7:4  |3:2|1|0|
+ * +-------+---+-+-+
+ *     |     |  | |
+ *     |     |  | +--- Interrupt type: edge or level triggered
+ *     |     |  +----- GPE can wake the system
+ *     |     +-------- Type of dispatch:to method, handler, or none
+ *     +-------------- <Reserved>
  */
 #define ACPI_GPE_XRUPT_TYPE_MASK        (u8) 0x01
 #define ACPI_GPE_LEVEL_TRIGGERED        (u8) 0x01
 #define ACPI_GPE_EDGE_TRIGGERED         (u8) 0x00
 
-#define ACPI_GPE_TYPE_MASK              (u8) 0x06
-#define ACPI_GPE_TYPE_WAKE_RUN          (u8) 0x06
-#define ACPI_GPE_TYPE_WAKE              (u8) 0x02
-#define ACPI_GPE_TYPE_RUNTIME           (u8) 0x04      /* Default */
 #define ACPI_GPE_CAN_WAKE              (u8) 0x02
 
-#define ACPI_GPE_DISPATCH_MASK          (u8) 0x18
-#define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x08
-#define ACPI_GPE_DISPATCH_METHOD        (u8) 0x10
-#define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00      /* Default */
+#define ACPI_GPE_DISPATCH_MASK          (u8) 0x0C
+#define ACPI_GPE_DISPATCH_HANDLER       (u8) 0x04
+#define ACPI_GPE_DISPATCH_METHOD        (u8) 0x08
+#define ACPI_GPE_DISPATCH_NOT_USED      (u8) 0x00
 
 /*
  * Flags for GPE and Lock interfaces
  */
-#define ACPI_EVENT_WAKE_ENABLE          0x2    /* acpi_gpe_enable */
-#define ACPI_EVENT_WAKE_DISABLE         0x2    /* acpi_gpe_disable */
-
 #define ACPI_NOT_ISR                    0x1
 #define ACPI_ISR                        0x0
 
@@ -953,7 +951,7 @@ acpi_status(*acpi_adr_space_setup) (acpi_handle region_handle,
 #define ACPI_REGION_DEACTIVATE  1
 
 typedef
-acpi_status(*acpi_walk_callback) (acpi_handle obj_handle,
+acpi_status(*acpi_walk_callback) (acpi_handle object,
                                  u32 nesting_level,
                                  void *context, void **return_value);
 
index c99c64d..c33749f 100644 (file)
@@ -33,7 +33,7 @@
  * Atomically reads the value of @v.  Note that the guaranteed
  * useful range of an atomic_t is only 24 bits.
  */
-#define atomic_read(v) ((v)->counter)
+#define atomic_read(v) (*(volatile int *)&(v)->counter)
 
 /**
  * atomic_set - set atomic variable
diff --git a/include/asm-generic/bitops/arch_hweight.h b/include/asm-generic/bitops/arch_hweight.h
new file mode 100644 (file)
index 0000000..6a211f4
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_
+#define _ASM_GENERIC_BITOPS_ARCH_HWEIGHT_H_
+
+#include <asm/types.h>
+
+static inline unsigned int __arch_hweight32(unsigned int w)
+{
+       return __sw_hweight32(w);
+}
+
+static inline unsigned int __arch_hweight16(unsigned int w)
+{
+       return __sw_hweight16(w);
+}
+
+static inline unsigned int __arch_hweight8(unsigned int w)
+{
+       return __sw_hweight8(w);
+}
+
+static inline unsigned long __arch_hweight64(__u64 w)
+{
+       return __sw_hweight64(w);
+}
+#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
diff --git a/include/asm-generic/bitops/const_hweight.h b/include/asm-generic/bitops/const_hweight.h
new file mode 100644 (file)
index 0000000..fa2a50b
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_
+#define _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_
+
+/*
+ * Compile time versions of __arch_hweightN()
+ */
+#define __const_hweight8(w)            \
+      (        (!!((w) & (1ULL << 0))) +       \
+       (!!((w) & (1ULL << 1))) +       \
+       (!!((w) & (1ULL << 2))) +       \
+       (!!((w) & (1ULL << 3))) +       \
+       (!!((w) & (1ULL << 4))) +       \
+       (!!((w) & (1ULL << 5))) +       \
+       (!!((w) & (1ULL << 6))) +       \
+       (!!((w) & (1ULL << 7))) )
+
+#define __const_hweight16(w) (__const_hweight8(w)  + __const_hweight8((w)  >> 8 ))
+#define __const_hweight32(w) (__const_hweight16(w) + __const_hweight16((w) >> 16))
+#define __const_hweight64(w) (__const_hweight32(w) + __const_hweight32((w) >> 32))
+
+/*
+ * Generic interface.
+ */
+#define hweight8(w)  (__builtin_constant_p(w) ? __const_hweight8(w)  : __arch_hweight8(w))
+#define hweight16(w) (__builtin_constant_p(w) ? __const_hweight16(w) : __arch_hweight16(w))
+#define hweight32(w) (__builtin_constant_p(w) ? __const_hweight32(w) : __arch_hweight32(w))
+#define hweight64(w) (__builtin_constant_p(w) ? __const_hweight64(w) : __arch_hweight64(w))
+
+/*
+ * Interface for known constant arguments
+ */
+#define HWEIGHT8(w)  (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight8(w))
+#define HWEIGHT16(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight16(w))
+#define HWEIGHT32(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight32(w))
+#define HWEIGHT64(w) (BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) + __const_hweight64(w))
+
+/*
+ * Type invariant interface to the compile time constant hweight functions.
+ */
+#define HWEIGHT(w)   HWEIGHT64((u64)w)
+
+#endif /* _ASM_GENERIC_BITOPS_CONST_HWEIGHT_H_ */
index fbbc383..a94d651 100644 (file)
@@ -1,11 +1,7 @@
 #ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_
 #define _ASM_GENERIC_BITOPS_HWEIGHT_H_
 
-#include <asm/types.h>
-
-extern unsigned int hweight32(unsigned int w);
-extern unsigned int hweight16(unsigned int w);
-extern unsigned int hweight8(unsigned int w);
-extern unsigned long hweight64(__u64 w);
+#include <asm-generic/bitops/arch_hweight.h>
+#include <asm-generic/bitops/const_hweight.h>
 
 #endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
index b926afe..3da73f5 100644 (file)
@@ -116,11 +116,12 @@ extern unsigned long acpi_realmode_flags;
 
 int acpi_register_gsi (struct device *dev, u32 gsi, int triggering, int polarity);
 int acpi_gsi_to_irq (u32 gsi, unsigned int *irq);
+int acpi_isa_irq_to_gsi (unsigned isa_irq, u32 *gsi);
 
 #ifdef CONFIG_X86_IO_APIC
-extern int acpi_get_override_irq(int bus_irq, int *trigger, int *polarity);
+extern int acpi_get_override_irq(u32 gsi, int *trigger, int *polarity);
 #else
-#define acpi_get_override_irq(bus, trigger, polarity) (-1)
+#define acpi_get_override_irq(gsi, trigger, polarity) (-1)
 #endif
 /*
  * This function undoes the effect of one call to acpi_register_gsi().
diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h
new file mode 100644 (file)
index 0000000..f7dd576
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * AHCI SATA platform driver
+ *
+ * Copyright 2004-2005  Red Hat, Inc.
+ *   Jeff Garzik <jgarzik@pobox.com>
+ * Copyright 2010  MontaVista Software, LLC.
+ *   Anton Vorontsov <avorontsov@ru.mvista.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, or (at your option)
+ * any later version.
+ */
+
+#ifndef _AHCI_PLATFORM_H
+#define _AHCI_PLATFORM_H
+
+struct device;
+struct ata_port_info;
+
+struct ahci_platform_data {
+       int (*init)(struct device *dev);
+       void (*exit)(struct device *dev);
+       const struct ata_port_info *ata_port_info;
+       unsigned int force_port_map;
+       unsigned int mask_port_map;
+};
+
+#endif /* _AHCI_PLATFORM_H */
index 6b42417..7e466fe 100644 (file)
@@ -6,8 +6,29 @@
 
 #include <linux/mmc/host.h>
 
+/**
+ * struct mmci_platform_data - platform configuration for the MMCI
+ * (also known as PL180) block.
+ * @f_max: the maximum operational frequency for this host in this
+ * platform configuration. When this is specified it takes precedence
+ * over the module parameter for the same frequency.
+ * @ocr_mask: available voltages on the 4 pins from the block, this
+ * is ignored if a regulator is used, see the MMC_VDD_* masks in
+ * mmc/host.h
+ * @translate_vdd: a callback function to translate a MMC_VDD_*
+ * mask into a value to be binary or:ed and written into the
+ * MMCIPWR register of the block
+ * @status: if no GPIO read function was given to the block in
+ * gpio_wp (below) this function will be called to determine
+ * whether a card is present in the MMC slot or not
+ * @gpio_wp: read this GPIO pin to see if the card is write protected
+ * @gpio_cd: read this GPIO pin to detect card insertion
+ * @capabilities: the capabilities of the block as implemented in
+ * this platform, signify anything MMC_CAP_* from mmc/host.h
+ */
 struct mmci_platform_data {
-       unsigned int ocr_mask;                  /* available voltages */
+       unsigned int f_max;
+       unsigned int ocr_mask;
        u32 (*translate_vdd)(struct device *, unsigned int);
        unsigned int (*status)(struct device *);
        int     gpio_wp;
index 700c5b9..fe6e681 100644 (file)
@@ -467,7 +467,7 @@ enum ata_ioctls {
 
 /* core structures */
 
-struct ata_prd {
+struct ata_bmdma_prd {
        __le32                  addr;
        __le32                  flags_len;
 };
index b796eab..fc68053 100644 (file)
 #define BITS_TO_LONGS(nr)      DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 #endif
 
+extern unsigned int __sw_hweight8(unsigned int w);
+extern unsigned int __sw_hweight16(unsigned int w);
+extern unsigned int __sw_hweight32(unsigned int w);
+extern unsigned long __sw_hweight64(__u64 w);
+
 /*
  * Include this here because some architectures need generic_ffs/fls in
  * scope
@@ -44,31 +49,6 @@ static inline unsigned long hweight_long(unsigned long w)
        return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
 }
 
-/*
- * Clearly slow versions of the hweightN() functions, their benefit is
- * of course compile time evaluation of constant arguments.
- */
-#define HWEIGHT8(w)                                    \
-      (        BUILD_BUG_ON_ZERO(!__builtin_constant_p(w)) +   \
-       (!!((w) & (1ULL << 0))) +                       \
-       (!!((w) & (1ULL << 1))) +                       \
-       (!!((w) & (1ULL << 2))) +                       \
-       (!!((w) & (1ULL << 3))) +                       \
-       (!!((w) & (1ULL << 4))) +                       \
-       (!!((w) & (1ULL << 5))) +                       \
-       (!!((w) & (1ULL << 6))) +                       \
-       (!!((w) & (1ULL << 7))) )
-
-#define HWEIGHT16(w) (HWEIGHT8(w)  + HWEIGHT8((w) >> 8))
-#define HWEIGHT32(w) (HWEIGHT16(w) + HWEIGHT16((w) >> 16))
-#define HWEIGHT64(w) (HWEIGHT32(w) + HWEIGHT32((w) >> 32))
-
-/*
- * Type invariant version that simply casts things to the
- * largest type.
- */
-#define HWEIGHT(w)   HWEIGHT64((u64)(w))
-
 /**
  * rol32 - rotate a 32-bit value left
  * @word: value to rotate
index 4bca8b6..5ea3c60 100644 (file)
@@ -273,7 +273,6 @@ static inline s64 clocksource_cyc2ns(cycle_t cycles, u32 mult, u32 shift)
 }
 
 
-/* used to install a new clocksource */
 extern int clocksource_register(struct clocksource*);
 extern void clocksource_unregister(struct clocksource*);
 extern void clocksource_touch_watchdog(void);
@@ -287,6 +286,24 @@ extern void clocksource_mark_unstable(struct clocksource *cs);
 extern void
 clocks_calc_mult_shift(u32 *mult, u32 *shift, u32 from, u32 to, u32 minsec);
 
+/*
+ * Don't call __clocksource_register_scale directly, use
+ * clocksource_register_hz/khz
+ */
+extern int
+__clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq);
+
+static inline int clocksource_register_hz(struct clocksource *cs, u32 hz)
+{
+       return __clocksource_register_scale(cs, 1, hz);
+}
+
+static inline int clocksource_register_khz(struct clocksource *cs, u32 khz)
+{
+       return __clocksource_register_scale(cs, 1000, khz);
+}
+
+
 static inline void
 clocksource_calc_mult_shift(struct clocksource *cs, u32 freq, u32 minsec)
 {
index 4de02b1..9f15150 100644 (file)
@@ -278,6 +278,27 @@ struct freq_attr {
        ssize_t (*store)(struct cpufreq_policy *, const char *, size_t count);
 };
 
+#define cpufreq_freq_attr_ro(_name)            \
+static struct freq_attr _name =                        \
+__ATTR(_name, 0444, show_##_name, NULL)
+
+#define cpufreq_freq_attr_ro_perm(_name, _perm)        \
+static struct freq_attr _name =                        \
+__ATTR(_name, _perm, show_##_name, NULL)
+
+#define cpufreq_freq_attr_ro_old(_name)                \
+static struct freq_attr _name##_old =          \
+__ATTR(_name, 0444, show_##_name##_old, NULL)
+
+#define cpufreq_freq_attr_rw(_name)            \
+static struct freq_attr _name =                        \
+__ATTR(_name, 0644, show_##_name, store_##_name)
+
+#define cpufreq_freq_attr_rw_old(_name)                \
+static struct freq_attr _name##_old =          \
+__ATTR(_name, 0644, show_##_name##_old, store_##_name##_old)
+
+
 struct global_attr {
        struct attribute attr;
        ssize_t (*show)(struct kobject *kobj,
@@ -286,6 +307,15 @@ struct global_attr {
                         const char *c, size_t count);
 };
 
+#define define_one_global_ro(_name)            \
+static struct global_attr _name =              \
+__ATTR(_name, 0444, show_##_name, NULL)
+
+#define define_one_global_rw(_name)            \
+static struct global_attr _name =              \
+__ATTR(_name, 0644, show_##_name, store_##_name)
+
+
 /*********************************************************************
  *                        CPUFREQ 2.6. INTERFACE                     *
  *********************************************************************/
index a5740fc..a73454a 100644 (file)
@@ -21,8 +21,7 @@ extern int number_of_cpusets; /* How many cpusets are defined in system? */
 extern int cpuset_init(void);
 extern void cpuset_init_smp(void);
 extern void cpuset_cpus_allowed(struct task_struct *p, struct cpumask *mask);
-extern void cpuset_cpus_allowed_locked(struct task_struct *p,
-                                      struct cpumask *mask);
+extern int cpuset_cpus_allowed_fallback(struct task_struct *p);
 extern nodemask_t cpuset_mems_allowed(struct task_struct *p);
 #define cpuset_current_mems_allowed (current->mems_allowed)
 void cpuset_init_current_mems_allowed(void);
@@ -69,9 +68,6 @@ struct seq_file;
 extern void cpuset_task_status_allowed(struct seq_file *m,
                                        struct task_struct *task);
 
-extern void cpuset_lock(void);
-extern void cpuset_unlock(void);
-
 extern int cpuset_mem_spread_node(void);
 
 static inline int cpuset_do_page_mem_spread(void)
@@ -105,10 +101,11 @@ static inline void cpuset_cpus_allowed(struct task_struct *p,
 {
        cpumask_copy(mask, cpu_possible_mask);
 }
-static inline void cpuset_cpus_allowed_locked(struct task_struct *p,
-                                             struct cpumask *mask)
+
+static inline int cpuset_cpus_allowed_fallback(struct task_struct *p)
 {
-       cpumask_copy(mask, cpu_possible_mask);
+       cpumask_copy(&p->cpus_allowed, cpu_possible_mask);
+       return cpumask_any(cpu_active_mask);
 }
 
 static inline nodemask_t cpuset_mems_allowed(struct task_struct *p)
@@ -157,9 +154,6 @@ static inline void cpuset_task_status_allowed(struct seq_file *m,
 {
 }
 
-static inline void cpuset_lock(void) {}
-static inline void cpuset_unlock(void) {}
-
 static inline int cpuset_mem_spread_node(void)
 {
        return 0;
index 8c243aa..597692f 100644 (file)
@@ -20,12 +20,14 @@ struct debug_obj_descr;
  * struct debug_obj - representaion of an tracked object
  * @node:      hlist node to link the object into the tracker list
  * @state:     tracked object state
+ * @astate:    current active state
  * @object:    pointer to the real object
  * @descr:     pointer to an object type specific debug description structure
  */
 struct debug_obj {
        struct hlist_node       node;
        enum debug_obj_state    state;
+       unsigned int            astate;
        void                    *object;
        struct debug_obj_descr  *descr;
 };
@@ -60,6 +62,15 @@ extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
 extern void debug_object_destroy   (void *addr, struct debug_obj_descr *descr);
 extern void debug_object_free      (void *addr, struct debug_obj_descr *descr);
 
+/*
+ * Active state:
+ * - Set at 0 upon initialization.
+ * - Must return to 0 before deactivation.
+ */
+extern void
+debug_object_active_state(void *addr, struct debug_obj_descr *descr,
+                         unsigned int expect, unsigned int next);
+
 extern void debug_objects_early_init(void);
 extern void debug_objects_mem_init(void);
 #else
index 1821928..241b96b 100644 (file)
@@ -451,6 +451,10 @@ struct device {
 
 static inline const char *dev_name(const struct device *dev)
 {
+       /* Use the init name until the kobject becomes available */
+       if (dev->init_name)
+               return dev->init_name;
+
        return kobject_name(&dev->kobj);
 }
 
index 5978584..4d60801 100644 (file)
@@ -394,6 +394,7 @@ typedef struct elf64_shdr {
 #define NT_S390_TODPREG        0x303           /* s390 TOD programmable register */
 #define NT_S390_CTRS   0x304           /* s390 control registers */
 #define NT_S390_PREFIX 0x305           /* s390 prefix register */
+#define NT_S390_LAST_BREAK     0x306   /* s390 breaking event address */
 
 
 /* Note header in a PT_NOTE section */
index 44f35ae..948bd2b 100644 (file)
@@ -2362,6 +2362,8 @@ extern void simple_release_fs(struct vfsmount **mount, int *count);
 
 extern ssize_t simple_read_from_buffer(void __user *to, size_t count,
                        loff_t *ppos, const void *from, size_t available);
+extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos,
+               const void __user *from, size_t count);
 
 extern int simple_fsync(struct file *, struct dentry *, int);
 
index 01e6ade..41e4633 100644 (file)
@@ -82,9 +82,13 @@ void clear_ftrace_function(void);
 extern void ftrace_stub(unsigned long a0, unsigned long a1);
 
 #else /* !CONFIG_FUNCTION_TRACER */
-# define register_ftrace_function(ops) do { } while (0)
-# define unregister_ftrace_function(ops) do { } while (0)
-# define clear_ftrace_function(ops) do { } while (0)
+/*
+ * (un)register_ftrace_function must be a macro since the ops parameter
+ * must not be evaluated.
+ */
+#define register_ftrace_function(ops) ({ 0; })
+#define unregister_ftrace_function(ops) ({ 0; })
+static inline void clear_ftrace_function(void) { }
 static inline void ftrace_kill(void) { }
 static inline void ftrace_stop(void) { }
 static inline void ftrace_start(void) { }
@@ -237,11 +241,13 @@ extern int skip_trace(unsigned long ip);
 extern void ftrace_disable_daemon(void);
 extern void ftrace_enable_daemon(void);
 #else
-# define skip_trace(ip)                                ({ 0; })
-# define ftrace_force_update()                 ({ 0; })
-# define ftrace_set_filter(buf, len, reset)    do { } while (0)
-# define ftrace_disable_daemon()               do { } while (0)
-# define ftrace_enable_daemon()                        do { } while (0)
+static inline int skip_trace(unsigned long ip) { return 0; }
+static inline int ftrace_force_update(void) { return 0; }
+static inline void ftrace_set_filter(unsigned char *buf, int len, int reset)
+{
+}
+static inline void ftrace_disable_daemon(void) { }
+static inline void ftrace_enable_daemon(void) { }
 static inline void ftrace_release_mod(struct module *mod) {}
 static inline int register_ftrace_command(struct ftrace_func_command *cmd)
 {
@@ -314,16 +320,16 @@ static inline void __ftrace_enabled_restore(int enabled)
   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
   extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
 #else
-# define time_hardirqs_on(a0, a1)              do { } while (0)
-# define time_hardirqs_off(a0, a1)             do { } while (0)
+  static inline void time_hardirqs_on(unsigned long a0, unsigned long a1) { }
+  static inline void time_hardirqs_off(unsigned long a0, unsigned long a1) { }
 #endif
 
 #ifdef CONFIG_PREEMPT_TRACER
   extern void trace_preempt_on(unsigned long a0, unsigned long a1);
   extern void trace_preempt_off(unsigned long a0, unsigned long a1);
 #else
-# define trace_preempt_on(a0, a1)              do { } while (0)
-# define trace_preempt_off(a0, a1)             do { } while (0)
+  static inline void trace_preempt_on(unsigned long a0, unsigned long a1) { }
+  static inline void trace_preempt_off(unsigned long a0, unsigned long a1) { }
 #endif
 
 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
@@ -352,6 +358,10 @@ struct ftrace_graph_ret {
        int depth;
 };
 
+/* Type of the callback handlers for tracing function graph*/
+typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
+typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
+
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
 
 /* for init task */
@@ -400,10 +410,6 @@ extern char __irqentry_text_end[];
 
 #define FTRACE_RETFUNC_DEPTH 50
 #define FTRACE_RETSTACK_ALLOC_SIZE 32
-/* Type of the callback handlers for tracing function graph*/
-typedef void (*trace_func_graph_ret_t)(struct ftrace_graph_ret *); /* return */
-typedef int (*trace_func_graph_ent_t)(struct ftrace_graph_ent *); /* entry */
-
 extern int register_ftrace_graph(trace_func_graph_ret_t retfunc,
                                trace_func_graph_ent_t entryfunc);
 
@@ -441,6 +447,13 @@ static inline void unpause_graph_tracing(void)
 static inline void ftrace_graph_init_task(struct task_struct *t) { }
 static inline void ftrace_graph_exit_task(struct task_struct *t) { }
 
+static inline int register_ftrace_graph(trace_func_graph_ret_t retfunc,
+                         trace_func_graph_ent_t entryfunc)
+{
+       return -1;
+}
+static inline void unregister_ftrace_graph(void) { }
+
 static inline int task_curr_ret_stack(struct task_struct *tsk)
 {
        return -1;
@@ -492,7 +505,9 @@ static inline int test_tsk_trace_graph(struct task_struct *tsk)
        return tsk->trace & TSK_TRACE_FL_GRAPH;
 }
 
-extern int ftrace_dump_on_oops;
+enum ftrace_dump_mode;
+
+extern enum ftrace_dump_mode ftrace_dump_on_oops;
 
 #ifdef CONFIG_PREEMPT
 #define INIT_TRACE_RECURSION           .trace_recursion = 0,
@@ -504,18 +519,6 @@ extern int ftrace_dump_on_oops;
 #define INIT_TRACE_RECURSION
 #endif
 
-#ifdef CONFIG_HW_BRANCH_TRACER
-
-void trace_hw_branch(u64 from, u64 to);
-void trace_hw_branch_oops(void);
-
-#else /* CONFIG_HW_BRANCH_TRACER */
-
-static inline void trace_hw_branch(u64 from, u64 to) {}
-static inline void trace_hw_branch_oops(void) {}
-
-#endif /* CONFIG_HW_BRANCH_TRACER */
-
 #ifdef CONFIG_FTRACE_SYSCALLS
 
 unsigned long arch_syscall_addr(int nr);
index c0f4b36..39e71b0 100644 (file)
@@ -58,6 +58,7 @@ struct trace_iterator {
        /* The below is zeroed out in pipe_read */
        struct trace_seq        seq;
        struct trace_entry      *ent;
+       unsigned long           lost_events;
        int                     leftover;
        int                     cpu;
        u64                     ts;
index 5d86fb2..fd0c1b8 100644 (file)
@@ -422,6 +422,8 @@ extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
 
 extern int schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
                                                const enum hrtimer_mode mode);
+extern int schedule_hrtimeout_range_clock(ktime_t *expires,
+               unsigned long delta, const enum hrtimer_mode mode, int clock);
 extern int schedule_hrtimeout(ktime_t *expires, const enum hrtimer_mode mode);
 
 /* Soft interrupt function to run the hrtimer queues: */
index c70d27a..a2d6ea4 100644 (file)
@@ -9,9 +9,22 @@ enum {
 };
 
 enum {
-       HW_BREAKPOINT_R = 1,
-       HW_BREAKPOINT_W = 2,
-       HW_BREAKPOINT_X = 4,
+       HW_BREAKPOINT_EMPTY     = 0,
+       HW_BREAKPOINT_R         = 1,
+       HW_BREAKPOINT_W         = 2,
+       HW_BREAKPOINT_RW        = HW_BREAKPOINT_R | HW_BREAKPOINT_W,
+       HW_BREAKPOINT_X         = 4,
+       HW_BREAKPOINT_INVALID   = HW_BREAKPOINT_RW | HW_BREAKPOINT_X,
+};
+
+enum bp_type_idx {
+       TYPE_INST       = 0,
+#ifdef CONFIG_HAVE_MIXED_BREAKPOINTS_REGS
+       TYPE_DATA       = 0,
+#else
+       TYPE_DATA       = 1,
+#endif
+       TYPE_MAX
 };
 
 #ifdef __KERNEL__
@@ -34,6 +47,12 @@ static inline void hw_breakpoint_init(struct perf_event_attr *attr)
        attr->sample_period = 1;
 }
 
+static inline void ptrace_breakpoint_init(struct perf_event_attr *attr)
+{
+       hw_breakpoint_init(attr);
+       attr->exclude_kernel = 1;
+}
+
 static inline unsigned long hw_breakpoint_addr(struct perf_event *bp)
 {
        return bp->attr.bp_addr;
diff --git a/include/linux/i2c-omap.h b/include/linux/i2c-omap.h
new file mode 100644 (file)
index 0000000..78ebf50
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __I2C_OMAP_H__
+#define __I2C_OMAP_H__
+
+struct omap_i2c_bus_platform_data {
+       u32             clkrate;
+       void            (*set_mpu_wkup_lat)(struct device *dev, long set);
+};
+
+#endif
index fb6784e..6de90bf 100644 (file)
@@ -496,7 +496,7 @@ struct twl4030_madc_platform_data {
        int             irq_line;
 };
 
-/* Boards have uniqe mappings of {row, col} --> keycode.
+/* Boards have unique mappings of {row, col} --> keycode.
  * Column and row are 8 bits each, but range only from 0..7.
  * a PERSISTENT_KEY is "always on" and never reported.
  */
@@ -569,9 +569,9 @@ struct twl4030_codec_data {
        struct twl4030_codec_audio_data         *audio;
        struct twl4030_codec_vibra_data         *vibra;
 
-       /* twl6030 */
-       int audpwron_gpio;      /* audio power-on gpio */
-       int naudint_irq;        /* audio interrupt */
+       /* twl6040 */
+       int audpwron_gpio;      /* audio power-on gpio */
+       int naudint_irq;        /* audio interrupt */
 };
 
 struct twl4030_platform_data {
@@ -664,15 +664,15 @@ static inline int twl4030charger_usb_en(int enable) { return 0; }
 #define TWL4030_REG_VUSB3V1    19
 
 /* TWL6030 SMPS/LDO's */
-/* EXTERNAL dc-to-dc buck convertor contollable via SR */
+/* EXTERNAL dc-to-dc buck convertor controllable via SR */
 #define TWL6030_REG_VDD1       30
 #define TWL6030_REG_VDD2       31
 #define TWL6030_REG_VDD3       32
 
 /* Non SR compliant dc-to-dc buck convertors */
-#define        TWL6030_REG_VMEM        33
+#define TWL6030_REG_VMEM       33
 #define TWL6030_REG_V2V1       34
-#define        TWL6030_REG_V1V29       35
+#define TWL6030_REG_V1V29      35
 #define TWL6030_REG_V1V8       36
 
 /* EXTERNAL LDOs */
index b1ed1cd..7996fc2 100644 (file)
@@ -49,7 +49,6 @@ extern struct group_info init_groups;
                { .first = &init_task.pids[PIDTYPE_PGID].node },        \
                { .first = &init_task.pids[PIDTYPE_SID].node },         \
        },                                                              \
-       .rcu            = RCU_HEAD_INIT,                                \
        .level          = 0,                                            \
        .numbers        = { {                                           \
                .nr             = 0,                                    \
index 75f3f00..5137db3 100644 (file)
@@ -39,7 +39,8 @@
  * These flags used only by the kernel as part of the
  * irq handling routines.
  *
- * IRQF_DISABLED - keep irqs disabled when calling the action handler
+ * IRQF_DISABLED - keep irqs disabled when calling the action handler.
+ *                 DEPRECATED. This flag is a NOOP and scheduled to be removed
  * IRQF_SAMPLE_RANDOM - irq is used to feed the random generator
  * IRQF_SHARED - allow sharing the irq among several devices
  * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
@@ -77,6 +78,18 @@ enum {
        IRQTF_AFFINITY,
 };
 
+/**
+ * These values can be returned by request_any_context_irq() and
+ * describe the context the interrupt will be run in.
+ *
+ * IRQC_IS_HARDIRQ - interrupt runs in hardirq context
+ * IRQC_IS_NESTED - interrupt runs in a nested threaded context
+ */
+enum {
+       IRQC_IS_HARDIRQ = 0,
+       IRQC_IS_NESTED,
+};
+
 typedef irqreturn_t (*irq_handler_t)(int, void *);
 
 /**
@@ -120,6 +133,10 @@ request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
        return request_threaded_irq(irq, handler, NULL, flags, name, dev);
 }
 
+extern int __must_check
+request_any_context_irq(unsigned int irq, irq_handler_t handler,
+                       unsigned long flags, const char *name, void *dev_id);
+
 extern void exit_irq_thread(void);
 #else
 
@@ -141,6 +158,13 @@ request_threaded_irq(unsigned int irq, irq_handler_t handler,
        return request_irq(irq, handler, flags, name, dev);
 }
 
+static inline int __must_check
+request_any_context_irq(unsigned int irq, irq_handler_t handler,
+                       unsigned long flags, const char *name, void *dev_id)
+{
+       return request_irq(irq, handler, flags, name, dev_id);
+}
+
 static inline void exit_irq_thread(void) { }
 #endif
 
@@ -209,6 +233,7 @@ extern int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask);
 extern int irq_can_set_affinity(unsigned int irq);
 extern int irq_select_affinity(unsigned int irq);
 
+extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
 #else /* CONFIG_SMP */
 
 static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
@@ -223,6 +248,11 @@ static inline int irq_can_set_affinity(unsigned int irq)
 
 static inline int irq_select_affinity(unsigned int irq)  { return 0; }
 
+static inline int irq_set_affinity_hint(unsigned int irq,
+                                        const struct cpumask *m)
+{
+       return -EINVAL;
+}
 #endif /* CONFIG_SMP && CONFIG_GENERIC_HARDIRQS */
 
 #ifdef CONFIG_GENERIC_HARDIRQS
index 3af4ffd..be22ad8 100644 (file)
@@ -37,9 +37,9 @@ struct iommu_ops {
        int (*attach_dev)(struct iommu_domain *domain, struct device *dev);
        void (*detach_dev)(struct iommu_domain *domain, struct device *dev);
        int (*map)(struct iommu_domain *domain, unsigned long iova,
-                  phys_addr_t paddr, size_t size, int prot);
-       void (*unmap)(struct iommu_domain *domain, unsigned long iova,
-                     size_t size);
+                  phys_addr_t paddr, int gfp_order, int prot);
+       int (*unmap)(struct iommu_domain *domain, unsigned long iova,
+                    int gfp_order);
        phys_addr_t (*iova_to_phys)(struct iommu_domain *domain,
                                    unsigned long iova);
        int (*domain_has_cap)(struct iommu_domain *domain,
@@ -56,10 +56,10 @@ extern int iommu_attach_device(struct iommu_domain *domain,
                               struct device *dev);
 extern void iommu_detach_device(struct iommu_domain *domain,
                                struct device *dev);
-extern int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
-                          phys_addr_t paddr, size_t size, int prot);
-extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
-                             size_t size);
+extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
+                    phys_addr_t paddr, int gfp_order, int prot);
+extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
+                      int gfp_order);
 extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
                                      unsigned long iova);
 extern int iommu_domain_has_cap(struct iommu_domain *domain,
@@ -96,16 +96,16 @@ static inline void iommu_detach_device(struct iommu_domain *domain,
 {
 }
 
-static inline int iommu_map_range(struct iommu_domain *domain,
-                                 unsigned long iova, phys_addr_t paddr,
-                                 size_t size, int prot)
+static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
+                           phys_addr_t paddr, int gfp_order, int prot)
 {
        return -ENODEV;
 }
 
-static inline void iommu_unmap_range(struct iommu_domain *domain,
-                                    unsigned long iova, size_t size)
+static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
+                             int gfp_order)
 {
+       return -ENODEV;
 }
 
 static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
index 707ab12..c03243a 100644 (file)
@@ -195,6 +195,7 @@ struct irq_desc {
        raw_spinlock_t          lock;
 #ifdef CONFIG_SMP
        cpumask_var_t           affinity;
+       const struct cpumask    *affinity_hint;
        unsigned int            node;
 #ifdef CONFIG_GENERIC_PENDING_IRQ
        cpumask_var_t           pending_mask;
index 9365227..9fb1c12 100644 (file)
@@ -490,6 +490,13 @@ static inline void tracing_off(void) { }
 static inline void tracing_off_permanent(void) { }
 static inline int tracing_is_on(void) { return 0; }
 #endif
+
+enum ftrace_dump_mode {
+       DUMP_NONE,
+       DUMP_ALL,
+       DUMP_ORIG,
+};
+
 #ifdef CONFIG_TRACING
 extern void tracing_start(void);
 extern void tracing_stop(void);
@@ -571,7 +578,7 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
 extern int
 __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
 
-extern void ftrace_dump(void);
+extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
 #else
 static inline void
 ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
@@ -592,7 +599,7 @@ ftrace_vprintk(const char *fmt, va_list ap)
 {
        return 0;
 }
-static inline void ftrace_dump(void) { }
+static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
 #endif /* CONFIG_TRACING */
 
 /*
index e117b1a..9fad052 100644 (file)
@@ -201,7 +201,7 @@ static inline __must_check unsigned int kfifo_avail(struct kfifo *fifo)
  * @n: the length of the data to be added.
  * @lock: pointer to the spinlock to use for locking.
  *
- * This function copies at most @len bytes from the @from buffer into
+ * This function copies at most @n bytes from the @from buffer into
  * the FIFO depending on the free space, and returns the number of
  * bytes copied.
  */
@@ -227,7 +227,7 @@ static inline unsigned int kfifo_in_locked(struct kfifo *fifo,
  * @n: the size of the destination buffer.
  * @lock: pointer to the spinlock to use for locking.
  *
- * This function copies at most @len bytes from the FIFO into the
+ * This function copies at most @n bytes from the FIFO into the
  * @to buffer and returns the number of copied bytes.
  */
 static inline __must_check unsigned int kfifo_out_locked(struct kfifo *fifo,
index 73717ed..18ca75f 100644 (file)
@@ -1,3 +1,10 @@
+/*
+ * kobj_map.h
+ */
+
+#ifndef _KOBJ_MAP_H_
+#define _KOBJ_MAP_H_
+
 #include <linux/mutex.h>
 
 typedef struct kobject *kobj_probe_t(dev_t, int *, void *);
@@ -8,3 +15,5 @@ int kobj_map(struct kobj_map *, dev_t, unsigned long, struct module *,
 void kobj_unmap(struct kobj_map *, dev_t, unsigned long);
 struct kobject *kobj_lookup(struct kobj_map *, dev_t, int *);
 struct kobj_map *kobj_map_init(kobj_probe_t *, struct mutex *);
+
+#endif /* _KOBJ_MAP_H_ */
index b0cb0eb..baf4b9e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * kref.c - library routines for handling generic reference counted objects
+ * kref.h - library routines for handling generic reference counted objects
  *
  * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2004 IBM Corp.
index ce59832..e1ceaa9 100644 (file)
@@ -130,7 +130,7 @@ static inline ktime_t timeval_to_ktime(struct timeval tv)
 /* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */
 #define ktime_to_ns(kt)                        ((kt).tv64)
 
-#else
+#else  /* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */
 
 /*
  * Helper macros/inlines to get the ktime_t math right in the timespec
@@ -275,7 +275,7 @@ static inline s64 ktime_to_ns(const ktime_t kt)
        return (s64) kt.tv.sec * NSEC_PER_SEC + kt.tv.nsec;
 }
 
-#endif
+#endif /* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */
 
 /**
  * ktime_equal - Compares two ktime_t variables to see if they are equal
@@ -295,6 +295,12 @@ static inline s64 ktime_to_us(const ktime_t kt)
        return (s64) tv.tv_sec * USEC_PER_SEC + tv.tv_usec;
 }
 
+static inline s64 ktime_to_ms(const ktime_t kt)
+{
+       struct timeval tv = ktime_to_timeval(kt);
+       return (s64) tv.tv_sec * MSEC_PER_SEC + tv.tv_usec / USEC_PER_MSEC;
+}
+
 static inline s64 ktime_us_delta(const ktime_t later, const ktime_t earlier)
 {
        return ktime_to_us(ktime_sub(later, earlier));
index b2f2003..ee84e7e 100644 (file)
@@ -202,12 +202,6 @@ enum {
        ATA_FLAG_SW_ACTIVITY    = (1 << 22), /* driver supports sw activity
                                              * led */
 
-       /* The following flag belongs to ap->pflags but is kept in
-        * ap->flags because it's referenced in many LLDs and will be
-        * removed in not-too-distant future.
-        */
-       ATA_FLAG_DISABLED       = (1 << 23), /* port is disabled, ignore it */
-
        /* bits 24:31 of ap->flags are reserved for LLD specific flags */
 
 
@@ -256,12 +250,13 @@ enum {
        ATA_TMOUT_INTERNAL_QUICK = 5000,
        ATA_TMOUT_MAX_PARK      = 30000,
 
-       /* FIXME: GoVault needs 2s but we can't afford that without
-        * parallel probing.  800ms is enough for iVDR disk
-        * HHD424020F7SV00.  Increase to 2secs when parallel probing
-        * is in place.
+       /*
+        * GoVault needs 2s and iVDR disk HHD424020F7SV00 800ms.  2s
+        * is too much without parallel probing.  Use 2s if parallel
+        * probing is available, 800ms otherwise.
         */
-       ATA_TMOUT_FF_WAIT       =  800,
+       ATA_TMOUT_FF_WAIT_LONG  =  2000,
+       ATA_TMOUT_FF_WAIT       =   800,
 
        /* Spec mandates to wait for ">= 2ms" before checking status
         * after reset.  We wait 150ms, because that was the magic
@@ -721,15 +716,15 @@ struct ata_port {
        unsigned int            print_id; /* user visible unique port ID */
        unsigned int            port_no; /* 0 based port no. inside the host */
 
-       struct ata_prd          *prd;    /* our SG list */
-       dma_addr_t              prd_dma; /* and its DMA mapping */
-
 #ifdef CONFIG_ATA_SFF
        struct ata_ioports      ioaddr; /* ATA cmd/ctl/dma register blocks */
-#endif /* CONFIG_ATA_SFF */
-
        u8                      ctl;    /* cache of ATA control register */
        u8                      last_ctl;       /* Cache last written value */
+       struct delayed_work     sff_pio_task;
+       struct ata_bmdma_prd    *bmdma_prd;     /* BMDMA SG list */
+       dma_addr_t              bmdma_prd_dma;  /* and its DMA mapping */
+#endif /* CONFIG_ATA_SFF */
+
        unsigned int            pio_mask;
        unsigned int            mwdma_mask;
        unsigned int            udma_mask;
@@ -751,8 +746,6 @@ struct ata_port {
        struct ata_host         *host;
        struct device           *dev;
 
-       void                    *port_task_data;
-       struct delayed_work     port_task;
        struct delayed_work     hotplug_task;
        struct work_struct      scsi_rescan_task;
 
@@ -849,6 +842,7 @@ struct ata_port_operations {
         * SFF / taskfile oriented ops
         */
        void (*sff_dev_select)(struct ata_port *ap, unsigned int device);
+       void (*sff_set_devctl)(struct ata_port *ap, u8 ctl);
        u8   (*sff_check_status)(struct ata_port *ap);
        u8   (*sff_check_altstatus)(struct ata_port *ap);
        void (*sff_tf_load)(struct ata_port *ap, const struct ata_taskfile *tf);
@@ -857,16 +851,15 @@ struct ata_port_operations {
                                 const struct ata_taskfile *tf);
        unsigned int (*sff_data_xfer)(struct ata_device *dev,
                        unsigned char *buf, unsigned int buflen, int rw);
-       u8   (*sff_irq_on)(struct ata_port *);
+       void (*sff_irq_on)(struct ata_port *);
        bool (*sff_irq_check)(struct ata_port *);
        void (*sff_irq_clear)(struct ata_port *);
+       void (*sff_drain_fifo)(struct ata_queued_cmd *qc);
 
        void (*bmdma_setup)(struct ata_queued_cmd *qc);
        void (*bmdma_start)(struct ata_queued_cmd *qc);
        void (*bmdma_stop)(struct ata_queued_cmd *qc);
        u8   (*bmdma_status)(struct ata_port *ap);
-
-       void (*drain_fifo)(struct ata_queued_cmd *qc);
 #endif /* CONFIG_ATA_SFF */
 
        ssize_t (*em_show)(struct ata_port *ap, char *buf);
@@ -935,7 +928,6 @@ static inline int ata_port_is_dummy(struct ata_port *ap)
        return ap->ops == &ata_dummy_port_ops;
 }
 
-extern void ata_port_probe(struct ata_port *);
 extern int sata_set_spd(struct ata_link *link);
 extern int ata_std_prereset(struct ata_link *link, unsigned long deadline);
 extern int ata_wait_after_reset(struct ata_link *link, unsigned long deadline,
@@ -950,7 +942,6 @@ extern int sata_link_hardreset(struct ata_link *link,
 extern int sata_std_hardreset(struct ata_link *link, unsigned int *class,
                              unsigned long deadline);
 extern void ata_std_postreset(struct ata_link *link, unsigned int *classes);
-extern void ata_port_disable(struct ata_port *);
 
 extern struct ata_host *ata_host_alloc(struct device *dev, int max_ports);
 extern struct ata_host *ata_host_alloc_pinfo(struct device *dev,
@@ -1006,7 +997,6 @@ extern unsigned long ata_xfer_mode2mask(u8 xfer_mode);
 extern int ata_xfer_mode2shift(unsigned long xfer_mode);
 extern const char *ata_mode_string(unsigned long xfer_mask);
 extern unsigned long ata_id_xfermask(const u16 *id);
-extern int ata_port_start(struct ata_port *ap);
 extern int ata_std_qc_defer(struct ata_queued_cmd *qc);
 extern void ata_noop_qc_prep(struct ata_queued_cmd *qc);
 extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
@@ -1039,9 +1029,6 @@ extern int ata_cable_sata(struct ata_port *ap);
 extern int ata_cable_ignore(struct ata_port *ap);
 extern int ata_cable_unknown(struct ata_port *ap);
 
-extern void ata_pio_queue_task(struct ata_port *ap, void *data,
-                              unsigned long delay);
-
 /* Timing helpers */
 extern unsigned int ata_pio_need_iordy(const struct ata_device *);
 extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
@@ -1443,7 +1430,11 @@ static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
 {
        memset(tf, 0, sizeof(*tf));
 
+#ifdef CONFIG_ATA_SFF
        tf->ctl = dev->link->ap->ctl;
+#else
+       tf->ctl = ATA_DEVCTL_OBS;
+#endif
        if (dev->devno == 0)
                tf->device = ATA_DEVICE_OBS;
        else
@@ -1578,8 +1569,6 @@ extern const struct ata_port_operations ata_bmdma32_port_ops;
        .sg_tablesize           = LIBATA_MAX_PRD,               \
        .dma_boundary           = ATA_DMA_BOUNDARY
 
-extern void ata_sff_qc_prep(struct ata_queued_cmd *qc);
-extern void ata_sff_dumb_qc_prep(struct ata_queued_cmd *qc);
 extern void ata_sff_dev_select(struct ata_port *ap, unsigned int device);
 extern u8 ata_sff_check_status(struct ata_port *ap);
 extern void ata_sff_pause(struct ata_port *ap);
@@ -1597,10 +1586,11 @@ extern unsigned int ata_sff_data_xfer32(struct ata_device *dev,
                        unsigned char *buf, unsigned int buflen, int rw);
 extern unsigned int ata_sff_data_xfer_noirq(struct ata_device *dev,
                        unsigned char *buf, unsigned int buflen, int rw);
-extern u8 ata_sff_irq_on(struct ata_port *ap);
+extern void ata_sff_irq_on(struct ata_port *ap);
 extern void ata_sff_irq_clear(struct ata_port *ap);
 extern int ata_sff_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
                            u8 status, int in_wq);
+extern void ata_sff_queue_pio_task(struct ata_port *ap, unsigned long delay);
 extern unsigned int ata_sff_qc_issue(struct ata_queued_cmd *qc);
 extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
 extern unsigned int ata_sff_host_intr(struct ata_port *ap,
@@ -1621,21 +1611,8 @@ extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
 extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
 extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
 extern void ata_sff_error_handler(struct ata_port *ap);
-extern void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc);
-extern int ata_sff_port_start(struct ata_port *ap);
-extern int ata_sff_port_start32(struct ata_port *ap);
 extern void ata_sff_std_ports(struct ata_ioports *ioaddr);
-extern unsigned long ata_bmdma_mode_filter(struct ata_device *dev,
-                                          unsigned long xfer_mask);
-extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
-extern void ata_bmdma_start(struct ata_queued_cmd *qc);
-extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
-extern u8 ata_bmdma_status(struct ata_port *ap);
-extern void ata_bus_reset(struct ata_port *ap);
-
 #ifdef CONFIG_PCI
-extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
-extern int ata_pci_bmdma_init(struct ata_host *host);
 extern int ata_pci_sff_init_host(struct ata_host *host);
 extern int ata_pci_sff_prepare_host(struct pci_dev *pdev,
                                    const struct ata_port_info * const * ppi,
@@ -1648,6 +1625,23 @@ extern int ata_pci_sff_init_one(struct pci_dev *pdev,
                struct scsi_host_template *sht, void *host_priv, int hflags);
 #endif /* CONFIG_PCI */
 
+extern void ata_bmdma_qc_prep(struct ata_queued_cmd *qc);
+extern unsigned int ata_bmdma_qc_issue(struct ata_queued_cmd *qc);
+extern void ata_bmdma_dumb_qc_prep(struct ata_queued_cmd *qc);
+extern void ata_bmdma_error_handler(struct ata_port *ap);
+extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
+extern void ata_bmdma_setup(struct ata_queued_cmd *qc);
+extern void ata_bmdma_start(struct ata_queued_cmd *qc);
+extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
+extern u8 ata_bmdma_status(struct ata_port *ap);
+extern int ata_bmdma_port_start(struct ata_port *ap);
+extern int ata_bmdma_port_start32(struct ata_port *ap);
+
+#ifdef CONFIG_PCI
+extern int ata_pci_bmdma_clear_simplex(struct pci_dev *pdev);
+extern void ata_pci_bmdma_init(struct ata_host *host);
+#endif /* CONFIG_PCI */
+
 /**
  *     ata_sff_busy_wait - Wait for a port status register
  *     @ap: Port to wait for.
index f78f83d..6907251 100644 (file)
@@ -33,7 +33,7 @@ struct common_audit_data {
 #define LSM_AUDIT_DATA_IPC     4
 #define LSM_AUDIT_DATA_TASK    5
 #define LSM_AUDIT_DATA_KEY     6
-#define LSM_AUDIT_NO_AUDIT     7
+#define LSM_AUDIT_DATA_NONE    7
 #define LSM_AUDIT_DATA_KMOD    8
        struct task_struct *tsk;
        union   {
index 12010ac..0dd4995 100644 (file)
@@ -44,17 +44,17 @@ struct meye_params {
 };
 
 /* query the extended parameters */
-#define MEYEIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0, struct meye_params)
+#define MEYEIOC_G_PARAMS       _IOR ('v', BASE_VIDIOC_PRIVATE+0, struct meye_params)
 /* set the extended parameters */
-#define MEYEIOC_S_PARAMS       _IOW ('v', BASE_VIDIOCPRIVATE+1, struct meye_params)
+#define MEYEIOC_S_PARAMS       _IOW ('v', BASE_VIDIOC_PRIVATE+1, struct meye_params)
 /* queue a buffer for mjpeg capture */
-#define MEYEIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+2, int)
+#define MEYEIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOC_PRIVATE+2, int)
 /* sync a previously queued mjpeg buffer */
-#define MEYEIOC_SYNC           _IOWR('v', BASE_VIDIOCPRIVATE+3, int)
+#define MEYEIOC_SYNC           _IOWR('v', BASE_VIDIOC_PRIVATE+3, int)
 /* get a still uncompressed snapshot */
-#define MEYEIOC_STILLCAPT      _IO  ('v', BASE_VIDIOCPRIVATE+4)
+#define MEYEIOC_STILLCAPT      _IO  ('v', BASE_VIDIOC_PRIVATE+4)
 /* get a jpeg compressed snapshot */
-#define MEYEIOC_STILLJCAPT     _IOR ('v', BASE_VIDIOCPRIVATE+5, int)
+#define MEYEIOC_STILLJCAPT     _IOR ('v', BASE_VIDIOC_PRIVATE+5, int)
 
 /* V4L2 private controls */
 #define V4L2_CID_AGC           V4L2_CID_PRIVATE_BASE
diff --git a/include/linux/mfd/davinci_voicecodec.h b/include/linux/mfd/davinci_voicecodec.h
new file mode 100644 (file)
index 0000000..0ab6132
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ * DaVinci Voice Codec Core Interface for TI platforms
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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
+ */
+
+#ifndef __LINUX_MFD_DAVINCI_VOICECODEC_H_
+#define __LINUX_MFD_DAVINIC_VOICECODEC_H_
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/core.h>
+
+#include <mach/edma.h>
+
+/*
+ * Register values.
+ */
+#define DAVINCI_VC_PID                 0x00
+#define DAVINCI_VC_CTRL                        0x04
+#define DAVINCI_VC_INTEN               0x08
+#define DAVINCI_VC_INTSTATUS           0x0c
+#define DAVINCI_VC_INTCLR              0x10
+#define DAVINCI_VC_EMUL_CTRL           0x14
+#define DAVINCI_VC_RFIFO               0x20
+#define DAVINCI_VC_WFIFO               0x24
+#define DAVINCI_VC_FIFOSTAT            0x28
+#define DAVINCI_VC_TST_CTRL            0x2C
+#define DAVINCI_VC_REG05               0x94
+#define DAVINCI_VC_REG09               0xA4
+#define DAVINCI_VC_REG12               0xB0
+
+/* DAVINCI_VC_CTRL bit fields */
+#define DAVINCI_VC_CTRL_MASK           0x5500
+#define DAVINCI_VC_CTRL_RSTADC         BIT(0)
+#define DAVINCI_VC_CTRL_RSTDAC         BIT(1)
+#define DAVINCI_VC_CTRL_RD_BITS_8      BIT(4)
+#define DAVINCI_VC_CTRL_RD_UNSIGNED    BIT(5)
+#define DAVINCI_VC_CTRL_WD_BITS_8      BIT(6)
+#define DAVINCI_VC_CTRL_WD_UNSIGNED    BIT(7)
+#define DAVINCI_VC_CTRL_RFIFOEN                BIT(8)
+#define DAVINCI_VC_CTRL_RFIFOCL                BIT(9)
+#define DAVINCI_VC_CTRL_RFIFOMD_WORD_1 BIT(10)
+#define DAVINCI_VC_CTRL_WFIFOEN                BIT(12)
+#define DAVINCI_VC_CTRL_WFIFOCL                BIT(13)
+#define DAVINCI_VC_CTRL_WFIFOMD_WORD_1 BIT(14)
+
+/* DAVINCI_VC_INT bit fields */
+#define DAVINCI_VC_INT_MASK            0x3F
+#define DAVINCI_VC_INT_RDRDY_MASK      BIT(0)
+#define DAVINCI_VC_INT_RERROVF_MASK    BIT(1)
+#define DAVINCI_VC_INT_RERRUDR_MASK    BIT(2)
+#define DAVINCI_VC_INT_WDREQ_MASK      BIT(3)
+#define DAVINCI_VC_INT_WERROVF_MASKBIT BIT(4)
+#define DAVINCI_VC_INT_WERRUDR_MASK    BIT(5)
+
+/* DAVINCI_VC_REG05 bit fields */
+#define DAVINCI_VC_REG05_PGA_GAIN      0x07
+
+/* DAVINCI_VC_REG09 bit fields */
+#define DAVINCI_VC_REG09_MUTE          0x40
+#define DAVINCI_VC_REG09_DIG_ATTEN     0x3F
+
+/* DAVINCI_VC_REG12 bit fields */
+#define DAVINCI_VC_REG12_POWER_ALL_ON  0xFD
+#define DAVINCI_VC_REG12_POWER_ALL_OFF 0x00
+
+#define DAVINCI_VC_CELLS               2
+
+enum davinci_vc_cells {
+       DAVINCI_VC_VCIF_CELL,
+       DAVINCI_VC_CQ93VC_CELL,
+};
+
+struct davinci_vcif {
+       struct platform_device  *pdev;
+       u32 dma_tx_channel;
+       u32 dma_rx_channel;
+       dma_addr_t dma_tx_addr;
+       dma_addr_t dma_rx_addr;
+};
+
+struct cq93vc {
+       struct platform_device *pdev;
+       struct snd_soc_codec *codec;
+       u32 sysclk;
+};
+
+struct davinci_vc;
+
+struct davinci_vc {
+       /* Device data */
+       struct device *dev;
+       struct platform_device *pdev;
+       struct clk *clk;
+
+       /* Memory resources */
+       void __iomem *base;
+       resource_size_t pbase;
+       size_t base_size;
+
+       /* MFD cells */
+       struct mfd_cell cells[DAVINCI_VC_CELLS];
+
+       /* Client devices */
+       struct davinci_vcif davinci_vcif;
+       struct cq93vc cq93vc;
+};
+
+#endif
index d899dc0..a95141e 100644 (file)
  */
 #define WM8350_JACK_L_LVL                      0x0800
 #define WM8350_JACK_R_LVL                       0x0400
+#define WM8350_JACK_MICSCD_LVL                 0x0200
+#define WM8350_JACK_MICSD_LVL                  0x0100
 
 /*
  * WM8350 Platform setup
index b06ff28..de79bae 100644 (file)
 #ifndef __MFD_WM8994_CORE_H__
 #define __MFD_WM8994_CORE_H__
 
+#include <linux/interrupt.h>
+
 struct regulator_dev;
 struct regulator_bulk_data;
 
 #define WM8994_NUM_GPIO_REGS 11
-#define WM8994_NUM_LDO_REGS 2
+#define WM8994_NUM_LDO_REGS   2
+#define WM8994_NUM_IRQ_REGS   2
+
+#define WM8994_IRQ_TEMP_SHUT           0
+#define WM8994_IRQ_MIC1_DET            1
+#define WM8994_IRQ_MIC1_SHRT           2
+#define WM8994_IRQ_MIC2_DET            3
+#define WM8994_IRQ_MIC2_SHRT           4
+#define WM8994_IRQ_FLL1_LOCK           5
+#define WM8994_IRQ_FLL2_LOCK           6
+#define WM8994_IRQ_SRC1_LOCK           7
+#define WM8994_IRQ_SRC2_LOCK           8
+#define WM8994_IRQ_AIF1DRC1_SIG_DET    9
+#define WM8994_IRQ_AIF1DRC2_SIG_DET    10
+#define WM8994_IRQ_AIF2DRC_SIG_DET     11
+#define WM8994_IRQ_FIFOS_ERR           12
+#define WM8994_IRQ_WSEQ_DONE           13
+#define WM8994_IRQ_DCS_DONE            14
+#define WM8994_IRQ_TEMP_WARN           15
+
+/* GPIOs in the chip are numbered from 1-11 */
+#define WM8994_IRQ_GPIO(x) (x + WM8994_IRQ_TEMP_WARN)
 
 struct wm8994 {
        struct mutex io_lock;
+       struct mutex irq_lock;
 
        struct device *dev;
        int (*read_dev)(struct wm8994 *wm8994, unsigned short reg,
@@ -33,6 +57,11 @@ struct wm8994 {
        void *control_data;
 
        int gpio_base;
+       int irq_base;
+
+       int irq;
+       u16 irq_masks_cur[WM8994_NUM_IRQ_REGS];
+       u16 irq_masks_cache[WM8994_NUM_IRQ_REGS];
 
        /* Used over suspend/resume */
        u16 ldo_regs[WM8994_NUM_LDO_REGS];
@@ -51,4 +80,26 @@ int wm8994_set_bits(struct wm8994 *wm8994, unsigned short reg,
 int wm8994_bulk_read(struct wm8994 *wm8994, unsigned short reg,
                     int count, u16 *buf);
 
+
+/* Helper to save on boilerplate */
+static inline int wm8994_request_irq(struct wm8994 *wm8994, int irq,
+                                    irq_handler_t handler, const char *name,
+                                    void *data)
+{
+       if (!wm8994->irq_base)
+               return -EINVAL;
+       return request_threaded_irq(wm8994->irq_base + irq, NULL, handler,
+                                   IRQF_TRIGGER_RISING, name,
+                                   data);
+}
+static inline void wm8994_free_irq(struct wm8994 *wm8994, int irq, void *data)
+{
+       if (!wm8994->irq_base)
+               return;
+       free_irq(wm8994->irq_base + irq, data);
+}
+
+int wm8994_irq_init(struct wm8994 *wm8994);
+void wm8994_irq_exit(struct wm8994 *wm8994);
+
 #endif
index 70d6a86..5c51f36 100644 (file)
@@ -70,6 +70,7 @@ struct wm8994_pdata {
 
        struct wm8994_ldo_pdata ldo[WM8994_NUM_LDO];
 
+       int irq_base;  /** Base IRQ number for WM8994, required for IRQs */
 
         int num_drc_cfgs;
         struct wm8994_drc_cfg *drc_cfgs;
index e92d1bf..7a7f9c1 100644 (file)
@@ -123,8 +123,8 @@ enum {
        MLX4_OPCODE_RDMA_READ           = 0x10,
        MLX4_OPCODE_ATOMIC_CS           = 0x11,
        MLX4_OPCODE_ATOMIC_FA           = 0x12,
-       MLX4_OPCODE_ATOMIC_MASK_CS      = 0x14,
-       MLX4_OPCODE_ATOMIC_MASK_FA      = 0x15,
+       MLX4_OPCODE_MASKED_ATOMIC_CS    = 0x14,
+       MLX4_OPCODE_MASKED_ATOMIC_FA    = 0x15,
        MLX4_OPCODE_BIND_MW             = 0x18,
        MLX4_OPCODE_FMR                 = 0x19,
        MLX4_OPCODE_LOCAL_INVAL         = 0x1b,
index 9f29d86..7abe643 100644 (file)
@@ -285,6 +285,13 @@ struct mlx4_wqe_atomic_seg {
        __be64                  compare;
 };
 
+struct mlx4_wqe_masked_atomic_seg {
+       __be64                  swap_add;
+       __be64                  compare;
+       __be64                  swap_add_mask;
+       __be64                  compare_mask;
+};
+
 struct mlx4_wqe_data_seg {
        __be32                  byte_count;
        __be32                  lkey;
index 462acaf..fb19bb9 100644 (file)
@@ -19,7 +19,6 @@ struct anon_vma;
 struct file_ra_state;
 struct user_struct;
 struct writeback_control;
-struct rlimit;
 
 #ifndef CONFIG_DISCONTIGMEM          /* Don't use mapnrs, do it properly */
 extern unsigned long max_mapnr;
@@ -1449,9 +1448,6 @@ int vmemmap_populate_basepages(struct page *start_page,
 int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
 void vmemmap_populate_print_last(void);
 
-extern int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim,
-                                size_t size);
-extern void refund_locked_memory(struct mm_struct *mm, size_t size);
 
 enum mf_flags {
        MF_COUNT_INCREASED = 1 << 0,
index f58e9d8..56fde43 100644 (file)
@@ -474,4 +474,13 @@ struct platform_device_id {
                        __attribute__((aligned(sizeof(kernel_ulong_t))));
 };
 
+struct zorro_device_id {
+       __u32 id;                       /* Device ID or ZORRO_WILDCARD */
+       kernel_ulong_t driver_data;     /* Data private to the driver */
+};
+
+#define ZORRO_WILDCARD                 (0xffffffff)    /* not official */
+
+#define ZORRO_DEVICE_MODALIAS_FMT      "zorro:i%08X"
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
index 515d53a..6914fca 100644 (file)
@@ -465,8 +465,7 @@ static inline void __module_get(struct module *module)
        if (module) {
                preempt_disable();
                __this_cpu_inc(module->refptr->incs);
-               trace_module_get(module, _THIS_IP_,
-                                __this_cpu_read(module->refptr->incs));
+               trace_module_get(module, _THIS_IP_);
                preempt_enable();
        }
 }
@@ -480,8 +479,7 @@ static inline int try_module_get(struct module *module)
 
                if (likely(module_is_live(module))) {
                        __this_cpu_inc(module->refptr->incs);
-                       trace_module_get(module, _THIS_IP_,
-                               __this_cpu_read(module->refptr->incs));
+                       trace_module_get(module, _THIS_IP_);
                } else
                        ret = 0;
 
index fa8b476..3857517 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/if_link.h>
 
 #ifdef __KERNEL__
+#include <linux/pm_qos_params.h>
 #include <linux/timer.h>
 #include <linux/delay.h>
 #include <linux/mm.h>
@@ -711,6 +712,9 @@ struct net_device {
         * the interface.
         */
        char                    name[IFNAMSIZ];
+
+       struct pm_qos_request_list *pm_qos_req;
+
        /* device name hash chain */
        struct hlist_node       name_hlist;
        /* snmp alias */
index 07ce460..77c2ae5 100644 (file)
@@ -356,6 +356,20 @@ extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struc
 extern u64 nfs_compat_user_ino64(u64 fileid);
 extern void nfs_fattr_init(struct nfs_fattr *fattr);
 
+extern struct nfs_fattr *nfs_alloc_fattr(void);
+
+static inline void nfs_free_fattr(const struct nfs_fattr *fattr)
+{
+       kfree(fattr);
+}
+
+extern struct nfs_fh *nfs_alloc_fhandle(void);
+
+static inline void nfs_free_fhandle(const struct nfs_fh *fh)
+{
+       kfree(fh);
+}
+
 /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
 extern __be32 root_nfs_parse_addr(char *name); /*__init*/
 extern unsigned long nfs_inc_attr_generation_counter(void);
index e82957a..d6e10a4 100644 (file)
@@ -44,7 +44,6 @@ struct nfs_client {
 
 #ifdef CONFIG_NFS_V4
        u64                     cl_clientid;    /* constant */
-       nfs4_verifier           cl_confirm;
        unsigned long           cl_state;
 
        struct rb_root          cl_openowner_id;
index 89b2881..51914d7 100644 (file)
@@ -386,8 +386,8 @@ struct nfs_removeargs {
 
 struct nfs_removeres {
        const struct nfs_server *server;
+       struct nfs_fattr        *dir_attr;
        struct nfs4_change_info cinfo;
-       struct nfs_fattr        dir_attr;
        struct nfs4_sequence_res        seq_res;
 };
 
@@ -824,6 +824,11 @@ struct nfs4_setclientid {
        u32                             sc_cb_ident;
 };
 
+struct nfs4_setclientid_res {
+       u64                             clientid;
+       nfs4_verifier                   confirm;
+};
+
 struct nfs4_statfs_arg {
        const struct nfs_fh *           fh;
        const u32 *                     bitmask;
index 65e333a..80d55bb 100644 (file)
@@ -40,12 +40,12 @@ struct nfs_fhbase_old {
  * This is the new flexible, extensible style NFSv2/v3 file handle.
  * by Neil Brown <neilb@cse.unsw.edu.au> - March 2000
  *
- * The file handle is seens as a list of 4byte words.
- * The first word contains a version number (1) and four descriptor bytes
+ * The file handle starts with a sequence of four-byte words.
+ * The first word contains a version number (1) and three descriptor bytes
  * that tell how the remaining 3 variable length fields should be handled.
  * These three bytes are auth_type, fsid_type and fileid_type.
  *
- * All 4byte values are in host-byte-order.
+ * All four-byte values are in host-byte-order.
  *
  * The auth_type field specifies how the filehandle can be authenticated
  * This might allow a file to be confirmed to be in a writable part of a
index c8e3754..3fd5c82 100644 (file)
@@ -203,8 +203,19 @@ struct perf_event_attr {
                                enable_on_exec :  1, /* next exec enables     */
                                task           :  1, /* trace fork/exit       */
                                watermark      :  1, /* wakeup_watermark      */
-
-                               __reserved_1   : 49;
+                               /*
+                                * precise_ip:
+                                *
+                                *  0 - SAMPLE_IP can have arbitrary skid
+                                *  1 - SAMPLE_IP must have constant skid
+                                *  2 - SAMPLE_IP requested to have 0 skid
+                                *  3 - SAMPLE_IP must have 0 skid
+                                *
+                                *  See also PERF_RECORD_MISC_EXACT_IP
+                                */
+                               precise_ip     :  2, /* skid constraint       */
+
+                               __reserved_1   : 47;
 
        union {
                __u32           wakeup_events;    /* wakeup every n events */
@@ -287,11 +298,24 @@ struct perf_event_mmap_page {
        __u64   data_tail;              /* user-space written tail */
 };
 
-#define PERF_RECORD_MISC_CPUMODE_MASK          (3 << 0)
+#define PERF_RECORD_MISC_CPUMODE_MASK          (7 << 0)
 #define PERF_RECORD_MISC_CPUMODE_UNKNOWN       (0 << 0)
 #define PERF_RECORD_MISC_KERNEL                        (1 << 0)
 #define PERF_RECORD_MISC_USER                  (2 << 0)
 #define PERF_RECORD_MISC_HYPERVISOR            (3 << 0)
+#define PERF_RECORD_MISC_GUEST_KERNEL          (4 << 0)
+#define PERF_RECORD_MISC_GUEST_USER            (5 << 0)
+
+/*
+ * Indicates that the content of PERF_SAMPLE_IP points to
+ * the actual instruction that triggered the event. See also
+ * perf_event_attr::precise_ip.
+ */
+#define PERF_RECORD_MISC_EXACT_IP              (1 << 14)
+/*
+ * Reserve the last bit to indicate some extended misc field
+ */
+#define PERF_RECORD_MISC_EXT_RESERVED          (1 << 15)
 
 struct perf_event_header {
        __u32   type;
@@ -439,6 +463,12 @@ enum perf_callchain_context {
 # include <asm/perf_event.h>
 #endif
 
+struct perf_guest_info_callbacks {
+       int (*is_in_guest) (void);
+       int (*is_user_mode) (void);
+       unsigned long (*get_guest_ip) (void);
+};
+
 #ifdef CONFIG_HAVE_HW_BREAKPOINT
 #include <asm/hw_breakpoint.h>
 #endif
@@ -468,6 +498,17 @@ struct perf_raw_record {
        void                            *data;
 };
 
+struct perf_branch_entry {
+       __u64                           from;
+       __u64                           to;
+       __u64                           flags;
+};
+
+struct perf_branch_stack {
+       __u64                           nr;
+       struct perf_branch_entry        entries[0];
+};
+
 struct task_struct;
 
 /**
@@ -506,6 +547,8 @@ struct hw_perf_event {
 
 struct perf_event;
 
+#define PERF_EVENT_TXN_STARTED 1
+
 /**
  * struct pmu - generic performance monitoring unit
  */
@@ -516,6 +559,16 @@ struct pmu {
        void (*stop)                    (struct perf_event *event);
        void (*read)                    (struct perf_event *event);
        void (*unthrottle)              (struct perf_event *event);
+
+       /*
+        * group events scheduling is treated as a transaction,
+        * add group events as a whole and perform one schedulability test.
+        * If test fails, roll back the whole group
+        */
+
+       void (*start_txn)       (const struct pmu *pmu);
+       void (*cancel_txn)      (const struct pmu *pmu);
+       int  (*commit_txn)      (const struct pmu *pmu);
 };
 
 /**
@@ -571,6 +624,14 @@ enum perf_group_flag {
        PERF_GROUP_SOFTWARE = 0x1,
 };
 
+#define SWEVENT_HLIST_BITS     8
+#define SWEVENT_HLIST_SIZE     (1 << SWEVENT_HLIST_BITS)
+
+struct swevent_hlist {
+       struct hlist_head       heads[SWEVENT_HLIST_SIZE];
+       struct rcu_head         rcu_head;
+};
+
 /**
  * struct perf_event - performance event kernel representation:
  */
@@ -579,6 +640,7 @@ struct perf_event {
        struct list_head                group_entry;
        struct list_head                event_entry;
        struct list_head                sibling_list;
+       struct hlist_node               hlist_entry;
        int                             nr_siblings;
        int                             group_flags;
        struct perf_event               *group_leader;
@@ -726,6 +788,9 @@ struct perf_cpu_context {
        int                             active_oncpu;
        int                             max_pertask;
        int                             exclusive;
+       struct swevent_hlist            *swevent_hlist;
+       struct mutex                    hlist_mutex;
+       int                             hlist_refcount;
 
        /*
         * Recursion avoidance:
@@ -769,9 +834,6 @@ extern void perf_disable(void);
 extern void perf_enable(void);
 extern int perf_event_task_disable(void);
 extern int perf_event_task_enable(void);
-extern int hw_perf_group_sched_in(struct perf_event *group_leader,
-              struct perf_cpu_context *cpuctx,
-              struct perf_event_context *ctx);
 extern void perf_event_update_userpage(struct perf_event *event);
 extern int perf_event_release_kernel(struct perf_event *event);
 extern struct perf_event *
@@ -902,6 +964,10 @@ static inline void perf_event_mmap(struct vm_area_struct *vma)
                __perf_event_mmap(vma);
 }
 
+extern struct perf_guest_info_callbacks *perf_guest_cbs;
+extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
+extern int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);
+
 extern void perf_event_comm(struct task_struct *tsk);
 extern void perf_event_fork(struct task_struct *tsk);
 
@@ -971,6 +1037,11 @@ perf_sw_event(u32 event_id, u64 nr, int nmi,
 static inline void
 perf_bp_event(struct perf_event *event, void *data)                    { }
 
+static inline int perf_register_guest_info_callbacks
+(struct perf_guest_info_callbacks *callbacks) { return 0; }
+static inline int perf_unregister_guest_info_callbacks
+(struct perf_guest_info_callbacks *callbacks) { return 0; }
+
 static inline void perf_event_mmap(struct vm_area_struct *vma)         { }
 static inline void perf_event_comm(struct task_struct *tsk)            { }
 static inline void perf_event_fork(struct task_struct *tsk)            { }
index 212da17..5417944 100644 (file)
@@ -44,12 +44,14 @@ extern int platform_get_irq_byname(struct platform_device *, const char *);
 extern int platform_add_devices(struct platform_device **, int);
 
 extern struct platform_device *platform_device_register_simple(const char *, int id,
-                                       struct resource *, unsigned int);
+                                       const struct resource *, unsigned int);
 extern struct platform_device *platform_device_register_data(struct device *,
                const char *, int, const void *, size_t);
 
 extern struct platform_device *platform_device_alloc(const char *name, int id);
-extern int platform_device_add_resources(struct platform_device *pdev, struct resource *res, unsigned int num);
+extern int platform_device_add_resources(struct platform_device *pdev,
+                                        const struct resource *res,
+                                        unsigned int num);
 extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size);
 extern int platform_device_add(struct platform_device *pdev);
 extern void platform_device_del(struct platform_device *pdev);
index d74f75e..8ba440e 100644 (file)
 #define PM_QOS_NUM_CLASSES 4
 #define PM_QOS_DEFAULT_VALUE -1
 
-int pm_qos_add_requirement(int qos, char *name, s32 value);
-int pm_qos_update_requirement(int qos, char *name, s32 new_value);
-void pm_qos_remove_requirement(int qos, char *name);
+struct pm_qos_request_list;
 
-int pm_qos_requirement(int qos);
+struct pm_qos_request_list *pm_qos_add_request(int pm_qos_class, s32 value);
+void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req,
+               s32 new_value);
+void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req);
 
-int pm_qos_add_notifier(int qos, struct notifier_block *notifier);
-int pm_qos_remove_notifier(int qos, struct notifier_block *notifier);
+int pm_qos_request(int pm_qos_class);
+int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier);
+int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier);
 
index b776db7..6e81888 100644 (file)
@@ -30,6 +30,9 @@ extern void pm_runtime_enable(struct device *dev);
 extern void __pm_runtime_disable(struct device *dev, bool check_resume);
 extern void pm_runtime_allow(struct device *dev);
 extern void pm_runtime_forbid(struct device *dev);
+extern int pm_generic_runtime_idle(struct device *dev);
+extern int pm_generic_runtime_suspend(struct device *dev);
+extern int pm_generic_runtime_resume(struct device *dev);
 
 static inline bool pm_children_suspended(struct device *dev)
 {
@@ -96,6 +99,10 @@ static inline bool device_run_wake(struct device *dev) { return false; }
 static inline void device_set_run_wake(struct device *dev, bool enable) {}
 static inline bool pm_runtime_suspended(struct device *dev) { return false; }
 
+static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
+static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
+static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
+
 #endif /* !CONFIG_PM_RUNTIME */
 
 static inline int pm_runtime_get(struct device *dev)
index 0aae777..22d64c1 100644 (file)
 # error "please don't include this file directly"
 #endif
 
+#include <linux/types.h>
+
 #ifdef CONFIG_PM
 
 /* changes to device_may_wakeup take effect on the next pm state change.
  * by default, devices should wakeup if they can.
  */
-static inline void device_init_wakeup(struct device *dev, int val)
+static inline void device_init_wakeup(struct device *dev, bool val)
 {
-       dev->power.can_wakeup = dev->power.should_wakeup = !!val;
+       dev->power.can_wakeup = dev->power.should_wakeup = val;
 }
 
-static inline void device_set_wakeup_capable(struct device *dev, int val)
+static inline void device_set_wakeup_capable(struct device *dev, bool capable)
 {
-       dev->power.can_wakeup = !!val;
+       dev->power.can_wakeup = capable;
 }
 
-static inline int device_can_wakeup(struct device *dev)
+static inline bool device_can_wakeup(struct device *dev)
 {
        return dev->power.can_wakeup;
 }
 
-static inline void device_set_wakeup_enable(struct device *dev, int val)
+static inline void device_set_wakeup_enable(struct device *dev, bool enable)
 {
-       dev->power.should_wakeup = !!val;
+       dev->power.should_wakeup = enable;
 }
 
-static inline int device_may_wakeup(struct device *dev)
+static inline bool device_may_wakeup(struct device *dev)
 {
        return dev->power.can_wakeup && dev->power.should_wakeup;
 }
@@ -58,20 +60,28 @@ static inline int device_may_wakeup(struct device *dev)
 #else /* !CONFIG_PM */
 
 /* For some reason the next two routines work even without CONFIG_PM */
-static inline void device_init_wakeup(struct device *dev, int val)
+static inline void device_init_wakeup(struct device *dev, bool val)
 {
-       dev->power.can_wakeup = !!val;
+       dev->power.can_wakeup = val;
 }
 
-static inline void device_set_wakeup_capable(struct device *dev, int val) { }
+static inline void device_set_wakeup_capable(struct device *dev, bool capable)
+{
+}
 
-static inline int device_can_wakeup(struct device *dev)
+static inline bool device_can_wakeup(struct device *dev)
 {
        return dev->power.can_wakeup;
 }
 
-#define device_set_wakeup_enable(dev, val)     do {} while (0)
-#define device_may_wakeup(dev)                 0
+static inline void device_set_wakeup_enable(struct device *dev, bool enable)
+{
+}
+
+static inline bool device_may_wakeup(struct device *dev)
+{
+       return false;
+}
 
 #endif /* !CONFIG_PM */
 
index e1fb607..4272521 100644 (file)
@@ -345,18 +345,6 @@ static inline void user_single_step_siginfo(struct task_struct *tsk,
 #define arch_ptrace_stop(code, info)           do { } while (0)
 #endif
 
-#ifndef arch_ptrace_untrace
-/*
- * Do machine-specific work before untracing child.
- *
- * This is called for a normal detach as well as from ptrace_exit()
- * when the tracing task dies.
- *
- * Called with write_lock(&tasklist_lock) held.
- */
-#define arch_ptrace_untrace(task)              do { } while (0)
-#endif
-
 extern int task_current_syscall(struct task_struct *target, long *callno,
                                unsigned long args[6], unsigned int maxargs,
                                unsigned long *sp, unsigned long *pc);
index 5210a5c..fe1872e 100644 (file)
@@ -110,6 +110,7 @@ struct rb_node
 struct rb_root
 {
        struct rb_node *rb_node;
+       void (*augment_cb)(struct rb_node *node);
 };
 
 
@@ -129,7 +130,9 @@ static inline void rb_set_color(struct rb_node *rb, int color)
        rb->rb_parent_color = (rb->rb_parent_color & ~1) | color;
 }
 
-#define RB_ROOT        (struct rb_root) { NULL, }
+#define RB_ROOT        (struct rb_root) { NULL, NULL, }
+#define RB_AUGMENT_ROOT(x)     (struct rb_root) { NULL, x}
+
 #define        rb_entry(ptr, type, member) container_of(ptr, type, member)
 
 #define RB_EMPTY_ROOT(root)    ((root)->rb_node == NULL)
index db266bb..b653b4a 100644 (file)
@@ -56,8 +56,6 @@ struct rcu_head {
 };
 
 /* Exported common interfaces */
-extern void synchronize_rcu_bh(void);
-extern void synchronize_sched(void);
 extern void rcu_barrier(void);
 extern void rcu_barrier_bh(void);
 extern void rcu_barrier_sched(void);
@@ -66,8 +64,6 @@ extern int sched_expedited_torture_stats(char *page);
 
 /* Internal to kernel */
 extern void rcu_init(void);
-extern int rcu_scheduler_active;
-extern void rcu_scheduler_starting(void);
 
 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
 #include <linux/rcutree.h>
@@ -83,6 +79,14 @@ extern void rcu_scheduler_starting(void);
        (ptr)->next = NULL; (ptr)->func = NULL; \
 } while (0)
 
+static inline void init_rcu_head_on_stack(struct rcu_head *head)
+{
+}
+
+static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
+{
+}
+
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
 extern struct lockdep_map rcu_lock_map;
@@ -106,12 +110,13 @@ extern int debug_lockdep_rcu_enabled(void);
 /**
  * rcu_read_lock_held - might we be in RCU read-side critical section?
  *
- * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in
- * an RCU read-side critical section.  In absence of CONFIG_PROVE_LOCKING,
+ * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
+ * read-side critical section.  In absence of CONFIG_DEBUG_LOCK_ALLOC,
  * this assumes we are in an RCU read-side critical section unless it can
  * prove otherwise.
  *
- * Check rcu_scheduler_active to prevent false positives during boot.
+ * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
+ * and while lockdep is disabled.
  */
 static inline int rcu_read_lock_held(void)
 {
@@ -129,13 +134,15 @@ extern int rcu_read_lock_bh_held(void);
 /**
  * rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section?
  *
- * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in an
- * RCU-sched read-side critical section.  In absence of CONFIG_PROVE_LOCKING,
- * this assumes we are in an RCU-sched read-side critical section unless it
- * can prove otherwise.  Note that disabling of preemption (including
- * disabling irqs) counts as an RCU-sched read-side critical section.
+ * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an
+ * RCU-sched read-side critical section.  In absence of
+ * CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
+ * critical section unless it can prove otherwise.  Note that disabling
+ * of preemption (including disabling irqs) counts as an RCU-sched
+ * read-side critical section.
  *
- * Check rcu_scheduler_active to prevent false positives during boot.
+ * Check debug_lockdep_rcu_enabled() to prevent false positives during boot
+ * and while lockdep is disabled.
  */
 #ifdef CONFIG_PREEMPT
 static inline int rcu_read_lock_sched_held(void)
@@ -177,7 +184,7 @@ static inline int rcu_read_lock_bh_held(void)
 #ifdef CONFIG_PREEMPT
 static inline int rcu_read_lock_sched_held(void)
 {
-       return !rcu_scheduler_active || preempt_count() != 0 || irqs_disabled();
+       return preempt_count() != 0 || irqs_disabled();
 }
 #else /* #ifdef CONFIG_PREEMPT */
 static inline int rcu_read_lock_sched_held(void)
@@ -192,6 +199,15 @@ static inline int rcu_read_lock_sched_held(void)
 
 extern int rcu_my_thread_group_empty(void);
 
+#define __do_rcu_dereference_check(c)                                  \
+       do {                                                            \
+               static bool __warned;                                   \
+               if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
+                       __warned = true;                                \
+                       lockdep_rcu_dereference(__FILE__, __LINE__);    \
+               }                                                       \
+       } while (0)
+
 /**
  * rcu_dereference_check - rcu_dereference with debug checking
  * @p: The pointer to read, prior to dereferencing
@@ -221,8 +237,7 @@ extern int rcu_my_thread_group_empty(void);
  */
 #define rcu_dereference_check(p, c) \
        ({ \
-               if (debug_lockdep_rcu_enabled() && !(c)) \
-                       lockdep_rcu_dereference(__FILE__, __LINE__); \
+               __do_rcu_dereference_check(c); \
                rcu_dereference_raw(p); \
        })
 
@@ -239,8 +254,7 @@ extern int rcu_my_thread_group_empty(void);
  */
 #define rcu_dereference_protected(p, c) \
        ({ \
-               if (debug_lockdep_rcu_enabled() && !(c)) \
-                       lockdep_rcu_dereference(__FILE__, __LINE__); \
+               __do_rcu_dereference_check(c); \
                (p); \
        })
 
index a519587..e2e8931 100644 (file)
 
 void rcu_sched_qs(int cpu);
 void rcu_bh_qs(int cpu);
+static inline void rcu_note_context_switch(int cpu)
+{
+       rcu_sched_qs(cpu);
+}
 
 #define __rcu_read_lock()      preempt_disable()
 #define __rcu_read_unlock()    preempt_enable()
@@ -60,8 +64,6 @@ static inline long rcu_batches_completed_bh(void)
        return 0;
 }
 
-extern int rcu_expedited_torture_stats(char *page);
-
 static inline void rcu_force_quiescent_state(void)
 {
 }
@@ -74,7 +76,17 @@ static inline void rcu_sched_force_quiescent_state(void)
 {
 }
 
-#define synchronize_rcu synchronize_sched
+extern void synchronize_sched(void);
+
+static inline void synchronize_rcu(void)
+{
+       synchronize_sched();
+}
+
+static inline void synchronize_rcu_bh(void)
+{
+       synchronize_sched();
+}
 
 static inline void synchronize_rcu_expedited(void)
 {
@@ -114,4 +126,17 @@ static inline int rcu_preempt_depth(void)
        return 0;
 }
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+
+extern int rcu_scheduler_active __read_mostly;
+extern void rcu_scheduler_starting(void);
+
+#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+
+static inline void rcu_scheduler_starting(void)
+{
+}
+
+#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+
 #endif /* __LINUX_RCUTINY_H */
index 42cc3a0..c0ed1c0 100644 (file)
@@ -34,8 +34,8 @@ struct notifier_block;
 
 extern void rcu_sched_qs(int cpu);
 extern void rcu_bh_qs(int cpu);
+extern void rcu_note_context_switch(int cpu);
 extern int rcu_needs_cpu(int cpu);
-extern int rcu_expedited_torture_stats(char *page);
 
 #ifdef CONFIG_TREE_PREEMPT_RCU
 
@@ -86,6 +86,8 @@ static inline void __rcu_read_unlock_bh(void)
 
 extern void call_rcu_sched(struct rcu_head *head,
                           void (*func)(struct rcu_head *rcu));
+extern void synchronize_rcu_bh(void);
+extern void synchronize_sched(void);
 extern void synchronize_rcu_expedited(void);
 
 static inline void synchronize_rcu_bh_expedited(void)
@@ -120,4 +122,7 @@ static inline int rcu_blocking_is_gp(void)
        return num_online_cpus() == 1;
 }
 
+extern void rcu_scheduler_starting(void);
+extern int rcu_scheduler_active __read_mostly;
+
 #endif /* __LINUX_RCUTREE_H */
index 5fcc31e..25b4f68 100644 (file)
@@ -120,12 +120,16 @@ int ring_buffer_write(struct ring_buffer *buffer,
                      unsigned long length, void *data);
 
 struct ring_buffer_event *
-ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts);
+ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts,
+                unsigned long *lost_events);
 struct ring_buffer_event *
-ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts);
+ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts,
+                   unsigned long *lost_events);
 
 struct ring_buffer_iter *
-ring_buffer_read_start(struct ring_buffer *buffer, int cpu);
+ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu);
+void ring_buffer_read_prepare_sync(void);
+void ring_buffer_read_start(struct ring_buffer_iter *iter);
 void ring_buffer_read_finish(struct ring_buffer_iter *iter);
 
 struct ring_buffer_event *
index 8ba646e..e55d82c 100644 (file)
@@ -15,7 +15,7 @@
 struct v3020_platform_data {
        int leftshift; /* (1<<(leftshift)) & readl() */
 
-       int use_gpio:1;
+       unsigned int use_gpio:1;
        unsigned int gpio_cs;
        unsigned int gpio_wr;
        unsigned int gpio_rd;
index 2b7b81d..b55e988 100644 (file)
@@ -99,7 +99,6 @@ struct futex_pi_state;
 struct robust_list_head;
 struct bio_list;
 struct fs_struct;
-struct bts_context;
 struct perf_event_context;
 
 /*
@@ -275,11 +274,17 @@ extern cpumask_var_t nohz_cpu_mask;
 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ)
 extern int select_nohz_load_balancer(int cpu);
 extern int get_nohz_load_balancer(void);
+extern int nohz_ratelimit(int cpu);
 #else
 static inline int select_nohz_load_balancer(int cpu)
 {
        return 0;
 }
+
+static inline int nohz_ratelimit(int cpu)
+{
+       return 0;
+}
 #endif
 
 /*
@@ -954,6 +959,7 @@ struct sched_domain {
        char *name;
 #endif
 
+       unsigned int span_weight;
        /*
         * Span of all CPUs in this domain.
         *
@@ -1026,12 +1032,17 @@ struct sched_domain;
 #define WF_SYNC                0x01            /* waker goes to sleep after wakup */
 #define WF_FORK                0x02            /* child wakeup after fork */
 
+#define ENQUEUE_WAKEUP         1
+#define ENQUEUE_WAKING         2
+#define ENQUEUE_HEAD           4
+
+#define DEQUEUE_SLEEP          1
+
 struct sched_class {
        const struct sched_class *next;
 
-       void (*enqueue_task) (struct rq *rq, struct task_struct *p, int wakeup,
-                             bool head);
-       void (*dequeue_task) (struct rq *rq, struct task_struct *p, int sleep);
+       void (*enqueue_task) (struct rq *rq, struct task_struct *p, int flags);
+       void (*dequeue_task) (struct rq *rq, struct task_struct *p, int flags);
        void (*yield_task) (struct rq *rq);
 
        void (*check_preempt_curr) (struct rq *rq, struct task_struct *p, int flags);
@@ -1040,7 +1051,8 @@ struct sched_class {
        void (*put_prev_task) (struct rq *rq, struct task_struct *p);
 
 #ifdef CONFIG_SMP
-       int  (*select_task_rq)(struct task_struct *p, int sd_flag, int flags);
+       int  (*select_task_rq)(struct rq *rq, struct task_struct *p,
+                              int sd_flag, int flags);
 
        void (*pre_schedule) (struct rq *this_rq, struct task_struct *task);
        void (*post_schedule) (struct rq *this_rq);
@@ -1077,36 +1089,8 @@ struct load_weight {
        unsigned long weight, inv_weight;
 };
 
-/*
- * CFS stats for a schedulable entity (task, task-group etc)
- *
- * Current field usage histogram:
- *
- *     4 se->block_start
- *     4 se->run_node
- *     4 se->sleep_start
- *     6 se->load.weight
- */
-struct sched_entity {
-       struct load_weight      load;           /* for load-balancing */
-       struct rb_node          run_node;
-       struct list_head        group_node;
-       unsigned int            on_rq;
-
-       u64                     exec_start;
-       u64                     sum_exec_runtime;
-       u64                     vruntime;
-       u64                     prev_sum_exec_runtime;
-
-       u64                     last_wakeup;
-       u64                     avg_overlap;
-
-       u64                     nr_migrations;
-
-       u64                     start_runtime;
-       u64                     avg_wakeup;
-
 #ifdef CONFIG_SCHEDSTATS
+struct sched_statistics {
        u64                     wait_start;
        u64                     wait_max;
        u64                     wait_count;
@@ -1138,6 +1122,24 @@ struct sched_entity {
        u64                     nr_wakeups_affine_attempts;
        u64                     nr_wakeups_passive;
        u64                     nr_wakeups_idle;
+};
+#endif
+
+struct sched_entity {
+       struct load_weight      load;           /* for load-balancing */
+       struct rb_node          run_node;
+       struct list_head        group_node;
+       unsigned int            on_rq;
+
+       u64                     exec_start;
+       u64                     sum_exec_runtime;
+       u64                     vruntime;
+       u64                     prev_sum_exec_runtime;
+
+       u64                     nr_migrations;
+
+#ifdef CONFIG_SCHEDSTATS
+       struct sched_statistics statistics;
 #endif
 
 #ifdef CONFIG_FAIR_GROUP_SCHED
@@ -1272,12 +1274,6 @@ struct task_struct {
        struct list_head ptraced;
        struct list_head ptrace_entry;
 
-       /*
-        * This is the tracer handle for the ptrace BTS extension.
-        * This field actually belongs to the ptracer task.
-        */
-       struct bts_context *bts;
-
        /* PID/PID hash table linkage. */
        struct pid_link pids[PIDTYPE_MAX];
        struct list_head thread_group;
@@ -1846,6 +1842,7 @@ extern void sched_clock_idle_sleep_event(void);
 extern void sched_clock_idle_wakeup_event(u64 delta_ns);
 
 #ifdef CONFIG_HOTPLUG_CPU
+extern void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p);
 extern void idle_task_exit(void);
 #else
 static inline void idle_task_exit(void) {}
@@ -2122,10 +2119,8 @@ extern void set_task_comm(struct task_struct *tsk, char *from);
 extern char *get_task_comm(char *to, struct task_struct *tsk);
 
 #ifdef CONFIG_SMP
-extern void wait_task_context_switch(struct task_struct *p);
 extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
 #else
-static inline void wait_task_context_switch(struct task_struct *p) {}
 static inline unsigned long wait_task_inactive(struct task_struct *p,
                                               long match_state)
 {
index 3158dd9..0c88191 100644 (file)
@@ -267,49 +267,16 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @orig the original mount data copied from userspace.
  *     @copy copied data which will be passed to the security module.
  *     Returns 0 if the copy was successful.
- * @sb_check_sb:
- *     Check permission before the device with superblock @mnt->sb is mounted
- *     on the mount point named by @nd.
- *     @mnt contains the vfsmount for device being mounted.
- *     @path contains the path for the mount point.
- *     Return 0 if permission is granted.
  * @sb_umount:
  *     Check permission before the @mnt file system is unmounted.
  *     @mnt contains the mounted file system.
  *     @flags contains the unmount flags, e.g. MNT_FORCE.
  *     Return 0 if permission is granted.
- * @sb_umount_close:
- *     Close any files in the @mnt mounted filesystem that are held open by
- *     the security module.  This hook is called during an umount operation
- *     prior to checking whether the filesystem is still busy.
- *     @mnt contains the mounted filesystem.
- * @sb_umount_busy:
- *     Handle a failed umount of the @mnt mounted filesystem, e.g.  re-opening
- *     any files that were closed by umount_close.  This hook is called during
- *     an umount operation if the umount fails after a call to the
- *     umount_close hook.
- *     @mnt contains the mounted filesystem.
- * @sb_post_remount:
- *     Update the security module's state when a filesystem is remounted.
- *     This hook is only called if the remount was successful.
- *     @mnt contains the mounted file system.
- *     @flags contains the new filesystem flags.
- *     @data contains the filesystem-specific data.
- * @sb_post_addmount:
- *     Update the security module's state when a filesystem is mounted.
- *     This hook is called any time a mount is successfully grafetd to
- *     the tree.
- *     @mnt contains the mounted filesystem.
- *     @mountpoint contains the path for the mount point.
  * @sb_pivotroot:
  *     Check permission before pivoting the root filesystem.
  *     @old_path contains the path for the new location of the current root (put_old).
  *     @new_path contains the path for the new root (new_root).
  *     Return 0 if permission is granted.
- * @sb_post_pivotroot:
- *     Update module state after a successful pivot.
- *     @old_path contains the path for the old root.
- *     @new_path contains the path for the new root.
  * @sb_set_mnt_opts:
  *     Set the security relevant mount options used for a superblock
  *     @sb the superblock to set security mount options for
@@ -511,12 +478,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @mnt is the vfsmount where the dentry was looked up
  *     @dentry contains the dentry structure for the file.
  *     Return 0 if permission is granted.
- * @inode_delete:
- *     @inode contains the inode structure for deleted inode.
- *     This hook is called when a deleted inode is released (i.e. an inode
- *     with no hard links has its use count drop to zero).  A security module
- *     can use this hook to release any persistent label associated with the
- *     inode.
  * @inode_setxattr:
  *     Check permission before setting the extended attributes
  *     @value identified by @name for @dentry.
@@ -691,10 +652,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @old points to the original credentials.
  *     @gfp indicates the atomicity of any memory allocations.
  *     Prepare a new set of credentials by copying the data from the old set.
- * @cred_commit:
- *     @new points to the new credentials.
- *     @old points to the original credentials.
- *     Install a new set of credentials.
  * @cred_transfer:
  *     @new points to the new credentials.
  *     @old points to the original credentials.
@@ -717,18 +674,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     userspace to load a kernel module with the given name.
  *     @kmod_name name of the module requested by the kernel
  *     Return 0 if successful.
- * @task_setuid:
- *     Check permission before setting one or more of the user identity
- *     attributes of the current process.  The @flags parameter indicates
- *     which of the set*uid system calls invoked this hook and how to
- *     interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
- *     definitions at the beginning of this file for the @flags values and
- *     their meanings.
- *     @id0 contains a uid.
- *     @id1 contains a uid.
- *     @id2 contains a uid.
- *     @flags contains one of the LSM_SETID_* values.
- *     Return 0 if permission is granted.
  * @task_fix_setuid:
  *     Update the module's state after setting one or more of the user
  *     identity attributes of the current process.  The @flags parameter
@@ -738,18 +683,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @old is the set of credentials that are being replaces
  *     @flags contains one of the LSM_SETID_* values.
  *     Return 0 on success.
- * @task_setgid:
- *     Check permission before setting one or more of the group identity
- *     attributes of the current process.  The @flags parameter indicates
- *     which of the set*gid system calls invoked this hook and how to
- *     interpret the @id0, @id1, and @id2 parameters.  See the LSM_SETID
- *     definitions at the beginning of this file for the @flags values and
- *     their meanings.
- *     @id0 contains a gid.
- *     @id1 contains a gid.
- *     @id2 contains a gid.
- *     @flags contains one of the LSM_SETID_* values.
- *     Return 0 if permission is granted.
  * @task_setpgid:
  *     Check permission before setting the process group identifier of the
  *     process @p to @pgid.
@@ -771,11 +704,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @p contains the task_struct for the process and place is into @secid.
  *     In case of failure, @secid will be set to zero.
  *
- * @task_setgroups:
- *     Check permission before setting the supplementary group set of the
- *     current process.
- *     @group_info contains the new group information.
- *     Return 0 if permission is granted.
  * @task_setnice:
  *     Check permission before setting the nice value of @p to @nice.
  *     @p contains the task_struct of process.
@@ -1139,13 +1067,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     Return the length of the string (including terminating NUL) or -ve if
  *      an error.
  *     May also return 0 (and a NULL buffer pointer) if there is no label.
- * @key_session_to_parent:
- *     Forcibly assign the session keyring from a process to its parent
- *     process.
- *     @cred: Pointer to process's credentials
- *     @parent_cred: Pointer to parent process's credentials
- *     @keyring: Proposed new session keyring
- *     Return 0 if permission is granted, -ve error otherwise.
  *
  * Security hooks affecting all System V IPC operations.
  *
@@ -1333,13 +1254,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  *     @cap contains the capability <include/linux/capability.h>.
  *     @audit: Whether to write an audit message or not
  *     Return 0 if the capability is granted for @tsk.
- * @acct:
- *     Check permission before enabling or disabling process accounting.  If
- *     accounting is being enabled, then @file refers to the open file used to
- *     store accounting records.  If accounting is being disabled, then @file
- *     is NULL.
- *     @file contains the file structure for the accounting file (may be NULL).
- *     Return 0 if permission is granted.
  * @sysctl:
  *     Check permission before accessing the @table sysctl variable in the
  *     manner specified by @op.
@@ -1462,7 +1376,6 @@ struct security_operations {
                       const kernel_cap_t *permitted);
        int (*capable) (struct task_struct *tsk, const struct cred *cred,
                        int cap, int audit);
-       int (*acct) (struct file *file);
        int (*sysctl) (struct ctl_table *table, int op);
        int (*quotactl) (int cmds, int type, int id, struct super_block *sb);
        int (*quota_on) (struct dentry *dentry);
@@ -1484,18 +1397,9 @@ struct security_operations {
        int (*sb_statfs) (struct dentry *dentry);
        int (*sb_mount) (char *dev_name, struct path *path,
                         char *type, unsigned long flags, void *data);
-       int (*sb_check_sb) (struct vfsmount *mnt, struct path *path);
        int (*sb_umount) (struct vfsmount *mnt, int flags);
-       void (*sb_umount_close) (struct vfsmount *mnt);
-       void (*sb_umount_busy) (struct vfsmount *mnt);
-       void (*sb_post_remount) (struct vfsmount *mnt,
-                                unsigned long flags, void *data);
-       void (*sb_post_addmount) (struct vfsmount *mnt,
-                                 struct path *mountpoint);
        int (*sb_pivotroot) (struct path *old_path,
                             struct path *new_path);
-       void (*sb_post_pivotroot) (struct path *old_path,
-                                  struct path *new_path);
        int (*sb_set_mnt_opts) (struct super_block *sb,
                                struct security_mnt_opts *opts);
        void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
@@ -1544,7 +1448,6 @@ struct security_operations {
        int (*inode_permission) (struct inode *inode, int mask);
        int (*inode_setattr)    (struct dentry *dentry, struct iattr *attr);
        int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
-       void (*inode_delete) (struct inode *inode);
        int (*inode_setxattr) (struct dentry *dentry, const char *name,
                               const void *value, size_t size, int flags);
        void (*inode_post_setxattr) (struct dentry *dentry, const char *name,
@@ -1585,20 +1488,16 @@ struct security_operations {
        void (*cred_free) (struct cred *cred);
        int (*cred_prepare)(struct cred *new, const struct cred *old,
                            gfp_t gfp);
-       void (*cred_commit)(struct cred *new, const struct cred *old);
        void (*cred_transfer)(struct cred *new, const struct cred *old);
        int (*kernel_act_as)(struct cred *new, u32 secid);
        int (*kernel_create_files_as)(struct cred *new, struct inode *inode);
        int (*kernel_module_request)(char *kmod_name);
-       int (*task_setuid) (uid_t id0, uid_t id1, uid_t id2, int flags);
        int (*task_fix_setuid) (struct cred *new, const struct cred *old,
                                int flags);
-       int (*task_setgid) (gid_t id0, gid_t id1, gid_t id2, int flags);
        int (*task_setpgid) (struct task_struct *p, pid_t pgid);
        int (*task_getpgid) (struct task_struct *p);
        int (*task_getsid) (struct task_struct *p);
        void (*task_getsecid) (struct task_struct *p, u32 *secid);
-       int (*task_setgroups) (struct group_info *group_info);
        int (*task_setnice) (struct task_struct *p, int nice);
        int (*task_setioprio) (struct task_struct *p, int ioprio);
        int (*task_getioprio) (struct task_struct *p);
@@ -1728,9 +1627,6 @@ struct security_operations {
                               const struct cred *cred,
                               key_perm_t perm);
        int (*key_getsecurity)(struct key *key, char **_buffer);
-       int (*key_session_to_parent)(const struct cred *cred,
-                                    const struct cred *parent_cred,
-                                    struct key *key);
 #endif /* CONFIG_KEYS */
 
 #ifdef CONFIG_AUDIT
@@ -1761,7 +1657,6 @@ int security_capset(struct cred *new, const struct cred *old,
 int security_capable(int cap);
 int security_real_capable(struct task_struct *tsk, int cap);
 int security_real_capable_noaudit(struct task_struct *tsk, int cap);
-int security_acct(struct file *file);
 int security_sysctl(struct ctl_table *table, int op);
 int security_quotactl(int cmds, int type, int id, struct super_block *sb);
 int security_quota_on(struct dentry *dentry);
@@ -1783,14 +1678,8 @@ int security_sb_show_options(struct seq_file *m, struct super_block *sb);
 int security_sb_statfs(struct dentry *dentry);
 int security_sb_mount(char *dev_name, struct path *path,
                      char *type, unsigned long flags, void *data);
-int security_sb_check_sb(struct vfsmount *mnt, struct path *path);
 int security_sb_umount(struct vfsmount *mnt, int flags);
-void security_sb_umount_close(struct vfsmount *mnt);
-void security_sb_umount_busy(struct vfsmount *mnt);
-void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data);
-void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
 int security_sb_pivotroot(struct path *old_path, struct path *new_path);
-void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
 int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
 void security_sb_clone_mnt_opts(const struct super_block *oldsb,
                                struct super_block *newsb);
@@ -1816,7 +1705,6 @@ int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd);
 int security_inode_permission(struct inode *inode, int mask);
 int security_inode_setattr(struct dentry *dentry, struct iattr *attr);
 int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry);
-void security_inode_delete(struct inode *inode);
 int security_inode_setxattr(struct dentry *dentry, const char *name,
                            const void *value, size_t size, int flags);
 void security_inode_post_setxattr(struct dentry *dentry, const char *name,
@@ -1850,20 +1738,16 @@ int security_task_create(unsigned long clone_flags);
 int security_cred_alloc_blank(struct cred *cred, gfp_t gfp);
 void security_cred_free(struct cred *cred);
 int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp);
-void security_commit_creds(struct cred *new, const struct cred *old);
 void security_transfer_creds(struct cred *new, const struct cred *old);
 int security_kernel_act_as(struct cred *new, u32 secid);
 int security_kernel_create_files_as(struct cred *new, struct inode *inode);
 int security_kernel_module_request(char *kmod_name);
-int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags);
 int security_task_fix_setuid(struct cred *new, const struct cred *old,
                             int flags);
-int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags);
 int security_task_setpgid(struct task_struct *p, pid_t pgid);
 int security_task_getpgid(struct task_struct *p);
 int security_task_getsid(struct task_struct *p);
 void security_task_getsecid(struct task_struct *p, u32 *secid);
-int security_task_setgroups(struct group_info *group_info);
 int security_task_setnice(struct task_struct *p, int nice);
 int security_task_setioprio(struct task_struct *p, int ioprio);
 int security_task_getioprio(struct task_struct *p);
@@ -1990,11 +1874,6 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap)
        return ret;
 }
 
-static inline int security_acct(struct file *file)
-{
-       return 0;
-}
-
 static inline int security_sysctl(struct ctl_table *table, int op)
 {
        return 0;
@@ -2099,41 +1978,17 @@ static inline int security_sb_mount(char *dev_name, struct path *path,
        return 0;
 }
 
-static inline int security_sb_check_sb(struct vfsmount *mnt,
-                                      struct path *path)
-{
-       return 0;
-}
-
 static inline int security_sb_umount(struct vfsmount *mnt, int flags)
 {
        return 0;
 }
 
-static inline void security_sb_umount_close(struct vfsmount *mnt)
-{ }
-
-static inline void security_sb_umount_busy(struct vfsmount *mnt)
-{ }
-
-static inline void security_sb_post_remount(struct vfsmount *mnt,
-                                            unsigned long flags, void *data)
-{ }
-
-static inline void security_sb_post_addmount(struct vfsmount *mnt,
-                                            struct path *mountpoint)
-{ }
-
 static inline int security_sb_pivotroot(struct path *old_path,
                                        struct path *new_path)
 {
        return 0;
 }
 
-static inline void security_sb_post_pivotroot(struct path *old_path,
-                                             struct path *new_path)
-{ }
-
 static inline int security_sb_set_mnt_opts(struct super_block *sb,
                                           struct security_mnt_opts *opts)
 {
@@ -2249,9 +2104,6 @@ static inline int security_inode_getattr(struct vfsmount *mnt,
        return 0;
 }
 
-static inline void security_inode_delete(struct inode *inode)
-{ }
-
 static inline int security_inode_setxattr(struct dentry *dentry,
                const char *name, const void *value, size_t size, int flags)
 {
@@ -2398,11 +2250,6 @@ static inline int security_prepare_creds(struct cred *new,
        return 0;
 }
 
-static inline void security_commit_creds(struct cred *new,
-                                        const struct cred *old)
-{
-}
-
 static inline void security_transfer_creds(struct cred *new,
                                           const struct cred *old)
 {
@@ -2424,12 +2271,6 @@ static inline int security_kernel_module_request(char *kmod_name)
        return 0;
 }
 
-static inline int security_task_setuid(uid_t id0, uid_t id1, uid_t id2,
-                                      int flags)
-{
-       return 0;
-}
-
 static inline int security_task_fix_setuid(struct cred *new,
                                           const struct cred *old,
                                           int flags)
@@ -2437,12 +2278,6 @@ static inline int security_task_fix_setuid(struct cred *new,
        return cap_task_fix_setuid(new, old, flags);
 }
 
-static inline int security_task_setgid(gid_t id0, gid_t id1, gid_t id2,
-                                      int flags)
-{
-       return 0;
-}
-
 static inline int security_task_setpgid(struct task_struct *p, pid_t pgid)
 {
        return 0;
@@ -2463,11 +2298,6 @@ static inline void security_task_getsecid(struct task_struct *p, u32 *secid)
        *secid = 0;
 }
 
-static inline int security_task_setgroups(struct group_info *group_info)
-{
-       return 0;
-}
-
 static inline int security_task_setnice(struct task_struct *p, int nice)
 {
        return cap_task_setnice(p, nice);
@@ -3064,9 +2894,6 @@ void security_key_free(struct key *key);
 int security_key_permission(key_ref_t key_ref,
                            const struct cred *cred, key_perm_t perm);
 int security_key_getsecurity(struct key *key, char **_buffer);
-int security_key_session_to_parent(const struct cred *cred,
-                                  const struct cred *parent_cred,
-                                  struct key *key);
 
 #else
 
@@ -3094,13 +2921,6 @@ static inline int security_key_getsecurity(struct key *key, char **_buffer)
        return 0;
 }
 
-static inline int security_key_session_to_parent(const struct cred *cred,
-                                                const struct cred *parent_cred,
-                                                struct key *key)
-{
-       return 0;
-}
-
 #endif
 #endif /* CONFIG_KEYS */
 
index 193d4bf..f5364a1 100644 (file)
@@ -33,8 +33,8 @@ struct plat_sci_port {
        char            *clk;                   /* clock string */
        struct device   *dma_dev;
 #ifdef CONFIG_SERIAL_SH_SCI_DMA
-       enum sh_dmae_slave_chan_id dma_slave_tx;
-       enum sh_dmae_slave_chan_id dma_slave_rx;
+       unsigned int dma_slave_tx;
+       unsigned int dma_slave_rx;
 #endif
 };
 
diff --git a/include/linux/sh_clk.h b/include/linux/sh_clk.h
new file mode 100644 (file)
index 0000000..1636d1e
--- /dev/null
@@ -0,0 +1,150 @@
+#ifndef __SH_CLOCK_H
+#define __SH_CLOCK_H
+
+#include <linux/list.h>
+#include <linux/seq_file.h>
+#include <linux/cpufreq.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+
+struct clk;
+
+struct clk_ops {
+       void (*init)(struct clk *clk);
+       int (*enable)(struct clk *clk);
+       void (*disable)(struct clk *clk);
+       unsigned long (*recalc)(struct clk *clk);
+       int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
+       int (*set_parent)(struct clk *clk, struct clk *parent);
+       long (*round_rate)(struct clk *clk, unsigned long rate);
+};
+
+struct clk {
+       struct list_head        node;
+       const char              *name;
+       int                     id;
+
+       struct clk              *parent;
+       struct clk_ops          *ops;
+
+       struct list_head        children;
+       struct list_head        sibling;        /* node for children */
+
+       int                     usecount;
+
+       unsigned long           rate;
+       unsigned long           flags;
+
+       void __iomem            *enable_reg;
+       unsigned int            enable_bit;
+
+       unsigned long           arch_flags;
+       void                    *priv;
+       struct dentry           *dentry;
+       struct cpufreq_frequency_table *freq_table;
+};
+
+#define CLK_ENABLE_ON_INIT     (1 << 0)
+
+/* drivers/sh/clk.c */
+unsigned long followparent_recalc(struct clk *);
+void recalculate_root_clocks(void);
+void propagate_rate(struct clk *);
+int clk_reparent(struct clk *child, struct clk *parent);
+int clk_register(struct clk *);
+void clk_unregister(struct clk *);
+void clk_enable_init_clocks(void);
+
+/**
+ * clk_set_rate_ex - set the clock rate for a clock source, with additional parameter
+ * @clk: clock source
+ * @rate: desired clock rate in Hz
+ * @algo_id: algorithm id to be passed down to ops->set_rate
+ *
+ * Returns success (0) or negative errno.
+ */
+int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id);
+
+enum clk_sh_algo_id {
+       NO_CHANGE = 0,
+
+       IUS_N1_N1,
+       IUS_322,
+       IUS_522,
+       IUS_N11,
+
+       SB_N1,
+
+       SB3_N1,
+       SB3_32,
+       SB3_43,
+       SB3_54,
+
+       BP_N1,
+
+       IP_N1,
+};
+
+struct clk_div_mult_table {
+       unsigned int *divisors;
+       unsigned int nr_divisors;
+       unsigned int *multipliers;
+       unsigned int nr_multipliers;
+};
+
+struct cpufreq_frequency_table;
+void clk_rate_table_build(struct clk *clk,
+                         struct cpufreq_frequency_table *freq_table,
+                         int nr_freqs,
+                         struct clk_div_mult_table *src_table,
+                         unsigned long *bitmap);
+
+long clk_rate_table_round(struct clk *clk,
+                         struct cpufreq_frequency_table *freq_table,
+                         unsigned long rate);
+
+int clk_rate_table_find(struct clk *clk,
+                       struct cpufreq_frequency_table *freq_table,
+                       unsigned long rate);
+
+#define SH_CLK_MSTP32(_parent, _enable_reg, _enable_bit, _flags)       \
+{                                                                      \
+       .parent         = _parent,                                      \
+       .enable_reg     = (void __iomem *)_enable_reg,                  \
+       .enable_bit     = _enable_bit,                                  \
+       .flags          = _flags,                                       \
+}
+
+int sh_clk_mstp32_register(struct clk *clks, int nr);
+
+#define SH_CLK_DIV4(_parent, _reg, _shift, _div_bitmap, _flags)        \
+{                                                              \
+       .parent = _parent,                                      \
+       .enable_reg = (void __iomem *)_reg,                     \
+       .enable_bit = _shift,                                   \
+       .arch_flags = _div_bitmap,                              \
+       .flags = _flags,                                        \
+}
+
+struct clk_div4_table {
+       struct clk_div_mult_table *div_mult_table;
+       void (*kick)(struct clk *clk);
+};
+
+int sh_clk_div4_register(struct clk *clks, int nr,
+                        struct clk_div4_table *table);
+int sh_clk_div4_enable_register(struct clk *clks, int nr,
+                        struct clk_div4_table *table);
+int sh_clk_div4_reparent_register(struct clk *clks, int nr,
+                        struct clk_div4_table *table);
+
+#define SH_CLK_DIV6(_parent, _reg, _flags)     \
+{                                              \
+       .parent = _parent,                      \
+       .enable_reg = (void __iomem *)_reg,     \
+       .flags = _flags,                        \
+}
+
+int sh_clk_div6_register(struct clk *clks, int nr);
+
+#endif /* __SH_CLOCK_H */
diff --git a/include/linux/sh_dma.h b/include/linux/sh_dma.h
new file mode 100644 (file)
index 0000000..b08cd4e
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * Header for the new SH dmaengine driver
+ *
+ * Copyright (C) 2010 Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef SH_DMA_H
+#define SH_DMA_H
+
+#include <linux/list.h>
+#include <linux/dmaengine.h>
+
+/* Used by slave DMA clients to request DMA to/from a specific peripheral */
+struct sh_dmae_slave {
+       unsigned int                    slave_id; /* Set by the platform */
+       struct device                   *dma_dev; /* Set by the platform */
+       const struct sh_dmae_slave_config       *config;  /* Set by the driver */
+};
+
+struct sh_dmae_regs {
+       u32 sar; /* SAR / source address */
+       u32 dar; /* DAR / destination address */
+       u32 tcr; /* TCR / transfer count */
+};
+
+struct sh_desc {
+       struct sh_dmae_regs hw;
+       struct list_head node;
+       struct dma_async_tx_descriptor async_tx;
+       enum dma_data_direction direction;
+       dma_cookie_t cookie;
+       size_t partial;
+       int chunks;
+       int mark;
+};
+
+struct sh_dmae_slave_config {
+       unsigned int                    slave_id;
+       dma_addr_t                      addr;
+       u32                             chcr;
+       char                            mid_rid;
+};
+
+struct sh_dmae_channel {
+       unsigned int    offset;
+       unsigned int    dmars;
+       unsigned int    dmars_bit;
+};
+
+struct sh_dmae_pdata {
+       const struct sh_dmae_slave_config *slave;
+       int slave_num;
+       const struct sh_dmae_channel *channel;
+       int channel_num;
+       unsigned int ts_low_shift;
+       unsigned int ts_low_mask;
+       unsigned int ts_high_shift;
+       unsigned int ts_high_mask;
+       const unsigned int *ts_shift;
+       int ts_shift_num;
+       u16 dmaor_init;
+};
+
+/* DMA register */
+#define SAR    0x00
+#define DAR    0x04
+#define TCR    0x08
+#define CHCR   0x0C
+#define DMAOR  0x40
+
+/* DMAOR definitions */
+#define DMAOR_AE       0x00000004
+#define DMAOR_NMIF     0x00000002
+#define DMAOR_DME      0x00000001
+
+/* Definitions for the SuperH DMAC */
+#define REQ_L  0x00000000
+#define REQ_E  0x00080000
+#define RACK_H 0x00000000
+#define RACK_L 0x00040000
+#define ACK_R  0x00000000
+#define ACK_W  0x00020000
+#define ACK_H  0x00000000
+#define ACK_L  0x00010000
+#define DM_INC 0x00004000
+#define DM_DEC 0x00008000
+#define DM_FIX 0x0000c000
+#define SM_INC 0x00001000
+#define SM_DEC 0x00002000
+#define SM_FIX 0x00003000
+#define RS_IN  0x00000200
+#define RS_OUT 0x00000300
+#define TS_BLK 0x00000040
+#define TM_BUR 0x00000020
+#define CHCR_DE        0x00000001
+#define CHCR_TE        0x00000002
+#define CHCR_IE        0x00000004
+
+#endif
index 51d288d..0d6cd38 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __SH_INTC_H
 #define __SH_INTC_H
 
+#include <linux/ioport.h>
+
 typedef unsigned char intc_enum;
 
 struct intc_vect {
@@ -21,6 +23,9 @@ struct intc_group {
 struct intc_mask_reg {
        unsigned long set_reg, clr_reg, reg_width;
        intc_enum enum_ids[32];
+#ifdef CONFIG_INTC_BALANCING
+       unsigned long dist_reg;
+#endif
 #ifdef CONFIG_SMP
        unsigned long smp;
 #endif
@@ -39,8 +44,14 @@ struct intc_sense_reg {
        intc_enum enum_ids[16];
 };
 
+#ifdef CONFIG_INTC_BALANCING
+#define INTC_SMP_BALANCING(reg)        .dist_reg = (reg)
+#else
+#define INTC_SMP_BALANCING(reg)
+#endif
+
 #ifdef CONFIG_SMP
-#define INTC_SMP(stride, nr) .smp = (stride) | ((nr) << 8)
+#define INTC_SMP(stride, nr)   .smp = (stride) | ((nr) << 8)
 #else
 #define INTC_SMP(stride, nr)
 #endif
@@ -71,6 +82,8 @@ struct intc_hw_desc {
 
 struct intc_desc {
        char *name;
+       struct resource *resource;
+       unsigned int num_resources;
        intc_enum force_enable;
        intc_enum force_disable;
        struct intc_hw_desc hw;
@@ -92,9 +105,18 @@ struct intc_desc symbol __initdata = {                                      \
                           prio_regs, sense_regs, ack_regs),            \
 }
 
-void __init register_intc_controller(struct intc_desc *desc);
+int __init register_intc_controller(struct intc_desc *desc);
 int intc_set_priority(unsigned int irq, unsigned int prio);
 
+#ifdef CONFIG_INTC_USERIMASK
+int register_intc_userimask(unsigned long addr);
+#else
+static inline int register_intc_userimask(unsigned long addr)
+{
+       return 0;
+}
+#endif
+
 int reserve_irq_vector(unsigned int irq);
 void reserve_irq_legacy(void);
 
index 4d5ecb2..4d5d2f5 100644 (file)
@@ -27,6 +27,8 @@
 #ifndef _LINUX_SRCU_H
 #define _LINUX_SRCU_H
 
+#include <linux/mutex.h>
+
 struct srcu_struct_array {
        int c[2];
 };
@@ -84,8 +86,8 @@ long srcu_batches_completed(struct srcu_struct *sp);
 /**
  * srcu_read_lock_held - might we be in SRCU read-side critical section?
  *
- * If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in
- * an SRCU read-side critical section.  In absence of CONFIG_PROVE_LOCKING,
+ * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an SRCU
+ * read-side critical section.  In absence of CONFIG_DEBUG_LOCK_ALLOC,
  * this assumes we are in an SRCU read-side critical section unless it can
  * prove otherwise.
  */
index baba3a2..6b524a0 100644 (file)
 #ifndef _LINUX_STOP_MACHINE
 #define _LINUX_STOP_MACHINE
-/* "Bogolock": stop the entire machine, disable interrupts.  This is a
-   very heavy lock, which is equivalent to grabbing every spinlock
-   (and more).  So the "read" side to such a lock is anything which
-   disables preeempt. */
+
 #include <linux/cpu.h>
 #include <linux/cpumask.h>
+#include <linux/list.h>
 #include <asm/system.h>
 
+/*
+ * stop_cpu[s]() is simplistic per-cpu maximum priority cpu
+ * monopolization mechanism.  The caller can specify a non-sleeping
+ * function to be executed on a single or multiple cpus preempting all
+ * other processes and monopolizing those cpus until it finishes.
+ *
+ * Resources for this mechanism are preallocated when a cpu is brought
+ * up and requests are guaranteed to be served as long as the target
+ * cpus are online.
+ */
+typedef int (*cpu_stop_fn_t)(void *arg);
+
+#ifdef CONFIG_SMP
+
+struct cpu_stop_work {
+       struct list_head        list;           /* cpu_stopper->works */
+       cpu_stop_fn_t           fn;
+       void                    *arg;
+       struct cpu_stop_done    *done;
+};
+
+int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
+void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
+                        struct cpu_stop_work *work_buf);
+int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg);
+int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg);
+
+#else  /* CONFIG_SMP */
+
+#include <linux/workqueue.h>
+
+struct cpu_stop_work {
+       struct work_struct      work;
+       cpu_stop_fn_t           fn;
+       void                    *arg;
+};
+
+static inline int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
+{
+       int ret = -ENOENT;
+       preempt_disable();
+       if (cpu == smp_processor_id())
+               ret = fn(arg);
+       preempt_enable();
+       return ret;
+}
+
+static void stop_one_cpu_nowait_workfn(struct work_struct *work)
+{
+       struct cpu_stop_work *stwork =
+               container_of(work, struct cpu_stop_work, work);
+       preempt_disable();
+       stwork->fn(stwork->arg);
+       preempt_enable();
+}
+
+static inline void stop_one_cpu_nowait(unsigned int cpu,
+                                      cpu_stop_fn_t fn, void *arg,
+                                      struct cpu_stop_work *work_buf)
+{
+       if (cpu == smp_processor_id()) {
+               INIT_WORK(&work_buf->work, stop_one_cpu_nowait_workfn);
+               work_buf->fn = fn;
+               work_buf->arg = arg;
+               schedule_work(&work_buf->work);
+       }
+}
+
+static inline int stop_cpus(const struct cpumask *cpumask,
+                           cpu_stop_fn_t fn, void *arg)
+{
+       if (cpumask_test_cpu(raw_smp_processor_id(), cpumask))
+               return stop_one_cpu(raw_smp_processor_id(), fn, arg);
+       return -ENOENT;
+}
+
+static inline int try_stop_cpus(const struct cpumask *cpumask,
+                               cpu_stop_fn_t fn, void *arg)
+{
+       return stop_cpus(cpumask, fn, arg);
+}
+
+#endif /* CONFIG_SMP */
+
+/*
+ * stop_machine "Bogolock": stop the entire machine, disable
+ * interrupts.  This is a very heavy lock, which is equivalent to
+ * grabbing every spinlock (and more).  So the "read" side to such a
+ * lock is anything which disables preeempt.
+ */
 #if defined(CONFIG_STOP_MACHINE) && defined(CONFIG_SMP)
 
 /**
@@ -36,24 +124,7 @@ int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
  */
 int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus);
 
-/**
- * stop_machine_create: create all stop_machine threads
- *
- * Description: This causes all stop_machine threads to be created before
- * stop_machine actually gets called. This can be used by subsystems that
- * need a non failing stop_machine infrastructure.
- */
-int stop_machine_create(void);
-
-/**
- * stop_machine_destroy: destroy all stop_machine threads
- *
- * Description: This causes all stop_machine threads which were created with
- * stop_machine_create to be destroyed again.
- */
-void stop_machine_destroy(void);
-
-#else
+#else   /* CONFIG_STOP_MACHINE && CONFIG_SMP */
 
 static inline int stop_machine(int (*fn)(void *), void *data,
                               const struct cpumask *cpus)
@@ -65,8 +136,5 @@ static inline int stop_machine(int (*fn)(void *), void *data,
        return ret;
 }
 
-static inline int stop_machine_create(void) { return 0; }
-static inline void stop_machine_destroy(void) { }
-
-#endif /* CONFIG_SMP */
-#endif /* _LINUX_STOP_MACHINE */
+#endif /* CONFIG_STOP_MACHINE && CONFIG_SMP */
+#endif /* _LINUX_STOP_MACHINE */
index 996df4d..87d7ec0 100644 (file)
@@ -54,6 +54,7 @@ struct rpc_cred {
 #define RPCAUTH_CRED_NEW       0
 #define RPCAUTH_CRED_UPTODATE  1
 #define RPCAUTH_CRED_HASHED    2
+#define RPCAUTH_CRED_NEGATIVE  3
 
 #define RPCAUTH_CRED_MAGIC     0x0f4aa4f0
 
index d48d4e6..671538d 100644 (file)
@@ -82,6 +82,7 @@ struct gss_cred {
        enum rpc_gss_svc        gc_service;
        struct gss_cl_ctx       *gc_ctx;
        struct gss_upcall_msg   *gc_upcall;
+       unsigned long           gc_upcall_timestamp;
        unsigned char           gc_machine_cred : 1;
 };
 
index 03f3333..5d8048b 100644 (file)
@@ -35,7 +35,8 @@ int gss_import_sec_context(
                const void*             input_token,
                size_t                  bufsize,
                struct gss_api_mech     *mech,
-               struct gss_ctx          **ctx_id);
+               struct gss_ctx          **ctx_id,
+               gfp_t                   gfp_mask);
 u32 gss_get_mic(
                struct gss_ctx          *ctx_id,
                struct xdr_buf          *message,
@@ -80,6 +81,8 @@ struct gss_api_mech {
        /* pseudoflavors supported by this mechanism: */
        int                     gm_pf_num;
        struct pf_desc *        gm_pfs;
+       /* Should the following be a callback operation instead? */
+       const char              *gm_upcall_enctypes;
 };
 
 /* and must provide the following operations: */
@@ -87,7 +90,8 @@ struct gss_api_ops {
        int (*gss_import_sec_context)(
                        const void              *input_token,
                        size_t                  bufsize,
-                       struct gss_ctx          *ctx_id);
+                       struct gss_ctx          *ctx_id,
+                       gfp_t                   gfp_mask);
        u32 (*gss_get_mic)(
                        struct gss_ctx          *ctx_id,
                        struct xdr_buf          *message,
index e7bbdba..5af2931 100644 (file)
@@ -4,7 +4,7 @@
  *  Adapted from MIT Kerberos 5-1.2.1 lib/include/krb5.h,
  *  lib/gssapi/krb5/gssapiP_krb5.h, and others
  *
- *  Copyright (c) 2000 The Regents of the University of Michigan.
+ *  Copyright (c) 2000-2008 The Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  Andy Adamson   <andros@umich.edu>
  *
  */
 
+#include <linux/crypto.h>
 #include <linux/sunrpc/auth_gss.h>
 #include <linux/sunrpc/gss_err.h>
 #include <linux/sunrpc/gss_asn1.h>
 
+/* Length of constant used in key derivation */
+#define GSS_KRB5_K5CLENGTH (5)
+
+/* Maximum key length (in bytes) for the supported crypto algorithms*/
+#define GSS_KRB5_MAX_KEYLEN (32)
+
+/* Maximum checksum function output for the supported crypto algorithms */
+#define GSS_KRB5_MAX_CKSUM_LEN  (20)
+
+/* Maximum blocksize for the supported crypto algorithms */
+#define GSS_KRB5_MAX_BLOCKSIZE  (16)
+
+struct krb5_ctx;
+
+struct gss_krb5_enctype {
+       const u32               etype;          /* encryption (key) type */
+       const u32               ctype;          /* checksum type */
+       const char              *name;          /* "friendly" name */
+       const char              *encrypt_name;  /* crypto encrypt name */
+       const char              *cksum_name;    /* crypto checksum name */
+       const u16               signalg;        /* signing algorithm */
+       const u16               sealalg;        /* sealing algorithm */
+       const u32               blocksize;      /* encryption blocksize */
+       const u32               conflen;        /* confounder length
+                                                  (normally the same as
+                                                  the blocksize) */
+       const u32               cksumlength;    /* checksum length */
+       const u32               keyed_cksum;    /* is it a keyed cksum? */
+       const u32               keybytes;       /* raw key len, in bytes */
+       const u32               keylength;      /* final key len, in bytes */
+       u32 (*encrypt) (struct crypto_blkcipher *tfm,
+                       void *iv, void *in, void *out,
+                       int length);            /* encryption function */
+       u32 (*decrypt) (struct crypto_blkcipher *tfm,
+                       void *iv, void *in, void *out,
+                       int length);            /* decryption function */
+       u32 (*mk_key) (const struct gss_krb5_enctype *gk5e,
+                      struct xdr_netobj *in,
+                      struct xdr_netobj *out); /* complete key generation */
+       u32 (*encrypt_v2) (struct krb5_ctx *kctx, u32 offset,
+                          struct xdr_buf *buf, int ec,
+                          struct page **pages); /* v2 encryption function */
+       u32 (*decrypt_v2) (struct krb5_ctx *kctx, u32 offset,
+                          struct xdr_buf *buf, u32 *headskip,
+                          u32 *tailskip);      /* v2 decryption function */
+};
+
+/* krb5_ctx flags definitions */
+#define KRB5_CTX_FLAG_INITIATOR         0x00000001
+#define KRB5_CTX_FLAG_CFX               0x00000002
+#define KRB5_CTX_FLAG_ACCEPTOR_SUBKEY   0x00000004
+
 struct krb5_ctx {
        int                     initiate; /* 1 = initiating, 0 = accepting */
+       u32                     enctype;
+       u32                     flags;
+       const struct gss_krb5_enctype *gk5e; /* enctype-specific info */
        struct crypto_blkcipher *enc;
        struct crypto_blkcipher *seq;
+       struct crypto_blkcipher *acceptor_enc;
+       struct crypto_blkcipher *initiator_enc;
+       struct crypto_blkcipher *acceptor_enc_aux;
+       struct crypto_blkcipher *initiator_enc_aux;
+       u8                      Ksess[GSS_KRB5_MAX_KEYLEN]; /* session key */
+       u8                      cksum[GSS_KRB5_MAX_KEYLEN];
        s32                     endtime;
        u32                     seq_send;
+       u64                     seq_send64;
        struct xdr_netobj       mech_used;
+       u8                      initiator_sign[GSS_KRB5_MAX_KEYLEN];
+       u8                      acceptor_sign[GSS_KRB5_MAX_KEYLEN];
+       u8                      initiator_seal[GSS_KRB5_MAX_KEYLEN];
+       u8                      acceptor_seal[GSS_KRB5_MAX_KEYLEN];
+       u8                      initiator_integ[GSS_KRB5_MAX_KEYLEN];
+       u8                      acceptor_integ[GSS_KRB5_MAX_KEYLEN];
 };
 
 extern spinlock_t krb5_seq_lock;
@@ -57,6 +126,18 @@ extern spinlock_t krb5_seq_lock;
 #define KG_TOK_MIC_MSG    0x0101
 #define KG_TOK_WRAP_MSG   0x0201
 
+#define KG2_TOK_INITIAL     0x0101
+#define KG2_TOK_RESPONSE    0x0202
+#define KG2_TOK_MIC         0x0404
+#define KG2_TOK_WRAP        0x0504
+
+#define KG2_TOKEN_FLAG_SENTBYACCEPTOR   0x01
+#define KG2_TOKEN_FLAG_SEALED           0x02
+#define KG2_TOKEN_FLAG_ACCEPTORSUBKEY   0x04
+
+#define KG2_RESP_FLAG_ERROR             0x0001
+#define KG2_RESP_FLAG_DELEG_OK          0x0002
+
 enum sgn_alg {
        SGN_ALG_DES_MAC_MD5 = 0x0000,
        SGN_ALG_MD2_5 = 0x0001,
@@ -81,6 +162,9 @@ enum seal_alg {
 #define CKSUMTYPE_RSA_MD5_DES          0x0008
 #define CKSUMTYPE_NIST_SHA             0x0009
 #define CKSUMTYPE_HMAC_SHA1_DES3       0x000c
+#define CKSUMTYPE_HMAC_SHA1_96_AES128   0x000f
+#define CKSUMTYPE_HMAC_SHA1_96_AES256   0x0010
+#define CKSUMTYPE_HMAC_MD5_ARCFOUR      -138 /* Microsoft md5 hmac cksumtype */
 
 /* from gssapi_err_krb5.h */
 #define KG_CCACHE_NOMATCH                        (39756032L)
@@ -111,11 +195,56 @@ enum seal_alg {
 #define ENCTYPE_DES3_CBC_RAW    0x0006 /* DES-3 cbc mode raw */
 #define ENCTYPE_DES_HMAC_SHA1   0x0008
 #define ENCTYPE_DES3_CBC_SHA1   0x0010
+#define ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011
+#define ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012
+#define ENCTYPE_ARCFOUR_HMAC            0x0017
+#define ENCTYPE_ARCFOUR_HMAC_EXP        0x0018
 #define ENCTYPE_UNKNOWN         0x01ff
 
-s32
-make_checksum(char *, char *header, int hdrlen, struct xdr_buf *body,
-                  int body_offset, struct xdr_netobj *cksum);
+/*
+ * Constants used for key derivation
+ */
+/* for 3DES */
+#define KG_USAGE_SEAL (22)
+#define KG_USAGE_SIGN (23)
+#define KG_USAGE_SEQ  (24)
+
+/* from rfc3961 */
+#define KEY_USAGE_SEED_CHECKSUM         (0x99)
+#define KEY_USAGE_SEED_ENCRYPTION       (0xAA)
+#define KEY_USAGE_SEED_INTEGRITY        (0x55)
+
+/* from rfc4121 */
+#define KG_USAGE_ACCEPTOR_SEAL  (22)
+#define KG_USAGE_ACCEPTOR_SIGN  (23)
+#define KG_USAGE_INITIATOR_SEAL (24)
+#define KG_USAGE_INITIATOR_SIGN (25)
+
+/*
+ * This compile-time check verifies that we will not exceed the
+ * slack space allotted by the client and server auth_gss code
+ * before they call gss_wrap().
+ */
+#define GSS_KRB5_MAX_SLACK_NEEDED \
+       (GSS_KRB5_TOK_HDR_LEN     /* gss token header */         \
+       + GSS_KRB5_MAX_CKSUM_LEN  /* gss token checksum */       \
+       + GSS_KRB5_MAX_BLOCKSIZE  /* confounder */               \
+       + GSS_KRB5_MAX_BLOCKSIZE  /* possible padding */         \
+       + GSS_KRB5_TOK_HDR_LEN    /* encrypted hdr in v2 token */\
+       + GSS_KRB5_MAX_CKSUM_LEN  /* encryption hmac */          \
+       + 4 + 4                   /* RPC verifier */             \
+       + GSS_KRB5_TOK_HDR_LEN                                   \
+       + GSS_KRB5_MAX_CKSUM_LEN)
+
+u32
+make_checksum(struct krb5_ctx *kctx, char *header, int hdrlen,
+               struct xdr_buf *body, int body_offset, u8 *cksumkey,
+               unsigned int usage, struct xdr_netobj *cksumout);
+
+u32
+make_checksum_v2(struct krb5_ctx *, char *header, int hdrlen,
+                struct xdr_buf *body, int body_offset, u8 *key,
+                unsigned int usage, struct xdr_netobj *cksum);
 
 u32 gss_get_mic_kerberos(struct gss_ctx *, struct xdr_buf *,
                struct xdr_netobj *);
@@ -149,11 +278,54 @@ gss_decrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *inbuf,
                    int offset);
 
 s32
-krb5_make_seq_num(struct crypto_blkcipher *key,
+krb5_make_seq_num(struct krb5_ctx *kctx,
+               struct crypto_blkcipher *key,
                int direction,
                u32 seqnum, unsigned char *cksum, unsigned char *buf);
 
 s32
-krb5_get_seq_num(struct crypto_blkcipher *key,
+krb5_get_seq_num(struct krb5_ctx *kctx,
               unsigned char *cksum,
               unsigned char *buf, int *direction, u32 *seqnum);
+
+int
+xdr_extend_head(struct xdr_buf *buf, unsigned int base, unsigned int shiftlen);
+
+u32
+krb5_derive_key(const struct gss_krb5_enctype *gk5e,
+               const struct xdr_netobj *inkey,
+               struct xdr_netobj *outkey,
+               const struct xdr_netobj *in_constant,
+               gfp_t gfp_mask);
+
+u32
+gss_krb5_des3_make_key(const struct gss_krb5_enctype *gk5e,
+                      struct xdr_netobj *randombits,
+                      struct xdr_netobj *key);
+
+u32
+gss_krb5_aes_make_key(const struct gss_krb5_enctype *gk5e,
+                     struct xdr_netobj *randombits,
+                     struct xdr_netobj *key);
+
+u32
+gss_krb5_aes_encrypt(struct krb5_ctx *kctx, u32 offset,
+                    struct xdr_buf *buf, int ec,
+                    struct page **pages);
+
+u32
+gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset,
+                    struct xdr_buf *buf, u32 *plainoffset,
+                    u32 *plainlen);
+
+int
+krb5_rc4_setup_seq_key(struct krb5_ctx *kctx,
+                      struct crypto_blkcipher *cipher,
+                      unsigned char *cksum);
+
+int
+krb5_rc4_setup_enc_key(struct krb5_ctx *kctx,
+                      struct crypto_blkcipher *cipher,
+                      s32 seqnum);
+void
+gss_krb5_make_confounder(char *p, u32 conflen);
index 77f78e5..b6edbc0 100644 (file)
@@ -26,6 +26,7 @@
 #define _LINUX_SUNRPC_METRICS_H
 
 #include <linux/seq_file.h>
+#include <linux/ktime.h>
 
 #define RPC_IOSTATS_VERS       "1.0"
 
@@ -58,9 +59,9 @@ struct rpc_iostats {
         * and the total time the request spent from init to release
         * are measured.
         */
-       unsigned long long      om_queue,       /* jiffies queued for xmit */
-                               om_rtt,         /* jiffies for RPC RTT */
-                               om_execute;     /* jiffies for RPC execution */
+       ktime_t                 om_queue,       /* queued for xmit */
+                               om_rtt,         /* RPC RTT */
+                               om_execute;     /* RPC execution */
 } ____cacheline_aligned;
 
 struct rpc_task;
index 7bc7fd5..7be4f3a 100644 (file)
@@ -10,6 +10,7 @@
 #define _LINUX_SUNRPC_SCHED_H_
 
 #include <linux/timer.h>
+#include <linux/ktime.h>
 #include <linux/sunrpc/types.h>
 #include <linux/spinlock.h>
 #include <linux/wait.h>
@@ -40,21 +41,15 @@ struct rpc_wait {
  * This is the RPC task struct
  */
 struct rpc_task {
-#ifdef RPC_DEBUG
-       unsigned long           tk_magic;       /* 0xf00baa */
-#endif
        atomic_t                tk_count;       /* Reference count */
        struct list_head        tk_task;        /* global list of tasks */
        struct rpc_clnt *       tk_client;      /* RPC client */
        struct rpc_rqst *       tk_rqstp;       /* RPC request */
-       int                     tk_status;      /* result of last operation */
 
        /*
         * RPC call state
         */
        struct rpc_message      tk_msg;         /* RPC call info */
-       __u8                    tk_garb_retry;
-       __u8                    tk_cred_retry;
 
        /*
         * callback     to be executed after waking up
@@ -67,7 +62,6 @@ struct rpc_task {
        void *                  tk_calldata;
 
        unsigned long           tk_timeout;     /* timeout for rpc_sleep() */
-       unsigned short          tk_flags;       /* misc flags */
        unsigned long           tk_runstate;    /* Task run status */
        struct workqueue_struct *tk_workqueue;  /* Normally rpciod, but could
                                                 * be any workqueue
@@ -78,17 +72,19 @@ struct rpc_task {
                struct rpc_wait         tk_wait;        /* RPC wait */
        } u;
 
-       unsigned short          tk_timeouts;    /* maj timeouts */
-       size_t                  tk_bytes_sent;  /* total bytes sent */
-       unsigned long           tk_start;       /* RPC task init timestamp */
-       long                    tk_rtt;         /* round-trip time (jiffies) */
+       ktime_t                 tk_start;       /* RPC task init timestamp */
 
        pid_t                   tk_owner;       /* Process id for batching tasks */
-       unsigned char           tk_priority : 2;/* Task priority */
+       int                     tk_status;      /* result of last operation */
+       unsigned short          tk_flags;       /* misc flags */
+       unsigned short          tk_timeouts;    /* maj timeouts */
 
 #ifdef RPC_DEBUG
        unsigned short          tk_pid;         /* debugging aid */
 #endif
+       unsigned char           tk_priority : 2,/* Task priority */
+                               tk_garb_retry : 2,
+                               tk_cred_retry : 2;
 };
 #define tk_xprt                        tk_client->cl_xprt
 
index f5cc089..35cf2e8 100644 (file)
@@ -1,7 +1,10 @@
 /*
- * include/linux/sunrpc/xdr.h
+ * XDR standard data types and function declarations
  *
  * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
+ *
+ * Based on:
+ *   RFC 4506 "XDR: External Data Representation Standard", May 2006
  */
 
 #ifndef _SUNRPC_XDR_H_
@@ -62,7 +65,6 @@ struct xdr_buf {
 
        unsigned int    buflen,         /* Total length of storage buffer */
                        len;            /* Length of XDR encoded message */
-
 };
 
 /*
@@ -178,7 +180,7 @@ struct xdr_array2_desc {
 };
 
 extern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
-                             struct xdr_array2_desc *desc);
+                            struct xdr_array2_desc *desc);
 extern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
                             struct xdr_array2_desc *desc);
 
index 6f9457a..b514703 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/socket.h>
 #include <linux/in.h>
 #include <linux/kref.h>
+#include <linux/ktime.h>
 #include <linux/sunrpc/sched.h>
 #include <linux/sunrpc/xdr.h>
 #include <linux/sunrpc/msg_prot.h>
@@ -65,8 +66,6 @@ struct rpc_rqst {
        struct rpc_task *       rq_task;        /* RPC task data */
        __be32                  rq_xid;         /* request XID */
        int                     rq_cong;        /* has incremented xprt->cong */
-       int                     rq_reply_bytes_recvd;   /* number of reply */
-                                                       /* bytes received */
        u32                     rq_seqno;       /* gss seq no. used on req. */
        int                     rq_enc_pages_num;
        struct page             **rq_enc_pages; /* scratch pages for use by
@@ -77,12 +76,16 @@ struct rpc_rqst {
        __u32 *                 rq_buffer;      /* XDR encode buffer */
        size_t                  rq_callsize,
                                rq_rcvsize;
+       size_t                  rq_xmit_bytes_sent;     /* total bytes sent */
+       size_t                  rq_reply_bytes_recvd;   /* total reply bytes */
+                                                       /* received */
 
        struct xdr_buf          rq_private_buf;         /* The receive buffer
                                                         * used in the softirq.
                                                         */
        unsigned long           rq_majortimeo;  /* major timeout alarm */
        unsigned long           rq_timeout;     /* Current timeout value */
+       ktime_t                 rq_rtt;         /* round-trip time */
        unsigned int            rq_retries;     /* # of retries */
        unsigned int            rq_connect_cookie;
                                                /* A cookie used to track the
@@ -94,7 +97,7 @@ struct rpc_rqst {
         */
        u32                     rq_bytes_sent;  /* Bytes we have sent */
 
-       unsigned long           rq_xtime;       /* when transmitted */
+       ktime_t                 rq_xtime;       /* transmit time stamp */
        int                     rq_ntrans;
 
 #if defined(CONFIG_NFS_V4_1)
@@ -174,8 +177,7 @@ struct rpc_xprt {
        /*
         * Connection of transports
         */
-       unsigned long           connect_timeout,
-                               bind_timeout,
+       unsigned long           bind_timeout,
                                reestablish_timeout;
        unsigned int            connect_cookie; /* A cookie that gets bumped
                                                   every time the transport
@@ -294,7 +296,6 @@ void                        xprt_set_retrans_timeout_rtt(struct rpc_task *task);
 void                   xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status);
 void                   xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action);
 void                   xprt_write_space(struct rpc_xprt *xprt);
-void                   xprt_update_rtt(struct rpc_task *task);
 void                   xprt_adjust_cwnd(struct rpc_task *task, int result);
 struct rpc_rqst *      xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid);
 void                   xprt_complete_rqst(struct rpc_task *task, int copied);
index d2ae79e..b232ccc 100644 (file)
@@ -42,6 +42,7 @@ enum tick_nohz_mode {
  * @idle_waketime:     Time when the idle was interrupted
  * @idle_exittime:     Time when the idle state was left
  * @idle_sleeptime:    Sum of the time slept in idle with sched tick stopped
+ * @iowait_sleeptime:  Sum of the time slept in idle with sched tick stopped, with IO outstanding
  * @sleep_length:      Duration of the current idle sleep
  * @do_timer_lst:      CPU was the last one doing do_timer before going idle
  */
@@ -60,7 +61,7 @@ struct tick_sched {
        ktime_t                         idle_waketime;
        ktime_t                         idle_exittime;
        ktime_t                         idle_sleeptime;
-       ktime_t                         idle_lastupdate;
+       ktime_t                         iowait_sleeptime;
        ktime_t                         sleep_length;
        unsigned long                   last_jiffies;
        unsigned long                   next_jiffies;
@@ -124,6 +125,7 @@ extern void tick_nohz_stop_sched_tick(int inidle);
 extern void tick_nohz_restart_sched_tick(void);
 extern ktime_t tick_nohz_get_sleep_length(void);
 extern u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time);
+extern u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time);
 # else
 static inline void tick_nohz_stop_sched_tick(int inidle) { }
 static inline void tick_nohz_restart_sched_tick(void) { }
@@ -134,6 +136,7 @@ static inline ktime_t tick_nohz_get_sleep_length(void)
        return len;
 }
 static inline u64 get_cpu_idle_time_us(int cpu, u64 *unused) { return -1; }
+static inline u64 get_cpu_iowait_time_us(int cpu, u64 *unused) { return -1; }
 # endif /* !NO_HZ */
 
 #endif
index 6e026e4..ea3559f 100644 (file)
@@ -150,7 +150,6 @@ extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
 extern int timekeeping_valid_for_hres(void);
 extern u64 timekeeping_max_deferment(void);
 extern void update_wall_time(void);
-extern void update_xtime_cache(u64 nsec);
 extern void timekeeping_leap_insert(int leapsecond);
 
 struct tms;
index a2d1eb6..ea965b8 100644 (file)
 struct tvec_base;
 
 struct timer_list {
+       /*
+        * All fields that change during normal runtime grouped to the
+        * same cacheline
+        */
        struct list_head entry;
        unsigned long expires;
+       struct tvec_base *base;
 
        void (*function)(unsigned long);
        unsigned long data;
 
-       struct tvec_base *base;
+       int slack;
+
 #ifdef CONFIG_TIMER_STATS
        void *start_site;
        char start_comm[16];
@@ -165,6 +171,8 @@ extern int mod_timer(struct timer_list *timer, unsigned long expires);
 extern int mod_timer_pending(struct timer_list *timer, unsigned long expires);
 extern int mod_timer_pinned(struct timer_list *timer, unsigned long expires);
 
+extern void set_timer_slack(struct timer_list *time, int slack_hz);
+
 #define TIMER_NOT_PINNED       0
 #define TIMER_PINNED           1
 /*
index 7a082b3..32d852f 100644 (file)
@@ -232,13 +232,11 @@ struct timex {
  */
 extern unsigned long tick_usec;                /* USER_HZ period (usec) */
 extern unsigned long tick_nsec;                /* ACTHZ          period (nsec) */
-extern int tickadj;                    /* amount of adjustment per tick */
 
 /*
  * phase-lock loop variables
  */
 extern int time_status;                /* clock synchronization status bits */
-extern long time_adjust;       /* The amount of adjtime left */
 
 extern void ntp_init(void);
 extern void ntp_clear(void);
@@ -271,9 +269,6 @@ extern void second_overflow(void);
 extern void update_ntp_one_tick(void);
 extern int do_adjtimex(struct timex *);
 
-/* Don't use! Compatibility define for existing users. */
-#define tickadj        (500/HZ ? : 1)
-
 int read_current_timer(unsigned long *timer_val);
 
 /* The clock frequency of the i8253/i8254 PIT */
index 78b4bd3..1d85f9a 100644 (file)
@@ -33,6 +33,65 @@ struct tracepoint {
                                         * Keep in sync with vmlinux.lds.h.
                                         */
 
+/*
+ * Connect a probe to a tracepoint.
+ * Internal API, should not be used directly.
+ */
+extern int tracepoint_probe_register(const char *name, void *probe);
+
+/*
+ * Disconnect a probe from a tracepoint.
+ * Internal API, should not be used directly.
+ */
+extern int tracepoint_probe_unregister(const char *name, void *probe);
+
+extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
+extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
+extern void tracepoint_probe_update_all(void);
+
+struct tracepoint_iter {
+       struct module *module;
+       struct tracepoint *tracepoint;
+};
+
+extern void tracepoint_iter_start(struct tracepoint_iter *iter);
+extern void tracepoint_iter_next(struct tracepoint_iter *iter);
+extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
+extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
+extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
+       struct tracepoint *begin, struct tracepoint *end);
+
+/*
+ * tracepoint_synchronize_unregister must be called between the last tracepoint
+ * probe unregistration and the end of module exit to make sure there is no
+ * caller executing a probe when it is freed.
+ */
+static inline void tracepoint_synchronize_unregister(void)
+{
+       synchronize_sched();
+}
+
+#define PARAMS(args...) args
+
+#ifdef CONFIG_TRACEPOINTS
+extern void tracepoint_update_probe_range(struct tracepoint *begin,
+       struct tracepoint *end);
+#else
+static inline void tracepoint_update_probe_range(struct tracepoint *begin,
+       struct tracepoint *end)
+{ }
+#endif /* CONFIG_TRACEPOINTS */
+
+#endif /* _LINUX_TRACEPOINT_H */
+
+/*
+ * Note: we keep the TRACE_EVENT and DECLARE_TRACE outside the include
+ *  file ifdef protection.
+ *  This is due to the way trace events work. If a file includes two
+ *  trace event headers under one "CREATE_TRACE_POINTS" the first include
+ *  will override the TRACE_EVENT and break the second include.
+ */
+
 #ifndef DECLARE_TRACE
 
 #define TP_PROTO(args...)      args
@@ -96,9 +155,6 @@ struct tracepoint {
 #define EXPORT_TRACEPOINT_SYMBOL(name)                                 \
        EXPORT_SYMBOL(__tracepoint_##name)
 
-extern void tracepoint_update_probe_range(struct tracepoint *begin,
-       struct tracepoint *end);
-
 #else /* !CONFIG_TRACEPOINTS */
 #define DECLARE_TRACE(name, proto, args)                               \
        static inline void _do_trace_##name(struct tracepoint *tp, proto) \
@@ -119,61 +175,9 @@ extern void tracepoint_update_probe_range(struct tracepoint *begin,
 #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
 #define EXPORT_TRACEPOINT_SYMBOL(name)
 
-static inline void tracepoint_update_probe_range(struct tracepoint *begin,
-       struct tracepoint *end)
-{ }
 #endif /* CONFIG_TRACEPOINTS */
 #endif /* DECLARE_TRACE */
 
-/*
- * Connect a probe to a tracepoint.
- * Internal API, should not be used directly.
- */
-extern int tracepoint_probe_register(const char *name, void *probe);
-
-/*
- * Disconnect a probe from a tracepoint.
- * Internal API, should not be used directly.
- */
-extern int tracepoint_probe_unregister(const char *name, void *probe);
-
-extern int tracepoint_probe_register_noupdate(const char *name, void *probe);
-extern int tracepoint_probe_unregister_noupdate(const char *name, void *probe);
-extern void tracepoint_probe_update_all(void);
-
-struct tracepoint_iter {
-       struct module *module;
-       struct tracepoint *tracepoint;
-};
-
-extern void tracepoint_iter_start(struct tracepoint_iter *iter);
-extern void tracepoint_iter_next(struct tracepoint_iter *iter);
-extern void tracepoint_iter_stop(struct tracepoint_iter *iter);
-extern void tracepoint_iter_reset(struct tracepoint_iter *iter);
-extern int tracepoint_get_iter_range(struct tracepoint **tracepoint,
-       struct tracepoint *begin, struct tracepoint *end);
-
-/*
- * tracepoint_synchronize_unregister must be called between the last tracepoint
- * probe unregistration and the end of module exit to make sure there is no
- * caller executing a probe when it is freed.
- */
-static inline void tracepoint_synchronize_unregister(void)
-{
-       synchronize_sched();
-}
-
-#define PARAMS(args...) args
-
-#endif /* _LINUX_TRACEPOINT_H */
-
-/*
- * Note: we keep the TRACE_EVENT outside the include file ifdef protection.
- *  This is due to the way trace events work. If a file includes two
- *  trace event headers under one "CREATE_TRACE_POINTS" the first include
- *  will override the TRACE_EVENT and break the second include.
- */
-
 #ifndef TRACE_EVENT
 /*
  * For use with the TRACE_EVENT macro:
index c42724f..23d237a 100644 (file)
@@ -188,12 +188,12 @@ typedef u32 phys_addr_t;
 typedef phys_addr_t resource_size_t;
 
 typedef struct {
-       volatile int counter;
+       int counter;
 } atomic_t;
 
 #ifdef CONFIG_64BIT
 typedef struct {
-       volatile long counter;
+       long counter;
 } atomic64_t;
 #endif
 
diff --git a/include/linux/usb/audio-v2.h b/include/linux/usb/audio-v2.h
new file mode 100644 (file)
index 0000000..2389f93
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2010 Daniel Mack <daniel@caiaq.de>
+ *
+ * This software is distributed under the terms of the GNU General Public
+ * License ("GPL") version 2, as published by the Free Software Foundation.
+ *
+ * This file holds USB constants and structures defined
+ * by the USB Device Class Definition for Audio Devices in version 2.0.
+ * Comments below reference relevant sections of the documents contained
+ * in http://www.usb.org/developers/devclass_docs/Audio2.0_final.zip
+ */
+
+#ifndef __LINUX_USB_AUDIO_V2_H
+#define __LINUX_USB_AUDIO_V2_H
+
+#include <linux/types.h>
+
+/* v1.0 and v2.0 of this standard have many things in common. For the rest
+ * of the definitions, please refer to audio.h */
+
+/* 4.7.2.1 Clock Source Descriptor */
+
+struct uac_clock_source_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bClockID;
+       __u8 bmAttributes;
+       __u8 bmControls;
+       __u8 bAssocTerminal;
+       __u8 iClockSource;
+} __attribute__((packed));
+
+/* 4.7.2.2 Clock Source Descriptor */
+
+struct uac_clock_selector_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bClockID;
+       __u8 bNrInPins;
+       __u8 bmControls;
+       __u8 baCSourceID[];
+} __attribute__((packed));
+
+/* 4.7.2.4 Input terminal descriptor */
+
+struct uac2_input_terminal_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bTerminalID;
+       __u16 wTerminalType;
+       __u8 bAssocTerminal;
+       __u8 bCSourceID;
+       __u8 bNrChannels;
+       __u32 bmChannelConfig;
+       __u8 iChannelNames;
+       __u16 bmControls;
+       __u8 iTerminal;
+} __attribute__((packed));
+
+/* 4.7.2.5 Output terminal descriptor */
+
+struct uac2_output_terminal_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bTerminalID;
+       __u16 wTerminalType;
+       __u8 bAssocTerminal;
+       __u8 bSourceID;
+       __u8 bCSourceID;
+       __u16 bmControls;
+       __u8 iTerminal;
+} __attribute__((packed));
+
+
+
+/* 4.7.2.8 Feature Unit Descriptor */
+
+struct uac2_feature_unit_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bUnitID;
+       __u8 bSourceID;
+       /* bmaControls is actually u32,
+        * but u8 is needed for the hybrid parser */
+       __u8 bmaControls[0]; /* variable length */
+} __attribute__((packed));
+
+/* 4.9.2 Class-Specific AS Interface Descriptor */
+
+struct uac_as_header_descriptor_v2 {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bTerminalLink;
+       __u8 bmControls;
+       __u8 bFormatType;
+       __u32 bmFormats;
+       __u8 bNrChannels;
+       __u32 bmChannelConfig;
+       __u8 iChannelNames;
+} __attribute__((packed));
+
+/* 6.1 Interrupt Data Message */
+
+#define UAC2_INTERRUPT_DATA_MSG_VENDOR (1 << 0)
+#define UAC2_INTERRUPT_DATA_MSG_EP     (1 << 1)
+
+struct uac2_interrupt_data_msg {
+       __u8 bInfo;
+       __u8 bAttribute;
+       __le16 wValue;
+       __le16 wIndex;
+} __attribute__((packed));
+
+/* A.7 Audio Function Category Codes */
+#define UAC2_FUNCTION_SUBCLASS_UNDEFINED       0x00
+#define UAC2_FUNCTION_DESKTOP_SPEAKER          0x01
+#define UAC2_FUNCTION_HOME_THEATER             0x02
+#define UAC2_FUNCTION_MICROPHONE               0x03
+#define UAC2_FUNCTION_HEADSET                  0x04
+#define UAC2_FUNCTION_TELEPHONE                        0x05
+#define UAC2_FUNCTION_CONVERTER                        0x06
+#define UAC2_FUNCTION_SOUND_RECORDER           0x07
+#define UAC2_FUNCTION_IO_BOX                   0x08
+#define UAC2_FUNCTION_MUSICAL_INSTRUMENT       0x09
+#define UAC2_FUNCTION_PRO_AUDIO                        0x0a
+#define UAC2_FUNCTION_AUDIO_VIDEO              0x0b
+#define UAC2_FUNCTION_CONTROL_PANEL            0x0c
+#define UAC2_FUNCTION_OTHER                    0xff
+
+/* A.9 Audio Class-Specific AC Interface Descriptor Subtypes */
+/* see audio.h for the rest, which is identical to v1 */
+#define UAC2_EFFECT_UNIT                       0x07
+#define UAC2_PROCESSING_UNIT_V2                0x08
+#define UAC2_EXTENSION_UNIT_V2         0x09
+#define UAC2_CLOCK_SOURCE              0x0a
+#define UAC2_CLOCK_SELECTOR            0x0b
+#define UAC2_CLOCK_MULTIPLIER          0x0c
+#define UAC2_SAMPLE_RATE_CONVERTER     0x0d
+
+/* A.10 Audio Class-Specific AS Interface Descriptor Subtypes */
+/* see audio.h for the rest, which is identical to v1 */
+#define UAC2_ENCODER                   0x03
+#define UAC2_DECODER                   0x04
+
+/* A.11 Effect Unit Effect Types */
+#define UAC2_EFFECT_UNDEFINED          0x00
+#define UAC2_EFFECT_PARAM_EQ           0x01
+#define UAC2_EFFECT_REVERB             0x02
+#define UAC2_EFFECT_MOD_DELAY          0x03
+#define UAC2_EFFECT_DYN_RANGE_COMP     0x04
+
+/* A.12 Processing Unit Process Types */
+#define UAC2_PROCESS_UNDEFINED         0x00
+#define UAC2_PROCESS_UP_DOWNMIX                0x01
+#define UAC2_PROCESS_DOLBY_PROLOCIC    0x02
+#define UAC2_PROCESS_STEREO_EXTENDER   0x03
+
+/* A.14 Audio Class-Specific Request Codes */
+#define UAC2_CS_CUR                    0x01
+#define UAC2_CS_RANGE                  0x02
+#define UAC2_CS_MEM                    0x03
+
+/* A.15 Encoder Type Codes */
+#define UAC2_ENCODER_UNDEFINED         0x00
+#define UAC2_ENCODER_OTHER             0x01
+#define UAC2_ENCODER_MPEG              0x02
+#define UAC2_ENCODER_AC3               0x03
+#define UAC2_ENCODER_WMA               0x04
+#define UAC2_ENCODER_DTS               0x05
+
+/* A.16 Decoder Type Codes */
+#define UAC2_DECODER_UNDEFINED         0x00
+#define UAC2_DECODER_OTHER             0x01
+#define UAC2_DECODER_MPEG              0x02
+#define UAC2_DECODER_AC3               0x03
+#define UAC2_DECODER_WMA               0x04
+#define UAC2_DECODER_DTS               0x05
+
+/* A.17.1 Clock Source Control Selectors */
+#define UAC2_CS_UNDEFINED              0x00
+#define UAC2_CS_CONTROL_SAM_FREQ       0x01
+#define UAC2_CS_CONTROL_CLOCK_VALID    0x02
+
+/* A.17.2 Clock Selector Control Selectors */
+#define UAC2_CX_UNDEFINED              0x00
+#define UAC2_CX_CLOCK_SELECTOR         0x01
+
+/* A.17.3 Clock Multiplier Control Selectors */
+#define UAC2_CM_UNDEFINED              0x00
+#define UAC2_CM_NUMERATOR              0x01
+#define UAC2_CM_DENOMINTATOR           0x02
+
+/* A.17.4 Terminal Control Selectors */
+#define UAC2_TE_UNDEFINED              0x00
+#define UAC2_TE_COPY_PROTECT           0x01
+#define UAC2_TE_CONNECTOR              0x02
+#define UAC2_TE_OVERLOAD               0x03
+#define UAC2_TE_CLUSTER                        0x04
+#define UAC2_TE_UNDERFLOW              0x05
+#define UAC2_TE_OVERFLOW               0x06
+#define UAC2_TE_LATENCY                        0x07
+
+/* A.17.5 Mixer Control Selectors */
+#define UAC2_MU_UNDEFINED              0x00
+#define UAC2_MU_MIXER                  0x01
+#define UAC2_MU_CLUSTER                        0x02
+#define UAC2_MU_UNDERFLOW              0x03
+#define UAC2_MU_OVERFLOW               0x04
+#define UAC2_MU_LATENCY                        0x05
+
+/* A.17.6 Selector Control Selectors */
+#define UAC2_SU_UNDEFINED              0x00
+#define UAC2_SU_SELECTOR               0x01
+#define UAC2_SU_LATENCY                        0x02
+
+/* A.17.7 Feature Unit Control Selectors */
+/* see audio.h for the rest, which is identical to v1 */
+#define UAC2_FU_INPUT_GAIN             0x0b
+#define UAC2_FU_INPUT_GAIN_PAD         0x0c
+#define UAC2_FU_PHASE_INVERTER         0x0d
+#define UAC2_FU_UNDERFLOW              0x0e
+#define UAC2_FU_OVERFLOW               0x0f
+#define UAC2_FU_LATENCY                        0x10
+
+/* A.17.8.1 Parametric Equalizer Section Effect Unit Control Selectors */
+#define UAC2_PE_UNDEFINED              0x00
+#define UAC2_PE_ENABLE                 0x01
+#define UAC2_PE_CENTERFREQ             0x02
+#define UAC2_PE_QFACTOR                        0x03
+#define UAC2_PE_GAIN                   0x04
+#define UAC2_PE_UNDERFLOW              0x05
+#define UAC2_PE_OVERFLOW               0x06
+#define UAC2_PE_LATENCY                        0x07
+
+/* A.17.8.2 Reverberation Effect Unit Control Selectors */
+#define UAC2_RV_UNDEFINED              0x00
+#define UAC2_RV_ENABLE                 0x01
+#define UAC2_RV_TYPE                   0x02
+#define UAC2_RV_LEVEL                  0x03
+#define UAC2_RV_TIME                   0x04
+#define UAC2_RV_FEEDBACK               0x05
+#define UAC2_RV_PREDELAY               0x06
+#define UAC2_RV_DENSITY                        0x07
+#define UAC2_RV_HIFREQ_ROLLOFF         0x08
+#define UAC2_RV_UNDERFLOW              0x09
+#define UAC2_RV_OVERFLOW               0x0a
+#define UAC2_RV_LATENCY                        0x0b
+
+/* A.17.8.3 Modulation Delay Effect Control Selectors */
+#define UAC2_MD_UNDEFINED              0x00
+#define UAC2_MD_ENABLE                 0x01
+#define UAC2_MD_BALANCE                        0x02
+#define UAC2_MD_RATE                   0x03
+#define UAC2_MD_DEPTH                  0x04
+#define UAC2_MD_TIME                   0x05
+#define UAC2_MD_FEEDBACK               0x06
+#define UAC2_MD_UNDERFLOW              0x07
+#define UAC2_MD_OVERFLOW               0x08
+#define UAC2_MD_LATENCY                        0x09
+
+/* A.17.8.4 Dynamic Range Compressor Effect Unit Control Selectors */
+#define UAC2_DR_UNDEFINED              0x00
+#define UAC2_DR_ENABLE                 0x01
+#define UAC2_DR_COMPRESSION_RATE       0x02
+#define UAC2_DR_MAXAMPL                        0x03
+#define UAC2_DR_THRESHOLD              0x04
+#define UAC2_DR_ATTACK_TIME            0x05
+#define UAC2_DR_RELEASE_TIME           0x06
+#define UAC2_DR_UNDEFLOW               0x07
+#define UAC2_DR_OVERFLOW               0x08
+#define UAC2_DR_LATENCY                        0x09
+
+/* A.17.9.1 Up/Down-mix Processing Unit Control Selectors */
+#define UAC2_UD_UNDEFINED              0x00
+#define UAC2_UD_ENABLE                 0x01
+#define UAC2_UD_MODE_SELECT            0x02
+#define UAC2_UD_CLUSTER                        0x03
+#define UAC2_UD_UNDERFLOW              0x04
+#define UAC2_UD_OVERFLOW               0x05
+#define UAC2_UD_LATENCY                        0x06
+
+/* A.17.9.2 Dolby Prologic[tm] Processing Unit Control Selectors */
+#define UAC2_DP_UNDEFINED              0x00
+#define UAC2_DP_ENABLE                 0x01
+#define UAC2_DP_MODE_SELECT            0x02
+#define UAC2_DP_CLUSTER                        0x03
+#define UAC2_DP_UNDERFFLOW             0x04
+#define UAC2_DP_OVERFLOW               0x05
+#define UAC2_DP_LATENCY                        0x06
+
+/* A.17.9.3 Stereo Expander Processing Unit Control Selectors */
+#define UAC2_ST_EXT_UNDEFINED          0x00
+#define UAC2_ST_EXT_ENABLE             0x01
+#define UAC2_ST_EXT_WIDTH              0x02
+#define UAC2_ST_EXT_UNDEFLOW           0x03
+#define UAC2_ST_EXT_OVERFLOW           0x04
+#define UAC2_ST_EXT_LATENCY            0x05
+
+/* A.17.10 Extension Unit Control Selectors */
+#define UAC2_XU_UNDEFINED              0x00
+#define UAC2_XU_ENABLE                 0x01
+#define UAC2_XU_CLUSTER                        0x02
+#define UAC2_XU_UNDERFLOW              0x03
+#define UAC2_XU_OVERFLOW               0x04
+#define UAC2_XU_LATENCY                        0x05
+
+/* A.17.11 AudioStreaming Interface Control Selectors */
+#define UAC2_AS_UNDEFINED              0x00
+#define UAC2_AS_ACT_ALT_SETTING                0x01
+#define UAC2_AS_VAL_ALT_SETTINGS       0x02
+#define UAC2_AS_AUDIO_DATA_FORMAT      0x03
+
+/* A.17.12 Encoder Control Selectors */
+#define UAC2_EN_UNDEFINED              0x00
+#define UAC2_EN_BIT_RATE               0x01
+#define UAC2_EN_QUALITY                        0x02
+#define UAC2_EN_VBR                    0x03
+#define UAC2_EN_TYPE                   0x04
+#define UAC2_EN_UNDERFLOW              0x05
+#define UAC2_EN_OVERFLOW               0x06
+#define UAC2_EN_ENCODER_ERROR          0x07
+#define UAC2_EN_PARAM1                 0x08
+#define UAC2_EN_PARAM2                 0x09
+#define UAC2_EN_PARAM3                 0x0a
+#define UAC2_EN_PARAM4                 0x0b
+#define UAC2_EN_PARAM5                 0x0c
+#define UAC2_EN_PARAM6                 0x0d
+#define UAC2_EN_PARAM7                 0x0e
+#define UAC2_EN_PARAM8                 0x0f
+
+/* A.17.13.1 MPEG Decoder Control Selectors */
+#define UAC2_MPEG_UNDEFINED            0x00
+#define UAC2_MPEG_DUAL_CHANNEL         0x01
+#define UAC2_MPEG_SECOND_STEREO                0x02
+#define UAC2_MPEG_MULTILINGUAL         0x03
+#define UAC2_MPEG_DYN_RANGE            0x04
+#define UAC2_MPEG_SCALING              0x05
+#define UAC2_MPEG_HILO_SCALING         0x06
+#define UAC2_MPEG_UNDERFLOW            0x07
+#define UAC2_MPEG_OVERFLOW             0x08
+#define UAC2_MPEG_DECODER_ERROR                0x09
+
+/* A17.13.2 AC3 Decoder Control Selectors */
+#define UAC2_AC3_UNDEFINED             0x00
+#define UAC2_AC3_MODE                  0x01
+#define UAC2_AC3_DYN_RANGE             0x02
+#define UAC2_AC3_SCALING               0x03
+#define UAC2_AC3_HILO_SCALING          0x04
+#define UAC2_AC3_UNDERFLOW             0x05
+#define UAC2_AC3_OVERFLOW              0x06
+#define UAC2_AC3_DECODER_ERROR         0x07
+
+/* A17.13.3 WMA Decoder Control Selectors */
+#define UAC2_WMA_UNDEFINED             0x00
+#define UAC2_WMA_UNDERFLOW             0x01
+#define UAC2_WMA_OVERFLOW              0x02
+#define UAC2_WMA_DECODER_ERROR         0x03
+
+/* A17.13.4 DTS Decoder Control Selectors */
+#define UAC2_DTS_UNDEFINED             0x00
+#define UAC2_DTS_UNDERFLOW             0x01
+#define UAC2_DTS_OVERFLOW              0x02
+#define UAC2_DTS_DECODER_ERROR         0x03
+
+/* A17.14 Endpoint Control Selectors */
+#define UAC2_EP_CS_UNDEFINED           0x00
+#define UAC2_EP_CS_PITCH               0x01
+#define UAC2_EP_CS_DATA_OVERRUN                0x02
+#define UAC2_EP_CS_DATA_UNDERRUN       0x03
+
+#endif /* __LINUX_USB_AUDIO_V2_H */
+
index 4d3e450..c0ef18d 100644 (file)
@@ -13,6 +13,9 @@
  * Comments below reference relevant sections of that document:
  *
  * http://www.usb.org/developers/devclass_docs/audio10.pdf
+ *
+ * Types and defines in this file are either specific to version 1.0 of
+ * this standard or common for newer versions.
  */
 
 #ifndef __LINUX_USB_AUDIO_H
 
 #include <linux/types.h>
 
+/* bInterfaceProtocol values to denote the version of the standard used */
+#define UAC_VERSION_1                  0x00
+#define UAC_VERSION_2                  0x20
+
 /* A.2 Audio Interface Subclass Codes */
 #define USB_SUBCLASS_AUDIOCONTROL      0x01
 #define USB_SUBCLASS_AUDIOSTREAMING    0x02
 #define USB_SUBCLASS_MIDISTREAMING     0x03
 
-#define UAC_VERSION_1                  0x00
-#define UAC_VERSION_2                  0x20
-
 /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */
 #define UAC_HEADER                     0x01
 #define UAC_INPUT_TERMINAL             0x02
 #define UAC_PROCESSING_UNIT_V1         0x07
 #define UAC_EXTENSION_UNIT_V1          0x08
 
-/* UAC v2.0 types */
-#define UAC_EFFECT_UNIT                        0x07
-#define UAC_PROCESSING_UNIT_V2         0x08
-#define UAC_EXTENSION_UNIT_V2          0x09
-#define UAC_CLOCK_SOURCE               0x0a
-#define UAC_CLOCK_SELECTOR             0x0b
-#define UAC_CLOCK_MULTIPLIER           0x0c
-#define UAC_SAMPLE_RATE_CONVERTER      0x0d
-
 /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */
 #define UAC_AS_GENERAL                 0x01
 #define UAC_FORMAT_TYPE                        0x02
 
 #define UAC_GET_STAT                   0xff
 
-/* Audio class v2.0 handles all the parameter calls differently */
-#define UAC2_CS_CUR                    0x01
-#define UAC2_CS_RANGE                  0x02
-
 /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */
 #define UAC_MS_HEADER                  0x01
 #define UAC_MIDI_IN_JACK               0x02
@@ -190,6 +181,156 @@ struct uac_feature_unit_descriptor_##ch {                 \
        __u8  iFeature;                                         \
 } __attribute__ ((packed))
 
+/* 4.3.2.3 Mixer Unit Descriptor */
+struct uac_mixer_unit_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bUnitID;
+       __u8 bNrInPins;
+       __u8 baSourceID[];
+} __attribute__ ((packed));
+
+static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc)
+{
+       return desc->baSourceID[desc->bNrInPins];
+}
+
+static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc,
+                                                 int protocol)
+{
+       if (protocol == UAC_VERSION_1)
+               return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
+                       desc->baSourceID[desc->bNrInPins + 1];
+       else
+               return  (desc->baSourceID[desc->bNrInPins + 4] << 24) |
+                       (desc->baSourceID[desc->bNrInPins + 3] << 16) |
+                       (desc->baSourceID[desc->bNrInPins + 2] << 8)  |
+                       (desc->baSourceID[desc->bNrInPins + 1]);
+}
+
+static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc,
+                                               int protocol)
+{
+       return (protocol == UAC_VERSION_1) ?
+               desc->baSourceID[desc->bNrInPins + 3] :
+               desc->baSourceID[desc->bNrInPins + 5];
+}
+
+static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc,
+                                             int protocol)
+{
+       return (protocol == UAC_VERSION_1) ?
+               &desc->baSourceID[desc->bNrInPins + 4] :
+               &desc->baSourceID[desc->bNrInPins + 6];
+}
+
+static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc)
+{
+       __u8 *raw = (__u8 *) desc;
+       return raw[desc->bLength - 1];
+}
+
+/* 4.3.2.4 Selector Unit Descriptor */
+struct uac_selector_unit_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bUintID;
+       __u8 bNrInPins;
+       __u8 baSourceID[];
+} __attribute__ ((packed));
+
+static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc)
+{
+       __u8 *raw = (__u8 *) desc;
+       return raw[9 + desc->bLength - 1];
+}
+
+/* 4.3.2.5 Feature Unit Descriptor */
+struct uac_feature_unit_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bUnitID;
+       __u8 bSourceID;
+       __u8 bControlSize;
+       __u8 bmaControls[0]; /* variable length */
+} __attribute__((packed));
+
+static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc)
+{
+       __u8 *raw = (__u8 *) desc;
+       return raw[desc->bLength - 1];
+}
+
+/* 4.3.2.6 Processing Unit Descriptors */
+struct uac_processing_unit_descriptor {
+       __u8 bLength;
+       __u8 bDescriptorType;
+       __u8 bDescriptorSubtype;
+       __u8 bUnitID;
+       __u16 wProcessType;
+       __u8 bNrInPins;
+       __u8 baSourceID[];
+} __attribute__ ((packed));
+
+static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc)
+{
+       return desc->baSourceID[desc->bNrInPins];
+}
+
+static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc,
+                                                      int protocol)
+{
+       if (protocol == UAC_VERSION_1)
+               return (desc->baSourceID[desc->bNrInPins + 2] << 8) |
+                       desc->baSourceID[desc->bNrInPins + 1];
+       else
+               return  (desc->baSourceID[desc->bNrInPins + 4] << 24) |
+                       (desc->baSourceID[desc->bNrInPins + 3] << 16) |
+                       (desc->baSourceID[desc->bNrInPins + 2] << 8)  |
+                       (desc->baSourceID[desc->bNrInPins + 1]);
+}
+
+static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc,
+                                                    int protocol)
+{
+       return (protocol == UAC_VERSION_1) ?
+               desc->baSourceID[desc->bNrInPins + 3] :
+               desc->baSourceID[desc->bNrInPins + 5];
+}
+
+static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc,
+                                                   int protocol)
+{
+       return (protocol == UAC_VERSION_1) ?
+               desc->baSourceID[desc->bNrInPins + 4] :
+               desc->baSourceID[desc->bNrInPins + 6];
+}
+
+static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc,
+                                                  int protocol)
+{
+       return (protocol == UAC_VERSION_1) ?
+               &desc->baSourceID[desc->bNrInPins + 5] :
+               &desc->baSourceID[desc->bNrInPins + 7];
+}
+
+static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc,
+                                                  int protocol)
+{
+       __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
+       return desc->baSourceID[desc->bNrInPins + control_size];
+}
+
+static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc,
+                                                int protocol)
+{
+       __u8 control_size = uac_processing_unit_bControlSize(desc, protocol);
+       return &desc->baSourceID[desc->bNrInPins + control_size + 1];
+}
+
 /* 4.5.2 Class-Specific AS Interface Descriptor */
 struct uac_as_header_descriptor_v1 {
        __u8  bLength;                  /* in bytes: 7 */
@@ -200,19 +341,6 @@ struct uac_as_header_descriptor_v1 {
        __le16 wFormatTag;              /* The Audio Data Format */
 } __attribute__ ((packed));
 
-struct uac_as_header_descriptor_v2 {
-       __u8 bLength;
-       __u8 bDescriptorType;
-       __u8 bDescriptorSubtype;
-       __u8 bTerminalLink;
-       __u8 bmControls;
-       __u8 bFormatType;
-       __u32 bmFormats;
-       __u8 bNrChannels;
-       __u32 bmChannelConfig;
-       __u8 iChannelNames;
-} __attribute__((packed));
-
 #define UAC_DT_AS_HEADER_SIZE          7
 
 /* Formats - A.1.1 Audio Data Format Type I Codes */
@@ -277,7 +405,6 @@ struct uac_format_type_i_ext_descriptor {
        __u8 bSideBandProtocol;
 } __attribute__((packed));
 
-
 /* Formats - Audio Data Format Type I Codes */
 
 #define UAC_FORMAT_TYPE_II_MPEG        0x1001
@@ -329,38 +456,15 @@ struct uac_iso_endpoint_descriptor {
        __u8  bmAttributes;
        __u8  bLockDelayUnits;
        __le16 wLockDelay;
-};
+} __attribute__((packed));
 #define UAC_ISO_ENDPOINT_DESC_SIZE     7
 
 #define UAC_EP_CS_ATTR_SAMPLE_RATE     0x01
 #define UAC_EP_CS_ATTR_PITCH_CONTROL   0x02
 #define UAC_EP_CS_ATTR_FILL_MAX                0x80
 
-/* Audio class v2.0: CLOCK_SOURCE descriptor */
-
-struct uac_clock_source_descriptor {
-       __u8 bLength;
-       __u8 bDescriptorType;
-       __u8 bDescriptorSubtype;
-       __u8 bClockID;
-       __u8 bmAttributes;
-       __u8 bmControls;
-       __u8 bAssocTerminal;
-       __u8 iClockSource;
-} __attribute__((packed));
-
 /* A.10.2 Feature Unit Control Selectors */
 
-struct uac_feature_unit_descriptor {
-       __u8 bLength;
-       __u8 bDescriptorType;
-       __u8 bDescriptorSubtype;
-       __u8 bUnitID;
-       __u8 bSourceID;
-       __u8 bControlSize;
-       __u8 controls[0]; /* variable length */
-} __attribute__((packed));
-
 #define UAC_FU_CONTROL_UNDEFINED       0x00
 #define UAC_MUTE_CONTROL               0x01
 #define UAC_VOLUME_CONTROL             0x02
@@ -384,6 +488,21 @@ struct uac_feature_unit_descriptor {
 #define UAC_FU_BASS_BOOST      (1 << (UAC_BASS_BOOST_CONTROL - 1))
 #define UAC_FU_LOUDNESS                (1 << (UAC_LOUDNESS_CONTROL - 1))
 
+/* status word format (3.7.1.1) */
+
+#define UAC1_STATUS_TYPE_ORIG_MASK             0x0f
+#define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0
+#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF  0x1
+#define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP  0x2
+
+#define UAC1_STATUS_TYPE_IRQ_PENDING           (1 << 7)
+#define UAC1_STATUS_TYPE_MEM_CHANGED           (1 << 6)
+
+struct uac1_status_word {
+       __u8 bStatusType;
+       __u8 bOriginator;
+} __attribute__((packed));
+
 #ifdef __KERNEL__
 
 struct usb_audio_control {
index 3793d16..047f7e6 100644 (file)
@@ -160,16 +160,6 @@ enum v4l2_buf_type {
        V4L2_BUF_TYPE_PRIVATE              = 0x80,
 };
 
-enum v4l2_ctrl_type {
-       V4L2_CTRL_TYPE_INTEGER       = 1,
-       V4L2_CTRL_TYPE_BOOLEAN       = 2,
-       V4L2_CTRL_TYPE_MENU          = 3,
-       V4L2_CTRL_TYPE_BUTTON        = 4,
-       V4L2_CTRL_TYPE_INTEGER64     = 5,
-       V4L2_CTRL_TYPE_CTRL_CLASS    = 6,
-       V4L2_CTRL_TYPE_STRING        = 7,
-};
-
 enum v4l2_tuner_type {
        V4L2_TUNER_RADIO             = 1,
        V4L2_TUNER_ANALOG_TV         = 2,
@@ -294,6 +284,8 @@ struct v4l2_pix_format {
 
 /* Grey formats */
 #define V4L2_PIX_FMT_GREY    v4l2_fourcc('G', 'R', 'E', 'Y') /*  8  Greyscale     */
+#define V4L2_PIX_FMT_Y4      v4l2_fourcc('Y', '0', '4', ' ') /*  4  Greyscale     */
+#define V4L2_PIX_FMT_Y6      v4l2_fourcc('Y', '0', '6', ' ') /*  6  Greyscale     */
 #define V4L2_PIX_FMT_Y10     v4l2_fourcc('Y', '1', '0', ' ') /* 10  Greyscale     */
 #define V4L2_PIX_FMT_Y16     v4l2_fourcc('Y', '1', '6', ' ') /* 16  Greyscale     */
 
@@ -369,6 +361,7 @@ struct v4l2_pix_format {
 #define V4L2_PIX_FMT_OV511    v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
 #define V4L2_PIX_FMT_OV518    v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
 #define V4L2_PIX_FMT_STV0680  v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
+#define V4L2_PIX_FMT_TM6000   v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
 
 /*
  *     F O R M A T   E N U M E R A T I O N
@@ -549,6 +542,8 @@ struct v4l2_buffer {
 #define V4L2_BUF_FLAG_KEYFRAME 0x0008  /* Image is a keyframe (I-frame) */
 #define V4L2_BUF_FLAG_PFRAME   0x0010  /* Image is a P-frame */
 #define V4L2_BUF_FLAG_BFRAME   0x0020  /* Image is a B-frame */
+/* Buffer is ready, but the data contained within is corrupted. */
+#define V4L2_BUF_FLAG_ERROR    0x0040
 #define V4L2_BUF_FLAG_TIMECODE 0x0100  /* timecode field is valid */
 #define V4L2_BUF_FLAG_INPUT     0x0200  /* input field is valid */
 
@@ -939,6 +934,16 @@ struct v4l2_ext_controls {
 #define V4L2_CTRL_ID2CLASS(id)    ((id) & 0x0fff0000UL)
 #define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
 
+enum v4l2_ctrl_type {
+       V4L2_CTRL_TYPE_INTEGER       = 1,
+       V4L2_CTRL_TYPE_BOOLEAN       = 2,
+       V4L2_CTRL_TYPE_MENU          = 3,
+       V4L2_CTRL_TYPE_BUTTON        = 4,
+       V4L2_CTRL_TYPE_INTEGER64     = 5,
+       V4L2_CTRL_TYPE_CTRL_CLASS    = 6,
+       V4L2_CTRL_TYPE_STRING        = 7,
+};
+
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
 struct v4l2_queryctrl {
        __u32                id;
@@ -1023,14 +1028,24 @@ enum v4l2_colorfx {
        V4L2_COLORFX_NONE       = 0,
        V4L2_COLORFX_BW         = 1,
        V4L2_COLORFX_SEPIA      = 2,
+       V4L2_COLORFX_NEGATIVE = 3,
+       V4L2_COLORFX_EMBOSS = 4,
+       V4L2_COLORFX_SKETCH = 5,
+       V4L2_COLORFX_SKY_BLUE = 6,
+       V4L2_COLORFX_GRASS_GREEN = 7,
+       V4L2_COLORFX_SKIN_WHITEN = 8,
+       V4L2_COLORFX_VIVID = 9,
 };
 #define V4L2_CID_AUTOBRIGHTNESS                        (V4L2_CID_BASE+32)
 #define V4L2_CID_BAND_STOP_FILTER              (V4L2_CID_BASE+33)
 
 #define V4L2_CID_ROTATE                                (V4L2_CID_BASE+34)
 #define V4L2_CID_BG_COLOR                      (V4L2_CID_BASE+35)
+
+#define V4L2_CID_CHROMA_GAIN                    (V4L2_CID_BASE+36)
+
 /* last CID + 1 */
-#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+36)
+#define V4L2_CID_LASTP1                         (V4L2_CID_BASE+37)
 
 /*  MPEG-class control IDs defined by V4L2 */
 #define V4L2_CID_MPEG_BASE                     (V4L2_CTRL_CLASS_MPEG | 0x900)
@@ -1276,6 +1291,9 @@ enum  v4l2_exposure_auto_type {
 
 #define V4L2_CID_PRIVACY                       (V4L2_CID_CAMERA_CLASS_BASE+16)
 
+#define V4L2_CID_IRIS_ABSOLUTE                 (V4L2_CID_CAMERA_CLASS_BASE+17)
+#define V4L2_CID_IRIS_RELATIVE                 (V4L2_CID_CAMERA_CLASS_BASE+18)
+
 /* FM Modulator class control IDs */
 #define V4L2_CID_FM_TX_CLASS_BASE              (V4L2_CTRL_CLASS_FM_TX | 0x900)
 #define V4L2_CID_FM_TX_CLASS                   (V4L2_CTRL_CLASS_FM_TX | 1)
@@ -1620,6 +1638,38 @@ struct v4l2_streamparm {
        } parm;
 };
 
+/*
+ *     E V E N T S
+ */
+
+#define V4L2_EVENT_ALL                         0
+#define V4L2_EVENT_VSYNC                       1
+#define V4L2_EVENT_EOS                         2
+#define V4L2_EVENT_PRIVATE_START               0x08000000
+
+/* Payload for V4L2_EVENT_VSYNC */
+struct v4l2_event_vsync {
+       /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
+       __u8 field;
+} __attribute__ ((packed));
+
+struct v4l2_event {
+       __u32                           type;
+       union {
+               struct v4l2_event_vsync vsync;
+               __u8                    data[64];
+       } u;
+       __u32                           pending;
+       __u32                           sequence;
+       struct timespec                 timestamp;
+       __u32                           reserved[9];
+};
+
+struct v4l2_event_subscription {
+       __u32                           type;
+       __u32                           reserved[7];
+};
+
 /*
  *     A D V A N C E D   D E B U G G I N G
  *
@@ -1742,6 +1792,9 @@ struct v4l2_dbg_chip_ident {
 #define        VIDIOC_QUERY_DV_PRESET  _IOR('V',  86, struct v4l2_dv_preset)
 #define        VIDIOC_S_DV_TIMINGS     _IOWR('V', 87, struct v4l2_dv_timings)
 #define        VIDIOC_G_DV_TIMINGS     _IOWR('V', 88, struct v4l2_dv_timings)
+#define        VIDIOC_DQEVENT           _IOR('V', 89, struct v4l2_event)
+#define        VIDIOC_SUBSCRIBE_EVENT   _IOW('V', 90, struct v4l2_event_subscription)
+#define        VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription)
 
 /* Reminder: when adding new ioctls please add support for them to
    drivers/media/video/v4l2-compat-ioctl32.c as well! */
index a48e16b..76d96d0 100644 (file)
@@ -127,12 +127,26 @@ static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
 /*
  * Used for wake-one threads:
  */
+static inline void __add_wait_queue_exclusive(wait_queue_head_t *q,
+                                             wait_queue_t *wait)
+{
+       wait->flags |= WQ_FLAG_EXCLUSIVE;
+       __add_wait_queue(q, wait);
+}
+
 static inline void __add_wait_queue_tail(wait_queue_head_t *head,
-                                               wait_queue_t *new)
+                                        wait_queue_t *new)
 {
        list_add_tail(&new->task_list, &head->task_list);
 }
 
+static inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q,
+                                             wait_queue_t *wait)
+{
+       wait->flags |= WQ_FLAG_EXCLUSIVE;
+       __add_wait_queue_tail(q, wait);
+}
+
 static inline void __remove_wait_queue(wait_queue_head_t *head,
                                                        wait_queue_t *old)
 {
@@ -403,25 +417,6 @@ do {                                                                       \
        __ret;                                                          \
 })
 
-/*
- * Must be called with the spinlock in the wait_queue_head_t held.
- */
-static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
-                                                  wait_queue_t * wait)
-{
-       wait->flags |= WQ_FLAG_EXCLUSIVE;
-       __add_wait_queue_tail(q,  wait);
-}
-
-/*
- * Must be called with the spinlock in the wait_queue_head_t held.
- */
-static inline void remove_wait_queue_locked(wait_queue_head_t *q,
-                                           wait_queue_t * wait)
-{
-       __remove_wait_queue(q,  wait);
-}
-
 /*
  * These are the old interfaces to sleep waiting for an event.
  * They are racy.  DO NOT use them, use the wait_event* interfaces above.
index 913bfc2..7bf9db5 100644 (file)
@@ -38,8 +38,6 @@
 typedef __u32 zorro_id;
 
 
-#define ZORRO_WILDCARD         (0xffffffff)    /* not official */
-
 /* Include the ID list */
 #include <linux/zorro_ids.h>
 
@@ -116,6 +114,7 @@ struct ConfigDev {
 
 #include <linux/init.h>
 #include <linux/ioport.h>
+#include <linux/mod_devicetable.h>
 
 #include <asm/zorro.h>
 
@@ -142,28 +141,9 @@ struct zorro_dev {
      *  Zorro bus
      */
 
-struct zorro_bus {
-    struct list_head devices;          /* list of devices on this bus */
-    unsigned int num_resources;                /* number of resources */
-    struct resource resources[4];      /* address space routed to this bus */
-    struct device dev;
-    char name[10];
-};
-
-extern struct zorro_bus zorro_bus;     /* single Zorro bus */
 extern struct bus_type zorro_bus_type;
 
 
-    /*
-     *  Zorro device IDs
-     */
-
-struct zorro_device_id {
-       zorro_id id;                    /* Device ID or ZORRO_WILDCARD */
-       unsigned long driver_data;      /* Data private to the driver */
-};
-
-
     /*
      *  Zorro device drivers
      */
diff --git a/include/media/ak881x.h b/include/media/ak881x.h
new file mode 100644 (file)
index 0000000..b7f2add
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * Header for AK8813 / AK8814 TV-ecoders from Asahi Kasei Microsystems Co., Ltd. (AKM)
+ *
+ * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef AK881X_H
+#define AK881X_H
+
+#define AK881X_IF_MODE_MASK    (3 << 0)
+#define AK881X_IF_MODE_BT656   (0 << 0)
+#define AK881X_IF_MODE_MASTER  (1 << 0)
+#define AK881X_IF_MODE_SLAVE   (2 << 0)
+#define AK881X_FIELD           (1 << 2)
+#define AK881X_COMPONENT       (1 << 3)
+
+struct ak881x_pdata {
+       unsigned long flags;
+};
+
+#endif
index 4314a5f..cc973ed 100644 (file)
@@ -94,6 +94,8 @@ struct vpfe_config {
        /* vpfe clock */
        struct clk *vpssclk;
        struct clk *slaveclk;
+       /* Function for Clearing the interrupt */
+       void (*clr_intr)(int vdint);
 };
 
 struct vpfe_device {
index c662980..528050e 100644 (file)
@@ -50,6 +50,10 @@ struct card_ir {
        struct ir_input_state   ir;
        char                    name[32];
        char                    phys[32];
+       int                     users;
+
+       u32                     running:1;
+       struct ir_dev_props     props;
 
        /* Usual gpio signalling */
 
@@ -79,6 +83,9 @@ struct card_ir {
        /* NEC decoding */
        u32                     nec_gpio;
        struct tasklet_struct   tlet;
+
+       /* IR core raw decoding */
+       u32                     raw_decode;
 };
 
 /* Routines from ir-functions.c */
@@ -97,71 +104,4 @@ u32  ir_rc5_decode(unsigned int code);
 void ir_rc5_timer_end(unsigned long data);
 void ir_rc5_timer_keyup(unsigned long data);
 
-/* scancode->keycode map tables from ir-keymaps.c */
-
-extern struct ir_scancode_table ir_codes_empty_table;
-extern struct ir_scancode_table ir_codes_avermedia_table;
-extern struct ir_scancode_table ir_codes_avermedia_dvbt_table;
-extern struct ir_scancode_table ir_codes_avermedia_m135a_table;
-extern struct ir_scancode_table ir_codes_avermedia_cardbus_table;
-extern struct ir_scancode_table ir_codes_apac_viewcomp_table;
-extern struct ir_scancode_table ir_codes_pixelview_table;
-extern struct ir_scancode_table ir_codes_pixelview_new_table;
-extern struct ir_scancode_table ir_codes_nebula_table;
-extern struct ir_scancode_table ir_codes_dntv_live_dvb_t_table;
-extern struct ir_scancode_table ir_codes_iodata_bctv7e_table;
-extern struct ir_scancode_table ir_codes_adstech_dvb_t_pci_table;
-extern struct ir_scancode_table ir_codes_msi_tvanywhere_table;
-extern struct ir_scancode_table ir_codes_cinergy_1400_table;
-extern struct ir_scancode_table ir_codes_avertv_303_table;
-extern struct ir_scancode_table ir_codes_dntv_live_dvbt_pro_table;
-extern struct ir_scancode_table ir_codes_em_terratec_table;
-extern struct ir_scancode_table ir_codes_pinnacle_grey_table;
-extern struct ir_scancode_table ir_codes_flyvideo_table;
-extern struct ir_scancode_table ir_codes_flydvb_table;
-extern struct ir_scancode_table ir_codes_cinergy_table;
-extern struct ir_scancode_table ir_codes_eztv_table;
-extern struct ir_scancode_table ir_codes_avermedia_table;
-extern struct ir_scancode_table ir_codes_videomate_tv_pvr_table;
-extern struct ir_scancode_table ir_codes_manli_table;
-extern struct ir_scancode_table ir_codes_gotview7135_table;
-extern struct ir_scancode_table ir_codes_purpletv_table;
-extern struct ir_scancode_table ir_codes_pctv_sedna_table;
-extern struct ir_scancode_table ir_codes_pv951_table;
-extern struct ir_scancode_table ir_codes_rc5_tv_table;
-extern struct ir_scancode_table ir_codes_winfast_table;
-extern struct ir_scancode_table ir_codes_pinnacle_color_table;
-extern struct ir_scancode_table ir_codes_hauppauge_new_table;
-extern struct ir_scancode_table ir_codes_rc5_hauppauge_new_table;
-extern struct ir_scancode_table ir_codes_npgtech_table;
-extern struct ir_scancode_table ir_codes_norwood_table;
-extern struct ir_scancode_table ir_codes_proteus_2309_table;
-extern struct ir_scancode_table ir_codes_budget_ci_old_table;
-extern struct ir_scancode_table ir_codes_asus_pc39_table;
-extern struct ir_scancode_table ir_codes_encore_enltv_table;
-extern struct ir_scancode_table ir_codes_encore_enltv2_table;
-extern struct ir_scancode_table ir_codes_tt_1500_table;
-extern struct ir_scancode_table ir_codes_fusionhdtv_mce_table;
-extern struct ir_scancode_table ir_codes_behold_table;
-extern struct ir_scancode_table ir_codes_behold_columbus_table;
-extern struct ir_scancode_table ir_codes_pinnacle_pctv_hd_table;
-extern struct ir_scancode_table ir_codes_genius_tvgo_a11mce_table;
-extern struct ir_scancode_table ir_codes_powercolor_real_angel_table;
-extern struct ir_scancode_table ir_codes_avermedia_a16d_table;
-extern struct ir_scancode_table ir_codes_encore_enltv_fm53_table;
-extern struct ir_scancode_table ir_codes_real_audio_220_32_keys_table;
-extern struct ir_scancode_table ir_codes_msi_tvanywhere_plus_table;
-extern struct ir_scancode_table ir_codes_ati_tv_wonder_hd_600_table;
-extern struct ir_scancode_table ir_codes_kworld_plus_tv_analog_table;
-extern struct ir_scancode_table ir_codes_kaiomy_table;
-extern struct ir_scancode_table ir_codes_dm1105_nec_table;
-extern struct ir_scancode_table ir_codes_tevii_nec_table;
-extern struct ir_scancode_table ir_codes_tbs_nec_table;
-extern struct ir_scancode_table ir_codes_evga_indtube_table;
-extern struct ir_scancode_table ir_codes_terratec_cinergy_xs_table;
-extern struct ir_scancode_table ir_codes_videomate_s350_table;
-extern struct ir_scancode_table ir_codes_gadmei_rm008z_table;
-extern struct ir_scancode_table ir_codes_nec_terratec_cinergy_xs_table;
-extern struct ir_scancode_table ir_codes_winfast_usbii_deluxe_table;
-extern struct ir_scancode_table ir_codes_kworld_315u_table;
 #endif
index 61c223b..ad1303f 100644 (file)
@@ -1,6 +1,8 @@
 /*
  * Remote Controller core header
  *
+ * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.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 version 2 of the License.
 #ifndef _IR_CORE
 #define _IR_CORE
 
-#include <linux/input.h>
 #include <linux/spinlock.h>
+#include <linux/kfifo.h>
+#include <linux/time.h>
+#include <linux/timer.h>
+#include <media/rc-map.h>
 
 extern int ir_core_debug;
 #define IR_dprintk(level, fmt, arg...) if (ir_core_debug >= level) \
        printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
 
-#define IR_TYPE_UNKNOWN        0
-#define IR_TYPE_RC5    (1  << 0)       /* Philips RC5 protocol */
-#define IR_TYPE_PD     (1  << 1)       /* Pulse distance encoded IR */
-#define IR_TYPE_NEC    (1  << 2)
-#define IR_TYPE_OTHER  (((u64)1) << 63l)
-
-struct ir_scancode {
-       u16     scancode;
-       u32     keycode;
-};
-
-struct ir_scancode_table {
-       struct ir_scancode      *scan;
-       int                     size;
-       u64             ir_type;
-       spinlock_t              lock;
+enum rc_driver_type {
+       RC_DRIVER_SCANCODE = 0, /* Driver or hardware generates a scancode */
+       RC_DRIVER_IR_RAW,       /* Needs a Infra-Red pulse/space decoder */
 };
 
+/**
+ * struct ir_dev_props - Allow caller drivers to set special properties
+ * @driver_type: specifies if the driver or hardware have already a decoder,
+ *     or if it needs to use the IR raw event decoders to produce a scancode
+ * @allowed_protos: bitmask with the supported IR_TYPE_* protocols
+ * @scanmask: some hardware decoders are not capable of providing the full
+ *     scancode to the application. As this is a hardware limit, we can't do
+ *     anything with it. Yet, as the same keycode table can be used with other
+ *     devices, a mask is provided to allow its usage. Drivers should generally
+ *     leave this field in blank
+ * @priv: driver-specific data, to be used on the callbacks
+ * @change_protocol: allow changing the protocol used on hardware decoders
+ * @open: callback to allow drivers to enable polling/irq when IR input device
+ *     is opened.
+ * @close: callback to allow drivers to disable polling/irq when IR input device
+ *     is opened.
+ */
 struct ir_dev_props {
-       unsigned long allowed_protos;
-       void            *priv;
-       int (*change_protocol)(void *priv, u64 ir_type);
+       enum rc_driver_type     driver_type;
+       unsigned long           allowed_protos;
+       u32                     scanmask;
+       void                    *priv;
+       int                     (*change_protocol)(void *priv, u64 ir_type);
+       int                     (*open)(void *priv);
+       void                    (*close)(void *priv);
 };
 
-
 struct ir_input_dev {
-       struct input_dev                *dev;           /* Input device*/
+       struct device                   dev;            /* device */
+       char                            *driver_name;   /* Name of the driver module */
        struct ir_scancode_table        rc_tab;         /* scan/key table */
        unsigned long                   devno;          /* device number */
-       struct attribute_group          attr;           /* IR attributes */
-       struct device                   *class_dev;     /* virtual class dev */
        const struct ir_dev_props       *props;         /* Device properties */
+       struct ir_raw_event_ctrl        *raw;           /* for raw pulse/space events */
+       struct input_dev                *input_dev;     /* the input device associated with this device */
+
+       /* key info - needed by IR keycode handlers */
+       spinlock_t                      keylock;        /* protects the below members */
+       bool                            keypressed;     /* current state */
+       unsigned long                   keyup_jiffies;  /* when should the current keypress be released? */
+       struct timer_list               timer_keyup;    /* timer for releasing a keypress */
+       u32                             last_keycode;   /* keycode of last command */
+       u32                             last_scancode;  /* scancode of last command */
+       u8                              last_toggle;    /* toggle of last command */
 };
-#define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
 
-/* Routines from ir-keytable.c */
+enum raw_event_type {
+       IR_SPACE        = (1 << 0),
+       IR_PULSE        = (1 << 1),
+       IR_START_EVENT  = (1 << 2),
+       IR_STOP_EVENT   = (1 << 3),
+};
 
-u32 ir_g_keycode_from_table(struct input_dev *input_dev,
-                           u32 scancode);
+#define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
 
-int ir_input_register(struct input_dev *dev,
+/* From ir-keytable.c */
+int __ir_input_register(struct input_dev *dev,
                      const struct ir_scancode_table *ir_codes,
-                     const struct ir_dev_props *props);
+                     const struct ir_dev_props *props,
+                     const char *driver_name);
+
+static inline int ir_input_register(struct input_dev *dev,
+                     const char *map_name,
+                     const struct ir_dev_props *props,
+                     const char *driver_name) {
+       struct ir_scancode_table *ir_codes;
+       struct ir_input_dev *ir_dev;
+       int rc;
+
+       if (!map_name)
+               return -EINVAL;
+
+       ir_codes = get_rc_map(map_name);
+       if (!ir_codes)
+               return -EINVAL;
+
+       rc = __ir_input_register(dev, ir_codes, props, driver_name);
+       if (rc < 0)
+               return -EINVAL;
+
+       ir_dev = input_get_drvdata(dev);
+
+       if (!rc && ir_dev->props && ir_dev->props->change_protocol)
+               rc = ir_dev->props->change_protocol(ir_dev->props->priv,
+                                                   ir_codes->ir_type);
+
+       return rc;
+}
+
 void ir_input_unregister(struct input_dev *input_dev);
 
-/* Routines from ir-sysfs.c */
+void ir_repeat(struct input_dev *dev);
+void ir_keydown(struct input_dev *dev, int scancode, u8 toggle);
+u32 ir_g_keycode_from_table(struct input_dev *input_dev, u32 scancode);
+
+/* From ir-raw-event.c */
+
+struct ir_raw_event {
+       unsigned                        pulse:1;
+       unsigned                        duration:31;
+};
+
+#define IR_MAX_DURATION                 0x7FFFFFFF      /* a bit more than 2 seconds */
 
-int ir_register_class(struct input_dev *input_dev);
-void ir_unregister_class(struct input_dev *input_dev);
+void ir_raw_event_handle(struct input_dev *input_dev);
+int ir_raw_event_store(struct input_dev *input_dev, struct ir_raw_event *ev);
+int ir_raw_event_store_edge(struct input_dev *input_dev, enum raw_event_type type);
+static inline void ir_raw_event_reset(struct input_dev *input_dev)
+{
+       struct ir_raw_event ev = { .pulse = false, .duration = 0 };
+       ir_raw_event_store(input_dev, &ev);
+       ir_raw_event_handle(input_dev);
+}
 
-#endif
+#endif /* _IR_CORE */
index 9142936..0506e45 100644 (file)
@@ -6,7 +6,7 @@
 struct IR_i2c;
 
 struct IR_i2c {
-       struct ir_scancode_table *ir_codes;
+       char                   *ir_codes;
 
        struct i2c_client      *c;
        struct input_dev       *input;
@@ -34,9 +34,9 @@ enum ir_kbd_get_key_fn {
 
 /* Can be passed when instantiating an ir_video i2c device */
 struct IR_i2c_init_data {
-       struct ir_scancode_table *ir_codes;
+       char                    *ir_codes;
        const char             *name;
-       u64          type; /* IR_TYPE_RC5, IR_TYPE_PD, etc */
+       u64          type; /* IR_TYPE_RC5, etc */
        /*
         * Specify either a function pointer or a value indicating one of
         * ir_kbd_i2c's internal get_key functions
diff --git a/include/media/rc-map.h b/include/media/rc-map.h
new file mode 100644 (file)
index 0000000..5833966
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * rc-map.h - define RC map names used by RC drivers
+ *
+ * Copyright (c) 2010 by Mauro Carvalho Chehab <mchehab@redhat.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.
+ */
+
+#include <linux/input.h>
+
+#define IR_TYPE_UNKNOWN        0
+#define IR_TYPE_RC5    (1  << 0)       /* Philips RC5 protocol */
+#define IR_TYPE_NEC    (1  << 1)
+#define IR_TYPE_RC6    (1  << 2)       /* Philips RC6 protocol */
+#define IR_TYPE_JVC    (1  << 3)       /* JVC protocol */
+#define IR_TYPE_SONY   (1  << 4)       /* Sony12/15/20 protocol */
+#define IR_TYPE_OTHER  (1u << 31)
+
+struct ir_scancode {
+       u32     scancode;
+       u32     keycode;
+};
+
+struct ir_scancode_table {
+       struct ir_scancode      *scan;
+       unsigned int            size;   /* Max number of entries */
+       unsigned int            len;    /* Used number of entries */
+       unsigned int            alloc;  /* Size of *scan in bytes */
+       u64                     ir_type;
+       char                    *name;
+       spinlock_t              lock;
+};
+
+struct rc_keymap {
+       struct list_head         list;
+       struct ir_scancode_table map;
+};
+
+/* Routines from rc-map.c */
+
+int ir_register_map(struct rc_keymap *map);
+void ir_unregister_map(struct rc_keymap *map);
+struct ir_scancode_table *get_rc_map(const char *name);
+void rc_map_init(void);
+
+/* Names of the several keytables defined in-kernel */
+
+#define RC_MAP_ADSTECH_DVB_T_PCI         "rc-adstech-dvb-t-pci"
+#define RC_MAP_APAC_VIEWCOMP             "rc-apac-viewcomp"
+#define RC_MAP_ASUS_PC39                 "rc-asus-pc39"
+#define RC_MAP_ATI_TV_WONDER_HD_600      "rc-ati-tv-wonder-hd-600"
+#define RC_MAP_AVERMEDIA_A16D            "rc-avermedia-a16d"
+#define RC_MAP_AVERMEDIA_CARDBUS         "rc-avermedia-cardbus"
+#define RC_MAP_AVERMEDIA_DVBT            "rc-avermedia-dvbt"
+#define RC_MAP_AVERMEDIA_M135A_RM_JX     "rc-avermedia-m135a-rm-jx"
+#define RC_MAP_AVERMEDIA                 "rc-avermedia"
+#define RC_MAP_AVERTV_303                "rc-avertv-303"
+#define RC_MAP_BEHOLD_COLUMBUS           "rc-behold-columbus"
+#define RC_MAP_BEHOLD                    "rc-behold"
+#define RC_MAP_BUDGET_CI_OLD             "rc-budget-ci-old"
+#define RC_MAP_CINERGY_1400              "rc-cinergy-1400"
+#define RC_MAP_CINERGY                   "rc-cinergy"
+#define RC_MAP_DM1105_NEC                "rc-dm1105-nec"
+#define RC_MAP_DNTV_LIVE_DVBT_PRO        "rc-dntv-live-dvbt-pro"
+#define RC_MAP_DNTV_LIVE_DVB_T           "rc-dntv-live-dvb-t"
+#define RC_MAP_EMPTY                     "rc-empty"
+#define RC_MAP_EM_TERRATEC               "rc-em-terratec"
+#define RC_MAP_ENCORE_ENLTV2             "rc-encore-enltv2"
+#define RC_MAP_ENCORE_ENLTV_FM53         "rc-encore-enltv-fm53"
+#define RC_MAP_ENCORE_ENLTV              "rc-encore-enltv"
+#define RC_MAP_EVGA_INDTUBE              "rc-evga-indtube"
+#define RC_MAP_EZTV                      "rc-eztv"
+#define RC_MAP_FLYDVB                    "rc-flydvb"
+#define RC_MAP_FLYVIDEO                  "rc-flyvideo"
+#define RC_MAP_FUSIONHDTV_MCE            "rc-fusionhdtv-mce"
+#define RC_MAP_GADMEI_RM008Z             "rc-gadmei-rm008z"
+#define RC_MAP_GENIUS_TVGO_A11MCE        "rc-genius-tvgo-a11mce"
+#define RC_MAP_GOTVIEW7135               "rc-gotview7135"
+#define RC_MAP_HAUPPAUGE_NEW             "rc-hauppauge-new"
+#define RC_MAP_IMON_MCE                  "rc-imon-mce"
+#define RC_MAP_IMON_PAD                  "rc-imon-pad"
+#define RC_MAP_IODATA_BCTV7E             "rc-iodata-bctv7e"
+#define RC_MAP_KAIOMY                    "rc-kaiomy"
+#define RC_MAP_KWORLD_315U               "rc-kworld-315u"
+#define RC_MAP_KWORLD_PLUS_TV_ANALOG     "rc-kworld-plus-tv-analog"
+#define RC_MAP_MANLI                     "rc-manli"
+#define RC_MAP_MSI_TVANYWHERE_PLUS       "rc-msi-tvanywhere-plus"
+#define RC_MAP_MSI_TVANYWHERE            "rc-msi-tvanywhere"
+#define RC_MAP_NEBULA                    "rc-nebula"
+#define RC_MAP_NEC_TERRATEC_CINERGY_XS   "rc-nec-terratec-cinergy-xs"
+#define RC_MAP_NORWOOD                   "rc-norwood"
+#define RC_MAP_NPGTECH                   "rc-npgtech"
+#define RC_MAP_PCTV_SEDNA                "rc-pctv-sedna"
+#define RC_MAP_PINNACLE_COLOR            "rc-pinnacle-color"
+#define RC_MAP_PINNACLE_GREY             "rc-pinnacle-grey"
+#define RC_MAP_PINNACLE_PCTV_HD          "rc-pinnacle-pctv-hd"
+#define RC_MAP_PIXELVIEW_NEW             "rc-pixelview-new"
+#define RC_MAP_PIXELVIEW                 "rc-pixelview"
+#define RC_MAP_PIXELVIEW_MK12            "rc-pixelview-mk12"
+#define RC_MAP_POWERCOLOR_REAL_ANGEL     "rc-powercolor-real-angel"
+#define RC_MAP_PROTEUS_2309              "rc-proteus-2309"
+#define RC_MAP_PURPLETV                  "rc-purpletv"
+#define RC_MAP_PV951                     "rc-pv951"
+#define RC_MAP_RC5_HAUPPAUGE_NEW         "rc-rc5-hauppauge-new"
+#define RC_MAP_RC5_TV                    "rc-rc5-tv"
+#define RC_MAP_REAL_AUDIO_220_32_KEYS    "rc-real-audio-220-32-keys"
+#define RC_MAP_TBS_NEC                   "rc-tbs-nec"
+#define RC_MAP_TERRATEC_CINERGY_XS       "rc-terratec-cinergy-xs"
+#define RC_MAP_TEVII_NEC                 "rc-tevii-nec"
+#define RC_MAP_TT_1500                   "rc-tt-1500"
+#define RC_MAP_VIDEOMATE_S350            "rc-videomate-s350"
+#define RC_MAP_VIDEOMATE_TV_PVR          "rc-videomate-tv-pvr"
+#define RC_MAP_WINFAST                   "rc-winfast"
+#define RC_MAP_WINFAST_USBII_DELUXE      "rc-winfast-usbii-deluxe"
+/*
+ * Please, do not just append newer Remote Controller names at the end.
+ * The names should be ordered in alphabetical order
+ */
diff --git a/include/media/sh_vou.h b/include/media/sh_vou.h
new file mode 100644 (file)
index 0000000..a3ef302
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SuperH Video Output Unit (VOU) driver header
+ *
+ * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef SH_VOU_H
+#define SH_VOU_H
+
+#include <linux/i2c.h>
+
+/* Bus flags */
+#define SH_VOU_PCLK_FALLING    (1 << 0)
+#define SH_VOU_HSYNC_LOW       (1 << 1)
+#define SH_VOU_VSYNC_LOW       (1 << 2)
+
+enum sh_vou_bus_fmt {
+       SH_VOU_BUS_8BIT,
+       SH_VOU_BUS_16BIT,
+       SH_VOU_BUS_BT656,
+};
+
+struct sh_vou_pdata {
+       enum sh_vou_bus_fmt bus_fmt;
+       int i2c_adap;
+       struct i2c_board_info *board_info;
+       unsigned long flags;
+       char *module_name;
+};
+
+#endif
index 9d69f01..c9a5bbf 100644 (file)
@@ -266,8 +266,8 @@ static inline unsigned long soc_camera_bus_param_compatible(
                common_flags;
 }
 
-static inline void soc_camera_limit_side(unsigned int *start,
-               unsigned int *length, unsigned int start_min,
+static inline void soc_camera_limit_side(int *start, int *length,
+               unsigned int start_min,
                unsigned int length_min, unsigned int length_max)
 {
        if (*length < length_min)
@@ -284,4 +284,12 @@ static inline void soc_camera_limit_side(unsigned int *start,
 extern unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl,
                                                   unsigned long flags);
 
+/* This is only temporary here - until v4l2-subdev begins to link to video_device */
+#include <linux/i2c.h>
+static inline struct video_device *soc_camera_i2c_to_vdev(struct i2c_client *client)
+{
+       struct soc_camera_device *icd = client->dev.platform_data;
+       return icd->vdev;
+}
+
 #endif
index 56abf21..21b4428 100644 (file)
 #define V4L2_CHIP_IDENT_H_
 
 /* VIDIOC_DBG_G_CHIP_IDENT: identifies the actual chip installed on the board */
+
+/* KEEP THIS LIST ORDERED BY ID!
+   Otherwise it will be hard to see which ranges are already in use when
+   adding support to a new chip family. */
 enum {
        /* general idents: reserved range 0-49 */
        V4L2_IDENT_NONE      = 0,       /* No chip matched */
@@ -77,17 +81,14 @@ enum {
        V4L2_IDENT_CX23417 = 417,
        V4L2_IDENT_CX23418 = 418,
 
-       /* module au0828 */
-       V4L2_IDENT_AU0828 = 828,
-
-       /* module indycam: just ident 2000 */
-       V4L2_IDENT_INDYCAM = 2000,
-
        /* module bt819: reserved range 810-819 */
        V4L2_IDENT_BT815A = 815,
        V4L2_IDENT_BT817A = 817,
        V4L2_IDENT_BT819A = 819,
 
+       /* module au0828 */
+       V4L2_IDENT_AU0828 = 828,
+
        /* module bt856: just ident 856 */
        V4L2_IDENT_BT856 = 856,
 
@@ -99,6 +100,9 @@ enum {
        V4L2_IDENT_KS0127  = 1127,
        V4L2_IDENT_KS0127B = 1128,
 
+       /* module indycam: just ident 2000 */
+       V4L2_IDENT_INDYCAM = 2000,
+
        /* module vp27smpx: just ident 2700 */
        V4L2_IDENT_VP27SMPX = 2700,
 
@@ -162,20 +166,21 @@ enum {
        /* module saa7706h: just ident 7706 */
        V4L2_IDENT_SAA7706H = 7706,
 
+       /* module mt9v011, just ident 8243 */
+       V4L2_IDENT_MT9V011 = 8243,
+
        /* module wm8739: just ident 8739 */
        V4L2_IDENT_WM8739 = 8739,
 
        /* module wm8775: just ident 8775 */
        V4L2_IDENT_WM8775 = 8775,
 
-       /* module tda9840: just ident 9840 */
-       V4L2_IDENT_TDA9840 = 9840,
-
        /* module cafe_ccic, just ident 8801 */
        V4L2_IDENT_CAFE = 8801,
 
-       /* module mt9v011, just ident 8243 */
-       V4L2_IDENT_MT9V011 = 8243,
+       /* AKM AK8813/AK8814 */
+       V4L2_IDENT_AK8813 = 8813,
+       V4L2_IDENT_AK8814 = 8814,
 
        /* module cx23885 and cx25840 */
        V4L2_IDENT_CX23885    = 8850,
@@ -186,6 +191,9 @@ enum {
        V4L2_IDENT_CX23888_AV = 8881, /* Integrated A/V decoder */
        V4L2_IDENT_CX23888_IR = 8882, /* Integrated infrared controller */
 
+       /* module tda9840: just ident 9840 */
+       V4L2_IDENT_TDA9840 = 9840,
+
        /* module tw9910: just ident 9910 */
        V4L2_IDENT_TW9910 = 9910,
 
@@ -198,72 +206,70 @@ enum {
        V4L2_IDENT_CX23101    = 23101,
        V4L2_IDENT_CX23102    = 23102,
 
-       /* module msp3400: reserved range 34000-34999 and 44000-44999 */
+       /* module msp3400: reserved range 34000-34999 for msp34xx */
        V4L2_IDENT_MSPX4XX  = 34000, /* generic MSPX4XX identifier, only
                                        use internally (tveeprom.c). */
 
        V4L2_IDENT_MSP3400B = 34002,
-       V4L2_IDENT_MSP3410B = 34102,
-
        V4L2_IDENT_MSP3400C = 34003,
-       V4L2_IDENT_MSP3410C = 34103,
-
        V4L2_IDENT_MSP3400D = 34004,
-       V4L2_IDENT_MSP3410D = 34104,
+       V4L2_IDENT_MSP3400G = 34007,
+       V4L2_IDENT_MSP3401G = 34017,
+       V4L2_IDENT_MSP3402G = 34027,
        V4L2_IDENT_MSP3405D = 34054,
-       V4L2_IDENT_MSP3415D = 34154,
+       V4L2_IDENT_MSP3405G = 34057,
        V4L2_IDENT_MSP3407D = 34074,
-       V4L2_IDENT_MSP3417D = 34174,
+       V4L2_IDENT_MSP3407G = 34077,
 
-       V4L2_IDENT_MSP3400G = 34007,
+       V4L2_IDENT_MSP3410B = 34102,
+       V4L2_IDENT_MSP3410C = 34103,
+       V4L2_IDENT_MSP3410D = 34104,
        V4L2_IDENT_MSP3410G = 34107,
-       V4L2_IDENT_MSP3420G = 34207,
-       V4L2_IDENT_MSP3430G = 34307,
-       V4L2_IDENT_MSP3440G = 34407,
-       V4L2_IDENT_MSP3450G = 34507,
-       V4L2_IDENT_MSP3460G = 34607,
-
-       V4L2_IDENT_MSP3401G = 34017,
        V4L2_IDENT_MSP3411G = 34117,
-       V4L2_IDENT_MSP3421G = 34217,
-       V4L2_IDENT_MSP3431G = 34317,
-       V4L2_IDENT_MSP3441G = 34417,
-       V4L2_IDENT_MSP3451G = 34517,
-       V4L2_IDENT_MSP3461G = 34617,
-
-       V4L2_IDENT_MSP3402G = 34027,
        V4L2_IDENT_MSP3412G = 34127,
-       V4L2_IDENT_MSP3422G = 34227,
-       V4L2_IDENT_MSP3442G = 34427,
-       V4L2_IDENT_MSP3452G = 34527,
-
-       V4L2_IDENT_MSP3405G = 34057,
+       V4L2_IDENT_MSP3415D = 34154,
        V4L2_IDENT_MSP3415G = 34157,
-       V4L2_IDENT_MSP3425G = 34257,
-       V4L2_IDENT_MSP3435G = 34357,
-       V4L2_IDENT_MSP3445G = 34457,
-       V4L2_IDENT_MSP3455G = 34557,
-       V4L2_IDENT_MSP3465G = 34657,
-
-       V4L2_IDENT_MSP3407G = 34077,
+       V4L2_IDENT_MSP3417D = 34174,
        V4L2_IDENT_MSP3417G = 34177,
+
+       V4L2_IDENT_MSP3420G = 34207,
+       V4L2_IDENT_MSP3421G = 34217,
+       V4L2_IDENT_MSP3422G = 34227,
+       V4L2_IDENT_MSP3425G = 34257,
        V4L2_IDENT_MSP3427G = 34277,
+
+       V4L2_IDENT_MSP3430G = 34307,
+       V4L2_IDENT_MSP3431G = 34317,
+       V4L2_IDENT_MSP3435G = 34357,
        V4L2_IDENT_MSP3437G = 34377,
+
+       V4L2_IDENT_MSP3440G = 34407,
+       V4L2_IDENT_MSP3441G = 34417,
+       V4L2_IDENT_MSP3442G = 34427,
+       V4L2_IDENT_MSP3445G = 34457,
        V4L2_IDENT_MSP3447G = 34477,
+
+       V4L2_IDENT_MSP3450G = 34507,
+       V4L2_IDENT_MSP3451G = 34517,
+       V4L2_IDENT_MSP3452G = 34527,
+       V4L2_IDENT_MSP3455G = 34557,
        V4L2_IDENT_MSP3457G = 34577,
+
+       V4L2_IDENT_MSP3460G = 34607,
+       V4L2_IDENT_MSP3461G = 34617,
+       V4L2_IDENT_MSP3465G = 34657,
        V4L2_IDENT_MSP3467G = 34677,
 
-       /* module msp3400: reserved range 34000-34999 and 44000-44999 */
+       /* module msp3400: reserved range 44000-44999 for msp44xx */
        V4L2_IDENT_MSP4400G = 44007,
-       V4L2_IDENT_MSP4410G = 44107,
-       V4L2_IDENT_MSP4420G = 44207,
-       V4L2_IDENT_MSP4440G = 44407,
-       V4L2_IDENT_MSP4450G = 44507,
-
        V4L2_IDENT_MSP4408G = 44087,
+       V4L2_IDENT_MSP4410G = 44107,
        V4L2_IDENT_MSP4418G = 44187,
+       V4L2_IDENT_MSP4420G = 44207,
        V4L2_IDENT_MSP4428G = 44287,
+       V4L2_IDENT_MSP4440G = 44407,
        V4L2_IDENT_MSP4448G = 44487,
+       V4L2_IDENT_MSP4450G = 44507,
        V4L2_IDENT_MSP4458G = 44587,
 
        /* Micron CMOS sensor chips: 45000-45099 */
@@ -282,20 +288,27 @@ enum {
        /* HV7131R CMOS sensor: just ident 46000 */
        V4L2_IDENT_HV7131R              = 46000,
 
+       /* Sharp RJ54N1CB0C, 0xCB0C = 51980 */
+       V4L2_IDENT_RJ54N1CB0C = 51980,
+
+       /* module m52790: just ident 52790 */
+       V4L2_IDENT_M52790 = 52790,
+
        /* module cs53132a: just ident 53132 */
        V4L2_IDENT_CS53l32A = 53132,
 
+       /* modules upd61151 MPEG2 encoder: just ident 54000 */
+       V4L2_IDENT_UPD61161 = 54000,
+       /* modules upd61152 MPEG2 encoder with AC3: just ident 54001 */
+       V4L2_IDENT_UPD61162 = 54001,
+
        /* module upd64031a: just ident 64031 */
        V4L2_IDENT_UPD64031A = 64031,
 
        /* module upd64083: just ident 64083 */
        V4L2_IDENT_UPD64083 = 64083,
 
-       /* module m52790: just ident 52790 */
-       V4L2_IDENT_M52790 = 52790,
-
-       /* Sharp RJ54N1CB0C, 0xCB0C = 51980 */
-       V4L2_IDENT_RJ54N1CB0C = 51980,
+       /* Don't just add new IDs at the end: KEEP THIS LIST ORDERED BY ID! */
 };
 
 #endif
index 1c7b259..98b3264 100644 (file)
 struct v4l2_prio_state {
        atomic_t prios[4];
 };
-int v4l2_prio_init(struct v4l2_prio_state *global);
+void v4l2_prio_init(struct v4l2_prio_state *global);
 int v4l2_prio_change(struct v4l2_prio_state *global, enum v4l2_priority *local,
                     enum v4l2_priority new);
-int v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
-int v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority *local);
+void v4l2_prio_open(struct v4l2_prio_state *global, enum v4l2_priority *local);
+void v4l2_prio_close(struct v4l2_prio_state *global, enum v4l2_priority local);
 enum v4l2_priority v4l2_prio_max(struct v4l2_prio_state *global);
-int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
+int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
 
 /* ------------------------------------------------------------------------- */
 
@@ -184,6 +184,25 @@ const unsigned short *v4l2_i2c_tuner_addrs(enum v4l2_i2c_tuner_type type);
 
 /* ------------------------------------------------------------------------- */
 
+/* SPI Helper functions */
+#if defined(CONFIG_SPI)
+
+#include <linux/spi/spi.h>
+
+struct spi_device;
+
+/* Load an spi module and return an initialized v4l2_subdev struct.
+   The client_type argument is the name of the chip that's on the adapter. */
+struct v4l2_subdev *v4l2_spi_new_subdev(struct v4l2_device *v4l2_dev,
+               struct spi_master *master, struct spi_board_info *info);
+
+/* Initialize an v4l2_subdev with data from an spi_device struct */
+void v4l2_spi_subdev_init(struct v4l2_subdev *sd, struct spi_device *spi,
+               const struct v4l2_subdev_ops *ops);
+#endif
+
+/* ------------------------------------------------------------------------- */
+
 /* Note: these remaining ioctls/structs should be removed as well, but they are
    still used in tuner-simple.c (TUNER_SET_CONFIG), cx18/ivtv (RESET) and
    v4l2-int-device.h (v4l2_routing). To remove these ioctls some more cleanup
index 2dee938..bebe44b 100644 (file)
@@ -32,6 +32,7 @@ struct v4l2_device;
    Drivers can clear this flag if they want to block all future
    device access. It is cleared by video_unregister_device. */
 #define V4L2_FL_REGISTERED     (0)
+#define V4L2_FL_USES_V4L2_FH   (1)
 
 struct v4l2_file_operations {
        struct module *owner;
@@ -77,6 +78,10 @@ struct video_device
        /* attribute to differentiate multiple indices on one physical device */
        int index;
 
+       /* V4L2 file handles */
+       spinlock_t              fh_lock; /* Lock for all v4l2_fhs */
+       struct list_head        fh_list; /* List of struct v4l2_fh */
+
        int debug;                      /* Activates debug level*/
 
        /* Video standard vars */
diff --git a/include/media/v4l2-event.h b/include/media/v4l2-event.h
new file mode 100644 (file)
index 0000000..3b86177
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * v4l2-event.h
+ *
+ * V4L2 events.
+ *
+ * Copyright (C) 2009--2010 Nokia Corporation.
+ *
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef V4L2_EVENT_H
+#define V4L2_EVENT_H
+
+#include <linux/types.h>
+#include <linux/videodev2.h>
+#include <linux/wait.h>
+
+struct v4l2_fh;
+struct video_device;
+
+struct v4l2_kevent {
+       struct list_head        list;
+       struct v4l2_event       event;
+};
+
+struct v4l2_subscribed_event {
+       struct list_head        list;
+       u32                     type;
+};
+
+struct v4l2_events {
+       wait_queue_head_t       wait;
+       struct list_head        subscribed; /* Subscribed events */
+       struct list_head        free; /* Events ready for use */
+       struct list_head        available; /* Dequeueable event */
+       unsigned int            navailable;
+       unsigned int            nallocated; /* Number of allocated events */
+       u32                     sequence;
+};
+
+int v4l2_event_init(struct v4l2_fh *fh);
+int v4l2_event_alloc(struct v4l2_fh *fh, unsigned int n);
+void v4l2_event_free(struct v4l2_fh *fh);
+int v4l2_event_dequeue(struct v4l2_fh *fh, struct v4l2_event *event,
+                      int nonblocking);
+void v4l2_event_queue(struct video_device *vdev, const struct v4l2_event *ev);
+int v4l2_event_pending(struct v4l2_fh *fh);
+int v4l2_event_subscribe(struct v4l2_fh *fh,
+                        struct v4l2_event_subscription *sub);
+int v4l2_event_unsubscribe(struct v4l2_fh *fh,
+                          struct v4l2_event_subscription *sub);
+
+#endif /* V4L2_EVENT_H */
diff --git a/include/media/v4l2-fh.h b/include/media/v4l2-fh.h
new file mode 100644 (file)
index 0000000..1d72dde
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * v4l2-fh.h
+ *
+ * V4L2 file handle. Store per file handle data for the V4L2
+ * framework. Using file handles is optional for the drivers.
+ *
+ * Copyright (C) 2009--2010 Nokia Corporation.
+ *
+ * Contact: Sakari Ailus <sakari.ailus@maxwell.research.nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef V4L2_FH_H
+#define V4L2_FH_H
+
+#include <linux/list.h>
+
+struct video_device;
+struct v4l2_events;
+
+struct v4l2_fh {
+       struct list_head        list;
+       struct video_device     *vdev;
+       struct v4l2_events      *events; /* events, pending and subscribed */
+};
+
+/*
+ * Initialise the file handle. Parts of the V4L2 framework using the
+ * file handles should be initialised in this function. Must be called
+ * from driver's v4l2_file_operations->open() handler if the driver
+ * uses v4l2_fh.
+ */
+int v4l2_fh_init(struct v4l2_fh *fh, struct video_device *vdev);
+/*
+ * Add the fh to the list of file handles on a video_device. The file
+ * handle must be initialised first.
+ */
+void v4l2_fh_add(struct v4l2_fh *fh);
+/*
+ * Remove file handle from the list of file handles. Must be called in
+ * v4l2_file_operations->release() handler if the driver uses v4l2_fh.
+ */
+void v4l2_fh_del(struct v4l2_fh *fh);
+/*
+ * Release resources related to a file handle. Parts of the V4L2
+ * framework using the v4l2_fh must release their resources here, too.
+ * Must be called in v4l2_file_operations->release() handler if the
+ * driver uses v4l2_fh.
+ */
+void v4l2_fh_exit(struct v4l2_fh *fh);
+
+#endif /* V4L2_EVENT_H */
index e8ba0f2..06daa6e 100644 (file)
@@ -21,6 +21,8 @@
 #include <linux/videodev2.h>
 #endif
 
+struct v4l2_fh;
+
 struct v4l2_ioctl_ops {
        /* ioctl callbacks */
 
@@ -254,6 +256,11 @@ struct v4l2_ioctl_ops {
        int (*vidioc_g_dv_timings) (struct file *file, void *fh,
                                    struct v4l2_dv_timings *timings);
 
+       int (*vidioc_subscribe_event)  (struct v4l2_fh *fh,
+                                       struct v4l2_event_subscription *sub);
+       int (*vidioc_unsubscribe_event)(struct v4l2_fh *fh,
+                                       struct v4l2_event_subscription *sub);
+
        /* For other private ioctls */
        long (*vidioc_default)         (struct file *file, void *fh,
                                        int cmd, void *arg);
diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h
new file mode 100644 (file)
index 0000000..8d149f1
--- /dev/null
@@ -0,0 +1,201 @@
+/*
+ * Memory-to-memory device framework for Video for Linux 2.
+ *
+ * Helper functions for devices that use memory buffers for both source
+ * and destination.
+ *
+ * Copyright (c) 2009 Samsung Electronics Co., Ltd.
+ * Pawel Osciak, <p.osciak@samsung.com>
+ * Marek Szyprowski, <m.szyprowski@samsung.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
+ */
+
+#ifndef _MEDIA_V4L2_MEM2MEM_H
+#define _MEDIA_V4L2_MEM2MEM_H
+
+#include <media/videobuf-core.h>
+
+/**
+ * struct v4l2_m2m_ops - mem-to-mem device driver callbacks
+ * @device_run:        required. Begin the actual job (transaction) inside this
+ *             callback.
+ *             The job does NOT have to end before this callback returns
+ *             (and it will be the usual case). When the job finishes,
+ *             v4l2_m2m_job_finish() has to be called.
+ * @job_ready: optional. Should return 0 if the driver does not have a job
+ *             fully prepared to run yet (i.e. it will not be able to finish a
+ *             transaction without sleeping). If not provided, it will be
+ *             assumed that one source and one destination buffer are all
+ *             that is required for the driver to perform one full transaction.
+ *             This method may not sleep.
+ * @job_abort: required. Informs the driver that it has to abort the currently
+ *             running transaction as soon as possible (i.e. as soon as it can
+ *             stop the device safely; e.g. in the next interrupt handler),
+ *             even if the transaction would not have been finished by then.
+ *             After the driver performs the necessary steps, it has to call
+ *             v4l2_m2m_job_finish() (as if the transaction ended normally).
+ *             This function does not have to (and will usually not) wait
+ *             until the device enters a state when it can be stopped.
+ */
+struct v4l2_m2m_ops {
+       void (*device_run)(void *priv);
+       int (*job_ready)(void *priv);
+       void (*job_abort)(void *priv);
+};
+
+struct v4l2_m2m_dev;
+
+struct v4l2_m2m_queue_ctx {
+/* private: internal use only */
+       struct videobuf_queue   q;
+
+       /* Queue for buffers ready to be processed as soon as this
+        * instance receives access to the device */
+       struct list_head        rdy_queue;
+       u8                      num_rdy;
+};
+
+struct v4l2_m2m_ctx {
+/* private: internal use only */
+       struct v4l2_m2m_dev             *m2m_dev;
+
+       /* Capture (output to memory) queue context */
+       struct v4l2_m2m_queue_ctx       cap_q_ctx;
+
+       /* Output (input from memory) queue context */
+       struct v4l2_m2m_queue_ctx       out_q_ctx;
+
+       /* For device job queue */
+       struct list_head                queue;
+       unsigned long                   job_flags;
+
+       /* Instance private data */
+       void                            *priv;
+};
+
+void *v4l2_m2m_get_curr_priv(struct v4l2_m2m_dev *m2m_dev);
+
+struct videobuf_queue *v4l2_m2m_get_vq(struct v4l2_m2m_ctx *m2m_ctx,
+                                      enum v4l2_buf_type type);
+
+void v4l2_m2m_job_finish(struct v4l2_m2m_dev *m2m_dev,
+                        struct v4l2_m2m_ctx *m2m_ctx);
+
+int v4l2_m2m_reqbufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                    struct v4l2_requestbuffers *reqbufs);
+
+int v4l2_m2m_querybuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                     struct v4l2_buffer *buf);
+
+int v4l2_m2m_qbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                 struct v4l2_buffer *buf);
+int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                  struct v4l2_buffer *buf);
+
+int v4l2_m2m_streamon(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                     enum v4l2_buf_type type);
+int v4l2_m2m_streamoff(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                      enum v4l2_buf_type type);
+
+unsigned int v4l2_m2m_poll(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                          struct poll_table_struct *wait);
+
+int v4l2_m2m_mmap(struct file *file, struct v4l2_m2m_ctx *m2m_ctx,
+                 struct vm_area_struct *vma);
+
+struct v4l2_m2m_dev *v4l2_m2m_init(struct v4l2_m2m_ops *m2m_ops);
+void v4l2_m2m_release(struct v4l2_m2m_dev *m2m_dev);
+
+struct v4l2_m2m_ctx *v4l2_m2m_ctx_init(void *priv, struct v4l2_m2m_dev *m2m_dev,
+                       void (*vq_init)(void *priv, struct videobuf_queue *,
+                                       enum v4l2_buf_type));
+void v4l2_m2m_ctx_release(struct v4l2_m2m_ctx *m2m_ctx);
+
+void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, struct videobuf_queue *vq,
+                       struct videobuf_buffer *vb);
+
+/**
+ * v4l2_m2m_num_src_bufs_ready() - return the number of source buffers ready for
+ * use
+ */
+static inline
+unsigned int v4l2_m2m_num_src_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return m2m_ctx->cap_q_ctx.num_rdy;
+}
+
+/**
+ * v4l2_m2m_num_src_bufs_ready() - return the number of destination buffers
+ * ready for use
+ */
+static inline
+unsigned int v4l2_m2m_num_dst_bufs_ready(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return m2m_ctx->out_q_ctx.num_rdy;
+}
+
+void *v4l2_m2m_next_buf(struct v4l2_m2m_ctx *m2m_ctx, enum v4l2_buf_type type);
+
+/**
+ * v4l2_m2m_next_src_buf() - return next source buffer from the list of ready
+ * buffers
+ */
+static inline void *v4l2_m2m_next_src_buf(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+}
+
+/**
+ * v4l2_m2m_next_dst_buf() - return next destination buffer from the list of
+ * ready buffers
+ */
+static inline void *v4l2_m2m_next_dst_buf(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_next_buf(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+}
+
+/**
+ * v4l2_m2m_get_src_vq() - return videobuf_queue for source buffers
+ */
+static inline
+struct videobuf_queue *v4l2_m2m_get_src_vq(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+}
+
+/**
+ * v4l2_m2m_get_dst_vq() - return videobuf_queue for destination buffers
+ */
+static inline
+struct videobuf_queue *v4l2_m2m_get_dst_vq(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_get_vq(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+}
+
+void *v4l2_m2m_buf_remove(struct v4l2_m2m_ctx *m2m_ctx,
+                         enum v4l2_buf_type type);
+
+/**
+ * v4l2_m2m_src_buf_remove() - take off a source buffer from the list of ready
+ * buffers and return it
+ */
+static inline void *v4l2_m2m_src_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
+}
+
+/**
+ * v4l2_m2m_dst_buf_remove() - take off a destination buffer from the list of
+ * ready buffers and return it
+ */
+static inline void *v4l2_m2m_dst_buf_remove(struct v4l2_m2m_ctx *m2m_ctx)
+{
+       return v4l2_m2m_buf_remove(m2m_ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE);
+}
+
+#endif /* _MEDIA_V4L2_MEM2MEM_H */
+
index 2bcdca0..a888893 100644 (file)
@@ -184,28 +184,6 @@ struct v4l2_subdev_audio_ops {
 };
 
 /*
-   decode_vbi_line: video decoders that support sliced VBI need to implement
-       this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the
-       start of the VBI data that was generated by the decoder. The driver
-       then parses the sliced VBI data and sets the other fields in the
-       struct accordingly. The pointer p is updated to point to the start of
-       the payload which can be copied verbatim into the data field of the
-       v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the
-       type field is set to 0 on return.
-
-   s_vbi_data: used to generate VBI signals on a video signal.
-       v4l2_sliced_vbi_data is filled with the data packets that should be
-       output. Note that if you set the line field to 0, then that VBI signal
-       is disabled. If no valid VBI data was found, then the type field is
-       set to 0 on return.
-
-   g_vbi_data: used to obtain the sliced VBI packet from a readback register.
-       Not all video decoders support this. If no data is available because
-       the readback register contains invalid or erroneous data -EIO is
-       returned. Note that you must fill in the 'id' member and the 'field'
-       member (to determine whether CC data from the first or second field
-       should be obtained).
-
    s_std_output: set v4l2_std_id for video OUTPUT devices. This is ignored by
        video input devices.
 
@@ -243,10 +221,6 @@ struct v4l2_subdev_audio_ops {
 struct v4l2_subdev_video_ops {
        int (*s_routing)(struct v4l2_subdev *sd, u32 input, u32 output, u32 config);
        int (*s_crystal_freq)(struct v4l2_subdev *sd, u32 freq, u32 flags);
-       int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
-       int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
-       int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
-       int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
        int (*s_std_output)(struct v4l2_subdev *sd, v4l2_std_id std);
        int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std);
        int (*g_input_status)(struct v4l2_subdev *sd, u32 *status);
@@ -262,6 +236,8 @@ struct v4l2_subdev_video_ops {
        int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param);
        int (*enum_framesizes)(struct v4l2_subdev *sd, struct v4l2_frmsizeenum *fsize);
        int (*enum_frameintervals)(struct v4l2_subdev *sd, struct v4l2_frmivalenum *fival);
+       int (*enum_dv_presets) (struct v4l2_subdev *sd,
+                       struct v4l2_dv_enum_preset *preset);
        int (*s_dv_preset)(struct v4l2_subdev *sd,
                        struct v4l2_dv_preset *preset);
        int (*query_dv_preset)(struct v4l2_subdev *sd,
@@ -280,6 +256,45 @@ struct v4l2_subdev_video_ops {
                          struct v4l2_mbus_framefmt *fmt);
 };
 
+/*
+   decode_vbi_line: video decoders that support sliced VBI need to implement
+       this ioctl. Field p of the v4l2_sliced_vbi_line struct is set to the
+       start of the VBI data that was generated by the decoder. The driver
+       then parses the sliced VBI data and sets the other fields in the
+       struct accordingly. The pointer p is updated to point to the start of
+       the payload which can be copied verbatim into the data field of the
+       v4l2_sliced_vbi_data struct. If no valid VBI data was found, then the
+       type field is set to 0 on return.
+
+   s_vbi_data: used to generate VBI signals on a video signal.
+       v4l2_sliced_vbi_data is filled with the data packets that should be
+       output. Note that if you set the line field to 0, then that VBI signal
+       is disabled. If no valid VBI data was found, then the type field is
+       set to 0 on return.
+
+   g_vbi_data: used to obtain the sliced VBI packet from a readback register.
+       Not all video decoders support this. If no data is available because
+       the readback register contains invalid or erroneous data -EIO is
+       returned. Note that you must fill in the 'id' member and the 'field'
+       member (to determine whether CC data from the first or second field
+       should be obtained).
+
+   s_raw_fmt: setup the video encoder/decoder for raw VBI.
+
+   g_sliced_fmt: retrieve the current sliced VBI settings.
+
+   s_sliced_fmt: setup the sliced VBI settings.
+ */
+struct v4l2_subdev_vbi_ops {
+       int (*decode_vbi_line)(struct v4l2_subdev *sd, struct v4l2_decode_vbi_line *vbi_line);
+       int (*s_vbi_data)(struct v4l2_subdev *sd, const struct v4l2_sliced_vbi_data *vbi_data);
+       int (*g_vbi_data)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_data *vbi_data);
+       int (*g_sliced_vbi_cap)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_cap *cap);
+       int (*s_raw_fmt)(struct v4l2_subdev *sd, struct v4l2_vbi_format *fmt);
+       int (*g_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
+       int (*s_sliced_fmt)(struct v4l2_subdev *sd, struct v4l2_sliced_vbi_format *fmt);
+};
+
 /**
  * struct v4l2_subdev_sensor_ops - v4l2-subdev sensor operations
  * @g_skip_top_lines: number of lines at the top of the image to be skipped.
@@ -379,6 +394,7 @@ struct v4l2_subdev_ops {
        const struct v4l2_subdev_tuner_ops      *tuner;
        const struct v4l2_subdev_audio_ops      *audio;
        const struct v4l2_subdev_video_ops      *video;
+       const struct v4l2_subdev_vbi_ops        *vbi;
        const struct v4l2_subdev_ir_ops         *ir;
        const struct v4l2_subdev_sensor_ops     *sensor;
 };
@@ -387,6 +403,8 @@ struct v4l2_subdev_ops {
 
 /* Set this flag if this subdev is a i2c device. */
 #define V4L2_SUBDEV_FL_IS_I2C (1U << 0)
+/* Set this flag if this subdev is a spi device. */
+#define V4L2_SUBDEV_FL_IS_SPI (1U << 1)
 
 /* Each instance of a subdev driver should create this struct, either
    stand-alone or embedded in a larger struct.
index 316fdcc..f91a736 100644 (file)
@@ -127,30 +127,16 @@ struct videobuf_queue_ops {
 struct videobuf_qtype_ops {
        u32                     magic;
 
-       void *(*alloc)          (size_t size);
-       void *(*vmalloc)        (struct videobuf_buffer *buf);
-       int (*iolock)           (struct videobuf_queueq,
+       struct videobuf_buffer *(*alloc)(size_t size);
+       void *(*vaddr)          (struct videobuf_buffer *buf);
+       int (*iolock)           (struct videobuf_queue *q,
                                 struct videobuf_buffer *vb,
                                 struct v4l2_framebuffer *fbuf);
-       int (*mmap)             (struct videobuf_queue *q,
-                                unsigned int *count,
-                                unsigned int *size,
-                                enum v4l2_memory memory);
-       int (*sync)             (struct videobuf_queue* q,
+       int (*sync)             (struct videobuf_queue *q,
                                 struct videobuf_buffer *buf);
-       int (*video_copy_to_user)(struct videobuf_queue *q,
-                                char __user *data,
-                                size_t count,
-                                int nonblocking);
-       int (*copy_stream)      (struct videobuf_queue *q,
-                                char __user *data,
-                                size_t count,
-                                size_t pos,
-                                int vbihack,
-                                int nonblocking);
-       int (*mmap_free)        (struct videobuf_queue *q);
        int (*mmap_mapper)      (struct videobuf_queue *q,
-                               struct vm_area_struct *vma);
+                                struct videobuf_buffer *buf,
+                                struct vm_area_struct *vma);
 };
 
 struct videobuf_queue {
@@ -171,7 +157,6 @@ struct videobuf_queue {
 
        unsigned int               streaming:1;
        unsigned int               reading:1;
-       unsigned int               is_mmapped:1;
 
        /* capture via mmap() + ioctl(QBUF/DQBUF) */
        struct list_head           stream;
@@ -185,14 +170,14 @@ struct videobuf_queue {
 };
 
 int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr);
-int videobuf_iolock(struct videobuf_queueq, struct videobuf_buffer *vb,
+int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
                struct v4l2_framebuffer *fbuf);
 
-void *videobuf_alloc(struct videobuf_queue* q);
+struct videobuf_buffer *videobuf_alloc(struct videobuf_queue *q);
 
 /* Used on videobuf-dvb */
-void *videobuf_queue_to_vmalloc (struct videobuf_queue* q,
-                                struct videobuf_buffer *buf);
+void *videobuf_queue_to_vaddr(struct videobuf_queue *q,
+                             struct videobuf_buffer *buf);
 
 void videobuf_queue_core_init(struct videobuf_queue *q,
                         const struct videobuf_queue_ops *ops,
index 53e72f7..a195f3b 100644 (file)
@@ -17,6 +17,8 @@
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2
  */
+#ifndef _VIDEOBUF_DMA_SG_H
+#define _VIDEOBUF_DMA_SG_H
 
 #include <media/videobuf-core.h>
 
  * block (NULL on errors).  Memory for the scatterlist is allocated
  * using kmalloc.  The caller must free the memory.
  */
-struct scatterlistvideobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
+struct scatterlist *videobuf_vmalloc_to_sg(unsigned char *virt, int nr_pages);
 
 /*
  * Return a scatterlist for a an array of userpages (NULL on errors).
  * Memory for the scatterlist is allocated using kmalloc.  The caller
  * must free the memory.
  */
-struct scatterlistvideobuf_pages_to_sg(struct page **pages, int nr_pages,
+struct scatterlist *videobuf_pages_to_sg(struct page **pages, int nr_pages,
                                         int offset);
 
 /* --------------------------------------------------------------------- */
@@ -78,8 +80,7 @@ struct videobuf_dmabuf {
        int                 direction;
 };
 
-struct videobuf_dma_sg_memory
-{
+struct videobuf_dma_sg_memory {
        u32                 magic;
 
        /* for mmap'ed buffers */
@@ -95,14 +96,13 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
                              dma_addr_t addr, int nr_pages);
 int videobuf_dma_free(struct videobuf_dmabuf *dma);
 
-int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
-int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
-int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
-struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf);
+int videobuf_dma_map(struct videobuf_queue *q, struct videobuf_dmabuf *dma);
+int videobuf_dma_unmap(struct videobuf_queue *q, struct videobuf_dmabuf *dma);
+struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf);
 
 void *videobuf_sg_alloc(size_t size);
 
-void videobuf_queue_sg_init(struct videobuf_queueq,
+void videobuf_queue_sg_init(struct videobuf_queue *q,
                         const struct videobuf_queue_ops *ops,
                         struct device *dev,
                         spinlock_t *irqlock,
@@ -111,9 +111,11 @@ void videobuf_queue_sg_init(struct videobuf_queue* q,
                         unsigned int msize,
                         void *priv);
 
-       /*FIXME: these variants are used only on *-alsa code, where videobuf is
       * used without queue
       */
+/*FIXME: these variants are used only on *-alsa code, where videobuf is
+ * used without queue
+ */
 int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
 int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
 
+#endif /* _VIDEOBUF_DMA_SG_H */
+
index 4b419a2..851eb1a 100644 (file)
 
 /* --------------------------------------------------------------------- */
 
-struct videobuf_vmalloc_memory
-{
+struct videobuf_vmalloc_memory {
        u32                 magic;
 
        void                *vmalloc;
 
-       /* remap_vmalloc_range seems to need to run after mmap() on some cases */
+       /* remap_vmalloc_range seems to need to run
+        * after mmap() on some cases */
        struct vm_area_struct *vma;
 };
 
-void videobuf_queue_vmalloc_init(struct videobuf_queueq,
+void videobuf_queue_vmalloc_init(struct videobuf_queue *q,
                         const struct videobuf_queue_ops *ops,
                         struct device *dev,
                         spinlock_t *irqlock,
@@ -38,8 +38,8 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
                         unsigned int msize,
                         void *priv);
 
-void *videobuf_to_vmalloc (struct videobuf_buffer *buf);
+void *videobuf_to_vmalloc(struct videobuf_buffer *buf);
 
-void videobuf_vmalloc_free (struct videobuf_buffer *buf);
+void videobuf_vmalloc_free(struct videobuf_buffer *buf);
 
 #endif
index 75fa353..57d8d03 100644 (file)
@@ -85,6 +85,7 @@ typedef struct config_req_t {
 #define CONF_ENABLE_IRQ                0x01
 #define CONF_ENABLE_DMA                0x02
 #define CONF_ENABLE_SPKR       0x04
+#define CONF_ENABLE_PULSE_IRQ  0x08
 #define CONF_VALID_CLIENT      0x100
 
 /* IntType field */
@@ -113,25 +114,7 @@ typedef struct io_req_t {
 #define IO_DATA_PATH_WIDTH_16  0x08
 #define IO_DATA_PATH_WIDTH_AUTO        0x10
 
-/* For RequestIRQ and ReleaseIRQ */
-typedef struct irq_req_t {
-       u_int           Attributes;
-       u_int           AssignedIRQ;
-       irq_handler_t   Handler;
-} irq_req_t;
-
-/* Attributes for RequestIRQ and ReleaseIRQ */
-#define IRQ_TYPE                       0x03
-#define IRQ_TYPE_EXCLUSIVE             0x00
-#define IRQ_TYPE_TIME                  0x01
-#define IRQ_TYPE_DYNAMIC_SHARING       0x02
-#define IRQ_FORCED_PULSE               0x04
-#define IRQ_FIRST_SHARED               0x08 /* unused */
-#define IRQ_HANDLE_PRESENT             0x10 /* unused */
-#define IRQ_PULSE_ALLOCATED            0x100
-
 /* Bits in IRQInfo1 field */
-#define IRQ_MASK               0x0f
 #define IRQ_NMI_ID             0x01
 #define IRQ_IOCK_ID            0x02
 #define IRQ_BERR_ID            0x04
index aab3c13..c180165 100644 (file)
@@ -62,15 +62,6 @@ struct pcmcia_driver {
 int pcmcia_register_driver(struct pcmcia_driver *driver);
 void pcmcia_unregister_driver(struct pcmcia_driver *driver);
 
-/* Some drivers use dev_node_t to store char or block device information.
- * Don't use this in new drivers, though.
- */
-typedef struct dev_node_t {
-       char                    dev_name[DEV_NAME_LEN];
-       u_short                 major, minor;
-       struct dev_node_t       *next;
-} dev_node_t;
-
 struct pcmcia_device {
        /* the socket and the device_no [for multifunction devices]
           uniquely define a pcmcia_device */
@@ -88,13 +79,14 @@ struct pcmcia_device {
        struct list_head        socket_device_list;
 
        /* deprecated, will be cleaned up soon */
-       dev_node_t              *dev_node;
        u_int                   open;
        io_req_t                io;
-       irq_req_t               irq;
        config_req_t            conf;
        window_handle_t         win;
 
+       /* device setup */
+       unsigned int            irq;
+
        /* Is the device suspended? */
        u16                     suspended:1;
 
@@ -191,7 +183,20 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
 
 /* device configuration */
 int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
-int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
+
+int __must_check
+__pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
+                               irq_handler_t handler);
+static inline __must_check __deprecated int
+pcmcia_request_exclusive_irq(struct pcmcia_device *p_dev,
+                               irq_handler_t handler)
+{
+       return __pcmcia_request_exclusive_irq(p_dev, handler);
+}
+
+int __must_check pcmcia_request_irq(struct pcmcia_device *p_dev,
+                               irq_handler_t handler);
+
 int pcmcia_request_configuration(struct pcmcia_device *p_dev,
                                 config_req_t *req);
 
diff --git a/include/pcmcia/mem_op.h b/include/pcmcia/mem_op.h
deleted file mode 100644 (file)
index 0fa06e5..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * mem_op.h
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * The initial developer of the original code is David A. Hinds
- * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
- * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
- *
- * (C) 1999             David A. Hinds
- */
-
-#ifndef _LINUX_MEM_OP_H
-#define _LINUX_MEM_OP_H
-
-#include <linux/io.h>
-#include <asm/uaccess.h>
-
-/*
-   If UNSAFE_MEMCPY is defined, we use the (optimized) system routines
-   to copy between a card and kernel memory.  These routines do 32-bit
-   operations which may not work with all PCMCIA controllers.  The
-   safe versions defined here will do only 8-bit and 16-bit accesses.
-*/
-
-#ifdef UNSAFE_MEMCPY
-
-#define copy_from_pc memcpy_fromio
-#define copy_to_pc memcpy_toio
-
-static inline void copy_pc_to_user(void *to, const void *from, size_t n)
-{
-    size_t odd = (n & 3);
-    n -= odd;
-    while (n) {
-       put_user(__raw_readl(from), (int *)to);
-       (char *)from += 4; (char *)to += 4; n -= 4;
-    }
-    while (odd--)
-       put_user(readb((char *)from++), (char *)to++);
-}
-
-static inline void copy_user_to_pc(void *to, const void *from, size_t n)
-{
-    int l;
-    char c;
-    size_t odd = (n & 3);
-    n -= odd;
-    while (n) {
-       get_user(l, (int *)from);
-       __raw_writel(l, to);
-       (char *)to += 4; (char *)from += 4; n -= 4;
-    }
-    while (odd--) {
-       get_user(c, (char *)from++);
-       writeb(c, (char *)to++);
-    }
-}
-
-#else /* UNSAFE_MEMCPY */
-
-static inline void copy_from_pc(void *to, void __iomem *from, size_t n)
-{
-       __u16 *t = to;
-       __u16 __iomem *f = from;
-       size_t odd = (n & 1);
-       for (n >>= 1; n; n--)
-               *t++ = __raw_readw(f++);
-       if (odd)
-               *(__u8 *)t = readb(f);
-}
-
-static inline void copy_to_pc(void __iomem *to, const void *from, size_t n)
-{
-       __u16 __iomem *t = to;
-       const __u16 *f = from;
-       size_t odd = (n & 1);
-       for (n >>= 1; n ; n--)
-               __raw_writew(*f++, t++);
-       if (odd)
-               writeb(*(__u8 *)f, t);
-}
-
-static inline void copy_pc_to_user(void __user *to, void __iomem *from, size_t n)
-{
-       __u16 __user *t = to;
-       __u16 __iomem *f = from;
-       size_t odd = (n & 1);
-       for (n >>= 1; n ; n--)
-               put_user(__raw_readw(f++), t++);
-       if (odd)
-               put_user(readb(f), (char __user *)t);
-}
-
-static inline void copy_user_to_pc(void __iomem *to, void __user *from, size_t n)
-{
-       __u16 __user *f = from;
-       __u16 __iomem *t = to;
-       short s;
-       char c;
-       size_t odd = (n & 1);
-       for (n >>= 1; n; n--) {
-               get_user(s, f++);
-               __raw_writew(s, t++);
-       }
-       if (odd) {
-               get_user(c, (char __user *)f);
-               writeb(c, t);
-       }
-}
-
-#endif /* UNSAFE_MEMCPY */
-
-#endif /* _LINUX_MEM_OP_H */
index 344705c..764281b 100644 (file)
@@ -141,10 +141,6 @@ struct pcmcia_socket {
        u_short                         lock_count;
        pccard_mem_map                  cis_mem;
        void __iomem                    *cis_virt;
-       struct {
-               u_int                   AssignedIRQ;
-               u_int                   Config;
-       } irq;
        io_window_t                     io[MAX_IO_WIN];
        pccard_mem_map                  win[MAX_WIN];
        struct list_head                cis_cache;
@@ -235,6 +231,9 @@ struct pcmcia_socket {
        /* non-zero if PCMCIA card is present */
        atomic_t                        present;
 
+       /* IRQ to be used by PCMCIA devices. May not be IRQ 0. */
+       unsigned int                    pcmcia_irq;
+
 #ifdef CONFIG_PCMCIA_IOCTL
        struct user_info_t              *user;
        wait_queue_head_t               queue;
index a585e0f..310d314 100644 (file)
@@ -136,6 +136,7 @@ struct ib_device_attr {
        int                     max_qp_init_rd_atom;
        int                     max_ee_init_rd_atom;
        enum ib_atomic_cap      atomic_cap;
+       enum ib_atomic_cap      masked_atomic_cap;
        int                     max_ee;
        int                     max_rdd;
        int                     max_mw;
@@ -467,6 +468,8 @@ enum ib_wc_opcode {
        IB_WC_LSO,
        IB_WC_LOCAL_INV,
        IB_WC_FAST_REG_MR,
+       IB_WC_MASKED_COMP_SWAP,
+       IB_WC_MASKED_FETCH_ADD,
 /*
  * Set value of IB_WC_RECV so consumers can test if a completion is a
  * receive by testing (opcode & IB_WC_RECV).
@@ -689,6 +692,8 @@ enum ib_wr_opcode {
        IB_WR_RDMA_READ_WITH_INV,
        IB_WR_LOCAL_INV,
        IB_WR_FAST_REG_MR,
+       IB_WR_MASKED_ATOMIC_CMP_AND_SWP,
+       IB_WR_MASKED_ATOMIC_FETCH_AND_ADD,
 };
 
 enum ib_send_flags {
@@ -731,6 +736,8 @@ struct ib_send_wr {
                        u64     remote_addr;
                        u64     compare_add;
                        u64     swap;
+                       u64     compare_add_mask;
+                       u64     swap_mask;
                        u32     rkey;
                } atomic;
                struct {
index 0985955..9f1eecf 100644 (file)
@@ -574,7 +574,7 @@ enum {
 #define SNDRV_TIMER_FLG_SLAVE          (1<<0)  /* cannot be controlled */
 
 struct snd_timer_id {
-       int dev_class;  
+       int dev_class;
        int dev_sclass;
        int card;
        int device;
@@ -762,7 +762,7 @@ struct snd_ctl_elem_id {
        snd_ctl_elem_iface_t iface;     /* interface identifier */
        unsigned int device;            /* device/client number */
        unsigned int subdevice;         /* subdevice (substream) number */
-        unsigned char name[44];                /* ASCII name of item */
+       unsigned char name[44];         /* ASCII name of item */
        unsigned int index;             /* index of item */
 };
 
@@ -809,7 +809,7 @@ struct snd_ctl_elem_info {
 struct snd_ctl_elem_value {
        struct snd_ctl_elem_id id;      /* W: element ID */
        unsigned int indirect: 1;       /* W: indirect access - obsoleted */
-        union {
+       union {
                union {
                        long value[128];
                        long *value_ptr;        /* obsoleted */
@@ -827,15 +827,15 @@ struct snd_ctl_elem_value {
                        unsigned char *data_ptr;        /* obsoleted */
                } bytes;
                struct snd_aes_iec958 iec958;
-        } value;                /* RO */
+       } value;                /* RO */
        struct timespec tstamp;
-        unsigned char reserved[128-sizeof(struct timespec)];
+       unsigned char reserved[128-sizeof(struct timespec)];
 };
 
 struct snd_ctl_tlv {
-        unsigned int numid;    /* control element numeric identification */
-        unsigned int length;   /* in bytes aligned to 4 */
-        unsigned int tlv[0];   /* first TLV */
+       unsigned int numid;     /* control element numeric identification */
+       unsigned int length;    /* in bytes aligned to 4 */
+       unsigned int tlv[0];    /* first TLV */
 };
 
 #define SNDRV_CTL_IOCTL_PVERSION       _IOR('U', 0x00, int)
@@ -886,8 +886,8 @@ struct snd_ctl_event {
                        unsigned int mask;
                        struct snd_ctl_elem_id id;
                } elem;
-                unsigned char data8[60];
-        } data;
+               unsigned char data8[60];
+       } data;
 };
 
 /*
index 10fcf14..3ec7ecb 100644 (file)
@@ -44,7 +44,6 @@ struct snd_es1688 {
        unsigned char pad;
        unsigned int dma_size;
 
-       struct snd_card *card;
        struct snd_pcm *pcm;
        struct snd_pcm_substream *playback_substream;
        struct snd_pcm_substream *capture_substream;
@@ -108,14 +107,16 @@ struct snd_es1688 {
 void snd_es1688_mixer_write(struct snd_es1688 *chip, unsigned char reg, unsigned char data);
 
 int snd_es1688_create(struct snd_card *card,
+                     struct snd_es1688 *chip,
                      unsigned long port,
                      unsigned long mpu_port,
                      int irq,
                      int mpu_irq,
                      int dma8,
-                     unsigned short hardware,
-                     struct snd_es1688 ** rchip);
-int snd_es1688_pcm(struct snd_es1688 *chip, int device, struct snd_pcm ** rpcm);
-int snd_es1688_mixer(struct snd_es1688 *chip);
+                     unsigned short hardware);
+int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip, int device,
+                  struct snd_pcm **rpcm);
+int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip);
+int snd_es1688_reset(struct snd_es1688 *chip);
 
 #endif /* __SOUND_ES1688_H */
index 112e894..4e94cf1 100644 (file)
@@ -51,18 +51,18 @@ struct snd_info_entry_ops {
                    unsigned short mode, void **file_private_data);
        int (*release)(struct snd_info_entry *entry,
                       unsigned short mode, void *file_private_data);
-       long (*read)(struct snd_info_entry *entry, void *file_private_data,
-                    struct file *file, char __user *buf,
-                    unsigned long count, unsigned long pos);
-       long (*write)(struct snd_info_entry *entry, void *file_private_data,
-                     struct file *file, const char __user *buf,
-                     unsigned long count, unsigned long pos);
-       long long (*llseek)(struct snd_info_entry *entry,
-                           void *file_private_data, struct file *file,
-                           long long offset, int orig);
-       unsigned int(*poll)(struct snd_info_entry *entry,
-                           void *file_private_data, struct file *file,
-                           poll_table *wait);
+       ssize_t (*read)(struct snd_info_entry *entry, void *file_private_data,
+                       struct file *file, char __user *buf,
+                       size_t count, loff_t pos);
+       ssize_t (*write)(struct snd_info_entry *entry, void *file_private_data,
+                        struct file *file, const char __user *buf,
+                        size_t count, loff_t pos);
+       loff_t (*llseek)(struct snd_info_entry *entry,
+                        void *file_private_data, struct file *file,
+                        loff_t offset, int orig);
+       unsigned int (*poll)(struct snd_info_entry *entry,
+                            void *file_private_data, struct file *file,
+                            poll_table *wait);
        int (*ioctl)(struct snd_info_entry *entry, void *file_private_data,
                     struct file *file, unsigned int cmd, unsigned long arg);
        int (*mmap)(struct snd_info_entry *entry, void *file_private_data,
index f236e42..d90b9fa 100644 (file)
@@ -42,6 +42,11 @@ enum snd_jack_types {
        SND_JACK_MECHANICAL     = 0x0008, /* If detected separately */
        SND_JACK_VIDEOOUT       = 0x0010,
        SND_JACK_AVOUT          = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
+
+       /* Kept separate from switches to facilitate implementation */
+       SND_JACK_BTN_0          = 0x4000,
+       SND_JACK_BTN_1          = 0x2000,
+       SND_JACK_BTN_2          = 0x1000,
 };
 
 struct snd_jack {
@@ -50,6 +55,7 @@ struct snd_jack {
        int type;
        const char *id;
        char name[100];
+       unsigned int key[3];   /* Keep in sync with definitions above */
        void *private_data;
        void (*private_free)(struct snd_jack *);
 };
@@ -59,6 +65,8 @@ struct snd_jack {
 int snd_jack_new(struct snd_card *card, const char *id, int type,
                 struct snd_jack **jack);
 void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
+int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
+                    int keytype);
 
 void snd_jack_report(struct snd_jack *jack, int status);
 
index 8b611a5..dd76cde 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/poll.h>
 #include <linux/mm.h>
 #include <linux/bitops.h>
+#include <linux/pm_qos_params.h>
 
 #define snd_pcm_substream_chip(substream) ((substream)->private_data)
 #define snd_pcm_chip(pcm) ((pcm)->private_data)
@@ -365,7 +366,7 @@ struct snd_pcm_substream {
        int number;
        char name[32];                  /* substream name */
        int stream;                     /* stream (direction) */
-       char latency_id[20];            /* latency identifier */
+       struct pm_qos_request_list *latency_pm_qos_req; /* pm_qos request */
        size_t buffer_bytes_max;        /* limit ring buffer size */
        struct snd_dma_buffer dma_buffer;
        unsigned int dma_buf_id;
index 0a0b019..377693a 100644 (file)
@@ -182,6 +182,12 @@ struct snd_soc_dai_ops {
                struct snd_soc_dai *);
        int (*trigger)(struct snd_pcm_substream *, int,
                struct snd_soc_dai *);
+       /*
+        * For hardware based FIFO caused delay reporting.
+        * Optional.
+        */
+       snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
+               struct snd_soc_dai *);
 };
 
 /*
@@ -215,7 +221,6 @@ struct snd_soc_dai {
        unsigned int symmetric_rates:1;
 
        /* DAI runtime info */
-       struct snd_pcm_runtime *runtime;
        struct snd_soc_codec *codec;
        unsigned int active;
        unsigned char pop_wait:1;
index c0922a0..66ff4c1 100644 (file)
@@ -339,6 +339,9 @@ int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_sync(struct snd_soc_codec *codec);
+int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec,
+                                 const char *pin);
+int snd_soc_dapm_ignore_suspend(struct snd_soc_codec *codec, const char *pin);
 
 /* dapm widget types */
 enum snd_soc_dapm_type {
@@ -425,9 +428,8 @@ struct snd_soc_dapm_widget {
        unsigned char connected:1;              /* connected codec pin */
        unsigned char new:1;                    /* cnew complete */
        unsigned char ext:1;                    /* has external widgets */
-       unsigned char muted:1;                  /* muted for pop reduction */
-       unsigned char suspend:1;                /* was active before suspend */
-       unsigned char pmdown:1;                 /* waiting for timeout */
+       unsigned char force:1;                  /* force state */
+       unsigned char ignore_suspend:1;         /* kept enabled over suspend */
 
        int (*power_check)(struct snd_soc_dapm_widget *w);
 
index a57fbfc..697e7ff 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <linux/platform_device.h>
 #include <linux/types.h>
+#include <linux/notifier.h>
 #include <linux/workqueue.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
        ((unsigned long)&(struct soc_mixer_control) \
        {.reg = xreg, .shift = xshift, .rshift = xshift, .max = xmax, \
-       .invert = xinvert})
+       .platform_max = xmax, .invert = xinvert})
 #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
        ((unsigned long)&(struct soc_mixer_control) \
-       {.reg = xreg, .max = xmax, .invert = xinvert})
+       {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
 #define SOC_SINGLE(xname, reg, shift, max, invert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
        .put = snd_soc_put_volsw, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-                .max = xmax, .invert = xinvert} }
+                .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
        .info = snd_soc_info_volsw_2r, \
        .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .invert = xinvert} }
+               .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_DOUBLE_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
@@ -69,7 +70,7 @@
        .put = snd_soc_put_volsw, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = xreg, .shift = shift_left, .rshift = shift_right,\
-                .max = xmax, .invert = xinvert} }
+                .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
@@ -79,7 +80,7 @@
        .get = snd_soc_get_volsw_2r, .put = snd_soc_put_volsw_2r, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .invert = xinvert} }
+               .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
 {      .iface  = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
        .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
@@ -88,7 +89,8 @@
        .info   = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
        .put    = snd_soc_put_volsw_s8, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
-               {.reg = xreg, .min = xmin, .max = xmax} }
+               {.reg = xreg, .min = xmin, .max = xmax, \
+                .platform_max = xmax} }
 #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
 {      .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
        .max = xmax, .texts = xtexts }
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-                .max = xmax, .invert = xinvert} }
+                .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
         xhandler_get, xhandler_put, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = xreg, .shift = shift_left, .rshift = shift_right, \
-               .max = xmax, .invert = xinvert} }
+               .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
         xhandler_get, xhandler_put, tlv_array) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
        .get = xhandler_get, .put = xhandler_put, \
        .private_value = (unsigned long)&(struct soc_mixer_control) \
                {.reg = reg_left, .rreg = reg_right, .shift = xshift, \
-               .max = xmax, .invert = xinvert} }
+               .max = xmax, .platform_max = xmax, .invert = xinvert} }
 #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
 {      .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
        .info = snd_soc_info_bool_ext, \
@@ -212,6 +214,7 @@ struct snd_soc_dai_mode;
 struct snd_soc_pcm_runtime;
 struct snd_soc_dai;
 struct snd_soc_platform;
+struct snd_soc_dai_link;
 struct snd_soc_codec;
 struct soc_enum;
 struct snd_soc_ac97_ops;
@@ -260,6 +263,10 @@ int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
 void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
 int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
                          struct snd_soc_jack_pin *pins);
+void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
+                                   struct notifier_block *nb);
+void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
+                                     struct notifier_block *nb);
 #ifdef CONFIG_GPIOLIB
 int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
                        struct snd_soc_jack_gpio *gpios);
@@ -320,6 +327,8 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol);
+int snd_soc_limit_volume(struct snd_soc_codec *codec,
+       const char *name, int max);
 
 /**
  * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
@@ -363,6 +372,7 @@ struct snd_soc_jack {
        struct snd_soc_card *card;
        struct list_head pins;
        int status;
+       struct blocking_notifier_head notifier;
 };
 
 /* SoC PCM stream information */
@@ -374,7 +384,7 @@ struct snd_soc_pcm_stream {
        unsigned int rate_max;          /* max rate */
        unsigned int channels_min;      /* min channels */
        unsigned int channels_max;      /* max channels */
-       unsigned int active:1;          /* stream is in use */
+       unsigned int active;            /* stream is in use */
        void *dma_data;                 /* used by platform code */
 };
 
@@ -407,7 +417,7 @@ struct snd_soc_codec {
        struct snd_ac97 *ac97;  /* for ad-hoc ac97 devices */
        unsigned int active;
        unsigned int pcm_devs;
-       void *private_data;
+       void *drvdata;
 
        /* codec IO */
        void *control_data; /* codec control (i2c/3wire) data */
@@ -462,14 +472,21 @@ struct snd_soc_platform {
 
        int (*probe)(struct platform_device *pdev);
        int (*remove)(struct platform_device *pdev);
-       int (*suspend)(struct snd_soc_dai *dai);
-       int (*resume)(struct snd_soc_dai *dai);
+       int (*suspend)(struct snd_soc_dai_link *dai_link);
+       int (*resume)(struct snd_soc_dai_link *dai_link);
 
        /* pcm creation and destruction */
        int (*pcm_new)(struct snd_card *, struct snd_soc_dai *,
                struct snd_pcm *);
        void (*pcm_free)(struct snd_pcm *);
 
+       /*
+        * For platform caused delay reporting.
+        * Optional.
+        */
+       snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
+               struct snd_soc_dai *);
+
        /* platform stream ops */
        struct snd_pcm_ops *pcm_ops;
 };
@@ -489,6 +506,9 @@ struct snd_soc_dai_link  {
        /* codec/machine specific init - e.g. add machine controls */
        int (*init)(struct snd_soc_codec *codec);
 
+       /* Keep DAI active over suspend */
+       unsigned int ignore_suspend:1;
+
        /* Symmetry requirements */
        unsigned int symmetric_rates:1;
 
@@ -553,7 +573,7 @@ struct snd_soc_pcm_runtime {
 
 /* mixer control */
 struct soc_mixer_control {
-       int min, max;
+       int min, max, platform_max;
        unsigned int reg, rreg, shift, rshift, invert;
 };
 
@@ -583,6 +603,17 @@ static inline unsigned int snd_soc_write(struct snd_soc_codec *codec,
        return codec->write(codec, reg, val);
 }
 
+static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
+                                            void *data)
+{
+       codec->drvdata = data;
+}
+
+static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
+{
+       return codec->drvdata;
+}
+
 #include <sound/soc-dai.h>
 
 #endif
diff --git a/include/sound/tlv320aic3x.h b/include/sound/tlv320aic3x.h
new file mode 100644 (file)
index 0000000..b1a5f34
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Platform data for Texas Instruments TLV320AIC3x codec
+ *
+ * Author: Jarkko Nikula <jhnikula@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef __TLV320AIC3x_H__
+#define __TLV320AIC3x_H__
+
+struct aic3x_pdata {
+       int gpio_reset; /* < 0 if not used */
+};
+
+#endif
\ No newline at end of file
index ac06652..3f428d5 100644 (file)
@@ -15,6 +15,7 @@
 
 struct tlv320dac33_platform_data {
        int power_gpio;
+       int keep_bclk;  /* Keep the BCLK running in FIFO modes */
        u8 burst_bclkdiv;
 };
 
index 475ef8b..509efb0 100644 (file)
@@ -21,6 +21,7 @@ struct uda134x_platform_data {
 #define UDA134X_UDA1340 1
 #define UDA134X_UDA1341 2
 #define UDA134X_UDA1344 3
+#define UDA134X_UDA1345 4
 };
 
 #endif /* _UDA134X_H */
index 7fed234..bf69a5b 100644 (file)
@@ -1,3 +1,3 @@
 /* include/version.h */
-#define CONFIG_SND_VERSION "1.0.22.1"
+#define CONFIG_SND_VERSION "1.0.23"
 #define CONFIG_SND_DATE ""
diff --git a/include/sound/wm8903.h b/include/sound/wm8903.h
new file mode 100644 (file)
index 0000000..b4a0db2
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * linux/sound/wm8903.h -- Platform data for WM8903
+ *
+ * Copyright 2010 Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_SND_WM8903_H
+#define __LINUX_SND_WM8903_H
+
+/* Used to enable configuration of a GPIO to all zeros */
+#define WM8903_GPIO_NO_CONFIG 0x8000
+
+/*
+ * R6 (0x06) - Mic Bias Control 0
+ */
+#define WM8903_MICDET_HYST_ENA                  0x0080  /* MICDET_HYST_ENA */
+#define WM8903_MICDET_HYST_ENA_MASK             0x0080  /* MICDET_HYST_ENA */
+#define WM8903_MICDET_HYST_ENA_SHIFT                 7  /* MICDET_HYST_ENA */
+#define WM8903_MICDET_HYST_ENA_WIDTH                 1  /* MICDET_HYST_ENA */
+#define WM8903_MICDET_THR_MASK                  0x0070  /* MICDET_THR - [6:4] */
+#define WM8903_MICDET_THR_SHIFT                      4  /* MICDET_THR - [6:4] */
+#define WM8903_MICDET_THR_WIDTH                      3  /* MICDET_THR - [6:4] */
+#define WM8903_MICSHORT_THR_MASK                0x000C  /* MICSHORT_THR - [3:2] */
+#define WM8903_MICSHORT_THR_SHIFT                    2  /* MICSHORT_THR - [3:2] */
+#define WM8903_MICSHORT_THR_WIDTH                    2  /* MICSHORT_THR - [3:2] */
+#define WM8903_MICDET_ENA                       0x0002  /* MICDET_ENA */
+#define WM8903_MICDET_ENA_MASK                  0x0002  /* MICDET_ENA */
+#define WM8903_MICDET_ENA_SHIFT                      1  /* MICDET_ENA */
+#define WM8903_MICDET_ENA_WIDTH                      1  /* MICDET_ENA */
+#define WM8903_MICBIAS_ENA                      0x0001  /* MICBIAS_ENA */
+#define WM8903_MICBIAS_ENA_MASK                 0x0001  /* MICBIAS_ENA */
+#define WM8903_MICBIAS_ENA_SHIFT                     0  /* MICBIAS_ENA */
+#define WM8903_MICBIAS_ENA_WIDTH                     1  /* MICBIAS_ENA */
+
+/*
+ * R116 (0x74) - GPIO Control 1
+ */
+#define WM8903_GP1_FN_MASK                      0x1F00  /* GP1_FN - [12:8] */
+#define WM8903_GP1_FN_SHIFT                          8  /* GP1_FN - [12:8] */
+#define WM8903_GP1_FN_WIDTH                          5  /* GP1_FN - [12:8] */
+#define WM8903_GP1_DIR                          0x0080  /* GP1_DIR */
+#define WM8903_GP1_DIR_MASK                     0x0080  /* GP1_DIR */
+#define WM8903_GP1_DIR_SHIFT                         7  /* GP1_DIR */
+#define WM8903_GP1_DIR_WIDTH                         1  /* GP1_DIR */
+#define WM8903_GP1_OP_CFG                       0x0040  /* GP1_OP_CFG */
+#define WM8903_GP1_OP_CFG_MASK                  0x0040  /* GP1_OP_CFG */
+#define WM8903_GP1_OP_CFG_SHIFT                      6  /* GP1_OP_CFG */
+#define WM8903_GP1_OP_CFG_WIDTH                      1  /* GP1_OP_CFG */
+#define WM8903_GP1_IP_CFG                       0x0020  /* GP1_IP_CFG */
+#define WM8903_GP1_IP_CFG_MASK                  0x0020  /* GP1_IP_CFG */
+#define WM8903_GP1_IP_CFG_SHIFT                      5  /* GP1_IP_CFG */
+#define WM8903_GP1_IP_CFG_WIDTH                      1  /* GP1_IP_CFG */
+#define WM8903_GP1_LVL                          0x0010  /* GP1_LVL */
+#define WM8903_GP1_LVL_MASK                     0x0010  /* GP1_LVL */
+#define WM8903_GP1_LVL_SHIFT                         4  /* GP1_LVL */
+#define WM8903_GP1_LVL_WIDTH                         1  /* GP1_LVL */
+#define WM8903_GP1_PD                           0x0008  /* GP1_PD */
+#define WM8903_GP1_PD_MASK                      0x0008  /* GP1_PD */
+#define WM8903_GP1_PD_SHIFT                          3  /* GP1_PD */
+#define WM8903_GP1_PD_WIDTH                          1  /* GP1_PD */
+#define WM8903_GP1_PU                           0x0004  /* GP1_PU */
+#define WM8903_GP1_PU_MASK                      0x0004  /* GP1_PU */
+#define WM8903_GP1_PU_SHIFT                          2  /* GP1_PU */
+#define WM8903_GP1_PU_WIDTH                          1  /* GP1_PU */
+#define WM8903_GP1_INTMODE                      0x0002  /* GP1_INTMODE */
+#define WM8903_GP1_INTMODE_MASK                 0x0002  /* GP1_INTMODE */
+#define WM8903_GP1_INTMODE_SHIFT                     1  /* GP1_INTMODE */
+#define WM8903_GP1_INTMODE_WIDTH                     1  /* GP1_INTMODE */
+#define WM8903_GP1_DB                           0x0001  /* GP1_DB */
+#define WM8903_GP1_DB_MASK                      0x0001  /* GP1_DB */
+#define WM8903_GP1_DB_SHIFT                          0  /* GP1_DB */
+#define WM8903_GP1_DB_WIDTH                          1  /* GP1_DB */
+
+/*
+ * R117 (0x75) - GPIO Control 2
+ */
+#define WM8903_GP2_FN_MASK                      0x1F00  /* GP2_FN - [12:8] */
+#define WM8903_GP2_FN_SHIFT                          8  /* GP2_FN - [12:8] */
+#define WM8903_GP2_FN_WIDTH                          5  /* GP2_FN - [12:8] */
+#define WM8903_GP2_DIR                          0x0080  /* GP2_DIR */
+#define WM8903_GP2_DIR_MASK                     0x0080  /* GP2_DIR */
+#define WM8903_GP2_DIR_SHIFT                         7  /* GP2_DIR */
+#define WM8903_GP2_DIR_WIDTH                         1  /* GP2_DIR */
+#define WM8903_GP2_OP_CFG                       0x0040  /* GP2_OP_CFG */
+#define WM8903_GP2_OP_CFG_MASK                  0x0040  /* GP2_OP_CFG */
+#define WM8903_GP2_OP_CFG_SHIFT                      6  /* GP2_OP_CFG */
+#define WM8903_GP2_OP_CFG_WIDTH                      1  /* GP2_OP_CFG */
+#define WM8903_GP2_IP_CFG                       0x0020  /* GP2_IP_CFG */
+#define WM8903_GP2_IP_CFG_MASK                  0x0020  /* GP2_IP_CFG */
+#define WM8903_GP2_IP_CFG_SHIFT                      5  /* GP2_IP_CFG */
+#define WM8903_GP2_IP_CFG_WIDTH                      1  /* GP2_IP_CFG */
+#define WM8903_GP2_LVL                          0x0010  /* GP2_LVL */
+#define WM8903_GP2_LVL_MASK                     0x0010  /* GP2_LVL */
+#define WM8903_GP2_LVL_SHIFT                         4  /* GP2_LVL */
+#define WM8903_GP2_LVL_WIDTH                         1  /* GP2_LVL */
+#define WM8903_GP2_PD                           0x0008  /* GP2_PD */
+#define WM8903_GP2_PD_MASK                      0x0008  /* GP2_PD */
+#define WM8903_GP2_PD_SHIFT                          3  /* GP2_PD */
+#define WM8903_GP2_PD_WIDTH                          1  /* GP2_PD */
+#define WM8903_GP2_PU                           0x0004  /* GP2_PU */
+#define WM8903_GP2_PU_MASK                      0x0004  /* GP2_PU */
+#define WM8903_GP2_PU_SHIFT                          2  /* GP2_PU */
+#define WM8903_GP2_PU_WIDTH                          1  /* GP2_PU */
+#define WM8903_GP2_INTMODE                      0x0002  /* GP2_INTMODE */
+#define WM8903_GP2_INTMODE_MASK                 0x0002  /* GP2_INTMODE */
+#define WM8903_GP2_INTMODE_SHIFT                     1  /* GP2_INTMODE */
+#define WM8903_GP2_INTMODE_WIDTH                     1  /* GP2_INTMODE */
+#define WM8903_GP2_DB                           0x0001  /* GP2_DB */
+#define WM8903_GP2_DB_MASK                      0x0001  /* GP2_DB */
+#define WM8903_GP2_DB_SHIFT                          0  /* GP2_DB */
+#define WM8903_GP2_DB_WIDTH                          1  /* GP2_DB */
+
+/*
+ * R118 (0x76) - GPIO Control 3
+ */
+#define WM8903_GP3_FN_MASK                      0x1F00  /* GP3_FN - [12:8] */
+#define WM8903_GP3_FN_SHIFT                          8  /* GP3_FN - [12:8] */
+#define WM8903_GP3_FN_WIDTH                          5  /* GP3_FN - [12:8] */
+#define WM8903_GP3_DIR                          0x0080  /* GP3_DIR */
+#define WM8903_GP3_DIR_MASK                     0x0080  /* GP3_DIR */
+#define WM8903_GP3_DIR_SHIFT                         7  /* GP3_DIR */
+#define WM8903_GP3_DIR_WIDTH                         1  /* GP3_DIR */
+#define WM8903_GP3_OP_CFG                       0x0040  /* GP3_OP_CFG */
+#define WM8903_GP3_OP_CFG_MASK                  0x0040  /* GP3_OP_CFG */
+#define WM8903_GP3_OP_CFG_SHIFT                      6  /* GP3_OP_CFG */
+#define WM8903_GP3_OP_CFG_WIDTH                      1  /* GP3_OP_CFG */
+#define WM8903_GP3_IP_CFG                       0x0020  /* GP3_IP_CFG */
+#define WM8903_GP3_IP_CFG_MASK                  0x0020  /* GP3_IP_CFG */
+#define WM8903_GP3_IP_CFG_SHIFT                      5  /* GP3_IP_CFG */
+#define WM8903_GP3_IP_CFG_WIDTH                      1  /* GP3_IP_CFG */
+#define WM8903_GP3_LVL                          0x0010  /* GP3_LVL */
+#define WM8903_GP3_LVL_MASK                     0x0010  /* GP3_LVL */
+#define WM8903_GP3_LVL_SHIFT                         4  /* GP3_LVL */
+#define WM8903_GP3_LVL_WIDTH                         1  /* GP3_LVL */
+#define WM8903_GP3_PD                           0x0008  /* GP3_PD */
+#define WM8903_GP3_PD_MASK                      0x0008  /* GP3_PD */
+#define WM8903_GP3_PD_SHIFT                          3  /* GP3_PD */
+#define WM8903_GP3_PD_WIDTH                          1  /* GP3_PD */
+#define WM8903_GP3_PU                           0x0004  /* GP3_PU */
+#define WM8903_GP3_PU_MASK                      0x0004  /* GP3_PU */
+#define WM8903_GP3_PU_SHIFT                          2  /* GP3_PU */
+#define WM8903_GP3_PU_WIDTH                          1  /* GP3_PU */
+#define WM8903_GP3_INTMODE                      0x0002  /* GP3_INTMODE */
+#define WM8903_GP3_INTMODE_MASK                 0x0002  /* GP3_INTMODE */
+#define WM8903_GP3_INTMODE_SHIFT                     1  /* GP3_INTMODE */
+#define WM8903_GP3_INTMODE_WIDTH                     1  /* GP3_INTMODE */
+#define WM8903_GP3_DB                           0x0001  /* GP3_DB */
+#define WM8903_GP3_DB_MASK                      0x0001  /* GP3_DB */
+#define WM8903_GP3_DB_SHIFT                          0  /* GP3_DB */
+#define WM8903_GP3_DB_WIDTH                          1  /* GP3_DB */
+
+/*
+ * R119 (0x77) - GPIO Control 4
+ */
+#define WM8903_GP4_FN_MASK                      0x1F00  /* GP4_FN - [12:8] */
+#define WM8903_GP4_FN_SHIFT                          8  /* GP4_FN - [12:8] */
+#define WM8903_GP4_FN_WIDTH                          5  /* GP4_FN - [12:8] */
+#define WM8903_GP4_DIR                          0x0080  /* GP4_DIR */
+#define WM8903_GP4_DIR_MASK                     0x0080  /* GP4_DIR */
+#define WM8903_GP4_DIR_SHIFT                         7  /* GP4_DIR */
+#define WM8903_GP4_DIR_WIDTH                         1  /* GP4_DIR */
+#define WM8903_GP4_OP_CFG                       0x0040  /* GP4_OP_CFG */
+#define WM8903_GP4_OP_CFG_MASK                  0x0040  /* GP4_OP_CFG */
+#define WM8903_GP4_OP_CFG_SHIFT                      6  /* GP4_OP_CFG */
+#define WM8903_GP4_OP_CFG_WIDTH                      1  /* GP4_OP_CFG */
+#define WM8903_GP4_IP_CFG                       0x0020  /* GP4_IP_CFG */
+#define WM8903_GP4_IP_CFG_MASK                  0x0020  /* GP4_IP_CFG */
+#define WM8903_GP4_IP_CFG_SHIFT                      5  /* GP4_IP_CFG */
+#define WM8903_GP4_IP_CFG_WIDTH                      1  /* GP4_IP_CFG */
+#define WM8903_GP4_LVL                          0x0010  /* GP4_LVL */
+#define WM8903_GP4_LVL_MASK                     0x0010  /* GP4_LVL */
+#define WM8903_GP4_LVL_SHIFT                         4  /* GP4_LVL */
+#define WM8903_GP4_LVL_WIDTH                         1  /* GP4_LVL */
+#define WM8903_GP4_PD                           0x0008  /* GP4_PD */
+#define WM8903_GP4_PD_MASK                      0x0008  /* GP4_PD */
+#define WM8903_GP4_PD_SHIFT                          3  /* GP4_PD */
+#define WM8903_GP4_PD_WIDTH                          1  /* GP4_PD */
+#define WM8903_GP4_PU                           0x0004  /* GP4_PU */
+#define WM8903_GP4_PU_MASK                      0x0004  /* GP4_PU */
+#define WM8903_GP4_PU_SHIFT                          2  /* GP4_PU */
+#define WM8903_GP4_PU_WIDTH                          1  /* GP4_PU */
+#define WM8903_GP4_INTMODE                      0x0002  /* GP4_INTMODE */
+#define WM8903_GP4_INTMODE_MASK                 0x0002  /* GP4_INTMODE */
+#define WM8903_GP4_INTMODE_SHIFT                     1  /* GP4_INTMODE */
+#define WM8903_GP4_INTMODE_WIDTH                     1  /* GP4_INTMODE */
+#define WM8903_GP4_DB                           0x0001  /* GP4_DB */
+#define WM8903_GP4_DB_MASK                      0x0001  /* GP4_DB */
+#define WM8903_GP4_DB_SHIFT                          0  /* GP4_DB */
+#define WM8903_GP4_DB_WIDTH                          1  /* GP4_DB */
+
+/*
+ * R120 (0x78) - GPIO Control 5
+ */
+#define WM8903_GP5_FN_MASK                      0x1F00  /* GP5_FN - [12:8] */
+#define WM8903_GP5_FN_SHIFT                          8  /* GP5_FN - [12:8] */
+#define WM8903_GP5_FN_WIDTH                          5  /* GP5_FN - [12:8] */
+#define WM8903_GP5_DIR                          0x0080  /* GP5_DIR */
+#define WM8903_GP5_DIR_MASK                     0x0080  /* GP5_DIR */
+#define WM8903_GP5_DIR_SHIFT                         7  /* GP5_DIR */
+#define WM8903_GP5_DIR_WIDTH                         1  /* GP5_DIR */
+#define WM8903_GP5_OP_CFG                       0x0040  /* GP5_OP_CFG */
+#define WM8903_GP5_OP_CFG_MASK                  0x0040  /* GP5_OP_CFG */
+#define WM8903_GP5_OP_CFG_SHIFT                      6  /* GP5_OP_CFG */
+#define WM8903_GP5_OP_CFG_WIDTH                      1  /* GP5_OP_CFG */
+#define WM8903_GP5_IP_CFG                       0x0020  /* GP5_IP_CFG */
+#define WM8903_GP5_IP_CFG_MASK                  0x0020  /* GP5_IP_CFG */
+#define WM8903_GP5_IP_CFG_SHIFT                      5  /* GP5_IP_CFG */
+#define WM8903_GP5_IP_CFG_WIDTH                      1  /* GP5_IP_CFG */
+#define WM8903_GP5_LVL                          0x0010  /* GP5_LVL */
+#define WM8903_GP5_LVL_MASK                     0x0010  /* GP5_LVL */
+#define WM8903_GP5_LVL_SHIFT                         4  /* GP5_LVL */
+#define WM8903_GP5_LVL_WIDTH                         1  /* GP5_LVL */
+#define WM8903_GP5_PD                           0x0008  /* GP5_PD */
+#define WM8903_GP5_PD_MASK                      0x0008  /* GP5_PD */
+#define WM8903_GP5_PD_SHIFT                          3  /* GP5_PD */
+#define WM8903_GP5_PD_WIDTH                          1  /* GP5_PD */
+#define WM8903_GP5_PU                           0x0004  /* GP5_PU */
+#define WM8903_GP5_PU_MASK                      0x0004  /* GP5_PU */
+#define WM8903_GP5_PU_SHIFT                          2  /* GP5_PU */
+#define WM8903_GP5_PU_WIDTH                          1  /* GP5_PU */
+#define WM8903_GP5_INTMODE                      0x0002  /* GP5_INTMODE */
+#define WM8903_GP5_INTMODE_MASK                 0x0002  /* GP5_INTMODE */
+#define WM8903_GP5_INTMODE_SHIFT                     1  /* GP5_INTMODE */
+#define WM8903_GP5_INTMODE_WIDTH                     1  /* GP5_INTMODE */
+#define WM8903_GP5_DB                           0x0001  /* GP5_DB */
+#define WM8903_GP5_DB_MASK                      0x0001  /* GP5_DB */
+#define WM8903_GP5_DB_SHIFT                          0  /* GP5_DB */
+#define WM8903_GP5_DB_WIDTH                          1  /* GP5_DB */
+
+struct wm8903_platform_data {
+       bool irq_active_low;   /* Set if IRQ active low, default high */
+
+        /* Default register value for R6 (Mic bias), used to configure
+        * microphone detection.  In conjunction with gpio_cfg this
+        * can be used to route the microphone status signals out onto
+        * the GPIOs for use with snd_soc_jack_add_gpios().
+        */
+       u16 micdet_cfg;
+
+       int micdet_delay;      /* Delay after microphone detection (ms) */
+
+       u32 gpio_cfg[5];       /* Default register values for GPIO pin mux */
+};
+
+#endif
index d66575a..898be3a 100644 (file)
 #ifndef __MFD_WM8994_PDATA_H__
 #define __MFD_WM8994_PDATA_H__
 
-#define WM8904_DRC_REGS 4
-#define WM8904_EQ_REGS  25
+/* Used to enable configuration of a GPIO to all zeros */
+#define WM8904_GPIO_NO_CONFIG 0x8000
+
+/*
+ * R6 (0x06) - Mic Bias Control 0
+ */
+#define WM8904_MICDET_THR_MASK                  0x0070  /* MICDET_THR - [6:4] */
+#define WM8904_MICDET_THR_SHIFT                      4  /* MICDET_THR - [6:4] */
+#define WM8904_MICDET_THR_WIDTH                      3  /* MICDET_THR - [6:4] */
+#define WM8904_MICSHORT_THR_MASK                0x000C  /* MICSHORT_THR - [3:2] */
+#define WM8904_MICSHORT_THR_SHIFT                    2  /* MICSHORT_THR - [3:2] */
+#define WM8904_MICSHORT_THR_WIDTH                    2  /* MICSHORT_THR - [3:2] */
+#define WM8904_MICDET_ENA                       0x0002  /* MICDET_ENA */
+#define WM8904_MICDET_ENA_MASK                  0x0002  /* MICDET_ENA */
+#define WM8904_MICDET_ENA_SHIFT                      1  /* MICDET_ENA */
+#define WM8904_MICDET_ENA_WIDTH                      1  /* MICDET_ENA */
+#define WM8904_MICBIAS_ENA                      0x0001  /* MICBIAS_ENA */
+#define WM8904_MICBIAS_ENA_MASK                 0x0001  /* MICBIAS_ENA */
+#define WM8904_MICBIAS_ENA_SHIFT                     0  /* MICBIAS_ENA */
+#define WM8904_MICBIAS_ENA_WIDTH                     1  /* MICBIAS_ENA */
+
+/*
+ * R7 (0x07) - Mic Bias Control 1
+ */
+#define WM8904_MIC_DET_FILTER_ENA               0x8000  /* MIC_DET_FILTER_ENA */
+#define WM8904_MIC_DET_FILTER_ENA_MASK          0x8000  /* MIC_DET_FILTER_ENA */
+#define WM8904_MIC_DET_FILTER_ENA_SHIFT             15  /* MIC_DET_FILTER_ENA */
+#define WM8904_MIC_DET_FILTER_ENA_WIDTH              1  /* MIC_DET_FILTER_ENA */
+#define WM8904_MIC_SHORT_FILTER_ENA             0x4000  /* MIC_SHORT_FILTER_ENA */
+#define WM8904_MIC_SHORT_FILTER_ENA_MASK        0x4000  /* MIC_SHORT_FILTER_ENA */
+#define WM8904_MIC_SHORT_FILTER_ENA_SHIFT           14  /* MIC_SHORT_FILTER_ENA */
+#define WM8904_MIC_SHORT_FILTER_ENA_WIDTH            1  /* MIC_SHORT_FILTER_ENA */
+#define WM8904_MICBIAS_SEL_MASK                 0x0007  /* MICBIAS_SEL - [2:0] */
+#define WM8904_MICBIAS_SEL_SHIFT                     0  /* MICBIAS_SEL - [2:0] */
+#define WM8904_MICBIAS_SEL_WIDTH                     3  /* MICBIAS_SEL - [2:0] */
+
+
+/*
+ * R121 (0x79) - GPIO Control 1
+ */
+#define WM8904_GPIO1_PU                         0x0020  /* GPIO1_PU */
+#define WM8904_GPIO1_PU_MASK                    0x0020  /* GPIO1_PU */
+#define WM8904_GPIO1_PU_SHIFT                        5  /* GPIO1_PU */
+#define WM8904_GPIO1_PU_WIDTH                        1  /* GPIO1_PU */
+#define WM8904_GPIO1_PD                         0x0010  /* GPIO1_PD */
+#define WM8904_GPIO1_PD_MASK                    0x0010  /* GPIO1_PD */
+#define WM8904_GPIO1_PD_SHIFT                        4  /* GPIO1_PD */
+#define WM8904_GPIO1_PD_WIDTH                        1  /* GPIO1_PD */
+#define WM8904_GPIO1_SEL_MASK                   0x000F  /* GPIO1_SEL - [3:0] */
+#define WM8904_GPIO1_SEL_SHIFT                       0  /* GPIO1_SEL - [3:0] */
+#define WM8904_GPIO1_SEL_WIDTH                       4  /* GPIO1_SEL - [3:0] */
+
+/*
+ * R122 (0x7A) - GPIO Control 2
+ */
+#define WM8904_GPIO2_PU                         0x0020  /* GPIO2_PU */
+#define WM8904_GPIO2_PU_MASK                    0x0020  /* GPIO2_PU */
+#define WM8904_GPIO2_PU_SHIFT                        5  /* GPIO2_PU */
+#define WM8904_GPIO2_PU_WIDTH                        1  /* GPIO2_PU */
+#define WM8904_GPIO2_PD                         0x0010  /* GPIO2_PD */
+#define WM8904_GPIO2_PD_MASK                    0x0010  /* GPIO2_PD */
+#define WM8904_GPIO2_PD_SHIFT                        4  /* GPIO2_PD */
+#define WM8904_GPIO2_PD_WIDTH                        1  /* GPIO2_PD */
+#define WM8904_GPIO2_SEL_MASK                   0x000F  /* GPIO2_SEL - [3:0] */
+#define WM8904_GPIO2_SEL_SHIFT                       0  /* GPIO2_SEL - [3:0] */
+#define WM8904_GPIO2_SEL_WIDTH                       4  /* GPIO2_SEL - [3:0] */
+
+/*
+ * R123 (0x7B) - GPIO Control 3
+ */
+#define WM8904_GPIO3_PU                         0x0020  /* GPIO3_PU */
+#define WM8904_GPIO3_PU_MASK                    0x0020  /* GPIO3_PU */
+#define WM8904_GPIO3_PU_SHIFT                        5  /* GPIO3_PU */
+#define WM8904_GPIO3_PU_WIDTH                        1  /* GPIO3_PU */
+#define WM8904_GPIO3_PD                         0x0010  /* GPIO3_PD */
+#define WM8904_GPIO3_PD_MASK                    0x0010  /* GPIO3_PD */
+#define WM8904_GPIO3_PD_SHIFT                        4  /* GPIO3_PD */
+#define WM8904_GPIO3_PD_WIDTH                        1  /* GPIO3_PD */
+#define WM8904_GPIO3_SEL_MASK                   0x000F  /* GPIO3_SEL - [3:0] */
+#define WM8904_GPIO3_SEL_SHIFT                       0  /* GPIO3_SEL - [3:0] */
+#define WM8904_GPIO3_SEL_WIDTH                       4  /* GPIO3_SEL - [3:0] */
+
+/*
+ * R124 (0x7C) - GPIO Control 4
+ */
+#define WM8904_GPI7_ENA                         0x0200  /* GPI7_ENA */
+#define WM8904_GPI7_ENA_MASK                    0x0200  /* GPI7_ENA */
+#define WM8904_GPI7_ENA_SHIFT                        9  /* GPI7_ENA */
+#define WM8904_GPI7_ENA_WIDTH                        1  /* GPI7_ENA */
+#define WM8904_GPI8_ENA                         0x0100  /* GPI8_ENA */
+#define WM8904_GPI8_ENA_MASK                    0x0100  /* GPI8_ENA */
+#define WM8904_GPI8_ENA_SHIFT                        8  /* GPI8_ENA */
+#define WM8904_GPI8_ENA_WIDTH                        1  /* GPI8_ENA */
+#define WM8904_GPIO_BCLK_MODE_ENA               0x0080  /* GPIO_BCLK_MODE_ENA */
+#define WM8904_GPIO_BCLK_MODE_ENA_MASK          0x0080  /* GPIO_BCLK_MODE_ENA */
+#define WM8904_GPIO_BCLK_MODE_ENA_SHIFT              7  /* GPIO_BCLK_MODE_ENA */
+#define WM8904_GPIO_BCLK_MODE_ENA_WIDTH              1  /* GPIO_BCLK_MODE_ENA */
+#define WM8904_GPIO_BCLK_SEL_MASK               0x000F  /* GPIO_BCLK_SEL - [3:0] */
+#define WM8904_GPIO_BCLK_SEL_SHIFT                   0  /* GPIO_BCLK_SEL - [3:0] */
+#define WM8904_GPIO_BCLK_SEL_WIDTH                   4  /* GPIO_BCLK_SEL - [3:0] */
+
+#define WM8904_MIC_REGS  2
+#define WM8904_GPIO_REGS 4
+#define WM8904_DRC_REGS  4
+#define WM8904_EQ_REGS   25
 
 /**
  * DRC configurations are specified with a label and a set of register
@@ -52,6 +155,9 @@ struct wm8904_pdata {
 
        int num_retune_mobile_cfgs;
        struct wm8904_retune_mobile_cfg *retune_mobile_cfgs;
+
+       u32 gpio_cfg[WM8904_GPIO_REGS];
+       u32 mic_cfg[WM8904_MIC_REGS];
 };
 
 #endif
diff --git a/include/sound/wm8960.h b/include/sound/wm8960.h
new file mode 100644 (file)
index 0000000..74e9a95
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * wm8960.h  --  WM8960 Soc Audio driver platform data
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _WM8960_PDATA_H
+#define _WM8960_PDATA_H
+
+#define WM8960_DRES_400R 0
+#define WM8960_DRES_200R 1
+#define WM8960_DRES_600R 2
+#define WM8960_DRES_150R 3
+#define WM8960_DRES_MAX  3
+
+struct wm8960_data {
+       bool capless;  /* Headphone outputs configured in capless mode */
+
+       int dres;  /* Discharge resistance for headphone outputs */
+};
+
+#endif
diff --git a/include/sound/wm9090.h b/include/sound/wm9090.h
new file mode 100644 (file)
index 0000000..3718928
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * linux/sound/wm9090.h -- Platform data for WM9090
+ *
+ * Copyright 2009, 2010 Wolfson Microelectronics. PLC.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __LINUX_SND_WM9090_H
+#define __LINUX_SND_WM9090_H
+
+struct wm9090_platform_data {
+       /* Line inputs 1 & 2 can optionally be differential */
+       unsigned int lin1_diff:1;
+       unsigned int lin2_diff:1;
+
+       /* AGC configuration.  This is intended to protect the speaker
+        * against overdriving and will therefore depend on the
+        * hardware setup with incorrect runtime configuration
+        * potentially causing hardware damage.
+        */
+       unsigned int agc_ena:1;
+       u16 agc[3];
+};
+
+#endif
index 5acfb1e..1dfab54 100644 (file)
 
 #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
 
+/* Make all open coded DECLARE_TRACE nops */
+#undef DECLARE_TRACE
+#define DECLARE_TRACE(name, proto, args)
+
 #ifdef CONFIG_EVENT_TRACING
 #include <trace/ftrace.h>
 #endif
@@ -75,6 +79,7 @@
 #undef DEFINE_EVENT
 #undef DEFINE_EVENT_PRINT
 #undef TRACE_HEADER_MULTI_READ
+#undef DECLARE_TRACE
 
 /* Only undef what we defined in this file */
 #ifdef UNDEF_TRACE_INCLUDE_FILE
index 5c1dcfc..2821b86 100644 (file)
@@ -35,15 +35,15 @@ TRACE_EVENT(lock_acquire,
                  __get_str(name))
 );
 
-TRACE_EVENT(lock_release,
+DECLARE_EVENT_CLASS(lock,
 
-       TP_PROTO(struct lockdep_map *lock, int nested, unsigned long ip),
+       TP_PROTO(struct lockdep_map *lock, unsigned long ip),
 
-       TP_ARGS(lock, nested, ip),
+       TP_ARGS(lock, ip),
 
        TP_STRUCT__entry(
-               __string(name, lock->name)
-               __field(void *, lockdep_addr)
+               __string(       name,   lock->name      )
+               __field(        void *, lockdep_addr    )
        ),
 
        TP_fast_assign(
@@ -51,51 +51,30 @@ TRACE_EVENT(lock_release,
                __entry->lockdep_addr = lock;
        ),
 
-       TP_printk("%p %s",
-                 __entry->lockdep_addr, __get_str(name))
+       TP_printk("%p %s",  __entry->lockdep_addr, __get_str(name))
 );
 
-#ifdef CONFIG_LOCK_STAT
-
-TRACE_EVENT(lock_contended,
+DEFINE_EVENT(lock, lock_release,
 
        TP_PROTO(struct lockdep_map *lock, unsigned long ip),
 
-       TP_ARGS(lock, ip),
+       TP_ARGS(lock, ip)
+);
 
-       TP_STRUCT__entry(
-               __string(name, lock->name)
-               __field(void *, lockdep_addr)
-       ),
+#ifdef CONFIG_LOCK_STAT
 
-       TP_fast_assign(
-               __assign_str(name, lock->name);
-               __entry->lockdep_addr = lock;
-       ),
+DEFINE_EVENT(lock, lock_contended,
 
-       TP_printk("%p %s",
-                 __entry->lockdep_addr, __get_str(name))
-);
+       TP_PROTO(struct lockdep_map *lock, unsigned long ip),
 
-TRACE_EVENT(lock_acquired,
-       TP_PROTO(struct lockdep_map *lock, unsigned long ip, s64 waittime),
+       TP_ARGS(lock, ip)
+);
 
-       TP_ARGS(lock, ip, waittime),
+DEFINE_EVENT(lock, lock_acquired,
 
-       TP_STRUCT__entry(
-               __string(name, lock->name)
-               __field(s64, wait_nsec)
-               __field(void *, lockdep_addr)
-       ),
+       TP_PROTO(struct lockdep_map *lock, unsigned long ip),
 
-       TP_fast_assign(
-               __assign_str(name, lock->name);
-               __entry->wait_nsec = waittime;
-               __entry->lockdep_addr = lock;
-       ),
-       TP_printk("%p %s (%llu ns)", __entry->lockdep_addr,
-                 __get_str(name),
-                 __entry->wait_nsec)
+       TP_ARGS(lock, ip)
 );
 
 #endif
index 4b0f48b..c7bb2f0 100644 (file)
@@ -51,11 +51,14 @@ TRACE_EVENT(module_free,
        TP_printk("%s", __get_str(name))
 );
 
+#ifdef CONFIG_MODULE_UNLOAD
+/* trace_module_get/put are only used if CONFIG_MODULE_UNLOAD is defined */
+
 DECLARE_EVENT_CLASS(module_refcnt,
 
-       TP_PROTO(struct module *mod, unsigned long ip, int refcnt),
+       TP_PROTO(struct module *mod, unsigned long ip),
 
-       TP_ARGS(mod, ip, refcnt),
+       TP_ARGS(mod, ip),
 
        TP_STRUCT__entry(
                __field(        unsigned long,  ip              )
@@ -65,7 +68,7 @@ DECLARE_EVENT_CLASS(module_refcnt,
 
        TP_fast_assign(
                __entry->ip     = ip;
-               __entry->refcnt = refcnt;
+               __entry->refcnt = __this_cpu_read(mod->refptr->incs) + __this_cpu_read(mod->refptr->decs);
                __assign_str(name, mod->name);
        ),
 
@@ -75,17 +78,18 @@ DECLARE_EVENT_CLASS(module_refcnt,
 
 DEFINE_EVENT(module_refcnt, module_get,
 
-       TP_PROTO(struct module *mod, unsigned long ip, int refcnt),
+       TP_PROTO(struct module *mod, unsigned long ip),
 
-       TP_ARGS(mod, ip, refcnt)
+       TP_ARGS(mod, ip)
 );
 
 DEFINE_EVENT(module_refcnt, module_put,
 
-       TP_PROTO(struct module *mod, unsigned long ip, int refcnt),
+       TP_PROTO(struct module *mod, unsigned long ip),
 
-       TP_ARGS(mod, ip, refcnt)
+       TP_ARGS(mod, ip)
 );
+#endif /* CONFIG_MODULE_UNLOAD */
 
 TRACE_EVENT(module_request,
 
index a8989c4..188deca 100644 (file)
@@ -1,4 +1,7 @@
-#ifndef _TRACE_NAPI_H_
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM napi
+
+#if !defined(_TRACE_NAPI_H) || defined(TRACE_HEADER_MULTI_READ)
 #define _TRACE_NAPI_H_
 
 #include <linux/netdevice.h>
@@ -8,4 +11,7 @@ DECLARE_TRACE(napi_poll,
        TP_PROTO(struct napi_struct *napi),
        TP_ARGS(napi));
 
-#endif
+#endif /* _TRACE_NAPI_H_ */
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>
index cfceb0b..4f733ec 100644 (file)
@@ -51,15 +51,12 @@ TRACE_EVENT(sched_kthread_stop_ret,
 
 /*
  * Tracepoint for waiting on task to unschedule:
- *
- * (NOTE: the 'rq' argument is not used by generic trace events,
- *        but used by the latency tracer plugin. )
  */
 TRACE_EVENT(sched_wait_task,
 
-       TP_PROTO(struct rq *rq, struct task_struct *p),
+       TP_PROTO(struct task_struct *p),
 
-       TP_ARGS(rq, p),
+       TP_ARGS(p),
 
        TP_STRUCT__entry(
                __array(        char,   comm,   TASK_COMM_LEN   )
@@ -79,15 +76,12 @@ TRACE_EVENT(sched_wait_task,
 
 /*
  * Tracepoint for waking up a task:
- *
- * (NOTE: the 'rq' argument is not used by generic trace events,
- *        but used by the latency tracer plugin. )
  */
 DECLARE_EVENT_CLASS(sched_wakeup_template,
 
-       TP_PROTO(struct rq *rq, struct task_struct *p, int success),
+       TP_PROTO(struct task_struct *p, int success),
 
-       TP_ARGS(rq, p, success),
+       TP_ARGS(p, success),
 
        TP_STRUCT__entry(
                __array(        char,   comm,   TASK_COMM_LEN   )
@@ -111,31 +105,25 @@ DECLARE_EVENT_CLASS(sched_wakeup_template,
 );
 
 DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
-            TP_PROTO(struct rq *rq, struct task_struct *p, int success),
-            TP_ARGS(rq, p, success));
+            TP_PROTO(struct task_struct *p, int success),
+            TP_ARGS(p, success));
 
 /*
  * Tracepoint for waking up a new task:
- *
- * (NOTE: the 'rq' argument is not used by generic trace events,
- *        but used by the latency tracer plugin. )
  */
 DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
-            TP_PROTO(struct rq *rq, struct task_struct *p, int success),
-            TP_ARGS(rq, p, success));
+            TP_PROTO(struct task_struct *p, int success),
+            TP_ARGS(p, success));
 
 /*
  * Tracepoint for task switches, performed by the scheduler:
- *
- * (NOTE: the 'rq' argument is not used by generic trace events,
- *        but used by the latency tracer plugin. )
  */
 TRACE_EVENT(sched_switch,
 
-       TP_PROTO(struct rq *rq, struct task_struct *prev,
+       TP_PROTO(struct task_struct *prev,
                 struct task_struct *next),
 
-       TP_ARGS(rq, prev, next),
+       TP_ARGS(prev, next),
 
        TP_STRUCT__entry(
                __array(        char,   prev_comm,      TASK_COMM_LEN   )
index a510b75..814566c 100644 (file)
@@ -100,18 +100,7 @@ TRACE_EVENT(signal_deliver,
                  __entry->sa_handler, __entry->sa_flags)
 );
 
-/**
- * signal_overflow_fail - called when signal queue is overflow
- * @sig: signal number
- * @group: signal to process group or not (bool)
- * @info: pointer to struct siginfo
- *
- * Kernel fails to generate 'sig' signal with 'info' siginfo, because
- * siginfo queue is overflow, and the signal is dropped.
- * 'group' is not 0 if the signal will be sent to a process group.
- * 'sig' is always one of RT signals.
- */
-TRACE_EVENT(signal_overflow_fail,
+DECLARE_EVENT_CLASS(signal_queue_overflow,
 
        TP_PROTO(int sig, int group, struct siginfo *info),
 
@@ -134,6 +123,24 @@ TRACE_EVENT(signal_overflow_fail,
                  __entry->sig, __entry->group, __entry->errno, __entry->code)
 );
 
+/**
+ * signal_overflow_fail - called when signal queue is overflow
+ * @sig: signal number
+ * @group: signal to process group or not (bool)
+ * @info: pointer to struct siginfo
+ *
+ * Kernel fails to generate 'sig' signal with 'info' siginfo, because
+ * siginfo queue is overflow, and the signal is dropped.
+ * 'group' is not 0 if the signal will be sent to a process group.
+ * 'sig' is always one of RT signals.
+ */
+DEFINE_EVENT(signal_queue_overflow, signal_overflow_fail,
+
+       TP_PROTO(int sig, int group, struct siginfo *info),
+
+       TP_ARGS(sig, group, info)
+);
+
 /**
  * signal_lose_info - called when siginfo is lost
  * @sig: signal number
@@ -145,28 +152,13 @@ TRACE_EVENT(signal_overflow_fail,
  * 'group' is not 0 if the signal will be sent to a process group.
  * 'sig' is always one of non-RT signals.
  */
-TRACE_EVENT(signal_lose_info,
+DEFINE_EVENT(signal_queue_overflow, signal_lose_info,
 
        TP_PROTO(int sig, int group, struct siginfo *info),
 
-       TP_ARGS(sig, group, info),
-
-       TP_STRUCT__entry(
-               __field(        int,    sig     )
-               __field(        int,    group   )
-               __field(        int,    errno   )
-               __field(        int,    code    )
-       ),
-
-       TP_fast_assign(
-               __entry->sig    = sig;
-               __entry->group  = group;
-               TP_STORE_SIGINFO(__entry, info);
-       ),
-
-       TP_printk("sig=%d group=%d errno=%d code=%d",
-                 __entry->sig, __entry->group, __entry->errno, __entry->code)
+       TP_ARGS(sig, group, info)
 );
+
 #endif /* _TRACE_SIGNAL_H */
 
 /* This part must be outside protection */
index ea6f9d4..16253db 100644 (file)
  *
  *     field = (typeof(field))entry;
  *
- *     p = get_cpu_var(ftrace_event_seq);
+ *     p = &get_cpu_var(ftrace_event_seq);
  *     trace_seq_init(p);
- *     ret = trace_seq_printf(s, <TP_printk> "\n");
+ *     ret = trace_seq_printf(s, "%s: ", <call>);
+ *     if (ret)
+ *             ret = trace_seq_printf(s, <TP_printk> "\n");
  *     put_cpu();
  *     if (!ret)
  *             return TRACE_TYPE_PARTIAL_LINE;
@@ -450,38 +452,38 @@ perf_trace_disable_##name(struct ftrace_event_call *unused)               \
  *
  * static void ftrace_raw_event_<call>(proto)
  * {
+ *     struct ftrace_data_offsets_<call> __maybe_unused __data_offsets;
  *     struct ring_buffer_event *event;
  *     struct ftrace_raw_<call> *entry; <-- defined in stage 1
  *     struct ring_buffer *buffer;
  *     unsigned long irq_flags;
+ *     int __data_size;
  *     int pc;
  *
  *     local_save_flags(irq_flags);
  *     pc = preempt_count();
  *
+ *     __data_size = ftrace_get_offsets_<call>(&__data_offsets, args);
+ *
  *     event = trace_current_buffer_lock_reserve(&buffer,
  *                               event_<call>.id,
- *                               sizeof(struct ftrace_raw_<call>),
+ *                               sizeof(*entry) + __data_size,
  *                               irq_flags, pc);
  *     if (!event)
  *             return;
  *     entry   = ring_buffer_event_data(event);
  *
- *     <assign>;  <-- Here we assign the entries by the __field and
- *                     __array macros.
+ *     { <assign>; }  <-- Here we assign the entries by the __field and
+ *                        __array macros.
  *
- *     trace_current_buffer_unlock_commit(buffer, event, irq_flags, pc);
+ *     if (!filter_current_check_discard(buffer, event_call, entry, event))
+ *             trace_current_buffer_unlock_commit(buffer,
+ *                                                event, irq_flags, pc);
  * }
  *
  * static int ftrace_raw_reg_event_<call>(struct ftrace_event_call *unused)
  * {
- *     int ret;
- *
- *     ret = register_trace_<call>(ftrace_raw_event_<call>);
- *     if (!ret)
- *             pr_info("event trace: Could not activate trace point "
- *                     "probe to <call>");
- *     return ret;
+ *     return register_trace_<call>(ftrace_raw_event_<call>);
  * }
  *
  * static void ftrace_unreg_event_<call>(struct ftrace_event_call *unused)
@@ -493,6 +495,8 @@ perf_trace_disable_##name(struct ftrace_event_call *unused)         \
  *     .trace                  = ftrace_raw_output_<call>, <-- stage 2
  * };
  *
+ * static const char print_fmt_<call>[] = <TP_printk>;
+ *
  * static struct ftrace_event_call __used
  * __attribute__((__aligned__(4)))
  * __attribute__((section("_ftrace_events"))) event_<call> = {
@@ -501,6 +505,8 @@ perf_trace_disable_##name(struct ftrace_event_call *unused)         \
  *     .raw_init               = trace_event_raw_init,
  *     .regfunc                = ftrace_reg_event_<call>,
  *     .unregfunc              = ftrace_unreg_event_<call>,
+ *     .print_fmt              = print_fmt_<call>,
+ *     .define_fields          = ftrace_define_fields_<call>,
  * }
  *
  */
@@ -569,7 +575,6 @@ ftrace_raw_event_id_##call(struct ftrace_event_call *event_call,    \
                return;                                                 \
        entry   = ring_buffer_event_data(event);                        \
                                                                        \
-                                                                       \
        tstruct                                                         \
                                                                        \
        { assign; }                                                     \
@@ -758,13 +763,12 @@ __attribute__((section("_ftrace_events"))) event_##call = {               \
 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
 static notrace void                                                    \
 perf_trace_templ_##call(struct ftrace_event_call *event_call,          \
-                           proto)                                      \
+                       struct pt_regs *__regs, proto)                  \
 {                                                                      \
        struct ftrace_data_offsets_##call __maybe_unused __data_offsets;\
        struct ftrace_raw_##call *entry;                                \
        u64 __addr = 0, __count = 1;                                    \
        unsigned long irq_flags;                                        \
-       struct pt_regs *__regs;                                         \
        int __entry_size;                                               \
        int __data_size;                                                \
        int rctx;                                                       \
@@ -785,20 +789,22 @@ perf_trace_templ_##call(struct ftrace_event_call *event_call,             \
                                                                        \
        { assign; }                                                     \
                                                                        \
-       __regs = &__get_cpu_var(perf_trace_regs);                       \
-       perf_fetch_caller_regs(__regs, 2);                              \
-                                                                       \
        perf_trace_buf_submit(entry, __entry_size, rctx, __addr,        \
                               __count, irq_flags, __regs);             \
 }
 
 #undef DEFINE_EVENT
-#define DEFINE_EVENT(template, call, proto, args)              \
-static notrace void perf_trace_##call(proto)                   \
-{                                                              \
-       struct ftrace_event_call *event_call = &event_##call;   \
-                                                               \
-       perf_trace_templ_##template(event_call, args);          \
+#define DEFINE_EVENT(template, call, proto, args)                      \
+static notrace void perf_trace_##call(proto)                           \
+{                                                                      \
+       struct ftrace_event_call *event_call = &event_##call;           \
+       struct pt_regs *__regs = &get_cpu_var(perf_trace_regs);         \
+                                                                       \
+       perf_fetch_caller_regs(__regs, 1);                              \
+                                                                       \
+       perf_trace_templ_##template(event_call, __regs, args);          \
+                                                                       \
+       put_cpu_var(perf_trace_regs);                                   \
 }
 
 #undef DEFINE_EVENT_PRINT
index eb77e8c..5fe94b8 100644 (file)
@@ -604,8 +604,7 @@ config RT_GROUP_SCHED
        default n
        help
          This feature lets you explicitly allocate real CPU bandwidth
-         to users or control groups (depending on the "Basis for grouping tasks"
-         setting below. If enabled, it will also make it impossible to
+         to task groups. If enabled, it will also make it impossible to
          schedule realtime tasks for non-root users until you allocate
          realtime bandwidth for them.
          See Documentation/scheduler/sched-rt-group.txt for more information.
index 59a009d..5108232 100644 (file)
@@ -429,7 +429,7 @@ static void wq_add(struct mqueue_inode_info *info, int sr,
  * sr: SEND or RECV
  */
 static int wq_sleep(struct mqueue_inode_info *info, int sr,
-                       long timeout, struct ext_wait_queue *ewp)
+                   ktime_t *timeout, struct ext_wait_queue *ewp)
 {
        int retval;
        signed long time;
@@ -440,7 +440,8 @@ static int wq_sleep(struct mqueue_inode_info *info, int sr,
                set_current_state(TASK_INTERRUPTIBLE);
 
                spin_unlock(&info->lock);
-               time = schedule_timeout(timeout);
+               time = schedule_hrtimeout_range_clock(timeout,
+                   HRTIMER_MODE_ABS, 0, CLOCK_REALTIME);
 
                while (ewp->state == STATE_PENDING)
                        cpu_relax();
@@ -552,31 +553,16 @@ static void __do_notify(struct mqueue_inode_info *info)
        wake_up(&info->wait_q);
 }
 
-static long prepare_timeout(struct timespec *p)
+static int prepare_timeout(const struct timespec __user *u_abs_timeout,
+                          ktime_t *expires, struct timespec *ts)
 {
-       struct timespec nowts;
-       long timeout;
-
-       if (p) {
-               if (unlikely(p->tv_nsec < 0 || p->tv_sec < 0
-                       || p->tv_nsec >= NSEC_PER_SEC))
-                       return -EINVAL;
-               nowts = CURRENT_TIME;
-               /* first subtract as jiffies can't be too big */
-               p->tv_sec -= nowts.tv_sec;
-               if (p->tv_nsec < nowts.tv_nsec) {
-                       p->tv_nsec += NSEC_PER_SEC;
-                       p->tv_sec--;
-               }
-               p->tv_nsec -= nowts.tv_nsec;
-               if (p->tv_sec < 0)
-                       return 0;
-
-               timeout = timespec_to_jiffies(p) + 1;
-       } else
-               return MAX_SCHEDULE_TIMEOUT;
+       if (copy_from_user(ts, u_abs_timeout, sizeof(struct timespec)))
+               return -EFAULT;
+       if (!timespec_valid(ts))
+               return -EINVAL;
 
-       return timeout;
+       *expires = timespec_to_ktime(*ts);
+       return 0;
 }
 
 static void remove_notification(struct mqueue_inode_info *info)
@@ -862,22 +848,21 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
        struct ext_wait_queue *receiver;
        struct msg_msg *msg_ptr;
        struct mqueue_inode_info *info;
-       struct timespec ts, *p = NULL;
-       long timeout;
+       ktime_t expires, *timeout = NULL;
+       struct timespec ts;
        int ret;
 
        if (u_abs_timeout) {
-               if (copy_from_user(&ts, u_abs_timeout, 
-                                       sizeof(struct timespec)))
-                       return -EFAULT;
-               p = &ts;
+               int res = prepare_timeout(u_abs_timeout, &expires, &ts);
+               if (res)
+                       return res;
+               timeout = &expires;
        }
 
        if (unlikely(msg_prio >= (unsigned long) MQ_PRIO_MAX))
                return -EINVAL;
 
-       audit_mq_sendrecv(mqdes, msg_len, msg_prio, p);
-       timeout = prepare_timeout(p);
+       audit_mq_sendrecv(mqdes, msg_len, msg_prio, timeout ? &ts : NULL);
 
        filp = fget(mqdes);
        if (unlikely(!filp)) {
@@ -919,9 +904,6 @@ SYSCALL_DEFINE5(mq_timedsend, mqd_t, mqdes, const char __user *, u_msg_ptr,
                if (filp->f_flags & O_NONBLOCK) {
                        spin_unlock(&info->lock);
                        ret = -EAGAIN;
-               } else if (unlikely(timeout < 0)) {
-                       spin_unlock(&info->lock);
-                       ret = timeout;
                } else {
                        wait.task = current;
                        wait.msg = (void *) msg_ptr;
@@ -954,24 +936,23 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
                size_t, msg_len, unsigned int __user *, u_msg_prio,
                const struct timespec __user *, u_abs_timeout)
 {
-       long timeout;
        ssize_t ret;
        struct msg_msg *msg_ptr;
        struct file *filp;
        struct inode *inode;
        struct mqueue_inode_info *info;
        struct ext_wait_queue wait;
-       struct timespec ts, *p = NULL;
+       ktime_t expires, *timeout = NULL;
+       struct timespec ts;
 
        if (u_abs_timeout) {
-               if (copy_from_user(&ts, u_abs_timeout, 
-                                       sizeof(struct timespec)))
-                       return -EFAULT;
-               p = &ts;
+               int res = prepare_timeout(u_abs_timeout, &expires, &ts);
+               if (res)
+                       return res;
+               timeout = &expires;
        }
 
-       audit_mq_sendrecv(mqdes, msg_len, 0, p);
-       timeout = prepare_timeout(p);
+       audit_mq_sendrecv(mqdes, msg_len, 0, timeout ? &ts : NULL);
 
        filp = fget(mqdes);
        if (unlikely(!filp)) {
@@ -1003,11 +984,6 @@ SYSCALL_DEFINE5(mq_timedreceive, mqd_t, mqdes, char __user *, u_msg_ptr,
                if (filp->f_flags & O_NONBLOCK) {
                        spin_unlock(&info->lock);
                        ret = -EAGAIN;
-                       msg_ptr = NULL;
-               } else if (unlikely(timeout < 0)) {
-                       spin_unlock(&info->lock);
-                       ret = timeout;
-                       msg_ptr = NULL;
                } else {
                        wait.task = current;
                        wait.state = STATE_NONE;
index a987aa1..149e18e 100644 (file)
@@ -68,7 +68,7 @@ obj-$(CONFIG_USER_NS) += user_namespace.o
 obj-$(CONFIG_PID_NS) += pid_namespace.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o
-obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
+obj-$(CONFIG_SMP) += stop_machine.o
 obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o
 obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
index e4c0e1f..385b884 100644 (file)
@@ -216,7 +216,6 @@ static int acct_on(char *name)
 {
        struct file *file;
        struct vfsmount *mnt;
-       int error;
        struct pid_namespace *ns;
        struct bsd_acct_struct *acct = NULL;
 
@@ -244,13 +243,6 @@ static int acct_on(char *name)
                }
        }
 
-       error = security_acct(file);
-       if (error) {
-               kfree(acct);
-               filp_close(file, NULL);
-               return error;
-       }
-
        spin_lock(&acct_lock);
        if (ns->bacct == NULL) {
                ns->bacct = acct;
@@ -281,7 +273,7 @@ static int acct_on(char *name)
  */
 SYSCALL_DEFINE1(acct, const char __user *, name)
 {
-       int error;
+       int error = 0;
 
        if (!capable(CAP_SYS_PACCT))
                return -EPERM;
@@ -299,13 +291,11 @@ SYSCALL_DEFINE1(acct, const char __user *, name)
                if (acct == NULL)
                        return 0;
 
-               error = security_acct(NULL);
-               if (!error) {
-                       spin_lock(&acct_lock);
-                       acct_file_reopen(acct, NULL, NULL);
-                       spin_unlock(&acct_lock);
-               }
+               spin_lock(&acct_lock);
+               acct_file_reopen(acct, NULL, NULL);
+               spin_unlock(&acct_lock);
        }
+
        return error;
 }
 
index 9e4697e..2f05303 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/syscalls.h>
 #include <linux/pid_namespace.h>
 #include <asm/uaccess.h>
-#include "cred-internals.h"
 
 /*
  * Leveraged for setting/resetting capabilities
index 6d870f2..2917750 100644 (file)
@@ -3016,7 +3016,7 @@ static int cgroup_event_wake(wait_queue_t *wait, unsigned mode,
        unsigned long flags = (unsigned long)key;
 
        if (flags & POLLHUP) {
-               remove_wait_queue_locked(event->wqh, &event->wait);
+               __remove_wait_queue(event->wqh, &event->wait);
                spin_lock(&cgrp->event_list_lock);
                list_del(&event->list);
                spin_unlock(&cgrp->event_list_lock);
@@ -3615,7 +3615,7 @@ static void __init cgroup_init_subsys(struct cgroup_subsys *ss)
  * @ss: the subsystem to load
  *
  * This function should be called in a modular subsystem's initcall. If the
- * subsytem is built as a module, it will be assigned a new subsys_id and set
+ * subsystem is built as a module, it will be assigned a new subsys_id and set
  * up for use. If the subsystem is built-in anyway, work is delegated to the
  * simpler cgroup_init_subsys.
  */
index e5c0244..ce71ed5 100644 (file)
@@ -89,10 +89,10 @@ struct cgroup_subsys freezer_subsys;
 
 /* Locks taken and their ordering
  * ------------------------------
- * css_set_lock
  * cgroup_mutex (AKA cgroup_lock)
- * task->alloc_lock (AKA task_lock)
  * freezer->lock
+ * css_set_lock
+ * task->alloc_lock (AKA task_lock)
  * task->sighand->siglock
  *
  * cgroup code forces css_set_lock to be taken before task->alloc_lock
@@ -100,33 +100,38 @@ struct cgroup_subsys freezer_subsys;
  * freezer_create(), freezer_destroy():
  * cgroup_mutex [ by cgroup core ]
  *
- * can_attach():
- * cgroup_mutex
+ * freezer_can_attach():
+ * cgroup_mutex (held by caller of can_attach)
  *
- * cgroup_frozen():
+ * cgroup_freezing_or_frozen():
  * task->alloc_lock (to get task's cgroup)
  *
  * freezer_fork() (preserving fork() performance means can't take cgroup_mutex):
- * task->alloc_lock (to get task's cgroup)
  * freezer->lock
  *  sighand->siglock (if the cgroup is freezing)
  *
  * freezer_read():
  * cgroup_mutex
  *  freezer->lock
+ *   write_lock css_set_lock (cgroup iterator start)
+ *    task->alloc_lock
  *   read_lock css_set_lock (cgroup iterator start)
  *
  * freezer_write() (freeze):
  * cgroup_mutex
  *  freezer->lock
+ *   write_lock css_set_lock (cgroup iterator start)
+ *    task->alloc_lock
  *   read_lock css_set_lock (cgroup iterator start)
- *    sighand->siglock
+ *    sighand->siglock (fake signal delivery inside freeze_task())
  *
  * freezer_write() (unfreeze):
  * cgroup_mutex
  *  freezer->lock
+ *   write_lock css_set_lock (cgroup iterator start)
+ *    task->alloc_lock
  *   read_lock css_set_lock (cgroup iterator start)
- *    task->alloc_lock (to prevent races with freeze_task())
+ *    task->alloc_lock (inside thaw_process(), prevents race with refrigerator())
  *     sighand->siglock
  */
 static struct cgroup_subsys_state *freezer_create(struct cgroup_subsys *ss,
index 7f40e92..5adab05 100644 (file)
@@ -495,29 +495,26 @@ asmlinkage long compat_sys_sched_getaffinity(compat_pid_t pid, unsigned int len,
 {
        int ret;
        cpumask_var_t mask;
-       unsigned long *k;
-       unsigned int min_length = cpumask_size();
-
-       if (nr_cpu_ids <= BITS_PER_COMPAT_LONG)
-               min_length = sizeof(compat_ulong_t);
 
-       if (len < min_length)
+       if ((len * BITS_PER_BYTE) < nr_cpu_ids)
+               return -EINVAL;
+       if (len & (sizeof(compat_ulong_t)-1))
                return -EINVAL;
 
        if (!alloc_cpumask_var(&mask, GFP_KERNEL))
                return -ENOMEM;
 
        ret = sched_getaffinity(pid, mask);
-       if (ret < 0)
-               goto out;
+       if (ret == 0) {
+               size_t retlen = min_t(size_t, len, cpumask_size());
 
-       k = cpumask_bits(mask);
-       ret = compat_put_bitmap(user_mask_ptr, k, min_length * 8);
-       if (ret == 0)
-               ret = min_length;
-
-out:
+               if (compat_put_bitmap(user_mask_ptr, cpumask_bits(mask), retlen * 8))
+                       ret = -EFAULT;
+               else
+                       ret = retlen;
+       }
        free_cpumask_var(mask);
+
        return ret;
 }
 
index 25bba73..5457775 100644 (file)
@@ -164,6 +164,7 @@ static inline void check_for_tasks(int cpu)
 }
 
 struct take_cpu_down_param {
+       struct task_struct *caller;
        unsigned long mod;
        void *hcpu;
 };
@@ -172,6 +173,7 @@ struct take_cpu_down_param {
 static int __ref take_cpu_down(void *_param)
 {
        struct take_cpu_down_param *param = _param;
+       unsigned int cpu = (unsigned long)param->hcpu;
        int err;
 
        /* Ensure this CPU doesn't handle any more interrupts. */
@@ -182,6 +184,8 @@ static int __ref take_cpu_down(void *_param)
        raw_notifier_call_chain(&cpu_chain, CPU_DYING | param->mod,
                                param->hcpu);
 
+       if (task_cpu(param->caller) == cpu)
+               move_task_off_dead_cpu(cpu, param->caller);
        /* Force idle task to run as soon as we yield: it should
           immediately notice cpu is offline and die quickly. */
        sched_idle_next();
@@ -192,10 +196,10 @@ static int __ref take_cpu_down(void *_param)
 static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 {
        int err, nr_calls = 0;
-       cpumask_var_t old_allowed;
        void *hcpu = (void *)(long)cpu;
        unsigned long mod = tasks_frozen ? CPU_TASKS_FROZEN : 0;
        struct take_cpu_down_param tcd_param = {
+               .caller = current,
                .mod = mod,
                .hcpu = hcpu,
        };
@@ -206,9 +210,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
        if (!cpu_online(cpu))
                return -EINVAL;
 
-       if (!alloc_cpumask_var(&old_allowed, GFP_KERNEL))
-               return -ENOMEM;
-
        cpu_hotplug_begin();
        set_cpu_active(cpu, false);
        err = __raw_notifier_call_chain(&cpu_chain, CPU_DOWN_PREPARE | mod,
@@ -225,10 +226,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
                goto out_release;
        }
 
-       /* Ensure that we are not runnable on dying cpu */
-       cpumask_copy(old_allowed, &current->cpus_allowed);
-       set_cpus_allowed_ptr(current, cpu_active_mask);
-
        err = __stop_machine(take_cpu_down, &tcd_param, cpumask_of(cpu));
        if (err) {
                set_cpu_active(cpu, true);
@@ -237,7 +234,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
                                            hcpu) == NOTIFY_BAD)
                        BUG();
 
-               goto out_allowed;
+               goto out_release;
        }
        BUG_ON(cpu_online(cpu));
 
@@ -255,8 +252,6 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 
        check_for_tasks(cpu);
 
-out_allowed:
-       set_cpus_allowed_ptr(current, old_allowed);
 out_release:
        cpu_hotplug_done();
        if (!err) {
@@ -264,7 +259,6 @@ out_release:
                                            hcpu) == NOTIFY_BAD)
                        BUG();
        }
-       free_cpumask_var(old_allowed);
        return err;
 }
 
@@ -272,9 +266,6 @@ int __ref cpu_down(unsigned int cpu)
 {
        int err;
 
-       err = stop_machine_create();
-       if (err)
-               return err;
        cpu_maps_update_begin();
 
        if (cpu_hotplug_disabled) {
@@ -286,7 +277,6 @@ int __ref cpu_down(unsigned int cpu)
 
 out:
        cpu_maps_update_done();
-       stop_machine_destroy();
        return err;
 }
 EXPORT_SYMBOL(cpu_down);
@@ -367,9 +357,6 @@ int disable_nonboot_cpus(void)
 {
        int cpu, first_cpu, error;
 
-       error = stop_machine_create();
-       if (error)
-               return error;
        cpu_maps_update_begin();
        first_cpu = cpumask_first(cpu_online_mask);
        /*
@@ -400,7 +387,6 @@ int disable_nonboot_cpus(void)
                printk(KERN_ERR "Non-boot CPUs are not disabled\n");
        }
        cpu_maps_update_done();
-       stop_machine_destroy();
        return error;
 }
 
index d109467..9a50c5f 100644 (file)
@@ -2182,19 +2182,52 @@ void __init cpuset_init_smp(void)
 void cpuset_cpus_allowed(struct task_struct *tsk, struct cpumask *pmask)
 {
        mutex_lock(&callback_mutex);
-       cpuset_cpus_allowed_locked(tsk, pmask);
+       task_lock(tsk);
+       guarantee_online_cpus(task_cs(tsk), pmask);
+       task_unlock(tsk);
        mutex_unlock(&callback_mutex);
 }
 
-/**
- * cpuset_cpus_allowed_locked - return cpus_allowed mask from a tasks cpuset.
- * Must be called with callback_mutex held.
- **/
-void cpuset_cpus_allowed_locked(struct task_struct *tsk, struct cpumask *pmask)
+int cpuset_cpus_allowed_fallback(struct task_struct *tsk)
 {
-       task_lock(tsk);
-       guarantee_online_cpus(task_cs(tsk), pmask);
-       task_unlock(tsk);
+       const struct cpuset *cs;
+       int cpu;
+
+       rcu_read_lock();
+       cs = task_cs(tsk);
+       if (cs)
+               cpumask_copy(&tsk->cpus_allowed, cs->cpus_allowed);
+       rcu_read_unlock();
+
+       /*
+        * We own tsk->cpus_allowed, nobody can change it under us.
+        *
+        * But we used cs && cs->cpus_allowed lockless and thus can
+        * race with cgroup_attach_task() or update_cpumask() and get
+        * the wrong tsk->cpus_allowed. However, both cases imply the
+        * subsequent cpuset_change_cpumask()->set_cpus_allowed_ptr()
+        * which takes task_rq_lock().
+        *
+        * If we are called after it dropped the lock we must see all
+        * changes in tsk_cs()->cpus_allowed. Otherwise we can temporary
+        * set any mask even if it is not right from task_cs() pov,
+        * the pending set_cpus_allowed_ptr() will fix things.
+        */
+
+       cpu = cpumask_any_and(&tsk->cpus_allowed, cpu_active_mask);
+       if (cpu >= nr_cpu_ids) {
+               /*
+                * Either tsk->cpus_allowed is wrong (see above) or it
+                * is actually empty. The latter case is only possible
+                * if we are racing with remove_tasks_in_empty_cpuset().
+                * Like above we can temporary set any mask and rely on
+                * set_cpus_allowed_ptr() as synchronization point.
+                */
+               cpumask_copy(&tsk->cpus_allowed, cpu_possible_mask);
+               cpu = cpumask_any(cpu_active_mask);
+       }
+
+       return cpu;
 }
 
 void cpuset_init_current_mems_allowed(void)
@@ -2382,22 +2415,6 @@ int __cpuset_node_allowed_hardwall(int node, gfp_t gfp_mask)
        return 0;
 }
 
-/**
- * cpuset_lock - lock out any changes to cpuset structures
- *
- * The out of memory (oom) code needs to mutex_lock cpusets
- * from being changed while it scans the tasklist looking for a
- * task in an overlapping cpuset.  Expose callback_mutex via this
- * cpuset_lock() routine, so the oom code can lock it, before
- * locking the task list.  The tasklist_lock is a spinlock, so
- * must be taken inside callback_mutex.
- */
-
-void cpuset_lock(void)
-{
-       mutex_lock(&callback_mutex);
-}
-
 /**
  * cpuset_unlock - release lock on cpuset changes
  *
diff --git a/kernel/cred-internals.h b/kernel/cred-internals.h
deleted file mode 100644 (file)
index 2dc4fc2..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/* Internal credentials stuff
- *
- * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
- * Written by David Howells (dhowells@redhat.com)
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public Licence
- * as published by the Free Software Foundation; either version
- * 2 of the Licence, or (at your option) any later version.
- */
-
-/*
- * user.c
- */
-static inline void sched_switch_user(struct task_struct *p)
-{
-#ifdef CONFIG_USER_SCHED
-       sched_move_task(p);
-#endif /* CONFIG_USER_SCHED */
-}
-
index 62af181..2c24870 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/init_task.h>
 #include <linux/security.h>
 #include <linux/cn_proc.h>
-#include "cred-internals.h"
 
 #if 0
 #define kdebug(FMT, ...) \
@@ -523,8 +522,6 @@ int commit_creds(struct cred *new)
 #endif
        BUG_ON(atomic_read(&new->usage) < 1);
 
-       security_commit_creds(new, old);
-
        get_cred(new); /* we will require a ref for the subj creds too */
 
        /* dumpability changes */
@@ -560,8 +557,6 @@ int commit_creds(struct cred *new)
                atomic_dec(&old->user->processes);
        alter_cred_subscribers(old, -2);
 
-       sched_switch_user(task);
-
        /* send notifications */
        if (new->uid   != old->uid  ||
            new->euid  != old->euid ||
index 7f2683a..eabca5a 100644 (file)
@@ -55,7 +55,6 @@
 #include <asm/unistd.h>
 #include <asm/pgtable.h>
 #include <asm/mmu_context.h>
-#include "cred-internals.h"
 
 static void exit_mm(struct task_struct * tsk);
 
index 4c14942..4d57d9e 100644 (file)
@@ -1112,8 +1112,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
        p->memcg_batch.memcg = NULL;
 #endif
 
-       p->bts = NULL;
-
        /* Perform scheduler related setup. Assign this task to a CPU. */
        sched_fork(p, clone_flags);
 
index 2b45b2e..53b1916 100644 (file)
@@ -164,12 +164,6 @@ int groups_search(const struct group_info *group_info, gid_t grp)
  */
 int set_groups(struct cred *new, struct group_info *group_info)
 {
-       int retval;
-
-       retval = security_task_setgroups(group_info);
-       if (retval)
-               return retval;
-
        put_group_info(new->group_info);
        groups_sort(group_info);
        get_group_info(group_info);
index 0086628..b9b134b 100644 (file)
@@ -1749,35 +1749,15 @@ void __init hrtimers_init(void)
 }
 
 /**
- * schedule_hrtimeout_range - sleep until timeout
+ * schedule_hrtimeout_range_clock - sleep until timeout
  * @expires:   timeout value (ktime_t)
  * @delta:     slack in expires timeout (ktime_t)
  * @mode:      timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
- *
- * Make the current task sleep until the given expiry time has
- * elapsed. The routine will return immediately unless
- * the current task state has been set (see set_current_state()).
- *
- * The @delta argument gives the kernel the freedom to schedule the
- * actual wakeup to a time that is both power and performance friendly.
- * The kernel give the normal best effort behavior for "@expires+@delta",
- * but may decide to fire the timer earlier, but no earlier than @expires.
- *
- * You can set the task state as follows -
- *
- * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
- * pass before the routine returns.
- *
- * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
- * delivered to the current task.
- *
- * The current task state is guaranteed to be TASK_RUNNING when this
- * routine returns.
- *
- * Returns 0 when the timer has expired otherwise -EINTR
+ * @clock:     timer clock, CLOCK_MONOTONIC or CLOCK_REALTIME
  */
-int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
-                              const enum hrtimer_mode mode)
+int __sched
+schedule_hrtimeout_range_clock(ktime_t *expires, unsigned long delta,
+                              const enum hrtimer_mode mode, int clock)
 {
        struct hrtimer_sleeper t;
 
@@ -1799,7 +1779,7 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
                return -EINTR;
        }
 
-       hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode);
+       hrtimer_init_on_stack(&t.timer, clock, mode);
        hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
 
        hrtimer_init_sleeper(&t, current);
@@ -1818,6 +1798,41 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
 
        return !t.task ? 0 : -EINTR;
 }
+
+/**
+ * schedule_hrtimeout_range - sleep until timeout
+ * @expires:   timeout value (ktime_t)
+ * @delta:     slack in expires timeout (ktime_t)
+ * @mode:      timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
+ *
+ * Make the current task sleep until the given expiry time has
+ * elapsed. The routine will return immediately unless
+ * the current task state has been set (see set_current_state()).
+ *
+ * The @delta argument gives the kernel the freedom to schedule the
+ * actual wakeup to a time that is both power and performance friendly.
+ * The kernel give the normal best effort behavior for "@expires+@delta",
+ * but may decide to fire the timer earlier, but no earlier than @expires.
+ *
+ * You can set the task state as follows -
+ *
+ * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
+ * pass before the routine returns.
+ *
+ * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
+ * delivered to the current task.
+ *
+ * The current task state is guaranteed to be TASK_RUNNING when this
+ * routine returns.
+ *
+ * Returns 0 when the timer has expired otherwise -EINTR
+ */
+int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
+                                    const enum hrtimer_mode mode)
+{
+       return schedule_hrtimeout_range_clock(expires, delta, mode,
+                                             CLOCK_MONOTONIC);
+}
 EXPORT_SYMBOL_GPL(schedule_hrtimeout_range);
 
 /**
index 03808ed..7a56b22 100644 (file)
 #include <linux/percpu.h>
 #include <linux/sched.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/cpu.h>
 #include <linux/smp.h>
 
 #include <linux/hw_breakpoint.h>
 
+
 /*
  * Constraints data
  */
 
 /* Number of pinned cpu breakpoints in a cpu */
-static DEFINE_PER_CPU(unsigned int, nr_cpu_bp_pinned);
+static DEFINE_PER_CPU(unsigned int, nr_cpu_bp_pinned[TYPE_MAX]);
 
 /* Number of pinned task breakpoints in a cpu */
-static DEFINE_PER_CPU(unsigned int, nr_task_bp_pinned[HBP_NUM]);
+static DEFINE_PER_CPU(unsigned int *, nr_task_bp_pinned[TYPE_MAX]);
 
 /* Number of non-pinned cpu/task breakpoints in a cpu */
-static DEFINE_PER_CPU(unsigned int, nr_bp_flexible);
+static DEFINE_PER_CPU(unsigned int, nr_bp_flexible[TYPE_MAX]);
+
+static int nr_slots[TYPE_MAX];
+
+static int constraints_initialized;
 
 /* Gather the number of total pinned and un-pinned bp in a cpuset */
 struct bp_busy_slots {
@@ -67,16 +73,29 @@ struct bp_busy_slots {
 /* Serialize accesses to the above constraints */
 static DEFINE_MUTEX(nr_bp_mutex);
 
+__weak int hw_breakpoint_weight(struct perf_event *bp)
+{
+       return 1;
+}
+
+static inline enum bp_type_idx find_slot_idx(struct perf_event *bp)
+{
+       if (bp->attr.bp_type & HW_BREAKPOINT_RW)
+               return TYPE_DATA;
+
+       return TYPE_INST;
+}
+
 /*
  * Report the maximum number of pinned breakpoints a task
  * have in this cpu
  */
-static unsigned int max_task_bp_pinned(int cpu)
+static unsigned int max_task_bp_pinned(int cpu, enum bp_type_idx type)
 {
        int i;
-       unsigned int *tsk_pinned = per_cpu(nr_task_bp_pinned, cpu);
+       unsigned int *tsk_pinned = per_cpu(nr_task_bp_pinned[type], cpu);
 
-       for (i = HBP_NUM -1; i >= 0; i--) {
+       for (i = nr_slots[type] - 1; i >= 0; i--) {
                if (tsk_pinned[i] > 0)
                        return i + 1;
        }
@@ -84,7 +103,7 @@ static unsigned int max_task_bp_pinned(int cpu)
        return 0;
 }
 
-static int task_bp_pinned(struct task_struct *tsk)
+static int task_bp_pinned(struct task_struct *tsk, enum bp_type_idx type)
 {
        struct perf_event_context *ctx = tsk->perf_event_ctxp;
        struct list_head *list;
@@ -105,7 +124,8 @@ static int task_bp_pinned(struct task_struct *tsk)
         */
        list_for_each_entry(bp, list, event_entry) {
                if (bp->attr.type == PERF_TYPE_BREAKPOINT)
-                       count++;
+                       if (find_slot_idx(bp) == type)
+                               count += hw_breakpoint_weight(bp);
        }
 
        raw_spin_unlock_irqrestore(&ctx->lock, flags);
@@ -118,18 +138,19 @@ static int task_bp_pinned(struct task_struct *tsk)
  * a given cpu (cpu > -1) or in all of them (cpu = -1).
  */
 static void
-fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp)
+fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp,
+                   enum bp_type_idx type)
 {
        int cpu = bp->cpu;
        struct task_struct *tsk = bp->ctx->task;
 
        if (cpu >= 0) {
-               slots->pinned = per_cpu(nr_cpu_bp_pinned, cpu);
+               slots->pinned = per_cpu(nr_cpu_bp_pinned[type], cpu);
                if (!tsk)
-                       slots->pinned += max_task_bp_pinned(cpu);
+                       slots->pinned += max_task_bp_pinned(cpu, type);
                else
-                       slots->pinned += task_bp_pinned(tsk);
-               slots->flexible = per_cpu(nr_bp_flexible, cpu);
+                       slots->pinned += task_bp_pinned(tsk, type);
+               slots->flexible = per_cpu(nr_bp_flexible[type], cpu);
 
                return;
        }
@@ -137,48 +158,66 @@ fetch_bp_busy_slots(struct bp_busy_slots *slots, struct perf_event *bp)
        for_each_online_cpu(cpu) {
                unsigned int nr;
 
-               nr = per_cpu(nr_cpu_bp_pinned, cpu);
+               nr = per_cpu(nr_cpu_bp_pinned[type], cpu);
                if (!tsk)
-                       nr += max_task_bp_pinned(cpu);
+                       nr += max_task_bp_pinned(cpu, type);
                else
-                       nr += task_bp_pinned(tsk);
+                       nr += task_bp_pinned(tsk, type);
 
                if (nr > slots->pinned)
                        slots->pinned = nr;
 
-               nr = per_cpu(nr_bp_flexible, cpu);
+               nr = per_cpu(nr_bp_flexible[type], cpu);
 
                if (nr > slots->flexible)
                        slots->flexible = nr;
        }
 }
 
+/*
+ * For now, continue to consider flexible as pinned, until we can
+ * ensure no flexible event can ever be scheduled before a pinned event
+ * in a same cpu.
+ */
+static void
+fetch_this_slot(struct bp_busy_slots *slots, int weight)
+{
+       slots->pinned += weight;
+}
+
 /*
  * Add a pinned breakpoint for the given task in our constraint table
  */
-static void toggle_bp_task_slot(struct task_struct *tsk, int cpu, bool enable)
+static void toggle_bp_task_slot(struct task_struct *tsk, int cpu, bool enable,
+                               enum bp_type_idx type, int weight)
 {
        unsigned int *tsk_pinned;
-       int count = 0;
+       int old_count = 0;
+       int old_idx = 0;
+       int idx = 0;
 
-       count = task_bp_pinned(tsk);
+       old_count = task_bp_pinned(tsk, type);
+       old_idx = old_count - 1;
+       idx = old_idx + weight;
 
-       tsk_pinned = per_cpu(nr_task_bp_pinned, cpu);
+       tsk_pinned = per_cpu(nr_task_bp_pinned[type], cpu);
        if (enable) {
-               tsk_pinned[count]++;
-               if (count > 0)
-                       tsk_pinned[count-1]--;
+               tsk_pinned[idx]++;
+               if (old_count > 0)
+                       tsk_pinned[old_idx]--;
        } else {
-               tsk_pinned[count]--;
-               if (count > 0)
-                       tsk_pinned[count-1]++;
+               tsk_pinned[idx]--;
+               if (old_count > 0)
+                       tsk_pinned[old_idx]++;
        }
 }
 
 /*
  * Add/remove the given breakpoint in our constraint table
  */
-static void toggle_bp_slot(struct perf_event *bp, bool enable)
+static void
+toggle_bp_slot(struct perf_event *bp, bool enable, enum bp_type_idx type,
+              int weight)
 {
        int cpu = bp->cpu;
        struct task_struct *tsk = bp->ctx->task;
@@ -186,20 +225,20 @@ static void toggle_bp_slot(struct perf_event *bp, bool enable)
        /* Pinned counter task profiling */
        if (tsk) {
                if (cpu >= 0) {
-                       toggle_bp_task_slot(tsk, cpu, enable);
+                       toggle_bp_task_slot(tsk, cpu, enable, type, weight);
                        return;
                }
 
                for_each_online_cpu(cpu)
-                       toggle_bp_task_slot(tsk, cpu, enable);
+                       toggle_bp_task_slot(tsk, cpu, enable, type, weight);
                return;
        }
 
        /* Pinned counter cpu profiling */
        if (enable)
-               per_cpu(nr_cpu_bp_pinned, bp->cpu)++;
+               per_cpu(nr_cpu_bp_pinned[type], bp->cpu) += weight;
        else
-               per_cpu(nr_cpu_bp_pinned, bp->cpu)--;
+               per_cpu(nr_cpu_bp_pinned[type], bp->cpu) -= weight;
 }
 
 /*
@@ -246,14 +285,29 @@ static void toggle_bp_slot(struct perf_event *bp, bool enable)
 static int __reserve_bp_slot(struct perf_event *bp)
 {
        struct bp_busy_slots slots = {0};
+       enum bp_type_idx type;
+       int weight;
 
-       fetch_bp_busy_slots(&slots, bp);
+       /* We couldn't initialize breakpoint constraints on boot */
+       if (!constraints_initialized)
+               return -ENOMEM;
+
+       /* Basic checks */
+       if (bp->attr.bp_type == HW_BREAKPOINT_EMPTY ||
+           bp->attr.bp_type == HW_BREAKPOINT_INVALID)
+               return -EINVAL;
+
+       type = find_slot_idx(bp);
+       weight = hw_breakpoint_weight(bp);
+
+       fetch_bp_busy_slots(&slots, bp, type);
+       fetch_this_slot(&slots, weight);
 
        /* Flexible counters need to keep at least one slot */
-       if (slots.pinned + (!!slots.flexible) == HBP_NUM)
+       if (slots.pinned + (!!slots.flexible) > nr_slots[type])
                return -ENOSPC;
 
-       toggle_bp_slot(bp, true);
+       toggle_bp_slot(bp, true, type, weight);
 
        return 0;
 }
@@ -273,7 +327,12 @@ int reserve_bp_slot(struct perf_event *bp)
 
 static void __release_bp_slot(struct perf_event *bp)
 {
-       toggle_bp_slot(bp, false);
+       enum bp_type_idx type;
+       int weight;
+
+       type = find_slot_idx(bp);
+       weight = hw_breakpoint_weight(bp);
+       toggle_bp_slot(bp, false, type, weight);
 }
 
 void release_bp_slot(struct perf_event *bp)
@@ -308,6 +367,28 @@ int dbg_release_bp_slot(struct perf_event *bp)
        return 0;
 }
 
+static int validate_hw_breakpoint(struct perf_event *bp)
+{
+       int ret;
+
+       ret = arch_validate_hwbkpt_settings(bp);
+       if (ret)
+               return ret;
+
+       if (arch_check_bp_in_kernelspace(bp)) {
+               if (bp->attr.exclude_kernel)
+                       return -EINVAL;
+               /*
+                * Don't let unprivileged users set a breakpoint in the trap
+                * path to avoid trap recursion attacks.
+                */
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+       }
+
+       return 0;
+}
+
 int register_perf_hw_breakpoint(struct perf_event *bp)
 {
        int ret;
@@ -316,17 +397,7 @@ int register_perf_hw_breakpoint(struct perf_event *bp)
        if (ret)
                return ret;
 
-       /*
-        * Ptrace breakpoints can be temporary perf events only
-        * meant to reserve a slot. In this case, it is created disabled and
-        * we don't want to check the params right now (as we put a null addr)
-        * But perf tools create events as disabled and we want to check
-        * the params for them.
-        * This is a quick hack that will be removed soon, once we remove
-        * the tmp breakpoints from ptrace
-        */
-       if (!bp->attr.disabled || !bp->overflow_handler)
-               ret = arch_validate_hwbkpt_settings(bp, bp->ctx->task);
+       ret = validate_hw_breakpoint(bp);
 
        /* if arch_validate_hwbkpt_settings() fails then release bp slot */
        if (ret)
@@ -373,7 +444,7 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
        if (attr->disabled)
                goto end;
 
-       err = arch_validate_hwbkpt_settings(bp, bp->ctx->task);
+       err = validate_hw_breakpoint(bp);
        if (!err)
                perf_event_enable(bp);
 
@@ -480,7 +551,36 @@ static struct notifier_block hw_breakpoint_exceptions_nb = {
 
 static int __init init_hw_breakpoint(void)
 {
+       unsigned int **task_bp_pinned;
+       int cpu, err_cpu;
+       int i;
+
+       for (i = 0; i < TYPE_MAX; i++)
+               nr_slots[i] = hw_breakpoint_slots(i);
+
+       for_each_possible_cpu(cpu) {
+               for (i = 0; i < TYPE_MAX; i++) {
+                       task_bp_pinned = &per_cpu(nr_task_bp_pinned[i], cpu);
+                       *task_bp_pinned = kzalloc(sizeof(int) * nr_slots[i],
+                                                 GFP_KERNEL);
+                       if (!*task_bp_pinned)
+                               goto err_alloc;
+               }
+       }
+
+       constraints_initialized = 1;
+
        return register_die_notifier(&hw_breakpoint_exceptions_nb);
+
+ err_alloc:
+       for_each_possible_cpu(err_cpu) {
+               if (err_cpu == cpu)
+                       break;
+               for (i = 0; i < TYPE_MAX; i++)
+                       kfree(per_cpu(nr_task_bp_pinned[i], cpu));
+       }
+
+       return -ENOMEM;
 }
 core_initcall(init_hw_breakpoint);
 
index 76d5a67..27e5c69 100644 (file)
@@ -370,9 +370,6 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
        irqreturn_t ret, retval = IRQ_NONE;
        unsigned int status = 0;
 
-       if (!(action->flags & IRQF_DISABLED))
-               local_irq_enable_in_hardirq();
-
        do {
                trace_irq_handler_entry(irq, action);
                ret = action->handler(irq, action->dev_id);
index 704e488..3164ba7 100644 (file)
@@ -138,6 +138,22 @@ int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
        return 0;
 }
 
+int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m)
+{
+       struct irq_desc *desc = irq_to_desc(irq);
+       unsigned long flags;
+
+       if (!desc)
+               return -EINVAL;
+
+       raw_spin_lock_irqsave(&desc->lock, flags);
+       desc->affinity_hint = m;
+       raw_spin_unlock_irqrestore(&desc->lock, flags);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(irq_set_affinity_hint);
+
 #ifndef CONFIG_AUTO_IRQ_AFFINITY
 /*
  * Generic version of the affinity autoselector.
@@ -757,16 +773,6 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
                if (new->flags & IRQF_ONESHOT)
                        desc->status |= IRQ_ONESHOT;
 
-               /*
-                * Force MSI interrupts to run with interrupts
-                * disabled. The multi vector cards can cause stack
-                * overflows due to nested interrupts when enough of
-                * them are directed to a core and fire at the same
-                * time.
-                */
-               if (desc->msi_desc)
-                       new->flags |= IRQF_DISABLED;
-
                if (!(desc->status & IRQ_NOAUTOEN)) {
                        desc->depth = 0;
                        desc->status &= ~IRQ_DISABLED;
@@ -916,6 +922,12 @@ static struct irqaction *__free_irq(unsigned int irq, void *dev_id)
                        desc->chip->disable(irq);
        }
 
+#ifdef CONFIG_SMP
+       /* make sure affinity_hint is cleaned up */
+       if (WARN_ON_ONCE(desc->affinity_hint))
+               desc->affinity_hint = NULL;
+#endif
+
        raw_spin_unlock_irqrestore(&desc->lock, flags);
 
        unregister_handler_proc(irq, action);
@@ -1027,7 +1039,6 @@ EXPORT_SYMBOL(free_irq);
  *     Flags:
  *
  *     IRQF_SHARED             Interrupt is shared
- *     IRQF_DISABLED   Disable local interrupts while processing
  *     IRQF_SAMPLE_RANDOM      The interrupt can be used for entropy
  *     IRQF_TRIGGER_*          Specify active edge(s) or level
  *
@@ -1040,25 +1051,6 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler,
        struct irq_desc *desc;
        int retval;
 
-       /*
-        * handle_IRQ_event() always ignores IRQF_DISABLED except for
-        * the _first_ irqaction (sigh).  That can cause oopsing, but
-        * the behavior is classified as "will not fix" so we need to
-        * start nudging drivers away from using that idiom.
-        */
-       if ((irqflags & (IRQF_SHARED|IRQF_DISABLED)) ==
-                                       (IRQF_SHARED|IRQF_DISABLED)) {
-               pr_warning(
-                 "IRQ %d/%s: IRQF_DISABLED is not guaranteed on shared IRQs\n",
-                       irq, devname);
-       }
-
-#ifdef CONFIG_LOCKDEP
-       /*
-        * Lockdep wants atomic interrupt handlers:
-        */
-       irqflags |= IRQF_DISABLED;
-#endif
        /*
         * Sanity-check: shared interrupts must pass in a real dev-ID,
         * otherwise we'll have trouble later trying to figure out
@@ -1120,3 +1112,40 @@ int request_threaded_irq(unsigned int irq, irq_handler_t handler,
        return retval;
 }
 EXPORT_SYMBOL(request_threaded_irq);
+
+/**
+ *     request_any_context_irq - allocate an interrupt line
+ *     @irq: Interrupt line to allocate
+ *     @handler: Function to be called when the IRQ occurs.
+ *               Threaded handler for threaded interrupts.
+ *     @flags: Interrupt type flags
+ *     @name: An ascii name for the claiming device
+ *     @dev_id: A cookie passed back to the handler function
+ *
+ *     This call allocates interrupt resources and enables the
+ *     interrupt line and IRQ handling. It selects either a
+ *     hardirq or threaded handling method depending on the
+ *     context.
+ *
+ *     On failure, it returns a negative value. On success,
+ *     it returns either IRQC_IS_HARDIRQ or IRQC_IS_NESTED.
+ */
+int request_any_context_irq(unsigned int irq, irq_handler_t handler,
+                           unsigned long flags, const char *name, void *dev_id)
+{
+       struct irq_desc *desc = irq_to_desc(irq);
+       int ret;
+
+       if (!desc)
+               return -EINVAL;
+
+       if (desc->status & IRQ_NESTED_THREAD) {
+               ret = request_threaded_irq(irq, NULL, handler,
+                                          flags, name, dev_id);
+               return !ret ? IRQC_IS_NESTED : ret;
+       }
+
+       ret = request_irq(irq, handler, flags, name, dev_id);
+       return !ret ? IRQC_IS_HARDIRQ : ret;
+}
+EXPORT_SYMBOL_GPL(request_any_context_irq);
index 7a6eb04..09a2ee5 100644 (file)
@@ -32,6 +32,27 @@ static int irq_affinity_proc_show(struct seq_file *m, void *v)
        return 0;
 }
 
+static int irq_affinity_hint_proc_show(struct seq_file *m, void *v)
+{
+       struct irq_desc *desc = irq_to_desc((long)m->private);
+       unsigned long flags;
+       cpumask_var_t mask;
+
+       if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
+               return -ENOMEM;
+
+       raw_spin_lock_irqsave(&desc->lock, flags);
+       if (desc->affinity_hint)
+               cpumask_copy(mask, desc->affinity_hint);
+       raw_spin_unlock_irqrestore(&desc->lock, flags);
+
+       seq_cpumask(m, mask);
+       seq_putc(m, '\n');
+       free_cpumask_var(mask);
+
+       return 0;
+}
+
 #ifndef is_affinity_mask_valid
 #define is_affinity_mask_valid(val) 1
 #endif
@@ -84,6 +105,11 @@ static int irq_affinity_proc_open(struct inode *inode, struct file *file)
        return single_open(file, irq_affinity_proc_show, PDE(inode)->data);
 }
 
+static int irq_affinity_hint_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, irq_affinity_hint_proc_show, PDE(inode)->data);
+}
+
 static const struct file_operations irq_affinity_proc_fops = {
        .open           = irq_affinity_proc_open,
        .read           = seq_read,
@@ -92,6 +118,13 @@ static const struct file_operations irq_affinity_proc_fops = {
        .write          = irq_affinity_proc_write,
 };
 
+static const struct file_operations irq_affinity_hint_proc_fops = {
+       .open           = irq_affinity_hint_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 static int default_affinity_show(struct seq_file *m, void *v)
 {
        seq_cpumask(m, irq_default_affinity);
@@ -147,6 +180,26 @@ static const struct file_operations default_affinity_proc_fops = {
        .release        = single_release,
        .write          = default_affinity_write,
 };
+
+static int irq_node_proc_show(struct seq_file *m, void *v)
+{
+       struct irq_desc *desc = irq_to_desc((long) m->private);
+
+       seq_printf(m, "%d\n", desc->node);
+       return 0;
+}
+
+static int irq_node_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, irq_node_proc_show, PDE(inode)->data);
+}
+
+static const struct file_operations irq_node_proc_fops = {
+       .open           = irq_node_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif
 
 static int irq_spurious_proc_show(struct seq_file *m, void *v)
@@ -231,6 +284,13 @@ void register_irq_proc(unsigned int irq, struct irq_desc *desc)
        /* create /proc/irq/<irq>/smp_affinity */
        proc_create_data("smp_affinity", 0600, desc->dir,
                         &irq_affinity_proc_fops, (void *)(long)irq);
+
+       /* create /proc/irq/<irq>/affinity_hint */
+       proc_create_data("affinity_hint", 0400, desc->dir,
+                        &irq_affinity_hint_proc_fops, (void *)(long)irq);
+
+       proc_create_data("node", 0444, desc->dir,
+                        &irq_node_proc_fops, (void *)(long)irq);
 #endif
 
        proc_create_data("spurious", 0444, desc->dir,
index 0ed46f3..282035f 100644 (file)
@@ -1588,6 +1588,72 @@ static void __kprobes kill_kprobe(struct kprobe *p)
        arch_remove_kprobe(p);
 }
 
+/* Disable one kprobe */
+int __kprobes disable_kprobe(struct kprobe *kp)
+{
+       int ret = 0;
+       struct kprobe *p;
+
+       mutex_lock(&kprobe_mutex);
+
+       /* Check whether specified probe is valid. */
+       p = __get_valid_kprobe(kp);
+       if (unlikely(p == NULL)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       /* If the probe is already disabled (or gone), just return */
+       if (kprobe_disabled(kp))
+               goto out;
+
+       kp->flags |= KPROBE_FLAG_DISABLED;
+       if (p != kp)
+               /* When kp != p, p is always enabled. */
+               try_to_disable_aggr_kprobe(p);
+
+       if (!kprobes_all_disarmed && kprobe_disabled(p))
+               disarm_kprobe(p);
+out:
+       mutex_unlock(&kprobe_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(disable_kprobe);
+
+/* Enable one kprobe */
+int __kprobes enable_kprobe(struct kprobe *kp)
+{
+       int ret = 0;
+       struct kprobe *p;
+
+       mutex_lock(&kprobe_mutex);
+
+       /* Check whether specified probe is valid. */
+       p = __get_valid_kprobe(kp);
+       if (unlikely(p == NULL)) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (kprobe_gone(kp)) {
+               /* This kprobe has gone, we couldn't enable it. */
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (p != kp)
+               kp->flags &= ~KPROBE_FLAG_DISABLED;
+
+       if (!kprobes_all_disarmed && kprobe_disabled(p)) {
+               p->flags &= ~KPROBE_FLAG_DISABLED;
+               arm_kprobe(p);
+       }
+out:
+       mutex_unlock(&kprobe_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(enable_kprobe);
+
 void __kprobes dump_kprobe(struct kprobe *kp)
 {
        printk(KERN_WARNING "Dumping kprobe:\n");
@@ -1805,72 +1871,6 @@ static const struct file_operations debugfs_kprobes_operations = {
        .release        = seq_release,
 };
 
-/* Disable one kprobe */
-int __kprobes disable_kprobe(struct kprobe *kp)
-{
-       int ret = 0;
-       struct kprobe *p;
-
-       mutex_lock(&kprobe_mutex);
-
-       /* Check whether specified probe is valid. */
-       p = __get_valid_kprobe(kp);
-       if (unlikely(p == NULL)) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       /* If the probe is already disabled (or gone), just return */
-       if (kprobe_disabled(kp))
-               goto out;
-
-       kp->flags |= KPROBE_FLAG_DISABLED;
-       if (p != kp)
-               /* When kp != p, p is always enabled. */
-               try_to_disable_aggr_kprobe(p);
-
-       if (!kprobes_all_disarmed && kprobe_disabled(p))
-               disarm_kprobe(p);
-out:
-       mutex_unlock(&kprobe_mutex);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(disable_kprobe);
-
-/* Enable one kprobe */
-int __kprobes enable_kprobe(struct kprobe *kp)
-{
-       int ret = 0;
-       struct kprobe *p;
-
-       mutex_lock(&kprobe_mutex);
-
-       /* Check whether specified probe is valid. */
-       p = __get_valid_kprobe(kp);
-       if (unlikely(p == NULL)) {
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (kprobe_gone(kp)) {
-               /* This kprobe has gone, we couldn't enable it. */
-               ret = -EINVAL;
-               goto out;
-       }
-
-       if (p != kp)
-               kp->flags &= ~KPROBE_FLAG_DISABLED;
-
-       if (!kprobes_all_disarmed && kprobe_disabled(p)) {
-               p->flags &= ~KPROBE_FLAG_DISABLED;
-               arm_kprobe(p);
-       }
-out:
-       mutex_unlock(&kprobe_mutex);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(enable_kprobe);
-
 static void __kprobes arm_all_kprobes(void)
 {
        struct hlist_head *head;
index 2594e1c..ec21304 100644 (file)
@@ -431,20 +431,7 @@ static struct stack_trace lockdep_init_trace = {
 /*
  * Various lockdep statistics:
  */
-atomic_t chain_lookup_hits;
-atomic_t chain_lookup_misses;
-atomic_t hardirqs_on_events;
-atomic_t hardirqs_off_events;
-atomic_t redundant_hardirqs_on;
-atomic_t redundant_hardirqs_off;
-atomic_t softirqs_on_events;
-atomic_t softirqs_off_events;
-atomic_t redundant_softirqs_on;
-atomic_t redundant_softirqs_off;
-atomic_t nr_unused_locks;
-atomic_t nr_cyclic_checks;
-atomic_t nr_find_usage_forwards_checks;
-atomic_t nr_find_usage_backwards_checks;
+DEFINE_PER_CPU(struct lockdep_stats, lockdep_stats);
 #endif
 
 /*
@@ -748,7 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
                return NULL;
        }
        class = lock_classes + nr_lock_classes++;
-       debug_atomic_inc(&nr_unused_locks);
+       debug_atomic_inc(nr_unused_locks);
        class->key = key;
        class->name = lock->name;
        class->subclass = subclass;
@@ -818,7 +805,8 @@ static struct lock_list *alloc_list_entry(void)
  * Add a new dependency to the head of the list:
  */
 static int add_lock_to_list(struct lock_class *class, struct lock_class *this,
-                           struct list_head *head, unsigned long ip, int distance)
+                           struct list_head *head, unsigned long ip,
+                           int distance, struct stack_trace *trace)
 {
        struct lock_list *entry;
        /*
@@ -829,11 +817,9 @@ static int add_lock_to_list(struct lock_class *class, struct lock_class *this,
        if (!entry)
                return 0;
 
-       if (!save_trace(&entry->trace))
-               return 0;
-
        entry->class = this;
        entry->distance = distance;
+       entry->trace = *trace;
        /*
         * Since we never remove from the dependency list, the list can
         * be walked lockless by other CPUs, it's only allocation
@@ -1205,7 +1191,7 @@ check_noncircular(struct lock_list *root, struct lock_class *target,
 {
        int result;
 
-       debug_atomic_inc(&nr_cyclic_checks);
+       debug_atomic_inc(nr_cyclic_checks);
 
        result = __bfs_forwards(root, target, class_equal, target_entry);
 
@@ -1242,7 +1228,7 @@ find_usage_forwards(struct lock_list *root, enum lock_usage_bit bit,
 {
        int result;
 
-       debug_atomic_inc(&nr_find_usage_forwards_checks);
+       debug_atomic_inc(nr_find_usage_forwards_checks);
 
        result = __bfs_forwards(root, (void *)bit, usage_match, target_entry);
 
@@ -1265,7 +1251,7 @@ find_usage_backwards(struct lock_list *root, enum lock_usage_bit bit,
 {
        int result;
 
-       debug_atomic_inc(&nr_find_usage_backwards_checks);
+       debug_atomic_inc(nr_find_usage_backwards_checks);
 
        result = __bfs_backwards(root, (void *)bit, usage_match, target_entry);
 
@@ -1635,12 +1621,20 @@ check_deadlock(struct task_struct *curr, struct held_lock *next,
  */
 static int
 check_prev_add(struct task_struct *curr, struct held_lock *prev,
-              struct held_lock *next, int distance)
+              struct held_lock *next, int distance, int trylock_loop)
 {
        struct lock_list *entry;
        int ret;
        struct lock_list this;
        struct lock_list *uninitialized_var(target_entry);
+       /*
+        * Static variable, serialized by the graph_lock().
+        *
+        * We use this static variable to save the stack trace in case
+        * we call into this function multiple times due to encountering
+        * trylocks in the held lock stack.
+        */
+       static struct stack_trace trace;
 
        /*
         * Prove that the new <prev> -> <next> dependency would not
@@ -1688,20 +1682,23 @@ check_prev_add(struct task_struct *curr, struct held_lock *prev,
                }
        }
 
+       if (!trylock_loop && !save_trace(&trace))
+               return 0;
+
        /*
         * Ok, all validations passed, add the new lock
         * to the previous lock's dependency list:
         */
        ret = add_lock_to_list(hlock_class(prev), hlock_class(next),
                               &hlock_class(prev)->locks_after,
-                              next->acquire_ip, distance);
+                              next->acquire_ip, distance, &trace);
 
        if (!ret)
                return 0;
 
        ret = add_lock_to_list(hlock_class(next), hlock_class(prev),
                               &hlock_class(next)->locks_before,
-                              next->acquire_ip, distance);
+                              next->acquire_ip, distance, &trace);
        if (!ret)
                return 0;
 
@@ -1731,6 +1728,7 @@ static int
 check_prevs_add(struct task_struct *curr, struct held_lock *next)
 {
        int depth = curr->lockdep_depth;
+       int trylock_loop = 0;
        struct held_lock *hlock;
 
        /*
@@ -1756,7 +1754,8 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
                 * added:
                 */
                if (hlock->read != 2) {
-                       if (!check_prev_add(curr, hlock, next, distance))
+                       if (!check_prev_add(curr, hlock, next,
+                                               distance, trylock_loop))
                                return 0;
                        /*
                         * Stop after the first non-trylock entry,
@@ -1779,6 +1778,7 @@ check_prevs_add(struct task_struct *curr, struct held_lock *next)
                if (curr->held_locks[depth].irq_context !=
                                curr->held_locks[depth-1].irq_context)
                        break;
+               trylock_loop = 1;
        }
        return 1;
 out_bug:
@@ -1825,7 +1825,7 @@ static inline int lookup_chain_cache(struct task_struct *curr,
        list_for_each_entry(chain, hash_head, entry) {
                if (chain->chain_key == chain_key) {
 cache_hit:
-                       debug_atomic_inc(&chain_lookup_hits);
+                       debug_atomic_inc(chain_lookup_hits);
                        if (very_verbose(class))
                                printk("\nhash chain already cached, key: "
                                        "%016Lx tail class: [%p] %s\n",
@@ -1890,7 +1890,7 @@ cache_hit:
                chain_hlocks[chain->base + j] = class - lock_classes;
        }
        list_add_tail_rcu(&chain->entry, hash_head);
-       debug_atomic_inc(&chain_lookup_misses);
+       debug_atomic_inc(chain_lookup_misses);
        inc_chains();
 
        return 1;
@@ -2311,7 +2311,12 @@ void trace_hardirqs_on_caller(unsigned long ip)
                return;
 
        if (unlikely(curr->hardirqs_enabled)) {
-               debug_atomic_inc(&redundant_hardirqs_on);
+               /*
+                * Neither irq nor preemption are disabled here
+                * so this is racy by nature but loosing one hit
+                * in a stat is not a big deal.
+                */
+               __debug_atomic_inc(redundant_hardirqs_on);
                return;
        }
        /* we'll do an OFF -> ON transition: */
@@ -2338,7 +2343,7 @@ void trace_hardirqs_on_caller(unsigned long ip)
 
        curr->hardirq_enable_ip = ip;
        curr->hardirq_enable_event = ++curr->irq_events;
-       debug_atomic_inc(&hardirqs_on_events);
+       debug_atomic_inc(hardirqs_on_events);
 }
 EXPORT_SYMBOL(trace_hardirqs_on_caller);
 
@@ -2370,9 +2375,9 @@ void trace_hardirqs_off_caller(unsigned long ip)
                curr->hardirqs_enabled = 0;
                curr->hardirq_disable_ip = ip;
                curr->hardirq_disable_event = ++curr->irq_events;
-               debug_atomic_inc(&hardirqs_off_events);
+               debug_atomic_inc(hardirqs_off_events);
        } else
-               debug_atomic_inc(&redundant_hardirqs_off);
+               debug_atomic_inc(redundant_hardirqs_off);
 }
 EXPORT_SYMBOL(trace_hardirqs_off_caller);
 
@@ -2396,7 +2401,7 @@ void trace_softirqs_on(unsigned long ip)
                return;
 
        if (curr->softirqs_enabled) {
-               debug_atomic_inc(&redundant_softirqs_on);
+               debug_atomic_inc(redundant_softirqs_on);
                return;
        }
 
@@ -2406,7 +2411,7 @@ void trace_softirqs_on(unsigned long ip)
        curr->softirqs_enabled = 1;
        curr->softirq_enable_ip = ip;
        curr->softirq_enable_event = ++curr->irq_events;
-       debug_atomic_inc(&softirqs_on_events);
+       debug_atomic_inc(softirqs_on_events);
        /*
         * We are going to turn softirqs on, so set the
         * usage bit for all held locks, if hardirqs are
@@ -2436,10 +2441,10 @@ void trace_softirqs_off(unsigned long ip)
                curr->softirqs_enabled = 0;
                curr->softirq_disable_ip = ip;
                curr->softirq_disable_event = ++curr->irq_events;
-               debug_atomic_inc(&softirqs_off_events);
+               debug_atomic_inc(softirqs_off_events);
                DEBUG_LOCKS_WARN_ON(!softirq_count());
        } else
-               debug_atomic_inc(&redundant_softirqs_off);
+               debug_atomic_inc(redundant_softirqs_off);
 }
 
 static void __lockdep_trace_alloc(gfp_t gfp_mask, unsigned long flags)
@@ -2644,7 +2649,7 @@ static int mark_lock(struct task_struct *curr, struct held_lock *this,
                        return 0;
                break;
        case LOCK_USED:
-               debug_atomic_dec(&nr_unused_locks);
+               debug_atomic_dec(nr_unused_locks);
                break;
        default:
                if (!debug_locks_off_graph_unlock())
@@ -2750,7 +2755,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
                if (!class)
                        return 0;
        }
-       debug_atomic_inc((atomic_t *)&class->ops);
+       atomic_inc((atomic_t *)&class->ops);
        if (very_verbose(class)) {
                printk("\nacquire class [%p] %s", class->key, class->name);
                if (class->name_version > 1)
@@ -3227,7 +3232,7 @@ void lock_release(struct lockdep_map *lock, int nested,
        raw_local_irq_save(flags);
        check_flags(flags);
        current->lockdep_recursion = 1;
-       trace_lock_release(lock, nested, ip);
+       trace_lock_release(lock, ip);
        __lock_release(lock, nested, ip);
        current->lockdep_recursion = 0;
        raw_local_irq_restore(flags);
@@ -3380,7 +3385,7 @@ found_it:
                hlock->holdtime_stamp = now;
        }
 
-       trace_lock_acquired(lock, ip, waittime);
+       trace_lock_acquired(lock, ip);
 
        stats = get_lock_stats(hlock_class(hlock));
        if (waittime) {
@@ -3801,8 +3806,11 @@ void lockdep_rcu_dereference(const char *file, const int line)
 {
        struct task_struct *curr = current;
 
+#ifndef CONFIG_PROVE_RCU_REPEATEDLY
        if (!debug_locks_off())
                return;
+#endif /* #ifdef CONFIG_PROVE_RCU_REPEATEDLY */
+       /* Note: the following can be executed concurrently, so be careful. */
        printk("\n===================================================\n");
        printk(  "[ INFO: suspicious rcu_dereference_check() usage. ]\n");
        printk(  "---------------------------------------------------\n");
index a2ee95a..4f560cf 100644 (file)
@@ -110,30 +110,60 @@ lockdep_count_backward_deps(struct lock_class *class)
 #endif
 
 #ifdef CONFIG_DEBUG_LOCKDEP
+
+#include <asm/local.h>
 /*
- * Various lockdep statistics:
+ * Various lockdep statistics.
+ * We want them per cpu as they are often accessed in fast path
+ * and we want to avoid too much cache bouncing.
  */
-extern atomic_t chain_lookup_hits;
-extern atomic_t chain_lookup_misses;
-extern atomic_t hardirqs_on_events;
-extern atomic_t hardirqs_off_events;
-extern atomic_t redundant_hardirqs_on;
-extern atomic_t redundant_hardirqs_off;
-extern atomic_t softirqs_on_events;
-extern atomic_t softirqs_off_events;
-extern atomic_t redundant_softirqs_on;
-extern atomic_t redundant_softirqs_off;
-extern atomic_t nr_unused_locks;
-extern atomic_t nr_cyclic_checks;
-extern atomic_t nr_cyclic_check_recursions;
-extern atomic_t nr_find_usage_forwards_checks;
-extern atomic_t nr_find_usage_forwards_recursions;
-extern atomic_t nr_find_usage_backwards_checks;
-extern atomic_t nr_find_usage_backwards_recursions;
-# define debug_atomic_inc(ptr)         atomic_inc(ptr)
-# define debug_atomic_dec(ptr)         atomic_dec(ptr)
-# define debug_atomic_read(ptr)                atomic_read(ptr)
+struct lockdep_stats {
+       int     chain_lookup_hits;
+       int     chain_lookup_misses;
+       int     hardirqs_on_events;
+       int     hardirqs_off_events;
+       int     redundant_hardirqs_on;
+       int     redundant_hardirqs_off;
+       int     softirqs_on_events;
+       int     softirqs_off_events;
+       int     redundant_softirqs_on;
+       int     redundant_softirqs_off;
+       int     nr_unused_locks;
+       int     nr_cyclic_checks;
+       int     nr_cyclic_check_recursions;
+       int     nr_find_usage_forwards_checks;
+       int     nr_find_usage_forwards_recursions;
+       int     nr_find_usage_backwards_checks;
+       int     nr_find_usage_backwards_recursions;
+};
+
+DECLARE_PER_CPU(struct lockdep_stats, lockdep_stats);
+
+#define __debug_atomic_inc(ptr)                                        \
+       this_cpu_inc(lockdep_stats.ptr);
+
+#define debug_atomic_inc(ptr)                  {               \
+       WARN_ON_ONCE(!irqs_disabled());                         \
+       __this_cpu_inc(lockdep_stats.ptr);                      \
+}
+
+#define debug_atomic_dec(ptr)                  {               \
+       WARN_ON_ONCE(!irqs_disabled());                         \
+       __this_cpu_dec(lockdep_stats.ptr);                      \
+}
+
+#define debug_atomic_read(ptr)         ({                              \
+       struct lockdep_stats *__cpu_lockdep_stats;                      \
+       unsigned long long __total = 0;                                 \
+       int __cpu;                                                      \
+       for_each_possible_cpu(__cpu) {                                  \
+               __cpu_lockdep_stats = &per_cpu(lockdep_stats, __cpu);   \
+               __total += __cpu_lockdep_stats->ptr;                    \
+       }                                                               \
+       __total;                                                        \
+})
 #else
+# define __debug_atomic_inc(ptr)       do { } while (0)
 # define debug_atomic_inc(ptr)         do { } while (0)
 # define debug_atomic_dec(ptr)         do { } while (0)
 # define debug_atomic_read(ptr)                0
index d4aba4f..59b76c8 100644 (file)
@@ -184,34 +184,34 @@ static const struct file_operations proc_lockdep_chains_operations = {
 static void lockdep_stats_debug_show(struct seq_file *m)
 {
 #ifdef CONFIG_DEBUG_LOCKDEP
-       unsigned int hi1 = debug_atomic_read(&hardirqs_on_events),
-                    hi2 = debug_atomic_read(&hardirqs_off_events),
-                    hr1 = debug_atomic_read(&redundant_hardirqs_on),
-                    hr2 = debug_atomic_read(&redundant_hardirqs_off),
-                    si1 = debug_atomic_read(&softirqs_on_events),
-                    si2 = debug_atomic_read(&softirqs_off_events),
-                    sr1 = debug_atomic_read(&redundant_softirqs_on),
-                    sr2 = debug_atomic_read(&redundant_softirqs_off);
-
-       seq_printf(m, " chain lookup misses:           %11u\n",
-               debug_atomic_read(&chain_lookup_misses));
-       seq_printf(m, " chain lookup hits:             %11u\n",
-               debug_atomic_read(&chain_lookup_hits));
-       seq_printf(m, " cyclic checks:                 %11u\n",
-               debug_atomic_read(&nr_cyclic_checks));
-       seq_printf(m, " find-mask forwards checks:     %11u\n",
-               debug_atomic_read(&nr_find_usage_forwards_checks));
-       seq_printf(m, " find-mask backwards checks:    %11u\n",
-               debug_atomic_read(&nr_find_usage_backwards_checks));
-
-       seq_printf(m, " hardirq on events:             %11u\n", hi1);
-       seq_printf(m, " hardirq off events:            %11u\n", hi2);
-       seq_printf(m, " redundant hardirq ons:         %11u\n", hr1);
-       seq_printf(m, " redundant hardirq offs:        %11u\n", hr2);
-       seq_printf(m, " softirq on events:             %11u\n", si1);
-       seq_printf(m, " softirq off events:            %11u\n", si2);
-       seq_printf(m, " redundant softirq ons:         %11u\n", sr1);
-       seq_printf(m, " redundant softirq offs:        %11u\n", sr2);
+       unsigned long long hi1 = debug_atomic_read(hardirqs_on_events),
+                          hi2 = debug_atomic_read(hardirqs_off_events),
+                          hr1 = debug_atomic_read(redundant_hardirqs_on),
+                          hr2 = debug_atomic_read(redundant_hardirqs_off),
+                          si1 = debug_atomic_read(softirqs_on_events),
+                          si2 = debug_atomic_read(softirqs_off_events),
+                          sr1 = debug_atomic_read(redundant_softirqs_on),
+                          sr2 = debug_atomic_read(redundant_softirqs_off);
+
+       seq_printf(m, " chain lookup misses:           %11llu\n",
+               debug_atomic_read(chain_lookup_misses));
+       seq_printf(m, " chain lookup hits:             %11llu\n",
+               debug_atomic_read(chain_lookup_hits));
+       seq_printf(m, " cyclic checks:                 %11llu\n",
+               debug_atomic_read(nr_cyclic_checks));
+       seq_printf(m, " find-mask forwards checks:     %11llu\n",
+               debug_atomic_read(nr_find_usage_forwards_checks));
+       seq_printf(m, " find-mask backwards checks:    %11llu\n",
+               debug_atomic_read(nr_find_usage_backwards_checks));
+
+       seq_printf(m, " hardirq on events:             %11llu\n", hi1);
+       seq_printf(m, " hardirq off events:            %11llu\n", hi2);
+       seq_printf(m, " redundant hardirq ons:         %11llu\n", hr1);
+       seq_printf(m, " redundant hardirq offs:        %11llu\n", hr2);
+       seq_printf(m, " softirq on events:             %11llu\n", si1);
+       seq_printf(m, " softirq off events:            %11llu\n", si2);
+       seq_printf(m, " redundant softirq ons:         %11llu\n", sr1);
+       seq_printf(m, " redundant softirq offs:        %11llu\n", sr2);
 #endif
 }
 
@@ -263,7 +263,7 @@ static int lockdep_stats_show(struct seq_file *m, void *v)
 #endif
        }
 #ifdef CONFIG_DEBUG_LOCKDEP
-       DEBUG_LOCKS_WARN_ON(debug_atomic_read(&nr_unused_locks) != nr_unused);
+       DEBUG_LOCKS_WARN_ON(debug_atomic_read(nr_unused_locks) != nr_unused);
 #endif
        seq_printf(m, " lock-classes:                  %11lu [max: %lu]\n",
                        nr_lock_classes, MAX_LOCKDEP_KEYS);
index 1016b75..e256458 100644 (file)
@@ -59,8 +59,6 @@
 #define CREATE_TRACE_POINTS
 #include <trace/events/module.h>
 
-EXPORT_TRACEPOINT_SYMBOL(module_get);
-
 #if 0
 #define DEBUGP printk
 #else
@@ -515,6 +513,9 @@ MODINFO_ATTR(srcversion);
 static char last_unloaded_module[MODULE_NAME_LEN+1];
 
 #ifdef CONFIG_MODULE_UNLOAD
+
+EXPORT_TRACEPOINT_SYMBOL(module_get);
+
 /* Init the unload section of the module. */
 static void module_unload_init(struct module *mod)
 {
@@ -723,16 +724,8 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
                return -EFAULT;
        name[MODULE_NAME_LEN-1] = '\0';
 
-       /* Create stop_machine threads since free_module relies on
-        * a non-failing stop_machine call. */
-       ret = stop_machine_create();
-       if (ret)
-               return ret;
-
-       if (mutex_lock_interruptible(&module_mutex) != 0) {
-               ret = -EINTR;
-               goto out_stop;
-       }
+       if (mutex_lock_interruptible(&module_mutex) != 0)
+               return -EINTR;
 
        mod = find_module(name);
        if (!mod) {
@@ -792,8 +785,6 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
 
  out:
        mutex_unlock(&module_mutex);
-out_stop:
-       stop_machine_destroy();
        return ret;
 }
 
@@ -867,8 +858,7 @@ void module_put(struct module *module)
                smp_wmb(); /* see comment in module_refcount */
                __this_cpu_inc(module->refptr->decs);
 
-               trace_module_put(module, _RET_IP_,
-                                __this_cpu_read(module->refptr->decs));
+               trace_module_put(module, _RET_IP_);
                /* Maybe they're waiting for us to drop reference? */
                if (unlikely(!module_is_live(module)))
                        wake_up_process(module->waiter);
index 3d1552d..a4fa381 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/file.h>
 #include <linux/poll.h>
 #include <linux/slab.h>
+#include <linux/hash.h>
 #include <linux/sysfs.h>
 #include <linux/dcache.h>
 #include <linux/percpu.h>
@@ -82,14 +83,6 @@ extern __weak const struct pmu *hw_perf_event_init(struct perf_event *event)
 void __weak hw_perf_disable(void)              { barrier(); }
 void __weak hw_perf_enable(void)               { barrier(); }
 
-int __weak
-hw_perf_group_sched_in(struct perf_event *group_leader,
-              struct perf_cpu_context *cpuctx,
-              struct perf_event_context *ctx)
-{
-       return 0;
-}
-
 void __weak perf_event_print_debug(void)       { }
 
 static DEFINE_PER_CPU(int, perf_disable_count);
@@ -262,6 +255,18 @@ static void update_event_times(struct perf_event *event)
        event->total_time_running = run_end - event->tstamp_running;
 }
 
+/*
+ * Update total_time_enabled and total_time_running for all events in a group.
+ */
+static void update_group_times(struct perf_event *leader)
+{
+       struct perf_event *event;
+
+       update_event_times(leader);
+       list_for_each_entry(event, &leader->sibling_list, group_entry)
+               update_event_times(event);
+}
+
 static struct list_head *
 ctx_group_list(struct perf_event *event, struct perf_event_context *ctx)
 {
@@ -315,8 +320,6 @@ list_add_event(struct perf_event *event, struct perf_event_context *ctx)
 static void
 list_del_event(struct perf_event *event, struct perf_event_context *ctx)
 {
-       struct perf_event *sibling, *tmp;
-
        if (list_empty(&event->group_entry))
                return;
        ctx->nr_events--;
@@ -329,7 +332,7 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
        if (event->group_leader != event)
                event->group_leader->nr_siblings--;
 
-       update_event_times(event);
+       update_group_times(event);
 
        /*
         * If event was in error state, then keep it
@@ -340,6 +343,12 @@ list_del_event(struct perf_event *event, struct perf_event_context *ctx)
         */
        if (event->state > PERF_EVENT_STATE_OFF)
                event->state = PERF_EVENT_STATE_OFF;
+}
+
+static void
+perf_destroy_group(struct perf_event *event, struct perf_event_context *ctx)
+{
+       struct perf_event *sibling, *tmp;
 
        /*
         * If this was a group event with sibling events then
@@ -504,18 +513,6 @@ retry:
        raw_spin_unlock_irq(&ctx->lock);
 }
 
-/*
- * Update total_time_enabled and total_time_running for all events in a group.
- */
-static void update_group_times(struct perf_event *leader)
-{
-       struct perf_event *event;
-
-       update_event_times(leader);
-       list_for_each_entry(event, &leader->sibling_list, group_entry)
-               update_event_times(event);
-}
-
 /*
  * Cross CPU call to disable a performance event
  */
@@ -640,15 +637,20 @@ group_sched_in(struct perf_event *group_event,
               struct perf_cpu_context *cpuctx,
               struct perf_event_context *ctx)
 {
-       struct perf_event *event, *partial_group;
+       struct perf_event *event, *partial_group = NULL;
+       const struct pmu *pmu = group_event->pmu;
+       bool txn = false;
        int ret;
 
        if (group_event->state == PERF_EVENT_STATE_OFF)
                return 0;
 
-       ret = hw_perf_group_sched_in(group_event, cpuctx, ctx);
-       if (ret)
-               return ret < 0 ? ret : 0;
+       /* Check if group transaction availabe */
+       if (pmu->start_txn)
+               txn = true;
+
+       if (txn)
+               pmu->start_txn(pmu);
 
        if (event_sched_in(group_event, cpuctx, ctx))
                return -EAGAIN;
@@ -663,9 +665,19 @@ group_sched_in(struct perf_event *group_event,
                }
        }
 
-       return 0;
+       if (!txn)
+               return 0;
+
+       ret = pmu->commit_txn(pmu);
+       if (!ret) {
+               pmu->cancel_txn(pmu);
+               return 0;
+       }
 
 group_error:
+       if (txn)
+               pmu->cancel_txn(pmu);
+
        /*
         * Groups can be scheduled in as one unit only, so undo any
         * partial group before returning:
@@ -1367,6 +1379,8 @@ void perf_event_task_sched_in(struct task_struct *task)
        if (cpuctx->task_ctx == ctx)
                return;
 
+       perf_disable();
+
        /*
         * We want to keep the following priority order:
         * cpu pinned (that don't need to move), task pinned,
@@ -1379,6 +1393,8 @@ void perf_event_task_sched_in(struct task_struct *task)
        ctx_sched_in(ctx, cpuctx, EVENT_FLEXIBLE);
 
        cpuctx->task_ctx = ctx;
+
+       perf_enable();
 }
 
 #define MAX_INTERRUPTS (~0ULL)
@@ -1856,9 +1872,30 @@ int perf_event_release_kernel(struct perf_event *event)
 {
        struct perf_event_context *ctx = event->ctx;
 
+       /*
+        * Remove from the PMU, can't get re-enabled since we got
+        * here because the last ref went.
+        */
+       perf_event_disable(event);
+
        WARN_ON_ONCE(ctx->parent_ctx);
-       mutex_lock(&ctx->mutex);
-       perf_event_remove_from_context(event);
+       /*
+        * There are two ways this annotation is useful:
+        *
+        *  1) there is a lock recursion from perf_event_exit_task
+        *     see the comment there.
+        *
+        *  2) there is a lock-inversion with mmap_sem through
+        *     perf_event_read_group(), which takes faults while
+        *     holding ctx->mutex, however this is called after
+        *     the last filedesc died, so there is no possibility
+        *     to trigger the AB-BA case.
+        */
+       mutex_lock_nested(&ctx->mutex, SINGLE_DEPTH_NESTING);
+       raw_spin_lock_irq(&ctx->lock);
+       list_del_event(event, ctx);
+       perf_destroy_group(event, ctx);
+       raw_spin_unlock_irq(&ctx->lock);
        mutex_unlock(&ctx->mutex);
 
        mutex_lock(&event->owner->perf_event_mutex);
@@ -2642,6 +2679,7 @@ static int perf_fasync(int fd, struct file *filp, int on)
 }
 
 static const struct file_operations perf_fops = {
+       .llseek                 = no_llseek,
        .release                = perf_release,
        .read                   = perf_read,
        .poll                   = perf_poll,
@@ -2791,6 +2829,27 @@ void perf_arch_fetch_caller_regs(struct pt_regs *regs, unsigned long ip, int ski
 }
 
 
+/*
+ * We assume there is only KVM supporting the callbacks.
+ * Later on, we might change it to a list if there is
+ * another virtualization implementation supporting the callbacks.
+ */
+struct perf_guest_info_callbacks *perf_guest_cbs;
+
+int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+       perf_guest_cbs = cbs;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(perf_register_guest_info_callbacks);
+
+int perf_unregister_guest_info_callbacks(struct perf_guest_info_callbacks *cbs)
+{
+       perf_guest_cbs = NULL;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(perf_unregister_guest_info_callbacks);
+
 /*
  * Output
  */
@@ -3743,7 +3802,7 @@ void __perf_event_mmap(struct vm_area_struct *vma)
                .event_id  = {
                        .header = {
                                .type = PERF_RECORD_MMAP,
-                               .misc = 0,
+                               .misc = PERF_RECORD_MISC_USER,
                                /* .size */
                        },
                        /* .pid */
@@ -3961,36 +4020,6 @@ static void perf_swevent_add(struct perf_event *event, u64 nr,
        perf_swevent_overflow(event, 0, nmi, data, regs);
 }
 
-static int perf_swevent_is_counting(struct perf_event *event)
-{
-       /*
-        * The event is active, we're good!
-        */
-       if (event->state == PERF_EVENT_STATE_ACTIVE)
-               return 1;
-
-       /*
-        * The event is off/error, not counting.
-        */
-       if (event->state != PERF_EVENT_STATE_INACTIVE)
-               return 0;
-
-       /*
-        * The event is inactive, if the context is active
-        * we're part of a group that didn't make it on the 'pmu',
-        * not counting.
-        */
-       if (event->ctx->is_active)
-               return 0;
-
-       /*
-        * We're inactive and the context is too, this means the
-        * task is scheduled out, we're counting events that happen
-        * to us, like migration events.
-        */
-       return 1;
-}
-
 static int perf_tp_event_match(struct perf_event *event,
                                struct perf_sample_data *data);
 
@@ -4014,12 +4043,6 @@ static int perf_swevent_match(struct perf_event *event,
                                struct perf_sample_data *data,
                                struct pt_regs *regs)
 {
-       if (event->cpu != -1 && event->cpu != smp_processor_id())
-               return 0;
-
-       if (!perf_swevent_is_counting(event))
-               return 0;
-
        if (event->attr.type != type)
                return 0;
 
@@ -4036,18 +4059,53 @@ static int perf_swevent_match(struct perf_event *event,
        return 1;
 }
 
-static void perf_swevent_ctx_event(struct perf_event_context *ctx,
-                                    enum perf_type_id type,
-                                    u32 event_id, u64 nr, int nmi,
-                                    struct perf_sample_data *data,
-                                    struct pt_regs *regs)
+static inline u64 swevent_hash(u64 type, u32 event_id)
 {
+       u64 val = event_id | (type << 32);
+
+       return hash_64(val, SWEVENT_HLIST_BITS);
+}
+
+static struct hlist_head *
+find_swevent_head(struct perf_cpu_context *ctx, u64 type, u32 event_id)
+{
+       u64 hash;
+       struct swevent_hlist *hlist;
+
+       hash = swevent_hash(type, event_id);
+
+       hlist = rcu_dereference(ctx->swevent_hlist);
+       if (!hlist)
+               return NULL;
+
+       return &hlist->heads[hash];
+}
+
+static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
+                                   u64 nr, int nmi,
+                                   struct perf_sample_data *data,
+                                   struct pt_regs *regs)
+{
+       struct perf_cpu_context *cpuctx;
        struct perf_event *event;
+       struct hlist_node *node;
+       struct hlist_head *head;
 
-       list_for_each_entry_rcu(event, &ctx->event_list, event_entry) {
+       cpuctx = &__get_cpu_var(perf_cpu_context);
+
+       rcu_read_lock();
+
+       head = find_swevent_head(cpuctx, type, event_id);
+
+       if (!head)
+               goto end;
+
+       hlist_for_each_entry_rcu(event, node, head, hlist_entry) {
                if (perf_swevent_match(event, type, event_id, data, regs))
                        perf_swevent_add(event, nr, nmi, data, regs);
        }
+end:
+       rcu_read_unlock();
 }
 
 int perf_swevent_get_recursion_context(void)
@@ -4085,27 +4143,6 @@ void perf_swevent_put_recursion_context(int rctx)
 }
 EXPORT_SYMBOL_GPL(perf_swevent_put_recursion_context);
 
-static void do_perf_sw_event(enum perf_type_id type, u32 event_id,
-                                   u64 nr, int nmi,
-                                   struct perf_sample_data *data,
-                                   struct pt_regs *regs)
-{
-       struct perf_cpu_context *cpuctx;
-       struct perf_event_context *ctx;
-
-       cpuctx = &__get_cpu_var(perf_cpu_context);
-       rcu_read_lock();
-       perf_swevent_ctx_event(&cpuctx->ctx, type, event_id,
-                                nr, nmi, data, regs);
-       /*
-        * doesn't really matter which of the child contexts the
-        * events ends up in.
-        */
-       ctx = rcu_dereference(current->perf_event_ctxp);
-       if (ctx)
-               perf_swevent_ctx_event(ctx, type, event_id, nr, nmi, data, regs);
-       rcu_read_unlock();
-}
 
 void __perf_sw_event(u32 event_id, u64 nr, int nmi,
                            struct pt_regs *regs, u64 addr)
@@ -4131,16 +4168,28 @@ static void perf_swevent_read(struct perf_event *event)
 static int perf_swevent_enable(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
+       struct perf_cpu_context *cpuctx;
+       struct hlist_head *head;
+
+       cpuctx = &__get_cpu_var(perf_cpu_context);
 
        if (hwc->sample_period) {
                hwc->last_period = hwc->sample_period;
                perf_swevent_set_period(event);
        }
+
+       head = find_swevent_head(cpuctx, event->attr.type, event->attr.config);
+       if (WARN_ON_ONCE(!head))
+               return -EINVAL;
+
+       hlist_add_head_rcu(&event->hlist_entry, head);
+
        return 0;
 }
 
 static void perf_swevent_disable(struct perf_event *event)
 {
+       hlist_del_rcu(&event->hlist_entry);
 }
 
 static const struct pmu perf_ops_generic = {
@@ -4168,15 +4217,8 @@ static enum hrtimer_restart perf_swevent_hrtimer(struct hrtimer *hrtimer)
        perf_sample_data_init(&data, 0);
        data.period = event->hw.last_period;
        regs = get_irq_regs();
-       /*
-        * In case we exclude kernel IPs or are somehow not in interrupt
-        * context, provide the next best thing, the user IP.
-        */
-       if ((event->attr.exclude_kernel || !regs) &&
-                       !event->attr.exclude_user)
-               regs = task_pt_regs(current);
 
-       if (regs) {
+       if (regs && !perf_exclude_event(event, regs)) {
                if (!(event->attr.exclude_idle && current->pid == 0))
                        if (perf_event_overflow(event, 0, &data, regs))
                                ret = HRTIMER_NORESTART;
@@ -4324,6 +4366,105 @@ static const struct pmu perf_ops_task_clock = {
        .read           = task_clock_perf_event_read,
 };
 
+static void swevent_hlist_release_rcu(struct rcu_head *rcu_head)
+{
+       struct swevent_hlist *hlist;
+
+       hlist = container_of(rcu_head, struct swevent_hlist, rcu_head);
+       kfree(hlist);
+}
+
+static void swevent_hlist_release(struct perf_cpu_context *cpuctx)
+{
+       struct swevent_hlist *hlist;
+
+       if (!cpuctx->swevent_hlist)
+               return;
+
+       hlist = cpuctx->swevent_hlist;
+       rcu_assign_pointer(cpuctx->swevent_hlist, NULL);
+       call_rcu(&hlist->rcu_head, swevent_hlist_release_rcu);
+}
+
+static void swevent_hlist_put_cpu(struct perf_event *event, int cpu)
+{
+       struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
+
+       mutex_lock(&cpuctx->hlist_mutex);
+
+       if (!--cpuctx->hlist_refcount)
+               swevent_hlist_release(cpuctx);
+
+       mutex_unlock(&cpuctx->hlist_mutex);
+}
+
+static void swevent_hlist_put(struct perf_event *event)
+{
+       int cpu;
+
+       if (event->cpu != -1) {
+               swevent_hlist_put_cpu(event, event->cpu);
+               return;
+       }
+
+       for_each_possible_cpu(cpu)
+               swevent_hlist_put_cpu(event, cpu);
+}
+
+static int swevent_hlist_get_cpu(struct perf_event *event, int cpu)
+{
+       struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
+       int err = 0;
+
+       mutex_lock(&cpuctx->hlist_mutex);
+
+       if (!cpuctx->swevent_hlist && cpu_online(cpu)) {
+               struct swevent_hlist *hlist;
+
+               hlist = kzalloc(sizeof(*hlist), GFP_KERNEL);
+               if (!hlist) {
+                       err = -ENOMEM;
+                       goto exit;
+               }
+               rcu_assign_pointer(cpuctx->swevent_hlist, hlist);
+       }
+       cpuctx->hlist_refcount++;
+ exit:
+       mutex_unlock(&cpuctx->hlist_mutex);
+
+       return err;
+}
+
+static int swevent_hlist_get(struct perf_event *event)
+{
+       int err;
+       int cpu, failed_cpu;
+
+       if (event->cpu != -1)
+               return swevent_hlist_get_cpu(event, event->cpu);
+
+       get_online_cpus();
+       for_each_possible_cpu(cpu) {
+               err = swevent_hlist_get_cpu(event, cpu);
+               if (err) {
+                       failed_cpu = cpu;
+                       goto fail;
+               }
+       }
+       put_online_cpus();
+
+       return 0;
+ fail:
+       for_each_possible_cpu(cpu) {
+               if (cpu == failed_cpu)
+                       break;
+               swevent_hlist_put_cpu(event, cpu);
+       }
+
+       put_online_cpus();
+       return err;
+}
+
 #ifdef CONFIG_EVENT_TRACING
 
 void perf_tp_event(int event_id, u64 addr, u64 count, void *record,
@@ -4357,10 +4498,13 @@ static int perf_tp_event_match(struct perf_event *event,
 static void tp_perf_event_destroy(struct perf_event *event)
 {
        perf_trace_disable(event->attr.config);
+       swevent_hlist_put(event);
 }
 
 static const struct pmu *tp_perf_event_init(struct perf_event *event)
 {
+       int err;
+
        /*
         * Raw tracepoint data is a severe data leak, only allow root to
         * have these.
@@ -4374,6 +4518,11 @@ static const struct pmu *tp_perf_event_init(struct perf_event *event)
                return NULL;
 
        event->destroy = tp_perf_event_destroy;
+       err = swevent_hlist_get(event);
+       if (err) {
+               perf_trace_disable(event->attr.config);
+               return ERR_PTR(err);
+       }
 
        return &perf_ops_generic;
 }
@@ -4474,6 +4623,7 @@ static void sw_perf_event_destroy(struct perf_event *event)
        WARN_ON(event->parent);
 
        atomic_dec(&perf_swevent_enabled[event_id]);
+       swevent_hlist_put(event);
 }
 
 static const struct pmu *sw_perf_event_init(struct perf_event *event)
@@ -4512,6 +4662,12 @@ static const struct pmu *sw_perf_event_init(struct perf_event *event)
        case PERF_COUNT_SW_ALIGNMENT_FAULTS:
        case PERF_COUNT_SW_EMULATION_FAULTS:
                if (!event->parent) {
+                       int err;
+
+                       err = swevent_hlist_get(event);
+                       if (err)
+                               return ERR_PTR(err);
+
                        atomic_inc(&perf_swevent_enabled[event_id]);
                        event->destroy = sw_perf_event_destroy;
                }
@@ -5176,7 +5332,7 @@ void perf_event_exit_task(struct task_struct *child)
         *
         * But since its the parent context it won't be the same instance.
         */
-       mutex_lock_nested(&child_ctx->mutex, SINGLE_DEPTH_NESTING);
+       mutex_lock(&child_ctx->mutex);
 
 again:
        list_for_each_entry_safe(child_event, tmp, &child_ctx->pinned_groups,
@@ -5384,6 +5540,7 @@ static void __init perf_event_init_all_cpus(void)
 
        for_each_possible_cpu(cpu) {
                cpuctx = &per_cpu(perf_cpu_context, cpu);
+               mutex_init(&cpuctx->hlist_mutex);
                __perf_event_init_context(&cpuctx->ctx, NULL);
        }
 }
@@ -5397,6 +5554,16 @@ static void __cpuinit perf_event_init_cpu(int cpu)
        spin_lock(&perf_resource_lock);
        cpuctx->max_pertask = perf_max_events - perf_reserved_percpu;
        spin_unlock(&perf_resource_lock);
+
+       mutex_lock(&cpuctx->hlist_mutex);
+       if (cpuctx->hlist_refcount > 0) {
+               struct swevent_hlist *hlist;
+
+               hlist = kzalloc(sizeof(*hlist), GFP_KERNEL);
+               WARN_ON_ONCE(!hlist);
+               rcu_assign_pointer(cpuctx->swevent_hlist, hlist);
+       }
+       mutex_unlock(&cpuctx->hlist_mutex);
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
@@ -5416,6 +5583,10 @@ static void perf_event_exit_cpu(int cpu)
        struct perf_cpu_context *cpuctx = &per_cpu(perf_cpu_context, cpu);
        struct perf_event_context *ctx = &cpuctx->ctx;
 
+       mutex_lock(&cpuctx->hlist_mutex);
+       swevent_hlist_release(cpuctx);
+       mutex_unlock(&cpuctx->hlist_mutex);
+
        mutex_lock(&ctx->mutex);
        smp_call_function_single(cpu, __perf_event_exit_cpu, NULL, 1);
        mutex_unlock(&ctx->mutex);
index 3db49b9..f42d3f7 100644 (file)
@@ -2,7 +2,7 @@
  * This module exposes the interface to kernel space for specifying
  * QoS dependencies.  It provides infrastructure for registration of:
  *
- * Dependents on a QoS value : register requirements
+ * Dependents on a QoS value : register requests
  * Watchers of QoS value : get notified when target QoS value changes
  *
  * This QoS design is best effort based.  Dependents register their QoS needs.
  * timeout: usec <-- currently not used.
  * throughput: kbs (kilo byte / sec)
  *
- * There are lists of pm_qos_objects each one wrapping requirements, notifiers
+ * There are lists of pm_qos_objects each one wrapping requests, notifiers
  *
- * User mode requirements on a QOS parameter register themselves to the
+ * User mode requests on a QOS parameter register themselves to the
  * subsystem by opening the device node /dev/... and writing there request to
  * the node.  As long as the process holds a file handle open to the node the
  * client continues to be accounted for.  Upon file release the usermode
- * requirement is removed and a new qos target is computed.  This way when the
- * requirement that the application has is cleaned up when closes the file
+ * request is removed and a new qos target is computed.  This way when the
+ * request that the application has is cleaned up when closes the file
  * pointer or exits the pm_qos_object will get an opportunity to clean up.
  *
  * Mark Gross <mgross@linux.intel.com>
  */
 
+/*#define DEBUG*/
+
 #include <linux/pm_qos_params.h>
 #include <linux/sched.h>
 #include <linux/spinlock.h>
 #include <linux/uaccess.h>
 
 /*
- * locking rule: all changes to requirements or notifiers lists
+ * locking rule: all changes to requests or notifiers lists
  * or pm_qos_object list and pm_qos_objects need to happen with pm_qos_lock
  * held, taken with _irqsave.  One lock to rule them all
  */
-struct requirement_list {
+struct pm_qos_request_list {
        struct list_head list;
        union {
                s32 value;
                s32 usec;
                s32 kbps;
        };
-       char *name;
+       int pm_qos_class;
 };
 
 static s32 max_compare(s32 v1, s32 v2);
 static s32 min_compare(s32 v1, s32 v2);
 
 struct pm_qos_object {
-       struct requirement_list requirements;
+       struct pm_qos_request_list requests;
        struct blocking_notifier_head *notifiers;
        struct miscdevice pm_qos_power_miscdev;
        char *name;
@@ -72,7 +74,7 @@ struct pm_qos_object {
 static struct pm_qos_object null_pm_qos;
 static BLOCKING_NOTIFIER_HEAD(cpu_dma_lat_notifier);
 static struct pm_qos_object cpu_dma_pm_qos = {
-       .requirements = {LIST_HEAD_INIT(cpu_dma_pm_qos.requirements.list)},
+       .requests = {LIST_HEAD_INIT(cpu_dma_pm_qos.requests.list)},
        .notifiers = &cpu_dma_lat_notifier,
        .name = "cpu_dma_latency",
        .default_value = 2000 * USEC_PER_SEC,
@@ -82,7 +84,7 @@ static struct pm_qos_object cpu_dma_pm_qos = {
 
 static BLOCKING_NOTIFIER_HEAD(network_lat_notifier);
 static struct pm_qos_object network_lat_pm_qos = {
-       .requirements = {LIST_HEAD_INIT(network_lat_pm_qos.requirements.list)},
+       .requests = {LIST_HEAD_INIT(network_lat_pm_qos.requests.list)},
        .notifiers = &network_lat_notifier,
        .name = "network_latency",
        .default_value = 2000 * USEC_PER_SEC,
@@ -93,8 +95,7 @@ static struct pm_qos_object network_lat_pm_qos = {
 
 static BLOCKING_NOTIFIER_HEAD(network_throughput_notifier);
 static struct pm_qos_object network_throughput_pm_qos = {
-       .requirements =
-               {LIST_HEAD_INIT(network_throughput_pm_qos.requirements.list)},
+       .requests = {LIST_HEAD_INIT(network_throughput_pm_qos.requests.list)},
        .notifiers = &network_throughput_notifier,
        .name = "network_throughput",
        .default_value = 0,
@@ -135,31 +136,34 @@ static s32 min_compare(s32 v1, s32 v2)
 }
 
 
-static void update_target(int target)
+static void update_target(int pm_qos_class)
 {
        s32 extreme_value;
-       struct requirement_list *node;
+       struct pm_qos_request_list *node;
        unsigned long flags;
        int call_notifier = 0;
 
        spin_lock_irqsave(&pm_qos_lock, flags);
-       extreme_value = pm_qos_array[target]->default_value;
+       extreme_value = pm_qos_array[pm_qos_class]->default_value;
        list_for_each_entry(node,
-                       &pm_qos_array[target]->requirements.list, list) {
-               extreme_value = pm_qos_array[target]->comparitor(
+                       &pm_qos_array[pm_qos_class]->requests.list, list) {
+               extreme_value = pm_qos_array[pm_qos_class]->comparitor(
                                extreme_value, node->value);
        }
-       if (atomic_read(&pm_qos_array[target]->target_value) != extreme_value) {
+       if (atomic_read(&pm_qos_array[pm_qos_class]->target_value) !=
+                       extreme_value) {
                call_notifier = 1;
-               atomic_set(&pm_qos_array[target]->target_value, extreme_value);
-               pr_debug(KERN_ERR "new target for qos %d is %d\n", target,
-                       atomic_read(&pm_qos_array[target]->target_value));
+               atomic_set(&pm_qos_array[pm_qos_class]->target_value,
+                               extreme_value);
+               pr_debug(KERN_ERR "new target for qos %d is %d\n", pm_qos_class,
+                       atomic_read(&pm_qos_array[pm_qos_class]->target_value));
        }
        spin_unlock_irqrestore(&pm_qos_lock, flags);
 
        if (call_notifier)
-               blocking_notifier_call_chain(pm_qos_array[target]->notifiers,
-                       (unsigned long) extreme_value, NULL);
+               blocking_notifier_call_chain(
+                               pm_qos_array[pm_qos_class]->notifiers,
+                                       (unsigned long) extreme_value, NULL);
 }
 
 static int register_pm_qos_misc(struct pm_qos_object *qos)
@@ -185,125 +189,112 @@ static int find_pm_qos_object_by_minor(int minor)
 }
 
 /**
- * pm_qos_requirement - returns current system wide qos expectation
+ * pm_qos_request - returns current system wide qos expectation
  * @pm_qos_class: identification of which qos value is requested
  *
  * This function returns the current target value in an atomic manner.
  */
-int pm_qos_requirement(int pm_qos_class)
+int pm_qos_request(int pm_qos_class)
 {
        return atomic_read(&pm_qos_array[pm_qos_class]->target_value);
 }
-EXPORT_SYMBOL_GPL(pm_qos_requirement);
+EXPORT_SYMBOL_GPL(pm_qos_request);
 
 /**
- * pm_qos_add_requirement - inserts new qos request into the list
+ * pm_qos_add_request - inserts new qos request into the list
  * @pm_qos_class: identifies which list of qos request to us
- * @name: identifies the request
  * @value: defines the qos request
  *
  * This function inserts a new entry in the pm_qos_class list of requested qos
  * performance characteristics.  It recomputes the aggregate QoS expectations
- * for the pm_qos_class of parameters.
+ * for the pm_qos_class of parameters, and returns the pm_qos_request list
+ * element as a handle for use in updating and removal.  Call needs to save
+ * this handle for later use.
  */
-int pm_qos_add_requirement(int pm_qos_class, char *name, s32 value)
+struct pm_qos_request_list *pm_qos_add_request(int pm_qos_class, s32 value)
 {
-       struct requirement_list *dep;
+       struct pm_qos_request_list *dep;
        unsigned long flags;
 
-       dep = kzalloc(sizeof(struct requirement_list), GFP_KERNEL);
+       dep = kzalloc(sizeof(struct pm_qos_request_list), GFP_KERNEL);
        if (dep) {
                if (value == PM_QOS_DEFAULT_VALUE)
                        dep->value = pm_qos_array[pm_qos_class]->default_value;
                else
                        dep->value = value;
-               dep->name = kstrdup(name, GFP_KERNEL);
-               if (!dep->name)
-                       goto cleanup;
+               dep->pm_qos_class = pm_qos_class;
 
                spin_lock_irqsave(&pm_qos_lock, flags);
                list_add(&dep->list,
-                       &pm_qos_array[pm_qos_class]->requirements.list);
+                       &pm_qos_array[pm_qos_class]->requests.list);
                spin_unlock_irqrestore(&pm_qos_lock, flags);
                update_target(pm_qos_class);
-
-               return 0;
        }
 
-cleanup:
-       kfree(dep);
-       return -ENOMEM;
+       return dep;
 }
-EXPORT_SYMBOL_GPL(pm_qos_add_requirement);
+EXPORT_SYMBOL_GPL(pm_qos_add_request);
 
 /**
- * pm_qos_update_requirement - modifies an existing qos request
- * @pm_qos_class: identifies which list of qos request to us
- * @name: identifies the request
+ * pm_qos_update_request - modifies an existing qos request
+ * @pm_qos_req : handle to list element holding a pm_qos request to use
  * @value: defines the qos request
  *
- * Updates an existing qos requirement for the pm_qos_class of parameters along
+ * Updates an existing qos request for the pm_qos_class of parameters along
  * with updating the target pm_qos_class value.
  *
- * If the named request isn't in the list then no change is made.
+ * Attempts are made to make this code callable on hot code paths.
  */
-int pm_qos_update_requirement(int pm_qos_class, char *name, s32 new_value)
+void pm_qos_update_request(struct pm_qos_request_list *pm_qos_req,
+               s32 new_value)
 {
        unsigned long flags;
-       struct requirement_list *node;
        int pending_update = 0;
+       s32 temp;
 
-       spin_lock_irqsave(&pm_qos_lock, flags);
-       list_for_each_entry(node,
-               &pm_qos_array[pm_qos_class]->requirements.list, list) {
-               if (strcmp(node->name, name) == 0) {
-                       if (new_value == PM_QOS_DEFAULT_VALUE)
-                               node->value =
-                               pm_qos_array[pm_qos_class]->default_value;
-                       else
-                               node->value = new_value;
+       if (pm_qos_req) { /*guard against callers passing in null */
+               spin_lock_irqsave(&pm_qos_lock, flags);
+               if (new_value == PM_QOS_DEFAULT_VALUE)
+                       temp = pm_qos_array[pm_qos_req->pm_qos_class]->default_value;
+               else
+                       temp = new_value;
+
+               if (temp != pm_qos_req->value) {
                        pending_update = 1;
-                       break;
+                       pm_qos_req->value = temp;
                }
+               spin_unlock_irqrestore(&pm_qos_lock, flags);
+               if (pending_update)
+                       update_target(pm_qos_req->pm_qos_class);
        }
-       spin_unlock_irqrestore(&pm_qos_lock, flags);
-       if (pending_update)
-               update_target(pm_qos_class);
-
-       return 0;
 }
-EXPORT_SYMBOL_GPL(pm_qos_update_requirement);
+EXPORT_SYMBOL_GPL(pm_qos_update_request);
 
 /**
- * pm_qos_remove_requirement - modifies an existing qos request
- * @pm_qos_class: identifies which list of qos request to us
- * @name: identifies the request
+ * pm_qos_remove_request - modifies an existing qos request
+ * @pm_qos_req: handle to request list element
  *
- * Will remove named qos request from pm_qos_class list of parameters and
- * recompute the current target value for the pm_qos_class.
+ * Will remove pm qos request from the list of requests and
+ * recompute the current target value for the pm_qos_class.  Call this
+ * on slow code paths.
  */
-void pm_qos_remove_requirement(int pm_qos_class, char *name)
+void pm_qos_remove_request(struct pm_qos_request_list *pm_qos_req)
 {
        unsigned long flags;
-       struct requirement_list *node;
-       int pending_update = 0;
+       int qos_class;
 
+       if (pm_qos_req == NULL)
+               return;
+               /* silent return to keep pcm code cleaner */
+
+       qos_class = pm_qos_req->pm_qos_class;
        spin_lock_irqsave(&pm_qos_lock, flags);
-       list_for_each_entry(node,
-               &pm_qos_array[pm_qos_class]->requirements.list, list) {
-               if (strcmp(node->name, name) == 0) {
-                       kfree(node->name);
-                       list_del(&node->list);
-                       kfree(node);
-                       pending_update = 1;
-                       break;
-               }
-       }
+       list_del(&pm_qos_req->list);
+       kfree(pm_qos_req);
        spin_unlock_irqrestore(&pm_qos_lock, flags);
-       if (pending_update)
-               update_target(pm_qos_class);
+       update_target(qos_class);
 }
-EXPORT_SYMBOL_GPL(pm_qos_remove_requirement);
+EXPORT_SYMBOL_GPL(pm_qos_remove_request);
 
 /**
  * pm_qos_add_notifier - sets notification entry for changes to target value
@@ -313,7 +304,7 @@ EXPORT_SYMBOL_GPL(pm_qos_remove_requirement);
  * will register the notifier into a notification chain that gets called
  * upon changes to the pm_qos_class target value.
  */
- int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier)
+int pm_qos_add_notifier(int pm_qos_class, struct notifier_block *notifier)
 {
        int retval;
 
@@ -343,21 +334,16 @@ int pm_qos_remove_notifier(int pm_qos_class, struct notifier_block *notifier)
 }
 EXPORT_SYMBOL_GPL(pm_qos_remove_notifier);
 
-#define PID_NAME_LEN 32
-
 static int pm_qos_power_open(struct inode *inode, struct file *filp)
 {
-       int ret;
        long pm_qos_class;
-       char name[PID_NAME_LEN];
 
        pm_qos_class = find_pm_qos_object_by_minor(iminor(inode));
        if (pm_qos_class >= 0) {
-               filp->private_data = (void *)pm_qos_class;
-               snprintf(name, PID_NAME_LEN, "process_%d", current->pid);
-               ret = pm_qos_add_requirement(pm_qos_class, name,
-                                       PM_QOS_DEFAULT_VALUE);
-               if (ret >= 0)
+               filp->private_data = (void *) pm_qos_add_request(pm_qos_class,
+                               PM_QOS_DEFAULT_VALUE);
+
+               if (filp->private_data)
                        return 0;
        }
        return -EPERM;
@@ -365,32 +351,40 @@ static int pm_qos_power_open(struct inode *inode, struct file *filp)
 
 static int pm_qos_power_release(struct inode *inode, struct file *filp)
 {
-       int pm_qos_class;
-       char name[PID_NAME_LEN];
+       struct pm_qos_request_list *req;
 
-       pm_qos_class = (long)filp->private_data;
-       snprintf(name, PID_NAME_LEN, "process_%d", current->pid);
-       pm_qos_remove_requirement(pm_qos_class, name);
+       req = (struct pm_qos_request_list *)filp->private_data;
+       pm_qos_remove_request(req);
 
        return 0;
 }
 
+
 static ssize_t pm_qos_power_write(struct file *filp, const char __user *buf,
                size_t count, loff_t *f_pos)
 {
        s32 value;
-       int pm_qos_class;
-       char name[PID_NAME_LEN];
-
-       pm_qos_class = (long)filp->private_data;
-       if (count != sizeof(s32))
+       int x;
+       char ascii_value[11];
+       struct pm_qos_request_list *pm_qos_req;
+
+       if (count == sizeof(s32)) {
+               if (copy_from_user(&value, buf, sizeof(s32)))
+                       return -EFAULT;
+       } else if (count == 11) { /* len('0x12345678/0') */
+               if (copy_from_user(ascii_value, buf, 11))
+                       return -EFAULT;
+               x = sscanf(ascii_value, "%x", &value);
+               if (x != 1)
+                       return -EINVAL;
+               pr_debug(KERN_ERR "%s, %d, 0x%x\n", ascii_value, x, value);
+       } else
                return -EINVAL;
-       if (copy_from_user(&value, buf, sizeof(s32)))
-               return -EFAULT;
-       snprintf(name, PID_NAME_LEN, "process_%d", current->pid);
-       pm_qos_update_requirement(pm_qos_class, name, value);
 
-       return  sizeof(s32);
+       pm_qos_req = (struct pm_qos_request_list *)filp->private_data;
+       pm_qos_update_request(pm_qos_req, value);
+
+       return count;
 }
 
 
index bc7704b..00bb252 100644 (file)
 #include <trace/events/timer.h>
 
 /*
- * Called after updating RLIMIT_CPU to set timer expiration if necessary.
+ * Called after updating RLIMIT_CPU to run cpu timer and update
+ * tsk->signal->cputime_expires expiration cache if necessary. Needs
+ * siglock protection since other code may update expiration cache as
+ * well.
  */
 void update_rlimit_cpu(unsigned long rlim_new)
 {
        cputime_t cputime = secs_to_cputime(rlim_new);
-       struct signal_struct *const sig = current->signal;
 
-       if (cputime_eq(sig->it[CPUCLOCK_PROF].expires, cputime_zero) ||
-           cputime_gt(sig->it[CPUCLOCK_PROF].expires, cputime)) {
-               spin_lock_irq(&current->sighand->siglock);
-               set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
-               spin_unlock_irq(&current->sighand->siglock);
-       }
+       spin_lock_irq(&current->sighand->siglock);
+       set_process_cpu_timer(current, CPUCLOCK_PROF, &cputime, NULL);
+       spin_unlock_irq(&current->sighand->siglock);
 }
 
 static int check_clock(const clockid_t which_clock)
@@ -548,111 +547,62 @@ static inline int expires_gt(cputime_t expires, cputime_t new_exp)
               cputime_gt(expires, new_exp);
 }
 
-static inline int expires_le(cputime_t expires, cputime_t new_exp)
-{
-       return !cputime_eq(expires, cputime_zero) &&
-              cputime_le(expires, new_exp);
-}
 /*
  * Insert the timer on the appropriate list before any timers that
  * expire later.  This must be called with the tasklist_lock held
- * for reading, and interrupts disabled.
+ * for reading, interrupts disabled and p->sighand->siglock taken.
  */
-static void arm_timer(struct k_itimer *timer, union cpu_time_count now)
+static void arm_timer(struct k_itimer *timer)
 {
        struct task_struct *p = timer->it.cpu.task;
        struct list_head *head, *listpos;
+       struct task_cputime *cputime_expires;
        struct cpu_timer_list *const nt = &timer->it.cpu;
        struct cpu_timer_list *next;
-       unsigned long i;
 
-       head = (CPUCLOCK_PERTHREAD(timer->it_clock) ?
-               p->cpu_timers : p->signal->cpu_timers);
+       if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
+               head = p->cpu_timers;
+               cputime_expires = &p->cputime_expires;
+       } else {
+               head = p->signal->cpu_timers;
+               cputime_expires = &p->signal->cputime_expires;
+       }
        head += CPUCLOCK_WHICH(timer->it_clock);
 
-       BUG_ON(!irqs_disabled());
-       spin_lock(&p->sighand->siglock);
-
        listpos = head;
-       if (CPUCLOCK_WHICH(timer->it_clock) == CPUCLOCK_SCHED) {
-               list_for_each_entry(next, head, entry) {
-                       if (next->expires.sched > nt->expires.sched)
-                               break;
-                       listpos = &next->entry;
-               }
-       } else {
-               list_for_each_entry(next, head, entry) {
-                       if (cputime_gt(next->expires.cpu, nt->expires.cpu))
-                               break;
-                       listpos = &next->entry;
-               }
+       list_for_each_entry(next, head, entry) {
+               if (cpu_time_before(timer->it_clock, nt->expires, next->expires))
+                       break;
+               listpos = &next->entry;
        }
        list_add(&nt->entry, listpos);
 
        if (listpos == head) {
+               union cpu_time_count *exp = &nt->expires;
+
                /*
-                * We are the new earliest-expiring timer.
-                * If we are a thread timer, there can always
-                * be a process timer telling us to stop earlier.
+                * We are the new earliest-expiring POSIX 1.b timer, hence
+                * need to update expiration cache. Take into account that
+                * for process timers we share expiration cache with itimers
+                * and RLIMIT_CPU and for thread timers with RLIMIT_RTTIME.
                 */
 
-               if (CPUCLOCK_PERTHREAD(timer->it_clock)) {
-                       union cpu_time_count *exp = &nt->expires;
-
-                       switch (CPUCLOCK_WHICH(timer->it_clock)) {
-                       default:
-                               BUG();
-                       case CPUCLOCK_PROF:
-                               if (expires_gt(p->cputime_expires.prof_exp,
-                                              exp->cpu))
-                                       p->cputime_expires.prof_exp = exp->cpu;
-                               break;
-                       case CPUCLOCK_VIRT:
-                               if (expires_gt(p->cputime_expires.virt_exp,
-                                              exp->cpu))
-                                       p->cputime_expires.virt_exp = exp->cpu;
-                               break;
-                       case CPUCLOCK_SCHED:
-                               if (p->cputime_expires.sched_exp == 0 ||
-                                   p->cputime_expires.sched_exp > exp->sched)
-                                       p->cputime_expires.sched_exp =
-                                                               exp->sched;
-                               break;
-                       }
-               } else {
-                       struct signal_struct *const sig = p->signal;
-                       union cpu_time_count *exp = &timer->it.cpu.expires;
-
-                       /*
-                        * For a process timer, set the cached expiration time.
-                        */
-                       switch (CPUCLOCK_WHICH(timer->it_clock)) {
-                       default:
-                               BUG();
-                       case CPUCLOCK_VIRT:
-                               if (expires_le(sig->it[CPUCLOCK_VIRT].expires,
-                                              exp->cpu))
-                                       break;
-                               sig->cputime_expires.virt_exp = exp->cpu;
-                               break;
-                       case CPUCLOCK_PROF:
-                               if (expires_le(sig->it[CPUCLOCK_PROF].expires,
-                                              exp->cpu))
-                                       break;
-                               i = sig->rlim[RLIMIT_CPU].rlim_cur;
-                               if (i != RLIM_INFINITY &&
-                                   i <= cputime_to_secs(exp->cpu))
-                                       break;
-                               sig->cputime_expires.prof_exp = exp->cpu;
-                               break;
-                       case CPUCLOCK_SCHED:
-                               sig->cputime_expires.sched_exp = exp->sched;
-                               break;
-                       }
+               switch (CPUCLOCK_WHICH(timer->it_clock)) {
+               case CPUCLOCK_PROF:
+                       if (expires_gt(cputime_expires->prof_exp, exp->cpu))
+                               cputime_expires->prof_exp = exp->cpu;
+                       break;
+               case CPUCLOCK_VIRT:
+                       if (expires_gt(cputime_expires->virt_exp, exp->cpu))
+                               cputime_expires->virt_exp = exp->cpu;
+                       break;
+               case CPUCLOCK_SCHED:
+                       if (cputime_expires->sched_exp == 0 ||
+                           cputime_expires->sched_exp > exp->sched)
+                               cputime_expires->sched_exp = exp->sched;
+                       break;
                }
        }
-
-       spin_unlock(&p->sighand->siglock);
 }
 
 /*
@@ -660,7 +610,12 @@ static void arm_timer(struct k_itimer *timer, union cpu_time_count now)
  */
 static void cpu_timer_fire(struct k_itimer *timer)
 {
-       if (unlikely(timer->sigq == NULL)) {
+       if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
+               /*
+                * User don't want any signal.
+                */
+               timer->it.cpu.expires.sched = 0;
+       } else if (unlikely(timer->sigq == NULL)) {
                /*
                 * This a special case for clock_nanosleep,
                 * not a normal timer from sys_timer_create.
@@ -721,7 +676,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
                        struct itimerspec *new, struct itimerspec *old)
 {
        struct task_struct *p = timer->it.cpu.task;
-       union cpu_time_count old_expires, new_expires, val;
+       union cpu_time_count old_expires, new_expires, old_incr, val;
        int ret;
 
        if (unlikely(p == NULL)) {
@@ -752,6 +707,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
        BUG_ON(!irqs_disabled());
 
        ret = 0;
+       old_incr = timer->it.cpu.incr;
        spin_lock(&p->sighand->siglock);
        old_expires = timer->it.cpu.expires;
        if (unlikely(timer->it.cpu.firing)) {
@@ -759,7 +715,6 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
                ret = TIMER_RETRY;
        } else
                list_del_init(&timer->it.cpu.entry);
-       spin_unlock(&p->sighand->siglock);
 
        /*
         * We need to sample the current value to convert the new
@@ -813,6 +768,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
                 * disable this firing since we are already reporting
                 * it as an overrun (thanks to bump_cpu_timer above).
                 */
+               spin_unlock(&p->sighand->siglock);
                read_unlock(&tasklist_lock);
                goto out;
        }
@@ -828,11 +784,11 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
         */
        timer->it.cpu.expires = new_expires;
        if (new_expires.sched != 0 &&
-           (timer->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE &&
            cpu_time_before(timer->it_clock, val, new_expires)) {
-               arm_timer(timer, val);
+               arm_timer(timer);
        }
 
+       spin_unlock(&p->sighand->siglock);
        read_unlock(&tasklist_lock);
 
        /*
@@ -853,7 +809,6 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
        timer->it_overrun = -1;
 
        if (new_expires.sched != 0 &&
-           (timer->it_sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_NONE &&
            !cpu_time_before(timer->it_clock, val, new_expires)) {
                /*
                 * The designated time already passed, so we notify
@@ -867,7 +822,7 @@ int posix_cpu_timer_set(struct k_itimer *timer, int flags,
  out:
        if (old) {
                sample_to_timespec(timer->it_clock,
-                                  timer->it.cpu.incr, &old->it_interval);
+                                  old_incr, &old->it_interval);
        }
        return ret;
 }
@@ -927,25 +882,6 @@ void posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec *itp)
                read_unlock(&tasklist_lock);
        }
 
-       if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
-               if (timer->it.cpu.incr.sched == 0 &&
-                   cpu_time_before(timer->it_clock,
-                                   timer->it.cpu.expires, now)) {
-                       /*
-                        * Do-nothing timer expired and has no reload,
-                        * so it's as if it was never set.
-                        */
-                       timer->it.cpu.expires.sched = 0;
-                       itp->it_value.tv_sec = itp->it_value.tv_nsec = 0;
-                       return;
-               }
-               /*
-                * Account for any expirations and reloads that should
-                * have happened.
-                */
-               bump_cpu_timer(timer, now);
-       }
-
        if (unlikely(clear_dead)) {
                /*
                 * We've noticed that the thread is dead, but
@@ -1066,16 +1002,9 @@ static void stop_process_timers(struct signal_struct *sig)
        struct thread_group_cputimer *cputimer = &sig->cputimer;
        unsigned long flags;
 
-       if (!cputimer->running)
-               return;
-
        spin_lock_irqsave(&cputimer->lock, flags);
        cputimer->running = 0;
        spin_unlock_irqrestore(&cputimer->lock, flags);
-
-       sig->cputime_expires.prof_exp = cputime_zero;
-       sig->cputime_expires.virt_exp = cputime_zero;
-       sig->cputime_expires.sched_exp = 0;
 }
 
 static u32 onecputick;
@@ -1112,6 +1041,23 @@ static void check_cpu_itimer(struct task_struct *tsk, struct cpu_itimer *it,
        }
 }
 
+/**
+ * task_cputime_zero - Check a task_cputime struct for all zero fields.
+ *
+ * @cputime:   The struct to compare.
+ *
+ * Checks @cputime to see if all fields are zero.  Returns true if all fields
+ * are zero, false if any field is nonzero.
+ */
+static inline int task_cputime_zero(const struct task_cputime *cputime)
+{
+       if (cputime_eq(cputime->utime, cputime_zero) &&
+           cputime_eq(cputime->stime, cputime_zero) &&
+           cputime->sum_exec_runtime == 0)
+               return 1;
+       return 0;
+}
+
 /*
  * Check for any per-thread CPU timers that have fired and move them
  * off the tsk->*_timers list onto the firing list.  Per-thread timers
@@ -1128,19 +1074,6 @@ static void check_process_timers(struct task_struct *tsk,
        struct task_cputime cputime;
        unsigned long soft;
 
-       /*
-        * Don't sample the current process CPU clocks if there are no timers.
-        */
-       if (list_empty(&timers[CPUCLOCK_PROF]) &&
-           cputime_eq(sig->it[CPUCLOCK_PROF].expires, cputime_zero) &&
-           sig->rlim[RLIMIT_CPU].rlim_cur == RLIM_INFINITY &&
-           list_empty(&timers[CPUCLOCK_VIRT]) &&
-           cputime_eq(sig->it[CPUCLOCK_VIRT].expires, cputime_zero) &&
-           list_empty(&timers[CPUCLOCK_SCHED])) {
-               stop_process_timers(sig);
-               return;
-       }
-
        /*
         * Collect the current process totals.
         */
@@ -1230,18 +1163,11 @@ static void check_process_timers(struct task_struct *tsk,
                }
        }
 
-       if (!cputime_eq(prof_expires, cputime_zero) &&
-           (cputime_eq(sig->cputime_expires.prof_exp, cputime_zero) ||
-            cputime_gt(sig->cputime_expires.prof_exp, prof_expires)))
-               sig->cputime_expires.prof_exp = prof_expires;
-       if (!cputime_eq(virt_expires, cputime_zero) &&
-           (cputime_eq(sig->cputime_expires.virt_exp, cputime_zero) ||
-            cputime_gt(sig->cputime_expires.virt_exp, virt_expires)))
-               sig->cputime_expires.virt_exp = virt_expires;
-       if (sched_expires != 0 &&
-           (sig->cputime_expires.sched_exp == 0 ||
-            sig->cputime_expires.sched_exp > sched_expires))
-               sig->cputime_expires.sched_exp = sched_expires;
+       sig->cputime_expires.prof_exp = prof_expires;
+       sig->cputime_expires.virt_exp = virt_expires;
+       sig->cputime_expires.sched_exp = sched_expires;
+       if (task_cputime_zero(&sig->cputime_expires))
+               stop_process_timers(sig);
 }
 
 /*
@@ -1270,6 +1196,7 @@ void posix_cpu_timer_schedule(struct k_itimer *timer)
                        goto out;
                }
                read_lock(&tasklist_lock); /* arm_timer needs it.  */
+               spin_lock(&p->sighand->siglock);
        } else {
                read_lock(&tasklist_lock);
                if (unlikely(p->signal == NULL)) {
@@ -1290,6 +1217,7 @@ void posix_cpu_timer_schedule(struct k_itimer *timer)
                        clear_dead_task(timer, now);
                        goto out_unlock;
                }
+               spin_lock(&p->sighand->siglock);
                cpu_timer_sample_group(timer->it_clock, p, &now);
                bump_cpu_timer(timer, now);
                /* Leave the tasklist_lock locked for the call below.  */
@@ -1298,7 +1226,9 @@ void posix_cpu_timer_schedule(struct k_itimer *timer)
        /*
         * Now re-arm for the new expiry time.
         */
-       arm_timer(timer, now);
+       BUG_ON(!irqs_disabled());
+       arm_timer(timer);
+       spin_unlock(&p->sighand->siglock);
 
 out_unlock:
        read_unlock(&tasklist_lock);
@@ -1309,23 +1239,6 @@ out:
        ++timer->it_requeue_pending;
 }
 
-/**
- * task_cputime_zero - Check a task_cputime struct for all zero fields.
- *
- * @cputime:   The struct to compare.
- *
- * Checks @cputime to see if all fields are zero.  Returns true if all fields
- * are zero, false if any field is nonzero.
- */
-static inline int task_cputime_zero(const struct task_cputime *cputime)
-{
-       if (cputime_eq(cputime->utime, cputime_zero) &&
-           cputime_eq(cputime->stime, cputime_zero) &&
-           cputime->sum_exec_runtime == 0)
-               return 1;
-       return 0;
-}
-
 /**
  * task_cputime_expired - Compare two task_cputime entities.
  *
@@ -1382,7 +1295,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
        }
 
        sig = tsk->signal;
-       if (!task_cputime_zero(&sig->cputime_expires)) {
+       if (sig->cputimer.running) {
                struct task_cputime group_sample;
 
                thread_group_cputimer(tsk, &group_sample);
@@ -1390,7 +1303,7 @@ static inline int fastpath_timer_check(struct task_struct *tsk)
                        return 1;
        }
 
-       return sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY;
+       return 0;
 }
 
 /*
@@ -1419,7 +1332,12 @@ void run_posix_cpu_timers(struct task_struct *tsk)
         * put them on the firing list.
         */
        check_thread_timers(tsk, &firing);
-       check_process_timers(tsk, &firing);
+       /*
+        * If there are any active process wide timers (POSIX 1.b, itimers,
+        * RLIMIT_CPU) cputimer must be running.
+        */
+       if (tsk->signal->cputimer.running)
+               check_process_timers(tsk, &firing);
 
        /*
         * We must release these locks before taking any timer's lock.
@@ -1456,21 +1374,23 @@ void run_posix_cpu_timers(struct task_struct *tsk)
 }
 
 /*
- * Set one of the process-wide special case CPU timers.
+ * Set one of the process-wide special case CPU timers or RLIMIT_CPU.
  * The tsk->sighand->siglock must be held by the caller.
- * The *newval argument is relative and we update it to be absolute, *oldval
- * is absolute and we update it to be relative.
  */
 void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
                           cputime_t *newval, cputime_t *oldval)
 {
        union cpu_time_count now;
-       struct list_head *head;
 
        BUG_ON(clock_idx == CPUCLOCK_SCHED);
        cpu_timer_sample_group(clock_idx, tsk, &now);
 
        if (oldval) {
+               /*
+                * We are setting itimer. The *oldval is absolute and we update
+                * it to be relative, *newval argument is relative and we update
+                * it to be absolute.
+                */
                if (!cputime_eq(*oldval, cputime_zero)) {
                        if (cputime_le(*oldval, now.cpu)) {
                                /* Just about to fire. */
@@ -1483,33 +1403,21 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clock_idx,
                if (cputime_eq(*newval, cputime_zero))
                        return;
                *newval = cputime_add(*newval, now.cpu);
-
-               /*
-                * If the RLIMIT_CPU timer will expire before the
-                * ITIMER_PROF timer, we have nothing else to do.
-                */
-               if (tsk->signal->rlim[RLIMIT_CPU].rlim_cur
-                   < cputime_to_secs(*newval))
-                       return;
        }
 
        /*
-        * Check whether there are any process timers already set to fire
-        * before this one.  If so, we don't have anything more to do.
+        * Update expiration cache if we are the earliest timer, or eventually
+        * RLIMIT_CPU limit is earlier than prof_exp cpu timer expire.
         */
-       head = &tsk->signal->cpu_timers[clock_idx];
-       if (list_empty(head) ||
-           cputime_ge(list_first_entry(head,
-                                 struct cpu_timer_list, entry)->expires.cpu,
-                      *newval)) {
-               switch (clock_idx) {
-               case CPUCLOCK_PROF:
+       switch (clock_idx) {
+       case CPUCLOCK_PROF:
+               if (expires_gt(tsk->signal->cputime_expires.prof_exp, *newval))
                        tsk->signal->cputime_expires.prof_exp = *newval;
-                       break;
-               case CPUCLOCK_VIRT:
+               break;
+       case CPUCLOCK_VIRT:
+               if (expires_gt(tsk->signal->cputime_expires.virt_exp, *newval))
                        tsk->signal->cputime_expires.virt_exp = *newval;
-                       break;
-               }
+               break;
        }
 }
 
index 4319181..524e058 100644 (file)
@@ -8,7 +8,8 @@ obj-$(CONFIG_PM_SLEEP)          += console.o
 obj-$(CONFIG_FREEZER)          += process.o
 obj-$(CONFIG_SUSPEND)          += suspend.o
 obj-$(CONFIG_PM_TEST_SUSPEND)  += suspend_test.o
-obj-$(CONFIG_HIBERNATION)      += hibernate.o snapshot.o swap.o user.o
+obj-$(CONFIG_HIBERNATION)      += hibernate.o snapshot.o swap.o user.o \
+                                  block_io.o
 obj-$(CONFIG_HIBERNATION_NVS)  += hibernate_nvs.o
 
 obj-$(CONFIG_MAGIC_SYSRQ)      += poweroff.o
diff --git a/kernel/power/block_io.c b/kernel/power/block_io.c
new file mode 100644 (file)
index 0000000..97024fd
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * This file provides functions for block I/O operations on swap/file.
+ *
+ * Copyright (C) 1998,2001-2005 Pavel Machek <pavel@ucw.cz>
+ * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
+ *
+ * This file is released under the GPLv2.
+ */
+
+#include <linux/bio.h>
+#include <linux/kernel.h>
+#include <linux/pagemap.h>
+#include <linux/swap.h>
+
+#include "power.h"
+
+/**
+ *     submit - submit BIO request.
+ *     @rw:    READ or WRITE.
+ *     @off    physical offset of page.
+ *     @page:  page we're reading or writing.
+ *     @bio_chain: list of pending biod (for async reading)
+ *
+ *     Straight from the textbook - allocate and initialize the bio.
+ *     If we're reading, make sure the page is marked as dirty.
+ *     Then submit it and, if @bio_chain == NULL, wait.
+ */
+static int submit(int rw, struct block_device *bdev, sector_t sector,
+               struct page *page, struct bio **bio_chain)
+{
+       const int bio_rw = rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
+       struct bio *bio;
+
+       bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1);
+       bio->bi_sector = sector;
+       bio->bi_bdev = bdev;
+       bio->bi_end_io = end_swap_bio_read;
+
+       if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
+               printk(KERN_ERR "PM: Adding page to bio failed at %llu\n",
+                       (unsigned long long)sector);
+               bio_put(bio);
+               return -EFAULT;
+       }
+
+       lock_page(page);
+       bio_get(bio);
+
+       if (bio_chain == NULL) {
+               submit_bio(bio_rw, bio);
+               wait_on_page_locked(page);
+               if (rw == READ)
+                       bio_set_pages_dirty(bio);
+               bio_put(bio);
+       } else {
+               if (rw == READ)
+                       get_page(page); /* These pages are freed later */
+               bio->bi_private = *bio_chain;
+               *bio_chain = bio;
+               submit_bio(bio_rw, bio);
+       }
+       return 0;
+}
+
+int hib_bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
+{
+       return submit(READ, hib_resume_bdev, page_off * (PAGE_SIZE >> 9),
+                       virt_to_page(addr), bio_chain);
+}
+
+int hib_bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
+{
+       return submit(WRITE, hib_resume_bdev, page_off * (PAGE_SIZE >> 9),
+                       virt_to_page(addr), bio_chain);
+}
+
+int hib_wait_on_bio_chain(struct bio **bio_chain)
+{
+       struct bio *bio;
+       struct bio *next_bio;
+       int ret = 0;
+
+       if (bio_chain == NULL)
+               return 0;
+
+       bio = *bio_chain;
+       if (bio == NULL)
+               return 0;
+       while (bio) {
+               struct page *page;
+
+               next_bio = bio->bi_private;
+               page = bio->bi_io_vec[0].bv_page;
+               wait_on_page_locked(page);
+               if (!PageUptodate(page) || PageError(page))
+                       ret = -EIO;
+               put_page(page);
+               bio_put(bio);
+               bio = next_bio;
+       }
+       *bio_chain = NULL;
+       return ret;
+}
index 46c5a26..006270f 100644 (file)
@@ -97,24 +97,12 @@ extern int hibernate_preallocate_memory(void);
  */
 
 struct snapshot_handle {
-       loff_t          offset; /* number of the last byte ready for reading
-                                * or writing in the sequence
-                                */
        unsigned int    cur;    /* number of the block of PAGE_SIZE bytes the
                                 * next operation will refer to (ie. current)
                                 */
-       unsigned int    cur_offset;     /* offset with respect to the current
-                                        * block (for the next operation)
-                                        */
-       unsigned int    prev;   /* number of the block of PAGE_SIZE bytes that
-                                * was the current one previously
-                                */
        void            *buffer;        /* address of the block to read from
                                         * or write to
                                         */
-       unsigned int    buf_offset;     /* location to read from or write to,
-                                        * given as a displacement from 'buffer'
-                                        */
        int             sync_read;      /* Set to one to notify the caller of
                                         * snapshot_write_next() that it may
                                         * need to call wait_on_bio_chain()
@@ -125,12 +113,12 @@ struct snapshot_handle {
  * snapshot_read_next()/snapshot_write_next() is allowed to
  * read/write data after the function returns
  */
-#define data_of(handle)        ((handle).buffer + (handle).buf_offset)
+#define data_of(handle)        ((handle).buffer)
 
 extern unsigned int snapshot_additional_pages(struct zone *zone);
 extern unsigned long snapshot_get_image_size(void);
-extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
-extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
+extern int snapshot_read_next(struct snapshot_handle *handle);
+extern int snapshot_write_next(struct snapshot_handle *handle);
 extern void snapshot_write_finalize(struct snapshot_handle *handle);
 extern int snapshot_image_loaded(struct snapshot_handle *handle);
 
@@ -154,6 +142,15 @@ extern int swsusp_read(unsigned int *flags_p);
 extern int swsusp_write(unsigned int flags);
 extern void swsusp_close(fmode_t);
 
+/* kernel/power/block_io.c */
+extern struct block_device *hib_resume_bdev;
+
+extern int hib_bio_read_page(pgoff_t page_off, void *addr,
+               struct bio **bio_chain);
+extern int hib_bio_write_page(pgoff_t page_off, void *addr,
+               struct bio **bio_chain);
+extern int hib_wait_on_bio_chain(struct bio **bio_chain);
+
 struct timeval;
 /* kernel/power/swsusp.c */
 extern void swsusp_show_speed(struct timeval *, struct timeval *,
index be861c2..25ce010 100644 (file)
@@ -1604,14 +1604,9 @@ pack_pfns(unsigned long *buf, struct memory_bitmap *bm)
  *     snapshot_handle structure.  The structure gets updated and a pointer
  *     to it should be passed to this function every next time.
  *
- *     The @count parameter should contain the number of bytes the caller
- *     wants to read from the snapshot.  It must not be zero.
- *
  *     On success the function returns a positive number.  Then, the caller
  *     is allowed to read up to the returned number of bytes from the memory
- *     location computed by the data_of() macro.  The number returned
- *     may be smaller than @count, but this only happens if the read would
- *     cross a page boundary otherwise.
+ *     location computed by the data_of() macro.
  *
  *     The function returns 0 to indicate the end of data stream condition,
  *     and a negative number is returned on error.  In such cases the
@@ -1619,7 +1614,7 @@ pack_pfns(unsigned long *buf, struct memory_bitmap *bm)
  *     any more.
  */
 
-int snapshot_read_next(struct snapshot_handle *handle, size_t count)
+int snapshot_read_next(struct snapshot_handle *handle)
 {
        if (handle->cur > nr_meta_pages + nr_copy_pages)
                return 0;
@@ -1630,7 +1625,7 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
                if (!buffer)
                        return -ENOMEM;
        }
-       if (!handle->offset) {
+       if (!handle->cur) {
                int error;
 
                error = init_header((struct swsusp_info *)buffer);
@@ -1639,42 +1634,30 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
                handle->buffer = buffer;
                memory_bm_position_reset(&orig_bm);
                memory_bm_position_reset(&copy_bm);
-       }
-       if (handle->prev < handle->cur) {
-               if (handle->cur <= nr_meta_pages) {
-                       memset(buffer, 0, PAGE_SIZE);
-                       pack_pfns(buffer, &orig_bm);
-               } else {
-                       struct page *page;
+       } else if (handle->cur <= nr_meta_pages) {
+               memset(buffer, 0, PAGE_SIZE);
+               pack_pfns(buffer, &orig_bm);
+       } else {
+               struct page *page;
 
-                       page = pfn_to_page(memory_bm_next_pfn(&copy_bm));
-                       if (PageHighMem(page)) {
-                               /* Highmem pages are copied to the buffer,
-                                * because we can't return with a kmapped
-                                * highmem page (we may not be called again).
-                                */
-                               void *kaddr;
+               page = pfn_to_page(memory_bm_next_pfn(&copy_bm));
+               if (PageHighMem(page)) {
+                       /* Highmem pages are copied to the buffer,
+                        * because we can't return with a kmapped
+                        * highmem page (we may not be called again).
+                        */
+                       void *kaddr;
 
-                               kaddr = kmap_atomic(page, KM_USER0);
-                               memcpy(buffer, kaddr, PAGE_SIZE);
-                               kunmap_atomic(kaddr, KM_USER0);
-                               handle->buffer = buffer;
-                       } else {
-                               handle->buffer = page_address(page);
-                       }
+                       kaddr = kmap_atomic(page, KM_USER0);
+                       memcpy(buffer, kaddr, PAGE_SIZE);
+                       kunmap_atomic(kaddr, KM_USER0);
+                       handle->buffer = buffer;
+               } else {
+                       handle->buffer = page_address(page);
                }
-               handle->prev = handle->cur;
-       }
-       handle->buf_offset = handle->cur_offset;
-       if (handle->cur_offset + count >= PAGE_SIZE) {
-               count = PAGE_SIZE - handle->cur_offset;
-               handle->cur_offset = 0;
-               handle->cur++;
-       } else {
-               handle->cur_offset += count;
        }
-       handle->offset += count;
-       return count;
+       handle->cur++;
+       return PAGE_SIZE;
 }
 
 /**
@@ -2133,14 +2116,9 @@ static void *get_buffer(struct memory_bitmap *bm, struct chain_allocator *ca)
  *     snapshot_handle structure.  The structure gets updated and a pointer
  *     to it should be passed to this function every next time.
  *
- *     The @count parameter should contain the number of bytes the caller
- *     wants to write to the image.  It must not be zero.
- *
  *     On success the function returns a positive number.  Then, the caller
  *     is allowed to write up to the returned number of bytes to the memory
- *     location computed by the data_of() macro.  The number returned
- *     may be smaller than @count, but this only happens if the write would
- *     cross a page boundary otherwise.
+ *     location computed by the data_of() macro.
  *
  *     The function returns 0 to indicate the "end of file" condition,
  *     and a negative number is returned on error.  In such cases the
@@ -2148,16 +2126,18 @@ static void *get_buffer(struct memory_bitmap *bm, struct chain_allocator *ca)
  *     any more.
  */
 
-int snapshot_write_next(struct snapshot_handle *handle, size_t count)
+int snapshot_write_next(struct snapshot_handle *handle)
 {
        static struct chain_allocator ca;
        int error = 0;
 
        /* Check if we have already loaded the entire image */
-       if (handle->prev && handle->cur > nr_meta_pages + nr_copy_pages)
+       if (handle->cur > 1 && handle->cur > nr_meta_pages + nr_copy_pages)
                return 0;
 
-       if (handle->offset == 0) {
+       handle->sync_read = 1;
+
+       if (!handle->cur) {
                if (!buffer)
                        /* This makes the buffer be freed by swsusp_free() */
                        buffer = get_image_page(GFP_ATOMIC, PG_ANY);
@@ -2166,56 +2146,43 @@ int snapshot_write_next(struct snapshot_handle *handle, size_t count)
                        return -ENOMEM;
 
                handle->buffer = buffer;
-       }
-       handle->sync_read = 1;
-       if (handle->prev < handle->cur) {
-               if (handle->prev == 0) {
-                       error = load_header(buffer);
-                       if (error)
-                               return error;
+       } else if (handle->cur == 1) {
+               error = load_header(buffer);
+               if (error)
+                       return error;
 
-                       error = memory_bm_create(&copy_bm, GFP_ATOMIC, PG_ANY);
-                       if (error)
-                               return error;
+               error = memory_bm_create(&copy_bm, GFP_ATOMIC, PG_ANY);
+               if (error)
+                       return error;
+
+       } else if (handle->cur <= nr_meta_pages + 1) {
+               error = unpack_orig_pfns(buffer, &copy_bm);
+               if (error)
+                       return error;
 
-               } else if (handle->prev <= nr_meta_pages) {
-                       error = unpack_orig_pfns(buffer, &copy_bm);
+               if (handle->cur == nr_meta_pages + 1) {
+                       error = prepare_image(&orig_bm, &copy_bm);
                        if (error)
                                return error;
 
-                       if (handle->prev == nr_meta_pages) {
-                               error = prepare_image(&orig_bm, &copy_bm);
-                               if (error)
-                                       return error;
-
-                               chain_init(&ca, GFP_ATOMIC, PG_SAFE);
-                               memory_bm_position_reset(&orig_bm);
-                               restore_pblist = NULL;
-                               handle->buffer = get_buffer(&orig_bm, &ca);
-                               handle->sync_read = 0;
-                               if (IS_ERR(handle->buffer))
-                                       return PTR_ERR(handle->buffer);
-                       }
-               } else {
-                       copy_last_highmem_page();
+                       chain_init(&ca, GFP_ATOMIC, PG_SAFE);
+                       memory_bm_position_reset(&orig_bm);
+                       restore_pblist = NULL;
                        handle->buffer = get_buffer(&orig_bm, &ca);
+                       handle->sync_read = 0;
                        if (IS_ERR(handle->buffer))
                                return PTR_ERR(handle->buffer);
-                       if (handle->buffer != buffer)
-                               handle->sync_read = 0;
                }
-               handle->prev = handle->cur;
-       }
-       handle->buf_offset = handle->cur_offset;
-       if (handle->cur_offset + count >= PAGE_SIZE) {
-               count = PAGE_SIZE - handle->cur_offset;
-               handle->cur_offset = 0;
-               handle->cur++;
        } else {
-               handle->cur_offset += count;
+               copy_last_highmem_page();
+               handle->buffer = get_buffer(&orig_bm, &ca);
+               if (IS_ERR(handle->buffer))
+                       return PTR_ERR(handle->buffer);
+               if (handle->buffer != buffer)
+                       handle->sync_read = 0;
        }
-       handle->offset += count;
-       return count;
+       handle->cur++;
+       return PAGE_SIZE;
 }
 
 /**
@@ -2230,7 +2197,7 @@ void snapshot_write_finalize(struct snapshot_handle *handle)
 {
        copy_last_highmem_page();
        /* Free only if we have loaded the image entirely */
-       if (handle->prev && handle->cur > nr_meta_pages + nr_copy_pages) {
+       if (handle->cur > 1 && handle->cur > nr_meta_pages + nr_copy_pages) {
                memory_bm_free(&orig_bm, PG_UNSAFE_CLEAR);
                free_highmem_data();
        }
index 66824d7..b0bb217 100644 (file)
 
 #define SWSUSP_SIG     "S1SUSPEND"
 
+/*
+ *     The swap map is a data structure used for keeping track of each page
+ *     written to a swap partition.  It consists of many swap_map_page
+ *     structures that contain each an array of MAP_PAGE_SIZE swap entries.
+ *     These structures are stored on the swap and linked together with the
+ *     help of the .next_swap member.
+ *
+ *     The swap map is created during suspend.  The swap map pages are
+ *     allocated and populated one at a time, so we only need one memory
+ *     page to set up the entire structure.
+ *
+ *     During resume we also only need to use one swap_map_page structure
+ *     at a time.
+ */
+
+#define MAP_PAGE_ENTRIES       (PAGE_SIZE / sizeof(sector_t) - 1)
+
+struct swap_map_page {
+       sector_t entries[MAP_PAGE_ENTRIES];
+       sector_t next_swap;
+};
+
+/**
+ *     The swap_map_handle structure is used for handling swap in
+ *     a file-alike way
+ */
+
+struct swap_map_handle {
+       struct swap_map_page *cur;
+       sector_t cur_swap;
+       sector_t first_sector;
+       unsigned int k;
+};
+
 struct swsusp_header {
        char reserved[PAGE_SIZE - 20 - sizeof(sector_t) - sizeof(int)];
        sector_t image;
@@ -145,110 +179,24 @@ int swsusp_swap_in_use(void)
  */
 
 static unsigned short root_swap = 0xffff;
-static struct block_device *resume_bdev;
-
-/**
- *     submit - submit BIO request.
- *     @rw:    READ or WRITE.
- *     @off    physical offset of page.
- *     @page:  page we're reading or writing.
- *     @bio_chain: list of pending biod (for async reading)
- *
- *     Straight from the textbook - allocate and initialize the bio.
- *     If we're reading, make sure the page is marked as dirty.
- *     Then submit it and, if @bio_chain == NULL, wait.
- */
-static int submit(int rw, pgoff_t page_off, struct page *page,
-                       struct bio **bio_chain)
-{
-       const int bio_rw = rw | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG);
-       struct bio *bio;
-
-       bio = bio_alloc(__GFP_WAIT | __GFP_HIGH, 1);
-       bio->bi_sector = page_off * (PAGE_SIZE >> 9);
-       bio->bi_bdev = resume_bdev;
-       bio->bi_end_io = end_swap_bio_read;
-
-       if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
-               printk(KERN_ERR "PM: Adding page to bio failed at %ld\n",
-                       page_off);
-               bio_put(bio);
-               return -EFAULT;
-       }
-
-       lock_page(page);
-       bio_get(bio);
-
-       if (bio_chain == NULL) {
-               submit_bio(bio_rw, bio);
-               wait_on_page_locked(page);
-               if (rw == READ)
-                       bio_set_pages_dirty(bio);
-               bio_put(bio);
-       } else {
-               if (rw == READ)
-                       get_page(page); /* These pages are freed later */
-               bio->bi_private = *bio_chain;
-               *bio_chain = bio;
-               submit_bio(bio_rw, bio);
-       }
-       return 0;
-}
-
-static int bio_read_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
-{
-       return submit(READ, page_off, virt_to_page(addr), bio_chain);
-}
-
-static int bio_write_page(pgoff_t page_off, void *addr, struct bio **bio_chain)
-{
-       return submit(WRITE, page_off, virt_to_page(addr), bio_chain);
-}
-
-static int wait_on_bio_chain(struct bio **bio_chain)
-{
-       struct bio *bio;
-       struct bio *next_bio;
-       int ret = 0;
-
-       if (bio_chain == NULL)
-               return 0;
-
-       bio = *bio_chain;
-       if (bio == NULL)
-               return 0;
-       while (bio) {
-               struct page *page;
-
-               next_bio = bio->bi_private;
-               page = bio->bi_io_vec[0].bv_page;
-               wait_on_page_locked(page);
-               if (!PageUptodate(page) || PageError(page))
-                       ret = -EIO;
-               put_page(page);
-               bio_put(bio);
-               bio = next_bio;
-       }
-       *bio_chain = NULL;
-       return ret;
-}
+struct block_device *hib_resume_bdev;
 
 /*
  * Saving part
  */
 
-static int mark_swapfiles(sector_t start, unsigned int flags)
+static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags)
 {
        int error;
 
-       bio_read_page(swsusp_resume_block, swsusp_header, NULL);
+       hib_bio_read_page(swsusp_resume_block, swsusp_header, NULL);
        if (!memcmp("SWAP-SPACE",swsusp_header->sig, 10) ||
            !memcmp("SWAPSPACE2",swsusp_header->sig, 10)) {
                memcpy(swsusp_header->orig_sig,swsusp_header->sig, 10);
                memcpy(swsusp_header->sig,SWSUSP_SIG, 10);
-               swsusp_header->image = start;
+               swsusp_header->image = handle->first_sector;
                swsusp_header->flags = flags;
-               error = bio_write_page(swsusp_resume_block,
+               error = hib_bio_write_page(swsusp_resume_block,
                                        swsusp_header, NULL);
        } else {
                printk(KERN_ERR "PM: Swap header not found!\n");
@@ -260,25 +208,26 @@ static int mark_swapfiles(sector_t start, unsigned int flags)
 /**
  *     swsusp_swap_check - check if the resume device is a swap device
  *     and get its index (if so)
+ *
+ *     This is called before saving image
  */
-
-static int swsusp_swap_check(void) /* This is called before saving image */
+static int swsusp_swap_check(void)
 {
        int res;
 
        res = swap_type_of(swsusp_resume_device, swsusp_resume_block,
-                       &resume_bdev);
+                       &hib_resume_bdev);
        if (res < 0)
                return res;
 
        root_swap = res;
-       res = blkdev_get(resume_bdev, FMODE_WRITE);
+       res = blkdev_get(hib_resume_bdev, FMODE_WRITE);
        if (res)
                return res;
 
-       res = set_blocksize(resume_bdev, PAGE_SIZE);
+       res = set_blocksize(hib_resume_bdev, PAGE_SIZE);
        if (res < 0)
-               blkdev_put(resume_bdev, FMODE_WRITE);
+               blkdev_put(hib_resume_bdev, FMODE_WRITE);
 
        return res;
 }
@@ -309,42 +258,9 @@ static int write_page(void *buf, sector_t offset, struct bio **bio_chain)
        } else {
                src = buf;
        }
-       return bio_write_page(offset, src, bio_chain);
+       return hib_bio_write_page(offset, src, bio_chain);
 }
 
-/*
- *     The swap map is a data structure used for keeping track of each page
- *     written to a swap partition.  It consists of many swap_map_page
- *     structures that contain each an array of MAP_PAGE_SIZE swap entries.
- *     These structures are stored on the swap and linked together with the
- *     help of the .next_swap member.
- *
- *     The swap map is created during suspend.  The swap map pages are
- *     allocated and populated one at a time, so we only need one memory
- *     page to set up the entire structure.
- *
- *     During resume we also only need to use one swap_map_page structure
- *     at a time.
- */
-
-#define MAP_PAGE_ENTRIES       (PAGE_SIZE / sizeof(sector_t) - 1)
-
-struct swap_map_page {
-       sector_t entries[MAP_PAGE_ENTRIES];
-       sector_t next_swap;
-};
-
-/**
- *     The swap_map_handle structure is used for handling swap in
- *     a file-alike way
- */
-
-struct swap_map_handle {
-       struct swap_map_page *cur;
-       sector_t cur_swap;
-       unsigned int k;
-};
-
 static void release_swap_writer(struct swap_map_handle *handle)
 {
        if (handle->cur)
@@ -354,16 +270,33 @@ static void release_swap_writer(struct swap_map_handle *handle)
 
 static int get_swap_writer(struct swap_map_handle *handle)
 {
+       int ret;
+
+       ret = swsusp_swap_check();
+       if (ret) {
+               if (ret != -ENOSPC)
+                       printk(KERN_ERR "PM: Cannot find swap device, try "
+                                       "swapon -a.\n");
+               return ret;
+       }
        handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
-       if (!handle->cur)
-               return -ENOMEM;
+       if (!handle->cur) {
+               ret = -ENOMEM;
+               goto err_close;
+       }
        handle->cur_swap = alloc_swapdev_block(root_swap);
        if (!handle->cur_swap) {
-               release_swap_writer(handle);
-               return -ENOSPC;
+               ret = -ENOSPC;
+               goto err_rel;
        }
        handle->k = 0;
+       handle->first_sector = handle->cur_swap;
        return 0;
+err_rel:
+       release_swap_writer(handle);
+err_close:
+       swsusp_close(FMODE_WRITE);
+       return ret;
 }
 
 static int swap_write_page(struct swap_map_handle *handle, void *buf,
@@ -380,7 +313,7 @@ static int swap_write_page(struct swap_map_handle *handle, void *buf,
                return error;
        handle->cur->entries[handle->k++] = offset;
        if (handle->k >= MAP_PAGE_ENTRIES) {
-               error = wait_on_bio_chain(bio_chain);
+               error = hib_wait_on_bio_chain(bio_chain);
                if (error)
                        goto out;
                offset = alloc_swapdev_block(root_swap);
@@ -406,6 +339,24 @@ static int flush_swap_writer(struct swap_map_handle *handle)
                return -EINVAL;
 }
 
+static int swap_writer_finish(struct swap_map_handle *handle,
+               unsigned int flags, int error)
+{
+       if (!error) {
+               flush_swap_writer(handle);
+               printk(KERN_INFO "PM: S");
+               error = mark_swapfiles(handle, flags);
+               printk("|\n");
+       }
+
+       if (error)
+               free_all_swap_pages(root_swap);
+       release_swap_writer(handle);
+       swsusp_close(FMODE_WRITE);
+
+       return error;
+}
+
 /**
  *     save_image - save the suspend image data
  */
@@ -431,7 +382,7 @@ static int save_image(struct swap_map_handle *handle,
        bio = NULL;
        do_gettimeofday(&start);
        while (1) {
-               ret = snapshot_read_next(snapshot, PAGE_SIZE);
+               ret = snapshot_read_next(snapshot);
                if (ret <= 0)
                        break;
                ret = swap_write_page(handle, data_of(*snapshot), &bio);
@@ -441,7 +392,7 @@ static int save_image(struct swap_map_handle *handle,
                        printk(KERN_CONT "\b\b\b\b%3d%%", nr_pages / m);
                nr_pages++;
        }
-       err2 = wait_on_bio_chain(&bio);
+       err2 = hib_wait_on_bio_chain(&bio);
        do_gettimeofday(&stop);
        if (!ret)
                ret = err2;
@@ -483,50 +434,34 @@ int swsusp_write(unsigned int flags)
        struct swap_map_handle handle;
        struct snapshot_handle snapshot;
        struct swsusp_info *header;
+       unsigned long pages;
        int error;
 
-       error = swsusp_swap_check();
+       pages = snapshot_get_image_size();
+       error = get_swap_writer(&handle);
        if (error) {
-               printk(KERN_ERR "PM: Cannot find swap device, try "
-                               "swapon -a.\n");
+               printk(KERN_ERR "PM: Cannot get swap writer\n");
                return error;
        }
+       if (!enough_swap(pages)) {
+               printk(KERN_ERR "PM: Not enough free swap\n");
+               error = -ENOSPC;
+               goto out_finish;
+       }
        memset(&snapshot, 0, sizeof(struct snapshot_handle));
-       error = snapshot_read_next(&snapshot, PAGE_SIZE);
+       error = snapshot_read_next(&snapshot);
        if (error < PAGE_SIZE) {
                if (error >= 0)
                        error = -EFAULT;
 
-               goto out;
+               goto out_finish;
        }
        header = (struct swsusp_info *)data_of(snapshot);
-       if (!enough_swap(header->pages)) {
-               printk(KERN_ERR "PM: Not enough free swap\n");
-               error = -ENOSPC;
-               goto out;
-       }
-       error = get_swap_writer(&handle);
-       if (!error) {
-               sector_t start = handle.cur_swap;
-
-               error = swap_write_page(&handle, header, NULL);
-               if (!error)
-                       error = save_image(&handle, &snapshot,
-                                       header->pages - 1);
-
-               if (!error) {
-                       flush_swap_writer(&handle);
-                       printk(KERN_INFO "PM: S");
-                       error = mark_swapfiles(start, flags);
-                       printk("|\n");
-               }
-       }
-       if (error)
-               free_all_swap_pages(root_swap);
-
-       release_swap_writer(&handle);
- out:
-       swsusp_close(FMODE_WRITE);
+       error = swap_write_page(&handle, header, NULL);
+       if (!error)
+               error = save_image(&handle, &snapshot, pages - 1);
+out_finish:
+       error = swap_writer_finish(&handle, flags, error);
        return error;
 }
 
@@ -542,18 +477,21 @@ static void release_swap_reader(struct swap_map_handle *handle)
        handle->cur = NULL;
 }
 
-static int get_swap_reader(struct swap_map_handle *handle, sector_t start)
+static int get_swap_reader(struct swap_map_handle *handle,
+               unsigned int *flags_p)
 {
        int error;
 
-       if (!start)
+       *flags_p = swsusp_header->flags;
+
+       if (!swsusp_header->image) /* how can this happen? */
                return -EINVAL;
 
        handle->cur = (struct swap_map_page *)get_zeroed_page(__GFP_WAIT | __GFP_HIGH);
        if (!handle->cur)
                return -ENOMEM;
 
-       error = bio_read_page(start, handle->cur, NULL);
+       error = hib_bio_read_page(swsusp_header->image, handle->cur, NULL);
        if (error) {
                release_swap_reader(handle);
                return error;
@@ -573,21 +511,28 @@ static int swap_read_page(struct swap_map_handle *handle, void *buf,
        offset = handle->cur->entries[handle->k];
        if (!offset)
                return -EFAULT;
-       error = bio_read_page(offset, buf, bio_chain);
+       error = hib_bio_read_page(offset, buf, bio_chain);
        if (error)
                return error;
        if (++handle->k >= MAP_PAGE_ENTRIES) {
-               error = wait_on_bio_chain(bio_chain);
+               error = hib_wait_on_bio_chain(bio_chain);
                handle->k = 0;
                offset = handle->cur->next_swap;
                if (!offset)
                        release_swap_reader(handle);
                else if (!error)
-                       error = bio_read_page(offset, handle->cur, NULL);
+                       error = hib_bio_read_page(offset, handle->cur, NULL);
        }
        return error;
 }
 
+static int swap_reader_finish(struct swap_map_handle *handle)
+{
+       release_swap_reader(handle);
+
+       return 0;
+}
+
 /**
  *     load_image - load the image using the swap map handle
  *     @handle and the snapshot handle @snapshot
@@ -615,21 +560,21 @@ static int load_image(struct swap_map_handle *handle,
        bio = NULL;
        do_gettimeofday(&start);
        for ( ; ; ) {
-               error = snapshot_write_next(snapshot, PAGE_SIZE);
+               error = snapshot_write_next(snapshot);
                if (error <= 0)
                        break;
                error = swap_read_page(handle, data_of(*snapshot), &bio);
                if (error)
                        break;
                if (snapshot->sync_read)
-                       error = wait_on_bio_chain(&bio);
+                       error = hib_wait_on_bio_chain(&bio);
                if (error)
                        break;
                if (!(nr_pages % m))
                        printk("\b\b\b\b%3d%%", nr_pages / m);
                nr_pages++;
        }
-       err2 = wait_on_bio_chain(&bio);
+       err2 = hib_wait_on_bio_chain(&bio);
        do_gettimeofday(&stop);
        if (!error)
                error = err2;
@@ -657,20 +602,20 @@ int swsusp_read(unsigned int *flags_p)
        struct snapshot_handle snapshot;
        struct swsusp_info *header;
 
-       *flags_p = swsusp_header->flags;
-
        memset(&snapshot, 0, sizeof(struct snapshot_handle));
-       error = snapshot_write_next(&snapshot, PAGE_SIZE);
+       error = snapshot_write_next(&snapshot);
        if (error < PAGE_SIZE)
                return error < 0 ? error : -EFAULT;
        header = (struct swsusp_info *)data_of(snapshot);
-       error = get_swap_reader(&handle, swsusp_header->image);
+       error = get_swap_reader(&handle, flags_p);
+       if (error)
+               goto end;
        if (!error)
                error = swap_read_page(&handle, header, NULL);
        if (!error)
                error = load_image(&handle, &snapshot, header->pages - 1);
-       release_swap_reader(&handle);
-
+       swap_reader_finish(&handle);
+end:
        if (!error)
                pr_debug("PM: Image successfully loaded\n");
        else
@@ -686,11 +631,11 @@ int swsusp_check(void)
 {
        int error;
 
-       resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
-       if (!IS_ERR(resume_bdev)) {
-               set_blocksize(resume_bdev, PAGE_SIZE);
+       hib_resume_bdev = open_by_devnum(swsusp_resume_device, FMODE_READ);
+       if (!IS_ERR(hib_resume_bdev)) {
+               set_blocksize(hib_resume_bdev, PAGE_SIZE);
                memset(swsusp_header, 0, PAGE_SIZE);
-               error = bio_read_page(swsusp_resume_block,
+               error = hib_bio_read_page(swsusp_resume_block,
                                        swsusp_header, NULL);
                if (error)
                        goto put;
@@ -698,7 +643,7 @@ int swsusp_check(void)
                if (!memcmp(SWSUSP_SIG, swsusp_header->sig, 10)) {
                        memcpy(swsusp_header->sig, swsusp_header->orig_sig, 10);
                        /* Reset swap signature now */
-                       error = bio_write_page(swsusp_resume_block,
+                       error = hib_bio_write_page(swsusp_resume_block,
                                                swsusp_header, NULL);
                } else {
                        error = -EINVAL;
@@ -706,11 +651,11 @@ int swsusp_check(void)
 
 put:
                if (error)
-                       blkdev_put(resume_bdev, FMODE_READ);
+                       blkdev_put(hib_resume_bdev, FMODE_READ);
                else
                        pr_debug("PM: Signature found, resuming\n");
        } else {
-               error = PTR_ERR(resume_bdev);
+               error = PTR_ERR(hib_resume_bdev);
        }
 
        if (error)
@@ -725,12 +670,12 @@ put:
 
 void swsusp_close(fmode_t mode)
 {
-       if (IS_ERR(resume_bdev)) {
+       if (IS_ERR(hib_resume_bdev)) {
                pr_debug("PM: Image device not initialised\n");
                return;
        }
 
-       blkdev_put(resume_bdev, mode);
+       blkdev_put(hib_resume_bdev, mode);
 }
 
 static int swsusp_header_init(void)
index a8c9621..e819e17 100644 (file)
@@ -151,6 +151,7 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
 {
        struct snapshot_data *data;
        ssize_t res;
+       loff_t pg_offp = *offp & ~PAGE_MASK;
 
        mutex_lock(&pm_mutex);
 
@@ -159,14 +160,19 @@ static ssize_t snapshot_read(struct file *filp, char __user *buf,
                res = -ENODATA;
                goto Unlock;
        }
-       res = snapshot_read_next(&data->handle, count);
-       if (res > 0) {
-               if (copy_to_user(buf, data_of(data->handle), res))
-                       res = -EFAULT;
-               else
-                       *offp = data->handle.offset;
+       if (!pg_offp) { /* on page boundary? */
+               res = snapshot_read_next(&data->handle);
+               if (res <= 0)
+                       goto Unlock;
+       } else {
+               res = PAGE_SIZE - pg_offp;
        }
 
+       res = simple_read_from_buffer(buf, count, &pg_offp,
+                       data_of(data->handle), res);
+       if (res > 0)
+               *offp += res;
+
  Unlock:
        mutex_unlock(&pm_mutex);
 
@@ -178,18 +184,25 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf,
 {
        struct snapshot_data *data;
        ssize_t res;
+       loff_t pg_offp = *offp & ~PAGE_MASK;
 
        mutex_lock(&pm_mutex);
 
        data = filp->private_data;
-       res = snapshot_write_next(&data->handle, count);
-       if (res > 0) {
-               if (copy_from_user(data_of(data->handle), buf, res))
-                       res = -EFAULT;
-               else
-                       *offp = data->handle.offset;
+
+       if (!pg_offp) {
+               res = snapshot_write_next(&data->handle);
+               if (res <= 0)
+                       goto unlock;
+       } else {
+               res = PAGE_SIZE - pg_offp;
        }
 
+       res = simple_write_to_buffer(data_of(data->handle), res, &pg_offp,
+                       buf, count);
+       if (res > 0)
+               *offp += res;
+unlock:
        mutex_unlock(&pm_mutex);
 
        return res;
index 42ad8ae..6af9cdd 100644 (file)
@@ -14,7 +14,6 @@
 #include <linux/mm.h>
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
-#include <linux/smp_lock.h>
 #include <linux/ptrace.h>
 #include <linux/security.h>
 #include <linux/signal.h>
@@ -76,7 +75,6 @@ void __ptrace_unlink(struct task_struct *child)
        child->parent = child->real_parent;
        list_del_init(&child->ptrace_entry);
 
-       arch_ptrace_untrace(child);
        if (task_is_traced(child))
                ptrace_untrace(child);
 }
@@ -666,10 +664,6 @@ 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)
@@ -703,7 +697,6 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data)
  out_put_task_struct:
        put_task_struct(child);
  out:
-       unlock_kernel();
        return ret;
 }
 
@@ -813,10 +806,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
        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;
@@ -846,7 +835,6 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
  out_put_task_struct:
        put_task_struct(child);
  out:
-       unlock_kernel();
        return ret;
 }
 #endif /* CONFIG_COMPAT */
index 49d808e..72a8dc9 100644 (file)
@@ -44,7 +44,6 @@
 #include <linux/cpu.h>
 #include <linux/mutex.h>
 #include <linux/module.h>
-#include <linux/kernel_stat.h>
 #include <linux/hardirq.h>
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
@@ -64,9 +63,6 @@ struct lockdep_map rcu_sched_lock_map =
 EXPORT_SYMBOL_GPL(rcu_sched_lock_map);
 #endif
 
-int rcu_scheduler_active __read_mostly;
-EXPORT_SYMBOL_GPL(rcu_scheduler_active);
-
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 
 int debug_lockdep_rcu_enabled(void)
@@ -96,21 +92,6 @@ EXPORT_SYMBOL_GPL(rcu_read_lock_bh_held);
 
 #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
 
-/*
- * This function is invoked towards the end of the scheduler's initialization
- * process.  Before this is called, the idle task might contain
- * RCU read-side critical sections (during which time, this idle
- * task is booting the system).  After this function is called, the
- * idle tasks are prohibited from containing RCU read-side critical
- * sections.
- */
-void rcu_scheduler_starting(void)
-{
-       WARN_ON(num_online_cpus() != 1);
-       WARN_ON(nr_context_switches() > 0);
-       rcu_scheduler_active = 1;
-}
-
 /*
  * Awaken the corresponding synchronize_rcu() instance now that a
  * grace period has elapsed.
index 9f6d9ff..38729d3 100644 (file)
@@ -44,9 +44,9 @@ struct rcu_ctrlblk {
 };
 
 /* Definition for rcupdate control block. */
-static struct rcu_ctrlblk rcu_ctrlblk = {
-       .donetail       = &rcu_ctrlblk.rcucblist,
-       .curtail        = &rcu_ctrlblk.rcucblist,
+static struct rcu_ctrlblk rcu_sched_ctrlblk = {
+       .donetail       = &rcu_sched_ctrlblk.rcucblist,
+       .curtail        = &rcu_sched_ctrlblk.rcucblist,
 };
 
 static struct rcu_ctrlblk rcu_bh_ctrlblk = {
@@ -54,6 +54,11 @@ static struct rcu_ctrlblk rcu_bh_ctrlblk = {
        .curtail        = &rcu_bh_ctrlblk.rcucblist,
 };
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+int rcu_scheduler_active __read_mostly;
+EXPORT_SYMBOL_GPL(rcu_scheduler_active);
+#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+
 #ifdef CONFIG_NO_HZ
 
 static long rcu_dynticks_nesting = 1;
@@ -108,7 +113,8 @@ static int rcu_qsctr_help(struct rcu_ctrlblk *rcp)
  */
 void rcu_sched_qs(int cpu)
 {
-       if (rcu_qsctr_help(&rcu_ctrlblk) + rcu_qsctr_help(&rcu_bh_ctrlblk))
+       if (rcu_qsctr_help(&rcu_sched_ctrlblk) +
+           rcu_qsctr_help(&rcu_bh_ctrlblk))
                raise_softirq(RCU_SOFTIRQ);
 }
 
@@ -173,7 +179,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
  */
 static void rcu_process_callbacks(struct softirq_action *unused)
 {
-       __rcu_process_callbacks(&rcu_ctrlblk);
+       __rcu_process_callbacks(&rcu_sched_ctrlblk);
        __rcu_process_callbacks(&rcu_bh_ctrlblk);
 }
 
@@ -187,7 +193,8 @@ static void rcu_process_callbacks(struct softirq_action *unused)
  *
  * Cool, huh?  (Due to Josh Triplett.)
  *
- * But we want to make this a static inline later.
+ * But we want to make this a static inline later.  The cond_resched()
+ * currently makes this problematic.
  */
 void synchronize_sched(void)
 {
@@ -195,12 +202,6 @@ void synchronize_sched(void)
 }
 EXPORT_SYMBOL_GPL(synchronize_sched);
 
-void synchronize_rcu_bh(void)
-{
-       synchronize_sched();
-}
-EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
-
 /*
  * Helper function for call_rcu() and call_rcu_bh().
  */
@@ -226,7 +227,7 @@ static void __call_rcu(struct rcu_head *head,
  */
 void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
 {
-       __call_rcu(head, func, &rcu_ctrlblk);
+       __call_rcu(head, func, &rcu_sched_ctrlblk);
 }
 EXPORT_SYMBOL_GPL(call_rcu);
 
@@ -244,11 +245,13 @@ void rcu_barrier(void)
 {
        struct rcu_synchronize rcu;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(rcu_barrier);
 
@@ -256,11 +259,13 @@ void rcu_barrier_bh(void)
 {
        struct rcu_synchronize rcu;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu_bh(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(rcu_barrier_bh);
 
@@ -268,11 +273,13 @@ void rcu_barrier_sched(void)
 {
        struct rcu_synchronize rcu;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu_sched(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(rcu_barrier_sched);
 
@@ -280,3 +287,5 @@ void __init rcu_init(void)
 {
        open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
 }
+
+#include "rcutiny_plugin.h"
diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
new file mode 100644 (file)
index 0000000..d223a92
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Read-Copy Update mechanism for mutual exclusion (tree-based version)
+ * Internal non-public definitions that provide either classic
+ * or preemptable semantics.
+ *
+ * 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.
+ *
+ * Copyright IBM Corporation, 2009
+ *
+ * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
+ */
+
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+
+#include <linux/kernel_stat.h>
+
+/*
+ * During boot, we forgive RCU lockdep issues.  After this function is
+ * invoked, we start taking RCU lockdep issues seriously.
+ */
+void rcu_scheduler_starting(void)
+{
+       WARN_ON(nr_context_switches() > 0);
+       rcu_scheduler_active = 1;
+}
+
+#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
index 58df55b..6535ac8 100644 (file)
@@ -464,9 +464,11 @@ static void rcu_bh_torture_synchronize(void)
 {
        struct rcu_bh_torture_synchronize rcu;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        call_rcu_bh(&rcu.head, rcu_bh_torture_wakeme_after_cb);
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 
 static struct rcu_torture_ops rcu_bh_ops = {
@@ -669,7 +671,7 @@ static struct rcu_torture_ops sched_expedited_ops = {
        .sync           = synchronize_sched_expedited,
        .cb_barrier     = NULL,
        .fqs            = rcu_sched_force_quiescent_state,
-       .stats          = rcu_expedited_torture_stats,
+       .stats          = NULL,
        .irq_capable    = 1,
        .name           = "sched_expedited"
 };
index 3ec8160..d443734 100644 (file)
@@ -46,6 +46,7 @@
 #include <linux/cpu.h>
 #include <linux/mutex.h>
 #include <linux/time.h>
+#include <linux/kernel_stat.h>
 
 #include "rcutree.h"
 
@@ -53,8 +54,8 @@
 
 static struct lock_class_key rcu_node_class[NUM_RCU_LVLS];
 
-#define RCU_STATE_INITIALIZER(name) { \
-       .level = { &name.node[0] }, \
+#define RCU_STATE_INITIALIZER(structname) { \
+       .level = { &structname.node[0] }, \
        .levelcnt = { \
                NUM_RCU_LVL_0,  /* root of hierarchy. */ \
                NUM_RCU_LVL_1, \
@@ -65,13 +66,14 @@ static struct lock_class_key rcu_node_class[NUM_RCU_LVLS];
        .signaled = RCU_GP_IDLE, \
        .gpnum = -300, \
        .completed = -300, \
-       .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&name.onofflock), \
+       .onofflock = __RAW_SPIN_LOCK_UNLOCKED(&structname.onofflock), \
        .orphan_cbs_list = NULL, \
-       .orphan_cbs_tail = &name.orphan_cbs_list, \
+       .orphan_cbs_tail = &structname.orphan_cbs_list, \
        .orphan_qlen = 0, \
-       .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&name.fqslock), \
+       .fqslock = __RAW_SPIN_LOCK_UNLOCKED(&structname.fqslock), \
        .n_force_qs = 0, \
        .n_force_qs_ngp = 0, \
+       .name = #structname, \
 }
 
 struct rcu_state rcu_sched_state = RCU_STATE_INITIALIZER(rcu_sched_state);
@@ -80,6 +82,9 @@ DEFINE_PER_CPU(struct rcu_data, rcu_sched_data);
 struct rcu_state rcu_bh_state = RCU_STATE_INITIALIZER(rcu_bh_state);
 DEFINE_PER_CPU(struct rcu_data, rcu_bh_data);
 
+int rcu_scheduler_active __read_mostly;
+EXPORT_SYMBOL_GPL(rcu_scheduler_active);
+
 /*
  * Return true if an RCU grace period is in progress.  The ACCESS_ONCE()s
  * permit this function to be invoked without holding the root rcu_node
@@ -97,25 +102,32 @@ static int rcu_gp_in_progress(struct rcu_state *rsp)
  */
 void rcu_sched_qs(int cpu)
 {
-       struct rcu_data *rdp;
+       struct rcu_data *rdp = &per_cpu(rcu_sched_data, cpu);
 
-       rdp = &per_cpu(rcu_sched_data, cpu);
        rdp->passed_quiesc_completed = rdp->gpnum - 1;
        barrier();
        rdp->passed_quiesc = 1;
-       rcu_preempt_note_context_switch(cpu);
 }
 
 void rcu_bh_qs(int cpu)
 {
-       struct rcu_data *rdp;
+       struct rcu_data *rdp = &per_cpu(rcu_bh_data, cpu);
 
-       rdp = &per_cpu(rcu_bh_data, cpu);
        rdp->passed_quiesc_completed = rdp->gpnum - 1;
        barrier();
        rdp->passed_quiesc = 1;
 }
 
+/*
+ * Note a context switch.  This is a quiescent state for RCU-sched,
+ * and requires special handling for preemptible RCU.
+ */
+void rcu_note_context_switch(int cpu)
+{
+       rcu_sched_qs(cpu);
+       rcu_preempt_note_context_switch(cpu);
+}
+
 #ifdef CONFIG_NO_HZ
 DEFINE_PER_CPU(struct rcu_dynticks, rcu_dynticks) = {
        .dynticks_nesting = 1,
@@ -438,6 +450,8 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
 
 #ifdef CONFIG_RCU_CPU_STALL_DETECTOR
 
+int rcu_cpu_stall_panicking __read_mostly;
+
 static void record_gp_stall_check_time(struct rcu_state *rsp)
 {
        rsp->gp_start = jiffies;
@@ -470,7 +484,8 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
 
        /* OK, time to rat on our buddy... */
 
-       printk(KERN_ERR "INFO: RCU detected CPU stalls:");
+       printk(KERN_ERR "INFO: %s detected stalls on CPUs/tasks: {",
+              rsp->name);
        rcu_for_each_leaf_node(rsp, rnp) {
                raw_spin_lock_irqsave(&rnp->lock, flags);
                rcu_print_task_stall(rnp);
@@ -481,7 +496,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
                        if (rnp->qsmask & (1UL << cpu))
                                printk(" %d", rnp->grplo + cpu);
        }
-       printk(" (detected by %d, t=%ld jiffies)\n",
+       printk("} (detected by %d, t=%ld jiffies)\n",
               smp_processor_id(), (long)(jiffies - rsp->gp_start));
        trigger_all_cpu_backtrace();
 
@@ -497,8 +512,8 @@ static void print_cpu_stall(struct rcu_state *rsp)
        unsigned long flags;
        struct rcu_node *rnp = rcu_get_root(rsp);
 
-       printk(KERN_ERR "INFO: RCU detected CPU %d stall (t=%lu jiffies)\n",
-                       smp_processor_id(), jiffies - rsp->gp_start);
+       printk(KERN_ERR "INFO: %s detected stall on CPU %d (t=%lu jiffies)\n",
+              rsp->name, smp_processor_id(), jiffies - rsp->gp_start);
        trigger_all_cpu_backtrace();
 
        raw_spin_lock_irqsave(&rnp->lock, flags);
@@ -515,6 +530,8 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
        long delta;
        struct rcu_node *rnp;
 
+       if (rcu_cpu_stall_panicking)
+               return;
        delta = jiffies - rsp->jiffies_stall;
        rnp = rdp->mynode;
        if ((rnp->qsmask & rdp->grpmask) && delta >= 0) {
@@ -529,6 +546,21 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
        }
 }
 
+static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)
+{
+       rcu_cpu_stall_panicking = 1;
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block rcu_panic_block = {
+       .notifier_call = rcu_panic,
+};
+
+static void __init check_cpu_stall_init(void)
+{
+       atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);
+}
+
 #else /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
 
 static void record_gp_stall_check_time(struct rcu_state *rsp)
@@ -539,6 +571,10 @@ static void check_cpu_stall(struct rcu_state *rsp, struct rcu_data *rdp)
 {
 }
 
+static void __init check_cpu_stall_init(void)
+{
+}
+
 #endif /* #else #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
 
 /*
@@ -1125,8 +1161,6 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
  */
 void rcu_check_callbacks(int cpu, int user)
 {
-       if (!rcu_pending(cpu))
-               return; /* if nothing for RCU to do. */
        if (user ||
            (idle_cpu(cpu) && rcu_scheduler_active &&
             !in_softirq() && hardirq_count() <= (1 << HARDIRQ_SHIFT))) {
@@ -1158,7 +1192,8 @@ void rcu_check_callbacks(int cpu, int user)
                rcu_bh_qs(cpu);
        }
        rcu_preempt_check_callbacks(cpu);
-       raise_softirq(RCU_SOFTIRQ);
+       if (rcu_pending(cpu))
+               raise_softirq(RCU_SOFTIRQ);
 }
 
 #ifdef CONFIG_SMP
@@ -1236,11 +1271,11 @@ static void force_quiescent_state(struct rcu_state *rsp, int relaxed)
                break; /* grace period idle or initializing, ignore. */
 
        case RCU_SAVE_DYNTICK:
-
-               raw_spin_unlock(&rnp->lock);  /* irqs remain disabled */
                if (RCU_SIGNAL_INIT != RCU_SAVE_DYNTICK)
                        break; /* So gcc recognizes the dead code. */
 
+               raw_spin_unlock(&rnp->lock);  /* irqs remain disabled */
+
                /* Record dyntick-idle state. */
                force_qs_rnp(rsp, dyntick_save_progress_counter);
                raw_spin_lock(&rnp->lock);  /* irqs already disabled */
@@ -1449,11 +1484,13 @@ void synchronize_sched(void)
        if (rcu_blocking_is_gp())
                return;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu_sched(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(synchronize_sched);
 
@@ -1473,11 +1510,13 @@ void synchronize_rcu_bh(void)
        if (rcu_blocking_is_gp())
                return;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu_bh(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
 
@@ -1498,8 +1537,20 @@ static int __rcu_pending(struct rcu_state *rsp, struct rcu_data *rdp)
        check_cpu_stall(rsp, rdp);
 
        /* Is the RCU core waiting for a quiescent state from this CPU? */
-       if (rdp->qs_pending) {
+       if (rdp->qs_pending && !rdp->passed_quiesc) {
+
+               /*
+                * If force_quiescent_state() coming soon and this CPU
+                * needs a quiescent state, and this is either RCU-sched
+                * or RCU-bh, force a local reschedule.
+                */
                rdp->n_rp_qs_pending++;
+               if (!rdp->preemptable &&
+                   ULONG_CMP_LT(ACCESS_ONCE(rsp->jiffies_force_qs) - 1,
+                                jiffies))
+                       set_need_resched();
+       } else if (rdp->qs_pending && rdp->passed_quiesc) {
+               rdp->n_rp_report_qs++;
                return 1;
        }
 
@@ -1766,6 +1817,21 @@ static int __cpuinit rcu_cpu_notify(struct notifier_block *self,
        return NOTIFY_OK;
 }
 
+/*
+ * This function is invoked towards the end of the scheduler's initialization
+ * process.  Before this is called, the idle task might contain
+ * RCU read-side critical sections (during which time, this idle
+ * task is booting the system).  After this function is called, the
+ * idle tasks are prohibited from containing RCU read-side critical
+ * sections.  This function also enables RCU lockdep checking.
+ */
+void rcu_scheduler_starting(void)
+{
+       WARN_ON(num_online_cpus() != 1);
+       WARN_ON(nr_context_switches() > 0);
+       rcu_scheduler_active = 1;
+}
+
 /*
  * Compute the per-level fanout, either using the exact fanout specified
  * or balancing the tree, depending on CONFIG_RCU_FANOUT_EXACT.
@@ -1849,6 +1915,14 @@ static void __init rcu_init_one(struct rcu_state *rsp)
                        INIT_LIST_HEAD(&rnp->blocked_tasks[3]);
                }
        }
+
+       rnp = rsp->level[NUM_RCU_LVLS - 1];
+       for_each_possible_cpu(i) {
+               while (i > rnp->grphi)
+                       rnp++;
+               rsp->rda[i]->mynode = rnp;
+               rcu_boot_init_percpu_data(i, rsp);
+       }
 }
 
 /*
@@ -1859,19 +1933,11 @@ static void __init rcu_init_one(struct rcu_state *rsp)
 #define RCU_INIT_FLAVOR(rsp, rcu_data) \
 do { \
        int i; \
-       int j; \
-       struct rcu_node *rnp; \
        \
-       rcu_init_one(rsp); \
-       rnp = (rsp)->level[NUM_RCU_LVLS - 1]; \
-       j = 0; \
        for_each_possible_cpu(i) { \
-               if (i > rnp[j].grphi) \
-                       j++; \
-               per_cpu(rcu_data, i).mynode = &rnp[j]; \
                (rsp)->rda[i] = &per_cpu(rcu_data, i); \
-               rcu_boot_init_percpu_data(i, rsp); \
        } \
+       rcu_init_one(rsp); \
 } while (0)
 
 void __init rcu_init(void)
@@ -1879,12 +1945,6 @@ void __init rcu_init(void)
        int cpu;
 
        rcu_bootup_announce();
-#ifdef CONFIG_RCU_CPU_STALL_DETECTOR
-       printk(KERN_INFO "RCU-based detection of stalled CPUs is enabled.\n");
-#endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
-#if NUM_RCU_LVL_4 != 0
-       printk(KERN_INFO "Experimental four-level hierarchy is enabled.\n");
-#endif /* #if NUM_RCU_LVL_4 != 0 */
        RCU_INIT_FLAVOR(&rcu_sched_state, rcu_sched_data);
        RCU_INIT_FLAVOR(&rcu_bh_state, rcu_bh_data);
        __rcu_init_preempt();
@@ -1898,6 +1958,7 @@ void __init rcu_init(void)
        cpu_notifier(rcu_cpu_notify, 0);
        for_each_online_cpu(cpu)
                rcu_cpu_notify(NULL, CPU_UP_PREPARE, (void *)(long)cpu);
+       check_cpu_stall_init();
 }
 
 #include "rcutree_plugin.h"
index 4a525a3..14c040b 100644 (file)
@@ -223,6 +223,7 @@ struct rcu_data {
        /* 5) __rcu_pending() statistics. */
        unsigned long n_rcu_pending;    /* rcu_pending() calls since boot. */
        unsigned long n_rp_qs_pending;
+       unsigned long n_rp_report_qs;
        unsigned long n_rp_cb_ready;
        unsigned long n_rp_cpu_needs_gp;
        unsigned long n_rp_gp_completed;
@@ -326,6 +327,7 @@ struct rcu_state {
        unsigned long jiffies_stall;            /* Time at which to check */
                                                /*  for CPU stalls. */
 #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */
+       char *name;                             /* Name of structure. */
 };
 
 /* Return values for rcu_preempt_offline_tasks(). */
index 79b53bd..0e4f420 100644 (file)
 
 #include <linux/delay.h>
 
+/*
+ * Check the RCU kernel configuration parameters and print informative
+ * messages about anything out of the ordinary.  If you like #ifdef, you
+ * will love this function.
+ */
+static void __init rcu_bootup_announce_oddness(void)
+{
+#ifdef CONFIG_RCU_TRACE
+       printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n");
+#endif
+#if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)
+       printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
+              CONFIG_RCU_FANOUT);
+#endif
+#ifdef CONFIG_RCU_FANOUT_EXACT
+       printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n");
+#endif
+#ifdef CONFIG_RCU_FAST_NO_HZ
+       printk(KERN_INFO
+              "\tRCU dyntick-idle grace-period acceleration is enabled.\n");
+#endif
+#ifdef CONFIG_PROVE_RCU
+       printk(KERN_INFO "\tRCU lockdep checking is enabled.\n");
+#endif
+#ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE
+       printk(KERN_INFO "\tRCU torture testing starts during boot.\n");
+#endif
+#ifndef CONFIG_RCU_CPU_STALL_DETECTOR
+       printk(KERN_INFO
+              "\tRCU-based detection of stalled CPUs is disabled.\n");
+#endif
+#ifndef CONFIG_RCU_CPU_STALL_VERBOSE
+       printk(KERN_INFO "\tVerbose stalled-CPUs detection is disabled.\n");
+#endif
+#if NUM_RCU_LVL_4 != 0
+       printk(KERN_INFO "\tExperimental four-level hierarchy is enabled.\n");
+#endif
+}
+
 #ifdef CONFIG_TREE_PREEMPT_RCU
 
 struct rcu_state rcu_preempt_state = RCU_STATE_INITIALIZER(rcu_preempt_state);
@@ -38,8 +77,8 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp);
  */
 static void __init rcu_bootup_announce(void)
 {
-       printk(KERN_INFO
-              "Experimental preemptable hierarchical RCU implementation.\n");
+       printk(KERN_INFO "Preemptable hierarchical RCU implementation.\n");
+       rcu_bootup_announce_oddness();
 }
 
 /*
@@ -75,13 +114,19 @@ EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
  * that this just means that the task currently running on the CPU is
  * not in a quiescent state.  There might be any number of tasks blocked
  * while in an RCU read-side critical section.
+ *
+ * Unlike the other rcu_*_qs() functions, callers to this function
+ * must disable irqs in order to protect the assignment to
+ * ->rcu_read_unlock_special.
  */
 static void rcu_preempt_qs(int cpu)
 {
        struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
+
        rdp->passed_quiesc_completed = rdp->gpnum - 1;
        barrier();
        rdp->passed_quiesc = 1;
+       current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
 }
 
 /*
@@ -144,9 +189,8 @@ static void rcu_preempt_note_context_switch(int cpu)
         * grace period, then the fact that the task has been enqueued
         * means that we continue to block the current grace period.
         */
-       rcu_preempt_qs(cpu);
        local_irq_save(flags);
-       t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
+       rcu_preempt_qs(cpu);
        local_irq_restore(flags);
 }
 
@@ -236,7 +280,6 @@ static void rcu_read_unlock_special(struct task_struct *t)
         */
        special = t->rcu_read_unlock_special;
        if (special & RCU_READ_UNLOCK_NEED_QS) {
-               t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
                rcu_preempt_qs(smp_processor_id());
        }
 
@@ -473,7 +516,6 @@ static void rcu_preempt_check_callbacks(int cpu)
        struct task_struct *t = current;
 
        if (t->rcu_read_lock_nesting == 0) {
-               t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
                rcu_preempt_qs(cpu);
                return;
        }
@@ -515,11 +557,13 @@ void synchronize_rcu(void)
        if (!rcu_scheduler_active)
                return;
 
+       init_rcu_head_on_stack(&rcu.head);
        init_completion(&rcu.completion);
        /* Will wake me after RCU finished. */
        call_rcu(&rcu.head, wakeme_after_rcu);
        /* Wait for it. */
        wait_for_completion(&rcu.completion);
+       destroy_rcu_head_on_stack(&rcu.head);
 }
 EXPORT_SYMBOL_GPL(synchronize_rcu);
 
@@ -754,6 +798,7 @@ void exit_rcu(void)
 static void __init rcu_bootup_announce(void)
 {
        printk(KERN_INFO "Hierarchical RCU implementation.\n");
+       rcu_bootup_announce_oddness();
 }
 
 /*
@@ -1008,6 +1053,8 @@ static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
 int rcu_needs_cpu(int cpu)
 {
        int c = 0;
+       int snap;
+       int snap_nmi;
        int thatcpu;
 
        /* Check for being in the holdoff period. */
@@ -1015,12 +1062,18 @@ int rcu_needs_cpu(int cpu)
                return rcu_needs_cpu_quick_check(cpu);
 
        /* Don't bother unless we are the last non-dyntick-idle CPU. */
-       for_each_cpu_not(thatcpu, nohz_cpu_mask)
-               if (thatcpu != cpu) {
+       for_each_online_cpu(thatcpu) {
+               if (thatcpu == cpu)
+                       continue;
+               snap = per_cpu(rcu_dynticks, thatcpu).dynticks;
+               snap_nmi = per_cpu(rcu_dynticks, thatcpu).dynticks_nmi;
+               smp_mb(); /* Order sampling of snap with end of grace period. */
+               if (((snap & 0x1) != 0) || ((snap_nmi & 0x1) != 0)) {
                        per_cpu(rcu_dyntick_drain, cpu) = 0;
                        per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
                        return rcu_needs_cpu_quick_check(cpu);
                }
+       }
 
        /* Check and update the rcu_dyntick_drain sequencing. */
        if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
index d45db2e..36c95b4 100644 (file)
@@ -241,11 +241,13 @@ static const struct file_operations rcugp_fops = {
 static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
 {
        seq_printf(m, "%3d%cnp=%ld "
-                  "qsp=%ld cbr=%ld cng=%ld gpc=%ld gps=%ld nf=%ld nn=%ld\n",
+                  "qsp=%ld rpq=%ld cbr=%ld cng=%ld "
+                  "gpc=%ld gps=%ld nf=%ld nn=%ld\n",
                   rdp->cpu,
                   cpu_is_offline(rdp->cpu) ? '!' : ' ',
                   rdp->n_rcu_pending,
                   rdp->n_rp_qs_pending,
+                  rdp->n_rp_report_qs,
                   rdp->n_rp_cb_ready,
                   rdp->n_rp_cpu_needs_gp,
                   rdp->n_rp_gp_completed,
index 3c2a54f..1d93cd0 100644 (file)
@@ -55,9 +55,9 @@
 #include <linux/cpu.h>
 #include <linux/cpuset.h>
 #include <linux/percpu.h>
-#include <linux/kthread.h>
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
+#include <linux/stop_machine.h>
 #include <linux/sysctl.h>
 #include <linux/syscalls.h>
 #include <linux/times.h>
@@ -503,8 +503,11 @@ struct rq {
        #define CPU_LOAD_IDX_MAX 5
        unsigned long cpu_load[CPU_LOAD_IDX_MAX];
 #ifdef CONFIG_NO_HZ
+       u64 nohz_stamp;
        unsigned char in_nohz_recently;
 #endif
+       unsigned int skip_clock_update;
+
        /* capture load from *all* tasks on this cpu: */
        struct load_weight load;
        unsigned long nr_load_updates;
@@ -546,15 +549,13 @@ struct rq {
        int post_schedule;
        int active_balance;
        int push_cpu;
+       struct cpu_stop_work active_balance_work;
        /* cpu of this runqueue: */
        int cpu;
        int online;
 
        unsigned long avg_load_per_task;
 
-       struct task_struct *migration_thread;
-       struct list_head migration_queue;
-
        u64 rt_avg;
        u64 age_stamp;
        u64 idle_stamp;
@@ -602,6 +603,13 @@ static inline
 void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags)
 {
        rq->curr->sched_class->check_preempt_curr(rq, p, flags);
+
+       /*
+        * A queue event has occurred, and we're going to schedule.  In
+        * this case, we can save a useless back to back clock update.
+        */
+       if (test_tsk_need_resched(p))
+               rq->skip_clock_update = 1;
 }
 
 static inline int cpu_of(struct rq *rq)
@@ -636,7 +644,8 @@ static inline int cpu_of(struct rq *rq)
 
 inline void update_rq_clock(struct rq *rq)
 {
-       rq->clock = sched_clock_cpu(cpu_of(rq));
+       if (!rq->skip_clock_update)
+               rq->clock = sched_clock_cpu(cpu_of(rq));
 }
 
 /*
@@ -914,16 +923,12 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev)
 #endif /* __ARCH_WANT_UNLOCKED_CTXSW */
 
 /*
- * Check whether the task is waking, we use this to synchronize against
- * ttwu() so that task_cpu() reports a stable number.
- *
- * We need to make an exception for PF_STARTING tasks because the fork
- * path might require task_rq_lock() to work, eg. it can call
- * set_cpus_allowed_ptr() from the cpuset clone_ns code.
+ * Check whether the task is waking, we use this to synchronize ->cpus_allowed
+ * against ttwu().
  */
 static inline int task_is_waking(struct task_struct *p)
 {
-       return unlikely((p->state == TASK_WAKING) && !(p->flags & PF_STARTING));
+       return unlikely(p->state == TASK_WAKING);
 }
 
 /*
@@ -936,11 +941,9 @@ static inline struct rq *__task_rq_lock(struct task_struct *p)
        struct rq *rq;
 
        for (;;) {
-               while (task_is_waking(p))
-                       cpu_relax();
                rq = task_rq(p);
                raw_spin_lock(&rq->lock);
-               if (likely(rq == task_rq(p) && !task_is_waking(p)))
+               if (likely(rq == task_rq(p)))
                        return rq;
                raw_spin_unlock(&rq->lock);
        }
@@ -957,12 +960,10 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags)
        struct rq *rq;
 
        for (;;) {
-               while (task_is_waking(p))
-                       cpu_relax();
                local_irq_save(*flags);
                rq = task_rq(p);
                raw_spin_lock(&rq->lock);
-               if (likely(rq == task_rq(p) && !task_is_waking(p)))
+               if (likely(rq == task_rq(p)))
                        return rq;
                raw_spin_unlock_irqrestore(&rq->lock, *flags);
        }
@@ -1239,6 +1240,17 @@ void wake_up_idle_cpu(int cpu)
        if (!tsk_is_polling(rq->idle))
                smp_send_reschedule(cpu);
 }
+
+int nohz_ratelimit(int cpu)
+{
+       struct rq *rq = cpu_rq(cpu);
+       u64 diff = rq->clock - rq->nohz_stamp;
+
+       rq->nohz_stamp = rq->clock;
+
+       return diff < (NSEC_PER_SEC / HZ) >> 1;
+}
+
 #endif /* CONFIG_NO_HZ */
 
 static u64 sched_avg_period(void)
@@ -1781,8 +1793,6 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2)
                        raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING);
                }
        }
-       update_rq_clock(rq1);
-       update_rq_clock(rq2);
 }
 
 /*
@@ -1813,7 +1823,7 @@ static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares)
 }
 #endif
 
-static void calc_load_account_active(struct rq *this_rq);
+static void calc_load_account_idle(struct rq *this_rq);
 static void update_sysctl(void);
 static int get_update_sysctl_factor(void);
 
@@ -1870,62 +1880,43 @@ static void set_load_weight(struct task_struct *p)
        p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO];
 }
 
-static void update_avg(u64 *avg, u64 sample)
-{
-       s64 diff = sample - *avg;
-       *avg += diff >> 3;
-}
-
-static void
-enqueue_task(struct rq *rq, struct task_struct *p, int wakeup, bool head)
+static void enqueue_task(struct rq *rq, struct task_struct *p, int flags)
 {
-       if (wakeup)
-               p->se.start_runtime = p->se.sum_exec_runtime;
-
+       update_rq_clock(rq);
        sched_info_queued(p);
-       p->sched_class->enqueue_task(rq, p, wakeup, head);
+       p->sched_class->enqueue_task(rq, p, flags);
        p->se.on_rq = 1;
 }
 
-static void dequeue_task(struct rq *rq, struct task_struct *p, int sleep)
+static void dequeue_task(struct rq *rq, struct task_struct *p, int flags)
 {
-       if (sleep) {
-               if (p->se.last_wakeup) {
-                       update_avg(&p->se.avg_overlap,
-                               p->se.sum_exec_runtime - p->se.last_wakeup);
-                       p->se.last_wakeup = 0;
-               } else {
-                       update_avg(&p->se.avg_wakeup,
-                               sysctl_sched_wakeup_granularity);
-               }
-       }
-
+       update_rq_clock(rq);
        sched_info_dequeued(p);
-       p->sched_class->dequeue_task(rq, p, sleep);
+       p->sched_class->dequeue_task(rq, p, flags);
        p->se.on_rq = 0;
 }
 
 /*
  * activate_task - move a task to the runqueue.
  */
-static void activate_task(struct rq *rq, struct task_struct *p, int wakeup)
+static void activate_task(struct rq *rq, struct task_struct *p, int flags)
 {
        if (task_contributes_to_load(p))
                rq->nr_uninterruptible--;
 
-       enqueue_task(rq, p, wakeup, false);
+       enqueue_task(rq, p, flags);
        inc_nr_running(rq);
 }
 
 /*
  * deactivate_task - remove a task from the runqueue.
  */
-static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep)
+static void deactivate_task(struct rq *rq, struct task_struct *p, int flags)
 {
        if (task_contributes_to_load(p))
                rq->nr_uninterruptible++;
 
-       dequeue_task(rq, p, sleep);
+       dequeue_task(rq, p, flags);
        dec_nr_running(rq);
 }
 
@@ -2054,21 +2045,18 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)
        __set_task_cpu(p, new_cpu);
 }
 
-struct migration_req {
-       struct list_head list;
-
+struct migration_arg {
        struct task_struct *task;
        int dest_cpu;
-
-       struct completion done;
 };
 
+static int migration_cpu_stop(void *data);
+
 /*
  * The task's runqueue lock must be held.
  * Returns true if you have to wait for migration thread.
  */
-static int
-migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req)
+static bool migrate_task(struct task_struct *p, int dest_cpu)
 {
        struct rq *rq = task_rq(p);
 
@@ -2076,58 +2064,7 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req)
         * If the task is not on a runqueue (and not running), then
         * the next wake-up will properly place the task.
         */
-       if (!p->se.on_rq && !task_running(rq, p))
-               return 0;
-
-       init_completion(&req->done);
-       req->task = p;
-       req->dest_cpu = dest_cpu;
-       list_add(&req->list, &rq->migration_queue);
-
-       return 1;
-}
-
-/*
- * wait_task_context_switch -  wait for a thread to complete at least one
- *                             context switch.
- *
- * @p must not be current.
- */
-void wait_task_context_switch(struct task_struct *p)
-{
-       unsigned long nvcsw, nivcsw, flags;
-       int running;
-       struct rq *rq;
-
-       nvcsw   = p->nvcsw;
-       nivcsw  = p->nivcsw;
-       for (;;) {
-               /*
-                * The runqueue is assigned before the actual context
-                * switch. We need to take the runqueue lock.
-                *
-                * We could check initially without the lock but it is
-                * very likely that we need to take the lock in every
-                * iteration.
-                */
-               rq = task_rq_lock(p, &flags);
-               running = task_running(rq, p);
-               task_rq_unlock(rq, &flags);
-
-               if (likely(!running))
-                       break;
-               /*
-                * The switch count is incremented before the actual
-                * context switch. We thus wait for two switches to be
-                * sure at least one completed.
-                */
-               if ((p->nvcsw - nvcsw) > 1)
-                       break;
-               if ((p->nivcsw - nivcsw) > 1)
-                       break;
-
-               cpu_relax();
-       }
+       return p->se.on_rq || task_running(rq, p);
 }
 
 /*
@@ -2185,7 +2122,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state)
                 * just go back and repeat.
                 */
                rq = task_rq_lock(p, &flags);
-               trace_sched_wait_task(rq, p);
+               trace_sched_wait_task(p);
                running = task_running(rq, p);
                on_rq = p->se.on_rq;
                ncsw = 0;
@@ -2283,6 +2220,9 @@ void task_oncpu_function_call(struct task_struct *p,
 }
 
 #ifdef CONFIG_SMP
+/*
+ * ->cpus_allowed is protected by either TASK_WAKING or rq->lock held.
+ */
 static int select_fallback_rq(int cpu, struct task_struct *p)
 {
        int dest_cpu;
@@ -2299,12 +2239,8 @@ static int select_fallback_rq(int cpu, struct task_struct *p)
                return dest_cpu;
 
        /* No more Mr. Nice Guy. */
-       if (dest_cpu >= nr_cpu_ids) {
-               rcu_read_lock();
-               cpuset_cpus_allowed_locked(p, &p->cpus_allowed);
-               rcu_read_unlock();
-               dest_cpu = cpumask_any_and(cpu_active_mask, &p->cpus_allowed);
-
+       if (unlikely(dest_cpu >= nr_cpu_ids)) {
+               dest_cpu = cpuset_cpus_allowed_fallback(p);
                /*
                 * Don't tell them about moving exiting tasks or
                 * kernel threads (both mm NULL), since they never
@@ -2321,17 +2257,12 @@ static int select_fallback_rq(int cpu, struct task_struct *p)
 }
 
 /*
- * Gets called from 3 sites (exec, fork, wakeup), since it is called without
- * holding rq->lock we need to ensure ->cpus_allowed is stable, this is done
- * by:
- *
- *  exec:           is unstable, retry loop
- *  fork & wake-up: serialize ->cpus_allowed against TASK_WAKING
+ * The caller (fork, wakeup) owns TASK_WAKING, ->cpus_allowed is stable.
  */
 static inline
-int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags)
+int select_task_rq(struct rq *rq, struct task_struct *p, int sd_flags, int wake_flags)
 {
-       int cpu = p->sched_class->select_task_rq(p, sd_flags, wake_flags);
+       int cpu = p->sched_class->select_task_rq(rq, p, sd_flags, wake_flags);
 
        /*
         * In order not to call set_task_cpu() on a blocking task we need
@@ -2349,6 +2280,12 @@ int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags)
 
        return cpu;
 }
+
+static void update_avg(u64 *avg, u64 sample)
+{
+       s64 diff = sample - *avg;
+       *avg += diff >> 3;
+}
 #endif
 
 /***
@@ -2370,16 +2307,13 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
 {
        int cpu, orig_cpu, this_cpu, success = 0;
        unsigned long flags;
+       unsigned long en_flags = ENQUEUE_WAKEUP;
        struct rq *rq;
 
-       if (!sched_feat(SYNC_WAKEUPS))
-               wake_flags &= ~WF_SYNC;
-
        this_cpu = get_cpu();
 
        smp_wmb();
        rq = task_rq_lock(p, &flags);
-       update_rq_clock(rq);
        if (!(p->state & state))
                goto out;
 
@@ -2399,28 +2333,26 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
         *
         * First fix up the nr_uninterruptible count:
         */
-       if (task_contributes_to_load(p))
-               rq->nr_uninterruptible--;
+       if (task_contributes_to_load(p)) {
+               if (likely(cpu_online(orig_cpu)))
+                       rq->nr_uninterruptible--;
+               else
+                       this_rq()->nr_uninterruptible--;
+       }
        p->state = TASK_WAKING;
 
-       if (p->sched_class->task_waking)
+       if (p->sched_class->task_waking) {
                p->sched_class->task_waking(rq, p);
+               en_flags |= ENQUEUE_WAKING;
+       }
 
-       __task_rq_unlock(rq);
-
-       cpu = select_task_rq(p, SD_BALANCE_WAKE, wake_flags);
-       if (cpu != orig_cpu) {
-               /*
-                * Since we migrate the task without holding any rq->lock,
-                * we need to be careful with task_rq_lock(), since that
-                * might end up locking an invalid rq.
-                */
+       cpu = select_task_rq(rq, p, SD_BALANCE_WAKE, wake_flags);
+       if (cpu != orig_cpu)
                set_task_cpu(p, cpu);
-       }
+       __task_rq_unlock(rq);
 
        rq = cpu_rq(cpu);
        raw_spin_lock(&rq->lock);
-       update_rq_clock(rq);
 
        /*
         * We migrated the task without holding either rq->lock, however
@@ -2448,36 +2380,20 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state,
 
 out_activate:
 #endif /* CONFIG_SMP */
-       schedstat_inc(p, se.nr_wakeups);
+       schedstat_inc(p, se.statistics.nr_wakeups);
        if (wake_flags & WF_SYNC)
-               schedstat_inc(p, se.nr_wakeups_sync);
+               schedstat_inc(p, se.statistics.nr_wakeups_sync);
        if (orig_cpu != cpu)
-               schedstat_inc(p, se.nr_wakeups_migrate);
+               schedstat_inc(p, se.statistics.nr_wakeups_migrate);
        if (cpu == this_cpu)
-               schedstat_inc(p, se.nr_wakeups_local);
+               schedstat_inc(p, se.statistics.nr_wakeups_local);
        else
-               schedstat_inc(p, se.nr_wakeups_remote);
-       activate_task(rq, p, 1);
+               schedstat_inc(p, se.statistics.nr_wakeups_remote);
+       activate_task(rq, p, en_flags);
        success = 1;
 
-       /*
-        * Only attribute actual wakeups done by this task.
-        */
-       if (!in_interrupt()) {
-               struct sched_entity *se = &current->se;
-               u64 sample = se->sum_exec_runtime;
-
-               if (se->last_wakeup)
-                       sample -= se->last_wakeup;
-               else
-                       sample -= se->start_runtime;
-               update_avg(&se->avg_wakeup, sample);
-
-               se->last_wakeup = se->sum_exec_runtime;
-       }
-
 out_running:
-       trace_sched_wakeup(rq, p, success);
+       trace_sched_wakeup(p, success);
        check_preempt_curr(rq, p, wake_flags);
 
        p->state = TASK_RUNNING;
@@ -2537,42 +2453,9 @@ static void __sched_fork(struct task_struct *p)
        p->se.sum_exec_runtime          = 0;
        p->se.prev_sum_exec_runtime     = 0;
        p->se.nr_migrations             = 0;
-       p->se.last_wakeup               = 0;
-       p->se.avg_overlap               = 0;
-       p->se.start_runtime             = 0;
-       p->se.avg_wakeup                = sysctl_sched_wakeup_granularity;
 
 #ifdef CONFIG_SCHEDSTATS
-       p->se.wait_start                        = 0;
-       p->se.wait_max                          = 0;
-       p->se.wait_count                        = 0;
-       p->se.wait_sum                          = 0;
-
-       p->se.sleep_start                       = 0;
-       p->se.sleep_max                         = 0;
-       p->se.sum_sleep_runtime                 = 0;
-
-       p->se.block_start                       = 0;
-       p->se.block_max                         = 0;
-       p->se.exec_max                          = 0;
-       p->se.slice_max                         = 0;
-
-       p->se.nr_migrations_cold                = 0;
-       p->se.nr_failed_migrations_affine       = 0;
-       p->se.nr_failed_migrations_running      = 0;
-       p->se.nr_failed_migrations_hot          = 0;
-       p->se.nr_forced_migrations              = 0;
-
-       p->se.nr_wakeups                        = 0;
-       p->se.nr_wakeups_sync                   = 0;
-       p->se.nr_wakeups_migrate                = 0;
-       p->se.nr_wakeups_local                  = 0;
-       p->se.nr_wakeups_remote                 = 0;
-       p->se.nr_wakeups_affine                 = 0;
-       p->se.nr_wakeups_affine_attempts        = 0;
-       p->se.nr_wakeups_passive                = 0;
-       p->se.nr_wakeups_idle                   = 0;
-
+       memset(&p->se.statistics, 0, sizeof(p->se.statistics));
 #endif
 
        INIT_LIST_HEAD(&p->rt.run_list);
@@ -2593,11 +2476,11 @@ void sched_fork(struct task_struct *p, int clone_flags)
 
        __sched_fork(p);
        /*
-        * We mark the process as waking here. This guarantees that
+        * We mark the process as running here. This guarantees that
         * nobody will actually run it, and a signal or other external
         * event cannot wake it up and insert it on the runqueue either.
         */
-       p->state = TASK_WAKING;
+       p->state = TASK_RUNNING;
 
        /*
         * Revert to default priority/policy on fork if requested.
@@ -2664,31 +2547,27 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
        int cpu __maybe_unused = get_cpu();
 
 #ifdef CONFIG_SMP
+       rq = task_rq_lock(p, &flags);
+       p->state = TASK_WAKING;
+
        /*
         * Fork balancing, do it here and not earlier because:
         *  - cpus_allowed can change in the fork path
         *  - any previously selected cpu might disappear through hotplug
         *
-        * We still have TASK_WAKING but PF_STARTING is gone now, meaning
-        * ->cpus_allowed is stable, we have preemption disabled, meaning
-        * cpu_online_mask is stable.
+        * We set TASK_WAKING so that select_task_rq() can drop rq->lock
+        * without people poking at ->cpus_allowed.
         */
-       cpu = select_task_rq(p, SD_BALANCE_FORK, 0);
+       cpu = select_task_rq(rq, p, SD_BALANCE_FORK, 0);
        set_task_cpu(p, cpu);
-#endif
-
-       /*
-        * Since the task is not on the rq and we still have TASK_WAKING set
-        * nobody else will migrate this task.
-        */
-       rq = cpu_rq(cpu);
-       raw_spin_lock_irqsave(&rq->lock, flags);
 
-       BUG_ON(p->state != TASK_WAKING);
        p->state = TASK_RUNNING;
-       update_rq_clock(rq);
+       task_rq_unlock(rq, &flags);
+#endif
+
+       rq = task_rq_lock(p, &flags);
        activate_task(rq, p, 0);
-       trace_sched_wakeup_new(rq, p, 1);
+       trace_sched_wakeup_new(p, 1);
        check_preempt_curr(rq, p, WF_FORK);
 #ifdef CONFIG_SMP
        if (p->sched_class->task_woken)
@@ -2908,7 +2787,7 @@ context_switch(struct rq *rq, struct task_struct *prev,
        struct mm_struct *mm, *oldmm;
 
        prepare_task_switch(rq, prev, next);
-       trace_sched_switch(rq, prev, next);
+       trace_sched_switch(prev, next);
        mm = next->mm;
        oldmm = prev->active_mm;
        /*
@@ -3025,6 +2904,61 @@ static unsigned long calc_load_update;
 unsigned long avenrun[3];
 EXPORT_SYMBOL(avenrun);
 
+static long calc_load_fold_active(struct rq *this_rq)
+{
+       long nr_active, delta = 0;
+
+       nr_active = this_rq->nr_running;
+       nr_active += (long) this_rq->nr_uninterruptible;
+
+       if (nr_active != this_rq->calc_load_active) {
+               delta = nr_active - this_rq->calc_load_active;
+               this_rq->calc_load_active = nr_active;
+       }
+
+       return delta;
+}
+
+#ifdef CONFIG_NO_HZ
+/*
+ * For NO_HZ we delay the active fold to the next LOAD_FREQ update.
+ *
+ * When making the ILB scale, we should try to pull this in as well.
+ */
+static atomic_long_t calc_load_tasks_idle;
+
+static void calc_load_account_idle(struct rq *this_rq)
+{
+       long delta;
+
+       delta = calc_load_fold_active(this_rq);
+       if (delta)
+               atomic_long_add(delta, &calc_load_tasks_idle);
+}
+
+static long calc_load_fold_idle(void)
+{
+       long delta = 0;
+
+       /*
+        * Its got a race, we don't care...
+        */
+       if (atomic_long_read(&calc_load_tasks_idle))
+               delta = atomic_long_xchg(&calc_load_tasks_idle, 0);
+
+       return delta;
+}
+#else
+static void calc_load_account_idle(struct rq *this_rq)
+{
+}
+
+static inline long calc_load_fold_idle(void)
+{
+       return 0;
+}
+#endif
+
 /**
  * get_avenrun - get the load average array
  * @loads:     pointer to dest load array
@@ -3071,20 +3005,22 @@ void calc_global_load(void)
 }
 
 /*
- * Either called from update_cpu_load() or from a cpu going idle
+ * Called from update_cpu_load() to periodically update this CPU's
+ * active count.
  */
 static void calc_load_account_active(struct rq *this_rq)
 {
-       long nr_active, delta;
+       long delta;
 
-       nr_active = this_rq->nr_running;
-       nr_active += (long) this_rq->nr_uninterruptible;
+       if (time_before(jiffies, this_rq->calc_load_update))
+               return;
 
-       if (nr_active != this_rq->calc_load_active) {
-               delta = nr_active - this_rq->calc_load_active;
-               this_rq->calc_load_active = nr_active;
+       delta  = calc_load_fold_active(this_rq);
+       delta += calc_load_fold_idle();
+       if (delta)
                atomic_long_add(delta, &calc_load_tasks);
-       }
+
+       this_rq->calc_load_update += LOAD_FREQ;
 }
 
 /*
@@ -3116,10 +3052,7 @@ static void update_cpu_load(struct rq *this_rq)
                this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i;
        }
 
-       if (time_after_eq(jiffies, this_rq->calc_load_update)) {
-               this_rq->calc_load_update += LOAD_FREQ;
-               calc_load_account_active(this_rq);
-       }
+       calc_load_account_active(this_rq);
 }
 
 #ifdef CONFIG_SMP
@@ -3131,44 +3064,27 @@ static void update_cpu_load(struct rq *this_rq)
 void sched_exec(void)
 {
        struct task_struct *p = current;
-       struct migration_req req;
-       int dest_cpu, this_cpu;
        unsigned long flags;
        struct rq *rq;
-
-again:
-       this_cpu = get_cpu();
-       dest_cpu = select_task_rq(p, SD_BALANCE_EXEC, 0);
-       if (dest_cpu == this_cpu) {
-               put_cpu();
-               return;
-       }
+       int dest_cpu;
 
        rq = task_rq_lock(p, &flags);
-       put_cpu();
+       dest_cpu = p->sched_class->select_task_rq(rq, p, SD_BALANCE_EXEC, 0);
+       if (dest_cpu == smp_processor_id())
+               goto unlock;
 
        /*
         * select_task_rq() can race against ->cpus_allowed
         */
-       if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)
-           || unlikely(!cpu_active(dest_cpu))) {
-               task_rq_unlock(rq, &flags);
-               goto again;
-       }
+       if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed) &&
+           likely(cpu_active(dest_cpu)) && migrate_task(p, dest_cpu)) {
+               struct migration_arg arg = { p, dest_cpu };
 
-       /* force the process onto the specified CPU */
-       if (migrate_task(p, dest_cpu, &req)) {
-               /* Need to wait for migration thread (might exit: take ref). */
-               struct task_struct *mt = rq->migration_thread;
-
-               get_task_struct(mt);
                task_rq_unlock(rq, &flags);
-               wake_up_process(mt);
-               put_task_struct(mt);
-               wait_for_completion(&req.done);
-
+               stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
                return;
        }
+unlock:
        task_rq_unlock(rq, &flags);
 }
 
@@ -3640,23 +3556,9 @@ static inline void schedule_debug(struct task_struct *prev)
 
 static void put_prev_task(struct rq *rq, struct task_struct *prev)
 {
-       if (prev->state == TASK_RUNNING) {
-               u64 runtime = prev->se.sum_exec_runtime;
-
-               runtime -= prev->se.prev_sum_exec_runtime;
-               runtime = min_t(u64, runtime, 2*sysctl_sched_migration_cost);
-
-               /*
-                * In order to avoid avg_overlap growing stale when we are
-                * indeed overlapping and hence not getting put to sleep, grow
-                * the avg_overlap on preemption.
-                *
-                * We use the average preemption runtime because that
-                * correlates to the amount of cache footprint a task can
-                * build up.
-                */
-               update_avg(&prev->se.avg_overlap, runtime);
-       }
+       if (prev->se.on_rq)
+               update_rq_clock(rq);
+       rq->skip_clock_update = 0;
        prev->sched_class->put_prev_task(rq, prev);
 }
 
@@ -3706,7 +3608,7 @@ need_resched:
        preempt_disable();
        cpu = smp_processor_id();
        rq = cpu_rq(cpu);
-       rcu_sched_qs(cpu);
+       rcu_note_context_switch(cpu);
        prev = rq->curr;
        switch_count = &prev->nivcsw;
 
@@ -3719,14 +3621,13 @@ need_resched_nonpreemptible:
                hrtick_clear(rq);
 
        raw_spin_lock_irq(&rq->lock);
-       update_rq_clock(rq);
        clear_tsk_need_resched(prev);
 
        if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
                if (unlikely(signal_pending_state(prev->state, prev)))
                        prev->state = TASK_RUNNING;
                else
-                       deactivate_task(rq, prev, 1);
+                       deactivate_task(rq, prev, DEQUEUE_SLEEP);
                switch_count = &prev->nvcsw;
        }
 
@@ -4049,8 +3950,7 @@ do_wait_for_common(struct completion *x, long timeout, int state)
        if (!x->done) {
                DECLARE_WAITQUEUE(wait, current);
 
-               wait.flags |= WQ_FLAG_EXCLUSIVE;
-               __add_wait_queue_tail(&x->wait, &wait);
+               __add_wait_queue_tail_exclusive(&x->wait, &wait);
                do {
                        if (signal_pending_state(state, current)) {
                                timeout = -ERESTARTSYS;
@@ -4276,7 +4176,6 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
        BUG_ON(prio < 0 || prio > MAX_PRIO);
 
        rq = task_rq_lock(p, &flags);
-       update_rq_clock(rq);
 
        oldprio = p->prio;
        prev_class = p->sched_class;
@@ -4297,7 +4196,7 @@ void rt_mutex_setprio(struct task_struct *p, int prio)
        if (running)
                p->sched_class->set_curr_task(rq);
        if (on_rq) {
-               enqueue_task(rq, p, 0, oldprio < prio);
+               enqueue_task(rq, p, oldprio < prio ? ENQUEUE_HEAD : 0);
 
                check_class_changed(rq, p, prev_class, oldprio, running);
        }
@@ -4319,7 +4218,6 @@ void set_user_nice(struct task_struct *p, long nice)
         * the task might be in the middle of scheduling on another CPU.
         */
        rq = task_rq_lock(p, &flags);
-       update_rq_clock(rq);
        /*
         * The RT priorities are set via sched_setscheduler(), but we still
         * allow the 'normal' nice value to be set - but as expected
@@ -4341,7 +4239,7 @@ void set_user_nice(struct task_struct *p, long nice)
        delta = p->prio - old_prio;
 
        if (on_rq) {
-               enqueue_task(rq, p, 0, false);
+               enqueue_task(rq, p, 0);
                /*
                 * If the task increased its priority or is running and
                 * lowered its priority, then reschedule its CPU:
@@ -4602,7 +4500,6 @@ recheck:
                raw_spin_unlock_irqrestore(&p->pi_lock, flags);
                goto recheck;
        }
-       update_rq_clock(rq);
        on_rq = p->se.on_rq;
        running = task_current(rq, p);
        if (on_rq)
@@ -5339,17 +5236,15 @@ static inline void sched_init_granularity(void)
 /*
  * This is how migration works:
  *
- * 1) we queue a struct migration_req structure in the source CPU's
- *    runqueue and wake up that CPU's migration thread.
- * 2) we down() the locked semaphore => thread blocks.
- * 3) migration thread wakes up (implicitly it forces the migrated
- *    thread off the CPU)
- * 4) it gets the migration request and checks whether the migrated
- *    task is still in the wrong runqueue.
- * 5) if it's in the wrong runqueue then the migration thread removes
+ * 1) we invoke migration_cpu_stop() on the target CPU using
+ *    stop_one_cpu().
+ * 2) stopper starts to run (implicitly forcing the migrated thread
+ *    off the CPU)
+ * 3) it checks whether the migrated task is still in the wrong runqueue.
+ * 4) if it's in the wrong runqueue then the migration thread removes
  *    it and puts it into the right queue.
- * 6) migration thread up()s the semaphore.
- * 7) we wake up and the migration is done.
+ * 5) stopper completes and stop_one_cpu() returns and the migration
+ *    is done.
  */
 
 /*
@@ -5363,12 +5258,23 @@ static inline void sched_init_granularity(void)
  */
 int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
 {
-       struct migration_req req;
        unsigned long flags;
        struct rq *rq;
+       unsigned int dest_cpu;
        int ret = 0;
 
+       /*
+        * Serialize against TASK_WAKING so that ttwu() and wunt() can
+        * drop the rq->lock and still rely on ->cpus_allowed.
+        */
+again:
+       while (task_is_waking(p))
+               cpu_relax();
        rq = task_rq_lock(p, &flags);
+       if (task_is_waking(p)) {
+               task_rq_unlock(rq, &flags);
+               goto again;
+       }
 
        if (!cpumask_intersects(new_mask, cpu_active_mask)) {
                ret = -EINVAL;
@@ -5392,15 +5298,12 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
        if (cpumask_test_cpu(task_cpu(p), new_mask))
                goto out;
 
-       if (migrate_task(p, cpumask_any_and(cpu_active_mask, new_mask), &req)) {
+       dest_cpu = cpumask_any_and(cpu_active_mask, new_mask);
+       if (migrate_task(p, dest_cpu)) {
+               struct migration_arg arg = { p, dest_cpu };
                /* Need help from migration thread: drop lock and wait. */
-               struct task_struct *mt = rq->migration_thread;
-
-               get_task_struct(mt);
                task_rq_unlock(rq, &flags);
-               wake_up_process(mt);
-               put_task_struct(mt);
-               wait_for_completion(&req.done);
+               stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg);
                tlb_migrate_finish(p->mm);
                return 0;
        }
@@ -5458,98 +5361,49 @@ fail:
        return ret;
 }
 
-#define RCU_MIGRATION_IDLE     0
-#define RCU_MIGRATION_NEED_QS  1
-#define RCU_MIGRATION_GOT_QS   2
-#define RCU_MIGRATION_MUST_SYNC        3
-
 /*
- * migration_thread - this is a highprio system thread that performs
- * thread migration by bumping thread off CPU then 'pushing' onto
- * another runqueue.
+ * migration_cpu_stop - this will be executed by a highprio stopper thread
+ * and performs thread migration by bumping thread off CPU then
+ * 'pushing' onto another runqueue.
  */
-static int migration_thread(void *data)
-{
-       int badcpu;
-       int cpu = (long)data;
-       struct rq *rq;
-
-       rq = cpu_rq(cpu);
-       BUG_ON(rq->migration_thread != current);
-
-       set_current_state(TASK_INTERRUPTIBLE);
-       while (!kthread_should_stop()) {
-               struct migration_req *req;
-               struct list_head *head;
-
-               raw_spin_lock_irq(&rq->lock);
-
-               if (cpu_is_offline(cpu)) {
-                       raw_spin_unlock_irq(&rq->lock);
-                       break;
-               }
-
-               if (rq->active_balance) {
-                       active_load_balance(rq, cpu);
-                       rq->active_balance = 0;
-               }
-
-               head = &rq->migration_queue;
-
-               if (list_empty(head)) {
-                       raw_spin_unlock_irq(&rq->lock);
-                       schedule();
-                       set_current_state(TASK_INTERRUPTIBLE);
-                       continue;
-               }
-               req = list_entry(head->next, struct migration_req, list);
-               list_del_init(head->next);
-
-               if (req->task != NULL) {
-                       raw_spin_unlock(&rq->lock);
-                       __migrate_task(req->task, cpu, req->dest_cpu);
-               } else if (likely(cpu == (badcpu = smp_processor_id()))) {
-                       req->dest_cpu = RCU_MIGRATION_GOT_QS;
-                       raw_spin_unlock(&rq->lock);
-               } else {
-                       req->dest_cpu = RCU_MIGRATION_MUST_SYNC;
-                       raw_spin_unlock(&rq->lock);
-                       WARN_ONCE(1, "migration_thread() on CPU %d, expected %d\n", badcpu, cpu);
-               }
-               local_irq_enable();
-
-               complete(&req->done);
-       }
-       __set_current_state(TASK_RUNNING);
-
-       return 0;
-}
-
-#ifdef CONFIG_HOTPLUG_CPU
-
-static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu)
+static int migration_cpu_stop(void *data)
 {
-       int ret;
+       struct migration_arg *arg = data;
 
+       /*
+        * The original target cpu might have gone down and we might
+        * be on another cpu but it doesn't matter.
+        */
        local_irq_disable();
-       ret = __migrate_task(p, src_cpu, dest_cpu);
+       __migrate_task(arg->task, raw_smp_processor_id(), arg->dest_cpu);
        local_irq_enable();
-       return ret;
+       return 0;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Figure out where task on dead CPU should go, use force if necessary.
  */
-static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
+void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
 {
-       int dest_cpu;
+       struct rq *rq = cpu_rq(dead_cpu);
+       int needs_cpu, uninitialized_var(dest_cpu);
+       unsigned long flags;
 
-again:
-       dest_cpu = select_fallback_rq(dead_cpu, p);
+       local_irq_save(flags);
 
-       /* It can have affinity changed while we were choosing. */
-       if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu)))
-               goto again;
+       raw_spin_lock(&rq->lock);
+       needs_cpu = (task_cpu(p) == dead_cpu) && (p->state != TASK_WAKING);
+       if (needs_cpu)
+               dest_cpu = select_fallback_rq(dead_cpu, p);
+       raw_spin_unlock(&rq->lock);
+       /*
+        * It can only fail if we race with set_cpus_allowed(),
+        * in the racer should migrate the task anyway.
+        */
+       if (needs_cpu)
+               __migrate_task(p, dead_cpu, dest_cpu);
+       local_irq_restore(flags);
 }
 
 /*
@@ -5613,7 +5467,6 @@ void sched_idle_next(void)
 
        __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
 
-       update_rq_clock(rq);
        activate_task(rq, p, 0);
 
        raw_spin_unlock_irqrestore(&rq->lock, flags);
@@ -5668,7 +5521,6 @@ static void migrate_dead_tasks(unsigned int dead_cpu)
        for ( ; ; ) {
                if (!rq->nr_running)
                        break;
-               update_rq_clock(rq);
                next = pick_next_task(rq);
                if (!next)
                        break;
@@ -5891,35 +5743,20 @@ static void set_rq_offline(struct rq *rq)
 static int __cpuinit
 migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
 {
-       struct task_struct *p;
        int cpu = (long)hcpu;
        unsigned long flags;
-       struct rq *rq;
+       struct rq *rq = cpu_rq(cpu);
 
        switch (action) {
 
        case CPU_UP_PREPARE:
        case CPU_UP_PREPARE_FROZEN:
-               p = kthread_create(migration_thread, hcpu, "migration/%d", cpu);
-               if (IS_ERR(p))
-                       return NOTIFY_BAD;
-               kthread_bind(p, cpu);
-               /* Must be high prio: stop_machine expects to yield to it. */
-               rq = task_rq_lock(p, &flags);
-               __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1);
-               task_rq_unlock(rq, &flags);
-               get_task_struct(p);
-               cpu_rq(cpu)->migration_thread = p;
                rq->calc_load_update = calc_load_update;
                break;
 
        case CPU_ONLINE:
        case CPU_ONLINE_FROZEN:
-               /* Strictly unnecessary, as first user will wake it. */
-               wake_up_process(cpu_rq(cpu)->migration_thread);
-
                /* Update our root-domain */
-               rq = cpu_rq(cpu);
                raw_spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
@@ -5930,61 +5767,24 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
                break;
 
 #ifdef CONFIG_HOTPLUG_CPU
-       case CPU_UP_CANCELED:
-       case CPU_UP_CANCELED_FROZEN:
-               if (!cpu_rq(cpu)->migration_thread)
-                       break;
-               /* Unbind it from offline cpu so it can run. Fall thru. */
-               kthread_bind(cpu_rq(cpu)->migration_thread,
-                            cpumask_any(cpu_online_mask));
-               kthread_stop(cpu_rq(cpu)->migration_thread);
-               put_task_struct(cpu_rq(cpu)->migration_thread);
-               cpu_rq(cpu)->migration_thread = NULL;
-               break;
-
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
-               cpuset_lock(); /* around calls to cpuset_cpus_allowed_lock() */
                migrate_live_tasks(cpu);
-               rq = cpu_rq(cpu);
-               kthread_stop(rq->migration_thread);
-               put_task_struct(rq->migration_thread);
-               rq->migration_thread = NULL;
                /* Idle task back to normal (off runqueue, low prio) */
                raw_spin_lock_irq(&rq->lock);
-               update_rq_clock(rq);
                deactivate_task(rq, rq->idle, 0);
                __setscheduler(rq, rq->idle, SCHED_NORMAL, 0);
                rq->idle->sched_class = &idle_sched_class;
                migrate_dead_tasks(cpu);
                raw_spin_unlock_irq(&rq->lock);
-               cpuset_unlock();
                migrate_nr_uninterruptible(rq);
                BUG_ON(rq->nr_running != 0);
                calc_global_load_remove(rq);
-               /*
-                * No need to migrate the tasks: it was best-effort if
-                * they didn't take sched_hotcpu_mutex. Just wake up
-                * the requestors.
-                */
-               raw_spin_lock_irq(&rq->lock);
-               while (!list_empty(&rq->migration_queue)) {
-                       struct migration_req *req;
-
-                       req = list_entry(rq->migration_queue.next,
-                                        struct migration_req, list);
-                       list_del_init(&req->list);
-                       raw_spin_unlock_irq(&rq->lock);
-                       complete(&req->done);
-                       raw_spin_lock_irq(&rq->lock);
-               }
-               raw_spin_unlock_irq(&rq->lock);
                break;
 
        case CPU_DYING:
        case CPU_DYING_FROZEN:
                /* Update our root-domain */
-               rq = cpu_rq(cpu);
                raw_spin_lock_irqsave(&rq->lock, flags);
                if (rq->rd) {
                        BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
@@ -6315,6 +6115,9 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
        struct rq *rq = cpu_rq(cpu);
        struct sched_domain *tmp;
 
+       for (tmp = sd; tmp; tmp = tmp->parent)
+               tmp->span_weight = cpumask_weight(sched_domain_span(tmp));
+
        /* Remove the sched domains which do not contribute to scheduling. */
        for (tmp = sd; tmp; ) {
                struct sched_domain *parent = tmp->parent;
@@ -7798,10 +7601,8 @@ void __init sched_init(void)
                rq->push_cpu = 0;
                rq->cpu = i;
                rq->online = 0;
-               rq->migration_thread = NULL;
                rq->idle_stamp = 0;
                rq->avg_idle = 2*sysctl_sched_migration_cost;
-               INIT_LIST_HEAD(&rq->migration_queue);
                rq_attach_root(rq, &def_root_domain);
 #endif
                init_rq_hrtick(rq);
@@ -7902,7 +7703,6 @@ static void normalize_task(struct rq *rq, struct task_struct *p)
 {
        int on_rq;
 
-       update_rq_clock(rq);
        on_rq = p->se.on_rq;
        if (on_rq)
                deactivate_task(rq, p, 0);
@@ -7929,9 +7729,9 @@ void normalize_rt_tasks(void)
 
                p->se.exec_start                = 0;
 #ifdef CONFIG_SCHEDSTATS
-               p->se.wait_start                = 0;
-               p->se.sleep_start               = 0;
-               p->se.block_start               = 0;
+               p->se.statistics.wait_start     = 0;
+               p->se.statistics.sleep_start    = 0;
+               p->se.statistics.block_start    = 0;
 #endif
 
                if (!rt_task(p)) {
@@ -8264,8 +8064,6 @@ void sched_move_task(struct task_struct *tsk)
 
        rq = task_rq_lock(tsk, &flags);
 
-       update_rq_clock(rq);
-
        running = task_current(rq, tsk);
        on_rq = tsk->se.on_rq;
 
@@ -8284,7 +8082,7 @@ void sched_move_task(struct task_struct *tsk)
        if (unlikely(running))
                tsk->sched_class->set_curr_task(rq);
        if (on_rq)
-               enqueue_task(rq, tsk, 0, false);
+               enqueue_task(rq, tsk, 0);
 
        task_rq_unlock(rq, &flags);
 }
@@ -9098,43 +8896,32 @@ struct cgroup_subsys cpuacct_subsys = {
 
 #ifndef CONFIG_SMP
 
-int rcu_expedited_torture_stats(char *page)
-{
-       return 0;
-}
-EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats);
-
 void synchronize_sched_expedited(void)
 {
+       barrier();
 }
 EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
 
 #else /* #ifndef CONFIG_SMP */
 
-static DEFINE_PER_CPU(struct migration_req, rcu_migration_req);
-static DEFINE_MUTEX(rcu_sched_expedited_mutex);
+static atomic_t synchronize_sched_expedited_count = ATOMIC_INIT(0);
 
-#define RCU_EXPEDITED_STATE_POST -2
-#define RCU_EXPEDITED_STATE_IDLE -1
-
-static int rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE;
-
-int rcu_expedited_torture_stats(char *page)
+static int synchronize_sched_expedited_cpu_stop(void *data)
 {
-       int cnt = 0;
-       int cpu;
-
-       cnt += sprintf(&page[cnt], "state: %d /", rcu_expedited_state);
-       for_each_online_cpu(cpu) {
-                cnt += sprintf(&page[cnt], " %d:%d",
-                               cpu, per_cpu(rcu_migration_req, cpu).dest_cpu);
-       }
-       cnt += sprintf(&page[cnt], "\n");
-       return cnt;
+       /*
+        * There must be a full memory barrier on each affected CPU
+        * between the time that try_stop_cpus() is called and the
+        * time that it returns.
+        *
+        * In the current initial implementation of cpu_stop, the
+        * above condition is already met when the control reaches
+        * this point and the following smp_mb() is not strictly
+        * necessary.  Do smp_mb() anyway for documentation and
+        * robustness against future implementation changes.
+        */
+       smp_mb(); /* See above comment block. */
+       return 0;
 }
-EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats);
-
-static long synchronize_sched_expedited_count;
 
 /*
  * Wait for an rcu-sched grace period to elapse, but use "big hammer"
@@ -9148,18 +8935,14 @@ static long synchronize_sched_expedited_count;
  */
 void synchronize_sched_expedited(void)
 {
-       int cpu;
-       unsigned long flags;
-       bool need_full_sync = 0;
-       struct rq *rq;
-       struct migration_req *req;
-       long snap;
-       int trycount = 0;
+       int snap, trycount = 0;
 
        smp_mb();  /* ensure prior mod happens before capturing snap. */
-       snap = ACCESS_ONCE(synchronize_sched_expedited_count) + 1;
+       snap = atomic_read(&synchronize_sched_expedited_count) + 1;
        get_online_cpus();
-       while (!mutex_trylock(&rcu_sched_expedited_mutex)) {
+       while (try_stop_cpus(cpu_online_mask,
+                            synchronize_sched_expedited_cpu_stop,
+                            NULL) == -EAGAIN) {
                put_online_cpus();
                if (trycount++ < 10)
                        udelay(trycount * num_online_cpus());
@@ -9167,41 +8950,15 @@ void synchronize_sched_expedited(void)
                        synchronize_sched();
                        return;
                }
-               if (ACCESS_ONCE(synchronize_sched_expedited_count) - snap > 0) {
+               if (atomic_read(&synchronize_sched_expedited_count) - snap > 0) {
                        smp_mb(); /* ensure test happens before caller kfree */
                        return;
                }
                get_online_cpus();
        }
-       rcu_expedited_state = RCU_EXPEDITED_STATE_POST;
-       for_each_online_cpu(cpu) {
-               rq = cpu_rq(cpu);
-               req = &per_cpu(rcu_migration_req, cpu);
-               init_completion(&req->done);
-               req->task = NULL;
-               req->dest_cpu = RCU_MIGRATION_NEED_QS;
-               raw_spin_lock_irqsave(&rq->lock, flags);
-               list_add(&req->list, &rq->migration_queue);
-               raw_spin_unlock_irqrestore(&rq->lock, flags);
-               wake_up_process(rq->migration_thread);
-       }
-       for_each_online_cpu(cpu) {
-               rcu_expedited_state = cpu;
-               req = &per_cpu(rcu_migration_req, cpu);
-               rq = cpu_rq(cpu);
-               wait_for_completion(&req->done);
-               raw_spin_lock_irqsave(&rq->lock, flags);
-               if (unlikely(req->dest_cpu == RCU_MIGRATION_MUST_SYNC))
-                       need_full_sync = 1;
-               req->dest_cpu = RCU_MIGRATION_IDLE;
-               raw_spin_unlock_irqrestore(&rq->lock, flags);
-       }
-       rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE;
-       synchronize_sched_expedited_count++;
-       mutex_unlock(&rcu_sched_expedited_mutex);
+       atomic_inc(&synchronize_sched_expedited_count);
+       smp_mb__after_atomic_inc(); /* ensure post-GP actions seen after GP. */
        put_online_cpus();
-       if (need_full_sync)
-               synchronize_sched();
 }
 EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
 
index 19be00b..87a330a 100644 (file)
@@ -70,16 +70,16 @@ static void print_cfs_group_stats(struct seq_file *m, int cpu,
        PN(se->vruntime);
        PN(se->sum_exec_runtime);
 #ifdef CONFIG_SCHEDSTATS
-       PN(se->wait_start);
-       PN(se->sleep_start);
-       PN(se->block_start);
-       PN(se->sleep_max);
-       PN(se->block_max);
-       PN(se->exec_max);
-       PN(se->slice_max);
-       PN(se->wait_max);
-       PN(se->wait_sum);
-       P(se->wait_count);
+       PN(se->statistics.wait_start);
+       PN(se->statistics.sleep_start);
+       PN(se->statistics.block_start);
+       PN(se->statistics.sleep_max);
+       PN(se->statistics.block_max);
+       PN(se->statistics.exec_max);
+       PN(se->statistics.slice_max);
+       PN(se->statistics.wait_max);
+       PN(se->statistics.wait_sum);
+       P(se->statistics.wait_count);
 #endif
        P(se->load.weight);
 #undef PN
@@ -104,7 +104,7 @@ print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
        SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
                SPLIT_NS(p->se.vruntime),
                SPLIT_NS(p->se.sum_exec_runtime),
-               SPLIT_NS(p->se.sum_sleep_runtime));
+               SPLIT_NS(p->se.statistics.sum_sleep_runtime));
 #else
        SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld",
                0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L);
@@ -175,11 +175,6 @@ void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
        task_group_path(tg, path, sizeof(path));
 
        SEQ_printf(m, "\ncfs_rq[%d]:%s\n", cpu, path);
-#elif defined(CONFIG_USER_SCHED) && defined(CONFIG_FAIR_GROUP_SCHED)
-       {
-               uid_t uid = cfs_rq->tg->uid;
-               SEQ_printf(m, "\ncfs_rq[%d] for UID: %u\n", cpu, uid);
-       }
 #else
        SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
 #endif
@@ -409,40 +404,38 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
        PN(se.exec_start);
        PN(se.vruntime);
        PN(se.sum_exec_runtime);
-       PN(se.avg_overlap);
-       PN(se.avg_wakeup);
 
        nr_switches = p->nvcsw + p->nivcsw;
 
 #ifdef CONFIG_SCHEDSTATS
-       PN(se.wait_start);
-       PN(se.sleep_start);
-       PN(se.block_start);
-       PN(se.sleep_max);
-       PN(se.block_max);
-       PN(se.exec_max);
-       PN(se.slice_max);
-       PN(se.wait_max);
-       PN(se.wait_sum);
-       P(se.wait_count);
-       PN(se.iowait_sum);
-       P(se.iowait_count);
+       PN(se.statistics.wait_start);
+       PN(se.statistics.sleep_start);
+       PN(se.statistics.block_start);
+       PN(se.statistics.sleep_max);
+       PN(se.statistics.block_max);
+       PN(se.statistics.exec_max);
+       PN(se.statistics.slice_max);
+       PN(se.statistics.wait_max);
+       PN(se.statistics.wait_sum);
+       P(se.statistics.wait_count);
+       PN(se.statistics.iowait_sum);
+       P(se.statistics.iowait_count);
        P(sched_info.bkl_count);
        P(se.nr_migrations);
-       P(se.nr_migrations_cold);
-       P(se.nr_failed_migrations_affine);
-       P(se.nr_failed_migrations_running);
-       P(se.nr_failed_migrations_hot);
-       P(se.nr_forced_migrations);
-       P(se.nr_wakeups);
-       P(se.nr_wakeups_sync);
-       P(se.nr_wakeups_migrate);
-       P(se.nr_wakeups_local);
-       P(se.nr_wakeups_remote);
-       P(se.nr_wakeups_affine);
-       P(se.nr_wakeups_affine_attempts);
-       P(se.nr_wakeups_passive);
-       P(se.nr_wakeups_idle);
+       P(se.statistics.nr_migrations_cold);
+       P(se.statistics.nr_failed_migrations_affine);
+       P(se.statistics.nr_failed_migrations_running);
+       P(se.statistics.nr_failed_migrations_hot);
+       P(se.statistics.nr_forced_migrations);
+       P(se.statistics.nr_wakeups);
+       P(se.statistics.nr_wakeups_sync);
+       P(se.statistics.nr_wakeups_migrate);
+       P(se.statistics.nr_wakeups_local);
+       P(se.statistics.nr_wakeups_remote);
+       P(se.statistics.nr_wakeups_affine);
+       P(se.statistics.nr_wakeups_affine_attempts);
+       P(se.statistics.nr_wakeups_passive);
+       P(se.statistics.nr_wakeups_idle);
 
        {
                u64 avg_atom, avg_per_cpu;
@@ -493,31 +486,6 @@ void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
 void proc_sched_set_task(struct task_struct *p)
 {
 #ifdef CONFIG_SCHEDSTATS
-       p->se.wait_max                          = 0;
-       p->se.wait_sum                          = 0;
-       p->se.wait_count                        = 0;
-       p->se.iowait_sum                        = 0;
-       p->se.iowait_count                      = 0;
-       p->se.sleep_max                         = 0;
-       p->se.sum_sleep_runtime                 = 0;
-       p->se.block_max                         = 0;
-       p->se.exec_max                          = 0;
-       p->se.slice_max                         = 0;
-       p->se.nr_migrations                     = 0;
-       p->se.nr_migrations_cold                = 0;
-       p->se.nr_failed_migrations_affine       = 0;
-       p->se.nr_failed_migrations_running      = 0;
-       p->se.nr_failed_migrations_hot          = 0;
-       p->se.nr_forced_migrations              = 0;
-       p->se.nr_wakeups                        = 0;
-       p->se.nr_wakeups_sync                   = 0;
-       p->se.nr_wakeups_migrate                = 0;
-       p->se.nr_wakeups_local                  = 0;
-       p->se.nr_wakeups_remote                 = 0;
-       p->se.nr_wakeups_affine                 = 0;
-       p->se.nr_wakeups_affine_attempts        = 0;
-       p->se.nr_wakeups_passive                = 0;
-       p->se.nr_wakeups_idle                   = 0;
-       p->sched_info.bkl_count                 = 0;
+       memset(&p->se.statistics, 0, sizeof(p->se.statistics));
 #endif
 }
index 5a5ea2c..217e4a9 100644 (file)
@@ -35,8 +35,8 @@
  * (to see the precise effective timeslice length of your workload,
  *  run vmstat and monitor the context-switches (cs) field)
  */
-unsigned int sysctl_sched_latency = 5000000ULL;
-unsigned int normalized_sysctl_sched_latency = 5000000ULL;
+unsigned int sysctl_sched_latency = 6000000ULL;
+unsigned int normalized_sysctl_sched_latency = 6000000ULL;
 
 /*
  * The initial- and re-scaling of tunables is configurable
@@ -52,15 +52,15 @@ enum sched_tunable_scaling sysctl_sched_tunable_scaling
 
 /*
  * Minimal preemption granularity for CPU-bound tasks:
- * (default: 1 msec * (1 + ilog(ncpus)), units: nanoseconds)
+ * (default: 2 msec * (1 + ilog(ncpus)), units: nanoseconds)
  */
-unsigned int sysctl_sched_min_granularity = 1000000ULL;
-unsigned int normalized_sysctl_sched_min_granularity = 1000000ULL;
+unsigned int sysctl_sched_min_granularity = 2000000ULL;
+unsigned int normalized_sysctl_sched_min_granularity = 2000000ULL;
 
 /*
  * is kept at sysctl_sched_latency / sysctl_sched_min_granularity
  */
-static unsigned int sched_nr_latency = 5;
+static unsigned int sched_nr_latency = 3;
 
 /*
  * After fork, child runs first. If set to 0 (default) then
@@ -505,7 +505,8 @@ __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr,
 {
        unsigned long delta_exec_weighted;
 
-       schedstat_set(curr->exec_max, max((u64)delta_exec, curr->exec_max));
+       schedstat_set(curr->statistics.exec_max,
+                     max((u64)delta_exec, curr->statistics.exec_max));
 
        curr->sum_exec_runtime += delta_exec;
        schedstat_add(cfs_rq, exec_clock, delta_exec);
@@ -548,7 +549,7 @@ static void update_curr(struct cfs_rq *cfs_rq)
 static inline void
 update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
-       schedstat_set(se->wait_start, rq_of(cfs_rq)->clock);
+       schedstat_set(se->statistics.wait_start, rq_of(cfs_rq)->clock);
 }
 
 /*
@@ -567,18 +568,18 @@ static void update_stats_enqueue(struct cfs_rq *cfs_rq, struct sched_entity *se)
 static void
 update_stats_wait_end(struct cfs_rq *cfs_rq, struct sched_entity *se)
 {
-       schedstat_set(se->wait_max, max(se->wait_max,
-                       rq_of(cfs_rq)->clock - se->wait_start));
-       schedstat_set(se->wait_count, se->wait_count + 1);
-       schedstat_set(se->wait_sum, se->wait_sum +
-                       rq_of(cfs_rq)->clock - se->wait_start);
+       schedstat_set(se->statistics.wait_max, max(se->statistics.wait_max,
+                       rq_of(cfs_rq)->clock - se->statistics.wait_start));
+       schedstat_set(se->statistics.wait_count, se->statistics.wait_count + 1);
+       schedstat_set(se->statistics.wait_sum, se->statistics.wait_sum +
+                       rq_of(cfs_rq)->clock - se->statistics.wait_start);
 #ifdef CONFIG_SCHEDSTATS
        if (entity_is_task(se)) {
                trace_sched_stat_wait(task_of(se),
-                       rq_of(cfs_rq)->clock - se->wait_start);
+                       rq_of(cfs_rq)->clock - se->statistics.wait_start);
        }
 #endif
-       schedstat_set(se->wait_start, 0);
+       schedstat_set(se->statistics.wait_start, 0);
 }
 
 static inline void
@@ -657,39 +658,39 @@ static void enqueue_sleeper(struct cfs_rq *cfs_rq, struct sched_entity *se)
        if (entity_is_task(se))
                tsk = task_of(se);
 
-       if (se->sleep_start) {
-               u64 delta = rq_of(cfs_rq)->clock - se->sleep_start;
+       if (se->statistics.sleep_start) {
+               u64 delta = rq_of(cfs_rq)->clock - se->statistics.sleep_start;
 
                if ((s64)delta < 0)
                        delta = 0;
 
-               if (unlikely(delta > se->sleep_max))
-                       se->sleep_max = delta;
+               if (unlikely(delta > se->statistics.sleep_max))
+                       se->statistics.sleep_max = delta;
 
-               se->sleep_start = 0;
-               se->sum_sleep_runtime += delta;
+               se->statistics.sleep_start = 0;
+               se->statistics.sum_sleep_runtime += delta;
 
                if (tsk) {
                        account_scheduler_latency(tsk, delta >> 10, 1);
                        trace_sched_stat_sleep(tsk, delta);
                }
        }
-       if (se->block_start) {
-               u64 delta = rq_of(cfs_rq)->clock - se->block_start;
+       if (se->statistics.block_start) {
+               u64 delta = rq_of(cfs_rq)->clock - se->statistics.block_start;
 
                if ((s64)delta < 0)
                        delta = 0;
 
-               if (unlikely(delta > se->block_max))
-                       se->block_max = delta;
+               if (unlikely(delta > se->statistics.block_max))
+                       se->statistics.block_max = delta;
 
-               se->block_start = 0;
-               se->sum_sleep_runtime += delta;
+               se->statistics.block_start = 0;
+               se->statistics.sum_sleep_runtime += delta;
 
                if (tsk) {
                        if (tsk->in_iowait) {
-                               se->iowait_sum += delta;
-                               se->iowait_count++;
+                               se->statistics.iowait_sum += delta;
+                               se->statistics.iowait_count++;
                                trace_sched_stat_iowait(tsk, delta);
                        }
 
@@ -737,19 +738,9 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
                vruntime += sched_vslice(cfs_rq, se);
 
        /* sleeps up to a single latency don't count. */
-       if (!initial && sched_feat(FAIR_SLEEPERS)) {
+       if (!initial) {
                unsigned long thresh = sysctl_sched_latency;
 
-               /*
-                * Convert the sleeper threshold into virtual time.
-                * SCHED_IDLE is a special sub-class.  We care about
-                * fairness only relative to other SCHED_IDLE tasks,
-                * all of which have the same weight.
-                */
-               if (sched_feat(NORMALIZED_SLEEPER) && (!entity_is_task(se) ||
-                                task_of(se)->policy != SCHED_IDLE))
-                       thresh = calc_delta_fair(thresh, se);
-
                /*
                 * Halve their sleep time's effect, to allow
                 * for a gentler effect of sleepers:
@@ -766,9 +757,6 @@ place_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int initial)
        se->vruntime = vruntime;
 }
 
-#define ENQUEUE_WAKEUP 1
-#define ENQUEUE_MIGRATE 2
-
 static void
 enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
 {
@@ -776,7 +764,7 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
         * Update the normalized vruntime before updating min_vruntime
         * through callig update_curr().
         */
-       if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_MIGRATE))
+       if (!(flags & ENQUEUE_WAKEUP) || (flags & ENQUEUE_WAKING))
                se->vruntime += cfs_rq->min_vruntime;
 
        /*
@@ -812,7 +800,7 @@ static void clear_buddies(struct cfs_rq *cfs_rq, struct sched_entity *se)
 }
 
 static void
-dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
+dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
 {
        /*
         * Update run-time statistics of the 'current'.
@@ -820,15 +808,15 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
        update_curr(cfs_rq);
 
        update_stats_dequeue(cfs_rq, se);
-       if (sleep) {
+       if (flags & DEQUEUE_SLEEP) {
 #ifdef CONFIG_SCHEDSTATS
                if (entity_is_task(se)) {
                        struct task_struct *tsk = task_of(se);
 
                        if (tsk->state & TASK_INTERRUPTIBLE)
-                               se->sleep_start = rq_of(cfs_rq)->clock;
+                               se->statistics.sleep_start = rq_of(cfs_rq)->clock;
                        if (tsk->state & TASK_UNINTERRUPTIBLE)
-                               se->block_start = rq_of(cfs_rq)->clock;
+                               se->statistics.block_start = rq_of(cfs_rq)->clock;
                }
 #endif
        }
@@ -845,7 +833,7 @@ dequeue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int sleep)
         * update can refer to the ->curr item and we need to reflect this
         * movement in our normalized position.
         */
-       if (!sleep)
+       if (!(flags & DEQUEUE_SLEEP))
                se->vruntime -= cfs_rq->min_vruntime;
 }
 
@@ -912,7 +900,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_entity *se)
         * when there are only lesser-weight tasks around):
         */
        if (rq_of(cfs_rq)->load.weight >= 2*se->load.weight) {
-               se->slice_max = max(se->slice_max,
+               se->statistics.slice_max = max(se->statistics.slice_max,
                        se->sum_exec_runtime - se->prev_sum_exec_runtime);
        }
 #endif
@@ -1054,16 +1042,10 @@ static inline void hrtick_update(struct rq *rq)
  * then put the task into the rbtree:
  */
 static void
-enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head)
+enqueue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 {
        struct cfs_rq *cfs_rq;
        struct sched_entity *se = &p->se;
-       int flags = 0;
-
-       if (wakeup)
-               flags |= ENQUEUE_WAKEUP;
-       if (p->state == TASK_WAKING)
-               flags |= ENQUEUE_MIGRATE;
 
        for_each_sched_entity(se) {
                if (se->on_rq)
@@ -1081,18 +1063,18 @@ enqueue_task_fair(struct rq *rq, struct task_struct *p, int wakeup, bool head)
  * decreased. We remove the task from the rbtree and
  * update the fair scheduling stats:
  */
-static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int sleep)
+static void dequeue_task_fair(struct rq *rq, struct task_struct *p, int flags)
 {
        struct cfs_rq *cfs_rq;
        struct sched_entity *se = &p->se;
 
        for_each_sched_entity(se) {
                cfs_rq = cfs_rq_of(se);
-               dequeue_entity(cfs_rq, se, sleep);
+               dequeue_entity(cfs_rq, se, flags);
                /* Don't dequeue parent if it has other entities besides us */
                if (cfs_rq->load.weight)
                        break;
-               sleep = 1;
+               flags |= DEQUEUE_SLEEP;
        }
 
        hrtick_update(rq);
@@ -1240,7 +1222,6 @@ static inline unsigned long effective_load(struct task_group *tg, int cpu,
 
 static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
 {
-       struct task_struct *curr = current;
        unsigned long this_load, load;
        int idx, this_cpu, prev_cpu;
        unsigned long tl_per_task;
@@ -1255,18 +1236,6 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
        load      = source_load(prev_cpu, idx);
        this_load = target_load(this_cpu, idx);
 
-       if (sync) {
-              if (sched_feat(SYNC_LESS) &&
-                  (curr->se.avg_overlap > sysctl_sched_migration_cost ||
-                   p->se.avg_overlap > sysctl_sched_migration_cost))
-                      sync = 0;
-       } else {
-               if (sched_feat(SYNC_MORE) &&
-                   (curr->se.avg_overlap < sysctl_sched_migration_cost &&
-                    p->se.avg_overlap < sysctl_sched_migration_cost))
-                       sync = 1;
-       }
-
        /*
         * If sync wakeup then subtract the (maximum possible)
         * effect of the currently running task from the load
@@ -1306,7 +1275,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
        if (sync && balanced)
                return 1;
 
-       schedstat_inc(p, se.nr_wakeups_affine_attempts);
+       schedstat_inc(p, se.statistics.nr_wakeups_affine_attempts);
        tl_per_task = cpu_avg_load_per_task(this_cpu);
 
        if (balanced ||
@@ -1318,7 +1287,7 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync)
                 * there is no bad imbalance.
                 */
                schedstat_inc(sd, ttwu_move_affine);
-               schedstat_inc(p, se.nr_wakeups_affine);
+               schedstat_inc(p, se.statistics.nr_wakeups_affine);
 
                return 1;
        }
@@ -1406,29 +1375,48 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
 /*
  * Try and locate an idle CPU in the sched_domain.
  */
-static int
-select_idle_sibling(struct task_struct *p, struct sched_domain *sd, int target)
+static int select_idle_sibling(struct task_struct *p, int target)
 {
        int cpu = smp_processor_id();
        int prev_cpu = task_cpu(p);
+       struct sched_domain *sd;
        int i;
 
        /*
-        * If this domain spans both cpu and prev_cpu (see the SD_WAKE_AFFINE
-        * test in select_task_rq_fair) and the prev_cpu is idle then that's
-        * always a better target than the current cpu.
+        * If the task is going to be woken-up on this cpu and if it is
+        * already idle, then it is the right target.
         */
-       if (target == cpu && !cpu_rq(prev_cpu)->cfs.nr_running)
+       if (target == cpu && idle_cpu(cpu))
+               return cpu;
+
+       /*
+        * If the task is going to be woken-up on the cpu where it previously
+        * ran and if it is currently idle, then it the right target.
+        */
+       if (target == prev_cpu && idle_cpu(prev_cpu))
                return prev_cpu;
 
        /*
-        * Otherwise, iterate the domain and find an elegible idle cpu.
+        * Otherwise, iterate the domains and find an elegible idle cpu.
         */
-       for_each_cpu_and(i, sched_domain_span(sd), &p->cpus_allowed) {
-               if (!cpu_rq(i)->cfs.nr_running) {
-                       target = i;
+       for_each_domain(target, sd) {
+               if (!(sd->flags & SD_SHARE_PKG_RESOURCES))
                        break;
+
+               for_each_cpu_and(i, sched_domain_span(sd), &p->cpus_allowed) {
+                       if (idle_cpu(i)) {
+                               target = i;
+                               break;
+                       }
                }
+
+               /*
+                * Lets stop looking for an idle sibling when we reached
+                * the domain that spans the current cpu and prev_cpu.
+                */
+               if (cpumask_test_cpu(cpu, sched_domain_span(sd)) &&
+                   cpumask_test_cpu(prev_cpu, sched_domain_span(sd)))
+                       break;
        }
 
        return target;
@@ -1445,7 +1433,8 @@ select_idle_sibling(struct task_struct *p, struct sched_domain *sd, int target)
  *
  * preempt must be disabled.
  */
-static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags)
+static int
+select_task_rq_fair(struct rq *rq, struct task_struct *p, int sd_flag, int wake_flags)
 {
        struct sched_domain *tmp, *affine_sd = NULL, *sd = NULL;
        int cpu = smp_processor_id();
@@ -1456,8 +1445,7 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
        int sync = wake_flags & WF_SYNC;
 
        if (sd_flag & SD_BALANCE_WAKE) {
-               if (sched_feat(AFFINE_WAKEUPS) &&
-                   cpumask_test_cpu(cpu, &p->cpus_allowed))
+               if (cpumask_test_cpu(cpu, &p->cpus_allowed))
                        want_affine = 1;
                new_cpu = prev_cpu;
        }
@@ -1491,34 +1479,13 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
                }
 
                /*
-                * While iterating the domains looking for a spanning
-                * WAKE_AFFINE domain, adjust the affine target to any idle cpu
-                * in cache sharing domains along the way.
+                * If both cpu and prev_cpu are part of this domain,
+                * cpu is a valid SD_WAKE_AFFINE target.
                 */
-               if (want_affine) {
-                       int target = -1;
-
-                       /*
-                        * If both cpu and prev_cpu are part of this domain,
-                        * cpu is a valid SD_WAKE_AFFINE target.
-                        */
-                       if (cpumask_test_cpu(prev_cpu, sched_domain_span(tmp)))
-                               target = cpu;
-
-                       /*
-                        * If there's an idle sibling in this domain, make that
-                        * the wake_affine target instead of the current cpu.
-                        */
-                       if (tmp->flags & SD_SHARE_PKG_RESOURCES)
-                               target = select_idle_sibling(p, tmp, target);
-
-                       if (target >= 0) {
-                               if (tmp->flags & SD_WAKE_AFFINE) {
-                                       affine_sd = tmp;
-                                       want_affine = 0;
-                               }
-                               cpu = target;
-                       }
+               if (want_affine && (tmp->flags & SD_WAKE_AFFINE) &&
+                   cpumask_test_cpu(prev_cpu, sched_domain_span(tmp))) {
+                       affine_sd = tmp;
+                       want_affine = 0;
                }
 
                if (!want_sd && !want_affine)
@@ -1531,22 +1498,29 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
                        sd = tmp;
        }
 
+#ifdef CONFIG_FAIR_GROUP_SCHED
        if (sched_feat(LB_SHARES_UPDATE)) {
                /*
                 * Pick the largest domain to update shares over
                 */
                tmp = sd;
-               if (affine_sd && (!tmp ||
-                                 cpumask_weight(sched_domain_span(affine_sd)) >
-                                 cpumask_weight(sched_domain_span(sd))))
+               if (affine_sd && (!tmp || affine_sd->span_weight > sd->span_weight))
                        tmp = affine_sd;
 
-               if (tmp)
+               if (tmp) {
+                       raw_spin_unlock(&rq->lock);
                        update_shares(tmp);
+                       raw_spin_lock(&rq->lock);
+               }
        }
+#endif
 
-       if (affine_sd && wake_affine(affine_sd, p, sync))
-               return cpu;
+       if (affine_sd) {
+               if (cpu == prev_cpu || wake_affine(affine_sd, p, sync))
+                       return select_idle_sibling(p, cpu);
+               else
+                       return select_idle_sibling(p, prev_cpu);
+       }
 
        while (sd) {
                int load_idx = sd->forkexec_idx;
@@ -1576,10 +1550,10 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
 
                /* Now try balancing at a lower domain level of new_cpu */
                cpu = new_cpu;
-               weight = cpumask_weight(sched_domain_span(sd));
+               weight = sd->span_weight;
                sd = NULL;
                for_each_domain(cpu, tmp) {
-                       if (weight <= cpumask_weight(sched_domain_span(tmp)))
+                       if (weight <= tmp->span_weight)
                                break;
                        if (tmp->flags & sd_flag)
                                sd = tmp;
@@ -1591,63 +1565,26 @@ static int select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flag
 }
 #endif /* CONFIG_SMP */
 
-/*
- * Adaptive granularity
- *
- * se->avg_wakeup gives the average time a task runs until it does a wakeup,
- * with the limit of wakeup_gran -- when it never does a wakeup.
- *
- * So the smaller avg_wakeup is the faster we want this task to preempt,
- * but we don't want to treat the preemptee unfairly and therefore allow it
- * to run for at least the amount of time we'd like to run.
- *
- * NOTE: we use 2*avg_wakeup to increase the probability of actually doing one
- *
- * NOTE: we use *nr_running to scale with load, this nicely matches the
- *       degrading latency on load.
- */
-static unsigned long
-adaptive_gran(struct sched_entity *curr, struct sched_entity *se)
-{
-       u64 this_run = curr->sum_exec_runtime - curr->prev_sum_exec_runtime;
-       u64 expected_wakeup = 2*se->avg_wakeup * cfs_rq_of(se)->nr_running;
-       u64 gran = 0;
-
-       if (this_run < expected_wakeup)
-               gran = expected_wakeup - this_run;
-
-       return min_t(s64, gran, sysctl_sched_wakeup_granularity);
-}
-
 static unsigned long
 wakeup_gran(struct sched_entity *curr, struct sched_entity *se)
 {
        unsigned long gran = sysctl_sched_wakeup_granularity;
 
-       if (cfs_rq_of(curr)->curr && sched_feat(ADAPTIVE_GRAN))
-               gran = adaptive_gran(curr, se);
-
        /*
         * Since its curr running now, convert the gran from real-time
         * to virtual-time in his units.
+        *
+        * By using 'se' instead of 'curr' we penalize light tasks, so
+        * they get preempted easier. That is, if 'se' < 'curr' then
+        * the resulting gran will be larger, therefore penalizing the
+        * lighter, if otoh 'se' > 'curr' then the resulting gran will
+        * be smaller, again penalizing the lighter task.
+        *
+        * This is especially important for buddies when the leftmost
+        * task is higher priority than the buddy.
         */
-       if (sched_feat(ASYM_GRAN)) {
-               /*
-                * By using 'se' instead of 'curr' we penalize light tasks, so
-                * they get preempted easier. That is, if 'se' < 'curr' then
-                * the resulting gran will be larger, therefore penalizing the
-                * lighter, if otoh 'se' > 'curr' then the resulting gran will
-                * be smaller, again penalizing the lighter task.
-                *
-                * This is especially important for buddies when the leftmost
-                * task is higher priority than the buddy.
-                */
-               if (unlikely(se->load.weight != NICE_0_LOAD))
-                       gran = calc_delta_fair(gran, se);
-       } else {
-               if (unlikely(curr->load.weight != NICE_0_LOAD))
-                       gran = calc_delta_fair(gran, curr);
-       }
+       if (unlikely(se->load.weight != NICE_0_LOAD))
+               gran = calc_delta_fair(gran, se);
 
        return gran;
 }
@@ -1705,7 +1642,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
        struct task_struct *curr = rq->curr;
        struct sched_entity *se = &curr->se, *pse = &p->se;
        struct cfs_rq *cfs_rq = task_cfs_rq(curr);
-       int sync = wake_flags & WF_SYNC;
        int scale = cfs_rq->nr_running >= sched_nr_latency;
 
        if (unlikely(rt_prio(p->prio)))
@@ -1738,14 +1674,6 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int wake_
        if (unlikely(curr->policy == SCHED_IDLE))
                goto preempt;
 
-       if (sched_feat(WAKEUP_SYNC) && sync)
-               goto preempt;
-
-       if (sched_feat(WAKEUP_OVERLAP) &&
-                       se->avg_overlap < sysctl_sched_migration_cost &&
-                       pse->avg_overlap < sysctl_sched_migration_cost)
-               goto preempt;
-
        if (!sched_feat(WAKEUP_PREEMPT))
                return;
 
@@ -1844,13 +1772,13 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu,
         * 3) are cache-hot on their current CPU.
         */
        if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) {
-               schedstat_inc(p, se.nr_failed_migrations_affine);
+               schedstat_inc(p, se.statistics.nr_failed_migrations_affine);
                return 0;
        }
        *all_pinned = 0;
 
        if (task_running(rq, p)) {
-               schedstat_inc(p, se.nr_failed_migrations_running);
+               schedstat_inc(p, se.statistics.nr_failed_migrations_running);
                return 0;
        }
 
@@ -1866,14 +1794,14 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu,
 #ifdef CONFIG_SCHEDSTATS
                if (tsk_cache_hot) {
                        schedstat_inc(sd, lb_hot_gained[idle]);
-                       schedstat_inc(p, se.nr_forced_migrations);
+                       schedstat_inc(p, se.statistics.nr_forced_migrations);
                }
 #endif
                return 1;
        }
 
        if (tsk_cache_hot) {
-               schedstat_inc(p, se.nr_failed_migrations_hot);
+               schedstat_inc(p, se.statistics.nr_failed_migrations_hot);
                return 0;
        }
        return 1;
@@ -2311,7 +2239,7 @@ unsigned long __weak arch_scale_freq_power(struct sched_domain *sd, int cpu)
 
 unsigned long default_scale_smt_power(struct sched_domain *sd, int cpu)
 {
-       unsigned long weight = cpumask_weight(sched_domain_span(sd));
+       unsigned long weight = sd->span_weight;
        unsigned long smt_gain = sd->smt_gain;
 
        smt_gain /= weight;
@@ -2344,7 +2272,7 @@ unsigned long scale_rt_power(int cpu)
 
 static void update_cpu_power(struct sched_domain *sd, int cpu)
 {
-       unsigned long weight = cpumask_weight(sched_domain_span(sd));
+       unsigned long weight = sd->span_weight;
        unsigned long power = SCHED_LOAD_SCALE;
        struct sched_group *sdg = sd->groups;
 
@@ -2870,6 +2798,8 @@ static int need_active_balance(struct sched_domain *sd, int sd_idle, int idle)
        return unlikely(sd->nr_balance_failed > sd->cache_nice_tries+2);
 }
 
+static int active_load_balance_cpu_stop(void *data);
+
 /*
  * Check this_cpu to ensure it is balanced within domain. Attempt to move
  * tasks if there is an imbalance.
@@ -2959,8 +2889,9 @@ redo:
                if (need_active_balance(sd, sd_idle, idle)) {
                        raw_spin_lock_irqsave(&busiest->lock, flags);
 
-                       /* don't kick the migration_thread, if the curr
-                        * task on busiest cpu can't be moved to this_cpu
+                       /* don't kick the active_load_balance_cpu_stop,
+                        * if the curr task on busiest cpu can't be
+                        * moved to this_cpu
                         */
                        if (!cpumask_test_cpu(this_cpu,
                                              &busiest->curr->cpus_allowed)) {
@@ -2970,14 +2901,22 @@ redo:
                                goto out_one_pinned;
                        }
 
+                       /*
+                        * ->active_balance synchronizes accesses to
+                        * ->active_balance_work.  Once set, it's cleared
+                        * only after active load balance is finished.
+                        */
                        if (!busiest->active_balance) {
                                busiest->active_balance = 1;
                                busiest->push_cpu = this_cpu;
                                active_balance = 1;
                        }
                        raw_spin_unlock_irqrestore(&busiest->lock, flags);
+
                        if (active_balance)
-                               wake_up_process(busiest->migration_thread);
+                               stop_one_cpu_nowait(cpu_of(busiest),
+                                       active_load_balance_cpu_stop, busiest,
+                                       &busiest->active_balance_work);
 
                        /*
                         * We've kicked active balancing, reset the failure
@@ -3084,24 +3023,29 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
 }
 
 /*
- * active_load_balance is run by migration threads. It pushes running tasks
- * off the busiest CPU onto idle CPUs. It requires at least 1 task to be
- * running on each physical CPU where possible, and avoids physical /
- * logical imbalances.
- *
- * Called with busiest_rq locked.
+ * active_load_balance_cpu_stop is run by cpu stopper. It pushes
+ * running tasks off the busiest CPU onto idle CPUs. It requires at
+ * least 1 task to be running on each physical CPU where possible, and
+ * avoids physical / logical imbalances.
  */
-static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
+static int active_load_balance_cpu_stop(void *data)
 {
+       struct rq *busiest_rq = data;
+       int busiest_cpu = cpu_of(busiest_rq);
        int target_cpu = busiest_rq->push_cpu;
+       struct rq *target_rq = cpu_rq(target_cpu);
        struct sched_domain *sd;
-       struct rq *target_rq;
+
+       raw_spin_lock_irq(&busiest_rq->lock);
+
+       /* make sure the requested cpu hasn't gone down in the meantime */
+       if (unlikely(busiest_cpu != smp_processor_id() ||
+                    !busiest_rq->active_balance))
+               goto out_unlock;
 
        /* Is there any task to move? */
        if (busiest_rq->nr_running <= 1)
-               return;
-
-       target_rq = cpu_rq(target_cpu);
+               goto out_unlock;
 
        /*
         * This condition is "impossible", if it occurs
@@ -3112,8 +3056,6 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
 
        /* move a task from busiest_rq to target_rq */
        double_lock_balance(busiest_rq, target_rq);
-       update_rq_clock(busiest_rq);
-       update_rq_clock(target_rq);
 
        /* Search for an sd spanning us and the target CPU. */
        for_each_domain(target_cpu, sd) {
@@ -3132,6 +3074,10 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
                        schedstat_inc(sd, alb_failed);
        }
        double_unlock_balance(busiest_rq, target_rq);
+out_unlock:
+       busiest_rq->active_balance = 0;
+       raw_spin_unlock_irq(&busiest_rq->lock);
+       return 0;
 }
 
 #ifdef CONFIG_NO_HZ
index d5059fd..83c66e8 100644 (file)
@@ -1,10 +1,3 @@
-/*
- * Disregards a certain amount of sleep time (sched_latency_ns) and
- * considers the task to be running during that period. This gives it
- * a service deficit on wakeup, allowing it to run sooner.
- */
-SCHED_FEAT(FAIR_SLEEPERS, 1)
-
 /*
  * Only give sleepers 50% of their service deficit. This allows
  * them to run sooner, but does not allow tons of sleepers to
@@ -12,13 +5,6 @@ SCHED_FEAT(FAIR_SLEEPERS, 1)
  */
 SCHED_FEAT(GENTLE_FAIR_SLEEPERS, 1)
 
-/*
- * By not normalizing the sleep time, heavy tasks get an effective
- * longer period, and lighter task an effective shorter period they
- * are considered running.
- */
-SCHED_FEAT(NORMALIZED_SLEEPER, 0)
-
 /*
  * Place new tasks ahead so that they do not starve already running
  * tasks
@@ -30,37 +16,6 @@ SCHED_FEAT(START_DEBIT, 1)
  */
 SCHED_FEAT(WAKEUP_PREEMPT, 1)
 
-/*
- * Compute wakeup_gran based on task behaviour, clipped to
- *  [0, sched_wakeup_gran_ns]
- */
-SCHED_FEAT(ADAPTIVE_GRAN, 1)
-
-/*
- * When converting the wakeup granularity to virtual time, do it such
- * that heavier tasks preempting a lighter task have an edge.
- */
-SCHED_FEAT(ASYM_GRAN, 1)
-
-/*
- * Always wakeup-preempt SYNC wakeups, see SYNC_WAKEUPS.
- */
-SCHED_FEAT(WAKEUP_SYNC, 0)
-
-/*
- * Wakeup preempt based on task behaviour. Tasks that do not overlap
- * don't get preempted.
- */
-SCHED_FEAT(WAKEUP_OVERLAP, 0)
-
-/*
- * Use the SYNC wakeup hint, pipes and the likes use this to indicate
- * the remote end is likely to consume the data we just wrote, and
- * therefore has cache benefit from being placed on the same cpu, see
- * also AFFINE_WAKEUPS.
- */
-SCHED_FEAT(SYNC_WAKEUPS, 1)
-
 /*
  * Based on load and program behaviour, see if it makes sense to place
  * a newly woken task on the same cpu as the task that woke it --
@@ -69,16 +24,6 @@ SCHED_FEAT(SYNC_WAKEUPS, 1)
  */
 SCHED_FEAT(AFFINE_WAKEUPS, 1)
 
-/*
- * Weaken SYNC hint based on overlap
- */
-SCHED_FEAT(SYNC_LESS, 1)
-
-/*
- * Add SYNC hint based on overlap
- */
-SCHED_FEAT(SYNC_MORE, 0)
-
 /*
  * Prefer to schedule the task we woke last (assuming it failed
  * wakeup-preemption), since its likely going to consume data we
index a8a6d8a..9fa0f40 100644 (file)
@@ -6,7 +6,8 @@
  */
 
 #ifdef CONFIG_SMP
-static int select_task_rq_idle(struct task_struct *p, int sd_flag, int flags)
+static int
+select_task_rq_idle(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
 {
        return task_cpu(p); /* IDLE tasks as never migrated */
 }
@@ -22,8 +23,7 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl
 static struct task_struct *pick_next_task_idle(struct rq *rq)
 {
        schedstat_inc(rq, sched_goidle);
-       /* adjust the active tasks as we might go into a long sleep */
-       calc_load_account_active(rq);
+       calc_load_account_idle(rq);
        return rq->idle;
 }
 
@@ -32,7 +32,7 @@ static struct task_struct *pick_next_task_idle(struct rq *rq)
  * message if some code attempts to do it:
  */
 static void
-dequeue_task_idle(struct rq *rq, struct task_struct *p, int sleep)
+dequeue_task_idle(struct rq *rq, struct task_struct *p, int flags)
 {
        raw_spin_unlock_irq(&rq->lock);
        printk(KERN_ERR "bad: scheduling from the idle thread!\n");
index b5b920a..8afb953 100644 (file)
@@ -613,7 +613,7 @@ static void update_curr_rt(struct rq *rq)
        if (unlikely((s64)delta_exec < 0))
                delta_exec = 0;
 
-       schedstat_set(curr->se.exec_max, max(curr->se.exec_max, delta_exec));
+       schedstat_set(curr->se.statistics.exec_max, max(curr->se.statistics.exec_max, delta_exec));
 
        curr->se.sum_exec_runtime += delta_exec;
        account_group_exec_runtime(curr, delta_exec);
@@ -888,20 +888,20 @@ static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
  * Adding/removing a task to/from a priority array:
  */
 static void
-enqueue_task_rt(struct rq *rq, struct task_struct *p, int wakeup, bool head)
+enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
 {
        struct sched_rt_entity *rt_se = &p->rt;
 
-       if (wakeup)
+       if (flags & ENQUEUE_WAKEUP)
                rt_se->timeout = 0;
 
-       enqueue_rt_entity(rt_se, head);
+       enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
 
        if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1)
                enqueue_pushable_task(rq, p);
 }
 
-static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int sleep)
+static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
 {
        struct sched_rt_entity *rt_se = &p->rt;
 
@@ -948,10 +948,9 @@ static void yield_task_rt(struct rq *rq)
 #ifdef CONFIG_SMP
 static int find_lowest_rq(struct task_struct *task);
 
-static int select_task_rq_rt(struct task_struct *p, int sd_flag, int flags)
+static int
+select_task_rq_rt(struct rq *rq, struct task_struct *p, int sd_flag, int flags)
 {
-       struct rq *rq = task_rq(p);
-
        if (sd_flag != SD_BALANCE_WAKE)
                return smp_processor_id();
 
index 7c1a67e..0db913a 100644 (file)
@@ -716,7 +716,7 @@ static int run_ksoftirqd(void * __bind_cpu)
                        preempt_enable_no_resched();
                        cond_resched();
                        preempt_disable();
-                       rcu_sched_qs((long)__bind_cpu);
+                       rcu_note_context_switch((long)__bind_cpu);
                }
                preempt_enable();
                set_current_state(TASK_INTERRUPTIBLE);
index 9bb9fb1..b4e7431 100644 (file)
-/* Copyright 2008, 2005 Rusty Russell rusty@rustcorp.com.au IBM Corporation.
- * GPL v2 and any later version.
+/*
+ * kernel/stop_machine.c
+ *
+ * Copyright (C) 2008, 2005    IBM Corporation.
+ * Copyright (C) 2008, 2005    Rusty Russell rusty@rustcorp.com.au
+ * Copyright (C) 2010          SUSE Linux Products GmbH
+ * Copyright (C) 2010          Tejun Heo <tj@kernel.org>
+ *
+ * This file is released under the GPLv2 and any later version.
  */
+#include <linux/completion.h>
 #include <linux/cpu.h>
-#include <linux/err.h>
+#include <linux/init.h>
 #include <linux/kthread.h>
 #include <linux/module.h>
+#include <linux/percpu.h>
 #include <linux/sched.h>
 #include <linux/stop_machine.h>
-#include <linux/syscalls.h>
 #include <linux/interrupt.h>
+#include <linux/kallsyms.h>
 
 #include <asm/atomic.h>
-#include <asm/uaccess.h>
+
+/*
+ * Structure to determine completion condition and record errors.  May
+ * be shared by works on different cpus.
+ */
+struct cpu_stop_done {
+       atomic_t                nr_todo;        /* nr left to execute */
+       bool                    executed;       /* actually executed? */
+       int                     ret;            /* collected return value */
+       struct completion       completion;     /* fired if nr_todo reaches 0 */
+};
+
+/* the actual stopper, one per every possible cpu, enabled on online cpus */
+struct cpu_stopper {
+       spinlock_t              lock;
+       struct list_head        works;          /* list of pending works */
+       struct task_struct      *thread;        /* stopper thread */
+       bool                    enabled;        /* is this stopper enabled? */
+};
+
+static DEFINE_PER_CPU(struct cpu_stopper, cpu_stopper);
+
+static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
+{
+       memset(done, 0, sizeof(*done));
+       atomic_set(&done->nr_todo, nr_todo);
+       init_completion(&done->completion);
+}
+
+/* signal completion unless @done is NULL */
+static void cpu_stop_signal_done(struct cpu_stop_done *done, bool executed)
+{
+       if (done) {
+               if (executed)
+                       done->executed = true;
+               if (atomic_dec_and_test(&done->nr_todo))
+                       complete(&done->completion);
+       }
+}
+
+/* queue @work to @stopper.  if offline, @work is completed immediately */
+static void cpu_stop_queue_work(struct cpu_stopper *stopper,
+                               struct cpu_stop_work *work)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&stopper->lock, flags);
+
+       if (stopper->enabled) {
+               list_add_tail(&work->list, &stopper->works);
+               wake_up_process(stopper->thread);
+       } else
+               cpu_stop_signal_done(work->done, false);
+
+       spin_unlock_irqrestore(&stopper->lock, flags);
+}
+
+/**
+ * stop_one_cpu - stop a cpu
+ * @cpu: cpu to stop
+ * @fn: function to execute
+ * @arg: argument to @fn
+ *
+ * Execute @fn(@arg) on @cpu.  @fn is run in a process context with
+ * the highest priority preempting any task on the cpu and
+ * monopolizing it.  This function returns after the execution is
+ * complete.
+ *
+ * This function doesn't guarantee @cpu stays online till @fn
+ * completes.  If @cpu goes down in the middle, execution may happen
+ * partially or fully on different cpus.  @fn should either be ready
+ * for that or the caller should ensure that @cpu stays online until
+ * this function completes.
+ *
+ * CONTEXT:
+ * Might sleep.
+ *
+ * RETURNS:
+ * -ENOENT if @fn(@arg) was not executed because @cpu was offline;
+ * otherwise, the return value of @fn.
+ */
+int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg)
+{
+       struct cpu_stop_done done;
+       struct cpu_stop_work work = { .fn = fn, .arg = arg, .done = &done };
+
+       cpu_stop_init_done(&done, 1);
+       cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), &work);
+       wait_for_completion(&done.completion);
+       return done.executed ? done.ret : -ENOENT;
+}
+
+/**
+ * stop_one_cpu_nowait - stop a cpu but don't wait for completion
+ * @cpu: cpu to stop
+ * @fn: function to execute
+ * @arg: argument to @fn
+ *
+ * Similar to stop_one_cpu() but doesn't wait for completion.  The
+ * caller is responsible for ensuring @work_buf is currently unused
+ * and will remain untouched until stopper starts executing @fn.
+ *
+ * CONTEXT:
+ * Don't care.
+ */
+void stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
+                       struct cpu_stop_work *work_buf)
+{
+       *work_buf = (struct cpu_stop_work){ .fn = fn, .arg = arg, };
+       cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu), work_buf);
+}
+
+/* static data for stop_cpus */
+static DEFINE_MUTEX(stop_cpus_mutex);
+static DEFINE_PER_CPU(struct cpu_stop_work, stop_cpus_work);
+
+int __stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)
+{
+       struct cpu_stop_work *work;
+       struct cpu_stop_done done;
+       unsigned int cpu;
+
+       /* initialize works and done */
+       for_each_cpu(cpu, cpumask) {
+               work = &per_cpu(stop_cpus_work, cpu);
+               work->fn = fn;
+               work->arg = arg;
+               work->done = &done;
+       }
+       cpu_stop_init_done(&done, cpumask_weight(cpumask));
+
+       /*
+        * Disable preemption while queueing to avoid getting
+        * preempted by a stopper which might wait for other stoppers
+        * to enter @fn which can lead to deadlock.
+        */
+       preempt_disable();
+       for_each_cpu(cpu, cpumask)
+               cpu_stop_queue_work(&per_cpu(cpu_stopper, cpu),
+                                   &per_cpu(stop_cpus_work, cpu));
+       preempt_enable();
+
+       wait_for_completion(&done.completion);
+       return done.executed ? done.ret : -ENOENT;
+}
+
+/**
+ * stop_cpus - stop multiple cpus
+ * @cpumask: cpus to stop
+ * @fn: function to execute
+ * @arg: argument to @fn
+ *
+ * Execute @fn(@arg) on online cpus in @cpumask.  On each target cpu,
+ * @fn is run in a process context with the highest priority
+ * preempting any task on the cpu and monopolizing it.  This function
+ * returns after all executions are complete.
+ *
+ * This function doesn't guarantee the cpus in @cpumask stay online
+ * till @fn completes.  If some cpus go down in the middle, execution
+ * on the cpu may happen partially or fully on different cpus.  @fn
+ * should either be ready for that or the caller should ensure that
+ * the cpus stay online until this function completes.
+ *
+ * All stop_cpus() calls are serialized making it safe for @fn to wait
+ * for all cpus to start executing it.
+ *
+ * CONTEXT:
+ * Might sleep.
+ *
+ * RETURNS:
+ * -ENOENT if @fn(@arg) was not executed at all because all cpus in
+ * @cpumask were offline; otherwise, 0 if all executions of @fn
+ * returned 0, any non zero return value if any returned non zero.
+ */
+int stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)
+{
+       int ret;
+
+       /* static works are used, process one request at a time */
+       mutex_lock(&stop_cpus_mutex);
+       ret = __stop_cpus(cpumask, fn, arg);
+       mutex_unlock(&stop_cpus_mutex);
+       return ret;
+}
+
+/**
+ * try_stop_cpus - try to stop multiple cpus
+ * @cpumask: cpus to stop
+ * @fn: function to execute
+ * @arg: argument to @fn
+ *
+ * Identical to stop_cpus() except that it fails with -EAGAIN if
+ * someone else is already using the facility.
+ *
+ * CONTEXT:
+ * Might sleep.
+ *
+ * RETURNS:
+ * -EAGAIN if someone else is already stopping cpus, -ENOENT if
+ * @fn(@arg) was not executed at all because all cpus in @cpumask were
+ * offline; otherwise, 0 if all executions of @fn returned 0, any non
+ * zero return value if any returned non zero.
+ */
+int try_stop_cpus(const struct cpumask *cpumask, cpu_stop_fn_t fn, void *arg)
+{
+       int ret;
+
+       /* static works are used, process one request at a time */
+       if (!mutex_trylock(&stop_cpus_mutex))
+               return -EAGAIN;
+       ret = __stop_cpus(cpumask, fn, arg);
+       mutex_unlock(&stop_cpus_mutex);
+       return ret;
+}
+
+static int cpu_stopper_thread(void *data)
+{
+       struct cpu_stopper *stopper = data;
+       struct cpu_stop_work *work;
+       int ret;
+
+repeat:
+       set_current_state(TASK_INTERRUPTIBLE);  /* mb paired w/ kthread_stop */
+
+       if (kthread_should_stop()) {
+               __set_current_state(TASK_RUNNING);
+               return 0;
+       }
+
+       work = NULL;
+       spin_lock_irq(&stopper->lock);
+       if (!list_empty(&stopper->works)) {
+               work = list_first_entry(&stopper->works,
+                                       struct cpu_stop_work, list);
+               list_del_init(&work->list);
+       }
+       spin_unlock_irq(&stopper->lock);
+
+       if (work) {
+               cpu_stop_fn_t fn = work->fn;
+               void *arg = work->arg;
+               struct cpu_stop_done *done = work->done;
+               char ksym_buf[KSYM_NAME_LEN];
+
+               __set_current_state(TASK_RUNNING);
+
+               /* cpu stop callbacks are not allowed to sleep */
+               preempt_disable();
+
+               ret = fn(arg);
+               if (ret)
+                       done->ret = ret;
+
+               /* restore preemption and check it's still balanced */
+               preempt_enable();
+               WARN_ONCE(preempt_count(),
+                         "cpu_stop: %s(%p) leaked preempt count\n",
+                         kallsyms_lookup((unsigned long)fn, NULL, NULL, NULL,
+                                         ksym_buf), arg);
+
+               cpu_stop_signal_done(done, true);
+       } else
+               schedule();
+
+       goto repeat;
+}
+
+/* manage stopper for a cpu, mostly lifted from sched migration thread mgmt */
+static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
+                                          unsigned long action, void *hcpu)
+{
+       struct sched_param param = { .sched_priority = MAX_RT_PRIO - 1 };
+       unsigned int cpu = (unsigned long)hcpu;
+       struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
+       struct task_struct *p;
+
+       switch (action & ~CPU_TASKS_FROZEN) {
+       case CPU_UP_PREPARE:
+               BUG_ON(stopper->thread || stopper->enabled ||
+                      !list_empty(&stopper->works));
+               p = kthread_create(cpu_stopper_thread, stopper, "migration/%d",
+                                  cpu);
+               if (IS_ERR(p))
+                       return NOTIFY_BAD;
+               sched_setscheduler_nocheck(p, SCHED_FIFO, &param);
+               get_task_struct(p);
+               stopper->thread = p;
+               break;
+
+       case CPU_ONLINE:
+               kthread_bind(stopper->thread, cpu);
+               /* strictly unnecessary, as first user will wake it */
+               wake_up_process(stopper->thread);
+               /* mark enabled */
+               spin_lock_irq(&stopper->lock);
+               stopper->enabled = true;
+               spin_unlock_irq(&stopper->lock);
+               break;
+
+#ifdef CONFIG_HOTPLUG_CPU
+       case CPU_UP_CANCELED:
+       case CPU_DEAD:
+       {
+               struct cpu_stop_work *work;
+
+               /* kill the stopper */
+               kthread_stop(stopper->thread);
+               /* drain remaining works */
+               spin_lock_irq(&stopper->lock);
+               list_for_each_entry(work, &stopper->works, list)
+                       cpu_stop_signal_done(work->done, false);
+               stopper->enabled = false;
+               spin_unlock_irq(&stopper->lock);
+               /* release the stopper */
+               put_task_struct(stopper->thread);
+               stopper->thread = NULL;
+               break;
+       }
+#endif
+       }
+
+       return NOTIFY_OK;
+}
+
+/*
+ * Give it a higher priority so that cpu stopper is available to other
+ * cpu notifiers.  It currently shares the same priority as sched
+ * migration_notifier.
+ */
+static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
+       .notifier_call  = cpu_stop_cpu_callback,
+       .priority       = 10,
+};
+
+static int __init cpu_stop_init(void)
+{
+       void *bcpu = (void *)(long)smp_processor_id();
+       unsigned int cpu;
+       int err;
+
+       for_each_possible_cpu(cpu) {
+               struct cpu_stopper *stopper = &per_cpu(cpu_stopper, cpu);
+
+               spin_lock_init(&stopper->lock);
+               INIT_LIST_HEAD(&stopper->works);
+       }
+
+       /* start one for the boot cpu */
+       err = cpu_stop_cpu_callback(&cpu_stop_cpu_notifier, CPU_UP_PREPARE,
+                                   bcpu);
+       BUG_ON(err == NOTIFY_BAD);
+       cpu_stop_cpu_callback(&cpu_stop_cpu_notifier, CPU_ONLINE, bcpu);
+       register_cpu_notifier(&cpu_stop_cpu_notifier);
+
+       return 0;
+}
+early_initcall(cpu_stop_init);
+
+#ifdef CONFIG_STOP_MACHINE
 
 /* This controls the threads on each CPU. */
 enum stopmachine_state {
@@ -26,174 +393,94 @@ enum stopmachine_state {
        /* Exit */
        STOPMACHINE_EXIT,
 };
-static enum stopmachine_state state;
 
 struct stop_machine_data {
-       int (*fn)(void *);
-       void *data;
-       int fnret;
+       int                     (*fn)(void *);
+       void                    *data;
+       /* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */
+       unsigned int            num_threads;
+       const struct cpumask    *active_cpus;
+
+       enum stopmachine_state  state;
+       atomic_t                thread_ack;
 };
 
-/* Like num_online_cpus(), but hotplug cpu uses us, so we need this. */
-static unsigned int num_threads;
-static atomic_t thread_ack;
-static DEFINE_MUTEX(lock);
-/* setup_lock protects refcount, stop_machine_wq and stop_machine_work. */
-static DEFINE_MUTEX(setup_lock);
-/* Users of stop_machine. */
-static int refcount;
-static struct workqueue_struct *stop_machine_wq;
-static struct stop_machine_data active, idle;
-static const struct cpumask *active_cpus;
-static void __percpu *stop_machine_work;
-
-static void set_state(enum stopmachine_state newstate)
+static void set_state(struct stop_machine_data *smdata,
+                     enum stopmachine_state newstate)
 {
        /* Reset ack counter. */
-       atomic_set(&thread_ack, num_threads);
+       atomic_set(&smdata->thread_ack, smdata->num_threads);
        smp_wmb();
-       state = newstate;
+       smdata->state = newstate;
 }
 
 /* Last one to ack a state moves to the next state. */
-static void ack_state(void)
+static void ack_state(struct stop_machine_data *smdata)
 {
-       if (atomic_dec_and_test(&thread_ack))
-               set_state(state + 1);
+       if (atomic_dec_and_test(&smdata->thread_ack))
+               set_state(smdata, smdata->state + 1);
 }
 
-/* This is the actual function which stops the CPU. It runs
- * in the context of a dedicated stopmachine workqueue. */
-static void stop_cpu(struct work_struct *unused)
+/* This is the cpu_stop function which stops the CPU. */
+static int stop_machine_cpu_stop(void *data)
 {
+       struct stop_machine_data *smdata = data;
        enum stopmachine_state curstate = STOPMACHINE_NONE;
-       struct stop_machine_data *smdata = &idle;
-       int cpu = smp_processor_id();
-       int err;
+       int cpu = smp_processor_id(), err = 0;
+       bool is_active;
+
+       if (!smdata->active_cpus)
+               is_active = cpu == cpumask_first(cpu_online_mask);
+       else
+               is_active = cpumask_test_cpu(cpu, smdata->active_cpus);
 
-       if (!active_cpus) {
-               if (cpu == cpumask_first(cpu_online_mask))
-                       smdata = &active;
-       } else {
-               if (cpumask_test_cpu(cpu, active_cpus))
-                       smdata = &active;
-       }
        /* Simple state machine */
        do {
                /* Chill out and ensure we re-read stopmachine_state. */
                cpu_relax();
-               if (state != curstate) {
-                       curstate = state;
+               if (smdata->state != curstate) {
+                       curstate = smdata->state;
                        switch (curstate) {
                        case STOPMACHINE_DISABLE_IRQ:
                                local_irq_disable();
                                hard_irq_disable();
                                break;
                        case STOPMACHINE_RUN:
-                               /* On multiple CPUs only a single error code
-                                * is needed to tell that something failed. */
-                               err = smdata->fn(smdata->data);
-                               if (err)
-                                       smdata->fnret = err;
+                               if (is_active)
+                                       err = smdata->fn(smdata->data);
                                break;
                        default:
                                break;
                        }
-                       ack_state();
+                       ack_state(smdata);
                }
        } while (curstate != STOPMACHINE_EXIT);
 
        local_irq_enable();
+       return err;
 }
 
-/* Callback for CPUs which aren't supposed to do anything. */
-static int chill(void *unused)
-{
-       return 0;
-}
-
-int stop_machine_create(void)
-{
-       mutex_lock(&setup_lock);
-       if (refcount)
-               goto done;
-       stop_machine_wq = create_rt_workqueue("kstop");
-       if (!stop_machine_wq)
-               goto err_out;
-       stop_machine_work = alloc_percpu(struct work_struct);
-       if (!stop_machine_work)
-               goto err_out;
-done:
-       refcount++;
-       mutex_unlock(&setup_lock);
-       return 0;
-
-err_out:
-       if (stop_machine_wq)
-               destroy_workqueue(stop_machine_wq);
-       mutex_unlock(&setup_lock);
-       return -ENOMEM;
-}
-EXPORT_SYMBOL_GPL(stop_machine_create);
-
-void stop_machine_destroy(void)
-{
-       mutex_lock(&setup_lock);
-       refcount--;
-       if (refcount)
-               goto done;
-       destroy_workqueue(stop_machine_wq);
-       free_percpu(stop_machine_work);
-done:
-       mutex_unlock(&setup_lock);
-}
-EXPORT_SYMBOL_GPL(stop_machine_destroy);
-
 int __stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
 {
-       struct work_struct *sm_work;
-       int i, ret;
-
-       /* Set up initial state. */
-       mutex_lock(&lock);
-       num_threads = num_online_cpus();
-       active_cpus = cpus;
-       active.fn = fn;
-       active.data = data;
-       active.fnret = 0;
-       idle.fn = chill;
-       idle.data = NULL;
-
-       set_state(STOPMACHINE_PREPARE);
-
-       /* Schedule the stop_cpu work on all cpus: hold this CPU so one
-        * doesn't hit this CPU until we're ready. */
-       get_cpu();
-       for_each_online_cpu(i) {
-               sm_work = per_cpu_ptr(stop_machine_work, i);
-               INIT_WORK(sm_work, stop_cpu);
-               queue_work_on(i, stop_machine_wq, sm_work);
-       }
-       /* This will release the thread on our CPU. */
-       put_cpu();
-       flush_workqueue(stop_machine_wq);
-       ret = active.fnret;
-       mutex_unlock(&lock);
-       return ret;
+       struct stop_machine_data smdata = { .fn = fn, .data = data,
+                                           .num_threads = num_online_cpus(),
+                                           .active_cpus = cpus };
+
+       /* Set the initial state and stop all online cpus. */
+       set_state(&smdata, STOPMACHINE_PREPARE);
+       return stop_cpus(cpu_online_mask, stop_machine_cpu_stop, &smdata);
 }
 
 int stop_machine(int (*fn)(void *), void *data, const struct cpumask *cpus)
 {
        int ret;
 
-       ret = stop_machine_create();
-       if (ret)
-               return ret;
        /* No CPUs can come up or down during this. */
        get_online_cpus();
        ret = __stop_machine(fn, data, cpus);
        put_online_cpus();
-       stop_machine_destroy();
        return ret;
 }
 EXPORT_SYMBOL_GPL(stop_machine);
+
+#endif /* CONFIG_STOP_MACHINE */
index 7cb426a..0d36d88 100644 (file)
@@ -492,10 +492,6 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
                return -ENOMEM;
        old = current_cred();
 
-       retval = security_task_setgid(rgid, egid, (gid_t)-1, LSM_SETID_RE);
-       if (retval)
-               goto error;
-
        retval = -EPERM;
        if (rgid != (gid_t) -1) {
                if (old->gid == rgid ||
@@ -543,10 +539,6 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
                return -ENOMEM;
        old = current_cred();
 
-       retval = security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_ID);
-       if (retval)
-               goto error;
-
        retval = -EPERM;
        if (capable(CAP_SETGID))
                new->gid = new->egid = new->sgid = new->fsgid = gid;
@@ -610,10 +602,6 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
                return -ENOMEM;
        old = current_cred();
 
-       retval = security_task_setuid(ruid, euid, (uid_t)-1, LSM_SETID_RE);
-       if (retval)
-               goto error;
-
        retval = -EPERM;
        if (ruid != (uid_t) -1) {
                new->uid = ruid;
@@ -675,10 +663,6 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
                return -ENOMEM;
        old = current_cred();
 
-       retval = security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_ID);
-       if (retval)
-               goto error;
-
        retval = -EPERM;
        if (capable(CAP_SETUID)) {
                new->suid = new->uid = uid;
@@ -719,9 +703,6 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
        if (!new)
                return -ENOMEM;
 
-       retval = security_task_setuid(ruid, euid, suid, LSM_SETID_RES);
-       if (retval)
-               goto error;
        old = current_cred();
 
        retval = -EPERM;
@@ -788,10 +769,6 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
                return -ENOMEM;
        old = current_cred();
 
-       retval = security_task_setgid(rgid, egid, sgid, LSM_SETID_RES);
-       if (retval)
-               goto error;
-
        retval = -EPERM;
        if (!capable(CAP_SETGID)) {
                if (rgid != (gid_t) -1 && rgid != old->gid &&
@@ -851,9 +828,6 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
        old = current_cred();
        old_fsuid = old->fsuid;
 
-       if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS) < 0)
-               goto error;
-
        if (uid == old->uid  || uid == old->euid  ||
            uid == old->suid || uid == old->fsuid ||
            capable(CAP_SETUID)) {
@@ -864,7 +838,6 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
                }
        }
 
-error:
        abort_creds(new);
        return old_fsuid;
 
@@ -888,9 +861,6 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
        old = current_cred();
        old_fsgid = old->fsgid;
 
-       if (security_task_setgid(gid, (gid_t)-1, (gid_t)-1, LSM_SETID_FS))
-               goto error;
-
        if (gid == old->gid  || gid == old->egid  ||
            gid == old->sgid || gid == old->fsgid ||
            capable(CAP_SETGID)) {
@@ -900,7 +870,6 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
                }
        }
 
-error:
        abort_creds(new);
        return old_fsgid;
 
index ce724a0..509e6ba 100644 (file)
@@ -642,7 +642,7 @@ static struct ctl_table kern_table[] = {
 #endif
        {
                .procname       = "userprocess_debug",
-               .data           = &sysctl_userprocess_debug,
+               .data           = &show_unhandled_signals,
                .maxlen         = sizeof(int),
                .mode           = 0644,
                .proc_handler   = proc_dointvec,
@@ -1452,7 +1452,8 @@ static struct ctl_table fs_table[] = {
 };
 
 static struct ctl_table debug_table[] = {
-#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
+#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
+    defined(CONFIG_S390)
        {
                .procname       = "exception-trace",
                .data           = &show_unhandled_signals,
index 656dccf..50612fa 100644 (file)
@@ -132,12 +132,11 @@ SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv,
  */
 static inline void warp_clock(void)
 {
-       write_seqlock_irq(&xtime_lock);
-       wall_to_monotonic.tv_sec -= sys_tz.tz_minuteswest * 60;
-       xtime.tv_sec += sys_tz.tz_minuteswest * 60;
-       update_xtime_cache(0);
-       write_sequnlock_irq(&xtime_lock);
-       clock_was_set();
+       struct timespec delta, adjust;
+       delta.tv_sec = sys_tz.tz_minuteswest * 60;
+       delta.tv_nsec = 0;
+       adjust = timespec_add_safe(current_kernel_time(), delta);
+       do_settimeofday(&adjust);
 }
 
 /*
index 1f5dde6..f08e99c 100644 (file)
@@ -625,6 +625,54 @@ static void clocksource_enqueue(struct clocksource *cs)
        list_add(&cs->list, entry);
 }
 
+
+/*
+ * Maximum time we expect to go between ticks. This includes idle
+ * tickless time. It provides the trade off between selecting a
+ * mult/shift pair that is very precise but can only handle a short
+ * period of time, vs. a mult/shift pair that can handle long periods
+ * of time but isn't as precise.
+ *
+ * This is a subsystem constant, and actual hardware limitations
+ * may override it (ie: clocksources that wrap every 3 seconds).
+ */
+#define MAX_UPDATE_LENGTH 5 /* Seconds */
+
+/**
+ * __clocksource_register_scale - Used to install new clocksources
+ * @t:         clocksource to be registered
+ * @scale:     Scale factor multiplied against freq to get clocksource hz
+ * @freq:      clocksource frequency (cycles per second) divided by scale
+ *
+ * Returns -EBUSY if registration fails, zero otherwise.
+ *
+ * This *SHOULD NOT* be called directly! Please use the
+ * clocksource_register_hz() or clocksource_register_khz helper functions.
+ */
+int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
+{
+
+       /*
+        * Ideally we want to use  some of the limits used in
+        * clocksource_max_deferment, to provide a more informed
+        * MAX_UPDATE_LENGTH. But for now this just gets the
+        * register interface working properly.
+        */
+       clocks_calc_mult_shift(&cs->mult, &cs->shift, freq,
+                                     NSEC_PER_SEC/scale,
+                                     MAX_UPDATE_LENGTH*scale);
+       cs->max_idle_ns = clocksource_max_deferment(cs);
+
+       mutex_lock(&clocksource_mutex);
+       clocksource_enqueue(cs);
+       clocksource_select();
+       clocksource_enqueue_watchdog(cs);
+       mutex_unlock(&clocksource_mutex);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(__clocksource_register_scale);
+
+
 /**
  * clocksource_register - Used to install new clocksources
  * @t:         clocksource to be registered
index 7c0f180..c631168 100644 (file)
@@ -69,7 +69,7 @@ static s64                    time_freq;
 /* time at last adjustment (secs):                                     */
 static long                    time_reftime;
 
-long                           time_adjust;
+static long                    time_adjust;
 
 /* constant (boot-param configurable) NTP tick adjustment (upscaled)   */
 static s64                     ntp_tick_adj;
index f992762..1d7b9bc 100644 (file)
@@ -150,14 +150,32 @@ static void tick_nohz_update_jiffies(ktime_t now)
        touch_softlockup_watchdog();
 }
 
+/*
+ * Updates the per cpu time idle statistics counters
+ */
+static void
+update_ts_time_stats(struct tick_sched *ts, ktime_t now, u64 *last_update_time)
+{
+       ktime_t delta;
+
+       if (ts->idle_active) {
+               delta = ktime_sub(now, ts->idle_entrytime);
+               ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
+               if (nr_iowait_cpu() > 0)
+                       ts->iowait_sleeptime = ktime_add(ts->iowait_sleeptime, delta);
+               ts->idle_entrytime = now;
+       }
+
+       if (last_update_time)
+               *last_update_time = ktime_to_us(now);
+
+}
+
 static void tick_nohz_stop_idle(int cpu, ktime_t now)
 {
        struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
-       ktime_t delta;
 
-       delta = ktime_sub(now, ts->idle_entrytime);
-       ts->idle_lastupdate = now;
-       ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
+       update_ts_time_stats(ts, now, NULL);
        ts->idle_active = 0;
 
        sched_clock_idle_wakeup_event(0);
@@ -165,20 +183,32 @@ static void tick_nohz_stop_idle(int cpu, ktime_t now)
 
 static ktime_t tick_nohz_start_idle(struct tick_sched *ts)
 {
-       ktime_t now, delta;
+       ktime_t now;
 
        now = ktime_get();
-       if (ts->idle_active) {
-               delta = ktime_sub(now, ts->idle_entrytime);
-               ts->idle_lastupdate = now;
-               ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
-       }
+
+       update_ts_time_stats(ts, now, NULL);
+
        ts->idle_entrytime = now;
        ts->idle_active = 1;
        sched_clock_idle_sleep_event();
        return now;
 }
 
+/**
+ * get_cpu_idle_time_us - get the total idle time of a cpu
+ * @cpu: CPU number to query
+ * @last_update_time: variable to store update time in
+ *
+ * Return the cummulative idle time (since boot) for a given
+ * CPU, in microseconds. The idle time returned includes
+ * the iowait time (unlike what "top" and co report).
+ *
+ * This time is measured via accounting rather than sampling,
+ * and is as accurate as ktime_get() is.
+ *
+ * This function returns -1 if NOHZ is not enabled.
+ */
 u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time)
 {
        struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
@@ -186,15 +216,38 @@ u64 get_cpu_idle_time_us(int cpu, u64 *last_update_time)
        if (!tick_nohz_enabled)
                return -1;
 
-       if (ts->idle_active)
-               *last_update_time = ktime_to_us(ts->idle_lastupdate);
-       else
-               *last_update_time = ktime_to_us(ktime_get());
+       update_ts_time_stats(ts, ktime_get(), last_update_time);
 
        return ktime_to_us(ts->idle_sleeptime);
 }
 EXPORT_SYMBOL_GPL(get_cpu_idle_time_us);
 
+/*
+ * get_cpu_iowait_time_us - get the total iowait time of a cpu
+ * @cpu: CPU number to query
+ * @last_update_time: variable to store update time in
+ *
+ * Return the cummulative iowait time (since boot) for a given
+ * CPU, in microseconds.
+ *
+ * This time is measured via accounting rather than sampling,
+ * and is as accurate as ktime_get() is.
+ *
+ * This function returns -1 if NOHZ is not enabled.
+ */
+u64 get_cpu_iowait_time_us(int cpu, u64 *last_update_time)
+{
+       struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
+
+       if (!tick_nohz_enabled)
+               return -1;
+
+       update_ts_time_stats(ts, ktime_get(), last_update_time);
+
+       return ktime_to_us(ts->iowait_sleeptime);
+}
+EXPORT_SYMBOL_GPL(get_cpu_iowait_time_us);
+
 /**
  * tick_nohz_stop_sched_tick - stop the idle tick from the idle task
  *
@@ -262,6 +315,9 @@ void tick_nohz_stop_sched_tick(int inidle)
                goto end;
        }
 
+       if (nohz_ratelimit(cpu))
+               goto end;
+
        ts->idle_calls++;
        /* Read jiffies and the time when jiffies were updated last */
        do {
index 39f6177..caf8d4d 100644 (file)
@@ -165,13 +165,6 @@ struct timespec raw_time;
 /* flag for if timekeeping is suspended */
 int __read_mostly timekeeping_suspended;
 
-static struct timespec xtime_cache __attribute__ ((aligned (16)));
-void update_xtime_cache(u64 nsec)
-{
-       xtime_cache = xtime;
-       timespec_add_ns(&xtime_cache, nsec);
-}
-
 /* must hold xtime_lock */
 void timekeeping_leap_insert(int leapsecond)
 {
@@ -332,8 +325,6 @@ int do_settimeofday(struct timespec *tv)
 
        xtime = *tv;
 
-       update_xtime_cache(0);
-
        timekeeper.ntp_error = 0;
        ntp_clear();
 
@@ -559,7 +550,6 @@ void __init timekeeping_init(void)
        }
        set_normalized_timespec(&wall_to_monotonic,
                                -boot.tv_sec, -boot.tv_nsec);
-       update_xtime_cache(0);
        total_sleep_time.tv_sec = 0;
        total_sleep_time.tv_nsec = 0;
        write_sequnlock_irqrestore(&xtime_lock, flags);
@@ -593,7 +583,6 @@ static int timekeeping_resume(struct sys_device *dev)
                wall_to_monotonic = timespec_sub(wall_to_monotonic, ts);
                total_sleep_time = timespec_add_safe(total_sleep_time, ts);
        }
-       update_xtime_cache(0);
        /* re-base the last cycle value */
        timekeeper.clock->cycle_last = timekeeper.clock->read(timekeeper.clock);
        timekeeper.ntp_error = 0;
@@ -788,7 +777,6 @@ void update_wall_time(void)
 {
        struct clocksource *clock;
        cycle_t offset;
-       u64 nsecs;
        int shift = 0, maxshift;
 
        /* Make sure we're fully resumed: */
@@ -847,7 +835,9 @@ void update_wall_time(void)
                timekeeper.ntp_error += neg << timekeeper.ntp_error_shift;
        }
 
-       /* store full nanoseconds into xtime after rounding it up and
+
+       /*
+        * Store full nanoseconds into xtime after rounding it up and
         * add the remainder to the error difference.
         */
        xtime.tv_nsec = ((s64) timekeeper.xtime_nsec >> timekeeper.shift) + 1;
@@ -855,8 +845,15 @@ void update_wall_time(void)
        timekeeper.ntp_error += timekeeper.xtime_nsec <<
                                timekeeper.ntp_error_shift;
 
-       nsecs = clocksource_cyc2ns(offset, timekeeper.mult, timekeeper.shift);
-       update_xtime_cache(nsecs);
+       /*
+        * Finally, make sure that after the rounding
+        * xtime.tv_nsec isn't larger then NSEC_PER_SEC
+        */
+       if (unlikely(xtime.tv_nsec >= NSEC_PER_SEC)) {
+               xtime.tv_nsec -= NSEC_PER_SEC;
+               xtime.tv_sec++;
+               second_overflow();
+       }
 
        /* check to see if there is a new clocksource to use */
        update_vsyscall(&xtime, timekeeper.clock, timekeeper.mult);
@@ -896,13 +893,13 @@ EXPORT_SYMBOL_GPL(monotonic_to_bootbased);
 
 unsigned long get_seconds(void)
 {
-       return xtime_cache.tv_sec;
+       return xtime.tv_sec;
 }
 EXPORT_SYMBOL(get_seconds);
 
 struct timespec __current_kernel_time(void)
 {
-       return xtime_cache;
+       return xtime;
 }
 
 struct timespec current_kernel_time(void)
@@ -913,7 +910,7 @@ struct timespec current_kernel_time(void)
        do {
                seq = read_seqbegin(&xtime_lock);
 
-               now = xtime_cache;
+               now = xtime;
        } while (read_seqretry(&xtime_lock, seq));
 
        return now;
@@ -928,7 +925,7 @@ struct timespec get_monotonic_coarse(void)
        do {
                seq = read_seqbegin(&xtime_lock);
 
-               now = xtime_cache;
+               now = xtime;
                mono = wall_to_monotonic;
        } while (read_seqretry(&xtime_lock, seq));
 
index 1a4a7dd..ab8f5e3 100644 (file)
@@ -176,6 +176,7 @@ static void print_cpu(struct seq_file *m, int cpu, u64 now)
                P_ns(idle_waketime);
                P_ns(idle_exittime);
                P_ns(idle_sleeptime);
+               P_ns(iowait_sleeptime);
                P(last_jiffies);
                P(next_jiffies);
                P_ns(idle_expires);
index aeb6a54..9199f3c 100644 (file)
@@ -319,6 +319,24 @@ unsigned long round_jiffies_up_relative(unsigned long j)
 }
 EXPORT_SYMBOL_GPL(round_jiffies_up_relative);
 
+/**
+ * set_timer_slack - set the allowed slack for a timer
+ * @slack_hz: the amount of time (in jiffies) allowed for rounding
+ *
+ * Set the amount of time, in jiffies, that a certain timer has
+ * in terms of slack. By setting this value, the timer subsystem
+ * will schedule the actual timer somewhere between
+ * the time mod_timer() asks for, and that time plus the slack.
+ *
+ * By setting the slack to -1, a percentage of the delay is used
+ * instead.
+ */
+void set_timer_slack(struct timer_list *timer, int slack_hz)
+{
+       timer->slack = slack_hz;
+}
+EXPORT_SYMBOL_GPL(set_timer_slack);
+
 
 static inline void set_running_timer(struct tvec_base *base,
                                        struct timer_list *timer)
@@ -550,6 +568,7 @@ static void __init_timer(struct timer_list *timer,
 {
        timer->entry.next = NULL;
        timer->base = __raw_get_cpu_var(tvec_bases);
+       timer->slack = -1;
 #ifdef CONFIG_TIMER_STATS
        timer->start_site = NULL;
        timer->start_pid = -1;
@@ -715,6 +734,41 @@ int mod_timer_pending(struct timer_list *timer, unsigned long expires)
 }
 EXPORT_SYMBOL(mod_timer_pending);
 
+/*
+ * Decide where to put the timer while taking the slack into account
+ *
+ * Algorithm:
+ *   1) calculate the maximum (absolute) time
+ *   2) calculate the highest bit where the expires and new max are different
+ *   3) use this bit to make a mask
+ *   4) use the bitmask to round down the maximum time, so that all last
+ *      bits are zeros
+ */
+static inline
+unsigned long apply_slack(struct timer_list *timer, unsigned long expires)
+{
+       unsigned long expires_limit, mask;
+       int bit;
+
+       expires_limit = expires + timer->slack;
+
+       if (timer->slack < 0) /* auto slack: use 0.4% */
+               expires_limit = expires + (expires - jiffies)/256;
+
+       mask = expires ^ expires_limit;
+
+       if (mask == 0)
+               return expires;
+
+       bit = find_last_bit(&mask, BITS_PER_LONG);
+
+       mask = (1 << bit) - 1;
+
+       expires_limit = expires_limit & ~(mask);
+
+       return expires_limit;
+}
+
 /**
  * mod_timer - modify a timer's timeout
  * @timer: the timer to be modified
@@ -745,6 +799,8 @@ int mod_timer(struct timer_list *timer, unsigned long expires)
        if (timer_pending(timer) && timer->expires == expires)
                return 1;
 
+       expires = apply_slack(timer, expires);
+
        return __mod_timer(timer, expires, false, TIMER_NOT_PINNED);
 }
 EXPORT_SYMBOL(mod_timer);
@@ -955,6 +1011,47 @@ static int cascade(struct tvec_base *base, struct tvec *tv, int index)
        return index;
 }
 
+static void call_timer_fn(struct timer_list *timer, void (*fn)(unsigned long),
+                         unsigned long data)
+{
+       int preempt_count = preempt_count();
+
+#ifdef CONFIG_LOCKDEP
+       /*
+        * It is permissible to free the timer from inside the
+        * function that is called from it, this we need to take into
+        * account for lockdep too. To avoid bogus "held lock freed"
+        * warnings as well as problems when looking into
+        * timer->lockdep_map, make a copy and use that here.
+        */
+       struct lockdep_map lockdep_map = timer->lockdep_map;
+#endif
+       /*
+        * Couple the lock chain with the lock chain at
+        * del_timer_sync() by acquiring the lock_map around the fn()
+        * call here and in del_timer_sync().
+        */
+       lock_map_acquire(&lockdep_map);
+
+       trace_timer_expire_entry(timer);
+       fn(data);
+       trace_timer_expire_exit(timer);
+
+       lock_map_release(&lockdep_map);
+
+       if (preempt_count != preempt_count()) {
+               WARN_ONCE(1, "timer: %pF preempt leak: %08x -> %08x\n",
+                         fn, preempt_count, preempt_count());
+               /*
+                * Restore the preempt count. That gives us a decent
+                * chance to survive and extract information. If the
+                * callback kept a lock held, bad luck, but not worse
+                * than the BUG() we had.
+                */
+               preempt_count() = preempt_count;
+       }
+}
+
 #define INDEX(N) ((base->timer_jiffies >> (TVR_BITS + (N) * TVN_BITS)) & TVN_MASK)
 
 /**
@@ -998,45 +1095,7 @@ static inline void __run_timers(struct tvec_base *base)
                        detach_timer(timer, 1);
 
                        spin_unlock_irq(&base->lock);
-                       {
-                               int preempt_count = preempt_count();
-
-#ifdef CONFIG_LOCKDEP
-                               /*
-                                * It is permissible to free the timer from
-                                * inside the function that is called from
-                                * it, this we need to take into account for
-                                * lockdep too. To avoid bogus "held lock
-                                * freed" warnings as well as problems when
-                                * looking into timer->lockdep_map, make a
-                                * copy and use that here.
-                                */
-                               struct lockdep_map lockdep_map =
-                                       timer->lockdep_map;
-#endif
-                               /*
-                                * Couple the lock chain with the lock chain at
-                                * del_timer_sync() by acquiring the lock_map
-                                * around the fn() call here and in
-                                * del_timer_sync().
-                                */
-                               lock_map_acquire(&lockdep_map);
-
-                               trace_timer_expire_entry(timer);
-                               fn(data);
-                               trace_timer_expire_exit(timer);
-
-                               lock_map_release(&lockdep_map);
-
-                               if (preempt_count != preempt_count()) {
-                                       printk(KERN_ERR "huh, entered %p "
-                                              "with preempt_count %08x, exited"
-                                              " with %08x?\n",
-                                              fn, preempt_count,
-                                              preempt_count());
-                                       BUG();
-                               }
-                       }
+                       call_timer_fn(timer, fn, data);
                        spin_lock_irq(&base->lock);
                }
        }
index 13e13d4..8b1797c 100644 (file)
@@ -44,9 +44,6 @@ config HAVE_FTRACE_MCOUNT_RECORD
        help
          See Documentation/trace/ftrace-design.txt
 
-config HAVE_HW_BRANCH_TRACER
-       bool
-
 config HAVE_SYSCALL_TRACEPOINTS
        bool
        help
@@ -374,14 +371,6 @@ config STACK_TRACER
 
          Say N if unsure.
 
-config HW_BRANCH_TRACER
-       depends on HAVE_HW_BRANCH_TRACER
-       bool "Trace hw branches"
-       select GENERIC_TRACER
-       help
-         This tracer records all branches on the system in a circular
-         buffer, giving access to the last N branches for each cpu.
-
 config KMEMTRACE
        bool "Trace SLAB allocations"
        select GENERIC_TRACER
index 78edc64..ffb1a5b 100644 (file)
@@ -41,7 +41,6 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
 obj-$(CONFIG_BOOT_TRACER) += trace_boot.o
 obj-$(CONFIG_FUNCTION_GRAPH_TRACER) += trace_functions_graph.o
 obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o
-obj-$(CONFIG_HW_BRANCH_TRACER) += trace_hw_branches.o
 obj-$(CONFIG_KMEMTRACE) += kmemtrace.o
 obj-$(CONFIG_WORKQUEUE_TRACER) += trace_workqueue.o
 obj-$(CONFIG_BLK_DEV_IO_TRACE) += blktrace.o
index 2404b59..32837e1 100644 (file)
@@ -264,6 +264,7 @@ struct ftrace_profile {
        unsigned long                   counter;
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
        unsigned long long              time;
+       unsigned long long              time_squared;
 #endif
 };
 
@@ -366,9 +367,9 @@ static int function_stat_headers(struct seq_file *m)
 {
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
        seq_printf(m, "  Function                               "
-                  "Hit    Time            Avg\n"
+                  "Hit    Time            Avg             s^2\n"
                      "  --------                               "
-                  "---    ----            ---\n");
+                  "---    ----            ---             ---\n");
 #else
        seq_printf(m, "  Function                               Hit\n"
                      "  --------                               ---\n");
@@ -384,6 +385,7 @@ static int function_stat_show(struct seq_file *m, void *v)
        static DEFINE_MUTEX(mutex);
        static struct trace_seq s;
        unsigned long long avg;
+       unsigned long long stddev;
 #endif
 
        kallsyms_lookup(rec->ip, NULL, NULL, NULL, str);
@@ -394,11 +396,25 @@ static int function_stat_show(struct seq_file *m, void *v)
        avg = rec->time;
        do_div(avg, rec->counter);
 
+       /* Sample standard deviation (s^2) */
+       if (rec->counter <= 1)
+               stddev = 0;
+       else {
+               stddev = rec->time_squared - rec->counter * avg * avg;
+               /*
+                * Divide only 1000 for ns^2 -> us^2 conversion.
+                * trace_print_graph_duration will divide 1000 again.
+                */
+               do_div(stddev, (rec->counter - 1) * 1000);
+       }
+
        mutex_lock(&mutex);
        trace_seq_init(&s);
        trace_print_graph_duration(rec->time, &s);
        trace_seq_puts(&s, "    ");
        trace_print_graph_duration(avg, &s);
+       trace_seq_puts(&s, "    ");
+       trace_print_graph_duration(stddev, &s);
        trace_print_seq(m, &s);
        mutex_unlock(&mutex);
 #endif
@@ -650,6 +666,10 @@ static void profile_graph_return(struct ftrace_graph_ret *trace)
        if (!stat->hash || !ftrace_profile_enabled)
                goto out;
 
+       /* If the calltime was zero'd ignore it */
+       if (!trace->calltime)
+               goto out;
+
        calltime = trace->rettime - trace->calltime;
 
        if (!(trace_flags & TRACE_ITER_GRAPH_TIME)) {
@@ -668,8 +688,10 @@ static void profile_graph_return(struct ftrace_graph_ret *trace)
        }
 
        rec = ftrace_find_profiled_func(stat, trace->func);
-       if (rec)
+       if (rec) {
                rec->time += calltime;
+               rec->time_squared += calltime * calltime;
+       }
 
  out:
        local_irq_restore(flags);
@@ -3212,8 +3234,7 @@ free:
 }
 
 static void
-ftrace_graph_probe_sched_switch(struct rq *__rq, struct task_struct *prev,
-                               struct task_struct *next)
+ftrace_graph_probe_sched_switch(struct task_struct *prev, struct task_struct *next)
 {
        unsigned long long timestamp;
        int index;
@@ -3339,11 +3360,11 @@ void unregister_ftrace_graph(void)
                goto out;
 
        ftrace_graph_active--;
-       unregister_trace_sched_switch(ftrace_graph_probe_sched_switch);
        ftrace_graph_return = (trace_func_graph_ret_t)ftrace_stub;
        ftrace_graph_entry = ftrace_graph_entry_stub;
        ftrace_shutdown(FTRACE_STOP_FUNC_RET);
        unregister_pm_notifier(&ftrace_suspend_notifier);
+       unregister_trace_sched_switch(ftrace_graph_probe_sched_switch);
 
  out:
        mutex_unlock(&ftrace_lock);
index 41ca394..7f6059c 100644 (file)
@@ -319,6 +319,11 @@ EXPORT_SYMBOL_GPL(ring_buffer_event_data);
 #define TS_MASK                ((1ULL << TS_SHIFT) - 1)
 #define TS_DELTA_TEST  (~TS_MASK)
 
+/* Flag when events were overwritten */
+#define RB_MISSED_EVENTS       (1 << 31)
+/* Missed count stored at end */
+#define RB_MISSED_STORED       (1 << 30)
+
 struct buffer_data_page {
        u64              time_stamp;    /* page time stamp */
        local_t          commit;        /* write committed index */
@@ -338,6 +343,7 @@ struct buffer_page {
        local_t          write;         /* index for next write */
        unsigned         read;          /* index for next read */
        local_t          entries;       /* entries on this page */
+       unsigned long    real_end;      /* real end of data */
        struct buffer_data_page *page;  /* Actual data page */
 };
 
@@ -417,6 +423,12 @@ int ring_buffer_print_page_header(struct trace_seq *s)
                               (unsigned int)sizeof(field.commit),
                               (unsigned int)is_signed_type(long));
 
+       ret = trace_seq_printf(s, "\tfield: int overwrite;\t"
+                              "offset:%u;\tsize:%u;\tsigned:%u;\n",
+                              (unsigned int)offsetof(typeof(field), commit),
+                              1,
+                              (unsigned int)is_signed_type(long));
+
        ret = trace_seq_printf(s, "\tfield: char data;\t"
                               "offset:%u;\tsize:%u;\tsigned:%u;\n",
                               (unsigned int)offsetof(typeof(field), data),
@@ -440,6 +452,8 @@ struct ring_buffer_per_cpu {
        struct buffer_page              *tail_page;     /* write to tail */
        struct buffer_page              *commit_page;   /* committed pages */
        struct buffer_page              *reader_page;
+       unsigned long                   lost_events;
+       unsigned long                   last_overrun;
        local_t                         commit_overrun;
        local_t                         overrun;
        local_t                         entries;
@@ -1761,6 +1775,13 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
        event = __rb_page_index(tail_page, tail);
        kmemcheck_annotate_bitfield(event, bitfield);
 
+       /*
+        * Save the original length to the meta data.
+        * This will be used by the reader to add lost event
+        * counter.
+        */
+       tail_page->real_end = tail;
+
        /*
         * If this event is bigger than the minimum size, then
         * we need to be careful that we don't subtract the
@@ -1979,17 +2000,13 @@ rb_add_time_stamp(struct ring_buffer_per_cpu *cpu_buffer,
                  u64 *ts, u64 *delta)
 {
        struct ring_buffer_event *event;
-       static int once;
        int ret;
 
-       if (unlikely(*delta > (1ULL << 59) && !once++)) {
-               printk(KERN_WARNING "Delta way too big! %llu"
-                      " ts=%llu write stamp = %llu\n",
-                      (unsigned long long)*delta,
-                      (unsigned long long)*ts,
-                      (unsigned long long)cpu_buffer->write_stamp);
-               WARN_ON(1);
-       }
+       WARN_ONCE(*delta > (1ULL << 59),
+                 KERN_WARNING "Delta way too big! %llu ts=%llu write stamp = %llu\n",
+                 (unsigned long long)*delta,
+                 (unsigned long long)*ts,
+                 (unsigned long long)cpu_buffer->write_stamp);
 
        /*
         * The delta is too big, we to add a
@@ -2838,6 +2855,7 @@ static struct buffer_page *
 rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
 {
        struct buffer_page *reader = NULL;
+       unsigned long overwrite;
        unsigned long flags;
        int nr_loops = 0;
        int ret;
@@ -2879,6 +2897,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
        local_set(&cpu_buffer->reader_page->write, 0);
        local_set(&cpu_buffer->reader_page->entries, 0);
        local_set(&cpu_buffer->reader_page->page->commit, 0);
+       cpu_buffer->reader_page->real_end = 0;
 
  spin:
        /*
@@ -2898,6 +2917,18 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
        /* The reader page will be pointing to the new head */
        rb_set_list_to_head(cpu_buffer, &cpu_buffer->reader_page->list);
 
+       /*
+        * We want to make sure we read the overruns after we set up our
+        * pointers to the next object. The writer side does a
+        * cmpxchg to cross pages which acts as the mb on the writer
+        * side. Note, the reader will constantly fail the swap
+        * while the writer is updating the pointers, so this
+        * guarantees that the overwrite recorded here is the one we
+        * want to compare with the last_overrun.
+        */
+       smp_mb();
+       overwrite = local_read(&(cpu_buffer->overrun));
+
        /*
         * Here's the tricky part.
         *
@@ -2929,6 +2960,11 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
        cpu_buffer->reader_page = reader;
        rb_reset_reader_page(cpu_buffer);
 
+       if (overwrite != cpu_buffer->last_overrun) {
+               cpu_buffer->lost_events = overwrite - cpu_buffer->last_overrun;
+               cpu_buffer->last_overrun = overwrite;
+       }
+
        goto again;
 
  out:
@@ -3005,8 +3041,14 @@ static void rb_advance_iter(struct ring_buffer_iter *iter)
                rb_advance_iter(iter);
 }
 
+static int rb_lost_events(struct ring_buffer_per_cpu *cpu_buffer)
+{
+       return cpu_buffer->lost_events;
+}
+
 static struct ring_buffer_event *
-rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts)
+rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts,
+              unsigned long *lost_events)
 {
        struct ring_buffer_event *event;
        struct buffer_page *reader;
@@ -3058,6 +3100,8 @@ rb_buffer_peek(struct ring_buffer_per_cpu *cpu_buffer, u64 *ts)
                        ring_buffer_normalize_time_stamp(cpu_buffer->buffer,
                                                         cpu_buffer->cpu, ts);
                }
+               if (lost_events)
+                       *lost_events = rb_lost_events(cpu_buffer);
                return event;
 
        default:
@@ -3168,12 +3212,14 @@ static inline int rb_ok_to_lock(void)
  * @buffer: The ring buffer to read
  * @cpu: The cpu to peak at
  * @ts: The timestamp counter of this event.
+ * @lost_events: a variable to store if events were lost (may be NULL)
  *
  * This will return the event that will be read next, but does
  * not consume the data.
  */
 struct ring_buffer_event *
-ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
+ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts,
+                unsigned long *lost_events)
 {
        struct ring_buffer_per_cpu *cpu_buffer = buffer->buffers[cpu];
        struct ring_buffer_event *event;
@@ -3188,7 +3234,7 @@ ring_buffer_peek(struct ring_buffer *buffer, int cpu, u64 *ts)
        local_irq_save(flags);
        if (dolock)
                spin_lock(&cpu_buffer->reader_lock);
-       event = rb_buffer_peek(cpu_buffer, ts);
+       event = rb_buffer_peek(cpu_buffer, ts, lost_events);
        if (event && event->type_len == RINGBUF_TYPE_PADDING)
                rb_advance_reader(cpu_buffer);
        if (dolock)
@@ -3230,13 +3276,17 @@ ring_buffer_iter_peek(struct ring_buffer_iter *iter, u64 *ts)
 /**
  * ring_buffer_consume - return an event and consume it
  * @buffer: The ring buffer to get the next event from
+ * @cpu: the cpu to read the buffer from
+ * @ts: a variable to store the timestamp (may be NULL)
+ * @lost_events: a variable to store if events were lost (may be NULL)
  *
  * Returns the next event in the ring buffer, and that event is consumed.
  * Meaning, that sequential reads will keep returning a different event,
  * and eventually empty the ring buffer if the producer is slower.
  */
 struct ring_buffer_event *
-ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
+ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts,
+                   unsigned long *lost_events)
 {
        struct ring_buffer_per_cpu *cpu_buffer;
        struct ring_buffer_event *event = NULL;
@@ -3257,9 +3307,11 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
        if (dolock)
                spin_lock(&cpu_buffer->reader_lock);
 
-       event = rb_buffer_peek(cpu_buffer, ts);
-       if (event)
+       event = rb_buffer_peek(cpu_buffer, ts, lost_events);
+       if (event) {
+               cpu_buffer->lost_events = 0;
                rb_advance_reader(cpu_buffer);
+       }
 
        if (dolock)
                spin_unlock(&cpu_buffer->reader_lock);
@@ -3276,23 +3328,30 @@ ring_buffer_consume(struct ring_buffer *buffer, int cpu, u64 *ts)
 EXPORT_SYMBOL_GPL(ring_buffer_consume);
 
 /**
- * ring_buffer_read_start - start a non consuming read of the buffer
+ * ring_buffer_read_prepare - Prepare for a non consuming read of the buffer
  * @buffer: The ring buffer to read from
  * @cpu: The cpu buffer to iterate over
  *
- * This starts up an iteration through the buffer. It also disables
- * the recording to the buffer until the reading is finished.
- * This prevents the reading from being corrupted. This is not
- * a consuming read, so a producer is not expected.
+ * This performs the initial preparations necessary to iterate
+ * through the buffer.  Memory is allocated, buffer recording
+ * is disabled, and the iterator pointer is returned to the caller.
  *
- * Must be paired with ring_buffer_finish.
+ * Disabling buffer recordng prevents the reading from being
+ * corrupted. This is not a consuming read, so a producer is not
+ * expected.
+ *
+ * After a sequence of ring_buffer_read_prepare calls, the user is
+ * expected to make at least one call to ring_buffer_prepare_sync.
+ * Afterwards, ring_buffer_read_start is invoked to get things going
+ * for real.
+ *
+ * This overall must be paired with ring_buffer_finish.
  */
 struct ring_buffer_iter *
-ring_buffer_read_start(struct ring_buffer *buffer, int cpu)
+ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu)
 {
        struct ring_buffer_per_cpu *cpu_buffer;
        struct ring_buffer_iter *iter;
-       unsigned long flags;
 
        if (!cpumask_test_cpu(cpu, buffer->cpumask))
                return NULL;
@@ -3306,15 +3365,52 @@ ring_buffer_read_start(struct ring_buffer *buffer, int cpu)
        iter->cpu_buffer = cpu_buffer;
 
        atomic_inc(&cpu_buffer->record_disabled);
+
+       return iter;
+}
+EXPORT_SYMBOL_GPL(ring_buffer_read_prepare);
+
+/**
+ * ring_buffer_read_prepare_sync - Synchronize a set of prepare calls
+ *
+ * All previously invoked ring_buffer_read_prepare calls to prepare
+ * iterators will be synchronized.  Afterwards, read_buffer_read_start
+ * calls on those iterators are allowed.
+ */
+void
+ring_buffer_read_prepare_sync(void)
+{
        synchronize_sched();
+}
+EXPORT_SYMBOL_GPL(ring_buffer_read_prepare_sync);
+
+/**
+ * ring_buffer_read_start - start a non consuming read of the buffer
+ * @iter: The iterator returned by ring_buffer_read_prepare
+ *
+ * This finalizes the startup of an iteration through the buffer.
+ * The iterator comes from a call to ring_buffer_read_prepare and
+ * an intervening ring_buffer_read_prepare_sync must have been
+ * performed.
+ *
+ * Must be paired with ring_buffer_finish.
+ */
+void
+ring_buffer_read_start(struct ring_buffer_iter *iter)
+{
+       struct ring_buffer_per_cpu *cpu_buffer;
+       unsigned long flags;
+
+       if (!iter)
+               return;
+
+       cpu_buffer = iter->cpu_buffer;
 
        spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
        arch_spin_lock(&cpu_buffer->lock);
        rb_iter_reset(iter);
        arch_spin_unlock(&cpu_buffer->lock);
        spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
-
-       return iter;
 }
 EXPORT_SYMBOL_GPL(ring_buffer_read_start);
 
@@ -3408,6 +3504,9 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
        cpu_buffer->write_stamp = 0;
        cpu_buffer->read_stamp = 0;
 
+       cpu_buffer->lost_events = 0;
+       cpu_buffer->last_overrun = 0;
+
        rb_head_page_activate(cpu_buffer);
 }
 
@@ -3683,6 +3782,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
        struct ring_buffer_event *event;
        struct buffer_data_page *bpage;
        struct buffer_page *reader;
+       unsigned long missed_events;
        unsigned long flags;
        unsigned int commit;
        unsigned int read;
@@ -3719,6 +3819,9 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
        read = reader->read;
        commit = rb_page_commit(reader);
 
+       /* Check if any events were dropped */
+       missed_events = cpu_buffer->lost_events;
+
        /*
         * If this page has been partially read or
         * if len is not big enough to read the rest of the page or
@@ -3779,9 +3882,35 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
                local_set(&reader->entries, 0);
                reader->read = 0;
                *data_page = bpage;
+
+               /*
+                * Use the real_end for the data size,
+                * This gives us a chance to store the lost events
+                * on the page.
+                */
+               if (reader->real_end)
+                       local_set(&bpage->commit, reader->real_end);
        }
        ret = read;
 
+       cpu_buffer->lost_events = 0;
+       /*
+        * Set a flag in the commit field if we lost events
+        */
+       if (missed_events) {
+               commit = local_read(&bpage->commit);
+
+               /* If there is room at the end of the page to save the
+                * missed events, then record it there.
+                */
+               if (BUF_PAGE_SIZE - commit >= sizeof(missed_events)) {
+                       memcpy(&bpage->data[commit], &missed_events,
+                              sizeof(missed_events));
+                       local_add(RB_MISSED_STORED, &bpage->commit);
+               }
+               local_add(RB_MISSED_EVENTS, &bpage->commit);
+       }
+
  out_unlock:
        spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
 
index df74c79..302f8a6 100644 (file)
@@ -81,7 +81,7 @@ static enum event_status read_event(int cpu)
        int *entry;
        u64 ts;
 
-       event = ring_buffer_consume(buffer, cpu, &ts);
+       event = ring_buffer_consume(buffer, cpu, &ts, NULL);
        if (!event)
                return EVENT_DROPPED;
 
@@ -113,7 +113,8 @@ static enum event_status read_page(int cpu)
        ret = ring_buffer_read_page(buffer, &bpage, PAGE_SIZE, cpu, 1);
        if (ret >= 0) {
                rpage = bpage;
-               commit = local_read(&rpage->commit);
+               /* The commit may have missed event flags set, clear them */
+               commit = local_read(&rpage->commit) & 0xfffff;
                for (i = 0; i < commit && !kill_test; i += inc) {
 
                        if (i >= (PAGE_SIZE - offsetof(struct rb_page, data))) {
index 44f916a..756d728 100644 (file)
@@ -117,9 +117,12 @@ static cpumask_var_t __read_mostly tracing_buffer_mask;
  *
  * It is default off, but you can enable it with either specifying
  * "ftrace_dump_on_oops" in the kernel command line, or setting
- * /proc/sys/kernel/ftrace_dump_on_oops to true.
+ * /proc/sys/kernel/ftrace_dump_on_oops
+ * Set 1 if you want to dump buffers of all CPUs
+ * Set 2 if you want to dump the buffer of the CPU that triggered oops
  */
-int ftrace_dump_on_oops;
+
+enum ftrace_dump_mode ftrace_dump_on_oops;
 
 static int tracing_set_tracer(const char *buf);
 
@@ -139,8 +142,17 @@ __setup("ftrace=", set_cmdline_ftrace);
 
 static int __init set_ftrace_dump_on_oops(char *str)
 {
-       ftrace_dump_on_oops = 1;
-       return 1;
+       if (*str++ != '=' || !*str) {
+               ftrace_dump_on_oops = DUMP_ALL;
+               return 1;
+       }
+
+       if (!strcmp("orig_cpu", str)) {
+               ftrace_dump_on_oops = DUMP_ORIG;
+                return 1;
+        }
+
+        return 0;
 }
 __setup("ftrace_dump_on_oops", set_ftrace_dump_on_oops);
 
@@ -1545,7 +1557,8 @@ static void trace_iterator_increment(struct trace_iterator *iter)
 }
 
 static struct trace_entry *
-peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
+peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts,
+               unsigned long *lost_events)
 {
        struct ring_buffer_event *event;
        struct ring_buffer_iter *buf_iter = iter->buffer_iter[cpu];
@@ -1556,7 +1569,8 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
        if (buf_iter)
                event = ring_buffer_iter_peek(buf_iter, ts);
        else
-               event = ring_buffer_peek(iter->tr->buffer, cpu, ts);
+               event = ring_buffer_peek(iter->tr->buffer, cpu, ts,
+                                        lost_events);
 
        ftrace_enable_cpu();
 
@@ -1564,10 +1578,12 @@ peek_next_entry(struct trace_iterator *iter, int cpu, u64 *ts)
 }
 
 static struct trace_entry *
-__find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
+__find_next_entry(struct trace_iterator *iter, int *ent_cpu,
+                 unsigned long *missing_events, u64 *ent_ts)
 {
        struct ring_buffer *buffer = iter->tr->buffer;
        struct trace_entry *ent, *next = NULL;
+       unsigned long lost_events = 0, next_lost = 0;
        int cpu_file = iter->cpu_file;
        u64 next_ts = 0, ts;
        int next_cpu = -1;
@@ -1580,7 +1596,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
        if (cpu_file > TRACE_PIPE_ALL_CPU) {
                if (ring_buffer_empty_cpu(buffer, cpu_file))
                        return NULL;
-               ent = peek_next_entry(iter, cpu_file, ent_ts);
+               ent = peek_next_entry(iter, cpu_file, ent_ts, missing_events);
                if (ent_cpu)
                        *ent_cpu = cpu_file;
 
@@ -1592,7 +1608,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
                if (ring_buffer_empty_cpu(buffer, cpu))
                        continue;
 
-               ent = peek_next_entry(iter, cpu, &ts);
+               ent = peek_next_entry(iter, cpu, &ts, &lost_events);
 
                /*
                 * Pick the entry with the smallest timestamp:
@@ -1601,6 +1617,7 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
                        next = ent;
                        next_cpu = cpu;
                        next_ts = ts;
+                       next_lost = lost_events;
                }
        }
 
@@ -1610,6 +1627,9 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
        if (ent_ts)
                *ent_ts = next_ts;
 
+       if (missing_events)
+               *missing_events = next_lost;
+
        return next;
 }
 
@@ -1617,13 +1637,14 @@ __find_next_entry(struct trace_iterator *iter, int *ent_cpu, u64 *ent_ts)
 struct trace_entry *trace_find_next_entry(struct trace_iterator *iter,
                                          int *ent_cpu, u64 *ent_ts)
 {
-       return __find_next_entry(iter, ent_cpu, ent_ts);
+       return __find_next_entry(iter, ent_cpu, NULL, ent_ts);
 }
 
 /* Find the next real entry, and increment the iterator to the next entry */
 static void *find_next_entry_inc(struct trace_iterator *iter)
 {
-       iter->ent = __find_next_entry(iter, &iter->cpu, &iter->ts);
+       iter->ent = __find_next_entry(iter, &iter->cpu,
+                                     &iter->lost_events, &iter->ts);
 
        if (iter->ent)
                trace_iterator_increment(iter);
@@ -1635,7 +1656,8 @@ static void trace_consume(struct trace_iterator *iter)
 {
        /* Don't allow ftrace to trace into the ring buffers */
        ftrace_disable_cpu();
-       ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts);
+       ring_buffer_consume(iter->tr->buffer, iter->cpu, &iter->ts,
+                           &iter->lost_events);
        ftrace_enable_cpu();
 }
 
@@ -1786,7 +1808,7 @@ static void print_func_help_header(struct seq_file *m)
 }
 
 
-static void
+void
 print_trace_header(struct seq_file *m, struct trace_iterator *iter)
 {
        unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
@@ -1995,7 +2017,7 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
        return event ? event->binary(iter, 0) : TRACE_TYPE_HANDLED;
 }
 
-static int trace_empty(struct trace_iterator *iter)
+int trace_empty(struct trace_iterator *iter)
 {
        int cpu;
 
@@ -2030,6 +2052,10 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)
 {
        enum print_line_t ret;
 
+       if (iter->lost_events)
+               trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
+                                iter->cpu, iter->lost_events);
+
        if (iter->trace && iter->trace->print_line) {
                ret = iter->trace->print_line(iter);
                if (ret != TRACE_TYPE_UNHANDLED)
@@ -2058,6 +2084,23 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)
        return print_trace_fmt(iter);
 }
 
+void trace_default_header(struct seq_file *m)
+{
+       struct trace_iterator *iter = m->private;
+
+       if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
+               /* print nothing if the buffers are empty */
+               if (trace_empty(iter))
+                       return;
+               print_trace_header(m, iter);
+               if (!(trace_flags & TRACE_ITER_VERBOSE))
+                       print_lat_help_header(m);
+       } else {
+               if (!(trace_flags & TRACE_ITER_VERBOSE))
+                       print_func_help_header(m);
+       }
+}
+
 static int s_show(struct seq_file *m, void *v)
 {
        struct trace_iterator *iter = v;
@@ -2070,17 +2113,9 @@ static int s_show(struct seq_file *m, void *v)
                }
                if (iter->trace && iter->trace->print_header)
                        iter->trace->print_header(m);
-               else if (iter->iter_flags & TRACE_FILE_LAT_FMT) {
-                       /* print nothing if the buffers are empty */
-                       if (trace_empty(iter))
-                               return 0;
-                       print_trace_header(m, iter);
-                       if (!(trace_flags & TRACE_ITER_VERBOSE))
-                               print_lat_help_header(m);
-               } else {
-                       if (!(trace_flags & TRACE_ITER_VERBOSE))
-                               print_func_help_header(m);
-               }
+               else
+                       trace_default_header(m);
+
        } else if (iter->leftover) {
                /*
                 * If we filled the seq_file buffer earlier, we
@@ -2166,15 +2201,20 @@ __tracing_open(struct inode *inode, struct file *file)
 
        if (iter->cpu_file == TRACE_PIPE_ALL_CPU) {
                for_each_tracing_cpu(cpu) {
-
                        iter->buffer_iter[cpu] =
-                               ring_buffer_read_start(iter->tr->buffer, cpu);
+                               ring_buffer_read_prepare(iter->tr->buffer, cpu);
+               }
+               ring_buffer_read_prepare_sync();
+               for_each_tracing_cpu(cpu) {
+                       ring_buffer_read_start(iter->buffer_iter[cpu]);
                        tracing_iter_reset(iter, cpu);
                }
        } else {
                cpu = iter->cpu_file;
                iter->buffer_iter[cpu] =
-                               ring_buffer_read_start(iter->tr->buffer, cpu);
+                       ring_buffer_read_prepare(iter->tr->buffer, cpu);
+               ring_buffer_read_prepare_sync();
+               ring_buffer_read_start(iter->buffer_iter[cpu]);
                tracing_iter_reset(iter, cpu);
        }
 
@@ -4324,7 +4364,7 @@ static int trace_panic_handler(struct notifier_block *this,
                               unsigned long event, void *unused)
 {
        if (ftrace_dump_on_oops)
-               ftrace_dump();
+               ftrace_dump(ftrace_dump_on_oops);
        return NOTIFY_OK;
 }
 
@@ -4341,7 +4381,7 @@ static int trace_die_handler(struct notifier_block *self,
        switch (val) {
        case DIE_OOPS:
                if (ftrace_dump_on_oops)
-                       ftrace_dump();
+                       ftrace_dump(ftrace_dump_on_oops);
                break;
        default:
                break;
@@ -4382,7 +4422,8 @@ trace_printk_seq(struct trace_seq *s)
        trace_seq_init(s);
 }
 
-static void __ftrace_dump(bool disable_tracing)
+static void
+__ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode)
 {
        static arch_spinlock_t ftrace_dump_lock =
                (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
@@ -4415,12 +4456,25 @@ static void __ftrace_dump(bool disable_tracing)
        /* don't look at user memory in panic mode */
        trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
 
-       printk(KERN_TRACE "Dumping ftrace buffer:\n");
-
        /* Simulate the iterator */
        iter.tr = &global_trace;
        iter.trace = current_trace;
-       iter.cpu_file = TRACE_PIPE_ALL_CPU;
+
+       switch (oops_dump_mode) {
+       case DUMP_ALL:
+               iter.cpu_file = TRACE_PIPE_ALL_CPU;
+               break;
+       case DUMP_ORIG:
+               iter.cpu_file = raw_smp_processor_id();
+               break;
+       case DUMP_NONE:
+               goto out_enable;
+       default:
+               printk(KERN_TRACE "Bad dumping mode, switching to all CPUs dump\n");
+               iter.cpu_file = TRACE_PIPE_ALL_CPU;
+       }
+
+       printk(KERN_TRACE "Dumping ftrace buffer:\n");
 
        /*
         * We need to stop all tracing on all CPUS to read the
@@ -4459,6 +4513,7 @@ static void __ftrace_dump(bool disable_tracing)
        else
                printk(KERN_TRACE "---------------------------------\n");
 
+ out_enable:
        /* Re-enable tracing if requested */
        if (!disable_tracing) {
                trace_flags |= old_userobj;
@@ -4475,9 +4530,9 @@ static void __ftrace_dump(bool disable_tracing)
 }
 
 /* By default: disable tracing after the dump */
-void ftrace_dump(void)
+void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
 {
-       __ftrace_dump(true);
+       __ftrace_dump(true, oops_dump_mode);
 }
 
 __init static int tracer_alloc_buffers(void)
index 2825ef2..d1ce0be 100644 (file)
@@ -34,7 +34,6 @@ enum trace_type {
        TRACE_GRAPH_RET,
        TRACE_GRAPH_ENT,
        TRACE_USER_STACK,
-       TRACE_HW_BRANCHES,
        TRACE_KMEM_ALLOC,
        TRACE_KMEM_FREE,
        TRACE_BLK,
@@ -103,29 +102,17 @@ struct syscall_trace_exit {
        long                    ret;
 };
 
-struct kprobe_trace_entry {
+struct kprobe_trace_entry_head {
        struct trace_entry      ent;
        unsigned long           ip;
-       int                     nargs;
-       unsigned long           args[];
 };
 
-#define SIZEOF_KPROBE_TRACE_ENTRY(n)                   \
-       (offsetof(struct kprobe_trace_entry, args) +    \
-       (sizeof(unsigned long) * (n)))
-
-struct kretprobe_trace_entry {
+struct kretprobe_trace_entry_head {
        struct trace_entry      ent;
        unsigned long           func;
        unsigned long           ret_ip;
-       int                     nargs;
-       unsigned long           args[];
 };
 
-#define SIZEOF_KRETPROBE_TRACE_ENTRY(n)                        \
-       (offsetof(struct kretprobe_trace_entry, args) + \
-       (sizeof(unsigned long) * (n)))
-
 /*
  * trace_flag_type is an enumeration that holds different
  * states when a trace occurs. These are:
@@ -229,7 +216,6 @@ extern void __ftrace_bad_type(void);
                          TRACE_GRAPH_ENT);             \
                IF_ASSIGN(var, ent, struct ftrace_graph_ret_entry,      \
                          TRACE_GRAPH_RET);             \
-               IF_ASSIGN(var, ent, struct hw_branch_entry, TRACE_HW_BRANCHES);\
                IF_ASSIGN(var, ent, struct kmemtrace_alloc_entry,       \
                          TRACE_KMEM_ALLOC);    \
                IF_ASSIGN(var, ent, struct kmemtrace_free_entry,        \
@@ -378,6 +364,9 @@ void trace_function(struct trace_array *tr,
                    unsigned long ip,
                    unsigned long parent_ip,
                    unsigned long flags, int pc);
+void trace_default_header(struct seq_file *m);
+void print_trace_header(struct seq_file *m, struct trace_iterator *iter);
+int trace_empty(struct trace_iterator *iter);
 
 void trace_graph_return(struct ftrace_graph_ret *trace);
 int trace_graph_entry(struct ftrace_graph_ent *trace);
@@ -467,8 +456,6 @@ extern int trace_selftest_startup_sysprof(struct tracer *trace,
                                               struct trace_array *tr);
 extern int trace_selftest_startup_branch(struct tracer *trace,
                                         struct trace_array *tr);
-extern int trace_selftest_startup_hw_branches(struct tracer *trace,
-                                             struct trace_array *tr);
 extern int trace_selftest_startup_ksym(struct tracer *trace,
                                         struct trace_array *tr);
 #endif /* CONFIG_FTRACE_STARTUP_TEST */
@@ -491,9 +478,29 @@ extern int trace_clock_id;
 
 /* Standard output formatting function used for function return traces */
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-extern enum print_line_t print_graph_function(struct trace_iterator *iter);
+
+/* Flag options */
+#define TRACE_GRAPH_PRINT_OVERRUN       0x1
+#define TRACE_GRAPH_PRINT_CPU           0x2
+#define TRACE_GRAPH_PRINT_OVERHEAD      0x4
+#define TRACE_GRAPH_PRINT_PROC          0x8
+#define TRACE_GRAPH_PRINT_DURATION      0x10
+#define TRACE_GRAPH_PRINT_ABS_TIME      0x20
+
+extern enum print_line_t
+print_graph_function_flags(struct trace_iterator *iter, u32 flags);
+extern void print_graph_headers_flags(struct seq_file *s, u32 flags);
 extern enum print_line_t
 trace_print_graph_duration(unsigned long long duration, struct trace_seq *s);
+extern void graph_trace_open(struct trace_iterator *iter);
+extern void graph_trace_close(struct trace_iterator *iter);
+extern int __trace_graph_entry(struct trace_array *tr,
+                              struct ftrace_graph_ent *trace,
+                              unsigned long flags, int pc);
+extern void __trace_graph_return(struct trace_array *tr,
+                                struct ftrace_graph_ret *trace,
+                                unsigned long flags, int pc);
+
 
 #ifdef CONFIG_DYNAMIC_FTRACE
 /* TODO: make this variable */
@@ -524,7 +531,7 @@ static inline int ftrace_graph_addr(unsigned long addr)
 #endif /* CONFIG_DYNAMIC_FTRACE */
 #else /* CONFIG_FUNCTION_GRAPH_TRACER */
 static inline enum print_line_t
-print_graph_function(struct trace_iterator *iter)
+print_graph_function_flags(struct trace_iterator *iter, u32 flags)
 {
        return TRACE_TYPE_UNHANDLED;
 }
index c16a08f..dc008c1 100644 (file)
@@ -318,18 +318,6 @@ FTRACE_ENTRY(branch, trace_branch,
                 __entry->func, __entry->file, __entry->correct)
 );
 
-FTRACE_ENTRY(hw_branch, hw_branch_entry,
-
-       TRACE_HW_BRANCHES,
-
-       F_STRUCT(
-               __field(        u64,    from    )
-               __field(        u64,    to      )
-       ),
-
-       F_printk("from: %llx to: %llx", __entry->from, __entry->to)
-);
-
 FTRACE_ENTRY(kmem_alloc, kmemtrace_alloc_entry,
 
        TRACE_KMEM_ALLOC,
index 88c0b6d..58092d8 100644 (file)
@@ -1398,7 +1398,7 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
        }
 
        err = -EINVAL;
-       if (!call)
+       if (&call->list == &ftrace_events)
                goto out_unlock;
 
        err = -EEXIST;
index 9aed1a5..dd11c83 100644 (file)
@@ -40,7 +40,7 @@ struct fgraph_data {
 #define TRACE_GRAPH_PRINT_OVERHEAD     0x4
 #define TRACE_GRAPH_PRINT_PROC         0x8
 #define TRACE_GRAPH_PRINT_DURATION     0x10
-#define TRACE_GRAPH_PRINT_ABS_TIME     0X20
+#define TRACE_GRAPH_PRINT_ABS_TIME     0x20
 
 static struct tracer_opt trace_opts[] = {
        /* Display overruns? (for self-debug purpose) */
@@ -179,7 +179,7 @@ unsigned long ftrace_return_to_handler(unsigned long frame_pointer)
        return ret;
 }
 
-static int __trace_graph_entry(struct trace_array *tr,
+int __trace_graph_entry(struct trace_array *tr,
                                struct ftrace_graph_ent *trace,
                                unsigned long flags,
                                int pc)
@@ -246,7 +246,7 @@ int trace_graph_thresh_entry(struct ftrace_graph_ent *trace)
                return trace_graph_entry(trace);
 }
 
-static void __trace_graph_return(struct trace_array *tr,
+void __trace_graph_return(struct trace_array *tr,
                                struct ftrace_graph_ret *trace,
                                unsigned long flags,
                                int pc)
@@ -490,9 +490,10 @@ get_return_for_leaf(struct trace_iterator *iter,
                         * We need to consume the current entry to see
                         * the next one.
                         */
-                       ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL);
+                       ring_buffer_consume(iter->tr->buffer, iter->cpu,
+                                           NULL, NULL);
                        event = ring_buffer_peek(iter->tr->buffer, iter->cpu,
-                                                NULL);
+                                                NULL, NULL);
                }
 
                if (!event)
@@ -526,17 +527,18 @@ get_return_for_leaf(struct trace_iterator *iter,
 
 /* Signal a overhead of time execution to the output */
 static int
-print_graph_overhead(unsigned long long duration, struct trace_seq *s)
+print_graph_overhead(unsigned long long duration, struct trace_seq *s,
+                    u32 flags)
 {
        /* If duration disappear, we don't need anything */
-       if (!(tracer_flags.val & TRACE_GRAPH_PRINT_DURATION))
+       if (!(flags & TRACE_GRAPH_PRINT_DURATION))
                return 1;
 
        /* Non nested entry or return */
        if (duration == -1)
                return trace_seq_printf(s, "  ");
 
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERHEAD) {
+       if (flags & TRACE_GRAPH_PRINT_OVERHEAD) {
                /* Duration exceeded 100 msecs */
                if (duration > 100000ULL)
                        return trace_seq_printf(s, "! ");
@@ -562,7 +564,7 @@ static int print_graph_abs_time(u64 t, struct trace_seq *s)
 
 static enum print_line_t
 print_graph_irq(struct trace_iterator *iter, unsigned long addr,
-               enum trace_type type, int cpu, pid_t pid)
+               enum trace_type type, int cpu, pid_t pid, u32 flags)
 {
        int ret;
        struct trace_seq *s = &iter->seq;
@@ -572,21 +574,21 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
                return TRACE_TYPE_UNHANDLED;
 
        /* Absolute time */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) {
+       if (flags & TRACE_GRAPH_PRINT_ABS_TIME) {
                ret = print_graph_abs_time(iter->ts, s);
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
        /* Cpu */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
+       if (flags & TRACE_GRAPH_PRINT_CPU) {
                ret = print_graph_cpu(s, cpu);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
        /* Proc */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
+       if (flags & TRACE_GRAPH_PRINT_PROC) {
                ret = print_graph_proc(s, pid);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -596,7 +598,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
        }
 
        /* No overhead */
-       ret = print_graph_overhead(-1, s);
+       ret = print_graph_overhead(-1, s, flags);
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
@@ -609,7 +611,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* Don't close the duration column if haven't one */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION)
+       if (flags & TRACE_GRAPH_PRINT_DURATION)
                trace_seq_printf(s, " |");
        ret = trace_seq_printf(s, "\n");
 
@@ -679,7 +681,8 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s)
 static enum print_line_t
 print_graph_entry_leaf(struct trace_iterator *iter,
                struct ftrace_graph_ent_entry *entry,
-               struct ftrace_graph_ret_entry *ret_entry, struct trace_seq *s)
+               struct ftrace_graph_ret_entry *ret_entry,
+               struct trace_seq *s, u32 flags)
 {
        struct fgraph_data *data = iter->private;
        struct ftrace_graph_ret *graph_ret;
@@ -711,12 +714,12 @@ print_graph_entry_leaf(struct trace_iterator *iter,
        }
 
        /* Overhead */
-       ret = print_graph_overhead(duration, s);
+       ret = print_graph_overhead(duration, s, flags);
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* Duration */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) {
+       if (flags & TRACE_GRAPH_PRINT_DURATION) {
                ret = print_graph_duration(duration, s);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -739,7 +742,7 @@ print_graph_entry_leaf(struct trace_iterator *iter,
 static enum print_line_t
 print_graph_entry_nested(struct trace_iterator *iter,
                         struct ftrace_graph_ent_entry *entry,
-                        struct trace_seq *s, int cpu)
+                        struct trace_seq *s, int cpu, u32 flags)
 {
        struct ftrace_graph_ent *call = &entry->graph_ent;
        struct fgraph_data *data = iter->private;
@@ -759,12 +762,12 @@ print_graph_entry_nested(struct trace_iterator *iter,
        }
 
        /* No overhead */
-       ret = print_graph_overhead(-1, s);
+       ret = print_graph_overhead(-1, s, flags);
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* No time */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) {
+       if (flags & TRACE_GRAPH_PRINT_DURATION) {
                ret = trace_seq_printf(s, "            |  ");
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -790,7 +793,7 @@ print_graph_entry_nested(struct trace_iterator *iter,
 
 static enum print_line_t
 print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
-                    int type, unsigned long addr)
+                    int type, unsigned long addr, u32 flags)
 {
        struct fgraph_data *data = iter->private;
        struct trace_entry *ent = iter->ent;
@@ -803,27 +806,27 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
 
        if (type) {
                /* Interrupt */
-               ret = print_graph_irq(iter, addr, type, cpu, ent->pid);
+               ret = print_graph_irq(iter, addr, type, cpu, ent->pid, flags);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
        /* Absolute time */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) {
+       if (flags & TRACE_GRAPH_PRINT_ABS_TIME) {
                ret = print_graph_abs_time(iter->ts, s);
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
        /* Cpu */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
+       if (flags & TRACE_GRAPH_PRINT_CPU) {
                ret = print_graph_cpu(s, cpu);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
        /* Proc */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
+       if (flags & TRACE_GRAPH_PRINT_PROC) {
                ret = print_graph_proc(s, ent->pid);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -845,7 +848,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
 
 static enum print_line_t
 print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
-                       struct trace_iterator *iter)
+                       struct trace_iterator *iter, u32 flags)
 {
        struct fgraph_data *data = iter->private;
        struct ftrace_graph_ent *call = &field->graph_ent;
@@ -853,14 +856,14 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
        static enum print_line_t ret;
        int cpu = iter->cpu;
 
-       if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func))
+       if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags))
                return TRACE_TYPE_PARTIAL_LINE;
 
        leaf_ret = get_return_for_leaf(iter, field);
        if (leaf_ret)
-               ret = print_graph_entry_leaf(iter, field, leaf_ret, s);
+               ret = print_graph_entry_leaf(iter, field, leaf_ret, s, flags);
        else
-               ret = print_graph_entry_nested(iter, field, s, cpu);
+               ret = print_graph_entry_nested(iter, field, s, cpu, flags);
 
        if (data) {
                /*
@@ -879,7 +882,8 @@ print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s,
 
 static enum print_line_t
 print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
-                  struct trace_entry *ent, struct trace_iterator *iter)
+                  struct trace_entry *ent, struct trace_iterator *iter,
+                  u32 flags)
 {
        unsigned long long duration = trace->rettime - trace->calltime;
        struct fgraph_data *data = iter->private;
@@ -909,16 +913,16 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
                }
        }
 
-       if (print_graph_prologue(iter, s, 0, 0))
+       if (print_graph_prologue(iter, s, 0, 0, flags))
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* Overhead */
-       ret = print_graph_overhead(duration, s);
+       ret = print_graph_overhead(duration, s, flags);
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* Duration */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) {
+       if (flags & TRACE_GRAPH_PRINT_DURATION) {
                ret = print_graph_duration(duration, s);
                if (ret == TRACE_TYPE_PARTIAL_LINE)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -948,14 +952,15 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
        }
 
        /* Overrun */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERRUN) {
+       if (flags & TRACE_GRAPH_PRINT_OVERRUN) {
                ret = trace_seq_printf(s, " (Overruns: %lu)\n",
                                        trace->overrun);
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
        }
 
-       ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET, cpu, pid);
+       ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET,
+                             cpu, pid, flags);
        if (ret == TRACE_TYPE_PARTIAL_LINE)
                return TRACE_TYPE_PARTIAL_LINE;
 
@@ -963,8 +968,8 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
 }
 
 static enum print_line_t
-print_graph_comment(struct trace_seq *s,  struct trace_entry *ent,
-                   struct trace_iterator *iter)
+print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
+                   struct trace_iterator *iter, u32 flags)
 {
        unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK);
        struct fgraph_data *data = iter->private;
@@ -976,16 +981,16 @@ print_graph_comment(struct trace_seq *s,  struct trace_entry *ent,
        if (data)
                depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth;
 
-       if (print_graph_prologue(iter, s, 0, 0))
+       if (print_graph_prologue(iter, s, 0, 0, flags))
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* No overhead */
-       ret = print_graph_overhead(-1, s);
+       ret = print_graph_overhead(-1, s, flags);
        if (!ret)
                return TRACE_TYPE_PARTIAL_LINE;
 
        /* No time */
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) {
+       if (flags & TRACE_GRAPH_PRINT_DURATION) {
                ret = trace_seq_printf(s, "            |  ");
                if (!ret)
                        return TRACE_TYPE_PARTIAL_LINE;
@@ -1040,7 +1045,7 @@ print_graph_comment(struct trace_seq *s,  struct trace_entry *ent,
 
 
 enum print_line_t
-print_graph_function(struct trace_iterator *iter)
+print_graph_function_flags(struct trace_iterator *iter, u32 flags)
 {
        struct ftrace_graph_ent_entry *field;
        struct fgraph_data *data = iter->private;
@@ -1061,7 +1066,7 @@ print_graph_function(struct trace_iterator *iter)
        if (data && data->failed) {
                field = &data->ent;
                iter->cpu = data->cpu;
-               ret = print_graph_entry(field, s, iter);
+               ret = print_graph_entry(field, s, iter, flags);
                if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) {
                        per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1;
                        ret = TRACE_TYPE_NO_CONSUME;
@@ -1081,32 +1086,49 @@ print_graph_function(struct trace_iterator *iter)
                struct ftrace_graph_ent_entry saved;
                trace_assign_type(field, entry);
                saved = *field;
-               return print_graph_entry(&saved, s, iter);
+               return print_graph_entry(&saved, s, iter, flags);
        }
        case TRACE_GRAPH_RET: {
                struct ftrace_graph_ret_entry *field;
                trace_assign_type(field, entry);
-               return print_graph_return(&field->ret, s, entry, iter);
+               return print_graph_return(&field->ret, s, entry, iter, flags);
        }
+       case TRACE_STACK:
+       case TRACE_FN:
+               /* dont trace stack and functions as comments */
+               return TRACE_TYPE_UNHANDLED;
+
        default:
-               return print_graph_comment(s, entry, iter);
+               return print_graph_comment(s, entry, iter, flags);
        }
 
        return TRACE_TYPE_HANDLED;
 }
 
-static void print_lat_header(struct seq_file *s)
+static enum print_line_t
+print_graph_function(struct trace_iterator *iter)
+{
+       return print_graph_function_flags(iter, tracer_flags.val);
+}
+
+static enum print_line_t
+print_graph_function_event(struct trace_iterator *iter, int flags)
+{
+       return print_graph_function(iter);
+}
+
+static void print_lat_header(struct seq_file *s, u32 flags)
 {
        static const char spaces[] = "                " /* 16 spaces */
                "    "                                  /* 4 spaces */
                "                 ";                    /* 17 spaces */
        int size = 0;
 
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME)
+       if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
                size += 16;
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU)
+       if (flags & TRACE_GRAPH_PRINT_CPU)
                size += 4;
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC)
+       if (flags & TRACE_GRAPH_PRINT_PROC)
                size += 17;
 
        seq_printf(s, "#%.*s  _-----=> irqs-off        \n", size, spaces);
@@ -1117,43 +1139,48 @@ static void print_lat_header(struct seq_file *s)
        seq_printf(s, "#%.*s|||| /                     \n", size, spaces);
 }
 
-static void print_graph_headers(struct seq_file *s)
+void print_graph_headers_flags(struct seq_file *s, u32 flags)
 {
        int lat = trace_flags & TRACE_ITER_LATENCY_FMT;
 
        if (lat)
-               print_lat_header(s);
+               print_lat_header(s, flags);
 
        /* 1st line */
        seq_printf(s, "#");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME)
+       if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
                seq_printf(s, "     TIME       ");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU)
+       if (flags & TRACE_GRAPH_PRINT_CPU)
                seq_printf(s, " CPU");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC)
+       if (flags & TRACE_GRAPH_PRINT_PROC)
                seq_printf(s, "  TASK/PID       ");
        if (lat)
                seq_printf(s, "|||||");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION)
+       if (flags & TRACE_GRAPH_PRINT_DURATION)
                seq_printf(s, "  DURATION   ");
        seq_printf(s, "               FUNCTION CALLS\n");
 
        /* 2nd line */
        seq_printf(s, "#");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME)
+       if (flags & TRACE_GRAPH_PRINT_ABS_TIME)
                seq_printf(s, "      |         ");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU)
+       if (flags & TRACE_GRAPH_PRINT_CPU)
                seq_printf(s, " |  ");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC)
+       if (flags & TRACE_GRAPH_PRINT_PROC)
                seq_printf(s, "   |    |        ");
        if (lat)
                seq_printf(s, "|||||");
-       if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION)
+       if (flags & TRACE_GRAPH_PRINT_DURATION)
                seq_printf(s, "   |   |      ");
        seq_printf(s, "               |   |   |   |\n");
 }
 
-static void graph_trace_open(struct trace_iterator *iter)
+void print_graph_headers(struct seq_file *s)
+{
+       print_graph_headers_flags(s, tracer_flags.val);
+}
+
+void graph_trace_open(struct trace_iterator *iter)
 {
        /* pid and depth on the last trace processed */
        struct fgraph_data *data;
@@ -1188,7 +1215,7 @@ static void graph_trace_open(struct trace_iterator *iter)
        pr_warning("function graph tracer: not enough memory\n");
 }
 
-static void graph_trace_close(struct trace_iterator *iter)
+void graph_trace_close(struct trace_iterator *iter)
 {
        struct fgraph_data *data = iter->private;
 
@@ -1198,6 +1225,16 @@ static void graph_trace_close(struct trace_iterator *iter)
        }
 }
 
+static struct trace_event graph_trace_entry_event = {
+       .type           = TRACE_GRAPH_ENT,
+       .trace          = print_graph_function_event,
+};
+
+static struct trace_event graph_trace_ret_event = {
+       .type           = TRACE_GRAPH_RET,
+       .trace          = print_graph_function_event,
+};
+
 static struct tracer graph_trace __read_mostly = {
        .name           = "function_graph",
        .open           = graph_trace_open,
@@ -1219,6 +1256,16 @@ static __init int init_graph_trace(void)
 {
        max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1);
 
+       if (!register_ftrace_event(&graph_trace_entry_event)) {
+               pr_warning("Warning: could not register graph trace events\n");
+               return 1;
+       }
+
+       if (!register_ftrace_event(&graph_trace_ret_event)) {
+               pr_warning("Warning: could not register graph trace events\n");
+               return 1;
+       }
+
        return register_tracer(&graph_trace);
 }
 
diff --git a/kernel/trace/trace_hw_branches.c b/kernel/trace/trace_hw_branches.c
deleted file mode 100644 (file)
index 7b97000..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * h/w branch tracer for x86 based on BTS
- *
- * Copyright (C) 2008-2009 Intel Corporation.
- * Markus Metzger <markus.t.metzger@gmail.com>, 2008-2009
- */
-#include <linux/kallsyms.h>
-#include <linux/debugfs.h>
-#include <linux/ftrace.h>
-#include <linux/module.h>
-#include <linux/cpu.h>
-#include <linux/smp.h>
-#include <linux/fs.h>
-
-#include <asm/ds.h>
-
-#include "trace_output.h"
-#include "trace.h"
-
-
-#define BTS_BUFFER_SIZE (1 << 13)
-
-static DEFINE_PER_CPU(struct bts_tracer *, hwb_tracer);
-static DEFINE_PER_CPU(unsigned char[BTS_BUFFER_SIZE], hwb_buffer);
-
-#define this_tracer per_cpu(hwb_tracer, smp_processor_id())
-
-static int trace_hw_branches_enabled __read_mostly;
-static int trace_hw_branches_suspended __read_mostly;
-static struct trace_array *hw_branch_trace __read_mostly;
-
-
-static void bts_trace_init_cpu(int cpu)
-{
-       per_cpu(hwb_tracer, cpu) =
-               ds_request_bts_cpu(cpu, per_cpu(hwb_buffer, cpu),
-                                  BTS_BUFFER_SIZE, NULL, (size_t)-1,
-                                  BTS_KERNEL);
-
-       if (IS_ERR(per_cpu(hwb_tracer, cpu)))
-               per_cpu(hwb_tracer, cpu) = NULL;
-}
-
-static int bts_trace_init(struct trace_array *tr)
-{
-       int cpu;
-
-       hw_branch_trace = tr;
-       trace_hw_branches_enabled = 0;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu) {
-               bts_trace_init_cpu(cpu);
-
-               if (likely(per_cpu(hwb_tracer, cpu)))
-                       trace_hw_branches_enabled = 1;
-       }
-       trace_hw_branches_suspended = 0;
-       put_online_cpus();
-
-       /* If we could not enable tracing on a single cpu, we fail. */
-       return trace_hw_branches_enabled ? 0 : -EOPNOTSUPP;
-}
-
-static void bts_trace_reset(struct trace_array *tr)
-{
-       int cpu;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu) {
-               if (likely(per_cpu(hwb_tracer, cpu))) {
-                       ds_release_bts(per_cpu(hwb_tracer, cpu));
-                       per_cpu(hwb_tracer, cpu) = NULL;
-               }
-       }
-       trace_hw_branches_enabled = 0;
-       trace_hw_branches_suspended = 0;
-       put_online_cpus();
-}
-
-static void bts_trace_start(struct trace_array *tr)
-{
-       int cpu;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu)
-               if (likely(per_cpu(hwb_tracer, cpu)))
-                       ds_resume_bts(per_cpu(hwb_tracer, cpu));
-       trace_hw_branches_suspended = 0;
-       put_online_cpus();
-}
-
-static void bts_trace_stop(struct trace_array *tr)
-{
-       int cpu;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu)
-               if (likely(per_cpu(hwb_tracer, cpu)))
-                       ds_suspend_bts(per_cpu(hwb_tracer, cpu));
-       trace_hw_branches_suspended = 1;
-       put_online_cpus();
-}
-
-static int __cpuinit bts_hotcpu_handler(struct notifier_block *nfb,
-                                    unsigned long action, void *hcpu)
-{
-       int cpu = (long)hcpu;
-
-       switch (action) {
-       case CPU_ONLINE:
-       case CPU_DOWN_FAILED:
-               /* The notification is sent with interrupts enabled. */
-               if (trace_hw_branches_enabled) {
-                       bts_trace_init_cpu(cpu);
-
-                       if (trace_hw_branches_suspended &&
-                           likely(per_cpu(hwb_tracer, cpu)))
-                               ds_suspend_bts(per_cpu(hwb_tracer, cpu));
-               }
-               break;
-
-       case CPU_DOWN_PREPARE:
-               /* The notification is sent with interrupts enabled. */
-               if (likely(per_cpu(hwb_tracer, cpu))) {
-                       ds_release_bts(per_cpu(hwb_tracer, cpu));
-                       per_cpu(hwb_tracer, cpu) = NULL;
-               }
-       }
-
-       return NOTIFY_DONE;
-}
-
-static struct notifier_block bts_hotcpu_notifier __cpuinitdata = {
-       .notifier_call = bts_hotcpu_handler
-};
-
-static void bts_trace_print_header(struct seq_file *m)
-{
-       seq_puts(m, "# CPU#        TO  <-  FROM\n");
-}
-
-static enum print_line_t bts_trace_print_line(struct trace_iterator *iter)
-{
-       unsigned long symflags = TRACE_ITER_SYM_OFFSET;
-       struct trace_entry *entry = iter->ent;
-       struct trace_seq *seq = &iter->seq;
-       struct hw_branch_entry *it;
-
-       trace_assign_type(it, entry);
-
-       if (entry->type == TRACE_HW_BRANCHES) {
-               if (trace_seq_printf(seq, "%4d  ", iter->cpu) &&
-                   seq_print_ip_sym(seq, it->to, symflags) &&
-                   trace_seq_printf(seq, "\t  <-  ") &&
-                   seq_print_ip_sym(seq, it->from, symflags) &&
-                   trace_seq_printf(seq, "\n"))
-                       return TRACE_TYPE_HANDLED;
-               return TRACE_TYPE_PARTIAL_LINE;
-       }
-       return TRACE_TYPE_UNHANDLED;
-}
-
-void trace_hw_branch(u64 from, u64 to)
-{
-       struct ftrace_event_call *call = &event_hw_branch;
-       struct trace_array *tr = hw_branch_trace;
-       struct ring_buffer_event *event;
-       struct ring_buffer *buf;
-       struct hw_branch_entry *entry;
-       unsigned long irq1;
-       int cpu;
-
-       if (unlikely(!tr))
-               return;
-
-       if (unlikely(!trace_hw_branches_enabled))
-               return;
-
-       local_irq_save(irq1);
-       cpu = raw_smp_processor_id();
-       if (atomic_inc_return(&tr->data[cpu]->disabled) != 1)
-               goto out;
-
-       buf = tr->buffer;
-       event = trace_buffer_lock_reserve(buf, TRACE_HW_BRANCHES,
-                                         sizeof(*entry), 0, 0);
-       if (!event)
-               goto out;
-       entry   = ring_buffer_event_data(event);
-       tracing_generic_entry_update(&entry->ent, 0, from);
-       entry->ent.type = TRACE_HW_BRANCHES;
-       entry->from = from;
-       entry->to   = to;
-       if (!filter_check_discard(call, entry, buf, event))
-               trace_buffer_unlock_commit(buf, event, 0, 0);
-
- out:
-       atomic_dec(&tr->data[cpu]->disabled);
-       local_irq_restore(irq1);
-}
-
-static void trace_bts_at(const struct bts_trace *trace, void *at)
-{
-       struct bts_struct bts;
-       int err = 0;
-
-       WARN_ON_ONCE(!trace->read);
-       if (!trace->read)
-               return;
-
-       err = trace->read(this_tracer, at, &bts);
-       if (err < 0)
-               return;
-
-       switch (bts.qualifier) {
-       case BTS_BRANCH:
-               trace_hw_branch(bts.variant.lbr.from, bts.variant.lbr.to);
-               break;
-       }
-}
-
-/*
- * Collect the trace on the current cpu and write it into the ftrace buffer.
- *
- * pre: tracing must be suspended on the current cpu
- */
-static void trace_bts_cpu(void *arg)
-{
-       struct trace_array *tr = (struct trace_array *)arg;
-       const struct bts_trace *trace;
-       unsigned char *at;
-
-       if (unlikely(!tr))
-               return;
-
-       if (unlikely(atomic_read(&tr->data[raw_smp_processor_id()]->disabled)))
-               return;
-
-       if (unlikely(!this_tracer))
-               return;
-
-       trace = ds_read_bts(this_tracer);
-       if (!trace)
-               return;
-
-       for (at = trace->ds.top; (void *)at < trace->ds.end;
-            at += trace->ds.size)
-               trace_bts_at(trace, at);
-
-       for (at = trace->ds.begin; (void *)at < trace->ds.top;
-            at += trace->ds.size)
-               trace_bts_at(trace, at);
-}
-
-static void trace_bts_prepare(struct trace_iterator *iter)
-{
-       int cpu;
-
-       get_online_cpus();
-       for_each_online_cpu(cpu)
-               if (likely(per_cpu(hwb_tracer, cpu)))
-                       ds_suspend_bts(per_cpu(hwb_tracer, cpu));
-       /*
-        * We need to collect the trace on the respective cpu since ftrace
-        * implicitly adds the record for the current cpu.
-        * Once that is more flexible, we could collect the data from any cpu.
-        */
-       on_each_cpu(trace_bts_cpu, iter->tr, 1);
-
-       for_each_online_cpu(cpu)
-               if (likely(per_cpu(hwb_tracer, cpu)))
-                       ds_resume_bts(per_cpu(hwb_tracer, cpu));
-       put_online_cpus();
-}
-
-static void trace_bts_close(struct trace_iterator *iter)
-{
-       tracing_reset_online_cpus(iter->tr);
-}
-
-void trace_hw_branch_oops(void)
-{
-       if (this_tracer) {
-               ds_suspend_bts_noirq(this_tracer);
-               trace_bts_cpu(hw_branch_trace);
-               ds_resume_bts_noirq(this_tracer);
-       }
-}
-
-struct tracer bts_tracer __read_mostly =
-{
-       .name           = "hw-branch-tracer",
-       .init           = bts_trace_init,
-       .reset          = bts_trace_reset,
-       .print_header   = bts_trace_print_header,
-       .print_line     = bts_trace_print_line,
-       .start          = bts_trace_start,
-       .stop           = bts_trace_stop,
-       .open           = trace_bts_prepare,
-       .close          = trace_bts_close,
-#ifdef CONFIG_FTRACE_SELFTEST
-       .selftest       = trace_selftest_startup_hw_branches,
-#endif /* CONFIG_FTRACE_SELFTEST */
-};
-
-__init static int init_bts_trace(void)
-{
-       register_hotcpu_notifier(&bts_hotcpu_notifier);
-       return register_tracer(&bts_tracer);
-}
-device_initcall(init_bts_trace);
index 2974bc7..6fd486e 100644 (file)
@@ -34,6 +34,9 @@ static int trace_type __read_mostly;
 
 static int save_lat_flag;
 
+static void stop_irqsoff_tracer(struct trace_array *tr, int graph);
+static int start_irqsoff_tracer(struct trace_array *tr, int graph);
+
 #ifdef CONFIG_PREEMPT_TRACER
 static inline int
 preempt_trace(void)
@@ -55,6 +58,23 @@ irq_trace(void)
 # define irq_trace() (0)
 #endif
 
+#define TRACE_DISPLAY_GRAPH    1
+
+static struct tracer_opt trace_opts[] = {
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+       /* display latency trace as call graph */
+       { TRACER_OPT(display-graph, TRACE_DISPLAY_GRAPH) },
+#endif
+       { } /* Empty entry */
+};
+
+static struct tracer_flags tracer_flags = {
+       .val  = 0,
+       .opts = trace_opts,
+};
+
+#define is_graph() (tracer_flags.val & TRACE_DISPLAY_GRAPH)
+
 /*
  * Sequence count - we record it when starting a measurement and
  * skip the latency if the sequence has changed - some other section
@@ -108,6 +128,202 @@ static struct ftrace_ops trace_ops __read_mostly =
 };
 #endif /* CONFIG_FUNCTION_TRACER */
 
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+static int irqsoff_set_flag(u32 old_flags, u32 bit, int set)
+{
+       int cpu;
+
+       if (!(bit & TRACE_DISPLAY_GRAPH))
+               return -EINVAL;
+
+       if (!(is_graph() ^ set))
+               return 0;
+
+       stop_irqsoff_tracer(irqsoff_trace, !set);
+
+       for_each_possible_cpu(cpu)
+               per_cpu(tracing_cpu, cpu) = 0;
+
+       tracing_max_latency = 0;
+       tracing_reset_online_cpus(irqsoff_trace);
+
+       return start_irqsoff_tracer(irqsoff_trace, set);
+}
+
+static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
+{
+       struct trace_array *tr = irqsoff_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int ret;
+       int cpu;
+       int pc;
+
+       cpu = raw_smp_processor_id();
+       if (likely(!per_cpu(tracing_cpu, cpu)))
+               return 0;
+
+       local_save_flags(flags);
+       /* slight chance to get a false positive on tracing_cpu */
+       if (!irqs_disabled_flags(flags))
+               return 0;
+
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1)) {
+               pc = preempt_count();
+               ret = __trace_graph_entry(tr, trace, flags, pc);
+       } else
+               ret = 0;
+
+       atomic_dec(&data->disabled);
+       return ret;
+}
+
+static void irqsoff_graph_return(struct ftrace_graph_ret *trace)
+{
+       struct trace_array *tr = irqsoff_trace;
+       struct trace_array_cpu *data;
+       unsigned long flags;
+       long disabled;
+       int cpu;
+       int pc;
+
+       cpu = raw_smp_processor_id();
+       if (likely(!per_cpu(tracing_cpu, cpu)))
+               return;
+
+       local_save_flags(flags);
+       /* slight chance to get a false positive on tracing_cpu */
+       if (!irqs_disabled_flags(flags))
+               return;
+
+       data = tr->data[cpu];
+       disabled = atomic_inc_return(&data->disabled);
+
+       if (likely(disabled == 1)) {
+               pc = preempt_count();
+               __trace_graph_return(tr, trace, flags, pc);
+       }
+
+       atomic_dec(&data->disabled);
+}
+
+static void irqsoff_trace_open(struct trace_iterator *iter)
+{
+       if (is_graph())
+               graph_trace_open(iter);
+
+}
+
+static void irqsoff_trace_close(struct trace_iterator *iter)
+{
+       if (iter->private)
+               graph_trace_close(iter);
+}
+
+#define GRAPH_TRACER_FLAGS (TRACE_GRAPH_PRINT_CPU | \
+                           TRACE_GRAPH_PRINT_PROC)
+
+static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
+{
+       u32 flags = GRAPH_TRACER_FLAGS;
+
+       if (trace_flags & TRACE_ITER_LATENCY_FMT)
+               flags |= TRACE_GRAPH_PRINT_DURATION;
+       else
+               flags |= TRACE_GRAPH_PRINT_ABS_TIME;
+
+       /*
+        * In graph mode call the graph tracer output function,
+        * otherwise go with the TRACE_FN event handler
+        */
+       if (is_graph())
+               return print_graph_function_flags(iter, flags);
+
+       return TRACE_TYPE_UNHANDLED;
+}
+
+static void irqsoff_print_header(struct seq_file *s)
+{
+       if (is_graph()) {
+               struct trace_iterator *iter = s->private;
+               u32 flags = GRAPH_TRACER_FLAGS;
+
+               if (trace_flags & TRACE_ITER_LATENCY_FMT) {
+                       /* print nothing if the buffers are empty */
+                       if (trace_empty(iter))
+                               return;
+
+                       print_trace_header(s, iter);
+                       flags |= TRACE_GRAPH_PRINT_DURATION;
+               } else
+                       flags |= TRACE_GRAPH_PRINT_ABS_TIME;
+
+               print_graph_headers_flags(s, flags);
+       } else
+               trace_default_header(s);
+}
+
+static void
+trace_graph_function(struct trace_array *tr,
+                unsigned long ip, unsigned long flags, int pc)
+{
+       u64 time = trace_clock_local();
+       struct ftrace_graph_ent ent = {
+               .func  = ip,
+               .depth = 0,
+       };
+       struct ftrace_graph_ret ret = {
+               .func     = ip,
+               .depth    = 0,
+               .calltime = time,
+               .rettime  = time,
+       };
+
+       __trace_graph_entry(tr, &ent, flags, pc);
+       __trace_graph_return(tr, &ret, flags, pc);
+}
+
+static void
+__trace_function(struct trace_array *tr,
+                unsigned long ip, unsigned long parent_ip,
+                unsigned long flags, int pc)
+{
+       if (!is_graph())
+               trace_function(tr, ip, parent_ip, flags, pc);
+       else {
+               trace_graph_function(tr, parent_ip, flags, pc);
+               trace_graph_function(tr, ip, flags, pc);
+       }
+}
+
+#else
+#define __trace_function trace_function
+
+static int irqsoff_set_flag(u32 old_flags, u32 bit, int set)
+{
+       return -EINVAL;
+}
+
+static int irqsoff_graph_entry(struct ftrace_graph_ent *trace)
+{
+       return -1;
+}
+
+static enum print_line_t irqsoff_print_line(struct trace_iterator *iter)
+{
+       return TRACE_TYPE_UNHANDLED;
+}
+
+static void irqsoff_graph_return(struct ftrace_graph_ret *trace) { }
+static void irqsoff_print_header(struct seq_file *s) { }
+static void irqsoff_trace_open(struct trace_iterator *iter) { }
+static void irqsoff_trace_close(struct trace_iterator *iter) { }
+#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
+
 /*
  * Should this new latency be reported/recorded?
  */
@@ -150,7 +366,7 @@ check_critical_timing(struct trace_array *tr,
        if (!report_latency(delta))
                goto out_unlock;
 
-       trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
+       __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
        /* Skip 5 functions to get to the irq/preempt enable function */
        __trace_stack(tr, flags, 5, pc);
 
@@ -172,7 +388,7 @@ out_unlock:
 out:
        data->critical_sequence = max_sequence;
        data->preempt_timestamp = ftrace_now(cpu);
-       trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
+       __trace_function(tr, CALLER_ADDR0, parent_ip, flags, pc);
 }
 
 static inline void
@@ -204,7 +420,7 @@ start_critical_timing(unsigned long ip, unsigned long parent_ip)
 
        local_save_flags(flags);
 
-       trace_function(tr, ip, parent_ip, flags, preempt_count());
+       __trace_function(tr, ip, parent_ip, flags, preempt_count());
 
        per_cpu(tracing_cpu, cpu) = 1;
 
@@ -238,7 +454,7 @@ stop_critical_timing(unsigned long ip, unsigned long parent_ip)
        atomic_inc(&data->disabled);
 
        local_save_flags(flags);
-       trace_function(tr, ip, parent_ip, flags, preempt_count());
+       __trace_function(tr, ip, parent_ip, flags, preempt_count());
        check_critical_timing(tr, data, parent_ip ? : ip, cpu);
        data->critical_start = 0;
        atomic_dec(&data->disabled);
@@ -347,19 +563,32 @@ void trace_preempt_off(unsigned long a0, unsigned long a1)
 }
 #endif /* CONFIG_PREEMPT_TRACER */
 
-static void start_irqsoff_tracer(struct trace_array *tr)
+static int start_irqsoff_tracer(struct trace_array *tr, int graph)
 {
-       register_ftrace_function(&trace_ops);
-       if (tracing_is_enabled())
+       int ret = 0;
+
+       if (!graph)
+               ret = register_ftrace_function(&trace_ops);
+       else
+               ret = register_ftrace_graph(&irqsoff_graph_return,
+                                           &irqsoff_graph_entry);
+
+       if (!ret && tracing_is_enabled())
                tracer_enabled = 1;
        else
                tracer_enabled = 0;
+
+       return ret;
 }
 
-static void stop_irqsoff_tracer(struct trace_array *tr)
+static void stop_irqsoff_tracer(struct trace_array *tr, int graph)
 {
        tracer_enabled = 0;
-       unregister_ftrace_function(&trace_ops);
+
+       if (!graph)
+               unregister_ftrace_function(&trace_ops);
+       else
+               unregister_ftrace_graph();
 }
 
 static void __irqsoff_tracer_init(struct trace_array *tr)
@@ -372,12 +601,14 @@ static void __irqsoff_tracer_init(struct trace_array *tr)
        /* make sure that the tracer is visible */
        smp_wmb();
        tracing_reset_online_cpus(tr);
-       start_irqsoff_tracer(tr);
+
+       if (start_irqsoff_tracer(tr, is_graph()))
+               printk(KERN_ERR "failed to start irqsoff tracer\n");
 }
 
 static void irqsoff_tracer_reset(struct trace_array *tr)
 {
-       stop_irqsoff_tracer(tr);
+       stop_irqsoff_tracer(tr, is_graph());
 
        if (!save_lat_flag)
                trace_flags &= ~TRACE_ITER_LATENCY_FMT;
@@ -409,9 +640,15 @@ static struct tracer irqsoff_tracer __read_mostly =
        .start          = irqsoff_tracer_start,
        .stop           = irqsoff_tracer_stop,
        .print_max      = 1,
+       .print_header   = irqsoff_print_header,
+       .print_line     = irqsoff_print_line,
+       .flags          = &tracer_flags,
+       .set_flag       = irqsoff_set_flag,
 #ifdef CONFIG_FTRACE_SELFTEST
        .selftest    = trace_selftest_startup_irqsoff,
 #endif
+       .open           = irqsoff_trace_open,
+       .close          = irqsoff_trace_close,
 };
 # define register_irqsoff(trace) register_tracer(&trace)
 #else
@@ -435,9 +672,15 @@ static struct tracer preemptoff_tracer __read_mostly =
        .start          = irqsoff_tracer_start,
        .stop           = irqsoff_tracer_stop,
        .print_max      = 1,
+       .print_header   = irqsoff_print_header,
+       .print_line     = irqsoff_print_line,
+       .flags          = &tracer_flags,
+       .set_flag       = irqsoff_set_flag,
 #ifdef CONFIG_FTRACE_SELFTEST
        .selftest    = trace_selftest_startup_preemptoff,
 #endif
+       .open           = irqsoff_trace_open,
+       .close          = irqsoff_trace_close,
 };
 # define register_preemptoff(trace) register_tracer(&trace)
 #else
@@ -463,9 +706,15 @@ static struct tracer preemptirqsoff_tracer __read_mostly =
        .start          = irqsoff_tracer_start,
        .stop           = irqsoff_tracer_stop,
        .print_max      = 1,
+       .print_header   = irqsoff_print_header,
+       .print_line     = irqsoff_print_line,
+       .flags          = &tracer_flags,
+       .set_flag       = irqsoff_set_flag,
 #ifdef CONFIG_FTRACE_SELFTEST
        .selftest    = trace_selftest_startup_preemptirqsoff,
 #endif
+       .open           = irqsoff_trace_open,
+       .close          = irqsoff_trace_close,
 };
 
 # define register_preemptirqsoff(trace) register_tracer(&trace)
index 1251e36..a751432 100644 (file)
@@ -29,6 +29,8 @@
 #include <linux/ctype.h>
 #include <linux/ptrace.h>
 #include <linux/perf_event.h>
+#include <linux/stringify.h>
+#include <asm/bitsperlong.h>
 
 #include "trace.h"
 #include "trace_output.h"
@@ -40,7 +42,6 @@
 
 /* Reserved field names */
 #define FIELD_STRING_IP "__probe_ip"
-#define FIELD_STRING_NARGS "__probe_nargs"
 #define FIELD_STRING_RETIP "__probe_ret_ip"
 #define FIELD_STRING_FUNC "__probe_func"
 
@@ -52,56 +53,102 @@ const char *reserved_field_names[] = {
        "common_tgid",
        "common_lock_depth",
        FIELD_STRING_IP,
-       FIELD_STRING_NARGS,
        FIELD_STRING_RETIP,
        FIELD_STRING_FUNC,
 };
 
-struct fetch_func {
-       unsigned long (*func)(struct pt_regs *, void *);
+/* Printing function type */
+typedef int (*print_type_func_t)(struct trace_seq *, const char *, void *);
+#define PRINT_TYPE_FUNC_NAME(type)     print_type_##type
+#define PRINT_TYPE_FMT_NAME(type)      print_type_format_##type
+
+/* Printing  in basic type function template */
+#define DEFINE_BASIC_PRINT_TYPE_FUNC(type, fmt, cast)                  \
+static __kprobes int PRINT_TYPE_FUNC_NAME(type)(struct trace_seq *s,   \
+                                               const char *name, void *data)\
+{                                                                      \
+       return trace_seq_printf(s, " %s=" fmt, name, (cast)*(type *)data);\
+}                                                                      \
+static const char PRINT_TYPE_FMT_NAME(type)[] = fmt;
+
+DEFINE_BASIC_PRINT_TYPE_FUNC(u8, "%x", unsigned int)
+DEFINE_BASIC_PRINT_TYPE_FUNC(u16, "%x", unsigned int)
+DEFINE_BASIC_PRINT_TYPE_FUNC(u32, "%lx", unsigned long)
+DEFINE_BASIC_PRINT_TYPE_FUNC(u64, "%llx", unsigned long long)
+DEFINE_BASIC_PRINT_TYPE_FUNC(s8, "%d", int)
+DEFINE_BASIC_PRINT_TYPE_FUNC(s16, "%d", int)
+DEFINE_BASIC_PRINT_TYPE_FUNC(s32, "%ld", long)
+DEFINE_BASIC_PRINT_TYPE_FUNC(s64, "%lld", long long)
+
+/* Data fetch function type */
+typedef        void (*fetch_func_t)(struct pt_regs *, void *, void *);
+
+struct fetch_param {
+       fetch_func_t    fn;
        void *data;
 };
 
-static __kprobes unsigned long call_fetch(struct fetch_func *f,
-                                         struct pt_regs *regs)
+static __kprobes void call_fetch(struct fetch_param *fprm,
+                                struct pt_regs *regs, void *dest)
 {
-       return f->func(regs, f->data);
+       return fprm->fn(regs, fprm->data, dest);
 }
 
-/* fetch handlers */
-static __kprobes unsigned long fetch_register(struct pt_regs *regs,
-                                             void *offset)
-{
-       return regs_get_register(regs, (unsigned int)((unsigned long)offset));
+#define FETCH_FUNC_NAME(kind, type)    fetch_##kind##_##type
+/*
+ * Define macro for basic types - we don't need to define s* types, because
+ * we have to care only about bitwidth at recording time.
+ */
+#define DEFINE_BASIC_FETCH_FUNCS(kind)  \
+DEFINE_FETCH_##kind(u8)                        \
+DEFINE_FETCH_##kind(u16)               \
+DEFINE_FETCH_##kind(u32)               \
+DEFINE_FETCH_##kind(u64)
+
+#define CHECK_BASIC_FETCH_FUNCS(kind, fn)      \
+       ((FETCH_FUNC_NAME(kind, u8) == fn) ||   \
+        (FETCH_FUNC_NAME(kind, u16) == fn) ||  \
+        (FETCH_FUNC_NAME(kind, u32) == fn) ||  \
+        (FETCH_FUNC_NAME(kind, u64) == fn))
+
+/* Data fetch function templates */
+#define DEFINE_FETCH_reg(type)                                         \
+static __kprobes void FETCH_FUNC_NAME(reg, type)(struct pt_regs *regs, \
+                                         void *offset, void *dest)     \
+{                                                                      \
+       *(type *)dest = (type)regs_get_register(regs,                   \
+                               (unsigned int)((unsigned long)offset)); \
 }
-
-static __kprobes unsigned long fetch_stack(struct pt_regs *regs,
-                                          void *num)
-{
-       return regs_get_kernel_stack_nth(regs,
-                                        (unsigned int)((unsigned long)num));
+DEFINE_BASIC_FETCH_FUNCS(reg)
+
+#define DEFINE_FETCH_stack(type)                                       \
+static __kprobes void FETCH_FUNC_NAME(stack, type)(struct pt_regs *regs,\
+                                         void *offset, void *dest)     \
+{                                                                      \
+       *(type *)dest = (type)regs_get_kernel_stack_nth(regs,           \
+                               (unsigned int)((unsigned long)offset)); \
 }
+DEFINE_BASIC_FETCH_FUNCS(stack)
 
-static __kprobes unsigned long fetch_memory(struct pt_regs *regs, void *addr)
-{
-       unsigned long retval;
-
-       if (probe_kernel_address(addr, retval))
-               return 0;
-       return retval;
+#define DEFINE_FETCH_retval(type)                                      \
+static __kprobes void FETCH_FUNC_NAME(retval, type)(struct pt_regs *regs,\
+                                         void *dummy, void *dest)      \
+{                                                                      \
+       *(type *)dest = (type)regs_return_value(regs);                  \
 }
-
-static __kprobes unsigned long fetch_retvalue(struct pt_regs *regs,
-                                             void *dummy)
-{
-       return regs_return_value(regs);
-}
-
-static __kprobes unsigned long fetch_stack_address(struct pt_regs *regs,
-                                                  void *dummy)
-{
-       return kernel_stack_pointer(regs);
+DEFINE_BASIC_FETCH_FUNCS(retval)
+
+#define DEFINE_FETCH_memory(type)                                      \
+static __kprobes void FETCH_FUNC_NAME(memory, type)(struct pt_regs *regs,\
+                                         void *addr, void *dest)       \
+{                                                                      \
+       type retval;                                                    \
+       if (probe_kernel_address(addr, retval))                         \
+               *(type *)dest = 0;                                      \
+       else                                                            \
+               *(type *)dest = retval;                                 \
 }
+DEFINE_BASIC_FETCH_FUNCS(memory)
 
 /* Memory fetching by symbol */
 struct symbol_cache {
@@ -145,51 +192,126 @@ static struct symbol_cache *alloc_symbol_cache(const char *sym, long offset)
        return sc;
 }
 
-static __kprobes unsigned long fetch_symbol(struct pt_regs *regs, void *data)
-{
-       struct symbol_cache *sc = data;
-
-       if (sc->addr)
-               return fetch_memory(regs, (void *)sc->addr);
-       else
-               return 0;
+#define DEFINE_FETCH_symbol(type)                                      \
+static __kprobes void FETCH_FUNC_NAME(symbol, type)(struct pt_regs *regs,\
+                                         void *data, void *dest)       \
+{                                                                      \
+       struct symbol_cache *sc = data;                                 \
+       if (sc->addr)                                                   \
+               fetch_memory_##type(regs, (void *)sc->addr, dest);      \
+       else                                                            \
+               *(type *)dest = 0;                                      \
 }
+DEFINE_BASIC_FETCH_FUNCS(symbol)
 
-/* Special indirect memory access interface */
-struct indirect_fetch_data {
-       struct fetch_func orig;
+/* Dereference memory access function */
+struct deref_fetch_param {
+       struct fetch_param orig;
        long offset;
 };
 
-static __kprobes unsigned long fetch_indirect(struct pt_regs *regs, void *data)
-{
-       struct indirect_fetch_data *ind = data;
-       unsigned long addr;
-
-       addr = call_fetch(&ind->orig, regs);
-       if (addr) {
-               addr += ind->offset;
-               return fetch_memory(regs, (void *)addr);
-       } else
-               return 0;
+#define DEFINE_FETCH_deref(type)                                       \
+static __kprobes void FETCH_FUNC_NAME(deref, type)(struct pt_regs *regs,\
+                                           void *data, void *dest)     \
+{                                                                      \
+       struct deref_fetch_param *dprm = data;                          \
+       unsigned long addr;                                             \
+       call_fetch(&dprm->orig, regs, &addr);                           \
+       if (addr) {                                                     \
+               addr += dprm->offset;                                   \
+               fetch_memory_##type(regs, (void *)addr, dest);          \
+       } else                                                          \
+               *(type *)dest = 0;                                      \
 }
+DEFINE_BASIC_FETCH_FUNCS(deref)
 
-static __kprobes void free_indirect_fetch_data(struct indirect_fetch_data *data)
+static __kprobes void free_deref_fetch_param(struct deref_fetch_param *data)
 {
-       if (data->orig.func == fetch_indirect)
-               free_indirect_fetch_data(data->orig.data);
-       else if (data->orig.func == fetch_symbol)
+       if (CHECK_BASIC_FETCH_FUNCS(deref, data->orig.fn))
+               free_deref_fetch_param(data->orig.data);
+       else if (CHECK_BASIC_FETCH_FUNCS(symbol, data->orig.fn))
                free_symbol_cache(data->orig.data);
        kfree(data);
 }
 
+/* Default (unsigned long) fetch type */
+#define __DEFAULT_FETCH_TYPE(t) u##t
+#define _DEFAULT_FETCH_TYPE(t) __DEFAULT_FETCH_TYPE(t)
+#define DEFAULT_FETCH_TYPE _DEFAULT_FETCH_TYPE(BITS_PER_LONG)
+#define DEFAULT_FETCH_TYPE_STR __stringify(DEFAULT_FETCH_TYPE)
+
+#define ASSIGN_FETCH_FUNC(kind, type)  \
+       .kind = FETCH_FUNC_NAME(kind, type)
+
+#define ASSIGN_FETCH_TYPE(ptype, ftype, sign)  \
+       {.name = #ptype,                        \
+        .size = sizeof(ftype),                 \
+        .is_signed = sign,                     \
+        .print = PRINT_TYPE_FUNC_NAME(ptype),  \
+        .fmt = PRINT_TYPE_FMT_NAME(ptype),     \
+ASSIGN_FETCH_FUNC(reg, ftype),                 \
+ASSIGN_FETCH_FUNC(stack, ftype),               \
+ASSIGN_FETCH_FUNC(retval, ftype),              \
+ASSIGN_FETCH_FUNC(memory, ftype),              \
+ASSIGN_FETCH_FUNC(symbol, ftype),              \
+ASSIGN_FETCH_FUNC(deref, ftype),               \
+       }
+
+/* Fetch type information table */
+static const struct fetch_type {
+       const char      *name;          /* Name of type */
+       size_t          size;           /* Byte size of type */
+       int             is_signed;      /* Signed flag */
+       print_type_func_t       print;  /* Print functions */
+       const char      *fmt;           /* Fromat string */
+       /* Fetch functions */
+       fetch_func_t    reg;
+       fetch_func_t    stack;
+       fetch_func_t    retval;
+       fetch_func_t    memory;
+       fetch_func_t    symbol;
+       fetch_func_t    deref;
+} fetch_type_table[] = {
+       ASSIGN_FETCH_TYPE(u8,  u8,  0),
+       ASSIGN_FETCH_TYPE(u16, u16, 0),
+       ASSIGN_FETCH_TYPE(u32, u32, 0),
+       ASSIGN_FETCH_TYPE(u64, u64, 0),
+       ASSIGN_FETCH_TYPE(s8,  u8,  1),
+       ASSIGN_FETCH_TYPE(s16, u16, 1),
+       ASSIGN_FETCH_TYPE(s32, u32, 1),
+       ASSIGN_FETCH_TYPE(s64, u64, 1),
+};
+
+static const struct fetch_type *find_fetch_type(const char *type)
+{
+       int i;
+
+       if (!type)
+               type = DEFAULT_FETCH_TYPE_STR;
+
+       for (i = 0; i < ARRAY_SIZE(fetch_type_table); i++)
+               if (strcmp(type, fetch_type_table[i].name) == 0)
+                       return &fetch_type_table[i];
+       return NULL;
+}
+
+/* Special function : only accept unsigned long */
+static __kprobes void fetch_stack_address(struct pt_regs *regs,
+                                         void *dummy, void *dest)
+{
+       *(unsigned long *)dest = kernel_stack_pointer(regs);
+}
+
 /**
  * Kprobe event core functions
  */
 
 struct probe_arg {
-       struct fetch_func       fetch;
-       const char              *name;
+       struct fetch_param      fetch;
+       unsigned int            offset; /* Offset from argument entry */
+       const char              *name;  /* Name of this argument */
+       const char              *comm;  /* Command of this argument */
+       const struct fetch_type *type;  /* Type of this argument */
 };
 
 /* Flags for trace_probe */
@@ -204,6 +326,7 @@ struct trace_probe {
        const char              *symbol;        /* symbol name */
        struct ftrace_event_call        call;
        struct trace_event              event;
+       ssize_t                 size;           /* trace entry size */
        unsigned int            nr_args;
        struct probe_arg        args[];
 };
@@ -212,6 +335,7 @@ struct trace_probe {
        (offsetof(struct trace_probe, args) +   \
        (sizeof(struct probe_arg) * (n)))
 
+
 static __kprobes int probe_is_return(struct trace_probe *tp)
 {
        return tp->rp.handler != NULL;
@@ -222,49 +346,6 @@ static __kprobes const char *probe_symbol(struct trace_probe *tp)
        return tp->symbol ? tp->symbol : "unknown";
 }
 
-static int probe_arg_string(char *buf, size_t n, struct fetch_func *ff)
-{
-       int ret = -EINVAL;
-
-       if (ff->func == fetch_register) {
-               const char *name;
-               name = regs_query_register_name((unsigned int)((long)ff->data));
-               ret = snprintf(buf, n, "%%%s", name);
-       } else if (ff->func == fetch_stack)
-               ret = snprintf(buf, n, "$stack%lu", (unsigned long)ff->data);
-       else if (ff->func == fetch_memory)
-               ret = snprintf(buf, n, "@0x%p", ff->data);
-       else if (ff->func == fetch_symbol) {
-               struct symbol_cache *sc = ff->data;
-               if (sc->offset)
-                       ret = snprintf(buf, n, "@%s%+ld", sc->symbol,
-                                       sc->offset);
-               else
-                       ret = snprintf(buf, n, "@%s", sc->symbol);
-       } else if (ff->func == fetch_retvalue)
-               ret = snprintf(buf, n, "$retval");
-       else if (ff->func == fetch_stack_address)
-               ret = snprintf(buf, n, "$stack");
-       else if (ff->func == fetch_indirect) {
-               struct indirect_fetch_data *id = ff->data;
-               size_t l = 0;
-               ret = snprintf(buf, n, "%+ld(", id->offset);
-               if (ret >= n)
-                       goto end;
-               l += ret;
-               ret = probe_arg_string(buf + l, n - l, &id->orig);
-               if (ret < 0)
-                       goto end;
-               l += ret;
-               ret = snprintf(buf + l, n - l, ")");
-               ret += l;
-       }
-end:
-       if (ret >= n)
-               return -ENOSPC;
-       return ret;
-}
-
 static int register_probe_event(struct trace_probe *tp);
 static void unregister_probe_event(struct trace_probe *tp);
 
@@ -347,11 +428,12 @@ error:
 
 static void free_probe_arg(struct probe_arg *arg)
 {
-       if (arg->fetch.func == fetch_symbol)
+       if (CHECK_BASIC_FETCH_FUNCS(deref, arg->fetch.fn))
+               free_deref_fetch_param(arg->fetch.data);
+       else if (CHECK_BASIC_FETCH_FUNCS(symbol, arg->fetch.fn))
                free_symbol_cache(arg->fetch.data);
-       else if (arg->fetch.func == fetch_indirect)
-               free_indirect_fetch_data(arg->fetch.data);
        kfree(arg->name);
+       kfree(arg->comm);
 }
 
 static void free_trace_probe(struct trace_probe *tp)
@@ -457,28 +539,30 @@ static int split_symbol_offset(char *symbol, unsigned long *offset)
 #define PARAM_MAX_ARGS 16
 #define PARAM_MAX_STACK (THREAD_SIZE / sizeof(unsigned long))
 
-static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return)
+static int parse_probe_vars(char *arg, const struct fetch_type *t,
+                           struct fetch_param *f, int is_return)
 {
        int ret = 0;
        unsigned long param;
 
        if (strcmp(arg, "retval") == 0) {
-               if (is_return) {
-                       ff->func = fetch_retvalue;
-                       ff->data = NULL;
-               } else
+               if (is_return)
+                       f->fn = t->retval;
+               else
                        ret = -EINVAL;
        } else if (strncmp(arg, "stack", 5) == 0) {
                if (arg[5] == '\0') {
-                       ff->func = fetch_stack_address;
-                       ff->data = NULL;
+                       if (strcmp(t->name, DEFAULT_FETCH_TYPE_STR) == 0)
+                               f->fn = fetch_stack_address;
+                       else
+                               ret = -EINVAL;
                } else if (isdigit(arg[5])) {
                        ret = strict_strtoul(arg + 5, 10, &param);
                        if (ret || param > PARAM_MAX_STACK)
                                ret = -EINVAL;
                        else {
-                               ff->func = fetch_stack;
-                               ff->data = (void *)param;
+                               f->fn = t->stack;
+                               f->data = (void *)param;
                        }
                } else
                        ret = -EINVAL;
@@ -488,7 +572,8 @@ static int parse_probe_vars(char *arg, struct fetch_func *ff, int is_return)
 }
 
 /* Recursive argument parser */
-static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)
+static int __parse_probe_arg(char *arg, const struct fetch_type *t,
+                            struct fetch_param *f, int is_return)
 {
        int ret = 0;
        unsigned long param;
@@ -497,13 +582,13 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)
 
        switch (arg[0]) {
        case '$':
-               ret = parse_probe_vars(arg + 1, ff, is_return);
+               ret = parse_probe_vars(arg + 1, t, f, is_return);
                break;
        case '%':       /* named register */
                ret = regs_query_register_offset(arg + 1);
                if (ret >= 0) {
-                       ff->func = fetch_register;
-                       ff->data = (void *)(unsigned long)ret;
+                       f->fn = t->reg;
+                       f->data = (void *)(unsigned long)ret;
                        ret = 0;
                }
                break;
@@ -512,26 +597,22 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)
                        ret = strict_strtoul(arg + 1, 0, &param);
                        if (ret)
                                break;
-                       ff->func = fetch_memory;
-                       ff->data = (void *)param;
+                       f->fn = t->memory;
+                       f->data = (void *)param;
                } else {
                        ret = split_symbol_offset(arg + 1, &offset);
                        if (ret)
                                break;
-                       ff->data = alloc_symbol_cache(arg + 1, offset);
-                       if (ff->data)
-                               ff->func = fetch_symbol;
-                       else
-                               ret = -EINVAL;
+                       f->data = alloc_symbol_cache(arg + 1, offset);
+                       if (f->data)
+                               f->fn = t->symbol;
                }
                break;
-       case '+':       /* indirect memory */
+       case '+':       /* deref memory */
        case '-':
                tmp = strchr(arg, '(');
-               if (!tmp) {
-                       ret = -EINVAL;
+               if (!tmp)
                        break;
-               }
                *tmp = '\0';
                ret = strict_strtol(arg + 1, 0, &offset);
                if (ret)
@@ -541,38 +622,58 @@ static int __parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)
                arg = tmp + 1;
                tmp = strrchr(arg, ')');
                if (tmp) {
-                       struct indirect_fetch_data *id;
+                       struct deref_fetch_param *dprm;
+                       const struct fetch_type *t2 = find_fetch_type(NULL);
                        *tmp = '\0';
-                       id = kzalloc(sizeof(struct indirect_fetch_data),
-                                    GFP_KERNEL);
-                       if (!id)
+                       dprm = kzalloc(sizeof(struct deref_fetch_param),
+                                      GFP_KERNEL);
+                       if (!dprm)
                                return -ENOMEM;
-                       id->offset = offset;
-                       ret = __parse_probe_arg(arg, &id->orig, is_return);
+                       dprm->offset = offset;
+                       ret = __parse_probe_arg(arg, t2, &dprm->orig,
+                                               is_return);
                        if (ret)
-                               kfree(id);
+                               kfree(dprm);
                        else {
-                               ff->func = fetch_indirect;
-                               ff->data = (void *)id;
+                               f->fn = t->deref;
+                               f->data = (void *)dprm;
                        }
-               } else
-                       ret = -EINVAL;
+               }
                break;
-       default:
-               /* TODO: support custom handler */
-               ret = -EINVAL;
        }
+       if (!ret && !f->fn)
+               ret = -EINVAL;
        return ret;
 }
 
 /* String length checking wrapper */
-static int parse_probe_arg(char *arg, struct fetch_func *ff, int is_return)
+static int parse_probe_arg(char *arg, struct trace_probe *tp,
+                          struct probe_arg *parg, int is_return)
 {
+       const char *t;
+
        if (strlen(arg) > MAX_ARGSTR_LEN) {
                pr_info("Argument is too long.: %s\n",  arg);
                return -ENOSPC;
        }
-       return __parse_probe_arg(arg, ff, is_return);
+       parg->comm = kstrdup(arg, GFP_KERNEL);
+       if (!parg->comm) {
+               pr_info("Failed to allocate memory for command '%s'.\n", arg);
+               return -ENOMEM;
+       }
+       t = strchr(parg->comm, ':');
+       if (t) {
+               arg[t - parg->comm] = '\0';
+               t++;
+       }
+       parg->type = find_fetch_type(t);
+       if (!parg->type) {
+               pr_info("Unsupported type: %s\n", t);
+               return -EINVAL;
+       }
+       parg->offset = tp->size;
+       tp->size += parg->type->size;
+       return __parse_probe_arg(arg, parg->type, &parg->fetch, is_return);
 }
 
 /* Return 1 if name is reserved or already used by another argument */
@@ -602,15 +703,18 @@ static int create_trace_probe(int argc, char **argv)
         *  @ADDR       : fetch memory at ADDR (ADDR should be in kernel)
         *  @SYM[+|-offs] : fetch memory at SYM +|- offs (SYM is a data symbol)
         *  %REG        : fetch register REG
-        * Indirect memory fetch:
+        * Dereferencing memory fetch:
         *  +|-offs(ARG) : fetch memory at ARG +|- offs address.
         * Alias name of args:
         *  NAME=FETCHARG : set NAME as alias of FETCHARG.
+        * Type of args:
+        *  FETCHARG:TYPE : use TYPE instead of unsigned long.
         */
        struct trace_probe *tp;
        int i, ret = 0;
        int is_return = 0, is_delete = 0;
-       char *symbol = NULL, *event = NULL, *arg = NULL, *group = NULL;
+       char *symbol = NULL, *event = NULL, *group = NULL;
+       char *arg, *tmp;
        unsigned long offset = 0;
        void *addr = NULL;
        char buf[MAX_EVENT_NAME_LEN];
@@ -723,13 +827,6 @@ static int create_trace_probe(int argc, char **argv)
                else
                        arg = argv[i];
 
-               if (conflict_field_name(argv[i], tp->args, i)) {
-                       pr_info("Argument%d name '%s' conflicts with "
-                               "another field.\n", i, argv[i]);
-                       ret = -EINVAL;
-                       goto error;
-               }
-
                tp->args[i].name = kstrdup(argv[i], GFP_KERNEL);
                if (!tp->args[i].name) {
                        pr_info("Failed to allocate argument%d name '%s'.\n",
@@ -737,9 +834,19 @@ static int create_trace_probe(int argc, char **argv)
                        ret = -ENOMEM;
                        goto error;
                }
+               tmp = strchr(tp->args[i].name, ':');
+               if (tmp)
+                       *tmp = '_';     /* convert : to _ */
+
+               if (conflict_field_name(tp->args[i].name, tp->args, i)) {
+                       pr_info("Argument%d name '%s' conflicts with "
+                               "another field.\n", i, argv[i]);
+                       ret = -EINVAL;
+                       goto error;
+               }
 
                /* Parse fetch argument */
-               ret = parse_probe_arg(arg, &tp->args[i].fetch, is_return);
+               ret = parse_probe_arg(arg, tp, &tp->args[i], is_return);
                if (ret) {
                        pr_info("Parse error at argument%d. (%d)\n", i, ret);
                        kfree(tp->args[i].name);
@@ -794,8 +901,7 @@ static void probes_seq_stop(struct seq_file *m, void *v)
 static int probes_seq_show(struct seq_file *m, void *v)
 {
        struct trace_probe *tp = v;
-       int i, ret;
-       char buf[MAX_ARGSTR_LEN + 1];
+       int i;
 
        seq_printf(m, "%c", probe_is_return(tp) ? 'r' : 'p');
        seq_printf(m, ":%s/%s", tp->call.system, tp->call.name);
@@ -807,15 +913,10 @@ static int probes_seq_show(struct seq_file *m, void *v)
        else
                seq_printf(m, " %s", probe_symbol(tp));
 
-       for (i = 0; i < tp->nr_args; i++) {
-               ret = probe_arg_string(buf, MAX_ARGSTR_LEN, &tp->args[i].fetch);
-               if (ret < 0) {
-                       pr_warning("Argument%d decoding error(%d).\n", i, ret);
-                       return ret;
-               }
-               seq_printf(m, " %s=%s", tp->args[i].name, buf);
-       }
+       for (i = 0; i < tp->nr_args; i++)
+               seq_printf(m, " %s=%s", tp->args[i].name, tp->args[i].comm);
        seq_printf(m, "\n");
+
        return 0;
 }
 
@@ -945,9 +1046,10 @@ static const struct file_operations kprobe_profile_ops = {
 static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
 {
        struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
-       struct kprobe_trace_entry *entry;
+       struct kprobe_trace_entry_head *entry;
        struct ring_buffer_event *event;
        struct ring_buffer *buffer;
+       u8 *data;
        int size, i, pc;
        unsigned long irq_flags;
        struct ftrace_event_call *call = &tp->call;
@@ -957,7 +1059,7 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
        local_save_flags(irq_flags);
        pc = preempt_count();
 
-       size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args);
+       size = sizeof(*entry) + tp->size;
 
        event = trace_current_buffer_lock_reserve(&buffer, call->id, size,
                                                  irq_flags, pc);
@@ -965,10 +1067,10 @@ static __kprobes void kprobe_trace_func(struct kprobe *kp, struct pt_regs *regs)
                return;
 
        entry = ring_buffer_event_data(event);
-       entry->nargs = tp->nr_args;
        entry->ip = (unsigned long)kp->addr;
+       data = (u8 *)&entry[1];
        for (i = 0; i < tp->nr_args; i++)
-               entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+               call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
 
        if (!filter_current_check_discard(buffer, call, entry, event))
                trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc);
@@ -979,9 +1081,10 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
                                          struct pt_regs *regs)
 {
        struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
-       struct kretprobe_trace_entry *entry;
+       struct kretprobe_trace_entry_head *entry;
        struct ring_buffer_event *event;
        struct ring_buffer *buffer;
+       u8 *data;
        int size, i, pc;
        unsigned long irq_flags;
        struct ftrace_event_call *call = &tp->call;
@@ -989,7 +1092,7 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
        local_save_flags(irq_flags);
        pc = preempt_count();
 
-       size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args);
+       size = sizeof(*entry) + tp->size;
 
        event = trace_current_buffer_lock_reserve(&buffer, call->id, size,
                                                  irq_flags, pc);
@@ -997,11 +1100,11 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
                return;
 
        entry = ring_buffer_event_data(event);
-       entry->nargs = tp->nr_args;
        entry->func = (unsigned long)tp->rp.kp.addr;
        entry->ret_ip = (unsigned long)ri->ret_addr;
+       data = (u8 *)&entry[1];
        for (i = 0; i < tp->nr_args; i++)
-               entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+               call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
 
        if (!filter_current_check_discard(buffer, call, entry, event))
                trace_nowake_buffer_unlock_commit(buffer, event, irq_flags, pc);
@@ -1011,13 +1114,14 @@ static __kprobes void kretprobe_trace_func(struct kretprobe_instance *ri,
 enum print_line_t
 print_kprobe_event(struct trace_iterator *iter, int flags)
 {
-       struct kprobe_trace_entry *field;
+       struct kprobe_trace_entry_head *field;
        struct trace_seq *s = &iter->seq;
        struct trace_event *event;
        struct trace_probe *tp;
+       u8 *data;
        int i;
 
-       field = (struct kprobe_trace_entry *)iter->ent;
+       field = (struct kprobe_trace_entry_head *)iter->ent;
        event = ftrace_find_event(field->ent.type);
        tp = container_of(event, struct trace_probe, event);
 
@@ -1030,9 +1134,10 @@ print_kprobe_event(struct trace_iterator *iter, int flags)
        if (!trace_seq_puts(s, ")"))
                goto partial;
 
-       for (i = 0; i < field->nargs; i++)
-               if (!trace_seq_printf(s, " %s=%lx",
-                                     tp->args[i].name, field->args[i]))
+       data = (u8 *)&field[1];
+       for (i = 0; i < tp->nr_args; i++)
+               if (!tp->args[i].type->print(s, tp->args[i].name,
+                                            data + tp->args[i].offset))
                        goto partial;
 
        if (!trace_seq_puts(s, "\n"))
@@ -1046,13 +1151,14 @@ partial:
 enum print_line_t
 print_kretprobe_event(struct trace_iterator *iter, int flags)
 {
-       struct kretprobe_trace_entry *field;
+       struct kretprobe_trace_entry_head *field;
        struct trace_seq *s = &iter->seq;
        struct trace_event *event;
        struct trace_probe *tp;
+       u8 *data;
        int i;
 
-       field = (struct kretprobe_trace_entry *)iter->ent;
+       field = (struct kretprobe_trace_entry_head *)iter->ent;
        event = ftrace_find_event(field->ent.type);
        tp = container_of(event, struct trace_probe, event);
 
@@ -1071,9 +1177,10 @@ print_kretprobe_event(struct trace_iterator *iter, int flags)
        if (!trace_seq_puts(s, ")"))
                goto partial;
 
-       for (i = 0; i < field->nargs; i++)
-               if (!trace_seq_printf(s, " %s=%lx",
-                                     tp->args[i].name, field->args[i]))
+       data = (u8 *)&field[1];
+       for (i = 0; i < tp->nr_args; i++)
+               if (!tp->args[i].type->print(s, tp->args[i].name,
+                                            data + tp->args[i].offset))
                        goto partial;
 
        if (!trace_seq_puts(s, "\n"))
@@ -1129,29 +1236,43 @@ static int probe_event_raw_init(struct ftrace_event_call *event_call)
 static int kprobe_event_define_fields(struct ftrace_event_call *event_call)
 {
        int ret, i;
-       struct kprobe_trace_entry field;
+       struct kprobe_trace_entry_head field;
        struct trace_probe *tp = (struct trace_probe *)event_call->data;
 
        DEFINE_FIELD(unsigned long, ip, FIELD_STRING_IP, 0);
-       DEFINE_FIELD(int, nargs, FIELD_STRING_NARGS, 1);
        /* Set argument names as fields */
-       for (i = 0; i < tp->nr_args; i++)
-               DEFINE_FIELD(unsigned long, args[i], tp->args[i].name, 0);
+       for (i = 0; i < tp->nr_args; i++) {
+               ret = trace_define_field(event_call, tp->args[i].type->name,
+                                        tp->args[i].name,
+                                        sizeof(field) + tp->args[i].offset,
+                                        tp->args[i].type->size,
+                                        tp->args[i].type->is_signed,
+                                        FILTER_OTHER);
+               if (ret)
+                       return ret;
+       }
        return 0;
 }
 
 static int kretprobe_event_define_fields(struct ftrace_event_call *event_call)
 {
        int ret, i;
-       struct kretprobe_trace_entry field;
+       struct kretprobe_trace_entry_head field;
        struct trace_probe *tp = (struct trace_probe *)event_call->data;
 
        DEFINE_FIELD(unsigned long, func, FIELD_STRING_FUNC, 0);
        DEFINE_FIELD(unsigned long, ret_ip, FIELD_STRING_RETIP, 0);
-       DEFINE_FIELD(int, nargs, FIELD_STRING_NARGS, 1);
        /* Set argument names as fields */
-       for (i = 0; i < tp->nr_args; i++)
-               DEFINE_FIELD(unsigned long, args[i], tp->args[i].name, 0);
+       for (i = 0; i < tp->nr_args; i++) {
+               ret = trace_define_field(event_call, tp->args[i].type->name,
+                                        tp->args[i].name,
+                                        sizeof(field) + tp->args[i].offset,
+                                        tp->args[i].type->size,
+                                        tp->args[i].type->is_signed,
+                                        FILTER_OTHER);
+               if (ret)
+                       return ret;
+       }
        return 0;
 }
 
@@ -1176,8 +1297,8 @@ static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
        pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
 
        for (i = 0; i < tp->nr_args; i++) {
-               pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%%lx",
-                               tp->args[i].name);
+               pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%s",
+                               tp->args[i].name, tp->args[i].type->fmt);
        }
 
        pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
@@ -1219,12 +1340,13 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
 {
        struct trace_probe *tp = container_of(kp, struct trace_probe, rp.kp);
        struct ftrace_event_call *call = &tp->call;
-       struct kprobe_trace_entry *entry;
+       struct kprobe_trace_entry_head *entry;
+       u8 *data;
        int size, __size, i;
        unsigned long irq_flags;
        int rctx;
 
-       __size = SIZEOF_KPROBE_TRACE_ENTRY(tp->nr_args);
+       __size = sizeof(*entry) + tp->size;
        size = ALIGN(__size + sizeof(u32), sizeof(u64));
        size -= sizeof(u32);
        if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
@@ -1235,10 +1357,10 @@ static __kprobes void kprobe_perf_func(struct kprobe *kp,
        if (!entry)
                return;
 
-       entry->nargs = tp->nr_args;
        entry->ip = (unsigned long)kp->addr;
+       data = (u8 *)&entry[1];
        for (i = 0; i < tp->nr_args; i++)
-               entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+               call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
 
        perf_trace_buf_submit(entry, size, rctx, entry->ip, 1, irq_flags, regs);
 }
@@ -1249,12 +1371,13 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
 {
        struct trace_probe *tp = container_of(ri->rp, struct trace_probe, rp);
        struct ftrace_event_call *call = &tp->call;
-       struct kretprobe_trace_entry *entry;
+       struct kretprobe_trace_entry_head *entry;
+       u8 *data;
        int size, __size, i;
        unsigned long irq_flags;
        int rctx;
 
-       __size = SIZEOF_KRETPROBE_TRACE_ENTRY(tp->nr_args);
+       __size = sizeof(*entry) + tp->size;
        size = ALIGN(__size + sizeof(u32), sizeof(u64));
        size -= sizeof(u32);
        if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
@@ -1265,11 +1388,11 @@ static __kprobes void kretprobe_perf_func(struct kretprobe_instance *ri,
        if (!entry)
                return;
 
-       entry->nargs = tp->nr_args;
        entry->func = (unsigned long)tp->rp.kp.addr;
        entry->ret_ip = (unsigned long)ri->ret_addr;
+       data = (u8 *)&entry[1];
        for (i = 0; i < tp->nr_args; i++)
-               entry->args[i] = call_fetch(&tp->args[i].fetch, regs);
+               call_fetch(&tp->args[i].fetch, regs, data + tp->args[i].offset);
 
        perf_trace_buf_submit(entry, size, rctx, entry->ret_ip, 1,
                               irq_flags, regs);
index d59cd68..8eaf007 100644 (file)
 
 #include <asm/atomic.h>
 
-/*
- * For now, let us restrict the no. of symbols traced simultaneously to number
- * of available hardware breakpoint registers.
- */
-#define KSYM_TRACER_MAX HBP_NUM
-
 #define KSYM_TRACER_OP_LEN 3 /* rw- */
 
 struct trace_ksym {
@@ -53,7 +47,6 @@ struct trace_ksym {
 
 static struct trace_array *ksym_trace_array;
 
-static unsigned int ksym_filter_entry_count;
 static unsigned int ksym_tracing_enabled;
 
 static HLIST_HEAD(ksym_filter_head);
@@ -181,13 +174,6 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr)
        struct trace_ksym *entry;
        int ret = -ENOMEM;
 
-       if (ksym_filter_entry_count >= KSYM_TRACER_MAX) {
-               printk(KERN_ERR "ksym_tracer: Maximum limit:(%d) reached. No"
-               " new requests for tracing can be accepted now.\n",
-                       KSYM_TRACER_MAX);
-               return -ENOSPC;
-       }
-
        entry = kzalloc(sizeof(struct trace_ksym), GFP_KERNEL);
        if (!entry)
                return -ENOMEM;
@@ -203,13 +189,17 @@ int process_new_ksym_entry(char *ksymname, int op, unsigned long addr)
 
        if (IS_ERR(entry->ksym_hbp)) {
                ret = PTR_ERR(entry->ksym_hbp);
-               printk(KERN_INFO "ksym_tracer request failed. Try again"
-                                       " later!!\n");
+               if (ret == -ENOSPC) {
+                       printk(KERN_ERR "ksym_tracer: Maximum limit reached."
+                       " No new requests for tracing can be accepted now.\n");
+               } else {
+                       printk(KERN_INFO "ksym_tracer request failed. Try again"
+                                        " later!!\n");
+               }
                goto err;
        }
 
        hlist_add_head_rcu(&(entry->ksym_hlist), &ksym_filter_head);
-       ksym_filter_entry_count++;
 
        return 0;
 
@@ -265,7 +255,6 @@ static void __ksym_trace_reset(void)
        hlist_for_each_entry_safe(entry, node, node1, &ksym_filter_head,
                                                                ksym_hlist) {
                unregister_wide_hw_breakpoint(entry->ksym_hbp);
-               ksym_filter_entry_count--;
                hlist_del_rcu(&(entry->ksym_hlist));
                synchronize_rcu();
                kfree(entry);
@@ -338,7 +327,6 @@ static ssize_t ksym_trace_filter_write(struct file *file,
                                goto out_unlock;
                }
                /* Error or "symbol:---" case: drop it */
-               ksym_filter_entry_count--;
                hlist_del_rcu(&(entry->ksym_hlist));
                synchronize_rcu();
                kfree(entry);
index 8e46b33..2404c12 100644 (file)
@@ -253,7 +253,7 @@ void *trace_seq_reserve(struct trace_seq *s, size_t len)
        void *ret;
 
        if (s->full)
-               return 0;
+               return NULL;
 
        if (len > ((PAGE_SIZE - 1) - s->len)) {
                s->full = 1;
index 5fca0f5..a55fccf 100644 (file)
@@ -50,8 +50,7 @@ tracing_sched_switch_trace(struct trace_array *tr,
 }
 
 static void
-probe_sched_switch(struct rq *__rq, struct task_struct *prev,
-                       struct task_struct *next)
+probe_sched_switch(struct task_struct *prev, struct task_struct *next)
 {
        struct trace_array_cpu *data;
        unsigned long flags;
@@ -109,7 +108,7 @@ tracing_sched_wakeup_trace(struct trace_array *tr,
 }
 
 static void
-probe_sched_wakeup(struct rq *__rq, struct task_struct *wakee, int success)
+probe_sched_wakeup(struct task_struct *wakee, int success)
 {
        struct trace_array_cpu *data;
        unsigned long flags;
index 0271742..8052446 100644 (file)
@@ -107,8 +107,7 @@ static void probe_wakeup_migrate_task(struct task_struct *task, int cpu)
 }
 
 static void notrace
-probe_wakeup_sched_switch(struct rq *rq, struct task_struct *prev,
-       struct task_struct *next)
+probe_wakeup_sched_switch(struct task_struct *prev, struct task_struct *next)
 {
        struct trace_array_cpu *data;
        cycle_t T0, T1, delta;
@@ -200,7 +199,7 @@ static void wakeup_reset(struct trace_array *tr)
 }
 
 static void
-probe_wakeup(struct rq *rq, struct task_struct *p, int success)
+probe_wakeup(struct task_struct *p, int success)
 {
        struct trace_array_cpu *data;
        int cpu = smp_processor_id();
index 81003b4..250e7f9 100644 (file)
@@ -17,7 +17,6 @@ static inline int trace_valid_entry(struct trace_entry *entry)
        case TRACE_BRANCH:
        case TRACE_GRAPH_ENT:
        case TRACE_GRAPH_RET:
-       case TRACE_HW_BRANCHES:
        case TRACE_KSYM:
                return 1;
        }
@@ -30,7 +29,7 @@ static int trace_test_buffer_cpu(struct trace_array *tr, int cpu)
        struct trace_entry *entry;
        unsigned int loops = 0;
 
-       while ((event = ring_buffer_consume(tr->buffer, cpu, NULL))) {
+       while ((event = ring_buffer_consume(tr->buffer, cpu, NULL, NULL))) {
                entry = ring_buffer_event_data(event);
 
                /*
@@ -256,7 +255,8 @@ trace_selftest_startup_function(struct tracer *trace, struct trace_array *tr)
 /* Maximum number of functions to trace before diagnosing a hang */
 #define GRAPH_MAX_FUNC_TEST    100000000
 
-static void __ftrace_dump(bool disable_tracing);
+static void
+__ftrace_dump(bool disable_tracing, enum ftrace_dump_mode oops_dump_mode);
 static unsigned int graph_hang_thresh;
 
 /* Wrap the real function entry probe to avoid possible hanging */
@@ -267,7 +267,7 @@ static int trace_graph_entry_watchdog(struct ftrace_graph_ent *trace)
                ftrace_graph_stop();
                printk(KERN_WARNING "BUG: Function graph tracer hang!\n");
                if (ftrace_dump_on_oops)
-                       __ftrace_dump(false);
+                       __ftrace_dump(false, DUMP_ALL);
                return 0;
        }
 
@@ -755,62 +755,6 @@ trace_selftest_startup_branch(struct tracer *trace, struct trace_array *tr)
 }
 #endif /* CONFIG_BRANCH_TRACER */
 
-#ifdef CONFIG_HW_BRANCH_TRACER
-int
-trace_selftest_startup_hw_branches(struct tracer *trace,
-                                  struct trace_array *tr)
-{
-       struct trace_iterator *iter;
-       struct tracer tracer;
-       unsigned long count;
-       int ret;
-
-       if (!trace->open) {
-               printk(KERN_CONT "missing open function...");
-               return -1;
-       }
-
-       ret = tracer_init(trace, tr);
-       if (ret) {
-               warn_failed_init_tracer(trace, ret);
-               return ret;
-       }
-
-       /*
-        * The hw-branch tracer needs to collect the trace from the various
-        * cpu trace buffers - before tracing is stopped.
-        */
-       iter = kzalloc(sizeof(*iter), GFP_KERNEL);
-       if (!iter)
-               return -ENOMEM;
-
-       memcpy(&tracer, trace, sizeof(tracer));
-
-       iter->trace = &tracer;
-       iter->tr = tr;
-       iter->pos = -1;
-       mutex_init(&iter->mutex);
-
-       trace->open(iter);
-
-       mutex_destroy(&iter->mutex);
-       kfree(iter);
-
-       tracing_stop();
-
-       ret = trace_test_buffer(tr, &count);
-       trace->reset(tr);
-       tracing_start();
-
-       if (!ret && !count) {
-               printk(KERN_CONT "no entries found..");
-               ret = -1;
-       }
-
-       return ret;
-}
-#endif /* CONFIG_HW_BRANCH_TRACER */
-
 #ifdef CONFIG_KSYM_TRACER
 static int ksym_selftest_dummy;
 
index 766467b..7e72614 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/user_namespace.h>
-#include "cred-internals.h"
 
 struct user_namespace init_user_ns = {
        .kref = {
@@ -137,9 +136,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
        struct hlist_head *hashent = uidhashentry(ns, uid);
        struct user_struct *up, *new;
 
-       /* Make uid_hash_find() + uids_user_create() + uid_hash_insert()
-        * atomic.
-        */
        spin_lock_irq(&uidhash_lock);
        up = uid_hash_find(uid, hashent);
        spin_unlock_irq(&uidhash_lock);
@@ -161,11 +157,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
                spin_lock_irq(&uidhash_lock);
                up = uid_hash_find(uid, hashent);
                if (up) {
-                       /* This case is not possible when CONFIG_USER_SCHED
-                        * is defined, since we serialize alloc_uid() using
-                        * uids_mutex. Hence no need to call
-                        * sched_destroy_user() or remove_user_sysfs_dir().
-                        */
                        key_put(new->uid_keyring);
                        key_put(new->session_keyring);
                        kmem_cache_free(uid_cachep, new);
@@ -178,8 +169,6 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
 
        return up;
 
-       put_user_ns(new->user_ns);
-       kmem_cache_free(uid_cachep, new);
 out_unlock:
        return NULL;
 }
index 5bfb213..77dabbf 100644 (file)
@@ -229,6 +229,16 @@ static inline void set_wq_data(struct work_struct *work,
        atomic_long_set(&work->data, new);
 }
 
+/*
+ * Clear WORK_STRUCT_PENDING and the workqueue on which it was queued.
+ */
+static inline void clear_wq_data(struct work_struct *work)
+{
+       unsigned long flags = *work_data_bits(work) &
+                               (1UL << WORK_STRUCT_STATIC);
+       atomic_long_set(&work->data, flags);
+}
+
 static inline
 struct cpu_workqueue_struct *get_wq_data(struct work_struct *work)
 {
@@ -671,7 +681,7 @@ static int __cancel_work_timer(struct work_struct *work,
                wait_on_work(work);
        } while (unlikely(ret < 0));
 
-       work_clear_pending(work);
+       clear_wq_data(work);
        return ret;
 }
 
@@ -845,6 +855,30 @@ int schedule_on_each_cpu(work_func_t func)
        return 0;
 }
 
+/**
+ * flush_scheduled_work - ensure that any scheduled work has run to completion.
+ *
+ * Forces execution of the kernel-global workqueue and blocks until its
+ * completion.
+ *
+ * Think twice before calling this function!  It's very easy to get into
+ * trouble if you don't take great care.  Either of the following situations
+ * will lead to deadlock:
+ *
+ *     One of the work items currently on the workqueue needs to acquire
+ *     a lock held by your code or its caller.
+ *
+ *     Your code is running in the context of a work routine.
+ *
+ * They will be detected by lockdep when they occur, but the first might not
+ * occur very often.  It depends on what work items are on the workqueue and
+ * what locks they need, which you have no control over.
+ *
+ * In most situations flushing the entire workqueue is overkill; you merely
+ * need to know that a particular work item isn't queued and isn't running.
+ * In such cases you should use cancel_delayed_work_sync() or
+ * cancel_work_sync() instead.
+ */
 void flush_scheduled_work(void)
 {
        flush_workqueue(keventd_wq);
index 935248b..d85be90 100644 (file)
@@ -512,6 +512,18 @@ config PROVE_RCU
 
         Say N if you are unsure.
 
+config PROVE_RCU_REPEATEDLY
+       bool "RCU debugging: don't disable PROVE_RCU on first splat"
+       depends on PROVE_RCU
+       default n
+       help
+        By itself, PROVE_RCU will disable checking upon issuing the
+        first warning (or "splat").  This feature prevents such
+        disabling, allowing multiple RCU-lockdep warnings to be printed
+        on a single reboot.
+
+        Say N if you are unsure.
+
 config LOCKDEP
        bool
        depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
@@ -793,7 +805,7 @@ config RCU_CPU_STALL_DETECTOR
 config RCU_CPU_STALL_VERBOSE
        bool "Print additional per-task information for RCU_CPU_STALL_DETECTOR"
        depends on RCU_CPU_STALL_DETECTOR && TREE_PREEMPT_RCU
-       default n
+       default y
        help
          This option causes RCU to printk detailed per-task information
          for any tasks that are stalling the current RCU grace period.
@@ -1086,6 +1098,13 @@ config DMA_API_DEBUG
          This option causes a performance degredation.  Use only if you want
          to debug device drivers. If unsure, say N.
 
+config ATOMIC64_SELFTEST
+       bool "Perform an atomic64_t self-test at boot"
+       help
+         Enable this option to test the atomic64_t functions at boot.
+
+         If unsure, say N.
+
 source "samples/Kconfig"
 
 source "lib/Kconfig.kgdb"
index 0d40152..9e6d3c2 100644 (file)
@@ -39,7 +39,10 @@ lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
 lib-$(CONFIG_GENERIC_FIND_FIRST_BIT) += find_next_bit.o
 lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find_next_bit.o
 obj-$(CONFIG_GENERIC_FIND_LAST_BIT) += find_last_bit.o
+
+CFLAGS_hweight.o = $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
 obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
+
 obj-$(CONFIG_LOCK_KERNEL) += kernel_lock.o
 obj-$(CONFIG_BTREE) += btree.o
 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
@@ -101,6 +104,8 @@ obj-$(CONFIG_GENERIC_CSUM) += checksum.o
 
 obj-$(CONFIG_GENERIC_ATOMIC64) += atomic64.o
 
+obj-$(CONFIG_ATOMIC64_SELFTEST) += atomic64_test.o
+
 hostprogs-y    := gen_crc32table
 clean-files    := crc32table.h
 
index 8bee16e..a21c12b 100644 (file)
@@ -162,12 +162,12 @@ int atomic64_add_unless(atomic64_t *v, long long a, long long u)
 {
        unsigned long flags;
        spinlock_t *lock = lock_addr(v);
-       int ret = 1;
+       int ret = 0;
 
        spin_lock_irqsave(lock, flags);
        if (v->counter != u) {
                v->counter += a;
-               ret = 0;
+               ret = 1;
        }
        spin_unlock_irqrestore(lock, flags);
        return ret;
diff --git a/lib/atomic64_test.c b/lib/atomic64_test.c
new file mode 100644 (file)
index 0000000..65e482c
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Testsuite for atomic64_t functions
+ *
+ * Copyright Â© 2010  Luca Barbieri
+ *
+ * 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.
+ */
+#include <linux/init.h>
+#include <asm/atomic.h>
+
+#define INIT(c) do { atomic64_set(&v, c); r = c; } while (0)
+static __init int test_atomic64(void)
+{
+       long long v0 = 0xaaa31337c001d00dLL;
+       long long v1 = 0xdeadbeefdeafcafeLL;
+       long long v2 = 0xfaceabadf00df001LL;
+       long long onestwos = 0x1111111122222222LL;
+       long long one = 1LL;
+
+       atomic64_t v = ATOMIC64_INIT(v0);
+       long long r = v0;
+       BUG_ON(v.counter != r);
+
+       atomic64_set(&v, v1);
+       r = v1;
+       BUG_ON(v.counter != r);
+       BUG_ON(atomic64_read(&v) != r);
+
+       INIT(v0);
+       atomic64_add(onestwos, &v);
+       r += onestwos;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       atomic64_add(-one, &v);
+       r += -one;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r += onestwos;
+       BUG_ON(atomic64_add_return(onestwos, &v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r += -one;
+       BUG_ON(atomic64_add_return(-one, &v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       atomic64_sub(onestwos, &v);
+       r -= onestwos;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       atomic64_sub(-one, &v);
+       r -= -one;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r -= onestwos;
+       BUG_ON(atomic64_sub_return(onestwos, &v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r -= -one;
+       BUG_ON(atomic64_sub_return(-one, &v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       atomic64_inc(&v);
+       r += one;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r += one;
+       BUG_ON(atomic64_inc_return(&v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       atomic64_dec(&v);
+       r -= one;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       r -= one;
+       BUG_ON(atomic64_dec_return(&v) != r);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       BUG_ON(atomic64_xchg(&v, v1) != v0);
+       r = v1;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       BUG_ON(atomic64_cmpxchg(&v, v0, v1) != v0);
+       r = v1;
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       BUG_ON(atomic64_cmpxchg(&v, v2, v1) != v0);
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       BUG_ON(atomic64_add_unless(&v, one, v0));
+       BUG_ON(v.counter != r);
+
+       INIT(v0);
+       BUG_ON(!atomic64_add_unless(&v, one, v1));
+       r += one;
+       BUG_ON(v.counter != r);
+
+#if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(_ASM_GENERIC_ATOMIC64_H)
+       INIT(onestwos);
+       BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
+       r -= one;
+       BUG_ON(v.counter != r);
+
+       INIT(0);
+       BUG_ON(atomic64_dec_if_positive(&v) != -one);
+       BUG_ON(v.counter != r);
+
+       INIT(-one);
+       BUG_ON(atomic64_dec_if_positive(&v) != (-one - one));
+       BUG_ON(v.counter != r);
+#else
+#warning Please implement atomic64_dec_if_positive for your architecture, and add it to the IF above
+#endif
+
+       INIT(onestwos);
+       BUG_ON(!atomic64_inc_not_zero(&v));
+       r += one;
+       BUG_ON(v.counter != r);
+
+       INIT(0);
+       BUG_ON(atomic64_inc_not_zero(&v));
+       BUG_ON(v.counter != r);
+
+       INIT(-one);
+       BUG_ON(!atomic64_inc_not_zero(&v));
+       r += one;
+       BUG_ON(v.counter != r);
+
+#ifdef CONFIG_X86
+       printk(KERN_INFO "atomic64 test passed for %s platform %s CX8 and %s SSE\n",
+#ifdef CONFIG_X86_64
+              "x86-64",
+#elif defined(CONFIG_X86_CMPXCHG64)
+              "i586+",
+#else
+              "i386+",
+#endif
+              boot_cpu_has(X86_FEATURE_CX8) ? "with" : "without",
+              boot_cpu_has(X86_FEATURE_XMM) ? "with" : "without");
+#else
+       printk(KERN_INFO "atomic64 test passed\n");
+#endif
+
+       return 0;
+}
+
+core_initcall(test_atomic64);
index b862b30..deebcc5 100644 (file)
@@ -141,6 +141,7 @@ alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
                obj->object = addr;
                obj->descr  = descr;
                obj->state  = ODEBUG_STATE_NONE;
+               obj->astate = 0;
                hlist_del(&obj->node);
 
                hlist_add_head(&obj->node, &b->list);
@@ -252,8 +253,10 @@ static void debug_print_object(struct debug_obj *obj, char *msg)
 
        if (limit < 5 && obj->descr != descr_test) {
                limit++;
-               WARN(1, KERN_ERR "ODEBUG: %s %s object type: %s\n", msg,
-                      obj_states[obj->state], obj->descr->name);
+               WARN(1, KERN_ERR "ODEBUG: %s %s (active state %u) "
+                                "object type: %s\n",
+                       msg, obj_states[obj->state], obj->astate,
+                       obj->descr->name);
        }
        debug_objects_warnings++;
 }
@@ -447,7 +450,10 @@ void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
                case ODEBUG_STATE_INIT:
                case ODEBUG_STATE_INACTIVE:
                case ODEBUG_STATE_ACTIVE:
-                       obj->state = ODEBUG_STATE_INACTIVE;
+                       if (!obj->astate)
+                               obj->state = ODEBUG_STATE_INACTIVE;
+                       else
+                               debug_print_object(obj, "deactivate");
                        break;
 
                case ODEBUG_STATE_DESTROYED:
@@ -553,6 +559,53 @@ out_unlock:
        raw_spin_unlock_irqrestore(&db->lock, flags);
 }
 
+/**
+ * debug_object_active_state - debug checks object usage state machine
+ * @addr:      address of the object
+ * @descr:     pointer to an object specific debug description structure
+ * @expect:    expected state
+ * @next:      state to move to if expected state is found
+ */
+void
+debug_object_active_state(void *addr, struct debug_obj_descr *descr,
+                         unsigned int expect, unsigned int next)
+{
+       struct debug_bucket *db;
+       struct debug_obj *obj;
+       unsigned long flags;
+
+       if (!debug_objects_enabled)
+               return;
+
+       db = get_bucket((unsigned long) addr);
+
+       raw_spin_lock_irqsave(&db->lock, flags);
+
+       obj = lookup_object(addr, db);
+       if (obj) {
+               switch (obj->state) {
+               case ODEBUG_STATE_ACTIVE:
+                       if (obj->astate == expect)
+                               obj->astate = next;
+                       else
+                               debug_print_object(obj, "active_state");
+                       break;
+
+               default:
+                       debug_print_object(obj, "active_state");
+                       break;
+               }
+       } else {
+               struct debug_obj o = { .object = addr,
+                                      .state = ODEBUG_STATE_NOTAVAILABLE,
+                                      .descr = descr };
+
+               debug_print_object(&o, "active_state");
+       }
+
+       raw_spin_unlock_irqrestore(&db->lock, flags);
+}
+
 #ifdef CONFIG_DEBUG_OBJECTS_FREE
 static void __debug_check_no_obj_freed(const void *address, unsigned long size)
 {
@@ -774,7 +827,7 @@ static int __init fixup_free(void *addr, enum debug_obj_state state)
        }
 }
 
-static int
+static int __init
 check_results(void *addr, enum debug_obj_state state, int fixups, int warnings)
 {
        struct debug_bucket *db;
@@ -917,7 +970,7 @@ void __init debug_objects_early_init(void)
 /*
  * Convert the statically allocated objects to dynamic ones:
  */
-static int debug_objects_replace_static_objects(void)
+static int __init debug_objects_replace_static_objects(void)
 {
        struct debug_bucket *db = obj_hash;
        struct hlist_node *node, *tmp;
index 63ee4eb..3c79d50 100644 (file)
@@ -9,7 +9,7 @@
  * The Hamming Weight of a number is the total number of bits set in it.
  */
 
-unsigned int hweight32(unsigned int w)
+unsigned int __sw_hweight32(unsigned int w)
 {
 #ifdef ARCH_HAS_FAST_MULTIPLIER
        w -= (w >> 1) & 0x55555555;
@@ -24,29 +24,30 @@ unsigned int hweight32(unsigned int w)
        return (res + (res >> 16)) & 0x000000FF;
 #endif
 }
-EXPORT_SYMBOL(hweight32);
+EXPORT_SYMBOL(__sw_hweight32);
 
-unsigned int hweight16(unsigned int w)
+unsigned int __sw_hweight16(unsigned int w)
 {
        unsigned int res = w - ((w >> 1) & 0x5555);
        res = (res & 0x3333) + ((res >> 2) & 0x3333);
        res = (res + (res >> 4)) & 0x0F0F;
        return (res + (res >> 8)) & 0x00FF;
 }
-EXPORT_SYMBOL(hweight16);
+EXPORT_SYMBOL(__sw_hweight16);
 
-unsigned int hweight8(unsigned int w)
+unsigned int __sw_hweight8(unsigned int w)
 {
        unsigned int res = w - ((w >> 1) & 0x55);
        res = (res & 0x33) + ((res >> 2) & 0x33);
        return (res + (res >> 4)) & 0x0F;
 }
-EXPORT_SYMBOL(hweight8);
+EXPORT_SYMBOL(__sw_hweight8);
 
-unsigned long hweight64(__u64 w)
+unsigned long __sw_hweight64(__u64 w)
 {
 #if BITS_PER_LONG == 32
-       return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+       return __sw_hweight32((unsigned int)(w >> 32)) +
+              __sw_hweight32((unsigned int)w);
 #elif BITS_PER_LONG == 64
 #ifdef ARCH_HAS_FAST_MULTIPLIER
        w -= (w >> 1) & 0x5555555555555555ul;
@@ -63,4 +64,4 @@ unsigned long hweight64(__u64 w)
 #endif
 #endif
 }
-EXPORT_SYMBOL(hweight64);
+EXPORT_SYMBOL(__sw_hweight64);
index e2aa3be..15e10b1 100644 (file)
@@ -44,6 +44,11 @@ static void __rb_rotate_left(struct rb_node *node, struct rb_root *root)
        else
                root->rb_node = right;
        rb_set_parent(node, right);
+
+       if (root->augment_cb) {
+               root->augment_cb(node);
+               root->augment_cb(right);
+       }
 }
 
 static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
@@ -67,12 +72,20 @@ static void __rb_rotate_right(struct rb_node *node, struct rb_root *root)
        else
                root->rb_node = left;
        rb_set_parent(node, left);
+
+       if (root->augment_cb) {
+               root->augment_cb(node);
+               root->augment_cb(left);
+       }
 }
 
 void rb_insert_color(struct rb_node *node, struct rb_root *root)
 {
        struct rb_node *parent, *gparent;
 
+       if (root->augment_cb)
+               root->augment_cb(node);
+
        while ((parent = rb_parent(node)) && rb_is_red(parent))
        {
                gparent = rb_parent(parent);
@@ -227,12 +240,15 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
        else
        {
                struct rb_node *old = node, *left;
+               int old_parent_cb = 0;
+               int successor_parent_cb = 0;
 
                node = node->rb_right;
                while ((left = node->rb_left) != NULL)
                        node = left;
 
                if (rb_parent(old)) {
+                       old_parent_cb = 1;
                        if (rb_parent(old)->rb_left == old)
                                rb_parent(old)->rb_left = node;
                        else
@@ -247,8 +263,10 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
                if (parent == old) {
                        parent = node;
                } else {
+                       successor_parent_cb = 1;
                        if (child)
                                rb_set_parent(child, parent);
+
                        parent->rb_left = child;
 
                        node->rb_right = old->rb_right;
@@ -259,6 +277,24 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
                node->rb_left = old->rb_left;
                rb_set_parent(old->rb_left, node);
 
+               if (root->augment_cb) {
+                       /*
+                        * Here, three different nodes can have new children.
+                        * The parent of the successor node that was selected
+                        * to replace the node to be erased.
+                        * The node that is getting erased and is now replaced
+                        * by its successor.
+                        * The parent of the node getting erased-replaced.
+                        */
+                       if (successor_parent_cb)
+                               root->augment_cb(parent);
+
+                       root->augment_cb(node);
+
+                       if (old_parent_cb)
+                               root->augment_cb(rb_parent(old));
+               }
+
                goto color;
        }
 
@@ -267,15 +303,19 @@ void rb_erase(struct rb_node *node, struct rb_root *root)
 
        if (child)
                rb_set_parent(child, parent);
-       if (parent)
-       {
+
+       if (parent) {
                if (parent->rb_left == node)
                        parent->rb_left = child;
                else
                        parent->rb_right = child;
-       }
-       else
+
+               if (root->augment_cb)
+                       root->augment_cb(parent);
+
+       } else {
                root->rb_node = child;
+       }
 
  color:
        if (color == RB_BLACK)
index 8a79a6f..c8569bc 100644 (file)
@@ -1438,7 +1438,7 @@ static void drain_local_stock(struct work_struct *dummy)
 
 /*
  * Cache charges(val) which is from res_counter, to local per_cpu area.
- * This will be consumed by consumt_stock() function, later.
+ * This will be consumed by consume_stock() function, later.
  */
 static void refill_stock(struct mem_cgroup *mem, int val)
 {
index 8f4e2df..3f82720 100644 (file)
@@ -607,44 +607,3 @@ void user_shm_unlock(size_t size, struct user_struct *user)
        spin_unlock(&shmlock_user_lock);
        free_uid(user);
 }
-
-int account_locked_memory(struct mm_struct *mm, struct rlimit *rlim,
-                         size_t size)
-{
-       unsigned long lim, vm, pgsz;
-       int error = -ENOMEM;
-
-       pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;
-
-       down_write(&mm->mmap_sem);
-
-       lim = ACCESS_ONCE(rlim[RLIMIT_AS].rlim_cur) >> PAGE_SHIFT;
-       vm   = mm->total_vm + pgsz;
-       if (lim < vm)
-               goto out;
-
-       lim = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur) >> PAGE_SHIFT;
-       vm   = mm->locked_vm + pgsz;
-       if (lim < vm)
-               goto out;
-
-       mm->total_vm  += pgsz;
-       mm->locked_vm += pgsz;
-
-       error = 0;
- out:
-       up_write(&mm->mmap_sem);
-       return error;
-}
-
-void refund_locked_memory(struct mm_struct *mm, size_t size)
-{
-       unsigned long pgsz = PAGE_ALIGN(size) >> PAGE_SHIFT;
-
-       down_write(&mm->mmap_sem);
-
-       mm->total_vm  -= pgsz;
-       mm->locked_vm -= pgsz;
-
-       up_write(&mm->mmap_sem);
-}
index d03c946..a6326c7 100644 (file)
@@ -2579,7 +2579,7 @@ static int default_zonelist_order(void)
        struct zone *z;
        int average_size;
        /*
-         * ZONE_DMA and ZONE_DMA32 can be very small area in the sytem.
+         * ZONE_DMA and ZONE_DMA32 can be very small area in the system.
         * If they are really small and used heavily, the system can fall
         * into OOM very easily.
         * This function detect ZONE_DMA/DMA32 size and confgigures zone order.
diff --git a/mm/percpu-km.c b/mm/percpu-km.c
new file mode 100644 (file)
index 0000000..df68085
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * mm/percpu-km.c - kernel memory based chunk allocation
+ *
+ * Copyright (C) 2010          SUSE Linux Products GmbH
+ * Copyright (C) 2010          Tejun Heo <tj@kernel.org>
+ *
+ * This file is released under the GPLv2.
+ *
+ * Chunks are allocated as a contiguous kernel memory using gfp
+ * allocation.  This is to be used on nommu architectures.
+ *
+ * To use percpu-km,
+ *
+ * - define CONFIG_NEED_PER_CPU_KM from the arch Kconfig.
+ *
+ * - CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK must not be defined.  It's
+ *   not compatible with PER_CPU_KM.  EMBED_FIRST_CHUNK should work
+ *   fine.
+ *
+ * - NUMA is not supported.  When setting up the first chunk,
+ *   @cpu_distance_fn should be NULL or report all CPUs to be nearer
+ *   than or at LOCAL_DISTANCE.
+ *
+ * - It's best if the chunk size is power of two multiple of
+ *   PAGE_SIZE.  Because each chunk is allocated as a contiguous
+ *   kernel memory block using alloc_pages(), memory will be wasted if
+ *   chunk size is not aligned.  percpu-km code will whine about it.
+ */
+
+#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
+#error "contiguous percpu allocation is incompatible with paged first chunk"
+#endif
+
+#include <linux/log2.h>
+
+static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
+{
+       /* noop */
+       return 0;
+}
+
+static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
+{
+       /* nada */
+}
+
+static struct pcpu_chunk *pcpu_create_chunk(void)
+{
+       const int nr_pages = pcpu_group_sizes[0] >> PAGE_SHIFT;
+       struct pcpu_chunk *chunk;
+       struct page *pages;
+       int i;
+
+       chunk = pcpu_alloc_chunk();
+       if (!chunk)
+               return NULL;
+
+       pages = alloc_pages(GFP_KERNEL, order_base_2(nr_pages));
+       if (!pages) {
+               pcpu_free_chunk(chunk);
+               return NULL;
+       }
+
+       for (i = 0; i < nr_pages; i++)
+               pcpu_set_page_chunk(nth_page(pages, i), chunk);
+
+       chunk->data = pages;
+       chunk->base_addr = page_address(pages) - pcpu_group_offsets[0];
+       return chunk;
+}
+
+static void pcpu_destroy_chunk(struct pcpu_chunk *chunk)
+{
+       const int nr_pages = pcpu_group_sizes[0] >> PAGE_SHIFT;
+
+       if (chunk && chunk->data)
+               __free_pages(chunk->data, order_base_2(nr_pages));
+       pcpu_free_chunk(chunk);
+}
+
+static struct page *pcpu_addr_to_page(void *addr)
+{
+       return virt_to_page(addr);
+}
+
+static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai)
+{
+       size_t nr_pages, alloc_pages;
+
+       /* all units must be in a single group */
+       if (ai->nr_groups != 1) {
+               printk(KERN_CRIT "percpu: can't handle more than one groups\n");
+               return -EINVAL;
+       }
+
+       nr_pages = (ai->groups[0].nr_units * ai->unit_size) >> PAGE_SHIFT;
+       alloc_pages = roundup_pow_of_two(nr_pages);
+
+       if (alloc_pages > nr_pages)
+               printk(KERN_WARNING "percpu: wasting %zu pages per chunk\n",
+                      alloc_pages - nr_pages);
+
+       return 0;
+}
diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c
new file mode 100644 (file)
index 0000000..7d9c1d0
--- /dev/null
@@ -0,0 +1,451 @@
+/*
+ * mm/percpu-vm.c - vmalloc area based chunk allocation
+ *
+ * Copyright (C) 2010          SUSE Linux Products GmbH
+ * Copyright (C) 2010          Tejun Heo <tj@kernel.org>
+ *
+ * This file is released under the GPLv2.
+ *
+ * Chunks are mapped into vmalloc areas and populated page by page.
+ * This is the default chunk allocator.
+ */
+
+static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
+                                   unsigned int cpu, int page_idx)
+{
+       /* must not be used on pre-mapped chunk */
+       WARN_ON(chunk->immutable);
+
+       return vmalloc_to_page((void *)pcpu_chunk_addr(chunk, cpu, page_idx));
+}
+
+/**
+ * pcpu_get_pages_and_bitmap - get temp pages array and bitmap
+ * @chunk: chunk of interest
+ * @bitmapp: output parameter for bitmap
+ * @may_alloc: may allocate the array
+ *
+ * Returns pointer to array of pointers to struct page and bitmap,
+ * both of which can be indexed with pcpu_page_idx().  The returned
+ * array is cleared to zero and *@bitmapp is copied from
+ * @chunk->populated.  Note that there is only one array and bitmap
+ * and access exclusion is the caller's responsibility.
+ *
+ * CONTEXT:
+ * pcpu_alloc_mutex and does GFP_KERNEL allocation if @may_alloc.
+ * Otherwise, don't care.
+ *
+ * RETURNS:
+ * Pointer to temp pages array on success, NULL on failure.
+ */
+static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk,
+                                              unsigned long **bitmapp,
+                                              bool may_alloc)
+{
+       static struct page **pages;
+       static unsigned long *bitmap;
+       size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]);
+       size_t bitmap_size = BITS_TO_LONGS(pcpu_unit_pages) *
+                            sizeof(unsigned long);
+
+       if (!pages || !bitmap) {
+               if (may_alloc && !pages)
+                       pages = pcpu_mem_alloc(pages_size);
+               if (may_alloc && !bitmap)
+                       bitmap = pcpu_mem_alloc(bitmap_size);
+               if (!pages || !bitmap)
+                       return NULL;
+       }
+
+       memset(pages, 0, pages_size);
+       bitmap_copy(bitmap, chunk->populated, pcpu_unit_pages);
+
+       *bitmapp = bitmap;
+       return pages;
+}
+
+/**
+ * pcpu_free_pages - free pages which were allocated for @chunk
+ * @chunk: chunk pages were allocated for
+ * @pages: array of pages to be freed, indexed by pcpu_page_idx()
+ * @populated: populated bitmap
+ * @page_start: page index of the first page to be freed
+ * @page_end: page index of the last page to be freed + 1
+ *
+ * Free pages [@page_start and @page_end) in @pages for all units.
+ * The pages were allocated for @chunk.
+ */
+static void pcpu_free_pages(struct pcpu_chunk *chunk,
+                           struct page **pages, unsigned long *populated,
+                           int page_start, int page_end)
+{
+       unsigned int cpu;
+       int i;
+
+       for_each_possible_cpu(cpu) {
+               for (i = page_start; i < page_end; i++) {
+                       struct page *page = pages[pcpu_page_idx(cpu, i)];
+
+                       if (page)
+                               __free_page(page);
+               }
+       }
+}
+
+/**
+ * pcpu_alloc_pages - allocates pages for @chunk
+ * @chunk: target chunk
+ * @pages: array to put the allocated pages into, indexed by pcpu_page_idx()
+ * @populated: populated bitmap
+ * @page_start: page index of the first page to be allocated
+ * @page_end: page index of the last page to be allocated + 1
+ *
+ * Allocate pages [@page_start,@page_end) into @pages for all units.
+ * The allocation is for @chunk.  Percpu core doesn't care about the
+ * content of @pages and will pass it verbatim to pcpu_map_pages().
+ */
+static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
+                           struct page **pages, unsigned long *populated,
+                           int page_start, int page_end)
+{
+       const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_COLD;
+       unsigned int cpu;
+       int i;
+
+       for_each_possible_cpu(cpu) {
+               for (i = page_start; i < page_end; i++) {
+                       struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
+
+                       *pagep = alloc_pages_node(cpu_to_node(cpu), gfp, 0);
+                       if (!*pagep) {
+                               pcpu_free_pages(chunk, pages, populated,
+                                               page_start, page_end);
+                               return -ENOMEM;
+                       }
+               }
+       }
+       return 0;
+}
+
+/**
+ * pcpu_pre_unmap_flush - flush cache prior to unmapping
+ * @chunk: chunk the regions to be flushed belongs to
+ * @page_start: page index of the first page to be flushed
+ * @page_end: page index of the last page to be flushed + 1
+ *
+ * Pages in [@page_start,@page_end) of @chunk are about to be
+ * unmapped.  Flush cache.  As each flushing trial can be very
+ * expensive, issue flush on the whole region at once rather than
+ * doing it for each cpu.  This could be an overkill but is more
+ * scalable.
+ */
+static void pcpu_pre_unmap_flush(struct pcpu_chunk *chunk,
+                                int page_start, int page_end)
+{
+       flush_cache_vunmap(
+               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
+               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
+}
+
+static void __pcpu_unmap_pages(unsigned long addr, int nr_pages)
+{
+       unmap_kernel_range_noflush(addr, nr_pages << PAGE_SHIFT);
+}
+
+/**
+ * pcpu_unmap_pages - unmap pages out of a pcpu_chunk
+ * @chunk: chunk of interest
+ * @pages: pages array which can be used to pass information to free
+ * @populated: populated bitmap
+ * @page_start: page index of the first page to unmap
+ * @page_end: page index of the last page to unmap + 1
+ *
+ * For each cpu, unmap pages [@page_start,@page_end) out of @chunk.
+ * Corresponding elements in @pages were cleared by the caller and can
+ * be used to carry information to pcpu_free_pages() which will be
+ * called after all unmaps are finished.  The caller should call
+ * proper pre/post flush functions.
+ */
+static void pcpu_unmap_pages(struct pcpu_chunk *chunk,
+                            struct page **pages, unsigned long *populated,
+                            int page_start, int page_end)
+{
+       unsigned int cpu;
+       int i;
+
+       for_each_possible_cpu(cpu) {
+               for (i = page_start; i < page_end; i++) {
+                       struct page *page;
+
+                       page = pcpu_chunk_page(chunk, cpu, i);
+                       WARN_ON(!page);
+                       pages[pcpu_page_idx(cpu, i)] = page;
+               }
+               __pcpu_unmap_pages(pcpu_chunk_addr(chunk, cpu, page_start),
+                                  page_end - page_start);
+       }
+
+       for (i = page_start; i < page_end; i++)
+               __clear_bit(i, populated);
+}
+
+/**
+ * pcpu_post_unmap_tlb_flush - flush TLB after unmapping
+ * @chunk: pcpu_chunk the regions to be flushed belong to
+ * @page_start: page index of the first page to be flushed
+ * @page_end: page index of the last page to be flushed + 1
+ *
+ * Pages [@page_start,@page_end) of @chunk have been unmapped.  Flush
+ * TLB for the regions.  This can be skipped if the area is to be
+ * returned to vmalloc as vmalloc will handle TLB flushing lazily.
+ *
+ * As with pcpu_pre_unmap_flush(), TLB flushing also is done at once
+ * for the whole region.
+ */
+static void pcpu_post_unmap_tlb_flush(struct pcpu_chunk *chunk,
+                                     int page_start, int page_end)
+{
+       flush_tlb_kernel_range(
+               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
+               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
+}
+
+static int __pcpu_map_pages(unsigned long addr, struct page **pages,
+                           int nr_pages)
+{
+       return map_kernel_range_noflush(addr, nr_pages << PAGE_SHIFT,
+                                       PAGE_KERNEL, pages);
+}
+
+/**
+ * pcpu_map_pages - map pages into a pcpu_chunk
+ * @chunk: chunk of interest
+ * @pages: pages array containing pages to be mapped
+ * @populated: populated bitmap
+ * @page_start: page index of the first page to map
+ * @page_end: page index of the last page to map + 1
+ *
+ * For each cpu, map pages [@page_start,@page_end) into @chunk.  The
+ * caller is responsible for calling pcpu_post_map_flush() after all
+ * mappings are complete.
+ *
+ * This function is responsible for setting corresponding bits in
+ * @chunk->populated bitmap and whatever is necessary for reverse
+ * lookup (addr -> chunk).
+ */
+static int pcpu_map_pages(struct pcpu_chunk *chunk,
+                         struct page **pages, unsigned long *populated,
+                         int page_start, int page_end)
+{
+       unsigned int cpu, tcpu;
+       int i, err;
+
+       for_each_possible_cpu(cpu) {
+               err = __pcpu_map_pages(pcpu_chunk_addr(chunk, cpu, page_start),
+                                      &pages[pcpu_page_idx(cpu, page_start)],
+                                      page_end - page_start);
+               if (err < 0)
+                       goto err;
+       }
+
+       /* mapping successful, link chunk and mark populated */
+       for (i = page_start; i < page_end; i++) {
+               for_each_possible_cpu(cpu)
+                       pcpu_set_page_chunk(pages[pcpu_page_idx(cpu, i)],
+                                           chunk);
+               __set_bit(i, populated);
+       }
+
+       return 0;
+
+err:
+       for_each_possible_cpu(tcpu) {
+               if (tcpu == cpu)
+                       break;
+               __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
+                                  page_end - page_start);
+       }
+       return err;
+}
+
+/**
+ * pcpu_post_map_flush - flush cache after mapping
+ * @chunk: pcpu_chunk the regions to be flushed belong to
+ * @page_start: page index of the first page to be flushed
+ * @page_end: page index of the last page to be flushed + 1
+ *
+ * Pages [@page_start,@page_end) of @chunk have been mapped.  Flush
+ * cache.
+ *
+ * As with pcpu_pre_unmap_flush(), TLB flushing also is done at once
+ * for the whole region.
+ */
+static void pcpu_post_map_flush(struct pcpu_chunk *chunk,
+                               int page_start, int page_end)
+{
+       flush_cache_vmap(
+               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
+               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
+}
+
+/**
+ * pcpu_populate_chunk - populate and map an area of a pcpu_chunk
+ * @chunk: chunk of interest
+ * @off: offset to the area to populate
+ * @size: size of the area to populate in bytes
+ *
+ * For each cpu, populate and map pages [@page_start,@page_end) into
+ * @chunk.  The area is cleared on return.
+ *
+ * CONTEXT:
+ * pcpu_alloc_mutex, does GFP_KERNEL allocation.
+ */
+static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
+{
+       int page_start = PFN_DOWN(off);
+       int page_end = PFN_UP(off + size);
+       int free_end = page_start, unmap_end = page_start;
+       struct page **pages;
+       unsigned long *populated;
+       unsigned int cpu;
+       int rs, re, rc;
+
+       /* quick path, check whether all pages are already there */
+       rs = page_start;
+       pcpu_next_pop(chunk, &rs, &re, page_end);
+       if (rs == page_start && re == page_end)
+               goto clear;
+
+       /* need to allocate and map pages, this chunk can't be immutable */
+       WARN_ON(chunk->immutable);
+
+       pages = pcpu_get_pages_and_bitmap(chunk, &populated, true);
+       if (!pages)
+               return -ENOMEM;
+
+       /* alloc and map */
+       pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
+               rc = pcpu_alloc_pages(chunk, pages, populated, rs, re);
+               if (rc)
+                       goto err_free;
+               free_end = re;
+       }
+
+       pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
+               rc = pcpu_map_pages(chunk, pages, populated, rs, re);
+               if (rc)
+                       goto err_unmap;
+               unmap_end = re;
+       }
+       pcpu_post_map_flush(chunk, page_start, page_end);
+
+       /* commit new bitmap */
+       bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
+clear:
+       for_each_possible_cpu(cpu)
+               memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
+       return 0;
+
+err_unmap:
+       pcpu_pre_unmap_flush(chunk, page_start, unmap_end);
+       pcpu_for_each_unpop_region(chunk, rs, re, page_start, unmap_end)
+               pcpu_unmap_pages(chunk, pages, populated, rs, re);
+       pcpu_post_unmap_tlb_flush(chunk, page_start, unmap_end);
+err_free:
+       pcpu_for_each_unpop_region(chunk, rs, re, page_start, free_end)
+               pcpu_free_pages(chunk, pages, populated, rs, re);
+       return rc;
+}
+
+/**
+ * pcpu_depopulate_chunk - depopulate and unmap an area of a pcpu_chunk
+ * @chunk: chunk to depopulate
+ * @off: offset to the area to depopulate
+ * @size: size of the area to depopulate in bytes
+ * @flush: whether to flush cache and tlb or not
+ *
+ * For each cpu, depopulate and unmap pages [@page_start,@page_end)
+ * from @chunk.  If @flush is true, vcache is flushed before unmapping
+ * and tlb after.
+ *
+ * CONTEXT:
+ * pcpu_alloc_mutex.
+ */
+static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
+{
+       int page_start = PFN_DOWN(off);
+       int page_end = PFN_UP(off + size);
+       struct page **pages;
+       unsigned long *populated;
+       int rs, re;
+
+       /* quick path, check whether it's empty already */
+       rs = page_start;
+       pcpu_next_unpop(chunk, &rs, &re, page_end);
+       if (rs == page_start && re == page_end)
+               return;
+
+       /* immutable chunks can't be depopulated */
+       WARN_ON(chunk->immutable);
+
+       /*
+        * If control reaches here, there must have been at least one
+        * successful population attempt so the temp pages array must
+        * be available now.
+        */
+       pages = pcpu_get_pages_and_bitmap(chunk, &populated, false);
+       BUG_ON(!pages);
+
+       /* unmap and free */
+       pcpu_pre_unmap_flush(chunk, page_start, page_end);
+
+       pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
+               pcpu_unmap_pages(chunk, pages, populated, rs, re);
+
+       /* no need to flush tlb, vmalloc will handle it lazily */
+
+       pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
+               pcpu_free_pages(chunk, pages, populated, rs, re);
+
+       /* commit new bitmap */
+       bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
+}
+
+static struct pcpu_chunk *pcpu_create_chunk(void)
+{
+       struct pcpu_chunk *chunk;
+       struct vm_struct **vms;
+
+       chunk = pcpu_alloc_chunk();
+       if (!chunk)
+               return NULL;
+
+       vms = pcpu_get_vm_areas(pcpu_group_offsets, pcpu_group_sizes,
+                               pcpu_nr_groups, pcpu_atom_size, GFP_KERNEL);
+       if (!vms) {
+               pcpu_free_chunk(chunk);
+               return NULL;
+       }
+
+       chunk->data = vms;
+       chunk->base_addr = vms[0]->addr - pcpu_group_offsets[0];
+       return chunk;
+}
+
+static void pcpu_destroy_chunk(struct pcpu_chunk *chunk)
+{
+       if (chunk && chunk->data)
+               pcpu_free_vm_areas(chunk->data, pcpu_nr_groups);
+       pcpu_free_chunk(chunk);
+}
+
+static struct page *pcpu_addr_to_page(void *addr)
+{
+       return vmalloc_to_page(addr);
+}
+
+static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai)
+{
+       /* no extra restriction */
+       return 0;
+}
index 6e09741..39f7dfd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * linux/mm/percpu.c - percpu memory allocator
+ * mm/percpu.c - percpu memory allocator
  *
  * Copyright (C) 2009          SUSE Linux Products GmbH
  * Copyright (C) 2009          Tejun Heo <tj@kernel.org>
@@ -7,14 +7,13 @@
  * This file is released under the GPLv2.
  *
  * This is percpu allocator which can handle both static and dynamic
- * areas.  Percpu areas are allocated in chunks in vmalloc area.  Each
- * chunk is consisted of boot-time determined number of units and the
- * first chunk is used for static percpu variables in the kernel image
+ * areas.  Percpu areas are allocated in chunks.  Each chunk is
+ * consisted of boot-time determined number of units and the first
+ * chunk is used for static percpu variables in the kernel image
  * (special boot time alloc/init handling necessary as these areas
  * need to be brought up before allocation services are running).
  * Unit grows as necessary and all units grow or shrink in unison.
- * When a chunk is filled up, another chunk is allocated.  ie. in
- * vmalloc area
+ * When a chunk is filled up, another chunk is allocated.
  *
  *  c0                           c1                         c2
  *  -------------------          -------------------        ------------
@@ -99,7 +98,7 @@ struct pcpu_chunk {
        int                     map_used;       /* # of map entries used */
        int                     map_alloc;      /* # of map entries allocated */
        int                     *map;           /* allocation map */
-       struct vm_struct        **vms;          /* mapped vmalloc regions */
+       void                    *data;          /* chunk data */
        bool                    immutable;      /* no [de]population allowed */
        unsigned long           populated[];    /* populated bitmap */
 };
@@ -177,6 +176,21 @@ static struct list_head *pcpu_slot __read_mostly; /* chunk list slots */
 static void pcpu_reclaim(struct work_struct *work);
 static DECLARE_WORK(pcpu_reclaim_work, pcpu_reclaim);
 
+static bool pcpu_addr_in_first_chunk(void *addr)
+{
+       void *first_start = pcpu_first_chunk->base_addr;
+
+       return addr >= first_start && addr < first_start + pcpu_unit_size;
+}
+
+static bool pcpu_addr_in_reserved_chunk(void *addr)
+{
+       void *first_start = pcpu_first_chunk->base_addr;
+
+       return addr >= first_start &&
+               addr < first_start + pcpu_reserved_chunk_limit;
+}
+
 static int __pcpu_size_to_slot(int size)
 {
        int highbit = fls(size);        /* size is in bytes */
@@ -198,27 +212,6 @@ static int pcpu_chunk_slot(const struct pcpu_chunk *chunk)
        return pcpu_size_to_slot(chunk->free_size);
 }
 
-static int pcpu_page_idx(unsigned int cpu, int page_idx)
-{
-       return pcpu_unit_map[cpu] * pcpu_unit_pages + page_idx;
-}
-
-static unsigned long pcpu_chunk_addr(struct pcpu_chunk *chunk,
-                                    unsigned int cpu, int page_idx)
-{
-       return (unsigned long)chunk->base_addr + pcpu_unit_offsets[cpu] +
-               (page_idx << PAGE_SHIFT);
-}
-
-static struct page *pcpu_chunk_page(struct pcpu_chunk *chunk,
-                                   unsigned int cpu, int page_idx)
-{
-       /* must not be used on pre-mapped chunk */
-       WARN_ON(chunk->immutable);
-
-       return vmalloc_to_page((void *)pcpu_chunk_addr(chunk, cpu, page_idx));
-}
-
 /* set the pointer to a chunk in a page struct */
 static void pcpu_set_page_chunk(struct page *page, struct pcpu_chunk *pcpu)
 {
@@ -231,13 +224,27 @@ static struct pcpu_chunk *pcpu_get_page_chunk(struct page *page)
        return (struct pcpu_chunk *)page->index;
 }
 
-static void pcpu_next_unpop(struct pcpu_chunk *chunk, int *rs, int *re, int end)
+static int __maybe_unused pcpu_page_idx(unsigned int cpu, int page_idx)
+{
+       return pcpu_unit_map[cpu] * pcpu_unit_pages + page_idx;
+}
+
+static unsigned long __maybe_unused pcpu_chunk_addr(struct pcpu_chunk *chunk,
+                                               unsigned int cpu, int page_idx)
+{
+       return (unsigned long)chunk->base_addr + pcpu_unit_offsets[cpu] +
+               (page_idx << PAGE_SHIFT);
+}
+
+static void __maybe_unused pcpu_next_unpop(struct pcpu_chunk *chunk,
+                                          int *rs, int *re, int end)
 {
        *rs = find_next_zero_bit(chunk->populated, end, *rs);
        *re = find_next_bit(chunk->populated, end, *rs + 1);
 }
 
-static void pcpu_next_pop(struct pcpu_chunk *chunk, int *rs, int *re, int end)
+static void __maybe_unused pcpu_next_pop(struct pcpu_chunk *chunk,
+                                        int *rs, int *re, int end)
 {
        *rs = find_next_bit(chunk->populated, end, *rs);
        *re = find_next_zero_bit(chunk->populated, end, *rs + 1);
@@ -325,36 +332,6 @@ static void pcpu_chunk_relocate(struct pcpu_chunk *chunk, int oslot)
        }
 }
 
-/**
- * pcpu_chunk_addr_search - determine chunk containing specified address
- * @addr: address for which the chunk needs to be determined.
- *
- * RETURNS:
- * The address of the found chunk.
- */
-static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr)
-{
-       void *first_start = pcpu_first_chunk->base_addr;
-
-       /* is it in the first chunk? */
-       if (addr >= first_start && addr < first_start + pcpu_unit_size) {
-               /* is it in the reserved area? */
-               if (addr < first_start + pcpu_reserved_chunk_limit)
-                       return pcpu_reserved_chunk;
-               return pcpu_first_chunk;
-       }
-
-       /*
-        * The address is relative to unit0 which might be unused and
-        * thus unmapped.  Offset the address to the unit space of the
-        * current processor before looking it up in the vmalloc
-        * space.  Note that any possible cpu id can be used here, so
-        * there's no need to worry about preemption or cpu hotplug.
-        */
-       addr += pcpu_unit_offsets[raw_smp_processor_id()];
-       return pcpu_get_page_chunk(vmalloc_to_page(addr));
-}
-
 /**
  * pcpu_need_to_extend - determine whether chunk area map needs to be extended
  * @chunk: chunk of interest
@@ -623,434 +600,92 @@ static void pcpu_free_area(struct pcpu_chunk *chunk, int freeme)
        pcpu_chunk_relocate(chunk, oslot);
 }
 
-/**
- * pcpu_get_pages_and_bitmap - get temp pages array and bitmap
- * @chunk: chunk of interest
- * @bitmapp: output parameter for bitmap
- * @may_alloc: may allocate the array
- *
- * Returns pointer to array of pointers to struct page and bitmap,
- * both of which can be indexed with pcpu_page_idx().  The returned
- * array is cleared to zero and *@bitmapp is copied from
- * @chunk->populated.  Note that there is only one array and bitmap
- * and access exclusion is the caller's responsibility.
- *
- * CONTEXT:
- * pcpu_alloc_mutex and does GFP_KERNEL allocation if @may_alloc.
- * Otherwise, don't care.
- *
- * RETURNS:
- * Pointer to temp pages array on success, NULL on failure.
- */
-static struct page **pcpu_get_pages_and_bitmap(struct pcpu_chunk *chunk,
-                                              unsigned long **bitmapp,
-                                              bool may_alloc)
-{
-       static struct page **pages;
-       static unsigned long *bitmap;
-       size_t pages_size = pcpu_nr_units * pcpu_unit_pages * sizeof(pages[0]);
-       size_t bitmap_size = BITS_TO_LONGS(pcpu_unit_pages) *
-                            sizeof(unsigned long);
-
-       if (!pages || !bitmap) {
-               if (may_alloc && !pages)
-                       pages = pcpu_mem_alloc(pages_size);
-               if (may_alloc && !bitmap)
-                       bitmap = pcpu_mem_alloc(bitmap_size);
-               if (!pages || !bitmap)
-                       return NULL;
-       }
-
-       memset(pages, 0, pages_size);
-       bitmap_copy(bitmap, chunk->populated, pcpu_unit_pages);
-
-       *bitmapp = bitmap;
-       return pages;
-}
-
-/**
- * pcpu_free_pages - free pages which were allocated for @chunk
- * @chunk: chunk pages were allocated for
- * @pages: array of pages to be freed, indexed by pcpu_page_idx()
- * @populated: populated bitmap
- * @page_start: page index of the first page to be freed
- * @page_end: page index of the last page to be freed + 1
- *
- * Free pages [@page_start and @page_end) in @pages for all units.
- * The pages were allocated for @chunk.
- */
-static void pcpu_free_pages(struct pcpu_chunk *chunk,
-                           struct page **pages, unsigned long *populated,
-                           int page_start, int page_end)
+static struct pcpu_chunk *pcpu_alloc_chunk(void)
 {
-       unsigned int cpu;
-       int i;
+       struct pcpu_chunk *chunk;
 
-       for_each_possible_cpu(cpu) {
-               for (i = page_start; i < page_end; i++) {
-                       struct page *page = pages[pcpu_page_idx(cpu, i)];
+       chunk = kzalloc(pcpu_chunk_struct_size, GFP_KERNEL);
+       if (!chunk)
+               return NULL;
 
-                       if (page)
-                               __free_page(page);
-               }
+       chunk->map = pcpu_mem_alloc(PCPU_DFL_MAP_ALLOC * sizeof(chunk->map[0]));
+       if (!chunk->map) {
+               kfree(chunk);
+               return NULL;
        }
-}
 
-/**
- * pcpu_alloc_pages - allocates pages for @chunk
- * @chunk: target chunk
- * @pages: array to put the allocated pages into, indexed by pcpu_page_idx()
- * @populated: populated bitmap
- * @page_start: page index of the first page to be allocated
- * @page_end: page index of the last page to be allocated + 1
- *
- * Allocate pages [@page_start,@page_end) into @pages for all units.
- * The allocation is for @chunk.  Percpu core doesn't care about the
- * content of @pages and will pass it verbatim to pcpu_map_pages().
- */
-static int pcpu_alloc_pages(struct pcpu_chunk *chunk,
-                           struct page **pages, unsigned long *populated,
-                           int page_start, int page_end)
-{
-       const gfp_t gfp = GFP_KERNEL | __GFP_HIGHMEM | __GFP_COLD;
-       unsigned int cpu;
-       int i;
+       chunk->map_alloc = PCPU_DFL_MAP_ALLOC;
+       chunk->map[chunk->map_used++] = pcpu_unit_size;
 
-       for_each_possible_cpu(cpu) {
-               for (i = page_start; i < page_end; i++) {
-                       struct page **pagep = &pages[pcpu_page_idx(cpu, i)];
-
-                       *pagep = alloc_pages_node(cpu_to_node(cpu), gfp, 0);
-                       if (!*pagep) {
-                               pcpu_free_pages(chunk, pages, populated,
-                                               page_start, page_end);
-                               return -ENOMEM;
-                       }
-               }
-       }
-       return 0;
-}
+       INIT_LIST_HEAD(&chunk->list);
+       chunk->free_size = pcpu_unit_size;
+       chunk->contig_hint = pcpu_unit_size;
 
-/**
- * pcpu_pre_unmap_flush - flush cache prior to unmapping
- * @chunk: chunk the regions to be flushed belongs to
- * @page_start: page index of the first page to be flushed
- * @page_end: page index of the last page to be flushed + 1
- *
- * Pages in [@page_start,@page_end) of @chunk are about to be
- * unmapped.  Flush cache.  As each flushing trial can be very
- * expensive, issue flush on the whole region at once rather than
- * doing it for each cpu.  This could be an overkill but is more
- * scalable.
- */
-static void pcpu_pre_unmap_flush(struct pcpu_chunk *chunk,
-                                int page_start, int page_end)
-{
-       flush_cache_vunmap(
-               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
-               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
+       return chunk;
 }
 
-static void __pcpu_unmap_pages(unsigned long addr, int nr_pages)
+static void pcpu_free_chunk(struct pcpu_chunk *chunk)
 {
-       unmap_kernel_range_noflush(addr, nr_pages << PAGE_SHIFT);
+       if (!chunk)
+               return;
+       pcpu_mem_free(chunk->map, chunk->map_alloc * sizeof(chunk->map[0]));
+       kfree(chunk);
 }
 
-/**
- * pcpu_unmap_pages - unmap pages out of a pcpu_chunk
- * @chunk: chunk of interest
- * @pages: pages array which can be used to pass information to free
- * @populated: populated bitmap
- * @page_start: page index of the first page to unmap
- * @page_end: page index of the last page to unmap + 1
- *
- * For each cpu, unmap pages [@page_start,@page_end) out of @chunk.
- * Corresponding elements in @pages were cleared by the caller and can
- * be used to carry information to pcpu_free_pages() which will be
- * called after all unmaps are finished.  The caller should call
- * proper pre/post flush functions.
+/*
+ * Chunk management implementation.
+ *
+ * To allow different implementations, chunk alloc/free and
+ * [de]population are implemented in a separate file which is pulled
+ * into this file and compiled together.  The following functions
+ * should be implemented.
+ *
+ * pcpu_populate_chunk         - populate the specified range of a chunk
+ * pcpu_depopulate_chunk       - depopulate the specified range of a chunk
+ * pcpu_create_chunk           - create a new chunk
+ * pcpu_destroy_chunk          - destroy a chunk, always preceded by full depop
+ * pcpu_addr_to_page           - translate address to physical address
+ * pcpu_verify_alloc_info      - check alloc_info is acceptable during init
  */
-static void pcpu_unmap_pages(struct pcpu_chunk *chunk,
-                            struct page **pages, unsigned long *populated,
-                            int page_start, int page_end)
-{
-       unsigned int cpu;
-       int i;
-
-       for_each_possible_cpu(cpu) {
-               for (i = page_start; i < page_end; i++) {
-                       struct page *page;
-
-                       page = pcpu_chunk_page(chunk, cpu, i);
-                       WARN_ON(!page);
-                       pages[pcpu_page_idx(cpu, i)] = page;
-               }
-               __pcpu_unmap_pages(pcpu_chunk_addr(chunk, cpu, page_start),
-                                  page_end - page_start);
-       }
-
-       for (i = page_start; i < page_end; i++)
-               __clear_bit(i, populated);
-}
+static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size);
+static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size);
+static struct pcpu_chunk *pcpu_create_chunk(void);
+static void pcpu_destroy_chunk(struct pcpu_chunk *chunk);
+static struct page *pcpu_addr_to_page(void *addr);
+static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai);
+
+#ifdef CONFIG_NEED_PER_CPU_KM
+#include "percpu-km.c"
+#else
+#include "percpu-vm.c"
+#endif
 
 /**
- * pcpu_post_unmap_tlb_flush - flush TLB after unmapping
- * @chunk: pcpu_chunk the regions to be flushed belong to
- * @page_start: page index of the first page to be flushed
- * @page_end: page index of the last page to be flushed + 1
- *
- * Pages [@page_start,@page_end) of @chunk have been unmapped.  Flush
- * TLB for the regions.  This can be skipped if the area is to be
- * returned to vmalloc as vmalloc will handle TLB flushing lazily.
+ * pcpu_chunk_addr_search - determine chunk containing specified address
+ * @addr: address for which the chunk needs to be determined.
  *
- * As with pcpu_pre_unmap_flush(), TLB flushing also is done at once
- * for the whole region.
- */
-static void pcpu_post_unmap_tlb_flush(struct pcpu_chunk *chunk,
-                                     int page_start, int page_end)
-{
-       flush_tlb_kernel_range(
-               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
-               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
-}
-
-static int __pcpu_map_pages(unsigned long addr, struct page **pages,
-                           int nr_pages)
-{
-       return map_kernel_range_noflush(addr, nr_pages << PAGE_SHIFT,
-                                       PAGE_KERNEL, pages);
-}
-
-/**
- * pcpu_map_pages - map pages into a pcpu_chunk
- * @chunk: chunk of interest
- * @pages: pages array containing pages to be mapped
- * @populated: populated bitmap
- * @page_start: page index of the first page to map
- * @page_end: page index of the last page to map + 1
- *
- * For each cpu, map pages [@page_start,@page_end) into @chunk.  The
- * caller is responsible for calling pcpu_post_map_flush() after all
- * mappings are complete.
- *
- * This function is responsible for setting corresponding bits in
- * @chunk->populated bitmap and whatever is necessary for reverse
- * lookup (addr -> chunk).
+ * RETURNS:
+ * The address of the found chunk.
  */
-static int pcpu_map_pages(struct pcpu_chunk *chunk,
-                         struct page **pages, unsigned long *populated,
-                         int page_start, int page_end)
+static struct pcpu_chunk *pcpu_chunk_addr_search(void *addr)
 {
-       unsigned int cpu, tcpu;
-       int i, err;
-
-       for_each_possible_cpu(cpu) {
-               err = __pcpu_map_pages(pcpu_chunk_addr(chunk, cpu, page_start),
-                                      &pages[pcpu_page_idx(cpu, page_start)],
-                                      page_end - page_start);
-               if (err < 0)
-                       goto err;
-       }
-
-       /* mapping successful, link chunk and mark populated */
-       for (i = page_start; i < page_end; i++) {
-               for_each_possible_cpu(cpu)
-                       pcpu_set_page_chunk(pages[pcpu_page_idx(cpu, i)],
-                                           chunk);
-               __set_bit(i, populated);
-       }
-
-       return 0;
-
-err:
-       for_each_possible_cpu(tcpu) {
-               if (tcpu == cpu)
-                       break;
-               __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start),
-                                  page_end - page_start);
+       /* is it in the first chunk? */
+       if (pcpu_addr_in_first_chunk(addr)) {
+               /* is it in the reserved area? */
+               if (pcpu_addr_in_reserved_chunk(addr))
+                       return pcpu_reserved_chunk;
+               return pcpu_first_chunk;
        }
-       return err;
-}
-
-/**
- * pcpu_post_map_flush - flush cache after mapping
- * @chunk: pcpu_chunk the regions to be flushed belong to
- * @page_start: page index of the first page to be flushed
- * @page_end: page index of the last page to be flushed + 1
- *
- * Pages [@page_start,@page_end) of @chunk have been mapped.  Flush
- * cache.
- *
- * As with pcpu_pre_unmap_flush(), TLB flushing also is done at once
- * for the whole region.
- */
-static void pcpu_post_map_flush(struct pcpu_chunk *chunk,
-                               int page_start, int page_end)
-{
-       flush_cache_vmap(
-               pcpu_chunk_addr(chunk, pcpu_first_unit_cpu, page_start),
-               pcpu_chunk_addr(chunk, pcpu_last_unit_cpu, page_end));
-}
-
-/**
- * pcpu_depopulate_chunk - depopulate and unmap an area of a pcpu_chunk
- * @chunk: chunk to depopulate
- * @off: offset to the area to depopulate
- * @size: size of the area to depopulate in bytes
- * @flush: whether to flush cache and tlb or not
- *
- * For each cpu, depopulate and unmap pages [@page_start,@page_end)
- * from @chunk.  If @flush is true, vcache is flushed before unmapping
- * and tlb after.
- *
- * CONTEXT:
- * pcpu_alloc_mutex.
- */
-static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size)
-{
-       int page_start = PFN_DOWN(off);
-       int page_end = PFN_UP(off + size);
-       struct page **pages;
-       unsigned long *populated;
-       int rs, re;
-
-       /* quick path, check whether it's empty already */
-       rs = page_start;
-       pcpu_next_unpop(chunk, &rs, &re, page_end);
-       if (rs == page_start && re == page_end)
-               return;
-
-       /* immutable chunks can't be depopulated */
-       WARN_ON(chunk->immutable);
 
        /*
-        * If control reaches here, there must have been at least one
-        * successful population attempt so the temp pages array must
-        * be available now.
+        * The address is relative to unit0 which might be unused and
+        * thus unmapped.  Offset the address to the unit space of the
+        * current processor before looking it up in the vmalloc
+        * space.  Note that any possible cpu id can be used here, so
+        * there's no need to worry about preemption or cpu hotplug.
         */
-       pages = pcpu_get_pages_and_bitmap(chunk, &populated, false);
-       BUG_ON(!pages);
-
-       /* unmap and free */
-       pcpu_pre_unmap_flush(chunk, page_start, page_end);
-
-       pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
-               pcpu_unmap_pages(chunk, pages, populated, rs, re);
-
-       /* no need to flush tlb, vmalloc will handle it lazily */
-
-       pcpu_for_each_pop_region(chunk, rs, re, page_start, page_end)
-               pcpu_free_pages(chunk, pages, populated, rs, re);
-
-       /* commit new bitmap */
-       bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
-}
-
-/**
- * pcpu_populate_chunk - populate and map an area of a pcpu_chunk
- * @chunk: chunk of interest
- * @off: offset to the area to populate
- * @size: size of the area to populate in bytes
- *
- * For each cpu, populate and map pages [@page_start,@page_end) into
- * @chunk.  The area is cleared on return.
- *
- * CONTEXT:
- * pcpu_alloc_mutex, does GFP_KERNEL allocation.
- */
-static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size)
-{
-       int page_start = PFN_DOWN(off);
-       int page_end = PFN_UP(off + size);
-       int free_end = page_start, unmap_end = page_start;
-       struct page **pages;
-       unsigned long *populated;
-       unsigned int cpu;
-       int rs, re, rc;
-
-       /* quick path, check whether all pages are already there */
-       rs = page_start;
-       pcpu_next_pop(chunk, &rs, &re, page_end);
-       if (rs == page_start && re == page_end)
-               goto clear;
-
-       /* need to allocate and map pages, this chunk can't be immutable */
-       WARN_ON(chunk->immutable);
-
-       pages = pcpu_get_pages_and_bitmap(chunk, &populated, true);
-       if (!pages)
-               return -ENOMEM;
-
-       /* alloc and map */
-       pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
-               rc = pcpu_alloc_pages(chunk, pages, populated, rs, re);
-               if (rc)
-                       goto err_free;
-               free_end = re;
-       }
-
-       pcpu_for_each_unpop_region(chunk, rs, re, page_start, page_end) {
-               rc = pcpu_map_pages(chunk, pages, populated, rs, re);
-               if (rc)
-                       goto err_unmap;
-               unmap_end = re;
-       }
-       pcpu_post_map_flush(chunk, page_start, page_end);
-
-       /* commit new bitmap */
-       bitmap_copy(chunk->populated, populated, pcpu_unit_pages);
-clear:
-       for_each_possible_cpu(cpu)
-               memset((void *)pcpu_chunk_addr(chunk, cpu, 0) + off, 0, size);
-       return 0;
-
-err_unmap:
-       pcpu_pre_unmap_flush(chunk, page_start, unmap_end);
-       pcpu_for_each_unpop_region(chunk, rs, re, page_start, unmap_end)
-               pcpu_unmap_pages(chunk, pages, populated, rs, re);
-       pcpu_post_unmap_tlb_flush(chunk, page_start, unmap_end);
-err_free:
-       pcpu_for_each_unpop_region(chunk, rs, re, page_start, free_end)
-               pcpu_free_pages(chunk, pages, populated, rs, re);
-       return rc;
-}
-
-static void free_pcpu_chunk(struct pcpu_chunk *chunk)
-{
-       if (!chunk)
-               return;
-       if (chunk->vms)
-               pcpu_free_vm_areas(chunk->vms, pcpu_nr_groups);
-       pcpu_mem_free(chunk->map, chunk->map_alloc * sizeof(chunk->map[0]));
-       kfree(chunk);
-}
-
-static struct pcpu_chunk *alloc_pcpu_chunk(void)
-{
-       struct pcpu_chunk *chunk;
-
-       chunk = kzalloc(pcpu_chunk_struct_size, GFP_KERNEL);
-       if (!chunk)
-               return NULL;
-
-       chunk->map = pcpu_mem_alloc(PCPU_DFL_MAP_ALLOC * sizeof(chunk->map[0]));
-       chunk->map_alloc = PCPU_DFL_MAP_ALLOC;
-       chunk->map[chunk->map_used++] = pcpu_unit_size;
-
-       chunk->vms = pcpu_get_vm_areas(pcpu_group_offsets, pcpu_group_sizes,
-                                      pcpu_nr_groups, pcpu_atom_size,
-                                      GFP_KERNEL);
-       if (!chunk->vms) {
-               free_pcpu_chunk(chunk);
-               return NULL;
-       }
-
-       INIT_LIST_HEAD(&chunk->list);
-       chunk->free_size = pcpu_unit_size;
-       chunk->contig_hint = pcpu_unit_size;
-       chunk->base_addr = chunk->vms[0]->addr - pcpu_group_offsets[0];
-
-       return chunk;
+       addr += pcpu_unit_offsets[raw_smp_processor_id()];
+       return pcpu_get_page_chunk(pcpu_addr_to_page(addr));
 }
 
 /**
@@ -1142,7 +777,7 @@ restart:
        /* hmmm... no space left, create a new chunk */
        spin_unlock_irqrestore(&pcpu_lock, flags);
 
-       chunk = alloc_pcpu_chunk();
+       chunk = pcpu_create_chunk();
        if (!chunk) {
                err = "failed to allocate new chunk";
                goto fail_unlock_mutex;
@@ -1254,7 +889,7 @@ static void pcpu_reclaim(struct work_struct *work)
 
        list_for_each_entry_safe(chunk, next, &todo, list) {
                pcpu_depopulate_chunk(chunk, 0, pcpu_unit_size);
-               free_pcpu_chunk(chunk);
+               pcpu_destroy_chunk(chunk);
        }
 
        mutex_unlock(&pcpu_alloc_mutex);
@@ -1343,11 +978,14 @@ bool is_kernel_percpu_address(unsigned long addr)
  */
 phys_addr_t per_cpu_ptr_to_phys(void *addr)
 {
-       if ((unsigned long)addr < VMALLOC_START ||
-                       (unsigned long)addr >= VMALLOC_END)
-               return __pa(addr);
-       else
-               return page_to_phys(vmalloc_to_page(addr));
+       if (pcpu_addr_in_first_chunk(addr)) {
+               if ((unsigned long)addr < VMALLOC_START ||
+                   (unsigned long)addr >= VMALLOC_END)
+                       return __pa(addr);
+               else
+                       return page_to_phys(vmalloc_to_page(addr));
+       } else
+               return page_to_phys(pcpu_addr_to_page(addr));
 }
 
 static inline size_t pcpu_calc_fc_sizes(size_t static_size,
@@ -1719,6 +1357,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
        PCPU_SETUP_BUG_ON(ai->unit_size < size_sum);
        PCPU_SETUP_BUG_ON(ai->unit_size & ~PAGE_MASK);
        PCPU_SETUP_BUG_ON(ai->unit_size < PCPU_MIN_UNIT_SIZE);
+       PCPU_SETUP_BUG_ON(pcpu_verify_alloc_info(ai) < 0);
 
        /* process group information and build config tables accordingly */
        group_offsets = alloc_bootmem(ai->nr_groups * sizeof(group_offsets[0]));
index ec19a89..82aa9c9 100644 (file)
@@ -22,7 +22,7 @@
  *                                     overflow.
  *      Carlos Picoto           :       PIMv1 Support
  *     Pavlin Ivanov Radoslavov:       PIMv2 Registers must checksum only PIM header
- *                                     Relax this requrement to work with older peers.
+ *                                     Relax this requirement to work with older peers.
  *
  */
 
index 875c8de..88f95e7 100644 (file)
@@ -495,7 +495,7 @@ void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
                s32 beaconint_us;
 
                if (latency < 0)
-                       latency = pm_qos_requirement(PM_QOS_NETWORK_LATENCY);
+                       latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
 
                beaconint_us = ieee80211_tu_to_usec(
                                        found->vif.bss_conf.beacon_int);
index 95afe79..73affb8 100644 (file)
@@ -236,10 +236,15 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
 
        list_for_each_entry_safe(cred, next, &cred_unused, cr_lru) {
 
-               /* Enforce a 60 second garbage collection moratorium */
+               if (nr_to_scan-- == 0)
+                       break;
+               /*
+                * Enforce a 60 second garbage collection moratorium
+                * Note that the cred_unused list must be time-ordered.
+                */
                if (time_in_range(cred->cr_expire, expired, jiffies) &&
                    test_bit(RPCAUTH_CRED_HASHED, &cred->cr_flags) != 0)
-                       continue;
+                       return 0;
 
                list_del_init(&cred->cr_lru);
                number_cred_unused--;
@@ -252,13 +257,10 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
                        get_rpccred(cred);
                        list_add_tail(&cred->cr_lru, free);
                        rpcauth_unhash_cred_locked(cred);
-                       nr_to_scan--;
                }
                spin_unlock(cache_lock);
-               if (nr_to_scan == 0)
-                       break;
        }
-       return nr_to_scan;
+       return (number_cred_unused / 100) * sysctl_vfs_cache_pressure;
 }
 
 /*
@@ -270,11 +272,12 @@ rpcauth_cache_shrinker(int nr_to_scan, gfp_t gfp_mask)
        LIST_HEAD(free);
        int res;
 
+       if ((gfp_mask & GFP_KERNEL) != GFP_KERNEL)
+               return (nr_to_scan == 0) ? 0 : -1;
        if (list_empty(&cred_unused))
                return 0;
        spin_lock(&rpc_credcache_lock);
-       nr_to_scan = rpcauth_prune_expired(&free, nr_to_scan);
-       res = (number_cred_unused / 100) * sysctl_vfs_cache_pressure;
+       res = rpcauth_prune_expired(&free, nr_to_scan);
        spin_unlock(&rpc_credcache_lock);
        rpcauth_destroy_credlist(&free);
        return res;
index 4de8bcf..74a2317 100644 (file)
@@ -10,7 +10,7 @@ auth_rpcgss-objs := auth_gss.o gss_generic_token.o \
 obj-$(CONFIG_RPCSEC_GSS_KRB5) += rpcsec_gss_krb5.o
 
 rpcsec_gss_krb5-objs := gss_krb5_mech.o gss_krb5_seal.o gss_krb5_unseal.o \
-       gss_krb5_seqnum.o gss_krb5_wrap.o gss_krb5_crypto.o
+       gss_krb5_seqnum.o gss_krb5_wrap.o gss_krb5_crypto.o gss_krb5_keys.o
 
 obj-$(CONFIG_RPCSEC_GSS_SPKM3) += rpcsec_gss_spkm3.o
 
index c389ccf..8da2a0e 100644 (file)
@@ -57,11 +57,14 @@ static const struct rpc_authops authgss_ops;
 static const struct rpc_credops gss_credops;
 static const struct rpc_credops gss_nullops;
 
+#define GSS_RETRY_EXPIRED 5
+static unsigned int gss_expired_cred_retry_delay = GSS_RETRY_EXPIRED;
+
 #ifdef RPC_DEBUG
 # define RPCDBG_FACILITY       RPCDBG_AUTH
 #endif
 
-#define GSS_CRED_SLACK         1024
+#define GSS_CRED_SLACK         (RPC_MAX_AUTH_SIZE * 2)
 /* length of a krb5 verifier (48), plus data added before arguments when
  * using integrity (two 4-byte integers): */
 #define GSS_VERF_SLACK         100
@@ -229,7 +232,7 @@ gss_fill_context(const void *p, const void *end, struct gss_cl_ctx *ctx, struct
                p = ERR_PTR(-EFAULT);
                goto err;
        }
-       ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx);
+       ret = gss_import_sec_context(p, seclen, gm, &ctx->gc_gss_ctx, GFP_NOFS);
        if (ret < 0) {
                p = ERR_PTR(ret);
                goto err;
@@ -349,6 +352,24 @@ gss_unhash_msg(struct gss_upcall_msg *gss_msg)
        spin_unlock(&inode->i_lock);
 }
 
+static void
+gss_handle_downcall_result(struct gss_cred *gss_cred, struct gss_upcall_msg *gss_msg)
+{
+       switch (gss_msg->msg.errno) {
+       case 0:
+               if (gss_msg->ctx == NULL)
+                       break;
+               clear_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags);
+               gss_cred_set_ctx(&gss_cred->gc_base, gss_msg->ctx);
+               break;
+       case -EKEYEXPIRED:
+               set_bit(RPCAUTH_CRED_NEGATIVE, &gss_cred->gc_base.cr_flags);
+       }
+       gss_cred->gc_upcall_timestamp = jiffies;
+       gss_cred->gc_upcall = NULL;
+       rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
+}
+
 static void
 gss_upcall_callback(struct rpc_task *task)
 {
@@ -358,13 +379,9 @@ gss_upcall_callback(struct rpc_task *task)
        struct inode *inode = &gss_msg->inode->vfs_inode;
 
        spin_lock(&inode->i_lock);
-       if (gss_msg->ctx)
-               gss_cred_set_ctx(task->tk_msg.rpc_cred, gss_msg->ctx);
-       else
-               task->tk_status = gss_msg->msg.errno;
-       gss_cred->gc_upcall = NULL;
-       rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
+       gss_handle_downcall_result(gss_cred, gss_msg);
        spin_unlock(&inode->i_lock);
+       task->tk_status = gss_msg->msg.errno;
        gss_release_msg(gss_msg);
 }
 
@@ -377,11 +394,12 @@ static void gss_encode_v0_msg(struct gss_upcall_msg *gss_msg)
 static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
                                struct rpc_clnt *clnt, int machine_cred)
 {
+       struct gss_api_mech *mech = gss_msg->auth->mech;
        char *p = gss_msg->databuf;
        int len = 0;
 
        gss_msg->msg.len = sprintf(gss_msg->databuf, "mech=%s uid=%d ",
-                                  gss_msg->auth->mech->gm_name,
+                                  mech->gm_name,
                                   gss_msg->uid);
        p += gss_msg->msg.len;
        if (clnt->cl_principal) {
@@ -398,6 +416,11 @@ static void gss_encode_v1_msg(struct gss_upcall_msg *gss_msg,
                p += len;
                gss_msg->msg.len += len;
        }
+       if (mech->gm_upcall_enctypes) {
+               len = sprintf(p, mech->gm_upcall_enctypes);
+               p += len;
+               gss_msg->msg.len += len;
+       }
        len = sprintf(p, "\n");
        gss_msg->msg.len += len;
 
@@ -507,18 +530,16 @@ gss_refresh_upcall(struct rpc_task *task)
        spin_lock(&inode->i_lock);
        if (gss_cred->gc_upcall != NULL)
                rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL);
-       else if (gss_msg->ctx != NULL) {
-               gss_cred_set_ctx(task->tk_msg.rpc_cred, gss_msg->ctx);
-               gss_cred->gc_upcall = NULL;
-               rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
-       } else if (gss_msg->msg.errno >= 0) {
+       else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) {
                task->tk_timeout = 0;
                gss_cred->gc_upcall = gss_msg;
                /* gss_upcall_callback will release the reference to gss_upcall_msg */
                atomic_inc(&gss_msg->count);
                rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback);
-       } else
+       } else {
+               gss_handle_downcall_result(gss_cred, gss_msg);
                err = gss_msg->msg.errno;
+       }
        spin_unlock(&inode->i_lock);
        gss_release_msg(gss_msg);
 out:
@@ -1117,6 +1138,23 @@ static int gss_renew_cred(struct rpc_task *task)
        return 0;
 }
 
+static int gss_cred_is_negative_entry(struct rpc_cred *cred)
+{
+       if (test_bit(RPCAUTH_CRED_NEGATIVE, &cred->cr_flags)) {
+               unsigned long now = jiffies;
+               unsigned long begin, expire;
+               struct gss_cred *gss_cred; 
+
+               gss_cred = container_of(cred, struct gss_cred, gc_base);
+               begin = gss_cred->gc_upcall_timestamp;
+               expire = begin + gss_expired_cred_retry_delay * HZ;
+
+               if (time_in_range_open(now, begin, expire))
+                       return 1;
+       }
+       return 0;
+}
+
 /*
 * Refresh credentials. XXX - finish
 */
@@ -1126,6 +1164,9 @@ gss_refresh(struct rpc_task *task)
        struct rpc_cred *cred = task->tk_msg.rpc_cred;
        int ret = 0;
 
+       if (gss_cred_is_negative_entry(cred))
+               return -EKEYEXPIRED;
+
        if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) &&
                        !test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags)) {
                ret = gss_renew_cred(task);
@@ -1316,15 +1357,21 @@ gss_wrap_req_priv(struct rpc_cred *cred, struct gss_cl_ctx *ctx,
        inpages = snd_buf->pages + first;
        snd_buf->pages = rqstp->rq_enc_pages;
        snd_buf->page_base -= first << PAGE_CACHE_SHIFT;
-       /* Give the tail its own page, in case we need extra space in the
-        * head when wrapping: */
+       /*
+        * Give the tail its own page, in case we need extra space in the
+        * head when wrapping:
+        *
+        * call_allocate() allocates twice the slack space required
+        * by the authentication flavor to rq_callsize.
+        * For GSS, slack is GSS_CRED_SLACK.
+        */
        if (snd_buf->page_len || snd_buf->tail[0].iov_len) {
                tmp = page_address(rqstp->rq_enc_pages[rqstp->rq_enc_pages_num - 1]);
                memcpy(tmp, snd_buf->tail[0].iov_base, snd_buf->tail[0].iov_len);
                snd_buf->tail[0].iov_base = tmp;
        }
        maj_stat = gss_wrap(ctx->gc_gss_ctx, offset, snd_buf, inpages);
-       /* RPC_SLACK_SPACE should prevent this ever happening: */
+       /* slack space should prevent this ever happening: */
        BUG_ON(snd_buf->len > snd_buf->buflen);
        status = -EIO;
        /* We're assuming that when GSS_S_CONTEXT_EXPIRED, the encryption was
@@ -1573,5 +1620,11 @@ static void __exit exit_rpcsec_gss(void)
 }
 
 MODULE_LICENSE("GPL");
+module_param_named(expired_cred_retry_delay,
+                  gss_expired_cred_retry_delay,
+                  uint, 0644);
+MODULE_PARM_DESC(expired_cred_retry_delay, "Timeout (in seconds) until "
+               "the RPC engine retries an expired credential");
+
 module_init(init_rpcsec_gss)
 module_exit(exit_rpcsec_gss)
index e9b6361..75ee993 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  linux/net/sunrpc/gss_krb5_crypto.c
  *
- *  Copyright (c) 2000 The Regents of the University of Michigan.
+ *  Copyright (c) 2000-2008 The Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  Andy Adamson   <andros@umich.edu>
@@ -41,6 +41,7 @@
 #include <linux/crypto.h>
 #include <linux/highmem.h>
 #include <linux/pagemap.h>
+#include <linux/random.h>
 #include <linux/sunrpc/gss_krb5.h>
 #include <linux/sunrpc/xdr.h>
 
@@ -58,13 +59,13 @@ krb5_encrypt(
 {
        u32 ret = -EINVAL;
        struct scatterlist sg[1];
-       u8 local_iv[16] = {0};
+       u8 local_iv[GSS_KRB5_MAX_BLOCKSIZE] = {0};
        struct blkcipher_desc desc = { .tfm = tfm, .info = local_iv };
 
        if (length % crypto_blkcipher_blocksize(tfm) != 0)
                goto out;
 
-       if (crypto_blkcipher_ivsize(tfm) > 16) {
+       if (crypto_blkcipher_ivsize(tfm) > GSS_KRB5_MAX_BLOCKSIZE) {
                dprintk("RPC:       gss_k5encrypt: tfm iv size too large %d\n",
                        crypto_blkcipher_ivsize(tfm));
                goto out;
@@ -92,13 +93,13 @@ krb5_decrypt(
 {
        u32 ret = -EINVAL;
        struct scatterlist sg[1];
-       u8 local_iv[16] = {0};
+       u8 local_iv[GSS_KRB5_MAX_BLOCKSIZE] = {0};
        struct blkcipher_desc desc = { .tfm = tfm, .info = local_iv };
 
        if (length % crypto_blkcipher_blocksize(tfm) != 0)
                goto out;
 
-       if (crypto_blkcipher_ivsize(tfm) > 16) {
+       if (crypto_blkcipher_ivsize(tfm) > GSS_KRB5_MAX_BLOCKSIZE) {
                dprintk("RPC:       gss_k5decrypt: tfm iv size too large %d\n",
                        crypto_blkcipher_ivsize(tfm));
                goto out;
@@ -123,21 +124,155 @@ checksummer(struct scatterlist *sg, void *data)
        return crypto_hash_update(desc, sg, sg->length);
 }
 
-/* checksum the plaintext data and hdrlen bytes of the token header */
-s32
-make_checksum(char *cksumname, char *header, int hdrlen, struct xdr_buf *body,
-                  int body_offset, struct xdr_netobj *cksum)
+static int
+arcfour_hmac_md5_usage_to_salt(unsigned int usage, u8 salt[4])
+{
+       unsigned int ms_usage;
+
+       switch (usage) {
+       case KG_USAGE_SIGN:
+               ms_usage = 15;
+               break;
+       case KG_USAGE_SEAL:
+               ms_usage = 13;
+               break;
+       default:
+               return EINVAL;;
+       }
+       salt[0] = (ms_usage >> 0) & 0xff;
+       salt[1] = (ms_usage >> 8) & 0xff;
+       salt[2] = (ms_usage >> 16) & 0xff;
+       salt[3] = (ms_usage >> 24) & 0xff;
+
+       return 0;
+}
+
+static u32
+make_checksum_hmac_md5(struct krb5_ctx *kctx, char *header, int hdrlen,
+                      struct xdr_buf *body, int body_offset, u8 *cksumkey,
+                      unsigned int usage, struct xdr_netobj *cksumout)
 {
-       struct hash_desc                desc; /* XXX add to ctx? */
+       struct hash_desc                desc;
        struct scatterlist              sg[1];
        int err;
+       u8 checksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       u8 rc4salt[4];
+       struct crypto_hash *md5;
+       struct crypto_hash *hmac_md5;
+
+       if (cksumkey == NULL)
+               return GSS_S_FAILURE;
+
+       if (cksumout->len < kctx->gk5e->cksumlength) {
+               dprintk("%s: checksum buffer length, %u, too small for %s\n",
+                       __func__, cksumout->len, kctx->gk5e->name);
+               return GSS_S_FAILURE;
+       }
+
+       if (arcfour_hmac_md5_usage_to_salt(usage, rc4salt)) {
+               dprintk("%s: invalid usage value %u\n", __func__, usage);
+               return GSS_S_FAILURE;
+       }
+
+       md5 = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(md5))
+               return GSS_S_FAILURE;
+
+       hmac_md5 = crypto_alloc_hash(kctx->gk5e->cksum_name, 0,
+                                    CRYPTO_ALG_ASYNC);
+       if (IS_ERR(hmac_md5)) {
+               crypto_free_hash(md5);
+               return GSS_S_FAILURE;
+       }
+
+       desc.tfm = md5;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out;
+       sg_init_one(sg, rc4salt, 4);
+       err = crypto_hash_update(&desc, sg, 4);
+       if (err)
+               goto out;
+
+       sg_init_one(sg, header, hdrlen);
+       err = crypto_hash_update(&desc, sg, hdrlen);
+       if (err)
+               goto out;
+       err = xdr_process_buf(body, body_offset, body->len - body_offset,
+                             checksummer, &desc);
+       if (err)
+               goto out;
+       err = crypto_hash_final(&desc, checksumdata);
+       if (err)
+               goto out;
+
+       desc.tfm = hmac_md5;
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out;
+       err = crypto_hash_setkey(hmac_md5, cksumkey, kctx->gk5e->keylength);
+       if (err)
+               goto out;
+
+       sg_init_one(sg, checksumdata, crypto_hash_digestsize(md5));
+       err = crypto_hash_digest(&desc, sg, crypto_hash_digestsize(md5),
+                                checksumdata);
+       if (err)
+               goto out;
+
+       memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
+       cksumout->len = kctx->gk5e->cksumlength;
+out:
+       crypto_free_hash(md5);
+       crypto_free_hash(hmac_md5);
+       return err ? GSS_S_FAILURE : 0;
+}
+
+/*
+ * checksum the plaintext data and hdrlen bytes of the token header
+ * The checksum is performed over the first 8 bytes of the
+ * gss token header and then over the data body
+ */
+u32
+make_checksum(struct krb5_ctx *kctx, char *header, int hdrlen,
+             struct xdr_buf *body, int body_offset, u8 *cksumkey,
+             unsigned int usage, struct xdr_netobj *cksumout)
+{
+       struct hash_desc                desc;
+       struct scatterlist              sg[1];
+       int err;
+       u8 checksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       unsigned int checksumlen;
+
+       if (kctx->gk5e->ctype == CKSUMTYPE_HMAC_MD5_ARCFOUR)
+               return make_checksum_hmac_md5(kctx, header, hdrlen,
+                                             body, body_offset,
+                                             cksumkey, usage, cksumout);
+
+       if (cksumout->len < kctx->gk5e->cksumlength) {
+               dprintk("%s: checksum buffer length, %u, too small for %s\n",
+                       __func__, cksumout->len, kctx->gk5e->name);
+               return GSS_S_FAILURE;
+       }
 
-       desc.tfm = crypto_alloc_hash(cksumname, 0, CRYPTO_ALG_ASYNC);
+       desc.tfm = crypto_alloc_hash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
        if (IS_ERR(desc.tfm))
                return GSS_S_FAILURE;
-       cksum->len = crypto_hash_digestsize(desc.tfm);
        desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
 
+       checksumlen = crypto_hash_digestsize(desc.tfm);
+
+       if (cksumkey != NULL) {
+               err = crypto_hash_setkey(desc.tfm, cksumkey,
+                                        kctx->gk5e->keylength);
+               if (err)
+                       goto out;
+       }
+
        err = crypto_hash_init(&desc);
        if (err)
                goto out;
@@ -149,15 +284,109 @@ make_checksum(char *cksumname, char *header, int hdrlen, struct xdr_buf *body,
                              checksummer, &desc);
        if (err)
                goto out;
-       err = crypto_hash_final(&desc, cksum->data);
+       err = crypto_hash_final(&desc, checksumdata);
+       if (err)
+               goto out;
 
+       switch (kctx->gk5e->ctype) {
+       case CKSUMTYPE_RSA_MD5:
+               err = kctx->gk5e->encrypt(kctx->seq, NULL, checksumdata,
+                                         checksumdata, checksumlen);
+               if (err)
+                       goto out;
+               memcpy(cksumout->data,
+                      checksumdata + checksumlen - kctx->gk5e->cksumlength,
+                      kctx->gk5e->cksumlength);
+               break;
+       case CKSUMTYPE_HMAC_SHA1_DES3:
+               memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
+               break;
+       default:
+               BUG();
+               break;
+       }
+       cksumout->len = kctx->gk5e->cksumlength;
+out:
+       crypto_free_hash(desc.tfm);
+       return err ? GSS_S_FAILURE : 0;
+}
+
+/*
+ * checksum the plaintext data and hdrlen bytes of the token header
+ * Per rfc4121, sec. 4.2.4, the checksum is performed over the data
+ * body then over the first 16 octets of the MIC token
+ * Inclusion of the header data in the calculation of the
+ * checksum is optional.
+ */
+u32
+make_checksum_v2(struct krb5_ctx *kctx, char *header, int hdrlen,
+                struct xdr_buf *body, int body_offset, u8 *cksumkey,
+                unsigned int usage, struct xdr_netobj *cksumout)
+{
+       struct hash_desc desc;
+       struct scatterlist sg[1];
+       int err;
+       u8 checksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       unsigned int checksumlen;
+
+       if (kctx->gk5e->keyed_cksum == 0) {
+               dprintk("%s: expected keyed hash for %s\n",
+                       __func__, kctx->gk5e->name);
+               return GSS_S_FAILURE;
+       }
+       if (cksumkey == NULL) {
+               dprintk("%s: no key supplied for %s\n",
+                       __func__, kctx->gk5e->name);
+               return GSS_S_FAILURE;
+       }
+
+       desc.tfm = crypto_alloc_hash(kctx->gk5e->cksum_name, 0,
+                                                       CRYPTO_ALG_ASYNC);
+       if (IS_ERR(desc.tfm))
+               return GSS_S_FAILURE;
+       checksumlen = crypto_hash_digestsize(desc.tfm);
+       desc.flags = CRYPTO_TFM_REQ_MAY_SLEEP;
+
+       err = crypto_hash_setkey(desc.tfm, cksumkey, kctx->gk5e->keylength);
+       if (err)
+               goto out;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out;
+       err = xdr_process_buf(body, body_offset, body->len - body_offset,
+                             checksummer, &desc);
+       if (err)
+               goto out;
+       if (header != NULL) {
+               sg_init_one(sg, header, hdrlen);
+               err = crypto_hash_update(&desc, sg, hdrlen);
+               if (err)
+                       goto out;
+       }
+       err = crypto_hash_final(&desc, checksumdata);
+       if (err)
+               goto out;
+
+       cksumout->len = kctx->gk5e->cksumlength;
+
+       switch (kctx->gk5e->ctype) {
+       case CKSUMTYPE_HMAC_SHA1_96_AES128:
+       case CKSUMTYPE_HMAC_SHA1_96_AES256:
+               /* note that this truncates the hash */
+               memcpy(cksumout->data, checksumdata, kctx->gk5e->cksumlength);
+               break;
+       default:
+               BUG();
+               break;
+       }
 out:
        crypto_free_hash(desc.tfm);
        return err ? GSS_S_FAILURE : 0;
 }
 
 struct encryptor_desc {
-       u8 iv[8]; /* XXX hard-coded blocksize */
+       u8 iv[GSS_KRB5_MAX_BLOCKSIZE];
        struct blkcipher_desc desc;
        int pos;
        struct xdr_buf *outbuf;
@@ -198,7 +427,7 @@ encryptor(struct scatterlist *sg, void *data)
        desc->fraglen += sg->length;
        desc->pos += sg->length;
 
-       fraglen = thislen & 7; /* XXX hardcoded blocksize */
+       fraglen = thislen & (crypto_blkcipher_blocksize(desc->desc.tfm) - 1);
        thislen -= fraglen;
 
        if (thislen == 0)
@@ -256,7 +485,7 @@ gss_encrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *buf,
 }
 
 struct decryptor_desc {
-       u8 iv[8]; /* XXX hard-coded blocksize */
+       u8 iv[GSS_KRB5_MAX_BLOCKSIZE];
        struct blkcipher_desc desc;
        struct scatterlist frags[4];
        int fragno;
@@ -278,7 +507,7 @@ decryptor(struct scatterlist *sg, void *data)
        desc->fragno++;
        desc->fraglen += sg->length;
 
-       fraglen = thislen & 7; /* XXX hardcoded blocksize */
+       fraglen = thislen & (crypto_blkcipher_blocksize(desc->desc.tfm) - 1);
        thislen -= fraglen;
 
        if (thislen == 0)
@@ -325,3 +554,437 @@ gss_decrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *buf,
 
        return xdr_process_buf(buf, offset, buf->len - offset, decryptor, &desc);
 }
+
+/*
+ * This function makes the assumption that it was ultimately called
+ * from gss_wrap().
+ *
+ * The client auth_gss code moves any existing tail data into a
+ * separate page before calling gss_wrap.
+ * The server svcauth_gss code ensures that both the head and the
+ * tail have slack space of RPC_MAX_AUTH_SIZE before calling gss_wrap.
+ *
+ * Even with that guarantee, this function may be called more than
+ * once in the processing of gss_wrap().  The best we can do is
+ * verify at compile-time (see GSS_KRB5_SLACK_CHECK) that the
+ * largest expected shift will fit within RPC_MAX_AUTH_SIZE.
+ * At run-time we can verify that a single invocation of this
+ * function doesn't attempt to use more the RPC_MAX_AUTH_SIZE.
+ */
+
+int
+xdr_extend_head(struct xdr_buf *buf, unsigned int base, unsigned int shiftlen)
+{
+       u8 *p;
+
+       if (shiftlen == 0)
+               return 0;
+
+       BUILD_BUG_ON(GSS_KRB5_MAX_SLACK_NEEDED > RPC_MAX_AUTH_SIZE);
+       BUG_ON(shiftlen > RPC_MAX_AUTH_SIZE);
+
+       p = buf->head[0].iov_base + base;
+
+       memmove(p + shiftlen, p, buf->head[0].iov_len - base);
+
+       buf->head[0].iov_len += shiftlen;
+       buf->len += shiftlen;
+
+       return 0;
+}
+
+static u32
+gss_krb5_cts_crypt(struct crypto_blkcipher *cipher, struct xdr_buf *buf,
+                  u32 offset, u8 *iv, struct page **pages, int encrypt)
+{
+       u32 ret;
+       struct scatterlist sg[1];
+       struct blkcipher_desc desc = { .tfm = cipher, .info = iv };
+       u8 data[crypto_blkcipher_blocksize(cipher) * 2];
+       struct page **save_pages;
+       u32 len = buf->len - offset;
+
+       BUG_ON(len > crypto_blkcipher_blocksize(cipher) * 2);
+
+       /*
+        * For encryption, we want to read from the cleartext
+        * page cache pages, and write the encrypted data to
+        * the supplied xdr_buf pages.
+        */
+       save_pages = buf->pages;
+       if (encrypt)
+               buf->pages = pages;
+
+       ret = read_bytes_from_xdr_buf(buf, offset, data, len);
+       buf->pages = save_pages;
+       if (ret)
+               goto out;
+
+       sg_init_one(sg, data, len);
+
+       if (encrypt)
+               ret = crypto_blkcipher_encrypt_iv(&desc, sg, sg, len);
+       else
+               ret = crypto_blkcipher_decrypt_iv(&desc, sg, sg, len);
+
+       if (ret)
+               goto out;
+
+       ret = write_bytes_to_xdr_buf(buf, offset, data, len);
+
+out:
+       return ret;
+}
+
+u32
+gss_krb5_aes_encrypt(struct krb5_ctx *kctx, u32 offset,
+                    struct xdr_buf *buf, int ec, struct page **pages)
+{
+       u32 err;
+       struct xdr_netobj hmac;
+       u8 *cksumkey;
+       u8 *ecptr;
+       struct crypto_blkcipher *cipher, *aux_cipher;
+       int blocksize;
+       struct page **save_pages;
+       int nblocks, nbytes;
+       struct encryptor_desc desc;
+       u32 cbcbytes;
+       unsigned int usage;
+
+       if (kctx->initiate) {
+               cipher = kctx->initiator_enc;
+               aux_cipher = kctx->initiator_enc_aux;
+               cksumkey = kctx->initiator_integ;
+               usage = KG_USAGE_INITIATOR_SEAL;
+       } else {
+               cipher = kctx->acceptor_enc;
+               aux_cipher = kctx->acceptor_enc_aux;
+               cksumkey = kctx->acceptor_integ;
+               usage = KG_USAGE_ACCEPTOR_SEAL;
+       }
+       blocksize = crypto_blkcipher_blocksize(cipher);
+
+       /* hide the gss token header and insert the confounder */
+       offset += GSS_KRB5_TOK_HDR_LEN;
+       if (xdr_extend_head(buf, offset, kctx->gk5e->conflen))
+               return GSS_S_FAILURE;
+       gss_krb5_make_confounder(buf->head[0].iov_base + offset, kctx->gk5e->conflen);
+       offset -= GSS_KRB5_TOK_HDR_LEN;
+
+       if (buf->tail[0].iov_base != NULL) {
+               ecptr = buf->tail[0].iov_base + buf->tail[0].iov_len;
+       } else {
+               buf->tail[0].iov_base = buf->head[0].iov_base
+                                                       + buf->head[0].iov_len;
+               buf->tail[0].iov_len = 0;
+               ecptr = buf->tail[0].iov_base;
+       }
+
+       memset(ecptr, 'X', ec);
+       buf->tail[0].iov_len += ec;
+       buf->len += ec;
+
+       /* copy plaintext gss token header after filler (if any) */
+       memcpy(ecptr + ec, buf->head[0].iov_base + offset,
+                                               GSS_KRB5_TOK_HDR_LEN);
+       buf->tail[0].iov_len += GSS_KRB5_TOK_HDR_LEN;
+       buf->len += GSS_KRB5_TOK_HDR_LEN;
+
+       /* Do the HMAC */
+       hmac.len = GSS_KRB5_MAX_CKSUM_LEN;
+       hmac.data = buf->tail[0].iov_base + buf->tail[0].iov_len;
+
+       /*
+        * When we are called, pages points to the real page cache
+        * data -- which we can't go and encrypt!  buf->pages points
+        * to scratch pages which we are going to send off to the
+        * client/server.  Swap in the plaintext pages to calculate
+        * the hmac.
+        */
+       save_pages = buf->pages;
+       buf->pages = pages;
+
+       err = make_checksum_v2(kctx, NULL, 0, buf,
+                              offset + GSS_KRB5_TOK_HDR_LEN,
+                              cksumkey, usage, &hmac);
+       buf->pages = save_pages;
+       if (err)
+               return GSS_S_FAILURE;
+
+       nbytes = buf->len - offset - GSS_KRB5_TOK_HDR_LEN;
+       nblocks = (nbytes + blocksize - 1) / blocksize;
+       cbcbytes = 0;
+       if (nblocks > 2)
+               cbcbytes = (nblocks - 2) * blocksize;
+
+       memset(desc.iv, 0, sizeof(desc.iv));
+
+       if (cbcbytes) {
+               desc.pos = offset + GSS_KRB5_TOK_HDR_LEN;
+               desc.fragno = 0;
+               desc.fraglen = 0;
+               desc.pages = pages;
+               desc.outbuf = buf;
+               desc.desc.info = desc.iv;
+               desc.desc.flags = 0;
+               desc.desc.tfm = aux_cipher;
+
+               sg_init_table(desc.infrags, 4);
+               sg_init_table(desc.outfrags, 4);
+
+               err = xdr_process_buf(buf, offset + GSS_KRB5_TOK_HDR_LEN,
+                                     cbcbytes, encryptor, &desc);
+               if (err)
+                       goto out_err;
+       }
+
+       /* Make sure IV carries forward from any CBC results. */
+       err = gss_krb5_cts_crypt(cipher, buf,
+                                offset + GSS_KRB5_TOK_HDR_LEN + cbcbytes,
+                                desc.iv, pages, 1);
+       if (err) {
+               err = GSS_S_FAILURE;
+               goto out_err;
+       }
+
+       /* Now update buf to account for HMAC */
+       buf->tail[0].iov_len += kctx->gk5e->cksumlength;
+       buf->len += kctx->gk5e->cksumlength;
+
+out_err:
+       if (err)
+               err = GSS_S_FAILURE;
+       return err;
+}
+
+u32
+gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf,
+                    u32 *headskip, u32 *tailskip)
+{
+       struct xdr_buf subbuf;
+       u32 ret = 0;
+       u8 *cksum_key;
+       struct crypto_blkcipher *cipher, *aux_cipher;
+       struct xdr_netobj our_hmac_obj;
+       u8 our_hmac[GSS_KRB5_MAX_CKSUM_LEN];
+       u8 pkt_hmac[GSS_KRB5_MAX_CKSUM_LEN];
+       int nblocks, blocksize, cbcbytes;
+       struct decryptor_desc desc;
+       unsigned int usage;
+
+       if (kctx->initiate) {
+               cipher = kctx->acceptor_enc;
+               aux_cipher = kctx->acceptor_enc_aux;
+               cksum_key = kctx->acceptor_integ;
+               usage = KG_USAGE_ACCEPTOR_SEAL;
+       } else {
+               cipher = kctx->initiator_enc;
+               aux_cipher = kctx->initiator_enc_aux;
+               cksum_key = kctx->initiator_integ;
+               usage = KG_USAGE_INITIATOR_SEAL;
+       }
+       blocksize = crypto_blkcipher_blocksize(cipher);
+
+
+       /* create a segment skipping the header and leaving out the checksum */
+       xdr_buf_subsegment(buf, &subbuf, offset + GSS_KRB5_TOK_HDR_LEN,
+                                   (buf->len - offset - GSS_KRB5_TOK_HDR_LEN -
+                                    kctx->gk5e->cksumlength));
+
+       nblocks = (subbuf.len + blocksize - 1) / blocksize;
+
+       cbcbytes = 0;
+       if (nblocks > 2)
+               cbcbytes = (nblocks - 2) * blocksize;
+
+       memset(desc.iv, 0, sizeof(desc.iv));
+
+       if (cbcbytes) {
+               desc.fragno = 0;
+               desc.fraglen = 0;
+               desc.desc.info = desc.iv;
+               desc.desc.flags = 0;
+               desc.desc.tfm = aux_cipher;
+
+               sg_init_table(desc.frags, 4);
+
+               ret = xdr_process_buf(&subbuf, 0, cbcbytes, decryptor, &desc);
+               if (ret)
+                       goto out_err;
+       }
+
+       /* Make sure IV carries forward from any CBC results. */
+       ret = gss_krb5_cts_crypt(cipher, &subbuf, cbcbytes, desc.iv, NULL, 0);
+       if (ret)
+               goto out_err;
+
+
+       /* Calculate our hmac over the plaintext data */
+       our_hmac_obj.len = sizeof(our_hmac);
+       our_hmac_obj.data = our_hmac;
+
+       ret = make_checksum_v2(kctx, NULL, 0, &subbuf, 0,
+                              cksum_key, usage, &our_hmac_obj);
+       if (ret)
+               goto out_err;
+
+       /* Get the packet's hmac value */
+       ret = read_bytes_from_xdr_buf(buf, buf->len - kctx->gk5e->cksumlength,
+                                     pkt_hmac, kctx->gk5e->cksumlength);
+       if (ret)
+               goto out_err;
+
+       if (memcmp(pkt_hmac, our_hmac, kctx->gk5e->cksumlength) != 0) {
+               ret = GSS_S_BAD_SIG;
+               goto out_err;
+       }
+       *headskip = kctx->gk5e->conflen;
+       *tailskip = kctx->gk5e->cksumlength;
+out_err:
+       if (ret && ret != GSS_S_BAD_SIG)
+               ret = GSS_S_FAILURE;
+       return ret;
+}
+
+/*
+ * Compute Kseq given the initial session key and the checksum.
+ * Set the key of the given cipher.
+ */
+int
+krb5_rc4_setup_seq_key(struct krb5_ctx *kctx, struct crypto_blkcipher *cipher,
+                      unsigned char *cksum)
+{
+       struct crypto_hash *hmac;
+       struct hash_desc desc;
+       struct scatterlist sg[1];
+       u8 Kseq[GSS_KRB5_MAX_KEYLEN];
+       u32 zeroconstant = 0;
+       int err;
+
+       dprintk("%s: entered\n", __func__);
+
+       hmac = crypto_alloc_hash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(hmac)) {
+               dprintk("%s: error %ld, allocating hash '%s'\n",
+                       __func__, PTR_ERR(hmac), kctx->gk5e->cksum_name);
+               return PTR_ERR(hmac);
+       }
+
+       desc.tfm = hmac;
+       desc.flags = 0;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out_err;
+
+       /* Compute intermediate Kseq from session key */
+       err = crypto_hash_setkey(hmac, kctx->Ksess, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       sg_init_table(sg, 1);
+       sg_set_buf(sg, &zeroconstant, 4);
+
+       err = crypto_hash_digest(&desc, sg, 4, Kseq);
+       if (err)
+               goto out_err;
+
+       /* Compute final Kseq from the checksum and intermediate Kseq */
+       err = crypto_hash_setkey(hmac, Kseq, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       sg_set_buf(sg, cksum, 8);
+
+       err = crypto_hash_digest(&desc, sg, 8, Kseq);
+       if (err)
+               goto out_err;
+
+       err = crypto_blkcipher_setkey(cipher, Kseq, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       err = 0;
+
+out_err:
+       crypto_free_hash(hmac);
+       dprintk("%s: returning %d\n", __func__, err);
+       return err;
+}
+
+/*
+ * Compute Kcrypt given the initial session key and the plaintext seqnum.
+ * Set the key of cipher kctx->enc.
+ */
+int
+krb5_rc4_setup_enc_key(struct krb5_ctx *kctx, struct crypto_blkcipher *cipher,
+                      s32 seqnum)
+{
+       struct crypto_hash *hmac;
+       struct hash_desc desc;
+       struct scatterlist sg[1];
+       u8 Kcrypt[GSS_KRB5_MAX_KEYLEN];
+       u8 zeroconstant[4] = {0};
+       u8 seqnumarray[4];
+       int err, i;
+
+       dprintk("%s: entered, seqnum %u\n", __func__, seqnum);
+
+       hmac = crypto_alloc_hash(kctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(hmac)) {
+               dprintk("%s: error %ld, allocating hash '%s'\n",
+                       __func__, PTR_ERR(hmac), kctx->gk5e->cksum_name);
+               return PTR_ERR(hmac);
+       }
+
+       desc.tfm = hmac;
+       desc.flags = 0;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out_err;
+
+       /* Compute intermediate Kcrypt from session key */
+       for (i = 0; i < kctx->gk5e->keylength; i++)
+               Kcrypt[i] = kctx->Ksess[i] ^ 0xf0;
+
+       err = crypto_hash_setkey(hmac, Kcrypt, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       sg_init_table(sg, 1);
+       sg_set_buf(sg, zeroconstant, 4);
+
+       err = crypto_hash_digest(&desc, sg, 4, Kcrypt);
+       if (err)
+               goto out_err;
+
+       /* Compute final Kcrypt from the seqnum and intermediate Kcrypt */
+       err = crypto_hash_setkey(hmac, Kcrypt, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       seqnumarray[0] = (unsigned char) ((seqnum >> 24) & 0xff);
+       seqnumarray[1] = (unsigned char) ((seqnum >> 16) & 0xff);
+       seqnumarray[2] = (unsigned char) ((seqnum >> 8) & 0xff);
+       seqnumarray[3] = (unsigned char) ((seqnum >> 0) & 0xff);
+
+       sg_set_buf(sg, seqnumarray, 4);
+
+       err = crypto_hash_digest(&desc, sg, 4, Kcrypt);
+       if (err)
+               goto out_err;
+
+       err = crypto_blkcipher_setkey(cipher, Kcrypt, kctx->gk5e->keylength);
+       if (err)
+               goto out_err;
+
+       err = 0;
+
+out_err:
+       crypto_free_hash(hmac);
+       dprintk("%s: returning %d\n", __func__, err);
+       return err;
+}
+
diff --git a/net/sunrpc/auth_gss/gss_krb5_keys.c b/net/sunrpc/auth_gss/gss_krb5_keys.c
new file mode 100644 (file)
index 0000000..76e42e6
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+ * COPYRIGHT (c) 2008
+ * The Regents of the University of Michigan
+ * ALL RIGHTS RESERVED
+ *
+ * Permission is granted to use, copy, create derivative works
+ * and redistribute this software and such derivative works
+ * for any purpose, so long as the name of The University of
+ * Michigan is not used in any advertising or publicity
+ * pertaining to the use of distribution of this software
+ * without specific, written prior authorization.  If the
+ * above copyright notice or any other identification of the
+ * University of Michigan is included in any copy of any
+ * portion of this software, then the disclaimer below must
+ * also be included.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
+ * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
+ * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
+ * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
+ * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
+ * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
+ * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
+ * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGES.
+ */
+
+/*
+ * Copyright (C) 1998 by the FundsXpress, INC.
+ *
+ * All rights reserved.
+ *
+ * Export of this software from the United States of America may require
+ * a specific license from the United States Government.  It is the
+ * responsibility of any person or organization contemplating export to
+ * obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of FundsXpress. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission.  FundsXpress makes no representations about the suitability of
+ * this software for any purpose.  It is provided "as is" without express
+ * or implied warranty.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/err.h>
+#include <linux/types.h>
+#include <linux/crypto.h>
+#include <linux/sunrpc/gss_krb5.h>
+#include <linux/sunrpc/xdr.h>
+
+#ifdef RPC_DEBUG
+# define RPCDBG_FACILITY        RPCDBG_AUTH
+#endif
+
+/*
+ * This is the n-fold function as described in rfc3961, sec 5.1
+ * Taken from MIT Kerberos and modified.
+ */
+
+static void krb5_nfold(u32 inbits, const u8 *in,
+                      u32 outbits, u8 *out)
+{
+       int a, b, c, lcm;
+       int byte, i, msbit;
+
+       /* the code below is more readable if I make these bytes
+          instead of bits */
+
+       inbits >>= 3;
+       outbits >>= 3;
+
+       /* first compute lcm(n,k) */
+
+       a = outbits;
+       b = inbits;
+
+       while (b != 0) {
+               c = b;
+               b = a%b;
+               a = c;
+       }
+
+       lcm = outbits*inbits/a;
+
+       /* now do the real work */
+
+       memset(out, 0, outbits);
+       byte = 0;
+
+       /* this will end up cycling through k lcm(k,n)/k times, which
+          is correct */
+       for (i = lcm-1; i >= 0; i--) {
+               /* compute the msbit in k which gets added into this byte */
+               msbit = (
+                       /* first, start with the msbit in the first,
+                        * unrotated byte */
+                        ((inbits << 3) - 1)
+                        /* then, for each byte, shift to the right
+                         * for each repetition */
+                        + (((inbits << 3) + 13) * (i/inbits))
+                        /* last, pick out the correct byte within
+                         * that shifted repetition */
+                        + ((inbits - (i % inbits)) << 3)
+                        ) % (inbits << 3);
+
+               /* pull out the byte value itself */
+               byte += (((in[((inbits - 1) - (msbit >> 3)) % inbits] << 8)|
+                                 (in[((inbits) - (msbit >> 3)) % inbits]))
+                                >> ((msbit & 7) + 1)) & 0xff;
+
+               /* do the addition */
+               byte += out[i % outbits];
+               out[i % outbits] = byte & 0xff;
+
+               /* keep around the carry bit, if any */
+               byte >>= 8;
+
+       }
+
+       /* if there's a carry bit left over, add it back in */
+       if (byte) {
+               for (i = outbits - 1; i >= 0; i--) {
+                       /* do the addition */
+                       byte += out[i];
+                       out[i] = byte & 0xff;
+
+                       /* keep around the carry bit, if any */
+                       byte >>= 8;
+               }
+       }
+}
+
+/*
+ * This is the DK (derive_key) function as described in rfc3961, sec 5.1
+ * Taken from MIT Kerberos and modified.
+ */
+
+u32 krb5_derive_key(const struct gss_krb5_enctype *gk5e,
+                   const struct xdr_netobj *inkey,
+                   struct xdr_netobj *outkey,
+                   const struct xdr_netobj *in_constant,
+                   gfp_t gfp_mask)
+{
+       size_t blocksize, keybytes, keylength, n;
+       unsigned char *inblockdata, *outblockdata, *rawkey;
+       struct xdr_netobj inblock, outblock;
+       struct crypto_blkcipher *cipher;
+       u32 ret = EINVAL;
+
+       blocksize = gk5e->blocksize;
+       keybytes = gk5e->keybytes;
+       keylength = gk5e->keylength;
+
+       if ((inkey->len != keylength) || (outkey->len != keylength))
+               goto err_return;
+
+       cipher = crypto_alloc_blkcipher(gk5e->encrypt_name, 0,
+                                       CRYPTO_ALG_ASYNC);
+       if (IS_ERR(cipher))
+               goto err_return;
+       if (crypto_blkcipher_setkey(cipher, inkey->data, inkey->len))
+               goto err_return;
+
+       /* allocate and set up buffers */
+
+       ret = ENOMEM;
+       inblockdata = kmalloc(blocksize, gfp_mask);
+       if (inblockdata == NULL)
+               goto err_free_cipher;
+
+       outblockdata = kmalloc(blocksize, gfp_mask);
+       if (outblockdata == NULL)
+               goto err_free_in;
+
+       rawkey = kmalloc(keybytes, gfp_mask);
+       if (rawkey == NULL)
+               goto err_free_out;
+
+       inblock.data = (char *) inblockdata;
+       inblock.len = blocksize;
+
+       outblock.data = (char *) outblockdata;
+       outblock.len = blocksize;
+
+       /* initialize the input block */
+
+       if (in_constant->len == inblock.len) {
+               memcpy(inblock.data, in_constant->data, inblock.len);
+       } else {
+               krb5_nfold(in_constant->len * 8, in_constant->data,
+                          inblock.len * 8, inblock.data);
+       }
+
+       /* loop encrypting the blocks until enough key bytes are generated */
+
+       n = 0;
+       while (n < keybytes) {
+               (*(gk5e->encrypt))(cipher, NULL, inblock.data,
+                                  outblock.data, inblock.len);
+
+               if ((keybytes - n) <= outblock.len) {
+                       memcpy(rawkey + n, outblock.data, (keybytes - n));
+                       break;
+               }
+
+               memcpy(rawkey + n, outblock.data, outblock.len);
+               memcpy(inblock.data, outblock.data, outblock.len);
+               n += outblock.len;
+       }
+
+       /* postprocess the key */
+
+       inblock.data = (char *) rawkey;
+       inblock.len = keybytes;
+
+       BUG_ON(gk5e->mk_key == NULL);
+       ret = (*(gk5e->mk_key))(gk5e, &inblock, outkey);
+       if (ret) {
+               dprintk("%s: got %d from mk_key function for '%s'\n",
+                       __func__, ret, gk5e->encrypt_name);
+               goto err_free_raw;
+       }
+
+       /* clean memory, free resources and exit */
+
+       ret = 0;
+
+err_free_raw:
+       memset(rawkey, 0, keybytes);
+       kfree(rawkey);
+err_free_out:
+       memset(outblockdata, 0, blocksize);
+       kfree(outblockdata);
+err_free_in:
+       memset(inblockdata, 0, blocksize);
+       kfree(inblockdata);
+err_free_cipher:
+       crypto_free_blkcipher(cipher);
+err_return:
+       return ret;
+}
+
+#define smask(step) ((1<<step)-1)
+#define pstep(x, step) (((x)&smask(step))^(((x)>>step)&smask(step)))
+#define parity_char(x) pstep(pstep(pstep((x), 4), 2), 1)
+
+static void mit_des_fixup_key_parity(u8 key[8])
+{
+       int i;
+       for (i = 0; i < 8; i++) {
+               key[i] &= 0xfe;
+               key[i] |= 1^parity_char(key[i]);
+       }
+}
+
+/*
+ * This is the des3 key derivation postprocess function
+ */
+u32 gss_krb5_des3_make_key(const struct gss_krb5_enctype *gk5e,
+                          struct xdr_netobj *randombits,
+                          struct xdr_netobj *key)
+{
+       int i;
+       u32 ret = EINVAL;
+
+       if (key->len != 24) {
+               dprintk("%s: key->len is %d\n", __func__, key->len);
+               goto err_out;
+       }
+       if (randombits->len != 21) {
+               dprintk("%s: randombits->len is %d\n",
+                       __func__, randombits->len);
+               goto err_out;
+       }
+
+       /* take the seven bytes, move them around into the top 7 bits of the
+          8 key bytes, then compute the parity bits.  Do this three times. */
+
+       for (i = 0; i < 3; i++) {
+               memcpy(key->data + i*8, randombits->data + i*7, 7);
+               key->data[i*8+7] = (((key->data[i*8]&1)<<1) |
+                                   ((key->data[i*8+1]&1)<<2) |
+                                   ((key->data[i*8+2]&1)<<3) |
+                                   ((key->data[i*8+3]&1)<<4) |
+                                   ((key->data[i*8+4]&1)<<5) |
+                                   ((key->data[i*8+5]&1)<<6) |
+                                   ((key->data[i*8+6]&1)<<7));
+
+               mit_des_fixup_key_parity(key->data + i*8);
+       }
+       ret = 0;
+err_out:
+       return ret;
+}
+
+/*
+ * This is the aes key derivation postprocess function
+ */
+u32 gss_krb5_aes_make_key(const struct gss_krb5_enctype *gk5e,
+                         struct xdr_netobj *randombits,
+                         struct xdr_netobj *key)
+{
+       u32 ret = EINVAL;
+
+       if (key->len != 16 && key->len != 32) {
+               dprintk("%s: key->len is %d\n", __func__, key->len);
+               goto err_out;
+       }
+       if (randombits->len != 16 && randombits->len != 32) {
+               dprintk("%s: randombits->len is %d\n",
+                       __func__, randombits->len);
+               goto err_out;
+       }
+       if (randombits->len != key->len) {
+               dprintk("%s: randombits->len is %d, key->len is %d\n",
+                       __func__, randombits->len, key->len);
+               goto err_out;
+       }
+       memcpy(key->data, randombits->data, key->len);
+       ret = 0;
+err_out:
+       return ret;
+}
+
index 2deb0ed..0326446 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  linux/net/sunrpc/gss_krb5_mech.c
  *
- *  Copyright (c) 2001 The Regents of the University of Michigan.
+ *  Copyright (c) 2001-2008 The Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  Andy Adamson <andros@umich.edu>
 # define RPCDBG_FACILITY       RPCDBG_AUTH
 #endif
 
+static struct gss_api_mech gss_kerberos_mech;  /* forward declaration */
+
+static const struct gss_krb5_enctype supported_gss_krb5_enctypes[] = {
+       /*
+        * DES (All DES enctypes are mapped to the same gss functionality)
+        */
+       {
+         .etype = ENCTYPE_DES_CBC_RAW,
+         .ctype = CKSUMTYPE_RSA_MD5,
+         .name = "des-cbc-crc",
+         .encrypt_name = "cbc(des)",
+         .cksum_name = "md5",
+         .encrypt = krb5_encrypt,
+         .decrypt = krb5_decrypt,
+         .mk_key = NULL,
+         .signalg = SGN_ALG_DES_MAC_MD5,
+         .sealalg = SEAL_ALG_DES,
+         .keybytes = 7,
+         .keylength = 8,
+         .blocksize = 8,
+         .conflen = 8,
+         .cksumlength = 8,
+         .keyed_cksum = 0,
+       },
+       /*
+        * RC4-HMAC
+        */
+       {
+         .etype = ENCTYPE_ARCFOUR_HMAC,
+         .ctype = CKSUMTYPE_HMAC_MD5_ARCFOUR,
+         .name = "rc4-hmac",
+         .encrypt_name = "ecb(arc4)",
+         .cksum_name = "hmac(md5)",
+         .encrypt = krb5_encrypt,
+         .decrypt = krb5_decrypt,
+         .mk_key = NULL,
+         .signalg = SGN_ALG_HMAC_MD5,
+         .sealalg = SEAL_ALG_MICROSOFT_RC4,
+         .keybytes = 16,
+         .keylength = 16,
+         .blocksize = 1,
+         .conflen = 8,
+         .cksumlength = 8,
+         .keyed_cksum = 1,
+       },
+       /*
+        * 3DES
+        */
+       {
+         .etype = ENCTYPE_DES3_CBC_RAW,
+         .ctype = CKSUMTYPE_HMAC_SHA1_DES3,
+         .name = "des3-hmac-sha1",
+         .encrypt_name = "cbc(des3_ede)",
+         .cksum_name = "hmac(sha1)",
+         .encrypt = krb5_encrypt,
+         .decrypt = krb5_decrypt,
+         .mk_key = gss_krb5_des3_make_key,
+         .signalg = SGN_ALG_HMAC_SHA1_DES3_KD,
+         .sealalg = SEAL_ALG_DES3KD,
+         .keybytes = 21,
+         .keylength = 24,
+         .blocksize = 8,
+         .conflen = 8,
+         .cksumlength = 20,
+         .keyed_cksum = 1,
+       },
+       /*
+        * AES128
+        */
+       {
+         .etype = ENCTYPE_AES128_CTS_HMAC_SHA1_96,
+         .ctype = CKSUMTYPE_HMAC_SHA1_96_AES128,
+         .name = "aes128-cts",
+         .encrypt_name = "cts(cbc(aes))",
+         .cksum_name = "hmac(sha1)",
+         .encrypt = krb5_encrypt,
+         .decrypt = krb5_decrypt,
+         .mk_key = gss_krb5_aes_make_key,
+         .encrypt_v2 = gss_krb5_aes_encrypt,
+         .decrypt_v2 = gss_krb5_aes_decrypt,
+         .signalg = -1,
+         .sealalg = -1,
+         .keybytes = 16,
+         .keylength = 16,
+         .blocksize = 16,
+         .conflen = 16,
+         .cksumlength = 12,
+         .keyed_cksum = 1,
+       },
+       /*
+        * AES256
+        */
+       {
+         .etype = ENCTYPE_AES256_CTS_HMAC_SHA1_96,
+         .ctype = CKSUMTYPE_HMAC_SHA1_96_AES256,
+         .name = "aes256-cts",
+         .encrypt_name = "cts(cbc(aes))",
+         .cksum_name = "hmac(sha1)",
+         .encrypt = krb5_encrypt,
+         .decrypt = krb5_decrypt,
+         .mk_key = gss_krb5_aes_make_key,
+         .encrypt_v2 = gss_krb5_aes_encrypt,
+         .decrypt_v2 = gss_krb5_aes_decrypt,
+         .signalg = -1,
+         .sealalg = -1,
+         .keybytes = 32,
+         .keylength = 32,
+         .blocksize = 16,
+         .conflen = 16,
+         .cksumlength = 12,
+         .keyed_cksum = 1,
+       },
+};
+
+static const int num_supported_enctypes =
+       ARRAY_SIZE(supported_gss_krb5_enctypes);
+
+static int
+supported_gss_krb5_enctype(int etype)
+{
+       int i;
+       for (i = 0; i < num_supported_enctypes; i++)
+               if (supported_gss_krb5_enctypes[i].etype == etype)
+                       return 1;
+       return 0;
+}
+
+static const struct gss_krb5_enctype *
+get_gss_krb5_enctype(int etype)
+{
+       int i;
+       for (i = 0; i < num_supported_enctypes; i++)
+               if (supported_gss_krb5_enctypes[i].etype == etype)
+                       return &supported_gss_krb5_enctypes[i];
+       return NULL;
+}
+
 static const void *
 simple_get_bytes(const void *p, const void *end, void *res, int len)
 {
@@ -78,35 +215,45 @@ simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res)
 }
 
 static inline const void *
-get_key(const void *p, const void *end, struct crypto_blkcipher **res)
+get_key(const void *p, const void *end,
+       struct krb5_ctx *ctx, struct crypto_blkcipher **res)
 {
        struct xdr_netobj       key;
        int                     alg;
-       char                    *alg_name;
 
        p = simple_get_bytes(p, end, &alg, sizeof(alg));
        if (IS_ERR(p))
                goto out_err;
+
+       switch (alg) {
+       case ENCTYPE_DES_CBC_CRC:
+       case ENCTYPE_DES_CBC_MD4:
+       case ENCTYPE_DES_CBC_MD5:
+               /* Map all these key types to ENCTYPE_DES_CBC_RAW */
+               alg = ENCTYPE_DES_CBC_RAW;
+               break;
+       }
+
+       if (!supported_gss_krb5_enctype(alg)) {
+               printk(KERN_WARNING "gss_kerberos_mech: unsupported "
+                       "encryption key algorithm %d\n", alg);
+               goto out_err;
+       }
        p = simple_get_netobj(p, end, &key);
        if (IS_ERR(p))
                goto out_err;
 
-       switch (alg) {
-               case ENCTYPE_DES_CBC_RAW:
-                       alg_name = "cbc(des)";
-                       break;
-               default:
-                       printk("gss_kerberos_mech: unsupported algorithm %d\n", alg);
-                       goto out_err_free_key;
-       }
-       *res = crypto_alloc_blkcipher(alg_name, 0, CRYPTO_ALG_ASYNC);
+       *res = crypto_alloc_blkcipher(ctx->gk5e->encrypt_name, 0,
+                                                       CRYPTO_ALG_ASYNC);
        if (IS_ERR(*res)) {
-               printk("gss_kerberos_mech: unable to initialize crypto algorithm %s\n", alg_name);
+               printk(KERN_WARNING "gss_kerberos_mech: unable to initialize "
+                       "crypto algorithm %s\n", ctx->gk5e->encrypt_name);
                *res = NULL;
                goto out_err_free_key;
        }
        if (crypto_blkcipher_setkey(*res, key.data, key.len)) {
-               printk("gss_kerberos_mech: error setting key for crypto algorithm %s\n", alg_name);
+               printk(KERN_WARNING "gss_kerberos_mech: error setting key for "
+                       "crypto algorithm %s\n", ctx->gk5e->encrypt_name);
                goto out_err_free_tfm;
        }
 
@@ -123,56 +270,55 @@ out_err:
 }
 
 static int
-gss_import_sec_context_kerberos(const void *p,
-                               size_t len,
-                               struct gss_ctx *ctx_id)
+gss_import_v1_context(const void *p, const void *end, struct krb5_ctx *ctx)
 {
-       const void *end = (const void *)((const char *)p + len);
-       struct  krb5_ctx *ctx;
        int tmp;
 
-       if (!(ctx = kzalloc(sizeof(*ctx), GFP_NOFS))) {
-               p = ERR_PTR(-ENOMEM);
-               goto out_err;
-       }
-
        p = simple_get_bytes(p, end, &ctx->initiate, sizeof(ctx->initiate));
        if (IS_ERR(p))
-               goto out_err_free_ctx;
+               goto out_err;
+
+       /* Old format supports only DES!  Any other enctype uses new format */
+       ctx->enctype = ENCTYPE_DES_CBC_RAW;
+
+       ctx->gk5e = get_gss_krb5_enctype(ctx->enctype);
+       if (ctx->gk5e == NULL)
+               goto out_err;
+
        /* The downcall format was designed before we completely understood
         * the uses of the context fields; so it includes some stuff we
         * just give some minimal sanity-checking, and some we ignore
         * completely (like the next twenty bytes): */
        if (unlikely(p + 20 > end || p + 20 < p))
-               goto out_err_free_ctx;
+               goto out_err;
        p += 20;
        p = simple_get_bytes(p, end, &tmp, sizeof(tmp));
        if (IS_ERR(p))
-               goto out_err_free_ctx;
+               goto out_err;
        if (tmp != SGN_ALG_DES_MAC_MD5) {
                p = ERR_PTR(-ENOSYS);
-               goto out_err_free_ctx;
+               goto out_err;
        }
        p = simple_get_bytes(p, end, &tmp, sizeof(tmp));
        if (IS_ERR(p))
-               goto out_err_free_ctx;
+               goto out_err;
        if (tmp != SEAL_ALG_DES) {
                p = ERR_PTR(-ENOSYS);
-               goto out_err_free_ctx;
+               goto out_err;
        }
        p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
        if (IS_ERR(p))
-               goto out_err_free_ctx;
+               goto out_err;
        p = simple_get_bytes(p, end, &ctx->seq_send, sizeof(ctx->seq_send));
        if (IS_ERR(p))
-               goto out_err_free_ctx;
+               goto out_err;
        p = simple_get_netobj(p, end, &ctx->mech_used);
        if (IS_ERR(p))
-               goto out_err_free_ctx;
-       p = get_key(p, end, &ctx->enc);
+               goto out_err;
+       p = get_key(p, end, ctx, &ctx->enc);
        if (IS_ERR(p))
                goto out_err_free_mech;
-       p = get_key(p, end, &ctx->seq);
+       p = get_key(p, end, ctx, &ctx->seq);
        if (IS_ERR(p))
                goto out_err_free_key1;
        if (p != end) {
@@ -180,9 +326,6 @@ gss_import_sec_context_kerberos(const void *p,
                goto out_err_free_key2;
        }
 
-       ctx_id->internal_ctx_id = ctx;
-
-       dprintk("RPC:       Successfully imported new context.\n");
        return 0;
 
 out_err_free_key2:
@@ -191,18 +334,378 @@ out_err_free_key1:
        crypto_free_blkcipher(ctx->enc);
 out_err_free_mech:
        kfree(ctx->mech_used.data);
-out_err_free_ctx:
-       kfree(ctx);
 out_err:
        return PTR_ERR(p);
 }
 
+struct crypto_blkcipher *
+context_v2_alloc_cipher(struct krb5_ctx *ctx, const char *cname, u8 *key)
+{
+       struct crypto_blkcipher *cp;
+
+       cp = crypto_alloc_blkcipher(cname, 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(cp)) {
+               dprintk("gss_kerberos_mech: unable to initialize "
+                       "crypto algorithm %s\n", cname);
+               return NULL;
+       }
+       if (crypto_blkcipher_setkey(cp, key, ctx->gk5e->keylength)) {
+               dprintk("gss_kerberos_mech: error setting key for "
+                       "crypto algorithm %s\n", cname);
+               crypto_free_blkcipher(cp);
+               return NULL;
+       }
+       return cp;
+}
+
+static inline void
+set_cdata(u8 cdata[GSS_KRB5_K5CLENGTH], u32 usage, u8 seed)
+{
+       cdata[0] = (usage>>24)&0xff;
+       cdata[1] = (usage>>16)&0xff;
+       cdata[2] = (usage>>8)&0xff;
+       cdata[3] = usage&0xff;
+       cdata[4] = seed;
+}
+
+static int
+context_derive_keys_des3(struct krb5_ctx *ctx, gfp_t gfp_mask)
+{
+       struct xdr_netobj c, keyin, keyout;
+       u8 cdata[GSS_KRB5_K5CLENGTH];
+       u32 err;
+
+       c.len = GSS_KRB5_K5CLENGTH;
+       c.data = cdata;
+
+       keyin.data = ctx->Ksess;
+       keyin.len = ctx->gk5e->keylength;
+       keyout.len = ctx->gk5e->keylength;
+
+       /* seq uses the raw key */
+       ctx->seq = context_v2_alloc_cipher(ctx, ctx->gk5e->encrypt_name,
+                                          ctx->Ksess);
+       if (ctx->seq == NULL)
+               goto out_err;
+
+       ctx->enc = context_v2_alloc_cipher(ctx, ctx->gk5e->encrypt_name,
+                                          ctx->Ksess);
+       if (ctx->enc == NULL)
+               goto out_free_seq;
+
+       /* derive cksum */
+       set_cdata(cdata, KG_USAGE_SIGN, KEY_USAGE_SEED_CHECKSUM);
+       keyout.data = ctx->cksum;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving cksum key\n",
+                       __func__, err);
+               goto out_free_enc;
+       }
+
+       return 0;
+
+out_free_enc:
+       crypto_free_blkcipher(ctx->enc);
+out_free_seq:
+       crypto_free_blkcipher(ctx->seq);
+out_err:
+       return -EINVAL;
+}
+
+/*
+ * Note that RC4 depends on deriving keys using the sequence
+ * number or the checksum of a token.  Therefore, the final keys
+ * cannot be calculated until the token is being constructed!
+ */
+static int
+context_derive_keys_rc4(struct krb5_ctx *ctx)
+{
+       struct crypto_hash *hmac;
+       char sigkeyconstant[] = "signaturekey";
+       int slen = strlen(sigkeyconstant) + 1;  /* include null terminator */
+       struct hash_desc desc;
+       struct scatterlist sg[1];
+       int err;
+
+       dprintk("RPC:       %s: entered\n", __func__);
+       /*
+        * derive cksum (aka Ksign) key
+        */
+       hmac = crypto_alloc_hash(ctx->gk5e->cksum_name, 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(hmac)) {
+               dprintk("%s: error %ld allocating hash '%s'\n",
+                       __func__, PTR_ERR(hmac), ctx->gk5e->cksum_name);
+               err = PTR_ERR(hmac);
+               goto out_err;
+       }
+
+       err = crypto_hash_setkey(hmac, ctx->Ksess, ctx->gk5e->keylength);
+       if (err)
+               goto out_err_free_hmac;
+
+       sg_init_table(sg, 1);
+       sg_set_buf(sg, sigkeyconstant, slen);
+
+       desc.tfm = hmac;
+       desc.flags = 0;
+
+       err = crypto_hash_init(&desc);
+       if (err)
+               goto out_err_free_hmac;
+
+       err = crypto_hash_digest(&desc, sg, slen, ctx->cksum);
+       if (err)
+               goto out_err_free_hmac;
+       /*
+        * allocate hash, and blkciphers for data and seqnum encryption
+        */
+       ctx->enc = crypto_alloc_blkcipher(ctx->gk5e->encrypt_name, 0,
+                                         CRYPTO_ALG_ASYNC);
+       if (IS_ERR(ctx->enc)) {
+               err = PTR_ERR(ctx->enc);
+               goto out_err_free_hmac;
+       }
+
+       ctx->seq = crypto_alloc_blkcipher(ctx->gk5e->encrypt_name, 0,
+                                         CRYPTO_ALG_ASYNC);
+       if (IS_ERR(ctx->seq)) {
+               crypto_free_blkcipher(ctx->enc);
+               err = PTR_ERR(ctx->seq);
+               goto out_err_free_hmac;
+       }
+
+       dprintk("RPC:       %s: returning success\n", __func__);
+
+       err = 0;
+
+out_err_free_hmac:
+       crypto_free_hash(hmac);
+out_err:
+       dprintk("RPC:       %s: returning %d\n", __func__, err);
+       return err;
+}
+
+static int
+context_derive_keys_new(struct krb5_ctx *ctx, gfp_t gfp_mask)
+{
+       struct xdr_netobj c, keyin, keyout;
+       u8 cdata[GSS_KRB5_K5CLENGTH];
+       u32 err;
+
+       c.len = GSS_KRB5_K5CLENGTH;
+       c.data = cdata;
+
+       keyin.data = ctx->Ksess;
+       keyin.len = ctx->gk5e->keylength;
+       keyout.len = ctx->gk5e->keylength;
+
+       /* initiator seal encryption */
+       set_cdata(cdata, KG_USAGE_INITIATOR_SEAL, KEY_USAGE_SEED_ENCRYPTION);
+       keyout.data = ctx->initiator_seal;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving initiator_seal key\n",
+                       __func__, err);
+               goto out_err;
+       }
+       ctx->initiator_enc = context_v2_alloc_cipher(ctx,
+                                                    ctx->gk5e->encrypt_name,
+                                                    ctx->initiator_seal);
+       if (ctx->initiator_enc == NULL)
+               goto out_err;
+
+       /* acceptor seal encryption */
+       set_cdata(cdata, KG_USAGE_ACCEPTOR_SEAL, KEY_USAGE_SEED_ENCRYPTION);
+       keyout.data = ctx->acceptor_seal;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving acceptor_seal key\n",
+                       __func__, err);
+               goto out_free_initiator_enc;
+       }
+       ctx->acceptor_enc = context_v2_alloc_cipher(ctx,
+                                                   ctx->gk5e->encrypt_name,
+                                                   ctx->acceptor_seal);
+       if (ctx->acceptor_enc == NULL)
+               goto out_free_initiator_enc;
+
+       /* initiator sign checksum */
+       set_cdata(cdata, KG_USAGE_INITIATOR_SIGN, KEY_USAGE_SEED_CHECKSUM);
+       keyout.data = ctx->initiator_sign;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving initiator_sign key\n",
+                       __func__, err);
+               goto out_free_acceptor_enc;
+       }
+
+       /* acceptor sign checksum */
+       set_cdata(cdata, KG_USAGE_ACCEPTOR_SIGN, KEY_USAGE_SEED_CHECKSUM);
+       keyout.data = ctx->acceptor_sign;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving acceptor_sign key\n",
+                       __func__, err);
+               goto out_free_acceptor_enc;
+       }
+
+       /* initiator seal integrity */
+       set_cdata(cdata, KG_USAGE_INITIATOR_SEAL, KEY_USAGE_SEED_INTEGRITY);
+       keyout.data = ctx->initiator_integ;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving initiator_integ key\n",
+                       __func__, err);
+               goto out_free_acceptor_enc;
+       }
+
+       /* acceptor seal integrity */
+       set_cdata(cdata, KG_USAGE_ACCEPTOR_SEAL, KEY_USAGE_SEED_INTEGRITY);
+       keyout.data = ctx->acceptor_integ;
+       err = krb5_derive_key(ctx->gk5e, &keyin, &keyout, &c, gfp_mask);
+       if (err) {
+               dprintk("%s: Error %d deriving acceptor_integ key\n",
+                       __func__, err);
+               goto out_free_acceptor_enc;
+       }
+
+       switch (ctx->enctype) {
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               ctx->initiator_enc_aux =
+                       context_v2_alloc_cipher(ctx, "cbc(aes)",
+                                               ctx->initiator_seal);
+               if (ctx->initiator_enc_aux == NULL)
+                       goto out_free_acceptor_enc;
+               ctx->acceptor_enc_aux =
+                       context_v2_alloc_cipher(ctx, "cbc(aes)",
+                                               ctx->acceptor_seal);
+               if (ctx->acceptor_enc_aux == NULL) {
+                       crypto_free_blkcipher(ctx->initiator_enc_aux);
+                       goto out_free_acceptor_enc;
+               }
+       }
+
+       return 0;
+
+out_free_acceptor_enc:
+       crypto_free_blkcipher(ctx->acceptor_enc);
+out_free_initiator_enc:
+       crypto_free_blkcipher(ctx->initiator_enc);
+out_err:
+       return -EINVAL;
+}
+
+static int
+gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
+               gfp_t gfp_mask)
+{
+       int keylen;
+
+       p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags));
+       if (IS_ERR(p))
+               goto out_err;
+       ctx->initiate = ctx->flags & KRB5_CTX_FLAG_INITIATOR;
+
+       p = simple_get_bytes(p, end, &ctx->endtime, sizeof(ctx->endtime));
+       if (IS_ERR(p))
+               goto out_err;
+       p = simple_get_bytes(p, end, &ctx->seq_send64, sizeof(ctx->seq_send64));
+       if (IS_ERR(p))
+               goto out_err;
+       /* set seq_send for use by "older" enctypes */
+       ctx->seq_send = ctx->seq_send64;
+       if (ctx->seq_send64 != ctx->seq_send) {
+               dprintk("%s: seq_send64 %lx, seq_send %x overflow?\n", __func__,
+                       (long unsigned)ctx->seq_send64, ctx->seq_send);
+               goto out_err;
+       }
+       p = simple_get_bytes(p, end, &ctx->enctype, sizeof(ctx->enctype));
+       if (IS_ERR(p))
+               goto out_err;
+       /* Map ENCTYPE_DES3_CBC_SHA1 to ENCTYPE_DES3_CBC_RAW */
+       if (ctx->enctype == ENCTYPE_DES3_CBC_SHA1)
+               ctx->enctype = ENCTYPE_DES3_CBC_RAW;
+       ctx->gk5e = get_gss_krb5_enctype(ctx->enctype);
+       if (ctx->gk5e == NULL) {
+               dprintk("gss_kerberos_mech: unsupported krb5 enctype %u\n",
+                       ctx->enctype);
+               p = ERR_PTR(-EINVAL);
+               goto out_err;
+       }
+       keylen = ctx->gk5e->keylength;
+
+       p = simple_get_bytes(p, end, ctx->Ksess, keylen);
+       if (IS_ERR(p))
+               goto out_err;
+
+       if (p != end) {
+               p = ERR_PTR(-EINVAL);
+               goto out_err;
+       }
+
+       ctx->mech_used.data = kmemdup(gss_kerberos_mech.gm_oid.data,
+                                     gss_kerberos_mech.gm_oid.len, gfp_mask);
+       if (unlikely(ctx->mech_used.data == NULL)) {
+               p = ERR_PTR(-ENOMEM);
+               goto out_err;
+       }
+       ctx->mech_used.len = gss_kerberos_mech.gm_oid.len;
+
+       switch (ctx->enctype) {
+       case ENCTYPE_DES3_CBC_RAW:
+               return context_derive_keys_des3(ctx, gfp_mask);
+       case ENCTYPE_ARCFOUR_HMAC:
+               return context_derive_keys_rc4(ctx);
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               return context_derive_keys_new(ctx, gfp_mask);
+       default:
+               return -EINVAL;
+       }
+
+out_err:
+       return PTR_ERR(p);
+}
+
+static int
+gss_import_sec_context_kerberos(const void *p, size_t len,
+                               struct gss_ctx *ctx_id,
+                               gfp_t gfp_mask)
+{
+       const void *end = (const void *)((const char *)p + len);
+       struct  krb5_ctx *ctx;
+       int ret;
+
+       ctx = kzalloc(sizeof(*ctx), gfp_mask);
+       if (ctx == NULL)
+               return -ENOMEM;
+
+       if (len == 85)
+               ret = gss_import_v1_context(p, end, ctx);
+       else
+               ret = gss_import_v2_context(p, end, ctx, gfp_mask);
+
+       if (ret == 0)
+               ctx_id->internal_ctx_id = ctx;
+       else
+               kfree(ctx);
+
+       dprintk("RPC:       %s: returning %d\n", __func__, ret);
+       return ret;
+}
+
 static void
 gss_delete_sec_context_kerberos(void *internal_ctx) {
        struct krb5_ctx *kctx = internal_ctx;
 
        crypto_free_blkcipher(kctx->seq);
        crypto_free_blkcipher(kctx->enc);
+       crypto_free_blkcipher(kctx->acceptor_enc);
+       crypto_free_blkcipher(kctx->initiator_enc);
+       crypto_free_blkcipher(kctx->acceptor_enc_aux);
+       crypto_free_blkcipher(kctx->initiator_enc_aux);
        kfree(kctx->mech_used.data);
        kfree(kctx);
 }
@@ -241,6 +744,7 @@ static struct gss_api_mech gss_kerberos_mech = {
        .gm_ops         = &gss_kerberos_ops,
        .gm_pf_num      = ARRAY_SIZE(gss_kerberos_pfs),
        .gm_pfs         = gss_kerberos_pfs,
+       .gm_upcall_enctypes = "enctypes=18,17,16,23,3,1,2 ",
 };
 
 static int __init init_kerberos_module(void)
index 88fe6e7..d7941ea 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  Adapted from MIT Kerberos 5-1.2.1 lib/gssapi/krb5/k5seal.c
  *
- *  Copyright (c) 2000 The Regents of the University of Michigan.
+ *  Copyright (c) 2000-2008 The Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  Andy Adamson       <andros@umich.edu>
 
 DEFINE_SPINLOCK(krb5_seq_lock);
 
-u32
-gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
+static char *
+setup_token(struct krb5_ctx *ctx, struct xdr_netobj *token)
+{
+       __be16 *ptr, *krb5_hdr;
+       int body_size = GSS_KRB5_TOK_HDR_LEN + ctx->gk5e->cksumlength;
+
+       token->len = g_token_size(&ctx->mech_used, body_size);
+
+       ptr = (__be16 *)token->data;
+       g_make_token_header(&ctx->mech_used, body_size, (unsigned char **)&ptr);
+
+       /* ptr now at start of header described in rfc 1964, section 1.2.1: */
+       krb5_hdr = ptr;
+       *ptr++ = KG_TOK_MIC_MSG;
+       *ptr++ = cpu_to_le16(ctx->gk5e->signalg);
+       *ptr++ = SEAL_ALG_NONE;
+       *ptr++ = 0xffff;
+
+       return (char *)krb5_hdr;
+}
+
+static void *
+setup_token_v2(struct krb5_ctx *ctx, struct xdr_netobj *token)
+{
+       __be16 *ptr, *krb5_hdr;
+       u8 *p, flags = 0x00;
+
+       if ((ctx->flags & KRB5_CTX_FLAG_INITIATOR) == 0)
+               flags |= 0x01;
+       if (ctx->flags & KRB5_CTX_FLAG_ACCEPTOR_SUBKEY)
+               flags |= 0x04;
+
+       /* Per rfc 4121, sec 4.2.6.1, there is no header,
+        * just start the token */
+       krb5_hdr = ptr = (__be16 *)token->data;
+
+       *ptr++ = KG2_TOK_MIC;
+       p = (u8 *)ptr;
+       *p++ = flags;
+       *p++ = 0xff;
+       ptr = (__be16 *)p;
+       *ptr++ = 0xffff;
+       *ptr++ = 0xffff;
+
+       token->len = GSS_KRB5_TOK_HDR_LEN + ctx->gk5e->cksumlength;
+       return krb5_hdr;
+}
+
+static u32
+gss_get_mic_v1(struct krb5_ctx *ctx, struct xdr_buf *text,
                struct xdr_netobj *token)
 {
-       struct krb5_ctx         *ctx = gss_ctx->internal_ctx_id;
-       char                    cksumdata[16];
-       struct xdr_netobj       md5cksum = {.len = 0, .data = cksumdata};
-       unsigned char           *ptr, *msg_start;
+       char                    cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj       md5cksum = {.len = sizeof(cksumdata),
+                                           .data = cksumdata};
+       void                    *ptr;
        s32                     now;
        u32                     seq_send;
+       u8                      *cksumkey;
 
-       dprintk("RPC:       gss_krb5_seal\n");
+       dprintk("RPC:       %s\n", __func__);
        BUG_ON(ctx == NULL);
 
        now = get_seconds();
 
-       token->len = g_token_size(&ctx->mech_used, GSS_KRB5_TOK_HDR_LEN + 8);
+       ptr = setup_token(ctx, token);
 
-       ptr = token->data;
-       g_make_token_header(&ctx->mech_used, GSS_KRB5_TOK_HDR_LEN + 8, &ptr);
+       if (ctx->gk5e->keyed_cksum)
+               cksumkey = ctx->cksum;
+       else
+               cksumkey = NULL;
 
-       /* ptr now at header described in rfc 1964, section 1.2.1: */
-       ptr[0] = (unsigned char) ((KG_TOK_MIC_MSG >> 8) & 0xff);
-       ptr[1] = (unsigned char) (KG_TOK_MIC_MSG & 0xff);
+       if (make_checksum(ctx, ptr, 8, text, 0, cksumkey,
+                         KG_USAGE_SIGN, &md5cksum))
+               return GSS_S_FAILURE;
 
-       msg_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8;
+       memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data, md5cksum.len);
 
-       *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5);
-       memset(ptr + 4, 0xff, 4);
+       spin_lock(&krb5_seq_lock);
+       seq_send = ctx->seq_send++;
+       spin_unlock(&krb5_seq_lock);
 
-       if (make_checksum("md5", ptr, 8, text, 0, &md5cksum))
+       if (krb5_make_seq_num(ctx, ctx->seq, ctx->initiate ? 0 : 0xff,
+                             seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8))
                return GSS_S_FAILURE;
 
-       if (krb5_encrypt(ctx->seq, NULL, md5cksum.data,
-                         md5cksum.data, md5cksum.len))
-               return GSS_S_FAILURE;
+       return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
+}
+
+u32
+gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text,
+               struct xdr_netobj *token)
+{
+       char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj cksumobj = { .len = sizeof(cksumdata),
+                                      .data = cksumdata};
+       void *krb5_hdr;
+       s32 now;
+       u64 seq_send;
+       u8 *cksumkey;
+       unsigned int cksum_usage;
 
-       memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8);
+       dprintk("RPC:       %s\n", __func__);
 
+       krb5_hdr = setup_token_v2(ctx, token);
+
+       /* Set up the sequence number. Now 64-bits in clear
+        * text and w/o direction indicator */
        spin_lock(&krb5_seq_lock);
-       seq_send = ctx->seq_send++;
+       seq_send = ctx->seq_send64++;
        spin_unlock(&krb5_seq_lock);
-
-       if (krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff,
-                             seq_send, ptr + GSS_KRB5_TOK_HDR_LEN,
-                             ptr + 8))
+       *((u64 *)(krb5_hdr + 8)) = cpu_to_be64(seq_send);
+
+       if (ctx->initiate) {
+               cksumkey = ctx->initiator_sign;
+               cksum_usage = KG_USAGE_INITIATOR_SIGN;
+       } else {
+               cksumkey = ctx->acceptor_sign;
+               cksum_usage = KG_USAGE_ACCEPTOR_SIGN;
+       }
+
+       if (make_checksum_v2(ctx, krb5_hdr, GSS_KRB5_TOK_HDR_LEN,
+                            text, 0, cksumkey, cksum_usage, &cksumobj))
                return GSS_S_FAILURE;
 
+       memcpy(krb5_hdr + GSS_KRB5_TOK_HDR_LEN, cksumobj.data, cksumobj.len);
+
+       now = get_seconds();
+
        return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
 }
+
+u32
+gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
+                    struct xdr_netobj *token)
+{
+       struct krb5_ctx         *ctx = gss_ctx->internal_ctx_id;
+
+       switch (ctx->enctype) {
+       default:
+               BUG();
+       case ENCTYPE_DES_CBC_RAW:
+       case ENCTYPE_DES3_CBC_RAW:
+       case ENCTYPE_ARCFOUR_HMAC:
+               return gss_get_mic_v1(ctx, text, token);
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               return gss_get_mic_v2(ctx, text, token);
+       }
+}
+
index 6331cd6..415c013 100644 (file)
 # define RPCDBG_FACILITY        RPCDBG_AUTH
 #endif
 
+static s32
+krb5_make_rc4_seq_num(struct krb5_ctx *kctx, int direction, s32 seqnum,
+                     unsigned char *cksum, unsigned char *buf)
+{
+       struct crypto_blkcipher *cipher;
+       unsigned char plain[8];
+       s32 code;
+
+       dprintk("RPC:       %s:\n", __func__);
+       cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
+                                       CRYPTO_ALG_ASYNC);
+       if (IS_ERR(cipher))
+               return PTR_ERR(cipher);
+
+       plain[0] = (unsigned char) ((seqnum >> 24) & 0xff);
+       plain[1] = (unsigned char) ((seqnum >> 16) & 0xff);
+       plain[2] = (unsigned char) ((seqnum >> 8) & 0xff);
+       plain[3] = (unsigned char) ((seqnum >> 0) & 0xff);
+       plain[4] = direction;
+       plain[5] = direction;
+       plain[6] = direction;
+       plain[7] = direction;
+
+       code = krb5_rc4_setup_seq_key(kctx, cipher, cksum);
+       if (code)
+               goto out;
+
+       code = krb5_encrypt(cipher, cksum, plain, buf, 8);
+out:
+       crypto_free_blkcipher(cipher);
+       return code;
+}
 s32
-krb5_make_seq_num(struct crypto_blkcipher *key,
+krb5_make_seq_num(struct krb5_ctx *kctx,
+               struct crypto_blkcipher *key,
                int direction,
                u32 seqnum,
                unsigned char *cksum, unsigned char *buf)
 {
        unsigned char plain[8];
 
+       if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC)
+               return krb5_make_rc4_seq_num(kctx, direction, seqnum,
+                                            cksum, buf);
+
        plain[0] = (unsigned char) (seqnum & 0xff);
        plain[1] = (unsigned char) ((seqnum >> 8) & 0xff);
        plain[2] = (unsigned char) ((seqnum >> 16) & 0xff);
@@ -60,17 +97,59 @@ krb5_make_seq_num(struct crypto_blkcipher *key,
        return krb5_encrypt(key, cksum, plain, buf, 8);
 }
 
+static s32
+krb5_get_rc4_seq_num(struct krb5_ctx *kctx, unsigned char *cksum,
+                    unsigned char *buf, int *direction, s32 *seqnum)
+{
+       struct crypto_blkcipher *cipher;
+       unsigned char plain[8];
+       s32 code;
+
+       dprintk("RPC:       %s:\n", __func__);
+       cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
+                                       CRYPTO_ALG_ASYNC);
+       if (IS_ERR(cipher))
+               return PTR_ERR(cipher);
+
+       code = krb5_rc4_setup_seq_key(kctx, cipher, cksum);
+       if (code)
+               goto out;
+
+       code = krb5_decrypt(cipher, cksum, buf, plain, 8);
+       if (code)
+               goto out;
+
+       if ((plain[4] != plain[5]) || (plain[4] != plain[6])
+                                  || (plain[4] != plain[7])) {
+               code = (s32)KG_BAD_SEQ;
+               goto out;
+       }
+
+       *direction = plain[4];
+
+       *seqnum = ((plain[0] << 24) | (plain[1] << 16) |
+                                       (plain[2] << 8) | (plain[3]));
+out:
+       crypto_free_blkcipher(cipher);
+       return code;
+}
+
 s32
-krb5_get_seq_num(struct crypto_blkcipher *key,
+krb5_get_seq_num(struct krb5_ctx *kctx,
               unsigned char *cksum,
               unsigned char *buf,
               int *direction, u32 *seqnum)
 {
        s32 code;
        unsigned char plain[8];
+       struct crypto_blkcipher *key = kctx->seq;
 
        dprintk("RPC:       krb5_get_seq_num:\n");
 
+       if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC)
+               return krb5_get_rc4_seq_num(kctx, cksum, buf,
+                                           direction, seqnum);
+
        if ((code = krb5_decrypt(key, cksum, buf, plain, 8)))
                return code;
 
index ce6c247..6cd930f 100644 (file)
@@ -3,7 +3,7 @@
  *
  *  Adapted from MIT Kerberos 5-1.2.1 lib/gssapi/krb5/k5unseal.c
  *
- *  Copyright (c) 2000 The Regents of the University of Michigan.
+ *  Copyright (c) 2000-2008 The Regents of the University of Michigan.
  *  All rights reserved.
  *
  *  Andy Adamson   <andros@umich.edu>
 /* read_token is a mic token, and message_buffer is the data that the mic was
  * supposedly taken over. */
 
-u32
-gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
+static u32
+gss_verify_mic_v1(struct krb5_ctx *ctx,
                struct xdr_buf *message_buffer, struct xdr_netobj *read_token)
 {
-       struct krb5_ctx         *ctx = gss_ctx->internal_ctx_id;
        int                     signalg;
        int                     sealalg;
-       char                    cksumdata[16];
-       struct xdr_netobj       md5cksum = {.len = 0, .data = cksumdata};
+       char                    cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj       md5cksum = {.len = sizeof(cksumdata),
+                                           .data = cksumdata};
        s32                     now;
        int                     direction;
        u32                     seqnum;
        unsigned char           *ptr = (unsigned char *)read_token->data;
        int                     bodysize;
+       u8                      *cksumkey;
 
        dprintk("RPC:       krb5_read_token\n");
 
@@ -98,7 +99,7 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
        /* XXX sanity-check bodysize?? */
 
        signalg = ptr[2] + (ptr[3] << 8);
-       if (signalg != SGN_ALG_DES_MAC_MD5)
+       if (signalg != ctx->gk5e->signalg)
                return GSS_S_DEFECTIVE_TOKEN;
 
        sealalg = ptr[4] + (ptr[5] << 8);
@@ -108,13 +109,17 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
        if ((ptr[6] != 0xff) || (ptr[7] != 0xff))
                return GSS_S_DEFECTIVE_TOKEN;
 
-       if (make_checksum("md5", ptr, 8, message_buffer, 0, &md5cksum))
-               return GSS_S_FAILURE;
+       if (ctx->gk5e->keyed_cksum)
+               cksumkey = ctx->cksum;
+       else
+               cksumkey = NULL;
 
-       if (krb5_encrypt(ctx->seq, NULL, md5cksum.data, md5cksum.data, 16))
+       if (make_checksum(ctx, ptr, 8, message_buffer, 0,
+                         cksumkey, KG_USAGE_SIGN, &md5cksum))
                return GSS_S_FAILURE;
 
-       if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8))
+       if (memcmp(md5cksum.data, ptr + GSS_KRB5_TOK_HDR_LEN,
+                                       ctx->gk5e->cksumlength))
                return GSS_S_BAD_SIG;
 
        /* it got through unscathed.  Make sure the context is unexpired */
@@ -126,7 +131,8 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
 
        /* do sequencing checks */
 
-       if (krb5_get_seq_num(ctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, &direction, &seqnum))
+       if (krb5_get_seq_num(ctx, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8,
+                            &direction, &seqnum))
                return GSS_S_FAILURE;
 
        if ((ctx->initiate && direction != 0xff) ||
@@ -135,3 +141,86 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
 
        return GSS_S_COMPLETE;
 }
+
+static u32
+gss_verify_mic_v2(struct krb5_ctx *ctx,
+               struct xdr_buf *message_buffer, struct xdr_netobj *read_token)
+{
+       char cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj cksumobj = {.len = sizeof(cksumdata),
+                                     .data = cksumdata};
+       s32 now;
+       u64 seqnum;
+       u8 *ptr = read_token->data;
+       u8 *cksumkey;
+       u8 flags;
+       int i;
+       unsigned int cksum_usage;
+
+       dprintk("RPC:       %s\n", __func__);
+
+       if (be16_to_cpu(*((__be16 *)ptr)) != KG2_TOK_MIC)
+               return GSS_S_DEFECTIVE_TOKEN;
+
+       flags = ptr[2];
+       if ((!ctx->initiate && (flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)) ||
+           (ctx->initiate && !(flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)))
+               return GSS_S_BAD_SIG;
+
+       if (flags & KG2_TOKEN_FLAG_SEALED) {
+               dprintk("%s: token has unexpected sealed flag\n", __func__);
+               return GSS_S_FAILURE;
+       }
+
+       for (i = 3; i < 8; i++)
+               if (ptr[i] != 0xff)
+                       return GSS_S_DEFECTIVE_TOKEN;
+
+       if (ctx->initiate) {
+               cksumkey = ctx->acceptor_sign;
+               cksum_usage = KG_USAGE_ACCEPTOR_SIGN;
+       } else {
+               cksumkey = ctx->initiator_sign;
+               cksum_usage = KG_USAGE_INITIATOR_SIGN;
+       }
+
+       if (make_checksum_v2(ctx, ptr, GSS_KRB5_TOK_HDR_LEN, message_buffer, 0,
+                            cksumkey, cksum_usage, &cksumobj))
+               return GSS_S_FAILURE;
+
+       if (memcmp(cksumobj.data, ptr + GSS_KRB5_TOK_HDR_LEN,
+                               ctx->gk5e->cksumlength))
+               return GSS_S_BAD_SIG;
+
+       /* it got through unscathed.  Make sure the context is unexpired */
+       now = get_seconds();
+       if (now > ctx->endtime)
+               return GSS_S_CONTEXT_EXPIRED;
+
+       /* do sequencing checks */
+
+       seqnum = be64_to_cpup((__be64 *)ptr + 8);
+
+       return GSS_S_COMPLETE;
+}
+
+u32
+gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
+                       struct xdr_buf *message_buffer,
+                       struct xdr_netobj *read_token)
+{
+       struct krb5_ctx *ctx = gss_ctx->internal_ctx_id;
+
+       switch (ctx->enctype) {
+       default:
+               BUG();
+       case ENCTYPE_DES_CBC_RAW:
+       case ENCTYPE_DES3_CBC_RAW:
+       case ENCTYPE_ARCFOUR_HMAC:
+               return gss_verify_mic_v1(ctx, message_buffer, read_token);
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               return gss_verify_mic_v2(ctx, message_buffer, read_token);
+       }
+}
+
index a6e9056..2763e3e 100644 (file)
@@ -1,3 +1,33 @@
+/*
+ * COPYRIGHT (c) 2008
+ * The Regents of the University of Michigan
+ * ALL RIGHTS RESERVED
+ *
+ * Permission is granted to use, copy, create derivative works
+ * and redistribute this software and such derivative works
+ * for any purpose, so long as the name of The University of
+ * Michigan is not used in any advertising or publicity
+ * pertaining to the use of distribution of this software
+ * without specific, written prior authorization.  If the
+ * above copyright notice or any other identification of the
+ * University of Michigan is included in any copy of any
+ * portion of this software, then the disclaimer below must
+ * also be included.
+ *
+ * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
+ * FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
+ * PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF
+ * MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
+ * WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
+ * REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
+ * FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
+ * CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
+ * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGES.
+ */
+
 #include <linux/types.h>
 #include <linux/jiffies.h>
 #include <linux/sunrpc/gss_krb5.h>
 static inline int
 gss_krb5_padding(int blocksize, int length)
 {
-       /* Most of the code is block-size independent but currently we
-        * use only 8: */
-       BUG_ON(blocksize != 8);
-       return 8 - (length & 7);
+       return blocksize - (length % blocksize);
 }
 
 static inline void
@@ -86,8 +113,8 @@ out:
        return 0;
 }
 
-static void
-make_confounder(char *p, u32 conflen)
+void
+gss_krb5_make_confounder(char *p, u32 conflen)
 {
        static u64 i = 0;
        u64 *q = (u64 *)p;
@@ -127,69 +154,73 @@ make_confounder(char *p, u32 conflen)
 
 /* XXX factor out common code with seal/unseal. */
 
-u32
-gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
+static u32
+gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
                struct xdr_buf *buf, struct page **pages)
 {
-       struct krb5_ctx         *kctx = ctx->internal_ctx_id;
-       char                    cksumdata[16];
-       struct xdr_netobj       md5cksum = {.len = 0, .data = cksumdata};
+       char                    cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj       md5cksum = {.len = sizeof(cksumdata),
+                                           .data = cksumdata};
        int                     blocksize = 0, plainlen;
        unsigned char           *ptr, *msg_start;
        s32                     now;
        int                     headlen;
        struct page             **tmp_pages;
        u32                     seq_send;
+       u8                      *cksumkey;
+       u32                     conflen = kctx->gk5e->conflen;
 
-       dprintk("RPC:       gss_wrap_kerberos\n");
+       dprintk("RPC:       %s\n", __func__);
 
        now = get_seconds();
 
        blocksize = crypto_blkcipher_blocksize(kctx->enc);
        gss_krb5_add_padding(buf, offset, blocksize);
        BUG_ON((buf->len - offset) % blocksize);
-       plainlen = blocksize + buf->len - offset;
+       plainlen = conflen + buf->len - offset;
 
-       headlen = g_token_size(&kctx->mech_used, 24 + plainlen) -
-                                               (buf->len - offset);
+       headlen = g_token_size(&kctx->mech_used,
+               GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength + plainlen) -
+               (buf->len - offset);
 
        ptr = buf->head[0].iov_base + offset;
        /* shift data to make room for header. */
+       xdr_extend_head(buf, offset, headlen);
+
        /* XXX Would be cleverer to encrypt while copying. */
-       /* XXX bounds checking, slack, etc. */
-       memmove(ptr + headlen, ptr, buf->head[0].iov_len - offset);
-       buf->head[0].iov_len += headlen;
-       buf->len += headlen;
        BUG_ON((buf->len - offset - headlen) % blocksize);
 
        g_make_token_header(&kctx->mech_used,
-                               GSS_KRB5_TOK_HDR_LEN + 8 + plainlen, &ptr);
+                               GSS_KRB5_TOK_HDR_LEN +
+                               kctx->gk5e->cksumlength + plainlen, &ptr);
 
 
        /* ptr now at header described in rfc 1964, section 1.2.1: */
        ptr[0] = (unsigned char) ((KG_TOK_WRAP_MSG >> 8) & 0xff);
        ptr[1] = (unsigned char) (KG_TOK_WRAP_MSG & 0xff);
 
-       msg_start = ptr + 24;
+       msg_start = ptr + GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength;
 
-       *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5);
+       *(__be16 *)(ptr + 2) = cpu_to_le16(kctx->gk5e->signalg);
        memset(ptr + 4, 0xff, 4);
-       *(__be16 *)(ptr + 4) = htons(SEAL_ALG_DES);
+       *(__be16 *)(ptr + 4) = cpu_to_le16(kctx->gk5e->sealalg);
 
-       make_confounder(msg_start, blocksize);
+       gss_krb5_make_confounder(msg_start, conflen);
+
+       if (kctx->gk5e->keyed_cksum)
+               cksumkey = kctx->cksum;
+       else
+               cksumkey = NULL;
 
        /* XXXJBF: UGH!: */
        tmp_pages = buf->pages;
        buf->pages = pages;
-       if (make_checksum("md5", ptr, 8, buf,
-                               offset + headlen - blocksize, &md5cksum))
+       if (make_checksum(kctx, ptr, 8, buf, offset + headlen - conflen,
+                                       cksumkey, KG_USAGE_SEAL, &md5cksum))
                return GSS_S_FAILURE;
        buf->pages = tmp_pages;
 
-       if (krb5_encrypt(kctx->seq, NULL, md5cksum.data,
-                         md5cksum.data, md5cksum.len))
-               return GSS_S_FAILURE;
-       memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8);
+       memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data, md5cksum.len);
 
        spin_lock(&krb5_seq_lock);
        seq_send = kctx->seq_send++;
@@ -197,25 +228,42 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
 
        /* XXX would probably be more efficient to compute checksum
         * and encrypt at the same time: */
-       if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff,
+       if ((krb5_make_seq_num(kctx, kctx->seq, kctx->initiate ? 0 : 0xff,
                               seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8)))
                return GSS_S_FAILURE;
 
-       if (gss_encrypt_xdr_buf(kctx->enc, buf, offset + headlen - blocksize,
-                                                                       pages))
-               return GSS_S_FAILURE;
+       if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC) {
+               struct crypto_blkcipher *cipher;
+               int err;
+               cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
+                                               CRYPTO_ALG_ASYNC);
+               if (IS_ERR(cipher))
+                       return GSS_S_FAILURE;
+
+               krb5_rc4_setup_enc_key(kctx, cipher, seq_send);
+
+               err = gss_encrypt_xdr_buf(cipher, buf,
+                                         offset + headlen - conflen, pages);
+               crypto_free_blkcipher(cipher);
+               if (err)
+                       return GSS_S_FAILURE;
+       } else {
+               if (gss_encrypt_xdr_buf(kctx->enc, buf,
+                                       offset + headlen - conflen, pages))
+                       return GSS_S_FAILURE;
+       }
 
        return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
 }
 
-u32
-gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
+static u32
+gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
 {
-       struct krb5_ctx         *kctx = ctx->internal_ctx_id;
        int                     signalg;
        int                     sealalg;
-       char                    cksumdata[16];
-       struct xdr_netobj       md5cksum = {.len = 0, .data = cksumdata};
+       char                    cksumdata[GSS_KRB5_MAX_CKSUM_LEN];
+       struct xdr_netobj       md5cksum = {.len = sizeof(cksumdata),
+                                           .data = cksumdata};
        s32                     now;
        int                     direction;
        s32                     seqnum;
@@ -224,6 +272,9 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
        void                    *data_start, *orig_start;
        int                     data_len;
        int                     blocksize;
+       u32                     conflen = kctx->gk5e->conflen;
+       int                     crypt_offset;
+       u8                      *cksumkey;
 
        dprintk("RPC:       gss_unwrap_kerberos\n");
 
@@ -241,29 +292,65 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
        /* get the sign and seal algorithms */
 
        signalg = ptr[2] + (ptr[3] << 8);
-       if (signalg != SGN_ALG_DES_MAC_MD5)
+       if (signalg != kctx->gk5e->signalg)
                return GSS_S_DEFECTIVE_TOKEN;
 
        sealalg = ptr[4] + (ptr[5] << 8);
-       if (sealalg != SEAL_ALG_DES)
+       if (sealalg != kctx->gk5e->sealalg)
                return GSS_S_DEFECTIVE_TOKEN;
 
        if ((ptr[6] != 0xff) || (ptr[7] != 0xff))
                return GSS_S_DEFECTIVE_TOKEN;
 
-       if (gss_decrypt_xdr_buf(kctx->enc, buf,
-                       ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base))
-               return GSS_S_DEFECTIVE_TOKEN;
+       /*
+        * Data starts after token header and checksum.  ptr points
+        * to the beginning of the token header
+        */
+       crypt_offset = ptr + (GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength) -
+                                       (unsigned char *)buf->head[0].iov_base;
+
+       /*
+        * Need plaintext seqnum to derive encryption key for arcfour-hmac
+        */
+       if (krb5_get_seq_num(kctx, ptr + GSS_KRB5_TOK_HDR_LEN,
+                            ptr + 8, &direction, &seqnum))
+               return GSS_S_BAD_SIG;
 
-       if (make_checksum("md5", ptr, 8, buf,
-                ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base, &md5cksum))
-               return GSS_S_FAILURE;
+       if ((kctx->initiate && direction != 0xff) ||
+           (!kctx->initiate && direction != 0))
+               return GSS_S_BAD_SIG;
+
+       if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC) {
+               struct crypto_blkcipher *cipher;
+               int err;
+
+               cipher = crypto_alloc_blkcipher(kctx->gk5e->encrypt_name, 0,
+                                               CRYPTO_ALG_ASYNC);
+               if (IS_ERR(cipher))
+                       return GSS_S_FAILURE;
+
+               krb5_rc4_setup_enc_key(kctx, cipher, seqnum);
 
-       if (krb5_encrypt(kctx->seq, NULL, md5cksum.data,
-                          md5cksum.data, md5cksum.len))
+               err = gss_decrypt_xdr_buf(cipher, buf, crypt_offset);
+               crypto_free_blkcipher(cipher);
+               if (err)
+                       return GSS_S_DEFECTIVE_TOKEN;
+       } else {
+               if (gss_decrypt_xdr_buf(kctx->enc, buf, crypt_offset))
+                       return GSS_S_DEFECTIVE_TOKEN;
+       }
+
+       if (kctx->gk5e->keyed_cksum)
+               cksumkey = kctx->cksum;
+       else
+               cksumkey = NULL;
+
+       if (make_checksum(kctx, ptr, 8, buf, crypt_offset,
+                                       cksumkey, KG_USAGE_SEAL, &md5cksum))
                return GSS_S_FAILURE;
 
-       if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8))
+       if (memcmp(md5cksum.data, ptr + GSS_KRB5_TOK_HDR_LEN,
+                                               kctx->gk5e->cksumlength))
                return GSS_S_BAD_SIG;
 
        /* it got through unscathed.  Make sure the context is unexpired */
@@ -275,19 +362,12 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
 
        /* do sequencing checks */
 
-       if (krb5_get_seq_num(kctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8,
-                                   &direction, &seqnum))
-               return GSS_S_BAD_SIG;
-
-       if ((kctx->initiate && direction != 0xff) ||
-           (!kctx->initiate && direction != 0))
-               return GSS_S_BAD_SIG;
-
        /* Copy the data back to the right position.  XXX: Would probably be
         * better to copy and encrypt at the same time. */
 
        blocksize = crypto_blkcipher_blocksize(kctx->enc);
-       data_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8 + blocksize;
+       data_start = ptr + (GSS_KRB5_TOK_HDR_LEN + kctx->gk5e->cksumlength) +
+                                       conflen;
        orig_start = buf->head[0].iov_base + offset;
        data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start;
        memmove(orig_start, data_start, data_len);
@@ -299,3 +379,209 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
 
        return GSS_S_COMPLETE;
 }
+
+/*
+ * We cannot currently handle tokens with rotated data.  We need a
+ * generalized routine to rotate the data in place.  It is anticipated
+ * that we won't encounter rotated data in the general case.
+ */
+static u32
+rotate_left(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf, u16 rrc)
+{
+       unsigned int realrrc = rrc % (buf->len - offset - GSS_KRB5_TOK_HDR_LEN);
+
+       if (realrrc == 0)
+               return 0;
+
+       dprintk("%s: cannot process token with rotated data: "
+               "rrc %u, realrrc %u\n", __func__, rrc, realrrc);
+       return 1;
+}
+
+static u32
+gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
+                    struct xdr_buf *buf, struct page **pages)
+{
+       int             blocksize;
+       u8              *ptr, *plainhdr;
+       s32             now;
+       u8              flags = 0x00;
+       __be16          *be16ptr, ec = 0;
+       __be64          *be64ptr;
+       u32             err;
+
+       dprintk("RPC:       %s\n", __func__);
+
+       if (kctx->gk5e->encrypt_v2 == NULL)
+               return GSS_S_FAILURE;
+
+       /* make room for gss token header */
+       if (xdr_extend_head(buf, offset, GSS_KRB5_TOK_HDR_LEN))
+               return GSS_S_FAILURE;
+
+       /* construct gss token header */
+       ptr = plainhdr = buf->head[0].iov_base + offset;
+       *ptr++ = (unsigned char) ((KG2_TOK_WRAP>>8) & 0xff);
+       *ptr++ = (unsigned char) (KG2_TOK_WRAP & 0xff);
+
+       if ((kctx->flags & KRB5_CTX_FLAG_INITIATOR) == 0)
+               flags |= KG2_TOKEN_FLAG_SENTBYACCEPTOR;
+       if ((kctx->flags & KRB5_CTX_FLAG_ACCEPTOR_SUBKEY) != 0)
+               flags |= KG2_TOKEN_FLAG_ACCEPTORSUBKEY;
+       /* We always do confidentiality in wrap tokens */
+       flags |= KG2_TOKEN_FLAG_SEALED;
+
+       *ptr++ = flags;
+       *ptr++ = 0xff;
+       be16ptr = (__be16 *)ptr;
+
+       blocksize = crypto_blkcipher_blocksize(kctx->acceptor_enc);
+       *be16ptr++ = cpu_to_be16(ec);
+       /* "inner" token header always uses 0 for RRC */
+       *be16ptr++ = cpu_to_be16(0);
+
+       be64ptr = (__be64 *)be16ptr;
+       spin_lock(&krb5_seq_lock);
+       *be64ptr = cpu_to_be64(kctx->seq_send64++);
+       spin_unlock(&krb5_seq_lock);
+
+       err = (*kctx->gk5e->encrypt_v2)(kctx, offset, buf, ec, pages);
+       if (err)
+               return err;
+
+       now = get_seconds();
+       return (kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
+}
+
+static u32
+gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
+{
+       s32             now;
+       u64             seqnum;
+       u8              *ptr;
+       u8              flags = 0x00;
+       u16             ec, rrc;
+       int             err;
+       u32             headskip, tailskip;
+       u8              decrypted_hdr[GSS_KRB5_TOK_HDR_LEN];
+       unsigned int    movelen;
+
+
+       dprintk("RPC:       %s\n", __func__);
+
+       if (kctx->gk5e->decrypt_v2 == NULL)
+               return GSS_S_FAILURE;
+
+       ptr = buf->head[0].iov_base + offset;
+
+       if (be16_to_cpu(*((__be16 *)ptr)) != KG2_TOK_WRAP)
+               return GSS_S_DEFECTIVE_TOKEN;
+
+       flags = ptr[2];
+       if ((!kctx->initiate && (flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)) ||
+           (kctx->initiate && !(flags & KG2_TOKEN_FLAG_SENTBYACCEPTOR)))
+               return GSS_S_BAD_SIG;
+
+       if ((flags & KG2_TOKEN_FLAG_SEALED) == 0) {
+               dprintk("%s: token missing expected sealed flag\n", __func__);
+               return GSS_S_DEFECTIVE_TOKEN;
+       }
+
+       if (ptr[3] != 0xff)
+               return GSS_S_DEFECTIVE_TOKEN;
+
+       ec = be16_to_cpup((__be16 *)(ptr + 4));
+       rrc = be16_to_cpup((__be16 *)(ptr + 6));
+
+       seqnum = be64_to_cpup((__be64 *)(ptr + 8));
+
+       if (rrc != 0) {
+               err = rotate_left(kctx, offset, buf, rrc);
+               if (err)
+                       return GSS_S_FAILURE;
+       }
+
+       err = (*kctx->gk5e->decrypt_v2)(kctx, offset, buf,
+                                       &headskip, &tailskip);
+       if (err)
+               return GSS_S_FAILURE;
+
+       /*
+        * Retrieve the decrypted gss token header and verify
+        * it against the original
+        */
+       err = read_bytes_from_xdr_buf(buf,
+                               buf->len - GSS_KRB5_TOK_HDR_LEN - tailskip,
+                               decrypted_hdr, GSS_KRB5_TOK_HDR_LEN);
+       if (err) {
+               dprintk("%s: error %u getting decrypted_hdr\n", __func__, err);
+               return GSS_S_FAILURE;
+       }
+       if (memcmp(ptr, decrypted_hdr, 6)
+                               || memcmp(ptr + 8, decrypted_hdr + 8, 8)) {
+               dprintk("%s: token hdr, plaintext hdr mismatch!\n", __func__);
+               return GSS_S_FAILURE;
+       }
+
+       /* do sequencing checks */
+
+       /* it got through unscathed.  Make sure the context is unexpired */
+       now = get_seconds();
+       if (now > kctx->endtime)
+               return GSS_S_CONTEXT_EXPIRED;
+
+       /*
+        * Move the head data back to the right position in xdr_buf.
+        * We ignore any "ec" data since it might be in the head or
+        * the tail, and we really don't need to deal with it.
+        * Note that buf->head[0].iov_len may indicate the available
+        * head buffer space rather than that actually occupied.
+        */
+       movelen = min_t(unsigned int, buf->head[0].iov_len, buf->len);
+       movelen -= offset + GSS_KRB5_TOK_HDR_LEN + headskip;
+       BUG_ON(offset + GSS_KRB5_TOK_HDR_LEN + headskip + movelen >
+                                                       buf->head[0].iov_len);
+       memmove(ptr, ptr + GSS_KRB5_TOK_HDR_LEN + headskip, movelen);
+       buf->head[0].iov_len -= GSS_KRB5_TOK_HDR_LEN + headskip;
+       buf->len -= GSS_KRB5_TOK_HDR_LEN + headskip;
+
+       return GSS_S_COMPLETE;
+}
+
+u32
+gss_wrap_kerberos(struct gss_ctx *gctx, int offset,
+                 struct xdr_buf *buf, struct page **pages)
+{
+       struct krb5_ctx *kctx = gctx->internal_ctx_id;
+
+       switch (kctx->enctype) {
+       default:
+               BUG();
+       case ENCTYPE_DES_CBC_RAW:
+       case ENCTYPE_DES3_CBC_RAW:
+       case ENCTYPE_ARCFOUR_HMAC:
+               return gss_wrap_kerberos_v1(kctx, offset, buf, pages);
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               return gss_wrap_kerberos_v2(kctx, offset, buf, pages);
+       }
+}
+
+u32
+gss_unwrap_kerberos(struct gss_ctx *gctx, int offset, struct xdr_buf *buf)
+{
+       struct krb5_ctx *kctx = gctx->internal_ctx_id;
+
+       switch (kctx->enctype) {
+       default:
+               BUG();
+       case ENCTYPE_DES_CBC_RAW:
+       case ENCTYPE_DES3_CBC_RAW:
+       case ENCTYPE_ARCFOUR_HMAC:
+               return gss_unwrap_kerberos_v1(kctx, offset, buf);
+       case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
+       case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
+               return gss_unwrap_kerberos_v2(kctx, offset, buf);
+       }
+}
+
index 76e4c6f..2689de3 100644 (file)
@@ -249,14 +249,15 @@ EXPORT_SYMBOL_GPL(gss_mech_put);
 int
 gss_import_sec_context(const void *input_token, size_t bufsize,
                       struct gss_api_mech      *mech,
-                      struct gss_ctx           **ctx_id)
+                      struct gss_ctx           **ctx_id,
+                      gfp_t gfp_mask)
 {
-       if (!(*ctx_id = kzalloc(sizeof(**ctx_id), GFP_KERNEL)))
+       if (!(*ctx_id = kzalloc(sizeof(**ctx_id), gfp_mask)))
                return -ENOMEM;
        (*ctx_id)->mech_type = gss_mech_get(mech);
 
        return mech->gm_ops
-               ->gss_import_sec_context(input_token, bufsize, *ctx_id);
+               ->gss_import_sec_context(input_token, bufsize, *ctx_id, gfp_mask);
 }
 
 /* gss_get_mic: compute a mic over message and return mic_token. */
@@ -285,6 +286,20 @@ gss_verify_mic(struct gss_ctx              *context_handle,
                                 mic_token);
 }
 
+/*
+ * This function is called from both the client and server code.
+ * Each makes guarantees about how much "slack" space is available
+ * for the underlying function in "buf"'s head and tail while
+ * performing the wrap.
+ *
+ * The client and server code allocate RPC_MAX_AUTH_SIZE extra
+ * space in both the head and tail which is available for use by
+ * the wrap function.
+ *
+ * Underlying functions should verify they do not use more than
+ * RPC_MAX_AUTH_SIZE of extra space in either the head or tail
+ * when performing the wrap.
+ */
 u32
 gss_wrap(struct gss_ctx        *ctx_id,
         int            offset,
index 035e1dd..dc3f1f5 100644 (file)
@@ -84,13 +84,14 @@ simple_get_netobj(const void *p, const void *end, struct xdr_netobj *res)
 
 static int
 gss_import_sec_context_spkm3(const void *p, size_t len,
-                               struct gss_ctx *ctx_id)
+                               struct gss_ctx *ctx_id,
+                               gfp_t gfp_mask)
 {
        const void *end = (const void *)((const char *)p + len);
        struct  spkm3_ctx *ctx;
        int     version;
 
-       if (!(ctx = kzalloc(sizeof(*ctx), GFP_NOFS)))
+       if (!(ctx = kzalloc(sizeof(*ctx), gfp_mask)))
                goto out_err;
 
        p = simple_get_bytes(p, end, &version, sizeof(version));
index b81e790..cc385b3 100644 (file)
@@ -494,7 +494,7 @@ static int rsc_parse(struct cache_detail *cd,
                len = qword_get(&mesg, buf, mlen);
                if (len < 0)
                        goto out;
-               status = gss_import_sec_context(buf, len, gm, &rsci.mechctx);
+               status = gss_import_sec_context(buf, len, gm, &rsci.mechctx, GFP_KERNEL);
                if (status)
                        goto out;
 
@@ -1315,6 +1315,14 @@ svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp)
        inpages = resbuf->pages;
        /* XXX: Would be better to write some xdr helper functions for
         * nfs{2,3,4}xdr.c that place the data right, instead of copying: */
+
+       /*
+        * If there is currently tail data, make sure there is
+        * room for the head, tail, and 2 * RPC_MAX_AUTH_SIZE in
+        * the page, and move the current tail data such that
+        * there is RPC_MAX_AUTH_SIZE slack space available in
+        * both the head and tail.
+        */
        if (resbuf->tail[0].iov_base) {
                BUG_ON(resbuf->tail[0].iov_base >= resbuf->head[0].iov_base
                                                        + PAGE_SIZE);
@@ -1327,6 +1335,13 @@ svcauth_gss_wrap_resp_priv(struct svc_rqst *rqstp)
                        resbuf->tail[0].iov_len);
                resbuf->tail[0].iov_base += RPC_MAX_AUTH_SIZE;
        }
+       /*
+        * If there is no current tail data, make sure there is
+        * room for the head data, and 2 * RPC_MAX_AUTH_SIZE in the
+        * allotted page, and set up tail information such that there
+        * is RPC_MAX_AUTH_SIZE slack space available in both the
+        * head and tail.
+        */
        if (resbuf->tail[0].iov_base == NULL) {
                if (resbuf->head[0].iov_len + 2*RPC_MAX_AUTH_SIZE > PAGE_SIZE)
                        return -ENOMEM;
index 39bddba..c2173eb 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/workqueue.h>
 #include <linux/mutex.h>
 #include <linux/pagemap.h>
+#include <linux/smp_lock.h>
 #include <asm/ioctls.h>
 #include <linux/sunrpc/types.h>
 #include <linux/sunrpc/cache.h>
@@ -49,11 +50,17 @@ static void cache_init(struct cache_head *h)
        h->last_refresh = now;
 }
 
+static inline int cache_is_expired(struct cache_detail *detail, struct cache_head *h)
+{
+       return  (h->expiry_time < get_seconds()) ||
+               (detail->flush_time > h->last_refresh);
+}
+
 struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
                                       struct cache_head *key, int hash)
 {
        struct cache_head **head,  **hp;
-       struct cache_head *new = NULL;
+       struct cache_head *new = NULL, *freeme = NULL;
 
        head = &detail->hash_table[hash];
 
@@ -62,6 +69,9 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
        for (hp=head; *hp != NULL ; hp = &(*hp)->next) {
                struct cache_head *tmp = *hp;
                if (detail->match(tmp, key)) {
+                       if (cache_is_expired(detail, tmp))
+                               /* This entry is expired, we will discard it. */
+                               break;
                        cache_get(tmp);
                        read_unlock(&detail->hash_lock);
                        return tmp;
@@ -86,6 +96,13 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
        for (hp=head; *hp != NULL ; hp = &(*hp)->next) {
                struct cache_head *tmp = *hp;
                if (detail->match(tmp, key)) {
+                       if (cache_is_expired(detail, tmp)) {
+                               *hp = tmp->next;
+                               tmp->next = NULL;
+                               detail->entries --;
+                               freeme = tmp;
+                               break;
+                       }
                        cache_get(tmp);
                        write_unlock(&detail->hash_lock);
                        cache_put(new, detail);
@@ -98,6 +115,8 @@ struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
        cache_get(new);
        write_unlock(&detail->hash_lock);
 
+       if (freeme)
+               cache_put(freeme, detail);
        return new;
 }
 EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
@@ -183,10 +202,7 @@ static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
 
 static inline int cache_is_valid(struct cache_detail *detail, struct cache_head *h)
 {
-       if (!test_bit(CACHE_VALID, &h->flags) ||
-           h->expiry_time < get_seconds())
-               return -EAGAIN;
-       else if (detail->flush_time > h->last_refresh)
+       if (!test_bit(CACHE_VALID, &h->flags))
                return -EAGAIN;
        else {
                /* entry is valid */
@@ -397,31 +413,27 @@ static int cache_clean(void)
                /* Ok, now to clean this strand */
 
                cp = & current_detail->hash_table[current_index];
-               ch = *cp;
-               for (; ch; cp= & ch->next, ch= *cp) {
+               for (ch = *cp ; ch ; cp = & ch->next, ch = *cp) {
                        if (current_detail->nextcheck > ch->expiry_time)
                                current_detail->nextcheck = ch->expiry_time+1;
-                       if (ch->expiry_time >= get_seconds() &&
-                           ch->last_refresh >= current_detail->flush_time)
+                       if (!cache_is_expired(current_detail, ch))
                                continue;
-                       if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
-                               cache_dequeue(current_detail, ch);
 
-                       if (atomic_read(&ch->ref.refcount) == 1)
-                               break;
-               }
-               if (ch) {
                        *cp = ch->next;
                        ch->next = NULL;
                        current_detail->entries--;
                        rv = 1;
+                       break;
                }
+
                write_unlock(&current_detail->hash_lock);
                d = current_detail;
                if (!ch)
                        current_index ++;
                spin_unlock(&cache_list_lock);
                if (ch) {
+                       if (test_and_clear_bit(CACHE_PENDING, &ch->flags))
+                               cache_dequeue(current_detail, ch);
                        cache_revisit_request(ch);
                        cache_put(ch, d);
                }
@@ -1233,8 +1245,10 @@ static int content_open(struct inode *inode, struct file *file,
        if (!cd || !try_module_get(cd->owner))
                return -EACCES;
        han = __seq_open_private(file, &cache_content_op, sizeof(*han));
-       if (han == NULL)
+       if (han == NULL) {
+               module_put(cd->owner);
                return -ENOMEM;
+       }
 
        han->cd = cd;
        return 0;
@@ -1331,12 +1345,18 @@ static unsigned int cache_poll_procfs(struct file *filp, poll_table *wait)
        return cache_poll(filp, wait, cd);
 }
 
-static int cache_ioctl_procfs(struct inode *inode, struct file *filp,
-                             unsigned int cmd, unsigned long arg)
+static long cache_ioctl_procfs(struct file *filp,
+                              unsigned int cmd, unsigned long arg)
 {
+       long ret;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct cache_detail *cd = PDE(inode)->data;
 
-       return cache_ioctl(inode, filp, cmd, arg, cd);
+       lock_kernel();
+       ret = cache_ioctl(inode, filp, cmd, arg, cd);
+       unlock_kernel();
+
+       return ret;
 }
 
 static int cache_open_procfs(struct inode *inode, struct file *filp)
@@ -1359,7 +1379,7 @@ static const struct file_operations cache_file_operations_procfs = {
        .read           = cache_read_procfs,
        .write          = cache_write_procfs,
        .poll           = cache_poll_procfs,
-       .ioctl          = cache_ioctl_procfs, /* for FIONREAD */
+       .unlocked_ioctl = cache_ioctl_procfs, /* for FIONREAD */
        .open           = cache_open_procfs,
        .release        = cache_release_procfs,
 };
index 19c9983..8c7b543 100644 (file)
@@ -556,26 +556,16 @@ static const struct rpc_call_ops rpc_default_ops = {
  */
 struct rpc_task *rpc_run_task(const struct rpc_task_setup *task_setup_data)
 {
-       struct rpc_task *task, *ret;
+       struct rpc_task *task;
 
        task = rpc_new_task(task_setup_data);
-       if (task == NULL) {
-               rpc_release_calldata(task_setup_data->callback_ops,
-                               task_setup_data->callback_data);
-               ret = ERR_PTR(-ENOMEM);
+       if (IS_ERR(task))
                goto out;
-       }
 
-       if (task->tk_status != 0) {
-               ret = ERR_PTR(task->tk_status);
-               rpc_put_task(task);
-               goto out;
-       }
        atomic_inc(&task->tk_count);
        rpc_execute(task);
-       ret = task;
 out:
-       return ret;
+       return task;
 }
 EXPORT_SYMBOL_GPL(rpc_run_task);
 
@@ -657,9 +647,8 @@ struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
         * Create an rpc_task to send the data
         */
        task = rpc_new_task(&task_setup_data);
-       if (!task) {
+       if (IS_ERR(task)) {
                xprt_free_bc_request(req);
-               task = ERR_PTR(-ENOMEM);
                goto out;
        }
        task->tk_rqstp = req;
index aae6907..4a843b8 100644 (file)
@@ -25,7 +25,6 @@
 
 #ifdef RPC_DEBUG
 #define RPCDBG_FACILITY                RPCDBG_SCHED
-#define RPC_TASK_MAGIC_ID      0xf00baa
 #endif
 
 /*
@@ -237,7 +236,6 @@ static void rpc_task_set_debuginfo(struct rpc_task *task)
 {
        static atomic_t rpc_pid;
 
-       task->tk_magic = RPC_TASK_MAGIC_ID;
        task->tk_pid = atomic_inc_return(&rpc_pid);
 }
 #else
@@ -360,9 +358,6 @@ static void __rpc_do_wake_up_task(struct rpc_wait_queue *queue, struct rpc_task
        dprintk("RPC: %5u __rpc_wake_up_task (now %lu)\n",
                        task->tk_pid, jiffies);
 
-#ifdef RPC_DEBUG
-       BUG_ON(task->tk_magic != RPC_TASK_MAGIC_ID);
-#endif
        /* Has the task been executed yet? If not, we cannot wake it up! */
        if (!RPC_IS_ACTIVATED(task)) {
                printk(KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task);
@@ -834,7 +829,7 @@ static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *ta
        }
 
        /* starting timestamp */
-       task->tk_start = jiffies;
+       task->tk_start = ktime_get();
 
        dprintk("RPC:       new task initialized, procpid %u\n",
                                task_pid_nr(current));
@@ -856,16 +851,23 @@ struct rpc_task *rpc_new_task(const struct rpc_task_setup *setup_data)
 
        if (task == NULL) {
                task = rpc_alloc_task();
-               if (task == NULL)
-                       goto out;
+               if (task == NULL) {
+                       rpc_release_calldata(setup_data->callback_ops,
+                                       setup_data->callback_data);
+                       return ERR_PTR(-ENOMEM);
+               }
                flags = RPC_TASK_DYNAMIC;
        }
 
        rpc_init_task(task, setup_data);
+       if (task->tk_status < 0) {
+               int err = task->tk_status;
+               rpc_put_task(task);
+               return ERR_PTR(err);
+       }
 
        task->tk_flags |= flags;
        dprintk("RPC:       allocated task %p\n", task);
-out:
        return task;
 }
 
@@ -909,9 +911,6 @@ EXPORT_SYMBOL_GPL(rpc_put_task);
 
 static void rpc_release_task(struct rpc_task *task)
 {
-#ifdef RPC_DEBUG
-       BUG_ON(task->tk_magic != RPC_TASK_MAGIC_ID);
-#endif
        dprintk("RPC: %5u release task\n", task->tk_pid);
 
        if (!list_empty(&task->tk_task)) {
@@ -923,9 +922,6 @@ static void rpc_release_task(struct rpc_task *task)
        }
        BUG_ON (RPC_IS_QUEUED(task));
 
-#ifdef RPC_DEBUG
-       task->tk_magic = 0;
-#endif
        /* Wake up anyone who is waiting for task completion */
        rpc_mark_complete_task(task);
 
index 5785d20..ea1046f 100644 (file)
@@ -144,7 +144,7 @@ void rpc_count_iostats(struct rpc_task *task)
        struct rpc_rqst *req = task->tk_rqstp;
        struct rpc_iostats *stats;
        struct rpc_iostats *op_metrics;
-       long rtt, execute, queue;
+       ktime_t delta;
 
        if (!task->tk_client || !task->tk_client->cl_metrics || !req)
                return;
@@ -156,23 +156,16 @@ void rpc_count_iostats(struct rpc_task *task)
        op_metrics->om_ntrans += req->rq_ntrans;
        op_metrics->om_timeouts += task->tk_timeouts;
 
-       op_metrics->om_bytes_sent += task->tk_bytes_sent;
+       op_metrics->om_bytes_sent += req->rq_xmit_bytes_sent;
        op_metrics->om_bytes_recv += req->rq_reply_bytes_recvd;
 
-       queue = (long)req->rq_xtime - task->tk_start;
-       if (queue < 0)
-               queue = -queue;
-       op_metrics->om_queue += queue;
+       delta = ktime_sub(req->rq_xtime, task->tk_start);
+       op_metrics->om_queue = ktime_add(op_metrics->om_queue, delta);
 
-       rtt = task->tk_rtt;
-       if (rtt < 0)
-               rtt = -rtt;
-       op_metrics->om_rtt += rtt;
+       op_metrics->om_rtt = ktime_add(op_metrics->om_rtt, req->rq_rtt);
 
-       execute = (long)jiffies - task->tk_start;
-       if (execute < 0)
-               execute = -execute;
-       op_metrics->om_execute += execute;
+       delta = ktime_sub(ktime_get(), task->tk_start);
+       op_metrics->om_execute = ktime_add(op_metrics->om_execute, delta);
 }
 
 static void _print_name(struct seq_file *seq, unsigned int op,
@@ -186,8 +179,6 @@ static void _print_name(struct seq_file *seq, unsigned int op,
                seq_printf(seq, "\t%12u: ", op);
 }
 
-#define MILLISECS_PER_JIFFY    (1000 / HZ)
-
 void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
 {
        struct rpc_iostats *stats = clnt->cl_metrics;
@@ -214,9 +205,9 @@ void rpc_print_iostats(struct seq_file *seq, struct rpc_clnt *clnt)
                                metrics->om_timeouts,
                                metrics->om_bytes_sent,
                                metrics->om_bytes_recv,
-                               metrics->om_queue * MILLISECS_PER_JIFFY,
-                               metrics->om_rtt * MILLISECS_PER_JIFFY,
-                               metrics->om_execute * MILLISECS_PER_JIFFY);
+                               ktime_to_ms(metrics->om_queue),
+                               ktime_to_ms(metrics->om_rtt),
+                               ktime_to_ms(metrics->om_execute));
        }
 }
 EXPORT_SYMBOL_GPL(rpc_print_iostats);
index 061b2e0..cbc0849 100644 (file)
@@ -744,8 +744,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
                if (rqstp->rq_deferred) {
                        svc_xprt_received(xprt);
                        len = svc_deferred_recv(rqstp);
-               } else
+               } else {
                        len = xprt->xpt_ops->xpo_recvfrom(rqstp);
+                       svc_xprt_received(xprt);
+               }
                dprintk("svc: got len=%d\n", len);
        }
 
@@ -893,12 +895,12 @@ void svc_delete_xprt(struct svc_xprt *xprt)
         */
        if (test_bit(XPT_TEMP, &xprt->xpt_flags))
                serv->sv_tmpcnt--;
+       spin_unlock_bh(&serv->sv_lock);
 
        while ((dr = svc_deferred_dequeue(xprt)) != NULL)
                kfree(dr);
 
        svc_xprt_put(xprt);
-       spin_unlock_bh(&serv->sv_lock);
 }
 
 void svc_close_xprt(struct svc_xprt *xprt)
index a29f259..a338927 100644 (file)
@@ -547,7 +547,6 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
                        dprintk("svc: recvfrom returned error %d\n", -err);
                        set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags);
                }
-               svc_xprt_received(&svsk->sk_xprt);
                return -EAGAIN;
        }
        len = svc_addr_len(svc_addr(rqstp));
@@ -562,11 +561,6 @@ static int svc_udp_recvfrom(struct svc_rqst *rqstp)
        svsk->sk_sk->sk_stamp = skb->tstamp;
        set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); /* there may be more data... */
 
-       /*
-        * Maybe more packets - kick another thread ASAP.
-        */
-       svc_xprt_received(&svsk->sk_xprt);
-
        len  = skb->len - sizeof(struct udphdr);
        rqstp->rq_arg.len = len;
 
@@ -917,7 +911,6 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
                if (len < want) {
                        dprintk("svc: short recvfrom while reading record "
                                "length (%d of %d)\n", len, want);
-                       svc_xprt_received(&svsk->sk_xprt);
                        goto err_again; /* record header not complete */
                }
 
@@ -953,7 +946,6 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
        if (len < svsk->sk_reclen) {
                dprintk("svc: incomplete TCP record (%d of %d)\n",
                        len, svsk->sk_reclen);
-               svc_xprt_received(&svsk->sk_xprt);
                goto err_again; /* record not complete */
        }
        len = svsk->sk_reclen;
@@ -961,14 +953,11 @@ static int svc_tcp_recv_record(struct svc_sock *svsk, struct svc_rqst *rqstp)
 
        return len;
  error:
-       if (len == -EAGAIN) {
+       if (len == -EAGAIN)
                dprintk("RPC: TCP recv_record got EAGAIN\n");
-               svc_xprt_received(&svsk->sk_xprt);
-       }
        return len;
  err_delete:
        set_bit(XPT_CLOSE, &svsk->sk_xprt.xpt_flags);
-       svc_xprt_received(&svsk->sk_xprt);
  err_again:
        return -EAGAIN;
 }
@@ -1110,7 +1099,6 @@ out:
        svsk->sk_tcplen = 0;
 
        svc_xprt_copy_addrs(rqstp, &svsk->sk_xprt);
-       svc_xprt_received(&svsk->sk_xprt);
        if (serv->sv_stats)
                serv->sv_stats->nettcpcnt++;
 
@@ -1119,7 +1107,6 @@ out:
 err_again:
        if (len == -EAGAIN) {
                dprintk("RPC: TCP recvfrom got EAGAIN\n");
-               svc_xprt_received(&svsk->sk_xprt);
                return len;
        }
 error:
index 2763fde..a1f82a8 100644 (file)
@@ -762,6 +762,7 @@ int write_bytes_to_xdr_buf(struct xdr_buf *buf, unsigned int base, void *obj, un
        __write_bytes_to_xdr_buf(&subbuf, obj, len);
        return 0;
 }
+EXPORT_SYMBOL_GPL(write_bytes_to_xdr_buf);
 
 int
 xdr_decode_word(struct xdr_buf *buf, unsigned int base, u32 *obj)
index 42f09ad..65fe2e4 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/interrupt.h>
 #include <linux/workqueue.h>
 #include <linux/net.h>
+#include <linux/ktime.h>
 
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/metrics.h>
@@ -62,7 +63,6 @@
  * Local functions
  */
 static void    xprt_request_init(struct rpc_task *, struct rpc_xprt *);
-static inline void     do_xprt_reserve(struct rpc_task *);
 static void    xprt_connect_status(struct rpc_task *task);
 static int      __xprt_get_cong(struct rpc_xprt *, struct rpc_task *);
 
@@ -711,12 +711,16 @@ void xprt_connect(struct rpc_task *task)
                if (task->tk_rqstp)
                        task->tk_rqstp->rq_bytes_sent = 0;
 
-               task->tk_timeout = xprt->connect_timeout;
+               task->tk_timeout = task->tk_rqstp->rq_timeout;
                rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
+
+               if (test_bit(XPRT_CLOSING, &xprt->state))
+                       return;
+               if (xprt_test_and_set_connecting(xprt))
+                       return;
                xprt->stat.connect_start = jiffies;
                xprt->ops->connect(task);
        }
-       return;
 }
 
 static void xprt_connect_status(struct rpc_task *task)
@@ -771,25 +775,19 @@ struct rpc_rqst *xprt_lookup_rqst(struct rpc_xprt *xprt, __be32 xid)
 }
 EXPORT_SYMBOL_GPL(xprt_lookup_rqst);
 
-/**
- * xprt_update_rtt - update an RPC client's RTT state after receiving a reply
- * @task: RPC request that recently completed
- *
- */
-void xprt_update_rtt(struct rpc_task *task)
+static void xprt_update_rtt(struct rpc_task *task)
 {
        struct rpc_rqst *req = task->tk_rqstp;
        struct rpc_rtt *rtt = task->tk_client->cl_rtt;
        unsigned timer = task->tk_msg.rpc_proc->p_timer;
+       long m = usecs_to_jiffies(ktime_to_us(req->rq_rtt));
 
        if (timer) {
                if (req->rq_ntrans == 1)
-                       rpc_update_rtt(rtt, timer,
-                                       (long)jiffies - req->rq_xtime);
+                       rpc_update_rtt(rtt, timer, m);
                rpc_set_timeo(rtt, timer, req->rq_ntrans - 1);
        }
 }
-EXPORT_SYMBOL_GPL(xprt_update_rtt);
 
 /**
  * xprt_complete_rqst - called when reply processing is complete
@@ -807,7 +805,9 @@ void xprt_complete_rqst(struct rpc_task *task, int copied)
                        task->tk_pid, ntohl(req->rq_xid), copied);
 
        xprt->stat.recvs++;
-       task->tk_rtt = (long)jiffies - req->rq_xtime;
+       req->rq_rtt = ktime_sub(ktime_get(), req->rq_xtime);
+       if (xprt->ops->timer != NULL)
+               xprt_update_rtt(task);
 
        list_del_init(&req->rq_list);
        req->rq_private_buf.len = copied;
@@ -906,7 +906,7 @@ void xprt_transmit(struct rpc_task *task)
                return;
 
        req->rq_connect_cookie = xprt->connect_cookie;
-       req->rq_xtime = jiffies;
+       req->rq_xtime = ktime_get();
        status = xprt->ops->send_request(task);
        if (status != 0) {
                task->tk_status = status;
@@ -935,7 +935,7 @@ void xprt_transmit(struct rpc_task *task)
        spin_unlock_bh(&xprt->transport_lock);
 }
 
-static inline void do_xprt_reserve(struct rpc_task *task)
+static void xprt_alloc_slot(struct rpc_task *task)
 {
        struct rpc_xprt *xprt = task->tk_xprt;
 
@@ -955,6 +955,16 @@ static inline void do_xprt_reserve(struct rpc_task *task)
        rpc_sleep_on(&xprt->backlog, task, NULL);
 }
 
+static void xprt_free_slot(struct rpc_xprt *xprt, struct rpc_rqst *req)
+{
+       memset(req, 0, sizeof(*req));   /* mark unused */
+
+       spin_lock(&xprt->reserve_lock);
+       list_add(&req->rq_list, &xprt->free);
+       rpc_wake_up_next(&xprt->backlog);
+       spin_unlock(&xprt->reserve_lock);
+}
+
 /**
  * xprt_reserve - allocate an RPC request slot
  * @task: RPC task requesting a slot allocation
@@ -968,7 +978,7 @@ void xprt_reserve(struct rpc_task *task)
 
        task->tk_status = -EIO;
        spin_lock(&xprt->reserve_lock);
-       do_xprt_reserve(task);
+       xprt_alloc_slot(task);
        spin_unlock(&xprt->reserve_lock);
 }
 
@@ -1006,14 +1016,10 @@ void xprt_release(struct rpc_task *task)
 {
        struct rpc_xprt *xprt;
        struct rpc_rqst *req;
-       int is_bc_request;
 
        if (!(req = task->tk_rqstp))
                return;
 
-       /* Preallocated backchannel request? */
-       is_bc_request = bc_prealloc(req);
-
        xprt = req->rq_xprt;
        rpc_count_iostats(task);
        spin_lock_bh(&xprt->transport_lock);
@@ -1027,21 +1033,16 @@ void xprt_release(struct rpc_task *task)
                mod_timer(&xprt->timer,
                                xprt->last_used + xprt->idle_timeout);
        spin_unlock_bh(&xprt->transport_lock);
-       if (!bc_prealloc(req))
+       if (req->rq_buffer)
                xprt->ops->buf_free(req->rq_buffer);
        task->tk_rqstp = NULL;
        if (req->rq_release_snd_buf)
                req->rq_release_snd_buf(req);
 
        dprintk("RPC: %5u release request %p\n", task->tk_pid, req);
-       if (likely(!is_bc_request)) {
-               memset(req, 0, sizeof(*req));   /* mark unused */
-
-               spin_lock(&xprt->reserve_lock);
-               list_add(&req->rq_list, &xprt->free);
-               rpc_wake_up_next(&xprt->backlog);
-               spin_unlock(&xprt->reserve_lock);
-       } else
+       if (likely(!bc_prealloc(req)))
+               xprt_free_slot(xprt, req);
+       else
                xprt_free_bc_request(req);
 }
 
index f92e37e..0194de8 100644 (file)
@@ -566,7 +566,6 @@ static int rdma_read_complete(struct svc_rqst *rqstp,
                ret, rqstp->rq_arg.len, rqstp->rq_arg.head[0].iov_base,
                rqstp->rq_arg.head[0].iov_len);
 
-       svc_xprt_received(rqstp->rq_xprt);
        return ret;
 }
 
@@ -665,7 +664,6 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
                rqstp->rq_arg.head[0].iov_len);
        rqstp->rq_prot = IPPROTO_MAX;
        svc_xprt_copy_addrs(rqstp, xprt);
-       svc_xprt_received(xprt);
        return ret;
 
  close_out:
@@ -678,6 +676,5 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
         */
        set_bit(XPT_CLOSE, &xprt->xpt_flags);
 defer:
-       svc_xprt_received(xprt);
        return 0;
 }
index 187257b..a85e866 100644 (file)
@@ -305,7 +305,6 @@ xprt_setup_rdma(struct xprt_create *args)
        /* 60 second timeout, no retries */
        xprt->timeout = &xprt_rdma_default_timeout;
        xprt->bind_timeout = (60U * HZ);
-       xprt->connect_timeout = (60U * HZ);
        xprt->reestablish_timeout = (5U * HZ);
        xprt->idle_timeout = (5U * 60 * HZ);
 
@@ -449,21 +448,19 @@ xprt_rdma_connect(struct rpc_task *task)
        struct rpc_xprt *xprt = (struct rpc_xprt *)task->tk_xprt;
        struct rpcrdma_xprt *r_xprt = rpcx_to_rdmax(xprt);
 
-       if (!xprt_test_and_set_connecting(xprt)) {
-               if (r_xprt->rx_ep.rep_connected != 0) {
-                       /* Reconnect */
-                       schedule_delayed_work(&r_xprt->rdma_connect,
-                               xprt->reestablish_timeout);
-                       xprt->reestablish_timeout <<= 1;
-                       if (xprt->reestablish_timeout > (30 * HZ))
-                               xprt->reestablish_timeout = (30 * HZ);
-                       else if (xprt->reestablish_timeout < (5 * HZ))
-                               xprt->reestablish_timeout = (5 * HZ);
-               } else {
-                       schedule_delayed_work(&r_xprt->rdma_connect, 0);
-                       if (!RPC_IS_ASYNC(task))
-                               flush_scheduled_work();
-               }
+       if (r_xprt->rx_ep.rep_connected != 0) {
+               /* Reconnect */
+               schedule_delayed_work(&r_xprt->rdma_connect,
+                       xprt->reestablish_timeout);
+               xprt->reestablish_timeout <<= 1;
+               if (xprt->reestablish_timeout > (30 * HZ))
+                       xprt->reestablish_timeout = (30 * HZ);
+               else if (xprt->reestablish_timeout < (5 * HZ))
+                       xprt->reestablish_timeout = (5 * HZ);
+       } else {
+               schedule_delayed_work(&r_xprt->rdma_connect, 0);
+               if (!RPC_IS_ASYNC(task))
+                       flush_scheduled_work();
        }
 }
 
@@ -677,7 +674,7 @@ xprt_rdma_send_request(struct rpc_task *task)
        if (rpcrdma_ep_post(&r_xprt->rx_ia, &r_xprt->rx_ep, req))
                goto drop_connection;
 
-       task->tk_bytes_sent += rqst->rq_snd_buf.len;
+       rqst->rq_xmit_bytes_sent += rqst->rq_snd_buf.len;
        rqst->rq_bytes_sent = 0;
        return 0;
 
index 9847c30..02fc7f0 100644 (file)
@@ -137,20 +137,6 @@ static ctl_table sunrpc_table[] = {
 
 #endif
 
-/*
- * Time out for an RPC UDP socket connect.  UDP socket connects are
- * synchronous, but we set a timeout anyway in case of resource
- * exhaustion on the local host.
- */
-#define XS_UDP_CONN_TO         (5U * HZ)
-
-/*
- * Wait duration for an RPC TCP connection to be established.  Solaris
- * NFS over TCP uses 60 seconds, for example, which is in line with how
- * long a server takes to reboot.
- */
-#define XS_TCP_CONN_TO         (60U * HZ)
-
 /*
  * Wait duration for a reply from the RPC portmapper.
  */
@@ -542,7 +528,7 @@ static int xs_udp_send_request(struct rpc_task *task)
                        xdr->len - req->rq_bytes_sent, status);
 
        if (status >= 0) {
-               task->tk_bytes_sent += status;
+               req->rq_xmit_bytes_sent += status;
                if (status >= req->rq_slen)
                        return 0;
                /* Still some bytes left; set up for a retry later. */
@@ -638,7 +624,7 @@ static int xs_tcp_send_request(struct rpc_task *task)
                /* If we've sent the entire packet, immediately
                 * reset the count of bytes sent. */
                req->rq_bytes_sent += status;
-               task->tk_bytes_sent += status;
+               req->rq_xmit_bytes_sent += status;
                if (likely(req->rq_bytes_sent >= req->rq_slen)) {
                        req->rq_bytes_sent = 0;
                        return 0;
@@ -858,7 +844,6 @@ static void xs_udp_data_ready(struct sock *sk, int len)
        dst_confirm(skb_dst(skb));
 
        xprt_adjust_cwnd(task, copied);
-       xprt_update_rtt(task);
        xprt_complete_rqst(task, copied);
 
  out_unlock:
@@ -2016,9 +2001,6 @@ static void xs_connect(struct rpc_task *task)
        struct rpc_xprt *xprt = task->tk_xprt;
        struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
 
-       if (xprt_test_and_set_connecting(xprt))
-               return;
-
        if (transport->sock != NULL && !RPC_IS_SOFTCONN(task)) {
                dprintk("RPC:       xs_connect delayed xprt %p for %lu "
                                "seconds\n",
@@ -2038,16 +2020,6 @@ static void xs_connect(struct rpc_task *task)
        }
 }
 
-static void xs_tcp_connect(struct rpc_task *task)
-{
-       struct rpc_xprt *xprt = task->tk_xprt;
-
-       /* Exit if we need to wait for socket shutdown to complete */
-       if (test_bit(XPRT_CLOSING, &xprt->state))
-               return;
-       xs_connect(task);
-}
-
 /**
  * xs_udp_print_stats - display UDP socket-specifc stats
  * @xprt: rpc_xprt struct containing statistics
@@ -2246,7 +2218,7 @@ static struct rpc_xprt_ops xs_tcp_ops = {
        .release_xprt           = xs_tcp_release_xprt,
        .rpcbind                = rpcb_getport_async,
        .set_port               = xs_set_port,
-       .connect                = xs_tcp_connect,
+       .connect                = xs_connect,
        .buf_alloc              = rpc_malloc,
        .buf_free               = rpc_free,
        .send_request           = xs_tcp_send_request,
@@ -2337,7 +2309,6 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
        xprt->max_payload = (1U << 16) - (MAX_HEADER << 3);
 
        xprt->bind_timeout = XS_BIND_TO;
-       xprt->connect_timeout = XS_UDP_CONN_TO;
        xprt->reestablish_timeout = XS_UDP_REEST_TO;
        xprt->idle_timeout = XS_IDLE_DISC_TO;
 
@@ -2412,7 +2383,6 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
        xprt->max_payload = RPC_MAX_FRAGMENT_SIZE;
 
        xprt->bind_timeout = XS_BIND_TO;
-       xprt->connect_timeout = XS_TCP_CONN_TO;
        xprt->reestablish_timeout = XS_TCP_INIT_REEST_TO;
        xprt->idle_timeout = XS_IDLE_DISC_TO;
 
@@ -2472,9 +2442,6 @@ static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
        struct sock_xprt *transport;
        struct svc_sock *bc_sock;
 
-       if (!args->bc_xprt)
-               ERR_PTR(-EINVAL);
-
        xprt = xs_setup_xprt(args, xprt_tcp_slot_table_entries);
        if (IS_ERR(xprt))
                return xprt;
@@ -2488,7 +2455,6 @@ static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
        /* backchannel */
        xprt_set_bound(xprt);
        xprt->bind_timeout = 0;
-       xprt->connect_timeout = 0;
        xprt->reestablish_timeout = 0;
        xprt->idle_timeout = 0;
 
index e978c71..2609e44 100644 (file)
@@ -43,7 +43,7 @@
  *   wimax_rfkill()             Kernel calling wimax_rfkill()
  *     __wimax_rf_toggle_radio()
  *
- * wimax_rfkill_set_radio_block()  RF-Kill subsytem calling
+ * wimax_rfkill_set_radio_block()  RF-Kill subsystem calling
  *   __wimax_rf_toggle_radio()
  *
  * __wimax_rf_toggle_radio()
index f9bdf26..cbcd654 100644 (file)
@@ -245,3 +245,7 @@ quiet_cmd_lzo = LZO    $@
 cmd_lzo = (cat $(filter-out FORCE,$^) | \
        lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
        (rm -f $@ ; false)
+
+# misc stuff
+# ---------------------------------------------------------------------------
+quote:="
index b6b2a46..25d1ec4 100644 (file)
@@ -72,7 +72,7 @@ int file_write_dep(const char *name)
 }
 
 
-/* Allocate initial growable sting */
+/* Allocate initial growable string */
 struct gstr str_new(void)
 {
        struct gstr gs;
index 220213e..df90f31 100644 (file)
@@ -796,6 +796,16 @@ static int do_platform_entry(const char *filename,
        return 1;
 }
 
+/* Looks like: zorro:iN. */
+static int do_zorro_entry(const char *filename, struct zorro_device_id *id,
+                         char *alias)
+{
+       id->id = TO_NATIVE(id->id);
+       strcpy(alias, "zorro:");
+       ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id);
+       return 1;
+}
+
 /* Ignore any prefix, eg. some architectures prepend _ */
 static inline int sym_is(const char *symbol, const char *name)
 {
@@ -943,6 +953,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_zorro_device_table"))
+               do_table(symval, sym->st_size,
+                        sizeof(struct zorro_device_id), "zorro",
+                        do_zorro_entry, mod);
        free(zeros);
 }
 
index 47bdd2f..fa27f3d 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-#      Output a simple RPM spec file that uses no fancy features requring
+#      Output a simple RPM spec file that uses no fancy features requiring
 #      RPM v4. This is intended to work with any RPM distro.
 #
 #      The only gothic bit here is redefining install_post to avoid
index 2462696..58a12c2 100644 (file)
@@ -81,7 +81,7 @@ int main(int argc, char *argv[])
        fprintf(fout, "\n");
 
        for (i = 1; i < isids_len; i++) {
-               char *s = initial_sid_to_string[i];
+               const char *s = initial_sid_to_string[i];
                fprintf(fout, "#define SECINITSID_%s", s);
                for (j = 0; j < max(1, 40 - strlen(s)); j++)
                        fprintf(fout, " ");
index 4875142..8168e3e 100644 (file)
 
 #include <linux/security.h>
 
-static int cap_acct(struct file *file)
-{
-       return 0;
-}
-
 static int cap_sysctl(ctl_table *table, int op)
 {
        return 0;
@@ -80,42 +75,16 @@ static int cap_sb_mount(char *dev_name, struct path *path, char *type,
        return 0;
 }
 
-static int cap_sb_check_sb(struct vfsmount *mnt, struct path *path)
-{
-       return 0;
-}
-
 static int cap_sb_umount(struct vfsmount *mnt, int flags)
 {
        return 0;
 }
 
-static void cap_sb_umount_close(struct vfsmount *mnt)
-{
-}
-
-static void cap_sb_umount_busy(struct vfsmount *mnt)
-{
-}
-
-static void cap_sb_post_remount(struct vfsmount *mnt, unsigned long flags,
-                               void *data)
-{
-}
-
-static void cap_sb_post_addmount(struct vfsmount *mnt, struct path *path)
-{
-}
-
 static int cap_sb_pivotroot(struct path *old_path, struct path *new_path)
 {
        return 0;
 }
 
-static void cap_sb_post_pivotroot(struct path *old_path, struct path *new_path)
-{
-}
-
 static int cap_sb_set_mnt_opts(struct super_block *sb,
                               struct security_mnt_opts *opts)
 {
@@ -221,10 +190,6 @@ static int cap_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
        return 0;
 }
 
-static void cap_inode_delete(struct inode *ino)
-{
-}
-
 static void cap_inode_post_setxattr(struct dentry *dentry, const char *name,
                                    const void *value, size_t size, int flags)
 {
@@ -403,10 +368,6 @@ static int cap_cred_prepare(struct cred *new, const struct cred *old, gfp_t gfp)
        return 0;
 }
 
-static void cap_cred_commit(struct cred *new, const struct cred *old)
-{
-}
-
 static void cap_cred_transfer(struct cred *new, const struct cred *old)
 {
 }
@@ -426,16 +387,6 @@ static int cap_kernel_module_request(char *kmod_name)
        return 0;
 }
 
-static int cap_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
-{
-       return 0;
-}
-
-static int cap_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
-{
-       return 0;
-}
-
 static int cap_task_setpgid(struct task_struct *p, pid_t pgid)
 {
        return 0;
@@ -456,11 +407,6 @@ static void cap_task_getsecid(struct task_struct *p, u32 *secid)
        *secid = 0;
 }
 
-static int cap_task_setgroups(struct group_info *group_info)
-{
-       return 0;
-}
-
 static int cap_task_getioprio(struct task_struct *p)
 {
        return 0;
@@ -875,13 +821,6 @@ static int cap_key_getsecurity(struct key *key, char **_buffer)
        return 0;
 }
 
-static int cap_key_session_to_parent(const struct cred *cred,
-                                    const struct cred *parent_cred,
-                                    struct key *key)
-{
-       return 0;
-}
-
 #endif /* CONFIG_KEYS */
 
 #ifdef CONFIG_AUDIT
@@ -915,13 +854,12 @@ static void cap_audit_rule_free(void *lsmrule)
                        }                                               \
        } while (0)
 
-void security_fixup_ops(struct security_operations *ops)
+void __init security_fixup_ops(struct security_operations *ops)
 {
        set_to_cap_if_null(ops, ptrace_access_check);
        set_to_cap_if_null(ops, ptrace_traceme);
        set_to_cap_if_null(ops, capget);
        set_to_cap_if_null(ops, capset);
-       set_to_cap_if_null(ops, acct);
        set_to_cap_if_null(ops, capable);
        set_to_cap_if_null(ops, quotactl);
        set_to_cap_if_null(ops, quota_on);
@@ -941,14 +879,8 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, sb_show_options);
        set_to_cap_if_null(ops, sb_statfs);
        set_to_cap_if_null(ops, sb_mount);
-       set_to_cap_if_null(ops, sb_check_sb);
        set_to_cap_if_null(ops, sb_umount);
-       set_to_cap_if_null(ops, sb_umount_close);
-       set_to_cap_if_null(ops, sb_umount_busy);
-       set_to_cap_if_null(ops, sb_post_remount);
-       set_to_cap_if_null(ops, sb_post_addmount);
        set_to_cap_if_null(ops, sb_pivotroot);
-       set_to_cap_if_null(ops, sb_post_pivotroot);
        set_to_cap_if_null(ops, sb_set_mnt_opts);
        set_to_cap_if_null(ops, sb_clone_mnt_opts);
        set_to_cap_if_null(ops, sb_parse_opts_str);
@@ -968,7 +900,6 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, inode_permission);
        set_to_cap_if_null(ops, inode_setattr);
        set_to_cap_if_null(ops, inode_getattr);
-       set_to_cap_if_null(ops, inode_delete);
        set_to_cap_if_null(ops, inode_setxattr);
        set_to_cap_if_null(ops, inode_post_setxattr);
        set_to_cap_if_null(ops, inode_getxattr);
@@ -1009,19 +940,15 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, cred_alloc_blank);
        set_to_cap_if_null(ops, cred_free);
        set_to_cap_if_null(ops, cred_prepare);
-       set_to_cap_if_null(ops, cred_commit);
        set_to_cap_if_null(ops, cred_transfer);
        set_to_cap_if_null(ops, kernel_act_as);
        set_to_cap_if_null(ops, kernel_create_files_as);
        set_to_cap_if_null(ops, kernel_module_request);
-       set_to_cap_if_null(ops, task_setuid);
        set_to_cap_if_null(ops, task_fix_setuid);
-       set_to_cap_if_null(ops, task_setgid);
        set_to_cap_if_null(ops, task_setpgid);
        set_to_cap_if_null(ops, task_getpgid);
        set_to_cap_if_null(ops, task_getsid);
        set_to_cap_if_null(ops, task_getsecid);
-       set_to_cap_if_null(ops, task_setgroups);
        set_to_cap_if_null(ops, task_setnice);
        set_to_cap_if_null(ops, task_setioprio);
        set_to_cap_if_null(ops, task_getioprio);
@@ -1113,7 +1040,6 @@ void security_fixup_ops(struct security_operations *ops)
        set_to_cap_if_null(ops, key_free);
        set_to_cap_if_null(ops, key_permission);
        set_to_cap_if_null(ops, key_getsecurity);
-       set_to_cap_if_null(ops, key_session_to_parent);
 #endif /* CONFIG_KEYS */
 #ifdef CONFIG_AUDIT
        set_to_cap_if_null(ops, audit_rule_init);
index 6166973..4e01599 100644 (file)
@@ -570,7 +570,7 @@ int cap_inode_setxattr(struct dentry *dentry, const char *name,
        }
 
        if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
+                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
            !capable(CAP_SYS_ADMIN))
                return -EPERM;
        return 0;
@@ -596,7 +596,7 @@ int cap_inode_removexattr(struct dentry *dentry, const char *name)
        }
 
        if (!strncmp(name, XATTR_SECURITY_PREFIX,
-                    sizeof(XATTR_SECURITY_PREFIX) - 1)  &&
+                    sizeof(XATTR_SECURITY_PREFIX) - 1) &&
            !capable(CAP_SYS_ADMIN))
                return -EPERM;
        return 0;
@@ -931,7 +931,7 @@ int cap_vm_enough_memory(struct mm_struct *mm, long pages)
  * @addr: address attempting to be mapped
  * @addr_only: unused
  *
- * If the process is attempting to map memory below mmap_min_addr they need
+ * If the process is attempting to map memory below dac_mmap_min_addr they need
  * CAP_SYS_RAWIO.  The other parameters to this function are unused by the
  * capability security module.  Returns 0 if this mapping should be allowed
  * -EPERM if not.
index f77c604..8d9c48f 100644 (file)
@@ -470,7 +470,7 @@ struct cgroup_subsys devices_subsys = {
        .name = "devices",
        .can_attach = devcgroup_can_attach,
        .create = devcgroup_create,
-       .destroy  = devcgroup_destroy,
+       .destroy = devcgroup_destroy,
        .populate = devcgroup_populate,
        .subsys_id = devices_subsys_id,
 };
index 3d7846d..b6ecfd4 100644 (file)
@@ -2,15 +2,14 @@
 #
 config IMA
        bool "Integrity Measurement Architecture(IMA)"
-       depends on ACPI
        depends on SECURITY
        select SECURITYFS
        select CRYPTO
        select CRYPTO_HMAC
        select CRYPTO_MD5
        select CRYPTO_SHA1
-       select TCG_TPM
-       select TCG_TIS
+       select TCG_TPM if !S390
+       select TCG_TIS if TCG_TPM
        help
          The Trusted Computing Group(TCG) runtime Integrity
          Measurement Architecture(IMA) maintains a list of hash
index 47fb65d..16d100d 100644 (file)
@@ -135,7 +135,7 @@ enum ima_hooks { FILE_CHECK = 1, FILE_MMAP, BPRM_CHECK };
 int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask);
 void ima_init_policy(void);
 void ima_update_policy(void);
-int ima_parse_add_rule(char *);
+ssize_t ima_parse_add_rule(char *);
 void ima_delete_rules(void);
 
 /* LSM based policy rules require audit */
index 5af7634..c5c5a72 100644 (file)
@@ -41,7 +41,7 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
                return;
 
        ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno);
-       audit_log_format(ab, "integrity: pid=%d uid=%u auid=%u ses=%u",
+       audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
                         current->pid, current_cred()->uid,
                         audit_get_loginuid(current),
                         audit_get_sessionid(current));
index 952e513..9b3ade7 100644 (file)
@@ -27,7 +27,7 @@ static int init_desc(struct hash_desc *desc)
 
        desc->tfm = crypto_alloc_hash(ima_hash, 0, CRYPTO_ALG_ASYNC);
        if (IS_ERR(desc->tfm)) {
-               pr_info("failed to load %s transform: %ld\n",
+               pr_info("IMA: failed to load %s transform: %ld\n",
                        ima_hash, PTR_ERR(desc->tfm));
                rc = PTR_ERR(desc->tfm);
                return rc;
@@ -112,7 +112,7 @@ static void __init ima_pcrread(int idx, u8 *pcr)
                return;
 
        if (tpm_pcr_read(TPM_ANY_NUM, idx, pcr) != 0)
-               pr_err("Error Communicating to TPM chip\n");
+               pr_err("IMA: Error Communicating to TPM chip\n");
 }
 
 /*
index 07cb9c3..8fe736a 100644 (file)
@@ -244,32 +244,34 @@ static const struct file_operations ima_ascii_measurements_ops = {
 static ssize_t ima_write_policy(struct file *file, const char __user *buf,
                                size_t datalen, loff_t *ppos)
 {
-       char *data;
-       int rc;
+       char *data = NULL;
+       ssize_t result;
 
        if (datalen >= PAGE_SIZE)
-               return -ENOMEM;
-       if (*ppos != 0) {
-               /* No partial writes. */
-               return -EINVAL;
-       }
+               datalen = PAGE_SIZE - 1;
+
+       /* No partial writes. */
+       result = -EINVAL;
+       if (*ppos != 0)
+               goto out;
+
+       result = -ENOMEM;
        data = kmalloc(datalen + 1, GFP_KERNEL);
        if (!data)
-               return -ENOMEM;
+               goto out;
 
-       if (copy_from_user(data, buf, datalen)) {
-               kfree(data);
-               return -EFAULT;
-       }
        *(data + datalen) = '\0';
-       rc = ima_parse_add_rule(data);
-       if (rc < 0) {
-               datalen = -EINVAL;
-               valid_policy = 0;
-       }
 
+       result = -EFAULT;
+       if (copy_from_user(data, buf, datalen))
+               goto out;
+
+       result = ima_parse_add_rule(data);
+out:
+       if (result < 0)
+               valid_policy = 0;
        kfree(data);
-       return datalen;
+       return result;
 }
 
 static struct dentry *ima_dir;
index 2c744d4..2dc2d65 100644 (file)
@@ -80,17 +80,17 @@ void iint_free(struct kref *kref)
        iint->version = 0;
        iint->flags = 0UL;
        if (iint->readcount != 0) {
-               printk(KERN_INFO "%s: readcount: %ld\n", __FUNCTION__,
+               printk(KERN_INFO "%s: readcount: %ld\n", __func__,
                       iint->readcount);
                iint->readcount = 0;
        }
        if (iint->writecount != 0) {
-               printk(KERN_INFO "%s: writecount: %ld\n", __FUNCTION__,
+               printk(KERN_INFO "%s: writecount: %ld\n", __func__,
                       iint->writecount);
                iint->writecount = 0;
        }
        if (iint->opencount != 0) {
-               printk(KERN_INFO "%s: opencount: %ld\n", __FUNCTION__,
+               printk(KERN_INFO "%s: opencount: %ld\n", __func__,
                       iint->opencount);
                iint->opencount = 0;
        }
index b1bcb70..17f1f06 100644 (file)
@@ -83,7 +83,7 @@ int __init ima_init(void)
                ima_used_chip = 1;
 
        if (!ima_used_chip)
-               pr_info("No TPM chip found, activating TPM-bypass!\n");
+               pr_info("IMA: No TPM chip found, activating TPM-bypass!\n");
 
        ima_add_boot_aggregate();       /* boot aggregate must be first entry */
        ima_init_policy();
index b2c89d9..f936413 100644 (file)
@@ -195,7 +195,7 @@ static void ima_dec_counts(struct ima_iint_cache *iint, struct inode *inode,
             (iint->writecount < 0)) &&
            !ima_limit_imbalance(file)) {
                printk(KERN_INFO "%s: open/free imbalance (r:%ld w:%ld o:%ld)\n",
-                      __FUNCTION__, iint->readcount, iint->writecount,
+                      __func__, iint->readcount, iint->writecount,
                       iint->opencount);
                dump_stack();
        }
index 8643a93..aef8c0a 100644 (file)
@@ -246,6 +246,9 @@ static int ima_lsm_rule_init(struct ima_measure_rule_entry *entry,
 {
        int result;
 
+       if (entry->lsm[lsm_rule].rule)
+               return -EINVAL;
+
        entry->lsm[lsm_rule].type = audit_type;
        result = security_filter_rule_init(entry->lsm[lsm_rule].type,
                                           Audit_equal, args,
@@ -253,6 +256,13 @@ static int ima_lsm_rule_init(struct ima_measure_rule_entry *entry,
        return result;
 }
 
+static void ima_log_string(struct audit_buffer *ab, char *key, char *value)
+{
+       audit_log_format(ab, "%s=", key);
+       audit_log_untrustedstring(ab, value);
+       audit_log_format(ab, " ");
+}
+
 static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
 {
        struct audit_buffer *ab;
@@ -261,28 +271,41 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
 
        ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_INTEGRITY_RULE);
 
-       entry->action = -1;
-       while ((p = strsep(&rule, " \n")) != NULL) {
+       entry->uid = -1;
+       entry->action = UNKNOWN;
+       while ((p = strsep(&rule, " \t")) != NULL) {
                substring_t args[MAX_OPT_ARGS];
                int token;
                unsigned long lnum;
 
                if (result < 0)
                        break;
-               if (!*p)
+               if ((*p == '\0') || (*p == ' ') || (*p == '\t'))
                        continue;
                token = match_token(p, policy_tokens, args);
                switch (token) {
                case Opt_measure:
-                       audit_log_format(ab, "%s ", "measure");
+                       ima_log_string(ab, "action", "measure");
+
+                       if (entry->action != UNKNOWN)
+                               result = -EINVAL;
+
                        entry->action = MEASURE;
                        break;
                case Opt_dont_measure:
-                       audit_log_format(ab, "%s ", "dont_measure");
+                       ima_log_string(ab, "action", "dont_measure");
+
+                       if (entry->action != UNKNOWN)
+                               result = -EINVAL;
+
                        entry->action = DONT_MEASURE;
                        break;
                case Opt_func:
-                       audit_log_format(ab, "func=%s ", args[0].from);
+                       ima_log_string(ab, "func", args[0].from);
+
+                       if (entry->func)
+                               result  = -EINVAL;
+
                        if (strcmp(args[0].from, "FILE_CHECK") == 0)
                                entry->func = FILE_CHECK;
                        /* PATH_CHECK is for backwards compat */
@@ -298,7 +321,11 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
                                entry->flags |= IMA_FUNC;
                        break;
                case Opt_mask:
-                       audit_log_format(ab, "mask=%s ", args[0].from);
+                       ima_log_string(ab, "mask", args[0].from);
+
+                       if (entry->mask)
+                               result = -EINVAL;
+
                        if ((strcmp(args[0].from, "MAY_EXEC")) == 0)
                                entry->mask = MAY_EXEC;
                        else if (strcmp(args[0].from, "MAY_WRITE") == 0)
@@ -313,14 +340,26 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
                                entry->flags |= IMA_MASK;
                        break;
                case Opt_fsmagic:
-                       audit_log_format(ab, "fsmagic=%s ", args[0].from);
+                       ima_log_string(ab, "fsmagic", args[0].from);
+
+                       if (entry->fsmagic) {
+                               result = -EINVAL;
+                               break;
+                       }
+
                        result = strict_strtoul(args[0].from, 16,
                                                &entry->fsmagic);
                        if (!result)
                                entry->flags |= IMA_FSMAGIC;
                        break;
                case Opt_uid:
-                       audit_log_format(ab, "uid=%s ", args[0].from);
+                       ima_log_string(ab, "uid", args[0].from);
+
+                       if (entry->uid != -1) {
+                               result = -EINVAL;
+                               break;
+                       }
+
                        result = strict_strtoul(args[0].from, 10, &lnum);
                        if (!result) {
                                entry->uid = (uid_t) lnum;
@@ -331,50 +370,51 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
                        }
                        break;
                case Opt_obj_user:
-                       audit_log_format(ab, "obj_user=%s ", args[0].from);
+                       ima_log_string(ab, "obj_user", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_OBJ_USER,
                                                   AUDIT_OBJ_USER);
                        break;
                case Opt_obj_role:
-                       audit_log_format(ab, "obj_role=%s ", args[0].from);
+                       ima_log_string(ab, "obj_role", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_OBJ_ROLE,
                                                   AUDIT_OBJ_ROLE);
                        break;
                case Opt_obj_type:
-                       audit_log_format(ab, "obj_type=%s ", args[0].from);
+                       ima_log_string(ab, "obj_type", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_OBJ_TYPE,
                                                   AUDIT_OBJ_TYPE);
                        break;
                case Opt_subj_user:
-                       audit_log_format(ab, "subj_user=%s ", args[0].from);
+                       ima_log_string(ab, "subj_user", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_SUBJ_USER,
                                                   AUDIT_SUBJ_USER);
                        break;
                case Opt_subj_role:
-                       audit_log_format(ab, "subj_role=%s ", args[0].from);
+                       ima_log_string(ab, "subj_role", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_SUBJ_ROLE,
                                                   AUDIT_SUBJ_ROLE);
                        break;
                case Opt_subj_type:
-                       audit_log_format(ab, "subj_type=%s ", args[0].from);
+                       ima_log_string(ab, "subj_type", args[0].from);
                        result = ima_lsm_rule_init(entry, args[0].from,
                                                   LSM_SUBJ_TYPE,
                                                   AUDIT_SUBJ_TYPE);
                        break;
                case Opt_err:
-                       audit_log_format(ab, "UNKNOWN=%s ", p);
+                       ima_log_string(ab, "UNKNOWN", p);
+                       result = -EINVAL;
                        break;
                }
        }
-       if (entry->action == UNKNOWN)
+       if (!result && (entry->action == UNKNOWN))
                result = -EINVAL;
 
-       audit_log_format(ab, "res=%d", !result ? 0 : 1);
+       audit_log_format(ab, "res=%d", !!result);
        audit_log_end(ab);
        return result;
 }
@@ -384,13 +424,14 @@ static int ima_parse_rule(char *rule, struct ima_measure_rule_entry *entry)
  * @rule - ima measurement policy rule
  *
  * Uses a mutex to protect the policy list from multiple concurrent writers.
- * Returns 0 on success, an error code on failure.
+ * Returns the length of the rule parsed, an error code on failure
  */
-int ima_parse_add_rule(char *rule)
+ssize_t ima_parse_add_rule(char *rule)
 {
        const char *op = "update_policy";
+       char *p;
        struct ima_measure_rule_entry *entry;
-       int result = 0;
+       ssize_t result, len;
        int audit_info = 0;
 
        /* Prevent installed policy from changing */
@@ -410,18 +451,28 @@ int ima_parse_add_rule(char *rule)
 
        INIT_LIST_HEAD(&entry->list);
 
-       result = ima_parse_rule(rule, entry);
-       if (!result) {
-               mutex_lock(&ima_measure_mutex);
-               list_add_tail(&entry->list, &measure_policy_rules);
-               mutex_unlock(&ima_measure_mutex);
-       } else {
+       p = strsep(&rule, "\n");
+       len = strlen(p) + 1;
+
+       if (*p == '#') {
+               kfree(entry);
+               return len;
+       }
+
+       result = ima_parse_rule(p, entry);
+       if (result) {
                kfree(entry);
                integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL,
                                    NULL, op, "invalid policy", result,
                                    audit_info);
+               return result;
        }
-       return result;
+
+       mutex_lock(&ima_measure_mutex);
+       list_add_tail(&entry->list, &measure_policy_rules);
+       mutex_unlock(&ima_measure_mutex);
+
+       return len;
 }
 
 /* ima_delete_rules called to cleanup invalid policy */
index 46ba62b..8e28f04 100644 (file)
@@ -71,7 +71,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
 
        qe = kmalloc(sizeof(*qe), GFP_KERNEL);
        if (qe == NULL) {
-               pr_err("OUT OF MEMORY ERROR creating queue entry.\n");
+               pr_err("IMA: OUT OF MEMORY ERROR creating queue entry.\n");
                return -ENOMEM;
        }
        qe->entry = entry;
@@ -94,7 +94,7 @@ static int ima_pcr_extend(const u8 *hash)
 
        result = tpm_pcr_extend(TPM_ANY_NUM, CONFIG_IMA_MEASURE_PCR_IDX, hash);
        if (result != 0)
-               pr_err("Error Communicating to TPM chip\n");
+               pr_err("IMA: Error Communicating to TPM chip\n");
        return result;
 }
 
index 24ba030..5d4402a 100644 (file)
@@ -87,7 +87,16 @@ extern wait_queue_head_t request_key_conswq;
 extern struct key_type *key_type_lookup(const char *type);
 extern void key_type_put(struct key_type *ktype);
 
-extern int __key_link(struct key *keyring, struct key *key);
+extern int __key_link_begin(struct key *keyring,
+                           const struct key_type *type,
+                           const char *description,
+                           struct keyring_list **_prealloc);
+extern int __key_link_check_live_key(struct key *keyring, struct key *key);
+extern void __key_link(struct key *keyring, struct key *key,
+                      struct keyring_list **_prealloc);
+extern void __key_link_end(struct key *keyring,
+                          struct key_type *type,
+                          struct keyring_list *prealloc);
 
 extern key_ref_t __keyring_search_one(key_ref_t keyring_ref,
                                      const struct key_type *type,
index e50d264..c1eac80 100644 (file)
@@ -355,7 +355,7 @@ EXPORT_SYMBOL(key_alloc);
  */
 int key_payload_reserve(struct key *key, size_t datalen)
 {
-       int delta = (int) datalen - key->datalen;
+       int delta = (int)datalen - key->datalen;
        int ret = 0;
 
        key_check(key);
@@ -398,7 +398,8 @@ static int __key_instantiate_and_link(struct key *key,
                                      const void *data,
                                      size_t datalen,
                                      struct key *keyring,
-                                     struct key *authkey)
+                                     struct key *authkey,
+                                     struct keyring_list **_prealloc)
 {
        int ret, awaken;
 
@@ -425,7 +426,7 @@ static int __key_instantiate_and_link(struct key *key,
 
                        /* and link it into the destination keyring */
                        if (keyring)
-                               ret = __key_link(keyring, key);
+                               __key_link(keyring, key, _prealloc);
 
                        /* disable the authorisation key */
                        if (authkey)
@@ -453,15 +454,21 @@ int key_instantiate_and_link(struct key *key,
                             struct key *keyring,
                             struct key *authkey)
 {
+       struct keyring_list *prealloc;
        int ret;
 
-       if (keyring)
-               down_write(&keyring->sem);
+       if (keyring) {
+               ret = __key_link_begin(keyring, key->type, key->description,
+                                      &prealloc);
+               if (ret < 0)
+                       return ret;
+       }
 
-       ret = __key_instantiate_and_link(key, data, datalen, keyring, authkey);
+       ret = __key_instantiate_and_link(key, data, datalen, keyring, authkey,
+                                        &prealloc);
 
        if (keyring)
-               up_write(&keyring->sem);
+               __key_link_end(keyring, key->type, prealloc);
 
        return ret;
 
@@ -478,8 +485,9 @@ int key_negate_and_link(struct key *key,
                        struct key *keyring,
                        struct key *authkey)
 {
+       struct keyring_list *prealloc;
        struct timespec now;
-       int ret, awaken;
+       int ret, awaken, link_ret = 0;
 
        key_check(key);
        key_check(keyring);
@@ -488,7 +496,8 @@ int key_negate_and_link(struct key *key,
        ret = -EBUSY;
 
        if (keyring)
-               down_write(&keyring->sem);
+               link_ret = __key_link_begin(keyring, key->type,
+                                           key->description, &prealloc);
 
        mutex_lock(&key_construction_mutex);
 
@@ -508,8 +517,8 @@ int key_negate_and_link(struct key *key,
                ret = 0;
 
                /* and link it into the destination keyring */
-               if (keyring)
-                       ret = __key_link(keyring, key);
+               if (keyring && link_ret == 0)
+                       __key_link(keyring, key, &prealloc);
 
                /* disable the authorisation key */
                if (authkey)
@@ -519,13 +528,13 @@ int key_negate_and_link(struct key *key,
        mutex_unlock(&key_construction_mutex);
 
        if (keyring)
-               up_write(&keyring->sem);
+               __key_link_end(keyring, key->type, prealloc);
 
        /* wake up anyone waiting for a key to be constructed */
        if (awaken)
                wake_up_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT);
 
-       return ret;
+       return ret == 0 ? link_ret : ret;
 
 } /* end key_negate_and_link() */
 
@@ -749,6 +758,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
                               key_perm_t perm,
                               unsigned long flags)
 {
+       struct keyring_list *prealloc;
        const struct cred *cred = current_cred();
        struct key_type *ktype;
        struct key *keyring, *key = NULL;
@@ -775,7 +785,9 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
        if (keyring->type != &key_type_keyring)
                goto error_2;
 
-       down_write(&keyring->sem);
+       ret = __key_link_begin(keyring, ktype, description, &prealloc);
+       if (ret < 0)
+               goto error_2;
 
        /* if we're going to allocate a new key, we're going to have
         * to modify the keyring */
@@ -817,7 +829,8 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
        }
 
        /* instantiate it and link it into the target keyring */
-       ret = __key_instantiate_and_link(key, payload, plen, keyring, NULL);
+       ret = __key_instantiate_and_link(key, payload, plen, keyring, NULL,
+                                        &prealloc);
        if (ret < 0) {
                key_put(key);
                key_ref = ERR_PTR(ret);
@@ -827,7 +840,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
        key_ref = make_key_ref(key, is_key_possessed(keyring_ref));
 
  error_3:
-       up_write(&keyring->sem);
+       __key_link_end(keyring, ktype, prealloc);
  error_2:
        key_type_put(ktype);
  error:
@@ -837,7 +850,7 @@ key_ref_t key_create_or_update(key_ref_t keyring_ref,
        /* we found a matching key, so we're going to try to update it
         * - we can drop the locks first as we have the key pinned
         */
-       up_write(&keyring->sem);
+       __key_link_end(keyring, ktype, prealloc);
        key_type_put(ktype);
 
        key_ref = __key_update(key_ref, payload, plen);
index e9c2e7c..8f4dce1 100644 (file)
@@ -212,15 +212,15 @@ SYSCALL_DEFINE4(request_key, const char __user *, _type,
        ret = key->serial;
 
        key_put(key);
- error5:
+error5:
        key_type_put(ktype);
- error4:
+error4:
        key_ref_put(dest_ref);
- error3:
+error3:
        kfree(callout_info);
- error2:
+error2:
        kfree(description);
- error:
+error:
        return ret;
 
 } /* end sys_request_key() */
@@ -246,7 +246,7 @@ long keyctl_get_keyring_ID(key_serial_t id, int create)
 
        ret = key_ref_to_ptr(key_ref)->serial;
        key_ref_put(key_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_get_keyring_ID() */
@@ -275,7 +275,7 @@ long keyctl_join_session_keyring(const char __user *_name)
        ret = join_session_keyring(name);
        kfree(name);
 
- error:
+error:
        return ret;
 
 } /* end keyctl_join_session_keyring() */
@@ -322,9 +322,9 @@ long keyctl_update_key(key_serial_t id,
        ret = key_update(key_ref, payload, plen);
 
        key_ref_put(key_ref);
- error2:
+error2:
        kfree(payload);
- error:
+error:
        return ret;
 
 } /* end keyctl_update_key() */
@@ -356,7 +356,7 @@ long keyctl_revoke_key(key_serial_t id)
        ret = 0;
 
        key_ref_put(key_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_revoke_key() */
@@ -381,7 +381,7 @@ long keyctl_keyring_clear(key_serial_t ringid)
        ret = keyring_clear(key_ref_to_ptr(keyring_ref));
 
        key_ref_put(keyring_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_keyring_clear() */
@@ -413,9 +413,9 @@ long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
        ret = key_link(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
 
        key_ref_put(key_ref);
- error2:
+error2:
        key_ref_put(keyring_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_keyring_link() */
@@ -447,9 +447,9 @@ long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
        ret = key_unlink(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
 
        key_ref_put(key_ref);
- error2:
+error2:
        key_ref_put(keyring_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_keyring_unlink() */
@@ -529,9 +529,9 @@ okay:
        }
 
        kfree(tmpbuf);
- error2:
+error2:
        key_ref_put(key_ref);
- error:
+error:
        return ret;
 
 } /* end keyctl_describe_key() */
@@ -616,17 +616,17 @@ long keyctl_keyring_search(key_serial_t ringid,
 
        ret = key_ref_to_ptr(key_ref)->serial;
 
- error6:
+error6:
        key_ref_put(key_ref);
- error5:
+error5:
        key_type_put(ktype);
- error4:
+error4:
        key_ref_put(dest_ref);
- error3:
+error3:
        key_ref_put(keyring_ref);
- error2:
+error2:
        kfree(description);
- error:
+error:
        return ret;
 
 } /* end keyctl_keyring_search() */
@@ -673,7 +673,7 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
        }
 
        /* the key is probably readable - now try to read it */
- can_read_key:
+can_read_key:
        ret = key_validate(key);
        if (ret == 0) {
                ret = -EOPNOTSUPP;
@@ -686,9 +686,9 @@ long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
                }
        }
 
- error2:
+error2:
        key_put(key);
- error:
+error:
        return ret;
 
 } /* end keyctl_read_key() */
@@ -1282,26 +1282,19 @@ long keyctl_session_to_parent(void)
 
        /* the parent must have the same effective ownership and mustn't be
         * SUID/SGID */
-       if (pcred-> uid != mycred->euid ||
+       if (pcred->uid  != mycred->euid ||
            pcred->euid != mycred->euid ||
            pcred->suid != mycred->euid ||
-           pcred-> gid != mycred->egid ||
+           pcred->gid  != mycred->egid ||
            pcred->egid != mycred->egid ||
            pcred->sgid != mycred->egid)
                goto not_permitted;
 
        /* the keyrings must have the same UID */
-       if (pcred ->tgcred->session_keyring->uid != mycred->euid ||
+       if (pcred->tgcred->session_keyring->uid != mycred->euid ||
            mycred->tgcred->session_keyring->uid != mycred->euid)
                goto not_permitted;
 
-       /* the LSM must permit the replacement of the parent's keyring with the
-        * keyring from this process */
-       ret = security_key_session_to_parent(mycred, pcred,
-                                            key_ref_to_ptr(keyring_r));
-       if (ret < 0)
-               goto not_permitted;
-
        /* if there's an already pending keyring replacement, then we replace
         * that */
        oldcred = parent->replacement_session_keyring;
index 1e4b003..ef03a82 100644 (file)
@@ -17,7 +17,7 @@
 #include <linux/seq_file.h>
 #include <linux/err.h>
 #include <keys/keyring-type.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
 #include "internal.h"
 
 #define rcu_dereference_locked_keyring(keyring)                                \
@@ -44,7 +44,7 @@ static inline unsigned keyring_hash(const char *desc)
        unsigned bucket = 0;
 
        for (; *desc; desc++)
-               bucket += (unsigned char) *desc;
+               bucket += (unsigned char)*desc;
 
        return bucket & (KEYRING_NAME_HASH_SIZE - 1);
 }
@@ -175,12 +175,10 @@ static void keyring_describe(const struct key *keyring, struct seq_file *m)
 {
        struct keyring_list *klist;
 
-       if (keyring->description) {
+       if (keyring->description)
                seq_puts(m, keyring->description);
-       }
-       else {
+       else
                seq_puts(m, "[anon]");
-       }
 
        rcu_read_lock();
        klist = rcu_dereference(keyring->payload.subscriptions);
@@ -241,7 +239,7 @@ static long keyring_read(const struct key *keyring,
                ret = qty;
        }
 
- error:
+error:
        return ret;
 
 } /* end keyring_read() */
@@ -310,7 +308,7 @@ key_ref_t keyring_search_aux(key_ref_t keyring_ref,
        key_check(keyring);
 
        /* top keyring must have search permission to begin the search */
-        err = key_task_permission(keyring_ref, cred, KEY_SEARCH);
+       err = key_task_permission(keyring_ref, cred, KEY_SEARCH);
        if (err < 0) {
                key_ref = ERR_PTR(err);
                goto error;
@@ -512,7 +510,7 @@ key_ref_t __keyring_search_one(key_ref_t keyring_ref,
        rcu_read_unlock();
        return ERR_PTR(-ENOKEY);
 
- found:
+found:
        atomic_inc(&key->usage);
        rcu_read_unlock();
        return make_key_ref(key, possessed);
@@ -602,7 +600,7 @@ static int keyring_detect_cycle(struct key *A, struct key *B)
        sp = 0;
 
        /* start processing a new keyring */
- descend:
+descend:
        if (test_bit(KEY_FLAG_REVOKED, &subtree->flags))
                goto not_this_keyring;
 
@@ -611,7 +609,7 @@ static int keyring_detect_cycle(struct key *A, struct key *B)
                goto not_this_keyring;
        kix = 0;
 
- ascend:
+ascend:
        /* iterate through the remaining keys in this keyring */
        for (; kix < keylist->nkeys; kix++) {
                key = keylist->keys[kix];
@@ -637,7 +635,7 @@ static int keyring_detect_cycle(struct key *A, struct key *B)
 
        /* the keyring we're looking at was disqualified or didn't contain a
         * matching key */
- not_this_keyring:
+not_this_keyring:
        if (sp > 0) {
                /* resume the checking of a keyring higher up in the tree */
                sp--;
@@ -648,34 +646,20 @@ static int keyring_detect_cycle(struct key *A, struct key *B)
 
        ret = 0; /* no cycles detected */
 
- error:
+error:
        rcu_read_unlock();
        return ret;
 
- too_deep:
+too_deep:
        ret = -ELOOP;
        goto error;
 
- cycle_detected:
+cycle_detected:
        ret = -EDEADLK;
        goto error;
 
 } /* end keyring_detect_cycle() */
 
-/*****************************************************************************/
-/*
- * dispose of a keyring list after the RCU grace period
- */
-static void keyring_link_rcu_disposal(struct rcu_head *rcu)
-{
-       struct keyring_list *klist =
-               container_of(rcu, struct keyring_list, rcu);
-
-       kfree(klist);
-
-} /* end keyring_link_rcu_disposal() */
-
-/*****************************************************************************/
 /*
  * dispose of a keyring list after the RCU grace period, freeing the unlinked
  * key
@@ -685,55 +669,51 @@ static void keyring_unlink_rcu_disposal(struct rcu_head *rcu)
        struct keyring_list *klist =
                container_of(rcu, struct keyring_list, rcu);
 
-       key_put(klist->keys[klist->delkey]);
+       if (klist->delkey != USHORT_MAX)
+               key_put(klist->keys[klist->delkey]);
        kfree(klist);
+}
 
-} /* end keyring_unlink_rcu_disposal() */
-
-/*****************************************************************************/
 /*
- * link a key into to a keyring
- * - must be called with the keyring's semaphore write-locked
- * - discard already extant link to matching key if there is one
+ * preallocate memory so that a key can be linked into to a keyring
  */
-int __key_link(struct key *keyring, struct key *key)
+int __key_link_begin(struct key *keyring, const struct key_type *type,
+                    const char *description,
+                    struct keyring_list **_prealloc)
+       __acquires(&keyring->sem)
 {
        struct keyring_list *klist, *nklist;
        unsigned max;
        size_t size;
        int loop, ret;
 
-       ret = -EKEYREVOKED;
-       if (test_bit(KEY_FLAG_REVOKED, &keyring->flags))
-               goto error;
+       kenter("%d,%s,%s,", key_serial(keyring), type->name, description);
 
-       ret = -ENOTDIR;
        if (keyring->type != &key_type_keyring)
-               goto error;
+               return -ENOTDIR;
 
-       /* serialise link/link calls to prevent parallel calls causing a
-        * cycle when applied to two keyring in opposite orders */
-       down_write(&keyring_serialise_link_sem);
+       down_write(&keyring->sem);
 
-       /* check that we aren't going to create a cycle adding one keyring to
-        * another */
-       if (key->type == &key_type_keyring) {
-               ret = keyring_detect_cycle(keyring, key);
-               if (ret < 0)
-                       goto error2;
-       }
+       ret = -EKEYREVOKED;
+       if (test_bit(KEY_FLAG_REVOKED, &keyring->flags))
+               goto error_krsem;
+
+       /* serialise link/link calls to prevent parallel calls causing a cycle
+        * when linking two keyring in opposite orders */
+       if (type == &key_type_keyring)
+               down_write(&keyring_serialise_link_sem);
 
-       /* see if there's a matching key we can displace */
        klist = rcu_dereference_locked_keyring(keyring);
-       if (klist && klist->nkeys > 0) {
-               struct key_type *type = key->type;
 
+       /* see if there's a matching key we can displace */
+       if (klist && klist->nkeys > 0) {
                for (loop = klist->nkeys - 1; loop >= 0; loop--) {
                        if (klist->keys[loop]->type == type &&
                            strcmp(klist->keys[loop]->description,
-                                  key->description) == 0
+                                  description) == 0
                            ) {
-                               /* found a match - replace with new key */
+                               /* found a match - we'll replace this one with
+                                * the new key */
                                size = sizeof(struct key *) * klist->maxkeys;
                                size += sizeof(*klist);
                                BUG_ON(size > PAGE_SIZE);
@@ -741,22 +721,10 @@ int __key_link(struct key *keyring, struct key *key)
                                ret = -ENOMEM;
                                nklist = kmemdup(klist, size, GFP_KERNEL);
                                if (!nklist)
-                                       goto error2;
-
-                               /* replace matched key */
-                               atomic_inc(&key->usage);
-                               nklist->keys[loop] = key;
-
-                               rcu_assign_pointer(
-                                       keyring->payload.subscriptions,
-                                       nklist);
-
-                               /* dispose of the old keyring list and the
-                                * displaced key */
-                               klist->delkey = loop;
-                               call_rcu(&klist->rcu,
-                                        keyring_unlink_rcu_disposal);
+                                       goto error_sem;
 
+                               /* note replacement slot */
+                               klist->delkey = nklist->delkey = loop;
                                goto done;
                        }
                }
@@ -766,88 +734,167 @@ int __key_link(struct key *keyring, struct key *key)
        ret = key_payload_reserve(keyring,
                                  keyring->datalen + KEYQUOTA_LINK_BYTES);
        if (ret < 0)
-               goto error2;
+               goto error_sem;
 
        if (klist && klist->nkeys < klist->maxkeys) {
-               /* there's sufficient slack space to add directly */
-               atomic_inc(&key->usage);
-
-               klist->keys[klist->nkeys] = key;
-               smp_wmb();
-               klist->nkeys++;
-               smp_wmb();
-       }
-       else {
+               /* there's sufficient slack space to append directly */
+               nklist = NULL;
+       } else {
                /* grow the key list */
                max = 4;
                if (klist)
                        max += klist->maxkeys;
 
                ret = -ENFILE;
-               if (max > 65535)
-                       goto error3;
+               if (max > USHORT_MAX - 1)
+                       goto error_quota;
                size = sizeof(*klist) + sizeof(struct key *) * max;
                if (size > PAGE_SIZE)
-                       goto error3;
+                       goto error_quota;
 
                ret = -ENOMEM;
                nklist = kmalloc(size, GFP_KERNEL);
                if (!nklist)
-                       goto error3;
-               nklist->maxkeys = max;
-               nklist->nkeys = 0;
+                       goto error_quota;
 
+               nklist->maxkeys = max;
                if (klist) {
-                       nklist->nkeys = klist->nkeys;
-                       memcpy(nklist->keys,
-                              klist->keys,
+                       memcpy(nklist->keys, klist->keys,
                               sizeof(struct key *) * klist->nkeys);
+                       nklist->delkey = klist->nkeys;
+                       nklist->nkeys = klist->nkeys + 1;
+                       klist->delkey = USHORT_MAX;
+               } else {
+                       nklist->nkeys = 1;
+                       nklist->delkey = 0;
                }
 
                /* add the key into the new space */
-               atomic_inc(&key->usage);
-               nklist->keys[nklist->nkeys++] = key;
-
-               rcu_assign_pointer(keyring->payload.subscriptions, nklist);
-
-               /* dispose of the old keyring list */
-               if (klist)
-                       call_rcu(&klist->rcu, keyring_link_rcu_disposal);
+               nklist->keys[nklist->delkey] = NULL;
        }
 
 done:
-       ret = 0;
-error2:
-       up_write(&keyring_serialise_link_sem);
-error:
-       return ret;
+       *_prealloc = nklist;
+       kleave(" = 0");
+       return 0;
 
-error3:
+error_quota:
        /* undo the quota changes */
        key_payload_reserve(keyring,
                            keyring->datalen - KEYQUOTA_LINK_BYTES);
-       goto error2;
+error_sem:
+       if (type == &key_type_keyring)
+               up_write(&keyring_serialise_link_sem);
+error_krsem:
+       up_write(&keyring->sem);
+       kleave(" = %d", ret);
+       return ret;
+}
 
-} /* end __key_link() */
+/*
+ * check already instantiated keys aren't going to be a problem
+ * - the caller must have called __key_link_begin()
+ * - don't need to call this for keys that were created since __key_link_begin()
+ *   was called
+ */
+int __key_link_check_live_key(struct key *keyring, struct key *key)
+{
+       if (key->type == &key_type_keyring)
+               /* check that we aren't going to create a cycle by linking one
+                * keyring to another */
+               return keyring_detect_cycle(keyring, key);
+       return 0;
+}
+
+/*
+ * link a key into to a keyring
+ * - must be called with __key_link_begin() having being called
+ * - discard already extant link to matching key if there is one
+ */
+void __key_link(struct key *keyring, struct key *key,
+               struct keyring_list **_prealloc)
+{
+       struct keyring_list *klist, *nklist;
+
+       nklist = *_prealloc;
+       *_prealloc = NULL;
+
+       kenter("%d,%d,%p", keyring->serial, key->serial, nklist);
+
+       klist = rcu_dereference_protected(keyring->payload.subscriptions,
+                                         rwsem_is_locked(&keyring->sem));
+
+       atomic_inc(&key->usage);
+
+       /* there's a matching key we can displace or an empty slot in a newly
+        * allocated list we can fill */
+       if (nklist) {
+               kdebug("replace %hu/%hu/%hu",
+                      nklist->delkey, nklist->nkeys, nklist->maxkeys);
+
+               nklist->keys[nklist->delkey] = key;
+
+               rcu_assign_pointer(keyring->payload.subscriptions, nklist);
+
+               /* dispose of the old keyring list and, if there was one, the
+                * displaced key */
+               if (klist) {
+                       kdebug("dispose %hu/%hu/%hu",
+                              klist->delkey, klist->nkeys, klist->maxkeys);
+                       call_rcu(&klist->rcu, keyring_unlink_rcu_disposal);
+               }
+       } else {
+               /* there's sufficient slack space to append directly */
+               klist->keys[klist->nkeys] = key;
+               smp_wmb();
+               klist->nkeys++;
+       }
+}
+
+/*
+ * finish linking a key into to a keyring
+ * - must be called with __key_link_begin() having being called
+ */
+void __key_link_end(struct key *keyring, struct key_type *type,
+                   struct keyring_list *prealloc)
+       __releases(&keyring->sem)
+{
+       BUG_ON(type == NULL);
+       BUG_ON(type->name == NULL);
+       kenter("%d,%s,%p", keyring->serial, type->name, prealloc);
+
+       if (type == &key_type_keyring)
+               up_write(&keyring_serialise_link_sem);
+
+       if (prealloc) {
+               kfree(prealloc);
+               key_payload_reserve(keyring,
+                                   keyring->datalen - KEYQUOTA_LINK_BYTES);
+       }
+       up_write(&keyring->sem);
+}
 
-/*****************************************************************************/
 /*
  * link a key to a keyring
  */
 int key_link(struct key *keyring, struct key *key)
 {
+       struct keyring_list *prealloc;
        int ret;
 
        key_check(keyring);
        key_check(key);
 
-       down_write(&keyring->sem);
-       ret = __key_link(keyring, key);
-       up_write(&keyring->sem);
+       ret = __key_link_begin(keyring, key->type, key->description, &prealloc);
+       if (ret == 0) {
+               ret = __key_link_check_live_key(keyring, key);
+               if (ret == 0)
+                       __key_link(keyring, key, &prealloc);
+               __key_link_end(keyring, key->type, prealloc);
+       }
 
        return ret;
-
-} /* end key_link() */
+}
 
 EXPORT_SYMBOL(key_link);
 
index 0ed802c..2864550 100644 (file)
@@ -109,7 +109,7 @@ int key_validate(struct key *key)
                }
        }
 
- error:
+error:
        return ret;
 
 } /* end key_validate() */
index 706d63f..068b66e 100644 (file)
@@ -306,7 +306,7 @@ static void *proc_key_users_start(struct seq_file *p, loff_t *_pos)
 static void *proc_key_users_next(struct seq_file *p, void *v, loff_t *_pos)
 {
        (*_pos)++;
-       return key_user_next((struct rb_node *) v);
+       return key_user_next((struct rb_node *)v);
 }
 
 static void proc_key_users_stop(struct seq_file *p, void *v)
index 06c2ccf..20a38fe 100644 (file)
@@ -508,7 +508,7 @@ try_again:
 
                        ret = install_thread_keyring();
                        if (ret < 0) {
-                               key = ERR_PTR(ret);
+                               key_ref = ERR_PTR(ret);
                                goto error;
                        }
                        goto reget_creds;
@@ -526,7 +526,7 @@ try_again:
 
                        ret = install_process_keyring();
                        if (ret < 0) {
-                               key = ERR_PTR(ret);
+                               key_ref = ERR_PTR(ret);
                                goto error;
                        }
                        goto reget_creds;
@@ -585,7 +585,7 @@ try_again:
 
        case KEY_SPEC_GROUP_KEYRING:
                /* group keyrings are not yet supported */
-               key = ERR_PTR(-EINVAL);
+               key_ref = ERR_PTR(-EINVAL);
                goto error;
 
        case KEY_SPEC_REQKEY_AUTH_KEY:
index d8c1a6a..f656e9c 100644 (file)
@@ -299,12 +299,15 @@ static int construct_alloc_key(struct key_type *type,
                               struct key_user *user,
                               struct key **_key)
 {
+       struct keyring_list *prealloc;
        const struct cred *cred = current_cred();
        struct key *key;
        key_ref_t key_ref;
+       int ret;
 
        kenter("%s,%s,,,", type->name, description);
 
+       *_key = NULL;
        mutex_lock(&user->cons_lock);
 
        key = key_alloc(type, description, cred->fsuid, cred->fsgid, cred,
@@ -314,8 +317,12 @@ static int construct_alloc_key(struct key_type *type,
 
        set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags);
 
-       if (dest_keyring)
-               down_write(&dest_keyring->sem);
+       if (dest_keyring) {
+               ret = __key_link_begin(dest_keyring, type, description,
+                                      &prealloc);
+               if (ret < 0)
+                       goto link_prealloc_failed;
+       }
 
        /* attach the key to the destination keyring under lock, but we do need
         * to do another check just in case someone beat us to it whilst we
@@ -327,31 +334,49 @@ static int construct_alloc_key(struct key_type *type,
                goto key_already_present;
 
        if (dest_keyring)
-               __key_link(dest_keyring, key);
+               __key_link(dest_keyring, key, &prealloc);
 
        mutex_unlock(&key_construction_mutex);
        if (dest_keyring)
-               up_write(&dest_keyring->sem);
+               __key_link_end(dest_keyring, type, prealloc);
        mutex_unlock(&user->cons_lock);
        *_key = key;
        kleave(" = 0 [%d]", key_serial(key));
        return 0;
 
+       /* the key is now present - we tell the caller that we found it by
+        * returning -EINPROGRESS  */
 key_already_present:
+       key_put(key);
        mutex_unlock(&key_construction_mutex);
+       key = key_ref_to_ptr(key_ref);
        if (dest_keyring) {
-               __key_link(dest_keyring, key_ref_to_ptr(key_ref));
-               up_write(&dest_keyring->sem);
+               ret = __key_link_check_live_key(dest_keyring, key);
+               if (ret == 0)
+                       __key_link(dest_keyring, key, &prealloc);
+               __key_link_end(dest_keyring, type, prealloc);
+               if (ret < 0)
+                       goto link_check_failed;
        }
        mutex_unlock(&user->cons_lock);
-       key_put(key);
-       *_key = key = key_ref_to_ptr(key_ref);
+       *_key = key;
        kleave(" = -EINPROGRESS [%d]", key_serial(key));
        return -EINPROGRESS;
 
+link_check_failed:
+       mutex_unlock(&user->cons_lock);
+       key_put(key);
+       kleave(" = %d [linkcheck]", ret);
+       return ret;
+
+link_prealloc_failed:
+       up_write(&dest_keyring->sem);
+       mutex_unlock(&user->cons_lock);
+       kleave(" = %d [prelink]", ret);
+       return ret;
+
 alloc_failed:
        mutex_unlock(&user->cons_lock);
-       *_key = NULL;
        kleave(" = %ld", PTR_ERR(key));
        return PTR_ERR(key);
 }
@@ -390,6 +415,10 @@ static struct key *construct_key_and_link(struct key_type *type,
                        kdebug("cons failed");
                        goto construction_failed;
                }
+       } else if (ret == -EINPROGRESS) {
+               ret = 0;
+       } else {
+               key = ERR_PTR(ret);
        }
 
        key_put(dest_keyring);
@@ -422,6 +451,7 @@ struct key *request_key_and_link(struct key_type *type,
        const struct cred *cred = current_cred();
        struct key *key;
        key_ref_t key_ref;
+       int ret;
 
        kenter("%s,%s,%p,%zu,%p,%p,%lx",
               type->name, description, callout_info, callout_len, aux,
@@ -435,8 +465,13 @@ struct key *request_key_and_link(struct key_type *type,
                key = key_ref_to_ptr(key_ref);
                if (dest_keyring) {
                        construct_get_dest_keyring(&dest_keyring);
-                       key_link(dest_keyring, key);
+                       ret = key_link(dest_keyring, key);
                        key_put(dest_keyring);
+                       if (ret < 0) {
+                               key_put(key);
+                               key = ERR_PTR(ret);
+                               goto error;
+                       }
                }
        } else if (PTR_ERR(key_ref) != -EAGAIN) {
                key = ERR_CAST(key_ref);
index 893365b..908aa71 100644 (file)
@@ -221,7 +221,7 @@ static void dump_common_audit_data(struct audit_buffer *ab,
        }
 
        switch (a->type) {
-       case LSM_AUDIT_NO_AUDIT:
+       case LSM_AUDIT_DATA_NONE:
                return;
        case LSM_AUDIT_DATA_IPC:
                audit_log_format(ab, " key=%d ", a->u.ipc_id);
index 687c6fd..351942a 100644 (file)
@@ -23,14 +23,14 @@ static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
        CONFIG_DEFAULT_SECURITY;
 
 /* things that live in capability.c */
-extern void security_fixup_ops(struct security_operations *ops);
+extern void __init security_fixup_ops(struct security_operations *ops);
 
 static struct security_operations *security_ops;
 static struct security_operations default_security_ops = {
        .name   = "default",
 };
 
-static inline int verify(struct security_operations *ops)
+static inline int __init verify(struct security_operations *ops)
 {
        /* verify the security_operations structure exists */
        if (!ops)
@@ -117,7 +117,7 @@ int __init security_module_enable(struct security_operations *ops)
  * If there is already a security module registered with the kernel,
  * an error will be returned.  Otherwise %0 is returned on success.
  */
-int register_security(struct security_operations *ops)
+int __init register_security(struct security_operations *ops)
 {
        if (verify(ops)) {
                printk(KERN_DEBUG "%s could not verify "
@@ -190,11 +190,6 @@ int security_real_capable_noaudit(struct task_struct *tsk, int cap)
        return ret;
 }
 
-int security_acct(struct file *file)
-{
-       return security_ops->acct(file);
-}
-
 int security_sysctl(struct ctl_table *table, int op)
 {
        return security_ops->sysctl(table, op);
@@ -306,46 +301,16 @@ int security_sb_mount(char *dev_name, struct path *path,
        return security_ops->sb_mount(dev_name, path, type, flags, data);
 }
 
-int security_sb_check_sb(struct vfsmount *mnt, struct path *path)
-{
-       return security_ops->sb_check_sb(mnt, path);
-}
-
 int security_sb_umount(struct vfsmount *mnt, int flags)
 {
        return security_ops->sb_umount(mnt, flags);
 }
 
-void security_sb_umount_close(struct vfsmount *mnt)
-{
-       security_ops->sb_umount_close(mnt);
-}
-
-void security_sb_umount_busy(struct vfsmount *mnt)
-{
-       security_ops->sb_umount_busy(mnt);
-}
-
-void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *data)
-{
-       security_ops->sb_post_remount(mnt, flags, data);
-}
-
-void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint)
-{
-       security_ops->sb_post_addmount(mnt, mountpoint);
-}
-
 int security_sb_pivotroot(struct path *old_path, struct path *new_path)
 {
        return security_ops->sb_pivotroot(old_path, new_path);
 }
 
-void security_sb_post_pivotroot(struct path *old_path, struct path *new_path)
-{
-       security_ops->sb_post_pivotroot(old_path, new_path);
-}
-
 int security_sb_set_mnt_opts(struct super_block *sb,
                                struct security_mnt_opts *opts)
 {
@@ -580,13 +545,6 @@ int security_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
        return security_ops->inode_getattr(mnt, dentry);
 }
 
-void security_inode_delete(struct inode *inode)
-{
-       if (unlikely(IS_PRIVATE(inode)))
-               return;
-       security_ops->inode_delete(inode);
-}
-
 int security_inode_setxattr(struct dentry *dentry, const char *name,
                            const void *value, size_t size, int flags)
 {
@@ -749,11 +707,6 @@ int security_prepare_creds(struct cred *new, const struct cred *old, gfp_t gfp)
        return security_ops->cred_prepare(new, old, gfp);
 }
 
-void security_commit_creds(struct cred *new, const struct cred *old)
-{
-       security_ops->cred_commit(new, old);
-}
-
 void security_transfer_creds(struct cred *new, const struct cred *old)
 {
        security_ops->cred_transfer(new, old);
@@ -774,22 +727,12 @@ int security_kernel_module_request(char *kmod_name)
        return security_ops->kernel_module_request(kmod_name);
 }
 
-int security_task_setuid(uid_t id0, uid_t id1, uid_t id2, int flags)
-{
-       return security_ops->task_setuid(id0, id1, id2, flags);
-}
-
 int security_task_fix_setuid(struct cred *new, const struct cred *old,
                             int flags)
 {
        return security_ops->task_fix_setuid(new, old, flags);
 }
 
-int security_task_setgid(gid_t id0, gid_t id1, gid_t id2, int flags)
-{
-       return security_ops->task_setgid(id0, id1, id2, flags);
-}
-
 int security_task_setpgid(struct task_struct *p, pid_t pgid)
 {
        return security_ops->task_setpgid(p, pgid);
@@ -811,11 +754,6 @@ void security_task_getsecid(struct task_struct *p, u32 *secid)
 }
 EXPORT_SYMBOL(security_task_getsecid);
 
-int security_task_setgroups(struct group_info *group_info)
-{
-       return security_ops->task_setgroups(group_info);
-}
-
 int security_task_setnice(struct task_struct *p, int nice)
 {
        return security_ops->task_setnice(p, nice);
@@ -1319,13 +1257,6 @@ int security_key_getsecurity(struct key *key, char **_buffer)
        return security_ops->key_getsecurity(key, _buffer);
 }
 
-int security_key_session_to_parent(const struct cred *cred,
-                                  const struct cred *parent_cred,
-                                  struct key *key)
-{
-       return security_ops->key_session_to_parent(cred, parent_cred, key);
-}
-
 #endif /* CONFIG_KEYS */
 
 #ifdef CONFIG_AUDIT
index 989fef8..7f1a304 100644 (file)
@@ -499,8 +499,7 @@ void avc_audit(u32 ssid, u32 tsid,
                return;
        if (!a) {
                a = &stack_data;
-               memset(a, 0, sizeof(*a));
-               a->type = LSM_AUDIT_NO_AUDIT;
+               COMMON_AUDIT_DATA_INIT(a, NONE);
        }
        a->selinux_audit_data.tclass = tclass;
        a->selinux_audit_data.requested = requested;
index 5feecb4..a03fd74 100644 (file)
@@ -293,28 +293,28 @@ static void superblock_free_security(struct super_block *sb)
 
 static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
 {
-       struct sk_security_struct *ssec;
+       struct sk_security_struct *sksec;
 
-       ssec = kzalloc(sizeof(*ssec), priority);
-       if (!ssec)
+       sksec = kzalloc(sizeof(*sksec), priority);
+       if (!sksec)
                return -ENOMEM;
 
-       ssec->peer_sid = SECINITSID_UNLABELED;
-       ssec->sid = SECINITSID_UNLABELED;
-       sk->sk_security = ssec;
+       sksec->peer_sid = SECINITSID_UNLABELED;
+       sksec->sid = SECINITSID_UNLABELED;
+       sk->sk_security = sksec;
 
-       selinux_netlbl_sk_security_reset(ssec);
+       selinux_netlbl_sk_security_reset(sksec);
 
        return 0;
 }
 
 static void sk_free_security(struct sock *sk)
 {
-       struct sk_security_struct *ssec = sk->sk_security;
+       struct sk_security_struct *sksec = sk->sk_security;
 
        sk->sk_security = NULL;
-       selinux_netlbl_sk_security_free(ssec);
-       kfree(ssec);
+       selinux_netlbl_sk_security_free(sksec);
+       kfree(sksec);
 }
 
 /* The security server must be initialized before
@@ -323,7 +323,7 @@ extern int ss_initialized;
 
 /* The file system's label must be initialized prior to use. */
 
-static char *labeling_behaviors[6] = {
+static const char *labeling_behaviors[6] = {
        "uses xattr",
        "uses transition SIDs",
        "uses task SIDs",
@@ -2999,13 +2999,15 @@ static int selinux_file_ioctl(struct file *file, unsigned int cmd,
        return file_has_perm(cred, file, av);
 }
 
+static int default_noexec;
+
 static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
 {
        const struct cred *cred = current_cred();
        int rc = 0;
 
-#ifndef CONFIG_PPC32
-       if ((prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) {
+       if (default_noexec &&
+           (prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) {
                /*
                 * We are making executable an anonymous mapping or a
                 * private file mapping that will also be writable.
@@ -3015,7 +3017,6 @@ static int file_map_prot_check(struct file *file, unsigned long prot, int shared
                if (rc)
                        goto error;
        }
-#endif
 
        if (file) {
                /* read access is always possible with a mapping */
@@ -3076,8 +3077,8 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
        if (selinux_checkreqprot)
                prot = reqprot;
 
-#ifndef CONFIG_PPC32
-       if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
+       if (default_noexec &&
+           (prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) {
                int rc = 0;
                if (vma->vm_start >= vma->vm_mm->start_brk &&
                    vma->vm_end <= vma->vm_mm->brk) {
@@ -3099,7 +3100,6 @@ static int selinux_file_mprotect(struct vm_area_struct *vma,
                if (rc)
                        return rc;
        }
-#endif
 
        return file_map_prot_check(vma->vm_file, prot, vma->vm_flags&VM_SHARED);
 }
@@ -4002,7 +4002,7 @@ static int selinux_socket_unix_stream_connect(struct socket *sock,
                                              struct socket *other,
                                              struct sock *newsk)
 {
-       struct sk_security_struct *ssec;
+       struct sk_security_struct *sksec;
        struct inode_security_struct *isec;
        struct inode_security_struct *other_isec;
        struct common_audit_data ad;
@@ -4021,13 +4021,13 @@ static int selinux_socket_unix_stream_connect(struct socket *sock,
                return err;
 
        /* connecting socket */
-       ssec = sock->sk->sk_security;
-       ssec->peer_sid = other_isec->sid;
+       sksec = sock->sk->sk_security;
+       sksec->peer_sid = other_isec->sid;
 
        /* server child socket */
-       ssec = newsk->sk_security;
-       ssec->peer_sid = isec->sid;
-       err = security_sid_mls_copy(other_isec->sid, ssec->peer_sid, &ssec->sid);
+       sksec = newsk->sk_security;
+       sksec->peer_sid = isec->sid;
+       err = security_sid_mls_copy(other_isec->sid, sksec->peer_sid, &sksec->sid);
 
        return err;
 }
@@ -4190,7 +4190,7 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op
        int err = 0;
        char *scontext;
        u32 scontext_len;
-       struct sk_security_struct *ssec;
+       struct sk_security_struct *sksec;
        struct inode_security_struct *isec;
        u32 peer_sid = SECSID_NULL;
 
@@ -4198,8 +4198,8 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op
 
        if (isec->sclass == SECCLASS_UNIX_STREAM_SOCKET ||
            isec->sclass == SECCLASS_TCP_SOCKET) {
-               ssec = sock->sk->sk_security;
-               peer_sid = ssec->peer_sid;
+               sksec = sock->sk->sk_security;
+               peer_sid = sksec->peer_sid;
        }
        if (peer_sid == SECSID_NULL) {
                err = -ENOPROTOOPT;
@@ -4266,14 +4266,14 @@ static void selinux_sk_free_security(struct sock *sk)
 
 static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
 {
-       struct sk_security_struct *ssec = sk->sk_security;
-       struct sk_security_struct *newssec = newsk->sk_security;
+       struct sk_security_struct *sksec = sk->sk_security;
+       struct sk_security_struct *newsksec = newsk->sk_security;
 
-       newssec->sid = ssec->sid;
-       newssec->peer_sid = ssec->peer_sid;
-       newssec->sclass = ssec->sclass;
+       newsksec->sid = sksec->sid;
+       newsksec->peer_sid = sksec->peer_sid;
+       newsksec->sclass = sksec->sclass;
 
-       selinux_netlbl_sk_security_reset(newssec);
+       selinux_netlbl_sk_security_reset(newsksec);
 }
 
 static void selinux_sk_getsecid(struct sock *sk, u32 *secid)
@@ -5662,6 +5662,8 @@ static __init int selinux_init(void)
        /* Set the security state for the initial task. */
        cred_init_security();
 
+       default_noexec = !(VM_DATA_DEFAULT_FLAGS & VM_EXEC);
+
        sel_inode_cache = kmem_cache_create("selinux_inode_security",
                                            sizeof(struct inode_security_struct),
                                            0, SLAB_PANIC, NULL);
index d4fac82..a59b64e 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is automatically generated.  Do not edit. */
-static char *initial_sid_to_string[] =
+static const char *initial_sid_to_string[] =
 {
     "null",
     "kernel",
index 8d73842..cf2f628 100644 (file)
@@ -42,8 +42,8 @@ void selinux_netlbl_cache_invalidate(void);
 
 void selinux_netlbl_err(struct sk_buff *skb, int error, int gateway);
 
-void selinux_netlbl_sk_security_free(struct sk_security_struct *ssec);
-void selinux_netlbl_sk_security_reset(struct sk_security_struct *ssec);
+void selinux_netlbl_sk_security_free(struct sk_security_struct *sksec);
+void selinux_netlbl_sk_security_reset(struct sk_security_struct *sksec);
 
 int selinux_netlbl_skbuff_getsid(struct sk_buff *skb,
                                 u16 family,
@@ -79,13 +79,13 @@ static inline void selinux_netlbl_err(struct sk_buff *skb,
 }
 
 static inline void selinux_netlbl_sk_security_free(
-                                              struct sk_security_struct *ssec)
+                                              struct sk_security_struct *sksec)
 {
        return;
 }
 
 static inline void selinux_netlbl_sk_security_reset(
-                                              struct sk_security_struct *ssec)
+                                              struct sk_security_struct *sksec)
 {
        return;
 }
index 628da72..1c2fc46 100644 (file)
@@ -132,21 +132,21 @@ void selinux_netlbl_err(struct sk_buff *skb, int error, int gateway)
 
 /**
  * selinux_netlbl_sk_security_free - Free the NetLabel fields
- * @sssec: the sk_security_struct
+ * @sksec: the sk_security_struct
  *
  * Description:
  * Free all of the memory in the NetLabel fields of a sk_security_struct.
  *
  */
-void selinux_netlbl_sk_security_free(struct sk_security_struct *ssec)
+void selinux_netlbl_sk_security_free(struct sk_security_struct *sksec)
 {
-       if (ssec->nlbl_secattr != NULL)
-               netlbl_secattr_free(ssec->nlbl_secattr);
+       if (sksec->nlbl_secattr != NULL)
+               netlbl_secattr_free(sksec->nlbl_secattr);
 }
 
 /**
  * selinux_netlbl_sk_security_reset - Reset the NetLabel fields
- * @ssec: the sk_security_struct
+ * @sksec: the sk_security_struct
  * @family: the socket family
  *
  * Description:
@@ -154,9 +154,9 @@ void selinux_netlbl_sk_security_free(struct sk_security_struct *ssec)
  * The caller is responsibile for all the NetLabel sk_security_struct locking.
  *
  */
-void selinux_netlbl_sk_security_reset(struct sk_security_struct *ssec)
+void selinux_netlbl_sk_security_reset(struct sk_security_struct *sksec)
 {
-       ssec->nlbl_state = NLBL_UNSET;
+       sksec->nlbl_state = NLBL_UNSET;
 }
 
 /**
index 0e147b6..36ac257 100644 (file)
@@ -14,7 +14,6 @@
 #include <linux/slab.h>
 #include <linux/stddef.h>
 #include <linux/kernel.h>
-#include <linux/list.h>
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
 #include <linux/selinux_netlink.h>
index dd7cc6d..75ec0c6 100644 (file)
@@ -11,7 +11,6 @@
  */
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/skbuff.h>
 #include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 #include <linux/if.h>
index cd191bb..0293843 100644 (file)
@@ -503,11 +503,11 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
                return length;
 
        length = -ENOMEM;
-       scon = kzalloc(size+1, GFP_KERNEL);
+       scon = kzalloc(size + 1, GFP_KERNEL);
        if (!scon)
                return length;
 
-       tcon = kzalloc(size+1, GFP_KERNEL);
+       tcon = kzalloc(size + 1, GFP_KERNEL);
        if (!tcon)
                goto out;
 
@@ -515,10 +515,10 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
        if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
                goto out2;
 
-       length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
+       length = security_context_to_sid(scon, strlen(scon) + 1, &ssid);
        if (length < 0)
                goto out2;
-       length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
+       length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
        if (length < 0)
                goto out2;
 
@@ -550,11 +550,11 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
                return length;
 
        length = -ENOMEM;
-       scon = kzalloc(size+1, GFP_KERNEL);
+       scon = kzalloc(size + 1, GFP_KERNEL);
        if (!scon)
                return length;
 
-       tcon = kzalloc(size+1, GFP_KERNEL);
+       tcon = kzalloc(size + 1, GFP_KERNEL);
        if (!tcon)
                goto out;
 
@@ -562,10 +562,10 @@ static ssize_t sel_write_create(struct file *file, char *buf, size_t size)
        if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
                goto out2;
 
-       length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
+       length = security_context_to_sid(scon, strlen(scon) + 1, &ssid);
        if (length < 0)
                goto out2;
-       length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
+       length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
        if (length < 0)
                goto out2;
 
@@ -609,11 +609,11 @@ static ssize_t sel_write_relabel(struct file *file, char *buf, size_t size)
                return length;
 
        length = -ENOMEM;
-       scon = kzalloc(size+1, GFP_KERNEL);
+       scon = kzalloc(size + 1, GFP_KERNEL);
        if (!scon)
                return length;
 
-       tcon = kzalloc(size+1, GFP_KERNEL);
+       tcon = kzalloc(size + 1, GFP_KERNEL);
        if (!tcon)
                goto out;
 
@@ -621,10 +621,10 @@ static ssize_t sel_write_relabel(struct file *file, char *buf, size_t size)
        if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
                goto out2;
 
-       length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
+       length = security_context_to_sid(scon, strlen(scon) + 1, &ssid);
        if (length < 0)
                goto out2;
-       length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
+       length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
        if (length < 0)
                goto out2;
 
@@ -666,11 +666,11 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
                return length;
 
        length = -ENOMEM;
-       con = kzalloc(size+1, GFP_KERNEL);
+       con = kzalloc(size + 1, GFP_KERNEL);
        if (!con)
                return length;
 
-       user = kzalloc(size+1, GFP_KERNEL);
+       user = kzalloc(size + 1, GFP_KERNEL);
        if (!user)
                goto out;
 
@@ -678,7 +678,7 @@ static ssize_t sel_write_user(struct file *file, char *buf, size_t size)
        if (sscanf(buf, "%s %s", con, user) != 2)
                goto out2;
 
-       length = security_context_to_sid(con, strlen(con)+1, &sid);
+       length = security_context_to_sid(con, strlen(con) + 1, &sid);
        if (length < 0)
                goto out2;
 
@@ -727,11 +727,11 @@ static ssize_t sel_write_member(struct file *file, char *buf, size_t size)
                return length;
 
        length = -ENOMEM;
-       scon = kzalloc(size+1, GFP_KERNEL);
+       scon = kzalloc(size + 1, GFP_KERNEL);
        if (!scon)
                return length;
 
-       tcon = kzalloc(size+1, GFP_KERNEL);
+       tcon = kzalloc(size + 1, GFP_KERNEL);
        if (!tcon)
                goto out;
 
@@ -739,10 +739,10 @@ static ssize_t sel_write_member(struct file *file, char *buf, size_t size)
        if (sscanf(buf, "%s %s %hu", scon, tcon, &tclass) != 3)
                goto out2;
 
-       length = security_context_to_sid(scon, strlen(scon)+1, &ssid);
+       length = security_context_to_sid(scon, strlen(scon) + 1, &ssid);
        if (length < 0)
                goto out2;
-       length = security_context_to_sid(tcon, strlen(tcon)+1, &tsid);
+       length = security_context_to_sid(tcon, strlen(tcon) + 1, &tsid);
        if (length < 0)
                goto out2;
 
@@ -1401,7 +1401,7 @@ static int sel_make_perm_files(char *objclass, int classvalue,
                }
                inode->i_fop = &sel_perm_ops;
                /* i+1 since perm values are 1-indexed */
-               inode->i_ino = sel_perm_to_ino(classvalue, i+1);
+               inode->i_ino = sel_perm_to_ino(classvalue, i + 1);
                d_add(dentry, inode);
        }
 
@@ -1489,7 +1489,7 @@ static int sel_make_classes(void)
                goto out;
 
        /* +2 since classes are 1-indexed */
-       last_class_ino = sel_class_to_ino(nclasses+2);
+       last_class_ino = sel_class_to_ino(nclasses + 2);
 
        for (i = 0; i < nclasses; i++) {
                struct dentry *class_name_dir;
@@ -1506,7 +1506,7 @@ static int sel_make_classes(void)
                        goto out1;
 
                /* i+1 since class values are 1-indexed */
-               rc = sel_make_class_dir_entries(classes[i], i+1,
+               rc = sel_make_class_dir_entries(classes[i], i + 1,
                                class_name_dir);
                if (rc)
                        goto out1;
index 372b773..b4eff7a 100644 (file)
@@ -255,7 +255,7 @@ int mls_context_to_sid(struct policydb *pol,
 
        if (!pol->mls_enabled) {
                if (def_sid != SECSID_NULL && oldc)
-                       *scontext += strlen(*scontext)+1;
+                       *scontext += strlen(*scontext) + 1;
                return 0;
        }
 
index 23c6e53..c57802a 100644 (file)
@@ -40,7 +40,7 @@
 #define _DEBUG_HASHES
 
 #ifdef DEBUG_HASHES
-static char *symtab_name[SYM_NUM] = {
+static const char *symtab_name[SYM_NUM] = {
        "common prefixes",
        "classes",
        "roles",
@@ -156,12 +156,11 @@ static int roles_init(struct policydb *p)
                rc = -EINVAL;
                goto out_free_role;
        }
-       key = kmalloc(strlen(OBJECT_R)+1, GFP_KERNEL);
+       key = kstrdup(OBJECT_R, GFP_KERNEL);
        if (!key) {
                rc = -ENOMEM;
                goto out_free_role;
        }
-       strcpy(key, OBJECT_R);
        rc = hashtab_insert(p->p_roles.table, key, role);
        if (rc)
                goto out_free_key;
@@ -2195,7 +2194,7 @@ int policydb_read(struct policydb *p, void *fp)
                rangetr_hash_eval(p->range_tr);
        }
 
-       p->type_attr_map = kmalloc(p->p_types.nprim*sizeof(struct ebitmap), GFP_KERNEL);
+       p->type_attr_map = kmalloc(p->p_types.nprim * sizeof(struct ebitmap), GFP_KERNEL);
        if (!p->type_attr_map)
                goto bad;
 
index cf27b3e..1de60ce 100644 (file)
@@ -274,15 +274,15 @@ static int constraint_expr_eval(struct context *scontext,
                case CEXPR_AND:
                        BUG_ON(sp < 1);
                        sp--;
-                       s[sp] &= s[sp+1];
+                       s[sp] &= s[sp + 1];
                        break;
                case CEXPR_OR:
                        BUG_ON(sp < 1);
                        sp--;
-                       s[sp] |= s[sp+1];
+                       s[sp] |= s[sp + 1];
                        break;
                case CEXPR_ATTR:
-                       if (sp == (CEXPR_MAXDEPTH-1))
+                       if (sp == (CEXPR_MAXDEPTH - 1))
                                return 0;
                        switch (e->attr) {
                        case CEXPR_USER:
@@ -1216,7 +1216,7 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
        *sid = SECSID_NULL;
 
        /* Copy the string so that we can modify the copy as we parse it. */
-       scontext2 = kmalloc(scontext_len+1, gfp_flags);
+       scontext2 = kmalloc(scontext_len + 1, gfp_flags);
        if (!scontext2)
                return -ENOMEM;
        memcpy(scontext2, scontext, scontext_len);
@@ -1760,22 +1760,28 @@ int security_load_policy(void *data, size_t len)
 
        if (!ss_initialized) {
                avtab_cache_init();
-               if (policydb_read(&policydb, fp)) {
+               rc = policydb_read(&policydb, fp);
+               if (rc) {
                        avtab_cache_destroy();
-                       return -EINVAL;
+                       return rc;
                }
-               if (selinux_set_mapping(&policydb, secclass_map,
-                                       &current_mapping,
-                                       &current_mapping_size)) {
+
+               rc = selinux_set_mapping(&policydb, secclass_map,
+                                        &current_mapping,
+                                        &current_mapping_size);
+               if (rc) {
                        policydb_destroy(&policydb);
                        avtab_cache_destroy();
-                       return -EINVAL;
+                       return rc;
                }
-               if (policydb_load_isids(&policydb, &sidtab)) {
+
+               rc = policydb_load_isids(&policydb, &sidtab);
+               if (rc) {
                        policydb_destroy(&policydb);
                        avtab_cache_destroy();
-                       return -EINVAL;
+                       return rc;
                }
+
                security_load_policycaps();
                ss_initialized = 1;
                seqno = ++latest_granting;
@@ -1791,8 +1797,9 @@ int security_load_policy(void *data, size_t len)
        sidtab_hash_eval(&sidtab, "sids");
 #endif
 
-       if (policydb_read(&newpolicydb, fp))
-               return -EINVAL;
+       rc = policydb_read(&newpolicydb, fp);
+       if (rc)
+               return rc;
 
        /* If switching between different policy types, log MLS status */
        if (policydb.mls_enabled && !newpolicydb.mls_enabled)
@@ -1807,8 +1814,8 @@ int security_load_policy(void *data, size_t len)
                return rc;
        }
 
-       if (selinux_set_mapping(&newpolicydb, secclass_map,
-                               &map, &map_size))
+       rc = selinux_set_mapping(&newpolicydb, secclass_map, &map, &map_size);
+       if (rc)
                goto err;
 
        rc = security_preserve_bools(&newpolicydb);
@@ -1819,10 +1826,10 @@ int security_load_policy(void *data, size_t len)
 
        /* Clone the SID table. */
        sidtab_shutdown(&sidtab);
-       if (sidtab_map(&sidtab, clone_sid, &newsidtab)) {
-               rc = -ENOMEM;
+
+       rc = sidtab_map(&sidtab, clone_sid, &newsidtab);
+       if (rc)
                goto err;
-       }
 
        /*
         * Convert the internal representations of contexts
@@ -2101,9 +2108,9 @@ int security_get_user_sids(u32 fromsid,
 
        ebitmap_for_each_positive_bit(&user->roles, rnode, i) {
                role = policydb.role_val_to_struct[i];
-               usercon.role = i+1;
+               usercon.role = i + 1;
                ebitmap_for_each_positive_bit(&role->types, tnode, j) {
-                       usercon.type = j+1;
+                       usercon.type = j + 1;
 
                        if (mls_setup_user_range(fromcon, user, &usercon))
                                continue;
index fdfeaa2..0f2fc48 100644 (file)
@@ -19,7 +19,6 @@
 #include <linux/pagemap.h>
 #include <linux/mount.h>
 #include <linux/stat.h>
-#include <linux/ext2_fs.h>
 #include <linux/kd.h>
 #include <asm/ioctls.h>
 #include <linux/ip.h>
@@ -1118,15 +1117,6 @@ static int smack_cred_prepare(struct cred *new, const struct cred *old,
        return 0;
 }
 
-/**
- * smack_cred_commit - commit new credentials
- * @new: the new credentials
- * @old: the original credentials
- */
-static void smack_cred_commit(struct cred *new, const struct cred *old)
-{
-}
-
 /**
  * smack_cred_transfer - Transfer the old credentials to the new credentials
  * @new: the new credentials
@@ -3121,7 +3111,6 @@ struct security_operations smack_ops = {
        .cred_alloc_blank =             smack_cred_alloc_blank,
        .cred_free =                    smack_cred_free,
        .cred_prepare =                 smack_cred_prepare,
-       .cred_commit =                  smack_cred_commit,
        .cred_transfer =                smack_cred_transfer,
        .kernel_act_as =                smack_kernel_act_as,
        .kernel_create_files_as =       smack_kernel_create_files_as,
index 60a9e20..4fb3903 100644 (file)
@@ -1 +1 @@
-obj-y = common.o realpath.o tomoyo.o domain.o file.o gc.o
+obj-y = common.o realpath.o tomoyo.o domain.o file.o gc.o path_group.o
index 975c45d..b5dbdc9 100644 (file)
@@ -75,6 +75,49 @@ static int tomoyo_read_control(struct file *file, char __user *buffer,
 static int tomoyo_write_control(struct file *file, const char __user *buffer,
                                const int buffer_len);
 
+/**
+ * tomoyo_parse_name_union - Parse a tomoyo_name_union.
+ *
+ * @filename: Name or name group.
+ * @ptr:      Pointer to "struct tomoyo_name_union".
+ *
+ * Returns true on success, false otherwise.
+ */
+bool tomoyo_parse_name_union(const char *filename,
+                            struct tomoyo_name_union *ptr)
+{
+       if (!tomoyo_is_correct_path(filename, 0, 0, 0))
+               return false;
+       if (filename[0] == '@') {
+               ptr->group = tomoyo_get_path_group(filename + 1);
+               ptr->is_group = true;
+               return ptr->group != NULL;
+       }
+       ptr->filename = tomoyo_get_name(filename);
+       ptr->is_group = false;
+       return ptr->filename != NULL;
+}
+
+/**
+ * tomoyo_print_name_union - Print a tomoyo_name_union.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ * @ptr:  Pointer to "struct tomoyo_name_union".
+ *
+ * Returns true on success, false otherwise.
+ */
+static bool tomoyo_print_name_union(struct tomoyo_io_buffer *head,
+                                const struct tomoyo_name_union *ptr)
+{
+       int pos = head->read_avail;
+       if (pos && head->read_buf[pos - 1] == ' ')
+               head->read_avail--;
+       if (ptr->is_group)
+               return tomoyo_io_printf(head, " @%s",
+                                       ptr->group->group_name->name);
+       return tomoyo_io_printf(head, " %s", ptr->filename->name);
+}
+
 /**
  * tomoyo_is_byte_range - Check whether the string isa \ooo style octal value.
  *
@@ -171,6 +214,33 @@ static void tomoyo_normalize_line(unsigned char *buffer)
        *dp = '\0';
 }
 
+/**
+ * tomoyo_tokenize - Tokenize string.
+ *
+ * @buffer: The line to tokenize.
+ * @w:      Pointer to "char *".
+ * @size:   Sizeof @w .
+ *
+ * Returns true on success, false otherwise.
+ */
+bool tomoyo_tokenize(char *buffer, char *w[], size_t size)
+{
+       int count = size / sizeof(char *);
+       int i;
+       for (i = 0; i < count; i++)
+               w[i] = "";
+       for (i = 0; i < count; i++) {
+               char *cp = strchr(buffer, ' ');
+               if (cp)
+                       *cp = '\0';
+               w[i] = buffer;
+               if (!cp)
+                       break;
+               buffer = cp + 1;
+       }
+       return i < count || !*buffer;
+}
+
 /**
  * tomoyo_is_correct_path - Validate a pathname.
  * @filename:     The pathname to check.
@@ -874,17 +944,17 @@ bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain)
 static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
                                                                int profile)
 {
-       static DEFINE_MUTEX(lock);
        struct tomoyo_profile *ptr = NULL;
        int i;
 
        if (profile >= TOMOYO_MAX_PROFILES)
                return NULL;
-       mutex_lock(&lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return NULL;
        ptr = tomoyo_profile_ptr[profile];
        if (ptr)
                goto ok;
-       ptr = kmalloc(sizeof(*ptr), GFP_KERNEL);
+       ptr = kmalloc(sizeof(*ptr), GFP_NOFS);
        if (!tomoyo_memory_ok(ptr)) {
                kfree(ptr);
                ptr = NULL;
@@ -895,7 +965,7 @@ static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
        mb(); /* Avoid out-of-order execution. */
        tomoyo_profile_ptr[profile] = ptr;
  ok:
-       mutex_unlock(&lock);
+       mutex_unlock(&tomoyo_policy_lock);
        return ptr;
 }
 
@@ -1071,44 +1141,42 @@ LIST_HEAD(tomoyo_policy_manager_list);
 static int tomoyo_update_manager_entry(const char *manager,
                                       const bool is_delete)
 {
-       struct tomoyo_policy_manager_entry *entry = NULL;
        struct tomoyo_policy_manager_entry *ptr;
-       const struct tomoyo_path_info *saved_manager;
+       struct tomoyo_policy_manager_entry e = { };
        int error = is_delete ? -ENOENT : -ENOMEM;
-       bool is_domain = false;
 
        if (tomoyo_is_domain_def(manager)) {
                if (!tomoyo_is_correct_domain(manager))
                        return -EINVAL;
-               is_domain = true;
+               e.is_domain = true;
        } else {
                if (!tomoyo_is_correct_path(manager, 1, -1, -1))
                        return -EINVAL;
        }
-       saved_manager = tomoyo_get_name(manager);
-       if (!saved_manager)
+       e.manager = tomoyo_get_name(manager);
+       if (!e.manager)
                return -ENOMEM;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
        list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
-               if (ptr->manager != saved_manager)
+               if (ptr->manager != e.manager)
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->manager = saved_manager;
-               saved_manager = NULL;
-               entry->is_domain = is_domain;
-               list_add_tail_rcu(&entry->list, &tomoyo_policy_manager_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_policy_manager_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_policy_manager_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
-       tomoyo_put_name(saved_manager);
-       kfree(entry);
+ out:
+       tomoyo_put_name(e.manager);
        return error;
 }
 
@@ -1287,7 +1355,8 @@ static int tomoyo_delete_domain(char *domainname)
 
        name.name = domainname;
        tomoyo_fill_path_info(&name);
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return 0;
        /* Is there an active domain? */
        list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
                /* Never delete tomoyo_kernel_domain */
@@ -1369,23 +1438,20 @@ static bool tomoyo_print_path_acl(struct tomoyo_io_buffer *head,
 {
        int pos;
        u8 bit;
-       const char *atmark = "";
-       const char *filename;
        const u32 perm = ptr->perm | (((u32) ptr->perm_high) << 16);
 
-       filename = ptr->filename->name;
        for (bit = head->read_bit; bit < TOMOYO_MAX_PATH_OPERATION; bit++) {
-               const char *msg;
                if (!(perm & (1 << bit)))
                        continue;
                /* Print "read/write" instead of "read" and "write". */
                if ((bit == TOMOYO_TYPE_READ || bit == TOMOYO_TYPE_WRITE)
                    && (perm & (1 << TOMOYO_TYPE_READ_WRITE)))
                        continue;
-               msg = tomoyo_path2keyword(bit);
                pos = head->read_avail;
-               if (!tomoyo_io_printf(head, "allow_%s %s%s\n", msg,
-                                     atmark, filename))
+               if (!tomoyo_io_printf(head, "allow_%s ",
+                                     tomoyo_path2keyword(bit)) ||
+                   !tomoyo_print_name_union(head, &ptr->name) ||
+                   !tomoyo_io_printf(head, "\n"))
                        goto out;
        }
        head->read_bit = 0;
@@ -1408,23 +1474,18 @@ static bool tomoyo_print_path2_acl(struct tomoyo_io_buffer *head,
                                   struct tomoyo_path2_acl *ptr)
 {
        int pos;
-       const char *atmark1 = "";
-       const char *atmark2 = "";
-       const char *filename1;
-       const char *filename2;
        const u8 perm = ptr->perm;
        u8 bit;
 
-       filename1 = ptr->filename1->name;
-       filename2 = ptr->filename2->name;
        for (bit = head->read_bit; bit < TOMOYO_MAX_PATH2_OPERATION; bit++) {
-               const char *msg;
                if (!(perm & (1 << bit)))
                        continue;
-               msg = tomoyo_path22keyword(bit);
                pos = head->read_avail;
-               if (!tomoyo_io_printf(head, "allow_%s %s%s %s%s\n", msg,
-                                     atmark1, filename1, atmark2, filename2))
+               if (!tomoyo_io_printf(head, "allow_%s ",
+                                     tomoyo_path22keyword(bit)) ||
+                   !tomoyo_print_name_union(head, &ptr->name1) ||
+                   !tomoyo_print_name_union(head, &ptr->name2) ||
+                   !tomoyo_io_printf(head, "\n"))
                        goto out;
        }
        head->read_bit = 0;
@@ -1687,6 +1748,8 @@ static int tomoyo_write_exception_policy(struct tomoyo_io_buffer *head)
                return tomoyo_write_pattern_policy(data, is_delete);
        if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_DENY_REWRITE))
                return tomoyo_write_no_rewrite_policy(data, is_delete);
+       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_PATH_GROUP))
+               return tomoyo_write_path_group_policy(data, is_delete);
        return -EINVAL;
 }
 
@@ -1743,6 +1806,12 @@ static int tomoyo_read_exception_policy(struct tomoyo_io_buffer *head)
                        head->read_var2 = NULL;
                        head->read_step = 9;
                case 9:
+                       if (!tomoyo_read_path_group_policy(head))
+                               break;
+                       head->read_var1 = NULL;
+                       head->read_var2 = NULL;
+                       head->read_step = 10;
+               case 10:
                        head->read_eof = true;
                        break;
                default:
@@ -1886,7 +1955,7 @@ static int tomoyo_read_self_domain(struct tomoyo_io_buffer *head)
  */
 static int tomoyo_open_control(const u8 type, struct file *file)
 {
-       struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_KERNEL);
+       struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
 
        if (!head)
                return -ENOMEM;
@@ -1947,7 +2016,7 @@ static int tomoyo_open_control(const u8 type, struct file *file)
        } else {
                if (!head->readbuf_size)
                        head->readbuf_size = 4096 * 2;
-               head->read_buf = kzalloc(head->readbuf_size, GFP_KERNEL);
+               head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS);
                if (!head->read_buf) {
                        kfree(head);
                        return -ENOMEM;
@@ -1961,7 +2030,7 @@ static int tomoyo_open_control(const u8 type, struct file *file)
                head->write = NULL;
        } else if (head->write) {
                head->writebuf_size = 4096 * 2;
-               head->write_buf = kzalloc(head->writebuf_size, GFP_KERNEL);
+               head->write_buf = kzalloc(head->writebuf_size, GFP_NOFS);
                if (!head->write_buf) {
                        kfree(head->read_buf);
                        kfree(head);
index 67bd22d..9f1ae5e 100644 (file)
@@ -54,6 +54,7 @@ struct linux_binprm;
 #define TOMOYO_KEYWORD_KEEP_DOMAIN               "keep_domain "
 #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN      "no_initialize_domain "
 #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN            "no_keep_domain "
+#define TOMOYO_KEYWORD_PATH_GROUP                "path_group "
 #define TOMOYO_KEYWORD_SELECT                    "select "
 #define TOMOYO_KEYWORD_USE_PROFILE               "use_profile "
 #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ  "ignore_global_allow_read"
@@ -204,6 +205,27 @@ struct tomoyo_path_info_with_data {
        char barrier2[16]; /* Safeguard for overrun. */
 };
 
+struct tomoyo_name_union {
+       const struct tomoyo_path_info *filename;
+       struct tomoyo_path_group *group;
+       u8 is_group;
+};
+
+/* Structure for "path_group" directive. */
+struct tomoyo_path_group {
+       struct list_head list;
+       const struct tomoyo_path_info *group_name;
+       struct list_head member_list;
+       atomic_t users;
+};
+
+/* Structure for "path_group" directive. */
+struct tomoyo_path_group_member {
+       struct list_head list;
+       bool is_deleted;
+       const struct tomoyo_path_info *member_name;
+};
+
 /*
  * tomoyo_acl_info is a structure which is used for holding
  *
@@ -274,7 +296,7 @@ struct tomoyo_domain_info {
  *
  *  (1) "head" which is a "struct tomoyo_acl_info".
  *  (2) "perm" which is a bitmask of permitted operations.
- *  (3) "filename" is the pathname.
+ *  (3) "name" is the pathname.
  *
  * Directives held by this structure are "allow_read/write", "allow_execute",
  * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
@@ -287,8 +309,7 @@ struct tomoyo_path_acl {
        struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
        u8 perm_high;
        u16 perm;
-       /* Pointer to single pathname. */
-       const struct tomoyo_path_info *filename;
+       struct tomoyo_name_union name;
 };
 
 /*
@@ -298,8 +319,8 @@ struct tomoyo_path_acl {
  *
  *  (1) "head" which is a "struct tomoyo_acl_info".
  *  (2) "perm" which is a bitmask of permitted operations.
- *  (3) "filename1" is the source/old pathname.
- *  (4) "filename2" is the destination/new pathname.
+ *  (3) "name1" is the source/old pathname.
+ *  (4) "name2" is the destination/new pathname.
  *
  * Directives held by this structure are "allow_rename", "allow_link" and
  * "allow_pivot_root".
@@ -307,10 +328,8 @@ struct tomoyo_path_acl {
 struct tomoyo_path2_acl {
        struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH2_ACL */
        u8 perm;
-       /* Pointer to single pathname. */
-       const struct tomoyo_path_info *filename1;
-       /* Pointer to single pathname. */
-       const struct tomoyo_path_info *filename2;
+       struct tomoyo_name_union name1;
+       struct tomoyo_name_union name2;
 };
 
 /*
@@ -514,6 +533,9 @@ struct tomoyo_policy_manager_entry {
 
 /********** Function prototypes. **********/
 
+/* Check whether the given name matches the given name_union. */
+bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
+                              const struct tomoyo_name_union *ptr);
 /* Check whether the domain has too many ACL entries to hold. */
 bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain);
 /* Transactional sprintf() for policy dump. */
@@ -526,6 +548,12 @@ bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
                            const s8 pattern_type, const s8 end_type);
 /* Check whether the token can be a domainname. */
 bool tomoyo_is_domain_def(const unsigned char *buffer);
+bool tomoyo_parse_name_union(const char *filename,
+                            struct tomoyo_name_union *ptr);
+/* Check whether the given filename matches the given path_group. */
+bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
+                              const struct tomoyo_path_group *group,
+                              const bool may_use_pattern);
 /* Check whether the given filename matches the given pattern. */
 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
                                 const struct tomoyo_path_info *pattern);
@@ -540,10 +568,14 @@ bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
 bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
 /* Read "file_pattern" entry in exception policy. */
 bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
+/* Read "path_group" entry in exception policy. */
+bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
 /* Read "allow_read" entry in exception policy. */
 bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
 /* Read "deny_rewrite" entry in exception policy. */
 bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
+/* Tokenize a line. */
+bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
 /* Write domain policy violation warning message to console? */
 bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
 /* Convert double path operation to operation name. */
@@ -580,12 +612,18 @@ int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
 int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
 /* Create "file_pattern" entry in exception policy. */
 int tomoyo_write_pattern_policy(char *data, const bool is_delete);
+/* Create "path_group" entry in exception policy. */
+int tomoyo_write_path_group_policy(char *data, const bool is_delete);
 /* Find a domain by the given name. */
 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
 /* Find or create a domain by the given name. */
 struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
                                                            domainname,
                                                            const u8 profile);
+
+/* Allocate memory for "struct tomoyo_path_group". */
+struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
+
 /* Check mode for specified functionality. */
 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
                                const u8 index);
@@ -616,6 +654,7 @@ char *tomoyo_realpath_from_path(struct path *path);
 
 /* Check memory quota. */
 bool tomoyo_memory_ok(void *ptr);
+void *tomoyo_commit_ok(void *data, const unsigned int size);
 
 /*
  * Keep the given name on the RAM.
@@ -641,6 +680,9 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
 int tomoyo_check_rewrite_permission(struct file *filp);
 int tomoyo_find_next_domain(struct linux_binprm *bprm);
 
+/* Drop refcount on tomoyo_name_union. */
+void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
+
 /* Run garbage collector. */
 void tomoyo_run_gc(void);
 
@@ -654,6 +696,7 @@ extern struct srcu_struct tomoyo_ss;
 /* The list for "struct tomoyo_domain_info". */
 extern struct list_head tomoyo_domain_list;
 
+extern struct list_head tomoyo_path_group_list;
 extern struct list_head tomoyo_domain_initializer_list;
 extern struct list_head tomoyo_domain_keeper_list;
 extern struct list_head tomoyo_alias_list;
@@ -662,7 +705,6 @@ extern struct list_head tomoyo_pattern_list;
 extern struct list_head tomoyo_no_rewrite_list;
 extern struct list_head tomoyo_policy_manager_list;
 extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
-extern struct mutex tomoyo_name_list_lock;
 
 /* Lock for protecting policy. */
 extern struct mutex tomoyo_policy_lock;
@@ -725,6 +767,12 @@ static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
        }
 }
 
+static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
+{
+       if (group)
+               atomic_dec(&group->users);
+}
+
 static inline struct tomoyo_domain_info *tomoyo_domain(void)
 {
        return current_cred()->security;
@@ -736,6 +784,59 @@ static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
        return task_cred_xxx(task, security);
 }
 
+static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1,
+                                          const struct tomoyo_acl_info *p2)
+{
+       return p1->type == p2->type;
+}
+
+static inline bool tomoyo_is_same_name_union
+(const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
+{
+       return p1->filename == p2->filename && p1->group == p2->group &&
+               p1->is_group == p2->is_group;
+}
+
+static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
+                                          const struct tomoyo_path_acl *p2)
+{
+       return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
+               tomoyo_is_same_name_union(&p1->name, &p2->name);
+}
+
+static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
+                                           const struct tomoyo_path2_acl *p2)
+{
+       return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
+               tomoyo_is_same_name_union(&p1->name1, &p2->name1) &&
+               tomoyo_is_same_name_union(&p1->name2, &p2->name2);
+}
+
+static inline bool tomoyo_is_same_domain_initializer_entry
+(const struct tomoyo_domain_initializer_entry *p1,
+ const struct tomoyo_domain_initializer_entry *p2)
+{
+       return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
+               && p1->domainname == p2->domainname
+               && p1->program == p2->program;
+}
+
+static inline bool tomoyo_is_same_domain_keeper_entry
+(const struct tomoyo_domain_keeper_entry *p1,
+ const struct tomoyo_domain_keeper_entry *p2)
+{
+       return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
+               && p1->domainname == p2->domainname
+               && p1->program == p2->program;
+}
+
+static inline bool tomoyo_is_same_alias_entry
+(const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2)
+{
+       return p1->original_name == p2->original_name &&
+               p1->aliased_name == p2->aliased_name;
+}
+
 /**
  * list_for_each_cookie - iterate over a list with cookie.
  * @pos:        the &struct list_head to use as a loop cursor.
index acb8c39..cd8ba44 100644 (file)
@@ -130,57 +130,47 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
                                                  const bool is_not,
                                                  const bool is_delete)
 {
-       struct tomoyo_domain_initializer_entry *entry = NULL;
        struct tomoyo_domain_initializer_entry *ptr;
-       const struct tomoyo_path_info *saved_program = NULL;
-       const struct tomoyo_path_info *saved_domainname = NULL;
+       struct tomoyo_domain_initializer_entry e = { .is_not = is_not };
        int error = is_delete ? -ENOENT : -ENOMEM;
-       bool is_last_name = false;
 
        if (!tomoyo_is_correct_path(program, 1, -1, -1))
                return -EINVAL; /* No patterns allowed. */
        if (domainname) {
                if (!tomoyo_is_domain_def(domainname) &&
                    tomoyo_is_correct_path(domainname, 1, -1, -1))
-                       is_last_name = true;
+                       e.is_last_name = true;
                else if (!tomoyo_is_correct_domain(domainname))
                        return -EINVAL;
-               saved_domainname = tomoyo_get_name(domainname);
-               if (!saved_domainname)
+               e.domainname = tomoyo_get_name(domainname);
+               if (!e.domainname)
                        goto out;
        }
-       saved_program = tomoyo_get_name(program);
-       if (!saved_program)
+       e.program = tomoyo_get_name(program);
+       if (!e.program)
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
                goto out;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
        list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
-               if (ptr->is_not != is_not ||
-                   ptr->domainname != saved_domainname ||
-                   ptr->program != saved_program)
+               if (!tomoyo_is_same_domain_initializer_entry(ptr, &e))
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->domainname = saved_domainname;
-               saved_domainname = NULL;
-               entry->program = saved_program;
-               saved_program = NULL;
-               entry->is_not = is_not;
-               entry->is_last_name = is_last_name;
-               list_add_tail_rcu(&entry->list,
-                                 &tomoyo_domain_initializer_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_domain_initializer_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_domain_initializer_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
  out:
-       tomoyo_put_name(saved_domainname);
-       tomoyo_put_name(saved_program);
-       kfree(entry);
+       tomoyo_put_name(e.domainname);
+       tomoyo_put_name(e.program);
        return error;
 }
 
@@ -350,56 +340,47 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
                                             const bool is_not,
                                             const bool is_delete)
 {
-       struct tomoyo_domain_keeper_entry *entry = NULL;
        struct tomoyo_domain_keeper_entry *ptr;
-       const struct tomoyo_path_info *saved_domainname = NULL;
-       const struct tomoyo_path_info *saved_program = NULL;
+       struct tomoyo_domain_keeper_entry e = { .is_not = is_not };
        int error = is_delete ? -ENOENT : -ENOMEM;
-       bool is_last_name = false;
 
        if (!tomoyo_is_domain_def(domainname) &&
            tomoyo_is_correct_path(domainname, 1, -1, -1))
-               is_last_name = true;
+               e.is_last_name = true;
        else if (!tomoyo_is_correct_domain(domainname))
                return -EINVAL;
        if (program) {
                if (!tomoyo_is_correct_path(program, 1, -1, -1))
                        return -EINVAL;
-               saved_program = tomoyo_get_name(program);
-               if (!saved_program)
+               e.program = tomoyo_get_name(program);
+               if (!e.program)
                        goto out;
        }
-       saved_domainname = tomoyo_get_name(domainname);
-       if (!saved_domainname)
+       e.domainname = tomoyo_get_name(domainname);
+       if (!e.domainname)
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
                goto out;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
        list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
-               if (ptr->is_not != is_not ||
-                   ptr->domainname != saved_domainname ||
-                   ptr->program != saved_program)
+               if (!tomoyo_is_same_domain_keeper_entry(ptr, &e))
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->domainname = saved_domainname;
-               saved_domainname = NULL;
-               entry->program = saved_program;
-               saved_program = NULL;
-               entry->is_not = is_not;
-               entry->is_last_name = is_last_name;
-               list_add_tail_rcu(&entry->list, &tomoyo_domain_keeper_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_domain_keeper_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_domain_keeper_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
  out:
-       tomoyo_put_name(saved_domainname);
-       tomoyo_put_name(saved_program);
-       kfree(entry);
+       tomoyo_put_name(e.domainname);
+       tomoyo_put_name(e.program);
        return error;
 }
 
@@ -551,44 +532,38 @@ static int tomoyo_update_alias_entry(const char *original_name,
                                     const char *aliased_name,
                                     const bool is_delete)
 {
-       struct tomoyo_alias_entry *entry = NULL;
        struct tomoyo_alias_entry *ptr;
-       const struct tomoyo_path_info *saved_original_name;
-       const struct tomoyo_path_info *saved_aliased_name;
+       struct tomoyo_alias_entry e = { };
        int error = is_delete ? -ENOENT : -ENOMEM;
 
        if (!tomoyo_is_correct_path(original_name, 1, -1, -1) ||
            !tomoyo_is_correct_path(aliased_name, 1, -1, -1))
                return -EINVAL; /* No patterns allowed. */
-       saved_original_name = tomoyo_get_name(original_name);
-       saved_aliased_name = tomoyo_get_name(aliased_name);
-       if (!saved_original_name || !saved_aliased_name)
+       e.original_name = tomoyo_get_name(original_name);
+       e.aliased_name = tomoyo_get_name(aliased_name);
+       if (!e.original_name || !e.aliased_name)
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
                goto out;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
        list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
-               if (ptr->original_name != saved_original_name ||
-                   ptr->aliased_name != saved_aliased_name)
+               if (!tomoyo_is_same_alias_entry(ptr, &e))
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->original_name = saved_original_name;
-               saved_original_name = NULL;
-               entry->aliased_name = saved_aliased_name;
-               saved_aliased_name = NULL;
-               list_add_tail_rcu(&entry->list, &tomoyo_alias_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_alias_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list, &tomoyo_alias_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
  out:
-       tomoyo_put_name(saved_original_name);
-       tomoyo_put_name(saved_aliased_name);
-       kfree(entry);
+       tomoyo_put_name(e.original_name);
+       tomoyo_put_name(e.aliased_name);
        return error;
 }
 
@@ -656,7 +631,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
                                                            const u8 profile)
 {
        struct tomoyo_domain_info *entry;
-       struct tomoyo_domain_info *domain;
+       struct tomoyo_domain_info *domain = NULL;
        const struct tomoyo_path_info *saved_domainname;
        bool found = false;
 
@@ -665,8 +640,9 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
        saved_domainname = tomoyo_get_name(domainname);
        if (!saved_domainname)
                return NULL;
-       entry = kzalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
+       entry = kzalloc(sizeof(*entry), GFP_NOFS);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
        list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
                if (domain->is_deleted ||
                    tomoyo_pathcmp(saved_domainname, domain->domainname))
@@ -685,6 +661,7 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
                found = true;
        }
        mutex_unlock(&tomoyo_policy_lock);
+ out:
        tomoyo_put_name(saved_domainname);
        kfree(entry);
        return found ? domain : NULL;
@@ -705,7 +682,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
         * This function assumes that the size of buffer returned by
         * tomoyo_realpath() = TOMOYO_MAX_PATHNAME_LEN.
         */
-       struct tomoyo_page_buffer *tmp = kzalloc(sizeof(*tmp), GFP_KERNEL);
+       struct tomoyo_page_buffer *tmp = kzalloc(sizeof(*tmp), GFP_NOFS);
        struct tomoyo_domain_info *old_domain = tomoyo_domain();
        struct tomoyo_domain_info *domain = NULL;
        const char *old_domain_name = old_domain->domainname->name;
index 6f3fe76..1c6f823 100644 (file)
@@ -45,6 +45,37 @@ static const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = {
        [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root",
 };
 
+void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
+{
+       if (!ptr)
+               return;
+       if (ptr->is_group)
+               tomoyo_put_path_group(ptr->group);
+       else
+               tomoyo_put_name(ptr->filename);
+}
+
+bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
+                              const struct tomoyo_name_union *ptr)
+{
+       if (ptr->is_group)
+               return tomoyo_path_matches_group(name, ptr->group, 1);
+       return tomoyo_path_matches_pattern(name, ptr->filename);
+}
+
+static bool tomoyo_compare_name_union_pattern(const struct tomoyo_path_info
+                                             *name,
+                                             const struct tomoyo_name_union
+                                             *ptr, const bool may_use_pattern)
+{
+       if (ptr->is_group)
+               return tomoyo_path_matches_group(name, ptr->group,
+                                                may_use_pattern);
+       if (may_use_pattern || !ptr->filename->is_patterned)
+               return tomoyo_path_matches_pattern(name, ptr->filename);
+       return false;
+}
+
 /**
  * tomoyo_path2keyword - Get the name of single path operation.
  *
@@ -100,7 +131,7 @@ static struct tomoyo_path_info *tomoyo_get_path(struct path *path)
 {
        int error;
        struct tomoyo_path_info_with_data *buf = kzalloc(sizeof(*buf),
-                                                        GFP_KERNEL);
+                                                        GFP_NOFS);
 
        if (!buf)
                return NULL;
@@ -164,36 +195,36 @@ LIST_HEAD(tomoyo_globally_readable_list);
 static int tomoyo_update_globally_readable_entry(const char *filename,
                                                 const bool is_delete)
 {
-       struct tomoyo_globally_readable_file_entry *entry = NULL;
        struct tomoyo_globally_readable_file_entry *ptr;
-       const struct tomoyo_path_info *saved_filename;
+       struct tomoyo_globally_readable_file_entry e = { };
        int error = is_delete ? -ENOENT : -ENOMEM;
 
        if (!tomoyo_is_correct_path(filename, 1, 0, -1))
                return -EINVAL;
-       saved_filename = tomoyo_get_name(filename);
-       if (!saved_filename)
+       e.filename = tomoyo_get_name(filename);
+       if (!e.filename)
                return -ENOMEM;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
        list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) {
-               if (ptr->filename != saved_filename)
+               if (ptr->filename != e.filename)
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->filename = saved_filename;
-               saved_filename = NULL;
-               list_add_tail_rcu(&entry->list, &tomoyo_globally_readable_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_globally_readable_file_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_globally_readable_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
-       tomoyo_put_name(saved_filename);
-       kfree(entry);
+ out:
+       tomoyo_put_name(e.filename);
        return error;
 }
 
@@ -311,37 +342,34 @@ LIST_HEAD(tomoyo_pattern_list);
 static int tomoyo_update_file_pattern_entry(const char *pattern,
                                            const bool is_delete)
 {
-       struct tomoyo_pattern_entry *entry = NULL;
        struct tomoyo_pattern_entry *ptr;
-       const struct tomoyo_path_info *saved_pattern;
+       struct tomoyo_pattern_entry e = { .pattern = tomoyo_get_name(pattern) };
        int error = is_delete ? -ENOENT : -ENOMEM;
 
-       saved_pattern = tomoyo_get_name(pattern);
-       if (!saved_pattern)
+       if (!e.pattern)
                return error;
-       if (!saved_pattern->is_patterned)
+       if (!e.pattern->is_patterned)
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
                goto out;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
        list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
-               if (saved_pattern != ptr->pattern)
+               if (e.pattern != ptr->pattern)
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->pattern = saved_pattern;
-               saved_pattern = NULL;
-               list_add_tail_rcu(&entry->list, &tomoyo_pattern_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_pattern_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list, &tomoyo_pattern_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
  out:
-       kfree(entry);
-       tomoyo_put_name(saved_pattern);
+       tomoyo_put_name(e.pattern);
        return error;
 }
 
@@ -464,36 +492,36 @@ LIST_HEAD(tomoyo_no_rewrite_list);
 static int tomoyo_update_no_rewrite_entry(const char *pattern,
                                          const bool is_delete)
 {
-       struct tomoyo_no_rewrite_entry *entry = NULL;
        struct tomoyo_no_rewrite_entry *ptr;
-       const struct tomoyo_path_info *saved_pattern;
+       struct tomoyo_no_rewrite_entry e = { };
        int error = is_delete ? -ENOENT : -ENOMEM;
 
        if (!tomoyo_is_correct_path(pattern, 0, 0, 0))
                return -EINVAL;
-       saved_pattern = tomoyo_get_name(pattern);
-       if (!saved_pattern)
+       e.pattern = tomoyo_get_name(pattern);
+       if (!e.pattern)
                return error;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
        list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
-               if (ptr->pattern != saved_pattern)
+               if (ptr->pattern != e.pattern)
                        continue;
                ptr->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->pattern = saved_pattern;
-               saved_pattern = NULL;
-               list_add_tail_rcu(&entry->list, &tomoyo_no_rewrite_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_no_rewrite_entry *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_no_rewrite_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
-       tomoyo_put_name(saved_pattern);
-       kfree(entry);
+ out:
+       tomoyo_put_name(e.pattern);
        return error;
 }
 
@@ -640,13 +668,9 @@ static int tomoyo_path_acl2(const struct tomoyo_domain_info *domain,
                        if (!(acl->perm_high & (perm >> 16)))
                                continue;
                }
-               if (may_use_pattern || !acl->filename->is_patterned) {
-                       if (!tomoyo_path_matches_pattern(filename,
-                                                        acl->filename))
-                               continue;
-               } else {
+               if (!tomoyo_compare_name_union_pattern(filename, &acl->name,
+                                                       may_use_pattern))
                        continue;
-               }
                error = 0;
                break;
        }
@@ -805,70 +829,64 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename,
                                  struct tomoyo_domain_info *const domain,
                                  const bool is_delete)
 {
-       static const u32 rw_mask =
+       static const u32 tomoyo_rw_mask =
                (1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE);
-       const struct tomoyo_path_info *saved_filename;
+       const u32 perm = 1 << type;
        struct tomoyo_acl_info *ptr;
-       struct tomoyo_path_acl *entry = NULL;
+       struct tomoyo_path_acl e = {
+               .head.type = TOMOYO_TYPE_PATH_ACL,
+               .perm_high = perm >> 16,
+               .perm = perm
+       };
        int error = is_delete ? -ENOENT : -ENOMEM;
-       const u32 perm = 1 << type;
 
+       if (type == TOMOYO_TYPE_READ_WRITE)
+               e.perm |= tomoyo_rw_mask;
        if (!domain)
                return -EINVAL;
-       if (!tomoyo_is_correct_path(filename, 0, 0, 0))
+       if (!tomoyo_parse_name_union(filename, &e.name))
                return -EINVAL;
-       saved_filename = tomoyo_get_name(filename);
-       if (!saved_filename)
-               return -ENOMEM;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
        list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
                struct tomoyo_path_acl *acl =
                        container_of(ptr, struct tomoyo_path_acl, head);
-               if (ptr->type != TOMOYO_TYPE_PATH_ACL)
-                       continue;
-               if (acl->filename != saved_filename)
+               if (!tomoyo_is_same_path_acl(acl, &e))
                        continue;
                if (is_delete) {
                        if (perm <= 0xFFFF)
                                acl->perm &= ~perm;
                        else
                                acl->perm_high &= ~(perm >> 16);
-                       if ((acl->perm & rw_mask) != rw_mask)
+                       if ((acl->perm & tomoyo_rw_mask) != tomoyo_rw_mask)
                                acl->perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
                        else if (!(acl->perm & (1 << TOMOYO_TYPE_READ_WRITE)))
-                               acl->perm &= ~rw_mask;
+                               acl->perm &= ~tomoyo_rw_mask;
                } else {
                        if (perm <= 0xFFFF)
                                acl->perm |= perm;
                        else
                                acl->perm_high |= (perm >> 16);
-                       if ((acl->perm & rw_mask) == rw_mask)
+                       if ((acl->perm & tomoyo_rw_mask) == tomoyo_rw_mask)
                                acl->perm |= 1 << TOMOYO_TYPE_READ_WRITE;
                        else if (acl->perm & (1 << TOMOYO_TYPE_READ_WRITE))
-                               acl->perm |= rw_mask;
+                               acl->perm |= tomoyo_rw_mask;
                }
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->head.type = TOMOYO_TYPE_PATH_ACL;
-               if (perm <= 0xFFFF)
-                       entry->perm = perm;
-               else
-                       entry->perm_high = (perm >> 16);
-               if (perm == (1 << TOMOYO_TYPE_READ_WRITE))
-                       entry->perm |= rw_mask;
-               entry->filename = saved_filename;
-               saved_filename = NULL;
-               list_add_tail_rcu(&entry->head.list, &domain->acl_info_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_path_acl *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->head.list,
+                                         &domain->acl_info_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
-       kfree(entry);
-       tomoyo_put_name(saved_filename);
+ out:
+       tomoyo_put_name_union(&e.name);
        return error;
 }
 
@@ -890,32 +908,25 @@ static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
                                   struct tomoyo_domain_info *const domain,
                                   const bool is_delete)
 {
-       const struct tomoyo_path_info *saved_filename1;
-       const struct tomoyo_path_info *saved_filename2;
+       const u8 perm = 1 << type;
+       struct tomoyo_path2_acl e = {
+               .head.type = TOMOYO_TYPE_PATH2_ACL,
+               .perm = perm
+       };
        struct tomoyo_acl_info *ptr;
-       struct tomoyo_path2_acl *entry = NULL;
        int error = is_delete ? -ENOENT : -ENOMEM;
-       const u8 perm = 1 << type;
 
        if (!domain)
                return -EINVAL;
-       if (!tomoyo_is_correct_path(filename1, 0, 0, 0) ||
-           !tomoyo_is_correct_path(filename2, 0, 0, 0))
-               return -EINVAL;
-       saved_filename1 = tomoyo_get_name(filename1);
-       saved_filename2 = tomoyo_get_name(filename2);
-       if (!saved_filename1 || !saved_filename2)
+       if (!tomoyo_parse_name_union(filename1, &e.name1) ||
+           !tomoyo_parse_name_union(filename2, &e.name2))
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
                goto out;
-       if (!is_delete)
-               entry = kmalloc(sizeof(*entry), GFP_KERNEL);
-       mutex_lock(&tomoyo_policy_lock);
        list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
                struct tomoyo_path2_acl *acl =
                        container_of(ptr, struct tomoyo_path2_acl, head);
-               if (ptr->type != TOMOYO_TYPE_PATH2_ACL)
-                       continue;
-               if (acl->filename1 != saved_filename1 ||
-                   acl->filename2 != saved_filename2)
+               if (!tomoyo_is_same_path2_acl(acl, &e))
                        continue;
                if (is_delete)
                        acl->perm &= ~perm;
@@ -924,22 +935,19 @@ static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
                error = 0;
                break;
        }
-       if (!is_delete && error && tomoyo_memory_ok(entry)) {
-               entry->head.type = TOMOYO_TYPE_PATH2_ACL;
-               entry->perm = perm;
-               entry->filename1 = saved_filename1;
-               saved_filename1 = NULL;
-               entry->filename2 = saved_filename2;
-               saved_filename2 = NULL;
-               list_add_tail_rcu(&entry->head.list, &domain->acl_info_list);
-               entry = NULL;
-               error = 0;
+       if (!is_delete && error) {
+               struct tomoyo_path2_acl *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->head.list,
+                                         &domain->acl_info_list);
+                       error = 0;
+               }
        }
        mutex_unlock(&tomoyo_policy_lock);
  out:
-       tomoyo_put_name(saved_filename1);
-       tomoyo_put_name(saved_filename2);
-       kfree(entry);
+       tomoyo_put_name_union(&e.name1);
+       tomoyo_put_name_union(&e.name2);
        return error;
 }
 
@@ -992,9 +1000,9 @@ static int tomoyo_path2_acl(const struct tomoyo_domain_info *domain,
                acl = container_of(ptr, struct tomoyo_path2_acl, head);
                if (!(acl->perm & perm))
                        continue;
-               if (!tomoyo_path_matches_pattern(filename1, acl->filename1))
+               if (!tomoyo_compare_name_union(filename1, &acl->name1))
                        continue;
-               if (!tomoyo_path_matches_pattern(filename2, acl->filename2))
+               if (!tomoyo_compare_name_union(filename2, &acl->name2))
                        continue;
                error = 0;
                break;
index d9ad35b..b9cc71b 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/slab.h>
 
 enum tomoyo_gc_id {
+       TOMOYO_ID_PATH_GROUP,
+       TOMOYO_ID_PATH_GROUP_MEMBER,
        TOMOYO_ID_DOMAIN_INITIALIZER,
        TOMOYO_ID_DOMAIN_KEEPER,
        TOMOYO_ID_ALIAS,
@@ -91,15 +93,15 @@ static void tomoyo_del_acl(struct tomoyo_acl_info *acl)
                {
                        struct tomoyo_path_acl *entry
                                = container_of(acl, typeof(*entry), head);
-                       tomoyo_put_name(entry->filename);
+                       tomoyo_put_name_union(&entry->name);
                }
                break;
        case TOMOYO_TYPE_PATH2_ACL:
                {
                        struct tomoyo_path2_acl *entry
                                = container_of(acl, typeof(*entry), head);
-                       tomoyo_put_name(entry->filename1);
-                       tomoyo_put_name(entry->filename2);
+                       tomoyo_put_name_union(&entry->name1);
+                       tomoyo_put_name_union(&entry->name2);
                }
                break;
        default:
@@ -149,9 +151,21 @@ static void tomoyo_del_name(const struct tomoyo_name_entry *ptr)
 {
 }
 
+static void tomoyo_del_path_group_member(struct tomoyo_path_group_member
+                                        *member)
+{
+       tomoyo_put_name(member->member_name);
+}
+
+static void tomoyo_del_path_group(struct tomoyo_path_group *group)
+{
+       tomoyo_put_name(group->group_name);
+}
+
 static void tomoyo_collect_entry(void)
 {
-       mutex_lock(&tomoyo_policy_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return;
        {
                struct tomoyo_globally_readable_file_entry *ptr;
                list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
@@ -275,8 +289,6 @@ static void tomoyo_collect_entry(void)
                                break;
                }
        }
-       mutex_unlock(&tomoyo_policy_lock);
-       mutex_lock(&tomoyo_name_list_lock);
        {
                int i;
                for (i = 0; i < TOMOYO_MAX_HASH; i++) {
@@ -294,7 +306,30 @@ static void tomoyo_collect_entry(void)
                        }
                }
        }
-       mutex_unlock(&tomoyo_name_list_lock);
+       {
+               struct tomoyo_path_group *group;
+               list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
+                       struct tomoyo_path_group_member *member;
+                       list_for_each_entry_rcu(member, &group->member_list,
+                                               list) {
+                               if (!member->is_deleted)
+                                       continue;
+                               if (tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP_MEMBER,
+                                                    member))
+                                       list_del_rcu(&member->list);
+                               else
+                                       break;
+                       }
+                       if (!list_empty(&group->member_list) ||
+                           atomic_read(&group->users))
+                               continue;
+                       if (tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP, group))
+                               list_del_rcu(&group->list);
+                       else
+                               break;
+               }
+       }
+       mutex_unlock(&tomoyo_policy_lock);
 }
 
 static void tomoyo_kfree_entry(void)
@@ -335,6 +370,12 @@ static void tomoyo_kfree_entry(void)
                        if (!tomoyo_del_domain(p->element))
                                continue;
                        break;
+               case TOMOYO_ID_PATH_GROUP_MEMBER:
+                       tomoyo_del_path_group_member(p->element);
+                       break;
+               case TOMOYO_ID_PATH_GROUP:
+                       tomoyo_del_path_group(p->element);
+                       break;
                default:
                        printk(KERN_WARNING "Unknown type\n");
                        break;
diff --git a/security/tomoyo/path_group.c b/security/tomoyo/path_group.c
new file mode 100644 (file)
index 0000000..c988041
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+ * security/tomoyo/path_group.c
+ *
+ * Copyright (C) 2005-2009  NTT DATA CORPORATION
+ */
+
+#include <linux/slab.h>
+#include "common.h"
+/* The list for "struct ccs_path_group". */
+LIST_HEAD(tomoyo_path_group_list);
+
+/**
+ * tomoyo_get_path_group - Allocate memory for "struct tomoyo_path_group".
+ *
+ * @group_name: The name of pathname group.
+ *
+ * Returns pointer to "struct tomoyo_path_group" on success, NULL otherwise.
+ */
+struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name)
+{
+       struct tomoyo_path_group *entry = NULL;
+       struct tomoyo_path_group *group = NULL;
+       const struct tomoyo_path_info *saved_group_name;
+       int error = -ENOMEM;
+       if (!tomoyo_is_correct_path(group_name, 0, 0, 0) ||
+           !group_name[0])
+               return NULL;
+       saved_group_name = tomoyo_get_name(group_name);
+       if (!saved_group_name)
+               return NULL;
+       entry = kzalloc(sizeof(*entry), GFP_NOFS);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
+       list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
+               if (saved_group_name != group->group_name)
+                       continue;
+               atomic_inc(&group->users);
+               error = 0;
+               break;
+       }
+       if (error && tomoyo_memory_ok(entry)) {
+               INIT_LIST_HEAD(&entry->member_list);
+               entry->group_name = saved_group_name;
+               saved_group_name = NULL;
+               atomic_set(&entry->users, 1);
+               list_add_tail_rcu(&entry->list, &tomoyo_path_group_list);
+               group = entry;
+               entry = NULL;
+               error = 0;
+       }
+       mutex_unlock(&tomoyo_policy_lock);
+ out:
+       tomoyo_put_name(saved_group_name);
+       kfree(entry);
+       return !error ? group : NULL;
+}
+
+/**
+ * tomoyo_write_path_group_policy - Write "struct tomoyo_path_group" list.
+ *
+ * @data:      String to parse.
+ * @is_delete: True if it is a delete request.
+ *
+ * Returns 0 on success, nagative value otherwise.
+ */
+int tomoyo_write_path_group_policy(char *data, const bool is_delete)
+{
+       struct tomoyo_path_group *group;
+       struct tomoyo_path_group_member *member;
+       struct tomoyo_path_group_member e = { };
+       int error = is_delete ? -ENOENT : -ENOMEM;
+       char *w[2];
+       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
+               return -EINVAL;
+       group = tomoyo_get_path_group(w[0]);
+       if (!group)
+               return -ENOMEM;
+       e.member_name = tomoyo_get_name(w[1]);
+       if (!e.member_name)
+               goto out;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
+       list_for_each_entry_rcu(member, &group->member_list, list) {
+               if (member->member_name != e.member_name)
+                       continue;
+               member->is_deleted = is_delete;
+               error = 0;
+               break;
+       }
+       if (!is_delete && error) {
+               struct tomoyo_path_group_member *entry =
+                       tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       list_add_tail_rcu(&entry->list, &group->member_list);
+                       error = 0;
+               }
+       }
+       mutex_unlock(&tomoyo_policy_lock);
+ out:
+       tomoyo_put_name(e.member_name);
+       tomoyo_put_path_group(group);
+       return error;
+}
+
+/**
+ * tomoyo_read_path_group_policy - Read "struct tomoyo_path_group" list.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns true on success, false otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
+{
+       struct list_head *gpos;
+       struct list_head *mpos;
+       list_for_each_cookie(gpos, head->read_var1, &tomoyo_path_group_list) {
+               struct tomoyo_path_group *group;
+               group = list_entry(gpos, struct tomoyo_path_group, list);
+               list_for_each_cookie(mpos, head->read_var2,
+                                    &group->member_list) {
+                       struct tomoyo_path_group_member *member;
+                       member = list_entry(mpos,
+                                           struct tomoyo_path_group_member,
+                                           list);
+                       if (member->is_deleted)
+                               continue;
+                       if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_PATH_GROUP
+                                             "%s %s\n",
+                                             group->group_name->name,
+                                             member->member_name->name))
+                               return false;
+               }
+       }
+       return true;
+}
+
+/**
+ * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group.
+ *
+ * @pathname:        The name of pathname.
+ * @group:           Pointer to "struct tomoyo_path_group".
+ * @may_use_pattern: True if wild card is permitted.
+ *
+ * Returns true if @pathname matches pathnames in @group, false otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
+                              const struct tomoyo_path_group *group,
+                              const bool may_use_pattern)
+{
+       struct tomoyo_path_group_member *member;
+       bool matched = false;
+       list_for_each_entry_rcu(member, &group->member_list, list) {
+               if (member->is_deleted)
+                       continue;
+               if (!member->member_name->is_patterned) {
+                       if (tomoyo_pathcmp(pathname, member->member_name))
+                               continue;
+               } else if (may_use_pattern) {
+                       if (!tomoyo_path_matches_pattern(pathname,
+                                                        member->member_name))
+                               continue;
+               } else
+                       continue;
+               matched = true;
+               break;
+       }
+       return matched;
+}
index c225c65..d1b96f0 100644 (file)
@@ -139,7 +139,7 @@ int tomoyo_realpath_from_path2(struct path *path, char *newname,
  */
 char *tomoyo_realpath_from_path(struct path *path)
 {
-       char *buf = kzalloc(sizeof(struct tomoyo_page_buffer), GFP_KERNEL);
+       char *buf = kzalloc(sizeof(struct tomoyo_page_buffer), GFP_NOFS);
 
        BUILD_BUG_ON(sizeof(struct tomoyo_page_buffer)
                     <= TOMOYO_MAX_PATHNAME_LEN - 1);
@@ -222,6 +222,25 @@ bool tomoyo_memory_ok(void *ptr)
        return false;
 }
 
+/**
+ * tomoyo_commit_ok - Check memory quota.
+ *
+ * @data:   Data to copy from.
+ * @size:   Size in byte.
+ *
+ * Returns pointer to allocated memory on success, NULL otherwise.
+ */
+void *tomoyo_commit_ok(void *data, const unsigned int size)
+{
+       void *ptr = kzalloc(size, GFP_NOFS);
+       if (tomoyo_memory_ok(ptr)) {
+               memmove(ptr, data, size);
+               memset(data, 0, size);
+               return ptr;
+       }
+       return NULL;
+}
+
 /**
  * tomoyo_memory_free - Free memory for elements.
  *
@@ -240,8 +259,6 @@ void tomoyo_memory_free(void *ptr)
  * "const struct tomoyo_path_info *".
  */
 struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
-/* Lock for protecting tomoyo_name_list . */
-DEFINE_MUTEX(tomoyo_name_list_lock);
 
 /**
  * tomoyo_get_name - Allocate permanent memory for string data.
@@ -263,14 +280,15 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name)
        len = strlen(name) + 1;
        hash = full_name_hash((const unsigned char *) name, len - 1);
        head = &tomoyo_name_list[hash_long(hash, TOMOYO_HASH_BITS)];
-       mutex_lock(&tomoyo_name_list_lock);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return NULL;
        list_for_each_entry(ptr, head, list) {
                if (hash != ptr->entry.hash || strcmp(name, ptr->entry.name))
                        continue;
                atomic_inc(&ptr->users);
                goto out;
        }
-       ptr = kzalloc(sizeof(*ptr) + len, GFP_KERNEL);
+       ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS);
        allocated_len = ptr ? ksize(ptr) : 0;
        if (!ptr || (tomoyo_quota_for_policy &&
                     atomic_read(&tomoyo_policy_memory_size) + allocated_len
@@ -290,7 +308,7 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name)
        tomoyo_fill_path_info(&ptr->entry);
        list_add_tail(&ptr->list, head);
  out:
-       mutex_unlock(&tomoyo_name_list_lock);
+       mutex_unlock(&tomoyo_policy_lock);
        return ptr ? &ptr->entry : NULL;
 }
 
index 6c228a9..94de43a 100644 (file)
@@ -12,7 +12,7 @@ config SND_ATMEL_AC97C
        tristate "Atmel AC97 Controller (AC97C) driver"
        select SND_PCM
        select SND_AC97_CODEC
-       depends on DW_DMAC && AVR32
+       depends on (DW_DMAC && AVR32) || ARCH_AT91
        help
          ALSA sound driver for the Atmel AC97 controller.
 
index 0c0f877..428121a 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/dmaengine.h>
 #include <linux/dma-mapping.h>
+#include <linux/atmel_pdc.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
 
 #include <linux/dw_dmac.h>
 
+#include <mach/cpu.h>
+#include <mach/hardware.h>
+#include <mach/gpio.h>
+
 #include "ac97c.h"
 
 enum {
@@ -63,6 +68,7 @@ struct atmel_ac97c {
        u64                             cur_format;
        unsigned int                    cur_rate;
        unsigned long                   flags;
+       int                             playback_period, capture_period;
        /* Serialize access to opened variable */
        spinlock_t                      lock;
        void __iomem                    *regs;
@@ -242,10 +248,12 @@ static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
        if (retval < 0)
                return retval;
        /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
-       if (retval == 1)
-               if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
-                       dw_dma_cyclic_free(chip->dma.tx_chan);
-
+       if (cpu_is_at32ap7000()) {
+               /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
+               if (retval == 1)
+                       if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
+                               dw_dma_cyclic_free(chip->dma.tx_chan);
+       }
        /* Set restrictions to params. */
        mutex_lock(&opened_mutex);
        chip->cur_rate = params_rate(hw_params);
@@ -266,9 +274,14 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
        if (retval < 0)
                return retval;
        /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
-       if (retval == 1)
-               if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
-                       dw_dma_cyclic_free(chip->dma.rx_chan);
+       if (cpu_is_at32ap7000()) {
+               if (retval < 0)
+                       return retval;
+               /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
+               if (retval == 1)
+                       if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
+                               dw_dma_cyclic_free(chip->dma.rx_chan);
+       }
 
        /* Set restrictions to params. */
        mutex_lock(&opened_mutex);
@@ -282,16 +295,20 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
 static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
-       if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
-               dw_dma_cyclic_free(chip->dma.tx_chan);
+       if (cpu_is_at32ap7000()) {
+               if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
+                       dw_dma_cyclic_free(chip->dma.tx_chan);
+       }
        return snd_pcm_lib_free_pages(substream);
 }
 
 static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
-       if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
-               dw_dma_cyclic_free(chip->dma.rx_chan);
+       if (cpu_is_at32ap7000()) {
+               if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
+                       dw_dma_cyclic_free(chip->dma.rx_chan);
+       }
        return snd_pcm_lib_free_pages(substream);
 }
 
@@ -299,9 +316,11 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
+       int block_size = frames_to_bytes(runtime, runtime->period_size);
        unsigned long word = ac97c_readl(chip, OCA);
        int retval;
 
+       chip->playback_period = 0;
        word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
 
        /* assign channels to AC97C channel A */
@@ -320,11 +339,16 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
        ac97c_writel(chip, OCA, word);
 
        /* configure sample format and size */
-       word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
+       word = ac97c_readl(chip, CAMR);
+       if (chip->opened <= 1)
+               word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
+       else
+               word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
 
        switch (runtime->format) {
        case SNDRV_PCM_FORMAT_S16_LE:
-               word |= AC97C_CMR_CEM_LITTLE;
+               if (cpu_is_at32ap7000())
+                       word |= AC97C_CMR_CEM_LITTLE;
                break;
        case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
                word &= ~(AC97C_CMR_CEM_LITTLE);
@@ -363,9 +387,18 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
                dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
                                runtime->rate);
 
-       if (!test_bit(DMA_TX_READY, &chip->flags))
-               retval = atmel_ac97c_prepare_dma(chip, substream,
-                               DMA_TO_DEVICE);
+       if (cpu_is_at32ap7000()) {
+               if (!test_bit(DMA_TX_READY, &chip->flags))
+                       retval = atmel_ac97c_prepare_dma(chip, substream,
+                                       DMA_TO_DEVICE);
+       } else {
+               /* Initialize and start the PDC */
+               writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
+               writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
+               writel(runtime->dma_addr + block_size,
+                               chip->regs + ATMEL_PDC_TNPR);
+               writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
+       }
 
        return retval;
 }
@@ -374,9 +407,11 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
+       int block_size = frames_to_bytes(runtime, runtime->period_size);
        unsigned long word = ac97c_readl(chip, ICA);
        int retval;
 
+       chip->capture_period = 0;
        word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
 
        /* assign channels to AC97C channel A */
@@ -395,11 +430,16 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
        ac97c_writel(chip, ICA, word);
 
        /* configure sample format and size */
-       word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
+       word = ac97c_readl(chip, CAMR);
+       if (chip->opened <= 1)
+               word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
+       else
+               word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
 
        switch (runtime->format) {
        case SNDRV_PCM_FORMAT_S16_LE:
-               word |= AC97C_CMR_CEM_LITTLE;
+               if (cpu_is_at32ap7000())
+                       word |= AC97C_CMR_CEM_LITTLE;
                break;
        case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
                word &= ~(AC97C_CMR_CEM_LITTLE);
@@ -438,9 +478,18 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
                dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
                                runtime->rate);
 
-       if (!test_bit(DMA_RX_READY, &chip->flags))
-               retval = atmel_ac97c_prepare_dma(chip, substream,
-                               DMA_FROM_DEVICE);
+       if (cpu_is_at32ap7000()) {
+               if (!test_bit(DMA_RX_READY, &chip->flags))
+                       retval = atmel_ac97c_prepare_dma(chip, substream,
+                                       DMA_FROM_DEVICE);
+       } else {
+               /* Initialize and start the PDC */
+               writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
+               writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
+               writel(runtime->dma_addr + block_size,
+                               chip->regs + ATMEL_PDC_RNPR);
+               writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
+       }
 
        return retval;
 }
@@ -449,7 +498,7 @@ static int
 atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
-       unsigned long camr;
+       unsigned long camr, ptcr = 0;
        int retval = 0;
 
        camr = ac97c_readl(chip, CAMR);
@@ -458,15 +507,22 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
        case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
        case SNDRV_PCM_TRIGGER_START:
-               retval = dw_dma_cyclic_start(chip->dma.tx_chan);
-               if (retval)
-                       goto out;
-               camr |= AC97C_CMR_CENA;
+               if (cpu_is_at32ap7000()) {
+                       retval = dw_dma_cyclic_start(chip->dma.tx_chan);
+                       if (retval)
+                               goto out;
+               } else {
+                       ptcr = ATMEL_PDC_TXTEN;
+               }
+               camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
        case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
        case SNDRV_PCM_TRIGGER_STOP:
-               dw_dma_cyclic_stop(chip->dma.tx_chan);
+               if (cpu_is_at32ap7000())
+                       dw_dma_cyclic_stop(chip->dma.tx_chan);
+               else
+                       ptcr |= ATMEL_PDC_TXTDIS;
                if (chip->opened <= 1)
                        camr &= ~AC97C_CMR_CENA;
                break;
@@ -476,6 +532,8 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
        }
 
        ac97c_writel(chip, CAMR, camr);
+       if (!cpu_is_at32ap7000())
+               writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
 out:
        return retval;
 }
@@ -484,24 +542,32 @@ static int
 atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
 {
        struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
-       unsigned long camr;
+       unsigned long camr, ptcr = 0;
        int retval = 0;
 
        camr = ac97c_readl(chip, CAMR);
+       ptcr = readl(chip->regs + ATMEL_PDC_PTSR);
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
        case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
        case SNDRV_PCM_TRIGGER_START:
-               retval = dw_dma_cyclic_start(chip->dma.rx_chan);
-               if (retval)
-                       goto out;
-               camr |= AC97C_CMR_CENA;
+               if (cpu_is_at32ap7000()) {
+                       retval = dw_dma_cyclic_start(chip->dma.rx_chan);
+                       if (retval)
+                               goto out;
+               } else {
+                       ptcr = ATMEL_PDC_RXTEN;
+               }
+               camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
        case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
        case SNDRV_PCM_TRIGGER_STOP:
-               dw_dma_cyclic_stop(chip->dma.rx_chan);
+               if (cpu_is_at32ap7000())
+                       dw_dma_cyclic_stop(chip->dma.rx_chan);
+               else
+                       ptcr |= (ATMEL_PDC_RXTDIS);
                if (chip->opened <= 1)
                        camr &= ~AC97C_CMR_CENA;
                break;
@@ -511,6 +577,8 @@ atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
        }
 
        ac97c_writel(chip, CAMR, camr);
+       if (!cpu_is_at32ap7000())
+               writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
 out:
        return retval;
 }
@@ -523,7 +591,10 @@ atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
        snd_pcm_uframes_t       frames;
        unsigned long           bytes;
 
-       bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
+       if (cpu_is_at32ap7000())
+               bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
+       else
+               bytes = readl(chip->regs + ATMEL_PDC_TPR);
        bytes -= runtime->dma_addr;
 
        frames = bytes_to_frames(runtime, bytes);
@@ -540,7 +611,10 @@ atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
        snd_pcm_uframes_t       frames;
        unsigned long           bytes;
 
-       bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
+       if (cpu_is_at32ap7000())
+               bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
+       else
+               bytes = readl(chip->regs + ATMEL_PDC_RPR);
        bytes -= runtime->dma_addr;
 
        frames = bytes_to_frames(runtime, bytes);
@@ -578,8 +652,11 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
        u32                     sr     = ac97c_readl(chip, SR);
        u32                     casr   = ac97c_readl(chip, CASR);
        u32                     cosr   = ac97c_readl(chip, COSR);
+       u32                     camr   = ac97c_readl(chip, CAMR);
 
        if (sr & AC97C_SR_CAEVT) {
+               struct snd_pcm_runtime *runtime;
+               int offset, next_period, block_size;
                dev_info(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
                                casr & AC97C_CSR_OVRUN   ? " OVRUN"   : "",
                                casr & AC97C_CSR_RXRDY   ? " RXRDY"   : "",
@@ -587,6 +664,50 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
                                casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
                                casr & AC97C_CSR_TXRDY   ? " TXRDY"   : "",
                                !casr                    ? " NONE"    : "");
+               if (!cpu_is_at32ap7000()) {
+                       if ((casr & camr) & AC97C_CSR_ENDTX) {
+                               runtime = chip->playback_substream->runtime;
+                               block_size = frames_to_bytes(runtime,
+                                               runtime->period_size);
+                               chip->playback_period++;
+
+                               if (chip->playback_period == runtime->periods)
+                                       chip->playback_period = 0;
+                               next_period = chip->playback_period + 1;
+                               if (next_period == runtime->periods)
+                                       next_period = 0;
+
+                               offset = block_size * next_period;
+
+                               writel(runtime->dma_addr + offset,
+                                               chip->regs + ATMEL_PDC_TNPR);
+                               writel(block_size / 2,
+                                               chip->regs + ATMEL_PDC_TNCR);
+
+                               snd_pcm_period_elapsed(
+                                               chip->playback_substream);
+                       }
+                       if ((casr & camr) & AC97C_CSR_ENDRX) {
+                               runtime = chip->capture_substream->runtime;
+                               block_size = frames_to_bytes(runtime,
+                                               runtime->period_size);
+                               chip->capture_period++;
+
+                               if (chip->capture_period == runtime->periods)
+                                       chip->capture_period = 0;
+                               next_period = chip->capture_period + 1;
+                               if (next_period == runtime->periods)
+                                       next_period = 0;
+
+                               offset = block_size * next_period;
+
+                               writel(runtime->dma_addr + offset,
+                                               chip->regs + ATMEL_PDC_RNPR);
+                               writel(block_size / 2,
+                                               chip->regs + ATMEL_PDC_RNCR);
+                               snd_pcm_period_elapsed(chip->capture_substream);
+                       }
+               }
                retval = IRQ_HANDLED;
        }
 
@@ -608,15 +729,50 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
        return retval;
 }
 
+static struct ac97_pcm at91_ac97_pcm_defs[] __devinitdata = {
+       /* Playback */
+       {
+               .exclusive = 1,
+               .r = { {
+                       .slots = ((1 << AC97_SLOT_PCM_LEFT)
+                                 | (1 << AC97_SLOT_PCM_RIGHT)),
+               } },
+       },
+       /* PCM in */
+       {
+               .stream = 1,
+               .exclusive = 1,
+               .r = { {
+                       .slots = ((1 << AC97_SLOT_PCM_LEFT)
+                                       | (1 << AC97_SLOT_PCM_RIGHT)),
+               } }
+       },
+       /* Mic in */
+       {
+               .stream = 1,
+               .exclusive = 1,
+               .r = { {
+                       .slots = (1<<AC97_SLOT_MIC),
+               } }
+       },
+};
+
 static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
 {
        struct snd_pcm          *pcm;
        struct snd_pcm_hardware hw = atmel_ac97c_hw;
-       int                     capture, playback, retval;
+       int                     capture, playback, retval, err;
 
        capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
        playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
 
+       if (!cpu_is_at32ap7000()) {
+               err = snd_ac97_pcm_assign(chip->ac97_bus,
+                               ARRAY_SIZE(at91_ac97_pcm_defs),
+                               at91_ac97_pcm_defs);
+               if (err)
+                       return err;
+       }
        retval = snd_pcm_new(chip->card, chip->card->shortname,
                        chip->pdev->id, playback, capture, &pcm);
        if (retval)
@@ -775,7 +931,12 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
                return -ENXIO;
        }
 
-       pclk = clk_get(&pdev->dev, "pclk");
+       if (cpu_is_at32ap7000()) {
+               pclk = clk_get(&pdev->dev, "pclk");
+       } else {
+               pclk = clk_get(&pdev->dev, "ac97_clk");
+       }
+
        if (IS_ERR(pclk)) {
                dev_dbg(&pdev->dev, "no peripheral clock\n");
                return PTR_ERR(pclk);
@@ -844,43 +1005,52 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
                goto err_ac97_bus;
        }
 
-       if (pdata->rx_dws.dma_dev) {
-               struct dw_dma_slave *dws = &pdata->rx_dws;
-               dma_cap_mask_t mask;
+       if (cpu_is_at32ap7000()) {
+               if (pdata->rx_dws.dma_dev) {
+                       struct dw_dma_slave *dws = &pdata->rx_dws;
+                       dma_cap_mask_t mask;
 
-               dws->rx_reg = regs->start + AC97C_CARHR + 2;
+                       dws->rx_reg = regs->start + AC97C_CARHR + 2;
 
-               dma_cap_zero(mask);
-               dma_cap_set(DMA_SLAVE, mask);
+                       dma_cap_zero(mask);
+                       dma_cap_set(DMA_SLAVE, mask);
 
-               chip->dma.rx_chan = dma_request_channel(mask, filter, dws);
+                       chip->dma.rx_chan = dma_request_channel(mask, filter,
+                                                               dws);
 
-               dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
+                       dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
                                dev_name(&chip->dma.rx_chan->dev->device));
-               set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
-       }
+                       set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+               }
 
-       if (pdata->tx_dws.dma_dev) {
-               struct dw_dma_slave *dws = &pdata->tx_dws;
-               dma_cap_mask_t mask;
+               if (pdata->tx_dws.dma_dev) {
+                       struct dw_dma_slave *dws = &pdata->tx_dws;
+                       dma_cap_mask_t mask;
 
-               dws->tx_reg = regs->start + AC97C_CATHR + 2;
+                       dws->tx_reg = regs->start + AC97C_CATHR + 2;
 
-               dma_cap_zero(mask);
-               dma_cap_set(DMA_SLAVE, mask);
+                       dma_cap_zero(mask);
+                       dma_cap_set(DMA_SLAVE, mask);
 
-               chip->dma.tx_chan = dma_request_channel(mask, filter, dws);
+                       chip->dma.tx_chan = dma_request_channel(mask, filter,
+                                                               dws);
 
-               dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
+                       dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
                                dev_name(&chip->dma.tx_chan->dev->device));
-               set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
-       }
+                       set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+               }
 
-       if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
-                       !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
-               dev_dbg(&pdev->dev, "DMA not available\n");
-               retval = -ENODEV;
-               goto err_dma;
+               if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
+                               !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
+                       dev_dbg(&pdev->dev, "DMA not available\n");
+                       retval = -ENODEV;
+                       goto err_dma;
+               }
+       } else {
+               /* Just pretend that we have DMA channel(for at91 i is actually
+                * the PDC) */
+               set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+               set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
        }
 
        retval = atmel_ac97c_pcm_new(chip);
@@ -897,20 +1067,22 @@ static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, card);
 
-       dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p\n",
-                       chip->regs);
+       dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n",
+                       chip->regs, irq);
 
        return 0;
 
 err_dma:
-       if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
-               dma_release_channel(chip->dma.rx_chan);
-       if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
-               dma_release_channel(chip->dma.tx_chan);
-       clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
-       clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
-       chip->dma.rx_chan = NULL;
-       chip->dma.tx_chan = NULL;
+       if (cpu_is_at32ap7000()) {
+               if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
+                       dma_release_channel(chip->dma.rx_chan);
+               if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
+                       dma_release_channel(chip->dma.tx_chan);
+               clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+               clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+               chip->dma.rx_chan = NULL;
+               chip->dma.tx_chan = NULL;
+       }
 err_ac97_bus:
        snd_card_set_dev(card, NULL);
 
@@ -934,10 +1106,12 @@ static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg)
        struct snd_card *card = platform_get_drvdata(pdev);
        struct atmel_ac97c *chip = card->private_data;
 
-       if (test_bit(DMA_RX_READY, &chip->flags))
-               dw_dma_cyclic_stop(chip->dma.rx_chan);
-       if (test_bit(DMA_TX_READY, &chip->flags))
-               dw_dma_cyclic_stop(chip->dma.tx_chan);
+       if (cpu_is_at32ap7000()) {
+               if (test_bit(DMA_RX_READY, &chip->flags))
+                       dw_dma_cyclic_stop(chip->dma.rx_chan);
+               if (test_bit(DMA_TX_READY, &chip->flags))
+                       dw_dma_cyclic_stop(chip->dma.tx_chan);
+       }
        clk_disable(chip->pclk);
 
        return 0;
@@ -949,11 +1123,12 @@ static int atmel_ac97c_resume(struct platform_device *pdev)
        struct atmel_ac97c *chip = card->private_data;
 
        clk_enable(chip->pclk);
-       if (test_bit(DMA_RX_READY, &chip->flags))
-               dw_dma_cyclic_start(chip->dma.rx_chan);
-       if (test_bit(DMA_TX_READY, &chip->flags))
-               dw_dma_cyclic_start(chip->dma.tx_chan);
-
+       if (cpu_is_at32ap7000()) {
+               if (test_bit(DMA_RX_READY, &chip->flags))
+                       dw_dma_cyclic_start(chip->dma.rx_chan);
+               if (test_bit(DMA_TX_READY, &chip->flags))
+                       dw_dma_cyclic_start(chip->dma.tx_chan);
+       }
        return 0;
 }
 #else
@@ -978,14 +1153,16 @@ static int __devexit atmel_ac97c_remove(struct platform_device *pdev)
        iounmap(chip->regs);
        free_irq(chip->irq, chip);
 
-       if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
-               dma_release_channel(chip->dma.rx_chan);
-       if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
-               dma_release_channel(chip->dma.tx_chan);
-       clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
-       clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
-       chip->dma.rx_chan = NULL;
-       chip->dma.tx_chan = NULL;
+       if (cpu_is_at32ap7000()) {
+               if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
+                       dma_release_channel(chip->dma.rx_chan);
+               if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
+                       dma_release_channel(chip->dma.tx_chan);
+               clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
+               clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
+               chip->dma.rx_chan = NULL;
+               chip->dma.tx_chan = NULL;
+       }
 
        snd_card_set_dev(card, NULL);
        snd_card_free(card);
index 439ce64..070aab4 100644 (file)
@@ -50,6 +50,10 @@ static int snd_ctl_open(struct inode *inode, struct file *file)
        struct snd_ctl_file *ctl;
        int err;
 
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
+
        card = snd_lookup_minor_data(iminor(inode), SNDRV_DEVICE_TYPE_CONTROL);
        if (!card) {
                err = -ENODEV;
@@ -1388,6 +1392,7 @@ static const struct file_operations snd_ctl_f_ops =
        .read =         snd_ctl_read,
        .open =         snd_ctl_open,
        .release =      snd_ctl_release,
+       .llseek =       no_llseek,
        .poll =         snd_ctl_poll,
        .unlocked_ioctl =       snd_ctl_ioctl,
        .compat_ioctl = snd_ctl_ioctl_compat,
index cc4a53d..b70564e 100644 (file)
@@ -164,40 +164,44 @@ static loff_t snd_info_entry_llseek(struct file *file, loff_t offset, int orig)
 {
        struct snd_info_private_data *data;
        struct snd_info_entry *entry;
-       loff_t ret;
+       loff_t ret = -EINVAL, size;
 
        data = file->private_data;
        entry = data->entry;
-       lock_kernel();
-       switch (entry->content) {
-       case SNDRV_INFO_CONTENT_TEXT:
-               switch (orig) {
-               case SEEK_SET:
-                       file->f_pos = offset;
-                       ret = file->f_pos;
-                       goto out;
-               case SEEK_CUR:
-                       file->f_pos += offset;
-                       ret = file->f_pos;
-                       goto out;
-               case SEEK_END:
-               default:
-                       ret = -EINVAL;
-                       goto out;
-               }
+       mutex_lock(&entry->access);
+       if (entry->content == SNDRV_INFO_CONTENT_DATA &&
+           entry->c.ops->llseek) {
+               offset = entry->c.ops->llseek(entry,
+                                             data->file_private_data,
+                                             file, offset, orig);
+               goto out;
+       }
+       if (entry->content == SNDRV_INFO_CONTENT_DATA)
+               size = entry->size;
+       else
+               size = 0;
+       switch (orig) {
+       case SEEK_SET:
                break;
-       case SNDRV_INFO_CONTENT_DATA:
-               if (entry->c.ops->llseek) {
-                       ret = entry->c.ops->llseek(entry,
-                                                   data->file_private_data,
-                                                   file, offset, orig);
+       case SEEK_CUR:
+               offset += file->f_pos;
+               break;
+       case SEEK_END:
+               if (!size)
                        goto out;
-               }
+               offset += size;
                break;
-       }
-       ret = -ENXIO;
-out:
-       unlock_kernel();
+       default:
+               goto out;
+       }
+       if (offset < 0)
+               goto out;
+       if (size && offset > size)
+               offset = size;
+       file->f_pos = offset;
+       ret = offset;
+ out:
+       mutex_unlock(&entry->access);
        return ret;
 }
 
@@ -232,10 +236,15 @@ static ssize_t snd_info_entry_read(struct file *file, char __user *buffer,
                        return -EFAULT;
                break;
        case SNDRV_INFO_CONTENT_DATA:
-               if (entry->c.ops->read)
+               if (pos >= entry->size)
+                       return 0;
+               if (entry->c.ops->read) {
+                       size = entry->size - pos;
+                       size = min(count, size);
                        size = entry->c.ops->read(entry,
                                                  data->file_private_data,
-                                                 file, buffer, count, pos);
+                                                 file, buffer, size, pos);
+               }
                break;
        }
        if ((ssize_t) size > 0)
@@ -282,10 +291,13 @@ static ssize_t snd_info_entry_write(struct file *file, const char __user *buffer
                size = count;
                break;
        case SNDRV_INFO_CONTENT_DATA:
-               if (entry->c.ops->write)
+               if (entry->c.ops->write && count > 0) {
+                       size_t maxsize = entry->size - pos;
+                       count = min(count, maxsize);
                        size = entry->c.ops->write(entry,
                                                   data->file_private_data,
                                                   file, buffer, count, pos);
+               }
                break;
        }
        if ((ssize_t) size > 0)
index 14b8a4e..4902ae5 100644 (file)
@@ -24,7 +24,7 @@
 #include <sound/jack.h>
 #include <sound/core.h>
 
-static int jack_types[] = {
+static int jack_switch_types[] = {
        SW_HEADPHONE_INSERT,
        SW_MICROPHONE_INSERT,
        SW_LINEOUT_INSERT,
@@ -56,7 +56,7 @@ static int snd_jack_dev_register(struct snd_device *device)
 {
        struct snd_jack *jack = device->device_data;
        struct snd_card *card = device->card;
-       int err;
+       int err, i;
 
        snprintf(jack->name, sizeof(jack->name), "%s %s",
                 card->shortname, jack->id);
@@ -66,6 +66,19 @@ static int snd_jack_dev_register(struct snd_device *device)
        if (!jack->input_dev->dev.parent)
                jack->input_dev->dev.parent = snd_card_get_device_link(card);
 
+       /* Add capabilities for any keys that are enabled */
+       for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
+               int testbit = SND_JACK_BTN_0 >> i;
+
+               if (!(jack->type & testbit))
+                       continue;
+
+               if (!jack->key[i])
+                       jack->key[i] = BTN_0 + i;
+
+               input_set_capability(jack->input_dev, EV_KEY, jack->key[i]);
+       }
+
        err = input_register_device(jack->input_dev);
        if (err == 0)
                jack->registered = 1;
@@ -113,10 +126,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
 
        jack->type = type;
 
-       for (i = 0; i < ARRAY_SIZE(jack_types); i++)
+       for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++)
                if (type & (1 << i))
                        input_set_capability(jack->input_dev, EV_SW,
-                                            jack_types[i]);
+                                            jack_switch_types[i]);
 
        err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
        if (err < 0)
@@ -151,6 +164,43 @@ void snd_jack_set_parent(struct snd_jack *jack, struct device *parent)
 }
 EXPORT_SYMBOL(snd_jack_set_parent);
 
+/**
+ * snd_jack_set_key - Set a key mapping on a jack
+ *
+ * @jack:    The jack to configure
+ * @type:    Jack report type for this key
+ * @keytype: Input layer key type to be reported
+ *
+ * Map a SND_JACK_BTN_ button type to an input layer key, allowing
+ * reporting of keys on accessories via the jack abstraction.  If no
+ * mapping is provided but keys are enabled in the jack type then
+ * BTN_n numeric buttons will be reported.
+ *
+ * Note that this is intended to be use by simple devices with small
+ * numbers of keys that can be reported.  It is also possible to
+ * access the input device directly - devices with complex input
+ * capabilities on accessories should consider doing this rather than
+ * using this abstraction.
+ *
+ * This function may only be called prior to registration of the jack.
+ */
+int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
+                    int keytype)
+{
+       int key = fls(SND_JACK_BTN_0) - fls(type);
+
+       WARN_ON(jack->registered);
+
+       if (!keytype || key >= ARRAY_SIZE(jack->key))
+               return -EINVAL;
+
+       jack->type |= type;
+       jack->key[key] = keytype;
+
+       return 0;
+}
+EXPORT_SYMBOL(snd_jack_set_key);
+
 /**
  * snd_jack_report - Report the current status of a jack
  *
@@ -164,10 +214,19 @@ void snd_jack_report(struct snd_jack *jack, int status)
        if (!jack)
                return;
 
-       for (i = 0; i < ARRAY_SIZE(jack_types); i++) {
+       for (i = 0; i < ARRAY_SIZE(jack->key); i++) {
+               int testbit = SND_JACK_BTN_0 >> i;
+
+               if (jack->type & testbit)
+                       input_report_key(jack->input_dev, jack->key[i],
+                                        status & testbit);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(jack_switch_types); i++) {
                int testbit = 1 << i;
                if (jack->type & testbit)
-                       input_report_switch(jack->input_dev, jack_types[i],
+                       input_report_switch(jack->input_dev,
+                                           jack_switch_types[i],
                                            status & testbit);
        }
 
index 54e2eb5..f50ebf2 100644 (file)
@@ -43,6 +43,10 @@ static int snd_mixer_oss_open(struct inode *inode, struct file *file)
        struct snd_mixer_oss_file *fmixer;
        int err;
 
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
+
        card = snd_lookup_oss_minor_data(iminor(inode),
                                         SNDRV_OSS_DEVICE_TYPE_MIXER);
        if (card == NULL)
@@ -397,6 +401,7 @@ static const struct file_operations snd_mixer_oss_f_ops =
        .owner =        THIS_MODULE,
        .open =         snd_mixer_oss_open,
        .release =      snd_mixer_oss_release,
+       .llseek =       no_llseek,
        .unlocked_ioctl =       snd_mixer_oss_ioctl,
        .compat_ioctl = snd_mixer_oss_ioctl_compat,
 };
index 82d4e33..5c8c7df 100644 (file)
@@ -2379,6 +2379,10 @@ static int snd_pcm_oss_open(struct inode *inode, struct file *file)
        int nonblock;
        wait_queue_t wait;
 
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
+
        pcm = snd_lookup_oss_minor_data(iminor(inode),
                                        SNDRV_OSS_DEVICE_TYPE_PCM);
        if (pcm == NULL) {
@@ -2977,6 +2981,7 @@ static const struct file_operations snd_pcm_oss_f_reg =
        .write =        snd_pcm_oss_write,
        .open =         snd_pcm_oss_open,
        .release =      snd_pcm_oss_release,
+       .llseek =       no_llseek,
        .poll =         snd_pcm_oss_poll,
        .unlocked_ioctl =       snd_pcm_oss_ioctl,
        .compat_ioctl = snd_pcm_oss_ioctl_compat,
index 0d428d0..cbe815d 100644 (file)
@@ -648,9 +648,6 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
                substream->number = idx;
                substream->stream = stream;
                sprintf(substream->name, "subdevice #%i", idx);
-               snprintf(substream->latency_id, sizeof(substream->latency_id),
-                        "ALSA-PCM%d-%d%c%d", pcm->card->number, pcm->device,
-                        (stream ? 'c' : 'p'), idx);
                substream->buffer_bytes_max = UINT_MAX;
                if (prev == NULL)
                        pstr->substream = substream;
index 20b5982..644c2bb 100644 (file)
@@ -484,11 +484,13 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream,
        snd_pcm_timer_resolution_change(substream);
        runtime->status->state = SNDRV_PCM_STATE_SETUP;
 
-       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
-                               substream->latency_id);
+       if (substream->latency_pm_qos_req) {
+               pm_qos_remove_request(substream->latency_pm_qos_req);
+               substream->latency_pm_qos_req = NULL;
+       }
        if ((usecs = period_to_usecs(runtime)) >= 0)
-               pm_qos_add_requirement(PM_QOS_CPU_DMA_LATENCY,
-                                       substream->latency_id, usecs);
+               substream->latency_pm_qos_req = pm_qos_add_request(
+                                       PM_QOS_CPU_DMA_LATENCY, usecs);
        return 0;
  _error:
        /* hardware might be unuseable from this time,
@@ -543,8 +545,8 @@ static int snd_pcm_hw_free(struct snd_pcm_substream *substream)
        if (substream->ops->hw_free)
                result = substream->ops->hw_free(substream);
        runtime->status->state = SNDRV_PCM_STATE_OPEN;
-       pm_qos_remove_requirement(PM_QOS_CPU_DMA_LATENCY,
-               substream->latency_id);
+       pm_qos_remove_request(substream->latency_pm_qos_req);
+       substream->latency_pm_qos_req = NULL;
        return result;
 }
 
@@ -2110,7 +2112,9 @@ static int snd_pcm_open_file(struct file *file,
 static int snd_pcm_playback_open(struct inode *inode, struct file *file)
 {
        struct snd_pcm *pcm;
-
+       int err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
        pcm = snd_lookup_minor_data(iminor(inode),
                                    SNDRV_DEVICE_TYPE_PCM_PLAYBACK);
        return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_PLAYBACK);
@@ -2119,7 +2123,9 @@ static int snd_pcm_playback_open(struct inode *inode, struct file *file)
 static int snd_pcm_capture_open(struct inode *inode, struct file *file)
 {
        struct snd_pcm *pcm;
-
+       int err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
        pcm = snd_lookup_minor_data(iminor(inode),
                                    SNDRV_DEVICE_TYPE_PCM_CAPTURE);
        return snd_pcm_open(file, pcm, SNDRV_PCM_STREAM_CAPTURE);
@@ -3310,18 +3316,13 @@ static int snd_pcm_fasync(int fd, struct file * file, int on)
        struct snd_pcm_file * pcm_file;
        struct snd_pcm_substream *substream;
        struct snd_pcm_runtime *runtime;
-       int err = -ENXIO;
 
-       lock_kernel();
        pcm_file = file->private_data;
        substream = pcm_file->substream;
        if (PCM_RUNTIME_CHECK(substream))
-               goto out;
+               return -ENXIO;
        runtime = substream->runtime;
-       err = fasync_helper(fd, file, on, &runtime->fasync);
-out:
-       unlock_kernel();
-       return err;
+       return fasync_helper(fd, file, on, &runtime->fasync);
 }
 
 /*
@@ -3441,14 +3442,28 @@ out:
 #endif /* CONFIG_SND_SUPPORT_OLD_API */
 
 #ifndef CONFIG_MMU
-unsigned long dummy_get_unmapped_area(struct file *file, unsigned long addr,
-                                     unsigned long len, unsigned long pgoff,
-                                     unsigned long flags)
-{
-       return 0;
+static unsigned long snd_pcm_get_unmapped_area(struct file *file,
+                                              unsigned long addr,
+                                              unsigned long len,
+                                              unsigned long pgoff,
+                                              unsigned long flags)
+{
+       struct snd_pcm_file *pcm_file = file->private_data;
+       struct snd_pcm_substream *substream = pcm_file->substream;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       unsigned long offset = pgoff << PAGE_SHIFT;
+
+       switch (offset) {
+       case SNDRV_PCM_MMAP_OFFSET_STATUS:
+               return (unsigned long)runtime->status;
+       case SNDRV_PCM_MMAP_OFFSET_CONTROL:
+               return (unsigned long)runtime->control;
+       default:
+               return (unsigned long)runtime->dma_area + offset;
+       }
 }
 #else
-# define dummy_get_unmapped_area NULL
+# define snd_pcm_get_unmapped_area NULL
 #endif
 
 /*
@@ -3462,12 +3477,13 @@ const struct file_operations snd_pcm_f_ops[2] = {
                .aio_write =            snd_pcm_aio_write,
                .open =                 snd_pcm_playback_open,
                .release =              snd_pcm_release,
+               .llseek =               no_llseek,
                .poll =                 snd_pcm_playback_poll,
                .unlocked_ioctl =       snd_pcm_playback_ioctl,
                .compat_ioctl =         snd_pcm_ioctl_compat,
                .mmap =                 snd_pcm_mmap,
                .fasync =               snd_pcm_fasync,
-               .get_unmapped_area =    dummy_get_unmapped_area,
+               .get_unmapped_area =    snd_pcm_get_unmapped_area,
        },
        {
                .owner =                THIS_MODULE,
@@ -3475,11 +3491,12 @@ const struct file_operations snd_pcm_f_ops[2] = {
                .aio_read =             snd_pcm_aio_read,
                .open =                 snd_pcm_capture_open,
                .release =              snd_pcm_release,
+               .llseek =               no_llseek,
                .poll =                 snd_pcm_capture_poll,
                .unlocked_ioctl =       snd_pcm_capture_ioctl,
                .compat_ioctl =         snd_pcm_ioctl_compat,
                .mmap =                 snd_pcm_mmap,
                .fasync =               snd_pcm_fasync,
-               .get_unmapped_area =    dummy_get_unmapped_area,
+               .get_unmapped_area =    snd_pcm_get_unmapped_area,
        }
 };
index 0f5a194..eb68326 100644 (file)
@@ -376,6 +376,10 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
        if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) 
                return -EINVAL;         /* invalid combination */
 
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
+
        if (maj == snd_major) {
                rmidi = snd_lookup_minor_data(iminor(inode),
                                              SNDRV_DEVICE_TYPE_RAWMIDI);
@@ -1391,6 +1395,7 @@ static const struct file_operations snd_rawmidi_f_ops =
        .write =        snd_rawmidi_write,
        .open =         snd_rawmidi_open,
        .release =      snd_rawmidi_release,
+       .llseek =       no_llseek,
        .poll =         snd_rawmidi_poll,
        .unlocked_ioctl =       snd_rawmidi_ioctl,
        .compat_ioctl = snd_rawmidi_ioctl_compat,
index 48eca9f..99a485f 100644 (file)
@@ -318,6 +318,11 @@ static int snd_seq_open(struct inode *inode, struct file *file)
        int c, mode;                    /* client id */
        struct snd_seq_client *client;
        struct snd_seq_user_client *user;
+       int err;
+
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
 
        if (mutex_lock_interruptible(&register_mutex))
                return -ERESTARTSYS;
@@ -2550,6 +2555,7 @@ static const struct file_operations snd_seq_f_ops =
        .write =        snd_seq_write,
        .open =         snd_seq_open,
        .release =      snd_seq_release,
+       .llseek =       no_llseek,
        .poll =         snd_seq_poll,
        .unlocked_ioctl =       snd_seq_ioctl,
        .compat_ioctl = snd_seq_ioctl_compat,
index 563d196..ac42af4 100644 (file)
@@ -120,7 +120,29 @@ void *snd_lookup_minor_data(unsigned int minor, int type)
 
 EXPORT_SYMBOL(snd_lookup_minor_data);
 
-static int __snd_open(struct inode *inode, struct file *file)
+#ifdef CONFIG_MODULES
+static struct snd_minor *autoload_device(unsigned int minor)
+{
+       int dev;
+       mutex_unlock(&sound_mutex); /* release lock temporarily */
+       dev = SNDRV_MINOR_DEVICE(minor);
+       if (dev == SNDRV_MINOR_CONTROL) {
+               /* /dev/aloadC? */
+               int card = SNDRV_MINOR_CARD(minor);
+               if (snd_cards[card] == NULL)
+                       snd_request_card(card);
+       } else if (dev == SNDRV_MINOR_GLOBAL) {
+               /* /dev/aloadSEQ */
+               snd_request_other(minor);
+       }
+       mutex_lock(&sound_mutex); /* reacuire lock */
+       return snd_minors[minor];
+}
+#else /* !CONFIG_MODULES */
+#define autoload_device(minor) NULL
+#endif /* CONFIG_MODULES */
+
+static int snd_open(struct inode *inode, struct file *file)
 {
        unsigned int minor = iminor(inode);
        struct snd_minor *mptr = NULL;
@@ -129,55 +151,36 @@ static int __snd_open(struct inode *inode, struct file *file)
 
        if (minor >= ARRAY_SIZE(snd_minors))
                return -ENODEV;
+       mutex_lock(&sound_mutex);
        mptr = snd_minors[minor];
        if (mptr == NULL) {
-#ifdef CONFIG_MODULES
-               int dev = SNDRV_MINOR_DEVICE(minor);
-               if (dev == SNDRV_MINOR_CONTROL) {
-                       /* /dev/aloadC? */
-                       int card = SNDRV_MINOR_CARD(minor);
-                       if (snd_cards[card] == NULL)
-                               snd_request_card(card);
-               } else if (dev == SNDRV_MINOR_GLOBAL) {
-                       /* /dev/aloadSEQ */
-                       snd_request_other(minor);
-               }
-#ifndef CONFIG_SND_DYNAMIC_MINORS
-               /* /dev/snd/{controlC?,seq} */
-               mptr = snd_minors[minor];
-               if (mptr == NULL)
-#endif
-#endif
+               mptr = autoload_device(minor);
+               if (!mptr) {
+                       mutex_unlock(&sound_mutex);
                        return -ENODEV;
+               }
        }
        old_fops = file->f_op;
        file->f_op = fops_get(mptr->f_ops);
        if (file->f_op == NULL) {
                file->f_op = old_fops;
-               return -ENODEV;
+               err = -ENODEV;
        }
-       if (file->f_op->open)
+       mutex_unlock(&sound_mutex);
+       if (err < 0)
+               return err;
+
+       if (file->f_op->open) {
                err = file->f_op->open(inode, file);
-       if (err) {
-               fops_put(file->f_op);
-               file->f_op = fops_get(old_fops);
+               if (err) {
+                       fops_put(file->f_op);
+                       file->f_op = fops_get(old_fops);
+               }
        }
        fops_put(old_fops);
        return err;
 }
 
-
-/* BKL pushdown: nasty #ifdef avoidance wrapper */
-static int snd_open(struct inode *inode, struct file *file)
-{
-       int ret;
-
-       lock_kernel();
-       ret = __snd_open(inode, file);
-       unlock_kernel();
-       return ret;
-}
-
 static const struct file_operations snd_fops =
 {
        .owner =        THIS_MODULE,
index 5040c7b..13afb60 100644 (file)
@@ -1238,6 +1238,11 @@ static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
 static int snd_timer_user_open(struct inode *inode, struct file *file)
 {
        struct snd_timer_user *tu;
+       int err;
+
+       err = nonseekable_open(inode, file);
+       if (err < 0)
+               return err;
 
        tu = kzalloc(sizeof(*tu), GFP_KERNEL);
        if (tu == NULL)
@@ -1922,6 +1927,7 @@ static const struct file_operations snd_timer_f_ops =
        .read =         snd_timer_user_read,
        .open =         snd_timer_user_open,
        .release =      snd_timer_user_release,
+       .llseek =       no_llseek,
        .poll =         snd_timer_user_poll,
        .unlocked_ioctl =       snd_timer_user_ioctl,
        .compat_ioctl = snd_timer_user_ioctl_compat,
index 1679300..df850b8 100644 (file)
@@ -49,77 +49,45 @@ static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
        return 0;
 }
 
-static long snd_opl4_mem_proc_read(struct snd_info_entry *entry, void *file_private_data,
-                                  struct file *file, char __user *_buf,
-                                  unsigned long count, unsigned long pos)
+static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
+                                     void *file_private_data,
+                                     struct file *file, char __user *_buf,
+                                     size_t count, loff_t pos)
 {
        struct snd_opl4 *opl4 = entry->private_data;
-       long size;
        char* buf;
 
-       size = count;
-       if (pos + size > entry->size)
-               size = entry->size - pos;
-       if (size > 0) {
-               buf = vmalloc(size);
-               if (!buf)
-                       return -ENOMEM;
-               snd_opl4_read_memory(opl4, buf, pos, size);
-               if (copy_to_user(_buf, buf, size)) {
-                       vfree(buf);
-                       return -EFAULT;
-               }
+       buf = vmalloc(count);
+       if (!buf)
+               return -ENOMEM;
+       snd_opl4_read_memory(opl4, buf, pos, count);
+       if (copy_to_user(_buf, buf, count)) {
                vfree(buf);
-               return size;
+               return -EFAULT;
        }
-       return 0;
+       vfree(buf);
+       return count;
 }
 
-static long snd_opl4_mem_proc_write(struct snd_info_entry *entry, void *file_private_data,
-                                   struct file *file, const char __user *_buf,
-                                   unsigned long count, unsigned long pos)
+static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
+                                      void *file_private_data,
+                                      struct file *file,
+                                      const char __user *_buf,
+                                      size_t count, loff_t pos)
 {
        struct snd_opl4 *opl4 = entry->private_data;
-       long size;
        char *buf;
 
-       size = count;
-       if (pos + size > entry->size)
-               size = entry->size - pos;
-       if (size > 0) {
-               buf = vmalloc(size);
-               if (!buf)
-                       return -ENOMEM;
-               if (copy_from_user(buf, _buf, size)) {
-                       vfree(buf);
-                       return -EFAULT;
-               }
-               snd_opl4_write_memory(opl4, buf, pos, size);
+       buf = vmalloc(count);
+       if (!buf)
+               return -ENOMEM;
+       if (copy_from_user(buf, _buf, count)) {
                vfree(buf);
-               return size;
-       }
-       return 0;
-}
-
-static long long snd_opl4_mem_proc_llseek(struct snd_info_entry *entry, void *file_private_data,
-                                         struct file *file, long long offset, int orig)
-{
-       switch (orig) {
-       case SEEK_SET:
-               file->f_pos = offset;
-               break;
-       case SEEK_CUR:
-               file->f_pos += offset;
-               break;
-       case SEEK_END: /* offset is negative */
-               file->f_pos = entry->size + offset;
-               break;
-       default:
-               return -EINVAL;
+               return -EFAULT;
        }
-       if (file->f_pos > entry->size)
-               file->f_pos = entry->size;
-       return file->f_pos;
+       snd_opl4_write_memory(opl4, buf, pos, count);
+       vfree(buf);
+       return count;
 }
 
 static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
@@ -127,7 +95,6 @@ static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
        .release = snd_opl4_mem_proc_release,
        .read = snd_opl4_mem_proc_read,
        .write = snd_opl4_mem_proc_write,
-       .llseek = snd_opl4_mem_proc_llseek,
 };
 
 int snd_opl4_create_proc(struct snd_opl4 *opl4)
index 1e12307..4ff6c8c 100644 (file)
@@ -16,7 +16,7 @@
 #include <asm/i8253.h>
 #else
 #include <asm/8253pit.h>
-static DEFINE_SPINLOCK(i8253_lock);
+static DEFINE_RAW_SPINLOCK(i8253_lock);
 #endif
 
 #define PCSP_SOUND_VERSION 0x400       /* read 4.00 */
index 0444cde..b5e2b54 100644 (file)
@@ -21,7 +21,7 @@ static void pcspkr_do_sound(unsigned int count)
 {
        unsigned long flags;
 
-       spin_lock_irqsave(&i8253_lock, flags);
+       raw_spin_lock_irqsave(&i8253_lock, flags);
 
        if (count) {
                /* set command for counter 2, 2 byte write */
@@ -36,7 +36,7 @@ static void pcspkr_do_sound(unsigned int count)
                outb(inb_p(0x61) & 0xFC, 0x61);
        }
 
-       spin_unlock_irqrestore(&i8253_lock, flags);
+       raw_spin_unlock_irqrestore(&i8253_lock, flags);
 }
 
 void pcspkr_stop_sound(void)
index d77ffa9..ce9e7d1 100644 (file)
@@ -66,7 +66,7 @@ static u64 pcsp_timer_update(struct snd_pcsp *chip)
        timer_cnt = val * CUR_DIV() / 256;
 
        if (timer_cnt && chip->enable) {
-               spin_lock_irqsave(&i8253_lock, flags);
+               raw_spin_lock_irqsave(&i8253_lock, flags);
                if (!nforce_wa) {
                        outb_p(chip->val61, 0x61);
                        outb_p(timer_cnt, 0x42);
@@ -75,7 +75,7 @@ static u64 pcsp_timer_update(struct snd_pcsp *chip)
                        outb(chip->val61 ^ 2, 0x61);
                        chip->thalf = 1;
                }
-               spin_unlock_irqrestore(&i8253_lock, flags);
+               raw_spin_unlock_irqrestore(&i8253_lock, flags);
        }
 
        chip->ns_rem = PCSP_PERIOD_NS();
@@ -159,10 +159,10 @@ static int pcsp_start_playing(struct snd_pcsp *chip)
                return -EIO;
        }
 
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
        chip->val61 = inb(0x61) | 0x03;
        outb_p(0x92, 0x43);     /* binary, mode 1, LSB only, ch 2 */
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
        atomic_set(&chip->timer_active, 1);
        chip->thalf = 0;
 
@@ -179,11 +179,11 @@ static void pcsp_stop_playing(struct snd_pcsp *chip)
                return;
 
        atomic_set(&chip->timer_active, 0);
-       spin_lock(&i8253_lock);
+       raw_spin_lock(&i8253_lock);
        /* restore the timer */
        outb_p(0xb6, 0x43);     /* binary, mode 3, LSB/MSB, ch 2 */
        outb(chip->val61 & 0xFC, 0x61);
-       spin_unlock(&i8253_lock);
+       raw_spin_unlock(&i8253_lock);
 }
 
 /*
index 5c0c77d..eb7c7d0 100644 (file)
@@ -98,7 +98,8 @@ int snd_i2c_bus_create(struct snd_card *card, const char *name,
                bus->master = master;
        }
        strlcpy(bus->name, name, sizeof(bus->name));
-       if ((err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops)) < 0) {
+       err = snd_device_new(card, SNDRV_DEV_BUS, bus, &ops);
+       if (err < 0) {
                snd_i2c_bus_free(bus);
                return err;
        }
@@ -246,7 +247,8 @@ static int snd_i2c_bit_sendbyte(struct snd_i2c_bus *bus, unsigned char data)
 
        for (i = 7; i >= 0; i--)
                snd_i2c_bit_send(bus, !!(data & (1 << i)));
-       if ((err = snd_i2c_bit_ack(bus)) < 0)
+       err = snd_i2c_bit_ack(bus);
+       if (err < 0)
                return err;
        return 0;
 }
@@ -278,12 +280,14 @@ static int snd_i2c_bit_sendbytes(struct snd_i2c_device *device,
        if (device->flags & SND_I2C_DEVICE_ADDRTEN)
                return -EIO;            /* not yet implemented */
        snd_i2c_bit_start(bus);
-       if ((err = snd_i2c_bit_sendbyte(bus, device->addr << 1)) < 0) {
+       err = snd_i2c_bit_sendbyte(bus, device->addr << 1);
+       if (err < 0) {
                snd_i2c_bit_hw_stop(bus);
                return err;
        }
        while (count-- > 0) {
-               if ((err = snd_i2c_bit_sendbyte(bus, *bytes++)) < 0) {
+               err = snd_i2c_bit_sendbyte(bus, *bytes++);
+               if (err < 0) {
                        snd_i2c_bit_hw_stop(bus);
                        return err;
                }
@@ -302,12 +306,14 @@ static int snd_i2c_bit_readbytes(struct snd_i2c_device *device,
        if (device->flags & SND_I2C_DEVICE_ADDRTEN)
                return -EIO;            /* not yet implemented */
        snd_i2c_bit_start(bus);
-       if ((err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1)) < 0) {
+       err = snd_i2c_bit_sendbyte(bus, (device->addr << 1) | 1);
+       if (err < 0) {
                snd_i2c_bit_hw_stop(bus);
                return err;
        }
        while (count-- > 0) {
-               if ((err = snd_i2c_bit_readbyte(bus, count == 0)) < 0) {
+               err = snd_i2c_bit_readbyte(bus, count == 0);
+               if (err < 0) {
                        snd_i2c_bit_hw_stop(bus);
                        return err;
                }
index 755a0a5..c6990c6 100644 (file)
@@ -128,26 +128,14 @@ config SND_CS4236
          To compile this driver as a module, choose M here: the module
          will be called snd-cs4236.
 
-config SND_ES968
-       tristate "Generic ESS ES968 driver"
-       depends on PNP
-       select ISAPNP
-       select SND_MPU401_UART
-       select SND_SB8_DSP
-       help
-         Say Y here to include support for ESS AudioDrive ES968 chips.
-
-         To compile this driver as a module, choose M here: the module
-         will be called snd-es968.
-
 config SND_ES1688
-       tristate "Generic ESS ES688/ES1688 driver"
+       tristate "Generic ESS ES688/ES1688 and ES968 PnP driver"
        select SND_OPL3_LIB
        select SND_MPU401_UART
        select SND_PCM
        help
          Say Y here to include support for ESS AudioDrive ES688 or
-         ES1688 chips.
+         ES1688 chips. Also, this module support cards with ES968 PnP chip.
 
          To compile this driver as a module, choose M here: the module
          will be called snd-es1688.
index 07df201..0cde813 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/init.h>
 #include <linux/err.h>
 #include <linux/isa.h>
+#include <linux/isapnp.h>
 #include <linux/time.h>
 #include <linux/wait.h>
 #include <linux/moduleparam.h>
@@ -45,8 +46,13 @@ MODULE_SUPPORTED_DEVICE("{{ESS,ES688 PnP AudioDrive,pnp:ESS0100},"
                "{ESS,ES688 AudioDrive,pnp:ESS6881},"
                "{ESS,ES1688 AudioDrive,pnp:ESS1681}}");
 
+MODULE_ALIAS("snd_es968");
+
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
+#ifdef CONFIG_PNP
+static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
+#endif
 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* 0x220,0x240,0x260 */
 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */
@@ -60,6 +66,10 @@ MODULE_PARM_DESC(index, "Index value for " CRD_NAME " soundcard.");
 module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for " CRD_NAME " soundcard.");
 module_param_array(enable, bool, NULL, 0444);
+#ifdef CONFIG_PNP
+module_param_array(isapnp, bool, NULL, 0444);
+MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
+#endif
 MODULE_PARM_DESC(enable, "Enable " CRD_NAME " soundcard.");
 module_param_array(port, long, NULL, 0444);
 MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
@@ -74,14 +84,21 @@ MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
 module_param_array(dma8, int, NULL, 0444);
 MODULE_PARM_DESC(dma8, "8-bit DMA # for " CRD_NAME " driver.");
 
+#ifdef CONFIG_PNP
+#define is_isapnp_selected(dev)                isapnp[dev]
+#else
+#define is_isapnp_selected(dev)                0
+#endif
+
 static int __devinit snd_es1688_match(struct device *dev, unsigned int n)
 {
-       return enable[n];
+       return enable[n] && !is_isapnp_selected(n);
 }
 
-static int __devinit snd_es1688_legacy_create(struct snd_card *card, 
-               struct device *dev, unsigned int n, struct snd_es1688 **rchip)
+static int __devinit snd_es1688_legacy_create(struct snd_card *card,
+                                       struct device *dev, unsigned int n)
 {
+       struct snd_es1688 *chip = card->private_data;
        static long possible_ports[] = {0x220, 0x240, 0x260};
        static int possible_irqs[] = {5, 9, 10, 7, -1};
        static int possible_dmas[] = {1, 3, 0, -1};
@@ -104,47 +121,39 @@ static int __devinit snd_es1688_legacy_create(struct snd_card *card,
        }
 
        if (port[n] != SNDRV_AUTO_PORT)
-               return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
-                               mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
+               return snd_es1688_create(card, chip, port[n], mpu_port[n],
+                               irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO);
 
        i = 0;
        do {
                port[n] = possible_ports[i];
-               error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
-                               mpu_irq[n], dma8[n], ES1688_HW_AUTO, rchip);
+               error = snd_es1688_create(card, chip, port[n], mpu_port[n],
+                               irq[n], mpu_irq[n], dma8[n], ES1688_HW_AUTO);
        } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
 
        return error;
 }
 
-static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
+static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n)
 {
-       struct snd_card *card;
-       struct snd_es1688 *chip;
+       struct snd_es1688 *chip = card->private_data;
        struct snd_opl3 *opl3;
        struct snd_pcm *pcm;
        int error;
 
-       error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
+       error = snd_es1688_pcm(card, chip, 0, &pcm);
        if (error < 0)
                return error;
 
-       error = snd_es1688_legacy_create(card, dev, n, &chip);
-       if (error < 0)
-               goto out;
-
-       error = snd_es1688_pcm(chip, 0, &pcm);
+       error = snd_es1688_mixer(card, chip);
        if (error < 0)
-               goto out;
-
-       error = snd_es1688_mixer(chip);
-       if (error < 0)
-               goto out;
+               return error;
 
-       strcpy(card->driver, "ES1688");
-       strcpy(card->shortname, pcm->name);
-       sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
-               chip->port, chip->irq, chip->dma8);
+       strlcpy(card->driver, "ES1688", sizeof(card->driver));
+       strlcpy(card->shortname, pcm->name, sizeof(card->shortname));
+       snprintf(card->longname, sizeof(card->longname),
+               "%s at 0x%lx, irq %i, dma %i", pcm->name, chip->port,
+                chip->irq, chip->dma8);
 
        if (fm_port[n] == SNDRV_AUTO_PORT)
                fm_port[n] = port[n];   /* share the same port */
@@ -152,12 +161,12 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
        if (fm_port[n] > 0) {
                if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2,
                                OPL3_HW_OPL3, 0, &opl3) < 0)
-                       dev_warn(dev,
+                       dev_warn(card->dev,
                                 "opl3 not detected at 0x%lx\n", fm_port[n]);
                else {
                        error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
                        if (error < 0)
-                               goto out;
+                               return error;
                }
        }
 
@@ -167,23 +176,41 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
                                chip->mpu_port, 0,
                                mpu_irq[n], IRQF_DISABLED, NULL);
                if (error < 0)
-                       goto out;
+                       return error;
        }
 
+       return snd_card_register(card);
+}
+
+static int __devinit snd_es1688_isa_probe(struct device *dev, unsigned int n)
+{
+       struct snd_card *card;
+       int error;
+
+       error = snd_card_create(index[n], id[n], THIS_MODULE,
+                               sizeof(struct snd_es1688), &card);
+       if (error < 0)
+               return error;
+
+       error = snd_es1688_legacy_create(card, dev, n);
+       if (error < 0)
+               goto out;
+
        snd_card_set_dev(card, dev);
 
-       error = snd_card_register(card);
+       error = snd_es1688_probe(card, n);
        if (error < 0)
                goto out;
 
        dev_set_drvdata(dev, card);
-       return 0;
 
-out:   snd_card_free(card);
+       return 0;
+out:
+       snd_card_free(card);
        return error;
 }
 
-static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
+static int __devexit snd_es1688_isa_remove(struct device *dev, unsigned int n)
 {
        snd_card_free(dev_get_drvdata(dev));
        dev_set_drvdata(dev, NULL);
@@ -192,8 +219,8 @@ static int __devexit snd_es1688_remove(struct device *dev, unsigned int n)
 
 static struct isa_driver snd_es1688_driver = {
        .match          = snd_es1688_match,
-       .probe          = snd_es1688_probe,
-       .remove         = __devexit_p(snd_es1688_remove),
+       .probe          = snd_es1688_isa_probe,
+       .remove         = __devexit_p(snd_es1688_isa_remove),
 #if 0  /* FIXME */
        .suspend        = snd_es1688_suspend,
        .resume         = snd_es1688_resume,
@@ -203,14 +230,142 @@ static struct isa_driver snd_es1688_driver = {
        }
 };
 
+static int snd_es968_pnp_is_probed;
+
+#ifdef CONFIG_PNP
+static int __devinit snd_card_es968_pnp(struct snd_card *card, unsigned int n,
+                                       struct pnp_card_link *pcard,
+                                       const struct pnp_card_device_id *pid)
+{
+       struct snd_es1688 *chip = card->private_data;
+       struct pnp_dev *pdev;
+       int error;
+
+       pdev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
+       if (pdev == NULL)
+               return -ENODEV;
+
+       error = pnp_activate_dev(pdev);
+       if (error < 0) {
+               snd_printk(KERN_ERR "ES968 pnp configure failure\n");
+               return error;
+       }
+       port[n] = pnp_port_start(pdev, 0);
+       dma8[n] = pnp_dma(pdev, 0);
+       irq[n] = pnp_irq(pdev, 0);
+
+       return snd_es1688_create(card, chip, port[n], mpu_port[n], irq[n],
+                                mpu_irq[n], dma8[n], ES1688_HW_AUTO);
+}
+
+static int __devinit snd_es968_pnp_detect(struct pnp_card_link *pcard,
+                                         const struct pnp_card_device_id *pid)
+{
+       struct snd_card *card;
+       static unsigned int dev;
+       int error;
+       struct snd_es1688 *chip;
+
+       if (snd_es968_pnp_is_probed)
+               return -EBUSY;
+       for ( ; dev < SNDRV_CARDS; dev++) {
+               if (enable[dev] && isapnp[dev])
+                       break;
+       }
+       if (dev == SNDRV_CARDS)
+               return -ENODEV;
+
+       error = snd_card_create(index[dev], id[dev], THIS_MODULE,
+                               sizeof(struct snd_es1688), &card);
+       if (error < 0)
+               return error;
+       chip = card->private_data;
+
+       error = snd_card_es968_pnp(card, dev, pcard, pid);
+       if (error < 0) {
+               snd_card_free(card);
+               return error;
+       }
+       snd_card_set_dev(card, &pcard->card->dev);
+       error = snd_es1688_probe(card, dev);
+       if (error < 0)
+               return error;
+       pnp_set_card_drvdata(pcard, card);
+       snd_es968_pnp_is_probed = 1;
+       return 0;
+}
+
+static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
+{
+       snd_card_free(pnp_get_card_drvdata(pcard));
+       pnp_set_card_drvdata(pcard, NULL);
+       snd_es968_pnp_is_probed = 0;
+}
+
+#ifdef CONFIG_PM
+static int snd_es968_pnp_suspend(struct pnp_card_link *pcard,
+                                pm_message_t state)
+{
+       struct snd_card *card = pnp_get_card_drvdata(pcard);
+       struct snd_es1688 *chip = card->private_data;
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       snd_pcm_suspend_all(chip->pcm);
+       return 0;
+}
+
+static int snd_es968_pnp_resume(struct pnp_card_link *pcard)
+{
+       struct snd_card *card = pnp_get_card_drvdata(pcard);
+       struct snd_es1688 *chip = card->private_data;
+
+       snd_es1688_reset(chip);
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif
+
+static struct pnp_card_device_id snd_es968_pnpids[] = {
+       { .id = "ESS0968", .devs = { { "@@@0968" }, } },
+       { .id = "ESS0968", .devs = { { "ESS0968" }, } },
+       { .id = "", } /* end */
+};
+
+MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
+
+static struct pnp_card_driver es968_pnpc_driver = {
+       .flags          = PNP_DRIVER_RES_DISABLE,
+       .name           = DEV_NAME " PnP",
+       .id_table       = snd_es968_pnpids,
+       .probe          = snd_es968_pnp_detect,
+       .remove         = __devexit_p(snd_es968_pnp_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_es968_pnp_suspend,
+       .resume         = snd_es968_pnp_resume,
+#endif
+};
+#endif
+
 static int __init alsa_card_es1688_init(void)
 {
+#ifdef CONFIG_PNP
+       pnp_register_card_driver(&es968_pnpc_driver);
+       if (snd_es968_pnp_is_probed)
+               return 0;
+       pnp_unregister_card_driver(&es968_pnpc_driver);
+#endif
        return isa_register_driver(&snd_es1688_driver, SNDRV_CARDS);
 }
 
 static void __exit alsa_card_es1688_exit(void)
 {
-       isa_unregister_driver(&snd_es1688_driver);
+       if (!snd_es968_pnp_is_probed) {
+               isa_unregister_driver(&snd_es1688_driver);
+               return;
+       }
+#ifdef CONFIG_PNP
+       pnp_unregister_card_driver(&es968_pnpc_driver);
+#endif
 }
 
 module_init(alsa_card_es1688_init);
index c76bb00..0767620 100644 (file)
@@ -99,7 +99,7 @@ static unsigned char snd_es1688_mixer_read(struct snd_es1688 *chip, unsigned cha
        return result;
 }
 
-static int snd_es1688_reset(struct snd_es1688 *chip)
+int snd_es1688_reset(struct snd_es1688 *chip)
 {
        int i;
 
@@ -115,6 +115,7 @@ static int snd_es1688_reset(struct snd_es1688 *chip)
        snd_es1688_dsp_command(chip, 0xc6);     /* enable extended mode */
        return 0;
 }
+EXPORT_SYMBOL(snd_es1688_reset);
 
 static int snd_es1688_probe(struct snd_es1688 *chip)
 {
@@ -620,7 +621,6 @@ static int snd_es1688_free(struct snd_es1688 *chip)
                disable_dma(chip->dma8);
                free_dma(chip->dma8);
        }
-       kfree(chip);
        return 0;
 }
 
@@ -638,23 +638,20 @@ static const char *snd_es1688_chip_id(struct snd_es1688 *chip)
 }
 
 int snd_es1688_create(struct snd_card *card,
+                     struct snd_es1688 *chip,
                      unsigned long port,
                      unsigned long mpu_port,
                      int irq,
                      int mpu_irq,
                      int dma8,
-                     unsigned short hardware,
-                     struct snd_es1688 **rchip)
+                     unsigned short hardware)
 {
        static struct snd_device_ops ops = {
                .dev_free =     snd_es1688_dev_free,
        };
                                 
-       struct snd_es1688 *chip;
        int err;
 
-       *rchip = NULL;
-       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
        if (chip == NULL)
                return -ENOMEM;
        chip->irq = -1;
@@ -662,25 +659,21 @@ int snd_es1688_create(struct snd_card *card,
        
        if ((chip->res_port = request_region(port + 4, 12, "ES1688")) == NULL) {
                snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4);
-               snd_es1688_free(chip);
                return -EBUSY;
        }
        if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) {
                snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq);
-               snd_es1688_free(chip);
                return -EBUSY;
        }
        chip->irq = irq;
        if (request_dma(dma8, "ES1688")) {
                snd_printk(KERN_ERR "es1688: can't grab DMA8 %d\n", dma8);
-               snd_es1688_free(chip);
                return -EBUSY;
        }
        chip->dma8 = dma8;
 
        spin_lock_init(&chip->reg_lock);
        spin_lock_init(&chip->mixer_lock);
-       chip->card = card;
        chip->port = port;
        mpu_port &= ~0x000f;
        if (mpu_port < 0x300 || mpu_port > 0x330)
@@ -689,23 +682,16 @@ int snd_es1688_create(struct snd_card *card,
        chip->mpu_irq = mpu_irq;
        chip->hardware = hardware;
 
-       if ((err = snd_es1688_probe(chip)) < 0) {
-               snd_es1688_free(chip);
+       err = snd_es1688_probe(chip);
+       if (err < 0)
                return err;
-       }
-       if ((err = snd_es1688_init(chip, 1)) < 0) {
-               snd_es1688_free(chip);
-               return err;
-       }
 
-       /* Register device */
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
-               snd_es1688_free(chip);
+       err = snd_es1688_init(chip, 1);
+       if (err < 0)
                return err;
-       }
 
-       *rchip = chip;
-       return 0;
+       /* Register device */
+       return snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 }
 
 static struct snd_pcm_ops snd_es1688_playback_ops = {
@@ -730,12 +716,14 @@ static struct snd_pcm_ops snd_es1688_capture_ops = {
        .pointer =              snd_es1688_capture_pointer,
 };
 
-int snd_es1688_pcm(struct snd_es1688 * chip, int device, struct snd_pcm ** rpcm)
+int snd_es1688_pcm(struct snd_card *card, struct snd_es1688 *chip,
+                  int device, struct snd_pcm **rpcm)
 {
        struct snd_pcm *pcm;
        int err;
 
-       if ((err = snd_pcm_new(chip->card, "ESx688", device, 1, 1, &pcm)) < 0)
+       err = snd_pcm_new(card, "ESx688", device, 1, 1, &pcm);
+       if (err < 0)
                return err;
 
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1688_playback_ops);
@@ -1009,18 +997,15 @@ static unsigned char snd_es1688_init_table[][2] = {
        { ES1688_REC_DEV, 0x17 }
 };
                                         
-int snd_es1688_mixer(struct snd_es1688 *chip)
+int snd_es1688_mixer(struct snd_card *card, struct snd_es1688 *chip)
 {
-       struct snd_card *card;
        unsigned int idx;
        int err;
        unsigned char reg, val;
 
-       if (snd_BUG_ON(!chip || !chip->card))
+       if (snd_BUG_ON(!chip || !card))
                return -EINVAL;
 
-       card = chip->card;
-
        strcpy(card->mixername, snd_es1688_chip_id(chip));
 
        for (idx = 0; idx < ARRAY_SIZE(snd_es1688_controls); idx++) {
index 2803e22..2ccb3fa 100644 (file)
@@ -31,52 +31,21 @@ struct gus_proc_private {
        struct snd_gus_card * gus;
 };
 
-static long snd_gf1_mem_proc_dump(struct snd_info_entry *entry, void *file_private_data,
-                                 struct file *file, char __user *buf,
-                                 unsigned long count, unsigned long pos)
+static ssize_t snd_gf1_mem_proc_dump(struct snd_info_entry *entry,
+                                    void *file_private_data,
+                                    struct file *file, char __user *buf,
+                                    size_t count, loff_t pos)
 {
-       long size;
        struct gus_proc_private *priv = entry->private_data;
        struct snd_gus_card *gus = priv->gus;
        int err;
 
-       size = count;
-       if (pos + size > priv->size)
-               size = (long)priv->size - pos;
-       if (size > 0) {
-               if ((err = snd_gus_dram_read(gus, buf, pos, size, priv->rom)) < 0)
-                       return err;
-               return size;
-       }
-       return 0;
+       err = snd_gus_dram_read(gus, buf, pos, count, priv->rom);
+       if (err < 0)
+               return err;
+       return count;
 }                      
 
-static long long snd_gf1_mem_proc_llseek(struct snd_info_entry *entry,
-                                       void *private_file_data,
-                                       struct file *file,
-                                       long long offset,
-                                       int orig)
-{
-       struct gus_proc_private *priv = entry->private_data;
-
-       switch (orig) {
-       case SEEK_SET:
-               file->f_pos = offset;
-               break;
-       case SEEK_CUR:
-               file->f_pos += offset;
-               break;
-       case SEEK_END: /* offset is negative */
-               file->f_pos = priv->size + offset;
-               break;
-       default:
-               return -EINVAL;
-       }
-       if (file->f_pos > priv->size)
-               file->f_pos = priv->size;
-       return file->f_pos;
-}
-
 static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
 {
        struct gus_proc_private *priv = entry->private_data;
@@ -85,7 +54,6 @@ static void snd_gf1_mem_proc_free(struct snd_info_entry *entry)
 
 static struct snd_info_entry_ops snd_gf1_mem_proc_ops = {
        .read = snd_gf1_mem_proc_dump,
-       .llseek = snd_gf1_mem_proc_llseek,
 };
 
 int snd_gf1_mem_proc_init(struct snd_gus_card * gus)
index 65e4b18..008e8e5 100644 (file)
@@ -95,7 +95,7 @@ static int __devinit snd_gusextreme_match(struct device *dev, unsigned int n)
 }
 
 static int __devinit snd_gusextreme_es1688_create(struct snd_card *card,
-               struct device *dev, unsigned int n, struct snd_es1688 **rchip)
+               struct snd_es1688 *chip, struct device *dev, unsigned int n)
 {
        static long possible_ports[] = {0x220, 0x240, 0x260};
        static int possible_irqs[] = {5, 9, 10, 7, -1};
@@ -119,14 +119,14 @@ static int __devinit snd_gusextreme_es1688_create(struct snd_card *card,
        }
 
        if (port[n] != SNDRV_AUTO_PORT)
-               return snd_es1688_create(card, port[n], mpu_port[n], irq[n],
-                               mpu_irq[n], dma8[n], ES1688_HW_1688, rchip);
+               return snd_es1688_create(card, chip, port[n], mpu_port[n],
+                               irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688);
 
        i = 0;
        do {
                port[n] = possible_ports[i];
-               error = snd_es1688_create(card, port[n], mpu_port[n], irq[n],
-                               mpu_irq[n], dma8[n], ES1688_HW_1688, rchip);
+               error = snd_es1688_create(card, chip, port[n], mpu_port[n],
+                               irq[n], mpu_irq[n], dma8[n], ES1688_HW_1688);
        } while (error < 0 && ++i < ARRAY_SIZE(possible_ports));
 
        return error;
@@ -206,9 +206,8 @@ static int __devinit snd_gusextreme_detect(struct snd_gus_card *gus,
        return 0;
 }
 
-static int __devinit snd_gusextreme_mixer(struct snd_es1688 *chip)
+static int __devinit snd_gusextreme_mixer(struct snd_card *card)
 {
-       struct snd_card *card = chip->card;
        struct snd_ctl_elem_id id1, id2;
        int error;
 
@@ -241,17 +240,20 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
        struct snd_opl3 *opl3;
        int error;
 
-       error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
+       error = snd_card_create(index[n], id[n], THIS_MODULE,
+                               sizeof(struct snd_es1688), &card);
        if (error < 0)
                return error;
 
+       es1688 = card->private_data;
+
        if (mpu_port[n] == SNDRV_AUTO_PORT)
                mpu_port[n] = 0;
 
        if (mpu_irq[n] > 15)
                mpu_irq[n] = -1;
 
-       error = snd_gusextreme_es1688_create(card, dev, n, &es1688);
+       error = snd_gusextreme_es1688_create(card, es1688, dev, n);
        if (error < 0)
                goto out;
 
@@ -280,11 +282,11 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
        }
        gus->codec_flag = 1;
 
-       error = snd_es1688_pcm(es1688, 0, NULL);
+       error = snd_es1688_pcm(card, es1688, 0, NULL);
        if (error < 0)
                goto out;
 
-       error = snd_es1688_mixer(es1688);
+       error = snd_es1688_mixer(card, es1688);
        if (error < 0)
                goto out;
 
@@ -300,7 +302,7 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
        if (error < 0)
                goto out;
 
-       error = snd_gusextreme_mixer(es1688);
+       error = snd_gusextreme_mixer(card);
        if (error < 0)
                goto out;
 
index af36696..08b9fb9 100644 (file)
@@ -11,7 +11,6 @@ snd-sb8-objs := sb8.o
 snd-sb16-objs := sb16.o
 snd-sbawe-objs := sbawe.o emu8000.o
 snd-emu8000-synth-objs := emu8000_synth.o emu8000_callback.o emu8000_patch.o emu8000_pcm.o
-snd-es968-objs := es968.o
 snd-jazz16-objs := jazz16.o
 
 # Toplevel Module Dependency
@@ -21,7 +20,6 @@ obj-$(CONFIG_SND_SB8_DSP) += snd-sb8-dsp.o
 obj-$(CONFIG_SND_SB8) += snd-sb8.o
 obj-$(CONFIG_SND_SB16) += snd-sb16.o
 obj-$(CONFIG_SND_SBAWE) += snd-sbawe.o
-obj-$(CONFIG_SND_ES968) += snd-es968.o
 obj-$(CONFIG_SND_JAZZ16) += snd-jazz16.o
 ifeq ($(CONFIG_SND_SB16_CSP),y)
   obj-$(CONFIG_SND_SB16) += snd-sb16-csp.o
diff --git a/sound/isa/sb/es968.c b/sound/isa/sb/es968.c
deleted file mode 100644 (file)
index ff18286..0000000
+++ /dev/null
@@ -1,248 +0,0 @@
-
-/*
-    card-es968.c - driver for ESS AudioDrive ES968 based soundcards.
-    Copyright (C) 1999 by Massimo Piccioni <dafastidio@libero.it>
-
-    Thanks to Pierfrancesco 'qM2' Passerini.
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-*/
-
-#include <linux/init.h>
-#include <linux/time.h>
-#include <linux/pnp.h>
-#include <linux/moduleparam.h>
-#include <sound/core.h>
-#include <sound/initval.h>
-#include <sound/sb.h>
-
-#define PFX "es968: "
-
-MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
-MODULE_DESCRIPTION("ESS AudioDrive ES968");
-MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{ESS,AudioDrive ES968}}");
-
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
-static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* PnP setup */
-static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;       /* Pnp setup */
-static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* PnP setup */
-
-module_param_array(index, int, NULL, 0444);
-MODULE_PARM_DESC(index, "Index value for es968 based soundcard.");
-module_param_array(id, charp, NULL, 0444);
-MODULE_PARM_DESC(id, "ID string for es968 based soundcard.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable es968 based soundcard.");
-
-struct snd_card_es968 {
-       struct pnp_dev *dev;
-       struct snd_sb *chip;
-};
-
-static struct pnp_card_device_id snd_es968_pnpids[] = {
-       { .id = "ESS0968", .devs = { { "@@@0968" }, } },
-       { .id = "", } /* end */
-};
-
-MODULE_DEVICE_TABLE(pnp_card, snd_es968_pnpids);
-
-#define        DRIVER_NAME     "snd-card-es968"
-
-static irqreturn_t snd_card_es968_interrupt(int irq, void *dev_id)
-{
-       struct snd_sb *chip = dev_id;
-
-       if (chip->open & SB_OPEN_PCM) {
-               return snd_sb8dsp_interrupt(chip);
-       } else {
-               return snd_sb8dsp_midi_interrupt(chip);
-       }
-}
-
-static int __devinit snd_card_es968_pnp(int dev, struct snd_card_es968 *acard,
-                                       struct pnp_card_link *card,
-                                       const struct pnp_card_device_id *id)
-{
-       struct pnp_dev *pdev;
-       int err;
-
-       acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
-       if (acard->dev == NULL)
-               return -ENODEV;
-
-       pdev = acard->dev;
-
-       err = pnp_activate_dev(pdev);
-       if (err < 0) {
-               snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
-               return err;
-       }
-       port[dev] = pnp_port_start(pdev, 0);
-       dma8[dev] = pnp_dma(pdev, 0);
-       irq[dev] = pnp_irq(pdev, 0);
-
-       return 0;
-}
-
-static int __devinit snd_card_es968_probe(int dev,
-                                       struct pnp_card_link *pcard,
-                                       const struct pnp_card_device_id *pid)
-{
-       int error;
-       struct snd_sb *chip;
-       struct snd_card *card;
-       struct snd_card_es968 *acard;
-
-       error = snd_card_create(index[dev], id[dev], THIS_MODULE,
-                               sizeof(struct snd_card_es968), &card);
-       if (error < 0)
-               return error;
-       acard = card->private_data;
-       if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
-               snd_card_free(card);
-               return error;
-       }
-       snd_card_set_dev(card, &pcard->card->dev);
-
-       if ((error = snd_sbdsp_create(card, port[dev],
-                                     irq[dev],
-                                     snd_card_es968_interrupt,
-                                     dma8[dev],
-                                     -1,
-                                     SB_HW_AUTO, &chip)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-       acard->chip = chip;
-
-       if ((error = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-
-       if ((error = snd_sbmixer_new(chip)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-
-       if ((error = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-
-       strcpy(card->driver, "ES968");
-       strcpy(card->shortname, "ESS ES968");
-       sprintf(card->longname, "%s soundcard, %s at 0x%lx, irq %d, dma %d",
-               card->shortname, chip->name, chip->port, irq[dev], dma8[dev]);
-
-       if ((error = snd_card_register(card)) < 0) {
-               snd_card_free(card);
-               return error;
-       }
-       pnp_set_card_drvdata(pcard, card);
-       return 0;
-}
-
-static unsigned int __devinitdata es968_devices;
-
-static int __devinit snd_es968_pnp_detect(struct pnp_card_link *card,
-                                          const struct pnp_card_device_id *id)
-{
-       static int dev;
-       int res;
-
-       for ( ; dev < SNDRV_CARDS; dev++) {
-               if (!enable[dev])
-                       continue;
-               res = snd_card_es968_probe(dev, card, id);
-               if (res < 0)
-                       return res;
-               dev++;
-               es968_devices++;
-               return 0;
-       }
-       return -ENODEV;
-}
-
-static void __devexit snd_es968_pnp_remove(struct pnp_card_link * pcard)
-{
-       snd_card_free(pnp_get_card_drvdata(pcard));
-       pnp_set_card_drvdata(pcard, NULL);
-}
-
-#ifdef CONFIG_PM
-static int snd_es968_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
-{
-       struct snd_card *card = pnp_get_card_drvdata(pcard);
-       struct snd_card_es968 *acard = card->private_data;
-       struct snd_sb *chip = acard->chip;
-
-       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       snd_pcm_suspend_all(chip->pcm);
-       snd_sbmixer_suspend(chip);
-       return 0;
-}
-
-static int snd_es968_pnp_resume(struct pnp_card_link *pcard)
-{
-       struct snd_card *card = pnp_get_card_drvdata(pcard);
-       struct snd_card_es968 *acard = card->private_data;
-       struct snd_sb *chip = acard->chip;
-
-       snd_sbdsp_reset(chip);
-       snd_sbmixer_resume(chip);
-       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
-       return 0;
-}
-#endif
-
-static struct pnp_card_driver es968_pnpc_driver = {
-       .flags          = PNP_DRIVER_RES_DISABLE,
-       .name           = "es968",
-       .id_table       = snd_es968_pnpids,
-       .probe          = snd_es968_pnp_detect,
-       .remove         = __devexit_p(snd_es968_pnp_remove),
-#ifdef CONFIG_PM
-       .suspend        = snd_es968_pnp_suspend,
-       .resume         = snd_es968_pnp_resume,
-#endif
-};
-
-static int __init alsa_card_es968_init(void)
-{
-       int err = pnp_register_card_driver(&es968_pnpc_driver);
-       if (err)
-               return err;
-
-       if (!es968_devices) {
-               pnp_unregister_card_driver(&es968_pnpc_driver);
-#ifdef MODULE
-               snd_printk(KERN_ERR "no ES968 based soundcards found\n");
-#endif
-               return -ENODEV;
-       }
-       return 0;
-}
-
-static void __exit alsa_card_es968_exit(void)
-{
-       pnp_unregister_card_driver(&es968_pnpc_driver);
-}
-
-module_init(alsa_card_es968_init)
-module_exit(alsa_card_es968_exit)
index bb14e4c..87910e9 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/ioport.h>
 #include <linux/soundcard.h>
 #include <linux/interrupt.h>
+#include <linux/platform_device.h>
 
 #include <asm/uaccess.h>
 #include <asm/setup.h>
@@ -710,31 +711,41 @@ static MACHINE machAmiga = {
 /*** Config & Setup **********************************************************/
 
 
-static int __init dmasound_paula_init(void)
+static int __init amiga_audio_probe(struct platform_device *pdev)
 {
-       int err;
-
-       if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_AUDIO)) {
-           if (!request_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40,
-                                   "dmasound [Paula]"))
-               return -EBUSY;
-           dmasound.mach = machAmiga;
-           dmasound.mach.default_hard = def_hard ;
-           dmasound.mach.default_soft = def_soft ;
-           err = dmasound_init();
-           if (err)
-               release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
-           return err;
-       } else
-           return -ENODEV;
+       dmasound.mach = machAmiga;
+       dmasound.mach.default_hard = def_hard ;
+       dmasound.mach.default_soft = def_soft ;
+       return dmasound_init();
 }
 
-static void __exit dmasound_paula_cleanup(void)
+static int __exit amiga_audio_remove(struct platform_device *pdev)
 {
        dmasound_deinit();
-       release_mem_region(CUSTOM_PHYSADDR+0xa0, 0x40);
+       return 0;
+}
+
+static struct platform_driver amiga_audio_driver = {
+       .remove = __exit_p(amiga_audio_remove),
+       .driver   = {
+               .name   = "amiga-audio",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init amiga_audio_init(void)
+{
+       return platform_driver_probe(&amiga_audio_driver, amiga_audio_probe);
 }
 
-module_init(dmasound_paula_init);
-module_exit(dmasound_paula_cleanup);
+module_init(amiga_audio_init);
+
+static void __exit amiga_audio_exit(void)
+{
+       platform_driver_unregister(&amiga_audio_driver);
+}
+
+module_exit(amiga_audio_exit);
+
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:amiga-audio");
index 1298c68..e7a8cd0 100644 (file)
@@ -58,6 +58,18 @@ config SND_ALI5451
          To compile this driver as a module, choose M here: the module
          will be called snd-ali5451.
 
+config SND_ASIHPI
+       tristate "AudioScience ASIxxxx"
+       depends on X86
+       select FW_LOADER
+       select SND_PCM
+       select SND_HWDEP
+       help
+         Say Y here to include support for AudioScience ASI sound cards.
+
+         To compile this driver as a module, choose M here: the module
+         will be called snd-asihpi.
+
 config SND_ATIIXP
        tristate "ATI IXP AC97 Controller"
        select SND_AC97_CODEC
@@ -501,6 +513,16 @@ config SND_ES1968
          To compile this driver as a module, choose M here: the module
          will be called snd-es1968.
 
+config SND_ES1968_INPUT
+       bool "Enable input device for es1968 volume buttons"
+       depends on SND_ES1968
+       depends on INPUT=y || INPUT=SND_ES1968
+       help
+         If you say Y here, you will get an input device which reports
+         keypresses for the volume buttons connected to the es1968 chip.
+         If you say N the buttons will directly control the master volume.
+         It is recommended to say Y.
+
 config SND_FM801
        tristate "ForteMedia FM801"
        select SND_OPL3_LIB
@@ -655,6 +677,16 @@ config SND_MAESTRO3
          To compile this driver as a module, choose M here: the module
          will be called snd-maestro3.
 
+config SND_MAESTRO3_INPUT
+       bool "Enable input device for maestro3 volume buttons"
+       depends on SND_MAESTRO3
+       depends on INPUT=y || INPUT=SND_MAESTRO3
+       help
+         If you say Y here, you will get an input device which reports
+         keypresses for the volume buttons connected to the maestro3 chip.
+         If you say N the buttons will directly control the master volume.
+         It is recommended to say Y.
+
 config SND_MIXART
        tristate "Digigram miXart"
        select SND_HWDEP
index ecfc609..9cf4348 100644 (file)
@@ -57,6 +57,7 @@ obj-$(CONFIG_SND_VIA82XX_MODEM) += snd-via82xx-modem.o
 obj-$(CONFIG_SND) += \
        ac97/ \
        ali5451/ \
+       asihpi/ \
        au88x0/ \
        aw2/ \
        ctxfi/ \
diff --git a/sound/pci/asihpi/Makefile b/sound/pci/asihpi/Makefile
new file mode 100644 (file)
index 0000000..391830a
--- /dev/null
@@ -0,0 +1,5 @@
+snd-asihpi-objs := asihpi.o hpioctl.o hpimsginit.o\
+       hpicmn.o hpifunc.o hpidebug.o hpidspcd.o\
+       hpios.o hpi6000.o hpi6205.o hpimsgx.o
+
+obj-$(CONFIG_SND_ASIHPI) += snd-asihpi.o
diff --git a/sound/pci/asihpi/asihpi.c b/sound/pci/asihpi/asihpi.c
new file mode 100644 (file)
index 0000000..f74c737
--- /dev/null
@@ -0,0 +1,3002 @@
+/*
+ *  Asihpi soundcard
+ *  Copyright (c) by AudioScience Inc <alsa@audioscience.com>
+ *
+ *   This program 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;
+ *
+ *   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
+ *
+ *
+ *  The following is not a condition of use, merely a request:
+ *  If you modify this program, particularly if you fix errors, AudioScience Inc
+ *  would appreciate it if you grant us the right to use those modifications
+ *  for any purpose including commercial applications.
+ */
+/* >0: print Hw params, timer vars. >1: print stream write/copy sizes  */
+#define REALLY_VERBOSE_LOGGING 0
+
+#if REALLY_VERBOSE_LOGGING
+#define VPRINTK1 snd_printd
+#else
+#define VPRINTK1(...)
+#endif
+
+#if REALLY_VERBOSE_LOGGING > 1
+#define VPRINTK2 snd_printd
+#else
+#define VPRINTK2(...)
+#endif
+
+#ifndef ASI_STYLE_NAMES
+/* not sure how ALSA style name should look */
+#define ASI_STYLE_NAMES 1
+#endif
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+#include "hpioctl.h"
+
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/jiffies.h>
+#include <linux/slab.h>
+#include <linux/time.h>
+#include <linux/wait.h>
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/info.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+#include <sound/hwdep.h>
+
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
+MODULE_DESCRIPTION("AudioScience ALSA ASI5000 ASI6000 ASI87xx ASI89xx");
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
+static int enable_hpi_hwdep = 1;
+
+module_param_array(index, int, NULL, S_IRUGO);
+MODULE_PARM_DESC(index, "ALSA index value for AudioScience soundcard.");
+
+module_param_array(id, charp, NULL, S_IRUGO);
+MODULE_PARM_DESC(id, "ALSA ID string for AudioScience soundcard.");
+
+module_param_array(enable, bool, NULL, S_IRUGO);
+MODULE_PARM_DESC(enable, "ALSA enable AudioScience soundcard.");
+
+module_param(enable_hpi_hwdep, bool, S_IRUGO|S_IWUSR);
+MODULE_PARM_DESC(enable_hpi_hwdep,
+               "ALSA enable HPI hwdep for AudioScience soundcard ");
+
+/* identify driver */
+#ifdef KERNEL_ALSA_BUILD
+static char *build_info = "built using headers from kernel source";
+module_param(build_info, charp, S_IRUGO);
+MODULE_PARM_DESC(build_info, "built using headers from kernel source");
+#else
+static char *build_info = "built within ALSA source";
+module_param(build_info, charp, S_IRUGO);
+MODULE_PARM_DESC(build_info, "built within ALSA source");
+#endif
+
+/* set to 1 to dump every control from adapter to log */
+static const int mixer_dump;
+
+#define DEFAULT_SAMPLERATE 44100
+static int adapter_fs = DEFAULT_SAMPLERATE;
+
+static struct hpi_hsubsys *ss; /* handle to HPI audio subsystem */
+
+/* defaults */
+#define PERIODS_MIN 2
+#define PERIOD_BYTES_MIN  2304
+#define BUFFER_BYTES_MAX (512 * 1024)
+
+/*#define TIMER_MILLISECONDS 20
+#define FORCE_TIMER_JIFFIES ((TIMER_MILLISECONDS * HZ + 999)/1000)
+*/
+
+#define MAX_CLOCKSOURCES (HPI_SAMPLECLOCK_SOURCE_LAST + 1 + 7)
+
+struct clk_source {
+       int source;
+       int index;
+       char *name;
+};
+
+struct clk_cache {
+       int count;
+       int has_local;
+       struct clk_source s[MAX_CLOCKSOURCES];
+};
+
+/* Per card data */
+struct snd_card_asihpi {
+       struct snd_card *card;
+       struct pci_dev *pci;
+       u16 adapter_index;
+       u32 serial_number;
+       u16 type;
+       u16 version;
+       u16 num_outstreams;
+       u16 num_instreams;
+
+       u32 h_mixer;
+       struct clk_cache cc;
+
+       u16 support_mmap;
+       u16 support_grouping;
+       u16 support_mrx;
+       u16 update_interval_frames;
+       u16 in_max_chans;
+       u16 out_max_chans;
+};
+
+/* Per stream data */
+struct snd_card_asihpi_pcm {
+       struct timer_list timer;
+       unsigned int respawn_timer;
+       unsigned int hpi_buffer_attached;
+       unsigned int pcm_size;
+       unsigned int pcm_count;
+       unsigned int bytes_per_sec;
+       unsigned int pcm_irq_pos;       /* IRQ position */
+       unsigned int pcm_buf_pos;       /* position in buffer */
+       struct snd_pcm_substream *substream;
+       u32 h_stream;
+       struct hpi_format format;
+};
+
+/* universal stream verbs work with out or in stream handles */
+
+/* Functions to allow driver to give a buffer to HPI for busmastering */
+
+static u16 hpi_stream_host_buffer_attach(
+       struct hpi_hsubsys *hS,
+       u32 h_stream,   /* handle to outstream. */
+       u32 size_in_bytes, /* size in bytes of bus mastering buffer */
+       u32 pci_address
+)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       unsigned int obj = hpi_handle_object(h_stream);
+
+       if (!h_stream)
+               return HPI_ERROR_INVALID_OBJ;
+       hpi_init_message_response(&hm, &hr, obj,
+                       obj == HPI_OBJ_OSTREAM ?
+                               HPI_OSTREAM_HOSTBUFFER_ALLOC :
+                               HPI_ISTREAM_HOSTBUFFER_ALLOC);
+
+       hpi_handle_to_indexes(h_stream, &hm.adapter_index,
+                               &hm.obj_index);
+
+       hm.u.d.u.buffer.buffer_size = size_in_bytes;
+       hm.u.d.u.buffer.pci_address = pci_address;
+       hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+static u16 hpi_stream_host_buffer_detach(
+       struct hpi_hsubsys *hS,
+       u32  h_stream
+)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       unsigned int obj = hpi_handle_object(h_stream);
+
+       if (!h_stream)
+               return HPI_ERROR_INVALID_OBJ;
+
+       hpi_init_message_response(&hm, &hr,  obj,
+                       obj == HPI_OBJ_OSTREAM ?
+                               HPI_OSTREAM_HOSTBUFFER_FREE :
+                               HPI_ISTREAM_HOSTBUFFER_FREE);
+
+       hpi_handle_to_indexes(h_stream, &hm.adapter_index,
+                               &hm.obj_index);
+       hm.u.d.u.buffer.command = HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+static inline u16 hpi_stream_start(struct hpi_hsubsys *hS, u32 h_stream)
+{
+       if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_start(hS, h_stream);
+       else
+               return hpi_instream_start(hS, h_stream);
+}
+
+static inline u16 hpi_stream_stop(struct hpi_hsubsys *hS, u32 h_stream)
+{
+       if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_stop(hS, h_stream);
+       else
+               return hpi_instream_stop(hS, h_stream);
+}
+
+static inline u16 hpi_stream_get_info_ex(
+    struct hpi_hsubsys *hS,
+    u32 h_stream,
+    u16        *pw_state,
+    u32        *pbuffer_size,
+    u32        *pdata_in_buffer,
+    u32        *psample_count,
+    u32        *pauxiliary_data
+)
+{
+       if (hpi_handle_object(h_stream)  ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_get_info_ex(hS, h_stream, pw_state,
+                                       pbuffer_size, pdata_in_buffer,
+                                       psample_count, pauxiliary_data);
+       else
+               return hpi_instream_get_info_ex(hS, h_stream, pw_state,
+                                       pbuffer_size, pdata_in_buffer,
+                                       psample_count, pauxiliary_data);
+}
+
+static inline u16 hpi_stream_group_add(struct hpi_hsubsys *hS,
+                                       u32 h_master,
+                                       u32 h_stream)
+{
+       if (hpi_handle_object(h_master) ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_group_add(hS, h_master, h_stream);
+       else
+               return hpi_instream_group_add(hS, h_master, h_stream);
+}
+
+static inline u16 hpi_stream_group_reset(struct hpi_hsubsys *hS,
+                                               u32 h_stream)
+{
+       if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_group_reset(hS, h_stream);
+       else
+               return hpi_instream_group_reset(hS, h_stream);
+}
+
+static inline u16 hpi_stream_group_get_map(struct hpi_hsubsys *hS,
+                               u32 h_stream, u32 *mo, u32 *mi)
+{
+       if (hpi_handle_object(h_stream) ==  HPI_OBJ_OSTREAM)
+               return hpi_outstream_group_get_map(hS, h_stream, mo, mi);
+       else
+               return hpi_instream_group_get_map(hS, h_stream, mo, mi);
+}
+
+static u16 handle_error(u16 err, int line, char *filename)
+{
+       if (err)
+               printk(KERN_WARNING
+                       "in file %s, line %d: HPI error %d\n",
+                       filename, line, err);
+       return err;
+}
+
+#define hpi_handle_error(x)  handle_error(x, __LINE__, __FILE__)
+
+/***************************** GENERAL PCM ****************/
+#if REALLY_VERBOSE_LOGGING
+static void print_hwparams(struct snd_pcm_hw_params *p)
+{
+       snd_printd("HWPARAMS \n");
+       snd_printd("samplerate %d \n", params_rate(p));
+       snd_printd("channels %d \n", params_channels(p));
+       snd_printd("format %d \n", params_format(p));
+       snd_printd("subformat %d \n", params_subformat(p));
+       snd_printd("buffer bytes %d \n", params_buffer_bytes(p));
+       snd_printd("period bytes %d \n", params_period_bytes(p));
+       snd_printd("access %d \n", params_access(p));
+       snd_printd("period_size %d \n", params_period_size(p));
+       snd_printd("periods %d \n", params_periods(p));
+       snd_printd("buffer_size %d \n", params_buffer_size(p));
+}
+#else
+#define print_hwparams(x)
+#endif
+
+static snd_pcm_format_t hpi_to_alsa_formats[] = {
+       -1,                     /* INVALID */
+       SNDRV_PCM_FORMAT_U8,    /* HPI_FORMAT_PCM8_UNSIGNED        1 */
+       SNDRV_PCM_FORMAT_S16,   /* HPI_FORMAT_PCM16_SIGNED         2 */
+       -1,                     /* HPI_FORMAT_MPEG_L1              3 */
+       SNDRV_PCM_FORMAT_MPEG,  /* HPI_FORMAT_MPEG_L2              4 */
+       SNDRV_PCM_FORMAT_MPEG,  /* HPI_FORMAT_MPEG_L3              5 */
+       -1,                     /* HPI_FORMAT_DOLBY_AC2            6 */
+       -1,                     /* HPI_FORMAT_DOLBY_AC3            7 */
+       SNDRV_PCM_FORMAT_S16_BE,/* HPI_FORMAT_PCM16_BIGENDIAN      8 */
+       -1,                     /* HPI_FORMAT_AA_TAGIT1_HITS       9 */
+       -1,                     /* HPI_FORMAT_AA_TAGIT1_INSERTS   10 */
+       SNDRV_PCM_FORMAT_S32,   /* HPI_FORMAT_PCM32_SIGNED        11 */
+       -1,                     /* HPI_FORMAT_RAW_BITSTREAM       12 */
+       -1,                     /* HPI_FORMAT_AA_TAGIT1_HITS_EX1  13 */
+       SNDRV_PCM_FORMAT_FLOAT, /* HPI_FORMAT_PCM32_FLOAT         14 */
+#if 1
+       /* ALSA can't handle 3 byte sample size together with power-of-2
+        *  constraint on buffer_bytes, so disable this format
+        */
+       -1
+#else
+       /* SNDRV_PCM_FORMAT_S24_3LE */  /* { HPI_FORMAT_PCM24_SIGNED        15 */
+#endif
+};
+
+
+static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
+                                          u16 *hpi_format)
+{
+       u16 format;
+
+       for (format = HPI_FORMAT_PCM8_UNSIGNED;
+            format <= HPI_FORMAT_PCM24_SIGNED; format++) {
+               if (hpi_to_alsa_formats[format] == alsa_format) {
+                       *hpi_format = format;
+                       return 0;
+               }
+       }
+
+       snd_printd(KERN_WARNING "failed match for alsa format %d\n",
+                  alsa_format);
+       *hpi_format = 0;
+       return -EINVAL;
+}
+
+static void snd_card_asihpi_pcm_samplerates(struct snd_card_asihpi *asihpi,
+                                        struct snd_pcm_hardware *pcmhw)
+{
+       u16 err;
+       u32 h_control;
+       u32 sample_rate;
+       int idx;
+       unsigned int rate_min = 200000;
+       unsigned int rate_max = 0;
+       unsigned int rates = 0;
+
+       if (asihpi->support_mrx) {
+               rates |= SNDRV_PCM_RATE_CONTINUOUS;
+               rates |= SNDRV_PCM_RATE_8000_96000;
+               rate_min = 8000;
+               rate_max = 100000;
+       } else {
+               /* on cards without SRC,
+                  valid rates are determined by sampleclock */
+               err = hpi_mixer_get_control(ss, asihpi->h_mixer,
+                                         HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
+                                         HPI_CONTROL_SAMPLECLOCK, &h_control);
+               if (err) {
+                       snd_printk(KERN_ERR
+                               "no local sampleclock, err %d\n", err);
+               }
+
+               for (idx = 0; idx < 100; idx++) {
+                       if (hpi_sample_clock_query_local_rate(ss,
+                               h_control, idx, &sample_rate)) {
+                               if (!idx)
+                                       snd_printk(KERN_ERR
+                                               "local rate query failed\n");
+
+                               break;
+                       }
+
+                       rate_min = min(rate_min, sample_rate);
+                       rate_max = max(rate_max, sample_rate);
+
+                       switch (sample_rate) {
+                       case 5512:
+                               rates |= SNDRV_PCM_RATE_5512;
+                               break;
+                       case 8000:
+                               rates |= SNDRV_PCM_RATE_8000;
+                               break;
+                       case 11025:
+                               rates |= SNDRV_PCM_RATE_11025;
+                               break;
+                       case 16000:
+                               rates |= SNDRV_PCM_RATE_16000;
+                               break;
+                       case 22050:
+                               rates |= SNDRV_PCM_RATE_22050;
+                               break;
+                       case 32000:
+                               rates |= SNDRV_PCM_RATE_32000;
+                               break;
+                       case 44100:
+                               rates |= SNDRV_PCM_RATE_44100;
+                               break;
+                       case 48000:
+                               rates |= SNDRV_PCM_RATE_48000;
+                               break;
+                       case 64000:
+                               rates |= SNDRV_PCM_RATE_64000;
+                               break;
+                       case 88200:
+                               rates |= SNDRV_PCM_RATE_88200;
+                               break;
+                       case 96000:
+                               rates |= SNDRV_PCM_RATE_96000;
+                               break;
+                       case 176400:
+                               rates |= SNDRV_PCM_RATE_176400;
+                               break;
+                       case 192000:
+                               rates |= SNDRV_PCM_RATE_192000;
+                               break;
+                       default: /* some other rate */
+                               rates |= SNDRV_PCM_RATE_KNOT;
+                       }
+               }
+       }
+
+       /* printk(KERN_INFO "Supported rates %X %d %d\n",
+          rates, rate_min, rate_max); */
+       pcmhw->rates = rates;
+       pcmhw->rate_min = rate_min;
+       pcmhw->rate_max = rate_max;
+}
+
+static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
+                                        struct snd_pcm_hw_params *params)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
+       int err;
+       u16 format;
+       unsigned int bytes_per_sec;
+
+       print_hwparams(params);
+       err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
+       if (err < 0)
+               return err;
+       err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format);
+       if (err)
+               return err;
+
+       VPRINTK1(KERN_INFO "format %d, %d chans, %d_hz\n",
+                               format, params_channels(params),
+                               params_rate(params));
+
+       hpi_handle_error(hpi_format_create(&dpcm->format,
+                       params_channels(params),
+                       format, params_rate(params), 0, 0));
+
+       if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
+               if (hpi_instream_reset(ss, dpcm->h_stream) != 0)
+                       return -EINVAL;
+
+               if (hpi_instream_set_format(ss,
+                       dpcm->h_stream, &dpcm->format) != 0)
+                       return -EINVAL;
+       }
+
+       dpcm->hpi_buffer_attached = 0;
+       if (card->support_mmap) {
+
+               err = hpi_stream_host_buffer_attach(ss, dpcm->h_stream,
+                       params_buffer_bytes(params),  runtime->dma_addr);
+               if (err == 0) {
+                       snd_printd(KERN_INFO
+                               "stream_host_buffer_attach succeeded %u %lu\n",
+                               params_buffer_bytes(params),
+                               (unsigned long)runtime->dma_addr);
+               } else {
+                       snd_printd(KERN_INFO
+                                       "stream_host_buffer_attach error %d\n",
+                                       err);
+                       return -ENOMEM;
+               }
+
+               err = hpi_stream_get_info_ex(ss, dpcm->h_stream, NULL,
+                                               &dpcm->hpi_buffer_attached,
+                                               NULL, NULL, NULL);
+
+               snd_printd(KERN_INFO "stream_host_buffer_attach status 0x%x\n",
+                               dpcm->hpi_buffer_attached);
+       }
+       bytes_per_sec = params_rate(params) * params_channels(params);
+       bytes_per_sec *= snd_pcm_format_width(params_format(params));
+       bytes_per_sec /= 8;
+       if (bytes_per_sec <= 0)
+               return -EINVAL;
+
+       dpcm->bytes_per_sec = bytes_per_sec;
+       dpcm->pcm_size = params_buffer_bytes(params);
+       dpcm->pcm_count = params_period_bytes(params);
+       snd_printd(KERN_INFO "pcm_size=%d, pcm_count=%d, bps=%d\n",
+                       dpcm->pcm_size, dpcm->pcm_count, bytes_per_sec);
+
+       dpcm->pcm_irq_pos = 0;
+       dpcm->pcm_buf_pos = 0;
+       return 0;
+}
+
+static void snd_card_asihpi_pcm_timer_start(struct snd_pcm_substream *
+                                           substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       int expiry;
+
+       expiry = (dpcm->pcm_count * HZ / dpcm->bytes_per_sec);
+       /* wait longer the first time, for samples to propagate */
+       expiry = max(expiry, 20);
+       dpcm->timer.expires = jiffies + expiry;
+       dpcm->respawn_timer = 1;
+       add_timer(&dpcm->timer);
+}
+
+static void snd_card_asihpi_pcm_timer_stop(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       dpcm->respawn_timer = 0;
+       del_timer(&dpcm->timer);
+}
+
+static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
+                                          int cmd)
+{
+       struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
+       struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
+       struct snd_pcm_substream *s;
+       u16 e;
+
+       snd_printd("trigger %dstream %d\n",
+                       substream->stream, substream->number);
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               snd_pcm_group_for_each_entry(s, substream) {
+                       struct snd_card_asihpi_pcm *ds;
+                       ds = s->runtime->private_data;
+
+                       if (snd_pcm_substream_chip(s) != card)
+                               continue;
+
+                       if ((s->stream == SNDRV_PCM_STREAM_PLAYBACK) &&
+                               (card->support_mmap)) {
+                               /* How do I know how much valid data is present
+                               * in buffer? Just guessing 2 periods, but if
+                               * buffer is bigger it may contain even more
+                               * data??
+                               */
+                               unsigned int preload = ds->pcm_count * 2;
+                               VPRINTK2("preload %d\n", preload);
+                               hpi_handle_error(hpi_outstream_write_buf(
+                                               ss, ds->h_stream,
+                                               &s->runtime->dma_area[0],
+                                               preload,
+                                               &ds->format));
+                       }
+
+                       if (card->support_grouping) {
+                               VPRINTK1("\t_group %dstream %d\n", s->stream,
+                                               s->number);
+                               e = hpi_stream_group_add(ss,
+                                       dpcm->h_stream,
+                                       ds->h_stream);
+                               if (!e) {
+                                       snd_pcm_trigger_done(s, substream);
+                               } else {
+                                       hpi_handle_error(e);
+                                       break;
+                               }
+                       } else
+                               break;
+               }
+               snd_printd("start\n");
+               /* start the master stream */
+               snd_card_asihpi_pcm_timer_start(substream);
+               hpi_handle_error(hpi_stream_start(ss, dpcm->h_stream));
+               break;
+
+       case SNDRV_PCM_TRIGGER_STOP:
+               snd_card_asihpi_pcm_timer_stop(substream);
+               snd_pcm_group_for_each_entry(s, substream) {
+                       if (snd_pcm_substream_chip(s) != card)
+                               continue;
+
+                       /*? workaround linked streams don't
+                       transition to SETUP 20070706*/
+                       s->runtime->status->state = SNDRV_PCM_STATE_SETUP;
+
+                       if (card->support_grouping) {
+                               VPRINTK1("\t_group %dstream %d\n", s->stream,
+                                       s->number);
+                               snd_pcm_trigger_done(s, substream);
+                       } else
+                               break;
+               }
+               snd_printd("stop\n");
+
+               /* _prepare and _hwparams reset the stream */
+               hpi_handle_error(hpi_stream_stop(ss, dpcm->h_stream));
+               if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       hpi_handle_error(
+                               hpi_outstream_reset(ss, dpcm->h_stream));
+
+               if (card->support_grouping)
+                       hpi_handle_error(hpi_stream_group_reset(ss,
+                                               dpcm->h_stream));
+               break;
+
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               snd_printd("pause release\n");
+               hpi_handle_error(hpi_stream_start(ss, dpcm->h_stream));
+               snd_card_asihpi_pcm_timer_start(substream);
+               break;
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               snd_printd("pause\n");
+               snd_card_asihpi_pcm_timer_stop(substream);
+               hpi_handle_error(hpi_stream_stop(ss, dpcm->h_stream));
+               break;
+       default:
+               snd_printd("\tINVALID\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int
+snd_card_asihpi_hw_free(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       if (dpcm->hpi_buffer_attached)
+               hpi_stream_host_buffer_detach(ss, dpcm->h_stream);
+
+       snd_pcm_lib_free_pages(substream);
+       return 0;
+}
+
+static void snd_card_asihpi_runtime_free(struct snd_pcm_runtime *runtime)
+{
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       kfree(dpcm);
+}
+
+/*algorithm outline
+ Without linking degenerates to getting single stream pos etc
+ Without mmap 2nd loop degenerates to snd_pcm_period_elapsed
+*/
+/*
+buf_pos=get_buf_pos(s);
+for_each_linked_stream(s) {
+       buf_pos=get_buf_pos(s);
+       min_buf_pos = modulo_min(min_buf_pos, buf_pos, pcm_size)
+       new_data = min(new_data, calc_new_data(buf_pos,irq_pos)
+}
+timer.expires = jiffies + predict_next_period_ready(min_buf_pos);
+for_each_linked_stream(s) {
+       s->buf_pos = min_buf_pos;
+       if (new_data > pcm_count) {
+               if (mmap) {
+                       irq_pos = (irq_pos + pcm_count) % pcm_size;
+                       if (playback) {
+                               write(pcm_count);
+                       } else {
+                               read(pcm_count);
+                       }
+               }
+               snd_pcm_period_elapsed(s);
+       }
+}
+*/
+
+/** Minimum of 2 modulo values.  Works correctly when the difference between
+* the values is less than half the modulus
+*/
+static inline unsigned int modulo_min(unsigned int a, unsigned int b,
+                                       unsigned long int modulus)
+{
+       unsigned int result;
+       if (((a-b) % modulus) < (modulus/2))
+               result = b;
+       else
+               result = a;
+
+       return result;
+}
+
+/** Timer function, equivalent to interrupt service routine for cards
+*/
+static void snd_card_asihpi_timer_function(unsigned long data)
+{
+       struct snd_card_asihpi_pcm *dpcm = (struct snd_card_asihpi_pcm *)data;
+       struct snd_card_asihpi *card = snd_pcm_substream_chip(dpcm->substream);
+       struct snd_pcm_runtime *runtime;
+       struct snd_pcm_substream *s;
+       unsigned int newdata = 0;
+       unsigned int buf_pos, min_buf_pos = 0;
+       unsigned int remdata, xfercount, next_jiffies;
+       int first = 1;
+       u16 state;
+       u32 buffer_size, data_avail, samples_played, aux;
+
+       /* find minimum newdata and buffer pos in group */
+       snd_pcm_group_for_each_entry(s, dpcm->substream) {
+               struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
+               runtime = s->runtime;
+
+               if (snd_pcm_substream_chip(s) != card)
+                       continue;
+
+               hpi_handle_error(hpi_stream_get_info_ex(ss,
+                                       ds->h_stream, &state,
+                                       &buffer_size, &data_avail,
+                                       &samples_played, &aux));
+
+               /* number of bytes in on-card buffer */
+               runtime->delay = aux;
+
+               if (state == HPI_STATE_DRAINED) {
+                       snd_printd(KERN_WARNING  "outstream %d drained\n",
+                                       s->number);
+                       snd_pcm_stop(s, SNDRV_PCM_STATE_XRUN);
+                       return;
+               }
+
+               if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+                       buf_pos = frames_to_bytes(runtime, samples_played);
+               } else {
+                       buf_pos = data_avail + ds->pcm_irq_pos;
+               }
+
+               if (first) {
+                       /* can't statically init min when wrap is involved */
+                       min_buf_pos = buf_pos;
+                       newdata = (buf_pos - ds->pcm_irq_pos) % ds->pcm_size;
+                       first = 0;
+               } else {
+                       min_buf_pos =
+                               modulo_min(min_buf_pos, buf_pos, UINT_MAX+1L);
+                       newdata = min(
+                               (buf_pos - ds->pcm_irq_pos) % ds->pcm_size,
+                               newdata);
+               }
+
+               VPRINTK1("PB timer hw_ptr x%04lX, appl_ptr x%04lX\n",
+                       (unsigned long)frames_to_bytes(runtime,
+                                               runtime->status->hw_ptr),
+                       (unsigned long)frames_to_bytes(runtime,
+                                               runtime->control->appl_ptr));
+               VPRINTK1("%d S=%d, irq=%04X, pos=x%04X, left=x%04X,"
+                       " aux=x%04X space=x%04X\n", s->number,
+                       state,  ds->pcm_irq_pos, buf_pos, (int)data_avail,
+                       (int)aux, buffer_size-data_avail);
+       }
+
+       remdata = newdata % dpcm->pcm_count;
+       xfercount = newdata - remdata; /* a multiple of pcm_count */
+       next_jiffies = ((dpcm->pcm_count-remdata) * HZ / dpcm->bytes_per_sec)+1;
+       next_jiffies = max(next_jiffies, 2U * HZ / 1000U);
+       dpcm->timer.expires = jiffies + next_jiffies;
+       VPRINTK1("jif %d buf pos x%04X newdata x%04X xc x%04X\n",
+                       next_jiffies, min_buf_pos, newdata, xfercount);
+
+       snd_pcm_group_for_each_entry(s, dpcm->substream) {
+               struct snd_card_asihpi_pcm *ds = s->runtime->private_data;
+               ds->pcm_buf_pos = min_buf_pos;
+
+               if (xfercount) {
+                       if (card->support_mmap) {
+                               ds->pcm_irq_pos = ds->pcm_irq_pos + xfercount;
+                               if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+                                       VPRINTK2("write OS%d x%04x\n",
+                                                       s->number,
+                                                       ds->pcm_count);
+                                       hpi_handle_error(
+                                               hpi_outstream_write_buf(
+                                                       ss, ds->h_stream,
+                                                       &s->runtime->
+                                                               dma_area[0],
+                                                       xfercount,
+                                                       &ds->format));
+                               } else {
+                                       VPRINTK2("read IS%d x%04x\n",
+                                               s->number,
+                                               dpcm->pcm_count);
+                                       hpi_handle_error(
+                                               hpi_instream_read_buf(
+                                                       ss, ds->h_stream,
+                                                       NULL, xfercount));
+                               }
+                       } /* else R/W will be handled by read/write callbacks */
+                       snd_pcm_period_elapsed(s);
+               }
+       }
+
+       if (dpcm->respawn_timer)
+               add_timer(&dpcm->timer);
+}
+
+/***************************** PLAYBACK OPS ****************/
+static int snd_card_asihpi_playback_ioctl(struct snd_pcm_substream *substream,
+                                         unsigned int cmd, void *arg)
+{
+       /* snd_printd(KERN_INFO "Playback ioctl %d\n", cmd); */
+       return snd_pcm_lib_ioctl(substream, cmd, arg);
+}
+
+static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
+                                           substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       snd_printd(KERN_INFO "playback prepare %d\n", substream->number);
+
+       hpi_handle_error(hpi_outstream_reset(ss, dpcm->h_stream));
+       dpcm->pcm_irq_pos = 0;
+       dpcm->pcm_buf_pos = 0;
+
+       return 0;
+}
+
+static snd_pcm_uframes_t
+snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       snd_pcm_uframes_t ptr;
+
+       u32 samples_played;
+       u16 err;
+
+       if (!snd_pcm_stream_linked(substream)) {
+               /* NOTE, can use samples played for playback position here and
+               * in timer fn because it LAGS the actual read pointer, and is a
+               * better representation of actual playout position
+               */
+               err = hpi_outstream_get_info_ex(ss, dpcm->h_stream, NULL,
+                                       NULL, NULL,
+                                       &samples_played, NULL);
+               hpi_handle_error(err);
+
+               dpcm->pcm_buf_pos = frames_to_bytes(runtime, samples_played);
+       }
+       /* else must return most conservative value found in timer func
+        * by looping over all streams
+        */
+
+       ptr = bytes_to_frames(runtime, dpcm->pcm_buf_pos  % dpcm->pcm_size);
+       VPRINTK2("playback_pointer=%04ld\n", (unsigned long)ptr);
+       return ptr;
+}
+
+static void snd_card_asihpi_playback_format(struct snd_card_asihpi *asihpi,
+                                               u32 h_stream,
+                                               struct snd_pcm_hardware *pcmhw)
+{
+       struct hpi_format hpi_format;
+       u16 format;
+       u16 err;
+       u32 h_control;
+       u32 sample_rate = 48000;
+
+       /* on cards without SRC, must query at valid rate,
+       * maybe set by external sync
+       */
+       err = hpi_mixer_get_control(ss, asihpi->h_mixer,
+                                 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
+                                 HPI_CONTROL_SAMPLECLOCK, &h_control);
+
+       if (!err)
+               err = hpi_sample_clock_get_sample_rate(ss, h_control,
+                               &sample_rate);
+
+       for (format = HPI_FORMAT_PCM8_UNSIGNED;
+            format <= HPI_FORMAT_PCM24_SIGNED; format++) {
+               err = hpi_format_create(&hpi_format,
+                                       2, format, sample_rate, 128000, 0);
+               if (!err)
+                       err = hpi_outstream_query_format(ss, h_stream,
+                                                       &hpi_format);
+               if (!err && (hpi_to_alsa_formats[format] != -1))
+                       pcmhw->formats |=
+                               (1ULL << hpi_to_alsa_formats[format]);
+       }
+}
+
+static struct snd_pcm_hardware snd_card_asihpi_playback = {
+       .channels_min = 1,
+       .channels_max = 2,
+       .buffer_bytes_max = BUFFER_BYTES_MAX,
+       .period_bytes_min = PERIOD_BYTES_MIN,
+       .period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN,
+       .periods_min = PERIODS_MIN,
+       .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
+       .fifo_size = 0,
+};
+
+static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm;
+       struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
+       int err;
+
+       dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
+       if (dpcm == NULL)
+               return -ENOMEM;
+
+       err =
+           hpi_outstream_open(ss, card->adapter_index,
+                             substream->number, &dpcm->h_stream);
+       hpi_handle_error(err);
+       if (err)
+               kfree(dpcm);
+       if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
+               return -EBUSY;
+       if (err)
+               return -EIO;
+
+       /*? also check ASI5000 samplerate source
+           If external, only support external rate.
+           If internal and other stream playing, cant switch
+       */
+
+       init_timer(&dpcm->timer);
+       dpcm->timer.data = (unsigned long) dpcm;
+       dpcm->timer.function = snd_card_asihpi_timer_function;
+       dpcm->substream = substream;
+       runtime->private_data = dpcm;
+       runtime->private_free = snd_card_asihpi_runtime_free;
+
+       snd_card_asihpi_playback.channels_max = card->out_max_chans;
+       /*?snd_card_asihpi_playback.period_bytes_min =
+       card->out_max_chans * 4096; */
+
+       snd_card_asihpi_playback_format(card, dpcm->h_stream,
+                                       &snd_card_asihpi_playback);
+
+       snd_card_asihpi_pcm_samplerates(card,  &snd_card_asihpi_playback);
+
+       snd_card_asihpi_playback.info = SNDRV_PCM_INFO_INTERLEAVED |
+                                       SNDRV_PCM_INFO_DOUBLE |
+                                       SNDRV_PCM_INFO_BATCH |
+                                       SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                                       SNDRV_PCM_INFO_PAUSE;
+
+       if (card->support_mmap)
+               snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_MMAP |
+                                               SNDRV_PCM_INFO_MMAP_VALID;
+
+       if (card->support_grouping)
+               snd_card_asihpi_playback.info |= SNDRV_PCM_INFO_SYNC_START;
+
+       /* struct is copied, so can create initializer dynamically */
+       runtime->hw = snd_card_asihpi_playback;
+
+       if (card->support_mmap)
+               err = snd_pcm_hw_constraint_pow2(runtime, 0,
+                                       SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
+       if (err < 0)
+               return err;
+
+       snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+               card->update_interval_frames);
+       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+               card->update_interval_frames * 4, UINT_MAX);
+
+       snd_pcm_set_sync(substream);
+
+       snd_printd(KERN_INFO "playback open\n");
+
+       return 0;
+}
+
+static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       hpi_handle_error(hpi_outstream_close(ss, dpcm->h_stream));
+       snd_printd(KERN_INFO "playback close\n");
+
+       return 0;
+}
+
+static int snd_card_asihpi_playback_copy(struct snd_pcm_substream *substream,
+                                       int channel,
+                                       snd_pcm_uframes_t pos,
+                                       void __user *src,
+                                       snd_pcm_uframes_t count)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       unsigned int len;
+
+       len = frames_to_bytes(runtime, count);
+
+       if (copy_from_user(runtime->dma_area, src, len))
+               return -EFAULT;
+
+       VPRINTK2(KERN_DEBUG "playback copy%d %u bytes\n",
+                       substream->number, len);
+
+       hpi_handle_error(hpi_outstream_write_buf(ss, dpcm->h_stream,
+                               runtime->dma_area, len, &dpcm->format));
+
+       return 0;
+}
+
+static int snd_card_asihpi_playback_silence(struct snd_pcm_substream *
+                                           substream, int channel,
+                                           snd_pcm_uframes_t pos,
+                                           snd_pcm_uframes_t count)
+{
+       unsigned int len;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       len = frames_to_bytes(runtime, count);
+       snd_printd(KERN_INFO "playback silence  %u bytes\n", len);
+
+       memset(runtime->dma_area, 0, len);
+       hpi_handle_error(hpi_outstream_write_buf(ss, dpcm->h_stream,
+                               runtime->dma_area, len, &dpcm->format));
+       return 0;
+}
+
+static struct snd_pcm_ops snd_card_asihpi_playback_ops = {
+       .open = snd_card_asihpi_playback_open,
+       .close = snd_card_asihpi_playback_close,
+       .ioctl = snd_card_asihpi_playback_ioctl,
+       .hw_params = snd_card_asihpi_pcm_hw_params,
+       .hw_free = snd_card_asihpi_hw_free,
+       .prepare = snd_card_asihpi_playback_prepare,
+       .trigger = snd_card_asihpi_trigger,
+       .pointer = snd_card_asihpi_playback_pointer,
+       .copy = snd_card_asihpi_playback_copy,
+       .silence = snd_card_asihpi_playback_silence,
+};
+
+static struct snd_pcm_ops snd_card_asihpi_playback_mmap_ops = {
+       .open = snd_card_asihpi_playback_open,
+       .close = snd_card_asihpi_playback_close,
+       .ioctl = snd_card_asihpi_playback_ioctl,
+       .hw_params = snd_card_asihpi_pcm_hw_params,
+       .hw_free = snd_card_asihpi_hw_free,
+       .prepare = snd_card_asihpi_playback_prepare,
+       .trigger = snd_card_asihpi_trigger,
+       .pointer = snd_card_asihpi_playback_pointer,
+};
+
+/***************************** CAPTURE OPS ****************/
+static snd_pcm_uframes_t
+snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       VPRINTK2("capture pointer %d=%d\n",
+                       substream->number, dpcm->pcm_buf_pos);
+       /* NOTE Unlike playback can't use actual dwSamplesPlayed
+               for the capture position, because those samples aren't yet in
+               the local buffer available for reading.
+       */
+       return bytes_to_frames(runtime, dpcm->pcm_buf_pos % dpcm->pcm_size);
+}
+
+static int snd_card_asihpi_capture_ioctl(struct snd_pcm_substream *substream,
+                                        unsigned int cmd, void *arg)
+{
+       return snd_pcm_lib_ioctl(substream, cmd, arg);
+}
+
+static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+
+       hpi_handle_error(hpi_instream_reset(ss, dpcm->h_stream));
+       dpcm->pcm_irq_pos = 0;
+       dpcm->pcm_buf_pos = 0;
+
+       snd_printd("capture prepare %d\n", substream->number);
+       return 0;
+}
+
+
+
+static void snd_card_asihpi_capture_format(struct snd_card_asihpi *asihpi,
+                                       u32 h_stream,
+                                        struct snd_pcm_hardware *pcmhw)
+{
+  struct hpi_format hpi_format;
+       u16 format;
+       u16 err;
+       u32 h_control;
+       u32 sample_rate = 48000;
+
+       /* on cards without SRC, must query at valid rate,
+               maybe set by external sync */
+       err = hpi_mixer_get_control(ss, asihpi->h_mixer,
+                                 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
+                                 HPI_CONTROL_SAMPLECLOCK, &h_control);
+
+       if (!err)
+               err = hpi_sample_clock_get_sample_rate(ss, h_control,
+                       &sample_rate);
+
+       for (format = HPI_FORMAT_PCM8_UNSIGNED;
+               format <= HPI_FORMAT_PCM24_SIGNED; format++) {
+
+               err = hpi_format_create(&hpi_format, 2, format,
+                               sample_rate, 128000, 0);
+               if (!err)
+                       err = hpi_instream_query_format(ss, h_stream,
+                                           &hpi_format);
+               if (!err)
+                       pcmhw->formats |=
+                               (1ULL << hpi_to_alsa_formats[format]);
+       }
+}
+
+
+static struct snd_pcm_hardware snd_card_asihpi_capture = {
+       .channels_min = 1,
+       .channels_max = 2,
+       .buffer_bytes_max = BUFFER_BYTES_MAX,
+       .period_bytes_min = PERIOD_BYTES_MIN,
+       .period_bytes_max = BUFFER_BYTES_MAX / PERIODS_MIN,
+       .periods_min = PERIODS_MIN,
+       .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN,
+       .fifo_size = 0,
+};
+
+static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi *card = snd_pcm_substream_chip(substream);
+       struct snd_card_asihpi_pcm *dpcm;
+       int err;
+
+       dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL);
+       if (dpcm == NULL)
+               return -ENOMEM;
+
+       snd_printd("hpi_instream_open adapter %d stream %d\n",
+                  card->adapter_index, substream->number);
+
+       err = hpi_handle_error(
+           hpi_instream_open(ss, card->adapter_index,
+                            substream->number, &dpcm->h_stream));
+       if (err)
+               kfree(dpcm);
+       if (err == HPI_ERROR_OBJ_ALREADY_OPEN)
+               return -EBUSY;
+       if (err)
+               return -EIO;
+
+
+       init_timer(&dpcm->timer);
+       dpcm->timer.data = (unsigned long) dpcm;
+       dpcm->timer.function = snd_card_asihpi_timer_function;
+       dpcm->substream = substream;
+       runtime->private_data = dpcm;
+       runtime->private_free = snd_card_asihpi_runtime_free;
+
+       snd_card_asihpi_capture.channels_max = card->in_max_chans;
+       snd_card_asihpi_capture_format(card, dpcm->h_stream,
+                                      &snd_card_asihpi_capture);
+       snd_card_asihpi_pcm_samplerates(card,  &snd_card_asihpi_capture);
+       snd_card_asihpi_capture.info = SNDRV_PCM_INFO_INTERLEAVED;
+
+       if (card->support_mmap)
+               snd_card_asihpi_capture.info |= SNDRV_PCM_INFO_MMAP |
+                                               SNDRV_PCM_INFO_MMAP_VALID;
+
+       runtime->hw = snd_card_asihpi_capture;
+
+       if (card->support_mmap)
+               err = snd_pcm_hw_constraint_pow2(runtime, 0,
+                                       SNDRV_PCM_HW_PARAM_BUFFER_BYTES);
+       if (err < 0)
+               return err;
+
+       snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+               card->update_interval_frames);
+       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
+               card->update_interval_frames * 2, UINT_MAX);
+
+       snd_pcm_set_sync(substream);
+
+       return 0;
+}
+
+static int snd_card_asihpi_capture_close(struct snd_pcm_substream *substream)
+{
+       struct snd_card_asihpi_pcm *dpcm = substream->runtime->private_data;
+
+       hpi_handle_error(hpi_instream_close(ss, dpcm->h_stream));
+       return 0;
+}
+
+static int snd_card_asihpi_capture_copy(struct snd_pcm_substream *substream,
+                               int channel, snd_pcm_uframes_t pos,
+                               void __user *dst, snd_pcm_uframes_t count)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
+       u32 data_size;
+
+       data_size = frames_to_bytes(runtime, count);
+
+       VPRINTK2("capture copy%d %d bytes\n", substream->number, data_size);
+       hpi_handle_error(hpi_instream_read_buf(ss, dpcm->h_stream,
+                               runtime->dma_area, data_size));
+
+       /* Used by capture_pointer */
+       dpcm->pcm_irq_pos = dpcm->pcm_irq_pos + data_size;
+
+       if (copy_to_user(dst, runtime->dma_area, data_size))
+               return -EFAULT;
+
+       return 0;
+}
+
+static struct snd_pcm_ops snd_card_asihpi_capture_mmap_ops = {
+       .open = snd_card_asihpi_capture_open,
+       .close = snd_card_asihpi_capture_close,
+       .ioctl = snd_card_asihpi_capture_ioctl,
+       .hw_params = snd_card_asihpi_pcm_hw_params,
+       .hw_free = snd_card_asihpi_hw_free,
+       .prepare = snd_card_asihpi_capture_prepare,
+       .trigger = snd_card_asihpi_trigger,
+       .pointer = snd_card_asihpi_capture_pointer,
+};
+
+static struct snd_pcm_ops snd_card_asihpi_capture_ops = {
+       .open = snd_card_asihpi_capture_open,
+       .close = snd_card_asihpi_capture_close,
+       .ioctl = snd_card_asihpi_capture_ioctl,
+       .hw_params = snd_card_asihpi_pcm_hw_params,
+       .hw_free = snd_card_asihpi_hw_free,
+       .prepare = snd_card_asihpi_capture_prepare,
+       .trigger = snd_card_asihpi_trigger,
+       .pointer = snd_card_asihpi_capture_pointer,
+       .copy = snd_card_asihpi_capture_copy
+};
+
+static int __devinit snd_card_asihpi_pcm_new(struct snd_card_asihpi *asihpi,
+                                     int device, int substreams)
+{
+       struct snd_pcm *pcm;
+       int err;
+
+       err = snd_pcm_new(asihpi->card, "asihpi PCM", device,
+                        asihpi->num_outstreams, asihpi->num_instreams,
+                        &pcm);
+       if (err < 0)
+               return err;
+       /* pointer to ops struct is stored, dont change ops afterwards! */
+       if (asihpi->support_mmap) {
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                               &snd_card_asihpi_playback_mmap_ops);
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+                               &snd_card_asihpi_capture_mmap_ops);
+       } else {
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                               &snd_card_asihpi_playback_ops);
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+                               &snd_card_asihpi_capture_ops);
+       }
+
+       pcm->private_data = asihpi;
+       pcm->info_flags = 0;
+       strcpy(pcm->name, "asihpi PCM");
+
+       /*? do we want to emulate MMAP for non-BBM cards?
+       Jack doesn't work with ALSAs MMAP emulation - WHY NOT? */
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
+                                               snd_dma_pci_data(asihpi->pci),
+                                               64*1024, BUFFER_BYTES_MAX);
+
+       return 0;
+}
+
+/***************************** MIXER CONTROLS ****************/
+struct hpi_control {
+       u32 h_control;
+       u16 control_type;
+       u16 src_node_type;
+       u16 src_node_index;
+       u16 dst_node_type;
+       u16 dst_node_index;
+       u16 band;
+       char name[44]; /* copied to snd_ctl_elem_id.name[44]; */
+};
+
+static char *asihpi_tuner_band_names[] =
+{
+       "invalid",
+       "AM",
+       "FM mono",
+       "TV NTSC-M",
+       "FM stereo",
+       "AUX",
+       "TV PAL BG",
+       "TV PAL I",
+       "TV PAL DK",
+       "TV SECAM",
+};
+
+compile_time_assert(
+       (ARRAY_SIZE(asihpi_tuner_band_names) ==
+               (HPI_TUNER_BAND_LAST+1)),
+       assert_tuner_band_names_size);
+
+#if ASI_STYLE_NAMES
+static char *asihpi_src_names[] =
+{
+       "no source",
+       "outstream",
+       "line_in",
+       "aes_in",
+       "tuner",
+       "RF",
+       "clock",
+       "bitstr",
+       "mic",
+       "cobranet",
+       "analog_in",
+       "adapter",
+};
+#else
+static char *asihpi_src_names[] =
+{
+       "no source",
+       "PCM playback",
+       "line in",
+       "digital in",
+       "tuner",
+       "RF",
+       "clock",
+       "bitstream",
+       "mic",
+       "cobranet in",
+       "analog in",
+       "adapter",
+};
+#endif
+
+compile_time_assert(
+       (ARRAY_SIZE(asihpi_src_names) ==
+               (HPI_SOURCENODE_LAST_INDEX-HPI_SOURCENODE_BASE+1)),
+       assert_src_names_size);
+
+#if ASI_STYLE_NAMES
+static char *asihpi_dst_names[] =
+{
+       "no destination",
+       "instream",
+       "line_out",
+       "aes_out",
+       "RF",
+       "speaker" ,
+       "cobranet",
+       "analog_out",
+};
+#else
+static char *asihpi_dst_names[] =
+{
+       "no destination",
+       "PCM capture",
+       "line out",
+       "digital out",
+       "RF",
+       "speaker",
+       "cobranet out",
+       "analog out"
+};
+#endif
+
+compile_time_assert(
+       (ARRAY_SIZE(asihpi_dst_names) ==
+               (HPI_DESTNODE_LAST_INDEX-HPI_DESTNODE_BASE+1)),
+       assert_dst_names_size);
+
+static inline int ctl_add(struct snd_card *card, struct snd_kcontrol_new *ctl,
+                               struct snd_card_asihpi *asihpi)
+{
+       int err;
+
+       err = snd_ctl_add(card, snd_ctl_new1(ctl, asihpi));
+       if (err < 0)
+               return err;
+       else if (mixer_dump)
+               snd_printk(KERN_INFO "added %s(%d)\n", ctl->name, ctl->index);
+
+       return 0;
+}
+
+/* Convert HPI control name and location into ALSA control name */
+static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
+                               struct hpi_control *hpi_ctl,
+                               char *name)
+{
+       memset(snd_control, 0, sizeof(*snd_control));
+       snd_control->name = hpi_ctl->name;
+       snd_control->private_value = hpi_ctl->h_control;
+       snd_control->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+       snd_control->index = 0;
+
+       if (hpi_ctl->src_node_type && hpi_ctl->dst_node_type)
+               sprintf(hpi_ctl->name, "%s%d to %s%d %s",
+                       asihpi_src_names[hpi_ctl->src_node_type],
+                       hpi_ctl->src_node_index,
+                       asihpi_dst_names[hpi_ctl->dst_node_type],
+                       hpi_ctl->dst_node_index,
+                       name);
+       else if (hpi_ctl->dst_node_type) {
+               sprintf(hpi_ctl->name, "%s%d %s",
+               asihpi_dst_names[hpi_ctl->dst_node_type],
+               hpi_ctl->dst_node_index,
+               name);
+       } else {
+               sprintf(hpi_ctl->name, "%s%d %s",
+               asihpi_src_names[hpi_ctl->src_node_type],
+               hpi_ctl->src_node_index,
+               name);
+       }
+}
+
+/*------------------------------------------------------------
+   Volume controls
+ ------------------------------------------------------------*/
+#define VOL_STEP_mB 1
+static int snd_asihpi_volume_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 err;
+       /* native gains are in millibels */
+       short min_gain_mB;
+       short max_gain_mB;
+       short step_gain_mB;
+
+       err = hpi_volume_query_range(ss, h_control,
+                       &min_gain_mB, &max_gain_mB, &step_gain_mB);
+       if (err) {
+               max_gain_mB = 0;
+               min_gain_mB = -10000;
+               step_gain_mB = VOL_STEP_mB;
+       }
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = min_gain_mB / VOL_STEP_mB;
+       uinfo->value.integer.max = max_gain_mB / VOL_STEP_mB;
+       uinfo->value.integer.step = step_gain_mB / VOL_STEP_mB;
+       return 0;
+}
+
+static int snd_asihpi_volume_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       short an_gain_mB[HPI_MAX_CHANNELS];
+
+       hpi_handle_error(hpi_volume_get_gain(ss, h_control, an_gain_mB));
+       ucontrol->value.integer.value[0] = an_gain_mB[0] / VOL_STEP_mB;
+       ucontrol->value.integer.value[1] = an_gain_mB[1] / VOL_STEP_mB;
+
+       return 0;
+}
+
+static int snd_asihpi_volume_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       int change;
+       u32 h_control = kcontrol->private_value;
+       short an_gain_mB[HPI_MAX_CHANNELS];
+
+       an_gain_mB[0] =
+           (ucontrol->value.integer.value[0]) * VOL_STEP_mB;
+       an_gain_mB[1] =
+           (ucontrol->value.integer.value[1]) * VOL_STEP_mB;
+       /*  change = asihpi->mixer_volume[addr][0] != left ||
+          asihpi->mixer_volume[addr][1] != right;
+        */
+       change = 1;
+       hpi_handle_error(hpi_volume_set_gain(ss, h_control, an_gain_mB));
+       return change;
+}
+
+static const DECLARE_TLV_DB_SCALE(db_scale_100, -10000, VOL_STEP_mB, 0);
+
+static int __devinit snd_asihpi_volume_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "volume");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                               SNDRV_CTL_ELEM_ACCESS_TLV_READ;
+       snd_control.info = snd_asihpi_volume_info;
+       snd_control.get = snd_asihpi_volume_get;
+       snd_control.put = snd_asihpi_volume_put;
+       snd_control.tlv.p = db_scale_100;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   Level controls
+ ------------------------------------------------------------*/
+static int snd_asihpi_level_info(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 err;
+       short min_gain_mB;
+       short max_gain_mB;
+       short step_gain_mB;
+
+       err =
+           hpi_level_query_range(ss, h_control, &min_gain_mB,
+                              &max_gain_mB, &step_gain_mB);
+       if (err) {
+               max_gain_mB = 2400;
+               min_gain_mB = -1000;
+               step_gain_mB = 100;
+       }
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = min_gain_mB / HPI_UNITS_PER_dB;
+       uinfo->value.integer.max = max_gain_mB / HPI_UNITS_PER_dB;
+       uinfo->value.integer.step = step_gain_mB / HPI_UNITS_PER_dB;
+       return 0;
+}
+
+static int snd_asihpi_level_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       short an_gain_mB[HPI_MAX_CHANNELS];
+
+       hpi_handle_error(hpi_level_get_gain(ss, h_control, an_gain_mB));
+       ucontrol->value.integer.value[0] =
+           an_gain_mB[0] / HPI_UNITS_PER_dB;
+       ucontrol->value.integer.value[1] =
+           an_gain_mB[1] / HPI_UNITS_PER_dB;
+
+       return 0;
+}
+
+static int snd_asihpi_level_put(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
+{
+       int change;
+       u32 h_control = kcontrol->private_value;
+       short an_gain_mB[HPI_MAX_CHANNELS];
+
+       an_gain_mB[0] =
+           (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
+       an_gain_mB[1] =
+           (ucontrol->value.integer.value[1]) * HPI_UNITS_PER_dB;
+       /*  change = asihpi->mixer_level[addr][0] != left ||
+          asihpi->mixer_level[addr][1] != right;
+        */
+       change = 1;
+       hpi_handle_error(hpi_level_set_gain(ss, h_control, an_gain_mB));
+       return change;
+}
+
+static const DECLARE_TLV_DB_SCALE(db_scale_level, -1000, 100, 0);
+
+static int __devinit snd_asihpi_level_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       /* can't use 'volume' cos some nodes have volume as well */
+       asihpi_ctl_init(&snd_control, hpi_ctl, "level");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                               SNDRV_CTL_ELEM_ACCESS_TLV_READ;
+       snd_control.info = snd_asihpi_level_info;
+       snd_control.get = snd_asihpi_level_get;
+       snd_control.put = snd_asihpi_level_put;
+       snd_control.tlv.p = db_scale_level;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   AESEBU controls
+ ------------------------------------------------------------*/
+
+/* AESEBU format */
+static char *asihpi_aesebu_format_names[] =
+{
+       "N/A",
+       "S/PDIF",
+       "AES/EBU",
+};
+
+static int snd_asihpi_aesebu_format_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = 3;
+
+       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+               uinfo->value.enumerated.item =
+                       uinfo->value.enumerated.items - 1;
+
+       strcpy(uinfo->value.enumerated.name,
+               asihpi_aesebu_format_names[uinfo->value.enumerated.item]);
+
+       return 0;
+}
+
+static int snd_asihpi_aesebu_format_get(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol,
+                       u16 (*func)(const struct hpi_hsubsys *, u32, u16 *))
+{
+       u32 h_control = kcontrol->private_value;
+       u16 source, err;
+
+       err = func(ss, h_control, &source);
+
+       /* default to N/A */
+       ucontrol->value.enumerated.item[0] = 0;
+       /* return success but set the control to N/A */
+       if (err)
+               return 0;
+       if (source == HPI_AESEBU_FORMAT_SPDIF)
+               ucontrol->value.enumerated.item[0] = 1;
+       if (source == HPI_AESEBU_FORMAT_AESEBU)
+               ucontrol->value.enumerated.item[0] = 2;
+
+       return 0;
+}
+
+static int snd_asihpi_aesebu_format_put(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol,
+                        u16 (*func)(const struct hpi_hsubsys *, u32, u16))
+{
+       u32 h_control = kcontrol->private_value;
+
+       /* default to S/PDIF */
+       u16 source = HPI_AESEBU_FORMAT_SPDIF;
+
+       if (ucontrol->value.enumerated.item[0] == 1)
+               source = HPI_AESEBU_FORMAT_SPDIF;
+       if (ucontrol->value.enumerated.item[0] == 2)
+               source = HPI_AESEBU_FORMAT_AESEBU;
+
+       if (func(ss, h_control, source) != 0)
+               return -EINVAL;
+
+       return 1;
+}
+
+static int snd_asihpi_aesebu_rx_format_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol) {
+       return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
+                                       HPI_AESEBU__receiver_get_format);
+}
+
+static int snd_asihpi_aesebu_rx_format_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol) {
+       return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
+                                       HPI_AESEBU__receiver_set_format);
+}
+
+static int snd_asihpi_aesebu_rxstatus_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 0X1F;
+       uinfo->value.integer.step = 1;
+
+       return 0;
+}
+
+static int snd_asihpi_aesebu_rxstatus_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol) {
+
+       u32 h_control = kcontrol->private_value;
+       u16 status;
+
+       hpi_handle_error(HPI_AESEBU__receiver_get_error_status(
+                               ss, h_control, &status));
+       ucontrol->value.integer.value[0] = status;
+       return 0;
+}
+
+static int __devinit snd_asihpi_aesebu_rx_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "format");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+       snd_control.info = snd_asihpi_aesebu_format_info;
+       snd_control.get = snd_asihpi_aesebu_rx_format_get;
+       snd_control.put = snd_asihpi_aesebu_rx_format_put;
+
+
+       if (ctl_add(card, &snd_control, asihpi) < 0)
+               return -EINVAL;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "status");
+       snd_control.access =
+           SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
+       snd_control.info = snd_asihpi_aesebu_rxstatus_info;
+       snd_control.get = snd_asihpi_aesebu_rxstatus_get;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+static int snd_asihpi_aesebu_tx_format_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol) {
+       return snd_asihpi_aesebu_format_get(kcontrol, ucontrol,
+                                       HPI_AESEBU__transmitter_get_format);
+}
+
+static int snd_asihpi_aesebu_tx_format_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol) {
+       return snd_asihpi_aesebu_format_put(kcontrol, ucontrol,
+                                       HPI_AESEBU__transmitter_set_format);
+}
+
+
+static int __devinit snd_asihpi_aesebu_tx_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "format");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+       snd_control.info = snd_asihpi_aesebu_format_info;
+       snd_control.get = snd_asihpi_aesebu_tx_format_get;
+       snd_control.put = snd_asihpi_aesebu_tx_format_put;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   Tuner controls
+ ------------------------------------------------------------*/
+
+/* Gain */
+
+static int snd_asihpi_tuner_gain_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 err;
+       short idx;
+       u16 gain_range[3];
+
+       for (idx = 0; idx < 3; idx++) {
+               err = hpi_tuner_query_gain(ss, h_control,
+                                         idx, &gain_range[idx]);
+               if (err != 0)
+                       return err;
+       }
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = ((int)gain_range[0]) / HPI_UNITS_PER_dB;
+       uinfo->value.integer.max = ((int)gain_range[1]) / HPI_UNITS_PER_dB;
+       uinfo->value.integer.step = ((int) gain_range[2]) / HPI_UNITS_PER_dB;
+       return 0;
+}
+
+static int snd_asihpi_tuner_gain_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       /*
+       struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
+       */
+       u32 h_control = kcontrol->private_value;
+       short gain;
+
+       hpi_handle_error(hpi_tuner_get_gain(ss, h_control, &gain));
+       ucontrol->value.integer.value[0] = gain / HPI_UNITS_PER_dB;
+
+       return 0;
+}
+
+static int snd_asihpi_tuner_gain_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       /*
+       struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
+       */
+       u32 h_control = kcontrol->private_value;
+       short gain;
+
+       gain = (ucontrol->value.integer.value[0]) * HPI_UNITS_PER_dB;
+       hpi_handle_error(hpi_tuner_set_gain(ss, h_control, gain));
+
+       return 1;
+}
+
+/* Band  */
+
+static int asihpi_tuner_band_query(struct snd_kcontrol *kcontrol,
+                                       u16 *band_list, u32 len) {
+       u32 h_control = kcontrol->private_value;
+       u16 err = 0;
+       u32 i;
+
+       for (i = 0; i < len; i++) {
+               err = hpi_tuner_query_band(ss,
+                               h_control, i, &band_list[i]);
+               if (err != 0)
+                       break;
+       }
+
+       if (err && (err != HPI_ERROR_INVALID_OBJ_INDEX))
+               return -EIO;
+
+       return i;
+}
+
+static int snd_asihpi_tuner_band_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       u16 tuner_bands[HPI_TUNER_BAND_LAST];
+       int num_bands = 0;
+
+       num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
+                               HPI_TUNER_BAND_LAST);
+
+       if (num_bands < 0)
+               return num_bands;
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = num_bands;
+
+       if (num_bands > 0) {
+               if (uinfo->value.enumerated.item >=
+                                       uinfo->value.enumerated.items)
+                       uinfo->value.enumerated.item =
+                               uinfo->value.enumerated.items - 1;
+
+               strcpy(uinfo->value.enumerated.name,
+                       asihpi_tuner_band_names[
+                               tuner_bands[uinfo->value.enumerated.item]]);
+
+       }
+       return 0;
+}
+
+static int snd_asihpi_tuner_band_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       /*
+       struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
+       */
+       u16 band, idx;
+       u16 tuner_bands[HPI_TUNER_BAND_LAST];
+       u32 num_bands = 0;
+
+       num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
+                               HPI_TUNER_BAND_LAST);
+
+       hpi_handle_error(hpi_tuner_get_band(ss, h_control, &band));
+
+       ucontrol->value.enumerated.item[0] = -1;
+       for (idx = 0; idx < HPI_TUNER_BAND_LAST; idx++)
+               if (tuner_bands[idx] == band) {
+                       ucontrol->value.enumerated.item[0] = idx;
+                       break;
+               }
+
+       return 0;
+}
+
+static int snd_asihpi_tuner_band_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       /*
+       struct snd_card_asihpi *asihpi = snd_kcontrol_chip(kcontrol);
+       */
+       u32 h_control = kcontrol->private_value;
+       u16 band;
+       u16 tuner_bands[HPI_TUNER_BAND_LAST];
+       u32 num_bands = 0;
+
+       num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
+                       HPI_TUNER_BAND_LAST);
+
+       band = tuner_bands[ucontrol->value.enumerated.item[0]];
+       hpi_handle_error(hpi_tuner_set_band(ss, h_control, band));
+
+       return 1;
+}
+
+/* Freq */
+
+static int snd_asihpi_tuner_freq_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 err;
+       u16 tuner_bands[HPI_TUNER_BAND_LAST];
+       u16 num_bands = 0, band_iter, idx;
+       u32 freq_range[3], temp_freq_range[3];
+
+       num_bands = asihpi_tuner_band_query(kcontrol, tuner_bands,
+                       HPI_TUNER_BAND_LAST);
+
+       freq_range[0] = INT_MAX;
+       freq_range[1] = 0;
+       freq_range[2] = INT_MAX;
+
+       for (band_iter = 0; band_iter < num_bands; band_iter++) {
+               for (idx = 0; idx < 3; idx++) {
+                       err = hpi_tuner_query_frequency(ss, h_control,
+                               idx, tuner_bands[band_iter],
+                               &temp_freq_range[idx]);
+                       if (err != 0)
+                               return err;
+               }
+
+               /* skip band with bogus stepping */
+               if (temp_freq_range[2] <= 0)
+                       continue;
+
+               if (temp_freq_range[0] < freq_range[0])
+                       freq_range[0] = temp_freq_range[0];
+               if (temp_freq_range[1] > freq_range[1])
+                       freq_range[1] = temp_freq_range[1];
+               if (temp_freq_range[2] < freq_range[2])
+                       freq_range[2] = temp_freq_range[2];
+       }
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = ((int)freq_range[0]);
+       uinfo->value.integer.max = ((int)freq_range[1]);
+       uinfo->value.integer.step = ((int)freq_range[2]);
+       return 0;
+}
+
+static int snd_asihpi_tuner_freq_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u32 freq;
+
+       hpi_handle_error(hpi_tuner_get_frequency(ss, h_control, &freq));
+       ucontrol->value.integer.value[0] = freq;
+
+       return 0;
+}
+
+static int snd_asihpi_tuner_freq_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u32 freq;
+
+       freq = ucontrol->value.integer.value[0];
+       hpi_handle_error(hpi_tuner_set_frequency(ss, h_control, freq));
+
+       return 1;
+}
+
+/* Tuner control group initializer  */
+static int __devinit snd_asihpi_tuner_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       snd_control.private_value = hpi_ctl->h_control;
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+
+       if (!hpi_tuner_get_gain(ss, hpi_ctl->h_control, NULL)) {
+               asihpi_ctl_init(&snd_control, hpi_ctl, "gain");
+               snd_control.info = snd_asihpi_tuner_gain_info;
+               snd_control.get = snd_asihpi_tuner_gain_get;
+               snd_control.put = snd_asihpi_tuner_gain_put;
+
+               if (ctl_add(card, &snd_control, asihpi) < 0)
+                       return -EINVAL;
+       }
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "band");
+       snd_control.info = snd_asihpi_tuner_band_info;
+       snd_control.get = snd_asihpi_tuner_band_get;
+       snd_control.put = snd_asihpi_tuner_band_put;
+
+       if (ctl_add(card, &snd_control, asihpi) < 0)
+               return -EINVAL;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "freq");
+       snd_control.info = snd_asihpi_tuner_freq_info;
+       snd_control.get = snd_asihpi_tuner_freq_get;
+       snd_control.put = snd_asihpi_tuner_freq_put;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   Meter controls
+ ------------------------------------------------------------*/
+static int snd_asihpi_meter_info(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = HPI_MAX_CHANNELS;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = 0x7FFFFFFF;
+       return 0;
+}
+
+/* linear values for 10dB steps */
+static int log2lin[] = {
+       0x7FFFFFFF, /* 0dB */
+       679093956,
+       214748365,
+        67909396,
+        21474837,
+         6790940,
+         2147484, /* -60dB */
+          679094,
+          214748, /* -80 */
+           67909,
+           21475, /* -100 */
+            6791,
+            2147,
+             679,
+             214,
+              68,
+              21,
+               7,
+               2
+};
+
+static int snd_asihpi_meter_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       short an_gain_mB[HPI_MAX_CHANNELS], i;
+       u16 err;
+
+       err = hpi_meter_get_peak(ss, h_control, an_gain_mB);
+
+       for (i = 0; i < HPI_MAX_CHANNELS; i++) {
+               if (err) {
+                       ucontrol->value.integer.value[i] = 0;
+               } else if (an_gain_mB[i] >= 0) {
+                       ucontrol->value.integer.value[i] =
+                               an_gain_mB[i] << 16;
+               } else {
+                       /* -ve is log value in millibels < -60dB,
+                       * convert to (roughly!) linear,
+                       */
+                       ucontrol->value.integer.value[i] =
+                                       log2lin[an_gain_mB[i] / -1000];
+               }
+       }
+       return 0;
+}
+
+static int __devinit snd_asihpi_meter_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl, int subidx)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "meter");
+       snd_control.access =
+           SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
+       snd_control.info = snd_asihpi_meter_info;
+       snd_control.get = snd_asihpi_meter_get;
+
+       snd_control.index = subidx;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   Multiplexer controls
+ ------------------------------------------------------------*/
+static int snd_card_asihpi_mux_count_sources(struct snd_kcontrol *snd_control)
+{
+       u32 h_control = snd_control->private_value;
+       struct hpi_control hpi_ctl;
+       int s, err;
+       for (s = 0; s < 32; s++) {
+               err = hpi_multiplexer_query_source(ss, h_control, s,
+                                                 &hpi_ctl.
+                                                 src_node_type,
+                                                 &hpi_ctl.
+                                                 src_node_index);
+               if (err)
+                       break;
+       }
+       return s;
+}
+
+static int snd_asihpi_mux_info(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_info *uinfo)
+{
+       int err;
+       u16 src_node_type, src_node_index;
+       u32 h_control = kcontrol->private_value;
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items =
+           snd_card_asihpi_mux_count_sources(kcontrol);
+
+       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+               uinfo->value.enumerated.item =
+                   uinfo->value.enumerated.items - 1;
+
+       err =
+           hpi_multiplexer_query_source(ss, h_control,
+                                       uinfo->value.enumerated.item,
+                                       &src_node_type, &src_node_index);
+
+       sprintf(uinfo->value.enumerated.name, "%s %d",
+               asihpi_src_names[src_node_type - HPI_SOURCENODE_BASE],
+               src_node_index);
+       return 0;
+}
+
+static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
+                             struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 source_type, source_index;
+       u16 src_node_type, src_node_index;
+       int s;
+
+       hpi_handle_error(hpi_multiplexer_get_source(ss, h_control,
+                               &source_type, &source_index));
+       /* Should cache this search result! */
+       for (s = 0; s < 256; s++) {
+               if (hpi_multiplexer_query_source(ss, h_control, s,
+                                           &src_node_type, &src_node_index))
+                       break;
+
+               if ((source_type == src_node_type)
+                   && (source_index == src_node_index)) {
+                       ucontrol->value.enumerated.item[0] = s;
+                       return 0;
+               }
+       }
+       snd_printd(KERN_WARNING
+               "control %x failed to match mux source %hu %hu\n",
+               h_control, source_type, source_index);
+       ucontrol->value.enumerated.item[0] = 0;
+       return 0;
+}
+
+static int snd_asihpi_mux_put(struct snd_kcontrol *kcontrol,
+                             struct snd_ctl_elem_value *ucontrol)
+{
+       int change;
+       u32 h_control = kcontrol->private_value;
+       u16 source_type, source_index;
+       u16 e;
+
+       change = 1;
+
+       e = hpi_multiplexer_query_source(ss, h_control,
+                                   ucontrol->value.enumerated.item[0],
+                                   &source_type, &source_index);
+       if (!e)
+               hpi_handle_error(
+                       hpi_multiplexer_set_source(ss, h_control,
+                                               source_type, source_index));
+       return change;
+}
+
+
+static int  __devinit snd_asihpi_mux_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+#if ASI_STYLE_NAMES
+       asihpi_ctl_init(&snd_control, hpi_ctl, "multiplexer");
+#else
+       asihpi_ctl_init(&snd_control, hpi_ctl, "route");
+#endif
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+       snd_control.info = snd_asihpi_mux_info;
+       snd_control.get = snd_asihpi_mux_get;
+       snd_control.put = snd_asihpi_mux_put;
+
+       return ctl_add(card, &snd_control, asihpi);
+
+}
+
+/*------------------------------------------------------------
+   Channel mode controls
+ ------------------------------------------------------------*/
+static int snd_asihpi_cmode_info(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
+{
+       static char *mode_names[HPI_CHANNEL_MODE_LAST] = {
+               "normal", "swap",
+               "from_left", "from_right",
+               "to_left", "to_right"
+       };
+
+       u32 h_control = kcontrol->private_value;
+       u16 mode;
+       int i;
+
+       /* HPI channel mode values can be from 1 to 6
+       Some adapters only support a contiguous subset
+       */
+       for (i = 0; i < HPI_CHANNEL_MODE_LAST; i++)
+               if (hpi_channel_mode_query_mode(
+                       ss,  h_control, i, &mode))
+                       break;
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = i;
+
+       if (uinfo->value.enumerated.item >= i)
+               uinfo->value.enumerated.item = i - 1;
+
+       strcpy(uinfo->value.enumerated.name,
+              mode_names[uinfo->value.enumerated.item]);
+
+       return 0;
+}
+
+static int snd_asihpi_cmode_get(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u16 mode;
+
+       if (hpi_channel_mode_get(ss, h_control, &mode))
+               mode = 1;
+
+       ucontrol->value.enumerated.item[0] = mode - 1;
+
+       return 0;
+}
+
+static int snd_asihpi_cmode_put(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
+{
+       int change;
+       u32 h_control = kcontrol->private_value;
+
+       change = 1;
+
+       hpi_handle_error(hpi_channel_mode_set(ss, h_control,
+                          ucontrol->value.enumerated.item[0] + 1));
+       return change;
+}
+
+
+static int __devinit snd_asihpi_cmode_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "channel mode");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE;
+       snd_control.info = snd_asihpi_cmode_info;
+       snd_control.get = snd_asihpi_cmode_get;
+       snd_control.put = snd_asihpi_cmode_put;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+
+/*------------------------------------------------------------
+   Sampleclock source  controls
+ ------------------------------------------------------------*/
+
+static char *sampleclock_sources[MAX_CLOCKSOURCES] =
+    { "N/A", "local PLL", "AES/EBU sync", "word external", "word header",
+         "SMPTE", "AES/EBU in1", "auto", "network", "invalid",
+         "prev module",
+         "AES/EBU in2", "AES/EBU in3", "AES/EBU in4", "AES/EBU in5",
+         "AES/EBU in6", "AES/EBU in7", "AES/EBU in8"};
+
+
+
+static int snd_asihpi_clksrc_info(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
+{
+       struct snd_card_asihpi *asihpi =
+                       (struct snd_card_asihpi *)(kcontrol->private_data);
+       struct clk_cache *clkcache = &asihpi->cc;
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = clkcache->count;
+
+       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+               uinfo->value.enumerated.item =
+                               uinfo->value.enumerated.items - 1;
+
+       strcpy(uinfo->value.enumerated.name,
+              clkcache->s[uinfo->value.enumerated.item].name);
+       return 0;
+}
+
+static int snd_asihpi_clksrc_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_card_asihpi *asihpi =
+                       (struct snd_card_asihpi *)(kcontrol->private_data);
+       struct clk_cache *clkcache = &asihpi->cc;
+       u32 h_control = kcontrol->private_value;
+       u16 source, srcindex = 0;
+       int i;
+
+       ucontrol->value.enumerated.item[0] = 0;
+       if (hpi_sample_clock_get_source(ss, h_control, &source))
+               source = 0;
+
+       if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
+               if (hpi_sample_clock_get_source_index(ss, h_control, &srcindex))
+                       srcindex = 0;
+
+       for (i = 0; i < clkcache->count; i++)
+               if ((clkcache->s[i].source == source) &&
+                       (clkcache->s[i].index == srcindex))
+                       break;
+
+       ucontrol->value.enumerated.item[0] = i;
+
+       return 0;
+}
+
+static int snd_asihpi_clksrc_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_card_asihpi *asihpi =
+                       (struct snd_card_asihpi *)(kcontrol->private_data);
+       struct clk_cache *clkcache = &asihpi->cc;
+       int change, item;
+       u32 h_control = kcontrol->private_value;
+
+       change = 1;
+       item = ucontrol->value.enumerated.item[0];
+       if (item >= clkcache->count)
+               item = clkcache->count-1;
+
+       hpi_handle_error(hpi_sample_clock_set_source(ss,
+                               h_control, clkcache->s[item].source));
+
+       if (clkcache->s[item].source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
+               hpi_handle_error(hpi_sample_clock_set_source_index(ss,
+                               h_control, clkcache->s[item].index));
+       return change;
+}
+
+/*------------------------------------------------------------
+   Clkrate controls
+ ------------------------------------------------------------*/
+/* Need to change this to enumerated control with list of rates */
+static int snd_asihpi_clklocal_info(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = 8000;
+       uinfo->value.integer.max = 192000;
+       uinfo->value.integer.step = 100;
+
+       return 0;
+}
+
+static int snd_asihpi_clklocal_get(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u32 rate;
+       u16 e;
+
+       e = hpi_sample_clock_get_local_rate(ss, h_control, &rate);
+       if (!e)
+               ucontrol->value.integer.value[0] = rate;
+       else
+               ucontrol->value.integer.value[0] = 0;
+       return 0;
+}
+
+static int snd_asihpi_clklocal_put(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       int change;
+       u32 h_control = kcontrol->private_value;
+
+       /*  change = asihpi->mixer_clkrate[addr][0] != left ||
+          asihpi->mixer_clkrate[addr][1] != right;
+        */
+       change = 1;
+       hpi_handle_error(hpi_sample_clock_set_local_rate(ss, h_control,
+                                     ucontrol->value.integer.value[0]));
+       return change;
+}
+
+static int snd_asihpi_clkrate_info(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_info *uinfo)
+{
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 1;
+       uinfo->value.integer.min = 8000;
+       uinfo->value.integer.max = 192000;
+       uinfo->value.integer.step = 100;
+
+       return 0;
+}
+
+static int snd_asihpi_clkrate_get(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
+{
+       u32 h_control = kcontrol->private_value;
+       u32 rate;
+       u16 e;
+
+       e = hpi_sample_clock_get_sample_rate(ss, h_control, &rate);
+       if (!e)
+               ucontrol->value.integer.value[0] = rate;
+       else
+               ucontrol->value.integer.value[0] = 0;
+       return 0;
+}
+
+static int __devinit snd_asihpi_sampleclock_add(struct snd_card_asihpi *asihpi,
+                                       struct hpi_control *hpi_ctl)
+{
+       struct snd_card *card = asihpi->card;
+       struct snd_kcontrol_new snd_control;
+
+       struct clk_cache *clkcache = &asihpi->cc;
+       u32 hSC =  hpi_ctl->h_control;
+       int has_aes_in = 0;
+       int i, j;
+       u16 source;
+
+       snd_control.private_value = hpi_ctl->h_control;
+
+       clkcache->has_local = 0;
+
+       for (i = 0; i <= HPI_SAMPLECLOCK_SOURCE_LAST; i++) {
+               if  (hpi_sample_clock_query_source(ss, hSC,
+                               i, &source))
+                       break;
+               clkcache->s[i].source = source;
+               clkcache->s[i].index = 0;
+               clkcache->s[i].name = sampleclock_sources[source];
+               if (source == HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT)
+                       has_aes_in = 1;
+               if (source == HPI_SAMPLECLOCK_SOURCE_LOCAL)
+                       clkcache->has_local = 1;
+       }
+       if (has_aes_in)
+               /* already will have picked up index 0 above */
+               for (j = 1; j < 8; j++) {
+                       if (hpi_sample_clock_query_source_index(ss, hSC,
+                               j, HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT,
+                               &source))
+                               break;
+                       clkcache->s[i].source =
+                               HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT;
+                       clkcache->s[i].index = j;
+                       clkcache->s[i].name = sampleclock_sources[
+                                       j+HPI_SAMPLECLOCK_SOURCE_LAST];
+                       i++;
+               }
+       clkcache->count = i;
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "source");
+       snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
+       snd_control.info = snd_asihpi_clksrc_info;
+       snd_control.get = snd_asihpi_clksrc_get;
+       snd_control.put = snd_asihpi_clksrc_put;
+       if (ctl_add(card, &snd_control, asihpi) < 0)
+               return -EINVAL;
+
+
+       if (clkcache->has_local) {
+               asihpi_ctl_init(&snd_control, hpi_ctl, "local_rate");
+               snd_control.access = SNDRV_CTL_ELEM_ACCESS_READWRITE ;
+               snd_control.info = snd_asihpi_clklocal_info;
+               snd_control.get = snd_asihpi_clklocal_get;
+               snd_control.put = snd_asihpi_clklocal_put;
+
+
+               if (ctl_add(card, &snd_control, asihpi) < 0)
+                       return -EINVAL;
+       }
+
+       asihpi_ctl_init(&snd_control, hpi_ctl, "rate");
+       snd_control.access =
+           SNDRV_CTL_ELEM_ACCESS_VOLATILE | SNDRV_CTL_ELEM_ACCESS_READ;
+       snd_control.info = snd_asihpi_clkrate_info;
+       snd_control.get = snd_asihpi_clkrate_get;
+
+       return ctl_add(card, &snd_control, asihpi);
+}
+/*------------------------------------------------------------
+   Mixer
+ ------------------------------------------------------------*/
+
+static int __devinit snd_card_asihpi_mixer_new(struct snd_card_asihpi *asihpi)
+{
+       struct snd_card *card = asihpi->card;
+       unsigned int idx = 0;
+       unsigned int subindex = 0;
+       int err;
+       struct hpi_control hpi_ctl, prev_ctl;
+
+       if (snd_BUG_ON(!asihpi))
+               return -EINVAL;
+       strcpy(card->mixername, "asihpi mixer");
+
+       err =
+           hpi_mixer_open(ss, asihpi->adapter_index,
+                         &asihpi->h_mixer);
+       hpi_handle_error(err);
+       if (err)
+               return -err;
+
+       for (idx = 0; idx < 2000; idx++) {
+               err = hpi_mixer_get_control_by_index(
+                               ss, asihpi->h_mixer,
+                               idx,
+                               &hpi_ctl.src_node_type,
+                               &hpi_ctl.src_node_index,
+                               &hpi_ctl.dst_node_type,
+                               &hpi_ctl.dst_node_index,
+                               &hpi_ctl.control_type,
+                               &hpi_ctl.h_control);
+               if (err) {
+                       if (err == HPI_ERROR_CONTROL_DISABLED) {
+                               if (mixer_dump)
+                                       snd_printk(KERN_INFO
+                                                  "disabled HPI control(%d)\n",
+                                                  idx);
+                               continue;
+                       } else
+                               break;
+
+               }
+
+               hpi_ctl.src_node_type -= HPI_SOURCENODE_BASE;
+               hpi_ctl.dst_node_type -= HPI_DESTNODE_BASE;
+
+               /* ASI50xx in SSX mode has multiple meters on the same node.
+                  Use subindex to create distinct ALSA controls
+                  for any duplicated controls.
+               */
+               if ((hpi_ctl.control_type == prev_ctl.control_type) &&
+                   (hpi_ctl.src_node_type == prev_ctl.src_node_type) &&
+                   (hpi_ctl.src_node_index == prev_ctl.src_node_index) &&
+                   (hpi_ctl.dst_node_type == prev_ctl.dst_node_type) &&
+                   (hpi_ctl.dst_node_index == prev_ctl.dst_node_index))
+                       subindex++;
+               else
+                       subindex = 0;
+
+               prev_ctl = hpi_ctl;
+
+               switch (hpi_ctl.control_type) {
+               case HPI_CONTROL_VOLUME:
+                       err = snd_asihpi_volume_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_LEVEL:
+                       err = snd_asihpi_level_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_MULTIPLEXER:
+                       err = snd_asihpi_mux_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_CHANNEL_MODE:
+                       err = snd_asihpi_cmode_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_METER:
+                       err = snd_asihpi_meter_add(asihpi, &hpi_ctl, subindex);
+                       break;
+               case HPI_CONTROL_SAMPLECLOCK:
+                       err = snd_asihpi_sampleclock_add(
+                                               asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_CONNECTION:    /* ignore these */
+                       continue;
+               case HPI_CONTROL_TUNER:
+                       err = snd_asihpi_tuner_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_AESEBU_TRANSMITTER:
+                       err = snd_asihpi_aesebu_tx_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_AESEBU_RECEIVER:
+                       err = snd_asihpi_aesebu_rx_add(asihpi, &hpi_ctl);
+                       break;
+               case HPI_CONTROL_VOX:
+               case HPI_CONTROL_BITSTREAM:
+               case HPI_CONTROL_MICROPHONE:
+               case HPI_CONTROL_PARAMETRIC_EQ:
+               case HPI_CONTROL_COMPANDER:
+               default:
+                       if (mixer_dump)
+                               snd_printk(KERN_INFO
+                                       "untranslated HPI control"
+                                       "(%d) %d %d %d %d %d\n",
+                                       idx,
+                                       hpi_ctl.control_type,
+                                       hpi_ctl.src_node_type,
+                                       hpi_ctl.src_node_index,
+                                       hpi_ctl.dst_node_type,
+                                       hpi_ctl.dst_node_index);
+                       continue;
+               };
+               if (err < 0)
+                       return err;
+       }
+       if (HPI_ERROR_INVALID_OBJ_INDEX != err)
+               hpi_handle_error(err);
+
+       snd_printk(KERN_INFO "%d mixer controls found\n", idx);
+
+       return 0;
+}
+
+/*------------------------------------------------------------
+   /proc interface
+ ------------------------------------------------------------*/
+
+static void
+snd_asihpi_proc_read(struct snd_info_entry *entry,
+                       struct snd_info_buffer *buffer)
+{
+       struct snd_card_asihpi *asihpi = entry->private_data;
+       u16 version;
+       u32 h_control;
+       u32 rate = 0;
+       u16 source = 0;
+       int err;
+
+       snd_iprintf(buffer, "ASIHPI driver proc file\n");
+       snd_iprintf(buffer,
+               "adapter ID=%4X\n_index=%d\n"
+               "num_outstreams=%d\n_num_instreams=%d\n",
+               asihpi->type, asihpi->adapter_index,
+               asihpi->num_outstreams, asihpi->num_instreams);
+
+       version = asihpi->version;
+       snd_iprintf(buffer,
+               "serial#=%d\n_hw version %c%d\nDSP code version %03d\n",
+               asihpi->serial_number, ((version >> 3) & 0xf) + 'A',
+               version & 0x7,
+               ((version >> 13) * 100) + ((version >> 7) & 0x3f));
+
+       err = hpi_mixer_get_control(ss, asihpi->h_mixer,
+                                 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
+                                 HPI_CONTROL_SAMPLECLOCK, &h_control);
+
+       if (!err) {
+               err = hpi_sample_clock_get_sample_rate(ss,
+                                       h_control, &rate);
+               err += hpi_sample_clock_get_source(ss, h_control, &source);
+
+               if (!err)
+                       snd_iprintf(buffer, "sample_clock=%d_hz, source %s\n",
+                       rate, sampleclock_sources[source]);
+       }
+
+}
+
+
+static void __devinit snd_asihpi_proc_init(struct snd_card_asihpi *asihpi)
+{
+       struct snd_info_entry *entry;
+
+       if (!snd_card_proc_new(asihpi->card, "info", &entry))
+               snd_info_set_text_ops(entry, asihpi, snd_asihpi_proc_read);
+}
+
+/*------------------------------------------------------------
+   HWDEP
+ ------------------------------------------------------------*/
+
+static int snd_asihpi_hpi_open(struct snd_hwdep *hw, struct file *file)
+{
+       if (enable_hpi_hwdep)
+               return 0;
+       else
+               return -ENODEV;
+
+}
+
+static int snd_asihpi_hpi_release(struct snd_hwdep *hw, struct file *file)
+{
+       if (enable_hpi_hwdep)
+               return asihpi_hpi_release(file);
+       else
+               return -ENODEV;
+}
+
+static int snd_asihpi_hpi_ioctl(struct snd_hwdep *hw, struct file *file,
+                               unsigned int cmd, unsigned long arg)
+{
+       if (enable_hpi_hwdep)
+               return asihpi_hpi_ioctl(file, cmd, arg);
+       else
+               return -ENODEV;
+}
+
+
+/* results in /dev/snd/hwC#D0 file for each card with index #
+   also /proc/asound/hwdep will contain '#-00: asihpi (HPI) for each card'
+*/
+static int __devinit snd_asihpi_hpi_new(struct snd_card_asihpi *asihpi,
+       int device, struct snd_hwdep **rhwdep)
+{
+       struct snd_hwdep *hw;
+       int err;
+
+       if (rhwdep)
+               *rhwdep = NULL;
+       err = snd_hwdep_new(asihpi->card, "HPI", device, &hw);
+       if (err < 0)
+               return err;
+       strcpy(hw->name, "asihpi (HPI)");
+       hw->iface = SNDRV_HWDEP_IFACE_LAST;
+       hw->ops.open = snd_asihpi_hpi_open;
+       hw->ops.ioctl = snd_asihpi_hpi_ioctl;
+       hw->ops.release = snd_asihpi_hpi_release;
+       hw->private_data = asihpi;
+       if (rhwdep)
+               *rhwdep = hw;
+       return 0;
+}
+
+/*------------------------------------------------------------
+   CARD
+ ------------------------------------------------------------*/
+static int __devinit snd_asihpi_probe(struct pci_dev *pci_dev,
+                                      const struct pci_device_id *pci_id)
+{
+       int err;
+
+       u16 version;
+       int pcm_substreams;
+
+       struct hpi_adapter *hpi_card;
+       struct snd_card *card;
+       struct snd_card_asihpi *asihpi;
+
+       u32 h_control;
+       u32 h_stream;
+
+       static int dev;
+       if (dev >= SNDRV_CARDS)
+               return -ENODEV;
+
+       /* Should this be enable[hpi_card->index] ? */
+       if (!enable[dev]) {
+               dev++;
+               return -ENOENT;
+       }
+
+       err = asihpi_adapter_probe(pci_dev, pci_id);
+       if (err < 0)
+               return err;
+
+       hpi_card = pci_get_drvdata(pci_dev);
+       /* first try to give the card the same index as its hardware index */
+       err = snd_card_create(hpi_card->index,
+                             id[hpi_card->index], THIS_MODULE,
+                             sizeof(struct snd_card_asihpi),
+                             &card);
+       if (err < 0) {
+               /* if that fails, try the default index==next available */
+               err =
+                   snd_card_create(index[dev], id[dev],
+                                   THIS_MODULE,
+                                   sizeof(struct snd_card_asihpi),
+                                   &card);
+               if (err < 0)
+                       return err;
+               snd_printk(KERN_WARNING
+                       "**** WARNING **** adapter index %d->ALSA index %d\n",
+                       hpi_card->index, card->number);
+       }
+
+       asihpi = (struct snd_card_asihpi *) card->private_data;
+       asihpi->card = card;
+       asihpi->pci = hpi_card->pci;
+       asihpi->adapter_index = hpi_card->index;
+       hpi_handle_error(hpi_adapter_get_info(ss,
+                                asihpi->adapter_index,
+                                &asihpi->num_outstreams,
+                                &asihpi->num_instreams,
+                                &asihpi->version,
+                                &asihpi->serial_number, &asihpi->type));
+
+       version = asihpi->version;
+       snd_printk(KERN_INFO "adapter ID=%4X index=%d num_outstreams=%d "
+                       "num_instreams=%d S/N=%d\n"
+                       "hw version %c%d DSP code version %03d\n",
+                       asihpi->type, asihpi->adapter_index,
+                       asihpi->num_outstreams,
+                       asihpi->num_instreams, asihpi->serial_number,
+                       ((version >> 3) & 0xf) + 'A',
+                       version & 0x7,
+                       ((version >> 13) * 100) + ((version >> 7) & 0x3f));
+
+       pcm_substreams = asihpi->num_outstreams;
+       if (pcm_substreams < asihpi->num_instreams)
+               pcm_substreams = asihpi->num_instreams;
+
+       err = hpi_adapter_get_property(ss, asihpi->adapter_index,
+               HPI_ADAPTER_PROPERTY_CAPS1,
+               NULL, &asihpi->support_grouping);
+       if (err)
+               asihpi->support_grouping = 0;
+
+       err = hpi_adapter_get_property(ss, asihpi->adapter_index,
+               HPI_ADAPTER_PROPERTY_CAPS2,
+               &asihpi->support_mrx, NULL);
+       if (err)
+               asihpi->support_mrx = 0;
+
+       err = hpi_adapter_get_property(ss, asihpi->adapter_index,
+               HPI_ADAPTER_PROPERTY_INTERVAL,
+               NULL, &asihpi->update_interval_frames);
+       if (err)
+               asihpi->update_interval_frames = 512;
+
+       hpi_handle_error(hpi_instream_open(ss, asihpi->adapter_index,
+                            0, &h_stream));
+
+       err = hpi_instream_host_buffer_free(ss, h_stream);
+       asihpi->support_mmap = (!err);
+
+       hpi_handle_error(hpi_instream_close(ss, h_stream));
+
+       err = hpi_adapter_get_property(ss, asihpi->adapter_index,
+               HPI_ADAPTER_PROPERTY_CURCHANNELS,
+               &asihpi->in_max_chans, &asihpi->out_max_chans);
+       if (err) {
+               asihpi->in_max_chans = 2;
+               asihpi->out_max_chans = 2;
+       }
+
+       snd_printk(KERN_INFO "supports mmap:%d grouping:%d mrx:%d\n",
+                       asihpi->support_mmap,
+                       asihpi->support_grouping,
+                       asihpi->support_mrx
+             );
+
+
+       err = snd_card_asihpi_pcm_new(asihpi, 0, pcm_substreams);
+       if (err < 0) {
+               snd_printk(KERN_ERR "pcm_new failed\n");
+               goto __nodev;
+       }
+       err = snd_card_asihpi_mixer_new(asihpi);
+       if (err < 0) {
+               snd_printk(KERN_ERR "mixer_new failed\n");
+               goto __nodev;
+       }
+
+       err = hpi_mixer_get_control(ss, asihpi->h_mixer,
+                                 HPI_SOURCENODE_CLOCK_SOURCE, 0, 0, 0,
+                                 HPI_CONTROL_SAMPLECLOCK, &h_control);
+
+       if (!err)
+               err = hpi_sample_clock_set_local_rate(
+                       ss, h_control, adapter_fs);
+
+       snd_asihpi_proc_init(asihpi);
+
+       /* always create, can be enabled or disabled dynamically
+           by enable_hwdep  module param*/
+       snd_asihpi_hpi_new(asihpi, 0, NULL);
+
+       if (asihpi->support_mmap)
+               strcpy(card->driver, "ASIHPI-MMAP");
+       else
+               strcpy(card->driver, "ASIHPI");
+
+       sprintf(card->shortname, "AudioScience ASI%4X", asihpi->type);
+       sprintf(card->longname, "%s %i",
+                       card->shortname, asihpi->adapter_index);
+       err = snd_card_register(card);
+       if (!err) {
+               hpi_card->snd_card_asihpi = card;
+               dev++;
+               return 0;
+       }
+__nodev:
+       snd_card_free(card);
+       snd_printk(KERN_ERR "snd_asihpi_probe error %d\n", err);
+       return err;
+
+}
+
+static void __devexit snd_asihpi_remove(struct pci_dev *pci_dev)
+{
+       struct hpi_adapter *hpi_card = pci_get_drvdata(pci_dev);
+
+       snd_card_free(hpi_card->snd_card_asihpi);
+       hpi_card->snd_card_asihpi = NULL;
+       asihpi_adapter_remove(pci_dev);
+}
+
+static DEFINE_PCI_DEVICE_TABLE(asihpi_pci_tbl) = {
+       {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
+               HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
+               (kernel_ulong_t)HPI_6205},
+       {HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
+               HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
+               (kernel_ulong_t)HPI_6000},
+       {0,}
+};
+MODULE_DEVICE_TABLE(pci, asihpi_pci_tbl);
+
+static struct pci_driver driver = {
+       .name = "asihpi",
+       .id_table = asihpi_pci_tbl,
+       .probe = snd_asihpi_probe,
+       .remove = __devexit_p(snd_asihpi_remove),
+#ifdef CONFIG_PM
+/*     .suspend = snd_asihpi_suspend,
+       .resume = snd_asihpi_resume, */
+#endif
+};
+
+static int __init snd_asihpi_init(void)
+{
+       asihpi_init();
+       return pci_register_driver(&driver);
+}
+
+static void __exit snd_asihpi_exit(void)
+{
+
+       pci_unregister_driver(&driver);
+       asihpi_exit();
+}
+
+module_init(snd_asihpi_init)
+module_exit(snd_asihpi_exit)
+
diff --git a/sound/pci/asihpi/hpi.h b/sound/pci/asihpi/hpi.h
new file mode 100644 (file)
index 0000000..99400de
--- /dev/null
@@ -0,0 +1,2001 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+*/
+/** \file hpi.h
+
+ AudioScience Hardware Programming Interface (HPI)
+ public API definition.
+
+ The HPI is a low-level hardware abstraction layer to all
+ AudioScience digital audio adapters
+*/
+/*
+ You must define one operating system that the HPI is to be compiled under
+ HPI_OS_WIN32_USER   32bit Windows
+ HPI_OS_DSP_C6000    DSP TI C6000  (automatically set)
+ HPI_OS_WDM          Windows WDM kernel driver
+ HPI_OS_LINUX        Linux userspace
+ HPI_OS_LINUX_KERNEL Linux kernel (automatically set)
+
+(C) Copyright AudioScience Inc. 1998-2010
+******************************************************************************/
+#ifndef _HPI_H_
+#define _HPI_H_
+/* HPI Version
+If HPI_VER_MINOR is odd then its a development release not intended for the
+public. If HPI_VER_MINOR is even then is a release version
+i.e 3.05.02 is a development version
+*/
+#define HPI_VERSION_CONSTRUCTOR(maj, min, rel) \
+       ((maj << 16) + (min << 8) + rel)
+
+#define HPI_VER_MAJOR(v) ((int)(v >> 16))
+#define HPI_VER_MINOR(v) ((int)((v >> 8) & 0xFF))
+#define HPI_VER_RELEASE(v) ((int)(v & 0xFF))
+
+/* Use single digits for versions less that 10 to avoid octal. */
+#define HPI_VER HPI_VERSION_CONSTRUCTOR(4L, 3, 18)
+
+/* Library version as documented in hpi-api-versions.txt */
+#define HPI_LIB_VER  HPI_VERSION_CONSTRUCTOR(9, 0, 0)
+
+#include <linux/types.h>
+#define HPI_EXCLUDE_DEPRECATED
+
+/******************************************************************************/
+/******************************************************************************/
+/********       HPI API DEFINITIONS                                       *****/
+/******************************************************************************/
+/******************************************************************************/
+/*******************************************/
+/**  Audio format types
+\ingroup stream
+*/
+enum HPI_FORMATS {
+/** Used internally on adapter. */
+       HPI_FORMAT_MIXER_NATIVE = 0,
+/** 8-bit unsigned PCM. Windows equivalent is WAVE_FORMAT_PCM. */
+       HPI_FORMAT_PCM8_UNSIGNED = 1,
+/** 16-bit signed PCM. Windows equivalent is WAVE_FORMAT_PCM. */
+       HPI_FORMAT_PCM16_SIGNED = 2,
+/** MPEG-1 Layer-1. */
+       HPI_FORMAT_MPEG_L1 = 3,
+/** MPEG-1 Layer-2.
+
+Windows equivalent is WAVE_FORMAT_MPEG.
+
+The following table shows what combinations of mode and bitrate are possible:
+
+<table border=1 cellspacing=0 cellpadding=5>
+<tr>
+<td><p><b>Bitrate (kbs)</b></p>
+<td><p><b>Mono</b></p>
+<td><p><b>Stereo,<br>Joint Stereo or<br>Dual Channel</b></p>
+
+<tr><td>32<td>X<td>_
+<tr><td>40<td>_<td>_
+<tr><td>48<td>X<td>_
+<tr><td>56<td>X<td>_
+<tr><td>64<td>X<td>X
+<tr><td>80<td>X<td>_
+<tr><td>96<td>X<td>X
+<tr><td>112<td>X<td>X
+<tr><td>128<td>X<td>X
+<tr><td>160<td>X<td>X
+<tr><td>192<td>X<td>X
+<tr><td>224<td>_<td>X
+<tr><td>256<td>-<td>X
+<tr><td>320<td>-<td>X
+<tr><td>384<td>_<td>X
+</table>
+*/
+       HPI_FORMAT_MPEG_L2 = 4,
+/** MPEG-1 Layer-3.
+Windows equivalent is WAVE_FORMAT_MPEG.
+
+The following table shows what combinations of mode and bitrate are possible:
+
+<table border=1 cellspacing=0 cellpadding=5>
+<tr>
+<td><p><b>Bitrate (kbs)</b></p>
+<td><p><b>Mono<br>Stereo @ 8,<br>11.025 and<br>12kHz*</b></p>
+<td><p><b>Mono<br>Stereo @ 16,<br>22.050 and<br>24kHz*</b></p>
+<td><p><b>Mono<br>Stereo @ 32,<br>44.1 and<br>48kHz</b></p>
+
+<tr><td>16<td>X<td>X<td>_
+<tr><td>24<td>X<td>X<td>_
+<tr><td>32<td>X<td>X<td>X
+<tr><td>40<td>X<td>X<td>X
+<tr><td>48<td>X<td>X<td>X
+<tr><td>56<td>X<td>X<td>X
+<tr><td>64<td>X<td>X<td>X
+<tr><td>80<td>_<td>X<td>X
+<tr><td>96<td>_<td>X<td>X
+<tr><td>112<td>_<td>X<td>X
+<tr><td>128<td>_<td>X<td>X
+<tr><td>144<td>_<td>X<td>_
+<tr><td>160<td>_<td>X<td>X
+<tr><td>192<td>_<td>_<td>X
+<tr><td>224<td>_<td>_<td>X
+<tr><td>256<td>-<td>_<td>X
+<tr><td>320<td>-<td>_<td>X
+</table>
+\b * Available on the ASI6000 series only
+*/
+       HPI_FORMAT_MPEG_L3 = 5,
+/** Dolby AC-2. */
+       HPI_FORMAT_DOLBY_AC2 = 6,
+/** Dolbt AC-3. */
+       HPI_FORMAT_DOLBY_AC3 = 7,
+/** 16-bit PCM big-endian. */
+       HPI_FORMAT_PCM16_BIGENDIAN = 8,
+/** TAGIT-1 algorithm - hits. */
+       HPI_FORMAT_AA_TAGIT1_HITS = 9,
+/** TAGIT-1 algorithm - inserts. */
+       HPI_FORMAT_AA_TAGIT1_INSERTS = 10,
+/** 32-bit signed PCM. Windows equivalent is WAVE_FORMAT_PCM.
+Each sample is a 32bit word. The most significant 24 bits contain a 24-bit
+sample and the least significant 8 bits are set to 0.
+*/
+       HPI_FORMAT_PCM32_SIGNED = 11,
+/** Raw bitstream - unknown format. */
+       HPI_FORMAT_RAW_BITSTREAM = 12,
+/** TAGIT-1 algorithm hits - extended. */
+       HPI_FORMAT_AA_TAGIT1_HITS_EX1 = 13,
+/** 32-bit PCM as an IEEE float. Windows equivalent is WAVE_FORMAT_IEEE_FLOAT.
+Each sample is a 32bit word in IEEE754 floating point format.
+The range is +1.0 to -1.0, which corresponds to digital fullscale.
+*/
+       HPI_FORMAT_PCM32_FLOAT = 14,
+/** 24-bit PCM signed. Windows equivalent is WAVE_FORMAT_PCM. */
+       HPI_FORMAT_PCM24_SIGNED = 15,
+/** OEM format 1 - private. */
+       HPI_FORMAT_OEM1 = 16,
+/** OEM format 2 - private. */
+       HPI_FORMAT_OEM2 = 17,
+/** Undefined format. */
+       HPI_FORMAT_UNDEFINED = 0xffff
+};
+
+/******************************************* in/out Stream states */
+/*******************************************/
+/** Stream States
+\ingroup stream
+*/
+enum HPI_STREAM_STATES {
+       /** State stopped - stream is stopped. */
+       HPI_STATE_STOPPED = 1,
+       /** State playing - stream is playing audio. */
+       HPI_STATE_PLAYING = 2,
+       /** State recording - stream is recording. */
+       HPI_STATE_RECORDING = 3,
+       /** State drained - playing stream ran out of data to play. */
+       HPI_STATE_DRAINED = 4,
+       /** State generate sine - to be implemented. */
+       HPI_STATE_SINEGEN = 5,
+       /** State wait - used for inter-card sync to mean waiting for all
+               cards to be ready. */
+       HPI_STATE_WAIT = 6
+};
+/******************************************* mixer source node types */
+/** Source node types
+\ingroup mixer
+*/
+enum HPI_SOURCENODES {
+       /** This define can be used instead of 0 to indicate
+       that there is no valid source node. A control that
+       exists on a destination node can be searched for using a source
+       node value of either 0, or HPI_SOURCENODE_NONE */
+       HPI_SOURCENODE_NONE = 100,
+       /** \deprecated Use HPI_SOURCENODE_NONE instead. */
+       HPI_SOURCENODE_BASE = 100,
+       /** Out Stream (Play) node. */
+       HPI_SOURCENODE_OSTREAM = 101,
+       /** Line in node - could be analog, AES/EBU or network. */
+       HPI_SOURCENODE_LINEIN = 102,
+       HPI_SOURCENODE_AESEBU_IN = 103,      /**< AES/EBU input node. */
+       HPI_SOURCENODE_TUNER = 104,          /**< tuner node. */
+       HPI_SOURCENODE_RF = 105,             /**< RF input node. */
+       HPI_SOURCENODE_CLOCK_SOURCE = 106,   /**< clock source node. */
+       HPI_SOURCENODE_RAW_BITSTREAM = 107,  /**< raw bitstream node. */
+       HPI_SOURCENODE_MICROPHONE = 108,     /**< microphone node. */
+       /** Cobranet input node -
+           Audio samples come from the Cobranet network and into the device. */
+       HPI_SOURCENODE_COBRANET = 109,
+       HPI_SOURCENODE_ANALOG = 110,         /**< analog input node. */
+       HPI_SOURCENODE_ADAPTER = 111,        /**< adapter node. */
+       /* !!!Update this  AND hpidebug.h if you add a new sourcenode type!!! */
+       HPI_SOURCENODE_LAST_INDEX = 111      /**< largest ID */
+               /* AX6 max sourcenode types = 15 */
+};
+
+/******************************************* mixer dest node types */
+/** Destination node types
+\ingroup mixer
+*/
+enum HPI_DESTNODES {
+       /** This define can be used instead of 0 to indicate
+       that there is no valid destination node. A control that
+       exists on a source node can be searched for using a destination
+       node value of either 0, or HPI_DESTNODE_NONE */
+       HPI_DESTNODE_NONE = 200,
+       /** \deprecated Use HPI_DESTNODE_NONE instead. */
+       HPI_DESTNODE_BASE = 200,
+       /** In Stream (Record) node. */
+       HPI_DESTNODE_ISTREAM = 201,
+       HPI_DESTNODE_LINEOUT = 202,         /**< line out node. */
+       HPI_DESTNODE_AESEBU_OUT = 203,       /**< AES/EBU output node. */
+       HPI_DESTNODE_RF = 204,               /**< RF output node. */
+       HPI_DESTNODE_SPEAKER = 205,          /**< speaker output node. */
+       /** Cobranet output node -
+           Audio samples from the device are sent out on the Cobranet network.*/
+       HPI_DESTNODE_COBRANET = 206,
+       HPI_DESTNODE_ANALOG = 207,           /**< analog output node. */
+
+       /* !!!Update this AND hpidebug.h if you add a new destnode type!!! */
+       HPI_DESTNODE_LAST_INDEX = 207        /**< largest ID */
+               /* AX6 max destnode types = 15 */
+};
+
+/*******************************************/
+/** Mixer control types
+\ingroup mixer
+*/
+enum HPI_CONTROLS {
+       HPI_CONTROL_GENERIC = 0,        /**< generic control. */
+       HPI_CONTROL_CONNECTION = 1, /**< A connection between nodes. */
+       HPI_CONTROL_VOLUME = 2,       /**< volume control - works in dB_fs. */
+       HPI_CONTROL_METER = 3,  /**< peak meter control. */
+       HPI_CONTROL_MUTE = 4,   /*mute control - not used at present. */
+       HPI_CONTROL_MULTIPLEXER = 5,    /**< multiplexer control. */
+
+       HPI_CONTROL_AESEBU_TRANSMITTER = 6,     /**< AES/EBU transmitter control. */
+       HPI_CONTROL_AESEBUTX = HPI_CONTROL_AESEBU_TRANSMITTER,
+
+       HPI_CONTROL_AESEBU_RECEIVER = 7, /**< AES/EBU receiver control. */
+       HPI_CONTROL_AESEBURX = HPI_CONTROL_AESEBU_RECEIVER,
+
+       HPI_CONTROL_LEVEL = 8, /**< level/trim control - works in d_bu. */
+       HPI_CONTROL_TUNER = 9,  /**< tuner control. */
+/*      HPI_CONTROL_ONOFFSWITCH =       10 */
+       HPI_CONTROL_VOX = 11,   /**< vox control. */
+/*      HPI_CONTROL_AES18_TRANSMITTER = 12 */
+/*      HPI_CONTROL_AES18_RECEIVER = 13 */
+/*      HPI_CONTROL_AES18_BLOCKGENERATOR  = 14 */
+       HPI_CONTROL_CHANNEL_MODE = 15,  /**< channel mode control. */
+
+       HPI_CONTROL_BITSTREAM = 16,     /**< bitstream control. */
+       HPI_CONTROL_SAMPLECLOCK = 17,   /**< sample clock control. */
+       HPI_CONTROL_MICROPHONE = 18,    /**< microphone control. */
+       HPI_CONTROL_PARAMETRIC_EQ = 19, /**< parametric EQ control. */
+       HPI_CONTROL_EQUALIZER = HPI_CONTROL_PARAMETRIC_EQ,
+
+       HPI_CONTROL_COMPANDER = 20,     /**< compander control. */
+       HPI_CONTROL_COBRANET = 21,      /**< cobranet control. */
+       HPI_CONTROL_TONEDETECTOR = 22,  /**< tone detector control. */
+       HPI_CONTROL_SILENCEDETECTOR = 23,       /**< silence detector control. */
+       HPI_CONTROL_PAD = 24,   /**< tuner PAD control. */
+       HPI_CONTROL_SRC = 25,   /**< samplerate converter control. */
+       HPI_CONTROL_UNIVERSAL = 26,     /**< universal control. */
+
+/*  !!! Update this AND hpidebug.h if you add a new control type!!!*/
+       HPI_CONTROL_LAST_INDEX = 26 /**<highest control type ID */
+/* WARNING types 256 or greater impact bit packing in all AX6 DSP code */
+};
+
+/* Shorthand names that match attribute names */
+
+/******************************************* ADAPTER ATTRIBUTES ****/
+
+/** Adapter properties
+These are used in HPI_AdapterSetProperty() and HPI_AdapterGetProperty()
+\ingroup adapter
+*/
+enum HPI_ADAPTER_PROPERTIES {
+/** \internal Used in dwProperty field of HPI_AdapterSetProperty() and
+HPI_AdapterGetProperty(). This errata applies to all ASI6000 cards with both
+analog and digital outputs. The CS4224 A/D+D/A has a one sample delay between
+left and right channels on both its input (ADC) and output (DAC).
+More details are available in Cirrus Logic errata ER284B2.
+PDF available from www.cirrus.com, released by Cirrus in 2001.
+*/
+       HPI_ADAPTER_PROPERTY_ERRATA_1 = 1,
+
+/** Adapter grouping property
+Indicates whether the adapter supports the grouping API (for ASIO and SSX2)
+*/
+       HPI_ADAPTER_PROPERTY_GROUPING = 2,
+
+/** Driver SSX2 property
+Tells the kernel driver to turn on SSX2 stream mapping.
+This feature is not used by the DSP. In fact the call is completely processed
+by the driver and is not passed on to the DSP at all.
+*/
+       HPI_ADAPTER_PROPERTY_ENABLE_SSX2 = 3,
+
+/** Adapter SSX2 property
+Indicates the state of the adapter's SSX2 setting. This setting is stored in
+non-volatile memory on the adapter. A typical call sequence would be to use
+HPI_ADAPTER_PROPERTY_SSX2_SETTING to set SSX2 on the adapter and then to reload
+the driver. The driver would query HPI_ADAPTER_PROPERTY_SSX2_SETTING during startup
+and if SSX2 is set, it would then call HPI_ADAPTER_PROPERTY_ENABLE_SSX2 to enable
+SSX2 stream mapping within the kernel level of the driver.
+*/
+       HPI_ADAPTER_PROPERTY_SSX2_SETTING = 4,
+
+/** Base number for readonly properties */
+       HPI_ADAPTER_PROPERTY_READONLYBASE = 256,
+
+/** Readonly adapter latency property.
+This property returns in the input and output latency in samples.
+Property 1 is the estimated input latency
+in samples, while Property 2 is that output latency in  samples.
+*/
+       HPI_ADAPTER_PROPERTY_LATENCY = 256,
+
+/** Readonly adapter granularity property.
+The granulariy is the smallest size chunk of stereo samples that is processed by
+the adapter.
+This property returns the record granularity in samples in Property 1.
+Property 2 returns the play granularity.
+*/
+       HPI_ADAPTER_PROPERTY_GRANULARITY = 257,
+
+/** Readonly adapter number of current channels property.
+Property 1 is the number of record channels per record device.
+Property 2 is the number of play channels per playback device.*/
+       HPI_ADAPTER_PROPERTY_CURCHANNELS = 258,
+
+/** Readonly adapter software version.
+The SOFTWARE_VERSION property returns the version of the software running
+on the adapter as Major.Minor.Release.
+Property 1 contains Major in bits 15..8 and Minor in bits 7..0.
+Property 2 contains Release in bits 7..0. */
+       HPI_ADAPTER_PROPERTY_SOFTWARE_VERSION = 259,
+
+/** Readonly adapter MAC address MSBs.
+The MAC_ADDRESS_MSB property returns
+the most significant 32 bits of the MAC address.
+Property 1 contains bits 47..32 of the MAC address.
+Property 2 contains bits 31..16 of the MAC address. */
+       HPI_ADAPTER_PROPERTY_MAC_ADDRESS_MSB = 260,
+
+/** Readonly adapter MAC address LSBs
+The MAC_ADDRESS_LSB property returns
+the least significant 16 bits of the MAC address.
+Property 1 contains bits 15..0 of the MAC address. */
+       HPI_ADAPTER_PROPERTY_MAC_ADDRESS_LSB = 261,
+
+/** Readonly extended adapter type number
+The EXTENDED_ADAPTER_TYPE property returns the 4 digits of an extended
+adapter type, i.e ASI8920-0022, 0022 is the extended type.
+The digits are returned as ASCII characters rather than the hex digits that
+are returned for the main type
+Property 1 returns the 1st two (left most) digits, i.e "00"
+in the example above, the upper byte being the left most digit.
+Property 2 returns the 2nd two digits, i.e "22" in the example above*/
+       HPI_ADAPTER_PROPERTY_EXTENDED_ADAPTER_TYPE = 262,
+
+/** Readonly debug log buffer information */
+       HPI_ADAPTER_PROPERTY_LOGTABLEN = 263,
+       HPI_ADAPTER_PROPERTY_LOGTABBEG = 264,
+
+/** Readonly adapter IP address
+For 192.168.1.101
+Property 1 returns the 1st two (left most) digits, i.e 192*256 + 168
+in the example above, the upper byte being the left most digit.
+Property 2 returns the 2nd two digits, i.e 1*256 + 101 in the example above, */
+       HPI_ADAPTER_PROPERTY_IP_ADDRESS = 265,
+
+/** Readonly adapter buffer processed count. Returns a buffer processed count
+that is incremented every time all buffers for all streams are updated. This
+is useful for checking completion of all stream operations across the adapter
+when using grouped streams.
+*/
+       HPI_ADAPTER_PROPERTY_BUFFER_UPDATE_COUNT = 266,
+
+/** Readonly mixer and stream intervals
+
+These intervals are  measured in mixer frames.
+To convert to time, divide  by the adapter samplerate.
+
+The mixer interval is the number of frames processed in one mixer iteration.
+The stream update interval is the interval at which streams check for and
+process data, and BBM host buffer counters are updated.
+
+Property 1 is the mixer interval in mixer frames.
+Property 2 is the stream update interval in mixer frames.
+*/
+       HPI_ADAPTER_PROPERTY_INTERVAL = 267,
+/** Adapter capabilities 1
+Property 1 - adapter can do multichannel (SSX1)
+Property 2 - adapter can do stream grouping (supports SSX2)
+*/
+       HPI_ADAPTER_PROPERTY_CAPS1 = 268,
+/** Adapter capabilities 2
+Property 1 - adapter can do samplerate conversion (MRX)
+Property 2 - adapter can do timestretch (TSX)
+*/
+       HPI_ADAPTER_PROPERTY_CAPS2 = 269
+};
+
+/** Adapter mode commands
+
+Used in wQueryOrSet field of HPI_AdapterSetModeEx().
+\ingroup adapter
+*/
+enum HPI_ADAPTER_MODE_CMDS {
+       HPI_ADAPTER_MODE_SET = 0,
+       HPI_ADAPTER_MODE_QUERY = 1
+};
+
+/** Adapter Modes
+       These are used by HPI_AdapterSetModeEx()
+
+\warning - more than 16 possible modes breaks
+a bitmask in the Windows WAVE DLL
+\ingroup adapter
+*/
+enum HPI_ADAPTER_MODES {
+/** 4 outstream mode.
+- ASI6114: 1 instream
+- ASI6044: 4 instreams
+- ASI6012: 1 instream
+- ASI6102: no instreams
+- ASI6022, ASI6122: 2 instreams
+- ASI5111, ASI5101: 2 instreams
+- ASI652x, ASI662x: 2 instreams
+- ASI654x, ASI664x: 4 instreams
+*/
+       HPI_ADAPTER_MODE_4OSTREAM = 1,
+
+/** 6 outstream mode.
+- ASI6012: 1 instream,
+- ASI6022, ASI6122: 2 instreams
+- ASI652x, ASI662x: 4 instreams
+*/
+       HPI_ADAPTER_MODE_6OSTREAM = 2,
+
+/** 8 outstream mode.
+- ASI6114: 8 instreams
+- ASI6118: 8 instreams
+- ASI6585: 8 instreams
+*/
+       HPI_ADAPTER_MODE_8OSTREAM = 3,
+
+/** 16 outstream mode.
+- ASI6416 16 instreams
+- ASI6518, ASI6618 16 instreams
+- ASI6118 16 mono out and in streams
+*/
+       HPI_ADAPTER_MODE_16OSTREAM = 4,
+
+/** one outstream mode.
+- ASI5111 1 outstream, 1 instream
+*/
+       HPI_ADAPTER_MODE_1OSTREAM = 5,
+
+/** ASI504X mode 1. 12 outstream, 4 instream 0 to 48kHz sample rates
+       (see ASI504X datasheet for more info).
+*/
+       HPI_ADAPTER_MODE_1 = 6,
+
+/** ASI504X mode 2. 4 outstreams, 4 instreams at 0 to 192kHz sample rates
+       (see ASI504X datasheet for more info).
+*/
+       HPI_ADAPTER_MODE_2 = 7,
+
+/** ASI504X mode 3. 4 outstreams, 4 instreams at 0 to 192kHz sample rates
+       (see ASI504X datasheet for more info).
+*/
+       HPI_ADAPTER_MODE_3 = 8,
+
+/** ASI504X multichannel mode.
+       2 outstreams -> 4 line outs = 1 to 8 channel streams),
+       4 lineins -> 1 instream (1 to 8 channel streams) at 0-48kHz.
+       For more info see the SSX Specification.
+*/
+       HPI_ADAPTER_MODE_MULTICHANNEL = 9,
+
+/** 12 outstream mode.
+- ASI6514, ASI6614: 2 instreams
+- ASI6540,ASI6544: 8 instreams
+- ASI6640,ASI6644: 8 instreams
+*/
+       HPI_ADAPTER_MODE_12OSTREAM = 10,
+
+/** 9 outstream mode.
+- ASI6044: 8 instreams
+*/
+       HPI_ADAPTER_MODE_9OSTREAM = 11,
+
+/** mono mode.
+- ASI6416: 16 outstreams/instreams
+- ASI5402: 2 outstreams/instreams
+*/
+       HPI_ADAPTER_MODE_MONO = 12,
+
+/** Low latency mode.
+- ASI6416/ASI6316: 1 16 channel outstream and instream
+*/
+       HPI_ADAPTER_MODE_LOW_LATENCY = 13
+};
+
+/* Note, adapters can have more than one capability -
+encoding as bitfield is recommended. */
+#define HPI_CAPABILITY_NONE             (0)
+#define HPI_CAPABILITY_MPEG_LAYER3      (1)
+
+/* Set this equal to maximum capability index,
+Must not be greater than 32 - see axnvdef.h */
+#define HPI_CAPABILITY_MAX                      1
+/* #define HPI_CAPABILITY_AAC              2 */
+
+/******************************************* STREAM ATTRIBUTES ****/
+
+/** MPEG Ancillary Data modes
+
+The mode for the ancillary data insertion or extraction to operate in.
+\ingroup stream
+*/
+enum HPI_MPEG_ANC_MODES {
+       /** the MPEG frames have energy information stored in them (5 bytes per stereo frame, 3 per mono) */
+       HPI_MPEG_ANC_HASENERGY = 0,
+       /** the entire ancillary data field is taken up by data from the Anc data buffer
+       On encode, the encoder will insert the energy bytes before filling the remainder
+       of the ancillary data space with data from the ancillary data buffer.
+       */
+       HPI_MPEG_ANC_RAW = 1
+};
+
+/** Ancillary Data Alignment
+\ingroup instream
+*/
+enum HPI_ISTREAM_MPEG_ANC_ALIGNS {
+       /** data is packed against the end of data, then padded to the end of frame */
+       HPI_MPEG_ANC_ALIGN_LEFT = 0,
+       /** data is packed against the end of the frame */
+       HPI_MPEG_ANC_ALIGN_RIGHT = 1
+};
+
+/** MPEG modes
+MPEG modes - can be used optionally for HPI_FormatCreate()
+parameter dwAttributes.
+
+Using any mode setting other than HPI_MPEG_MODE_DEFAULT
+with single channel format will return an error.
+\ingroup stream
+*/
+enum HPI_MPEG_MODES {
+/** Causes the MPEG-1 Layer II bitstream to be recorded
+in single_channel mode when the number of channels is 1 and in stereo when the
+number of channels is 2. */
+       HPI_MPEG_MODE_DEFAULT = 0,
+       /** Standard stereo without joint-stereo compression */
+       HPI_MPEG_MODE_STEREO = 1,
+       /** Joint stereo  */
+       HPI_MPEG_MODE_JOINTSTEREO = 2,
+       /** Left and Right channels are completely independent */
+       HPI_MPEG_MODE_DUALCHANNEL = 3
+};
+/******************************************* MIXER ATTRIBUTES ****/
+
+/* \defgroup mixer_flags Mixer flags for HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES
+{
+*/
+#define HPI_MIXER_GET_CONTROL_MULTIPLE_CHANGED  (0)
+#define HPI_MIXER_GET_CONTROL_MULTIPLE_RESET    (1)
+/*}*/
+
+/** Commands used by HPI_MixerStore()
+\ingroup mixer
+*/
+enum HPI_MIXER_STORE_COMMAND {
+/** Save all mixer control settings. */
+       HPI_MIXER_STORE_SAVE = 1,
+/** Restore all controls from saved. */
+       HPI_MIXER_STORE_RESTORE = 2,
+/** Delete saved control settings. */
+       HPI_MIXER_STORE_DELETE = 3,
+/** Enable auto storage of some control settings. */
+       HPI_MIXER_STORE_ENABLE = 4,
+/** Disable auto storage of some control settings. */
+       HPI_MIXER_STORE_DISABLE = 5,
+/** Save the attributes of a single control. */
+       HPI_MIXER_STORE_SAVE_SINGLE = 6
+};
+
+/************************************* CONTROL ATTRIBUTE VALUES ****/
+/** Used by mixer plugin enable functions
+
+E.g. HPI_ParametricEQ_SetState()
+\ingroup mixer
+*/
+enum HPI_SWITCH_STATES {
+       HPI_SWITCH_OFF = 0,     /**< turn the mixer plugin on. */
+       HPI_SWITCH_ON = 1       /**< turn the mixer plugin off. */
+};
+
+/* Volume control special gain values */
+/** volumes units are 100ths of a dB
+\ingroup volume
+*/
+#define HPI_UNITS_PER_dB                100
+/** turns volume control OFF or MUTE
+\ingroup volume
+*/
+#define HPI_GAIN_OFF                    (-100 * HPI_UNITS_PER_dB)
+
+/** value returned for no signal
+\ingroup meter
+*/
+#define HPI_METER_MINIMUM               (-150 * HPI_UNITS_PER_dB)
+
+/** autofade profiles
+\ingroup volume
+*/
+enum HPI_VOLUME_AUTOFADES {
+/** log fade - dB attenuation changes linearly over time */
+       HPI_VOLUME_AUTOFADE_LOG = 2,
+/** linear fade - amplitude changes linearly */
+       HPI_VOLUME_AUTOFADE_LINEAR = 3
+};
+
+/** The physical encoding format of the AESEBU I/O.
+
+Used in HPI_AESEBU_Transmitter_SetFormat(), HPI_AESEBU_Receiver_SetFormat()
+along with related Get and Query functions
+\ingroup aestx
+*/
+enum HPI_AESEBU_FORMATS {
+/** AES/EBU physical format - AES/EBU balanced "professional"  */
+       HPI_AESEBU_FORMAT_AESEBU = 1,
+/** AES/EBU physical format - S/PDIF unbalanced "consumer"      */
+       HPI_AESEBU_FORMAT_SPDIF = 2
+};
+
+/** AES/EBU error status bits
+
+Returned by HPI_AESEBU_Receiver_GetErrorStatus()
+\ingroup aesrx
+*/
+enum HPI_AESEBU_ERRORS {
+/**  bit0: 1 when PLL is not locked */
+       HPI_AESEBU_ERROR_NOT_LOCKED = 0x01,
+/**  bit1: 1 when signal quality is poor */
+       HPI_AESEBU_ERROR_POOR_QUALITY = 0x02,
+/** bit2: 1 when there is a parity error */
+       HPI_AESEBU_ERROR_PARITY_ERROR = 0x04,
+/**  bit3: 1 when there is a bi-phase coding violation */
+       HPI_AESEBU_ERROR_BIPHASE_VIOLATION = 0x08,
+/**  bit4: 1 when the validity bit is high */
+       HPI_AESEBU_ERROR_VALIDITY = 0x10,
+/**  bit5: 1 when the CRC error bit is high */
+       HPI_AESEBU_ERROR_CRC = 0x20
+};
+
+/** \addtogroup pad
+\{
+*/
+/** The text string containing the station/channel combination. */
+#define HPI_PAD_CHANNEL_NAME_LEN        16
+/** The text string containing the artist. */
+#define HPI_PAD_ARTIST_LEN              64
+/** The text string containing the title. */
+#define HPI_PAD_TITLE_LEN               64
+/** The text string containing the comment. */
+#define HPI_PAD_COMMENT_LEN             256
+/** The PTY when the tuner has not recieved any PTY. */
+#define HPI_PAD_PROGRAM_TYPE_INVALID    0xffff
+/** \} */
+
+/** Data types for PTY string translation.
+\ingroup rds
+*/
+enum eHPI_RDS_type {
+       HPI_RDS_DATATYPE_RDS = 0,       /**< RDS bitstream.*/
+       HPI_RDS_DATATYPE_RBDS = 1       /**< RBDS bitstream.*/
+};
+
+/** Tuner bands
+
+Used for HPI_Tuner_SetBand(),HPI_Tuner_GetBand()
+\ingroup tuner
+*/
+enum HPI_TUNER_BAND {
+       HPI_TUNER_BAND_AM = 1,   /**< AM band */
+       HPI_TUNER_BAND_FM = 2,   /**< FM band (mono) */
+       HPI_TUNER_BAND_TV_NTSC_M = 3,    /**< NTSC-M TV band*/
+       HPI_TUNER_BAND_TV = 3,  /* use TV_NTSC_M */
+       HPI_TUNER_BAND_FM_STEREO = 4,    /**< FM band (stereo) */
+       HPI_TUNER_BAND_AUX = 5,  /**< auxiliary input */
+       HPI_TUNER_BAND_TV_PAL_BG = 6,    /**< PAL-B/G TV band*/
+       HPI_TUNER_BAND_TV_PAL_I = 7,     /**< PAL-I TV band*/
+       HPI_TUNER_BAND_TV_PAL_DK = 8,    /**< PAL-D/K TV band*/
+       HPI_TUNER_BAND_TV_SECAM_L = 9,   /**< SECAM-L TV band*/
+       HPI_TUNER_BAND_LAST = 9 /**< the index of the last tuner band. */
+};
+
+/** Tuner mode attributes
+
+Used by HPI_Tuner_SetMode(), HPI_Tuner_GetMode()
+\ingroup tuner
+
+*/
+enum HPI_TUNER_MODES {
+       HPI_TUNER_MODE_RSS = 1, /**< control  RSS */
+       HPI_TUNER_MODE_RDS = 2  /**< control  RBDS/RDS */
+};
+
+/** Tuner mode attribute values
+
+Used by HPI_Tuner_SetMode(), HPI_Tuner_GetMode()
+\ingroup tuner
+*/
+enum HPI_TUNER_MODE_VALUES {
+/* RSS attribute values */
+       HPI_TUNER_MODE_RSS_DISABLE = 0, /**< RSS disable */
+       HPI_TUNER_MODE_RSS_ENABLE = 1,  /**< RSS enable */
+
+/* RDS mode attributes */
+       HPI_TUNER_MODE_RDS_DISABLE = 0, /**< RDS - disabled */
+       HPI_TUNER_MODE_RDS_RDS = 1,  /**< RDS - RDS mode */
+       HPI_TUNER_MODE_RDS_RBDS = 2 /**<  RDS - RBDS mode */
+};
+
+/** Tuner Level settings
+\ingroup tuner
+*/
+enum HPI_TUNER_LEVEL {
+       HPI_TUNER_LEVEL_AVERAGE = 0,
+       HPI_TUNER_LEVEL_RAW = 1
+};
+
+/** Tuner Status Bits
+
+These bitfield values are returned by a call to HPI_Tuner_GetStatus().
+Multiple fields are returned from a single call.
+\ingroup tuner
+*/
+enum HPI_TUNER_STATUS_BITS {
+       HPI_TUNER_VIDEO_COLOR_PRESENT = 0x0001, /**< video color is present. */
+       HPI_TUNER_VIDEO_IS_60HZ = 0x0020,       /**< 60 hz video detected. */
+       HPI_TUNER_VIDEO_HORZ_SYNC_MISSING = 0x0040,     /**< video HSYNC is missing. */
+       HPI_TUNER_VIDEO_STATUS_VALID = 0x0100,  /**< video status is valid. */
+       HPI_TUNER_PLL_LOCKED = 0x1000,          /**< the tuner's PLL is locked. */
+       HPI_TUNER_FM_STEREO = 0x2000,           /**< tuner reports back FM stereo. */
+       HPI_TUNER_DIGITAL = 0x0200,             /**< tuner reports digital programming. */
+       HPI_TUNER_MULTIPROGRAM = 0x0400         /**< tuner reports multiple programs. */
+};
+
+/** Channel Modes
+Used for HPI_ChannelModeSet/Get()
+\ingroup channelmode
+*/
+enum HPI_CHANNEL_MODES {
+/** Left channel out = left channel in, Right channel out = right channel in. */
+       HPI_CHANNEL_MODE_NORMAL = 1,
+/** Left channel out = right channel in, Right channel out = left channel in. */
+       HPI_CHANNEL_MODE_SWAP = 2,
+/** Left channel out = left channel in, Right channel out = left channel in. */
+       HPI_CHANNEL_MODE_LEFT_TO_STEREO = 3,
+/** Left channel out = right channel in, Right channel out = right channel in.*/
+       HPI_CHANNEL_MODE_RIGHT_TO_STEREO = 4,
+/** Left channel out = (left channel in + right channel in)/2,
+    Right channel out = mute. */
+       HPI_CHANNEL_MODE_STEREO_TO_LEFT = 5,
+/** Left channel out = mute,
+    Right channel out = (right channel in + left channel in)/2. */
+       HPI_CHANNEL_MODE_STEREO_TO_RIGHT = 6,
+       HPI_CHANNEL_MODE_LAST = 6
+};
+
+/** SampleClock source values
+\ingroup sampleclock
+*/
+enum HPI_SAMPLECLOCK_SOURCES {
+/** The sampleclock output is derived from its local samplerate generator.
+    The local samplerate may be set using HPI_SampleClock_SetLocalRate(). */
+       HPI_SAMPLECLOCK_SOURCE_LOCAL = 1,
+/** \deprecated Use HPI_SAMPLECLOCK_SOURCE_LOCAL instead */
+       HPI_SAMPLECLOCK_SOURCE_ADAPTER = 1,
+/** The adapter is clocked from a dedicated AES/EBU SampleClock input.*/
+       HPI_SAMPLECLOCK_SOURCE_AESEBU_SYNC = 2,
+/** From external wordclock connector */
+       HPI_SAMPLECLOCK_SOURCE_WORD = 3,
+/** Board-to-board header */
+       HPI_SAMPLECLOCK_SOURCE_WORD_HEADER = 4,
+/** FUTURE - SMPTE clock. */
+       HPI_SAMPLECLOCK_SOURCE_SMPTE = 5,
+/** One of the aesebu inputs */
+       HPI_SAMPLECLOCK_SOURCE_AESEBU_INPUT = 6,
+/** \deprecated The first aesebu input with a valid signal
+Superseded by separate Auto enable flag
+*/
+       HPI_SAMPLECLOCK_SOURCE_AESEBU_AUTO = 7,
+/** From a network interface e.g. Cobranet or Livewire at either 48 or 96kHz */
+       HPI_SAMPLECLOCK_SOURCE_NETWORK = 8,
+/** From previous adjacent module (ASI2416 only)*/
+       HPI_SAMPLECLOCK_SOURCE_PREV_MODULE = 10,
+/*! Update this if you add a new clock source.*/
+       HPI_SAMPLECLOCK_SOURCE_LAST = 10
+};
+
+/** Equalizer filter types. Used by HPI_ParametricEQ_SetBand()
+\ingroup parmeq
+*/
+enum HPI_FILTER_TYPE {
+       HPI_FILTER_TYPE_BYPASS = 0,     /**< filter is turned off */
+
+       HPI_FILTER_TYPE_LOWSHELF = 1,   /**< EQ low shelf */
+       HPI_FILTER_TYPE_HIGHSHELF = 2,  /**< EQ high shelf */
+       HPI_FILTER_TYPE_EQ_BAND = 3,    /**< EQ gain */
+
+       HPI_FILTER_TYPE_LOWPASS = 4,    /**< standard low pass */
+       HPI_FILTER_TYPE_HIGHPASS = 5,   /**< standard high pass */
+       HPI_FILTER_TYPE_BANDPASS = 6,   /**< standard band pass */
+       HPI_FILTER_TYPE_BANDSTOP = 7    /**< standard band stop/notch */
+};
+
+/** Async Event sources
+\ingroup async
+*/
+enum ASYNC_EVENT_SOURCES {
+       HPI_ASYNC_EVENT_GPIO = 1,       /**< GPIO event. */
+       HPI_ASYNC_EVENT_SILENCE = 2,    /**< silence event detected. */
+       HPI_ASYNC_EVENT_TONE = 3        /**< tone event detected. */
+};
+/*******************************************/
+/** HPI Error codes
+
+Almost all HPI functions return an error code
+A return value of zero means there was no error.
+Otherwise one of these error codes is returned.
+Error codes can be converted to a descriptive string using HPI_GetErrorText()
+
+\note When a new error code is added HPI_GetErrorText() MUST be updated.
+\note Codes 1-100 are reserved for driver use
+\ingroup utility
+*/
+enum HPI_ERROR_CODES {
+       /** Message type does not exist. */
+       HPI_ERROR_INVALID_TYPE = 100,
+       /** Object type does not exist. */
+       HPI_ERROR_INVALID_OBJ = 101,
+       /** Function does not exist. */
+       HPI_ERROR_INVALID_FUNC = 102,
+       /** The specified object (adapter/Stream) does not exist. */
+       HPI_ERROR_INVALID_OBJ_INDEX = 103,
+       /** Trying to access an object that has not been opened yet. */
+       HPI_ERROR_OBJ_NOT_OPEN = 104,
+       /** Trying to open an already open object. */
+       HPI_ERROR_OBJ_ALREADY_OPEN = 105,
+       /** PCI, ISA resource not valid. */
+       HPI_ERROR_INVALID_RESOURCE = 106,
+       /** GetInfo call from SubSysFindAdapters failed. */
+       HPI_ERROR_SUBSYSFINDADAPTERS_GETINFO = 107,
+       /** Default response was never updated with actual error code. */
+       HPI_ERROR_INVALID_RESPONSE = 108,
+       /** wSize field of response was not updated,
+       indicating that the message was not processed. */
+       HPI_ERROR_PROCESSING_MESSAGE = 109,
+       /** The network did not respond in a timely manner. */
+       HPI_ERROR_NETWORK_TIMEOUT = 110,
+       /** An HPI handle is invalid (uninitialised?). */
+       HPI_ERROR_INVALID_HANDLE = 111,
+       /** A function or attribute has not been implemented yet. */
+       HPI_ERROR_UNIMPLEMENTED = 112,
+       /** There are too many clients attempting to access a network resource. */
+       HPI_ERROR_NETWORK_TOO_MANY_CLIENTS = 113,
+       /** Response buffer passed to HPI_Message was smaller than returned response */
+       HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL = 114,
+       /** The returned response did not match the sent message */
+       HPI_ERROR_RESPONSE_MISMATCH = 115,
+
+       /** Too many adapters.*/
+       HPI_ERROR_TOO_MANY_ADAPTERS = 200,
+       /** Bad adpater. */
+       HPI_ERROR_BAD_ADAPTER = 201,
+       /** Adapter number out of range or not set properly. */
+       HPI_ERROR_BAD_ADAPTER_NUMBER = 202,
+       /** 2 adapters with the same adapter number. */
+       HPI_DUPLICATE_ADAPTER_NUMBER = 203,
+       /** DSP code failed to bootload. */
+       HPI_ERROR_DSP_BOOTLOAD = 204,
+       /** Adapter failed DSP code self test. */
+       HPI_ERROR_DSP_SELFTEST = 205,
+       /** Couldn't find or open the DSP code file. */
+       HPI_ERROR_DSP_FILE_NOT_FOUND = 206,
+       /** Internal DSP hardware error. */
+       HPI_ERROR_DSP_HARDWARE = 207,
+       /** Could not allocate memory in DOS. */
+       HPI_ERROR_DOS_MEMORY_ALLOC = 208,
+       /** Could not allocate memory */
+       HPI_ERROR_MEMORY_ALLOC = 208,
+       /** Failed to correctly load/config PLD .*/
+       HPI_ERROR_PLD_LOAD = 209,
+       /** Unexpected end of file, block length too big etc. */
+       HPI_ERROR_DSP_FILE_FORMAT = 210,
+
+       /** Found but could not open DSP code file. */
+       HPI_ERROR_DSP_FILE_ACCESS_DENIED = 211,
+       /** First DSP code section header not found in DSP file. */
+       HPI_ERROR_DSP_FILE_NO_HEADER = 212,
+       /** File read operation on DSP code file failed. */
+       HPI_ERROR_DSP_FILE_READ_ERROR = 213,
+       /** DSP code for adapter family not found. */
+       HPI_ERROR_DSP_SECTION_NOT_FOUND = 214,
+       /** Other OS specific error opening DSP file. */
+       HPI_ERROR_DSP_FILE_OTHER_ERROR = 215,
+       /** Sharing violation opening DSP code file. */
+       HPI_ERROR_DSP_FILE_SHARING_VIOLATION = 216,
+       /** DSP code section header had size == 0. */
+       HPI_ERROR_DSP_FILE_NULL_HEADER = 217,
+
+       /** Base number for flash errors. */
+       HPI_ERROR_FLASH = 220,
+
+       /** Flash has bad checksum */
+       HPI_ERROR_BAD_CHECKSUM = (HPI_ERROR_FLASH + 1),
+       HPI_ERROR_BAD_SEQUENCE = (HPI_ERROR_FLASH + 2),
+       HPI_ERROR_FLASH_ERASE = (HPI_ERROR_FLASH + 3),
+       HPI_ERROR_FLASH_PROGRAM = (HPI_ERROR_FLASH + 4),
+       HPI_ERROR_FLASH_VERIFY = (HPI_ERROR_FLASH + 5),
+       HPI_ERROR_FLASH_TYPE = (HPI_ERROR_FLASH + 6),
+       HPI_ERROR_FLASH_START = (HPI_ERROR_FLASH + 7),
+
+       /** Reserved for OEMs. */
+       HPI_ERROR_RESERVED_1 = 290,
+
+       /** Stream does not exist. */
+       HPI_ERROR_INVALID_STREAM = 300,
+       /** Invalid compression format. */
+       HPI_ERROR_INVALID_FORMAT = 301,
+       /** Invalid format samplerate */
+       HPI_ERROR_INVALID_SAMPLERATE = 302,
+       /** Invalid format number of channels. */
+       HPI_ERROR_INVALID_CHANNELS = 303,
+       /** Invalid format bitrate. */
+       HPI_ERROR_INVALID_BITRATE = 304,
+       /** Invalid datasize used for stream read/write. */
+       HPI_ERROR_INVALID_DATASIZE = 305,
+       /** Stream buffer is full during stream write. */
+       HPI_ERROR_BUFFER_FULL = 306,
+       /** Stream buffer is empty during stream read. */
+       HPI_ERROR_BUFFER_EMPTY = 307,
+       /** Invalid datasize used for stream read/write. */
+       HPI_ERROR_INVALID_DATA_TRANSFER = 308,
+       /** Packet ordering error for stream read/write. */
+       HPI_ERROR_INVALID_PACKET_ORDER = 309,
+
+       /** Object can't do requested operation in its current
+       state, eg set format, change rec mux state while recording.*/
+       HPI_ERROR_INVALID_OPERATION = 310,
+
+       /** Where an SRG is shared amongst streams, an incompatible samplerate is one
+       that is different to any currently playing or recording stream. */
+       HPI_ERROR_INCOMPATIBLE_SAMPLERATE = 311,
+       /** Adapter mode is illegal.*/
+       HPI_ERROR_BAD_ADAPTER_MODE = 312,
+
+       /** There have been too many attempts to set the adapter's
+       capabilities (using bad keys), the card should be returned
+       to ASI if further capabilities updates are required */
+       HPI_ERROR_TOO_MANY_CAPABILITY_CHANGE_ATTEMPTS = 313,
+       /** Streams on different adapters cannot be grouped. */
+       HPI_ERROR_NO_INTERADAPTER_GROUPS = 314,
+       /** Streams on different DSPs cannot be grouped. */
+       HPI_ERROR_NO_INTERDSP_GROUPS = 315,
+
+       /** Invalid mixer node for this adapter. */
+       HPI_ERROR_INVALID_NODE = 400,
+       /** Invalid control. */
+       HPI_ERROR_INVALID_CONTROL = 401,
+       /** Invalid control value was passed. */
+       HPI_ERROR_INVALID_CONTROL_VALUE = 402,
+       /** Control attribute not supported by this control. */
+       HPI_ERROR_INVALID_CONTROL_ATTRIBUTE = 403,
+       /** Control is disabled. */
+       HPI_ERROR_CONTROL_DISABLED = 404,
+       /** I2C transaction failed due to a missing ACK. */
+       HPI_ERROR_CONTROL_I2C_MISSING_ACK = 405,
+       /** Control attribute is valid, but not supported by this hardware. */
+       HPI_ERROR_UNSUPPORTED_CONTROL_ATTRIBUTE = 406,
+       /** Control is busy, or coming out of
+       reset and cannot be accessed at this time. */
+       HPI_ERROR_CONTROL_NOT_READY = 407,
+
+       /** Non volatile memory */
+       HPI_ERROR_NVMEM_BUSY = 450,
+       HPI_ERROR_NVMEM_FULL = 451,
+       HPI_ERROR_NVMEM_FAIL = 452,
+
+       /** I2C */
+       HPI_ERROR_I2C_MISSING_ACK = HPI_ERROR_CONTROL_I2C_MISSING_ACK,
+       HPI_ERROR_I2C_BAD_ADR = 460,
+
+       /** Entity errors */
+       HPI_ERROR_ENTITY_TYPE_MISMATCH = 470,
+       HPI_ERROR_ENTITY_ITEM_COUNT = 471,
+       HPI_ERROR_ENTITY_TYPE_INVALID = 472,
+       HPI_ERROR_ENTITY_ROLE_INVALID = 473,
+
+       /* AES18 specific errors were 500..507 */
+
+       /** custom error to use for debugging */
+       HPI_ERROR_CUSTOM = 600,
+
+       /** hpioct32.c can't obtain mutex */
+       HPI_ERROR_MUTEX_TIMEOUT = 700,
+
+       /** errors from HPI backends have values >= this */
+       HPI_ERROR_BACKEND_BASE = 900,
+
+       /** indicates a cached u16 value is invalid. */
+       HPI_ERROR_ILLEGAL_CACHE_VALUE = 0xffff
+};
+
+/** \defgroup maximums HPI maximum values
+\{
+*/
+/** Maximum number of adapters per HPI sub-system
+   WARNING: modifying this value changes the response structure size.*/
+#define HPI_MAX_ADAPTERS                20
+/** Maximum number of in or out streams per adapter */
+#define HPI_MAX_STREAMS                 16
+#define HPI_MAX_CHANNELS                2      /* per stream */
+#define HPI_MAX_NODES                   8      /* per mixer ? */
+#define HPI_MAX_CONTROLS                4      /* per node ? */
+/** maximum number of ancillary bytes per MPEG frame */
+#define HPI_MAX_ANC_BYTES_PER_FRAME     (64)
+#define HPI_STRING_LEN                  16
+
+/** Velocity units */
+#define HPI_OSTREAM_VELOCITY_UNITS      4096
+/** OutStream timescale units */
+#define HPI_OSTREAM_TIMESCALE_UNITS     10000
+/** OutStream timescale passthrough - turns timescaling on in passthough mode */
+#define HPI_OSTREAM_TIMESCALE_PASSTHROUGH       99999
+
+/**\}*/
+
+/* ////////////////////////////////////////////////////////////////////// */
+/* STRUCTURES */
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(push, 1)
+#endif
+
+/** Structure containing sample format information.
+    See also HPI_FormatCreate().
+  */
+struct hpi_format {
+       u32 sample_rate;
+                               /**< 11025, 32000, 44100 ... */
+       u32 bit_rate;         /**< for MPEG */
+       u32 attributes;
+                               /**< Stereo/JointStereo/Mono */
+       u16 mode_legacy;
+                               /**< Legacy ancillary mode or idle bit  */
+       u16 unused;           /**< unused */
+       u16 channels; /**< 1,2..., (or ancillary mode or idle bit */
+       u16 format;   /**< HPI_FORMAT_PCM16, _MPEG etc. see #HPI_FORMATS. */
+};
+
+struct hpi_anc_frame {
+       u32 valid_bits_in_this_frame;
+       u8 b_data[HPI_MAX_ANC_BYTES_PER_FRAME];
+};
+
+/** An object for containing a single async event.
+*/
+struct hpi_async_event {
+       u16 event_type; /**< type of event. \sa async_event  */
+       u16 sequence;  /**< sequence number, allows lost event detection */
+       u32 state;    /**< new state */
+       u32 h_object;    /**< handle to the object returning the event. */
+       union {
+               struct {
+                       u16 index; /**< GPIO bit index. */
+               } gpio;
+               struct {
+                       u16 node_index; /**< what node is the control on ? */
+                       u16 node_type;  /**< what type of node is the control on ? */
+               } control;
+       } u;
+};
+
+/*/////////////////////////////////////////////////////////////////////////// */
+/* Public HPI Entity related definitions                                     */
+
+struct hpi_entity;
+
+enum e_entity_type {
+       entity_type_null,
+       entity_type_sequence,   /* sequence of potentially heterogeneous TLV entities */
+
+       entity_type_reference,  /* refers to a TLV entity or NULL */
+
+       entity_type_int,        /* 32 bit */
+       entity_type_float,      /* ieee754 binary 32 bit encoding */
+       entity_type_double,
+
+       entity_type_cstring,
+       entity_type_octet,
+       entity_type_ip4_address,
+       entity_type_ip6_address,
+       entity_type_mac_address,
+
+       LAST_ENTITY_TYPE
+};
+
+enum e_entity_role {
+       entity_role_null,
+       entity_role_value,
+       entity_role_classname,
+
+       entity_role_units,
+       entity_role_flags,
+       entity_role_range,
+
+       entity_role_mapping,
+       entity_role_enum,
+
+       entity_role_instance_of,
+       entity_role_depends_on,
+       entity_role_member_of_group,
+       entity_role_value_constraint,
+       entity_role_parameter_port,
+
+       entity_role_block,
+       entity_role_node_group,
+       entity_role_audio_port,
+       entity_role_clock_port,
+       LAST_ENTITY_ROLE
+};
+
+/* skip host side function declarations for
+   DSP compile and documentation extraction */
+
+struct hpi_hsubsys {
+       int not_really_used;
+};
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(pop)
+#endif
+
+/*////////////////////////////////////////////////////////////////////////// */
+/* HPI FUNCTIONS */
+
+/*/////////////////////////// */
+/* DATA and FORMAT and STREAM */
+
+u16 hpi_stream_estimate_buffer_size(struct hpi_format *pF,
+       u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size);
+
+/*/////////// */
+/* SUB SYSTEM */
+struct hpi_hsubsys *hpi_subsys_create(void
+       );
+
+void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys);
+
+u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys,
+       u32 *pversion);
+
+u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 *pversion_ex);
+
+u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
+       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length);
+
+u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
+       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length);
+
+u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,
+       int *pn_num_adapters);
+
+u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
+       u32 *padapter_index, u16 *pw_adapter_type);
+
+u16 hpi_subsys_ssx2_bypass(const struct hpi_hsubsys *ph_subsys, u16 bypass);
+
+u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
+       const char *sz_interface);
+
+/*///////// */
+/* ADAPTER */
+
+u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index);
+
+u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index);
+
+u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams,
+       u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type);
+
+u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 module_index, u16 *pw_num_outputs,
+       u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number,
+       u16 *pw_module_type, u32 *ph_module);
+
+u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 adapter_mode);
+
+u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 adapter_mode, u16 query_or_set);
+
+u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 *padapter_mode);
+
+u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *assert_present, char *psz_assert,
+       u16 *pw_line_number);
+
+u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *assert_present, char *psz_assert,
+       u32 *pline_number, u16 *pw_assert_on_dsp);
+
+u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 assert_id);
+
+u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 capability, u32 key);
+
+u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index);
+
+u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 dsp_address, char *p_bytes, int *count_bytes);
+
+u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 property, u16 paramter1, u16 paramter2);
+
+u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 property, u16 *pw_paramter1,
+       u16 *pw_paramter2);
+
+u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 index, u16 what_to_enumerate,
+       u16 property_index, u32 *psetting);
+
+/*////////////// */
+/* NonVol Memory */
+u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_nv_memory, u16 *pw_size_in_bytes);
+
+u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
+       u32 h_nv_memory, u16 index, u16 *pw_data);
+
+u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
+       u32 h_nv_memory, u16 index, u16 data);
+
+/*////////////// */
+/* Digital I/O */
+u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits);
+
+u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 bit_index, u16 *pw_bit_data);
+
+u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 aw_all_bit_data[4]
+       );
+
+u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 bit_index, u16 bit_data);
+
+u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 aw_all_bit_data[4]
+       );
+
+/**********************/
+/* Async Event Object */
+/**********************/
+u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 *ph_async);
+
+u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async);
+
+u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
+       u16 maximum_events, struct hpi_async_event *p_events,
+       u16 *pw_number_returned);
+
+u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
+       u32 h_async, u16 *pw_count);
+
+u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
+       u16 maximum_events, struct hpi_async_event *p_events,
+       u16 *pw_number_returned);
+
+/*/////////// */
+/* WATCH-DOG  */
+u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_watchdog);
+
+u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
+       u32 time_millisec);
+
+u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog);
+
+/**************/
+/* OUT STREAM */
+/**************/
+u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u16 outstream_index, u32 *ph_outstream);
+
+u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream);
+
+u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play,
+       u32 *psamples_played, u32 *pauxiliary_data_to_play);
+
+u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, const u8 *pb_write_buf, u32 bytes_to_write,
+       const struct hpi_format *p_format);
+
+u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream);
+
+u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream);
+
+u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream);
+
+u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream);
+
+u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream);
+
+u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_format *p_format);
+
+u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_format *p_format);
+
+u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample);
+
+u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, short velocity);
+
+u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u16 mode);
+
+u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 *pframes_available);
+
+u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer,
+       u32 anc_frame_buffer_size_in_bytes,
+       u32 number_of_ancillary_frames_to_read);
+
+u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 time_scaleX10000);
+
+u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 size_in_bytes);
+
+u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream);
+
+u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 h_stream);
+
+u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map);
+
+u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream);
+
+/*////////// */
+/* IN_STREAM */
+u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u16 instream_index, u32 *ph_instream);
+
+u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream);
+
+u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_format *p_format);
+
+u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_format *p_format);
+
+u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,
+       u8 *pb_read_buf, u32 bytes_to_read);
+
+u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream);
+
+u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream);
+
+u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream);
+
+u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream);
+
+u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded,
+       u32 *psamples_recorded, u32 *pauxiliary_data_recorded);
+
+u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment,
+       u16 idle_bit);
+
+u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 *pframe_space);
+
+u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer,
+       u32 anc_frame_buffer_size_in_bytes,
+       u32 number_of_ancillary_frames_to_write);
+
+u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 size_in_bytes);
+
+u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream);
+
+u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 h_stream);
+
+u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 *poutstream_map, u32 *pinstream_map);
+
+u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream);
+
+/*********/
+/* MIXER */
+/*********/
+u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_mixer);
+
+u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer);
+
+u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
+       u16 src_node_type, u16 src_node_type_index, u16 dst_node_type,
+       u16 dst_node_type_index, u16 control_type, u32 *ph_control);
+
+u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_mixer, u16 control_index, u16 *pw_src_node_type,
+       u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index,
+       u16 *pw_control_type, u32 *ph_control);
+
+u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
+       enum HPI_MIXER_STORE_COMMAND command, u16 index);
+/*************************/
+/* mixer CONTROLS                */
+/*************************/
+/*************************/
+/* volume control                */
+/*************************/
+u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB[HPI_MAX_CHANNELS]
+       );
+
+u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB_out[HPI_MAX_CHANNELS]
+       );
+
+#define hpi_volume_get_range hpi_volume_query_range
+u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB);
+
+u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_volume, u32 *p_channels);
+
+u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms);
+
+u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
+       u32 duration_ms, u16 profile);
+
+/*************************/
+/* level control         */
+/*************************/
+u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB);
+
+u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB[HPI_MAX_CHANNELS]
+       );
+
+u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB_out[HPI_MAX_CHANNELS]
+       );
+
+/*************************/
+/* meter control                 */
+/*************************/
+u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_meter, u32 *p_channels);
+
+u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_peak0_01dB_out[HPI_MAX_CHANNELS]
+       );
+
+u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_peak0_01dB_out[HPI_MAX_CHANNELS]
+       );
+
+u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 attack, u16 decay);
+
+u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 attack, u16 decay);
+
+u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *attack, u16 *decay);
+
+u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *attack, u16 *decay);
+
+/*************************/
+/* channel mode control  */
+/*************************/
+u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_mode, const u32 index, u16 *pw_mode);
+
+u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 mode);
+
+u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *mode);
+
+/*************************/
+/* Tuner control                 */
+/*************************/
+u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, u16 *pw_band);
+
+u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 band);
+
+u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_band);
+
+u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq);
+
+u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 freq_ink_hz);
+
+u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pw_freq_ink_hz);
+
+u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *pw_level);
+
+u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, short *pw_level);
+
+u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, u16 *pw_gain);
+
+u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short gain);
+
+u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *pn_gain);
+
+u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_status_mask, u16 *pw_status);
+
+u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 mode, u32 value);
+
+u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 mode, u32 *pn_value);
+
+u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *p_rds_data);
+
+u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis);
+
+u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 deemphasis);
+u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pdeemphasis);
+
+u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, u32 *pbitmap_program);
+
+u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 program);
+
+u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 *pprogram);
+
+u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_dsp_version, const u32 string_size);
+
+u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_sdk_version, const u32 string_size);
+
+u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pquality);
+
+/****************************/
+/* PADs control             */
+/****************************/
+
+u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_string, const u32 string_length);
+
+u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 string_length);
+
+u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 string_length);
+
+u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 string_length);
+
+u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *ppTY);
+
+u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 *ppI);
+
+u16 HPI_PAD__get_program_type_string(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, const u32 data_type, const u32 pTY, char *psz_string,
+       const u32 string_length);
+
+/****************************/
+/* AES/EBU Receiver control */
+/****************************/
+u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_aes_rx, const u32 index, u16 *pw_format);
+
+u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source);
+
+u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_source);
+
+u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate);
+
+u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *pw_data);
+
+u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 *pw_data);
+
+u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_error_data);
+
+/*******************************/
+/* AES/EBU Transmitter control */
+/*******************************/
+u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u32 sample_rate);
+
+u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 data);
+
+u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 data);
+
+u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 *pw_data);
+
+u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_aes_tx, const u32 index, u16 *pw_format);
+
+u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 output_format);
+
+u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_output_format);
+
+/***********************/
+/* multiplexer control */
+/***********************/
+u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source_node_type, u16 source_node_index);
+
+u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *source_node_type, u16 *source_node_index);
+
+u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *source_node_type,
+       u16 *source_node_index);
+
+/***************/
+/* VOX control */
+/***************/
+u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB);
+
+u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *an_gain0_01dB);
+
+/*********************/
+/* Bitstream control */
+/*********************/
+u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 edge_type);
+
+u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 polarity);
+
+u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity);
+
+/***********************/
+/* SampleClock control */
+/***********************/
+
+u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, u16 *pw_source);
+
+u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source);
+
+u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_source);
+
+u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, const u32 source,
+       u16 *pw_source_index);
+
+u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source_index);
+
+u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_source_index);
+
+u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate);
+
+u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, u32 *psource);
+
+u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 sample_rate);
+
+u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate);
+
+u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 enable);
+
+u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *penable);
+
+u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 lock);
+
+u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *plock);
+
+/***********************/
+/* Microphone control */
+/***********************/
+u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 on_off);
+
+u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_on_off);
+
+/*******************************
+  Parametric Equalizer control
+*******************************/
+u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_number_of_bands, u16 *pw_enabled);
+
+u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 on_off);
+
+u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100,
+       short gain0_01dB);
+
+u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz,
+       short *pnQ100, short *pn_gain0_01dB);
+
+u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, short coeffs[5]
+       );
+
+/*******************************
+  Compressor Expander control
+*******************************/
+
+u16 hpi_compander_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 attack, u16 decay, short ratio100, short threshold0_01dB,
+       short makeup_gain0_01dB);
+
+u16 hpi_compander_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_attack, u16 *pw_decay, short *pw_ratio100,
+       short *pn_threshold0_01dB, short *pn_makeup_gain0_01dB);
+
+/*******************************
+  Cobranet HMI control
+*******************************/
+u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 hmi_address, u32 byte_count, u8 *pb_data);
+
+u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data);
+
+u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pstatus, u32 *preadable_size,
+       u32 *pwriteable_size);
+
+/*Read the current IP address
+*/
+u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pi_paddress);
+
+/* Write the current IP address
+*/
+u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 i_paddress);
+
+/* Read the static IP address
+*/
+u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pi_paddress);
+
+/* Write the static IP address
+*/
+u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 i_paddress);
+
+/* Read the MAC address
+*/
+u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs);
+
+/*******************************
+  Tone Detector control
+*******************************/
+u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       u32 *state);
+
+u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       u32 enable);
+
+u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       u32 *enable);
+
+u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 event_enable);
+
+u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 *event_enable);
+
+u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, int threshold);
+
+u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, int *threshold);
+
+u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 index, u32 *frequency);
+
+/*******************************
+  Silence Detector control
+*******************************/
+u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 *state);
+
+u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 enable);
+
+u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 *enable);
+
+u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 event_enable);
+
+u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 *event_enable);
+
+u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 delay);
+
+u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, u32 *delay);
+
+u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, int threshold);
+
+u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 hC, int *threshold);
+
+/*******************************
+  Universal control
+*******************************/
+u16 hpi_entity_find_next(struct hpi_entity *container_entity,
+       enum e_entity_type type, enum e_entity_role role, int recursive_flag,
+       struct hpi_entity **current_match);
+
+u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
+       enum e_entity_type type, size_t item_count, void *value_dst_p);
+
+u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
+       size_t *items, enum e_entity_role *role, void **value);
+
+u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
+       const size_t item_count, const enum e_entity_role role, void *value,
+       struct hpi_entity **entity);
+
+void hpi_entity_free(struct hpi_entity *entity);
+
+u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity **info);
+
+u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity **value);
+
+u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity *value);
+
+/*/////////// */
+/* DSP CLOCK  */
+/*/////////// */
+u16 hpi_clock_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_dsp_clock);
+
+u16 hpi_clock_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_clock,
+       u16 hour, u16 minute, u16 second, u16 milli_second);
+
+u16 hpi_clock_get_time(const struct hpi_hsubsys *ph_subsys, u32 h_clock,
+       u16 *pw_hour, u16 *pw_minute, u16 *pw_second, u16 *pw_milli_second);
+
+/*/////////// */
+/* PROFILE        */
+/*/////////// */
+u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 profile_index, u32 *ph_profile,
+       u16 *pw_max_profiles);
+
+u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
+       u16 index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
+       u32 *pmax_micro_seconds, u32 *pmin_micro_seconds);
+
+u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile);
+
+u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile);
+
+u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
+       u16 index, char *sz_profile_name, u16 profile_name_length);
+
+u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
+       u32 h_profile, u32 *putilization);
+
+/*//////////////////// */
+/* UTILITY functions */
+
+u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
+       u32 sample_rate, u32 bit_rate, u32 attributes);
+
+/* Until it's verified, this function is for Windows OSs only */
+
+#endif  /*_H_HPI_ */
+/*
+///////////////////////////////////////////////////////////////////////////////
+// See CVS for history.  Last complete set in rev 1.146
+////////////////////////////////////////////////////////////////////////////////
+*/
diff --git a/sound/pci/asihpi/hpi6000.c b/sound/pci/asihpi/hpi6000.c
new file mode 100644 (file)
index 0000000..839ecb2
--- /dev/null
@@ -0,0 +1,1840 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ Hardware Programming Interface (HPI) for AudioScience ASI6200 series adapters.
+ These PCI bus adapters are based on the TI C6711 DSP.
+
+ Exported functions:
+ void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
+
+ #defines
+ HIDE_PCI_ASSERTS to show the PCI asserts
+ PROFILE_DSP2 get profile data from DSP2 if present (instead of DSP 1)
+
+(C) Copyright AudioScience Inc. 1998-2003
+*******************************************************************************/
+#define SOURCEFILE_NAME "hpi6000.c"
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+#include "hpidebug.h"
+#include "hpi6000.h"
+#include "hpidspcd.h"
+#include "hpicmn.h"
+
+#define HPI_HIF_BASE (0x00000200)      /* start of C67xx internal RAM */
+#define HPI_HIF_ADDR(member) \
+       (HPI_HIF_BASE + offsetof(struct hpi_hif_6000, member))
+#define HPI_HIF_ERROR_MASK      0x4000
+
+/* HPI6000 specific error codes */
+
+#define HPI6000_ERROR_BASE                              900
+#define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT             901
+#define HPI6000_ERROR_MSG_RESP_SEND_MSG_ACK             902
+#define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK             903
+#define HPI6000_ERROR_MSG_GET_ADR                       904
+#define HPI6000_ERROR_RESP_GET_ADR                      905
+#define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32             906
+#define HPI6000_ERROR_MSG_RESP_BLOCKREAD32              907
+#define HPI6000_ERROR_MSG_INVALID_DSP_INDEX             908
+#define HPI6000_ERROR_CONTROL_CACHE_PARAMS              909
+
+#define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT            911
+#define HPI6000_ERROR_SEND_DATA_ACK                     912
+#define HPI6000_ERROR_SEND_DATA_ADR                     913
+#define HPI6000_ERROR_SEND_DATA_TIMEOUT                 914
+#define HPI6000_ERROR_SEND_DATA_CMD                     915
+#define HPI6000_ERROR_SEND_DATA_WRITE                   916
+#define HPI6000_ERROR_SEND_DATA_IDLECMD                 917
+#define HPI6000_ERROR_SEND_DATA_VERIFY                  918
+
+#define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT             921
+#define HPI6000_ERROR_GET_DATA_ACK                      922
+#define HPI6000_ERROR_GET_DATA_CMD                      923
+#define HPI6000_ERROR_GET_DATA_READ                     924
+#define HPI6000_ERROR_GET_DATA_IDLECMD                  925
+
+#define HPI6000_ERROR_CONTROL_CACHE_ADDRLEN             951
+#define HPI6000_ERROR_CONTROL_CACHE_READ                952
+#define HPI6000_ERROR_CONTROL_CACHE_FLUSH               953
+
+#define HPI6000_ERROR_MSG_RESP_GETRESPCMD               961
+#define HPI6000_ERROR_MSG_RESP_IDLECMD                  962
+#define HPI6000_ERROR_MSG_RESP_BLOCKVERIFY32            963
+
+/* adapter init errors */
+#define HPI6000_ERROR_UNHANDLED_SUBSYS_ID               930
+
+/* can't access PCI2040 */
+#define HPI6000_ERROR_INIT_PCI2040                      931
+/* can't access DSP HPI i/f */
+#define HPI6000_ERROR_INIT_DSPHPI                       932
+/* can't access internal DSP memory */
+#define HPI6000_ERROR_INIT_DSPINTMEM                    933
+/* can't access SDRAM - test#1 */
+#define HPI6000_ERROR_INIT_SDRAM1                       934
+/* can't access SDRAM - test#2 */
+#define HPI6000_ERROR_INIT_SDRAM2                       935
+
+#define HPI6000_ERROR_INIT_VERIFY                       938
+
+#define HPI6000_ERROR_INIT_NOACK                        939
+
+#define HPI6000_ERROR_INIT_PLDTEST1                     941
+#define HPI6000_ERROR_INIT_PLDTEST2                     942
+
+/* local defines */
+
+#define HIDE_PCI_ASSERTS
+#define PROFILE_DSP2
+
+/* for PCI2040 i/f chip */
+/* HPI CSR registers */
+/* word offsets from CSR base */
+/* use when io addresses defined as u32 * */
+
+#define INTERRUPT_EVENT_SET     0
+#define INTERRUPT_EVENT_CLEAR   1
+#define INTERRUPT_MASK_SET      2
+#define INTERRUPT_MASK_CLEAR    3
+#define HPI_ERROR_REPORT        4
+#define HPI_RESET               5
+#define HPI_DATA_WIDTH          6
+
+#define MAX_DSPS 2
+/* HPI registers, spaced 8K bytes = 2K words apart */
+#define DSP_SPACING             0x800
+
+#define CONTROL                 0x0000
+#define ADDRESS                 0x0200
+#define DATA_AUTOINC            0x0400
+#define DATA                    0x0600
+
+#define TIMEOUT 500000
+
+struct dsp_obj {
+       __iomem u32 *prHPI_control;
+       __iomem u32 *prHPI_address;
+       __iomem u32 *prHPI_data;
+       __iomem u32 *prHPI_data_auto_inc;
+       char c_dsp_rev;         /*A, B */
+       u32 control_cache_address_on_dsp;
+       u32 control_cache_length_on_dsp;
+       struct hpi_adapter_obj *pa_parent_adapter;
+};
+
+struct hpi_hw_obj {
+       __iomem u32 *dw2040_HPICSR;
+       __iomem u32 *dw2040_HPIDSP;
+
+       u16 num_dsp;
+       struct dsp_obj ado[MAX_DSPS];
+
+       u32 message_buffer_address_on_dsp;
+       u32 response_buffer_address_on_dsp;
+       u32 pCI2040HPI_error_count;
+
+       struct hpi_control_cache_single control_cache[HPI_NMIXER_CONTROLS];
+       struct hpi_control_cache *p_cache;
+};
+
+static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 hpi_address, u32 *source, u32 count);
+static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 hpi_address, u32 *dest, u32 count);
+
+static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code);
+static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
+       u16 read_or_write);
+#define H6READ 1
+#define H6WRITE 0
+
+static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm);
+static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
+       u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr);
+
+static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
+       struct hpi_response *phr);
+
+static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
+       u32 ack_value);
+
+static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 host_cmd);
+
+static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo);
+
+static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data);
+
+static u32 hpi_read_word(struct dsp_obj *pdo, u32 address);
+
+static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
+       u32 length);
+
+static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
+       u32 length);
+
+static void subsys_create_adapter(struct hpi_message *phm,
+       struct hpi_response *phr);
+
+static void subsys_delete_adapter(struct hpi_message *phm,
+       struct hpi_response *phr);
+
+static void adapter_get_asserts(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static short create_adapter_obj(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code);
+
+/* local globals */
+
+static u16 gw_pci_read_asserts;        /* used to count PCI2040 errors */
+static u16 gw_pci_write_asserts;       /* used to count PCI2040 errors */
+
+static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       switch (phm->function) {
+       case HPI_SUBSYS_OPEN:
+       case HPI_SUBSYS_CLOSE:
+       case HPI_SUBSYS_GET_INFO:
+       case HPI_SUBSYS_DRIVER_UNLOAD:
+       case HPI_SUBSYS_DRIVER_LOAD:
+       case HPI_SUBSYS_FIND_ADAPTERS:
+               /* messages that should not get here */
+               phr->error = HPI_ERROR_UNIMPLEMENTED;
+               break;
+       case HPI_SUBSYS_CREATE_ADAPTER:
+               subsys_create_adapter(phm, phr);
+               break;
+       case HPI_SUBSYS_DELETE_ADAPTER:
+               subsys_delete_adapter(phm, phr);
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+static void control_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       switch (phm->function) {
+       case HPI_CONTROL_GET_STATE:
+               if (pao->has_control_cache) {
+                       u16 err;
+                       err = hpi6000_update_control_cache(pao, phm);
+
+                       if (err) {
+                               phr->error = err;
+                               break;
+                       }
+
+                       if (hpi_check_control_cache(((struct hpi_hw_obj *)
+                                               pao->priv)->p_cache, phm,
+                                       phr))
+                               break;
+               }
+               hw_message(pao, phm, phr);
+               break;
+       case HPI_CONTROL_GET_INFO:
+               hw_message(pao, phm, phr);
+               break;
+       case HPI_CONTROL_SET_STATE:
+               hw_message(pao, phm, phr);
+               hpi_sync_control_cache(((struct hpi_hw_obj *)pao->priv)->
+                       p_cache, phm, phr);
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+static void adapter_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       switch (phm->function) {
+       case HPI_ADAPTER_GET_INFO:
+               hw_message(pao, phm, phr);
+               break;
+       case HPI_ADAPTER_GET_ASSERT:
+               adapter_get_asserts(pao, phm, phr);
+               break;
+       case HPI_ADAPTER_OPEN:
+       case HPI_ADAPTER_CLOSE:
+       case HPI_ADAPTER_TEST_ASSERT:
+       case HPI_ADAPTER_SELFTEST:
+       case HPI_ADAPTER_GET_MODE:
+       case HPI_ADAPTER_SET_MODE:
+       case HPI_ADAPTER_FIND_OBJECT:
+       case HPI_ADAPTER_GET_PROPERTY:
+       case HPI_ADAPTER_SET_PROPERTY:
+       case HPI_ADAPTER_ENUM_PROPERTY:
+               hw_message(pao, phm, phr);
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+static void outstream_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       switch (phm->function) {
+       case HPI_OSTREAM_HOSTBUFFER_ALLOC:
+       case HPI_OSTREAM_HOSTBUFFER_FREE:
+               /* Don't let these messages go to the HW function because
+                * they're called without allocating the spinlock.
+                * For the HPI6000 adapters the HW would return
+                * HPI_ERROR_INVALID_FUNC anyway.
+                */
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       default:
+               hw_message(pao, phm, phr);
+               return;
+       }
+}
+
+static void instream_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       switch (phm->function) {
+       case HPI_ISTREAM_HOSTBUFFER_ALLOC:
+       case HPI_ISTREAM_HOSTBUFFER_FREE:
+               /* Don't let these messages go to the HW function because
+                * they're called without allocating the spinlock.
+                * For the HPI6000 adapters the HW would return
+                * HPI_ERROR_INVALID_FUNC anyway.
+                */
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       default:
+               hw_message(pao, phm, phr);
+               return;
+       }
+}
+
+/************************************************************************/
+/** HPI_6000()
+ * Entry point from HPIMAN
+ * All calls to the HPI start here
+ */
+void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_adapter_obj *pao = NULL;
+
+       /* subsytem messages get executed by every HPI. */
+       /* All other messages are ignored unless the adapter index matches */
+       /* an adapter in the HPI */
+       HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->object, phm->function);
+
+       /* if Dsp has crashed then do not communicate with it any more */
+       if (phm->object != HPI_OBJ_SUBSYSTEM) {
+               pao = hpi_find_adapter(phm->adapter_index);
+               if (!pao) {
+                       HPI_DEBUG_LOG(DEBUG,
+                               " %d,%d refused, for another HPI?\n",
+                               phm->object, phm->function);
+                       return;
+               }
+
+               if (pao->dsp_crashed >= 10) {
+                       hpi_init_response(phr, phm->object, phm->function,
+                               HPI_ERROR_DSP_HARDWARE);
+                       HPI_DEBUG_LOG(DEBUG, " %d,%d dsp crashed.\n",
+                               phm->object, phm->function);
+                       return;
+               }
+       }
+       /* Init default response including the size field */
+       if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
+               hpi_init_response(phr, phm->object, phm->function,
+                       HPI_ERROR_PROCESSING_MESSAGE);
+
+       switch (phm->type) {
+       case HPI_TYPE_MESSAGE:
+               switch (phm->object) {
+               case HPI_OBJ_SUBSYSTEM:
+                       subsys_message(phm, phr);
+                       break;
+
+               case HPI_OBJ_ADAPTER:
+                       phr->size =
+                               sizeof(struct hpi_response_header) +
+                               sizeof(struct hpi_adapter_res);
+                       adapter_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_CONTROL:
+                       control_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_OSTREAM:
+                       outstream_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_ISTREAM:
+                       instream_message(pao, phm, phr);
+                       break;
+
+               default:
+                       hw_message(pao, phm, phr);
+                       break;
+               }
+               break;
+
+       default:
+               phr->error = HPI_ERROR_INVALID_TYPE;
+               break;
+       }
+}
+
+/************************************************************************/
+/* SUBSYSTEM */
+
+/* create an adapter object and initialise it based on resource information
+ * passed in in the message
+ * NOTE - you cannot use this function AND the FindAdapters function at the
+ * same time, the application must use only one of them to get the adapters
+ */
+static void subsys_create_adapter(struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+       /* create temp adapter obj, because we don't know what index yet */
+       struct hpi_adapter_obj ao;
+       struct hpi_adapter_obj *pao;
+       u32 os_error_code;
+       short error = 0;
+       u32 dsp_index = 0;
+
+       HPI_DEBUG_LOG(VERBOSE, "subsys_create_adapter\n");
+
+       memset(&ao, 0, sizeof(ao));
+
+       /* this HPI only creates adapters for TI/PCI2040 based devices */
+       if (phm->u.s.resource.bus_type != HPI_BUS_PCI)
+               return;
+       if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI)
+               return;
+       if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_PCI2040)
+               return;
+
+       ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
+       if (!ao.priv) {
+               HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
+               phr->error = HPI_ERROR_MEMORY_ALLOC;
+               return;
+       }
+
+       /* create the adapter object based on the resource information */
+       /*? memcpy(&ao.Pci,&phm->u.s.Resource.r.Pci,sizeof(ao.Pci)); */
+       ao.pci = *phm->u.s.resource.r.pci;
+
+       error = create_adapter_obj(&ao, &os_error_code);
+       if (!error)
+               error = hpi_add_adapter(&ao);
+       if (error) {
+               phr->u.s.data = os_error_code;
+               kfree(ao.priv);
+               phr->error = error;
+               return;
+       }
+       /* need to update paParentAdapter */
+       pao = hpi_find_adapter(ao.index);
+       if (!pao) {
+               /* We just added this adapter, why can't we find it!? */
+               HPI_DEBUG_LOG(ERROR, "lost adapter after boot\n");
+               phr->error = 950;
+               return;
+       }
+
+       for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
+               struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+               phw->ado[dsp_index].pa_parent_adapter = pao;
+       }
+
+       phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type;
+       phr->u.s.adapter_index = ao.index;
+       phr->u.s.num_adapters++;
+       phr->error = 0;
+}
+
+static void subsys_delete_adapter(struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+       struct hpi_adapter_obj *pao = NULL;
+       struct hpi_hw_obj *phw;
+
+       pao = hpi_find_adapter(phm->adapter_index);
+       if (!pao)
+               return;
+
+       phw = (struct hpi_hw_obj *)pao->priv;
+
+       if (pao->has_control_cache)
+               hpi_free_control_cache(phw->p_cache);
+
+       hpi_delete_adapter(pao);
+       kfree(phw);
+
+       phr->error = 0;
+}
+
+/* this routine is called from SubSysFindAdapter and SubSysCreateAdapter */
+static short create_adapter_obj(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code)
+{
+       short boot_error = 0;
+       u32 dsp_index = 0;
+       u32 control_cache_size = 0;
+       u32 control_cache_count = 0;
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+
+       /* init error reporting */
+       pao->dsp_crashed = 0;
+
+       /* The PCI2040 has the following address map */
+       /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
+       /* BAR1 - 32K = HPI registers on DSP */
+       phw->dw2040_HPICSR = pao->pci.ap_mem_base[0];
+       phw->dw2040_HPIDSP = pao->pci.ap_mem_base[1];
+       HPI_DEBUG_LOG(VERBOSE, "csr %p, dsp %p\n", phw->dw2040_HPICSR,
+               phw->dw2040_HPIDSP);
+
+       /* set addresses for the possible DSP HPI interfaces */
+       for (dsp_index = 0; dsp_index < MAX_DSPS; dsp_index++) {
+               phw->ado[dsp_index].prHPI_control =
+                       phw->dw2040_HPIDSP + (CONTROL +
+                       DSP_SPACING * dsp_index);
+
+               phw->ado[dsp_index].prHPI_address =
+                       phw->dw2040_HPIDSP + (ADDRESS +
+                       DSP_SPACING * dsp_index);
+               phw->ado[dsp_index].prHPI_data =
+                       phw->dw2040_HPIDSP + (DATA + DSP_SPACING * dsp_index);
+
+               phw->ado[dsp_index].prHPI_data_auto_inc =
+                       phw->dw2040_HPIDSP + (DATA_AUTOINC +
+                       DSP_SPACING * dsp_index);
+
+               HPI_DEBUG_LOG(VERBOSE, "ctl %p, adr %p, dat %p, dat++ %p\n",
+                       phw->ado[dsp_index].prHPI_control,
+                       phw->ado[dsp_index].prHPI_address,
+                       phw->ado[dsp_index].prHPI_data,
+                       phw->ado[dsp_index].prHPI_data_auto_inc);
+
+               phw->ado[dsp_index].pa_parent_adapter = pao;
+       }
+
+       phw->pCI2040HPI_error_count = 0;
+       pao->has_control_cache = 0;
+
+       /* Set the default number of DSPs on this card */
+       /* This is (conditionally) adjusted after bootloading */
+       /* of the first DSP in the bootload section. */
+       phw->num_dsp = 1;
+
+       boot_error = hpi6000_adapter_boot_load_dsp(pao, pos_error_code);
+       if (boot_error)
+               return boot_error;
+
+       HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
+
+       phw->message_buffer_address_on_dsp = 0L;
+       phw->response_buffer_address_on_dsp = 0L;
+
+       /* get info about the adapter by asking the adapter */
+       /* send a HPI_ADAPTER_GET_INFO message */
+       {
+               struct hpi_message hM;
+               struct hpi_response hR0;        /* response from DSP 0 */
+               struct hpi_response hR1;        /* response from DSP 1 */
+               u16 error = 0;
+
+               HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
+               memset(&hM, 0, sizeof(hM));
+               hM.type = HPI_TYPE_MESSAGE;
+               hM.size = sizeof(struct hpi_message);
+               hM.object = HPI_OBJ_ADAPTER;
+               hM.function = HPI_ADAPTER_GET_INFO;
+               hM.adapter_index = 0;
+               memset(&hR0, 0, sizeof(hR0));
+               memset(&hR1, 0, sizeof(hR1));
+               hR0.size = sizeof(hR0);
+               hR1.size = sizeof(hR1);
+
+               error = hpi6000_message_response_sequence(pao, 0, &hM, &hR0);
+               if (hR0.error) {
+                       HPI_DEBUG_LOG(DEBUG, "message error %d\n", hR0.error);
+                       return hR0.error;
+               }
+               if (phw->num_dsp == 2) {
+                       error = hpi6000_message_response_sequence(pao, 1, &hM,
+                               &hR1);
+                       if (error)
+                               return error;
+               }
+               pao->adapter_type = hR0.u.a.adapter_type;
+               pao->index = hR0.u.a.adapter_index;
+       }
+
+       memset(&phw->control_cache[0], 0,
+               sizeof(struct hpi_control_cache_single) *
+               HPI_NMIXER_CONTROLS);
+       /* Read the control cache length to figure out if it is turned on */
+       control_cache_size =
+               hpi_read_word(&phw->ado[0],
+               HPI_HIF_ADDR(control_cache_size_in_bytes));
+       if (control_cache_size) {
+               control_cache_count =
+                       hpi_read_word(&phw->ado[0],
+                       HPI_HIF_ADDR(control_cache_count));
+               pao->has_control_cache = 1;
+
+               phw->p_cache =
+                       hpi_alloc_control_cache(control_cache_count,
+                       control_cache_size, (struct hpi_control_cache_info *)
+                       &phw->control_cache[0]
+                       );
+       } else
+               pao->has_control_cache = 0;
+
+       HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n",
+               pao->adapter_type, pao->index);
+       pao->open = 0;  /* upon creation the adapter is closed */
+       return 0;
+}
+
+/************************************************************************/
+/* ADAPTER */
+
+static void adapter_get_asserts(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+#ifndef HIDE_PCI_ASSERTS
+       /* if we have PCI2040 asserts then collect them */
+       if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
+               phr->u.a.serial_number =
+                       gw_pci_read_asserts * 100 + gw_pci_write_asserts;
+               phr->u.a.adapter_index = 1;     /* assert count */
+               phr->u.a.adapter_type = -1;     /* "dsp index" */
+               strcpy(phr->u.a.sz_adapter_assert, "PCI2040 error");
+               gw_pci_read_asserts = 0;
+               gw_pci_write_asserts = 0;
+               phr->error = 0;
+       } else
+#endif
+               hw_message(pao, phm, phr);      /*get DSP asserts */
+
+       return;
+}
+
+/************************************************************************/
+/* LOW-LEVEL */
+
+static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code)
+{
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+       short error;
+       u32 timeout;
+       u32 read = 0;
+       u32 i = 0;
+       u32 data = 0;
+       u32 j = 0;
+       u32 test_addr = 0x80000000;
+       u32 test_data = 0x00000001;
+       u32 dw2040_reset = 0;
+       u32 dsp_index = 0;
+       u32 endian = 0;
+       u32 adapter_info = 0;
+       u32 delay = 0;
+
+       struct dsp_code dsp_code;
+       u16 boot_load_family = 0;
+
+       /* NOTE don't use wAdapterType in this routine. It is not setup yet */
+
+       switch (pao->pci.subsys_device_id) {
+       case 0x5100:
+       case 0x5110:    /* ASI5100 revB or higher with C6711D */
+       case 0x6100:
+       case 0x6200:
+               boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
+               break;
+       case 0x8800:
+               boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x8800);
+               break;
+       default:
+               return HPI6000_ERROR_UNHANDLED_SUBSYS_ID;
+       }
+
+       /* reset all DSPs, indicate two DSPs are present
+        * set RST3-=1 to disconnect HAD8 to set DSP in little endian mode
+        */
+       endian = 0;
+       dw2040_reset = 0x0003000F;
+       iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
+
+       /* read back register to make sure PCI2040 chip is functioning
+        * note that bits 4..15 are read-only and so should always return zero,
+        * even though we wrote 1 to them
+        */
+       for (i = 0; i < 1000; i++)
+               delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+       if (delay != dw2040_reset) {
+               HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
+                       delay);
+               return HPI6000_ERROR_INIT_PCI2040;
+       }
+
+       /* Indicate that DSP#0,1 is a C6X */
+       iowrite32(0x00000003, phw->dw2040_HPICSR + HPI_DATA_WIDTH);
+       /* set Bit30 and 29 - which will prevent Target aborts from being
+        * issued upon HPI or GP error
+        */
+       iowrite32(0x60000000, phw->dw2040_HPICSR + INTERRUPT_MASK_SET);
+
+       /* isolate DSP HAD8 line from PCI2040 so that
+        * Little endian can be set by pullup
+        */
+       dw2040_reset = dw2040_reset & (~(endian << 3));
+       iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
+
+       phw->ado[0].c_dsp_rev = 'B';    /* revB */
+       phw->ado[1].c_dsp_rev = 'B';    /* revB */
+
+       /*Take both DSPs out of reset, setting HAD8 to the correct Endian */
+       dw2040_reset = dw2040_reset & (~0x00000001);    /* start DSP 0 */
+       iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
+       dw2040_reset = dw2040_reset & (~0x00000002);    /* start DSP 1 */
+       iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
+
+       /* set HAD8 back to PCI2040, now that DSP set to little endian mode */
+       dw2040_reset = dw2040_reset & (~0x00000008);
+       iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
+       /*delay to allow DSP to get going */
+       for (i = 0; i < 100; i++)
+               delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+
+       /* loop through all DSPs, downloading DSP code */
+       for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
+               struct dsp_obj *pdo = &phw->ado[dsp_index];
+
+               /* configure DSP so that we download code into the SRAM */
+               /* set control reg for little endian, HWOB=1 */
+               iowrite32(0x00010001, pdo->prHPI_control);
+
+               /* test access to the HPI address register (HPIA) */
+               test_data = 0x00000001;
+               for (j = 0; j < 32; j++) {
+                       iowrite32(test_data, pdo->prHPI_address);
+                       data = ioread32(pdo->prHPI_address);
+                       if (data != test_data) {
+                               HPI_DEBUG_LOG(ERROR, "INIT_DSPHPI %x %x %x\n",
+                                       test_data, data, dsp_index);
+                               return HPI6000_ERROR_INIT_DSPHPI;
+                       }
+                       test_data = test_data << 1;
+               }
+
+/* if C6713 the setup PLL to generate 225MHz from 25MHz.
+* Since the PLLDIV1 read is sometimes wrong, even on a C6713,
+* we're going to do this unconditionally
+*/
+/* PLLDIV1 should have a value of 8000 after reset */
+/*
+       if (HpiReadWord(pdo,0x01B7C118) == 0x8000)
+*/
+               {
+                       /* C6713 datasheet says we cannot program PLL from HPI,
+                        * and indeed if we try to set the PLL multiply from the
+                        * HPI, the PLL does not seem to lock,
+                        * so we enable the PLL and use the default of x 7
+                        */
+                       /* bypass PLL */
+                       hpi_write_word(pdo, 0x01B7C100, 0x0000);
+                       for (i = 0; i < 100; i++)
+                               delay = ioread32(phw->dw2040_HPICSR +
+                                       HPI_RESET);
+
+                       /*  ** use default of PLL  x7 ** */
+                       /* EMIF = 225/3=75MHz */
+                       hpi_write_word(pdo, 0x01B7C120, 0x8002);
+                       /* peri = 225/2 */
+                       hpi_write_word(pdo, 0x01B7C11C, 0x8001);
+                       /* cpu  = 225/1 */
+                       hpi_write_word(pdo, 0x01B7C118, 0x8000);
+                       /* ~200us delay */
+                       for (i = 0; i < 2000; i++)
+                               delay = ioread32(phw->dw2040_HPICSR +
+                                       HPI_RESET);
+                       /* PLL not bypassed */
+                       hpi_write_word(pdo, 0x01B7C100, 0x0001);
+                       /* ~200us delay */
+                       for (i = 0; i < 2000; i++)
+                               delay = ioread32(phw->dw2040_HPICSR +
+                                       HPI_RESET);
+               }
+
+               /* test r/w to internal DSP memory
+                * C6711 has L2 cache mapped to 0x0 when reset
+                *
+                *  revB - because of bug 3.0.1 last HPI read
+                * (before HPI address issued) must be non-autoinc
+                */
+               /* test each bit in the 32bit word */
+               for (i = 0; i < 100; i++) {
+                       test_addr = 0x00000000;
+                       test_data = 0x00000001;
+                       for (j = 0; j < 32; j++) {
+                               hpi_write_word(pdo, test_addr + i, test_data);
+                               data = hpi_read_word(pdo, test_addr + i);
+                               if (data != test_data) {
+                                       HPI_DEBUG_LOG(ERROR,
+                                               "DSP mem %x %x %x %x\n",
+                                               test_addr + i, test_data,
+                                               data, dsp_index);
+
+                                       return HPI6000_ERROR_INIT_DSPINTMEM;
+                               }
+                               test_data = test_data << 1;
+                       }
+               }
+
+               /* memory map of ASI6200
+                  00000000-0000FFFF    16Kx32 internal program
+                  01800000-019FFFFF    Internal peripheral
+                  80000000-807FFFFF    CE0 2Mx32 SDRAM running @ 100MHz
+                  90000000-9000FFFF    CE1 Async peripherals:
+
+                  EMIF config
+                  ------------
+                  Global EMIF control
+                  0 -
+                  1 -
+                  2 -
+                  3 CLK2EN = 1   CLKOUT2 enabled
+                  4 CLK1EN = 0   CLKOUT1 disabled
+                  5 EKEN = 1 <--!! C6713 specific, enables ECLKOUT
+                  6 -
+                  7 NOHOLD = 1   external HOLD disabled
+                  8 HOLDA = 0    HOLDA output is low
+                  9 HOLD = 0             HOLD input is low
+                  10 ARDY = 1    ARDY input is high
+                  11 BUSREQ = 0   BUSREQ output is low
+                  12,13 Reserved = 1
+                */
+               hpi_write_word(pdo, 0x01800000, 0x34A8);
+
+               /* EMIF CE0 setup - 2Mx32 Sync DRAM
+                  31..28       Wr setup
+                  27..22       Wr strobe
+                  21..20       Wr hold
+                  19..16       Rd setup
+                  15..14       -
+                  13..8        Rd strobe
+                  7..4         MTYPE   0011            Sync DRAM 32bits
+                  3            Wr hold MSB
+                  2..0         Rd hold
+                */
+               hpi_write_word(pdo, 0x01800008, 0x00000030);
+
+               /* EMIF SDRAM Extension
+                  31-21        0
+                  20           WR2RD = 0
+                  19-18        WR2DEAC = 1
+                  17           WR2WR = 0
+                  16-15        R2WDQM = 2
+                  14-12        RD2WR = 4
+                  11-10        RD2DEAC = 1
+                  9            RD2RD = 1
+                  8-7          THZP = 10b
+                  6-5          TWR  = 2-1 = 01b (tWR = 10ns)
+                  4            TRRD = 0b = 2 ECLK (tRRD = 14ns)
+                  3-1          TRAS = 5-1 = 100b (Tras=42ns = 5 ECLK)
+                  1            CAS latency = 3 ECLK
+                  (for Micron 2M32-7 operating at 100Mhz)
+                */
+
+               /* need to use this else DSP code crashes */
+               hpi_write_word(pdo, 0x01800020, 0x001BDF29);
+
+               /* EMIF SDRAM control - set up for a 2Mx32 SDRAM (512x32x4 bank)
+                  31           -               -
+                  30           SDBSZ   1               4 bank
+                  29..28       SDRSZ   00              11 row address pins
+                  27..26       SDCSZ   01              8 column address pins
+                  25           RFEN    1               refersh enabled
+                  24           INIT    1               init SDRAM
+                  23..20       TRCD    0001
+                  19..16       TRP             0001
+                  15..12       TRC             0110
+                  11..0        -               -
+                */
+               /*      need to use this else DSP code crashes */
+               hpi_write_word(pdo, 0x01800018, 0x47117000);
+
+               /* EMIF SDRAM Refresh Timing */
+               hpi_write_word(pdo, 0x0180001C, 0x00000410);
+
+               /*MIF CE1 setup - Async peripherals
+                  @100MHz bus speed, each cycle is 10ns,
+                  31..28       Wr setup  = 1
+                  27..22       Wr strobe = 3                   30ns
+                  21..20       Wr hold = 1
+                  19..16       Rd setup =1
+                  15..14       Ta = 2
+                  13..8        Rd strobe = 3                   30ns
+                  7..4         MTYPE   0010            Async 32bits
+                  3            Wr hold MSB =0
+                  2..0         Rd hold = 1
+                */
+               {
+                       u32 cE1 =
+                               (1L << 28) | (3L << 22) | (1L << 20) | (1L <<
+                               16) | (2L << 14) | (3L << 8) | (2L << 4) | 1L;
+                       hpi_write_word(pdo, 0x01800004, cE1);
+               }
+
+               /* delay a little to allow SDRAM and DSP to "get going" */
+
+               for (i = 0; i < 1000; i++)
+                       delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+
+               /* test access to SDRAM */
+               {
+                       test_addr = 0x80000000;
+                       test_data = 0x00000001;
+                       /* test each bit in the 32bit word */
+                       for (j = 0; j < 32; j++) {
+                               hpi_write_word(pdo, test_addr, test_data);
+                               data = hpi_read_word(pdo, test_addr);
+                               if (data != test_data) {
+                                       HPI_DEBUG_LOG(ERROR,
+                                               "DSP dram %x %x %x %x\n",
+                                               test_addr, test_data, data,
+                                               dsp_index);
+
+                                       return HPI6000_ERROR_INIT_SDRAM1;
+                               }
+                               test_data = test_data << 1;
+                       }
+                       /* test every Nth address in the DRAM */
+#define DRAM_SIZE_WORDS 0x200000       /*2_mx32 */
+#define DRAM_INC 1024
+                       test_addr = 0x80000000;
+                       test_data = 0x0;
+                       for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
+                               hpi_write_word(pdo, test_addr + i, test_data);
+                               test_data++;
+                       }
+                       test_addr = 0x80000000;
+                       test_data = 0x0;
+                       for (i = 0; i < DRAM_SIZE_WORDS; i = i + DRAM_INC) {
+                               data = hpi_read_word(pdo, test_addr + i);
+                               if (data != test_data) {
+                                       HPI_DEBUG_LOG(ERROR,
+                                               "DSP dram %x %x %x %x\n",
+                                               test_addr + i, test_data,
+                                               data, dsp_index);
+                                       return HPI6000_ERROR_INIT_SDRAM2;
+                               }
+                               test_data++;
+                       }
+
+               }
+
+               /* write the DSP code down into the DSPs memory */
+               /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
+               dsp_code.ps_dev = pao->pci.p_os_data;
+
+               error = hpi_dsp_code_open(boot_load_family, &dsp_code,
+                       pos_error_code);
+
+               if (error)
+                       return error;
+
+               while (1) {
+                       u32 length;
+                       u32 address;
+                       u32 type;
+                       u32 *pcode;
+
+                       error = hpi_dsp_code_read_word(&dsp_code, &length);
+                       if (error)
+                               break;
+                       if (length == 0xFFFFFFFF)
+                               break;  /* end of code */
+
+                       error = hpi_dsp_code_read_word(&dsp_code, &address);
+                       if (error)
+                               break;
+                       error = hpi_dsp_code_read_word(&dsp_code, &type);
+                       if (error)
+                               break;
+                       error = hpi_dsp_code_read_block(length, &dsp_code,
+                               &pcode);
+                       if (error)
+                               break;
+                       error = hpi6000_dsp_block_write32(pao, (u16)dsp_index,
+                               address, pcode, length);
+                       if (error)
+                               break;
+               }
+
+               if (error) {
+                       hpi_dsp_code_close(&dsp_code);
+                       return error;
+               }
+               /* verify that code was written correctly */
+               /* this time through, assume no errors in DSP code file/array */
+               hpi_dsp_code_rewind(&dsp_code);
+               while (1) {
+                       u32 length;
+                       u32 address;
+                       u32 type;
+                       u32 *pcode;
+
+                       hpi_dsp_code_read_word(&dsp_code, &length);
+                       if (length == 0xFFFFFFFF)
+                               break;  /* end of code */
+
+                       hpi_dsp_code_read_word(&dsp_code, &address);
+                       hpi_dsp_code_read_word(&dsp_code, &type);
+                       hpi_dsp_code_read_block(length, &dsp_code, &pcode);
+
+                       for (i = 0; i < length; i++) {
+                               data = hpi_read_word(pdo, address);
+                               if (data != *pcode) {
+                                       error = HPI6000_ERROR_INIT_VERIFY;
+                                       HPI_DEBUG_LOG(ERROR,
+                                               "DSP verify %x %x %x %x\n",
+                                               address, *pcode, data,
+                                               dsp_index);
+                                       break;
+                               }
+                               pcode++;
+                               address += 4;
+                       }
+                       if (error)
+                               break;
+               }
+               hpi_dsp_code_close(&dsp_code);
+               if (error)
+                       return error;
+
+               /* zero out the hostmailbox */
+               {
+                       u32 address = HPI_HIF_ADDR(host_cmd);
+                       for (i = 0; i < 4; i++) {
+                               hpi_write_word(pdo, address, 0);
+                               address += 4;
+                       }
+               }
+               /* write the DSP number into the hostmailbox */
+               /* structure before starting the DSP */
+               hpi_write_word(pdo, HPI_HIF_ADDR(dsp_number), dsp_index);
+
+               /* write the DSP adapter Info into the */
+               /* hostmailbox before starting the DSP */
+               if (dsp_index > 0)
+                       hpi_write_word(pdo, HPI_HIF_ADDR(adapter_info),
+                               adapter_info);
+
+               /* step 3. Start code by sending interrupt */
+               iowrite32(0x00030003, pdo->prHPI_control);
+               for (i = 0; i < 10000; i++)
+                       delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+
+               /* wait for a non-zero value in hostcmd -
+                * indicating initialization is complete
+                *
+                * Init could take a while if DSP checks SDRAM memory
+                * Was 200000. Increased to 2000000 for ASI8801 so we
+                * don't get 938 errors.
+                */
+               timeout = 2000000;
+               while (timeout) {
+                       do {
+                               read = hpi_read_word(pdo,
+                                       HPI_HIF_ADDR(host_cmd));
+                       } while (--timeout
+                               && hpi6000_check_PCI2040_error_flag(pao,
+                                       H6READ));
+
+                       if (read)
+                               break;
+                       /* The following is a workaround for bug #94:
+                        * Bluescreen on install and subsequent boots on a
+                        * DELL PowerEdge 600SC PC with 1.8GHz P4 and
+                        * ServerWorks chipset. Without this delay the system
+                        * locks up with a bluescreen (NOT GPF or pagefault).
+                        */
+                       else
+                               hpios_delay_micro_seconds(1000);
+               }
+               if (timeout == 0)
+                       return HPI6000_ERROR_INIT_NOACK;
+
+               /* read the DSP adapter Info from the */
+               /* hostmailbox structure after starting the DSP */
+               if (dsp_index == 0) {
+                       /*u32 dwTestData=0; */
+                       u32 mask = 0;
+
+                       adapter_info =
+                               hpi_read_word(pdo,
+                               HPI_HIF_ADDR(adapter_info));
+                       if (HPI_ADAPTER_FAMILY_ASI
+                               (HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER
+                                       (adapter_info)) ==
+                               HPI_ADAPTER_FAMILY_ASI(0x6200))
+                               /* all 6200 cards have this many DSPs */
+                               phw->num_dsp = 2;
+
+                       /* test that the PLD is programmed */
+                       /* and we can read/write 24bits */
+#define PLD_BASE_ADDRESS 0x90000000L   /*for ASI6100/6200/8800 */
+
+                       switch (boot_load_family) {
+                       case HPI_ADAPTER_FAMILY_ASI(0x6200):
+                               /* ASI6100/6200 has 24bit path to FPGA */
+                               mask = 0xFFFFFF00L;
+                               /* ASI5100 uses AX6 code, */
+                               /* but has no PLD r/w register to test */
+                               if (HPI_ADAPTER_FAMILY_ASI(pao->pci.
+                                               subsys_device_id) ==
+                                       HPI_ADAPTER_FAMILY_ASI(0x5100))
+                                       mask = 0x00000000L;
+                               break;
+                       case HPI_ADAPTER_FAMILY_ASI(0x8800):
+                               /* ASI8800 has 16bit path to FPGA */
+                               mask = 0xFFFF0000L;
+                               break;
+                       }
+                       test_data = 0xAAAAAA00L & mask;
+                       /* write to 24 bit Debug register (D31-D8) */
+                       hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
+                       read = hpi_read_word(pdo,
+                               PLD_BASE_ADDRESS + 4L) & mask;
+                       if (read != test_data) {
+                               HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
+                                       read);
+                               return HPI6000_ERROR_INIT_PLDTEST1;
+                       }
+                       test_data = 0x55555500L & mask;
+                       hpi_write_word(pdo, PLD_BASE_ADDRESS + 4L, test_data);
+                       read = hpi_read_word(pdo,
+                               PLD_BASE_ADDRESS + 4L) & mask;
+                       if (read != test_data) {
+                               HPI_DEBUG_LOG(ERROR, "PLD %x %x\n", test_data,
+                                       read);
+                               return HPI6000_ERROR_INIT_PLDTEST2;
+                       }
+               }
+       }       /* for numDSP */
+       return 0;
+}
+
+#define PCI_TIMEOUT 100
+
+static int hpi_set_address(struct dsp_obj *pdo, u32 address)
+{
+       u32 timeout = PCI_TIMEOUT;
+
+       do {
+               iowrite32(address, pdo->prHPI_address);
+       } while (hpi6000_check_PCI2040_error_flag(pdo->pa_parent_adapter,
+                       H6WRITE)
+               && --timeout);
+
+       if (timeout)
+               return 0;
+
+       return 1;
+}
+
+/* write one word to the HPI port */
+static void hpi_write_word(struct dsp_obj *pdo, u32 address, u32 data)
+{
+       if (hpi_set_address(pdo, address))
+               return;
+       iowrite32(data, pdo->prHPI_data);
+}
+
+/* read one word from the HPI port */
+static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
+{
+       u32 data = 0;
+
+       if (hpi_set_address(pdo, address))
+               return 0;       /*? no way to return error */
+
+       /* take care of errata in revB DSP (2.0.1) */
+       data = ioread32(pdo->prHPI_data);
+       return data;
+}
+
+/* write a block of 32bit words to the DSP HPI port using auto-inc mode */
+static void hpi_write_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
+       u32 length)
+{
+       u16 length16 = length - 1;
+
+       if (length == 0)
+               return;
+
+       if (hpi_set_address(pdo, address))
+               return;
+
+       iowrite32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
+
+       /* take care of errata in revB DSP (2.0.1) */
+       /* must end with non auto-inc */
+       iowrite32(*(pdata + length - 1), pdo->prHPI_data);
+}
+
+/** read a block of 32bit words from the DSP HPI port using auto-inc mode
+ */
+static void hpi_read_block(struct dsp_obj *pdo, u32 address, u32 *pdata,
+       u32 length)
+{
+       u16 length16 = length - 1;
+
+       if (length == 0)
+               return;
+
+       if (hpi_set_address(pdo, address))
+               return;
+
+       ioread32_rep(pdo->prHPI_data_auto_inc, pdata, length16);
+
+       /* take care of errata in revB DSP (2.0.1) */
+       /* must end with non auto-inc */
+       *(pdata + length - 1) = ioread32(pdo->prHPI_data);
+}
+
+static u16 hpi6000_dsp_block_write32(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 hpi_address, u32 *source, u32 count)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 time_out = PCI_TIMEOUT;
+       int c6711_burst_size = 128;
+       u32 local_hpi_address = hpi_address;
+       int local_count = count;
+       int xfer_size;
+       u32 *pdata = source;
+
+       while (local_count) {
+               if (local_count > c6711_burst_size)
+                       xfer_size = c6711_burst_size;
+               else
+                       xfer_size = local_count;
+
+               time_out = PCI_TIMEOUT;
+               do {
+                       hpi_write_block(pdo, local_hpi_address, pdata,
+                               xfer_size);
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
+                       && --time_out);
+
+               if (!time_out)
+                       break;
+               pdata += xfer_size;
+               local_hpi_address += sizeof(u32) * xfer_size;
+               local_count -= xfer_size;
+       }
+
+       if (time_out)
+               return 0;
+       else
+               return 1;
+}
+
+static u16 hpi6000_dsp_block_read32(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 hpi_address, u32 *dest, u32 count)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 time_out = PCI_TIMEOUT;
+       int c6711_burst_size = 16;
+       u32 local_hpi_address = hpi_address;
+       int local_count = count;
+       int xfer_size;
+       u32 *pdata = dest;
+       u32 loop_count = 0;
+
+       while (local_count) {
+               if (local_count > c6711_burst_size)
+                       xfer_size = c6711_burst_size;
+               else
+                       xfer_size = local_count;
+
+               time_out = PCI_TIMEOUT;
+               do {
+                       hpi_read_block(pdo, local_hpi_address, pdata,
+                               xfer_size);
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
+                       && --time_out);
+               if (!time_out)
+                       break;
+
+               pdata += xfer_size;
+               local_hpi_address += sizeof(u32) * xfer_size;
+               local_count -= xfer_size;
+               loop_count++;
+       }
+
+       if (time_out)
+               return 0;
+       else
+               return 1;
+}
+
+static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
+       u16 dsp_index, struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+       struct dsp_obj *pdo = &phw->ado[dsp_index];
+       u32 timeout;
+       u16 ack;
+       u32 address;
+       u32 length;
+       u32 *p_data;
+       u16 error = 0;
+
+       /* does the DSP we are referencing exist? */
+       if (dsp_index >= phw->num_dsp)
+               return HPI6000_ERROR_MSG_INVALID_DSP_INDEX;
+
+       ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
+       if (ack & HPI_HIF_ERROR_MASK) {
+               pao->dsp_crashed++;
+               return HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT;
+       }
+       pao->dsp_crashed = 0;
+
+       /* send the message */
+
+       /* get the address and size */
+       if (phw->message_buffer_address_on_dsp == 0) {
+               timeout = TIMEOUT;
+               do {
+                       address =
+                               hpi_read_word(pdo,
+                               HPI_HIF_ADDR(message_buffer_address));
+                       phw->message_buffer_address_on_dsp = address;
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
+                       && --timeout);
+               if (!timeout)
+                       return HPI6000_ERROR_MSG_GET_ADR;
+       } else
+               address = phw->message_buffer_address_on_dsp;
+
+       /*        dwLength = sizeof(struct hpi_message); */
+       length = phm->size;
+
+       /* send it */
+       p_data = (u32 *)phm;
+       if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
+                       (u16)length / 4))
+               return HPI6000_ERROR_MSG_RESP_BLOCKWRITE32;
+
+       if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_GET_RESP))
+               return HPI6000_ERROR_MSG_RESP_GETRESPCMD;
+       hpi6000_send_dsp_interrupt(pdo);
+
+       ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_RESP);
+       if (ack & HPI_HIF_ERROR_MASK)
+               return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
+
+       /* get the address and size */
+       if (phw->response_buffer_address_on_dsp == 0) {
+               timeout = TIMEOUT;
+               do {
+                       address =
+                               hpi_read_word(pdo,
+                               HPI_HIF_ADDR(response_buffer_address));
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
+                       && --timeout);
+               phw->response_buffer_address_on_dsp = address;
+
+               if (!timeout)
+                       return HPI6000_ERROR_RESP_GET_ADR;
+       } else
+               address = phw->response_buffer_address_on_dsp;
+
+       /* read the length of the response back from the DSP */
+       timeout = TIMEOUT;
+       do {
+               length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
+       } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
+       if (!timeout)
+               length = sizeof(struct hpi_response);
+
+       /* get it */
+       p_data = (u32 *)phr;
+       if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
+                       (u16)length / 4))
+               return HPI6000_ERROR_MSG_RESP_BLOCKREAD32;
+
+       /* set i/f back to idle */
+       if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
+               return HPI6000_ERROR_MSG_RESP_IDLECMD;
+       hpi6000_send_dsp_interrupt(pdo);
+
+       error = hpi_validate_response(phm, phr);
+       return error;
+}
+
+/* have to set up the below defines to match stuff in the MAP file */
+
+#define MSG_ADDRESS (HPI_HIF_BASE+0x18)
+#define MSG_LENGTH 11
+#define RESP_ADDRESS (HPI_HIF_BASE+0x44)
+#define RESP_LENGTH 16
+#define QUEUE_START  (HPI_HIF_BASE+0x88)
+#define QUEUE_SIZE 0x8000
+
+static short hpi6000_send_data_check_adr(u32 address, u32 length_in_dwords)
+{
+/*#define CHECKING       // comment this line in to enable checking */
+#ifdef CHECKING
+       if (address < (u32)MSG_ADDRESS)
+               return 0;
+       if (address > (u32)(QUEUE_START + QUEUE_SIZE))
+               return 0;
+       if ((address + (length_in_dwords << 2)) >
+               (u32)(QUEUE_START + QUEUE_SIZE))
+               return 0;
+#else
+       (void)address;
+       (void)length_in_dwords;
+       return 1;
+#endif
+}
+
+static short hpi6000_send_data(struct hpi_adapter_obj *pao, u16 dsp_index,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 data_sent = 0;
+       u16 ack;
+       u32 length, address;
+       u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
+       u16 time_out = 8;
+
+       (void)phr;
+
+       /* round dwDataSize down to nearest 4 bytes */
+       while ((data_sent < (phm->u.d.u.data.data_size & ~3L))
+               && --time_out) {
+               ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
+               if (ack & HPI_HIF_ERROR_MASK)
+                       return HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT;
+
+               if (hpi6000_send_host_command(pao, dsp_index,
+                               HPI_HIF_SEND_DATA))
+                       return HPI6000_ERROR_SEND_DATA_CMD;
+
+               hpi6000_send_dsp_interrupt(pdo);
+
+               ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_SEND_DATA);
+
+               if (ack & HPI_HIF_ERROR_MASK)
+                       return HPI6000_ERROR_SEND_DATA_ACK;
+
+               do {
+                       /* get the address and size */
+                       address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
+                       /* DSP returns number of DWORDS */
+                       length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
+
+               if (!hpi6000_send_data_check_adr(address, length))
+                       return HPI6000_ERROR_SEND_DATA_ADR;
+
+               /* send the data. break data into 512 DWORD blocks (2K bytes)
+                * and send using block write. 2Kbytes is the max as this is the
+                * memory window given to the HPI data register by the PCI2040
+                */
+
+               {
+                       u32 len = length;
+                       u32 blk_len = 512;
+                       while (len) {
+                               if (len < blk_len)
+                                       blk_len = len;
+                               if (hpi6000_dsp_block_write32(pao, dsp_index,
+                                               address, p_data, blk_len))
+                                       return HPI6000_ERROR_SEND_DATA_WRITE;
+                               address += blk_len * 4;
+                               p_data += blk_len;
+                               len -= blk_len;
+                       }
+               }
+
+               if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
+                       return HPI6000_ERROR_SEND_DATA_IDLECMD;
+
+               hpi6000_send_dsp_interrupt(pdo);
+
+               data_sent += length * 4;
+       }
+       if (!time_out)
+               return HPI6000_ERROR_SEND_DATA_TIMEOUT;
+       return 0;
+}
+
+static short hpi6000_get_data(struct hpi_adapter_obj *pao, u16 dsp_index,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 data_got = 0;
+       u16 ack;
+       u32 length, address;
+       u32 *p_data = (u32 *)phm->u.d.u.data.pb_data;
+
+       (void)phr;      /* this parameter not used! */
+
+       /* round dwDataSize down to nearest 4 bytes */
+       while (data_got < (phm->u.d.u.data.data_size & ~3L)) {
+               ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
+               if (ack & HPI_HIF_ERROR_MASK)
+                       return HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT;
+
+               if (hpi6000_send_host_command(pao, dsp_index,
+                               HPI_HIF_GET_DATA))
+                       return HPI6000_ERROR_GET_DATA_CMD;
+               hpi6000_send_dsp_interrupt(pdo);
+
+               ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_GET_DATA);
+
+               if (ack & HPI_HIF_ERROR_MASK)
+                       return HPI6000_ERROR_GET_DATA_ACK;
+
+               /* get the address and size */
+               do {
+                       address = hpi_read_word(pdo, HPI_HIF_ADDR(address));
+                       length = hpi_read_word(pdo, HPI_HIF_ADDR(length));
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6READ));
+
+               /* read the data */
+               {
+                       u32 len = length;
+                       u32 blk_len = 512;
+                       while (len) {
+                               if (len < blk_len)
+                                       blk_len = len;
+                               if (hpi6000_dsp_block_read32(pao, dsp_index,
+                                               address, p_data, blk_len))
+                                       return HPI6000_ERROR_GET_DATA_READ;
+                               address += blk_len * 4;
+                               p_data += blk_len;
+                               len -= blk_len;
+                       }
+               }
+
+               if (hpi6000_send_host_command(pao, dsp_index, HPI_HIF_IDLE))
+                       return HPI6000_ERROR_GET_DATA_IDLECMD;
+               hpi6000_send_dsp_interrupt(pdo);
+
+               data_got += length * 4;
+       }
+       return 0;
+}
+
+static void hpi6000_send_dsp_interrupt(struct dsp_obj *pdo)
+{
+       iowrite32(0x00030003, pdo->prHPI_control);      /* DSPINT */
+}
+
+static short hpi6000_send_host_command(struct hpi_adapter_obj *pao,
+       u16 dsp_index, u32 host_cmd)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 timeout = TIMEOUT;
+
+       /* set command */
+       do {
+               hpi_write_word(pdo, HPI_HIF_ADDR(host_cmd), host_cmd);
+               /* flush the FIFO */
+               hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
+       } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE) && --timeout);
+
+       /* reset the interrupt bit */
+       iowrite32(0x00040004, pdo->prHPI_control);
+
+       if (timeout)
+               return 0;
+       else
+               return 1;
+}
+
+/* if the PCI2040 has recorded an HPI timeout, reset the error and return 1 */
+static short hpi6000_check_PCI2040_error_flag(struct hpi_adapter_obj *pao,
+       u16 read_or_write)
+{
+       u32 hPI_error;
+
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+
+       /* read the error bits from the PCI2040 */
+       hPI_error = ioread32(phw->dw2040_HPICSR + HPI_ERROR_REPORT);
+       if (hPI_error) {
+               /* reset the error flag */
+               iowrite32(0L, phw->dw2040_HPICSR + HPI_ERROR_REPORT);
+               phw->pCI2040HPI_error_count++;
+               if (read_or_write == 1)
+                       gw_pci_read_asserts++;     /************* inc global */
+               else
+                       gw_pci_write_asserts++;
+               return 1;
+       } else
+               return 0;
+}
+
+static short hpi6000_wait_dsp_ack(struct hpi_adapter_obj *pao, u16 dsp_index,
+       u32 ack_value)
+{
+       struct dsp_obj *pdo =
+               &(*(struct hpi_hw_obj *)pao->priv).ado[dsp_index];
+       u32 ack = 0L;
+       u32 timeout;
+       u32 hPIC = 0L;
+
+       /* wait for host interrupt to signal ack is ready */
+       timeout = TIMEOUT;
+       while (--timeout) {
+               hPIC = ioread32(pdo->prHPI_control);
+               if (hPIC & 0x04)        /* 0x04 = HINT from DSP */
+                       break;
+       }
+       if (timeout == 0)
+               return HPI_HIF_ERROR_MASK;
+
+       /* wait for dwAckValue */
+       timeout = TIMEOUT;
+       while (--timeout) {
+               /* read the ack mailbox */
+               ack = hpi_read_word(pdo, HPI_HIF_ADDR(dsp_ack));
+               if (ack == ack_value)
+                       break;
+               if ((ack & HPI_HIF_ERROR_MASK)
+                       && !hpi6000_check_PCI2040_error_flag(pao, H6READ))
+                       break;
+               /*for (i=0;i<1000;i++) */
+               /*      dwPause=i+1; */
+       }
+       if (ack & HPI_HIF_ERROR_MASK)
+               /* indicates bad read from DSP -
+                  typically 0xffffff is read for some reason */
+               ack = HPI_HIF_ERROR_MASK;
+
+       if (timeout == 0)
+               ack = HPI_HIF_ERROR_MASK;
+       return (short)ack;
+}
+
+static short hpi6000_update_control_cache(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm)
+{
+       const u16 dsp_index = 0;
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+       struct dsp_obj *pdo = &phw->ado[dsp_index];
+       u32 timeout;
+       u32 cache_dirty_flag;
+       u16 err;
+
+       hpios_dsplock_lock(pao);
+
+       timeout = TIMEOUT;
+       do {
+               cache_dirty_flag =
+                       hpi_read_word((struct dsp_obj *)pdo,
+                       HPI_HIF_ADDR(control_cache_is_dirty));
+       } while (hpi6000_check_PCI2040_error_flag(pao, H6READ) && --timeout);
+       if (!timeout) {
+               err = HPI6000_ERROR_CONTROL_CACHE_PARAMS;
+               goto unlock;
+       }
+
+       if (cache_dirty_flag) {
+               /* read the cached controls */
+               u32 address;
+               u32 length;
+
+               timeout = TIMEOUT;
+               if (pdo->control_cache_address_on_dsp == 0) {
+                       do {
+                               address =
+                                       hpi_read_word((struct dsp_obj *)pdo,
+                                       HPI_HIF_ADDR(control_cache_address));
+
+                               length = hpi_read_word((struct dsp_obj *)pdo,
+                                       HPI_HIF_ADDR
+                                       (control_cache_size_in_bytes));
+                       } while (hpi6000_check_PCI2040_error_flag(pao, H6READ)
+                               && --timeout);
+                       if (!timeout) {
+                               err = HPI6000_ERROR_CONTROL_CACHE_ADDRLEN;
+                               goto unlock;
+                       }
+                       pdo->control_cache_address_on_dsp = address;
+                       pdo->control_cache_length_on_dsp = length;
+               } else {
+                       address = pdo->control_cache_address_on_dsp;
+                       length = pdo->control_cache_length_on_dsp;
+               }
+
+               if (hpi6000_dsp_block_read32(pao, dsp_index, address,
+                               (u32 *)&phw->control_cache[0],
+                               length / sizeof(u32))) {
+                       err = HPI6000_ERROR_CONTROL_CACHE_READ;
+                       goto unlock;
+               }
+               do {
+                       hpi_write_word((struct dsp_obj *)pdo,
+                               HPI_HIF_ADDR(control_cache_is_dirty), 0);
+                       /* flush the FIFO */
+                       hpi_set_address(pdo, HPI_HIF_ADDR(host_cmd));
+               } while (hpi6000_check_PCI2040_error_flag(pao, H6WRITE)
+                       && --timeout);
+               if (!timeout) {
+                       err = HPI6000_ERROR_CONTROL_CACHE_FLUSH;
+                       goto unlock;
+               }
+
+       }
+       err = 0;
+
+unlock:
+       hpios_dsplock_unlock(pao);
+       return err;
+}
+
+/** Get dsp index for multi DSP adapters only */
+static u16 get_dsp_index(struct hpi_adapter_obj *pao, struct hpi_message *phm)
+{
+       u16 ret = 0;
+       switch (phm->object) {
+       case HPI_OBJ_ISTREAM:
+               if (phm->obj_index < 2)
+                       ret = 1;
+               break;
+       case HPI_OBJ_PROFILE:
+               ret = phm->obj_index;
+               break;
+       default:
+               break;
+       }
+       return ret;
+}
+
+/** Complete transaction with DSP
+
+Send message, get response, send or get stream data if any.
+*/
+static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+       u16 error = 0;
+       u16 dsp_index = 0;
+       u16 num_dsp = ((struct hpi_hw_obj *)pao->priv)->num_dsp;
+       hpios_dsplock_lock(pao);
+
+       if (num_dsp < 2)
+               dsp_index = 0;
+       else {
+               dsp_index = get_dsp_index(pao, phm);
+
+               /* is this  checked on the DSP anyway? */
+               if ((phm->function == HPI_ISTREAM_GROUP_ADD)
+                       || (phm->function == HPI_OSTREAM_GROUP_ADD)) {
+                       struct hpi_message hm;
+                       u16 add_index;
+                       hm.obj_index = phm->u.d.u.stream.stream_index;
+                       hm.object = phm->u.d.u.stream.object_type;
+                       add_index = get_dsp_index(pao, &hm);
+                       if (add_index != dsp_index) {
+                               phr->error = HPI_ERROR_NO_INTERDSP_GROUPS;
+                               return;
+                       }
+               }
+       }
+       error = hpi6000_message_response_sequence(pao, dsp_index, phm, phr);
+
+       /* maybe an error response */
+       if (error) {
+               /* something failed in the HPI/DSP interface */
+               phr->error = error;
+               /* just the header of the response is valid */
+               phr->size = sizeof(struct hpi_response_header);
+               goto err;
+       }
+
+       if (phr->error != 0)    /* something failed in the DSP */
+               goto err;
+
+       switch (phm->function) {
+       case HPI_OSTREAM_WRITE:
+       case HPI_ISTREAM_ANC_WRITE:
+               error = hpi6000_send_data(pao, dsp_index, phm, phr);
+               break;
+       case HPI_ISTREAM_READ:
+       case HPI_OSTREAM_ANC_READ:
+               error = hpi6000_get_data(pao, dsp_index, phm, phr);
+               break;
+       case HPI_ADAPTER_GET_ASSERT:
+               phr->u.a.adapter_index = 0;     /* dsp 0 default */
+               if (num_dsp == 2) {
+                       if (!phr->u.a.adapter_type) {
+                               /* no assert from dsp 0, check dsp 1 */
+                               error = hpi6000_message_response_sequence(pao,
+                                       1, phm, phr);
+                               phr->u.a.adapter_index = 1;
+                       }
+               }
+       }
+
+       if (error)
+               phr->error = error;
+
+err:
+       hpios_dsplock_unlock(pao);
+       return;
+}
diff --git a/sound/pci/asihpi/hpi6000.h b/sound/pci/asihpi/hpi6000.h
new file mode 100644 (file)
index 0000000..4c7d507
--- /dev/null
@@ -0,0 +1,70 @@
+/*****************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Public declarations for DSP Proramming Interface to TI C6701
+
+Shared between hpi6000.c and DSP code
+
+(C) Copyright AudioScience Inc. 1998-2003
+******************************************************************************/
+
+#ifndef _HPI6000_H_
+#define _HPI6000_H_
+
+#define HPI_NMIXER_CONTROLS 200
+
+/*
+ * Control caching is always supported in the HPI code.
+ * The DSP should make sure that dwControlCacheSizeInBytes is initialized to 0
+ * during boot to make it in-active.
+ */
+struct hpi_hif_6000 {
+       u32 host_cmd;
+       u32 dsp_ack;
+       u32 address;
+       u32 length;
+       u32 message_buffer_address;
+       u32 response_buffer_address;
+       u32 dsp_number;
+       u32 adapter_info;
+       u32 control_cache_is_dirty;
+       u32 control_cache_address;
+       u32 control_cache_size_in_bytes;
+       u32 control_cache_count;
+};
+
+#define HPI_HIF_PACK_ADAPTER_INFO(adapter, version_major, version_minor) \
+               ((adapter << 16) | (version_major << 8) | version_minor)
+#define HPI_HIF_ADAPTER_INFO_EXTRACT_ADAPTER(adapterinfo) \
+               ((adapterinfo >> 16) & 0xffff)
+#define HPI_HIF_ADAPTER_INFO_EXTRACT_HWVERSION_MAJOR(adapterinfo) \
+               ((adapterinfo >> 8) & 0xff)
+#define HPI_HIF_ADAPTER_INFO_EXTRACT_HWVERSION_MINOR(adapterinfo) \
+               (adapterinfo & 0xff)
+
+/* Command/status exchanged between host and DSP */
+#define HPI_HIF_IDLE            0
+#define HPI_HIF_SEND_MSG        1
+#define HPI_HIF_GET_RESP        2
+#define HPI_HIF_DATA_MASK       0x10
+#define HPI_HIF_SEND_DATA       0x13
+#define HPI_HIF_GET_DATA        0x14
+#define HPI_HIF_SEND_DONE       5
+#define HPI_HIF_RESET           9
+
+#endif                         /* _HPI6000_H_ */
diff --git a/sound/pci/asihpi/hpi6205.c b/sound/pci/asihpi/hpi6205.c
new file mode 100644 (file)
index 0000000..5e88c1f
--- /dev/null
@@ -0,0 +1,2331 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ Hardware Programming Interface (HPI) for AudioScience
+ ASI50xx, AS51xx, ASI6xxx, ASI87xx ASI89xx series adapters.
+ These PCI and PCIe bus adapters are based on a
+ TMS320C6205 PCI bus mastering DSP,
+ and (except ASI50xx) TI TMS320C6xxx floating point DSP
+
+ Exported function:
+ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
+
+(C) Copyright AudioScience Inc. 1998-2010
+*******************************************************************************/
+#define SOURCEFILE_NAME "hpi6205.c"
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+#include "hpidebug.h"
+#include "hpi6205.h"
+#include "hpidspcd.h"
+#include "hpicmn.h"
+
+/*****************************************************************************/
+/* HPI6205 specific error codes */
+#define HPI6205_ERROR_BASE                      1000
+/*#define HPI6205_ERROR_MEM_ALLOC 1001 */
+#define HPI6205_ERROR_6205_NO_IRQ               1002
+#define HPI6205_ERROR_6205_INIT_FAILED          1003
+/*#define HPI6205_ERROR_MISSING_DSPCODE 1004 */
+#define HPI6205_ERROR_UNKNOWN_PCI_DEVICE        1005
+#define HPI6205_ERROR_6205_REG                  1006
+#define HPI6205_ERROR_6205_DSPPAGE              1007
+#define HPI6205_ERROR_BAD_DSPINDEX              1008
+#define HPI6205_ERROR_C6713_HPIC                1009
+#define HPI6205_ERROR_C6713_HPIA                1010
+#define HPI6205_ERROR_C6713_PLL                 1011
+#define HPI6205_ERROR_DSP_INTMEM                1012
+#define HPI6205_ERROR_DSP_EXTMEM                1013
+#define HPI6205_ERROR_DSP_PLD                   1014
+#define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT     1015
+#define HPI6205_ERROR_MSG_RESP_TIMEOUT          1016
+#define HPI6205_ERROR_6205_EEPROM               1017
+#define HPI6205_ERROR_DSP_EMIF                  1018
+
+#define hpi6205_error(dsp_index, err) (err)
+/*****************************************************************************/
+/* for C6205 PCI i/f */
+/* Host Status Register (HSR) bitfields */
+#define C6205_HSR_INTSRC        0x01
+#define C6205_HSR_INTAVAL       0x02
+#define C6205_HSR_INTAM         0x04
+#define C6205_HSR_CFGERR        0x08
+#define C6205_HSR_EEREAD        0x10
+/* Host-to-DSP Control Register (HDCR) bitfields */
+#define C6205_HDCR_WARMRESET    0x01
+#define C6205_HDCR_DSPINT       0x02
+#define C6205_HDCR_PCIBOOT      0x04
+/* DSP Page Register (DSPP) bitfields, */
+/* defines 4 Mbyte page that BAR0 points to */
+#define C6205_DSPP_MAP1         0x400
+
+/* BAR0 maps to prefetchable 4 Mbyte memory block set by DSPP.
+ * BAR1 maps to non-prefetchable 8 Mbyte memory block
+ * of DSP memory mapped registers (starting at 0x01800000).
+ * 0x01800000 is hardcoded in the PCI i/f, so that only the offset from this
+ * needs to be added to the BAR1 base address set in the PCI config reg
+ */
+#define C6205_BAR1_PCI_IO_OFFSET (0x027FFF0L)
+#define C6205_BAR1_HSR  (C6205_BAR1_PCI_IO_OFFSET)
+#define C6205_BAR1_HDCR (C6205_BAR1_PCI_IO_OFFSET+4)
+#define C6205_BAR1_DSPP (C6205_BAR1_PCI_IO_OFFSET+8)
+
+/* used to control LED (revA) and reset C6713 (revB) */
+#define C6205_BAR0_TIMER1_CTL (0x01980000L)
+
+/* For first 6713 in CE1 space, using DA17,16,2 */
+#define HPICL_ADDR      0x01400000L
+#define HPICH_ADDR      0x01400004L
+#define HPIAL_ADDR      0x01410000L
+#define HPIAH_ADDR      0x01410004L
+#define HPIDIL_ADDR     0x01420000L
+#define HPIDIH_ADDR     0x01420004L
+#define HPIDL_ADDR      0x01430000L
+#define HPIDH_ADDR      0x01430004L
+
+#define C6713_EMIF_GCTL         0x01800000
+#define C6713_EMIF_CE1          0x01800004
+#define C6713_EMIF_CE0          0x01800008
+#define C6713_EMIF_CE2          0x01800010
+#define C6713_EMIF_CE3          0x01800014
+#define C6713_EMIF_SDRAMCTL     0x01800018
+#define C6713_EMIF_SDRAMTIMING  0x0180001C
+#define C6713_EMIF_SDRAMEXT     0x01800020
+
+struct hpi_hw_obj {
+       /* PCI registers */
+       __iomem u32 *prHSR;
+       __iomem u32 *prHDCR;
+       __iomem u32 *prDSPP;
+
+       u32 dsp_page;
+
+       struct consistent_dma_area h_locked_mem;
+       struct bus_master_interface *p_interface_buffer;
+
+       u16 flag_outstream_just_reset[HPI_MAX_STREAMS];
+       /* a non-NULL handle means there is an HPI allocated buffer */
+       struct consistent_dma_area instream_host_buffers[HPI_MAX_STREAMS];
+       struct consistent_dma_area outstream_host_buffers[HPI_MAX_STREAMS];
+       /* non-zero size means a buffer exists, may be external */
+       u32 instream_host_buffer_size[HPI_MAX_STREAMS];
+       u32 outstream_host_buffer_size[HPI_MAX_STREAMS];
+
+       struct consistent_dma_area h_control_cache;
+       struct consistent_dma_area h_async_event_buffer;
+/*      struct hpi_control_cache_single *pControlCache; */
+       struct hpi_async_event *p_async_event_buffer;
+       struct hpi_control_cache *p_cache;
+};
+
+/*****************************************************************************/
+/* local prototypes */
+
+#define check_before_bbm_copy(status, p_bbm_data, l_first_write, l_second_write)
+
+static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us);
+
+static void send_dsp_command(struct hpi_hw_obj *phw, int cmd);
+
+static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code);
+
+static u16 message_response_sequence(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
+       struct hpi_response *phr);
+
+#define HPI6205_TIMEOUT 1000000
+
+static void subsys_create_adapter(struct hpi_message *phm,
+       struct hpi_response *phr);
+static void subsys_delete_adapter(struct hpi_message *phm,
+       struct hpi_response *phr);
+
+static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code);
+
+static void delete_adapter_obj(struct hpi_adapter_obj *pao);
+
+static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+static void outstream_write(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_start(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_open(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_reset(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_read(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static void instream_start(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr);
+
+static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 address);
+
+static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 address, u32 data);
+
+static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
+       int dsp_index);
+
+static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 address, u32 length);
+
+static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
+       int dsp_index);
+
+static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
+       int dsp_index);
+
+static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
+
+/*****************************************************************************/
+
+static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       switch (phm->function) {
+       case HPI_SUBSYS_OPEN:
+       case HPI_SUBSYS_CLOSE:
+       case HPI_SUBSYS_GET_INFO:
+       case HPI_SUBSYS_DRIVER_UNLOAD:
+       case HPI_SUBSYS_DRIVER_LOAD:
+       case HPI_SUBSYS_FIND_ADAPTERS:
+               /* messages that should not get here */
+               phr->error = HPI_ERROR_UNIMPLEMENTED;
+               break;
+       case HPI_SUBSYS_CREATE_ADAPTER:
+               subsys_create_adapter(phm, phr);
+               break;
+       case HPI_SUBSYS_DELETE_ADAPTER:
+               subsys_delete_adapter(phm, phr);
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+static void control_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       struct hpi_hw_obj *phw = pao->priv;
+
+       switch (phm->function) {
+       case HPI_CONTROL_GET_STATE:
+               if (pao->has_control_cache) {
+                       rmb();  /* make sure we see updates DM_aed from DSP */
+                       if (hpi_check_control_cache(phw->p_cache, phm, phr))
+                               break;
+               }
+               hw_message(pao, phm, phr);
+               break;
+       case HPI_CONTROL_GET_INFO:
+               hw_message(pao, phm, phr);
+               break;
+       case HPI_CONTROL_SET_STATE:
+               hw_message(pao, phm, phr);
+               if (pao->has_control_cache)
+                       hpi_sync_control_cache(phw->p_cache, phm, phr);
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+static void adapter_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       switch (phm->function) {
+       default:
+               hw_message(pao, phm, phr);
+               break;
+       }
+}
+
+static void outstream_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       if (phm->obj_index >= HPI_MAX_STREAMS) {
+               phr->error = HPI_ERROR_INVALID_STREAM;
+               HPI_DEBUG_LOG(WARNING,
+                       "message referencing invalid stream %d "
+                       "on adapter index %d\n", phm->obj_index,
+                       phm->adapter_index);
+               return;
+       }
+
+       switch (phm->function) {
+       case HPI_OSTREAM_WRITE:
+               outstream_write(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_GET_INFO:
+               outstream_get_info(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_HOSTBUFFER_ALLOC:
+               outstream_host_buffer_allocate(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_HOSTBUFFER_GET_INFO:
+               outstream_host_buffer_get_info(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_HOSTBUFFER_FREE:
+               outstream_host_buffer_free(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_START:
+               outstream_start(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_OPEN:
+               outstream_open(pao, phm, phr);
+               break;
+       case HPI_OSTREAM_RESET:
+               outstream_reset(pao, phm, phr);
+               break;
+       default:
+               hw_message(pao, phm, phr);
+               break;
+       }
+}
+
+static void instream_message(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       if (phm->obj_index >= HPI_MAX_STREAMS) {
+               phr->error = HPI_ERROR_INVALID_STREAM;
+               HPI_DEBUG_LOG(WARNING,
+                       "message referencing invalid stream %d "
+                       "on adapter index %d\n", phm->obj_index,
+                       phm->adapter_index);
+               return;
+       }
+
+       switch (phm->function) {
+       case HPI_ISTREAM_READ:
+               instream_read(pao, phm, phr);
+               break;
+       case HPI_ISTREAM_GET_INFO:
+               instream_get_info(pao, phm, phr);
+               break;
+       case HPI_ISTREAM_HOSTBUFFER_ALLOC:
+               instream_host_buffer_allocate(pao, phm, phr);
+               break;
+       case HPI_ISTREAM_HOSTBUFFER_GET_INFO:
+               instream_host_buffer_get_info(pao, phm, phr);
+               break;
+       case HPI_ISTREAM_HOSTBUFFER_FREE:
+               instream_host_buffer_free(pao, phm, phr);
+               break;
+       case HPI_ISTREAM_START:
+               instream_start(pao, phm, phr);
+               break;
+       default:
+               hw_message(pao, phm, phr);
+               break;
+       }
+}
+
+/*****************************************************************************/
+/** Entry point to this HPI backend
+ * All calls to the HPI start here
+ */
+void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_adapter_obj *pao = NULL;
+
+       /* subsytem messages are processed by every HPI.
+        * All other messages are ignored unless the adapter index matches
+        * an adapter in the HPI
+        */
+       HPI_DEBUG_LOG(DEBUG, "HPI obj=%d, func=%d\n", phm->object,
+               phm->function);
+
+       /* if Dsp has crashed then do not communicate with it any more */
+       if (phm->object != HPI_OBJ_SUBSYSTEM) {
+               pao = hpi_find_adapter(phm->adapter_index);
+               if (!pao) {
+                       HPI_DEBUG_LOG(DEBUG,
+                               " %d,%d refused, for another HPI?\n",
+                               phm->object, phm->function);
+                       return;
+               }
+
+               if ((pao->dsp_crashed >= 10)
+                       && (phm->function != HPI_ADAPTER_DEBUG_READ)) {
+                       /* allow last resort debug read even after crash */
+                       hpi_init_response(phr, phm->object, phm->function,
+                               HPI_ERROR_DSP_HARDWARE);
+                       HPI_DEBUG_LOG(WARNING, " %d,%d dsp crashed.\n",
+                               phm->object, phm->function);
+                       return;
+               }
+       }
+
+       /* Init default response  */
+       if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
+               hpi_init_response(phr, phm->object, phm->function,
+                       HPI_ERROR_PROCESSING_MESSAGE);
+
+       HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
+       switch (phm->type) {
+       case HPI_TYPE_MESSAGE:
+               switch (phm->object) {
+               case HPI_OBJ_SUBSYSTEM:
+                       subsys_message(phm, phr);
+                       break;
+
+               case HPI_OBJ_ADAPTER:
+                       phr->size =
+                               sizeof(struct hpi_response_header) +
+                               sizeof(struct hpi_adapter_res);
+                       adapter_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_CONTROLEX:
+               case HPI_OBJ_CONTROL:
+                       control_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_OSTREAM:
+                       outstream_message(pao, phm, phr);
+                       break;
+
+               case HPI_OBJ_ISTREAM:
+                       instream_message(pao, phm, phr);
+                       break;
+
+               default:
+                       hw_message(pao, phm, phr);
+                       break;
+               }
+               break;
+
+       default:
+               phr->error = HPI_ERROR_INVALID_TYPE;
+               break;
+       }
+}
+
+/*****************************************************************************/
+/* SUBSYSTEM */
+
+/** Create an adapter object and initialise it based on resource information
+ * passed in in the message
+ * *** NOTE - you cannot use this function AND the FindAdapters function at the
+ * same time, the application must use only one of them to get the adapters ***
+ */
+static void subsys_create_adapter(struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+       /* create temp adapter obj, because we don't know what index yet */
+       struct hpi_adapter_obj ao;
+       u32 os_error_code;
+       u16 err;
+
+       HPI_DEBUG_LOG(DEBUG, " subsys_create_adapter\n");
+
+       memset(&ao, 0, sizeof(ao));
+
+       /* this HPI only creates adapters for TI/PCI devices */
+       if (phm->u.s.resource.bus_type != HPI_BUS_PCI)
+               return;
+       if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI)
+               return;
+       if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_DSP6205)
+               return;
+
+       ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
+       if (!ao.priv) {
+               HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
+               phr->error = HPI_ERROR_MEMORY_ALLOC;
+               return;
+       }
+
+       ao.pci = *phm->u.s.resource.r.pci;
+       err = create_adapter_obj(&ao, &os_error_code);
+       if (!err)
+               err = hpi_add_adapter(&ao);
+       if (err) {
+               phr->u.s.data = os_error_code;
+               delete_adapter_obj(&ao);
+               phr->error = err;
+               return;
+       }
+
+       phr->u.s.aw_adapter_list[ao.index] = ao.adapter_type;
+       phr->u.s.adapter_index = ao.index;
+       phr->u.s.num_adapters++;
+       phr->error = 0;
+}
+
+/** delete an adapter - required by WDM driver */
+static void subsys_delete_adapter(struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+       struct hpi_adapter_obj *pao;
+       struct hpi_hw_obj *phw;
+
+       pao = hpi_find_adapter(phm->adapter_index);
+       if (!pao) {
+               phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
+               return;
+       }
+       phw = (struct hpi_hw_obj *)pao->priv;
+       /* reset adapter h/w */
+       /* Reset C6713 #1 */
+       boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
+       /* reset C6205 */
+       iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
+
+       delete_adapter_obj(pao);
+       phr->error = 0;
+}
+
+/** Create adapter object
+  allocate buffers, bootload DSPs, initialise control cache
+*/
+static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface;
+       u32 phys_addr;
+#ifndef HPI6205_NO_HSR_POLL
+       u32 time_out = HPI6205_TIMEOUT;
+       u32 temp1;
+#endif
+       int i;
+       u16 err;
+
+       /* init error reporting */
+       pao->dsp_crashed = 0;
+
+       for (i = 0; i < HPI_MAX_STREAMS; i++)
+               phw->flag_outstream_just_reset[i] = 1;
+
+       /* The C6205 memory area 1 is 8Mbyte window into DSP registers */
+       phw->prHSR =
+               pao->pci.ap_mem_base[1] +
+               C6205_BAR1_HSR / sizeof(*pao->pci.ap_mem_base[1]);
+       phw->prHDCR =
+               pao->pci.ap_mem_base[1] +
+               C6205_BAR1_HDCR / sizeof(*pao->pci.ap_mem_base[1]);
+       phw->prDSPP =
+               pao->pci.ap_mem_base[1] +
+               C6205_BAR1_DSPP / sizeof(*pao->pci.ap_mem_base[1]);
+
+       pao->has_control_cache = 0;
+
+       if (hpios_locked_mem_alloc(&phw->h_locked_mem,
+                       sizeof(struct bus_master_interface),
+                       pao->pci.p_os_data))
+               phw->p_interface_buffer = NULL;
+       else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
+                       (void *)&phw->p_interface_buffer))
+               phw->p_interface_buffer = NULL;
+
+       HPI_DEBUG_LOG(DEBUG, "interface buffer address %p\n",
+               phw->p_interface_buffer);
+
+       if (phw->p_interface_buffer) {
+               memset((void *)phw->p_interface_buffer, 0,
+                       sizeof(struct bus_master_interface));
+               phw->p_interface_buffer->dsp_ack = H620_HIF_UNKNOWN;
+       }
+
+       err = adapter_boot_load_dsp(pao, pos_error_code);
+       if (err)
+               /* no need to clean up as SubSysCreateAdapter */
+               /* calls DeleteAdapter on error. */
+               return err;
+
+       HPI_DEBUG_LOG(INFO, "load DSP code OK\n");
+
+       /* allow boot load even if mem alloc wont work */
+       if (!phw->p_interface_buffer)
+               return hpi6205_error(0, HPI_ERROR_MEMORY_ALLOC);
+
+       interface = phw->p_interface_buffer;
+
+#ifndef HPI6205_NO_HSR_POLL
+       /* wait for first interrupt indicating the DSP init is done */
+       time_out = HPI6205_TIMEOUT * 10;
+       temp1 = 0;
+       while (((temp1 & C6205_HSR_INTSRC) == 0) && --time_out)
+               temp1 = ioread32(phw->prHSR);
+
+       if (temp1 & C6205_HSR_INTSRC)
+               HPI_DEBUG_LOG(INFO,
+                       "interrupt confirming DSP code running OK\n");
+       else {
+               HPI_DEBUG_LOG(ERROR,
+                       "timed out waiting for interrupt "
+                       "confirming DSP code running\n");
+               return hpi6205_error(0, HPI6205_ERROR_6205_NO_IRQ);
+       }
+
+       /* reset the interrupt */
+       iowrite32(C6205_HSR_INTSRC, phw->prHSR);
+#endif
+
+       /* make sure the DSP has started ok */
+       if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
+               HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
+               return hpi6205_error(0, HPI6205_ERROR_6205_INIT_FAILED);
+       }
+       /* Note that *pao, *phw are zeroed after allocation,
+        * so pointers and flags are NULL by default.
+        * Allocate bus mastering control cache buffer and tell the DSP about it
+        */
+       if (interface->control_cache.number_of_controls) {
+               void *p_control_cache_virtual;
+
+               err = hpios_locked_mem_alloc(&phw->h_control_cache,
+                       interface->control_cache.size_in_bytes,
+                       pao->pci.p_os_data);
+               if (!err)
+                       err = hpios_locked_mem_get_virt_addr(&phw->
+                               h_control_cache, &p_control_cache_virtual);
+               if (!err) {
+                       memset(p_control_cache_virtual, 0,
+                               interface->control_cache.size_in_bytes);
+
+                       phw->p_cache =
+                               hpi_alloc_control_cache(interface->
+                               control_cache.number_of_controls,
+                               interface->control_cache.size_in_bytes,
+                               (struct hpi_control_cache_info *)
+                               p_control_cache_virtual);
+               }
+               if (!err) {
+                       err = hpios_locked_mem_get_phys_addr(&phw->
+                               h_control_cache, &phys_addr);
+                       interface->control_cache.physical_address32 =
+                               phys_addr;
+               }
+
+               if (!err)
+                       pao->has_control_cache = 1;
+               else {
+                       if (hpios_locked_mem_valid(&phw->h_control_cache))
+                               hpios_locked_mem_free(&phw->h_control_cache);
+                       pao->has_control_cache = 0;
+               }
+       }
+       /* allocate bus mastering async buffer and tell the DSP about it */
+       if (interface->async_buffer.b.size) {
+               err = hpios_locked_mem_alloc(&phw->h_async_event_buffer,
+                       interface->async_buffer.b.size *
+                       sizeof(struct hpi_async_event), pao->pci.p_os_data);
+               if (!err)
+                       err = hpios_locked_mem_get_virt_addr
+                               (&phw->h_async_event_buffer, (void *)
+                               &phw->p_async_event_buffer);
+               if (!err)
+                       memset((void *)phw->p_async_event_buffer, 0,
+                               interface->async_buffer.b.size *
+                               sizeof(struct hpi_async_event));
+               if (!err) {
+                       err = hpios_locked_mem_get_phys_addr
+                               (&phw->h_async_event_buffer, &phys_addr);
+                       interface->async_buffer.physical_address32 =
+                               phys_addr;
+               }
+               if (err) {
+                       if (hpios_locked_mem_valid(&phw->
+                                       h_async_event_buffer)) {
+                               hpios_locked_mem_free
+                                       (&phw->h_async_event_buffer);
+                               phw->p_async_event_buffer = NULL;
+                       }
+               }
+       }
+       send_dsp_command(phw, H620_HIF_IDLE);
+
+       {
+               struct hpi_message hM;
+               struct hpi_response hR;
+               u32 max_streams;
+
+               HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
+               memset(&hM, 0, sizeof(hM));
+               hM.type = HPI_TYPE_MESSAGE;
+               hM.size = sizeof(hM);
+               hM.object = HPI_OBJ_ADAPTER;
+               hM.function = HPI_ADAPTER_GET_INFO;
+               hM.adapter_index = 0;
+               memset(&hR, 0, sizeof(hR));
+               hR.size = sizeof(hR);
+
+               err = message_response_sequence(pao, &hM, &hR);
+               if (err) {
+                       HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
+                               err);
+                       return err;
+               }
+               if (hR.error)
+                       return hR.error;
+
+               pao->adapter_type = hR.u.a.adapter_type;
+               pao->index = hR.u.a.adapter_index;
+
+               max_streams = hR.u.a.num_outstreams + hR.u.a.num_instreams;
+
+               hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams,
+                       65536, pao->pci.p_os_data);
+
+               HPI_DEBUG_LOG(VERBOSE,
+                       "got adapter info type %x index %d serial %d\n",
+                       hR.u.a.adapter_type, hR.u.a.adapter_index,
+                       hR.u.a.serial_number);
+       }
+
+       pao->open = 0;  /* upon creation the adapter is closed */
+
+       HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
+       return 0;
+}
+
+/** Free memory areas allocated by adapter
+ * this routine is called from SubSysDeleteAdapter,
+  * and SubSysCreateAdapter if duplicate index
+*/
+static void delete_adapter_obj(struct hpi_adapter_obj *pao)
+{
+       struct hpi_hw_obj *phw;
+       int i;
+
+       phw = pao->priv;
+
+       if (hpios_locked_mem_valid(&phw->h_async_event_buffer)) {
+               hpios_locked_mem_free(&phw->h_async_event_buffer);
+               phw->p_async_event_buffer = NULL;
+       }
+
+       if (hpios_locked_mem_valid(&phw->h_control_cache)) {
+               hpios_locked_mem_free(&phw->h_control_cache);
+               hpi_free_control_cache(phw->p_cache);
+       }
+
+       if (hpios_locked_mem_valid(&phw->h_locked_mem)) {
+               hpios_locked_mem_free(&phw->h_locked_mem);
+               phw->p_interface_buffer = NULL;
+       }
+
+       for (i = 0; i < HPI_MAX_STREAMS; i++)
+               if (hpios_locked_mem_valid(&phw->instream_host_buffers[i])) {
+                       hpios_locked_mem_free(&phw->instream_host_buffers[i]);
+                       /*?phw->InStreamHostBuffers[i] = NULL; */
+                       phw->instream_host_buffer_size[i] = 0;
+               }
+
+       for (i = 0; i < HPI_MAX_STREAMS; i++)
+               if (hpios_locked_mem_valid(&phw->outstream_host_buffers[i])) {
+                       hpios_locked_mem_free(&phw->outstream_host_buffers
+                               [i]);
+                       phw->outstream_host_buffer_size[i] = 0;
+               }
+
+       hpios_locked_mem_unprepare(pao->pci.p_os_data);
+
+       hpi_delete_adapter(pao);
+       kfree(phw);
+}
+
+/*****************************************************************************/
+/* OutStream Host buffer functions */
+
+/** Allocate or attach buffer for busmastering
+*/
+static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       u16 err = 0;
+       u32 command = phm->u.d.u.buffer.command;
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+
+       hpi_init_response(phr, phm->object, phm->function, 0);
+
+       if (command == HPI_BUFFER_CMD_EXTERNAL
+               || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
+               /* ALLOC phase, allocate a buffer with power of 2 size,
+                  get its bus address for PCI bus mastering
+                */
+               phm->u.d.u.buffer.buffer_size =
+                       roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
+               /* return old size and allocated size,
+                  so caller can detect change */
+               phr->u.d.u.stream_info.data_available =
+                       phw->outstream_host_buffer_size[phm->obj_index];
+               phr->u.d.u.stream_info.buffer_size =
+                       phm->u.d.u.buffer.buffer_size;
+
+               if (phw->outstream_host_buffer_size[phm->obj_index] ==
+                       phm->u.d.u.buffer.buffer_size) {
+                       /* Same size, no action required */
+                       return;
+               }
+
+               if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
+                                       obj_index]))
+                       hpios_locked_mem_free(&phw->outstream_host_buffers
+                               [phm->obj_index]);
+
+               err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
+                       [phm->obj_index], phm->u.d.u.buffer.buffer_size,
+                       pao->pci.p_os_data);
+
+               if (err) {
+                       phr->error = HPI_ERROR_INVALID_DATASIZE;
+                       phw->outstream_host_buffer_size[phm->obj_index] = 0;
+                       return;
+               }
+
+               err = hpios_locked_mem_get_phys_addr
+                       (&phw->outstream_host_buffers[phm->obj_index],
+                       &phm->u.d.u.buffer.pci_address);
+               /* get the phys addr into msg for single call alloc caller
+                * needs to do this for split alloc (or use the same message)
+                * return the phy address for split alloc in the respose too
+                */
+               phr->u.d.u.stream_info.auxiliary_data_available =
+                       phm->u.d.u.buffer.pci_address;
+
+               if (err) {
+                       hpios_locked_mem_free(&phw->outstream_host_buffers
+                               [phm->obj_index]);
+                       phw->outstream_host_buffer_size[phm->obj_index] = 0;
+                       phr->error = HPI_ERROR_MEMORY_ALLOC;
+                       return;
+               }
+       }
+
+       if (command == HPI_BUFFER_CMD_EXTERNAL
+               || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
+               /* GRANT phase.  Set up the BBM status, tell the DSP about
+                  the buffer so it can start using BBM.
+                */
+               struct hpi_hostbuffer_status *status;
+
+               if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
+                               buffer_size - 1)) {
+                       HPI_DEBUG_LOG(ERROR,
+                               "buffer size must be 2^N not %d\n",
+                               phm->u.d.u.buffer.buffer_size);
+                       phr->error = HPI_ERROR_INVALID_DATASIZE;
+                       return;
+               }
+               phw->outstream_host_buffer_size[phm->obj_index] =
+                       phm->u.d.u.buffer.buffer_size;
+               status = &interface->outstream_host_buffer_status[phm->
+                       obj_index];
+               status->samples_processed = 0;
+               status->stream_state = HPI_STATE_STOPPED;
+               status->dSP_index = 0;
+               status->host_index = status->dSP_index;
+               status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
+
+               hw_message(pao, phm, phr);
+
+               if (phr->error
+                       && hpios_locked_mem_valid(&phw->
+                               outstream_host_buffers[phm->obj_index])) {
+                       hpios_locked_mem_free(&phw->outstream_host_buffers
+                               [phm->obj_index]);
+                       phw->outstream_host_buffer_size[phm->obj_index] = 0;
+               }
+       }
+}
+
+static void outstream_host_buffer_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+       u8 *p_bbm_data;
+
+       if (hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
+                               obj_index])) {
+               if (hpios_locked_mem_get_virt_addr(&phw->
+                               outstream_host_buffers[phm->obj_index],
+                               (void *)&p_bbm_data)) {
+                       phr->error = HPI_ERROR_INVALID_OPERATION;
+                       return;
+               }
+               status = &interface->outstream_host_buffer_status[phm->
+                       obj_index];
+               hpi_init_response(phr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_HOSTBUFFER_GET_INFO, 0);
+               phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
+               phr->u.d.u.hostbuffer_info.p_status = status;
+       } else {
+               hpi_init_response(phr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_HOSTBUFFER_GET_INFO,
+                       HPI_ERROR_INVALID_OPERATION);
+       }
+}
+
+static void outstream_host_buffer_free(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       u32 command = phm->u.d.u.buffer.command;
+
+       if (phw->outstream_host_buffer_size[phm->obj_index]) {
+               if (command == HPI_BUFFER_CMD_EXTERNAL
+                       || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
+                       phw->outstream_host_buffer_size[phm->obj_index] = 0;
+                       hw_message(pao, phm, phr);
+                       /* Tell adapter to stop using the host buffer. */
+               }
+               if (command == HPI_BUFFER_CMD_EXTERNAL
+                       || command == HPI_BUFFER_CMD_INTERNAL_FREE)
+                       hpios_locked_mem_free(&phw->outstream_host_buffers
+                               [phm->obj_index]);
+       }
+       /* Should HPI_ERROR_INVALID_OPERATION be returned
+          if no host buffer is allocated? */
+       else
+               hpi_init_response(phr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_HOSTBUFFER_FREE, 0);
+
+}
+
+static long outstream_get_space_available(struct hpi_hostbuffer_status
+       *status)
+{
+       return status->size_in_bytes - ((long)(status->host_index) -
+               (long)(status->dSP_index));
+}
+
+static void outstream_write(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+       long space_available;
+
+       if (!phw->outstream_host_buffer_size[phm->obj_index]) {
+               /* there  is no BBM buffer, write via message */
+               hw_message(pao, phm, phr);
+               return;
+       }
+
+       hpi_init_response(phr, phm->object, phm->function, 0);
+       status = &interface->outstream_host_buffer_status[phm->obj_index];
+
+       if (phw->flag_outstream_just_reset[phm->obj_index]) {
+               /* Format can only change after reset. Must tell DSP. */
+               u16 function = phm->function;
+               phw->flag_outstream_just_reset[phm->obj_index] = 0;
+               phm->function = HPI_OSTREAM_SET_FORMAT;
+               hw_message(pao, phm, phr);      /* send the format to the DSP */
+               phm->function = function;
+               if (phr->error)
+                       return;
+       }
+#if 1
+       if (phw->flag_outstream_just_reset[phm->obj_index]) {
+               /* First OutStremWrite() call following reset will write data to the
+                  adapter's buffers, reducing delay before stream can start
+                */
+               int partial_write = 0;
+               unsigned int original_size = 0;
+
+               /* Send the first buffer to the DSP the old way. */
+               /* Limit size of first transfer - */
+               /* expect that this will not usually be triggered. */
+               if (phm->u.d.u.data.data_size > HPI6205_SIZEOF_DATA) {
+                       partial_write = 1;
+                       original_size = phm->u.d.u.data.data_size;
+                       phm->u.d.u.data.data_size = HPI6205_SIZEOF_DATA;
+               }
+               /* write it */
+               phm->function = HPI_OSTREAM_WRITE;
+               hw_message(pao, phm, phr);
+               /* update status information that the DSP would typically
+                * update (and will update next time the DSP
+                * buffer update task reads data from the host BBM buffer)
+                */
+               status->auxiliary_data_available = phm->u.d.u.data.data_size;
+               status->host_index += phm->u.d.u.data.data_size;
+               status->dSP_index += phm->u.d.u.data.data_size;
+
+               /* if we did a full write, we can return from here. */
+               if (!partial_write)
+                       return;
+
+               /* tweak buffer parameters and let the rest of the */
+               /* buffer land in internal BBM buffer */
+               phm->u.d.u.data.data_size =
+                       original_size - HPI6205_SIZEOF_DATA;
+               phm->u.d.u.data.pb_data += HPI6205_SIZEOF_DATA;
+       }
+#endif
+
+       space_available = outstream_get_space_available(status);
+       if (space_available < (long)phm->u.d.u.data.data_size) {
+               phr->error = HPI_ERROR_INVALID_DATASIZE;
+               return;
+       }
+
+       /* HostBuffers is used to indicate host buffer is internally allocated.
+          otherwise, assumed external, data written externally */
+       if (phm->u.d.u.data.pb_data
+               && hpios_locked_mem_valid(&phw->outstream_host_buffers[phm->
+                               obj_index])) {
+               u8 *p_bbm_data;
+               long l_first_write;
+               u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
+
+               if (hpios_locked_mem_get_virt_addr(&phw->
+                               outstream_host_buffers[phm->obj_index],
+                               (void *)&p_bbm_data)) {
+                       phr->error = HPI_ERROR_INVALID_OPERATION;
+                       return;
+               }
+
+               /* either all data,
+                  or enough to fit from current to end of BBM buffer */
+               l_first_write =
+                       min(phm->u.d.u.data.data_size,
+                       status->size_in_bytes -
+                       (status->host_index & (status->size_in_bytes - 1)));
+
+               memcpy(p_bbm_data +
+                       (status->host_index & (status->size_in_bytes - 1)),
+                       p_app_data, l_first_write);
+               /* remaining data if any */
+               memcpy(p_bbm_data, p_app_data + l_first_write,
+                       phm->u.d.u.data.data_size - l_first_write);
+       }
+       status->host_index += phm->u.d.u.data.data_size;
+}
+
+static void outstream_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+
+       if (!phw->outstream_host_buffer_size[phm->obj_index]) {
+               hw_message(pao, phm, phr);
+               return;
+       }
+
+       hpi_init_response(phr, phm->object, phm->function, 0);
+
+       status = &interface->outstream_host_buffer_status[phm->obj_index];
+
+       phr->u.d.u.stream_info.state = (u16)status->stream_state;
+       phr->u.d.u.stream_info.samples_transferred =
+               status->samples_processed;
+       phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
+       phr->u.d.u.stream_info.data_available =
+               status->size_in_bytes - outstream_get_space_available(status);
+       phr->u.d.u.stream_info.auxiliary_data_available =
+               status->auxiliary_data_available;
+}
+
+static void outstream_start(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       hw_message(pao, phm, phr);
+}
+
+static void outstream_reset(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       phw->flag_outstream_just_reset[phm->obj_index] = 1;
+       hw_message(pao, phm, phr);
+}
+
+static void outstream_open(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       outstream_reset(pao, phm, phr);
+}
+
+/*****************************************************************************/
+/* InStream Host buffer functions */
+
+static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       u16 err = 0;
+       u32 command = phm->u.d.u.buffer.command;
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+
+       hpi_init_response(phr, phm->object, phm->function, 0);
+
+       if (command == HPI_BUFFER_CMD_EXTERNAL
+               || command == HPI_BUFFER_CMD_INTERNAL_ALLOC) {
+
+               phm->u.d.u.buffer.buffer_size =
+                       roundup_pow_of_two(phm->u.d.u.buffer.buffer_size);
+               phr->u.d.u.stream_info.data_available =
+                       phw->instream_host_buffer_size[phm->obj_index];
+               phr->u.d.u.stream_info.buffer_size =
+                       phm->u.d.u.buffer.buffer_size;
+
+               if (phw->instream_host_buffer_size[phm->obj_index] ==
+                       phm->u.d.u.buffer.buffer_size) {
+                       /* Same size, no action required */
+                       return;
+               }
+
+               if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
+                                       obj_index]))
+                       hpios_locked_mem_free(&phw->instream_host_buffers
+                               [phm->obj_index]);
+
+               err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
+                               obj_index], phm->u.d.u.buffer.buffer_size,
+                       pao->pci.p_os_data);
+
+               if (err) {
+                       phr->error = HPI_ERROR_INVALID_DATASIZE;
+                       phw->instream_host_buffer_size[phm->obj_index] = 0;
+                       return;
+               }
+
+               err = hpios_locked_mem_get_phys_addr
+                       (&phw->instream_host_buffers[phm->obj_index],
+                       &phm->u.d.u.buffer.pci_address);
+               /* get the phys addr into msg for single call alloc. Caller
+                  needs to do this for split alloc so return the phy address */
+               phr->u.d.u.stream_info.auxiliary_data_available =
+                       phm->u.d.u.buffer.pci_address;
+               if (err) {
+                       hpios_locked_mem_free(&phw->instream_host_buffers
+                               [phm->obj_index]);
+                       phw->instream_host_buffer_size[phm->obj_index] = 0;
+                       phr->error = HPI_ERROR_MEMORY_ALLOC;
+                       return;
+               }
+       }
+
+       if (command == HPI_BUFFER_CMD_EXTERNAL
+               || command == HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER) {
+               struct hpi_hostbuffer_status *status;
+
+               if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
+                               buffer_size - 1)) {
+                       HPI_DEBUG_LOG(ERROR,
+                               "buffer size must be 2^N not %d\n",
+                               phm->u.d.u.buffer.buffer_size);
+                       phr->error = HPI_ERROR_INVALID_DATASIZE;
+                       return;
+               }
+
+               phw->instream_host_buffer_size[phm->obj_index] =
+                       phm->u.d.u.buffer.buffer_size;
+               status = &interface->instream_host_buffer_status[phm->
+                       obj_index];
+               status->samples_processed = 0;
+               status->stream_state = HPI_STATE_STOPPED;
+               status->dSP_index = 0;
+               status->host_index = status->dSP_index;
+               status->size_in_bytes = phm->u.d.u.buffer.buffer_size;
+
+               hw_message(pao, phm, phr);
+               if (phr->error
+                       && hpios_locked_mem_valid(&phw->
+                               instream_host_buffers[phm->obj_index])) {
+                       hpios_locked_mem_free(&phw->instream_host_buffers
+                               [phm->obj_index]);
+                       phw->instream_host_buffer_size[phm->obj_index] = 0;
+               }
+       }
+}
+
+static void instream_host_buffer_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+       u8 *p_bbm_data;
+
+       if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
+                               obj_index])) {
+               if (hpios_locked_mem_get_virt_addr(&phw->
+                               instream_host_buffers[phm->obj_index],
+                               (void *)&p_bbm_data)) {
+                       phr->error = HPI_ERROR_INVALID_OPERATION;
+                       return;
+               }
+               status = &interface->instream_host_buffer_status[phm->
+                       obj_index];
+               hpi_init_response(phr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_HOSTBUFFER_GET_INFO, 0);
+               phr->u.d.u.hostbuffer_info.p_buffer = p_bbm_data;
+               phr->u.d.u.hostbuffer_info.p_status = status;
+       } else {
+               hpi_init_response(phr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_HOSTBUFFER_GET_INFO,
+                       HPI_ERROR_INVALID_OPERATION);
+       }
+}
+
+static void instream_host_buffer_free(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       u32 command = phm->u.d.u.buffer.command;
+
+       if (phw->instream_host_buffer_size[phm->obj_index]) {
+               if (command == HPI_BUFFER_CMD_EXTERNAL
+                       || command == HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER) {
+                       phw->instream_host_buffer_size[phm->obj_index] = 0;
+                       hw_message(pao, phm, phr);
+               }
+
+               if (command == HPI_BUFFER_CMD_EXTERNAL
+                       || command == HPI_BUFFER_CMD_INTERNAL_FREE)
+                       hpios_locked_mem_free(&phw->instream_host_buffers
+                               [phm->obj_index]);
+
+       } else {
+               /* Should HPI_ERROR_INVALID_OPERATION be returned
+                  if no host buffer is allocated? */
+               hpi_init_response(phr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_HOSTBUFFER_FREE, 0);
+
+       }
+
+}
+
+static void instream_start(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       hw_message(pao, phm, phr);
+}
+
+static long instream_get_bytes_available(struct hpi_hostbuffer_status *status)
+{
+       return (long)(status->dSP_index) - (long)(status->host_index);
+}
+
+static void instream_read(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+       long data_available;
+       u8 *p_bbm_data;
+       long l_first_read;
+       u8 *p_app_data = (u8 *)phm->u.d.u.data.pb_data;
+
+       if (!phw->instream_host_buffer_size[phm->obj_index]) {
+               hw_message(pao, phm, phr);
+               return;
+       }
+       hpi_init_response(phr, phm->object, phm->function, 0);
+
+       status = &interface->instream_host_buffer_status[phm->obj_index];
+       data_available = instream_get_bytes_available(status);
+       if (data_available < (long)phm->u.d.u.data.data_size) {
+               phr->error = HPI_ERROR_INVALID_DATASIZE;
+               return;
+       }
+
+       if (hpios_locked_mem_valid(&phw->instream_host_buffers[phm->
+                               obj_index])) {
+               if (hpios_locked_mem_get_virt_addr(&phw->
+                               instream_host_buffers[phm->obj_index],
+                               (void *)&p_bbm_data)) {
+                       phr->error = HPI_ERROR_INVALID_OPERATION;
+                       return;
+               }
+
+               /* either all data,
+                  or enough to fit from current to end of BBM buffer */
+               l_first_read =
+                       min(phm->u.d.u.data.data_size,
+                       status->size_in_bytes -
+                       (status->host_index & (status->size_in_bytes - 1)));
+
+               memcpy(p_app_data,
+                       p_bbm_data +
+                       (status->host_index & (status->size_in_bytes - 1)),
+                       l_first_read);
+               /* remaining data if any */
+               memcpy(p_app_data + l_first_read, p_bbm_data,
+                       phm->u.d.u.data.data_size - l_first_read);
+       }
+       status->host_index += phm->u.d.u.data.data_size;
+}
+
+static void instream_get_info(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       struct hpi_hostbuffer_status *status;
+       if (!phw->instream_host_buffer_size[phm->obj_index]) {
+               hw_message(pao, phm, phr);
+               return;
+       }
+
+       status = &interface->instream_host_buffer_status[phm->obj_index];
+
+       hpi_init_response(phr, phm->object, phm->function, 0);
+
+       phr->u.d.u.stream_info.state = (u16)status->stream_state;
+       phr->u.d.u.stream_info.samples_transferred =
+               status->samples_processed;
+       phr->u.d.u.stream_info.buffer_size = status->size_in_bytes;
+       phr->u.d.u.stream_info.data_available =
+               instream_get_bytes_available(status);
+       phr->u.d.u.stream_info.auxiliary_data_available =
+               status->auxiliary_data_available;
+}
+
+/*****************************************************************************/
+/* LOW-LEVEL */
+#define HPI6205_MAX_FILES_TO_LOAD 2
+
+static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
+       u32 *pos_error_code)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       struct dsp_code dsp_code;
+       u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
+       u16 firmware_id = pao->pci.subsys_device_id;
+       u32 temp;
+       int dsp = 0, i = 0;
+       u16 err = 0;
+
+       boot_code_id[0] = HPI_ADAPTER_ASI(0x6205);
+
+       /* special cases where firmware_id != subsys ID */
+       switch (firmware_id) {
+       case HPI_ADAPTER_FAMILY_ASI(0x5000):
+               boot_code_id[0] = firmware_id;
+               firmware_id = 0;
+               break;
+       case HPI_ADAPTER_FAMILY_ASI(0x5300):
+       case HPI_ADAPTER_FAMILY_ASI(0x5400):
+       case HPI_ADAPTER_FAMILY_ASI(0x6300):
+               firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6400);
+               break;
+       case HPI_ADAPTER_FAMILY_ASI(0x5600):
+       case HPI_ADAPTER_FAMILY_ASI(0x6500):
+               firmware_id = HPI_ADAPTER_FAMILY_ASI(0x6600);
+               break;
+       }
+       boot_code_id[1] = firmware_id;
+
+       /* reset DSP by writing a 1 to the WARMRESET bit */
+       temp = C6205_HDCR_WARMRESET;
+       iowrite32(temp, phw->prHDCR);
+       hpios_delay_micro_seconds(1000);
+
+       /* check that PCI i/f was configured by EEPROM */
+       temp = ioread32(phw->prHSR);
+       if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
+               C6205_HSR_EEREAD)
+               return hpi6205_error(0, HPI6205_ERROR_6205_EEPROM);
+       temp |= 0x04;
+       /* disable PINTA interrupt */
+       iowrite32(temp, phw->prHSR);
+
+       /* check control register reports PCI boot mode */
+       temp = ioread32(phw->prHDCR);
+       if (!(temp & C6205_HDCR_PCIBOOT))
+               return hpi6205_error(0, HPI6205_ERROR_6205_REG);
+
+       /* try writing a couple of numbers to the DSP page register */
+       /* and reading them back. */
+       temp = 1;
+       iowrite32(temp, phw->prDSPP);
+       if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
+               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+       temp = 2;
+       iowrite32(temp, phw->prDSPP);
+       if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
+               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+       temp = 3;
+       iowrite32(temp, phw->prDSPP);
+       if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
+               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+       /* reset DSP page to the correct number */
+       temp = 0;
+       iowrite32(temp, phw->prDSPP);
+       if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
+               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+       phw->dsp_page = 0;
+
+       /* release 6713 from reset before 6205 is bootloaded.
+          This ensures that the EMIF is inactive,
+          and the 6713 HPI gets the correct bootmode etc
+        */
+       if (boot_code_id[1] != 0) {
+               /* DSP 1 is a C6713 */
+               /* CLKX0 <- '1' release the C6205 bootmode pulldowns */
+               boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002202);
+               hpios_delay_micro_seconds(100);
+               /* Reset the 6713 #1 - revB */
+               boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 0);
+
+               /* dummy read every 4 words for 6205 advisory 1.4.4 */
+               boot_loader_read_mem32(pao, 0, 0);
+
+               hpios_delay_micro_seconds(100);
+               /* Release C6713 from reset - revB */
+               boot_loader_write_mem32(pao, 0, C6205_BAR0_TIMER1_CTL, 4);
+               hpios_delay_micro_seconds(100);
+       }
+
+       for (dsp = 0; dsp < HPI6205_MAX_FILES_TO_LOAD; dsp++) {
+               /* is there a DSP to load? */
+               if (boot_code_id[dsp] == 0)
+                       continue;
+
+               err = boot_loader_config_emif(pao, dsp);
+               if (err)
+                       return err;
+
+               err = boot_loader_test_internal_memory(pao, dsp);
+               if (err)
+                       return err;
+
+               err = boot_loader_test_external_memory(pao, dsp);
+               if (err)
+                       return err;
+
+               err = boot_loader_test_pld(pao, dsp);
+               if (err)
+                       return err;
+
+               /* write the DSP code down into the DSPs memory */
+               dsp_code.ps_dev = pao->pci.p_os_data;
+               err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
+                       pos_error_code);
+               if (err)
+                       return err;
+
+               while (1) {
+                       u32 length;
+                       u32 address;
+                       u32 type;
+                       u32 *pcode;
+
+                       err = hpi_dsp_code_read_word(&dsp_code, &length);
+                       if (err)
+                               break;
+                       if (length == 0xFFFFFFFF)
+                               break;  /* end of code */
+
+                       err = hpi_dsp_code_read_word(&dsp_code, &address);
+                       if (err)
+                               break;
+                       err = hpi_dsp_code_read_word(&dsp_code, &type);
+                       if (err)
+                               break;
+                       err = hpi_dsp_code_read_block(length, &dsp_code,
+                               &pcode);
+                       if (err)
+                               break;
+                       for (i = 0; i < (int)length; i++) {
+                               err = boot_loader_write_mem32(pao, dsp,
+                                       address, *pcode);
+                               if (err)
+                                       break;
+                               /* dummy read every 4 words */
+                               /* for 6205 advisory 1.4.4 */
+                               if (i % 4 == 0)
+                                       boot_loader_read_mem32(pao, dsp,
+                                               address);
+                               pcode++;
+                               address += 4;
+                       }
+
+               }
+               if (err) {
+                       hpi_dsp_code_close(&dsp_code);
+                       return err;
+               }
+
+               /* verify code */
+               hpi_dsp_code_rewind(&dsp_code);
+               while (1) {
+                       u32 length = 0;
+                       u32 address = 0;
+                       u32 type = 0;
+                       u32 *pcode = NULL;
+                       u32 data = 0;
+
+                       hpi_dsp_code_read_word(&dsp_code, &length);
+                       if (length == 0xFFFFFFFF)
+                               break;  /* end of code */
+
+                       hpi_dsp_code_read_word(&dsp_code, &address);
+                       hpi_dsp_code_read_word(&dsp_code, &type);
+                       hpi_dsp_code_read_block(length, &dsp_code, &pcode);
+
+                       for (i = 0; i < (int)length; i++) {
+                               data = boot_loader_read_mem32(pao, dsp,
+                                       address);
+                               if (data != *pcode) {
+                                       err = 0;
+                                       break;
+                               }
+                               pcode++;
+                               address += 4;
+                       }
+                       if (err)
+                               break;
+               }
+               hpi_dsp_code_close(&dsp_code);
+               if (err)
+                       return err;
+       }
+
+       /* After bootloading all DSPs, start DSP0 running
+        * The DSP0 code will handle starting and synchronizing with its slaves
+        */
+       if (phw->p_interface_buffer) {
+               /* we need to tell the card the physical PCI address */
+               u32 physicalPC_iaddress;
+               struct bus_master_interface *interface =
+                       phw->p_interface_buffer;
+               u32 host_mailbox_address_on_dsp;
+               u32 physicalPC_iaddress_verify = 0;
+               int time_out = 10;
+               /* set ack so we know when DSP is ready to go */
+               /* (dwDspAck will be changed to HIF_RESET) */
+               interface->dsp_ack = H620_HIF_UNKNOWN;
+               wmb();  /* ensure ack is written before dsp writes back */
+
+               err = hpios_locked_mem_get_phys_addr(&phw->h_locked_mem,
+                       &physicalPC_iaddress);
+
+               /* locate the host mailbox on the DSP. */
+               host_mailbox_address_on_dsp = 0x80000000;
+               while ((physicalPC_iaddress != physicalPC_iaddress_verify)
+                       && time_out--) {
+                       err = boot_loader_write_mem32(pao, 0,
+                               host_mailbox_address_on_dsp,
+                               physicalPC_iaddress);
+                       physicalPC_iaddress_verify =
+                               boot_loader_read_mem32(pao, 0,
+                               host_mailbox_address_on_dsp);
+               }
+       }
+       HPI_DEBUG_LOG(DEBUG, "starting DS_ps running\n");
+       /* enable interrupts */
+       temp = ioread32(phw->prHSR);
+       temp &= ~(u32)C6205_HSR_INTAM;
+       iowrite32(temp, phw->prHSR);
+
+       /* start code running... */
+       temp = ioread32(phw->prHDCR);
+       temp |= (u32)C6205_HDCR_DSPINT;
+       iowrite32(temp, phw->prHDCR);
+
+       /* give the DSP 10ms to start up */
+       hpios_delay_micro_seconds(10000);
+       return err;
+
+}
+
+/*****************************************************************************/
+/* Bootloader utility functions */
+
+static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 address)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       u32 data = 0;
+       __iomem u32 *p_data;
+
+       if (dsp_index == 0) {
+               /* DSP 0 is always C6205 */
+               if ((address >= 0x01800000) & (address < 0x02000000)) {
+                       /* BAR1 register access */
+                       p_data = pao->pci.ap_mem_base[1] +
+                               (address & 0x007fffff) /
+                               sizeof(*pao->pci.ap_mem_base[1]);
+                       /* HPI_DEBUG_LOG(WARNING,
+                          "BAR1 access %08x\n", dwAddress); */
+               } else {
+                       u32 dw4M_page = address >> 22L;
+                       if (dw4M_page != phw->dsp_page) {
+                               phw->dsp_page = dw4M_page;
+                               /* *INDENT OFF* */
+                               iowrite32(phw->dsp_page, phw->prDSPP);
+                               /* *INDENT-ON* */
+                       }
+                       address &= 0x3fffff;    /* address within 4M page */
+                       /* BAR0 memory access */
+                       p_data = pao->pci.ap_mem_base[0] +
+                               address / sizeof(u32);
+               }
+               data = ioread32(p_data);
+       } else if (dsp_index == 1) {
+               /* DSP 1 is a C6713 */
+               u32 lsb;
+               boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
+               boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
+               lsb = boot_loader_read_mem32(pao, 0, HPIDL_ADDR);
+               data = boot_loader_read_mem32(pao, 0, HPIDH_ADDR);
+               data = (data << 16) | (lsb & 0xFFFF);
+       }
+       return data;
+}
+
+static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 address, u32 data)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       u16 err = 0;
+       __iomem u32 *p_data;
+       /*      u32 dwVerifyData=0; */
+
+       if (dsp_index == 0) {
+               /* DSP 0 is always C6205 */
+               if ((address >= 0x01800000) & (address < 0x02000000)) {
+                       /* BAR1 - DSP  register access using */
+                       /* Non-prefetchable PCI access */
+                       p_data = pao->pci.ap_mem_base[1] +
+                               (address & 0x007fffff) /
+                               sizeof(*pao->pci.ap_mem_base[1]);
+               } else {
+                       /* BAR0 access - all of DSP memory using */
+                       /* pre-fetchable PCI access */
+                       u32 dw4M_page = address >> 22L;
+                       if (dw4M_page != phw->dsp_page) {
+                               phw->dsp_page = dw4M_page;
+                               /* *INDENT-OFF* */
+                               iowrite32(phw->dsp_page, phw->prDSPP);
+                               /* *INDENT-ON* */
+                       }
+                       address &= 0x3fffff;    /* address within 4M page */
+                       p_data = pao->pci.ap_mem_base[0] +
+                               address / sizeof(u32);
+               }
+               iowrite32(data, p_data);
+       } else if (dsp_index == 1) {
+               /* DSP 1 is a C6713 */
+               boot_loader_write_mem32(pao, 0, HPIAL_ADDR, address);
+               boot_loader_write_mem32(pao, 0, HPIAH_ADDR, address >> 16);
+
+               /* dummy read every 4 words for 6205 advisory 1.4.4 */
+               boot_loader_read_mem32(pao, 0, 0);
+
+               boot_loader_write_mem32(pao, 0, HPIDL_ADDR, data);
+               boot_loader_write_mem32(pao, 0, HPIDH_ADDR, data >> 16);
+
+               /* dummy read every 4 words for 6205 advisory 1.4.4 */
+               boot_loader_read_mem32(pao, 0, 0);
+       } else
+               err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+       return err;
+}
+
+static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
+{
+       u16 err = 0;
+
+       if (dsp_index == 0) {
+               u32 setting;
+
+               /* DSP 0 is always C6205 */
+
+               /* Set the EMIF */
+               /* memory map of C6205 */
+               /* 00000000-0000FFFF    16Kx32 internal program */
+               /* 00400000-00BFFFFF    CE0     2Mx32 SDRAM running @ 100MHz */
+
+               /* EMIF config */
+               /*------------ */
+               /* Global EMIF control */
+               boot_loader_write_mem32(pao, dsp_index, 0x01800000, 0x3779);
+#define WS_OFS 28
+#define WST_OFS 22
+#define WH_OFS 20
+#define RS_OFS 16
+#define RST_OFS 8
+#define MTYPE_OFS 4
+#define RH_OFS 0
+
+               /* EMIF CE0 setup - 2Mx32 Sync DRAM on ASI5000 cards only */
+               setting = 0x00000030;
+               boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
+               if (setting != boot_loader_read_mem32(pao, dsp_index,
+                               0x01800008))
+                       return hpi6205_error(dsp_index,
+                               HPI6205_ERROR_DSP_EMIF);
+
+               /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
+               /* which occupies D15..0. 6713 starts at 27MHz, so need */
+               /* plenty of wait states. See dsn8701.rtf, and 6713 errata. */
+               /* WST should be 71, but 63  is max possible */
+               setting =
+                       (1L << WS_OFS) | (63L << WST_OFS) | (1L << WH_OFS) |
+                       (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
+                       (2L << MTYPE_OFS);
+               boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
+               if (setting != boot_loader_read_mem32(pao, dsp_index,
+                               0x01800004))
+                       return hpi6205_error(dsp_index,
+                               HPI6205_ERROR_DSP_EMIF);
+
+               /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
+               /* which occupies D15..0. 6713 starts at 27MHz, so need */
+               /* plenty of wait states */
+               setting =
+                       (1L << WS_OFS) | (28L << WST_OFS) | (1L << WH_OFS) |
+                       (1L << RS_OFS) | (63L << RST_OFS) | (1L << RH_OFS) |
+                       (2L << MTYPE_OFS);
+               boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
+               if (setting != boot_loader_read_mem32(pao, dsp_index,
+                               0x01800010))
+                       return hpi6205_error(dsp_index,
+                               HPI6205_ERROR_DSP_EMIF);
+
+               /* EMIF CE3 setup - 32 bit async. */
+               /* This is the PLD on the ASI5000 cards only */
+               setting =
+                       (1L << WS_OFS) | (10L << WST_OFS) | (1L << WH_OFS) |
+                       (1L << RS_OFS) | (10L << RST_OFS) | (1L << RH_OFS) |
+                       (2L << MTYPE_OFS);
+               boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
+               if (setting != boot_loader_read_mem32(pao, dsp_index,
+                               0x01800014))
+                       return hpi6205_error(dsp_index,
+                               HPI6205_ERROR_DSP_EMIF);
+
+               /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
+               /*  need to use this else DSP code crashes? */
+               boot_loader_write_mem32(pao, dsp_index, 0x01800018,
+                       0x07117000);
+
+               /* EMIF SDRAM Refresh Timing */
+               /* EMIF SDRAM timing  (orig = 0x410, emulator = 0x61a) */
+               boot_loader_write_mem32(pao, dsp_index, 0x0180001C,
+                       0x00000410);
+
+       } else if (dsp_index == 1) {
+               /* test access to the C6713s HPI registers */
+               u32 write_data = 0, read_data = 0, i = 0;
+
+               /* Set up HPIC for little endian, by setiing HPIC:HWOB=1 */
+               write_data = 1;
+               boot_loader_write_mem32(pao, 0, HPICL_ADDR, write_data);
+               boot_loader_write_mem32(pao, 0, HPICH_ADDR, write_data);
+               /* C67 HPI is on lower 16bits of 32bit EMIF */
+               read_data =
+                       0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
+               if (write_data != read_data) {
+                       err = hpi6205_error(dsp_index,
+                               HPI6205_ERROR_C6713_HPIC);
+                       HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
+                               read_data);
+
+                       return err;
+               }
+               /* HPIA - walking ones test */
+               write_data = 1;
+               for (i = 0; i < 32; i++) {
+                       boot_loader_write_mem32(pao, 0, HPIAL_ADDR,
+                               write_data);
+                       boot_loader_write_mem32(pao, 0, HPIAH_ADDR,
+                               (write_data >> 16));
+                       read_data =
+                               0xFFFF & boot_loader_read_mem32(pao, 0,
+                               HPIAL_ADDR);
+                       read_data =
+                               read_data | ((0xFFFF &
+                                       boot_loader_read_mem32(pao, 0,
+                                               HPIAH_ADDR))
+                               << 16);
+                       if (read_data != write_data) {
+                               err = hpi6205_error(dsp_index,
+                                       HPI6205_ERROR_C6713_HPIA);
+                               HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
+                                       write_data, read_data);
+                               return err;
+                       }
+                       write_data = write_data << 1;
+               }
+
+               /* setup C67x PLL
+                *  ** C6713 datasheet says we cannot program PLL from HPI,
+                * and indeed if we try to set the PLL multiply from the HPI,
+                * the PLL does not seem to lock, so we enable the PLL and
+                * use the default multiply of x 7, which for a 27MHz clock
+                * gives a DSP speed of 189MHz
+                */
+               /* bypass PLL */
+               boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0000);
+               hpios_delay_micro_seconds(1000);
+               /* EMIF = 189/3=63MHz */
+               boot_loader_write_mem32(pao, dsp_index, 0x01B7C120, 0x8002);
+               /* peri = 189/2 */
+               boot_loader_write_mem32(pao, dsp_index, 0x01B7C11C, 0x8001);
+               /* cpu  = 189/1 */
+               boot_loader_write_mem32(pao, dsp_index, 0x01B7C118, 0x8000);
+               hpios_delay_micro_seconds(1000);
+               /* ** SGT test to take GPO3 high when we start the PLL */
+               /* and low when the delay is completed */
+               /* FSX0 <- '1' (GPO3) */
+               boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A0A);
+               /* PLL not bypassed */
+               boot_loader_write_mem32(pao, dsp_index, 0x01B7C100, 0x0001);
+               hpios_delay_micro_seconds(1000);
+               /* FSX0 <- '0' (GPO3) */
+               boot_loader_write_mem32(pao, 0, (0x018C0024L), 0x00002A02);
+
+               /* 6205 EMIF CE1 resetup - 32 bit async. */
+               /* Now 6713 #1 is running at 189MHz can reduce waitstates */
+               boot_loader_write_mem32(pao, 0, 0x01800004,     /* CE1 */
+                       (1L << WS_OFS) | (8L << WST_OFS) | (1L << WH_OFS) |
+                       (1L << RS_OFS) | (12L << RST_OFS) | (1L << RH_OFS) |
+                       (2L << MTYPE_OFS));
+
+               hpios_delay_micro_seconds(1000);
+
+               /* check that we can read one of the PLL registers */
+               /* PLL should not be bypassed! */
+               if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
+                       != 0x0001) {
+                       err = hpi6205_error(dsp_index,
+                               HPI6205_ERROR_C6713_PLL);
+                       return err;
+               }
+               /* setup C67x EMIF  (note this is the only use of
+                  BAR1 via BootLoader_WriteMem32) */
+               boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_GCTL,
+                       0x000034A8);
+               boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_CE0,
+                       0x00000030);
+               boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMEXT,
+                       0x001BDF29);
+               boot_loader_write_mem32(pao, dsp_index, C6713_EMIF_SDRAMCTL,
+                       0x47117000);
+               boot_loader_write_mem32(pao, dsp_index,
+                       C6713_EMIF_SDRAMTIMING, 0x00000410);
+
+               hpios_delay_micro_seconds(1000);
+       } else if (dsp_index == 2) {
+               /* DSP 2 is a C6713 */
+
+       } else
+               err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+       return err;
+}
+
+static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
+       u32 start_address, u32 length)
+{
+       u32 i = 0, j = 0;
+       u32 test_addr = 0;
+       u32 test_data = 0, data = 0;
+
+       length = 1000;
+
+       /* for 1st word, test each bit in the 32bit word, */
+       /* dwLength specifies number of 32bit words to test */
+       /*for(i=0; i<dwLength; i++) */
+       i = 0;
+       {
+               test_addr = start_address + i * 4;
+               test_data = 0x00000001;
+               for (j = 0; j < 32; j++) {
+                       boot_loader_write_mem32(pao, dsp_index, test_addr,
+                               test_data);
+                       data = boot_loader_read_mem32(pao, dsp_index,
+                               test_addr);
+                       if (data != test_data) {
+                               HPI_DEBUG_LOG(VERBOSE,
+                                       "memtest error details  "
+                                       "%08x %08x %08x %i\n", test_addr,
+                                       test_data, data, dsp_index);
+                               return 1;       /* error */
+                       }
+                       test_data = test_data << 1;
+               }       /* for(j) */
+       }       /* for(i) */
+
+       /* for the next 100 locations test each location, leaving it as zero */
+       /* write a zero to the next word in memory before we read */
+       /* the previous write to make sure every memory location is unique */
+       for (i = 0; i < 100; i++) {
+               test_addr = start_address + i * 4;
+               test_data = 0xA5A55A5A;
+               boot_loader_write_mem32(pao, dsp_index, test_addr, test_data);
+               boot_loader_write_mem32(pao, dsp_index, test_addr + 4, 0);
+               data = boot_loader_read_mem32(pao, dsp_index, test_addr);
+               if (data != test_data) {
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "memtest error details  "
+                               "%08x %08x %08x %i\n", test_addr, test_data,
+                               data, dsp_index);
+                       return 1;       /* error */
+               }
+               /* leave location as zero */
+               boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
+       }
+
+       /* zero out entire memory block */
+       for (i = 0; i < length; i++) {
+               test_addr = start_address + i * 4;
+               boot_loader_write_mem32(pao, dsp_index, test_addr, 0x0);
+       }
+       return 0;
+}
+
+static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
+       int dsp_index)
+{
+       int err = 0;
+       if (dsp_index == 0) {
+               /* DSP 0 is a C6205 */
+               /* 64K prog mem */
+               err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
+                       0x10000);
+               if (!err)
+                       /* 64K data mem */
+                       err = boot_loader_test_memory(pao, dsp_index,
+                               0x80000000, 0x10000);
+       } else if ((dsp_index == 1) || (dsp_index == 2)) {
+               /* DSP 1&2 are a C6713 */
+               /* 192K internal mem */
+               err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
+                       0x30000);
+               if (!err)
+                       /* 64K internal mem / L2 cache */
+                       err = boot_loader_test_memory(pao, dsp_index,
+                               0x00030000, 0x10000);
+       } else
+               return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+
+       if (err)
+               return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_INTMEM);
+       else
+               return 0;
+}
+
+static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
+       int dsp_index)
+{
+       u32 dRAM_start_address = 0;
+       u32 dRAM_size = 0;
+
+       if (dsp_index == 0) {
+               /* only test for SDRAM if an ASI5000 card */
+               if (pao->pci.subsys_device_id == 0x5000) {
+                       /* DSP 0 is always C6205 */
+                       dRAM_start_address = 0x00400000;
+                       dRAM_size = 0x200000;
+                       /*dwDRAMinc=1024; */
+               } else
+                       return 0;
+       } else if ((dsp_index == 1) || (dsp_index == 2)) {
+               /* DSP 1 is a C6713 */
+               dRAM_start_address = 0x80000000;
+               dRAM_size = 0x200000;
+               /*dwDRAMinc=1024; */
+       } else
+               return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+
+       if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
+                       dRAM_size))
+               return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_EXTMEM);
+       return 0;
+}
+
+static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
+{
+       u32 data = 0;
+       if (dsp_index == 0) {
+               /* only test for DSP0 PLD on ASI5000 card */
+               if (pao->pci.subsys_device_id == 0x5000) {
+                       /* PLD is located at CE3=0x03000000 */
+                       data = boot_loader_read_mem32(pao, dsp_index,
+                               0x03000008);
+                       if ((data & 0xF) != 0x5)
+                               return hpi6205_error(dsp_index,
+                                       HPI6205_ERROR_DSP_PLD);
+                       data = boot_loader_read_mem32(pao, dsp_index,
+                               0x0300000C);
+                       if ((data & 0xF) != 0xA)
+                               return hpi6205_error(dsp_index,
+                                       HPI6205_ERROR_DSP_PLD);
+               }
+       } else if (dsp_index == 1) {
+               /* DSP 1 is a C6713 */
+               if (pao->pci.subsys_device_id == 0x8700) {
+                       /* PLD is located at CE1=0x90000000 */
+                       data = boot_loader_read_mem32(pao, dsp_index,
+                               0x90000010);
+                       if ((data & 0xFF) != 0xAA)
+                               return hpi6205_error(dsp_index,
+                                       HPI6205_ERROR_DSP_PLD);
+                       /* 8713 - LED on */
+                       boot_loader_write_mem32(pao, dsp_index, 0x90000000,
+                               0x02);
+               }
+       }
+       return 0;
+}
+
+/** Transfer data to or from DSP
+ nOperation = H620_H620_HIF_SEND_DATA or H620_HIF_GET_DATA
+*/
+static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
+       u32 data_size, int operation)
+{
+       struct hpi_hw_obj *phw = pao->priv;
+       u32 data_transferred = 0;
+       u16 err = 0;
+#ifndef HPI6205_NO_HSR_POLL
+       u32 time_out;
+#endif
+       u32 temp2;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+
+       if (!p_data)
+               return HPI_ERROR_INVALID_DATA_TRANSFER;
+
+       data_size &= ~3L;       /* round data_size down to nearest 4 bytes */
+
+       /* make sure state is IDLE */
+       if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT))
+               return HPI_ERROR_DSP_HARDWARE;
+
+       while (data_transferred < data_size) {
+               u32 this_copy = data_size - data_transferred;
+
+               if (this_copy > HPI6205_SIZEOF_DATA)
+                       this_copy = HPI6205_SIZEOF_DATA;
+
+               if (operation == H620_HIF_SEND_DATA)
+                       memcpy((void *)&interface->u.b_data[0],
+                               &p_data[data_transferred], this_copy);
+
+               interface->transfer_size_in_bytes = this_copy;
+
+#ifdef HPI6205_NO_HSR_POLL
+               /* DSP must change this back to nOperation */
+               interface->dsp_ack = H620_HIF_IDLE;
+#endif
+
+               send_dsp_command(phw, operation);
+
+#ifdef HPI6205_NO_HSR_POLL
+               temp2 = wait_dsp_ack(phw, operation, HPI6205_TIMEOUT);
+               HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
+                       HPI6205_TIMEOUT - temp2, this_copy);
+
+               if (!temp2) {
+                       /* timed out */
+                       HPI_DEBUG_LOG(ERROR,
+                               "timed out waiting for " "state %d got %d\n",
+                               operation, interface->dsp_ack);
+
+                       break;
+               }
+#else
+               /* spin waiting on the result */
+               time_out = HPI6205_TIMEOUT;
+               temp2 = 0;
+               while ((temp2 == 0) && time_out--) {
+                       /* give 16k bus mastering transfer time to happen */
+                       /*(16k / 132Mbytes/s = 122usec) */
+                       hpios_delay_micro_seconds(20);
+                       temp2 = ioread32(phw->prHSR);
+                       temp2 &= C6205_HSR_INTSRC;
+               }
+               HPI_DEBUG_LOG(DEBUG, "spun %d times for data xfer of %d\n",
+                       HPI6205_TIMEOUT - time_out, this_copy);
+               if (temp2 == C6205_HSR_INTSRC) {
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "interrupt from HIF <data> OK\n");
+                       /*
+                          if(interface->dwDspAck != nOperation) {
+                          HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d,
+                          expected %d \n",
+                          interface->dwDspAck,nOperation);
+                          }
+                        */
+               }
+/* need to handle this differently... */
+               else {
+                       HPI_DEBUG_LOG(ERROR,
+                               "interrupt from HIF <data> BAD\n");
+                       err = HPI_ERROR_DSP_HARDWARE;
+               }
+
+               /* reset the interrupt from the DSP */
+               iowrite32(C6205_HSR_INTSRC, phw->prHSR);
+#endif
+               if (operation == H620_HIF_GET_DATA)
+                       memcpy(&p_data[data_transferred],
+                               (void *)&interface->u.b_data[0], this_copy);
+
+               data_transferred += this_copy;
+       }
+       if (interface->dsp_ack != operation)
+               HPI_DEBUG_LOG(DEBUG, "interface->dsp_ack=%d, expected %d\n",
+                       interface->dsp_ack, operation);
+       /*                      err=HPI_ERROR_DSP_HARDWARE; */
+
+       send_dsp_command(phw, H620_HIF_IDLE);
+
+       return err;
+}
+
+/* wait for up to timeout_us microseconds for the DSP
+   to signal state by DMA into dwDspAck
+*/
+static int wait_dsp_ack(struct hpi_hw_obj *phw, int state, int timeout_us)
+{
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       int t = timeout_us / 4;
+
+       rmb();  /* ensure interface->dsp_ack is up to date */
+       while ((interface->dsp_ack != state) && --t) {
+               hpios_delay_micro_seconds(4);
+               rmb();  /* DSP changes dsp_ack by DMA */
+       }
+
+       /*HPI_DEBUG_LOG(VERBOSE, "Spun %d for %d\n", timeout_us/4-t, state); */
+       return t * 4;
+}
+
+/* set the busmaster interface to cmd, then interrupt the DSP */
+static void send_dsp_command(struct hpi_hw_obj *phw, int cmd)
+{
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+
+       u32 r;
+
+       interface->host_cmd = cmd;
+       wmb();  /* DSP gets state by DMA, make sure it is written to memory */
+       /* before we interrupt the DSP */
+       r = ioread32(phw->prHDCR);
+       r |= (u32)C6205_HDCR_DSPINT;
+       iowrite32(r, phw->prHDCR);
+       r &= ~(u32)C6205_HDCR_DSPINT;
+       iowrite32(r, phw->prHDCR);
+}
+
+static unsigned int message_count;
+
+static u16 message_response_sequence(struct hpi_adapter_obj *pao,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+#ifndef HPI6205_NO_HSR_POLL
+       u32 temp2;
+#endif
+       u32 time_out, time_out2;
+       struct hpi_hw_obj *phw = pao->priv;
+       struct bus_master_interface *interface = phw->p_interface_buffer;
+       u16 err = 0;
+
+       message_count++;
+       /* Assume buffer of type struct bus_master_interface
+          is allocated "noncacheable" */
+
+       if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
+               HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
+               return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
+       }
+       interface->u.message_buffer = *phm;
+       /* signal we want a response */
+       send_dsp_command(phw, H620_HIF_GET_RESP);
+
+       time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
+
+       if (time_out2 == 0) {
+               HPI_DEBUG_LOG(ERROR,
+                       "(%u) timed out waiting for " "GET_RESP state [%x]\n",
+                       message_count, interface->dsp_ack);
+       } else {
+               HPI_DEBUG_LOG(VERBOSE,
+                       "(%u) transition to GET_RESP after %u\n",
+                       message_count, HPI6205_TIMEOUT - time_out2);
+       }
+       /* spin waiting on HIF interrupt flag (end of msg process) */
+       time_out = HPI6205_TIMEOUT;
+
+#ifndef HPI6205_NO_HSR_POLL
+       temp2 = 0;
+       while ((temp2 == 0) && --time_out) {
+               temp2 = ioread32(phw->prHSR);
+               temp2 &= C6205_HSR_INTSRC;
+               hpios_delay_micro_seconds(1);
+       }
+       if (temp2 == C6205_HSR_INTSRC) {
+               rmb();  /* ensure we see latest value for dsp_ack */
+               if ((interface->dsp_ack != H620_HIF_GET_RESP)) {
+                       HPI_DEBUG_LOG(DEBUG,
+                               "(%u)interface->dsp_ack(0x%x) != "
+                               "H620_HIF_GET_RESP, t=%u\n", message_count,
+                               interface->dsp_ack,
+                               HPI6205_TIMEOUT - time_out);
+               } else {
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "(%u)int with GET_RESP after %u\n",
+                               message_count, HPI6205_TIMEOUT - time_out);
+               }
+
+       } else {
+               /* can we do anything else in response to the error ? */
+               HPI_DEBUG_LOG(ERROR,
+                       "interrupt from HIF module BAD (function %x)\n",
+                       phm->function);
+       }
+
+       /* reset the interrupt from the DSP */
+       iowrite32(C6205_HSR_INTSRC, phw->prHSR);
+#endif
+
+       /* read the result */
+       if (time_out != 0)
+               *phr = interface->u.response_buffer;
+
+       /* set interface back to idle */
+       send_dsp_command(phw, H620_HIF_IDLE);
+
+       if ((time_out == 0) || (time_out2 == 0)) {
+               HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
+               return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_TIMEOUT);
+       }
+       /* special case for adapter close - */
+       /* wait for the DSP to indicate it is idle */
+       if (phm->function == HPI_ADAPTER_CLOSE) {
+               if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
+                       HPI_DEBUG_LOG(DEBUG,
+                               "timeout waiting for idle "
+                               "(on adapter_close)\n");
+                       return hpi6205_error(0,
+                               HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
+               }
+       }
+       err = hpi_validate_response(phm, phr);
+       return err;
+}
+
+static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+
+       u16 err = 0;
+
+       hpios_dsplock_lock(pao);
+
+       err = message_response_sequence(pao, phm, phr);
+
+       /* maybe an error response */
+       if (err) {
+               /* something failed in the HPI/DSP interface */
+               phr->error = err;
+               pao->dsp_crashed++;
+
+               /* just the header of the response is valid */
+               phr->size = sizeof(struct hpi_response_header);
+               goto err;
+       } else
+               pao->dsp_crashed = 0;
+
+       if (phr->error != 0)    /* something failed in the DSP */
+               goto err;
+
+       switch (phm->function) {
+       case HPI_OSTREAM_WRITE:
+       case HPI_ISTREAM_ANC_WRITE:
+               err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
+                       phm->u.d.u.data.data_size, H620_HIF_SEND_DATA);
+               break;
+
+       case HPI_ISTREAM_READ:
+       case HPI_OSTREAM_ANC_READ:
+               err = hpi6205_transfer_data(pao, phm->u.d.u.data.pb_data,
+                       phm->u.d.u.data.data_size, H620_HIF_GET_DATA);
+               break;
+
+       case HPI_CONTROL_SET_STATE:
+               if (phm->object == HPI_OBJ_CONTROLEX
+                       && phm->u.cx.attribute == HPI_COBRANET_SET_DATA)
+                       err = hpi6205_transfer_data(pao,
+                               phm->u.cx.u.cobranet_bigdata.pb_data,
+                               phm->u.cx.u.cobranet_bigdata.byte_count,
+                               H620_HIF_SEND_DATA);
+               break;
+
+       case HPI_CONTROL_GET_STATE:
+               if (phm->object == HPI_OBJ_CONTROLEX
+                       && phm->u.cx.attribute == HPI_COBRANET_GET_DATA)
+                       err = hpi6205_transfer_data(pao,
+                               phm->u.cx.u.cobranet_bigdata.pb_data,
+                               phr->u.cx.u.cobranet_data.byte_count,
+                               H620_HIF_GET_DATA);
+               break;
+       }
+       phr->error = err;
+
+err:
+       hpios_dsplock_unlock(pao);
+
+       return;
+}
diff --git a/sound/pci/asihpi/hpi6205.h b/sound/pci/asihpi/hpi6205.h
new file mode 100644 (file)
index 0000000..1adae08
--- /dev/null
@@ -0,0 +1,93 @@
+/*****************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Host Interface module for an ASI6205 based
+bus mastering PCI adapter.
+
+Copyright AudioScience, Inc., 2003
+******************************************************************************/
+
+#ifndef _HPI6205_H_
+#define _HPI6205_H_
+
+/* transitional conditional compile shared between host and DSP */
+/* #define HPI6205_NO_HSR_POLL */
+
+#include "hpi_internal.h"
+
+/***********************************************************
+       Defines used for basic messaging
+************************************************************/
+#define H620_HIF_RESET          0
+#define H620_HIF_IDLE           1
+#define H620_HIF_GET_RESP       2
+#define H620_HIF_DATA_DONE      3
+#define H620_HIF_DATA_MASK      0x10
+#define H620_HIF_SEND_DATA      0x14
+#define H620_HIF_GET_DATA       0x15
+#define H620_HIF_UNKNOWN                0x0000ffff
+
+/***********************************************************
+       Types used for mixer control caching
+************************************************************/
+
+#define H620_MAX_ISTREAMS 32
+#define H620_MAX_OSTREAMS 32
+#define HPI_NMIXER_CONTROLS 2048
+
+/*********************************************************************
+This is used for dynamic control cache allocation
+**********************************************************************/
+struct controlcache_6205 {
+       u32 number_of_controls;
+       u32 physical_address32;
+       u32 size_in_bytes;
+};
+
+/*********************************************************************
+This is used for dynamic allocation of async event array
+**********************************************************************/
+struct async_event_buffer_6205 {
+       u32 physical_address32;
+       u32 spare;
+       struct hpi_fifo_buffer b;
+};
+
+/***********************************************************
+The Host located memory buffer that the 6205 will bus master
+in and out of.
+************************************************************/
+#define HPI6205_SIZEOF_DATA (16*1024)
+struct bus_master_interface {
+       u32 host_cmd;
+       u32 dsp_ack;
+       u32 transfer_size_in_bytes;
+       union {
+               struct hpi_message message_buffer;
+               struct hpi_response response_buffer;
+               u8 b_data[HPI6205_SIZEOF_DATA];
+       } u;
+       struct controlcache_6205 control_cache;
+       struct async_event_buffer_6205 async_buffer;
+       struct hpi_hostbuffer_status
+        instream_host_buffer_status[H620_MAX_ISTREAMS];
+       struct hpi_hostbuffer_status
+        outstream_host_buffer_status[H620_MAX_OSTREAMS];
+};
+
+#endif
diff --git a/sound/pci/asihpi/hpi_internal.h b/sound/pci/asihpi/hpi_internal.h
new file mode 100644 (file)
index 0000000..f1cd6f1
--- /dev/null
@@ -0,0 +1,1641 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+HPI internal definitions
+
+(C) Copyright AudioScience Inc. 1996-2009
+******************************************************************************/
+
+#ifndef _HPI_INTERNAL_H_
+#define _HPI_INTERNAL_H_
+
+#include "hpi.h"
+/** maximum number of memory regions mapped to an adapter */
+#define HPI_MAX_ADAPTER_MEM_SPACES (2)
+
+/* Each OS needs its own hpios.h, or specific define as above */
+#include "hpios.h"
+
+/* physical memory allocation */
+void hpios_locked_mem_init(void
+       );
+void hpios_locked_mem_free_all(void
+       );
+#define hpios_locked_mem_prepare(a, b, c, d);
+#define hpios_locked_mem_unprepare(a)
+
+/** Allocate and map an area of locked memory for bus master DMA operations.
+
+On success, *pLockedMemeHandle is a valid handle, and 0 is returned
+On error *pLockedMemHandle marked invalid, non-zero returned.
+
+If this function succeeds, then HpiOs_LockedMem_GetVirtAddr() and
+HpiOs_LockedMem_GetPyhsAddr() will always succed on the returned handle.
+*/
+u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_locked_mem_handle,
+                                                          /**< memory handle */
+       u32 size, /**< size in bytes to allocate */
+       struct pci_dev *p_os_reference
+       /**< OS specific data required for memory allocation */
+       );
+
+/** Free mapping and memory represented by LockedMemHandle
+
+Frees any resources, then invalidates the handle.
+Returns 0 on success, 1 if handle is invalid.
+
+*/
+u16 hpios_locked_mem_free(struct consistent_dma_area *locked_mem_handle);
+
+/** Get the physical PCI address of memory represented by LockedMemHandle.
+
+If handle is invalid *pPhysicalAddr is set to zero and return 1
+*/
+u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
+       *locked_mem_handle, u32 *p_physical_addr);
+
+/** Get the CPU address of of memory represented by LockedMemHandle.
+
+If handle is NULL *ppvVirtualAddr is set to NULL and return 1
+*/
+u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
+       *locked_mem_handle, void **ppv_virtual_addr);
+
+/** Check that handle is valid
+i.e it represents a valid memory area
+*/
+u16 hpios_locked_mem_valid(struct consistent_dma_area *locked_mem_handle);
+
+/* timing/delay */
+void hpios_delay_micro_seconds(u32 num_micro_sec);
+
+struct hpi_message;
+struct hpi_response;
+
+typedef void hpi_handler_func(struct hpi_message *, struct hpi_response *);
+
+/* If the assert fails, compiler complains
+   something like size of array `msg' is negative.
+   Unlike linux BUILD_BUG_ON, this works outside function scope.
+*/
+#define compile_time_assert(cond, msg) \
+    typedef char ASSERT_##msg[(cond) ? 1 : -1]
+
+/*/////////////////////////////////////////////////////////////////////////// */
+/* Private HPI Entity related definitions                                     */
+
+#define STR_SIZE_FIELD_MAX 65535U
+#define STR_TYPE_FIELD_MAX 255U
+#define STR_ROLE_FIELD_MAX 255U
+
+struct hpi_entity_str {
+       uint16_t size;
+       uint8_t type;
+       uint8_t role;
+};
+
+#if defined(_MSC_VER)
+#pragma warning(push)
+#pragma warning(disable : 4200)
+#endif
+
+struct hpi_entity {
+       struct hpi_entity_str header;
+#if ! defined(HPI_OS_DSP_C6000) || (defined(HPI_OS_DSP_C6000) && (__TI_COMPILER_VERSION__ > 6000008))
+       /* DSP C6000 compiler v6.0.8 and lower
+          do not support  flexible array member */
+       uint8_t value[];
+#else
+       /* NOTE! Using sizeof(struct hpi_entity) will give erroneous results */
+#define HPI_INTERNAL_WARN_ABOUT_ENTITY_VALUE
+       uint8_t value[1];
+#endif
+};
+
+#if defined(_MSC_VER)
+#pragma warning(pop)
+#endif
+
+/******************************************* bus types */
+enum HPI_BUSES {
+       HPI_BUS_ISAPNP = 1,
+       HPI_BUS_PCI = 2,
+       HPI_BUS_USB = 3,
+       HPI_BUS_NET = 4
+};
+
+/******************************************* CONTROL ATTRIBUTES ****/
+/* (in order of control type ID */
+
+       /* This allows for 255 control types, 256 unique attributes each */
+#define HPI_CTL_ATTR(ctl, ai) (HPI_CONTROL_##ctl * 0x100 + ai)
+
+/* Get the sub-index of the attribute for a control type */
+#define HPI_CTL_ATTR_INDEX(i) (i&0xff)
+
+/* Generic control attributes.  */
+
+/** Enable a control.
+0=disable, 1=enable
+\note generic to all mixer plugins?
+*/
+#define HPI_GENERIC_ENABLE HPI_CTL_ATTR(GENERIC, 1)
+
+/** Enable event generation for a control.
+0=disable, 1=enable
+\note generic to all controls that can generate events
+*/
+#define HPI_GENERIC_EVENT_ENABLE HPI_CTL_ATTR(GENERIC, 2)
+
+/* Volume Control attributes */
+#define HPI_VOLUME_GAIN                 HPI_CTL_ATTR(VOLUME, 1)
+#define HPI_VOLUME_AUTOFADE             HPI_CTL_ATTR(VOLUME, 2)
+
+/** For HPI_ControlQuery() to get the number of channels of a volume control*/
+#define HPI_VOLUME_NUM_CHANNELS         HPI_CTL_ATTR(VOLUME, 6)
+#define HPI_VOLUME_RANGE                HPI_CTL_ATTR(VOLUME, 10)
+
+/** Level Control attributes */
+#define HPI_LEVEL_GAIN                  HPI_CTL_ATTR(LEVEL, 1)
+#define HPI_LEVEL_RANGE                 HPI_CTL_ATTR(LEVEL, 10)
+
+/* Meter Control attributes */
+/** return RMS signal level */
+#define HPI_METER_RMS                   HPI_CTL_ATTR(METER, 1)
+/** return peak signal level */
+#define HPI_METER_PEAK                  HPI_CTL_ATTR(METER, 2)
+/** ballistics for ALL rms meters on adapter */
+#define HPI_METER_RMS_BALLISTICS        HPI_CTL_ATTR(METER, 3)
+/** ballistics for ALL peak meters on adapter */
+#define HPI_METER_PEAK_BALLISTICS       HPI_CTL_ATTR(METER, 4)
+
+/** For HPI_ControlQuery() to get the number of channels of a meter control*/
+#define HPI_METER_NUM_CHANNELS          HPI_CTL_ATTR(METER, 5)
+
+/* Multiplexer control attributes */
+#define HPI_MULTIPLEXER_SOURCE          HPI_CTL_ATTR(MULTIPLEXER, 1)
+#define HPI_MULTIPLEXER_QUERYSOURCE     HPI_CTL_ATTR(MULTIPLEXER, 2)
+
+/** AES/EBU transmitter control attributes */
+/** AESEBU or SPDIF */
+#define HPI_AESEBUTX_FORMAT             HPI_CTL_ATTR(AESEBUTX, 1)
+#define HPI_AESEBUTX_SAMPLERATE         HPI_CTL_ATTR(AESEBUTX, 3)
+#define HPI_AESEBUTX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBUTX, 4)
+#define HPI_AESEBUTX_USERDATA           HPI_CTL_ATTR(AESEBUTX, 5)
+
+/** AES/EBU receiver control attributes */
+#define HPI_AESEBURX_FORMAT             HPI_CTL_ATTR(AESEBURX, 1)
+#define HPI_AESEBURX_ERRORSTATUS        HPI_CTL_ATTR(AESEBURX, 2)
+#define HPI_AESEBURX_SAMPLERATE         HPI_CTL_ATTR(AESEBURX, 3)
+#define HPI_AESEBURX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBURX, 4)
+#define HPI_AESEBURX_USERDATA           HPI_CTL_ATTR(AESEBURX, 5)
+
+/** \defgroup tuner_defs Tuners
+\{
+*/
+/** \defgroup tuner_attrs Tuner control attributes
+\{
+*/
+#define HPI_TUNER_BAND                  HPI_CTL_ATTR(TUNER, 1)
+#define HPI_TUNER_FREQ                  HPI_CTL_ATTR(TUNER, 2)
+#define HPI_TUNER_LEVEL                 HPI_CTL_ATTR(TUNER, 3)
+#define HPI_TUNER_AUDIOMUTE             HPI_CTL_ATTR(TUNER, 4)
+/* use TUNER_STATUS instead */
+#define HPI_TUNER_VIDEO_STATUS          HPI_CTL_ATTR(TUNER, 5)
+#define HPI_TUNER_GAIN                  HPI_CTL_ATTR(TUNER, 6)
+#define HPI_TUNER_STATUS                HPI_CTL_ATTR(TUNER, 7)
+#define HPI_TUNER_MODE                  HPI_CTL_ATTR(TUNER, 8)
+/** RDS data. */
+#define HPI_TUNER_RDS                   HPI_CTL_ATTR(TUNER, 9)
+/** Audio pre-emphasis. */
+#define HPI_TUNER_DEEMPHASIS            HPI_CTL_ATTR(TUNER, 10)
+/** HD Radio tuner program control. */
+#define HPI_TUNER_PROGRAM               HPI_CTL_ATTR(TUNER, 11)
+/** HD Radio tuner digital signal quality. */
+#define HPI_TUNER_HDRADIO_SIGNAL_QUALITY        HPI_CTL_ATTR(TUNER, 12)
+/** HD Radio SDK firmware version. */
+#define HPI_TUNER_HDRADIO_SDK_VERSION   HPI_CTL_ATTR(TUNER, 13)
+/** HD Radio DSP firmware version. */
+#define HPI_TUNER_HDRADIO_DSP_VERSION   HPI_CTL_ATTR(TUNER, 14)
+
+/** \} */
+
+/** \defgroup pads_attrs Tuner PADs control attributes
+\{
+*/
+/** The text string containing the station/channel combination. */
+#define HPI_PAD_CHANNEL_NAME            HPI_CTL_ATTR(PAD, 1)
+/** The text string containing the artist. */
+#define HPI_PAD_ARTIST                  HPI_CTL_ATTR(PAD, 2)
+/** The text string containing the title. */
+#define HPI_PAD_TITLE                   HPI_CTL_ATTR(PAD, 3)
+/** The text string containing the comment. */
+#define HPI_PAD_COMMENT                 HPI_CTL_ATTR(PAD, 4)
+/** The integer containing the PTY code. */
+#define HPI_PAD_PROGRAM_TYPE            HPI_CTL_ATTR(PAD, 5)
+/** The integer containing the program identification. */
+#define HPI_PAD_PROGRAM_ID              HPI_CTL_ATTR(PAD, 6)
+/** The integer containing whether traffic information is supported.
+Contains either 1 or 0. */
+#define HPI_PAD_TA_SUPPORT              HPI_CTL_ATTR(PAD, 7)
+/** The integer containing whether traffic announcement is in progress.
+Contains either 1 or 0. */
+#define HPI_PAD_TA_ACTIVE               HPI_CTL_ATTR(PAD, 8)
+/** \} */
+/** \} */
+
+/* VOX control attributes */
+#define HPI_VOX_THRESHOLD               HPI_CTL_ATTR(VOX, 1)
+
+/*?? channel mode used hpi_multiplexer_source attribute == 1 */
+#define HPI_CHANNEL_MODE_MODE HPI_CTL_ATTR(CHANNEL_MODE, 1)
+
+/** \defgroup channel_modes Channel Modes
+Used for HPI_ChannelModeSet/Get()
+\{
+*/
+/** Left channel out = left channel in, Right channel out = right channel in. */
+#define HPI_CHANNEL_MODE_NORMAL                 1
+/** Left channel out = right channel in, Right channel out = left channel in. */
+#define HPI_CHANNEL_MODE_SWAP                   2
+/** Left channel out = left channel in, Right channel out = left channel in. */
+#define HPI_CHANNEL_MODE_LEFT_TO_STEREO         3
+/** Left channel out = right channel in, Right channel out = right channel in.*/
+#define HPI_CHANNEL_MODE_RIGHT_TO_STEREO        4
+/** Left channel out = (left channel in + right channel in)/2,
+    Right channel out = mute. */
+#define HPI_CHANNEL_MODE_STEREO_TO_LEFT         5
+/** Left channel out = mute,
+    Right channel out = (right channel in + left channel in)/2. */
+#define HPI_CHANNEL_MODE_STEREO_TO_RIGHT        6
+#define HPI_CHANNEL_MODE_LAST                   6
+/** \} */
+
+/* Bitstream control set attributes */
+#define HPI_BITSTREAM_DATA_POLARITY     HPI_CTL_ATTR(BITSTREAM, 1)
+#define HPI_BITSTREAM_CLOCK_EDGE        HPI_CTL_ATTR(BITSTREAM, 2)
+#define HPI_BITSTREAM_CLOCK_SOURCE      HPI_CTL_ATTR(BITSTREAM, 3)
+
+#define HPI_POLARITY_POSITIVE           0
+#define HPI_POLARITY_NEGATIVE           1
+
+/* Bitstream control get attributes */
+#define HPI_BITSTREAM_ACTIVITY          1
+
+/* SampleClock control attributes */
+#define HPI_SAMPLECLOCK_SOURCE                  HPI_CTL_ATTR(SAMPLECLOCK, 1)
+#define HPI_SAMPLECLOCK_SAMPLERATE              HPI_CTL_ATTR(SAMPLECLOCK, 2)
+#define HPI_SAMPLECLOCK_SOURCE_INDEX            HPI_CTL_ATTR(SAMPLECLOCK, 3)
+#define HPI_SAMPLECLOCK_LOCAL_SAMPLERATE\
+       HPI_CTL_ATTR(SAMPLECLOCK, 4)
+#define HPI_SAMPLECLOCK_AUTO                    HPI_CTL_ATTR(SAMPLECLOCK, 5)
+#define HPI_SAMPLECLOCK_LOCAL_LOCK                      HPI_CTL_ATTR(SAMPLECLOCK, 6)
+
+/* Microphone control attributes */
+#define HPI_MICROPHONE_PHANTOM_POWER HPI_CTL_ATTR(MICROPHONE, 1)
+
+/** Equalizer control attributes
+*/
+/** Used to get number of filters in an EQ. (Can't set) */
+#define HPI_EQUALIZER_NUM_FILTERS HPI_CTL_ATTR(EQUALIZER, 1)
+/** Set/get the filter by type, freq, Q, gain */
+#define HPI_EQUALIZER_FILTER HPI_CTL_ATTR(EQUALIZER, 2)
+/** Get the biquad coefficients */
+#define HPI_EQUALIZER_COEFFICIENTS HPI_CTL_ATTR(EQUALIZER, 3)
+
+#define HPI_COMPANDER_PARAMS HPI_CTL_ATTR(COMPANDER, 1)
+
+/* Cobranet control attributes.
+   MUST be distinct from all other control attributes.
+   This is so that host side processing can easily identify a Cobranet control
+   and apply additional host side operations (like copying data) as required.
+*/
+#define HPI_COBRANET_SET         HPI_CTL_ATTR(COBRANET, 1)
+#define HPI_COBRANET_GET         HPI_CTL_ATTR(COBRANET, 2)
+#define HPI_COBRANET_SET_DATA    HPI_CTL_ATTR(COBRANET, 3)
+#define HPI_COBRANET_GET_DATA    HPI_CTL_ATTR(COBRANET, 4)
+#define HPI_COBRANET_GET_STATUS  HPI_CTL_ATTR(COBRANET, 5)
+#define HPI_COBRANET_SEND_PACKET HPI_CTL_ATTR(COBRANET, 6)
+#define HPI_COBRANET_GET_PACKET  HPI_CTL_ATTR(COBRANET, 7)
+
+/*------------------------------------------------------------
+ Cobranet Chip Bridge - copied from HMI.H
+------------------------------------------------------------*/
+#define  HPI_COBRANET_HMI_cobra_bridge           0x20000
+#define  HPI_COBRANET_HMI_cobra_bridge_tx_pkt_buf \
+       (HPI_COBRANET_HMI_cobra_bridge + 0x1000)
+#define  HPI_COBRANET_HMI_cobra_bridge_rx_pkt_buf \
+       (HPI_COBRANET_HMI_cobra_bridge + 0x2000)
+#define  HPI_COBRANET_HMI_cobra_if_table1         0x110000
+#define  HPI_COBRANET_HMI_cobra_if_phy_address \
+       (HPI_COBRANET_HMI_cobra_if_table1 + 0xd)
+#define  HPI_COBRANET_HMI_cobra_protocolIP       0x72000
+#define  HPI_COBRANET_HMI_cobra_ip_mon_currentIP \
+       (HPI_COBRANET_HMI_cobra_protocolIP + 0x0)
+#define  HPI_COBRANET_HMI_cobra_ip_mon_staticIP \
+       (HPI_COBRANET_HMI_cobra_protocolIP + 0x2)
+#define  HPI_COBRANET_HMI_cobra_sys              0x100000
+#define  HPI_COBRANET_HMI_cobra_sys_desc \
+               (HPI_COBRANET_HMI_cobra_sys + 0x0)
+#define  HPI_COBRANET_HMI_cobra_sys_objectID \
+       (HPI_COBRANET_HMI_cobra_sys + 0x100)
+#define  HPI_COBRANET_HMI_cobra_sys_contact \
+       (HPI_COBRANET_HMI_cobra_sys + 0x200)
+#define  HPI_COBRANET_HMI_cobra_sys_name \
+               (HPI_COBRANET_HMI_cobra_sys + 0x300)
+#define  HPI_COBRANET_HMI_cobra_sys_location \
+       (HPI_COBRANET_HMI_cobra_sys + 0x400)
+
+/*------------------------------------------------------------
+ Cobranet Chip Status bits
+------------------------------------------------------------*/
+#define HPI_COBRANET_HMI_STATUS_RXPACKET 2
+#define HPI_COBRANET_HMI_STATUS_TXPACKET 3
+
+/*------------------------------------------------------------
+ Ethernet header size
+------------------------------------------------------------*/
+#define HPI_ETHERNET_HEADER_SIZE (16)
+
+/* These defines are used to fill in protocol information for an Ethernet packet
+    sent using HMI on CS18102 */
+/** ID supplied by Cirrius for ASI packets. */
+#define HPI_ETHERNET_PACKET_ID                  0x85
+/** Simple packet - no special routing required */
+#define HPI_ETHERNET_PACKET_V1                  0x01
+/** This packet must make its way to the host across the HPI interface */
+#define HPI_ETHERNET_PACKET_HOSTED_VIA_HMI      0x20
+/** This packet must make its way to the host across the HPI interface */
+#define HPI_ETHERNET_PACKET_HOSTED_VIA_HMI_V1   0x21
+/** This packet must make its way to the host across the HPI interface */
+#define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI      0x40
+/** This packet must make its way to the host across the HPI interface */
+#define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI_V1   0x41
+
+#define HPI_ETHERNET_UDP_PORT (44600)  /*!< UDP messaging port */
+
+/** Base network time out is set to 100 milli-seconds. */
+#define HPI_ETHERNET_TIMEOUT_MS      (100)
+
+/** \defgroup tonedet_attr Tonedetector attributes
+\{
+Used by HPI_ToneDetector_Set() and HPI_ToneDetector_Get()
+*/
+
+/** Set the threshold level of a tonedetector,
+Threshold is a -ve number in units of dB/100,
+*/
+#define HPI_TONEDETECTOR_THRESHOLD HPI_CTL_ATTR(TONEDETECTOR, 1)
+
+/** Get the current state of tonedetection
+The result is a bitmap of detected tones.  pairs of bits represent the left
+and right channels, with left channel in LSB.
+The lowest frequency detector state is in the LSB
+*/
+#define HPI_TONEDETECTOR_STATE HPI_CTL_ATTR(TONEDETECTOR, 2)
+
+/** Get the frequency of a tonedetector band.
+*/
+#define HPI_TONEDETECTOR_FREQUENCY HPI_CTL_ATTR(TONEDETECTOR, 3)
+
+/**\}*/
+
+/** \defgroup silencedet_attr SilenceDetector attributes
+\{
+*/
+
+/** Get the current state of tonedetection
+The result is a bitmap with 1s for silent channels. Left channel is in LSB
+*/
+#define HPI_SILENCEDETECTOR_STATE \
+  HPI_CTL_ATTR(SILENCEDETECTOR, 2)
+
+/** Set the threshold level of a SilenceDetector,
+Threshold is a -ve number in units of dB/100,
+*/
+#define HPI_SILENCEDETECTOR_THRESHOLD \
+  HPI_CTL_ATTR(SILENCEDETECTOR, 1)
+
+/** get/set the silence time before the detector triggers
+*/
+#define HPI_SILENCEDETECTOR_DELAY \
+       HPI_CTL_ATTR(SILENCEDETECTOR, 3)
+
+/**\}*/
+
+/* Locked memory buffer alloc/free phases */
+/** use one message to allocate or free physical memory */
+#define HPI_BUFFER_CMD_EXTERNAL                 0
+/** alloc physical memory */
+#define HPI_BUFFER_CMD_INTERNAL_ALLOC           1
+/** send physical memory address to adapter */
+#define HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER    2
+/** notify adapter to stop using physical buffer */
+#define HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER   3
+/** free physical buffer */
+#define HPI_BUFFER_CMD_INTERNAL_FREE            4
+
+/******************************************* CONTROLX ATTRIBUTES ****/
+/* NOTE: All controlx attributes must be unique, unlike control attributes */
+
+/*****************************************************************************/
+/*****************************************************************************/
+/********               HPI LOW LEVEL MESSAGES                  *******/
+/*****************************************************************************/
+/*****************************************************************************/
+/** Pnp ids */
+/** "ASI"  - actual is "ASX" - need to change */
+#define HPI_ID_ISAPNP_AUDIOSCIENCE      0x0669
+/** PCI vendor ID that AudioScience uses */
+#define HPI_PCI_VENDOR_ID_AUDIOSCIENCE  0x175C
+/** PCI vendor ID that the DSP56301 has */
+#define HPI_PCI_VENDOR_ID_MOTOROLA      0x1057
+/** PCI vendor ID that TI uses */
+#define HPI_PCI_VENDOR_ID_TI            0x104C
+
+#define HPI_PCI_DEV_ID_PCI2040          0xAC60
+/** TI's C6205 PCI interface has this ID */
+#define HPI_PCI_DEV_ID_DSP6205          0xA106
+
+#define HPI_USB_VENDOR_ID_AUDIOSCIENCE  0x1257
+#define HPI_USB_W2K_TAG                 0x57495341     /* "ASIW"       */
+#define HPI_USB_LINUX_TAG               0x4C495341     /* "ASIL"       */
+
+/** First 2 hex digits define the adapter family */
+#define HPI_ADAPTER_FAMILY_MASK         0xff00
+
+#define HPI_ADAPTER_FAMILY_ASI(f)   (f & HPI_ADAPTER_FAMILY_MASK)
+#define HPI_ADAPTER_ASI(f)   (f)
+
+/******************************************* message types */
+#define HPI_TYPE_MESSAGE                        1
+#define HPI_TYPE_RESPONSE                       2
+#define HPI_TYPE_DATA                           3
+#define HPI_TYPE_SSX2BYPASS_MESSAGE             4
+
+/******************************************* object types */
+#define HPI_OBJ_SUBSYSTEM                       1
+#define HPI_OBJ_ADAPTER                         2
+#define HPI_OBJ_OSTREAM                         3
+#define HPI_OBJ_ISTREAM                         4
+#define HPI_OBJ_MIXER                           5
+#define HPI_OBJ_NODE                            6
+#define HPI_OBJ_CONTROL                         7
+#define HPI_OBJ_NVMEMORY                        8
+#define HPI_OBJ_GPIO                            9
+#define HPI_OBJ_WATCHDOG                        10
+#define HPI_OBJ_CLOCK                           11
+#define HPI_OBJ_PROFILE                         12
+#define HPI_OBJ_CONTROLEX                       13
+#define HPI_OBJ_ASYNCEVENT                      14
+
+#define HPI_OBJ_MAXINDEX                        14
+
+/******************************************* methods/functions */
+
+#define HPI_OBJ_FUNCTION_SPACING        0x100
+#define HPI_MAKE_INDEX(obj, index) (obj * HPI_OBJ_FUNCTION_SPACING + index)
+#define HPI_EXTRACT_INDEX(fn) (fn & 0xff)
+
+/* SUB-SYSTEM */
+#define HPI_SUBSYS_OPEN                 HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 1)
+#define HPI_SUBSYS_GET_VERSION          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 2)
+#define HPI_SUBSYS_GET_INFO             HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 3)
+#define HPI_SUBSYS_FIND_ADAPTERS        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 4)
+#define HPI_SUBSYS_CREATE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 5)
+#define HPI_SUBSYS_CLOSE                HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 6)
+#define HPI_SUBSYS_DELETE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 7)
+#define HPI_SUBSYS_DRIVER_LOAD          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 8)
+#define HPI_SUBSYS_DRIVER_UNLOAD        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 9)
+#define HPI_SUBSYS_READ_PORT_8          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 10)
+#define HPI_SUBSYS_WRITE_PORT_8         HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 11)
+#define HPI_SUBSYS_GET_NUM_ADAPTERS     HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 12)
+#define HPI_SUBSYS_GET_ADAPTER          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 13)
+#define HPI_SUBSYS_SET_NETWORK_INTERFACE HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 14)
+#define HPI_SUBSYS_FUNCTION_COUNT 14
+/* ADAPTER */
+#define HPI_ADAPTER_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 1)
+#define HPI_ADAPTER_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 2)
+#define HPI_ADAPTER_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 3)
+#define HPI_ADAPTER_GET_ASSERT          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 4)
+#define HPI_ADAPTER_TEST_ASSERT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 5)
+#define HPI_ADAPTER_SET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 6)
+#define HPI_ADAPTER_GET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 7)
+#define HPI_ADAPTER_ENABLE_CAPABILITY   HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 8)
+#define HPI_ADAPTER_SELFTEST            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 9)
+#define HPI_ADAPTER_FIND_OBJECT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 10)
+#define HPI_ADAPTER_QUERY_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 11)
+#define HPI_ADAPTER_START_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 12)
+#define HPI_ADAPTER_PROGRAM_FLASH       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 13)
+#define HPI_ADAPTER_SET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 14)
+#define HPI_ADAPTER_GET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 15)
+#define HPI_ADAPTER_ENUM_PROPERTY       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 16)
+#define HPI_ADAPTER_MODULE_INFO         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 17)
+#define HPI_ADAPTER_DEBUG_READ          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 18)
+#define HPI_ADAPTER_FUNCTION_COUNT 18
+/* OUTPUT STREAM */
+#define HPI_OSTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 1)
+#define HPI_OSTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 2)
+#define HPI_OSTREAM_WRITE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 3)
+#define HPI_OSTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 4)
+#define HPI_OSTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 5)
+#define HPI_OSTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 6)
+#define HPI_OSTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 7)
+#define HPI_OSTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 8)
+#define HPI_OSTREAM_DATA                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 9)
+#define HPI_OSTREAM_SET_VELOCITY        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 10)
+#define HPI_OSTREAM_SET_PUNCHINOUT      HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 11)
+#define HPI_OSTREAM_SINEGEN             HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 12)
+#define HPI_OSTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 13)
+#define HPI_OSTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 14)
+#define HPI_OSTREAM_ANC_READ            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 15)
+#define HPI_OSTREAM_SET_TIMESCALE       HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 16)
+#define HPI_OSTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 17)
+#define HPI_OSTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 18)
+#define HPI_OSTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 19)
+#define HPI_OSTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 20)
+#define HPI_OSTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 21)
+#define HPI_OSTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 22)
+#define HPI_OSTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 23)
+#define HPI_OSTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 24)
+#define HPI_OSTREAM_FUNCTION_COUNT              24
+/* INPUT STREAM */
+#define HPI_ISTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 1)
+#define HPI_ISTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 2)
+#define HPI_ISTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 3)
+#define HPI_ISTREAM_READ                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 4)
+#define HPI_ISTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 5)
+#define HPI_ISTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 6)
+#define HPI_ISTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 7)
+#define HPI_ISTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 8)
+#define HPI_ISTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 9)
+#define HPI_ISTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 10)
+#define HPI_ISTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 11)
+#define HPI_ISTREAM_ANC_WRITE           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 12)
+#define HPI_ISTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 13)
+#define HPI_ISTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 14)
+#define HPI_ISTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 15)
+#define HPI_ISTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 16)
+#define HPI_ISTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 17)
+#define HPI_ISTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 18)
+#define HPI_ISTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 19)
+#define HPI_ISTREAM_FUNCTION_COUNT              19
+/* MIXER */
+/* NOTE:
+   GET_NODE_INFO, SET_CONNECTION, GET_CONNECTIONS are not currently used */
+#define HPI_MIXER_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 1)
+#define HPI_MIXER_CLOSE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 2)
+#define HPI_MIXER_GET_INFO              HPI_MAKE_INDEX(HPI_OBJ_MIXER, 3)
+#define HPI_MIXER_GET_NODE_INFO         HPI_MAKE_INDEX(HPI_OBJ_MIXER, 4)
+#define HPI_MIXER_GET_CONTROL           HPI_MAKE_INDEX(HPI_OBJ_MIXER, 5)
+#define HPI_MIXER_SET_CONNECTION        HPI_MAKE_INDEX(HPI_OBJ_MIXER, 6)
+#define HPI_MIXER_GET_CONNECTIONS       HPI_MAKE_INDEX(HPI_OBJ_MIXER, 7)
+#define HPI_MIXER_GET_CONTROL_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 8)
+#define HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 9)
+#define HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES HPI_MAKE_INDEX(HPI_OBJ_MIXER, 10)
+#define HPI_MIXER_STORE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 11)
+#define HPI_MIXER_FUNCTION_COUNT        11
+/* MIXER CONTROLS */
+#define HPI_CONTROL_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 1)
+#define HPI_CONTROL_GET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 2)
+#define HPI_CONTROL_SET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 3)
+#define HPI_CONTROL_FUNCTION_COUNT 3
+/* NONVOL MEMORY */
+#define HPI_NVMEMORY_OPEN               HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 1)
+#define HPI_NVMEMORY_READ_BYTE          HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 2)
+#define HPI_NVMEMORY_WRITE_BYTE         HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 3)
+#define HPI_NVMEMORY_FUNCTION_COUNT 3
+/* GPIO */
+#define HPI_GPIO_OPEN                   HPI_MAKE_INDEX(HPI_OBJ_GPIO, 1)
+#define HPI_GPIO_READ_BIT               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 2)
+#define HPI_GPIO_WRITE_BIT              HPI_MAKE_INDEX(HPI_OBJ_GPIO, 3)
+#define HPI_GPIO_READ_ALL               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 4)
+#define HPI_GPIO_WRITE_STATUS           HPI_MAKE_INDEX(HPI_OBJ_GPIO, 5)
+#define HPI_GPIO_FUNCTION_COUNT 5
+/* ASYNC EVENT */
+#define HPI_ASYNCEVENT_OPEN             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 1)
+#define HPI_ASYNCEVENT_CLOSE            HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 2)
+#define HPI_ASYNCEVENT_WAIT             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 3)
+#define HPI_ASYNCEVENT_GETCOUNT         HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 4)
+#define HPI_ASYNCEVENT_GET              HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 5)
+#define HPI_ASYNCEVENT_SENDEVENTS       HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 6)
+#define HPI_ASYNCEVENT_FUNCTION_COUNT 6
+/* WATCH-DOG */
+#define HPI_WATCHDOG_OPEN               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 1)
+#define HPI_WATCHDOG_SET_TIME           HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 2)
+#define HPI_WATCHDOG_PING               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 3)
+/* CLOCK */
+#define HPI_CLOCK_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 1)
+#define HPI_CLOCK_SET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 2)
+#define HPI_CLOCK_GET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 3)
+/* PROFILE */
+#define HPI_PROFILE_OPEN_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 1)
+#define HPI_PROFILE_START_ALL           HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 2)
+#define HPI_PROFILE_STOP_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 3)
+#define HPI_PROFILE_GET                 HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 4)
+#define HPI_PROFILE_GET_IDLECOUNT       HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 5)
+#define HPI_PROFILE_GET_NAME            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 6)
+#define HPI_PROFILE_GET_UTILIZATION     HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 7)
+#define HPI_PROFILE_FUNCTION_COUNT 7
+/* ////////////////////////////////////////////////////////////////////// */
+/* PRIVATE ATTRIBUTES */
+
+/* ////////////////////////////////////////////////////////////////////// */
+/* STRUCTURES */
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(push, 1)
+#endif
+
+/** PCI bus resource */
+struct hpi_pci {
+       u32 __iomem *ap_mem_base[HPI_MAX_ADAPTER_MEM_SPACES];
+       struct pci_dev *p_os_data;
+
+#ifndef HPI64BIT               /* keep structure size constant */
+       u32 padding[HPI_MAX_ADAPTER_MEM_SPACES + 1];
+#endif
+       u16 vendor_id;
+       u16 device_id;
+       u16 subsys_vendor_id;
+       u16 subsys_device_id;
+       u16 bus_number;
+       u16 device_number;
+       u32 interrupt;
+};
+
+struct hpi_resource {
+       union {
+               const struct hpi_pci *pci;
+               const char *net_if;
+       } r;
+#ifndef HPI64BIT               /* keep structure size constant */
+       u32 pad_to64;
+#endif
+       u16 bus_type;           /* HPI_BUS_PNPISA, _PCI, _USB etc */
+       u16 padding;
+
+};
+
+/** Format info used inside struct hpi_message
+    Not the same as public API struct hpi_format */
+struct hpi_msg_format {
+       u32 sample_rate;
+                               /**< 11025, 32000, 44100 ... */
+       u32 bit_rate;         /**< for MPEG */
+       u32 attributes;
+                               /**< Stereo/JointStereo/Mono */
+       u16 channels;         /**< 1,2..., (or ancillary mode or idle bit */
+       u16 format; /**< HPI_FORMAT_PCM16, _MPEG etc. see \ref HPI_FORMATS. */
+};
+
+/**  Buffer+format structure.
+        Must be kept 7 * 32 bits to match public struct hpi_datastruct */
+struct hpi_msg_data {
+       struct hpi_msg_format format;
+       u8 *pb_data;
+#ifndef HPI64BIT
+       u32 padding;
+#endif
+       u32 data_size;
+};
+
+/** struct hpi_datastructure used up to 3.04 driver */
+struct hpi_data_legacy32 {
+       struct hpi_format format;
+       u32 pb_data;
+       u32 data_size;
+};
+
+#ifdef HPI64BIT
+/* Compatibility version of struct hpi_data*/
+struct hpi_data_compat32 {
+       struct hpi_msg_format format;
+       u32 pb_data;
+       u32 padding;
+       u32 data_size;
+};
+#endif
+
+struct hpi_buffer {
+  /** placehoder for backward compatability (see dwBufferSize) */
+       struct hpi_msg_format reserved;
+       u32 command;    /**< HPI_BUFFER_CMD_xxx*/
+       u32 pci_address; /**< PCI physical address of buffer for DSP DMA */
+       u32 buffer_size; /**< must line up with data_size of HPI_DATA*/
+};
+
+/*/////////////////////////////////////////////////////////////////////////// */
+/* This is used for background buffer bus mastering stream buffers.           */
+struct hpi_hostbuffer_status {
+       u32 samples_processed;
+       u32 auxiliary_data_available;
+       u32 stream_state;
+       /* DSP index in to the host bus master buffer. */
+       u32 dSP_index;
+       /* Host index in to the host bus master buffer. */
+       u32 host_index;
+       u32 size_in_bytes;
+};
+
+struct hpi_streamid {
+       u16 object_type;
+                   /**< Type of object, HPI_OBJ_OSTREAM or HPI_OBJ_ISTREAM. */
+       u16 stream_index; /**< outstream or instream index. */
+};
+
+struct hpi_punchinout {
+       u32 punch_in_sample;
+       u32 punch_out_sample;
+};
+
+struct hpi_subsys_msg {
+       struct hpi_resource resource;
+};
+
+struct hpi_subsys_res {
+       u32 version;
+       u32 data;               /* used to return extended version */
+       u16 num_adapters;       /* number of adapters */
+       u16 adapter_index;
+       u16 aw_adapter_list[HPI_MAX_ADAPTERS];
+};
+
+struct hpi_adapter_msg {
+       u32 adapter_mode;       /* adapter mode */
+       u16 assert_id;          /* assert number for "test assert" call
+                                  object_index for find object call
+                                  query_or_set for hpi_adapter_set_mode_ex() */
+       u16 object_type;        /* for adapter find object call */
+};
+
+union hpi_adapterx_msg {
+       struct hpi_adapter_msg adapter;
+       struct {
+               u32 offset;
+       } query_flash;
+       struct {
+               u32 offset;
+               u32 length;
+               u32 key;
+       } start_flash;
+       struct {
+               u32 checksum;
+               u16 sequence;
+               u16 length;
+               u16 offset; /**< offset from start of msg to data */
+               u16 unused;
+       } program_flash;
+       struct {
+               u16 property;
+               u16 parameter1;
+               u16 parameter2;
+       } property_set;
+       struct {
+               u16 index;
+               u16 what;
+               u16 property_index;
+       } property_enum;
+       struct {
+               u16 index;
+       } module_info;
+       struct {
+               u32 dsp_address;
+               u32 count_bytes;
+       } debug_read;
+};
+
+struct hpi_adapter_res {
+       u32 serial_number;
+       u16 adapter_type;
+       u16 adapter_index;      /* is this needed? also used for dsp_index */
+       u16 num_instreams;
+       u16 num_outstreams;
+       u16 num_mixers;
+       u16 version;
+       u8 sz_adapter_assert[HPI_STRING_LEN];
+};
+
+union hpi_adapterx_res {
+       struct hpi_adapter_res adapter;
+       struct {
+               u32 checksum;
+               u32 length;
+               u32 version;
+       } query_flash;
+       struct {
+               u16 sequence;
+       } program_flash;
+       struct {
+               u16 parameter1;
+               u16 parameter2;
+       } property_get;
+};
+
+struct hpi_stream_msg {
+       union {
+               struct hpi_msg_data data;
+               struct hpi_data_legacy32 data32;
+               u16 velocity;
+               struct hpi_punchinout pio;
+               u32 time_scale;
+               struct hpi_buffer buffer;
+               struct hpi_streamid stream;
+       } u;
+};
+
+struct hpi_stream_res {
+       union {
+               struct {
+                       /* size of hardware buffer */
+                       u32 buffer_size;
+                       /* OutStream - data to play,
+                          InStream - data recorded */
+                       u32 data_available;
+                       /* OutStream - samples played,
+                          InStream - samples recorded */
+                       u32 samples_transferred;
+                       /* Adapter - OutStream - data to play,
+                          InStream - data recorded */
+                       u32 auxiliary_data_available;
+                       u16 state;      /* HPI_STATE_PLAYING, _STATE_STOPPED */
+                       u16 padding;
+               } stream_info;
+               struct {
+                       u32 buffer_size;
+                       u32 data_available;
+                       u32 samples_transfered;
+                       u16 state;
+                       u16 outstream_index;
+                       u16 instream_index;
+                       u16 padding;
+                       u32 auxiliary_data_available;
+               } legacy_stream_info;
+               struct {
+                       /* bitmap of grouped OutStreams */
+                       u32 outstream_group_map;
+                       /* bitmap of grouped InStreams */
+                       u32 instream_group_map;
+               } group_info;
+               struct {
+                       /* pointer to the buffer */
+                       u8 *p_buffer;
+                       /* pointer to the hostbuffer status */
+                       struct hpi_hostbuffer_status *p_status;
+               } hostbuffer_info;
+       } u;
+};
+
+struct hpi_mixer_msg {
+       u16 control_index;
+       u16 control_type;       /* = HPI_CONTROL_METER _VOLUME etc */
+       u16 padding1;           /* maintain alignment of subsequent fields */
+       u16 node_type1;         /* = HPI_SOURCENODE_LINEIN etc */
+       u16 node_index1;        /* = 0..N */
+       u16 node_type2;
+       u16 node_index2;
+       u16 padding2;           /* round to 4 bytes */
+};
+
+struct hpi_mixer_res {
+       u16 src_node_type;      /* = HPI_SOURCENODE_LINEIN etc */
+       u16 src_node_index;     /* = 0..N */
+       u16 dst_node_type;
+       u16 dst_node_index;
+       /* Also controlType for MixerGetControlByIndex */
+       u16 control_index;
+       /* may indicate which DSP the control is located on */
+       u16 dsp_index;
+};
+
+union hpi_mixerx_msg {
+       struct {
+               u16 starting_index;
+               u16 flags;
+               u32 length_in_bytes;    /* length in bytes of p_data */
+               u32 p_data;     /* pointer to a data array */
+       } gcabi;
+       struct {
+               u16 command;
+               u16 index;
+       } store;                /* for HPI_MIXER_STORE message */
+};
+
+union hpi_mixerx_res {
+       struct {
+               u32 bytes_returned;     /* size of items returned */
+               u32 p_data;     /* pointer to data array */
+               u16 more_to_do; /* indicates if there is more to do */
+       } gcabi;
+};
+
+struct hpi_control_msg {
+       u16 attribute;          /* control attribute or property */
+       u16 saved_index;
+       u32 param1;             /* generic parameter 1 */
+       u32 param2;             /* generic parameter 2 */
+       short an_log_value[HPI_MAX_CHANNELS];
+};
+
+struct hpi_control_union_msg {
+       u16 attribute;          /* control attribute or property */
+       u16 saved_index;        /* only used in ctrl save/restore */
+       union {
+               struct {
+                       u32 param1;     /* generic parameter 1 */
+                       u32 param2;     /* generic parameter 2 */
+                       short an_log_value[HPI_MAX_CHANNELS];
+               } old;
+               union {
+                       u32 frequency;
+                       u32 gain;
+                       u32 band;
+                       u32 deemphasis;
+                       u32 program;
+                       struct {
+                               u32 mode;
+                               u32 value;
+                       } mode;
+               } tuner;
+       } u;
+};
+
+struct hpi_control_res {
+       /* Could make union. dwParam, anLogValue never used in same response */
+       u32 param1;
+       u32 param2;
+       short an_log_value[HPI_MAX_CHANNELS];
+};
+
+union hpi_control_union_res {
+       struct {
+               u32 param1;
+               u32 param2;
+               short an_log_value[HPI_MAX_CHANNELS];
+       } old;
+       union {
+               u32 band;
+               u32 frequency;
+               u32 gain;
+               u32 level;
+               u32 deemphasis;
+               struct {
+                       u32 data[2];
+                       u32 bLER;
+               } rds;
+       } tuner;
+       struct {
+               char sz_data[8];
+               u32 remaining_chars;
+       } chars8;
+       char c_data12[12];
+};
+
+/* HPI_CONTROLX_STRUCTURES */
+
+/* Message */
+
+/** Used for all HMI variables where max length <= 8 bytes
+*/
+struct hpi_controlx_msg_cobranet_data {
+       u32 hmi_address;
+       u32 byte_count;
+       u32 data[2];
+};
+
+/** Used for string data, and for packet bridge
+*/
+struct hpi_controlx_msg_cobranet_bigdata {
+       u32 hmi_address;
+       u32 byte_count;
+       u8 *pb_data;
+#ifndef HPI64BIT
+       u32 padding;
+#endif
+};
+
+/** Used for PADS control reading of string fields.
+*/
+struct hpi_controlx_msg_pad_data {
+       u32 field;
+       u32 byte_count;
+       u8 *pb_data;
+#ifndef HPI64BIT
+       u32 padding;
+#endif
+};
+
+/** Used for generic data
+*/
+
+struct hpi_controlx_msg_generic {
+       u32 param1;
+       u32 param2;
+};
+
+struct hpi_controlx_msg {
+       u16 attribute;          /* control attribute or property */
+       u16 saved_index;
+       union {
+               struct hpi_controlx_msg_cobranet_data cobranet_data;
+               struct hpi_controlx_msg_cobranet_bigdata cobranet_bigdata;
+               struct hpi_controlx_msg_generic generic;
+               struct hpi_controlx_msg_pad_data pad_data;
+               /*struct param_value universal_value; */
+               /* nothing extra to send for status read */
+       } u;
+};
+
+/* Response */
+/**
+*/
+struct hpi_controlx_res_cobranet_data {
+       u32 byte_count;
+       u32 data[2];
+};
+
+struct hpi_controlx_res_cobranet_bigdata {
+       u32 byte_count;
+};
+
+struct hpi_controlx_res_cobranet_status {
+       u32 status;
+       u32 readable_size;
+       u32 writeable_size;
+};
+
+struct hpi_controlx_res_generic {
+       u32 param1;
+       u32 param2;
+};
+
+struct hpi_controlx_res {
+       union {
+               struct hpi_controlx_res_cobranet_bigdata cobranet_bigdata;
+               struct hpi_controlx_res_cobranet_data cobranet_data;
+               struct hpi_controlx_res_cobranet_status cobranet_status;
+               struct hpi_controlx_res_generic generic;
+               /*struct param_info universal_info; */
+               /*struct param_value universal_value; */
+       } u;
+};
+
+struct hpi_nvmemory_msg {
+       u16 address;
+       u16 data;
+};
+
+struct hpi_nvmemory_res {
+       u16 size_in_bytes;
+       u16 data;
+};
+
+struct hpi_gpio_msg {
+       u16 bit_index;
+       u16 bit_data;
+};
+
+struct hpi_gpio_res {
+       u16 number_input_bits;
+       u16 number_output_bits;
+       u16 bit_data[4];
+};
+
+struct hpi_async_msg {
+       u32 events;
+       u16 maximum_events;
+       u16 padding;
+};
+
+struct hpi_async_res {
+       union {
+               struct {
+                       u16 count;
+               } count;
+               struct {
+                       u32 events;
+                       u16 number_returned;
+                       u16 padding;
+               } get;
+               struct hpi_async_event event;
+       } u;
+};
+
+struct hpi_watchdog_msg {
+       u32 time_ms;
+};
+
+struct hpi_watchdog_res {
+       u32 time_ms;
+};
+
+struct hpi_clock_msg {
+       u16 hours;
+       u16 minutes;
+       u16 seconds;
+       u16 milli_seconds;
+};
+
+struct hpi_clock_res {
+       u16 size_in_bytes;
+       u16 hours;
+       u16 minutes;
+       u16 seconds;
+       u16 milli_seconds;
+       u16 padding;
+};
+
+struct hpi_profile_msg {
+       u16 bin_index;
+       u16 padding;
+};
+
+struct hpi_profile_res_open {
+       u16 max_profiles;
+};
+
+struct hpi_profile_res_time {
+       u32 micro_seconds;
+       u32 call_count;
+       u32 max_micro_seconds;
+       u32 min_micro_seconds;
+       u16 seconds;
+};
+
+struct hpi_profile_res_name {
+       u8 sz_name[32];
+};
+
+struct hpi_profile_res {
+       union {
+               struct hpi_profile_res_open o;
+               struct hpi_profile_res_time t;
+               struct hpi_profile_res_name n;
+       } u;
+};
+
+struct hpi_message_header {
+       u16 size;               /* total size in bytes */
+       u8 type;                /* HPI_TYPE_MESSAGE  */
+       u8 version;             /* message version */
+       u16 object;             /* HPI_OBJ_* */
+       u16 function;           /* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
+       u16 adapter_index;      /* the adapter index */
+       u16 obj_index;          /* */
+};
+
+struct hpi_message {
+       /* following fields must match HPI_MESSAGE_HEADER */
+       u16 size;               /* total size in bytes */
+       u8 type;                /* HPI_TYPE_MESSAGE  */
+       u8 version;             /* message version */
+       u16 object;             /* HPI_OBJ_* */
+       u16 function;           /* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
+       u16 adapter_index;      /* the adapter index */
+       u16 obj_index;          /*  */
+       union {
+               struct hpi_subsys_msg s;
+               struct hpi_adapter_msg a;
+               union hpi_adapterx_msg ax;
+               struct hpi_stream_msg d;
+               struct hpi_mixer_msg m;
+               union hpi_mixerx_msg mx;        /* extended mixer; */
+               struct hpi_control_msg c;       /* mixer control; */
+               /* identical to struct hpi_control_msg,
+                  but field naming is improved */
+               struct hpi_control_union_msg cu;
+               struct hpi_controlx_msg cx;     /* extended mixer control; */
+               struct hpi_nvmemory_msg n;
+               struct hpi_gpio_msg l;  /* digital i/o */
+               struct hpi_watchdog_msg w;
+               struct hpi_clock_msg t; /* dsp time */
+               struct hpi_profile_msg p;
+               struct hpi_async_msg as;
+               char fixed_size[32];
+       } u;
+};
+
+#define HPI_MESSAGE_SIZE_BY_OBJECT { \
+       sizeof(struct hpi_message_header) ,   /* default, no object type 0 */ \
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_subsys_msg),\
+       sizeof(struct hpi_message_header) + sizeof(union hpi_adapterx_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_mixer_msg),\
+       sizeof(struct hpi_message_header) ,   /* no node message */ \
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_control_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_nvmemory_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_gpio_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_watchdog_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_clock_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_profile_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_controlx_msg),\
+       sizeof(struct hpi_message_header) + sizeof(struct hpi_async_msg) \
+}
+
+struct hpi_response_header {
+       u16 size;
+       u8 type;                /* HPI_TYPE_RESPONSE  */
+       u8 version;             /* response version */
+       u16 object;             /* HPI_OBJ_* */
+       u16 function;           /* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
+       u16 error;              /* HPI_ERROR_xxx */
+       u16 specific_error;     /* adapter specific error */
+};
+
+struct hpi_response {
+/* following fields must match HPI_RESPONSE_HEADER */
+       u16 size;
+       u8 type;                /* HPI_TYPE_RESPONSE  */
+       u8 version;             /* response version */
+       u16 object;             /* HPI_OBJ_* */
+       u16 function;           /* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
+       u16 error;              /* HPI_ERROR_xxx */
+       u16 specific_error;     /* adapter specific error */
+       union {
+               struct hpi_subsys_res s;
+               struct hpi_adapter_res a;
+               union hpi_adapterx_res ax;
+               struct hpi_stream_res d;
+               struct hpi_mixer_res m;
+               union hpi_mixerx_res mx;        /* extended mixer; */
+               struct hpi_control_res c;       /* mixer control; */
+               /* identical to hpi_control_res, but field naming is improved */
+               union hpi_control_union_res cu;
+               struct hpi_controlx_res cx;     /* extended mixer control; */
+               struct hpi_nvmemory_res n;
+               struct hpi_gpio_res l;  /* digital i/o */
+               struct hpi_watchdog_res w;
+               struct hpi_clock_res t; /* dsp time */
+               struct hpi_profile_res p;
+               struct hpi_async_res as;
+               u8 bytes[52];
+       } u;
+};
+
+#define HPI_RESPONSE_SIZE_BY_OBJECT { \
+       sizeof(struct hpi_response_header) ,/* default, no object type 0 */ \
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_subsys_res),\
+       sizeof(struct hpi_response_header) + sizeof(union  hpi_adapterx_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_mixer_res),\
+       sizeof(struct hpi_response_header) , /* no node response */ \
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_control_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_nvmemory_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_gpio_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_watchdog_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_clock_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_profile_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_controlx_res),\
+       sizeof(struct hpi_response_header) + sizeof(struct hpi_async_res) \
+}
+
+/*********************** version 1 message/response *****************************/
+#define HPINET_ETHERNET_DATA_SIZE (1500)
+#define HPINET_IP_HDR_SIZE (20)
+#define HPINET_IP_DATA_SIZE (HPINET_ETHERNET_DATA_SIZE - HPINET_IP_HDR_SIZE)
+#define HPINET_UDP_HDR_SIZE (8)
+#define HPINET_UDP_DATA_SIZE (HPINET_IP_DATA_SIZE - HPINET_UDP_HDR_SIZE)
+#define HPINET_ASI_HDR_SIZE (2)
+#define HPINET_ASI_DATA_SIZE (HPINET_UDP_DATA_SIZE - HPINET_ASI_HDR_SIZE)
+
+#define HPI_MAX_PAYLOAD_SIZE (HPINET_ASI_DATA_SIZE - 2)
+
+/* New style message/response, but still V0 compatible */
+struct hpi_msg_adapter_get_info {
+       struct hpi_message_header h;
+};
+
+struct hpi_res_adapter_get_info {
+       struct hpi_response_header h;   /*v0 */
+       struct hpi_adapter_res p;
+};
+
+/* padding is so these are same size as v0 hpi_message */
+struct hpi_msg_adapter_query_flash {
+       struct hpi_message_header h;
+       u32 offset;
+       u8 pad_to_version0_size[sizeof(struct hpi_message) -    /* V0 res */
+               sizeof(struct hpi_message_header) - 1 * sizeof(u32)];
+};
+
+/* padding is so these are same size as v0 hpi_response */
+struct hpi_res_adapter_query_flash {
+       struct hpi_response_header h;
+       u32 checksum;
+       u32 length;
+       u32 version;
+       u8 pad_to_version0_size[sizeof(struct hpi_response) -   /* V0 res */
+               sizeof(struct hpi_response_header) - 3 * sizeof(u32)];
+};
+
+struct hpi_msg_adapter_start_flash {
+       struct hpi_message_header h;
+       u32 offset;
+       u32 length;
+       u32 key;
+       u8 pad_to_version0_size[sizeof(struct hpi_message) -    /* V0 res */
+               sizeof(struct hpi_message_header) - 3 * sizeof(u32)];
+};
+
+struct hpi_res_adapter_start_flash {
+       struct hpi_response_header h;
+       u8 pad_to_version0_size[sizeof(struct hpi_response) -   /* V0 res */
+               sizeof(struct hpi_response_header)];
+};
+
+struct hpi_msg_adapter_program_flash_payload {
+       u32 checksum;
+       u16 sequence;
+       u16 length;
+       u16 offset; /**< offset from start of msg to data */
+       u16 unused;
+       /* ensure sizeof(header + payload) == sizeof(hpi_message_V0)
+          because old firmware expects data after message of this size */
+       u8 pad_to_version0_size[sizeof(struct hpi_message) -    /* V0 message */
+               sizeof(struct hpi_message_header) - sizeof(u32) -
+               4 * sizeof(u16)];
+};
+
+struct hpi_msg_adapter_program_flash {
+       struct hpi_message_header h;
+       struct hpi_msg_adapter_program_flash_payload p;
+       u32 data[256];
+};
+
+struct hpi_res_adapter_program_flash {
+       struct hpi_response_header h;
+       u16 sequence;
+       u8 pad_to_version0_size[sizeof(struct hpi_response) -   /* V0 res */
+               sizeof(struct hpi_response_header) - sizeof(u16)];
+};
+
+#if 1
+#define hpi_message_header_v1 hpi_message_header
+#define hpi_response_header_v1 hpi_response_header
+#else
+/* V1 headers in Addition to v0 headers */
+struct hpi_message_header_v1 {
+       struct hpi_message_header h0;
+/* struct {
+} h1; */
+};
+
+struct hpi_response_header_v1 {
+       struct hpi_response_header h0;
+       struct {
+               u16 adapter_index;      /* the adapter index */
+               u16 obj_index;  /* object index */
+       } h1;
+};
+#endif
+
+/* STRV HPI Packet */
+struct hpi_msg_strv {
+       struct hpi_message_header h;
+       struct hpi_entity strv;
+};
+
+struct hpi_res_strv {
+       struct hpi_response_header h;
+       struct hpi_entity strv;
+};
+#define MIN_STRV_PACKET_SIZE sizeof(struct hpi_res_strv)
+
+struct hpi_msg_payload_v0 {
+       struct hpi_message_header h;
+       union {
+               struct hpi_subsys_msg s;
+               struct hpi_adapter_msg a;
+               union hpi_adapterx_msg ax;
+               struct hpi_stream_msg d;
+               struct hpi_mixer_msg m;
+               union hpi_mixerx_msg mx;
+               struct hpi_control_msg c;
+               struct hpi_control_union_msg cu;
+               struct hpi_controlx_msg cx;
+               struct hpi_nvmemory_msg n;
+               struct hpi_gpio_msg l;
+               struct hpi_watchdog_msg w;
+               struct hpi_clock_msg t;
+               struct hpi_profile_msg p;
+               struct hpi_async_msg as;
+       } u;
+};
+
+struct hpi_res_payload_v0 {
+       struct hpi_response_header h;
+       union {
+               struct hpi_subsys_res s;
+               struct hpi_adapter_res a;
+               union hpi_adapterx_res ax;
+               struct hpi_stream_res d;
+               struct hpi_mixer_res m;
+               union hpi_mixerx_res mx;
+               struct hpi_control_res c;
+               union hpi_control_union_res cu;
+               struct hpi_controlx_res cx;
+               struct hpi_nvmemory_res n;
+               struct hpi_gpio_res l;
+               struct hpi_watchdog_res w;
+               struct hpi_clock_res t;
+               struct hpi_profile_res p;
+               struct hpi_async_res as;
+       } u;
+};
+
+union hpi_message_buffer_v1 {
+       struct hpi_message m0;  /* version 0 */
+       struct hpi_message_header_v1 h;
+       unsigned char buf[HPI_MAX_PAYLOAD_SIZE];
+};
+
+union hpi_response_buffer_v1 {
+       struct hpi_response r0; /* version 0 */
+       struct hpi_response_header_v1 h;
+       unsigned char buf[HPI_MAX_PAYLOAD_SIZE];
+};
+
+compile_time_assert((sizeof(union hpi_message_buffer_v1) <=
+               HPI_MAX_PAYLOAD_SIZE), message_buffer_ok);
+compile_time_assert((sizeof(union hpi_response_buffer_v1) <=
+               HPI_MAX_PAYLOAD_SIZE), response_buffer_ok);
+
+/*////////////////////////////////////////////////////////////////////////// */
+/* declarations for compact control calls  */
+struct hpi_control_defn {
+       u8 type;
+       u8 channels;
+       u8 src_node_type;
+       u8 src_node_index;
+       u8 dest_node_type;
+       u8 dest_node_index;
+};
+
+/*////////////////////////////////////////////////////////////////////////// */
+/* declarations for control caching (internal to HPI<->DSP interaction)      */
+
+/** A compact representation of (part of) a controls state.
+Used for efficient transfer of the control state
+between DSP and host or across a network
+*/
+struct hpi_control_cache_info {
+       /** one of HPI_CONTROL_* */
+       u8 control_type;
+       /** The total size of cached information in 32-bit words. */
+       u8 size_in32bit_words;
+       /** The original index of the control on the DSP */
+       u16 control_index;
+};
+
+struct hpi_control_cache_single {
+       struct hpi_control_cache_info i;
+       union {
+               struct {        /* volume */
+                       u16 an_log[2];
+               } v;
+               struct {        /* peak meter */
+                       u16 an_log_peak[2];
+                       u16 an_logRMS[2];
+               } p;
+               struct {        /* channel mode */
+                       u16 mode;
+               } m;
+               struct {        /* multiplexer */
+                       u16 source_node_type;
+                       u16 source_node_index;
+               } x;
+               struct {        /* level/trim */
+                       u16 an_log[2];
+               } l;
+               struct {        /* tuner - partial caching.
+                                  some attributes go to the DSP. */
+                       u32 freq_ink_hz;
+                       u16 band;
+                       u16 level;
+               } t;
+               struct {        /* AESEBU rx status */
+                       u32 error_status;
+                       u32 source;
+               } aes3rx;
+               struct {        /* AESEBU tx */
+                       u32 format;
+               } aes3tx;
+               struct {        /* tone detector */
+                       u16 state;
+               } tone;
+               struct {        /* silence detector */
+                       u32 state;
+                       u32 count;
+               } silence;
+               struct {        /* sample clock */
+                       u16 source;
+                       u16 source_index;
+                       u32 sample_rate;
+               } clk;
+               struct {        /* microphone control */
+                       u16 state;
+               } phantom_power;
+               struct {        /* generic control */
+                       u32 dw1;
+                       u32 dw2;
+               } g;
+       } u;
+};
+
+struct hpi_control_cache_pad {
+       struct hpi_control_cache_info i;
+       u32 field_valid_flags;
+       u8 c_channel[8];
+       u8 c_artist[40];
+       u8 c_title[40];
+       u8 c_comment[200];
+       u32 pTY;
+       u32 pI;
+       u32 traffic_supported;
+       u32 traffic_anouncement;
+};
+
+/*/////////////////////////////////////////////////////////////////////////// */
+/* declarations for 2^N sized FIFO buffer (internal to HPI<->DSP interaction) */
+struct hpi_fifo_buffer {
+       u32 size;
+       u32 dSP_index;
+       u32 host_index;
+};
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(pop)
+#endif
+
+/* skip host side function declarations for DSP
+   compile and documentation extraction */
+
+char hpi_handle_object(const u32 handle);
+
+void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
+       u16 *pw_object_index);
+
+u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
+       const u16 object_index);
+
+/*////////////////////////////////////////////////////////////////////////// */
+
+/* main HPI entry point */
+hpi_handler_func hpi_send_recv;
+
+/* UDP message */
+void hpi_send_recvUDP(struct hpi_message *phm, struct hpi_response *phr,
+       const unsigned int timeout);
+
+/* used in PnP OS/driver */
+u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
+       const struct hpi_resource *p_resource, u16 *pw_adapter_index);
+
+u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index);
+
+u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u8 **pp_buffer,
+       struct hpi_hostbuffer_status **pp_status);
+
+u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u8 **pp_buffer,
+       struct hpi_hostbuffer_status **pp_status);
+
+u16 hpi_adapter_restart(u16 adapter_index);
+
+/*
+The following 3 functions were last declared in header files for
+driver 3.10. HPI_ControlQuery() used to be the recommended way
+of getting a volume range. Declared here for binary asihpi32.dll
+compatibility.
+*/
+
+void hpi_format_to_msg(struct hpi_msg_format *pMF,
+       const struct hpi_format *pF);
+void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR);
+
+/*////////////////////////////////////////////////////////////////////////// */
+/* declarations for individual HPI entry points */
+hpi_handler_func HPI_1000;
+hpi_handler_func HPI_6000;
+hpi_handler_func HPI_6205;
+hpi_handler_func HPI_COMMON;
+
+#endif                         /* _HPI_INTERNAL_H_ */
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
new file mode 100644 (file)
index 0000000..565102c
--- /dev/null
@@ -0,0 +1,643 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+\file hpicmn.c
+
+ Common functions used by hpixxxx.c modules
+
+(C) Copyright AudioScience Inc. 1998-2003
+*******************************************************************************/
+#define SOURCEFILE_NAME "hpicmn.c"
+
+#include "hpi_internal.h"
+#include "hpidebug.h"
+#include "hpicmn.h"
+
+struct hpi_adapters_list {
+       struct hpios_spinlock list_lock;
+       struct hpi_adapter_obj adapter[HPI_MAX_ADAPTERS];
+       u16 gw_num_adapters;
+};
+
+static struct hpi_adapters_list adapters;
+
+/**
+* Given an HPI Message that was sent out and a response that was received,
+* validate that the response has the correct fields filled in,
+* i.e ObjectType, Function etc
+**/
+u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr)
+{
+       u16 error = 0;
+
+       if ((phr->type != HPI_TYPE_RESPONSE)
+               || (phr->object != phm->object)
+               || (phr->function != phm->function))
+               error = HPI_ERROR_INVALID_RESPONSE;
+
+       return error;
+}
+
+u16 hpi_add_adapter(struct hpi_adapter_obj *pao)
+{
+       u16 retval = 0;
+       /*HPI_ASSERT(pao->wAdapterType); */
+
+       hpios_alistlock_lock(&adapters);
+
+       if (pao->index >= HPI_MAX_ADAPTERS) {
+               retval = HPI_ERROR_BAD_ADAPTER_NUMBER;
+               goto unlock;
+       }
+
+       if (adapters.adapter[pao->index].adapter_type) {
+               {
+                       retval = HPI_DUPLICATE_ADAPTER_NUMBER;
+                       goto unlock;
+               }
+       }
+       adapters.adapter[pao->index] = *pao;
+       hpios_dsplock_init(&adapters.adapter[pao->index]);
+       adapters.gw_num_adapters++;
+
+unlock:
+       hpios_alistlock_un_lock(&adapters);
+       return retval;
+}
+
+void hpi_delete_adapter(struct hpi_adapter_obj *pao)
+{
+       memset(pao, 0, sizeof(struct hpi_adapter_obj));
+
+       hpios_alistlock_lock(&adapters);
+       adapters.gw_num_adapters--;     /* dec the number of adapters */
+       hpios_alistlock_un_lock(&adapters);
+}
+
+/**
+* FindAdapter returns a pointer to the struct hpi_adapter_obj with
+* index wAdapterIndex in an HPI_ADAPTERS_LIST structure.
+*
+*/
+struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)
+{
+       struct hpi_adapter_obj *pao = NULL;
+
+       if (adapter_index >= HPI_MAX_ADAPTERS) {
+               HPI_DEBUG_LOG(VERBOSE, "find_adapter invalid index %d ",
+                       adapter_index);
+               return NULL;
+       }
+
+       pao = &adapters.adapter[adapter_index];
+       if (pao->adapter_type != 0) {
+               /*
+                  HPI_DEBUG_LOG(VERBOSE, "Found adapter index %d\n",
+                  wAdapterIndex);
+                */
+               return pao;
+       } else {
+               /*
+                  HPI_DEBUG_LOG(VERBOSE, "No adapter index %d\n",
+                  wAdapterIndex);
+                */
+               return NULL;
+       }
+}
+
+/**
+*
+* wipe an HPI_ADAPTERS_LIST structure.
+*
+**/
+static void wipe_adapter_list(void
+       )
+{
+       memset(&adapters, 0, sizeof(adapters));
+}
+
+/**
+* SubSysGetAdapters fills awAdapterList in an struct hpi_response structure
+* with all adapters in the given HPI_ADAPTERS_LIST.
+*
+*/
+static void subsys_get_adapters(struct hpi_response *phr)
+{
+       /* fill in the response adapter array with the position */
+       /* identified by the adapter number/index of the adapters in */
+       /* this HPI */
+       /* i.e. if we have an A120 with it's jumper set to */
+       /* Adapter Number 2 then put an Adapter type A120 in the */
+       /* array in position 1 */
+       /* NOTE: AdapterNumber is 1..N, Index is 0..N-1 */
+
+       /* input:  NONE */
+       /* output: wNumAdapters */
+       /*                 awAdapter[] */
+       /* */
+
+       short i;
+       struct hpi_adapter_obj *pao = NULL;
+
+       HPI_DEBUG_LOG(VERBOSE, "subsys_get_adapters\n");
+
+       /* for each adapter, place it's type in the position of the array */
+       /* corresponding to it's adapter number */
+       for (i = 0; i < adapters.gw_num_adapters; i++) {
+               pao = &adapters.adapter[i];
+               if (phr->u.s.aw_adapter_list[pao->index] != 0) {
+                       phr->error = HPI_DUPLICATE_ADAPTER_NUMBER;
+                       phr->specific_error = pao->index;
+                       return;
+               }
+               phr->u.s.aw_adapter_list[pao->index] = pao->adapter_type;
+       }
+
+       phr->u.s.num_adapters = adapters.gw_num_adapters;
+       phr->error = 0; /* the function completed OK; */
+}
+
+static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
+{
+       unsigned int i;
+       int cached = 0;
+       if (!pC)
+               return 0;
+       if ((!pC->init) && (pC->p_cache != NULL) && (pC->control_count)
+               && (pC->cache_size_in_bytes)
+               ) {
+               u32 *p_master_cache;
+               pC->init = 1;
+
+               p_master_cache = (u32 *)pC->p_cache;
+               HPI_DEBUG_LOG(VERBOSE, "check %d controls\n",
+                       pC->control_count);
+               for (i = 0; i < pC->control_count; i++) {
+                       struct hpi_control_cache_info *info =
+                               (struct hpi_control_cache_info *)
+                               p_master_cache;
+
+                       if (info->control_type) {
+                               pC->p_info[i] = info;
+                               cached++;
+                       } else
+                               pC->p_info[i] = NULL;
+
+                       if (info->size_in32bit_words)
+                               p_master_cache += info->size_in32bit_words;
+                       else
+                               p_master_cache +=
+                                       sizeof(struct
+                                       hpi_control_cache_single) /
+                                       sizeof(u32);
+
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "cached %d, pinfo %p index %d type %d\n",
+                               cached, pC->p_info[i], info->control_index,
+                               info->control_type);
+               }
+               /*
+                  We didn't find anything to cache, so try again later !
+                */
+               if (!cached)
+                       pC->init = 0;
+       }
+       return pC->init;
+}
+
+/** Find a control.
+*/
+static short find_control(struct hpi_message *phm,
+       struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI,
+       u16 *pw_control_index)
+{
+       *pw_control_index = phm->obj_index;
+
+       if (!control_cache_alloc_check(p_cache)) {
+               HPI_DEBUG_LOG(VERBOSE,
+                       "control_cache_alloc_check() failed. adap%d ci%d\n",
+                       phm->adapter_index, *pw_control_index);
+               return 0;
+       }
+
+       *pI = p_cache->p_info[*pw_control_index];
+       if (!*pI) {
+               HPI_DEBUG_LOG(VERBOSE, "uncached adap %d, control %d\n",
+                       phm->adapter_index, *pw_control_index);
+               return 0;
+       } else {
+               HPI_DEBUG_LOG(VERBOSE, "find_control() type %d\n",
+                       (*pI)->control_type);
+       }
+       return 1;
+}
+
+/** Used by the kernel driver to figure out if a buffer needs mapping.
+ */
+short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
+       struct hpi_message *phm, void **p, unsigned int *pN)
+{
+       *pN = 0;
+       *p = NULL;
+       if ((phm->function == HPI_CONTROL_GET_STATE)
+               && (phm->object == HPI_OBJ_CONTROLEX)
+               ) {
+               u16 control_index;
+               struct hpi_control_cache_info *pI;
+
+               if (!find_control(phm, p_cache, &pI, &control_index))
+                       return 0;
+       }
+       return 0;
+}
+
+/* allow unified treatment of several string fields within struct */
+#define HPICMN_PAD_OFS_AND_SIZE(m)  {\
+       offsetof(struct hpi_control_cache_pad, m), \
+       sizeof(((struct hpi_control_cache_pad *)(NULL))->m) }
+
+struct pad_ofs_size {
+       unsigned int offset;
+       unsigned int field_size;
+};
+
+static struct pad_ofs_size pad_desc[] = {
+       HPICMN_PAD_OFS_AND_SIZE(c_channel),     /* HPI_PAD_CHANNEL_NAME */
+       HPICMN_PAD_OFS_AND_SIZE(c_artist),      /* HPI_PAD_ARTIST */
+       HPICMN_PAD_OFS_AND_SIZE(c_title),       /* HPI_PAD_TITLE */
+       HPICMN_PAD_OFS_AND_SIZE(c_comment),     /* HPI_PAD_COMMENT */
+};
+
+/** CheckControlCache checks the cache and fills the struct hpi_response
+ * accordingly. It returns one if a cache hit occurred, zero otherwise.
+ */
+short hpi_check_control_cache(struct hpi_control_cache *p_cache,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       short found = 1;
+       u16 control_index;
+       struct hpi_control_cache_info *pI;
+       struct hpi_control_cache_single *pC;
+       struct hpi_control_cache_pad *p_pad;
+
+       if (!find_control(phm, p_cache, &pI, &control_index))
+               return 0;
+
+       phr->error = 0;
+
+       /* pC is the default cached control strucure. May be cast to
+          something else in the following switch statement.
+        */
+       pC = (struct hpi_control_cache_single *)pI;
+       p_pad = (struct hpi_control_cache_pad *)pI;
+
+       switch (pI->control_type) {
+
+       case HPI_CONTROL_METER:
+               if (phm->u.c.attribute == HPI_METER_PEAK) {
+                       phr->u.c.an_log_value[0] = pC->u.p.an_log_peak[0];
+                       phr->u.c.an_log_value[1] = pC->u.p.an_log_peak[1];
+               } else if (phm->u.c.attribute == HPI_METER_RMS) {
+                       phr->u.c.an_log_value[0] = pC->u.p.an_logRMS[0];
+                       phr->u.c.an_log_value[1] = pC->u.p.an_logRMS[1];
+               } else
+                       found = 0;
+               break;
+       case HPI_CONTROL_VOLUME:
+               if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
+                       phr->u.c.an_log_value[0] = pC->u.v.an_log[0];
+                       phr->u.c.an_log_value[1] = pC->u.v.an_log[1];
+               } else
+                       found = 0;
+               break;
+       case HPI_CONTROL_MULTIPLEXER:
+               if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
+                       phr->u.c.param1 = pC->u.x.source_node_type;
+                       phr->u.c.param2 = pC->u.x.source_node_index;
+               } else {
+                       found = 0;
+               }
+               break;
+       case HPI_CONTROL_CHANNEL_MODE:
+               if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
+                       phr->u.c.param1 = pC->u.m.mode;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_LEVEL:
+               if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
+                       phr->u.c.an_log_value[0] = pC->u.l.an_log[0];
+                       phr->u.c.an_log_value[1] = pC->u.l.an_log[1];
+               } else
+                       found = 0;
+               break;
+       case HPI_CONTROL_TUNER:
+               {
+                       struct hpi_control_cache_single *pCT =
+                               (struct hpi_control_cache_single *)pI;
+                       if (phm->u.c.attribute == HPI_TUNER_FREQ)
+                               phr->u.c.param1 = pCT->u.t.freq_ink_hz;
+                       else if (phm->u.c.attribute == HPI_TUNER_BAND)
+                               phr->u.c.param1 = pCT->u.t.band;
+                       else if ((phm->u.c.attribute == HPI_TUNER_LEVEL)
+                               && (phm->u.c.param1 ==
+                                       HPI_TUNER_LEVEL_AVERAGE))
+                               phr->u.c.param1 = pCT->u.t.level;
+                       else
+                               found = 0;
+               }
+               break;
+       case HPI_CONTROL_AESEBU_RECEIVER:
+               if (phm->u.c.attribute == HPI_AESEBURX_ERRORSTATUS)
+                       phr->u.c.param1 = pC->u.aes3rx.error_status;
+               else if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
+                       phr->u.c.param1 = pC->u.aes3rx.source;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_AESEBU_TRANSMITTER:
+               if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
+                       phr->u.c.param1 = pC->u.aes3tx.format;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_TONEDETECTOR:
+               if (phm->u.c.attribute == HPI_TONEDETECTOR_STATE)
+                       phr->u.c.param1 = pC->u.tone.state;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_SILENCEDETECTOR:
+               if (phm->u.c.attribute == HPI_SILENCEDETECTOR_STATE) {
+                       phr->u.c.param1 = pC->u.silence.state;
+                       phr->u.c.param2 = pC->u.silence.count;
+               } else
+                       found = 0;
+               break;
+       case HPI_CONTROL_MICROPHONE:
+               if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
+                       phr->u.c.param1 = pC->u.phantom_power.state;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_SAMPLECLOCK:
+               if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
+                       phr->u.c.param1 = pC->u.clk.source;
+               else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX) {
+                       if (pC->u.clk.source_index ==
+                               HPI_ERROR_ILLEGAL_CACHE_VALUE) {
+                               phr->u.c.param1 = 0;
+                               phr->error = HPI_ERROR_INVALID_OPERATION;
+                       } else
+                               phr->u.c.param1 = pC->u.clk.source_index;
+               } else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SAMPLERATE)
+                       phr->u.c.param1 = pC->u.clk.sample_rate;
+               else
+                       found = 0;
+               break;
+       case HPI_CONTROL_PAD:
+
+               if (!(p_pad->field_valid_flags & (1 <<
+                                       HPI_CTL_ATTR_INDEX(phm->u.c.
+                                               attribute)))) {
+                       phr->error = HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
+                       break;
+               }
+
+               if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID)
+                       phr->u.c.param1 = p_pad->pI;
+               else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE)
+                       phr->u.c.param1 = p_pad->pTY;
+               else {
+                       unsigned int index =
+                               HPI_CTL_ATTR_INDEX(phm->u.c.attribute) - 1;
+                       unsigned int offset = phm->u.c.param1;
+                       unsigned int pad_string_len, field_size;
+                       char *pad_string;
+                       unsigned int tocopy;
+
+                       HPI_DEBUG_LOG(VERBOSE, "PADS HPI_PADS_ %d\n",
+                               phm->u.c.attribute);
+
+                       if (index > ARRAY_SIZE(pad_desc) - 1) {
+                               phr->error =
+                                       HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
+                               break;
+                       }
+
+                       pad_string = ((char *)p_pad) + pad_desc[index].offset;
+                       field_size = pad_desc[index].field_size;
+                       /* Ensure null terminator */
+                       pad_string[field_size - 1] = 0;
+
+                       pad_string_len = strlen(pad_string) + 1;
+
+                       if (offset > pad_string_len) {
+                               phr->error = HPI_ERROR_INVALID_CONTROL_VALUE;
+                               break;
+                       }
+
+                       tocopy = pad_string_len - offset;
+                       if (tocopy > sizeof(phr->u.cu.chars8.sz_data))
+                               tocopy = sizeof(phr->u.cu.chars8.sz_data);
+
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "PADS memcpy(%d), offset %d \n", tocopy,
+                               offset);
+                       memcpy(phr->u.cu.chars8.sz_data, &pad_string[offset],
+                               tocopy);
+
+                       phr->u.cu.chars8.remaining_chars =
+                               pad_string_len - offset - tocopy;
+               }
+               break;
+       default:
+               found = 0;
+               break;
+       }
+
+       if (found)
+               HPI_DEBUG_LOG(VERBOSE,
+                       "cached adap %d, ctl %d, type %d, attr %d\n",
+                       phm->adapter_index, pI->control_index,
+                       pI->control_type, phm->u.c.attribute);
+       else
+               HPI_DEBUG_LOG(VERBOSE,
+                       "uncached adap %d, ctl %d, ctl type %d\n",
+                       phm->adapter_index, pI->control_index,
+                       pI->control_type);
+
+       if (found)
+               phr->size =
+                       sizeof(struct hpi_response_header) +
+                       sizeof(struct hpi_control_res);
+
+       return found;
+}
+
+/** Updates the cache with Set values.
+
+Only update if no error.
+Volume and Level return the limited values in the response, so use these
+Multiplexer does so use sent values
+*/
+void hpi_sync_control_cache(struct hpi_control_cache *p_cache,
+       struct hpi_message *phm, struct hpi_response *phr)
+{
+       u16 control_index;
+       struct hpi_control_cache_single *pC;
+       struct hpi_control_cache_info *pI;
+
+       if (!find_control(phm, p_cache, &pI, &control_index))
+               return;
+
+       /* pC is the default cached control strucure.
+          May be cast to something else in the following switch statement.
+        */
+       pC = (struct hpi_control_cache_single *)pI;
+
+       switch (pI->control_type) {
+       case HPI_CONTROL_VOLUME:
+               if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
+                       pC->u.v.an_log[0] = phr->u.c.an_log_value[0];
+                       pC->u.v.an_log[1] = phr->u.c.an_log_value[1];
+               }
+               break;
+       case HPI_CONTROL_MULTIPLEXER:
+               /* mux does not return its setting on Set command. */
+               if (phr->error)
+                       return;
+               if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
+                       pC->u.x.source_node_type = (u16)phm->u.c.param1;
+                       pC->u.x.source_node_index = (u16)phm->u.c.param2;
+               }
+               break;
+       case HPI_CONTROL_CHANNEL_MODE:
+               /* mode does not return its setting on Set command. */
+               if (phr->error)
+                       return;
+               if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
+                       pC->u.m.mode = (u16)phm->u.c.param1;
+               break;
+       case HPI_CONTROL_LEVEL:
+               if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
+                       pC->u.v.an_log[0] = phr->u.c.an_log_value[0];
+                       pC->u.v.an_log[1] = phr->u.c.an_log_value[1];
+               }
+               break;
+       case HPI_CONTROL_MICROPHONE:
+               if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
+                       pC->u.phantom_power.state = (u16)phm->u.c.param1;
+               break;
+       case HPI_CONTROL_AESEBU_TRANSMITTER:
+               if (phr->error)
+                       return;
+               if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
+                       pC->u.aes3tx.format = phm->u.c.param1;
+               break;
+       case HPI_CONTROL_AESEBU_RECEIVER:
+               if (phr->error)
+                       return;
+               if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
+                       pC->u.aes3rx.source = phm->u.c.param1;
+               break;
+       case HPI_CONTROL_SAMPLECLOCK:
+               if (phr->error)
+                       return;
+               if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
+                       pC->u.clk.source = (u16)phm->u.c.param1;
+               else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX)
+                       pC->u.clk.source_index = (u16)phm->u.c.param1;
+               else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SAMPLERATE)
+                       pC->u.clk.sample_rate = phm->u.c.param1;
+               break;
+       default:
+               break;
+       }
+}
+
+struct hpi_control_cache *hpi_alloc_control_cache(const u32
+       number_of_controls, const u32 size_in_bytes,
+       struct hpi_control_cache_info *pDSP_control_buffer)
+{
+       struct hpi_control_cache *p_cache =
+               kmalloc(sizeof(*p_cache), GFP_KERNEL);
+       p_cache->cache_size_in_bytes = size_in_bytes;
+       p_cache->control_count = number_of_controls;
+       p_cache->p_cache =
+               (struct hpi_control_cache_single *)pDSP_control_buffer;
+       p_cache->init = 0;
+       p_cache->p_info =
+               kmalloc(sizeof(*p_cache->p_info) * p_cache->control_count,
+               GFP_KERNEL);
+       return p_cache;
+}
+
+void hpi_free_control_cache(struct hpi_control_cache *p_cache)
+{
+       if ((p_cache->init) && (p_cache->p_info)) {
+               kfree(p_cache->p_info);
+               p_cache->p_info = NULL;
+               p_cache->init = 0;
+               kfree(p_cache);
+       }
+}
+
+static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
+{
+
+       switch (phm->function) {
+       case HPI_SUBSYS_OPEN:
+       case HPI_SUBSYS_CLOSE:
+       case HPI_SUBSYS_DRIVER_UNLOAD:
+               phr->error = 0;
+               break;
+       case HPI_SUBSYS_DRIVER_LOAD:
+               wipe_adapter_list();
+               hpios_alistlock_init(&adapters);
+               phr->error = 0;
+               break;
+       case HPI_SUBSYS_GET_INFO:
+               subsys_get_adapters(phr);
+               break;
+       case HPI_SUBSYS_CREATE_ADAPTER:
+       case HPI_SUBSYS_DELETE_ADAPTER:
+               phr->error = 0;
+               break;
+       default:
+               phr->error = HPI_ERROR_INVALID_FUNC;
+               break;
+       }
+}
+
+void HPI_COMMON(struct hpi_message *phm, struct hpi_response *phr)
+{
+       switch (phm->type) {
+       case HPI_TYPE_MESSAGE:
+               switch (phm->object) {
+               case HPI_OBJ_SUBSYSTEM:
+                       subsys_message(phm, phr);
+                       break;
+               }
+               break;
+
+       default:
+               phr->error = HPI_ERROR_INVALID_TYPE;
+               break;
+       }
+}
diff --git a/sound/pci/asihpi/hpicmn.h b/sound/pci/asihpi/hpicmn.h
new file mode 100644 (file)
index 0000000..6229022
--- /dev/null
@@ -0,0 +1,64 @@
+/**
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+*/
+
+struct hpi_adapter_obj {
+       struct hpi_pci pci;     /* PCI info - bus#,dev#,address etc */
+       u16 adapter_type;       /* ASI6701 etc */
+       u16 index;              /* */
+       u16 open;               /* =1 when adapter open */
+       u16 mixer_open;
+
+       struct hpios_spinlock dsp_lock;
+
+       u16 dsp_crashed;
+       u16 has_control_cache;
+       void *priv;
+};
+
+struct hpi_control_cache {
+       u32 init;            /**< indicates whether the
+                               structures are initialized */
+       u32 control_count;
+       u32 cache_size_in_bytes;
+       struct hpi_control_cache_info
+       **p_info;                /**< pointer to allocated memory of
+                               lookup pointers. */
+       struct hpi_control_cache_single
+       *p_cache;                /**< pointer to DSP's control cache. */
+};
+
+struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index);
+u16 hpi_add_adapter(struct hpi_adapter_obj *pao);
+
+void hpi_delete_adapter(struct hpi_adapter_obj *pao);
+
+short hpi_check_control_cache(struct hpi_control_cache *pC,
+       struct hpi_message *phm, struct hpi_response *phr);
+struct hpi_control_cache *hpi_alloc_control_cache(const u32
+       number_of_controls, const u32 size_in_bytes,
+       struct hpi_control_cache_info
+       *pDSP_control_buffer);
+void hpi_free_control_cache(struct hpi_control_cache *p_cache);
+
+void hpi_sync_control_cache(struct hpi_control_cache *pC,
+       struct hpi_message *phm, struct hpi_response *phr);
+u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr);
+short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
+       struct hpi_message *phm, void **p, unsigned int *pN);
diff --git a/sound/pci/asihpi/hpidebug.c b/sound/pci/asihpi/hpidebug.c
new file mode 100644 (file)
index 0000000..4cd85a4
--- /dev/null
@@ -0,0 +1,225 @@
+/************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Debug macro translation.
+
+************************************************************************/
+
+#include "hpi_internal.h"
+#include "hpidebug.h"
+
+/* Debug level; 0 quiet; 1 informative, 2 debug, 3 verbose debug.  */
+int hpi_debug_level = HPI_DEBUG_LEVEL_DEFAULT;
+
+void hpi_debug_init(void)
+{
+       printk(KERN_INFO "debug start\n");
+}
+
+int hpi_debug_level_set(int level)
+{
+       int old_level;
+
+       old_level = hpi_debug_level;
+       hpi_debug_level = level;
+       return old_level;
+}
+
+int hpi_debug_level_get(void)
+{
+       return hpi_debug_level;
+}
+
+#ifdef HPIOS_DEBUG_PRINT
+/* implies OS has no printf-like function */
+#include <stdarg.h>
+
+void hpi_debug_printf(char *fmt, ...)
+{
+       va_list arglist;
+       char buffer[128];
+
+       va_start(arglist, fmt);
+
+       if (buffer[0])
+               HPIOS_DEBUG_PRINT(buffer);
+       va_end(arglist);
+}
+#endif
+
+struct treenode {
+       void *array;
+       unsigned int num_elements;
+};
+
+#define make_treenode_from_array(nodename, array) \
+static void *tmp_strarray_##nodename[] = array; \
+static struct treenode nodename = { \
+       &tmp_strarray_##nodename, \
+       ARRAY_SIZE(tmp_strarray_##nodename) \
+};
+
+#define get_treenode_elem(node_ptr, idx, type)  \
+       (&(*((type *)(node_ptr)->array)[idx]))
+
+make_treenode_from_array(hpi_control_type_strings, HPI_CONTROL_TYPE_STRINGS)
+
+       make_treenode_from_array(hpi_subsys_strings, HPI_SUBSYS_STRINGS)
+       make_treenode_from_array(hpi_adapter_strings, HPI_ADAPTER_STRINGS)
+       make_treenode_from_array(hpi_istream_strings, HPI_ISTREAM_STRINGS)
+       make_treenode_from_array(hpi_ostream_strings, HPI_OSTREAM_STRINGS)
+       make_treenode_from_array(hpi_mixer_strings, HPI_MIXER_STRINGS)
+       make_treenode_from_array(hpi_node_strings,
+       {
+       "NODE is invalid object"})
+
+       make_treenode_from_array(hpi_control_strings, HPI_CONTROL_STRINGS)
+       make_treenode_from_array(hpi_nvmemory_strings, HPI_OBJ_STRINGS)
+       make_treenode_from_array(hpi_digitalio_strings, HPI_DIGITALIO_STRINGS)
+       make_treenode_from_array(hpi_watchdog_strings, HPI_WATCHDOG_STRINGS)
+       make_treenode_from_array(hpi_clock_strings, HPI_CLOCK_STRINGS)
+       make_treenode_from_array(hpi_profile_strings, HPI_PROFILE_STRINGS)
+       make_treenode_from_array(hpi_asyncevent_strings, HPI_ASYNCEVENT_STRINGS)
+#define HPI_FUNCTION_STRINGS \
+{ \
+  &hpi_subsys_strings,\
+  &hpi_adapter_strings,\
+  &hpi_ostream_strings,\
+  &hpi_istream_strings,\
+  &hpi_mixer_strings,\
+  &hpi_node_strings,\
+  &hpi_control_strings,\
+  &hpi_nvmemory_strings,\
+  &hpi_digitalio_strings,\
+  &hpi_watchdog_strings,\
+  &hpi_clock_strings,\
+  &hpi_profile_strings,\
+  &hpi_control_strings, \
+  &hpi_asyncevent_strings \
+};
+       make_treenode_from_array(hpi_function_strings, HPI_FUNCTION_STRINGS)
+
+       compile_time_assert(HPI_OBJ_MAXINDEX == 14, obj_list_doesnt_match);
+
+static char *hpi_function_string(unsigned int function)
+{
+       unsigned int object;
+       struct treenode *tmp;
+
+       object = function / HPI_OBJ_FUNCTION_SPACING;
+       function = function - object * HPI_OBJ_FUNCTION_SPACING;
+
+       if (object == 0 || object == HPI_OBJ_NODE
+               || object > hpi_function_strings.num_elements)
+               return "invalid object";
+
+       tmp = get_treenode_elem(&hpi_function_strings, object - 1,
+               struct treenode *);
+
+       if (function == 0 || function > tmp->num_elements)
+               return "invalid function";
+
+       return get_treenode_elem(tmp, function - 1, char *);
+}
+
+void hpi_debug_message(struct hpi_message *phm, char *sz_fileline)
+{
+       if (phm) {
+               if ((phm->object <= HPI_OBJ_MAXINDEX) && phm->object) {
+                       u16 index = 0;
+                       u16 attrib = 0;
+                       int is_control = 0;
+
+                       index = phm->obj_index;
+                       switch (phm->object) {
+                       case HPI_OBJ_ADAPTER:
+                       case HPI_OBJ_PROFILE:
+                               break;
+                       case HPI_OBJ_MIXER:
+                               if (phm->function ==
+                                       HPI_MIXER_GET_CONTROL_BY_INDEX)
+                                       index = phm->u.m.control_index;
+                               break;
+                       case HPI_OBJ_OSTREAM:
+                       case HPI_OBJ_ISTREAM:
+                               break;
+
+                       case HPI_OBJ_CONTROLEX:
+                       case HPI_OBJ_CONTROL:
+                               if (phm->version == 1)
+                                       attrib = HPI_CTL_ATTR(UNIVERSAL, 1);
+                               else
+                                       attrib = phm->u.c.attribute;
+                               is_control = 1;
+                               break;
+                       default:
+                               break;
+                       }
+
+                       if (is_control && (attrib & 0xFF00)) {
+                               int control_type = (attrib & 0xFF00) >> 8;
+                               int attr_index = HPI_CTL_ATTR_INDEX(attrib);
+                               /* note the KERN facility level
+                                  is in szFileline already */
+                               printk("%s adapter %d %s "
+                                       "ctrl_index x%04x %s %d\n",
+                                       sz_fileline, phm->adapter_index,
+                                       hpi_function_string(phm->function),
+                                       index,
+                                       get_treenode_elem
+                                       (&hpi_control_type_strings,
+                                               control_type, char *),
+                                       attr_index);
+
+                       } else
+                               printk("%s adapter %d %s "
+                                       "idx x%04x attr x%04x \n",
+                                       sz_fileline, phm->adapter_index,
+                                       hpi_function_string(phm->function),
+                                       index, attrib);
+               } else {
+                       printk("adap=%d, invalid obj=%d, func=0x%x\n",
+                               phm->adapter_index, phm->object,
+                               phm->function);
+               }
+       } else
+               printk(KERN_ERR
+                       "NULL message pointer to hpi_debug_message!\n");
+}
+
+void hpi_debug_data(u16 *pdata, u32 len)
+{
+       u32 i;
+       int j;
+       int k;
+       int lines;
+       int cols = 8;
+
+       lines = (len + cols - 1) / cols;
+       if (lines > 8)
+               lines = 8;
+
+       for (i = 0, j = 0; j < lines; j++) {
+               printk(KERN_DEBUG "%p:", (pdata + i));
+
+               for (k = 0; k < cols && i < len; i++, k++)
+                       printk("%s%04x", k == 0 ? "" : " ", pdata[i]);
+
+               printk("\n");
+       }
+}
diff --git a/sound/pci/asihpi/hpidebug.h b/sound/pci/asihpi/hpidebug.h
new file mode 100644 (file)
index 0000000..44dccad
--- /dev/null
@@ -0,0 +1,385 @@
+/*****************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Debug macros.
+
+*****************************************************************************/
+
+#ifndef _HPIDEBUG_H
+#define _HPIDEBUG_H
+
+#include "hpi_internal.h"
+
+/* Define debugging levels.  */
+enum { HPI_DEBUG_LEVEL_ERROR = 0,      /* always log errors */
+       HPI_DEBUG_LEVEL_WARNING = 1,
+       HPI_DEBUG_LEVEL_NOTICE = 2,
+       HPI_DEBUG_LEVEL_INFO = 3,
+       HPI_DEBUG_LEVEL_DEBUG = 4,
+       HPI_DEBUG_LEVEL_VERBOSE = 5     /* same printk level as DEBUG */
+};
+
+#define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE
+
+/* an OS can define an extra flag string that is appended to
+   the start of each message, eg see hpios_linux.h */
+
+#ifdef SOURCEFILE_NAME
+#define FILE_LINE  SOURCEFILE_NAME ":" __stringify(__LINE__) " "
+#else
+#define FILE_LINE  __FILE__ ":" __stringify(__LINE__) " "
+#endif
+
+#if defined(HPI_DEBUG) && defined(_WINDOWS)
+#define HPI_DEBUGBREAK() debug_break()
+#else
+#define HPI_DEBUGBREAK()
+#endif
+
+#define HPI_DEBUG_ASSERT(expression) \
+       do { \
+               if (!(expression)) {\
+                       printk(KERN_ERR  FILE_LINE\
+                               "ASSERT " __stringify(expression));\
+                       HPI_DEBUGBREAK();\
+               } \
+       } while (0)
+
+#define HPI_DEBUG_LOG(level, ...) \
+       do { \
+               if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
+                       printk(HPI_DEBUG_FLAG_##level \
+                       FILE_LINE  __VA_ARGS__); \
+               } \
+       } while (0)
+
+void hpi_debug_init(void);
+int hpi_debug_level_set(int level);
+int hpi_debug_level_get(void);
+/* needed by Linux driver for dynamic debug level changes */
+extern int hpi_debug_level;
+
+void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);
+
+void hpi_debug_data(u16 *pdata, u32 len);
+
+#define HPI_DEBUG_DATA(pdata, len)                                      \
+       do {                                                            \
+               if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
+                       hpi_debug_data(pdata, len); \
+       } while (0)
+
+#define HPI_DEBUG_MESSAGE(level, phm)                                   \
+       do {                                                            \
+               if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) {         \
+                       hpi_debug_message(phm,HPI_DEBUG_FLAG_##level    \
+                               FILE_LINE __stringify(level));\
+               }                                                       \
+       } while (0)
+
+#define HPI_DEBUG_RESPONSE(phr)                                         \
+       do {                                                            \
+               if ((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && (phr->error))\
+                       HPI_DEBUG_LOG(ERROR, \
+                               "HPI response - error# %d\n", \
+                               phr->error); \
+               else if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
+                       HPI_DEBUG_LOG(VERBOSE, "HPI response OK\n");\
+       } while (0)
+
+#ifndef compile_time_assert
+#define compile_time_assert(cond, msg) \
+    typedef char msg[(cond) ? 1 : -1]
+#endif
+
+         /* check that size is exactly some number */
+#define function_count_check(sym, size) \
+    compile_time_assert((sym##_FUNCTION_COUNT) == (size),\
+           strings_match_defs_##sym)
+
+/* These strings should be generated using a macro which defines
+   the corresponding symbol values.  */
+#define HPI_OBJ_STRINGS \
+{                               \
+  "HPI_OBJ_SUBSYSTEM",        \
+  "HPI_OBJ_ADAPTER",          \
+  "HPI_OBJ_OSTREAM",          \
+  "HPI_OBJ_ISTREAM",          \
+  "HPI_OBJ_MIXER",            \
+  "HPI_OBJ_NODE",             \
+  "HPI_OBJ_CONTROL",          \
+  "HPI_OBJ_NVMEMORY",         \
+  "HPI_OBJ_DIGITALIO",        \
+  "HPI_OBJ_WATCHDOG",         \
+  "HPI_OBJ_CLOCK",            \
+  "HPI_OBJ_PROFILE",          \
+  "HPI_OBJ_CONTROLEX"         \
+}
+
+#define HPI_SUBSYS_STRINGS      \
+{                               \
+  "HPI_SUBSYS_OPEN",          \
+  "HPI_SUBSYS_GET_VERSION",   \
+  "HPI_SUBSYS_GET_INFO",      \
+  "HPI_SUBSYS_FIND_ADAPTERS", \
+  "HPI_SUBSYS_CREATE_ADAPTER",\
+  "HPI_SUBSYS_CLOSE",         \
+  "HPI_SUBSYS_DELETE_ADAPTER", \
+  "HPI_SUBSYS_DRIVER_LOAD", \
+  "HPI_SUBSYS_DRIVER_UNLOAD", \
+  "HPI_SUBSYS_READ_PORT_8",   \
+  "HPI_SUBSYS_WRITE_PORT_8",  \
+  "HPI_SUBSYS_GET_NUM_ADAPTERS",\
+  "HPI_SUBSYS_GET_ADAPTER",   \
+  "HPI_SUBSYS_SET_NETWORK_INTERFACE"\
+}
+function_count_check(HPI_SUBSYS, 14);
+
+#define HPI_ADAPTER_STRINGS     \
+{                               \
+  "HPI_ADAPTER_OPEN",         \
+  "HPI_ADAPTER_CLOSE",        \
+  "HPI_ADAPTER_GET_INFO",     \
+  "HPI_ADAPTER_GET_ASSERT",   \
+  "HPI_ADAPTER_TEST_ASSERT",    \
+  "HPI_ADAPTER_SET_MODE",       \
+  "HPI_ADAPTER_GET_MODE",       \
+  "HPI_ADAPTER_ENABLE_CAPABILITY",\
+  "HPI_ADAPTER_SELFTEST",        \
+  "HPI_ADAPTER_FIND_OBJECT",     \
+  "HPI_ADAPTER_QUERY_FLASH",     \
+  "HPI_ADAPTER_START_FLASH",     \
+  "HPI_ADAPTER_PROGRAM_FLASH",   \
+  "HPI_ADAPTER_SET_PROPERTY",    \
+  "HPI_ADAPTER_GET_PROPERTY",    \
+  "HPI_ADAPTER_ENUM_PROPERTY",    \
+  "HPI_ADAPTER_MODULE_INFO",    \
+  "HPI_ADAPTER_DEBUG_READ"    \
+}
+
+function_count_check(HPI_ADAPTER, 18);
+
+#define HPI_OSTREAM_STRINGS     \
+{                               \
+  "HPI_OSTREAM_OPEN",         \
+  "HPI_OSTREAM_CLOSE",        \
+  "HPI_OSTREAM_WRITE",        \
+  "HPI_OSTREAM_START",        \
+  "HPI_OSTREAM_STOP",         \
+  "HPI_OSTREAM_RESET",                \
+  "HPI_OSTREAM_GET_INFO",     \
+  "HPI_OSTREAM_QUERY_FORMAT", \
+  "HPI_OSTREAM_DATA",         \
+  "HPI_OSTREAM_SET_VELOCITY", \
+  "HPI_OSTREAM_SET_PUNCHINOUT", \
+  "HPI_OSTREAM_SINEGEN",        \
+  "HPI_OSTREAM_ANC_RESET",      \
+  "HPI_OSTREAM_ANC_GET_INFO",   \
+  "HPI_OSTREAM_ANC_READ",       \
+  "HPI_OSTREAM_SET_TIMESCALE",\
+  "HPI_OSTREAM_SET_FORMAT", \
+  "HPI_OSTREAM_HOSTBUFFER_ALLOC", \
+  "HPI_OSTREAM_HOSTBUFFER_FREE", \
+  "HPI_OSTREAM_GROUP_ADD",\
+  "HPI_OSTREAM_GROUP_GETMAP", \
+  "HPI_OSTREAM_GROUP_RESET", \
+  "HPI_OSTREAM_HOSTBUFFER_GET_INFO", \
+  "HPI_OSTREAM_WAIT_START", \
+}
+function_count_check(HPI_OSTREAM, 24);
+
+#define HPI_ISTREAM_STRINGS     \
+{                               \
+  "HPI_ISTREAM_OPEN",         \
+  "HPI_ISTREAM_CLOSE",        \
+  "HPI_ISTREAM_SET_FORMAT",   \
+  "HPI_ISTREAM_READ",         \
+  "HPI_ISTREAM_START",        \
+  "HPI_ISTREAM_STOP",         \
+  "HPI_ISTREAM_RESET",        \
+  "HPI_ISTREAM_GET_INFO",     \
+  "HPI_ISTREAM_QUERY_FORMAT", \
+  "HPI_ISTREAM_ANC_RESET",      \
+  "HPI_ISTREAM_ANC_GET_INFO",   \
+  "HPI_ISTREAM_ANC_WRITE",   \
+  "HPI_ISTREAM_HOSTBUFFER_ALLOC",\
+  "HPI_ISTREAM_HOSTBUFFER_FREE", \
+  "HPI_ISTREAM_GROUP_ADD", \
+  "HPI_ISTREAM_GROUP_GETMAP", \
+  "HPI_ISTREAM_GROUP_RESET", \
+  "HPI_ISTREAM_HOSTBUFFER_GET_INFO", \
+  "HPI_ISTREAM_WAIT_START", \
+}
+function_count_check(HPI_ISTREAM, 19);
+
+#define HPI_MIXER_STRINGS       \
+{                               \
+  "HPI_MIXER_OPEN",           \
+  "HPI_MIXER_CLOSE",          \
+  "HPI_MIXER_GET_INFO",       \
+  "HPI_MIXER_GET_NODE_INFO",  \
+  "HPI_MIXER_GET_CONTROL",    \
+  "HPI_MIXER_SET_CONNECTION", \
+  "HPI_MIXER_GET_CONNECTIONS",        \
+  "HPI_MIXER_GET_CONTROL_BY_INDEX",   \
+  "HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX",     \
+  "HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES",    \
+  "HPI_MIXER_STORE",  \
+}
+function_count_check(HPI_MIXER, 11);
+
+#define HPI_CONTROL_STRINGS     \
+{                               \
+  "HPI_CONTROL_GET_INFO",     \
+  "HPI_CONTROL_GET_STATE",    \
+  "HPI_CONTROL_SET_STATE"     \
+}
+function_count_check(HPI_CONTROL, 3);
+
+#define HPI_NVMEMORY_STRINGS    \
+{                               \
+  "HPI_NVMEMORY_OPEN",        \
+  "HPI_NVMEMORY_READ_BYTE",   \
+  "HPI_NVMEMORY_WRITE_BYTE"   \
+}
+function_count_check(HPI_NVMEMORY, 3);
+
+#define HPI_DIGITALIO_STRINGS   \
+{                               \
+  "HPI_GPIO_OPEN",            \
+  "HPI_GPIO_READ_BIT",        \
+  "HPI_GPIO_WRITE_BIT",       \
+  "HPI_GPIO_READ_ALL",                \
+  "HPI_GPIO_WRITE_STATUS"\
+}
+function_count_check(HPI_GPIO, 5);
+
+#define HPI_WATCHDOG_STRINGS    \
+{                               \
+  "HPI_WATCHDOG_OPEN",        \
+  "HPI_WATCHDOG_SET_TIME",    \
+  "HPI_WATCHDOG_PING"         \
+}
+
+#define HPI_CLOCK_STRINGS       \
+{                               \
+  "HPI_CLOCK_OPEN",           \
+  "HPI_CLOCK_SET_TIME",       \
+  "HPI_CLOCK_GET_TIME"        \
+}
+
+#define HPI_PROFILE_STRINGS     \
+{                               \
+  "HPI_PROFILE_OPEN_ALL",     \
+  "HPI_PROFILE_START_ALL",    \
+  "HPI_PROFILE_STOP_ALL",     \
+  "HPI_PROFILE_GET",          \
+  "HPI_PROFILE_GET_IDLECOUNT",  \
+  "HPI_PROFILE_GET_NAME",       \
+  "HPI_PROFILE_GET_UTILIZATION" \
+}
+function_count_check(HPI_PROFILE, 7);
+
+#define HPI_ASYNCEVENT_STRINGS  \
+{                               \
+  "HPI_ASYNCEVENT_OPEN",\
+  "HPI_ASYNCEVENT_CLOSE  ",\
+  "HPI_ASYNCEVENT_WAIT",\
+  "HPI_ASYNCEVENT_GETCOUNT",\
+  "HPI_ASYNCEVENT_GET",\
+  "HPI_ASYNCEVENT_SENDEVENTS"\
+}
+function_count_check(HPI_ASYNCEVENT, 6);
+
+#define HPI_CONTROL_TYPE_STRINGS \
+{ \
+       "null control", \
+       "HPI_CONTROL_CONNECTION", \
+       "HPI_CONTROL_VOLUME", \
+       "HPI_CONTROL_METER", \
+       "HPI_CONTROL_MUTE", \
+       "HPI_CONTROL_MULTIPLEXER", \
+       "HPI_CONTROL_AESEBU_TRANSMITTER", \
+       "HPI_CONTROL_AESEBU_RECEIVER", \
+       "HPI_CONTROL_LEVEL", \
+       "HPI_CONTROL_TUNER", \
+       "HPI_CONTROL_ONOFFSWITCH", \
+       "HPI_CONTROL_VOX", \
+       "HPI_CONTROL_AES18_TRANSMITTER", \
+       "HPI_CONTROL_AES18_RECEIVER", \
+       "HPI_CONTROL_AES18_BLOCKGENERATOR", \
+       "HPI_CONTROL_CHANNEL_MODE", \
+       "HPI_CONTROL_BITSTREAM", \
+       "HPI_CONTROL_SAMPLECLOCK", \
+       "HPI_CONTROL_MICROPHONE", \
+       "HPI_CONTROL_PARAMETRIC_EQ", \
+       "HPI_CONTROL_COMPANDER", \
+       "HPI_CONTROL_COBRANET", \
+       "HPI_CONTROL_TONE_DETECT", \
+       "HPI_CONTROL_SILENCE_DETECT", \
+       "HPI_CONTROL_PAD", \
+       "HPI_CONTROL_SRC" ,\
+       "HPI_CONTROL_UNIVERSAL" \
+}
+
+compile_time_assert((HPI_CONTROL_LAST_INDEX + 1 == 27),
+       controltype_strings_match_defs);
+
+#define HPI_SOURCENODE_STRINGS \
+{ \
+       "no source", \
+       "HPI_SOURCENODE_OSTREAM", \
+       "HPI_SOURCENODE_LINEIN", \
+       "HPI_SOURCENODE_AESEBU_IN", \
+       "HPI_SOURCENODE_TUNER", \
+       "HPI_SOURCENODE_RF", \
+       "HPI_SOURCENODE_CLOCK_SOURCE", \
+       "HPI_SOURCENODE_RAW_BITSTREAM", \
+       "HPI_SOURCENODE_MICROPHONE", \
+       "HPI_SOURCENODE_COBRANET", \
+       "HPI_SOURCENODE_ANALOG", \
+       "HPI_SOURCENODE_ADAPTER" \
+}
+
+compile_time_assert((HPI_SOURCENODE_LAST_INDEX - HPI_SOURCENODE_BASE + 1) ==
+       (12), sourcenode_strings_match_defs);
+
+#define HPI_DESTNODE_STRINGS \
+{ \
+       "no destination", \
+       "HPI_DESTNODE_ISTREAM", \
+       "HPI_DESTNODE_LINEOUT", \
+       "HPI_DESTNODE_AESEBU_OUT", \
+       "HPI_DESTNODE_RF", \
+       "HPI_DESTNODE_SPEAKER", \
+       "HPI_DESTNODE_COBRANET", \
+       "HPI_DESTNODE_ANALOG" \
+}
+compile_time_assert((HPI_DESTNODE_LAST_INDEX - HPI_DESTNODE_BASE + 1) == (8),
+       destnode_strings_match_defs);
+
+#define HPI_CONTROL_CHANNEL_MODE_STRINGS \
+{ \
+       "XXX HPI_CHANNEL_MODE_ERROR XXX", \
+       "HPI_CHANNEL_MODE_NORMAL", \
+       "HPI_CHANNEL_MODE_SWAP", \
+       "HPI_CHANNEL_MODE_LEFT_ONLY", \
+       "HPI_CHANNEL_MODE_RIGHT_ONLY" \
+}
+
+#endif                         /* _HPIDEBUG_H  */
diff --git a/sound/pci/asihpi/hpidspcd.c b/sound/pci/asihpi/hpidspcd.c
new file mode 100644 (file)
index 0000000..9b10d9a
--- /dev/null
@@ -0,0 +1,172 @@
+/***********************************************************************/
+/*!
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+\file
+Functions for reading DSP code to load into DSP
+
+(Linux only:) If DSPCODE_FIRMWARE_LOADER is defined, code is read using
+hotplug firmware loader from individual dsp code files
+
+If neither of the above is defined, code is read from linked arrays.
+DSPCODE_ARRAY is defined.
+
+HPI_INCLUDE_**** must be defined
+and the appropriate hzz?????.c or hex?????.c linked in
+
+ */
+/***********************************************************************/
+#define SOURCEFILE_NAME "hpidspcd.c"
+#include "hpidspcd.h"
+#include "hpidebug.h"
+
+/**
+ Header structure for binary dsp code file (see asidsp.doc)
+ This structure must match that used in s2bin.c for generation of asidsp.bin
+ */
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(push, 1)
+#endif
+
+struct code_header {
+       u32 size;
+       char type[4];
+       u32 adapter;
+       u32 version;
+       u32 crc;
+};
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(pop)
+#endif
+
+#define HPI_VER_DECIMAL ((int)(HPI_VER_MAJOR(HPI_VER) * 10000 + \
+           HPI_VER_MINOR(HPI_VER) * 100 + HPI_VER_RELEASE(HPI_VER)))
+
+/***********************************************************************/
+#include "linux/pci.h"
+/*-------------------------------------------------------------------*/
+short hpi_dsp_code_open(u32 adapter, struct dsp_code *ps_dsp_code,
+       u32 *pos_error_code)
+{
+       const struct firmware *ps_firmware = ps_dsp_code->ps_firmware;
+       struct code_header header;
+       char fw_name[20];
+       int err;
+
+       sprintf(fw_name, "asihpi/dsp%04x.bin", adapter);
+       HPI_DEBUG_LOG(INFO, "requesting firmware for %s\n", fw_name);
+
+       err = request_firmware(&ps_firmware, fw_name,
+               &ps_dsp_code->ps_dev->dev);
+       if (err != 0) {
+               HPI_DEBUG_LOG(ERROR, "%d, request_firmware failed for  %s\n",
+                       err, fw_name);
+               goto error1;
+       }
+       if (ps_firmware->size < sizeof(header)) {
+               HPI_DEBUG_LOG(ERROR, "header size too small %s\n", fw_name);
+               goto error2;
+       }
+       memcpy(&header, ps_firmware->data, sizeof(header));
+       if (header.adapter != adapter) {
+               HPI_DEBUG_LOG(ERROR, "adapter type incorrect %4x != %4x\n",
+                       header.adapter, adapter);
+               goto error2;
+       }
+       if (header.size != ps_firmware->size) {
+               HPI_DEBUG_LOG(ERROR, "code size wrong  %d != %ld\n",
+                       header.size, (unsigned long)ps_firmware->size);
+               goto error2;
+       }
+
+       if (header.version / 10000 != HPI_VER_DECIMAL / 10000) {
+               HPI_DEBUG_LOG(ERROR,
+                       "firmware major version mismatch "
+                       "DSP image %d != driver %d\n", header.version,
+                       HPI_VER_DECIMAL);
+               goto error2;
+       }
+
+       if (header.version != HPI_VER_DECIMAL) {
+               HPI_DEBUG_LOG(WARNING,
+                       "version mismatch  DSP image %d != driver %d\n",
+                       header.version, HPI_VER_DECIMAL);
+               /* goto error2;  still allow driver to load */
+       }
+
+       HPI_DEBUG_LOG(INFO, "dsp code %s opened\n", fw_name);
+       ps_dsp_code->ps_firmware = ps_firmware;
+       ps_dsp_code->block_length = header.size / sizeof(u32);
+       ps_dsp_code->word_count = sizeof(header) / sizeof(u32);
+       ps_dsp_code->version = header.version;
+       ps_dsp_code->crc = header.crc;
+       return 0;
+
+error2:
+       release_firmware(ps_firmware);
+error1:
+       ps_dsp_code->ps_firmware = NULL;
+       ps_dsp_code->block_length = 0;
+       return HPI_ERROR_DSP_FILE_NOT_FOUND;
+}
+
+/*-------------------------------------------------------------------*/
+void hpi_dsp_code_close(struct dsp_code *ps_dsp_code)
+{
+       if (ps_dsp_code->ps_firmware != NULL) {
+               HPI_DEBUG_LOG(DEBUG, "dsp code closed\n");
+               release_firmware(ps_dsp_code->ps_firmware);
+               ps_dsp_code->ps_firmware = NULL;
+       }
+}
+
+/*-------------------------------------------------------------------*/
+void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code)
+{
+       /* Go back to start of  data, after header */
+       ps_dsp_code->word_count = sizeof(struct code_header) / sizeof(u32);
+}
+
+/*-------------------------------------------------------------------*/
+short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code, u32 *pword)
+{
+       if (ps_dsp_code->word_count + 1 > ps_dsp_code->block_length)
+               return (HPI_ERROR_DSP_FILE_FORMAT);
+
+       *pword = ((u32 *)(ps_dsp_code->ps_firmware->data))[ps_dsp_code->
+               word_count];
+       ps_dsp_code->word_count++;
+       return 0;
+}
+
+/*-------------------------------------------------------------------*/
+short hpi_dsp_code_read_block(size_t words_requested,
+       struct dsp_code *ps_dsp_code, u32 **ppblock)
+{
+       if (ps_dsp_code->word_count + words_requested >
+               ps_dsp_code->block_length)
+               return HPI_ERROR_DSP_FILE_FORMAT;
+
+       *ppblock =
+               ((u32 *)(ps_dsp_code->ps_firmware->data)) +
+               ps_dsp_code->word_count;
+       ps_dsp_code->word_count += words_requested;
+       return 0;
+}
diff --git a/sound/pci/asihpi/hpidspcd.h b/sound/pci/asihpi/hpidspcd.h
new file mode 100644 (file)
index 0000000..d7c2403
--- /dev/null
@@ -0,0 +1,104 @@
+/***********************************************************************/
+/**
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+\file
+Functions for reading DSP code to load into DSP
+
+ hpi_dspcode_defines HPI DSP code loading method
+Define exactly one of these to select how the DSP code is supplied to
+the adapter.
+
+End users writing applications that use the HPI interface do not have to
+use any of the below defines; they are only necessary for building drivers
+
+HPI_DSPCODE_FILE:
+DSP code is supplied as a file that is opened and read from by the driver.
+
+HPI_DSPCODE_FIRMWARE:
+DSP code is read using the hotplug firmware loader module.
+     Only valid when compiling the HPI kernel driver under Linux.
+*/
+/***********************************************************************/
+#ifndef _HPIDSPCD_H_
+#define _HPIDSPCD_H_
+
+#include "hpi_internal.h"
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(push, 1)
+#endif
+
+/** Descriptor for dspcode from firmware loader */
+struct dsp_code {
+       /**  Firmware descriptor */
+       const struct firmware *ps_firmware;
+       struct pci_dev *ps_dev;
+       /** Expected number of words in the whole dsp code,INCL header */
+       long int block_length;
+       /** Number of words read so far */
+       long int word_count;
+       /** Version read from dsp code file */
+       u32 version;
+       /** CRC read from dsp code file */
+       u32 crc;
+};
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(pop)
+#endif
+
+/** Prepare *psDspCode to refer to the requuested adapter.
+ Searches the file, or selects the appropriate linked array
+
+\return 0 for success, or error code if requested code is not available
+*/
+short hpi_dsp_code_open(
+       /** Code identifier, usually adapter family */
+       u32 adapter,
+       /** Pointer to DSP code control structure */
+       struct dsp_code *ps_dsp_code,
+       /** Pointer to dword to receive OS specific error code */
+       u32 *pos_error_code);
+
+/** Close the DSP code file */
+void hpi_dsp_code_close(struct dsp_code *ps_dsp_code);
+
+/** Rewind to the beginning of the DSP code file (for verify) */
+void hpi_dsp_code_rewind(struct dsp_code *ps_dsp_code);
+
+/** Read one word from the dsp code file
+       \return 0 for success, or error code if eof, or block length exceeded
+*/
+short hpi_dsp_code_read_word(struct dsp_code *ps_dsp_code,
+                                     /**< DSP code descriptor */
+       u32 *pword /**< where to store the read word */
+       );
+
+/** Get a block of dsp code into an internal buffer, and provide a pointer to
+that buffer. (If dsp code is already an array in memory, it is referenced,
+not copied.)
+
+\return Error if requested number of words are not available
+*/
+short hpi_dsp_code_read_block(size_t words_requested,
+       struct dsp_code *ps_dsp_code,
+       /* Pointer to store (Pointer to code buffer) */
+       u32 **ppblock);
+
+#endif
diff --git a/sound/pci/asihpi/hpifunc.c b/sound/pci/asihpi/hpifunc.c
new file mode 100644 (file)
index 0000000..eda26b3
--- /dev/null
@@ -0,0 +1,3864 @@
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+
+#include "hpidebug.h"
+
+struct hpi_handle {
+       unsigned int obj_index:12;
+       unsigned int obj_type:4;
+       unsigned int adapter_index:14;
+       unsigned int spare:1;
+       unsigned int read_only:1;
+};
+
+union handle_word {
+       struct hpi_handle h;
+       u32 w;
+};
+
+u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
+       const u16 object_index)
+{
+       union handle_word handle;
+
+       handle.h.adapter_index = adapter_index;
+       handle.h.spare = 0;
+       handle.h.read_only = 0;
+       handle.h.obj_type = c_object;
+       handle.h.obj_index = object_index;
+       return handle.w;
+}
+
+void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
+       u16 *pw_object_index)
+{
+       union handle_word uhandle;
+       uhandle.w = handle;
+
+       if (pw_adapter_index)
+               *pw_adapter_index = (u16)uhandle.h.adapter_index;
+       if (pw_object_index)
+               *pw_object_index = (u16)uhandle.h.obj_index;
+}
+
+char hpi_handle_object(const u32 handle)
+{
+       union handle_word uhandle;
+       uhandle.w = handle;
+       return (char)uhandle.h.obj_type;
+}
+
+#define u32TOINDEX(h, i1) \
+do {\
+       if (h == 0) \
+               return HPI_ERROR_INVALID_OBJ; \
+       else \
+               hpi_handle_to_indexes(h, i1, NULL); \
+} while (0)
+
+#define u32TOINDEXES(h, i1, i2) \
+do {\
+       if (h == 0) \
+               return HPI_ERROR_INVALID_OBJ; \
+       else \
+               hpi_handle_to_indexes(h, i1, i2);\
+} while (0)
+
+void hpi_format_to_msg(struct hpi_msg_format *pMF,
+       const struct hpi_format *pF)
+{
+       pMF->sample_rate = pF->sample_rate;
+       pMF->bit_rate = pF->bit_rate;
+       pMF->attributes = pF->attributes;
+       pMF->channels = pF->channels;
+       pMF->format = pF->format;
+}
+
+static void hpi_msg_to_format(struct hpi_format *pF,
+       struct hpi_msg_format *pMF)
+{
+       pF->sample_rate = pMF->sample_rate;
+       pF->bit_rate = pMF->bit_rate;
+       pF->attributes = pMF->attributes;
+       pF->channels = pMF->channels;
+       pF->format = pMF->format;
+       pF->mode_legacy = 0;
+       pF->unused = 0;
+}
+
+void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
+{
+       pSR->u.legacy_stream_info.auxiliary_data_available =
+               pSR->u.stream_info.auxiliary_data_available;
+       pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
+}
+
+static struct hpi_hsubsys gh_subsys;
+
+struct hpi_hsubsys *hpi_subsys_create(void
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
+
+       {
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+                       HPI_SUBSYS_OPEN);
+               hpi_send_recv(&hm, &hr);
+
+               if (hr.error == 0)
+                       return &gh_subsys;
+
+       }
+       return NULL;
+}
+
+void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_CLOSE);
+       hpi_send_recv(&hm, &hr);
+
+}
+
+u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_GET_VERSION);
+       hpi_send_recv(&hm, &hr);
+       *pversion = hr.u.s.version;
+       return hr.error;
+}
+
+u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 *pversion_ex)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_GET_VERSION);
+       hpi_send_recv(&hm, &hr);
+       *pversion_ex = hr.u.s.data;
+       return hr.error;
+}
+
+u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
+       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_GET_INFO);
+
+       hpi_send_recv(&hm, &hr);
+
+       *pversion = hr.u.s.version;
+       if (list_length > HPI_MAX_ADAPTERS)
+               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
+                       HPI_MAX_ADAPTERS);
+       else
+               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
+       *pw_num_adapters = hr.u.s.num_adapters;
+       return hr.error;
+}
+
+u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
+       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_FIND_ADAPTERS);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (list_length > HPI_MAX_ADAPTERS) {
+               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
+                       HPI_MAX_ADAPTERS * sizeof(u16));
+               memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
+                       (list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
+       } else
+               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
+                       list_length * sizeof(u16));
+       *pw_num_adapters = hr.u.s.num_adapters;
+
+       return hr.error;
+}
+
+u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
+       const struct hpi_resource *p_resource, u16 *pw_adapter_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_CREATE_ADAPTER);
+       hm.u.s.resource = *p_resource;
+
+       hpi_send_recv(&hm, &hr);
+
+       *pw_adapter_index = hr.u.s.adapter_index;
+       return hr.error;
+}
+
+u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_DELETE_ADAPTER);
+       hm.adapter_index = adapter_index;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,
+       int *pn_num_adapters)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_GET_NUM_ADAPTERS);
+       hpi_send_recv(&hm, &hr);
+       *pn_num_adapters = (int)hr.u.s.num_adapters;
+       return hr.error;
+}
+
+u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
+       u32 *padapter_index, u16 *pw_adapter_type)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_GET_ADAPTER);
+       hm.adapter_index = (u16)iterator;
+       hpi_send_recv(&hm, &hr);
+       *padapter_index = (int)hr.u.s.adapter_index;
+       *pw_adapter_type = hr.u.s.aw_adapter_list[0];
+       return hr.error;
+}
+
+u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
+       const char *sz_interface)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_SET_NETWORK_INTERFACE);
+       if (sz_interface == NULL)
+               return HPI_ERROR_INVALID_RESOURCE;
+       hm.u.s.resource.r.net_if = sz_interface;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+
+}
+
+u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_CLOSE);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 adapter_mode)
+{
+       return hpi_adapter_set_mode_ex(ph_subsys, adapter_index, adapter_mode,
+               HPI_ADAPTER_MODE_SET);
+}
+
+u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 adapter_mode, u16 query_or_set)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_SET_MODE);
+       hm.adapter_index = adapter_index;
+       hm.u.a.adapter_mode = adapter_mode;
+       hm.u.a.assert_id = query_or_set;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 *padapter_mode)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_MODE);
+       hm.adapter_index = adapter_index;
+       hpi_send_recv(&hm, &hr);
+       if (padapter_mode)
+               *padapter_mode = hr.u.a.serial_number;
+       return hr.error;
+}
+
+u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams,
+       u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_INFO);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       *pw_adapter_type = hr.u.a.adapter_type;
+       *pw_num_outstreams = hr.u.a.num_outstreams;
+       *pw_num_instreams = hr.u.a.num_instreams;
+       *pw_version = hr.u.a.version;
+       *pserial_number = hr.u.a.serial_number;
+       return hr.error;
+}
+
+u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 module_index, u16 *pw_num_outputs,
+       u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number,
+       u16 *pw_module_type, u32 *ph_module)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_MODULE_INFO);
+       hm.adapter_index = adapter_index;
+       hm.u.ax.module_info.index = module_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       *pw_module_type = hr.u.a.adapter_type;
+       *pw_num_outputs = hr.u.a.num_outstreams;
+       *pw_num_inputs = hr.u.a.num_instreams;
+       *pw_version = hr.u.a.version;
+       *pserial_number = hr.u.a.serial_number;
+       *ph_module = 0;
+
+       return hr.error;
+}
+
+u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *assert_present, char *psz_assert,
+       u16 *pw_line_number)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_ASSERT);
+       hm.adapter_index = adapter_index;
+       hpi_send_recv(&hm, &hr);
+
+       *assert_present = 0;
+
+       if (!hr.error) {
+
+               *pw_line_number = (u16)hr.u.a.serial_number;
+               if (*pw_line_number) {
+
+                       int i;
+                       char *src = (char *)hr.u.a.sz_adapter_assert;
+                       char *dst = psz_assert;
+
+                       *assert_present = 1;
+
+                       for (i = 0; i < HPI_STRING_LEN; i++) {
+                               char c;
+                               c = *src++;
+                               *dst++ = c;
+                               if (c == 0)
+                                       break;
+                       }
+
+               }
+       }
+       return hr.error;
+}
+
+u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *assert_present, char *psz_assert,
+       u32 *pline_number, u16 *pw_assert_on_dsp)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_ASSERT);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       *assert_present = 0;
+
+       if (!hr.error) {
+
+               *pline_number = hr.u.a.serial_number;
+
+               *assert_present = hr.u.a.adapter_type;
+
+               *pw_assert_on_dsp = hr.u.a.adapter_index;
+
+               if (!*assert_present && *pline_number)
+
+                       *assert_present = 1;
+
+               if (*assert_present) {
+
+                       int i;
+                       char *src = (char *)hr.u.a.sz_adapter_assert;
+                       char *dst = psz_assert;
+
+                       for (i = 0; i < HPI_STRING_LEN; i++) {
+                               char c;
+                               c = *src++;
+                               *dst++ = c;
+                               if (c == 0)
+                                       break;
+                       }
+
+               } else {
+                       *psz_assert = 0;
+               }
+       }
+       return hr.error;
+}
+
+u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 assert_id)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_TEST_ASSERT);
+       hm.adapter_index = adapter_index;
+       hm.u.a.assert_id = assert_id;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 capability, u32 key)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_ENABLE_CAPABILITY);
+       hm.adapter_index = adapter_index;
+       hm.u.a.assert_id = capability;
+       hm.u.a.adapter_mode = key;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_SELFTEST);
+       hm.adapter_index = adapter_index;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_DEBUG_READ);
+
+       hr.size = sizeof(hr);
+
+       hm.adapter_index = adapter_index;
+       hm.u.ax.debug_read.dsp_address = dsp_address;
+
+       if (*count_bytes > sizeof(hr.u.bytes))
+               *count_bytes = sizeof(hr.u.bytes);
+
+       hm.u.ax.debug_read.count_bytes = *count_bytes;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (!hr.error) {
+               *count_bytes = hr.size - 12;
+               memcpy(p_buffer, &hr.u.bytes, *count_bytes);
+       } else
+               *count_bytes = 0;
+       return hr.error;
+}
+
+u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 property, u16 parameter1, u16 parameter2)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_SET_PROPERTY);
+       hm.adapter_index = adapter_index;
+       hm.u.ax.property_set.property = property;
+       hm.u.ax.property_set.parameter1 = parameter1;
+       hm.u.ax.property_set.parameter2 = parameter2;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 property, u16 *pw_parameter1,
+       u16 *pw_parameter2)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_PROPERTY);
+       hm.adapter_index = adapter_index;
+       hm.u.ax.property_set.property = property;
+
+       hpi_send_recv(&hm, &hr);
+       if (!hr.error) {
+               if (pw_parameter1)
+                       *pw_parameter1 = hr.u.ax.property_get.parameter1;
+               if (pw_parameter2)
+                       *pw_parameter2 = hr.u.ax.property_get.parameter2;
+       }
+
+       return hr.error;
+}
+
+u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 index, u16 what_to_enumerate,
+       u16 property_index, u32 *psetting)
+{
+       return 0;
+}
+
+u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
+       u32 sample_rate, u32 bit_rate, u32 attributes)
+{
+       u16 error = 0;
+       struct hpi_msg_format fmt;
+
+       switch (channels) {
+       case 1:
+       case 2:
+       case 4:
+       case 6:
+       case 8:
+       case 16:
+               break;
+       default:
+               error = HPI_ERROR_INVALID_CHANNELS;
+               return error;
+       }
+       fmt.channels = channels;
+
+       switch (format) {
+       case HPI_FORMAT_PCM16_SIGNED:
+       case HPI_FORMAT_PCM24_SIGNED:
+       case HPI_FORMAT_PCM32_SIGNED:
+       case HPI_FORMAT_PCM32_FLOAT:
+       case HPI_FORMAT_PCM16_BIGENDIAN:
+       case HPI_FORMAT_PCM8_UNSIGNED:
+       case HPI_FORMAT_MPEG_L1:
+       case HPI_FORMAT_MPEG_L2:
+       case HPI_FORMAT_MPEG_L3:
+       case HPI_FORMAT_DOLBY_AC2:
+       case HPI_FORMAT_AA_TAGIT1_HITS:
+       case HPI_FORMAT_AA_TAGIT1_INSERTS:
+       case HPI_FORMAT_RAW_BITSTREAM:
+       case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
+       case HPI_FORMAT_OEM1:
+       case HPI_FORMAT_OEM2:
+               break;
+       default:
+               error = HPI_ERROR_INVALID_FORMAT;
+               return error;
+       }
+       fmt.format = format;
+
+       if (sample_rate < 8000L) {
+               error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
+               sample_rate = 8000L;
+       }
+       if (sample_rate > 200000L) {
+               error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
+               sample_rate = 200000L;
+       }
+       fmt.sample_rate = sample_rate;
+
+       switch (format) {
+       case HPI_FORMAT_MPEG_L1:
+       case HPI_FORMAT_MPEG_L2:
+       case HPI_FORMAT_MPEG_L3:
+               fmt.bit_rate = bit_rate;
+               break;
+       case HPI_FORMAT_PCM16_SIGNED:
+       case HPI_FORMAT_PCM16_BIGENDIAN:
+               fmt.bit_rate = channels * sample_rate * 2;
+               break;
+       case HPI_FORMAT_PCM32_SIGNED:
+       case HPI_FORMAT_PCM32_FLOAT:
+               fmt.bit_rate = channels * sample_rate * 4;
+               break;
+       case HPI_FORMAT_PCM8_UNSIGNED:
+               fmt.bit_rate = channels * sample_rate;
+               break;
+       default:
+               fmt.bit_rate = 0;
+       }
+
+       switch (format) {
+       case HPI_FORMAT_MPEG_L2:
+               if ((channels == 1)
+                       && (attributes != HPI_MPEG_MODE_DEFAULT)) {
+                       attributes = HPI_MPEG_MODE_DEFAULT;
+                       error = HPI_ERROR_INVALID_FORMAT;
+               } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
+                       attributes = HPI_MPEG_MODE_DEFAULT;
+                       error = HPI_ERROR_INVALID_FORMAT;
+               }
+               fmt.attributes = attributes;
+               break;
+       default:
+               fmt.attributes = attributes;
+       }
+
+       hpi_msg_to_format(p_format, &fmt);
+       return error;
+}
+
+u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
+       u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
+{
+
+       u32 bytes_per_second;
+       u32 size;
+       u16 channels;
+       struct hpi_format *pF = p_format;
+
+       channels = pF->channels;
+
+       switch (pF->format) {
+       case HPI_FORMAT_PCM16_BIGENDIAN:
+       case HPI_FORMAT_PCM16_SIGNED:
+               bytes_per_second = pF->sample_rate * 2L * channels;
+               break;
+       case HPI_FORMAT_PCM24_SIGNED:
+               bytes_per_second = pF->sample_rate * 3L * channels;
+               break;
+       case HPI_FORMAT_PCM32_SIGNED:
+       case HPI_FORMAT_PCM32_FLOAT:
+               bytes_per_second = pF->sample_rate * 4L * channels;
+               break;
+       case HPI_FORMAT_PCM8_UNSIGNED:
+               bytes_per_second = pF->sample_rate * 1L * channels;
+               break;
+       case HPI_FORMAT_MPEG_L1:
+       case HPI_FORMAT_MPEG_L2:
+       case HPI_FORMAT_MPEG_L3:
+               bytes_per_second = pF->bit_rate / 8L;
+               break;
+       case HPI_FORMAT_DOLBY_AC2:
+
+               bytes_per_second = 256000L / 8L;
+               break;
+       default:
+               return HPI_ERROR_INVALID_FORMAT;
+       }
+       size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
+               1000L;
+
+       *recommended_buffer_size =
+               roundup_pow_of_two(((size + 4095L) & ~4095L));
+       return 0;
+}
+
+u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u16 outstream_index, u32 *ph_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_OPEN);
+       hm.adapter_index = adapter_index;
+       hm.obj_index = outstream_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               *ph_outstream =
+                       hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
+                       outstream_index);
+       else
+               *ph_outstream = 0;
+       return hr.error;
+}
+
+u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_HOSTBUFFER_FREE);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_GROUP_RESET);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_CLOSE);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play,
+       u32 *psamples_played, u32 *pauxiliary_data_to_play)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_GET_INFO);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_state)
+               *pw_state = hr.u.d.u.stream_info.state;
+       if (pbuffer_size)
+               *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
+       if (pdata_to_play)
+               *pdata_to_play = hr.u.d.u.stream_info.data_available;
+       if (psamples_played)
+               *psamples_played = hr.u.d.u.stream_info.samples_transferred;
+       if (pauxiliary_data_to_play)
+               *pauxiliary_data_to_play =
+                       hr.u.d.u.stream_info.auxiliary_data_available;
+       return hr.error;
+}
+
+u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, const u8 *pb_data, u32 bytes_to_write,
+       const struct hpi_format *p_format)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_WRITE);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.pb_data = (u8 *)pb_data;
+       hm.u.d.u.data.data_size = bytes_to_write;
+
+       hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_START);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_WAIT_START);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_STOP);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_SINEGEN);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_RESET);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_format *p_format)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_QUERY_FORMAT);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_format *p_format)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_SET_FORMAT);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, short velocity)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_SET_VELOCITY);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.velocity = velocity;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_SET_PUNCHINOUT);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.d.u.pio.punch_in_sample = punch_in_sample;
+       hm.u.d.u.pio.punch_out_sample = punch_out_sample;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u16 mode)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_ANC_RESET);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.format.channels = mode;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 *pframes_available)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_ANC_GET_INFO);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       if (hr.error == 0) {
+               if (pframes_available)
+                       *pframes_available =
+                               hr.u.d.u.stream_info.data_available /
+                               sizeof(struct hpi_anc_frame);
+       }
+       return hr.error;
+}
+
+u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer,
+       u32 anc_frame_buffer_size_in_bytes,
+       u32 number_of_ancillary_frames_to_read)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_ANC_READ);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
+       hm.u.d.u.data.data_size =
+               number_of_ancillary_frames_to_read *
+               sizeof(struct hpi_anc_frame);
+       if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
+               hpi_send_recv(&hm, &hr);
+       else
+               hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
+       return hr.error;
+}
+
+u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 time_scale)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_SET_TIMESCALE);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.d.u.time_scale = time_scale;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 size_in_bytes)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_HOSTBUFFER_ALLOC);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.data_size = size_in_bytes;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u8 **pp_buffer,
+       struct hpi_hostbuffer_status **pp_status)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_HOSTBUFFER_GET_INFO);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0) {
+               if (pp_buffer)
+                       *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
+               if (pp_status)
+                       *pp_status = hr.u.d.u.hostbuffer_info.p_status;
+       }
+       return hr.error;
+}
+
+u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_HOSTBUFFER_FREE);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 h_stream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       u16 adapter;
+       char c_obj_type;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_GROUP_ADD);
+       hr.error = 0;
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       c_obj_type = hpi_handle_object(h_stream);
+       switch (c_obj_type) {
+       case HPI_OBJ_OSTREAM:
+               hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
+               u32TOINDEXES(h_stream, &adapter,
+                       &hm.u.d.u.stream.stream_index);
+               break;
+       case HPI_OBJ_ISTREAM:
+               hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
+               u32TOINDEXES(h_stream, &adapter,
+                       &hm.u.d.u.stream.stream_index);
+               break;
+       default:
+               return HPI_ERROR_INVALID_STREAM;
+       }
+       if (adapter != hm.adapter_index)
+               return HPI_ERROR_NO_INTERADAPTER_GROUPS;
+
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_GROUP_GETMAP);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       if (poutstream_map)
+               *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
+       if (pinstream_map)
+               *pinstream_map = hr.u.d.u.group_info.instream_group_map;
+
+       return hr.error;
+}
+
+u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_outstream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+               HPI_OSTREAM_GROUP_RESET);
+       u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u16 instream_index, u32 *ph_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_OPEN);
+       hm.adapter_index = adapter_index;
+       hm.obj_index = instream_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               *ph_instream =
+                       hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
+                       instream_index);
+       else
+               *ph_instream = 0;
+
+       return hr.error;
+}
+
+u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_HOSTBUFFER_FREE);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_GROUP_RESET);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_CLOSE);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_format *p_format)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_QUERY_FORMAT);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_format *p_format)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_SET_FORMAT);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,
+       u8 *pb_data, u32 bytes_to_read)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_READ);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.data_size = bytes_to_read;
+       hm.u.d.u.data.pb_data = pb_data;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_START);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_WAIT_START);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_STOP);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_RESET);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded,
+       u32 *psamples_recorded, u32 *pauxiliary_data_recorded)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_GET_INFO);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_state)
+               *pw_state = hr.u.d.u.stream_info.state;
+       if (pbuffer_size)
+               *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
+       if (pdata_recorded)
+               *pdata_recorded = hr.u.d.u.stream_info.data_available;
+       if (psamples_recorded)
+               *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
+       if (pauxiliary_data_recorded)
+               *pauxiliary_data_recorded =
+                       hr.u.d.u.stream_info.auxiliary_data_available;
+       return hr.error;
+}
+
+u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment,
+       u16 idle_bit)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_ANC_RESET);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.format.attributes = bytes_per_frame;
+       hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
+       hm.u.d.u.data.format.channels = idle_bit;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 *pframe_space)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_ANC_GET_INFO);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       if (pframe_space)
+               *pframe_space =
+                       (hr.u.d.u.stream_info.buffer_size -
+                       hr.u.d.u.stream_info.data_available) /
+                       sizeof(struct hpi_anc_frame);
+       return hr.error;
+}
+
+u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer,
+       u32 anc_frame_buffer_size_in_bytes,
+       u32 number_of_ancillary_frames_to_write)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_ANC_WRITE);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
+       hm.u.d.u.data.data_size =
+               number_of_ancillary_frames_to_write *
+               sizeof(struct hpi_anc_frame);
+       if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
+               hpi_send_recv(&hm, &hr);
+       else
+               hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
+       return hr.error;
+}
+
+u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 size_in_bytes)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_HOSTBUFFER_ALLOC);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hm.u.d.u.data.data_size = size_in_bytes;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u8 **pp_buffer,
+       struct hpi_hostbuffer_status **pp_status)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_HOSTBUFFER_GET_INFO);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0) {
+               if (pp_buffer)
+                       *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
+               if (pp_status)
+                       *pp_status = hr.u.d.u.hostbuffer_info.p_status;
+       }
+       return hr.error;
+}
+
+u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_HOSTBUFFER_FREE);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 h_stream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       u16 adapter;
+       char c_obj_type;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_GROUP_ADD);
+       hr.error = 0;
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       c_obj_type = hpi_handle_object(h_stream);
+
+       switch (c_obj_type) {
+       case HPI_OBJ_OSTREAM:
+               hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
+               u32TOINDEXES(h_stream, &adapter,
+                       &hm.u.d.u.stream.stream_index);
+               break;
+       case HPI_OBJ_ISTREAM:
+               hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
+               u32TOINDEXES(h_stream, &adapter,
+                       &hm.u.d.u.stream.stream_index);
+               break;
+       default:
+               return HPI_ERROR_INVALID_STREAM;
+       }
+
+       if (adapter != hm.adapter_index)
+               return HPI_ERROR_NO_INTERADAPTER_GROUPS;
+
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream, u32 *poutstream_map, u32 *pinstream_map)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_HOSTBUFFER_FREE);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       if (poutstream_map)
+               *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
+       if (pinstream_map)
+               *pinstream_map = hr.u.d.u.group_info.instream_group_map;
+
+       return hr.error;
+}
+
+u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys,
+       u32 h_instream)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+               HPI_ISTREAM_GROUP_RESET);
+       u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_mixer)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               *ph_mixer =
+                       hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
+                       0);
+       else
+               *ph_mixer = 0;
+       return hr.error;
+}
+
+u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
+       u32TOINDEX(h_mixer, &hm.adapter_index);
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
+       u16 src_node_type, u16 src_node_type_index, u16 dst_node_type,
+       u16 dst_node_type_index, u16 control_type, u32 *ph_control)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
+               HPI_MIXER_GET_CONTROL);
+       u32TOINDEX(h_mixer, &hm.adapter_index);
+       hm.u.m.node_type1 = src_node_type;
+       hm.u.m.node_index1 = src_node_type_index;
+       hm.u.m.node_type2 = dst_node_type;
+       hm.u.m.node_index2 = dst_node_type_index;
+       hm.u.m.control_type = control_type;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               *ph_control =
+                       hpi_indexes_to_handle(HPI_OBJ_CONTROL,
+                       hm.adapter_index, hr.u.m.control_index);
+       else
+               *ph_control = 0;
+       return hr.error;
+}
+
+u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_mixer, u16 control_index, u16 *pw_src_node_type,
+       u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index,
+       u16 *pw_control_type, u32 *ph_control)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
+               HPI_MIXER_GET_CONTROL_BY_INDEX);
+       u32TOINDEX(h_mixer, &hm.adapter_index);
+       hm.u.m.control_index = control_index;
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_src_node_type) {
+               *pw_src_node_type =
+                       hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
+               *pw_src_node_index = hr.u.m.src_node_index;
+               *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
+               *pw_dst_node_index = hr.u.m.dst_node_index;
+       }
+       if (pw_control_type)
+               *pw_control_type = hr.u.m.control_index;
+
+       if (ph_control) {
+               if (hr.error == 0)
+                       *ph_control =
+                               hpi_indexes_to_handle(HPI_OBJ_CONTROL,
+                               hm.adapter_index, control_index);
+               else
+                       *ph_control = 0;
+       }
+       return hr.error;
+}
+
+u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
+       enum HPI_MIXER_STORE_COMMAND command, u16 index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
+       u32TOINDEX(h_mixer, &hm.adapter_index);
+       hm.u.mx.store.command = command;
+       hm.u.mx.store.index = index;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+static
+u16 hpi_control_param_set(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_control, const u16 attrib, const u32 param1,
+       const u32 param2)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = attrib;
+       hm.u.c.param1 = param1;
+       hm.u.c.param2 = param2;
+       hpi_send_recv(&hm, &hr);
+       return hr.error;
+}
+
+static
+u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_control, const u16 attrib, u32 param1, u32 param2,
+       u32 *pparam1, u32 *pparam2)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = attrib;
+       hm.u.c.param1 = param1;
+       hm.u.c.param2 = param2;
+       hpi_send_recv(&hm, &hr);
+       if (pparam1)
+               *pparam1 = hr.u.c.param1;
+       if (pparam2)
+               *pparam2 = hr.u.c.param2;
+
+       return hr.error;
+}
+
+#define hpi_control_param1_get(s, h, a, p1) \
+               hpi_control_param_get(s, h, a, 0, 0, p1, NULL)
+#define hpi_control_param2_get(s, h, a, p1, p2) \
+               hpi_control_param_get(s, h, a, 0, 0, p1, p2)
+#define hpi_control_ex_param1_get(s, h, a, p1) \
+               hpi_control_ex_param_get(s, h, a, 0, 0, p1, NULL)
+#define hpi_control_ex_param2_get(s, h, a, p1, p2) \
+               hpi_control_ex_param_get(s, h, a, 0, 0, p1, p2)
+
+static
+u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_control, const u16 attrib, const u32 index,
+       const u32 param, u32 *psetting)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_INFO);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.c.attribute = attrib;
+       hm.u.c.param1 = index;
+       hm.u.c.param2 = param;
+
+       hpi_send_recv(&hm, &hr);
+       *psetting = hr.u.c.param1;
+
+       return hr.error;
+}
+
+static u16 hpi_control_get_string(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_control, const u16 attribute, char *psz_string,
+       const u32 string_length)
+{
+       unsigned int sub_string_index = 0, j = 0;
+       char c = 0;
+       unsigned int n = 0;
+       u16 hE = 0;
+
+       if ((string_length < 1) || (string_length > 256))
+               return HPI_ERROR_INVALID_CONTROL_VALUE;
+       for (sub_string_index = 0; sub_string_index < string_length;
+               sub_string_index += 8) {
+               struct hpi_message hm;
+               struct hpi_response hr;
+
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+                       HPI_CONTROL_GET_STATE);
+               u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+               hm.u.c.attribute = attribute;
+               hm.u.c.param1 = sub_string_index;
+               hm.u.c.param2 = 0;
+               hpi_send_recv(&hm, &hr);
+
+               if (sub_string_index == 0
+                       && (hr.u.cu.chars8.remaining_chars + 8) >
+                       string_length)
+                       return HPI_ERROR_INVALID_CONTROL_VALUE;
+
+               if (hr.error) {
+                       hE = hr.error;
+                       break;
+               }
+               for (j = 0; j < 8; j++) {
+                       c = hr.u.cu.chars8.sz_data[j];
+                       psz_string[sub_string_index + j] = c;
+                       n++;
+                       if (n >= string_length) {
+                               psz_string[string_length - 1] = 0;
+                               hE = HPI_ERROR_INVALID_CONTROL_VALUE;
+                               break;
+                       }
+                       if (c == 0)
+                               break;
+               }
+
+               if ((hr.u.cu.chars8.remaining_chars == 0)
+                       && ((sub_string_index + j) < string_length)
+                       && (c != 0)) {
+                       c = 0;
+                       psz_string[sub_string_index + j] = c;
+               }
+               if (c == 0)
+                       break;
+       }
+       return hE;
+}
+
+u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_aes_rx, const u32 index, u16 *pw_format)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_aes_rx, HPI_AESEBURX_FORMAT,
+               index, 0, &qr);
+       *pw_format = (u16)qr;
+       return err;
+}
+
+u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 format)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_AESEBURX_FORMAT, format, 0);
+}
+
+u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_format)
+{
+       u16 err;
+       u32 param;
+
+       err = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_AESEBURX_FORMAT, &param);
+       if (!err && pw_format)
+               *pw_format = (u16)param;
+
+       return err;
+}
+
+u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate)
+{
+       return hpi_control_param1_get(ph_subsys, h_control,
+               HPI_AESEBURX_SAMPLERATE, psample_rate);
+}
+
+u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *pw_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_AESEBURX_USERDATA;
+       hm.u.c.param1 = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_data)
+               *pw_data = (u16)hr.u.c.param2;
+       return hr.error;
+}
+
+u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
+       hm.u.c.param1 = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_data)
+               *pw_data = (u16)hr.u.c.param2;
+       return hr.error;
+}
+
+u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_error_data)
+{
+       u32 error_data = 0;
+       u16 error = 0;
+
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_AESEBURX_ERRORSTATUS, &error_data);
+       if (pw_error_data)
+               *pw_error_data = (u16)error_data;
+       return error;
+}
+
+u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u32 sample_rate)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_AESEBUTX_SAMPLERATE, sample_rate, 0);
+}
+
+u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 data)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_AESEBUTX_USERDATA, index, data);
+}
+
+u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 data)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_AESEBUTX_CHANNELSTATUS, index, data);
+}
+
+u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys
+       *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
+{
+       return HPI_ERROR_INVALID_OPERATION;
+}
+
+u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_aes_tx, const u32 index, u16 *pw_format)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_aes_tx, HPI_AESEBUTX_FORMAT,
+               index, 0, &qr);
+       *pw_format = (u16)qr;
+       return err;
+}
+
+u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 output_format)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_AESEBUTX_FORMAT, output_format, 0);
+}
+
+u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_output_format)
+{
+       u16 err;
+       u32 param;
+
+       err = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_AESEBUTX_FORMAT, &param);
+       if (!err && pw_output_format)
+               *pw_output_format = (u16)param;
+
+       return err;
+}
+
+u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 edge_type)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_BITSTREAM_CLOCK_EDGE, edge_type, 0);
+}
+
+u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 polarity)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_BITSTREAM_DATA_POLARITY, polarity, 0);
+}
+
+u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
+       hpi_send_recv(&hm, &hr);
+       if (pw_clk_activity)
+               *pw_clk_activity = (u16)hr.u.c.param1;
+       if (pw_data_activity)
+               *pw_data_activity = (u16)hr.u.c.param2;
+       return hr.error;
+}
+
+u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_mode, const u32 index, u16 *pw_mode)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_mode, HPI_CHANNEL_MODE_MODE,
+               index, 0, &qr);
+       *pw_mode = (u16)qr;
+       return err;
+}
+
+u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 mode)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_CHANNEL_MODE_MODE, mode, 0);
+}
+
+u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *mode)
+{
+       u32 mode32 = 0;
+       u16 error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_CHANNEL_MODE_MODE, &mode32);
+       if (mode)
+               *mode = (u16)mode32;
+       return error;
+}
+
+u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 hmi_address, u32 byte_count, u8 *pb_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.cx.u.cobranet_data.byte_count = byte_count;
+       hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
+
+       if (byte_count <= 8) {
+               memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
+               hm.u.cx.attribute = HPI_COBRANET_SET;
+       } else {
+               hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
+               hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
+       }
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
+       hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
+
+       if (max_byte_count <= 8) {
+               hm.u.cx.attribute = HPI_COBRANET_GET;
+       } else {
+               hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
+               hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
+       }
+
+       hpi_send_recv(&hm, &hr);
+       if (!hr.error && pb_data) {
+
+               *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
+
+               if (*pbyte_count < max_byte_count)
+                       max_byte_count = *pbyte_count;
+
+               if (hm.u.cx.attribute == HPI_COBRANET_GET) {
+                       memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
+                               max_byte_count);
+               } else {
+
+               }
+
+       }
+       return hr.error;
+}
+
+u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pstatus, u32 *preadable_size,
+       u32 *pwriteable_size)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
+
+       hpi_send_recv(&hm, &hr);
+       if (!hr.error) {
+               if (pstatus)
+                       *pstatus = hr.u.cx.u.cobranet_status.status;
+               if (preadable_size)
+                       *preadable_size =
+                               hr.u.cx.u.cobranet_status.readable_size;
+               if (pwriteable_size)
+                       *pwriteable_size =
+                               hr.u.cx.u.cobranet_status.writeable_size;
+       }
+       return hr.error;
+}
+
+u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pi_paddress)
+{
+       u32 byte_count;
+       u32 iP;
+       u16 error;
+       error = hpi_cobranet_hmi_read(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
+               (u8 *)&iP);
+
+       *pi_paddress =
+               ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
+                       0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
+
+       if (error)
+               *pi_paddress = 0;
+
+       return error;
+
+}
+
+u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 i_paddress)
+{
+       u32 iP;
+       u16 error;
+
+       iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
+               8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
+                       0x000000ff) << 8);
+
+       error = hpi_cobranet_hmi_write(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
+
+       return error;
+
+}
+
+u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pi_paddress)
+{
+       u32 byte_count;
+       u32 iP;
+       u16 error;
+       error = hpi_cobranet_hmi_read(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
+               (u8 *)&iP);
+
+       *pi_paddress =
+               ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
+                       0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
+
+       if (error)
+               *pi_paddress = 0;
+
+       return error;
+
+}
+
+u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 i_paddress)
+{
+       u32 iP;
+       u16 error;
+
+       iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
+               8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
+                       0x000000ff) << 8);
+
+       error = hpi_cobranet_hmi_write(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
+
+       return error;
+
+}
+
+u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs)
+{
+       u32 byte_count;
+       u16 error;
+       u32 mAC;
+       error = hpi_cobranet_hmi_read(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
+               (u8 *)&mAC);
+       *pmAC_MS_bs =
+               ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
+                       & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
+       error += hpi_cobranet_hmi_read(ph_subsys, h_control,
+               HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
+               (u8 *)&mAC);
+       *pmAC_LS_bs =
+               ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
+                       & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
+
+       if (error) {
+               *pmAC_MS_bs = 0;
+               *pmAC_LS_bs = 0;
+       }
+
+       return error;
+}
+
+u16 hpi_compander_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 attack, u16 decay, short ratio100, short threshold0_01dB,
+       short makeup_gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.c.param1 = attack + ((u32)ratio100 << 16);
+       hm.u.c.param2 = (decay & 0xFFFFL);
+       hm.u.c.an_log_value[0] = threshold0_01dB;
+       hm.u.c.an_log_value[1] = makeup_gain0_01dB;
+       hm.u.c.attribute = HPI_COMPANDER_PARAMS;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_compander_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_attack, u16 *pw_decay, short *pw_ratio100,
+       short *pn_threshold0_01dB, short *pn_makeup_gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_COMPANDER_PARAMS;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pw_attack)
+               *pw_attack = (short)(hr.u.c.param1 & 0xFFFF);
+       if (pw_decay)
+               *pw_decay = (short)(hr.u.c.param2 & 0xFFFF);
+       if (pw_ratio100)
+               *pw_ratio100 = (short)(hr.u.c.param1 >> 16);
+
+       if (pn_threshold0_01dB)
+               *pn_threshold0_01dB = hr.u.c.an_log_value[0];
+       if (pn_makeup_gain0_01dB)
+               *pn_makeup_gain0_01dB = hr.u.c.an_log_value[1];
+
+       return hr.error;
+}
+
+u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_LEVEL_RANGE;
+
+       hpi_send_recv(&hm, &hr);
+       if (hr.error) {
+               hr.u.c.an_log_value[0] = 0;
+               hr.u.c.an_log_value[1] = 0;
+               hr.u.c.param1 = 0;
+       }
+       if (min_gain_01dB)
+               *min_gain_01dB = hr.u.c.an_log_value[0];
+       if (max_gain_01dB)
+               *max_gain_01dB = hr.u.c.an_log_value[1];
+       if (step_gain_01dB)
+               *step_gain_01dB = (short)hr.u.c.param1;
+       return hr.error;
+}
+
+u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB[HPI_MAX_CHANNELS]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       memcpy(hm.u.c.an_log_value, an_gain0_01dB,
+               sizeof(short) * HPI_MAX_CHANNELS);
+       hm.u.c.attribute = HPI_LEVEL_GAIN;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB[HPI_MAX_CHANNELS]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_LEVEL_GAIN;
+
+       hpi_send_recv(&hm, &hr);
+
+       memcpy(an_gain0_01dB, hr.u.c.an_log_value,
+               sizeof(short) * HPI_MAX_CHANNELS);
+       return hr.error;
+}
+
+u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_meter, u32 *p_channels)
+{
+       return hpi_control_query(ph_subsys, h_meter, HPI_METER_NUM_CHANNELS,
+               0, 0, p_channels);
+}
+
+u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_peakdB[HPI_MAX_CHANNELS]
+       )
+{
+       short i = 0;
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.obj_index = hm.obj_index;
+       hm.u.c.attribute = HPI_METER_PEAK;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (!hr.error)
+               memcpy(an_peakdB, hr.u.c.an_log_value,
+                       sizeof(short) * HPI_MAX_CHANNELS);
+       else
+               for (i = 0; i < HPI_MAX_CHANNELS; i++)
+                       an_peakdB[i] = HPI_METER_MINIMUM;
+       return hr.error;
+}
+
+u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_rmsdB[HPI_MAX_CHANNELS]
+       )
+{
+       short i = 0;
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_METER_RMS;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (!hr.error)
+               memcpy(an_rmsdB, hr.u.c.an_log_value,
+                       sizeof(short) * HPI_MAX_CHANNELS);
+       else
+               for (i = 0; i < HPI_MAX_CHANNELS; i++)
+                       an_rmsdB[i] = HPI_METER_MINIMUM;
+
+       return hr.error;
+}
+
+u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 attack, u16 decay)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_METER_RMS_BALLISTICS, attack, decay);
+}
+
+u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pn_attack, u16 *pn_decay)
+{
+       u32 attack;
+       u32 decay;
+       u16 error;
+
+       error = hpi_control_param2_get(ph_subsys, h_control,
+               HPI_METER_RMS_BALLISTICS, &attack, &decay);
+
+       if (pn_attack)
+               *pn_attack = (unsigned short)attack;
+       if (pn_decay)
+               *pn_decay = (unsigned short)decay;
+
+       return error;
+}
+
+u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 attack, u16 decay)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_METER_PEAK_BALLISTICS, attack, decay);
+}
+
+u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pn_attack, u16 *pn_decay)
+{
+       u32 attack;
+       u32 decay;
+       u16 error;
+
+       error = hpi_control_param2_get(ph_subsys, h_control,
+               HPI_METER_PEAK_BALLISTICS, &attack, &decay);
+
+       if (pn_attack)
+               *pn_attack = (short)attack;
+       if (pn_decay)
+               *pn_decay = (short)decay;
+
+       return error;
+}
+
+u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 on_off)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_MICROPHONE_PHANTOM_POWER, (u32)on_off, 0);
+}
+
+u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_on_off)
+{
+       u16 error = 0;
+       u32 on_off = 0;
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_MICROPHONE_PHANTOM_POWER, &on_off);
+       if (pw_on_off)
+               *pw_on_off = (u16)on_off;
+       return error;
+}
+
+u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source_node_type, u16 source_node_index)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_MULTIPLEXER_SOURCE, source_node_type, source_node_index);
+}
+
+u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *source_node_type, u16 *source_node_index)
+{
+       u32 node, index;
+       u16 error = hpi_control_param2_get(ph_subsys, h_control,
+               HPI_MULTIPLEXER_SOURCE, &node,
+               &index);
+       if (source_node_type)
+               *source_node_type = (u16)node;
+       if (source_node_index)
+               *source_node_index = (u16)index;
+       return error;
+}
+
+u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *source_node_type,
+       u16 *source_node_index)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
+       hm.u.c.param1 = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (source_node_type)
+               *source_node_type = (u16)hr.u.c.param1;
+       if (source_node_index)
+               *source_node_index = (u16)hr.u.c.param2;
+       return hr.error;
+}
+
+u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_number_of_bands, u16 *pw_on_off)
+{
+       u32 oB = 0;
+       u32 oO = 0;
+       u16 error = 0;
+
+       error = hpi_control_param2_get(ph_subsys, h_control,
+               HPI_EQUALIZER_NUM_FILTERS, &oO, &oB);
+       if (pw_number_of_bands)
+               *pw_number_of_bands = (u16)oB;
+       if (pw_on_off)
+               *pw_on_off = (u16)oO;
+       return error;
+}
+
+u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 on_off)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_EQUALIZER_NUM_FILTERS, on_off, 0);
+}
+
+u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz,
+       short *pnQ100, short *pn_gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_EQUALIZER_FILTER;
+       hm.u.c.param2 = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (pfrequency_hz)
+               *pfrequency_hz = hr.u.c.param1;
+       if (pn_type)
+               *pn_type = (u16)(hr.u.c.param2 >> 16);
+       if (pnQ100)
+               *pnQ100 = hr.u.c.an_log_value[1];
+       if (pn_gain0_01dB)
+               *pn_gain0_01dB = hr.u.c.an_log_value[0];
+
+       return hr.error;
+}
+
+u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100,
+       short gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       hm.u.c.param1 = frequency_hz;
+       hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
+       hm.u.c.an_log_value[0] = gain0_01dB;
+       hm.u.c.an_log_value[1] = q100;
+       hm.u.c.attribute = HPI_EQUALIZER_FILTER;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 index, short coeffs[5]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
+       hm.u.c.param2 = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       coeffs[0] = (short)hr.u.c.an_log_value[0];
+       coeffs[1] = (short)hr.u.c.an_log_value[1];
+       coeffs[2] = (short)hr.u.c.param1;
+       coeffs[3] = (short)(hr.u.c.param1 >> 16);
+       coeffs[4] = (short)hr.u.c.param2;
+
+       return hr.error;
+}
+
+u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, u16 *pw_source)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_clock, HPI_SAMPLECLOCK_SOURCE,
+               index, 0, &qr);
+       *pw_source = (u16)qr;
+       return err;
+}
+
+u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_SOURCE, source, 0);
+}
+
+u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_source)
+{
+       u16 error = 0;
+       u32 source = 0;
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_SOURCE, &source);
+       if (!error)
+               if (pw_source)
+                       *pw_source = (u16)source;
+       return error;
+}
+
+u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, const u32 source,
+       u16 *pw_source_index)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_clock,
+               HPI_SAMPLECLOCK_SOURCE_INDEX, index, source, &qr);
+       *pw_source_index = (u16)qr;
+       return err;
+}
+
+u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 source_index)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_SOURCE_INDEX, source_index, 0);
+}
+
+u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u16 *pw_source_index)
+{
+       u16 error = 0;
+       u32 source_index = 0;
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
+       if (!error)
+               if (pw_source_index)
+                       *pw_source_index = (u16)source_index;
+       return error;
+}
+
+u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_clock, const u32 index, u32 *prate)
+{
+       u16 err;
+       err = hpi_control_query(ph_subsys, h_clock,
+               HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, index, 0, prate);
+
+       return err;
+}
+
+u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 sample_rate)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
+}
+
+u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate)
+{
+       u16 error = 0;
+       u32 sample_rate = 0;
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
+       if (!error)
+               if (psample_rate)
+                       *psample_rate = sample_rate;
+       return error;
+}
+
+u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *psample_rate)
+{
+       u16 error = 0;
+       u32 sample_rate = 0;
+       error = hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_SAMPLERATE, &sample_rate);
+       if (!error)
+               if (psample_rate)
+                       *psample_rate = sample_rate;
+       return error;
+}
+
+u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 enable)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_AUTO, enable, 0);
+}
+
+u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *penable)
+{
+       return hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_AUTO, penable);
+}
+
+u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 lock)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_LOCAL_LOCK, lock, 0);
+}
+
+u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *plock)
+{
+       return hpi_control_param1_get(ph_subsys, h_control,
+               HPI_SAMPLECLOCK_LOCAL_LOCK, plock);
+}
+
+u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 index, u32 *frequency)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_TONEDETECTOR_FREQUENCY, index, 0, frequency, NULL);
+}
+
+u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *state)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_TONEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
+}
+
+u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 enable)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
+               (u32)enable, 0);
+}
+
+u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *enable)
+{
+       return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
+               0, 0, (u32 *)enable, NULL);
+}
+
+u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 event_enable)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
+}
+
+u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *event_enable)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
+}
+
+u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, int threshold)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_TONEDETECTOR_THRESHOLD, (u32)threshold, 0);
+}
+
+u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, int *threshold)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_TONEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
+}
+
+u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *state)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_SILENCEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
+}
+
+u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 enable)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
+               (u32)enable, 0);
+}
+
+u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *enable)
+{
+       return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
+               0, 0, (u32 *)enable, NULL);
+}
+
+u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 event_enable)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
+}
+
+u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *event_enable)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
+}
+
+u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 delay)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SILENCEDETECTOR_DELAY, (u32)delay, 0);
+}
+
+u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *delay)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_SILENCEDETECTOR_DELAY, 0, 0, (u32 *)delay, NULL);
+}
+
+u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, int threshold)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_SILENCEDETECTOR_THRESHOLD, (u32)threshold, 0);
+}
+
+u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, int *threshold)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_SILENCEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
+}
+
+u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, u16 *pw_band)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
+               &qr);
+       *pw_band = (u16)qr;
+       return err;
+}
+
+u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 band)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_BAND,
+               band, 0);
+}
+
+u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_band)
+{
+       u32 band = 0;
+       u16 error = 0;
+
+       error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_BAND,
+               &band);
+       if (pw_band)
+               *pw_band = (u16)band;
+       return error;
+}
+
+u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq)
+{
+       return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_FREQ, index,
+               band, pfreq);
+}
+
+u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 freq_ink_hz)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_FREQ,
+               freq_ink_hz, 0);
+}
+
+u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pw_freq_ink_hz)
+{
+       return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_FREQ,
+               pw_freq_ink_hz);
+}
+
+u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, u16 *pw_gain)
+{
+       u32 qr;
+       u16 err;
+
+       err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
+               &qr);
+       *pw_gain = (u16)qr;
+       return err;
+}
+
+u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short gain)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_GAIN,
+               gain, 0);
+}
+
+u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *pn_gain)
+{
+       u32 gain = 0;
+       u16 error = 0;
+
+       error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_GAIN,
+               &gain);
+       if (pn_gain)
+               *pn_gain = (u16)gain;
+       return error;
+}
+
+u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *pw_level)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_TUNER_LEVEL;
+       hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
+       hpi_send_recv(&hm, &hr);
+       if (pw_level)
+               *pw_level = (short)hr.u.c.param1;
+       return hr.error;
+}
+
+u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, short *pw_level)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_TUNER_LEVEL;
+       hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
+       hpi_send_recv(&hm, &hr);
+       if (pw_level)
+               *pw_level = (short)hr.u.c.param1;
+       return hr.error;
+}
+
+u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis)
+{
+       return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_DEEMPHASIS,
+               index, band, pdeemphasis);
+}
+
+u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 deemphasis)
+{
+       return hpi_control_param_set(ph_subsys, h_control,
+               HPI_TUNER_DEEMPHASIS, deemphasis, 0);
+}
+
+u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pdeemphasis)
+{
+       return hpi_control_param1_get(ph_subsys, h_control,
+               HPI_TUNER_DEEMPHASIS, pdeemphasis);
+}
+
+u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_tuner, u32 *pbitmap_program)
+{
+       return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_PROGRAM, 0, 0,
+               pbitmap_program);
+}
+
+u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 program)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_PROGRAM,
+               program, 0);
+}
+
+u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 *pprogram)
+{
+       return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_PROGRAM,
+               pprogram);
+}
+
+u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_dsp_version, const u32 string_size)
+{
+       return hpi_control_get_string(ph_subsys, h_control,
+               HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
+}
+
+u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_sdk_version, const u32 string_size)
+{
+       return hpi_control_get_string(ph_subsys, h_control,
+               HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
+}
+
+u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u16 *pw_status_mask, u16 *pw_status)
+{
+       u32 status = 0;
+       u16 error = 0;
+
+       error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_STATUS,
+               &status);
+       if (pw_status) {
+               if (!error) {
+                       *pw_status_mask = (u16)(status >> 16);
+                       *pw_status = (u16)(status & 0xFFFF);
+               } else {
+                       *pw_status_mask = 0;
+                       *pw_status = 0;
+               }
+       }
+       return error;
+}
+
+u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 mode, u32 value)
+{
+       return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_MODE,
+               mode, value);
+}
+
+u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 mode, u32 *pn_value)
+{
+       return hpi_control_param_get(ph_subsys, h_control, HPI_TUNER_MODE,
+               mode, 0, pn_value, NULL);
+}
+
+u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *pquality)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_TUNER_HDRADIO_SIGNAL_QUALITY, 0, 0, pquality, NULL);
+}
+
+u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *p_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_TUNER_RDS;
+       hpi_send_recv(&hm, &hr);
+       if (p_data) {
+               *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
+               *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
+               *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
+       }
+       return hr.error;
+}
+
+u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, char *psz_string, const u32 data_length)
+{
+       return hpi_control_get_string(ph_subsys, h_control,
+               HPI_PAD_CHANNEL_NAME, psz_string, data_length);
+}
+
+u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 data_length)
+{
+       return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_ARTIST,
+               psz_string, data_length);
+}
+
+u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 data_length)
+{
+       return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_TITLE,
+               psz_string, data_length);
+}
+
+u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       char *psz_string, const u32 data_length)
+{
+       return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_COMMENT,
+               psz_string, data_length);
+}
+
+u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, u32 *ppTY)
+{
+       return hpi_control_param_get(ph_subsys, h_control,
+               HPI_PAD_PROGRAM_TYPE, 0, 0, ppTY, NULL);
+}
+
+u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       u32 *ppI)
+{
+       return hpi_control_param_get(ph_subsys, h_control, HPI_PAD_PROGRAM_ID,
+               0, 0, ppI, NULL);
+}
+
+u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
+       const u32 h_volume, u32 *p_channels)
+{
+       return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS,
+               0, 0, p_channels);
+}
+
+u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_log_gain[HPI_MAX_CHANNELS]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       memcpy(hm.u.c.an_log_value, an_log_gain,
+               sizeof(short) * HPI_MAX_CHANNELS);
+       hm.u.c.attribute = HPI_VOLUME_GAIN;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_log_gain[HPI_MAX_CHANNELS]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_VOLUME_GAIN;
+
+       hpi_send_recv(&hm, &hr);
+
+       memcpy(an_log_gain, hr.u.c.an_log_value,
+               sizeof(short) * HPI_MAX_CHANNELS);
+       return hr.error;
+}
+
+u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_VOLUME_RANGE;
+
+       hpi_send_recv(&hm, &hr);
+       if (hr.error) {
+               hr.u.c.an_log_value[0] = 0;
+               hr.u.c.an_log_value[1] = 0;
+               hr.u.c.param1 = 0;
+       }
+       if (min_gain_01dB)
+               *min_gain_01dB = hr.u.c.an_log_value[0];
+       if (max_gain_01dB)
+               *max_gain_01dB = hr.u.c.an_log_value[1];
+       if (step_gain_01dB)
+               *step_gain_01dB = (short)hr.u.c.param1;
+       return hr.error;
+}
+
+u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
+       u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
+       u32 duration_ms, u16 profile)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+
+       memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
+               sizeof(short) * HPI_MAX_CHANNELS);
+
+       hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
+       hm.u.c.param1 = duration_ms;
+       hm.u.c.param2 = profile;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
+{
+       return hpi_volume_auto_fade_profile(ph_subsys, h_control,
+               an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG);
+}
+
+u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short an_gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_VOX_THRESHOLD;
+
+       hm.u.c.an_log_value[0] = an_gain0_01dB;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
+       short *an_gain0_01dB)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
+               HPI_CONTROL_GET_STATE);
+       u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
+       hm.u.c.attribute = HPI_VOX_THRESHOLD;
+
+       hpi_send_recv(&hm, &hr);
+
+       *an_gain0_01dB = hr.u.c.an_log_value[0];
+
+       return hr.error;
+}
+
+static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
+
+static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
+       0,
+       sizeof(struct hpi_entity),
+       sizeof(void *),
+
+       sizeof(int),
+       sizeof(float),
+       sizeof(double),
+
+       sizeof(char),
+       sizeof(char),
+
+       4 * sizeof(char),
+       16 * sizeof(char),
+       6 * sizeof(char),
+};
+
+inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
+{
+       return entity_ptr->header.size;
+}
+
+inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
+{
+       return sizeof(entity_ptr->header);
+}
+
+inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
+{
+       return hpi_entity_size(entity_ptr) -
+               hpi_entity_header_size(entity_ptr);
+}
+
+inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
+{
+       return hpi_entity_value_size(entity_ptr) /
+               entity_type_to_size[entity_ptr->header.type];
+}
+
+inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
+       *entity_ptr)
+{
+       return (void *)(((uint8_t *) entity_ptr) +
+               hpi_entity_size(entity_ptr));
+}
+
+inline u16 hpi_entity_check_type(const enum e_entity_type t)
+{
+       if (t >= 0 && t < STR_TYPE_FIELD_MAX)
+               return 0;
+       return HPI_ERROR_ENTITY_TYPE_INVALID;
+}
+
+inline u16 hpi_entity_check_role(const enum e_entity_role r)
+{
+       if (r >= 0 && r < STR_ROLE_FIELD_MAX)
+               return 0;
+       return HPI_ERROR_ENTITY_ROLE_INVALID;
+}
+
+static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
+       void *guard_p, struct hpi_entity **next)
+{
+       HPI_DEBUG_ASSERT(entity != NULL);
+       HPI_DEBUG_ASSERT(next != NULL);
+       HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
+
+       if (guard_p <= (void *)entity) {
+               *next = NULL;
+               return 0;
+       }
+
+       if (recursive_flag && entity->header.type == entity_type_sequence)
+               *next = (struct hpi_entity *)entity->value;
+       else
+               *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
+
+       if (guard_p <= (void *)*next) {
+               *next = NULL;
+               return 0;
+       }
+
+       HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
+       return 0;
+}
+
+u16 hpi_entity_find_next(struct hpi_entity *container_entity,
+       enum e_entity_type type, enum e_entity_role role, int recursive_flag,
+       struct hpi_entity **current_match)
+{
+       struct hpi_entity *tmp = NULL;
+       void *guard_p = NULL;
+
+       HPI_DEBUG_ASSERT(container_entity != NULL);
+       guard_p = hpi_entity_ptr_to_next(container_entity);
+
+       if (*current_match != NULL)
+               hpi_entity_get_next(*current_match, recursive_flag, guard_p,
+                       &tmp);
+       else
+               hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
+
+       while (tmp) {
+               u16 err;
+
+               HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
+
+               if ((!type || tmp->header.type == type) && (!role
+                               || tmp->header.role == role)) {
+                       *current_match = tmp;
+                       return 0;
+               }
+
+               err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
+                       current_match);
+               if (err)
+                       return err;
+
+               tmp = *current_match;
+       }
+
+       *current_match = NULL;
+       return 0;
+}
+
+void hpi_entity_free(struct hpi_entity *entity)
+{
+       if (entity != NULL)
+               kfree(entity);
+}
+
+static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
+       struct hpi_entity **dst)
+{
+       size_t buf_size;
+       HPI_DEBUG_ASSERT(dst != NULL);
+       HPI_DEBUG_ASSERT(src != NULL);
+
+       buf_size = hpi_entity_size(src);
+       *dst = kmalloc(buf_size, GFP_KERNEL);
+       if (*dst == NULL)
+               return HPI_ERROR_MEMORY_ALLOC;
+       memcpy(*dst, src, buf_size);
+       return 0;
+}
+
+u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity **info)
+{
+       struct hpi_msg_strv hm;
+       struct hpi_res_strv *phr;
+       u16 hpi_err;
+       int remaining_attempts = 2;
+       size_t resp_packet_size = 1024;
+
+       *info = NULL;
+
+       while (remaining_attempts--) {
+               phr = kmalloc(resp_packet_size, GFP_KERNEL);
+               HPI_DEBUG_ASSERT(phr != NULL);
+
+               hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
+                       (u16)resp_packet_size, HPI_OBJ_CONTROL,
+                       HPI_CONTROL_GET_INFO);
+               u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
+
+               hm.strv.header.size = sizeof(hm.strv);
+               phr->strv.header.size = resp_packet_size - sizeof(phr->h);
+
+               hpi_send_recv((struct hpi_message *)&hm.h,
+                       (struct hpi_response *)&phr->h);
+               if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
+
+                       HPI_DEBUG_ASSERT(phr->h.specific_error >
+                               MIN_STRV_PACKET_SIZE
+                               && phr->h.specific_error < 1500);
+                       resp_packet_size = phr->h.specific_error;
+               } else {
+                       remaining_attempts = 0;
+                       if (!phr->h.error)
+                               hpi_entity_alloc_and_copy(&phr->strv, info);
+               }
+
+               hpi_err = phr->h.error;
+               kfree(phr);
+       }
+
+       return hpi_err;
+}
+
+u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity **value)
+{
+       struct hpi_msg_strv hm;
+       struct hpi_res_strv *phr;
+       u16 hpi_err;
+       int remaining_attempts = 2;
+
+       *value = NULL;
+
+       while (remaining_attempts--) {
+               phr = kmalloc(strv_packet_size, GFP_KERNEL);
+               if (!phr)
+                       return HPI_ERROR_MEMORY_ALLOC;
+
+               hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
+                       (u16)strv_packet_size, HPI_OBJ_CONTROL,
+                       HPI_CONTROL_GET_STATE);
+               u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
+
+               hm.strv.header.size = sizeof(hm.strv);
+               phr->strv.header.size = strv_packet_size - sizeof(phr->h);
+
+               hpi_send_recv((struct hpi_message *)&hm.h,
+                       (struct hpi_response *)&phr->h);
+               if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
+
+                       HPI_DEBUG_ASSERT(phr->h.specific_error >
+                               MIN_STRV_PACKET_SIZE
+                               && phr->h.specific_error < 1000);
+                       strv_packet_size = phr->h.specific_error;
+               } else {
+                       remaining_attempts = 0;
+                       if (!phr->h.error)
+                               hpi_entity_alloc_and_copy(&phr->strv, value);
+               }
+
+               hpi_err = phr->h.error;
+               kfree(phr);
+       }
+
+       return hpi_err;
+}
+
+u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
+       struct hpi_entity *value)
+{
+       struct hpi_msg_strv *phm;
+       struct hpi_res_strv hr;
+
+       phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
+       HPI_DEBUG_ASSERT(phm != NULL);
+
+       hpi_init_message_responseV1(&phm->h,
+               sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
+               HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
+       u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
+       hr.strv.header.size = sizeof(hr.strv);
+
+       memcpy(&phm->strv, value, value->header.size);
+       hpi_send_recv((struct hpi_message *)&phm->h,
+               (struct hpi_response *)&hr.h);
+
+       return hr.h.error;
+}
+
+u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
+       const size_t item_count, const enum e_entity_role role, void *value,
+       struct hpi_entity **entity)
+{
+       size_t bytes_to_copy, total_size;
+       u16 hE = 0;
+       *entity = NULL;
+
+       hE = hpi_entity_check_type(type);
+       if (hE)
+               return hE;
+
+       HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
+
+       bytes_to_copy = entity_type_to_size[type] * item_count;
+       total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
+
+       HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
+               && total_size < STR_SIZE_FIELD_MAX);
+
+       *entity = kmalloc(total_size, GFP_KERNEL);
+       if (*entity == NULL)
+               return HPI_ERROR_MEMORY_ALLOC;
+       memcpy((*entity)->value, value, bytes_to_copy);
+       (*entity)->header.size =
+               hpi_entity_header_size(*entity) + bytes_to_copy;
+       (*entity)->header.type = type;
+       (*entity)->header.role = role;
+       return 0;
+}
+
+u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
+       enum e_entity_type type, size_t item_count, void *value_dst_p)
+{
+       size_t bytes_to_copy;
+
+       if (entity->header.type != type)
+               return HPI_ERROR_ENTITY_TYPE_MISMATCH;
+
+       if (hpi_entity_item_count(entity) != item_count)
+               return HPI_ERROR_ENTITY_ITEM_COUNT;
+
+       bytes_to_copy = entity_type_to_size[type] * item_count;
+       memcpy(value_dst_p, entity->value, bytes_to_copy);
+       return 0;
+}
+
+u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
+       size_t *item_count, enum e_entity_role *role, void **value)
+{
+       u16 err = 0;
+       HPI_DEBUG_ASSERT(entity != NULL);
+
+       if (type)
+               *type = entity->header.type;
+
+       if (role)
+               *role = entity->header.role;
+
+       if (value)
+               *value = entity->value;
+
+       if (item_count != NULL) {
+               if (entity->header.type == entity_type_sequence) {
+                       void *guard_p = hpi_entity_ptr_to_next(entity);
+                       struct hpi_entity *next = NULL;
+                       void *contents = entity->value;
+
+                       *item_count = 0;
+                       while (contents < guard_p) {
+                               (*item_count)++;
+                               err = hpi_entity_get_next(contents, 0,
+                                       guard_p, &next);
+                               if (next == NULL || err)
+                                       break;
+                               contents = next;
+                       }
+               } else {
+                       *item_count = hpi_entity_item_count(entity);
+               }
+       }
+       return err;
+}
+
+u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0) {
+               *ph_gpio =
+                       hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
+               if (pw_number_input_bits)
+                       *pw_number_input_bits = hr.u.l.number_input_bits;
+               if (pw_number_output_bits)
+                       *pw_number_output_bits = hr.u.l.number_output_bits;
+       } else
+               *ph_gpio = 0;
+       return hr.error;
+}
+
+u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 bit_index, u16 *pw_bit_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
+       u32TOINDEX(h_gpio, &hm.adapter_index);
+       hm.u.l.bit_index = bit_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       *pw_bit_data = hr.u.l.bit_data[0];
+       return hr.error;
+}
+
+u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 aw_all_bit_data[4]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
+       u32TOINDEX(h_gpio, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (aw_all_bit_data) {
+               aw_all_bit_data[0] = hr.u.l.bit_data[0];
+               aw_all_bit_data[1] = hr.u.l.bit_data[1];
+               aw_all_bit_data[2] = hr.u.l.bit_data[2];
+               aw_all_bit_data[3] = hr.u.l.bit_data[3];
+       }
+       return hr.error;
+}
+
+u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 bit_index, u16 bit_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
+       u32TOINDEX(h_gpio, &hm.adapter_index);
+       hm.u.l.bit_index = bit_index;
+       hm.u.l.bit_data = bit_data;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
+       u16 aw_all_bit_data[4]
+       )
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
+               HPI_GPIO_WRITE_STATUS);
+       u32TOINDEX(h_gpio, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (aw_all_bit_data) {
+               aw_all_bit_data[0] = hr.u.l.bit_data[0];
+               aw_all_bit_data[1] = hr.u.l.bit_data[1];
+               aw_all_bit_data[2] = hr.u.l.bit_data[2];
+               aw_all_bit_data[3] = hr.u.l.bit_data[3];
+       }
+       return hr.error;
+}
+
+u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u32 *ph_async)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
+               HPI_ASYNCEVENT_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+
+               *ph_async =
+                       hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
+                       adapter_index, 0);
+       else
+               *ph_async = 0;
+       return hr.error;
+
+}
+
+u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
+               HPI_ASYNCEVENT_OPEN);
+       u32TOINDEX(h_async, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
+       u16 maximum_events, struct hpi_async_event *p_events,
+       u16 *pw_number_returned)
+{
+       return 0;
+}
+
+u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
+       u32 h_async, u16 *pw_count)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
+               HPI_ASYNCEVENT_GETCOUNT);
+       u32TOINDEX(h_async, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               if (pw_count)
+                       *pw_count = hr.u.as.u.count.count;
+
+       return hr.error;
+}
+
+u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
+       u16 maximum_events, struct hpi_async_event *p_events,
+       u16 *pw_number_returned)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
+               HPI_ASYNCEVENT_GET);
+       u32TOINDEX(h_async, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+       if (!hr.error) {
+               memcpy(p_events, &hr.u.as.u.event,
+                       sizeof(struct hpi_async_event));
+               *pw_number_returned = 1;
+       }
+
+       return hr.error;
+}
+
+u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_nv_memory, u16 *pw_size_in_bytes)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
+               HPI_NVMEMORY_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0) {
+               *ph_nv_memory =
+                       hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
+                       0);
+               if (pw_size_in_bytes)
+                       *pw_size_in_bytes = hr.u.n.size_in_bytes;
+       } else
+               *ph_nv_memory = 0;
+       return hr.error;
+}
+
+u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
+       u32 h_nv_memory, u16 index, u16 *pw_data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
+               HPI_NVMEMORY_READ_BYTE);
+       u32TOINDEX(h_nv_memory, &hm.adapter_index);
+       hm.u.n.address = index;
+
+       hpi_send_recv(&hm, &hr);
+
+       *pw_data = hr.u.n.data;
+       return hr.error;
+}
+
+u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
+       u32 h_nv_memory, u16 index, u16 data)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
+               HPI_NVMEMORY_WRITE_BYTE);
+       u32TOINDEX(h_nv_memory, &hm.adapter_index);
+       hm.u.n.address = index;
+       hm.u.n.data = data;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 profile_index, u32 *ph_profile,
+       u16 *pw_max_profiles)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
+               HPI_PROFILE_OPEN_ALL);
+       hm.adapter_index = adapter_index;
+       hm.obj_index = profile_index;
+       hpi_send_recv(&hm, &hr);
+
+       *pw_max_profiles = hr.u.p.u.o.max_profiles;
+       if (hr.error == 0)
+               *ph_profile =
+                       hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
+                       profile_index);
+       else
+               *ph_profile = 0;
+       return hr.error;
+}
+
+u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
+       u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
+       u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
+       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
+       hm.u.p.bin_index = bin_index;
+       hpi_send_recv(&hm, &hr);
+       if (pw_seconds)
+               *pw_seconds = hr.u.p.u.t.seconds;
+       if (pmicro_seconds)
+               *pmicro_seconds = hr.u.p.u.t.micro_seconds;
+       if (pcall_count)
+               *pcall_count = hr.u.p.u.t.call_count;
+       if (pmax_micro_seconds)
+               *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
+       if (pmin_micro_seconds)
+               *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
+       return hr.error;
+}
+
+u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
+       u32 h_profile, u32 *putilization)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
+               HPI_PROFILE_GET_UTILIZATION);
+       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+       if (hr.error) {
+               if (putilization)
+                       *putilization = 0;
+       } else {
+               if (putilization)
+                       *putilization = hr.u.p.u.t.call_count;
+       }
+       return hr.error;
+}
+
+u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
+       u16 bin_index, char *sz_name, u16 name_length)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
+               HPI_PROFILE_GET_NAME);
+       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
+       hm.u.p.bin_index = bin_index;
+       hpi_send_recv(&hm, &hr);
+       if (hr.error) {
+               if (sz_name)
+                       strcpy(sz_name, "??");
+       } else {
+               if (sz_name)
+                       memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
+                               name_length);
+       }
+       return hr.error;
+}
+
+u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
+               HPI_PROFILE_START_ALL);
+       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
+               HPI_PROFILE_STOP_ALL);
+       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
+       u32 *ph_watchdog)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
+               HPI_WATCHDOG_OPEN);
+       hm.adapter_index = adapter_index;
+
+       hpi_send_recv(&hm, &hr);
+
+       if (hr.error == 0)
+               *ph_watchdog =
+                       hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
+                       0);
+       else
+               *ph_watchdog = 0;
+       return hr.error;
+}
+
+u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
+       u32 time_millisec)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
+               HPI_WATCHDOG_SET_TIME);
+       u32TOINDEX(h_watchdog, &hm.adapter_index);
+       hm.u.w.time_ms = time_millisec;
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
+
+u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
+               HPI_WATCHDOG_PING);
+       u32TOINDEX(h_watchdog, &hm.adapter_index);
+
+       hpi_send_recv(&hm, &hr);
+
+       return hr.error;
+}
diff --git a/sound/pci/asihpi/hpimsginit.c b/sound/pci/asihpi/hpimsginit.c
new file mode 100644 (file)
index 0000000..8e1d099
--- /dev/null
@@ -0,0 +1,130 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ Hardware Programming Interface (HPI) Utility functions.
+
+ (C) Copyright AudioScience Inc. 2007
+*******************************************************************************/
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+
+/* The actual message size for each object type */
+static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
+/* The actual response size for each object type */
+static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
+/* Flag to enable alternate message type for SSX2 bypass. */
+static u16 gwSSX2_bypass;
+
+/** \internal
+  * Used by ASIO driver to disable SSX2 for a single process
+  * \param phSubSys Pointer to HPI subsystem handle.
+  * \param wBypass New bypass setting 0 = off, nonzero = on
+  * \return Previous bypass setting.
+  */
+u16 hpi_subsys_ssx2_bypass(const struct hpi_hsubsys *ph_subsys, u16 bypass)
+{
+       u16 old_value = gwSSX2_bypass;
+
+       gwSSX2_bypass = bypass;
+
+       return old_value;
+}
+
+/** \internal
+  * initialize the HPI message structure
+  */
+static void hpi_init_message(struct hpi_message *phm, u16 object,
+       u16 function)
+{
+       memset(phm, 0, sizeof(*phm));
+       if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
+               phm->size = msg_size[object];
+       else
+               phm->size = sizeof(*phm);
+
+       if (gwSSX2_bypass)
+               phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
+       else
+               phm->type = HPI_TYPE_MESSAGE;
+       phm->object = object;
+       phm->function = function;
+       phm->version = 0;
+       /* Expect adapter index to be set by caller */
+}
+
+/** \internal
+  * initialize the HPI response structure
+  */
+void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
+       u16 error)
+{
+       memset(phr, 0, sizeof(*phr));
+       phr->type = HPI_TYPE_RESPONSE;
+       if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
+               phr->size = res_size[object];
+       else
+               phr->size = sizeof(*phr);
+       phr->object = object;
+       phr->function = function;
+       phr->error = error;
+       phr->specific_error = 0;
+       phr->version = 0;
+}
+
+void hpi_init_message_response(struct hpi_message *phm,
+       struct hpi_response *phr, u16 object, u16 function)
+{
+       hpi_init_message(phm, object, function);
+       /* default error return if the response is
+          not filled in by the callee */
+       hpi_init_response(phr, object, function,
+               HPI_ERROR_PROCESSING_MESSAGE);
+}
+
+static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
+       u16 object, u16 function)
+{
+       memset(phm, 0, sizeof(*phm));
+       if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
+               phm->size = size;
+               phm->type = HPI_TYPE_MESSAGE;
+               phm->object = object;
+               phm->function = function;
+               phm->version = 1;
+               /* Expect adapter index to be set by caller */
+       }
+}
+
+void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
+       u16 object, u16 function)
+{
+       memset(phr, 0, sizeof(*phr));
+       phr->size = size;
+       phr->version = 1;
+       phr->type = HPI_TYPE_RESPONSE;
+       phr->error = HPI_ERROR_PROCESSING_MESSAGE;
+}
+
+void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
+       struct hpi_response_header *phr, u16 res_size, u16 object,
+       u16 function)
+{
+       hpi_init_messageV1(phm, msg_size, object, function);
+       hpi_init_responseV1(phr, res_size, object, function);
+}
diff --git a/sound/pci/asihpi/hpimsginit.h b/sound/pci/asihpi/hpimsginit.h
new file mode 100644 (file)
index 0000000..864ad02
--- /dev/null
@@ -0,0 +1,40 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ Hardware Programming Interface (HPI) Utility functions
+
+ (C) Copyright AudioScience Inc. 2007
+*******************************************************************************/
+/* Initialise response headers, or msg/response pairs.
+Note that it is valid to just init a response e.g. when a lower level is preparing
+a response to a message.
+However, when sending a message, a matching response buffer always must be prepared
+*/
+
+void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
+       u16 error);
+
+void hpi_init_message_response(struct hpi_message *phm,
+       struct hpi_response *phr, u16 object, u16 function);
+
+void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
+       u16 object, u16 function);
+
+void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
+       struct hpi_response_header *phr, u16 res_size, u16 object,
+       u16 function);
diff --git a/sound/pci/asihpi/hpimsgx.c b/sound/pci/asihpi/hpimsgx.c
new file mode 100644 (file)
index 0000000..2ee90dc
--- /dev/null
@@ -0,0 +1,907 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Extended Message Function With Response Cacheing
+
+(C) Copyright AudioScience Inc. 2002
+*****************************************************************************/
+#define SOURCEFILE_NAME "hpimsgx.c"
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+#include "hpimsgx.h"
+#include "hpidebug.h"
+
+static struct pci_device_id asihpi_pci_tbl[] = {
+#include "hpipcida.h"
+};
+
+static struct hpios_spinlock msgx_lock;
+
+static hpi_handler_func *hpi_entry_points[HPI_MAX_ADAPTERS];
+
+static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
+       *pci_info)
+{
+
+       int i;
+
+       for (i = 0; asihpi_pci_tbl[i].vendor != 0; i++) {
+               if (asihpi_pci_tbl[i].vendor != PCI_ANY_ID
+                       && asihpi_pci_tbl[i].vendor != pci_info->vendor_id)
+                       continue;
+               if (asihpi_pci_tbl[i].device != PCI_ANY_ID
+                       && asihpi_pci_tbl[i].device != pci_info->device_id)
+                       continue;
+               if (asihpi_pci_tbl[i].subvendor != PCI_ANY_ID
+                       && asihpi_pci_tbl[i].subvendor !=
+                       pci_info->subsys_vendor_id)
+                       continue;
+               if (asihpi_pci_tbl[i].subdevice != PCI_ANY_ID
+                       && asihpi_pci_tbl[i].subdevice !=
+                       pci_info->subsys_device_id)
+                       continue;
+
+               HPI_DEBUG_LOG(DEBUG, " %x,%lu\n", i,
+                       asihpi_pci_tbl[i].driver_data);
+               return (hpi_handler_func *) asihpi_pci_tbl[i].driver_data;
+       }
+
+       return NULL;
+}
+
+static inline void hw_entry_point(struct hpi_message *phm,
+       struct hpi_response *phr)
+{
+
+       hpi_handler_func *ep;
+
+       if (phm->adapter_index < HPI_MAX_ADAPTERS) {
+               ep = (hpi_handler_func *) hpi_entry_points[phm->
+                       adapter_index];
+               if (ep) {
+                       HPI_DEBUG_MESSAGE(DEBUG, phm);
+                       ep(phm, phr);
+                       HPI_DEBUG_RESPONSE(phr);
+                       return;
+               }
+       }
+       hpi_init_response(phr, phm->object, phm->function,
+               HPI_ERROR_PROCESSING_MESSAGE);
+}
+
+static void adapter_open(struct hpi_message *phm, struct hpi_response *phr);
+static void adapter_close(struct hpi_message *phm, struct hpi_response *phr);
+
+static void mixer_open(struct hpi_message *phm, struct hpi_response *phr);
+static void mixer_close(struct hpi_message *phm, struct hpi_response *phr);
+
+static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner);
+static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner);
+static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner);
+static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner);
+
+static void HPIMSGX__reset(u16 adapter_index);
+static u16 HPIMSGX__init(struct hpi_message *phm, struct hpi_response *phr);
+static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner);
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(push, 1)
+#endif
+
+struct hpi_subsys_response {
+       struct hpi_response_header h;
+       struct hpi_subsys_res s;
+};
+
+struct hpi_adapter_response {
+       struct hpi_response_header h;
+       struct hpi_adapter_res a;
+};
+
+struct hpi_mixer_response {
+       struct hpi_response_header h;
+       struct hpi_mixer_res m;
+};
+
+struct hpi_stream_response {
+       struct hpi_response_header h;
+       struct hpi_stream_res d;
+};
+
+struct adapter_info {
+       u16 type;
+       u16 num_instreams;
+       u16 num_outstreams;
+};
+
+struct asi_open_state {
+       int open_flag;
+       void *h_owner;
+};
+
+#ifndef DISABLE_PRAGMA_PACK1
+#pragma pack(pop)
+#endif
+
+/* Globals */
+static struct hpi_adapter_response rESP_HPI_ADAPTER_OPEN[HPI_MAX_ADAPTERS];
+
+static struct hpi_stream_response
+       rESP_HPI_OSTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
+
+static struct hpi_stream_response
+       rESP_HPI_ISTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
+
+static struct hpi_mixer_response rESP_HPI_MIXER_OPEN[HPI_MAX_ADAPTERS];
+
+static struct hpi_subsys_response gRESP_HPI_SUBSYS_FIND_ADAPTERS;
+
+static struct adapter_info aDAPTER_INFO[HPI_MAX_ADAPTERS];
+
+/* use these to keep track of opens from user mode apps/DLLs */
+static struct asi_open_state
+       outstream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
+
+static struct asi_open_state
+       instream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
+
+static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+       switch (phm->function) {
+       case HPI_SUBSYS_GET_VERSION:
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
+                       HPI_SUBSYS_GET_VERSION, 0);
+               phr->u.s.version = HPI_VER >> 8;        /* return major.minor */
+               phr->u.s.data = HPI_VER;        /* return major.minor.release */
+               break;
+       case HPI_SUBSYS_OPEN:
+               /*do not propagate the message down the chain */
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_OPEN, 0);
+               break;
+       case HPI_SUBSYS_CLOSE:
+               /*do not propagate the message down the chain */
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CLOSE,
+                       0);
+               HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
+               break;
+       case HPI_SUBSYS_DRIVER_LOAD:
+               /* Initialize this module's internal state */
+               hpios_msgxlock_init(&msgx_lock);
+               memset(&hpi_entry_points, 0, sizeof(hpi_entry_points));
+               hpios_locked_mem_init();
+               /* Init subsys_findadapters response to no-adapters */
+               HPIMSGX__reset(HPIMSGX_ALLADAPTERS);
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
+                       HPI_SUBSYS_DRIVER_LOAD, 0);
+               /* individual HPIs dont implement driver load */
+               HPI_COMMON(phm, phr);
+               break;
+       case HPI_SUBSYS_DRIVER_UNLOAD:
+               HPI_COMMON(phm, phr);
+               HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
+               hpios_locked_mem_free_all();
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
+                       HPI_SUBSYS_DRIVER_UNLOAD, 0);
+               return;
+
+       case HPI_SUBSYS_GET_INFO:
+               HPI_COMMON(phm, phr);
+               break;
+
+       case HPI_SUBSYS_FIND_ADAPTERS:
+               memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS,
+                       sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS));
+               break;
+       case HPI_SUBSYS_GET_NUM_ADAPTERS:
+               memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS,
+                       sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS));
+               phr->function = HPI_SUBSYS_GET_NUM_ADAPTERS;
+               break;
+       case HPI_SUBSYS_GET_ADAPTER:
+               {
+                       int count = phm->adapter_index;
+                       int index = 0;
+                       hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
+                               HPI_SUBSYS_GET_ADAPTER, 0);
+
+                       /* This is complicated by the fact that we want to
+                        * "skip" 0's in the adapter list.
+                        * First, make sure we are pointing to a
+                        * non-zero adapter type.
+                        */
+                       while (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
+                               s.aw_adapter_list[index] == 0) {
+                               index++;
+                               if (index >= HPI_MAX_ADAPTERS)
+                                       break;
+                       }
+                       while (count) {
+                               /* move on to the next adapter */
+                               index++;
+                               if (index >= HPI_MAX_ADAPTERS)
+                                       break;
+                               while (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
+                                       s.aw_adapter_list[index] == 0) {
+                                       index++;
+                                       if (index >= HPI_MAX_ADAPTERS)
+                                               break;
+                               }
+                               count--;
+                       }
+
+                       if (index < HPI_MAX_ADAPTERS) {
+                               phr->u.s.adapter_index = (u16)index;
+                               phr->u.s.aw_adapter_list[0] =
+                                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.
+                                       s.aw_adapter_list[index];
+                       } else {
+                               phr->u.s.adapter_index = 0;
+                               phr->u.s.aw_adapter_list[0] = 0;
+                               phr->error = HPI_ERROR_BAD_ADAPTER_NUMBER;
+                       }
+                       break;
+               }
+       case HPI_SUBSYS_CREATE_ADAPTER:
+               HPIMSGX__init(phm, phr);
+               break;
+       case HPI_SUBSYS_DELETE_ADAPTER:
+               HPIMSGX__cleanup(phm->adapter_index, h_owner);
+               {
+                       struct hpi_message hm;
+                       struct hpi_response hr;
+                       /* call to HPI_ADAPTER_CLOSE */
+                       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+                               HPI_ADAPTER_CLOSE);
+                       hm.adapter_index = phm->adapter_index;
+                       hw_entry_point(&hm, &hr);
+               }
+               hw_entry_point(phm, phr);
+               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.
+                       aw_adapter_list[phm->adapter_index]
+                       = 0;
+               hpi_entry_points[phm->adapter_index] = NULL;
+               break;
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+}
+
+static void adapter_message(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+       switch (phm->function) {
+       case HPI_ADAPTER_OPEN:
+               adapter_open(phm, phr);
+               break;
+       case HPI_ADAPTER_CLOSE:
+               adapter_close(phm, phr);
+               break;
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+}
+
+static void mixer_message(struct hpi_message *phm, struct hpi_response *phr)
+{
+       switch (phm->function) {
+       case HPI_MIXER_OPEN:
+               mixer_open(phm, phr);
+               break;
+       case HPI_MIXER_CLOSE:
+               mixer_close(phm, phr);
+               break;
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+}
+
+static void outstream_message(struct hpi_message *phm,
+       struct hpi_response *phr, void *h_owner)
+{
+       if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_outstreams) {
+               hpi_init_response(phr, HPI_OBJ_OSTREAM, phm->function,
+                       HPI_ERROR_INVALID_OBJ_INDEX);
+               return;
+       }
+
+       switch (phm->function) {
+       case HPI_OSTREAM_OPEN:
+               outstream_open(phm, phr, h_owner);
+               break;
+       case HPI_OSTREAM_CLOSE:
+               outstream_close(phm, phr, h_owner);
+               break;
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+}
+
+static void instream_message(struct hpi_message *phm,
+       struct hpi_response *phr, void *h_owner)
+{
+       if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_instreams) {
+               hpi_init_response(phr, HPI_OBJ_ISTREAM, phm->function,
+                       HPI_ERROR_INVALID_OBJ_INDEX);
+               return;
+       }
+
+       switch (phm->function) {
+       case HPI_ISTREAM_OPEN:
+               instream_open(phm, phr, h_owner);
+               break;
+       case HPI_ISTREAM_CLOSE:
+               instream_close(phm, phr, h_owner);
+               break;
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+}
+
+/* NOTE: HPI_Message() must be defined in the driver as a wrapper for
+ * HPI_MessageEx so that functions in hpifunc.c compile.
+ */
+void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+       HPI_DEBUG_MESSAGE(DEBUG, phm);
+
+       if (phm->type != HPI_TYPE_MESSAGE) {
+               hpi_init_response(phr, phm->object, phm->function,
+                       HPI_ERROR_INVALID_TYPE);
+               return;
+       }
+
+       if (phm->adapter_index >= HPI_MAX_ADAPTERS
+               && phm->adapter_index != HPIMSGX_ALLADAPTERS) {
+               hpi_init_response(phr, phm->object, phm->function,
+                       HPI_ERROR_BAD_ADAPTER_NUMBER);
+               return;
+       }
+
+       switch (phm->object) {
+       case HPI_OBJ_SUBSYSTEM:
+               subsys_message(phm, phr, h_owner);
+               break;
+
+       case HPI_OBJ_ADAPTER:
+               adapter_message(phm, phr, h_owner);
+               break;
+
+       case HPI_OBJ_MIXER:
+               mixer_message(phm, phr);
+               break;
+
+       case HPI_OBJ_OSTREAM:
+               outstream_message(phm, phr, h_owner);
+               break;
+
+       case HPI_OBJ_ISTREAM:
+               instream_message(phm, phr, h_owner);
+               break;
+
+       default:
+               hw_entry_point(phm, phr);
+               break;
+       }
+       HPI_DEBUG_RESPONSE(phr);
+#if 1
+       if (phr->error >= HPI_ERROR_BACKEND_BASE) {
+               void *ep = NULL;
+               char *ep_name;
+
+               HPI_DEBUG_MESSAGE(ERROR, phm);
+
+               if (phm->adapter_index < HPI_MAX_ADAPTERS)
+                       ep = hpi_entry_points[phm->adapter_index];
+
+               /* Don't need this? Have adapter index in debug info
+                  Know at driver load time index->backend mapping */
+               if (ep == HPI_6000)
+                       ep_name = "HPI_6000";
+               else if (ep == HPI_6205)
+                       ep_name = "HPI_6205";
+               else
+                       ep_name = "unknown";
+
+               HPI_DEBUG_LOG(ERROR, "HPI %s response - error# %d\n", ep_name,
+                       phr->error);
+
+               if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)
+                       hpi_debug_data((u16 *)phm,
+                               sizeof(*phm) / sizeof(u16));
+       }
+#endif
+}
+
+static void adapter_open(struct hpi_message *phm, struct hpi_response *phr)
+{
+       HPI_DEBUG_LOG(VERBOSE, "adapter_open\n");
+       memcpy(phr, &rESP_HPI_ADAPTER_OPEN[phm->adapter_index],
+               sizeof(rESP_HPI_ADAPTER_OPEN[0]));
+}
+
+static void adapter_close(struct hpi_message *phm, struct hpi_response *phr)
+{
+       HPI_DEBUG_LOG(VERBOSE, "adapter_close\n");
+       hpi_init_response(phr, HPI_OBJ_ADAPTER, HPI_ADAPTER_CLOSE, 0);
+}
+
+static void mixer_open(struct hpi_message *phm, struct hpi_response *phr)
+{
+       memcpy(phr, &rESP_HPI_MIXER_OPEN[phm->adapter_index],
+               sizeof(rESP_HPI_MIXER_OPEN[0]));
+}
+
+static void mixer_close(struct hpi_message *phm, struct hpi_response *phr)
+{
+       hpi_init_response(phr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE, 0);
+}
+
+static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_OPEN, 0);
+
+       hpios_msgxlock_lock(&msgx_lock);
+
+       if (instream_user_open[phm->adapter_index][phm->obj_index].open_flag)
+               phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
+       else if (rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
+               [phm->obj_index].h.error)
+               memcpy(phr,
+                       &rESP_HPI_ISTREAM_OPEN[phm->adapter_index][phm->
+                               obj_index],
+                       sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
+       else {
+               instream_user_open[phm->adapter_index][phm->
+                       obj_index].open_flag = 1;
+               hpios_msgxlock_un_lock(&msgx_lock);
+
+               /* issue a reset */
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_RESET);
+               hm.adapter_index = phm->adapter_index;
+               hm.obj_index = phm->obj_index;
+               hw_entry_point(&hm, &hr);
+
+               hpios_msgxlock_lock(&msgx_lock);
+               if (hr.error) {
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 0;
+                       phr->error = hr.error;
+               } else {
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 1;
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = h_owner;
+                       memcpy(phr,
+                               &rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
+                               [phm->obj_index],
+                               sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
+               }
+       }
+       hpios_msgxlock_un_lock(&msgx_lock);
+}
+
+static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_CLOSE, 0);
+
+       hpios_msgxlock_lock(&msgx_lock);
+       if (h_owner ==
+               instream_user_open[phm->adapter_index][phm->
+                       obj_index].h_owner) {
+               /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
+                  "instream %d owned by %p\n",
+                  phm->wAdapterIndex, phm->wObjIndex, hOwner); */
+               instream_user_open[phm->adapter_index][phm->
+                       obj_index].h_owner = NULL;
+               hpios_msgxlock_un_lock(&msgx_lock);
+               /* issue a reset */
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_RESET);
+               hm.adapter_index = phm->adapter_index;
+               hm.obj_index = phm->obj_index;
+               hw_entry_point(&hm, &hr);
+               hpios_msgxlock_lock(&msgx_lock);
+               if (hr.error) {
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = h_owner;
+                       phr->error = hr.error;
+               } else {
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 0;
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = NULL;
+               }
+       } else {
+               HPI_DEBUG_LOG(WARNING,
+                       "%p trying to close %d instream %d owned by %p\n",
+                       h_owner, phm->adapter_index, phm->obj_index,
+                       instream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner);
+               phr->error = HPI_ERROR_OBJ_NOT_OPEN;
+       }
+       hpios_msgxlock_un_lock(&msgx_lock);
+}
+
+static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_OPEN, 0);
+
+       hpios_msgxlock_lock(&msgx_lock);
+
+       if (outstream_user_open[phm->adapter_index][phm->obj_index].open_flag)
+               phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
+       else if (rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
+               [phm->obj_index].h.error)
+               memcpy(phr,
+                       &rESP_HPI_OSTREAM_OPEN[phm->adapter_index][phm->
+                               obj_index],
+                       sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
+       else {
+               outstream_user_open[phm->adapter_index][phm->
+                       obj_index].open_flag = 1;
+               hpios_msgxlock_un_lock(&msgx_lock);
+
+               /* issue a reset */
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_RESET);
+               hm.adapter_index = phm->adapter_index;
+               hm.obj_index = phm->obj_index;
+               hw_entry_point(&hm, &hr);
+
+               hpios_msgxlock_lock(&msgx_lock);
+               if (hr.error) {
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 0;
+                       phr->error = hr.error;
+               } else {
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 1;
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = h_owner;
+                       memcpy(phr,
+                               &rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
+                               [phm->obj_index],
+                               sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
+               }
+       }
+       hpios_msgxlock_un_lock(&msgx_lock);
+}
+
+static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner)
+{
+
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_CLOSE, 0);
+
+       hpios_msgxlock_lock(&msgx_lock);
+
+       if (h_owner ==
+               outstream_user_open[phm->adapter_index][phm->
+                       obj_index].h_owner) {
+               /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
+                  "outstream %d owned by %p\n",
+                  phm->wAdapterIndex, phm->wObjIndex, hOwner); */
+               outstream_user_open[phm->adapter_index][phm->
+                       obj_index].h_owner = NULL;
+               hpios_msgxlock_un_lock(&msgx_lock);
+               /* issue a reset */
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_RESET);
+               hm.adapter_index = phm->adapter_index;
+               hm.obj_index = phm->obj_index;
+               hw_entry_point(&hm, &hr);
+               hpios_msgxlock_lock(&msgx_lock);
+               if (hr.error) {
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = h_owner;
+                       phr->error = hr.error;
+               } else {
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].open_flag = 0;
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner = NULL;
+               }
+       } else {
+               HPI_DEBUG_LOG(WARNING,
+                       "%p trying to close %d outstream %d owned by %p\n",
+                       h_owner, phm->adapter_index, phm->obj_index,
+                       outstream_user_open[phm->adapter_index][phm->
+                               obj_index].h_owner);
+               phr->error = HPI_ERROR_OBJ_NOT_OPEN;
+       }
+       hpios_msgxlock_un_lock(&msgx_lock);
+}
+
+static u16 adapter_prepare(u16 adapter)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       /* Open the adapter and streams */
+       u16 i;
+
+       /* call to HPI_ADAPTER_OPEN */
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_OPEN);
+       hm.adapter_index = adapter;
+       hw_entry_point(&hm, &hr);
+       memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
+               sizeof(rESP_HPI_ADAPTER_OPEN[0]));
+       if (hr.error)
+               return hr.error;
+
+       /* call to HPI_ADAPTER_GET_INFO */
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
+               HPI_ADAPTER_GET_INFO);
+       hm.adapter_index = adapter;
+       hw_entry_point(&hm, &hr);
+       if (hr.error)
+               return hr.error;
+
+       aDAPTER_INFO[adapter].num_outstreams = hr.u.a.num_outstreams;
+       aDAPTER_INFO[adapter].num_instreams = hr.u.a.num_instreams;
+       aDAPTER_INFO[adapter].type = hr.u.a.adapter_type;
+
+       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list[adapter] =
+               hr.u.a.adapter_type;
+       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters++;
+       if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters > HPI_MAX_ADAPTERS)
+               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters =
+                       HPI_MAX_ADAPTERS;
+
+       /* call to HPI_OSTREAM_OPEN */
+       for (i = 0; i < aDAPTER_INFO[adapter].num_outstreams; i++) {
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
+                       HPI_OSTREAM_OPEN);
+               hm.adapter_index = adapter;
+               hm.obj_index = i;
+               hw_entry_point(&hm, &hr);
+               memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i], &hr,
+                       sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
+               outstream_user_open[adapter][i].open_flag = 0;
+               outstream_user_open[adapter][i].h_owner = NULL;
+       }
+
+       /* call to HPI_ISTREAM_OPEN */
+       for (i = 0; i < aDAPTER_INFO[adapter].num_instreams; i++) {
+               hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
+                       HPI_ISTREAM_OPEN);
+               hm.adapter_index = adapter;
+               hm.obj_index = i;
+               hw_entry_point(&hm, &hr);
+               memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i], &hr,
+                       sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
+               instream_user_open[adapter][i].open_flag = 0;
+               instream_user_open[adapter][i].h_owner = NULL;
+       }
+
+       /* call to HPI_MIXER_OPEN */
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
+       hm.adapter_index = adapter;
+       hw_entry_point(&hm, &hr);
+       memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
+               sizeof(rESP_HPI_MIXER_OPEN[0]));
+
+       return gRESP_HPI_SUBSYS_FIND_ADAPTERS.h.error;
+}
+
+static void HPIMSGX__reset(u16 adapter_index)
+{
+       int i;
+       u16 adapter;
+       struct hpi_response hr;
+
+       if (adapter_index == HPIMSGX_ALLADAPTERS) {
+               /* reset all responses to contain errors */
+               hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM,
+                       HPI_SUBSYS_FIND_ADAPTERS, 0);
+               memcpy(&gRESP_HPI_SUBSYS_FIND_ADAPTERS, &hr,
+                       sizeof(&gRESP_HPI_SUBSYS_FIND_ADAPTERS));
+
+               for (adapter = 0; adapter < HPI_MAX_ADAPTERS; adapter++) {
+
+                       hpi_init_response(&hr, HPI_OBJ_ADAPTER,
+                               HPI_ADAPTER_OPEN, HPI_ERROR_BAD_ADAPTER);
+                       memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
+                               sizeof(rESP_HPI_ADAPTER_OPEN[adapter]));
+
+                       hpi_init_response(&hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN,
+                               HPI_ERROR_INVALID_OBJ);
+                       memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
+                               sizeof(rESP_HPI_MIXER_OPEN[adapter]));
+
+                       for (i = 0; i < HPI_MAX_STREAMS; i++) {
+                               hpi_init_response(&hr, HPI_OBJ_OSTREAM,
+                                       HPI_OSTREAM_OPEN,
+                                       HPI_ERROR_INVALID_OBJ);
+                               memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i],
+                                       &hr,
+                                       sizeof(rESP_HPI_OSTREAM_OPEN[adapter]
+                                               [i]));
+                               hpi_init_response(&hr, HPI_OBJ_ISTREAM,
+                                       HPI_ISTREAM_OPEN,
+                                       HPI_ERROR_INVALID_OBJ);
+                               memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i],
+                                       &hr,
+                                       sizeof(rESP_HPI_ISTREAM_OPEN[adapter]
+                                               [i]));
+                       }
+               }
+       } else if (adapter_index < HPI_MAX_ADAPTERS) {
+               rESP_HPI_ADAPTER_OPEN[adapter_index].h.error =
+                       HPI_ERROR_BAD_ADAPTER;
+               rESP_HPI_MIXER_OPEN[adapter_index].h.error =
+                       HPI_ERROR_INVALID_OBJ;
+               for (i = 0; i < HPI_MAX_STREAMS; i++) {
+                       rESP_HPI_OSTREAM_OPEN[adapter_index][i].h.error =
+                               HPI_ERROR_INVALID_OBJ;
+                       rESP_HPI_ISTREAM_OPEN[adapter_index][i].h.error =
+                               HPI_ERROR_INVALID_OBJ;
+               }
+               if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
+                       s.aw_adapter_list[adapter_index]) {
+                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.
+                               s.aw_adapter_list[adapter_index] = 0;
+                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters--;
+               }
+       }
+}
+
+static u16 HPIMSGX__init(struct hpi_message *phm,
+       /* HPI_SUBSYS_CREATE_ADAPTER structure with */
+       /* resource list or NULL=find all */
+       struct hpi_response *phr
+       /* response from HPI_ADAPTER_GET_INFO */
+       )
+{
+       hpi_handler_func *entry_point_func;
+       struct hpi_response hr;
+
+       if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters >= HPI_MAX_ADAPTERS)
+               return HPI_ERROR_BAD_ADAPTER_NUMBER;
+
+       /* Init response here so we can pass in previous adapter list */
+       hpi_init_response(&hr, phm->object, phm->function,
+               HPI_ERROR_INVALID_OBJ);
+       memcpy(hr.u.s.aw_adapter_list,
+               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list,
+               sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list));
+
+       entry_point_func =
+               hpi_lookup_entry_point_function(phm->u.s.resource.r.pci);
+
+       if (entry_point_func) {
+               HPI_DEBUG_MESSAGE(DEBUG, phm);
+               entry_point_func(phm, &hr);
+       } else {
+               phr->error = HPI_ERROR_PROCESSING_MESSAGE;
+               return phr->error;
+       }
+       if (hr.error == 0) {
+               /* the adapter was created succesfully
+                  save the mapping for future use */
+               hpi_entry_points[hr.u.s.adapter_index] = entry_point_func;
+               /* prepare adapter (pre-open streams etc.) */
+               HPI_DEBUG_LOG(DEBUG,
+                       "HPI_SUBSYS_CREATE_ADAPTER successful,"
+                       " preparing adapter\n");
+               adapter_prepare(hr.u.s.adapter_index);
+       }
+       memcpy(phr, &hr, hr.size);
+       return phr->error;
+}
+
+static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)
+{
+       int i, adapter, adapter_limit;
+
+       if (!h_owner)
+               return;
+
+       if (adapter_index == HPIMSGX_ALLADAPTERS) {
+               adapter = 0;
+               adapter_limit = HPI_MAX_ADAPTERS;
+       } else {
+               adapter = adapter_index;
+               adapter_limit = adapter + 1;
+       }
+
+       for (; adapter < adapter_limit; adapter++) {
+               /*      printk(KERN_INFO "Cleanup adapter #%d\n",wAdapter); */
+               for (i = 0; i < HPI_MAX_STREAMS; i++) {
+                       if (h_owner ==
+                               outstream_user_open[adapter][i].h_owner) {
+                               struct hpi_message hm;
+                               struct hpi_response hr;
+
+                               HPI_DEBUG_LOG(DEBUG,
+                                       "close adapter %d ostream %d\n",
+                                       adapter, i);
+
+                               hpi_init_message_response(&hm, &hr,
+                                       HPI_OBJ_OSTREAM, HPI_OSTREAM_RESET);
+                               hm.adapter_index = (u16)adapter;
+                               hm.obj_index = (u16)i;
+                               hw_entry_point(&hm, &hr);
+
+                               hm.function = HPI_OSTREAM_HOSTBUFFER_FREE;
+                               hw_entry_point(&hm, &hr);
+
+                               hm.function = HPI_OSTREAM_GROUP_RESET;
+                               hw_entry_point(&hm, &hr);
+
+                               outstream_user_open[adapter][i].open_flag = 0;
+                               outstream_user_open[adapter][i].h_owner =
+                                       NULL;
+                       }
+                       if (h_owner == instream_user_open[adapter][i].h_owner) {
+                               struct hpi_message hm;
+                               struct hpi_response hr;
+
+                               HPI_DEBUG_LOG(DEBUG,
+                                       "close adapter %d istream %d\n",
+                                       adapter, i);
+
+                               hpi_init_message_response(&hm, &hr,
+                                       HPI_OBJ_ISTREAM, HPI_ISTREAM_RESET);
+                               hm.adapter_index = (u16)adapter;
+                               hm.obj_index = (u16)i;
+                               hw_entry_point(&hm, &hr);
+
+                               hm.function = HPI_ISTREAM_HOSTBUFFER_FREE;
+                               hw_entry_point(&hm, &hr);
+
+                               hm.function = HPI_ISTREAM_GROUP_RESET;
+                               hw_entry_point(&hm, &hr);
+
+                               instream_user_open[adapter][i].open_flag = 0;
+                               instream_user_open[adapter][i].h_owner = NULL;
+                       }
+               }
+       }
+}
diff --git a/sound/pci/asihpi/hpimsgx.h b/sound/pci/asihpi/hpimsgx.h
new file mode 100644 (file)
index 0000000..fd49e75
--- /dev/null
@@ -0,0 +1,36 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ HPI Extended Message Handler Functions
+
+(C) Copyright AudioScience Inc. 1997-2003
+******************************************************************************/
+
+#ifndef _HPIMSGX_H_
+#define _HPIMSGX_H_
+
+#include "hpi_internal.h"
+
+#define HPIMSGX_ALLADAPTERS     (0xFFFF)
+
+void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
+       void *h_owner);
+
+#define HPI_MESSAGE_LOWER_LAYER hpi_send_recv_ex
+
+#endif                         /* _HPIMSGX_H_ */
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
new file mode 100644 (file)
index 0000000..7396ac5
--- /dev/null
@@ -0,0 +1,484 @@
+/*******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Common Linux HPI ioctl and module probe/remove functions
+*******************************************************************************/
+#define SOURCEFILE_NAME "hpioctl.c"
+
+#include "hpi_internal.h"
+#include "hpimsginit.h"
+#include "hpidebug.h"
+#include "hpimsgx.h"
+#include "hpioctl.h"
+
+#include <linux/fs.h>
+#include <linux/slab.h>
+#include <linux/moduleparam.h>
+#include <asm/uaccess.h>
+#include <linux/stringify.h>
+
+#ifdef MODULE_FIRMWARE
+MODULE_FIRMWARE("asihpi/dsp5000.bin");
+MODULE_FIRMWARE("asihpi/dsp6200.bin");
+MODULE_FIRMWARE("asihpi/dsp6205.bin");
+MODULE_FIRMWARE("asihpi/dsp6400.bin");
+MODULE_FIRMWARE("asihpi/dsp6600.bin");
+MODULE_FIRMWARE("asihpi/dsp8700.bin");
+MODULE_FIRMWARE("asihpi/dsp8900.bin");
+#endif
+
+static int prealloc_stream_buf;
+module_param(prealloc_stream_buf, int, S_IRUGO);
+MODULE_PARM_DESC(prealloc_stream_buf,
+       "preallocate size for per-adapter stream buffer");
+
+/* Allow the debug level to be changed after module load.
+ E.g.   echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel
+*/
+module_param(hpi_debug_level, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(hpi_debug_level, "debug verbosity 0..5");
+
+/* List of adapters found */
+static struct hpi_adapter adapters[HPI_MAX_ADAPTERS];
+
+/* Wrapper function to HPI_Message to enable dumping of the
+   message and response types.
+*/
+static void hpi_send_recv_f(struct hpi_message *phm, struct hpi_response *phr,
+       struct file *file)
+{
+       int adapter = phm->adapter_index;
+
+       if ((adapter >= HPI_MAX_ADAPTERS || adapter < 0)
+               && (phm->object != HPI_OBJ_SUBSYSTEM))
+               phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
+       else
+               hpi_send_recv_ex(phm, phr, file);
+}
+
+/* This is called from hpifunc.c functions, called by ALSA
+ * (or other kernel process) In this case there is no file descriptor
+ * available for the message cache code
+ */
+void hpi_send_recv(struct hpi_message *phm, struct hpi_response *phr)
+{
+       hpi_send_recv_f(phm, phr, HOWNER_KERNEL);
+}
+
+EXPORT_SYMBOL(hpi_send_recv);
+/* for radio-asihpi */
+
+int asihpi_hpi_release(struct file *file)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+/* HPI_DEBUG_LOG(INFO,"hpi_release file %p, pid %d\n", file, current->pid); */
+       /* close the subsystem just in case the application forgot to. */
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_CLOSE);
+       hpi_send_recv_ex(&hm, &hr, file);
+       return 0;
+}
+
+long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+{
+       struct hpi_ioctl_linux __user *phpi_ioctl_data;
+       void __user *puhm;
+       void __user *puhr;
+       union hpi_message_buffer_v1 *hm;
+       union hpi_response_buffer_v1 *hr;
+       u16 res_max_size;
+       u32 uncopied_bytes;
+       struct hpi_adapter *pa = NULL;
+       int err = 0;
+
+       if (cmd != HPI_IOCTL_LINUX)
+               return -EINVAL;
+
+       hm = kmalloc(sizeof(*hm), GFP_KERNEL);
+       hr = kmalloc(sizeof(*hr), GFP_KERNEL);
+       if (!hm || !hr) {
+               err = -ENOMEM;
+               goto out;
+       }
+
+       phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg;
+
+       /* Read the message and response pointers from user space.  */
+       get_user(puhm, &phpi_ioctl_data->phm);
+       get_user(puhr, &phpi_ioctl_data->phr);
+
+       /* Now read the message size and data from user space.  */
+       get_user(hm->h.size, (u16 __user *)puhm);
+       if (hm->h.size > sizeof(*hm))
+               hm->h.size = sizeof(*hm);
+
+       /*printk(KERN_INFO "message size %d\n", hm->h.wSize); */
+
+       uncopied_bytes = copy_from_user(hm, puhm, hm->h.size);
+       if (uncopied_bytes) {
+               HPI_DEBUG_LOG(ERROR, "uncopied bytes %d\n", uncopied_bytes);
+               err = -EFAULT;
+               goto out;
+       }
+
+       get_user(res_max_size, (u16 __user *)puhr);
+       /* printk(KERN_INFO "user response size %d\n", res_max_size); */
+       if (res_max_size < sizeof(struct hpi_response_header)) {
+               HPI_DEBUG_LOG(WARNING, "small res size %d\n", res_max_size);
+               err = -EFAULT;
+               goto out;
+       }
+
+       pa = &adapters[hm->h.adapter_index];
+       hr->h.size = 0;
+       if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
+               switch (hm->h.function) {
+               case HPI_SUBSYS_CREATE_ADAPTER:
+               case HPI_SUBSYS_DELETE_ADAPTER:
+                       /* Application must not use these functions! */
+                       hr->h.size = sizeof(hr->h);
+                       hr->h.error = HPI_ERROR_INVALID_OPERATION;
+                       hr->h.function = hm->h.function;
+                       uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
+                       if (uncopied_bytes)
+                               err = -EFAULT;
+                       else
+                               err = 0;
+                       goto out;
+
+               default:
+                       hpi_send_recv_f(&hm->m0, &hr->r0, file);
+               }
+       } else {
+               u16 __user *ptr = NULL;
+               u32 size = 0;
+
+               /* -1=no data 0=read from user mem, 1=write to user mem */
+               int wrflag = -1;
+               u32 adapter = hm->h.adapter_index;
+
+               if ((hm->h.adapter_index > HPI_MAX_ADAPTERS) || (!pa->type)) {
+                       hpi_init_response(&hr->r0, HPI_OBJ_ADAPTER,
+                               HPI_ADAPTER_OPEN,
+                               HPI_ERROR_BAD_ADAPTER_NUMBER);
+
+                       uncopied_bytes =
+                               copy_to_user(puhr, hr, sizeof(hr->h));
+                       if (uncopied_bytes)
+                               err = -EFAULT;
+                       else
+                               err = 0;
+                       goto out;
+               }
+
+               if (mutex_lock_interruptible(&adapters[adapter].mutex)) {
+                       err = -EINTR;
+                       goto out;
+               }
+
+               /* Dig out any pointers embedded in the message.  */
+               switch (hm->h.function) {
+               case HPI_OSTREAM_WRITE:
+               case HPI_ISTREAM_READ:{
+                               /* Yes, sparse, this is correct. */
+                               ptr = (u16 __user *)hm->m0.u.d.u.data.pb_data;
+                               size = hm->m0.u.d.u.data.data_size;
+
+                               /* Allocate buffer according to application request.
+                                  ?Is it better to alloc/free for the duration
+                                  of the transaction?
+                                */
+                               if (pa->buffer_size < size) {
+                                       HPI_DEBUG_LOG(DEBUG,
+                                               "realloc adapter %d stream "
+                                               "buffer from %zd to %d\n",
+                                               hm->h.adapter_index,
+                                               pa->buffer_size, size);
+                                       if (pa->p_buffer) {
+                                               pa->buffer_size = 0;
+                                               vfree(pa->p_buffer);
+                                       }
+                                       pa->p_buffer = vmalloc(size);
+                                       if (pa->p_buffer)
+                                               pa->buffer_size = size;
+                                       else {
+                                               HPI_DEBUG_LOG(ERROR,
+                                                       "HPI could not allocate "
+                                                       "stream buffer size %d\n",
+                                                       size);
+
+                                               mutex_unlock(&adapters
+                                                       [adapter].mutex);
+                                               err = -EINVAL;
+                                               goto out;
+                                       }
+                               }
+
+                               hm->m0.u.d.u.data.pb_data = pa->p_buffer;
+                               if (hm->h.function == HPI_ISTREAM_READ)
+                                       /* from card, WRITE to user mem */
+                                       wrflag = 1;
+                               else
+                                       wrflag = 0;
+                               break;
+                       }
+
+               default:
+                       size = 0;
+                       break;
+               }
+
+               if (size && (wrflag == 0)) {
+                       uncopied_bytes =
+                               copy_from_user(pa->p_buffer, ptr, size);
+                       if (uncopied_bytes)
+                               HPI_DEBUG_LOG(WARNING,
+                                       "missed %d of %d "
+                                       "bytes from user\n", uncopied_bytes,
+                                       size);
+               }
+
+               hpi_send_recv_f(&hm->m0, &hr->r0, file);
+
+               if (size && (wrflag == 1)) {
+                       uncopied_bytes =
+                               copy_to_user(ptr, pa->p_buffer, size);
+                       if (uncopied_bytes)
+                               HPI_DEBUG_LOG(WARNING,
+                                       "missed %d of %d " "bytes to user\n",
+                                       uncopied_bytes, size);
+               }
+
+               mutex_unlock(&adapters[adapter].mutex);
+       }
+
+       /* on return response size must be set */
+       /*printk(KERN_INFO "response size %d\n", hr->h.wSize); */
+
+       if (!hr->h.size) {
+               HPI_DEBUG_LOG(ERROR, "response zero size\n");
+               err = -EFAULT;
+               goto out;
+       }
+
+       if (hr->h.size > res_max_size) {
+               HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,
+                       res_max_size);
+               /*HPI_DEBUG_MESSAGE(ERROR, hm); */
+               err = -EFAULT;
+               goto out;
+       }
+
+       uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
+       if (uncopied_bytes) {
+               HPI_DEBUG_LOG(ERROR, "uncopied bytes %d\n", uncopied_bytes);
+               err = -EFAULT;
+               goto out;
+       }
+
+out:
+       kfree(hm);
+       kfree(hr);
+       return err;
+}
+
+int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
+       const struct pci_device_id *pci_id)
+{
+       int err, idx, nm;
+       unsigned int memlen;
+       struct hpi_message hm;
+       struct hpi_response hr;
+       struct hpi_adapter adapter;
+       struct hpi_pci pci;
+
+       memset(&adapter, 0, sizeof(adapter));
+
+       printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n",
+               pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor,
+               pci_dev->subsystem_device, pci_dev->devfn);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_CREATE_ADAPTER);
+       hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,
+               HPI_ERROR_PROCESSING_MESSAGE);
+
+       hm.adapter_index = -1;  /* an invalid index */
+
+       /* fill in HPI_PCI information from kernel provided information */
+       adapter.pci = pci_dev;
+
+       nm = HPI_MAX_ADAPTER_MEM_SPACES;
+
+       for (idx = 0; idx < nm; idx++) {
+               HPI_DEBUG_LOG(INFO, "resource %d %s %08llx-%08llx %04llx\n",
+                       idx, pci_dev->resource[idx].name,
+                       (unsigned long long)pci_resource_start(pci_dev, idx),
+                       (unsigned long long)pci_resource_end(pci_dev, idx),
+                       (unsigned long long)pci_resource_flags(pci_dev, idx));
+
+               if (pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM) {
+                       memlen = pci_resource_len(pci_dev, idx);
+                       adapter.ap_remapped_mem_base[idx] =
+                               ioremap(pci_resource_start(pci_dev, idx),
+                               memlen);
+                       if (!adapter.ap_remapped_mem_base[idx]) {
+                               HPI_DEBUG_LOG(ERROR,
+                                       "ioremap failed, aborting\n");
+                               /* unmap previously mapped pci mem space */
+                               goto err;
+                       }
+               }
+
+               pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];
+       }
+
+       /* could replace Pci with direct pointer to pci_dev for linux
+          Instead wrap accessor functions for IDs etc.
+          Would it work for windows?
+        */
+       pci.bus_number = pci_dev->bus->number;
+       pci.vendor_id = (u16)pci_dev->vendor;
+       pci.device_id = (u16)pci_dev->device;
+       pci.subsys_vendor_id = (u16)(pci_dev->subsystem_vendor & 0xffff);
+       pci.subsys_device_id = (u16)(pci_dev->subsystem_device & 0xffff);
+       pci.device_number = pci_dev->devfn;
+       pci.interrupt = pci_dev->irq;
+       pci.p_os_data = pci_dev;
+
+       hm.u.s.resource.bus_type = HPI_BUS_PCI;
+       hm.u.s.resource.r.pci = &pci;
+
+       /* call CreateAdapterObject on the relevant hpi module */
+       hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
+       if (hr.error)
+               goto err;
+
+       if (prealloc_stream_buf) {
+               adapter.p_buffer = vmalloc(prealloc_stream_buf);
+               if (!adapter.p_buffer) {
+                       HPI_DEBUG_LOG(ERROR,
+                               "HPI could not allocate "
+                               "kernel buffer size %d\n",
+                               prealloc_stream_buf);
+                       goto err;
+               }
+       }
+
+       adapter.index = hr.u.s.adapter_index;
+       adapter.type = hr.u.s.aw_adapter_list[adapter.index];
+       hm.adapter_index = adapter.index;
+
+       err = hpi_adapter_open(NULL, adapter.index);
+       if (err)
+               goto err;
+
+       adapter.snd_card_asihpi = NULL;
+       /* WARNING can't init mutex in 'adapter'
+        * and then copy it to adapters[] ?!?!
+        */
+       adapters[hr.u.s.adapter_index] = adapter;
+       mutex_init(&adapters[adapter.index].mutex);
+       pci_set_drvdata(pci_dev, &adapters[adapter.index]);
+
+       printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n",
+               adapter.type, adapter.index);
+
+       return 0;
+
+err:
+       for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
+               if (adapter.ap_remapped_mem_base[idx]) {
+                       iounmap(adapter.ap_remapped_mem_base[idx]);
+                       adapter.ap_remapped_mem_base[idx] = NULL;
+               }
+       }
+
+       if (adapter.p_buffer) {
+               adapter.buffer_size = 0;
+               vfree(adapter.p_buffer);
+       }
+
+       HPI_DEBUG_LOG(ERROR, "adapter_probe failed\n");
+       return -ENODEV;
+}
+
+void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
+{
+       int idx;
+       struct hpi_message hm;
+       struct hpi_response hr;
+       struct hpi_adapter *pa;
+       pa = (struct hpi_adapter *)pci_get_drvdata(pci_dev);
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_DELETE_ADAPTER);
+       hm.adapter_index = pa->index;
+       hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
+
+       /* unmap PCI memory space, mapped during device init. */
+       for (idx = 0; idx < HPI_MAX_ADAPTER_MEM_SPACES; idx++) {
+               if (pa->ap_remapped_mem_base[idx]) {
+                       iounmap(pa->ap_remapped_mem_base[idx]);
+                       pa->ap_remapped_mem_base[idx] = NULL;
+               }
+       }
+
+       if (pa->p_buffer) {
+               pa->buffer_size = 0;
+               vfree(pa->p_buffer);
+       }
+
+       pci_set_drvdata(pci_dev, NULL);
+       /*
+          printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x),"
+          " HPI index # %d, removed.\n",
+          pci_dev->vendor, pci_dev->device,
+          pci_dev->subsystem_vendor,
+          pci_dev->subsystem_device, pci_dev->devfn,
+          pa->index);
+        */
+}
+
+void __init asihpi_init(void)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       memset(adapters, 0, sizeof(adapters));
+
+       printk(KERN_INFO "ASIHPI driver %d.%02d.%02d\n",
+               HPI_VER_MAJOR(HPI_VER), HPI_VER_MINOR(HPI_VER),
+               HPI_VER_RELEASE(HPI_VER));
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_DRIVER_LOAD);
+       hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
+}
+
+void asihpi_exit(void)
+{
+       struct hpi_message hm;
+       struct hpi_response hr;
+
+       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
+               HPI_SUBSYS_DRIVER_UNLOAD);
+       hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
+}
diff --git a/sound/pci/asihpi/hpioctl.h b/sound/pci/asihpi/hpioctl.h
new file mode 100644 (file)
index 0000000..847f72f
--- /dev/null
@@ -0,0 +1,38 @@
+/*******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+Linux HPI ioctl, and shared module init functions
+*******************************************************************************/
+
+int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
+       const struct pci_device_id *pci_id);
+void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev);
+void __init asihpi_init(void);
+void __exit asihpi_exit(void);
+
+int asihpi_hpi_release(struct file *file);
+
+long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
+
+/* This is called from hpifunc.c functions, called by ALSA
+ * (or other kernel process) In this case there is no file descriptor
+ * available for the message cache code
+ */
+void hpi_send_recv(struct hpi_message *phm, struct hpi_response *phr);
+
+#define HOWNER_KERNEL ((void *)-1)
diff --git a/sound/pci/asihpi/hpios.c b/sound/pci/asihpi/hpios.c
new file mode 100644 (file)
index 0000000..de615cf
--- /dev/null
@@ -0,0 +1,114 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+HPI Operating System function implementation for Linux
+
+(C) Copyright AudioScience Inc. 1997-2003
+******************************************************************************/
+#define SOURCEFILE_NAME "hpios.c"
+#include "hpi_internal.h"
+#include "hpidebug.h"
+#include <linux/delay.h>
+#include <linux/sched.h>
+
+void hpios_delay_micro_seconds(u32 num_micro_sec)
+{
+       if ((usecs_to_jiffies(num_micro_sec) > 1) && !in_interrupt()) {
+               /* MUST NOT SCHEDULE IN INTERRUPT CONTEXT! */
+               schedule_timeout_uninterruptible(usecs_to_jiffies
+                       (num_micro_sec));
+       } else if (num_micro_sec <= 2000)
+               udelay(num_micro_sec);
+       else
+               mdelay(num_micro_sec / 1000);
+
+}
+
+void hpios_locked_mem_init(void)
+{
+}
+
+/** Allocated an area of locked memory for bus master DMA operations.
+
+On error, return -ENOMEM, and *pMemArea.size = 0
+*/
+u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_mem_area, u32 size,
+       struct pci_dev *pdev)
+{
+       /*?? any benefit in using managed dmam_alloc_coherent? */
+       p_mem_area->vaddr =
+               dma_alloc_coherent(&pdev->dev, size, &p_mem_area->dma_handle,
+               GFP_DMA32 | GFP_KERNEL);
+
+       if (p_mem_area->vaddr) {
+               HPI_DEBUG_LOG(DEBUG, "allocated %d bytes, dma 0x%x vma %p\n",
+                       size, (unsigned int)p_mem_area->dma_handle,
+                       p_mem_area->vaddr);
+               p_mem_area->pdev = &pdev->dev;
+               p_mem_area->size = size;
+               return 0;
+       } else {
+               HPI_DEBUG_LOG(WARNING,
+                       "failed to allocate %d bytes locked memory\n", size);
+               p_mem_area->size = 0;
+               return -ENOMEM;
+       }
+}
+
+u16 hpios_locked_mem_free(struct consistent_dma_area *p_mem_area)
+{
+       if (p_mem_area->size) {
+               dma_free_coherent(p_mem_area->pdev, p_mem_area->size,
+                       p_mem_area->vaddr, p_mem_area->dma_handle);
+               HPI_DEBUG_LOG(DEBUG, "freed %lu bytes, dma 0x%x vma %p\n",
+                       (unsigned long)p_mem_area->size,
+                       (unsigned int)p_mem_area->dma_handle,
+                       p_mem_area->vaddr);
+               p_mem_area->size = 0;
+               return 0;
+       } else {
+               return 1;
+       }
+}
+
+void hpios_locked_mem_free_all(void)
+{
+}
+
+void __iomem *hpios_map_io(struct pci_dev *pci_dev, int idx,
+       unsigned int length)
+{
+       HPI_DEBUG_LOG(DEBUG, "mapping %d %s %08llx-%08llx %04llx len 0x%x\n",
+               idx, pci_dev->resource[idx].name,
+               (unsigned long long)pci_resource_start(pci_dev, idx),
+               (unsigned long long)pci_resource_end(pci_dev, idx),
+               (unsigned long long)pci_resource_flags(pci_dev, idx), length);
+
+       if (!(pci_resource_flags(pci_dev, idx) & IORESOURCE_MEM)) {
+               HPI_DEBUG_LOG(ERROR, "not an io memory resource\n");
+               return NULL;
+       }
+
+       if (length > pci_resource_len(pci_dev, idx)) {
+               HPI_DEBUG_LOG(ERROR, "resource too small for requested %d \n",
+                       length);
+               return NULL;
+       }
+
+       return ioremap(pci_resource_start(pci_dev, idx), length);
+}
diff --git a/sound/pci/asihpi/hpios.h b/sound/pci/asihpi/hpios.h
new file mode 100644 (file)
index 0000000..a62c3f1
--- /dev/null
@@ -0,0 +1,178 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+HPI Operating System Specific macros for Linux Kernel driver
+
+(C) Copyright AudioScience Inc. 1997-2003
+******************************************************************************/
+#ifndef _HPIOS_H_
+#define _HPIOS_H_
+
+#undef HPI_OS_LINUX_KERNEL
+#define HPI_OS_LINUX_KERNEL
+
+#define HPI_OS_DEFINED
+#define HPI_KERNEL_MODE
+
+#define HPI_REASSIGN_DUPLICATE_ADAPTER_IDX
+
+#include <linux/io.h>
+#include <asm/system.h>
+#include <linux/ioctl.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/device.h>
+#include <linux/firmware.h>
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+
+#define HPI_NO_OS_FILE_OPS
+
+#ifdef CONFIG_64BIT
+#define HPI64BIT
+#endif
+
+/** Details of a memory area allocated with  pci_alloc_consistent
+Need all info for parameters to pci_free_consistent
+*/
+struct consistent_dma_area {
+       struct device *pdev;
+       /* looks like dma-mapping dma_devres ?! */
+       size_t size;
+       void *vaddr;
+       dma_addr_t dma_handle;
+};
+
+static inline u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
+       *locked_mem_handle, u32 *p_physical_addr)
+{
+       *p_physical_addr = locked_mem_handle->dma_handle;
+       return 0;
+}
+
+static inline u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
+       *locked_mem_handle, void **pp_virtual_addr)
+{
+       *pp_virtual_addr = locked_mem_handle->vaddr;
+       return 0;
+}
+
+static inline u16 hpios_locked_mem_valid(struct consistent_dma_area
+       *locked_mem_handle)
+{
+       return locked_mem_handle->size != 0;
+}
+
+struct hpi_ioctl_linux {
+       void __user *phm;
+       void __user *phr;
+};
+
+/* Conflict?: H is already used by a number of drivers hid, bluetooth hci,
+   and some sound drivers sb16, hdsp, emu10k. AFAIK 0xFC is ununsed command
+*/
+#define HPI_IOCTL_LINUX _IOWR('H', 0xFC, struct hpi_ioctl_linux)
+
+#define HPI_DEBUG_FLAG_ERROR   KERN_ERR
+#define HPI_DEBUG_FLAG_WARNING KERN_WARNING
+#define HPI_DEBUG_FLAG_NOTICE  KERN_NOTICE
+#define HPI_DEBUG_FLAG_INFO    KERN_INFO
+#define HPI_DEBUG_FLAG_DEBUG   KERN_DEBUG
+#define HPI_DEBUG_FLAG_VERBOSE KERN_DEBUG      /* kernel has no verbose */
+
+#include <linux/spinlock.h>
+
+#define HPI_LOCKING
+
+struct hpios_spinlock {
+       spinlock_t lock;        /* SEE hpios_spinlock */
+       int lock_context;
+};
+
+/* The reason for all this evilness is that ALSA calls some of a drivers
+ * operators in atomic context, and some not.  But all our functions channel
+ * through the HPI_Message conduit, so we can't handle the different context
+ * per function
+ */
+#define IN_LOCK_BH 1
+#define IN_LOCK_IRQ 0
+static inline void cond_lock(struct hpios_spinlock *l)
+{
+       if (irqs_disabled()) {
+               /* NO bh or isr can execute on this processor,
+                  so ordinary lock will do
+                */
+               spin_lock(&((l)->lock));
+               l->lock_context = IN_LOCK_IRQ;
+       } else {
+               spin_lock_bh(&((l)->lock));
+               l->lock_context = IN_LOCK_BH;
+       }
+}
+
+static inline void cond_unlock(struct hpios_spinlock *l)
+{
+       if (l->lock_context == IN_LOCK_BH)
+               spin_unlock_bh(&((l)->lock));
+       else
+               spin_unlock(&((l)->lock));
+}
+
+#define hpios_msgxlock_init(obj)      spin_lock_init(&(obj)->lock)
+#define hpios_msgxlock_lock(obj)   cond_lock(obj)
+#define hpios_msgxlock_un_lock(obj) cond_unlock(obj)
+
+#define hpios_dsplock_init(obj)       spin_lock_init(&(obj)->dsp_lock.lock)
+#define hpios_dsplock_lock(obj)    cond_lock(&(obj)->dsp_lock)
+#define hpios_dsplock_unlock(obj)  cond_unlock(&(obj)->dsp_lock)
+
+#ifdef CONFIG_SND_DEBUG
+#define HPI_DEBUG
+#endif
+
+#define HPI_ALIST_LOCKING
+#define hpios_alistlock_init(obj)    spin_lock_init(&((obj)->list_lock.lock))
+#define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
+#define hpios_alistlock_un_lock(obj) spin_unlock(&((obj)->list_lock.lock))
+
+struct hpi_adapter {
+       /* mutex prevents contention for one card
+          between multiple user programs (via ioctl) */
+       struct mutex mutex;
+       u16 index;
+       u16 type;
+
+       /* ALSA card structure */
+       void *snd_card_asihpi;
+
+       char *p_buffer;
+       size_t buffer_size;
+       struct pci_dev *pci;
+       void __iomem *ap_remapped_mem_base[HPI_MAX_ADAPTER_MEM_SPACES];
+};
+
+static inline void hpios_unmap_io(void __iomem *addr,
+       unsigned long size)
+{
+       iounmap(addr);
+}
+
+void __iomem *hpios_map_io(struct pci_dev *pci_dev, int idx,
+       unsigned int length);
+
+#endif
diff --git a/sound/pci/asihpi/hpipcida.h b/sound/pci/asihpi/hpipcida.h
new file mode 100644 (file)
index 0000000..bb30868
--- /dev/null
@@ -0,0 +1,37 @@
+/******************************************************************************
+
+    AudioScience HPI driver
+    Copyright (C) 1997-2010  AudioScience Inc. <support@audioscience.com>
+
+    This program 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;
+
+    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
+
+ Array initializer for PCI card IDs
+
+(C) Copyright AudioScience Inc. 1998-2003
+*******************************************************************************/
+
+/*NOTE: when adding new lines to this header file
+  they MUST be grouped by HPI entry point.
+*/
+
+{
+HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_DSP6205,
+               HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
+               (kernel_ulong_t) HPI_6205}
+, {
+HPI_PCI_VENDOR_ID_TI, HPI_PCI_DEV_ID_PCI2040,
+               HPI_PCI_VENDOR_ID_AUDIOSCIENCE, PCI_ANY_ID, 0, 0,
+               (kernel_ulong_t) HPI_6000}
+, {
+0}
index 9edc650..6772070 100644 (file)
@@ -1139,40 +1139,28 @@ static void snd_cs4281_proc_read(struct snd_info_entry *entry,
        snd_iprintf(buffer, "Spurious end IRQs    : %u\n", chip->spurious_dtc_irq);
 }
 
-static long snd_cs4281_BA0_read(struct snd_info_entry *entry,
-                               void *file_private_data,
-                               struct file *file, char __user *buf,
-                               unsigned long count, unsigned long pos)
+static ssize_t snd_cs4281_BA0_read(struct snd_info_entry *entry,
+                                  void *file_private_data,
+                                  struct file *file, char __user *buf,
+                                  size_t count, loff_t pos)
 {
-       long size;
        struct cs4281 *chip = entry->private_data;
        
-       size = count;
-       if (pos + size > CS4281_BA0_SIZE)
-               size = (long)CS4281_BA0_SIZE - pos;
-       if (size > 0) {
-               if (copy_to_user_fromio(buf, chip->ba0 + pos, size))
-                       return -EFAULT;
-       }
-       return size;
+       if (copy_to_user_fromio(buf, chip->ba0 + pos, count))
+               return -EFAULT;
+       return count;
 }
 
-static long snd_cs4281_BA1_read(struct snd_info_entry *entry,
-                               void *file_private_data,
-                               struct file *file, char __user *buf,
-                               unsigned long count, unsigned long pos)
+static ssize_t snd_cs4281_BA1_read(struct snd_info_entry *entry,
+                                  void *file_private_data,
+                                  struct file *file, char __user *buf,
+                                  size_t count, loff_t pos)
 {
-       long size;
        struct cs4281 *chip = entry->private_data;
        
-       size = count;
-       if (pos + size > CS4281_BA1_SIZE)
-               size = (long)CS4281_BA1_SIZE - pos;
-       if (size > 0) {
-               if (copy_to_user_fromio(buf, chip->ba1 + pos, size))
-                       return -EFAULT;
-       }
-       return size;
+       if (copy_to_user_fromio(buf, chip->ba1 + pos, count))
+               return -EFAULT;
+       return count;
 }
 
 static struct snd_info_entry_ops snd_cs4281_proc_ops_BA0 = {
index 3f99a5e..aad3708 100644 (file)
@@ -2657,21 +2657,16 @@ static inline void snd_cs46xx_remove_gameport(struct snd_cs46xx *chip) { }
  *  proc interface
  */
 
-static long snd_cs46xx_io_read(struct snd_info_entry *entry, void *file_private_data,
-                              struct file *file, char __user *buf,
-                              unsigned long count, unsigned long pos)
+static ssize_t snd_cs46xx_io_read(struct snd_info_entry *entry,
+                                 void *file_private_data,
+                                 struct file *file, char __user *buf,
+                                 size_t count, loff_t pos)
 {
-       long size;
        struct snd_cs46xx_region *region = entry->private_data;
        
-       size = count;
-       if (pos + (size_t)size > region->size)
-               size = region->size - pos;
-       if (size > 0) {
-               if (copy_to_user_fromio(buf, region->remap_addr + pos, size))
-                       return -EFAULT;
-       }
-       return size;
+       if (copy_to_user_fromio(buf, region->remap_addr + pos, count))
+               return -EFAULT;
+       return count;
 }
 
 static struct snd_info_entry_ops snd_cs46xx_proc_io_ops = {
index f18bd62..66c7fb3 100644 (file)
@@ -1787,7 +1787,7 @@ int __devinit snd_emu10k1_create(struct snd_card *card,
        else if (subsystem)
                snd_printdd("Sound card name = %s, "
                        "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. "
-                       "Forced to subsytem = 0x%x\n",  c->name,
+                       "Forced to subsystem = 0x%x\n", c->name,
                        pci->vendor, pci->device, emu->serial, c->subsystem);
        else
                snd_printdd("Sound card name = %s, "
index baa7cd5..bc38dd4 100644 (file)
@@ -341,15 +341,17 @@ static void snd_emu10k1_proc_acode_read(struct snd_info_entry *entry,
 #define TOTAL_SIZE_CODE                (0x200*8)
 #define A_TOTAL_SIZE_CODE      (0x400*8)
 
-static long snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
-                                   void *file_private_data,
-                                   struct file *file, char __user *buf,
-                                   unsigned long count, unsigned long pos)
+static ssize_t snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
+                                      void *file_private_data,
+                                      struct file *file, char __user *buf,
+                                      size_t count, loff_t pos)
 {
-       long size;
        struct snd_emu10k1 *emu = entry->private_data;
        unsigned int offset;
        int tram_addr = 0;
+       unsigned int *tmp;
+       long res;
+       unsigned int idx;
        
        if (!strcmp(entry->name, "fx8010_tram_addr")) {
                offset = TANKMEMADDRREGBASE;
@@ -361,30 +363,25 @@ static long snd_emu10k1_fx8010_read(struct snd_info_entry *entry,
        } else {
                offset = emu->audigy ? A_FXGPREGBASE : FXGPREGBASE;
        }
-       size = count;
-       if (pos + size > entry->size)
-               size = (long)entry->size - pos;
-       if (size > 0) {
-               unsigned int *tmp;
-               long res;
-               unsigned int idx;
-               if ((tmp = kmalloc(size + 8, GFP_KERNEL)) == NULL)
-                       return -ENOMEM;
-               for (idx = 0; idx < ((pos & 3) + size + 3) >> 2; idx++)
-                       if (tram_addr && emu->audigy) {
-                               tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0) >> 11;
-                               tmp[idx] |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
-                       } else 
-                               tmp[idx] = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
-               if (copy_to_user(buf, ((char *)tmp) + (pos & 3), size))
-                       res = -EFAULT;
-               else {
-                       res = size;
+
+       tmp = kmalloc(count + 8, GFP_KERNEL);
+       if (!tmp)
+               return -ENOMEM;
+       for (idx = 0; idx < ((pos & 3) + count + 3) >> 2; idx++) {
+               unsigned int val;
+               val = snd_emu10k1_ptr_read(emu, offset + idx + (pos >> 2), 0);
+               if (tram_addr && emu->audigy) {
+                       val >>= 11;
+                       val |= snd_emu10k1_ptr_read(emu, 0x100 + idx + (pos >> 2), 0) << 20;
                }
-               kfree(tmp);
-               return res;
+               tmp[idx] = val;
        }
-       return 0;
+       if (copy_to_user(buf, ((char *)tmp) + (pos & 3), count))
+               res = -EFAULT;
+       else
+               res = count;
+       kfree(tmp);
+       return res;
 }
 
 static void snd_emu10k1_proc_voices_read(struct snd_info_entry *entry, 
index ecaea9f..23a58f0 100644 (file)
 #include <linux/gameport.h>
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
+#include <linux/input.h>
 
 #include <sound/core.h>
 #include <sound/pcm.h>
@@ -517,14 +518,9 @@ struct es1968 {
 
        /* ALSA Stuff */
        struct snd_ac97 *ac97;
-       struct snd_kcontrol *master_switch; /* for h/w volume control */
-       struct snd_kcontrol *master_volume;
-
        struct snd_rawmidi *rmidi;
 
        spinlock_t reg_lock;
-       spinlock_t ac97_lock;
-       struct tasklet_struct hwvol_tq;
        unsigned int in_suspend;
 
        /* Maestro Stuff */
@@ -547,6 +543,16 @@ struct es1968 {
 #ifdef SUPPORT_JOYSTICK
        struct gameport *gameport;
 #endif
+
+#ifdef CONFIG_SND_ES1968_INPUT
+       struct input_dev *input_dev;
+       char phys[64];                  /* physical device path */
+#else
+       struct snd_kcontrol *master_switch; /* for h/w volume control */
+       struct snd_kcontrol *master_volume;
+       spinlock_t ac97_lock;
+       struct tasklet_struct hwvol_tq;
+#endif
 };
 
 static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id);
@@ -632,28 +638,38 @@ static int snd_es1968_ac97_wait_poll(struct es1968 *chip)
 static void snd_es1968_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
 {
        struct es1968 *chip = ac97->private_data;
+#ifndef CONFIG_SND_ES1968_INPUT
        unsigned long flags;
+#endif
 
        snd_es1968_ac97_wait(chip);
 
        /* Write the bus */
+#ifndef CONFIG_SND_ES1968_INPUT
        spin_lock_irqsave(&chip->ac97_lock, flags);
+#endif
        outw(val, chip->io_port + ESM_AC97_DATA);
        /*msleep(1);*/
        outb(reg, chip->io_port + ESM_AC97_INDEX);
        /*msleep(1);*/
+#ifndef CONFIG_SND_ES1968_INPUT
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#endif
 }
 
 static unsigned short snd_es1968_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 {
        u16 data = 0;
        struct es1968 *chip = ac97->private_data;
+#ifndef CONFIG_SND_ES1968_INPUT
        unsigned long flags;
+#endif
 
        snd_es1968_ac97_wait(chip);
 
+#ifndef CONFIG_SND_ES1968_INPUT
        spin_lock_irqsave(&chip->ac97_lock, flags);
+#endif
        outb(reg | 0x80, chip->io_port + ESM_AC97_INDEX);
        /*msleep(1);*/
 
@@ -661,7 +677,9 @@ static unsigned short snd_es1968_ac97_read(struct snd_ac97 *ac97, unsigned short
                data = inw(chip->io_port + ESM_AC97_DATA);
                /*msleep(1);*/
        }
+#ifndef CONFIG_SND_ES1968_INPUT
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#endif
 
        return data;
 }
@@ -1874,13 +1892,17 @@ static void snd_es1968_update_pcm(struct es1968 *chip, struct esschan *es)
        }
 }
 
-/*
- */
+/* The hardware volume works by incrementing / decrementing 2 counters
+   (without wrap around) in response to volume button presses and then
+   generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
+   of a byte wide register. The meaning of bits 0 and 4 is unknown. */
 static void es1968_update_hw_volume(unsigned long private_data)
 {
        struct es1968 *chip = (struct es1968 *) private_data;
        int x, val;
+#ifndef CONFIG_SND_ES1968_INPUT
        unsigned long flags;
+#endif
 
        /* Figure out which volume control button was pushed,
           based on differences from the default register
@@ -1895,6 +1917,7 @@ static void es1968_update_hw_volume(unsigned long private_data)
        if (chip->in_suspend)
                return;
 
+#ifndef CONFIG_SND_ES1968_INPUT
        if (! chip->master_switch || ! chip->master_volume)
                return;
 
@@ -1937,6 +1960,35 @@ static void es1968_update_hw_volume(unsigned long private_data)
                break;
        }
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#else
+       if (!chip->input_dev)
+               return;
+
+       val = 0;
+       switch (x) {
+       case 0x88:
+               /* The counters have not changed, yet we've received a HV
+                  interrupt. According to tests run by various people this
+                  happens when pressing the mute button. */
+               val = KEY_MUTE;
+               break;
+       case 0xaa:
+               /* counters increased by 1 -> volume up */
+               val = KEY_VOLUMEUP;
+               break;
+       case 0x66:
+               /* counters decreased by 1 -> volume down */
+               val = KEY_VOLUMEDOWN;
+               break;
+       }
+
+       if (val) {
+               input_report_key(chip->input_dev, val, 1);
+               input_sync(chip->input_dev);
+               input_report_key(chip->input_dev, val, 0);
+               input_sync(chip->input_dev);
+       }
+#endif
 }
 
 /*
@@ -1953,7 +2005,11 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)
        outw(inw(chip->io_port + 4) & 1, chip->io_port + 4);
 
        if (event & ESM_HWVOL_IRQ)
+#ifdef CONFIG_SND_ES1968_INPUT
+               es1968_update_hw_volume((unsigned long)chip);
+#else
                tasklet_schedule(&chip->hwvol_tq); /* we'll do this later */
+#endif
 
        /* else ack 'em all, i imagine */
        outb(0xFF, chip->io_port + 0x1A);
@@ -1993,7 +2049,9 @@ snd_es1968_mixer(struct es1968 *chip)
 {
        struct snd_ac97_bus *pbus;
        struct snd_ac97_template ac97;
+#ifndef CONFIG_SND_ES1968_INPUT
        struct snd_ctl_elem_id elem_id;
+#endif
        int err;
        static struct snd_ac97_bus_ops ops = {
                .write = snd_es1968_ac97_write,
@@ -2009,6 +2067,7 @@ snd_es1968_mixer(struct es1968 *chip)
        if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97)) < 0)
                return err;
 
+#ifndef CONFIG_SND_ES1968_INPUT
        /* attach master switch / volumes for h/w volume control */
        memset(&elem_id, 0, sizeof(elem_id));
        elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
@@ -2018,6 +2077,7 @@ snd_es1968_mixer(struct es1968 *chip)
        elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
        strcpy(elem_id.name, "Master Playback Volume");
        chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
+#endif
 
        return 0;
 }
@@ -2341,6 +2401,7 @@ static void snd_es1968_start_irq(struct es1968 *chip)
        w = ESM_HIRQ_DSIE | ESM_HIRQ_HW_VOLUME;
        if (chip->rmidi)
                w |= ESM_HIRQ_MPU401;
+       outb(w, chip->io_port + 0x1A);
        outw(w, chip->io_port + ESM_PORT_HOST_IRQ);
 }
 
@@ -2474,8 +2535,49 @@ static inline int snd_es1968_create_gameport(struct es1968 *chip, int dev) { ret
 static inline void snd_es1968_free_gameport(struct es1968 *chip) { }
 #endif
 
+#ifdef CONFIG_SND_ES1968_INPUT
+static int __devinit snd_es1968_input_register(struct es1968 *chip)
+{
+       struct input_dev *input_dev;
+       int err;
+
+       input_dev = input_allocate_device();
+       if (!input_dev)
+               return -ENOMEM;
+
+       snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0",
+                pci_name(chip->pci));
+
+       input_dev->name = chip->card->driver;
+       input_dev->phys = chip->phys;
+       input_dev->id.bustype = BUS_PCI;
+       input_dev->id.vendor  = chip->pci->vendor;
+       input_dev->id.product = chip->pci->device;
+       input_dev->dev.parent = &chip->pci->dev;
+
+       __set_bit(EV_KEY, input_dev->evbit);
+       __set_bit(KEY_MUTE, input_dev->keybit);
+       __set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
+       __set_bit(KEY_VOLUMEUP, input_dev->keybit);
+
+       err = input_register_device(input_dev);
+       if (err) {
+               input_free_device(input_dev);
+               return err;
+       }
+
+       chip->input_dev = input_dev;
+       return 0;
+}
+#endif /* CONFIG_SND_ES1968_INPUT */
+
 static int snd_es1968_free(struct es1968 *chip)
 {
+#ifdef CONFIG_SND_ES1968_INPUT
+       if (chip->input_dev)
+               input_unregister_device(chip->input_dev);
+#endif
+
        if (chip->io_port) {
                if (chip->irq >= 0)
                        synchronize_irq(chip->irq);
@@ -2486,8 +2588,6 @@ static int snd_es1968_free(struct es1968 *chip)
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
        snd_es1968_free_gameport(chip);
-       chip->master_switch = NULL;
-       chip->master_volume = NULL;
        pci_release_regions(chip->pci);
        pci_disable_device(chip->pci);
        kfree(chip);
@@ -2558,9 +2658,11 @@ static int __devinit snd_es1968_create(struct snd_card *card,
        spin_lock_init(&chip->substream_lock);
        INIT_LIST_HEAD(&chip->buf_list);
        INIT_LIST_HEAD(&chip->substream_list);
-       spin_lock_init(&chip->ac97_lock);
        mutex_init(&chip->memory_mutex);
+#ifndef CONFIG_SND_ES1968_INPUT
+       spin_lock_init(&chip->ac97_lock);
        tasklet_init(&chip->hwvol_tq, es1968_update_hw_volume, (unsigned long)chip);
+#endif
        chip->card = card;
        chip->pci = pci;
        chip->irq = -1;
@@ -2713,6 +2815,13 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci,
 
        snd_es1968_create_gameport(chip, dev);
 
+#ifdef CONFIG_SND_ES1968_INPUT
+       err = snd_es1968_input_register(chip);
+       if (err)
+               snd_printk(KERN_WARNING "Input device registration "
+                       "failed with error %i", err);
+#endif
+
        snd_es1968_start_irq(chip);
 
        chip->clock = clock[dev];
index 567348b..9194c3c 100644 (file)
@@ -145,6 +145,7 @@ config SND_HDA_CODEC_NVHDMI
 
 config SND_HDA_CODEC_INTELHDMI
        bool "Build INTEL HDMI HD-audio codec support"
+       select SND_DYNAMIC_MINORS
        default y
        help
          Say Y here to include INTEL HDMI HD-audio codec support in
index 0e76ac2..a3d638c 100644 (file)
@@ -1209,8 +1209,7 @@ static void free_hda_cache(struct hda_cache_rec *cache)
 }
 
 /* query the hash.  allocate an entry if not found. */
-static struct hda_cache_head  *get_alloc_hash(struct hda_cache_rec *cache,
-                                             u32 key)
+static struct hda_cache_head  *get_hash(struct hda_cache_rec *cache, u32 key)
 {
        u16 idx = key % (u16)ARRAY_SIZE(cache->hash);
        u16 cur = cache->hash[idx];
@@ -1222,17 +1221,27 @@ static struct hda_cache_head  *get_alloc_hash(struct hda_cache_rec *cache,
                        return info;
                cur = info->next;
        }
+       return NULL;
+}
 
-       /* add a new hash entry */
-       info = snd_array_new(&cache->buf);
-       if (!info)
-               return NULL;
-       cur = snd_array_index(&cache->buf, info);
-       info->key = key;
-       info->val = 0;
-       info->next = cache->hash[idx];
-       cache->hash[idx] = cur;
-
+/* query the hash.  allocate an entry if not found. */
+static struct hda_cache_head  *get_alloc_hash(struct hda_cache_rec *cache,
+                                             u32 key)
+{
+       struct hda_cache_head *info = get_hash(cache, key);
+       if (!info) {
+               u16 idx, cur;
+               /* add a new hash entry */
+               info = snd_array_new(&cache->buf);
+               if (!info)
+                       return NULL;
+               cur = snd_array_index(&cache->buf, info);
+               info->key = key;
+               info->val = 0;
+               idx = key % (u16)ARRAY_SIZE(cache->hash);
+               info->next = cache->hash[idx];
+               cache->hash[idx] = cur;
+       }
        return info;
 }
 
@@ -1461,6 +1470,8 @@ int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid, int ch,
        info = get_alloc_amp_hash(codec, HDA_HASH_KEY(nid, direction, idx));
        if (!info)
                return 0;
+       if (snd_BUG_ON(mask & ~0xff))
+               mask &= 0xff;
        val &= mask;
        val |= get_vol_mute(codec, info, nid, ch, direction, idx) & ~mask;
        if (info->vol[ch] == val)
@@ -1486,6 +1497,9 @@ int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
                             int direction, int idx, int mask, int val)
 {
        int ch, ret = 0;
+
+       if (snd_BUG_ON(mask & ~0xff))
+               mask &= 0xff;
        for (ch = 0; ch < 2; ch++)
                ret |= snd_hda_codec_amp_update(codec, nid, ch, direction,
                                                idx, mask, val);
@@ -2716,6 +2730,41 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
 }
 EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
 
+/**
+ * snd_hda_codec_update_cache - check cache and write the cmd only when needed
+ * @codec: the HDA codec
+ * @nid: NID to send the command
+ * @direct: direct flag
+ * @verb: the verb to send
+ * @parm: the parameter for the verb
+ *
+ * This function works like snd_hda_codec_write_cache(), but it doesn't send
+ * command if the parameter is already identical with the cached value.
+ * If not, it sends the command and refreshes the cache.
+ *
+ * Returns 0 if successful, or a negative error code.
+ */
+int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
+                              int direct, unsigned int verb, unsigned int parm)
+{
+       struct hda_cache_head *c;
+       u32 key;
+
+       /* parm may contain the verb stuff for get/set amp */
+       verb = verb | (parm >> 8);
+       parm &= 0xff;
+       key = build_cmd_cache_key(nid, verb);
+       mutex_lock(&codec->bus->cmd_mutex);
+       c = get_hash(&codec->cmd_cache, key);
+       if (c && c->val == parm) {
+               mutex_unlock(&codec->bus->cmd_mutex);
+               return 0;
+       }
+       mutex_unlock(&codec->bus->cmd_mutex);
+       return snd_hda_codec_write_cache(codec, nid, direct, verb, parm);
+}
+EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache);
+
 /**
  * snd_hda_codec_resume_cache - Resume the all commands from the cache
  * @codec: HD-audio codec
@@ -4218,7 +4267,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
                        break;
                case AC_JACK_MIC_IN: {
                        int preferred, alt;
-                       if (loc == AC_JACK_LOC_FRONT) {
+                       if (loc == AC_JACK_LOC_FRONT ||
+                           (loc & 0x30) == AC_JACK_LOC_INTERNAL) {
                                preferred = AUTO_PIN_FRONT_MIC;
                                alt = AUTO_PIN_MIC;
                        } else {
index b75da47..49e939e 100644 (file)
@@ -885,9 +885,12 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
                              int direct, unsigned int verb, unsigned int parm);
 void snd_hda_sequence_write_cache(struct hda_codec *codec,
                                  const struct hda_verb *seq);
+int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
+                             int direct, unsigned int verb, unsigned int parm);
 void snd_hda_codec_resume_cache(struct hda_codec *codec);
 #else
 #define snd_hda_codec_write_cache      snd_hda_codec_write
+#define snd_hda_codec_update_cache     snd_hda_codec_write
 #define snd_hda_sequence_write_cache   snd_hda_sequence_write
 #endif
 
index cec6815..170610e 100644 (file)
@@ -84,7 +84,7 @@ module_param_array(bdl_pos_adj, int, NULL, 0644);
 MODULE_PARM_DESC(bdl_pos_adj, "BDL position adjustment offset.");
 module_param_array(probe_mask, int, NULL, 0444);
 MODULE_PARM_DESC(probe_mask, "Bitmask to probe codecs (default = -1).");
-module_param_array(probe_only, bool, NULL, 0444);
+module_param_array(probe_only, int, NULL, 0444);
 MODULE_PARM_DESC(probe_only, "Only probing and no codec initialization.");
 module_param(single_cmd, bool, 0444);
 MODULE_PARM_DESC(single_cmd, "Use single command to communicate with codecs "
@@ -174,7 +174,7 @@ MODULE_DESCRIPTION("Intel HDA driver");
 #define   ICH6_GSTS_FSTS       (1 << 1)   /* flush status */
 #define ICH6_REG_INTCTL                        0x20
 #define ICH6_REG_INTSTS                        0x24
-#define ICH6_REG_WALCLK                        0x30
+#define ICH6_REG_WALLCLK               0x30    /* 24Mhz source */
 #define ICH6_REG_SYNC                  0x34    
 #define ICH6_REG_CORBLBASE             0x40
 #define ICH6_REG_CORBUBASE             0x44
@@ -340,8 +340,8 @@ struct azx_dev {
        unsigned int period_bytes; /* size of the period in bytes */
        unsigned int frags;     /* number for period in the play buffer */
        unsigned int fifo_size; /* FIFO size */
-       unsigned long start_jiffies;    /* start + minimum jiffies */
-       unsigned long min_jiffies;      /* minimum jiffies before position is valid */
+       unsigned long start_wallclk;    /* start + minimum wallclk */
+       unsigned long period_wallclk;   /* wallclk for period */
 
        void __iomem *sd_addr;  /* stream descriptor pointer */
 
@@ -361,7 +361,6 @@ struct azx_dev {
        unsigned int opened :1;
        unsigned int running :1;
        unsigned int irq_pending :1;
-       unsigned int start_flag: 1;     /* stream full start flag */
        /*
         * For VIA:
         *  A flag to ensure DMA position is 0
@@ -425,7 +424,7 @@ struct azx {
        struct snd_dma_buffer posbuf;
 
        /* flags */
-       int position_fix;
+       int position_fix[2]; /* for both playback/capture streams */
        int poll_count;
        unsigned int running :1;
        unsigned int initialized :1;
@@ -858,10 +857,13 @@ static void azx_power_notify(struct hda_bus *bus);
 #endif
 
 /* reset codec link */
-static int azx_reset(struct azx *chip)
+static int azx_reset(struct azx *chip, int full_reset)
 {
        int count;
 
+       if (!full_reset)
+               goto __skip;
+
        /* clear STATESTS */
        azx_writeb(chip, STATESTS, STATESTS_INT_MASK);
 
@@ -887,6 +889,7 @@ static int azx_reset(struct azx *chip)
        /* Brent Chartrand said to wait >= 540us for codecs to initialize */
        msleep(1);
 
+      __skip:
        /* check to see if controller is ready */
        if (!azx_readb(chip, GCTL)) {
                snd_printd(SFX "azx_reset: controller not ready!\n");
@@ -998,13 +1001,13 @@ static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
 /*
  * reset and start the controller registers
  */
-static void azx_init_chip(struct azx *chip)
+static void azx_init_chip(struct azx *chip, int full_reset)
 {
        if (chip->initialized)
                return;
 
        /* reset controller */
-       azx_reset(chip);
+       azx_reset(chip, full_reset);
 
        /* initialize interrupts */
        azx_int_clear(chip);
@@ -1302,8 +1305,10 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
        azx_sd_writel(azx_dev, SD_BDLPU, upper_32_bits(azx_dev->bdl.addr));
 
        /* enable the position buffer */
-       if (chip->position_fix == POS_FIX_POSBUF ||
-           chip->position_fix == POS_FIX_AUTO ||
+       if (chip->position_fix[0] == POS_FIX_POSBUF ||
+           chip->position_fix[0] == POS_FIX_AUTO ||
+           chip->position_fix[1] == POS_FIX_POSBUF ||
+           chip->position_fix[1] == POS_FIX_AUTO ||
            chip->via_dmapos_patch) {
                if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
                        azx_writel(chip, DPLBASE,
@@ -1348,7 +1353,7 @@ static void azx_bus_reset(struct hda_bus *bus)
 
        bus->in_reset = 1;
        azx_stop_chip(chip);
-       azx_init_chip(chip);
+       azx_init_chip(chip, 1);
 #ifdef CONFIG_PM
        if (chip->initialized) {
                int i;
@@ -1422,7 +1427,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model)
                                 * get back to the sanity state.
                                 */
                                azx_stop_chip(chip);
-                               azx_init_chip(chip);
+                               azx_init_chip(chip, 1);
                        }
                }
        }
@@ -1670,8 +1675,9 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
                        return err;
        }
 
-       azx_dev->min_jiffies = (runtime->period_size * HZ) /
-                                               (runtime->rate * 2);
+       /* wallclk has 24Mhz clock source */
+       azx_dev->period_wallclk = (((runtime->period_size * 24000) /
+                                               runtime->rate) * 1000);
        azx_setup_controller(chip, azx_dev);
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -1725,14 +1731,15 @@ static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                if (s->pcm->card != substream->pcm->card)
                        continue;
                azx_dev = get_azx_dev(s);
-               if (rstart) {
-                       azx_dev->start_flag = 1;
-                       azx_dev->start_jiffies = jiffies + azx_dev->min_jiffies;
-               }
-               if (start)
+               if (start) {
+                       azx_dev->start_wallclk = azx_readl(chip, WALLCLK);
+                       if (!rstart)
+                               azx_dev->start_wallclk -=
+                                               azx_dev->period_wallclk;
                        azx_stream_start(chip, azx_dev);
-               else
+               } else {
                        azx_stream_stop(chip, azx_dev);
+               }
                azx_dev->running = start;
        }
        spin_unlock(&chip->reg_lock);
@@ -1843,13 +1850,16 @@ static unsigned int azx_get_position(struct azx *chip,
 
        if (chip->via_dmapos_patch)
                pos = azx_via_get_position(chip, azx_dev);
-       else if (chip->position_fix == POS_FIX_POSBUF ||
-                chip->position_fix == POS_FIX_AUTO) {
-               /* use the position buffer */
-               pos = le32_to_cpu(*azx_dev->posbuf);
-       } else {
-               /* read LPIB */
-               pos = azx_sd_readl(azx_dev, SD_LPIB);
+       else {
+               int stream = azx_dev->substream->stream;
+               if (chip->position_fix[stream] == POS_FIX_POSBUF ||
+                   chip->position_fix[stream] == POS_FIX_AUTO) {
+                       /* use the position buffer */
+                       pos = le32_to_cpu(*azx_dev->posbuf);
+               } else {
+                       /* read LPIB */
+                       pos = azx_sd_readl(azx_dev, SD_LPIB);
+               }
        }
        if (pos >= azx_dev->bufsize)
                pos = 0;
@@ -1876,32 +1886,35 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
  */
 static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 {
+       u32 wallclk;
        unsigned int pos;
+       int stream;
 
-       if (azx_dev->start_flag &&
-           time_before_eq(jiffies, azx_dev->start_jiffies))
+       wallclk = azx_readl(chip, WALLCLK) - azx_dev->start_wallclk;
+       if (wallclk < (azx_dev->period_wallclk * 2) / 3)
                return -1;      /* bogus (too early) interrupt */
-       azx_dev->start_flag = 0;
 
+       stream = azx_dev->substream->stream;
        pos = azx_get_position(chip, azx_dev);
-       if (chip->position_fix == POS_FIX_AUTO) {
+       if (chip->position_fix[stream] == POS_FIX_AUTO) {
                if (!pos) {
                        printk(KERN_WARNING
                               "hda-intel: Invalid position buffer, "
                               "using LPIB read method instead.\n");
-                       chip->position_fix = POS_FIX_LPIB;
+                       chip->position_fix[stream] = POS_FIX_LPIB;
                        pos = azx_get_position(chip, azx_dev);
                } else
-                       chip->position_fix = POS_FIX_POSBUF;
+                       chip->position_fix[stream] = POS_FIX_POSBUF;
        }
 
-       if (!bdl_pos_adj[chip->dev_index])
-               return 1; /* no delayed ack */
        if (WARN_ONCE(!azx_dev->period_bytes,
                      "hda-intel: zero azx_dev->period_bytes"))
-               return 0; /* this shouldn't happen! */
-       if (pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
-               return 0; /* NG - it's below the period boundary */
+               return -1; /* this shouldn't happen! */
+       if (wallclk <= azx_dev->period_wallclk &&
+           pos % azx_dev->period_bytes > azx_dev->period_bytes / 2)
+               /* NG - it's below the first next period boundary */
+               return bdl_pos_adj[chip->dev_index] ? 0 : -1;
+       azx_dev->start_wallclk = wallclk;
        return 1; /* OK, it's fine */
 }
 
@@ -1911,7 +1924,7 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
 static void azx_irq_pending_work(struct work_struct *work)
 {
        struct azx *chip = container_of(work, struct azx, irq_pending_work);
-       int i, pending;
+       int i, pending, ok;
 
        if (!chip->irq_pending_warned) {
                printk(KERN_WARNING
@@ -1930,11 +1943,14 @@ static void azx_irq_pending_work(struct work_struct *work)
                            !azx_dev->substream ||
                            !azx_dev->running)
                                continue;
-                       if (azx_position_ok(chip, azx_dev)) {
+                       ok = azx_position_ok(chip, azx_dev);
+                       if (ok > 0) {
                                azx_dev->irq_pending = 0;
                                spin_unlock(&chip->reg_lock);
                                snd_pcm_period_elapsed(azx_dev->substream);
                                spin_lock(&chip->reg_lock);
+                       } else if (ok < 0) {
+                               pending = 0;    /* too early */
                        } else
                                pending++;
                }
@@ -2112,7 +2128,7 @@ static void azx_power_notify(struct hda_bus *bus)
                }
        }
        if (power_on)
-               azx_init_chip(chip);
+               azx_init_chip(chip, 1);
        else if (chip->running && power_save_controller &&
                 !bus->power_keep_link_on)
                azx_stop_chip(chip);
@@ -2182,7 +2198,7 @@ static int azx_resume(struct pci_dev *pci)
        azx_init_pci(chip);
 
        if (snd_hda_codecs_inuse(chip->bus))
-               azx_init_chip(chip);
+               azx_init_chip(chip, 1);
 
        snd_hda_resume(chip->bus);
        snd_power_change_state(card, SNDRV_CTL_POWER_D0);
@@ -2431,7 +2447,8 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
        chip->dev_index = dev;
        INIT_WORK(&chip->irq_pending_work, azx_irq_pending_work);
 
-       chip->position_fix = check_position_fix(chip, position_fix[dev]);
+       chip->position_fix[0] = chip->position_fix[1] =
+               check_position_fix(chip, position_fix[dev]);
        check_probe_mask(chip, dev);
 
        chip->single_cmd = single_cmd;
@@ -2577,7 +2594,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
 
        /* initialize chip */
        azx_init_pci(chip);
-       azx_init_chip(chip);
+       azx_init_chip(chip, (probe_only[dev] & 2) == 0);
 
        /* codec detection */
        if (!chip->codec_mask) {
@@ -2666,7 +2683,7 @@ static int __devinit azx_probe(struct pci_dev *pci,
                        goto out_free;
        }
 #endif
-       if (!probe_only[dev]) {
+       if ((probe_only[dev] & 1) == 0) {
                err = azx_codec_configure(chip);
                if (err < 0)
                        goto out_free;
index 7cee364..7a97f12 100644 (file)
@@ -361,7 +361,7 @@ struct hda_bus_unsolicited {
 };
 
 /*
- * Helper for automatic ping configuration
+ * Helper for automatic pin configuration
  */
 
 enum {
index e9fdfc4..afbe314 100644 (file)
@@ -71,9 +71,10 @@ struct ad198x_spec {
        struct hda_input_mux private_imux;
        hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
 
-       unsigned int jack_present :1;
-       unsigned int inv_jack_detect:1; /* inverted jack-detection */
-       unsigned int inv_eapd:1;        /* inverted EAPD implementation */
+       unsigned int jack_present: 1;
+       unsigned int inv_jack_detect: 1;/* inverted jack-detection */
+       unsigned int inv_eapd: 1;       /* inverted EAPD implementation */
+       unsigned int analog_beep: 1;    /* analog beep input present */
 
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        struct hda_loopback_check loopback;
@@ -165,6 +166,12 @@ static struct snd_kcontrol_new ad_beep_mixer[] = {
        { } /* end */
 };
 
+static struct snd_kcontrol_new ad_beep2_mixer[] = {
+       HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
+       HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
+       { } /* end */
+};
+
 #define set_beep_amp(spec, nid, idx, dir) \
        ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
 #else
@@ -203,7 +210,8 @@ static int ad198x_build_controls(struct hda_codec *codec)
 #ifdef CONFIG_SND_HDA_INPUT_BEEP
        if (spec->beep_amp) {
                struct snd_kcontrol_new *knew;
-               for (knew = ad_beep_mixer; knew->name; knew++) {
+               knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
+               for ( ; knew->name; knew++) {
                        struct snd_kcontrol *kctl;
                        kctl = snd_ctl_new1(knew, codec);
                        if (!kctl)
@@ -3481,6 +3489,8 @@ static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
        HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
        HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
        HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
+       HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
+       HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
        HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
        HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
        HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
@@ -3522,6 +3532,8 @@ static struct hda_verb ad1984_thinkpad_init_verbs[] = {
        {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
        /* docking mic boost */
        {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
+       /* Analog PC Beeper - allow firmware/ACPI beeps */
+       {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
        /* Analog mixer - docking mic; mute as default */
        {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
        /* enable EAPD bit */
@@ -3654,6 +3666,7 @@ static int patch_ad1984(struct hda_codec *codec)
                spec->input_mux = &ad1984_thinkpad_capture_source;
                spec->mixers[0] = ad1984_thinkpad_mixers;
                spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
+               spec->analog_beep = 1;
                break;
        case AD1984_DELL_DESKTOP:
                spec->multiout.dig_out_nid = 0;
index feabb44..e863649 100644 (file)
@@ -115,6 +115,7 @@ struct conexant_spec {
        unsigned int port_d_mode;
        unsigned int dell_vostro:1;
        unsigned int ideapad:1;
+       unsigned int thinkpad:1;
 
        unsigned int ext_mic_present;
        unsigned int recording;
@@ -1784,6 +1785,7 @@ static struct hda_verb cxt5051_init_verbs[] = {
        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
        /* SPDIF route: PCM */
+       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
        /* EAPD */
        {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */ 
@@ -1840,6 +1842,7 @@ static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
        {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
        {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
        /* SPDIF route: PCM */
+       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
        {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
        /* EAPD */
        {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
@@ -1911,7 +1914,7 @@ enum {
        CXT5051_LAPTOP,  /* Laptops w/ EAPD support */
        CXT5051_HP,     /* no docking */
        CXT5051_HP_DV6736,      /* HP without mic switch */
-       CXT5051_LENOVO_X200,    /* Lenovo X200 laptop */
+       CXT5051_LENOVO_X200,    /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
        CXT5051_F700,       /* HP Compaq Presario F700 */
        CXT5051_TOSHIBA,        /* Toshiba M300 & co */
        CXT5051_MODELS
@@ -2033,6 +2036,9 @@ static void cxt5066_update_speaker(struct hda_codec *codec)
        /* Port D (HP/LO) */
        pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
                ? spec->port_d_mode : 0;
+       /* Mute if Port A is connected on Thinkpad */
+       if (spec->thinkpad && (spec->hp_present & 1))
+               pinctl = 0;
        snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
                        pinctl);
 
@@ -2213,6 +2219,50 @@ static void cxt5066_ideapad_automic(struct hda_codec *codec)
        }
 }
 
+/* toggle input of built-in digital mic and mic jack appropriately
+   order is: external mic -> dock mic -> interal mic */
+static void cxt5066_thinkpad_automic(struct hda_codec *codec)
+{
+       unsigned int ext_present, dock_present;
+
+       static struct hda_verb ext_mic_present[] = {
+               {0x14, AC_VERB_SET_CONNECT_SEL, 0},
+               {0x17, AC_VERB_SET_CONNECT_SEL, 1},
+               {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
+               {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {}
+       };
+       static struct hda_verb dock_mic_present[] = {
+               {0x14, AC_VERB_SET_CONNECT_SEL, 0},
+               {0x17, AC_VERB_SET_CONNECT_SEL, 0},
+               {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
+               {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {}
+       };
+       static struct hda_verb ext_mic_absent[] = {
+               {0x14, AC_VERB_SET_CONNECT_SEL, 2},
+               {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
+               {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+               {}
+       };
+
+       ext_present = snd_hda_jack_detect(codec, 0x1b);
+       dock_present = snd_hda_jack_detect(codec, 0x1a);
+       if (ext_present) {
+               snd_printdd("CXT5066: external microphone detected\n");
+               snd_hda_sequence_write(codec, ext_mic_present);
+       } else if (dock_present) {
+               snd_printdd("CXT5066: dock microphone detected\n");
+               snd_hda_sequence_write(codec, dock_mic_present);
+       } else {
+               snd_printdd("CXT5066: external microphone absent\n");
+               snd_hda_sequence_write(codec, ext_mic_absent);
+       }
+}
+
 /* mute internal speaker if HP is plugged */
 static void cxt5066_hp_automute(struct hda_codec *codec)
 {
@@ -2225,7 +2275,8 @@ static void cxt5066_hp_automute(struct hda_codec *codec)
        /* Port D */
        portD = snd_hda_jack_detect(codec, 0x1c);
 
-       spec->hp_present = !!(portA | portD);
+       spec->hp_present = !!(portA);
+       spec->hp_present |= portD ? 2 : 0;
        snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
                portA, portD, spec->hp_present);
        cxt5066_update_speaker(codec);
@@ -2276,6 +2327,20 @@ static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
        }
 }
 
+/* unsolicited event for jack sensing */
+static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
+{
+       snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
+       switch (res >> 26) {
+       case CONEXANT_HP_EVENT:
+               cxt5066_hp_automute(codec);
+               break;
+       case CONEXANT_MIC_EVENT:
+               cxt5066_thinkpad_automic(codec);
+               break;
+       }
+}
+
 static const struct hda_input_mux cxt5066_analog_mic_boost = {
        .num_items = 5,
        .items = {
@@ -2294,7 +2359,7 @@ static void cxt5066_set_mic_boost(struct hda_codec *codec)
                AC_VERB_SET_AMP_GAIN_MUTE,
                AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
                        cxt5066_analog_mic_boost.items[spec->mic_boost].index);
-       if (spec->ideapad) {
+       if (spec->ideapad || spec->thinkpad) {
                /* adjust the internal mic as well...it is not through 0x17 */
                snd_hda_codec_write_cache(codec, 0x23, 0,
                        AC_VERB_SET_AMP_GAIN_MUTE,
@@ -2782,6 +2847,64 @@ static struct hda_verb cxt5066_init_verbs_ideapad[] = {
        { } /* end */
 };
 
+static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
+       {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
+       {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
+
+       /* Port G: internal speakers  */
+       {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+       {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
+
+       /* Port A: HP, Amp  */
+       {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+       {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
+
+       /* Port B: Mic Dock */
+       {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+
+       /* Port C: Mic */
+       {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+
+       /* Port D: HP Dock, Amp */
+       {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
+       {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
+
+       /* DAC1 */
+       {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
+
+       /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
+       {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
+       {0x14, AC_VERB_SET_CONNECT_SEL, 2},     /* default to internal mic */
+
+       /* Audio input selector */
+       {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
+       {0x17, AC_VERB_SET_CONNECT_SEL, 1},     /* route ext mic */
+
+       /* SPDIF route: PCM */
+       {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
+       {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
+
+       {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+       {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
+
+       /* internal microphone */
+       {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
+
+       /* EAPD */
+       {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
+
+       /* enable unsolicited events for Port A, B, C and D */
+       {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
+       {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
+       {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
+       {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
+       { } /* end */
+};
+
 static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
        {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
        { } /* end */
@@ -2800,6 +2923,8 @@ static int cxt5066_init(struct hda_codec *codec)
                        cxt5066_vostro_automic(codec);
                else if (spec->ideapad)
                        cxt5066_ideapad_automic(codec);
+               else if (spec->thinkpad)
+                       cxt5066_thinkpad_automic(codec);
        }
        cxt5066_set_mic_boost(codec);
        return 0;
@@ -2821,20 +2946,22 @@ static int cxt5066_olpc_init(struct hda_codec *codec)
 }
 
 enum {
-       CXT5066_LAPTOP,                 /* Laptops w/ EAPD support */
+       CXT5066_LAPTOP,         /* Laptops w/ EAPD support */
        CXT5066_DELL_LAPTOP,    /* Dell Laptop */
        CXT5066_OLPC_XO_1_5,    /* OLPC XO 1.5 */
        CXT5066_DELL_VOSTO,     /* Dell Vostro 1015i */
        CXT5066_IDEAPAD,        /* Lenovo IdeaPad U150 */
+       CXT5066_THINKPAD,       /* Lenovo ThinkPad T410s, others? */
        CXT5066_MODELS
 };
 
 static const char *cxt5066_models[CXT5066_MODELS] = {
-       [CXT5066_LAPTOP]                = "laptop",
+       [CXT5066_LAPTOP]        = "laptop",
        [CXT5066_DELL_LAPTOP]   = "dell-laptop",
        [CXT5066_OLPC_XO_1_5]   = "olpc-xo-1_5",
        [CXT5066_DELL_VOSTO]    = "dell-vostro",
        [CXT5066_IDEAPAD]       = "ideapad",
+       [CXT5066_THINKPAD]      = "thinkpad",
 };
 
 static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
@@ -2849,6 +2976,7 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
        SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
        SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
        SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
+       SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
        {}
 };
 
@@ -2953,6 +3081,22 @@ static int patch_cxt5066(struct hda_codec *codec)
                /* no S/PDIF out */
                spec->multiout.dig_out_nid = 0;
 
+               /* input source automatically selected */
+               spec->input_mux = NULL;
+               break;
+       case CXT5066_THINKPAD:
+               codec->patch_ops.init = cxt5066_init;
+               codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
+               spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
+               spec->mixers[spec->num_mixers++] = cxt5066_mixers;
+               spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
+               spec->thinkpad = 1;
+               spec->port_d_mode = PIN_OUT;
+               spec->mic_boost = 2;    /* default 20dB gain */
+
+               /* no S/PDIF out */
+               spec->multiout.dig_out_nid = 0;
+
                /* input source automatically selected */
                spec->input_mux = NULL;
                break;
@@ -2975,6 +3119,8 @@ static struct hda_codec_preset snd_hda_preset_conexant[] = {
          .patch = patch_cxt5066 },
        { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
          .patch = patch_cxt5066 },
+       { .id = 0x14f15069, .name = "CX20585",
+         .patch = patch_cxt5066 },
        {} /* terminator */
 };
 
@@ -2983,6 +3129,7 @@ MODULE_ALIAS("snd-hda-codec-id:14f15047");
 MODULE_ALIAS("snd-hda-codec-id:14f15051");
 MODULE_ALIAS("snd-hda-codec-id:14f15066");
 MODULE_ALIAS("snd-hda-codec-id:14f15067");
+MODULE_ALIAS("snd-hda-codec-id:14f15069");
 
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Conexant HD-audio codec");
index 2c2bafb..86067ee 100644 (file)
@@ -766,7 +766,7 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
        if (spec->num_pins >= MAX_HDMI_PINS) {
                snd_printk(KERN_WARNING
                           "HDMI: no space for pin %d\n", pin_nid);
-               return -EINVAL;
+               return -E2BIG;
        }
 
        hdmi_present_sense(codec, pin_nid, &spec->sink_eld[spec->num_pins]);
@@ -788,7 +788,7 @@ static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t nid)
        if (spec->num_cvts >= MAX_HDMI_CVTS) {
                snd_printk(KERN_WARNING
                           "HDMI: no space for converter %d\n", nid);
-               return -EINVAL;
+               return -E2BIG;
        }
 
        spec->cvt[spec->num_cvts] = nid;
@@ -820,15 +820,13 @@ static int hdmi_parse_codec(struct hda_codec *codec)
 
                switch (type) {
                case AC_WID_AUD_OUT:
-                       if (hdmi_add_cvt(codec, nid) < 0)
-                               return -EINVAL;
+                       hdmi_add_cvt(codec, nid);
                        break;
                case AC_WID_PIN:
                        caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
                        if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
                                continue;
-                       if (hdmi_add_pin(codec, nid) < 0)
-                               return -EINVAL;
+                       hdmi_add_pin(codec, nid);
                        break;
                }
        }
index 88d0351..b81d23e 100644 (file)
@@ -40,7 +40,7 @@
  *
  * The HDA correspondence of pipes/ports are converter/pin nodes.
  */
-#define MAX_HDMI_CVTS  2
+#define MAX_HDMI_CVTS  3
 #define MAX_HDMI_PINS  3
 
 #include "patch_hdmi.c"
@@ -48,6 +48,7 @@
 static char *intel_hdmi_pcm_names[MAX_HDMI_CVTS] = {
        "INTEL HDMI 0",
        "INTEL HDMI 1",
+       "INTEL HDMI 2",
 };
 
 /*
@@ -185,14 +186,15 @@ static int patch_intel_hdmi(struct hda_codec *codec)
 }
 
 static struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
-       { .id = 0x808629fb, .name = "G45 DEVCL",  .patch = patch_intel_hdmi },
-       { .id = 0x80862801, .name = "G45 DEVBLC", .patch = patch_intel_hdmi },
-       { .id = 0x80862802, .name = "G45 DEVCTG", .patch = patch_intel_hdmi },
-       { .id = 0x80862803, .name = "G45 DEVELK", .patch = patch_intel_hdmi },
-       { .id = 0x80862804, .name = "G45 DEVIBX", .patch = patch_intel_hdmi },
-       { .id = 0x80860054, .name = "Q57 DEVIBX", .patch = patch_intel_hdmi },
-       { .id = 0x10951392, .name = "SiI1392 HDMI",     .patch = patch_intel_hdmi },
-       {} /* terminator */
+{ .id = 0x808629fb, .name = "Crestline HDMI",  .patch = patch_intel_hdmi },
+{ .id = 0x80862801, .name = "Bearlake HDMI",   .patch = patch_intel_hdmi },
+{ .id = 0x80862802, .name = "Cantiga HDMI",    .patch = patch_intel_hdmi },
+{ .id = 0x80862803, .name = "Eaglelake HDMI",  .patch = patch_intel_hdmi },
+{ .id = 0x80862804, .name = "IbexPeak HDMI",   .patch = patch_intel_hdmi },
+{ .id = 0x80860054, .name = "IbexPeak HDMI",   .patch = patch_intel_hdmi },
+{ .id = 0x80862805, .name = "CougarPoint HDMI",        .patch = patch_intel_hdmi },
+{ .id = 0x10951392, .name = "SiI1392 HDMI",    .patch = patch_intel_hdmi },
+{} /* terminator */
 };
 
 MODULE_ALIAS("snd-hda-codec-id:808629fb");
@@ -200,6 +202,7 @@ MODULE_ALIAS("snd-hda-codec-id:80862801");
 MODULE_ALIAS("snd-hda-codec-id:80862802");
 MODULE_ALIAS("snd-hda-codec-id:80862803");
 MODULE_ALIAS("snd-hda-codec-id:80862804");
+MODULE_ALIAS("snd-hda-codec-id:80862805");
 MODULE_ALIAS("snd-hda-codec-id:80860054");
 MODULE_ALIAS("snd-hda-codec-id:10951392");
 
index 886d8e4..53538b0 100644 (file)
@@ -276,6 +276,18 @@ struct alc_mic_route {
 
 #define MUX_IDX_UNDEF  ((unsigned char)-1)
 
+struct alc_customize_define {
+       unsigned int  sku_cfg;
+       unsigned char port_connectivity;
+       unsigned char check_sum;
+       unsigned char customization;
+       unsigned char external_amp;
+       unsigned int  enable_pcbeep:1;
+       unsigned int  platform_type:1;
+       unsigned int  swap:1;
+       unsigned int  override:1;
+};
+
 struct alc_spec {
        /* codec parameterization */
        struct snd_kcontrol_new *mixers[5];     /* mixer arrays */
@@ -333,6 +345,7 @@ struct alc_spec {
 
        /* dynamic controls, init_verbs and input_mux */
        struct auto_pin_cfg autocfg;
+       struct alc_customize_define cdefine;
        struct snd_array kctls;
        struct hda_input_mux private_imux[3];
        hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
@@ -1248,6 +1261,62 @@ static void alc_init_auto_mic(struct hda_codec *codec)
        spec->unsol_event = alc_sku_unsol_event;
 }
 
+static int alc_auto_parse_customize_define(struct hda_codec *codec)
+{
+       unsigned int ass, tmp, i;
+       unsigned nid = 0;
+       struct alc_spec *spec = codec->spec;
+
+       ass = codec->subsystem_id & 0xffff;
+       if (ass != codec->bus->pci->subsystem_device && (ass & 1))
+               goto do_sku;
+
+       nid = 0x1d;
+       if (codec->vendor_id == 0x10ec0260)
+               nid = 0x17;
+       ass = snd_hda_codec_get_pincfg(codec, nid);
+
+       if (!(ass & 1)) {
+               printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
+                      codec->chip_name, ass);
+               return -1;
+       }
+
+       /* check sum */
+       tmp = 0;
+       for (i = 1; i < 16; i++) {
+               if ((ass >> i) & 1)
+                       tmp++;
+       }
+       if (((ass >> 16) & 0xf) != tmp)
+               return -1;
+
+       spec->cdefine.port_connectivity = ass >> 30;
+       spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
+       spec->cdefine.check_sum = (ass >> 16) & 0xf;
+       spec->cdefine.customization = ass >> 8;
+do_sku:
+       spec->cdefine.sku_cfg = ass;
+       spec->cdefine.external_amp = (ass & 0x38) >> 3;
+       spec->cdefine.platform_type = (ass & 0x4) >> 2;
+       spec->cdefine.swap = (ass & 0x2) >> 1;
+       spec->cdefine.override = ass & 0x1;
+
+       snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
+                  nid, spec->cdefine.sku_cfg);
+       snd_printd("SKU: port_connectivity=0x%x\n",
+                  spec->cdefine.port_connectivity);
+       snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
+       snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
+       snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
+       snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
+       snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
+       snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
+       snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
+
+       return 0;
+}
+
 /* check subsystem ID and set up device-specific initialization;
  * return 1 if initialized, 0 if invalid SSID
  */
@@ -3415,6 +3484,10 @@ static int alc_init(struct hda_codec *codec)
        if (spec->init_hook)
                spec->init_hook(codec);
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       if (codec->patch_ops.check_power_status)
+               codec->patch_ops.check_power_status(codec, 0x01);
+#endif
        return 0;
 }
 
@@ -3775,6 +3848,10 @@ static int alc_resume(struct hda_codec *codec)
        codec->patch_ops.init(codec);
        snd_hda_codec_resume_amp(codec);
        snd_hda_codec_resume_cache(codec);
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+       if (codec->patch_ops.check_power_status)
+               codec->patch_ops.check_power_status(codec, 0x01);
+#endif
        return 0;
 }
 #endif
@@ -3797,6 +3874,17 @@ static struct hda_codec_ops alc_patch_ops = {
        .reboot_notify = alc_shutup,
 };
 
+/* replace the codec chip_name with the given string */
+static int alc_codec_rename(struct hda_codec *codec, const char *name)
+{
+       kfree(codec->chip_name);
+       codec->chip_name = kstrdup(name, GFP_KERNEL);
+       if (!codec->chip_name) {
+               alc_free(codec);
+               return -ENOMEM;
+       }
+       return 0;
+}
 
 /*
  * Test configuration for debugging
@@ -10189,21 +10277,20 @@ static int alc882_auto_create_input_ctls(struct hda_codec *codec,
 
 static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
                                              hda_nid_t nid, int pin_type,
-                                             int dac_idx)
+                                             hda_nid_t dac)
 {
-       /* set as output */
-       struct alc_spec *spec = codec->spec;
        int idx;
 
+       /* set as output */
        alc_set_pin_output(codec, nid, pin_type);
-       if (dac_idx >= spec->multiout.num_dacs)
-               return;
-       if (spec->multiout.dac_nids[dac_idx] == 0x25)
+
+       if (dac == 0x25)
                idx = 4;
+       else if (dac >= 0x02 && dac <= 0x05)
+               idx = dac - 2;
        else
-               idx = spec->multiout.dac_nids[dac_idx] - 2;
+               return;
        snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
-
 }
 
 static void alc882_auto_init_multi_out(struct hda_codec *codec)
@@ -10216,22 +10303,29 @@ static void alc882_auto_init_multi_out(struct hda_codec *codec)
                int pin_type = get_pin_type(spec->autocfg.line_out_type);
                if (nid)
                        alc882_auto_set_output_and_unmute(codec, nid, pin_type,
-                                                         i);
+                                       spec->multiout.dac_nids[i]);
        }
 }
 
 static void alc882_auto_init_hp_out(struct hda_codec *codec)
 {
        struct alc_spec *spec = codec->spec;
-       hda_nid_t pin;
+       hda_nid_t pin, dac;
 
        pin = spec->autocfg.hp_pins[0];
-       if (pin) /* connect to front */
-               /* use dac 0 */
-               alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
+       if (pin) {
+               dac = spec->multiout.hp_nid;
+               if (!dac)
+                       dac = spec->multiout.dac_nids[0]; /* to front */
+               alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
+       }
        pin = spec->autocfg.speaker_pins[0];
-       if (pin)
-               alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
+       if (pin) {
+               dac = spec->multiout.extra_out_nid[0];
+               if (!dac)
+                       dac = spec->multiout.dac_nids[0]; /* to front */
+               alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
+       }
 }
 
 static void alc882_auto_init_analog_input(struct hda_codec *codec)
@@ -10345,6 +10439,10 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
        if (err < 0)
                return err;
        err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg);
+       if (err < 0)
+               return err;
+       err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
+                                          "Headphone");
        if (err < 0)
                return err;
        err = alc880_auto_create_extra_out(spec,
@@ -10352,10 +10450,6 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
                                           "Speaker");
        if (err < 0)
                return err;
-       err = alc880_auto_create_extra_out(spec, spec->autocfg.hp_pins[0],
-                                          "Headphone");
-       if (err < 0)
-               return err;
        err = alc882_auto_create_input_ctls(codec, &spec->autocfg);
        if (err < 0)
                return err;
@@ -10425,6 +10519,8 @@ static int patch_alc882(struct hda_codec *codec)
 
        codec->spec = spec;
 
+       alc_auto_parse_customize_define(codec);
+
        switch (codec->vendor_id) {
        case 0x10ec0882:
        case 0x10ec0885:
@@ -10484,9 +10580,6 @@ static int patch_alc882(struct hda_codec *codec)
        spec->stream_digital_playback = &alc882_pcm_digital_playback;
        spec->stream_digital_capture = &alc882_pcm_digital_capture;
 
-       if (codec->vendor_id == 0x10ec0888)
-               spec->init_amp = ALC_INIT_DEFAULT; /* always initialize */
-
        if (!spec->adc_nids && spec->input_mux) {
                int i, j;
                spec->num_adc_nids = 0;
@@ -10521,7 +10614,9 @@ static int patch_alc882(struct hda_codec *codec)
        }
 
        set_capture_mixer(codec);
-       set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
+
+       if (spec->cdefine.enable_pcbeep)
+               set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
 
        if (board_config == ALC882_AUTO)
                alc_pick_fixup(codec, alc882_fixup_tbl, alc882_fixups, 0);
@@ -12308,6 +12403,7 @@ static int patch_alc262(struct hda_codec *codec)
        snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
        }
 #endif
+       alc_auto_parse_customize_define(codec);
 
        alc_fix_pll_init(codec, 0x20, 0x0a, 10);
 
@@ -12386,7 +12482,7 @@ static int patch_alc262(struct hda_codec *codec)
        }
        if (!spec->cap_mixer && !spec->no_analog)
                set_capture_mixer(codec);
-       if (!spec->no_analog)
+       if (!spec->no_analog && spec->cdefine.enable_pcbeep)
                set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
 
        spec->vmaster_nid = 0x0c;
@@ -14005,6 +14101,35 @@ static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
        /* NID is set in alc_build_pcms */
 };
 
+#ifdef CONFIG_SND_HDA_POWER_SAVE
+static int alc269_mic2_for_mute_led(struct hda_codec *codec)
+{
+       switch (codec->subsystem_id) {
+       case 0x103c1586:
+               return 1;
+       }
+       return 0;
+}
+
+static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
+{
+       /* update mute-LED according to the speaker mute state */
+       if (nid == 0x01 || nid == 0x14) {
+               int pinval;
+               if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
+                   HDA_AMP_MUTE)
+                       pinval = 0x24;
+               else
+                       pinval = 0x20;
+               /* mic2 vref pin is used for mute LED control */
+               snd_hda_codec_update_cache(codec, 0x19, 0,
+                                          AC_VERB_SET_PIN_WIDGET_CONTROL,
+                                          pinval);
+       }
+       return alc_check_power_status(codec, nid);
+}
+#endif /* CONFIG_SND_HDA_POWER_SAVE */
+
 /*
  * BIOS auto configuration
  */
@@ -14082,7 +14207,7 @@ enum {
        ALC269_FIXUP_SONY_VAIO,
 };
 
-const static struct hda_verb alc269_sony_vaio_fixup_verbs[] = {
+static const struct hda_verb alc269_sony_vaio_fixup_verbs[] = {
        {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
        {}
 };
@@ -14290,17 +14415,17 @@ static int patch_alc269(struct hda_codec *codec)
 
        codec->spec = spec;
 
-       alc_fix_pll_init(codec, 0x20, 0x04, 15);
+       alc_auto_parse_customize_define(codec);
 
        if ((alc_read_coef_idx(codec, 0) & 0x00f0) == 0x0010){
-               kfree(codec->chip_name);
-               codec->chip_name = kstrdup("ALC259", GFP_KERNEL);
-               if (!codec->chip_name) {
-                       alc_free(codec);
-                       return -ENOMEM;
-               }
+               if (codec->bus->pci->subsystem_vendor == 0x1025 &&
+                   spec->cdefine.platform_type == 1)
+                       alc_codec_rename(codec, "ALC271X");
+               else
+                       alc_codec_rename(codec, "ALC259");
                is_alc269vb = 1;
-       }
+       } else
+               alc_fix_pll_init(codec, 0x20, 0x04, 15);
 
        board_config = snd_hda_check_board_config(codec, ALC269_MODEL_LAST,
                                                  alc269_models,
@@ -14365,7 +14490,8 @@ static int patch_alc269(struct hda_codec *codec)
 
        if (!spec->cap_mixer)
                set_capture_mixer(codec);
-       set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
+       if (spec->cdefine.enable_pcbeep)
+               set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
 
        if (board_config == ALC269_AUTO)
                alc_pick_fixup(codec, alc269_fixup_tbl, alc269_fixups, 0);
@@ -14378,6 +14504,8 @@ static int patch_alc269(struct hda_codec *codec)
 #ifdef CONFIG_SND_HDA_POWER_SAVE
        if (!spec->loopback.amplist)
                spec->loopback.amplist = alc269_loopbacks;
+       if (alc269_mic2_for_mute_led(codec))
+               codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
 #endif
 
        return 0;
@@ -18525,16 +18653,16 @@ static int patch_alc662(struct hda_codec *codec)
 
        codec->spec = spec;
 
+       alc_auto_parse_customize_define(codec);
+
        alc_fix_pll_init(codec, 0x20, 0x04, 15);
 
-       if (alc_read_coef_idx(codec, 0)==0x8020){
-               kfree(codec->chip_name);
-               codec->chip_name = kstrdup("ALC661", GFP_KERNEL);
-               if (!codec->chip_name) {
-                       alc_free(codec);
-                       return -ENOMEM;
-               }
-       }
+       if (alc_read_coef_idx(codec, 0) == 0x8020)
+               alc_codec_rename(codec, "ALC661");
+       else if ((alc_read_coef_idx(codec, 0) & (1 << 14)) &&
+                codec->bus->pci->subsystem_vendor == 0x1025 &&
+                spec->cdefine.platform_type == 1)
+               alc_codec_rename(codec, "ALC272X");
 
        board_config = snd_hda_check_board_config(codec, ALC662_MODEL_LAST,
                                                  alc662_models,
@@ -18584,18 +18712,20 @@ static int patch_alc662(struct hda_codec *codec)
        if (!spec->cap_mixer)
                set_capture_mixer(codec);
 
-       switch (codec->vendor_id) {
-       case 0x10ec0662:
-               set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
-               break;
-       case 0x10ec0272:
-       case 0x10ec0663:
-       case 0x10ec0665:
-               set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
-               break;
-       case 0x10ec0273:
-               set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
-               break;
+       if (spec->cdefine.enable_pcbeep) {
+               switch (codec->vendor_id) {
+               case 0x10ec0662:
+                       set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
+                       break;
+               case 0x10ec0272:
+               case 0x10ec0663:
+               case 0x10ec0665:
+                       set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
+                       break;
+               case 0x10ec0273:
+                       set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
+                       break;
+               }
        }
        spec->vmaster_nid = 0x02;
 
index 9e66f6d..2f62522 100644 (file)
@@ -1956,11 +1956,10 @@ static int __devinit aureon_add_controls(struct snd_ice1712 *ice)
        return 0;
 }
 
-
 /*
- * initialize the chip
+ * reset the chip
  */
-static int __devinit aureon_init(struct snd_ice1712 *ice)
+static int aureon_reset(struct snd_ice1712 *ice)
 {
        static const unsigned short wm_inits_aureon[] = {
                /* These come first to reduce init pop noise */
@@ -2047,30 +2046,10 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
                0x0605, /* slave, 24bit, MSB on second OSCLK, SDOUT for right channel when OLRCK is high */
                (unsigned short)-1
        };
-       struct aureon_spec *spec;
        unsigned int tmp;
        const unsigned short *p;
-       int err, i;
-
-       spec = kzalloc(sizeof(*spec), GFP_KERNEL);
-       if (!spec)
-               return -ENOMEM;
-       ice->spec = spec;
-
-       if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY) {
-               ice->num_total_dacs = 6;
-               ice->num_total_adcs = 2;
-       } else {
-               /* aureon 7.1 and prodigy 7.1 */
-               ice->num_total_dacs = 8;
-               ice->num_total_adcs = 2;
-       }
-
-       /* to remeber the register values of CS8415 */
-       ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
-       if (!ice->akm)
-               return -ENOMEM;
-       ice->akm_codecs = 1;
+       int err;
+       struct aureon_spec *spec = ice->spec;
 
        err = aureon_ac97_init(ice);
        if (err != 0)
@@ -2118,6 +2097,61 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
        /* initialize PCA9554 pin directions & set default input */
        aureon_pca9554_write(ice, PCA9554_DIR, 0x00);
        aureon_pca9554_write(ice, PCA9554_OUT, 0x00);   /* internal AUX */
+       return 0;
+}
+
+/*
+ * suspend/resume
+ */
+#ifdef CONFIG_PM
+static int aureon_resume(struct snd_ice1712 *ice)
+{
+       struct aureon_spec *spec = ice->spec;
+       int err, i;
+
+       err = aureon_reset(ice);
+       if (err != 0)
+               return err;
+
+       /* workaround for poking volume with alsamixer after resume:
+        * just set stored volume again */
+       for (i = 0; i < ice->num_total_dacs; i++)
+               wm_set_vol(ice, i, spec->vol[i], spec->master[i % 2]);
+       return 0;
+}
+#endif
+
+/*
+ * initialize the chip
+ */
+static int __devinit aureon_init(struct snd_ice1712 *ice)
+{
+       struct aureon_spec *spec;
+       int i, err;
+
+       spec = kzalloc(sizeof(*spec), GFP_KERNEL);
+       if (!spec)
+               return -ENOMEM;
+       ice->spec = spec;
+
+       if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AUREON51_SKY) {
+               ice->num_total_dacs = 6;
+               ice->num_total_adcs = 2;
+       } else {
+               /* aureon 7.1 and prodigy 7.1 */
+               ice->num_total_dacs = 8;
+               ice->num_total_adcs = 2;
+       }
+
+       /* to remeber the register values of CS8415 */
+       ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
+       if (!ice->akm)
+               return -ENOMEM;
+       ice->akm_codecs = 1;
+
+       err = aureon_reset(ice);
+       if (err != 0)
+               return err;
 
        spec->master[0] = WM_VOL_MUTE;
        spec->master[1] = WM_VOL_MUTE;
@@ -2126,6 +2160,11 @@ static int __devinit aureon_init(struct snd_ice1712 *ice)
                wm_set_vol(ice, i, spec->vol[i], spec->master[i % 2]);
        }
 
+#ifdef CONFIG_PM
+       ice->pm_resume = aureon_resume;
+       ice->pm_suspend_enabled = 1;
+#endif
+
        return 0;
 }
 
index b56e336..3c40d72 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/vmalloc.h>
 #include <linux/moduleparam.h>
 #include <linux/firmware.h>
+#include <linux/input.h>
 #include <sound/core.h>
 #include <sound/info.h>
 #include <sound/control.h>
@@ -844,11 +845,17 @@ struct snd_m3 {
        struct m3_dma *substreams;
 
        spinlock_t reg_lock;
-       spinlock_t ac97_lock;
 
+#ifdef CONFIG_SND_MAESTRO3_INPUT
+       struct input_dev *input_dev;
+       char phys[64];                  /* physical device path */
+#else
+       spinlock_t ac97_lock;
        struct snd_kcontrol *master_switch;
        struct snd_kcontrol *master_volume;
        struct tasklet_struct hwvol_tq;
+#endif
+
        unsigned int in_suspend;
 
 #ifdef CONFIG_PM
@@ -1598,18 +1605,32 @@ static void snd_m3_update_ptr(struct snd_m3 *chip, struct m3_dma *s)
        }
 }
 
+/* The m3's hardware volume works by incrementing / decrementing 2 counters
+   (without wrap around) in response to volume button presses and then
+   generating an interrupt. The pair of counters is stored in bits 1-3 and 5-7
+   of a byte wide register. The meaning of bits 0 and 4 is unknown. */
 static void snd_m3_update_hw_volume(unsigned long private_data)
 {
        struct snd_m3 *chip = (struct snd_m3 *) private_data;
        int x, val;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        unsigned long flags;
+#endif
 
        /* Figure out which volume control button was pushed,
           based on differences from the default register
           values. */
        x = inb(chip->iobase + SHADOW_MIX_REG_VOICE) & 0xee;
 
-       /* Reset the volume control registers. */
+       /* Reset the volume counters to 4. Tests on the allegro integrated
+          into a Compaq N600C laptop, have revealed that:
+          1) Writing any value will result in the 2 counters being reset to
+             4 so writing 0x88 is not strictly necessary
+          2) Writing to any of the 4 involved registers will reset all 4
+             of them (and reading them always returns the same value for all
+             of them)
+          It could be that a maestro deviates from this, so leave the code
+          as is. */
        outb(0x88, chip->iobase + SHADOW_MIX_REG_VOICE);
        outb(0x88, chip->iobase + HW_VOL_COUNTER_VOICE);
        outb(0x88, chip->iobase + SHADOW_MIX_REG_MASTER);
@@ -1620,6 +1641,7 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
        if (chip->in_suspend)
                return;
 
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        if (!chip->master_switch || !chip->master_volume)
                return;
 
@@ -1629,7 +1651,9 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
        val = chip->ac97->regs[AC97_MASTER_VOL];
        switch (x) {
        case 0x88:
-               /* mute */
+               /* The counters have not changed, yet we've received a HV
+                  interrupt. According to tests run by various people this
+                  happens when pressing the mute button. */
                val ^= 0x8000;
                chip->ac97->regs[AC97_MASTER_VOL] = val;
                outw(val, chip->iobase + CODEC_DATA);
@@ -1638,7 +1662,7 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
                               &chip->master_switch->id);
                break;
        case 0xaa:
-               /* volume up */
+               /* counters increased by 1 -> volume up */
                if ((val & 0x7f) > 0)
                        val--;
                if ((val & 0x7f00) > 0)
@@ -1650,7 +1674,7 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
                               &chip->master_volume->id);
                break;
        case 0x66:
-               /* volume down */
+               /* counters decreased by 1 -> volume down */
                if ((val & 0x7f) < 0x1f)
                        val++;
                if ((val & 0x7f00) < 0x1f00)
@@ -1663,6 +1687,35 @@ static void snd_m3_update_hw_volume(unsigned long private_data)
                break;
        }
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#else
+       if (!chip->input_dev)
+               return;
+
+       val = 0;
+       switch (x) {
+       case 0x88:
+               /* The counters have not changed, yet we've received a HV
+                  interrupt. According to tests run by various people this
+                  happens when pressing the mute button. */
+               val = KEY_MUTE;
+               break;
+       case 0xaa:
+               /* counters increased by 1 -> volume up */
+               val = KEY_VOLUMEUP;
+               break;
+       case 0x66:
+               /* counters decreased by 1 -> volume down */
+               val = KEY_VOLUMEDOWN;
+               break;
+       }
+
+       if (val) {
+               input_report_key(chip->input_dev, val, 1);
+               input_sync(chip->input_dev);
+               input_report_key(chip->input_dev, val, 0);
+               input_sync(chip->input_dev);
+       }
+#endif
 }
 
 static irqreturn_t snd_m3_interrupt(int irq, void *dev_id)
@@ -1677,7 +1730,11 @@ static irqreturn_t snd_m3_interrupt(int irq, void *dev_id)
                return IRQ_NONE;
 
        if (status & HV_INT_PENDING)
+#ifdef CONFIG_SND_MAESTRO3_INPUT
+               snd_m3_update_hw_volume((unsigned long)chip);
+#else
                tasklet_schedule(&chip->hwvol_tq);
+#endif
 
        /*
         * ack an assp int if its running
@@ -1943,18 +2000,24 @@ static unsigned short
 snd_m3_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 {
        struct snd_m3 *chip = ac97->private_data;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        unsigned long flags;
+#endif
        unsigned short data = 0xffff;
 
        if (snd_m3_ac97_wait(chip))
                goto fail;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        spin_lock_irqsave(&chip->ac97_lock, flags);
+#endif
        snd_m3_outb(chip, 0x80 | (reg & 0x7f), CODEC_COMMAND);
        if (snd_m3_ac97_wait(chip))
                goto fail_unlock;
        data = snd_m3_inw(chip, CODEC_DATA);
 fail_unlock:
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#endif
 fail:
        return data;
 }
@@ -1963,14 +2026,20 @@ static void
 snd_m3_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
 {
        struct snd_m3 *chip = ac97->private_data;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        unsigned long flags;
+#endif
 
        if (snd_m3_ac97_wait(chip))
                return;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        spin_lock_irqsave(&chip->ac97_lock, flags);
+#endif
        snd_m3_outw(chip, val, CODEC_DATA);
        snd_m3_outb(chip, reg & 0x7f, CODEC_COMMAND);
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        spin_unlock_irqrestore(&chip->ac97_lock, flags);
+#endif
 }
 
 
@@ -2077,7 +2146,9 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
 {
        struct snd_ac97_bus *pbus;
        struct snd_ac97_template ac97;
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        struct snd_ctl_elem_id elem_id;
+#endif
        int err;
        static struct snd_ac97_bus_ops ops = {
                .write = snd_m3_ac97_write,
@@ -2097,6 +2168,7 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
        schedule_timeout_uninterruptible(msecs_to_jiffies(100));
        snd_ac97_write(chip->ac97, AC97_PCM, 0);
 
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        memset(&elem_id, 0, sizeof(elem_id));
        elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
        strcpy(elem_id.name, "Master Playback Switch");
@@ -2105,6 +2177,7 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
        elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
        strcpy(elem_id.name, "Master Playback Volume");
        chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
+#endif
 
        return 0;
 }
@@ -2370,6 +2443,7 @@ snd_m3_enable_ints(struct snd_m3 *chip)
        val = ASSP_INT_ENABLE /*| MPU401_INT_ENABLE*/;
        if (chip->hv_config & HV_CTRL_ENABLE)
                val |= HV_INT_ENABLE;
+       outb(val, chip->iobase + HOST_INT_STATUS);
        outw(val, io + HOST_INT_CTRL);
        outb(inb(io + ASSP_CONTROL_C) | ASSP_HOST_INT_ENABLE,
             io + ASSP_CONTROL_C);
@@ -2384,6 +2458,11 @@ static int snd_m3_free(struct snd_m3 *chip)
        struct m3_dma *s;
        int i;
 
+#ifdef CONFIG_SND_MAESTRO3_INPUT
+       if (chip->input_dev)
+               input_unregister_device(chip->input_dev);
+#endif
+
        if (chip->substreams) {
                spin_lock_irq(&chip->reg_lock);
                for (i = 0; i < chip->num_substreams; i++) {
@@ -2510,6 +2589,41 @@ static int m3_resume(struct pci_dev *pci)
 }
 #endif /* CONFIG_PM */
 
+#ifdef CONFIG_SND_MAESTRO3_INPUT
+static int __devinit snd_m3_input_register(struct snd_m3 *chip)
+{
+       struct input_dev *input_dev;
+       int err;
+
+       input_dev = input_allocate_device();
+       if (!input_dev)
+               return -ENOMEM;
+
+       snprintf(chip->phys, sizeof(chip->phys), "pci-%s/input0",
+                pci_name(chip->pci));
+
+       input_dev->name = chip->card->driver;
+       input_dev->phys = chip->phys;
+       input_dev->id.bustype = BUS_PCI;
+       input_dev->id.vendor  = chip->pci->vendor;
+       input_dev->id.product = chip->pci->device;
+       input_dev->dev.parent = &chip->pci->dev;
+
+       __set_bit(EV_KEY, input_dev->evbit);
+       __set_bit(KEY_MUTE, input_dev->keybit);
+       __set_bit(KEY_VOLUMEDOWN, input_dev->keybit);
+       __set_bit(KEY_VOLUMEUP, input_dev->keybit);
+
+       err = input_register_device(input_dev);
+       if (err) {
+               input_free_device(input_dev);
+               return err;
+       }
+
+       chip->input_dev = input_dev;
+       return 0;
+}
+#endif /* CONFIG_INPUT */
 
 /*
  */
@@ -2553,7 +2667,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
        }
 
        spin_lock_init(&chip->reg_lock);
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        spin_lock_init(&chip->ac97_lock);
+#endif
 
        switch (pci->device) {
        case PCI_DEVICE_ID_ESS_ALLEGRO:
@@ -2636,7 +2752,9 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
 
        snd_m3_hv_init(chip);
 
+#ifndef CONFIG_SND_MAESTRO3_INPUT
        tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
+#endif
 
        if (request_irq(pci->irq, snd_m3_interrupt, IRQF_SHARED,
                        card->driver, chip)) {
@@ -2668,7 +2786,16 @@ snd_m3_create(struct snd_card *card, struct pci_dev *pci,
 
        if ((err = snd_m3_pcm(chip, 0)) < 0)
                return err;
-    
+
+#ifdef CONFIG_SND_MAESTRO3_INPUT
+       if (chip->hv_config & HV_CTRL_ENABLE) {
+               err = snd_m3_input_register(chip);
+               if (err)
+                       snd_printk(KERN_WARNING "Input device registration "
+                               "failed with error %i", err);
+       }
+#endif
+
        snd_m3_enable_ints(chip);
        snd_m3_assp_continue(chip);
 
index 3be8f97..6c3fd4d 100644 (file)
@@ -1102,73 +1102,17 @@ static int snd_mixart_free(struct mixart_mgr *mgr)
 /*
  * proc interface
  */
-static long long snd_mixart_BA0_llseek(struct snd_info_entry *entry,
-                                      void *private_file_data,
-                                      struct file *file,
-                                      long long offset,
-                                      int orig)
-{
-       offset = offset & ~3; /* 4 bytes aligned */
-
-       switch(orig) {
-       case SEEK_SET:
-               file->f_pos = offset;
-               break;
-       case SEEK_CUR:
-               file->f_pos += offset;
-               break;
-       case SEEK_END: /* offset is negative */
-               file->f_pos = MIXART_BA0_SIZE + offset;
-               break;
-       default:
-               return -EINVAL;
-       }
-       if(file->f_pos > MIXART_BA0_SIZE)
-               file->f_pos = MIXART_BA0_SIZE;
-       return file->f_pos;
-}
-
-static long long snd_mixart_BA1_llseek(struct snd_info_entry *entry,
-                                      void *private_file_data,
-                                      struct file *file,
-                                      long long offset,
-                                      int orig)
-{
-       offset = offset & ~3; /* 4 bytes aligned */
-
-       switch(orig) {
-       case SEEK_SET:
-               file->f_pos = offset;
-               break;
-       case SEEK_CUR:
-               file->f_pos += offset;
-               break;
-       case SEEK_END: /* offset is negative */
-               file->f_pos = MIXART_BA1_SIZE + offset;
-               break;
-       default:
-               return -EINVAL;
-       }
-       if(file->f_pos > MIXART_BA1_SIZE)
-               file->f_pos = MIXART_BA1_SIZE;
-       return file->f_pos;
-}
 
 /*
   mixart_BA0 proc interface for BAR 0 - read callback
  */
-static long snd_mixart_BA0_read(struct snd_info_entry *entry, void *file_private_data,
-                               struct file *file, char __user *buf,
-                               unsigned long count, unsigned long pos)
+static ssize_t snd_mixart_BA0_read(struct snd_info_entry *entry,
+                                  void *file_private_data,
+                                  struct file *file, char __user *buf,
+                                  size_t count, loff_t pos)
 {
        struct mixart_mgr *mgr = entry->private_data;
-       unsigned long maxsize;
 
-       if (pos >= MIXART_BA0_SIZE)
-               return 0;
-       maxsize = MIXART_BA0_SIZE - pos;
-       if (count > maxsize)
-               count = maxsize;
        count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
        if (copy_to_user_fromio(buf, MIXART_MEM(mgr, pos), count))
                return -EFAULT;
@@ -1178,18 +1122,13 @@ static long snd_mixart_BA0_read(struct snd_info_entry *entry, void *file_private
 /*
   mixart_BA1 proc interface for BAR 1 - read callback
  */
-static long snd_mixart_BA1_read(struct snd_info_entry *entry, void *file_private_data,
-                               struct file *file, char __user *buf,
-                               unsigned long count, unsigned long pos)
+static ssize_t snd_mixart_BA1_read(struct snd_info_entry *entry,
+                                  void *file_private_data,
+                                  struct file *file, char __user *buf,
+                                  size_t count, loff_t pos)
 {
        struct mixart_mgr *mgr = entry->private_data;
-       unsigned long maxsize;
 
-       if (pos > MIXART_BA1_SIZE)
-               return 0;
-       maxsize = MIXART_BA1_SIZE - pos;
-       if (count > maxsize)
-               count = maxsize;
        count = count & ~3; /* make sure the read size is a multiple of 4 bytes */
        if (copy_to_user_fromio(buf, MIXART_REG(mgr, pos), count))
                return -EFAULT;
@@ -1198,12 +1137,10 @@ static long snd_mixart_BA1_read(struct snd_info_entry *entry, void *file_private
 
 static struct snd_info_entry_ops snd_mixart_proc_ops_BA0 = {
        .read   = snd_mixart_BA0_read,
-       .llseek = snd_mixart_BA0_llseek
 };
 
 static struct snd_info_entry_ops snd_mixart_proc_ops_BA1 = {
        .read   = snd_mixart_BA1_read,
-       .llseek = snd_mixart_BA1_llseek
 };
 
 
index edaa729..df110df 100644 (file)
@@ -142,12 +142,7 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.NumPorts1 = 16;
 
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_FORCED_PULSE;
-       /* FIXME: This driver should be updated to allow for dynamic IRQ sharing */
-       /* link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_FORCED_PULSE; */
-
-       link->irq.Handler = pdacf_interrupt;
-       link->conf.Attributes = CONF_ENABLE_IRQ;
+       link->conf.Attributes = CONF_ENABLE_IRQ | CONF_ENABLE_PULSE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.ConfigIndex = 1;
        link->conf.Present = PRESENT_OPTION;
@@ -228,7 +223,7 @@ static int pdacf_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_exclusive_irq(link, pdacf_interrupt);
        if (ret)
                goto failed;
 
@@ -236,10 +231,9 @@ static int pdacf_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       if (snd_pdacf_assign_resources(pdacf, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
+       if (snd_pdacf_assign_resources(pdacf, link->io.BasePort1, link->irq) < 0)
                goto failed;
 
-       link->dev_node = &pdacf->node;
        return 0;
 
 failed:
index b060183..a0a7ec6 100644 (file)
@@ -117,7 +117,6 @@ struct snd_pdacf {
        
        /* pcmcia stuff */
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
 };
 
 static inline void pdacf_reg_write(struct snd_pdacf *chip, unsigned char reg, unsigned short val)
index cfd1438..624b47a 100644 (file)
@@ -162,10 +162,6 @@ static int snd_vxpocket_new(struct snd_card *card, int ibl,
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.NumPorts1 = 16;
 
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-
-       link->irq.Handler = &snd_vx_irq_handler;
-
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.ConfigIndex = 1;
@@ -215,7 +211,6 @@ static int snd_vxpocket_assign_resources(struct vx_core *chip, int port, int irq
 static int vxpocket_config(struct pcmcia_device *link)
 {
        struct vx_core *chip = link->priv;
-       struct snd_vxpocket *vxp = (struct snd_vxpocket *)chip;
        int ret;
 
        snd_printdd(KERN_DEBUG "vxpocket_config called\n");
@@ -235,7 +230,7 @@ static int vxpocket_config(struct pcmcia_device *link)
        if (ret)
                goto failed;
 
-       ret = pcmcia_request_irq(link, &link->irq);
+       ret = pcmcia_request_exclusive_irq(link, snd_vx_irq_handler);
        if (ret)
                goto failed;
 
@@ -246,10 +241,9 @@ static int vxpocket_config(struct pcmcia_device *link)
        chip->dev = &link->dev;
        snd_card_set_dev(chip->card, chip->dev);
 
-       if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq.AssignedIRQ) < 0)
+       if (snd_vxpocket_assign_resources(chip, link->io.BasePort1, link->irq) < 0)
                goto failed;
 
-       link->dev_node = &vxp->node;
        return 0;
 
 failed:
index 27ea002..ea4df16 100644 (file)
@@ -43,7 +43,6 @@ struct snd_vxpocket {
 
        /* pcmcia stuff */
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
 };
 
 extern struct snd_vx_ops snd_vxpocket_ops;
index 789f44f..20afdf9 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/kmod.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
+#include <linux/string.h>
 #include <sound/core.h>
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -46,6 +47,8 @@
 #define DBG(fmt...)
 #endif
 
+#define IS_G4DA (of_machine_is_compatible("PowerMac3,4"))
+
 /* i2c address for tumbler */
 #define TAS_I2C_ADDR   0x34
 
@@ -243,6 +246,7 @@ static int tumbler_set_master_volume(struct pmac_tumbler *mix)
                snd_printk(KERN_ERR "failed to set volume \n");
                return -EINVAL;
        }
+       DBG("(I) succeeded to set volume (%u, %u)\n", left_vol, right_vol);
        return 0;
 }
 
@@ -353,6 +357,7 @@ static int tumbler_set_drc(struct pmac_tumbler *mix)
                snd_printk(KERN_ERR "failed to set DRC\n");
                return -EINVAL;
        }
+       DBG("(I) succeeded to set DRC (%u, %u)\n", val[0], val[1]);
        return 0;
 }
 
@@ -389,6 +394,7 @@ static int snapper_set_drc(struct pmac_tumbler *mix)
                snd_printk(KERN_ERR "failed to set DRC\n");
                return -EINVAL;
        }
+       DBG("(I) succeeded to set DRC (%u, %u)\n", val[0], val[1]);
        return 0;
 }
 
@@ -1134,7 +1140,8 @@ static long tumbler_find_device(const char *device, const char *platform,
                gp->inactive_val = (*base) ? 0x4 : 0x5;
        } else {
                const u32 *prop = NULL;
-               gp->active_state = 0;
+               gp->active_state = IS_G4DA
+                               && !strncmp(device, "keywest-gpio1", 13);
                gp->active_val = 0x4;
                gp->inactive_val = 0x5;
                /* Here are some crude hacks to extract the GPIO polarity and
@@ -1312,6 +1319,9 @@ static int __devinit tumbler_init(struct snd_pmac *chip)
        if (irq <= NO_IRQ)
                irq = tumbler_find_device("line-output-detect",
                                          NULL, &mix->line_detect, 1);
+       if (IS_G4DA && irq <= NO_IRQ)
+               irq = tumbler_find_device("keywest-gpio16",
+                                         NULL, &mix->line_detect, 1);
        mix->lineout_irq = irq;
 
        tumbler_reset_audio(chip);
index 3e6628c..f6b3cc0 100644 (file)
@@ -415,9 +415,12 @@ static void atmel_pcm_free_dma_buffers(struct snd_pcm *pcm)
 }
 
 #ifdef CONFIG_PM
-static int atmel_pcm_suspend(struct snd_soc_dai *dai)
+static int atmel_pcm_suspend(struct snd_soc_dai_link *dai_link)
 {
-       struct snd_pcm_runtime *runtime = dai->runtime;
+       struct snd_pcm *pcm = dai_link->pcm;
+       struct snd_pcm_str *stream = &pcm->streams[0];
+       struct snd_pcm_substream *substream = stream->substream;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        struct atmel_runtime_data *prtd;
        struct atmel_pcm_dma_params *params;
 
@@ -439,9 +442,12 @@ static int atmel_pcm_suspend(struct snd_soc_dai *dai)
        return 0;
 }
 
-static int atmel_pcm_resume(struct snd_soc_dai *dai)
+static int atmel_pcm_resume(struct snd_soc_dai_link *dai_link)
 {
-       struct snd_pcm_runtime *runtime = dai->runtime;
+       struct snd_pcm *pcm = dai_link->pcm;
+       struct snd_pcm_str *stream = &pcm->streams[0];
+       struct snd_pcm_substream *substream = stream->substream;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        struct atmel_runtime_data *prtd;
        struct atmel_pcm_dma_params *params;
 
index 97f1a25..8ef2502 100644 (file)
@@ -49,13 +49,14 @@ config SND_BF5XX_SOC_AD1836
        help
          Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
 
-config SND_BF5XX_SOC_AD1938
-       tristate "SoC AD1938 Audio support for Blackfin"
+config SND_BF5XX_SOC_AD193X
+       tristate "SoC AD193X Audio support for Blackfin"
        depends on SND_BF5XX_TDM
        select SND_BF5XX_SOC_TDM
-       select SND_SOC_AD1938
+       select SND_SOC_AD193X
        help
-         Say Y if you want to add support for AD1938 codec on Blackfin.
+         Say Y if you want to add support for AD193X codec on Blackfin.
+         This driver supports AD1936, AD1937, AD1938 and AD1939.
 
 config SND_BF5XX_AC97
        tristate "SoC AC97 Audio for the ADI BF5xx chip"
index 87e3042..49af3f3 100644 (file)
@@ -20,10 +20,10 @@ snd-ad1836-objs := bf5xx-ad1836.o
 snd-ad1980-objs := bf5xx-ad1980.o
 snd-ssm2602-objs := bf5xx-ssm2602.o
 snd-ad73311-objs := bf5xx-ad73311.o
-snd-ad1938-objs := bf5xx-ad1938.o
+snd-ad193x-objs := bf5xx-ad193x.o
 
 obj-$(CONFIG_SND_BF5XX_SOC_AD1836) += snd-ad1836.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD1980) += snd-ad1980.o
 obj-$(CONFIG_SND_BF5XX_SOC_SSM2602) += snd-ssm2602.o
 obj-$(CONFIG_SND_BF5XX_SOC_AD73311) += snd-ad73311.o
-obj-$(CONFIG_SND_BF5XX_SOC_AD1938) += snd-ad1938.o
+obj-$(CONFIG_SND_BF5XX_SOC_AD193X) += snd-ad193x.o
similarity index 65%
rename from sound/soc/blackfin/bf5xx-ad1938.c
rename to sound/soc/blackfin/bf5xx-ad193x.c
index 2ef1e50..b8c9060 100644 (file)
@@ -1,9 +1,9 @@
 /*
- * File:         sound/soc/blackfin/bf5xx-ad1938.c
+ * File:         sound/soc/blackfin/bf5xx-ad193x.c
  * Author:       Barry Song <Barry.Song@analog.com>
  *
  * Created:      Thur June 4 2009
- * Description:  Board driver for ad1938 sound chip
+ * Description:  Board driver for ad193x sound chip
  *
  * Bugs:         Enter bugs at http://blackfin.uclinux.org/
  *
 #include <asm/dma.h>
 #include <asm/portmux.h>
 
-#include "../codecs/ad1938.h"
+#include "../codecs/ad193x.h"
 #include "bf5xx-sport.h"
 
 #include "bf5xx-tdm-pcm.h"
 #include "bf5xx-tdm.h"
 
-static struct snd_soc_card bf5xx_ad1938;
+static struct snd_soc_card bf5xx_ad193x;
 
-static int bf5xx_ad1938_startup(struct snd_pcm_substream *substream)
+static int bf5xx_ad193x_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
@@ -55,7 +55,7 @@ static int bf5xx_ad1938_startup(struct snd_pcm_substream *substream)
        return 0;
 }
 
-static int bf5xx_ad1938_hw_params(struct snd_pcm_substream *substream,
+static int bf5xx_ad193x_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
@@ -89,61 +89,61 @@ static int bf5xx_ad1938_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
-static struct snd_soc_ops bf5xx_ad1938_ops = {
-       .startup = bf5xx_ad1938_startup,
-       .hw_params = bf5xx_ad1938_hw_params,
+static struct snd_soc_ops bf5xx_ad193x_ops = {
+       .startup = bf5xx_ad193x_startup,
+       .hw_params = bf5xx_ad193x_hw_params,
 };
 
-static struct snd_soc_dai_link bf5xx_ad1938_dai = {
-       .name = "ad1938",
-       .stream_name = "AD1938",
+static struct snd_soc_dai_link bf5xx_ad193x_dai = {
+       .name = "ad193x",
+       .stream_name = "AD193X",
        .cpu_dai = &bf5xx_tdm_dai,
-       .codec_dai = &ad1938_dai,
-       .ops = &bf5xx_ad1938_ops,
+       .codec_dai = &ad193x_dai,
+       .ops = &bf5xx_ad193x_ops,
 };
 
-static struct snd_soc_card bf5xx_ad1938 = {
-       .name = "bf5xx_ad1938",
+static struct snd_soc_card bf5xx_ad193x = {
+       .name = "bf5xx_ad193x",
        .platform = &bf5xx_tdm_soc_platform,
-       .dai_link = &bf5xx_ad1938_dai,
+       .dai_link = &bf5xx_ad193x_dai,
        .num_links = 1,
 };
 
-static struct snd_soc_device bf5xx_ad1938_snd_devdata = {
-       .card = &bf5xx_ad1938,
-       .codec_dev = &soc_codec_dev_ad1938,
+static struct snd_soc_device bf5xx_ad193x_snd_devdata = {
+       .card = &bf5xx_ad193x,
+       .codec_dev = &soc_codec_dev_ad193x,
 };
 
-static struct platform_device *bfxx_ad1938_snd_device;
+static struct platform_device *bfxx_ad193x_snd_device;
 
-static int __init bf5xx_ad1938_init(void)
+static int __init bf5xx_ad193x_init(void)
 {
        int ret;
 
-       bfxx_ad1938_snd_device = platform_device_alloc("soc-audio", -1);
-       if (!bfxx_ad1938_snd_device)
+       bfxx_ad193x_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!bfxx_ad193x_snd_device)
                return -ENOMEM;
 
-       platform_set_drvdata(bfxx_ad1938_snd_device, &bf5xx_ad1938_snd_devdata);
-       bf5xx_ad1938_snd_devdata.dev = &bfxx_ad1938_snd_device->dev;
-       ret = platform_device_add(bfxx_ad1938_snd_device);
+       platform_set_drvdata(bfxx_ad193x_snd_device, &bf5xx_ad193x_snd_devdata);
+       bf5xx_ad193x_snd_devdata.dev = &bfxx_ad193x_snd_device->dev;
+       ret = platform_device_add(bfxx_ad193x_snd_device);
 
        if (ret)
-               platform_device_put(bfxx_ad1938_snd_device);
+               platform_device_put(bfxx_ad193x_snd_device);
 
        return ret;
 }
 
-static void __exit bf5xx_ad1938_exit(void)
+static void __exit bf5xx_ad193x_exit(void)
 {
-       platform_device_unregister(bfxx_ad1938_snd_device);
+       platform_device_unregister(bfxx_ad193x_snd_device);
 }
 
-module_init(bf5xx_ad1938_init);
-module_exit(bf5xx_ad1938_exit);
+module_init(bf5xx_ad193x_init);
+module_exit(bf5xx_ad193x_exit);
 
 /* Module information */
 MODULE_AUTHOR("Barry Song");
-MODULE_DESCRIPTION("ALSA SoC AD1938 board driver");
+MODULE_DESCRIPTION("ALSA SoC AD193X board driver");
 MODULE_LICENSE("GPL");
 
index 2e63dea..a86e8cc 100644 (file)
 #include <linux/wait.h>
 #include <linux/workqueue.h>
 #include <asm/dma.h>
-
-struct sport_register {
-       u16 tcr1;       u16 reserved0;
-       u16 tcr2;       u16 reserved1;
-       u16 tclkdiv;    u16 reserved2;
-       u16 tfsdiv;     u16 reserved3;
-       u32 tx;
-       u32 reserved_l0;
-       u32 rx;
-       u32 reserved_l1;
-       u16 rcr1;       u16 reserved4;
-       u16 rcr2;       u16 reserved5;
-       u16 rclkdiv;    u16 reserved6;
-       u16 rfsdiv;     u16 reserved7;
-       u16 stat;       u16 reserved8;
-       u16 chnl;       u16 reserved9;
-       u16 mcmc1;      u16 reserved10;
-       u16 mcmc2;      u16 reserved11;
-       u32 mtcs0;
-       u32 mtcs1;
-       u32 mtcs2;
-       u32 mtcs3;
-       u32 mrcs0;
-       u32 mrcs1;
-       u32 mrcs2;
-       u32 mrcs3;
-};
+#include <asm/bfin_sport.h>
 
 #define DESC_ELEMENT_COUNT 9
 
index 1743d56..31ac553 100644 (file)
@@ -13,7 +13,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_L3
        select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS
        select SND_SOC_AD1836 if SPI_MASTER
-       select SND_SOC_AD1938 if SPI_MASTER
+       select SND_SOC_AD193X if SND_SOC_I2C_AND_SPI
        select SND_SOC_AD1980 if SND_SOC_AC97_BUS
        select SND_SOC_ADS117X
        select SND_SOC_AD73311 if I2C
@@ -21,6 +21,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_AK4535 if I2C
        select SND_SOC_AK4642 if I2C
        select SND_SOC_AK4671 if I2C
+       select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
        select SND_SOC_CS4270 if I2C
        select SND_SOC_MAX9877 if I2C
        select SND_SOC_DA7210 if I2C
@@ -34,6 +35,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_TPA6130A2 if I2C
        select SND_SOC_TLV320DAC33 if I2C
        select SND_SOC_TWL4030 if TWL4030_CORE
+       select SND_SOC_TWL6040 if TWL4030_CORE
        select SND_SOC_UDA134X
        select SND_SOC_UDA1380 if I2C
        select SND_SOC_WM2000 if I2C
@@ -64,6 +66,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_WM8993 if I2C
        select SND_SOC_WM8994 if MFD_WM8994
        select SND_SOC_WM9081 if I2C
+       select SND_SOC_WM9090 if I2C
        select SND_SOC_WM9705 if SND_SOC_AC97_BUS
        select SND_SOC_WM9712 if SND_SOC_AC97_BUS
        select SND_SOC_WM9713 if SND_SOC_AC97_BUS
@@ -90,7 +93,7 @@ config SND_SOC_AC97_CODEC
 config SND_SOC_AD1836
        tristate
 
-config SND_SOC_AD1938
+config SND_SOC_AD193X
        tristate
 
 config SND_SOC_AD1980
@@ -114,6 +117,9 @@ config SND_SOC_AK4642
 config SND_SOC_AK4671
        tristate
 
+config SND_SOC_CQ0093VC
+       tristate
+
 # Cirrus Logic CS4270 Codec
 config SND_SOC_CS4270
        tristate
@@ -164,6 +170,9 @@ config SND_SOC_TWL4030
        select TWL4030_CODEC
        tristate
 
+config SND_SOC_TWL6040
+       tristate
+
 config SND_SOC_UDA134X
        tristate
 
@@ -269,3 +278,6 @@ config SND_SOC_TPA6130A2
 
 config SND_SOC_WM2000
        tristate
+
+config SND_SOC_WM9090
+       tristate
index dd5ce6d..91429ea 100644 (file)
@@ -1,6 +1,6 @@
 snd-soc-ac97-objs := ac97.o
 snd-soc-ad1836-objs := ad1836.o
-snd-soc-ad1938-objs := ad1938.o
+snd-soc-ad193x-objs := ad193x.o
 snd-soc-ad1980-objs := ad1980.o
 snd-soc-ad73311-objs := ad73311.o
 snd-soc-ads117x-objs := ads117x.o
@@ -8,6 +8,7 @@ snd-soc-ak4104-objs := ak4104.o
 snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4642-objs := ak4642.o
 snd-soc-ak4671-objs := ak4671.o
+snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs4270-objs := cs4270.o
 snd-soc-cx20442-objs := cx20442.o
 snd-soc-da7210-objs := da7210.o
@@ -21,6 +22,7 @@ snd-soc-tlv320aic26-objs := tlv320aic26.o
 snd-soc-tlv320aic3x-objs := tlv320aic3x.o
 snd-soc-tlv320dac33-objs := tlv320dac33.o
 snd-soc-twl4030-objs := twl4030.o
+snd-soc-twl6040-objs := twl6040.o
 snd-soc-uda134x-objs := uda134x.o
 snd-soc-uda1380-objs := uda1380.o
 snd-soc-wm8350-objs := wm8350.o
@@ -59,10 +61,11 @@ snd-soc-wm-hubs-objs := wm_hubs.o
 snd-soc-max9877-objs := max9877.o
 snd-soc-tpa6130a2-objs := tpa6130a2.o
 snd-soc-wm2000-objs := wm2000.o
+snd-soc-wm9090-objs := wm9090.o
 
 obj-$(CONFIG_SND_SOC_AC97_CODEC)       += snd-soc-ac97.o
 obj-$(CONFIG_SND_SOC_AD1836)   += snd-soc-ad1836.o
-obj-$(CONFIG_SND_SOC_AD1938)   += snd-soc-ad1938.o
+obj-$(CONFIG_SND_SOC_AD193X)   += snd-soc-ad193x.o
 obj-$(CONFIG_SND_SOC_AD1980)   += snd-soc-ad1980.o
 obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
 obj-$(CONFIG_SND_SOC_ADS117X)  += snd-soc-ads117x.o
@@ -70,6 +73,7 @@ obj-$(CONFIG_SND_SOC_AK4104)  += snd-soc-ak4104.o
 obj-$(CONFIG_SND_SOC_AK4535)   += snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4642)   += snd-soc-ak4642.o
 obj-$(CONFIG_SND_SOC_AK4671)   += snd-soc-ak4671.o
+obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
 obj-$(CONFIG_SND_SOC_CS4270)   += snd-soc-cs4270.o
 obj-$(CONFIG_SND_SOC_CX20442)  += snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_DA7210)   += snd-soc-da7210.o
@@ -83,6 +87,7 @@ obj-$(CONFIG_SND_SOC_TLV320AIC26)     += snd-soc-tlv320aic26.o
 obj-$(CONFIG_SND_SOC_TLV320AIC3X)      += snd-soc-tlv320aic3x.o
 obj-$(CONFIG_SND_SOC_TLV320DAC33)      += snd-soc-tlv320dac33.o
 obj-$(CONFIG_SND_SOC_TWL4030)  += snd-soc-twl4030.o
+obj-$(CONFIG_SND_SOC_TWL6040)  += snd-soc-twl6040.o
 obj-$(CONFIG_SND_SOC_UDA134X)  += snd-soc-uda134x.o
 obj-$(CONFIG_SND_SOC_UDA1380)  += snd-soc-uda1380.o
 obj-$(CONFIG_SND_SOC_WM8350)   += snd-soc-wm8350.o
@@ -121,3 +126,4 @@ obj-$(CONFIG_SND_SOC_WM_HUBS)       += snd-soc-wm-hubs.o
 obj-$(CONFIG_SND_SOC_MAX9877)  += snd-soc-max9877.o
 obj-$(CONFIG_SND_SOC_TPA6130A2)        += snd-soc-tpa6130a2.o
 obj-$(CONFIG_SND_SOC_WM2000)   += snd-soc-wm2000.o
+obj-$(CONFIG_SND_SOC_WM9090)   += snd-soc-wm9090.o
index 11b62de..2175384 100644 (file)
@@ -278,7 +278,7 @@ static int ad1836_register(struct ad1836_priv *ad1836)
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
-       codec->private_data = ad1836;
+       snd_soc_codec_set_drvdata(codec, ad1836);
        codec->reg_cache = ad1836->reg_cache;
        codec->reg_cache_size = AD1836_NUM_REGS;
        codec->name = "AD1836";
diff --git a/sound/soc/codecs/ad1938.c b/sound/soc/codecs/ad1938.c
deleted file mode 100644 (file)
index 240cd15..0000000
+++ /dev/null
@@ -1,522 +0,0 @@
-/*
- * File:         sound/soc/codecs/ad1938.c
- * Author:       Barry Song <Barry.Song@analog.com>
- *
- * Created:      June 04 2009
- * Description:  Driver for AD1938 sound chip
- *
- * Modified:
- *               Copyright 2009 Analog Devices Inc.
- *
- * Bugs:         Enter bugs at http://blackfin.uclinux.org/
- *
- * 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, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/device.h>
-#include <sound/core.h>
-#include <sound/pcm.h>
-#include <sound/pcm_params.h>
-#include <sound/initval.h>
-#include <sound/soc.h>
-#include <sound/tlv.h>
-#include <sound/soc-dapm.h>
-#include <linux/spi/spi.h>
-#include "ad1938.h"
-
-/* codec private data */
-struct ad1938_priv {
-       struct snd_soc_codec codec;
-       u8 reg_cache[AD1938_NUM_REGS];
-};
-
-/* ad1938 register cache & default register settings */
-static const u8 ad1938_reg[AD1938_NUM_REGS] = {
-       0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0,
-};
-
-static struct snd_soc_codec *ad1938_codec;
-struct snd_soc_codec_device soc_codec_dev_ad1938;
-static int ad1938_register(struct ad1938_priv *ad1938);
-static void ad1938_unregister(struct ad1938_priv *ad1938);
-
-/*
- * AD1938 volume/mute/de-emphasis etc. controls
- */
-static const char *ad1938_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"};
-
-static const struct soc_enum ad1938_deemp_enum =
-       SOC_ENUM_SINGLE(AD1938_DAC_CTRL2, 1, 4, ad1938_deemp);
-
-static const struct snd_kcontrol_new ad1938_snd_controls[] = {
-       /* DAC volume control */
-       SOC_DOUBLE_R("DAC1  Volume", AD1938_DAC_L1_VOL,
-                       AD1938_DAC_R1_VOL, 0, 0xFF, 1),
-       SOC_DOUBLE_R("DAC2  Volume", AD1938_DAC_L2_VOL,
-                       AD1938_DAC_R2_VOL, 0, 0xFF, 1),
-       SOC_DOUBLE_R("DAC3  Volume", AD1938_DAC_L3_VOL,
-                       AD1938_DAC_R3_VOL, 0, 0xFF, 1),
-       SOC_DOUBLE_R("DAC4  Volume", AD1938_DAC_L4_VOL,
-                       AD1938_DAC_R4_VOL, 0, 0xFF, 1),
-
-       /* ADC switch control */
-       SOC_DOUBLE("ADC1 Switch", AD1938_ADC_CTRL0, AD1938_ADCL1_MUTE,
-               AD1938_ADCR1_MUTE, 1, 1),
-       SOC_DOUBLE("ADC2 Switch", AD1938_ADC_CTRL0, AD1938_ADCL2_MUTE,
-               AD1938_ADCR2_MUTE, 1, 1),
-
-       /* DAC switch control */
-       SOC_DOUBLE("DAC1 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL1_MUTE,
-               AD1938_DACR1_MUTE, 1, 1),
-       SOC_DOUBLE("DAC2 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL2_MUTE,
-               AD1938_DACR2_MUTE, 1, 1),
-       SOC_DOUBLE("DAC3 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL3_MUTE,
-               AD1938_DACR3_MUTE, 1, 1),
-       SOC_DOUBLE("DAC4 Switch", AD1938_DAC_CHNL_MUTE, AD1938_DACL4_MUTE,
-               AD1938_DACR4_MUTE, 1, 1),
-
-       /* ADC high-pass filter */
-       SOC_SINGLE("ADC High Pass Filter Switch", AD1938_ADC_CTRL0,
-                       AD1938_ADC_HIGHPASS_FILTER, 1, 0),
-
-       /* DAC de-emphasis */
-       SOC_ENUM("Playback Deemphasis", ad1938_deemp_enum),
-};
-
-static const struct snd_soc_dapm_widget ad1938_dapm_widgets[] = {
-       SND_SOC_DAPM_DAC("DAC", "Playback", AD1938_DAC_CTRL0, 0, 1),
-       SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
-       SND_SOC_DAPM_SUPPLY("PLL_PWR", AD1938_PLL_CLK_CTRL0, 0, 1, NULL, 0),
-       SND_SOC_DAPM_SUPPLY("ADC_PWR", AD1938_ADC_CTRL0, 0, 1, NULL, 0),
-       SND_SOC_DAPM_OUTPUT("DAC1OUT"),
-       SND_SOC_DAPM_OUTPUT("DAC2OUT"),
-       SND_SOC_DAPM_OUTPUT("DAC3OUT"),
-       SND_SOC_DAPM_OUTPUT("DAC4OUT"),
-       SND_SOC_DAPM_INPUT("ADC1IN"),
-       SND_SOC_DAPM_INPUT("ADC2IN"),
-};
-
-static const struct snd_soc_dapm_route audio_paths[] = {
-       { "DAC", NULL, "PLL_PWR" },
-       { "ADC", NULL, "PLL_PWR" },
-       { "DAC", NULL, "ADC_PWR" },
-       { "ADC", NULL, "ADC_PWR" },
-       { "DAC1OUT", "DAC1 Switch", "DAC" },
-       { "DAC2OUT", "DAC2 Switch", "DAC" },
-       { "DAC3OUT", "DAC3 Switch", "DAC" },
-       { "DAC4OUT", "DAC4 Switch", "DAC" },
-       { "ADC", "ADC1 Switch", "ADC1IN" },
-       { "ADC", "ADC2 Switch", "ADC2IN" },
-};
-
-/*
- * DAI ops entries
- */
-
-static int ad1938_mute(struct snd_soc_dai *dai, int mute)
-{
-       struct snd_soc_codec *codec = dai->codec;
-       int reg;
-
-       reg = snd_soc_read(codec, AD1938_DAC_CTRL2);
-       reg = (mute > 0) ? reg | AD1938_DAC_MASTER_MUTE : reg &
-               (~AD1938_DAC_MASTER_MUTE);
-       snd_soc_write(codec, AD1938_DAC_CTRL2, reg);
-
-       return 0;
-}
-
-static int ad1938_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
-                              unsigned int rx_mask, int slots, int width)
-{
-       struct snd_soc_codec *codec = dai->codec;
-       int dac_reg = snd_soc_read(codec, AD1938_DAC_CTRL1);
-       int adc_reg = snd_soc_read(codec, AD1938_ADC_CTRL2);
-
-       dac_reg &= ~AD1938_DAC_CHAN_MASK;
-       adc_reg &= ~AD1938_ADC_CHAN_MASK;
-
-       switch (slots) {
-       case 2:
-               dac_reg |= AD1938_DAC_2_CHANNELS << AD1938_DAC_CHAN_SHFT;
-               adc_reg |= AD1938_ADC_2_CHANNELS << AD1938_ADC_CHAN_SHFT;
-               break;
-       case 4:
-               dac_reg |= AD1938_DAC_4_CHANNELS << AD1938_DAC_CHAN_SHFT;
-               adc_reg |= AD1938_ADC_4_CHANNELS << AD1938_ADC_CHAN_SHFT;
-               break;
-       case 8:
-               dac_reg |= AD1938_DAC_8_CHANNELS << AD1938_DAC_CHAN_SHFT;
-               adc_reg |= AD1938_ADC_8_CHANNELS << AD1938_ADC_CHAN_SHFT;
-               break;
-       case 16:
-               dac_reg |= AD1938_DAC_16_CHANNELS << AD1938_DAC_CHAN_SHFT;
-               adc_reg |= AD1938_ADC_16_CHANNELS << AD1938_ADC_CHAN_SHFT;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       snd_soc_write(codec, AD1938_DAC_CTRL1, dac_reg);
-       snd_soc_write(codec, AD1938_ADC_CTRL2, adc_reg);
-
-       return 0;
-}
-
-static int ad1938_set_dai_fmt(struct snd_soc_dai *codec_dai,
-               unsigned int fmt)
-{
-       struct snd_soc_codec *codec = codec_dai->codec;
-       int adc_reg, dac_reg;
-
-       adc_reg = snd_soc_read(codec, AD1938_ADC_CTRL2);
-       dac_reg = snd_soc_read(codec, AD1938_DAC_CTRL1);
-
-       /* At present, the driver only support AUX ADC mode(SND_SOC_DAIFMT_I2S
-        * with TDM) and ADC&DAC TDM mode(SND_SOC_DAIFMT_DSP_A)
-        */
-       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
-       case SND_SOC_DAIFMT_I2S:
-               adc_reg &= ~AD1938_ADC_SERFMT_MASK;
-               adc_reg |= AD1938_ADC_SERFMT_TDM;
-               break;
-       case SND_SOC_DAIFMT_DSP_A:
-               adc_reg &= ~AD1938_ADC_SERFMT_MASK;
-               adc_reg |= AD1938_ADC_SERFMT_AUX;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
-       case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
-               adc_reg &= ~AD1938_ADC_LEFT_HIGH;
-               adc_reg &= ~AD1938_ADC_BCLK_INV;
-               dac_reg &= ~AD1938_DAC_LEFT_HIGH;
-               dac_reg &= ~AD1938_DAC_BCLK_INV;
-               break;
-       case SND_SOC_DAIFMT_NB_IF: /* normal bclk + invert frm */
-               adc_reg |= AD1938_ADC_LEFT_HIGH;
-               adc_reg &= ~AD1938_ADC_BCLK_INV;
-               dac_reg |= AD1938_DAC_LEFT_HIGH;
-               dac_reg &= ~AD1938_DAC_BCLK_INV;
-               break;
-       case SND_SOC_DAIFMT_IB_NF: /* invert bclk + normal frm */
-               adc_reg &= ~AD1938_ADC_LEFT_HIGH;
-               adc_reg |= AD1938_ADC_BCLK_INV;
-               dac_reg &= ~AD1938_DAC_LEFT_HIGH;
-               dac_reg |= AD1938_DAC_BCLK_INV;
-               break;
-
-       case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */
-               adc_reg |= AD1938_ADC_LEFT_HIGH;
-               adc_reg |= AD1938_ADC_BCLK_INV;
-               dac_reg |= AD1938_DAC_LEFT_HIGH;
-               dac_reg |= AD1938_DAC_BCLK_INV;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
-       case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */
-               adc_reg |= AD1938_ADC_LCR_MASTER;
-               adc_reg |= AD1938_ADC_BCLK_MASTER;
-               dac_reg |= AD1938_DAC_LCR_MASTER;
-               dac_reg |= AD1938_DAC_BCLK_MASTER;
-               break;
-       case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & frm master */
-               adc_reg |= AD1938_ADC_LCR_MASTER;
-               adc_reg &= ~AD1938_ADC_BCLK_MASTER;
-               dac_reg |= AD1938_DAC_LCR_MASTER;
-               dac_reg &= ~AD1938_DAC_BCLK_MASTER;
-               break;
-       case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */
-               adc_reg &= ~AD1938_ADC_LCR_MASTER;
-               adc_reg |= AD1938_ADC_BCLK_MASTER;
-               dac_reg &= ~AD1938_DAC_LCR_MASTER;
-               dac_reg |= AD1938_DAC_BCLK_MASTER;
-               break;
-       case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */
-               adc_reg &= ~AD1938_ADC_LCR_MASTER;
-               adc_reg &= ~AD1938_ADC_BCLK_MASTER;
-               dac_reg &= ~AD1938_DAC_LCR_MASTER;
-               dac_reg &= ~AD1938_DAC_BCLK_MASTER;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       snd_soc_write(codec, AD1938_ADC_CTRL2, adc_reg);
-       snd_soc_write(codec, AD1938_DAC_CTRL1, dac_reg);
-
-       return 0;
-}
-
-static int ad1938_hw_params(struct snd_pcm_substream *substream,
-               struct snd_pcm_hw_params *params,
-               struct snd_soc_dai *dai)
-{
-       int word_len = 0, reg = 0;
-
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_device *socdev = rtd->socdev;
-       struct snd_soc_codec *codec = socdev->card->codec;
-
-       /* bit size */
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S16_LE:
-               word_len = 3;
-               break;
-       case SNDRV_PCM_FORMAT_S20_3LE:
-               word_len = 1;
-               break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-       case SNDRV_PCM_FORMAT_S32_LE:
-               word_len = 0;
-               break;
-       }
-
-       reg = snd_soc_read(codec, AD1938_DAC_CTRL2);
-       reg = (reg & (~AD1938_DAC_WORD_LEN_MASK)) | word_len;
-       snd_soc_write(codec, AD1938_DAC_CTRL2, reg);
-
-       reg = snd_soc_read(codec, AD1938_ADC_CTRL1);
-       reg = (reg & (~AD1938_ADC_WORD_LEN_MASK)) | word_len;
-       snd_soc_write(codec, AD1938_ADC_CTRL1, reg);
-
-       return 0;
-}
-
-static int __devinit ad1938_spi_probe(struct spi_device *spi)
-{
-       struct snd_soc_codec *codec;
-       struct ad1938_priv *ad1938;
-
-       ad1938 = kzalloc(sizeof(struct ad1938_priv), GFP_KERNEL);
-       if (ad1938 == NULL)
-               return -ENOMEM;
-
-       codec = &ad1938->codec;
-       codec->control_data = spi;
-       codec->dev = &spi->dev;
-
-       dev_set_drvdata(&spi->dev, ad1938);
-
-       return ad1938_register(ad1938);
-}
-
-static int __devexit ad1938_spi_remove(struct spi_device *spi)
-{
-       struct ad1938_priv *ad1938 = dev_get_drvdata(&spi->dev);
-
-       ad1938_unregister(ad1938);
-       return 0;
-}
-
-static struct spi_driver ad1938_spi_driver = {
-       .driver = {
-               .name   = "ad1938",
-               .owner  = THIS_MODULE,
-       },
-       .probe          = ad1938_spi_probe,
-       .remove         = __devexit_p(ad1938_spi_remove),
-};
-
-static struct snd_soc_dai_ops ad1938_dai_ops = {
-       .hw_params = ad1938_hw_params,
-       .digital_mute = ad1938_mute,
-       .set_tdm_slot = ad1938_set_tdm_slot,
-       .set_fmt = ad1938_set_dai_fmt,
-};
-
-/* codec DAI instance */
-struct snd_soc_dai ad1938_dai = {
-       .name = "AD1938",
-       .playback = {
-               .stream_name = "Playback",
-               .channels_min = 2,
-               .channels_max = 8,
-               .rates = SNDRV_PCM_RATE_48000,
-               .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
-                       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
-       },
-       .capture = {
-               .stream_name = "Capture",
-               .channels_min = 2,
-               .channels_max = 4,
-               .rates = SNDRV_PCM_RATE_48000,
-               .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
-                       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
-       },
-       .ops = &ad1938_dai_ops,
-};
-EXPORT_SYMBOL_GPL(ad1938_dai);
-
-static int ad1938_register(struct ad1938_priv *ad1938)
-{
-       int ret;
-       struct snd_soc_codec *codec = &ad1938->codec;
-
-       if (ad1938_codec) {
-               dev_err(codec->dev, "Another ad1938 is registered\n");
-               return -EINVAL;
-       }
-
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-       codec->private_data = ad1938;
-       codec->reg_cache = ad1938->reg_cache;
-       codec->reg_cache_size = AD1938_NUM_REGS;
-       codec->name = "AD1938";
-       codec->owner = THIS_MODULE;
-       codec->dai = &ad1938_dai;
-       codec->num_dai = 1;
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-
-       ad1938_dai.dev = codec->dev;
-       ad1938_codec = codec;
-
-       memcpy(codec->reg_cache, ad1938_reg, AD1938_NUM_REGS);
-
-       ret = snd_soc_codec_set_cache_io(codec, 16, 8, SND_SOC_SPI);
-       if (ret < 0) {
-               dev_err(codec->dev, "failed to set cache I/O: %d\n",
-                               ret);
-               kfree(ad1938);
-               return ret;
-       }
-
-       /* default setting for ad1938 */
-
-       /* unmute dac channels */
-       snd_soc_write(codec, AD1938_DAC_CHNL_MUTE, 0x0);
-       /* de-emphasis: 48kHz, powedown dac */
-       snd_soc_write(codec, AD1938_DAC_CTRL2, 0x1A);
-       /* powerdown dac, dac in tdm mode */
-       snd_soc_write(codec, AD1938_DAC_CTRL0, 0x41);
-       /* high-pass filter enable */
-       snd_soc_write(codec, AD1938_ADC_CTRL0, 0x3);
-       /* sata delay=1, adc aux mode */
-       snd_soc_write(codec, AD1938_ADC_CTRL1, 0x43);
-       /* pll input: mclki/xi */
-       snd_soc_write(codec, AD1938_PLL_CLK_CTRL0, 0x9D);
-       snd_soc_write(codec, AD1938_PLL_CLK_CTRL1, 0x04);
-
-       ret = snd_soc_register_codec(codec);
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
-               kfree(ad1938);
-               return ret;
-       }
-
-       ret = snd_soc_register_dai(&ad1938_dai);
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
-               snd_soc_unregister_codec(codec);
-               kfree(ad1938);
-               return ret;
-       }
-
-       return 0;
-}
-
-static void ad1938_unregister(struct ad1938_priv *ad1938)
-{
-       snd_soc_unregister_dai(&ad1938_dai);
-       snd_soc_unregister_codec(&ad1938->codec);
-       kfree(ad1938);
-       ad1938_codec = NULL;
-}
-
-static int ad1938_probe(struct platform_device *pdev)
-{
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec;
-       int ret = 0;
-
-       if (ad1938_codec == NULL) {
-               dev_err(&pdev->dev, "Codec device not registered\n");
-               return -ENODEV;
-       }
-
-       socdev->card->codec = ad1938_codec;
-       codec = ad1938_codec;
-
-       /* register pcms */
-       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
-       if (ret < 0) {
-               dev_err(codec->dev, "failed to create pcms: %d\n", ret);
-               goto pcm_err;
-       }
-
-       snd_soc_add_controls(codec, ad1938_snd_controls,
-                            ARRAY_SIZE(ad1938_snd_controls));
-       snd_soc_dapm_new_controls(codec, ad1938_dapm_widgets,
-                                 ARRAY_SIZE(ad1938_dapm_widgets));
-       snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
-
-
-pcm_err:
-       return ret;
-}
-
-/* power down chip */
-static int ad1938_remove(struct platform_device *pdev)
-{
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
-
-       return 0;
-}
-
-struct snd_soc_codec_device soc_codec_dev_ad1938 = {
-       .probe =        ad1938_probe,
-       .remove =       ad1938_remove,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_ad1938);
-
-static int __init ad1938_init(void)
-{
-       int ret;
-
-       ret = spi_register_driver(&ad1938_spi_driver);
-       if (ret != 0) {
-               printk(KERN_ERR "Failed to register ad1938 SPI driver: %d\n",
-                               ret);
-       }
-
-       return ret;
-}
-module_init(ad1938_init);
-
-static void __exit ad1938_exit(void)
-{
-       spi_unregister_driver(&ad1938_spi_driver);
-}
-module_exit(ad1938_exit);
-
-MODULE_DESCRIPTION("ASoC ad1938 driver");
-MODULE_AUTHOR("Barry Song ");
-MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad1938.h b/sound/soc/codecs/ad1938.h
deleted file mode 100644 (file)
index fe3c48c..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * File:         sound/soc/codecs/ad1836.h
- * Based on:
- * Author:       Barry Song <Barry.Song@analog.com>
- *
- * Created:      May 25, 2009
- * Description:  definitions for AD1938 registers
- *
- * Modified:
- *
- * Bugs:         Enter bugs at http://blackfin.uclinux.org/
- *
- * 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, see the file COPYING, or write
- * to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef __AD1938_H__
-#define __AD1938_H__
-
-#define AD1938_PLL_CLK_CTRL0    0
-#define AD1938_PLL_POWERDOWN           0x01
-#define AD1938_PLL_CLK_CTRL1    1
-#define AD1938_DAC_CTRL0        2
-#define AD1938_DAC_POWERDOWN           0x01
-#define AD1938_DAC_SERFMT_MASK         0xC0
-#define AD1938_DAC_SERFMT_STEREO       (0 << 6)
-#define AD1938_DAC_SERFMT_TDM          (1 << 6)
-#define AD1938_DAC_CTRL1        3
-#define AD1938_DAC_2_CHANNELS   0
-#define AD1938_DAC_4_CHANNELS   1
-#define AD1938_DAC_8_CHANNELS   2
-#define AD1938_DAC_16_CHANNELS  3
-#define AD1938_DAC_CHAN_SHFT    1
-#define AD1938_DAC_CHAN_MASK    (3 << AD1938_DAC_CHAN_SHFT)
-#define AD1938_DAC_LCR_MASTER   (1 << 4)
-#define AD1938_DAC_BCLK_MASTER  (1 << 5)
-#define AD1938_DAC_LEFT_HIGH    (1 << 3)
-#define AD1938_DAC_BCLK_INV     (1 << 7)
-#define AD1938_DAC_CTRL2        4
-#define AD1938_DAC_WORD_LEN_MASK       0xC
-#define AD1938_DAC_MASTER_MUTE  1
-#define AD1938_DAC_CHNL_MUTE    5
-#define AD1938_DACL1_MUTE       0
-#define AD1938_DACR1_MUTE       1
-#define AD1938_DACL2_MUTE       2
-#define AD1938_DACR2_MUTE       3
-#define AD1938_DACL3_MUTE       4
-#define AD1938_DACR3_MUTE       5
-#define AD1938_DACL4_MUTE       6
-#define AD1938_DACR4_MUTE       7
-#define AD1938_DAC_L1_VOL       6
-#define AD1938_DAC_R1_VOL       7
-#define AD1938_DAC_L2_VOL       8
-#define AD1938_DAC_R2_VOL       9
-#define AD1938_DAC_L3_VOL       10
-#define AD1938_DAC_R3_VOL       11
-#define AD1938_DAC_L4_VOL       12
-#define AD1938_DAC_R4_VOL       13
-#define AD1938_ADC_CTRL0        14
-#define AD1938_ADC_POWERDOWN           0x01
-#define AD1938_ADC_HIGHPASS_FILTER     1
-#define AD1938_ADCL1_MUTE              2
-#define AD1938_ADCR1_MUTE              3
-#define AD1938_ADCL2_MUTE              4
-#define AD1938_ADCR2_MUTE              5
-#define AD1938_ADC_CTRL1        15
-#define AD1938_ADC_SERFMT_MASK         0x60
-#define AD1938_ADC_SERFMT_STEREO       (0 << 5)
-#define AD1938_ADC_SERFMT_TDM          (1 << 2)
-#define AD1938_ADC_SERFMT_AUX          (2 << 5)
-#define AD1938_ADC_WORD_LEN_MASK       0x3
-#define AD1938_ADC_CTRL2        16
-#define AD1938_ADC_2_CHANNELS   0
-#define AD1938_ADC_4_CHANNELS   1
-#define AD1938_ADC_8_CHANNELS   2
-#define AD1938_ADC_16_CHANNELS  3
-#define AD1938_ADC_CHAN_SHFT    4
-#define AD1938_ADC_CHAN_MASK    (3 << AD1938_ADC_CHAN_SHFT)
-#define AD1938_ADC_LCR_MASTER   (1 << 3)
-#define AD1938_ADC_BCLK_MASTER  (1 << 6)
-#define AD1938_ADC_LEFT_HIGH    (1 << 2)
-#define AD1938_ADC_BCLK_INV     (1 << 1)
-
-#define AD1938_NUM_REGS          17
-
-extern struct snd_soc_dai ad1938_dai;
-extern struct snd_soc_codec_device soc_codec_dev_ad1938;
-#endif
diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
new file mode 100644 (file)
index 0000000..c8ca114
--- /dev/null
@@ -0,0 +1,547 @@
+/*
+ * AD193X Audio Codec driver supporting AD1936/7/8/9
+ *
+ * Copyright 2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/soc-dapm.h>
+#include "ad193x.h"
+
+/* codec private data */
+struct ad193x_priv {
+       struct snd_soc_codec codec;
+       u8 reg_cache[AD193X_NUM_REGS];
+};
+
+/* ad193x register cache & default register settings */
+static const u8 ad193x_reg[AD193X_NUM_REGS] = {
+       0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0,
+};
+
+static struct snd_soc_codec *ad193x_codec;
+struct snd_soc_codec_device soc_codec_dev_ad193x;
+
+/*
+ * AD193X volume/mute/de-emphasis etc. controls
+ */
+static const char *ad193x_deemp[] = {"None", "48kHz", "44.1kHz", "32kHz"};
+
+static const struct soc_enum ad193x_deemp_enum =
+       SOC_ENUM_SINGLE(AD193X_DAC_CTRL2, 1, 4, ad193x_deemp);
+
+static const struct snd_kcontrol_new ad193x_snd_controls[] = {
+       /* DAC volume control */
+       SOC_DOUBLE_R("DAC1 Volume", AD193X_DAC_L1_VOL,
+                       AD193X_DAC_R1_VOL, 0, 0xFF, 1),
+       SOC_DOUBLE_R("DAC2 Volume", AD193X_DAC_L2_VOL,
+                       AD193X_DAC_R2_VOL, 0, 0xFF, 1),
+       SOC_DOUBLE_R("DAC3 Volume", AD193X_DAC_L3_VOL,
+                       AD193X_DAC_R3_VOL, 0, 0xFF, 1),
+       SOC_DOUBLE_R("DAC4 Volume", AD193X_DAC_L4_VOL,
+                       AD193X_DAC_R4_VOL, 0, 0xFF, 1),
+
+       /* ADC switch control */
+       SOC_DOUBLE("ADC1 Switch", AD193X_ADC_CTRL0, AD193X_ADCL1_MUTE,
+               AD193X_ADCR1_MUTE, 1, 1),
+       SOC_DOUBLE("ADC2 Switch", AD193X_ADC_CTRL0, AD193X_ADCL2_MUTE,
+               AD193X_ADCR2_MUTE, 1, 1),
+
+       /* DAC switch control */
+       SOC_DOUBLE("DAC1 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL1_MUTE,
+               AD193X_DACR1_MUTE, 1, 1),
+       SOC_DOUBLE("DAC2 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL2_MUTE,
+               AD193X_DACR2_MUTE, 1, 1),
+       SOC_DOUBLE("DAC3 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL3_MUTE,
+               AD193X_DACR3_MUTE, 1, 1),
+       SOC_DOUBLE("DAC4 Switch", AD193X_DAC_CHNL_MUTE, AD193X_DACL4_MUTE,
+               AD193X_DACR4_MUTE, 1, 1),
+
+       /* ADC high-pass filter */
+       SOC_SINGLE("ADC High Pass Filter Switch", AD193X_ADC_CTRL0,
+                       AD193X_ADC_HIGHPASS_FILTER, 1, 0),
+
+       /* DAC de-emphasis */
+       SOC_ENUM("Playback Deemphasis", ad193x_deemp_enum),
+};
+
+static const struct snd_soc_dapm_widget ad193x_dapm_widgets[] = {
+       SND_SOC_DAPM_DAC("DAC", "Playback", AD193X_DAC_CTRL0, 0, 1),
+       SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_SUPPLY("PLL_PWR", AD193X_PLL_CLK_CTRL0, 0, 1, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("ADC_PWR", AD193X_ADC_CTRL0, 0, 1, NULL, 0),
+       SND_SOC_DAPM_OUTPUT("DAC1OUT"),
+       SND_SOC_DAPM_OUTPUT("DAC2OUT"),
+       SND_SOC_DAPM_OUTPUT("DAC3OUT"),
+       SND_SOC_DAPM_OUTPUT("DAC4OUT"),
+       SND_SOC_DAPM_INPUT("ADC1IN"),
+       SND_SOC_DAPM_INPUT("ADC2IN"),
+};
+
+static const struct snd_soc_dapm_route audio_paths[] = {
+       { "DAC", NULL, "PLL_PWR" },
+       { "ADC", NULL, "PLL_PWR" },
+       { "DAC", NULL, "ADC_PWR" },
+       { "ADC", NULL, "ADC_PWR" },
+       { "DAC1OUT", "DAC1 Switch", "DAC" },
+       { "DAC2OUT", "DAC2 Switch", "DAC" },
+       { "DAC3OUT", "DAC3 Switch", "DAC" },
+       { "DAC4OUT", "DAC4 Switch", "DAC" },
+       { "ADC", "ADC1 Switch", "ADC1IN" },
+       { "ADC", "ADC2 Switch", "ADC2IN" },
+};
+
+/*
+ * DAI ops entries
+ */
+
+static int ad193x_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       int reg;
+
+       reg = snd_soc_read(codec, AD193X_DAC_CTRL2);
+       reg = (mute > 0) ? reg | AD193X_DAC_MASTER_MUTE : reg &
+               (~AD193X_DAC_MASTER_MUTE);
+       snd_soc_write(codec, AD193X_DAC_CTRL2, reg);
+
+       return 0;
+}
+
+static int ad193x_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
+                              unsigned int rx_mask, int slots, int width)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       int dac_reg = snd_soc_read(codec, AD193X_DAC_CTRL1);
+       int adc_reg = snd_soc_read(codec, AD193X_ADC_CTRL2);
+
+       dac_reg &= ~AD193X_DAC_CHAN_MASK;
+       adc_reg &= ~AD193X_ADC_CHAN_MASK;
+
+       switch (slots) {
+       case 2:
+               dac_reg |= AD193X_DAC_2_CHANNELS << AD193X_DAC_CHAN_SHFT;
+               adc_reg |= AD193X_ADC_2_CHANNELS << AD193X_ADC_CHAN_SHFT;
+               break;
+       case 4:
+               dac_reg |= AD193X_DAC_4_CHANNELS << AD193X_DAC_CHAN_SHFT;
+               adc_reg |= AD193X_ADC_4_CHANNELS << AD193X_ADC_CHAN_SHFT;
+               break;
+       case 8:
+               dac_reg |= AD193X_DAC_8_CHANNELS << AD193X_DAC_CHAN_SHFT;
+               adc_reg |= AD193X_ADC_8_CHANNELS << AD193X_ADC_CHAN_SHFT;
+               break;
+       case 16:
+               dac_reg |= AD193X_DAC_16_CHANNELS << AD193X_DAC_CHAN_SHFT;
+               adc_reg |= AD193X_ADC_16_CHANNELS << AD193X_ADC_CHAN_SHFT;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_write(codec, AD193X_DAC_CTRL1, dac_reg);
+       snd_soc_write(codec, AD193X_ADC_CTRL2, adc_reg);
+
+       return 0;
+}
+
+static int ad193x_set_dai_fmt(struct snd_soc_dai *codec_dai,
+               unsigned int fmt)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       int adc_reg1, adc_reg2, dac_reg;
+
+       adc_reg1 = snd_soc_read(codec, AD193X_ADC_CTRL1);
+       adc_reg2 = snd_soc_read(codec, AD193X_ADC_CTRL2);
+       dac_reg = snd_soc_read(codec, AD193X_DAC_CTRL1);
+
+       /* At present, the driver only support AUX ADC mode(SND_SOC_DAIFMT_I2S
+        * with TDM) and ADC&DAC TDM mode(SND_SOC_DAIFMT_DSP_A)
+        */
+       switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_I2S:
+               adc_reg1 &= ~AD193X_ADC_SERFMT_MASK;
+               adc_reg1 |= AD193X_ADC_SERFMT_TDM;
+               break;
+       case SND_SOC_DAIFMT_DSP_A:
+               adc_reg1 &= ~AD193X_ADC_SERFMT_MASK;
+               adc_reg1 |= AD193X_ADC_SERFMT_AUX;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
+       case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + frame */
+               adc_reg2 &= ~AD193X_ADC_LEFT_HIGH;
+               adc_reg2 &= ~AD193X_ADC_BCLK_INV;
+               dac_reg &= ~AD193X_DAC_LEFT_HIGH;
+               dac_reg &= ~AD193X_DAC_BCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_NB_IF: /* normal bclk + invert frm */
+               adc_reg2 |= AD193X_ADC_LEFT_HIGH;
+               adc_reg2 &= ~AD193X_ADC_BCLK_INV;
+               dac_reg |= AD193X_DAC_LEFT_HIGH;
+               dac_reg &= ~AD193X_DAC_BCLK_INV;
+               break;
+       case SND_SOC_DAIFMT_IB_NF: /* invert bclk + normal frm */
+               adc_reg2 &= ~AD193X_ADC_LEFT_HIGH;
+               adc_reg2 |= AD193X_ADC_BCLK_INV;
+               dac_reg &= ~AD193X_DAC_LEFT_HIGH;
+               dac_reg |= AD193X_DAC_BCLK_INV;
+               break;
+
+       case SND_SOC_DAIFMT_IB_IF: /* invert bclk + frm */
+               adc_reg2 |= AD193X_ADC_LEFT_HIGH;
+               adc_reg2 |= AD193X_ADC_BCLK_INV;
+               dac_reg |= AD193X_DAC_LEFT_HIGH;
+               dac_reg |= AD193X_DAC_BCLK_INV;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master */
+               adc_reg2 |= AD193X_ADC_LCR_MASTER;
+               adc_reg2 |= AD193X_ADC_BCLK_MASTER;
+               dac_reg |= AD193X_DAC_LCR_MASTER;
+               dac_reg |= AD193X_DAC_BCLK_MASTER;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFM: /* codec clk slave & frm master */
+               adc_reg2 |= AD193X_ADC_LCR_MASTER;
+               adc_reg2 &= ~AD193X_ADC_BCLK_MASTER;
+               dac_reg |= AD193X_DAC_LCR_MASTER;
+               dac_reg &= ~AD193X_DAC_BCLK_MASTER;
+               break;
+       case SND_SOC_DAIFMT_CBM_CFS: /* codec clk master & frame slave */
+               adc_reg2 &= ~AD193X_ADC_LCR_MASTER;
+               adc_reg2 |= AD193X_ADC_BCLK_MASTER;
+               dac_reg &= ~AD193X_DAC_LCR_MASTER;
+               dac_reg |= AD193X_DAC_BCLK_MASTER;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave */
+               adc_reg2 &= ~AD193X_ADC_LCR_MASTER;
+               adc_reg2 &= ~AD193X_ADC_BCLK_MASTER;
+               dac_reg &= ~AD193X_DAC_LCR_MASTER;
+               dac_reg &= ~AD193X_DAC_BCLK_MASTER;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       snd_soc_write(codec, AD193X_ADC_CTRL1, adc_reg1);
+       snd_soc_write(codec, AD193X_ADC_CTRL2, adc_reg2);
+       snd_soc_write(codec, AD193X_DAC_CTRL1, dac_reg);
+
+       return 0;
+}
+
+static int ad193x_hw_params(struct snd_pcm_substream *substream,
+               struct snd_pcm_hw_params *params,
+               struct snd_soc_dai *dai)
+{
+       int word_len = 0, reg = 0;
+
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       /* bit size */
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               word_len = 3;
+               break;
+       case SNDRV_PCM_FORMAT_S20_3LE:
+               word_len = 1;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+       case SNDRV_PCM_FORMAT_S32_LE:
+               word_len = 0;
+               break;
+       }
+
+       reg = snd_soc_read(codec, AD193X_DAC_CTRL2);
+       reg = (reg & (~AD193X_DAC_WORD_LEN_MASK)) | word_len;
+       snd_soc_write(codec, AD193X_DAC_CTRL2, reg);
+
+       reg = snd_soc_read(codec, AD193X_ADC_CTRL1);
+       reg = (reg & (~AD193X_ADC_WORD_LEN_MASK)) | word_len;
+       snd_soc_write(codec, AD193X_ADC_CTRL1, reg);
+
+       return 0;
+}
+
+static int ad193x_bus_probe(struct device *dev, void *ctrl_data, int bus_type)
+{
+       struct snd_soc_codec *codec;
+       struct ad193x_priv *ad193x;
+       int ret;
+
+       if (ad193x_codec) {
+               dev_err(dev, "Another ad193x is registered\n");
+               return -EINVAL;
+       }
+
+       ad193x = kzalloc(sizeof(struct ad193x_priv), GFP_KERNEL);
+       if (ad193x == NULL)
+               return -ENOMEM;
+
+       dev_set_drvdata(dev, ad193x);
+
+       codec = &ad193x->codec;
+       mutex_init(&codec->mutex);
+       codec->control_data = ctrl_data;
+       codec->dev = dev;
+       snd_soc_codec_set_drvdata(codec, ad193x);
+       codec->reg_cache = ad193x->reg_cache;
+       codec->reg_cache_size = AD193X_NUM_REGS;
+       codec->name = "AD193X";
+       codec->owner = THIS_MODULE;
+       codec->dai = &ad193x_dai;
+       codec->num_dai = 1;
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
+       ad193x_dai.dev = codec->dev;
+       ad193x_codec = codec;
+
+       memcpy(codec->reg_cache, ad193x_reg, AD193X_NUM_REGS);
+
+       if (bus_type == SND_SOC_I2C)
+               ret = snd_soc_codec_set_cache_io(codec, 8, 8, bus_type);
+       else
+               ret = snd_soc_codec_set_cache_io(codec, 16, 8, bus_type);
+       if (ret < 0) {
+               dev_err(codec->dev, "failed to set cache I/O: %d\n",
+                               ret);
+               kfree(ad193x);
+               return ret;
+       }
+
+       /* default setting for ad193x */
+
+       /* unmute dac channels */
+       snd_soc_write(codec, AD193X_DAC_CHNL_MUTE, 0x0);
+       /* de-emphasis: 48kHz, powedown dac */
+       snd_soc_write(codec, AD193X_DAC_CTRL2, 0x1A);
+       /* powerdown dac, dac in tdm mode */
+       snd_soc_write(codec, AD193X_DAC_CTRL0, 0x41);
+       /* high-pass filter enable */
+       snd_soc_write(codec, AD193X_ADC_CTRL0, 0x3);
+       /* sata delay=1, adc aux mode */
+       snd_soc_write(codec, AD193X_ADC_CTRL1, 0x43);
+       /* pll input: mclki/xi */
+       snd_soc_write(codec, AD193X_PLL_CLK_CTRL0, 0x99); /* mclk=24.576Mhz: 0x9D; mclk=12.288Mhz: 0x99 */
+       snd_soc_write(codec, AD193X_PLL_CLK_CTRL1, 0x04);
+
+       ret = snd_soc_register_codec(codec);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
+               kfree(ad193x);
+               return ret;
+       }
+
+       ret = snd_soc_register_dai(&ad193x_dai);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
+               snd_soc_unregister_codec(codec);
+               kfree(ad193x);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int ad193x_bus_remove(struct device *dev)
+{
+       struct ad193x_priv *ad193x = dev_get_drvdata(dev);
+
+       snd_soc_unregister_dai(&ad193x_dai);
+       snd_soc_unregister_codec(&ad193x->codec);
+       kfree(ad193x);
+       ad193x_codec = NULL;
+
+       return 0;
+}
+
+static struct snd_soc_dai_ops ad193x_dai_ops = {
+       .hw_params = ad193x_hw_params,
+       .digital_mute = ad193x_mute,
+       .set_tdm_slot = ad193x_set_tdm_slot,
+       .set_fmt = ad193x_set_dai_fmt,
+};
+
+/* codec DAI instance */
+struct snd_soc_dai ad193x_dai = {
+       .name = "AD193X",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 2,
+               .channels_max = 8,
+               .rates = SNDRV_PCM_RATE_48000,
+               .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
+                       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
+       },
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 2,
+               .channels_max = 4,
+               .rates = SNDRV_PCM_RATE_48000,
+               .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE |
+                       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE,
+       },
+       .ops = &ad193x_dai_ops,
+};
+EXPORT_SYMBOL_GPL(ad193x_dai);
+
+static int ad193x_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       if (ad193x_codec == NULL) {
+               dev_err(&pdev->dev, "Codec device not registered\n");
+               return -ENODEV;
+       }
+
+       socdev->card->codec = ad193x_codec;
+       codec = ad193x_codec;
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               dev_err(codec->dev, "failed to create pcms: %d\n", ret);
+               goto pcm_err;
+       }
+
+       snd_soc_add_controls(codec, ad193x_snd_controls,
+                            ARRAY_SIZE(ad193x_snd_controls));
+       snd_soc_dapm_new_controls(codec, ad193x_dapm_widgets,
+                                 ARRAY_SIZE(ad193x_dapm_widgets));
+       snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
+
+pcm_err:
+       return ret;
+}
+
+/* power down chip */
+static int ad193x_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_ad193x = {
+       .probe =        ad193x_probe,
+       .remove =       ad193x_remove,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_ad193x);
+
+#if defined(CONFIG_SPI_MASTER)
+static int __devinit ad193x_spi_probe(struct spi_device *spi)
+{
+       return ad193x_bus_probe(&spi->dev, spi, SND_SOC_SPI);
+}
+
+static int __devexit ad193x_spi_remove(struct spi_device *spi)
+{
+       return ad193x_bus_remove(&spi->dev);
+}
+
+static struct spi_driver ad193x_spi_driver = {
+       .driver = {
+               .name   = "ad193x",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = ad193x_spi_probe,
+       .remove         = __devexit_p(ad193x_spi_remove),
+};
+#endif
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static const struct i2c_device_id ad193x_id[] = {
+       { "ad1936", 0 },
+       { "ad1937", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, ad193x_id);
+
+static int __devinit ad193x_i2c_probe(struct i2c_client *client,
+               const struct i2c_device_id *id)
+{
+       return ad193x_bus_probe(&client->dev, client, SND_SOC_I2C);
+}
+
+static int __devexit ad193x_i2c_remove(struct i2c_client *client)
+{
+       return ad193x_bus_remove(&client->dev);
+}
+
+static struct i2c_driver ad193x_i2c_driver = {
+       .driver = {
+               .name = "ad193x",
+       },
+       .probe    = ad193x_i2c_probe,
+       .remove   = __devexit_p(ad193x_i2c_remove),
+       .id_table = ad193x_id,
+};
+#endif
+
+static int __init ad193x_modinit(void)
+{
+       int ret;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       ret =  i2c_add_driver(&ad193x_i2c_driver);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register AD193X I2C driver: %d\n",
+                               ret);
+       }
+#endif
+
+#if defined(CONFIG_SPI_MASTER)
+       ret = spi_register_driver(&ad193x_spi_driver);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register AD193X SPI driver: %d\n",
+                               ret);
+       }
+#endif
+       return ret;
+}
+module_init(ad193x_modinit);
+
+static void __exit ad193x_modexit(void)
+{
+#if defined(CONFIG_SPI_MASTER)
+       spi_unregister_driver(&ad193x_spi_driver);
+#endif
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&ad193x_i2c_driver);
+#endif
+}
+module_exit(ad193x_modexit);
+
+MODULE_DESCRIPTION("ASoC ad193x driver");
+MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ad193x.h b/sound/soc/codecs/ad193x.h
new file mode 100644 (file)
index 0000000..a03c880
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * AD193X Audio Codec driver
+ *
+ * Copyright 2010 Analog Devices Inc.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#ifndef __AD193X_H__
+#define __AD193X_H__
+
+#define AD193X_PLL_CLK_CTRL0    0x800
+#define AD193X_PLL_POWERDOWN           0x01
+#define AD193X_PLL_CLK_CTRL1    0x801
+#define AD193X_DAC_CTRL0        0x802
+#define AD193X_DAC_POWERDOWN           0x01
+#define AD193X_DAC_SERFMT_MASK         0xC0
+#define AD193X_DAC_SERFMT_STEREO       (0 << 6)
+#define AD193X_DAC_SERFMT_TDM          (1 << 6)
+#define AD193X_DAC_CTRL1        0x803
+#define AD193X_DAC_2_CHANNELS   0
+#define AD193X_DAC_4_CHANNELS   1
+#define AD193X_DAC_8_CHANNELS   2
+#define AD193X_DAC_16_CHANNELS  3
+#define AD193X_DAC_CHAN_SHFT    1
+#define AD193X_DAC_CHAN_MASK    (3 << AD193X_DAC_CHAN_SHFT)
+#define AD193X_DAC_LCR_MASTER   (1 << 4)
+#define AD193X_DAC_BCLK_MASTER  (1 << 5)
+#define AD193X_DAC_LEFT_HIGH    (1 << 3)
+#define AD193X_DAC_BCLK_INV     (1 << 7)
+#define AD193X_DAC_CTRL2        0x804
+#define AD193X_DAC_WORD_LEN_MASK       0xC
+#define AD193X_DAC_MASTER_MUTE  1
+#define AD193X_DAC_CHNL_MUTE    0x805
+#define AD193X_DACL1_MUTE       0
+#define AD193X_DACR1_MUTE       1
+#define AD193X_DACL2_MUTE       2
+#define AD193X_DACR2_MUTE       3
+#define AD193X_DACL3_MUTE       4
+#define AD193X_DACR3_MUTE       5
+#define AD193X_DACL4_MUTE       6
+#define AD193X_DACR4_MUTE       7
+#define AD193X_DAC_L1_VOL       0x806
+#define AD193X_DAC_R1_VOL       0x807
+#define AD193X_DAC_L2_VOL       0x808
+#define AD193X_DAC_R2_VOL       0x809
+#define AD193X_DAC_L3_VOL       0x80a
+#define AD193X_DAC_R3_VOL       0x80b
+#define AD193X_DAC_L4_VOL       0x80c
+#define AD193X_DAC_R4_VOL       0x80d
+#define AD193X_ADC_CTRL0        0x80e
+#define AD193X_ADC_POWERDOWN           0x01
+#define AD193X_ADC_HIGHPASS_FILTER     1
+#define AD193X_ADCL1_MUTE              2
+#define AD193X_ADCR1_MUTE              3
+#define AD193X_ADCL2_MUTE              4
+#define AD193X_ADCR2_MUTE              5
+#define AD193X_ADC_CTRL1        0x80f
+#define AD193X_ADC_SERFMT_MASK         0x60
+#define AD193X_ADC_SERFMT_STEREO       (0 << 5)
+#define AD193X_ADC_SERFMT_TDM          (1 << 2)
+#define AD193X_ADC_SERFMT_AUX          (2 << 5)
+#define AD193X_ADC_WORD_LEN_MASK       0x3
+#define AD193X_ADC_CTRL2        0x810
+#define AD193X_ADC_2_CHANNELS   0
+#define AD193X_ADC_4_CHANNELS   1
+#define AD193X_ADC_8_CHANNELS   2
+#define AD193X_ADC_16_CHANNELS  3
+#define AD193X_ADC_CHAN_SHFT    4
+#define AD193X_ADC_CHAN_MASK    (3 << AD193X_ADC_CHAN_SHFT)
+#define AD193X_ADC_LCR_MASTER   (1 << 3)
+#define AD193X_ADC_BCLK_MASTER  (1 << 6)
+#define AD193X_ADC_LEFT_HIGH    (1 << 2)
+#define AD193X_ADC_BCLK_INV     (1 << 1)
+
+#define AD193X_NUM_REGS          17
+
+extern struct snd_soc_dai ad193x_dai;
+extern struct snd_soc_codec_device soc_codec_dev_ad193x;
+
+#endif
index bdeb10d..192aebd 100644 (file)
@@ -222,7 +222,7 @@ static int ak4104_spi_probe(struct spi_device *spi)
        codec->owner = THIS_MODULE;
        codec->dai = &ak4104_dai;
        codec->num_dai = 1;
-       codec->private_data = ak4104;
+       snd_soc_codec_set_drvdata(codec, ak4104);
        codec->control_data = spi;
        codec->reg_cache = ak4104->reg_cache;
        codec->reg_cache_size = AK4104_NUM_REGS;
index 352d1d0..d425367 100644 (file)
@@ -302,7 +302,7 @@ static int ak4535_set_dai_sysclk(struct snd_soc_dai *codec_dai,
        int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct ak4535_priv *ak4535 = codec->private_data;
+       struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
 
        ak4535->sysclk = freq;
        return 0;
@@ -315,7 +315,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct ak4535_priv *ak4535 = codec->private_data;
+       struct ak4535_priv *ak4535 = snd_soc_codec_get_drvdata(codec);
        u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
        int rate = params_rate(params), fs = 256;
 
@@ -446,7 +446,6 @@ static int ak4535_resume(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->card->codec;
        ak4535_sync(codec);
        ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       ak4535_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
@@ -600,7 +599,7 @@ static int ak4535_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
-       codec->private_data = ak4535;
+       snd_soc_codec_set_drvdata(codec, ak4535);
        socdev->card->codec = codec;
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -617,7 +616,7 @@ static int ak4535_probe(struct platform_device *pdev)
 #endif
 
        if (ret != 0) {
-               kfree(codec->private_data);
+               kfree(snd_soc_codec_get_drvdata(codec));
                kfree(codec);
        }
        return ret;
@@ -639,7 +638,7 @@ static int ak4535_remove(struct platform_device *pdev)
                i2c_unregister_device(codec->control_data);
        i2c_del_driver(&ak4535_i2c_driver);
 #endif
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec);
 
        return 0;
index 729859c..7528a54 100644 (file)
 
 #define AK4642_CACHEREGNUM     0x25
 
+/* PW_MGMT2 */
+#define HPMTN          (1 << 6)
+#define PMHPL          (1 << 5)
+#define PMHPR          (1 << 4)
+#define MS             (1 << 3) /* master/slave select */
+#define MCKO           (1 << 1)
+#define PMPLL          (1 << 0)
+
+#define PMHP_MASK      (PMHPL | PMHPR)
+#define PMHP           PMHP_MASK
+
+/* MD_CTL1 */
+#define PLL3           (1 << 7)
+#define PLL2           (1 << 6)
+#define PLL1           (1 << 5)
+#define PLL0           (1 << 4)
+#define PLL_MASK       (PLL3 | PLL2 | PLL1 | PLL0)
+
+#define BCKO_MASK      (1 << 3)
+#define BCKO_64                BCKO_MASK
+
+/* MD_CTL2 */
+#define FS0            (1 << 0)
+#define FS1            (1 << 1)
+#define FS2            (1 << 2)
+#define FS3            (1 << 5)
+#define FS_MASK                (FS0 | FS1 | FS2 | FS3)
+
 struct snd_soc_codec_device soc_codec_dev_ak4642;
 
 /* codec private data */
 struct ak4642_priv {
        struct snd_soc_codec codec;
-       unsigned int sysclk;
 };
 
 static struct snd_soc_codec *ak4642_codec;
@@ -177,17 +204,12 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
                 *
                 * PLL, Master Mode
                 * Audio I/F Format :MSB justified (ADC & DAC)
-                * Sampling Frequency: 44.1kHz
-                * Digital Volume: âˆ’8dB
+                * Digital Volume: -8dB
                 * Bass Boost Level : Middle
                 *
                 * This operation came from example code of
                 * "ASAHI KASEI AK4642" (japanese) manual p97.
-                *
-                * Example code use 0x39, 0x79 value for 0x01 address,
-                * But we need MCKO (0x02) bit now
                 */
-               ak4642_write(codec, 0x05, 0x27);
                ak4642_write(codec, 0x0f, 0x09);
                ak4642_write(codec, 0x0e, 0x19);
                ak4642_write(codec, 0x09, 0x91);
@@ -195,15 +217,14 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
                ak4642_write(codec, 0x0a, 0x28);
                ak4642_write(codec, 0x0d, 0x28);
                ak4642_write(codec, 0x00, 0x64);
-               ak4642_write(codec, 0x01, 0x3b); /* + MCKO bit */
-               ak4642_write(codec, 0x01, 0x7b); /* + MCKO bit */
+               snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK, PMHP);
+               snd_soc_update_bits(codec, PW_MGMT2, HPMTN,     HPMTN);
        } else {
                /*
                 * start stereo input
                 *
                 * PLL Master Mode
                 * Audio I/F Format:MSB justified (ADC & DAC)
-                * Sampling Frequency:44.1kHz
                 * Pre MIC AMP:+20dB
                 * MIC Power On
                 * ALC setting:Refer to Table 35
@@ -212,7 +233,6 @@ static int ak4642_dai_startup(struct snd_pcm_substream *substream,
                 * This operation came from example code of
                 * "ASAHI KASEI AK4642" (japanese) manual p94.
                 */
-               ak4642_write(codec, 0x05, 0x27);
                ak4642_write(codec, 0x02, 0x05);
                ak4642_write(codec, 0x06, 0x3c);
                ak4642_write(codec, 0x08, 0xe1);
@@ -233,8 +253,8 @@ static void ak4642_dai_shutdown(struct snd_pcm_substream *substream,
 
        if (is_play) {
                /* stop headphone output */
-               ak4642_write(codec, 0x01, 0x3b);
-               ak4642_write(codec, 0x01, 0x0b);
+               snd_soc_update_bits(codec, PW_MGMT2, HPMTN,     0);
+               snd_soc_update_bits(codec, PW_MGMT2, PMHP_MASK, 0);
                ak4642_write(codec, 0x00, 0x40);
                ak4642_write(codec, 0x0e, 0x11);
                ak4642_write(codec, 0x0f, 0x08);
@@ -250,9 +270,111 @@ static int ak4642_dai_set_sysclk(struct snd_soc_dai *codec_dai,
        int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct ak4642_priv *ak4642 = codec->private_data;
+       u8 pll;
+
+       switch (freq) {
+       case 11289600:
+               pll = PLL2;
+               break;
+       case 12288000:
+               pll = PLL2 | PLL0;
+               break;
+       case 12000000:
+               pll = PLL2 | PLL1;
+               break;
+       case 24000000:
+               pll = PLL2 | PLL1 | PLL0;
+               break;
+       case 13500000:
+               pll = PLL3 | PLL2;
+               break;
+       case 27000000:
+               pll = PLL3 | PLL2 | PLL0;
+               break;
+       default:
+               return -EINVAL;
+       }
+       snd_soc_update_bits(codec, MD_CTL1, PLL_MASK, pll);
+
+       return 0;
+}
+
+static int ak4642_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u8 data;
+       u8 bcko;
+
+       data = MCKO | PMPLL; /* use MCKO */
+       bcko = 0;
+
+       /* set master/slave audio interface */
+       switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:
+               data |= MS;
+               bcko = BCKO_64;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               break;
+       default:
+               return -EINVAL;
+       }
+       snd_soc_update_bits(codec, PW_MGMT2, MS, data);
+       snd_soc_update_bits(codec, MD_CTL1, BCKO_MASK, bcko);
+
+       return 0;
+}
+
+static int ak4642_dai_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params,
+                               struct snd_soc_dai *dai)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u8 rate;
+
+       switch (params_rate(params)) {
+       case 7350:
+               rate = FS2;
+               break;
+       case 8000:
+               rate = 0;
+               break;
+       case 11025:
+               rate = FS2 | FS0;
+               break;
+       case 12000:
+               rate = FS0;
+               break;
+       case 14700:
+               rate = FS2 | FS1;
+               break;
+       case 16000:
+               rate = FS1;
+               break;
+       case 22050:
+               rate = FS2 | FS1 | FS0;
+               break;
+       case 24000:
+               rate = FS1 | FS0;
+               break;
+       case 29400:
+               rate = FS3 | FS2 | FS1;
+               break;
+       case 32000:
+               rate = FS3 | FS1;
+               break;
+       case 44100:
+               rate = FS3 | FS2 | FS1 | FS0;
+               break;
+       case 48000:
+               rate = FS3 | FS1 | FS0;
+               break;
+       default:
+               return -EINVAL;
+               break;
+       }
+       snd_soc_update_bits(codec, MD_CTL2, FS_MASK, rate);
 
-       ak4642->sysclk = freq;
        return 0;
 }
 
@@ -260,6 +382,8 @@ static struct snd_soc_dai_ops ak4642_dai_ops = {
        .startup        = ak4642_dai_startup,
        .shutdown       = ak4642_dai_shutdown,
        .set_sysclk     = ak4642_dai_set_sysclk,
+       .set_fmt        = ak4642_dai_set_fmt,
+       .hw_params      = ak4642_dai_hw_params,
 };
 
 struct snd_soc_dai ak4642_dai = {
@@ -277,6 +401,7 @@ struct snd_soc_dai ak4642_dai = {
                .rates = SNDRV_PCM_RATE_8000_48000,
                .formats = SNDRV_PCM_FMTBIT_S16_LE },
        .ops = &ak4642_dai_ops,
+       .symmetric_rates = 1,
 };
 EXPORT_SYMBOL_GPL(ak4642_dai);
 
@@ -307,7 +432,7 @@ static int ak4642_init(struct ak4642_priv *ak4642)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data     = ak4642;
+       snd_soc_codec_set_drvdata(codec, ak4642);
        codec->name             = "AK4642";
        codec->owner            = THIS_MODULE;
        codec->read             = ak4642_read_reg_cache;
@@ -338,26 +463,6 @@ static int ak4642_init(struct ak4642_priv *ak4642)
                goto reg_cache_err;
        }
 
-       /*
-        * clock setting
-        *
-        * Audio I/F Format: MSB justified (ADC & DAC)
-        * BICK frequency at Master Mode: 64fs
-        * Input Master Clock Select at PLL Mode: 11.2896MHz
-        * MCKO: Enable
-        * Sampling Frequency: 44.1kHz
-        *
-        * This operation came from example code of
-        * "ASAHI KASEI AK4642" (japanese) manual p89.
-        *
-        * please fix-me
-        */
-       ak4642_write(codec, 0x01, 0x08);
-       ak4642_write(codec, 0x04, 0x4a);
-       ak4642_write(codec, 0x05, 0x27);
-       ak4642_write(codec, 0x00, 0x40);
-       ak4642_write(codec, 0x01, 0x0b);
-
        return ret;
 
 reg_cache_err:
index 926797a..8756693 100644 (file)
@@ -702,7 +702,7 @@ static int ak4671_register(struct ak4671_priv *ak4671,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = ak4671;
+       snd_soc_codec_set_drvdata(codec,  ak4671);
        codec->name = "AK4671";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
diff --git a/sound/soc/codecs/cq93vc.c b/sound/soc/codecs/cq93vc.c
new file mode 100644 (file)
index 0000000..a320fb5
--- /dev/null
@@ -0,0 +1,299 @@
+/*
+ * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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 <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/platform_device.h>
+#include <linux/device.h>
+#include <linux/slab.h>
+#include <linux/clk.h>
+#include <linux/mfd/davinci_voicecodec.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dai.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+
+#include <mach/dm365.h>
+
+#include "cq93vc.h"
+
+static inline unsigned int cq93vc_read(struct snd_soc_codec *codec,
+                                               unsigned int reg)
+{
+       struct davinci_vc *davinci_vc = codec->control_data;
+
+       return readl(davinci_vc->base + reg);
+}
+
+static inline int cq93vc_write(struct snd_soc_codec *codec, unsigned int reg,
+                      unsigned int value)
+{
+       struct davinci_vc *davinci_vc = codec->control_data;
+
+       writel(value, davinci_vc->base + reg);
+
+       return 0;
+}
+
+static const struct snd_kcontrol_new cq93vc_snd_controls[] = {
+       SOC_SINGLE("PGA Capture Volume", DAVINCI_VC_REG05, 0, 0x03, 0),
+       SOC_SINGLE("Mono DAC Playback Volume", DAVINCI_VC_REG09, 0, 0x3f, 0),
+};
+
+static int cq93vc_mute(struct snd_soc_dai *dai, int mute)
+{
+       struct snd_soc_codec *codec = dai->codec;
+       u8 reg = cq93vc_read(codec, DAVINCI_VC_REG09) & ~DAVINCI_VC_REG09_MUTE;
+
+       if (mute)
+               cq93vc_write(codec, DAVINCI_VC_REG09,
+                            reg | DAVINCI_VC_REG09_MUTE);
+       else
+               cq93vc_write(codec, DAVINCI_VC_REG09, reg);
+
+       return 0;
+}
+
+static int cq93vc_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+                                int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct davinci_vc *davinci_vc = codec->control_data;
+
+       switch (freq) {
+       case 22579200:
+       case 27000000:
+       case 33868800:
+               davinci_vc->cq93vc.sysclk = freq;
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+static int cq93vc_set_bias_level(struct snd_soc_codec *codec,
+                               enum snd_soc_bias_level level)
+{
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               cq93vc_write(codec, DAVINCI_VC_REG12,
+                            DAVINCI_VC_REG12_POWER_ALL_ON);
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               cq93vc_write(codec, DAVINCI_VC_REG12,
+                            DAVINCI_VC_REG12_POWER_ALL_OFF);
+               break;
+       case SND_SOC_BIAS_OFF:
+               /* force all power off */
+               cq93vc_write(codec, DAVINCI_VC_REG12,
+                            DAVINCI_VC_REG12_POWER_ALL_OFF);
+               break;
+       }
+       codec->bias_level = level;
+
+       return 0;
+}
+
+#define CQ93VC_RATES   (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000)
+#define CQ93VC_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE)
+
+static struct snd_soc_dai_ops cq93vc_dai_ops = {
+       .digital_mute   = cq93vc_mute,
+       .set_sysclk     = cq93vc_set_dai_sysclk,
+};
+
+struct snd_soc_dai cq93vc_dai = {
+       .name = "CQ93VC",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = CQ93VC_RATES,
+               .formats = CQ93VC_FORMATS,},
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = CQ93VC_RATES,
+               .formats = CQ93VC_FORMATS,},
+       .ops = &cq93vc_dai_ops,
+};
+EXPORT_SYMBOL_GPL(cq93vc_dai);
+
+static int cq93vc_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       return 0;
+}
+
+static struct snd_soc_codec *cq93vc_codec;
+
+static int cq93vc_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct device *dev = &pdev->dev;
+       struct snd_soc_codec *codec;
+       int ret;
+
+       socdev->card->codec = cq93vc_codec;
+       codec = socdev->card->codec;
+
+       /* Register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               dev_err(dev, "%s: failed to create pcms\n", pdev->name);
+               return ret;
+       }
+
+       /* Set controls */
+       snd_soc_add_controls(codec, cq93vc_snd_controls,
+                            ARRAY_SIZE(cq93vc_snd_controls));
+
+       /* Off, with power on */
+       cq93vc_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       return 0;
+}
+
+static int cq93vc_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_cq93vc = {
+       .probe = cq93vc_probe,
+       .remove = cq93vc_remove,
+       .resume = cq93vc_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_cq93vc);
+
+static __init int cq93vc_codec_probe(struct platform_device *pdev)
+{
+       struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret;
+
+       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
+       if (codec == NULL) {
+               dev_dbg(davinci_vc->dev,
+                       "could not allocate memory for codec data\n");
+               return -ENOMEM;
+       }
+
+       davinci_vc->cq93vc.codec = codec;
+
+       cq93vc_dai.dev = &pdev->dev;
+
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+       codec->dev = &pdev->dev;
+       codec->name = "CQ93VC";
+       codec->owner = THIS_MODULE;
+       codec->read = cq93vc_read;
+       codec->write = cq93vc_write;
+       codec->set_bias_level = cq93vc_set_bias_level;
+       codec->dai = &cq93vc_dai;
+       codec->num_dai = 1;
+       codec->control_data = davinci_vc;
+
+       cq93vc_codec = codec;
+
+       ret = snd_soc_register_codec(codec);
+       if (ret) {
+               dev_err(davinci_vc->dev, "failed to register codec\n");
+               goto fail1;
+       }
+
+       ret = snd_soc_register_dai(&cq93vc_dai);
+       if (ret) {
+               dev_err(davinci_vc->dev, "could register dai\n");
+               goto fail2;
+       }
+       return 0;
+
+fail2:
+       snd_soc_unregister_codec(codec);
+
+fail1:
+       kfree(codec);
+       cq93vc_codec = NULL;
+
+       return ret;
+}
+
+static int __devexit cq93vc_codec_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       snd_soc_unregister_dai(&cq93vc_dai);
+       snd_soc_unregister_codec(&codec);
+
+       kfree(codec);
+       cq93vc_codec = NULL;
+
+       return 0;
+}
+
+static struct platform_driver cq93vc_codec_driver = {
+       .driver = {
+                  .name = "cq93vc",
+                  .owner = THIS_MODULE,
+                  },
+       .probe = cq93vc_codec_probe,
+       .remove = __devexit_p(cq93vc_codec_remove),
+};
+
+static __init int cq93vc_init(void)
+{
+       return platform_driver_probe(&cq93vc_codec_driver, cq93vc_codec_probe);
+}
+module_init(cq93vc_init);
+
+static __exit void cq93vc_exit(void)
+{
+       platform_driver_unregister(&cq93vc_codec_driver);
+}
+module_exit(cq93vc_exit);
+
+MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC CQ0093 Voice Codec Driver");
+MODULE_AUTHOR("Miguel Aguilar");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cq93vc.h b/sound/soc/codecs/cq93vc.h
new file mode 100644 (file)
index 0000000..845b196
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * ALSA SoC CQ0093 Voice Codec Driver for DaVinci platforms
+ *
+ * Copyright (C) 2010 Texas Instruments, Inc
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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
+ */
+
+#ifndef _CQ93VC_H
+#define _CQ93VC_H
+
+extern struct snd_soc_dai cq93vc_dai;
+extern struct snd_soc_codec_device soc_codec_dev_cq93vc;
+
+#endif
index 81a62d1..30d9492 100644 (file)
@@ -211,7 +211,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                 int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        unsigned int rates = 0;
        unsigned int rate_min = -1;
        unsigned int rate_max = 0;
@@ -270,7 +270,7 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
                              unsigned int format)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        /* set DAI format */
@@ -412,7 +412,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int ret;
        unsigned int i;
        unsigned int rate;
@@ -491,7 +491,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
 static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int reg6;
 
        reg6 = snd_soc_read(codec, CS4270_MUTE);
@@ -524,7 +524,7 @@ static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol,
                                struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int left = !ucontrol->value.integer.value[0];
        int right = !ucontrol->value.integer.value[1];
 
@@ -600,7 +600,7 @@ static int cs4270_probe(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = cs4270_codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int i, ret;
 
        /* Connect the codec to the socdev.  snd_soc_new_pcms() needs this. */
@@ -657,7 +657,7 @@ static int cs4270_remove(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = cs4270_codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
 
        snd_soc_free_pcms(socdev);
        regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies);
@@ -730,7 +730,7 @@ static int cs4270_i2c_probe(struct i2c_client *i2c_client,
        codec->owner = THIS_MODULE;
        codec->dai = &cs4270_dai;
        codec->num_dai = 1;
-       codec->private_data = cs4270;
+       snd_soc_codec_set_drvdata(codec, cs4270);
        codec->control_data = i2c_client;
        codec->read = cs4270_read_reg_cache;
        codec->write = cs4270_i2c_write;
@@ -843,7 +843,7 @@ MODULE_DEVICE_TABLE(i2c, cs4270_id);
 static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg)
 {
        struct snd_soc_codec *codec = cs4270_codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        int reg, ret;
 
        reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL;
@@ -863,7 +863,7 @@ static int cs4270_soc_suspend(struct platform_device *pdev, pm_message_t mesg)
 static int cs4270_soc_resume(struct platform_device *pdev)
 {
        struct snd_soc_codec *codec = cs4270_codec;
-       struct cs4270_private *cs4270 = codec->private_data;
+       struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c_client = codec->control_data;
        int reg;
 
index 9f169c4..f07a415 100644 (file)
@@ -387,7 +387,7 @@ static int cx20442_register(struct cx20442_priv *cx20442)
 
        codec->name = "CX20442";
        codec->owner = THIS_MODULE;
-       codec->private_data = cx20442;
+       snd_soc_codec_set_drvdata(codec, cx20442);
 
        codec->dai = &cx20442_dai;
        codec->num_dai = 1;
index 366daf1..75af2d6 100644 (file)
 #define DA7210_DAI_SRC_SEL             0x25
 #define DA7210_DAI_CFG1                        0x26
 #define DA7210_DAI_CFG3                        0x28
+#define DA7210_PLL_DIV1                        0x29
+#define DA7210_PLL_DIV2                        0x2A
 #define DA7210_PLL_DIV3                        0x2B
 #define DA7210_PLL                     0x2C
+#define DA7210_A_HID_UNLOCK            0x8A
+#define DA7210_A_TEST_UNLOCK           0x8B
+#define DA7210_A_PLL1                  0x90
+#define DA7210_A_CP_MODE               0xA7
 
 /* STARTUP1 bit fields */
 #define DA7210_SC_MST_EN               (1 << 0)
 /* INMIX_R bit fields */
 #define DA7210_IN_R_EN                 (1 << 7)
 
-/* ADC_HPF bit fields */
-#define DA7210_ADC_VOICE_EN            (1 << 7)
-
 /* ADC bit fields */
 #define DA7210_ADC_L_EN                        (1 << 3)
 #define DA7210_ADC_R_EN                        (1 << 7)
 
-/* DAC_HPF fields */
-#define DA7210_DAC_VOICE_EN            (1 << 7)
+/* DAC/ADC HPF fields */
+#define DA7210_VOICE_F0_MASK           (0x7 << 4)
+#define DA7210_VOICE_F0_25             (1 << 4)
+#define DA7210_VOICE_EN                        (1 << 7)
 
 /* DAC_SEL bit fields */
 #define DA7210_DAC_L_SRC_DAI_L         (4 << 0)
 #define DA7210_PLL_BYP                 (1 << 6)
 
 /* PLL bit fields */
-#define DA7210_PLL_FS_48000            (11 << 0)
+#define DA7210_PLL_FS_MASK             (0xF << 0)
+#define DA7210_PLL_FS_8000             (0x1 << 0)
+#define DA7210_PLL_FS_11025            (0x2 << 0)
+#define DA7210_PLL_FS_12000            (0x3 << 0)
+#define DA7210_PLL_FS_16000            (0x5 << 0)
+#define DA7210_PLL_FS_22050            (0x6 << 0)
+#define DA7210_PLL_FS_24000            (0x7 << 0)
+#define DA7210_PLL_FS_32000            (0x9 << 0)
+#define DA7210_PLL_FS_44100            (0xA << 0)
+#define DA7210_PLL_FS_48000            (0xB << 0)
+#define DA7210_PLL_FS_88200            (0xE << 0)
+#define DA7210_PLL_FS_96000            (0xF << 0)
+#define DA7210_PLL_EN                  (0x1 << 7)
 
 #define DA7210_VERSION "0.0.1"
 
@@ -165,7 +182,7 @@ static const u8 da7210_reg[] = {
 static inline u32 da7210_read_reg_cache(struct snd_soc_codec *codec, u32 reg)
 {
        u8 *cache = codec->reg_cache;
-       BUG_ON(reg > ARRAY_SIZE(da7210_reg));
+       BUG_ON(reg >= ARRAY_SIZE(da7210_reg));
        return cache[reg];
 }
 
@@ -242,7 +259,8 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
        u32 dai_cfg1;
-       u32 reg, mask;
+       u32 hpf_reg, hpf_mask, hpf_value;
+       u32 fs, bypass;
 
        /* set DAI source to Left and Right ADC */
        da7210_write(codec, DA7210_DAI_SRC_SEL,
@@ -266,25 +284,84 @@ static int da7210_hw_params(struct snd_pcm_substream *substream,
 
        da7210_write(codec, DA7210_DAI_CFG1, dai_cfg1);
 
-       /* FIXME
-        *
-        * It support 48K only now
-        */
+       hpf_reg = (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) ?
+               DA7210_DAC_HPF : DA7210_ADC_HPF;
+
        switch (params_rate(params)) {
+       case 8000:
+               fs              = DA7210_PLL_FS_8000;
+               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
+               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
+               bypass          = DA7210_PLL_BYP;
+               break;
+       case 11025:
+               fs              = DA7210_PLL_FS_11025;
+               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
+               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
+               bypass          = 0;
+               break;
+       case 12000:
+               fs              = DA7210_PLL_FS_12000;
+               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
+               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
+               bypass          = DA7210_PLL_BYP;
+               break;
+       case 16000:
+               fs              = DA7210_PLL_FS_16000;
+               hpf_mask        = DA7210_VOICE_F0_MASK  | DA7210_VOICE_EN;
+               hpf_value       = DA7210_VOICE_F0_25    | DA7210_VOICE_EN;
+               bypass          = DA7210_PLL_BYP;
+               break;
+       case 22050:
+               fs              = DA7210_PLL_FS_22050;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = 0;
+               break;
+       case 32000:
+               fs              = DA7210_PLL_FS_32000;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = DA7210_PLL_BYP;
+               break;
+       case 44100:
+               fs              = DA7210_PLL_FS_44100;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = 0;
+               break;
        case 48000:
-               if (SNDRV_PCM_STREAM_PLAYBACK == substream->stream) {
-                       reg  = DA7210_DAC_HPF;
-                       mask = DA7210_DAC_VOICE_EN;
-               } else {
-                       reg  = DA7210_ADC_HPF;
-                       mask = DA7210_ADC_VOICE_EN;
-               }
+               fs              = DA7210_PLL_FS_48000;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = DA7210_PLL_BYP;
+               break;
+       case 88200:
+               fs              = DA7210_PLL_FS_88200;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = 0;
+               break;
+       case 96000:
+               fs              = DA7210_PLL_FS_96000;
+               hpf_mask        = DA7210_VOICE_EN;
+               hpf_value       = 0;
+               bypass          = DA7210_PLL_BYP;
                break;
        default:
                return -EINVAL;
        }
 
-       snd_soc_update_bits(codec, reg, mask, 0);
+       /* Disable active mode */
+       snd_soc_update_bits(codec, DA7210_STARTUP1, DA7210_SC_MST_EN, 0);
+
+       snd_soc_update_bits(codec, hpf_reg, hpf_mask, hpf_value);
+       snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_FS_MASK, fs);
+       snd_soc_update_bits(codec, DA7210_PLL_DIV3, DA7210_PLL_BYP, bypass);
+
+       /* Enable active mode */
+       snd_soc_update_bits(codec, DA7210_STARTUP1,
+                           DA7210_SC_MST_EN, DA7210_SC_MST_EN);
 
        return 0;
 }
@@ -362,6 +439,7 @@ struct snd_soc_dai da7210_dai = {
                .formats = DA7210_FORMATS,
        },
        .ops = &da7210_dai_ops,
+       .symmetric_rates = 1,
 };
 EXPORT_SYMBOL_GPL(da7210_dai);
 
@@ -383,7 +461,7 @@ static int da7210_init(struct da7210_priv *da7210)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data     = da7210;
+       snd_soc_codec_set_drvdata(codec, da7210);
        codec->name             = "DA7210";
        codec->owner            = THIS_MODULE;
        codec->read             = da7210_read;
@@ -416,8 +494,22 @@ static int da7210_init(struct da7210_priv *da7210)
        /* FIXME
         *
         * This driver use fixed value here
+        * And below settings expects MCLK = 12.288MHz
+        *
+        * When you select different MCLK, please check...
+        *      DA7210_PLL_DIV1 val
+        *      DA7210_PLL_DIV2 val
+        *      DA7210_PLL_DIV3 val
+        *      DA7210_PLL_DIV3 :: DA7210_MCLK_RANGExxx
         */
 
+       /*
+        * make sure that DA7210 use bypass mode before start up
+        */
+       da7210_write(codec, DA7210_STARTUP1, 0);
+       da7210_write(codec, DA7210_PLL_DIV3,
+                    DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
+
        /*
         * ADC settings
         */
@@ -454,9 +546,28 @@ static int da7210_init(struct da7210_priv *da7210)
        /* Diable PLL and bypass it */
        da7210_write(codec, DA7210_PLL, DA7210_PLL_FS_48000);
 
-       /* Bypass PLL and set MCLK freq rang to 10-20MHz */
-       da7210_write(codec, DA7210_PLL_DIV3,
+       /*
+        * If 48kHz sound came, it use bypass mode,
+        * and when it is 44.1kHz, it use PLL.
+        *
+        * This time, this driver sets PLL always ON
+        * and controls bypass/PLL mode by switching
+        * DA7210_PLL_DIV3 :: DA7210_PLL_BYP bit.
+        *   see da7210_hw_params
+        */
+       da7210_write(codec, DA7210_PLL_DIV1, 0xE5); /* MCLK = 12.288MHz */
+       da7210_write(codec, DA7210_PLL_DIV2, 0x99);
+       da7210_write(codec, DA7210_PLL_DIV3, 0x0A |
                     DA7210_MCLK_RANGE_10_20_MHZ | DA7210_PLL_BYP);
+       snd_soc_update_bits(codec, DA7210_PLL, DA7210_PLL_EN, DA7210_PLL_EN);
+
+       /* As suggested by Dialog */
+       da7210_write(codec, DA7210_A_HID_UNLOCK,        0x8B); /* unlock */
+       da7210_write(codec, DA7210_A_TEST_UNLOCK,       0xB4);
+       da7210_write(codec, DA7210_A_PLL1,              0x01);
+       da7210_write(codec, DA7210_A_CP_MODE,           0x7C);
+       da7210_write(codec, DA7210_A_HID_UNLOCK,        0x00); /* re-lock */
+       da7210_write(codec, DA7210_A_TEST_UNLOCK,       0x00);
 
        /* Activate all enabled subsystem */
        da7210_write(codec, DA7210_STARTUP1, DA7210_SC_MST_EN);
index 29d0906..b47ed4f 100644 (file)
@@ -140,6 +140,7 @@ SOC_DOUBLE_R("Capture Volume", SSM2602_LINVOL, SSM2602_RINVOL, 0, 31, 0),
 SOC_DOUBLE_R("Capture Switch", SSM2602_LINVOL, SSM2602_RINVOL, 7, 1, 1),
 
 SOC_SINGLE("Mic Boost (+20dB)", SSM2602_APANA, 0, 1, 0),
+SOC_SINGLE("Mic Boost2 (+20dB)", SSM2602_APANA, 7, 1, 0),
 SOC_SINGLE("Mic Switch", SSM2602_APANA, 1, 1, 1),
 
 SOC_SINGLE("Sidetone Playback Volume", SSM2602_APANA, 6, 3, 1),
@@ -277,7 +278,7 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct ssm2602_priv *ssm2602 = codec->private_data;
+       struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c = codec->control_data;
        u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3;
        int i = get_coeff(ssm2602->sysclk, params_rate(params));
@@ -322,7 +323,7 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct ssm2602_priv *ssm2602 = codec->private_data;
+       struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c = codec->control_data;
        struct snd_pcm_runtime *master_runtime;
 
@@ -373,7 +374,7 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct ssm2602_priv *ssm2602 = codec->private_data;
+       struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
 
        /* deactivate */
        if (!codec->active)
@@ -401,7 +402,7 @@ static int ssm2602_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct ssm2602_priv *ssm2602 = codec->private_data;
+       struct ssm2602_priv *ssm2602 = snd_soc_codec_get_drvdata(codec);
        switch (freq) {
        case 11289600:
        case 12000000:
@@ -559,7 +560,6 @@ static int ssm2602_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
        ssm2602_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       ssm2602_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
@@ -605,8 +605,7 @@ static int ssm2602_init(struct snd_soc_device *socdev)
        reg = ssm2602_read_reg_cache(codec, SSM2602_ROUT1V);
        ssm2602_write(codec, SSM2602_ROUT1V, reg | ROUT1V_RLHP_BOTH);
        /*select Line in as default input*/
-       ssm2602_write(codec, SSM2602_APANA,
-                       APANA_ENABLE_MIC_BOOST2 | APANA_SELECT_DAC |
+       ssm2602_write(codec, SSM2602_APANA, APANA_SELECT_DAC |
                        APANA_ENABLE_MIC_BOOST);
        ssm2602_write(codec, SSM2602_PWR, 0);
 
@@ -727,7 +726,7 @@ static int ssm2602_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
-       codec->private_data = ssm2602;
+       snd_soc_codec_set_drvdata(codec, ssm2602);
        socdev->card->codec = codec;
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -760,7 +759,7 @@ static int ssm2602_remove(struct platform_device *pdev)
        i2c_unregister_device(codec->control_data);
        i2c_del_driver(&ssm2602_i2c_driver);
 #endif
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec);
 
        return 0;
index 3293629..ee86568 100644 (file)
@@ -289,9 +289,6 @@ reset:
        }
        stac9766_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
-               stac9766_set_bias_level(codec, SND_SOC_BIAS_ON);
-
        return 0;
 }
 
@@ -410,7 +407,7 @@ reset_err:
 pcm_err:
        snd_soc_free_ac97_codec(codec);
 codec_err:
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
 cache_err:
        kfree(socdev->card->codec);
        socdev->card->codec = NULL;
index 776b79c..b0bae35 100644 (file)
@@ -634,7 +634,6 @@ static int tlv320aic23_resume(struct platform_device *pdev)
        }
 
        tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       tlv320aic23_set_bias_level(codec, codec->suspend_bias_level);
 
        return 0;
 }
index b5b7d6a..f0e00fd 100644 (file)
@@ -49,7 +49,7 @@ struct aic26 {
 static unsigned int aic26_reg_read(struct snd_soc_codec *codec,
                                   unsigned int reg)
 {
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
        u16 *cache = codec->reg_cache;
        u16 cmd, value;
        u8 buffer[2];
@@ -93,7 +93,7 @@ static unsigned int aic26_reg_read_cache(struct snd_soc_codec *codec,
 static int aic26_reg_write(struct snd_soc_codec *codec, unsigned int reg,
                           unsigned int value)
 {
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
        u16 *cache = codec->reg_cache;
        u16 cmd;
        u8 buffer[4];
@@ -132,7 +132,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
        int fsref, divisor, wlen, pval, jval, dval, qval;
        u16 reg;
 
@@ -199,7 +199,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
 static int aic26_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
        u16 reg = aic26_reg_read_cache(codec, AIC26_REG_DAC_GAIN);
 
        dev_dbg(&aic26->spi->dev, "aic26_mute(dai=%p, mute=%i)\n",
@@ -218,7 +218,7 @@ static int aic26_set_sysclk(struct snd_soc_dai *codec_dai,
                            int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
 
        dev_dbg(&aic26->spi->dev, "aic26_set_sysclk(dai=%p, clk_id==%i,"
                " freq=%i, dir=%i)\n",
@@ -235,7 +235,7 @@ static int aic26_set_sysclk(struct snd_soc_dai *codec_dai,
 static int aic26_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct aic26 *aic26 = codec->private_data;
+       struct aic26 *aic26 = snd_soc_codec_get_drvdata(codec);
 
        dev_dbg(&aic26->spi->dev, "aic26_set_fmt(dai=%p, fmt==%i)\n",
                codec_dai, fmt);
@@ -431,7 +431,7 @@ static int aic26_spi_probe(struct spi_device *spi)
        /* Setup what we can in the codec structure so that the register
         * access functions will work as expected.  More will be filled
         * out when it is probed by the SoC CODEC part of this driver */
-       aic26->codec.private_data = aic26;
+       snd_soc_codec_set_drvdata(&aic26->codec, aic26);
        aic26->codec.name = "aic26";
        aic26->codec.owner = THIS_MODULE;
        aic26->codec.dai = &aic26_dai;
index 4a6d56c..71a6990 100644 (file)
@@ -38,6 +38,8 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/regulator/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <sound/core.h>
 #include <sound/soc-dapm.h>
 #include <sound/initval.h>
 #include <sound/tlv.h>
+#include <sound/tlv320aic3x.h>
 
 #include "tlv320aic3x.h"
 
-#define AIC3X_VERSION "0.2"
+#define AIC3X_NUM_SUPPLIES     4
+static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
+       "IOVDD",        /* I/O Voltage */
+       "DVDD",         /* Digital Core Voltage */
+       "AVDD",         /* Analog DAC Voltage */
+       "DRVDD",        /* ADC Analog and Output Driver Voltage */
+};
 
 /* codec private data */
 struct aic3x_priv {
        struct snd_soc_codec codec;
+       struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES];
        unsigned int sysclk;
        int master;
+       int gpio_reset;
 };
 
 /*
@@ -764,7 +775,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct aic3x_priv *aic3x = codec->private_data;
+       struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
        int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
        u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
        u16 d, pll_d = 1;
@@ -931,7 +942,7 @@ static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct aic3x_priv *aic3x = codec->private_data;
+       struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
 
        aic3x->sysclk = freq;
        return 0;
@@ -941,7 +952,7 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
                             unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct aic3x_priv *aic3x = codec->private_data;
+       struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
        u8 iface_areg, iface_breg;
        int delay = 0;
 
@@ -995,12 +1006,13 @@ static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
 static int aic3x_set_bias_level(struct snd_soc_codec *codec,
                                enum snd_soc_bias_level level)
 {
-       struct aic3x_priv *aic3x = codec->private_data;
+       struct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
        u8 reg;
 
        switch (level) {
        case SND_SOC_BIAS_ON:
-               /* all power is driven by DAPM system */
+               break;
+       case SND_SOC_BIAS_PREPARE:
                if (aic3x->master) {
                        /* enable pll */
                        reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
@@ -1008,48 +1020,9 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
                                    reg | PLL_ENABLE);
                }
                break;
-       case SND_SOC_BIAS_PREPARE:
-               break;
        case SND_SOC_BIAS_STANDBY:
-               /*
-                * all power is driven by DAPM system,
-                * so output power is safe if bypass was set
-                */
-               if (aic3x->master) {
-                       /* disable pll */
-                       reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
-                       aic3x_write(codec, AIC3X_PLL_PROGA_REG,
-                                   reg & ~PLL_ENABLE);
-               }
-               break;
+               /* fall through and disable pll */
        case SND_SOC_BIAS_OFF:
-               /* force all power off */
-               reg = aic3x_read_reg_cache(codec, LINE1L_2_LADC_CTRL);
-               aic3x_write(codec, LINE1L_2_LADC_CTRL, reg & ~LADC_PWR_ON);
-               reg = aic3x_read_reg_cache(codec, LINE1R_2_RADC_CTRL);
-               aic3x_write(codec, LINE1R_2_RADC_CTRL, reg & ~RADC_PWR_ON);
-
-               reg = aic3x_read_reg_cache(codec, DAC_PWR);
-               aic3x_write(codec, DAC_PWR, reg & ~(LDAC_PWR_ON | RDAC_PWR_ON));
-
-               reg = aic3x_read_reg_cache(codec, HPLOUT_CTRL);
-               aic3x_write(codec, HPLOUT_CTRL, reg & ~HPLOUT_PWR_ON);
-               reg = aic3x_read_reg_cache(codec, HPROUT_CTRL);
-               aic3x_write(codec, HPROUT_CTRL, reg & ~HPROUT_PWR_ON);
-
-               reg = aic3x_read_reg_cache(codec, HPLCOM_CTRL);
-               aic3x_write(codec, HPLCOM_CTRL, reg & ~HPLCOM_PWR_ON);
-               reg = aic3x_read_reg_cache(codec, HPRCOM_CTRL);
-               aic3x_write(codec, HPRCOM_CTRL, reg & ~HPRCOM_PWR_ON);
-
-               reg = aic3x_read_reg_cache(codec, MONOLOPM_CTRL);
-               aic3x_write(codec, MONOLOPM_CTRL, reg & ~MONOLOPM_PWR_ON);
-
-               reg = aic3x_read_reg_cache(codec, LLOPM_CTRL);
-               aic3x_write(codec, LLOPM_CTRL, reg & ~LLOPM_PWR_ON);
-               reg = aic3x_read_reg_cache(codec, RLOPM_CTRL);
-               aic3x_write(codec, RLOPM_CTRL, reg & ~RLOPM_PWR_ON);
-
                if (aic3x->master) {
                        /* disable pll */
                        reg = aic3x_read_reg_cache(codec, AIC3X_PLL_PROGA_REG);
@@ -1171,7 +1144,7 @@ static int aic3x_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
 
-       aic3x_set_bias_level(codec, codec->suspend_bias_level);
+       aic3x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        return 0;
 }
@@ -1309,6 +1282,13 @@ static int aic3x_unregister(struct aic3x_priv *aic3x)
        snd_soc_unregister_dai(&aic3x_dai);
        snd_soc_unregister_codec(&aic3x->codec);
 
+       if (aic3x->gpio_reset >= 0) {
+               gpio_set_value(aic3x->gpio_reset, 0);
+               gpio_free(aic3x->gpio_reset);
+       }
+       regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
+       regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
+
        kfree(aic3x);
        aic3x_codec = NULL;
 
@@ -1330,6 +1310,8 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
 {
        struct snd_soc_codec *codec;
        struct aic3x_priv *aic3x;
+       struct aic3x_pdata *pdata = i2c->dev.platform_data;
+       int ret, i;
 
        aic3x = kzalloc(sizeof(struct aic3x_priv), GFP_KERNEL);
        if (aic3x == NULL) {
@@ -1339,13 +1321,53 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
 
        codec = &aic3x->codec;
        codec->dev = &i2c->dev;
-       codec->private_data = aic3x;
+       snd_soc_codec_set_drvdata(codec, aic3x);
        codec->control_data = i2c;
        codec->hw_write = (hw_write_t) i2c_master_send;
 
        i2c_set_clientdata(i2c, aic3x);
 
+       aic3x->gpio_reset = -1;
+       if (pdata && pdata->gpio_reset >= 0) {
+               ret = gpio_request(pdata->gpio_reset, "tlv320aic3x reset");
+               if (ret != 0)
+                       goto err_gpio;
+               aic3x->gpio_reset = pdata->gpio_reset;
+               gpio_direction_output(aic3x->gpio_reset, 0);
+       }
+
+       for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
+               aic3x->supplies[i].supply = aic3x_supply_names[i];
+
+       ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(aic3x->supplies),
+                                aic3x->supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
+               goto err_get;
+       }
+
+       ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
+                                   aic3x->supplies);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
+               goto err_enable;
+       }
+
+       if (aic3x->gpio_reset >= 0) {
+               udelay(1);
+               gpio_set_value(aic3x->gpio_reset, 1);
+       }
+
        return aic3x_register(codec);
+
+err_enable:
+       regulator_bulk_free(ARRAY_SIZE(aic3x->supplies), aic3x->supplies);
+err_get:
+       if (aic3x->gpio_reset >= 0)
+               gpio_free(aic3x->gpio_reset);
+err_gpio:
+       kfree(aic3x);
+       return ret;
 }
 
 static int aic3x_i2c_remove(struct i2c_client *client)
index d1e0e81..65adc77 100644 (file)
 
 #define LATENCY_TIME_MS                20
 
+#define MODE7_LTHR             10
+#define MODE7_UTHR             (DAC33_BUFFER_SIZE_SAMPLES - 10)
+
+#define BURST_BASEFREQ_HZ      49152000
+
+#define SAMPLES_TO_US(rate, samples) \
+       (1000000000 / ((rate * 1000) / samples))
+
+#define US_TO_SAMPLES(rate, us) \
+       (rate / (1000000 / us))
+
+static void dac33_calculate_times(struct snd_pcm_substream *substream);
+static int dac33_prepare_chip(struct snd_pcm_substream *substream);
+
 static struct snd_soc_codec *tlv320dac33_codec;
 
 enum dac33_state {
@@ -80,6 +94,7 @@ struct tlv320dac33_priv {
        struct work_struct work;
        struct snd_soc_codec codec;
        struct regulator_bulk_data supplies[DAC33_NUM_SUPPLIES];
+       struct snd_pcm_substream *substream;
        int power_gpio;
        int chip_power;
        int irq;
@@ -93,6 +108,17 @@ struct tlv320dac33_priv {
        enum dac33_fifo_modes fifo_mode;/* FIFO mode selection */
        unsigned int nsample;           /* burst read amount from host */
        u8 burst_bclkdiv;               /* BCLK divider value in burst mode */
+       unsigned int burst_rate;        /* Interface speed in Burst modes */
+
+       int keep_bclk;                  /* Keep the BCLK continuously running
+                                        * in FIFO modes */
+       spinlock_t lock;
+       unsigned long long t_stamp1;    /* Time stamp for FIFO modes to */
+       unsigned long long t_stamp2;    /* calculate the FIFO caused delay */
+
+       unsigned int mode1_us_burst;    /* Time to burst read n number of
+                                        * samples */
+       unsigned int mode7_us_to_lthr;  /* Time to reach lthr from uthr */
 
        enum dac33_state state;
 };
@@ -166,7 +192,7 @@ static inline void dac33_write_reg_cache(struct snd_soc_codec *codec,
 static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
                      u8 *value)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        int val;
 
        *value = reg & 0xff;
@@ -191,7 +217,7 @@ static int dac33_read(struct snd_soc_codec *codec, unsigned int reg,
 static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
                       unsigned int value)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        u8 data[2];
        int ret = 0;
 
@@ -218,7 +244,7 @@ static int dac33_write(struct snd_soc_codec *codec, unsigned int reg,
 static int dac33_write_locked(struct snd_soc_codec *codec, unsigned int reg,
                       unsigned int value)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        mutex_lock(&dac33->mutex);
@@ -232,7 +258,7 @@ static int dac33_write_locked(struct snd_soc_codec *codec, unsigned int reg,
 static int dac33_write16(struct snd_soc_codec *codec, unsigned int reg,
                       unsigned int value)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        u8 data[3];
        int ret = 0;
 
@@ -262,45 +288,47 @@ static int dac33_write16(struct snd_soc_codec *codec, unsigned int reg,
        return ret;
 }
 
-static void dac33_restore_regs(struct snd_soc_codec *codec)
+static void dac33_init_chip(struct snd_soc_codec *codec)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
-       u8 *cache = codec->reg_cache;
-       u8 data[2];
-       int i, ret;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
 
-       if (!dac33->chip_power)
+       if (unlikely(!dac33->chip_power))
                return;
 
-       for (i = DAC33_PWR_CTRL; i <= DAC33_INTP_CTRL_B; i++) {
-               data[0] = i;
-               data[1] = cache[i];
-               /* Skip the read only registers */
-               if ((i >= DAC33_INT_OSC_STATUS &&
-                               i <= DAC33_INT_OSC_FREQ_RAT_READ_B) ||
-                   (i >= DAC33_FIFO_WPTR_MSB && i <= DAC33_FIFO_IRQ_FLAG) ||
-                   i == DAC33_DAC_STATUS_FLAGS ||
-                   i == DAC33_SRC_EST_REF_CLK_RATIO_A ||
-                   i == DAC33_SRC_EST_REF_CLK_RATIO_B)
-                       continue;
-               ret = codec->hw_write(codec->control_data, data, 2);
-               if (ret != 2)
-                       dev_err(codec->dev, "Write failed (%d)\n", ret);
-       }
-       for (i = DAC33_LDAC_PWR_CTRL; i <= DAC33_LINEL_TO_LLO_VOL; i++) {
-               data[0] = i;
-               data[1] = cache[i];
-               ret = codec->hw_write(codec->control_data, data, 2);
-               if (ret != 2)
-                       dev_err(codec->dev, "Write failed (%d)\n", ret);
-       }
-       for (i = DAC33_LINER_TO_RLO_VOL; i <= DAC33_OSC_TRIM; i++) {
-               data[0] = i;
-               data[1] = cache[i];
-               ret = codec->hw_write(codec->control_data, data, 2);
-               if (ret != 2)
-                       dev_err(codec->dev, "Write failed (%d)\n", ret);
-       }
+       /* 44-46: DAC Control Registers */
+       /* A : DAC sample rate Fsref/1.5 */
+       dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0));
+       /* B : DAC src=normal, not muted */
+       dac33_write(codec, DAC33_DAC_CTRL_B, DAC33_DACSRCR_RIGHT |
+                                            DAC33_DACSRCL_LEFT);
+       /* C : (defaults) */
+       dac33_write(codec, DAC33_DAC_CTRL_C, 0x00);
+
+       /* 73 : volume soft stepping control,
+        clock source = internal osc (?) */
+       dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
+
+       dac33_write(codec, DAC33_PWR_CTRL, DAC33_PDNALLB);
+
+       /* Restore only selected registers (gains mostly) */
+       dac33_write(codec, DAC33_LDAC_DIG_VOL_CTRL,
+                   dac33_read_reg_cache(codec, DAC33_LDAC_DIG_VOL_CTRL));
+       dac33_write(codec, DAC33_RDAC_DIG_VOL_CTRL,
+                   dac33_read_reg_cache(codec, DAC33_RDAC_DIG_VOL_CTRL));
+
+       dac33_write(codec, DAC33_LINEL_TO_LLO_VOL,
+                   dac33_read_reg_cache(codec, DAC33_LINEL_TO_LLO_VOL));
+       dac33_write(codec, DAC33_LINER_TO_RLO_VOL,
+                   dac33_read_reg_cache(codec, DAC33_LINER_TO_RLO_VOL));
+}
+
+static inline void dac33_read_id(struct snd_soc_codec *codec)
+{
+       u8 reg;
+
+       dac33_read(codec, DAC33_DEVICE_ID_MSB, &reg);
+       dac33_read(codec, DAC33_DEVICE_ID_LSB, &reg);
+       dac33_read(codec, DAC33_DEVICE_REV_ID, &reg);
 }
 
 static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
@@ -311,16 +339,25 @@ static inline void dac33_soft_power(struct snd_soc_codec *codec, int power)
        if (power)
                reg |= DAC33_PDNALLB;
        else
-               reg &= ~DAC33_PDNALLB;
+               reg &= ~(DAC33_PDNALLB | DAC33_OSCPDNB |
+                        DAC33_DACRPDNB | DAC33_DACLPDNB);
        dac33_write(codec, DAC33_PWR_CTRL, reg);
 }
 
 static int dac33_hard_power(struct snd_soc_codec *codec, int power)
 {
-       struct tlv320dac33_priv *dac33 = codec->private_data;
-       int ret;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
+       int ret = 0;
 
        mutex_lock(&dac33->mutex);
+
+       /* Safety check */
+       if (unlikely(power == dac33->chip_power)) {
+               dev_dbg(codec->dev, "Trying to set the same power state: %s\n",
+                       power ? "ON" : "OFF");
+               goto exit;
+       }
+
        if (power) {
                ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies),
                                          dac33->supplies);
@@ -334,11 +371,6 @@ static int dac33_hard_power(struct snd_soc_codec *codec, int power)
                        gpio_set_value(dac33->power_gpio, 1);
 
                dac33->chip_power = 1;
-
-               /* Restore registers */
-               dac33_restore_regs(codec);
-
-               dac33_soft_power(codec, 1);
        } else {
                dac33_soft_power(codec, 0);
                if (dac33->power_gpio >= 0)
@@ -360,11 +392,27 @@ exit:
        return ret;
 }
 
+static int playback_event(struct snd_soc_dapm_widget *w,
+               struct snd_kcontrol *kcontrol, int event)
+{
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(w->codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               if (likely(dac33->substream)) {
+                       dac33_calculate_times(dac33->substream);
+                       dac33_prepare_chip(dac33->substream);
+               }
+               break;
+       }
+       return 0;
+}
+
 static int dac33_get_nsample(struct snd_kcontrol *kcontrol,
                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
 
        ucontrol->value.integer.value[0] = dac33->nsample;
 
@@ -375,17 +423,21 @@ static int dac33_set_nsample(struct snd_kcontrol *kcontrol,
                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        if (dac33->nsample == ucontrol->value.integer.value[0])
                return 0;
 
        if (ucontrol->value.integer.value[0] < dac33->nsample_min ||
-           ucontrol->value.integer.value[0] > dac33->nsample_max)
+           ucontrol->value.integer.value[0] > dac33->nsample_max) {
                ret = -EINVAL;
-       else
+       } else {
                dac33->nsample = ucontrol->value.integer.value[0];
+               /* Re calculate the burst time */
+               dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
+                                                     dac33->nsample);
+       }
 
        return ret;
 }
@@ -394,7 +446,7 @@ static int dac33_get_fifo_mode(struct snd_kcontrol *kcontrol,
                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
 
        ucontrol->value.integer.value[0] = dac33->fifo_mode;
 
@@ -405,7 +457,7 @@ static int dac33_set_fifo_mode(struct snd_kcontrol *kcontrol,
                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        if (dac33->fifo_mode == ucontrol->value.integer.value[0])
@@ -485,6 +537,8 @@ static const struct snd_soc_dapm_widget dac33_dapm_widgets[] = {
                         DAC33_OUT_AMP_PWR_CTRL, 6, 3, 3, 0),
        SND_SOC_DAPM_REG(snd_soc_dapm_mixer, "Output Right Amp Power",
                         DAC33_OUT_AMP_PWR_CTRL, 4, 3, 3, 0),
+
+       SND_SOC_DAPM_PRE("Prepare Playback", playback_event),
 };
 
 static const struct snd_soc_dapm_route audio_map[] = {
@@ -527,18 +581,21 @@ static int dac33_set_bias_level(struct snd_soc_codec *codec,
                break;
        case SND_SOC_BIAS_STANDBY:
                if (codec->bias_level == SND_SOC_BIAS_OFF) {
+                       /* Coming from OFF, switch on the codec */
                        ret = dac33_hard_power(codec, 1);
                        if (ret != 0)
                                return ret;
-               }
 
-               dac33_soft_power(codec, 0);
+                       dac33_init_chip(codec);
+               }
                break;
        case SND_SOC_BIAS_OFF:
+               /* Do not power off, when the codec is already off */
+               if (codec->bias_level == SND_SOC_BIAS_OFF)
+                       return 0;
                ret = dac33_hard_power(codec, 0);
                if (ret != 0)
                        return ret;
-
                break;
        }
        codec->bias_level = level;
@@ -555,13 +612,34 @@ static inline void dac33_prefill_handler(struct tlv320dac33_priv *dac33)
        switch (dac33->fifo_mode) {
        case DAC33_FIFO_MODE1:
                dac33_write16(codec, DAC33_NSAMPLE_MSB,
-                               DAC33_THRREG(dac33->nsample));
+                       DAC33_THRREG(dac33->nsample + dac33->alarm_threshold));
+
+               /* Take the timestamps */
+               spin_lock_irq(&dac33->lock);
+               dac33->t_stamp2 = ktime_to_us(ktime_get());
+               dac33->t_stamp1 = dac33->t_stamp2;
+               spin_unlock_irq(&dac33->lock);
+
                dac33_write16(codec, DAC33_PREFILL_MSB,
                                DAC33_THRREG(dac33->alarm_threshold));
+               /* Enable Alarm Threshold IRQ with a delay */
+               udelay(SAMPLES_TO_US(dac33->burst_rate,
+                                    dac33->alarm_threshold));
+               dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
                break;
        case DAC33_FIFO_MODE7:
+               /* Take the timestamp */
+               spin_lock_irq(&dac33->lock);
+               dac33->t_stamp1 = ktime_to_us(ktime_get());
+               /* Move back the timestamp with drain time */
+               dac33->t_stamp1 -= dac33->mode7_us_to_lthr;
+               spin_unlock_irq(&dac33->lock);
+
                dac33_write16(codec, DAC33_PREFILL_MSB,
-                               DAC33_THRREG(10));
+                               DAC33_THRREG(MODE7_LTHR));
+
+               /* Enable Upper Threshold IRQ */
+               dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MUT);
                break;
        default:
                dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
@@ -578,6 +656,11 @@ static inline void dac33_playback_handler(struct tlv320dac33_priv *dac33)
 
        switch (dac33->fifo_mode) {
        case DAC33_FIFO_MODE1:
+               /* Take the timestamp */
+               spin_lock_irq(&dac33->lock);
+               dac33->t_stamp2 = ktime_to_us(ktime_get());
+               spin_unlock_irq(&dac33->lock);
+
                dac33_write16(codec, DAC33_NSAMPLE_MSB,
                                DAC33_THRREG(dac33->nsample));
                break;
@@ -628,31 +711,17 @@ static void dac33_work(struct work_struct *work)
 static irqreturn_t dac33_interrupt_handler(int irq, void *dev)
 {
        struct snd_soc_codec *codec = dev;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
-
-       queue_work(dac33->dac33_wq, &dac33->work);
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
 
-       return IRQ_HANDLED;
-}
+       spin_lock(&dac33->lock);
+       dac33->t_stamp1 = ktime_to_us(ktime_get());
+       spin_unlock(&dac33->lock);
 
-static void dac33_shutdown(struct snd_pcm_substream *substream,
-                            struct snd_soc_dai *dai)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_device *socdev = rtd->socdev;
-       struct snd_soc_codec *codec = socdev->card->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
-       unsigned int pwr_ctrl;
+       /* Do not schedule the workqueue in Mode7 */
+       if (dac33->fifo_mode != DAC33_FIFO_MODE7)
+               queue_work(dac33->dac33_wq, &dac33->work);
 
-       /* Stop pending workqueue */
-       if (dac33->fifo_mode)
-               cancel_work_sync(&dac33->work);
-
-       mutex_lock(&dac33->mutex);
-       pwr_ctrl = dac33_read_reg_cache(codec, DAC33_PWR_CTRL);
-       pwr_ctrl &= ~(DAC33_OSCPDNB | DAC33_DACRPDNB | DAC33_DACLPDNB);
-       dac33_write(codec, DAC33_PWR_CTRL, pwr_ctrl);
-       mutex_unlock(&dac33->mutex);
+       return IRQ_HANDLED;
 }
 
 static void dac33_oscwait(struct snd_soc_codec *codec)
@@ -669,6 +738,31 @@ static void dac33_oscwait(struct snd_soc_codec *codec)
                        "internal oscillator calibration failed\n");
 }
 
+static int dac33_startup(struct snd_pcm_substream *substream,
+                          struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
+
+       /* Stream started, save the substream pointer */
+       dac33->substream = substream;
+
+       return 0;
+}
+
+static void dac33_shutdown(struct snd_pcm_substream *substream,
+                            struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
+
+       dac33->substream = NULL;
+}
+
 static int dac33_hw_params(struct snd_pcm_substream *substream,
                           struct snd_pcm_hw_params *params,
                           struct snd_soc_dai *dai)
@@ -715,7 +809,7 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        unsigned int oscset, ratioset, pwr_ctrl, reg_tmp;
        u8 aictrl_a, aictrl_b, fifoctrl_a;
 
@@ -752,6 +846,17 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
        }
 
        mutex_lock(&dac33->mutex);
+
+       if (!dac33->chip_power) {
+               /*
+                * Chip is not powered yet.
+                * Do the init in the dac33_set_bias_level later.
+                */
+               mutex_unlock(&dac33->mutex);
+               return 0;
+       }
+
+       dac33_soft_power(codec, 0);
        dac33_soft_power(codec, 1);
 
        reg_tmp = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
@@ -799,11 +904,10 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
        case DAC33_FIFO_MODE1:
                dac33_write(codec, DAC33_FIFO_IRQ_MODE_B,
                            DAC33_ATM(DAC33_FIFO_IRQ_MODE_LEVEL));
-               dac33_write(codec, DAC33_FIFO_IRQ_MASK, DAC33_MAT);
                break;
        case DAC33_FIFO_MODE7:
-               /* Disable all interrupts */
-               dac33_write(codec, DAC33_FIFO_IRQ_MASK, 0);
+               dac33_write(codec, DAC33_FIFO_IRQ_MODE_A,
+                       DAC33_UTM(DAC33_FIFO_IRQ_MODE_LEVEL));
                break;
        default:
                /* in FIFO bypass mode, the interrupts are not used */
@@ -822,7 +926,10 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
                 */
                fifoctrl_a &= ~DAC33_FBYPAS;
                fifoctrl_a &= ~DAC33_FAUTO;
-               aictrl_b &= ~DAC33_BCLKON;
+               if (dac33->keep_bclk)
+                       aictrl_b |= DAC33_BCLKON;
+               else
+                       aictrl_b &= ~DAC33_BCLKON;
                break;
        case DAC33_FIFO_MODE7:
                /*
@@ -833,7 +940,10 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
                 */
                fifoctrl_a &= ~DAC33_FBYPAS;
                fifoctrl_a |= DAC33_FAUTO;
-               aictrl_b &= ~DAC33_BCLKON;
+               if (dac33->keep_bclk)
+                       aictrl_b |= DAC33_BCLKON;
+               else
+                       aictrl_b &= ~DAC33_BCLKON;
                break;
        default:
                /*
@@ -875,10 +985,8 @@ static int dac33_prepare_chip(struct snd_pcm_substream *substream)
                 * Configure the threshold levels, and leave 10 sample space
                 * at the bottom, and also at the top of the FIFO
                 */
-               dac33_write16(codec, DAC33_UTHR_MSB,
-                       DAC33_THRREG(DAC33_BUFFER_SIZE_SAMPLES - 10));
-               dac33_write16(codec, DAC33_LTHR_MSB,
-                       DAC33_THRREG(10));
+               dac33_write16(codec, DAC33_UTHR_MSB, DAC33_THRREG(MODE7_UTHR));
+               dac33_write16(codec, DAC33_LTHR_MSB, DAC33_THRREG(MODE7_LTHR));
                break;
        default:
                break;
@@ -894,9 +1002,13 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        unsigned int nsample_limit;
 
+       /* In bypass mode we don't need to calculate */
+       if (!dac33->fifo_mode)
+               return;
+
        /* Number of samples (16bit, stereo) in one period */
        dac33->nsample_min = snd_pcm_lib_period_bytes(substream) / 4;
 
@@ -930,15 +1042,24 @@ static void dac33_calculate_times(struct snd_pcm_substream *substream)
 
        if (dac33->nsample > dac33->nsample_max)
                dac33->nsample = dac33->nsample_max;
-}
 
-static int dac33_pcm_prepare(struct snd_pcm_substream *substream,
-                            struct snd_soc_dai *dai)
-{
-       dac33_calculate_times(substream);
-       dac33_prepare_chip(substream);
+       switch (dac33->fifo_mode) {
+       case DAC33_FIFO_MODE1:
+               dac33->mode1_us_burst = SAMPLES_TO_US(dac33->burst_rate,
+                                                     dac33->nsample);
+               dac33->t_stamp1 = 0;
+               dac33->t_stamp2 = 0;
+               break;
+       case DAC33_FIFO_MODE7:
+               dac33->mode7_us_to_lthr =
+                                       SAMPLES_TO_US(substream->runtime->rate,
+                                               MODE7_UTHR - MODE7_LTHR + 1);
+               dac33->t_stamp1 = 0;
+               break;
+       default:
+               break;
+       }
 
-       return 0;
 }
 
 static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -947,7 +1068,7 @@ static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        switch (cmd) {
@@ -974,11 +1095,156 @@ static int dac33_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
        return ret;
 }
 
+static snd_pcm_sframes_t dac33_dai_delay(
+                       struct snd_pcm_substream *substream,
+                       struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
+       unsigned long long t0, t1, t_now;
+       unsigned int time_delta;
+       int samples_out, samples_in, samples;
+       snd_pcm_sframes_t delay = 0;
+
+       switch (dac33->fifo_mode) {
+       case DAC33_FIFO_BYPASS:
+               break;
+       case DAC33_FIFO_MODE1:
+               spin_lock(&dac33->lock);
+               t0 = dac33->t_stamp1;
+               t1 = dac33->t_stamp2;
+               spin_unlock(&dac33->lock);
+               t_now = ktime_to_us(ktime_get());
+
+               /* We have not started to fill the FIFO yet, delay is 0 */
+               if (!t1)
+                       goto out;
+
+               if (t0 > t1) {
+                       /*
+                        * Phase 1:
+                        * After Alarm threshold, and before nSample write
+                        */
+                       time_delta = t_now - t0;
+                       samples_out = time_delta ? US_TO_SAMPLES(
+                                               substream->runtime->rate,
+                                               time_delta) : 0;
+
+                       if (likely(dac33->alarm_threshold > samples_out))
+                               delay = dac33->alarm_threshold - samples_out;
+                       else
+                               delay = 0;
+               } else if ((t_now - t1) <= dac33->mode1_us_burst) {
+                       /*
+                        * Phase 2:
+                        * After nSample write (during burst operation)
+                        */
+                       time_delta = t_now - t0;
+                       samples_out = time_delta ? US_TO_SAMPLES(
+                                               substream->runtime->rate,
+                                               time_delta) : 0;
+
+                       time_delta = t_now - t1;
+                       samples_in = time_delta ? US_TO_SAMPLES(
+                                               dac33->burst_rate,
+                                               time_delta) : 0;
+
+                       samples = dac33->alarm_threshold;
+                       samples += (samples_in - samples_out);
+
+                       if (likely(samples > 0))
+                               delay = samples;
+                       else
+                               delay = 0;
+               } else {
+                       /*
+                        * Phase 3:
+                        * After burst operation, before next alarm threshold
+                        */
+                       time_delta = t_now - t0;
+                       samples_out = time_delta ? US_TO_SAMPLES(
+                                               substream->runtime->rate,
+                                               time_delta) : 0;
+
+                       samples_in = dac33->nsample;
+                       samples = dac33->alarm_threshold;
+                       samples += (samples_in - samples_out);
+
+                       if (likely(samples > 0))
+                               delay = samples > DAC33_BUFFER_SIZE_SAMPLES ?
+                                       DAC33_BUFFER_SIZE_SAMPLES : samples;
+                       else
+                               delay = 0;
+               }
+               break;
+       case DAC33_FIFO_MODE7:
+               spin_lock(&dac33->lock);
+               t0 = dac33->t_stamp1;
+               spin_unlock(&dac33->lock);
+               t_now = ktime_to_us(ktime_get());
+
+               /* We have not started to fill the FIFO yet, delay is 0 */
+               if (!t0)
+                       goto out;
+
+               if (t_now <= t0) {
+                       /*
+                        * Either the timestamps are messed or equal. Report
+                        * maximum delay
+                        */
+                       delay = MODE7_UTHR;
+                       goto out;
+               }
+
+               time_delta = t_now - t0;
+               if (time_delta <= dac33->mode7_us_to_lthr) {
+                       /*
+                       * Phase 1:
+                       * After burst (draining phase)
+                       */
+                       samples_out = US_TO_SAMPLES(
+                                       substream->runtime->rate,
+                                       time_delta);
+
+                       if (likely(MODE7_UTHR > samples_out))
+                               delay = MODE7_UTHR - samples_out;
+                       else
+                               delay = 0;
+               } else {
+                       /*
+                       * Phase 2:
+                       * During burst operation
+                       */
+                       time_delta = time_delta - dac33->mode7_us_to_lthr;
+
+                       samples_out = US_TO_SAMPLES(
+                                       substream->runtime->rate,
+                                       time_delta);
+                       samples_in = US_TO_SAMPLES(
+                                       dac33->burst_rate,
+                                       time_delta);
+                       delay = MODE7_LTHR + samples_in - samples_out;
+
+                       if (unlikely(delay > MODE7_UTHR))
+                               delay = MODE7_UTHR;
+               }
+               break;
+       default:
+               dev_warn(codec->dev, "Unhandled FIFO mode: %d\n",
+                                                       dac33->fifo_mode);
+               break;
+       }
+out:
+       return delay;
+}
+
 static int dac33_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        u8 ioc_reg, asrcb_reg;
 
        ioc_reg = dac33_read_reg_cache(codec, DAC33_INT_OSC_CTRL);
@@ -1008,7 +1274,7 @@ static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
                             unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct tlv320dac33_priv *dac33 = codec->private_data;
+       struct tlv320dac33_priv *dac33 = snd_soc_codec_get_drvdata(codec);
        u8 aictrl_a, aictrl_b;
 
        aictrl_a = dac33_read_reg_cache(codec, DAC33_SER_AUDIOIF_CTRL_A);
@@ -1059,35 +1325,6 @@ static int dac33_set_dai_fmt(struct snd_soc_dai *codec_dai,
        return 0;
 }
 
-static void dac33_init_chip(struct snd_soc_codec *codec)
-{
-       /* 44-46: DAC Control Registers */
-       /* A : DAC sample rate Fsref/1.5 */
-       dac33_write(codec, DAC33_DAC_CTRL_A, DAC33_DACRATE(0));
-       /* B : DAC src=normal, not muted */
-       dac33_write(codec, DAC33_DAC_CTRL_B, DAC33_DACSRCR_RIGHT |
-                                            DAC33_DACSRCL_LEFT);
-       /* C : (defaults) */
-       dac33_write(codec, DAC33_DAC_CTRL_C, 0x00);
-
-       /* 64-65 : L&R DAC power control
-        Line In -> OUT 1V/V Gain, DAC -> OUT 4V/V Gain*/
-       dac33_write(codec, DAC33_LDAC_PWR_CTRL, DAC33_LROUT_GAIN(2));
-       dac33_write(codec, DAC33_RDAC_PWR_CTRL, DAC33_LROUT_GAIN(2));
-
-       /* 73 : volume soft stepping control,
-        clock source = internal osc (?) */
-       dac33_write(codec, DAC33_ANA_VOL_SOFT_STEP_CTRL, DAC33_VOLCLKEN);
-
-       /* 66 : LOP/LOM Modes */
-       dac33_write(codec, DAC33_OUT_AMP_CM_CTRL, 0xff);
-
-       /* 68 : LOM inverted from LOP */
-       dac33_write(codec, DAC33_OUT_AMP_CTRL, (3<<2));
-
-       dac33_write(codec, DAC33_PWR_CTRL, DAC33_PDNALLB);
-}
-
 static int dac33_soc_probe(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
@@ -1099,12 +1336,7 @@ static int dac33_soc_probe(struct platform_device *pdev)
 
        codec = tlv320dac33_codec;
        socdev->card->codec = codec;
-       dac33 = codec->private_data;
-
-       /* Power up the codec */
-       dac33_hard_power(codec, 1);
-       /* Set default configuration */
-       dac33_init_chip(codec);
+       dac33 = snd_soc_codec_get_drvdata(codec);
 
        /* register pcms */
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
@@ -1122,12 +1354,6 @@ static int dac33_soc_probe(struct platform_device *pdev)
 
        dac33_add_widgets(codec);
 
-       /* power on device */
-       dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-
-       /* Bias level configuration has enabled regulator an extra time */
-       regulator_bulk_disable(ARRAY_SIZE(dac33->supplies), dac33->supplies);
-
        return 0;
 
 pcm_err:
@@ -1164,7 +1390,6 @@ static int dac33_soc_resume(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->card->codec;
 
        dac33_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       dac33_set_bias_level(codec, codec->suspend_bias_level);
 
        return 0;
 }
@@ -1182,10 +1407,11 @@ EXPORT_SYMBOL_GPL(soc_codec_dev_tlv320dac33);
 #define DAC33_FORMATS  SNDRV_PCM_FMTBIT_S16_LE
 
 static struct snd_soc_dai_ops dac33_dai_ops = {
+       .startup        = dac33_startup,
        .shutdown       = dac33_shutdown,
        .hw_params      = dac33_hw_params,
-       .prepare        = dac33_pcm_prepare,
        .trigger        = dac33_pcm_trigger,
+       .delay          = dac33_dai_delay,
        .set_sysclk     = dac33_set_dai_sysclk,
        .set_fmt        = dac33_set_dai_fmt,
 };
@@ -1221,11 +1447,12 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
                return -ENOMEM;
 
        codec = &dac33->codec;
-       codec->private_data = dac33;
+       snd_soc_codec_set_drvdata(codec, dac33);
        codec->control_data = client;
 
        mutex_init(&codec->mutex);
        mutex_init(&dac33->mutex);
+       spin_lock_init(&dac33->lock);
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
@@ -1236,6 +1463,7 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
        codec->hw_write = (hw_write_t) i2c_master_send;
        codec->bias_level = SND_SOC_BIAS_OFF;
        codec->set_bias_level = dac33_set_bias_level;
+       codec->idle_bias_off = 1;
        codec->dai = &dac33_dai;
        codec->num_dai = 1;
        codec->reg_cache_size = ARRAY_SIZE(dac33_reg);
@@ -1250,8 +1478,12 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
 
        dac33->power_gpio = pdata->power_gpio;
        dac33->burst_bclkdiv = pdata->burst_bclkdiv;
+       /* Pre calculate the burst rate */
+       dac33->burst_rate = BURST_BASEFREQ_HZ / dac33->burst_bclkdiv / 32;
+       dac33->keep_bclk = pdata->keep_bclk;
        dac33->irq = client->irq;
        dac33->nsample = NSAMPLE_MAX;
+       dac33->nsample_max = NSAMPLE_MAX;
        /* Disable FIFO use by default */
        dac33->fifo_mode = DAC33_FIFO_BYPASS;
 
@@ -1272,8 +1504,6 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
                        goto error_gpio;
                }
                gpio_direction_output(dac33->power_gpio, 0);
-       } else {
-               dac33->chip_power = 1;
        }
 
        /* Check if the IRQ number is valid and request it */
@@ -1311,12 +1541,14 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
                goto err_get;
        }
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(dac33->supplies),
-                                   dac33->supplies);
+       /* Read the tlv320dac33 ID registers */
+       ret = dac33_hard_power(codec, 1);
        if (ret != 0) {
-               dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
-               goto err_enable;
+               dev_err(codec->dev, "Failed to power up codec: %d\n", ret);
+               goto error_codec;
        }
+       dac33_read_id(codec);
+       dac33_hard_power(codec, 0);
 
        ret = snd_soc_register_codec(codec);
        if (ret != 0) {
@@ -1331,14 +1563,9 @@ static int __devinit dac33_i2c_probe(struct i2c_client *client,
                goto error_codec;
        }
 
-       /* Shut down the codec for now */
-       dac33_hard_power(codec, 0);
-
        return ret;
 
 error_codec:
-       regulator_bulk_disable(ARRAY_SIZE(dac33->supplies), dac33->supplies);
-err_enable:
        regulator_bulk_free(ARRAY_SIZE(dac33->supplies), dac33->supplies);
 err_get:
        if (dac33->irq >= 0) {
@@ -1362,7 +1589,9 @@ static int __devexit dac33_i2c_remove(struct i2c_client *client)
        struct tlv320dac33_priv *dac33;
 
        dac33 = i2c_get_clientdata(client);
-       dac33_hard_power(&dac33->codec, 0);
+
+       if (unlikely(dac33->chip_power))
+               dac33_hard_power(&dac33->codec, 0);
 
        if (dac33->power_gpio >= 0)
                gpio_free(dac33->power_gpio);
index 569ad87..99b70e5 100644 (file)
 
 static struct i2c_client *tpa6130a2_client;
 
-#define TPA6130A2_NUM_SUPPLIES 2
-static const char *tpa6130a2_supply_names[TPA6130A2_NUM_SUPPLIES] = {
-       "CPVSS",
-       "Vdd",
-};
-
-static const char *tpa6140a2_supply_names[TPA6130A2_NUM_SUPPLIES] = {
-       "HPVdd",
-       "AVdd",
-};
-
 /* This struct is used to save the context */
 struct tpa6130a2_data {
        struct mutex mutex;
        unsigned char regs[TPA6130A2_CACHEREGNUM];
-       struct regulator_bulk_data supplies[TPA6130A2_NUM_SUPPLIES];
+       struct regulator *supply;
        int power_gpio;
        unsigned char power_state;
+       enum tpa_model id;
 };
 
 static int tpa6130a2_i2c_read(int reg)
@@ -135,11 +125,10 @@ static int tpa6130a2_power(int power)
                if (data->power_gpio >= 0)
                        gpio_set_value(data->power_gpio, 1);
 
-               ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies),
-                                           data->supplies);
+               ret = regulator_enable(data->supply);
                if (ret != 0) {
                        dev_err(&tpa6130a2_client->dev,
-                               "Failed to enable supplies: %d\n", ret);
+                               "Failed to enable supply: %d\n", ret);
                        goto exit;
                }
 
@@ -160,11 +149,10 @@ static int tpa6130a2_power(int power)
                if (data->power_gpio >= 0)
                        gpio_set_value(data->power_gpio, 0);
 
-               ret = regulator_bulk_disable(ARRAY_SIZE(data->supplies),
-                                            data->supplies);
+               ret = regulator_disable(data->supply);
                if (ret != 0) {
                        dev_err(&tpa6130a2_client->dev,
-                               "Failed to disable supplies: %d\n", ret);
+                               "Failed to disable supply: %d\n", ret);
                        goto exit;
                }
 
@@ -176,7 +164,7 @@ exit:
        return ret;
 }
 
-static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
+static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
                struct snd_ctl_elem_value *ucontrol)
 {
        struct soc_mixer_control *mc =
@@ -184,7 +172,8 @@ static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
        struct tpa6130a2_data *data;
        unsigned int reg = mc->reg;
        unsigned int shift = mc->shift;
-       unsigned int mask = mc->max;
+       int max = mc->max;
+       unsigned int mask = (1 << fls(max)) - 1;
        unsigned int invert = mc->invert;
 
        BUG_ON(tpa6130a2_client == NULL);
@@ -197,13 +186,13 @@ static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
 
        if (invert)
                ucontrol->value.integer.value[0] =
-                       mask - ucontrol->value.integer.value[0];
+                       max - ucontrol->value.integer.value[0];
 
        mutex_unlock(&data->mutex);
        return 0;
 }
 
-static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol,
+static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
                struct snd_ctl_elem_value *ucontrol)
 {
        struct soc_mixer_control *mc =
@@ -211,7 +200,8 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol,
        struct tpa6130a2_data *data;
        unsigned int reg = mc->reg;
        unsigned int shift = mc->shift;
-       unsigned int mask = mc->max;
+       int max = mc->max;
+       unsigned int mask = (1 << fls(max)) - 1;
        unsigned int invert = mc->invert;
        unsigned int val = (ucontrol->value.integer.value[0] & mask);
        unsigned int val_reg;
@@ -220,7 +210,7 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol,
        data = i2c_get_clientdata(tpa6130a2_client);
 
        if (invert)
-               val = mask - val;
+               val = max - val;
 
        mutex_lock(&data->mutex);
 
@@ -260,10 +250,24 @@ static const unsigned int tpa6130_tlv[] = {
 static const struct snd_kcontrol_new tpa6130a2_controls[] = {
        SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
                       TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
-                      tpa6130a2_get_reg, tpa6130a2_set_reg,
+                      tpa6130a2_get_volsw, tpa6130a2_put_volsw,
                       tpa6130_tlv),
 };
 
+static const unsigned int tpa6140_tlv[] = {
+       TLV_DB_RANGE_HEAD(3),
+       0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
+       9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
+       17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
+};
+
+static const struct snd_kcontrol_new tpa6140a2_controls[] = {
+       SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
+                      TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
+                      tpa6130a2_get_volsw, tpa6130a2_put_volsw,
+                      tpa6140_tlv),
+};
+
 /*
  * Enable or disable channel (left or right)
  * The bit number for mute and amplifier are the same per channel:
@@ -355,8 +359,8 @@ static const struct snd_soc_dapm_widget tpa6130a2_dapm_widgets[] = {
                        0, 0, tpa6130a2_supply_event,
                        SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
        /* Outputs */
-       SND_SOC_DAPM_HP("TPA6130A2 Headphone Left", NULL),
-       SND_SOC_DAPM_HP("TPA6130A2 Headphone Right", NULL),
+       SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Left"),
+       SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Right"),
 };
 
 static const struct snd_soc_dapm_route audio_map[] = {
@@ -369,13 +373,22 @@ static const struct snd_soc_dapm_route audio_map[] = {
 
 int tpa6130a2_add_controls(struct snd_soc_codec *codec)
 {
+       struct  tpa6130a2_data *data;
+
+       BUG_ON(tpa6130a2_client == NULL);
+       data = i2c_get_clientdata(tpa6130a2_client);
+
        snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,
                                ARRAY_SIZE(tpa6130a2_dapm_widgets));
 
        snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
-       return snd_soc_add_controls(codec, tpa6130a2_controls,
-                               ARRAY_SIZE(tpa6130a2_controls));
+       if (data->id == TPA6140A2)
+               return snd_soc_add_controls(codec, tpa6140a2_controls,
+                                               ARRAY_SIZE(tpa6140a2_controls));
+       else
+               return snd_soc_add_controls(codec, tpa6130a2_controls,
+                                               ARRAY_SIZE(tpa6130a2_controls));
 
 }
 EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
@@ -386,7 +399,8 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
        struct device *dev;
        struct tpa6130a2_data *data;
        struct tpa6130a2_platform_data *pdata;
-       int i, ret;
+       const char *regulator;
+       int ret;
 
        dev = &client->dev;
 
@@ -408,6 +422,7 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
 
        pdata = client->dev.platform_data;
        data->power_gpio = pdata->power_gpio;
+       data->id = pdata->id;
 
        mutex_init(&data->mutex);
 
@@ -426,26 +441,22 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
                gpio_direction_output(data->power_gpio, 0);
        }
 
-       switch (pdata->id) {
+       switch (data->id) {
+       default:
+               dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
+                        pdata->id);
        case TPA6130A2:
-               for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
-                       data->supplies[i].supply = tpa6130a2_supply_names[i];
+               regulator = "Vdd";
                break;
        case TPA6140A2:
-               for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
-                       data->supplies[i].supply = tpa6140a2_supply_names[i];;
+               regulator = "AVdd";
                break;
-       default:
-               dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
-                        pdata->id);
-               for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
-                       data->supplies[i].supply = tpa6130a2_supply_names[i];
        }
 
-       ret = regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
-                                data->supplies);
-       if (ret != 0) {
-               dev_err(dev, "Failed to request supplies: %d\n", ret);
+       data->supply = regulator_get(dev, regulator);
+       if (IS_ERR(data->supply)) {
+               ret = PTR_ERR(data->supply);
+               dev_err(dev, "Failed to request supply: %d\n", ret);
                goto err_regulator;
        }
 
@@ -468,7 +479,7 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
        return 0;
 
 err_power:
-       regulator_bulk_free(ARRAY_SIZE(data->supplies), data->supplies);
+       regulator_put(data->supply);
 err_regulator:
        if (data->power_gpio >= 0)
                gpio_free(data->power_gpio);
@@ -489,7 +500,7 @@ static int __devexit tpa6130a2_remove(struct i2c_client *client)
        if (data->power_gpio >= 0)
                gpio_free(data->power_gpio);
 
-       regulator_bulk_free(ARRAY_SIZE(data->supplies), data->supplies);
+       regulator_put(data->supply);
 
        kfree(data);
        tpa6130a2_client = NULL;
index 520ffd6..b4fcdb0 100644 (file)
@@ -124,6 +124,8 @@ struct twl4030_priv {
        struct snd_soc_codec codec;
 
        unsigned int codec_powered;
+
+       /* reference counts of AIF/APLL users */
        unsigned int apll_enabled;
 
        struct snd_pcm_substream *master_substream;
@@ -136,9 +138,11 @@ struct twl4030_priv {
 
        unsigned int sysclk;
 
-       /* Headset output state handling */
-       unsigned int hsl_enabled;
-       unsigned int hsr_enabled;
+       /* Output (with associated amp) states */
+       u8 hsl_enabled, hsr_enabled;
+       u8 earpiece_enabled;
+       u8 predrivel_enabled, predriver_enabled;
+       u8 carkitl_enabled, carkitr_enabled;
 };
 
 /*
@@ -174,17 +178,52 @@ static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec,
 static int twl4030_write(struct snd_soc_codec *codec,
                        unsigned int reg, unsigned int value)
 {
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+       int write_to_reg = 0;
+
        twl4030_write_reg_cache(codec, reg, value);
-       if (likely(reg < TWL4030_REG_SW_SHADOW))
-               return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value,
-                                           reg);
-       else
-               return 0;
+       if (likely(reg < TWL4030_REG_SW_SHADOW)) {
+               /* Decide if the given register can be written */
+               switch (reg) {
+               case TWL4030_REG_EAR_CTL:
+                       if (twl4030->earpiece_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PREDL_CTL:
+                       if (twl4030->predrivel_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PREDR_CTL:
+                       if (twl4030->predriver_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PRECKL_CTL:
+                       if (twl4030->carkitl_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_PRECKR_CTL:
+                       if (twl4030->carkitr_enabled)
+                               write_to_reg = 1;
+                       break;
+               case TWL4030_REG_HS_GAIN_SET:
+                       if (twl4030->hsl_enabled || twl4030->hsr_enabled)
+                               write_to_reg = 1;
+                       break;
+               default:
+                       /* All other register can be written */
+                       write_to_reg = 1;
+                       break;
+               }
+               if (write_to_reg)
+                       return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
+                                                   value, reg);
+       }
+       return 0;
 }
 
 static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
 {
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        int mode;
 
        if (enable == twl4030->codec_powered)
@@ -222,28 +261,28 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
 
 static void twl4030_apll_enable(struct snd_soc_codec *codec, int enable)
 {
-       struct twl4030_priv *twl4030 = codec->private_data;
-       int status;
-
-       if (enable == twl4030->apll_enabled)
-               return;
-
-       if (enable)
-               /* Enable PLL */
-               status = twl4030_codec_enable_resource(TWL4030_CODEC_RES_APLL);
-       else
-               /* Disable PLL */
-               status = twl4030_codec_disable_resource(TWL4030_CODEC_RES_APLL);
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
+       int status = -1;
+
+       if (enable) {
+               twl4030->apll_enabled++;
+               if (twl4030->apll_enabled == 1)
+                       status = twl4030_codec_enable_resource(
+                                                       TWL4030_CODEC_RES_APLL);
+       } else {
+               twl4030->apll_enabled--;
+               if (!twl4030->apll_enabled)
+                       status = twl4030_codec_disable_resource(
+                                                       TWL4030_CODEC_RES_APLL);
+       }
 
        if (status >= 0)
                twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, status);
-
-       twl4030->apll_enabled = enable;
 }
 
 static void twl4030_power_up(struct snd_soc_codec *codec)
 {
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 anamicl, regmisc1, byte;
        int i = 0;
 
@@ -526,26 +565,26 @@ static int micpath_event(struct snd_soc_dapm_widget *w,
  * Output PGA builder:
  * Handle the muting and unmuting of the given output (turning off the
  * amplifier associated with the output pin)
- * On mute bypass the reg_cache and mute the volume
- * On unmute: restore the register content
+ * On mute bypass the reg_cache and write 0 to the register
+ * On unmute: restore the register content from the reg_cache
  * Outputs handled in this way:  Earpiece, PreDrivL/R, CarkitL/R
  */
 #define TWL4030_OUTPUT_PGA(pin_name, reg, mask)                                \
 static int pin_name##pga_event(struct snd_soc_dapm_widget *w,          \
                struct snd_kcontrol *kcontrol, int event)               \
 {                                                                      \
-       u8 reg_val;                                                     \
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec); \
                                                                        \
        switch (event) {                                                \
        case SND_SOC_DAPM_POST_PMU:                                     \
+               twl4030->pin_name##_enabled = 1;                        \
                twl4030_write(w->codec, reg,                            \
                        twl4030_read_reg_cache(w->codec, reg));         \
                break;                                                  \
        case SND_SOC_DAPM_POST_PMD:                                     \
-               reg_val = twl4030_read_reg_cache(w->codec, reg);        \
-               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,    \
-                                       reg_val & (~mask),              \
-                                       reg);                           \
+               twl4030->pin_name##_enabled = 0;                        \
+               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,            \
+                                       0, reg);                        \
                break;                                                  \
        }                                                               \
        return 0;                                                       \
@@ -636,13 +675,38 @@ static int apll_event(struct snd_soc_dapm_widget *w,
        return 0;
 }
 
+static int aif_event(struct snd_soc_dapm_widget *w,
+               struct snd_kcontrol *kcontrol, int event)
+{
+       u8 audio_if;
+
+       audio_if = twl4030_read_reg_cache(w->codec, TWL4030_REG_AUDIO_IF);
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               /* Enable AIF */
+               /* enable the PLL before we use it to clock the DAI */
+               twl4030_apll_enable(w->codec, 1);
+
+               twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
+                                               audio_if | TWL4030_AIF_EN);
+               break;
+       case SND_SOC_DAPM_POST_PMD:
+               /* disable the DAI before we stop it's source PLL */
+               twl4030_write(w->codec, TWL4030_REG_AUDIO_IF,
+                                               audio_if &  ~TWL4030_AIF_EN);
+               twl4030_apll_enable(w->codec, 0);
+               break;
+       }
+       return 0;
+}
+
 static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 {
        struct snd_soc_device *socdev = codec->socdev;
        struct twl4030_setup_data *setup = socdev->codec_data;
 
        unsigned char hs_gain, hs_pop;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        /* Base values for ramp delay calculation: 2^19 - 2^26 */
        unsigned int ramp_base[] = {524288, 1048576, 2097152, 4194304,
                                    8388608, 16777216, 33554432, 67108864};
@@ -665,7 +729,10 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
                /* Headset ramp-up according to the TRM */
                hs_pop |= TWL4030_VMID_EN;
                twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
-               twl4030_write(codec, TWL4030_REG_HS_GAIN_SET, hs_gain);
+               /* Actually write to the register */
+               twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
+                                       hs_gain,
+                                       TWL4030_REG_HS_GAIN_SET);
                hs_pop |= TWL4030_RAMP_EN;
                twl4030_write(codec, TWL4030_REG_HS_POPN_SET, hs_pop);
                /* Wait ramp delay time + 1, so the VMID can settle */
@@ -702,7 +769,7 @@ static void headset_ramp(struct snd_soc_codec *codec, int ramp)
 static int headsetlpga_event(struct snd_soc_dapm_widget *w,
                struct snd_kcontrol *kcontrol, int event)
 {
-       struct twl4030_priv *twl4030 = w->codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
@@ -726,7 +793,7 @@ static int headsetlpga_event(struct snd_soc_dapm_widget *w,
 static int headsetrpga_event(struct snd_soc_dapm_widget *w,
                struct snd_kcontrol *kcontrol, int event)
 {
-       struct twl4030_priv *twl4030 = w->codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(w->codec);
 
        switch (event) {
        case SND_SOC_DAPM_POST_PMU:
@@ -918,7 +985,7 @@ static int snd_soc_put_twl4030_opmode_enum_double(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
        unsigned short val;
        unsigned short mask, bitmask;
@@ -1036,6 +1103,16 @@ static const struct soc_enum twl4030_vibradir_enum =
                        ARRAY_SIZE(twl4030_vibradir_texts),
                        twl4030_vibradir_texts);
 
+/* Digimic Left and right swapping */
+static const char *twl4030_digimicswap_texts[] = {
+       "Not swapped", "Swapped",
+};
+
+static const struct soc_enum twl4030_digimicswap_enum =
+       SOC_ENUM_SINGLE(TWL4030_REG_MISC_SET_1, 0,
+                       ARRAY_SIZE(twl4030_digimicswap_texts),
+                       twl4030_digimicswap_texts);
+
 static const struct snd_kcontrol_new twl4030_snd_controls[] = {
        /* Codec operation mode control */
        SOC_ENUM_EXT("Codec Operation Mode", twl4030_op_modes_enum,
@@ -1112,6 +1189,8 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = {
 
        SOC_ENUM("Vibra H-bridge mode", twl4030_vibradirmode_enum),
        SOC_ENUM("Vibra H-bridge direction", twl4030_vibradir_enum),
+
+       SOC_ENUM("Digimic LR Swap", twl4030_digimicswap_enum),
 };
 
 static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
@@ -1128,8 +1207,6 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_INPUT("DIGIMIC1"),
 
        /* Outputs */
-       SND_SOC_DAPM_OUTPUT("OUTL"),
-       SND_SOC_DAPM_OUTPUT("OUTR"),
        SND_SOC_DAPM_OUTPUT("EARPIECE"),
        SND_SOC_DAPM_OUTPUT("PREDRIVEL"),
        SND_SOC_DAPM_OUTPUT("PREDRIVER"),
@@ -1141,6 +1218,11 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_OUTPUT("HFR"),
        SND_SOC_DAPM_OUTPUT("VIBRA"),
 
+       /* AIF and APLL clocks for running DAIs (including loopback) */
+       SND_SOC_DAPM_OUTPUT("Virtual HiFi OUT"),
+       SND_SOC_DAPM_INPUT("Virtual HiFi IN"),
+       SND_SOC_DAPM_OUTPUT("Virtual Voice OUT"),
+
        /* DACs */
        SND_SOC_DAPM_DAC("DAC Right1", "Right Front HiFi Playback",
                        SND_SOC_NOPM, 0, 0),
@@ -1204,7 +1286,8 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
        SND_SOC_DAPM_SUPPLY("APLL Enable", SND_SOC_NOPM, 0, 0, apll_event,
                            SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
 
-       SND_SOC_DAPM_SUPPLY("AIF Enable", TWL4030_REG_AUDIO_IF, 0, 0, NULL, 0),
+       SND_SOC_DAPM_SUPPLY("AIF Enable", SND_SOC_NOPM, 0, 0, aif_event,
+                           SND_SOC_DAPM_PRE_PMU|SND_SOC_DAPM_POST_PMD),
 
        /* Output MIXER controls */
        /* Earpiece */
@@ -1334,10 +1417,6 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"Digital Voice Playback Mixer", NULL, "DAC Voice"},
 
        /* Supply for the digital part (APLL) */
-       {"Digital R1 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital L1 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital R2 Playback Mixer", NULL, "APLL Enable"},
-       {"Digital L2 Playback Mixer", NULL, "APLL Enable"},
        {"Digital Voice Playback Mixer", NULL, "APLL Enable"},
 
        {"Digital R1 Playback Mixer", NULL, "AIF Enable"},
@@ -1411,8 +1490,14 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"Vibra Mux", "AudioR2", "DAC Right2"},
 
        /* outputs */
-       {"OUTL", NULL, "Analog L2 Playback Mixer"},
-       {"OUTR", NULL, "Analog R2 Playback Mixer"},
+       /* Must be always connected (for AIF and APLL) */
+       {"Virtual HiFi OUT", NULL, "Digital L1 Playback Mixer"},
+       {"Virtual HiFi OUT", NULL, "Digital R1 Playback Mixer"},
+       {"Virtual HiFi OUT", NULL, "Digital L2 Playback Mixer"},
+       {"Virtual HiFi OUT", NULL, "Digital R2 Playback Mixer"},
+       /* Must be always connected (for APLL) */
+       {"Virtual Voice OUT", NULL, "Digital Voice Playback Mixer"},
+       /* Physical outputs */
        {"EARPIECE", NULL, "Earpiece PGA"},
        {"PREDRIVEL", NULL, "PredriveL PGA"},
        {"PREDRIVER", NULL, "PredriveR PGA"},
@@ -1426,6 +1511,12 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"VIBRA", NULL, "Vibra Route"},
 
        /* Capture path */
+       /* Must be always connected (for AIF and APLL) */
+       {"ADC Virtual Left1", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Right1", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Left2", NULL, "Virtual HiFi IN"},
+       {"ADC Virtual Right2", NULL, "Virtual HiFi IN"},
+       /* Physical inputs */
        {"Analog Left", "Main Mic Capture Switch", "MAINMIC"},
        {"Analog Left", "Headset Mic Capture Switch", "HSMIC"},
        {"Analog Left", "AUXL Capture Switch", "AUXL"},
@@ -1458,11 +1549,6 @@ static const struct snd_soc_dapm_route intercon[] = {
        {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
        {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
 
-       {"ADC Virtual Left1", NULL, "APLL Enable"},
-       {"ADC Virtual Right1", NULL, "APLL Enable"},
-       {"ADC Virtual Left2", NULL, "APLL Enable"},
-       {"ADC Virtual Right2", NULL, "APLL Enable"},
-
        {"ADC Virtual Left1", NULL, "AIF Enable"},
        {"ADC Virtual Right1", NULL, "AIF Enable"},
        {"ADC Virtual Left2", NULL, "AIF Enable"},
@@ -1588,7 +1674,7 @@ static int twl4030_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (twl4030->master_substream) {
                twl4030->slave_substream = substream;
@@ -1619,7 +1705,7 @@ static void twl4030_shutdown(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (twl4030->master_substream == substream)
                twl4030->master_substream = twl4030->slave_substream;
@@ -1645,7 +1731,7 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 mode, old_mode, format, old_format;
 
         /* If the substream has 4 channel, do the necessary setup */
@@ -1765,7 +1851,7 @@ static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 19200000:
@@ -1880,7 +1966,7 @@ static int twl4030_voice_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
        u8 mode;
 
        /* If the system master clock is not 26MHz, the voice PCM interface is
@@ -1962,7 +2048,7 @@ static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct twl4030_priv *twl4030 = codec->private_data;
+       struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec);
 
        if (freq != 26000000) {
                dev_err(codec->dev, "Unsupported APLL mclk: %u, the Voice"
@@ -2108,7 +2194,6 @@ static int twl4030_soc_resume(struct platform_device *pdev)
        struct snd_soc_codec *codec = socdev->card->codec;
 
        twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       twl4030_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
@@ -2125,7 +2210,7 @@ static int twl4030_soc_probe(struct platform_device *pdev)
        BUG_ON(!twl4030_codec);
 
        codec = twl4030_codec;
-       twl4030 = codec->private_data;
+       twl4030 = snd_soc_codec_get_drvdata(codec);
        socdev->card->codec = codec;
 
        /* Configuration for headset ramp delay from setup data */
@@ -2188,7 +2273,7 @@ static int __devinit twl4030_codec_probe(struct platform_device *pdev)
        }
 
        codec = &twl4030->codec;
-       codec->private_data = twl4030;
+       snd_soc_codec_set_drvdata(codec, twl4030);
        codec->dev = &pdev->dev;
        twl4030_dai[0].dev = &pdev->dev;
        twl4030_dai[1].dev = &pdev->dev;
diff --git a/sound/soc/codecs/twl6040.c b/sound/soc/codecs/twl6040.c
new file mode 100644 (file)
index 0000000..af36346
--- /dev/null
@@ -0,0 +1,1246 @@
+/*
+ * ALSA SoC TWL6040 codec driver
+ *
+ * Author:      Misael Lopez Cruz <x0052729@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/i2c/twl.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/initval.h>
+#include <sound/tlv.h>
+
+#include "twl6040.h"
+
+#define TWL6040_RATES   (SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+#define TWL6040_FORMATS         (SNDRV_PCM_FMTBIT_S32_LE)
+
+/* codec private data */
+struct twl6040_data {
+       struct snd_soc_codec codec;
+       int audpwron;
+       int naudint;
+       int codec_powered;
+       int pll;
+       int non_lp;
+       unsigned int sysclk;
+       struct snd_pcm_hw_constraint_list *sysclk_constraints;
+       struct completion ready;
+};
+
+/*
+ * twl6040 register cache & default register settings
+ */
+static const u8 twl6040_reg[TWL6040_CACHEREGNUM] = {
+       0x00, /* not used               0x00    */
+       0x4B, /* TWL6040_ASICID (ro)    0x01    */
+       0x00, /* TWL6040_ASICREV (ro)   0x02    */
+       0x00, /* TWL6040_INTID          0x03    */
+       0x00, /* TWL6040_INTMR          0x04    */
+       0x00, /* TWL6040_NCPCTRL        0x05    */
+       0x00, /* TWL6040_LDOCTL         0x06    */
+       0x60, /* TWL6040_HPPLLCTL       0x07    */
+       0x00, /* TWL6040_LPPLLCTL       0x08    */
+       0x4A, /* TWL6040_LPPLLDIV       0x09    */
+       0x00, /* TWL6040_AMICBCTL       0x0A    */
+       0x00, /* TWL6040_DMICBCTL       0x0B    */
+       0x18, /* TWL6040_MICLCTL        0x0C    - No input selected on Left Mic */
+       0x18, /* TWL6040_MICRCTL        0x0D    - No input selected on Right Mic */
+       0x00, /* TWL6040_MICGAIN        0x0E    */
+       0x1B, /* TWL6040_LINEGAIN       0x0F    */
+       0x00, /* TWL6040_HSLCTL         0x10    */
+       0x00, /* TWL6040_HSRCTL         0x11    */
+       0x00, /* TWL6040_HSGAIN         0x12    */
+       0x00, /* TWL6040_EARCTL         0x13    */
+       0x00, /* TWL6040_HFLCTL         0x14    */
+       0x00, /* TWL6040_HFLGAIN        0x15    */
+       0x00, /* TWL6040_HFRCTL         0x16    */
+       0x00, /* TWL6040_HFRGAIN        0x17    */
+       0x00, /* TWL6040_VIBCTLL        0x18    */
+       0x00, /* TWL6040_VIBDATL        0x19    */
+       0x00, /* TWL6040_VIBCTLR        0x1A    */
+       0x00, /* TWL6040_VIBDATR        0x1B    */
+       0x00, /* TWL6040_HKCTL1         0x1C    */
+       0x00, /* TWL6040_HKCTL2         0x1D    */
+       0x00, /* TWL6040_GPOCTL         0x1E    */
+       0x00, /* TWL6040_ALB            0x1F    */
+       0x00, /* TWL6040_DLB            0x20    */
+       0x00, /* not used               0x21    */
+       0x00, /* not used               0x22    */
+       0x00, /* not used               0x23    */
+       0x00, /* not used               0x24    */
+       0x00, /* not used               0x25    */
+       0x00, /* not used               0x26    */
+       0x00, /* not used               0x27    */
+       0x00, /* TWL6040_TRIM1          0x28    */
+       0x00, /* TWL6040_TRIM2          0x29    */
+       0x00, /* TWL6040_TRIM3          0x2A    */
+       0x00, /* TWL6040_HSOTRIM        0x2B    */
+       0x00, /* TWL6040_HFOTRIM        0x2C    */
+       0x09, /* TWL6040_ACCCTL         0x2D    */
+       0x00, /* TWL6040_STATUS (ro)    0x2E    */
+};
+
+/*
+ * twl6040 vio/gnd registers:
+ * registers under vio/gnd supply can be accessed
+ * before the power-up sequence, after NRESPWRON goes high
+ */
+static const int twl6040_vio_reg[TWL6040_VIOREGNUM] = {
+       TWL6040_REG_ASICID,
+       TWL6040_REG_ASICREV,
+       TWL6040_REG_INTID,
+       TWL6040_REG_INTMR,
+       TWL6040_REG_NCPCTL,
+       TWL6040_REG_LDOCTL,
+       TWL6040_REG_AMICBCTL,
+       TWL6040_REG_DMICBCTL,
+       TWL6040_REG_HKCTL1,
+       TWL6040_REG_HKCTL2,
+       TWL6040_REG_GPOCTL,
+       TWL6040_REG_TRIM1,
+       TWL6040_REG_TRIM2,
+       TWL6040_REG_TRIM3,
+       TWL6040_REG_HSOTRIM,
+       TWL6040_REG_HFOTRIM,
+       TWL6040_REG_ACCCTL,
+       TWL6040_REG_STATUS,
+};
+
+/*
+ * twl6040 vdd/vss registers:
+ * registers under vdd/vss supplies can only be accessed
+ * after the power-up sequence
+ */
+static const int twl6040_vdd_reg[TWL6040_VDDREGNUM] = {
+       TWL6040_REG_HPPLLCTL,
+       TWL6040_REG_LPPLLCTL,
+       TWL6040_REG_LPPLLDIV,
+       TWL6040_REG_MICLCTL,
+       TWL6040_REG_MICRCTL,
+       TWL6040_REG_MICGAIN,
+       TWL6040_REG_LINEGAIN,
+       TWL6040_REG_HSLCTL,
+       TWL6040_REG_HSRCTL,
+       TWL6040_REG_HSGAIN,
+       TWL6040_REG_EARCTL,
+       TWL6040_REG_HFLCTL,
+       TWL6040_REG_HFLGAIN,
+       TWL6040_REG_HFRCTL,
+       TWL6040_REG_HFRGAIN,
+       TWL6040_REG_VIBCTLL,
+       TWL6040_REG_VIBDATL,
+       TWL6040_REG_VIBCTLR,
+       TWL6040_REG_VIBDATR,
+       TWL6040_REG_ALB,
+       TWL6040_REG_DLB,
+};
+
+/*
+ * read twl6040 register cache
+ */
+static inline unsigned int twl6040_read_reg_cache(struct snd_soc_codec *codec,
+                                               unsigned int reg)
+{
+       u8 *cache = codec->reg_cache;
+
+       if (reg >= TWL6040_CACHEREGNUM)
+               return -EIO;
+
+       return cache[reg];
+}
+
+/*
+ * write twl6040 register cache
+ */
+static inline void twl6040_write_reg_cache(struct snd_soc_codec *codec,
+                                               u8 reg, u8 value)
+{
+       u8 *cache = codec->reg_cache;
+
+       if (reg >= TWL6040_CACHEREGNUM)
+               return;
+       cache[reg] = value;
+}
+
+/*
+ * read from twl6040 hardware register
+ */
+static int twl6040_read_reg_volatile(struct snd_soc_codec *codec,
+                       unsigned int reg)
+{
+       u8 value;
+
+       if (reg >= TWL6040_CACHEREGNUM)
+               return -EIO;
+
+       twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &value, reg);
+       twl6040_write_reg_cache(codec, reg, value);
+
+       return value;
+}
+
+/*
+ * write to the twl6040 register space
+ */
+static int twl6040_write(struct snd_soc_codec *codec,
+                       unsigned int reg, unsigned int value)
+{
+       if (reg >= TWL6040_CACHEREGNUM)
+               return -EIO;
+
+       twl6040_write_reg_cache(codec, reg, value);
+       return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg);
+}
+
+static void twl6040_init_vio_regs(struct snd_soc_codec *codec)
+{
+       u8 *cache = codec->reg_cache;
+       int reg, i;
+
+       /* allow registers to be accessed by i2c */
+       twl6040_write(codec, TWL6040_REG_ACCCTL, cache[TWL6040_REG_ACCCTL]);
+
+       for (i = 0; i < TWL6040_VIOREGNUM; i++) {
+               reg = twl6040_vio_reg[i];
+               /* skip read-only registers (ASICID, ASICREV, STATUS) */
+               switch (reg) {
+               case TWL6040_REG_ASICID:
+               case TWL6040_REG_ASICREV:
+               case TWL6040_REG_STATUS:
+                       continue;
+               default:
+                       break;
+               }
+               twl6040_write(codec, reg, cache[reg]);
+       }
+}
+
+static void twl6040_init_vdd_regs(struct snd_soc_codec *codec)
+{
+       u8 *cache = codec->reg_cache;
+       int reg, i;
+
+       for (i = 0; i < TWL6040_VDDREGNUM; i++) {
+               reg = twl6040_vdd_reg[i];
+               twl6040_write(codec, reg, cache[reg]);
+       }
+}
+
+/* twl6040 codec manual power-up sequence */
+static void twl6040_power_up(struct snd_soc_codec *codec)
+{
+       u8 ncpctl, ldoctl, lppllctl, accctl;
+
+       ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL);
+       ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL);
+       lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
+       accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL);
+
+       /* enable reference system */
+       ldoctl |= TWL6040_REFENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       msleep(10);
+       /* enable internal oscillator */
+       ldoctl |= TWL6040_OSCENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(10);
+       /* enable high-side ldo */
+       ldoctl |= TWL6040_HSLDOENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(244);
+       /* enable negative charge pump */
+       ncpctl |= TWL6040_NCPENA | TWL6040_NCPOPEN;
+       twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl);
+       udelay(488);
+       /* enable low-side ldo */
+       ldoctl |= TWL6040_LSLDOENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(244);
+       /* enable low-power pll */
+       lppllctl |= TWL6040_LPLLENA;
+       twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+       /* reset state machine */
+       accctl |= TWL6040_RESETSPLIT;
+       twl6040_write(codec, TWL6040_REG_ACCCTL, accctl);
+       mdelay(5);
+       accctl &= ~TWL6040_RESETSPLIT;
+       twl6040_write(codec, TWL6040_REG_ACCCTL, accctl);
+       /* disable internal oscillator */
+       ldoctl &= ~TWL6040_OSCENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+}
+
+/* twl6040 codec manual power-down sequence */
+static void twl6040_power_down(struct snd_soc_codec *codec)
+{
+       u8 ncpctl, ldoctl, lppllctl, accctl;
+
+       ncpctl = twl6040_read_reg_cache(codec, TWL6040_REG_NCPCTL);
+       ldoctl = twl6040_read_reg_cache(codec, TWL6040_REG_LDOCTL);
+       lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
+       accctl = twl6040_read_reg_cache(codec, TWL6040_REG_ACCCTL);
+
+       /* enable internal oscillator */
+       ldoctl |= TWL6040_OSCENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(10);
+       /* disable low-power pll */
+       lppllctl &= ~TWL6040_LPLLENA;
+       twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+       /* disable low-side ldo */
+       ldoctl &= ~TWL6040_LSLDOENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(244);
+       /* disable negative charge pump */
+       ncpctl &= ~(TWL6040_NCPENA | TWL6040_NCPOPEN);
+       twl6040_write(codec, TWL6040_REG_NCPCTL, ncpctl);
+       udelay(488);
+       /* disable high-side ldo */
+       ldoctl &= ~TWL6040_HSLDOENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       udelay(244);
+       /* disable internal oscillator */
+       ldoctl &= ~TWL6040_OSCENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       /* disable reference system */
+       ldoctl &= ~TWL6040_REFENA;
+       twl6040_write(codec, TWL6040_REG_LDOCTL, ldoctl);
+       msleep(10);
+}
+
+/* set headset dac and driver power mode */
+static int headset_power_mode(struct snd_soc_codec *codec, int high_perf)
+{
+       int hslctl, hsrctl;
+       int mask = TWL6040_HSDRVMODEL | TWL6040_HSDACMODEL;
+
+       hslctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSLCTL);
+       hsrctl = twl6040_read_reg_cache(codec, TWL6040_REG_HSRCTL);
+
+       if (high_perf) {
+               hslctl &= ~mask;
+               hsrctl &= ~mask;
+       } else {
+               hslctl |= mask;
+               hsrctl |= mask;
+       }
+
+       twl6040_write(codec, TWL6040_REG_HSLCTL, hslctl);
+       twl6040_write(codec, TWL6040_REG_HSRCTL, hsrctl);
+
+       return 0;
+}
+
+static int twl6040_power_mode_event(struct snd_soc_dapm_widget *w,
+                       struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+
+       if (SND_SOC_DAPM_EVENT_ON(event))
+               priv->non_lp++;
+       else
+               priv->non_lp--;
+
+       return 0;
+}
+
+/* audio interrupt handler */
+static irqreturn_t twl6040_naudint_handler(int irq, void *data)
+{
+       struct snd_soc_codec *codec = data;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+       u8 intid;
+
+       twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &intid, TWL6040_REG_INTID);
+
+       switch (intid) {
+       case TWL6040_THINT:
+               dev_alert(codec->dev, "die temp over-limit detection\n");
+               break;
+       case TWL6040_PLUGINT:
+       case TWL6040_UNPLUGINT:
+       case TWL6040_HOOKINT:
+               break;
+       case TWL6040_HFINT:
+               dev_alert(codec->dev, "hf drivers over current detection\n");
+               break;
+       case TWL6040_VIBINT:
+               dev_alert(codec->dev, "vib drivers over current detection\n");
+               break;
+       case TWL6040_READYINT:
+               complete(&priv->ready);
+               break;
+       default:
+               dev_err(codec->dev, "unknown audio interrupt %d\n", intid);
+               break;
+       }
+
+       return IRQ_HANDLED;
+}
+
+/*
+ * MICATT volume control:
+ * from -6 to 0 dB in 6 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(mic_preamp_tlv, -600, 600, 0);
+
+/*
+ * MICGAIN volume control:
+ * from 6 to 30 dB in 6 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(mic_amp_tlv, 600, 600, 0);
+
+/*
+ * HSGAIN volume control:
+ * from -30 to 0 dB in 2 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(hs_tlv, -3000, 200, 0);
+
+/*
+ * HFGAIN volume control:
+ * from -52 to 6 dB in 2 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(hf_tlv, -5200, 200, 0);
+
+/*
+ * EPGAIN volume control:
+ * from -24 to 6 dB in 2 dB steps
+ */
+static DECLARE_TLV_DB_SCALE(ep_tlv, -2400, 200, 0);
+
+/* Left analog microphone selection */
+static const char *twl6040_amicl_texts[] =
+       {"Headset Mic", "Main Mic", "Aux/FM Left", "Off"};
+
+/* Right analog microphone selection */
+static const char *twl6040_amicr_texts[] =
+       {"Headset Mic", "Sub Mic", "Aux/FM Right", "Off"};
+
+static const struct soc_enum twl6040_enum[] = {
+       SOC_ENUM_SINGLE(TWL6040_REG_MICLCTL, 3, 3, twl6040_amicl_texts),
+       SOC_ENUM_SINGLE(TWL6040_REG_MICRCTL, 3, 3, twl6040_amicr_texts),
+};
+
+static const struct snd_kcontrol_new amicl_control =
+       SOC_DAPM_ENUM("Route", twl6040_enum[0]);
+
+static const struct snd_kcontrol_new amicr_control =
+       SOC_DAPM_ENUM("Route", twl6040_enum[1]);
+
+/* Headset DAC playback switches */
+static const struct snd_kcontrol_new hsdacl_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSLCTL, 5, 1, 0);
+
+static const struct snd_kcontrol_new hsdacr_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSRCTL, 5, 1, 0);
+
+/* Handsfree DAC playback switches */
+static const struct snd_kcontrol_new hfdacl_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 2, 1, 0);
+
+static const struct snd_kcontrol_new hfdacr_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 2, 1, 0);
+
+/* Headset driver switches */
+static const struct snd_kcontrol_new hsl_driver_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSLCTL, 2, 1, 0);
+
+static const struct snd_kcontrol_new hsr_driver_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HSRCTL, 2, 1, 0);
+
+/* Handsfree driver switches */
+static const struct snd_kcontrol_new hfl_driver_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFLCTL, 4, 1, 0);
+
+static const struct snd_kcontrol_new hfr_driver_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_HFRCTL, 4, 1, 0);
+
+static const struct snd_kcontrol_new ep_driver_switch_controls =
+       SOC_DAPM_SINGLE("Switch", TWL6040_REG_EARCTL, 0, 1, 0);
+
+static const struct snd_kcontrol_new twl6040_snd_controls[] = {
+       /* Capture gains */
+       SOC_DOUBLE_TLV("Capture Preamplifier Volume",
+               TWL6040_REG_MICGAIN, 6, 7, 1, 1, mic_preamp_tlv),
+       SOC_DOUBLE_TLV("Capture Volume",
+               TWL6040_REG_MICGAIN, 0, 3, 4, 0, mic_amp_tlv),
+
+       /* Playback gains */
+       SOC_DOUBLE_TLV("Headset Playback Volume",
+               TWL6040_REG_HSGAIN, 0, 4, 0xF, 1, hs_tlv),
+       SOC_DOUBLE_R_TLV("Handsfree Playback Volume",
+               TWL6040_REG_HFLGAIN, TWL6040_REG_HFRGAIN, 0, 0x1D, 1, hf_tlv),
+       SOC_SINGLE_TLV("Earphone Playback Volume",
+               TWL6040_REG_EARCTL, 1, 0xF, 1, ep_tlv),
+};
+
+static const struct snd_soc_dapm_widget twl6040_dapm_widgets[] = {
+       /* Inputs */
+       SND_SOC_DAPM_INPUT("MAINMIC"),
+       SND_SOC_DAPM_INPUT("HSMIC"),
+       SND_SOC_DAPM_INPUT("SUBMIC"),
+       SND_SOC_DAPM_INPUT("AFML"),
+       SND_SOC_DAPM_INPUT("AFMR"),
+
+       /* Outputs */
+       SND_SOC_DAPM_OUTPUT("HSOL"),
+       SND_SOC_DAPM_OUTPUT("HSOR"),
+       SND_SOC_DAPM_OUTPUT("HFL"),
+       SND_SOC_DAPM_OUTPUT("HFR"),
+       SND_SOC_DAPM_OUTPUT("EP"),
+
+       /* Analog input muxes for the capture amplifiers */
+       SND_SOC_DAPM_MUX("Analog Left Capture Route",
+                       SND_SOC_NOPM, 0, 0, &amicl_control),
+       SND_SOC_DAPM_MUX("Analog Right Capture Route",
+                       SND_SOC_NOPM, 0, 0, &amicr_control),
+
+       /* Analog capture PGAs */
+       SND_SOC_DAPM_PGA("MicAmpL",
+                       TWL6040_REG_MICLCTL, 0, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("MicAmpR",
+                       TWL6040_REG_MICRCTL, 0, 0, NULL, 0),
+
+       /* ADCs */
+       SND_SOC_DAPM_ADC("ADC Left", "Left Front Capture",
+                       TWL6040_REG_MICLCTL, 2, 0),
+       SND_SOC_DAPM_ADC("ADC Right", "Right Front Capture",
+                       TWL6040_REG_MICRCTL, 2, 0),
+
+       /* Microphone bias */
+       SND_SOC_DAPM_MICBIAS("Headset Mic Bias",
+                       TWL6040_REG_AMICBCTL, 0, 0),
+       SND_SOC_DAPM_MICBIAS("Main Mic Bias",
+                       TWL6040_REG_AMICBCTL, 4, 0),
+       SND_SOC_DAPM_MICBIAS("Digital Mic1 Bias",
+                       TWL6040_REG_DMICBCTL, 0, 0),
+       SND_SOC_DAPM_MICBIAS("Digital Mic2 Bias",
+                       TWL6040_REG_DMICBCTL, 4, 0),
+
+       /* DACs */
+       SND_SOC_DAPM_DAC("HSDAC Left", "Headset Playback",
+                       TWL6040_REG_HSLCTL, 0, 0),
+       SND_SOC_DAPM_DAC("HSDAC Right", "Headset Playback",
+                       TWL6040_REG_HSRCTL, 0, 0),
+       SND_SOC_DAPM_DAC_E("HFDAC Left", "Handsfree Playback",
+                       TWL6040_REG_HFLCTL, 0, 0,
+                       twl6040_power_mode_event,
+                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_DAC_E("HFDAC Right", "Handsfree Playback",
+                       TWL6040_REG_HFRCTL, 0, 0,
+                       twl6040_power_mode_event,
+                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+       /* Analog playback switches */
+       SND_SOC_DAPM_SWITCH("HSDAC Left Playback",
+                       SND_SOC_NOPM, 0, 0, &hsdacl_switch_controls),
+       SND_SOC_DAPM_SWITCH("HSDAC Right Playback",
+                       SND_SOC_NOPM, 0, 0, &hsdacr_switch_controls),
+       SND_SOC_DAPM_SWITCH("HFDAC Left Playback",
+                       SND_SOC_NOPM, 0, 0, &hfdacl_switch_controls),
+       SND_SOC_DAPM_SWITCH("HFDAC Right Playback",
+                       SND_SOC_NOPM, 0, 0, &hfdacr_switch_controls),
+
+       SND_SOC_DAPM_SWITCH("Headset Left Driver",
+                       SND_SOC_NOPM, 0, 0, &hsl_driver_switch_controls),
+       SND_SOC_DAPM_SWITCH("Headset Right Driver",
+                       SND_SOC_NOPM, 0, 0, &hsr_driver_switch_controls),
+       SND_SOC_DAPM_SWITCH_E("Handsfree Left Driver",
+                       SND_SOC_NOPM, 0, 0, &hfl_driver_switch_controls,
+                       twl6040_power_mode_event,
+                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_SWITCH_E("Handsfree Right Driver",
+                       SND_SOC_NOPM, 0, 0, &hfr_driver_switch_controls,
+                       twl6040_power_mode_event,
+                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+       SND_SOC_DAPM_SWITCH_E("Earphone Driver",
+                       SND_SOC_NOPM, 0, 0, &ep_driver_switch_controls,
+                       twl6040_power_mode_event,
+                       SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
+
+       /* Analog playback PGAs */
+       SND_SOC_DAPM_PGA("HFDAC Left PGA",
+                       TWL6040_REG_HFLCTL, 1, 0, NULL, 0),
+       SND_SOC_DAPM_PGA("HFDAC Right PGA",
+                       TWL6040_REG_HFRCTL, 1, 0, NULL, 0),
+
+};
+
+static const struct snd_soc_dapm_route intercon[] = {
+       /* Capture path */
+       {"Analog Left Capture Route", "Headset Mic", "HSMIC"},
+       {"Analog Left Capture Route", "Main Mic", "MAINMIC"},
+       {"Analog Left Capture Route", "Aux/FM Left", "AFML"},
+
+       {"Analog Right Capture Route", "Headset Mic", "HSMIC"},
+       {"Analog Right Capture Route", "Sub Mic", "SUBMIC"},
+       {"Analog Right Capture Route", "Aux/FM Right", "AFMR"},
+
+       {"MicAmpL", NULL, "Analog Left Capture Route"},
+       {"MicAmpR", NULL, "Analog Right Capture Route"},
+
+       {"ADC Left", NULL, "MicAmpL"},
+       {"ADC Right", NULL, "MicAmpR"},
+
+       /* Headset playback path */
+       {"HSDAC Left Playback", "Switch", "HSDAC Left"},
+       {"HSDAC Right Playback", "Switch", "HSDAC Right"},
+
+       {"Headset Left Driver", "Switch", "HSDAC Left Playback"},
+       {"Headset Right Driver", "Switch", "HSDAC Right Playback"},
+
+       {"HSOL", NULL, "Headset Left Driver"},
+       {"HSOR", NULL, "Headset Right Driver"},
+
+       /* Earphone playback path */
+       {"Earphone Driver", "Switch", "HSDAC Left"},
+       {"EP", NULL, "Earphone Driver"},
+
+       /* Handsfree playback path */
+       {"HFDAC Left Playback", "Switch", "HFDAC Left"},
+       {"HFDAC Right Playback", "Switch", "HFDAC Right"},
+
+       {"HFDAC Left PGA", NULL, "HFDAC Left Playback"},
+       {"HFDAC Right PGA", NULL, "HFDAC Right Playback"},
+
+       {"Handsfree Left Driver", "Switch", "HFDAC Left PGA"},
+       {"Handsfree Right Driver", "Switch", "HFDAC Right PGA"},
+
+       {"HFL", NULL, "Handsfree Left Driver"},
+       {"HFR", NULL, "Handsfree Right Driver"},
+};
+
+static int twl6040_add_widgets(struct snd_soc_codec *codec)
+{
+       snd_soc_dapm_new_controls(codec, twl6040_dapm_widgets,
+                                ARRAY_SIZE(twl6040_dapm_widgets));
+
+       snd_soc_dapm_add_routes(codec, intercon, ARRAY_SIZE(intercon));
+
+       snd_soc_dapm_new_widgets(codec);
+
+       return 0;
+}
+
+static int twl6040_power_up_completion(struct snd_soc_codec *codec,
+                                       int naudint)
+{
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+       int time_left;
+       u8 intid;
+
+       time_left = wait_for_completion_timeout(&priv->ready,
+                               msecs_to_jiffies(48));
+
+       if (!time_left) {
+               twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &intid,
+                                                       TWL6040_REG_INTID);
+               if (!(intid & TWL6040_READYINT)) {
+                       dev_err(codec->dev, "timeout waiting for READYINT\n");
+                       return -ETIMEDOUT;
+               }
+       }
+
+       priv->codec_powered = 1;
+
+       return 0;
+}
+
+static int twl6040_set_bias_level(struct snd_soc_codec *codec,
+                               enum snd_soc_bias_level level)
+{
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+       int audpwron = priv->audpwron;
+       int naudint = priv->naudint;
+       int ret;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               if (priv->codec_powered)
+                       break;
+
+               if (gpio_is_valid(audpwron)) {
+                       /* use AUDPWRON line */
+                       gpio_set_value(audpwron, 1);
+
+                       /* wait for power-up completion */
+                       ret = twl6040_power_up_completion(codec, naudint);
+                       if (ret)
+                               return ret;
+
+                       /* sync registers updated during power-up sequence */
+                       twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL);
+                       twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL);
+                       twl6040_read_reg_volatile(codec, TWL6040_REG_LPPLLCTL);
+               } else {
+                       /* use manual power-up sequence */
+                       twl6040_power_up(codec);
+                       priv->codec_powered = 1;
+               }
+
+               /* initialize vdd/vss registers with reg_cache */
+               twl6040_init_vdd_regs(codec);
+               break;
+       case SND_SOC_BIAS_OFF:
+               if (!priv->codec_powered)
+                       break;
+
+               if (gpio_is_valid(audpwron)) {
+                       /* use AUDPWRON line */
+                       gpio_set_value(audpwron, 0);
+
+                       /* power-down sequence latency */
+                       udelay(500);
+
+                       /* sync registers updated during power-down sequence */
+                       twl6040_read_reg_volatile(codec, TWL6040_REG_NCPCTL);
+                       twl6040_read_reg_volatile(codec, TWL6040_REG_LDOCTL);
+                       twl6040_write_reg_cache(codec, TWL6040_REG_LPPLLCTL,
+                                               0x00);
+               } else {
+                       /* use manual power-down sequence */
+                       twl6040_power_down(codec);
+               }
+
+               priv->codec_powered = 0;
+               break;
+       }
+
+       codec->bias_level = level;
+
+       return 0;
+}
+
+/* set of rates for each pll: low-power and high-performance */
+
+static unsigned int lp_rates[] = {
+       88200,
+       96000,
+};
+
+static struct snd_pcm_hw_constraint_list lp_constraints = {
+       .count  = ARRAY_SIZE(lp_rates),
+       .list   = lp_rates,
+};
+
+static unsigned int hp_rates[] = {
+       96000,
+};
+
+static struct snd_pcm_hw_constraint_list hp_constraints = {
+       .count  = ARRAY_SIZE(hp_rates),
+       .list   = hp_rates,
+};
+
+static int twl6040_startup(struct snd_pcm_substream *substream,
+                       struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+
+       if (!priv->sysclk) {
+               dev_err(codec->dev,
+                       "no mclk configured, call set_sysclk() on init\n");
+               return -EINVAL;
+       }
+
+       /*
+        * capture is not supported at 17.64 MHz,
+        * it's reserved for headset low-power playback scenario
+        */
+       if ((priv->sysclk == 17640000) && substream->stream) {
+               dev_err(codec->dev,
+                       "capture mode is not supported at %dHz\n",
+                       priv->sysclk);
+               return -EINVAL;
+       }
+
+       snd_pcm_hw_constraint_list(substream->runtime, 0,
+                               SNDRV_PCM_HW_PARAM_RATE,
+                               priv->sysclk_constraints);
+
+       return 0;
+}
+
+static int twl6040_hw_params(struct snd_pcm_substream *substream,
+                       struct snd_pcm_hw_params *params,
+                       struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+       u8 lppllctl;
+       int rate;
+
+       /* nothing to do for high-perf pll, it supports only 48 kHz */
+       if (priv->pll == TWL6040_HPPLL_ID)
+               return 0;
+
+       lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
+
+       rate = params_rate(params);
+       switch (rate) {
+       case 88200:
+               lppllctl |= TWL6040_LPLLFIN;
+               priv->sysclk = 17640000;
+               break;
+       case 96000:
+               lppllctl &= ~TWL6040_LPLLFIN;
+               priv->sysclk = 19200000;
+               break;
+       default:
+               dev_err(codec->dev, "unsupported rate %d\n", rate);
+               return -EINVAL;
+       }
+
+       twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+
+       return 0;
+}
+
+static int twl6040_trigger(struct snd_pcm_substream *substream,
+                       int cmd, struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+               /*
+                * low-power playback mode is restricted
+                * for headset path only
+                */
+               if ((priv->sysclk == 17640000) && priv->non_lp) {
+                       dev_err(codec->dev,
+                               "some enabled paths aren't supported at %dHz\n",
+                               priv->sysclk);
+                       return -EPERM;
+               }
+               break;
+       default:
+               break;
+       }
+
+       return 0;
+}
+
+static int twl6040_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+               int clk_id, unsigned int freq, int dir)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(codec);
+       u8 hppllctl, lppllctl;
+
+       hppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_HPPLLCTL);
+       lppllctl = twl6040_read_reg_cache(codec, TWL6040_REG_LPPLLCTL);
+
+       switch (clk_id) {
+       case TWL6040_SYSCLK_SEL_LPPLL:
+               switch (freq) {
+               case 32768:
+                       /* headset dac and driver must be in low-power mode */
+                       headset_power_mode(codec, 0);
+
+                       /* clk32k input requires low-power pll */
+                       lppllctl |= TWL6040_LPLLENA;
+                       twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+                       mdelay(5);
+                       lppllctl &= ~TWL6040_HPLLSEL;
+                       twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+                       hppllctl &= ~TWL6040_HPLLENA;
+                       twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl);
+                       break;
+               default:
+                       dev_err(codec->dev, "unknown mclk freq %d\n", freq);
+                       return -EINVAL;
+               }
+
+               /* lppll divider */
+               switch (priv->sysclk) {
+               case 17640000:
+                       lppllctl |= TWL6040_LPLLFIN;
+                       break;
+               case 19200000:
+                       lppllctl &= ~TWL6040_LPLLFIN;
+                       break;
+               default:
+                       /* sysclk not yet configured */
+                       lppllctl &= ~TWL6040_LPLLFIN;
+                       priv->sysclk = 19200000;
+                       break;
+               }
+
+               twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+
+               priv->pll = TWL6040_LPPLL_ID;
+               priv->sysclk_constraints = &lp_constraints;
+               break;
+       case TWL6040_SYSCLK_SEL_HPPLL:
+               hppllctl &= ~TWL6040_MCLK_MSK;
+
+               switch (freq) {
+               case 12000000:
+                       /* mclk input, pll enabled */
+                       hppllctl |= TWL6040_MCLK_12000KHZ |
+                                   TWL6040_HPLLSQRBP |
+                                   TWL6040_HPLLENA;
+                       break;
+               case 19200000:
+                       /* mclk input, pll disabled */
+                       hppllctl |= TWL6040_MCLK_19200KHZ |
+                                   TWL6040_HPLLSQRBP |
+                                   TWL6040_HPLLBP;
+                       break;
+               case 26000000:
+                       /* mclk input, pll enabled */
+                       hppllctl |= TWL6040_MCLK_26000KHZ |
+                                   TWL6040_HPLLSQRBP |
+                                   TWL6040_HPLLENA;
+                       break;
+               case 38400000:
+                       /* clk slicer, pll disabled */
+                       hppllctl |= TWL6040_MCLK_38400KHZ |
+                                   TWL6040_HPLLSQRENA |
+                                   TWL6040_HPLLBP;
+                       break;
+               default:
+                       dev_err(codec->dev, "unknown mclk freq %d\n", freq);
+                       return -EINVAL;
+               }
+
+               /* headset dac and driver must be in high-performance mode */
+               headset_power_mode(codec, 1);
+
+               twl6040_write(codec, TWL6040_REG_HPPLLCTL, hppllctl);
+               udelay(500);
+               lppllctl |= TWL6040_HPLLSEL;
+               twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+               lppllctl &= ~TWL6040_LPLLENA;
+               twl6040_write(codec, TWL6040_REG_LPPLLCTL, lppllctl);
+
+               /* high-performance pll can provide only 19.2 MHz */
+               priv->pll = TWL6040_HPPLL_ID;
+               priv->sysclk = 19200000;
+               priv->sysclk_constraints = &hp_constraints;
+               break;
+       default:
+               dev_err(codec->dev, "unknown clk_id %d\n", clk_id);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct snd_soc_dai_ops twl6040_dai_ops = {
+       .startup        = twl6040_startup,
+       .hw_params      = twl6040_hw_params,
+       .trigger        = twl6040_trigger,
+       .set_sysclk     = twl6040_set_dai_sysclk,
+};
+
+struct snd_soc_dai twl6040_dai = {
+       .name = "twl6040",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 4,
+               .rates = TWL6040_RATES,
+               .formats = TWL6040_FORMATS,
+       },
+       .capture = {
+               .stream_name = "Capture",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = TWL6040_RATES,
+               .formats = TWL6040_FORMATS,
+       },
+       .ops = &twl6040_dai_ops,
+};
+EXPORT_SYMBOL_GPL(twl6040_dai);
+
+#ifdef CONFIG_PM
+static int twl6040_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       return 0;
+}
+
+static int twl6040_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       return 0;
+}
+#else
+#define twl6040_suspend NULL
+#define twl6040_resume NULL
+#endif
+
+static struct snd_soc_codec *twl6040_codec;
+
+static int twl6040_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       BUG_ON(!twl6040_codec);
+
+       codec = twl6040_codec;
+       socdev->card->codec = codec;
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed to create pcms\n");
+               return ret;
+       }
+
+       snd_soc_add_controls(codec, twl6040_snd_controls,
+                               ARRAY_SIZE(twl6040_snd_controls));
+       twl6040_add_widgets(codec);
+
+       if (ret < 0) {
+               dev_err(&pdev->dev, "failed to register card\n");
+               goto card_err;
+       }
+
+       return ret;
+
+card_err:
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+       return ret;
+}
+
+static int twl6040_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+       kfree(codec);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_twl6040 = {
+       .probe = twl6040_probe,
+       .remove = twl6040_remove,
+       .suspend = twl6040_suspend,
+       .resume = twl6040_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_twl6040);
+
+static int __devinit twl6040_codec_probe(struct platform_device *pdev)
+{
+       struct twl4030_codec_data *twl_codec = pdev->dev.platform_data;
+       struct snd_soc_codec *codec;
+       struct twl6040_data *priv;
+       int audpwron, naudint;
+       int ret = 0;
+
+       priv = kzalloc(sizeof(struct twl6040_data), GFP_KERNEL);
+       if (priv == NULL)
+               return -ENOMEM;
+
+       if (twl_codec) {
+               audpwron = twl_codec->audpwron_gpio;
+               naudint = twl_codec->naudint_irq;
+       } else {
+               audpwron = -EINVAL;
+               naudint = 0;
+       }
+
+       priv->audpwron = audpwron;
+       priv->naudint = naudint;
+
+       codec = &priv->codec;
+       codec->dev = &pdev->dev;
+       twl6040_dai.dev = &pdev->dev;
+
+       codec->name = "twl6040";
+       codec->owner = THIS_MODULE;
+       codec->read = twl6040_read_reg_cache;
+       codec->write = twl6040_write;
+       codec->set_bias_level = twl6040_set_bias_level;
+       snd_soc_codec_set_drvdata(codec, priv);
+       codec->dai = &twl6040_dai;
+       codec->num_dai = 1;
+       codec->reg_cache_size = ARRAY_SIZE(twl6040_reg);
+       codec->reg_cache = kmemdup(twl6040_reg, sizeof(twl6040_reg),
+                                       GFP_KERNEL);
+       if (codec->reg_cache == NULL) {
+               ret = -ENOMEM;
+               goto cache_err;
+       }
+
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+       init_completion(&priv->ready);
+
+       if (gpio_is_valid(audpwron)) {
+               ret = gpio_request(audpwron, "audpwron");
+               if (ret)
+                       goto gpio1_err;
+
+               ret = gpio_direction_output(audpwron, 0);
+               if (ret)
+                       goto gpio2_err;
+
+               priv->codec_powered = 0;
+       }
+
+       if (naudint) {
+               /* audio interrupt */
+               ret = request_threaded_irq(naudint, NULL,
+                               twl6040_naudint_handler,
+                               IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+                               "twl6040_codec", codec);
+               if (ret)
+                       goto gpio2_err;
+       } else {
+               if (gpio_is_valid(audpwron)) {
+                       /* enable only codec ready interrupt */
+                       twl6040_write_reg_cache(codec, TWL6040_REG_INTMR,
+                                       ~TWL6040_READYMSK & TWL6040_ALLINT_MSK);
+               } else {
+                       /* no interrupts at all */
+                       twl6040_write_reg_cache(codec, TWL6040_REG_INTMR,
+                                               TWL6040_ALLINT_MSK);
+               }
+       }
+
+       /* init vio registers */
+       twl6040_init_vio_regs(codec);
+
+       /* power on device */
+       ret = twl6040_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       if (ret)
+               goto irq_err;
+
+       ret = snd_soc_register_codec(codec);
+       if (ret)
+               goto reg_err;
+
+       twl6040_codec = codec;
+
+       ret = snd_soc_register_dai(&twl6040_dai);
+       if (ret)
+               goto dai_err;
+
+       return 0;
+
+dai_err:
+       snd_soc_unregister_codec(codec);
+       twl6040_codec = NULL;
+reg_err:
+       twl6040_set_bias_level(codec, SND_SOC_BIAS_OFF);
+irq_err:
+       if (naudint)
+               free_irq(naudint, codec);
+gpio2_err:
+       if (gpio_is_valid(audpwron))
+               gpio_free(audpwron);
+gpio1_err:
+       kfree(codec->reg_cache);
+cache_err:
+       kfree(priv);
+       return ret;
+}
+
+static int __devexit twl6040_codec_remove(struct platform_device *pdev)
+{
+       struct twl6040_data *priv = snd_soc_codec_get_drvdata(twl6040_codec);
+       int audpwron = priv->audpwron;
+       int naudint = priv->naudint;
+
+       if (gpio_is_valid(audpwron))
+               gpio_free(audpwron);
+
+       if (naudint)
+               free_irq(naudint, twl6040_codec);
+
+       snd_soc_unregister_dai(&twl6040_dai);
+       snd_soc_unregister_codec(twl6040_codec);
+
+       kfree(twl6040_codec);
+       twl6040_codec = NULL;
+
+       return 0;
+}
+
+static struct platform_driver twl6040_codec_driver = {
+       .driver = {
+               .name = "twl6040_codec",
+               .owner = THIS_MODULE,
+       },
+       .probe = twl6040_codec_probe,
+       .remove = __devexit_p(twl6040_codec_remove),
+};
+
+static int __init twl6040_codec_init(void)
+{
+       return platform_driver_register(&twl6040_codec_driver);
+}
+module_init(twl6040_codec_init);
+
+static void __exit twl6040_codec_exit(void)
+{
+       platform_driver_unregister(&twl6040_codec_driver);
+}
+module_exit(twl6040_codec_exit);
+
+MODULE_DESCRIPTION("ASoC TWL6040 codec driver");
+MODULE_AUTHOR("Misael Lopez Cruz");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/twl6040.h b/sound/soc/codecs/twl6040.h
new file mode 100644 (file)
index 0000000..c472070
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * ALSA SoC TWL6040 codec driver
+ *
+ * Author:     Misael Lopez Cruz <x0052729@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#ifndef __TWL6040_H__
+#define __TWL6040_H__
+
+#define TWL6040_REG_ASICID             0x01
+#define TWL6040_REG_ASICREV            0x02
+#define TWL6040_REG_INTID              0x03
+#define TWL6040_REG_INTMR              0x04
+#define TWL6040_REG_NCPCTL             0x05
+#define TWL6040_REG_LDOCTL             0x06
+#define TWL6040_REG_HPPLLCTL           0x07
+#define TWL6040_REG_LPPLLCTL           0x08
+#define TWL6040_REG_LPPLLDIV           0x09
+#define TWL6040_REG_AMICBCTL           0x0A
+#define TWL6040_REG_DMICBCTL           0x0B
+#define TWL6040_REG_MICLCTL            0x0C
+#define TWL6040_REG_MICRCTL            0x0D
+#define TWL6040_REG_MICGAIN            0x0E
+#define TWL6040_REG_LINEGAIN           0x0F
+#define TWL6040_REG_HSLCTL             0x10
+#define TWL6040_REG_HSRCTL             0x11
+#define TWL6040_REG_HSGAIN             0x12
+#define TWL6040_REG_EARCTL             0x13
+#define TWL6040_REG_HFLCTL             0x14
+#define TWL6040_REG_HFLGAIN            0x15
+#define TWL6040_REG_HFRCTL             0x16
+#define TWL6040_REG_HFRGAIN            0x17
+#define TWL6040_REG_VIBCTLL            0x18
+#define TWL6040_REG_VIBDATL            0x19
+#define TWL6040_REG_VIBCTLR            0x1A
+#define TWL6040_REG_VIBDATR            0x1B
+#define TWL6040_REG_HKCTL1             0x1C
+#define TWL6040_REG_HKCTL2             0x1D
+#define TWL6040_REG_GPOCTL             0x1E
+#define TWL6040_REG_ALB                        0x1F
+#define TWL6040_REG_DLB                        0x20
+#define TWL6040_REG_TRIM1              0x28
+#define TWL6040_REG_TRIM2              0x29
+#define TWL6040_REG_TRIM3              0x2A
+#define TWL6040_REG_HSOTRIM            0x2B
+#define TWL6040_REG_HFOTRIM            0x2C
+#define TWL6040_REG_ACCCTL             0x2D
+#define TWL6040_REG_STATUS             0x2E
+
+#define TWL6040_CACHEREGNUM            (TWL6040_REG_STATUS + 1)
+
+#define TWL6040_VIOREGNUM              18
+#define TWL6040_VDDREGNUM              21
+
+/* INTID (0x03) fields */
+
+#define TWL6040_THINT                  0x01
+#define TWL6040_PLUGINT                        0x02
+#define TWL6040_UNPLUGINT              0x04
+#define TWL6040_HOOKINT                        0x08
+#define TWL6040_HFINT                  0x10
+#define TWL6040_VIBINT                 0x20
+#define TWL6040_READYINT               0x40
+
+/* INTMR (0x04) fields */
+
+#define TWL6040_READYMSK               0x40
+#define TWL6040_ALLINT_MSK             0x7B
+
+/* NCPCTL (0x05) fields */
+
+#define TWL6040_NCPENA                 0x01
+#define TWL6040_NCPOPEN                        0x40
+
+/* LDOCTL (0x06) fields */
+
+#define TWL6040_LSLDOENA               0x01
+#define TWL6040_HSLDOENA               0x04
+#define TWL6040_REFENA                 0x40
+#define TWL6040_OSCENA                 0x80
+
+/* HPPLLCTL (0x07) fields */
+
+#define TWL6040_HPLLENA                        0x01
+#define TWL6040_HPLLRST                        0x02
+#define TWL6040_HPLLBP                 0x04
+#define TWL6040_HPLLSQRENA             0x08
+#define TWL6040_HPLLSQRBP              0x10
+#define TWL6040_MCLK_12000KHZ          (0 << 5)
+#define TWL6040_MCLK_19200KHZ          (1 << 5)
+#define TWL6040_MCLK_26000KHZ          (2 << 5)
+#define TWL6040_MCLK_38400KHZ          (3 << 5)
+#define TWL6040_MCLK_MSK               0x60
+
+/* LPPLLCTL (0x08) fields */
+
+#define TWL6040_LPLLENA                        0x01
+#define TWL6040_LPLLRST                        0x02
+#define TWL6040_LPLLSEL                        0x04
+#define TWL6040_LPLLFIN                        0x08
+#define TWL6040_HPLLSEL                        0x10
+
+/* HSLCTL (0x10) fields */
+
+#define TWL6040_HSDACMODEL             0x02
+#define TWL6040_HSDRVMODEL             0x08
+
+/* HSRCTL (0x11) fields */
+
+#define TWL6040_HSDACMODER             0x02
+#define TWL6040_HSDRVMODER             0x08
+
+/* ACCCTL (0x2D) fields */
+
+#define TWL6040_RESETSPLIT             0x04
+
+#define TWL6040_SYSCLK_SEL_LPPLL       1
+#define TWL6040_SYSCLK_SEL_HPPLL       2
+
+#define TWL6040_HPPLL_ID               1
+#define TWL6040_LPPLL_ID               2
+
+extern struct snd_soc_dai twl6040_dai;
+extern struct snd_soc_codec_device soc_codec_dev_twl6040;
+
+#endif /* End of __TWL6040_H__ */
index a8dcd5a..28aac53 100644 (file)
@@ -175,7 +175,7 @@ static int uda134x_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct uda134x_priv *uda134x = codec->private_data;
+       struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
        struct snd_pcm_runtime *master_runtime;
 
        if (uda134x->master_substream) {
@@ -208,7 +208,7 @@ static void uda134x_shutdown(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct uda134x_priv *uda134x = codec->private_data;
+       struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
 
        if (uda134x->master_substream == substream)
                uda134x->master_substream = uda134x->slave_substream;
@@ -223,7 +223,7 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct uda134x_priv *uda134x = codec->private_data;
+       struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
        u8 hw_params;
 
        if (substream == uda134x->slave_substream) {
@@ -295,7 +295,7 @@ static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                  int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct uda134x_priv *uda134x = codec->private_data;
+       struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
 
        pr_debug("%s clk_id: %d, freq: %u, dir: %d\n", __func__,
                 clk_id, freq, dir);
@@ -317,7 +317,7 @@ static int uda134x_set_dai_fmt(struct snd_soc_dai *codec_dai,
                               unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct uda134x_priv *uda134x = codec->private_data;
+       struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
 
        pr_debug("%s fmt: %08X\n", __func__, fmt);
 
@@ -432,6 +432,14 @@ SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
 SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
 };
 
+static const struct snd_kcontrol_new uda1345_snd_controls[] = {
+SOC_SINGLE("Master Playback Volume", UDA134X_DATA000, 0, 0x3F, 1),
+
+SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
+
+SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
+};
+
 static struct snd_soc_dai_ops uda134x_dai_ops = {
        .startup        = uda134x_startup,
        .shutdown       = uda134x_shutdown,
@@ -487,6 +495,7 @@ static int uda134x_soc_probe(struct platform_device *pdev)
        case UDA134X_UDA1340:
        case UDA134X_UDA1341:
        case UDA134X_UDA1344:
+       case UDA134X_UDA1345:
                break;
        default:
                printk(KERN_ERR "UDA134X SoC codec: "
@@ -504,7 +513,7 @@ static int uda134x_soc_probe(struct platform_device *pdev)
        uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL);
        if (uda134x == NULL)
                goto priv_err;
-       codec->private_data = uda134x;
+       snd_soc_codec_set_drvdata(codec, uda134x);
 
        codec->reg_cache = kmemdup(uda134x_reg, sizeof(uda134x_reg),
                                   GFP_KERNEL);
@@ -552,6 +561,10 @@ static int uda134x_soc_probe(struct platform_device *pdev)
                ret = snd_soc_add_controls(codec, uda1341_snd_controls,
                                        ARRAY_SIZE(uda1341_snd_controls));
        break;
+       case UDA134X_UDA1345:
+               ret = snd_soc_add_controls(codec, uda1345_snd_controls,
+                                       ARRAY_SIZE(uda1345_snd_controls));
+       break;
        default:
                printk(KERN_ERR "%s unknown codec type: %d",
                        __func__, pd->model);
@@ -568,7 +581,7 @@ static int uda134x_soc_probe(struct platform_device *pdev)
 pcm_err:
        kfree(codec->reg_cache);
 reg_err:
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
 priv_err:
        kfree(codec);
        return ret;
@@ -586,7 +599,7 @@ static int uda134x_soc_remove(struct platform_device *pdev)
        snd_soc_free_pcms(socdev);
        snd_soc_dapm_free(socdev);
 
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec->reg_cache);
        kfree(codec);
 
index 9cd0a66..2f925a2 100644 (file)
@@ -476,7 +476,7 @@ static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct uda1380_priv *uda1380 = codec->private_data;
+       struct uda1380_priv *uda1380 = snd_soc_codec_get_drvdata(codec);
        int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER);
 
        switch (cmd) {
@@ -670,7 +670,6 @@ static int uda1380_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
        uda1380_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       uda1380_set_bias_level(codec, codec->suspend_bias_level);
        return 0;
 }
 
@@ -774,7 +773,7 @@ static int uda1380_register(struct uda1380_priv *uda1380)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = uda1380;
+       snd_soc_codec_set_drvdata(codec, uda1380);
        codec->name = "UDA1380";
        codec->owner = THIS_MODULE;
        codec->read = uda1380_read_reg_cache;
index 2e0772f..8ae2020 100644 (file)
@@ -55,6 +55,7 @@ struct wm8350_output {
 struct wm8350_jack_data {
        struct snd_soc_jack *jack;
        int report;
+       int short_report;
 };
 
 struct wm8350_data {
@@ -63,6 +64,7 @@ struct wm8350_data {
        struct wm8350_output out2;
        struct wm8350_jack_data hpl;
        struct wm8350_jack_data hpr;
+       struct wm8350_jack_data mic;
        struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
        int fll_freq_out;
        int fll_freq_in;
@@ -94,7 +96,7 @@ static int wm8350_codec_write(struct snd_soc_codec *codec, unsigned int reg,
  */
 static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec)
 {
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_data->out1;
        struct wm8350 *wm8350 = codec->control_data;
        int left_complete = 0, right_complete = 0;
@@ -160,7 +162,7 @@ static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec)
  */
 static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec)
 {
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out2 = &wm8350_data->out2;
        struct wm8350 *wm8350 = codec->control_data;
        int left_complete = 0, right_complete = 0;
@@ -230,7 +232,7 @@ static void wm8350_pga_work(struct work_struct *work)
 {
        struct snd_soc_codec *codec =
            container_of(work, struct snd_soc_codec, delayed_work.work);
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_data->out1,
            *out2 = &wm8350_data->out2;
        int i, out1_complete, out2_complete;
@@ -277,7 +279,7 @@ static int pga_event(struct snd_soc_dapm_widget *w,
                     struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out;
 
        switch (w->shift) {
@@ -322,7 +324,7 @@ static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
                                  struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8350_data *wm8350_priv = codec->private_data;
+       struct wm8350_data *wm8350_priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out = NULL;
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
@@ -365,7 +367,7 @@ static int wm8350_get_volsw_2r(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8350_data *wm8350_priv = codec->private_data;
+       struct wm8350_data *wm8350_priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_priv->out1;
        struct wm8350_output *out2 = &wm8350_priv->out2;
        struct soc_mixer_control *mc =
@@ -1107,7 +1109,7 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
        int ret = 0;
        u16 fll_1, fll_4;
@@ -1159,7 +1161,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_audio_platform_data *platform =
                wm8350->codec.platform_data;
        u16 pm1;
@@ -1335,9 +1337,6 @@ static int wm8350_resume(struct platform_device *pdev)
 
        wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
-               wm8350_set_bias_level(codec, SND_SOC_BIAS_ON);
-
        return 0;
 }
 
@@ -1392,12 +1391,13 @@ static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
  * @jack:   jack to report detection events on
  * @report: value to report
  *
- * Enables the headphone jack detection of the WM8350.
+ * Enables the headphone jack detection of the WM8350.  If no report
+ * is specified then detection is disabled.
  */
 int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
                          struct snd_soc_jack *jack, int report)
 {
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350 *wm8350 = codec->control_data;
        int irq;
        int ena;
@@ -1421,8 +1421,12 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
                return -EINVAL;
        }
 
-       wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
-       wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena);
+       if (report) {
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
+               wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena);
+       } else {
+               wm8350_clear_bits(wm8350, WM8350_JACK_DETECT, ena);
+       }
 
        /* Sync status */
        wm8350_hp_jack_handler(irq + wm8350->irq_base, priv);
@@ -1431,6 +1435,60 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
 }
 EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect);
 
+static irqreturn_t wm8350_mic_handler(int irq, void *data)
+{
+       struct wm8350_data *priv = data;
+       struct wm8350 *wm8350 = priv->codec.control_data;
+       u16 reg;
+       int report = 0;
+
+       reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
+       if (reg & WM8350_JACK_MICSCD_LVL)
+               report |= priv->mic.short_report;
+       if (reg & WM8350_JACK_MICSD_LVL)
+               report |= priv->mic.report;
+
+       snd_soc_jack_report(priv->mic.jack, report,
+                           priv->mic.report | priv->mic.short_report);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * wm8350_mic_jack_detect - Enable microphone jack detection.
+ *
+ * @codec:         WM8350 codec
+ * @jack:          jack to report detection events on
+ * @detect_report: value to report when presence detected
+ * @short_report:  value to report when microphone short detected
+ *
+ * Enables the microphone jack detection of the WM8350.  If both reports
+ * are specified as zero then detection is disabled.
+ */
+int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
+                          struct snd_soc_jack *jack,
+                          int detect_report, int short_report)
+{
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
+       struct wm8350 *wm8350 = codec->control_data;
+
+       priv->mic.jack = jack;
+       priv->mic.report = detect_report;
+       priv->mic.short_report = short_report;
+
+       if (detect_report || short_report) {
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_1,
+                               WM8350_MIC_DET_ENA);
+       } else {
+               wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_1,
+                                 WM8350_MIC_DET_ENA);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect);
+
 static struct snd_soc_codec *wm8350_codec;
 
 static int wm8350_probe(struct platform_device *pdev)
@@ -1448,7 +1506,7 @@ static int wm8350_probe(struct platform_device *pdev)
        socdev->card->codec = wm8350_codec;
        codec = socdev->card->codec;
        wm8350 = codec->control_data;
-       priv = codec->private_data;
+       priv = snd_soc_codec_get_drvdata(codec);
 
        /* Enable the codec */
        wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
@@ -1494,6 +1552,10 @@ static int wm8350_probe(struct platform_device *pdev)
        wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R,
                            wm8350_hp_jack_handler, 0, "Right jack detect",
                            priv);
+       wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD,
+                           wm8350_mic_handler, 0, "Microphone short", priv);
+       wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICD,
+                           wm8350_mic_handler, 0, "Microphone detect", priv);
 
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
        if (ret < 0) {
@@ -1515,18 +1577,21 @@ static int wm8350_remove(struct platform_device *pdev)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
                          WM8350_JDL_ENA | WM8350_JDR_ENA);
        wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
 
+       wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICD, priv);
+       wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, priv);
        wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, priv);
        wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, priv);
 
        priv->hpl.jack = NULL;
        priv->hpr.jack = NULL;
+       priv->mic.jack = NULL;
 
        /* cancel any work waiting to be queued. */
        ret = cancel_delayed_work(&codec->delayed_work);
@@ -1631,7 +1696,7 @@ static __devinit int wm8350_codec_probe(struct platform_device *pdev)
        codec->dai = &wm8350_dai;
        codec->num_dai = 1;
        codec->reg_cache_size = WM8350_MAX_REGISTER;
-       codec->private_data = priv;
+       snd_soc_codec_set_drvdata(codec, priv);
        codec->control_data = wm8350;
 
        /* Put the codec into reset if it wasn't already */
@@ -1663,7 +1728,7 @@ static int __devexit wm8350_codec_remove(struct platform_device *pdev)
 {
        struct wm8350 *wm8350 = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = wm8350->codec.codec;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
 
        snd_soc_unregister_dai(&wm8350_dai);
        snd_soc_unregister_codec(codec);
index d088eb4..9ed0467 100644 (file)
@@ -25,5 +25,8 @@ enum wm8350_jack {
 
 int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
                          struct snd_soc_jack *jack, int report);
+int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
+                          struct snd_soc_jack *jack,
+                          int detect_report, int short_report);
 
 #endif
index 6acc885..7f5d080 100644 (file)
@@ -77,7 +77,7 @@ struct wm8400_priv {
 static inline unsigned int wm8400_read(struct snd_soc_codec *codec,
                                       unsigned int reg)
 {
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
 
        if (reg == WM8400_INTDRIVBITS)
                return wm8400->fake_register;
@@ -91,7 +91,7 @@ static inline unsigned int wm8400_read(struct snd_soc_codec *codec,
 static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg,
        unsigned int value)
 {
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
 
        if (reg == WM8400_INTDRIVBITS) {
                wm8400->fake_register = value;
@@ -102,7 +102,7 @@ static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg,
 
 static void wm8400_codec_reset(struct snd_soc_codec *codec)
 {
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
 
        wm8400_reset_codec_reg_cache(wm8400->wm8400);
 }
@@ -926,7 +926,7 @@ static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
 
        wm8400->sysclk = freq;
        return 0;
@@ -1015,7 +1015,7 @@ static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
                              unsigned int freq_out)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
        struct fll_factors factors;
        int ret;
        u16 reg;
@@ -1204,7 +1204,7 @@ static int wm8400_mute(struct snd_soc_dai *dai, int mute)
 static int wm8400_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct wm8400_priv *wm8400 = codec->private_data;
+       struct wm8400_priv *wm8400 = snd_soc_codec_get_drvdata(codec);
        u16 val;
        int ret;
 
@@ -1467,7 +1467,7 @@ static int wm8400_codec_probe(struct platform_device *dev)
                return -ENOMEM;
 
        codec = &priv->codec;
-       codec->private_data = priv;
+       snd_soc_codec_set_drvdata(codec, priv);
        codec->control_data = dev_get_drvdata(&dev->dev);
        priv->wm8400 = dev_get_drvdata(&dev->dev);
 
@@ -1530,7 +1530,7 @@ err:
 
 static int __exit wm8400_codec_remove(struct platform_device *dev)
 {
-       struct wm8400_priv *priv = wm8400_codec->private_data;
+       struct wm8400_priv *priv = snd_soc_codec_get_drvdata(wm8400_codec);
        u16 reg;
 
        snd_soc_unregister_dai(&wm8400_dai);
index 9000b1d..0f7bcb6 100644 (file)
@@ -557,7 +557,7 @@ static int wm8510_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
        wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8510_set_bias_level(codec, codec->suspend_bias_level);
+
        return 0;
 }
 
index 19cd472..37242a7 100644 (file)
@@ -138,7 +138,7 @@ static int wm8523_startup(struct snd_pcm_substream *substream,
                          struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8523_priv *wm8523 = codec->private_data;
+       struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
 
        /* The set of sample rates that can be supported depends on the
         * MCLK supplied to the CODEC - enforce this.
@@ -164,7 +164,7 @@ static int wm8523_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8523_priv *wm8523 = codec->private_data;
+       struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
        int i;
        u16 aifctrl1 = snd_soc_read(codec, WM8523_AIF_CTRL1);
        u16 aifctrl2 = snd_soc_read(codec, WM8523_AIF_CTRL2);
@@ -211,7 +211,7 @@ static int wm8523_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8523_priv *wm8523 = codec->private_data;
+       struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
        unsigned int val;
        int i;
 
@@ -318,7 +318,7 @@ static int wm8523_set_dai_fmt(struct snd_soc_dai *codec_dai,
 static int wm8523_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct wm8523_priv *wm8523 = codec->private_data;
+       struct wm8523_priv *wm8523 = snd_soc_codec_get_drvdata(codec);
        int ret, i;
 
        switch (level) {
@@ -489,7 +489,7 @@ static int wm8523_register(struct wm8523_priv *wm8523,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8523;
+       snd_soc_codec_set_drvdata(codec, wm8523);
        codec->name = "WM8523";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index 8cc9042..c3571ee 100644 (file)
@@ -412,7 +412,7 @@ static int wm8580_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
 {
        int offset;
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8580_priv *wm8580 = codec->private_data;
+       struct wm8580_priv *wm8580 = snd_soc_codec_get_drvdata(codec);
        struct pll_state *state;
        struct _pll_div pll_div;
        unsigned int reg;
@@ -840,7 +840,7 @@ static int wm8580_register(struct wm8580_priv *wm8580,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8580;
+       snd_soc_codec_set_drvdata(codec, wm8580);
        codec->name = "WM8580";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index 8ca3812..effb14e 100644 (file)
@@ -163,7 +163,7 @@ static int wm8711_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8711_priv *wm8711 = codec->private_data;
+       struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8711_IFACE) & 0xfffc;
        int i = get_coeff(wm8711->sysclk, params_rate(params));
        u16 srate = (coeff_div[i].sr << 2) |
@@ -227,7 +227,7 @@ static int wm8711_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8711_priv *wm8711 = codec->private_data;
+       struct wm8711_priv *wm8711 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -376,7 +376,7 @@ static int wm8711_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
        wm8711_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8711_set_bias_level(codec, codec->suspend_bias_level);
+
        return 0;
 }
 
@@ -446,7 +446,7 @@ static int wm8711_register(struct wm8711_priv *wm8711,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8711;
+       snd_soc_codec_set_drvdata(codec, wm8711);
        codec->name = "WM8711";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index 07adc37..34be2d2 100644 (file)
@@ -238,7 +238,7 @@ static int wm8728_resume(struct platform_device *pdev)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
 
-       wm8728_set_bias_level(codec, codec->suspend_bias_level);
+       wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        return 0;
 }
index e7c6bf1..0ab9b63 100644 (file)
@@ -225,7 +225,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8731_priv *wm8731 = codec->private_data;
+       struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8731_IFACE) & 0xfff3;
        int i = get_coeff(wm8731->sysclk, params_rate(params));
        u16 srate = (coeff_div[i].sr << 2) |
@@ -292,7 +292,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8731_priv *wm8731 = codec->private_data;
+       struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -369,6 +369,10 @@ static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
 static int wm8731_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
+       struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(codec);
+       int i, ret;
+       u8 data[2];
+       u16 *cache = codec->reg_cache;
        u16 reg;
 
        switch (level) {
@@ -377,6 +381,24 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_PREPARE:
                break;
        case SND_SOC_BIAS_STANDBY:
+               if (codec->bias_level == SND_SOC_BIAS_OFF) {
+                       ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
+                                                   wm8731->supplies);
+                       if (ret != 0)
+                               return ret;
+
+                       /* Sync reg_cache with the hardware */
+                       for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
+                               if (cache[i] == wm8731_reg[i])
+                                       continue;
+
+                               data[0] = (i << 1) | ((cache[i] >> 8)
+                                                     & 0x0001);
+                               data[1] = cache[i] & 0x00ff;
+                               codec->hw_write(codec->control_data, data, 2);
+                       }
+               }
+
                /* Clear PWROFF, gate CLKOUT, everything else as-is */
                reg = snd_soc_read(codec, WM8731_PWR) & 0xff7f;
                snd_soc_write(codec, WM8731_PWR, reg | 0x0040);
@@ -384,17 +406,15 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
        case SND_SOC_BIAS_OFF:
                snd_soc_write(codec, WM8731_ACTIVE, 0x0);
                snd_soc_write(codec, WM8731_PWR, 0xffff);
+               regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
+                                      wm8731->supplies);
                break;
        }
        codec->bias_level = level;
        return 0;
 }
 
-#define WM8731_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
-               SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
-               SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 |\
-               SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 |\
-               SNDRV_PCM_RATE_96000)
+#define WM8731_RATES SNDRV_PCM_RATE_8000_96000
 
 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
        SNDRV_PCM_FMTBIT_S24_LE)
@@ -432,12 +452,9 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8731_priv *wm8731 = codec->private_data;
 
-       snd_soc_write(codec, WM8731_ACTIVE, 0x0);
        wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
-       regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies),
-                              wm8731->supplies);
+
        return 0;
 }
 
@@ -445,27 +462,8 @@ static int wm8731_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8731_priv *wm8731 = codec->private_data;
-       int i, ret;
-       u8 data[2];
-       u16 *cache = codec->reg_cache;
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(wm8731->supplies),
-                                   wm8731->supplies);
-       if (ret != 0)
-               return ret;
-
-       /* Sync reg_cache with the hardware */
-       for (i = 0; i < ARRAY_SIZE(wm8731_reg); i++) {
-               if (cache[i] == wm8731_reg[i])
-                       continue;
-
-               data[0] = (i << 1) | ((cache[i] >> 8) & 0x0001);
-               data[1] = cache[i] & 0x00ff;
-               codec->hw_write(codec->control_data, data, 2);
-       }
        wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8731_set_bias_level(codec, codec->suspend_bias_level);
 
        return 0;
 }
@@ -540,7 +538,7 @@ static int wm8731_register(struct wm8731_priv *wm8731,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8731;
+       snd_soc_codec_set_drvdata(codec, wm8731);
        codec->name = "WM8731";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
@@ -609,6 +607,9 @@ static int wm8731_register(struct wm8731_priv *wm8731,
                goto err_codec;
        }
 
+       /* Regulators will have been enabled by bias management */
+       regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
+
        return 0;
 
 err_codec:
@@ -627,7 +628,6 @@ static void wm8731_unregister(struct wm8731_priv *wm8731)
        wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF);
        snd_soc_unregister_dai(&wm8731_dai);
        snd_soc_unregister_codec(&wm8731->codec);
-       regulator_bulk_disable(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
        regulator_bulk_free(ARRAY_SIZE(wm8731->supplies), wm8731->supplies);
        kfree(wm8731);
        wm8731_codec = NULL;
@@ -708,7 +708,7 @@ MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
 
 static struct i2c_driver wm8731_i2c_driver = {
        .driver = {
-               .name = "WM8731 I2C Codec",
+               .name = "wm8731",
                .owner = THIS_MODULE,
        },
        .probe =    wm8731_i2c_probe,
index 2916ed4..9407e19 100644 (file)
 
 #include "wm8750.h"
 
-#define WM8750_VERSION "0.12"
-
-/* codec private data */
-struct wm8750_priv {
-       unsigned int sysclk;
-};
-
 /*
  * wm8750 register cache
  * We can't read the WM8750 register space when we
@@ -56,6 +49,13 @@ static const u16 wm8750_reg[] = {
        0x0079, 0x0079, 0x0079,          /* 40 */
 };
 
+/* codec private data */
+struct wm8750_priv {
+       unsigned int sysclk;
+       struct snd_soc_codec codec;
+       u16 reg_cache[ARRAY_SIZE(wm8750_reg)];
+};
+
 #define wm8750_reset(c)        snd_soc_write(c, WM8750_RESET, 0)
 
 /*
@@ -483,7 +483,7 @@ static int wm8750_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8750_priv *wm8750 = codec->private_data;
+       struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -562,7 +562,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8750_priv *wm8750 = codec->private_data;
+       struct wm8750_priv *wm8750 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8750_IFACE) & 0x1f3;
        u16 srate = snd_soc_read(codec, WM8750_SRATE) & 0x1c0;
        int coeff = get_coeff(wm8750->sysclk, params_rate(params));
@@ -614,10 +614,16 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
                snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x00c0);
                break;
        case SND_SOC_BIAS_PREPARE:
-               /* set vmid to 5k for quick power up */
-               snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
                break;
        case SND_SOC_BIAS_STANDBY:
+               if (codec->bias_level == SND_SOC_BIAS_OFF) {
+                       /* Set VMID to 5k */
+                       snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x01c1);
+
+                       /* ...and ramp */
+                       msleep(1000);
+               }
+
                /* mute dac and set vmid to 500k, enable VREF */
                snd_soc_write(codec, WM8750_PWR1, pwr_reg | 0x0141);
                break;
@@ -661,13 +667,6 @@ struct snd_soc_dai wm8750_dai = {
 };
 EXPORT_SYMBOL_GPL(wm8750_dai);
 
-static void wm8750_work(struct work_struct *work)
-{
-       struct snd_soc_codec *codec =
-               container_of(work, struct snd_soc_codec, delayed_work.work);
-       wm8750_set_bias_level(codec, codec->bias_level);
-}
-
 static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
@@ -696,36 +695,92 @@ static int wm8750_resume(struct platform_device *pdev)
 
        wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       /* charge wm8750 caps */
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON) {
-               wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
-               codec->bias_level = SND_SOC_BIAS_ON;
-               schedule_delayed_work(&codec->delayed_work,
-                                       msecs_to_jiffies(1000));
+       return 0;
+}
+
+static struct snd_soc_codec *wm8750_codec;
+
+static int wm8750_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       if (!wm8750_codec) {
+               dev_err(&pdev->dev, "WM8750 codec not yet registered\n");
+               return -EINVAL;
+       }
+
+       socdev->card->codec = wm8750_codec;
+       codec = wm8750_codec;
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8750: failed to create pcms\n");
+               goto err;
        }
 
+       snd_soc_add_controls(codec, wm8750_snd_controls,
+                               ARRAY_SIZE(wm8750_snd_controls));
+       wm8750_add_widgets(codec);
+
+       return 0;
+
+err:
+       return ret;
+}
+
+/* power down chip */
+static int wm8750_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+
        return 0;
 }
 
+struct snd_soc_codec_device soc_codec_dev_wm8750 = {
+       .probe          = wm8750_probe,
+       .remove         = wm8750_remove,
+       .suspend        = wm8750_suspend,
+       .resume         = wm8750_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
+
 /*
  * initialise the WM8750 driver
  * register the mixer and dsp interfaces with the kernel
  */
-static int wm8750_init(struct snd_soc_device *socdev,
-                      enum snd_soc_control_type control)
+static int wm8750_register(struct wm8750_priv *wm8750,
+                       enum snd_soc_control_type control)
 {
-       struct snd_soc_codec *codec = socdev->card->codec;
+       struct snd_soc_codec *codec = &wm8750->codec;
        int reg, ret = 0;
 
+       if (wm8750_codec) {
+               dev_err(codec->dev, "Multiple WM8750 devices not supported\n");
+               ret = -EINVAL;
+               goto err;
+       }
+
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
        codec->name = "WM8750";
        codec->owner = THIS_MODULE;
+       codec->bias_level = SND_SOC_BIAS_STANDBY;
        codec->set_bias_level = wm8750_set_bias_level;
        codec->dai = &wm8750_dai;
        codec->num_dai = 1;
-       codec->reg_cache_size = ARRAY_SIZE(wm8750_reg);
-       codec->reg_cache = kmemdup(wm8750_reg, sizeof(wm8750_reg), GFP_KERNEL);
-       if (codec->reg_cache == NULL)
-               return -ENOMEM;
+       codec->reg_cache_size = ARRAY_SIZE(wm8750->reg_cache) + 1;
+       codec->reg_cache = &wm8750->reg_cache;
+       snd_soc_codec_set_drvdata(codec, wm8750);
+
+       memcpy(codec->reg_cache, wm8750_reg, sizeof(wm8750->reg_cache));
 
        ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
        if (ret < 0) {
@@ -739,17 +794,8 @@ static int wm8750_init(struct snd_soc_device *socdev,
                goto err;
        }
 
-       /* register pcms */
-       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
-       if (ret < 0) {
-               printk(KERN_ERR "wm8750: failed to create pcms\n");
-               goto err;
-       }
-
        /* charge output caps */
-       wm8750_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
-       codec->bias_level = SND_SOC_BIAS_STANDBY;
-       schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000));
+       wm8750_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* set the update bits */
        reg = snd_soc_read(codec, WM8750_LDAC);
@@ -769,19 +815,37 @@ static int wm8750_init(struct snd_soc_device *socdev,
        reg = snd_soc_read(codec, WM8750_RINVOL);
        snd_soc_write(codec, WM8750_RINVOL, reg | 0x0100);
 
-       snd_soc_add_controls(codec, wm8750_snd_controls,
-                               ARRAY_SIZE(wm8750_snd_controls));
-       wm8750_add_widgets(codec);
-       return ret;
+       wm8750_codec = codec;
 
+       ret = snd_soc_register_codec(codec);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
+               goto err;
+       }
+
+       ret = snd_soc_register_dais(&wm8750_dai, 1);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to register DAIs: %d\n", ret);
+               goto err_codec;
+       }
+
+       return 0;
+
+err_codec:
+       snd_soc_unregister_codec(codec);
 err:
-       kfree(codec->reg_cache);
+       kfree(wm8750);
        return ret;
 }
 
-/* If the i2c layer weren't so broken, we could pass this kind of data
-   around */
-static struct snd_soc_device *wm8750_socdev;
+static void wm8750_unregister(struct wm8750_priv *wm8750)
+{
+       wm8750_set_bias_level(&wm8750->codec, SND_SOC_BIAS_OFF);
+       snd_soc_unregister_dais(&wm8750_dai, 1);
+       snd_soc_unregister_codec(&wm8750->codec);
+       kfree(wm8750);
+       wm8750_codec = NULL;
+}
 
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 
@@ -795,24 +859,26 @@ static struct snd_soc_device *wm8750_socdev;
 static int wm8750_i2c_probe(struct i2c_client *i2c,
                            const struct i2c_device_id *id)
 {
-       struct snd_soc_device *socdev = wm8750_socdev;
-       struct snd_soc_codec *codec = socdev->card->codec;
-       int ret;
+       struct snd_soc_codec *codec;
+       struct wm8750_priv *wm8750;
+
+       wm8750 = kzalloc(sizeof(struct wm8750_priv), GFP_KERNEL);
+       if (wm8750 == NULL)
+               return -ENOMEM;
 
-       i2c_set_clientdata(i2c, codec);
+       codec = &wm8750->codec;
        codec->control_data = i2c;
+       i2c_set_clientdata(i2c, wm8750);
 
-       ret = wm8750_init(socdev, SND_SOC_I2C);
-       if (ret < 0)
-               pr_err("failed to initialise WM8750\n");
+       codec->dev = &i2c->dev;
 
-       return ret;
+       return wm8750_register(wm8750, SND_SOC_I2C);
 }
 
 static int wm8750_i2c_remove(struct i2c_client *client)
 {
-       struct snd_soc_codec *codec = i2c_get_clientdata(client);
-       kfree(codec->reg_cache);
+       struct wm8750_priv *wm8750 = i2c_get_clientdata(client);
+       wm8750_unregister(wm8750);
        return 0;
 }
 
@@ -831,66 +897,31 @@ static struct i2c_driver wm8750_i2c_driver = {
        .remove =   wm8750_i2c_remove,
        .id_table = wm8750_i2c_id,
 };
-
-static int wm8750_add_i2c_device(struct platform_device *pdev,
-                                const struct wm8750_setup_data *setup)
-{
-       struct i2c_board_info info;
-       struct i2c_adapter *adapter;
-       struct i2c_client *client;
-       int ret;
-
-       ret = i2c_add_driver(&wm8750_i2c_driver);
-       if (ret != 0) {
-               dev_err(&pdev->dev, "can't add i2c driver\n");
-               return ret;
-       }
-
-       memset(&info, 0, sizeof(struct i2c_board_info));
-       info.addr = setup->i2c_address;
-       strlcpy(info.type, "wm8750", I2C_NAME_SIZE);
-
-       adapter = i2c_get_adapter(setup->i2c_bus);
-       if (!adapter) {
-               dev_err(&pdev->dev, "can't get i2c adapter %d\n",
-                       setup->i2c_bus);
-               goto err_driver;
-       }
-
-       client = i2c_new_device(adapter, &info);
-       i2c_put_adapter(adapter);
-       if (!client) {
-               dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
-                       (unsigned int)info.addr);
-               goto err_driver;
-       }
-
-       return 0;
-
-err_driver:
-       i2c_del_driver(&wm8750_i2c_driver);
-       return -ENODEV;
-}
 #endif
 
 #if defined(CONFIG_SPI_MASTER)
 static int __devinit wm8750_spi_probe(struct spi_device *spi)
 {
-       struct snd_soc_device *socdev = wm8750_socdev;
-       struct snd_soc_codec *codec = socdev->card->codec;
-       int ret;
+       struct snd_soc_codec *codec;
+       struct wm8750_priv *wm8750;
+
+       wm8750 = kzalloc(sizeof(struct wm8750_priv), GFP_KERNEL);
+       if (wm8750 == NULL)
+               return -ENOMEM;
 
+       codec = &wm8750->codec;
        codec->control_data = spi;
+       codec->dev = &spi->dev;
 
-       ret = wm8750_init(socdev, SND_SOC_SPI);
-       if (ret < 0)
-               dev_err(&spi->dev, "failed to initialise WM8750\n");
+       dev_set_drvdata(&spi->dev, wm8750);
 
-       return ret;
+       return wm8750_register(wm8750, SND_SOC_SPI);
 }
 
 static int __devexit wm8750_spi_remove(struct spi_device *spi)
 {
+       struct wm8750_priv *wm8750 = dev_get_drvdata(&spi->dev);
+       wm8750_unregister(wm8750);
        return 0;
 }
 
@@ -905,115 +936,31 @@ static struct spi_driver wm8750_spi_driver = {
 };
 #endif
 
-static int wm8750_probe(struct platform_device *pdev)
+static int __init wm8750_modinit(void)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct wm8750_setup_data *setup = socdev->codec_data;
-       struct snd_soc_codec *codec;
-       struct wm8750_priv *wm8750;
        int ret;
-
-       pr_info("WM8750 Audio Codec %s", WM8750_VERSION);
-       codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
-       if (codec == NULL)
-               return -ENOMEM;
-
-       wm8750 = kzalloc(sizeof(struct wm8750_priv), GFP_KERNEL);
-       if (wm8750 == NULL) {
-               kfree(codec);
-               return -ENOMEM;
-       }
-
-       codec->private_data = wm8750;
-       socdev->card->codec = codec;
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-       wm8750_socdev = socdev;
-       INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work);
-
-       ret = -ENODEV;
-
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-       if (setup->i2c_address) {
-               ret = wm8750_add_i2c_device(pdev, setup);
-       }
+       ret = i2c_add_driver(&wm8750_i2c_driver);
+       if (ret != 0)
+               pr_err("Failed to register WM8750 I2C driver: %d\n", ret);
 #endif
 #if defined(CONFIG_SPI_MASTER)
-       if (setup->spi) {
-               ret = spi_register_driver(&wm8750_spi_driver);
-               if (ret != 0)
-                       printk(KERN_ERR "can't add spi driver");
-       }
+       ret = spi_register_driver(&wm8750_spi_driver);
+       if (ret != 0)
+               pr_err("Failed to register WM8750 SPI driver: %d\n", ret);
 #endif
-
-       if (ret != 0) {
-               kfree(codec->private_data);
-               kfree(codec);
-       }
-       return ret;
-}
-
-/*
- * This function forces any delayed work to be queued and run.
- */
-static int run_delayed_work(struct delayed_work *dwork)
-{
-       int ret;
-
-       /* cancel any work waiting to be queued. */
-       ret = cancel_delayed_work(dwork);
-
-       /* if there was any work waiting then we run it now and
-        * wait for it's completion */
-       if (ret) {
-               schedule_delayed_work(dwork, 0);
-               flush_scheduled_work();
-       }
-       return ret;
+       return 0;
 }
+module_init(wm8750_modinit);
 
-/* power down chip */
-static int wm8750_remove(struct platform_device *pdev)
+static void __exit wm8750_exit(void)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
-       if (codec->control_data)
-               wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
-       run_delayed_work(&codec->delayed_work);
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-       i2c_unregister_device(codec->control_data);
        i2c_del_driver(&wm8750_i2c_driver);
 #endif
 #if defined(CONFIG_SPI_MASTER)
        spi_unregister_driver(&wm8750_spi_driver);
 #endif
-       kfree(codec->private_data);
-       kfree(codec);
-
-       return 0;
-}
-
-struct snd_soc_codec_device soc_codec_dev_wm8750 = {
-       .probe =        wm8750_probe,
-       .remove =       wm8750_remove,
-       .suspend =      wm8750_suspend,
-       .resume =       wm8750_resume,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
-
-static int __init wm8750_modinit(void)
-{
-       return snd_soc_register_dai(&wm8750_dai);
-}
-module_init(wm8750_modinit);
-
-static void __exit wm8750_exit(void)
-{
-       snd_soc_unregister_dai(&wm8750_dai);
 }
 module_exit(wm8750_exit);
 
index 613199a..b59f349 100644 (file)
@@ -851,7 +851,7 @@ static int wm8753_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -914,7 +914,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
        u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3;
        u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f;
 
@@ -1148,7 +1148,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8753_priv *wm8753 = codec->private_data;
+       struct wm8753_priv *wm8753 = snd_soc_codec_get_drvdata(codec);
        u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0;
        u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3;
        int coeff;
@@ -1646,7 +1646,7 @@ static int wm8753_register(struct wm8753_priv *wm8753)
        codec->num_dai = 2;
        codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache) + 1;
        codec->reg_cache = &wm8753->reg_cache;
-       codec->private_data = wm8753;
+       snd_soc_codec_set_drvdata(codec, wm8753);
 
        memcpy(codec->reg_cache, wm8753_reg, sizeof(wm8753->reg_cache));
        INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
index 60b1b3e..7e4a627 100644 (file)
@@ -227,7 +227,7 @@ static int wm8776_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8776_priv *wm8776 = codec->private_data;
+       struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec);
        int iface_reg, iface;
        int ratio_shift, master;
        int i;
@@ -304,7 +304,7 @@ static int wm8776_set_sysclk(struct snd_soc_dai *dai,
                             int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8776_priv *wm8776 = codec->private_data;
+       struct wm8776_priv *wm8776 = snd_soc_codec_get_drvdata(codec);
 
        BUG_ON(dai->id >= ARRAY_SIZE(wm8776->sysclk));
 
@@ -491,7 +491,7 @@ static int wm8776_register(struct wm8776_priv *wm8776,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8776;
+       snd_soc_codec_set_drvdata(codec, wm8776);
        codec->name = "WM8776";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index b7fd96a..5da17a7 100644 (file)
@@ -745,7 +745,7 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
 static int wm8900_set_fll(struct snd_soc_codec *codec,
        int fll_id, unsigned int freq_in, unsigned int freq_out)
 {
-       struct wm8900_priv *wm8900 = codec->private_data;
+       struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
        unsigned int reg;
 
@@ -1132,7 +1132,7 @@ static int wm8900_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8900_priv *wm8900 = codec->private_data;
+       struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec);
        int fll_out = wm8900->fll_out;
        int fll_in  = wm8900->fll_in;
        int ret;
@@ -1156,7 +1156,7 @@ static int wm8900_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8900_priv *wm8900 = codec->private_data;
+       struct wm8900_priv *wm8900 = snd_soc_codec_get_drvdata(codec);
        u16 *cache;
        int i, ret;
 
@@ -1206,7 +1206,7 @@ static __devinit int wm8900_i2c_probe(struct i2c_client *i2c,
                return -ENOMEM;
 
        codec = &wm8900->codec;
-       codec->private_data = wm8900;
+       snd_soc_codec_set_drvdata(codec, wm8900);
        codec->reg_cache = &wm8900->reg_cache[0];
        codec->reg_cache_size = WM8900_MAXREG;
 
@@ -1305,7 +1305,7 @@ static __devexit int wm8900_i2c_remove(struct i2c_client *client)
        wm8900_set_bias_level(wm8900_codec, SND_SOC_BIAS_OFF);
 
        wm8900_dai.dev = NULL;
-       kfree(wm8900_codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(wm8900_codec));
        wm8900_codec = NULL;
 
        return 0;
index fa5f99f..bf08282 100644 (file)
  *
  * TODO:
  *  - TDM mode configuration.
- *  - Mic detect.
  *  - Digital microphone support.
- *  - Interrupt support (mic detect and sequencer).
  */
 
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <sound/core.h>
+#include <sound/jack.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/tlv.h>
 #include <sound/soc.h>
 #include <sound/soc-dapm.h>
 #include <sound/initval.h>
+#include <sound/wm8903.h>
 
 #include "wm8903.h"
 
@@ -222,6 +223,14 @@ struct wm8903_priv {
        int playback_active;
        int capture_active;
 
+       struct completion wseq;
+
+       struct snd_soc_jack *mic_jack;
+       int mic_det;
+       int mic_short;
+       int mic_last_report;
+       int mic_delay;
+
        struct snd_pcm_substream *master_substream;
        struct snd_pcm_substream *slave_substream;
 };
@@ -244,13 +253,14 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start)
 {
        u16 reg[5];
        struct i2c_client *i2c = codec->control_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
 
        BUG_ON(start > 48);
 
-       /* Enable the sequencer */
+       /* Enable the sequencer if it's not already on */
        reg[0] = snd_soc_read(codec, WM8903_WRITE_SEQUENCER_0);
-       reg[0] |= WM8903_WSEQ_ENA;
-       snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0, reg[0]);
+       snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0,
+                     reg[0] | WM8903_WSEQ_ENA);
 
        dev_dbg(&i2c->dev, "Starting sequence at %d\n", start);
 
@@ -258,20 +268,19 @@ static int wm8903_run_sequence(struct snd_soc_codec *codec, unsigned int start)
                     start | WM8903_WSEQ_START);
 
        /* Wait for it to complete.  If we have the interrupt wired up then
-        * we could block waiting for an interrupt, though polling may still
-        * be desirable for diagnostic purposes.
+        * that will break us out of the poll early.
         */
        do {
-               msleep(10);
+               wait_for_completion_timeout(&wm8903->wseq,
+                                           msecs_to_jiffies(10));
 
                reg[4] = snd_soc_read(codec, WM8903_WRITE_SEQUENCER_4);
        } while (reg[4] & WM8903_WSEQ_BUSY);
 
        dev_dbg(&i2c->dev, "Sequence complete\n");
 
-       /* Disable the sequencer again */
-       snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0,
-                    reg[0] & ~WM8903_WSEQ_ENA);
+       /* Disable the sequencer again if we enabled it */
+       snd_soc_write(codec, WM8903_WRITE_SEQUENCER_0, reg[0]);
 
        return 0;
 }
@@ -412,7 +421,7 @@ static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct snd_soc_codec *codec = widget->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c = codec->control_data;
        u16 reg;
        int ret;
@@ -993,7 +1002,7 @@ static int wm8903_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                 int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
 
        wm8903->sysclk = freq;
 
@@ -1221,7 +1230,7 @@ static int wm8903_startup(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c = codec->control_data;
        struct snd_pcm_runtime *master_runtime;
 
@@ -1257,7 +1266,7 @@ static void wm8903_shutdown(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                wm8903->playback_active--;
@@ -1277,7 +1286,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8903_priv *wm8903 = codec->private_data;
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
        struct i2c_client *i2c = codec->control_data;
        int fs = params_rate(params);
        int bclk;
@@ -1436,6 +1445,116 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
+/**
+ * wm8903_mic_detect - Enable microphone detection via the WM8903 IRQ
+ *
+ * @codec:  WM8903 codec
+ * @jack:   jack to report detection events on
+ * @det:    value to report for presence detection
+ * @shrt:   value to report for short detection
+ *
+ * Enable microphone detection via IRQ on the WM8903.  If GPIOs are
+ * being used to bring out signals to the processor then only platform
+ * data configuration is needed for WM8903 and processor GPIOs should
+ * be configured using snd_soc_jack_add_gpios() instead.
+ *
+ * The current threasholds for detection should be configured using
+ * micdet_cfg in the platform data.  Using this function will force on
+ * the microphone bias for the device.
+ */
+int wm8903_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
+                     int det, int shrt)
+{
+       struct wm8903_priv *wm8903 = snd_soc_codec_get_drvdata(codec);
+       int irq_mask = WM8903_MICDET_EINT | WM8903_MICSHRT_EINT;
+
+       dev_dbg(codec->dev, "Enabling microphone detection: %x %x\n",
+               det, shrt);
+
+       /* Store the configuration */
+       wm8903->mic_jack = jack;
+       wm8903->mic_det = det;
+       wm8903->mic_short = shrt;
+
+       /* Enable interrupts we've got a report configured for */
+       if (det)
+               irq_mask &= ~WM8903_MICDET_EINT;
+       if (shrt)
+               irq_mask &= ~WM8903_MICSHRT_EINT;
+
+       snd_soc_update_bits(codec, WM8903_INTERRUPT_STATUS_1_MASK,
+                           WM8903_MICDET_EINT | WM8903_MICSHRT_EINT,
+                           irq_mask);
+
+       if (det && shrt) {
+               /* Enable mic detection, this may not have been set through
+                * platform data (eg, if the defaults are OK). */
+               snd_soc_update_bits(codec, WM8903_WRITE_SEQUENCER_0,
+                                   WM8903_WSEQ_ENA, WM8903_WSEQ_ENA);
+               snd_soc_update_bits(codec, WM8903_MIC_BIAS_CONTROL_0,
+                                   WM8903_MICDET_ENA, WM8903_MICDET_ENA);
+       } else {
+               snd_soc_update_bits(codec, WM8903_MIC_BIAS_CONTROL_0,
+                                   WM8903_MICDET_ENA, 0);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8903_mic_detect);
+
+static irqreturn_t wm8903_irq(int irq, void *data)
+{
+       struct wm8903_priv *wm8903 = data;
+       struct snd_soc_codec *codec = &wm8903->codec;
+       int mic_report;
+       int int_pol;
+       int int_val = 0;
+       int mask = ~snd_soc_read(codec, WM8903_INTERRUPT_STATUS_1_MASK);
+
+       int_val = snd_soc_read(codec, WM8903_INTERRUPT_STATUS_1) & mask;
+
+       if (int_val & WM8903_WSEQ_BUSY_EINT) {
+               dev_dbg(codec->dev, "Write sequencer done\n");
+               complete(&wm8903->wseq);
+       }
+
+       /*
+        * The rest is microphone jack detection.  We need to manually
+        * invert the polarity of the interrupt after each event - to
+        * simplify the code keep track of the last state we reported
+        * and just invert the relevant bits in both the report and
+        * the polarity register.
+        */
+       mic_report = wm8903->mic_last_report;
+       int_pol = snd_soc_read(codec, WM8903_INTERRUPT_POLARITY_1);
+
+       if (int_val & WM8903_MICSHRT_EINT) {
+               dev_dbg(codec->dev, "Microphone short (pol=%x)\n", int_pol);
+
+               mic_report ^= wm8903->mic_short;
+               int_pol ^= WM8903_MICSHRT_INV;
+       }
+
+       if (int_val & WM8903_MICDET_EINT) {
+               dev_dbg(codec->dev, "Microphone detect (pol=%x)\n", int_pol);
+
+               mic_report ^= wm8903->mic_det;
+               int_pol ^= WM8903_MICDET_INV;
+
+               msleep(wm8903->mic_delay);
+       }
+
+       snd_soc_update_bits(codec, WM8903_INTERRUPT_POLARITY_1,
+                           WM8903_MICSHRT_INV | WM8903_MICDET_INV, int_pol);
+
+       snd_soc_jack_report(wm8903->mic_jack, mic_report,
+                           wm8903->mic_short | wm8903->mic_det);
+
+       wm8903->mic_last_report = mic_report;
+
+       return IRQ_HANDLED;
+}
+
 #define WM8903_PLAYBACK_RATES (SNDRV_PCM_RATE_8000 |\
                               SNDRV_PCM_RATE_11025 |   \
                               SNDRV_PCM_RATE_16000 |   \
@@ -1510,7 +1629,6 @@ static int wm8903_resume(struct platform_device *pdev)
 
        /* Bring the codec back up to standby first to minimise pop/clicks */
        wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8903_set_bias_level(codec, codec->suspend_bias_level);
 
        /* Sync back everything else */
        if (tmp_cache) {
@@ -1530,9 +1648,11 @@ static struct snd_soc_codec *wm8903_codec;
 static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
                                      const struct i2c_device_id *id)
 {
+       struct wm8903_platform_data *pdata = dev_get_platdata(&i2c->dev);
        struct wm8903_priv *wm8903;
        struct snd_soc_codec *codec;
-       int ret;
+       int ret, i;
+       int trigger, irq_pol;
        u16 val;
 
        wm8903 = kzalloc(sizeof(struct wm8903_priv), GFP_KERNEL);
@@ -1554,8 +1674,9 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
        codec->num_dai = 1;
        codec->reg_cache_size = ARRAY_SIZE(wm8903->reg_cache);
        codec->reg_cache = &wm8903->reg_cache[0];
-       codec->private_data = wm8903;
+       snd_soc_codec_set_drvdata(codec, wm8903);
        codec->volatile_register = wm8903_volatile_register;
+       init_completion(&wm8903->wseq);
 
        i2c_set_clientdata(i2c, codec);
        codec->control_data = i2c;
@@ -1579,6 +1700,53 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
 
        wm8903_reset(codec);
 
+       /* Set up GPIOs and microphone detection */
+       if (pdata) {
+               for (i = 0; i < ARRAY_SIZE(pdata->gpio_cfg); i++) {
+                       if (!pdata->gpio_cfg[i])
+                               continue;
+
+                       snd_soc_write(codec, WM8903_GPIO_CONTROL_1 + i,
+                                     pdata->gpio_cfg[i] & 0xffff);
+               }
+
+               snd_soc_write(codec, WM8903_MIC_BIAS_CONTROL_0,
+                             pdata->micdet_cfg);
+
+               /* Microphone detection needs the WSEQ clock */
+               if (pdata->micdet_cfg)
+                       snd_soc_update_bits(codec, WM8903_WRITE_SEQUENCER_0,
+                                           WM8903_WSEQ_ENA, WM8903_WSEQ_ENA);
+
+               wm8903->mic_delay = pdata->micdet_delay;
+       }
+       
+       if (i2c->irq) {
+               if (pdata && pdata->irq_active_low) {
+                       trigger = IRQF_TRIGGER_LOW;
+                       irq_pol = WM8903_IRQ_POL;
+               } else {
+                       trigger = IRQF_TRIGGER_HIGH;
+                       irq_pol = 0;
+               }
+
+               snd_soc_update_bits(codec, WM8903_INTERRUPT_CONTROL,
+                                   WM8903_IRQ_POL, irq_pol);
+               
+               ret = request_threaded_irq(i2c->irq, NULL, wm8903_irq,
+                                          trigger | IRQF_ONESHOT,
+                                          "wm8903", wm8903);
+               if (ret != 0) {
+                       dev_err(&i2c->dev, "Failed to request IRQ: %d\n",
+                               ret);
+                       goto err;
+               }
+
+               /* Enable write sequencer interrupts */
+               snd_soc_update_bits(codec, WM8903_INTERRUPT_STATUS_1_MASK,
+                                   WM8903_IM_WSEQ_BUSY_EINT, 0);
+       }
+
        /* power on device */
        wm8903_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
@@ -1619,7 +1787,7 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
        ret = snd_soc_register_codec(codec);
        if (ret != 0) {
                dev_err(&i2c->dev, "Failed to register codec: %d\n", ret);
-               goto err;
+               goto err_irq;
        }
 
        ret = snd_soc_register_dai(&wm8903_dai);
@@ -1632,6 +1800,9 @@ static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
 
 err_codec:
        snd_soc_unregister_codec(codec);
+err_irq:
+       if (i2c->irq)
+               free_irq(i2c->irq, wm8903);
 err:
        wm8903_codec = NULL;
        kfree(wm8903);
@@ -1641,13 +1812,17 @@ err:
 static __devexit int wm8903_i2c_remove(struct i2c_client *client)
 {
        struct snd_soc_codec *codec = i2c_get_clientdata(client);
+       struct wm8903_priv *priv = snd_soc_codec_get_drvdata(codec);
 
        snd_soc_unregister_dai(&wm8903_dai);
        snd_soc_unregister_codec(codec);
 
        wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
 
-       kfree(codec->private_data);
+       if (client->irq)
+               free_irq(client->irq, priv);
+
+       kfree(priv);
 
        wm8903_codec = NULL;
        wm8903_dai.dev = NULL;
index 0ea27e2..ce384a2 100644 (file)
 extern struct snd_soc_dai wm8903_dai;
 extern struct snd_soc_codec_device soc_codec_dev_wm8903;
 
+extern int wm8903_mic_detect(struct snd_soc_codec *codec,
+                            struct snd_soc_jack *jack,
+                            int det, int shrt);
+
 #define WM8903_MCLK_DIV_2 1
 #define WM8903_CLK_SYS    2
 #define WM8903_BCLK       3
@@ -172,28 +176,6 @@ extern struct snd_soc_codec_device soc_codec_dev_wm8903;
 #define WM8903_VMID_RES_250K                         3
 #define WM8903_VMID_RES_5K                           4
 
-/*
- * R6 (0x06) - Mic Bias Control 0
- */
-#define WM8903_MICDET_HYST_ENA                  0x0080  /* MICDET_HYST_ENA */
-#define WM8903_MICDET_HYST_ENA_MASK             0x0080  /* MICDET_HYST_ENA */
-#define WM8903_MICDET_HYST_ENA_SHIFT                 7  /* MICDET_HYST_ENA */
-#define WM8903_MICDET_HYST_ENA_WIDTH                 1  /* MICDET_HYST_ENA */
-#define WM8903_MICDET_THR_MASK                  0x0070  /* MICDET_THR - [6:4] */
-#define WM8903_MICDET_THR_SHIFT                      4  /* MICDET_THR - [6:4] */
-#define WM8903_MICDET_THR_WIDTH                      3  /* MICDET_THR - [6:4] */
-#define WM8903_MICSHORT_THR_MASK                0x000C  /* MICSHORT_THR - [3:2] */
-#define WM8903_MICSHORT_THR_SHIFT                    2  /* MICSHORT_THR - [3:2] */
-#define WM8903_MICSHORT_THR_WIDTH                    2  /* MICSHORT_THR - [3:2] */
-#define WM8903_MICDET_ENA                       0x0002  /* MICDET_ENA */
-#define WM8903_MICDET_ENA_MASK                  0x0002  /* MICDET_ENA */
-#define WM8903_MICDET_ENA_SHIFT                      1  /* MICDET_ENA */
-#define WM8903_MICDET_ENA_WIDTH                      1  /* MICDET_ENA */
-#define WM8903_MICBIAS_ENA                      0x0001  /* MICBIAS_ENA */
-#define WM8903_MICBIAS_ENA_MASK                 0x0001  /* MICBIAS_ENA */
-#define WM8903_MICBIAS_ENA_SHIFT                     0  /* MICBIAS_ENA */
-#define WM8903_MICBIAS_ENA_WIDTH                     1  /* MICBIAS_ENA */
-
 /*
  * R8 (0x08) - Analogue DAC 0
  */
@@ -1134,201 +1116,6 @@ extern struct snd_soc_codec_device soc_codec_dev_wm8903;
 #define WM8903_MASK_WRITE_ENA_SHIFT                  0  /* MASK_WRITE_ENA */
 #define WM8903_MASK_WRITE_ENA_WIDTH                  1  /* MASK_WRITE_ENA */
 
-/*
- * R116 (0x74) - GPIO Control 1
- */
-#define WM8903_GP1_FN_MASK                      0x1F00  /* GP1_FN - [12:8] */
-#define WM8903_GP1_FN_SHIFT                          8  /* GP1_FN - [12:8] */
-#define WM8903_GP1_FN_WIDTH                          5  /* GP1_FN - [12:8] */
-#define WM8903_GP1_DIR                          0x0080  /* GP1_DIR */
-#define WM8903_GP1_DIR_MASK                     0x0080  /* GP1_DIR */
-#define WM8903_GP1_DIR_SHIFT                         7  /* GP1_DIR */
-#define WM8903_GP1_DIR_WIDTH                         1  /* GP1_DIR */
-#define WM8903_GP1_OP_CFG                       0x0040  /* GP1_OP_CFG */
-#define WM8903_GP1_OP_CFG_MASK                  0x0040  /* GP1_OP_CFG */
-#define WM8903_GP1_OP_CFG_SHIFT                      6  /* GP1_OP_CFG */
-#define WM8903_GP1_OP_CFG_WIDTH                      1  /* GP1_OP_CFG */
-#define WM8903_GP1_IP_CFG                       0x0020  /* GP1_IP_CFG */
-#define WM8903_GP1_IP_CFG_MASK                  0x0020  /* GP1_IP_CFG */
-#define WM8903_GP1_IP_CFG_SHIFT                      5  /* GP1_IP_CFG */
-#define WM8903_GP1_IP_CFG_WIDTH                      1  /* GP1_IP_CFG */
-#define WM8903_GP1_LVL                          0x0010  /* GP1_LVL */
-#define WM8903_GP1_LVL_MASK                     0x0010  /* GP1_LVL */
-#define WM8903_GP1_LVL_SHIFT                         4  /* GP1_LVL */
-#define WM8903_GP1_LVL_WIDTH                         1  /* GP1_LVL */
-#define WM8903_GP1_PD                           0x0008  /* GP1_PD */
-#define WM8903_GP1_PD_MASK                      0x0008  /* GP1_PD */
-#define WM8903_GP1_PD_SHIFT                          3  /* GP1_PD */
-#define WM8903_GP1_PD_WIDTH                          1  /* GP1_PD */
-#define WM8903_GP1_PU                           0x0004  /* GP1_PU */
-#define WM8903_GP1_PU_MASK                      0x0004  /* GP1_PU */
-#define WM8903_GP1_PU_SHIFT                          2  /* GP1_PU */
-#define WM8903_GP1_PU_WIDTH                          1  /* GP1_PU */
-#define WM8903_GP1_INTMODE                      0x0002  /* GP1_INTMODE */
-#define WM8903_GP1_INTMODE_MASK                 0x0002  /* GP1_INTMODE */
-#define WM8903_GP1_INTMODE_SHIFT                     1  /* GP1_INTMODE */
-#define WM8903_GP1_INTMODE_WIDTH                     1  /* GP1_INTMODE */
-#define WM8903_GP1_DB                           0x0001  /* GP1_DB */
-#define WM8903_GP1_DB_MASK                      0x0001  /* GP1_DB */
-#define WM8903_GP1_DB_SHIFT                          0  /* GP1_DB */
-#define WM8903_GP1_DB_WIDTH                          1  /* GP1_DB */
-
-/*
- * R117 (0x75) - GPIO Control 2
- */
-#define WM8903_GP2_FN_MASK                      0x1F00  /* GP2_FN - [12:8] */
-#define WM8903_GP2_FN_SHIFT                          8  /* GP2_FN - [12:8] */
-#define WM8903_GP2_FN_WIDTH                          5  /* GP2_FN - [12:8] */
-#define WM8903_GP2_DIR                          0x0080  /* GP2_DIR */
-#define WM8903_GP2_DIR_MASK                     0x0080  /* GP2_DIR */
-#define WM8903_GP2_DIR_SHIFT                         7  /* GP2_DIR */
-#define WM8903_GP2_DIR_WIDTH                         1  /* GP2_DIR */
-#define WM8903_GP2_OP_CFG                       0x0040  /* GP2_OP_CFG */
-#define WM8903_GP2_OP_CFG_MASK                  0x0040  /* GP2_OP_CFG */
-#define WM8903_GP2_OP_CFG_SHIFT                      6  /* GP2_OP_CFG */
-#define WM8903_GP2_OP_CFG_WIDTH                      1  /* GP2_OP_CFG */
-#define WM8903_GP2_IP_CFG                       0x0020  /* GP2_IP_CFG */
-#define WM8903_GP2_IP_CFG_MASK                  0x0020  /* GP2_IP_CFG */
-#define WM8903_GP2_IP_CFG_SHIFT                      5  /* GP2_IP_CFG */
-#define WM8903_GP2_IP_CFG_WIDTH                      1  /* GP2_IP_CFG */
-#define WM8903_GP2_LVL                          0x0010  /* GP2_LVL */
-#define WM8903_GP2_LVL_MASK                     0x0010  /* GP2_LVL */
-#define WM8903_GP2_LVL_SHIFT                         4  /* GP2_LVL */
-#define WM8903_GP2_LVL_WIDTH                         1  /* GP2_LVL */
-#define WM8903_GP2_PD                           0x0008  /* GP2_PD */
-#define WM8903_GP2_PD_MASK                      0x0008  /* GP2_PD */
-#define WM8903_GP2_PD_SHIFT                          3  /* GP2_PD */
-#define WM8903_GP2_PD_WIDTH                          1  /* GP2_PD */
-#define WM8903_GP2_PU                           0x0004  /* GP2_PU */
-#define WM8903_GP2_PU_MASK                      0x0004  /* GP2_PU */
-#define WM8903_GP2_PU_SHIFT                          2  /* GP2_PU */
-#define WM8903_GP2_PU_WIDTH                          1  /* GP2_PU */
-#define WM8903_GP2_INTMODE                      0x0002  /* GP2_INTMODE */
-#define WM8903_GP2_INTMODE_MASK                 0x0002  /* GP2_INTMODE */
-#define WM8903_GP2_INTMODE_SHIFT                     1  /* GP2_INTMODE */
-#define WM8903_GP2_INTMODE_WIDTH                     1  /* GP2_INTMODE */
-#define WM8903_GP2_DB                           0x0001  /* GP2_DB */
-#define WM8903_GP2_DB_MASK                      0x0001  /* GP2_DB */
-#define WM8903_GP2_DB_SHIFT                          0  /* GP2_DB */
-#define WM8903_GP2_DB_WIDTH                          1  /* GP2_DB */
-
-/*
- * R118 (0x76) - GPIO Control 3
- */
-#define WM8903_GP3_FN_MASK                      0x1F00  /* GP3_FN - [12:8] */
-#define WM8903_GP3_FN_SHIFT                          8  /* GP3_FN - [12:8] */
-#define WM8903_GP3_FN_WIDTH                          5  /* GP3_FN - [12:8] */
-#define WM8903_GP3_DIR                          0x0080  /* GP3_DIR */
-#define WM8903_GP3_DIR_MASK                     0x0080  /* GP3_DIR */
-#define WM8903_GP3_DIR_SHIFT                         7  /* GP3_DIR */
-#define WM8903_GP3_DIR_WIDTH                         1  /* GP3_DIR */
-#define WM8903_GP3_OP_CFG                       0x0040  /* GP3_OP_CFG */
-#define WM8903_GP3_OP_CFG_MASK                  0x0040  /* GP3_OP_CFG */
-#define WM8903_GP3_OP_CFG_SHIFT                      6  /* GP3_OP_CFG */
-#define WM8903_GP3_OP_CFG_WIDTH                      1  /* GP3_OP_CFG */
-#define WM8903_GP3_IP_CFG                       0x0020  /* GP3_IP_CFG */
-#define WM8903_GP3_IP_CFG_MASK                  0x0020  /* GP3_IP_CFG */
-#define WM8903_GP3_IP_CFG_SHIFT                      5  /* GP3_IP_CFG */
-#define WM8903_GP3_IP_CFG_WIDTH                      1  /* GP3_IP_CFG */
-#define WM8903_GP3_LVL                          0x0010  /* GP3_LVL */
-#define WM8903_GP3_LVL_MASK                     0x0010  /* GP3_LVL */
-#define WM8903_GP3_LVL_SHIFT                         4  /* GP3_LVL */
-#define WM8903_GP3_LVL_WIDTH                         1  /* GP3_LVL */
-#define WM8903_GP3_PD                           0x0008  /* GP3_PD */
-#define WM8903_GP3_PD_MASK                      0x0008  /* GP3_PD */
-#define WM8903_GP3_PD_SHIFT                          3  /* GP3_PD */
-#define WM8903_GP3_PD_WIDTH                          1  /* GP3_PD */
-#define WM8903_GP3_PU                           0x0004  /* GP3_PU */
-#define WM8903_GP3_PU_MASK                      0x0004  /* GP3_PU */
-#define WM8903_GP3_PU_SHIFT                          2  /* GP3_PU */
-#define WM8903_GP3_PU_WIDTH                          1  /* GP3_PU */
-#define WM8903_GP3_INTMODE                      0x0002  /* GP3_INTMODE */
-#define WM8903_GP3_INTMODE_MASK                 0x0002  /* GP3_INTMODE */
-#define WM8903_GP3_INTMODE_SHIFT                     1  /* GP3_INTMODE */
-#define WM8903_GP3_INTMODE_WIDTH                     1  /* GP3_INTMODE */
-#define WM8903_GP3_DB                           0x0001  /* GP3_DB */
-#define WM8903_GP3_DB_MASK                      0x0001  /* GP3_DB */
-#define WM8903_GP3_DB_SHIFT                          0  /* GP3_DB */
-#define WM8903_GP3_DB_WIDTH                          1  /* GP3_DB */
-
-/*
- * R119 (0x77) - GPIO Control 4
- */
-#define WM8903_GP4_FN_MASK                      0x1F00  /* GP4_FN - [12:8] */
-#define WM8903_GP4_FN_SHIFT                          8  /* GP4_FN - [12:8] */
-#define WM8903_GP4_FN_WIDTH                          5  /* GP4_FN - [12:8] */
-#define WM8903_GP4_DIR                          0x0080  /* GP4_DIR */
-#define WM8903_GP4_DIR_MASK                     0x0080  /* GP4_DIR */
-#define WM8903_GP4_DIR_SHIFT                         7  /* GP4_DIR */
-#define WM8903_GP4_DIR_WIDTH                         1  /* GP4_DIR */
-#define WM8903_GP4_OP_CFG                       0x0040  /* GP4_OP_CFG */
-#define WM8903_GP4_OP_CFG_MASK                  0x0040  /* GP4_OP_CFG */
-#define WM8903_GP4_OP_CFG_SHIFT                      6  /* GP4_OP_CFG */
-#define WM8903_GP4_OP_CFG_WIDTH                      1  /* GP4_OP_CFG */
-#define WM8903_GP4_IP_CFG                       0x0020  /* GP4_IP_CFG */
-#define WM8903_GP4_IP_CFG_MASK                  0x0020  /* GP4_IP_CFG */
-#define WM8903_GP4_IP_CFG_SHIFT                      5  /* GP4_IP_CFG */
-#define WM8903_GP4_IP_CFG_WIDTH                      1  /* GP4_IP_CFG */
-#define WM8903_GP4_LVL                          0x0010  /* GP4_LVL */
-#define WM8903_GP4_LVL_MASK                     0x0010  /* GP4_LVL */
-#define WM8903_GP4_LVL_SHIFT                         4  /* GP4_LVL */
-#define WM8903_GP4_LVL_WIDTH                         1  /* GP4_LVL */
-#define WM8903_GP4_PD                           0x0008  /* GP4_PD */
-#define WM8903_GP4_PD_MASK                      0x0008  /* GP4_PD */
-#define WM8903_GP4_PD_SHIFT                          3  /* GP4_PD */
-#define WM8903_GP4_PD_WIDTH                          1  /* GP4_PD */
-#define WM8903_GP4_PU                           0x0004  /* GP4_PU */
-#define WM8903_GP4_PU_MASK                      0x0004  /* GP4_PU */
-#define WM8903_GP4_PU_SHIFT                          2  /* GP4_PU */
-#define WM8903_GP4_PU_WIDTH                          1  /* GP4_PU */
-#define WM8903_GP4_INTMODE                      0x0002  /* GP4_INTMODE */
-#define WM8903_GP4_INTMODE_MASK                 0x0002  /* GP4_INTMODE */
-#define WM8903_GP4_INTMODE_SHIFT                     1  /* GP4_INTMODE */
-#define WM8903_GP4_INTMODE_WIDTH                     1  /* GP4_INTMODE */
-#define WM8903_GP4_DB                           0x0001  /* GP4_DB */
-#define WM8903_GP4_DB_MASK                      0x0001  /* GP4_DB */
-#define WM8903_GP4_DB_SHIFT                          0  /* GP4_DB */
-#define WM8903_GP4_DB_WIDTH                          1  /* GP4_DB */
-
-/*
- * R120 (0x78) - GPIO Control 5
- */
-#define WM8903_GP5_FN_MASK                      0x1F00  /* GP5_FN - [12:8] */
-#define WM8903_GP5_FN_SHIFT                          8  /* GP5_FN - [12:8] */
-#define WM8903_GP5_FN_WIDTH                          5  /* GP5_FN - [12:8] */
-#define WM8903_GP5_DIR                          0x0080  /* GP5_DIR */
-#define WM8903_GP5_DIR_MASK                     0x0080  /* GP5_DIR */
-#define WM8903_GP5_DIR_SHIFT                         7  /* GP5_DIR */
-#define WM8903_GP5_DIR_WIDTH                         1  /* GP5_DIR */
-#define WM8903_GP5_OP_CFG                       0x0040  /* GP5_OP_CFG */
-#define WM8903_GP5_OP_CFG_MASK                  0x0040  /* GP5_OP_CFG */
-#define WM8903_GP5_OP_CFG_SHIFT                      6  /* GP5_OP_CFG */
-#define WM8903_GP5_OP_CFG_WIDTH                      1  /* GP5_OP_CFG */
-#define WM8903_GP5_IP_CFG                       0x0020  /* GP5_IP_CFG */
-#define WM8903_GP5_IP_CFG_MASK                  0x0020  /* GP5_IP_CFG */
-#define WM8903_GP5_IP_CFG_SHIFT                      5  /* GP5_IP_CFG */
-#define WM8903_GP5_IP_CFG_WIDTH                      1  /* GP5_IP_CFG */
-#define WM8903_GP5_LVL                          0x0010  /* GP5_LVL */
-#define WM8903_GP5_LVL_MASK                     0x0010  /* GP5_LVL */
-#define WM8903_GP5_LVL_SHIFT                         4  /* GP5_LVL */
-#define WM8903_GP5_LVL_WIDTH                         1  /* GP5_LVL */
-#define WM8903_GP5_PD                           0x0008  /* GP5_PD */
-#define WM8903_GP5_PD_MASK                      0x0008  /* GP5_PD */
-#define WM8903_GP5_PD_SHIFT                          3  /* GP5_PD */
-#define WM8903_GP5_PD_WIDTH                          1  /* GP5_PD */
-#define WM8903_GP5_PU                           0x0004  /* GP5_PU */
-#define WM8903_GP5_PU_MASK                      0x0004  /* GP5_PU */
-#define WM8903_GP5_PU_SHIFT                          2  /* GP5_PU */
-#define WM8903_GP5_PU_WIDTH                          1  /* GP5_PU */
-#define WM8903_GP5_INTMODE                      0x0002  /* GP5_INTMODE */
-#define WM8903_GP5_INTMODE_MASK                 0x0002  /* GP5_INTMODE */
-#define WM8903_GP5_INTMODE_SHIFT                     1  /* GP5_INTMODE */
-#define WM8903_GP5_INTMODE_WIDTH                     1  /* GP5_INTMODE */
-#define WM8903_GP5_DB                           0x0001  /* GP5_DB */
-#define WM8903_GP5_DB_MASK                      0x0001  /* GP5_DB */
-#define WM8903_GP5_DB_SHIFT                          0  /* GP5_DB */
-#define WM8903_GP5_DB_WIDTH                          1  /* GP5_DB */
-
 /*
  * R121 (0x79) - Interrupt Status 1
  */
index c6f0abc..87f14f8 100644 (file)
@@ -613,7 +613,7 @@ static int wm8904_reset(struct snd_soc_codec *codec)
 
 static int wm8904_configure_clocking(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        unsigned int clock0, clock2, rate;
 
        /* Gate the clock while we're updating to avoid misclocking */
@@ -669,7 +669,7 @@ static int wm8904_configure_clocking(struct snd_soc_codec *codec)
 
 static void wm8904_set_drc(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        struct wm8904_pdata *pdata = wm8904->pdata;
        int save, i;
 
@@ -689,7 +689,7 @@ static int wm8904_put_drc_enum(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;       
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);  
        struct wm8904_pdata *pdata = wm8904->pdata;
        int value = ucontrol->value.integer.value[0];
 
@@ -707,7 +707,7 @@ static int wm8904_get_drc_enum(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
 
        ucontrol->value.enumerated.item[0] = wm8904->drc_cfg;
 
@@ -716,7 +716,7 @@ static int wm8904_get_drc_enum(struct snd_kcontrol *kcontrol,
 
 static void wm8904_set_retune_mobile(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        struct wm8904_pdata *pdata = wm8904->pdata;
        int best, best_val, save, i, cfg;
 
@@ -760,7 +760,7 @@ static int wm8904_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
                                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;       
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);  
        struct wm8904_pdata *pdata = wm8904->pdata;
        int value = ucontrol->value.integer.value[0];
 
@@ -778,7 +778,7 @@ static int wm8904_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
                                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
 
        ucontrol->value.enumerated.item[0] = wm8904->retune_mobile_cfg;
 
@@ -789,7 +789,7 @@ static int deemph_settings[] = { 0, 32000, 44100, 48000 };
 
 static int wm8904_set_deemph(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int val, i, best;
 
        /* If we're using deemphasis select the nearest available sample 
@@ -818,7 +818,7 @@ static int wm8904_get_deemph(struct snd_kcontrol *kcontrol,
                             struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
 
        return wm8904->deemph;
 }
@@ -827,7 +827,7 @@ static int wm8904_put_deemph(struct snd_kcontrol *kcontrol,
                              struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int deemph = ucontrol->value.enumerated.item[0];
 
        if (deemph > 1)
@@ -943,7 +943,7 @@ static int sysclk_event(struct snd_soc_dapm_widget *w,
                         struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
 
        switch (event) {
        case SND_SOC_DAPM_PRE_PMU:
@@ -981,7 +981,7 @@ static int out_pga_event(struct snd_soc_dapm_widget *w,
                         struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int reg, val;
        int dcs_mask;
        int dcs_l, dcs_r;
@@ -1429,7 +1429,7 @@ static const struct snd_soc_dapm_route wm8912_intercon[] = {
 
 static int wm8904_add_widgets(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
 
        snd_soc_dapm_new_controls(codec, wm8904_core_dapm_widgets,
                                  ARRAY_SIZE(wm8904_core_dapm_widgets));
@@ -1543,7 +1543,7 @@ static int wm8904_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int ret, i, best, best_val, cur_val;
        unsigned int aif1 = 0;
        unsigned int aif2 = 0;
@@ -1670,7 +1670,7 @@ static int wm8904_set_sysclk(struct snd_soc_dai *dai, int clk_id,
                             unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8904_priv *priv = codec->private_data;
+       struct wm8904_priv *priv = snd_soc_codec_get_drvdata(codec);
 
        switch (clk_id) {
        case WM8904_CLK_MCLK:
@@ -1786,7 +1786,7 @@ static int wm8904_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
                               unsigned int rx_mask, int slots, int slot_width)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int aif1 = 0;
 
        /* Don't need to validate anything if we're turning off TDM */
@@ -1943,7 +1943,7 @@ static int wm8904_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
                          unsigned int Fref, unsigned int Fout)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
        int ret, val;
        int clock2, fll1;
@@ -2095,7 +2095,7 @@ static int wm8904_digital_mute(struct snd_soc_dai *codec_dai, int mute)
 
 static void wm8904_sync_cache(struct snd_soc_codec *codec)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int i;
 
        if (!codec->cache_sync)
@@ -2122,7 +2122,7 @@ static void wm8904_sync_cache(struct snd_soc_codec *codec)
 static int wm8904_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct wm8904_priv *wm8904 = codec->private_data;
+       struct wm8904_priv *wm8904 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        switch (level) {
@@ -2395,7 +2395,7 @@ static int wm8904_probe(struct platform_device *pdev)
                goto pcm_err;
        }
 
-       wm8904_handle_pdata(codec->private_data);
+       wm8904_handle_pdata(snd_soc_codec_get_drvdata(codec));
 
        wm8904_add_widgets(codec);
 
@@ -2426,6 +2426,7 @@ EXPORT_SYMBOL_GPL(soc_codec_dev_wm8904);
 static int wm8904_register(struct wm8904_priv *wm8904,
                           enum snd_soc_control_type control)
 {
+       struct wm8904_pdata *pdata = wm8904->pdata;
        int ret;
        struct snd_soc_codec *codec = &wm8904->codec;
        int i;
@@ -2439,7 +2440,7 @@ static int wm8904_register(struct wm8904_priv *wm8904,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8904;
+       snd_soc_codec_set_drvdata(codec, wm8904);
        codec->name = "WM8904";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
@@ -2531,6 +2532,22 @@ static int wm8904_register(struct wm8904_priv *wm8904,
                WM8904_LINEOUTRZC;
        wm8904->reg_cache[WM8904_CLOCK_RATES_0] &= ~WM8904_SR_MODE;
 
+       /* Apply configuration from the platform data. */
+       if (wm8904->pdata) {
+               for (i = 0; i < WM8904_GPIO_REGS; i++) {
+                       if (!pdata->gpio_cfg[i])
+                               continue;
+
+                       wm8904->reg_cache[WM8904_GPIO_CONTROL_1 + i]
+                               = pdata->gpio_cfg[i] & 0xffff;
+               }
+
+               /* Zero is the default value for these anyway */
+               for (i = 0; i < WM8904_MIC_REGS; i++)
+                       wm8904->reg_cache[WM8904_MIC_BIAS_CONTROL_0 + i]
+                               = pdata->mic_cfg[i];
+       }
+
        /* Set Class W by default - this will be managed by the Class
         * G widget at runtime where bypass paths are available.
         */
index b68886d..abe5059 100644 (file)
@@ -185,39 +185,6 @@ extern struct snd_soc_codec_device soc_codec_dev_wm8904;
 #define WM8904_VMID_ENA_SHIFT                        0  /* VMID_ENA */
 #define WM8904_VMID_ENA_WIDTH                        1  /* VMID_ENA */
 
-/*
- * R6 (0x06) - Mic Bias Control 0
- */
-#define WM8904_MICDET_THR_MASK                  0x0070  /* MICDET_THR - [6:4] */
-#define WM8904_MICDET_THR_SHIFT                      4  /* MICDET_THR - [6:4] */
-#define WM8904_MICDET_THR_WIDTH                      3  /* MICDET_THR - [6:4] */
-#define WM8904_MICSHORT_THR_MASK                0x000C  /* MICSHORT_THR - [3:2] */
-#define WM8904_MICSHORT_THR_SHIFT                    2  /* MICSHORT_THR - [3:2] */
-#define WM8904_MICSHORT_THR_WIDTH                    2  /* MICSHORT_THR - [3:2] */
-#define WM8904_MICDET_ENA                       0x0002  /* MICDET_ENA */
-#define WM8904_MICDET_ENA_MASK                  0x0002  /* MICDET_ENA */
-#define WM8904_MICDET_ENA_SHIFT                      1  /* MICDET_ENA */
-#define WM8904_MICDET_ENA_WIDTH                      1  /* MICDET_ENA */
-#define WM8904_MICBIAS_ENA                      0x0001  /* MICBIAS_ENA */
-#define WM8904_MICBIAS_ENA_MASK                 0x0001  /* MICBIAS_ENA */
-#define WM8904_MICBIAS_ENA_SHIFT                     0  /* MICBIAS_ENA */
-#define WM8904_MICBIAS_ENA_WIDTH                     1  /* MICBIAS_ENA */
-
-/*
- * R7 (0x07) - Mic Bias Control 1
- */
-#define WM8904_MIC_DET_FILTER_ENA               0x8000  /* MIC_DET_FILTER_ENA */
-#define WM8904_MIC_DET_FILTER_ENA_MASK          0x8000  /* MIC_DET_FILTER_ENA */
-#define WM8904_MIC_DET_FILTER_ENA_SHIFT             15  /* MIC_DET_FILTER_ENA */
-#define WM8904_MIC_DET_FILTER_ENA_WIDTH              1  /* MIC_DET_FILTER_ENA */
-#define WM8904_MIC_SHORT_FILTER_ENA             0x4000  /* MIC_SHORT_FILTER_ENA */
-#define WM8904_MIC_SHORT_FILTER_ENA_MASK        0x4000  /* MIC_SHORT_FILTER_ENA */
-#define WM8904_MIC_SHORT_FILTER_ENA_SHIFT           14  /* MIC_SHORT_FILTER_ENA */
-#define WM8904_MIC_SHORT_FILTER_ENA_WIDTH            1  /* MIC_SHORT_FILTER_ENA */
-#define WM8904_MICBIAS_SEL_MASK                 0x0007  /* MICBIAS_SEL - [2:0] */
-#define WM8904_MICBIAS_SEL_SHIFT                     0  /* MICBIAS_SEL - [2:0] */
-#define WM8904_MICBIAS_SEL_WIDTH                     3  /* MICBIAS_SEL - [2:0] */
-
 /*
  * R8 (0x08) - Analogue DAC 0
  */
@@ -1199,70 +1166,6 @@ extern struct snd_soc_codec_device soc_codec_dev_wm8904;
 #define WM8904_FLL_CLK_REF_SRC_SHIFT                 0  /* FLL_CLK_REF_SRC - [1:0] */
 #define WM8904_FLL_CLK_REF_SRC_WIDTH                 2  /* FLL_CLK_REF_SRC - [1:0] */
 
-/*
- * R121 (0x79) - GPIO Control 1
- */
-#define WM8904_GPIO1_PU                         0x0020  /* GPIO1_PU */
-#define WM8904_GPIO1_PU_MASK                    0x0020  /* GPIO1_PU */
-#define WM8904_GPIO1_PU_SHIFT                        5  /* GPIO1_PU */
-#define WM8904_GPIO1_PU_WIDTH                        1  /* GPIO1_PU */
-#define WM8904_GPIO1_PD                         0x0010  /* GPIO1_PD */
-#define WM8904_GPIO1_PD_MASK                    0x0010  /* GPIO1_PD */
-#define WM8904_GPIO1_PD_SHIFT                        4  /* GPIO1_PD */
-#define WM8904_GPIO1_PD_WIDTH                        1  /* GPIO1_PD */
-#define WM8904_GPIO1_SEL_MASK                   0x000F  /* GPIO1_SEL - [3:0] */
-#define WM8904_GPIO1_SEL_SHIFT                       0  /* GPIO1_SEL - [3:0] */
-#define WM8904_GPIO1_SEL_WIDTH                       4  /* GPIO1_SEL - [3:0] */
-
-/*
- * R122 (0x7A) - GPIO Control 2
- */
-#define WM8904_GPIO2_PU                         0x0020  /* GPIO2_PU */
-#define WM8904_GPIO2_PU_MASK                    0x0020  /* GPIO2_PU */
-#define WM8904_GPIO2_PU_SHIFT                        5  /* GPIO2_PU */
-#define WM8904_GPIO2_PU_WIDTH                        1  /* GPIO2_PU */
-#define WM8904_GPIO2_PD                         0x0010  /* GPIO2_PD */
-#define WM8904_GPIO2_PD_MASK                    0x0010  /* GPIO2_PD */
-#define WM8904_GPIO2_PD_SHIFT                        4  /* GPIO2_PD */
-#define WM8904_GPIO2_PD_WIDTH                        1  /* GPIO2_PD */
-#define WM8904_GPIO2_SEL_MASK                   0x000F  /* GPIO2_SEL - [3:0] */
-#define WM8904_GPIO2_SEL_SHIFT                       0  /* GPIO2_SEL - [3:0] */
-#define WM8904_GPIO2_SEL_WIDTH                       4  /* GPIO2_SEL - [3:0] */
-
-/*
- * R123 (0x7B) - GPIO Control 3
- */
-#define WM8904_GPIO3_PU                         0x0020  /* GPIO3_PU */
-#define WM8904_GPIO3_PU_MASK                    0x0020  /* GPIO3_PU */
-#define WM8904_GPIO3_PU_SHIFT                        5  /* GPIO3_PU */
-#define WM8904_GPIO3_PU_WIDTH                        1  /* GPIO3_PU */
-#define WM8904_GPIO3_PD                         0x0010  /* GPIO3_PD */
-#define WM8904_GPIO3_PD_MASK                    0x0010  /* GPIO3_PD */
-#define WM8904_GPIO3_PD_SHIFT                        4  /* GPIO3_PD */
-#define WM8904_GPIO3_PD_WIDTH                        1  /* GPIO3_PD */
-#define WM8904_GPIO3_SEL_MASK                   0x000F  /* GPIO3_SEL - [3:0] */
-#define WM8904_GPIO3_SEL_SHIFT                       0  /* GPIO3_SEL - [3:0] */
-#define WM8904_GPIO3_SEL_WIDTH                       4  /* GPIO3_SEL - [3:0] */
-
-/*
- * R124 (0x7C) - GPIO Control 4
- */
-#define WM8904_GPI7_ENA                         0x0200  /* GPI7_ENA */
-#define WM8904_GPI7_ENA_MASK                    0x0200  /* GPI7_ENA */
-#define WM8904_GPI7_ENA_SHIFT                        9  /* GPI7_ENA */
-#define WM8904_GPI7_ENA_WIDTH                        1  /* GPI7_ENA */
-#define WM8904_GPI8_ENA                         0x0100  /* GPI8_ENA */
-#define WM8904_GPI8_ENA_MASK                    0x0100  /* GPI8_ENA */
-#define WM8904_GPI8_ENA_SHIFT                        8  /* GPI8_ENA */
-#define WM8904_GPI8_ENA_WIDTH                        1  /* GPI8_ENA */
-#define WM8904_GPIO_BCLK_MODE_ENA               0x0080  /* GPIO_BCLK_MODE_ENA */
-#define WM8904_GPIO_BCLK_MODE_ENA_MASK          0x0080  /* GPIO_BCLK_MODE_ENA */
-#define WM8904_GPIO_BCLK_MODE_ENA_SHIFT              7  /* GPIO_BCLK_MODE_ENA */
-#define WM8904_GPIO_BCLK_MODE_ENA_WIDTH              1  /* GPIO_BCLK_MODE_ENA */
-#define WM8904_GPIO_BCLK_SEL_MASK               0x000F  /* GPIO_BCLK_SEL - [3:0] */
-#define WM8904_GPIO_BCLK_SEL_SHIFT                   0  /* GPIO_BCLK_SEL - [3:0] */
-#define WM8904_GPIO_BCLK_SEL_WIDTH                   4  /* GPIO_BCLK_SEL - [3:0] */
-
 /*
  * R126 (0x7E) - Digital Pulls
  */
index 0c04b47..e3c4bbf 100644 (file)
@@ -581,7 +581,7 @@ static int wm8940_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                                 int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8940_priv *wm8940 = codec->private_data;
+       struct wm8940_priv *wm8940 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -692,7 +692,6 @@ static int wm8940_resume(struct platform_device *pdev)
        ret = wm8940_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
        if (ret)
                goto error_ret;
-       ret = wm8940_set_bias_level(codec, codec->suspend_bias_level);
 
 error_ret:
        return ret;
@@ -773,7 +772,7 @@ static int wm8940_register(struct wm8940_priv *wm8940,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8940;
+       snd_soc_codec_set_drvdata(codec, wm8940);
        codec->name = "WM8940";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index c8d7a80..fedb764 100644 (file)
@@ -235,7 +235,7 @@ static struct {
 
 static int wm8955_configure_clocking(struct snd_soc_codec *codec)
 {
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
        int i, ret, val;
        int clocking = 0;
        int srate = 0;
@@ -353,7 +353,7 @@ static int deemph_settings[] = { 0, 32000, 44100, 48000 };
 
 static int wm8955_set_deemph(struct snd_soc_codec *codec)
 {
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
        int val, i, best;
 
        /* If we're using deemphasis select the nearest available sample
@@ -382,7 +382,7 @@ static int wm8955_get_deemph(struct snd_kcontrol *kcontrol,
                             struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
 
        return wm8955->deemph;
 }
@@ -391,7 +391,7 @@ static int wm8955_put_deemph(struct snd_kcontrol *kcontrol,
                             struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
        int deemph = ucontrol->value.enumerated.item[0];
 
        if (deemph > 1)
@@ -598,7 +598,7 @@ static int wm8955_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
        int ret;
        int wl;
 
@@ -647,7 +647,7 @@ static int wm8955_set_sysclk(struct snd_soc_dai *dai, int clk_id,
                             unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8955_priv *priv = codec->private_data;
+       struct wm8955_priv *priv = snd_soc_codec_get_drvdata(codec);
        int div;
 
        switch (clk_id) {
@@ -770,7 +770,7 @@ static int wm8955_digital_mute(struct snd_soc_dai *codec_dai, int mute)
 static int wm8955_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct wm8955_priv *wm8955 = codec->private_data;
+       struct wm8955_priv *wm8955 = snd_soc_codec_get_drvdata(codec);
        int ret, i;
 
        switch (level) {
@@ -971,7 +971,7 @@ static int wm8955_register(struct wm8955_priv *wm8955,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8955;
+       snd_soc_codec_set_drvdata(codec, wm8955);
        codec->name = "WM8955";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index f1e63e0..7233cc6 100644 (file)
@@ -23,6 +23,7 @@
 #include <sound/soc-dapm.h>
 #include <sound/initval.h>
 #include <sound/tlv.h>
+#include <sound/wm8960.h>
 
 #include "wm8960.h"
 
 struct snd_soc_codec_device soc_codec_dev_wm8960;
 
 /* R25 - Power 1 */
+#define WM8960_VMID_MASK 0x180
 #define WM8960_VREF      0x40
 
+/* R26 - Power 2 */
+#define WM8960_PWR2_LOUT1      0x40
+#define WM8960_PWR2_ROUT1      0x20
+#define WM8960_PWR2_OUT3       0x02
+
 /* R28 - Anti-pop 1 */
 #define WM8960_POBCTRL   0x80
 #define WM8960_BUFDCOPEN 0x10
@@ -42,6 +49,7 @@ struct snd_soc_codec_device soc_codec_dev_wm8960;
 
 /* R29 - Anti-pop 2 */
 #define WM8960_DISOP     0x40
+#define WM8960_DRES_MASK 0x30
 
 /*
  * wm8960 register cache
@@ -68,6 +76,9 @@ static const u16 wm8960_reg[WM8960_CACHEREGNUM] = {
 struct wm8960_priv {
        u16 reg_cache[WM8960_CACHEREGNUM];
        struct snd_soc_codec codec;
+       struct snd_soc_dapm_widget *lout1;
+       struct snd_soc_dapm_widget *rout1;
+       struct snd_soc_dapm_widget *out3;
 };
 
 #define wm8960_reset(c)        snd_soc_write(c, WM8960_RESET, 0)
@@ -226,10 +237,6 @@ SND_SOC_DAPM_MIXER("Right Output Mixer", WM8960_POWER3, 2, 0,
        &wm8960_routput_mixer[0],
        ARRAY_SIZE(wm8960_routput_mixer)),
 
-SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0,
-       &wm8960_mono_out[0],
-       ARRAY_SIZE(wm8960_mono_out)),
-
 SND_SOC_DAPM_PGA("LOUT1 PGA", WM8960_POWER2, 6, 0, NULL, 0),
 SND_SOC_DAPM_PGA("ROUT1 PGA", WM8960_POWER2, 5, 0, NULL, 0),
 
@@ -248,6 +255,17 @@ SND_SOC_DAPM_OUTPUT("SPK_RN"),
 SND_SOC_DAPM_OUTPUT("OUT3"),
 };
 
+static const struct snd_soc_dapm_widget wm8960_dapm_widgets_out3[] = {
+SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0,
+       &wm8960_mono_out[0],
+       ARRAY_SIZE(wm8960_mono_out)),
+};
+
+/* Represent OUT3 as a PGA so that it gets turned on with LOUT1/ROUT1 */
+static const struct snd_soc_dapm_widget wm8960_dapm_widgets_capless[] = {
+SND_SOC_DAPM_PGA("OUT3 VMID", WM8960_POWER2, 1, 0, NULL, 0),
+};
+
 static const struct snd_soc_dapm_route audio_paths[] = {
        { "Left Boost Mixer", "LINPUT1 Switch", "LINPUT1" },
        { "Left Boost Mixer", "LINPUT2 Switch", "LINPUT2" },
@@ -278,9 +296,6 @@ static const struct snd_soc_dapm_route audio_paths[] = {
        { "Right Output Mixer", "Boost Bypass Switch", "Right Boost Mixer" } ,
        { "Right Output Mixer", "PCM Playback Switch", "Right DAC" },
 
-       { "Mono Output Mixer", "Left Switch", "Left Output Mixer" },
-       { "Mono Output Mixer", "Right Switch", "Right Output Mixer" },
-
        { "LOUT1 PGA", NULL, "Left Output Mixer" },
        { "ROUT1 PGA", NULL, "Right Output Mixer" },
 
@@ -297,17 +312,65 @@ static const struct snd_soc_dapm_route audio_paths[] = {
        { "SPK_LP", NULL, "Left Speaker Output" },
        { "SPK_RN", NULL, "Right Speaker Output" },
        { "SPK_RP", NULL, "Right Speaker Output" },
+};
+
+static const struct snd_soc_dapm_route audio_paths_out3[] = {
+       { "Mono Output Mixer", "Left Switch", "Left Output Mixer" },
+       { "Mono Output Mixer", "Right Switch", "Right Output Mixer" },
 
        { "OUT3", NULL, "Mono Output Mixer", }
 };
 
+static const struct snd_soc_dapm_route audio_paths_capless[] = {
+       { "HP_L", NULL, "OUT3 VMID" },
+       { "HP_R", NULL, "OUT3 VMID" },
+
+       { "OUT3 VMID", NULL, "Left Output Mixer" },
+       { "OUT3 VMID", NULL, "Right Output Mixer" },
+};
+
 static int wm8960_add_widgets(struct snd_soc_codec *codec)
 {
+       struct wm8960_data *pdata = codec->dev->platform_data;
+       struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
+       struct snd_soc_dapm_widget *w;
+
        snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets,
                                  ARRAY_SIZE(wm8960_dapm_widgets));
 
        snd_soc_dapm_add_routes(codec, audio_paths, ARRAY_SIZE(audio_paths));
 
+       /* In capless mode OUT3 is used to provide VMID for the
+        * headphone outputs, otherwise it is used as a mono mixer.
+        */
+       if (pdata && pdata->capless) {
+               snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets_capless,
+                                         ARRAY_SIZE(wm8960_dapm_widgets_capless));
+
+               snd_soc_dapm_add_routes(codec, audio_paths_capless,
+                                       ARRAY_SIZE(audio_paths_capless));
+       } else {
+               snd_soc_dapm_new_controls(codec, wm8960_dapm_widgets_out3,
+                                         ARRAY_SIZE(wm8960_dapm_widgets_out3));
+
+               snd_soc_dapm_add_routes(codec, audio_paths_out3,
+                                       ARRAY_SIZE(audio_paths_out3));
+       }
+
+       /* We need to power up the headphone output stage out of
+        * sequence for capless mode.  To save scanning the widget
+        * list each time to find the desired power state do so now
+        * and save the result.
+        */
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (strcmp(w->name, "LOUT1 PGA") == 0)
+                       wm8960->lout1 = w;
+               if (strcmp(w->name, "ROUT1 PGA") == 0)
+                       wm8960->rout1 = w;
+               if (strcmp(w->name, "OUT3 VMID") == 0)
+                       wm8960->out3 = w;
+       }
+       
        return 0;
 }
 
@@ -408,10 +471,9 @@ static int wm8960_mute(struct snd_soc_dai *dai, int mute)
        return 0;
 }
 
-static int wm8960_set_bias_level(struct snd_soc_codec *codec,
-                                enum snd_soc_bias_level level)
+static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
+                                     enum snd_soc_bias_level level)
 {
-       struct wm8960_data *pdata = codec->dev->platform_data;
        u16 reg;
 
        switch (level) {
@@ -430,18 +492,8 @@ static int wm8960_set_bias_level(struct snd_soc_codec *codec,
                if (codec->bias_level == SND_SOC_BIAS_OFF) {
                        /* Enable anti-pop features */
                        snd_soc_write(codec, WM8960_APOP1,
-                                    WM8960_POBCTRL | WM8960_SOFT_ST |
-                                    WM8960_BUFDCOPEN | WM8960_BUFIOEN);
-
-                       /* Discharge HP output */
-                       reg = WM8960_DISOP;
-                       if (pdata)
-                               reg |= pdata->dres << 4;
-                       snd_soc_write(codec, WM8960_APOP2, reg);
-
-                       msleep(400);
-
-                       snd_soc_write(codec, WM8960_APOP2, 0);
+                                     WM8960_POBCTRL | WM8960_SOFT_ST |
+                                     WM8960_BUFDCOPEN | WM8960_BUFIOEN);
 
                        /* Enable & ramp VMID at 2x50k */
                        reg = snd_soc_read(codec, WM8960_POWER1);
@@ -472,8 +524,101 @@ static int wm8960_set_bias_level(struct snd_soc_codec *codec,
                /* Disable VMID and VREF, let them discharge */
                snd_soc_write(codec, WM8960_POWER1, 0);
                msleep(600);
+               break;
+       }
+
+       codec->bias_level = level;
+
+       return 0;
+}
+
+static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
+                                        enum snd_soc_bias_level level)
+{
+       struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
+       int reg;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+
+       case SND_SOC_BIAS_PREPARE:
+               switch (codec->bias_level) {
+               case SND_SOC_BIAS_STANDBY:
+                       /* Enable anti pop mode */
+                       snd_soc_update_bits(codec, WM8960_APOP1,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN);
+
+                       /* Enable LOUT1, ROUT1 and OUT3 if they're enabled */
+                       reg = 0;
+                       if (wm8960->lout1 && wm8960->lout1->power)
+                               reg |= WM8960_PWR2_LOUT1;
+                       if (wm8960->rout1 && wm8960->rout1->power)
+                               reg |= WM8960_PWR2_ROUT1;
+                       if (wm8960->out3 && wm8960->out3->power)
+                               reg |= WM8960_PWR2_OUT3;
+                       snd_soc_update_bits(codec, WM8960_POWER2,
+                                           WM8960_PWR2_LOUT1 |
+                                           WM8960_PWR2_ROUT1 |
+                                           WM8960_PWR2_OUT3, reg);
+
+                       /* Enable VMID at 2*50k */
+                       snd_soc_update_bits(codec, WM8960_POWER1,
+                                           WM8960_VMID_MASK, 0x80);
+
+                       /* Ramp */
+                       msleep(100);
+
+                       /* Enable VREF */
+                       snd_soc_update_bits(codec, WM8960_POWER1,
+                                           WM8960_VREF, WM8960_VREF);
+
+                       msleep(100);
+                       break;
+
+               case SND_SOC_BIAS_ON:
+                       /* Enable anti-pop mode */
+                       snd_soc_update_bits(codec, WM8960_APOP1,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN);
+
+                       /* Disable VMID and VREF */
+                       snd_soc_update_bits(codec, WM8960_POWER1,
+                                           WM8960_VREF | WM8960_VMID_MASK, 0);
+                       break;
+
+               default:
+                       break;
+               }
+               break;
 
-               snd_soc_write(codec, WM8960_APOP1, 0);
+       case SND_SOC_BIAS_STANDBY:
+               switch (codec->bias_level) {
+               case SND_SOC_BIAS_PREPARE:
+                       /* Disable HP discharge */
+                       snd_soc_update_bits(codec, WM8960_APOP2,
+                                           WM8960_DISOP | WM8960_DRES_MASK,
+                                           0);
+
+                       /* Disable anti-pop features */
+                       snd_soc_update_bits(codec, WM8960_APOP1,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN,
+                                           WM8960_POBCTRL | WM8960_SOFT_ST |
+                                           WM8960_BUFDCOPEN);
+                       break;
+
+               default:
+                       break;
+               }
+               break;
+
+       case SND_SOC_BIAS_OFF:
                break;
        }
 
@@ -594,10 +739,6 @@ static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
        u16 reg;
 
        switch (div_id) {
-       case WM8960_SYSCLKSEL:
-               reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1fe;
-               snd_soc_write(codec, WM8960_CLOCK1, reg | div);
-               break;
        case WM8960_SYSCLKDIV:
                reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9;
                snd_soc_write(codec, WM8960_CLOCK1, reg | div);
@@ -663,7 +804,7 @@ static int wm8960_suspend(struct platform_device *pdev, pm_message_t state)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
 
-       wm8960_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       codec->set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
@@ -682,8 +823,8 @@ static int wm8960_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
 
-       wm8960_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8960_set_bias_level(codec, codec->suspend_bias_level);
+       codec->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
        return 0;
 }
 
@@ -753,6 +894,8 @@ static int wm8960_register(struct wm8960_priv *wm8960,
                goto err;
        }
 
+       codec->set_bias_level = wm8960_set_bias_level_out3;
+
        if (!pdata) {
                dev_warn(codec->dev, "No platform data supplied\n");
        } else {
@@ -760,17 +903,19 @@ static int wm8960_register(struct wm8960_priv *wm8960,
                        dev_err(codec->dev, "Invalid DRES: %d\n", pdata->dres);
                        pdata->dres = 0;
                }
+
+               if (pdata->capless)
+                       codec->set_bias_level = wm8960_set_bias_level_capless;
        }
 
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8960;
+       snd_soc_codec_set_drvdata(codec, wm8960);
        codec->name = "WM8960";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
-       codec->set_bias_level = wm8960_set_bias_level;
        codec->dai = &wm8960_dai;
        codec->num_dai = 1;
        codec->reg_cache_size = WM8960_CACHEREGNUM;
@@ -792,7 +937,7 @@ static int wm8960_register(struct wm8960_priv *wm8960,
 
        wm8960_dai.dev = codec->dev;
 
-       wm8960_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+       codec->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        /* Latch the update bits */
        reg = snd_soc_read(codec, WM8960_LINVOL);
@@ -841,7 +986,7 @@ err:
 
 static void wm8960_unregister(struct wm8960_priv *wm8960)
 {
-       wm8960_set_bias_level(&wm8960->codec, SND_SOC_BIAS_OFF);
+       wm8960->codec.set_bias_level(&wm8960->codec, SND_SOC_BIAS_OFF);
        snd_soc_unregister_dai(&wm8960_dai);
        snd_soc_unregister_codec(&wm8960->codec);
        kfree(wm8960);
@@ -883,7 +1028,7 @@ MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id);
 
 static struct i2c_driver wm8960_i2c_driver = {
        .driver = {
-               .name = "WM8960 I2C Codec",
+               .name = "wm8960",
                .owner = THIS_MODULE,
        },
        .probe =    wm8960_i2c_probe,
index c9af56c..a5ef654 100644 (file)
@@ -76,7 +76,6 @@
 #define WM8960_OPCLKDIV                        2
 #define WM8960_DCLKDIV                 3
 #define WM8960_TOCLKSEL                        4
-#define WM8960_SYSCLKSEL               5
 
 #define WM8960_SYSCLK_DIV_1            (0 << 1)
 #define WM8960_SYSCLK_DIV_2            (2 << 1)
 extern struct snd_soc_dai wm8960_dai;
 extern struct snd_soc_codec_device soc_codec_dev_wm8960;
 
-#define WM8960_DRES_400R 0
-#define WM8960_DRES_200R 1
-#define WM8960_DRES_600R 2
-#define WM8960_DRES_150R 3
-#define WM8960_DRES_MAX  3
-
-struct wm8960_data {
-       int dres;
-};
-
 #endif
index 50634ab..5b9a756 100644 (file)
@@ -631,7 +631,7 @@ static int wm8961_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8961_priv *wm8961 = codec->private_data;
+       struct wm8961_priv *wm8961 = snd_soc_codec_get_drvdata(codec);
        int i, best, target, fs;
        u16 reg;
 
@@ -722,7 +722,7 @@ static int wm8961_set_sysclk(struct snd_soc_dai *dai, int clk_id,
                             int dir)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8961_priv *wm8961 = codec->private_data;
+       struct wm8961_priv *wm8961 = snd_soc_codec_get_drvdata(codec);
        u16 reg = snd_soc_read(codec, WM8961_CLOCKING1);
 
        if (freq > 33000000) {
@@ -1065,7 +1065,7 @@ static int wm8961_register(struct wm8961_priv *wm8961)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8961;
+       snd_soc_codec_set_drvdata(codec, wm8961);
        codec->name = "WM8961";
        codec->owner = THIS_MODULE;
        codec->dai = &wm8961_dai;
index a65b781..a99620f 100644 (file)
@@ -415,7 +415,7 @@ static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8971_priv *wm8971 = codec->private_data;
+       struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -494,7 +494,7 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8971_priv *wm8971 = codec->private_data;
+       struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8971_IFACE) & 0x1f3;
        u16 srate = snd_soc_read(codec, WM8971_SRATE) & 0x1c0;
        int coeff = get_coeff(wm8971->sysclk, params_rate(params));
@@ -820,7 +820,7 @@ static int wm8971_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
-       codec->private_data = wm8971;
+       snd_soc_codec_set_drvdata(codec, wm8971);
        socdev->card->codec = codec;
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -830,7 +830,7 @@ static int wm8971_probe(struct platform_device *pdev)
        INIT_DELAYED_WORK(&codec->delayed_work, wm8971_work);
        wm8971_workq = create_workqueue("wm8971");
        if (wm8971_workq == NULL) {
-               kfree(codec->private_data);
+               kfree(snd_soc_codec_get_drvdata(codec));
                kfree(codec);
                return -ENOMEM;
        }
@@ -844,7 +844,7 @@ static int wm8971_probe(struct platform_device *pdev)
 
        if (ret != 0) {
                destroy_workqueue(wm8971_workq);
-               kfree(codec->private_data);
+               kfree(snd_soc_codec_get_drvdata(codec));
                kfree(codec);
        }
 
@@ -867,7 +867,7 @@ static int wm8971_remove(struct platform_device *pdev)
        i2c_unregister_device(codec->control_data);
        i2c_del_driver(&wm8971_i2c_driver);
 #endif
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec);
 
        return 0;
index 69708c4..a2c4b2f 100644 (file)
@@ -181,7 +181,7 @@ SOC_SINGLE("ADC 128x Oversampling Switch", WM8974_ADC, 8, 1, 0),
 static const struct snd_kcontrol_new wm8974_speaker_mixer_controls[] = {
 SOC_DAPM_SINGLE("Line Bypass Switch", WM8974_SPKMIX, 1, 1, 0),
 SOC_DAPM_SINGLE("Aux Playback Switch", WM8974_SPKMIX, 5, 1, 0),
-SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_SPKMIX, 0, 1, 1),
+SOC_DAPM_SINGLE("PCM Playback Switch", WM8974_SPKMIX, 0, 1, 0),
 };
 
 /* Mono Output Mixer */
@@ -609,7 +609,7 @@ static int wm8974_resume(struct platform_device *pdev)
                codec->hw_write(codec->control_data, data, 2);
        }
        wm8974_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
-       wm8974_set_bias_level(codec, codec->suspend_bias_level);
+
        return 0;
 }
 
@@ -677,7 +677,7 @@ static __devinit int wm8974_register(struct wm8974_priv *wm8974)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8974;
+       snd_soc_codec_set_drvdata(codec, wm8974);
        codec->name = "WM8974";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index 526f56b..51d5f43 100644 (file)
@@ -439,7 +439,7 @@ static int wm8978_enum_mclk(unsigned int f_out, unsigned int f_mclk,
  */
 static int wm8978_configure_pll(struct snd_soc_codec *codec)
 {
-       struct wm8978_priv *wm8978 = codec->private_data;
+       struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
        struct wm8978_pll_div pll_div;
        unsigned int f_opclk = wm8978->f_opclk, f_mclk = wm8978->f_mclk,
                f_256fs = wm8978->f_256fs;
@@ -535,7 +535,7 @@ static int wm8978_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
                                 int div_id, int div)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8978_priv *wm8978 = codec->private_data;
+       struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        switch (div_id) {
@@ -580,7 +580,7 @@ static int wm8978_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id,
                                 unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8978_priv *wm8978 = codec->private_data;
+       struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
 
        dev_dbg(codec->dev, "%s: ID %d, freq %u\n", __func__, clk_id, freq);
@@ -692,7 +692,7 @@ static int wm8978_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8978_priv *wm8978 = codec->private_data;
+       struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
        /* Word length mask = 0x60 */
        u16 iface_ctl = snd_soc_read(codec, WM8978_AUDIO_INTERFACE) & ~0x60;
        /* Sampling rate mask = 0xe (for filters) */
@@ -912,7 +912,7 @@ static int wm8978_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8978_priv *wm8978 = codec->private_data;
+       struct wm8978_priv *wm8978 = snd_soc_codec_get_drvdata(codec);
        int i;
        u16 *cache = codec->reg_cache;
 
@@ -1020,7 +1020,7 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8978;
+       snd_soc_codec_set_drvdata(codec, wm8978);
        codec->name = "WM8978";
        codec->owner = THIS_MODULE;
        codec->bias_level = SND_SOC_BIAS_OFF;
index bb18c3e..0417dae 100644 (file)
@@ -495,7 +495,7 @@ static int wm8988_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8988_priv *wm8988 = codec->private_data;
+       struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
 
        switch (freq) {
        case 11289600:
@@ -585,7 +585,7 @@ static int wm8988_pcm_startup(struct snd_pcm_substream *substream,
                              struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8988_priv *wm8988 = codec->private_data;
+       struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
 
        /* The set of sample rates that can be supported depends on the
         * MCLK supplied to the CODEC - enforce this.
@@ -610,7 +610,7 @@ static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_device *socdev = rtd->socdev;
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8988_priv *wm8988 = codec->private_data;
+       struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3;
        u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180;
        int coeff;
@@ -833,7 +833,7 @@ static int wm8988_register(struct wm8988_priv *wm8988,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8988;
+       snd_soc_codec_set_drvdata(codec, wm8988);
        codec->name = "WM8988";
        codec->owner = THIS_MODULE;
        codec->dai = &wm8988_dai;
index 831f473..7b536d9 100644 (file)
@@ -1012,7 +1012,7 @@ static int wm8990_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8990_priv *wm8990 = codec->private_data;
+       struct wm8990_priv *wm8990 = snd_soc_codec_get_drvdata(codec);
 
        wm8990->sysclk = freq;
        return 0;
@@ -1524,7 +1524,7 @@ static int wm8990_probe(struct platform_device *pdev)
                return -ENOMEM;
        }
 
-       codec->private_data = wm8990;
+       snd_soc_codec_set_drvdata(codec, wm8990);
        socdev->card->codec = codec;
        mutex_init(&codec->mutex);
        INIT_LIST_HEAD(&codec->dapm_widgets);
@@ -1541,7 +1541,7 @@ static int wm8990_probe(struct platform_device *pdev)
 #endif
 
        if (ret != 0) {
-               kfree(codec->private_data);
+               kfree(snd_soc_codec_get_drvdata(codec));
                kfree(codec);
        }
        return ret;
@@ -1561,7 +1561,7 @@ static int wm8990_remove(struct platform_device *pdev)
        i2c_unregister_device(codec->control_data);
        i2c_del_driver(&wm8990_i2c_driver);
 #endif
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec);
 
        return 0;
index 03e8b1a..d8d300c 100644 (file)
@@ -371,7 +371,7 @@ static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
                          unsigned int Fref, unsigned int Fout)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        u16 reg1, reg4, reg5;
        struct _fll_div fll_div;
        int ret;
@@ -458,7 +458,7 @@ static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id, int source,
 
 static int configure_clock(struct snd_soc_codec *codec)
 {
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        unsigned int reg;
 
        /* This should be done on init() for bypass paths */
@@ -717,7 +717,7 @@ static int class_w_put(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct snd_soc_codec *codec = widget->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        /* Turn it off if we're using the main output mixer */
@@ -949,7 +949,7 @@ static void wm8993_cache_restore(struct snd_soc_codec *codec)
 static int wm8993_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        switch (level) {
@@ -1047,7 +1047,7 @@ static int wm8993_set_sysclk(struct snd_soc_dai *codec_dai,
                             int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
 
        switch (clk_id) {
        case WM8993_SYSCLK_MCLK:
@@ -1067,7 +1067,7 @@ static int wm8993_set_dai_fmt(struct snd_soc_dai *dai,
                              unsigned int fmt)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        unsigned int aif1 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_1);
        unsigned int aif4 = snd_soc_read(codec, WM8993_AUDIO_INTERFACE_4);
 
@@ -1163,7 +1163,7 @@ static int wm8993_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int ret, i, best, best_val, cur_val;
        unsigned int clocking1, clocking3, aif1, aif4;
 
@@ -1328,7 +1328,7 @@ static int wm8993_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
                               unsigned int rx_mask, int slots, int slot_width)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int aif1 = 0;
        int aif2 = 0;
 
@@ -1431,7 +1431,7 @@ static int wm8993_probe(struct platform_device *pdev)
 
        socdev->card->codec = wm8993_codec;
        codec = wm8993_codec;
-       wm8993 = codec->private_data;
+       wm8993 = snd_soc_codec_get_drvdata(codec);
 
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
        if (ret < 0) {
@@ -1478,7 +1478,7 @@ static int wm8993_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int fll_fout = wm8993->fll_fout;
        int fll_fref  = wm8993->fll_fref;
        int ret;
@@ -1502,7 +1502,7 @@ static int wm8993_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8993_priv *wm8993 = codec->private_data;
+       struct wm8993_priv *wm8993 = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -1571,7 +1571,7 @@ static int wm8993_i2c_probe(struct i2c_client *i2c,
        codec->set_bias_level = wm8993_set_bias_level;
        codec->dai = &wm8993_dai;
        codec->num_dai = 1;
-       codec->private_data = wm8993;
+       snd_soc_codec_set_drvdata(codec, wm8993);
 
        wm8993->hubs_data.hp_startup_mode = 1;
        wm8993->hubs_data.dcs_codes = -2;
index 9da0724..e84a117 100644 (file)
@@ -62,6 +62,12 @@ static int wm8994_retune_mobile_base[] = {
 
 #define WM8994_REG_CACHE_SIZE  0x621
 
+struct wm8994_micdet {
+       struct snd_soc_jack *jack;
+       int det;
+       int shrt;
+};
+
 /* codec private data */
 struct wm8994_priv {
        struct wm_hubs_data hubs;
@@ -87,6 +93,8 @@ struct wm8994_priv {
        int retune_mobile_cfg[WM8994_NUM_EQ];
        struct soc_enum retune_mobile_enum;
 
+       struct wm8994_micdet micdet[2];
+
        struct wm8994_pdata *pdata;
 };
 
@@ -1696,13 +1704,15 @@ static int wm8994_volatile(unsigned int reg)
 static int wm8994_write(struct snd_soc_codec *codec, unsigned int reg,
        unsigned int value)
 {
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
 
        BUG_ON(reg > WM8994_MAX_REGISTER);
 
        if (!wm8994_volatile(reg))
                wm8994->reg_cache[reg] = value;
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        return wm8994_reg_write(codec->control_data, reg, value);
 }
 
@@ -1721,7 +1731,7 @@ static unsigned int wm8994_read(struct snd_soc_codec *codec,
 
 static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
 {
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int rate;
        int reg1 = 0;
        int offset;
@@ -1762,6 +1772,11 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
                dev_dbg(codec->dev, "Dividing AIF%d clock to %dHz\n",
                        aif + 1, rate);
        }
+
+       if (rate && rate < 3000000)
+               dev_warn(codec->dev, "AIF%dCLK is %dHz, should be >=3MHz for optimal performance\n",
+                        aif + 1, rate);
+
        wm8994->aifclk[aif] = rate;
 
        snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1 + offset,
@@ -1773,7 +1788,7 @@ static int configure_aif_clock(struct snd_soc_codec *codec, int aif)
 
 static int configure_clock(struct snd_soc_codec *codec)
 {
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int old, new;
 
        /* Bring up the AIF clocks first */
@@ -1870,7 +1885,7 @@ static int wm8994_put_drc_sw(struct snd_kcontrol *kcontrol,
 
 static void wm8994_set_drc(struct snd_soc_codec *codec, int drc)
 {
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct wm8994_pdata *pdata = wm8994->pdata;
        int base = wm8994_drc_base[drc];
        int cfg = wm8994->drc_cfg[drc];
@@ -1906,7 +1921,7 @@ static int wm8994_put_drc_enum(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8994_priv *wm8994 = codec->private_data;       
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);  
        struct wm8994_pdata *pdata = wm8994->pdata;
        int drc = wm8994_get_drc(kcontrol->id.name);
        int value = ucontrol->value.integer.value[0];
@@ -1928,7 +1943,7 @@ static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int drc = wm8994_get_drc(kcontrol->id.name);
 
        ucontrol->value.enumerated.item[0] = wm8994->drc_cfg[drc];
@@ -1938,7 +1953,7 @@ static int wm8994_get_drc_enum(struct snd_kcontrol *kcontrol,
 
 static void wm8994_set_retune_mobile(struct snd_soc_codec *codec, int block)
 {
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        struct wm8994_pdata *pdata = wm8994->pdata;
        int base = wm8994_retune_mobile_base[block];
        int iface, best, best_val, save, i, cfg;
@@ -2009,7 +2024,7 @@ static int wm8994_put_retune_mobile_enum(struct snd_kcontrol *kcontrol,
                                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8994_priv *wm8994 = codec->private_data;       
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);  
        struct wm8994_pdata *pdata = wm8994->pdata;
        int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
        int value = ucontrol->value.integer.value[0];
@@ -2031,7 +2046,7 @@ static int wm8994_get_retune_mobile_enum(struct snd_kcontrol *kcontrol,
                                         struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int block = wm8994_get_retune_mobile_block(kcontrol->id.name);
 
        ucontrol->value.enumerated.item[0] = wm8994->retune_mobile_cfg[block];
@@ -2182,13 +2197,13 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec)
        /* Only support direct DAC->headphone paths */
        reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_1);
        if (!(reg & WM8994_DAC1L_TO_HPOUT1L)) {
-               dev_dbg(codec->dev, "HPL connected to output mixer\n");
+               dev_vdbg(codec->dev, "HPL connected to output mixer\n");
                enable = 0;
        }
 
        reg = snd_soc_read(codec, WM8994_OUTPUT_MIXER_2);
        if (!(reg & WM8994_DAC1R_TO_HPOUT1R)) {
-               dev_dbg(codec->dev, "HPR connected to output mixer\n");
+               dev_vdbg(codec->dev, "HPR connected to output mixer\n");
                enable = 0;
        }
 
@@ -2196,26 +2211,26 @@ static void wm8994_update_class_w(struct snd_soc_codec *codec)
        reg = snd_soc_read(codec, WM8994_DAC1_LEFT_MIXER_ROUTING);
        switch (reg) {
        case WM8994_AIF2DACL_TO_DAC1L:
-               dev_dbg(codec->dev, "Class W source AIF2DAC\n");
+               dev_vdbg(codec->dev, "Class W source AIF2DAC\n");
                source = 2 << WM8994_CP_DYN_SRC_SEL_SHIFT;
                break;
        case WM8994_AIF1DAC2L_TO_DAC1L:
-               dev_dbg(codec->dev, "Class W source AIF1DAC2\n");
+               dev_vdbg(codec->dev, "Class W source AIF1DAC2\n");
                source = 1 << WM8994_CP_DYN_SRC_SEL_SHIFT;
                break;
        case WM8994_AIF1DAC1L_TO_DAC1L:
-               dev_dbg(codec->dev, "Class W source AIF1DAC1\n");
+               dev_vdbg(codec->dev, "Class W source AIF1DAC1\n");
                source = 0 << WM8994_CP_DYN_SRC_SEL_SHIFT;
                break;
        default:
-               dev_dbg(codec->dev, "DAC mixer setting: %x\n", reg);
+               dev_vdbg(codec->dev, "DAC mixer setting: %x\n", reg);
                enable = 0;
                break;
        }
 
        reg_r = snd_soc_read(codec, WM8994_DAC1_RIGHT_MIXER_ROUTING);
        if (reg_r != reg) {
-               dev_dbg(codec->dev, "Left and right DAC mixers different\n");
+               dev_vdbg(codec->dev, "Left and right DAC mixers different\n");
                enable = 0;
        }
 
@@ -2777,9 +2792,18 @@ static int wm8994_get_fll_config(struct fll_div *fll,
 
        if (freq_in > 1000000) {
                fll->fll_fratio = 0;
-       } else {
+       } else if (freq_in > 256000) {
+               fll->fll_fratio = 1;
+               freq_in *= 2;
+       } else if (freq_in > 128000) {
+               fll->fll_fratio = 2;
+               freq_in *= 4;
+       } else if (freq_in > 64000) {
                fll->fll_fratio = 3;
                freq_in *= 8;
+       } else {
+               fll->fll_fratio = 4;
+               freq_in *= 16;
        }
        pr_debug("FLL_FRATIO=%d, Fref=%dHz\n", fll->fll_fratio, freq_in);
 
@@ -2812,7 +2836,7 @@ static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
                          unsigned int freq_in, unsigned int freq_out)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int reg_offset, ret;
        struct fll_div fll;
        u16 reg, aif1, aif2;
@@ -2836,6 +2860,21 @@ static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
                return -EINVAL;
        }
 
+       switch (src) {
+       case 0:
+               /* Allow no source specification when stopping */
+               if (freq_out)
+                       return -EINVAL;
+               break;
+       case WM8994_FLL_SRC_MCLK1:
+       case WM8994_FLL_SRC_MCLK2:
+       case WM8994_FLL_SRC_LRCLK:
+       case WM8994_FLL_SRC_BCLK:
+               break;
+       default:
+               return -EINVAL;
+       }
+
        /* Are we changing anything? */
        if (wm8994->fll[id].src == src &&
            wm8994->fll[id].in == freq_in && wm8994->fll[id].out == freq_out)
@@ -2876,8 +2915,10 @@ static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
                                    fll.n << WM8994_FLL1_N_SHIFT);
 
        snd_soc_update_bits(codec, WM8994_FLL1_CONTROL_5 + reg_offset,
-                           WM8994_FLL1_REFCLK_DIV_MASK,
-                           fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT);
+                           WM8994_FLL1_REFCLK_DIV_MASK |
+                           WM8994_FLL1_REFCLK_SRC_MASK,
+                           (fll.clk_ref_div << WM8994_FLL1_REFCLK_DIV_SHIFT) |
+                           (src - 1));
 
        /* Enable (with fractional mode if required) */
        if (freq_out) {
@@ -2892,6 +2933,7 @@ static int wm8994_set_fll(struct snd_soc_dai *dai, int id, int src,
 
        wm8994->fll[id].in = freq_in;
        wm8994->fll[id].out = freq_out;
+       wm8994->fll[id].src = src;
 
        /* Enable any gated AIF clocks */
        snd_soc_update_bits(codec, WM8994_AIF1_CLOCKING_1,
@@ -2908,7 +2950,7 @@ static int wm8994_set_dai_sysclk(struct snd_soc_dai *dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
 
        switch (dai->id) {
        case 1:
@@ -3174,7 +3216,7 @@ static int wm8994_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int aif1_reg;
        int bclk_reg;
        int lrclk_reg;
@@ -3338,6 +3380,36 @@ static int wm8994_aif_mute(struct snd_soc_dai *codec_dai, int mute)
        return 0;
 }
 
+static int wm8994_set_tristate(struct snd_soc_dai *codec_dai, int tristate)
+{
+       struct snd_soc_codec *codec = codec_dai->codec;
+       int reg, val, mask;
+
+       switch (codec_dai->id) {
+       case 1:
+               reg = WM8994_AIF1_MASTER_SLAVE;
+               mask = WM8994_AIF1_TRI;
+               break;
+       case 2:
+               reg = WM8994_AIF2_MASTER_SLAVE;
+               mask = WM8994_AIF2_TRI;
+               break;
+       case 3:
+               reg = WM8994_POWER_MANAGEMENT_6;
+               mask = WM8994_AIF3_TRI;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (tristate)
+               val = mask;
+       else
+               val = 0;
+
+       return snd_soc_update_bits(codec, reg, mask, reg);
+}
+
 #define WM8994_RATES SNDRV_PCM_RATE_8000_96000
 
 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
@@ -3349,6 +3421,7 @@ static struct snd_soc_dai_ops wm8994_aif1_dai_ops = {
        .hw_params      = wm8994_hw_params,
        .digital_mute   = wm8994_aif_mute,
        .set_pll        = wm8994_set_fll,
+       .set_tristate   = wm8994_set_tristate,
 };
 
 static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
@@ -3357,6 +3430,11 @@ static struct snd_soc_dai_ops wm8994_aif2_dai_ops = {
        .hw_params      = wm8994_hw_params,
        .digital_mute   = wm8994_aif_mute,
        .set_pll        = wm8994_set_fll,
+       .set_tristate   = wm8994_set_tristate,
+};
+
+static struct snd_soc_dai_ops wm8994_aif3_dai_ops = {
+       .set_tristate   = wm8994_set_tristate,
 };
 
 struct snd_soc_dai wm8994_dai[] = {
@@ -3400,6 +3478,7 @@ struct snd_soc_dai wm8994_dai[] = {
        },
        {
                .name = "WM8994 AIF3",
+               .id = 3,
                .playback = {
                        .stream_name = "AIF3 Playback",
                        .channels_min = 2,
@@ -3414,6 +3493,7 @@ struct snd_soc_dai wm8994_dai[] = {
                        .rates = WM8994_RATES,
                        .formats = WM8994_FORMATS,
                },
+               .ops = &wm8994_aif3_dai_ops,
        }
 };
 EXPORT_SYMBOL_GPL(wm8994_dai);
@@ -3423,7 +3503,7 @@ static int wm8994_suspend(struct platform_device *pdev, pm_message_t state)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        int i, ret;
 
        for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
@@ -3444,7 +3524,7 @@ static int wm8994_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm8994_priv *wm8994 = codec->private_data;
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
        u16 *reg_cache = codec->reg_cache;
        int i, ret;
 
@@ -3469,6 +3549,9 @@ static int wm8994_resume(struct platform_device *pdev)
        wm8994_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        for (i = 0; i < ARRAY_SIZE(wm8994->fll); i++) {
+               if (!wm8994->fll_suspend[i].out)
+                       continue;
+
                ret = wm8994_set_fll(&codec->dai[0], i + 1,
                                     wm8994->fll_suspend[i].src,
                                     wm8994->fll_suspend[i].in,
@@ -3639,7 +3722,7 @@ static int wm8994_probe(struct platform_device *pdev)
                return ret;
        }
 
-       wm8994_handle_pdata(codec->private_data);
+       wm8994_handle_pdata(snd_soc_codec_get_drvdata(codec));
 
        wm_hubs_add_analogue_controls(codec);
        snd_soc_add_controls(codec, wm8994_snd_controls,
@@ -3670,6 +3753,96 @@ struct snd_soc_codec_device soc_codec_dev_wm8994 = {
 };
 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8994);
 
+/**
+ * wm8994_mic_detect - Enable microphone detection via the WM8994 IRQ
+ *
+ * @codec:   WM8994 codec
+ * @jack:    jack to report detection events on
+ * @micbias: microphone bias to detect on
+ * @det:     value to report for presence detection
+ * @shrt:    value to report for short detection
+ *
+ * Enable microphone detection via IRQ on the WM8994.  If GPIOs are
+ * being used to bring out signals to the processor then only platform
+ * data configuration is needed for WM8903 and processor GPIOs should
+ * be configured using snd_soc_jack_add_gpios() instead.
+ *
+ * Configuration of detection levels is available via the micbias1_lvl
+ * and micbias2_lvl platform data members.
+ */
+int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
+                     int micbias, int det, int shrt)
+{
+       struct wm8994_priv *wm8994 = snd_soc_codec_get_drvdata(codec);
+       struct wm8994_micdet *micdet;
+       int reg;
+
+       switch (micbias) {
+       case 1:
+               micdet = &wm8994->micdet[0];
+               break;
+       case 2:
+               micdet = &wm8994->micdet[1];
+               break;
+       default:
+               return -EINVAL;
+       }       
+
+       dev_dbg(codec->dev, "Configuring microphone detection on %d: %x %x\n",
+               micbias, det, shrt);
+
+       /* Store the configuration */
+       micdet->jack = jack;
+       micdet->det = det;
+       micdet->shrt = shrt;
+
+       /* If either of the jacks is set up then enable detection */
+       if (wm8994->micdet[0].jack || wm8994->micdet[1].jack)
+               reg = WM8994_MICD_ENA;
+       else 
+               reg = 0;
+
+       snd_soc_update_bits(codec, WM8994_MICBIAS, WM8994_MICD_ENA, reg);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8994_mic_detect);
+
+static irqreturn_t wm8994_mic_irq(int irq, void *data)
+{
+       struct wm8994_priv *priv = data;
+       struct snd_soc_codec *codec = &priv->codec;
+       int reg;
+       int report;
+
+       reg = snd_soc_read(codec, WM8994_INTERRUPT_RAW_STATUS_2);
+       if (reg < 0) {
+               dev_err(codec->dev, "Failed to read microphone status: %d\n",
+                       reg);
+               return IRQ_HANDLED;
+       }
+
+       dev_dbg(codec->dev, "Microphone status: %x\n", reg);
+
+       report = 0;
+       if (reg & WM8994_MIC1_DET_STS)
+               report |= priv->micdet[0].det;
+       if (reg & WM8994_MIC1_SHRT_STS)
+               report |= priv->micdet[0].shrt;
+       snd_soc_jack_report(priv->micdet[0].jack, report,
+                           priv->micdet[0].det | priv->micdet[0].shrt);
+
+       report = 0;
+       if (reg & WM8994_MIC2_DET_STS)
+               report |= priv->micdet[1].det;
+       if (reg & WM8994_MIC2_SHRT_STS)
+               report |= priv->micdet[1].shrt;
+       snd_soc_jack_report(priv->micdet[1].jack, report,
+                           priv->micdet[1].det | priv->micdet[1].shrt);
+
+       return IRQ_HANDLED;
+}
+
 static int wm8994_codec_probe(struct platform_device *pdev)
 {
        int ret;
@@ -3695,7 +3868,7 @@ static int wm8994_codec_probe(struct platform_device *pdev)
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm8994;
+       snd_soc_codec_set_drvdata(codec, wm8994);
        codec->control_data = dev_get_drvdata(pdev->dev.parent);
        codec->name = "WM8994";
        codec->owner = THIS_MODULE;
@@ -3743,6 +3916,30 @@ static int wm8994_codec_probe(struct platform_device *pdev)
                break;
        }
 
+       ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_DET,
+                                wm8994_mic_irq, "Mic 1 detect", wm8994);
+       if (ret != 0)
+               dev_warn(&pdev->dev,
+                        "Failed to request Mic1 detect IRQ: %d\n", ret);
+
+       ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT,
+                                wm8994_mic_irq, "Mic 1 short", wm8994);
+       if (ret != 0)
+               dev_warn(&pdev->dev,
+                        "Failed to request Mic1 short IRQ: %d\n", ret);
+
+       ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_DET,
+                                wm8994_mic_irq, "Mic 2 detect", wm8994);
+       if (ret != 0)
+               dev_warn(&pdev->dev,
+                        "Failed to request Mic2 detect IRQ: %d\n", ret);
+
+       ret = wm8994_request_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT,
+                                wm8994_mic_irq, "Mic 2 short", wm8994);
+       if (ret != 0)
+               dev_warn(&pdev->dev,
+                        "Failed to request Mic2 short IRQ: %d\n", ret);
+
        /* Remember if AIFnLRCLK is configured as a GPIO.  This should be
         * configured on init - if a system wants to do this dynamically
         * at runtime we can deal with that then.
@@ -3750,7 +3947,7 @@ static int wm8994_codec_probe(struct platform_device *pdev)
        ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_1);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to read GPIO1 state: %d\n", ret);
-               goto err;
+               goto err_irq;
        }
        if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
                wm8994->lrclk_shared[0] = 1;
@@ -3762,7 +3959,7 @@ static int wm8994_codec_probe(struct platform_device *pdev)
        ret = wm8994_reg_read(codec->control_data, WM8994_GPIO_6);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to read GPIO6 state: %d\n", ret);
-               goto err;
+               goto err_irq;
        }
        if ((ret & WM8994_GPN_FN_MASK) != WM8994_GP_FN_PIN_SPECIFIC) {
                wm8994->lrclk_shared[1] = 1;
@@ -3812,7 +4009,7 @@ static int wm8994_codec_probe(struct platform_device *pdev)
        ret = snd_soc_register_codec(codec);
        if (ret != 0) {
                dev_err(codec->dev, "Failed to register codec: %d\n", ret);
-               goto err;
+               goto err_irq;
        }
 
        ret = snd_soc_register_dais(wm8994_dai, ARRAY_SIZE(wm8994_dai));
@@ -3827,6 +4024,11 @@ static int wm8994_codec_probe(struct platform_device *pdev)
 
 err_codec:
        snd_soc_unregister_codec(codec);
+err_irq:
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994);
 err:
        kfree(wm8994);
        return ret;
@@ -3840,6 +4042,10 @@ static int __devexit wm8994_codec_remove(struct platform_device *pdev)
        wm8994_set_bias_level(codec, SND_SOC_BIAS_OFF);
        snd_soc_unregister_dais(wm8994_dai, ARRAY_SIZE(wm8994_dai));
        snd_soc_unregister_codec(&wm8994->codec);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_SHRT, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC2_DET, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_SHRT, wm8994);
+       wm8994_free_irq(codec->control_data, WM8994_IRQ_MIC1_DET, wm8994);
        kfree(wm8994);
        wm8994_codec = NULL;
 
index 0a5e142..7072dc5 100644 (file)
@@ -23,4 +23,12 @@ extern struct snd_soc_dai wm8994_dai[];
 #define WM8994_FLL1 1
 #define WM8994_FLL2 2
 
+#define WM8994_FLL_SRC_MCLK1  1
+#define WM8994_FLL_SRC_MCLK2  2
+#define WM8994_FLL_SRC_LRCLK  3
+#define WM8994_FLL_SRC_BCLK   4
+
+int wm8994_mic_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack,
+                     int micbias, int det, int shrt);
+
 #endif
index 3a184fc..13186fb 100644 (file)
@@ -521,7 +521,7 @@ static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
 static int wm9081_set_fll(struct snd_soc_codec *codec, int fll_id,
                          unsigned int Fref, unsigned int Fout)
 {
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
        u16 reg1, reg4, reg5;
        struct _fll_div fll_div;
        int ret;
@@ -607,7 +607,7 @@ static int wm9081_set_fll(struct snd_soc_codec *codec, int fll_id,
 
 static int configure_clock(struct snd_soc_codec *codec)
 {
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
        int new_sysclk, i, target;
        unsigned int reg;
        int ret = 0;
@@ -702,7 +702,7 @@ static int clk_sys_event(struct snd_soc_dapm_widget *w,
                         struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
 
        /* This should be done on init() for bypass paths */
        switch (wm9081->sysclk_source) {
@@ -873,7 +873,7 @@ static int wm9081_set_dai_fmt(struct snd_soc_dai *dai,
                              unsigned int fmt)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
        unsigned int aif2 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_2);
 
        aif2 &= ~(WM9081_AIF_BCLK_INV | WM9081_AIF_LRCLK_INV |
@@ -965,7 +965,7 @@ static int wm9081_hw_params(struct snd_pcm_substream *substream,
                            struct snd_soc_dai *dai)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
        int ret, i, best, best_val, cur_val;
        unsigned int clk_ctrl2, aif1, aif2, aif3, aif4;
 
@@ -1139,7 +1139,7 @@ static int wm9081_set_sysclk(struct snd_soc_dai *codec_dai,
                             int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
 
        switch (clk_id) {
        case WM9081_SYSCLK_MCLK:
@@ -1159,7 +1159,7 @@ static int wm9081_set_tdm_slot(struct snd_soc_dai *dai,
        unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
 {
        struct snd_soc_codec *codec = dai->codec;
-       struct wm9081_priv *wm9081 = codec->private_data;
+       struct wm9081_priv *wm9081 = snd_soc_codec_get_drvdata(codec);
        unsigned int aif1 = snd_soc_read(codec, WM9081_AUDIO_INTERFACE_1);
 
        aif1 &= ~(WM9081_AIFDAC_TDM_SLOT_MASK | WM9081_AIFDAC_TDM_MODE_MASK);
@@ -1242,7 +1242,7 @@ static int wm9081_probe(struct platform_device *pdev)
 
        socdev->card->codec = wm9081_codec;
        codec = wm9081_codec;
-       wm9081 = codec->private_data;
+       wm9081 = snd_soc_codec_get_drvdata(codec);
 
        /* register pcms */
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
@@ -1339,7 +1339,7 @@ static int wm9081_register(struct wm9081_priv *wm9081,
        INIT_LIST_HEAD(&codec->dapm_widgets);
        INIT_LIST_HEAD(&codec->dapm_paths);
 
-       codec->private_data = wm9081;
+       snd_soc_codec_set_drvdata(codec, wm9081);
        codec->name = "WM9081";
        codec->owner = THIS_MODULE;
        codec->dai = &wm9081_dai;
diff --git a/sound/soc/codecs/wm9090.c b/sound/soc/codecs/wm9090.c
new file mode 100644 (file)
index 0000000..1592250
--- /dev/null
@@ -0,0 +1,773 @@
+/*
+ * ALSA SoC WM9090 driver
+ *
+ * Copyright 2009, 2010 Wolfson Microelectronics
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/device.h>
+#include <linux/i2c.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/tlv.h>
+#include <sound/wm9090.h>
+
+#include "wm9090.h"
+
+static struct snd_soc_codec *wm9090_codec;
+
+static const u16 wm9090_reg_defaults[] = {
+       0x9093,     /* R0   - Software Reset */
+       0x0006,     /* R1   - Power Management (1) */
+       0x6000,     /* R2   - Power Management (2) */
+       0x0000,     /* R3   - Power Management (3) */
+       0x0000,     /* R4 */
+       0x0000,     /* R5 */
+       0x01C0,     /* R6   - Clocking 1 */
+       0x0000,     /* R7 */
+       0x0000,     /* R8 */
+       0x0000,     /* R9 */
+       0x0000,     /* R10 */
+       0x0000,     /* R11 */
+       0x0000,     /* R12 */
+       0x0000,     /* R13 */
+       0x0000,     /* R14 */
+       0x0000,     /* R15 */
+       0x0000,     /* R16 */
+       0x0000,     /* R17 */
+       0x0000,     /* R18 */
+       0x0000,     /* R19 */
+       0x0000,     /* R20 */
+       0x0000,     /* R21 */
+       0x0003,     /* R22  - IN1 Line Control */
+       0x0003,     /* R23  - IN2 Line Control */
+       0x0083,     /* R24  - IN1 Line Input A Volume */
+       0x0083,     /* R25  - IN1  Line Input B Volume */
+       0x0083,     /* R26  - IN2 Line Input A Volume */
+       0x0083,     /* R27  - IN2 Line Input B Volume */
+       0x002D,     /* R28  - Left Output Volume */
+       0x002D,     /* R29  - Right Output Volume */
+       0x0000,     /* R30 */
+       0x0000,     /* R31 */
+       0x0000,     /* R32 */
+       0x0000,     /* R33 */
+       0x0100,     /* R34  - SPKMIXL Attenuation */
+       0x0000,     /* R35 */
+       0x0010,     /* R36  - SPKOUT Mixers */
+       0x0140,     /* R37  - ClassD3 */
+       0x0039,     /* R38  - Speaker Volume Left */
+       0x0000,     /* R39 */
+       0x0000,     /* R40 */
+       0x0000,     /* R41 */
+       0x0000,     /* R42 */
+       0x0000,     /* R43 */
+       0x0000,     /* R44 */
+       0x0000,     /* R45  - Output Mixer1 */
+       0x0000,     /* R46  - Output Mixer2 */
+       0x0100,     /* R47  - Output Mixer3 */
+       0x0100,     /* R48  - Output Mixer4 */
+       0x0000,     /* R49 */
+       0x0000,     /* R50 */
+       0x0000,     /* R51 */
+       0x0000,     /* R52 */
+       0x0000,     /* R53 */
+       0x0000,     /* R54  - Speaker Mixer */
+       0x0000,     /* R55 */
+       0x0000,     /* R56 */
+       0x000D,     /* R57  - AntiPOP2 */
+       0x0000,     /* R58 */
+       0x0000,     /* R59 */
+       0x0000,     /* R60 */
+       0x0000,     /* R61 */
+       0x0000,     /* R62 */
+       0x0000,     /* R63 */
+       0x0000,     /* R64 */
+       0x0000,     /* R65 */
+       0x0000,     /* R66 */
+       0x0000,     /* R67 */
+       0x0000,     /* R68 */
+       0x0000,     /* R69 */
+       0x0000,     /* R70  - Write Sequencer 0 */
+       0x0000,     /* R71  - Write Sequencer 1 */
+       0x0000,     /* R72  - Write Sequencer 2 */
+       0x0000,     /* R73  - Write Sequencer 3 */
+       0x0000,     /* R74  - Write Sequencer 4 */
+       0x0000,     /* R75  - Write Sequencer 5 */
+       0x1F25,     /* R76  - Charge Pump 1 */
+       0x0000,     /* R77 */
+       0x0000,     /* R78 */
+       0x0000,     /* R79 */
+       0x0000,     /* R80 */
+       0x0000,     /* R81 */
+       0x0000,     /* R82 */
+       0x0000,     /* R83 */
+       0x0000,     /* R84  - DC Servo 0 */
+       0x054A,     /* R85  - DC Servo 1 */
+       0x0000,     /* R86 */
+       0x0000,     /* R87  - DC Servo 3 */
+       0x0000,     /* R88  - DC Servo Readback 0 */
+       0x0000,     /* R89  - DC Servo Readback 1 */
+       0x0000,     /* R90  - DC Servo Readback 2 */
+       0x0000,     /* R91 */
+       0x0000,     /* R92 */
+       0x0000,     /* R93 */
+       0x0000,     /* R94 */
+       0x0000,     /* R95 */
+       0x0100,     /* R96  - Analogue HP 0 */
+       0x0000,     /* R97 */
+       0x8640,     /* R98  - AGC Control 0 */
+       0xC000,     /* R99  - AGC Control 1 */
+       0x0200,     /* R100 - AGC Control 2 */
+};
+
+/* This struct is used to save the context */
+struct wm9090_priv {
+       /* We're not really registering as a CODEC since ASoC core
+        * does not yet support multiple CODECs but having the CODEC
+        * structure means we can reuse some of the ASoC core
+        * features.
+        */
+       struct snd_soc_codec codec;
+       struct mutex mutex;
+       u16 reg_cache[WM9090_MAX_REGISTER + 1];
+       struct wm9090_platform_data pdata;
+};
+
+static int wm9090_volatile(unsigned int reg)
+{
+       switch (reg) {
+       case WM9090_SOFTWARE_RESET:
+       case WM9090_DC_SERVO_0:
+       case WM9090_DC_SERVO_READBACK_0:
+       case WM9090_DC_SERVO_READBACK_1:
+       case WM9090_DC_SERVO_READBACK_2:
+               return 1;
+
+       default:
+               return 0;
+       }
+}
+
+static void wait_for_dc_servo(struct snd_soc_codec *codec)
+{
+       unsigned int reg;
+       int count = 0;
+
+       dev_dbg(codec->dev, "Waiting for DC servo...\n");
+       do {
+               count++;
+               msleep(1);
+               reg = snd_soc_read(codec, WM9090_DC_SERVO_READBACK_0);
+               dev_dbg(codec->dev, "DC servo status: %x\n", reg);
+       } while ((reg & WM9090_DCS_CAL_COMPLETE_MASK)
+                != WM9090_DCS_CAL_COMPLETE_MASK && count < 1000);
+
+       if ((reg & WM9090_DCS_CAL_COMPLETE_MASK)
+           != WM9090_DCS_CAL_COMPLETE_MASK)
+               dev_err(codec->dev, "Timed out waiting for DC Servo\n");
+}
+
+static const unsigned int in_tlv[] = {
+       TLV_DB_RANGE_HEAD(6),
+       0, 0, TLV_DB_SCALE_ITEM(-600, 0, 0),
+       1, 3, TLV_DB_SCALE_ITEM(-350, 350, 0),
+       4, 6, TLV_DB_SCALE_ITEM(600, 600, 0),
+};
+static const unsigned int mix_tlv[] = {
+       TLV_DB_RANGE_HEAD(4),
+       0, 2, TLV_DB_SCALE_ITEM(-1200, 300, 0),
+       3, 3, TLV_DB_SCALE_ITEM(0, 0, 0),
+};
+static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0);
+static const unsigned int spkboost_tlv[] = {
+       TLV_DB_RANGE_HEAD(7),
+       0, 6, TLV_DB_SCALE_ITEM(0, 150, 0),
+       7, 7, TLV_DB_SCALE_ITEM(1200, 0, 0),
+};
+
+static const struct snd_kcontrol_new wm9090_controls[] = {
+SOC_SINGLE_TLV("IN1A Volume", WM9090_IN1_LINE_INPUT_A_VOLUME, 0, 6, 0,
+              in_tlv),
+SOC_SINGLE("IN1A Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 7, 1, 1),
+SOC_SINGLE("IN1A ZC Switch", WM9090_IN1_LINE_INPUT_A_VOLUME, 6, 1, 0),
+
+SOC_SINGLE_TLV("IN2A Volume", WM9090_IN2_LINE_INPUT_A_VOLUME, 0, 6, 0,
+              in_tlv),
+SOC_SINGLE("IN2A Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 7, 1, 1),
+SOC_SINGLE("IN2A ZC Switch", WM9090_IN2_LINE_INPUT_A_VOLUME, 6, 1, 0),
+
+SOC_SINGLE("MIXOUTL Switch", WM9090_OUTPUT_MIXER3, 8, 1, 1),
+SOC_SINGLE_TLV("MIXOUTL IN1A Volume", WM9090_OUTPUT_MIXER3, 6, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTL IN2A Volume", WM9090_OUTPUT_MIXER3, 2, 3, 1,
+              mix_tlv),
+
+SOC_SINGLE("MIXOUTR Switch", WM9090_OUTPUT_MIXER4, 8, 1, 1),
+SOC_SINGLE_TLV("MIXOUTR IN1A Volume", WM9090_OUTPUT_MIXER4, 6, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTR IN2A Volume", WM9090_OUTPUT_MIXER4, 2, 3, 1,
+              mix_tlv),
+
+SOC_SINGLE("SPKMIX Switch", WM9090_SPKMIXL_ATTENUATION, 8, 1, 1),
+SOC_SINGLE_TLV("SPKMIX IN1A Volume", WM9090_SPKMIXL_ATTENUATION, 6, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("SPKMIX IN2A Volume", WM9090_SPKMIXL_ATTENUATION, 2, 3, 1,
+              mix_tlv),
+
+SOC_DOUBLE_R_TLV("Headphone Volume", WM9090_LEFT_OUTPUT_VOLUME,
+                WM9090_RIGHT_OUTPUT_VOLUME, 0, 63, 0, out_tlv),
+SOC_DOUBLE_R("Headphone Switch", WM9090_LEFT_OUTPUT_VOLUME,
+            WM9090_RIGHT_OUTPUT_VOLUME, 6, 1, 1),
+SOC_DOUBLE_R("Headphone ZC Switch", WM9090_LEFT_OUTPUT_VOLUME,
+            WM9090_RIGHT_OUTPUT_VOLUME, 7, 1, 0),
+
+SOC_SINGLE_TLV("Speaker Volume", WM9090_SPEAKER_VOLUME_LEFT, 0, 63, 0,
+              out_tlv),
+SOC_SINGLE("Speaker Switch", WM9090_SPEAKER_VOLUME_LEFT, 6, 1, 1),
+SOC_SINGLE("Speaker ZC Switch", WM9090_SPEAKER_VOLUME_LEFT, 7, 1, 0),
+SOC_SINGLE_TLV("Speaker Boost Volume", WM9090_CLASSD3, 3, 7, 0, spkboost_tlv),
+};
+
+static const struct snd_kcontrol_new wm9090_in1_se_controls[] = {
+SOC_SINGLE_TLV("IN1B Volume", WM9090_IN1_LINE_INPUT_B_VOLUME, 0, 6, 0,
+              in_tlv),
+SOC_SINGLE("IN1B Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 7, 1, 1),
+SOC_SINGLE("IN1B ZC Switch", WM9090_IN1_LINE_INPUT_B_VOLUME, 6, 1, 0),
+
+SOC_SINGLE_TLV("SPKMIX IN1B Volume", WM9090_SPKMIXL_ATTENUATION, 4, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTL IN1B Volume", WM9090_OUTPUT_MIXER3, 4, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTR IN1B Volume", WM9090_OUTPUT_MIXER4, 4, 3, 1,
+              mix_tlv),
+};
+
+static const struct snd_kcontrol_new wm9090_in2_se_controls[] = {
+SOC_SINGLE_TLV("IN2B Volume", WM9090_IN2_LINE_INPUT_B_VOLUME, 0, 6, 0,
+              in_tlv),
+SOC_SINGLE("IN2B Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 7, 1, 1),
+SOC_SINGLE("IN2B ZC Switch", WM9090_IN2_LINE_INPUT_B_VOLUME, 6, 1, 0),
+
+SOC_SINGLE_TLV("SPKMIX IN2B Volume", WM9090_SPKMIXL_ATTENUATION, 0, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTL IN2B Volume", WM9090_OUTPUT_MIXER3, 0, 3, 1,
+              mix_tlv),
+SOC_SINGLE_TLV("MIXOUTR IN2B Volume", WM9090_OUTPUT_MIXER4, 0, 3, 1,
+              mix_tlv),
+};
+
+static int hp_ev(struct snd_soc_dapm_widget *w,
+                struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = w->codec;
+       unsigned int reg = snd_soc_read(codec, WM9090_ANALOGUE_HP_0);
+
+       switch (event) {
+       case SND_SOC_DAPM_POST_PMU:
+               snd_soc_update_bits(codec, WM9090_CHARGE_PUMP_1,
+                                   WM9090_CP_ENA, WM9090_CP_ENA);
+
+               msleep(5);
+
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1,
+                                   WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA,
+                                   WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA);
+
+               reg |= WM9090_HPOUT1L_DLY | WM9090_HPOUT1R_DLY;
+               snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
+
+               /* Start the DC servo.  We don't currently use the
+                * ability to save the state since we don't have full
+                * control of the analogue paths and they can change
+                * DC offsets; see the WM8904 driver for an example of
+                * doing so.
+                */
+               snd_soc_write(codec, WM9090_DC_SERVO_0,
+                             WM9090_DCS_ENA_CHAN_0 |
+                             WM9090_DCS_ENA_CHAN_1 |
+                             WM9090_DCS_TRIG_STARTUP_1 |
+                             WM9090_DCS_TRIG_STARTUP_0);
+               wait_for_dc_servo(codec);
+
+               reg |= WM9090_HPOUT1R_OUTP | WM9090_HPOUT1R_RMV_SHORT |
+                       WM9090_HPOUT1L_OUTP | WM9090_HPOUT1L_RMV_SHORT;
+               snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
+               break;
+
+       case SND_SOC_DAPM_PRE_PMD:
+               reg &= ~(WM9090_HPOUT1L_RMV_SHORT |
+                        WM9090_HPOUT1L_DLY |
+                        WM9090_HPOUT1L_OUTP |
+                        WM9090_HPOUT1R_RMV_SHORT |
+                        WM9090_HPOUT1R_DLY |
+                        WM9090_HPOUT1R_OUTP);
+
+               snd_soc_write(codec, WM9090_ANALOGUE_HP_0, reg);
+
+               snd_soc_write(codec, WM9090_DC_SERVO_0, 0);
+
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1,
+                                   WM9090_HPOUT1L_ENA | WM9090_HPOUT1R_ENA,
+                                   0);
+
+               snd_soc_update_bits(codec, WM9090_CHARGE_PUMP_1,
+                                   WM9090_CP_ENA, 0);
+               break;
+       }
+
+       return 0;
+}
+
+static const struct snd_kcontrol_new spkmix[] = {
+SOC_DAPM_SINGLE("IN1A Switch", WM9090_SPEAKER_MIXER, 6, 1, 0),
+SOC_DAPM_SINGLE("IN1B Switch", WM9090_SPEAKER_MIXER, 4, 1, 0),
+SOC_DAPM_SINGLE("IN2A Switch", WM9090_SPEAKER_MIXER, 2, 1, 0),
+SOC_DAPM_SINGLE("IN2B Switch", WM9090_SPEAKER_MIXER, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new spkout[] = {
+SOC_DAPM_SINGLE("Mixer Switch", WM9090_SPKOUT_MIXERS, 4, 1, 0),
+};
+
+static const struct snd_kcontrol_new mixoutl[] = {
+SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER1, 6, 1, 0),
+SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER1, 4, 1, 0),
+SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER1, 2, 1, 0),
+SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER1, 0, 1, 0),
+};
+
+static const struct snd_kcontrol_new mixoutr[] = {
+SOC_DAPM_SINGLE("IN1A Switch", WM9090_OUTPUT_MIXER2, 6, 1, 0),
+SOC_DAPM_SINGLE("IN1B Switch", WM9090_OUTPUT_MIXER2, 4, 1, 0),
+SOC_DAPM_SINGLE("IN2A Switch", WM9090_OUTPUT_MIXER2, 2, 1, 0),
+SOC_DAPM_SINGLE("IN2B Switch", WM9090_OUTPUT_MIXER2, 0, 1, 0),
+};
+
+static const struct snd_soc_dapm_widget wm9090_dapm_widgets[] = {
+SND_SOC_DAPM_INPUT("IN1+"),
+SND_SOC_DAPM_INPUT("IN1-"),
+SND_SOC_DAPM_INPUT("IN2+"),
+SND_SOC_DAPM_INPUT("IN2-"),
+
+SND_SOC_DAPM_SUPPLY("OSC", WM9090_POWER_MANAGEMENT_1, 3, 0, NULL, 0),
+
+SND_SOC_DAPM_PGA("IN1A PGA", WM9090_POWER_MANAGEMENT_2, 7, 0, NULL, 0),
+SND_SOC_DAPM_PGA("IN1B PGA", WM9090_POWER_MANAGEMENT_2, 6, 0, NULL, 0),
+SND_SOC_DAPM_PGA("IN2A PGA", WM9090_POWER_MANAGEMENT_2, 5, 0, NULL, 0),
+SND_SOC_DAPM_PGA("IN2B PGA", WM9090_POWER_MANAGEMENT_2, 4, 0, NULL, 0),
+
+SND_SOC_DAPM_MIXER("SPKMIX", WM9090_POWER_MANAGEMENT_3, 3, 0,
+                  spkmix, ARRAY_SIZE(spkmix)),
+SND_SOC_DAPM_MIXER("MIXOUTL", WM9090_POWER_MANAGEMENT_3, 5, 0,
+                  mixoutl, ARRAY_SIZE(mixoutl)),
+SND_SOC_DAPM_MIXER("MIXOUTR", WM9090_POWER_MANAGEMENT_3, 4, 0,
+                  mixoutr, ARRAY_SIZE(mixoutr)),
+
+SND_SOC_DAPM_PGA_E("HP PGA", SND_SOC_NOPM, 0, 0, NULL, 0,
+                  hp_ev, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+
+SND_SOC_DAPM_PGA("SPKPGA", WM9090_POWER_MANAGEMENT_3, 8, 0, NULL, 0),
+SND_SOC_DAPM_MIXER("SPKOUT", WM9090_POWER_MANAGEMENT_1, 12, 0,
+                  spkout, ARRAY_SIZE(spkout)),
+
+SND_SOC_DAPM_OUTPUT("HPR"),
+SND_SOC_DAPM_OUTPUT("HPL"),
+SND_SOC_DAPM_OUTPUT("Speaker"),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       { "IN1A PGA", NULL, "IN1+" },
+       { "IN2A PGA", NULL, "IN2+" },
+
+       { "SPKMIX", "IN1A Switch", "IN1A PGA" },
+       { "SPKMIX", "IN2A Switch", "IN2A PGA" },
+
+       { "MIXOUTL", "IN1A Switch", "IN1A PGA" },
+       { "MIXOUTL", "IN2A Switch", "IN2A PGA" },
+
+       { "MIXOUTR", "IN1A Switch", "IN1A PGA" },
+       { "MIXOUTR", "IN2A Switch", "IN2A PGA" },
+
+       { "HP PGA", NULL, "OSC" },
+       { "HP PGA", NULL, "MIXOUTL" },
+       { "HP PGA", NULL, "MIXOUTR" },
+
+       { "HPL", NULL, "HP PGA" },
+       { "HPR", NULL, "HP PGA" },
+
+       { "SPKPGA", NULL, "OSC" },
+       { "SPKPGA", NULL, "SPKMIX" },
+
+       { "SPKOUT", "Mixer Switch", "SPKPGA" },
+
+       { "Speaker", NULL, "SPKOUT" },
+};
+
+static const struct snd_soc_dapm_route audio_map_in1_se[] = {
+       { "IN1B PGA", NULL, "IN1-" },   
+
+       { "SPKMIX", "IN1B Switch", "IN1B PGA" },
+       { "MIXOUTL", "IN1B Switch", "IN1B PGA" },
+       { "MIXOUTR", "IN1B Switch", "IN1B PGA" },
+};
+
+static const struct snd_soc_dapm_route audio_map_in1_diff[] = {
+       { "IN1A PGA", NULL, "IN1-" },   
+};
+
+static const struct snd_soc_dapm_route audio_map_in2_se[] = {
+       { "IN2B PGA", NULL, "IN2-" },   
+
+       { "SPKMIX", "IN2B Switch", "IN2B PGA" },
+       { "MIXOUTL", "IN2B Switch", "IN2B PGA" },
+       { "MIXOUTR", "IN2B Switch", "IN2B PGA" },
+};
+
+static const struct snd_soc_dapm_route audio_map_in2_diff[] = {
+       { "IN2A PGA", NULL, "IN2-" },   
+};
+
+static int wm9090_add_controls(struct snd_soc_codec *codec)
+{
+       struct wm9090_priv *wm9090 = snd_soc_codec_get_drvdata(codec);
+       int i;
+
+       snd_soc_dapm_new_controls(codec, wm9090_dapm_widgets,
+                                 ARRAY_SIZE(wm9090_dapm_widgets));
+
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_add_controls(codec, wm9090_controls,
+                            ARRAY_SIZE(wm9090_controls));
+
+       if (wm9090->pdata.lin1_diff) {
+               snd_soc_dapm_add_routes(codec, audio_map_in1_diff,
+                                       ARRAY_SIZE(audio_map_in1_diff));
+       } else {
+               snd_soc_dapm_add_routes(codec, audio_map_in1_se,
+                                       ARRAY_SIZE(audio_map_in1_se));
+               snd_soc_add_controls(codec, wm9090_in1_se_controls,
+                                    ARRAY_SIZE(wm9090_in1_se_controls));
+       }
+
+       if (wm9090->pdata.lin2_diff) {
+               snd_soc_dapm_add_routes(codec, audio_map_in2_diff,
+                                       ARRAY_SIZE(audio_map_in2_diff));
+       } else {
+               snd_soc_dapm_add_routes(codec, audio_map_in2_se,
+                                       ARRAY_SIZE(audio_map_in2_se));
+               snd_soc_add_controls(codec, wm9090_in2_se_controls,
+                                    ARRAY_SIZE(wm9090_in2_se_controls));
+       }
+
+       if (wm9090->pdata.agc_ena) {
+               for (i = 0; i < ARRAY_SIZE(wm9090->pdata.agc); i++)
+                       snd_soc_write(codec, WM9090_AGC_CONTROL_0 + i,
+                                     wm9090->pdata.agc[i]);
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_3,
+                                   WM9090_AGC_ENA, WM9090_AGC_ENA);
+       } else {
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_3,
+                                   WM9090_AGC_ENA, 0);
+       }
+
+       return 0;
+
+}
+
+/*
+ * The machine driver should call this from their set_bias_level; if there
+ * isn't one then this can just be set as the set_bias_level function.
+ */
+static int wm9090_set_bias_level(struct snd_soc_codec *codec,
+                                enum snd_soc_bias_level level)
+{
+       u16 *reg_cache = codec->reg_cache;
+       int i, ret;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               break;
+
+       case SND_SOC_BIAS_PREPARE:
+               snd_soc_update_bits(codec, WM9090_ANTIPOP2, WM9090_VMID_ENA,
+                                   WM9090_VMID_ENA);
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1,
+                                   WM9090_BIAS_ENA |
+                                   WM9090_VMID_RES_MASK,
+                                   WM9090_BIAS_ENA |
+                                   1 << WM9090_VMID_RES_SHIFT);
+               msleep(1);  /* Probably an overestimate */
+               break;
+
+       case SND_SOC_BIAS_STANDBY:
+               if (codec->bias_level == SND_SOC_BIAS_OFF) {
+                       /* Restore the register cache */
+                       for (i = 1; i < codec->reg_cache_size; i++) {
+                               if (reg_cache[i] == wm9090_reg_defaults[i])
+                                       continue;
+                               if (wm9090_volatile(i))
+                                       continue;
+
+                               ret = snd_soc_write(codec, i, reg_cache[i]);
+                               if (ret != 0)
+                                       dev_warn(codec->dev,
+                                                "Failed to restore register %d: %d\n",
+                                                i, ret);
+                       }
+               }
+
+               /* We keep VMID off during standby since the combination of
+                * ground referenced outputs and class D speaker mean that
+                * latency is not an issue.
+                */
+               snd_soc_update_bits(codec, WM9090_POWER_MANAGEMENT_1,
+                                   WM9090_BIAS_ENA | WM9090_VMID_RES_MASK, 0);
+               snd_soc_update_bits(codec, WM9090_ANTIPOP2,
+                                   WM9090_VMID_ENA, 0);
+               break;
+
+       case SND_SOC_BIAS_OFF:
+               break;
+       }
+
+       codec->bias_level = level;
+
+       return 0;
+}
+
+static int wm9090_probe(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec;
+       int ret = 0;
+
+       if (wm9090_codec == NULL) {
+               dev_err(&pdev->dev, "Codec device not registered\n");
+               return -ENODEV;
+       }
+
+       socdev->card->codec = wm9090_codec;
+       codec = wm9090_codec;
+
+       /* register pcms */
+       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+       if (ret < 0) {
+               dev_err(codec->dev, "failed to create pcms: %d\n", ret);
+               goto pcm_err;
+       }
+
+       wm9090_add_controls(codec);
+
+       return 0;
+
+pcm_err:
+       return ret;
+}
+
+#ifdef CONFIG_PM
+static int wm9090_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+       return 0;
+}
+
+static int wm9090_resume(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_codec *codec = socdev->card->codec;
+
+       wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       return 0;
+}
+#else
+#define wm9090_suspend NULL
+#define wm9090_resume NULL
+#endif
+
+static int wm9090_remove(struct platform_device *pdev)
+{
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+       snd_soc_free_pcms(socdev);
+       snd_soc_dapm_free(socdev);
+
+       return 0;
+}
+
+struct snd_soc_codec_device soc_codec_dev_wm9090 = {
+       .probe =        wm9090_probe,
+       .remove =       wm9090_remove,
+       .suspend =      wm9090_suspend,
+       .resume =       wm9090_resume,
+};
+EXPORT_SYMBOL_GPL(soc_codec_dev_wm9090);
+
+static int wm9090_i2c_probe(struct i2c_client *i2c,
+                           const struct i2c_device_id *id)
+{
+       struct wm9090_priv *wm9090;
+       struct snd_soc_codec *codec;
+       int ret;
+
+       wm9090 = kzalloc(sizeof(*wm9090), GFP_KERNEL);
+       if (wm9090 == NULL) {
+               dev_err(&i2c->dev, "Can not allocate memory\n");
+               return -ENOMEM;
+       }
+       codec = &wm9090->codec;
+
+       if (i2c->dev.platform_data)
+               memcpy(&wm9090->pdata, i2c->dev.platform_data,
+                      sizeof(wm9090->pdata));
+
+       wm9090_codec = codec;
+
+       i2c_set_clientdata(i2c, wm9090);
+
+       mutex_init(&codec->mutex);
+       INIT_LIST_HEAD(&codec->dapm_widgets);
+       INIT_LIST_HEAD(&codec->dapm_paths);
+
+       codec->control_data = i2c;
+       snd_soc_codec_set_drvdata(codec, wm9090);
+       codec->dev = &i2c->dev;
+       codec->name = "WM9090";
+       codec->owner = THIS_MODULE;
+       codec->bias_level = SND_SOC_BIAS_OFF;
+       codec->set_bias_level = wm9090_set_bias_level,
+       codec->reg_cache_size = WM9090_MAX_REGISTER + 1;
+       codec->reg_cache = &wm9090->reg_cache;
+       codec->volatile_register = wm9090_volatile;
+
+       ret = snd_soc_codec_set_cache_io(codec, 8, 16, SND_SOC_I2C);
+       if (ret != 0) {
+               dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+               goto err;
+       }
+
+       memcpy(&wm9090->reg_cache, wm9090_reg_defaults,
+              sizeof(wm9090->reg_cache));
+
+       ret = snd_soc_read(codec, WM9090_SOFTWARE_RESET);
+       if (ret < 0)
+               goto err;
+       if (ret != wm9090_reg_defaults[WM9090_SOFTWARE_RESET]) {
+               dev_err(&i2c->dev, "Device is not a WM9090, ID=%x\n", ret);
+               ret = -EINVAL;
+               goto err;
+       }
+
+       ret = snd_soc_write(codec, WM9090_SOFTWARE_RESET, 0);
+       if (ret < 0)
+               goto err;
+
+       /* Configure some defaults; they will be written out when we
+        * bring the bias up.
+        */
+       wm9090->reg_cache[WM9090_IN1_LINE_INPUT_A_VOLUME] |= WM9090_IN1_VU
+               | WM9090_IN1A_ZC;
+       wm9090->reg_cache[WM9090_IN1_LINE_INPUT_B_VOLUME] |= WM9090_IN1_VU
+               | WM9090_IN1B_ZC;
+       wm9090->reg_cache[WM9090_IN2_LINE_INPUT_A_VOLUME] |= WM9090_IN2_VU
+               | WM9090_IN2A_ZC;
+       wm9090->reg_cache[WM9090_IN2_LINE_INPUT_B_VOLUME] |= WM9090_IN2_VU
+               | WM9090_IN2B_ZC;
+       wm9090->reg_cache[WM9090_SPEAKER_VOLUME_LEFT] |=
+               WM9090_SPKOUT_VU | WM9090_SPKOUTL_ZC;
+       wm9090->reg_cache[WM9090_LEFT_OUTPUT_VOLUME] |= 
+               WM9090_HPOUT1_VU | WM9090_HPOUT1L_ZC;
+       wm9090->reg_cache[WM9090_RIGHT_OUTPUT_VOLUME] |=
+               WM9090_HPOUT1_VU | WM9090_HPOUT1R_ZC;
+
+       wm9090->reg_cache[WM9090_CLOCKING_1] |= WM9090_TOCLK_ENA;
+
+       wm9090_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+       ret = snd_soc_register_codec(codec);
+       if (ret != 0) {
+               dev_err(&i2c->dev, "Failed to register CODEC: %d\n", ret);
+               goto err_bias;
+       }
+
+       return 0;
+
+err_bias:
+       wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
+err:
+       kfree(wm9090);
+       i2c_set_clientdata(i2c, NULL);
+       wm9090_codec = NULL;
+
+       return ret;
+}
+
+static int wm9090_i2c_remove(struct i2c_client *i2c)
+{
+       struct wm9090_priv *wm9090 = i2c_get_clientdata(i2c);
+       struct snd_soc_codec *codec = &wm9090->codec;
+
+       snd_soc_unregister_codec(codec);
+       wm9090_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       kfree(wm9090);
+       wm9090_codec = NULL;
+
+       return 0;
+}
+
+static const struct i2c_device_id wm9090_id[] = {
+       { "wm9090", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm9090_id);
+
+static struct i2c_driver wm9090_i2c_driver = {
+       .driver = {
+               .name = "wm9090",
+               .owner = THIS_MODULE,
+       },
+       .probe = wm9090_i2c_probe,
+       .remove = __devexit_p(wm9090_i2c_remove),
+       .id_table = wm9090_id,
+};
+
+static int __init wm9090_init(void)
+{
+       return i2c_add_driver(&wm9090_i2c_driver);
+}
+module_init(wm9090_init);
+
+static void __exit wm9090_exit(void)
+{
+       i2c_del_driver(&wm9090_i2c_driver);
+}
+module_exit(wm9090_exit);
+
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
+MODULE_DESCRIPTION("WM9090 ASoC driver");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm9090.h b/sound/soc/codecs/wm9090.h
new file mode 100644 (file)
index 0000000..b08eab9
--- /dev/null
@@ -0,0 +1,715 @@
+/*
+ * ALSA SoC WM9090 driver
+ *
+ * Copyright 2009 Wolfson Microelectronics
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef __WM9090_H
+#define __WM9090_H
+
+extern struct snd_soc_codec_device soc_codec_dev_wm9090;
+
+/*
+ * Register values.
+ */
+#define WM9090_SOFTWARE_RESET                   0x00
+#define WM9090_POWER_MANAGEMENT_1               0x01
+#define WM9090_POWER_MANAGEMENT_2               0x02
+#define WM9090_POWER_MANAGEMENT_3               0x03
+#define WM9090_CLOCKING_1                       0x06
+#define WM9090_IN1_LINE_CONTROL                 0x16
+#define WM9090_IN2_LINE_CONTROL                 0x17
+#define WM9090_IN1_LINE_INPUT_A_VOLUME          0x18
+#define WM9090_IN1_LINE_INPUT_B_VOLUME          0x19
+#define WM9090_IN2_LINE_INPUT_A_VOLUME          0x1A
+#define WM9090_IN2_LINE_INPUT_B_VOLUME          0x1B
+#define WM9090_LEFT_OUTPUT_VOLUME               0x1C
+#define WM9090_RIGHT_OUTPUT_VOLUME              0x1D
+#define WM9090_SPKMIXL_ATTENUATION              0x22
+#define WM9090_SPKOUT_MIXERS                    0x24
+#define WM9090_CLASSD3                          0x25
+#define WM9090_SPEAKER_VOLUME_LEFT              0x26
+#define WM9090_OUTPUT_MIXER1                    0x2D
+#define WM9090_OUTPUT_MIXER2                    0x2E
+#define WM9090_OUTPUT_MIXER3                    0x2F
+#define WM9090_OUTPUT_MIXER4                    0x30
+#define WM9090_SPEAKER_MIXER                    0x36
+#define WM9090_ANTIPOP2                         0x39
+#define WM9090_WRITE_SEQUENCER_0                0x46
+#define WM9090_WRITE_SEQUENCER_1                0x47
+#define WM9090_WRITE_SEQUENCER_2                0x48
+#define WM9090_WRITE_SEQUENCER_3                0x49
+#define WM9090_WRITE_SEQUENCER_4                0x4A
+#define WM9090_WRITE_SEQUENCER_5                0x4B
+#define WM9090_CHARGE_PUMP_1                    0x4C
+#define WM9090_DC_SERVO_0                       0x54
+#define WM9090_DC_SERVO_1                       0x55
+#define WM9090_DC_SERVO_3                       0x57
+#define WM9090_DC_SERVO_READBACK_0              0x58
+#define WM9090_DC_SERVO_READBACK_1              0x59
+#define WM9090_DC_SERVO_READBACK_2              0x5A
+#define WM9090_ANALOGUE_HP_0                    0x60
+#define WM9090_AGC_CONTROL_0                    0x62
+#define WM9090_AGC_CONTROL_1                    0x63
+#define WM9090_AGC_CONTROL_2                    0x64
+
+#define WM9090_REGISTER_COUNT                   40
+#define WM9090_MAX_REGISTER                     0x64
+
+/*
+ * Field Definitions.
+ */
+
+/*
+ * R0 (0x00) - Software Reset
+ */
+#define WM9090_SW_RESET_MASK                    0xFFFF  /* SW_RESET - [15:0] */
+#define WM9090_SW_RESET_SHIFT                        0  /* SW_RESET - [15:0] */
+#define WM9090_SW_RESET_WIDTH                       16  /* SW_RESET - [15:0] */
+
+/*
+ * R1 (0x01) - Power Management (1)
+ */
+#define WM9090_SPKOUTL_ENA                      0x1000  /* SPKOUTL_ENA */
+#define WM9090_SPKOUTL_ENA_MASK                 0x1000  /* SPKOUTL_ENA */
+#define WM9090_SPKOUTL_ENA_SHIFT                    12  /* SPKOUTL_ENA */
+#define WM9090_SPKOUTL_ENA_WIDTH                     1  /* SPKOUTL_ENA */
+#define WM9090_HPOUT1L_ENA                      0x0200  /* HPOUT1L_ENA */
+#define WM9090_HPOUT1L_ENA_MASK                 0x0200  /* HPOUT1L_ENA */
+#define WM9090_HPOUT1L_ENA_SHIFT                     9  /* HPOUT1L_ENA */
+#define WM9090_HPOUT1L_ENA_WIDTH                     1  /* HPOUT1L_ENA */
+#define WM9090_HPOUT1R_ENA                      0x0100  /* HPOUT1R_ENA */
+#define WM9090_HPOUT1R_ENA_MASK                 0x0100  /* HPOUT1R_ENA */
+#define WM9090_HPOUT1R_ENA_SHIFT                     8  /* HPOUT1R_ENA */
+#define WM9090_HPOUT1R_ENA_WIDTH                     1  /* HPOUT1R_ENA */
+#define WM9090_OSC_ENA                          0x0008  /* OSC_ENA */
+#define WM9090_OSC_ENA_MASK                     0x0008  /* OSC_ENA */
+#define WM9090_OSC_ENA_SHIFT                         3  /* OSC_ENA */
+#define WM9090_OSC_ENA_WIDTH                         1  /* OSC_ENA */
+#define WM9090_VMID_RES_MASK                    0x0006  /* VMID_RES - [2:1] */
+#define WM9090_VMID_RES_SHIFT                        1  /* VMID_RES - [2:1] */
+#define WM9090_VMID_RES_WIDTH                        2  /* VMID_RES - [2:1] */
+#define WM9090_BIAS_ENA                         0x0001  /* BIAS_ENA */
+#define WM9090_BIAS_ENA_MASK                    0x0001  /* BIAS_ENA */
+#define WM9090_BIAS_ENA_SHIFT                        0  /* BIAS_ENA */
+#define WM9090_BIAS_ENA_WIDTH                        1  /* BIAS_ENA */
+
+/*
+ * R2 (0x02) - Power Management (2)
+ */
+#define WM9090_TSHUT                            0x8000  /* TSHUT */
+#define WM9090_TSHUT_MASK                       0x8000  /* TSHUT */
+#define WM9090_TSHUT_SHIFT                          15  /* TSHUT */
+#define WM9090_TSHUT_WIDTH                           1  /* TSHUT */
+#define WM9090_TSHUT_ENA                        0x4000  /* TSHUT_ENA */
+#define WM9090_TSHUT_ENA_MASK                   0x4000  /* TSHUT_ENA */
+#define WM9090_TSHUT_ENA_SHIFT                      14  /* TSHUT_ENA */
+#define WM9090_TSHUT_ENA_WIDTH                       1  /* TSHUT_ENA */
+#define WM9090_TSHUT_OPDIS                      0x2000  /* TSHUT_OPDIS */
+#define WM9090_TSHUT_OPDIS_MASK                 0x2000  /* TSHUT_OPDIS */
+#define WM9090_TSHUT_OPDIS_SHIFT                    13  /* TSHUT_OPDIS */
+#define WM9090_TSHUT_OPDIS_WIDTH                     1  /* TSHUT_OPDIS */
+#define WM9090_IN1A_ENA                         0x0080  /* IN1A_ENA */
+#define WM9090_IN1A_ENA_MASK                    0x0080  /* IN1A_ENA */
+#define WM9090_IN1A_ENA_SHIFT                        7  /* IN1A_ENA */
+#define WM9090_IN1A_ENA_WIDTH                        1  /* IN1A_ENA */
+#define WM9090_IN1B_ENA                         0x0040  /* IN1B_ENA */
+#define WM9090_IN1B_ENA_MASK                    0x0040  /* IN1B_ENA */
+#define WM9090_IN1B_ENA_SHIFT                        6  /* IN1B_ENA */
+#define WM9090_IN1B_ENA_WIDTH                        1  /* IN1B_ENA */
+#define WM9090_IN2A_ENA                         0x0020  /* IN2A_ENA */
+#define WM9090_IN2A_ENA_MASK                    0x0020  /* IN2A_ENA */
+#define WM9090_IN2A_ENA_SHIFT                        5  /* IN2A_ENA */
+#define WM9090_IN2A_ENA_WIDTH                        1  /* IN2A_ENA */
+#define WM9090_IN2B_ENA                         0x0010  /* IN2B_ENA */
+#define WM9090_IN2B_ENA_MASK                    0x0010  /* IN2B_ENA */
+#define WM9090_IN2B_ENA_SHIFT                        4  /* IN2B_ENA */
+#define WM9090_IN2B_ENA_WIDTH                        1  /* IN2B_ENA */
+
+/*
+ * R3 (0x03) - Power Management (3)
+ */
+#define WM9090_AGC_ENA                          0x4000  /* AGC_ENA */
+#define WM9090_AGC_ENA_MASK                     0x4000  /* AGC_ENA */
+#define WM9090_AGC_ENA_SHIFT                        14  /* AGC_ENA */
+#define WM9090_AGC_ENA_WIDTH                         1  /* AGC_ENA */
+#define WM9090_SPKLVOL_ENA                      0x0100  /* SPKLVOL_ENA */
+#define WM9090_SPKLVOL_ENA_MASK                 0x0100  /* SPKLVOL_ENA */
+#define WM9090_SPKLVOL_ENA_SHIFT                     8  /* SPKLVOL_ENA */
+#define WM9090_SPKLVOL_ENA_WIDTH                     1  /* SPKLVOL_ENA */
+#define WM9090_MIXOUTL_ENA                      0x0020  /* MIXOUTL_ENA */
+#define WM9090_MIXOUTL_ENA_MASK                 0x0020  /* MIXOUTL_ENA */
+#define WM9090_MIXOUTL_ENA_SHIFT                     5  /* MIXOUTL_ENA */
+#define WM9090_MIXOUTL_ENA_WIDTH                     1  /* MIXOUTL_ENA */
+#define WM9090_MIXOUTR_ENA                      0x0010  /* MIXOUTR_ENA */
+#define WM9090_MIXOUTR_ENA_MASK                 0x0010  /* MIXOUTR_ENA */
+#define WM9090_MIXOUTR_ENA_SHIFT                     4  /* MIXOUTR_ENA */
+#define WM9090_MIXOUTR_ENA_WIDTH                     1  /* MIXOUTR_ENA */
+#define WM9090_SPKMIX_ENA                       0x0008  /* SPKMIX_ENA */
+#define WM9090_SPKMIX_ENA_MASK                  0x0008  /* SPKMIX_ENA */
+#define WM9090_SPKMIX_ENA_SHIFT                      3  /* SPKMIX_ENA */
+#define WM9090_SPKMIX_ENA_WIDTH                      1  /* SPKMIX_ENA */
+
+/*
+ * R6 (0x06) - Clocking 1
+ */
+#define WM9090_TOCLK_RATE                       0x8000  /* TOCLK_RATE */
+#define WM9090_TOCLK_RATE_MASK                  0x8000  /* TOCLK_RATE */
+#define WM9090_TOCLK_RATE_SHIFT                     15  /* TOCLK_RATE */
+#define WM9090_TOCLK_RATE_WIDTH                      1  /* TOCLK_RATE */
+#define WM9090_TOCLK_ENA                        0x4000  /* TOCLK_ENA */
+#define WM9090_TOCLK_ENA_MASK                   0x4000  /* TOCLK_ENA */
+#define WM9090_TOCLK_ENA_SHIFT                      14  /* TOCLK_ENA */
+#define WM9090_TOCLK_ENA_WIDTH                       1  /* TOCLK_ENA */
+
+/*
+ * R22 (0x16) - IN1 Line Control
+ */
+#define WM9090_IN1_DIFF                         0x0002  /* IN1_DIFF */
+#define WM9090_IN1_DIFF_MASK                    0x0002  /* IN1_DIFF */
+#define WM9090_IN1_DIFF_SHIFT                        1  /* IN1_DIFF */
+#define WM9090_IN1_DIFF_WIDTH                        1  /* IN1_DIFF */
+#define WM9090_IN1_CLAMP                        0x0001  /* IN1_CLAMP */
+#define WM9090_IN1_CLAMP_MASK                   0x0001  /* IN1_CLAMP */
+#define WM9090_IN1_CLAMP_SHIFT                       0  /* IN1_CLAMP */
+#define WM9090_IN1_CLAMP_WIDTH                       1  /* IN1_CLAMP */
+
+/*
+ * R23 (0x17) - IN2 Line Control
+ */
+#define WM9090_IN2_DIFF                         0x0002  /* IN2_DIFF */
+#define WM9090_IN2_DIFF_MASK                    0x0002  /* IN2_DIFF */
+#define WM9090_IN2_DIFF_SHIFT                        1  /* IN2_DIFF */
+#define WM9090_IN2_DIFF_WIDTH                        1  /* IN2_DIFF */
+#define WM9090_IN2_CLAMP                        0x0001  /* IN2_CLAMP */
+#define WM9090_IN2_CLAMP_MASK                   0x0001  /* IN2_CLAMP */
+#define WM9090_IN2_CLAMP_SHIFT                       0  /* IN2_CLAMP */
+#define WM9090_IN2_CLAMP_WIDTH                       1  /* IN2_CLAMP */
+
+/*
+ * R24 (0x18) - IN1 Line Input A Volume
+ */
+#define WM9090_IN1_VU                           0x0100  /* IN1_VU */
+#define WM9090_IN1_VU_MASK                      0x0100  /* IN1_VU */
+#define WM9090_IN1_VU_SHIFT                          8  /* IN1_VU */
+#define WM9090_IN1_VU_WIDTH                          1  /* IN1_VU */
+#define WM9090_IN1A_MUTE                        0x0080  /* IN1A_MUTE */
+#define WM9090_IN1A_MUTE_MASK                   0x0080  /* IN1A_MUTE */
+#define WM9090_IN1A_MUTE_SHIFT                       7  /* IN1A_MUTE */
+#define WM9090_IN1A_MUTE_WIDTH                       1  /* IN1A_MUTE */
+#define WM9090_IN1A_ZC                          0x0040  /* IN1A_ZC */
+#define WM9090_IN1A_ZC_MASK                     0x0040  /* IN1A_ZC */
+#define WM9090_IN1A_ZC_SHIFT                         6  /* IN1A_ZC */
+#define WM9090_IN1A_ZC_WIDTH                         1  /* IN1A_ZC */
+#define WM9090_IN1A_VOL_MASK                    0x0007  /* IN1A_VOL - [2:0] */
+#define WM9090_IN1A_VOL_SHIFT                        0  /* IN1A_VOL - [2:0] */
+#define WM9090_IN1A_VOL_WIDTH                        3  /* IN1A_VOL - [2:0] */
+
+/*
+ * R25 (0x19) - IN1  Line Input B Volume
+ */
+#define WM9090_IN1_VU                           0x0100  /* IN1_VU */
+#define WM9090_IN1_VU_MASK                      0x0100  /* IN1_VU */
+#define WM9090_IN1_VU_SHIFT                          8  /* IN1_VU */
+#define WM9090_IN1_VU_WIDTH                          1  /* IN1_VU */
+#define WM9090_IN1B_MUTE                        0x0080  /* IN1B_MUTE */
+#define WM9090_IN1B_MUTE_MASK                   0x0080  /* IN1B_MUTE */
+#define WM9090_IN1B_MUTE_SHIFT                       7  /* IN1B_MUTE */
+#define WM9090_IN1B_MUTE_WIDTH                       1  /* IN1B_MUTE */
+#define WM9090_IN1B_ZC                          0x0040  /* IN1B_ZC */
+#define WM9090_IN1B_ZC_MASK                     0x0040  /* IN1B_ZC */
+#define WM9090_IN1B_ZC_SHIFT                         6  /* IN1B_ZC */
+#define WM9090_IN1B_ZC_WIDTH                         1  /* IN1B_ZC */
+#define WM9090_IN1B_VOL_MASK                    0x0007  /* IN1B_VOL - [2:0] */
+#define WM9090_IN1B_VOL_SHIFT                        0  /* IN1B_VOL - [2:0] */
+#define WM9090_IN1B_VOL_WIDTH                        3  /* IN1B_VOL - [2:0] */
+
+/*
+ * R26 (0x1A) - IN2 Line Input A Volume
+ */
+#define WM9090_IN2_VU                           0x0100  /* IN2_VU */
+#define WM9090_IN2_VU_MASK                      0x0100  /* IN2_VU */
+#define WM9090_IN2_VU_SHIFT                          8  /* IN2_VU */
+#define WM9090_IN2_VU_WIDTH                          1  /* IN2_VU */
+#define WM9090_IN2A_MUTE                        0x0080  /* IN2A_MUTE */
+#define WM9090_IN2A_MUTE_MASK                   0x0080  /* IN2A_MUTE */
+#define WM9090_IN2A_MUTE_SHIFT                       7  /* IN2A_MUTE */
+#define WM9090_IN2A_MUTE_WIDTH                       1  /* IN2A_MUTE */
+#define WM9090_IN2A_ZC                          0x0040  /* IN2A_ZC */
+#define WM9090_IN2A_ZC_MASK                     0x0040  /* IN2A_ZC */
+#define WM9090_IN2A_ZC_SHIFT                         6  /* IN2A_ZC */
+#define WM9090_IN2A_ZC_WIDTH                         1  /* IN2A_ZC */
+#define WM9090_IN2A_VOL_MASK                    0x0007  /* IN2A_VOL - [2:0] */
+#define WM9090_IN2A_VOL_SHIFT                        0  /* IN2A_VOL - [2:0] */
+#define WM9090_IN2A_VOL_WIDTH                        3  /* IN2A_VOL - [2:0] */
+
+/*
+ * R27 (0x1B) - IN2 Line Input B Volume
+ */
+#define WM9090_IN2_VU                           0x0100  /* IN2_VU */
+#define WM9090_IN2_VU_MASK                      0x0100  /* IN2_VU */
+#define WM9090_IN2_VU_SHIFT                          8  /* IN2_VU */
+#define WM9090_IN2_VU_WIDTH                          1  /* IN2_VU */
+#define WM9090_IN2B_MUTE                        0x0080  /* IN2B_MUTE */
+#define WM9090_IN2B_MUTE_MASK                   0x0080  /* IN2B_MUTE */
+#define WM9090_IN2B_MUTE_SHIFT                       7  /* IN2B_MUTE */
+#define WM9090_IN2B_MUTE_WIDTH                       1  /* IN2B_MUTE */
+#define WM9090_IN2B_ZC                          0x0040  /* IN2B_ZC */
+#define WM9090_IN2B_ZC_MASK                     0x0040  /* IN2B_ZC */
+#define WM9090_IN2B_ZC_SHIFT                         6  /* IN2B_ZC */
+#define WM9090_IN2B_ZC_WIDTH                         1  /* IN2B_ZC */
+#define WM9090_IN2B_VOL_MASK                    0x0007  /* IN2B_VOL - [2:0] */
+#define WM9090_IN2B_VOL_SHIFT                        0  /* IN2B_VOL - [2:0] */
+#define WM9090_IN2B_VOL_WIDTH                        3  /* IN2B_VOL - [2:0] */
+
+/*
+ * R28 (0x1C) - Left Output Volume
+ */
+#define WM9090_HPOUT1_VU                        0x0100  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_MASK                   0x0100  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_SHIFT                       8  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_WIDTH                       1  /* HPOUT1_VU */
+#define WM9090_HPOUT1L_ZC                       0x0080  /* HPOUT1L_ZC */
+#define WM9090_HPOUT1L_ZC_MASK                  0x0080  /* HPOUT1L_ZC */
+#define WM9090_HPOUT1L_ZC_SHIFT                      7  /* HPOUT1L_ZC */
+#define WM9090_HPOUT1L_ZC_WIDTH                      1  /* HPOUT1L_ZC */
+#define WM9090_HPOUT1L_MUTE                     0x0040  /* HPOUT1L_MUTE */
+#define WM9090_HPOUT1L_MUTE_MASK                0x0040  /* HPOUT1L_MUTE */
+#define WM9090_HPOUT1L_MUTE_SHIFT                    6  /* HPOUT1L_MUTE */
+#define WM9090_HPOUT1L_MUTE_WIDTH                    1  /* HPOUT1L_MUTE */
+#define WM9090_HPOUT1L_VOL_MASK                 0x003F  /* HPOUT1L_VOL - [5:0] */
+#define WM9090_HPOUT1L_VOL_SHIFT                     0  /* HPOUT1L_VOL - [5:0] */
+#define WM9090_HPOUT1L_VOL_WIDTH                     6  /* HPOUT1L_VOL - [5:0] */
+
+/*
+ * R29 (0x1D) - Right Output Volume
+ */
+#define WM9090_HPOUT1_VU                        0x0100  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_MASK                   0x0100  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_SHIFT                       8  /* HPOUT1_VU */
+#define WM9090_HPOUT1_VU_WIDTH                       1  /* HPOUT1_VU */
+#define WM9090_HPOUT1R_ZC                       0x0080  /* HPOUT1R_ZC */
+#define WM9090_HPOUT1R_ZC_MASK                  0x0080  /* HPOUT1R_ZC */
+#define WM9090_HPOUT1R_ZC_SHIFT                      7  /* HPOUT1R_ZC */
+#define WM9090_HPOUT1R_ZC_WIDTH                      1  /* HPOUT1R_ZC */
+#define WM9090_HPOUT1R_MUTE                     0x0040  /* HPOUT1R_MUTE */
+#define WM9090_HPOUT1R_MUTE_MASK                0x0040  /* HPOUT1R_MUTE */
+#define WM9090_HPOUT1R_MUTE_SHIFT                    6  /* HPOUT1R_MUTE */
+#define WM9090_HPOUT1R_MUTE_WIDTH                    1  /* HPOUT1R_MUTE */
+#define WM9090_HPOUT1R_VOL_MASK                 0x003F  /* HPOUT1R_VOL - [5:0] */
+#define WM9090_HPOUT1R_VOL_SHIFT                     0  /* HPOUT1R_VOL - [5:0] */
+#define WM9090_HPOUT1R_VOL_WIDTH                     6  /* HPOUT1R_VOL - [5:0] */
+
+/*
+ * R34 (0x22) - SPKMIXL Attenuation
+ */
+#define WM9090_SPKMIX_MUTE                      0x0100  /* SPKMIX_MUTE */
+#define WM9090_SPKMIX_MUTE_MASK                 0x0100  /* SPKMIX_MUTE */
+#define WM9090_SPKMIX_MUTE_SHIFT                     8  /* SPKMIX_MUTE */
+#define WM9090_SPKMIX_MUTE_WIDTH                     1  /* SPKMIX_MUTE */
+#define WM9090_IN1A_SPKMIX_VOL_MASK             0x00C0  /* IN1A_SPKMIX_VOL - [7:6] */
+#define WM9090_IN1A_SPKMIX_VOL_SHIFT                 6  /* IN1A_SPKMIX_VOL - [7:6] */
+#define WM9090_IN1A_SPKMIX_VOL_WIDTH                 2  /* IN1A_SPKMIX_VOL - [7:6] */
+#define WM9090_IN1B_SPKMIX_VOL_MASK             0x0030  /* IN1B_SPKMIX_VOL - [5:4] */
+#define WM9090_IN1B_SPKMIX_VOL_SHIFT                 4  /* IN1B_SPKMIX_VOL - [5:4] */
+#define WM9090_IN1B_SPKMIX_VOL_WIDTH                 2  /* IN1B_SPKMIX_VOL - [5:4] */
+#define WM9090_IN2A_SPKMIX_VOL_MASK             0x000C  /* IN2A_SPKMIX_VOL - [3:2] */
+#define WM9090_IN2A_SPKMIX_VOL_SHIFT                 2  /* IN2A_SPKMIX_VOL - [3:2] */
+#define WM9090_IN2A_SPKMIX_VOL_WIDTH                 2  /* IN2A_SPKMIX_VOL - [3:2] */
+#define WM9090_IN2B_SPKMIX_VOL_MASK             0x0003  /* IN2B_SPKMIX_VOL - [1:0] */
+#define WM9090_IN2B_SPKMIX_VOL_SHIFT                 0  /* IN2B_SPKMIX_VOL - [1:0] */
+#define WM9090_IN2B_SPKMIX_VOL_WIDTH                 2  /* IN2B_SPKMIX_VOL - [1:0] */
+
+/*
+ * R36 (0x24) - SPKOUT Mixers
+ */
+#define WM9090_SPKMIXL_TO_SPKOUTL               0x0010  /* SPKMIXL_TO_SPKOUTL */
+#define WM9090_SPKMIXL_TO_SPKOUTL_MASK          0x0010  /* SPKMIXL_TO_SPKOUTL */
+#define WM9090_SPKMIXL_TO_SPKOUTL_SHIFT              4  /* SPKMIXL_TO_SPKOUTL */
+#define WM9090_SPKMIXL_TO_SPKOUTL_WIDTH              1  /* SPKMIXL_TO_SPKOUTL */
+
+/*
+ * R37 (0x25) - ClassD3
+ */
+#define WM9090_SPKOUTL_BOOST_MASK               0x0038  /* SPKOUTL_BOOST - [5:3] */
+#define WM9090_SPKOUTL_BOOST_SHIFT                   3  /* SPKOUTL_BOOST - [5:3] */
+#define WM9090_SPKOUTL_BOOST_WIDTH                   3  /* SPKOUTL_BOOST - [5:3] */
+
+/*
+ * R38 (0x26) - Speaker Volume Left
+ */
+#define WM9090_SPKOUT_VU                        0x0100  /* SPKOUT_VU */
+#define WM9090_SPKOUT_VU_MASK                   0x0100  /* SPKOUT_VU */
+#define WM9090_SPKOUT_VU_SHIFT                       8  /* SPKOUT_VU */
+#define WM9090_SPKOUT_VU_WIDTH                       1  /* SPKOUT_VU */
+#define WM9090_SPKOUTL_ZC                       0x0080  /* SPKOUTL_ZC */
+#define WM9090_SPKOUTL_ZC_MASK                  0x0080  /* SPKOUTL_ZC */
+#define WM9090_SPKOUTL_ZC_SHIFT                      7  /* SPKOUTL_ZC */
+#define WM9090_SPKOUTL_ZC_WIDTH                      1  /* SPKOUTL_ZC */
+#define WM9090_SPKOUTL_MUTE                     0x0040  /* SPKOUTL_MUTE */
+#define WM9090_SPKOUTL_MUTE_MASK                0x0040  /* SPKOUTL_MUTE */
+#define WM9090_SPKOUTL_MUTE_SHIFT                    6  /* SPKOUTL_MUTE */
+#define WM9090_SPKOUTL_MUTE_WIDTH                    1  /* SPKOUTL_MUTE */
+#define WM9090_SPKOUTL_VOL_MASK                 0x003F  /* SPKOUTL_VOL - [5:0] */
+#define WM9090_SPKOUTL_VOL_SHIFT                     0  /* SPKOUTL_VOL - [5:0] */
+#define WM9090_SPKOUTL_VOL_WIDTH                     6  /* SPKOUTL_VOL - [5:0] */
+
+/*
+ * R45 (0x2D) - Output Mixer1
+ */
+#define WM9090_IN1A_TO_MIXOUTL                  0x0040  /* IN1A_TO_MIXOUTL */
+#define WM9090_IN1A_TO_MIXOUTL_MASK             0x0040  /* IN1A_TO_MIXOUTL */
+#define WM9090_IN1A_TO_MIXOUTL_SHIFT                 6  /* IN1A_TO_MIXOUTL */
+#define WM9090_IN1A_TO_MIXOUTL_WIDTH                 1  /* IN1A_TO_MIXOUTL */
+#define WM9090_IN2A_TO_MIXOUTL                  0x0004  /* IN2A_TO_MIXOUTL */
+#define WM9090_IN2A_TO_MIXOUTL_MASK             0x0004  /* IN2A_TO_MIXOUTL */
+#define WM9090_IN2A_TO_MIXOUTL_SHIFT                 2  /* IN2A_TO_MIXOUTL */
+#define WM9090_IN2A_TO_MIXOUTL_WIDTH                 1  /* IN2A_TO_MIXOUTL */
+
+/*
+ * R46 (0x2E) - Output Mixer2
+ */
+#define WM9090_IN1A_TO_MIXOUTR                  0x0040  /* IN1A_TO_MIXOUTR */
+#define WM9090_IN1A_TO_MIXOUTR_MASK             0x0040  /* IN1A_TO_MIXOUTR */
+#define WM9090_IN1A_TO_MIXOUTR_SHIFT                 6  /* IN1A_TO_MIXOUTR */
+#define WM9090_IN1A_TO_MIXOUTR_WIDTH                 1  /* IN1A_TO_MIXOUTR */
+#define WM9090_IN1B_TO_MIXOUTR                  0x0010  /* IN1B_TO_MIXOUTR */
+#define WM9090_IN1B_TO_MIXOUTR_MASK             0x0010  /* IN1B_TO_MIXOUTR */
+#define WM9090_IN1B_TO_MIXOUTR_SHIFT                 4  /* IN1B_TO_MIXOUTR */
+#define WM9090_IN1B_TO_MIXOUTR_WIDTH                 1  /* IN1B_TO_MIXOUTR */
+#define WM9090_IN2A_TO_MIXOUTR                  0x0004  /* IN2A_TO_MIXOUTR */
+#define WM9090_IN2A_TO_MIXOUTR_MASK             0x0004  /* IN2A_TO_MIXOUTR */
+#define WM9090_IN2A_TO_MIXOUTR_SHIFT                 2  /* IN2A_TO_MIXOUTR */
+#define WM9090_IN2A_TO_MIXOUTR_WIDTH                 1  /* IN2A_TO_MIXOUTR */
+#define WM9090_IN2B_TO_MIXOUTR                  0x0001  /* IN2B_TO_MIXOUTR */
+#define WM9090_IN2B_TO_MIXOUTR_MASK             0x0001  /* IN2B_TO_MIXOUTR */
+#define WM9090_IN2B_TO_MIXOUTR_SHIFT                 0  /* IN2B_TO_MIXOUTR */
+#define WM9090_IN2B_TO_MIXOUTR_WIDTH                 1  /* IN2B_TO_MIXOUTR */
+
+/*
+ * R47 (0x2F) - Output Mixer3
+ */
+#define WM9090_MIXOUTL_MUTE                     0x0100  /* MIXOUTL_MUTE */
+#define WM9090_MIXOUTL_MUTE_MASK                0x0100  /* MIXOUTL_MUTE */
+#define WM9090_MIXOUTL_MUTE_SHIFT                    8  /* MIXOUTL_MUTE */
+#define WM9090_MIXOUTL_MUTE_WIDTH                    1  /* MIXOUTL_MUTE */
+#define WM9090_IN1A_MIXOUTL_VOL_MASK            0x00C0  /* IN1A_MIXOUTL_VOL - [7:6] */
+#define WM9090_IN1A_MIXOUTL_VOL_SHIFT                6  /* IN1A_MIXOUTL_VOL - [7:6] */
+#define WM9090_IN1A_MIXOUTL_VOL_WIDTH                2  /* IN1A_MIXOUTL_VOL - [7:6] */
+#define WM9090_IN2A_MIXOUTL_VOL_MASK            0x000C  /* IN2A_MIXOUTL_VOL - [3:2] */
+#define WM9090_IN2A_MIXOUTL_VOL_SHIFT                2  /* IN2A_MIXOUTL_VOL - [3:2] */
+#define WM9090_IN2A_MIXOUTL_VOL_WIDTH                2  /* IN2A_MIXOUTL_VOL - [3:2] */
+
+/*
+ * R48 (0x30) - Output Mixer4
+ */
+#define WM9090_MIXOUTR_MUTE                     0x0100  /* MIXOUTR_MUTE */
+#define WM9090_MIXOUTR_MUTE_MASK                0x0100  /* MIXOUTR_MUTE */
+#define WM9090_MIXOUTR_MUTE_SHIFT                    8  /* MIXOUTR_MUTE */
+#define WM9090_MIXOUTR_MUTE_WIDTH                    1  /* MIXOUTR_MUTE */
+#define WM9090_IN1A_MIXOUTR_VOL_MASK            0x00C0  /* IN1A_MIXOUTR_VOL - [7:6] */
+#define WM9090_IN1A_MIXOUTR_VOL_SHIFT                6  /* IN1A_MIXOUTR_VOL - [7:6] */
+#define WM9090_IN1A_MIXOUTR_VOL_WIDTH                2  /* IN1A_MIXOUTR_VOL - [7:6] */
+#define WM9090_IN1B_MIXOUTR_VOL_MASK            0x0030  /* IN1B_MIXOUTR_VOL - [5:4] */
+#define WM9090_IN1B_MIXOUTR_VOL_SHIFT                4  /* IN1B_MIXOUTR_VOL - [5:4] */
+#define WM9090_IN1B_MIXOUTR_VOL_WIDTH                2  /* IN1B_MIXOUTR_VOL - [5:4] */
+#define WM9090_IN2A_MIXOUTR_VOL_MASK            0x000C  /* IN2A_MIXOUTR_VOL - [3:2] */
+#define WM9090_IN2A_MIXOUTR_VOL_SHIFT                2  /* IN2A_MIXOUTR_VOL - [3:2] */
+#define WM9090_IN2A_MIXOUTR_VOL_WIDTH                2  /* IN2A_MIXOUTR_VOL - [3:2] */
+#define WM9090_IN2B_MIXOUTR_VOL_MASK            0x0003  /* IN2B_MIXOUTR_VOL - [1:0] */
+#define WM9090_IN2B_MIXOUTR_VOL_SHIFT                0  /* IN2B_MIXOUTR_VOL - [1:0] */
+#define WM9090_IN2B_MIXOUTR_VOL_WIDTH                2  /* IN2B_MIXOUTR_VOL - [1:0] */
+
+/*
+ * R54 (0x36) - Speaker Mixer
+ */
+#define WM9090_IN1A_TO_SPKMIX                   0x0040  /* IN1A_TO_SPKMIX */
+#define WM9090_IN1A_TO_SPKMIX_MASK              0x0040  /* IN1A_TO_SPKMIX */
+#define WM9090_IN1A_TO_SPKMIX_SHIFT                  6  /* IN1A_TO_SPKMIX */
+#define WM9090_IN1A_TO_SPKMIX_WIDTH                  1  /* IN1A_TO_SPKMIX */
+#define WM9090_IN1B_TO_SPKMIX                   0x0010  /* IN1B_TO_SPKMIX */
+#define WM9090_IN1B_TO_SPKMIX_MASK              0x0010  /* IN1B_TO_SPKMIX */
+#define WM9090_IN1B_TO_SPKMIX_SHIFT                  4  /* IN1B_TO_SPKMIX */
+#define WM9090_IN1B_TO_SPKMIX_WIDTH                  1  /* IN1B_TO_SPKMIX */
+#define WM9090_IN2A_TO_SPKMIX                   0x0004  /* IN2A_TO_SPKMIX */
+#define WM9090_IN2A_TO_SPKMIX_MASK              0x0004  /* IN2A_TO_SPKMIX */
+#define WM9090_IN2A_TO_SPKMIX_SHIFT                  2  /* IN2A_TO_SPKMIX */
+#define WM9090_IN2A_TO_SPKMIX_WIDTH                  1  /* IN2A_TO_SPKMIX */
+#define WM9090_IN2B_TO_SPKMIX                   0x0001  /* IN2B_TO_SPKMIX */
+#define WM9090_IN2B_TO_SPKMIX_MASK              0x0001  /* IN2B_TO_SPKMIX */
+#define WM9090_IN2B_TO_SPKMIX_SHIFT                  0  /* IN2B_TO_SPKMIX */
+#define WM9090_IN2B_TO_SPKMIX_WIDTH                  1  /* IN2B_TO_SPKMIX */
+
+/*
+ * R57 (0x39) - AntiPOP2
+ */
+#define WM9090_VMID_BUF_ENA                     0x0008  /* VMID_BUF_ENA */
+#define WM9090_VMID_BUF_ENA_MASK                0x0008  /* VMID_BUF_ENA */
+#define WM9090_VMID_BUF_ENA_SHIFT                    3  /* VMID_BUF_ENA */
+#define WM9090_VMID_BUF_ENA_WIDTH                    1  /* VMID_BUF_ENA */
+#define WM9090_VMID_ENA                         0x0001  /* VMID_ENA */
+#define WM9090_VMID_ENA_MASK                    0x0001  /* VMID_ENA */
+#define WM9090_VMID_ENA_SHIFT                        0  /* VMID_ENA */
+#define WM9090_VMID_ENA_WIDTH                        1  /* VMID_ENA */
+
+/*
+ * R70 (0x46) - Write Sequencer 0
+ */
+#define WM9090_WSEQ_ENA                         0x0100  /* WSEQ_ENA */
+#define WM9090_WSEQ_ENA_MASK                    0x0100  /* WSEQ_ENA */
+#define WM9090_WSEQ_ENA_SHIFT                        8  /* WSEQ_ENA */
+#define WM9090_WSEQ_ENA_WIDTH                        1  /* WSEQ_ENA */
+#define WM9090_WSEQ_WRITE_INDEX_MASK            0x000F  /* WSEQ_WRITE_INDEX - [3:0] */
+#define WM9090_WSEQ_WRITE_INDEX_SHIFT                0  /* WSEQ_WRITE_INDEX - [3:0] */
+#define WM9090_WSEQ_WRITE_INDEX_WIDTH                4  /* WSEQ_WRITE_INDEX - [3:0] */
+
+/*
+ * R71 (0x47) - Write Sequencer 1
+ */
+#define WM9090_WSEQ_DATA_WIDTH_MASK             0x7000  /* WSEQ_DATA_WIDTH - [14:12] */
+#define WM9090_WSEQ_DATA_WIDTH_SHIFT                12  /* WSEQ_DATA_WIDTH - [14:12] */
+#define WM9090_WSEQ_DATA_WIDTH_WIDTH                 3  /* WSEQ_DATA_WIDTH - [14:12] */
+#define WM9090_WSEQ_DATA_START_MASK             0x0F00  /* WSEQ_DATA_START - [11:8] */
+#define WM9090_WSEQ_DATA_START_SHIFT                 8  /* WSEQ_DATA_START - [11:8] */
+#define WM9090_WSEQ_DATA_START_WIDTH                 4  /* WSEQ_DATA_START - [11:8] */
+#define WM9090_WSEQ_ADDR_MASK                   0x00FF  /* WSEQ_ADDR - [7:0] */
+#define WM9090_WSEQ_ADDR_SHIFT                       0  /* WSEQ_ADDR - [7:0] */
+#define WM9090_WSEQ_ADDR_WIDTH                       8  /* WSEQ_ADDR - [7:0] */
+
+/*
+ * R72 (0x48) - Write Sequencer 2
+ */
+#define WM9090_WSEQ_EOS                         0x4000  /* WSEQ_EOS */
+#define WM9090_WSEQ_EOS_MASK                    0x4000  /* WSEQ_EOS */
+#define WM9090_WSEQ_EOS_SHIFT                       14  /* WSEQ_EOS */
+#define WM9090_WSEQ_EOS_WIDTH                        1  /* WSEQ_EOS */
+#define WM9090_WSEQ_DELAY_MASK                  0x0F00  /* WSEQ_DELAY - [11:8] */
+#define WM9090_WSEQ_DELAY_SHIFT                      8  /* WSEQ_DELAY - [11:8] */
+#define WM9090_WSEQ_DELAY_WIDTH                      4  /* WSEQ_DELAY - [11:8] */
+#define WM9090_WSEQ_DATA_MASK                   0x00FF  /* WSEQ_DATA - [7:0] */
+#define WM9090_WSEQ_DATA_SHIFT                       0  /* WSEQ_DATA - [7:0] */
+#define WM9090_WSEQ_DATA_WIDTH                       8  /* WSEQ_DATA - [7:0] */
+
+/*
+ * R73 (0x49) - Write Sequencer 3
+ */
+#define WM9090_WSEQ_ABORT                       0x0200  /* WSEQ_ABORT */
+#define WM9090_WSEQ_ABORT_MASK                  0x0200  /* WSEQ_ABORT */
+#define WM9090_WSEQ_ABORT_SHIFT                      9  /* WSEQ_ABORT */
+#define WM9090_WSEQ_ABORT_WIDTH                      1  /* WSEQ_ABORT */
+#define WM9090_WSEQ_START                       0x0100  /* WSEQ_START */
+#define WM9090_WSEQ_START_MASK                  0x0100  /* WSEQ_START */
+#define WM9090_WSEQ_START_SHIFT                      8  /* WSEQ_START */
+#define WM9090_WSEQ_START_WIDTH                      1  /* WSEQ_START */
+#define WM9090_WSEQ_START_INDEX_MASK            0x003F  /* WSEQ_START_INDEX - [5:0] */
+#define WM9090_WSEQ_START_INDEX_SHIFT                0  /* WSEQ_START_INDEX - [5:0] */
+#define WM9090_WSEQ_START_INDEX_WIDTH                6  /* WSEQ_START_INDEX - [5:0] */
+
+/*
+ * R74 (0x4A) - Write Sequencer 4
+ */
+#define WM9090_WSEQ_BUSY                        0x0001  /* WSEQ_BUSY */
+#define WM9090_WSEQ_BUSY_MASK                   0x0001  /* WSEQ_BUSY */
+#define WM9090_WSEQ_BUSY_SHIFT                       0  /* WSEQ_BUSY */
+#define WM9090_WSEQ_BUSY_WIDTH                       1  /* WSEQ_BUSY */
+
+/*
+ * R75 (0x4B) - Write Sequencer 5
+ */
+#define WM9090_WSEQ_CURRENT_INDEX_MASK          0x003F  /* WSEQ_CURRENT_INDEX - [5:0] */
+#define WM9090_WSEQ_CURRENT_INDEX_SHIFT              0  /* WSEQ_CURRENT_INDEX - [5:0] */
+#define WM9090_WSEQ_CURRENT_INDEX_WIDTH              6  /* WSEQ_CURRENT_INDEX - [5:0] */
+
+/*
+ * R76 (0x4C) - Charge Pump 1
+ */
+#define WM9090_CP_ENA                           0x8000  /* CP_ENA */
+#define WM9090_CP_ENA_MASK                      0x8000  /* CP_ENA */
+#define WM9090_CP_ENA_SHIFT                         15  /* CP_ENA */
+#define WM9090_CP_ENA_WIDTH                          1  /* CP_ENA */
+
+/*
+ * R84 (0x54) - DC Servo 0
+ */
+#define WM9090_DCS_TRIG_SINGLE_1                0x2000  /* DCS_TRIG_SINGLE_1 */
+#define WM9090_DCS_TRIG_SINGLE_1_MASK           0x2000  /* DCS_TRIG_SINGLE_1 */
+#define WM9090_DCS_TRIG_SINGLE_1_SHIFT              13  /* DCS_TRIG_SINGLE_1 */
+#define WM9090_DCS_TRIG_SINGLE_1_WIDTH               1  /* DCS_TRIG_SINGLE_1 */
+#define WM9090_DCS_TRIG_SINGLE_0                0x1000  /* DCS_TRIG_SINGLE_0 */
+#define WM9090_DCS_TRIG_SINGLE_0_MASK           0x1000  /* DCS_TRIG_SINGLE_0 */
+#define WM9090_DCS_TRIG_SINGLE_0_SHIFT              12  /* DCS_TRIG_SINGLE_0 */
+#define WM9090_DCS_TRIG_SINGLE_0_WIDTH               1  /* DCS_TRIG_SINGLE_0 */
+#define WM9090_DCS_TRIG_SERIES_1                0x0200  /* DCS_TRIG_SERIES_1 */
+#define WM9090_DCS_TRIG_SERIES_1_MASK           0x0200  /* DCS_TRIG_SERIES_1 */
+#define WM9090_DCS_TRIG_SERIES_1_SHIFT               9  /* DCS_TRIG_SERIES_1 */
+#define WM9090_DCS_TRIG_SERIES_1_WIDTH               1  /* DCS_TRIG_SERIES_1 */
+#define WM9090_DCS_TRIG_SERIES_0                0x0100  /* DCS_TRIG_SERIES_0 */
+#define WM9090_DCS_TRIG_SERIES_0_MASK           0x0100  /* DCS_TRIG_SERIES_0 */
+#define WM9090_DCS_TRIG_SERIES_0_SHIFT               8  /* DCS_TRIG_SERIES_0 */
+#define WM9090_DCS_TRIG_SERIES_0_WIDTH               1  /* DCS_TRIG_SERIES_0 */
+#define WM9090_DCS_TRIG_STARTUP_1               0x0020  /* DCS_TRIG_STARTUP_1 */
+#define WM9090_DCS_TRIG_STARTUP_1_MASK          0x0020  /* DCS_TRIG_STARTUP_1 */
+#define WM9090_DCS_TRIG_STARTUP_1_SHIFT              5  /* DCS_TRIG_STARTUP_1 */
+#define WM9090_DCS_TRIG_STARTUP_1_WIDTH              1  /* DCS_TRIG_STARTUP_1 */
+#define WM9090_DCS_TRIG_STARTUP_0               0x0010  /* DCS_TRIG_STARTUP_0 */
+#define WM9090_DCS_TRIG_STARTUP_0_MASK          0x0010  /* DCS_TRIG_STARTUP_0 */
+#define WM9090_DCS_TRIG_STARTUP_0_SHIFT              4  /* DCS_TRIG_STARTUP_0 */
+#define WM9090_DCS_TRIG_STARTUP_0_WIDTH              1  /* DCS_TRIG_STARTUP_0 */
+#define WM9090_DCS_TRIG_DAC_WR_1                0x0008  /* DCS_TRIG_DAC_WR_1 */
+#define WM9090_DCS_TRIG_DAC_WR_1_MASK           0x0008  /* DCS_TRIG_DAC_WR_1 */
+#define WM9090_DCS_TRIG_DAC_WR_1_SHIFT               3  /* DCS_TRIG_DAC_WR_1 */
+#define WM9090_DCS_TRIG_DAC_WR_1_WIDTH               1  /* DCS_TRIG_DAC_WR_1 */
+#define WM9090_DCS_TRIG_DAC_WR_0                0x0004  /* DCS_TRIG_DAC_WR_0 */
+#define WM9090_DCS_TRIG_DAC_WR_0_MASK           0x0004  /* DCS_TRIG_DAC_WR_0 */
+#define WM9090_DCS_TRIG_DAC_WR_0_SHIFT               2  /* DCS_TRIG_DAC_WR_0 */
+#define WM9090_DCS_TRIG_DAC_WR_0_WIDTH               1  /* DCS_TRIG_DAC_WR_0 */
+#define WM9090_DCS_ENA_CHAN_1                   0x0002  /* DCS_ENA_CHAN_1 */
+#define WM9090_DCS_ENA_CHAN_1_MASK              0x0002  /* DCS_ENA_CHAN_1 */
+#define WM9090_DCS_ENA_CHAN_1_SHIFT                  1  /* DCS_ENA_CHAN_1 */
+#define WM9090_DCS_ENA_CHAN_1_WIDTH                  1  /* DCS_ENA_CHAN_1 */
+#define WM9090_DCS_ENA_CHAN_0                   0x0001  /* DCS_ENA_CHAN_0 */
+#define WM9090_DCS_ENA_CHAN_0_MASK              0x0001  /* DCS_ENA_CHAN_0 */
+#define WM9090_DCS_ENA_CHAN_0_SHIFT                  0  /* DCS_ENA_CHAN_0 */
+#define WM9090_DCS_ENA_CHAN_0_WIDTH                  1  /* DCS_ENA_CHAN_0 */
+
+/*
+ * R85 (0x55) - DC Servo 1
+ */
+#define WM9090_DCS_SERIES_NO_01_MASK            0x0FE0  /* DCS_SERIES_NO_01 - [11:5] */
+#define WM9090_DCS_SERIES_NO_01_SHIFT                5  /* DCS_SERIES_NO_01 - [11:5] */
+#define WM9090_DCS_SERIES_NO_01_WIDTH                7  /* DCS_SERIES_NO_01 - [11:5] */
+#define WM9090_DCS_TIMER_PERIOD_01_MASK         0x000F  /* DCS_TIMER_PERIOD_01 - [3:0] */
+#define WM9090_DCS_TIMER_PERIOD_01_SHIFT             0  /* DCS_TIMER_PERIOD_01 - [3:0] */
+#define WM9090_DCS_TIMER_PERIOD_01_WIDTH             4  /* DCS_TIMER_PERIOD_01 - [3:0] */
+
+/*
+ * R87 (0x57) - DC Servo 3
+ */
+#define WM9090_DCS_DAC_WR_VAL_1_MASK            0xFF00  /* DCS_DAC_WR_VAL_1 - [15:8] */
+#define WM9090_DCS_DAC_WR_VAL_1_SHIFT                8  /* DCS_DAC_WR_VAL_1 - [15:8] */
+#define WM9090_DCS_DAC_WR_VAL_1_WIDTH                8  /* DCS_DAC_WR_VAL_1 - [15:8] */
+#define WM9090_DCS_DAC_WR_VAL_0_MASK            0x00FF  /* DCS_DAC_WR_VAL_0 - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_0_SHIFT                0  /* DCS_DAC_WR_VAL_0 - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_0_WIDTH                8  /* DCS_DAC_WR_VAL_0 - [7:0] */
+
+/*
+ * R88 (0x58) - DC Servo Readback 0
+ */
+#define WM9090_DCS_CAL_COMPLETE_MASK            0x0300  /* DCS_CAL_COMPLETE - [9:8] */
+#define WM9090_DCS_CAL_COMPLETE_SHIFT                8  /* DCS_CAL_COMPLETE - [9:8] */
+#define WM9090_DCS_CAL_COMPLETE_WIDTH                2  /* DCS_CAL_COMPLETE - [9:8] */
+#define WM9090_DCS_DAC_WR_COMPLETE_MASK         0x0030  /* DCS_DAC_WR_COMPLETE - [5:4] */
+#define WM9090_DCS_DAC_WR_COMPLETE_SHIFT             4  /* DCS_DAC_WR_COMPLETE - [5:4] */
+#define WM9090_DCS_DAC_WR_COMPLETE_WIDTH             2  /* DCS_DAC_WR_COMPLETE - [5:4] */
+#define WM9090_DCS_STARTUP_COMPLETE_MASK        0x0003  /* DCS_STARTUP_COMPLETE - [1:0] */
+#define WM9090_DCS_STARTUP_COMPLETE_SHIFT            0  /* DCS_STARTUP_COMPLETE - [1:0] */
+#define WM9090_DCS_STARTUP_COMPLETE_WIDTH            2  /* DCS_STARTUP_COMPLETE - [1:0] */
+
+/*
+ * R89 (0x59) - DC Servo Readback 1
+ */
+#define WM9090_DCS_DAC_WR_VAL_1_RD_MASK         0x00FF  /* DCS_DAC_WR_VAL_1_RD - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_1_RD_SHIFT             0  /* DCS_DAC_WR_VAL_1_RD - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_1_RD_WIDTH             8  /* DCS_DAC_WR_VAL_1_RD - [7:0] */
+
+/*
+ * R90 (0x5A) - DC Servo Readback 2
+ */
+#define WM9090_DCS_DAC_WR_VAL_0_RD_MASK         0x00FF  /* DCS_DAC_WR_VAL_0_RD - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_0_RD_SHIFT             0  /* DCS_DAC_WR_VAL_0_RD - [7:0] */
+#define WM9090_DCS_DAC_WR_VAL_0_RD_WIDTH             8  /* DCS_DAC_WR_VAL_0_RD - [7:0] */
+
+/*
+ * R96 (0x60) - Analogue HP 0
+ */
+#define WM9090_HPOUT1L_RMV_SHORT                0x0080  /* HPOUT1L_RMV_SHORT */
+#define WM9090_HPOUT1L_RMV_SHORT_MASK           0x0080  /* HPOUT1L_RMV_SHORT */
+#define WM9090_HPOUT1L_RMV_SHORT_SHIFT               7  /* HPOUT1L_RMV_SHORT */
+#define WM9090_HPOUT1L_RMV_SHORT_WIDTH               1  /* HPOUT1L_RMV_SHORT */
+#define WM9090_HPOUT1L_OUTP                     0x0040  /* HPOUT1L_OUTP */
+#define WM9090_HPOUT1L_OUTP_MASK                0x0040  /* HPOUT1L_OUTP */
+#define WM9090_HPOUT1L_OUTP_SHIFT                    6  /* HPOUT1L_OUTP */
+#define WM9090_HPOUT1L_OUTP_WIDTH                    1  /* HPOUT1L_OUTP */
+#define WM9090_HPOUT1L_DLY                      0x0020  /* HPOUT1L_DLY */
+#define WM9090_HPOUT1L_DLY_MASK                 0x0020  /* HPOUT1L_DLY */
+#define WM9090_HPOUT1L_DLY_SHIFT                     5  /* HPOUT1L_DLY */
+#define WM9090_HPOUT1L_DLY_WIDTH                     1  /* HPOUT1L_DLY */
+#define WM9090_HPOUT1R_RMV_SHORT                0x0008  /* HPOUT1R_RMV_SHORT */
+#define WM9090_HPOUT1R_RMV_SHORT_MASK           0x0008  /* HPOUT1R_RMV_SHORT */
+#define WM9090_HPOUT1R_RMV_SHORT_SHIFT               3  /* HPOUT1R_RMV_SHORT */
+#define WM9090_HPOUT1R_RMV_SHORT_WIDTH               1  /* HPOUT1R_RMV_SHORT */
+#define WM9090_HPOUT1R_OUTP                     0x0004  /* HPOUT1R_OUTP */
+#define WM9090_HPOUT1R_OUTP_MASK                0x0004  /* HPOUT1R_OUTP */
+#define WM9090_HPOUT1R_OUTP_SHIFT                    2  /* HPOUT1R_OUTP */
+#define WM9090_HPOUT1R_OUTP_WIDTH                    1  /* HPOUT1R_OUTP */
+#define WM9090_HPOUT1R_DLY                      0x0002  /* HPOUT1R_DLY */
+#define WM9090_HPOUT1R_DLY_MASK                 0x0002  /* HPOUT1R_DLY */
+#define WM9090_HPOUT1R_DLY_SHIFT                     1  /* HPOUT1R_DLY */
+#define WM9090_HPOUT1R_DLY_WIDTH                     1  /* HPOUT1R_DLY */
+
+/*
+ * R98 (0x62) - AGC Control 0
+ */
+#define WM9090_AGC_CLIP_ENA                     0x8000  /* AGC_CLIP_ENA */
+#define WM9090_AGC_CLIP_ENA_MASK                0x8000  /* AGC_CLIP_ENA */
+#define WM9090_AGC_CLIP_ENA_SHIFT                   15  /* AGC_CLIP_ENA */
+#define WM9090_AGC_CLIP_ENA_WIDTH                    1  /* AGC_CLIP_ENA */
+#define WM9090_AGC_CLIP_THR_MASK                0x0F00  /* AGC_CLIP_THR - [11:8] */
+#define WM9090_AGC_CLIP_THR_SHIFT                    8  /* AGC_CLIP_THR - [11:8] */
+#define WM9090_AGC_CLIP_THR_WIDTH                    4  /* AGC_CLIP_THR - [11:8] */
+#define WM9090_AGC_CLIP_ATK_MASK                0x0070  /* AGC_CLIP_ATK - [6:4] */
+#define WM9090_AGC_CLIP_ATK_SHIFT                    4  /* AGC_CLIP_ATK - [6:4] */
+#define WM9090_AGC_CLIP_ATK_WIDTH                    3  /* AGC_CLIP_ATK - [6:4] */
+#define WM9090_AGC_CLIP_DCY_MASK                0x0007  /* AGC_CLIP_DCY - [2:0] */
+#define WM9090_AGC_CLIP_DCY_SHIFT                    0  /* AGC_CLIP_DCY - [2:0] */
+#define WM9090_AGC_CLIP_DCY_WIDTH                    3  /* AGC_CLIP_DCY - [2:0] */
+
+/*
+ * R99 (0x63) - AGC Control 1
+ */
+#define WM9090_AGC_PWR_ENA                      0x8000  /* AGC_PWR_ENA */
+#define WM9090_AGC_PWR_ENA_MASK                 0x8000  /* AGC_PWR_ENA */
+#define WM9090_AGC_PWR_ENA_SHIFT                    15  /* AGC_PWR_ENA */
+#define WM9090_AGC_PWR_ENA_WIDTH                     1  /* AGC_PWR_ENA */
+#define WM9090_AGC_PWR_AVG                      0x1000  /* AGC_PWR_AVG */
+#define WM9090_AGC_PWR_AVG_MASK                 0x1000  /* AGC_PWR_AVG */
+#define WM9090_AGC_PWR_AVG_SHIFT                    12  /* AGC_PWR_AVG */
+#define WM9090_AGC_PWR_AVG_WIDTH                     1  /* AGC_PWR_AVG */
+#define WM9090_AGC_PWR_THR_MASK                 0x0F00  /* AGC_PWR_THR - [11:8] */
+#define WM9090_AGC_PWR_THR_SHIFT                     8  /* AGC_PWR_THR - [11:8] */
+#define WM9090_AGC_PWR_THR_WIDTH                     4  /* AGC_PWR_THR - [11:8] */
+#define WM9090_AGC_PWR_ATK_MASK                 0x0070  /* AGC_PWR_ATK - [6:4] */
+#define WM9090_AGC_PWR_ATK_SHIFT                     4  /* AGC_PWR_ATK - [6:4] */
+#define WM9090_AGC_PWR_ATK_WIDTH                     3  /* AGC_PWR_ATK - [6:4] */
+#define WM9090_AGC_PWR_DCY_MASK                 0x0007  /* AGC_PWR_DCY - [2:0] */
+#define WM9090_AGC_PWR_DCY_SHIFT                     0  /* AGC_PWR_DCY - [2:0] */
+#define WM9090_AGC_PWR_DCY_WIDTH                     3  /* AGC_PWR_DCY - [2:0] */
+
+/*
+ * R100 (0x64) - AGC Control 2
+ */
+#define WM9090_AGC_RAMP                         0x0100  /* AGC_RAMP */
+#define WM9090_AGC_RAMP_MASK                    0x0100  /* AGC_RAMP */
+#define WM9090_AGC_RAMP_SHIFT                        8  /* AGC_RAMP */
+#define WM9090_AGC_RAMP_WIDTH                        1  /* AGC_RAMP */
+#define WM9090_AGC_MINGAIN_MASK                 0x003F  /* AGC_MINGAIN - [5:0] */
+#define WM9090_AGC_MINGAIN_SHIFT                     0  /* AGC_MINGAIN - [5:0] */
+#define WM9090_AGC_MINGAIN_WIDTH                     6  /* AGC_MINGAIN - [5:0] */
+
+#endif
index 2f48a8a..28790a2 100644 (file)
@@ -632,9 +632,6 @@ static int wm9712_soc_resume(struct platform_device *pdev)
                }
        }
 
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
-               wm9712_set_bias_level(codec, SND_SOC_BIAS_ON);
-
        return ret;
 }
 
index 2fca514..34e0c91 100644 (file)
@@ -764,7 +764,7 @@ static void pll_factors(struct _pll_div *pll_div, unsigned int source)
 static int wm9713_set_pll(struct snd_soc_codec *codec,
        int pll_id, unsigned int freq_in, unsigned int freq_out)
 {
-       struct wm9713_priv *wm9713 = codec->private_data;
+       struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
        u16 reg, reg2;
        struct _pll_div pll_div;
 
@@ -1175,7 +1175,7 @@ static int wm9713_soc_resume(struct platform_device *pdev)
 {
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
-       struct wm9713_priv *wm9713 = codec->private_data;
+       struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec);
        int i, ret;
        u16 *cache = codec->reg_cache;
 
@@ -1201,9 +1201,6 @@ static int wm9713_soc_resume(struct platform_device *pdev)
                }
        }
 
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
-               wm9713_set_bias_level(codec, SND_SOC_BIAS_ON);
-
        return ret;
 }
 
@@ -1228,8 +1225,9 @@ static int wm9713_soc_probe(struct platform_device *pdev)
        codec->reg_cache_size = sizeof(wm9713_reg);
        codec->reg_cache_step = 2;
 
-       codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL);
-       if (codec->private_data == NULL) {
+       snd_soc_codec_set_drvdata(codec, kzalloc(sizeof(struct wm9713_priv),
+                                                GFP_KERNEL));
+       if (snd_soc_codec_get_drvdata(codec) == NULL) {
                ret = -ENOMEM;
                goto priv_err;
        }
@@ -1280,7 +1278,7 @@ pcm_err:
        snd_soc_free_ac97_codec(codec);
 
 codec_err:
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
 
 priv_err:
        kfree(codec->reg_cache);
@@ -1302,7 +1300,7 @@ static int wm9713_soc_remove(struct platform_device *pdev)
        snd_soc_dapm_free(socdev);
        snd_soc_free_pcms(socdev);
        snd_soc_free_ac97_codec(codec);
-       kfree(codec->private_data);
+       kfree(snd_soc_codec_get_drvdata(codec));
        kfree(codec->reg_cache);
        kfree(codec);
        return 0;
index e1f225a..16f1a57 100644 (file)
@@ -91,7 +91,7 @@ static void wait_for_dc_servo(struct snd_soc_codec *codec, unsigned int op)
  */
 static void calibrate_dc_servo(struct snd_soc_codec *codec)
 {
-       struct wm_hubs_data *hubs = codec->private_data;
+       struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
        u16 reg, reg_l, reg_r, dcs_cfg;
 
        /* Set for 32 series updates */
@@ -127,6 +127,8 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
                        break;
                }
 
+               dev_dbg(codec->dev, "DCS input: %x %x\n", reg_l, reg_r);
+
                /* HPOUT1L */
                if (reg_l + hubs->dcs_codes > 0 &&
                    reg_l + hubs->dcs_codes < 0xff)
@@ -139,6 +141,8 @@ static void calibrate_dc_servo(struct snd_soc_codec *codec)
                        reg_r += hubs->dcs_codes;
                dcs_cfg |= reg_r;
 
+               dev_dbg(codec->dev, "DCS result: %x\n", dcs_cfg);
+
                /* Do it */
                snd_soc_write(codec, WM8993_DC_SERVO_3, dcs_cfg);
                wait_for_dc_servo(codec,
@@ -154,7 +158,7 @@ static int wm8993_put_dc_servo(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm_hubs_data *hubs = codec->private_data;
+       struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        ret = snd_soc_put_volsw_2r(kcontrol, ucontrol);
@@ -327,7 +331,7 @@ static int hp_supply_event(struct snd_soc_dapm_widget *w,
                           struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm_hubs_data *hubs = codec->private_data;
+       struct wm_hubs_data *hubs = snd_soc_codec_get_drvdata(codec);
 
        switch (event) {
        case SND_SOC_DAPM_PRE_PMU:
@@ -397,14 +401,14 @@ static int hp_event(struct snd_soc_dapm_widget *w,
 
        case SND_SOC_DAPM_PRE_PMD:
                snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
-                                   WM8993_HPOUT1L_DLY |
-                                   WM8993_HPOUT1R_DLY |
+                                   WM8993_HPOUT1L_OUTP |
+                                   WM8993_HPOUT1R_OUTP |
                                    WM8993_HPOUT1L_RMV_SHORT |
                                    WM8993_HPOUT1R_RMV_SHORT, 0);
 
                snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
-                                   WM8993_HPOUT1L_OUTP |
-                                   WM8993_HPOUT1R_OUTP, 0);
+                                   WM8993_HPOUT1L_DLY |
+                                   WM8993_HPOUT1R_DLY, 0);
 
                snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
                                    WM8993_HPOUT1L_ENA | WM8993_HPOUT1R_ENA,
index 047ee39..6bbf001 100644 (file)
@@ -12,15 +12,38 @@ config SND_DAVINCI_SOC_I2S
 config SND_DAVINCI_SOC_MCASP
        tristate
 
+config SND_DAVINCI_SOC_VCIF
+       tristate
+
 config SND_DAVINCI_SOC_EVM
        tristate "SoC Audio support for DaVinci DM6446, DM355 or DM365 EVM"
        depends on SND_DAVINCI_SOC
-       depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM  || MACH_DAVINCI_DM365_EVM
+       depends on MACH_DAVINCI_EVM || MACH_DAVINCI_DM355_EVM || MACH_DAVINCI_DM365_EVM
        select SND_DAVINCI_SOC_I2S
        select SND_SOC_TLV320AIC3X
        help
          Say Y if you want to add support for SoC audio on TI
-         DaVinci DM6446 or DM355 EVM platforms.
+         DaVinci DM6446, DM355 or DM365 EVM platforms.
+
+choice
+       prompt "DM365 codec select"
+       depends on SND_DAVINCI_SOC_EVM
+       depends on MACH_DAVINCI_DM365_EVM
+       default SND_DM365_EXTERNAL_CODEC
+
+config SND_DM365_AIC3X_CODEC
+       bool "Audio Codec - AIC3101"
+       help
+         Say Y if you want to add support for AIC3101 audio codec
+
+config SND_DM365_VOICE_CODEC
+       bool "Voice Codec - CQ93VC"
+       select MFD_DAVINCI_VOICECODEC
+       select SND_DAVINCI_SOC_VCIF
+       select SND_SOC_CQ0093VC
+       help
+         Say Y if you want to add support for SoC On-chip voice codec
+endchoice
 
 config  SND_DM6467_SOC_EVM
        tristate "SoC Audio support for DaVinci DM6467 EVM"
index a6939d7..a93679d 100644 (file)
@@ -2,10 +2,12 @@
 snd-soc-davinci-objs := davinci-pcm.o
 snd-soc-davinci-i2s-objs := davinci-i2s.o
 snd-soc-davinci-mcasp-objs:= davinci-mcasp.o
+snd-soc-davinci-vcif-objs:= davinci-vcif.o
 
 obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
 obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
 obj-$(CONFIG_SND_DAVINCI_SOC_MCASP) += snd-soc-davinci-mcasp.o
+obj-$(CONFIG_SND_DAVINCI_SOC_VCIF) += snd-soc-davinci-vcif.o
 
 # DAVINCI Machine Support
 snd-soc-evm-objs := davinci-evm.o
index 7ccbe66..97f74d6 100644 (file)
 #include <mach/mux.h>
 
 #include "../codecs/tlv320aic3x.h"
+#include "../codecs/cq93vc.h"
 #include "../codecs/spdif_transciever.h"
 #include "davinci-pcm.h"
 #include "davinci-i2s.h"
 #include "davinci-mcasp.h"
+#include "davinci-vcif.h"
 
 #define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
                SND_SOC_DAIFMT_CBM_CFM | SND_SOC_DAIFMT_IB_NF)
@@ -81,10 +83,24 @@ static int evm_hw_params(struct snd_pcm_substream *substream,
        return 0;
 }
 
+static int evm_spdif_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+
+       /* set cpu DAI configuration */
+       return snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
+}
+
 static struct snd_soc_ops evm_ops = {
        .hw_params = evm_hw_params,
 };
 
+static struct snd_soc_ops evm_spdif_ops = {
+       .hw_params = evm_spdif_hw_params,
+};
+
 /* davinci-evm machine dapm widgets */
 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
        SND_SOC_DAPM_HP("Headphone Jack", NULL),
@@ -151,6 +167,22 @@ static struct snd_soc_dai_link evm_dai = {
        .ops = &evm_ops,
 };
 
+static struct snd_soc_dai_link dm365_evm_dai = {
+#ifdef CONFIG_SND_DM365_AIC3X_CODEC
+       .name = "TLV320AIC3X",
+       .stream_name = "AIC3X",
+       .cpu_dai = &davinci_i2s_dai,
+       .codec_dai = &aic3x_dai,
+       .init = evm_aic3x_init,
+       .ops = &evm_ops,
+#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
+       .name = "Voice Codec - CQ93VC",
+       .stream_name = "CQ93",
+       .cpu_dai = &davinci_vcif_dai,
+       .codec_dai = &cq93vc_dai,
+#endif
+};
+
 static struct snd_soc_dai_link dm6467_evm_dai[] = {
        {
                .name = "TLV320AIC3X",
@@ -165,7 +197,7 @@ static struct snd_soc_dai_link dm6467_evm_dai[] = {
                .stream_name = "spdif",
                .cpu_dai = &davinci_mcasp_dai[DAVINCI_MCASP_DIT_DAI],
                .codec_dai = &dit_stub_dai,
-               .ops = &evm_ops,
+               .ops = &evm_spdif_ops,
        },
 };
 static struct snd_soc_dai_link da8xx_evm_dai = {
@@ -177,7 +209,7 @@ static struct snd_soc_dai_link da8xx_evm_dai = {
        .ops = &evm_ops,
 };
 
-/* davinci dm6446, dm355 or dm365 evm audio machine driver */
+/* davinci dm6446, dm355 evm audio machine driver */
 static struct snd_soc_card snd_soc_card_evm = {
        .name = "DaVinci EVM",
        .platform = &davinci_soc_platform,
@@ -185,6 +217,15 @@ static struct snd_soc_card snd_soc_card_evm = {
        .num_links = 1,
 };
 
+/* davinci dm365 evm audio machine driver */
+static struct snd_soc_card dm365_snd_soc_card_evm = {
+       .name = "DaVinci DM365 EVM",
+       .platform = &davinci_soc_platform,
+       .dai_link = &dm365_evm_dai,
+       .num_links = 1,
+};
+
+
 /* davinci dm6467 evm audio machine driver */
 static struct snd_soc_card dm6467_snd_soc_card_evm = {
        .name = "DaVinci DM6467 EVM",
@@ -216,6 +257,17 @@ static struct snd_soc_device evm_snd_devdata = {
        .codec_data = &aic3x_setup,
 };
 
+/* evm audio subsystem */
+static struct snd_soc_device dm365_evm_snd_devdata = {
+       .card = &dm365_snd_soc_card_evm,
+#ifdef CONFIG_SND_DM365_AIC3X_CODEC
+       .codec_dev = &soc_codec_dev_aic3x,
+       .codec_data = &aic3x_setup,
+#elif defined(CONFIG_SND_DM365_VOICE_CODEC)
+       .codec_dev = &soc_codec_dev_cq93vc,
+#endif
+};
+
 /* evm audio subsystem */
 static struct snd_soc_device dm6467_evm_snd_devdata = {
        .card = &dm6467_snd_soc_card_evm,
@@ -244,12 +296,15 @@ static int __init evm_init(void)
        int index;
        int ret;
 
-       if (machine_is_davinci_evm() || machine_is_davinci_dm365_evm()) {
+       if (machine_is_davinci_evm()) {
                evm_snd_dev_data = &evm_snd_devdata;
                index = 0;
        } else if (machine_is_davinci_dm355_evm()) {
                evm_snd_dev_data = &evm_snd_devdata;
                index = 1;
+       } else if (machine_is_davinci_dm365_evm()) {
+               evm_snd_dev_data = &dm365_evm_snd_devdata;
+               index = 0;
        } else if (machine_is_davinci_dm6467_evm()) {
                evm_snd_dev_data = &dm6467_evm_snd_devdata;
                index = 0;
diff --git a/sound/soc/davinci/davinci-vcif.c b/sound/soc/davinci/davinci-vcif.c
new file mode 100644 (file)
index 0000000..9aa980d
--- /dev/null
@@ -0,0 +1,274 @@
+/*
+ * ALSA SoC Voice Codec Interface for TI DAVINCI processor
+ *
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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 <linux/init.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/io.h>
+#include <linux/mfd/davinci_voicecodec.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+
+#include "davinci-pcm.h"
+#include "davinci-i2s.h"
+#include "davinci-vcif.h"
+
+#define MOD_REG_BIT(val, mask, set) do { \
+       if (set) { \
+               val |= mask; \
+       } else { \
+               val &= ~mask; \
+       } \
+} while (0)
+
+struct davinci_vcif_dev {
+       struct davinci_vc *davinci_vc;
+       struct davinci_pcm_dma_params   dma_params[2];
+};
+
+static void davinci_vcif_start(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct davinci_vcif_dev *davinci_vcif_dev =
+                                       rtd->dai->cpu_dai->private_data;
+       struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
+       u32 w;
+
+       /* Start the sample generator and enable transmitter/receiver */
+       w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 1);
+       else
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 1);
+
+       writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
+}
+
+static void davinci_vcif_stop(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct davinci_vcif_dev *davinci_vcif_dev =
+                                       rtd->dai->cpu_dai->private_data;
+       struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
+       u32 w;
+
+       /* Reset transmitter/receiver and sample rate/frame sync generators */
+       w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTDAC, 0);
+       else
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RSTADC, 0);
+
+       writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
+}
+
+static int davinci_vcif_hw_params(struct snd_pcm_substream *substream,
+                                 struct snd_pcm_hw_params *params,
+                                 struct snd_soc_dai *dai)
+{
+       struct davinci_vcif_dev *davinci_vcif_dev = dai->private_data;
+       struct davinci_vc *davinci_vc = davinci_vcif_dev->davinci_vc;
+       struct davinci_pcm_dma_params *dma_params =
+                       &davinci_vcif_dev->dma_params[substream->stream];
+       u32 w;
+
+       /* Restart the codec before setup */
+       davinci_vcif_stop(substream);
+       davinci_vcif_start(substream);
+
+       /* General line settings */
+       writel(DAVINCI_VC_CTRL_MASK, davinci_vc->base + DAVINCI_VC_CTRL);
+
+       writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTCLR);
+
+       writel(DAVINCI_VC_INT_MASK, davinci_vc->base + DAVINCI_VC_INTEN);
+
+       w = readl(davinci_vc->base + DAVINCI_VC_CTRL);
+
+       /* Determine xfer data type */
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_U8:
+               dma_params->data_type = 0;
+
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
+                           DAVINCI_VC_CTRL_RD_UNSIGNED |
+                           DAVINCI_VC_CTRL_WD_BITS_8 |
+                           DAVINCI_VC_CTRL_WD_UNSIGNED, 1);
+               break;
+       case SNDRV_PCM_FORMAT_S8:
+               dma_params->data_type = 1;
+
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
+                           DAVINCI_VC_CTRL_WD_BITS_8, 1);
+
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_UNSIGNED |
+                           DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
+               break;
+       case SNDRV_PCM_FORMAT_S16_LE:
+               dma_params->data_type = 2;
+
+               MOD_REG_BIT(w, DAVINCI_VC_CTRL_RD_BITS_8 |
+                           DAVINCI_VC_CTRL_RD_UNSIGNED |
+                           DAVINCI_VC_CTRL_WD_BITS_8 |
+                           DAVINCI_VC_CTRL_WD_UNSIGNED, 0);
+               break;
+       default:
+               printk(KERN_WARNING "davinci-vcif: unsupported PCM format");
+               return -EINVAL;
+       }
+
+       dma_params->acnt  = dma_params->data_type;
+
+       writel(w, davinci_vc->base + DAVINCI_VC_CTRL);
+
+       return 0;
+}
+
+static int davinci_vcif_trigger(struct snd_pcm_substream *substream, int cmd,
+                               struct snd_soc_dai *dai)
+{
+       int ret = 0;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               davinci_vcif_start(substream);
+       case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               davinci_vcif_stop(substream);
+               break;
+       default:
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+#define DAVINCI_VCIF_RATES     SNDRV_PCM_RATE_8000_48000
+
+static struct snd_soc_dai_ops davinci_vcif_dai_ops = {
+       .trigger        = davinci_vcif_trigger,
+       .hw_params      = davinci_vcif_hw_params,
+};
+
+struct snd_soc_dai davinci_vcif_dai = {
+       .name = "davinci-vcif",
+       .playback = {
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = DAVINCI_VCIF_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .capture = {
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = DAVINCI_VCIF_RATES,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE,},
+       .ops = &davinci_vcif_dai_ops,
+
+};
+EXPORT_SYMBOL_GPL(davinci_vcif_dai);
+
+static int davinci_vcif_probe(struct platform_device *pdev)
+{
+       struct davinci_vc *davinci_vc = platform_get_drvdata(pdev);
+       struct davinci_vcif_dev *davinci_vcif_dev;
+       int ret;
+
+       davinci_vcif_dev = kzalloc(sizeof(struct davinci_vcif_dev), GFP_KERNEL);
+       if (!davinci_vc) {
+               dev_dbg(&pdev->dev,
+                       "could not allocate memory for private data\n");
+               return -ENOMEM;
+       }
+
+       /* DMA tx params */
+       davinci_vcif_dev->davinci_vc = davinci_vc;
+       davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel =
+                                       davinci_vc->davinci_vcif.dma_tx_channel;
+       davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr =
+                                       davinci_vc->davinci_vcif.dma_tx_addr;
+
+       /* DMA rx params */
+       davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel =
+                                       davinci_vc->davinci_vcif.dma_rx_channel;
+       davinci_vcif_dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr =
+                                       davinci_vc->davinci_vcif.dma_rx_addr;
+
+       davinci_vcif_dai.dev = &pdev->dev;
+       davinci_vcif_dai.capture.dma_data = davinci_vcif_dev->dma_params;
+       davinci_vcif_dai.playback.dma_data = davinci_vcif_dev->dma_params;
+       davinci_vcif_dai.private_data = davinci_vcif_dev;
+
+       ret = snd_soc_register_dai(&davinci_vcif_dai);
+       if (ret != 0) {
+               dev_err(&pdev->dev, "could not register dai\n");
+               goto fail;
+       }
+
+       return 0;
+
+fail:
+       kfree(davinci_vcif_dev);
+
+       return ret;
+}
+
+static int davinci_vcif_remove(struct platform_device *pdev)
+{
+       snd_soc_unregister_dai(&davinci_vcif_dai);
+
+       return 0;
+}
+
+static struct platform_driver davinci_vcif_driver = {
+       .probe          = davinci_vcif_probe,
+       .remove         = davinci_vcif_remove,
+       .driver         = {
+               .name   = "davinci_vcif",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init davinci_vcif_init(void)
+{
+       return platform_driver_probe(&davinci_vcif_driver, davinci_vcif_probe);
+}
+module_init(davinci_vcif_init);
+
+static void __exit davinci_vcif_exit(void)
+{
+       platform_driver_unregister(&davinci_vcif_driver);
+}
+module_exit(davinci_vcif_exit);
+
+MODULE_AUTHOR("Miguel Aguilar");
+MODULE_DESCRIPTION("Texas Instruments DaVinci ASoC Voice Codec Interface");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-vcif.h b/sound/soc/davinci/davinci-vcif.h
new file mode 100644 (file)
index 0000000..571c994
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * ALSA SoC Voice Codec Interface for TI DAVINCI processor
+ *
+ * Copyright (C) 2010 Texas Instruments.
+ *
+ * Author: Miguel Aguilar <miguel.aguilar@ridgerun.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
+ */
+
+#ifndef _DAVINCI_VCIF_H
+#define _DAVINCI_VCIF_H
+
+extern struct snd_soc_dai davinci_vcif_dai;
+
+#endif
index 7174b4c..eba9b9d 100644 (file)
@@ -11,3 +11,11 @@ config SND_IMX_SOC
 config SND_MXC_SOC_SSI
        tristate
 
+config SND_MXC_SOC_WM1133_EV1
+       tristate "Audio on the the i.MX31ADS with WM1133-EV1 fitted"
+       depends on SND_IMX_SOC && EXPERIMENTAL
+       select SND_SOC_WM8350
+       select SND_MXC_SOC_SSI
+       help
+         Enable support for audio on the i.MX31ADS with the WM1133-EV1
+         PMIC board with WM8835x fitted.
index 9f8bb92..2d20363 100644 (file)
@@ -9,4 +9,7 @@ obj-$(CONFIG_SND_IMX_SOC) += snd-soc-imx.o
 
 # i.MX Machine Support
 snd-soc-phycore-ac97-objs := phycore-ac97.o
+snd-soc-wm1133-ev1-objs := wm1133-ev1.o
+
 obj-$(CONFIG_SND_SOC_PHYCORE_AC97) += snd-soc-phycore-ac97.o
+obj-$(CONFIG_SND_MXC_SOC_WM1133_EV1) += snd-soc-wm1133-ev1.o
diff --git a/sound/soc/imx/wm1133-ev1.c b/sound/soc/imx/wm1133-ev1.c
new file mode 100644 (file)
index 0000000..a6e7d94
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ *  wm1133-ev1.c - Audio for WM1133-EV1 on i.MX31ADS
+ *
+ *  Copyright (c) 2010 Wolfson Microelectronics plc
+ *  Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ *  Based on an earlier driver for the same hardware by Liam Girdwood.
+ *
+ *  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.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <sound/core.h>
+#include <sound/jack.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <mach/audmux.h>
+
+#include "imx-ssi.h"
+#include "../codecs/wm8350.h"
+
+/* There is a silicon mic on the board optionally connected via a solder pad
+ * SP1.  Define this to enable it.
+ */
+#undef USE_SIMIC
+
+struct _wm8350_audio {
+       unsigned int channels;
+       snd_pcm_format_t format;
+       unsigned int rate;
+       unsigned int sysclk;
+       unsigned int bclkdiv;
+       unsigned int clkdiv;
+       unsigned int lr_rate;
+};
+
+/* in order of power consumption per rate (lowest first) */
+static const struct _wm8350_audio wm8350_audio[] = {
+       /* 16bit mono modes */
+       {1, SNDRV_PCM_FORMAT_S16_LE, 8000, 12288000 >> 1,
+        WM8350_BCLK_DIV_48, WM8350_DACDIV_3, 16,},
+
+       /* 16 bit stereo modes */
+       {2, SNDRV_PCM_FORMAT_S16_LE, 8000, 12288000,
+        WM8350_BCLK_DIV_48, WM8350_DACDIV_6, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 16000, 12288000,
+        WM8350_BCLK_DIV_24, WM8350_DACDIV_3, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 32000, 12288000,
+        WM8350_BCLK_DIV_12, WM8350_DACDIV_1_5, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 48000, 12288000,
+        WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 96000, 24576000,
+        WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 11025, 11289600,
+        WM8350_BCLK_DIV_32, WM8350_DACDIV_4, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 22050, 11289600,
+        WM8350_BCLK_DIV_16, WM8350_DACDIV_2, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 44100, 11289600,
+        WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,},
+       {2, SNDRV_PCM_FORMAT_S16_LE, 88200, 22579200,
+        WM8350_BCLK_DIV_8, WM8350_DACDIV_1, 32,},
+
+       /* 24bit stereo modes */
+       {2, SNDRV_PCM_FORMAT_S24_LE, 48000, 12288000,
+        WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,},
+       {2, SNDRV_PCM_FORMAT_S24_LE, 96000, 24576000,
+        WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,},
+       {2, SNDRV_PCM_FORMAT_S24_LE, 44100, 11289600,
+        WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,},
+       {2, SNDRV_PCM_FORMAT_S24_LE, 88200, 22579200,
+        WM8350_BCLK_DIV_4, WM8350_DACDIV_1, 64,},
+};
+
+static int wm1133_ev1_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       int i, found = 0;
+       snd_pcm_format_t format = params_format(params);
+       unsigned int rate = params_rate(params);
+       unsigned int channels = params_channels(params);
+       u32 dai_format;
+
+       /* find the correct audio parameters */
+       for (i = 0; i < ARRAY_SIZE(wm8350_audio); i++) {
+               if (rate == wm8350_audio[i].rate &&
+                   format == wm8350_audio[i].format &&
+                   channels == wm8350_audio[i].channels) {
+                       found = 1;
+                       break;
+               }
+       }
+       if (!found)
+               return -EINVAL;
+
+       /* codec FLL input is 14.75 MHz from MCLK */
+       snd_soc_dai_set_pll(codec_dai, 0, 0, 14750000, wm8350_audio[i].sysclk);
+
+       dai_format = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
+               SND_SOC_DAIFMT_CBM_CFM;
+
+       /* set codec DAI configuration */
+       snd_soc_dai_set_fmt(codec_dai, dai_format);
+
+       /* set cpu DAI configuration */
+       snd_soc_dai_set_fmt(cpu_dai, dai_format);
+
+       /* TODO: The SSI driver should figure this out for us */
+       switch (channels) {
+       case 2:
+               snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
+               break;
+       case 1:
+               snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffe, 0xffffffe, 1, 0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* set MCLK as the codec system clock for DAC and ADC */
+       snd_soc_dai_set_sysclk(codec_dai, WM8350_MCLK_SEL_PLL_MCLK,
+                              wm8350_audio[i].sysclk, SND_SOC_CLOCK_IN);
+
+       /* set codec BCLK division for sample rate */
+       snd_soc_dai_set_clkdiv(codec_dai, WM8350_BCLK_CLKDIV,
+                              wm8350_audio[i].bclkdiv);
+
+       /* DAI is synchronous and clocked with DAC LRCLK & ADC LRC */
+       snd_soc_dai_set_clkdiv(codec_dai,
+                              WM8350_DACLR_CLKDIV, wm8350_audio[i].lr_rate);
+       snd_soc_dai_set_clkdiv(codec_dai,
+                              WM8350_ADCLR_CLKDIV, wm8350_audio[i].lr_rate);
+
+       /* now configure DAC and ADC clocks */
+       snd_soc_dai_set_clkdiv(codec_dai,
+                              WM8350_DAC_CLKDIV, wm8350_audio[i].clkdiv);
+
+       snd_soc_dai_set_clkdiv(codec_dai,
+                              WM8350_ADC_CLKDIV, wm8350_audio[i].clkdiv);
+
+       return 0;
+}
+
+static struct snd_soc_ops wm1133_ev1_ops = {
+       .hw_params = wm1133_ev1_hw_params,
+};
+
+static const struct snd_soc_dapm_widget wm1133_ev1_widgets[] = {
+#ifdef USE_SIMIC
+       SND_SOC_DAPM_MIC("SiMIC", NULL),
+#endif
+       SND_SOC_DAPM_MIC("Mic1 Jack", NULL),
+       SND_SOC_DAPM_MIC("Mic2 Jack", NULL),
+       SND_SOC_DAPM_LINE("Line In Jack", NULL),
+       SND_SOC_DAPM_LINE("Line Out Jack", NULL),
+       SND_SOC_DAPM_HP("Headphone Jack", NULL),
+};
+
+/* imx32ads soc_card audio map */
+static const struct snd_soc_dapm_route wm1133_ev1_map[] = {
+
+#ifdef USE_SIMIC
+       /* SiMIC --> IN1LN (with automatic bias) via SP1 */
+       { "IN1LN", NULL, "Mic Bias" },
+       { "Mic Bias", NULL, "SiMIC" },
+#endif
+
+       /* Mic 1 Jack --> IN1LN and IN1LP (with automatic bias) */
+       { "IN1LN", NULL, "Mic Bias" },
+       { "IN1LP", NULL, "Mic1 Jack" },
+       { "Mic Bias", NULL, "Mic1 Jack" },
+
+       /* Mic 2 Jack --> IN1RN and IN1RP (with automatic bias) */
+       { "IN1RN", NULL, "Mic Bias" },
+       { "IN1RP", NULL, "Mic2 Jack" },
+       { "Mic Bias", NULL, "Mic2 Jack" },
+
+       /* Line in Jack --> AUX (L+R) */
+       { "IN3R", NULL, "Line In Jack" },
+       { "IN3L", NULL, "Line In Jack" },
+
+       /* Out1 --> Headphone Jack */
+       { "Headphone Jack", NULL, "OUT1R" },
+       { "Headphone Jack", NULL, "OUT1L" },
+
+       /* Out1 --> Line Out Jack */
+       { "Line Out Jack", NULL, "OUT2R" },
+       { "Line Out Jack", NULL, "OUT2L" },
+};
+
+static struct snd_soc_jack hp_jack;
+
+static struct snd_soc_jack_pin hp_jack_pins[] = {
+       { .pin = "Headphone Jack", .mask = SND_JACK_HEADPHONE },
+};
+
+static struct snd_soc_jack mic_jack;
+
+static struct snd_soc_jack_pin mic_jack_pins[] = {
+       { .pin = "Mic1 Jack", .mask = SND_JACK_MICROPHONE },
+       { .pin = "Mic2 Jack", .mask = SND_JACK_MICROPHONE },
+};
+
+static int wm1133_ev1_init(struct snd_soc_codec *codec)
+{
+       struct snd_soc_card *card = codec->socdev->card;
+
+       snd_soc_dapm_new_controls(codec, wm1133_ev1_widgets,
+                                 ARRAY_SIZE(wm1133_ev1_widgets));
+
+       snd_soc_dapm_add_routes(codec, wm1133_ev1_map,
+                               ARRAY_SIZE(wm1133_ev1_map));
+
+       /* Headphone jack detection */
+       snd_soc_jack_new(card, "Headphone", SND_JACK_HEADPHONE, &hp_jack);
+       snd_soc_jack_add_pins(&hp_jack, ARRAY_SIZE(hp_jack_pins),
+                             hp_jack_pins);
+       wm8350_hp_jack_detect(codec, WM8350_JDR, &hp_jack, SND_JACK_HEADPHONE);
+
+       /* Microphone jack detection */
+       snd_soc_jack_new(card, "Microphone",
+                        SND_JACK_MICROPHONE | SND_JACK_BTN_0, &mic_jack);
+       snd_soc_jack_add_pins(&mic_jack, ARRAY_SIZE(mic_jack_pins),
+                             mic_jack_pins);
+       wm8350_mic_jack_detect(codec, &mic_jack, SND_JACK_MICROPHONE,
+                              SND_JACK_BTN_0);
+
+       snd_soc_dapm_force_enable_pin(codec, "Mic Bias");
+
+       return 0;
+}
+
+
+static struct snd_soc_dai_link wm1133_ev1_dai = {
+       .name = "WM1133-EV1",
+       .stream_name = "Audio",
+       .cpu_dai = &imx_ssi_pcm_dai[0],
+       .codec_dai = &wm8350_dai,
+       .init = wm1133_ev1_init,
+       .ops = &wm1133_ev1_ops,
+       .symmetric_rates = 1,
+};
+
+static struct snd_soc_card wm1133_ev1 = {
+       .name = "WM1133-EV1",
+       .platform = &imx_soc_platform,
+       .dai_link = &wm1133_ev1_dai,
+       .num_links = 1,
+};
+
+static struct snd_soc_device wm1133_ev1_snd_devdata = {
+       .card = &wm1133_ev1,
+       .codec_dev = &soc_codec_dev_wm8350,
+};
+
+static struct platform_device *wm1133_ev1_snd_device;
+
+static int __init wm1133_ev1_audio_init(void)
+{
+       int ret;
+       unsigned int ptcr, pdcr;
+
+       /* SSI0 mastered by port 5 */
+       ptcr = MXC_AUDMUX_V2_PTCR_SYN |
+               MXC_AUDMUX_V2_PTCR_TFSDIR |
+               MXC_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT5_SSI_PINS_5) |
+               MXC_AUDMUX_V2_PTCR_TCLKDIR |
+               MXC_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT5_SSI_PINS_5);
+       pdcr = MXC_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT5_SSI_PINS_5);
+       mxc_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0, ptcr, pdcr);
+
+       ptcr = MXC_AUDMUX_V2_PTCR_SYN;
+       pdcr = MXC_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0);
+       mxc_audmux_v2_configure_port(MX31_AUDMUX_PORT5_SSI_PINS_5, ptcr, pdcr);
+
+       wm1133_ev1_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!wm1133_ev1_snd_device)
+               return -ENOMEM;
+
+       platform_set_drvdata(wm1133_ev1_snd_device, &wm1133_ev1_snd_devdata);
+       wm1133_ev1_snd_devdata.dev = &wm1133_ev1_snd_device->dev;
+       ret = platform_device_add(wm1133_ev1_snd_device);
+
+       if (ret)
+               platform_device_put(wm1133_ev1_snd_device);
+
+       return ret;
+}
+module_init(wm1133_ev1_audio_init);
+
+static void __exit wm1133_ev1_audio_exit(void)
+{
+       platform_device_unregister(wm1133_ev1_snd_device);
+}
+module_exit(wm1133_ev1_audio_exit);
+
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
+MODULE_DESCRIPTION("Audio for WM1133-EV1 on i.MX31ADS");
+MODULE_LICENSE("GPL");
index f11963c..d542ea2 100644 (file)
@@ -18,6 +18,16 @@ config SND_OMAP_SOC_N810
        help
          Say Y if you want to add support for SoC audio on Nokia N810.
 
+config SND_OMAP_SOC_RX51
+       tristate "SoC Audio support for Nokia RX-51"
+       depends on SND_OMAP_SOC && MACH_NOKIA_RX51
+       select OMAP_MCBSP
+       select SND_OMAP_SOC_MCBSP
+       select SND_SOC_TLV320AIC3X
+       help
+         Say Y if you want to add support for SoC audio on Nokia RX-51
+         hardware. This is also known as Nokia N900 product.
+
 config SND_OMAP_SOC_AMS_DELTA
        tristate "SoC Audio support for Amstrad E3 (Delta) videophone"
        depends on SND_OMAP_SOC && MACH_AMS_DELTA
@@ -88,6 +98,15 @@ config SND_OMAP_SOC_SDP3430
          Say Y if you want to add support for SoC audio on Texas Instruments
          SDP3430.
 
+config SND_OMAP_SOC_SDP4430
+       tristate "SoC Audio support for Texas Instruments SDP4430"
+       depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP_4430SDP
+       select SND_OMAP_SOC_MCPDM
+       select SND_SOC_TWL6040
+       help
+         Say Y if you want to add support for SoC audio on Texas Instruments
+         SDP4430.
+
 config SND_OMAP_SOC_OMAP3_PANDORA
        tristate "SoC Audio support for OMAP3 Pandora"
        depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP3_PANDORA
index 0bc00ca..ba9fc65 100644 (file)
@@ -9,6 +9,7 @@ obj-$(CONFIG_SND_OMAP_SOC_MCPDM) += snd-soc-omap-mcpdm.o
 
 # OMAP Machine Support
 snd-soc-n810-objs := n810.o
+snd-soc-rx51-objs := rx51.o
 snd-soc-ams-delta-objs := ams-delta.o
 snd-soc-osk5912-objs := osk5912.o
 snd-soc-overo-objs := overo.o
@@ -16,12 +17,14 @@ snd-soc-omap2evm-objs := omap2evm.o
 snd-soc-omap3evm-objs := omap3evm.o
 snd-soc-am3517evm-objs := am3517evm.o
 snd-soc-sdp3430-objs := sdp3430.o
+snd-soc-sdp4430-objs := sdp4430.o
 snd-soc-omap3pandora-objs := omap3pandora.o
 snd-soc-omap3beagle-objs := omap3beagle.o
 snd-soc-zoom2-objs := zoom2.o
 snd-soc-igep0020-objs := igep0020.o
 
 obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
+obj-$(CONFIG_SND_OMAP_SOC_RX51) += snd-soc-rx51.o
 obj-$(CONFIG_SND_OMAP_SOC_AMS_DELTA) += snd-soc-ams-delta.o
 obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o
 obj-$(CONFIG_SND_OMAP_SOC_OVERO) += snd-soc-overo.o
@@ -29,6 +32,7 @@ obj-$(CONFIG_SND_OMAP_SOC_OMAP2EVM) += snd-soc-omap2evm.o
 obj-$(CONFIG_SND_OMAP_SOC_OMAP3EVM) += snd-soc-omap3evm.o
 obj-$(CONFIG_SND_OMAP_SOC_AM3517EVM) += snd-soc-am3517evm.o
 obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o
+obj-$(CONFIG_SND_OMAP_SOC_SDP4430) += snd-soc-sdp4430.o
 obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o
 obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o
 obj-$(CONFIG_SND_OMAP_SOC_ZOOM2) += snd-soc-zoom2.o
index 1dab4c1..90b8bf7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * mcpdm.c  --  McPDM interface driver
+ * mcpdm.c  -- McPDM interface driver
  *
  * Author: Jorge Eduardo Candelaria <x0107209@ti.com>
  * Copyright (C) 2009 - Texas Instruments, Inc.
@@ -39,46 +39,46 @@ static struct omap_mcpdm *mcpdm;
 
 static inline void omap_mcpdm_write(u16 reg, u32 val)
 {
-       __raw_writel(val, mcpdm->io_base + reg);
+       __raw_writel(val, mcpdm->io_base + reg);
 }
 
 static inline int omap_mcpdm_read(u16 reg)
 {
-       return __raw_readl(mcpdm->io_base + reg);
+       return __raw_readl(mcpdm->io_base + reg);
 }
 
 static void omap_mcpdm_reg_dump(void)
 {
-       dev_dbg(mcpdm->dev, "***********************\n");
-       dev_dbg(mcpdm->dev, "IRQSTATUS_RAW:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQSTATUS_RAW));
-       dev_dbg(mcpdm->dev, "IRQSTATUS:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQSTATUS));
-       dev_dbg(mcpdm->dev, "IRQENABLE_SET:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQENABLE_SET));
-       dev_dbg(mcpdm->dev, "IRQENABLE_CLR:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQENABLE_CLR));
-       dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_IRQWAKE_EN));
-       dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAENABLE_SET));
-       dev_dbg(mcpdm->dev, "DMAENABLE_CLR:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAENABLE_CLR));
-       dev_dbg(mcpdm->dev, "DMAWAKEEN:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DMAWAKEEN));
-       dev_dbg(mcpdm->dev, "CTRL:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_CTRL));
-       dev_dbg(mcpdm->dev, "DN_DATA:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DN_DATA));
-       dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_UP_DATA));
-       dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
-                       omap_mcpdm_read(MCPDM_FIFO_CTRL_DN));
-       dev_dbg(mcpdm->dev, "FIFO_CTRL_UP:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_FIFO_CTRL_UP));
-       dev_dbg(mcpdm->dev, "DN_OFFSET:  0x%04x\n",
-                       omap_mcpdm_read(MCPDM_DN_OFFSET));
-       dev_dbg(mcpdm->dev, "***********************\n");
+       dev_dbg(mcpdm->dev, "***********************\n");
+       dev_dbg(mcpdm->dev, "IRQSTATUS_RAW:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_IRQSTATUS_RAW));
+       dev_dbg(mcpdm->dev, "IRQSTATUS: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_IRQSTATUS));
+       dev_dbg(mcpdm->dev, "IRQENABLE_SET:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_IRQENABLE_SET));
+       dev_dbg(mcpdm->dev, "IRQENABLE_CLR:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_IRQENABLE_CLR));
+       dev_dbg(mcpdm->dev, "IRQWAKE_EN: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_IRQWAKE_EN));
+       dev_dbg(mcpdm->dev, "DMAENABLE_SET: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_DMAENABLE_SET));
+       dev_dbg(mcpdm->dev, "DMAENABLE_CLR:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_DMAENABLE_CLR));
+       dev_dbg(mcpdm->dev, "DMAWAKEEN: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_DMAWAKEEN));
+       dev_dbg(mcpdm->dev, "CTRL:      0x%04x\n",
+                       omap_mcpdm_read(MCPDM_CTRL));
+       dev_dbg(mcpdm->dev, "DN_DATA:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_DN_DATA));
+       dev_dbg(mcpdm->dev, "UP_DATA: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_UP_DATA));
+       dev_dbg(mcpdm->dev, "FIFO_CTRL_DN: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_FIFO_CTRL_DN));
+       dev_dbg(mcpdm->dev, "FIFO_CTRL_UP:  0x%04x\n",
+                       omap_mcpdm_read(MCPDM_FIFO_CTRL_UP));
+       dev_dbg(mcpdm->dev, "DN_OFFSET: 0x%04x\n",
+                       omap_mcpdm_read(MCPDM_DN_OFFSET));
+       dev_dbg(mcpdm->dev, "***********************\n");
 }
 
 /*
@@ -87,26 +87,26 @@ static void omap_mcpdm_reg_dump(void)
  */
 static void omap_mcpdm_reset_capture(int reset)
 {
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
 
-       if (reset)
-               ctrl |= SW_UP_RST;
-       else
-               ctrl &= ~SW_UP_RST;
+       if (reset)
+               ctrl |= SW_UP_RST;
+       else
+               ctrl &= ~SW_UP_RST;
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 }
 
 static void omap_mcpdm_reset_playback(int reset)
 {
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
 
-       if (reset)
-               ctrl |= SW_DN_RST;
-       else
-               ctrl &= ~SW_DN_RST;
+       if (reset)
+               ctrl |= SW_DN_RST;
+       else
+               ctrl &= ~SW_DN_RST;
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 }
 
 /*
@@ -115,14 +115,14 @@ static void omap_mcpdm_reset_playback(int reset)
  */
 void omap_mcpdm_start(int stream)
 {
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
 
-       if (stream)
-               ctrl |= mcpdm->up_channels;
-       else
-               ctrl |= mcpdm->dn_channels;
+       if (stream)
+               ctrl |= mcpdm->up_channels;
+       else
+               ctrl |= mcpdm->dn_channels;
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 }
 
 /*
@@ -131,14 +131,14 @@ void omap_mcpdm_start(int stream)
  */
 void omap_mcpdm_stop(int stream)
 {
-       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       int ctrl = omap_mcpdm_read(MCPDM_CTRL);
 
-       if (stream)
-               ctrl &= ~mcpdm->up_channels;
-       else
-               ctrl &= ~mcpdm->dn_channels;
+       if (stream)
+               ctrl &= ~mcpdm->up_channels;
+       else
+               ctrl &= ~mcpdm->dn_channels;
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 }
 
 /*
@@ -147,38 +147,38 @@ void omap_mcpdm_stop(int stream)
  */
 int omap_mcpdm_capture_open(struct omap_mcpdm_link *uplink)
 {
-       int irq_mask = 0;
-       int ctrl;
+       int irq_mask = 0;
+       int ctrl;
 
-       if (!uplink)
-               return -EINVAL;
+       if (!uplink)
+               return -EINVAL;
 
-       mcpdm->uplink = uplink;
+       mcpdm->uplink = uplink;
 
-       /* Enable irq request generation */
-       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
+       /* Enable irq request generation */
+       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
+       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
 
-       /* Configure uplink threshold */
-       if (uplink->threshold > UP_THRES_MAX)
-               uplink->threshold = UP_THRES_MAX;
+       /* Configure uplink threshold */
+       if (uplink->threshold > UP_THRES_MAX)
+               uplink->threshold = UP_THRES_MAX;
 
-       omap_mcpdm_write(MCPDM_FIFO_CTRL_UP, uplink->threshold);
+       omap_mcpdm_write(MCPDM_FIFO_CTRL_UP, uplink->threshold);
 
-       /* Configure DMA controller */
-       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_UP_ENABLE);
+       /* Configure DMA controller */
+       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_UP_ENABLE);
 
-       /* Set pdm out format */
-       ctrl = omap_mcpdm_read(MCPDM_CTRL);
-       ctrl &= ~PDMOUTFORMAT;
-       ctrl |= uplink->format & PDMOUTFORMAT;
+       /* Set pdm out format */
+       ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       ctrl &= ~PDMOUTFORMAT;
+       ctrl |= uplink->format & PDMOUTFORMAT;
 
-       /* Uplink channels */
-       mcpdm->up_channels = uplink->channels & (PDM_UP_MASK | PDM_STATUS_MASK);
+       /* Uplink channels */
+       mcpdm->up_channels = uplink->channels & (PDM_UP_MASK | PDM_STATUS_MASK);
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 
-       return 0;
+       return 0;
 }
 
 /*
@@ -187,38 +187,38 @@ int omap_mcpdm_capture_open(struct omap_mcpdm_link *uplink)
  */
 int omap_mcpdm_playback_open(struct omap_mcpdm_link *downlink)
 {
-       int irq_mask = 0;
-       int ctrl;
+       int irq_mask = 0;
+       int ctrl;
 
-       if (!downlink)
-               return -EINVAL;
+       if (!downlink)
+               return -EINVAL;
 
-       mcpdm->downlink = downlink;
+       mcpdm->downlink = downlink;
 
-       /* Enable irq request generation */
-       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
+       /* Enable irq request generation */
+       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
+       omap_mcpdm_write(MCPDM_IRQENABLE_SET, irq_mask);
 
-       /* Configure uplink threshold */
-       if (downlink->threshold > DN_THRES_MAX)
-               downlink->threshold = DN_THRES_MAX;
+       /* Configure uplink threshold */
+       if (downlink->threshold > DN_THRES_MAX)
+               downlink->threshold = DN_THRES_MAX;
 
-       omap_mcpdm_write(MCPDM_FIFO_CTRL_DN, downlink->threshold);
+       omap_mcpdm_write(MCPDM_FIFO_CTRL_DN, downlink->threshold);
 
-       /* Enable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_DN_ENABLE);
+       /* Enable DMA request generation */
+       omap_mcpdm_write(MCPDM_DMAENABLE_SET, DMA_DN_ENABLE);
 
-       /* Set pdm out format */
-       ctrl = omap_mcpdm_read(MCPDM_CTRL);
-       ctrl &= ~PDMOUTFORMAT;
-       ctrl |= downlink->format & PDMOUTFORMAT;
+       /* Set pdm out format */
+       ctrl = omap_mcpdm_read(MCPDM_CTRL);
+       ctrl &= ~PDMOUTFORMAT;
+       ctrl |= downlink->format & PDMOUTFORMAT;
 
-       /* Downlink channels */
-       mcpdm->dn_channels = downlink->channels & (PDM_DN_MASK | PDM_CMD_MASK);
+       /* Downlink channels */
+       mcpdm->dn_channels = downlink->channels & (PDM_DN_MASK | PDM_CMD_MASK);
 
-       omap_mcpdm_write(MCPDM_CTRL, ctrl);
+       omap_mcpdm_write(MCPDM_CTRL, ctrl);
 
-       return 0;
+       return 0;
 }
 
 /*
@@ -227,24 +227,24 @@ int omap_mcpdm_playback_open(struct omap_mcpdm_link *downlink)
  */
 int omap_mcpdm_capture_close(struct omap_mcpdm_link *uplink)
 {
-       int irq_mask = 0;
+       int irq_mask = 0;
 
-       if (!uplink)
-               return -EINVAL;
+       if (!uplink)
+               return -EINVAL;
 
-       /* Disable irq request generation */
-       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
+       /* Disable irq request generation */
+       irq_mask |= uplink->irq_mask & MCPDM_UPLINK_IRQ_MASK;
+       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
 
-       /* Disable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_UP_ENABLE);
+       /* Disable DMA request generation */
+       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_UP_ENABLE);
 
-       /* Clear Downlink channels */
-       mcpdm->up_channels = 0;
+       /* Clear Downlink channels */
+       mcpdm->up_channels = 0;
 
-       mcpdm->uplink = NULL;
+       mcpdm->uplink = NULL;
 
-       return 0;
+       return 0;
 }
 
 /*
@@ -253,124 +253,124 @@ int omap_mcpdm_capture_close(struct omap_mcpdm_link *uplink)
  */
 int omap_mcpdm_playback_close(struct omap_mcpdm_link *downlink)
 {
-       int irq_mask = 0;
+       int irq_mask = 0;
 
-       if (!downlink)
-               return -EINVAL;
+       if (!downlink)
+               return -EINVAL;
 
-       /* Disable irq request generation */
-       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
-       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
+       /* Disable irq request generation */
+       irq_mask |= downlink->irq_mask & MCPDM_DOWNLINK_IRQ_MASK;
+       omap_mcpdm_write(MCPDM_IRQENABLE_CLR, irq_mask);
 
-       /* Disable DMA request generation */
-       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_DN_ENABLE);
+       /* Disable DMA request generation */
+       omap_mcpdm_write(MCPDM_DMAENABLE_CLR, DMA_DN_ENABLE);
 
-       /* clear Downlink channels */
-       mcpdm->dn_channels = 0;
+       /* clear Downlink channels */
+       mcpdm->dn_channels = 0;
 
-       mcpdm->downlink = NULL;
+       mcpdm->downlink = NULL;
 
-       return 0;
+       return 0;
 }
 
 static irqreturn_t omap_mcpdm_irq_handler(int irq, void *dev_id)
 {
-       struct omap_mcpdm *mcpdm_irq = dev_id;
-       int irq_status;
-
-       irq_status = omap_mcpdm_read(MCPDM_IRQSTATUS);
-
-       /* Acknowledge irq event */
-       omap_mcpdm_write(MCPDM_IRQSTATUS, irq_status);
-
-       if (irq & MCPDM_DN_IRQ_FULL) {
-               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_playback(1);
-               omap_mcpdm_playback_open(mcpdm_irq->downlink);
-               omap_mcpdm_reset_playback(0);
-       }
-
-       if (irq & MCPDM_DN_IRQ_EMPTY) {
-               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_playback(1);
-               omap_mcpdm_playback_open(mcpdm_irq->downlink);
-               omap_mcpdm_reset_playback(0);
-       }
-
-       if (irq & MCPDM_DN_IRQ) {
-               dev_dbg(mcpdm_irq->dev, "DN write request\n");
-       }
-
-       if (irq & MCPDM_UP_IRQ_FULL) {
-               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_capture(1);
-               omap_mcpdm_capture_open(mcpdm_irq->uplink);
-               omap_mcpdm_reset_capture(0);
-       }
-
-       if (irq & MCPDM_UP_IRQ_EMPTY) {
-               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
-               omap_mcpdm_reset_capture(1);
-               omap_mcpdm_capture_open(mcpdm_irq->uplink);
-               omap_mcpdm_reset_capture(0);
-       }
-
-       if (irq & MCPDM_UP_IRQ) {
-               dev_dbg(mcpdm_irq->dev, "UP write request\n");
-       }
-
-       return IRQ_HANDLED;
+       struct omap_mcpdm *mcpdm_irq = dev_id;
+       int irq_status;
+
+       irq_status = omap_mcpdm_read(MCPDM_IRQSTATUS);
+
+       /* Acknowledge irq event */
+       omap_mcpdm_write(MCPDM_IRQSTATUS, irq_status);
+
+       if (irq & MCPDM_DN_IRQ_FULL) {
+               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
+               omap_mcpdm_reset_playback(1);
+               omap_mcpdm_playback_open(mcpdm_irq->downlink);
+               omap_mcpdm_reset_playback(0);
+       }
+
+       if (irq & MCPDM_DN_IRQ_EMPTY) {
+               dev_err(mcpdm_irq->dev, "DN FIFO error %x\n", irq_status);
+               omap_mcpdm_reset_playback(1);
+               omap_mcpdm_playback_open(mcpdm_irq->downlink);
+               omap_mcpdm_reset_playback(0);
+       }
+
+       if (irq & MCPDM_DN_IRQ) {
+               dev_dbg(mcpdm_irq->dev, "DN write request\n");
+       }
+
+       if (irq & MCPDM_UP_IRQ_FULL) {
+               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
+               omap_mcpdm_reset_capture(1);
+               omap_mcpdm_capture_open(mcpdm_irq->uplink);
+               omap_mcpdm_reset_capture(0);
+       }
+
+       if (irq & MCPDM_UP_IRQ_EMPTY) {
+               dev_err(mcpdm_irq->dev, "UP FIFO error %x\n", irq_status);
+               omap_mcpdm_reset_capture(1);
+               omap_mcpdm_capture_open(mcpdm_irq->uplink);
+               omap_mcpdm_reset_capture(0);
+       }
+
+       if (irq & MCPDM_UP_IRQ) {
+               dev_dbg(mcpdm_irq->dev, "UP write request\n");
+       }
+
+       return IRQ_HANDLED;
 }
 
 int omap_mcpdm_request(void)
 {
-       int ret;
+       int ret;
 
-       clk_enable(mcpdm->clk);
+       clk_enable(mcpdm->clk);
 
-       spin_lock(&mcpdm->lock);
+       spin_lock(&mcpdm->lock);
 
-       if (!mcpdm->free) {
-               dev_err(mcpdm->dev, "McPDM interface is in use\n");
-               spin_unlock(&mcpdm->lock);
-               ret = -EBUSY;
-               goto err;
-       }
-       mcpdm->free = 0;
+       if (!mcpdm->free) {
+               dev_err(mcpdm->dev, "McPDM interface is in use\n");
+               spin_unlock(&mcpdm->lock);
+               ret = -EBUSY;
+               goto err;
+       }
+       mcpdm->free = 0;
 
-       spin_unlock(&mcpdm->lock);
+       spin_unlock(&mcpdm->lock);
 
-       /* Disable lines while request is ongoing */
-       omap_mcpdm_write(MCPDM_CTRL, 0x00);
+       /* Disable lines while request is ongoing */
+       omap_mcpdm_write(MCPDM_CTRL, 0x00);
 
-       ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler,
-                               0, "McPDM", (void *)mcpdm);
-       if (ret) {
-               dev_err(mcpdm->dev, "Request for McPDM IRQ failed\n");
-               goto err;
-       }
+       ret = request_irq(mcpdm->irq, omap_mcpdm_irq_handler,
+                               0, "McPDM", (void *)mcpdm);
+       if (ret) {
+               dev_err(mcpdm->dev, "Request for McPDM IRQ failed\n");
+               goto err;
+       }
 
-       return 0;
+       return 0;
 
 err:
-       clk_disable(mcpdm->clk);
-       return ret;
+       clk_disable(mcpdm->clk);
+       return ret;
 }
 
 void omap_mcpdm_free(void)
 {
-       spin_lock(&mcpdm->lock);
-       if (mcpdm->free) {
-               dev_err(mcpdm->dev, "McPDM interface is already free\n");
-               spin_unlock(&mcpdm->lock);
-               return;
-       }
-       mcpdm->free = 1;
-       spin_unlock(&mcpdm->lock);
-
-       clk_disable(mcpdm->clk);
-
-       free_irq(mcpdm->irq, (void *)mcpdm);
+       spin_lock(&mcpdm->lock);
+       if (mcpdm->free) {
+               dev_err(mcpdm->dev, "McPDM interface is already free\n");
+               spin_unlock(&mcpdm->lock);
+               return;
+       }
+       mcpdm->free = 1;
+       spin_unlock(&mcpdm->lock);
+
+       clk_disable(mcpdm->clk);
+
+       free_irq(mcpdm->irq, (void *)mcpdm);
 }
 
 /* Enable/disable DC offset cancelation for the analog
@@ -378,108 +378,108 @@ void omap_mcpdm_free(void)
  */
 int omap_mcpdm_set_offset(int offset1, int offset2)
 {
-       int offset;
+       int offset;
 
-       if ((offset1 > DN_OFST_MAX) || (offset2 > DN_OFST_MAX))
-               return -EINVAL;
+       if ((offset1 > DN_OFST_MAX) || (offset2 > DN_OFST_MAX))
+               return -EINVAL;
 
-       offset = (offset1 << DN_OFST_RX1) | (offset2 << DN_OFST_RX2);
+       offset = (offset1 << DN_OFST_RX1) | (offset2 << DN_OFST_RX2);
 
-       /* offset cancellation for channel 1 */
-       if (offset1)
-               offset |= DN_OFST_RX1_EN;
-       else
-               offset &= ~DN_OFST_RX1_EN;
+       /* offset cancellation for channel 1 */
+       if (offset1)
+               offset |= DN_OFST_RX1_EN;
+       else
+               offset &= ~DN_OFST_RX1_EN;
 
-       /* offset cancellation for channel 2 */
-       if (offset2)
-               offset |= DN_OFST_RX2_EN;
-       else
-               offset &= ~DN_OFST_RX2_EN;
+       /* offset cancellation for channel 2 */
+       if (offset2)
+               offset |= DN_OFST_RX2_EN;
+       else
+               offset &= ~DN_OFST_RX2_EN;
 
-       omap_mcpdm_write(MCPDM_DN_OFFSET, offset);
+       omap_mcpdm_write(MCPDM_DN_OFFSET, offset);
 
-       return 0;
+       return 0;
 }
 
 static int __devinit omap_mcpdm_probe(struct platform_device *pdev)
 {
-       struct resource *res;
-       int ret = 0;
-
-       mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL);
-       if (!mcpdm) {
-               ret = -ENOMEM;
-               goto exit;
-       }
-
-       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-       if (res == NULL) {
-               dev_err(&pdev->dev, "no resource\n");
-               goto err_resource;
-       }
-
-       spin_lock_init(&mcpdm->lock);
-       mcpdm->free = 1;
-       mcpdm->io_base = ioremap(res->start, resource_size(res));
-       if (!mcpdm->io_base) {
-               ret = -ENOMEM;
-               goto err_resource;
-       }
-
-       mcpdm->irq = platform_get_irq(pdev, 0);
-
-       mcpdm->clk = clk_get(&pdev->dev, "pdm_ck");
-       if (IS_ERR(mcpdm->clk)) {
-               ret = PTR_ERR(mcpdm->clk);
-               dev_err(&pdev->dev, "unable to get pdm_ck: %d\n", ret);
-               goto err_clk;
-       }
-
-       mcpdm->dev = &pdev->dev;
-       platform_set_drvdata(pdev, mcpdm);
-
-       return 0;
+       struct resource *res;
+       int ret = 0;
+
+       mcpdm = kzalloc(sizeof(struct omap_mcpdm), GFP_KERNEL);
+       if (!mcpdm) {
+               ret = -ENOMEM;
+               goto exit;
+       }
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (res == NULL) {
+               dev_err(&pdev->dev, "no resource\n");
+               goto err_resource;
+       }
+
+       spin_lock_init(&mcpdm->lock);
+       mcpdm->free = 1;
+       mcpdm->io_base = ioremap(res->start, resource_size(res));
+       if (!mcpdm->io_base) {
+               ret = -ENOMEM;
+               goto err_resource;
+       }
+
+       mcpdm->irq = platform_get_irq(pdev, 0);
+
+       mcpdm->clk = clk_get(&pdev->dev, "pdm_ck");
+       if (IS_ERR(mcpdm->clk)) {
+               ret = PTR_ERR(mcpdm->clk);
+               dev_err(&pdev->dev, "unable to get pdm_ck: %d\n", ret);
+               goto err_clk;
+       }
+
+       mcpdm->dev = &pdev->dev;
+       platform_set_drvdata(pdev, mcpdm);
+
+       return 0;
 
 err_clk:
-       iounmap(mcpdm->io_base);
+       iounmap(mcpdm->io_base);
 err_resource:
-       kfree(mcpdm);
+       kfree(mcpdm);
 exit:
-       return ret;
+       return ret;
 }
 
 static int __devexit omap_mcpdm_remove(struct platform_device *pdev)
 {
-       struct omap_mcpdm *mcpdm_ptr = platform_get_drvdata(pdev);
+       struct omap_mcpdm *mcpdm_ptr = platform_get_drvdata(pdev);
 
-       platform_set_drvdata(pdev, NULL);
+       platform_set_drvdata(pdev, NULL);
 
-       clk_put(mcpdm_ptr->clk);
+       clk_put(mcpdm_ptr->clk);
 
-       iounmap(mcpdm_ptr->io_base);
+       iounmap(mcpdm_ptr->io_base);
 
-       mcpdm_ptr->clk = NULL;
-       mcpdm_ptr->free = 0;
-       mcpdm_ptr->dev = NULL;
+       mcpdm_ptr->clk = NULL;
+       mcpdm_ptr->free = 0;
+       mcpdm_ptr->dev = NULL;
 
-       kfree(mcpdm_ptr);
+       kfree(mcpdm_ptr);
 
-       return 0;
+       return 0;
 }
 
 static struct platform_driver omap_mcpdm_driver = {
-       .probe = omap_mcpdm_probe,
-       .remove = __devexit_p(omap_mcpdm_remove),
-       .driver = {
-               .name = "omap-mcpdm",
-       },
+       .probe = omap_mcpdm_probe,
+       .remove = __devexit_p(omap_mcpdm_remove),
+       .driver = {
+               .name = "omap-mcpdm",
+       },
 };
 
 static struct platform_device *omap_mcpdm_device;
 
 static int __init omap_mcpdm_init(void)
 {
-       return platform_driver_register(&omap_mcpdm_driver);
+       return platform_driver_register(&omap_mcpdm_driver);
 }
 arch_initcall(omap_mcpdm_init);
index 8ad9dc9..6f44cb4 100644 (file)
@@ -256,6 +256,31 @@ static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
        return err;
 }
 
+static snd_pcm_sframes_t omap_mcbsp_dai_delay(
+                       struct snd_pcm_substream *substream,
+                       struct snd_soc_dai *dai)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct omap_mcbsp_data *mcbsp_data = to_mcbsp(cpu_dai->private_data);
+       u16 fifo_use;
+       snd_pcm_sframes_t delay;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               fifo_use = omap_mcbsp_get_tx_delay(mcbsp_data->bus_id);
+       else
+               fifo_use = omap_mcbsp_get_rx_delay(mcbsp_data->bus_id);
+
+       /*
+        * Divide the used locations with the channel count to get the
+        * FIFO usage in samples (don't care about partial samples in the
+        * buffer).
+        */
+       delay = fifo_use / substream->runtime->channels;
+
+       return delay;
+}
+
 static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
                                    struct snd_pcm_hw_params *params,
                                    struct snd_soc_dai *dai)
@@ -295,8 +320,18 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
        omap_mcbsp_dai_dma_params[id][substream->stream].dma_req = dma;
        omap_mcbsp_dai_dma_params[id][substream->stream].port_addr = port;
        omap_mcbsp_dai_dma_params[id][substream->stream].sync_mode = sync_mode;
-       omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
-                                                       OMAP_DMA_DATA_TYPE_S16;
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S16_LE:
+               omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
+                        OMAP_DMA_DATA_TYPE_S16;
+               break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               omap_mcbsp_dai_dma_params[id][substream->stream].data_type =
+                        OMAP_DMA_DATA_TYPE_S32;
+               break;
+       default:
+               return -EINVAL;
+       }
 
        snd_soc_dai_set_dma_data(cpu_dai, substream,
                &omap_mcbsp_dai_dma_params[id][substream->stream]);
@@ -308,7 +343,8 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
 
        format = mcbsp_data->fmt & SND_SOC_DAIFMT_FORMAT_MASK;
        wpf = channels = params_channels(params);
-       if (channels == 2 && format == SND_SOC_DAIFMT_I2S) {
+       if (channels == 2 && (format == SND_SOC_DAIFMT_I2S ||
+                             format == SND_SOC_DAIFMT_LEFT_J)) {
                /* Use dual-phase frames */
                regs->rcr2      |= RPHASE;
                regs->xcr2      |= XPHASE;
@@ -330,6 +366,14 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
                regs->xcr2      |= XWDLEN2(OMAP_MCBSP_WORD_16);
                regs->xcr1      |= XWDLEN1(OMAP_MCBSP_WORD_16);
                break;
+       case SNDRV_PCM_FORMAT_S32_LE:
+               /* Set word lengths */
+               wlen = 32;
+               regs->rcr2      |= RWDLEN2(OMAP_MCBSP_WORD_32);
+               regs->rcr1      |= RWDLEN1(OMAP_MCBSP_WORD_32);
+               regs->xcr2      |= XWDLEN2(OMAP_MCBSP_WORD_32);
+               regs->xcr1      |= XWDLEN1(OMAP_MCBSP_WORD_32);
+               break;
        default:
                /* Unsupported PCM format */
                return -EINVAL;
@@ -353,6 +397,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
        /* Set FS period and length in terms of bit clock periods */
        switch (format) {
        case SND_SOC_DAIFMT_I2S:
+       case SND_SOC_DAIFMT_LEFT_J:
                regs->srgr2     |= FPER(framesize - 1);
                regs->srgr1     |= FWID((framesize >> 1) - 1);
                break;
@@ -404,6 +449,14 @@ static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                regs->rcr2      |= RDATDLY(1);
                regs->xcr2      |= XDATDLY(1);
                break;
+       case SND_SOC_DAIFMT_LEFT_J:
+               /* 0-bit data delay */
+               regs->rcr2      |= RDATDLY(0);
+               regs->xcr2      |= XDATDLY(0);
+               regs->spcr1     |= RJUST(2);
+               /* Invert FS polarity configuration */
+               temp_fmt ^= SND_SOC_DAIFMT_NB_IF;
+               break;
        case SND_SOC_DAIFMT_DSP_A:
                /* 1-bit data delay */
                regs->rcr2      |= RDATDLY(1);
@@ -609,6 +662,7 @@ static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
        .startup        = omap_mcbsp_dai_startup,
        .shutdown       = omap_mcbsp_dai_shutdown,
        .trigger        = omap_mcbsp_dai_trigger,
+       .delay          = omap_mcbsp_dai_delay,
        .hw_params      = omap_mcbsp_dai_hw_params,
        .set_fmt        = omap_mcbsp_dai_set_dai_fmt,
        .set_clkdiv     = omap_mcbsp_dai_set_clkdiv,
@@ -623,13 +677,15 @@ static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
                .channels_min = 1,                              \
                .channels_max = 16,                             \
                .rates = OMAP_MCBSP_RATES,                      \
-               .formats = SNDRV_PCM_FMTBIT_S16_LE,             \
+               .formats = SNDRV_PCM_FMTBIT_S16_LE |            \
+                          SNDRV_PCM_FMTBIT_S32_LE,             \
        },                                                      \
        .capture = {                                            \
                .channels_min = 1,                              \
                .channels_max = 16,                             \
                .rates = OMAP_MCBSP_RATES,                      \
-               .formats = SNDRV_PCM_FMTBIT_S16_LE,             \
+               .formats = SNDRV_PCM_FMTBIT_S16_LE |            \
+                          SNDRV_PCM_FMTBIT_S32_LE,             \
        },                                                      \
        .ops = &omap_mcbsp_dai_ops,                             \
        .private_data = &mcbsp_data[(link_id)].bus_id,          \
index de10f76..87ce842 100644 (file)
@@ -188,8 +188,6 @@ static int omap3pandora_out_init(struct snd_soc_codec *codec)
        int ret;
 
        /* All TWL4030 output pins are floating */
-       snd_soc_dapm_nc_pin(codec, "OUTL");
-       snd_soc_dapm_nc_pin(codec, "OUTR");
        snd_soc_dapm_nc_pin(codec, "EARPIECE");
        snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
        snd_soc_dapm_nc_pin(codec, "PREDRIVER");
diff --git a/sound/soc/omap/rx51.c b/sound/soc/omap/rx51.c
new file mode 100644 (file)
index 0000000..47d831e
--- /dev/null
@@ -0,0 +1,294 @@
+/*
+ * rx51.c  --  SoC audio for Nokia RX-51
+ *
+ * Copyright (C) 2008 - 2009 Nokia Corporation
+ *
+ * Contact: Peter Ujfalusi <peter.ujfalusi@nokia.com>
+ *          Eduardo Valentin <eduardo.valentin@nokia.com>
+ *          Jarkko Nikula <jhnikula@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/mach-types.h>
+
+#include "omap-mcbsp.h"
+#include "omap-pcm.h"
+#include "../codecs/tlv320aic3x.h"
+
+/*
+ * REVISIT: TWL4030 GPIO base in RX-51. Now statically defined to 192. This
+ * gpio is reserved in arch/arm/mach-omap2/board-rx51-peripherals.c
+ */
+#define RX51_SPEAKER_AMP_TWL_GPIO      (192 + 7)
+
+static int rx51_spk_func;
+static int rx51_dmic_func;
+
+static void rx51_ext_control(struct snd_soc_codec *codec)
+{
+       if (rx51_spk_func)
+               snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       else
+               snd_soc_dapm_disable_pin(codec, "Ext Spk");
+       if (rx51_dmic_func)
+               snd_soc_dapm_enable_pin(codec, "DMic");
+       else
+               snd_soc_dapm_disable_pin(codec, "DMic");
+
+       snd_soc_dapm_sync(codec);
+}
+
+static int rx51_startup(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_codec *codec = rtd->socdev->card->codec;
+
+       snd_pcm_hw_constraint_minmax(runtime,
+                                    SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
+       rx51_ext_control(codec);
+
+       return 0;
+}
+
+static int rx51_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       int err;
+
+       /* Set codec DAI configuration */
+       err = snd_soc_dai_set_fmt(codec_dai,
+                                 SND_SOC_DAIFMT_DSP_A |
+                                 SND_SOC_DAIFMT_IB_NF |
+                                 SND_SOC_DAIFMT_CBM_CFM);
+       if (err < 0)
+               return err;
+
+       /* Set cpu DAI configuration */
+       err = snd_soc_dai_set_fmt(cpu_dai,
+                                 SND_SOC_DAIFMT_DSP_A |
+                                 SND_SOC_DAIFMT_IB_NF |
+                                 SND_SOC_DAIFMT_CBM_CFM);
+       if (err < 0)
+               return err;
+
+       /* Set the codec system clock for DAC and ADC */
+       return snd_soc_dai_set_sysclk(codec_dai, 0, 19200000,
+                                     SND_SOC_CLOCK_IN);
+}
+
+static struct snd_soc_ops rx51_ops = {
+       .startup = rx51_startup,
+       .hw_params = rx51_hw_params,
+};
+
+static int rx51_get_spk(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.integer.value[0] = rx51_spk_func;
+
+       return 0;
+}
+
+static int rx51_set_spk(struct snd_kcontrol *kcontrol,
+                       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+       if (rx51_spk_func == ucontrol->value.integer.value[0])
+               return 0;
+
+       rx51_spk_func = ucontrol->value.integer.value[0];
+       rx51_ext_control(codec);
+
+       return 1;
+}
+
+static int rx51_spk_event(struct snd_soc_dapm_widget *w,
+                         struct snd_kcontrol *k, int event)
+{
+       if (SND_SOC_DAPM_EVENT_ON(event))
+               gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 1);
+       else
+               gpio_set_value(RX51_SPEAKER_AMP_TWL_GPIO, 0);
+
+       return 0;
+}
+
+static int rx51_get_input(struct snd_kcontrol *kcontrol,
+                         struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.integer.value[0] = rx51_dmic_func;
+
+       return 0;
+}
+
+static int rx51_set_input(struct snd_kcontrol *kcontrol,
+                         struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+
+       if (rx51_dmic_func == ucontrol->value.integer.value[0])
+               return 0;
+
+       rx51_dmic_func = ucontrol->value.integer.value[0];
+       rx51_ext_control(codec);
+
+       return 1;
+}
+
+static const struct snd_soc_dapm_widget aic34_dapm_widgets[] = {
+       SND_SOC_DAPM_SPK("Ext Spk", rx51_spk_event),
+       SND_SOC_DAPM_MIC("DMic", NULL),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       {"Ext Spk", NULL, "HPLOUT"},
+       {"Ext Spk", NULL, "HPROUT"},
+
+       {"DMic Rate 64", NULL, "Mic Bias 2V"},
+       {"Mic Bias 2V", NULL, "DMic"},
+};
+
+static const char *spk_function[] = {"Off", "On"};
+static const char *input_function[] = {"ADC", "Digital Mic"};
+
+static const struct soc_enum rx51_enum[] = {
+       SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
+       SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(input_function), input_function),
+};
+
+static const struct snd_kcontrol_new aic34_rx51_controls[] = {
+       SOC_ENUM_EXT("Speaker Function", rx51_enum[0],
+                    rx51_get_spk, rx51_set_spk),
+       SOC_ENUM_EXT("Input Select",  rx51_enum[1],
+                    rx51_get_input, rx51_set_input),
+};
+
+static int rx51_aic34_init(struct snd_soc_codec *codec)
+{
+       int err;
+
+       /* Set up NC codec pins */
+       snd_soc_dapm_nc_pin(codec, "MIC3L");
+       snd_soc_dapm_nc_pin(codec, "MIC3R");
+       snd_soc_dapm_nc_pin(codec, "LINE1R");
+
+       /* Add RX-51 specific controls */
+       err = snd_soc_add_controls(codec, aic34_rx51_controls,
+                                  ARRAY_SIZE(aic34_rx51_controls));
+       if (err < 0)
+               return err;
+
+       /* Add RX-51 specific widgets */
+       snd_soc_dapm_new_controls(codec, aic34_dapm_widgets,
+                                 ARRAY_SIZE(aic34_dapm_widgets));
+
+       /* Set up RX-51 specific audio path audio_map */
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       snd_soc_dapm_sync(codec);
+
+       return 0;
+}
+
+/* Digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link rx51_dai[] = {
+       {
+               .name = "TLV320AIC34",
+               .stream_name = "AIC34",
+               .cpu_dai = &omap_mcbsp_dai[0],
+               .codec_dai = &aic3x_dai,
+               .init = rx51_aic34_init,
+               .ops = &rx51_ops,
+       },
+};
+
+/* Audio private data */
+static struct aic3x_setup_data rx51_aic34_setup = {
+       .gpio_func[0] = AIC3X_GPIO1_FUNC_DISABLED,
+       .gpio_func[1] = AIC3X_GPIO2_FUNC_DIGITAL_MIC_INPUT,
+};
+
+/* Audio card */
+static struct snd_soc_card rx51_sound_card = {
+       .name = "RX-51",
+       .dai_link = rx51_dai,
+       .num_links = ARRAY_SIZE(rx51_dai),
+       .platform = &omap_soc_platform,
+};
+
+/* Audio subsystem */
+static struct snd_soc_device rx51_snd_devdata = {
+       .card = &rx51_sound_card,
+       .codec_dev = &soc_codec_dev_aic3x,
+       .codec_data = &rx51_aic34_setup,
+};
+
+static struct platform_device *rx51_snd_device;
+
+static int __init rx51_soc_init(void)
+{
+       int err;
+
+       if (!machine_is_nokia_rx51())
+               return -ENODEV;
+
+       rx51_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!rx51_snd_device) {
+               err = -ENOMEM;
+               goto err1;
+       }
+
+       platform_set_drvdata(rx51_snd_device, &rx51_snd_devdata);
+       rx51_snd_devdata.dev = &rx51_snd_device->dev;
+       *(unsigned int *)rx51_dai[0].cpu_dai->private_data = 1; /* McBSP2 */
+
+       err = platform_device_add(rx51_snd_device);
+       if (err)
+               goto err2;
+
+       return 0;
+err2:
+       platform_device_put(rx51_snd_device);
+err1:
+
+       return err;
+}
+
+static void __exit rx51_soc_exit(void)
+{
+       platform_device_unregister(rx51_snd_device);
+}
+
+module_init(rx51_soc_init);
+module_exit(rx51_soc_exit);
+
+MODULE_AUTHOR("Nokia Corporation");
+MODULE_DESCRIPTION("ALSA SoC Nokia RX-51");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/omap/sdp4430.c b/sound/soc/omap/sdp4430.c
new file mode 100644 (file)
index 0000000..4ebbde6
--- /dev/null
@@ -0,0 +1,233 @@
+/*
+ * sdp4430.c  --  SoC audio for TI OMAP4430 SDP
+ *
+ * Author: Misael Lopez Cruz <x0052729@ti.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/platform_device.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include <asm/mach-types.h>
+#include <plat/hardware.h>
+#include <plat/mux.h>
+
+#include "mcpdm.h"
+#include "omap-mcpdm.h"
+#include "omap-pcm.h"
+#include "../codecs/twl6040.h"
+
+static int twl6040_power_mode;
+
+static int sdp4430_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       int clk_id, freq;
+       int ret;
+
+       if (twl6040_power_mode) {
+               clk_id = TWL6040_SYSCLK_SEL_HPPLL;
+               freq = 38400000;
+       } else {
+               clk_id = TWL6040_SYSCLK_SEL_LPPLL;
+               freq = 32768;
+       }
+
+       /* set the codec mclk */
+       ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
+                               SND_SOC_CLOCK_IN);
+       if (ret) {
+               printk(KERN_ERR "can't set codec system clock\n");
+               return ret;
+       }
+}
+
+static struct snd_soc_ops sdp4430_ops = {
+       .hw_params = sdp4430_hw_params,
+};
+
+static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       ucontrol->value.integer.value[0] = twl6040_power_mode;
+       return 0;
+}
+
+static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       if (twl6040_power_mode == ucontrol->value.integer.value[0])
+               return 0;
+
+       twl6040_power_mode = ucontrol->value.integer.value[0];
+
+       return 1;
+}
+
+static const char *power_texts[] = {"Low-Power", "High-Performance"};
+
+static const struct soc_enum sdp4430_enum[] = {
+       SOC_ENUM_SINGLE_EXT(2, power_texts),
+};
+
+static const struct snd_kcontrol_new sdp4430_controls[] = {
+       SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0],
+               sdp4430_get_power_mode, sdp4430_set_power_mode),
+};
+
+/* SDP4430 machine DAPM */
+static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
+       SND_SOC_DAPM_MIC("Ext Mic", NULL),
+       SND_SOC_DAPM_SPK("Ext Spk", NULL),
+       SND_SOC_DAPM_MIC("Headset Mic", NULL),
+       SND_SOC_DAPM_HP("Headset Stereophone", NULL),
+       SND_SOC_DAPM_SPK("Earphone Spk", NULL),
+};
+
+static const struct snd_soc_dapm_route audio_map[] = {
+       /* External Mics: MAINMIC, SUBMIC with bias*/
+       {"MAINMIC", NULL, "Main Mic Bias"},
+       {"SUBMIC", NULL, "Main Mic Bias"},
+       {"Main Mic Bias", NULL, "Ext Mic"},
+
+       /* External Speakers: HFL, HFR */
+       {"Ext Spk", NULL, "HFL"},
+       {"Ext Spk", NULL, "HFR"},
+
+       /* Headset Mic: HSMIC with bias */
+       {"HSMIC", NULL, "Headset Mic Bias"},
+       {"Headset Mic Bias", NULL, "Headset Mic"},
+
+       /* Headset Stereophone (Headphone): HSOL, HSOR */
+       {"Headset Stereophone", NULL, "HSOL"},
+       {"Headset Stereophone", NULL, "HSOR"},
+
+       /* Earphone speaker */
+       {"Earphone Spk", NULL, "EP"},
+};
+
+static int sdp4430_twl6040_init(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       /* Add SDP4430 specific controls */
+       ret = snd_soc_add_controls(codec, sdp4430_controls,
+                               ARRAY_SIZE(sdp4430_controls));
+       if (ret)
+               return ret;
+
+       /* Add SDP4430 specific widgets */
+       ret = snd_soc_dapm_new_controls(codec, sdp4430_twl6040_dapm_widgets,
+                               ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
+       if (ret)
+               return ret;
+
+       /* Set up SDP4430 specific audio path audio_map */
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       /* SDP4430 connected pins */
+       snd_soc_dapm_enable_pin(codec, "Ext Mic");
+       snd_soc_dapm_enable_pin(codec, "Ext Spk");
+       snd_soc_dapm_enable_pin(codec, "Headset Mic");
+       snd_soc_dapm_enable_pin(codec, "Headset Stereophone");
+
+       /* TWL6040 not connected pins */
+       snd_soc_dapm_nc_pin(codec, "AFML");
+       snd_soc_dapm_nc_pin(codec, "AFMR");
+
+       ret = snd_soc_dapm_sync(codec);
+
+       return ret;
+}
+
+/* Digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link sdp4430_dai = {
+       .name = "TWL6040",
+       .stream_name = "TWL6040",
+       .cpu_dai = &omap_mcpdm_dai,
+       .codec_dai = &twl6040_dai,
+       .init = sdp4430_twl6040_init,
+       .ops = &sdp4430_ops,
+};
+
+/* Audio machine driver */
+static struct snd_soc_card snd_soc_sdp4430 = {
+       .name = "SDP4430",
+       .platform = &omap_soc_platform,
+       .dai_link = &sdp4430_dai,
+       .num_links = 1,
+};
+
+/* Audio subsystem */
+static struct snd_soc_device sdp4430_snd_devdata = {
+       .card = &snd_soc_sdp4430,
+       .codec_dev = &soc_codec_dev_twl6040,
+};
+
+static struct platform_device *sdp4430_snd_device;
+
+static int __init sdp4430_soc_init(void)
+{
+       int ret;
+
+       if (!machine_is_omap_4430sdp()) {
+               pr_debug("Not SDP4430!\n");
+               return -ENODEV;
+       }
+       printk(KERN_INFO "SDP4430 SoC init\n");
+
+       sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!sdp4430_snd_device) {
+               printk(KERN_ERR "Platform device allocation failed\n");
+               return -ENOMEM;
+       }
+
+       platform_set_drvdata(sdp4430_snd_device, &sdp4430_snd_devdata);
+       sdp4430_snd_devdata.dev = &sdp4430_snd_device->dev;
+
+       ret = platform_device_add(sdp4430_snd_device);
+       if (ret)
+               goto err;
+
+       /* Codec starts in HP mode */
+       twl6040_power_mode = 1;
+
+       return 0;
+
+err:
+       printk(KERN_ERR "Unable to add platform device\n");
+       platform_device_put(sdp4430_snd_device);
+       return ret;
+}
+module_init(sdp4430_soc_init);
+
+static void __exit sdp4430_soc_exit(void)
+{
+       platform_device_unregister(sdp4430_snd_device);
+}
+module_exit(sdp4430_soc_exit);
+
+MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
+MODULE_DESCRIPTION("ALSA SoC SDP4430");
+MODULE_LICENSE("GPL");
+
index f90a2ac..50a94ee 100644 (file)
@@ -181,9 +181,6 @@ static int zoom2_twl4030_init(struct snd_soc_codec *codec)
        snd_soc_dapm_nc_pin(codec, "CARKITMIC");
        snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
        snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
-
-       snd_soc_dapm_nc_pin(codec, "OUTL");
-       snd_soc_dapm_nc_pin(codec, "OUTR");
        snd_soc_dapm_nc_pin(codec, "EARPIECE");
        snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
        snd_soc_dapm_nc_pin(codec, "PREDRIVER");
index 376e14a..e30c832 100644 (file)
@@ -23,6 +23,7 @@ config SND_PXA2XX_SOC_I2S
 
 config SND_PXA_SOC_SSP
        tristate
+       select PXA_SSP
 
 config SND_PXA2XX_SOC_CORGI
        tristate "SoC Audio support for Sharp Zaurus SL-C7x0"
@@ -42,6 +43,14 @@ config SND_PXA2XX_SOC_SPITZ
          Say Y if you want to add support for SoC audio on Sharp
          Zaurus SL-Cxx00 models (Spitz, Borzoi and Akita).
 
+config SND_PXA2XX_SOC_Z2
+       tristate "SoC Audio support for Zipit Z2"
+       depends on SND_PXA2XX_SOC && MACH_ZIPIT2
+       select SND_PXA2XX_SOC_I2S
+       select SND_SOC_WM8750
+       help
+         Say Y if you want to add support for SoC audio on Zipit Z2.
+
 config SND_PXA2XX_SOC_POODLE
        tristate "SoC Audio support for Poodle"
        depends on SND_PXA2XX_SOC && MACH_POODLE
index f3e08fd..caa03d8 100644 (file)
@@ -22,6 +22,7 @@ snd-soc-palm27x-objs := palm27x.o
 snd-soc-zylonite-objs := zylonite.o
 snd-soc-magician-objs := magician.o
 snd-soc-mioa701-objs := mioa701_wm9713.o
+snd-soc-z2-objs := z2.o
 snd-soc-imote2-objs := imote2.o
 snd-soc-raumfeld-objs := raumfeld.o
 
@@ -36,6 +37,7 @@ obj-$(CONFIG_SND_PXA2XX_SOC_EM_X270) += snd-soc-em-x270.o
 obj-$(CONFIG_SND_PXA2XX_SOC_PALM27X) += snd-soc-palm27x.o
 obj-$(CONFIG_SND_PXA2XX_SOC_MAGICIAN) += snd-soc-magician.o
 obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o
+obj-$(CONFIG_SND_PXA2XX_SOC_Z2) += snd-soc-z2.o
 obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o
 obj-$(CONFIG_SND_PXA2XX_SOC_IMOTE2) += snd-soc-imote2.o
 obj-$(CONFIG_SND_SOC_RAUMFELD) += snd-soc-raumfeld.o
index 544fd95..a1fd23e 100644 (file)
@@ -32,9 +32,8 @@
 
 #include <mach/hardware.h>
 #include <mach/dma.h>
-#include <mach/regs-ssp.h>
 #include <mach/audio.h>
-#include <mach/ssp.h>
+#include <plat/ssp.h>
 
 #include "pxa2xx-pcm.h"
 #include "pxa-ssp.h"
@@ -57,15 +56,15 @@ struct ssp_priv {
 static void dump_registers(struct ssp_device *ssp)
 {
        dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
-                ssp_read_reg(ssp, SSCR0), ssp_read_reg(ssp, SSCR1),
-                ssp_read_reg(ssp, SSTO));
+                pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1),
+                pxa_ssp_read_reg(ssp, SSTO));
 
        dev_dbg(&ssp->pdev->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
-                ssp_read_reg(ssp, SSPSP), ssp_read_reg(ssp, SSSR),
-                ssp_read_reg(ssp, SSACD));
+                pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR),
+                pxa_ssp_read_reg(ssp, SSACD));
 }
 
-static void ssp_enable(struct ssp_device *ssp)
+static void pxa_ssp_enable(struct ssp_device *ssp)
 {
        uint32_t sscr0;
 
@@ -73,7 +72,7 @@ static void ssp_enable(struct ssp_device *ssp)
        __raw_writel(sscr0, ssp->mmio_base + SSCR0);
 }
 
-static void ssp_disable(struct ssp_device *ssp)
+static void pxa_ssp_disable(struct ssp_device *ssp)
 {
        uint32_t sscr0;
 
@@ -87,7 +86,7 @@ struct pxa2xx_pcm_dma_data {
 };
 
 static struct pxa2xx_pcm_dma_params *
-ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
+pxa_ssp_get_dma_params(struct ssp_device *ssp, int width4, int out)
 {
        struct pxa2xx_pcm_dma_data *dma;
 
@@ -119,7 +118,7 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream,
 
        if (!cpu_dai->active) {
                clk_enable(ssp->clk);
-               ssp_disable(ssp);
+               pxa_ssp_disable(ssp);
        }
 
        kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
@@ -137,7 +136,7 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
        struct ssp_device *ssp = priv->ssp;
 
        if (!cpu_dai->active) {
-               ssp_disable(ssp);
+               pxa_ssp_disable(ssp);
                clk_disable(ssp->clk);
        }
 
@@ -160,7 +159,7 @@ static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
        priv->to  = __raw_readl(ssp->mmio_base + SSTO);
        priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
 
-       ssp_disable(ssp);
+       pxa_ssp_disable(ssp);
        clk_disable(ssp->clk);
        return 0;
 }
@@ -180,7 +179,7 @@ static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
        __raw_writel(priv->psp, ssp->mmio_base + SSPSP);
 
        if (cpu_dai->active)
-               ssp_enable(ssp);
+               pxa_ssp_enable(ssp);
        else
                clk_disable(ssp->clk);
 
@@ -196,9 +195,9 @@ static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
  * ssp_set_clkdiv - set SSP clock divider
  * @div: serial clock rate divider
  */
-static void ssp_set_scr(struct ssp_device *ssp, u32 div)
+static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
 {
-       u32 sscr0 = ssp_read_reg(ssp, SSCR0);
+       u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
 
        if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP) {
                sscr0 &= ~0x0000ff00;
@@ -207,15 +206,15 @@ static void ssp_set_scr(struct ssp_device *ssp, u32 div)
                sscr0 &= ~0x000fff00;
                sscr0 |= (div - 1) << 8;     /* 1..4096 */
        }
-       ssp_write_reg(ssp, SSCR0, sscr0);
+       pxa_ssp_write_reg(ssp, SSCR0, sscr0);
 }
 
 /**
- * ssp_get_clkdiv - get SSP clock divider
+ * pxa_ssp_get_clkdiv - get SSP clock divider
  */
-static u32 ssp_get_scr(struct ssp_device *ssp)
+static u32 pxa_ssp_get_scr(struct ssp_device *ssp)
 {
-       u32 sscr0 = ssp_read_reg(ssp, SSCR0);
+       u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
        u32 div;
 
        if (cpu_is_pxa25x() && ssp->type == PXA25x_SSP)
@@ -235,7 +234,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
        struct ssp_device *ssp = priv->ssp;
        int val;
 
-       u32 sscr0 = ssp_read_reg(ssp, SSCR0) &
+       u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
                ~(SSCR0_ECS |  SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
 
        dev_dbg(&ssp->pdev->dev,
@@ -263,7 +262,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
                break;
        case PXA_SSP_CLK_AUDIO:
                priv->sysclk = 0;
-               ssp_set_scr(ssp, 1);
+               pxa_ssp_set_scr(ssp, 1);
                sscr0 |= SSCR0_ACS;
                break;
        default:
@@ -274,8 +273,8 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
         * on PXA2xx.  On PXA3xx it must be enabled when doing so. */
        if (!cpu_is_pxa3xx())
                clk_disable(ssp->clk);
-       val = ssp_read_reg(ssp, SSCR0) | sscr0;
-       ssp_write_reg(ssp, SSCR0, val);
+       val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0;
+       pxa_ssp_write_reg(ssp, SSCR0, val);
        if (!cpu_is_pxa3xx())
                clk_enable(ssp->clk);
 
@@ -294,11 +293,11 @@ static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
 
        switch (div_id) {
        case PXA_SSP_AUDIO_DIV_ACDS:
-               val = (ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
-               ssp_write_reg(ssp, SSACD, val);
+               val = (pxa_ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
+               pxa_ssp_write_reg(ssp, SSACD, val);
                break;
        case PXA_SSP_AUDIO_DIV_SCDB:
-               val = ssp_read_reg(ssp, SSACD);
+               val = pxa_ssp_read_reg(ssp, SSACD);
                val &= ~SSACD_SCDB;
 #if defined(CONFIG_PXA3xx)
                if (cpu_is_pxa3xx())
@@ -321,10 +320,10 @@ static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
                default:
                        return -EINVAL;
                }
-               ssp_write_reg(ssp, SSACD, val);
+               pxa_ssp_write_reg(ssp, SSACD, val);
                break;
        case PXA_SSP_DIV_SCR:
-               ssp_set_scr(ssp, div);
+               pxa_ssp_set_scr(ssp, div);
                break;
        default:
                return -ENODEV;
@@ -341,11 +340,11 @@ static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
 {
        struct ssp_priv *priv = cpu_dai->private_data;
        struct ssp_device *ssp = priv->ssp;
-       u32 ssacd = ssp_read_reg(ssp, SSACD) & ~0x70;
+       u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
 
 #if defined(CONFIG_PXA3xx)
        if (cpu_is_pxa3xx())
-               ssp_write_reg(ssp, SSACDD, 0);
+               pxa_ssp_write_reg(ssp, SSACDD, 0);
 #endif
 
        switch (freq_out) {
@@ -383,7 +382,7 @@ static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
                        val = tmp;
 
                        val = (val << 16) | 64;
-                       ssp_write_reg(ssp, SSACDD, val);
+                       pxa_ssp_write_reg(ssp, SSACDD, val);
 
                        ssacd |= (0x6 << 4);
 
@@ -397,7 +396,7 @@ static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
                return -EINVAL;
        }
 
-       ssp_write_reg(ssp, SSACD, ssacd);
+       pxa_ssp_write_reg(ssp, SSACD, ssacd);
 
        return 0;
 }
@@ -412,7 +411,7 @@ static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
        struct ssp_device *ssp = priv->ssp;
        u32 sscr0;
 
-       sscr0 = ssp_read_reg(ssp, SSCR0);
+       sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
        sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
 
        /* set slot width */
@@ -429,10 +428,10 @@ static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
                sscr0 |= SSCR0_SlotsPerFrm(slots);
 
                /* set active slot mask */
-               ssp_write_reg(ssp, SSTSA, tx_mask);
-               ssp_write_reg(ssp, SSRSA, rx_mask);
+               pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
+               pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
        }
-       ssp_write_reg(ssp, SSCR0, sscr0);
+       pxa_ssp_write_reg(ssp, SSCR0, sscr0);
 
        return 0;
 }
@@ -447,12 +446,12 @@ static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
        struct ssp_device *ssp = priv->ssp;
        u32 sscr1;
 
-       sscr1 = ssp_read_reg(ssp, SSCR1);
+       sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
        if (tristate)
                sscr1 &= ~SSCR1_TTE;
        else
                sscr1 |= SSCR1_TTE;
-       ssp_write_reg(ssp, SSCR1, sscr1);
+       pxa_ssp_write_reg(ssp, SSCR1, sscr1);
 
        return 0;
 }
@@ -476,14 +475,14 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                return 0;
 
        /* we can only change the settings if the port is not in use */
-       if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
+       if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
                dev_err(&ssp->pdev->dev,
                        "can't change hardware dai format: stream is in use");
                return -EINVAL;
        }
 
        /* reset port settings */
-       sscr0 = ssp_read_reg(ssp, SSCR0) &
+       sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
                (SSCR0_ECS |  SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
        sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
        sspsp = 0;
@@ -535,9 +534,9 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
                return -EINVAL;
        }
 
-       ssp_write_reg(ssp, SSCR0, sscr0);
-       ssp_write_reg(ssp, SSCR1, sscr1);
-       ssp_write_reg(ssp, SSPSP, sspsp);
+       pxa_ssp_write_reg(ssp, SSCR0, sscr0);
+       pxa_ssp_write_reg(ssp, SSCR1, sscr1);
+       pxa_ssp_write_reg(ssp, SSPSP, sspsp);
 
        dump_registers(ssp);
 
@@ -566,7 +565,7 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
        u32 sscr0;
        u32 sspsp;
        int width = snd_pcm_format_physical_width(params_format(params));
-       int ttsa = ssp_read_reg(ssp, SSTSA) & 0xf;
+       int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
        struct pxa2xx_pcm_dma_params *dma_data;
 
        dma_data = snd_soc_dai_get_dma_data(dai, substream);
@@ -578,22 +577,22 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
         * to force 16-bit frame width on the wire (for S16_LE), even
         * with two channels. Use 16-bit DMA transfers for this case.
         */
-       dma_data = ssp_get_dma_params(ssp,
+       dma_data = pxa_ssp_get_dma_params(ssp,
                        ((chn == 2) && (ttsa != 1)) || (width == 32),
                        substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
 
        snd_soc_dai_set_dma_data(dai, substream, dma_data);
 
        /* we can only change the settings if the port is not in use */
-       if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
+       if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
                return 0;
 
        /* clear selected SSP bits */
-       sscr0 = ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
-       ssp_write_reg(ssp, SSCR0, sscr0);
+       sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
+       pxa_ssp_write_reg(ssp, SSCR0, sscr0);
 
        /* bit size */
-       sscr0 = ssp_read_reg(ssp, SSCR0);
+       sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
        switch (params_format(params)) {
        case SNDRV_PCM_FORMAT_S16_LE:
 #ifdef CONFIG_PXA3xx
@@ -609,13 +608,13 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
                sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
                break;
        }
-       ssp_write_reg(ssp, SSCR0, sscr0);
+       pxa_ssp_write_reg(ssp, SSCR0, sscr0);
 
        switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
        case SND_SOC_DAIFMT_I2S:
-              sspsp = ssp_read_reg(ssp, SSPSP);
+              sspsp = pxa_ssp_read_reg(ssp, SSPSP);
 
-               if ((ssp_get_scr(ssp) == 4) && (width == 16)) {
+               if ((pxa_ssp_get_scr(ssp) == 4) && (width == 16)) {
                        /* This is a special case where the bitclk is 64fs
                        * and we're not dealing with 2*32 bits of audio
                        * samples.
@@ -649,7 +648,7 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
                        sspsp |= SSPSP_DMYSTRT(1);
                }
 
-               ssp_write_reg(ssp, SSPSP, sspsp);
+               pxa_ssp_write_reg(ssp, SSPSP, sspsp);
                break;
        default:
                break;
@@ -680,45 +679,45 @@ static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_RESUME:
-               ssp_enable(ssp);
+               pxa_ssp_enable(ssp);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               val = ssp_read_reg(ssp, SSCR1);
+               val = pxa_ssp_read_reg(ssp, SSCR1);
                if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                        val |= SSCR1_TSRE;
                else
                        val |= SSCR1_RSRE;
-               ssp_write_reg(ssp, SSCR1, val);
-               val = ssp_read_reg(ssp, SSSR);
-               ssp_write_reg(ssp, SSSR, val);
+               pxa_ssp_write_reg(ssp, SSCR1, val);
+               val = pxa_ssp_read_reg(ssp, SSSR);
+               pxa_ssp_write_reg(ssp, SSSR, val);
                break;
        case SNDRV_PCM_TRIGGER_START:
-               val = ssp_read_reg(ssp, SSCR1);
+               val = pxa_ssp_read_reg(ssp, SSCR1);
                if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                        val |= SSCR1_TSRE;
                else
                        val |= SSCR1_RSRE;
-               ssp_write_reg(ssp, SSCR1, val);
-               ssp_enable(ssp);
+               pxa_ssp_write_reg(ssp, SSCR1, val);
+               pxa_ssp_enable(ssp);
                break;
        case SNDRV_PCM_TRIGGER_STOP:
-               val = ssp_read_reg(ssp, SSCR1);
+               val = pxa_ssp_read_reg(ssp, SSCR1);
                if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                        val &= ~SSCR1_TSRE;
                else
                        val &= ~SSCR1_RSRE;
-               ssp_write_reg(ssp, SSCR1, val);
+               pxa_ssp_write_reg(ssp, SSCR1, val);
                break;
        case SNDRV_PCM_TRIGGER_SUSPEND:
-               ssp_disable(ssp);
+               pxa_ssp_disable(ssp);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               val = ssp_read_reg(ssp, SSCR1);
+               val = pxa_ssp_read_reg(ssp, SSCR1);
                if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                        val &= ~SSCR1_TSRE;
                else
                        val &= ~SSCR1_RSRE;
-               ssp_write_reg(ssp, SSCR1, val);
+               pxa_ssp_write_reg(ssp, SSCR1, val);
                break;
 
        default:
@@ -740,7 +739,7 @@ static int pxa_ssp_probe(struct platform_device *pdev,
        if (!priv)
                return -ENOMEM;
 
-       priv->ssp = ssp_request(dai->id + 1, "SoC audio");
+       priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
        if (priv->ssp == NULL) {
                ret = -ENODEV;
                goto err_priv;
@@ -760,7 +759,7 @@ static void pxa_ssp_remove(struct platform_device *pdev,
                              struct snd_soc_dai *dai)
 {
        struct ssp_priv *priv = dai->private_data;
-       ssp_free(priv->ssp);
+       pxa_ssp_free(priv->ssp);
 }
 
 #define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
index c4cd2ac..1941a35 100644 (file)
@@ -322,19 +322,44 @@ static struct snd_soc_card snd_soc_spitz = {
        .num_links = 1,
 };
 
-/* spitz audio private data */
-static struct wm8750_setup_data spitz_wm8750_setup = {
-       .i2c_bus = 0,
-       .i2c_address = 0x1b,
-};
-
 /* spitz audio subsystem */
 static struct snd_soc_device spitz_snd_devdata = {
        .card = &snd_soc_spitz,
        .codec_dev = &soc_codec_dev_wm8750,
-       .codec_data = &spitz_wm8750_setup,
 };
 
+/*
+ * FIXME: This is a temporary bodge to avoid cross-tree merge issues.
+ * New drivers should register the wm8750 I2C device in the machine
+ * setup code (under arch/arm for ARM systems).
+ */
+static int wm8750_i2c_register(void)
+{
+       struct i2c_board_info info;
+       struct i2c_adapter *adapter;
+       struct i2c_client *client;
+
+       memset(&info, 0, sizeof(struct i2c_board_info));
+       info.addr = 0x1b;
+       strlcpy(info.type, "wm8750", I2C_NAME_SIZE);
+
+       adapter = i2c_get_adapter(0);
+       if (!adapter) {
+               printk(KERN_ERR "can't get i2c adapter 0\n");
+               return -ENODEV;
+       }
+
+       client = i2c_new_device(adapter, &info);
+       i2c_put_adapter(adapter);
+       if (!client) {
+               printk(KERN_ERR "can't add i2c device at 0x%x\n",
+               (unsigned int)info.addr);
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
 static struct platform_device *spitz_snd_device;
 
 static int __init spitz_init(void)
@@ -344,6 +369,10 @@ static int __init spitz_init(void)
        if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita()))
                return -ENODEV;
 
+       ret = wm8750_i2c_setup();
+       if (ret != 0)
+               return ret;
+
        spitz_snd_device = platform_device_alloc("soc-audio", -1);
        if (!spitz_snd_device)
                return -ENOMEM;
diff --git a/sound/soc/pxa/z2.c b/sound/soc/pxa/z2.c
new file mode 100644 (file)
index 0000000..4e4d2fa
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * linux/sound/soc/pxa/z2.c
+ *
+ * SoC Audio driver for Aeronix Zipit Z2
+ *
+ * Copyright (C) 2009 Ken McGuire <kenm@desertweyr.com>
+ * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <sound/jack.h>
+
+#include <asm/mach-types.h>
+#include <mach/hardware.h>
+#include <mach/audio.h>
+#include <mach/z2.h>
+
+#include "../codecs/wm8750.h"
+#include "pxa2xx-pcm.h"
+#include "pxa2xx-i2s.h"
+
+static struct snd_soc_card snd_soc_z2;
+
+static int z2_hw_params(struct snd_pcm_substream *substream,
+       struct snd_pcm_hw_params *params)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       unsigned int clk = 0;
+       int ret = 0;
+
+       switch (params_rate(params)) {
+       case 8000:
+       case 16000:
+       case 48000:
+       case 96000:
+               clk = 12288000;
+               break;
+       case 11025:
+       case 22050:
+       case 44100:
+               clk = 11289600;
+               break;
+       }
+
+       /* set codec DAI configuration */
+       ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+       if (ret < 0)
+               return ret;
+
+       /* set cpu DAI configuration */
+       ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
+               SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
+       if (ret < 0)
+               return ret;
+
+       /* set the codec system clock for DAC and ADC */
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
+               SND_SOC_CLOCK_IN);
+       if (ret < 0)
+               return ret;
+
+       /* set the I2S system clock as input (unused) */
+       ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, 0,
+               SND_SOC_CLOCK_IN);
+       if (ret < 0)
+               return ret;
+
+       return 0;
+}
+
+static struct snd_soc_jack hs_jack;
+
+/* Headset jack detection DAPM pins */
+static struct snd_soc_jack_pin hs_jack_pins[] = {
+       {
+               .pin    = "Mic Jack",
+               .mask   = SND_JACK_MICROPHONE,
+       },
+       {
+               .pin    = "Headphone Jack",
+               .mask   = SND_JACK_HEADPHONE,
+       },
+};
+
+/* Headset jack detection gpios */
+static struct snd_soc_jack_gpio hs_jack_gpios[] = {
+       {
+               .gpio           = GPIO37_ZIPITZ2_HEADSET_DETECT,
+               .name           = "hsdet-gpio",
+               .report         = SND_JACK_HEADSET,
+               .debounce_time  = 200,
+       },
+};
+
+/* z2 machine dapm widgets */
+static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
+       SND_SOC_DAPM_HP("Headphone Jack", NULL),
+       SND_SOC_DAPM_MIC("Mic Jack", NULL),
+       SND_SOC_DAPM_SPK("Ext Spk", NULL),
+
+       /* headset is a mic and mono headphone */
+       SND_SOC_DAPM_HP("Headset Jack", NULL),
+};
+
+/* Z2 machine audio_map */
+static const struct snd_soc_dapm_route audio_map[] = {
+
+       /* headphone connected to LOUT1, ROUT1 */
+       {"Headphone Jack", NULL, "LOUT1"},
+       {"Headphone Jack", NULL, "ROUT1"},
+
+       /* ext speaker connected to LOUT2, ROUT2  */
+       {"Ext Spk", NULL , "ROUT2"},
+       {"Ext Spk", NULL , "LOUT2"},
+
+       /* mic is connected to R input 2 - with bias */
+       {"RINPUT2", NULL, "Mic Bias"},
+       {"Mic Bias", NULL, "Mic Jack"},
+};
+
+/*
+ * Logic for a wm8750 as connected on a Z2 Device
+ */
+static int z2_wm8750_init(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       /* NC codec pins */
+       snd_soc_dapm_disable_pin(codec, "LINPUT3");
+       snd_soc_dapm_disable_pin(codec, "RINPUT3");
+       snd_soc_dapm_disable_pin(codec, "OUT3");
+       snd_soc_dapm_disable_pin(codec, "MONO");
+
+       /* Add z2 specific widgets */
+       snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
+                                ARRAY_SIZE(wm8750_dapm_widgets));
+
+       /* Set up z2 specific audio paths */
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+
+       ret = snd_soc_dapm_sync(codec);
+       if (ret)
+               goto err;
+
+       /* Jack detection API stuff */
+       ret = snd_soc_jack_new(&snd_soc_z2, "Headset Jack", SND_JACK_HEADSET,
+                               &hs_jack);
+       if (ret)
+               goto err;
+
+       ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
+                               hs_jack_pins);
+       if (ret)
+               goto err;
+
+       ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
+                               hs_jack_gpios);
+       if (ret)
+               goto err;
+
+       return 0;
+
+err:
+       return ret;
+}
+
+static struct snd_soc_ops z2_ops = {
+       .hw_params = z2_hw_params,
+};
+
+/* z2 digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link z2_dai = {
+       .name           = "wm8750",
+       .stream_name    = "WM8750",
+       .cpu_dai        = &pxa_i2s_dai,
+       .codec_dai      = &wm8750_dai,
+       .init           = z2_wm8750_init,
+       .ops            = &z2_ops,
+};
+
+/* z2 audio machine driver */
+static struct snd_soc_card snd_soc_z2 = {
+       .name           = "Z2",
+       .platform       = &pxa2xx_soc_platform,
+       .dai_link       = &z2_dai,
+       .num_links      = 1,
+};
+
+/* z2 audio subsystem */
+static struct snd_soc_device z2_snd_devdata = {
+       .card           = &snd_soc_z2,
+       .codec_dev      = &soc_codec_dev_wm8750,
+};
+
+static struct platform_device *z2_snd_device;
+
+static int __init z2_init(void)
+{
+       int ret;
+
+       if (!machine_is_zipit2())
+               return -ENODEV;
+
+       z2_snd_device = platform_device_alloc("soc-audio", -1);
+       if (!z2_snd_device)
+               return -ENOMEM;
+
+       platform_set_drvdata(z2_snd_device, &z2_snd_devdata);
+       z2_snd_devdata.dev = &z2_snd_device->dev;
+       ret = platform_device_add(z2_snd_device);
+
+       if (ret)
+               platform_device_put(z2_snd_device);
+
+       return ret;
+}
+
+static void __exit z2_exit(void)
+{
+       platform_device_unregister(z2_snd_device);
+}
+
+module_init(z2_init);
+module_exit(z2_exit);
+
+MODULE_AUTHOR("Ken McGuire <kenm@desertweyr.com>, "
+               "Marek Vasut <marek.vasut@gmail.com>");
+MODULE_DESCRIPTION("ALSA SoC ZipitZ2");
+MODULE_LICENSE("GPL");
index 15fe57e..2a7cc22 100644 (file)
@@ -24,6 +24,11 @@ config SND_S3C64XX_SOC_I2S
        select SND_S3C_I2SV2_SOC
        select S3C64XX_DMA
 
+config SND_S3C64XX_SOC_I2S_V4
+       tristate
+       select SND_S3C_I2SV2_SOC
+       select S3C64XX_DMA
+
 config SND_S3C_SOC_PCM
        tristate
 
@@ -59,12 +64,11 @@ config SND_S3C24XX_SOC_JIVE_WM8750
 
 config SND_S3C64XX_SOC_WM8580
        tristate "SoC I2S Audio support for WM8580 on SMDK64XX"
-       depends on SND_S3C24XX_SOC && (MACH_SMDK6400 || MACH_SMDK6410)
-       depends on BROKEN
+       depends on SND_S3C24XX_SOC && MACH_SMDK6410
        select SND_SOC_WM8580
-       select SND_S3C64XX_SOC_I2S
+       select SND_S3C64XX_SOC_I2S_V4
        help
-         Sat Y if you want to add support for SoC audio on the SMDK64XX.
+         Say Y if you want to add support for SoC audio on the SMDK6410.
 
 config SND_S3C24XX_SOC_SMDK2443_WM9710
        tristate "SoC AC97 Audio support for SMDK2443 - WM9710"
index df071a3..81d8dc5 100644 (file)
@@ -4,6 +4,7 @@ snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
 snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
 snd-soc-s3c64xx-i2s-objs := s3c64xx-i2s.o
 snd-soc-s3c-ac97-objs := s3c-ac97.o
+snd-soc-s3c64xx-i2s-v4-objs := s3c64xx-i2s-v4.o
 snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o
 snd-soc-s3c-pcm-objs := s3c-pcm.o
 
@@ -12,6 +13,7 @@ obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o
 obj-$(CONFIG_SND_S3C_SOC_AC97) += snd-soc-s3c-ac97.o
 obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
 obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += snd-soc-s3c64xx-i2s.o
+obj-$(CONFIG_SND_S3C64XX_SOC_I2S_V4) += snd-soc-s3c64xx-i2s-v4.o
 obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
 obj-$(CONFIG_SND_S3C_SOC_PCM) += snd-soc-s3c-pcm.o
 
index 59dc2c6..8c108b1 100644 (file)
@@ -70,7 +70,7 @@ static int jive_hw_params(struct snd_pcm_substream *substream,
        }
 
        s3c_i2sv2_iis_calc_rate(&div, NULL, params_rate(params),
-                               s3c2412_get_iisclk());
+                               s3c_i2sv2_get_clock(cpu_dai));
 
        /* set codec DAI configuration */
        ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
@@ -152,15 +152,10 @@ static struct snd_soc_card snd_soc_machine_jive = {
        .num_links      = 1,
 };
 
-/* jive audio private data */
-static struct wm8750_setup_data jive_wm8750_setup = {
-};
-
 /* jive audio subsystem */
 static struct snd_soc_device jive_snd_devdata = {
        .card           = &snd_soc_machine_jive,
        .codec_dev      = &soc_codec_dev_wm8750,
-       .codec_data     = &jive_wm8750_setup,
 };
 
 static struct platform_device *jive_snd_device;
index dea83d3..209c259 100644 (file)
@@ -362,6 +362,14 @@ static int neo1973_gta02_wm8753_init(struct snd_soc_codec *codec)
        snd_soc_dapm_disable_pin(codec, "Handset Mic");
        snd_soc_dapm_disable_pin(codec, "Handset Spk");
 
+       /* allow audio paths from the GSM modem to run during suspend */
+       snd_soc_dapm_ignore_suspend(codec, "Stereo Out");
+       snd_soc_dapm_ignore_suspend(codec, "GSM Line Out");
+       snd_soc_dapm_ignore_suspend(codec, "GSM Line In");
+       snd_soc_dapm_ignore_suspend(codec, "Headset Mic");
+       snd_soc_dapm_ignore_suspend(codec, "Handset Mic");
+       snd_soc_dapm_ignore_suspend(codec, "Handset Spk");
+
        snd_soc_dapm_sync(codec);
 
        return 0;
similarity index 60%
rename from arch/arm/plat-samsung/include/plat/regs-s3c2412-iis.h
rename to sound/soc/s3c24xx/regs-i2s-v2.h
index abf2fbc..5e5e568 100644 (file)
 #define S3C2412_IISTXD                 (0x10)
 #define S3C2412_IISRXD                 (0x14)
 
+#define S5PC1XX_IISFICS                0x18
+#define S5PC1XX_IISTXDS                0x1C
+
+#define S5PC1XX_IISCON_SW_RST          (1 << 31)
+#define S5PC1XX_IISCON_FRXOFSTATUS     (1 << 26)
+#define S5PC1XX_IISCON_FRXORINTEN      (1 << 25)
+#define S5PC1XX_IISCON_FTXSURSTAT      (1 << 24)
+#define S5PC1XX_IISCON_FTXSURINTEN     (1 << 23)
+#define S5PC1XX_IISCON_TXSDMAPAUSE     (1 << 20)
+#define S5PC1XX_IISCON_TXSDMACTIVE     (1 << 18)
+
+#define S3C64XX_IISCON_FTXURSTATUS     (1 << 17)
+#define S3C64XX_IISCON_FTXURINTEN      (1 << 16)
+#define S3C64XX_IISCON_TXFIFO2_EMPTY   (1 << 15)
+#define S3C64XX_IISCON_TXFIFO1_EMPTY   (1 << 14)
+#define S3C64XX_IISCON_TXFIFO2_FULL    (1 << 13)
+#define S3C64XX_IISCON_TXFIFO1_FULL    (1 << 12)
+
 #define S3C2412_IISCON_LRINDEX         (1 << 11)
 #define S3C2412_IISCON_TXFIFO_EMPTY    (1 << 10)
 #define S3C2412_IISCON_RXFIFO_EMPTY    (1 << 9)
 #define S3C2412_IISCON_RXDMA_ACTIVE    (1 << 1)
 #define S3C2412_IISCON_IIS_ACTIVE      (1 << 0)
 
+#define S5PC1XX_IISMOD_OPCLK_CDCLK_OUT (0 << 30)
+#define S5PC1XX_IISMOD_OPCLK_CDCLK_IN  (1 << 30)
+#define S5PC1XX_IISMOD_OPCLK_BCLK_OUT  (2 << 30)
+#define S5PC1XX_IISMOD_OPCLK_PCLK      (3 << 30)
+#define S5PC1XX_IISMOD_OPCLK_MASK      (3 << 30)
+#define S5PC1XX_IISMOD_TXS_IDMA                (1 << 28) /* Sec_TXFIFO use I-DMA */
+#define S5PC1XX_IISMOD_BLCS_MASK       0x3
+#define S5PC1XX_IISMOD_BLCS_SHIFT      26
+#define S5PC1XX_IISMOD_BLCP_MASK       0x3
+#define S5PC1XX_IISMOD_BLCP_SHIFT      24
+
+#define S3C64XX_IISMOD_C2DD_HHALF      (1 << 21) /* Discard Higher-half */
+#define S3C64XX_IISMOD_C2DD_LHALF      (1 << 20) /* Discard Lower-half */
+#define S3C64XX_IISMOD_C1DD_HHALF      (1 << 19)
+#define S3C64XX_IISMOD_C1DD_LHALF      (1 << 18)
+#define S3C64XX_IISMOD_DC2_EN          (1 << 17)
+#define S3C64XX_IISMOD_DC1_EN          (1 << 16)
 #define S3C64XX_IISMOD_BLC_16BIT       (0 << 13)
 #define S3C64XX_IISMOD_BLC_8BIT                (1 << 13)
 #define S3C64XX_IISMOD_BLC_24BIT       (2 << 13)
 #define S3C64XX_IISMOD_BLC_MASK                (3 << 13)
 
-#define S3C64XX_IISMOD_IMS_PCLK                (0 << 10)
-#define S3C64XX_IISMOD_IMS_SYSMUX      (1 << 10)
-
-#define S3C2412_IISMOD_MASTER_INTERNAL (0 << 10)
-#define S3C2412_IISMOD_MASTER_EXTERNAL (1 << 10)
-#define S3C2412_IISMOD_SLAVE           (2 << 10)
-#define S3C2412_IISMOD_MASTER_MASK     (3 << 10)
+#define S3C2412_IISMOD_IMS_SYSMUX      (1 << 10)
+#define S3C2412_IISMOD_SLAVE           (1 << 11)
 #define S3C2412_IISMOD_MODE_TXONLY     (0 << 8)
 #define S3C2412_IISMOD_MODE_RXONLY     (1 << 8)
 #define S3C2412_IISMOD_MODE_TXRX       (2 << 8)
 
 #define S3C2412_IISPSR_PSREN           (1 << 15)
 
+#define S3C64XX_IISFIC_TX2COUNT(x)     (((x) >>  24) & 0xf)
+#define S3C64XX_IISFIC_TX1COUNT(x)     (((x) >>  16) & 0xf)
+
 #define S3C2412_IISFIC_TXFLUSH         (1 << 15)
 #define S3C2412_IISFIC_RXFLUSH         (1 << 7)
 #define S3C2412_IISFIC_TXCOUNT(x)      (((x) >>  8) & 0xf)
 #define S3C2412_IISFIC_RXCOUNT(x)      (((x) >>  0) & 0xf)
 
-
+#define S5PC1XX_IISFICS_TXFLUSH                (1 << 15)
+#define S5PC1XX_IISFICS_TXCOUNT(x)     (((x) >>  8) & 0x7f)
 
 #endif /* __ASM_ARCH_REGS_S3C2412_IIS_H */
-
index 8851594..13311c8 100644 (file)
  * option) any later version.
  */
 
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/clk.h>
-#include <linux/kernel.h>
 #include <linux/io.h>
 
-#include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
-#include <sound/initval.h>
 #include <sound/soc.h>
 
-#include <plat/regs-s3c2412-iis.h>
-
 #include <mach/dma.h>
 
+#include "regs-i2s-v2.h"
 #include "s3c-i2s-v2.h"
 #include "s3c-dma.h"
 
@@ -272,35 +265,14 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
        iismod = readl(i2s->regs + S3C2412_IISMOD);
        pr_debug("hw_params r: IISMOD: %x \n", iismod);
 
-#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
-#define IISMOD_MASTER_MASK S3C2412_IISMOD_MASTER_MASK
-#define IISMOD_SLAVE S3C2412_IISMOD_SLAVE
-#define IISMOD_MASTER S3C2412_IISMOD_MASTER_INTERNAL
-#endif
-
-#if defined(CONFIG_PLAT_S3C64XX)
-/* From Rev1.1 datasheet, we have two master and two slave modes:
- * IMS[11:10]:
- *     00 = master mode, fed from PCLK
- *     01 = master mode, fed from CLKAUDIO
- *     10 = slave mode, using PCLK
- *     11 = slave mode, using I2SCLK
- */
-#define IISMOD_MASTER_MASK (1 << 11)
-#define IISMOD_SLAVE (1 << 11)
-#define IISMOD_MASTER (0 << 11)
-#endif
-
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
        case SND_SOC_DAIFMT_CBM_CFM:
                i2s->master = 0;
-               iismod &= ~IISMOD_MASTER_MASK;
-               iismod |= IISMOD_SLAVE;
+               iismod |= S3C2412_IISMOD_SLAVE;
                break;
        case SND_SOC_DAIFMT_CBS_CFS:
                i2s->master = 1;
-               iismod &= ~IISMOD_MASTER_MASK;
-               iismod |= IISMOD_MASTER;
+               iismod &= ~S3C2412_IISMOD_SLAVE;
                break;
        default:
                pr_err("unknwon master/slave format\n");
@@ -332,7 +304,7 @@ static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
        return 0;
 }
 
-static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
+static int s3c_i2sv2_hw_params(struct snd_pcm_substream *substream,
                                 struct snd_pcm_hw_params *params,
                                 struct snd_soc_dai *socdai)
 {
@@ -355,37 +327,67 @@ static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
        iismod = readl(i2s->regs + S3C2412_IISMOD);
        pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
 
-#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
+       iismod &= ~S3C64XX_IISMOD_BLC_MASK;
+       /* Sample size */
        switch (params_format(params)) {
        case SNDRV_PCM_FORMAT_S8:
-               iismod |= S3C2412_IISMOD_8BIT;
+               iismod |= S3C64XX_IISMOD_BLC_8BIT;
                break;
        case SNDRV_PCM_FORMAT_S16_LE:
-               iismod &= ~S3C2412_IISMOD_8BIT;
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               iismod |= S3C64XX_IISMOD_BLC_24BIT;
                break;
        }
-#endif
 
-#ifdef CONFIG_PLAT_S3C64XX
-       iismod &= ~(S3C64XX_IISMOD_BLC_MASK | S3C2412_IISMOD_BCLK_MASK);
-       /* Sample size */
-       switch (params_format(params)) {
-       case SNDRV_PCM_FORMAT_S8:
-               /* 8 bit sample, 16fs BCLK */
-               iismod |= (S3C64XX_IISMOD_BLC_8BIT | S3C2412_IISMOD_BCLK_16FS);
+       writel(iismod, i2s->regs + S3C2412_IISMOD);
+       pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
+
+       return 0;
+}
+
+static int s3c_i2sv2_set_sysclk(struct snd_soc_dai *cpu_dai,
+                                 int clk_id, unsigned int freq, int dir)
+{
+       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
+       u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
+
+       pr_debug("Entered %s\n", __func__);
+       pr_debug("%s r: IISMOD: %x\n", __func__, iismod);
+
+       switch (clk_id) {
+       case S3C_I2SV2_CLKSRC_PCLK:
+               iismod &= ~S3C2412_IISMOD_IMS_SYSMUX;
                break;
-       case SNDRV_PCM_FORMAT_S16_LE:
-               /* 16 bit sample, 32fs BCLK */
+
+       case S3C_I2SV2_CLKSRC_AUDIOBUS:
+               iismod |= S3C2412_IISMOD_IMS_SYSMUX;
                break;
-       case SNDRV_PCM_FORMAT_S24_LE:
-               /* 24 bit sample, 48fs BCLK */
-               iismod |= (S3C64XX_IISMOD_BLC_24BIT | S3C2412_IISMOD_BCLK_48FS);
+
+       case S3C_I2SV2_CLKSRC_CDCLK:
+               /* Error if controller doesn't have the CDCLKCON bit */
+               if (!(i2s->feature & S3C_FEATURE_CDCLKCON))
+                       return -EINVAL;
+
+               switch (dir) {
+               case SND_SOC_CLOCK_IN:
+                       iismod |= S3C64XX_IISMOD_CDCLKCON;
+                       break;
+               case SND_SOC_CLOCK_OUT:
+                       iismod &= ~S3C64XX_IISMOD_CDCLKCON;
+                       break;
+               default:
+                       return -EINVAL;
+               }
                break;
+
+       default:
+               return -EINVAL;
        }
-#endif
 
        writel(iismod, i2s->regs + S3C2412_IISMOD);
-       pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
+       pr_debug("%s w: IISMOD: %x\n", __func__, iismod);
+
        return 0;
 }
 
@@ -472,29 +474,25 @@ static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
 
        switch (div_id) {
        case S3C_I2SV2_DIV_BCLK:
-               if (div > 3) {
-                       /* convert value to bit field */
-
-                       switch (div) {
-                       case 16:
-                               div = S3C2412_IISMOD_BCLK_16FS;
-                               break;
+               switch (div) {
+               case 16:
+                       div = S3C2412_IISMOD_BCLK_16FS;
+                       break;
 
-                       case 32:
-                               div = S3C2412_IISMOD_BCLK_32FS;
-                               break;
+               case 32:
+                       div = S3C2412_IISMOD_BCLK_32FS;
+                       break;
 
-                       case 24:
-                               div = S3C2412_IISMOD_BCLK_24FS;
-                               break;
+               case 24:
+                       div = S3C2412_IISMOD_BCLK_24FS;
+                       break;
 
-                       case 48:
-                               div = S3C2412_IISMOD_BCLK_48FS;
-                               break;
+               case 48:
+                       div = S3C2412_IISMOD_BCLK_48FS;
+                       break;
 
-                       default:
-                               return -EINVAL;
-                       }
+               default:
+                       return -EINVAL;
                }
 
                reg = readl(i2s->regs + S3C2412_IISMOD);
@@ -505,29 +503,25 @@ static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
                break;
 
        case S3C_I2SV2_DIV_RCLK:
-               if (div > 3) {
-                       /* convert value to bit field */
-
-                       switch (div) {
-                       case 256:
-                               div = S3C2412_IISMOD_RCLK_256FS;
-                               break;
+               switch (div) {
+               case 256:
+                       div = S3C2412_IISMOD_RCLK_256FS;
+                       break;
 
-                       case 384:
-                               div = S3C2412_IISMOD_RCLK_384FS;
-                               break;
+               case 384:
+                       div = S3C2412_IISMOD_RCLK_384FS;
+                       break;
 
-                       case 512:
-                               div = S3C2412_IISMOD_RCLK_512FS;
-                               break;
+               case 512:
+                       div = S3C2412_IISMOD_RCLK_512FS;
+                       break;
 
-                       case 768:
-                               div = S3C2412_IISMOD_RCLK_768FS;
-                               break;
+               case 768:
+                       div = S3C2412_IISMOD_RCLK_768FS;
+                       break;
 
-                       default:
-                               return -EINVAL;
-                       }
+               default:
+                       return -EINVAL;
                }
 
                reg = readl(i2s->regs + S3C2412_IISMOD);
@@ -553,6 +547,33 @@ static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
        return 0;
 }
 
+static snd_pcm_sframes_t s3c2412_i2s_delay(struct snd_pcm_substream *substream,
+                                          struct snd_soc_dai *dai)
+{
+       struct s3c_i2sv2_info *i2s = to_info(dai);
+       u32 reg = readl(i2s->regs + S3C2412_IISFIC);
+       snd_pcm_sframes_t delay;
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               delay = S3C2412_IISFIC_TXCOUNT(reg);
+       else
+               delay = S3C2412_IISFIC_RXCOUNT(reg);
+
+       return delay;
+}
+
+struct clk *s3c_i2sv2_get_clock(struct snd_soc_dai *cpu_dai)
+{
+       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
+       u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
+
+       if (iismod & S3C2412_IISMOD_IMS_SYSMUX)
+               return i2s->iis_cclk;
+       else
+               return i2s->iis_pclk;
+}
+EXPORT_SYMBOL_GPL(s3c_i2sv2_get_clock);
+
 /* default table of all avaialable root fs divisors */
 static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
 
@@ -735,9 +756,15 @@ int s3c_i2sv2_register_dai(struct snd_soc_dai *dai)
        struct snd_soc_dai_ops *ops = dai->ops;
 
        ops->trigger = s3c2412_i2s_trigger;
-       ops->hw_params = s3c2412_i2s_hw_params;
+       if (!ops->hw_params)
+               ops->hw_params = s3c_i2sv2_hw_params;
        ops->set_fmt = s3c2412_i2s_set_fmt;
        ops->set_clkdiv = s3c2412_i2s_set_clkdiv;
+       ops->set_sysclk = s3c_i2sv2_set_sysclk;
+
+       /* Allow overriding by (for example) IISv4 */
+       if (!ops->delay)
+               ops->delay = s3c2412_i2s_delay;
 
        dai->suspend = s3c2412_i2s_suspend;
        dai->resume = s3c2412_i2s_resume;
index ecf8eaa..766f43a 100644 (file)
 #define S3C_I2SV2_DIV_RCLK     (2)
 #define S3C_I2SV2_DIV_PRESCALER        (3)
 
+#define S3C_I2SV2_CLKSRC_PCLK          0
+#define S3C_I2SV2_CLKSRC_AUDIOBUS      1
+#define S3C_I2SV2_CLKSRC_CDCLK         2
+
+/* Set this flag for I2S controllers that have the bit IISMOD[12]
+ * bridge/break RCLK signal and external Xi2sCDCLK pin.
+ */
+#define S3C_FEATURE_CDCLKCON   (1 << 0)
+
 /**
  * struct s3c_i2sv2_info - S3C I2S-V2 information
  * @dev: The parent device passed to use from the probe.
  * @regs: The pointer to the device registe block.
+ * @feature: Set of bit-flags indicating features of the controller.
  * @master: True if the I2S core is the I2S bit clock master.
  * @dma_playback: DMA information for playback channel.
  * @dma_capture: DMA information for capture channel.
@@ -43,9 +53,10 @@ struct s3c_i2sv2_info {
        struct device   *dev;
        void __iomem    *regs;
 
+       u32             feature;
+
        struct clk      *iis_pclk;
        struct clk      *iis_cclk;
-       struct clk      *iis_clk;
 
        unsigned char    master;
 
@@ -57,6 +68,8 @@ struct s3c_i2sv2_info {
        u32              suspend_iispsr;
 };
 
+extern struct clk *s3c_i2sv2_get_clock(struct snd_soc_dai *cpu_dai);
+
 struct s3c_i2sv2_rate_calc {
        unsigned int    clk_div;        /* for prescaler */
        unsigned int    fs_div;         /* for root frame clock */
index 359e593..709adef 100644 (file)
 #include <sound/soc.h>
 #include <mach/hardware.h>
 
-#include <plat/regs-s3c2412-iis.h>
-
 #include <mach/regs-gpio.h>
 #include <mach/dma.h>
 
 #include "s3c-dma.h"
+#include "regs-i2s-v2.h"
 #include "s3c2412-i2s.h"
 
 #define S3C2412_I2S_DEBUG 0
@@ -66,44 +65,11 @@ static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
 
 static struct s3c_i2sv2_info s3c2412_i2s;
 
-/*
- * Set S3C2412 Clock source
- */
-static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
-                                 int clk_id, unsigned int freq, int dir)
+static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
 {
-       u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
-
-       pr_debug("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id,
-           freq, dir);
-
-       switch (clk_id) {
-       case S3C2412_CLKSRC_PCLK:
-               s3c2412_i2s.master = 1;
-               iismod &= ~S3C2412_IISMOD_MASTER_MASK;
-               iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
-               break;
-       case S3C2412_CLKSRC_I2SCLK:
-               s3c2412_i2s.master = 0;
-               iismod &= ~S3C2412_IISMOD_MASTER_MASK;
-               iismod |= S3C2412_IISMOD_MASTER_EXTERNAL;
-               break;
-       default:
-               return -EINVAL;
-       }
-
-       writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
-       return 0;
+       return cpu_dai->private_data;
 }
 
-
-struct clk *s3c2412_get_iisclk(void)
-{
-       return s3c2412_i2s.iis_clk;
-}
-EXPORT_SYMBOL_GPL(s3c2412_get_iisclk);
-
-
 static int s3c2412_i2s_probe(struct platform_device *pdev,
                             struct snd_soc_dai *dai)
 {
@@ -142,13 +108,48 @@ static int s3c2412_i2s_probe(struct platform_device *pdev,
        return 0;
 }
 
+static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params,
+                                struct snd_soc_dai *cpu_dai)
+{
+       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
+       struct s3c_dma_params *dma_data;
+       u32 iismod;
+
+       pr_debug("Entered %s\n", __func__);
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               dma_data = i2s->dma_playback;
+       else
+               dma_data = i2s->dma_capture;
+
+       snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
+
+       iismod = readl(i2s->regs + S3C2412_IISMOD);
+       pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
+
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S8:
+               iismod |= S3C2412_IISMOD_8BIT;
+               break;
+       case SNDRV_PCM_FORMAT_S16_LE:
+               iismod &= ~S3C2412_IISMOD_8BIT;
+               break;
+       }
+
+       writel(iismod, i2s->regs + S3C2412_IISMOD);
+       pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
+
+       return 0;
+}
+
 #define S3C2412_I2S_RATES \
        (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
        SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
        SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
 
 static struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
-       .set_sysclk     = s3c2412_i2s_set_sysclk,
+       .hw_params      = s3c2412_i2s_hw_params,
 };
 
 struct snd_soc_dai s3c2412_i2s_dai = {
index 92848e5..0b5686b 100644 (file)
 #define S3C2412_DIV_RCLK       S3C_I2SV2_DIV_RCLK
 #define S3C2412_DIV_PRESCALER  S3C_I2SV2_DIV_PRESCALER
 
-#define S3C2412_CLKSRC_PCLK    (0)
-#define S3C2412_CLKSRC_I2SCLK  (1)
-
-extern struct clk *s3c2412_get_iisclk(void);
+#define S3C2412_CLKSRC_PCLK    S3C_I2SV2_CLKSRC_PCLK
+#define S3C2412_CLKSRC_I2SCLK  S3C_I2SV2_CLKSRC_AUDIOBUS
 
 extern struct snd_soc_dai s3c2412_i2s_dai;
 
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s-v4.c b/sound/soc/s3c24xx/s3c64xx-i2s-v4.c
new file mode 100644 (file)
index 0000000..06db130
--- /dev/null
@@ -0,0 +1,209 @@
+/* sound/soc/s3c24xx/s3c64xx-i2s-v4.c
+ *
+ * ALSA SoC Audio Layer - S3C64XX I2Sv4 driver
+ * Copyright (c) 2010 Samsung Electronics Co. Ltd
+ *     Author: Jaswinder Singh <jassi.brar@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/clk.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+
+#include <mach/gpio-bank-c.h>
+#include <mach/gpio-bank-h.h>
+#include <plat/gpio-cfg.h>
+
+#include <mach/map.h>
+#include <mach/dma.h>
+
+#include "s3c-dma.h"
+#include "regs-i2s-v2.h"
+#include "s3c64xx-i2s.h"
+
+static struct s3c2410_dma_client s3c64xx_dma_client_out = {
+       .name           = "I2Sv4 PCM Stereo out"
+};
+
+static struct s3c2410_dma_client s3c64xx_dma_client_in = {
+       .name           = "I2Sv4 PCM Stereo in"
+};
+
+static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
+static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
+static struct s3c_i2sv2_info s3c64xx_i2sv4;
+
+struct snd_soc_dai s3c64xx_i2s_v4_dai;
+EXPORT_SYMBOL_GPL(s3c64xx_i2s_v4_dai);
+
+static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
+{
+       return cpu_dai->private_data;
+}
+
+static int s3c64xx_i2sv4_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)
+{
+       /* configure GPIO for i2s port */
+       s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C64XX_GPC4_I2S_V40_DO0);
+       s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C64XX_GPC5_I2S_V40_DO1);
+       s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C64XX_GPC7_I2S_V40_DO2);
+       s3c_gpio_cfgpin(S3C64XX_GPH(6), S3C64XX_GPH6_I2S_V40_BCLK);
+       s3c_gpio_cfgpin(S3C64XX_GPH(7), S3C64XX_GPH7_I2S_V40_CDCLK);
+       s3c_gpio_cfgpin(S3C64XX_GPH(8), S3C64XX_GPH8_I2S_V40_LRCLK);
+       s3c_gpio_cfgpin(S3C64XX_GPH(9), S3C64XX_GPH9_I2S_V40_DI);
+
+       return 0;
+}
+
+static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params,
+                                struct snd_soc_dai *cpu_dai)
+{
+       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
+       struct s3c_dma_params *dma_data;
+       u32 iismod;
+
+       dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
+
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+               dma_data = i2s->dma_playback;
+       else
+               dma_data = i2s->dma_capture;
+
+       snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
+
+       iismod = readl(i2s->regs + S3C2412_IISMOD);
+       dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
+
+       iismod &= ~S3C64XX_IISMOD_BLC_MASK;
+       switch (params_format(params)) {
+       case SNDRV_PCM_FORMAT_S8:
+               iismod |= S3C64XX_IISMOD_BLC_8BIT;
+               break;
+       case SNDRV_PCM_FORMAT_S16_LE:
+               break;
+       case SNDRV_PCM_FORMAT_S24_LE:
+               iismod |= S3C64XX_IISMOD_BLC_24BIT;
+               break;
+       }
+
+       writel(iismod, i2s->regs + S3C2412_IISMOD);
+       dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
+
+       return 0;
+}
+
+static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
+       .hw_params      = s3c_i2sv4_hw_params,
+};
+
+static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
+{
+       struct s3c_i2sv2_info *i2s;
+       struct snd_soc_dai *dai;
+       int ret;
+
+       i2s = &s3c64xx_i2sv4;
+       dai = &s3c64xx_i2s_v4_dai;
+
+       if (dai->dev) {
+               dev_dbg(dai->dev, "%s: \
+                       I2Sv4 instance already registered!\n", __func__);
+               return -EBUSY;
+       }
+
+       dai->dev = &pdev->dev;
+       dai->name = "s3c64xx-i2s-v4";
+       dai->id = 0;
+       dai->symmetric_rates = 1;
+       dai->playback.channels_min = 2;
+       dai->playback.channels_max = 2;
+       dai->playback.rates = S3C64XX_I2S_RATES;
+       dai->playback.formats = S3C64XX_I2S_FMTS;
+       dai->capture.channels_min = 2;
+       dai->capture.channels_max = 2;
+       dai->capture.rates = S3C64XX_I2S_RATES;
+       dai->capture.formats = S3C64XX_I2S_FMTS;
+       dai->probe = s3c64xx_i2sv4_probe;
+       dai->ops = &s3c64xx_i2sv4_dai_ops;
+
+       i2s->feature |= S3C_FEATURE_CDCLKCON;
+
+       i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
+       i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
+
+       i2s->dma_capture->channel = DMACH_HSI_I2SV40_RX;
+       i2s->dma_capture->dma_addr = S3C64XX_PA_IISV4 + S3C2412_IISRXD;
+       i2s->dma_playback->channel = DMACH_HSI_I2SV40_TX;
+       i2s->dma_playback->dma_addr = S3C64XX_PA_IISV4 + S3C2412_IISTXD;
+
+       i2s->dma_capture->client = &s3c64xx_dma_client_in;
+       i2s->dma_capture->dma_size = 4;
+       i2s->dma_playback->client = &s3c64xx_dma_client_out;
+       i2s->dma_playback->dma_size = 4;
+
+       i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
+       if (IS_ERR(i2s->iis_cclk)) {
+               dev_err(&pdev->dev, "failed to get audio-bus\n");
+               ret = PTR_ERR(i2s->iis_cclk);
+               goto err;
+       }
+
+       clk_enable(i2s->iis_cclk);
+
+       ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
+       if (ret)
+               goto err_clk;
+
+       ret = s3c_i2sv2_register_dai(dai);
+       if (ret != 0)
+               goto err_i2sv2;
+
+       return 0;
+
+err_i2sv2:
+       /* Not implemented for I2Sv2 core yet */
+err_clk:
+       clk_put(i2s->iis_cclk);
+err:
+       return ret;
+}
+
+static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
+{
+       dev_err(&pdev->dev, "Device removal not yet supported\n");
+       return 0;
+}
+
+static struct platform_driver s3c64xx_i2sv4_driver = {
+       .probe  = s3c64xx_i2sv4_dev_probe,
+       .remove = s3c64xx_i2sv4_dev_remove,
+       .driver = {
+               .name = "s3c64xx-iis-v4",
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init s3c64xx_i2sv4_init(void)
+{
+       return platform_driver_register(&s3c64xx_i2sv4_driver);
+}
+module_init(s3c64xx_i2sv4_init);
+
+static void __exit s3c64xx_i2sv4_exit(void)
+{
+       platform_driver_unregister(&s3c64xx_i2sv4_driver);
+}
+module_exit(s3c64xx_i2sv4_exit);
+
+/* Module information */
+MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
+MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
+MODULE_LICENSE("GPL");
index a72c251..1d85cb8 100644 (file)
  * published by the Free Software Foundation.
  */
 
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/device.h>
 #include <linux/clk.h>
 #include <linux/gpio.h>
 #include <linux/io.h>
 
 #include <sound/soc.h>
 
-#include <plat/regs-s3c2412-iis.h>
 #include <mach/gpio-bank-d.h>
 #include <mach/gpio-bank-e.h>
 #include <plat/gpio-cfg.h>
@@ -30,6 +26,7 @@
 #include <mach/dma.h>
 
 #include "s3c-dma.h"
+#include "regs-i2s-v2.h"
 #include "s3c64xx-i2s.h"
 
 /* The value should be set to maximum of the total number
@@ -57,55 +54,6 @@ static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
        return cpu_dai->private_data;
 }
 
-static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
-                                 int clk_id, unsigned int freq, int dir)
-{
-       struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
-       u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
-
-       switch (clk_id) {
-       case S3C64XX_CLKSRC_PCLK:
-               iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
-               break;
-
-       case S3C64XX_CLKSRC_MUX:
-               iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
-               break;
-
-       case S3C64XX_CLKSRC_CDCLK:
-               switch (dir) {
-               case SND_SOC_CLOCK_IN:
-                       iismod |= S3C64XX_IISMOD_CDCLKCON;
-                       break;
-               case SND_SOC_CLOCK_OUT:
-                       iismod &= ~S3C64XX_IISMOD_CDCLKCON;
-                       break;
-               default:
-                       return -EINVAL;
-               }
-               break;
-
-       default:
-               return -EINVAL;
-       }
-
-       writel(iismod, i2s->regs + S3C2412_IISMOD);
-
-       return 0;
-}
-
-struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
-{
-       struct s3c_i2sv2_info *i2s = to_info(dai);
-       u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
-
-       if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
-               return i2s->iis_cclk;
-       else
-               return i2s->iis_pclk;
-}
-EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
-
 static int s3c64xx_i2s_probe(struct platform_device *pdev,
                             struct snd_soc_dai *dai)
 {
@@ -130,18 +78,7 @@ static int s3c64xx_i2s_probe(struct platform_device *pdev,
 }
 
 
-#define S3C64XX_I2S_RATES \
-       (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
-       SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
-       SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
-
-#define S3C64XX_I2S_FMTS \
-       (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
-        SNDRV_PCM_FMTBIT_S24_LE)
-
-static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
-       .set_sysclk     = s3c64xx_i2s_set_sysclk,       
-};
+static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
 
 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
 {
@@ -171,6 +108,8 @@ static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
        dai->probe = s3c64xx_i2s_probe;
        dai->ops = &s3c64xx_i2s_dai_ops;
 
+       i2s->feature |= S3C_FEATURE_CDCLKCON;
+
        i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
        i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
 
index abe7253..7a40f43 100644 (file)
@@ -23,12 +23,20 @@ struct clk;
 #define S3C64XX_DIV_RCLK       S3C_I2SV2_DIV_RCLK
 #define S3C64XX_DIV_PRESCALER  S3C_I2SV2_DIV_PRESCALER
 
-#define S3C64XX_CLKSRC_PCLK    (0)
-#define S3C64XX_CLKSRC_MUX     (1)
-#define S3C64XX_CLKSRC_CDCLK    (2)
+#define S3C64XX_CLKSRC_PCLK    S3C_I2SV2_CLKSRC_PCLK
+#define S3C64XX_CLKSRC_MUX     S3C_I2SV2_CLKSRC_AUDIOBUS
+#define S3C64XX_CLKSRC_CDCLK    S3C_I2SV2_CLKSRC_CDCLK
 
-extern struct snd_soc_dai s3c64xx_i2s_dai[];
+#define S3C64XX_I2S_RATES \
+       (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
+       SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
+       SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
+
+#define S3C64XX_I2S_FMTS \
+       (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
+        SNDRV_PCM_FMTBIT_S24_LE)
 
-extern struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai);
+extern struct snd_soc_dai s3c64xx_i2s_dai[];
+extern struct snd_soc_dai s3c64xx_i2s_v4_dai;
 
 #endif /* __SND_SOC_S3C24XX_S3C64XX_I2S_H */
index efe4901..07e8e51 100644 (file)
@@ -22,8 +22,6 @@
 #include "s3c-dma.h"
 #include "s3c64xx-i2s.h"
 
-#define S3C64XX_I2S_V4 2
-
 /* SMDK64XX has a 12MHZ crystal attached to WM8580 */
 #define SMDK64XX_WM8580_FREQ 12000000
 
@@ -215,7 +213,7 @@ static struct snd_soc_dai_link smdk64xx_dai[] = {
 { /* Primary Playback i/f */
        .name = "WM8580 PAIF RX",
        .stream_name = "Playback",
-       .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
+       .cpu_dai = &s3c64xx_i2s_v4_dai,
        .codec_dai = &wm8580_dai[WM8580_DAI_PAIFRX],
        .init = smdk64xx_wm8580_init_paifrx,
        .ops = &smdk64xx_ops,
@@ -223,7 +221,7 @@ static struct snd_soc_dai_link smdk64xx_dai[] = {
 { /* Primary Capture i/f */
        .name = "WM8580 PAIF TX",
        .stream_name = "Capture",
-       .cpu_dai = &s3c64xx_i2s_dai[S3C64XX_I2S_V4],
+       .cpu_dai = &s3c64xx_i2s_v4_dai,
        .codec_dai = &wm8580_dai[WM8580_DAI_PAIFTX],
        .init = smdk64xx_wm8580_init_paiftx,
        .ops = &smdk64xx_ops,
index f07f6d8..a1d14bc 100644 (file)
@@ -1,5 +1,5 @@
 menu "SoC Audio support for SuperH"
-       depends on SUPERH
+       depends on SUPERH || ARCH_SHMOBILE
 
 config SND_SOC_PCM_SH7760
        tristate "SoC Audio support for Renesas SH7760"
@@ -22,7 +22,6 @@ config SND_SOC_SH4_SSI
 
 config SND_SOC_SH4_FSI
        tristate "SH4 FSI support"
-       depends on CPU_SUBTYPE_SH7724
        help
          This option enables FSI sound support
 
index 5263ab1..be01854 100644 (file)
 #include <sound/sh_fsi.h>
 #include <../sound/soc/codecs/ak4642.h>
 
+static int fsi_ak4642_dai_init(struct snd_soc_codec *codec)
+{
+       int ret;
+
+       ret = snd_soc_dai_set_fmt(&ak4642_dai, SND_SOC_DAIFMT_CBM_CFM);
+       if (ret < 0)
+               return ret;
+
+       ret = snd_soc_dai_set_sysclk(&ak4642_dai, 0, 11289600, 0);
+
+       return ret;
+}
+
 static struct snd_soc_dai_link fsi_dai_link = {
        .name           = "AK4642",
        .stream_name    = "AK4642",
        .cpu_dai        = &fsi_soc_dai[0], /* fsi */
        .codec_dai      = &ak4642_dai,
+       .init           = fsi_ak4642_dai_init,
        .ops            = NULL,
 };
 
index 8dc966f..3396a0d 100644 (file)
 #define MUTE_ST                0x0028
 #define REG_END                MUTE_ST
 
+
+#define CPU_INT_ST     0x01F4
+#define CPU_IEMSK      0x01F8
+#define CPU_IMSK       0x01FC
 #define INT_ST         0x0200
 #define IEMSK          0x0204
 #define IMSK           0x0208
 #define MUTE           0x020C
 #define CLK_RST                0x0210
 #define SOFT_RST       0x0214
-#define MREG_START     INT_ST
-#define MREG_END       SOFT_RST
+#define FIFO_SZ                0x0218
+#define MREG_START     CPU_INT_ST
+#define MREG_END       FIFO_SZ
 
 /* DO_FMT */
 /* DI_FMT */
 #define INT_A_IN       (1 << 4)
 #define INT_A_OUT      (1 << 0)
 
+/* SOFT_RST */
+#define PBSR           (1 << 12) /* Port B Software Reset */
+#define PASR           (1 <<  8) /* Port A Software Reset */
+#define IR             (1 <<  4) /* Interrupt Reset */
+#define FSISR          (1 <<  0) /* Software Reset */
+
+/* FIFO_SZ */
+#define OUT_SZ_MASK    0x7
+#define BO_SZ_SHIFT    8
+#define AO_SZ_SHIFT    0
+
 #define FSI_RATES SNDRV_PCM_RATE_8000_96000
 
 #define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
@@ -105,11 +121,18 @@ struct fsi_priv {
        int periods;
 };
 
+struct fsi_regs {
+       u32 int_st;
+       u32 iemsk;
+       u32 imsk;
+};
+
 struct fsi_master {
        void __iomem *base;
        int irq;
        struct fsi_priv fsia;
        struct fsi_priv fsib;
+       struct fsi_regs *regs;
        struct sh_fsi_platform_info *info;
        spinlock_t lock;
 };
@@ -317,7 +340,7 @@ static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play)
 /************************************************************************
 
 
-               ctrl function
+               irq function
 
 
 ************************************************************************/
@@ -326,8 +349,8 @@ static void fsi_irq_enable(struct fsi_priv *fsi, int is_play)
        u32 data = fsi_port_ab_io_bit(fsi, is_play);
        struct fsi_master *master = fsi_get_master(fsi);
 
-       fsi_master_mask_set(master, IMSK,  data, data);
-       fsi_master_mask_set(master, IEMSK, data, data);
+       fsi_master_mask_set(master, master->regs->imsk,  data, data);
+       fsi_master_mask_set(master, master->regs->iemsk, data, data);
 }
 
 static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
@@ -335,10 +358,39 @@ static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
        u32 data = fsi_port_ab_io_bit(fsi, is_play);
        struct fsi_master *master = fsi_get_master(fsi);
 
-       fsi_master_mask_set(master, IMSK,  data, 0);
-       fsi_master_mask_set(master, IEMSK, data, 0);
+       fsi_master_mask_set(master, master->regs->imsk,  data, 0);
+       fsi_master_mask_set(master, master->regs->iemsk, data, 0);
+}
+
+static u32 fsi_irq_get_status(struct fsi_master *master)
+{
+       return fsi_master_read(master, master->regs->int_st);
+}
+
+static void fsi_irq_clear_all_status(struct fsi_master *master)
+{
+       fsi_master_write(master, master->regs->int_st, 0x0000000);
 }
 
+static void fsi_irq_clear_status(struct fsi_priv *fsi)
+{
+       u32 data = 0;
+       struct fsi_master *master = fsi_get_master(fsi);
+
+       data |= fsi_port_ab_io_bit(fsi, 0);
+       data |= fsi_port_ab_io_bit(fsi, 1);
+
+       /* clear interrupt factor */
+       fsi_master_mask_set(master, master->regs->int_st, data, 0);
+}
+
+/************************************************************************
+
+
+               ctrl function
+
+
+************************************************************************/
 static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)
 {
        u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4);
@@ -350,41 +402,61 @@ static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable)
                fsi_master_mask_set(master, CLK_RST, val, 0);
 }
 
-static void fsi_irq_init(struct fsi_priv *fsi, int is_play)
+static void fsi_fifo_init(struct fsi_priv *fsi,
+                         int is_play,
+                         struct snd_soc_dai *dai)
 {
-       u32 data;
-       u32 ctrl;
+       struct fsi_master *master = fsi_get_master(fsi);
+       u32 ctrl, shift, i;
 
-       data = fsi_port_ab_io_bit(fsi, is_play);
-       ctrl = is_play ? DOFF_CTL : DIFF_CTL;
+       /* get on-chip RAM capacity */
+       shift = fsi_master_read(master, FIFO_SZ);
+       shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT;
+       shift &= OUT_SZ_MASK;
+       fsi->fifo_max = 256 << shift;
+       dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max);
 
-       /* set IMSK */
-       fsi_irq_disable(fsi, is_play);
+       /*
+        * The maximum number of sample data varies depending
+        * on the number of channels selected for the format.
+        *
+        * FIFOs are used in 4-channel units in 3-channel mode
+        * and in 8-channel units in 5- to 7-channel mode
+        * meaning that more FIFOs than the required size of DPRAM
+        * are used.
+        *
+        * ex) if 256 words of DP-RAM is connected
+        * 1 channel:  256 (256 x 1 = 256)
+        * 2 channels: 128 (128 x 2 = 256)
+        * 3 channels:  64 ( 64 x 3 = 192)
+        * 4 channels:  64 ( 64 x 4 = 256)
+        * 5 channels:  32 ( 32 x 5 = 160)
+        * 6 channels:  32 ( 32 x 6 = 192)
+        * 7 channels:  32 ( 32 x 7 = 224)
+        * 8 channels:  32 ( 32 x 8 = 256)
+        */
+       for (i = 1; i < fsi->chan; i <<= 1)
+               fsi->fifo_max >>= 1;
+       dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max);
+
+       ctrl = is_play ? DOFF_CTL : DIFF_CTL;
 
        /* set interrupt generation factor */
        fsi_reg_write(fsi, ctrl, IRQ_HALF);
 
        /* clear FIFO */
        fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR);
-
-       /* clear interrupt factor */
-       fsi_master_mask_set(fsi_get_master(fsi), INT_ST, data, 0);
 }
 
 static void fsi_soft_all_reset(struct fsi_master *master)
 {
-       u32 status = fsi_master_read(master, SOFT_RST);
-
        /* port AB reset */
-       status &= 0x000000ff;
-       fsi_master_write(master, SOFT_RST, status);
+       fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0);
        mdelay(10);
 
        /* soft reset */
-       status &= 0x000000f0;
-       fsi_master_write(master, SOFT_RST, status);
-       status |= 0x00000001;
-       fsi_master_write(master, SOFT_RST, status);
+       fsi_master_mask_set(master, SOFT_RST, FSISR, 0);
+       fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR);
        mdelay(10);
 }
 
@@ -559,12 +631,11 @@ static int fsi_data_pop(struct fsi_priv *fsi, int startup)
 static irqreturn_t fsi_interrupt(int irq, void *data)
 {
        struct fsi_master *master = data;
-       u32 status = fsi_master_read(master, SOFT_RST) & ~0x00000010;
-       u32 int_st = fsi_master_read(master, INT_ST);
+       u32 int_st = fsi_irq_get_status(master);
 
        /* clear irq status */
-       fsi_master_write(master, SOFT_RST, status);
-       fsi_master_write(master, SOFT_RST, status | 0x00000010);
+       fsi_master_mask_set(master, SOFT_RST, IR, 0);
+       fsi_master_mask_set(master, SOFT_RST, IR, IR);
 
        if (int_st & INT_A_OUT)
                fsi_data_push(&master->fsia, 0);
@@ -575,7 +646,7 @@ static irqreturn_t fsi_interrupt(int irq, void *data)
        if (int_st & INT_B_IN)
                fsi_data_pop(&master->fsib, 0);
 
-       fsi_master_write(master, INT_ST, 0x0000000);
+       fsi_irq_clear_all_status(master);
 
        return IRQ_HANDLED;
 }
@@ -669,29 +740,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
                dev_err(dai->dev, "unknown format.\n");
                return -EINVAL;
        }
-
-       switch (fsi->chan) {
-       case 1:
-               fsi->fifo_max = 256;
-               break;
-       case 2:
-               fsi->fifo_max = 128;
-               break;
-       case 3:
-       case 4:
-               fsi->fifo_max = 64;
-               break;
-       case 5:
-       case 6:
-       case 7:
-       case 8:
-               fsi->fifo_max = 32;
-               break;
-       default:
-               dev_err(dai->dev, "channel size error.\n");
-               return -EINVAL;
-       }
-
        fsi_reg_write(fsi, reg, data);
 
        /*
@@ -700,8 +748,12 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
        if (is_master)
                fsi_clk_ctrl(fsi, 1);
 
-       /* irq setting */
-       fsi_irq_init(fsi, is_play);
+       /* irq clear */
+       fsi_irq_disable(fsi, is_play);
+       fsi_irq_clear_status(fsi);
+
+       /* fifo init */
+       fsi_fifo_init(fsi, is_play, dai);
 
        return ret;
 }
@@ -913,6 +965,7 @@ EXPORT_SYMBOL_GPL(fsi_soc_platform);
 static int fsi_probe(struct platform_device *pdev)
 {
        struct fsi_master *master;
+       const struct platform_device_id *id_entry;
        struct resource *res;
        unsigned int irq;
        int ret;
@@ -922,6 +975,12 @@ static int fsi_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
+       id_entry = pdev->id_entry;
+       if (!id_entry) {
+               dev_err(&pdev->dev, "unknown fsi device\n");
+               return -ENODEV;
+       }
+
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        irq = platform_get_irq(pdev, 0);
        if (!res || (int)irq <= 0) {
@@ -950,6 +1009,7 @@ static int fsi_probe(struct platform_device *pdev)
        master->fsia.master     = master;
        master->fsib.base       = master->base + 0x40;
        master->fsib.master     = master;
+       master->regs            = (struct fsi_regs *)id_entry->driver_data;
        spin_lock_init(&master->lock);
 
        pm_runtime_enable(&pdev->dev);
@@ -962,7 +1022,8 @@ static int fsi_probe(struct platform_device *pdev)
 
        fsi_soft_all_reset(master);
 
-       ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, "fsi", master);
+       ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED,
+                         id_entry->name, master);
        if (ret) {
                dev_err(&pdev->dev, "irq request err\n");
                goto exit_iounmap;
@@ -1029,6 +1090,23 @@ static struct dev_pm_ops fsi_pm_ops = {
        .runtime_resume         = fsi_runtime_nop,
 };
 
+static struct fsi_regs fsi_regs = {
+       .int_st = INT_ST,
+       .iemsk  = IEMSK,
+       .imsk   = IMSK,
+};
+
+static struct fsi_regs fsi2_regs = {
+       .int_st = CPU_INT_ST,
+       .iemsk  = CPU_IEMSK,
+       .imsk   = CPU_IMSK,
+};
+
+static struct platform_device_id fsi_id_table[] = {
+       { "sh_fsi",     (kernel_ulong_t)&fsi_regs },
+       { "sh_fsi2",    (kernel_ulong_t)&fsi2_regs },
+};
+
 static struct platform_driver fsi_driver = {
        .driver         = {
                .name   = "sh_fsi",
@@ -1036,6 +1114,7 @@ static struct platform_driver fsi_driver = {
        },
        .probe          = fsi_probe,
        .remove         = fsi_remove,
+       .id_table       = fsi_id_table,
 };
 
 static int __init fsi_mobile_init(void)
index 5869dc3..472af38 100644 (file)
@@ -44,6 +44,8 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        ret = codec->hw_write(codec->control_data, data, 2);
        if (ret == 2)
                return 0;
@@ -112,6 +114,8 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        ret = codec->hw_write(codec->control_data, data, 2);
        if (ret == 2)
                return 0;
@@ -159,7 +163,8 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
 
        BUG_ON(codec->volatile_register);
 
-       data[0] = reg & 0xff;
+       reg &= 0xff;
+       data[0] = reg;
        data[1] = value & 0xff;
 
        if (reg < codec->reg_cache_size)
@@ -170,6 +175,8 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        if (codec->hw_write(codec->control_data, data, 2) == 2)
                return 0;
        else
@@ -180,6 +187,7 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
                                     unsigned int reg)
 {
        u8 *cache = codec->reg_cache;
+       reg &= 0xff;
        if (reg >= codec->reg_cache_size)
                return -1;
        return cache[reg];
@@ -203,6 +211,8 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        if (codec->hw_write(codec->control_data, data, 3) == 3)
                return 0;
        else
@@ -225,6 +235,40 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
        }
 }
 
+#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
+static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec,
+                                         unsigned int r)
+{
+       struct i2c_msg xfer[2];
+       u8 reg = r;
+       u8 data;
+       int ret;
+       struct i2c_client *client = codec->control_data;
+
+       /* Write register */
+       xfer[0].addr = client->addr;
+       xfer[0].flags = 0;
+       xfer[0].len = 1;
+       xfer[0].buf = &reg;
+
+       /* Read data */
+       xfer[1].addr = client->addr;
+       xfer[1].flags = I2C_M_RD;
+       xfer[1].len = 1;
+       xfer[1].buf = &data;
+
+       ret = i2c_transfer(client->adapter, xfer, 2);
+       if (ret != 2) {
+               dev_err(&client->dev, "i2c_transfer() returned %d\n", ret);
+               return 0;
+       }
+
+       return data;
+}
+#else
+#define snd_soc_8_8_read_i2c NULL
+#endif
+
 #if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
 static unsigned int snd_soc_8_16_read_i2c(struct snd_soc_codec *codec,
                                          unsigned int r)
@@ -326,6 +370,8 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
                return 0;
        }
 
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
        ret = codec->hw_write(codec->control_data, data, 3);
        if (ret == 3)
                return 0;
@@ -366,6 +412,86 @@ static int snd_soc_16_8_spi_write(void *control_data, const char *data,
 #define snd_soc_16_8_spi_write NULL
 #endif
 
+#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
+static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec,
+                                          unsigned int r)
+{
+       struct i2c_msg xfer[2];
+       u16 reg = cpu_to_be16(r);
+       u16 data;
+       int ret;
+       struct i2c_client *client = codec->control_data;
+
+       /* Write register */
+       xfer[0].addr = client->addr;
+       xfer[0].flags = 0;
+       xfer[0].len = 2;
+       xfer[0].buf = (u8 *)&reg;
+
+       /* Read data */
+       xfer[1].addr = client->addr;
+       xfer[1].flags = I2C_M_RD;
+       xfer[1].len = 2;
+       xfer[1].buf = (u8 *)&data;
+
+       ret = i2c_transfer(client->adapter, xfer, 2);
+       if (ret != 2) {
+               dev_err(&client->dev, "i2c_transfer() returned %d\n", ret);
+               return 0;
+       }
+
+       return be16_to_cpu(data);
+}
+#else
+#define snd_soc_16_16_read_i2c NULL
+#endif
+
+static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec,
+                                      unsigned int reg)
+{
+       u16 *cache = codec->reg_cache;
+
+       if (reg >= codec->reg_cache_size ||
+           snd_soc_codec_volatile_register(codec, reg)) {
+               if (codec->cache_only)
+                       return -EINVAL;
+
+               return codec->hw_read(codec, reg);
+       }
+
+       return cache[reg];
+}
+
+static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
+                              unsigned int value)
+{
+       u16 *cache = codec->reg_cache;
+       u8 data[4];
+       int ret;
+
+       data[0] = (reg >> 8) & 0xff;
+       data[1] = reg & 0xff;
+       data[2] = (value >> 8) & 0xff;
+       data[3] = value & 0xff;
+
+       if (reg < codec->reg_cache_size)
+               cache[reg] = value;
+
+       if (codec->cache_only) {
+               codec->cache_sync = 1;
+               return 0;
+       }
+
+       dev_dbg(codec->dev, "0x%x = 0x%x\n", reg, value);
+
+       ret = codec->hw_write(codec->control_data, data, 4);
+       if (ret == 4)
+               return 0;
+       if (ret < 0)
+               return ret;
+       else
+               return -EIO;
+}
 
 static struct {
        int addr_bits;
@@ -388,6 +514,7 @@ static struct {
        {
                .addr_bits = 8, .data_bits = 8,
                .write = snd_soc_8_8_write, .read = snd_soc_8_8_read,
+               .i2c_read = snd_soc_8_8_read_i2c,
        },
        {
                .addr_bits = 8, .data_bits = 16,
@@ -400,6 +527,11 @@ static struct {
                .i2c_read = snd_soc_16_8_read_i2c,
                .spi_write = snd_soc_16_8_spi_write,
        },
+       {
+               .addr_bits = 16, .data_bits = 16,
+               .write = snd_soc_16_16_write, .read = snd_soc_16_16_read,
+               .i2c_read = snd_soc_16_16_read_i2c,
+       },
 };
 
 /**
index ad7f952..998569d 100644 (file)
@@ -316,7 +316,7 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
 
        if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
            machine->symmetric_rates) {
-               dev_dbg(card->dev, "Symmetry forces %dHz rate\n", 
+               dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
                        machine->rate);
 
                ret = snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -405,6 +405,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                        codec_dai->playback.formats & cpu_dai->playback.formats;
                runtime->hw.rates =
                        codec_dai->playback.rates & cpu_dai->playback.rates;
+               if (codec_dai->playback.rates
+                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+                       runtime->hw.rates |= cpu_dai->playback.rates;
+               if (cpu_dai->playback.rates
+                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+                       runtime->hw.rates |= codec_dai->playback.rates;
        } else {
                runtime->hw.rate_min =
                        max(codec_dai->capture.rate_min,
@@ -422,6 +428,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                        codec_dai->capture.formats & cpu_dai->capture.formats;
                runtime->hw.rates =
                        codec_dai->capture.rates & cpu_dai->capture.rates;
+               if (codec_dai->capture.rates
+                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+                       runtime->hw.rates |= cpu_dai->capture.rates;
+               if (cpu_dai->capture.rates
+                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
+                       runtime->hw.rates |= codec_dai->capture.rates;
        }
 
        snd_pcm_limit_hw_rates(runtime);
@@ -455,12 +467,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
                 runtime->hw.rate_max);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               cpu_dai->playback.active = codec_dai->playback.active = 1;
-       else
-               cpu_dai->capture.active = codec_dai->capture.active = 1;
-       cpu_dai->active = codec_dai->active = 1;
-       cpu_dai->runtime = runtime;
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               cpu_dai->playback.active++;
+               codec_dai->playback.active++;
+       } else {
+               cpu_dai->capture.active++;
+               codec_dai->capture.active++;
+       }
+       cpu_dai->active++;
+       codec_dai->active++;
        card->codec->active++;
        mutex_unlock(&pcm_mutex);
        return 0;
@@ -536,15 +551,16 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
 
        mutex_lock(&pcm_mutex);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               cpu_dai->playback.active = codec_dai->playback.active = 0;
-       else
-               cpu_dai->capture.active = codec_dai->capture.active = 0;
-
-       if (codec_dai->playback.active == 0 &&
-               codec_dai->capture.active == 0) {
-               cpu_dai->active = codec_dai->active = 0;
+       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+               cpu_dai->playback.active--;
+               codec_dai->playback.active--;
+       } else {
+               cpu_dai->capture.active--;
+               codec_dai->capture.active--;
        }
+
+       cpu_dai->active--;
+       codec_dai->active--;
        codec->active--;
 
        /* Muting the DAC suppresses artifacts caused during digital
@@ -564,7 +580,6 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
 
        if (platform->pcm_ops->close)
                platform->pcm_ops->close(substream);
-       cpu_dai->runtime = NULL;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                /* start delayed pop wq here for playback streams */
@@ -802,6 +817,41 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        return 0;
 }
 
+/*
+ * soc level wrapper for pointer callback
+ * If cpu_dai, codec_dai, platform driver has the delay callback, than
+ * the runtime->delay will be updated accordingly.
+ */
+static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct snd_soc_device *socdev = rtd->socdev;
+       struct snd_soc_card *card = socdev->card;
+       struct snd_soc_platform *platform = card->platform;
+       struct snd_soc_dai_link *machine = rtd->dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       snd_pcm_uframes_t offset = 0;
+       snd_pcm_sframes_t delay = 0;
+
+       if (platform->pcm_ops->pointer)
+               offset = platform->pcm_ops->pointer(substream);
+
+       if (cpu_dai->ops->delay)
+               delay += cpu_dai->ops->delay(substream, cpu_dai);
+
+       if (codec_dai->ops->delay)
+               delay += codec_dai->ops->delay(substream, codec_dai);
+
+       if (platform->delay)
+               delay += platform->delay(substream, codec_dai);
+
+       runtime->delay = delay;
+
+       return offset;
+}
+
 /* ASoC PCM operations */
 static struct snd_pcm_ops soc_pcm_ops = {
        .open           = soc_pcm_open,
@@ -810,6 +860,7 @@ static struct snd_pcm_ops soc_pcm_ops = {
        .hw_free        = soc_pcm_hw_free,
        .prepare        = soc_pcm_prepare,
        .trigger        = soc_pcm_trigger,
+       .pointer        = soc_pcm_pointer,
 };
 
 #ifdef CONFIG_PM
@@ -843,23 +894,35 @@ static int soc_suspend(struct device *dev)
        /* mute any active DAC's */
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (dai->ops->digital_mute && dai->playback.active)
                        dai->ops->digital_mute(dai, 1);
        }
 
        /* suspend all pcms */
-       for (i = 0; i < card->num_links; i++)
+       for (i = 0; i < card->num_links; i++) {
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                snd_pcm_suspend_all(card->dai_link[i].pcm);
+       }
 
        if (card->suspend_pre)
                card->suspend_pre(pdev, PMSG_SUSPEND);
 
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai  *cpu_dai = card->dai_link[i].cpu_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (cpu_dai->suspend && !cpu_dai->ac97_control)
                        cpu_dai->suspend(cpu_dai);
                if (platform->suspend)
-                       platform->suspend(cpu_dai);
+                       platform->suspend(&card->dai_link[i]);
        }
 
        /* close any waiting streams and save state */
@@ -868,6 +931,10 @@ static int soc_suspend(struct device *dev)
 
        for (i = 0; i < codec->num_dai; i++) {
                char *stream = codec->dai[i].playback.stream_name;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
                                SND_SOC_DAPM_STREAM_SUSPEND);
@@ -877,11 +944,26 @@ static int soc_suspend(struct device *dev)
                                SND_SOC_DAPM_STREAM_SUSPEND);
        }
 
-       if (codec_dev->suspend)
-               codec_dev->suspend(pdev, PMSG_SUSPEND);
+       /* If there are paths active then the CODEC will be held with
+        * bias _ON and should not be suspended. */
+       if (codec_dev->suspend) {
+               switch (codec->bias_level) {
+               case SND_SOC_BIAS_STANDBY:
+               case SND_SOC_BIAS_OFF:
+                       codec_dev->suspend(pdev, PMSG_SUSPEND);
+                       break;
+               default:
+                       dev_dbg(socdev->dev, "CODEC is on over suspend\n");
+                       break;
+               }
+       }
 
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (cpu_dai->suspend && cpu_dai->ac97_control)
                        cpu_dai->suspend(cpu_dai);
        }
@@ -913,20 +995,44 @@ static void soc_resume_deferred(struct work_struct *work)
 
        dev_dbg(socdev->dev, "starting resume work\n");
 
+       /* Bring us up into D2 so that DAPM starts enabling things */
+       snd_power_change_state(codec->card, SNDRV_CTL_POWER_D2);
+
        if (card->resume_pre)
                card->resume_pre(pdev);
 
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (cpu_dai->resume && cpu_dai->ac97_control)
                        cpu_dai->resume(cpu_dai);
        }
 
-       if (codec_dev->resume)
-               codec_dev->resume(pdev);
+       /* If the CODEC was idle over suspend then it will have been
+        * left with bias OFF or STANDBY and suspended so we must now
+        * resume.  Otherwise the suspend was suppressed.
+        */
+       if (codec_dev->resume) {
+               switch (codec->bias_level) {
+               case SND_SOC_BIAS_STANDBY:
+               case SND_SOC_BIAS_OFF:
+                       codec_dev->resume(pdev);
+                       break;
+               default:
+                       dev_dbg(socdev->dev, "CODEC was on over suspend\n");
+                       break;
+               }
+       }
 
        for (i = 0; i < codec->num_dai; i++) {
                char *stream = codec->dai[i].playback.stream_name;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
                                SND_SOC_DAPM_STREAM_RESUME);
@@ -939,16 +1045,24 @@ static void soc_resume_deferred(struct work_struct *work)
        /* unmute any active DACs */
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (dai->ops->digital_mute && dai->playback.active)
                        dai->ops->digital_mute(dai, 0);
        }
 
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
+
+               if (card->dai_link[i].ignore_suspend)
+                       continue;
+
                if (cpu_dai->resume && !cpu_dai->ac97_control)
                        cpu_dai->resume(cpu_dai);
                if (platform->resume)
-                       platform->resume(cpu_dai);
+                       platform->resume(&card->dai_link[i]);
        }
 
        if (card->resume_post)
@@ -1233,26 +1347,25 @@ static int soc_remove(struct platform_device *pdev)
        struct snd_soc_platform *platform = card->platform;
        struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
 
-       if (!card->instantiated)
-               return 0;
+       if (card->instantiated) {
+               run_delayed_work(&card->delayed_work);
 
-       run_delayed_work(&card->delayed_work);
+               if (platform->remove)
+                       platform->remove(pdev);
 
-       if (platform->remove)
-               platform->remove(pdev);
+               if (codec_dev->remove)
+                       codec_dev->remove(pdev);
 
-       if (codec_dev->remove)
-               codec_dev->remove(pdev);
+               for (i = 0; i < card->num_links; i++) {
+                       struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
+                       if (cpu_dai->remove)
+                               cpu_dai->remove(pdev, cpu_dai);
+               }
 
-       for (i = 0; i < card->num_links; i++) {
-               struct snd_soc_dai *cpu_dai = card->dai_link[i].cpu_dai;
-               if (cpu_dai->remove)
-                       cpu_dai->remove(pdev, cpu_dai);
+               if (card->remove)
+                       card->remove(pdev);
        }
 
-       if (card->remove)
-               card->remove(pdev);
-
        snd_soc_unregister_card(card);
 
        return 0;
@@ -1336,7 +1449,6 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        dai_link->pcm = pcm;
        pcm->private_data = rtd;
        soc_pcm_ops.mmap = platform->pcm_ops->mmap;
-       soc_pcm_ops.pointer = platform->pcm_ops->pointer;
        soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
        soc_pcm_ops.copy = platform->pcm_ops->copy;
        soc_pcm_ops.silence = platform->pcm_ops->silence;
@@ -1906,18 +2018,22 @@ int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
 {
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
-       int max = mc->max;
+       int platform_max;
        unsigned int shift = mc->shift;
        unsigned int rshift = mc->rshift;
 
-       if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
+       if (!mc->platform_max)
+               mc->platform_max = mc->max;
+       platform_max = mc->platform_max;
+
+       if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
                uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        else
                uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 
        uinfo->count = shift == rshift ? 1 : 2;
        uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = max;
+       uinfo->value.integer.max = platform_max;
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_info_volsw);
@@ -2015,16 +2131,20 @@ int snd_soc_info_volsw_2r(struct snd_kcontrol *kcontrol,
 {
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
-       int max = mc->max;
+       int platform_max;
 
-       if (max == 1 && !strstr(kcontrol->id.name, " Volume"))
+       if (!mc->platform_max)
+               mc->platform_max = mc->max;
+       platform_max = mc->platform_max;
+
+       if (platform_max == 1 && !strstr(kcontrol->id.name, " Volume"))
                uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        else
                uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 
        uinfo->count = 2;
        uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = max;
+       uinfo->value.integer.max = platform_max;
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_2r);
@@ -2125,13 +2245,17 @@ int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
 {
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
-       int max = mc->max;
+       int platform_max;
        int min = mc->min;
 
+       if (!mc->platform_max)
+               mc->platform_max = mc->max;
+       platform_max = mc->platform_max;
+
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 2;
        uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = max-min;
+       uinfo->value.integer.max = platform_max - min;
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
@@ -2189,6 +2313,45 @@ int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
 
+/**
+ * snd_soc_limit_volume - Set new limit to an existing volume control.
+ *
+ * @codec: where to look for the control
+ * @name: Name of the control
+ * @max: new maximum limit
+ *
+ * Return 0 for success, else error.
+ */
+int snd_soc_limit_volume(struct snd_soc_codec *codec,
+       const char *name, int max)
+{
+       struct snd_card *card = codec->card;
+       struct snd_kcontrol *kctl;
+       struct soc_mixer_control *mc;
+       int found = 0;
+       int ret = -EINVAL;
+
+       /* Sanity check for name and max */
+       if (unlikely(!name || max <= 0))
+               return -EINVAL;
+
+       list_for_each_entry(kctl, &card->controls, list) {
+               if (!strncmp(kctl->id.name, name, sizeof(kctl->id.name))) {
+                       found = 1;
+                       break;
+               }
+       }
+       if (found) {
+               mc = (struct soc_mixer_control *)kctl->private_value;
+               if (max <= mc->max) {
+                       mc->platform_max = max;
+                       ret = 0;
+               }
+       }
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_limit_volume);
+
 /**
  * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  * @dai: DAI
index 7c28f40..03cb7c0 100644 (file)
@@ -98,7 +98,6 @@ static void pop_dbg(u32 pop_time, const char *fmt, ...)
 
        if (pop_time) {
                vprintk(fmt, args);
-               pop_wait(pop_time);
        }
 
        va_end(args);
@@ -315,62 +314,14 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
                pop_dbg(codec->pop_time, "pop test %s : %s in %d ms\n",
                        widget->name, widget->power ? "on" : "off",
                        codec->pop_time);
-               snd_soc_write(codec, widget->reg, new);
                pop_wait(codec->pop_time);
+               snd_soc_write(codec, widget->reg, new);
        }
        pr_debug("reg %x old %x new %x change %d\n", widget->reg,
                 old, new, change);
        return change;
 }
 
-/* ramps the volume up or down to minimise pops before or after a
- * DAPM power event */
-static int dapm_set_pga(struct snd_soc_dapm_widget *widget, int power)
-{
-       const struct snd_kcontrol_new *k = widget->kcontrols;
-
-       if (widget->muted && !power)
-               return 0;
-       if (!widget->muted && power)
-               return 0;
-
-       if (widget->num_kcontrols && k) {
-               struct soc_mixer_control *mc =
-                       (struct soc_mixer_control *)k->private_value;
-               unsigned int reg = mc->reg;
-               unsigned int shift = mc->shift;
-               int max = mc->max;
-               unsigned int mask = (1 << fls(max)) - 1;
-               unsigned int invert = mc->invert;
-
-               if (power) {
-                       int i;
-                       /* power up has happended, increase volume to last level */
-                       if (invert) {
-                               for (i = max; i > widget->saved_value; i--)
-                                       snd_soc_update_bits(widget->codec, reg, mask, i);
-                       } else {
-                               for (i = 0; i < widget->saved_value; i++)
-                                       snd_soc_update_bits(widget->codec, reg, mask, i);
-                       }
-                       widget->muted = 0;
-               } else {
-                       /* power down is about to occur, decrease volume to mute */
-                       int val = snd_soc_read(widget->codec, reg);
-                       int i = widget->saved_value = (val >> shift) & mask;
-                       if (invert) {
-                               for (; i < mask; i++)
-                                       snd_soc_update_bits(widget->codec, reg, mask, i);
-                       } else {
-                               for (; i > 0; i--)
-                                       snd_soc_update_bits(widget->codec, reg, mask, i);
-                       }
-                       widget->muted = 1;
-               }
-       }
-       return 0;
-}
-
 /* create new dapm mixer control */
 static int dapm_new_mixer(struct snd_soc_codec *codec,
        struct snd_soc_dapm_widget *w)
@@ -465,20 +416,10 @@ err:
 static int dapm_new_pga(struct snd_soc_codec *codec,
        struct snd_soc_dapm_widget *w)
 {
-       struct snd_kcontrol *kcontrol;
-       int ret = 0;
-
-       if (!w->num_kcontrols)
-               return -EINVAL;
+       if (w->num_kcontrols)
+               pr_err("asoc: PGA controls not supported: '%s'\n", w->name);
 
-       kcontrol = snd_soc_cnew(&w->kcontrols[0], w, w->name);
-       ret = snd_ctl_add(codec->card, kcontrol);
-       if (ret < 0) {
-               printk(KERN_ERR "asoc: failed to add kcontrol %s\n", w->name);
-               return ret;
-       }
-
-       return ret;
+       return 0;
 }
 
 /* reset 'walked' bit for each dapm path */
@@ -490,6 +431,25 @@ static inline void dapm_clear_walk(struct snd_soc_codec *codec)
                p->walked = 0;
 }
 
+/* We implement power down on suspend by checking the power state of
+ * the ALSA card - when we are suspending the ALSA state for the card
+ * is set to D3.
+ */
+static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
+{
+       struct snd_soc_codec *codec = widget->codec;
+
+       switch (snd_power_get_state(codec->card)) {
+       case SNDRV_CTL_POWER_D3hot:
+       case SNDRV_CTL_POWER_D3cold:
+               if (widget->ignore_suspend)
+                       pr_debug("%s ignoring suspend\n", widget->name);
+               return widget->ignore_suspend;
+       default:
+               return 1;
+       }
+}
+
 /*
  * Recursively check for a completed path to an active or physically connected
  * output widget. Returns number of complete paths.
@@ -506,7 +466,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
        case snd_soc_dapm_adc:
        case snd_soc_dapm_aif_out:
                if (widget->active)
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
        default:
                break;
        }
@@ -514,12 +474,12 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
        if (widget->connected) {
                /* connected pin ? */
                if (widget->id == snd_soc_dapm_output && !widget->ext)
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
 
                /* connected jack or spk ? */
                if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
                    (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
        }
 
        list_for_each_entry(path, &widget->sinks, list_source) {
@@ -552,7 +512,7 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
        case snd_soc_dapm_dac:
        case snd_soc_dapm_aif_in:
                if (widget->active)
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
        default:
                break;
        }
@@ -560,16 +520,16 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
        if (widget->connected) {
                /* connected pin ? */
                if (widget->id == snd_soc_dapm_input && !widget->ext)
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
 
                /* connected VMID/Bias for lower pops */
                if (widget->id == snd_soc_dapm_vmid)
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
 
                /* connected jack ? */
                if (widget->id == snd_soc_dapm_mic ||
                    (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
-                       return 1;
+                       return snd_soc_dapm_suspend_check(widget);
        }
 
        list_for_each_entry(path, &widget->sources, list_sink) {
@@ -634,16 +594,8 @@ static int dapm_generic_apply_power(struct snd_soc_dapm_widget *w)
                        return ret;
        }
 
-       /* Lower PGA volume to reduce pops */
-       if (w->id == snd_soc_dapm_pga && !w->power)
-               dapm_set_pga(w, w->power);
-
        dapm_update_bits(w);
 
-       /* Raise PGA volume to reduce pops */
-       if (w->id == snd_soc_dapm_pga && w->power)
-               dapm_set_pga(w, w->power);
-
        /* power up post event */
        if (w->power && w->event &&
            (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
@@ -810,10 +762,6 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
                                pr_err("%s: pre event failed: %d\n",
                                       w->name, ret);
                }
-
-               /* Lower PGA volume to reduce pops */
-               if (w->id == snd_soc_dapm_pga && !w->power)
-                       dapm_set_pga(w, w->power);
        }
 
        if (reg >= 0) {
@@ -825,10 +773,6 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
        }
 
        list_for_each_entry(w, pending, power_list) {
-               /* Raise PGA volume to reduce pops */
-               if (w->id == snd_soc_dapm_pga && w->power)
-                       dapm_set_pga(w, w->power);
-
                /* power up post event */
                if (w->power && w->event &&
                    (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
@@ -973,19 +917,12 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                        if (!w->power_check)
                                continue;
 
-                       /* If we're suspending then pull down all the 
-                        * power. */
-                       switch (event) {
-                       case SND_SOC_DAPM_STREAM_SUSPEND:
-                               power = 0;
-                               break;
-
-                       default:
+                       if (!w->force)
                                power = w->power_check(w);
-                               if (power)
-                                       sys_power = 1;
-                               break;
-                       }
+                       else
+                               power = 1;
+                       if (power)
+                               sys_power = 1;
 
                        if (w->power == power)
                                continue;
@@ -1076,6 +1013,7 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
 
        pop_dbg(codec->pop_time, "DAPM sequencing finished, waiting %dms\n",
                codec->pop_time);
+       pop_wait(codec->pop_time);
 
        return 0;
 }
@@ -1338,6 +1276,9 @@ static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
                if (!strcmp(w->name, pin)) {
                        pr_debug("dapm: %s: pin %s\n", codec->name, pin);
                        w->connected = status;
+                       /* Allow disabling of forced pins */
+                       if (status == 0)
+                               w->force = 0;
                        return 0;
                }
        }
@@ -1594,12 +1535,6 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
        unsigned int invert = mc->invert;
        unsigned int mask = (1 << fls(max)) - 1;
 
-       /* return the saved value if we are powered down */
-       if (widget->id == snd_soc_dapm_pga && !widget->power) {
-               ucontrol->value.integer.value[0] = widget->saved_value;
-               return 0;
-       }
-
        ucontrol->value.integer.value[0] =
                (snd_soc_read(widget->codec, reg) >> shift) & mask;
        if (shift != rshift)
@@ -1659,13 +1594,6 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        mutex_lock(&widget->codec->mutex);
        widget->value = val;
 
-       /* save volume value if the widget is powered down */
-       if (widget->id == snd_soc_dapm_pga && !widget->power) {
-               widget->saved_value = val;
-               mutex_unlock(&widget->codec->mutex);
-               return 1;
-       }
-
        if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
                if (val)
                        /* new connection */
@@ -2094,18 +2022,8 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
                                w->active = 0;
                                break;
                        case SND_SOC_DAPM_STREAM_SUSPEND:
-                               if (w->active)
-                                       w->suspend = 1;
-                               w->active = 0;
-                               break;
                        case SND_SOC_DAPM_STREAM_RESUME:
-                               if (w->suspend) {
-                                       w->active = 1;
-                                       w->suspend = 0;
-                               }
-                               break;
                        case SND_SOC_DAPM_STREAM_PAUSE_PUSH:
-                               break;
                        case SND_SOC_DAPM_STREAM_PAUSE_RELEASE:
                                break;
                        }
@@ -2134,6 +2052,36 @@ int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
 
+/**
+ * snd_soc_dapm_force_enable_pin - force a pin to be enabled
+ * @codec: SoC codec
+ * @pin: pin name
+ *
+ * Enables input/output pin regardless of any other state.  This is
+ * intended for use with microphone bias supplies used in microphone
+ * jack detection.
+ *
+ * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
+ * do any widget power switching.
+ */
+int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, const char *pin)
+{
+       struct snd_soc_dapm_widget *w;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (!strcmp(w->name, pin)) {
+                       pr_debug("dapm: %s: pin %s\n", codec->name, pin);
+                       w->connected = 1;
+                       w->force = 1;
+                       return 0;
+               }
+       }
+
+       pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
+
 /**
  * snd_soc_dapm_disable_pin - disable pin.
  * @codec: SoC codec
@@ -2191,6 +2139,33 @@ int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
 
+/**
+ * snd_soc_dapm_ignore_suspend - ignore suspend status for DAPM endpoint
+ * @codec: audio codec
+ * @pin: audio signal pin endpoint (or start point)
+ *
+ * Mark the given endpoint or pin as ignoring suspend.  When the
+ * system is disabled a path between two endpoints flagged as ignoring
+ * suspend will not be disabled.  The path must already be enabled via
+ * normal means at suspend time, it will not be turned on if it was not
+ * already enabled.
+ */
+int snd_soc_dapm_ignore_suspend(struct snd_soc_codec *codec, const char *pin)
+{
+       struct snd_soc_dapm_widget *w;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (!strcmp(w->name, pin)) {
+                       w->ignore_suspend = 1;
+                       return 0;
+               }
+       }
+
+       pr_err("Unknown DAPM pin: %s\n", pin);
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_ignore_suspend);
+
 /**
  * snd_soc_dapm_free - free dapm resources
  * @socdev: SoC device
index 3c07a94..29159e1 100644 (file)
@@ -37,6 +37,7 @@ int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
 {
        jack->card = card;
        INIT_LIST_HEAD(&jack->pins);
+       BLOCKING_INIT_NOTIFIER_HEAD(&jack->notifier);
 
        return snd_jack_new(card->codec->card, id, type, &jack->jack);
 }
@@ -63,10 +64,9 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
        int enable;
        int oldstatus;
 
-       if (!jack) {
-               WARN_ON_ONCE(!jack);
+       if (!jack)
                return;
-       }
+
        codec = jack->card->codec;
 
        mutex_lock(&codec->mutex);
@@ -93,6 +93,9 @@ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
                        snd_soc_dapm_disable_pin(codec, pin->pin);
        }
 
+       /* Report before the DAPM sync to help users updating micbias status */
+       blocking_notifier_call_chain(&jack->notifier, status, NULL);
+
        snd_soc_dapm_sync(codec);
 
        snd_jack_report(jack->jack, status);
@@ -143,6 +146,40 @@ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
 }
 EXPORT_SYMBOL_GPL(snd_soc_jack_add_pins);
 
+/**
+ * snd_soc_jack_notifier_register - Register a notifier for jack status
+ *
+ * @jack:  ASoC jack
+ * @nb:    Notifier block to register
+ *
+ * Register for notification of the current status of the jack.  Note
+ * that it is not possible to report additional jack events in the
+ * callback from the notifier, this is intended to support
+ * applications such as enabling electrical detection only when a
+ * mechanical detection event has occurred.
+ */
+void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
+                                   struct notifier_block *nb)
+{
+       blocking_notifier_chain_register(&jack->notifier, nb);
+}
+EXPORT_SYMBOL_GPL(snd_soc_jack_notifier_register);
+
+/**
+ * snd_soc_jack_notifier_unregister - Unregister a notifier for jack status
+ *
+ * @jack:  ASoC jack
+ * @nb:    Notifier block to unregister
+ *
+ * Stop notifying for status changes.
+ */
+void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
+                                     struct notifier_block *nb)
+{
+       blocking_notifier_chain_unregister(&jack->notifier, nb);
+}
+EXPORT_SYMBOL_GPL(snd_soc_jack_notifier_unregister);
+
 #ifdef CONFIG_GPIOLIB
 /* gpio detect */
 static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
index c570ae3..44d6d2e 100644 (file)
@@ -22,8 +22,7 @@ config SND_USB_AUDIO
          will be called snd-usb-audio.
 
 config SND_USB_UA101
-       tristate "Edirol UA-101/UA-1000 driver (EXPERIMENTAL)"
-       depends on EXPERIMENTAL
+       tristate "Edirol UA-101/UA-1000 driver"
        select SND_PCM
        select SND_RAWMIDI
        help
@@ -65,6 +64,7 @@ config SND_USB_CAIAQ
            * Native Instruments Audio 8 DJ
            * Native Instruments Guitar Rig Session I/O
            * Native Instruments Guitar Rig mobile
+           * Native Instruments Traktor Kontrol X1
 
           To compile this driver as a module, choose M here: the module
           will be called snd-usb-caiaq.
index 5bf64ae..e7ac7f4 100644 (file)
@@ -2,14 +2,24 @@
 # Makefile for ALSA
 #
 
-snd-usb-audio-objs := usbaudio.o usbmixer.o
-snd-usb-lib-objs := usbmidi.o
-snd-ua101-objs := ua101.o
+snd-usb-audio-objs :=  card.o \
+                       mixer.o \
+                       mixer_quirks.o \
+                       proc.o \
+                       quirks.o \
+                       format.o \
+                       endpoint.o \
+                       urb.o \
+                       pcm.o \
+                       helper.o
+
+snd-usbmidi-lib-objs := midi.o
 
 # Toplevel Module Dependency
-obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o
-obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o snd-usb-lib.o
-obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o
-obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o
+obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usbmidi-lib.o
+
+obj-$(CONFIG_SND_USB_UA101) += snd-usbmidi-lib.o
+obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o
+obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o
 
-obj-$(CONFIG_SND) += usx2y/ caiaq/
+obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/
index 537102b..36ed703 100644 (file)
@@ -35,33 +35,41 @@ static int control_info(struct snd_kcontrol *kcontrol,
        struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
        int pos = kcontrol->private_value;
        int is_intval = pos & CNT_INTVAL;
-       unsigned int id = dev->chip.usb_id;
+       int maxval = 63;
 
        uinfo->count = 1;
        pos &= ~CNT_INTVAL;
 
-       if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
-               && (pos == 0)) {
-               /* current input mode of A8DJ */
-               uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-               uinfo->value.integer.min = 0;
-               uinfo->value.integer.max = 2;
-               return 0;
-       }
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
+               if (pos == 0) {
+                       /* current input mode of A8DJ */
+                       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+                       uinfo->value.integer.min = 0;
+                       uinfo->value.integer.max = 2;
+                       return 0;
+               }
+               break;
 
-       if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)
-               && (pos == 0)) {
-               /* current input mode of A4DJ */
-               uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
-               uinfo->value.integer.min = 0;
-               uinfo->value.integer.max = 1;
-               return 0;
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
+               if (pos == 0) {
+                       /* current input mode of A4DJ */
+                       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+                       uinfo->value.integer.min = 0;
+                       uinfo->value.integer.max = 1;
+                       return 0;
+               }
+               break;
+
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               maxval = 127;
+               break;
        }
 
        if (is_intval) {
                uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
                uinfo->value.integer.min = 0;
-               uinfo->value.integer.max = 64;
+               uinfo->value.integer.max = maxval;
        } else {
                uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
                uinfo->value.integer.min = 0;
@@ -102,9 +110,10 @@ static int control_put(struct snd_kcontrol *kcontrol,
        struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
        struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
        int pos = kcontrol->private_value;
+       unsigned char cmd = EP1_CMD_WRITE_IO;
 
-       if (dev->chip.usb_id ==
-               USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): {
                /* A4DJ has only one control */
                /* do not expose hardware input mode 0 */
                dev->control_state[0] = ucontrol->value.integer.value[0] + 1;
@@ -113,10 +122,15 @@ static int control_put(struct snd_kcontrol *kcontrol,
                return 1;
        }
 
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               cmd = EP1_CMD_DIMM_LEDS;
+               break;
+       }
+
        if (pos & CNT_INTVAL) {
                dev->control_state[pos & ~CNT_INTVAL]
                        = ucontrol->value.integer.value[0];
-               snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
+               snd_usb_caiaq_send_command(dev, cmd,
                                dev->control_state, sizeof(dev->control_state));
        } else {
                if (ucontrol->value.integer.value[0])
@@ -124,7 +138,7 @@ static int control_put(struct snd_kcontrol *kcontrol,
                else
                        dev->control_state[pos / 8] &= ~(1 << (pos % 8));
 
-               snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
+               snd_usb_caiaq_send_command(dev, cmd,
                                dev->control_state, sizeof(dev->control_state));
        }
 
@@ -273,6 +287,43 @@ static struct caiaq_controller a4dj_controller[] = {
        { "Current input mode", 0 | CNT_INTVAL  }
 };
 
+static struct caiaq_controller kontrolx1_controller[] = {
+       { "LED FX A: ON",               7 | CNT_INTVAL  },
+       { "LED FX A: 1",                6 | CNT_INTVAL  },
+       { "LED FX A: 2",                5 | CNT_INTVAL  },
+       { "LED FX A: 3",                4 | CNT_INTVAL  },
+       { "LED FX B: ON",               3 | CNT_INTVAL  },
+       { "LED FX B: 1",                2 | CNT_INTVAL  },
+       { "LED FX B: 2",                1 | CNT_INTVAL  },
+       { "LED FX B: 3",                0 | CNT_INTVAL  },
+
+       { "LED Hotcue",                 28 | CNT_INTVAL },
+       { "LED Shift (white)",          29 | CNT_INTVAL },
+       { "LED Shift (green)",          30 | CNT_INTVAL },
+
+       { "LED Deck A: FX1",            24 | CNT_INTVAL },
+       { "LED Deck A: FX2",            25 | CNT_INTVAL },
+       { "LED Deck A: IN",             17 | CNT_INTVAL },
+       { "LED Deck A: OUT",            16 | CNT_INTVAL },
+       { "LED Deck A: < BEAT",         19 | CNT_INTVAL },
+       { "LED Deck A: BEAT >",         18 | CNT_INTVAL },
+       { "LED Deck A: CUE/ABS",        21 | CNT_INTVAL },
+       { "LED Deck A: CUP/REL",        20 | CNT_INTVAL },
+       { "LED Deck A: PLAY",           23 | CNT_INTVAL },
+       { "LED Deck A: SYNC",           22 | CNT_INTVAL },
+
+       { "LED Deck B: FX1",            26 | CNT_INTVAL },
+       { "LED Deck B: FX2",            27 | CNT_INTVAL },
+       { "LED Deck B: IN",             15 | CNT_INTVAL },
+       { "LED Deck B: OUT",            14 | CNT_INTVAL },
+       { "LED Deck B: < BEAT",         13 | CNT_INTVAL },
+       { "LED Deck B: BEAT >",         12 | CNT_INTVAL },
+       { "LED Deck B: CUE/ABS",        11 | CNT_INTVAL },
+       { "LED Deck B: CUP/REL",        10 | CNT_INTVAL },
+       { "LED Deck B: PLAY",           9  | CNT_INTVAL },
+       { "LED Deck B: SYNC",           8  | CNT_INTVAL },
+};
+
 static int __devinit add_controls(struct caiaq_controller *c, int num,
                                  struct snd_usb_caiaqdev *dev)
 {
@@ -321,10 +372,16 @@ int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
                ret = add_controls(a8dj_controller,
                        ARRAY_SIZE(a8dj_controller), dev);
                break;
+
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
                ret = add_controls(a4dj_controller,
                        ARRAY_SIZE(a4dj_controller), dev);
                break;
+
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               ret = add_controls(kontrolx1_controller,
+                       ARRAY_SIZE(kontrolx1_controller), dev);
+               break;
        }
 
        return ret;
index afc5aeb..8052718 100644 (file)
@@ -47,7 +47,8 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
                         "{Native Instruments, Audio 4 DJ},"
                         "{Native Instruments, Audio 8 DJ},"
                         "{Native Instruments, Session I/O},"
-                        "{Native Instruments, GuitarRig mobile}");
+                        "{Native Instruments, GuitarRig mobile}"
+                        "{Native Instruments, Traktor Kontrol X1}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
 static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -128,6 +129,11 @@ static struct usb_device_id snd_usb_id_table[] = {
                .idVendor =     USB_VID_NATIVEINSTRUMENTS,
                .idProduct =    USB_PID_AUDIO2DJ
        },
+       {
+               .match_flags =  USB_DEVICE_ID_MATCH_DEVICE,
+               .idVendor =     USB_VID_NATIVEINSTRUMENTS,
+               .idProduct =    USB_PID_TRAKTORKONTROLX1
+       },
        { /* terminator */ }
 };
 
index 44e3edf..f1117ec 100644 (file)
@@ -5,18 +5,20 @@
 
 #define USB_VID_NATIVEINSTRUMENTS 0x17cc
 
-#define USB_PID_RIGKONTROL2    0x1969
-#define USB_PID_RIGKONTROL3    0x1940
-#define USB_PID_KORECONTROLLER 0x4711
-#define USB_PID_KORECONTROLLER2        0x4712
-#define USB_PID_AK1            0x0815
-#define USB_PID_AUDIO2DJ       0x041c
-#define USB_PID_AUDIO4DJ       0x0839
-#define USB_PID_AUDIO8DJ       0x1978
-#define USB_PID_SESSIONIO      0x1915
-#define USB_PID_GUITARRIGMOBILE        0x0d8d
+#define USB_PID_RIGKONTROL2            0x1969
+#define USB_PID_RIGKONTROL3            0x1940
+#define USB_PID_KORECONTROLLER         0x4711
+#define USB_PID_KORECONTROLLER2                0x4712
+#define USB_PID_AK1                    0x0815
+#define USB_PID_AUDIO2DJ               0x041c
+#define USB_PID_AUDIO4DJ               0x0839
+#define USB_PID_AUDIO8DJ               0x1978
+#define USB_PID_SESSIONIO              0x1915
+#define USB_PID_GUITARRIGMOBILE                0x0d8d
+#define USB_PID_TRAKTORKONTROLX1       0x2305
 
 #define EP1_BUFSIZE 64
+#define EP4_BUFSIZE 512
 #define CAIAQ_USB_STR_LEN 0xff
 #define MAX_STREAMS 32
 
@@ -104,6 +106,8 @@ struct snd_usb_caiaqdev {
        struct input_dev *input_dev;
        char phys[64];                  /* physical device path */
        unsigned short keycode[64];
+       struct urb *ep4_in_urb;
+       unsigned char ep4_in_buf[EP4_BUFSIZE];
 #endif
 
        /* ALSA */
index a48d309..8bbfbfd 100644 (file)
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 */
 
+#include <linux/gfp.h>
 #include <linux/init.h>
 #include <linux/usb.h>
 #include <linux/usb/input.h>
+#include <sound/core.h>
 #include <sound/pcm.h>
 
 #include "device.h"
@@ -65,6 +67,8 @@ static unsigned short keycode_kore[] = {
        KEY_BRL_DOT5
 };
 
+#define KONTROLX1_INPUTS 40
+
 #define DEG90          (range / 2)
 #define DEG180         (range)
 #define DEG270         (DEG90 + DEG180)
@@ -162,6 +166,17 @@ static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
                input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]);
                input_sync(input_dev);
                break;
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               input_report_abs(input_dev, ABS_HAT0X, (buf[8] << 8)  | buf[9]);
+               input_report_abs(input_dev, ABS_HAT0Y, (buf[4] << 8)  | buf[5]);
+               input_report_abs(input_dev, ABS_HAT1X, (buf[12] << 8) | buf[13]);
+               input_report_abs(input_dev, ABS_HAT1Y, (buf[2] << 8)  | buf[3]);
+               input_report_abs(input_dev, ABS_HAT2X, (buf[15] << 8) | buf[15]);
+               input_report_abs(input_dev, ABS_HAT2Y, (buf[0] << 8)  | buf[1]);
+               input_report_abs(input_dev, ABS_HAT3X, (buf[10] << 8) | buf[11]);
+               input_report_abs(input_dev, ABS_HAT3Y, (buf[6] << 8)  | buf[7]);
+               input_sync(input_dev);
+               break;
        }
 }
 
@@ -201,7 +216,7 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
 }
 
 static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
-                                   char *buf, unsigned int len)
+                                   unsigned char *buf, unsigned int len)
 {
        struct input_dev *input_dev = dev->input_dev;
        unsigned short *keycode = input_dev->keycode;
@@ -218,15 +233,84 @@ static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
                input_report_key(input_dev, keycode[i],
                                 buf[i / 8] & (1 << (i % 8)));
 
-       if (dev->chip.usb_id ==
-               USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER) ||
-           dev->chip.usb_id ==
-               USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2))
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
                input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]);
+               break;
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               /* rotary encoders */
+               input_report_abs(dev->input_dev, ABS_X, buf[5] & 0xf);
+               input_report_abs(dev->input_dev, ABS_Y, buf[5] >> 4);
+               input_report_abs(dev->input_dev, ABS_Z, buf[6] & 0xf);
+               input_report_abs(dev->input_dev, ABS_MISC, buf[6] >> 4);
+               break;
+       }
 
        input_sync(input_dev);
 }
 
+static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
+{
+       struct snd_usb_caiaqdev *dev = urb->context;
+       unsigned char *buf = urb->transfer_buffer;
+       int ret;
+
+       if (urb->status || !dev || urb != dev->ep4_in_urb)
+               return;
+
+       if (urb->actual_length < 24)
+               goto requeue;
+
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               if (buf[0] & 0x3)
+                       snd_caiaq_input_read_io(dev, buf + 1, 7);
+
+               if (buf[0] & 0x4)
+                       snd_caiaq_input_read_analog(dev, buf + 8, 16);
+
+               break;
+       }
+
+requeue:
+       dev->ep4_in_urb->actual_length = 0;
+       ret = usb_submit_urb(dev->ep4_in_urb, GFP_ATOMIC);
+       if (ret < 0)
+               log("unable to submit urb. OOM!?\n");
+}
+
+static int snd_usb_caiaq_input_open(struct input_dev *idev)
+{
+       struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
+
+       if (!dev)
+               return -EINVAL;
+
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
+                       return -EIO;
+               break;
+       }
+
+       return 0;
+}
+
+static void snd_usb_caiaq_input_close(struct input_dev *idev)
+{
+       struct snd_usb_caiaqdev *dev = input_get_drvdata(idev);
+
+       if (!dev)
+               return;
+
+       switch (dev->chip.usb_id) {
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               usb_kill_urb(dev->ep4_in_urb);
+               break;
+       }
+}
+
 void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev,
                                  char *buf,
                                  unsigned int len)
@@ -251,7 +335,7 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
 {
        struct usb_device *usb_dev = dev->chip.dev;
        struct input_dev *input;
-       int i, ret;
+       int i, ret = 0;
 
        input = input_allocate_device();
        if (!input)
@@ -265,7 +349,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
        usb_to_input_id(usb_dev, &input->id);
        input->dev.parent = &usb_dev->dev;
 
-        switch (dev->chip.usb_id) {
+       input_set_drvdata(input, dev);
+
+       switch (dev->chip.usb_id) {
        case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
                input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
                input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
@@ -325,26 +411,73 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
                input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
                input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1);
                snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
+               break;
+       case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
+               input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+               input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
+                                  BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
+                                  BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
+                                  BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
+                                  BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
+                                  BIT_MASK(ABS_Z);
+               input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
+               BUILD_BUG_ON(sizeof(dev->keycode) < KONTROLX1_INPUTS);
+               for (i = 0; i < KONTROLX1_INPUTS; i++)
+                       dev->keycode[i] = BTN_MISC + i;
+               input->keycodemax = KONTROLX1_INPUTS;
+
+               /* analog potentiometers */
+               input_set_abs_params(input, ABS_HAT0X, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT0Y, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT1X, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT1Y, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT2X, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT2Y, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT3X, 0, 4096, 0, 10);
+               input_set_abs_params(input, ABS_HAT3Y, 0, 4096, 0, 10);
+
+               /* rotary encoders */
+               input_set_abs_params(input, ABS_X, 0, 0xf, 0, 1);
+               input_set_abs_params(input, ABS_Y, 0, 0xf, 0, 1);
+               input_set_abs_params(input, ABS_Z, 0, 0xf, 0, 1);
+               input_set_abs_params(input, ABS_MISC, 0, 0xf, 0, 1);
+
+               dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
+               if (!dev->ep4_in_urb) {
+                       ret = -ENOMEM;
+                       goto exit_free_idev;
+               }
+
+               usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
+                                 usb_rcvbulkpipe(usb_dev, 0x4),
+                                 dev->ep4_in_buf, EP4_BUFSIZE,
+                                 snd_usb_caiaq_ep4_reply_dispatch, dev);
+
+               snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
+
                break;
        default:
                /* no input methods supported on this device */
-               input_free_device(input);
-               return 0;
+               goto exit_free_idev;
        }
 
+       input->open = snd_usb_caiaq_input_open;
+       input->close = snd_usb_caiaq_input_close;
        input->keycode = dev->keycode;
        input->keycodesize = sizeof(unsigned short);
        for (i = 0; i < input->keycodemax; i++)
                __set_bit(dev->keycode[i], input->keybit);
 
        ret = input_register_device(input);
-       if (ret < 0) {
-               input_free_device(input);
-               return ret;
-       }
+       if (ret < 0)
+               goto exit_free_idev;
 
        dev->input_dev = input;
        return 0;
+
+exit_free_idev:
+       input_free_device(input);
+       return ret;
 }
 
 void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
@@ -352,6 +485,10 @@ void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
        if (!dev || !dev->input_dev)
                return;
 
+       usb_kill_urb(dev->ep4_in_urb);
+       usb_free_urb(dev->ep4_in_urb);
+       dev->ep4_in_urb = NULL;
+
        input_unregister_device(dev->input_dev);
        dev->input_dev = NULL;
 }
diff --git a/sound/usb/card.c b/sound/usb/card.c
new file mode 100644 (file)
index 0000000..da1346b
--- /dev/null
@@ -0,0 +1,652 @@
+/*
+ *   (Tentative) USB Audio Driver for ALSA
+ *
+ *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
+ *
+ *   Many codes borrowed from audio.c by
+ *         Alan Cox (alan@lxorguk.ukuu.org.uk)
+ *         Thomas Sailer (sailer@ife.ee.ethz.ch)
+ *
+ *
+ *   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
+ *
+ *
+ *  NOTES:
+ *
+ *   - async unlink should be used for avoiding the sleep inside lock.
+ *     2.4.22 usb-uhci seems buggy for async unlinking and results in
+ *     oops.  in such a cse, pass async_unlink=0 option.
+ *   - the linked URBs would be preferred but not used so far because of
+ *     the instability of unlinking.
+ *   - type II is not supported properly.  there is no device which supports
+ *     this type *correctly*.  SB extigy looks as if it supports, but it's
+ *     indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream).
+ */
+
+
+#include <linux/bitops.h>
+#include <linux/init.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/usb.h>
+#include <linux/moduleparam.h>
+#include <linux/mutex.h>
+#include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
+
+#include <sound/core.h>
+#include <sound/info.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/initval.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "midi.h"
+#include "mixer.h"
+#include "proc.h"
+#include "quirks.h"
+#include "endpoint.h"
+#include "helper.h"
+#include "debug.h"
+#include "pcm.h"
+#include "urb.h"
+#include "format.h"
+
+MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
+MODULE_DESCRIPTION("USB Audio");
+MODULE_LICENSE("GPL");
+MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
+
+
+static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
+static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
+static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
+/* Vendor/product IDs for this card */
+static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
+static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
+static int nrpacks = 8;                /* max. number of packets per urb */
+static int async_unlink = 1;
+static int device_setup[SNDRV_CARDS]; /* device parameter for this card */
+static int ignore_ctl_error;
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for the USB audio adapter.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable USB audio adapter.");
+module_param_array(vid, int, NULL, 0444);
+MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
+module_param_array(pid, int, NULL, 0444);
+MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
+module_param(nrpacks, int, 0644);
+MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
+module_param(async_unlink, bool, 0444);
+MODULE_PARM_DESC(async_unlink, "Use async unlink mode.");
+module_param_array(device_setup, int, NULL, 0444);
+MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
+module_param(ignore_ctl_error, bool, 0444);
+MODULE_PARM_DESC(ignore_ctl_error,
+                "Ignore errors from USB controller for mixer interfaces.");
+
+/*
+ * we keep the snd_usb_audio_t instances by ourselves for merging
+ * the all interfaces on the same card as one sound device.
+ */
+
+static DEFINE_MUTEX(register_mutex);
+static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
+static struct usb_driver usb_audio_driver;
+
+/*
+ * disconnect streams
+ * called from snd_usb_audio_disconnect()
+ */
+static void snd_usb_stream_disconnect(struct list_head *head)
+{
+       int idx;
+       struct snd_usb_stream *as;
+       struct snd_usb_substream *subs;
+
+       as = list_entry(head, struct snd_usb_stream, list);
+       for (idx = 0; idx < 2; idx++) {
+               subs = &as->substream[idx];
+               if (!subs->num_formats)
+                       return;
+               snd_usb_release_substream_urbs(subs, 1);
+               subs->interface = -1;
+       }
+}
+
+static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
+{
+       struct usb_device *dev = chip->dev;
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
+
+       if (!iface) {
+               snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
+                          dev->devnum, ctrlif, interface);
+               return -EINVAL;
+       }
+
+       if (usb_interface_claimed(iface)) {
+               snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
+                                               dev->devnum, ctrlif, interface);
+               return -EINVAL;
+       }
+
+       alts = &iface->altsetting[0];
+       altsd = get_iface_desc(alts);
+       if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
+            altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
+           altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
+               int err = snd_usbmidi_create(chip->card, iface,
+                                            &chip->midi_list, NULL);
+               if (err < 0) {
+                       snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
+                                               dev->devnum, ctrlif, interface);
+                       return -EINVAL;
+               }
+               usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
+
+               return 0;
+       }
+
+       if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
+            altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
+           altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
+               snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
+                                       dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
+               /* skip non-supported classes */
+               return -EINVAL;
+       }
+
+       if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
+               snd_printk(KERN_ERR "low speed audio streaming not supported\n");
+               return -EINVAL;
+       }
+
+       if (! snd_usb_parse_audio_endpoints(chip, interface)) {
+               usb_set_interface(dev, interface, 0); /* reset the current interface */
+               usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/*
+ * parse audio control descriptor and create pcm/midi streams
+ */
+static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
+{
+       struct usb_device *dev = chip->dev;
+       struct usb_host_interface *host_iface;
+       struct usb_interface_descriptor *altsd;
+       void *control_header;
+       int i, protocol;
+
+       /* find audiocontrol interface */
+       host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
+       control_header = snd_usb_find_csint_desc(host_iface->extra,
+                                                host_iface->extralen,
+                                                NULL, UAC_HEADER);
+       altsd = get_iface_desc(host_iface);
+       protocol = altsd->bInterfaceProtocol;
+
+       if (!control_header) {
+               snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
+               return -EINVAL;
+       }
+
+       switch (protocol) {
+       case UAC_VERSION_1: {
+               struct uac_ac_header_descriptor_v1 *h1 = control_header;
+
+               if (!h1->bInCollection) {
+                       snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
+                       return -EINVAL;
+               }
+
+               if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
+                       snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
+                       return -EINVAL;
+               }
+
+               for (i = 0; i < h1->bInCollection; i++)
+                       snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
+
+               break;
+       }
+
+       case UAC_VERSION_2: {
+               struct uac_clock_source_descriptor *cs;
+               struct usb_interface_assoc_descriptor *assoc =
+                       usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
+
+               if (!assoc) {
+                       snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
+                       return -EINVAL;
+               }
+
+               /* FIXME: for now, we expect there is at least one clock source
+                * descriptor and we always take the first one.
+                * We should properly support devices with multiple clock sources,
+                * clock selectors and sample rate conversion units. */
+
+               cs = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen,
+                                               NULL, UAC2_CLOCK_SOURCE);
+
+               if (!cs) {
+                       snd_printk(KERN_ERR "CLOCK_SOURCE descriptor not found\n");
+                       return -EINVAL;
+               }
+
+               chip->clock_id = cs->bClockID;
+
+               for (i = 0; i < assoc->bInterfaceCount; i++) {
+                       int intf = assoc->bFirstInterface + i;
+
+                       if (intf != ctrlif)
+                               snd_usb_create_stream(chip, ctrlif, intf);
+               }
+
+               break;
+       }
+
+       default:
+               snd_printk(KERN_ERR "unknown protocol version 0x%02x\n", protocol);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+/*
+ * free the chip instance
+ *
+ * here we have to do not much, since pcm and controls are already freed
+ *
+ */
+
+static int snd_usb_audio_free(struct snd_usb_audio *chip)
+{
+       kfree(chip);
+       return 0;
+}
+
+static int snd_usb_audio_dev_free(struct snd_device *device)
+{
+       struct snd_usb_audio *chip = device->device_data;
+       return snd_usb_audio_free(chip);
+}
+
+
+/*
+ * create a chip instance and set its names.
+ */
+static int snd_usb_audio_create(struct usb_device *dev, int idx,
+                               const struct snd_usb_audio_quirk *quirk,
+                               struct snd_usb_audio **rchip)
+{
+       struct snd_card *card;
+       struct snd_usb_audio *chip;
+       int err, len;
+       char component[14];
+       static struct snd_device_ops ops = {
+               .dev_free =     snd_usb_audio_dev_free,
+       };
+
+       *rchip = NULL;
+
+       if (snd_usb_get_speed(dev) != USB_SPEED_LOW &&
+           snd_usb_get_speed(dev) != USB_SPEED_FULL &&
+           snd_usb_get_speed(dev) != USB_SPEED_HIGH) {
+               snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
+               return -ENXIO;
+       }
+
+       err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
+       if (err < 0) {
+               snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
+               return err;
+       }
+
+       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+       if (! chip) {
+               snd_card_free(card);
+               return -ENOMEM;
+       }
+
+       chip->index = idx;
+       chip->dev = dev;
+       chip->card = card;
+       chip->setup = device_setup[idx];
+       chip->nrpacks = nrpacks;
+       chip->async_unlink = async_unlink;
+
+       chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
+                             le16_to_cpu(dev->descriptor.idProduct));
+       INIT_LIST_HEAD(&chip->pcm_list);
+       INIT_LIST_HEAD(&chip->midi_list);
+       INIT_LIST_HEAD(&chip->mixer_list);
+
+       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
+               snd_usb_audio_free(chip);
+               snd_card_free(card);
+               return err;
+       }
+
+       strcpy(card->driver, "USB-Audio");
+       sprintf(component, "USB%04x:%04x",
+               USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
+       snd_component_add(card, component);
+
+       /* retrieve the device string as shortname */
+       if (quirk && quirk->product_name) {
+               strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
+       } else {
+               if (!dev->descriptor.iProduct ||
+                   usb_string(dev, dev->descriptor.iProduct,
+                   card->shortname, sizeof(card->shortname)) <= 0) {
+                       /* no name available from anywhere, so use ID */
+                       sprintf(card->shortname, "USB Device %#04x:%#04x",
+                               USB_ID_VENDOR(chip->usb_id),
+                               USB_ID_PRODUCT(chip->usb_id));
+               }
+       }
+
+       /* retrieve the vendor and device strings as longname */
+       if (quirk && quirk->vendor_name) {
+               len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
+       } else {
+               if (dev->descriptor.iManufacturer)
+                       len = usb_string(dev, dev->descriptor.iManufacturer,
+                                        card->longname, sizeof(card->longname));
+               else
+                       len = 0;
+               /* we don't really care if there isn't any vendor string */
+       }
+       if (len > 0)
+               strlcat(card->longname, " ", sizeof(card->longname));
+
+       strlcat(card->longname, card->shortname, sizeof(card->longname));
+
+       len = strlcat(card->longname, " at ", sizeof(card->longname));
+
+       if (len < sizeof(card->longname))
+               usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
+
+       strlcat(card->longname,
+               snd_usb_get_speed(dev) == USB_SPEED_LOW ? ", low speed" :
+               snd_usb_get_speed(dev) == USB_SPEED_FULL ? ", full speed" :
+               ", high speed",
+               sizeof(card->longname));
+
+       snd_usb_audio_create_proc(chip);
+
+       *rchip = chip;
+       return 0;
+}
+
+/*
+ * probe the active usb device
+ *
+ * note that this can be called multiple times per a device, when it
+ * includes multiple audio control interfaces.
+ *
+ * thus we check the usb device pointer and creates the card instance
+ * only at the first time.  the successive calls of this function will
+ * append the pcm interface to the corresponding card.
+ */
+static void *snd_usb_audio_probe(struct usb_device *dev,
+                                struct usb_interface *intf,
+                                const struct usb_device_id *usb_id)
+{
+       const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;
+       int i, err;
+       struct snd_usb_audio *chip;
+       struct usb_host_interface *alts;
+       int ifnum;
+       u32 id;
+
+       alts = &intf->altsetting[0];
+       ifnum = get_iface_desc(alts)->bInterfaceNumber;
+       id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
+                   le16_to_cpu(dev->descriptor.idProduct));
+       if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
+               goto __err_val;
+
+       if (snd_usb_apply_boot_quirk(dev, intf, quirk) < 0)
+               goto __err_val;
+
+       /*
+        * found a config.  now register to ALSA
+        */
+
+       /* check whether it's already registered */
+       chip = NULL;
+       mutex_lock(&register_mutex);
+       for (i = 0; i < SNDRV_CARDS; i++) {
+               if (usb_chip[i] && usb_chip[i]->dev == dev) {
+                       if (usb_chip[i]->shutdown) {
+                               snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
+                               goto __error;
+                       }
+                       chip = usb_chip[i];
+                       break;
+               }
+       }
+       if (! chip) {
+               /* it's a fresh one.
+                * now look for an empty slot and create a new card instance
+                */
+               for (i = 0; i < SNDRV_CARDS; i++)
+                       if (enable[i] && ! usb_chip[i] &&
+                           (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
+                           (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
+                               if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
+                                       goto __error;
+                               }
+                               snd_card_set_dev(chip->card, &intf->dev);
+                               break;
+                       }
+               if (!chip) {
+                       printk(KERN_ERR "no available usb audio device\n");
+                       goto __error;
+               }
+       }
+
+       chip->txfr_quirk = 0;
+       err = 1; /* continue */
+       if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
+               /* need some special handlings */
+               if ((err = snd_usb_create_quirk(chip, intf, &usb_audio_driver, quirk)) < 0)
+                       goto __error;
+       }
+
+       if (err > 0) {
+               /* create normal USB audio interfaces */
+               if (snd_usb_create_streams(chip, ifnum) < 0 ||
+                   snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {
+                       goto __error;
+               }
+       }
+
+       /* we are allowed to call snd_card_register() many times */
+       if (snd_card_register(chip->card) < 0) {
+               goto __error;
+       }
+
+       usb_chip[chip->index] = chip;
+       chip->num_interfaces++;
+       mutex_unlock(&register_mutex);
+       return chip;
+
+ __error:
+       if (chip && !chip->num_interfaces)
+               snd_card_free(chip->card);
+       mutex_unlock(&register_mutex);
+ __err_val:
+       return NULL;
+}
+
+/*
+ * we need to take care of counter, since disconnection can be called also
+ * many times as well as usb_audio_probe().
+ */
+static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
+{
+       struct snd_usb_audio *chip;
+       struct snd_card *card;
+       struct list_head *p;
+
+       if (ptr == (void *)-1L)
+               return;
+
+       chip = ptr;
+       card = chip->card;
+       mutex_lock(&register_mutex);
+       chip->shutdown = 1;
+       chip->num_interfaces--;
+       if (chip->num_interfaces <= 0) {
+               snd_card_disconnect(card);
+               /* release the pcm resources */
+               list_for_each(p, &chip->pcm_list) {
+                       snd_usb_stream_disconnect(p);
+               }
+               /* release the midi resources */
+               list_for_each(p, &chip->midi_list) {
+                       snd_usbmidi_disconnect(p);
+               }
+               /* release mixer resources */
+               list_for_each(p, &chip->mixer_list) {
+                       snd_usb_mixer_disconnect(p);
+               }
+               usb_chip[chip->index] = NULL;
+               mutex_unlock(&register_mutex);
+               snd_card_free_when_closed(card);
+       } else {
+               mutex_unlock(&register_mutex);
+       }
+}
+
+/*
+ * new 2.5 USB kernel API
+ */
+static int usb_audio_probe(struct usb_interface *intf,
+                          const struct usb_device_id *id)
+{
+       void *chip;
+       chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
+       if (chip) {
+               usb_set_intfdata(intf, chip);
+               return 0;
+       } else
+               return -EIO;
+}
+
+static void usb_audio_disconnect(struct usb_interface *intf)
+{
+       snd_usb_audio_disconnect(interface_to_usbdev(intf),
+                                usb_get_intfdata(intf));
+}
+
+#ifdef CONFIG_PM
+static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct snd_usb_audio *chip = usb_get_intfdata(intf);
+       struct list_head *p;
+       struct snd_usb_stream *as;
+
+       if (chip == (void *)-1L)
+               return 0;
+
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
+       if (!chip->num_suspended_intf++) {
+               list_for_each(p, &chip->pcm_list) {
+                       as = list_entry(p, struct snd_usb_stream, list);
+                       snd_pcm_suspend_all(as->pcm);
+               }
+       }
+
+       return 0;
+}
+
+static int usb_audio_resume(struct usb_interface *intf)
+{
+       struct snd_usb_audio *chip = usb_get_intfdata(intf);
+
+       if (chip == (void *)-1L)
+               return 0;
+       if (--chip->num_suspended_intf)
+               return 0;
+       /*
+        * ALSA leaves material resumption to user space
+        * we just notify
+        */
+
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
+
+       return 0;
+}
+#else
+#define usb_audio_suspend      NULL
+#define usb_audio_resume       NULL
+#endif         /* CONFIG_PM */
+
+static struct usb_device_id usb_audio_ids [] = {
+#include "quirks-table.h"
+    { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
+      .bInterfaceClass = USB_CLASS_AUDIO,
+      .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
+    { }                                                /* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE (usb, usb_audio_ids);
+
+/*
+ * entry point for linux usb interface
+ */
+
+static struct usb_driver usb_audio_driver = {
+       .name =         "snd-usb-audio",
+       .probe =        usb_audio_probe,
+       .disconnect =   usb_audio_disconnect,
+       .suspend =      usb_audio_suspend,
+       .resume =       usb_audio_resume,
+       .id_table =     usb_audio_ids,
+};
+
+static int __init snd_usb_audio_init(void)
+{
+       if (nrpacks < 1 || nrpacks > MAX_PACKS) {
+               printk(KERN_WARNING "invalid nrpacks value.\n");
+               return -EINVAL;
+       }
+       return usb_register(&usb_audio_driver);
+}
+
+static void __exit snd_usb_audio_cleanup(void)
+{
+       usb_deregister(&usb_audio_driver);
+}
+
+module_init(snd_usb_audio_init);
+module_exit(snd_usb_audio_cleanup);
diff --git a/sound/usb/card.h b/sound/usb/card.h
new file mode 100644 (file)
index 0000000..ed92420
--- /dev/null
@@ -0,0 +1,105 @@
+#ifndef __USBAUDIO_CARD_H
+#define __USBAUDIO_CARD_H
+
+#define MAX_PACKS      20
+#define MAX_PACKS_HS   (MAX_PACKS * 8) /* in high speed mode */
+#define MAX_URBS       8
+#define SYNC_URBS      4       /* always four urbs for sync */
+#define MAX_QUEUE      24      /* try not to exceed this queue length, in ms */
+
+struct audioformat {
+       struct list_head list;
+       u64 formats;                    /* ALSA format bits */
+       unsigned int channels;          /* # channels */
+       unsigned int fmt_type;          /* USB audio format type (1-3) */
+       unsigned int frame_size;        /* samples per frame for non-audio */
+       int iface;                      /* interface number */
+       unsigned char altsetting;       /* corresponding alternate setting */
+       unsigned char altset_idx;       /* array index of altenate setting */
+       unsigned char attributes;       /* corresponding attributes of cs endpoint */
+       unsigned char endpoint;         /* endpoint */
+       unsigned char ep_attr;          /* endpoint attributes */
+       unsigned char datainterval;     /* log_2 of data packet interval */
+       unsigned int maxpacksize;       /* max. packet size */
+       unsigned int rates;             /* rate bitmasks */
+       unsigned int rate_min, rate_max;        /* min/max rates */
+       unsigned int nr_rates;          /* number of rate table entries */
+       unsigned int *rate_table;       /* rate table */
+};
+
+struct snd_usb_substream;
+
+struct snd_urb_ctx {
+       struct urb *urb;
+       unsigned int buffer_size;       /* size of data buffer, if data URB */
+       struct snd_usb_substream *subs;
+       int index;      /* index for urb array */
+       int packets;    /* number of packets per urb */
+};
+
+struct snd_urb_ops {
+       int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
+       int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
+       int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
+       int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
+};
+
+struct snd_usb_substream {
+       struct snd_usb_stream *stream;
+       struct usb_device *dev;
+       struct snd_pcm_substream *pcm_substream;
+       int direction;  /* playback or capture */
+       int interface;  /* current interface */
+       int endpoint;   /* assigned endpoint */
+       struct audioformat *cur_audiofmt;       /* current audioformat pointer (for hw_params callback) */
+       unsigned int cur_rate;          /* current rate (for hw_params callback) */
+       unsigned int period_bytes;      /* current period bytes (for hw_params callback) */
+       unsigned int altset_idx;     /* USB data format: index of alternate setting */
+       unsigned int datapipe;   /* the data i/o pipe */
+       unsigned int syncpipe;   /* 1 - async out or adaptive in */
+       unsigned int datainterval;      /* log_2 of data packet interval */
+       unsigned int syncinterval;  /* P for adaptive mode, 0 otherwise */
+       unsigned int freqn;      /* nominal sampling rate in fs/fps in Q16.16 format */
+       unsigned int freqm;      /* momentary sampling rate in fs/fps in Q16.16 format */
+       unsigned int freqmax;    /* maximum sampling rate, used for buffer management */
+       unsigned int phase;      /* phase accumulator */
+       unsigned int maxpacksize;       /* max packet size in bytes */
+       unsigned int maxframesize;      /* max packet size in frames */
+       unsigned int curpacksize;       /* current packet size in bytes (for capture) */
+       unsigned int curframesize;      /* current packet size in frames (for capture) */
+       unsigned int fill_max: 1;       /* fill max packet size always */
+       unsigned int txfr_quirk:1;      /* allow sub-frame alignment */
+       unsigned int fmt_type;          /* USB audio format type (1-3) */
+
+       unsigned int running: 1;        /* running status */
+
+       unsigned int hwptr_done;        /* processed byte position in the buffer */
+       unsigned int transfer_done;             /* processed frames since last period update */
+       unsigned long active_mask;      /* bitmask of active urbs */
+       unsigned long unlink_mask;      /* bitmask of unlinked urbs */
+
+       unsigned int nurbs;                     /* # urbs */
+       struct snd_urb_ctx dataurb[MAX_URBS];   /* data urb table */
+       struct snd_urb_ctx syncurb[SYNC_URBS];  /* sync urb table */
+       char *syncbuf;                          /* sync buffer for all sync URBs */
+       dma_addr_t sync_dma;                    /* DMA address of syncbuf */
+
+       u64 formats;                    /* format bitmasks (all or'ed) */
+       unsigned int num_formats;               /* number of supported audio formats (list) */
+       struct list_head fmt_list;      /* format list */
+       struct snd_pcm_hw_constraint_list rate_list;    /* limited rates */
+       spinlock_t lock;
+
+       struct snd_urb_ops ops;         /* callbacks (must be filled at init) */
+};
+
+struct snd_usb_stream {
+       struct snd_usb_audio *chip;
+       struct snd_pcm *pcm;
+       int pcm_index;
+       unsigned int fmt_type;          /* USB audio format type (1-3) */
+       struct snd_usb_substream substream[2];
+       struct list_head list;
+};
+
+#endif /* __USBAUDIO_CARD_H */
diff --git a/sound/usb/debug.h b/sound/usb/debug.h
new file mode 100644 (file)
index 0000000..343ec2d
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __USBAUDIO_DEBUG_H
+#define __USBAUDIO_DEBUG_H
+
+/*
+ * h/w constraints
+ */
+
+#ifdef HW_CONST_DEBUG
+#define hwc_debug(fmt, args...) printk(KERN_DEBUG fmt, ##args)
+#else
+#define hwc_debug(fmt, args...) /**/
+#endif
+
+#endif /* __USBAUDIO_DEBUG_H */
+
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
new file mode 100644 (file)
index 0000000..ef07a6d
--- /dev/null
@@ -0,0 +1,362 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "proc.h"
+#include "quirks.h"
+#include "endpoint.h"
+#include "urb.h"
+#include "pcm.h"
+#include "helper.h"
+#include "format.h"
+
+/*
+ * free a substream
+ */
+static void free_substream(struct snd_usb_substream *subs)
+{
+       struct list_head *p, *n;
+
+       if (!subs->num_formats)
+               return; /* not initialized */
+       list_for_each_safe(p, n, &subs->fmt_list) {
+               struct audioformat *fp = list_entry(p, struct audioformat, list);
+               kfree(fp->rate_table);
+               kfree(fp);
+       }
+       kfree(subs->rate_list.list);
+}
+
+
+/*
+ * free a usb stream instance
+ */
+static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
+{
+       free_substream(&stream->substream[0]);
+       free_substream(&stream->substream[1]);
+       list_del(&stream->list);
+       kfree(stream);
+}
+
+static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
+{
+       struct snd_usb_stream *stream = pcm->private_data;
+       if (stream) {
+               stream->pcm = NULL;
+               snd_usb_audio_stream_free(stream);
+       }
+}
+
+
+/*
+ * add this endpoint to the chip instance.
+ * if a stream with the same endpoint already exists, append to it.
+ * if not, create a new pcm stream.
+ */
+int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audioformat *fp)
+{
+       struct list_head *p;
+       struct snd_usb_stream *as;
+       struct snd_usb_substream *subs;
+       struct snd_pcm *pcm;
+       int err;
+
+       list_for_each(p, &chip->pcm_list) {
+               as = list_entry(p, struct snd_usb_stream, list);
+               if (as->fmt_type != fp->fmt_type)
+                       continue;
+               subs = &as->substream[stream];
+               if (!subs->endpoint)
+                       continue;
+               if (subs->endpoint == fp->endpoint) {
+                       list_add_tail(&fp->list, &subs->fmt_list);
+                       subs->num_formats++;
+                       subs->formats |= fp->formats;
+                       return 0;
+               }
+       }
+       /* look for an empty stream */
+       list_for_each(p, &chip->pcm_list) {
+               as = list_entry(p, struct snd_usb_stream, list);
+               if (as->fmt_type != fp->fmt_type)
+                       continue;
+               subs = &as->substream[stream];
+               if (subs->endpoint)
+                       continue;
+               err = snd_pcm_new_stream(as->pcm, stream, 1);
+               if (err < 0)
+                       return err;
+               snd_usb_init_substream(as, stream, fp);
+               return 0;
+       }
+
+       /* create a new pcm */
+       as = kzalloc(sizeof(*as), GFP_KERNEL);
+       if (!as)
+               return -ENOMEM;
+       as->pcm_index = chip->pcm_devs;
+       as->chip = chip;
+       as->fmt_type = fp->fmt_type;
+       err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs,
+                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0,
+                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1,
+                         &pcm);
+       if (err < 0) {
+               kfree(as);
+               return err;
+       }
+       as->pcm = pcm;
+       pcm->private_data = as;
+       pcm->private_free = snd_usb_audio_pcm_free;
+       pcm->info_flags = 0;
+       if (chip->pcm_devs > 0)
+               sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
+       else
+               strcpy(pcm->name, "USB Audio");
+
+       snd_usb_init_substream(as, stream, fp);
+
+       list_add(&as->list, &chip->pcm_list);
+       chip->pcm_devs++;
+
+       snd_usb_proc_pcm_format_add(as);
+
+       return 0;
+}
+
+int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
+{
+       struct usb_device *dev;
+       struct usb_interface *iface;
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       int i, altno, err, stream;
+       int format = 0, num_channels = 0;
+       struct audioformat *fp = NULL;
+       unsigned char *fmt, *csep;
+       int num, protocol;
+
+       dev = chip->dev;
+
+       /* parse the interface's altsettings */
+       iface = usb_ifnum_to_if(dev, iface_no);
+
+       num = iface->num_altsetting;
+
+       /*
+        * Dallas DS4201 workaround: It presents 5 altsettings, but the last
+        * one misses syncpipe, and does not produce any sound.
+        */
+       if (chip->usb_id == USB_ID(0x04fa, 0x4201))
+               num = 4;
+
+       for (i = 0; i < num; i++) {
+               alts = &iface->altsetting[i];
+               altsd = get_iface_desc(alts);
+               protocol = altsd->bInterfaceProtocol;
+               /* skip invalid one */
+               if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
+                    altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
+                   (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
+                    altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
+                   altsd->bNumEndpoints < 1 ||
+                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
+                       continue;
+               /* must be isochronous */
+               if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
+                   USB_ENDPOINT_XFER_ISOC)
+                       continue;
+               /* check direction */
+               stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
+                       SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+               altno = altsd->bAlternateSetting;
+
+               if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
+                       continue;
+
+               /* get audio formats */
+               switch (protocol) {
+               case UAC_VERSION_1: {
+                       struct uac_as_header_descriptor_v1 *as =
+                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
+
+                       if (!as) {
+                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       if (as->bLength < sizeof(*as)) {
+                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       format = le16_to_cpu(as->wFormatTag); /* remember the format value */
+                       break;
+               }
+
+               case UAC_VERSION_2: {
+                       struct uac_as_header_descriptor_v2 *as =
+                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
+
+                       if (!as) {
+                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       if (as->bLength < sizeof(*as)) {
+                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
+                                          dev->devnum, iface_no, altno);
+                               continue;
+                       }
+
+                       num_channels = as->bNrChannels;
+                       format = le32_to_cpu(as->bmFormats);
+
+                       break;
+               }
+
+               default:
+                       snd_printk(KERN_ERR "%d:%u:%d : unknown interface protocol %04x\n",
+                                  dev->devnum, iface_no, altno, protocol);
+                       continue;
+               }
+
+               /* get format type */
+               fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
+               if (!fmt) {
+                       snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
+                                  dev->devnum, iface_no, altno);
+                       continue;
+               }
+               if (((protocol == UAC_VERSION_1) && (fmt[0] < 8)) ||
+                   ((protocol == UAC_VERSION_2) && (fmt[0] != 6))) {
+                       snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
+                                  dev->devnum, iface_no, altno);
+                       continue;
+               }
+
+               /*
+                * Blue Microphones workaround: The last altsetting is identical
+                * with the previous one, except for a larger packet size, but
+                * is actually a mislabeled two-channel setting; ignore it.
+                */
+               if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
+                   fp && fp->altsetting == 1 && fp->channels == 1 &&
+                   fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
+                   protocol == UAC_VERSION_1 &&
+                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
+                                                       fp->maxpacksize * 2)
+                       continue;
+
+               csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
+               /* Creamware Noah has this descriptor after the 2nd endpoint */
+               if (!csep && altsd->bNumEndpoints >= 2)
+                       csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
+               if (!csep || csep[0] < 7 || csep[2] != UAC_EP_GENERAL) {
+                       snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
+                                  " class specific endpoint descriptor\n",
+                                  dev->devnum, iface_no, altno);
+                       csep = NULL;
+               }
+
+               fp = kzalloc(sizeof(*fp), GFP_KERNEL);
+               if (! fp) {
+                       snd_printk(KERN_ERR "cannot malloc\n");
+                       return -ENOMEM;
+               }
+
+               fp->iface = iface_no;
+               fp->altsetting = altno;
+               fp->altset_idx = i;
+               fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
+               fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
+               fp->datainterval = snd_usb_parse_datainterval(chip, alts);
+               fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
+               /* num_channels is only set for v2 interfaces */
+               fp->channels = num_channels;
+               if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
+                       fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
+                                       * (fp->maxpacksize & 0x7ff);
+               fp->attributes = csep ? csep[3] : 0;
+
+               /* some quirks for attributes here */
+
+               switch (chip->usb_id) {
+               case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
+                       /* Optoplay sets the sample rate attribute although
+                        * it seems not supporting it in fact.
+                        */
+                       fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
+                       break;
+               case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
+               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
+               case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra 8 */
+               case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
+                       /* doesn't set the sample rate attribute, but supports it */
+                       fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
+                       break;
+               case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
+               case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
+                                               an older model 77d:223) */
+               /*
+                * plantronics headset and Griffin iMic have set adaptive-in
+                * although it's really not...
+                */
+                       fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
+                       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+                               fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
+                       else
+                               fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
+                       break;
+               }
+
+               /* ok, let's parse further... */
+               if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
+                       kfree(fp->rate_table);
+                       kfree(fp);
+                       continue;
+               }
+
+               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
+               err = snd_usb_add_audio_endpoint(chip, stream, fp);
+               if (err < 0) {
+                       kfree(fp->rate_table);
+                       kfree(fp);
+                       return err;
+               }
+               /* try to set the interface... */
+               usb_set_interface(chip->dev, iface_no, altno);
+               snd_usb_init_pitch(chip, iface_no, alts, fp);
+               snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
+       }
+       return 0;
+}
+
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
new file mode 100644 (file)
index 0000000..64dd0db
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __USBAUDIO_ENDPOINT_H
+#define __USBAUDIO_ENDPOINT_H
+
+int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip,
+                                 int iface_no);
+
+int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip,
+                              int stream,
+                              struct audioformat *fp);
+
+#endif /* __USBAUDIO_ENDPOINT_H */
diff --git a/sound/usb/format.c b/sound/usb/format.c
new file mode 100644 (file)
index 0000000..b87cf87
--- /dev/null
@@ -0,0 +1,432 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "quirks.h"
+#include "helper.h"
+#include "debug.h"
+
+/*
+ * parse the audio format type I descriptor
+ * and returns the corresponding pcm format
+ *
+ * @dev: usb device
+ * @fp: audioformat record
+ * @format: the format tag (wFormatTag)
+ * @fmt: the format type descriptor
+ */
+static u64 parse_audio_format_i_type(struct snd_usb_audio *chip,
+                                    struct audioformat *fp,
+                                    int format, void *_fmt,
+                                    int protocol)
+{
+       int sample_width, sample_bytes;
+       u64 pcm_formats;
+
+       switch (protocol) {
+       case UAC_VERSION_1: {
+               struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
+               sample_width = fmt->bBitResolution;
+               sample_bytes = fmt->bSubframeSize;
+               format = 1 << format;
+               break;
+       }
+
+       case UAC_VERSION_2: {
+               struct uac_format_type_i_ext_descriptor *fmt = _fmt;
+               sample_width = fmt->bBitResolution;
+               sample_bytes = fmt->bSubslotSize;
+               format <<= 1;
+               break;
+       }
+
+       default:
+               return -EINVAL;
+       }
+
+       pcm_formats = 0;
+
+       if (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED)) {
+               /* some devices don't define this correctly... */
+               snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
+                           chip->dev->devnum, fp->iface, fp->altsetting);
+               format = 1 << UAC_FORMAT_TYPE_I_PCM;
+       }
+       if (format & (1 << UAC_FORMAT_TYPE_I_PCM)) {
+               if (sample_width > sample_bytes * 8) {
+                       snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
+                                  chip->dev->devnum, fp->iface, fp->altsetting,
+                                  sample_width, sample_bytes);
+               }
+               /* check the format byte size */
+               switch (sample_bytes) {
+               case 1:
+                       pcm_formats |= SNDRV_PCM_FMTBIT_S8;
+                       break;
+               case 2:
+                       if (snd_usb_is_big_endian_format(chip, fp))
+                               pcm_formats |= SNDRV_PCM_FMTBIT_S16_BE; /* grrr, big endian!! */
+                       else
+                               pcm_formats |= SNDRV_PCM_FMTBIT_S16_LE;
+                       break;
+               case 3:
+                       if (snd_usb_is_big_endian_format(chip, fp))
+                               pcm_formats |= SNDRV_PCM_FMTBIT_S24_3BE; /* grrr, big endian!! */
+                       else
+                               pcm_formats |= SNDRV_PCM_FMTBIT_S24_3LE;
+                       break;
+               case 4:
+                       pcm_formats |= SNDRV_PCM_FMTBIT_S32_LE;
+                       break;
+               default:
+                       snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
+                                  chip->dev->devnum, fp->iface, fp->altsetting,
+                                  sample_width, sample_bytes);
+                       break;
+               }
+       }
+       if (format & (1 << UAC_FORMAT_TYPE_I_PCM8)) {
+               /* Dallas DS4201 workaround: it advertises U8 format, but really
+                  supports S8. */
+               if (chip->usb_id == USB_ID(0x04fa, 0x4201))
+                       pcm_formats |= SNDRV_PCM_FMTBIT_S8;
+               else
+                       pcm_formats |= SNDRV_PCM_FMTBIT_U8;
+       }
+       if (format & (1 << UAC_FORMAT_TYPE_I_IEEE_FLOAT)) {
+               pcm_formats |= SNDRV_PCM_FMTBIT_FLOAT_LE;
+       }
+       if (format & (1 << UAC_FORMAT_TYPE_I_ALAW)) {
+               pcm_formats |= SNDRV_PCM_FMTBIT_A_LAW;
+       }
+       if (format & (1 << UAC_FORMAT_TYPE_I_MULAW)) {
+               pcm_formats |= SNDRV_PCM_FMTBIT_MU_LAW;
+       }
+       if (format & ~0x3f) {
+               snd_printk(KERN_INFO "%d:%u:%d : unsupported format bits %#x\n",
+                          chip->dev->devnum, fp->iface, fp->altsetting, format);
+       }
+       return pcm_formats;
+}
+
+
+/*
+ * parse the format descriptor and stores the possible sample rates
+ * on the audioformat table (audio class v1).
+ *
+ * @dev: usb device
+ * @fp: audioformat record
+ * @fmt: the format descriptor
+ * @offset: the start offset of descriptor pointing the rate type
+ *          (7 for type I and II, 8 for type II)
+ */
+static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
+                                      unsigned char *fmt, int offset)
+{
+       int nr_rates = fmt[offset];
+
+       if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
+               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
+                                  chip->dev->devnum, fp->iface, fp->altsetting);
+               return -1;
+       }
+
+       if (nr_rates) {
+               /*
+                * build the rate table and bitmap flags
+                */
+               int r, idx;
+
+               fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
+               if (fp->rate_table == NULL) {
+                       snd_printk(KERN_ERR "cannot malloc\n");
+                       return -1;
+               }
+
+               fp->nr_rates = 0;
+               fp->rate_min = fp->rate_max = 0;
+               for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
+                       unsigned int rate = combine_triple(&fmt[idx]);
+                       if (!rate)
+                               continue;
+                       /* C-Media CM6501 mislabels its 96 kHz altsetting */
+                       if (rate == 48000 && nr_rates == 1 &&
+                           (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
+                            chip->usb_id == USB_ID(0x0d8c, 0x0102)) &&
+                           fp->altsetting == 5 && fp->maxpacksize == 392)
+                               rate = 96000;
+                       /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */
+                       if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068))
+                               rate = 8000;
+
+                       fp->rate_table[fp->nr_rates] = rate;
+                       if (!fp->rate_min || rate < fp->rate_min)
+                               fp->rate_min = rate;
+                       if (!fp->rate_max || rate > fp->rate_max)
+                               fp->rate_max = rate;
+                       fp->rates |= snd_pcm_rate_to_rate_bit(rate);
+                       fp->nr_rates++;
+               }
+               if (!fp->nr_rates) {
+                       hwc_debug("All rates were zero. Skipping format!\n");
+                       return -1;
+               }
+       } else {
+               /* continuous rates */
+               fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
+               fp->rate_min = combine_triple(&fmt[offset + 1]);
+               fp->rate_max = combine_triple(&fmt[offset + 4]);
+       }
+       return 0;
+}
+
+/*
+ * parse the format descriptor and stores the possible sample rates
+ * on the audioformat table (audio class v2).
+ */
+static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
+                                      struct audioformat *fp,
+                                      struct usb_host_interface *iface)
+{
+       struct usb_device *dev = chip->dev;
+       unsigned char tmp[2], *data;
+       int i, nr_rates, data_size, ret = 0;
+
+       /* get the number of sample rates first by only fetching 2 bytes */
+       ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
+                             USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+                             UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
+                             tmp, sizeof(tmp), 1000);
+
+       if (ret < 0) {
+               snd_printk(KERN_ERR "unable to retrieve number of sample rates\n");
+               goto err;
+       }
+
+       nr_rates = (tmp[1] << 8) | tmp[0];
+       data_size = 2 + 12 * nr_rates;
+       data = kzalloc(data_size, GFP_KERNEL);
+       if (!data) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       /* now get the full information */
+       ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
+                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+                              UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
+                              data, data_size, 1000);
+
+       if (ret < 0) {
+               snd_printk(KERN_ERR "unable to retrieve sample rate range\n");
+               ret = -EINVAL;
+               goto err_free;
+       }
+
+       fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
+       if (!fp->rate_table) {
+               ret = -ENOMEM;
+               goto err_free;
+       }
+
+       fp->nr_rates = 0;
+       fp->rate_min = fp->rate_max = 0;
+
+       for (i = 0; i < nr_rates; i++) {
+               int rate = combine_quad(&data[2 + 12 * i]);
+
+               fp->rate_table[fp->nr_rates] = rate;
+               if (!fp->rate_min || rate < fp->rate_min)
+                       fp->rate_min = rate;
+               if (!fp->rate_max || rate > fp->rate_max)
+                       fp->rate_max = rate;
+               fp->rates |= snd_pcm_rate_to_rate_bit(rate);
+               fp->nr_rates++;
+       }
+
+err_free:
+       kfree(data);
+err:
+       return ret;
+}
+
+/*
+ * parse the format type I and III descriptors
+ */
+static int parse_audio_format_i(struct snd_usb_audio *chip,
+                               struct audioformat *fp,
+                               int format, void *_fmt,
+                               struct usb_host_interface *iface)
+{
+       struct usb_interface_descriptor *altsd = get_iface_desc(iface);
+       struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
+       int protocol = altsd->bInterfaceProtocol;
+       int pcm_format, ret;
+
+       if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
+               /* FIXME: the format type is really IECxxx
+                *        but we give normal PCM format to get the existing
+                *        apps working...
+                */
+               switch (chip->usb_id) {
+
+               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
+                       if (chip->setup == 0x00 && 
+                           fp->altsetting == 6)
+                               pcm_format = SNDRV_PCM_FORMAT_S16_BE;
+                       else
+                               pcm_format = SNDRV_PCM_FORMAT_S16_LE;
+                       break;
+               default:
+                       pcm_format = SNDRV_PCM_FORMAT_S16_LE;
+               }
+               fp->formats = 1uLL << pcm_format;
+       } else {
+               fp->formats = parse_audio_format_i_type(chip, fp, format,
+                                                       fmt, protocol);
+               if (!fp->formats)
+                       return -1;
+       }
+
+       /* gather possible sample rates */
+       /* audio class v1 reports possible sample rates as part of the
+        * proprietary class specific descriptor.
+        * audio class v2 uses class specific EP0 range requests for that.
+        */
+       switch (protocol) {
+       case UAC_VERSION_1:
+               fp->channels = fmt->bNrChannels;
+               ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7);
+               break;
+       case UAC_VERSION_2:
+               /* fp->channels is already set in this case */
+               ret = parse_audio_format_rates_v2(chip, fp, iface);
+               break;
+       }
+
+       if (fp->channels < 1) {
+               snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
+                          chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
+               return -1;
+       }
+
+       return ret;
+}
+
+/*
+ * parse the format type II descriptor
+ */
+static int parse_audio_format_ii(struct snd_usb_audio *chip,
+                                struct audioformat *fp,
+                                int format, void *_fmt,
+                                struct usb_host_interface *iface)
+{
+       int brate, framesize, ret;
+       struct usb_interface_descriptor *altsd = get_iface_desc(iface);
+       int protocol = altsd->bInterfaceProtocol;
+
+       switch (format) {
+       case UAC_FORMAT_TYPE_II_AC3:
+               /* FIXME: there is no AC3 format defined yet */
+               // fp->formats = SNDRV_PCM_FMTBIT_AC3;
+               fp->formats = SNDRV_PCM_FMTBIT_U8; /* temporary hack to receive byte streams */
+               break;
+       case UAC_FORMAT_TYPE_II_MPEG:
+               fp->formats = SNDRV_PCM_FMTBIT_MPEG;
+               break;
+       default:
+               snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected.  processed as MPEG.\n",
+                          chip->dev->devnum, fp->iface, fp->altsetting, format);
+               fp->formats = SNDRV_PCM_FMTBIT_MPEG;
+               break;
+       }
+
+       fp->channels = 1;
+
+       switch (protocol) {
+       case UAC_VERSION_1: {
+               struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
+               brate = le16_to_cpu(fmt->wMaxBitRate);
+               framesize = le16_to_cpu(fmt->wSamplesPerFrame);
+               snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
+               fp->frame_size = framesize;
+               ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
+               break;
+       }
+       case UAC_VERSION_2: {
+               struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
+               brate = le16_to_cpu(fmt->wMaxBitRate);
+               framesize = le16_to_cpu(fmt->wSamplesPerFrame);
+               snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
+               fp->frame_size = framesize;
+               ret = parse_audio_format_rates_v2(chip, fp, iface);
+               break;
+       }
+       }
+
+       return ret;
+}
+
+int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
+                      int format, unsigned char *fmt, int stream,
+                      struct usb_host_interface *iface)
+{
+       int err;
+
+       switch (fmt[3]) {
+       case UAC_FORMAT_TYPE_I:
+       case UAC_FORMAT_TYPE_III:
+               err = parse_audio_format_i(chip, fp, format, fmt, iface);
+               break;
+       case UAC_FORMAT_TYPE_II:
+               err = parse_audio_format_ii(chip, fp, format, fmt, iface);
+               break;
+       default:
+               snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
+                          chip->dev->devnum, fp->iface, fp->altsetting, fmt[3]);
+               return -1;
+       }
+       fp->fmt_type = fmt[3];
+       if (err < 0)
+               return err;
+#if 1
+       /* FIXME: temporary hack for extigy/audigy 2 nx/zs */
+       /* extigy apparently supports sample rates other than 48k
+        * but not in ordinary way.  so we enable only 48k atm.
+        */
+       if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
+           chip->usb_id == USB_ID(0x041e, 0x3020) ||
+           chip->usb_id == USB_ID(0x041e, 0x3061)) {
+               if (fmt[3] == UAC_FORMAT_TYPE_I &&
+                   fp->rates != SNDRV_PCM_RATE_48000 &&
+                   fp->rates != SNDRV_PCM_RATE_96000)
+                       return -1;
+       }
+#endif
+       return 0;
+}
+
diff --git a/sound/usb/format.h b/sound/usb/format.h
new file mode 100644 (file)
index 0000000..8298c4e
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __USBAUDIO_FORMAT_H
+#define __USBAUDIO_FORMAT_H
+
+int snd_usb_parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
+                              int format, unsigned char *fmt, int stream,
+                              struct usb_host_interface *iface);
+
+#endif /*  __USBAUDIO_FORMAT_H */
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
new file mode 100644 (file)
index 0000000..d48d6f8
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#include "usbaudio.h"
+#include "helper.h"
+
+/*
+ * combine bytes and get an integer value
+ */
+unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size)
+{
+       switch (size) {
+       case 1:  return *bytes;
+       case 2:  return combine_word(bytes);
+       case 3:  return combine_triple(bytes);
+       case 4:  return combine_quad(bytes);
+       default: return 0;
+       }
+}
+
+/*
+ * parse descriptor buffer and return the pointer starting the given
+ * descriptor type.
+ */
+void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype)
+{
+       u8 *p, *end, *next;
+
+       p = descstart;
+       end = p + desclen;
+       for (; p < end;) {
+               if (p[0] < 2)
+                       return NULL;
+               next = p + p[0];
+               if (next > end)
+                       return NULL;
+               if (p[1] == dtype && (!after || (void *)p > after)) {
+                       return p;
+               }
+               p = next;
+       }
+       return NULL;
+}
+
+/*
+ * find a class-specified interface descriptor with the given subtype.
+ */
+void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype)
+{
+       unsigned char *p = after;
+
+       while ((p = snd_usb_find_desc(buffer, buflen, p,
+                                     USB_DT_CS_INTERFACE)) != NULL) {
+               if (p[0] >= 3 && p[2] == dsubtype)
+                       return p;
+       }
+       return NULL;
+}
+
+/*
+ * Wrapper for usb_control_msg().
+ * Allocates a temp buffer to prevent dmaing from/to the stack.
+ */
+int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
+                   __u8 requesttype, __u16 value, __u16 index, void *data,
+                   __u16 size, int timeout)
+{
+       int err;
+       void *buf = NULL;
+
+       if (size > 0) {
+               buf = kmemdup(data, size, GFP_KERNEL);
+               if (!buf)
+                       return -ENOMEM;
+       }
+       err = usb_control_msg(dev, pipe, request, requesttype,
+                             value, index, buf, size, timeout);
+       if (size > 0) {
+               memcpy(data, buf, size);
+               kfree(buf);
+       }
+       return err;
+}
+
+unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
+                                        struct usb_host_interface *alts)
+{
+       if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH &&
+           get_endpoint(alts, 0)->bInterval >= 1 &&
+           get_endpoint(alts, 0)->bInterval <= 4)
+               return get_endpoint(alts, 0)->bInterval - 1;
+       else
+               return 0;
+}
+
diff --git a/sound/usb/helper.h b/sound/usb/helper.h
new file mode 100644 (file)
index 0000000..a6b0e51
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __USBAUDIO_HELPER_H
+#define __USBAUDIO_HELPER_H
+
+unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size);
+
+void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype);
+void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype);
+
+int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
+                   __u8 request, __u8 requesttype, __u16 value, __u16 index,
+                   void *data, __u16 size, int timeout);
+
+unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
+                                        struct usb_host_interface *alts);
+
+/*
+ * retrieve usb_interface descriptor from the host interface
+ * (conditional for compatibility with the older API)
+ */
+#ifndef get_iface_desc
+#define get_iface_desc(iface)  (&(iface)->desc)
+#define get_endpoint(alt,ep)   (&(alt)->endpoint[ep].desc)
+#define get_ep_desc(ep)                (&(ep)->desc)
+#define get_cfg_desc(cfg)      (&(cfg)->desc)
+#endif
+
+#ifndef snd_usb_get_speed
+#define snd_usb_get_speed(dev) ((dev)->speed)
+#endif
+
+
+#endif /* __USBAUDIO_HELPER_H */
similarity index 99%
rename from sound/usb/usbmidi.c
rename to sound/usb/midi.c
index 9e28b20..2c1558c 100644 (file)
@@ -53,7 +53,8 @@
 #include <sound/rawmidi.h>
 #include <sound/asequencer.h>
 #include "usbaudio.h"
-
+#include "midi.h"
+#include "helper.h"
 
 /*
  * define this to log all USB packets
diff --git a/sound/usb/midi.h b/sound/usb/midi.h
new file mode 100644 (file)
index 0000000..2089ec9
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef __USBMIDI_H
+#define __USBMIDI_H
+
+/* maximum number of endpoints per interface */
+#define MIDI_MAX_ENDPOINTS 2
+
+/* data for QUIRK_MIDI_FIXED_ENDPOINT */
+struct snd_usb_midi_endpoint_info {
+       int8_t   out_ep;        /* ep number, 0 autodetect */
+       uint8_t  out_interval;  /* interval for interrupt endpoints */
+       int8_t   in_ep;
+       uint8_t  in_interval;
+       uint16_t out_cables;    /* bitmask */
+       uint16_t in_cables;     /* bitmask */
+};
+
+/* for QUIRK_MIDI_YAMAHA, data is NULL */
+
+/* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info
+ * structure (out_cables and in_cables only) */
+
+/* for QUIRK_COMPOSITE, data points to an array of snd_usb_audio_quirk
+ * structures, terminated with .ifnum = -1 */
+
+/* for QUIRK_AUDIO_FIXED_ENDPOINT, data points to an audioformat structure */
+
+/* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */
+
+/* for QUIRK_AUDIO_EDIROL_UA700_UA25/UA1000, data is NULL */
+
+/* for QUIRK_IGNORE_INTERFACE, data is NULL */
+
+/* for QUIRK_MIDI_NOVATION and _RAW, data is NULL */
+
+/* for QUIRK_MIDI_EMAGIC, data points to a snd_usb_midi_endpoint_info
+ * structure (out_cables and in_cables only) */
+
+/* for QUIRK_MIDI_CME, data is NULL */
+
+int snd_usbmidi_create(struct snd_card *card,
+                      struct usb_interface *iface,
+                      struct list_head *midi_list,
+                      const struct snd_usb_audio_quirk *quirk);
+void snd_usbmidi_input_stop(struct list_head* p);
+void snd_usbmidi_input_start(struct list_head* p);
+void snd_usbmidi_disconnect(struct list_head *p);
+
+#endif /* __USBMIDI_H */
diff --git a/sound/usb/misc/Makefile b/sound/usb/misc/Makefile
new file mode 100644 (file)
index 0000000..ccefd81
--- /dev/null
@@ -0,0 +1,2 @@
+snd-ua101-objs := ua101.o
+obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o
similarity index 99%
rename from sound/usb/ua101.c
rename to sound/usb/misc/ua101.c
index 3d458d3..796d8b2 100644 (file)
@@ -23,7 +23,8 @@
 #include <sound/initval.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
-#include "usbaudio.h"
+#include "../usbaudio.h"
+#include "../midi.h"
 
 MODULE_DESCRIPTION("Edirol UA-101/1000 driver");
 MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
similarity index 72%
rename from sound/usb/usbmixer.c
rename to sound/usb/mixer.c
index 8e8f871..97dd176 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/string.h>
 #include <linux/usb.h>
 #include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
 
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/tlv.h>
 
 #include "usbaudio.h"
-
-/*
- */
-
-/* ignore error from controls - for debugging */
-/* #define IGNORE_CTL_ERROR */
-
-/*
- * Sound Blaster remote control configuration
- *
- * format of remote control data:
- * Extigy:       xx 00
- * Audigy 2 NX:  06 80 xx 00 00 00
- * Live! 24-bit: 06 80 xx yy 22 83
- */
-static const struct rc_config {
-       u32 usb_id;
-       u8  offset;
-       u8  length;
-       u8  packet_length;
-       u8  min_packet_length; /* minimum accepted length of the URB result */
-       u8  mute_mixer_id;
-       u32 mute_code;
-} rc_configs[] = {
-       { USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
-       { USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
-       { USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
-       { USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
-};
+#include "mixer.h"
+#include "helper.h"
+#include "mixer_quirks.h"
 
 #define MAX_ID_ELEMS   256
 
-struct usb_mixer_interface {
-       struct snd_usb_audio *chip;
-       unsigned int ctrlif;
-       struct list_head list;
-       unsigned int ignore_ctl_error;
-       struct urb *urb;
-       /* array[MAX_ID_ELEMS], indexed by unit id */
-       struct usb_mixer_elem_info **id_elems;
-
-       /* Sound Blaster remote control stuff */
-       const struct rc_config *rc_cfg;
-       u32 rc_code;
-       wait_queue_head_t rc_waitq;
-       struct urb *rc_urb;
-       struct usb_ctrlrequest *rc_setup_packet;
-       u8 rc_buffer[6];
-
-       u8 audigy2nx_leds[3];
-       u8 xonar_u1_status;
-};
-
-
 struct usb_audio_term {
        int id;
        int type;
@@ -116,39 +69,6 @@ struct mixer_build {
        const struct usbmix_selector_map *selector_map;
 };
 
-#define MAX_CHANNELS   10      /* max logical channels */
-
-struct usb_mixer_elem_info {
-       struct usb_mixer_interface *mixer;
-       struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
-       struct snd_ctl_elem_id *elem_id;
-       unsigned int id;
-       unsigned int control;   /* CS or ICN (high byte) */
-       unsigned int cmask; /* channel mask bitmap: 0 = master */
-       int channels;
-       int val_type;
-       int min, max, res;
-       int dBmin, dBmax;
-       int cached;
-       int cache_val[MAX_CHANNELS];
-       u8 initialized;
-};
-
-
-enum {
-       USB_FEATURE_NONE = 0,
-       USB_FEATURE_MUTE = 1,
-       USB_FEATURE_VOLUME,
-       USB_FEATURE_BASS,
-       USB_FEATURE_MID,
-       USB_FEATURE_TREBLE,
-       USB_FEATURE_GEQ,
-       USB_FEATURE_AGC,
-       USB_FEATURE_DELAY,
-       USB_FEATURE_BASSBOOST,
-       USB_FEATURE_LOUDNESS
-};
-
 enum {
        USB_MIXER_BOOLEAN,
        USB_MIXER_INV_BOOLEAN,
@@ -213,7 +133,7 @@ enum {
  * if the mixer topology is too complicated and the parsed names are
  * ambiguous, add the entries in usbmixer_maps.c.
  */
-#include "usbmixer_maps.c"
+#include "mixer_maps.c"
 
 static const struct usbmix_name_map *
 find_map(struct mixer_build *state, int unitid, int control)
@@ -278,6 +198,7 @@ static int check_mapped_selector_name(struct mixer_build *state, int unitid,
 
 /*
  * find an audio control unit with the given unit id
+ * this doesn't return any clock related units, so they need to be handled elsewhere
  */
 static void *find_audio_control_unit(struct mixer_build *state, unsigned char unit)
 {
@@ -286,7 +207,7 @@ static void *find_audio_control_unit(struct mixer_build *state, unsigned char un
        p = NULL;
        while ((p = snd_usb_find_desc(state->buffer, state->buflen, p,
                                      USB_DT_CS_INTERFACE)) != NULL) {
-               if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC_EXTENSION_UNIT_V1 && p[3] == unit)
+               if (p[0] >= 4 && p[2] >= UAC_INPUT_TERMINAL && p[2] <= UAC2_EXTENSION_UNIT_V2 && p[3] == unit)
                        return p;
        }
        return NULL;
@@ -383,7 +304,7 @@ static int get_abs_value(struct usb_mixer_elem_info *cval, int val)
  * retrieve a mixer value
  */
 
-static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
+static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
 {
        unsigned char buf[2];
        int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
@@ -405,6 +326,58 @@ static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
        return -EINVAL;
 }
 
+static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
+{
+       unsigned char buf[14]; /* enough space for one range of 4 bytes */
+       unsigned char *val;
+       int ret;
+       __u8 bRequest;
+
+       bRequest = (request == UAC_GET_CUR) ?
+               UAC2_CS_CUR : UAC2_CS_RANGE;
+
+       ret = snd_usb_ctl_msg(cval->mixer->chip->dev,
+                             usb_rcvctrlpipe(cval->mixer->chip->dev, 0),
+                             bRequest,
+                             USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
+                             validx, cval->mixer->ctrlif | (cval->id << 8),
+                             buf, sizeof(buf), 1000);
+
+       if (ret < 0) {
+               snd_printdd(KERN_ERR "cannot get ctl value: req = %#x, wValue = %#x, wIndex = %#x, type = %d\n",
+                           request, validx, cval->mixer->ctrlif | (cval->id << 8), cval->val_type);
+               return ret;
+       }
+
+       switch (request) {
+       case UAC_GET_CUR:
+               val = buf;
+               break;
+       case UAC_GET_MIN:
+               val = buf + sizeof(__u16);
+               break;
+       case UAC_GET_MAX:
+               val = buf + sizeof(__u16) * 2;
+               break;
+       case UAC_GET_RES:
+               val = buf + sizeof(__u16) * 3;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(val, sizeof(__u16)));
+
+       return 0;
+}
+
+static int get_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int *value_ret)
+{
+       return (cval->mixer->protocol == UAC_VERSION_1) ?
+               get_ctl_value_v1(cval, request, validx, value_ret) :
+               get_ctl_value_v2(cval, request, validx, value_ret);
+}
+
 static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *value)
 {
        return get_ctl_value(cval, UAC_GET_CUR, validx, value);
@@ -429,8 +402,7 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
        err = get_cur_mix_raw(cval, channel, value);
        if (err < 0) {
                if (!cval->mixer->ignore_ctl_error)
-                       snd_printd(KERN_ERR "cannot get current value for "
-                                  "control %d ch %d: err = %d\n",
+                       snd_printd(KERN_ERR "cannot get current value for control %d ch %d: err = %d\n",
                                   cval->control, channel, err);
                return err;
        }
@@ -444,11 +416,26 @@ static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
  * set a mixer value
  */
 
-static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int validx, int value_set)
+int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
+                               int request, int validx, int value_set)
 {
        unsigned char buf[2];
-       int val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
-       int timeout = 10;
+       int val_len, timeout = 10;
+
+       if (cval->mixer->protocol == UAC_VERSION_1) {
+               val_len = cval->val_type >= USB_MIXER_S16 ? 2 : 1;
+       } else { /* UAC_VERSION_2 */
+               /* audio class v2 controls are always 2 bytes in size */
+               val_len = sizeof(__u16);
+
+               /* FIXME */
+               if (request != UAC_SET_CUR) {
+                       snd_printdd(KERN_WARNING "RANGE setting not yet supported\n");
+                       return -EINVAL;
+               }
+
+               request = UAC2_CS_CUR;
+       }
 
        value_set = convert_bytes_value(cval, value_set);
        buf[0] = value_set & 0xff;
@@ -468,14 +455,14 @@ static int set_ctl_value(struct usb_mixer_elem_info *cval, int request, int vali
 
 static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int value)
 {
-       return set_ctl_value(cval, UAC_SET_CUR, validx, value);
+       return snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, validx, value);
 }
 
 static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
                             int index, int value)
 {
        int err;
-       err = set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel,
+       err = snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR, (cval->control << 8) | channel,
                            value);
        if (err < 0)
                return err;
@@ -644,46 +631,65 @@ static int get_term_name(struct mixer_build *state, struct usb_audio_term *iterm
  */
 static int check_input_term(struct mixer_build *state, int id, struct usb_audio_term *term)
 {
-       unsigned char *p1;
+       void *p1;
 
        memset(term, 0, sizeof(*term));
        while ((p1 = find_audio_control_unit(state, id)) != NULL) {
+               unsigned char *hdr = p1;
                term->id = id;
-               switch (p1[2]) {
+               switch (hdr[2]) {
                case UAC_INPUT_TERMINAL:
-                       term->type = combine_word(p1 + 4);
-                       term->channels = p1[7];
-                       term->chconfig = combine_word(p1 + 8);
-                       term->name = p1[11];
+                       if (state->mixer->protocol == UAC_VERSION_1) {
+                               struct uac_input_terminal_descriptor *d = p1;
+                               term->type = le16_to_cpu(d->wTerminalType);
+                               term->channels = d->bNrChannels;
+                               term->chconfig = le16_to_cpu(d->wChannelConfig);
+                               term->name = d->iTerminal;
+                       } else { /* UAC_VERSION_2 */
+                               struct uac2_input_terminal_descriptor *d = p1;
+                               term->type = le16_to_cpu(d->wTerminalType);
+                               term->channels = d->bNrChannels;
+                               term->chconfig = le32_to_cpu(d->bmChannelConfig);
+                               term->name = d->iTerminal;
+                       }
                        return 0;
-               case UAC_FEATURE_UNIT:
-                       id = p1[4];
+               case UAC_FEATURE_UNIT: {
+                       /* the header is the same for v1 and v2 */
+                       struct uac_feature_unit_descriptor *d = p1;
+                       id = d->bSourceID;
                        break; /* continue to parse */
-               case UAC_MIXER_UNIT:
-                       term->type = p1[2] << 16; /* virtual type */
-                       term->channels = p1[5 + p1[4]];
-                       term->chconfig = combine_word(p1 + 6 + p1[4]);
-                       term->name = p1[p1[0] - 1];
+               }
+               case UAC_MIXER_UNIT: {
+                       struct uac_mixer_unit_descriptor *d = p1;
+                       term->type = d->bDescriptorSubtype << 16; /* virtual type */
+                       term->channels = uac_mixer_unit_bNrChannels(d);
+                       term->chconfig = uac_mixer_unit_wChannelConfig(d, state->mixer->protocol);
+                       term->name = uac_mixer_unit_iMixer(d);
                        return 0;
-               case UAC_SELECTOR_UNIT:
+               }
+               case UAC_SELECTOR_UNIT: {
+                       struct uac_selector_unit_descriptor *d = p1;
                        /* call recursively to retrieve the channel info */
-                       if (check_input_term(state, p1[5], term) < 0)
+                       if (check_input_term(state, d->baSourceID[0], term) < 0)
                                return -ENODEV;
-                       term->type = p1[2] << 16; /* virtual type */
+                       term->type = d->bDescriptorSubtype << 16; /* virtual type */
                        term->id = id;
-                       term->name = p1[9 + p1[0] - 1];
+                       term->name = uac_selector_unit_iSelector(d);
                        return 0;
+               }
                case UAC_PROCESSING_UNIT_V1:
-               case UAC_EXTENSION_UNIT_V1:
-                       if (p1[6] == 1) {
-                               id = p1[7];
+               case UAC_EXTENSION_UNIT_V1: {
+                       struct uac_processing_unit_descriptor *d = p1;
+                       if (d->bNrInPins) {
+                               id = d->baSourceID[0];
                                break; /* continue to parse */
                        }
-                       term->type = p1[2] << 16; /* virtual type */
-                       term->channels = p1[7 + p1[6]];
-                       term->chconfig = combine_word(p1 + 8 + p1[6]);
-                       term->name = p1[12 + p1[6] + p1[11 + p1[6]]];
+                       term->type = d->bDescriptorSubtype << 16; /* virtual type */
+                       term->channels = uac_processing_unit_bNrChannels(d);
+                       term->chconfig = uac_processing_unit_wChannelConfig(d, state->mixer->protocol);
+                       term->name = uac_processing_unit_iProcessing(d, state->mixer->protocol);
                        return 0;
+               }
                default:
                        return -ENODEV;
                }
@@ -764,7 +770,8 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
                        int last_valid_res = cval->res;
 
                        while (cval->res > 1) {
-                               if (set_ctl_value(cval, UAC_SET_RES, (cval->control << 8) | minchn, cval->res / 2) < 0)
+                               if (snd_usb_mixer_set_ctl_value(cval, UAC_SET_RES,
+                                                               (cval->control << 8) | minchn, cval->res / 2) < 0)
                                        break;
                                cval->res /= 2;
                        }
@@ -929,6 +936,15 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = {
        .put = mixer_ctl_feature_put,
 };
 
+/* the read-only variant */
+static struct snd_kcontrol_new usb_feature_unit_ctl_ro = {
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "", /* will be filled later manually */
+       .info = mixer_ctl_feature_info,
+       .get = mixer_ctl_feature_get,
+       .put = NULL,
+};
+
 
 /*
  * build a feature control
@@ -939,20 +955,22 @@ static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
        return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
 }
 
-static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
+static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
                              unsigned int ctl_mask, int control,
-                             struct usb_audio_term *iterm, int unitid)
+                             struct usb_audio_term *iterm, int unitid,
+                             int read_only)
 {
+       struct uac_feature_unit_descriptor *desc = raw_desc;
        unsigned int len = 0;
        int mapped_name = 0;
-       int nameid = desc[desc[0] - 1];
+       int nameid = uac_feature_unit_iFeature(desc);
        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 */
 
-       if (control == USB_FEATURE_GEQ) {
+       if (control == UAC_GRAPHIC_EQUALIZER_CONTROL) {
                /* FIXME: not supported yet */
                return;
        }
@@ -984,7 +1002,11 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
        /* get min/max values */
        get_min_max(cval, 0);
 
-       kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
+       if (read_only)
+               kctl = snd_ctl_new1(&usb_feature_unit_ctl_ro, cval);
+       else
+               kctl = snd_ctl_new1(&usb_feature_unit_ctl, cval);
+
        if (! kctl) {
                snd_printk(KERN_ERR "cannot malloc kcontrol\n");
                kfree(cval);
@@ -999,8 +1021,8 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
                                kctl->id.name, sizeof(kctl->id.name));
 
        switch (control) {
-       case USB_FEATURE_MUTE:
-       case USB_FEATURE_VOLUME:
+       case UAC_MUTE_CONTROL:
+       case UAC_VOLUME_CONTROL:
                /* determine the control name.  the rule is:
                 * - if a name id is given in descriptor, use it.
                 * - if the connected input can be determined, then use the name
@@ -1027,9 +1049,9 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
                                len = append_ctl_name(kctl, " Playback");
                        }
                }
-               append_ctl_name(kctl, control == USB_FEATURE_MUTE ?
+               append_ctl_name(kctl, control == UAC_MUTE_CONTROL ?
                                " Switch" : " Volume");
-               if (control == USB_FEATURE_VOLUME) {
+               if (control == UAC_VOLUME_CONTROL) {
                        kctl->tlv.c = mixer_vol_tlv;
                        kctl->vd[0].access |= 
                                SNDRV_CTL_ELEM_ACCESS_TLV_READ |
@@ -1094,49 +1116,92 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
        struct usb_audio_term iterm;
        unsigned int master_bits, first_ch_bits;
        int err, csize;
-       struct uac_feature_unit_descriptor *ftr = _ftr;
+       struct uac_feature_unit_descriptor *hdr = _ftr;
+       __u8 *bmaControls;
 
-       if (ftr->bLength < 7 || ! (csize = ftr->bControlSize) || ftr->bLength < 7 + csize) {
+       if (state->mixer->protocol == UAC_VERSION_1) {
+               csize = hdr->bControlSize;
+               channels = (hdr->bLength - 7) / csize - 1;
+               bmaControls = hdr->bmaControls;
+       } else {
+               struct uac2_feature_unit_descriptor *ftr = _ftr;
+               csize = 4;
+               channels = (hdr->bLength - 6) / 4;
+               bmaControls = ftr->bmaControls;
+       }
+
+       if (hdr->bLength < 7 || !csize || hdr->bLength < 7 + csize) {
                snd_printk(KERN_ERR "usbaudio: unit %u: invalid UAC_FEATURE_UNIT descriptor\n", unitid);
                return -EINVAL;
        }
 
        /* parse the source unit */
-       if ((err = parse_audio_unit(state, ftr->bSourceID)) < 0)
+       if ((err = parse_audio_unit(state, hdr->bSourceID)) < 0)
                return err;
 
        /* determine the input source type and name */
-       if (check_input_term(state, ftr->bSourceID, &iterm) < 0)
+       if (check_input_term(state, hdr->bSourceID, &iterm) < 0)
                return -EINVAL;
 
-       channels = (ftr->bLength - 7) / csize - 1;
-
-       master_bits = snd_usb_combine_bytes(ftr->controls, csize);
+       master_bits = snd_usb_combine_bytes(bmaControls, csize);
        /* master configuration quirks */
        switch (state->chip->usb_id) {
        case USB_ID(0x08bb, 0x2702):
                snd_printk(KERN_INFO
                           "usbmixer: master volume quirk for PCM2702 chip\n");
                /* disable non-functional volume control */
-               master_bits &= ~(1 << (USB_FEATURE_VOLUME - 1));
+               master_bits &= ~UAC_FU_VOLUME;
                break;
        }
        if (channels > 0)
-               first_ch_bits = snd_usb_combine_bytes(ftr->controls + csize, csize);
+               first_ch_bits = snd_usb_combine_bytes(bmaControls + csize, csize);
        else
                first_ch_bits = 0;
-       /* check all control types */
-       for (i = 0; i < 10; i++) {
-               unsigned int ch_bits = 0;
-               for (j = 0; j < channels; j++) {
-                       unsigned int mask = snd_usb_combine_bytes(ftr->controls + csize * (j+1), csize);
-                       if (mask & (1 << i))
-                               ch_bits |= (1 << j);
+
+       if (state->mixer->protocol == UAC_VERSION_1) {
+               /* check all control types */
+               for (i = 0; i < 10; i++) {
+                       unsigned int ch_bits = 0;
+                       for (j = 0; j < channels; j++) {
+                               unsigned int mask = snd_usb_combine_bytes(bmaControls + csize * (j+1), csize);
+                               if (mask & (1 << i))
+                                       ch_bits |= (1 << j);
+                       }
+                       /* audio class v1 controls are never read-only */
+                       if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
+                               build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid, 0);
+                       if (master_bits & (1 << i))
+                               build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0);
+               }
+       } else { /* UAC_VERSION_2 */
+               for (i = 0; i < 30/2; i++) {
+                       /* From the USB Audio spec v2.0:
+                          bmaControls() is a (ch+1)-element array of 4-byte bitmaps,
+                          each containing a set of bit pairs. If a Control is present,
+                          it must be Host readable. If a certain Control is not
+                          present then the bit pair must be set to 0b00.
+                          If a Control is present but read-only, the bit pair must be
+                          set to 0b01. If a Control is also Host programmable, the bit
+                          pair must be set to 0b11. The value 0b10 is not allowed. */
+                       unsigned int ch_bits = 0;
+                       unsigned int ch_read_only = 0;
+
+                       for (j = 0; j < channels; j++) {
+                               unsigned int mask = snd_usb_combine_bytes(bmaControls + csize * (j+1), csize);
+                               if (mask & (1 << (i * 2))) {
+                                       ch_bits |= (1 << j);
+                                       if (~mask & (1 << ((i * 2) + 1)))
+                                               ch_read_only |= (1 << j);
+                               }
+                       }
+
+                       /* FIXME: the whole unit is read-only if any of the channels is marked read-only */
+                       if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
+                               build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid, !!ch_read_only);
+                       if (master_bits & (1 << i * 2))
+                               build_feature_ctl(state, _ftr, 0, i, &iterm, unitid,
+                                                 ~master_bits & (1 << ((i * 2) + 1)));
                }
-               if (ch_bits & 1) /* the first channel must be set (for ease of programming) */
-                       build_feature_ctl(state, _ftr, ch_bits, i, &iterm, unitid);
-               if (master_bits & (1 << i))
-                       build_feature_ctl(state, _ftr, 0, i, &iterm, unitid);
        }
 
        return 0;
@@ -1154,13 +1219,13 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
  * input channel number (zero based) is given in control field instead.
  */
 
-static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
+static void build_mixer_unit_ctl(struct mixer_build *state,
+                                struct uac_mixer_unit_descriptor *desc,
                                 int in_pin, int in_ch, int unitid,
                                 struct usb_audio_term *iterm)
 {
        struct usb_mixer_elem_info *cval;
-       unsigned int input_pins = desc[4];
-       unsigned int num_outs = desc[5 + input_pins];
+       unsigned int num_outs = uac_mixer_unit_bNrChannels(desc);
        unsigned int i, len;
        struct snd_kcontrol *kctl;
        const struct usbmix_name_map *map;
@@ -1178,7 +1243,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
        cval->control = in_ch + 1; /* based on 1 */
        cval->val_type = USB_MIXER_S16;
        for (i = 0; i < num_outs; i++) {
-               if (check_matrix_bitmap(desc + 9 + input_pins, in_ch, i, num_outs)) {
+               if (check_matrix_bitmap(uac_mixer_unit_bmControls(desc, state->mixer->protocol), in_ch, i, num_outs)) {
                        cval->cmask |= (1 << i);
                        cval->channels++;
                }
@@ -1211,18 +1276,19 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
 /*
  * parse a mixer unit
  */
-static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigned char *desc)
+static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, void *raw_desc)
 {
+       struct uac_mixer_unit_descriptor *desc = raw_desc;
        struct usb_audio_term iterm;
        int input_pins, num_ins, num_outs;
        int pin, ich, err;
 
-       if (desc[0] < 11 || ! (input_pins = desc[4]) || ! (num_outs = desc[5 + input_pins])) {
+       if (desc->bLength < 11 || ! (input_pins = desc->bNrInPins) || ! (num_outs = uac_mixer_unit_bNrChannels(desc))) {
                snd_printk(KERN_ERR "invalid MIXER UNIT descriptor %d\n", unitid);
                return -EINVAL;
        }
        /* no bmControls field (e.g. Maya44) -> ignore */
-       if (desc[0] <= 10 + input_pins) {
+       if (desc->bLength <= 10 + input_pins) {
                snd_printdd(KERN_INFO "MU %d has no bmControls field\n", unitid);
                return 0;
        }
@@ -1230,10 +1296,10 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigne
        num_ins = 0;
        ich = 0;
        for (pin = 0; pin < input_pins; pin++) {
-               err = parse_audio_unit(state, desc[5 + pin]);
+               err = parse_audio_unit(state, desc->baSourceID[pin]);
                if (err < 0)
                        return err;
-               err = check_input_term(state, desc[5 + pin], &iterm);
+               err = check_input_term(state, desc->baSourceID[pin], &iterm);
                if (err < 0)
                        return err;
                num_ins += iterm.channels;
@@ -1241,7 +1307,7 @@ static int parse_audio_mixer_unit(struct mixer_build *state, int unitid, unsigne
                        int och, ich_has_controls = 0;
 
                        for (och = 0; och < num_outs; ++och) {
-                               if (check_matrix_bitmap(desc + 9 + input_pins,
+                               if (check_matrix_bitmap(uac_mixer_unit_bmControls(desc, state->mixer->protocol),
                                                        ich, och, num_outs)) {
                                        ich_has_controls = 1;
                                        break;
@@ -1377,8 +1443,8 @@ static struct procunit_info procunits[] = {
  * predefined data for extension units
  */
 static struct procunit_value_info clock_rate_xu_info[] = {
-       { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 },
-       { 0 }
+       { USB_XU_CLOCK_RATE_SELECTOR, "Selector", USB_MIXER_U8, 0 },
+       { 0 }
 };
 static struct procunit_value_info clock_source_xu_info[] = {
        { USB_XU_CLOCK_SOURCE_SELECTOR, "External", USB_MIXER_BOOLEAN },
@@ -1402,9 +1468,10 @@ static struct procunit_info extunits[] = {
 /*
  * build a processing/extension unit
  */
-static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned char *dsc, struct procunit_info *list, char *name)
+static int build_audio_procunit(struct mixer_build *state, int unitid, void *raw_desc, struct procunit_info *list, char *name)
 {
-       int num_ins = dsc[6];
+       struct uac_processing_unit_descriptor *desc = raw_desc;
+       int num_ins = desc->bNrInPins;
        struct usb_mixer_elem_info *cval;
        struct snd_kcontrol *kctl;
        int i, err, nameid, type, len;
@@ -1419,17 +1486,18 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
                0, NULL, default_value_info
        };
 
-       if (dsc[0] < 13 || dsc[0] < 13 + num_ins || dsc[0] < num_ins + dsc[11 + num_ins]) {
+       if (desc->bLength < 13 || desc->bLength < 13 + num_ins ||
+           desc->bLength < num_ins + uac_processing_unit_bControlSize(desc, state->mixer->protocol)) {
                snd_printk(KERN_ERR "invalid %s descriptor (id %d)\n", name, unitid);
                return -EINVAL;
        }
 
        for (i = 0; i < num_ins; i++) {
-               if ((err = parse_audio_unit(state, dsc[7 + i])) < 0)
+               if ((err = parse_audio_unit(state, desc->baSourceID[i])) < 0)
                        return err;
        }
 
-       type = combine_word(&dsc[4]);
+       type = le16_to_cpu(desc->wProcessType);
        for (info = list; info && info->type; info++)
                if (info->type == type)
                        break;
@@ -1437,8 +1505,9 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
                info = &default_info;
 
        for (valinfo = info->values; valinfo->control; valinfo++) {
-               /* FIXME: bitmap might be longer than 8bit */
-               if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1))))
+               __u8 *controls = uac_processing_unit_bmControls(desc, state->mixer->protocol);
+
+               if (! (controls[valinfo->control / 8] & (1 << ((valinfo->control % 8) - 1))))
                        continue;
                map = find_map(state, unitid, valinfo->control);
                if (check_ignored_ctl(map))
@@ -1456,9 +1525,10 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
 
                /* get min/max values */
                if (type == USB_PROC_UPDOWN && cval->control == USB_PROC_UPDOWN_MODE_SEL) {
+                       __u8 *control_spec = uac_processing_unit_specific(desc, state->mixer->protocol);
                        /* FIXME: hard-coded */
                        cval->min = 1;
-                       cval->max = dsc[15];
+                       cval->max = control_spec[0];
                        cval->res = 1;
                        cval->initialized = 1;
                } else {
@@ -1488,7 +1558,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
                else if (info->name)
                        strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name));
                else {
-                       nameid = dsc[12 + num_ins + dsc[11 + num_ins]];
+                       nameid = uac_processing_unit_iProcessing(desc, state->mixer->protocol);
                        len = 0;
                        if (nameid)
                                len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name));
@@ -1507,14 +1577,16 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
 }
 
 
-static int parse_audio_processing_unit(struct mixer_build *state, int unitid, unsigned char *desc)
+static int parse_audio_processing_unit(struct mixer_build *state, int unitid, void *raw_desc)
 {
-       return build_audio_procunit(state, unitid, desc, procunits, "Processing Unit");
+       return build_audio_procunit(state, unitid, raw_desc, procunits, "Processing Unit");
 }
 
-static int parse_audio_extension_unit(struct mixer_build *state, int unitid, unsigned char *desc)
+static int parse_audio_extension_unit(struct mixer_build *state, int unitid, void *raw_desc)
 {
-       return build_audio_procunit(state, unitid, desc, extunits, "Extension Unit");
+       /* Note that we parse extension units with processing unit descriptors.
+        * That's ok as the layout is the same */
+       return build_audio_procunit(state, unitid, raw_desc, extunits, "Extension Unit");
 }
 
 
@@ -1616,9 +1688,9 @@ static void usb_mixer_selector_elem_free(struct snd_kcontrol *kctl)
 /*
  * parse a selector unit
  */
-static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsigned char *desc)
+static int parse_audio_selector_unit(struct mixer_build *state, int unitid, void *raw_desc)
 {
-       unsigned int num_ins = desc[4];
+       struct uac_selector_unit_descriptor *desc = raw_desc;
        unsigned int i, nameid, len;
        int err;
        struct usb_mixer_elem_info *cval;
@@ -1626,17 +1698,17 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
        const struct usbmix_name_map *map;
        char **namelist;
 
-       if (! num_ins || desc[0] < 5 + num_ins) {
+       if (!desc->bNrInPins || desc->bLength < 5 + desc->bNrInPins) {
                snd_printk(KERN_ERR "invalid SELECTOR UNIT descriptor %d\n", unitid);
                return -EINVAL;
        }
 
-       for (i = 0; i < num_ins; i++) {
-               if ((err = parse_audio_unit(state, desc[5 + i])) < 0)
+       for (i = 0; i < desc->bNrInPins; i++) {
+               if ((err = parse_audio_unit(state, desc->baSourceID[i])) < 0)
                        return err;
        }
 
-       if (num_ins == 1) /* only one ? nonsense! */
+       if (desc->bNrInPins == 1) /* only one ? nonsense! */
                return 0;
 
        map = find_map(state, unitid, 0);
@@ -1653,18 +1725,18 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
        cval->val_type = USB_MIXER_U8;
        cval->channels = 1;
        cval->min = 1;
-       cval->max = num_ins;
+       cval->max = desc->bNrInPins;
        cval->res = 1;
        cval->initialized = 1;
 
-       namelist = kmalloc(sizeof(char *) * num_ins, GFP_KERNEL);
+       namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL);
        if (! namelist) {
                snd_printk(KERN_ERR "cannot malloc\n");
                kfree(cval);
                return -ENOMEM;
        }
 #define MAX_ITEM_NAME_LEN      64
-       for (i = 0; i < num_ins; i++) {
+       for (i = 0; i < desc->bNrInPins; i++) {
                struct usb_audio_term iterm;
                len = 0;
                namelist[i] = kmalloc(MAX_ITEM_NAME_LEN, GFP_KERNEL);
@@ -1678,7 +1750,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
                }
                len = check_mapped_selector_name(state, unitid, i, namelist[i],
                                                 MAX_ITEM_NAME_LEN);
-               if (! len && check_input_term(state, desc[5 + i], &iterm) >= 0)
+               if (! len && check_input_term(state, desc->baSourceID[i], &iterm) >= 0)
                        len = get_term_name(state, &iterm, namelist[i], MAX_ITEM_NAME_LEN, 0);
                if (! len)
                        sprintf(namelist[i], "Input %d", i);
@@ -1694,7 +1766,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
        kctl->private_value = (unsigned long)namelist;
        kctl->private_free = usb_mixer_selector_elem_free;
 
-       nameid = desc[desc[0] - 1];
+       nameid = uac_selector_unit_iSelector(desc);
        len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name));
        if (len)
                ;
@@ -1713,7 +1785,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
        }
 
        snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
-                   cval->id, kctl->id.name, num_ins);
+                   cval->id, kctl->id.name, desc->bNrInPins);
        if ((err = add_control_to_empty(state, kctl)) < 0)
                return err;
 
@@ -1748,9 +1820,17 @@ static int parse_audio_unit(struct mixer_build *state, int unitid)
        case UAC_FEATURE_UNIT:
                return parse_audio_feature_unit(state, unitid, p1);
        case UAC_PROCESSING_UNIT_V1:
-               return parse_audio_processing_unit(state, unitid, p1);
+       /*   UAC2_EFFECT_UNIT has the same value */
+               if (state->mixer->protocol == UAC_VERSION_1)
+                       return parse_audio_processing_unit(state, unitid, p1);
+               else
+                       return 0; /* FIXME - effect units not implemented yet */
        case UAC_EXTENSION_UNIT_V1:
-               return parse_audio_extension_unit(state, unitid, p1);
+       /*   UAC2_PROCESSING_UNIT_V2 has the same value */
+               if (state->mixer->protocol == UAC_VERSION_1)
+                       return parse_audio_extension_unit(state, unitid, p1);
+               else /* UAC_VERSION_2 */
+                       return parse_audio_processing_unit(state, unitid, p1);
        default:
                snd_printk(KERN_ERR "usbaudio: unit %u: unexpected type 0x%02x\n", unitid, p1[2]);
                return -EINVAL;
@@ -1783,11 +1863,11 @@ static int snd_usb_mixer_dev_free(struct snd_device *device)
  */
 static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
 {
-       struct uac_output_terminal_descriptor_v1 *desc;
        struct mixer_build state;
        int err;
        const struct usbmix_ctl_map *map;
        struct usb_host_interface *hostif;
+       void *p;
 
        hostif = &usb_ifnum_to_if(mixer->chip->dev, mixer->ctrlif)->altsetting[0];
        memset(&state, 0, sizeof(state));
@@ -1806,23 +1886,39 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
                }
        }
 
-       desc = NULL;
-       while ((desc = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, desc, UAC_OUTPUT_TERMINAL)) != NULL) {
-               if (desc->bLength < 9)
-                       continue; /* invalid descriptor? */
-               set_bit(desc->bTerminalID, state.unitbitmap);  /* mark terminal ID as visited */
-               state.oterm.id = desc->bTerminalID;
-               state.oterm.type = le16_to_cpu(desc->wTerminalType);
-               state.oterm.name = desc->iTerminal;
-               err = parse_audio_unit(&state, desc->bSourceID);
-               if (err < 0)
-                       return err;
+       p = NULL;
+       while ((p = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, p, UAC_OUTPUT_TERMINAL)) != NULL) {
+               if (mixer->protocol == UAC_VERSION_1) {
+                       struct uac_output_terminal_descriptor_v1 *desc = p;
+
+                       if (desc->bLength < sizeof(*desc))
+                               continue; /* invalid descriptor? */
+                       set_bit(desc->bTerminalID, state.unitbitmap);  /* mark terminal ID as visited */
+                       state.oterm.id = desc->bTerminalID;
+                       state.oterm.type = le16_to_cpu(desc->wTerminalType);
+                       state.oterm.name = desc->iTerminal;
+                       err = parse_audio_unit(&state, desc->bSourceID);
+                       if (err < 0)
+                               return err;
+               } else { /* UAC_VERSION_2 */
+                       struct uac2_output_terminal_descriptor *desc = p;
+
+                       if (desc->bLength < sizeof(*desc))
+                               continue; /* invalid descriptor? */
+                       set_bit(desc->bTerminalID, state.unitbitmap);  /* mark terminal ID as visited */
+                       state.oterm.id = desc->bTerminalID;
+                       state.oterm.type = le16_to_cpu(desc->wTerminalType);
+                       state.oterm.name = desc->iTerminal;
+                       err = parse_audio_unit(&state, desc->bSourceID);
+                       if (err < 0)
+                               return err;
+               }
        }
+
        return 0;
 }
 
-static void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer,
-                                   int unitid)
+void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid)
 {
        struct usb_mixer_elem_info *info;
 
@@ -1871,54 +1967,98 @@ static void snd_usb_mixer_proc_read(struct snd_info_entry *entry,
        }
 }
 
-static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
-                                       int unitid)
+static void snd_usb_mixer_interrupt_v2(struct usb_mixer_interface *mixer,
+                                      int attribute, int value, int index)
 {
-       if (!mixer->rc_cfg)
+       struct usb_mixer_elem_info *info;
+       __u8 unitid = (index >> 8) & 0xff;
+       __u8 control = (value >> 8) & 0xff;
+       __u8 channel = value & 0xff;
+
+       if (channel >= MAX_CHANNELS) {
+               snd_printk(KERN_DEBUG "%s(): bogus channel number %d\n",
+                               __func__, channel);
                return;
-       /* unit ids specific to Extigy/Audigy 2 NX: */
-       switch (unitid) {
-       case 0: /* remote control */
-               mixer->rc_urb->dev = mixer->chip->dev;
-               usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
-               break;
-       case 4: /* digital in jack */
-       case 7: /* line in jacks */
-       case 19: /* speaker out jacks */
-       case 20: /* headphones out jack */
-               break;
-       /* live24ext: 4 = line-in jack */
-       case 3: /* hp-out jack (may actuate Mute) */
-               if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
-                   mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
-                       snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
-               break;
-       default:
-               snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
-               break;
+       }
+
+       for (info = mixer->id_elems[unitid]; info; info = info->next_id_elem) {
+               if (info->control != control)
+                       continue;
+
+               switch (attribute) {
+               case UAC2_CS_CUR:
+                       /* invalidate cache, so the value is read from the device */
+                       if (channel)
+                               info->cached &= ~(1 << channel);
+                       else /* master channel */
+                               info->cached = 0;
+
+                       snd_ctl_notify(mixer->chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
+                                       info->elem_id);
+                       break;
+
+               case UAC2_CS_RANGE:
+                       /* TODO */
+                       break;
+
+               case UAC2_CS_MEM:
+                       /* TODO */
+                       break;
+
+               default:
+                       snd_printk(KERN_DEBUG "unknown attribute %d in interrupt\n",
+                                               attribute);
+                       break;
+               } /* switch */
        }
 }
 
-static void snd_usb_mixer_status_complete(struct urb *urb)
+static void snd_usb_mixer_interrupt(struct urb *urb)
 {
        struct usb_mixer_interface *mixer = urb->context;
+       int len = urb->actual_length;
+
+       if (urb->status != 0)
+               goto requeue;
 
-       if (urb->status == 0) {
-               u8 *buf = urb->transfer_buffer;
-               int i;
+       if (mixer->protocol == UAC_VERSION_1) {
+               struct uac1_status_word *status;
 
-               for (i = urb->actual_length; i >= 2; buf += 2, i -= 2) {
+               for (status = urb->transfer_buffer;
+                    len >= sizeof(*status);
+                    len -= sizeof(*status), status++) {
                        snd_printd(KERN_DEBUG "status interrupt: %02x %02x\n",
-                                  buf[0], buf[1]);
+                                               status->bStatusType,
+                                               status->bOriginator);
+
                        /* ignore any notifications not from the control interface */
-                       if ((buf[0] & 0x0f) != 0)
+                       if ((status->bStatusType & UAC1_STATUS_TYPE_ORIG_MASK) !=
+                               UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF)
                                continue;
-                       if (!(buf[0] & 0x40))
-                               snd_usb_mixer_notify_id(mixer, buf[1]);
+
+                       if (status->bStatusType & UAC1_STATUS_TYPE_MEM_CHANGED)
+                               snd_usb_mixer_rc_memory_change(mixer, status->bOriginator);
                        else
-                               snd_usb_mixer_memory_change(mixer, buf[1]);
+                               snd_usb_mixer_notify_id(mixer, status->bOriginator);
+               }
+       } else { /* UAC_VERSION_2 */
+               struct uac2_interrupt_data_msg *msg;
+
+               for (msg = urb->transfer_buffer;
+                    len >= sizeof(*msg);
+                    len -= sizeof(*msg), msg++) {
+                       /* drop vendor specific and endpoint requests */
+                       if ((msg->bInfo & UAC2_INTERRUPT_DATA_MSG_VENDOR) ||
+                           (msg->bInfo & UAC2_INTERRUPT_DATA_MSG_EP))
+                               continue;
+
+                       snd_usb_mixer_interrupt_v2(mixer, msg->bAttribute,
+                                                  le16_to_cpu(msg->wValue),
+                                                  le16_to_cpu(msg->wIndex));
                }
        }
+
+requeue:
        if (urb->status != -ENOENT && urb->status != -ECONNRESET) {
                urb->dev = mixer->chip->dev;
                usb_submit_urb(urb, GFP_ATOMIC);
@@ -1955,301 +2095,11 @@ static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
        usb_fill_int_urb(mixer->urb, mixer->chip->dev,
                         usb_rcvintpipe(mixer->chip->dev, epnum),
                         transfer_buffer, buffer_length,
-                        snd_usb_mixer_status_complete, mixer, ep->bInterval);
+                        snd_usb_mixer_interrupt, mixer, ep->bInterval);
        usb_submit_urb(mixer->urb, GFP_KERNEL);
        return 0;
 }
 
-static void snd_usb_soundblaster_remote_complete(struct urb *urb)
-{
-       struct usb_mixer_interface *mixer = urb->context;
-       const struct rc_config *rc = mixer->rc_cfg;
-       u32 code;
-
-       if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
-               return;
-
-       code = mixer->rc_buffer[rc->offset];
-       if (rc->length == 2)
-               code |= mixer->rc_buffer[rc->offset + 1] << 8;
-
-       /* the Mute button actually changes the mixer control */
-       if (code == rc->mute_code)
-               snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
-       mixer->rc_code = code;
-       wmb();
-       wake_up(&mixer->rc_waitq);
-}
-
-static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
-                                    long count, loff_t *offset)
-{
-       struct usb_mixer_interface *mixer = hw->private_data;
-       int err;
-       u32 rc_code;
-
-       if (count != 1 && count != 4)
-               return -EINVAL;
-       err = wait_event_interruptible(mixer->rc_waitq,
-                                      (rc_code = xchg(&mixer->rc_code, 0)) != 0);
-       if (err == 0) {
-               if (count == 1)
-                       err = put_user(rc_code, buf);
-               else
-                       err = put_user(rc_code, (u32 __user *)buf);
-       }
-       return err < 0 ? err : count;
-}
-
-static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
-                                           poll_table *wait)
-{
-       struct usb_mixer_interface *mixer = hw->private_data;
-
-       poll_wait(file, &mixer->rc_waitq, wait);
-       return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
-}
-
-static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
-{
-       struct snd_hwdep *hwdep;
-       int err, len, i;
-
-       for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
-               if (rc_configs[i].usb_id == mixer->chip->usb_id)
-                       break;
-       if (i >= ARRAY_SIZE(rc_configs))
-               return 0;
-       mixer->rc_cfg = &rc_configs[i];
-
-       len = mixer->rc_cfg->packet_length;
-       
-       init_waitqueue_head(&mixer->rc_waitq);
-       err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
-       if (err < 0)
-               return err;
-       snprintf(hwdep->name, sizeof(hwdep->name),
-                "%s remote control", mixer->chip->card->shortname);
-       hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
-       hwdep->private_data = mixer;
-       hwdep->ops.read = snd_usb_sbrc_hwdep_read;
-       hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
-       hwdep->exclusive = 1;
-
-       mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
-       if (!mixer->rc_urb)
-               return -ENOMEM;
-       mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
-       if (!mixer->rc_setup_packet) {
-               usb_free_urb(mixer->rc_urb);
-               mixer->rc_urb = NULL;
-               return -ENOMEM;
-       }
-       mixer->rc_setup_packet->bRequestType =
-               USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
-       mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
-       mixer->rc_setup_packet->wValue = cpu_to_le16(0);
-       mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
-       mixer->rc_setup_packet->wLength = cpu_to_le16(len);
-       usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
-                            usb_rcvctrlpipe(mixer->chip->dev, 0),
-                            (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
-                            snd_usb_soundblaster_remote_complete, mixer);
-       return 0;
-}
-
-#define snd_audigy2nx_led_info         snd_ctl_boolean_mono_info
-
-static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
-       int index = kcontrol->private_value;
-
-       ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
-       return 0;
-}
-
-static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
-{
-       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
-       int index = kcontrol->private_value;
-       int value = ucontrol->value.integer.value[0];
-       int err, changed;
-
-       if (value > 1)
-               return -EINVAL;
-       changed = value != mixer->audigy2nx_leds[index];
-       err = snd_usb_ctl_msg(mixer->chip->dev,
-                             usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
-                             USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             value, index + 2, NULL, 0, 100);
-       if (err < 0)
-               return err;
-       mixer->audigy2nx_leds[index] = value;
-       return changed;
-}
-
-static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "CMSS LED Switch",
-               .info = snd_audigy2nx_led_info,
-               .get = snd_audigy2nx_led_get,
-               .put = snd_audigy2nx_led_put,
-               .private_value = 0,
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Power LED Switch",
-               .info = snd_audigy2nx_led_info,
-               .get = snd_audigy2nx_led_get,
-               .put = snd_audigy2nx_led_put,
-               .private_value = 1,
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Dolby Digital LED Switch",
-               .info = snd_audigy2nx_led_info,
-               .get = snd_audigy2nx_led_get,
-               .put = snd_audigy2nx_led_put,
-               .private_value = 2,
-       },
-};
-
-static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
-{
-       int i, err;
-
-       for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
-               if (i > 1 && /* Live24ext has 2 LEDs only */
-                       (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
-                        mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
-                       break; 
-               err = snd_ctl_add(mixer->chip->card,
-                                 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
-               if (err < 0)
-                       return err;
-       }
-       mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
-       return 0;
-}
-
-static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
-                                   struct snd_info_buffer *buffer)
-{
-       static const struct sb_jack {
-               int unitid;
-               const char *name;
-       }  jacks_audigy2nx[] = {
-               {4,  "dig in "},
-               {7,  "line in"},
-               {19, "spk out"},
-               {20, "hph out"},
-               {-1, NULL}
-       }, jacks_live24ext[] = {
-               {4,  "line in"}, /* &1=Line, &2=Mic*/
-               {3,  "hph out"}, /* headphones */
-               {0,  "RC     "}, /* last command, 6 bytes see rc_config above */
-               {-1, NULL}
-       };
-       const struct sb_jack *jacks;
-       struct usb_mixer_interface *mixer = entry->private_data;
-       int i, err;
-       u8 buf[3];
-
-       snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
-       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
-               jacks = jacks_audigy2nx;
-       else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
-                mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
-               jacks = jacks_live24ext;
-       else
-               return;
-
-       for (i = 0; jacks[i].name; ++i) {
-               snd_iprintf(buffer, "%s: ", jacks[i].name);
-               err = snd_usb_ctl_msg(mixer->chip->dev,
-                                     usb_rcvctrlpipe(mixer->chip->dev, 0),
-                                     UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
-                                     USB_RECIP_INTERFACE, 0,
-                                     jacks[i].unitid << 8, buf, 3, 100);
-               if (err == 3 && (buf[0] == 3 || buf[0] == 6))
-                       snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
-               else
-                       snd_iprintf(buffer, "?\n");
-       }
-}
-
-static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
-                                  struct snd_ctl_elem_value *ucontrol)
-{
-       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
-
-       ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
-       return 0;
-}
-
-static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
-                                  struct snd_ctl_elem_value *ucontrol)
-{
-       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
-       u8 old_status, new_status;
-       int err, changed;
-
-       old_status = mixer->xonar_u1_status;
-       if (ucontrol->value.integer.value[0])
-               new_status = old_status | 0x02;
-       else
-               new_status = old_status & ~0x02;
-       changed = new_status != old_status;
-       err = snd_usb_ctl_msg(mixer->chip->dev,
-                             usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
-                             USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                             50, 0, &new_status, 1, 100);
-       if (err < 0)
-               return err;
-       mixer->xonar_u1_status = new_status;
-       return changed;
-}
-
-static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
-       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-       .name = "Digital Playback Switch",
-       .info = snd_ctl_boolean_mono_info,
-       .get = snd_xonar_u1_switch_get,
-       .put = snd_xonar_u1_switch_put,
-};
-
-static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
-{
-       int err;
-
-       err = snd_ctl_add(mixer->chip->card,
-                         snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
-       if (err < 0)
-               return err;
-       mixer->xonar_u1_status = 0x05;
-       return 0;
-}
-
-void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
-                              unsigned char samplerate_id)
-{
-       struct usb_mixer_interface *mixer;
-       struct usb_mixer_elem_info *cval;
-       int unitid = 12; /* SamleRate ExtensionUnit ID */
-
-       list_for_each_entry(mixer, &chip->mixer_list, list) {
-               cval = mixer->id_elems[unitid];
-               if (cval) {
-                       set_cur_ctl_value(cval, cval->control << 8,
-                                         samplerate_id);
-                       snd_usb_mixer_notify_id(mixer, unitid);
-               }
-               break;
-       }
-}
-
 int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
                         int ignore_error)
 {
@@ -2259,7 +2109,7 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
        struct usb_mixer_interface *mixer;
        struct snd_info_entry *entry;
        struct usb_host_interface *host_iface;
-       int err, protocol;
+       int err;
 
        strcpy(chip->card->mixername, "USB Mixer");
 
@@ -2277,38 +2127,13 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
        }
 
        host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
-       protocol = host_iface->desc.bInterfaceProtocol;
-
-       /* FIXME! */
-       if (protocol != UAC_VERSION_1) {
-               snd_printk(KERN_WARNING "mixer interface protocol 0x%02x not yet supported\n",
-                                       protocol);
-               return 0;
-       }
+       mixer->protocol = get_iface_desc(host_iface)->bInterfaceProtocol;
 
        if ((err = snd_usb_mixer_controls(mixer)) < 0 ||
            (err = snd_usb_mixer_status_create(mixer)) < 0)
                goto _error;
 
-       if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
-               goto _error;
-
-       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
-           mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
-           mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
-               if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
-                       goto _error;
-               if (!snd_card_proc_new(chip->card, "audigy2nx", &entry))
-                       snd_info_set_text_ops(entry, mixer,
-                                             snd_audigy2nx_proc_read);
-       }
-
-       if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) ||
-           mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) {
-               err = snd_xonar_u1_controls_create(mixer);
-               if (err < 0)
-                       goto _error;
-       }
+       snd_usb_mixer_apply_create_quirk(mixer);
 
        err = snd_device_new(chip->card, SNDRV_DEV_LOWLEVEL, mixer, &dev_ops);
        if (err < 0)
@@ -2329,7 +2154,7 @@ _error:
 void snd_usb_mixer_disconnect(struct list_head *p)
 {
        struct usb_mixer_interface *mixer;
-       
+
        mixer = list_entry(p, struct usb_mixer_interface, list);
        usb_kill_urb(mixer->urb);
        usb_kill_urb(mixer->rc_urb);
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
new file mode 100644 (file)
index 0000000..1301238
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef __USBMIXER_H
+#define __USBMIXER_H
+
+struct usb_mixer_interface {
+       struct snd_usb_audio *chip;
+       unsigned int ctrlif;
+       struct list_head list;
+       unsigned int ignore_ctl_error;
+       struct urb *urb;
+       /* array[MAX_ID_ELEMS], indexed by unit id */
+       struct usb_mixer_elem_info **id_elems;
+
+       /* the usb audio specification version this interface complies to */
+       int protocol;
+
+       /* Sound Blaster remote control stuff */
+       const struct rc_config *rc_cfg;
+       u32 rc_code;
+       wait_queue_head_t rc_waitq;
+       struct urb *rc_urb;
+       struct usb_ctrlrequest *rc_setup_packet;
+       u8 rc_buffer[6];
+
+       u8 audigy2nx_leds[3];
+       u8 xonar_u1_status;
+};
+
+#define MAX_CHANNELS   10      /* max logical channels */
+
+struct usb_mixer_elem_info {
+       struct usb_mixer_interface *mixer;
+       struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
+       struct snd_ctl_elem_id *elem_id;
+       unsigned int id;
+       unsigned int control;   /* CS or ICN (high byte) */
+       unsigned int cmask; /* channel mask bitmap: 0 = master */
+       int channels;
+       int val_type;
+       int min, max, res;
+       int dBmin, dBmax;
+       int cached;
+       int cache_val[MAX_CHANNELS];
+       u8 initialized;
+};
+
+int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
+                        int ignore_error);
+void snd_usb_mixer_disconnect(struct list_head *p);
+
+void snd_usb_mixer_notify_id(struct usb_mixer_interface *mixer, int unitid);
+
+int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
+                               int request, int validx, int value_set);
+
+#endif /* __USBMIXER_H */
similarity index 98%
rename from sound/usb/usbmixer_maps.c
rename to sound/usb/mixer_maps.c
index 79e903a..d93fc89 100644 (file)
@@ -85,8 +85,8 @@ static struct usbmix_name_map extigy_map[] = {
        /* 16: MU (w/o controls) */
        { 17, NULL, 1 }, /* DISABLED: PU-switch (any effect?) */
        { 17, "Channel Routing", 2 },   /* PU: mode select */
-       { 18, "Tone Control - Bass", USB_FEATURE_BASS }, /* FU */
-       { 18, "Tone Control - Treble", USB_FEATURE_TREBLE }, /* FU */
+       { 18, "Tone Control - Bass", UAC_BASS_CONTROL }, /* FU */
+       { 18, "Tone Control - Treble", UAC_TREBLE_CONTROL }, /* FU */
        { 18, "Master Playback" }, /* FU; others */
        /* 19: OT speaker */
        /* 20: OT headphone */
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
new file mode 100644 (file)
index 0000000..e7df1e5
--- /dev/null
@@ -0,0 +1,412 @@
+/*
+ *   USB Audio Driver for ALSA
+ *
+ *   Quirks and vendor-specific extensions for mixer interfaces
+ *
+ *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
+ *
+ *   Many codes borrowed from audio.c by
+ *         Alan Cox (alan@lxorguk.ukuu.org.uk)
+ *         Thomas Sailer (sailer@ife.ee.ethz.ch)
+ *
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+
+#include <sound/core.h>
+#include <sound/control.h>
+#include <sound/hwdep.h>
+#include <sound/info.h>
+
+#include "usbaudio.h"
+#include "mixer.h"
+#include "mixer_quirks.h"
+#include "helper.h"
+
+/*
+ * Sound Blaster remote control configuration
+ *
+ * format of remote control data:
+ * Extigy:       xx 00
+ * Audigy 2 NX:  06 80 xx 00 00 00
+ * Live! 24-bit: 06 80 xx yy 22 83
+ */
+static const struct rc_config {
+       u32 usb_id;
+       u8  offset;
+       u8  length;
+       u8  packet_length;
+       u8  min_packet_length; /* minimum accepted length of the URB result */
+       u8  mute_mixer_id;
+       u32 mute_code;
+} rc_configs[] = {
+       { USB_ID(0x041e, 0x3000), 0, 1, 2, 1,  18, 0x0013 }, /* Extigy       */
+       { USB_ID(0x041e, 0x3020), 2, 1, 6, 6,  18, 0x0013 }, /* Audigy 2 NX  */
+       { USB_ID(0x041e, 0x3040), 2, 2, 6, 6,  2,  0x6e91 }, /* Live! 24-bit */
+       { USB_ID(0x041e, 0x3048), 2, 2, 6, 6,  2,  0x6e91 }, /* Toshiba SB0500 */
+};
+
+static void snd_usb_soundblaster_remote_complete(struct urb *urb)
+{
+       struct usb_mixer_interface *mixer = urb->context;
+       const struct rc_config *rc = mixer->rc_cfg;
+       u32 code;
+
+       if (urb->status < 0 || urb->actual_length < rc->min_packet_length)
+               return;
+
+       code = mixer->rc_buffer[rc->offset];
+       if (rc->length == 2)
+               code |= mixer->rc_buffer[rc->offset + 1] << 8;
+
+       /* the Mute button actually changes the mixer control */
+       if (code == rc->mute_code)
+               snd_usb_mixer_notify_id(mixer, rc->mute_mixer_id);
+       mixer->rc_code = code;
+       wmb();
+       wake_up(&mixer->rc_waitq);
+}
+
+static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
+                                    long count, loff_t *offset)
+{
+       struct usb_mixer_interface *mixer = hw->private_data;
+       int err;
+       u32 rc_code;
+
+       if (count != 1 && count != 4)
+               return -EINVAL;
+       err = wait_event_interruptible(mixer->rc_waitq,
+                                      (rc_code = xchg(&mixer->rc_code, 0)) != 0);
+       if (err == 0) {
+               if (count == 1)
+                       err = put_user(rc_code, buf);
+               else
+                       err = put_user(rc_code, (u32 __user *)buf);
+       }
+       return err < 0 ? err : count;
+}
+
+static unsigned int snd_usb_sbrc_hwdep_poll(struct snd_hwdep *hw, struct file *file,
+                                           poll_table *wait)
+{
+       struct usb_mixer_interface *mixer = hw->private_data;
+
+       poll_wait(file, &mixer->rc_waitq, wait);
+       return mixer->rc_code ? POLLIN | POLLRDNORM : 0;
+}
+
+static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
+{
+       struct snd_hwdep *hwdep;
+       int err, len, i;
+
+       for (i = 0; i < ARRAY_SIZE(rc_configs); ++i)
+               if (rc_configs[i].usb_id == mixer->chip->usb_id)
+                       break;
+       if (i >= ARRAY_SIZE(rc_configs))
+               return 0;
+       mixer->rc_cfg = &rc_configs[i];
+
+       len = mixer->rc_cfg->packet_length;
+
+       init_waitqueue_head(&mixer->rc_waitq);
+       err = snd_hwdep_new(mixer->chip->card, "SB remote control", 0, &hwdep);
+       if (err < 0)
+               return err;
+       snprintf(hwdep->name, sizeof(hwdep->name),
+                "%s remote control", mixer->chip->card->shortname);
+       hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
+       hwdep->private_data = mixer;
+       hwdep->ops.read = snd_usb_sbrc_hwdep_read;
+       hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
+       hwdep->exclusive = 1;
+
+       mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (!mixer->rc_urb)
+               return -ENOMEM;
+       mixer->rc_setup_packet = kmalloc(sizeof(*mixer->rc_setup_packet), GFP_KERNEL);
+       if (!mixer->rc_setup_packet) {
+               usb_free_urb(mixer->rc_urb);
+               mixer->rc_urb = NULL;
+               return -ENOMEM;
+       }
+       mixer->rc_setup_packet->bRequestType =
+               USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
+       mixer->rc_setup_packet->bRequest = UAC_GET_MEM;
+       mixer->rc_setup_packet->wValue = cpu_to_le16(0);
+       mixer->rc_setup_packet->wIndex = cpu_to_le16(0);
+       mixer->rc_setup_packet->wLength = cpu_to_le16(len);
+       usb_fill_control_urb(mixer->rc_urb, mixer->chip->dev,
+                            usb_rcvctrlpipe(mixer->chip->dev, 0),
+                            (u8*)mixer->rc_setup_packet, mixer->rc_buffer, len,
+                            snd_usb_soundblaster_remote_complete, mixer);
+       return 0;
+}
+
+#define snd_audigy2nx_led_info         snd_ctl_boolean_mono_info
+
+static int snd_audigy2nx_led_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+       int index = kcontrol->private_value;
+
+       ucontrol->value.integer.value[0] = mixer->audigy2nx_leds[index];
+       return 0;
+}
+
+static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
+{
+       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+       int index = kcontrol->private_value;
+       int value = ucontrol->value.integer.value[0];
+       int err, changed;
+
+       if (value > 1)
+               return -EINVAL;
+       changed = value != mixer->audigy2nx_leds[index];
+       err = snd_usb_ctl_msg(mixer->chip->dev,
+                             usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
+                             USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+                             value, index + 2, NULL, 0, 100);
+       if (err < 0)
+               return err;
+       mixer->audigy2nx_leds[index] = value;
+       return changed;
+}
+
+static struct snd_kcontrol_new snd_audigy2nx_controls[] = {
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "CMSS LED Switch",
+               .info = snd_audigy2nx_led_info,
+               .get = snd_audigy2nx_led_get,
+               .put = snd_audigy2nx_led_put,
+               .private_value = 0,
+       },
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Power LED Switch",
+               .info = snd_audigy2nx_led_info,
+               .get = snd_audigy2nx_led_get,
+               .put = snd_audigy2nx_led_put,
+               .private_value = 1,
+       },
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Dolby Digital LED Switch",
+               .info = snd_audigy2nx_led_info,
+               .get = snd_audigy2nx_led_get,
+               .put = snd_audigy2nx_led_put,
+               .private_value = 2,
+       },
+};
+
+static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
+{
+       int i, err;
+
+       for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
+               if (i > 1 && /* Live24ext has 2 LEDs only */
+                       (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
+                        mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
+                       break; 
+               err = snd_ctl_add(mixer->chip->card,
+                                 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
+               if (err < 0)
+                       return err;
+       }
+       mixer->audigy2nx_leds[1] = 1; /* Power LED is on by default */
+       return 0;
+}
+
+static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
+                                   struct snd_info_buffer *buffer)
+{
+       static const struct sb_jack {
+               int unitid;
+               const char *name;
+       }  jacks_audigy2nx[] = {
+               {4,  "dig in "},
+               {7,  "line in"},
+               {19, "spk out"},
+               {20, "hph out"},
+               {-1, NULL}
+       }, jacks_live24ext[] = {
+               {4,  "line in"}, /* &1=Line, &2=Mic*/
+               {3,  "hph out"}, /* headphones */
+               {0,  "RC     "}, /* last command, 6 bytes see rc_config above */
+               {-1, NULL}
+       };
+       const struct sb_jack *jacks;
+       struct usb_mixer_interface *mixer = entry->private_data;
+       int i, err;
+       u8 buf[3];
+
+       snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
+       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
+               jacks = jacks_audigy2nx;
+       else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
+                mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
+               jacks = jacks_live24ext;
+       else
+               return;
+
+       for (i = 0; jacks[i].name; ++i) {
+               snd_iprintf(buffer, "%s: ", jacks[i].name);
+               err = snd_usb_ctl_msg(mixer->chip->dev,
+                                     usb_rcvctrlpipe(mixer->chip->dev, 0),
+                                     UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
+                                     USB_RECIP_INTERFACE, 0,
+                                     jacks[i].unitid << 8, buf, 3, 100);
+               if (err == 3 && (buf[0] == 3 || buf[0] == 6))
+                       snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
+               else
+                       snd_iprintf(buffer, "?\n");
+       }
+}
+
+static int snd_xonar_u1_switch_get(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
+{
+       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+
+       ucontrol->value.integer.value[0] = !!(mixer->xonar_u1_status & 0x02);
+       return 0;
+}
+
+static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
+{
+       struct usb_mixer_interface *mixer = snd_kcontrol_chip(kcontrol);
+       u8 old_status, new_status;
+       int err, changed;
+
+       old_status = mixer->xonar_u1_status;
+       if (ucontrol->value.integer.value[0])
+               new_status = old_status | 0x02;
+       else
+               new_status = old_status & ~0x02;
+       changed = new_status != old_status;
+       err = snd_usb_ctl_msg(mixer->chip->dev,
+                             usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
+                             USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+                             50, 0, &new_status, 1, 100);
+       if (err < 0)
+               return err;
+       mixer->xonar_u1_status = new_status;
+       return changed;
+}
+
+static struct snd_kcontrol_new snd_xonar_u1_output_switch = {
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Digital Playback Switch",
+       .info = snd_ctl_boolean_mono_info,
+       .get = snd_xonar_u1_switch_get,
+       .put = snd_xonar_u1_switch_put,
+};
+
+static int snd_xonar_u1_controls_create(struct usb_mixer_interface *mixer)
+{
+       int err;
+
+       err = snd_ctl_add(mixer->chip->card,
+                         snd_ctl_new1(&snd_xonar_u1_output_switch, mixer));
+       if (err < 0)
+               return err;
+       mixer->xonar_u1_status = 0x05;
+       return 0;
+}
+
+void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
+                              unsigned char samplerate_id)
+{
+       struct usb_mixer_interface *mixer;
+       struct usb_mixer_elem_info *cval;
+       int unitid = 12; /* SamleRate ExtensionUnit ID */
+
+       list_for_each_entry(mixer, &chip->mixer_list, list) {
+               cval = mixer->id_elems[unitid];
+               if (cval) {
+                       snd_usb_mixer_set_ctl_value(cval, UAC_SET_CUR,
+                                                   cval->control << 8,
+                                                   samplerate_id);
+                       snd_usb_mixer_notify_id(mixer, unitid);
+               }
+               break;
+       }
+}
+
+int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer)
+{
+       int err;
+       struct snd_info_entry *entry;
+
+       if ((err = snd_usb_soundblaster_remote_init(mixer)) < 0)
+               return err;
+
+       if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
+           mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
+           mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
+               if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
+                       return err;
+               if (!snd_card_proc_new(mixer->chip->card, "audigy2nx", &entry))
+                       snd_info_set_text_ops(entry, mixer,
+                                             snd_audigy2nx_proc_read);
+       }
+
+       if (mixer->chip->usb_id == USB_ID(0x0b05, 0x1739) ||
+           mixer->chip->usb_id == USB_ID(0x0b05, 0x1743)) {
+               err = snd_xonar_u1_controls_create(mixer);
+               if (err < 0)
+                       return err;
+       }
+
+       return 0;
+}
+
+void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
+                                   int unitid)
+{
+       if (!mixer->rc_cfg)
+               return;
+       /* unit ids specific to Extigy/Audigy 2 NX: */
+       switch (unitid) {
+       case 0: /* remote control */
+               mixer->rc_urb->dev = mixer->chip->dev;
+               usb_submit_urb(mixer->rc_urb, GFP_ATOMIC);
+               break;
+       case 4: /* digital in jack */
+       case 7: /* line in jacks */
+       case 19: /* speaker out jacks */
+       case 20: /* headphones out jack */
+               break;
+       /* live24ext: 4 = line-in jack */
+       case 3: /* hp-out jack (may actuate Mute) */
+               if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
+                   mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
+                       snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
+               break;
+       default:
+               snd_printd(KERN_DEBUG "memory change in unknown unit %d\n", unitid);
+               break;
+       }
+}
+
diff --git a/sound/usb/mixer_quirks.h b/sound/usb/mixer_quirks.h
new file mode 100644 (file)
index 0000000..bdbfab0
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef SND_USB_MIXER_QUIRKS_H
+#define SND_USB_MIXER_QUIRKS_H
+
+int snd_usb_mixer_apply_create_quirk(struct usb_mixer_interface *mixer);
+
+void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
+                              unsigned char samplerate_id);
+
+void snd_usb_mixer_rc_memory_change(struct usb_mixer_interface *mixer,
+                                   int unitid);
+
+#endif /* SND_USB_MIXER_QUIRKS_H */
+
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
new file mode 100644 (file)
index 0000000..2bf0d77
--- /dev/null
@@ -0,0 +1,935 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+#include <linux/usb/audio-v2.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "quirks.h"
+#include "debug.h"
+#include "urb.h"
+#include "helper.h"
+#include "pcm.h"
+
+/*
+ * return the current pcm pointer.  just based on the hwptr_done value.
+ */
+static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
+{
+       struct snd_usb_substream *subs;
+       unsigned int hwptr_done;
+
+       subs = (struct snd_usb_substream *)substream->runtime->private_data;
+       spin_lock(&subs->lock);
+       hwptr_done = subs->hwptr_done;
+       spin_unlock(&subs->lock);
+       return hwptr_done / (substream->runtime->frame_bits >> 3);
+}
+
+/*
+ * find a matching audio format
+ */
+static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned int format,
+                                      unsigned int rate, unsigned int channels)
+{
+       struct list_head *p;
+       struct audioformat *found = NULL;
+       int cur_attr = 0, attr;
+
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               fp = list_entry(p, struct audioformat, list);
+               if (!(fp->formats & (1uLL << format)))
+                       continue;
+               if (fp->channels != channels)
+                       continue;
+               if (rate < fp->rate_min || rate > fp->rate_max)
+                       continue;
+               if (! (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)) {
+                       unsigned int i;
+                       for (i = 0; i < fp->nr_rates; i++)
+                               if (fp->rate_table[i] == rate)
+                                       break;
+                       if (i >= fp->nr_rates)
+                               continue;
+               }
+               attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
+               if (! found) {
+                       found = fp;
+                       cur_attr = attr;
+                       continue;
+               }
+               /* avoid async out and adaptive in if the other method
+                * supports the same format.
+                * this is a workaround for the case like
+                * M-audio audiophile USB.
+                */
+               if (attr != cur_attr) {
+                       if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
+                            subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
+                           (attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
+                            subs->direction == SNDRV_PCM_STREAM_CAPTURE))
+                               continue;
+                       if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
+                            subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
+                           (cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
+                            subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
+                               found = fp;
+                               cur_attr = attr;
+                               continue;
+                       }
+               }
+               /* find the format with the largest max. packet size */
+               if (fp->maxpacksize > found->maxpacksize) {
+                       found = fp;
+                       cur_attr = attr;
+               }
+       }
+       return found;
+}
+
+static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
+                        struct usb_host_interface *alts,
+                        struct audioformat *fmt)
+{
+       struct usb_device *dev = chip->dev;
+       unsigned int ep;
+       unsigned char data[1];
+       int err;
+
+       ep = get_endpoint(alts, 0)->bEndpointAddress;
+
+       /* if endpoint doesn't have pitch control, bail out */
+       if (!(fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL))
+               return 0;
+
+       data[0] = 1;
+       if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
+                                  USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
+                                  UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep,
+                                  data, sizeof(data), 1000)) < 0) {
+               snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
+                          dev->devnum, iface, ep);
+               return err;
+       }
+
+       return 0;
+}
+
+/*
+ * initialize the picth control and sample rate
+ */
+int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
+                      struct usb_host_interface *alts,
+                      struct audioformat *fmt)
+{
+       struct usb_interface_descriptor *altsd = get_iface_desc(alts);
+
+       switch (altsd->bInterfaceProtocol) {
+       case UAC_VERSION_1:
+               return init_pitch_v1(chip, iface, alts, fmt);
+
+       case UAC_VERSION_2:
+               /* not implemented yet */
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
+                             struct usb_host_interface *alts,
+                             struct audioformat *fmt, int rate)
+{
+       struct usb_device *dev = chip->dev;
+       unsigned int ep;
+       unsigned char data[3];
+       int err, crate;
+
+       ep = get_endpoint(alts, 0)->bEndpointAddress;
+       /* if endpoint doesn't have sampling rate control, bail out */
+       if (!(fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE)) {
+               snd_printk(KERN_WARNING "%d:%d:%d: endpoint lacks sample rate attribute bit, cannot set.\n",
+                                  dev->devnum, iface, fmt->altsetting);
+               return 0;
+       }
+
+       data[0] = rate;
+       data[1] = rate >> 8;
+       data[2] = rate >> 16;
+       if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
+                                  USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
+                                  UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
+                                  data, sizeof(data), 1000)) < 0) {
+               snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
+                          dev->devnum, iface, fmt->altsetting, rate, ep);
+               return err;
+       }
+       if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
+                                  USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
+                                  UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
+                                  data, sizeof(data), 1000)) < 0) {
+               snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
+                          dev->devnum, iface, fmt->altsetting, ep);
+               return 0; /* some devices don't support reading */
+       }
+       crate = data[0] | (data[1] << 8) | (data[2] << 16);
+       if (crate != rate) {
+               snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate);
+               // runtime->rate = crate;
+       }
+
+       return 0;
+}
+
+static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
+                             struct usb_host_interface *alts,
+                             struct audioformat *fmt, int rate)
+{
+       struct usb_device *dev = chip->dev;
+       unsigned char data[4];
+       int err, crate;
+
+       data[0] = rate;
+       data[1] = rate >> 8;
+       data[2] = rate >> 16;
+       data[3] = rate >> 24;
+       if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
+                                  USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
+                                  UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
+                                  data, sizeof(data), 1000)) < 0) {
+               snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
+                          dev->devnum, iface, fmt->altsetting, rate);
+               return err;
+       }
+       if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
+                                  USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+                                  UAC2_CS_CONTROL_SAM_FREQ << 8, chip->clock_id << 8,
+                                  data, sizeof(data), 1000)) < 0) {
+               snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
+                          dev->devnum, iface, fmt->altsetting);
+               return err;
+       }
+       crate = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
+       if (crate != rate)
+               snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate);
+
+       return 0;
+}
+
+int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
+                            struct usb_host_interface *alts,
+                            struct audioformat *fmt, int rate)
+{
+       struct usb_interface_descriptor *altsd = get_iface_desc(alts);
+
+       switch (altsd->bInterfaceProtocol) {
+       case UAC_VERSION_1:
+               return set_sample_rate_v1(chip, iface, alts, fmt, rate);
+
+       case UAC_VERSION_2:
+               return set_sample_rate_v2(chip, iface, alts, fmt, rate);
+       }
+
+       return -EINVAL;
+}
+
+/*
+ * find a matching format and set up the interface
+ */
+static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
+{
+       struct usb_device *dev = subs->dev;
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       struct usb_interface *iface;
+       unsigned int ep, attr;
+       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
+       int err;
+
+       iface = usb_ifnum_to_if(dev, fmt->iface);
+       if (WARN_ON(!iface))
+               return -EINVAL;
+       alts = &iface->altsetting[fmt->altset_idx];
+       altsd = get_iface_desc(alts);
+       if (WARN_ON(altsd->bAlternateSetting != fmt->altsetting))
+               return -EINVAL;
+
+       if (fmt == subs->cur_audiofmt)
+               return 0;
+
+       /* close the old interface */
+       if (subs->interface >= 0 && subs->interface != fmt->iface) {
+               if (usb_set_interface(subs->dev, subs->interface, 0) < 0) {
+                       snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed\n",
+                               dev->devnum, fmt->iface, fmt->altsetting);
+                       return -EIO;
+               }
+               subs->interface = -1;
+               subs->altset_idx = 0;
+       }
+
+       /* set interface */
+       if (subs->interface != fmt->iface || subs->altset_idx != fmt->altset_idx) {
+               if (usb_set_interface(dev, fmt->iface, fmt->altsetting) < 0) {
+                       snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed\n",
+                                  dev->devnum, fmt->iface, fmt->altsetting);
+                       return -EIO;
+               }
+               snd_printdd(KERN_INFO "setting usb interface %d:%d\n", fmt->iface, fmt->altsetting);
+               subs->interface = fmt->iface;
+               subs->altset_idx = fmt->altset_idx;
+       }
+
+       /* create a data pipe */
+       ep = fmt->endpoint & USB_ENDPOINT_NUMBER_MASK;
+       if (is_playback)
+               subs->datapipe = usb_sndisocpipe(dev, ep);
+       else
+               subs->datapipe = usb_rcvisocpipe(dev, ep);
+       subs->datainterval = fmt->datainterval;
+       subs->syncpipe = subs->syncinterval = 0;
+       subs->maxpacksize = fmt->maxpacksize;
+       subs->fill_max = 0;
+
+       /* we need a sync pipe in async OUT or adaptive IN mode */
+       /* check the number of EP, since some devices have broken
+        * descriptors which fool us.  if it has only one EP,
+        * assume it as adaptive-out or sync-in.
+        */
+       attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
+       if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
+            (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
+           altsd->bNumEndpoints >= 2) {
+               /* check sync-pipe endpoint */
+               /* ... and check descriptor size before accessing bSynchAddress
+                  because there is a version of the SB Audigy 2 NX firmware lacking
+                  the audio fields in the endpoint descriptors */
+               if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 ||
+                   (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
+                    get_endpoint(alts, 1)->bSynchAddress != 0)) {
+                       snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
+                                  dev->devnum, fmt->iface, fmt->altsetting);
+                       return -EINVAL;
+               }
+               ep = get_endpoint(alts, 1)->bEndpointAddress;
+               if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
+                   (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) ||
+                    (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) {
+                       snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
+                                  dev->devnum, fmt->iface, fmt->altsetting);
+                       return -EINVAL;
+               }
+               ep &= USB_ENDPOINT_NUMBER_MASK;
+               if (is_playback)
+                       subs->syncpipe = usb_rcvisocpipe(dev, ep);
+               else
+                       subs->syncpipe = usb_sndisocpipe(dev, ep);
+               if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
+                   get_endpoint(alts, 1)->bRefresh >= 1 &&
+                   get_endpoint(alts, 1)->bRefresh <= 9)
+                       subs->syncinterval = get_endpoint(alts, 1)->bRefresh;
+               else if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
+                       subs->syncinterval = 1;
+               else if (get_endpoint(alts, 1)->bInterval >= 1 &&
+                        get_endpoint(alts, 1)->bInterval <= 16)
+                       subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1;
+               else
+                       subs->syncinterval = 3;
+       }
+
+       /* always fill max packet size */
+       if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX)
+               subs->fill_max = 1;
+
+       if ((err = snd_usb_init_pitch(subs->stream->chip, subs->interface, alts, fmt)) < 0)
+               return err;
+
+       subs->cur_audiofmt = fmt;
+
+       snd_usb_set_format_quirk(subs, fmt);
+
+#if 0
+       printk(KERN_DEBUG
+              "setting done: format = %d, rate = %d..%d, channels = %d\n",
+              fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
+       printk(KERN_DEBUG
+              "  datapipe = 0x%0x, syncpipe = 0x%0x\n",
+              subs->datapipe, subs->syncpipe);
+#endif
+
+       return 0;
+}
+
+/*
+ * hw_params callback
+ *
+ * allocate a buffer and set the given audio format.
+ *
+ * so far we use a physically linear buffer although packetize transfer
+ * doesn't need a continuous area.
+ * if sg buffer is supported on the later version of alsa, we'll follow
+ * that.
+ */
+static int snd_usb_hw_params(struct snd_pcm_substream *substream,
+                            struct snd_pcm_hw_params *hw_params)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
+       struct audioformat *fmt;
+       unsigned int channels, rate, format;
+       int ret, changed;
+
+       ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
+                                              params_buffer_bytes(hw_params));
+       if (ret < 0)
+               return ret;
+
+       format = params_format(hw_params);
+       rate = params_rate(hw_params);
+       channels = params_channels(hw_params);
+       fmt = find_format(subs, format, rate, channels);
+       if (!fmt) {
+               snd_printd(KERN_DEBUG "cannot set format: format = %#x, rate = %d, channels = %d\n",
+                          format, rate, channels);
+               return -EINVAL;
+       }
+
+       changed = subs->cur_audiofmt != fmt ||
+               subs->period_bytes != params_period_bytes(hw_params) ||
+               subs->cur_rate != rate;
+       if ((ret = set_format(subs, fmt)) < 0)
+               return ret;
+
+       if (subs->cur_rate != rate) {
+               struct usb_host_interface *alts;
+               struct usb_interface *iface;
+               iface = usb_ifnum_to_if(subs->dev, fmt->iface);
+               alts = &iface->altsetting[fmt->altset_idx];
+               ret = snd_usb_init_sample_rate(subs->stream->chip, subs->interface, alts, fmt, rate);
+               if (ret < 0)
+                       return ret;
+               subs->cur_rate = rate;
+       }
+
+       if (changed) {
+               /* format changed */
+               snd_usb_release_substream_urbs(subs, 0);
+               /* influenced: period_bytes, channels, rate, format, */
+               ret = snd_usb_init_substream_urbs(subs, params_period_bytes(hw_params),
+                                                 params_rate(hw_params),
+                                                 snd_pcm_format_physical_width(params_format(hw_params)) *
+                                                       params_channels(hw_params));
+       }
+
+       return ret;
+}
+
+/*
+ * hw_free callback
+ *
+ * reset the audio format and release the buffer
+ */
+static int snd_usb_hw_free(struct snd_pcm_substream *substream)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
+
+       subs->cur_audiofmt = NULL;
+       subs->cur_rate = 0;
+       subs->period_bytes = 0;
+       if (!subs->stream->chip->shutdown)
+               snd_usb_release_substream_urbs(subs, 0);
+       return snd_pcm_lib_free_vmalloc_buffer(substream);
+}
+
+/*
+ * prepare callback
+ *
+ * only a few subtle things...
+ */
+static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
+{
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_usb_substream *subs = runtime->private_data;
+
+       if (! subs->cur_audiofmt) {
+               snd_printk(KERN_ERR "usbaudio: no format is specified!\n");
+               return -ENXIO;
+       }
+
+       /* some unit conversions in runtime */
+       subs->maxframesize = bytes_to_frames(runtime, subs->maxpacksize);
+       subs->curframesize = bytes_to_frames(runtime, subs->curpacksize);
+
+       /* reset the pointer */
+       subs->hwptr_done = 0;
+       subs->transfer_done = 0;
+       subs->phase = 0;
+       runtime->delay = 0;
+
+       return snd_usb_substream_prepare(subs, runtime);
+}
+
+static struct snd_pcm_hardware snd_usb_hardware =
+{
+       .info =                 SNDRV_PCM_INFO_MMAP |
+                               SNDRV_PCM_INFO_MMAP_VALID |
+                               SNDRV_PCM_INFO_BATCH |
+                               SNDRV_PCM_INFO_INTERLEAVED |
+                               SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                               SNDRV_PCM_INFO_PAUSE,
+       .buffer_bytes_max =     1024 * 1024,
+       .period_bytes_min =     64,
+       .period_bytes_max =     512 * 1024,
+       .periods_min =          2,
+       .periods_max =          1024,
+};
+
+static int hw_check_valid_format(struct snd_usb_substream *subs,
+                                struct snd_pcm_hw_params *params,
+                                struct audioformat *fp)
+{
+       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+       struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+       struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+       struct snd_interval *pt = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
+       struct snd_mask check_fmts;
+       unsigned int ptime;
+
+       /* check the format */
+       snd_mask_none(&check_fmts);
+       check_fmts.bits[0] = (u32)fp->formats;
+       check_fmts.bits[1] = (u32)(fp->formats >> 32);
+       snd_mask_intersect(&check_fmts, fmts);
+       if (snd_mask_empty(&check_fmts)) {
+               hwc_debug("   > check: no supported format %d\n", fp->format);
+               return 0;
+       }
+       /* check the channels */
+       if (fp->channels < ct->min || fp->channels > ct->max) {
+               hwc_debug("   > check: no valid channels %d (%d/%d)\n", fp->channels, ct->min, ct->max);
+               return 0;
+       }
+       /* check the rate is within the range */
+       if (fp->rate_min > it->max || (fp->rate_min == it->max && it->openmax)) {
+               hwc_debug("   > check: rate_min %d > max %d\n", fp->rate_min, it->max);
+               return 0;
+       }
+       if (fp->rate_max < it->min || (fp->rate_max == it->min && it->openmin)) {
+               hwc_debug("   > check: rate_max %d < min %d\n", fp->rate_max, it->min);
+               return 0;
+       }
+       /* check whether the period time is >= the data packet interval */
+       if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH) {
+               ptime = 125 * (1 << fp->datainterval);
+               if (ptime > pt->max || (ptime == pt->max && pt->openmax)) {
+                       hwc_debug("   > check: ptime %u > max %u\n", ptime, pt->max);
+                       return 0;
+               }
+       }
+       return 1;
+}
+
+static int hw_rule_rate(struct snd_pcm_hw_params *params,
+                       struct snd_pcm_hw_rule *rule)
+{
+       struct snd_usb_substream *subs = rule->private;
+       struct list_head *p;
+       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+       unsigned int rmin, rmax;
+       int changed;
+
+       hwc_debug("hw_rule_rate: (%d,%d)\n", it->min, it->max);
+       changed = 0;
+       rmin = rmax = 0;
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               fp = list_entry(p, struct audioformat, list);
+               if (!hw_check_valid_format(subs, params, fp))
+                       continue;
+               if (changed++) {
+                       if (rmin > fp->rate_min)
+                               rmin = fp->rate_min;
+                       if (rmax < fp->rate_max)
+                               rmax = fp->rate_max;
+               } else {
+                       rmin = fp->rate_min;
+                       rmax = fp->rate_max;
+               }
+       }
+
+       if (!changed) {
+               hwc_debug("  --> get empty\n");
+               it->empty = 1;
+               return -EINVAL;
+       }
+
+       changed = 0;
+       if (it->min < rmin) {
+               it->min = rmin;
+               it->openmin = 0;
+               changed = 1;
+       }
+       if (it->max > rmax) {
+               it->max = rmax;
+               it->openmax = 0;
+               changed = 1;
+       }
+       if (snd_interval_checkempty(it)) {
+               it->empty = 1;
+               return -EINVAL;
+       }
+       hwc_debug("  --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
+       return changed;
+}
+
+
+static int hw_rule_channels(struct snd_pcm_hw_params *params,
+                           struct snd_pcm_hw_rule *rule)
+{
+       struct snd_usb_substream *subs = rule->private;
+       struct list_head *p;
+       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+       unsigned int rmin, rmax;
+       int changed;
+
+       hwc_debug("hw_rule_channels: (%d,%d)\n", it->min, it->max);
+       changed = 0;
+       rmin = rmax = 0;
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               fp = list_entry(p, struct audioformat, list);
+               if (!hw_check_valid_format(subs, params, fp))
+                       continue;
+               if (changed++) {
+                       if (rmin > fp->channels)
+                               rmin = fp->channels;
+                       if (rmax < fp->channels)
+                               rmax = fp->channels;
+               } else {
+                       rmin = fp->channels;
+                       rmax = fp->channels;
+               }
+       }
+
+       if (!changed) {
+               hwc_debug("  --> get empty\n");
+               it->empty = 1;
+               return -EINVAL;
+       }
+
+       changed = 0;
+       if (it->min < rmin) {
+               it->min = rmin;
+               it->openmin = 0;
+               changed = 1;
+       }
+       if (it->max > rmax) {
+               it->max = rmax;
+               it->openmax = 0;
+               changed = 1;
+       }
+       if (snd_interval_checkempty(it)) {
+               it->empty = 1;
+               return -EINVAL;
+       }
+       hwc_debug("  --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
+       return changed;
+}
+
+static int hw_rule_format(struct snd_pcm_hw_params *params,
+                         struct snd_pcm_hw_rule *rule)
+{
+       struct snd_usb_substream *subs = rule->private;
+       struct list_head *p;
+       struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
+       u64 fbits;
+       u32 oldbits[2];
+       int changed;
+
+       hwc_debug("hw_rule_format: %x:%x\n", fmt->bits[0], fmt->bits[1]);
+       fbits = 0;
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               fp = list_entry(p, struct audioformat, list);
+               if (!hw_check_valid_format(subs, params, fp))
+                       continue;
+               fbits |= fp->formats;
+       }
+
+       oldbits[0] = fmt->bits[0];
+       oldbits[1] = fmt->bits[1];
+       fmt->bits[0] &= (u32)fbits;
+       fmt->bits[1] &= (u32)(fbits >> 32);
+       if (!fmt->bits[0] && !fmt->bits[1]) {
+               hwc_debug("  --> get empty\n");
+               return -EINVAL;
+       }
+       changed = (oldbits[0] != fmt->bits[0] || oldbits[1] != fmt->bits[1]);
+       hwc_debug("  --> %x:%x (changed = %d)\n", fmt->bits[0], fmt->bits[1], changed);
+       return changed;
+}
+
+static int hw_rule_period_time(struct snd_pcm_hw_params *params,
+                              struct snd_pcm_hw_rule *rule)
+{
+       struct snd_usb_substream *subs = rule->private;
+       struct audioformat *fp;
+       struct snd_interval *it;
+       unsigned char min_datainterval;
+       unsigned int pmin;
+       int changed;
+
+       it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
+       hwc_debug("hw_rule_period_time: (%u,%u)\n", it->min, it->max);
+       min_datainterval = 0xff;
+       list_for_each_entry(fp, &subs->fmt_list, list) {
+               if (!hw_check_valid_format(subs, params, fp))
+                       continue;
+               min_datainterval = min(min_datainterval, fp->datainterval);
+       }
+       if (min_datainterval == 0xff) {
+               hwc_debug("  --> get emtpy\n");
+               it->empty = 1;
+               return -EINVAL;
+       }
+       pmin = 125 * (1 << min_datainterval);
+       changed = 0;
+       if (it->min < pmin) {
+               it->min = pmin;
+               it->openmin = 0;
+               changed = 1;
+       }
+       if (snd_interval_checkempty(it)) {
+               it->empty = 1;
+               return -EINVAL;
+       }
+       hwc_debug("  --> (%u,%u) (changed = %d)\n", it->min, it->max, changed);
+       return changed;
+}
+
+/*
+ *  If the device supports unusual bit rates, does the request meet these?
+ */
+static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
+                                 struct snd_usb_substream *subs)
+{
+       struct audioformat *fp;
+       int count = 0, needs_knot = 0;
+       int err;
+
+       list_for_each_entry(fp, &subs->fmt_list, list) {
+               if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
+                       return 0;
+               count += fp->nr_rates;
+               if (fp->rates & SNDRV_PCM_RATE_KNOT)
+                       needs_knot = 1;
+       }
+       if (!needs_knot)
+               return 0;
+
+       subs->rate_list.count = count;
+       subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL);
+       subs->rate_list.mask = 0;
+       count = 0;
+       list_for_each_entry(fp, &subs->fmt_list, list) {
+               int i;
+               for (i = 0; i < fp->nr_rates; i++)
+                       subs->rate_list.list[count++] = fp->rate_table[i];
+       }
+       err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                        &subs->rate_list);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+
+/*
+ * set up the runtime hardware information.
+ */
+
+static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs)
+{
+       struct list_head *p;
+       unsigned int pt, ptmin;
+       int param_period_time_if_needed;
+       int err;
+
+       runtime->hw.formats = subs->formats;
+
+       runtime->hw.rate_min = 0x7fffffff;
+       runtime->hw.rate_max = 0;
+       runtime->hw.channels_min = 256;
+       runtime->hw.channels_max = 0;
+       runtime->hw.rates = 0;
+       ptmin = UINT_MAX;
+       /* check min/max rates and channels */
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               fp = list_entry(p, struct audioformat, list);
+               runtime->hw.rates |= fp->rates;
+               if (runtime->hw.rate_min > fp->rate_min)
+                       runtime->hw.rate_min = fp->rate_min;
+               if (runtime->hw.rate_max < fp->rate_max)
+                       runtime->hw.rate_max = fp->rate_max;
+               if (runtime->hw.channels_min > fp->channels)
+                       runtime->hw.channels_min = fp->channels;
+               if (runtime->hw.channels_max < fp->channels)
+                       runtime->hw.channels_max = fp->channels;
+               if (fp->fmt_type == UAC_FORMAT_TYPE_II && fp->frame_size > 0) {
+                       /* FIXME: there might be more than one audio formats... */
+                       runtime->hw.period_bytes_min = runtime->hw.period_bytes_max =
+                               fp->frame_size;
+               }
+               pt = 125 * (1 << fp->datainterval);
+               ptmin = min(ptmin, pt);
+       }
+
+       param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME;
+       if (snd_usb_get_speed(subs->dev) != USB_SPEED_HIGH)
+               /* full speed devices have fixed data packet interval */
+               ptmin = 1000;
+       if (ptmin == 1000)
+               /* if period time doesn't go below 1 ms, no rules needed */
+               param_period_time_if_needed = -1;
+       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                    ptmin, UINT_MAX);
+
+       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                      hw_rule_rate, subs,
+                                      SNDRV_PCM_HW_PARAM_FORMAT,
+                                      SNDRV_PCM_HW_PARAM_CHANNELS,
+                                      param_period_time_if_needed,
+                                      -1)) < 0)
+               return err;
+       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
+                                      hw_rule_channels, subs,
+                                      SNDRV_PCM_HW_PARAM_FORMAT,
+                                      SNDRV_PCM_HW_PARAM_RATE,
+                                      param_period_time_if_needed,
+                                      -1)) < 0)
+               return err;
+       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
+                                      hw_rule_format, subs,
+                                      SNDRV_PCM_HW_PARAM_RATE,
+                                      SNDRV_PCM_HW_PARAM_CHANNELS,
+                                      param_period_time_if_needed,
+                                      -1)) < 0)
+               return err;
+       if (param_period_time_if_needed >= 0) {
+               err = snd_pcm_hw_rule_add(runtime, 0,
+                                         SNDRV_PCM_HW_PARAM_PERIOD_TIME,
+                                         hw_rule_period_time, subs,
+                                         SNDRV_PCM_HW_PARAM_FORMAT,
+                                         SNDRV_PCM_HW_PARAM_CHANNELS,
+                                         SNDRV_PCM_HW_PARAM_RATE,
+                                         -1);
+               if (err < 0)
+                       return err;
+       }
+       if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0)
+               return err;
+       return 0;
+}
+
+static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
+{
+       struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_usb_substream *subs = &as->substream[direction];
+
+       subs->interface = -1;
+       subs->altset_idx = 0;
+       runtime->hw = snd_usb_hardware;
+       runtime->private_data = subs;
+       subs->pcm_substream = substream;
+       return setup_hw_info(runtime, subs);
+}
+
+static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
+{
+       struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
+       struct snd_usb_substream *subs = &as->substream[direction];
+
+       if (!as->chip->shutdown && subs->interface >= 0) {
+               usb_set_interface(subs->dev, subs->interface, 0);
+               subs->interface = -1;
+       }
+       subs->pcm_substream = NULL;
+       return 0;
+}
+
+static int snd_usb_playback_open(struct snd_pcm_substream *substream)
+{
+       return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_PLAYBACK);
+}
+
+static int snd_usb_playback_close(struct snd_pcm_substream *substream)
+{
+       return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_PLAYBACK);
+}
+
+static int snd_usb_capture_open(struct snd_pcm_substream *substream)
+{
+       return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_CAPTURE);
+}
+
+static int snd_usb_capture_close(struct snd_pcm_substream *substream)
+{
+       return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
+}
+
+static struct snd_pcm_ops snd_usb_playback_ops = {
+       .open =         snd_usb_playback_open,
+       .close =        snd_usb_playback_close,
+       .ioctl =        snd_pcm_lib_ioctl,
+       .hw_params =    snd_usb_hw_params,
+       .hw_free =      snd_usb_hw_free,
+       .prepare =      snd_usb_pcm_prepare,
+       .trigger =      snd_usb_substream_playback_trigger,
+       .pointer =      snd_usb_pcm_pointer,
+       .page =         snd_pcm_lib_get_vmalloc_page,
+       .mmap =         snd_pcm_lib_mmap_vmalloc,
+};
+
+static struct snd_pcm_ops snd_usb_capture_ops = {
+       .open =         snd_usb_capture_open,
+       .close =        snd_usb_capture_close,
+       .ioctl =        snd_pcm_lib_ioctl,
+       .hw_params =    snd_usb_hw_params,
+       .hw_free =      snd_usb_hw_free,
+       .prepare =      snd_usb_pcm_prepare,
+       .trigger =      snd_usb_substream_capture_trigger,
+       .pointer =      snd_usb_pcm_pointer,
+       .page =         snd_pcm_lib_get_vmalloc_page,
+       .mmap =         snd_pcm_lib_mmap_vmalloc,
+};
+
+void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream)
+{
+       snd_pcm_set_ops(pcm, stream,
+                       stream == SNDRV_PCM_STREAM_PLAYBACK ?
+                       &snd_usb_playback_ops : &snd_usb_capture_ops);
+}
diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h
new file mode 100644 (file)
index 0000000..1c931b6
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __USBAUDIO_PCM_H
+#define __USBAUDIO_PCM_H
+
+void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream);
+
+int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
+                      struct usb_host_interface *alts,
+                      struct audioformat *fmt);
+
+int snd_usb_init_sample_rate(struct snd_usb_audio *chip, int iface,
+                            struct usb_host_interface *alts,
+                            struct audioformat *fmt, int rate);
+
+#endif /* __USBAUDIO_PCM_H */
diff --git a/sound/usb/proc.c b/sound/usb/proc.c
new file mode 100644 (file)
index 0000000..f5e3f35
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/usb.h>
+
+#include <sound/core.h>
+#include <sound/info.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "helper.h"
+#include "card.h"
+#include "proc.h"
+
+/* convert our full speed USB rate into sampling rate in Hz */
+static inline unsigned get_full_speed_hz(unsigned int usb_rate)
+{
+       return (usb_rate * 125 + (1 << 12)) >> 13;
+}
+
+/* convert our high speed USB rate into sampling rate in Hz */
+static inline unsigned get_high_speed_hz(unsigned int usb_rate)
+{
+       return (usb_rate * 125 + (1 << 9)) >> 10;
+}
+
+/*
+ * common proc files to show the usb device info
+ */
+static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
+{
+       struct snd_usb_audio *chip = entry->private_data;
+       if (!chip->shutdown)
+               snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
+}
+
+static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
+{
+       struct snd_usb_audio *chip = entry->private_data;
+       if (!chip->shutdown)
+               snd_iprintf(buffer, "%04x:%04x\n", 
+                           USB_ID_VENDOR(chip->usb_id),
+                           USB_ID_PRODUCT(chip->usb_id));
+}
+
+void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
+{
+       struct snd_info_entry *entry;
+       if (!snd_card_proc_new(chip->card, "usbbus", &entry))
+               snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
+       if (!snd_card_proc_new(chip->card, "usbid", &entry))
+               snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
+}
+
+/*
+ * proc interface for list the supported pcm formats
+ */
+static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
+{
+       struct list_head *p;
+       static char *sync_types[4] = {
+               "NONE", "ASYNC", "ADAPTIVE", "SYNC"
+       };
+
+       list_for_each(p, &subs->fmt_list) {
+               struct audioformat *fp;
+               snd_pcm_format_t fmt;
+               fp = list_entry(p, struct audioformat, list);
+               snd_iprintf(buffer, "  Interface %d\n", fp->iface);
+               snd_iprintf(buffer, "    Altset %d\n", fp->altsetting);
+               snd_iprintf(buffer, "    Format:");
+               for (fmt = 0; fmt <= SNDRV_PCM_FORMAT_LAST; ++fmt)
+                       if (fp->formats & (1uLL << fmt))
+                               snd_iprintf(buffer, " %s",
+                                           snd_pcm_format_name(fmt));
+               snd_iprintf(buffer, "\n");
+               snd_iprintf(buffer, "    Channels: %d\n", fp->channels);
+               snd_iprintf(buffer, "    Endpoint: %d %s (%s)\n",
+                           fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
+                           fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
+                           sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
+               if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
+                       snd_iprintf(buffer, "    Rates: %d - %d (continuous)\n",
+                                   fp->rate_min, fp->rate_max);
+               } else {
+                       unsigned int i;
+                       snd_iprintf(buffer, "    Rates: ");
+                       for (i = 0; i < fp->nr_rates; i++) {
+                               if (i > 0)
+                                       snd_iprintf(buffer, ", ");
+                               snd_iprintf(buffer, "%d", fp->rate_table[i]);
+                       }
+                       snd_iprintf(buffer, "\n");
+               }
+               if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH)
+                       snd_iprintf(buffer, "    Data packet interval: %d us\n",
+                                   125 * (1 << fp->datainterval));
+               // snd_iprintf(buffer, "    Max Packet Size = %d\n", fp->maxpacksize);
+               // snd_iprintf(buffer, "    EP Attribute = %#x\n", fp->attributes);
+       }
+}
+
+static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
+{
+       if (subs->running) {
+               unsigned int i;
+               snd_iprintf(buffer, "  Status: Running\n");
+               snd_iprintf(buffer, "    Interface = %d\n", subs->interface);
+               snd_iprintf(buffer, "    Altset = %d\n", subs->altset_idx);
+               snd_iprintf(buffer, "    URBs = %d [ ", subs->nurbs);
+               for (i = 0; i < subs->nurbs; i++)
+                       snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
+               snd_iprintf(buffer, "]\n");
+               snd_iprintf(buffer, "    Packet Size = %d\n", subs->curpacksize);
+               snd_iprintf(buffer, "    Momentary freq = %u Hz (%#x.%04x)\n",
+                           snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
+                           ? get_full_speed_hz(subs->freqm)
+                           : get_high_speed_hz(subs->freqm),
+                           subs->freqm >> 16, subs->freqm & 0xffff);
+       } else {
+               snd_iprintf(buffer, "  Status: Stop\n");
+       }
+}
+
+static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
+{
+       struct snd_usb_stream *stream = entry->private_data;
+
+       snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
+
+       if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
+               snd_iprintf(buffer, "\nPlayback:\n");
+               proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
+               proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
+       }
+       if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
+               snd_iprintf(buffer, "\nCapture:\n");
+               proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
+               proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
+       }
+}
+
+void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream)
+{
+       struct snd_info_entry *entry;
+       char name[32];
+       struct snd_card *card = stream->chip->card;
+
+       sprintf(name, "stream%d", stream->pcm_index);
+       if (!snd_card_proc_new(card, name, &entry))
+               snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
+}
+
diff --git a/sound/usb/proc.h b/sound/usb/proc.h
new file mode 100644 (file)
index 0000000..a45b765
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __USBAUDIO_PROC_H
+#define __USBAUDIO_PROC_H
+
+void snd_usb_audio_create_proc(struct snd_usb_audio *chip);
+void snd_usb_proc_pcm_format_add(struct snd_usb_stream *stream);
+
+#endif /* __USBAUDIO_PROC_H */
+
similarity index 97%
rename from sound/usb/usbquirks.h
rename to sound/usb/quirks-table.h
index 2b426c1..91ddef3 100644 (file)
@@ -279,7 +279,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 0,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S16_LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S16_LE,
                                        .channels = 4,
                                        .iface = 0,
                                        .altsetting = 1,
@@ -296,7 +296,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 1,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S16_LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S16_LE,
                                        .channels = 2,
                                        .iface = 1,
                                        .altsetting = 1,
@@ -580,7 +580,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 0,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S24_3LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S24_3LE,
                                        .channels = 2,
                                        .iface = 0,
                                        .altsetting = 1,
@@ -597,7 +597,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 1,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S24_3LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S24_3LE,
                                        .channels = 2,
                                        .iface = 1,
                                        .altsetting = 1,
@@ -793,7 +793,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 1,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S24_3LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S24_3LE,
                                        .channels = 2,
                                        .iface = 1,
                                        .altsetting = 1,
@@ -810,7 +810,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 2,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = & (const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S24_3LE,
+                                       .formats = SNDRV_PCM_FMTBIT_S24_3LE,
                                        .channels = 2,
                                        .iface = 2,
                                        .altsetting = 1,
@@ -1826,6 +1826,60 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                }
        }
 },
+{
+       USB_DEVICE(0x0763, 0x2080),
+       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
+               /* .vendor_name = "M-Audio", */
+               /* .product_name = "Fast Track Ultra 8", */
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_COMPOSITE,
+               .data = & (const struct snd_usb_audio_quirk[]) {
+                       {
+                               .ifnum = 0,
+                               .type = QUIRK_IGNORE_INTERFACE
+                       },
+                       {
+                               .ifnum = 1,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       {
+                               .ifnum = 2,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       /* interface 3 (MIDI) is standard compliant */
+                       {
+                               .ifnum = -1
+                       }
+               }
+       }
+},
+{
+       USB_DEVICE(0x0763, 0x2081),
+       .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
+               /* .vendor_name = "M-Audio", */
+               /* .product_name = "Fast Track Ultra 8R", */
+               .ifnum = QUIRK_ANY_INTERFACE,
+               .type = QUIRK_COMPOSITE,
+               .data = & (const struct snd_usb_audio_quirk[]) {
+                       {
+                               .ifnum = 0,
+                               .type = QUIRK_IGNORE_INTERFACE
+                       },
+                       {
+                               .ifnum = 1,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       {
+                               .ifnum = 2,
+                               .type = QUIRK_AUDIO_STANDARD_INTERFACE
+                       },
+                       /* interface 3 (MIDI) is standard compliant */
+                       {
+                               .ifnum = -1
+                       }
+               }
+       }
+},
 
 /* Casio devices */
 {
@@ -2203,7 +2257,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
                                .ifnum = 1,
                                .type = QUIRK_AUDIO_FIXED_ENDPOINT,
                                .data = &(const struct audioformat) {
-                                       .format = SNDRV_PCM_FORMAT_S24_3BE,
+                                       .formats = SNDRV_PCM_FMTBIT_S24_3BE,
                                        .channels = 2,
                                        .iface = 1,
                                        .altsetting = 1,
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
new file mode 100644 (file)
index 0000000..136e5b4
--- /dev/null
@@ -0,0 +1,594 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ */
+
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+
+#include <sound/core.h>
+#include <sound/info.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "card.h"
+#include "mixer.h"
+#include "mixer_quirks.h"
+#include "midi.h"
+#include "quirks.h"
+#include "helper.h"
+#include "endpoint.h"
+#include "pcm.h"
+
+/*
+ * handle the quirks for the contained interfaces
+ */
+static int create_composite_quirk(struct snd_usb_audio *chip,
+                                 struct usb_interface *iface,
+                                 struct usb_driver *driver,
+                                 const struct snd_usb_audio_quirk *quirk)
+{
+       int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
+       int err;
+
+       for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) {
+               iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
+               if (!iface)
+                       continue;
+               if (quirk->ifnum != probed_ifnum &&
+                   usb_interface_claimed(iface))
+                       continue;
+               err = snd_usb_create_quirk(chip, iface, driver, quirk);
+               if (err < 0)
+                       return err;
+               if (quirk->ifnum != probed_ifnum)
+                       usb_driver_claim_interface(driver, iface, (void *)-1L);
+       }
+       return 0;
+}
+
+static int ignore_interface_quirk(struct snd_usb_audio *chip,
+                                 struct usb_interface *iface,
+                                 struct usb_driver *driver,
+                                 const struct snd_usb_audio_quirk *quirk)
+{
+       return 0;
+}
+
+
+/*
+ * Allow alignment on audio sub-slot (channel samples) rather than
+ * on audio slots (audio frames)
+ */
+static int create_align_transfer_quirk(struct snd_usb_audio *chip,
+                                      struct usb_interface *iface,
+                                      struct usb_driver *driver,
+                                      const struct snd_usb_audio_quirk *quirk)
+{
+       chip->txfr_quirk = 1;
+       return 1;       /* Continue with creating streams and mixer */
+}
+
+static int create_any_midi_quirk(struct snd_usb_audio *chip,
+                                struct usb_interface *intf,
+                                struct usb_driver *driver,
+                                const struct snd_usb_audio_quirk *quirk)
+{
+       return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
+}
+
+/*
+ * create a stream for an interface with proper descriptors
+ */
+static int create_standard_audio_quirk(struct snd_usb_audio *chip,
+                                      struct usb_interface *iface,
+                                      struct usb_driver *driver,
+                                      const struct snd_usb_audio_quirk *quirk)
+{
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       int err;
+
+       alts = &iface->altsetting[0];
+       altsd = get_iface_desc(alts);
+       err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber);
+       if (err < 0) {
+               snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
+                          altsd->bInterfaceNumber, err);
+               return err;
+       }
+       /* reset the current interface */
+       usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
+       return 0;
+}
+
+/*
+ * create a stream for an endpoint/altsetting without proper descriptors
+ */
+static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
+                                    struct usb_interface *iface,
+                                    struct usb_driver *driver,
+                                    const struct snd_usb_audio_quirk *quirk)
+{
+       struct audioformat *fp;
+       struct usb_host_interface *alts;
+       int stream, err;
+       unsigned *rate_table = NULL;
+
+       fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
+       if (! fp) {
+               snd_printk(KERN_ERR "cannot memdup\n");
+               return -ENOMEM;
+       }
+       if (fp->nr_rates > 0) {
+               rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
+               if (!rate_table) {
+                       kfree(fp);
+                       return -ENOMEM;
+               }
+               memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
+               fp->rate_table = rate_table;
+       }
+
+       stream = (fp->endpoint & USB_DIR_IN)
+               ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+       err = snd_usb_add_audio_endpoint(chip, stream, fp);
+       if (err < 0) {
+               kfree(fp);
+               kfree(rate_table);
+               return err;
+       }
+       if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
+           fp->altset_idx >= iface->num_altsetting) {
+               kfree(fp);
+               kfree(rate_table);
+               return -EINVAL;
+       }
+       alts = &iface->altsetting[fp->altset_idx];
+       fp->datainterval = snd_usb_parse_datainterval(chip, alts);
+       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
+       usb_set_interface(chip->dev, fp->iface, 0);
+       snd_usb_init_pitch(chip, fp->iface, alts, fp);
+       snd_usb_init_sample_rate(chip, fp->iface, alts, fp, fp->rate_max);
+       return 0;
+}
+
+/*
+ * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.  
+ * The only way to detect the sample rate is by looking at wMaxPacketSize.
+ */
+static int create_uaxx_quirk(struct snd_usb_audio *chip,
+                            struct usb_interface *iface,
+                            struct usb_driver *driver,
+                            const struct snd_usb_audio_quirk *quirk)
+{
+       static const struct audioformat ua_format = {
+               .formats = SNDRV_PCM_FMTBIT_S24_3LE,
+               .channels = 2,
+               .fmt_type = UAC_FORMAT_TYPE_I,
+               .altsetting = 1,
+               .altset_idx = 1,
+               .rates = SNDRV_PCM_RATE_CONTINUOUS,
+       };
+       struct usb_host_interface *alts;
+       struct usb_interface_descriptor *altsd;
+       struct audioformat *fp;
+       int stream, err;
+
+       /* both PCM and MIDI interfaces have 2 or more altsettings */
+       if (iface->num_altsetting < 2)
+               return -ENXIO;
+       alts = &iface->altsetting[1];
+       altsd = get_iface_desc(alts);
+
+       if (altsd->bNumEndpoints == 2) {
+               static const struct snd_usb_midi_endpoint_info ua700_ep = {
+                       .out_cables = 0x0003,
+                       .in_cables  = 0x0003
+               };
+               static const struct snd_usb_audio_quirk ua700_quirk = {
+                       .type = QUIRK_MIDI_FIXED_ENDPOINT,
+                       .data = &ua700_ep
+               };
+               static const struct snd_usb_midi_endpoint_info uaxx_ep = {
+                       .out_cables = 0x0001,
+                       .in_cables  = 0x0001
+               };
+               static const struct snd_usb_audio_quirk uaxx_quirk = {
+                       .type = QUIRK_MIDI_FIXED_ENDPOINT,
+                       .data = &uaxx_ep
+               };
+               const struct snd_usb_audio_quirk *quirk =
+                       chip->usb_id == USB_ID(0x0582, 0x002b)
+                       ? &ua700_quirk : &uaxx_quirk;
+               return snd_usbmidi_create(chip->card, iface,
+                                         &chip->midi_list, quirk);
+       }
+
+       if (altsd->bNumEndpoints != 1)
+               return -ENXIO;
+
+       fp = kmalloc(sizeof(*fp), GFP_KERNEL);
+       if (!fp)
+               return -ENOMEM;
+       memcpy(fp, &ua_format, sizeof(*fp));
+
+       fp->iface = altsd->bInterfaceNumber;
+       fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
+       fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
+       fp->datainterval = 0;
+       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
+
+       switch (fp->maxpacksize) {
+       case 0x120:
+               fp->rate_max = fp->rate_min = 44100;
+               break;
+       case 0x138:
+       case 0x140:
+               fp->rate_max = fp->rate_min = 48000;
+               break;
+       case 0x258:
+       case 0x260:
+               fp->rate_max = fp->rate_min = 96000;
+               break;
+       default:
+               snd_printk(KERN_ERR "unknown sample rate\n");
+               kfree(fp);
+               return -ENXIO;
+       }
+
+       stream = (fp->endpoint & USB_DIR_IN)
+               ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+       err = snd_usb_add_audio_endpoint(chip, stream, fp);
+       if (err < 0) {
+               kfree(fp);
+               return err;
+       }
+       usb_set_interface(chip->dev, fp->iface, 0);
+       return 0;
+}
+
+/*
+ * audio-interface quirks
+ *
+ * returns zero if no standard audio/MIDI parsing is needed.
+ * returns a postive value if standard audio/midi interfaces are parsed
+ * after this.
+ * returns a negative value at error.
+ */
+int snd_usb_create_quirk(struct snd_usb_audio *chip,
+                        struct usb_interface *iface,
+                        struct usb_driver *driver,
+                        const struct snd_usb_audio_quirk *quirk)
+{
+       typedef int (*quirk_func_t)(struct snd_usb_audio *,
+                                   struct usb_interface *,
+                                   struct usb_driver *,
+                                   const struct snd_usb_audio_quirk *);
+       static const quirk_func_t quirk_funcs[] = {
+               [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
+               [QUIRK_COMPOSITE] = create_composite_quirk,
+               [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
+               [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
+               [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
+               [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
+               [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
+               [QUIRK_MIDI_FASTLANE] = create_any_midi_quirk,
+               [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
+               [QUIRK_MIDI_CME] = create_any_midi_quirk,
+               [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
+               [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
+               [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
+               [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
+       };
+
+       if (quirk->type < QUIRK_TYPE_COUNT) {
+               return quirk_funcs[quirk->type](chip, iface, driver, quirk);
+       } else {
+               snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
+               return -ENXIO;
+       }
+}
+
+/*
+ * boot quirks
+ */
+
+#define EXTIGY_FIRMWARE_SIZE_OLD 794
+#define EXTIGY_FIRMWARE_SIZE_NEW 483
+
+static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
+{
+       struct usb_host_config *config = dev->actconfig;
+       int err;
+
+       if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
+           le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
+               snd_printdd("sending Extigy boot sequence...\n");
+               /* Send message to force it to reconnect with full interface. */
+               err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
+                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
+               if (err < 0) snd_printdd("error sending boot message: %d\n", err);
+               err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
+                               &dev->descriptor, sizeof(dev->descriptor));
+               config = dev->actconfig;
+               if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
+               err = usb_reset_configuration(dev);
+               if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
+               snd_printdd("extigy_boot: new boot length = %d\n",
+                           le16_to_cpu(get_cfg_desc(config)->wTotalLength));
+               return -ENODEV; /* quit this anyway */
+       }
+       return 0;
+}
+
+static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
+{
+       u8 buf = 1;
+
+       snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
+                       USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+                       0, 0, &buf, 1, 1000);
+       if (buf == 0) {
+               snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
+                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
+                               1, 2000, NULL, 0, 1000);
+               return -ENODEV;
+       }
+       return 0;
+}
+
+/*
+ * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
+ * documented in the device's data sheet.
+ */
+static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
+{
+       u8 buf[4];
+       buf[0] = 0x20;
+       buf[1] = value & 0xff;
+       buf[2] = (value >> 8) & 0xff;
+       buf[3] = reg;
+       return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
+                              USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
+                              0, 0, &buf, 4, 1000);
+}
+
+static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
+{
+       /*
+        * Enable line-out driver mode, set headphone source to front
+        * channels, enable stereo mic.
+        */
+       return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
+}
+
+/*
+ * C-Media CM6206 is based on CM106 with two additional
+ * registers that are not documented in the data sheet.
+ * Values here are chosen based on sniffing USB traffic
+ * under Windows.
+ */
+static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
+{
+       int err, reg;
+       int val[] = {0x200c, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
+
+       for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
+               err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
+               if (err < 0)
+                       return err;
+       }
+
+       return err;
+}
+
+/*
+ * This call will put the synth in "USB send" mode, i.e it will send MIDI
+ * messages through USB (this is disabled at startup). The synth will
+ * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
+ * sign on its LCD. Values here are chosen based on sniffing USB traffic
+ * under Windows.
+ */
+static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
+{
+       int err, actual_length;
+
+       /* "midi send" enable */
+       static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
+
+       void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+       err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
+                       ARRAY_SIZE(seq), &actual_length, 1000);
+       kfree(buf);
+       if (err < 0)
+               return err;
+
+       return 0;
+}
+
+/*
+ * Setup quirks
+ */
+#define AUDIOPHILE_SET                 0x01 /* if set, parse device_setup */
+#define AUDIOPHILE_SET_DTS              0x02 /* if set, enable DTS Digital Output */
+#define AUDIOPHILE_SET_96K              0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
+#define AUDIOPHILE_SET_24B             0x08 /* 24bits sample if set, 16bits otherwise */
+#define AUDIOPHILE_SET_DI              0x10 /* if set, enable Digital Input */
+#define AUDIOPHILE_SET_MASK            0x1F /* bit mask for setup value */
+#define AUDIOPHILE_SET_24B_48K_DI      0x19 /* value for 24bits+48KHz+Digital Input */
+#define AUDIOPHILE_SET_24B_48K_NOTDI   0x09 /* value for 24bits+48KHz+No Digital Input */
+#define AUDIOPHILE_SET_16B_48K_DI      0x11 /* value for 16bits+48KHz+Digital Input */
+#define AUDIOPHILE_SET_16B_48K_NOTDI   0x01 /* value for 16bits+48KHz+No Digital Input */
+
+static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
+                                        int iface,
+                                        int altno)
+{
+       /* Reset ALL ifaces to 0 altsetting.
+        * Call it for every possible altsetting of every interface.
+        */
+       usb_set_interface(chip->dev, iface, 0);
+
+       if (chip->setup & AUDIOPHILE_SET) {
+               if ((chip->setup & AUDIOPHILE_SET_DTS)
+                   && altno != 6)
+                       return 1; /* skip this altsetting */
+               if ((chip->setup & AUDIOPHILE_SET_96K)
+                   && altno != 1)
+                       return 1; /* skip this altsetting */
+               if ((chip->setup & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_24B_48K_DI && altno != 2)
+                       return 1; /* skip this altsetting */
+               if ((chip->setup & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3)
+                       return 1; /* skip this altsetting */
+               if ((chip->setup & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_16B_48K_DI && altno != 4)
+                       return 1; /* skip this altsetting */
+               if ((chip->setup & AUDIOPHILE_SET_MASK) ==
+                   AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5)
+                       return 1; /* skip this altsetting */
+       }
+
+       return 0; /* keep this altsetting */
+}
+
+int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
+                                 int iface,
+                                 int altno)
+{
+       /* audiophile usb: skip altsets incompatible with device_setup */
+       if (chip->usb_id == USB_ID(0x0763, 0x2003))
+               return audiophile_skip_setting_quirk(chip, iface, altno);
+
+       return 0;
+}
+
+int snd_usb_apply_boot_quirk(struct usb_device *dev,
+                            struct usb_interface *intf,
+                            const struct snd_usb_audio_quirk *quirk)
+{
+       u32 id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
+                       le16_to_cpu(dev->descriptor.idProduct));
+
+       /* SB Extigy needs special boot-up sequence */
+       /* if more models come, this will go to the quirk list. */
+       if (id == USB_ID(0x041e, 0x3000))
+               return snd_usb_extigy_boot_quirk(dev, intf);
+
+       /* SB Audigy 2 NX needs its own boot-up magic, too */
+       if (id == USB_ID(0x041e, 0x3020))
+               return snd_usb_audigy2nx_boot_quirk(dev);
+
+       /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
+       if (id == USB_ID(0x10f5, 0x0200))
+               return snd_usb_cm106_boot_quirk(dev);
+
+       /* C-Media CM6206 / CM106-Like Sound Device */
+       if (id == USB_ID(0x0d8c, 0x0102))
+               return snd_usb_cm6206_boot_quirk(dev);
+
+       /* Access Music VirusTI Desktop */
+       if (id == USB_ID(0x133e, 0x0815))
+               return snd_usb_accessmusic_boot_quirk(dev);
+
+       return 0;
+}
+
+/*
+ * check if the device uses big-endian samples
+ */
+int snd_usb_is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
+{
+       switch (chip->usb_id) {
+       case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
+               if (fp->endpoint & USB_DIR_IN)
+                       return 1;
+               break;
+       case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
+               if (chip->setup == 0x00 ||
+                   fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3)
+                       return 1;
+       }
+       return 0;
+}
+
+/*
+ * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device,
+ * not for interface.
+ */
+
+enum {
+       EMU_QUIRK_SR_44100HZ = 0,
+       EMU_QUIRK_SR_48000HZ,
+       EMU_QUIRK_SR_88200HZ,
+       EMU_QUIRK_SR_96000HZ,
+       EMU_QUIRK_SR_176400HZ,
+       EMU_QUIRK_SR_192000HZ
+};
+
+static void set_format_emu_quirk(struct snd_usb_substream *subs,
+                                struct audioformat *fmt)
+{
+       unsigned char emu_samplerate_id = 0;
+
+       /* When capture is active
+        * sample rate shouldn't be changed
+        * by playback substream
+        */
+       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
+               if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
+                       return;
+       }
+
+       switch (fmt->rate_min) {
+       case 48000:
+               emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
+               break;
+       case 88200:
+               emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
+               break;
+       case 96000:
+               emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
+               break;
+       case 176400:
+               emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
+               break;
+       case 192000:
+               emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
+               break;
+       default:
+               emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
+               break;
+       }
+       snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
+}
+
+void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
+                             struct audioformat *fmt)
+{
+       switch (subs->stream->chip->usb_id) {
+       case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
+       case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
+       case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
+               set_format_emu_quirk(subs, fmt);
+               break;
+       }
+}
+
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
new file mode 100644 (file)
index 0000000..03e5e94
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __USBAUDIO_QUIRKS_H
+#define __USBAUDIO_QUIRKS_H
+
+int snd_usb_create_quirk(struct snd_usb_audio *chip,
+                        struct usb_interface *iface,
+                        struct usb_driver *driver,
+                        const struct snd_usb_audio_quirk *quirk);
+
+int snd_usb_apply_interface_quirk(struct snd_usb_audio *chip,
+                                 int iface,
+                                 int altno);
+
+int snd_usb_apply_boot_quirk(struct usb_device *dev,
+                            struct usb_interface *intf,
+                            const struct snd_usb_audio_quirk *quirk);
+
+void snd_usb_set_format_quirk(struct snd_usb_substream *subs,
+                             struct audioformat *fmt);
+
+int snd_usb_is_big_endian_format(struct snd_usb_audio *chip,
+                                struct audioformat *fp);
+
+#endif /* __USBAUDIO_QUIRKS_H */
diff --git a/sound/usb/urb.c b/sound/usb/urb.c
new file mode 100644 (file)
index 0000000..5570a2b
--- /dev/null
@@ -0,0 +1,995 @@
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+ *
+ */
+
+#include <linux/gfp.h>
+#include <linux/init.h>
+#include <linux/usb.h>
+#include <linux/usb/audio.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+
+#include "usbaudio.h"
+#include "helper.h"
+#include "card.h"
+#include "urb.h"
+#include "pcm.h"
+
+/*
+ * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
+ * this will overflow at approx 524 kHz
+ */
+static inline unsigned get_usb_full_speed_rate(unsigned int rate)
+{
+       return ((rate << 13) + 62) / 125;
+}
+
+/*
+ * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
+ * this will overflow at approx 4 MHz
+ */
+static inline unsigned get_usb_high_speed_rate(unsigned int rate)
+{
+       return ((rate << 10) + 62) / 125;
+}
+
+/*
+ * unlink active urbs.
+ */
+static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
+{
+       struct snd_usb_audio *chip = subs->stream->chip;
+       unsigned int i;
+       int async;
+
+       subs->running = 0;
+
+       if (!force && subs->stream->chip->shutdown) /* to be sure... */
+               return -EBADFD;
+
+       async = !can_sleep && chip->async_unlink;
+
+       if (!async && in_interrupt())
+               return 0;
+
+       for (i = 0; i < subs->nurbs; i++) {
+               if (test_bit(i, &subs->active_mask)) {
+                       if (!test_and_set_bit(i, &subs->unlink_mask)) {
+                               struct urb *u = subs->dataurb[i].urb;
+                               if (async)
+                                       usb_unlink_urb(u);
+                               else
+                                       usb_kill_urb(u);
+                       }
+               }
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       if (test_bit(i+16, &subs->active_mask)) {
+                               if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
+                                       struct urb *u = subs->syncurb[i].urb;
+                                       if (async)
+                                               usb_unlink_urb(u);
+                                       else
+                                               usb_kill_urb(u);
+                               }
+                       }
+               }
+       }
+       return 0;
+}
+
+
+/*
+ * release a urb data
+ */
+static void release_urb_ctx(struct snd_urb_ctx *u)
+{
+       if (u->urb) {
+               if (u->buffer_size)
+                       usb_buffer_free(u->subs->dev, u->buffer_size,
+                                       u->urb->transfer_buffer,
+                                       u->urb->transfer_dma);
+               usb_free_urb(u->urb);
+               u->urb = NULL;
+       }
+}
+
+/*
+ *  wait until all urbs are processed.
+ */
+static int wait_clear_urbs(struct snd_usb_substream *subs)
+{
+       unsigned long end_time = jiffies + msecs_to_jiffies(1000);
+       unsigned int i;
+       int alive;
+
+       do {
+               alive = 0;
+               for (i = 0; i < subs->nurbs; i++) {
+                       if (test_bit(i, &subs->active_mask))
+                               alive++;
+               }
+               if (subs->syncpipe) {
+                       for (i = 0; i < SYNC_URBS; i++) {
+                               if (test_bit(i + 16, &subs->active_mask))
+                                       alive++;
+                       }
+               }
+               if (! alive)
+                       break;
+               schedule_timeout_uninterruptible(1);
+       } while (time_before(jiffies, end_time));
+       if (alive)
+               snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
+       return 0;
+}
+
+/*
+ * release a substream
+ */
+void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force)
+{
+       int i;
+
+       /* stop urbs (to be sure) */
+       deactivate_urbs(subs, force, 1);
+       wait_clear_urbs(subs);
+
+       for (i = 0; i < MAX_URBS; i++)
+               release_urb_ctx(&subs->dataurb[i]);
+       for (i = 0; i < SYNC_URBS; i++)
+               release_urb_ctx(&subs->syncurb[i]);
+       usb_buffer_free(subs->dev, SYNC_URBS * 4,
+                       subs->syncbuf, subs->sync_dma);
+       subs->syncbuf = NULL;
+       subs->nurbs = 0;
+}
+
+/*
+ * complete callback from data urb
+ */
+static void snd_complete_urb(struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+       struct snd_usb_substream *subs = ctx->subs;
+       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
+       int err = 0;
+
+       if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
+           !subs->running || /* can be stopped during retire callback */
+           (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
+           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               clear_bit(ctx->index, &subs->active_mask);
+               if (err < 0) {
+                       snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
+                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
+               }
+       }
+}
+
+
+/*
+ * complete callback from sync urb
+ */
+static void snd_complete_sync_urb(struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+       struct snd_usb_substream *subs = ctx->subs;
+       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
+       int err = 0;
+
+       if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
+           !subs->running || /* can be stopped during retire callback */
+           (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
+           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
+               clear_bit(ctx->index + 16, &subs->active_mask);
+               if (err < 0) {
+                       snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
+                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
+               }
+       }
+}
+
+
+/*
+ * initialize a substream for plaback/capture
+ */
+int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
+                               unsigned int period_bytes,
+                               unsigned int rate,
+                               unsigned int frame_bits)
+{
+       unsigned int maxsize, i;
+       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
+       unsigned int urb_packs, total_packs, packs_per_ms;
+       struct snd_usb_audio *chip = subs->stream->chip;
+
+       /* calculate the frequency in 16.16 format */
+       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
+               subs->freqn = get_usb_full_speed_rate(rate);
+       else
+               subs->freqn = get_usb_high_speed_rate(rate);
+       subs->freqm = subs->freqn;
+       /* calculate max. frequency */
+       if (subs->maxpacksize) {
+               /* whatever fits into a max. size packet */
+               maxsize = subs->maxpacksize;
+               subs->freqmax = (maxsize / (frame_bits >> 3))
+                               << (16 - subs->datainterval);
+       } else {
+               /* no max. packet size: just take 25% higher than nominal */
+               subs->freqmax = subs->freqn + (subs->freqn >> 2);
+               maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
+                               >> (16 - subs->datainterval);
+       }
+       subs->phase = 0;
+
+       if (subs->fill_max)
+               subs->curpacksize = subs->maxpacksize;
+       else
+               subs->curpacksize = maxsize;
+
+       if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH)
+               packs_per_ms = 8 >> subs->datainterval;
+       else
+               packs_per_ms = 1;
+
+       if (is_playback) {
+               urb_packs = max(chip->nrpacks, 1);
+               urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
+       } else
+               urb_packs = 1;
+       urb_packs *= packs_per_ms;
+       if (subs->syncpipe)
+               urb_packs = min(urb_packs, 1U << subs->syncinterval);
+
+       /* decide how many packets to be used */
+       if (is_playback) {
+               unsigned int minsize, maxpacks;
+               /* determine how small a packet can be */
+               minsize = (subs->freqn >> (16 - subs->datainterval))
+                         * (frame_bits >> 3);
+               /* with sync from device, assume it can be 12% lower */
+               if (subs->syncpipe)
+                       minsize -= minsize >> 3;
+               minsize = max(minsize, 1u);
+               total_packs = (period_bytes + minsize - 1) / minsize;
+               /* we need at least two URBs for queueing */
+               if (total_packs < 2) {
+                       total_packs = 2;
+               } else {
+                       /* and we don't want too long a queue either */
+                       maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
+                       total_packs = min(total_packs, maxpacks);
+               }
+       } else {
+               while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
+                       urb_packs >>= 1;
+               total_packs = MAX_URBS * urb_packs;
+       }
+       subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
+       if (subs->nurbs > MAX_URBS) {
+               /* too much... */
+               subs->nurbs = MAX_URBS;
+               total_packs = MAX_URBS * urb_packs;
+       } else if (subs->nurbs < 2) {
+               /* too little - we need at least two packets
+                * to ensure contiguous playback/capture
+                */
+               subs->nurbs = 2;
+       }
+
+       /* allocate and initialize data urbs */
+       for (i = 0; i < subs->nurbs; i++) {
+               struct snd_urb_ctx *u = &subs->dataurb[i];
+               u->index = i;
+               u->subs = subs;
+               u->packets = (i + 1) * total_packs / subs->nurbs
+                       - i * total_packs / subs->nurbs;
+               u->buffer_size = maxsize * u->packets;
+               if (subs->fmt_type == UAC_FORMAT_TYPE_II)
+                       u->packets++; /* for transfer delimiter */
+               u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
+               if (!u->urb)
+                       goto out_of_memory;
+               u->urb->transfer_buffer =
+                       usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL,
+                                        &u->urb->transfer_dma);
+               if (!u->urb->transfer_buffer)
+                       goto out_of_memory;
+               u->urb->pipe = subs->datapipe;
+               u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
+               u->urb->interval = 1 << subs->datainterval;
+               u->urb->context = u;
+               u->urb->complete = snd_complete_urb;
+       }
+
+       if (subs->syncpipe) {
+               /* allocate and initialize sync urbs */
+               subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4,
+                                                GFP_KERNEL, &subs->sync_dma);
+               if (!subs->syncbuf)
+                       goto out_of_memory;
+               for (i = 0; i < SYNC_URBS; i++) {
+                       struct snd_urb_ctx *u = &subs->syncurb[i];
+                       u->index = i;
+                       u->subs = subs;
+                       u->packets = 1;
+                       u->urb = usb_alloc_urb(1, GFP_KERNEL);
+                       if (!u->urb)
+                               goto out_of_memory;
+                       u->urb->transfer_buffer = subs->syncbuf + i * 4;
+                       u->urb->transfer_dma = subs->sync_dma + i * 4;
+                       u->urb->transfer_buffer_length = 4;
+                       u->urb->pipe = subs->syncpipe;
+                       u->urb->transfer_flags = URB_ISO_ASAP |
+                                                URB_NO_TRANSFER_DMA_MAP;
+                       u->urb->number_of_packets = 1;
+                       u->urb->interval = 1 << subs->syncinterval;
+                       u->urb->context = u;
+                       u->urb->complete = snd_complete_sync_urb;
+               }
+       }
+       return 0;
+
+out_of_memory:
+       snd_usb_release_substream_urbs(subs, 0);
+       return -ENOMEM;
+}
+
+/*
+ * prepare urb for full speed capture sync pipe
+ *
+ * fill the length and offset of each urb descriptor.
+ * the fixed 10.14 frequency is passed through the pipe.
+ */
+static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
+                                   struct snd_pcm_runtime *runtime,
+                                   struct urb *urb)
+{
+       unsigned char *cp = urb->transfer_buffer;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 3;
+       urb->iso_frame_desc[0].offset = 0;
+       cp[0] = subs->freqn >> 2;
+       cp[1] = subs->freqn >> 10;
+       cp[2] = subs->freqn >> 18;
+       return 0;
+}
+
+/*
+ * prepare urb for high speed capture sync pipe
+ *
+ * fill the length and offset of each urb descriptor.
+ * the fixed 12.13 frequency is passed as 16.16 through the pipe.
+ */
+static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
+                                      struct snd_pcm_runtime *runtime,
+                                      struct urb *urb)
+{
+       unsigned char *cp = urb->transfer_buffer;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 4;
+       urb->iso_frame_desc[0].offset = 0;
+       cp[0] = subs->freqn;
+       cp[1] = subs->freqn >> 8;
+       cp[2] = subs->freqn >> 16;
+       cp[3] = subs->freqn >> 24;
+       return 0;
+}
+
+/*
+ * process after capture sync complete
+ * - nothing to do
+ */
+static int retire_capture_sync_urb(struct snd_usb_substream *subs,
+                                  struct snd_pcm_runtime *runtime,
+                                  struct urb *urb)
+{
+       return 0;
+}
+
+/*
+ * prepare urb for capture data pipe
+ *
+ * fill the offset and length of each descriptor.
+ *
+ * we use a temporary buffer to write the captured data.
+ * since the length of written data is determined by host, we cannot
+ * write onto the pcm buffer directly...  the data is thus copied
+ * later at complete callback to the global buffer.
+ */
+static int prepare_capture_urb(struct snd_usb_substream *subs,
+                              struct snd_pcm_runtime *runtime,
+                              struct urb *urb)
+{
+       int i, offs;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       offs = 0;
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       for (i = 0; i < ctx->packets; i++) {
+               urb->iso_frame_desc[i].offset = offs;
+               urb->iso_frame_desc[i].length = subs->curpacksize;
+               offs += subs->curpacksize;
+       }
+       urb->transfer_buffer_length = offs;
+       urb->number_of_packets = ctx->packets;
+       return 0;
+}
+
+/*
+ * process after capture complete
+ *
+ * copy the data from each desctiptor to the pcm buffer, and
+ * update the current position.
+ */
+static int retire_capture_urb(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime,
+                             struct urb *urb)
+{
+       unsigned long flags;
+       unsigned char *cp;
+       int i;
+       unsigned int stride, frames, bytes, oldptr;
+       int period_elapsed = 0;
+
+       stride = runtime->frame_bits >> 3;
+
+       for (i = 0; i < urb->number_of_packets; i++) {
+               cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
+               if (urb->iso_frame_desc[i].status) {
+                       snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
+                       // continue;
+               }
+               bytes = urb->iso_frame_desc[i].actual_length;
+               frames = bytes / stride;
+               if (!subs->txfr_quirk)
+                       bytes = frames * stride;
+               if (bytes % (runtime->sample_bits >> 3) != 0) {
+#ifdef CONFIG_SND_DEBUG_VERBOSE
+                       int oldbytes = bytes;
+#endif
+                       bytes = frames * stride;
+                       snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
+                                                       oldbytes, bytes);
+               }
+               /* update the current pointer */
+               spin_lock_irqsave(&subs->lock, flags);
+               oldptr = subs->hwptr_done;
+               subs->hwptr_done += bytes;
+               if (subs->hwptr_done >= runtime->buffer_size * stride)
+                       subs->hwptr_done -= runtime->buffer_size * stride;
+               frames = (bytes + (oldptr % stride)) / stride;
+               subs->transfer_done += frames;
+               if (subs->transfer_done >= runtime->period_size) {
+                       subs->transfer_done -= runtime->period_size;
+                       period_elapsed = 1;
+               }
+               spin_unlock_irqrestore(&subs->lock, flags);
+               /* copy a data chunk */
+               if (oldptr + bytes > runtime->buffer_size * stride) {
+                       unsigned int bytes1 =
+                                       runtime->buffer_size * stride - oldptr;
+                       memcpy(runtime->dma_area + oldptr, cp, bytes1);
+                       memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
+               } else {
+                       memcpy(runtime->dma_area + oldptr, cp, bytes);
+               }
+       }
+       if (period_elapsed)
+               snd_pcm_period_elapsed(subs->pcm_substream);
+       return 0;
+}
+
+/*
+ * Process after capture complete when paused.  Nothing to do.
+ */
+static int retire_paused_capture_urb(struct snd_usb_substream *subs,
+                                    struct snd_pcm_runtime *runtime,
+                                    struct urb *urb)
+{
+       return 0;
+}
+
+
+/*
+ * prepare urb for full speed playback sync pipe
+ *
+ * set up the offset and length to receive the current frequency.
+ */
+
+static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
+                                    struct snd_pcm_runtime *runtime,
+                                    struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 3;
+       urb->iso_frame_desc[0].offset = 0;
+       return 0;
+}
+
+/*
+ * prepare urb for high speed playback sync pipe
+ *
+ * set up the offset and length to receive the current frequency.
+ */
+
+static int prepare_playback_sync_urb_hs(struct snd_usb_substream *subs,
+                                       struct snd_pcm_runtime *runtime,
+                                       struct urb *urb)
+{
+       struct snd_urb_ctx *ctx = urb->context;
+
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->iso_frame_desc[0].length = 4;
+       urb->iso_frame_desc[0].offset = 0;
+       return 0;
+}
+
+/*
+ * process after full speed playback sync complete
+ *
+ * retrieve the current 10.14 frequency from pipe, and set it.
+ * the value is referred in prepare_playback_urb().
+ */
+static int retire_playback_sync_urb(struct snd_usb_substream *subs,
+                                   struct snd_pcm_runtime *runtime,
+                                   struct urb *urb)
+{
+       unsigned int f;
+       unsigned long flags;
+
+       if (urb->iso_frame_desc[0].status == 0 &&
+           urb->iso_frame_desc[0].actual_length == 3) {
+               f = combine_triple((u8*)urb->transfer_buffer) << 2;
+               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
+                       spin_lock_irqsave(&subs->lock, flags);
+                       subs->freqm = f;
+                       spin_unlock_irqrestore(&subs->lock, flags);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * process after high speed playback sync complete
+ *
+ * retrieve the current 12.13 frequency from pipe, and set it.
+ * the value is referred in prepare_playback_urb().
+ */
+static int retire_playback_sync_urb_hs(struct snd_usb_substream *subs,
+                                      struct snd_pcm_runtime *runtime,
+                                      struct urb *urb)
+{
+       unsigned int f;
+       unsigned long flags;
+
+       if (urb->iso_frame_desc[0].status == 0 &&
+           urb->iso_frame_desc[0].actual_length == 4) {
+               f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
+               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
+                       spin_lock_irqsave(&subs->lock, flags);
+                       subs->freqm = f;
+                       spin_unlock_irqrestore(&subs->lock, flags);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * process after E-Mu 0202/0404/Tracker Pre high speed playback sync complete
+ *
+ * These devices return the number of samples per packet instead of the number
+ * of samples per microframe.
+ */
+static int retire_playback_sync_urb_hs_emu(struct snd_usb_substream *subs,
+                                          struct snd_pcm_runtime *runtime,
+                                          struct urb *urb)
+{
+       unsigned int f;
+       unsigned long flags;
+
+       if (urb->iso_frame_desc[0].status == 0 &&
+           urb->iso_frame_desc[0].actual_length == 4) {
+               f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
+               f >>= subs->datainterval;
+               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
+                       spin_lock_irqsave(&subs->lock, flags);
+                       subs->freqm = f;
+                       spin_unlock_irqrestore(&subs->lock, flags);
+               }
+       }
+
+       return 0;
+}
+
+/* determine the number of frames in the next packet */
+static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
+{
+       if (subs->fill_max)
+               return subs->maxframesize;
+       else {
+               subs->phase = (subs->phase & 0xffff)
+                       + (subs->freqm << subs->datainterval);
+               return min(subs->phase >> 16, subs->maxframesize);
+       }
+}
+
+/*
+ * Prepare urb for streaming before playback starts or when paused.
+ *
+ * We don't have any data, so we send silence.
+ */
+static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
+                                      struct snd_pcm_runtime *runtime,
+                                      struct urb *urb)
+{
+       unsigned int i, offs, counts;
+       struct snd_urb_ctx *ctx = urb->context;
+       int stride = runtime->frame_bits >> 3;
+
+       offs = 0;
+       urb->dev = ctx->subs->dev;
+       for (i = 0; i < ctx->packets; ++i) {
+               counts = snd_usb_audio_next_packet_size(subs);
+               urb->iso_frame_desc[i].offset = offs * stride;
+               urb->iso_frame_desc[i].length = counts * stride;
+               offs += counts;
+       }
+       urb->number_of_packets = ctx->packets;
+       urb->transfer_buffer_length = offs * stride;
+       memset(urb->transfer_buffer,
+              runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
+              offs * stride);
+       return 0;
+}
+
+/*
+ * prepare urb for playback data pipe
+ *
+ * Since a URB can handle only a single linear buffer, we must use double
+ * buffering when the data to be transferred overflows the buffer boundary.
+ * To avoid inconsistencies when updating hwptr_done, we use double buffering
+ * for all URBs.
+ */
+static int prepare_playback_urb(struct snd_usb_substream *subs,
+                               struct snd_pcm_runtime *runtime,
+                               struct urb *urb)
+{
+       int i, stride;
+       unsigned int counts, frames, bytes;
+       unsigned long flags;
+       int period_elapsed = 0;
+       struct snd_urb_ctx *ctx = urb->context;
+
+       stride = runtime->frame_bits >> 3;
+
+       frames = 0;
+       urb->dev = ctx->subs->dev; /* we need to set this at each time */
+       urb->number_of_packets = 0;
+       spin_lock_irqsave(&subs->lock, flags);
+       for (i = 0; i < ctx->packets; i++) {
+               counts = snd_usb_audio_next_packet_size(subs);
+               /* set up descriptor */
+               urb->iso_frame_desc[i].offset = frames * stride;
+               urb->iso_frame_desc[i].length = counts * stride;
+               frames += counts;
+               urb->number_of_packets++;
+               subs->transfer_done += counts;
+               if (subs->transfer_done >= runtime->period_size) {
+                       subs->transfer_done -= runtime->period_size;
+                       period_elapsed = 1;
+                       if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
+                               if (subs->transfer_done > 0) {
+                                       /* FIXME: fill-max mode is not
+                                        * supported yet */
+                                       frames -= subs->transfer_done;
+                                       counts -= subs->transfer_done;
+                                       urb->iso_frame_desc[i].length =
+                                               counts * stride;
+                                       subs->transfer_done = 0;
+                               }
+                               i++;
+                               if (i < ctx->packets) {
+                                       /* add a transfer delimiter */
+                                       urb->iso_frame_desc[i].offset =
+                                               frames * stride;
+                                       urb->iso_frame_desc[i].length = 0;
+                                       urb->number_of_packets++;
+                               }
+                               break;
+                       }
+               }
+               if (period_elapsed) /* finish at the period boundary */
+                       break;
+       }
+       bytes = frames * stride;
+       if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
+               /* err, the transferred area goes over buffer boundary. */
+               unsigned int bytes1 =
+                       runtime->buffer_size * stride - subs->hwptr_done;
+               memcpy(urb->transfer_buffer,
+                      runtime->dma_area + subs->hwptr_done, bytes1);
+               memcpy(urb->transfer_buffer + bytes1,
+                      runtime->dma_area, bytes - bytes1);
+       } else {
+               memcpy(urb->transfer_buffer,
+                      runtime->dma_area + subs->hwptr_done, bytes);
+       }
+       subs->hwptr_done += bytes;
+       if (subs->hwptr_done >= runtime->buffer_size * stride)
+               subs->hwptr_done -= runtime->buffer_size * stride;
+       runtime->delay += frames;
+       spin_unlock_irqrestore(&subs->lock, flags);
+       urb->transfer_buffer_length = bytes;
+       if (period_elapsed)
+               snd_pcm_period_elapsed(subs->pcm_substream);
+       return 0;
+}
+
+/*
+ * process after playback data complete
+ * - decrease the delay count again
+ */
+static int retire_playback_urb(struct snd_usb_substream *subs,
+                              struct snd_pcm_runtime *runtime,
+                              struct urb *urb)
+{
+       unsigned long flags;
+       int stride = runtime->frame_bits >> 3;
+       int processed = urb->transfer_buffer_length / stride;
+
+       spin_lock_irqsave(&subs->lock, flags);
+       if (processed > runtime->delay)
+               runtime->delay = 0;
+       else
+               runtime->delay -= processed;
+       spin_unlock_irqrestore(&subs->lock, flags);
+       return 0;
+}
+
+static const char *usb_error_string(int err)
+{
+       switch (err) {
+       case -ENODEV:
+               return "no device";
+       case -ENOENT:
+               return "endpoint not enabled";
+       case -EPIPE:
+               return "endpoint stalled";
+       case -ENOSPC:
+               return "not enough bandwidth";
+       case -ESHUTDOWN:
+               return "device disabled";
+       case -EHOSTUNREACH:
+               return "device suspended";
+       case -EINVAL:
+       case -EAGAIN:
+       case -EFBIG:
+       case -EMSGSIZE:
+               return "internal error";
+       default:
+               return "unknown error";
+       }
+}
+
+/*
+ * set up and start data/sync urbs
+ */
+static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
+{
+       unsigned int i;
+       int err;
+
+       if (subs->stream->chip->shutdown)
+               return -EBADFD;
+
+       for (i = 0; i < subs->nurbs; i++) {
+               if (snd_BUG_ON(!subs->dataurb[i].urb))
+                       return -EINVAL;
+               if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
+                       snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
+                       goto __error;
+               }
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       if (snd_BUG_ON(!subs->syncurb[i].urb))
+                               return -EINVAL;
+                       if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
+                               snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
+                               goto __error;
+                       }
+               }
+       }
+
+       subs->active_mask = 0;
+       subs->unlink_mask = 0;
+       subs->running = 1;
+       for (i = 0; i < subs->nurbs; i++) {
+               err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
+               if (err < 0) {
+                       snd_printk(KERN_ERR "cannot submit datapipe "
+                                  "for urb %d, error %d: %s\n",
+                                  i, err, usb_error_string(err));
+                       goto __error;
+               }
+               set_bit(i, &subs->active_mask);
+       }
+       if (subs->syncpipe) {
+               for (i = 0; i < SYNC_URBS; i++) {
+                       err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
+                       if (err < 0) {
+                               snd_printk(KERN_ERR "cannot submit syncpipe "
+                                          "for urb %d, error %d: %s\n",
+                                          i, err, usb_error_string(err));
+                               goto __error;
+                       }
+                       set_bit(i + 16, &subs->active_mask);
+               }
+       }
+       return 0;
+
+ __error:
+       // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
+       deactivate_urbs(subs, 0, 0);
+       return -EPIPE;
+}
+
+
+/*
+ */
+static struct snd_urb_ops audio_urb_ops[2] = {
+       {
+               .prepare =      prepare_nodata_playback_urb,
+               .retire =       retire_playback_urb,
+               .prepare_sync = prepare_playback_sync_urb,
+               .retire_sync =  retire_playback_sync_urb,
+       },
+       {
+               .prepare =      prepare_capture_urb,
+               .retire =       retire_capture_urb,
+               .prepare_sync = prepare_capture_sync_urb,
+               .retire_sync =  retire_capture_sync_urb,
+       },
+};
+
+static struct snd_urb_ops audio_urb_ops_high_speed[2] = {
+       {
+               .prepare =      prepare_nodata_playback_urb,
+               .retire =       retire_playback_urb,
+               .prepare_sync = prepare_playback_sync_urb_hs,
+               .retire_sync =  retire_playback_sync_urb_hs,
+       },
+       {
+               .prepare =      prepare_capture_urb,
+               .retire =       retire_capture_urb,
+               .prepare_sync = prepare_capture_sync_urb_hs,
+               .retire_sync =  retire_capture_sync_urb,
+       },
+};
+
+/*
+ * initialize the substream instance.
+ */
+
+void snd_usb_init_substream(struct snd_usb_stream *as,
+                           int stream, struct audioformat *fp)
+{
+       struct snd_usb_substream *subs = &as->substream[stream];
+
+       INIT_LIST_HEAD(&subs->fmt_list);
+       spin_lock_init(&subs->lock);
+
+       subs->stream = as;
+       subs->direction = stream;
+       subs->dev = as->chip->dev;
+       subs->txfr_quirk = as->chip->txfr_quirk;
+       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
+               subs->ops = audio_urb_ops[stream];
+       } else {
+               subs->ops = audio_urb_ops_high_speed[stream];
+               switch (as->chip->usb_id) {
+               case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
+               case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
+               case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
+                       subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
+                       break;
+               case USB_ID(0x0763, 0x2080): /* M-Audio Fast Track Ultra 8  */
+               case USB_ID(0x0763, 0x2081): /* M-Audio Fast Track Ultra 8R */
+                       subs->ops.prepare_sync = prepare_playback_sync_urb;
+                       subs->ops.retire_sync = retire_playback_sync_urb;
+                       break;
+               }
+       }
+
+       snd_usb_set_pcm_ops(as->pcm, stream);
+
+       list_add_tail(&fp->list, &subs->fmt_list);
+       subs->formats |= fp->formats;
+       subs->endpoint = fp->endpoint;
+       subs->num_formats++;
+       subs->fmt_type = fp->fmt_type;
+}
+
+int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               subs->ops.prepare = prepare_playback_urb;
+               return 0;
+       case SNDRV_PCM_TRIGGER_STOP:
+               return deactivate_urbs(subs, 0, 0);
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               subs->ops.prepare = prepare_nodata_playback_urb;
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+       struct snd_usb_substream *subs = substream->runtime->private_data;
+
+       switch (cmd) {
+       case SNDRV_PCM_TRIGGER_START:
+               subs->ops.retire = retire_capture_urb;
+               return start_urbs(subs, substream->runtime);
+       case SNDRV_PCM_TRIGGER_STOP:
+               return deactivate_urbs(subs, 0, 0);
+       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+               subs->ops.retire = retire_paused_capture_urb;
+               return 0;
+       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+               subs->ops.retire = retire_capture_urb;
+               return 0;
+       }
+
+       return -EINVAL;
+}
+
+int snd_usb_substream_prepare(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime)
+{
+       /* clear urbs (to be sure) */
+       deactivate_urbs(subs, 0, 1);
+       wait_clear_urbs(subs);
+
+       /* for playback, submit the URBs now; otherwise, the first hwptr_done
+        * updates for all URBs would happen at the same time when starting */
+       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
+               subs->ops.prepare = prepare_nodata_playback_urb;
+               return start_urbs(subs, runtime);
+       }
+
+       return 0;
+}
+
diff --git a/sound/usb/urb.h b/sound/usb/urb.h
new file mode 100644 (file)
index 0000000..888da38
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __USBAUDIO_URB_H
+#define __USBAUDIO_URB_H
+
+void snd_usb_init_substream(struct snd_usb_stream *as,
+                           int stream,
+                           struct audioformat *fp);
+
+int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
+                               unsigned int period_bytes,
+                               unsigned int rate,
+                               unsigned int frame_bits);
+
+void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force);
+
+int snd_usb_substream_prepare(struct snd_usb_substream *subs,
+                             struct snd_pcm_runtime *runtime);
+
+int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd);
+int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd);
+
+#endif /* __USBAUDIO_URB_H */
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
deleted file mode 100644 (file)
index 11b0826..0000000
+++ /dev/null
@@ -1,4050 +0,0 @@
-/*
- *   (Tentative) USB Audio Driver for ALSA
- *
- *   Main and PCM part
- *
- *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
- *
- *   Many codes borrowed from audio.c by
- *         Alan Cox (alan@lxorguk.ukuu.org.uk)
- *         Thomas Sailer (sailer@ife.ee.ethz.ch)
- *
- *
- *   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
- *
- *
- *  NOTES:
- *
- *   - async unlink should be used for avoiding the sleep inside lock.
- *     2.4.22 usb-uhci seems buggy for async unlinking and results in
- *     oops.  in such a cse, pass async_unlink=0 option.
- *   - the linked URBs would be preferred but not used so far because of
- *     the instability of unlinking.
- *   - type II is not supported properly.  there is no device which supports
- *     this type *correctly*.  SB extigy looks as if it supports, but it's
- *     indeed an AC3 stream packed in SPDIF frames (i.e. no real AC3 stream).
- */
-
-
-#include <linux/bitops.h>
-#include <linux/init.h>
-#include <linux/list.h>
-#include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/usb.h>
-#include <linux/moduleparam.h>
-#include <linux/mutex.h>
-#include <linux/usb/audio.h>
-#include <linux/usb/ch9.h>
-
-#include <sound/core.h>
-#include <sound/info.h>
-#include <sound/pcm.h>
-#include <sound/pcm_params.h>
-#include <sound/initval.h>
-
-#include "usbaudio.h"
-
-
-MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
-MODULE_DESCRIPTION("USB Audio");
-MODULE_LICENSE("GPL");
-MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
-
-
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
-/* Vendor/product IDs for this card */
-static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
-static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
-static int nrpacks = 8;                /* max. number of packets per urb */
-static int async_unlink = 1;
-static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/
-static int ignore_ctl_error;
-
-module_param_array(index, int, NULL, 0444);
-MODULE_PARM_DESC(index, "Index value for the USB audio adapter.");
-module_param_array(id, charp, NULL, 0444);
-MODULE_PARM_DESC(id, "ID string for the USB audio adapter.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable USB audio adapter.");
-module_param_array(vid, int, NULL, 0444);
-MODULE_PARM_DESC(vid, "Vendor ID for the USB audio device.");
-module_param_array(pid, int, NULL, 0444);
-MODULE_PARM_DESC(pid, "Product ID for the USB audio device.");
-module_param(nrpacks, int, 0644);
-MODULE_PARM_DESC(nrpacks, "Max. number of packets per URB.");
-module_param(async_unlink, bool, 0444);
-MODULE_PARM_DESC(async_unlink, "Use async unlink mode.");
-module_param_array(device_setup, int, NULL, 0444);
-MODULE_PARM_DESC(device_setup, "Specific device setup (if needed).");
-module_param(ignore_ctl_error, bool, 0444);
-MODULE_PARM_DESC(ignore_ctl_error,
-                "Ignore errors from USB controller for mixer interfaces.");
-
-/*
- * debug the h/w constraints
- */
-/* #define HW_CONST_DEBUG */
-
-
-/*
- *
- */
-
-#define MAX_PACKS      20
-#define MAX_PACKS_HS   (MAX_PACKS * 8) /* in high speed mode */
-#define MAX_URBS       8
-#define SYNC_URBS      4       /* always four urbs for sync */
-#define MAX_QUEUE      24      /* try not to exceed this queue length, in ms */
-
-struct audioformat {
-       struct list_head list;
-       snd_pcm_format_t format;        /* format type */
-       unsigned int channels;          /* # channels */
-       unsigned int fmt_type;          /* USB audio format type (1-3) */
-       unsigned int frame_size;        /* samples per frame for non-audio */
-       int iface;                      /* interface number */
-       unsigned char altsetting;       /* corresponding alternate setting */
-       unsigned char altset_idx;       /* array index of altenate setting */
-       unsigned char attributes;       /* corresponding attributes of cs endpoint */
-       unsigned char endpoint;         /* endpoint */
-       unsigned char ep_attr;          /* endpoint attributes */
-       unsigned char datainterval;     /* log_2 of data packet interval */
-       unsigned int maxpacksize;       /* max. packet size */
-       unsigned int rates;             /* rate bitmasks */
-       unsigned int rate_min, rate_max;        /* min/max rates */
-       unsigned int nr_rates;          /* number of rate table entries */
-       unsigned int *rate_table;       /* rate table */
-};
-
-struct snd_usb_substream;
-
-struct snd_urb_ctx {
-       struct urb *urb;
-       unsigned int buffer_size;       /* size of data buffer, if data URB */
-       struct snd_usb_substream *subs;
-       int index;      /* index for urb array */
-       int packets;    /* number of packets per urb */
-};
-
-struct snd_urb_ops {
-       int (*prepare)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
-       int (*retire)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
-       int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
-       int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
-};
-
-struct snd_usb_substream {
-       struct snd_usb_stream *stream;
-       struct usb_device *dev;
-       struct snd_pcm_substream *pcm_substream;
-       int direction;  /* playback or capture */
-       int interface;  /* current interface */
-       int endpoint;   /* assigned endpoint */
-       struct audioformat *cur_audiofmt;       /* current audioformat pointer (for hw_params callback) */
-       unsigned int cur_rate;          /* current rate (for hw_params callback) */
-       unsigned int period_bytes;      /* current period bytes (for hw_params callback) */
-       unsigned int format;     /* USB data format */
-       unsigned int datapipe;   /* the data i/o pipe */
-       unsigned int syncpipe;   /* 1 - async out or adaptive in */
-       unsigned int datainterval;      /* log_2 of data packet interval */
-       unsigned int syncinterval;  /* P for adaptive mode, 0 otherwise */
-       unsigned int freqn;      /* nominal sampling rate in fs/fps in Q16.16 format */
-       unsigned int freqm;      /* momentary sampling rate in fs/fps in Q16.16 format */
-       unsigned int freqmax;    /* maximum sampling rate, used for buffer management */
-       unsigned int phase;      /* phase accumulator */
-       unsigned int maxpacksize;       /* max packet size in bytes */
-       unsigned int maxframesize;      /* max packet size in frames */
-       unsigned int curpacksize;       /* current packet size in bytes (for capture) */
-       unsigned int curframesize;      /* current packet size in frames (for capture) */
-       unsigned int fill_max: 1;       /* fill max packet size always */
-       unsigned int txfr_quirk:1;      /* allow sub-frame alignment */
-       unsigned int fmt_type;          /* USB audio format type (1-3) */
-
-       unsigned int running: 1;        /* running status */
-
-       unsigned int hwptr_done;        /* processed byte position in the buffer */
-       unsigned int transfer_done;             /* processed frames since last period update */
-       unsigned long active_mask;      /* bitmask of active urbs */
-       unsigned long unlink_mask;      /* bitmask of unlinked urbs */
-
-       unsigned int nurbs;                     /* # urbs */
-       struct snd_urb_ctx dataurb[MAX_URBS];   /* data urb table */
-       struct snd_urb_ctx syncurb[SYNC_URBS];  /* sync urb table */
-       char *syncbuf;                          /* sync buffer for all sync URBs */
-       dma_addr_t sync_dma;                    /* DMA address of syncbuf */
-
-       u64 formats;                    /* format bitmasks (all or'ed) */
-       unsigned int num_formats;               /* number of supported audio formats (list) */
-       struct list_head fmt_list;      /* format list */
-       struct snd_pcm_hw_constraint_list rate_list;    /* limited rates */
-       spinlock_t lock;
-
-       struct snd_urb_ops ops;         /* callbacks (must be filled at init) */
-};
-
-
-struct snd_usb_stream {
-       struct snd_usb_audio *chip;
-       struct snd_pcm *pcm;
-       int pcm_index;
-       unsigned int fmt_type;          /* USB audio format type (1-3) */
-       struct snd_usb_substream substream[2];
-       struct list_head list;
-};
-
-
-/*
- * we keep the snd_usb_audio_t instances by ourselves for merging
- * the all interfaces on the same card as one sound device.
- */
-
-static DEFINE_MUTEX(register_mutex);
-static struct snd_usb_audio *usb_chip[SNDRV_CARDS];
-
-
-/*
- * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
- * this will overflow at approx 524 kHz
- */
-static inline unsigned get_usb_full_speed_rate(unsigned int rate)
-{
-       return ((rate << 13) + 62) / 125;
-}
-
-/*
- * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
- * this will overflow at approx 4 MHz
- */
-static inline unsigned get_usb_high_speed_rate(unsigned int rate)
-{
-       return ((rate << 10) + 62) / 125;
-}
-
-/* convert our full speed USB rate into sampling rate in Hz */
-static inline unsigned get_full_speed_hz(unsigned int usb_rate)
-{
-       return (usb_rate * 125 + (1 << 12)) >> 13;
-}
-
-/* convert our high speed USB rate into sampling rate in Hz */
-static inline unsigned get_high_speed_hz(unsigned int usb_rate)
-{
-       return (usb_rate * 125 + (1 << 9)) >> 10;
-}
-
-
-/*
- * prepare urb for full speed capture sync pipe
- *
- * fill the length and offset of each urb descriptor.
- * the fixed 10.14 frequency is passed through the pipe.
- */
-static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
-                                   struct snd_pcm_runtime *runtime,
-                                   struct urb *urb)
-{
-       unsigned char *cp = urb->transfer_buffer;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 3;
-       urb->iso_frame_desc[0].offset = 0;
-       cp[0] = subs->freqn >> 2;
-       cp[1] = subs->freqn >> 10;
-       cp[2] = subs->freqn >> 18;
-       return 0;
-}
-
-/*
- * prepare urb for high speed capture sync pipe
- *
- * fill the length and offset of each urb descriptor.
- * the fixed 12.13 frequency is passed as 16.16 through the pipe.
- */
-static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
-                                      struct snd_pcm_runtime *runtime,
-                                      struct urb *urb)
-{
-       unsigned char *cp = urb->transfer_buffer;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 4;
-       urb->iso_frame_desc[0].offset = 0;
-       cp[0] = subs->freqn;
-       cp[1] = subs->freqn >> 8;
-       cp[2] = subs->freqn >> 16;
-       cp[3] = subs->freqn >> 24;
-       return 0;
-}
-
-/*
- * process after capture sync complete
- * - nothing to do
- */
-static int retire_capture_sync_urb(struct snd_usb_substream *subs,
-                                  struct snd_pcm_runtime *runtime,
-                                  struct urb *urb)
-{
-       return 0;
-}
-
-/*
- * prepare urb for capture data pipe
- *
- * fill the offset and length of each descriptor.
- *
- * we use a temporary buffer to write the captured data.
- * since the length of written data is determined by host, we cannot
- * write onto the pcm buffer directly...  the data is thus copied
- * later at complete callback to the global buffer.
- */
-static int prepare_capture_urb(struct snd_usb_substream *subs,
-                              struct snd_pcm_runtime *runtime,
-                              struct urb *urb)
-{
-       int i, offs;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       offs = 0;
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       for (i = 0; i < ctx->packets; i++) {
-               urb->iso_frame_desc[i].offset = offs;
-               urb->iso_frame_desc[i].length = subs->curpacksize;
-               offs += subs->curpacksize;
-       }
-       urb->transfer_buffer_length = offs;
-       urb->number_of_packets = ctx->packets;
-       return 0;
-}
-
-/*
- * process after capture complete
- *
- * copy the data from each desctiptor to the pcm buffer, and
- * update the current position.
- */
-static int retire_capture_urb(struct snd_usb_substream *subs,
-                             struct snd_pcm_runtime *runtime,
-                             struct urb *urb)
-{
-       unsigned long flags;
-       unsigned char *cp;
-       int i;
-       unsigned int stride, frames, bytes, oldptr;
-       int period_elapsed = 0;
-
-       stride = runtime->frame_bits >> 3;
-
-       for (i = 0; i < urb->number_of_packets; i++) {
-               cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
-               if (urb->iso_frame_desc[i].status) {
-                       snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
-                       // continue;
-               }
-               bytes = urb->iso_frame_desc[i].actual_length;
-               frames = bytes / stride;
-               if (!subs->txfr_quirk)
-                       bytes = frames * stride;
-               if (bytes % (runtime->sample_bits >> 3) != 0) {
-#ifdef CONFIG_SND_DEBUG_VERBOSE
-                       int oldbytes = bytes;
-#endif
-                       bytes = frames * stride;
-                       snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
-                                                       oldbytes, bytes);
-               }
-               /* update the current pointer */
-               spin_lock_irqsave(&subs->lock, flags);
-               oldptr = subs->hwptr_done;
-               subs->hwptr_done += bytes;
-               if (subs->hwptr_done >= runtime->buffer_size * stride)
-                       subs->hwptr_done -= runtime->buffer_size * stride;
-               frames = (bytes + (oldptr % stride)) / stride;
-               subs->transfer_done += frames;
-               if (subs->transfer_done >= runtime->period_size) {
-                       subs->transfer_done -= runtime->period_size;
-                       period_elapsed = 1;
-               }
-               spin_unlock_irqrestore(&subs->lock, flags);
-               /* copy a data chunk */
-               if (oldptr + bytes > runtime->buffer_size * stride) {
-                       unsigned int bytes1 =
-                                       runtime->buffer_size * stride - oldptr;
-                       memcpy(runtime->dma_area + oldptr, cp, bytes1);
-                       memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
-               } else {
-                       memcpy(runtime->dma_area + oldptr, cp, bytes);
-               }
-       }
-       if (period_elapsed)
-               snd_pcm_period_elapsed(subs->pcm_substream);
-       return 0;
-}
-
-/*
- * Process after capture complete when paused.  Nothing to do.
- */
-static int retire_paused_capture_urb(struct snd_usb_substream *subs,
-                                    struct snd_pcm_runtime *runtime,
-                                    struct urb *urb)
-{
-       return 0;
-}
-
-
-/*
- * prepare urb for full speed playback sync pipe
- *
- * set up the offset and length to receive the current frequency.
- */
-
-static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
-                                    struct snd_pcm_runtime *runtime,
-                                    struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 3;
-       urb->iso_frame_desc[0].offset = 0;
-       return 0;
-}
-
-/*
- * prepare urb for high speed playback sync pipe
- *
- * set up the offset and length to receive the current frequency.
- */
-
-static int prepare_playback_sync_urb_hs(struct snd_usb_substream *subs,
-                                       struct snd_pcm_runtime *runtime,
-                                       struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->iso_frame_desc[0].length = 4;
-       urb->iso_frame_desc[0].offset = 0;
-       return 0;
-}
-
-/*
- * process after full speed playback sync complete
- *
- * retrieve the current 10.14 frequency from pipe, and set it.
- * the value is referred in prepare_playback_urb().
- */
-static int retire_playback_sync_urb(struct snd_usb_substream *subs,
-                                   struct snd_pcm_runtime *runtime,
-                                   struct urb *urb)
-{
-       unsigned int f;
-       unsigned long flags;
-
-       if (urb->iso_frame_desc[0].status == 0 &&
-           urb->iso_frame_desc[0].actual_length == 3) {
-               f = combine_triple((u8*)urb->transfer_buffer) << 2;
-               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
-                       spin_lock_irqsave(&subs->lock, flags);
-                       subs->freqm = f;
-                       spin_unlock_irqrestore(&subs->lock, flags);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * process after high speed playback sync complete
- *
- * retrieve the current 12.13 frequency from pipe, and set it.
- * the value is referred in prepare_playback_urb().
- */
-static int retire_playback_sync_urb_hs(struct snd_usb_substream *subs,
-                                      struct snd_pcm_runtime *runtime,
-                                      struct urb *urb)
-{
-       unsigned int f;
-       unsigned long flags;
-
-       if (urb->iso_frame_desc[0].status == 0 &&
-           urb->iso_frame_desc[0].actual_length == 4) {
-               f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
-               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
-                       spin_lock_irqsave(&subs->lock, flags);
-                       subs->freqm = f;
-                       spin_unlock_irqrestore(&subs->lock, flags);
-               }
-       }
-
-       return 0;
-}
-
-/*
- * process after E-Mu 0202/0404/Tracker Pre high speed playback sync complete
- *
- * These devices return the number of samples per packet instead of the number
- * of samples per microframe.
- */
-static int retire_playback_sync_urb_hs_emu(struct snd_usb_substream *subs,
-                                          struct snd_pcm_runtime *runtime,
-                                          struct urb *urb)
-{
-       unsigned int f;
-       unsigned long flags;
-
-       if (urb->iso_frame_desc[0].status == 0 &&
-           urb->iso_frame_desc[0].actual_length == 4) {
-               f = combine_quad((u8*)urb->transfer_buffer) & 0x0fffffff;
-               f >>= subs->datainterval;
-               if (f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax) {
-                       spin_lock_irqsave(&subs->lock, flags);
-                       subs->freqm = f;
-                       spin_unlock_irqrestore(&subs->lock, flags);
-               }
-       }
-
-       return 0;
-}
-
-/* determine the number of frames in the next packet */
-static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
-{
-       if (subs->fill_max)
-               return subs->maxframesize;
-       else {
-               subs->phase = (subs->phase & 0xffff)
-                       + (subs->freqm << subs->datainterval);
-               return min(subs->phase >> 16, subs->maxframesize);
-       }
-}
-
-/*
- * Prepare urb for streaming before playback starts or when paused.
- *
- * We don't have any data, so we send silence.
- */
-static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
-                                      struct snd_pcm_runtime *runtime,
-                                      struct urb *urb)
-{
-       unsigned int i, offs, counts;
-       struct snd_urb_ctx *ctx = urb->context;
-       int stride = runtime->frame_bits >> 3;
-
-       offs = 0;
-       urb->dev = ctx->subs->dev;
-       for (i = 0; i < ctx->packets; ++i) {
-               counts = snd_usb_audio_next_packet_size(subs);
-               urb->iso_frame_desc[i].offset = offs * stride;
-               urb->iso_frame_desc[i].length = counts * stride;
-               offs += counts;
-       }
-       urb->number_of_packets = ctx->packets;
-       urb->transfer_buffer_length = offs * stride;
-       memset(urb->transfer_buffer,
-              subs->cur_audiofmt->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
-              offs * stride);
-       return 0;
-}
-
-/*
- * prepare urb for playback data pipe
- *
- * Since a URB can handle only a single linear buffer, we must use double
- * buffering when the data to be transferred overflows the buffer boundary.
- * To avoid inconsistencies when updating hwptr_done, we use double buffering
- * for all URBs.
- */
-static int prepare_playback_urb(struct snd_usb_substream *subs,
-                               struct snd_pcm_runtime *runtime,
-                               struct urb *urb)
-{
-       int i, stride;
-       unsigned int counts, frames, bytes;
-       unsigned long flags;
-       int period_elapsed = 0;
-       struct snd_urb_ctx *ctx = urb->context;
-
-       stride = runtime->frame_bits >> 3;
-
-       frames = 0;
-       urb->dev = ctx->subs->dev; /* we need to set this at each time */
-       urb->number_of_packets = 0;
-       spin_lock_irqsave(&subs->lock, flags);
-       for (i = 0; i < ctx->packets; i++) {
-               counts = snd_usb_audio_next_packet_size(subs);
-               /* set up descriptor */
-               urb->iso_frame_desc[i].offset = frames * stride;
-               urb->iso_frame_desc[i].length = counts * stride;
-               frames += counts;
-               urb->number_of_packets++;
-               subs->transfer_done += counts;
-               if (subs->transfer_done >= runtime->period_size) {
-                       subs->transfer_done -= runtime->period_size;
-                       period_elapsed = 1;
-                       if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
-                               if (subs->transfer_done > 0) {
-                                       /* FIXME: fill-max mode is not
-                                        * supported yet */
-                                       frames -= subs->transfer_done;
-                                       counts -= subs->transfer_done;
-                                       urb->iso_frame_desc[i].length =
-                                               counts * stride;
-                                       subs->transfer_done = 0;
-                               }
-                               i++;
-                               if (i < ctx->packets) {
-                                       /* add a transfer delimiter */
-                                       urb->iso_frame_desc[i].offset =
-                                               frames * stride;
-                                       urb->iso_frame_desc[i].length = 0;
-                                       urb->number_of_packets++;
-                               }
-                               break;
-                       }
-               }
-               if (period_elapsed) /* finish at the period boundary */
-                       break;
-       }
-       bytes = frames * stride;
-       if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
-               /* err, the transferred area goes over buffer boundary. */
-               unsigned int bytes1 =
-                       runtime->buffer_size * stride - subs->hwptr_done;
-               memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done, bytes1);
-               memcpy(urb->transfer_buffer + bytes1,
-                      runtime->dma_area, bytes - bytes1);
-       } else {
-               memcpy(urb->transfer_buffer,
-                      runtime->dma_area + subs->hwptr_done, bytes);
-       }
-       subs->hwptr_done += bytes;
-       if (subs->hwptr_done >= runtime->buffer_size * stride)
-               subs->hwptr_done -= runtime->buffer_size * stride;
-       runtime->delay += frames;
-       spin_unlock_irqrestore(&subs->lock, flags);
-       urb->transfer_buffer_length = bytes;
-       if (period_elapsed)
-               snd_pcm_period_elapsed(subs->pcm_substream);
-       return 0;
-}
-
-/*
- * process after playback data complete
- * - decrease the delay count again
- */
-static int retire_playback_urb(struct snd_usb_substream *subs,
-                              struct snd_pcm_runtime *runtime,
-                              struct urb *urb)
-{
-       unsigned long flags;
-       int stride = runtime->frame_bits >> 3;
-       int processed = urb->transfer_buffer_length / stride;
-
-       spin_lock_irqsave(&subs->lock, flags);
-       if (processed > runtime->delay)
-               runtime->delay = 0;
-       else
-               runtime->delay -= processed;
-       spin_unlock_irqrestore(&subs->lock, flags);
-       return 0;
-}
-
-
-/*
- */
-static struct snd_urb_ops audio_urb_ops[2] = {
-       {
-               .prepare =      prepare_nodata_playback_urb,
-               .retire =       retire_playback_urb,
-               .prepare_sync = prepare_playback_sync_urb,
-               .retire_sync =  retire_playback_sync_urb,
-       },
-       {
-               .prepare =      prepare_capture_urb,
-               .retire =       retire_capture_urb,
-               .prepare_sync = prepare_capture_sync_urb,
-               .retire_sync =  retire_capture_sync_urb,
-       },
-};
-
-static struct snd_urb_ops audio_urb_ops_high_speed[2] = {
-       {
-               .prepare =      prepare_nodata_playback_urb,
-               .retire =       retire_playback_urb,
-               .prepare_sync = prepare_playback_sync_urb_hs,
-               .retire_sync =  retire_playback_sync_urb_hs,
-       },
-       {
-               .prepare =      prepare_capture_urb,
-               .retire =       retire_capture_urb,
-               .prepare_sync = prepare_capture_sync_urb_hs,
-               .retire_sync =  retire_capture_sync_urb,
-       },
-};
-
-/*
- * complete callback from data urb
- */
-static void snd_complete_urb(struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-       struct snd_usb_substream *subs = ctx->subs;
-       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
-       int err = 0;
-
-       if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
-           !subs->running || /* can be stopped during retire callback */
-           (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
-           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
-               clear_bit(ctx->index, &subs->active_mask);
-               if (err < 0) {
-                       snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
-                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
-               }
-       }
-}
-
-
-/*
- * complete callback from sync urb
- */
-static void snd_complete_sync_urb(struct urb *urb)
-{
-       struct snd_urb_ctx *ctx = urb->context;
-       struct snd_usb_substream *subs = ctx->subs;
-       struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
-       int err = 0;
-
-       if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
-           !subs->running || /* can be stopped during retire callback */
-           (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
-           (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
-               clear_bit(ctx->index + 16, &subs->active_mask);
-               if (err < 0) {
-                       snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
-                       snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
-               }
-       }
-}
-
-
-/*
- * unlink active urbs.
- */
-static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
-{
-       unsigned int i;
-       int async;
-
-       subs->running = 0;
-
-       if (!force && subs->stream->chip->shutdown) /* to be sure... */
-               return -EBADFD;
-
-       async = !can_sleep && async_unlink;
-
-       if (!async && in_interrupt())
-               return 0;
-
-       for (i = 0; i < subs->nurbs; i++) {
-               if (test_bit(i, &subs->active_mask)) {
-                       if (!test_and_set_bit(i, &subs->unlink_mask)) {
-                               struct urb *u = subs->dataurb[i].urb;
-                               if (async)
-                                       usb_unlink_urb(u);
-                               else
-                                       usb_kill_urb(u);
-                       }
-               }
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       if (test_bit(i+16, &subs->active_mask)) {
-                               if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
-                                       struct urb *u = subs->syncurb[i].urb;
-                                       if (async)
-                                               usb_unlink_urb(u);
-                                       else
-                                               usb_kill_urb(u);
-                               }
-                       }
-               }
-       }
-       return 0;
-}
-
-
-static const char *usb_error_string(int err)
-{
-       switch (err) {
-       case -ENODEV:
-               return "no device";
-       case -ENOENT:
-               return "endpoint not enabled";
-       case -EPIPE:
-               return "endpoint stalled";
-       case -ENOSPC:
-               return "not enough bandwidth";
-       case -ESHUTDOWN:
-               return "device disabled";
-       case -EHOSTUNREACH:
-               return "device suspended";
-       case -EINVAL:
-       case -EAGAIN:
-       case -EFBIG:
-       case -EMSGSIZE:
-               return "internal error";
-       default:
-               return "unknown error";
-       }
-}
-
-/*
- * set up and start data/sync urbs
- */
-static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
-{
-       unsigned int i;
-       int err;
-
-       if (subs->stream->chip->shutdown)
-               return -EBADFD;
-
-       for (i = 0; i < subs->nurbs; i++) {
-               if (snd_BUG_ON(!subs->dataurb[i].urb))
-                       return -EINVAL;
-               if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
-                       snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
-                       goto __error;
-               }
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       if (snd_BUG_ON(!subs->syncurb[i].urb))
-                               return -EINVAL;
-                       if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
-                               snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
-                               goto __error;
-                       }
-               }
-       }
-
-       subs->active_mask = 0;
-       subs->unlink_mask = 0;
-       subs->running = 1;
-       for (i = 0; i < subs->nurbs; i++) {
-               err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
-               if (err < 0) {
-                       snd_printk(KERN_ERR "cannot submit datapipe "
-                                  "for urb %d, error %d: %s\n",
-                                  i, err, usb_error_string(err));
-                       goto __error;
-               }
-               set_bit(i, &subs->active_mask);
-       }
-       if (subs->syncpipe) {
-               for (i = 0; i < SYNC_URBS; i++) {
-                       err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
-                       if (err < 0) {
-                               snd_printk(KERN_ERR "cannot submit syncpipe "
-                                          "for urb %d, error %d: %s\n",
-                                          i, err, usb_error_string(err));
-                               goto __error;
-                       }
-                       set_bit(i + 16, &subs->active_mask);
-               }
-       }
-       return 0;
-
- __error:
-       // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
-       deactivate_urbs(subs, 0, 0);
-       return -EPIPE;
-}
-
-
-/*
- *  wait until all urbs are processed.
- */
-static int wait_clear_urbs(struct snd_usb_substream *subs)
-{
-       unsigned long end_time = jiffies + msecs_to_jiffies(1000);
-       unsigned int i;
-       int alive;
-
-       do {
-               alive = 0;
-               for (i = 0; i < subs->nurbs; i++) {
-                       if (test_bit(i, &subs->active_mask))
-                               alive++;
-               }
-               if (subs->syncpipe) {
-                       for (i = 0; i < SYNC_URBS; i++) {
-                               if (test_bit(i + 16, &subs->active_mask))
-                                       alive++;
-                       }
-               }
-               if (! alive)
-                       break;
-               schedule_timeout_uninterruptible(1);
-       } while (time_before(jiffies, end_time));
-       if (alive)
-               snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
-       return 0;
-}
-
-
-/*
- * return the current pcm pointer.  just based on the hwptr_done value.
- */
-static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_usb_substream *subs;
-       unsigned int hwptr_done;
-       
-       subs = (struct snd_usb_substream *)substream->runtime->private_data;
-       spin_lock(&subs->lock);
-       hwptr_done = subs->hwptr_done;
-       spin_unlock(&subs->lock);
-       return hwptr_done / (substream->runtime->frame_bits >> 3);
-}
-
-
-/*
- * start/stop playback substream
- */
-static int snd_usb_pcm_playback_trigger(struct snd_pcm_substream *substream,
-                                       int cmd)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               subs->ops.prepare = prepare_playback_urb;
-               return 0;
-       case SNDRV_PCM_TRIGGER_STOP:
-               return deactivate_urbs(subs, 0, 0);
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               subs->ops.prepare = prepare_nodata_playback_urb;
-               return 0;
-       default:
-               return -EINVAL;
-       }
-}
-
-/*
- * start/stop capture substream
- */
-static int snd_usb_pcm_capture_trigger(struct snd_pcm_substream *substream,
-                                      int cmd)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-
-       switch (cmd) {
-       case SNDRV_PCM_TRIGGER_START:
-               subs->ops.retire = retire_capture_urb;
-               return start_urbs(subs, substream->runtime);
-       case SNDRV_PCM_TRIGGER_STOP:
-               return deactivate_urbs(subs, 0, 0);
-       case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-               subs->ops.retire = retire_paused_capture_urb;
-               return 0;
-       case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-               subs->ops.retire = retire_capture_urb;
-               return 0;
-       default:
-               return -EINVAL;
-       }
-}
-
-
-/*
- * release a urb data
- */
-static void release_urb_ctx(struct snd_urb_ctx *u)
-{
-       if (u->urb) {
-               if (u->buffer_size)
-                       usb_buffer_free(u->subs->dev, u->buffer_size,
-                                       u->urb->transfer_buffer,
-                                       u->urb->transfer_dma);
-               usb_free_urb(u->urb);
-               u->urb = NULL;
-       }
-}
-
-/*
- * release a substream
- */
-static void release_substream_urbs(struct snd_usb_substream *subs, int force)
-{
-       int i;
-
-       /* stop urbs (to be sure) */
-       deactivate_urbs(subs, force, 1);
-       wait_clear_urbs(subs);
-
-       for (i = 0; i < MAX_URBS; i++)
-               release_urb_ctx(&subs->dataurb[i]);
-       for (i = 0; i < SYNC_URBS; i++)
-               release_urb_ctx(&subs->syncurb[i]);
-       usb_buffer_free(subs->dev, SYNC_URBS * 4,
-                       subs->syncbuf, subs->sync_dma);
-       subs->syncbuf = NULL;
-       subs->nurbs = 0;
-}
-
-/*
- * initialize a substream for plaback/capture
- */
-static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int period_bytes,
-                              unsigned int rate, unsigned int frame_bits)
-{
-       unsigned int maxsize, i;
-       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
-       unsigned int urb_packs, total_packs, packs_per_ms;
-
-       /* calculate the frequency in 16.16 format */
-       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
-               subs->freqn = get_usb_full_speed_rate(rate);
-       else
-               subs->freqn = get_usb_high_speed_rate(rate);
-       subs->freqm = subs->freqn;
-       /* calculate max. frequency */
-       if (subs->maxpacksize) {
-               /* whatever fits into a max. size packet */
-               maxsize = subs->maxpacksize;
-               subs->freqmax = (maxsize / (frame_bits >> 3))
-                               << (16 - subs->datainterval);
-       } else {
-               /* no max. packet size: just take 25% higher than nominal */
-               subs->freqmax = subs->freqn + (subs->freqn >> 2);
-               maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
-                               >> (16 - subs->datainterval);
-       }
-       subs->phase = 0;
-
-       if (subs->fill_max)
-               subs->curpacksize = subs->maxpacksize;
-       else
-               subs->curpacksize = maxsize;
-
-       if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH)
-               packs_per_ms = 8 >> subs->datainterval;
-       else
-               packs_per_ms = 1;
-
-       if (is_playback) {
-               urb_packs = max(nrpacks, 1);
-               urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
-       } else
-               urb_packs = 1;
-       urb_packs *= packs_per_ms;
-       if (subs->syncpipe)
-               urb_packs = min(urb_packs, 1U << subs->syncinterval);
-
-       /* decide how many packets to be used */
-       if (is_playback) {
-               unsigned int minsize, maxpacks;
-               /* determine how small a packet can be */
-               minsize = (subs->freqn >> (16 - subs->datainterval))
-                         * (frame_bits >> 3);
-               /* with sync from device, assume it can be 12% lower */
-               if (subs->syncpipe)
-                       minsize -= minsize >> 3;
-               minsize = max(minsize, 1u);
-               total_packs = (period_bytes + minsize - 1) / minsize;
-               /* we need at least two URBs for queueing */
-               if (total_packs < 2) {
-                       total_packs = 2;
-               } else {
-                       /* and we don't want too long a queue either */
-                       maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
-                       total_packs = min(total_packs, maxpacks);
-               }
-       } else {
-               while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
-                       urb_packs >>= 1;
-               total_packs = MAX_URBS * urb_packs;
-       }
-       subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
-       if (subs->nurbs > MAX_URBS) {
-               /* too much... */
-               subs->nurbs = MAX_URBS;
-               total_packs = MAX_URBS * urb_packs;
-       } else if (subs->nurbs < 2) {
-               /* too little - we need at least two packets
-                * to ensure contiguous playback/capture
-                */
-               subs->nurbs = 2;
-       }
-
-       /* allocate and initialize data urbs */
-       for (i = 0; i < subs->nurbs; i++) {
-               struct snd_urb_ctx *u = &subs->dataurb[i];
-               u->index = i;
-               u->subs = subs;
-               u->packets = (i + 1) * total_packs / subs->nurbs
-                       - i * total_packs / subs->nurbs;
-               u->buffer_size = maxsize * u->packets;
-               if (subs->fmt_type == UAC_FORMAT_TYPE_II)
-                       u->packets++; /* for transfer delimiter */
-               u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
-               if (!u->urb)
-                       goto out_of_memory;
-               u->urb->transfer_buffer =
-                       usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL,
-                                        &u->urb->transfer_dma);
-               if (!u->urb->transfer_buffer)
-                       goto out_of_memory;
-               u->urb->pipe = subs->datapipe;
-               u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
-               u->urb->interval = 1 << subs->datainterval;
-               u->urb->context = u;
-               u->urb->complete = snd_complete_urb;
-       }
-
-       if (subs->syncpipe) {
-               /* allocate and initialize sync urbs */
-               subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4,
-                                                GFP_KERNEL, &subs->sync_dma);
-               if (!subs->syncbuf)
-                       goto out_of_memory;
-               for (i = 0; i < SYNC_URBS; i++) {
-                       struct snd_urb_ctx *u = &subs->syncurb[i];
-                       u->index = i;
-                       u->subs = subs;
-                       u->packets = 1;
-                       u->urb = usb_alloc_urb(1, GFP_KERNEL);
-                       if (!u->urb)
-                               goto out_of_memory;
-                       u->urb->transfer_buffer = subs->syncbuf + i * 4;
-                       u->urb->transfer_dma = subs->sync_dma + i * 4;
-                       u->urb->transfer_buffer_length = 4;
-                       u->urb->pipe = subs->syncpipe;
-                       u->urb->transfer_flags = URB_ISO_ASAP |
-                                                URB_NO_TRANSFER_DMA_MAP;
-                       u->urb->number_of_packets = 1;
-                       u->urb->interval = 1 << subs->syncinterval;
-                       u->urb->context = u;
-                       u->urb->complete = snd_complete_sync_urb;
-               }
-       }
-       return 0;
-
-out_of_memory:
-       release_substream_urbs(subs, 0);
-       return -ENOMEM;
-}
-
-
-/*
- * find a matching audio format
- */
-static struct audioformat *find_format(struct snd_usb_substream *subs, unsigned int format,
-                                      unsigned int rate, unsigned int channels)
-{
-       struct list_head *p;
-       struct audioformat *found = NULL;
-       int cur_attr = 0, attr;
-
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               if (fp->format != format || fp->channels != channels)
-                       continue;
-               if (rate < fp->rate_min || rate > fp->rate_max)
-                       continue;
-               if (! (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)) {
-                       unsigned int i;
-                       for (i = 0; i < fp->nr_rates; i++)
-                               if (fp->rate_table[i] == rate)
-                                       break;
-                       if (i >= fp->nr_rates)
-                               continue;
-               }
-               attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
-               if (! found) {
-                       found = fp;
-                       cur_attr = attr;
-                       continue;
-               }
-               /* avoid async out and adaptive in if the other method
-                * supports the same format.
-                * this is a workaround for the case like
-                * M-audio audiophile USB.
-                */
-               if (attr != cur_attr) {
-                       if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
-                            subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
-                           (attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
-                            subs->direction == SNDRV_PCM_STREAM_CAPTURE))
-                               continue;
-                       if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
-                            subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
-                           (cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
-                            subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
-                               found = fp;
-                               cur_attr = attr;
-                               continue;
-                       }
-               }
-               /* find the format with the largest max. packet size */
-               if (fp->maxpacksize > found->maxpacksize) {
-                       found = fp;
-                       cur_attr = attr;
-               }
-       }
-       return found;
-}
-
-
-/*
- * initialize the picth control and sample rate
- */
-static int init_usb_pitch(struct usb_device *dev, int iface,
-                         struct usb_host_interface *alts,
-                         struct audioformat *fmt)
-{
-       unsigned int ep;
-       unsigned char data[1];
-       int err;
-
-       ep = get_endpoint(alts, 0)->bEndpointAddress;
-       /* if endpoint has pitch control, enable it */
-       if (fmt->attributes & UAC_EP_CS_ATTR_PITCH_CONTROL) {
-               data[0] = 1;
-               if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
-                                          USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
-                                          UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, data, 1, 1000)) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
-                                  dev->devnum, iface, ep);
-                       return err;
-               }
-       }
-       return 0;
-}
-
-static int init_usb_sample_rate(struct usb_device *dev, int iface,
-                               struct usb_host_interface *alts,
-                               struct audioformat *fmt, int rate)
-{
-       unsigned int ep;
-       unsigned char data[3];
-       int err;
-
-       ep = get_endpoint(alts, 0)->bEndpointAddress;
-       /* if endpoint has sampling rate control, set it */
-       if (fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE) {
-               int crate;
-               data[0] = rate;
-               data[1] = rate >> 8;
-               data[2] = rate >> 16;
-               if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
-                                          USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
-                                          UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
-                                  dev->devnum, iface, fmt->altsetting, rate, ep);
-                       return err;
-               }
-               if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
-                                          USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
-                                          UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, data, 3, 1000)) < 0) {
-                       snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
-                                  dev->devnum, iface, fmt->altsetting, ep);
-                       return 0; /* some devices don't support reading */
-               }
-               crate = data[0] | (data[1] << 8) | (data[2] << 16);
-               if (crate != rate) {
-                       snd_printd(KERN_WARNING "current rate %d is different from the runtime rate %d\n", crate, rate);
-                       // runtime->rate = crate;
-               }
-       }
-       return 0;
-}
-
-/*
- * For E-Mu 0404USB/0202USB/TrackerPre sample rate should be set for device,
- * not for interface.
- */
-static void set_format_emu_quirk(struct snd_usb_substream *subs,
-                                struct audioformat *fmt)
-{
-       unsigned char emu_samplerate_id = 0;
-
-       /* When capture is active
-        * sample rate shouldn't be changed
-        * by playback substream
-        */
-       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
-               if (subs->stream->substream[SNDRV_PCM_STREAM_CAPTURE].interface != -1)
-                       return;
-       }
-
-       switch (fmt->rate_min) {
-       case 48000:
-               emu_samplerate_id = EMU_QUIRK_SR_48000HZ;
-               break;
-       case 88200:
-               emu_samplerate_id = EMU_QUIRK_SR_88200HZ;
-               break;
-       case 96000:
-               emu_samplerate_id = EMU_QUIRK_SR_96000HZ;
-               break;
-       case 176400:
-               emu_samplerate_id = EMU_QUIRK_SR_176400HZ;
-               break;
-       case 192000:
-               emu_samplerate_id = EMU_QUIRK_SR_192000HZ;
-               break;
-       default:
-               emu_samplerate_id = EMU_QUIRK_SR_44100HZ;
-               break;
-       }
-       snd_emuusb_set_samplerate(subs->stream->chip, emu_samplerate_id);
-}
-
-/*
- * find a matching format and set up the interface
- */
-static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
-{
-       struct usb_device *dev = subs->dev;
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       struct usb_interface *iface;
-       unsigned int ep, attr;
-       int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
-       int err;
-
-       iface = usb_ifnum_to_if(dev, fmt->iface);
-       if (WARN_ON(!iface))
-               return -EINVAL;
-       alts = &iface->altsetting[fmt->altset_idx];
-       altsd = get_iface_desc(alts);
-       if (WARN_ON(altsd->bAlternateSetting != fmt->altsetting))
-               return -EINVAL;
-
-       if (fmt == subs->cur_audiofmt)
-               return 0;
-
-       /* close the old interface */
-       if (subs->interface >= 0 && subs->interface != fmt->iface) {
-               if (usb_set_interface(subs->dev, subs->interface, 0) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: return to setting 0 failed\n",
-                               dev->devnum, fmt->iface, fmt->altsetting);
-                       return -EIO;
-               }
-               subs->interface = -1;
-               subs->format = 0;
-       }
-
-       /* set interface */
-       if (subs->interface != fmt->iface || subs->format != fmt->altset_idx) {
-               if (usb_set_interface(dev, fmt->iface, fmt->altsetting) < 0) {
-                       snd_printk(KERN_ERR "%d:%d:%d: usb_set_interface failed\n",
-                                  dev->devnum, fmt->iface, fmt->altsetting);
-                       return -EIO;
-               }
-               snd_printdd(KERN_INFO "setting usb interface %d:%d\n", fmt->iface, fmt->altsetting);
-               subs->interface = fmt->iface;
-               subs->format = fmt->altset_idx;
-       }
-
-       /* create a data pipe */
-       ep = fmt->endpoint & USB_ENDPOINT_NUMBER_MASK;
-       if (is_playback)
-               subs->datapipe = usb_sndisocpipe(dev, ep);
-       else
-               subs->datapipe = usb_rcvisocpipe(dev, ep);
-       subs->datainterval = fmt->datainterval;
-       subs->syncpipe = subs->syncinterval = 0;
-       subs->maxpacksize = fmt->maxpacksize;
-       subs->fill_max = 0;
-
-       /* we need a sync pipe in async OUT or adaptive IN mode */
-       /* check the number of EP, since some devices have broken
-        * descriptors which fool us.  if it has only one EP,
-        * assume it as adaptive-out or sync-in.
-        */
-       attr = fmt->ep_attr & USB_ENDPOINT_SYNCTYPE;
-       if (((is_playback && attr == USB_ENDPOINT_SYNC_ASYNC) ||
-            (! is_playback && attr == USB_ENDPOINT_SYNC_ADAPTIVE)) &&
-           altsd->bNumEndpoints >= 2) {
-               /* check sync-pipe endpoint */
-               /* ... and check descriptor size before accessing bSynchAddress
-                  because there is a version of the SB Audigy 2 NX firmware lacking
-                  the audio fields in the endpoint descriptors */
-               if ((get_endpoint(alts, 1)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 0x01 ||
-                   (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
-                    get_endpoint(alts, 1)->bSynchAddress != 0)) {
-                       snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
-                                  dev->devnum, fmt->iface, fmt->altsetting);
-                       return -EINVAL;
-               }
-               ep = get_endpoint(alts, 1)->bEndpointAddress;
-               if (get_endpoint(alts, 0)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
-                   (( is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress | USB_DIR_IN)) ||
-                    (!is_playback && ep != (unsigned int)(get_endpoint(alts, 0)->bSynchAddress & ~USB_DIR_IN)))) {
-                       snd_printk(KERN_ERR "%d:%d:%d : invalid synch pipe\n",
-                                  dev->devnum, fmt->iface, fmt->altsetting);
-                       return -EINVAL;
-               }
-               ep &= USB_ENDPOINT_NUMBER_MASK;
-               if (is_playback)
-                       subs->syncpipe = usb_rcvisocpipe(dev, ep);
-               else
-                       subs->syncpipe = usb_sndisocpipe(dev, ep);
-               if (get_endpoint(alts, 1)->bLength >= USB_DT_ENDPOINT_AUDIO_SIZE &&
-                   get_endpoint(alts, 1)->bRefresh >= 1 &&
-                   get_endpoint(alts, 1)->bRefresh <= 9)
-                       subs->syncinterval = get_endpoint(alts, 1)->bRefresh;
-               else if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
-                       subs->syncinterval = 1;
-               else if (get_endpoint(alts, 1)->bInterval >= 1 &&
-                        get_endpoint(alts, 1)->bInterval <= 16)
-                       subs->syncinterval = get_endpoint(alts, 1)->bInterval - 1;
-               else
-                       subs->syncinterval = 3;
-       }
-
-       /* always fill max packet size */
-       if (fmt->attributes & UAC_EP_CS_ATTR_FILL_MAX)
-               subs->fill_max = 1;
-
-       if ((err = init_usb_pitch(dev, subs->interface, alts, fmt)) < 0)
-               return err;
-
-       subs->cur_audiofmt = fmt;
-
-       switch (subs->stream->chip->usb_id) {
-       case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
-       case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
-       case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
-               set_format_emu_quirk(subs, fmt);
-               break;
-       }
-
-#if 0
-       printk(KERN_DEBUG
-              "setting done: format = %d, rate = %d..%d, channels = %d\n",
-              fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
-       printk(KERN_DEBUG
-              "  datapipe = 0x%0x, syncpipe = 0x%0x\n",
-              subs->datapipe, subs->syncpipe);
-#endif
-
-       return 0;
-}
-
-/*
- * hw_params callback
- *
- * allocate a buffer and set the given audio format.
- *
- * so far we use a physically linear buffer although packetize transfer
- * doesn't need a continuous area.
- * if sg buffer is supported on the later version of alsa, we'll follow
- * that.
- */
-static int snd_usb_hw_params(struct snd_pcm_substream *substream,
-                            struct snd_pcm_hw_params *hw_params)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-       struct audioformat *fmt;
-       unsigned int channels, rate, format;
-       int ret, changed;
-
-       ret = snd_pcm_lib_alloc_vmalloc_buffer(substream,
-                                              params_buffer_bytes(hw_params));
-       if (ret < 0)
-               return ret;
-
-       format = params_format(hw_params);
-       rate = params_rate(hw_params);
-       channels = params_channels(hw_params);
-       fmt = find_format(subs, format, rate, channels);
-       if (!fmt) {
-               snd_printd(KERN_DEBUG "cannot set format: format = %#x, rate = %d, channels = %d\n",
-                          format, rate, channels);
-               return -EINVAL;
-       }
-
-       changed = subs->cur_audiofmt != fmt ||
-               subs->period_bytes != params_period_bytes(hw_params) ||
-               subs->cur_rate != rate;
-       if ((ret = set_format(subs, fmt)) < 0)
-               return ret;
-
-       if (subs->cur_rate != rate) {
-               struct usb_host_interface *alts;
-               struct usb_interface *iface;
-               iface = usb_ifnum_to_if(subs->dev, fmt->iface);
-               alts = &iface->altsetting[fmt->altset_idx];
-               ret = init_usb_sample_rate(subs->dev, subs->interface, alts, fmt, rate);
-               if (ret < 0)
-                       return ret;
-               subs->cur_rate = rate;
-       }
-
-       if (changed) {
-               /* format changed */
-               release_substream_urbs(subs, 0);
-               /* influenced: period_bytes, channels, rate, format, */
-               ret = init_substream_urbs(subs, params_period_bytes(hw_params),
-                                         params_rate(hw_params),
-                                         snd_pcm_format_physical_width(params_format(hw_params)) * params_channels(hw_params));
-       }
-
-       return ret;
-}
-
-/*
- * hw_free callback
- *
- * reset the audio format and release the buffer
- */
-static int snd_usb_hw_free(struct snd_pcm_substream *substream)
-{
-       struct snd_usb_substream *subs = substream->runtime->private_data;
-
-       subs->cur_audiofmt = NULL;
-       subs->cur_rate = 0;
-       subs->period_bytes = 0;
-       if (!subs->stream->chip->shutdown)
-               release_substream_urbs(subs, 0);
-       return snd_pcm_lib_free_vmalloc_buffer(substream);
-}
-
-/*
- * prepare callback
- *
- * only a few subtle things...
- */
-static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
-{
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_usb_substream *subs = runtime->private_data;
-
-       if (! subs->cur_audiofmt) {
-               snd_printk(KERN_ERR "usbaudio: no format is specified!\n");
-               return -ENXIO;
-       }
-
-       /* some unit conversions in runtime */
-       subs->maxframesize = bytes_to_frames(runtime, subs->maxpacksize);
-       subs->curframesize = bytes_to_frames(runtime, subs->curpacksize);
-
-       /* reset the pointer */
-       subs->hwptr_done = 0;
-       subs->transfer_done = 0;
-       subs->phase = 0;
-       runtime->delay = 0;
-
-       /* clear urbs (to be sure) */
-       deactivate_urbs(subs, 0, 1);
-       wait_clear_urbs(subs);
-
-       /* for playback, submit the URBs now; otherwise, the first hwptr_done
-        * updates for all URBs would happen at the same time when starting */
-       if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
-               subs->ops.prepare = prepare_nodata_playback_urb;
-               return start_urbs(subs, runtime);
-       } else
-               return 0;
-}
-
-static struct snd_pcm_hardware snd_usb_hardware =
-{
-       .info =                 SNDRV_PCM_INFO_MMAP |
-                               SNDRV_PCM_INFO_MMAP_VALID |
-                               SNDRV_PCM_INFO_BATCH |
-                               SNDRV_PCM_INFO_INTERLEAVED |
-                               SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                               SNDRV_PCM_INFO_PAUSE,
-       .buffer_bytes_max =     1024 * 1024,
-       .period_bytes_min =     64,
-       .period_bytes_max =     512 * 1024,
-       .periods_min =          2,
-       .periods_max =          1024,
-};
-
-/*
- * h/w constraints
- */
-
-#ifdef HW_CONST_DEBUG
-#define hwc_debug(fmt, args...) printk(KERN_DEBUG fmt, ##args)
-#else
-#define hwc_debug(fmt, args...) /**/
-#endif
-
-static int hw_check_valid_format(struct snd_usb_substream *subs,
-                                struct snd_pcm_hw_params *params,
-                                struct audioformat *fp)
-{
-       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
-       struct snd_interval *ct = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
-       struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
-       struct snd_interval *pt = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
-       unsigned int ptime;
-
-       /* check the format */
-       if (!snd_mask_test(fmts, fp->format)) {
-               hwc_debug("   > check: no supported format %d\n", fp->format);
-               return 0;
-       }
-       /* check the channels */
-       if (fp->channels < ct->min || fp->channels > ct->max) {
-               hwc_debug("   > check: no valid channels %d (%d/%d)\n", fp->channels, ct->min, ct->max);
-               return 0;
-       }
-       /* check the rate is within the range */
-       if (fp->rate_min > it->max || (fp->rate_min == it->max && it->openmax)) {
-               hwc_debug("   > check: rate_min %d > max %d\n", fp->rate_min, it->max);
-               return 0;
-       }
-       if (fp->rate_max < it->min || (fp->rate_max == it->min && it->openmin)) {
-               hwc_debug("   > check: rate_max %d < min %d\n", fp->rate_max, it->min);
-               return 0;
-       }
-       /* check whether the period time is >= the data packet interval */
-       if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH) {
-               ptime = 125 * (1 << fp->datainterval);
-               if (ptime > pt->max || (ptime == pt->max && pt->openmax)) {
-                       hwc_debug("   > check: ptime %u > max %u\n", ptime, pt->max);
-                       return 0;
-               }
-       }
-       return 1;
-}
-
-static int hw_rule_rate(struct snd_pcm_hw_params *params,
-                       struct snd_pcm_hw_rule *rule)
-{
-       struct snd_usb_substream *subs = rule->private;
-       struct list_head *p;
-       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
-       unsigned int rmin, rmax;
-       int changed;
-
-       hwc_debug("hw_rule_rate: (%d,%d)\n", it->min, it->max);
-       changed = 0;
-       rmin = rmax = 0;
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               if (!hw_check_valid_format(subs, params, fp))
-                       continue;
-               if (changed++) {
-                       if (rmin > fp->rate_min)
-                               rmin = fp->rate_min;
-                       if (rmax < fp->rate_max)
-                               rmax = fp->rate_max;
-               } else {
-                       rmin = fp->rate_min;
-                       rmax = fp->rate_max;
-               }
-       }
-
-       if (!changed) {
-               hwc_debug("  --> get empty\n");
-               it->empty = 1;
-               return -EINVAL;
-       }
-
-       changed = 0;
-       if (it->min < rmin) {
-               it->min = rmin;
-               it->openmin = 0;
-               changed = 1;
-       }
-       if (it->max > rmax) {
-               it->max = rmax;
-               it->openmax = 0;
-               changed = 1;
-       }
-       if (snd_interval_checkempty(it)) {
-               it->empty = 1;
-               return -EINVAL;
-       }
-       hwc_debug("  --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
-       return changed;
-}
-
-
-static int hw_rule_channels(struct snd_pcm_hw_params *params,
-                           struct snd_pcm_hw_rule *rule)
-{
-       struct snd_usb_substream *subs = rule->private;
-       struct list_head *p;
-       struct snd_interval *it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
-       unsigned int rmin, rmax;
-       int changed;
-
-       hwc_debug("hw_rule_channels: (%d,%d)\n", it->min, it->max);
-       changed = 0;
-       rmin = rmax = 0;
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               if (!hw_check_valid_format(subs, params, fp))
-                       continue;
-               if (changed++) {
-                       if (rmin > fp->channels)
-                               rmin = fp->channels;
-                       if (rmax < fp->channels)
-                               rmax = fp->channels;
-               } else {
-                       rmin = fp->channels;
-                       rmax = fp->channels;
-               }
-       }
-
-       if (!changed) {
-               hwc_debug("  --> get empty\n");
-               it->empty = 1;
-               return -EINVAL;
-       }
-
-       changed = 0;
-       if (it->min < rmin) {
-               it->min = rmin;
-               it->openmin = 0;
-               changed = 1;
-       }
-       if (it->max > rmax) {
-               it->max = rmax;
-               it->openmax = 0;
-               changed = 1;
-       }
-       if (snd_interval_checkempty(it)) {
-               it->empty = 1;
-               return -EINVAL;
-       }
-       hwc_debug("  --> (%d, %d) (changed = %d)\n", it->min, it->max, changed);
-       return changed;
-}
-
-static int hw_rule_format(struct snd_pcm_hw_params *params,
-                         struct snd_pcm_hw_rule *rule)
-{
-       struct snd_usb_substream *subs = rule->private;
-       struct list_head *p;
-       struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
-       u64 fbits;
-       u32 oldbits[2];
-       int changed;
-
-       hwc_debug("hw_rule_format: %x:%x\n", fmt->bits[0], fmt->bits[1]);
-       fbits = 0;
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               if (!hw_check_valid_format(subs, params, fp))
-                       continue;
-               fbits |= (1ULL << fp->format);
-       }
-
-       oldbits[0] = fmt->bits[0];
-       oldbits[1] = fmt->bits[1];
-       fmt->bits[0] &= (u32)fbits;
-       fmt->bits[1] &= (u32)(fbits >> 32);
-       if (!fmt->bits[0] && !fmt->bits[1]) {
-               hwc_debug("  --> get empty\n");
-               return -EINVAL;
-       }
-       changed = (oldbits[0] != fmt->bits[0] || oldbits[1] != fmt->bits[1]);
-       hwc_debug("  --> %x:%x (changed = %d)\n", fmt->bits[0], fmt->bits[1], changed);
-       return changed;
-}
-
-static int hw_rule_period_time(struct snd_pcm_hw_params *params,
-                              struct snd_pcm_hw_rule *rule)
-{
-       struct snd_usb_substream *subs = rule->private;
-       struct audioformat *fp;
-       struct snd_interval *it;
-       unsigned char min_datainterval;
-       unsigned int pmin;
-       int changed;
-
-       it = hw_param_interval(params, SNDRV_PCM_HW_PARAM_PERIOD_TIME);
-       hwc_debug("hw_rule_period_time: (%u,%u)\n", it->min, it->max);
-       min_datainterval = 0xff;
-       list_for_each_entry(fp, &subs->fmt_list, list) {
-               if (!hw_check_valid_format(subs, params, fp))
-                       continue;
-               min_datainterval = min(min_datainterval, fp->datainterval);
-       }
-       if (min_datainterval == 0xff) {
-               hwc_debug("  --> get emtpy\n");
-               it->empty = 1;
-               return -EINVAL;
-       }
-       pmin = 125 * (1 << min_datainterval);
-       changed = 0;
-       if (it->min < pmin) {
-               it->min = pmin;
-               it->openmin = 0;
-               changed = 1;
-       }
-       if (snd_interval_checkempty(it)) {
-               it->empty = 1;
-               return -EINVAL;
-       }
-       hwc_debug("  --> (%u,%u) (changed = %d)\n", it->min, it->max, changed);
-       return changed;
-}
-
-/*
- *  If the device supports unusual bit rates, does the request meet these?
- */
-static int snd_usb_pcm_check_knot(struct snd_pcm_runtime *runtime,
-                                 struct snd_usb_substream *subs)
-{
-       struct audioformat *fp;
-       int count = 0, needs_knot = 0;
-       int err;
-
-       list_for_each_entry(fp, &subs->fmt_list, list) {
-               if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS)
-                       return 0;
-               count += fp->nr_rates;
-               if (fp->rates & SNDRV_PCM_RATE_KNOT)
-                       needs_knot = 1;
-       }
-       if (!needs_knot)
-               return 0;
-
-       subs->rate_list.count = count;
-       subs->rate_list.list = kmalloc(sizeof(int) * count, GFP_KERNEL);
-       subs->rate_list.mask = 0;
-       count = 0;
-       list_for_each_entry(fp, &subs->fmt_list, list) {
-               int i;
-               for (i = 0; i < fp->nr_rates; i++)
-                       subs->rate_list.list[count++] = fp->rate_table[i];
-       }
-       err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
-                                        &subs->rate_list);
-       if (err < 0)
-               return err;
-
-       return 0;
-}
-
-
-/*
- * set up the runtime hardware information.
- */
-
-static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs)
-{
-       struct list_head *p;
-       unsigned int pt, ptmin;
-       int param_period_time_if_needed;
-       int err;
-
-       runtime->hw.formats = subs->formats;
-
-       runtime->hw.rate_min = 0x7fffffff;
-       runtime->hw.rate_max = 0;
-       runtime->hw.channels_min = 256;
-       runtime->hw.channels_max = 0;
-       runtime->hw.rates = 0;
-       ptmin = UINT_MAX;
-       /* check min/max rates and channels */
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               runtime->hw.rates |= fp->rates;
-               if (runtime->hw.rate_min > fp->rate_min)
-                       runtime->hw.rate_min = fp->rate_min;
-               if (runtime->hw.rate_max < fp->rate_max)
-                       runtime->hw.rate_max = fp->rate_max;
-               if (runtime->hw.channels_min > fp->channels)
-                       runtime->hw.channels_min = fp->channels;
-               if (runtime->hw.channels_max < fp->channels)
-                       runtime->hw.channels_max = fp->channels;
-               if (fp->fmt_type == UAC_FORMAT_TYPE_II && fp->frame_size > 0) {
-                       /* FIXME: there might be more than one audio formats... */
-                       runtime->hw.period_bytes_min = runtime->hw.period_bytes_max =
-                               fp->frame_size;
-               }
-               pt = 125 * (1 << fp->datainterval);
-               ptmin = min(ptmin, pt);
-       }
-
-       param_period_time_if_needed = SNDRV_PCM_HW_PARAM_PERIOD_TIME;
-       if (snd_usb_get_speed(subs->dev) != USB_SPEED_HIGH)
-               /* full speed devices have fixed data packet interval */
-               ptmin = 1000;
-       if (ptmin == 1000)
-               /* if period time doesn't go below 1 ms, no rules needed */
-               param_period_time_if_needed = -1;
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
-                                    ptmin, UINT_MAX);
-
-       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
-                                      hw_rule_rate, subs,
-                                      SNDRV_PCM_HW_PARAM_FORMAT,
-                                      SNDRV_PCM_HW_PARAM_CHANNELS,
-                                      param_period_time_if_needed,
-                                      -1)) < 0)
-               return err;
-       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
-                                      hw_rule_channels, subs,
-                                      SNDRV_PCM_HW_PARAM_FORMAT,
-                                      SNDRV_PCM_HW_PARAM_RATE,
-                                      param_period_time_if_needed,
-                                      -1)) < 0)
-               return err;
-       if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_FORMAT,
-                                      hw_rule_format, subs,
-                                      SNDRV_PCM_HW_PARAM_RATE,
-                                      SNDRV_PCM_HW_PARAM_CHANNELS,
-                                      param_period_time_if_needed,
-                                      -1)) < 0)
-               return err;
-       if (param_period_time_if_needed >= 0) {
-               err = snd_pcm_hw_rule_add(runtime, 0,
-                                         SNDRV_PCM_HW_PARAM_PERIOD_TIME,
-                                         hw_rule_period_time, subs,
-                                         SNDRV_PCM_HW_PARAM_FORMAT,
-                                         SNDRV_PCM_HW_PARAM_CHANNELS,
-                                         SNDRV_PCM_HW_PARAM_RATE,
-                                         -1);
-               if (err < 0)
-                       return err;
-       }
-       if ((err = snd_usb_pcm_check_knot(runtime, subs)) < 0)
-               return err;
-       return 0;
-}
-
-static int snd_usb_pcm_open(struct snd_pcm_substream *substream, int direction)
-{
-       struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_usb_substream *subs = &as->substream[direction];
-
-       subs->interface = -1;
-       subs->format = 0;
-       runtime->hw = snd_usb_hardware;
-       runtime->private_data = subs;
-       subs->pcm_substream = substream;
-       return setup_hw_info(runtime, subs);
-}
-
-static int snd_usb_pcm_close(struct snd_pcm_substream *substream, int direction)
-{
-       struct snd_usb_stream *as = snd_pcm_substream_chip(substream);
-       struct snd_usb_substream *subs = &as->substream[direction];
-
-       if (!as->chip->shutdown && subs->interface >= 0) {
-               usb_set_interface(subs->dev, subs->interface, 0);
-               subs->interface = -1;
-       }
-       subs->pcm_substream = NULL;
-       return 0;
-}
-
-static int snd_usb_playback_open(struct snd_pcm_substream *substream)
-{
-       return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_PLAYBACK);
-}
-
-static int snd_usb_playback_close(struct snd_pcm_substream *substream)
-{
-       return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_PLAYBACK);
-}
-
-static int snd_usb_capture_open(struct snd_pcm_substream *substream)
-{
-       return snd_usb_pcm_open(substream, SNDRV_PCM_STREAM_CAPTURE);
-}
-
-static int snd_usb_capture_close(struct snd_pcm_substream *substream)
-{
-       return snd_usb_pcm_close(substream, SNDRV_PCM_STREAM_CAPTURE);
-}
-
-static struct snd_pcm_ops snd_usb_playback_ops = {
-       .open =         snd_usb_playback_open,
-       .close =        snd_usb_playback_close,
-       .ioctl =        snd_pcm_lib_ioctl,
-       .hw_params =    snd_usb_hw_params,
-       .hw_free =      snd_usb_hw_free,
-       .prepare =      snd_usb_pcm_prepare,
-       .trigger =      snd_usb_pcm_playback_trigger,
-       .pointer =      snd_usb_pcm_pointer,
-       .page =         snd_pcm_lib_get_vmalloc_page,
-       .mmap =         snd_pcm_lib_mmap_vmalloc,
-};
-
-static struct snd_pcm_ops snd_usb_capture_ops = {
-       .open =         snd_usb_capture_open,
-       .close =        snd_usb_capture_close,
-       .ioctl =        snd_pcm_lib_ioctl,
-       .hw_params =    snd_usb_hw_params,
-       .hw_free =      snd_usb_hw_free,
-       .prepare =      snd_usb_pcm_prepare,
-       .trigger =      snd_usb_pcm_capture_trigger,
-       .pointer =      snd_usb_pcm_pointer,
-       .page =         snd_pcm_lib_get_vmalloc_page,
-       .mmap =         snd_pcm_lib_mmap_vmalloc,
-};
-
-
-
-/*
- * helper functions
- */
-
-/*
- * combine bytes and get an integer value
- */
-unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size)
-{
-       switch (size) {
-       case 1:  return *bytes;
-       case 2:  return combine_word(bytes);
-       case 3:  return combine_triple(bytes);
-       case 4:  return combine_quad(bytes);
-       default: return 0;
-       }
-}
-
-/*
- * parse descriptor buffer and return the pointer starting the given
- * descriptor type.
- */
-void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype)
-{
-       u8 *p, *end, *next;
-
-       p = descstart;
-       end = p + desclen;
-       for (; p < end;) {
-               if (p[0] < 2)
-                       return NULL;
-               next = p + p[0];
-               if (next > end)
-                       return NULL;
-               if (p[1] == dtype && (!after || (void *)p > after)) {
-                       return p;
-               }
-               p = next;
-       }
-       return NULL;
-}
-
-/*
- * find a class-specified interface descriptor with the given subtype.
- */
-void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype)
-{
-       unsigned char *p = after;
-
-       while ((p = snd_usb_find_desc(buffer, buflen, p,
-                                     USB_DT_CS_INTERFACE)) != NULL) {
-               if (p[0] >= 3 && p[2] == dsubtype)
-                       return p;
-       }
-       return NULL;
-}
-
-/*
- * Wrapper for usb_control_msg().
- * Allocates a temp buffer to prevent dmaing from/to the stack.
- */
-int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
-                   __u8 requesttype, __u16 value, __u16 index, void *data,
-                   __u16 size, int timeout)
-{
-       int err;
-       void *buf = NULL;
-
-       if (size > 0) {
-               buf = kmemdup(data, size, GFP_KERNEL);
-               if (!buf)
-                       return -ENOMEM;
-       }
-       err = usb_control_msg(dev, pipe, request, requesttype,
-                             value, index, buf, size, timeout);
-       if (size > 0) {
-               memcpy(data, buf, size);
-               kfree(buf);
-       }
-       return err;
-}
-
-
-/*
- * entry point for linux usb interface
- */
-
-static int usb_audio_probe(struct usb_interface *intf,
-                          const struct usb_device_id *id);
-static void usb_audio_disconnect(struct usb_interface *intf);
-
-#ifdef CONFIG_PM
-static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message);
-static int usb_audio_resume(struct usb_interface *intf);
-#else
-#define usb_audio_suspend NULL
-#define usb_audio_resume NULL
-#endif
-
-static struct usb_device_id usb_audio_ids [] = {
-#include "usbquirks.h"
-    { .match_flags = (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS),
-      .bInterfaceClass = USB_CLASS_AUDIO,
-      .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL },
-    { }                                                /* Terminating entry */
-};
-
-MODULE_DEVICE_TABLE (usb, usb_audio_ids);
-
-static struct usb_driver usb_audio_driver = {
-       .name =         "snd-usb-audio",
-       .probe =        usb_audio_probe,
-       .disconnect =   usb_audio_disconnect,
-       .suspend =      usb_audio_suspend,
-       .resume =       usb_audio_resume,
-       .id_table =     usb_audio_ids,
-};
-
-
-#if defined(CONFIG_PROC_FS) && defined(CONFIG_SND_VERBOSE_PROCFS)
-
-/*
- * proc interface for list the supported pcm formats
- */
-static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
-{
-       struct list_head *p;
-       static char *sync_types[4] = {
-               "NONE", "ASYNC", "ADAPTIVE", "SYNC"
-       };
-
-       list_for_each(p, &subs->fmt_list) {
-               struct audioformat *fp;
-               fp = list_entry(p, struct audioformat, list);
-               snd_iprintf(buffer, "  Interface %d\n", fp->iface);
-               snd_iprintf(buffer, "    Altset %d\n", fp->altsetting);
-               snd_iprintf(buffer, "    Format: %s\n",
-                           snd_pcm_format_name(fp->format));
-               snd_iprintf(buffer, "    Channels: %d\n", fp->channels);
-               snd_iprintf(buffer, "    Endpoint: %d %s (%s)\n",
-                           fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
-                           fp->endpoint & USB_DIR_IN ? "IN" : "OUT",
-                           sync_types[(fp->ep_attr & USB_ENDPOINT_SYNCTYPE) >> 2]);
-               if (fp->rates & SNDRV_PCM_RATE_CONTINUOUS) {
-                       snd_iprintf(buffer, "    Rates: %d - %d (continuous)\n",
-                                   fp->rate_min, fp->rate_max);
-               } else {
-                       unsigned int i;
-                       snd_iprintf(buffer, "    Rates: ");
-                       for (i = 0; i < fp->nr_rates; i++) {
-                               if (i > 0)
-                                       snd_iprintf(buffer, ", ");
-                               snd_iprintf(buffer, "%d", fp->rate_table[i]);
-                       }
-                       snd_iprintf(buffer, "\n");
-               }
-               if (snd_usb_get_speed(subs->dev) == USB_SPEED_HIGH)
-                       snd_iprintf(buffer, "    Data packet interval: %d us\n",
-                                   125 * (1 << fp->datainterval));
-               // snd_iprintf(buffer, "    Max Packet Size = %d\n", fp->maxpacksize);
-               // snd_iprintf(buffer, "    EP Attribute = %#x\n", fp->attributes);
-       }
-}
-
-static void proc_dump_substream_status(struct snd_usb_substream *subs, struct snd_info_buffer *buffer)
-{
-       if (subs->running) {
-               unsigned int i;
-               snd_iprintf(buffer, "  Status: Running\n");
-               snd_iprintf(buffer, "    Interface = %d\n", subs->interface);
-               snd_iprintf(buffer, "    Altset = %d\n", subs->format);
-               snd_iprintf(buffer, "    URBs = %d [ ", subs->nurbs);
-               for (i = 0; i < subs->nurbs; i++)
-                       snd_iprintf(buffer, "%d ", subs->dataurb[i].packets);
-               snd_iprintf(buffer, "]\n");
-               snd_iprintf(buffer, "    Packet Size = %d\n", subs->curpacksize);
-               snd_iprintf(buffer, "    Momentary freq = %u Hz (%#x.%04x)\n",
-                           snd_usb_get_speed(subs->dev) == USB_SPEED_FULL
-                           ? get_full_speed_hz(subs->freqm)
-                           : get_high_speed_hz(subs->freqm),
-                           subs->freqm >> 16, subs->freqm & 0xffff);
-       } else {
-               snd_iprintf(buffer, "  Status: Stop\n");
-       }
-}
-
-static void proc_pcm_format_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
-{
-       struct snd_usb_stream *stream = entry->private_data;
-
-       snd_iprintf(buffer, "%s : %s\n", stream->chip->card->longname, stream->pcm->name);
-
-       if (stream->substream[SNDRV_PCM_STREAM_PLAYBACK].num_formats) {
-               snd_iprintf(buffer, "\nPlayback:\n");
-               proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
-               proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_PLAYBACK], buffer);
-       }
-       if (stream->substream[SNDRV_PCM_STREAM_CAPTURE].num_formats) {
-               snd_iprintf(buffer, "\nCapture:\n");
-               proc_dump_substream_status(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
-               proc_dump_substream_formats(&stream->substream[SNDRV_PCM_STREAM_CAPTURE], buffer);
-       }
-}
-
-static void proc_pcm_format_add(struct snd_usb_stream *stream)
-{
-       struct snd_info_entry *entry;
-       char name[32];
-       struct snd_card *card = stream->chip->card;
-
-       sprintf(name, "stream%d", stream->pcm_index);
-       if (!snd_card_proc_new(card, name, &entry))
-               snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
-}
-
-#else
-
-static inline void proc_pcm_format_add(struct snd_usb_stream *stream)
-{
-}
-
-#endif
-
-/*
- * initialize the substream instance.
- */
-
-static void init_substream(struct snd_usb_stream *as, int stream, struct audioformat *fp)
-{
-       struct snd_usb_substream *subs = &as->substream[stream];
-
-       INIT_LIST_HEAD(&subs->fmt_list);
-       spin_lock_init(&subs->lock);
-
-       subs->stream = as;
-       subs->direction = stream;
-       subs->dev = as->chip->dev;
-       subs->txfr_quirk = as->chip->txfr_quirk;
-       if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) {
-               subs->ops = audio_urb_ops[stream];
-       } else {
-               subs->ops = audio_urb_ops_high_speed[stream];
-               switch (as->chip->usb_id) {
-               case USB_ID(0x041e, 0x3f02): /* E-Mu 0202 USB */
-               case USB_ID(0x041e, 0x3f04): /* E-Mu 0404 USB */
-               case USB_ID(0x041e, 0x3f0a): /* E-Mu Tracker Pre */
-                       subs->ops.retire_sync = retire_playback_sync_urb_hs_emu;
-                       break;
-               }
-       }
-       snd_pcm_set_ops(as->pcm, stream,
-                       stream == SNDRV_PCM_STREAM_PLAYBACK ?
-                       &snd_usb_playback_ops : &snd_usb_capture_ops);
-
-       list_add_tail(&fp->list, &subs->fmt_list);
-       subs->formats |= 1ULL << fp->format;
-       subs->endpoint = fp->endpoint;
-       subs->num_formats++;
-       subs->fmt_type = fp->fmt_type;
-}
-
-
-/*
- * free a substream
- */
-static void free_substream(struct snd_usb_substream *subs)
-{
-       struct list_head *p, *n;
-
-       if (!subs->num_formats)
-               return; /* not initialized */
-       list_for_each_safe(p, n, &subs->fmt_list) {
-               struct audioformat *fp = list_entry(p, struct audioformat, list);
-               kfree(fp->rate_table);
-               kfree(fp);
-       }
-       kfree(subs->rate_list.list);
-}
-
-
-/*
- * free a usb stream instance
- */
-static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
-{
-       free_substream(&stream->substream[0]);
-       free_substream(&stream->substream[1]);
-       list_del(&stream->list);
-       kfree(stream);
-}
-
-static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
-{
-       struct snd_usb_stream *stream = pcm->private_data;
-       if (stream) {
-               stream->pcm = NULL;
-               snd_usb_audio_stream_free(stream);
-       }
-}
-
-
-/*
- * add this endpoint to the chip instance.
- * if a stream with the same endpoint already exists, append to it.
- * if not, create a new pcm stream.
- */
-static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audioformat *fp)
-{
-       struct list_head *p;
-       struct snd_usb_stream *as;
-       struct snd_usb_substream *subs;
-       struct snd_pcm *pcm;
-       int err;
-
-       list_for_each(p, &chip->pcm_list) {
-               as = list_entry(p, struct snd_usb_stream, list);
-               if (as->fmt_type != fp->fmt_type)
-                       continue;
-               subs = &as->substream[stream];
-               if (!subs->endpoint)
-                       continue;
-               if (subs->endpoint == fp->endpoint) {
-                       list_add_tail(&fp->list, &subs->fmt_list);
-                       subs->num_formats++;
-                       subs->formats |= 1ULL << fp->format;
-                       return 0;
-               }
-       }
-       /* look for an empty stream */
-       list_for_each(p, &chip->pcm_list) {
-               as = list_entry(p, struct snd_usb_stream, list);
-               if (as->fmt_type != fp->fmt_type)
-                       continue;
-               subs = &as->substream[stream];
-               if (subs->endpoint)
-                       continue;
-               err = snd_pcm_new_stream(as->pcm, stream, 1);
-               if (err < 0)
-                       return err;
-               init_substream(as, stream, fp);
-               return 0;
-       }
-
-       /* create a new pcm */
-       as = kzalloc(sizeof(*as), GFP_KERNEL);
-       if (!as)
-               return -ENOMEM;
-       as->pcm_index = chip->pcm_devs;
-       as->chip = chip;
-       as->fmt_type = fp->fmt_type;
-       err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs,
-                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0,
-                         stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1,
-                         &pcm);
-       if (err < 0) {
-               kfree(as);
-               return err;
-       }
-       as->pcm = pcm;
-       pcm->private_data = as;
-       pcm->private_free = snd_usb_audio_pcm_free;
-       pcm->info_flags = 0;
-       if (chip->pcm_devs > 0)
-               sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
-       else
-               strcpy(pcm->name, "USB Audio");
-
-       init_substream(as, stream, fp);
-
-       list_add(&as->list, &chip->pcm_list);
-       chip->pcm_devs++;
-
-       proc_pcm_format_add(as);
-
-       return 0;
-}
-
-
-/*
- * check if the device uses big-endian samples
- */
-static int is_big_endian_format(struct snd_usb_audio *chip, struct audioformat *fp)
-{
-       switch (chip->usb_id) {
-       case USB_ID(0x0763, 0x2001): /* M-Audio Quattro: captured data only */
-               if (fp->endpoint & USB_DIR_IN)
-                       return 1;
-               break;
-       case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
-               if (device_setup[chip->index] == 0x00 ||
-                   fp->altsetting==1 || fp->altsetting==2 || fp->altsetting==3)
-                       return 1;
-       }
-       return 0;
-}
-
-/*
- * parse the audio format type I descriptor
- * and returns the corresponding pcm format
- *
- * @dev: usb device
- * @fp: audioformat record
- * @format: the format tag (wFormatTag)
- * @fmt: the format type descriptor
- */
-static int parse_audio_format_i_type(struct snd_usb_audio *chip,
-                                    struct audioformat *fp,
-                                    int format, void *_fmt,
-                                    int protocol)
-{
-       int pcm_format, i;
-       int sample_width, sample_bytes;
-
-       switch (protocol) {
-       case UAC_VERSION_1: {
-               struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
-               sample_width = fmt->bBitResolution;
-               sample_bytes = fmt->bSubframeSize;
-               break;
-       }
-
-       case UAC_VERSION_2: {
-               struct uac_format_type_i_ext_descriptor *fmt = _fmt;
-               sample_width = fmt->bBitResolution;
-               sample_bytes = fmt->bSubslotSize;
-
-               /*
-                * FIXME
-                * USB audio class v2 devices specify a bitmap of possible
-                * audio formats rather than one fix value. For now, we just
-                * pick one of them and report that as the only possible
-                * value for this setting.
-                * The bit allocation map is in fact compatible to the
-                * wFormatTag of the v1 AS streaming descriptors, which is why
-                * we can simply map the matrix.
-                */
-
-               for (i = 0; i < 5; i++)
-                       if (format & (1UL << i)) {
-                               format = i + 1;
-                               break;
-                       }
-
-               break;
-       }
-
-       default:
-               return -EINVAL;
-       }
-
-       /* FIXME: correct endianess and sign? */
-       pcm_format = -1;
-
-       switch (format) {
-       case UAC_FORMAT_TYPE_I_UNDEFINED: /* some devices don't define this correctly... */
-               snd_printdd(KERN_INFO "%d:%u:%d : format type 0 is detected, processed as PCM\n",
-                           chip->dev->devnum, fp->iface, fp->altsetting);
-               /* fall-through */
-       case UAC_FORMAT_TYPE_I_PCM:
-               if (sample_width > sample_bytes * 8) {
-                       snd_printk(KERN_INFO "%d:%u:%d : sample bitwidth %d in over sample bytes %d\n",
-                                  chip->dev->devnum, fp->iface, fp->altsetting,
-                                  sample_width, sample_bytes);
-               }
-               /* check the format byte size */
-               switch (sample_bytes) {
-               case 1:
-                       pcm_format = SNDRV_PCM_FORMAT_S8;
-                       break;
-               case 2:
-                       if (is_big_endian_format(chip, fp))
-                               pcm_format = SNDRV_PCM_FORMAT_S16_BE; /* grrr, big endian!! */
-                       else
-                               pcm_format = SNDRV_PCM_FORMAT_S16_LE;
-                       break;
-               case 3:
-                       if (is_big_endian_format(chip, fp))
-                               pcm_format = SNDRV_PCM_FORMAT_S24_3BE; /* grrr, big endian!! */
-                       else
-                               pcm_format = SNDRV_PCM_FORMAT_S24_3LE;
-                       break;
-               case 4:
-                       pcm_format = SNDRV_PCM_FORMAT_S32_LE;
-                       break;
-               default:
-                       snd_printk(KERN_INFO "%d:%u:%d : unsupported sample bitwidth %d in %d bytes\n",
-                                  chip->dev->devnum, fp->iface, fp->altsetting,
-                                  sample_width, sample_bytes);
-                       break;
-               }
-               break;
-       case UAC_FORMAT_TYPE_I_PCM8:
-               pcm_format = SNDRV_PCM_FORMAT_U8;
-
-               /* Dallas DS4201 workaround: it advertises U8 format, but really
-                  supports S8. */
-               if (chip->usb_id == USB_ID(0x04fa, 0x4201))
-                       pcm_format = SNDRV_PCM_FORMAT_S8;
-               break;
-       case UAC_FORMAT_TYPE_I_IEEE_FLOAT:
-               pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
-               break;
-       case UAC_FORMAT_TYPE_I_ALAW:
-               pcm_format = SNDRV_PCM_FORMAT_A_LAW;
-               break;
-       case UAC_FORMAT_TYPE_I_MULAW:
-               pcm_format = SNDRV_PCM_FORMAT_MU_LAW;
-               break;
-       default:
-               snd_printk(KERN_INFO "%d:%u:%d : unsupported format type %d\n",
-                          chip->dev->devnum, fp->iface, fp->altsetting, format);
-               break;
-       }
-       return pcm_format;
-}
-
-
-/*
- * parse the format descriptor and stores the possible sample rates
- * on the audioformat table (audio class v1).
- *
- * @dev: usb device
- * @fp: audioformat record
- * @fmt: the format descriptor
- * @offset: the start offset of descriptor pointing the rate type
- *          (7 for type I and II, 8 for type II)
- */
-static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audioformat *fp,
-                                      unsigned char *fmt, int offset)
-{
-       int nr_rates = fmt[offset];
-
-       if (fmt[0] < offset + 1 + 3 * (nr_rates ? nr_rates : 2)) {
-               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
-                                  chip->dev->devnum, fp->iface, fp->altsetting);
-               return -1;
-       }
-
-       if (nr_rates) {
-               /*
-                * build the rate table and bitmap flags
-                */
-               int r, idx;
-
-               fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
-               if (fp->rate_table == NULL) {
-                       snd_printk(KERN_ERR "cannot malloc\n");
-                       return -1;
-               }
-
-               fp->nr_rates = 0;
-               fp->rate_min = fp->rate_max = 0;
-               for (r = 0, idx = offset + 1; r < nr_rates; r++, idx += 3) {
-                       unsigned int rate = combine_triple(&fmt[idx]);
-                       if (!rate)
-                               continue;
-                       /* C-Media CM6501 mislabels its 96 kHz altsetting */
-                       if (rate == 48000 && nr_rates == 1 &&
-                           (chip->usb_id == USB_ID(0x0d8c, 0x0201) ||
-                            chip->usb_id == USB_ID(0x0d8c, 0x0102)) &&
-                           fp->altsetting == 5 && fp->maxpacksize == 392)
-                               rate = 96000;
-                       /* Creative VF0470 Live Cam reports 16 kHz instead of 8kHz */
-                       if (rate == 16000 && chip->usb_id == USB_ID(0x041e, 0x4068))
-                               rate = 8000;
-                       fp->rate_table[fp->nr_rates] = rate;
-                       if (!fp->rate_min || rate < fp->rate_min)
-                               fp->rate_min = rate;
-                       if (!fp->rate_max || rate > fp->rate_max)
-                               fp->rate_max = rate;
-                       fp->rates |= snd_pcm_rate_to_rate_bit(rate);
-                       fp->nr_rates++;
-               }
-               if (!fp->nr_rates) {
-                       hwc_debug("All rates were zero. Skipping format!\n");
-                       return -1;
-               }
-       } else {
-               /* continuous rates */
-               fp->rates = SNDRV_PCM_RATE_CONTINUOUS;
-               fp->rate_min = combine_triple(&fmt[offset + 1]);
-               fp->rate_max = combine_triple(&fmt[offset + 4]);
-       }
-       return 0;
-}
-
-/*
- * parse the format descriptor and stores the possible sample rates
- * on the audioformat table (audio class v2).
- */
-static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
-                                      struct audioformat *fp,
-                                      struct usb_host_interface *iface)
-{
-       struct usb_device *dev = chip->dev;
-       unsigned char tmp[2], *data;
-       int i, nr_rates, data_size, ret = 0;
-
-       /* get the number of sample rates first by only fetching 2 bytes */
-       ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
-                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
-                              0x0100, chip->clock_id << 8, tmp, sizeof(tmp), 1000);
-
-       if (ret < 0) {
-               snd_printk(KERN_ERR "unable to retrieve number of sample rates\n");
-               goto err;
-       }
-
-       nr_rates = (tmp[1] << 8) | tmp[0];
-       data_size = 2 + 12 * nr_rates;
-       data = kzalloc(data_size, GFP_KERNEL);
-       if (!data) {
-               ret = -ENOMEM;
-               goto err;
-       }
-
-       /* now get the full information */
-       ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_RANGE,
-                              USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
-                              0x0100, chip->clock_id << 8, data, data_size, 1000);
-
-       if (ret < 0) {
-               snd_printk(KERN_ERR "unable to retrieve sample rate range\n");
-               ret = -EINVAL;
-               goto err_free;
-       }
-
-       fp->rate_table = kmalloc(sizeof(int) * nr_rates, GFP_KERNEL);
-       if (!fp->rate_table) {
-               ret = -ENOMEM;
-               goto err_free;
-       }
-
-       fp->nr_rates = 0;
-       fp->rate_min = fp->rate_max = 0;
-
-       for (i = 0; i < nr_rates; i++) {
-               int rate = combine_quad(&data[2 + 12 * i]);
-
-               fp->rate_table[fp->nr_rates] = rate;
-               if (!fp->rate_min || rate < fp->rate_min)
-                       fp->rate_min = rate;
-               if (!fp->rate_max || rate > fp->rate_max)
-                       fp->rate_max = rate;
-               fp->rates |= snd_pcm_rate_to_rate_bit(rate);
-               fp->nr_rates++;
-       }
-
-err_free:
-       kfree(data);
-err:
-       return ret;
-}
-
-/*
- * parse the format type I and III descriptors
- */
-static int parse_audio_format_i(struct snd_usb_audio *chip,
-                               struct audioformat *fp,
-                               int format, void *_fmt,
-                               struct usb_host_interface *iface)
-{
-       struct usb_interface_descriptor *altsd = get_iface_desc(iface);
-       struct uac_format_type_i_discrete_descriptor *fmt = _fmt;
-       int protocol = altsd->bInterfaceProtocol;
-       int pcm_format, ret;
-
-       if (fmt->bFormatType == UAC_FORMAT_TYPE_III) {
-               /* FIXME: the format type is really IECxxx
-                *        but we give normal PCM format to get the existing
-                *        apps working...
-                */
-               switch (chip->usb_id) {
-
-               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
-                       if (device_setup[chip->index] == 0x00 && 
-                           fp->altsetting == 6)
-                               pcm_format = SNDRV_PCM_FORMAT_S16_BE;
-                       else
-                               pcm_format = SNDRV_PCM_FORMAT_S16_LE;
-                       break;
-               default:
-                       pcm_format = SNDRV_PCM_FORMAT_S16_LE;
-               }
-       } else {
-               pcm_format = parse_audio_format_i_type(chip, fp, format, fmt, protocol);
-               if (pcm_format < 0)
-                       return -1;
-       }
-
-       fp->format = pcm_format;
-
-       /* gather possible sample rates */
-       /* audio class v1 reports possible sample rates as part of the
-        * proprietary class specific descriptor.
-        * audio class v2 uses class specific EP0 range requests for that.
-        */
-       switch (protocol) {
-       case UAC_VERSION_1:
-               fp->channels = fmt->bNrChannels;
-               ret = parse_audio_format_rates_v1(chip, fp, _fmt, 7);
-               break;
-       case UAC_VERSION_2:
-               /* fp->channels is already set in this case */
-               ret = parse_audio_format_rates_v2(chip, fp, iface);
-               break;
-       }
-
-       if (fp->channels < 1) {
-               snd_printk(KERN_ERR "%d:%u:%d : invalid channels %d\n",
-                          chip->dev->devnum, fp->iface, fp->altsetting, fp->channels);
-               return -1;
-       }
-
-       return ret;
-}
-
-/*
- * parse the format type II descriptor
- */
-static int parse_audio_format_ii(struct snd_usb_audio *chip,
-                                struct audioformat *fp,
-                                int format, void *_fmt,
-                                struct usb_host_interface *iface)
-{
-       int brate, framesize, ret;
-       struct usb_interface_descriptor *altsd = get_iface_desc(iface);
-       int protocol = altsd->bInterfaceProtocol;
-
-       switch (format) {
-       case UAC_FORMAT_TYPE_II_AC3:
-               /* FIXME: there is no AC3 format defined yet */
-               // fp->format = SNDRV_PCM_FORMAT_AC3;
-               fp->format = SNDRV_PCM_FORMAT_U8; /* temporarily hack to receive byte streams */
-               break;
-       case UAC_FORMAT_TYPE_II_MPEG:
-               fp->format = SNDRV_PCM_FORMAT_MPEG;
-               break;
-       default:
-               snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected.  processed as MPEG.\n",
-                          chip->dev->devnum, fp->iface, fp->altsetting, format);
-               fp->format = SNDRV_PCM_FORMAT_MPEG;
-               break;
-       }
-
-       fp->channels = 1;
-
-       switch (protocol) {
-       case UAC_VERSION_1: {
-               struct uac_format_type_ii_discrete_descriptor *fmt = _fmt;
-               brate = le16_to_cpu(fmt->wMaxBitRate);
-               framesize = le16_to_cpu(fmt->wSamplesPerFrame);
-               snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
-               fp->frame_size = framesize;
-               ret = parse_audio_format_rates_v1(chip, fp, _fmt, 8); /* fmt[8..] sample rates */
-               break;
-       }
-       case UAC_VERSION_2: {
-               struct uac_format_type_ii_ext_descriptor *fmt = _fmt;
-               brate = le16_to_cpu(fmt->wMaxBitRate);
-               framesize = le16_to_cpu(fmt->wSamplesPerFrame);
-               snd_printd(KERN_INFO "found format II with max.bitrate = %d, frame size=%d\n", brate, framesize);
-               fp->frame_size = framesize;
-               ret = parse_audio_format_rates_v2(chip, fp, iface);
-               break;
-       }
-       }
-
-       return ret;
-}
-
-static int parse_audio_format(struct snd_usb_audio *chip, struct audioformat *fp,
-                             int format, unsigned char *fmt, int stream,
-                             struct usb_host_interface *iface)
-{
-       int err;
-
-       switch (fmt[3]) {
-       case UAC_FORMAT_TYPE_I:
-       case UAC_FORMAT_TYPE_III:
-               err = parse_audio_format_i(chip, fp, format, fmt, iface);
-               break;
-       case UAC_FORMAT_TYPE_II:
-               err = parse_audio_format_ii(chip, fp, format, fmt, iface);
-               break;
-       default:
-               snd_printd(KERN_INFO "%d:%u:%d : format type %d is not supported yet\n",
-                          chip->dev->devnum, fp->iface, fp->altsetting, fmt[3]);
-               return -1;
-       }
-       fp->fmt_type = fmt[3];
-       if (err < 0)
-               return err;
-#if 1
-       /* FIXME: temporary hack for extigy/audigy 2 nx/zs */
-       /* extigy apparently supports sample rates other than 48k
-        * but not in ordinary way.  so we enable only 48k atm.
-        */
-       if (chip->usb_id == USB_ID(0x041e, 0x3000) ||
-           chip->usb_id == USB_ID(0x041e, 0x3020) ||
-           chip->usb_id == USB_ID(0x041e, 0x3061)) {
-               if (fmt[3] == UAC_FORMAT_TYPE_I &&
-                   fp->rates != SNDRV_PCM_RATE_48000 &&
-                   fp->rates != SNDRV_PCM_RATE_96000)
-                       return -1;
-       }
-#endif
-       return 0;
-}
-
-static unsigned char parse_datainterval(struct snd_usb_audio *chip,
-                                       struct usb_host_interface *alts)
-{
-       if (snd_usb_get_speed(chip->dev) == USB_SPEED_HIGH &&
-           get_endpoint(alts, 0)->bInterval >= 1 &&
-           get_endpoint(alts, 0)->bInterval <= 4)
-               return get_endpoint(alts, 0)->bInterval - 1;
-       else
-               return 0;
-}
-
-static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
-                                        int iface, int altno);
-static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
-{
-       struct usb_device *dev;
-       struct usb_interface *iface;
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       int i, altno, err, stream;
-       int format = 0, num_channels = 0;
-       struct audioformat *fp = NULL;
-       unsigned char *fmt, *csep;
-       int num, protocol;
-
-       dev = chip->dev;
-
-       /* parse the interface's altsettings */
-       iface = usb_ifnum_to_if(dev, iface_no);
-
-       num = iface->num_altsetting;
-
-       /*
-        * Dallas DS4201 workaround: It presents 5 altsettings, but the last
-        * one misses syncpipe, and does not produce any sound.
-        */
-       if (chip->usb_id == USB_ID(0x04fa, 0x4201))
-               num = 4;
-
-       for (i = 0; i < num; i++) {
-               alts = &iface->altsetting[i];
-               altsd = get_iface_desc(alts);
-               protocol = altsd->bInterfaceProtocol;
-               /* skip invalid one */
-               if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
-                    altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
-                   (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
-                    altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
-                   altsd->bNumEndpoints < 1 ||
-                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
-                       continue;
-               /* must be isochronous */
-               if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
-                   USB_ENDPOINT_XFER_ISOC)
-                       continue;
-               /* check direction */
-               stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
-                       SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-               altno = altsd->bAlternateSetting;
-       
-               /* audiophile usb: skip altsets incompatible with device_setup
-                */
-               if (chip->usb_id == USB_ID(0x0763, 0x2003) && 
-                   audiophile_skip_setting_quirk(chip, iface_no, altno))
-                       continue;
-
-               /* get audio formats */
-               switch (protocol) {
-               case UAC_VERSION_1: {
-                       struct uac_as_header_descriptor_v1 *as =
-                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
-
-                       if (!as) {
-                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
-
-                       if (as->bLength < sizeof(*as)) {
-                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
-
-                       format = le16_to_cpu(as->wFormatTag); /* remember the format value */
-                       break;
-               }
-
-               case UAC_VERSION_2: {
-                       struct uac_as_header_descriptor_v2 *as =
-                               snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
-
-                       if (!as) {
-                               snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
-
-                       if (as->bLength < sizeof(*as)) {
-                               snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
-                                          dev->devnum, iface_no, altno);
-                               continue;
-                       }
-
-                       num_channels = as->bNrChannels;
-                       format = le32_to_cpu(as->bmFormats);
-
-                       break;
-               }
-
-               default:
-                       snd_printk(KERN_ERR "%d:%u:%d : unknown interface protocol %04x\n",
-                                  dev->devnum, iface_no, altno, protocol);
-                       continue;
-               }
-
-               /* get format type */
-               fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
-               if (!fmt) {
-                       snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
-                                  dev->devnum, iface_no, altno);
-                       continue;
-               }
-               if (((protocol == UAC_VERSION_1) && (fmt[0] < 8)) ||
-                   ((protocol == UAC_VERSION_2) && (fmt[0] != 6))) {
-                       snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
-                                  dev->devnum, iface_no, altno);
-                       continue;
-               }
-
-               /*
-                * Blue Microphones workaround: The last altsetting is identical
-                * with the previous one, except for a larger packet size, but
-                * is actually a mislabeled two-channel setting; ignore it.
-                */
-               if (fmt[4] == 1 && fmt[5] == 2 && altno == 2 && num == 3 &&
-                   fp && fp->altsetting == 1 && fp->channels == 1 &&
-                   fp->format == SNDRV_PCM_FORMAT_S16_LE &&
-                   protocol == UAC_VERSION_1 &&
-                   le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
-                                                       fp->maxpacksize * 2)
-                       continue;
-
-               csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
-               /* Creamware Noah has this descriptor after the 2nd endpoint */
-               if (!csep && altsd->bNumEndpoints >= 2)
-                       csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
-               if (!csep || csep[0] < 7 || csep[2] != UAC_EP_GENERAL) {
-                       snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
-                                  " class specific endpoint descriptor\n",
-                                  dev->devnum, iface_no, altno);
-                       csep = NULL;
-               }
-
-               fp = kzalloc(sizeof(*fp), GFP_KERNEL);
-               if (! fp) {
-                       snd_printk(KERN_ERR "cannot malloc\n");
-                       return -ENOMEM;
-               }
-
-               fp->iface = iface_no;
-               fp->altsetting = altno;
-               fp->altset_idx = i;
-               fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
-               fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-               fp->datainterval = parse_datainterval(chip, alts);
-               fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
-               /* num_channels is only set for v2 interfaces */
-               fp->channels = num_channels;
-               if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
-                       fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
-                                       * (fp->maxpacksize & 0x7ff);
-               fp->attributes = csep ? csep[3] : 0;
-
-               /* some quirks for attributes here */
-
-               switch (chip->usb_id) {
-               case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
-                       /* Optoplay sets the sample rate attribute although
-                        * it seems not supporting it in fact.
-                        */
-                       fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
-                       break;
-               case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
-               case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
-                       /* doesn't set the sample rate attribute, but supports it */
-                       fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
-                       break;
-               case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
-               case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
-                                               an older model 77d:223) */
-               /*
-                * plantronics headset and Griffin iMic have set adaptive-in
-                * although it's really not...
-                */
-                       fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
-                       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
-                               fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
-                       else
-                               fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
-                       break;
-               }
-
-               /* ok, let's parse further... */
-               if (parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
-                       kfree(fp->rate_table);
-                       kfree(fp);
-                       continue;
-               }
-
-               snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
-               err = add_audio_endpoint(chip, stream, fp);
-               if (err < 0) {
-                       kfree(fp->rate_table);
-                       kfree(fp);
-                       return err;
-               }
-               /* try to set the interface... */
-               usb_set_interface(chip->dev, iface_no, altno);
-               init_usb_pitch(chip->dev, iface_no, alts, fp);
-               init_usb_sample_rate(chip->dev, iface_no, alts, fp, fp->rate_max);
-       }
-       return 0;
-}
-
-
-/*
- * disconnect streams
- * called from snd_usb_audio_disconnect()
- */
-static void snd_usb_stream_disconnect(struct list_head *head)
-{
-       int idx;
-       struct snd_usb_stream *as;
-       struct snd_usb_substream *subs;
-
-       as = list_entry(head, struct snd_usb_stream, list);
-       for (idx = 0; idx < 2; idx++) {
-               subs = &as->substream[idx];
-               if (!subs->num_formats)
-                       return;
-               release_substream_urbs(subs, 1);
-               subs->interface = -1;
-       }
-}
-
-static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int interface)
-{
-       struct usb_device *dev = chip->dev;
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       struct usb_interface *iface = usb_ifnum_to_if(dev, interface);
-
-       if (!iface) {
-               snd_printk(KERN_ERR "%d:%u:%d : does not exist\n",
-                          dev->devnum, ctrlif, interface);
-               return -EINVAL;
-       }
-
-       if (usb_interface_claimed(iface)) {
-               snd_printdd(KERN_INFO "%d:%d:%d: skipping, already claimed\n",
-                                               dev->devnum, ctrlif, interface);
-               return -EINVAL;
-       }
-
-       alts = &iface->altsetting[0];
-       altsd = get_iface_desc(alts);
-       if ((altsd->bInterfaceClass == USB_CLASS_AUDIO ||
-            altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC) &&
-           altsd->bInterfaceSubClass == USB_SUBCLASS_MIDISTREAMING) {
-               int err = snd_usbmidi_create(chip->card, iface,
-                                            &chip->midi_list, NULL);
-               if (err < 0) {
-                       snd_printk(KERN_ERR "%d:%u:%d: cannot create sequencer device\n",
-                                               dev->devnum, ctrlif, interface);
-                       return -EINVAL;
-               }
-               usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
-
-               return 0;
-       }
-
-       if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
-            altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
-           altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING) {
-               snd_printdd(KERN_ERR "%d:%u:%d: skipping non-supported interface %d\n",
-                                       dev->devnum, ctrlif, interface, altsd->bInterfaceClass);
-               /* skip non-supported classes */
-               return -EINVAL;
-       }
-
-       if (snd_usb_get_speed(dev) == USB_SPEED_LOW) {
-               snd_printk(KERN_ERR "low speed audio streaming not supported\n");
-               return -EINVAL;
-       }
-
-       if (! parse_audio_endpoints(chip, interface)) {
-               usb_set_interface(dev, interface, 0); /* reset the current interface */
-               usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/*
- * parse audio control descriptor and create pcm/midi streams
- */
-static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
-{
-       struct usb_device *dev = chip->dev;
-       struct usb_host_interface *host_iface;
-       struct usb_interface_descriptor *altsd;
-       void *control_header;
-       int i, protocol;
-
-       /* find audiocontrol interface */
-       host_iface = &usb_ifnum_to_if(dev, ctrlif)->altsetting[0];
-       control_header = snd_usb_find_csint_desc(host_iface->extra,
-                                                host_iface->extralen,
-                                                NULL, UAC_HEADER);
-       altsd = get_iface_desc(host_iface);
-       protocol = altsd->bInterfaceProtocol;
-
-       if (!control_header) {
-               snd_printk(KERN_ERR "cannot find UAC_HEADER\n");
-               return -EINVAL;
-       }
-
-       switch (protocol) {
-       case UAC_VERSION_1: {
-               struct uac_ac_header_descriptor_v1 *h1 = control_header;
-
-               if (!h1->bInCollection) {
-                       snd_printk(KERN_INFO "skipping empty audio interface (v1)\n");
-                       return -EINVAL;
-               }
-
-               if (h1->bLength < sizeof(*h1) + h1->bInCollection) {
-                       snd_printk(KERN_ERR "invalid UAC_HEADER (v1)\n");
-                       return -EINVAL;
-               }
-
-               for (i = 0; i < h1->bInCollection; i++)
-                       snd_usb_create_stream(chip, ctrlif, h1->baInterfaceNr[i]);
-
-               break;
-       }
-
-       case UAC_VERSION_2: {
-               struct uac_clock_source_descriptor *cs;
-               struct usb_interface_assoc_descriptor *assoc =
-                       usb_ifnum_to_if(dev, ctrlif)->intf_assoc;
-
-               if (!assoc) {
-                       snd_printk(KERN_ERR "Audio class v2 interfaces need an interface association\n");
-                       return -EINVAL;
-               }
-
-               /* FIXME: for now, we expect there is at least one clock source
-                * descriptor and we always take the first one.
-                * We should properly support devices with multiple clock sources,
-                * clock selectors and sample rate conversion units. */
-
-               cs = snd_usb_find_csint_desc(host_iface->extra, host_iface->extralen,
-                                               NULL, UAC_CLOCK_SOURCE);
-
-               if (!cs) {
-                       snd_printk(KERN_ERR "CLOCK_SOURCE descriptor not found\n");
-                       return -EINVAL;
-               }
-
-               chip->clock_id = cs->bClockID;
-
-               for (i = 0; i < assoc->bInterfaceCount; i++) {
-                       int intf = assoc->bFirstInterface + i;
-
-                       if (intf != ctrlif)
-                               snd_usb_create_stream(chip, ctrlif, intf);
-               }
-
-               break;
-       }
-
-       default:
-               snd_printk(KERN_ERR "unknown protocol version 0x%02x\n", protocol);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
-/*
- * create a stream for an endpoint/altsetting without proper descriptors
- */
-static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
-                                    struct usb_interface *iface,
-                                    const struct snd_usb_audio_quirk *quirk)
-{
-       struct audioformat *fp;
-       struct usb_host_interface *alts;
-       int stream, err;
-       unsigned *rate_table = NULL;
-
-       fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
-       if (! fp) {
-               snd_printk(KERN_ERR "cannot memdup\n");
-               return -ENOMEM;
-       }
-       if (fp->nr_rates > 0) {
-               rate_table = kmalloc(sizeof(int) * fp->nr_rates, GFP_KERNEL);
-               if (!rate_table) {
-                       kfree(fp);
-                       return -ENOMEM;
-               }
-               memcpy(rate_table, fp->rate_table, sizeof(int) * fp->nr_rates);
-               fp->rate_table = rate_table;
-       }
-
-       stream = (fp->endpoint & USB_DIR_IN)
-               ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-       err = add_audio_endpoint(chip, stream, fp);
-       if (err < 0) {
-               kfree(fp);
-               kfree(rate_table);
-               return err;
-       }
-       if (fp->iface != get_iface_desc(&iface->altsetting[0])->bInterfaceNumber ||
-           fp->altset_idx >= iface->num_altsetting) {
-               kfree(fp);
-               kfree(rate_table);
-               return -EINVAL;
-       }
-       alts = &iface->altsetting[fp->altset_idx];
-       fp->datainterval = parse_datainterval(chip, alts);
-       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
-       usb_set_interface(chip->dev, fp->iface, 0);
-       init_usb_pitch(chip->dev, fp->iface, alts, fp);
-       init_usb_sample_rate(chip->dev, fp->iface, alts, fp, fp->rate_max);
-       return 0;
-}
-
-/*
- * create a stream for an interface with proper descriptors
- */
-static int create_standard_audio_quirk(struct snd_usb_audio *chip,
-                                      struct usb_interface *iface,
-                                      const struct snd_usb_audio_quirk *quirk)
-{
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       int err;
-
-       alts = &iface->altsetting[0];
-       altsd = get_iface_desc(alts);
-       err = parse_audio_endpoints(chip, altsd->bInterfaceNumber);
-       if (err < 0) {
-               snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
-                          altsd->bInterfaceNumber, err);
-               return err;
-       }
-       /* reset the current interface */
-       usb_set_interface(chip->dev, altsd->bInterfaceNumber, 0);
-       return 0;
-}
-
-/*
- * Create a stream for an Edirol UA-700/UA-25/UA-4FX interface.  
- * The only way to detect the sample rate is by looking at wMaxPacketSize.
- */
-static int create_uaxx_quirk(struct snd_usb_audio *chip,
-                             struct usb_interface *iface,
-                             const struct snd_usb_audio_quirk *quirk)
-{
-       static const struct audioformat ua_format = {
-               .format = SNDRV_PCM_FORMAT_S24_3LE,
-               .channels = 2,
-               .fmt_type = UAC_FORMAT_TYPE_I,
-               .altsetting = 1,
-               .altset_idx = 1,
-               .rates = SNDRV_PCM_RATE_CONTINUOUS,
-       };
-       struct usb_host_interface *alts;
-       struct usb_interface_descriptor *altsd;
-       struct audioformat *fp;
-       int stream, err;
-
-       /* both PCM and MIDI interfaces have 2 or more altsettings */
-       if (iface->num_altsetting < 2)
-               return -ENXIO;
-       alts = &iface->altsetting[1];
-       altsd = get_iface_desc(alts);
-
-       if (altsd->bNumEndpoints == 2) {
-               static const struct snd_usb_midi_endpoint_info ua700_ep = {
-                       .out_cables = 0x0003,
-                       .in_cables  = 0x0003
-               };
-               static const struct snd_usb_audio_quirk ua700_quirk = {
-                       .type = QUIRK_MIDI_FIXED_ENDPOINT,
-                       .data = &ua700_ep
-               };
-               static const struct snd_usb_midi_endpoint_info uaxx_ep = {
-                       .out_cables = 0x0001,
-                       .in_cables  = 0x0001
-               };
-               static const struct snd_usb_audio_quirk uaxx_quirk = {
-                       .type = QUIRK_MIDI_FIXED_ENDPOINT,
-                       .data = &uaxx_ep
-               };
-               const struct snd_usb_audio_quirk *quirk =
-                       chip->usb_id == USB_ID(0x0582, 0x002b)
-                       ? &ua700_quirk : &uaxx_quirk;
-               return snd_usbmidi_create(chip->card, iface,
-                                         &chip->midi_list, quirk);
-       }
-
-       if (altsd->bNumEndpoints != 1)
-               return -ENXIO;
-
-       fp = kmalloc(sizeof(*fp), GFP_KERNEL);
-       if (!fp)
-               return -ENOMEM;
-       memcpy(fp, &ua_format, sizeof(*fp));
-
-       fp->iface = altsd->bInterfaceNumber;
-       fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
-       fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
-       fp->datainterval = 0;
-       fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
-
-       switch (fp->maxpacksize) {
-       case 0x120:
-               fp->rate_max = fp->rate_min = 44100;
-               break;
-       case 0x138:
-       case 0x140:
-               fp->rate_max = fp->rate_min = 48000;
-               break;
-       case 0x258:
-       case 0x260:
-               fp->rate_max = fp->rate_min = 96000;
-               break;
-       default:
-               snd_printk(KERN_ERR "unknown sample rate\n");
-               kfree(fp);
-               return -ENXIO;
-       }
-
-       stream = (fp->endpoint & USB_DIR_IN)
-               ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-       err = add_audio_endpoint(chip, stream, fp);
-       if (err < 0) {
-               kfree(fp);
-               return err;
-       }
-       usb_set_interface(chip->dev, fp->iface, 0);
-       return 0;
-}
-
-static int snd_usb_create_quirk(struct snd_usb_audio *chip,
-                               struct usb_interface *iface,
-                               const struct snd_usb_audio_quirk *quirk);
-
-/*
- * handle the quirks for the contained interfaces
- */
-static int create_composite_quirk(struct snd_usb_audio *chip,
-                                 struct usb_interface *iface,
-                                 const struct snd_usb_audio_quirk *quirk)
-{
-       int probed_ifnum = get_iface_desc(iface->altsetting)->bInterfaceNumber;
-       int err;
-
-       for (quirk = quirk->data; quirk->ifnum >= 0; ++quirk) {
-               iface = usb_ifnum_to_if(chip->dev, quirk->ifnum);
-               if (!iface)
-                       continue;
-               if (quirk->ifnum != probed_ifnum &&
-                   usb_interface_claimed(iface))
-                       continue;
-               err = snd_usb_create_quirk(chip, iface, quirk);
-               if (err < 0)
-                       return err;
-               if (quirk->ifnum != probed_ifnum)
-                       usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
-       }
-       return 0;
-}
-
-static int ignore_interface_quirk(struct snd_usb_audio *chip,
-                                 struct usb_interface *iface,
-                                 const struct snd_usb_audio_quirk *quirk)
-{
-       return 0;
-}
-
-/*
- * Allow alignment on audio sub-slot (channel samples) rather than
- * on audio slots (audio frames)
- */
-static int create_align_transfer_quirk(struct snd_usb_audio *chip,
-                                 struct usb_interface *iface,
-                                 const struct snd_usb_audio_quirk *quirk)
-{
-       chip->txfr_quirk = 1;
-       return 1;       /* Continue with creating streams and mixer */
-}
-
-
-/*
- * boot quirks
- */
-
-#define EXTIGY_FIRMWARE_SIZE_OLD 794
-#define EXTIGY_FIRMWARE_SIZE_NEW 483
-
-static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interface *intf)
-{
-       struct usb_host_config *config = dev->actconfig;
-       int err;
-
-       if (le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_OLD ||
-           le16_to_cpu(get_cfg_desc(config)->wTotalLength) == EXTIGY_FIRMWARE_SIZE_NEW) {
-               snd_printdd("sending Extigy boot sequence...\n");
-               /* Send message to force it to reconnect with full interface. */
-               err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
-                                     0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000);
-               if (err < 0) snd_printdd("error sending boot message: %d\n", err);
-               err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
-                               &dev->descriptor, sizeof(dev->descriptor));
-               config = dev->actconfig;
-               if (err < 0) snd_printdd("error usb_get_descriptor: %d\n", err);
-               err = usb_reset_configuration(dev);
-               if (err < 0) snd_printdd("error usb_reset_configuration: %d\n", err);
-               snd_printdd("extigy_boot: new boot length = %d\n",
-                           le16_to_cpu(get_cfg_desc(config)->wTotalLength));
-               return -ENODEV; /* quit this anyway */
-       }
-       return 0;
-}
-
-static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
-{
-       u8 buf = 1;
-
-       snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
-                       USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                       0, 0, &buf, 1, 1000);
-       if (buf == 0) {
-               snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
-                               USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
-                               1, 2000, NULL, 0, 1000);
-               return -ENODEV;
-       }
-       return 0;
-}
-
-/*
- * C-Media CM106/CM106+ have four 16-bit internal registers that are nicely
- * documented in the device's data sheet.
- */
-static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 value)
-{
-       u8 buf[4];
-       buf[0] = 0x20;
-       buf[1] = value & 0xff;
-       buf[2] = (value >> 8) & 0xff;
-       buf[3] = reg;
-       return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
-                              USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
-                              0, 0, &buf, 4, 1000);
-}
-
-static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
-{
-       /*
-        * Enable line-out driver mode, set headphone source to front
-        * channels, enable stereo mic.
-        */
-       return snd_usb_cm106_write_int_reg(dev, 2, 0x8004);
-}
-
-/*
- * C-Media CM6206 is based on CM106 with two additional
- * registers that are not documented in the data sheet.
- * Values here are chosen based on sniffing USB traffic
- * under Windows.
- */
-static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
-{
-       int err, reg;
-       int val[] = {0x200c, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
-
-       for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
-               err = snd_usb_cm106_write_int_reg(dev, reg, val[reg]);
-               if (err < 0)
-                       return err;
-       }
-
-       return err;
-}
-
-/*
- * This call will put the synth in "USB send" mode, i.e it will send MIDI
- * messages through USB (this is disabled at startup). The synth will
- * acknowledge by sending a sysex on endpoint 0x85 and by displaying a USB
- * sign on its LCD. Values here are chosen based on sniffing USB traffic
- * under Windows.
- */
-static int snd_usb_accessmusic_boot_quirk(struct usb_device *dev)
-{
-       int err, actual_length;
-
-       /* "midi send" enable */
-       static const u8 seq[] = { 0x4e, 0x73, 0x52, 0x01 };
-
-       void *buf = kmemdup(seq, ARRAY_SIZE(seq), GFP_KERNEL);
-       if (!buf)
-               return -ENOMEM;
-       err = usb_interrupt_msg(dev, usb_sndintpipe(dev, 0x05), buf,
-                       ARRAY_SIZE(seq), &actual_length, 1000);
-       kfree(buf);
-       if (err < 0)
-               return err;
-
-       return 0;
-}
-
-/*
- * Setup quirks
- */
-#define AUDIOPHILE_SET                 0x01 /* if set, parse device_setup */
-#define AUDIOPHILE_SET_DTS              0x02 /* if set, enable DTS Digital Output */
-#define AUDIOPHILE_SET_96K              0x04 /* 48-96KHz rate if set, 8-48KHz otherwise */
-#define AUDIOPHILE_SET_24B             0x08 /* 24bits sample if set, 16bits otherwise */
-#define AUDIOPHILE_SET_DI              0x10 /* if set, enable Digital Input */
-#define AUDIOPHILE_SET_MASK            0x1F /* bit mask for setup value */
-#define AUDIOPHILE_SET_24B_48K_DI      0x19 /* value for 24bits+48KHz+Digital Input */
-#define AUDIOPHILE_SET_24B_48K_NOTDI   0x09 /* value for 24bits+48KHz+No Digital Input */
-#define AUDIOPHILE_SET_16B_48K_DI      0x11 /* value for 16bits+48KHz+Digital Input */
-#define AUDIOPHILE_SET_16B_48K_NOTDI   0x01 /* value for 16bits+48KHz+No Digital Input */
-
-static int audiophile_skip_setting_quirk(struct snd_usb_audio *chip,
-                                        int iface, int altno)
-{
-       /* Reset ALL ifaces to 0 altsetting.
-        * Call it for every possible altsetting of every interface.
-        */
-       usb_set_interface(chip->dev, iface, 0);
-
-       if (device_setup[chip->index] & AUDIOPHILE_SET) {
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_DTS)
-                   && altno != 6)
-                       return 1; /* skip this altsetting */
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_96K)
-                   && altno != 1)
-                       return 1; /* skip this altsetting */
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
-                   AUDIOPHILE_SET_24B_48K_DI && altno != 2)
-                       return 1; /* skip this altsetting */
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
-                   AUDIOPHILE_SET_24B_48K_NOTDI && altno != 3)
-                       return 1; /* skip this altsetting */
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
-                   AUDIOPHILE_SET_16B_48K_DI && altno != 4)
-                       return 1; /* skip this altsetting */
-               if ((device_setup[chip->index] & AUDIOPHILE_SET_MASK) ==
-                   AUDIOPHILE_SET_16B_48K_NOTDI && altno != 5)
-                       return 1; /* skip this altsetting */
-       }       
-       return 0; /* keep this altsetting */
-}
-
-static int create_any_midi_quirk(struct snd_usb_audio *chip,
-                                struct usb_interface *intf,
-                                const struct snd_usb_audio_quirk *quirk)
-{
-       return snd_usbmidi_create(chip->card, intf, &chip->midi_list, quirk);
-}
-
-/*
- * audio-interface quirks
- *
- * returns zero if no standard audio/MIDI parsing is needed.
- * returns a postive value if standard audio/midi interfaces are parsed
- * after this.
- * returns a negative value at error.
- */
-static int snd_usb_create_quirk(struct snd_usb_audio *chip,
-                               struct usb_interface *iface,
-                               const struct snd_usb_audio_quirk *quirk)
-{
-       typedef int (*quirk_func_t)(struct snd_usb_audio *, struct usb_interface *,
-                                   const struct snd_usb_audio_quirk *);
-       static const quirk_func_t quirk_funcs[] = {
-               [QUIRK_IGNORE_INTERFACE] = ignore_interface_quirk,
-               [QUIRK_COMPOSITE] = create_composite_quirk,
-               [QUIRK_MIDI_STANDARD_INTERFACE] = create_any_midi_quirk,
-               [QUIRK_MIDI_FIXED_ENDPOINT] = create_any_midi_quirk,
-               [QUIRK_MIDI_YAMAHA] = create_any_midi_quirk,
-               [QUIRK_MIDI_MIDIMAN] = create_any_midi_quirk,
-               [QUIRK_MIDI_NOVATION] = create_any_midi_quirk,
-               [QUIRK_MIDI_FASTLANE] = create_any_midi_quirk,
-               [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
-               [QUIRK_MIDI_CME] = create_any_midi_quirk,
-               [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
-               [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
-               [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
-               [QUIRK_AUDIO_ALIGN_TRANSFER] = create_align_transfer_quirk
-       };
-
-       if (quirk->type < QUIRK_TYPE_COUNT) {
-               return quirk_funcs[quirk->type](chip, iface, quirk);
-       } else {
-               snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
-               return -ENXIO;
-       }
-}
-
-
-/*
- * common proc files to show the usb device info
- */
-static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
-{
-       struct snd_usb_audio *chip = entry->private_data;
-       if (!chip->shutdown)
-               snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
-}
-
-static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
-{
-       struct snd_usb_audio *chip = entry->private_data;
-       if (!chip->shutdown)
-               snd_iprintf(buffer, "%04x:%04x\n", 
-                           USB_ID_VENDOR(chip->usb_id),
-                           USB_ID_PRODUCT(chip->usb_id));
-}
-
-static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
-{
-       struct snd_info_entry *entry;
-       if (!snd_card_proc_new(chip->card, "usbbus", &entry))
-               snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
-       if (!snd_card_proc_new(chip->card, "usbid", &entry))
-               snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
-}
-
-/*
- * free the chip instance
- *
- * here we have to do not much, since pcm and controls are already freed
- *
- */
-
-static int snd_usb_audio_free(struct snd_usb_audio *chip)
-{
-       kfree(chip);
-       return 0;
-}
-
-static int snd_usb_audio_dev_free(struct snd_device *device)
-{
-       struct snd_usb_audio *chip = device->device_data;
-       return snd_usb_audio_free(chip);
-}
-
-
-/*
- * create a chip instance and set its names.
- */
-static int snd_usb_audio_create(struct usb_device *dev, int idx,
-                               const struct snd_usb_audio_quirk *quirk,
-                               struct snd_usb_audio **rchip)
-{
-       struct snd_card *card;
-       struct snd_usb_audio *chip;
-       int err, len;
-       char component[14];
-       static struct snd_device_ops ops = {
-               .dev_free =     snd_usb_audio_dev_free,
-       };
-
-       *rchip = NULL;
-
-       if (snd_usb_get_speed(dev) != USB_SPEED_LOW &&
-           snd_usb_get_speed(dev) != USB_SPEED_FULL &&
-           snd_usb_get_speed(dev) != USB_SPEED_HIGH) {
-               snd_printk(KERN_ERR "unknown device speed %d\n", snd_usb_get_speed(dev));
-               return -ENXIO;
-       }
-
-       err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
-       if (err < 0) {
-               snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
-               return err;
-       }
-
-       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
-       if (! chip) {
-               snd_card_free(card);
-               return -ENOMEM;
-       }
-
-       chip->index = idx;
-       chip->dev = dev;
-       chip->card = card;
-       chip->usb_id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
-                             le16_to_cpu(dev->descriptor.idProduct));
-       INIT_LIST_HEAD(&chip->pcm_list);
-       INIT_LIST_HEAD(&chip->midi_list);
-       INIT_LIST_HEAD(&chip->mixer_list);
-
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
-               snd_usb_audio_free(chip);
-               snd_card_free(card);
-               return err;
-       }
-
-       strcpy(card->driver, "USB-Audio");
-       sprintf(component, "USB%04x:%04x",
-               USB_ID_VENDOR(chip->usb_id), USB_ID_PRODUCT(chip->usb_id));
-       snd_component_add(card, component);
-
-       /* retrieve the device string as shortname */
-       if (quirk && quirk->product_name) {
-               strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
-       } else {
-               if (!dev->descriptor.iProduct ||
-                   usb_string(dev, dev->descriptor.iProduct,
-                              card->shortname, sizeof(card->shortname)) <= 0) {
-                       /* no name available from anywhere, so use ID */
-                       sprintf(card->shortname, "USB Device %#04x:%#04x",
-                               USB_ID_VENDOR(chip->usb_id),
-                               USB_ID_PRODUCT(chip->usb_id));
-               }
-       }
-
-       /* retrieve the vendor and device strings as longname */
-       if (quirk && quirk->vendor_name) {
-               len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
-       } else {
-               if (dev->descriptor.iManufacturer)
-                       len = usb_string(dev, dev->descriptor.iManufacturer,
-                                        card->longname, sizeof(card->longname));
-               else
-                       len = 0;
-               /* we don't really care if there isn't any vendor string */
-       }
-       if (len > 0)
-               strlcat(card->longname, " ", sizeof(card->longname));
-
-       strlcat(card->longname, card->shortname, sizeof(card->longname));
-
-       len = strlcat(card->longname, " at ", sizeof(card->longname));
-
-       if (len < sizeof(card->longname))
-               usb_make_path(dev, card->longname + len, sizeof(card->longname) - len);
-
-       strlcat(card->longname,
-               snd_usb_get_speed(dev) == USB_SPEED_LOW ? ", low speed" :
-               snd_usb_get_speed(dev) == USB_SPEED_FULL ? ", full speed" :
-               ", high speed",
-               sizeof(card->longname));
-
-       snd_usb_audio_create_proc(chip);
-
-       *rchip = chip;
-       return 0;
-}
-
-
-/*
- * probe the active usb device
- *
- * note that this can be called multiple times per a device, when it
- * includes multiple audio control interfaces.
- *
- * thus we check the usb device pointer and creates the card instance
- * only at the first time.  the successive calls of this function will
- * append the pcm interface to the corresponding card.
- */
-static void *snd_usb_audio_probe(struct usb_device *dev,
-                                struct usb_interface *intf,
-                                const struct usb_device_id *usb_id)
-{
-       const struct snd_usb_audio_quirk *quirk = (const struct snd_usb_audio_quirk *)usb_id->driver_info;
-       int i, err;
-       struct snd_usb_audio *chip;
-       struct usb_host_interface *alts;
-       int ifnum;
-       u32 id;
-
-       alts = &intf->altsetting[0];
-       ifnum = get_iface_desc(alts)->bInterfaceNumber;
-       id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
-                   le16_to_cpu(dev->descriptor.idProduct));
-       if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
-               goto __err_val;
-
-       /* SB Extigy needs special boot-up sequence */
-       /* if more models come, this will go to the quirk list. */
-       if (id == USB_ID(0x041e, 0x3000)) {
-               if (snd_usb_extigy_boot_quirk(dev, intf) < 0)
-                       goto __err_val;
-       }
-       /* SB Audigy 2 NX needs its own boot-up magic, too */
-       if (id == USB_ID(0x041e, 0x3020)) {
-               if (snd_usb_audigy2nx_boot_quirk(dev) < 0)
-                       goto __err_val;
-       }
-
-       /* C-Media CM106 / Turtle Beach Audio Advantage Roadie */
-       if (id == USB_ID(0x10f5, 0x0200)) {
-               if (snd_usb_cm106_boot_quirk(dev) < 0)
-                       goto __err_val;
-       }
-
-       /* C-Media CM6206 / CM106-Like Sound Device */
-       if (id == USB_ID(0x0d8c, 0x0102)) {
-               if (snd_usb_cm6206_boot_quirk(dev) < 0)
-                       goto __err_val;
-       }
-
-       /* Access Music VirusTI Desktop */
-       if (id == USB_ID(0x133e, 0x0815)) {
-               if (snd_usb_accessmusic_boot_quirk(dev) < 0)
-                       goto __err_val;
-       }
-
-       /*
-        * found a config.  now register to ALSA
-        */
-
-       /* check whether it's already registered */
-       chip = NULL;
-       mutex_lock(&register_mutex);
-       for (i = 0; i < SNDRV_CARDS; i++) {
-               if (usb_chip[i] && usb_chip[i]->dev == dev) {
-                       if (usb_chip[i]->shutdown) {
-                               snd_printk(KERN_ERR "USB device is in the shutdown state, cannot create a card instance\n");
-                               goto __error;
-                       }
-                       chip = usb_chip[i];
-                       break;
-               }
-       }
-       if (! chip) {
-               /* it's a fresh one.
-                * now look for an empty slot and create a new card instance
-                */
-               for (i = 0; i < SNDRV_CARDS; i++)
-                       if (enable[i] && ! usb_chip[i] &&
-                           (vid[i] == -1 || vid[i] == USB_ID_VENDOR(id)) &&
-                           (pid[i] == -1 || pid[i] == USB_ID_PRODUCT(id))) {
-                               if (snd_usb_audio_create(dev, i, quirk, &chip) < 0) {
-                                       goto __error;
-                               }
-                               snd_card_set_dev(chip->card, &intf->dev);
-                               break;
-                       }
-               if (!chip) {
-                       printk(KERN_ERR "no available usb audio device\n");
-                       goto __error;
-               }
-       }
-
-       chip->txfr_quirk = 0;
-       err = 1; /* continue */
-       if (quirk && quirk->ifnum != QUIRK_NO_INTERFACE) {
-               /* need some special handlings */
-               if ((err = snd_usb_create_quirk(chip, intf, quirk)) < 0)
-                       goto __error;
-       }
-
-       if (err > 0) {
-               /* create normal USB audio interfaces */
-               if (snd_usb_create_streams(chip, ifnum) < 0 ||
-                   snd_usb_create_mixer(chip, ifnum, ignore_ctl_error) < 0) {
-                       goto __error;
-               }
-       }
-
-       /* we are allowed to call snd_card_register() many times */
-       if (snd_card_register(chip->card) < 0) {
-               goto __error;
-       }
-
-       usb_chip[chip->index] = chip;
-       chip->num_interfaces++;
-       mutex_unlock(&register_mutex);
-       return chip;
-
- __error:
-       if (chip && !chip->num_interfaces)
-               snd_card_free(chip->card);
-       mutex_unlock(&register_mutex);
- __err_val:
-       return NULL;
-}
-
-/*
- * we need to take care of counter, since disconnection can be called also
- * many times as well as usb_audio_probe().
- */
-static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
-{
-       struct snd_usb_audio *chip;
-       struct snd_card *card;
-       struct list_head *p;
-
-       if (ptr == (void *)-1L)
-               return;
-
-       chip = ptr;
-       card = chip->card;
-       mutex_lock(&register_mutex);
-       chip->shutdown = 1;
-       chip->num_interfaces--;
-       if (chip->num_interfaces <= 0) {
-               snd_card_disconnect(card);
-               /* release the pcm resources */
-               list_for_each(p, &chip->pcm_list) {
-                       snd_usb_stream_disconnect(p);
-               }
-               /* release the midi resources */
-               list_for_each(p, &chip->midi_list) {
-                       snd_usbmidi_disconnect(p);
-               }
-               /* release mixer resources */
-               list_for_each(p, &chip->mixer_list) {
-                       snd_usb_mixer_disconnect(p);
-               }
-               usb_chip[chip->index] = NULL;
-               mutex_unlock(&register_mutex);
-               snd_card_free_when_closed(card);
-       } else {
-               mutex_unlock(&register_mutex);
-       }
-}
-
-/*
- * new 2.5 USB kernel API
- */
-static int usb_audio_probe(struct usb_interface *intf,
-                          const struct usb_device_id *id)
-{
-       void *chip;
-       chip = snd_usb_audio_probe(interface_to_usbdev(intf), intf, id);
-       if (chip) {
-               usb_set_intfdata(intf, chip);
-               return 0;
-       } else
-               return -EIO;
-}
-
-static void usb_audio_disconnect(struct usb_interface *intf)
-{
-       snd_usb_audio_disconnect(interface_to_usbdev(intf),
-                                usb_get_intfdata(intf));
-}
-
-#ifdef CONFIG_PM
-static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
-{
-       struct snd_usb_audio *chip = usb_get_intfdata(intf);
-       struct list_head *p;
-       struct snd_usb_stream *as;
-
-       if (chip == (void *)-1L)
-               return 0;
-
-       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
-       if (!chip->num_suspended_intf++) {
-               list_for_each(p, &chip->pcm_list) {
-                       as = list_entry(p, struct snd_usb_stream, list);
-                       snd_pcm_suspend_all(as->pcm);
-               }
-       }
-
-       return 0;
-}
-
-static int usb_audio_resume(struct usb_interface *intf)
-{
-       struct snd_usb_audio *chip = usb_get_intfdata(intf);
-
-       if (chip == (void *)-1L)
-               return 0;
-       if (--chip->num_suspended_intf)
-               return 0;
-       /*
-        * ALSA leaves material resumption to user space
-        * we just notify
-        */
-
-       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
-
-       return 0;
-}
-#endif         /* CONFIG_PM */
-
-static int __init snd_usb_audio_init(void)
-{
-       if (nrpacks < 1 || nrpacks > MAX_PACKS) {
-               printk(KERN_WARNING "invalid nrpacks value.\n");
-               return -EINVAL;
-       }
-       return usb_register(&usb_audio_driver);
-}
-
-
-static void __exit snd_usb_audio_cleanup(void)
-{
-       usb_deregister(&usb_audio_driver);
-}
-
-module_init(snd_usb_audio_init);
-module_exit(snd_usb_audio_cleanup);
index 42c299c..d679e72 100644 (file)
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  */
 
-/* maximum number of endpoints per interface */
-#define MIDI_MAX_ENDPOINTS 2
-
 /* handling of USB vendor/product ID pairs as 32-bit numbers */
 #define USB_ID(vendor, product) (((vendor) << 16) | (product))
 #define USB_ID_VENDOR(id) ((id) >> 16)
 #define USB_ID_PRODUCT(id) ((u16)(id))
 
 /*
+ *
  */
 
 struct snd_usb_audio {
@@ -51,6 +49,10 @@ struct snd_usb_audio {
        struct list_head midi_list;     /* list of midi interfaces */
 
        struct list_head mixer_list;    /* list of mixer interfaces */
+
+       int setup;                      /* from the 'device_setup' module param */
+       int nrpacks;                    /* from the 'nrpacks' module param */
+       int async_unlink;               /* from the 'async_unlink' module param */
 };
 
 /*
@@ -89,93 +91,8 @@ struct snd_usb_audio_quirk {
        const void *data;
 };
 
-/* data for QUIRK_MIDI_FIXED_ENDPOINT */
-struct snd_usb_midi_endpoint_info {
-       int8_t   out_ep;        /* ep number, 0 autodetect */
-       uint8_t  out_interval;  /* interval for interrupt endpoints */
-       int8_t   in_ep; 
-       uint8_t  in_interval;
-       uint16_t out_cables;    /* bitmask */
-       uint16_t in_cables;     /* bitmask */
-};
-
-/* for QUIRK_MIDI_YAMAHA, data is NULL */
-
-/* for QUIRK_MIDI_MIDIMAN, data points to a snd_usb_midi_endpoint_info
- * structure (out_cables and in_cables only) */
-
-/* for QUIRK_COMPOSITE, data points to an array of snd_usb_audio_quirk
- * structures, terminated with .ifnum = -1 */
-
-/* for QUIRK_AUDIO_FIXED_ENDPOINT, data points to an audioformat structure */
-
-/* for QUIRK_AUDIO/MIDI_STANDARD_INTERFACE, data is NULL */
-
-/* for QUIRK_AUDIO_EDIROL_UAXX, data is NULL */
-
-/* for QUIRK_IGNORE_INTERFACE, data is NULL */
-
-/* for QUIRK_MIDI_NOVATION and _RAW, data is NULL */
-
-/* for QUIRK_MIDI_EMAGIC, data points to a snd_usb_midi_endpoint_info
- * structure (out_cables and in_cables only) */
-
-/* for QUIRK_MIDI_CME, data is NULL */
-
-/*
- */
-
-/*E-mu USB samplerate control quirk*/
-enum {
-       EMU_QUIRK_SR_44100HZ = 0,
-       EMU_QUIRK_SR_48000HZ,
-       EMU_QUIRK_SR_88200HZ,
-       EMU_QUIRK_SR_96000HZ,
-       EMU_QUIRK_SR_176400HZ,
-       EMU_QUIRK_SR_192000HZ
-};
-
 #define combine_word(s)    ((*(s)) | ((unsigned int)(s)[1] << 8))
 #define combine_triple(s)  (combine_word(s) | ((unsigned int)(s)[2] << 16))
 #define combine_quad(s)    (combine_triple(s) | ((unsigned int)(s)[3] << 24))
 
-unsigned int snd_usb_combine_bytes(unsigned char *bytes, int size);
-
-void *snd_usb_find_desc(void *descstart, int desclen, void *after, u8 dtype);
-void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsubtype);
-
-int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
-                   __u8 request, __u8 requesttype, __u16 value, __u16 index,
-                   void *data, __u16 size, int timeout);
-
-int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
-                        int ignore_error);
-void snd_usb_mixer_disconnect(struct list_head *p);
-
-int snd_usbmidi_create(struct snd_card *card,
-                      struct usb_interface *iface,
-                      struct list_head *midi_list,
-                      const struct snd_usb_audio_quirk *quirk);
-void snd_usbmidi_input_stop(struct list_head* p);
-void snd_usbmidi_input_start(struct list_head* p);
-void snd_usbmidi_disconnect(struct list_head *p);
-
-void snd_emuusb_set_samplerate(struct snd_usb_audio *chip,
-                       unsigned char samplerate_id);
-
-/*
- * retrieve usb_interface descriptor from the host interface
- * (conditional for compatibility with the older API)
- */
-#ifndef get_iface_desc
-#define get_iface_desc(iface)  (&(iface)->desc)
-#define get_endpoint(alt,ep)   (&(alt)->endpoint[ep].desc)
-#define get_ep_desc(ep)                (&(ep)->desc)
-#define get_cfg_desc(cfg)      (&(cfg)->desc)
-#endif
-
-#ifndef snd_usb_get_speed
-#define snd_usb_get_speed(dev) ((dev)->speed)
-#endif
-
 #endif /* __USBAUDIO_H */
index 9ca9a13..6ef68e4 100644 (file)
@@ -26,6 +26,7 @@
 #define MODNAME "US122L"
 #include "usb_stream.c"
 #include "../usbaudio.h"
+#include "../midi.h"
 #include "us122l.h"
 
 MODULE_AUTHOR("Karsten Wiese <fzu@wemgehoertderstaat.de>");
index 1d174ce..e43c0a8 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef USBUSX2Y_H
 #define USBUSX2Y_H
 #include "../usbaudio.h"
+#include "../midi.h"
 #include "usbus428ctldefs.h" 
 
 #define NRURBS         2       
index ae525ac..a3dbadb 100644 (file)
@@ -1,5 +1,5 @@
 perf-bench(1)
-============
+=============
 
 NAME
 ----
@@ -19,12 +19,12 @@ COMMON OPTIONS
 -f::
 --format=::
 Specify format style.
-Current available format styles are,
+Current available format styles are:
 
 'default'::
 Default style. This is mainly for human reading.
 ---------------------
-% perf bench sched pipe                      # with no style specify
+% perf bench sched pipe                      # with no style specified
 (executing 1000000 pipe operations between two tasks)
         Total time:5.855 sec
                 5.855061 usecs/op
@@ -79,7 +79,7 @@ options (20 sender and receiver processes per group)
 
       Total time:0.308 sec
 
-% perf bench sched messaging -t -g 20        # be multi-thread,with 20 groups
+% perf bench sched messaging -t -g 20        # be multi-thread, with 20 groups
 (20 sender and receiver threads per group)
 (20 groups == 800 threads run)
 
index 88bc3b5..5d1a950 100644 (file)
@@ -8,7 +8,7 @@ perf-buildid-cache - Manage build-id cache.
 SYNOPSIS
 --------
 [verse]
-'perf buildid-list <options>'
+'perf buildid-cache <options>'
 
 DESCRIPTION
 -----------
@@ -30,4 +30,4 @@ OPTIONS
 
 SEE ALSO
 --------
-linkperf:perf-record[1], linkperf:perf-report[1]
+linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-buildid-list[1]
index 8974e20..20d97d8 100644 (file)
@@ -1,5 +1,5 @@
 perf-diff(1)
-==============
+============
 
 NAME
 ----
diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt
new file mode 100644 (file)
index 0000000..025630d
--- /dev/null
@@ -0,0 +1,35 @@
+perf-inject(1)
+==============
+
+NAME
+----
+perf-inject - Filter to augment the events stream with additional information
+
+SYNOPSIS
+--------
+[verse]
+'perf inject <options>'
+
+DESCRIPTION
+-----------
+perf-inject reads a perf-record event stream and repipes it to stdout.  At any
+point the processing code can inject other events into the event stream - in
+this case build-ids (-b option) are read and injected as needed into the event
+stream.
+
+Build-ids are just the first user of perf-inject - potentially anything that
+needs userspace processing to augment the events stream with additional
+information could make use of this facility.
+
+OPTIONS
+-------
+-b::
+--build-ids=::
+        Inject build-ids into the output stream
+-v::
+--verbose::
+       Be more verbose.
+
+SEE ALSO
+--------
+linkperf:perf-record[1], linkperf:perf-report[1], linkperf:perf-archive[1]
index eac4d85..a52fcde 100644 (file)
@@ -1,5 +1,5 @@
 perf-kmem(1)
-==============
+============
 
 NAME
 ----
diff --git a/tools/perf/Documentation/perf-kvm.txt b/tools/perf/Documentation/perf-kvm.txt
new file mode 100644 (file)
index 0000000..d004e19
--- /dev/null
@@ -0,0 +1,68 @@
+perf-kvm(1)
+===========
+
+NAME
+----
+perf-kvm - Tool to trace/measure kvm guest os
+
+SYNOPSIS
+--------
+[verse]
+'perf kvm' [--host] [--guest] [--guestmount=<path>
+       [--guestkallsyms=<path> --guestmodules=<path> | --guestvmlinux=<path>]]
+       {top|record|report|diff|buildid-list}
+'perf kvm' [--host] [--guest] [--guestkallsyms=<path> --guestmodules=<path>
+       | --guestvmlinux=<path>] {top|record|report|diff|buildid-list}
+
+DESCRIPTION
+-----------
+There are a couple of variants of perf kvm:
+
+  'perf kvm [options] top <command>' to generates and displays
+  a performance counter profile of guest os in realtime
+  of an arbitrary workload.
+
+  'perf kvm record <command>' to record the performance couinter profile
+  of an arbitrary workload and save it into a perf data file. If both
+  --host and --guest are input, the perf data file name is perf.data.kvm.
+  If there is  no --host but --guest, the file name is perf.data.guest.
+  If there is no --guest but --host, the file name is perf.data.host.
+
+  'perf kvm report' to display the performance counter profile information
+  recorded via perf kvm record.
+
+  'perf kvm diff' to displays the performance difference amongst two perf.data
+  files captured via perf record.
+
+  'perf kvm buildid-list' to  display the buildids found in a perf data file,
+  so that other tools can be used to fetch packages with matching symbol tables
+  for use by perf report.
+
+OPTIONS
+-------
+--host=::
+        Collect host side performance profile.
+--guest=::
+        Collect guest side performance profile.
+--guestmount=<path>::
+       Guest os root file system mount directory. Users mounts guest os
+        root directories under <path> by a specific filesystem access method,
+       typically, sshfs. For example, start 2 guest os. The one's pid is 8888
+       and the other's is 9999.
+        #mkdir ~/guestmount; cd ~/guestmount
+        #sshfs -o allow_other,direct_io -p 5551 localhost:/ 8888/
+        #sshfs -o allow_other,direct_io -p 5552 localhost:/ 9999/
+        #perf kvm --host --guest --guestmount=~/guestmount top
+--guestkallsyms=<path>::
+        Guest os /proc/kallsyms file copy. 'perf' kvm' reads it to get guest
+       kernel symbols. Users copy it out from guest os.
+--guestmodules=<path>::
+       Guest os /proc/modules file copy. 'perf' kvm' reads it to get guest
+       kernel module information. Users copy it out from guest os.
+--guestvmlinux=<path>::
+       Guest os kernel vmlinux.
+
+SEE ALSO
+--------
+linkperf:perf-top[1], linkperf:perf-record[1], linkperf:perf-report[1],
+linkperf:perf-diff[1], linkperf:perf-buildid-list[1]
index 8290b94..43e3dd2 100644 (file)
@@ -15,6 +15,35 @@ DESCRIPTION
 This command displays the symbolic event types which can be selected in the
 various perf commands with the -e option.
 
+RAW HARDWARE EVENT DESCRIPTOR
+-----------------------------
+Even when an event is not available in a symbolic form within perf right now,
+it can be encoded in a per processor specific way.
+
+For instance For x86 CPUs NNN represents the raw register encoding with the
+layout of IA32_PERFEVTSELx MSRs (see [Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide] Figure 30-1 Layout
+of IA32_PERFEVTSELx MSRs) or AMD's PerfEvtSeln (see [AMD64 Architecture Programmer’s Manual Volume 2: System Programming], Page 344,
+Figure 13-7 Performance Event-Select Register (PerfEvtSeln)).
+
+Example:
+
+If the Intel docs for a QM720 Core i7 describe an event as:
+
+  Event  Umask  Event Mask
+  Num.   Value  Mnemonic    Description                        Comment
+
+  A8H      01H  LSD.UOPS    Counts the number of micro-ops     Use cmask=1 and
+                            delivered by loop stream detector  invert to count
+                                                               cycles
+
+raw encoding of 0x1A8 can be used:
+
+ perf stat -e r1a8 -a sleep 1
+ perf record -e r1a8 ...
+
+You should refer to the processor specific documentation for getting these
+details. Some of them are referenced in the SEE ALSO section below.
+
 OPTIONS
 -------
 None
@@ -22,4 +51,6 @@ None
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-top[1],
-linkperf:perf-record[1]
+linkperf:perf-record[1],
+http://www.intel.com/Assets/PDF/manual/253669.pdf[Intel® 64 and IA-32 Architectures Software Developer's Manual Volume 3B: System Programming Guide],
+http://support.amd.com/us/Processor_TechDocs/24593.pdf[AMD64 Architecture Programmer’s Manual Volume 2: System Programming]
index 34202b1..94a258c 100644 (file)
@@ -57,6 +57,14 @@ OPTIONS
 --force::
        Forcibly add events with existing name.
 
+-n::
+--dry-run::
+       Dry run. With this option, --add and --del doesn't execute actual
+       adding and removal operations.
+
+--max-probes::
+       Set the maximum number of probe points for an event. Default is 128.
+
 PROBE SYNTAX
 ------------
 Probe points are defined by following syntax.
@@ -74,13 +82,22 @@ Probe points are defined by following syntax.
 'EVENT' specifies the name of new event, if omitted, it will be set the name of the probed function. Currently, event group name is set as 'probe'.
 'FUNC' specifies a probed function name, and it may have one of the following options; '+OFFS' is the offset from function entry address in bytes, ':RLN' is the relative-line number from function entry line, and '%return' means that it probes function return. And ';PTN' means lazy matching pattern (see LAZY MATCHING). Note that ';PTN' must be the end of the probe point definition.  In addition, '@SRC' specifies a source file which has that function.
 It is also possible to specify a probe point by the source line number or lazy matching by using 'SRC:ALN' or 'SRC;PTN' syntax, where 'SRC' is the source file path, ':ALN' is the line number and ';PTN' is the lazy matching pattern.
-'ARG' specifies the arguments of this probe point. You can use the name of local variable, or kprobe-tracer argument format (e.g. $retval, %ax, etc).
+'ARG' specifies the arguments of this probe point, (see PROBE ARGUMENT).
+
+PROBE ARGUMENT
+--------------
+Each probe argument follows below syntax.
+
+ [NAME=]LOCALVAR|$retval|%REG|@SYMBOL[:TYPE]
+
+'NAME' specifies the name of this argument (optional). You can use the name of local variable, local data structure member (e.g. var->field, var.field2), or kprobe-tracer argument format (e.g. $retval, %ax, etc). Note that the name of this argument will be set as the last member name if you specify a local data structure member (e.g. field2 for 'var->field1.field2'.)
+'TYPE' casts the type of this argument (optional). If omitted, perf probe automatically set the type based on debuginfo.
 
 LINE SYNTAX
 -----------
 Line range is descripted by following syntax.
 
- "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]"
+ "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]"
 
 FUNC specifies the function name of showing lines. 'RLN' is the start line
 number from function entry line, and 'RLN2' is the end line number. As same as
index fc46c0b..34e255f 100644 (file)
@@ -58,7 +58,7 @@ OPTIONS
 
 -f::
 --force::
-       Overwrite existing data file.
+       Overwrite existing data file. (deprecated)
 
 -c::
 --count=::
@@ -69,8 +69,8 @@ OPTIONS
        Output file name.
 
 -i::
---inherit::
-       Child tasks inherit counters.
+--no-inherit::
+       Child tasks do not inherit counters.
 -F::
 --freq=::
        Profile at this frequency.
@@ -101,7 +101,7 @@ OPTIONS
 
 -R::
 --raw-samples::
-Collect raw sample records from all opened counters (typically for tracepoint counters).
+Collect raw sample records from all opened counters (default for tracepoint counters).
 
 SEE ALSO
 --------
index 1ce7919..8417644 100644 (file)
@@ -12,7 +12,7 @@ SYNOPSIS
 
 DESCRIPTION
 -----------
-There's four variants of perf sched:
+There are four variants of perf sched:
 
   'perf sched record <command>' to record the scheduling events
   of an arbitrary workload.
@@ -27,7 +27,7 @@ There's four variants of perf sched:
   via perf sched record. (this is done by starting up mockup threads
   that mimic the workload based on the events in the trace. These
   threads can then replay the timings (CPU runtime and sleep patterns)
-  of the workload as it occured when it was recorded - and can repeat
+  of the workload as it occurred when it was recorded - and can repeat
   it a number of times, measuring its performance.)
 
 OPTIONS
index 484080d..2cab8e8 100644 (file)
@@ -31,8 +31,8 @@ OPTIONS
         hexadecimal event descriptor.
 
 -i::
---inherit::
-        child tasks inherit counters
+--no-inherit::
+        child tasks do not inherit counters
 -p::
 --pid=<pid>::
         stat events on existing pid
diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt
new file mode 100644 (file)
index 0000000..1c4b5f5
--- /dev/null
@@ -0,0 +1,22 @@
+perf-test(1)
+============
+
+NAME
+----
+perf-test - Runs sanity tests.
+
+SYNOPSIS
+--------
+[verse]
+'perf test <options>'
+
+DESCRIPTION
+-----------
+This command does assorted sanity tests, initially thru linked routines but
+also will look for a directory with more tests in the form of scripts.
+
+OPTIONS
+-------
+-v::
+--verbose::
+       Be more verbose.
index d729cee..ee6525e 100644 (file)
@@ -49,12 +49,10 @@ available as calls back into the perf executable (see below).
 As an example, the following perf record command can be used to record
 all sched_wakeup events in the system:
 
- # perf record -c 1 -f -a -M -R -e sched:sched_wakeup
+ # perf record -a -e sched:sched_wakeup
 
 Traces meant to be processed using a script should be recorded with
-the above options: -c 1 says to sample every event, -a to enable
-system-wide collection, -M to multiplex the output, and -R to collect
-raw samples.
+the above option: -a to enable system-wide collection.
 
 The format file for the sched_wakep event defines the following fields
 (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format):
index a241aca..693be80 100644 (file)
@@ -1,5 +1,5 @@
 perf-trace-python(1)
-==================
+====================
 
 NAME
 ----
@@ -93,7 +93,7 @@ don't care how it exited, so we'll use 'perf record' to record only
 the sys_enter events:
 
 ----
-# perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
+# perf record -a -e raw_syscalls:sys_enter
 
 ^C[ perf record: Woken up 1 times to write data ]
 [ perf record: Captured and wrote 56.545 MB perf.data (~2470503 samples) ]
@@ -182,7 +182,7 @@ mean either that the record step recorded event types that it wasn't
 really interested in, or the script was run against a trace file that
 doesn't correspond to the script.
 
-The script generated by -g option option simply prints a line for each
+The script generated by -g option simply prints a line for each
 event found in the trace stream i.e. it basically just dumps the event
 and its parameter values to stdout.  The print_header() function is
 simply a utility function used for that purpose.  Let's rename the
@@ -359,7 +359,7 @@ your script:
 # cat kernel-source/tools/perf/scripts/python/bin/syscall-counts-record
 
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
+perf record -a -e raw_syscalls:sys_enter
 ----
 
 The 'report' script is also a shell script with the same base name as
@@ -449,12 +449,10 @@ available as calls back into the perf executable (see below).
 As an example, the following perf record command can be used to record
 all sched_wakeup events in the system:
 
- # perf record -c 1 -f -a -M -R -e sched:sched_wakeup
+ # perf record -a -e sched:sched_wakeup
 
 Traces meant to be processed using a script should be recorded with
-the above options: -c 1 says to sample every event, -a to enable
-system-wide collection, -M to multiplex the output, and -R to collect
-raw samples.
+the above option: -a to enable system-wide collection.
 
 The format file for the sched_wakep event defines the following fields
 (see /sys/kernel/debug/tracing/events/sched/sched_wakeup/format):
@@ -584,7 +582,7 @@ files:
   flag_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the flag field field_name of event event_name
   symbol_str(event_name, field_name, field_value) - returns the string represention corresponding to field_value for the symbolic field field_name of event event_name
 
-The *autodict* function returns a special special kind of Python
+The *autodict* function returns a special kind of Python
 dictionary that implements Perl's 'autovivifying' hashes in Python
 i.e. with autovivifying hashes, you can assign nested hash values
 without having to go to the trouble of creating intermediate levels if
index 8879299..122ec9d 100644 (file)
@@ -1,5 +1,5 @@
 perf-trace(1)
-==============
+=============
 
 NAME
 ----
index bc0f670..3d8f31e 100644 (file)
@@ -1,3 +1,7 @@
+ifeq ("$(origin O)", "command line")
+       OUTPUT := $(O)/
+endif
+
 # The default target of this Makefile is...
 all::
 
@@ -150,10 +154,17 @@ all::
 # Define LDFLAGS=-static to build a static binary.
 #
 # Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds.
+#
+# Define NO_DWARF if you do not want debug-info analysis feature at all.
 
-PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
-       @$(SHELL_PATH) util/PERF-VERSION-GEN
--include PERF-VERSION-FILE
+$(shell sh -c 'mkdir -p $(OUTPUT)scripts/python/Perf-Trace-Util/' 2> /dev/null)
+$(shell sh -c 'mkdir -p $(OUTPUT)scripts/perl/Perf-Trace-Util/' 2> /dev/null)
+$(shell sh -c 'mkdir -p $(OUTPUT)util/scripting-engines/' 2> /dev/null)
+$(shell sh -c 'mkdir $(OUTPUT)bench' 2> /dev/null)
+
+$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE
+       @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT)
+-include $(OUTPUT)PERF-VERSION-FILE
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
@@ -162,6 +173,22 @@ uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
 uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
 uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
 
+ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
+                                 -e s/arm.*/arm/ -e s/sa110/arm/ \
+                                 -e s/s390x/s390/ -e s/parisc64/parisc/ \
+                                 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
+                                 -e s/sh[234].*/sh/ )
+
+# Additional ARCH settings for x86
+ifeq ($(ARCH),i386)
+        ARCH := x86
+endif
+ifeq ($(ARCH),x86_64)
+        ARCH := x86
+endif
+
+$(shell sh -c 'mkdir -p $(OUTPUT)arch/$(ARCH)/util/' 2> /dev/null)
+
 # CFLAGS and LDFLAGS are for the users to override from the command line.
 
 #
@@ -274,7 +301,7 @@ endif
 # Those must not be GNU-specific; they are shared with perl/ which may
 # be built by a different compiler. (Note that this is an artifact now
 # but it still might be nice to keep that distinction.)
-BASIC_CFLAGS = -Iutil/include
+BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include
 BASIC_LDFLAGS =
 
 # Guard against environment variables
@@ -308,7 +335,7 @@ PROGRAMS += $(EXTRA_PROGRAMS)
 #
 # Single 'perf' binary right now:
 #
-PROGRAMS += perf
+PROGRAMS += $(OUTPUT)perf
 
 # List built-in command $C whose implementation cmd_$C() is not in
 # builtin-$C.o but is linked in as part of some other command.
@@ -318,7 +345,7 @@ PROGRAMS += perf
 ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
 
 # what 'all' will build but not install in perfexecdir
-OTHER_PROGRAMS = perf$X
+OTHER_PROGRAMS = $(OUTPUT)perf$X
 
 # Set paths to tools early so that they can be used for version tests.
 ifndef SHELL_PATH
@@ -330,7 +357,7 @@ endif
 
 export PERL_PATH
 
-LIB_FILE=libperf.a
+LIB_FILE=$(OUTPUT)libperf.a
 
 LIB_H += ../../include/linux/perf_event.h
 LIB_H += ../../include/linux/rbtree.h
@@ -350,12 +377,13 @@ LIB_H += util/include/linux/rbtree.h
 LIB_H += util/include/linux/string.h
 LIB_H += util/include/linux/types.h
 LIB_H += util/include/asm/asm-offsets.h
-LIB_H += util/include/asm/bitops.h
 LIB_H += util/include/asm/bug.h
 LIB_H += util/include/asm/byteorder.h
+LIB_H += util/include/asm/hweight.h
 LIB_H += util/include/asm/swab.h
 LIB_H += util/include/asm/system.h
 LIB_H += util/include/asm/uaccess.h
+LIB_H += util/include/dwarf-regs.h
 LIB_H += perf.h
 LIB_H += util/cache.h
 LIB_H += util/callchain.h
@@ -375,7 +403,6 @@ LIB_H += util/header.h
 LIB_H += util/help.h
 LIB_H += util/session.h
 LIB_H += util/strbuf.h
-LIB_H += util/string.h
 LIB_H += util/strlist.h
 LIB_H += util/svghelper.h
 LIB_H += util/run-command.h
@@ -389,79 +416,83 @@ LIB_H += util/thread.h
 LIB_H += util/trace-event.h
 LIB_H += util/probe-finder.h
 LIB_H += util/probe-event.h
+LIB_H += util/pstack.h
 LIB_H += util/cpumap.h
 
-LIB_OBJS += util/abspath.o
-LIB_OBJS += util/alias.o
-LIB_OBJS += util/build-id.o
-LIB_OBJS += util/config.o
-LIB_OBJS += util/ctype.o
-LIB_OBJS += util/debugfs.o
-LIB_OBJS += util/environment.o
-LIB_OBJS += util/event.o
-LIB_OBJS += util/exec_cmd.o
-LIB_OBJS += util/help.o
-LIB_OBJS += util/levenshtein.o
-LIB_OBJS += util/parse-options.o
-LIB_OBJS += util/parse-events.o
-LIB_OBJS += util/path.o
-LIB_OBJS += util/rbtree.o
-LIB_OBJS += util/bitmap.o
-LIB_OBJS += util/hweight.o
-LIB_OBJS += util/find_next_bit.o
-LIB_OBJS += util/run-command.o
-LIB_OBJS += util/quote.o
-LIB_OBJS += util/strbuf.o
-LIB_OBJS += util/string.o
-LIB_OBJS += util/strlist.o
-LIB_OBJS += util/usage.o
-LIB_OBJS += util/wrapper.o
-LIB_OBJS += util/sigchain.o
-LIB_OBJS += util/symbol.o
-LIB_OBJS += util/color.o
-LIB_OBJS += util/pager.o
-LIB_OBJS += util/header.o
-LIB_OBJS += util/callchain.o
-LIB_OBJS += util/values.o
-LIB_OBJS += util/debug.o
-LIB_OBJS += util/map.o
-LIB_OBJS += util/session.o
-LIB_OBJS += util/thread.o
-LIB_OBJS += util/trace-event-parse.o
-LIB_OBJS += util/trace-event-read.o
-LIB_OBJS += util/trace-event-info.o
-LIB_OBJS += util/trace-event-scripting.o
-LIB_OBJS += util/svghelper.o
-LIB_OBJS += util/sort.o
-LIB_OBJS += util/hist.o
-LIB_OBJS += util/probe-event.o
-LIB_OBJS += util/util.o
-LIB_OBJS += util/cpumap.o
-
-BUILTIN_OBJS += builtin-annotate.o
-
-BUILTIN_OBJS += builtin-bench.o
+LIB_OBJS += $(OUTPUT)util/abspath.o
+LIB_OBJS += $(OUTPUT)util/alias.o
+LIB_OBJS += $(OUTPUT)util/build-id.o
+LIB_OBJS += $(OUTPUT)util/config.o
+LIB_OBJS += $(OUTPUT)util/ctype.o
+LIB_OBJS += $(OUTPUT)util/debugfs.o
+LIB_OBJS += $(OUTPUT)util/environment.o
+LIB_OBJS += $(OUTPUT)util/event.o
+LIB_OBJS += $(OUTPUT)util/exec_cmd.o
+LIB_OBJS += $(OUTPUT)util/help.o
+LIB_OBJS += $(OUTPUT)util/levenshtein.o
+LIB_OBJS += $(OUTPUT)util/parse-options.o
+LIB_OBJS += $(OUTPUT)util/parse-events.o
+LIB_OBJS += $(OUTPUT)util/path.o
+LIB_OBJS += $(OUTPUT)util/rbtree.o
+LIB_OBJS += $(OUTPUT)util/bitmap.o
+LIB_OBJS += $(OUTPUT)util/hweight.o
+LIB_OBJS += $(OUTPUT)util/run-command.o
+LIB_OBJS += $(OUTPUT)util/quote.o
+LIB_OBJS += $(OUTPUT)util/strbuf.o
+LIB_OBJS += $(OUTPUT)util/string.o
+LIB_OBJS += $(OUTPUT)util/strlist.o
+LIB_OBJS += $(OUTPUT)util/usage.o
+LIB_OBJS += $(OUTPUT)util/wrapper.o
+LIB_OBJS += $(OUTPUT)util/sigchain.o
+LIB_OBJS += $(OUTPUT)util/symbol.o
+LIB_OBJS += $(OUTPUT)util/color.o
+LIB_OBJS += $(OUTPUT)util/pager.o
+LIB_OBJS += $(OUTPUT)util/header.o
+LIB_OBJS += $(OUTPUT)util/callchain.o
+LIB_OBJS += $(OUTPUT)util/values.o
+LIB_OBJS += $(OUTPUT)util/debug.o
+LIB_OBJS += $(OUTPUT)util/map.o
+LIB_OBJS += $(OUTPUT)util/pstack.o
+LIB_OBJS += $(OUTPUT)util/session.o
+LIB_OBJS += $(OUTPUT)util/thread.o
+LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
+LIB_OBJS += $(OUTPUT)util/trace-event-read.o
+LIB_OBJS += $(OUTPUT)util/trace-event-info.o
+LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
+LIB_OBJS += $(OUTPUT)util/svghelper.o
+LIB_OBJS += $(OUTPUT)util/sort.o
+LIB_OBJS += $(OUTPUT)util/hist.o
+LIB_OBJS += $(OUTPUT)util/probe-event.o
+LIB_OBJS += $(OUTPUT)util/util.o
+LIB_OBJS += $(OUTPUT)util/cpumap.o
+
+BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
+
+BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
 
 # Benchmark modules
-BUILTIN_OBJS += bench/sched-messaging.o
-BUILTIN_OBJS += bench/sched-pipe.o
-BUILTIN_OBJS += bench/mem-memcpy.o
-
-BUILTIN_OBJS += builtin-diff.o
-BUILTIN_OBJS += builtin-help.o
-BUILTIN_OBJS += builtin-sched.o
-BUILTIN_OBJS += builtin-buildid-list.o
-BUILTIN_OBJS += builtin-buildid-cache.o
-BUILTIN_OBJS += builtin-list.o
-BUILTIN_OBJS += builtin-record.o
-BUILTIN_OBJS += builtin-report.o
-BUILTIN_OBJS += builtin-stat.o
-BUILTIN_OBJS += builtin-timechart.o
-BUILTIN_OBJS += builtin-top.o
-BUILTIN_OBJS += builtin-trace.o
-BUILTIN_OBJS += builtin-probe.o
-BUILTIN_OBJS += builtin-kmem.o
-BUILTIN_OBJS += builtin-lock.o
+BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o
+BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o
+BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
+
+BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
+BUILTIN_OBJS += $(OUTPUT)builtin-help.o
+BUILTIN_OBJS += $(OUTPUT)builtin-sched.o
+BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o
+BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o
+BUILTIN_OBJS += $(OUTPUT)builtin-list.o
+BUILTIN_OBJS += $(OUTPUT)builtin-record.o
+BUILTIN_OBJS += $(OUTPUT)builtin-report.o
+BUILTIN_OBJS += $(OUTPUT)builtin-stat.o
+BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o
+BUILTIN_OBJS += $(OUTPUT)builtin-top.o
+BUILTIN_OBJS += $(OUTPUT)builtin-trace.o
+BUILTIN_OBJS += $(OUTPUT)builtin-probe.o
+BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
+BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
+BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
+BUILTIN_OBJS += $(OUTPUT)builtin-test.o
+BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
 
 PERFLIBS = $(LIB_FILE)
 
@@ -476,6 +507,15 @@ PERFLIBS = $(LIB_FILE)
 -include config.mak.autogen
 -include config.mak
 
+ifndef NO_DWARF
+ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo '\#include <version.h>'; echo '\#ifndef _ELFUTILS_PREREQ'; echo '\#error'; echo '\#endif'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
+       msg := $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev);
+       NO_DWARF := 1
+endif # Dwarf support
+endif # NO_DWARF
+
+-include arch/$(ARCH)/Makefile
+
 ifeq ($(uname_S),Darwin)
        ifndef NO_FINK
                ifeq ($(shell test -d /sw/lib && echo y),y)
@@ -492,6 +532,10 @@ ifeq ($(uname_S),Darwin)
        PTHREAD_LIBS =
 endif
 
+ifneq ($(OUTPUT),)
+       BASIC_CFLAGS += -I$(OUTPUT)
+endif
+
 ifeq ($(shell sh -c "(echo '\#include <libelf.h>'; echo 'int main(void) { Elf * elf = elf_begin(0, ELF_C_READ, 0); return (long)elf; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
 ifneq ($(shell sh -c "(echo '\#include <gnu/libc-version.h>'; echo 'int main(void) { const char * version = gnu_get_libc_version(); return (long)version; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
        msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
@@ -504,14 +548,29 @@ else
        msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel and glibc-dev[el]);
 endif
 
-ifneq ($(shell sh -c "(echo '\#include <dwarf.h>'; echo '\#include <libdw.h>'; echo 'int main(void) { Dwarf *dbg; dbg = dwarf_begin(0, DWARF_C_READ); return (long)dbg; }') | $(CC) -x c - $(ALL_CFLAGS) -I/usr/include/elfutils -ldw -lelf -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
-       msg := $(warning No libdw.h found or old libdw.h found, disables dwarf support. Please install elfutils-devel/elfutils-dev);
-       BASIC_CFLAGS += -DNO_DWARF_SUPPORT
+ifndef NO_DWARF
+ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
+       msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
 else
-       BASIC_CFLAGS += -I/usr/include/elfutils
+       BASIC_CFLAGS += -I/usr/include/elfutils -DDWARF_SUPPORT
        EXTLIBS += -lelf -ldw
-       LIB_OBJS += util/probe-finder.o
+       LIB_OBJS += $(OUTPUT)util/probe-finder.o
+endif # PERF_HAVE_DWARF_REGS
+endif # NO_DWARF
+
+ifdef NO_NEWT
+       BASIC_CFLAGS += -DNO_NEWT_SUPPORT
+else
+ifneq ($(shell sh -c "(echo '\#include <newt.h>'; echo 'int main(void) { newtInit(); newtCls(); return newtFinished(); }') | $(CC) -x c - $(ALL_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -lnewt -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) "$(QUIET_STDERR)" && echo y"), y)
+       msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev);
+       BASIC_CFLAGS += -DNO_NEWT_SUPPORT
+else
+       # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
+       BASIC_CFLAGS += -I/usr/include/slang
+       EXTLIBS += -lnewt -lslang
+       LIB_OBJS += $(OUTPUT)util/newt.o
 endif
+endif # NO_NEWT
 
 ifndef NO_LIBPERL
 PERL_EMBED_LDOPTS = `perl -MExtUtils::Embed -e ldopts 2>/dev/null`
@@ -522,8 +581,8 @@ ifneq ($(shell sh -c "(echo '\#include <EXTERN.h>'; echo '\#include <perl.h>'; e
        BASIC_CFLAGS += -DNO_LIBPERL
 else
        ALL_LDFLAGS += $(PERL_EMBED_LDOPTS)
-       LIB_OBJS += util/scripting-engines/trace-event-perl.o
-       LIB_OBJS += scripts/perl/Perf-Trace-Util/Context.o
+       LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o
+       LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o
 endif
 
 ifndef NO_LIBPYTHON
@@ -531,16 +590,19 @@ PYTHON_EMBED_LDOPTS = `python-config --ldflags 2>/dev/null`
 PYTHON_EMBED_CCOPTS = `python-config --cflags 2>/dev/null`
 endif
 
-ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o /dev/null $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
+ifneq ($(shell sh -c "(echo '\#include <Python.h>'; echo 'int main(void) { Py_Initialize(); return 0; }') | $(CC) -x c - $(PYTHON_EMBED_CCOPTS) -o $(BITBUCKET) $(PYTHON_EMBED_LDOPTS) > /dev/null 2>&1 && echo y"), y)
        BASIC_CFLAGS += -DNO_LIBPYTHON
 else
        ALL_LDFLAGS += $(PYTHON_EMBED_LDOPTS)
-       LIB_OBJS += util/scripting-engines/trace-event-python.o
-       LIB_OBJS += scripts/python/Perf-Trace-Util/Context.o
+       LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o
+       LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o
 endif
 
 ifdef NO_DEMANGLE
        BASIC_CFLAGS += -DNO_DEMANGLE
+else ifdef HAVE_CPLUS_DEMANGLE
+       EXTLIBS += -liberty
+       BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
 else
        has_bfd := $(shell sh -c "(echo '\#include <bfd.h>'; echo 'int main(void) { bfd_demangle(0, 0, 0); return 0; }') | $(CC) -x c - $(ALL_CFLAGS) -o $(BITBUCKET) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd "$(QUIET_STDERR)" && echo y")
 
@@ -607,53 +669,53 @@ ifdef NO_C99_FORMAT
 endif
 ifdef SNPRINTF_RETURNS_BOGUS
        COMPAT_CFLAGS += -DSNPRINTF_RETURNS_BOGUS
-       COMPAT_OBJS += compat/snprintf.o
+       COMPAT_OBJS += $(OUTPUT)compat/snprintf.o
 endif
 ifdef FREAD_READS_DIRECTORIES
        COMPAT_CFLAGS += -DFREAD_READS_DIRECTORIES
-       COMPAT_OBJS += compat/fopen.o
+       COMPAT_OBJS += $(OUTPUT)compat/fopen.o
 endif
 ifdef NO_SYMLINK_HEAD
        BASIC_CFLAGS += -DNO_SYMLINK_HEAD
 endif
 ifdef NO_STRCASESTR
        COMPAT_CFLAGS += -DNO_STRCASESTR
-       COMPAT_OBJS += compat/strcasestr.o
+       COMPAT_OBJS += $(OUTPUT)compat/strcasestr.o
 endif
 ifdef NO_STRTOUMAX
        COMPAT_CFLAGS += -DNO_STRTOUMAX
-       COMPAT_OBJS += compat/strtoumax.o
+       COMPAT_OBJS += $(OUTPUT)compat/strtoumax.o
 endif
 ifdef NO_STRTOULL
        COMPAT_CFLAGS += -DNO_STRTOULL
 endif
 ifdef NO_SETENV
        COMPAT_CFLAGS += -DNO_SETENV
-       COMPAT_OBJS += compat/setenv.o
+       COMPAT_OBJS += $(OUTPUT)compat/setenv.o
 endif
 ifdef NO_MKDTEMP
        COMPAT_CFLAGS += -DNO_MKDTEMP
-       COMPAT_OBJS += compat/mkdtemp.o
+       COMPAT_OBJS += $(OUTPUT)compat/mkdtemp.o
 endif
 ifdef NO_UNSETENV
        COMPAT_CFLAGS += -DNO_UNSETENV
-       COMPAT_OBJS += compat/unsetenv.o
+       COMPAT_OBJS += $(OUTPUT)compat/unsetenv.o
 endif
 ifdef NO_SYS_SELECT_H
        BASIC_CFLAGS += -DNO_SYS_SELECT_H
 endif
 ifdef NO_MMAP
        COMPAT_CFLAGS += -DNO_MMAP
-       COMPAT_OBJS += compat/mmap.o
+       COMPAT_OBJS += $(OUTPUT)compat/mmap.o
 else
        ifdef USE_WIN32_MMAP
                COMPAT_CFLAGS += -DUSE_WIN32_MMAP
-               COMPAT_OBJS += compat/win32mmap.o
+               COMPAT_OBJS += $(OUTPUT)compat/win32mmap.o
        endif
 endif
 ifdef NO_PREAD
        COMPAT_CFLAGS += -DNO_PREAD
-       COMPAT_OBJS += compat/pread.o
+       COMPAT_OBJS += $(OUTPUT)compat/pread.o
 endif
 ifdef NO_FAST_WORKING_DIRECTORY
        BASIC_CFLAGS += -DNO_FAST_WORKING_DIRECTORY
@@ -675,10 +737,10 @@ else
 endif
 endif
 ifdef NO_INET_NTOP
-       LIB_OBJS += compat/inet_ntop.o
+       LIB_OBJS += $(OUTPUT)compat/inet_ntop.o
 endif
 ifdef NO_INET_PTON
-       LIB_OBJS += compat/inet_pton.o
+       LIB_OBJS += $(OUTPUT)compat/inet_pton.o
 endif
 
 ifdef NO_ICONV
@@ -695,15 +757,15 @@ endif
 
 ifdef PPC_SHA1
        SHA1_HEADER = "ppc/sha1.h"
-       LIB_OBJS += ppc/sha1.o ppc/sha1ppc.o
+       LIB_OBJS += $(OUTPUT)ppc/sha1.o ppc/sha1ppc.o
 else
 ifdef ARM_SHA1
        SHA1_HEADER = "arm/sha1.h"
-       LIB_OBJS += arm/sha1.o arm/sha1_arm.o
+       LIB_OBJS += $(OUTPUT)arm/sha1.o $(OUTPUT)arm/sha1_arm.o
 else
 ifdef MOZILLA_SHA1
        SHA1_HEADER = "mozilla-sha1/sha1.h"
-       LIB_OBJS += mozilla-sha1/sha1.o
+       LIB_OBJS += $(OUTPUT)mozilla-sha1/sha1.o
 else
        SHA1_HEADER = <openssl/sha.h>
        EXTLIBS += $(LIB_4_CRYPTO)
@@ -715,15 +777,15 @@ ifdef NO_PERL_MAKEMAKER
 endif
 ifdef NO_HSTRERROR
        COMPAT_CFLAGS += -DNO_HSTRERROR
-       COMPAT_OBJS += compat/hstrerror.o
+       COMPAT_OBJS += $(OUTPUT)compat/hstrerror.o
 endif
 ifdef NO_MEMMEM
        COMPAT_CFLAGS += -DNO_MEMMEM
-       COMPAT_OBJS += compat/memmem.o
+       COMPAT_OBJS += $(OUTPUT)compat/memmem.o
 endif
 ifdef INTERNAL_QSORT
        COMPAT_CFLAGS += -DINTERNAL_QSORT
-       COMPAT_OBJS += compat/qsort.o
+       COMPAT_OBJS += $(OUTPUT)compat/qsort.o
 endif
 ifdef RUNTIME_PREFIX
        COMPAT_CFLAGS += -DRUNTIME_PREFIX
@@ -803,7 +865,7 @@ export TAR INSTALL DESTDIR SHELL_PATH
 
 SHELL = $(SHELL_PATH)
 
-all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) PERF-BUILD-OPTIONS
+all:: .perf.dev.null shell_compatibility_test $(ALL_PROGRAMS) $(BUILT_INS) $(OTHER_PROGRAMS) $(OUTPUT)PERF-BUILD-OPTIONS
 ifneq (,$X)
        $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), test '$p' -ef '$p$X' || $(RM) '$p';)
 endif
@@ -815,39 +877,39 @@ please_set_SHELL_PATH_to_a_more_modern_shell:
 
 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
 
-strip: $(PROGRAMS) perf$X
-       $(STRIP) $(STRIP_OPTS) $(PROGRAMS) perf$X
+strip: $(PROGRAMS) $(OUTPUT)perf$X
+       $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf$X
 
-perf.o: perf.c common-cmds.h PERF-CFLAGS
+$(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
        $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \
                '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
-               $(ALL_CFLAGS) -c $(filter %.c,$^)
+               $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
-perf$X: perf.o $(BUILTIN_OBJS) $(PERFLIBS)
-       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ perf.o \
+$(OUTPUT)perf$X: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
+       $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(OUTPUT)perf.o \
                $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
-builtin-help.o: builtin-help.c common-cmds.h PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
+$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
                '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
                '-DPERF_MAN_PATH="$(mandir_SQ)"' \
                '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
 
-builtin-timechart.o: builtin-timechart.c common-cmds.h PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
+$(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
                '-DPERF_HTML_PATH="$(htmldir_SQ)"' \
                '-DPERF_MAN_PATH="$(mandir_SQ)"' \
                '-DPERF_INFO_PATH="$(infodir_SQ)"' $<
 
-$(BUILT_INS): perf$X
+$(BUILT_INS): $(OUTPUT)perf$X
        $(QUIET_BUILT_IN)$(RM) $@ && \
        ln perf$X $@ 2>/dev/null || \
        ln -s perf$X $@ 2>/dev/null || \
        cp perf$X $@
 
-common-cmds.h: util/generate-cmdlist.sh command-list.txt
+$(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
 
-common-cmds.h: $(wildcard Documentation/perf-*.txt)
+$(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt)
        $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@
 
 $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
@@ -859,7 +921,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
            -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
            $@.sh >$@+ && \
        chmod +x $@+ && \
-       mv $@+ $@
+       mv $@+ $(OUTPUT)$@
 
 configure: configure.ac
        $(QUIET_GEN)$(RM) $@ $<+ && \
@@ -869,60 +931,50 @@ configure: configure.ac
        $(RM) $<+
 
 # These can record PERF_VERSION
-perf.o perf.spec \
+$(OUTPUT)perf.o perf.spec \
        $(patsubst %.sh,%,$(SCRIPT_SH)) \
        $(patsubst %.perl,%,$(SCRIPT_PERL)) \
-       : PERF-VERSION-FILE
+       : $(OUTPUT)PERF-VERSION-FILE
 
-%.o: %.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
-%.s: %.c PERF-CFLAGS
+$(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
+$(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS
        $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $<
-%.o: %.S
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) $<
+$(OUTPUT)%.o: %.S
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
 
-util/exec_cmd.o: util/exec_cmd.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
+$(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \
                '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \
                '-DBINDIR="$(bindir_relative_SQ)"' \
                '-DPREFIX="$(prefix_SQ)"' \
                $<
 
-builtin-init-db.o: builtin-init-db.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
-
-util/config.o: util/config.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
-
-util/rbtree.o: ../../lib/rbtree.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/rbtree.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
-
-# some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing
-# from <string.h> that comes from kernel headers wrapping.
-KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//`
+$(OUTPUT)builtin-init-db.o: builtin-init-db.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DDEFAULT_PERF_TEMPLATE_DIR='"$(template_dir_SQ)"' $<
 
-util/bitmap.o: ../../lib/bitmap.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/bitmap.o -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
+$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
-util/hweight.o: ../../lib/hweight.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/hweight.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
+$(OUTPUT)util/newt.o: util/newt.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $<
 
-util/find_next_bit.o: ../../lib/find_next_bit.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/find_next_bit.o -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
+$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<
 
-util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-perl.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
-scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o scripts/perl/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+$(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
 
-util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o util/scripting-engines/trace-event-python.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
+$(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<
 
-scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c PERF-CFLAGS
-       $(QUIET_CC)$(CC) -o scripts/python/Perf-Trace-Util/Context.o -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
+$(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS
+       $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $<
 
-perf-%$X: %.o $(PERFLIBS)
+$(OUTPUT)perf-%$X: %.o $(PERFLIBS)
        $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
 
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
@@ -963,17 +1015,17 @@ cscope:
 TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\
              $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ)
 
-PERF-CFLAGS: .FORCE-PERF-CFLAGS
+$(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS
        @FLAGS='$(TRACK_CFLAGS)'; \
-           if test x"$$FLAGS" != x"`cat PERF-CFLAGS 2>/dev/null`" ; then \
+           if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \
                echo 1>&2 "    * new build flags or prefix"; \
-               echo "$$FLAGS" >PERF-CFLAGS; \
+               echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \
             fi
 
 # We need to apply sq twice, once to protect from the shell
-# that runs PERF-BUILD-OPTIONS, and then again to protect it
+# that runs $(OUTPUT)PERF-BUILD-OPTIONS, and then again to protect it
 # and the first level quoting from the shell that runs "echo".
-PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS
+$(OUTPUT)PERF-BUILD-OPTIONS: .FORCE-PERF-BUILD-OPTIONS
        @echo SHELL_PATH=\''$(subst ','\'',$(SHELL_PATH_SQ))'\' >$@
        @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@
        @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@
@@ -994,7 +1046,7 @@ all:: $(TEST_PROGRAMS)
 
 export NO_SVN_TESTS
 
-check: common-cmds.h
+check: $(OUTPUT)common-cmds.h
        if sparse; \
        then \
                for i in *.c */*.c; \
@@ -1028,10 +1080,10 @@ export perfexec_instdir
 
 install: all
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
-       $(INSTALL) perf$X '$(DESTDIR_SQ)$(bindir_SQ)'
+       $(INSTALL) $(OUTPUT)perf$X '$(DESTDIR_SQ)$(bindir_SQ)'
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
-       $(INSTALL) perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
+       $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
        $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace'
        $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl'
        $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin'
@@ -1045,7 +1097,7 @@ ifdef BUILT_INS
        $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
        $(INSTALL) $(BUILT_INS) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)'
 ifneq (,$X)
-       $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';)
+       $(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) $(OUTPUT)perf$X)), $(RM) '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/$p';)
 endif
 endif
 
@@ -1129,14 +1181,14 @@ clean:
        $(RM) *.o */*.o */*/*.o */*/*/*.o $(LIB_FILE)
        $(RM) $(ALL_PROGRAMS) $(BUILT_INS) perf$X
        $(RM) $(TEST_PROGRAMS)
-       $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo common-cmds.h TAGS tags cscope*
+       $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
        $(RM) -r autom4te.cache
        $(RM) config.log config.mak.autogen config.mak.append config.status config.cache
        $(RM) -r $(PERF_TARNAME) .doc-tmp-dir
        $(RM) $(PERF_TARNAME).tar.gz perf-core_$(PERF_VERSION)-*.tar.gz
        $(RM) $(htmldocs).tar.gz $(manpages).tar.gz
        $(MAKE) -C Documentation/ clean
-       $(RM) PERF-VERSION-FILE PERF-CFLAGS PERF-BUILD-OPTIONS
+       $(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS $(OUTPUT)PERF-BUILD-OPTIONS
 
 .PHONY: all install clean strip
 .PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
diff --git a/tools/perf/arch/powerpc/Makefile b/tools/perf/arch/powerpc/Makefile
new file mode 100644 (file)
index 0000000..15130b5
--- /dev/null
@@ -0,0 +1,4 @@
+ifndef NO_DWARF
+PERF_HAVE_DWARF_REGS := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
+endif
diff --git a/tools/perf/arch/powerpc/util/dwarf-regs.c b/tools/perf/arch/powerpc/util/dwarf-regs.c
new file mode 100644 (file)
index 0000000..48ae0c5
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Mapping of DWARF debug register numbers into register names.
+ *
+ * Copyright (C) 2010 Ian Munsie, IBM Corporation.
+ *
+ * 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.
+ */
+
+#include <libio.h>
+#include <dwarf-regs.h>
+
+
+struct pt_regs_dwarfnum {
+       const char *name;
+       unsigned int dwarfnum;
+};
+
+#define STR(s) #s
+#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
+#define GPR_DWARFNUM_NAME(num) \
+       {.name = STR(%gpr##num), .dwarfnum = num}
+#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
+
+/*
+ * Reference:
+ * http://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html
+ */
+static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
+       GPR_DWARFNUM_NAME(0),
+       GPR_DWARFNUM_NAME(1),
+       GPR_DWARFNUM_NAME(2),
+       GPR_DWARFNUM_NAME(3),
+       GPR_DWARFNUM_NAME(4),
+       GPR_DWARFNUM_NAME(5),
+       GPR_DWARFNUM_NAME(6),
+       GPR_DWARFNUM_NAME(7),
+       GPR_DWARFNUM_NAME(8),
+       GPR_DWARFNUM_NAME(9),
+       GPR_DWARFNUM_NAME(10),
+       GPR_DWARFNUM_NAME(11),
+       GPR_DWARFNUM_NAME(12),
+       GPR_DWARFNUM_NAME(13),
+       GPR_DWARFNUM_NAME(14),
+       GPR_DWARFNUM_NAME(15),
+       GPR_DWARFNUM_NAME(16),
+       GPR_DWARFNUM_NAME(17),
+       GPR_DWARFNUM_NAME(18),
+       GPR_DWARFNUM_NAME(19),
+       GPR_DWARFNUM_NAME(20),
+       GPR_DWARFNUM_NAME(21),
+       GPR_DWARFNUM_NAME(22),
+       GPR_DWARFNUM_NAME(23),
+       GPR_DWARFNUM_NAME(24),
+       GPR_DWARFNUM_NAME(25),
+       GPR_DWARFNUM_NAME(26),
+       GPR_DWARFNUM_NAME(27),
+       GPR_DWARFNUM_NAME(28),
+       GPR_DWARFNUM_NAME(29),
+       GPR_DWARFNUM_NAME(30),
+       GPR_DWARFNUM_NAME(31),
+       REG_DWARFNUM_NAME("%msr",   66),
+       REG_DWARFNUM_NAME("%ctr",   109),
+       REG_DWARFNUM_NAME("%link",  108),
+       REG_DWARFNUM_NAME("%xer",   101),
+       REG_DWARFNUM_NAME("%dar",   119),
+       REG_DWARFNUM_NAME("%dsisr", 118),
+       REG_DWARFNUM_END,
+};
+
+/**
+ * get_arch_regstr() - lookup register name from it's DWARF register number
+ * @n: the DWARF register number
+ *
+ * get_arch_regstr() returns the name of the register in struct
+ * regdwarfnum_table from it's DWARF register number. If the register is not
+ * found in the table, this returns NULL;
+ */
+const char *get_arch_regstr(unsigned int n)
+{
+       const struct pt_regs_dwarfnum *roff;
+       for (roff = regdwarfnum_table; roff->name != NULL; roff++)
+               if (roff->dwarfnum == n)
+                       return roff->name;
+       return NULL;
+}
diff --git a/tools/perf/arch/x86/Makefile b/tools/perf/arch/x86/Makefile
new file mode 100644 (file)
index 0000000..15130b5
--- /dev/null
@@ -0,0 +1,4 @@
+ifndef NO_DWARF
+PERF_HAVE_DWARF_REGS := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
+endif
diff --git a/tools/perf/arch/x86/util/dwarf-regs.c b/tools/perf/arch/x86/util/dwarf-regs.c
new file mode 100644 (file)
index 0000000..a794d30
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * dwarf-regs.c : Mapping of DWARF debug register numbers into register names.
+ * Extracted from probe-finder.c
+ *
+ * Written by Masami Hiramatsu <mhiramat@redhat.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 <libio.h>
+#include <dwarf-regs.h>
+
+/*
+ * Generic dwarf analysis helpers
+ */
+
+#define X86_32_MAX_REGS 8
+const char *x86_32_regs_table[X86_32_MAX_REGS] = {
+       "%ax",
+       "%cx",
+       "%dx",
+       "%bx",
+       "$stack",       /* Stack address instead of %sp */
+       "%bp",
+       "%si",
+       "%di",
+};
+
+#define X86_64_MAX_REGS 16
+const char *x86_64_regs_table[X86_64_MAX_REGS] = {
+       "%ax",
+       "%dx",
+       "%cx",
+       "%bx",
+       "%si",
+       "%di",
+       "%bp",
+       "%sp",
+       "%r8",
+       "%r9",
+       "%r10",
+       "%r11",
+       "%r12",
+       "%r13",
+       "%r14",
+       "%r15",
+};
+
+/* TODO: switching by dwarf address size */
+#ifdef __x86_64__
+#define ARCH_MAX_REGS X86_64_MAX_REGS
+#define arch_regs_table x86_64_regs_table
+#else
+#define ARCH_MAX_REGS X86_32_MAX_REGS
+#define arch_regs_table x86_32_regs_table
+#endif
+
+/* Return architecture dependent register string (for kprobe-tracer) */
+const char *get_arch_regstr(unsigned int n)
+{
+       return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
+}
index 8977317..38dae74 100644 (file)
@@ -10,7 +10,6 @@
 #include "../perf.h"
 #include "../util/util.h"
 #include "../util/parse-options.h"
-#include "../util/string.h"
 #include "../util/header.h"
 #include "bench.h"
 
@@ -24,7 +23,7 @@
 
 static const char      *length_str     = "1MB";
 static const char      *routine        = "default";
-static int             use_clock       = 0;
+static bool            use_clock       = false;
 static int             clock_fd;
 
 static const struct option options[] = {
index 81cee78..d1d1b30 100644 (file)
@@ -31,9 +31,9 @@
 
 #define DATASIZE 100
 
-static int use_pipes = 0;
+static bool use_pipes = false;
 static unsigned int loops = 100;
-static unsigned int thread_mode = 0;
+static bool thread_mode = false;
 static unsigned int num_groups = 10;
 
 struct sender_context {
@@ -256,10 +256,8 @@ static const struct option options[] = {
                    "Use pipe() instead of socketpair()"),
        OPT_BOOLEAN('t', "thread", &thread_mode,
                    "Be multi thread instead of multi process"),
-       OPT_INTEGER('g', "group", &num_groups,
-                   "Specify number of groups"),
-       OPT_INTEGER('l', "loop", &loops,
-                   "Specify number of loops"),
+       OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"),
+       OPT_UINTEGER('l', "loop", &loops, "Specify number of loops"),
        OPT_END()
 };
 
index 4f77c7c..d9ab3ce 100644 (file)
@@ -93,7 +93,7 @@ int bench_sched_pipe(int argc, const char **argv,
 
        switch (bench_format) {
        case BENCH_FORMAT_DEFAULT:
-               printf("# Extecuted %d pipe operations between two tasks\n\n",
+               printf("# Executed %d pipe operations between two tasks\n\n",
                        loops);
 
                result_usec = diff.tv_sec * 1000000;
index 6ad7148..77bcc9b 100644 (file)
@@ -14,7 +14,6 @@
 #include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"
-#include "util/string.h"
 
 #include "perf.h"
 #include "util/debug.h"
 
 static char            const *input_name = "perf.data";
 
-static int             force;
+static bool            force;
 
-static int             full_paths;
+static bool            full_paths;
 
-static int             print_line;
-
-struct sym_hist {
-       u64             sum;
-       u64             ip[0];
-};
-
-struct sym_ext {
-       struct rb_node  node;
-       double          percent;
-       char            *path;
-};
-
-struct sym_priv {
-       struct sym_hist *hist;
-       struct sym_ext  *ext;
-};
+static bool            print_line;
 
 static const char *sym_hist_filter;
 
-static int sym__alloc_hist(struct symbol *self)
-{
-       struct sym_priv *priv = symbol__priv(self);
-       const int size = (sizeof(*priv->hist) +
-                         (self->end - self->start) * sizeof(u64));
-
-       priv->hist = zalloc(size);
-       return priv->hist == NULL ? -1 : 0;
-}
-
-/*
- * collect histogram counts
- */
-static int annotate__hist_hit(struct hist_entry *he, u64 ip)
-{
-       unsigned int sym_size, offset;
-       struct symbol *sym = he->sym;
-       struct sym_priv *priv;
-       struct sym_hist *h;
-
-       he->count++;
-
-       if (!sym || !he->map)
-               return 0;
-
-       priv = symbol__priv(sym);
-       if (priv->hist == NULL && sym__alloc_hist(sym) < 0)
-               return -ENOMEM;
-
-       sym_size = sym->end - sym->start;
-       offset = ip - sym->start;
-
-       pr_debug3("%s: ip=%#Lx\n", __func__, he->map->unmap_ip(he->map, ip));
-
-       if (offset >= sym_size)
-               return 0;
-
-       h = priv->hist;
-       h->sum++;
-       h->ip[offset]++;
-
-       pr_debug3("%#Lx %s: count++ [ip: %#Lx, %#Lx] => %Ld\n", he->sym->start,
-                 he->sym->name, ip, ip - he->sym->start, h->ip[offset]);
-       return 0;
-}
-
-static int perf_session__add_hist_entry(struct perf_session *self,
-                                       struct addr_location *al, u64 count)
+static int hists__add_entry(struct hists *self, struct addr_location *al)
 {
-       bool hit;
        struct hist_entry *he;
 
        if (sym_hist_filter != NULL &&
@@ -116,11 +51,11 @@ static int perf_session__add_hist_entry(struct perf_session *self,
                return 0;
        }
 
-       he = __perf_session__add_hist_entry(&self->hists, al, NULL, count, &hit);
+       he = __hists__add_entry(self, al, NULL, 1);
        if (he == NULL)
                return -ENOMEM;
 
-       return annotate__hist_hit(he, al->addr);
+       return hist_entry__inc_addr_samples(he, al->addr);
 }
 
 static int process_sample_event(event_t *event, struct perf_session *session)
@@ -136,7 +71,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
                return -1;
        }
 
-       if (!al.filtered && perf_session__add_hist_entry(session, &al, 1)) {
+       if (!al.filtered && hists__add_entry(&session->hists, &al)) {
                pr_warning("problem incrementing symbol count, "
                           "skipping event\n");
                return -1;
@@ -145,106 +80,11 @@ static int process_sample_event(event_t *event, struct perf_session *session)
        return 0;
 }
 
-struct objdump_line {
-       struct list_head node;
-       s64              offset;
-       char             *line;
-};
-
-static struct objdump_line *objdump_line__new(s64 offset, char *line)
-{
-       struct objdump_line *self = malloc(sizeof(*self));
-
-       if (self != NULL) {
-               self->offset = offset;
-               self->line = line;
-       }
-
-       return self;
-}
-
-static void objdump_line__free(struct objdump_line *self)
-{
-       free(self->line);
-       free(self);
-}
-
-static void objdump__add_line(struct list_head *head, struct objdump_line *line)
-{
-       list_add_tail(&line->node, head);
-}
-
-static struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
-                                                     struct objdump_line *pos)
-{
-       list_for_each_entry_continue(pos, head, node)
-               if (pos->offset >= 0)
-                       return pos;
-
-       return NULL;
-}
-
-static int parse_line(FILE *file, struct hist_entry *he,
-                     struct list_head *head)
-{
-       struct symbol *sym = he->sym;
-       struct objdump_line *objdump_line;
-       char *line = NULL, *tmp, *tmp2;
-       size_t line_len;
-       s64 line_ip, offset = -1;
-       char *c;
-
-       if (getline(&line, &line_len, file) < 0)
-               return -1;
-
-       if (!line)
-               return -1;
-
-       c = strchr(line, '\n');
-       if (c)
-               *c = 0;
-
-       line_ip = -1;
-
-       /*
-        * Strip leading spaces:
-        */
-       tmp = line;
-       while (*tmp) {
-               if (*tmp != ' ')
-                       break;
-               tmp++;
-       }
-
-       if (*tmp) {
-               /*
-                * Parse hexa addresses followed by ':'
-                */
-               line_ip = strtoull(tmp, &tmp2, 16);
-               if (*tmp2 != ':')
-                       line_ip = -1;
-       }
-
-       if (line_ip != -1) {
-               u64 start = map__rip_2objdump(he->map, sym->start);
-               offset = line_ip - start;
-       }
-
-       objdump_line = objdump_line__new(offset, line);
-       if (objdump_line == NULL) {
-               free(line);
-               return -1;
-       }
-       objdump__add_line(head, objdump_line);
-
-       return 0;
-}
-
 static int objdump_line__print(struct objdump_line *self,
                               struct list_head *head,
                               struct hist_entry *he, u64 len)
 {
-       struct symbol *sym = he->sym;
+       struct symbol *sym = he->ms.sym;
        static const char *prev_line;
        static const char *prev_color;
 
@@ -327,7 +167,7 @@ static void insert_source_line(struct sym_ext *sym_ext)
 
 static void free_source_line(struct hist_entry *he, int len)
 {
-       struct sym_priv *priv = symbol__priv(he->sym);
+       struct sym_priv *priv = symbol__priv(he->ms.sym);
        struct sym_ext *sym_ext = priv->ext;
        int i;
 
@@ -346,7 +186,7 @@ static void free_source_line(struct hist_entry *he, int len)
 static void
 get_source_line(struct hist_entry *he, int len, const char *filename)
 {
-       struct symbol *sym = he->sym;
+       struct symbol *sym = he->ms.sym;
        u64 start;
        int i;
        char cmd[PATH_MAX * 2];
@@ -361,7 +201,7 @@ get_source_line(struct hist_entry *he, int len, const char *filename)
        if (!priv->ext)
                return;
 
-       start = he->map->unmap_ip(he->map, sym->start);
+       start = he->ms.map->unmap_ip(he->ms.map, sym->start);
 
        for (i = 0; i < len; i++) {
                char *path = NULL;
@@ -425,7 +265,7 @@ static void print_summary(const char *filename)
 
 static void hist_entry__print_hits(struct hist_entry *self)
 {
-       struct symbol *sym = self->sym;
+       struct symbol *sym = self->ms.sym;
        struct sym_priv *priv = symbol__priv(sym);
        struct sym_hist *h = priv->hist;
        u64 len = sym->end - sym->start, offset;
@@ -439,23 +279,17 @@ static void hist_entry__print_hits(struct hist_entry *self)
 
 static void annotate_sym(struct hist_entry *he)
 {
-       struct map *map = he->map;
+       struct map *map = he->ms.map;
        struct dso *dso = map->dso;
-       struct symbol *sym = he->sym;
+       struct symbol *sym = he->ms.sym;
        const char *filename = dso->long_name, *d_filename;
        u64 len;
-       char command[PATH_MAX*2];
-       FILE *file;
        LIST_HEAD(head);
        struct objdump_line *pos, *n;
 
-       if (!filename)
+       if (hist_entry__annotate(he, &head) < 0)
                return;
 
-       pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__,
-                filename, sym->name, map->unmap_ip(map, sym->start),
-                map->unmap_ip(map, sym->end));
-
        if (full_paths)
                d_filename = filename;
        else
@@ -472,29 +306,6 @@ static void annotate_sym(struct hist_entry *he)
        printf(" Percent |      Source code & Disassembly of %s\n", d_filename);
        printf("------------------------------------------------\n");
 
-       if (verbose >= 2)
-               printf("annotating [%p] %30s : [%p] %30s\n",
-                      dso, dso->long_name, sym, sym->name);
-
-       sprintf(command, "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s",
-               map__rip_2objdump(map, sym->start),
-               map__rip_2objdump(map, sym->end),
-               filename, filename);
-
-       if (verbose >= 3)
-               printf("doing: %s\n", command);
-
-       file = popen(command, "r");
-       if (!file)
-               return;
-
-       while (!feof(file)) {
-               if (parse_line(file, he, &head) < 0)
-                       break;
-       }
-
-       pclose(file);
-
        if (verbose)
                hist_entry__print_hits(he);
 
@@ -508,25 +319,25 @@ static void annotate_sym(struct hist_entry *he)
                free_source_line(he, len);
 }
 
-static void perf_session__find_annotations(struct perf_session *self)
+static void hists__find_annotations(struct hists *self)
 {
        struct rb_node *nd;
 
-       for (nd = rb_first(&self->hists); nd; nd = rb_next(nd)) {
+       for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
                struct hist_entry *he = rb_entry(nd, struct hist_entry, rb_node);
                struct sym_priv *priv;
 
-               if (he->sym == NULL)
+               if (he->ms.sym == NULL)
                        continue;
 
-               priv = symbol__priv(he->sym);
+               priv = symbol__priv(he->ms.sym);
                if (priv->hist == NULL)
                        continue;
 
                annotate_sym(he);
                /*
                 * Since we have a hist_entry per IP for the same symbol, free
-                * he->sym->hist to signal we already processed this symbol.
+                * he->ms.sym->hist to signal we already processed this symbol.
                 */
                free(priv->hist);
                priv->hist = NULL;
@@ -545,7 +356,7 @@ static int __cmd_annotate(void)
        int ret;
        struct perf_session *session;
 
-       session = perf_session__new(input_name, O_RDONLY, force);
+       session = perf_session__new(input_name, O_RDONLY, force, false);
        if (session == NULL)
                return -ENOMEM;
 
@@ -554,7 +365,7 @@ static int __cmd_annotate(void)
                goto out_delete;
 
        if (dump_trace) {
-               event__print_totals();
+               perf_session__fprintf_nr_events(session, stdout);
                goto out_delete;
        }
 
@@ -562,11 +373,11 @@ static int __cmd_annotate(void)
                perf_session__fprintf(session, stdout);
 
        if (verbose > 2)
-               dsos__fprintf(stdout);
+               perf_session__fprintf_dsos(session, stdout);
 
-       perf_session__collapse_resort(&session->hists);
-       perf_session__output_resort(&session->hists, session->event_total[0]);
-       perf_session__find_annotations(session);
+       hists__collapse_resort(&session->hists);
+       hists__output_resort(&session->hists);
+       hists__find_annotations(&session->hists);
 out_delete:
        perf_session__delete(session);
 
@@ -581,10 +392,12 @@ static const char * const annotate_usage[] = {
 static const struct option options[] = {
        OPT_STRING('i', "input", &input_name, "file",
                    "input file name"),
+       OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
+                  "only consider symbols in these dsos"),
        OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
                    "symbol to annotate"),
        OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
index 4699677..fcb9626 100644 (file)
@@ -95,7 +95,7 @@ static void dump_suites(int subsys_index)
        return;
 }
 
-static char *bench_format_str;
+static const char *bench_format_str;
 int bench_format = BENCH_FORMAT_DEFAULT;
 
 static const struct option bench_options[] = {
@@ -126,7 +126,7 @@ static void print_usage(void)
        printf("\n");
 }
 
-static int bench_str2int(char *str)
+static int bench_str2int(const char *str)
 {
        if (!str)
                return BENCH_FORMAT_DEFAULT;
index 30a05f5..f8e3d18 100644 (file)
@@ -27,7 +27,7 @@ static const struct option buildid_cache_options[] = {
                   "file list", "file(s) to add"),
        OPT_STRING('r', "remove", &remove_name_list_str, "file list",
                    "file(s) to remove"),
-       OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose"),
+       OPT_INCR('v', "verbose", &verbose, "be more verbose"),
        OPT_END()
 };
 
index d0675c0..44a47e1 100644 (file)
@@ -16,7 +16,7 @@
 #include "util/symbol.h"
 
 static char const *input_name = "perf.data";
-static int force;
+static bool force;
 static bool with_hits;
 
 static const char * const buildid_list_usage[] = {
@@ -29,7 +29,7 @@ static const struct option options[] = {
        OPT_STRING('i', "input", &input_name, "file",
                    "input file name"),
        OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose"),
        OPT_END()
 };
@@ -39,14 +39,14 @@ static int __cmd_buildid_list(void)
        int err = -1;
        struct perf_session *session;
 
-       session = perf_session__new(input_name, O_RDONLY, force);
+       session = perf_session__new(input_name, O_RDONLY, force, false);
        if (session == NULL)
                return -1;
 
        if (with_hits)
                perf_session__process_events(session, &build_id__mark_dso_hit_ops);
 
-       dsos__fprintf_buildid(stdout, with_hits);
+       perf_session__fprintf_dsos_buildid(session, stdout, with_hits);
 
        perf_session__delete(session);
        return err;
index 1ea15d8..a6e2fdc 100644 (file)
 static char const *input_old = "perf.data.old",
                  *input_new = "perf.data";
 static char      diff__default_sort_order[] = "dso,symbol";
-static int  force;
+static bool  force;
 static bool show_displacement;
 
-static int perf_session__add_hist_entry(struct perf_session *self,
-                                       struct addr_location *al, u64 count)
+static int hists__add_entry(struct hists *self,
+                           struct addr_location *al, u64 period)
 {
-       bool hit;
-       struct hist_entry *he = __perf_session__add_hist_entry(&self->hists,
-                                                              al, NULL,
-                                                              count, &hit);
-       if (he == NULL)
-               return -ENOMEM;
-
-       if (hit)
-               he->count += count;
-
-       return 0;
+       if (__hists__add_entry(self, al, NULL, period) != NULL)
+               return 0;
+       return -ENOMEM;
 }
 
 static int diff__process_sample_event(event_t *event, struct perf_session *session)
@@ -57,12 +49,12 @@ static int diff__process_sample_event(event_t *event, struct perf_session *sessi
 
        event__parse_sample(event, session->sample_type, &data);
 
-       if (perf_session__add_hist_entry(session, &al, data.period)) {
-               pr_warning("problem incrementing symbol count, skipping event\n");
+       if (hists__add_entry(&session->hists, &al, data.period)) {
+               pr_warning("problem incrementing symbol period, skipping event\n");
                return -1;
        }
 
-       session->events_stats.total += data.period;
+       session->hists.stats.total_period += data.period;
        return 0;
 }
 
@@ -95,35 +87,34 @@ static void perf_session__insert_hist_entry_by_name(struct rb_root *root,
        rb_insert_color(&he->rb_node, root);
 }
 
-static void perf_session__resort_hist_entries(struct perf_session *self)
+static void hists__resort_entries(struct hists *self)
 {
        unsigned long position = 1;
        struct rb_root tmp = RB_ROOT;
-       struct rb_node *next = rb_first(&self->hists);
+       struct rb_node *next = rb_first(&self->entries);
 
        while (next != NULL) {
                struct hist_entry *n = rb_entry(next, struct hist_entry, rb_node);
 
                next = rb_next(&n->rb_node);
-               rb_erase(&n->rb_node, &self->hists);
+               rb_erase(&n->rb_node, &self->entries);
                n->position = position++;
                perf_session__insert_hist_entry_by_name(&tmp, n);
        }
 
-       self->hists = tmp;
+       self->entries = tmp;
 }
 
-static void perf_session__set_hist_entries_positions(struct perf_session *self)
+static void hists__set_positions(struct hists *self)
 {
-       perf_session__output_resort(&self->hists, self->events_stats.total);
-       perf_session__resort_hist_entries(self);
+       hists__output_resort(self);
+       hists__resort_entries(self);
 }
 
-static struct hist_entry *
-perf_session__find_hist_entry(struct perf_session *self,
-                             struct hist_entry *he)
+static struct hist_entry *hists__find_entry(struct hists *self,
+                                           struct hist_entry *he)
 {
-       struct rb_node *n = self->hists.rb_node;
+       struct rb_node *n = self->entries.rb_node;
 
        while (n) {
                struct hist_entry *iter = rb_entry(n, struct hist_entry, rb_node);
@@ -140,14 +131,13 @@ perf_session__find_hist_entry(struct perf_session *self,
        return NULL;
 }
 
-static void perf_session__match_hists(struct perf_session *old_session,
-                                     struct perf_session *new_session)
+static void hists__match(struct hists *older, struct hists *newer)
 {
        struct rb_node *nd;
 
-       for (nd = rb_first(&new_session->hists); nd; nd = rb_next(nd)) {
+       for (nd = rb_first(&newer->entries); nd; nd = rb_next(nd)) {
                struct hist_entry *pos = rb_entry(nd, struct hist_entry, rb_node);
-               pos->pair = perf_session__find_hist_entry(old_session, pos);
+               pos->pair = hists__find_entry(older, pos);
        }
 }
 
@@ -156,8 +146,8 @@ static int __cmd_diff(void)
        int ret, i;
        struct perf_session *session[2];
 
-       session[0] = perf_session__new(input_old, O_RDONLY, force);
-       session[1] = perf_session__new(input_new, O_RDONLY, force);
+       session[0] = perf_session__new(input_old, O_RDONLY, force, false);
+       session[1] = perf_session__new(input_new, O_RDONLY, force, false);
        if (session[0] == NULL || session[1] == NULL)
                return -ENOMEM;
 
@@ -167,15 +157,13 @@ static int __cmd_diff(void)
                        goto out_delete;
        }
 
-       perf_session__output_resort(&session[1]->hists,
-                                   session[1]->events_stats.total);
+       hists__output_resort(&session[1]->hists);
        if (show_displacement)
-               perf_session__set_hist_entries_positions(session[0]);
+               hists__set_positions(&session[0]->hists);
 
-       perf_session__match_hists(session[0], session[1]);
-       perf_session__fprintf_hists(&session[1]->hists, session[0],
-                                   show_displacement, stdout,
-                                   session[1]->events_stats.total);
+       hists__match(&session[0]->hists, &session[1]->hists);
+       hists__fprintf(&session[1]->hists, &session[0]->hists,
+                      show_displacement, stdout);
 out_delete:
        for (i = 0; i < 2; ++i)
                perf_session__delete(session[i]);
@@ -188,7 +176,7 @@ static const char * const diff_usage[] = {
 };
 
 static const struct option options[] = {
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('m', "displacement", &show_displacement,
                    "Show position displacement relative to baseline"),
@@ -225,6 +213,10 @@ int cmd_diff(int argc, const char **argv, const char *prefix __used)
                        input_new = argv[1];
                } else
                        input_new = argv[0];
+       } else if (symbol_conf.default_guest_vmlinux_name ||
+                  symbol_conf.default_guest_kallsyms) {
+               input_old = "perf.data.host";
+               input_new = "perf.data.guest";
        }
 
        symbol_conf.exclude_other = false;
index 215b584..6d5a8a7 100644 (file)
@@ -29,14 +29,14 @@ enum help_format {
        HELP_FORMAT_WEB,
 };
 
-static int show_all = 0;
+static bool show_all = false;
 static enum help_format help_format = HELP_FORMAT_MAN;
 static struct option builtin_help_options[] = {
        OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
-       OPT_SET_INT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
-       OPT_SET_INT('w', "web", &help_format, "show manual in web browser",
+       OPT_SET_UINT('m', "man", &help_format, "show man page", HELP_FORMAT_MAN),
+       OPT_SET_UINT('w', "web", &help_format, "show manual in web browser",
                        HELP_FORMAT_WEB),
-       OPT_SET_INT('i', "info", &help_format, "show info page",
+       OPT_SET_UINT('i', "info", &help_format, "show info page",
                        HELP_FORMAT_INFO),
        OPT_END(),
 };
diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
new file mode 100644 (file)
index 0000000..8e3e47b
--- /dev/null
@@ -0,0 +1,228 @@
+/*
+ * builtin-inject.c
+ *
+ * Builtin inject command: Examine the live mode (stdin) event stream
+ * and repipe it to stdout while optionally injecting additional
+ * events into it.
+ */
+#include "builtin.h"
+
+#include "perf.h"
+#include "util/session.h"
+#include "util/debug.h"
+
+#include "util/parse-options.h"
+
+static char            const *input_name = "-";
+static bool            inject_build_ids;
+
+static int event__repipe(event_t *event __used,
+                        struct perf_session *session __used)
+{
+       uint32_t size;
+       void *buf = event;
+
+       size = event->header.size;
+
+       while (size) {
+               int ret = write(STDOUT_FILENO, buf, size);
+               if (ret < 0)
+                       return -errno;
+
+               size -= ret;
+               buf += ret;
+       }
+
+       return 0;
+}
+
+static int event__repipe_mmap(event_t *self, struct perf_session *session)
+{
+       int err;
+
+       err = event__process_mmap(self, session);
+       event__repipe(self, session);
+
+       return err;
+}
+
+static int event__repipe_task(event_t *self, struct perf_session *session)
+{
+       int err;
+
+       err = event__process_task(self, session);
+       event__repipe(self, session);
+
+       return err;
+}
+
+static int event__repipe_tracing_data(event_t *self,
+                                     struct perf_session *session)
+{
+       int err;
+
+       event__repipe(self, session);
+       err = event__process_tracing_data(self, session);
+
+       return err;
+}
+
+static int dso__read_build_id(struct dso *self)
+{
+       if (self->has_build_id)
+               return 0;
+
+       if (filename__read_build_id(self->long_name, self->build_id,
+                                   sizeof(self->build_id)) > 0) {
+               self->has_build_id = true;
+               return 0;
+       }
+
+       return -1;
+}
+
+static int dso__inject_build_id(struct dso *self, struct perf_session *session)
+{
+       u16 misc = PERF_RECORD_MISC_USER;
+       struct machine *machine;
+       int err;
+
+       if (dso__read_build_id(self) < 0) {
+               pr_debug("no build_id found for %s\n", self->long_name);
+               return -1;
+       }
+
+       machine = perf_session__find_host_machine(session);
+       if (machine == NULL) {
+               pr_err("Can't find machine for session\n");
+               return -1;
+       }
+
+       if (self->kernel)
+               misc = PERF_RECORD_MISC_KERNEL;
+
+       err = event__synthesize_build_id(self, misc, event__repipe,
+                                        machine, session);
+       if (err) {
+               pr_err("Can't synthesize build_id event for %s\n", self->long_name);
+               return -1;
+       }
+
+       return 0;
+}
+
+static int event__inject_buildid(event_t *event, struct perf_session *session)
+{
+       struct addr_location al;
+       struct thread *thread;
+       u8 cpumode;
+
+       cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+
+       thread = perf_session__findnew(session, event->ip.pid);
+       if (thread == NULL) {
+               pr_err("problem processing %d event, skipping it.\n",
+                      event->header.type);
+               goto repipe;
+       }
+
+       thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
+                             event->ip.pid, event->ip.ip, &al);
+
+       if (al.map != NULL) {
+               if (!al.map->dso->hit) {
+                       al.map->dso->hit = 1;
+                       if (map__load(al.map, NULL) >= 0) {
+                               dso__inject_build_id(al.map->dso, session);
+                               /*
+                                * If this fails, too bad, let the other side
+                                * account this as unresolved.
+                                */
+                       } else
+                               pr_warning("no symbols found in %s, maybe "
+                                          "install a debug package?\n",
+                                          al.map->dso->long_name);
+               }
+       }
+
+repipe:
+       event__repipe(event, session);
+       return 0;
+}
+
+struct perf_event_ops inject_ops = {
+       .sample         = event__repipe,
+       .mmap           = event__repipe,
+       .comm           = event__repipe,
+       .fork           = event__repipe,
+       .exit           = event__repipe,
+       .lost           = event__repipe,
+       .read           = event__repipe,
+       .throttle       = event__repipe,
+       .unthrottle     = event__repipe,
+       .attr           = event__repipe,
+       .event_type     = event__repipe,
+       .tracing_data   = event__repipe,
+       .build_id       = event__repipe,
+};
+
+extern volatile int session_done;
+
+static void sig_handler(int sig __attribute__((__unused__)))
+{
+       session_done = 1;
+}
+
+static int __cmd_inject(void)
+{
+       struct perf_session *session;
+       int ret = -EINVAL;
+
+       signal(SIGINT, sig_handler);
+
+       if (inject_build_ids) {
+               inject_ops.sample       = event__inject_buildid;
+               inject_ops.mmap         = event__repipe_mmap;
+               inject_ops.fork         = event__repipe_task;
+               inject_ops.tracing_data = event__repipe_tracing_data;
+       }
+
+       session = perf_session__new(input_name, O_RDONLY, false, true);
+       if (session == NULL)
+               return -ENOMEM;
+
+       ret = perf_session__process_events(session, &inject_ops);
+
+       perf_session__delete(session);
+
+       return ret;
+}
+
+static const char * const report_usage[] = {
+       "perf inject [<options>]",
+       NULL
+};
+
+static const struct option options[] = {
+       OPT_BOOLEAN('b', "build-ids", &inject_build_ids,
+                   "Inject build-ids into the output stream"),
+       OPT_INCR('v', "verbose", &verbose,
+                "be more verbose (show build ids, etc)"),
+       OPT_END()
+};
+
+int cmd_inject(int argc, const char **argv, const char *prefix __used)
+{
+       argc = parse_options(argc, argv, options, report_usage, 0);
+
+       /*
+        * Any (unrecognized) arguments left?
+        */
+       if (argc)
+               usage_with_options(report_usage, options);
+
+       if (symbol__init() < 0)
+               return -1;
+
+       return __cmd_inject();
+}
index 924a951..31f60a2 100644 (file)
@@ -335,8 +335,9 @@ static int process_sample_event(event_t *event, struct perf_session *session)
 }
 
 static struct perf_event_ops event_ops = {
-       .sample = process_sample_event,
-       .comm   = event__process_comm,
+       .sample                 = process_sample_event,
+       .comm                   = event__process_comm,
+       .ordered_samples        = true,
 };
 
 static double fragmentation(unsigned long n_req, unsigned long n_alloc)
@@ -351,6 +352,7 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
                           int n_lines, int is_caller)
 {
        struct rb_node *next;
+       struct machine *machine;
 
        printf("%.102s\n", graph_dotted_line);
        printf(" %-34s |",  is_caller ? "Callsite": "Alloc Ptr");
@@ -359,23 +361,29 @@ static void __print_result(struct rb_root *root, struct perf_session *session,
 
        next = rb_first(root);
 
+       machine = perf_session__find_host_machine(session);
+       if (!machine) {
+               pr_err("__print_result: couldn't find kernel information\n");
+               return;
+       }
        while (next && n_lines--) {
                struct alloc_stat *data = rb_entry(next, struct alloc_stat,
                                                   node);
                struct symbol *sym = NULL;
+               struct map *map;
                char buf[BUFSIZ];
                u64 addr;
 
                if (is_caller) {
                        addr = data->call_site;
                        if (!raw_ip)
-                               sym = map_groups__find_function(&session->kmaps, addr, NULL);
+                               sym = machine__find_kernel_function(machine, addr, &map, NULL);
                } else
                        addr = data->ptr;
 
                if (sym != NULL)
                        snprintf(buf, sizeof(buf), "%s+%Lx", sym->name,
-                                addr - sym->start);
+                                addr - map->unmap_ip(map, sym->start));
                else
                        snprintf(buf, sizeof(buf), "%#Lx", addr);
                printf(" %-34s |", buf);
@@ -484,10 +492,13 @@ static void sort_result(void)
 static int __cmd_kmem(void)
 {
        int err = -EINVAL;
-       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
        if (session == NULL)
                return -ENOMEM;
 
+       if (perf_session__create_kernel_maps(session) < 0)
+               goto out_delete;
+
        if (!perf_session__has_traces(session, "kmem record"))
                goto out_delete;
 
@@ -718,7 +729,6 @@ static const char *record_args[] = {
        "record",
        "-a",
        "-R",
-       "-M",
        "-f",
        "-c", "1",
        "-e", "kmem:kmalloc",
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
new file mode 100644 (file)
index 0000000..34d1e85
--- /dev/null
@@ -0,0 +1,144 @@
+#include "builtin.h"
+#include "perf.h"
+
+#include "util/util.h"
+#include "util/cache.h"
+#include "util/symbol.h"
+#include "util/thread.h"
+#include "util/header.h"
+#include "util/session.h"
+
+#include "util/parse-options.h"
+#include "util/trace-event.h"
+
+#include "util/debug.h"
+
+#include <sys/prctl.h>
+
+#include <semaphore.h>
+#include <pthread.h>
+#include <math.h>
+
+static const char              *file_name;
+static char                    name_buffer[256];
+
+bool                           perf_host = 1;
+bool                           perf_guest;
+
+static const char * const kvm_usage[] = {
+       "perf kvm [<options>] {top|record|report|diff|buildid-list}",
+       NULL
+};
+
+static const struct option kvm_options[] = {
+       OPT_STRING('i', "input", &file_name, "file",
+                  "Input file name"),
+       OPT_STRING('o', "output", &file_name, "file",
+                  "Output file name"),
+       OPT_BOOLEAN(0, "guest", &perf_guest,
+                   "Collect guest os data"),
+       OPT_BOOLEAN(0, "host", &perf_host,
+                   "Collect guest os data"),
+       OPT_STRING(0, "guestmount", &symbol_conf.guestmount, "directory",
+                  "guest mount directory under which every guest os"
+                  " instance has a subdir"),
+       OPT_STRING(0, "guestvmlinux", &symbol_conf.default_guest_vmlinux_name,
+                  "file", "file saving guest os vmlinux"),
+       OPT_STRING(0, "guestkallsyms", &symbol_conf.default_guest_kallsyms,
+                  "file", "file saving guest os /proc/kallsyms"),
+       OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules,
+                  "file", "file saving guest os /proc/modules"),
+       OPT_END()
+};
+
+static int __cmd_record(int argc, const char **argv)
+{
+       int rec_argc, i = 0, j;
+       const char **rec_argv;
+
+       rec_argc = argc + 2;
+       rec_argv = calloc(rec_argc + 1, sizeof(char *));
+       rec_argv[i++] = strdup("record");
+       rec_argv[i++] = strdup("-o");
+       rec_argv[i++] = strdup(file_name);
+       for (j = 1; j < argc; j++, i++)
+               rec_argv[i] = argv[j];
+
+       BUG_ON(i != rec_argc);
+
+       return cmd_record(i, rec_argv, NULL);
+}
+
+static int __cmd_report(int argc, const char **argv)
+{
+       int rec_argc, i = 0, j;
+       const char **rec_argv;
+
+       rec_argc = argc + 2;
+       rec_argv = calloc(rec_argc + 1, sizeof(char *));
+       rec_argv[i++] = strdup("report");
+       rec_argv[i++] = strdup("-i");
+       rec_argv[i++] = strdup(file_name);
+       for (j = 1; j < argc; j++, i++)
+               rec_argv[i] = argv[j];
+
+       BUG_ON(i != rec_argc);
+
+       return cmd_report(i, rec_argv, NULL);
+}
+
+static int __cmd_buildid_list(int argc, const char **argv)
+{
+       int rec_argc, i = 0, j;
+       const char **rec_argv;
+
+       rec_argc = argc + 2;
+       rec_argv = calloc(rec_argc + 1, sizeof(char *));
+       rec_argv[i++] = strdup("buildid-list");
+       rec_argv[i++] = strdup("-i");
+       rec_argv[i++] = strdup(file_name);
+       for (j = 1; j < argc; j++, i++)
+               rec_argv[i] = argv[j];
+
+       BUG_ON(i != rec_argc);
+
+       return cmd_buildid_list(i, rec_argv, NULL);
+}
+
+int cmd_kvm(int argc, const char **argv, const char *prefix __used)
+{
+       perf_host = perf_guest = 0;
+
+       argc = parse_options(argc, argv, kvm_options, kvm_usage,
+                       PARSE_OPT_STOP_AT_NON_OPTION);
+       if (!argc)
+               usage_with_options(kvm_usage, kvm_options);
+
+       if (!perf_host)
+               perf_guest = 1;
+
+       if (!file_name) {
+               if (perf_host && !perf_guest)
+                       sprintf(name_buffer, "perf.data.host");
+               else if (!perf_host && perf_guest)
+                       sprintf(name_buffer, "perf.data.guest");
+               else
+                       sprintf(name_buffer, "perf.data.kvm");
+               file_name = name_buffer;
+       }
+
+       if (!strncmp(argv[0], "rec", 3))
+               return __cmd_record(argc, argv);
+       else if (!strncmp(argv[0], "rep", 3))
+               return __cmd_report(argc, argv);
+       else if (!strncmp(argv[0], "diff", 4))
+               return cmd_diff(argc, argv, NULL);
+       else if (!strncmp(argv[0], "top", 3))
+               return cmd_top(argc, argv, NULL);
+       else if (!strncmp(argv[0], "buildid-list", 12))
+               return __cmd_buildid_list(argc, argv);
+       else
+               usage_with_options(kvm_usage, kvm_options);
+
+       return 0;
+}
index e12c844..821c158 100644 (file)
@@ -23,6 +23,8 @@
 #include <linux/list.h>
 #include <linux/hash.h>
 
+static struct perf_session *session;
+
 /* based on kernel/lockdep.c */
 #define LOCKHASH_BITS          12
 #define LOCKHASH_SIZE          (1UL << LOCKHASH_BITS)
@@ -32,9 +34,6 @@ static struct list_head lockhash_table[LOCKHASH_SIZE];
 #define __lockhashfn(key)      hash_long((unsigned long)key, LOCKHASH_BITS)
 #define lockhashentry(key)     (lockhash_table + __lockhashfn((key)))
 
-#define LOCK_STATE_UNLOCKED    0              /* initial state */
-#define LOCK_STATE_LOCKED      1
-
 struct lock_stat {
        struct list_head        hash_entry;
        struct rb_node          rb;             /* used for sorting */
@@ -47,20 +46,151 @@ struct lock_stat {
        void                    *addr;          /* address of lockdep_map, used as ID */
        char                    *name;          /* for strcpy(), we cannot use const */
 
-       int                     state;
-       u64                     prev_event_time; /* timestamp of previous event */
-
-       unsigned int            nr_acquired;
        unsigned int            nr_acquire;
+       unsigned int            nr_acquired;
        unsigned int            nr_contended;
        unsigned int            nr_release;
 
+       unsigned int            nr_readlock;
+       unsigned int            nr_trylock;
        /* these times are in nano sec. */
        u64                     wait_time_total;
        u64                     wait_time_min;
        u64                     wait_time_max;
+
+       int                     discard; /* flag of blacklist */
 };
 
+/*
+ * States of lock_seq_stat
+ *
+ * UNINITIALIZED is required for detecting first event of acquire.
+ * As the nature of lock events, there is no guarantee
+ * that the first event for the locks are acquire,
+ * it can be acquired, contended or release.
+ */
+#define SEQ_STATE_UNINITIALIZED      0        /* initial state */
+#define SEQ_STATE_RELEASED     1
+#define SEQ_STATE_ACQUIRING    2
+#define SEQ_STATE_ACQUIRED     3
+#define SEQ_STATE_READ_ACQUIRED        4
+#define SEQ_STATE_CONTENDED    5
+
+/*
+ * MAX_LOCK_DEPTH
+ * Imported from include/linux/sched.h.
+ * Should this be synchronized?
+ */
+#define MAX_LOCK_DEPTH 48
+
+/*
+ * struct lock_seq_stat:
+ * Place to put on state of one lock sequence
+ * 1) acquire -> acquired -> release
+ * 2) acquire -> contended -> acquired -> release
+ * 3) acquire (with read or try) -> release
+ * 4) Are there other patterns?
+ */
+struct lock_seq_stat {
+       struct list_head        list;
+       int                     state;
+       u64                     prev_event_time;
+       void                    *addr;
+
+       int                     read_count;
+};
+
+struct thread_stat {
+       struct rb_node          rb;
+
+       u32                     tid;
+       struct list_head        seq_list;
+};
+
+static struct rb_root          thread_stats;
+
+static struct thread_stat *thread_stat_find(u32 tid)
+{
+       struct rb_node *node;
+       struct thread_stat *st;
+
+       node = thread_stats.rb_node;
+       while (node) {
+               st = container_of(node, struct thread_stat, rb);
+               if (st->tid == tid)
+                       return st;
+               else if (tid < st->tid)
+                       node = node->rb_left;
+               else
+                       node = node->rb_right;
+       }
+
+       return NULL;
+}
+
+static void thread_stat_insert(struct thread_stat *new)
+{
+       struct rb_node **rb = &thread_stats.rb_node;
+       struct rb_node *parent = NULL;
+       struct thread_stat *p;
+
+       while (*rb) {
+               p = container_of(*rb, struct thread_stat, rb);
+               parent = *rb;
+
+               if (new->tid < p->tid)
+                       rb = &(*rb)->rb_left;
+               else if (new->tid > p->tid)
+                       rb = &(*rb)->rb_right;
+               else
+                       BUG_ON("inserting invalid thread_stat\n");
+       }
+
+       rb_link_node(&new->rb, parent, rb);
+       rb_insert_color(&new->rb, &thread_stats);
+}
+
+static struct thread_stat *thread_stat_findnew_after_first(u32 tid)
+{
+       struct thread_stat *st;
+
+       st = thread_stat_find(tid);
+       if (st)
+               return st;
+
+       st = zalloc(sizeof(struct thread_stat));
+       if (!st)
+               die("memory allocation failed\n");
+
+       st->tid = tid;
+       INIT_LIST_HEAD(&st->seq_list);
+
+       thread_stat_insert(st);
+
+       return st;
+}
+
+static struct thread_stat *thread_stat_findnew_first(u32 tid);
+static struct thread_stat *(*thread_stat_findnew)(u32 tid) =
+       thread_stat_findnew_first;
+
+static struct thread_stat *thread_stat_findnew_first(u32 tid)
+{
+       struct thread_stat *st;
+
+       st = zalloc(sizeof(struct thread_stat));
+       if (!st)
+               die("memory allocation failed\n");
+       st->tid = tid;
+       INIT_LIST_HEAD(&st->seq_list);
+
+       rb_link_node(&st->rb, NULL, &thread_stats.rb_node);
+       rb_insert_color(&st->rb, &thread_stats);
+
+       thread_stat_findnew = thread_stat_findnew_after_first;
+       return st;
+}
+
 /* build simple key function one is bigger than two */
 #define SINGLE_KEY(member)                                             \
        static int lock_stat_key_ ## member(struct lock_stat *one,      \
@@ -175,8 +305,6 @@ static struct lock_stat *lock_stat_findnew(void *addr, const char *name)
                goto alloc_failed;
        strcpy(new->name, name);
 
-       /* LOCK_STATE_UNLOCKED == 0 isn't guaranteed forever */
-       new->state = LOCK_STATE_UNLOCKED;
        new->wait_time_min = ULLONG_MAX;
 
        list_add(&new->hash_entry, entry);
@@ -188,8 +316,6 @@ alloc_failed:
 
 static char                    const *input_name = "perf.data";
 
-static int                     profile_cpu = -1;
-
 struct raw_event_sample {
        u32                     size;
        char                    data[0];
@@ -198,6 +324,7 @@ struct raw_event_sample {
 struct trace_acquire_event {
        void                    *addr;
        const char              *name;
+       int                     flag;
 };
 
 struct trace_acquired_event {
@@ -241,120 +368,258 @@ struct trace_lock_handler {
                              struct thread *thread);
 };
 
+static struct lock_seq_stat *get_seq(struct thread_stat *ts, void *addr)
+{
+       struct lock_seq_stat *seq;
+
+       list_for_each_entry(seq, &ts->seq_list, list) {
+               if (seq->addr == addr)
+                       return seq;
+       }
+
+       seq = zalloc(sizeof(struct lock_seq_stat));
+       if (!seq)
+               die("Not enough memory\n");
+       seq->state = SEQ_STATE_UNINITIALIZED;
+       seq->addr = addr;
+
+       list_add(&seq->list, &ts->seq_list);
+       return seq;
+}
+
+enum broken_state {
+       BROKEN_ACQUIRE,
+       BROKEN_ACQUIRED,
+       BROKEN_CONTENDED,
+       BROKEN_RELEASE,
+       BROKEN_MAX,
+};
+
+static int bad_hist[BROKEN_MAX];
+
+enum acquire_flags {
+       TRY_LOCK = 1,
+       READ_LOCK = 2,
+};
+
 static void
 report_lock_acquire_event(struct trace_acquire_event *acquire_event,
                        struct event *__event __used,
                        int cpu __used,
-                       u64 timestamp,
+                       u64 timestamp __used,
                        struct thread *thread __used)
 {
-       struct lock_stat *st;
+       struct lock_stat *ls;
+       struct thread_stat *ts;
+       struct lock_seq_stat *seq;
+
+       ls = lock_stat_findnew(acquire_event->addr, acquire_event->name);
+       if (ls->discard)
+               return;
 
-       st = lock_stat_findnew(acquire_event->addr, acquire_event->name);
+       ts = thread_stat_findnew(thread->pid);
+       seq = get_seq(ts, acquire_event->addr);
 
-       switch (st->state) {
-       case LOCK_STATE_UNLOCKED:
+       switch (seq->state) {
+       case SEQ_STATE_UNINITIALIZED:
+       case SEQ_STATE_RELEASED:
+               if (!acquire_event->flag) {
+                       seq->state = SEQ_STATE_ACQUIRING;
+               } else {
+                       if (acquire_event->flag & TRY_LOCK)
+                               ls->nr_trylock++;
+                       if (acquire_event->flag & READ_LOCK)
+                               ls->nr_readlock++;
+                       seq->state = SEQ_STATE_READ_ACQUIRED;
+                       seq->read_count = 1;
+                       ls->nr_acquired++;
+               }
+               break;
+       case SEQ_STATE_READ_ACQUIRED:
+               if (acquire_event->flag & READ_LOCK) {
+                       seq->read_count++;
+                       ls->nr_acquired++;
+                       goto end;
+               } else {
+                       goto broken;
+               }
                break;
-       case LOCK_STATE_LOCKED:
+       case SEQ_STATE_ACQUIRED:
+       case SEQ_STATE_ACQUIRING:
+       case SEQ_STATE_CONTENDED:
+broken:
+               /* broken lock sequence, discard it */
+               ls->discard = 1;
+               bad_hist[BROKEN_ACQUIRE]++;
+               list_del(&seq->list);
+               free(seq);
+               goto end;
                break;
        default:
-               BUG_ON(1);
+               BUG_ON("Unknown state of lock sequence found!\n");
                break;
        }
 
-       st->prev_event_time = timestamp;
+       ls->nr_acquire++;
+       seq->prev_event_time = timestamp;
+end:
+       return;
 }
 
 static void
 report_lock_acquired_event(struct trace_acquired_event *acquired_event,
                         struct event *__event __used,
                         int cpu __used,
-                        u64 timestamp,
+                        u64 timestamp __used,
                         struct thread *thread __used)
 {
-       struct lock_stat *st;
+       struct lock_stat *ls;
+       struct thread_stat *ts;
+       struct lock_seq_stat *seq;
+       u64 contended_term;
+
+       ls = lock_stat_findnew(acquired_event->addr, acquired_event->name);
+       if (ls->discard)
+               return;
 
-       st = lock_stat_findnew(acquired_event->addr, acquired_event->name);
+       ts = thread_stat_findnew(thread->pid);
+       seq = get_seq(ts, acquired_event->addr);
 
-       switch (st->state) {
-       case LOCK_STATE_UNLOCKED:
-               st->state = LOCK_STATE_LOCKED;
-               st->nr_acquired++;
+       switch (seq->state) {
+       case SEQ_STATE_UNINITIALIZED:
+               /* orphan event, do nothing */
+               return;
+       case SEQ_STATE_ACQUIRING:
+               break;
+       case SEQ_STATE_CONTENDED:
+               contended_term = timestamp - seq->prev_event_time;
+               ls->wait_time_total += contended_term;
+               if (contended_term < ls->wait_time_min)
+                       ls->wait_time_min = contended_term;
+               if (ls->wait_time_max < contended_term)
+                       ls->wait_time_max = contended_term;
                break;
-       case LOCK_STATE_LOCKED:
+       case SEQ_STATE_RELEASED:
+       case SEQ_STATE_ACQUIRED:
+       case SEQ_STATE_READ_ACQUIRED:
+               /* broken lock sequence, discard it */
+               ls->discard = 1;
+               bad_hist[BROKEN_ACQUIRED]++;
+               list_del(&seq->list);
+               free(seq);
+               goto end;
                break;
+
        default:
-               BUG_ON(1);
+               BUG_ON("Unknown state of lock sequence found!\n");
                break;
        }
 
-       st->prev_event_time = timestamp;
+       seq->state = SEQ_STATE_ACQUIRED;
+       ls->nr_acquired++;
+       seq->prev_event_time = timestamp;
+end:
+       return;
 }
 
 static void
 report_lock_contended_event(struct trace_contended_event *contended_event,
                          struct event *__event __used,
                          int cpu __used,
-                         u64 timestamp,
+                         u64 timestamp __used,
                          struct thread *thread __used)
 {
-       struct lock_stat *st;
+       struct lock_stat *ls;
+       struct thread_stat *ts;
+       struct lock_seq_stat *seq;
 
-       st = lock_stat_findnew(contended_event->addr, contended_event->name);
+       ls = lock_stat_findnew(contended_event->addr, contended_event->name);
+       if (ls->discard)
+               return;
 
-       switch (st->state) {
-       case LOCK_STATE_UNLOCKED:
+       ts = thread_stat_findnew(thread->pid);
+       seq = get_seq(ts, contended_event->addr);
+
+       switch (seq->state) {
+       case SEQ_STATE_UNINITIALIZED:
+               /* orphan event, do nothing */
+               return;
+       case SEQ_STATE_ACQUIRING:
                break;
-       case LOCK_STATE_LOCKED:
-               st->nr_contended++;
+       case SEQ_STATE_RELEASED:
+       case SEQ_STATE_ACQUIRED:
+       case SEQ_STATE_READ_ACQUIRED:
+       case SEQ_STATE_CONTENDED:
+               /* broken lock sequence, discard it */
+               ls->discard = 1;
+               bad_hist[BROKEN_CONTENDED]++;
+               list_del(&seq->list);
+               free(seq);
+               goto end;
                break;
        default:
-               BUG_ON(1);
+               BUG_ON("Unknown state of lock sequence found!\n");
                break;
        }
 
-       st->prev_event_time = timestamp;
+       seq->state = SEQ_STATE_CONTENDED;
+       ls->nr_contended++;
+       seq->prev_event_time = timestamp;
+end:
+       return;
 }
 
 static void
 report_lock_release_event(struct trace_release_event *release_event,
                        struct event *__event __used,
                        int cpu __used,
-                       u64 timestamp,
+                       u64 timestamp __used,
                        struct thread *thread __used)
 {
-       struct lock_stat *st;
-       u64 hold_time;
+       struct lock_stat *ls;
+       struct thread_stat *ts;
+       struct lock_seq_stat *seq;
 
-       st = lock_stat_findnew(release_event->addr, release_event->name);
+       ls = lock_stat_findnew(release_event->addr, release_event->name);
+       if (ls->discard)
+               return;
 
-       switch (st->state) {
-       case LOCK_STATE_UNLOCKED:
-               break;
-       case LOCK_STATE_LOCKED:
-               st->state = LOCK_STATE_UNLOCKED;
-               hold_time = timestamp - st->prev_event_time;
+       ts = thread_stat_findnew(thread->pid);
+       seq = get_seq(ts, release_event->addr);
 
-               if (timestamp < st->prev_event_time) {
-                       /* terribly, this can happen... */
+       switch (seq->state) {
+       case SEQ_STATE_UNINITIALIZED:
+               goto end;
+               break;
+       case SEQ_STATE_ACQUIRED:
+               break;
+       case SEQ_STATE_READ_ACQUIRED:
+               seq->read_count--;
+               BUG_ON(seq->read_count < 0);
+               if (!seq->read_count) {
+                       ls->nr_release++;
                        goto end;
                }
-
-               if (st->wait_time_min > hold_time)
-                       st->wait_time_min = hold_time;
-               if (st->wait_time_max < hold_time)
-                       st->wait_time_max = hold_time;
-               st->wait_time_total += hold_time;
-
-               st->nr_release++;
+               break;
+       case SEQ_STATE_ACQUIRING:
+       case SEQ_STATE_CONTENDED:
+       case SEQ_STATE_RELEASED:
+               /* broken lock sequence, discard it */
+               ls->discard = 1;
+               bad_hist[BROKEN_RELEASE]++;
+               goto free_seq;
                break;
        default:
-               BUG_ON(1);
+               BUG_ON("Unknown state of lock sequence found!\n");
                break;
        }
 
+       ls->nr_release++;
+free_seq:
+       list_del(&seq->list);
+       free(seq);
 end:
-       st->prev_event_time = timestamp;
+       return;
 }
 
 /* lock oriented handlers */
@@ -381,6 +646,7 @@ process_lock_acquire_event(void *data,
        tmp = raw_field_value(event, "lockdep_addr", data);
        memcpy(&acquire_event.addr, &tmp, sizeof(void *));
        acquire_event.name = (char *)raw_field_ptr(event, "name", data);
+       acquire_event.flag = (int)raw_field_value(event, "flag", data);
 
        if (trace_handler->acquire_event)
                trace_handler->acquire_event(&acquire_event, event, cpu, timestamp, thread);
@@ -441,8 +707,7 @@ process_lock_release_event(void *data,
 }
 
 static void
-process_raw_event(void *data, int cpu,
-                 u64 timestamp, struct thread *thread)
+process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread)
 {
        struct event *event;
        int type;
@@ -460,173 +725,19 @@ process_raw_event(void *data, int cpu,
                process_lock_release_event(data, event, cpu, timestamp, thread);
 }
 
-struct raw_event_queue {
-       u64                     timestamp;
-       int                     cpu;
-       void                    *data;
-       struct thread           *thread;
-       struct list_head        list;
-};
-
-static LIST_HEAD(raw_event_head);
-
-#define FLUSH_PERIOD   (5 * NSEC_PER_SEC)
-
-static u64 flush_limit = ULLONG_MAX;
-static u64 last_flush = 0;
-struct raw_event_queue *last_inserted;
-
-static void flush_raw_event_queue(u64 limit)
-{
-       struct raw_event_queue *tmp, *iter;
-
-       list_for_each_entry_safe(iter, tmp, &raw_event_head, list) {
-               if (iter->timestamp > limit)
-                       return;
-
-               if (iter == last_inserted)
-                       last_inserted = NULL;
-
-               process_raw_event(iter->data, iter->cpu, iter->timestamp,
-                                 iter->thread);
-
-               last_flush = iter->timestamp;
-               list_del(&iter->list);
-               free(iter->data);
-               free(iter);
-       }
-}
-
-static void __queue_raw_event_end(struct raw_event_queue *new)
-{
-       struct raw_event_queue *iter;
-
-       list_for_each_entry_reverse(iter, &raw_event_head, list) {
-               if (iter->timestamp < new->timestamp) {
-                       list_add(&new->list, &iter->list);
-                       return;
-               }
-       }
-
-       list_add(&new->list, &raw_event_head);
-}
-
-static void __queue_raw_event_before(struct raw_event_queue *new,
-                                    struct raw_event_queue *iter)
+static void print_bad_events(int bad, int total)
 {
-       list_for_each_entry_continue_reverse(iter, &raw_event_head, list) {
-               if (iter->timestamp < new->timestamp) {
-                       list_add(&new->list, &iter->list);
-                       return;
-               }
-       }
-
-       list_add(&new->list, &raw_event_head);
-}
-
-static void __queue_raw_event_after(struct raw_event_queue *new,
-                                    struct raw_event_queue *iter)
-{
-       list_for_each_entry_continue(iter, &raw_event_head, list) {
-               if (iter->timestamp > new->timestamp) {
-                       list_add_tail(&new->list, &iter->list);
-                       return;
-               }
-       }
-       list_add_tail(&new->list, &raw_event_head);
-}
-
-/* The queue is ordered by time */
-static void __queue_raw_event(struct raw_event_queue *new)
-{
-       if (!last_inserted) {
-               __queue_raw_event_end(new);
-               return;
-       }
-
-       /*
-        * Most of the time the current event has a timestamp
-        * very close to the last event inserted, unless we just switched
-        * to another event buffer. Having a sorting based on a list and
-        * on the last inserted event that is close to the current one is
-        * probably more efficient than an rbtree based sorting.
-        */
-       if (last_inserted->timestamp >= new->timestamp)
-               __queue_raw_event_before(new, last_inserted);
-       else
-               __queue_raw_event_after(new, last_inserted);
-}
-
-static void queue_raw_event(void *data, int raw_size, int cpu,
-                           u64 timestamp, struct thread *thread)
-{
-       struct raw_event_queue *new;
-
-       if (flush_limit == ULLONG_MAX)
-               flush_limit = timestamp + FLUSH_PERIOD;
-
-       if (timestamp < last_flush) {
-               printf("Warning: Timestamp below last timeslice flush\n");
-               return;
-       }
-
-       new = malloc(sizeof(*new));
-       if (!new)
-               die("Not enough memory\n");
-
-       new->timestamp = timestamp;
-       new->cpu = cpu;
-       new->thread = thread;
-
-       new->data = malloc(raw_size);
-       if (!new->data)
-               die("Not enough memory\n");
-
-       memcpy(new->data, data, raw_size);
-
-       __queue_raw_event(new);
-       last_inserted = new;
-
-       /*
-        * We want to have a slice of events covering 2 * FLUSH_PERIOD
-        * If FLUSH_PERIOD is big enough, it ensures every events that occured
-        * in the first half of the timeslice have all been buffered and there
-        * are none remaining (we need that because of the weakly ordered
-        * event recording we have). Then once we reach the 2 * FLUSH_PERIOD
-        * timeslice, we flush the first half to be gentle with the memory
-        * (the second half can still get new events in the middle, so wait
-        * another period to flush it)
-        */
-       if (new->timestamp > flush_limit &&
-               new->timestamp - flush_limit > FLUSH_PERIOD) {
-               flush_limit += FLUSH_PERIOD;
-               flush_raw_event_queue(flush_limit);
-       }
-}
-
-static int process_sample_event(event_t *event, struct perf_session *session)
-{
-       struct thread *thread;
-       struct sample_data data;
-
-       bzero(&data, sizeof(struct sample_data));
-       event__parse_sample(event, session->sample_type, &data);
-       thread = perf_session__findnew(session, data.pid);
-
-       if (thread == NULL) {
-               pr_debug("problem processing %d event, skipping it.\n",
-                        event->header.type);
-               return -1;
-       }
-
-       dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
-
-       if (profile_cpu != -1 && profile_cpu != (int) data.cpu)
-               return 0;
-
-       queue_raw_event(data.raw_data, data.raw_size, data.cpu, data.time, thread);
-
-       return 0;
+       /* Output for debug, this have to be removed */
+       int i;
+       const char *name[4] =
+               { "acquire", "acquired", "contended", "release" };
+
+       pr_info("\n=== output for debug===\n\n");
+       pr_info("bad: %d, total: %d\n", bad, total);
+       pr_info("bad rate: %f %%\n", (double)bad / (double)total * 100);
+       pr_info("histogram of events caused bad sequence\n");
+       for (i = 0; i < BROKEN_MAX; i++)
+               pr_info(" %10s: %d\n", name[i], bad_hist[i]);
 }
 
 /* TODO: various way to print, coloring, nano or milli sec */
@@ -634,26 +745,30 @@ static void print_result(void)
 {
        struct lock_stat *st;
        char cut_name[20];
+       int bad, total;
 
-       printf("%18s ", "ID");
-       printf("%20s ", "Name");
-       printf("%10s ", "acquired");
-       printf("%10s ", "contended");
+       pr_info("%20s ", "Name");
+       pr_info("%10s ", "acquired");
+       pr_info("%10s ", "contended");
 
-       printf("%15s ", "total wait (ns)");
-       printf("%15s ", "max wait (ns)");
-       printf("%15s ", "min wait (ns)");
+       pr_info("%15s ", "total wait (ns)");
+       pr_info("%15s ", "max wait (ns)");
+       pr_info("%15s ", "min wait (ns)");
 
-       printf("\n\n");
+       pr_info("\n\n");
 
+       bad = total = 0;
        while ((st = pop_from_result())) {
+               total++;
+               if (st->discard) {
+                       bad++;
+                       continue;
+               }
                bzero(cut_name, 20);
 
-               printf("%p ", st->addr);
-
                if (strlen(st->name) < 16) {
                        /* output raw name */
-                       printf("%20s ", st->name);
+                       pr_info("%20s ", st->name);
                } else {
                        strncpy(cut_name, st->name, 16);
                        cut_name[16] = '.';
@@ -661,18 +776,39 @@ static void print_result(void)
                        cut_name[18] = '.';
                        cut_name[19] = '\0';
                        /* cut off name for saving output style */
-                       printf("%20s ", cut_name);
+                       pr_info("%20s ", cut_name);
                }
 
-               printf("%10u ", st->nr_acquired);
-               printf("%10u ", st->nr_contended);
+               pr_info("%10u ", st->nr_acquired);
+               pr_info("%10u ", st->nr_contended);
 
-               printf("%15llu ", st->wait_time_total);
-               printf("%15llu ", st->wait_time_max);
-               printf("%15llu ", st->wait_time_min == ULLONG_MAX ?
+               pr_info("%15llu ", st->wait_time_total);
+               pr_info("%15llu ", st->wait_time_max);
+               pr_info("%15llu ", st->wait_time_min == ULLONG_MAX ?
                       0 : st->wait_time_min);
-               printf("\n");
+               pr_info("\n");
        }
+
+       print_bad_events(bad, total);
+}
+
+static bool info_threads, info_map;
+
+static void dump_threads(void)
+{
+       struct thread_stat *st;
+       struct rb_node *node;
+       struct thread *t;
+
+       pr_info("%10s: comm\n", "Thread ID");
+
+       node = rb_first(&thread_stats);
+       while (node) {
+               st = container_of(node, struct thread_stat, rb);
+               t = perf_session__findnew(session, st->tid);
+               pr_info("%10d: %s\n", st->tid, t->comm);
+               node = rb_next(node);
+       };
 }
 
 static void dump_map(void)
@@ -680,23 +816,53 @@ static void dump_map(void)
        unsigned int i;
        struct lock_stat *st;
 
+       pr_info("Address of instance: name of class\n");
        for (i = 0; i < LOCKHASH_SIZE; i++) {
                list_for_each_entry(st, &lockhash_table[i], hash_entry) {
-                       printf("%p: %s\n", st->addr, st->name);
+                       pr_info(" %p: %s\n", st->addr, st->name);
                }
        }
 }
 
+static void dump_info(void)
+{
+       if (info_threads)
+               dump_threads();
+       else if (info_map)
+               dump_map();
+       else
+               die("Unknown type of information\n");
+}
+
+static int process_sample_event(event_t *self, struct perf_session *s)
+{
+       struct sample_data data;
+       struct thread *thread;
+
+       bzero(&data, sizeof(data));
+       event__parse_sample(self, s->sample_type, &data);
+
+       thread = perf_session__findnew(s, data.tid);
+       if (thread == NULL) {
+               pr_debug("problem processing %d event, skipping it.\n",
+                       self->header.type);
+               return -1;
+       }
+
+       process_raw_event(data.raw_data, data.cpu, data.time, thread);
+
+       return 0;
+}
+
 static struct perf_event_ops eops = {
        .sample                 = process_sample_event,
        .comm                   = event__process_comm,
+       .ordered_samples        = true,
 };
 
-static struct perf_session *session;
-
 static int read_events(void)
 {
-       session = perf_session__new(input_name, O_RDONLY, 0);
+       session = perf_session__new(input_name, O_RDONLY, 0, false);
        if (!session)
                die("Initializing perf session failed\n");
 
@@ -720,7 +886,6 @@ static void __cmd_report(void)
        setup_pager();
        select_key();
        read_events();
-       flush_raw_event_queue(ULLONG_MAX);
        sort_result();
        print_result();
 }
@@ -737,6 +902,19 @@ static const struct option report_options[] = {
        OPT_END()
 };
 
+static const char * const info_usage[] = {
+       "perf lock info [<options>]",
+       NULL
+};
+
+static const struct option info_options[] = {
+       OPT_BOOLEAN('t', "threads", &info_threads,
+                   "dump thread list in perf.data"),
+       OPT_BOOLEAN('m', "map", &info_map,
+                   "map of lock instances (name:address table)"),
+       OPT_END()
+};
+
 static const char * const lock_usage[] = {
        "perf lock [<options>] {record|trace|report}",
        NULL
@@ -744,14 +922,13 @@ static const char * const lock_usage[] = {
 
 static const struct option lock_options[] = {
        OPT_STRING('i', "input", &input_name, "file", "input file name"),
-       OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
+       OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
        OPT_END()
 };
 
 static const char *record_args[] = {
        "record",
-       "-a",
        "-R",
        "-f",
        "-m", "1024",
@@ -808,12 +985,18 @@ int cmd_lock(int argc, const char **argv, const char *prefix __used)
        } else if (!strcmp(argv[0], "trace")) {
                /* Aliased to 'perf trace' */
                return cmd_trace(argc, argv, prefix);
-       } else if (!strcmp(argv[0], "map")) {
+       } else if (!strcmp(argv[0], "info")) {
+               if (argc) {
+                       argc = parse_options(argc, argv,
+                                            info_options, info_usage, 0);
+                       if (argc)
+                               usage_with_options(info_usage, info_options);
+               }
                /* recycling report_lock_ops */
                trace_handler = &report_lock_ops;
                setup_pager();
                read_events();
-               dump_map();
+               dump_info();
        } else {
                usage_with_options(lock_usage, lock_options);
        }
index 152d6c9..61c6d70 100644 (file)
 #include "builtin.h"
 #include "util/util.h"
 #include "util/strlist.h"
-#include "util/event.h"
+#include "util/symbol.h"
 #include "util/debug.h"
 #include "util/debugfs.h"
-#include "util/symbol.h"
-#include "util/thread.h"
 #include "util/parse-options.h"
-#include "util/parse-events.h" /* For debugfs_path */
 #include "util/probe-finder.h"
 #include "util/probe-event.h"
 
 
 /* Session management structure */
 static struct {
-       bool need_dwarf;
        bool list_events;
        bool force_add;
        bool show_lines;
-       int nr_probe;
-       struct probe_point probes[MAX_PROBES];
+       int nevents;
+       struct perf_probe_event events[MAX_PROBES];
        struct strlist *dellist;
-       struct map_groups kmap_groups;
-       struct map *kmaps[MAP__NR_TYPES];
        struct line_range line_range;
-} session;
+       int max_probe_points;
+} params;
 
 
 /* Parse an event definition. Note that any error must die. */
-static void parse_probe_event(const char *str)
+static int parse_probe_event(const char *str)
 {
-       struct probe_point *pp = &session.probes[session.nr_probe];
+       struct perf_probe_event *pev = &params.events[params.nevents];
+       int ret;
 
-       pr_debug("probe-definition(%d): %s\n", session.nr_probe, str);
-       if (++session.nr_probe == MAX_PROBES)
+       pr_debug("probe-definition(%d): %s\n", params.nevents, str);
+       if (++params.nevents == MAX_PROBES)
                die("Too many probes (> %d) are specified.", MAX_PROBES);
 
-       /* Parse perf-probe event into probe_point */
-       parse_perf_probe_event(str, pp, &session.need_dwarf);
+       /* Parse a perf-probe command into event */
+       ret = parse_perf_probe_command(str, pev);
+       pr_debug("%d arguments\n", pev->nargs);
 
-       pr_debug("%d arguments\n", pp->nr_args);
+       return ret;
 }
 
-static void parse_probe_event_argv(int argc, const char **argv)
+static int parse_probe_event_argv(int argc, const char **argv)
 {
-       int i, len;
+       int i, len, ret;
        char *buf;
 
        /* Bind up rest arguments */
        len = 0;
        for (i = 0; i < argc; i++)
                len += strlen(argv[i]) + 1;
-       buf = zalloc(len + 1);
-       if (!buf)
-               die("Failed to allocate memory for binding arguments.");
+       buf = xzalloc(len + 1);
        len = 0;
        for (i = 0; i < argc; i++)
                len += sprintf(&buf[len], "%s ", argv[i]);
-       parse_probe_event(buf);
+       ret = parse_probe_event(buf);
        free(buf);
+       return ret;
 }
 
 static int opt_add_probe_event(const struct option *opt __used,
                              const char *str, int unset __used)
 {
        if (str)
-               parse_probe_event(str);
-       return 0;
+               return parse_probe_event(str);
+       else
+               return 0;
 }
 
 static int opt_del_probe_event(const struct option *opt __used,
                               const char *str, int unset __used)
 {
        if (str) {
-               if (!session.dellist)
-                       session.dellist = strlist__new(true, NULL);
-               strlist__add(session.dellist, str);
+               if (!params.dellist)
+                       params.dellist = strlist__new(true, NULL);
+               strlist__add(params.dellist, str);
        }
        return 0;
 }
 
-/* Currently just checking function name from symbol map */
-static void evaluate_probe_point(struct probe_point *pp)
-{
-       struct symbol *sym;
-       sym = map__find_symbol_by_name(session.kmaps[MAP__FUNCTION],
-                                      pp->function, NULL);
-       if (!sym)
-               die("Kernel symbol \'%s\' not found - probe not added.",
-                   pp->function);
-}
-
-#ifndef NO_DWARF_SUPPORT
-static int open_vmlinux(void)
-{
-       if (map__load(session.kmaps[MAP__FUNCTION], NULL) < 0) {
-               pr_debug("Failed to load kernel map.\n");
-               return -EINVAL;
-       }
-       pr_debug("Try to open %s\n",
-                session.kmaps[MAP__FUNCTION]->dso->long_name);
-       return open(session.kmaps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
-}
-
+#ifdef DWARF_SUPPORT
 static int opt_show_lines(const struct option *opt __used,
                          const char *str, int unset __used)
 {
+       int ret = 0;
+
        if (str)
-               parse_line_range_desc(str, &session.line_range);
-       INIT_LIST_HEAD(&session.line_range.line_list);
-       session.show_lines = true;
-       return 0;
+               ret = parse_line_range_desc(str, &params.line_range);
+       INIT_LIST_HEAD(&params.line_range.line_list);
+       params.show_lines = true;
+
+       return ret;
 }
 #endif
 
@@ -155,29 +133,25 @@ static const char * const probe_usage[] = {
        "perf probe [<options>] --add 'PROBEDEF' [--add 'PROBEDEF' ...]",
        "perf probe [<options>] --del '[GROUP:]EVENT' ...",
        "perf probe --list",
-#ifndef NO_DWARF_SUPPORT
+#ifdef DWARF_SUPPORT
        "perf probe --line 'LINEDESC'",
 #endif
        NULL
 };
 
 static const struct option options[] = {
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show parsed arguments, etc)"),
-#ifndef NO_DWARF_SUPPORT
-       OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
-                  "file", "vmlinux pathname"),
-#endif
-       OPT_BOOLEAN('l', "list", &session.list_events,
+       OPT_BOOLEAN('l', "list", &params.list_events,
                    "list up current probe events"),
        OPT_CALLBACK('d', "del", NULL, "[GROUP:]EVENT", "delete a probe event.",
                opt_del_probe_event),
        OPT_CALLBACK('a', "add", NULL,
-#ifdef NO_DWARF_SUPPORT
-               "[EVENT=]FUNC[+OFF|%return] [ARG ...]",
-#else
+#ifdef DWARF_SUPPORT
                "[EVENT=]FUNC[@SRC][+OFF|%return|:RL|;PT]|SRC:AL|SRC;PT"
-               " [ARG ...]",
+               " [[NAME=]ARG ...]",
+#else
+               "[EVENT=]FUNC[+OFF|%return] [[NAME=]ARG ...]",
 #endif
                "probe point definition, where\n"
                "\t\tGROUP:\tGroup name (optional)\n"
@@ -185,51 +159,35 @@ static const struct option options[] = {
                "\t\tFUNC:\tFunction name\n"
                "\t\tOFF:\tOffset from function entry (in byte)\n"
                "\t\t%return:\tPut the probe at function return\n"
-#ifdef NO_DWARF_SUPPORT
-               "\t\tARG:\tProbe argument (only \n"
-#else
+#ifdef DWARF_SUPPORT
                "\t\tSRC:\tSource code path\n"
                "\t\tRL:\tRelative line number from function entry.\n"
                "\t\tAL:\tAbsolute line number in file.\n"
                "\t\tPT:\tLazy expression of line code.\n"
                "\t\tARG:\tProbe argument (local variable name or\n"
-#endif
                "\t\t\tkprobe-tracer argument format.)\n",
+#else
+               "\t\tARG:\tProbe argument (kprobe-tracer argument format.)\n",
+#endif
                opt_add_probe_event),
-       OPT_BOOLEAN('f', "force", &session.force_add, "forcibly add events"
+       OPT_BOOLEAN('f', "force", &params.force_add, "forcibly add events"
                    " with existing name"),
-#ifndef NO_DWARF_SUPPORT
+#ifdef DWARF_SUPPORT
        OPT_CALLBACK('L', "line", NULL,
-                    "FUNC[:RLN[+NUM|:RLN2]]|SRC:ALN[+NUM|:ALN2]",
+                    "FUNC[:RLN[+NUM|-RLN2]]|SRC:ALN[+NUM|-ALN2]",
                     "Show source code lines.", opt_show_lines),
+       OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
+                  "file", "vmlinux pathname"),
 #endif
+       OPT__DRY_RUN(&probe_event_dry_run),
+       OPT_INTEGER('\0', "max-probes", &params.max_probe_points,
+                "Set how many probe points can be found for a probe."),
        OPT_END()
 };
 
-/* Initialize symbol maps for vmlinux */
-static void init_vmlinux(void)
-{
-       symbol_conf.sort_by_name = true;
-       if (symbol_conf.vmlinux_name == NULL)
-               symbol_conf.try_vmlinux_path = true;
-       else
-               pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
-       if (symbol__init() < 0)
-               die("Failed to init symbol map.");
-
-       map_groups__init(&session.kmap_groups);
-       if (map_groups__create_kernel_maps(&session.kmap_groups,
-                                          session.kmaps) < 0)
-               die("Failed to create kernel maps.");
-}
-
 int cmd_probe(int argc, const char **argv, const char *prefix __used)
 {
-       int i, ret;
-#ifndef NO_DWARF_SUPPORT
-       int fd;
-#endif
-       struct probe_point *pp;
+       int ret;
 
        argc = parse_options(argc, argv, options, probe_usage,
                             PARSE_OPT_STOP_AT_NON_OPTION);
@@ -238,123 +196,69 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used)
                        pr_warning("  Error: '-' is not supported.\n");
                        usage_with_options(probe_usage, options);
                }
-               parse_probe_event_argv(argc, argv);
+               ret = parse_probe_event_argv(argc, argv);
+               if (ret < 0) {
+                       pr_err("  Error: Parse Error.  (%d)\n", ret);
+                       return ret;
+               }
        }
 
-       if ((!session.nr_probe && !session.dellist && !session.list_events &&
-            !session.show_lines))
-               usage_with_options(probe_usage, options);
+       if (params.max_probe_points == 0)
+               params.max_probe_points = MAX_PROBES;
 
-       if (debugfs_valid_mountpoint(debugfs_path) < 0)
-               die("Failed to find debugfs path.");
+       if ((!params.nevents && !params.dellist && !params.list_events &&
+            !params.show_lines))
+               usage_with_options(probe_usage, options);
 
-       if (session.list_events) {
-               if (session.nr_probe != 0 || session.dellist) {
-                       pr_warning("  Error: Don't use --list with"
-                                  " --add/--del.\n");
+       if (params.list_events) {
+               if (params.nevents != 0 || params.dellist) {
+                       pr_err("  Error: Don't use --list with --add/--del.\n");
                        usage_with_options(probe_usage, options);
                }
-               if (session.show_lines) {
-                       pr_warning("  Error: Don't use --list with --line.\n");
+               if (params.show_lines) {
+                       pr_err("  Error: Don't use --list with --line.\n");
                        usage_with_options(probe_usage, options);
                }
-               show_perf_probe_events();
-               return 0;
+               ret = show_perf_probe_events();
+               if (ret < 0)
+                       pr_err("  Error: Failed to show event list. (%d)\n",
+                              ret);
+               return ret;
        }
 
-#ifndef NO_DWARF_SUPPORT
-       if (session.show_lines) {
-               if (session.nr_probe != 0 || session.dellist) {
+#ifdef DWARF_SUPPORT
+       if (params.show_lines) {
+               if (params.nevents != 0 || params.dellist) {
                        pr_warning("  Error: Don't use --line with"
                                   " --add/--del.\n");
                        usage_with_options(probe_usage, options);
                }
-               init_vmlinux();
-               fd = open_vmlinux();
-               if (fd < 0)
-                       die("Could not open debuginfo file.");
-               ret = find_line_range(fd, &session.line_range);
-               if (ret <= 0)
-                       die("Source line is not found.\n");
-               close(fd);
-               show_line_range(&session.line_range);
-               return 0;
-       }
-#endif
 
-       if (session.dellist) {
-               del_trace_kprobe_events(session.dellist);
-               strlist__delete(session.dellist);
-               if (session.nr_probe == 0)
-                       return 0;
+               ret = show_line_range(&params.line_range);
+               if (ret < 0)
+                       pr_err("  Error: Failed to show lines. (%d)\n", ret);
+               return ret;
        }
+#endif
 
-       /* Add probes */
-       init_vmlinux();
-
-       if (session.need_dwarf)
-#ifdef NO_DWARF_SUPPORT
-               die("Debuginfo-analysis is not supported");
-#else  /* !NO_DWARF_SUPPORT */
-               pr_debug("Some probes require debuginfo.\n");
-
-       fd = open_vmlinux();
-       if (fd < 0) {
-               if (session.need_dwarf)
-                       die("Could not open debuginfo file.");
-
-               pr_debug("Could not open vmlinux/module file."
-                        " Try to use symbols.\n");
-               goto end_dwarf;
-       }
-
-       /* Searching probe points */
-       for (i = 0; i < session.nr_probe; i++) {
-               pp = &session.probes[i];
-               if (pp->found)
-                       continue;
-
-               lseek(fd, SEEK_SET, 0);
-               ret = find_probe_point(fd, pp);
-               if (ret > 0)
-                       continue;
-               if (ret == 0) { /* No error but failed to find probe point. */
-                       synthesize_perf_probe_point(pp);
-                       die("Probe point '%s' not found. - probe not added.",
-                           pp->probes[0]);
-               }
-               /* Error path */
-               if (session.need_dwarf) {
-                       if (ret == -ENOENT)
-                               pr_warning("No dwarf info found in the vmlinux - please rebuild with CONFIG_DEBUG_INFO=y.\n");
-                       die("Could not analyze debuginfo.");
+       if (params.dellist) {
+               ret = del_perf_probe_events(params.dellist);
+               strlist__delete(params.dellist);
+               if (ret < 0) {
+                       pr_err("  Error: Failed to delete events. (%d)\n", ret);
+                       return ret;
                }
-               pr_debug("An error occurred in debuginfo analysis."
-                        " Try to use symbols.\n");
-               break;
        }
-       close(fd);
-
-end_dwarf:
-#endif /* !NO_DWARF_SUPPORT */
 
-       /* Synthesize probes without dwarf */
-       for (i = 0; i < session.nr_probe; i++) {
-               pp = &session.probes[i];
-               if (pp->found)  /* This probe is already found. */
-                       continue;
-
-               evaluate_probe_point(pp);
-               ret = synthesize_trace_kprobe_event(pp);
-               if (ret == -E2BIG)
-                       die("probe point definition becomes too long.");
-               else if (ret < 0)
-                       die("Failed to synthesize a probe point.");
+       if (params.nevents) {
+               ret = add_perf_probe_events(params.events, params.nevents,
+                                           params.force_add,
+                                           params.max_probe_points);
+               if (ret < 0) {
+                       pr_err("  Error: Failed to add events. (%d)\n", ret);
+                       return ret;
+               }
        }
-
-       /* Settng up probe points */
-       add_trace_kprobe_events(session.probes, session.nr_probe,
-                               session.force_add);
        return 0;
 }
 
index f1411e9..cb46c7d 100644 (file)
@@ -15,7 +15,6 @@
 #include "util/util.h"
 #include "util/parse-options.h"
 #include "util/parse-events.h"
-#include "util/string.h"
 
 #include "util/header.h"
 #include "util/event.h"
 #include <unistd.h>
 #include <sched.h>
 
-static int                     fd[MAX_NR_CPUS][MAX_COUNTERS];
+enum write_mode_t {
+       WRITE_FORCE,
+       WRITE_APPEND
+};
+
+static int                     *fd[MAX_NR_CPUS][MAX_COUNTERS];
 
-static long                    default_interval                =      0;
+static u64                     user_interval                   = ULLONG_MAX;
+static u64                     default_interval                =      0;
 
 static int                     nr_cpus                         =      0;
 static unsigned int            page_size;
 static unsigned int            mmap_pages                      =    128;
+static unsigned int            user_freq                       = UINT_MAX;
 static int                     freq                            =   1000;
 static int                     output;
+static int                     pipe_output                     =      0;
 static const char              *output_name                    = "perf.data";
 static int                     group                           =      0;
-static unsigned int            realtime_prio                   =      0;
-static int                     raw_samples                     =      0;
-static int                     system_wide                     =      0;
+static int                     realtime_prio                   =      0;
+static bool                    raw_samples                     =  false;
+static bool                    system_wide                     =  false;
 static int                     profile_cpu                     =     -1;
 static pid_t                   target_pid                      =     -1;
+static pid_t                   target_tid                      =     -1;
+static pid_t                   *all_tids                       =      NULL;
+static int                     thread_num                      =      0;
 static pid_t                   child_pid                       =     -1;
-static int                     inherit                         =      1;
-static int                     force                           =      0;
-static int                     append_file                     =      0;
-static int                     call_graph                      =      0;
-static int                     inherit_stat                    =      0;
-static int                     no_samples                      =      0;
-static int                     sample_address                  =      0;
-static int                     multiplex                       =      0;
+static bool                    no_inherit                      =  false;
+static enum write_mode_t       write_mode                      = WRITE_FORCE;
+static bool                    call_graph                      =  false;
+static bool                    inherit_stat                    =  false;
+static bool                    no_samples                      =  false;
+static bool                    sample_address                  =  false;
+static bool                    multiplex                       =  false;
 static int                     multiplex_fd                    =     -1;
 
 static long                    samples                         =      0;
@@ -60,7 +69,7 @@ static struct timeval         this_read;
 
 static u64                     bytes_written                   =      0;
 
-static struct pollfd           event_array[MAX_NR_CPUS * MAX_COUNTERS];
+static struct pollfd           *event_array;
 
 static int                     nr_poll                         =      0;
 static int                     nr_cpu                          =      0;
@@ -77,7 +86,7 @@ struct mmap_data {
        unsigned int            prev;
 };
 
-static struct mmap_data                mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
+static struct mmap_data                *mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
 
 static unsigned long mmap_read_head(struct mmap_data *md)
 {
@@ -101,6 +110,11 @@ static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
        pc->data_tail = tail;
 }
 
+static void advance_output(size_t size)
+{
+       bytes_written += size;
+}
+
 static void write_output(void *buf, size_t size)
 {
        while (size) {
@@ -225,12 +239,13 @@ static struct perf_header_attr *get_header_attr(struct perf_event_attr *a, int n
        return h_attr;
 }
 
-static void create_counter(int counter, int cpu, pid_t pid)
+static void create_counter(int counter, int cpu)
 {
        char *filter = filters[counter];
        struct perf_event_attr *attr = attrs + counter;
        struct perf_header_attr *h_attr;
        int track = !counter; /* only the first counter needs these */
+       int thread_index;
        int ret;
        struct {
                u64 count;
@@ -248,10 +263,19 @@ static void create_counter(int counter, int cpu, pid_t pid)
        if (nr_counters > 1)
                attr->sample_type |= PERF_SAMPLE_ID;
 
-       if (freq) {
-               attr->sample_type       |= PERF_SAMPLE_PERIOD;
-               attr->freq              = 1;
-               attr->sample_freq       = freq;
+       /*
+        * We default some events to a 1 default interval. But keep
+        * it a weak assumption overridable by the user.
+        */
+       if (!attr->sample_period || (user_freq != UINT_MAX &&
+                                    user_interval != ULLONG_MAX)) {
+               if (freq) {
+                       attr->sample_type       |= PERF_SAMPLE_PERIOD;
+                       attr->freq              = 1;
+                       attr->sample_freq       = freq;
+               } else {
+                       attr->sample_period = default_interval;
+               }
        }
 
        if (no_samples)
@@ -274,119 +298,130 @@ static void create_counter(int counter, int cpu, pid_t pid)
 
        attr->mmap              = track;
        attr->comm              = track;
-       attr->inherit           = inherit;
-       attr->disabled          = 1;
+       attr->inherit           = !no_inherit;
+       if (target_pid == -1 && target_tid == -1 && !system_wide) {
+               attr->disabled = 1;
+               attr->enable_on_exec = 1;
+       }
 
+       for (thread_index = 0; thread_index < thread_num; thread_index++) {
 try_again:
-       fd[nr_cpu][counter] = sys_perf_event_open(attr, pid, cpu, group_fd, 0);
-
-       if (fd[nr_cpu][counter] < 0) {
-               int err = errno;
-
-               if (err == EPERM || err == EACCES)
-                       die("Permission error - are you root?\n");
-               else if (err ==  ENODEV && profile_cpu != -1)
-                       die("No such device - did you specify an out-of-range profile CPU?\n");
+               fd[nr_cpu][counter][thread_index] = sys_perf_event_open(attr,
+                               all_tids[thread_index], cpu, group_fd, 0);
+
+               if (fd[nr_cpu][counter][thread_index] < 0) {
+                       int err = errno;
+
+                       if (err == EPERM || err == EACCES)
+                               die("Permission error - are you root?\n"
+                                       "\t Consider tweaking"
+                                       " /proc/sys/kernel/perf_event_paranoid.\n");
+                       else if (err ==  ENODEV && profile_cpu != -1) {
+                               die("No such device - did you specify"
+                                       " an out-of-range profile CPU?\n");
+                       }
 
-               /*
-                * If it's cycles then fall back to hrtimer
-                * based cpu-clock-tick sw counter, which
-                * is always available even if no PMU support:
-                */
-               if (attr->type == PERF_TYPE_HARDWARE
-                       && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
-
-                       if (verbose)
-                               warning(" ... trying to fall back to cpu-clock-ticks\n");
-                       attr->type = PERF_TYPE_SOFTWARE;
-                       attr->config = PERF_COUNT_SW_CPU_CLOCK;
-                       goto try_again;
-               }
-               printf("\n");
-               error("perfcounter syscall returned with %d (%s)\n",
-                       fd[nr_cpu][counter], strerror(err));
+                       /*
+                        * If it's cycles then fall back to hrtimer
+                        * based cpu-clock-tick sw counter, which
+                        * is always available even if no PMU support:
+                        */
+                       if (attr->type == PERF_TYPE_HARDWARE
+                                       && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
+
+                               if (verbose)
+                                       warning(" ... trying to fall back to cpu-clock-ticks\n");
+                               attr->type = PERF_TYPE_SOFTWARE;
+                               attr->config = PERF_COUNT_SW_CPU_CLOCK;
+                               goto try_again;
+                       }
+                       printf("\n");
+                       error("perfcounter syscall returned with %d (%s)\n",
+                                       fd[nr_cpu][counter][thread_index], strerror(err));
 
 #if defined(__i386__) || defined(__x86_64__)
-               if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
-                       die("No hardware sampling interrupt available. No APIC? If so then you can boot the kernel with the \"lapic\" boot parameter to force-enable it.\n");
+                       if (attr->type == PERF_TYPE_HARDWARE && err == EOPNOTSUPP)
+                               die("No hardware sampling interrupt available."
+                                   " No APIC? If so then you can boot the kernel"
+                                   " with the \"lapic\" boot parameter to"
+                                   " force-enable it.\n");
 #endif
 
-               die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
-               exit(-1);
-       }
+                       die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
+                       exit(-1);
+               }
 
-       h_attr = get_header_attr(attr, counter);
-       if (h_attr == NULL)
-               die("nomem\n");
+               h_attr = get_header_attr(attr, counter);
+               if (h_attr == NULL)
+                       die("nomem\n");
 
-       if (!file_new) {
-               if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
-                       fprintf(stderr, "incompatible append\n");
-                       exit(-1);
+               if (!file_new) {
+                       if (memcmp(&h_attr->attr, attr, sizeof(*attr))) {
+                               fprintf(stderr, "incompatible append\n");
+                               exit(-1);
+                       }
                }
-       }
 
-       if (read(fd[nr_cpu][counter], &read_data, sizeof(read_data)) == -1) {
-               perror("Unable to read perf file descriptor\n");
-               exit(-1);
-       }
+               if (read(fd[nr_cpu][counter][thread_index], &read_data, sizeof(read_data)) == -1) {
+                       perror("Unable to read perf file descriptor\n");
+                       exit(-1);
+               }
 
-       if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
-               pr_warning("Not enough memory to add id\n");
-               exit(-1);
-       }
+               if (perf_header_attr__add_id(h_attr, read_data.id) < 0) {
+                       pr_warning("Not enough memory to add id\n");
+                       exit(-1);
+               }
 
-       assert(fd[nr_cpu][counter] >= 0);
-       fcntl(fd[nr_cpu][counter], F_SETFL, O_NONBLOCK);
+               assert(fd[nr_cpu][counter][thread_index] >= 0);
+               fcntl(fd[nr_cpu][counter][thread_index], F_SETFL, O_NONBLOCK);
 
-       /*
-        * First counter acts as the group leader:
-        */
-       if (group && group_fd == -1)
-               group_fd = fd[nr_cpu][counter];
-       if (multiplex && multiplex_fd == -1)
-               multiplex_fd = fd[nr_cpu][counter];
+               /*
+                * First counter acts as the group leader:
+                */
+               if (group && group_fd == -1)
+                       group_fd = fd[nr_cpu][counter][thread_index];
+               if (multiplex && multiplex_fd == -1)
+                       multiplex_fd = fd[nr_cpu][counter][thread_index];
 
-       if (multiplex && fd[nr_cpu][counter] != multiplex_fd) {
+               if (multiplex && fd[nr_cpu][counter][thread_index] != multiplex_fd) {
 
-               ret = ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
-               assert(ret != -1);
-       } else {
-               event_array[nr_poll].fd = fd[nr_cpu][counter];
-               event_array[nr_poll].events = POLLIN;
-               nr_poll++;
-
-               mmap_array[nr_cpu][counter].counter = counter;
-               mmap_array[nr_cpu][counter].prev = 0;
-               mmap_array[nr_cpu][counter].mask = mmap_pages*page_size - 1;
-               mmap_array[nr_cpu][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
-                               PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter], 0);
-               if (mmap_array[nr_cpu][counter].base == MAP_FAILED) {
-                       error("failed to mmap with %d (%s)\n", errno, strerror(errno));
-                       exit(-1);
+                       ret = ioctl(fd[nr_cpu][counter][thread_index], PERF_EVENT_IOC_SET_OUTPUT, multiplex_fd);
+                       assert(ret != -1);
+               } else {
+                       event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
+                       event_array[nr_poll].events = POLLIN;
+                       nr_poll++;
+
+                       mmap_array[nr_cpu][counter][thread_index].counter = counter;
+                       mmap_array[nr_cpu][counter][thread_index].prev = 0;
+                       mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1;
+                       mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size,
+                               PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0);
+                       if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) {
+                               error("failed to mmap with %d (%s)\n", errno, strerror(errno));
+                               exit(-1);
+                       }
                }
-       }
 
-       if (filter != NULL) {
-               ret = ioctl(fd[nr_cpu][counter],
-                           PERF_EVENT_IOC_SET_FILTER, filter);
-               if (ret) {
-                       error("failed to set filter with %d (%s)\n", errno,
-                             strerror(errno));
-                       exit(-1);
+               if (filter != NULL) {
+                       ret = ioctl(fd[nr_cpu][counter][thread_index],
+                                       PERF_EVENT_IOC_SET_FILTER, filter);
+                       if (ret) {
+                               error("failed to set filter with %d (%s)\n", errno,
+                                               strerror(errno));
+                               exit(-1);
+                       }
                }
        }
-
-       ioctl(fd[nr_cpu][counter], PERF_EVENT_IOC_ENABLE);
 }
 
-static void open_counters(int cpu, pid_t pid)
+static void open_counters(int cpu)
 {
        int counter;
 
        group_fd = -1;
        for (counter = 0; counter < nr_counters; counter++)
-               create_counter(counter, cpu, pid);
+               create_counter(counter, cpu);
 
        nr_cpu++;
 }
@@ -406,10 +441,80 @@ static int process_buildids(void)
 
 static void atexit_header(void)
 {
-       session->header.data_size += bytes_written;
+       if (!pipe_output) {
+               session->header.data_size += bytes_written;
+
+               process_buildids();
+               perf_header__write(&session->header, output, true);
+       }
+}
+
+static void event__synthesize_guest_os(struct machine *machine, void *data)
+{
+       int err;
+       char *guest_kallsyms;
+       char path[PATH_MAX];
+       struct perf_session *psession = data;
+
+       if (machine__is_host(machine))
+               return;
+
+       /*
+        *As for guest kernel when processing subcommand record&report,
+        *we arrange module mmap prior to guest kernel mmap and trigger
+        *a preload dso because default guest module symbols are loaded
+        *from guest kallsyms instead of /lib/modules/XXX/XXX. This
+        *method is used to avoid symbol missing when the first addr is
+        *in module instead of in guest kernel.
+        */
+       err = event__synthesize_modules(process_synthesized_event,
+                                       psession, machine);
+       if (err < 0)
+               pr_err("Couldn't record guest kernel [%d]'s reference"
+                      " relocation symbol.\n", machine->pid);
+
+       if (machine__is_default_guest(machine))
+               guest_kallsyms = (char *) symbol_conf.default_guest_kallsyms;
+       else {
+               sprintf(path, "%s/proc/kallsyms", machine->root_dir);
+               guest_kallsyms = path;
+       }
+
+       /*
+        * We use _stext for guest kernel because guest kernel's /proc/kallsyms
+        * have no _text sometimes.
+        */
+       err = event__synthesize_kernel_mmap(process_synthesized_event,
+                                           psession, machine, "_text");
+       if (err < 0)
+               err = event__synthesize_kernel_mmap(process_synthesized_event,
+                                                   psession, machine, "_stext");
+       if (err < 0)
+               pr_err("Couldn't record guest kernel [%d]'s reference"
+                      " relocation symbol.\n", machine->pid);
+}
+
+static struct perf_event_header finished_round_event = {
+       .size = sizeof(struct perf_event_header),
+       .type = PERF_RECORD_FINISHED_ROUND,
+};
+
+static void mmap_read_all(void)
+{
+       int i, counter, thread;
+
+       for (i = 0; i < nr_cpu; i++) {
+               for (counter = 0; counter < nr_counters; counter++) {
+                       for (thread = 0; thread < thread_num; thread++) {
+                               if (mmap_array[i][counter][thread].base)
+                                       mmap_read(&mmap_array[i][counter][thread]);
+                       }
+
+               }
+       }
 
-       process_buildids();
-       perf_header__write(&session->header, output, true);
+       if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
+               write_output(&finished_round_event, sizeof(finished_round_event));
 }
 
 static int __cmd_record(int argc, const char **argv)
@@ -421,8 +526,9 @@ static int __cmd_record(int argc, const char **argv)
        int err;
        unsigned long waking = 0;
        int child_ready_pipe[2], go_pipe[2];
-       const bool forks = target_pid == -1 && argc > 0;
+       const bool forks = argc > 0;
        char buf;
+       struct machine *machine;
 
        page_size = sysconf(_SC_PAGE_SIZE);
 
@@ -435,70 +541,63 @@ static int __cmd_record(int argc, const char **argv)
                exit(-1);
        }
 
-       if (!stat(output_name, &st) && st.st_size) {
-               if (!force) {
-                       if (!append_file) {
-                               pr_err("Error, output file %s exists, use -A "
-                                      "to append or -f to overwrite.\n",
-                                      output_name);
-                               exit(-1);
-                       }
-               } else {
+       if (!strcmp(output_name, "-"))
+               pipe_output = 1;
+       else if (!stat(output_name, &st) && st.st_size) {
+               if (write_mode == WRITE_FORCE) {
                        char oldname[PATH_MAX];
                        snprintf(oldname, sizeof(oldname), "%s.old",
                                 output_name);
                        unlink(oldname);
                        rename(output_name, oldname);
                }
-       } else {
-               append_file = 0;
+       } else if (write_mode == WRITE_APPEND) {
+               write_mode = WRITE_FORCE;
        }
 
        flags = O_CREAT|O_RDWR;
-       if (append_file)
+       if (write_mode == WRITE_APPEND)
                file_new = 0;
        else
                flags |= O_TRUNC;
 
-       output = open(output_name, flags, S_IRUSR|S_IWUSR);
+       if (pipe_output)
+               output = STDOUT_FILENO;
+       else
+               output = open(output_name, flags, S_IRUSR | S_IWUSR);
        if (output < 0) {
                perror("failed to create output file");
                exit(-1);
        }
 
-       session = perf_session__new(output_name, O_WRONLY, force);
+       session = perf_session__new(output_name, O_WRONLY,
+                                   write_mode == WRITE_FORCE, false);
        if (session == NULL) {
                pr_err("Not enough memory for reading perf file header\n");
                return -1;
        }
 
        if (!file_new) {
-               err = perf_header__read(&session->header, output);
+               err = perf_header__read(session, output);
                if (err < 0)
                        return err;
        }
 
-       if (raw_samples) {
+       if (have_tracepoints(attrs, nr_counters))
                perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
-       } else {
-               for (i = 0; i < nr_counters; i++) {
-                       if (attrs[i].sample_type & PERF_SAMPLE_RAW) {
-                               perf_header__set_feat(&session->header, HEADER_TRACE_INFO);
-                               break;
-                       }
-               }
-       }
 
        atexit(atexit_header);
 
        if (forks) {
-               pid = fork();
+               child_pid = fork();
                if (pid < 0) {
                        perror("failed to fork");
                        exit(-1);
                }
 
-               if (!pid) {
+               if (!child_pid) {
+                       if (pipe_output)
+                               dup2(2, 1);
                        close(child_ready_pipe[0]);
                        close(go_pipe[1]);
                        fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -527,10 +626,8 @@ static int __cmd_record(int argc, const char **argv)
                        exit(-1);
                }
 
-               child_pid = pid;
-
-               if (!system_wide)
-                       target_pid = pid;
+               if (!system_wide && target_tid == -1 && target_pid == -1)
+                       all_tids[0] = child_pid;
 
                close(child_ready_pipe[1]);
                close(go_pipe[0]);
@@ -544,16 +641,19 @@ static int __cmd_record(int argc, const char **argv)
                close(child_ready_pipe[0]);
        }
 
-
-       if ((!system_wide && !inherit) || profile_cpu != -1) {
-               open_counters(profile_cpu, target_pid);
+       if ((!system_wide && no_inherit) || profile_cpu != -1) {
+               open_counters(profile_cpu);
        } else {
                nr_cpus = read_cpu_map();
                for (i = 0; i < nr_cpus; i++)
-                       open_counters(cpumap[i], target_pid);
+                       open_counters(cpumap[i]);
        }
 
-       if (file_new) {
+       if (pipe_output) {
+               err = perf_header__write_pipe(output);
+               if (err < 0)
+                       return err;
+       } else if (file_new) {
                err = perf_header__write(&session->header, output, false);
                if (err < 0)
                        return err;
@@ -561,24 +661,70 @@ static int __cmd_record(int argc, const char **argv)
 
        post_processing_offset = lseek(output, 0, SEEK_CUR);
 
+       if (pipe_output) {
+               err = event__synthesize_attrs(&session->header,
+                                             process_synthesized_event,
+                                             session);
+               if (err < 0) {
+                       pr_err("Couldn't synthesize attrs.\n");
+                       return err;
+               }
+
+               err = event__synthesize_event_types(process_synthesized_event,
+                                                   session);
+               if (err < 0) {
+                       pr_err("Couldn't synthesize event_types.\n");
+                       return err;
+               }
+
+               if (have_tracepoints(attrs, nr_counters)) {
+                       /*
+                        * FIXME err <= 0 here actually means that
+                        * there were no tracepoints so its not really
+                        * an error, just that we don't need to
+                        * synthesize anything.  We really have to
+                        * return this more properly and also
+                        * propagate errors that now are calling die()
+                        */
+                       err = event__synthesize_tracing_data(output, attrs,
+                                                            nr_counters,
+                                                            process_synthesized_event,
+                                                            session);
+                       if (err <= 0) {
+                               pr_err("Couldn't record tracing data.\n");
+                               return err;
+                       }
+                       advance_output(err);
+               }
+       }
+
+       machine = perf_session__find_host_machine(session);
+       if (!machine) {
+               pr_err("Couldn't find native kernel information.\n");
+               return -1;
+       }
+
        err = event__synthesize_kernel_mmap(process_synthesized_event,
-                                           session, "_text");
+                                           session, machine, "_text");
        if (err < 0)
                err = event__synthesize_kernel_mmap(process_synthesized_event,
-                                                   session, "_stext");
+                                                   session, machine, "_stext");
        if (err < 0) {
                pr_err("Couldn't record kernel reference relocation symbol.\n");
                return err;
        }
 
-       err = event__synthesize_modules(process_synthesized_event, session);
+       err = event__synthesize_modules(process_synthesized_event,
+                                       session, machine);
        if (err < 0) {
                pr_err("Couldn't record kernel reference relocation symbol.\n");
                return err;
        }
+       if (perf_guest)
+               perf_session__process_machines(session, event__synthesize_guest_os);
 
        if (!system_wide && profile_cpu == -1)
-               event__synthesize_thread(target_pid, process_synthesized_event,
+               event__synthesize_thread(target_tid, process_synthesized_event,
                                         session);
        else
                event__synthesize_threads(process_synthesized_event, session);
@@ -601,13 +747,9 @@ static int __cmd_record(int argc, const char **argv)
 
        for (;;) {
                int hits = samples;
+               int thread;
 
-               for (i = 0; i < nr_cpu; i++) {
-                       for (counter = 0; counter < nr_counters; counter++) {
-                               if (mmap_array[i][counter].base)
-                                       mmap_read(&mmap_array[i][counter]);
-                       }
-               }
+               mmap_read_all();
 
                if (hits == samples) {
                        if (done)
@@ -618,8 +760,15 @@ static int __cmd_record(int argc, const char **argv)
 
                if (done) {
                        for (i = 0; i < nr_cpu; i++) {
-                               for (counter = 0; counter < nr_counters; counter++)
-                                       ioctl(fd[i][counter], PERF_EVENT_IOC_DISABLE);
+                               for (counter = 0;
+                                       counter < nr_counters;
+                                       counter++) {
+                                       for (thread = 0;
+                                               thread < thread_num;
+                                               thread++)
+                                               ioctl(fd[i][counter][thread],
+                                                       PERF_EVENT_IOC_DISABLE);
+                               }
                        }
                }
        }
@@ -644,6 +793,8 @@ static const char * const record_usage[] = {
        NULL
 };
 
+static bool force, append_file;
+
 static const struct option options[] = {
        OPT_CALLBACK('e', "event", NULL, "event",
                     "event selector. use 'perf list' to list available events",
@@ -651,7 +802,9 @@ static const struct option options[] = {
        OPT_CALLBACK(0, "filter", NULL, "filter",
                     "event filter", parse_filter),
        OPT_INTEGER('p', "pid", &target_pid,
-                   "record events on existing pid"),
+                   "record events on existing process id"),
+       OPT_INTEGER('t', "tid", &target_tid,
+                   "record events on existing thread id"),
        OPT_INTEGER('r', "realtime", &realtime_prio,
                    "collect data with this RT SCHED_FIFO priority"),
        OPT_BOOLEAN('R', "raw-samples", &raw_samples,
@@ -663,20 +816,17 @@ static const struct option options[] = {
        OPT_INTEGER('C', "profile_cpu", &profile_cpu,
                            "CPU to profile on"),
        OPT_BOOLEAN('f', "force", &force,
-                       "overwrite existing data file"),
-       OPT_LONG('c', "count", &default_interval,
-                   "event period to sample"),
+                       "overwrite existing data file (deprecated)"),
+       OPT_U64('c', "count", &user_interval, "event period to sample"),
        OPT_STRING('o', "output", &output_name, "file",
                    "output file name"),
-       OPT_BOOLEAN('i', "inherit", &inherit,
-                   "child tasks inherit counters"),
-       OPT_INTEGER('F', "freq", &freq,
-                   "profile at this frequency"),
-       OPT_INTEGER('m', "mmap-pages", &mmap_pages,
-                   "number of mmap data pages"),
+       OPT_BOOLEAN('i', "no-inherit", &no_inherit,
+                   "child tasks do not inherit counters"),
+       OPT_UINTEGER('F', "freq", &user_freq, "profile at this frequency"),
+       OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"),
        OPT_BOOLEAN('g', "call-graph", &call_graph,
                    "do call-graph (stack chain/backtrace) recording"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show counter open errors, etc)"),
        OPT_BOOLEAN('s', "stat", &inherit_stat,
                    "per thread counts"),
@@ -691,13 +841,24 @@ static const struct option options[] = {
 
 int cmd_record(int argc, const char **argv, const char *prefix __used)
 {
-       int counter;
+       int i,j;
 
        argc = parse_options(argc, argv, options, record_usage,
                            PARSE_OPT_STOP_AT_NON_OPTION);
-       if (!argc && target_pid == -1 && !system_wide && profile_cpu == -1)
+       if (!argc && target_pid == -1 && target_tid == -1 &&
+               !system_wide && profile_cpu == -1)
                usage_with_options(record_usage, options);
 
+       if (force && append_file) {
+               fprintf(stderr, "Can't overwrite and append at the same time."
+                               " You need to choose between -f and -A");
+               usage_with_options(record_usage, options);
+       } else if (append_file) {
+               write_mode = WRITE_APPEND;
+       } else {
+               write_mode = WRITE_FORCE;
+       }
+
        symbol__init();
 
        if (!nr_counters) {
@@ -706,6 +867,42 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
                attrs[0].config = PERF_COUNT_HW_CPU_CYCLES;
        }
 
+       if (target_pid != -1) {
+               target_tid = target_pid;
+               thread_num = find_all_tid(target_pid, &all_tids);
+               if (thread_num <= 0) {
+                       fprintf(stderr, "Can't find all threads of pid %d\n",
+                                       target_pid);
+                       usage_with_options(record_usage, options);
+               }
+       } else {
+               all_tids=malloc(sizeof(pid_t));
+               if (!all_tids)
+                       return -ENOMEM;
+
+               all_tids[0] = target_tid;
+               thread_num = 1;
+       }
+
+       for (i = 0; i < MAX_NR_CPUS; i++) {
+               for (j = 0; j < MAX_COUNTERS; j++) {
+                       fd[i][j] = malloc(sizeof(int)*thread_num);
+                       mmap_array[i][j] = zalloc(
+                               sizeof(struct mmap_data)*thread_num);
+                       if (!fd[i][j] || !mmap_array[i][j])
+                               return -ENOMEM;
+               }
+       }
+       event_array = malloc(
+               sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num);
+       if (!event_array)
+               return -ENOMEM;
+
+       if (user_interval != ULLONG_MAX)
+               default_interval = user_interval;
+       if (user_freq != UINT_MAX)
+               freq = user_freq;
+
        /*
         * User specified count overrides default frequency.
         */
@@ -718,12 +915,5 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
                exit(EXIT_FAILURE);
        }
 
-       for (counter = 0; counter < nr_counters; counter++) {
-               if (attrs[counter].sample_period)
-                       continue;
-
-               attrs[counter].sample_period = default_interval;
-       }
-
        return __cmd_record(argc, argv);
 }
index f815de2..1d3c100 100644 (file)
@@ -14,7 +14,6 @@
 #include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"
-#include "util/string.h"
 #include "util/callchain.h"
 #include "util/strlist.h"
 #include "util/values.h"
 
 static char            const *input_name = "perf.data";
 
-static int             force;
+static bool            force;
 static bool            hide_unresolved;
 static bool            dont_use_callchains;
 
-static int             show_threads;
+static bool            show_threads;
 static struct perf_read_values show_threads_values;
 
-static char            default_pretty_printing_style[] = "normal";
-static char            *pretty_printing_style = default_pretty_printing_style;
+static const char      default_pretty_printing_style[] = "normal";
+static const char      *pretty_printing_style = default_pretty_printing_style;
 
 static char            callchain_default_opt[] = "fractal,0.5";
 
-static struct event_stat_id *get_stats(struct perf_session *self,
-                                      u64 event_stream, u32 type, u64 config)
+static struct hists *perf_session__hists_findnew(struct perf_session *self,
+                                                u64 event_stream, u32 type,
+                                                u64 config)
 {
-       struct rb_node **p = &self->stats_by_id.rb_node;
+       struct rb_node **p = &self->hists_tree.rb_node;
        struct rb_node *parent = NULL;
-       struct event_stat_id *iter, *new;
+       struct hists *iter, *new;
 
        while (*p != NULL) {
                parent = *p;
-               iter = rb_entry(parent, struct event_stat_id, rb_node);
+               iter = rb_entry(parent, struct hists, rb_node);
                if (iter->config == config)
                        return iter;
 
@@ -65,15 +65,15 @@ static struct event_stat_id *get_stats(struct perf_session *self,
                        p = &(*p)->rb_left;
        }
 
-       new = malloc(sizeof(struct event_stat_id));
+       new = malloc(sizeof(struct hists));
        if (new == NULL)
                return NULL;
-       memset(new, 0, sizeof(struct event_stat_id));
+       memset(new, 0, sizeof(struct hists));
        new->event_stream = event_stream;
        new->config = config;
        new->type = type;
        rb_link_node(&new->rb_node, parent, p);
-       rb_insert_color(&new->rb_node, &self->stats_by_id);
+       rb_insert_color(&new->rb_node, &self->hists_tree);
        return new;
 }
 
@@ -81,70 +81,71 @@ static int perf_session__add_hist_entry(struct perf_session *self,
                                        struct addr_location *al,
                                        struct sample_data *data)
 {
-       struct symbol **syms = NULL, *parent = NULL;
-       bool hit;
+       struct map_symbol *syms = NULL;
+       struct symbol *parent = NULL;
+       int err = -ENOMEM;
        struct hist_entry *he;
-       struct event_stat_id *stats;
+       struct hists *hists;
        struct perf_event_attr *attr;
 
-       if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain)
+       if ((sort__has_parent || symbol_conf.use_callchain) && data->callchain) {
                syms = perf_session__resolve_callchain(self, al->thread,
                                                       data->callchain, &parent);
+               if (syms == NULL)
+                       return -ENOMEM;
+       }
 
        attr = perf_header__find_attr(data->id, &self->header);
        if (attr)
-               stats = get_stats(self, data->id, attr->type, attr->config);
+               hists = perf_session__hists_findnew(self, data->id, attr->type, attr->config);
        else
-               stats = get_stats(self, data->id, 0, 0);
-       if (stats == NULL)
-               return -ENOMEM;
-       he = __perf_session__add_hist_entry(&stats->hists, al, parent,
-                                           data->period, &hit);
+               hists = perf_session__hists_findnew(self, data->id, 0, 0);
+       if (hists == NULL)
+               goto out_free_syms;
+       he = __hists__add_entry(hists, al, parent, data->period);
        if (he == NULL)
-               return -ENOMEM;
-
-       if (hit)
-               he->count += data->period;
-
+               goto out_free_syms;
+       err = 0;
        if (symbol_conf.use_callchain) {
-               if (!hit)
-                       callchain_init(&he->callchain);
-               append_chain(&he->callchain, data->callchain, syms);
-               free(syms);
+               err = append_chain(he->callchain, data->callchain, syms);
+               if (err)
+                       goto out_free_syms;
        }
-
-       return 0;
-}
-
-static int validate_chain(struct ip_callchain *chain, event_t *event)
-{
-       unsigned int chain_size;
-
-       chain_size = event->header.size;
-       chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
-
-       if (chain->nr*sizeof(u64) > chain_size)
-               return -1;
-
-       return 0;
+       /*
+        * Only in the newt browser we are doing integrated annotation,
+        * so we don't allocated the extra space needed because the stdio
+        * code will not use it.
+        */
+       if (use_browser)
+               err = hist_entry__inc_addr_samples(he, al->addr);
+out_free_syms:
+       free(syms);
+       return err;
 }
 
 static int add_event_total(struct perf_session *session,
                           struct sample_data *data,
                           struct perf_event_attr *attr)
 {
-       struct event_stat_id *stats;
+       struct hists *hists;
 
        if (attr)
-               stats = get_stats(session, data->id, attr->type, attr->config);
+               hists = perf_session__hists_findnew(session, data->id,
+                                                   attr->type, attr->config);
        else
-               stats = get_stats(session, data->id, 0, 0);
+               hists = perf_session__hists_findnew(session, data->id, 0, 0);
 
-       if (!stats)
+       if (!hists)
                return -ENOMEM;
 
-       stats->stats.total += data->period;
-       session->events_stats.total += data->period;
+       hists->stats.total_period += data->period;
+       /*
+        * FIXME: add_event_total should be moved from here to
+        * perf_session__process_event so that the proper hist is passed to
+        * the event_op methods.
+        */
+       hists__inc_nr_events(hists, PERF_RECORD_SAMPLE);
+       session->hists.stats.total_period += data->period;
        return 0;
 }
 
@@ -164,7 +165,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
 
                dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
 
-               if (validate_chain(data.callchain, event) < 0) {
+               if (!ip_callchain__valid(data.callchain, event)) {
                        pr_debug("call-chain problem with event, "
                                 "skipping it.\n");
                        return 0;
@@ -187,14 +188,14 @@ static int process_sample_event(event_t *event, struct perf_session *session)
                return 0;
 
        if (perf_session__add_hist_entry(session, &al, &data)) {
-               pr_debug("problem incrementing symbol count, skipping event\n");
+               pr_debug("problem incrementing symbol period, skipping event\n");
                return -1;
        }
 
        attr = perf_header__find_attr(data.id, &session->header);
 
        if (add_event_total(session, &data, attr)) {
-               pr_debug("problem adding event count\n");
+               pr_debug("problem adding event period\n");
                return -1;
        }
 
@@ -260,15 +261,43 @@ static struct perf_event_ops event_ops = {
        .fork   = event__process_task,
        .lost   = event__process_lost,
        .read   = process_read_event,
+       .attr   = event__process_attr,
+       .event_type = event__process_event_type,
+       .tracing_data = event__process_tracing_data,
+       .build_id = event__process_build_id,
 };
 
+extern volatile int session_done;
+
+static void sig_handler(int sig __used)
+{
+       session_done = 1;
+}
+
+static size_t hists__fprintf_nr_sample_events(struct hists *self,
+                                             const char *evname, FILE *fp)
+{
+       size_t ret;
+       char unit;
+       unsigned long nr_events = self->stats.nr_events[PERF_RECORD_SAMPLE];
+
+       nr_events = convert_unit(nr_events, &unit);
+       ret = fprintf(fp, "# Events: %lu%c", nr_events, unit);
+       if (evname != NULL)
+               ret += fprintf(fp, " %s", evname);
+       return ret + fprintf(fp, "\n#\n");
+}
+
 static int __cmd_report(void)
 {
        int ret = -EINVAL;
        struct perf_session *session;
        struct rb_node *next;
+       const char *help = "For a higher level overview, try: perf report --sort comm,dso";
+
+       signal(SIGINT, sig_handler);
 
-       session = perf_session__new(input_name, O_RDONLY, force);
+       session = perf_session__new(input_name, O_RDONLY, force, false);
        if (session == NULL)
                return -ENOMEM;
 
@@ -284,7 +313,7 @@ static int __cmd_report(void)
                goto out_delete;
 
        if (dump_trace) {
-               event__print_totals();
+               perf_session__fprintf_nr_events(session, stdout);
                goto out_delete;
        }
 
@@ -292,39 +321,42 @@ static int __cmd_report(void)
                perf_session__fprintf(session, stdout);
 
        if (verbose > 2)
-               dsos__fprintf(stdout);
+               perf_session__fprintf_dsos(session, stdout);
 
-       next = rb_first(&session->stats_by_id);
+       next = rb_first(&session->hists_tree);
        while (next) {
-               struct event_stat_id *stats;
-
-               stats = rb_entry(next, struct event_stat_id, rb_node);
-               perf_session__collapse_resort(&stats->hists);
-               perf_session__output_resort(&stats->hists, stats->stats.total);
-               if (rb_first(&session->stats_by_id) ==
-                   rb_last(&session->stats_by_id))
-                       fprintf(stdout, "# Samples: %Ld\n#\n",
-                               stats->stats.total);
-               else
-                       fprintf(stdout, "# Samples: %Ld %s\n#\n",
-                               stats->stats.total,
-                               __event_name(stats->type, stats->config));
-
-               perf_session__fprintf_hists(&stats->hists, NULL, false, stdout,
-                                           stats->stats.total);
-               fprintf(stdout, "\n\n");
-               next = rb_next(&stats->rb_node);
+               struct hists *hists;
+
+               hists = rb_entry(next, struct hists, rb_node);
+               hists__collapse_resort(hists);
+               hists__output_resort(hists);
+               if (use_browser)
+                       hists__browse(hists, help, input_name);
+               else {
+                       const char *evname = NULL;
+                       if (rb_first(&session->hists.entries) !=
+                           rb_last(&session->hists.entries))
+                               evname = __event_name(hists->type, hists->config);
+
+                       hists__fprintf_nr_sample_events(hists, evname, stdout);
+
+                       hists__fprintf(hists, NULL, false, stdout);
+                       fprintf(stdout, "\n\n");
+               }
+
+               next = rb_next(&hists->rb_node);
        }
 
-       if (sort_order == default_sort_order &&
-           parent_pattern == default_parent_pattern)
-               fprintf(stdout, "#\n# (For a higher level overview, try: perf report --sort comm,dso)\n#\n");
+       if (!use_browser && sort_order == default_sort_order &&
+           parent_pattern == default_parent_pattern) {
+               fprintf(stdout, "#\n# (%s)\n#\n", help);
 
-       if (show_threads) {
-               bool raw_printing_style = !strcmp(pretty_printing_style, "raw");
-               perf_read_values_display(stdout, &show_threads_values,
-                                        raw_printing_style);
-               perf_read_values_destroy(&show_threads_values);
+               if (show_threads) {
+                       bool style = !strcmp(pretty_printing_style, "raw");
+                       perf_read_values_display(stdout, &show_threads_values,
+                                                style);
+                       perf_read_values_destroy(&show_threads_values);
+               }
        }
 out_delete:
        perf_session__delete(session);
@@ -335,7 +367,7 @@ static int
 parse_callchain_opt(const struct option *opt __used, const char *arg,
                    int unset)
 {
-       char *tok;
+       char *tok, *tok2;
        char *endptr;
 
        /*
@@ -380,10 +412,13 @@ parse_callchain_opt(const struct option *opt __used, const char *arg,
        if (!tok)
                goto setup;
 
+       tok2 = strtok(NULL, ",");
        callchain_param.min_percent = strtod(tok, &endptr);
        if (tok == endptr)
                return -1;
 
+       if (tok2)
+               callchain_param.print_limit = strtod(tok2, &endptr);
 setup:
        if (register_callchain_param(&callchain_param) < 0) {
                fprintf(stderr, "Can't register callchain params\n");
@@ -400,7 +435,7 @@ static const char * const report_usage[] = {
 static const struct option options[] = {
        OPT_STRING('i', "input", &input_name, "file",
                    "input file name"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
@@ -419,12 +454,14 @@ static const struct option options[] = {
                   "sort by key(s): pid, comm, dso, symbol, parent"),
        OPT_BOOLEAN('P', "full-paths", &symbol_conf.full_paths,
                    "Don't shorten the pathnames taking into account the cwd"),
+       OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
+                   "Show sample percentage for different cpu modes"),
        OPT_STRING('p', "parent", &parent_pattern, "regex",
                   "regex filter to identify parent, see: '--sort parent'"),
        OPT_BOOLEAN('x', "exclude-other", &symbol_conf.exclude_other,
                    "Only display entries with parent-match"),
        OPT_CALLBACK_DEFAULT('g', "call-graph", NULL, "output_type,min_percent",
-                    "Display callchains using output_type and min percent threshold. "
+                    "Display callchains using output_type (graph, flat, fractal, or none) and min percent threshold. "
                     "Default: fractal,0.5", &parse_callchain_opt, callchain_default_opt),
        OPT_STRING('d', "dsos", &symbol_conf.dso_list_str, "dso[,dso...]",
                   "only consider symbols in these dsos"),
@@ -447,7 +484,15 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
 {
        argc = parse_options(argc, argv, options, report_usage, 0);
 
-       setup_pager();
+       if (strcmp(input_name, "-") != 0)
+               setup_browser();
+       /*
+        * Only in the newt browser we are doing integrated annotation,
+        * so don't allocate extra space that won't be used in the stdio
+        * implementation.
+        */
+       if (use_browser)
+               symbol_conf.priv_size = sizeof(struct sym_priv);
 
        if (symbol__init() < 0)
                return -1;
@@ -455,7 +500,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
        setup_sorting(report_usage, options);
 
        if (parent_pattern != default_parent_pattern) {
-               sort_dimension__add("parent");
+               if (sort_dimension__add("parent") < 0)
+                       return -1;
                sort_parent.elide = 1;
        } else
                symbol_conf.exclude_other = false;
index 4f5a03e..f67bce2 100644 (file)
@@ -22,7 +22,7 @@
 static char                    const *input_name = "perf.data";
 
 static char                    default_sort_order[] = "avg, max, switch, runtime";
-static char                    *sort_order = default_sort_order;
+static const char              *sort_order = default_sort_order;
 
 static int                     profile_cpu = -1;
 
@@ -68,10 +68,10 @@ enum sched_event_type {
 
 struct sched_atom {
        enum sched_event_type   type;
+       int                     specific_wait;
        u64                     timestamp;
        u64                     duration;
        unsigned long           nr;
-       int                     specific_wait;
        sem_t                   *wait_sem;
        struct task_desc        *wakee;
 };
@@ -105,7 +105,7 @@ static u64                  sum_runtime;
 static u64                     sum_fluct;
 static u64                     run_avg;
 
-static unsigned long           replay_repeat = 10;
+static unsigned int            replay_repeat = 10;
 static unsigned long           nr_timestamps;
 static unsigned long           nr_unordered_timestamps;
 static unsigned long           nr_state_machine_bugs;
@@ -1641,30 +1641,26 @@ static int process_sample_event(event_t *event, struct perf_session *session)
        return 0;
 }
 
-static int process_lost_event(event_t *event __used,
-                             struct perf_session *session __used)
-{
-       nr_lost_chunks++;
-       nr_lost_events += event->lost.lost;
-
-       return 0;
-}
-
 static struct perf_event_ops event_ops = {
-       .sample = process_sample_event,
-       .comm   = event__process_comm,
-       .lost   = process_lost_event,
+       .sample                 = process_sample_event,
+       .comm                   = event__process_comm,
+       .lost                   = event__process_lost,
+       .ordered_samples        = true,
 };
 
 static int read_events(void)
 {
        int err = -EINVAL;
-       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
        if (session == NULL)
                return -ENOMEM;
 
-       if (perf_session__has_traces(session, "record -R"))
+       if (perf_session__has_traces(session, "record -R")) {
                err = perf_session__process_events(session, &event_ops);
+               nr_events      = session->hists.stats.nr_events[0];
+               nr_lost_events = session->hists.stats.total_lost;
+               nr_lost_chunks = session->hists.stats.nr_events[PERF_RECORD_LOST];
+       }
 
        perf_session__delete(session);
        return err;
@@ -1790,7 +1786,7 @@ static const char * const sched_usage[] = {
 static const struct option sched_options[] = {
        OPT_STRING('i', "input", &input_name, "file",
                    "input file name"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
@@ -1805,7 +1801,7 @@ static const char * const latency_usage[] = {
 static const struct option latency_options[] = {
        OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
                   "sort by key(s): runtime, switch, avg, max"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_INTEGER('C', "CPU", &profile_cpu,
                    "CPU to profile on"),
@@ -1820,9 +1816,9 @@ static const char * const replay_usage[] = {
 };
 
 static const struct option replay_options[] = {
-       OPT_INTEGER('r', "repeat", &replay_repeat,
-                   "repeat the workload replay N times (-1: infinite)"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_UINTEGER('r', "repeat", &replay_repeat,
+                    "repeat the workload replay N times (-1: infinite)"),
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
@@ -1850,7 +1846,6 @@ static const char *record_args[] = {
        "record",
        "-a",
        "-R",
-       "-M",
        "-f",
        "-m", "1024",
        "-c", "1",
index 95db31c..ff8c413 100644 (file)
@@ -46,6 +46,7 @@
 #include "util/debug.h"
 #include "util/header.h"
 #include "util/cpumap.h"
+#include "util/thread.h"
 
 #include <sys/prctl.h>
 #include <math.h>
@@ -66,18 +67,21 @@ static struct perf_event_attr default_attrs[] = {
 
 };
 
-static int                     system_wide                     =  0;
+static bool                    system_wide                     =  false;
 static unsigned int            nr_cpus                         =  0;
 static int                     run_idx                         =  0;
 
 static int                     run_count                       =  1;
-static int                     inherit                         =  1;
-static int                     scale                           =  1;
+static bool                    no_inherit                      = false;
+static bool                    scale                           =  true;
 static pid_t                   target_pid                      = -1;
+static pid_t                   target_tid                      = -1;
+static pid_t                   *all_tids                       =  NULL;
+static int                     thread_num                      =  0;
 static pid_t                   child_pid                       = -1;
-static int                     null_run                        =  0;
+static bool                    null_run                        =  false;
 
-static int                     fd[MAX_NR_CPUS][MAX_COUNTERS];
+static int                     *fd[MAX_NR_CPUS][MAX_COUNTERS];
 
 static int                     event_scaled[MAX_COUNTERS];
 
@@ -140,9 +144,11 @@ struct stats                       runtime_branches_stats;
 #define ERR_PERF_OPEN \
 "Error: counter %d, sys_perf_event_open() syscall returned with %d (%s)\n"
 
-static void create_perf_stat_counter(int counter, int pid)
+static int create_perf_stat_counter(int counter)
 {
        struct perf_event_attr *attr = attrs + counter;
+       int thread;
+       int ncreated = 0;
 
        if (scale)
                attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
@@ -152,21 +158,33 @@ static void create_perf_stat_counter(int counter, int pid)
                unsigned int cpu;
 
                for (cpu = 0; cpu < nr_cpus; cpu++) {
-                       fd[cpu][counter] = sys_perf_event_open(attr, -1, cpumap[cpu], -1, 0);
-                       if (fd[cpu][counter] < 0 && verbose)
-                               fprintf(stderr, ERR_PERF_OPEN, counter,
-                                       fd[cpu][counter], strerror(errno));
+                       fd[cpu][counter][0] = sys_perf_event_open(attr,
+                                       -1, cpumap[cpu], -1, 0);
+                       if (fd[cpu][counter][0] < 0)
+                               pr_debug(ERR_PERF_OPEN, counter,
+                                        fd[cpu][counter][0], strerror(errno));
+                       else
+                               ++ncreated;
                }
        } else {
-               attr->inherit        = inherit;
-               attr->disabled       = 1;
-               attr->enable_on_exec = 1;
-
-               fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
-               if (fd[0][counter] < 0 && verbose)
-                       fprintf(stderr, ERR_PERF_OPEN, counter,
-                               fd[0][counter], strerror(errno));
+               attr->inherit = !no_inherit;
+               if (target_pid == -1 && target_tid == -1) {
+                       attr->disabled = 1;
+                       attr->enable_on_exec = 1;
+               }
+               for (thread = 0; thread < thread_num; thread++) {
+                       fd[0][counter][thread] = sys_perf_event_open(attr,
+                               all_tids[thread], -1, -1, 0);
+                       if (fd[0][counter][thread] < 0)
+                               pr_debug(ERR_PERF_OPEN, counter,
+                                        fd[0][counter][thread],
+                                        strerror(errno));
+                       else
+                               ++ncreated;
+               }
        }
+
+       return ncreated;
 }
 
 /*
@@ -190,25 +208,28 @@ static void read_counter(int counter)
        unsigned int cpu;
        size_t res, nv;
        int scaled;
-       int i;
+       int i, thread;
 
        count[0] = count[1] = count[2] = 0;
 
        nv = scale ? 3 : 1;
        for (cpu = 0; cpu < nr_cpus; cpu++) {
-               if (fd[cpu][counter] < 0)
-                       continue;
-
-               res = read(fd[cpu][counter], single_count, nv * sizeof(u64));
-               assert(res == nv * sizeof(u64));
-
-               close(fd[cpu][counter]);
-               fd[cpu][counter] = -1;
-
-               count[0] += single_count[0];
-               if (scale) {
-                       count[1] += single_count[1];
-                       count[2] += single_count[2];
+               for (thread = 0; thread < thread_num; thread++) {
+                       if (fd[cpu][counter][thread] < 0)
+                               continue;
+
+                       res = read(fd[cpu][counter][thread],
+                                       single_count, nv * sizeof(u64));
+                       assert(res == nv * sizeof(u64));
+
+                       close(fd[cpu][counter][thread]);
+                       fd[cpu][counter][thread] = -1;
+
+                       count[0] += single_count[0];
+                       if (scale) {
+                               count[1] += single_count[1];
+                               count[2] += single_count[2];
+                       }
                }
        }
 
@@ -250,10 +271,9 @@ static int run_perf_stat(int argc __used, const char **argv)
 {
        unsigned long long t0, t1;
        int status = 0;
-       int counter;
-       int pid = target_pid;
+       int counter, ncreated = 0;
        int child_ready_pipe[2], go_pipe[2];
-       const bool forks = (target_pid == -1 && argc > 0);
+       const bool forks = (argc > 0);
        char buf;
 
        if (!system_wide)
@@ -265,10 +285,10 @@ static int run_perf_stat(int argc __used, const char **argv)
        }
 
        if (forks) {
-               if ((pid = fork()) < 0)
+               if ((child_pid = fork()) < 0)
                        perror("failed to fork");
 
-               if (!pid) {
+               if (!child_pid) {
                        close(child_ready_pipe[0]);
                        close(go_pipe[1]);
                        fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
@@ -297,7 +317,8 @@ static int run_perf_stat(int argc __used, const char **argv)
                        exit(-1);
                }
 
-               child_pid = pid;
+               if (target_tid == -1 && target_pid == -1 && !system_wide)
+                       all_tids[0] = child_pid;
 
                /*
                 * Wait for the child to be ready to exec.
@@ -310,7 +331,16 @@ static int run_perf_stat(int argc __used, const char **argv)
        }
 
        for (counter = 0; counter < nr_counters; counter++)
-               create_perf_stat_counter(counter, pid);
+               ncreated += create_perf_stat_counter(counter);
+
+       if (ncreated == 0) {
+               pr_err("No permission to collect %sstats.\n"
+                      "Consider tweaking /proc/sys/kernel/perf_event_paranoid.\n",
+                      system_wide ? "system-wide " : "");
+               if (child_pid != -1)
+                       kill(child_pid, SIGTERM);
+               return -1;
+       }
 
        /*
         * Enable counters and exec the command:
@@ -321,7 +351,7 @@ static int run_perf_stat(int argc __used, const char **argv)
                close(go_pipe[1]);
                wait(&status);
        } else {
-               while(!done);
+               while(!done) sleep(1);
        }
 
        t1 = rdclock();
@@ -429,12 +459,14 @@ static void print_stat(int argc, const char **argv)
 
        fprintf(stderr, "\n");
        fprintf(stderr, " Performance counter stats for ");
-       if(target_pid == -1) {
+       if(target_pid == -1 && target_tid == -1) {
                fprintf(stderr, "\'%s", argv[0]);
                for (i = 1; i < argc; i++)
                        fprintf(stderr, " %s", argv[i]);
-       }else
-               fprintf(stderr, "task pid \'%d", target_pid);
+       } else if (target_pid != -1)
+               fprintf(stderr, "process id \'%d", target_pid);
+       else
+               fprintf(stderr, "thread id \'%d", target_tid);
 
        fprintf(stderr, "\'");
        if (run_count > 1)
@@ -459,7 +491,7 @@ static volatile int signr = -1;
 
 static void skip_signal(int signo)
 {
-       if(target_pid != -1)
+       if(child_pid == -1)
                done = 1;
 
        signr = signo;
@@ -486,15 +518,17 @@ static const struct option options[] = {
        OPT_CALLBACK('e', "event", NULL, "event",
                     "event selector. use 'perf list' to list available events",
                     parse_events),
-       OPT_BOOLEAN('i', "inherit", &inherit,
-                   "child tasks inherit counters"),
+       OPT_BOOLEAN('i', "no-inherit", &no_inherit,
+                   "child tasks do not inherit counters"),
        OPT_INTEGER('p', "pid", &target_pid,
-                   "stat events on existing pid"),
+                   "stat events on existing process id"),
+       OPT_INTEGER('t', "tid", &target_tid,
+                   "stat events on existing thread id"),
        OPT_BOOLEAN('a', "all-cpus", &system_wide,
                    "system-wide collection from all CPUs"),
        OPT_BOOLEAN('c', "scale", &scale,
                    "scale/normalize counters"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show counter open errors, etc)"),
        OPT_INTEGER('r', "repeat", &run_count,
                    "repeat command and print average + stddev (max: 100)"),
@@ -506,10 +540,11 @@ static const struct option options[] = {
 int cmd_stat(int argc, const char **argv, const char *prefix __used)
 {
        int status;
+       int i,j;
 
        argc = parse_options(argc, argv, options, stat_usage,
                PARSE_OPT_STOP_AT_NON_OPTION);
-       if (!argc && target_pid == -1)
+       if (!argc && target_pid == -1 && target_tid == -1)
                usage_with_options(stat_usage, options);
        if (run_count <= 0)
                usage_with_options(stat_usage, options);
@@ -525,6 +560,31 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
        else
                nr_cpus = 1;
 
+       if (target_pid != -1) {
+               target_tid = target_pid;
+               thread_num = find_all_tid(target_pid, &all_tids);
+               if (thread_num <= 0) {
+                       fprintf(stderr, "Can't find all threads of pid %d\n",
+                                       target_pid);
+                       usage_with_options(stat_usage, options);
+               }
+       } else {
+               all_tids=malloc(sizeof(pid_t));
+               if (!all_tids)
+                       return -ENOMEM;
+
+               all_tids[0] = target_tid;
+               thread_num = 1;
+       }
+
+       for (i = 0; i < MAX_NR_CPUS; i++) {
+               for (j = 0; j < MAX_COUNTERS; j++) {
+                       fd[i][j] = malloc(sizeof(int)*thread_num);
+                       if (!fd[i][j])
+                               return -ENOMEM;
+               }
+       }
+
        /*
         * We dont want to block the signals - that would cause
         * child tasks to inherit that and Ctrl-C would not work.
@@ -543,7 +603,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
                status = run_perf_stat(argc, argv);
        }
 
-       print_stat(argc, argv);
+       if (status != -1)
+               print_stat(argc, argv);
 
        return status;
 }
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
new file mode 100644 (file)
index 0000000..035b9fa
--- /dev/null
@@ -0,0 +1,281 @@
+/*
+ * builtin-test.c
+ *
+ * Builtin regression testing command: ever growing number of sanity tests
+ */
+#include "builtin.h"
+
+#include "util/cache.h"
+#include "util/debug.h"
+#include "util/parse-options.h"
+#include "util/session.h"
+#include "util/symbol.h"
+#include "util/thread.h"
+
+static long page_size;
+
+static int vmlinux_matches_kallsyms_filter(struct map *map __used, struct symbol *sym)
+{
+       bool *visited = symbol__priv(sym);
+       *visited = true;
+       return 0;
+}
+
+static int test__vmlinux_matches_kallsyms(void)
+{
+       int err = -1;
+       struct rb_node *nd;
+       struct symbol *sym;
+       struct map *kallsyms_map, *vmlinux_map;
+       struct machine kallsyms, vmlinux;
+       enum map_type type = MAP__FUNCTION;
+       struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
+
+       /*
+        * Step 1:
+        *
+        * Init the machines that will hold kernel, modules obtained from
+        * both vmlinux + .ko files and from /proc/kallsyms split by modules.
+        */
+       machine__init(&kallsyms, "", HOST_KERNEL_ID);
+       machine__init(&vmlinux, "", HOST_KERNEL_ID);
+
+       /*
+        * Step 2:
+        *
+        * Create the kernel maps for kallsyms and the DSO where we will then
+        * load /proc/kallsyms. Also create the modules maps from /proc/modules
+        * and find the .ko files that match them in /lib/modules/`uname -r`/.
+        */
+       if (machine__create_kernel_maps(&kallsyms) < 0) {
+               pr_debug("machine__create_kernel_maps ");
+               return -1;
+       }
+
+       /*
+        * Step 3:
+        *
+        * Load and split /proc/kallsyms into multiple maps, one per module.
+        */
+       if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) {
+               pr_debug("dso__load_kallsyms ");
+               goto out;
+       }
+
+       /*
+        * Step 4:
+        *
+        * kallsyms will be internally on demand sorted by name so that we can
+        * find the reference relocation * symbol, i.e. the symbol we will use
+        * to see if the running kernel was relocated by checking if it has the
+        * same value in the vmlinux file we load.
+        */
+       kallsyms_map = machine__kernel_map(&kallsyms, type);
+
+       sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL);
+       if (sym == NULL) {
+               pr_debug("dso__find_symbol_by_name ");
+               goto out;
+       }
+
+       ref_reloc_sym.addr = sym->start;
+
+       /*
+        * Step 5:
+        *
+        * Now repeat step 2, this time for the vmlinux file we'll auto-locate.
+        */
+       if (machine__create_kernel_maps(&vmlinux) < 0) {
+               pr_debug("machine__create_kernel_maps ");
+               goto out;
+       }
+
+       vmlinux_map = machine__kernel_map(&vmlinux, type);
+       map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym;
+
+       /*
+        * Step 6:
+        *
+        * Locate a vmlinux file in the vmlinux path that has a buildid that
+        * matches the one of the running kernel.
+        *
+        * While doing that look if we find the ref reloc symbol, if we find it
+        * we'll have its ref_reloc_symbol.unrelocated_addr and then
+        * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines
+        * to fixup the symbols.
+        */
+       if (machine__load_vmlinux_path(&vmlinux, type,
+                                      vmlinux_matches_kallsyms_filter) <= 0) {
+               pr_debug("machine__load_vmlinux_path ");
+               goto out;
+       }
+
+       err = 0;
+       /*
+        * Step 7:
+        *
+        * Now look at the symbols in the vmlinux DSO and check if we find all of them
+        * in the kallsyms dso. For the ones that are in both, check its names and
+        * end addresses too.
+        */
+       for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) {
+               struct symbol *pair;
+
+               sym  = rb_entry(nd, struct symbol, rb_node);
+               pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL);
+
+               if (pair && pair->start == sym->start) {
+next_pair:
+                       if (strcmp(sym->name, pair->name) == 0) {
+                               /*
+                                * kallsyms don't have the symbol end, so we
+                                * set that by using the next symbol start - 1,
+                                * in some cases we get this up to a page
+                                * wrong, trace_kmalloc when I was developing
+                                * this code was one such example, 2106 bytes
+                                * off the real size. More than that and we
+                                * _really_ have a problem.
+                                */
+                               s64 skew = sym->end - pair->end;
+                               if (llabs(skew) < page_size)
+                                       continue;
+
+                               pr_debug("%#Lx: diff end addr for %s v: %#Lx k: %#Lx\n",
+                                        sym->start, sym->name, sym->end, pair->end);
+                       } else {
+                               struct rb_node *nnd = rb_prev(&pair->rb_node);
+
+                               if (nnd) {
+                                       struct symbol *next = rb_entry(nnd, struct symbol, rb_node);
+
+                                       if (next->start == sym->start) {
+                                               pair = next;
+                                               goto next_pair;
+                                       }
+                               }
+                               pr_debug("%#Lx: diff name v: %s k: %s\n",
+                                        sym->start, sym->name, pair->name);
+                       }
+               } else
+                       pr_debug("%#Lx: %s not on kallsyms\n", sym->start, sym->name);
+
+               err = -1;
+       }
+
+       if (!verbose)
+               goto out;
+
+       pr_info("Maps only in vmlinux:\n");
+
+       for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
+               struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
+               /*
+                * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
+                * the kernel will have the path for the vmlinux file being used,
+                * so use the short name, less descriptive but the same ("[kernel]" in
+                * both cases.
+                */
+               pair = map_groups__find_by_name(&kallsyms.kmaps, type,
+                                               (pos->dso->kernel ?
+                                                       pos->dso->short_name :
+                                                       pos->dso->name));
+               if (pair)
+                       pair->priv = 1;
+               else
+                       map__fprintf(pos, stderr);
+       }
+
+       pr_info("Maps in vmlinux with a different name in kallsyms:\n");
+
+       for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
+               struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
+
+               pair = map_groups__find(&kallsyms.kmaps, type, pos->start);
+               if (pair == NULL || pair->priv)
+                       continue;
+
+               if (pair->start == pos->start) {
+                       pair->priv = 1;
+                       pr_info(" %Lx-%Lx %Lx %s in kallsyms as",
+                               pos->start, pos->end, pos->pgoff, pos->dso->name);
+                       if (pos->pgoff != pair->pgoff || pos->end != pair->end)
+                               pr_info(": \n*%Lx-%Lx %Lx",
+                                       pair->start, pair->end, pair->pgoff);
+                       pr_info(" %s\n", pair->dso->name);
+                       pair->priv = 1;
+               }
+       }
+
+       pr_info("Maps only in kallsyms:\n");
+
+       for (nd = rb_first(&kallsyms.kmaps.maps[type]);
+            nd; nd = rb_next(nd)) {
+               struct map *pos = rb_entry(nd, struct map, rb_node);
+
+               if (!pos->priv)
+                       map__fprintf(pos, stderr);
+       }
+out:
+       return err;
+}
+
+static struct test {
+       const char *desc;
+       int (*func)(void);
+} tests[] = {
+       {
+               .desc = "vmlinux symtab matches kallsyms",
+               .func = test__vmlinux_matches_kallsyms,
+       },
+       {
+               .func = NULL,
+       },
+};
+
+static int __cmd_test(void)
+{
+       int i = 0;
+
+       page_size = sysconf(_SC_PAGE_SIZE);
+
+       while (tests[i].func) {
+               int err;
+               pr_info("%2d: %s:", i + 1, tests[i].desc);
+               pr_debug("\n--- start ---\n");
+               err = tests[i].func();
+               pr_debug("---- end ----\n%s:", tests[i].desc);
+               pr_info(" %s\n", err ? "FAILED!\n" : "Ok");
+               ++i;
+       }
+
+       return 0;
+}
+
+static const char * const test_usage[] = {
+       "perf test [<options>]",
+       NULL,
+};
+
+static const struct option test_options[] = {
+       OPT_INTEGER('v', "verbose", &verbose,
+                   "be more verbose (show symbol address, etc)"),
+       OPT_END()
+};
+
+int cmd_test(int argc, const char **argv, const char *prefix __used)
+{
+       argc = parse_options(argc, argv, test_options, test_usage, 0);
+       if (argc)
+               usage_with_options(test_usage, test_options);
+
+       symbol_conf.priv_size = sizeof(int);
+       symbol_conf.sort_by_name = true;
+       symbol_conf.try_vmlinux_path = true;
+
+       if (symbol__init() < 0)
+               return -1;
+
+       setup_pager();
+
+       return __cmd_test();
+}
index 0d4d8ff..5a52ed9 100644 (file)
@@ -21,7 +21,6 @@
 #include "util/cache.h"
 #include <linux/rbtree.h>
 #include "util/symbol.h"
-#include "util/string.h"
 #include "util/callchain.h"
 #include "util/strlist.h"
 
@@ -43,7 +42,7 @@ static u64            turbo_frequency;
 
 static u64             first_time, last_time;
 
-static int             power_only;
+static bool            power_only;
 
 
 struct per_pid;
@@ -78,8 +77,6 @@ struct per_pid {
 
        struct per_pidcomm *all;
        struct per_pidcomm *current;
-
-       int painted;
 };
 
 
@@ -146,9 +143,6 @@ struct wake_event {
 static struct power_event    *power_events;
 static struct wake_event     *wake_events;
 
-struct sample_wrapper *all_samples;
-
-
 struct process_filter;
 struct process_filter {
        char                    *name;
@@ -569,88 +563,6 @@ static void end_sample_processing(void)
        }
 }
 
-static u64 sample_time(event_t *event, const struct perf_session *session)
-{
-       int cursor;
-
-       cursor = 0;
-       if (session->sample_type & PERF_SAMPLE_IP)
-               cursor++;
-       if (session->sample_type & PERF_SAMPLE_TID)
-               cursor++;
-       if (session->sample_type & PERF_SAMPLE_TIME)
-               return event->sample.array[cursor];
-       return 0;
-}
-
-
-/*
- * We first queue all events, sorted backwards by insertion.
- * The order will get flipped later.
- */
-static int queue_sample_event(event_t *event, struct perf_session *session)
-{
-       struct sample_wrapper *copy, *prev;
-       int size;
-
-       size = event->sample.header.size + sizeof(struct sample_wrapper) + 8;
-
-       copy = malloc(size);
-       if (!copy)
-               return 1;
-
-       memset(copy, 0, size);
-
-       copy->next = NULL;
-       copy->timestamp = sample_time(event, session);
-
-       memcpy(&copy->data, event, event->sample.header.size);
-
-       /* insert in the right place in the list */
-
-       if (!all_samples) {
-               /* first sample ever */
-               all_samples = copy;
-               return 0;
-       }
-
-       if (all_samples->timestamp < copy->timestamp) {
-               /* insert at the head of the list */
-               copy->next = all_samples;
-               all_samples = copy;
-               return 0;
-       }
-
-       prev = all_samples;
-       while (prev->next) {
-               if (prev->next->timestamp < copy->timestamp) {
-                       copy->next = prev->next;
-                       prev->next = copy;
-                       return 0;
-               }
-               prev = prev->next;
-       }
-       /* insert at the end of the list */
-       prev->next = copy;
-
-       return 0;
-}
-
-static void sort_queued_samples(void)
-{
-       struct sample_wrapper *cursor, *next;
-
-       cursor = all_samples;
-       all_samples = NULL;
-
-       while (cursor) {
-               next = cursor->next;
-               cursor->next = all_samples;
-               all_samples = cursor;
-               cursor = next;
-       }
-}
-
 /*
  * Sort the pid datastructure
  */
@@ -1014,31 +926,17 @@ static void write_svg_file(const char *filename)
        svg_close();
 }
 
-static void process_samples(struct perf_session *session)
-{
-       struct sample_wrapper *cursor;
-       event_t *event;
-
-       sort_queued_samples();
-
-       cursor = all_samples;
-       while (cursor) {
-               event = (void *)&cursor->data;
-               cursor = cursor->next;
-               process_sample_event(event, session);
-       }
-}
-
 static struct perf_event_ops event_ops = {
-       .comm   = process_comm_event,
-       .fork   = process_fork_event,
-       .exit   = process_exit_event,
-       .sample = queue_sample_event,
+       .comm                   = process_comm_event,
+       .fork                   = process_fork_event,
+       .exit                   = process_exit_event,
+       .sample                 = process_sample_event,
+       .ordered_samples        = true,
 };
 
 static int __cmd_timechart(void)
 {
-       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
+       struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
        int ret = -EINVAL;
 
        if (session == NULL)
@@ -1051,8 +949,6 @@ static int __cmd_timechart(void)
        if (ret)
                goto out_delete;
 
-       process_samples(session);
-
        end_sample_processing();
 
        sort_pids();
@@ -1075,7 +971,6 @@ static const char *record_args[] = {
        "record",
        "-a",
        "-R",
-       "-M",
        "-f",
        "-c", "1",
        "-e", "power:power_start",
index 1f52932..397290a 100644 (file)
@@ -55,9 +55,9 @@
 #include <linux/unistd.h>
 #include <linux/types.h>
 
-static int                     fd[MAX_NR_CPUS][MAX_COUNTERS];
+static int                     *fd[MAX_NR_CPUS][MAX_COUNTERS];
 
-static int                     system_wide                     =      0;
+static bool                    system_wide                     =  false;
 
 static int                     default_interval                =      0;
 
@@ -65,18 +65,21 @@ static int                  count_filter                    =      5;
 static int                     print_entries;
 
 static int                     target_pid                      =     -1;
-static int                     inherit                         =      0;
+static int                     target_tid                      =     -1;
+static pid_t                   *all_tids                       =      NULL;
+static int                     thread_num                      =      0;
+static bool                    inherit                         =  false;
 static int                     profile_cpu                     =     -1;
 static int                     nr_cpus                         =      0;
-static unsigned int            realtime_prio                   =      0;
-static int                     group                           =      0;
+static int                     realtime_prio                   =      0;
+static bool                    group                           =  false;
 static unsigned int            page_size;
 static unsigned int            mmap_pages                      =     16;
 static int                     freq                            =   1000; /* 1 KHz */
 
 static int                     delay_secs                      =      2;
-static int                     zero                            =      0;
-static int                     dump_symtab                     =      0;
+static bool                    zero                            =  false;
+static bool                    dump_symtab                     =  false;
 
 static bool                    hide_kernel_symbols             =  false;
 static bool                    hide_user_symbols               =  false;
@@ -93,7 +96,7 @@ struct source_line {
        struct source_line      *next;
 };
 
-static char                    *sym_filter                     =   NULL;
+static const char              *sym_filter                     =   NULL;
 struct sym_entry               *sym_filter_entry               =   NULL;
 struct sym_entry               *sym_filter_entry_sched         =   NULL;
 static int                     sym_pcnt_filter                 =      5;
@@ -133,7 +136,7 @@ static inline struct symbol *sym_entry__symbol(struct sym_entry *self)
        return ((void *)self) + symbol_conf.priv_size;
 }
 
-static void get_term_dimensions(struct winsize *ws)
+void get_term_dimensions(struct winsize *ws)
 {
        char *s = getenv("LINES");
 
@@ -169,7 +172,7 @@ static void sig_winch_handler(int sig __used)
        update_print_entries(&winsize);
 }
 
-static void parse_source(struct sym_entry *syme)
+static int parse_source(struct sym_entry *syme)
 {
        struct symbol *sym;
        struct sym_entry_source *source;
@@ -180,12 +183,21 @@ static void parse_source(struct sym_entry *syme)
        u64 len;
 
        if (!syme)
-               return;
+               return -1;
+
+       sym = sym_entry__symbol(syme);
+       map = syme->map;
+
+       /*
+        * We can't annotate with just /proc/kallsyms
+        */
+       if (map->dso->origin == DSO__ORIG_KERNEL)
+               return -1;
 
        if (syme->src == NULL) {
                syme->src = zalloc(sizeof(*source));
                if (syme->src == NULL)
-                       return;
+                       return -1;
                pthread_mutex_init(&syme->src->lock, NULL);
        }
 
@@ -195,9 +207,6 @@ static void parse_source(struct sym_entry *syme)
                pthread_mutex_lock(&source->lock);
                goto out_assign;
        }
-
-       sym = sym_entry__symbol(syme);
-       map = syme->map;
        path = map->dso->long_name;
 
        len = sym->end - sym->start;
@@ -209,7 +218,7 @@ static void parse_source(struct sym_entry *syme)
 
        file = popen(command, "r");
        if (!file)
-               return;
+               return -1;
 
        pthread_mutex_lock(&source->lock);
        source->lines_tail = &source->lines;
@@ -245,6 +254,7 @@ static void parse_source(struct sym_entry *syme)
 out_assign:
        sym_filter_entry = syme;
        pthread_mutex_unlock(&source->lock);
+       return 0;
 }
 
 static void __zero_source_counters(struct sym_entry *syme)
@@ -410,7 +420,9 @@ static double sym_weight(const struct sym_entry *sym)
 }
 
 static long                    samples;
-static long                    userspace_samples;
+static long                    kernel_samples, us_samples;
+static long                    exact_samples;
+static long                    guest_us_samples, guest_kernel_samples;
 static const char              CONSOLE_CLEAR[] = "\e[H\e[2J";
 
 static void __list_insert_active_sym(struct sym_entry *syme)
@@ -450,7 +462,11 @@ static void print_sym_table(void)
        int printed = 0, j;
        int counter, snap = !display_weighted ? sym_counter : 0;
        float samples_per_sec = samples/delay_secs;
-       float ksamples_per_sec = (samples-userspace_samples)/delay_secs;
+       float ksamples_per_sec = kernel_samples/delay_secs;
+       float us_samples_per_sec = (us_samples)/delay_secs;
+       float guest_kernel_samples_per_sec = (guest_kernel_samples)/delay_secs;
+       float guest_us_samples_per_sec = (guest_us_samples)/delay_secs;
+       float esamples_percent = (100.0*exact_samples)/samples;
        float sum_ksamples = 0.0;
        struct sym_entry *syme, *n;
        struct rb_root tmp = RB_ROOT;
@@ -458,7 +474,8 @@ static void print_sym_table(void)
        int sym_width = 0, dso_width = 0, dso_short_width = 0;
        const int win_width = winsize.ws_col - 1;
 
-       samples = userspace_samples = 0;
+       samples = us_samples = kernel_samples = exact_samples = 0;
+       guest_kernel_samples = guest_us_samples = 0;
 
        /* Sort the active symbols */
        pthread_mutex_lock(&active_symbols_lock);
@@ -489,9 +506,30 @@ static void print_sym_table(void)
        puts(CONSOLE_CLEAR);
 
        printf("%-*.*s\n", win_width, win_width, graph_dotted_line);
-       printf( "   PerfTop:%8.0f irqs/sec  kernel:%4.1f%% [",
-               samples_per_sec,
-               100.0 - (100.0*((samples_per_sec-ksamples_per_sec)/samples_per_sec)));
+       if (!perf_guest) {
+               printf("   PerfTop:%8.0f irqs/sec  kernel:%4.1f%%"
+                       "  exact: %4.1f%% [",
+                       samples_per_sec,
+                       100.0 - (100.0 * ((samples_per_sec - ksamples_per_sec) /
+                                        samples_per_sec)),
+                       esamples_percent);
+       } else {
+               printf("   PerfTop:%8.0f irqs/sec  kernel:%4.1f%% us:%4.1f%%"
+                       " guest kernel:%4.1f%% guest us:%4.1f%%"
+                       " exact: %4.1f%% [",
+                       samples_per_sec,
+                       100.0 - (100.0 * ((samples_per_sec-ksamples_per_sec) /
+                                         samples_per_sec)),
+                       100.0 - (100.0 * ((samples_per_sec-us_samples_per_sec) /
+                                         samples_per_sec)),
+                       100.0 - (100.0 * ((samples_per_sec -
+                                               guest_kernel_samples_per_sec) /
+                                         samples_per_sec)),
+                       100.0 - (100.0 * ((samples_per_sec -
+                                          guest_us_samples_per_sec) /
+                                         samples_per_sec)),
+                       esamples_percent);
+       }
 
        if (nr_counters == 1 || !display_weighted) {
                printf("%Ld", (u64)attrs[0].sample_period);
@@ -514,13 +552,15 @@ static void print_sym_table(void)
 
        if (target_pid != -1)
                printf(" (target_pid: %d", target_pid);
+       else if (target_tid != -1)
+               printf(" (target_tid: %d", target_tid);
        else
                printf(" (all");
 
        if (profile_cpu != -1)
                printf(", cpu: %d)\n", profile_cpu);
        else {
-               if (target_pid != -1)
+               if (target_tid != -1)
                        printf(")\n");
                else
                        printf(", %d CPUs)\n", nr_cpus);
@@ -582,7 +622,6 @@ static void print_sym_table(void)
 
                syme = rb_entry(nd, struct sym_entry, rb_node);
                sym = sym_entry__symbol(syme);
-
                if (++printed > print_entries || (int)syme->snap_count < count_filter)
                        continue;
 
@@ -746,7 +785,7 @@ static int key_mapped(int c)
        return 0;
 }
 
-static void handle_keypress(int c)
+static void handle_keypress(struct perf_session *session, int c)
 {
        if (!key_mapped(c)) {
                struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
@@ -815,7 +854,7 @@ static void handle_keypress(int c)
                case 'Q':
                        printf("exiting.\n");
                        if (dump_symtab)
-                               dsos__fprintf(stderr);
+                               perf_session__fprintf_dsos(session, stderr);
                        exit(0);
                case 's':
                        prompt_symbol(&sym_filter_entry, "Enter details symbol");
@@ -839,7 +878,7 @@ static void handle_keypress(int c)
                        display_weighted = ~display_weighted;
                        break;
                case 'z':
-                       zero = ~zero;
+                       zero = !zero;
                        break;
                default:
                        break;
@@ -851,6 +890,7 @@ static void *display_thread(void *arg __used)
        struct pollfd stdin_poll = { .fd = 0, .events = POLLIN };
        struct termios tc, save;
        int delay_msecs, c;
+       struct perf_session *session = (struct perf_session *) arg;
 
        tcgetattr(0, &save);
        tc = save;
@@ -871,7 +911,7 @@ repeat:
        c = getc(stdin);
        tcsetattr(0, TCSAFLUSH, &save);
 
-       handle_keypress(c);
+       handle_keypress(session, c);
        goto repeat;
 
        return NULL;
@@ -942,24 +982,48 @@ static void event__process_sample(const event_t *self,
        u64 ip = self->ip.ip;
        struct sym_entry *syme;
        struct addr_location al;
+       struct machine *machine;
        u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
        ++samples;
 
        switch (origin) {
        case PERF_RECORD_MISC_USER:
-               ++userspace_samples;
+               ++us_samples;
                if (hide_user_symbols)
                        return;
+               machine = perf_session__find_host_machine(session);
                break;
        case PERF_RECORD_MISC_KERNEL:
+               ++kernel_samples;
                if (hide_kernel_symbols)
                        return;
+               machine = perf_session__find_host_machine(session);
+               break;
+       case PERF_RECORD_MISC_GUEST_KERNEL:
+               ++guest_kernel_samples;
+               machine = perf_session__find_machine(session, self->ip.pid);
                break;
+       case PERF_RECORD_MISC_GUEST_USER:
+               ++guest_us_samples;
+               /*
+                * TODO: we don't process guest user from host side
+                * except simple counting.
+                */
+               return;
        default:
                return;
        }
 
+       if (!machine && perf_guest) {
+               pr_err("Can't find guest [%d]'s kernel information\n",
+                       self->ip.pid);
+               return;
+       }
+
+       if (self->header.misc & PERF_RECORD_MISC_EXACT_IP)
+               exact_samples++;
+
        if (event__preprocess_sample(self, session, &al, symbol_filter) < 0 ||
            al.filtered)
                return;
@@ -976,7 +1040,7 @@ static void event__process_sample(const event_t *self,
                 * --hide-kernel-symbols, even if the user specifies an
                 * invalid --vmlinux ;-)
                 */
-               if (al.map == session->vmlinux_maps[MAP__FUNCTION] &&
+               if (al.map == machine->vmlinux_maps[MAP__FUNCTION] &&
                    RB_EMPTY_ROOT(&al.map->dso->symbols[MAP__FUNCTION])) {
                        pr_err("The %s file can't be used\n",
                               symbol_conf.vmlinux_name);
@@ -990,7 +1054,17 @@ static void event__process_sample(const event_t *self,
        if (sym_filter_entry_sched) {
                sym_filter_entry = sym_filter_entry_sched;
                sym_filter_entry_sched = NULL;
-               parse_source(sym_filter_entry);
+               if (parse_source(sym_filter_entry) < 0) {
+                       struct symbol *sym = sym_entry__symbol(sym_filter_entry);
+
+                       pr_err("Can't annotate %s", sym->name);
+                       if (sym_filter_entry->map->dso->origin == DSO__ORIG_KERNEL) {
+                               pr_err(": No vmlinux file was found in the path:\n");
+                               vmlinux_path__fprintf(stderr);
+                       } else
+                               pr_err(".\n");
+                       exit(1);
+               }
        }
 
        syme = symbol__priv(al.sym);
@@ -1106,16 +1180,21 @@ static void perf_session__mmap_read_counter(struct perf_session *self,
        md->prev = old;
 }
 
-static struct pollfd event_array[MAX_NR_CPUS * MAX_COUNTERS];
-static struct mmap_data mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
+static struct pollfd *event_array;
+static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
 
 static void perf_session__mmap_read(struct perf_session *self)
 {
-       int i, counter;
+       int i, counter, thread_index;
 
        for (i = 0; i < nr_cpus; i++) {
                for (counter = 0; counter < nr_counters; counter++)
-                       perf_session__mmap_read_counter(self, &mmap_array[i][counter]);
+                       for (thread_index = 0;
+                               thread_index < thread_num;
+                               thread_index++) {
+                               perf_session__mmap_read_counter(self,
+                                       &mmap_array[i][counter][thread_index]);
+                       }
        }
 }
 
@@ -1126,9 +1205,10 @@ static void start_counter(int i, int counter)
 {
        struct perf_event_attr *attr;
        int cpu;
+       int thread_index;
 
        cpu = profile_cpu;
-       if (target_pid == -1 && profile_cpu == -1)
+       if (target_tid == -1 && profile_cpu == -1)
                cpu = cpumap[i];
 
        attr = attrs + counter;
@@ -1144,55 +1224,58 @@ static void start_counter(int i, int counter)
        attr->inherit           = (cpu < 0) && inherit;
        attr->mmap              = 1;
 
+       for (thread_index = 0; thread_index < thread_num; thread_index++) {
 try_again:
-       fd[i][counter] = sys_perf_event_open(attr, target_pid, cpu, group_fd, 0);
-
-       if (fd[i][counter] < 0) {
-               int err = errno;
+               fd[i][counter][thread_index] = sys_perf_event_open(attr,
+                               all_tids[thread_index], cpu, group_fd, 0);
+
+               if (fd[i][counter][thread_index] < 0) {
+                       int err = errno;
+
+                       if (err == EPERM || err == EACCES)
+                               die("No permission - are you root?\n");
+                       /*
+                        * If it's cycles then fall back to hrtimer
+                        * based cpu-clock-tick sw counter, which
+                        * is always available even if no PMU support:
+                        */
+                       if (attr->type == PERF_TYPE_HARDWARE
+                                       && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
+
+                               if (verbose)
+                                       warning(" ... trying to fall back to cpu-clock-ticks\n");
+
+                               attr->type = PERF_TYPE_SOFTWARE;
+                               attr->config = PERF_COUNT_SW_CPU_CLOCK;
+                               goto try_again;
+                       }
+                       printf("\n");
+                       error("perfcounter syscall returned with %d (%s)\n",
+                                       fd[i][counter][thread_index], strerror(err));
+                       die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
+                       exit(-1);
+               }
+               assert(fd[i][counter][thread_index] >= 0);
+               fcntl(fd[i][counter][thread_index], F_SETFL, O_NONBLOCK);
 
-               if (err == EPERM || err == EACCES)
-                       die("No permission - are you root?\n");
                /*
-                * If it's cycles then fall back to hrtimer
-                * based cpu-clock-tick sw counter, which
-                * is always available even if no PMU support:
+                * First counter acts as the group leader:
                 */
-               if (attr->type == PERF_TYPE_HARDWARE
-                       && attr->config == PERF_COUNT_HW_CPU_CYCLES) {
-
-                       if (verbose)
-                               warning(" ... trying to fall back to cpu-clock-ticks\n");
-
-                       attr->type = PERF_TYPE_SOFTWARE;
-                       attr->config = PERF_COUNT_SW_CPU_CLOCK;
-                       goto try_again;
-               }
-               printf("\n");
-               error("perfcounter syscall returned with %d (%s)\n",
-                       fd[i][counter], strerror(err));
-               die("No CONFIG_PERF_EVENTS=y kernel support configured?\n");
-               exit(-1);
+               if (group && group_fd == -1)
+                       group_fd = fd[i][counter][thread_index];
+
+               event_array[nr_poll].fd = fd[i][counter][thread_index];
+               event_array[nr_poll].events = POLLIN;
+               nr_poll++;
+
+               mmap_array[i][counter][thread_index].counter = counter;
+               mmap_array[i][counter][thread_index].prev = 0;
+               mmap_array[i][counter][thread_index].mask = mmap_pages*page_size - 1;
+               mmap_array[i][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size,
+                               PROT_READ, MAP_SHARED, fd[i][counter][thread_index], 0);
+               if (mmap_array[i][counter][thread_index].base == MAP_FAILED)
+                       die("failed to mmap with %d (%s)\n", errno, strerror(errno));
        }
-       assert(fd[i][counter] >= 0);
-       fcntl(fd[i][counter], F_SETFL, O_NONBLOCK);
-
-       /*
-        * First counter acts as the group leader:
-        */
-       if (group && group_fd == -1)
-               group_fd = fd[i][counter];
-
-       event_array[nr_poll].fd = fd[i][counter];
-       event_array[nr_poll].events = POLLIN;
-       nr_poll++;
-
-       mmap_array[i][counter].counter = counter;
-       mmap_array[i][counter].prev = 0;
-       mmap_array[i][counter].mask = mmap_pages*page_size - 1;
-       mmap_array[i][counter].base = mmap(NULL, (mmap_pages+1)*page_size,
-                       PROT_READ, MAP_SHARED, fd[i][counter], 0);
-       if (mmap_array[i][counter].base == MAP_FAILED)
-               die("failed to mmap with %d (%s)\n", errno, strerror(errno));
 }
 
 static int __cmd_top(void)
@@ -1204,12 +1287,12 @@ static int __cmd_top(void)
         * FIXME: perf_session__new should allow passing a O_MMAP, so that all this
         * mmap reading, etc is encapsulated in it. Use O_WRONLY for now.
         */
-       struct perf_session *session = perf_session__new(NULL, O_WRONLY, false);
+       struct perf_session *session = perf_session__new(NULL, O_WRONLY, false, false);
        if (session == NULL)
                return -ENOMEM;
 
-       if (target_pid != -1)
-               event__synthesize_thread(target_pid, event__process, session);
+       if (target_tid != -1)
+               event__synthesize_thread(target_tid, event__process, session);
        else
                event__synthesize_threads(event__process, session);
 
@@ -1220,11 +1303,11 @@ static int __cmd_top(void)
        }
 
        /* Wait for a minimal set of events before starting the snapshot */
-       poll(event_array, nr_poll, 100);
+       poll(&event_array[0], nr_poll, 100);
 
        perf_session__mmap_read(session);
 
-       if (pthread_create(&thread, NULL, display_thread, NULL)) {
+       if (pthread_create(&thread, NULL, display_thread, session)) {
                printf("Could not create display thread.\n");
                exit(-1);
        }
@@ -1263,7 +1346,9 @@ static const struct option options[] = {
        OPT_INTEGER('c', "count", &default_interval,
                    "event period to sample"),
        OPT_INTEGER('p', "pid", &target_pid,
-                   "profile events on existing pid"),
+                   "profile events on existing process id"),
+       OPT_INTEGER('t', "tid", &target_tid,
+                   "profile events on existing thread id"),
        OPT_BOOLEAN('a', "all-cpus", &system_wide,
                            "system-wide collection from all CPUs"),
        OPT_INTEGER('C', "CPU", &profile_cpu,
@@ -1272,8 +1357,7 @@ static const struct option options[] = {
                   "file", "vmlinux pathname"),
        OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols,
                    "hide kernel symbols"),
-       OPT_INTEGER('m', "mmap-pages", &mmap_pages,
-                   "number of mmap data pages"),
+       OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"),
        OPT_INTEGER('r', "realtime", &realtime_prio,
                    "collect data with this RT SCHED_FIFO priority"),
        OPT_INTEGER('d', "delay", &delay_secs,
@@ -1296,7 +1380,7 @@ static const struct option options[] = {
                    "display this many functions"),
        OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols,
                    "hide user symbols"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show counter open errors, etc)"),
        OPT_END()
 };
@@ -1304,6 +1388,7 @@ static const struct option options[] = {
 int cmd_top(int argc, const char **argv, const char *prefix __used)
 {
        int counter;
+       int i,j;
 
        page_size = sysconf(_SC_PAGE_SIZE);
 
@@ -1311,8 +1396,39 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
        if (argc)
                usage_with_options(top_usage, options);
 
+       if (target_pid != -1) {
+               target_tid = target_pid;
+               thread_num = find_all_tid(target_pid, &all_tids);
+               if (thread_num <= 0) {
+                       fprintf(stderr, "Can't find all threads of pid %d\n",
+                               target_pid);
+                       usage_with_options(top_usage, options);
+               }
+       } else {
+               all_tids=malloc(sizeof(pid_t));
+               if (!all_tids)
+                       return -ENOMEM;
+
+               all_tids[0] = target_tid;
+               thread_num = 1;
+       }
+
+       for (i = 0; i < MAX_NR_CPUS; i++) {
+               for (j = 0; j < MAX_COUNTERS; j++) {
+                       fd[i][j] = malloc(sizeof(int)*thread_num);
+                       mmap_array[i][j] = zalloc(
+                               sizeof(struct mmap_data)*thread_num);
+                       if (!fd[i][j] || !mmap_array[i][j])
+                               return -ENOMEM;
+               }
+       }
+       event_array = malloc(
+               sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num);
+       if (!event_array)
+               return -ENOMEM;
+
        /* CPU and PID are mutually exclusive */
-       if (target_pid != -1 && profile_cpu != -1) {
+       if (target_tid > 0 && profile_cpu != -1) {
                printf("WARNING: PID switch overriding CPU\n");
                sleep(1);
                profile_cpu = -1;
@@ -1353,7 +1469,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
                attrs[counter].sample_period = default_interval;
        }
 
-       if (target_pid != -1 || profile_cpu != -1)
+       if (target_tid != -1 || profile_cpu != -1)
                nr_cpus = 1;
        else
                nr_cpus = read_cpu_map();
index 407041d..dddf3f0 100644 (file)
@@ -11,6 +11,8 @@
 
 static char const              *script_name;
 static char const              *generate_script_lang;
+static bool                    debug_ordering;
+static u64                     last_timestamp;
 
 static int default_start_script(const char *script __unused,
                                int argc __unused,
@@ -51,6 +53,8 @@ static void setup_scripting(void)
 
 static int cleanup_scripting(void)
 {
+       pr_debug("\nperf trace script stopped\n");
+
        return scripting_ops->stop_script();
 }
 
@@ -87,6 +91,14 @@ static int process_sample_event(event_t *event, struct perf_session *session)
        }
 
        if (session->sample_type & PERF_SAMPLE_RAW) {
+               if (debug_ordering) {
+                       if (data.time < last_timestamp) {
+                               pr_err("Samples misordered, previous: %llu "
+                                       "this: %llu\n", last_timestamp,
+                                       data.time);
+                       }
+                       last_timestamp = data.time;
+               }
                /*
                 * FIXME: better resolve from pid from the struct trace_entry
                 * field, although it should be the same than this perf
@@ -97,17 +109,31 @@ static int process_sample_event(event_t *event, struct perf_session *session)
                                             data.time, thread->comm);
        }
 
-       session->events_stats.total += data.period;
+       session->hists.stats.total_period += data.period;
        return 0;
 }
 
 static struct perf_event_ops event_ops = {
        .sample = process_sample_event,
        .comm   = event__process_comm,
+       .attr   = event__process_attr,
+       .event_type = event__process_event_type,
+       .tracing_data = event__process_tracing_data,
+       .build_id = event__process_build_id,
+       .ordered_samples = true,
 };
 
+extern volatile int session_done;
+
+static void sig_handler(int sig __unused)
+{
+       session_done = 1;
+}
+
 static int __cmd_trace(struct perf_session *session)
 {
+       signal(SIGINT, sig_handler);
+
        return perf_session__process_events(session, &event_ops);
 }
 
@@ -505,7 +531,7 @@ static const char * const trace_usage[] = {
 static const struct option options[] = {
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
-       OPT_BOOLEAN('v', "verbose", &verbose,
+       OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('L', "Latency", &latency_format,
                    "show latency attributes (irqs/preemption disabled, etc)"),
@@ -518,6 +544,8 @@ static const struct option options[] = {
                   "generate perf-trace.xx script in specified language"),
        OPT_STRING('i', "input", &input_name, "file",
                    "input file name"),
+       OPT_BOOLEAN('d', "debug-ordering", &debug_ordering,
+                  "check that samples time ordering is monotonic"),
 
        OPT_END()
 };
@@ -548,6 +576,65 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
                suffix = REPORT_SUFFIX;
        }
 
+       if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) {
+               char *record_script_path, *report_script_path;
+               int live_pipe[2];
+               pid_t pid;
+
+               record_script_path = get_script_path(argv[1], RECORD_SUFFIX);
+               if (!record_script_path) {
+                       fprintf(stderr, "record script not found\n");
+                       return -1;
+               }
+
+               report_script_path = get_script_path(argv[1], REPORT_SUFFIX);
+               if (!report_script_path) {
+                       fprintf(stderr, "report script not found\n");
+                       return -1;
+               }
+
+               if (pipe(live_pipe) < 0) {
+                       perror("failed to create pipe");
+                       exit(-1);
+               }
+
+               pid = fork();
+               if (pid < 0) {
+                       perror("failed to fork");
+                       exit(-1);
+               }
+
+               if (!pid) {
+                       dup2(live_pipe[1], 1);
+                       close(live_pipe[0]);
+
+                       __argv = malloc(5 * sizeof(const char *));
+                       __argv[0] = "/bin/sh";
+                       __argv[1] = record_script_path;
+                       __argv[2] = "-o";
+                       __argv[3] = "-";
+                       __argv[4] = NULL;
+
+                       execvp("/bin/sh", (char **)__argv);
+                       exit(-1);
+               }
+
+               dup2(live_pipe[0], 0);
+               close(live_pipe[1]);
+
+               __argv = malloc((argc + 3) * sizeof(const char *));
+               __argv[0] = "/bin/sh";
+               __argv[1] = report_script_path;
+               for (i = 2; i < argc; i++)
+                       __argv[i] = argv[i];
+               __argv[i++] = "-i";
+               __argv[i++] = "-";
+               __argv[i++] = NULL;
+
+               execvp("/bin/sh", (char **)__argv);
+               exit(-1);
+       }
+
        if (suffix) {
                script_path = get_script_path(argv[2], suffix);
                if (!script_path) {
@@ -576,11 +663,12 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
        if (!script_name)
                setup_pager();
 
-       session = perf_session__new(input_name, O_RDONLY, 0);
+       session = perf_session__new(input_name, O_RDONLY, 0, false);
        if (session == NULL)
                return -ENOMEM;
 
-       if (!perf_session__has_traces(session, "record -R"))
+       if (strcmp(input_name, "-") &&
+           !perf_session__has_traces(session, "record -R"))
                return -EINVAL;
 
        if (generate_script_lang) {
@@ -617,6 +705,7 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
                err = scripting_ops->start_script(script_name, argc, argv);
                if (err)
                        goto out;
+               pr_debug("perf trace started with script %s\n\n", script_name);
        }
 
        err = __cmd_trace(session);
index 10fe49e..921245b 100644 (file)
@@ -32,5 +32,8 @@ extern int cmd_version(int argc, const char **argv, const char *prefix);
 extern int cmd_probe(int argc, const char **argv, const char *prefix);
 extern int cmd_kmem(int argc, const char **argv, const char *prefix);
 extern int cmd_lock(int argc, const char **argv, const char *prefix);
+extern int cmd_kvm(int argc, const char **argv, const char *prefix);
+extern int cmd_test(int argc, const char **argv, const char *prefix);
+extern int cmd_inject(int argc, const char **argv, const char *prefix);
 
 #endif
index db6ee94..949d77f 100644 (file)
@@ -8,6 +8,7 @@ perf-bench                      mainporcelain common
 perf-buildid-cache             mainporcelain common
 perf-buildid-list              mainporcelain common
 perf-diff                      mainporcelain common
+perf-inject                    mainporcelain common
 perf-list                      mainporcelain common
 perf-sched                     mainporcelain common
 perf-record                    mainporcelain common
@@ -19,3 +20,5 @@ perf-trace                    mainporcelain common
 perf-probe                     mainporcelain common
 perf-kmem                      mainporcelain common
 perf-lock                      mainporcelain common
+perf-kvm                       mainporcelain common
+perf-test                      mainporcelain common
index 910468e..2e7a4f4 100644 (file)
@@ -30,4 +30,7 @@ done
 
 tar cfj $PERF_DATA.tar.bz2 -C $DEBUGDIR -T $MANIFEST
 rm -f $MANIFEST $BUILDIDS
+echo -e "Now please run:\n"
+echo -e "$ tar xvf $PERF_DATA.tar.bz2 -C ~/.debug\n"
+echo "wherever you need to run 'perf report' on."
 exit 0
index cd32c20..08e0e5d 100644 (file)
 #include "util/quote.h"
 #include "util/run-command.h"
 #include "util/parse-events.h"
-#include "util/string.h"
 #include "util/debugfs.h"
 
+bool use_browser;
+
 const char perf_usage_string[] =
        "perf [--version] [--help] COMMAND [ARGS]";
 
@@ -262,6 +263,8 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
        set_debugfs_path();
 
        status = p->fn(argc, argv, prefix);
+       exit_browser(status);
+
        if (status)
                return status & 0xff;
 
@@ -304,6 +307,9 @@ static void handle_internal_command(int argc, const char **argv)
                { "probe",      cmd_probe,      0 },
                { "kmem",       cmd_kmem,       0 },
                { "lock",       cmd_lock,       0 },
+               { "kvm",        cmd_kvm,        0 },
+               { "test",       cmd_test,       0 },
+               { "inject",     cmd_inject,     0 },
        };
        unsigned int i;
        static const char ext[] = STRIP_EXTENSION;
index 6fb379b..ef7aa0a 100644 (file)
@@ -1,6 +1,10 @@
 #ifndef _PERF_PERF_H
 #define _PERF_PERF_H
 
+struct winsize;
+
+void get_term_dimensions(struct winsize *ws);
+
 #if defined(__i386__)
 #include "../../arch/x86/include/asm/unistd.h"
 #define rmb()          asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
@@ -76,6 +80,7 @@
 
 #include "../../include/linux/perf_event.h"
 #include "util/types.h"
+#include <stdbool.h>
 
 /*
  * prctl(PR_TASK_PERF_EVENTS_DISABLE) will (cheaply) disable all
@@ -102,8 +107,6 @@ static inline unsigned long long rdclock(void)
 #define __user
 #define asmlinkage
 
-#define __used         __attribute__((__unused__))
-
 #define unlikely(x)    __builtin_expect(!!(x), 0)
 #define min(x, y) ({                           \
        typeof(x) _min1 = (x);                  \
@@ -129,4 +132,6 @@ struct ip_callchain {
        u64 ips[0];
 };
 
+extern bool perf_host, perf_guest;
+
 #endif
index f869c48..d94b40c 100644 (file)
@@ -15,6 +15,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
 
 our @EXPORT = qw(
 avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs
+clear_term
 );
 
 our $VERSION = '0.01';
@@ -55,6 +56,11 @@ sub nsecs_str {
     return $str;
 }
 
+sub clear_term
+{
+    print "\x1b[H\x1b[2J";
+}
+
 1;
 __END__
 =head1 NAME
index e6cb147..423ad6a 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree
+perf record -a -e kmem:kmalloc -e irq:softirq_entry -e kmem:kfree
index f8885d3..eb5846b 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
+perf record -a -e raw_syscalls:sys_exit $@
index 8bfc660..e3a5e55 100644 (file)
@@ -1,4 +1,10 @@
 #!/bin/bash
 # description: system-wide failed syscalls
 # args: [comm]
-perf trace -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $1
+if [ $# -gt 0 ] ; then
+    if ! expr match "$1" "-" > /dev/null ; then
+       comm=$1
+       shift
+    fi
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $comm
index b25056e..5bfaae5 100644 (file)
@@ -1,2 +1,3 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_enter_write
+perf record -a -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@
+
index eddb9cc..d83070b 100644 (file)
@@ -1,7 +1,13 @@
 #!/bin/bash
 # description: r/w activity for a program, by file
 # args: <comm>
-perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $1
+if [ $# -lt 1 ] ; then
+    echo "usage: rw-by-file <comm>"
+    exit
+fi
+comm=$1
+shift
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $comm
 
 
 
index 8903979..6e0b2f7 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write
+perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
index 7f44c25..7ef4698 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 # description: system-wide r/w activity
-perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl
 
 
 
diff --git a/tools/perf/scripts/perl/bin/rwtop-record b/tools/perf/scripts/perl/bin/rwtop-record
new file mode 100644 (file)
index 0000000..6e0b2f7
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -a -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
diff --git a/tools/perf/scripts/perl/bin/rwtop-report b/tools/perf/scripts/perl/bin/rwtop-report
new file mode 100644 (file)
index 0000000..93e698c
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+# description: system-wide r/w top
+# args: [interval]
+n_args=0
+for i in "$@"
+do
+    if expr match "$i" "-" > /dev/null ; then
+       break
+    fi
+    n_args=$(( $n_args + 1 ))
+done
+if [ "$n_args" -gt 1 ] ; then
+    echo "usage: rwtop-report [interval]"
+    exit
+fi
+if [ "$n_args" -gt 0 ] ; then
+    interval=$1
+    shift
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/rwtop.pl $interval
+
+
+
index 6abedda..9f2acaa 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e sched:sched_switch -e sched:sched_wakeup
+perf record -a -e sched:sched_switch -e sched:sched_wakeup $@
 
 
 
index fce3adc..a0d898f 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 # description: system-wide min/max/avg wakeup latency
-perf trace -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl
 
 
 
index fce6637..85301f2 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion
+perf record -a -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@
index 71cfbd1..3508113 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 # description: workqueue stats (ins/exe/create/destroy)
-perf trace -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl
+perf trace $@ -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl
 
 
 
index c18e7e2..94bc25a 100644 (file)
@@ -11,6 +11,8 @@ use Perf::Trace::Core;
 use Perf::Trace::Context;
 use Perf::Trace::Util;
 
+my $for_comm = shift;
+
 my %failed_syscalls;
 
 sub raw_syscalls::sys_exit
@@ -33,6 +35,8 @@ sub trace_end
 
     foreach my $comm (sort {$failed_syscalls{$b} <=> $failed_syscalls{$a}}
                      keys %failed_syscalls) {
-           printf("%-20s  %10s\n", $comm, $failed_syscalls{$comm});
+       next if ($for_comm && $comm ne $for_comm);
+
+       printf("%-20s  %10s\n", $comm, $failed_syscalls{$comm});
     }
 }
index da601fa..9db23c9 100644 (file)
@@ -79,12 +79,12 @@ sub trace_end
     printf("%6s  %-20s  %10s  %10s  %10s\n", "------", "--------------------",
           "-----------", "----------", "----------");
 
-    foreach my $pid (sort {$reads{$b}{bytes_read} <=>
-                              $reads{$a}{bytes_read}} keys %reads) {
-       my $comm = $reads{$pid}{comm};
-       my $total_reads = $reads{$pid}{total_reads};
-       my $bytes_requested = $reads{$pid}{bytes_requested};
-       my $bytes_read = $reads{$pid}{bytes_read};
+    foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=>
+                               ($reads{$a}{bytes_read} || 0) } keys %reads) {
+       my $comm = $reads{$pid}{comm} || "";
+       my $total_reads = $reads{$pid}{total_reads} || 0;
+       my $bytes_requested = $reads{$pid}{bytes_requested} || 0;
+       my $bytes_read = $reads{$pid}{bytes_read} || 0;
 
        printf("%6s  %-20s  %10s  %10s  %10s\n", $pid, $comm,
               $total_reads, $bytes_requested, $bytes_read);
@@ -96,16 +96,23 @@ sub trace_end
     printf("%6s  %20s  %6s  %10s\n", "------", "--------------------",
           "------", "----------");
 
-    foreach my $pid (keys %reads) {
-       my $comm = $reads{$pid}{comm};
-       foreach my $err (sort {$reads{$b}{comm} cmp $reads{$a}{comm}}
-                        keys %{$reads{$pid}{errors}}) {
-           my $errors = $reads{$pid}{errors}{$err};
+    my @errcounts = ();
 
-           printf("%6d  %-20s  %6d  %10s\n", $pid, $comm, $err, $errors);
+    foreach my $pid (keys %reads) {
+       foreach my $error (keys %{$reads{$pid}{errors}}) {
+           my $comm = $reads{$pid}{comm} || "";
+           my $errcount = $reads{$pid}{errors}{$error} || 0;
+           push @errcounts, [$pid, $comm, $error, $errcount];
        }
     }
 
+    @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
+
+    for my $i (0 .. $#errcounts) {
+       printf("%6d  %-20s  %6d  %10s\n", $errcounts[$i][0],
+              $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
+    }
+
     printf("\nwrite counts by pid:\n\n");
 
     printf("%6s  %20s  %10s  %10s\n", "pid", "comm",
@@ -113,11 +120,11 @@ sub trace_end
     printf("%6s  %-20s  %10s  %10s\n", "------", "--------------------",
           "-----------", "----------");
 
-    foreach my $pid (sort {$writes{$b}{bytes_written} <=>
-                              $writes{$a}{bytes_written}} keys %writes) {
-       my $comm = $writes{$pid}{comm};
-       my $total_writes = $writes{$pid}{total_writes};
-       my $bytes_written = $writes{$pid}{bytes_written};
+    foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=>
+                       ($writes{$a}{bytes_written} || 0)} keys %writes) {
+       my $comm = $writes{$pid}{comm} || "";
+       my $total_writes = $writes{$pid}{total_writes} || 0;
+       my $bytes_written = $writes{$pid}{bytes_written} || 0;
 
        printf("%6s  %-20s  %10s  %10s\n", $pid, $comm,
               $total_writes, $bytes_written);
@@ -129,16 +136,23 @@ sub trace_end
     printf("%6s  %20s  %6s  %10s\n", "------", "--------------------",
           "------", "----------");
 
-    foreach my $pid (keys %writes) {
-       my $comm = $writes{$pid}{comm};
-       foreach my $err (sort {$writes{$b}{comm} cmp $writes{$a}{comm}}
-                        keys %{$writes{$pid}{errors}}) {
-           my $errors = $writes{$pid}{errors}{$err};
+    @errcounts = ();
 
-           printf("%6d  %-20s  %6d  %10s\n", $pid, $comm, $err, $errors);
+    foreach my $pid (keys %writes) {
+       foreach my $error (keys %{$writes{$pid}{errors}}) {
+           my $comm = $writes{$pid}{comm} || "";
+           my $errcount = $writes{$pid}{errors}{$error} || 0;
+           push @errcounts, [$pid, $comm, $error, $errcount];
        }
     }
 
+    @errcounts = sort { $b->[3] <=> $a->[3] } @errcounts;
+
+    for my $i (0 .. $#errcounts) {
+       printf("%6d  %-20s  %6d  %10s\n", $errcounts[$i][0],
+              $errcounts[$i][1], $errcounts[$i][2], $errcounts[$i][3]);
+    }
+
     print_unhandled();
 }
 
diff --git a/tools/perf/scripts/perl/rwtop.pl b/tools/perf/scripts/perl/rwtop.pl
new file mode 100644 (file)
index 0000000..4bb3ecd
--- /dev/null
@@ -0,0 +1,199 @@
+#!/usr/bin/perl -w
+# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
+# Licensed under the terms of the GNU GPL License version 2
+
+# read/write top
+#
+# Periodically displays system-wide r/w call activity, broken down by
+# pid.  If an [interval] arg is specified, the display will be
+# refreshed every [interval] seconds.  The default interval is 3
+# seconds.
+
+use 5.010000;
+use strict;
+use warnings;
+
+use lib "$ENV{'PERF_EXEC_PATH'}/scripts/perl/Perf-Trace-Util/lib";
+use lib "./Perf-Trace-Util/lib";
+use Perf::Trace::Core;
+use Perf::Trace::Util;
+
+my $default_interval = 3;
+my $nlines = 20;
+my $print_thread;
+my $print_pending = 0;
+
+my %reads;
+my %writes;
+
+my $interval = shift;
+if (!$interval) {
+    $interval = $default_interval;
+}
+
+sub syscalls::sys_exit_read
+{
+    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+       $common_pid, $common_comm,
+       $nr, $ret) = @_;
+
+    print_check();
+
+    if ($ret > 0) {
+       $reads{$common_pid}{bytes_read} += $ret;
+    } else {
+       if (!defined ($reads{$common_pid}{bytes_read})) {
+           $reads{$common_pid}{bytes_read} = 0;
+       }
+       $reads{$common_pid}{errors}{$ret}++;
+    }
+}
+
+sub syscalls::sys_enter_read
+{
+    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+       $common_pid, $common_comm,
+       $nr, $fd, $buf, $count) = @_;
+
+    print_check();
+
+    $reads{$common_pid}{bytes_requested} += $count;
+    $reads{$common_pid}{total_reads}++;
+    $reads{$common_pid}{comm} = $common_comm;
+}
+
+sub syscalls::sys_exit_write
+{
+    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+       $common_pid, $common_comm,
+       $nr, $ret) = @_;
+
+    print_check();
+
+    if ($ret <= 0) {
+       $writes{$common_pid}{errors}{$ret}++;
+    }
+}
+
+sub syscalls::sys_enter_write
+{
+    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+       $common_pid, $common_comm,
+       $nr, $fd, $buf, $count) = @_;
+
+    print_check();
+
+    $writes{$common_pid}{bytes_written} += $count;
+    $writes{$common_pid}{total_writes}++;
+    $writes{$common_pid}{comm} = $common_comm;
+}
+
+sub trace_begin
+{
+    $SIG{ALRM} = \&set_print_pending;
+    alarm 1;
+}
+
+sub trace_end
+{
+    print_unhandled();
+    print_totals();
+}
+
+sub print_check()
+{
+    if ($print_pending == 1) {
+       $print_pending = 0;
+       print_totals();
+    }
+}
+
+sub set_print_pending()
+{
+    $print_pending = 1;
+    alarm $interval;
+}
+
+sub print_totals
+{
+    my $count;
+
+    $count = 0;
+
+    clear_term();
+
+    printf("\nread counts by pid:\n\n");
+
+    printf("%6s  %20s  %10s  %10s  %10s\n", "pid", "comm",
+          "# reads", "bytes_req", "bytes_read");
+    printf("%6s  %-20s  %10s  %10s  %10s\n", "------", "--------------------",
+          "----------", "----------", "----------");
+
+    foreach my $pid (sort { ($reads{$b}{bytes_read} || 0) <=>
+                              ($reads{$a}{bytes_read} || 0) } keys %reads) {
+       my $comm = $reads{$pid}{comm} || "";
+       my $total_reads = $reads{$pid}{total_reads} || 0;
+       my $bytes_requested = $reads{$pid}{bytes_requested} || 0;
+       my $bytes_read = $reads{$pid}{bytes_read} || 0;
+
+       printf("%6s  %-20s  %10s  %10s  %10s\n", $pid, $comm,
+              $total_reads, $bytes_requested, $bytes_read);
+
+       if (++$count == $nlines) {
+           last;
+       }
+    }
+
+    $count = 0;
+
+    printf("\nwrite counts by pid:\n\n");
+
+    printf("%6s  %20s  %10s  %13s\n", "pid", "comm",
+          "# writes", "bytes_written");
+    printf("%6s  %-20s  %10s  %13s\n", "------", "--------------------",
+          "----------", "-------------");
+
+    foreach my $pid (sort { ($writes{$b}{bytes_written} || 0) <=>
+                       ($writes{$a}{bytes_written} || 0)} keys %writes) {
+       my $comm = $writes{$pid}{comm} || "";
+       my $total_writes = $writes{$pid}{total_writes} || 0;
+       my $bytes_written = $writes{$pid}{bytes_written} || 0;
+
+       printf("%6s  %-20s  %10s  %13s\n", $pid, $comm,
+              $total_writes, $bytes_written);
+
+       if (++$count == $nlines) {
+           last;
+       }
+    }
+
+    %reads = ();
+    %writes = ();
+}
+
+my %unhandled;
+
+sub print_unhandled
+{
+    if ((scalar keys %unhandled) == 0) {
+       return;
+    }
+
+    print "\nunhandled events:\n\n";
+
+    printf("%-40s  %10s\n", "event", "count");
+    printf("%-40s  %10s\n", "----------------------------------------",
+          "-----------");
+
+    foreach my $event_name (keys %unhandled) {
+       printf("%-40s  %10d\n", $event_name, $unhandled{$event_name});
+    }
+}
+
+sub trace_unhandled
+{
+    my ($event_name, $context, $common_cpu, $common_secs, $common_nsecs,
+       $common_pid, $common_comm) = @_;
+
+    $unhandled{$event_name}++;
+}
index ed58ef2..d9143dc 100644 (file)
@@ -22,8 +22,8 @@ my %last_wakeup;
 
 my $max_wakeup_latency;
 my $min_wakeup_latency;
-my $total_wakeup_latency;
-my $total_wakeups;
+my $total_wakeup_latency = 0;
+my $total_wakeups = 0;
 
 sub sched::sched_switch
 {
@@ -67,8 +67,12 @@ sub trace_end
 {
     printf("wakeup_latency stats:\n\n");
     print "total_wakeups: $total_wakeups\n";
-    printf("avg_wakeup_latency (ns): %u\n",
-          avg($total_wakeup_latency, $total_wakeups));
+    if ($total_wakeups) {
+       printf("avg_wakeup_latency (ns): %u\n",
+              avg($total_wakeup_latency, $total_wakeups));
+    } else {
+       printf("avg_wakeup_latency (ns): N/A\n");
+    }
     printf("min_wakeup_latency (ns): %u\n", $min_wakeup_latency);
     printf("max_wakeup_latency (ns): %u\n", $max_wakeup_latency);
 
index 511302c..b84b126 100644 (file)
@@ -71,9 +71,9 @@ sub trace_end
     printf("%3s %6s %6s\t%-20s\n", "---", "---", "----", "----");
     foreach my $pidhash (@cpus) {
        while ((my $pid, my $wqhash) = each %$pidhash) {
-           my $ins = $$wqhash{'inserted'};
-           my $exe = $$wqhash{'executed'};
-           my $comm = $$wqhash{'comm'};
+           my $ins = $$wqhash{'inserted'} || 0;
+           my $exe = $$wqhash{'executed'} || 0;
+           my $comm = $$wqhash{'comm'} || "";
            if ($ins || $exe) {
                printf("%3u %6u %6u\t%-20s\n", $cpu, $ins, $exe, $comm);
            }
@@ -87,9 +87,9 @@ sub trace_end
     printf("%3s %6s %6s\t%-20s\n", "---", "-------", "---------", "----");
     foreach my $pidhash (@cpus) {
        while ((my $pid, my $wqhash) = each %$pidhash) {
-           my $created = $$wqhash{'created'};
-           my $destroyed = $$wqhash{'destroyed'};
-           my $comm = $$wqhash{'comm'};
+           my $created = $$wqhash{'created'} || 0;
+           my $destroyed = $$wqhash{'destroyed'} || 0;
+           my $comm = $$wqhash{'comm'} || "";
            if ($created || $destroyed) {
                printf("%3u %6u %6u\t%-20s\n", $cpu, $created, $destroyed,
                       $comm);
index 83e9143..9689bc0 100644 (file)
@@ -23,3 +23,6 @@ def nsecs_nsecs(nsecs):
 def nsecs_str(nsecs):
     str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)),
     return str
+
+def clear_term():
+    print("\x1b[H\x1b[2J")
index f8885d3..eb5846b 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
+perf record -a -e raw_syscalls:sys_exit $@
index 1e0c0a8..3029354 100644 (file)
@@ -1,4 +1,10 @@
 #!/bin/bash
 # description: system-wide failed syscalls, by pid
 # args: [comm]
-perf trace -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $1
+if [ $# -gt 0 ] ; then
+    if ! expr match "$1" "-" > /dev/null ; then
+       comm=$1
+       shift
+    fi
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $comm
diff --git a/tools/perf/scripts/python/bin/sctop-record b/tools/perf/scripts/python/bin/sctop-record
new file mode 100644 (file)
index 0000000..1fc5998
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+perf record -a -e raw_syscalls:sys_enter $@
diff --git a/tools/perf/scripts/python/bin/sctop-report b/tools/perf/scripts/python/bin/sctop-report
new file mode 100644 (file)
index 0000000..b01c842
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+# description: syscall top
+# args: [comm] [interval]
+n_args=0
+for i in "$@"
+do
+    if expr match "$i" "-" > /dev/null ; then
+       break
+    fi
+    n_args=$(( $n_args + 1 ))
+done
+if [ "$n_args" -gt 2 ] ; then
+    echo "usage: sctop-report [comm] [interval]"
+    exit
+fi
+if [ "$n_args" -gt 1 ] ; then
+    comm=$1
+    interval=$2
+    shift 2
+elif [ "$n_args" -gt 0 ] ; then
+    interval=$1
+    shift
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/python/sctop.py $comm $interval
index 45a8c50..1fc5998 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
+perf record -a -e raw_syscalls:sys_enter $@
index f8044d1..9e9d8dd 100644 (file)
@@ -1,4 +1,10 @@
 #!/bin/bash
 # description: system-wide syscall counts, by pid
 # args: [comm]
-perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $1
+if [ $# -gt 0 ] ; then
+    if ! expr match "$1" "-" > /dev/null ; then
+       comm=$1
+       shift
+    fi
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $comm
index 45a8c50..1fc5998 100644 (file)
@@ -1,2 +1,2 @@
 #!/bin/bash
-perf record -c 1 -f -a -M -R -e raw_syscalls:sys_enter
+perf record -a -e raw_syscalls:sys_enter $@
index a366aa6..dc076b6 100644 (file)
@@ -1,4 +1,10 @@
 #!/bin/bash
 # description: system-wide syscall counts
 # args: [comm]
-perf trace -s ~/libexec/perf-core/scripts/python/syscall-counts.py $1
+if [ $# -gt 0 ] ; then
+    if ! expr match "$1" "-" > /dev/null ; then
+       comm=$1
+       shift
+    fi
+fi
+perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts.py $comm
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py
new file mode 100644 (file)
index 0000000..6cafad4
--- /dev/null
@@ -0,0 +1,78 @@
+# system call top
+# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
+# Licensed under the terms of the GNU GPL License version 2
+#
+# Periodically displays system-wide system call totals, broken down by
+# syscall.  If a [comm] arg is specified, only syscalls called by
+# [comm] are displayed. If an [interval] arg is specified, the display
+# will be refreshed every [interval] seconds.  The default interval is
+# 3 seconds.
+
+import thread
+import time
+import os
+import sys
+
+sys.path.append(os.environ['PERF_EXEC_PATH'] + \
+       '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
+
+from perf_trace_context import *
+from Core import *
+from Util import *
+
+usage = "perf trace -s syscall-counts.py [comm] [interval]\n";
+
+for_comm = None
+default_interval = 3
+interval = default_interval
+
+if len(sys.argv) > 3:
+       sys.exit(usage)
+
+if len(sys.argv) > 2:
+       for_comm = sys.argv[1]
+       interval = int(sys.argv[2])
+elif len(sys.argv) > 1:
+       try:
+               interval = int(sys.argv[1])
+       except ValueError:
+               for_comm = sys.argv[1]
+               interval = default_interval
+
+syscalls = autodict()
+
+def trace_begin():
+       thread.start_new_thread(print_syscall_totals, (interval,))
+       pass
+
+def raw_syscalls__sys_enter(event_name, context, common_cpu,
+       common_secs, common_nsecs, common_pid, common_comm,
+       id, args):
+       if for_comm is not None:
+               if common_comm != for_comm:
+                       return
+       try:
+               syscalls[id] += 1
+       except TypeError:
+               syscalls[id] = 1
+
+def print_syscall_totals(interval):
+       while 1:
+               clear_term()
+               if for_comm is not None:
+                       print "\nsyscall events for %s:\n\n" % (for_comm),
+               else:
+                       print "\nsyscall events:\n\n",
+
+               print "%-40s  %10s\n" % ("event", "count"),
+               print "%-40s  %10s\n" % ("----------------------------------------", \
+                                                "----------"),
+
+               for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
+                                             reverse = True):
+                       try:
+                               print "%-40d  %10d\n" % (id, val),
+                       except TypeError:
+                               pass
+               syscalls.clear()
+               time.sleep(interval)
index 54552a0..49ece79 100755 (executable)
@@ -1,6 +1,10 @@
 #!/bin/sh
 
-GVF=PERF-VERSION-FILE
+if [ $# -eq 1 ]  ; then
+       OUTPUT=$1
+fi
+
+GVF=${OUTPUT}PERF-VERSION-FILE
 DEF_VER=v0.0.2.PERF
 
 LF='
diff --git a/tools/perf/util/bitmap.c b/tools/perf/util/bitmap.c
new file mode 100644 (file)
index 0000000..5e230ac
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * From lib/bitmap.c
+ * Helper functions for bitmap.h.
+ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2.  See the file COPYING for more details.
+ */
+#include <linux/bitmap.h>
+
+int __bitmap_weight(const unsigned long *bitmap, int bits)
+{
+       int k, w = 0, lim = bits/BITS_PER_LONG;
+
+       for (k = 0; k < lim; k++)
+               w += hweight_long(bitmap[k]);
+
+       if (bits % BITS_PER_LONG)
+               w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
+
+       return w;
+}
index 04904b3..0f60a39 100644 (file)
@@ -24,7 +24,7 @@ static int build_id__mark_dso_hit(event_t *event, struct perf_session *session)
        }
 
        thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
-                             event->ip.ip, &al);
+                             event->ip.pid, event->ip.ip, &al);
 
        if (al.map != NULL)
                al.map->dso->hit = 1;
index 918eb37..4b9aab7 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __PERF_CACHE_H
 #define __PERF_CACHE_H
 
+#include <stdbool.h>
 #include "util.h"
 #include "strbuf.h"
 #include "../perf.h"
@@ -69,6 +70,19 @@ extern const char *pager_program;
 extern int pager_in_use(void);
 extern int pager_use_color;
 
+extern bool use_browser;
+
+#ifdef NO_NEWT_SUPPORT
+static inline void setup_browser(void)
+{
+       setup_pager();
+}
+static inline void exit_browser(bool wait_for_ok __used) {}
+#else
+void setup_browser(void);
+void exit_browser(bool wait_for_ok);
+#endif
+
 extern const char *editor_program;
 extern const char *excludes_file;
 
index b3b7125..21a52e0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009, Frederic Weisbecker <fweisbec@gmail.com>
+ * Copyright (C) 2009-2010, Frederic Weisbecker <fweisbec@gmail.com>
  *
  * Handle the callchains from the stream in an ad-hoc radix tree and then
  * sort them in an rbtree.
 
 #include "callchain.h"
 
+bool ip_callchain__valid(struct ip_callchain *chain, event_t *event)
+{
+       unsigned int chain_size = event->header.size;
+       chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
+       return chain->nr * sizeof(u64) <= chain_size;
+}
+
 #define chain_for_each_child(child, parent)    \
        list_for_each_entry(child, &parent->children, brothers)
 
@@ -160,7 +167,7 @@ create_child(struct callchain_node *parent, bool inherit_children)
 {
        struct callchain_node *new;
 
-       new = malloc(sizeof(*new));
+       new = zalloc(sizeof(*new));
        if (!new) {
                perror("not enough memory to create child for code path tree");
                return NULL;
@@ -183,25 +190,36 @@ create_child(struct callchain_node *parent, bool inherit_children)
        return new;
 }
 
+
+struct resolved_ip {
+       u64               ip;
+       struct map_symbol ms;
+};
+
+struct resolved_chain {
+       u64                     nr;
+       struct resolved_ip      ips[0];
+};
+
+
 /*
  * Fill the node with callchain values
  */
 static void
-fill_node(struct callchain_node *node, struct ip_callchain *chain,
-         int start, struct symbol **syms)
+fill_node(struct callchain_node *node, struct resolved_chain *chain, int start)
 {
        unsigned int i;
 
        for (i = start; i < chain->nr; i++) {
                struct callchain_list *call;
 
-               call = malloc(sizeof(*call));
+               call = zalloc(sizeof(*call));
                if (!call) {
                        perror("not enough memory for the code path tree");
                        return;
                }
-               call->ip = chain->ips[i];
-               call->sym = syms[i];
+               call->ip = chain->ips[i].ip;
+               call->ms = chain->ips[i].ms;
                list_add_tail(&call->list, &node->val);
        }
        node->val_nr = chain->nr - start;
@@ -210,13 +228,13 @@ fill_node(struct callchain_node *node, struct ip_callchain *chain,
 }
 
 static void
-add_child(struct callchain_node *parent, struct ip_callchain *chain,
-         int start, struct symbol **syms)
+add_child(struct callchain_node *parent, struct resolved_chain *chain,
+         int start)
 {
        struct callchain_node *new;
 
        new = create_child(parent, false);
-       fill_node(new, chain, start, syms);
+       fill_node(new, chain, start);
 
        new->children_hit = 0;
        new->hit = 1;
@@ -228,9 +246,8 @@ add_child(struct callchain_node *parent, struct ip_callchain *chain,
  * Then create another child to host the given callchain of new branch
  */
 static void
-split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
-               struct callchain_list *to_split, int idx_parents, int idx_local,
-               struct symbol **syms)
+split_add_child(struct callchain_node *parent, struct resolved_chain *chain,
+               struct callchain_list *to_split, int idx_parents, int idx_local)
 {
        struct callchain_node *new;
        struct list_head *old_tail;
@@ -257,7 +274,7 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
        /* create a new child for the new branch if any */
        if (idx_total < chain->nr) {
                parent->hit = 0;
-               add_child(parent, chain, idx_total, syms);
+               add_child(parent, chain, idx_total);
                parent->children_hit++;
        } else {
                parent->hit = 1;
@@ -265,32 +282,33 @@ split_add_child(struct callchain_node *parent, struct ip_callchain *chain,
 }
 
 static int
-__append_chain(struct callchain_node *root, struct ip_callchain *chain,
-              unsigned int start, struct symbol **syms);
+__append_chain(struct callchain_node *root, struct resolved_chain *chain,
+              unsigned int start);
 
 static void
-__append_chain_children(struct callchain_node *root, struct ip_callchain *chain,
-                       struct symbol **syms, unsigned int start)
+__append_chain_children(struct callchain_node *root,
+                       struct resolved_chain *chain,
+                       unsigned int start)
 {
        struct callchain_node *rnode;
 
        /* lookup in childrens */
        chain_for_each_child(rnode, root) {
-               unsigned int ret = __append_chain(rnode, chain, start, syms);
+               unsigned int ret = __append_chain(rnode, chain, start);
 
                if (!ret)
                        goto inc_children_hit;
        }
        /* nothing in children, add to the current node */
-       add_child(root, chain, start, syms);
+       add_child(root, chain, start);
 
 inc_children_hit:
        root->children_hit++;
 }
 
 static int
-__append_chain(struct callchain_node *root, struct ip_callchain *chain,
-              unsigned int start, struct symbol **syms)
+__append_chain(struct callchain_node *root, struct resolved_chain *chain,
+              unsigned int start)
 {
        struct callchain_list *cnode;
        unsigned int i = start;
@@ -302,13 +320,19 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,
         * anywhere inside a function.
         */
        list_for_each_entry(cnode, &root->val, list) {
+               struct symbol *sym;
+
                if (i == chain->nr)
                        break;
-               if (cnode->sym && syms[i]) {
-                       if (cnode->sym->start != syms[i]->start)
+
+               sym = chain->ips[i].ms.sym;
+
+               if (cnode->ms.sym && sym) {
+                       if (cnode->ms.sym->start != sym->start)
                                break;
-               } else if (cnode->ip != chain->ips[i])
+               } else if (cnode->ip != chain->ips[i].ip)
                        break;
+
                if (!found)
                        found = true;
                i++;
@@ -320,7 +344,7 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,
 
        /* we match only a part of the node. Split it and add the new chain */
        if (i - start < root->val_nr) {
-               split_add_child(root, chain, cnode, start, i - start, syms);
+               split_add_child(root, chain, cnode, start, i - start);
                return 0;
        }
 
@@ -331,15 +355,50 @@ __append_chain(struct callchain_node *root, struct ip_callchain *chain,
        }
 
        /* We match the node and still have a part remaining */
-       __append_chain_children(root, chain, syms, i);
+       __append_chain_children(root, chain, i);
 
        return 0;
 }
 
-void append_chain(struct callchain_node *root, struct ip_callchain *chain,
-                 struct symbol **syms)
+static void filter_context(struct ip_callchain *old, struct resolved_chain *new,
+                          struct map_symbol *syms)
 {
+       int i, j = 0;
+
+       for (i = 0; i < (int)old->nr; i++) {
+               if (old->ips[i] >= PERF_CONTEXT_MAX)
+                       continue;
+
+               new->ips[j].ip = old->ips[i];
+               new->ips[j].ms = syms[i];
+               j++;
+       }
+
+       new->nr = j;
+}
+
+
+int append_chain(struct callchain_node *root, struct ip_callchain *chain,
+                struct map_symbol *syms)
+{
+       struct resolved_chain *filtered;
+
        if (!chain->nr)
-               return;
-       __append_chain_children(root, chain, syms, 0);
+               return 0;
+
+       filtered = zalloc(sizeof(*filtered) +
+                         chain->nr * sizeof(struct resolved_ip));
+       if (!filtered)
+               return -ENOMEM;
+
+       filter_context(chain, filtered, syms);
+
+       if (!filtered->nr)
+               goto end;
+
+       __append_chain_children(root, filtered, 0);
+end:
+       free(filtered);
+
+       return 0;
 }
index ad4626d..1cba1f5 100644 (file)
@@ -4,6 +4,7 @@
 #include "../perf.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
+#include "event.h"
 #include "util.h"
 #include "symbol.h"
 
@@ -33,13 +34,14 @@ typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_node *,
 
 struct callchain_param {
        enum chain_mode         mode;
+       u32                     print_limit;
        double                  min_percent;
        sort_chain_func_t       sort;
 };
 
 struct callchain_list {
        u64                     ip;
-       struct symbol           *sym;
+       struct map_symbol       ms;
        struct list_head        list;
 };
 
@@ -56,6 +58,8 @@ static inline u64 cumul_hits(struct callchain_node *node)
 }
 
 int register_callchain_param(struct callchain_param *param);
-void append_chain(struct callchain_node *root, struct ip_callchain *chain,
-                 struct symbol **syms);
+int append_chain(struct callchain_node *root, struct ip_callchain *chain,
+                struct map_symbol *syms);
+
+bool ip_callchain__valid(struct ip_callchain *chain, event_t *event);
 #endif /* __PERF_CALLCHAIN_H */
index e88bca5..e191eb9 100644 (file)
@@ -166,6 +166,31 @@ int perf_color_default_config(const char *var, const char *value, void *cb)
        return perf_default_config(var, value, cb);
 }
 
+static int __color_vsnprintf(char *bf, size_t size, const char *color,
+                            const char *fmt, va_list args, const char *trail)
+{
+       int r = 0;
+
+       /*
+        * Auto-detect:
+        */
+       if (perf_use_color_default < 0) {
+               if (isatty(1) || pager_in_use())
+                       perf_use_color_default = 1;
+               else
+                       perf_use_color_default = 0;
+       }
+
+       if (perf_use_color_default && *color)
+               r += snprintf(bf, size, "%s", color);
+       r += vsnprintf(bf + r, size - r, fmt, args);
+       if (perf_use_color_default && *color)
+               r += snprintf(bf + r, size - r, "%s", PERF_COLOR_RESET);
+       if (trail)
+               r += snprintf(bf + r, size - r, "%s", trail);
+       return r;
+}
+
 static int __color_vfprintf(FILE *fp, const char *color, const char *fmt,
                va_list args, const char *trail)
 {
@@ -191,11 +216,28 @@ static int __color_vfprintf(FILE *fp, const char *color, const char *fmt,
        return r;
 }
 
+int color_vsnprintf(char *bf, size_t size, const char *color,
+                   const char *fmt, va_list args)
+{
+       return __color_vsnprintf(bf, size, color, fmt, args, NULL);
+}
+
 int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args)
 {
        return __color_vfprintf(fp, color, fmt, args, NULL);
 }
 
+int color_snprintf(char *bf, size_t size, const char *color,
+                  const char *fmt, ...)
+{
+       va_list args;
+       int r;
+
+       va_start(args, fmt);
+       r = color_vsnprintf(bf, size, color, fmt, args);
+       va_end(args);
+       return r;
+}
 
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...)
 {
@@ -274,3 +316,9 @@ int percent_color_fprintf(FILE *fp, const char *fmt, double percent)
 
        return r;
 }
+
+int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent)
+{
+       const char *color = get_percent_color(percent);
+       return color_snprintf(bf, size, color, fmt, percent);
+}
index 24e8809..dea082b 100644 (file)
@@ -32,10 +32,14 @@ int perf_color_default_config(const char *var, const char *value, void *cb);
 int perf_config_colorbool(const char *var, const char *value, int stdout_is_tty);
 void color_parse(const char *value, const char *var, char *dst);
 void color_parse_mem(const char *value, int len, const char *var, char *dst);
+int color_vsnprintf(char *bf, size_t size, const char *color,
+                   const char *fmt, va_list args);
 int color_vfprintf(FILE *fp, const char *color, const char *fmt, va_list args);
 int color_fprintf(FILE *fp, const char *color, const char *fmt, ...);
+int color_snprintf(char *bf, size_t size, const char *color, const char *fmt, ...);
 int color_fprintf_ln(FILE *fp, const char *color, const char *fmt, ...);
 int color_fwrite_lines(FILE *fp, const char *color, size_t count, const char *buf);
+int percent_color_snprintf(char *bf, size_t size, const char *fmt, double percent);
 int percent_color_fprintf(FILE *fp, const char *fmt, double percent);
 const char *get_percent_color(double percent);
 
index 0905600..dd824cf 100644 (file)
@@ -6,13 +6,14 @@
 #include <stdarg.h>
 #include <stdio.h>
 
+#include "cache.h"
 #include "color.h"
 #include "event.h"
 #include "debug.h"
 #include "util.h"
 
 int verbose = 0;
-int dump_trace = 0;
+bool dump_trace = false;
 
 int eprintf(int level, const char *fmt, ...)
 {
@@ -21,7 +22,10 @@ int eprintf(int level, const char *fmt, ...)
 
        if (verbose >= level) {
                va_start(args, fmt);
-               ret = vfprintf(stderr, fmt, args);
+               if (use_browser)
+                       ret = browser__show_help(fmt, args);
+               else
+                       ret = vfprintf(stderr, fmt, args);
                va_end(args);
        }
 
index c6c24c5..047ac33 100644 (file)
@@ -2,14 +2,38 @@
 #ifndef __PERF_DEBUG_H
 #define __PERF_DEBUG_H
 
+#include <stdbool.h>
 #include "event.h"
 
 extern int verbose;
-extern int dump_trace;
+extern bool dump_trace;
 
-int eprintf(int level,
-           const char *fmt, ...) __attribute__((format(printf, 2, 3)));
 int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
 void trace_event(event_t *event);
 
+struct ui_progress;
+
+#ifdef NO_NEWT_SUPPORT
+static inline int browser__show_help(const char *format __used, va_list ap __used)
+{
+       return 0;
+}
+
+static inline struct ui_progress *ui_progress__new(const char *title __used,
+                                                  u64 total __used)
+{
+       return (struct ui_progress *)1;
+}
+
+static inline void ui_progress__update(struct ui_progress *self __used,
+                                      u64 curr __used) {}
+
+static inline void ui_progress__delete(struct ui_progress *self __used) {}
+#else
+int browser__show_help(const char *format, va_list ap);
+struct ui_progress *ui_progress__new(const char *title, u64 total);
+void ui_progress__update(struct ui_progress *self, u64 curr);
+void ui_progress__delete(struct ui_progress *self);
+#endif
+
 #endif /* __PERF_DEBUG_H */
index 705ec63..50771b5 100644 (file)
@@ -7,6 +7,23 @@
 #include "strlist.h"
 #include "thread.h"
 
+const char *event__name[] = {
+       [0]                      = "TOTAL",
+       [PERF_RECORD_MMAP]       = "MMAP",
+       [PERF_RECORD_LOST]       = "LOST",
+       [PERF_RECORD_COMM]       = "COMM",
+       [PERF_RECORD_EXIT]       = "EXIT",
+       [PERF_RECORD_THROTTLE]   = "THROTTLE",
+       [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE",
+       [PERF_RECORD_FORK]       = "FORK",
+       [PERF_RECORD_READ]       = "READ",
+       [PERF_RECORD_SAMPLE]     = "SAMPLE",
+       [PERF_RECORD_HEADER_ATTR]        = "ATTR",
+       [PERF_RECORD_HEADER_EVENT_TYPE]  = "EVENT_TYPE",
+       [PERF_RECORD_HEADER_TRACING_DATA]        = "TRACING_DATA",
+       [PERF_RECORD_HEADER_BUILD_ID]    = "BUILD_ID",
+};
+
 static pid_t event__synthesize_comm(pid_t pid, int full,
                                    event__handler_t process,
                                    struct perf_session *session)
@@ -112,7 +129,11 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
                event_t ev = {
                        .header = {
                                .type = PERF_RECORD_MMAP,
-                               .misc = 0, /* Just like the kernel, see kernel/perf_event.c __perf_event_mmap */
+                               /*
+                                * Just like the kernel, see __perf_event_mmap
+                                * in kernel/perf_event.c
+                                */
+                               .misc = PERF_RECORD_MISC_USER,
                         },
                };
                int n;
@@ -130,6 +151,7 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
                        continue;
                pbf += n + 3;
                if (*pbf == 'x') { /* vm_exec */
+                       u64 vm_pgoff;
                        char *execname = strchr(bf, '/');
 
                        /* Catch VDSO */
@@ -139,6 +161,14 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
                        if (execname == NULL)
                                continue;
 
+                       pbf += 3;
+                       n = hex2u64(pbf, &vm_pgoff);
+                       /* pgoff is in bytes, not pages */
+                       if (n >= 0)
+                               ev.mmap.pgoff = vm_pgoff << getpagesize();
+                       else
+                               ev.mmap.pgoff = 0;
+
                        size = strlen(execname);
                        execname[size - 1] = '\0'; /* Remove \n */
                        memcpy(ev.mmap.filename, execname, size);
@@ -158,11 +188,23 @@ static int event__synthesize_mmap_events(pid_t pid, pid_t tgid,
 }
 
 int event__synthesize_modules(event__handler_t process,
-                             struct perf_session *session)
+                             struct perf_session *session,
+                             struct machine *machine)
 {
        struct rb_node *nd;
+       struct map_groups *kmaps = &machine->kmaps;
+       u16 misc;
+
+       /*
+        * kernel uses 0 for user space maps, see kernel/perf_event.c
+        * __perf_event_mmap
+        */
+       if (machine__is_host(machine))
+               misc = PERF_RECORD_MISC_KERNEL;
+       else
+               misc = PERF_RECORD_MISC_GUEST_KERNEL;
 
-       for (nd = rb_first(&session->kmaps.maps[MAP__FUNCTION]);
+       for (nd = rb_first(&kmaps->maps[MAP__FUNCTION]);
             nd; nd = rb_next(nd)) {
                event_t ev;
                size_t size;
@@ -173,12 +215,13 @@ int event__synthesize_modules(event__handler_t process,
 
                size = ALIGN(pos->dso->long_name_len + 1, sizeof(u64));
                memset(&ev, 0, sizeof(ev));
-               ev.mmap.header.misc = 1; /* kernel uses 0 for user space maps, see kernel/perf_event.c __perf_event_mmap */
+               ev.mmap.header.misc = misc;
                ev.mmap.header.type = PERF_RECORD_MMAP;
                ev.mmap.header.size = (sizeof(ev.mmap) -
                                        (sizeof(ev.mmap.filename) - size));
                ev.mmap.start = pos->start;
                ev.mmap.len   = pos->end - pos->start;
+               ev.mmap.pid   = machine->pid;
 
                memcpy(ev.mmap.filename, pos->dso->long_name,
                       pos->dso->long_name_len + 1);
@@ -241,13 +284,18 @@ static int find_symbol_cb(void *arg, const char *name, char type, u64 start)
 
 int event__synthesize_kernel_mmap(event__handler_t process,
                                  struct perf_session *session,
+                                 struct machine *machine,
                                  const char *symbol_name)
 {
        size_t size;
+       const char *filename, *mmap_name;
+       char path[PATH_MAX];
+       char name_buff[PATH_MAX];
+       struct map *map;
+
        event_t ev = {
                .header = {
                        .type = PERF_RECORD_MMAP,
-                       .misc = 1, /* kernel uses 0 for user space maps, see kernel/perf_event.c __perf_event_mmap */
                },
        };
        /*
@@ -257,16 +305,37 @@ int event__synthesize_kernel_mmap(event__handler_t process,
         */
        struct process_symbol_args args = { .name = symbol_name, };
 
-       if (kallsyms__parse("/proc/kallsyms", &args, find_symbol_cb) <= 0)
+       mmap_name = machine__mmap_name(machine, name_buff, sizeof(name_buff));
+       if (machine__is_host(machine)) {
+               /*
+                * kernel uses PERF_RECORD_MISC_USER for user space maps,
+                * see kernel/perf_event.c __perf_event_mmap
+                */
+               ev.header.misc = PERF_RECORD_MISC_KERNEL;
+               filename = "/proc/kallsyms";
+       } else {
+               ev.header.misc = PERF_RECORD_MISC_GUEST_KERNEL;
+               if (machine__is_default_guest(machine))
+                       filename = (char *) symbol_conf.default_guest_kallsyms;
+               else {
+                       sprintf(path, "%s/proc/kallsyms", machine->root_dir);
+                       filename = path;
+               }
+       }
+
+       if (kallsyms__parse(filename, &args, find_symbol_cb) <= 0)
                return -ENOENT;
 
+       map = machine->vmlinux_maps[MAP__FUNCTION];
        size = snprintf(ev.mmap.filename, sizeof(ev.mmap.filename),
-                       "[kernel.kallsyms.%s]", symbol_name) + 1;
+                       "%s%s", mmap_name, symbol_name) + 1;
        size = ALIGN(size, sizeof(u64));
-       ev.mmap.header.size = (sizeof(ev.mmap) - (sizeof(ev.mmap.filename) - size));
+       ev.mmap.header.size = (sizeof(ev.mmap) -
+                       (sizeof(ev.mmap.filename) - size));
        ev.mmap.pgoff = args.start;
-       ev.mmap.start = session->vmlinux_maps[MAP__FUNCTION]->start;
-       ev.mmap.len   = session->vmlinux_maps[MAP__FUNCTION]->end - ev.mmap.start ;
+       ev.mmap.start = map->start;
+       ev.mmap.len   = map->end - ev.mmap.start;
+       ev.mmap.pid   = machine->pid;
 
        return process(&ev, session);
 }
@@ -316,26 +385,54 @@ int event__process_comm(event_t *self, struct perf_session *session)
 int event__process_lost(event_t *self, struct perf_session *session)
 {
        dump_printf(": id:%Ld: lost:%Ld\n", self->lost.id, self->lost.lost);
-       session->events_stats.lost += self->lost.lost;
+       session->hists.stats.total_lost += self->lost.lost;
        return 0;
 }
 
-int event__process_mmap(event_t *self, struct perf_session *session)
+static void event_set_kernel_mmap_len(struct map **maps, event_t *self)
+{
+       maps[MAP__FUNCTION]->start = self->mmap.start;
+       maps[MAP__FUNCTION]->end   = self->mmap.start + self->mmap.len;
+       /*
+        * Be a bit paranoid here, some perf.data file came with
+        * a zero sized synthesized MMAP event for the kernel.
+        */
+       if (maps[MAP__FUNCTION]->end == 0)
+               maps[MAP__FUNCTION]->end = ~0UL;
+}
+
+static int event__process_kernel_mmap(event_t *self,
+                       struct perf_session *session)
 {
-       struct thread *thread;
        struct map *map;
+       char kmmap_prefix[PATH_MAX];
+       struct machine *machine;
+       enum dso_kernel_type kernel_type;
+       bool is_kernel_mmap;
+
+       machine = perf_session__findnew_machine(session, self->mmap.pid);
+       if (!machine) {
+               pr_err("Can't find id %d's machine\n", self->mmap.pid);
+               goto out_problem;
+       }
 
-       dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n",
-                   self->mmap.pid, self->mmap.tid, self->mmap.start,
-                   self->mmap.len, self->mmap.pgoff, self->mmap.filename);
+       machine__mmap_name(machine, kmmap_prefix, sizeof(kmmap_prefix));
+       if (machine__is_host(machine))
+               kernel_type = DSO_TYPE_KERNEL;
+       else
+               kernel_type = DSO_TYPE_GUEST_KERNEL;
 
-       if (self->mmap.pid == 0) {
-               static const char kmmap_prefix[] = "[kernel.kallsyms.";
+       is_kernel_mmap = memcmp(self->mmap.filename,
+                               kmmap_prefix,
+                               strlen(kmmap_prefix)) == 0;
+       if (self->mmap.filename[0] == '/' ||
+           (!is_kernel_mmap && self->mmap.filename[0] == '[')) {
 
-               if (self->mmap.filename[0] == '/') {
-                       char short_module_name[1024];
-                       char *name = strrchr(self->mmap.filename, '/'), *dot;
+               char short_module_name[1024];
+               char *name, *dot;
 
+               if (self->mmap.filename[0] == '/') {
+                       name = strrchr(self->mmap.filename, '/');
                        if (name == NULL)
                                goto out_problem;
 
@@ -343,58 +440,84 @@ int event__process_mmap(event_t *self, struct perf_session *session)
                        dot = strrchr(name, '.');
                        if (dot == NULL)
                                goto out_problem;
-
                        snprintf(short_module_name, sizeof(short_module_name),
-                                "[%.*s]", (int)(dot - name), name);
+                                       "[%.*s]", (int)(dot - name), name);
                        strxfrchar(short_module_name, '-', '_');
-
-                       map = perf_session__new_module_map(session,
-                                                          self->mmap.start,
-                                                          self->mmap.filename);
-                       if (map == NULL)
-                               goto out_problem;
-
-                       name = strdup(short_module_name);
-                       if (name == NULL)
-                               goto out_problem;
-
-                       map->dso->short_name = name;
-                       map->end = map->start + self->mmap.len;
-               } else if (memcmp(self->mmap.filename, kmmap_prefix,
-                               sizeof(kmmap_prefix) - 1) == 0) {
-                       const char *symbol_name = (self->mmap.filename +
-                                                  sizeof(kmmap_prefix) - 1);
+               } else
+                       strcpy(short_module_name, self->mmap.filename);
+
+               map = machine__new_module(machine, self->mmap.start,
+                                         self->mmap.filename);
+               if (map == NULL)
+                       goto out_problem;
+
+               name = strdup(short_module_name);
+               if (name == NULL)
+                       goto out_problem;
+
+               map->dso->short_name = name;
+               map->end = map->start + self->mmap.len;
+       } else if (is_kernel_mmap) {
+               const char *symbol_name = (self->mmap.filename +
+                               strlen(kmmap_prefix));
+               /*
+                * Should be there already, from the build-id table in
+                * the header.
+                */
+               struct dso *kernel = __dsos__findnew(&machine->kernel_dsos,
+                                                    kmmap_prefix);
+               if (kernel == NULL)
+                       goto out_problem;
+
+               kernel->kernel = kernel_type;
+               if (__machine__create_kernel_maps(machine, kernel) < 0)
+                       goto out_problem;
+
+               event_set_kernel_mmap_len(machine->vmlinux_maps, self);
+               perf_session__set_kallsyms_ref_reloc_sym(machine->vmlinux_maps,
+                                                        symbol_name,
+                                                        self->mmap.pgoff);
+               if (machine__is_default_guest(machine)) {
                        /*
-                        * Should be there already, from the build-id table in
-                        * the header.
+                        * preload dso of guest kernel and modules
                         */
-                       struct dso *kernel = __dsos__findnew(&dsos__kernel,
-                                                            "[kernel.kallsyms]");
-                       if (kernel == NULL)
-                               goto out_problem;
-
-                       kernel->kernel = 1;
-                       if (__perf_session__create_kernel_maps(session, kernel) < 0)
-                               goto out_problem;
+                       dso__load(kernel, machine->vmlinux_maps[MAP__FUNCTION],
+                                 NULL);
+               }
+       }
+       return 0;
+out_problem:
+       return -1;
+}
 
-                       session->vmlinux_maps[MAP__FUNCTION]->start = self->mmap.start;
-                       session->vmlinux_maps[MAP__FUNCTION]->end   = self->mmap.start + self->mmap.len;
-                       /*
-                        * Be a bit paranoid here, some perf.data file came with
-                        * a zero sized synthesized MMAP event for the kernel.
-                        */
-                       if (session->vmlinux_maps[MAP__FUNCTION]->end == 0)
-                               session->vmlinux_maps[MAP__FUNCTION]->end = ~0UL;
+int event__process_mmap(event_t *self, struct perf_session *session)
+{
+       struct machine *machine;
+       struct thread *thread;
+       struct map *map;
+       u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+       int ret = 0;
 
-                       perf_session__set_kallsyms_ref_reloc_sym(session, symbol_name,
-                                                                self->mmap.pgoff);
-               }
+       dump_printf(" %d/%d: [%#Lx(%#Lx) @ %#Lx]: %s\n",
+                       self->mmap.pid, self->mmap.tid, self->mmap.start,
+                       self->mmap.len, self->mmap.pgoff, self->mmap.filename);
+
+       if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL ||
+           cpumode == PERF_RECORD_MISC_KERNEL) {
+               ret = event__process_kernel_mmap(self, session);
+               if (ret < 0)
+                       goto out_problem;
                return 0;
        }
 
+       machine = perf_session__find_host_machine(session);
+       if (machine == NULL)
+               goto out_problem;
        thread = perf_session__findnew(session, self->mmap.pid);
-       map = map__new(&self->mmap, MAP__FUNCTION,
-                      session->cwd, session->cwdlen);
+       map = map__new(&machine->user_dsos, self->mmap.start,
+                       self->mmap.len, self->mmap.pgoff,
+                       self->mmap.pid, self->mmap.filename,
+                       MAP__FUNCTION, session->cwd, session->cwdlen);
 
        if (thread == NULL || map == NULL)
                goto out_problem;
@@ -434,22 +557,56 @@ int event__process_task(event_t *self, struct perf_session *session)
 
 void thread__find_addr_map(struct thread *self,
                           struct perf_session *session, u8 cpumode,
-                          enum map_type type, u64 addr,
+                          enum map_type type, pid_t pid, u64 addr,
                           struct addr_location *al)
 {
        struct map_groups *mg = &self->mg;
+       struct machine *machine = NULL;
 
        al->thread = self;
        al->addr = addr;
+       al->cpumode = cpumode;
+       al->filtered = false;
 
-       if (cpumode == PERF_RECORD_MISC_KERNEL) {
+       if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
                al->level = 'k';
-               mg = &session->kmaps;
-       } else if (cpumode == PERF_RECORD_MISC_USER)
+               machine = perf_session__find_host_machine(session);
+               if (machine == NULL) {
+                       al->map = NULL;
+                       return;
+               }
+               mg = &machine->kmaps;
+       } else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
                al->level = '.';
-       else {
-               al->level = 'H';
+               machine = perf_session__find_host_machine(session);
+       } else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
+               al->level = 'g';
+               machine = perf_session__find_machine(session, pid);
+               if (machine == NULL) {
+                       al->map = NULL;
+                       return;
+               }
+               mg = &machine->kmaps;
+       } else {
+               /*
+                * 'u' means guest os user space.
+                * TODO: We don't support guest user space. Might support late.
+                */
+               if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest)
+                       al->level = 'u';
+               else
+                       al->level = 'H';
                al->map = NULL;
+
+               if ((cpumode == PERF_RECORD_MISC_GUEST_USER ||
+                       cpumode == PERF_RECORD_MISC_GUEST_KERNEL) &&
+                       !perf_guest)
+                       al->filtered = true;
+               if ((cpumode == PERF_RECORD_MISC_USER ||
+                       cpumode == PERF_RECORD_MISC_KERNEL) &&
+                       !perf_host)
+                       al->filtered = true;
+
                return;
        }
 try_again:
@@ -464,8 +621,10 @@ try_again:
                 * "[vdso]" dso, but for now lets use the old trick of looking
                 * in the whole kernel symbol list.
                 */
-               if ((long long)al->addr < 0 && mg != &session->kmaps) {
-                       mg = &session->kmaps;
+               if ((long long)al->addr < 0 &&
+                   cpumode == PERF_RECORD_MISC_KERNEL &&
+                   machine && mg != &machine->kmaps) {
+                       mg = &machine->kmaps;
                        goto try_again;
                }
        } else
@@ -474,11 +633,11 @@ try_again:
 
 void thread__find_addr_location(struct thread *self,
                                struct perf_session *session, u8 cpumode,
-                               enum map_type type, u64 addr,
+                               enum map_type type, pid_t pid, u64 addr,
                                struct addr_location *al,
                                symbol_filter_t filter)
 {
-       thread__find_addr_map(self, session, cpumode, type, addr, al);
+       thread__find_addr_map(self, session, cpumode, type, pid, addr, al);
        if (al->map != NULL)
                al->sym = map__find_symbol(al->map, al->addr, filter);
        else
@@ -490,8 +649,10 @@ static void dso__calc_col_width(struct dso *self)
        if (!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
            (!symbol_conf.dso_list ||
             strlist__has_entry(symbol_conf.dso_list, self->name))) {
-               unsigned int slen = strlen(self->name);
-               if (slen > dsos__col_width)
+               u16 slen = self->short_name_len;
+               if (verbose)
+                       slen = self->long_name_len;
+               if (dsos__col_width < slen)
                        dsos__col_width = slen;
        }
 
@@ -512,31 +673,55 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
                goto out_filtered;
 
        dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
+       /*
+        * Have we already created the kernel maps for the host machine?
+        *
+        * This should have happened earlier, when we processed the kernel MMAP
+        * events, but for older perf.data files there was no such thing, so do
+        * it now.
+        */
+       if (cpumode == PERF_RECORD_MISC_KERNEL &&
+           session->host_machine.vmlinux_maps[MAP__FUNCTION] == NULL)
+               machine__create_kernel_maps(&session->host_machine);
 
-       thread__find_addr_location(thread, session, cpumode, MAP__FUNCTION,
-                                  self->ip.ip, al, filter);
+       thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
+                             self->ip.pid, self->ip.ip, al);
        dump_printf(" ...... dso: %s\n",
                    al->map ? al->map->dso->long_name :
                        al->level == 'H' ? "[hypervisor]" : "<not found>");
-       /*
-        * We have to do this here as we may have a dso with no symbol hit that
-        * has a name longer than the ones with symbols sampled.
-        */
-       if (al->map && !sort_dso.elide && !al->map->dso->slen_calculated)
-               dso__calc_col_width(al->map->dso);
-
-       if (symbol_conf.dso_list &&
-           (!al->map || !al->map->dso ||
-            !(strlist__has_entry(symbol_conf.dso_list, al->map->dso->short_name) ||
-              (al->map->dso->short_name != al->map->dso->long_name &&
-               strlist__has_entry(symbol_conf.dso_list, al->map->dso->long_name)))))
-               goto out_filtered;
+       al->sym = NULL;
+
+       if (al->map) {
+               if (symbol_conf.dso_list &&
+                   (!al->map || !al->map->dso ||
+                    !(strlist__has_entry(symbol_conf.dso_list,
+                                         al->map->dso->short_name) ||
+                      (al->map->dso->short_name != al->map->dso->long_name &&
+                       strlist__has_entry(symbol_conf.dso_list,
+                                          al->map->dso->long_name)))))
+                       goto out_filtered;
+               /*
+                * We have to do this here as we may have a dso with no symbol
+                * hit that has a name longer than the ones with symbols
+                * sampled.
+                */
+               if (!sort_dso.elide && !al->map->dso->slen_calculated)
+                       dso__calc_col_width(al->map->dso);
+
+               al->sym = map__find_symbol(al->map, al->addr, filter);
+       } else {
+               const unsigned int unresolved_col_width = BITS_PER_LONG / 4;
+
+               if (dsos__col_width < unresolved_col_width &&
+                   !symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
+                   !symbol_conf.dso_list)
+                       dsos__col_width = unresolved_col_width;
+       }
 
        if (symbol_conf.sym_list && al->sym &&
            !strlist__has_entry(symbol_conf.sym_list, al->sym->name))
                goto out_filtered;
 
-       al->filtered = false;
        return 0;
 
 out_filtered:
@@ -570,6 +755,7 @@ int event__parse_sample(event_t *event, u64 type, struct sample_data *data)
                array++;
        }
 
+       data->id = -1ULL;
        if (type & PERF_SAMPLE_ID) {
                data->id = *array;
                array++;
index a33b949..8577085 100644 (file)
@@ -68,21 +68,54 @@ struct sample_data {
        u64 addr;
        u64 id;
        u64 stream_id;
-       u32 cpu;
        u64 period;
-       struct ip_callchain *callchain;
+       u32 cpu;
        u32 raw_size;
        void *raw_data;
+       struct ip_callchain *callchain;
 };
 
 #define BUILD_ID_SIZE 20
 
 struct build_id_event {
        struct perf_event_header header;
+       pid_t                    pid;
        u8                       build_id[ALIGN(BUILD_ID_SIZE, sizeof(u64))];
        char                     filename[];
 };
 
+enum perf_user_event_type { /* above any possible kernel type */
+       PERF_RECORD_HEADER_ATTR                 = 64,
+       PERF_RECORD_HEADER_EVENT_TYPE           = 65,
+       PERF_RECORD_HEADER_TRACING_DATA         = 66,
+       PERF_RECORD_HEADER_BUILD_ID             = 67,
+       PERF_RECORD_FINISHED_ROUND              = 68,
+       PERF_RECORD_HEADER_MAX
+};
+
+struct attr_event {
+       struct perf_event_header header;
+       struct perf_event_attr attr;
+       u64 id[];
+};
+
+#define MAX_EVENT_NAME 64
+
+struct perf_trace_event_type {
+       u64     event_id;
+       char    name[MAX_EVENT_NAME];
+};
+
+struct event_type_event {
+       struct perf_event_header header;
+       struct perf_trace_event_type event_type;
+};
+
+struct tracing_data_event {
+       struct perf_event_header header;
+       u32 size;
+};
+
 typedef union event_union {
        struct perf_event_header        header;
        struct ip_event                 ip;
@@ -92,22 +125,12 @@ typedef union event_union {
        struct lost_event               lost;
        struct read_event               read;
        struct sample_event             sample;
+       struct attr_event               attr;
+       struct event_type_event         event_type;
+       struct tracing_data_event       tracing_data;
+       struct build_id_event           build_id;
 } event_t;
 
-struct events_stats {
-       u64 total;
-       u64 lost;
-};
-
-struct event_stat_id {
-       struct rb_node          rb_node;
-       struct rb_root          hists;
-       struct events_stats     stats;
-       u64                     config;
-       u64                     event_stream;
-       u32                     type;
-};
-
 void event__print_totals(void);
 
 struct perf_session;
@@ -119,10 +142,13 @@ int event__synthesize_thread(pid_t pid, event__handler_t process,
 void event__synthesize_threads(event__handler_t process,
                               struct perf_session *session);
 int event__synthesize_kernel_mmap(event__handler_t process,
-                                 struct perf_session *session,
-                                 const char *symbol_name);
+                               struct perf_session *session,
+                               struct machine *machine,
+                               const char *symbol_name);
+
 int event__synthesize_modules(event__handler_t process,
-                             struct perf_session *session);
+                             struct perf_session *session,
+                             struct machine *machine);
 
 int event__process_comm(event_t *self, struct perf_session *session);
 int event__process_lost(event_t *self, struct perf_session *session);
@@ -134,4 +160,6 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
                             struct addr_location *al, symbol_filter_t filter);
 int event__parse_sample(event_t *event, u64 type, struct sample_data *data);
 
+extern const char *event__name[];
+
 #endif /* __PERF_RECORD_H */
index 6c9aa16..8847bec 100644 (file)
@@ -99,13 +99,6 @@ int perf_header__add_attr(struct perf_header *self,
        return 0;
 }
 
-#define MAX_EVENT_NAME 64
-
-struct perf_trace_event_type {
-       u64     event_id;
-       char    name[MAX_EVENT_NAME];
-};
-
 static int event_count;
 static struct perf_trace_event_type *events;
 
@@ -197,7 +190,8 @@ static int write_padded(int fd, const void *bf, size_t count,
                        continue;               \
                else
 
-static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd)
+static int __dsos__write_buildid_table(struct list_head *head, pid_t pid,
+                               u16 misc, int fd)
 {
        struct dso *pos;
 
@@ -212,6 +206,7 @@ static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd)
                len = ALIGN(len, NAME_ALIGN);
                memset(&b, 0, sizeof(b));
                memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
+               b.pid = pid;
                b.header.misc = misc;
                b.header.size = sizeof(b) + len;
                err = do_write(fd, &b, sizeof(b));
@@ -226,13 +221,32 @@ static int __dsos__write_buildid_table(struct list_head *head, u16 misc, int fd)
        return 0;
 }
 
-static int dsos__write_buildid_table(int fd)
+static int dsos__write_buildid_table(struct perf_header *header, int fd)
 {
-       int err = __dsos__write_buildid_table(&dsos__kernel,
-                                             PERF_RECORD_MISC_KERNEL, fd);
-       if (err == 0)
-               err = __dsos__write_buildid_table(&dsos__user,
-                                                 PERF_RECORD_MISC_USER, fd);
+       struct perf_session *session = container_of(header,
+                       struct perf_session, header);
+       struct rb_node *nd;
+       int err = 0;
+       u16 kmisc, umisc;
+
+       for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               if (machine__is_host(pos)) {
+                       kmisc = PERF_RECORD_MISC_KERNEL;
+                       umisc = PERF_RECORD_MISC_USER;
+               } else {
+                       kmisc = PERF_RECORD_MISC_GUEST_KERNEL;
+                       umisc = PERF_RECORD_MISC_GUEST_USER;
+               }
+
+               err = __dsos__write_buildid_table(&pos->kernel_dsos, pos->pid,
+                                                 kmisc, fd);
+               if (err == 0)
+                       err = __dsos__write_buildid_table(&pos->user_dsos,
+                                                         pos->pid, umisc, fd);
+               if (err)
+                       break;
+       }
        return err;
 }
 
@@ -349,9 +363,12 @@ static int __dsos__cache_build_ids(struct list_head *head, const char *debugdir)
        return err;
 }
 
-static int dsos__cache_build_ids(void)
+static int dsos__cache_build_ids(struct perf_header *self)
 {
-       int err_kernel, err_user;
+       struct perf_session *session = container_of(self,
+                       struct perf_session, header);
+       struct rb_node *nd;
+       int ret = 0;
        char debugdir[PATH_MAX];
 
        snprintf(debugdir, sizeof(debugdir), "%s/%s", getenv("HOME"),
@@ -360,9 +377,28 @@ static int dsos__cache_build_ids(void)
        if (mkdir(debugdir, 0755) != 0 && errno != EEXIST)
                return -1;
 
-       err_kernel = __dsos__cache_build_ids(&dsos__kernel, debugdir);
-       err_user   = __dsos__cache_build_ids(&dsos__user, debugdir);
-       return err_kernel || err_user ? -1 : 0;
+       for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               ret |= __dsos__cache_build_ids(&pos->kernel_dsos, debugdir);
+               ret |= __dsos__cache_build_ids(&pos->user_dsos, debugdir);
+       }
+       return ret ? -1 : 0;
+}
+
+static bool dsos__read_build_ids(struct perf_header *self, bool with_hits)
+{
+       bool ret = false;
+       struct perf_session *session = container_of(self,
+                       struct perf_session, header);
+       struct rb_node *nd;
+
+       for (nd = rb_first(&session->machines); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               ret |= __dsos__read_build_ids(&pos->kernel_dsos, with_hits);
+               ret |= __dsos__read_build_ids(&pos->user_dsos, with_hits);
+       }
+
+       return ret;
 }
 
 static int perf_header__adds_write(struct perf_header *self, int fd)
@@ -373,7 +409,7 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
        u64 sec_start;
        int idx = 0, err;
 
-       if (dsos__read_build_ids(true))
+       if (dsos__read_build_ids(self, true))
                perf_header__set_feat(self, HEADER_BUILD_ID);
 
        nr_sections = bitmap_weight(self->adds_features, HEADER_FEAT_BITS);
@@ -400,7 +436,6 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
                trace_sec->size = lseek(fd, 0, SEEK_CUR) - trace_sec->offset;
        }
 
-
        if (perf_header__has_feat(self, HEADER_BUILD_ID)) {
                struct perf_file_section *buildid_sec;
 
@@ -408,14 +443,14 @@ static int perf_header__adds_write(struct perf_header *self, int fd)
 
                /* Write build-ids */
                buildid_sec->offset = lseek(fd, 0, SEEK_CUR);
-               err = dsos__write_buildid_table(fd);
+               err = dsos__write_buildid_table(self, fd);
                if (err < 0) {
                        pr_debug("failed to write buildid table\n");
                        goto out_free;
                }
                buildid_sec->size = lseek(fd, 0, SEEK_CUR) -
                                          buildid_sec->offset;
-               dsos__cache_build_ids();
+               dsos__cache_build_ids(self);
        }
 
        lseek(fd, sec_start, SEEK_SET);
@@ -427,6 +462,25 @@ out_free:
        return err;
 }
 
+int perf_header__write_pipe(int fd)
+{
+       struct perf_pipe_file_header f_header;
+       int err;
+
+       f_header = (struct perf_pipe_file_header){
+               .magic     = PERF_MAGIC,
+               .size      = sizeof(f_header),
+       };
+
+       err = do_write(fd, &f_header, sizeof(f_header));
+       if (err < 0) {
+               pr_debug("failed to write perf pipe header\n");
+               return err;
+       }
+
+       return 0;
+}
+
 int perf_header__write(struct perf_header *self, int fd, bool at_exit)
 {
        struct perf_file_header f_header;
@@ -518,25 +572,10 @@ int perf_header__write(struct perf_header *self, int fd, bool at_exit)
        return 0;
 }
 
-static int do_read(int fd, void *buf, size_t size)
-{
-       while (size) {
-               int ret = read(fd, buf, size);
-
-               if (ret <= 0)
-                       return -1;
-
-               size -= ret;
-               buf += ret;
-       }
-
-       return 0;
-}
-
 static int perf_header__getbuffer64(struct perf_header *self,
                                    int fd, void *buf, size_t size)
 {
-       if (do_read(fd, buf, size))
+       if (do_read(fd, buf, size) <= 0)
                return -1;
 
        if (self->needs_swap)
@@ -592,7 +631,7 @@ int perf_file_header__read(struct perf_file_header *self,
 {
        lseek(fd, 0, SEEK_SET);
 
-       if (do_read(fd, self, sizeof(*self)) ||
+       if (do_read(fd, self, sizeof(*self)) <= 0 ||
            memcmp(&self->magic, __perf_magic, sizeof(self->magic)))
                return -1;
 
@@ -636,6 +675,93 @@ int perf_file_header__read(struct perf_file_header *self,
        return 0;
 }
 
+static int __event_process_build_id(struct build_id_event *bev,
+                                   char *filename,
+                                   struct perf_session *session)
+{
+       int err = -1;
+       struct list_head *head;
+       struct machine *machine;
+       u16 misc;
+       struct dso *dso;
+       enum dso_kernel_type dso_type;
+
+       machine = perf_session__findnew_machine(session, bev->pid);
+       if (!machine)
+               goto out;
+
+       misc = bev->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
+
+       switch (misc) {
+       case PERF_RECORD_MISC_KERNEL:
+               dso_type = DSO_TYPE_KERNEL;
+               head = &machine->kernel_dsos;
+               break;
+       case PERF_RECORD_MISC_GUEST_KERNEL:
+               dso_type = DSO_TYPE_GUEST_KERNEL;
+               head = &machine->kernel_dsos;
+               break;
+       case PERF_RECORD_MISC_USER:
+       case PERF_RECORD_MISC_GUEST_USER:
+               dso_type = DSO_TYPE_USER;
+               head = &machine->user_dsos;
+               break;
+       default:
+               goto out;
+       }
+
+       dso = __dsos__findnew(head, filename);
+       if (dso != NULL) {
+               char sbuild_id[BUILD_ID_SIZE * 2 + 1];
+
+               dso__set_build_id(dso, &bev->build_id);
+
+               if (filename[0] == '[')
+                       dso->kernel = dso_type;
+
+               build_id__sprintf(dso->build_id, sizeof(dso->build_id),
+                                 sbuild_id);
+               pr_debug("build id event received for %s: %s\n",
+                        dso->long_name, sbuild_id);
+       }
+
+       err = 0;
+out:
+       return err;
+}
+
+static int perf_header__read_build_ids(struct perf_header *self,
+                       int input, u64 offset, u64 size)
+{
+       struct perf_session *session = container_of(self,
+                       struct perf_session, header);
+       struct build_id_event bev;
+       char filename[PATH_MAX];
+       u64 limit = offset + size;
+       int err = -1;
+
+       while (offset < limit) {
+               ssize_t len;
+
+               if (read(input, &bev, sizeof(bev)) != sizeof(bev))
+                       goto out;
+
+               if (self->needs_swap)
+                       perf_event_header__bswap(&bev.header);
+
+               len = bev.header.size - sizeof(bev);
+               if (read(input, filename, len) != len)
+                       goto out;
+
+               __event_process_build_id(&bev, filename, session);
+
+               offset += bev.header.size;
+       }
+       err = 0;
+out:
+       return err;
+}
+
 static int perf_file_section__process(struct perf_file_section *self,
                                      struct perf_header *ph,
                                      int feat, int fd)
@@ -648,7 +774,7 @@ static int perf_file_section__process(struct perf_file_section *self,
 
        switch (feat) {
        case HEADER_TRACE_INFO:
-               trace_report(fd);
+               trace_report(fd, false);
                break;
 
        case HEADER_BUILD_ID:
@@ -662,13 +788,56 @@ static int perf_file_section__process(struct perf_file_section *self,
        return 0;
 }
 
-int perf_header__read(struct perf_header *self, int fd)
+static int perf_file_header__read_pipe(struct perf_pipe_file_header *self,
+                                      struct perf_header *ph, int fd,
+                                      bool repipe)
+{
+       if (do_read(fd, self, sizeof(*self)) <= 0 ||
+           memcmp(&self->magic, __perf_magic, sizeof(self->magic)))
+               return -1;
+
+       if (repipe && do_write(STDOUT_FILENO, self, sizeof(*self)) < 0)
+               return -1;
+
+       if (self->size != sizeof(*self)) {
+               u64 size = bswap_64(self->size);
+
+               if (size != sizeof(*self))
+                       return -1;
+
+               ph->needs_swap = true;
+       }
+
+       return 0;
+}
+
+static int perf_header__read_pipe(struct perf_session *session, int fd)
 {
+       struct perf_header *self = &session->header;
+       struct perf_pipe_file_header f_header;
+
+       if (perf_file_header__read_pipe(&f_header, self, fd,
+                                       session->repipe) < 0) {
+               pr_debug("incompatible file format\n");
+               return -EINVAL;
+       }
+
+       session->fd = fd;
+
+       return 0;
+}
+
+int perf_header__read(struct perf_session *session, int fd)
+{
+       struct perf_header *self = &session->header;
        struct perf_file_header f_header;
        struct perf_file_attr   f_attr;
        u64                     f_id;
        int nr_attrs, nr_ids, i, j;
 
+       if (session->fd_pipe)
+               return perf_header__read_pipe(session, fd);
+
        if (perf_file_header__read(&f_header, self, fd) < 0) {
                pr_debug("incompatible file format\n");
                return -EINVAL;
@@ -753,6 +922,14 @@ perf_header__find_attr(u64 id, struct perf_header *header)
 {
        int i;
 
+       /*
+        * We set id to -1 if the data file doesn't contain sample
+        * ids. Check for this and avoid walking through the entire
+        * list of ids which may be large.
+        */
+       if (id == -1ULL)
+               return NULL;
+
        for (i = 0; i < header->attrs; i++) {
                struct perf_header_attr *attr = header->attr[i];
                int j;
@@ -765,3 +942,231 @@ perf_header__find_attr(u64 id, struct perf_header *header)
 
        return NULL;
 }
+
+int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
+                          event__handler_t process,
+                          struct perf_session *session)
+{
+       event_t *ev;
+       size_t size;
+       int err;
+
+       size = sizeof(struct perf_event_attr);
+       size = ALIGN(size, sizeof(u64));
+       size += sizeof(struct perf_event_header);
+       size += ids * sizeof(u64);
+
+       ev = malloc(size);
+
+       ev->attr.attr = *attr;
+       memcpy(ev->attr.id, id, ids * sizeof(u64));
+
+       ev->attr.header.type = PERF_RECORD_HEADER_ATTR;
+       ev->attr.header.size = size;
+
+       err = process(ev, session);
+
+       free(ev);
+
+       return err;
+}
+
+int event__synthesize_attrs(struct perf_header *self,
+                           event__handler_t process,
+                           struct perf_session *session)
+{
+       struct perf_header_attr *attr;
+       int i, err = 0;
+
+       for (i = 0; i < self->attrs; i++) {
+               attr = self->attr[i];
+
+               err = event__synthesize_attr(&attr->attr, attr->ids, attr->id,
+                                            process, session);
+               if (err) {
+                       pr_debug("failed to create perf header attribute\n");
+                       return err;
+               }
+       }
+
+       return err;
+}
+
+int event__process_attr(event_t *self, struct perf_session *session)
+{
+       struct perf_header_attr *attr;
+       unsigned int i, ids, n_ids;
+
+       attr = perf_header_attr__new(&self->attr.attr);
+       if (attr == NULL)
+               return -ENOMEM;
+
+       ids = self->header.size;
+       ids -= (void *)&self->attr.id - (void *)self;
+       n_ids = ids / sizeof(u64);
+
+       for (i = 0; i < n_ids; i++) {
+               if (perf_header_attr__add_id(attr, self->attr.id[i]) < 0) {
+                       perf_header_attr__delete(attr);
+                       return -ENOMEM;
+               }
+       }
+
+       if (perf_header__add_attr(&session->header, attr) < 0) {
+               perf_header_attr__delete(attr);
+               return -ENOMEM;
+       }
+
+       perf_session__update_sample_type(session);
+
+       return 0;
+}
+
+int event__synthesize_event_type(u64 event_id, char *name,
+                                event__handler_t process,
+                                struct perf_session *session)
+{
+       event_t ev;
+       size_t size = 0;
+       int err = 0;
+
+       memset(&ev, 0, sizeof(ev));
+
+       ev.event_type.event_type.event_id = event_id;
+       memset(ev.event_type.event_type.name, 0, MAX_EVENT_NAME);
+       strncpy(ev.event_type.event_type.name, name, MAX_EVENT_NAME - 1);
+
+       ev.event_type.header.type = PERF_RECORD_HEADER_EVENT_TYPE;
+       size = strlen(name);
+       size = ALIGN(size, sizeof(u64));
+       ev.event_type.header.size = sizeof(ev.event_type) -
+               (sizeof(ev.event_type.event_type.name) - size);
+
+       err = process(&ev, session);
+
+       return err;
+}
+
+int event__synthesize_event_types(event__handler_t process,
+                                 struct perf_session *session)
+{
+       struct perf_trace_event_type *type;
+       int i, err = 0;
+
+       for (i = 0; i < event_count; i++) {
+               type = &events[i];
+
+               err = event__synthesize_event_type(type->event_id, type->name,
+                                                  process, session);
+               if (err) {
+                       pr_debug("failed to create perf header event type\n");
+                       return err;
+               }
+       }
+
+       return err;
+}
+
+int event__process_event_type(event_t *self,
+                             struct perf_session *session __unused)
+{
+       if (perf_header__push_event(self->event_type.event_type.event_id,
+                                   self->event_type.event_type.name) < 0)
+               return -ENOMEM;
+
+       return 0;
+}
+
+int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs,
+                                  int nb_events,
+                                  event__handler_t process,
+                                  struct perf_session *session __unused)
+{
+       event_t ev;
+       ssize_t size = 0, aligned_size = 0, padding;
+       int err = 0;
+
+       memset(&ev, 0, sizeof(ev));
+
+       ev.tracing_data.header.type = PERF_RECORD_HEADER_TRACING_DATA;
+       size = read_tracing_data_size(fd, pattrs, nb_events);
+       if (size <= 0)
+               return size;
+       aligned_size = ALIGN(size, sizeof(u64));
+       padding = aligned_size - size;
+       ev.tracing_data.header.size = sizeof(ev.tracing_data);
+       ev.tracing_data.size = aligned_size;
+
+       process(&ev, session);
+
+       err = read_tracing_data(fd, pattrs, nb_events);
+       write_padded(fd, NULL, 0, padding);
+
+       return aligned_size;
+}
+
+int event__process_tracing_data(event_t *self,
+                               struct perf_session *session)
+{
+       ssize_t size_read, padding, size = self->tracing_data.size;
+       off_t offset = lseek(session->fd, 0, SEEK_CUR);
+       char buf[BUFSIZ];
+
+       /* setup for reading amidst mmap */
+       lseek(session->fd, offset + sizeof(struct tracing_data_event),
+             SEEK_SET);
+
+       size_read = trace_report(session->fd, session->repipe);
+
+       padding = ALIGN(size_read, sizeof(u64)) - size_read;
+
+       if (read(session->fd, buf, padding) < 0)
+               die("reading input file");
+       if (session->repipe) {
+               int retw = write(STDOUT_FILENO, buf, padding);
+               if (retw <= 0 || retw != padding)
+                       die("repiping tracing data padding");
+       }
+
+       if (size_read + padding != size)
+               die("tracing data size mismatch");
+
+       return size_read + padding;
+}
+
+int event__synthesize_build_id(struct dso *pos, u16 misc,
+                              event__handler_t process,
+                              struct machine *machine,
+                              struct perf_session *session)
+{
+       event_t ev;
+       size_t len;
+       int err = 0;
+
+       if (!pos->hit)
+               return err;
+
+       memset(&ev, 0, sizeof(ev));
+
+       len = pos->long_name_len + 1;
+       len = ALIGN(len, NAME_ALIGN);
+       memcpy(&ev.build_id.build_id, pos->build_id, sizeof(pos->build_id));
+       ev.build_id.header.type = PERF_RECORD_HEADER_BUILD_ID;
+       ev.build_id.header.misc = misc;
+       ev.build_id.pid = machine->pid;
+       ev.build_id.header.size = sizeof(ev.build_id) + len;
+       memcpy(&ev.build_id.filename, pos->long_name, pos->long_name_len);
+
+       err = process(&ev, session);
+
+       return err;
+}
+
+int event__process_build_id(event_t *self,
+                           struct perf_session *session)
+{
+       __event_process_build_id(&self->build_id,
+                                self->build_id.filename,
+                                session);
+       return 0;
+}
index 82a6af7..402ac24 100644 (file)
@@ -39,6 +39,11 @@ struct perf_file_header {
        DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
 };
 
+struct perf_pipe_file_header {
+       u64                             magic;
+       u64                             size;
+};
+
 struct perf_header;
 
 int perf_file_header__read(struct perf_file_header *self,
@@ -47,21 +52,22 @@ int perf_file_header__read(struct perf_file_header *self,
 struct perf_header {
        int                     frozen;
        int                     attrs, size;
+       bool                    needs_swap;
        struct perf_header_attr **attr;
        s64                     attr_offset;
        u64                     data_offset;
        u64                     data_size;
        u64                     event_offset;
        u64                     event_size;
-       bool                    needs_swap;
        DECLARE_BITMAP(adds_features, HEADER_FEAT_BITS);
 };
 
 int perf_header__init(struct perf_header *self);
 void perf_header__exit(struct perf_header *self);
 
-int perf_header__read(struct perf_header *self, int fd);
+int perf_header__read(struct perf_session *session, int fd);
 int perf_header__write(struct perf_header *self, int fd, bool at_exit);
+int perf_header__write_pipe(int fd);
 
 int perf_header__add_attr(struct perf_header *self,
                          struct perf_header_attr *attr);
@@ -89,4 +95,33 @@ int build_id_cache__add_s(const char *sbuild_id, const char *debugdir,
                          const char *name, bool is_kallsyms);
 int build_id_cache__remove_s(const char *sbuild_id, const char *debugdir);
 
+int event__synthesize_attr(struct perf_event_attr *attr, u16 ids, u64 *id,
+                          event__handler_t process,
+                          struct perf_session *session);
+int event__synthesize_attrs(struct perf_header *self,
+                           event__handler_t process,
+                           struct perf_session *session);
+int event__process_attr(event_t *self, struct perf_session *session);
+
+int event__synthesize_event_type(u64 event_id, char *name,
+                                event__handler_t process,
+                                struct perf_session *session);
+int event__synthesize_event_types(event__handler_t process,
+                                 struct perf_session *session);
+int event__process_event_type(event_t *self,
+                             struct perf_session *session);
+
+int event__synthesize_tracing_data(int fd, struct perf_event_attr *pattrs,
+                                  int nb_events,
+                                  event__handler_t process,
+                                  struct perf_session *session);
+int event__process_tracing_data(event_t *self,
+                               struct perf_session *session);
+
+int event__synthesize_build_id(struct dso *pos, u16 misc,
+                              event__handler_t process,
+                              struct machine *machine,
+                              struct perf_session *session);
+int event__process_build_id(event_t *self, struct perf_session *session);
+
 #endif /* __PERF_HEADER_H */
index 2be33c7..9a71c94 100644 (file)
@@ -1,3 +1,4 @@
+#include "util.h"
 #include "hist.h"
 #include "session.h"
 #include "sort.h"
@@ -8,25 +9,69 @@ struct callchain_param        callchain_param = {
        .min_percent = 0.5
 };
 
+static void hist_entry__add_cpumode_period(struct hist_entry *self,
+                                          unsigned int cpumode, u64 period)
+{
+       switch (cpumode) {
+       case PERF_RECORD_MISC_KERNEL:
+               self->period_sys += period;
+               break;
+       case PERF_RECORD_MISC_USER:
+               self->period_us += period;
+               break;
+       case PERF_RECORD_MISC_GUEST_KERNEL:
+               self->period_guest_sys += period;
+               break;
+       case PERF_RECORD_MISC_GUEST_USER:
+               self->period_guest_us += period;
+               break;
+       default:
+               break;
+       }
+}
+
 /*
- * histogram, sorted on item, collects counts
+ * histogram, sorted on item, collects periods
  */
 
-struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
-                                                 struct addr_location *al,
-                                                 struct symbol *sym_parent,
-                                                 u64 count, bool *hit)
+static struct hist_entry *hist_entry__new(struct hist_entry *template)
+{
+       size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0;
+       struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
+
+       if (self != NULL) {
+               *self = *template;
+               self->nr_events = 1;
+               if (symbol_conf.use_callchain)
+                       callchain_init(self->callchain);
+       }
+
+       return self;
+}
+
+static void hists__inc_nr_entries(struct hists *self, struct hist_entry *entry)
 {
-       struct rb_node **p = &hists->rb_node;
+       if (entry->ms.sym && self->max_sym_namelen < entry->ms.sym->namelen)
+               self->max_sym_namelen = entry->ms.sym->namelen;
+       ++self->nr_entries;
+}
+
+struct hist_entry *__hists__add_entry(struct hists *self,
+                                     struct addr_location *al,
+                                     struct symbol *sym_parent, u64 period)
+{
+       struct rb_node **p = &self->entries.rb_node;
        struct rb_node *parent = NULL;
        struct hist_entry *he;
        struct hist_entry entry = {
                .thread = al->thread,
-               .map    = al->map,
-               .sym    = al->sym,
+               .ms = {
+                       .map    = al->map,
+                       .sym    = al->sym,
+               },
                .ip     = al->addr,
                .level  = al->level,
-               .count  = count,
+               .period = period,
                .parent = sym_parent,
        };
        int cmp;
@@ -38,8 +83,9 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
                cmp = hist_entry__cmp(&entry, he);
 
                if (!cmp) {
-                       *hit = true;
-                       return he;
+                       he->period += period;
+                       ++he->nr_events;
+                       goto out;
                }
 
                if (cmp < 0)
@@ -48,13 +94,14 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
                        p = &(*p)->rb_right;
        }
 
-       he = malloc(sizeof(*he));
+       he = hist_entry__new(&entry);
        if (!he)
                return NULL;
-       *he = entry;
        rb_link_node(&he->rb_node, parent, p);
-       rb_insert_color(&he->rb_node, hists);
-       *hit = false;
+       rb_insert_color(&he->rb_node, &self->entries);
+       hists__inc_nr_entries(self, he);
+out:
+       hist_entry__add_cpumode_period(he, al->cpumode, period);
        return he;
 }
 
@@ -65,7 +112,7 @@ hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
        int64_t cmp = 0;
 
        list_for_each_entry(se, &hist_entry__sort_list, list) {
-               cmp = se->cmp(left, right);
+               cmp = se->se_cmp(left, right);
                if (cmp)
                        break;
        }
@@ -82,7 +129,7 @@ hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
        list_for_each_entry(se, &hist_entry__sort_list, list) {
                int64_t (*f)(struct hist_entry *, struct hist_entry *);
 
-               f = se->collapse ?: se->cmp;
+               f = se->se_collapse ?: se->se_cmp;
 
                cmp = f(left, right);
                if (cmp)
@@ -101,7 +148,7 @@ void hist_entry__free(struct hist_entry *he)
  * collapse the histogram
  */
 
-static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
+static bool collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
 {
        struct rb_node **p = &root->rb_node;
        struct rb_node *parent = NULL;
@@ -115,9 +162,9 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
                cmp = hist_entry__collapse(iter, he);
 
                if (!cmp) {
-                       iter->count += he->count;
+                       iter->period += he->period;
                        hist_entry__free(he);
-                       return;
+                       return false;
                }
 
                if (cmp < 0)
@@ -128,9 +175,10 @@ static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
 
        rb_link_node(&he->rb_node, parent, p);
        rb_insert_color(&he->rb_node, root);
+       return true;
 }
 
-void perf_session__collapse_resort(struct rb_root *hists)
+void hists__collapse_resort(struct hists *self)
 {
        struct rb_root tmp;
        struct rb_node *next;
@@ -140,72 +188,77 @@ void perf_session__collapse_resort(struct rb_root *hists)
                return;
 
        tmp = RB_ROOT;
-       next = rb_first(hists);
+       next = rb_first(&self->entries);
+       self->nr_entries = 0;
+       self->max_sym_namelen = 0;
 
        while (next) {
                n = rb_entry(next, struct hist_entry, rb_node);
                next = rb_next(&n->rb_node);
 
-               rb_erase(&n->rb_node, hists);
-               collapse__insert_entry(&tmp, n);
+               rb_erase(&n->rb_node, &self->entries);
+               if (collapse__insert_entry(&tmp, n))
+                       hists__inc_nr_entries(self, n);
        }
 
-       *hists = tmp;
+       self->entries = tmp;
 }
 
 /*
- * reverse the map, sort on count.
+ * reverse the map, sort on period.
  */
 
-static void perf_session__insert_output_hist_entry(struct rb_root *root,
-                                                  struct hist_entry *he,
-                                                  u64 min_callchain_hits)
+static void __hists__insert_output_entry(struct rb_root *entries,
+                                        struct hist_entry *he,
+                                        u64 min_callchain_hits)
 {
-       struct rb_node **p = &root->rb_node;
+       struct rb_node **p = &entries->rb_node;
        struct rb_node *parent = NULL;
        struct hist_entry *iter;
 
        if (symbol_conf.use_callchain)
-               callchain_param.sort(&he->sorted_chain, &he->callchain,
+               callchain_param.sort(&he->sorted_chain, he->callchain,
                                      min_callchain_hits, &callchain_param);
 
        while (*p != NULL) {
                parent = *p;
                iter = rb_entry(parent, struct hist_entry, rb_node);
 
-               if (he->count > iter->count)
+               if (he->period > iter->period)
                        p = &(*p)->rb_left;
                else
                        p = &(*p)->rb_right;
        }
 
        rb_link_node(&he->rb_node, parent, p);
-       rb_insert_color(&he->rb_node, root);
+       rb_insert_color(&he->rb_node, entries);
 }
 
-void perf_session__output_resort(struct rb_root *hists, u64 total_samples)
+void hists__output_resort(struct hists *self)
 {
        struct rb_root tmp;
        struct rb_node *next;
        struct hist_entry *n;
        u64 min_callchain_hits;
 
-       min_callchain_hits =
-               total_samples * (callchain_param.min_percent / 100);
+       min_callchain_hits = self->stats.total_period * (callchain_param.min_percent / 100);
 
        tmp = RB_ROOT;
-       next = rb_first(hists);
+       next = rb_first(&self->entries);
+
+       self->nr_entries = 0;
+       self->max_sym_namelen = 0;
 
        while (next) {
                n = rb_entry(next, struct hist_entry, rb_node);
                next = rb_next(&n->rb_node);
 
-               rb_erase(&n->rb_node, hists);
-               perf_session__insert_output_hist_entry(&tmp, n,
-                                                      min_callchain_hits);
+               rb_erase(&n->rb_node, &self->entries);
+               __hists__insert_output_entry(&tmp, n, min_callchain_hits);
+               hists__inc_nr_entries(self, n);
        }
 
-       *hists = tmp;
+       self->entries = tmp;
 }
 
 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
@@ -237,7 +290,7 @@ static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
 }
 
 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
-                                    int depth, int depth_mask, int count,
+                                    int depth, int depth_mask, int period,
                                     u64 total_samples, int hits,
                                     int left_margin)
 {
@@ -250,7 +303,7 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
                        ret += fprintf(fp, "|");
                else
                        ret += fprintf(fp, " ");
-               if (!count && i == depth - 1) {
+               if (!period && i == depth - 1) {
                        double percent;
 
                        percent = hits * 100.0 / total_samples;
@@ -258,8 +311,8 @@ static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
                } else
                        ret += fprintf(fp, "%s", "          ");
        }
-       if (chain->sym)
-               ret += fprintf(fp, "%s\n", chain->sym->name);
+       if (chain->ms.sym)
+               ret += fprintf(fp, "%s\n", chain->ms.sym->name);
        else
                ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
 
@@ -278,7 +331,7 @@ static void init_rem_hits(void)
        }
 
        strcpy(rem_sq_bracket->name, "[...]");
-       rem_hits.sym = rem_sq_bracket;
+       rem_hits.ms.sym = rem_sq_bracket;
 }
 
 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
@@ -293,6 +346,7 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
        u64 remaining;
        size_t ret = 0;
        int i;
+       uint entries_printed = 0;
 
        if (callchain_param.mode == CHAIN_GRAPH_REL)
                new_total = self->children_hit;
@@ -328,8 +382,6 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
                                                   left_margin);
                i = 0;
                list_for_each_entry(chain, &child->val, list) {
-                       if (chain->ip >= PERF_CONTEXT_MAX)
-                               continue;
                        ret += ipchain__fprintf_graph(fp, chain, depth,
                                                      new_depth_mask, i++,
                                                      new_total,
@@ -341,6 +393,8 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
                                                  new_depth_mask | (1 << depth),
                                                  left_margin);
                node = next;
+               if (++entries_printed == callchain_param.print_limit)
+                       break;
        }
 
        if (callchain_param.mode == CHAIN_GRAPH_REL &&
@@ -366,11 +420,9 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
        bool printed = false;
        int i = 0;
        int ret = 0;
+       u32 entries_printed = 0;
 
        list_for_each_entry(chain, &self->val, list) {
-               if (chain->ip >= PERF_CONTEXT_MAX)
-                       continue;
-
                if (!i++ && sort__first_dimension == SORT_SYM)
                        continue;
 
@@ -385,10 +437,13 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
                } else
                        ret += callchain__fprintf_left_margin(fp, left_margin);
 
-               if (chain->sym)
-                       ret += fprintf(fp, " %s\n", chain->sym->name);
+               if (chain->ms.sym)
+                       ret += fprintf(fp, " %s\n", chain->ms.sym->name);
                else
                        ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
+
+               if (++entries_printed == callchain_param.print_limit)
+                       break;
        }
 
        ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
@@ -411,8 +466,8 @@ static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
        list_for_each_entry(chain, &self->val, list) {
                if (chain->ip >= PERF_CONTEXT_MAX)
                        continue;
-               if (chain->sym)
-                       ret += fprintf(fp, "                %s\n", chain->sym->name);
+               if (chain->ms.sym)
+                       ret += fprintf(fp, "                %s\n", chain->ms.sym->name);
                else
                        ret += fprintf(fp, "                %p\n",
                                        (void *)(long)chain->ip);
@@ -427,6 +482,7 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
        struct rb_node *rb_node;
        struct callchain_node *chain;
        size_t ret = 0;
+       u32 entries_printed = 0;
 
        rb_node = rb_first(&self->sorted_chain);
        while (rb_node) {
@@ -449,55 +505,88 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
                        break;
                }
                ret += fprintf(fp, "\n");
+               if (++entries_printed == callchain_param.print_limit)
+                       break;
                rb_node = rb_next(rb_node);
        }
 
        return ret;
 }
 
-static size_t hist_entry__fprintf(struct hist_entry *self,
-                                 struct perf_session *pair_session,
-                                 bool show_displacement,
-                                 long displacement, FILE *fp,
-                                 u64 session_total)
+int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
+                        struct hists *pair_hists, bool show_displacement,
+                        long displacement, bool color, u64 session_total)
 {
        struct sort_entry *se;
-       u64 count, total;
+       u64 period, total, period_sys, period_us, period_guest_sys, period_guest_us;
        const char *sep = symbol_conf.field_sep;
-       size_t ret;
+       int ret;
 
        if (symbol_conf.exclude_other && !self->parent)
                return 0;
 
-       if (pair_session) {
-               count = self->pair ? self->pair->count : 0;
-               total = pair_session->events_stats.total;
+       if (pair_hists) {
+               period = self->pair ? self->pair->period : 0;
+               total = pair_hists->stats.total_period;
+               period_sys = self->pair ? self->pair->period_sys : 0;
+               period_us = self->pair ? self->pair->period_us : 0;
+               period_guest_sys = self->pair ? self->pair->period_guest_sys : 0;
+               period_guest_us = self->pair ? self->pair->period_guest_us : 0;
        } else {
-               count = self->count;
+               period = self->period;
                total = session_total;
+               period_sys = self->period_sys;
+               period_us = self->period_us;
+               period_guest_sys = self->period_guest_sys;
+               period_guest_us = self->period_guest_us;
        }
 
-       if (total)
-               ret = percent_color_fprintf(fp, sep ? "%.2f" : "   %6.2f%%",
-                                           (count * 100.0) / total);
-       else
-               ret = fprintf(fp, sep ? "%lld" : "%12lld ", count);
+       if (total) {
+               if (color)
+                       ret = percent_color_snprintf(s, size,
+                                                    sep ? "%.2f" : "   %6.2f%%",
+                                                    (period * 100.0) / total);
+               else
+                       ret = snprintf(s, size, sep ? "%.2f" : "   %6.2f%%",
+                                      (period * 100.0) / total);
+               if (symbol_conf.show_cpu_utilization) {
+                       ret += percent_color_snprintf(s + ret, size - ret,
+                                       sep ? "%.2f" : "   %6.2f%%",
+                                       (period_sys * 100.0) / total);
+                       ret += percent_color_snprintf(s + ret, size - ret,
+                                       sep ? "%.2f" : "   %6.2f%%",
+                                       (period_us * 100.0) / total);
+                       if (perf_guest) {
+                               ret += percent_color_snprintf(s + ret,
+                                               size - ret,
+                                               sep ? "%.2f" : "   %6.2f%%",
+                                               (period_guest_sys * 100.0) /
+                                                               total);
+                               ret += percent_color_snprintf(s + ret,
+                                               size - ret,
+                                               sep ? "%.2f" : "   %6.2f%%",
+                                               (period_guest_us * 100.0) /
+                                                               total);
+                       }
+               }
+       } else
+               ret = snprintf(s, size, sep ? "%lld" : "%12lld ", period);
 
        if (symbol_conf.show_nr_samples) {
                if (sep)
-                       fprintf(fp, "%c%lld", *sep, count);
+                       ret += snprintf(s + ret, size - ret, "%c%lld", *sep, period);
                else
-                       fprintf(fp, "%11lld", count);
+                       ret += snprintf(s + ret, size - ret, "%11lld", period);
        }
 
-       if (pair_session) {
+       if (pair_hists) {
                char bf[32];
                double old_percent = 0, new_percent = 0, diff;
 
                if (total > 0)
-                       old_percent = (count * 100.0) / total;
+                       old_percent = (period * 100.0) / total;
                if (session_total > 0)
-                       new_percent = (self->count * 100.0) / session_total;
+                       new_percent = (self->period * 100.0) / session_total;
 
                diff = new_percent - old_percent;
 
@@ -507,9 +596,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self,
                        snprintf(bf, sizeof(bf), " ");
 
                if (sep)
-                       ret += fprintf(fp, "%c%s", *sep, bf);
+                       ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
                else
-                       ret += fprintf(fp, "%11.11s", bf);
+                       ret += snprintf(s + ret, size - ret, "%11.11s", bf);
 
                if (show_displacement) {
                        if (displacement)
@@ -518,9 +607,9 @@ static size_t hist_entry__fprintf(struct hist_entry *self,
                                snprintf(bf, sizeof(bf), " ");
 
                        if (sep)
-                               fprintf(fp, "%c%s", *sep, bf);
+                               ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
                        else
-                               fprintf(fp, "%6.6s", bf);
+                               ret += snprintf(s + ret, size - ret, "%6.6s", bf);
                }
        }
 
@@ -528,33 +617,43 @@ static size_t hist_entry__fprintf(struct hist_entry *self,
                if (se->elide)
                        continue;
 
-               fprintf(fp, "%s", sep ?: "  ");
-               ret += se->print(fp, self, se->width ? *se->width : 0);
+               ret += snprintf(s + ret, size - ret, "%s", sep ?: "  ");
+               ret += se->se_snprintf(self, s + ret, size - ret,
+                                      se->se_width ? *se->se_width : 0);
        }
 
-       ret += fprintf(fp, "\n");
+       return ret;
+}
 
-       if (symbol_conf.use_callchain) {
-               int left_margin = 0;
+int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists,
+                       bool show_displacement, long displacement, FILE *fp,
+                       u64 session_total)
+{
+       char bf[512];
+       hist_entry__snprintf(self, bf, sizeof(bf), pair_hists,
+                            show_displacement, displacement,
+                            true, session_total);
+       return fprintf(fp, "%s\n", bf);
+}
 
-               if (sort__first_dimension == SORT_COMM) {
-                       se = list_first_entry(&hist_entry__sort_list, typeof(*se),
-                                               list);
-                       left_margin = se->width ? *se->width : 0;
-                       left_margin -= thread__comm_len(self->thread);
-               }
+static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
+                                           u64 session_total)
+{
+       int left_margin = 0;
 
-               hist_entry_callchain__fprintf(fp, self, session_total,
-                                             left_margin);
+       if (sort__first_dimension == SORT_COMM) {
+               struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
+                                                        typeof(*se), list);
+               left_margin = se->se_width ? *se->se_width : 0;
+               left_margin -= thread__comm_len(self->thread);
        }
 
-       return ret;
+       return hist_entry_callchain__fprintf(fp, self, session_total,
+                                            left_margin);
 }
 
-size_t perf_session__fprintf_hists(struct rb_root *hists,
-                                  struct perf_session *pair,
-                                  bool show_displacement, FILE *fp,
-                                  u64 session_total)
+size_t hists__fprintf(struct hists *self, struct hists *pair,
+                     bool show_displacement, FILE *fp)
 {
        struct sort_entry *se;
        struct rb_node *nd;
@@ -563,7 +662,7 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,
        long displacement = 0;
        unsigned int width;
        const char *sep = symbol_conf.field_sep;
-       char *col_width = symbol_conf.col_width_list_str;
+       const char *col_width = symbol_conf.col_width_list_str;
 
        init_rem_hits();
 
@@ -576,6 +675,24 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,
                        fputs("  Samples  ", fp);
        }
 
+       if (symbol_conf.show_cpu_utilization) {
+               if (sep) {
+                       ret += fprintf(fp, "%csys", *sep);
+                       ret += fprintf(fp, "%cus", *sep);
+                       if (perf_guest) {
+                               ret += fprintf(fp, "%cguest sys", *sep);
+                               ret += fprintf(fp, "%cguest us", *sep);
+                       }
+               } else {
+                       ret += fprintf(fp, "  sys  ");
+                       ret += fprintf(fp, "  us  ");
+                       if (perf_guest) {
+                               ret += fprintf(fp, "  guest sys  ");
+                               ret += fprintf(fp, "  guest us  ");
+                       }
+               }
+       }
+
        if (pair) {
                if (sep)
                        ret += fprintf(fp, "%cDelta", *sep);
@@ -594,22 +711,22 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,
                if (se->elide)
                        continue;
                if (sep) {
-                       fprintf(fp, "%c%s", *sep, se->header);
+                       fprintf(fp, "%c%s", *sep, se->se_header);
                        continue;
                }
-               width = strlen(se->header);
-               if (se->width) {
+               width = strlen(se->se_header);
+               if (se->se_width) {
                        if (symbol_conf.col_width_list_str) {
                                if (col_width) {
-                                       *se->width = atoi(col_width);
+                                       *se->se_width = atoi(col_width);
                                        col_width = strchr(col_width, ',');
                                        if (col_width)
                                                ++col_width;
                                }
                        }
-                       width = *se->width = max(*se->width, width);
+                       width = *se->se_width = max(*se->se_width, width);
                }
-               fprintf(fp, "  %*s", width, se->header);
+               fprintf(fp, "  %*s", width, se->se_header);
        }
        fprintf(fp, "\n");
 
@@ -631,10 +748,10 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,
                        continue;
 
                fprintf(fp, "  ");
-               if (se->width)
-                       width = *se->width;
+               if (se->se_width)
+                       width = *se->se_width;
                else
-                       width = strlen(se->header);
+                       width = strlen(se->se_header);
                for (i = 0; i < width; i++)
                        fprintf(fp, ".");
        }
@@ -642,7 +759,7 @@ size_t perf_session__fprintf_hists(struct rb_root *hists,
        fprintf(fp, "\n#\n");
 
 print_entries:
-       for (nd = rb_first(hists); nd; nd = rb_next(nd)) {
+       for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
                struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
 
                if (show_displacement) {
@@ -654,10 +771,14 @@ print_entries:
                        ++position;
                }
                ret += hist_entry__fprintf(h, pair, show_displacement,
-                                          displacement, fp, session_total);
-               if (h->map == NULL && verbose > 1) {
+                                          displacement, fp, self->stats.total_period);
+
+               if (symbol_conf.use_callchain)
+                       ret += hist_entry__fprintf_callchain(h, fp, self->stats.total_period);
+
+               if (h->ms.map == NULL && verbose > 1) {
                        __map_groups__fprintf_maps(&h->thread->mg,
-                                                  MAP__FUNCTION, fp);
+                                                  MAP__FUNCTION, verbose, fp);
                        fprintf(fp, "%.10s end\n", graph_dotted_line);
                }
        }
@@ -666,3 +787,271 @@ print_entries:
 
        return ret;
 }
+
+enum hist_filter {
+       HIST_FILTER__DSO,
+       HIST_FILTER__THREAD,
+};
+
+void hists__filter_by_dso(struct hists *self, const struct dso *dso)
+{
+       struct rb_node *nd;
+
+       self->nr_entries = self->stats.total_period = 0;
+       self->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       self->max_sym_namelen = 0;
+
+       for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
+               struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+
+               if (symbol_conf.exclude_other && !h->parent)
+                       continue;
+
+               if (dso != NULL && (h->ms.map == NULL || h->ms.map->dso != dso)) {
+                       h->filtered |= (1 << HIST_FILTER__DSO);
+                       continue;
+               }
+
+               h->filtered &= ~(1 << HIST_FILTER__DSO);
+               if (!h->filtered) {
+                       ++self->nr_entries;
+                       self->stats.total_period += h->period;
+                       self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
+                       if (h->ms.sym &&
+                           self->max_sym_namelen < h->ms.sym->namelen)
+                               self->max_sym_namelen = h->ms.sym->namelen;
+               }
+       }
+}
+
+void hists__filter_by_thread(struct hists *self, const struct thread *thread)
+{
+       struct rb_node *nd;
+
+       self->nr_entries = self->stats.total_period = 0;
+       self->stats.nr_events[PERF_RECORD_SAMPLE] = 0;
+       self->max_sym_namelen = 0;
+
+       for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
+               struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+
+               if (thread != NULL && h->thread != thread) {
+                       h->filtered |= (1 << HIST_FILTER__THREAD);
+                       continue;
+               }
+               h->filtered &= ~(1 << HIST_FILTER__THREAD);
+               if (!h->filtered) {
+                       ++self->nr_entries;
+                       self->stats.total_period += h->period;
+                       self->stats.nr_events[PERF_RECORD_SAMPLE] += h->nr_events;
+                       if (h->ms.sym &&
+                           self->max_sym_namelen < h->ms.sym->namelen)
+                               self->max_sym_namelen = h->ms.sym->namelen;
+               }
+       }
+}
+
+static int symbol__alloc_hist(struct symbol *self)
+{
+       struct sym_priv *priv = symbol__priv(self);
+       const int size = (sizeof(*priv->hist) +
+                         (self->end - self->start) * sizeof(u64));
+
+       priv->hist = zalloc(size);
+       return priv->hist == NULL ? -1 : 0;
+}
+
+int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip)
+{
+       unsigned int sym_size, offset;
+       struct symbol *sym = self->ms.sym;
+       struct sym_priv *priv;
+       struct sym_hist *h;
+
+       if (!sym || !self->ms.map)
+               return 0;
+
+       priv = symbol__priv(sym);
+       if (priv->hist == NULL && symbol__alloc_hist(sym) < 0)
+               return -ENOMEM;
+
+       sym_size = sym->end - sym->start;
+       offset = ip - sym->start;
+
+       pr_debug3("%s: ip=%#Lx\n", __func__, self->ms.map->unmap_ip(self->ms.map, ip));
+
+       if (offset >= sym_size)
+               return 0;
+
+       h = priv->hist;
+       h->sum++;
+       h->ip[offset]++;
+
+       pr_debug3("%#Lx %s: period++ [ip: %#Lx, %#Lx] => %Ld\n", self->ms.sym->start,
+                 self->ms.sym->name, ip, ip - self->ms.sym->start, h->ip[offset]);
+       return 0;
+}
+
+static struct objdump_line *objdump_line__new(s64 offset, char *line)
+{
+       struct objdump_line *self = malloc(sizeof(*self));
+
+       if (self != NULL) {
+               self->offset = offset;
+               self->line = line;
+       }
+
+       return self;
+}
+
+void objdump_line__free(struct objdump_line *self)
+{
+       free(self->line);
+       free(self);
+}
+
+static void objdump__add_line(struct list_head *head, struct objdump_line *line)
+{
+       list_add_tail(&line->node, head);
+}
+
+struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
+                                              struct objdump_line *pos)
+{
+       list_for_each_entry_continue(pos, head, node)
+               if (pos->offset >= 0)
+                       return pos;
+
+       return NULL;
+}
+
+static int hist_entry__parse_objdump_line(struct hist_entry *self, FILE *file,
+                                         struct list_head *head)
+{
+       struct symbol *sym = self->ms.sym;
+       struct objdump_line *objdump_line;
+       char *line = NULL, *tmp, *tmp2, *c;
+       size_t line_len;
+       s64 line_ip, offset = -1;
+
+       if (getline(&line, &line_len, file) < 0)
+               return -1;
+
+       if (!line)
+               return -1;
+
+       while (line_len != 0 && isspace(line[line_len - 1]))
+               line[--line_len] = '\0';
+
+       c = strchr(line, '\n');
+       if (c)
+               *c = 0;
+
+       line_ip = -1;
+
+       /*
+        * Strip leading spaces:
+        */
+       tmp = line;
+       while (*tmp) {
+               if (*tmp != ' ')
+                       break;
+               tmp++;
+       }
+
+       if (*tmp) {
+               /*
+                * Parse hexa addresses followed by ':'
+                */
+               line_ip = strtoull(tmp, &tmp2, 16);
+               if (*tmp2 != ':')
+                       line_ip = -1;
+       }
+
+       if (line_ip != -1) {
+               u64 start = map__rip_2objdump(self->ms.map, sym->start);
+               offset = line_ip - start;
+       }
+
+       objdump_line = objdump_line__new(offset, line);
+       if (objdump_line == NULL) {
+               free(line);
+               return -1;
+       }
+       objdump__add_line(head, objdump_line);
+
+       return 0;
+}
+
+int hist_entry__annotate(struct hist_entry *self, struct list_head *head)
+{
+       struct symbol *sym = self->ms.sym;
+       struct map *map = self->ms.map;
+       struct dso *dso = map->dso;
+       const char *filename = dso->long_name;
+       char command[PATH_MAX * 2];
+       FILE *file;
+       u64 len;
+
+       if (!filename)
+               return -1;
+
+       if (dso->origin == DSO__ORIG_KERNEL) {
+               if (dso->annotate_warned)
+                       return 0;
+               dso->annotate_warned = 1;
+               pr_err("Can't annotate %s: No vmlinux file was found in the "
+                      "path:\n", sym->name);
+               vmlinux_path__fprintf(stderr);
+               return -1;
+       }
+
+       pr_debug("%s: filename=%s, sym=%s, start=%#Lx, end=%#Lx\n", __func__,
+                filename, sym->name, map->unmap_ip(map, sym->start),
+                map->unmap_ip(map, sym->end));
+
+       len = sym->end - sym->start;
+
+       pr_debug("annotating [%p] %30s : [%p] %30s\n",
+                dso, dso->long_name, sym, sym->name);
+
+       snprintf(command, sizeof(command),
+                "objdump --start-address=0x%016Lx --stop-address=0x%016Lx -dS %s|grep -v %s|expand",
+                map__rip_2objdump(map, sym->start),
+                map__rip_2objdump(map, sym->end),
+                filename, filename);
+
+       pr_debug("Executing: %s\n", command);
+
+       file = popen(command, "r");
+       if (!file)
+               return -1;
+
+       while (!feof(file))
+               if (hist_entry__parse_objdump_line(self, file, head) < 0)
+                       break;
+
+       pclose(file);
+       return 0;
+}
+
+void hists__inc_nr_events(struct hists *self, u32 type)
+{
+       ++self->stats.nr_events[0];
+       ++self->stats.nr_events[type];
+}
+
+size_t hists__fprintf_nr_events(struct hists *self, FILE *fp)
+{
+       int i;
+       size_t ret = 0;
+
+       for (i = 0; i < PERF_RECORD_HEADER_MAX; ++i) {
+               if (!event__name[i])
+                       continue;
+               ret += fprintf(fp, "%10s events: %10d\n",
+                              event__name[i], self->stats.nr_events[i]);
+       }
+
+       return ret;
+}
index 16f360c..6f17dcd 100644 (file)
 
 extern struct callchain_param callchain_param;
 
-struct perf_session;
 struct hist_entry;
 struct addr_location;
 struct symbol;
 struct rb_root;
 
-struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
-                                                 struct addr_location *al,
-                                                 struct symbol *parent,
-                                                 u64 count, bool *hit);
+struct objdump_line {
+       struct list_head node;
+       s64              offset;
+       char             *line;
+};
+
+void objdump_line__free(struct objdump_line *self);
+struct objdump_line *objdump__get_next_ip_line(struct list_head *head,
+                                              struct objdump_line *pos);
+
+struct sym_hist {
+       u64             sum;
+       u64             ip[0];
+};
+
+struct sym_ext {
+       struct rb_node  node;
+       double          percent;
+       char            *path;
+};
+
+struct sym_priv {
+       struct sym_hist *hist;
+       struct sym_ext  *ext;
+};
+
+/*
+ * The kernel collects the number of events it couldn't send in a stretch and
+ * when possible sends this number in a PERF_RECORD_LOST event. The number of
+ * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while
+ * total_lost tells exactly how many events the kernel in fact lost, i.e. it is
+ * the sum of all struct lost_event.lost fields reported.
+ *
+ * The total_period is needed because by default auto-freq is used, so
+ * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get
+ * the total number of low level events, it is necessary to to sum all struct
+ * sample_event.period and stash the result in total_period.
+ */
+struct events_stats {
+       u64 total_period;
+       u64 total_lost;
+       u32 nr_events[PERF_RECORD_HEADER_MAX];
+       u32 nr_unknown_events;
+};
+
+struct hists {
+       struct rb_node          rb_node;
+       struct rb_root          entries;
+       u64                     nr_entries;
+       struct events_stats     stats;
+       u64                     config;
+       u64                     event_stream;
+       u32                     type;
+       u32                     max_sym_namelen;
+};
+
+struct hist_entry *__hists__add_entry(struct hists *self,
+                                     struct addr_location *al,
+                                     struct symbol *parent, u64 period);
 extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *);
 extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *);
+int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists,
+                       bool show_displacement, long displacement, FILE *fp,
+                       u64 total);
+int hist_entry__snprintf(struct hist_entry *self, char *bf, size_t size,
+                        struct hists *pair_hists, bool show_displacement,
+                        long displacement, bool color, u64 total);
 void hist_entry__free(struct hist_entry *);
 
-void perf_session__output_resort(struct rb_root *hists, u64 total_samples);
-void perf_session__collapse_resort(struct rb_root *hists);
-size_t perf_session__fprintf_hists(struct rb_root *hists,
-                                  struct perf_session *pair,
-                                  bool show_displacement, FILE *fp,
-                                  u64 session_total);
+void hists__output_resort(struct hists *self);
+void hists__collapse_resort(struct hists *self);
+
+void hists__inc_nr_events(struct hists *self, u32 type);
+size_t hists__fprintf_nr_events(struct hists *self, FILE *fp);
+
+size_t hists__fprintf(struct hists *self, struct hists *pair,
+                     bool show_displacement, FILE *fp);
+
+int hist_entry__inc_addr_samples(struct hist_entry *self, u64 ip);
+int hist_entry__annotate(struct hist_entry *self, struct list_head *head);
+
+void hists__filter_by_dso(struct hists *self, const struct dso *dso);
+void hists__filter_by_thread(struct hists *self, const struct thread *thread);
+
+#ifdef NO_NEWT_SUPPORT
+static inline int hists__browse(struct hists *self __used,
+                               const char *helpline __used,
+                               const char *input_name __used)
+{
+       return 0;
+}
+#else
+int hists__browse(struct hists *self, const char *helpline,
+                 const char *input_name);
+#endif
 #endif /* __PERF_HIST_H */
diff --git a/tools/perf/util/hweight.c b/tools/perf/util/hweight.c
new file mode 100644 (file)
index 0000000..5c1d0d0
--- /dev/null
@@ -0,0 +1,31 @@
+#include <linux/bitops.h>
+
+/**
+ * hweightN - returns the hamming weight of a N-bit word
+ * @x: the word to weigh
+ *
+ * The Hamming Weight of a number is the total number of bits set in it.
+ */
+
+unsigned int hweight32(unsigned int w)
+{
+       unsigned int res = w - ((w >> 1) & 0x55555555);
+       res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
+       res = (res + (res >> 4)) & 0x0F0F0F0F;
+       res = res + (res >> 8);
+       return (res + (res >> 16)) & 0x000000FF;
+}
+
+unsigned long hweight64(__u64 w)
+{
+#if BITS_PER_LONG == 32
+       return hweight32((unsigned int)(w >> 32)) + hweight32((unsigned int)w);
+#elif BITS_PER_LONG == 64
+       __u64 res = w - ((w >> 1) & 0x5555555555555555ul);
+       res = (res & 0x3333333333333333ul) + ((res >> 2) & 0x3333333333333333ul);
+       res = (res + (res >> 4)) & 0x0F0F0F0F0F0F0F0Ful;
+       res = res + (res >> 8);
+       res = res + (res >> 16);
+       return (res + (res >> 32)) & 0x00000000000000FFul;
+#endif
+}
diff --git a/tools/perf/util/include/asm/bitops.h b/tools/perf/util/include/asm/bitops.h
deleted file mode 100644 (file)
index 58e9817..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef _PERF_ASM_BITOPS_H_
-#define _PERF_ASM_BITOPS_H_
-
-#include <sys/types.h>
-#include "../../types.h"
-#include <linux/compiler.h>
-
-/* CHECKME: Not sure both always match */
-#define BITS_PER_LONG  __WORDSIZE
-
-#include "../../../../include/asm-generic/bitops/__fls.h"
-#include "../../../../include/asm-generic/bitops/fls.h"
-#include "../../../../include/asm-generic/bitops/fls64.h"
-#include "../../../../include/asm-generic/bitops/__ffs.h"
-#include "../../../../include/asm-generic/bitops/ffz.h"
-#include "../../../../include/asm-generic/bitops/hweight.h"
-
-#endif
diff --git a/tools/perf/util/include/asm/hweight.h b/tools/perf/util/include/asm/hweight.h
new file mode 100644 (file)
index 0000000..36cf26d
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef PERF_HWEIGHT_H
+#define PERF_HWEIGHT_H
+
+#include <linux/types.h>
+unsigned int hweight32(unsigned int w);
+unsigned long hweight64(__u64 w);
+
+#endif /* PERF_HWEIGHT_H */
diff --git a/tools/perf/util/include/dwarf-regs.h b/tools/perf/util/include/dwarf-regs.h
new file mode 100644 (file)
index 0000000..cf6727e
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _PERF_DWARF_REGS_H_
+#define _PERF_DWARF_REGS_H_
+
+#ifdef DWARF_SUPPORT
+const char *get_arch_regstr(unsigned int n);
+#endif
+
+#endif
index 9450763..eda4416 100644 (file)
@@ -1,3 +1,35 @@
-#include "../../../../include/linux/bitmap.h"
-#include "../../../../include/asm-generic/bitops/find.h"
-#include <linux/errno.h>
+#ifndef _PERF_BITOPS_H
+#define _PERF_BITOPS_H
+
+#include <string.h>
+#include <linux/bitops.h>
+
+int __bitmap_weight(const unsigned long *bitmap, int bits);
+
+#define BITMAP_LAST_WORD_MASK(nbits)                                   \
+(                                                                      \
+       ((nbits) % BITS_PER_LONG) ?                                     \
+               (1UL<<((nbits) % BITS_PER_LONG))-1 : ~0UL               \
+)
+
+#define small_const_nbits(nbits) \
+       (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG)
+
+static inline void bitmap_zero(unsigned long *dst, int nbits)
+{
+       if (small_const_nbits(nbits))
+               *dst = 0UL;
+       else {
+               int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long);
+               memset(dst, 0, len);
+       }
+}
+
+static inline int bitmap_weight(const unsigned long *src, int nbits)
+{
+       if (small_const_nbits(nbits))
+               return hweight_long(*src & BITMAP_LAST_WORD_MASK(nbits));
+       return __bitmap_weight(src, nbits);
+}
+
+#endif /* _PERF_BITOPS_H */
index 8d63116..bb4ac2e 100644 (file)
@@ -1,13 +1,12 @@
 #ifndef _PERF_LINUX_BITOPS_H_
 #define _PERF_LINUX_BITOPS_H_
 
-#define __KERNEL__
+#include <linux/kernel.h>
+#include <asm/hweight.h>
 
-#define CONFIG_GENERIC_FIND_NEXT_BIT
-#define CONFIG_GENERIC_FIND_FIRST_BIT
-#include "../../../../include/linux/bitops.h"
-
-#undef __KERNEL__
+#define BITS_PER_LONG __WORDSIZE
+#define BITS_PER_BYTE           8
+#define BITS_TO_LONGS(nr)       DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
 
 static inline void set_bit(int nr, unsigned long *addr)
 {
@@ -20,10 +19,9 @@ static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
                (((unsigned long *)addr)[nr / BITS_PER_LONG])) != 0;
 }
 
-unsigned long generic_find_next_zero_le_bit(const unsigned long *addr, unsigned
-               long size, unsigned long offset);
-
-unsigned long generic_find_next_le_bit(const unsigned long *addr, unsigned
-               long size, unsigned long offset);
+static inline unsigned long hweight_long(unsigned long w)
+{
+       return sizeof(w) == 4 ? hweight32(w) : hweight64(w);
+}
 
 #endif
index dfb0713..791f9dd 100644 (file)
@@ -7,4 +7,6 @@
 #define __user
 #define __attribute_const__
 
+#define __used         __attribute__((__unused__))
+
 #endif
index f261165..1eb804f 100644 (file)
@@ -28,6 +28,8 @@
        (type *)((char *)__mptr - offsetof(type, member)); })
 #endif
 
+#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))
+
 #ifndef max
 #define max(x, y) ({                           \
        typeof(x) _max1 = (x);                  \
@@ -85,16 +87,19 @@ simple_strtoul(const char *nptr, char **endptr, int base)
        return strtoul(nptr, endptr, base);
 }
 
+int eprintf(int level,
+           const char *fmt, ...) __attribute__((format(printf, 2, 3)));
+
 #ifndef pr_fmt
 #define pr_fmt(fmt) fmt
 #endif
 
 #define pr_err(fmt, ...) \
-       do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
+       eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_warning(fmt, ...) \
-       do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
+       eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_info(fmt, ...) \
-       do { fprintf(stderr, pr_fmt(fmt), ##__VA_ARGS__); } while (0)
+       eprintf(0, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_debug(fmt, ...) \
        eprintf(1, pr_fmt(fmt), ##__VA_ARGS__)
 #define pr_debugN(n, fmt, ...) \
index e509cd5..e672f2f 100644 (file)
@@ -1,9 +1,11 @@
-#include "event.h"
 #include "symbol.h"
+#include <errno.h>
+#include <limits.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include "debug.h"
+#include <unistd.h>
+#include "map.h"
 
 const char *map_type__name[MAP__NR_TYPES] = {
        [MAP__FUNCTION] = "Functions",
@@ -36,15 +38,16 @@ void map__init(struct map *self, enum map_type type,
        self->map_ip   = map__map_ip;
        self->unmap_ip = map__unmap_ip;
        RB_CLEAR_NODE(&self->rb_node);
+       self->groups   = NULL;
 }
 
-struct map *map__new(struct mmap_event *event, enum map_type type,
-                    char *cwd, int cwdlen)
+struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
+                    u64 pgoff, u32 pid, char *filename,
+                    enum map_type type, char *cwd, int cwdlen)
 {
        struct map *self = malloc(sizeof(*self));
 
        if (self != NULL) {
-               const char *filename = event->filename;
                char newfilename[PATH_MAX];
                struct dso *dso;
                int anon;
@@ -62,16 +65,15 @@ struct map *map__new(struct mmap_event *event, enum map_type type,
                anon = is_anon_memory(filename);
 
                if (anon) {
-                       snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", event->pid);
+                       snprintf(newfilename, sizeof(newfilename), "/tmp/perf-%d.map", pid);
                        filename = newfilename;
                }
 
-               dso = dsos__findnew(filename);
+               dso = __dsos__findnew(dsos__list, filename);
                if (dso == NULL)
                        goto out_delete;
 
-               map__init(self, type, event->start, event->start + event->len,
-                         event->pgoff, dso);
+               map__init(self, type, start, start + len, pgoff, dso);
 
                if (anon) {
 set_identity:
@@ -235,3 +237,392 @@ u64 map__objdump_2ip(struct map *map, u64 addr)
                        map->unmap_ip(map, addr);       /* RIP -> IP */
        return ip;
 }
+
+void map_groups__init(struct map_groups *self)
+{
+       int i;
+       for (i = 0; i < MAP__NR_TYPES; ++i) {
+               self->maps[i] = RB_ROOT;
+               INIT_LIST_HEAD(&self->removed_maps[i]);
+       }
+       self->machine = NULL;
+}
+
+void map_groups__flush(struct map_groups *self)
+{
+       int type;
+
+       for (type = 0; type < MAP__NR_TYPES; type++) {
+               struct rb_root *root = &self->maps[type];
+               struct rb_node *next = rb_first(root);
+
+               while (next) {
+                       struct map *pos = rb_entry(next, struct map, rb_node);
+                       next = rb_next(&pos->rb_node);
+                       rb_erase(&pos->rb_node, root);
+                       /*
+                        * We may have references to this map, for
+                        * instance in some hist_entry instances, so
+                        * just move them to a separate list.
+                        */
+                       list_add_tail(&pos->node, &self->removed_maps[pos->type]);
+               }
+       }
+}
+
+struct symbol *map_groups__find_symbol(struct map_groups *self,
+                                      enum map_type type, u64 addr,
+                                      struct map **mapp,
+                                      symbol_filter_t filter)
+{
+       struct map *map = map_groups__find(self, type, addr);
+
+       if (map != NULL) {
+               if (mapp != NULL)
+                       *mapp = map;
+               return map__find_symbol(map, map->map_ip(map, addr), filter);
+       }
+
+       return NULL;
+}
+
+struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
+                                              enum map_type type,
+                                              const char *name,
+                                              struct map **mapp,
+                                              symbol_filter_t filter)
+{
+       struct rb_node *nd;
+
+       for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
+               struct map *pos = rb_entry(nd, struct map, rb_node);
+               struct symbol *sym = map__find_symbol_by_name(pos, name, filter);
+
+               if (sym == NULL)
+                       continue;
+               if (mapp != NULL)
+                       *mapp = pos;
+               return sym;
+       }
+
+       return NULL;
+}
+
+size_t __map_groups__fprintf_maps(struct map_groups *self,
+                                 enum map_type type, int verbose, FILE *fp)
+{
+       size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
+       struct rb_node *nd;
+
+       for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
+               struct map *pos = rb_entry(nd, struct map, rb_node);
+               printed += fprintf(fp, "Map:");
+               printed += map__fprintf(pos, fp);
+               if (verbose > 2) {
+                       printed += dso__fprintf(pos->dso, type, fp);
+                       printed += fprintf(fp, "--\n");
+               }
+       }
+
+       return printed;
+}
+
+size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp)
+{
+       size_t printed = 0, i;
+       for (i = 0; i < MAP__NR_TYPES; ++i)
+               printed += __map_groups__fprintf_maps(self, i, verbose, fp);
+       return printed;
+}
+
+static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
+                                                enum map_type type,
+                                                int verbose, FILE *fp)
+{
+       struct map *pos;
+       size_t printed = 0;
+
+       list_for_each_entry(pos, &self->removed_maps[type], node) {
+               printed += fprintf(fp, "Map:");
+               printed += map__fprintf(pos, fp);
+               if (verbose > 1) {
+                       printed += dso__fprintf(pos->dso, type, fp);
+                       printed += fprintf(fp, "--\n");
+               }
+       }
+       return printed;
+}
+
+static size_t map_groups__fprintf_removed_maps(struct map_groups *self,
+                                              int verbose, FILE *fp)
+{
+       size_t printed = 0, i;
+       for (i = 0; i < MAP__NR_TYPES; ++i)
+               printed += __map_groups__fprintf_removed_maps(self, i, verbose, fp);
+       return printed;
+}
+
+size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp)
+{
+       size_t printed = map_groups__fprintf_maps(self, verbose, fp);
+       printed += fprintf(fp, "Removed maps:\n");
+       return printed + map_groups__fprintf_removed_maps(self, verbose, fp);
+}
+
+int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
+                                  int verbose, FILE *fp)
+{
+       struct rb_root *root = &self->maps[map->type];
+       struct rb_node *next = rb_first(root);
+
+       while (next) {
+               struct map *pos = rb_entry(next, struct map, rb_node);
+               next = rb_next(&pos->rb_node);
+
+               if (!map__overlap(pos, map))
+                       continue;
+
+               if (verbose >= 2) {
+                       fputs("overlapping maps:\n", fp);
+                       map__fprintf(map, fp);
+                       map__fprintf(pos, fp);
+               }
+
+               rb_erase(&pos->rb_node, root);
+               /*
+                * We may have references to this map, for instance in some
+                * hist_entry instances, so just move them to a separate
+                * list.
+                */
+               list_add_tail(&pos->node, &self->removed_maps[map->type]);
+               /*
+                * Now check if we need to create new maps for areas not
+                * overlapped by the new map:
+                */
+               if (map->start > pos->start) {
+                       struct map *before = map__clone(pos);
+
+                       if (before == NULL)
+                               return -ENOMEM;
+
+                       before->end = map->start - 1;
+                       map_groups__insert(self, before);
+                       if (verbose >= 2)
+                               map__fprintf(before, fp);
+               }
+
+               if (map->end < pos->end) {
+                       struct map *after = map__clone(pos);
+
+                       if (after == NULL)
+                               return -ENOMEM;
+
+                       after->start = map->end + 1;
+                       map_groups__insert(self, after);
+                       if (verbose >= 2)
+                               map__fprintf(after, fp);
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * XXX This should not really _copy_ te maps, but refcount them.
+ */
+int map_groups__clone(struct map_groups *self,
+                     struct map_groups *parent, enum map_type type)
+{
+       struct rb_node *nd;
+       for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
+               struct map *map = rb_entry(nd, struct map, rb_node);
+               struct map *new = map__clone(map);
+               if (new == NULL)
+                       return -ENOMEM;
+               map_groups__insert(self, new);
+       }
+       return 0;
+}
+
+static u64 map__reloc_map_ip(struct map *map, u64 ip)
+{
+       return ip + (s64)map->pgoff;
+}
+
+static u64 map__reloc_unmap_ip(struct map *map, u64 ip)
+{
+       return ip - (s64)map->pgoff;
+}
+
+void map__reloc_vmlinux(struct map *self)
+{
+       struct kmap *kmap = map__kmap(self);
+       s64 reloc;
+
+       if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr)
+               return;
+
+       reloc = (kmap->ref_reloc_sym->unrelocated_addr -
+                kmap->ref_reloc_sym->addr);
+
+       if (!reloc)
+               return;
+
+       self->map_ip   = map__reloc_map_ip;
+       self->unmap_ip = map__reloc_unmap_ip;
+       self->pgoff    = reloc;
+}
+
+void maps__insert(struct rb_root *maps, struct map *map)
+{
+       struct rb_node **p = &maps->rb_node;
+       struct rb_node *parent = NULL;
+       const u64 ip = map->start;
+       struct map *m;
+
+       while (*p != NULL) {
+               parent = *p;
+               m = rb_entry(parent, struct map, rb_node);
+               if (ip < m->start)
+                       p = &(*p)->rb_left;
+               else
+                       p = &(*p)->rb_right;
+       }
+
+       rb_link_node(&map->rb_node, parent, p);
+       rb_insert_color(&map->rb_node, maps);
+}
+
+struct map *maps__find(struct rb_root *maps, u64 ip)
+{
+       struct rb_node **p = &maps->rb_node;
+       struct rb_node *parent = NULL;
+       struct map *m;
+
+       while (*p != NULL) {
+               parent = *p;
+               m = rb_entry(parent, struct map, rb_node);
+               if (ip < m->start)
+                       p = &(*p)->rb_left;
+               else if (ip > m->end)
+                       p = &(*p)->rb_right;
+               else
+                       return m;
+       }
+
+       return NULL;
+}
+
+int machine__init(struct machine *self, const char *root_dir, pid_t pid)
+{
+       map_groups__init(&self->kmaps);
+       RB_CLEAR_NODE(&self->rb_node);
+       INIT_LIST_HEAD(&self->user_dsos);
+       INIT_LIST_HEAD(&self->kernel_dsos);
+
+       self->kmaps.machine = self;
+       self->pid           = pid;
+       self->root_dir      = strdup(root_dir);
+       return self->root_dir == NULL ? -ENOMEM : 0;
+}
+
+struct machine *machines__add(struct rb_root *self, pid_t pid,
+                             const char *root_dir)
+{
+       struct rb_node **p = &self->rb_node;
+       struct rb_node *parent = NULL;
+       struct machine *pos, *machine = malloc(sizeof(*machine));
+
+       if (!machine)
+               return NULL;
+
+       if (machine__init(machine, root_dir, pid) != 0) {
+               free(machine);
+               return NULL;
+       }
+
+       while (*p != NULL) {
+               parent = *p;
+               pos = rb_entry(parent, struct machine, rb_node);
+               if (pid < pos->pid)
+                       p = &(*p)->rb_left;
+               else
+                       p = &(*p)->rb_right;
+       }
+
+       rb_link_node(&machine->rb_node, parent, p);
+       rb_insert_color(&machine->rb_node, self);
+
+       return machine;
+}
+
+struct machine *machines__find(struct rb_root *self, pid_t pid)
+{
+       struct rb_node **p = &self->rb_node;
+       struct rb_node *parent = NULL;
+       struct machine *machine;
+       struct machine *default_machine = NULL;
+
+       while (*p != NULL) {
+               parent = *p;
+               machine = rb_entry(parent, struct machine, rb_node);
+               if (pid < machine->pid)
+                       p = &(*p)->rb_left;
+               else if (pid > machine->pid)
+                       p = &(*p)->rb_right;
+               else
+                       return machine;
+               if (!machine->pid)
+                       default_machine = machine;
+       }
+
+       return default_machine;
+}
+
+struct machine *machines__findnew(struct rb_root *self, pid_t pid)
+{
+       char path[PATH_MAX];
+       const char *root_dir;
+       struct machine *machine = machines__find(self, pid);
+
+       if (!machine || machine->pid != pid) {
+               if (pid == HOST_KERNEL_ID || pid == DEFAULT_GUEST_KERNEL_ID)
+                       root_dir = "";
+               else {
+                       if (!symbol_conf.guestmount)
+                               goto out;
+                       sprintf(path, "%s/%d", symbol_conf.guestmount, pid);
+                       if (access(path, R_OK)) {
+                               pr_err("Can't access file %s\n", path);
+                               goto out;
+                       }
+                       root_dir = path;
+               }
+               machine = machines__add(self, pid, root_dir);
+       }
+
+out:
+       return machine;
+}
+
+void machines__process(struct rb_root *self, machine__process_t process, void *data)
+{
+       struct rb_node *nd;
+
+       for (nd = rb_first(self); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               process(pos, data);
+       }
+}
+
+char *machine__mmap_name(struct machine *self, char *bf, size_t size)
+{
+       if (machine__is_host(self))
+               snprintf(bf, size, "[%s]", "kernel.kallsyms");
+       else if (machine__is_default_guest(self))
+               snprintf(bf, size, "[%s]", "guest.kernel.kallsyms");
+       else
+               snprintf(bf, size, "[%s.%d]", "guest.kernel.kallsyms", self->pid);
+
+       return bf;
+}
index b756368..f391345 100644 (file)
@@ -4,7 +4,9 @@
 #include <linux/compiler.h>
 #include <linux/list.h>
 #include <linux/rbtree.h>
-#include <linux/types.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include "types.h"
 
 enum map_type {
        MAP__FUNCTION = 0,
@@ -18,6 +20,7 @@ extern const char *map_type__name[MAP__NR_TYPES];
 struct dso;
 struct ref_reloc_sym;
 struct map_groups;
+struct machine;
 
 struct map {
        union {
@@ -27,6 +30,7 @@ struct map {
        u64                     start;
        u64                     end;
        enum map_type           type;
+       u32                     priv;
        u64                     pgoff;
 
        /* ip -> dso rip */
@@ -35,6 +39,7 @@ struct map {
        u64                     (*unmap_ip)(struct map *, u64);
 
        struct dso              *dso;
+       struct map_groups       *groups;
 };
 
 struct kmap {
@@ -42,6 +47,32 @@ struct kmap {
        struct map_groups       *kmaps;
 };
 
+struct map_groups {
+       struct rb_root   maps[MAP__NR_TYPES];
+       struct list_head removed_maps[MAP__NR_TYPES];
+       struct machine   *machine;
+};
+
+/* Native host kernel uses -1 as pid index in machine */
+#define        HOST_KERNEL_ID                  (-1)
+#define        DEFAULT_GUEST_KERNEL_ID         (0)
+
+struct machine {
+       struct rb_node    rb_node;
+       pid_t             pid;
+       char              *root_dir;
+       struct list_head  user_dsos;
+       struct list_head  kernel_dsos;
+       struct map_groups kmaps;
+       struct map        *vmlinux_maps[MAP__NR_TYPES];
+};
+
+static inline
+struct map *machine__kernel_map(struct machine *self, enum map_type type)
+{
+       return self->vmlinux_maps[type];
+}
+
 static inline struct kmap *map__kmap(struct map *self)
 {
        return (struct kmap *)(self + 1);
@@ -68,14 +99,14 @@ u64 map__rip_2objdump(struct map *map, u64 rip);
 u64 map__objdump_2ip(struct map *map, u64 addr);
 
 struct symbol;
-struct mmap_event;
 
 typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym);
 
 void map__init(struct map *self, enum map_type type,
               u64 start, u64 end, u64 pgoff, struct dso *dso);
-struct map *map__new(struct mmap_event *event, enum map_type,
-                    char *cwd, int cwdlen);
+struct map *map__new(struct list_head *dsos__list, u64 start, u64 len,
+                    u64 pgoff, u32 pid, char *filename,
+                    enum map_type type, char *cwd, int cwdlen);
 void map__delete(struct map *self);
 struct map *map__clone(struct map *self);
 int map__overlap(struct map *l, struct map *r);
@@ -91,4 +122,96 @@ void map__fixup_end(struct map *self);
 
 void map__reloc_vmlinux(struct map *self);
 
+size_t __map_groups__fprintf_maps(struct map_groups *self,
+                                 enum map_type type, int verbose, FILE *fp);
+void maps__insert(struct rb_root *maps, struct map *map);
+struct map *maps__find(struct rb_root *maps, u64 addr);
+void map_groups__init(struct map_groups *self);
+int map_groups__clone(struct map_groups *self,
+                     struct map_groups *parent, enum map_type type);
+size_t map_groups__fprintf(struct map_groups *self, int verbose, FILE *fp);
+size_t map_groups__fprintf_maps(struct map_groups *self, int verbose, FILE *fp);
+
+typedef void (*machine__process_t)(struct machine *self, void *data);
+
+void machines__process(struct rb_root *self, machine__process_t process, void *data);
+struct machine *machines__add(struct rb_root *self, pid_t pid,
+                             const char *root_dir);
+struct machine *machines__find_host(struct rb_root *self);
+struct machine *machines__find(struct rb_root *self, pid_t pid);
+struct machine *machines__findnew(struct rb_root *self, pid_t pid);
+char *machine__mmap_name(struct machine *self, char *bf, size_t size);
+int machine__init(struct machine *self, const char *root_dir, pid_t pid);
+
+/*
+ * Default guest kernel is defined by parameter --guestkallsyms
+ * and --guestmodules
+ */
+static inline bool machine__is_default_guest(struct machine *self)
+{
+       return self ? self->pid == DEFAULT_GUEST_KERNEL_ID : false;
+}
+
+static inline bool machine__is_host(struct machine *self)
+{
+       return self ? self->pid == HOST_KERNEL_ID : false;
+}
+
+static inline void map_groups__insert(struct map_groups *self, struct map *map)
+{
+       maps__insert(&self->maps[map->type], map);
+       map->groups = self;
+}
+
+static inline struct map *map_groups__find(struct map_groups *self,
+                                          enum map_type type, u64 addr)
+{
+       return maps__find(&self->maps[type], addr);
+}
+
+struct symbol *map_groups__find_symbol(struct map_groups *self,
+                                      enum map_type type, u64 addr,
+                                      struct map **mapp,
+                                      symbol_filter_t filter);
+
+struct symbol *map_groups__find_symbol_by_name(struct map_groups *self,
+                                              enum map_type type,
+                                              const char *name,
+                                              struct map **mapp,
+                                              symbol_filter_t filter);
+
+static inline
+struct symbol *machine__find_kernel_symbol(struct machine *self,
+                                          enum map_type type, u64 addr,
+                                          struct map **mapp,
+                                          symbol_filter_t filter)
+{
+       return map_groups__find_symbol(&self->kmaps, type, addr, mapp, filter);
+}
+
+static inline
+struct symbol *machine__find_kernel_function(struct machine *self, u64 addr,
+                                            struct map **mapp,
+                                            symbol_filter_t filter)
+{
+       return machine__find_kernel_symbol(self, MAP__FUNCTION, addr, mapp, filter);
+}
+
+static inline
+struct symbol *map_groups__find_function_by_name(struct map_groups *self,
+                                                const char *name, struct map **mapp,
+                                                symbol_filter_t filter)
+{
+       return map_groups__find_symbol_by_name(self, MAP__FUNCTION, name, mapp, filter);
+}
+
+int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
+                                  int verbose, FILE *fp);
+
+struct map *map_groups__find_by_name(struct map_groups *self,
+                                    enum map_type type, const char *name);
+struct map *machine__new_module(struct machine *self, u64 start, const char *filename);
+
+void map_groups__flush(struct map_groups *self);
+
 #endif /* __PERF_MAP_H */
diff --git a/tools/perf/util/newt.c b/tools/perf/util/newt.c
new file mode 100644 (file)
index 0000000..ccb7c5b
--- /dev/null
@@ -0,0 +1,1084 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#undef _GNU_SOURCE
+
+#include <slang.h>
+#include <stdlib.h>
+#include <newt.h>
+#include <sys/ttydefaults.h>
+
+#include "cache.h"
+#include "hist.h"
+#include "pstack.h"
+#include "session.h"
+#include "sort.h"
+#include "symbol.h"
+
+#if SLANG_VERSION < 20104
+#define slsmg_printf(msg, args...) SLsmg_printf((char *)msg, ##args)
+#define slsmg_write_nstring(msg, len) SLsmg_write_nstring((char *)msg, len)
+#define sltt_set_color(obj, name, fg, bg) SLtt_set_color(obj,(char *)name,\
+                                                        (char *)fg, (char *)bg)
+#else
+#define slsmg_printf SLsmg_printf
+#define slsmg_write_nstring SLsmg_write_nstring
+#define sltt_set_color SLtt_set_color
+#endif
+
+struct ui_progress {
+       newtComponent form, scale;
+};
+
+struct ui_progress *ui_progress__new(const char *title, u64 total)
+{
+       struct ui_progress *self = malloc(sizeof(*self));
+
+       if (self != NULL) {
+               int cols;
+               newtGetScreenSize(&cols, NULL);
+               cols -= 4;
+               newtCenteredWindow(cols, 1, title);
+               self->form  = newtForm(NULL, NULL, 0);
+               if (self->form == NULL)
+                       goto out_free_self;
+               self->scale = newtScale(0, 0, cols, total);
+               if (self->scale == NULL)
+                       goto out_free_form;
+               newtFormAddComponent(self->form, self->scale);
+               newtRefresh();
+       }
+
+       return self;
+
+out_free_form:
+       newtFormDestroy(self->form);
+out_free_self:
+       free(self);
+       return NULL;
+}
+
+void ui_progress__update(struct ui_progress *self, u64 curr)
+{
+       newtScaleSet(self->scale, curr);
+       newtRefresh();
+}
+
+void ui_progress__delete(struct ui_progress *self)
+{
+       newtFormDestroy(self->form);
+       newtPopWindow();
+       free(self);
+}
+
+static void ui_helpline__pop(void)
+{
+       newtPopHelpLine();
+}
+
+static void ui_helpline__push(const char *msg)
+{
+       newtPushHelpLine(msg);
+}
+
+static void ui_helpline__vpush(const char *fmt, va_list ap)
+{
+       char *s;
+
+       if (vasprintf(&s, fmt, ap) < 0)
+               vfprintf(stderr, fmt, ap);
+       else {
+               ui_helpline__push(s);
+               free(s);
+       }
+}
+
+static void ui_helpline__fpush(const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       ui_helpline__vpush(fmt, ap);
+       va_end(ap);
+}
+
+static void ui_helpline__puts(const char *msg)
+{
+       ui_helpline__pop();
+       ui_helpline__push(msg);
+}
+
+static char browser__last_msg[1024];
+
+int browser__show_help(const char *format, va_list ap)
+{
+       int ret;
+       static int backlog;
+
+        ret = vsnprintf(browser__last_msg + backlog,
+                       sizeof(browser__last_msg) - backlog, format, ap);
+       backlog += ret;
+
+       if (browser__last_msg[backlog - 1] == '\n') {
+               ui_helpline__puts(browser__last_msg);
+               newtRefresh();
+               backlog = 0;
+       }
+
+       return ret;
+}
+
+static void newt_form__set_exit_keys(newtComponent self)
+{
+       newtFormAddHotKey(self, NEWT_KEY_LEFT);
+       newtFormAddHotKey(self, NEWT_KEY_ESCAPE);
+       newtFormAddHotKey(self, 'Q');
+       newtFormAddHotKey(self, 'q');
+       newtFormAddHotKey(self, CTRL('c'));
+}
+
+static newtComponent newt_form__new(void)
+{
+       newtComponent self = newtForm(NULL, NULL, 0);
+       if (self)
+               newt_form__set_exit_keys(self);
+       return self;
+}
+
+static int popup_menu(int argc, char * const argv[])
+{
+       struct newtExitStruct es;
+       int i, rc = -1, max_len = 5;
+       newtComponent listbox, form = newt_form__new();
+
+       if (form == NULL)
+               return -1;
+
+       listbox = newtListbox(0, 0, argc, NEWT_FLAG_RETURNEXIT);
+       if (listbox == NULL)
+               goto out_destroy_form;
+
+       newtFormAddComponent(form, listbox);
+
+       for (i = 0; i < argc; ++i) {
+               int len = strlen(argv[i]);
+               if (len > max_len)
+                       max_len = len;
+               if (newtListboxAddEntry(listbox, argv[i], (void *)(long)i))
+                       goto out_destroy_form;
+       }
+
+       newtCenteredWindow(max_len, argc, NULL);
+       newtFormRun(form, &es);
+       rc = newtListboxGetCurrent(listbox) - NULL;
+       if (es.reason == NEWT_EXIT_HOTKEY)
+               rc = -1;
+       newtPopWindow();
+out_destroy_form:
+       newtFormDestroy(form);
+       return rc;
+}
+
+static int ui__help_window(const char *text)
+{
+       struct newtExitStruct es;
+       newtComponent tb, form = newt_form__new();
+       int rc = -1;
+       int max_len = 0, nr_lines = 0;
+       const char *t;
+
+       if (form == NULL)
+               return -1;
+
+       t = text;
+       while (1) {
+               const char *sep = strchr(t, '\n');
+               int len;
+
+               if (sep == NULL)
+                       sep = strchr(t, '\0');
+               len = sep - t;
+               if (max_len < len)
+                       max_len = len;
+               ++nr_lines;
+               if (*sep == '\0')
+                       break;
+               t = sep + 1;
+       }
+
+       tb = newtTextbox(0, 0, max_len, nr_lines, 0);
+       if (tb == NULL)
+               goto out_destroy_form;
+
+       newtTextboxSetText(tb, text);
+       newtFormAddComponent(form, tb);
+       newtCenteredWindow(max_len, nr_lines, NULL);
+       newtFormRun(form, &es);
+       newtPopWindow();
+       rc = 0;
+out_destroy_form:
+       newtFormDestroy(form);
+       return rc;
+}
+
+static bool dialog_yesno(const char *msg)
+{
+       /* newtWinChoice should really be accepting const char pointers... */
+       char yes[] = "Yes", no[] = "No";
+       return newtWinChoice(NULL, yes, no, (char *)msg) == 1;
+}
+
+#define HE_COLORSET_TOP                50
+#define HE_COLORSET_MEDIUM     51
+#define HE_COLORSET_NORMAL     52
+#define HE_COLORSET_SELECTED   53
+#define HE_COLORSET_CODE       54
+
+static int ui_browser__percent_color(double percent, bool current)
+{
+       if (current)
+               return HE_COLORSET_SELECTED;
+       if (percent >= MIN_RED)
+               return HE_COLORSET_TOP;
+       if (percent >= MIN_GREEN)
+               return HE_COLORSET_MEDIUM;
+       return HE_COLORSET_NORMAL;
+}
+
+struct ui_browser {
+       newtComponent   form, sb;
+       u64             index, first_visible_entry_idx;
+       void            *first_visible_entry, *entries;
+       u16             top, left, width, height;
+       void            *priv;
+       u32             nr_entries;
+};
+
+static void ui_browser__refresh_dimensions(struct ui_browser *self)
+{
+       int cols, rows;
+       newtGetScreenSize(&cols, &rows);
+
+       if (self->width > cols - 4)
+               self->width = cols - 4;
+       self->height = rows - 5;
+       if (self->height > self->nr_entries)
+               self->height = self->nr_entries;
+       self->top  = (rows - self->height) / 2;
+       self->left = (cols - self->width) / 2;
+}
+
+static void ui_browser__reset_index(struct ui_browser *self)
+{
+        self->index = self->first_visible_entry_idx = 0;
+        self->first_visible_entry = NULL;
+}
+
+static int objdump_line__show(struct objdump_line *self, struct list_head *head,
+                             int width, struct hist_entry *he, int len,
+                             bool current_entry)
+{
+       if (self->offset != -1) {
+               struct symbol *sym = he->ms.sym;
+               unsigned int hits = 0;
+               double percent = 0.0;
+               int color;
+               struct sym_priv *priv = symbol__priv(sym);
+               struct sym_ext *sym_ext = priv->ext;
+               struct sym_hist *h = priv->hist;
+               s64 offset = self->offset;
+               struct objdump_line *next = objdump__get_next_ip_line(head, self);
+
+               while (offset < (s64)len &&
+                      (next == NULL || offset < next->offset)) {
+                       if (sym_ext) {
+                               percent += sym_ext[offset].percent;
+                       } else
+                               hits += h->ip[offset];
+
+                       ++offset;
+               }
+
+               if (sym_ext == NULL && h->sum)
+                       percent = 100.0 * hits / h->sum;
+
+               color = ui_browser__percent_color(percent, current_entry);
+               SLsmg_set_color(color);
+               slsmg_printf(" %7.2f ", percent);
+               if (!current_entry)
+                       SLsmg_set_color(HE_COLORSET_CODE);
+       } else {
+               int color = ui_browser__percent_color(0, current_entry);
+               SLsmg_set_color(color);
+               slsmg_write_nstring(" ", 9);
+       }
+
+       SLsmg_write_char(':');
+       slsmg_write_nstring(" ", 8);
+       if (!*self->line)
+               slsmg_write_nstring(" ", width - 18);
+       else
+               slsmg_write_nstring(self->line, width - 18);
+
+       return 0;
+}
+
+static int ui_browser__refresh_entries(struct ui_browser *self)
+{
+       struct objdump_line *pos;
+       struct list_head *head = self->entries;
+       struct hist_entry *he = self->priv;
+       int row = 0;
+       int len = he->ms.sym->end - he->ms.sym->start;
+
+       if (self->first_visible_entry == NULL || self->first_visible_entry == self->entries)
+                self->first_visible_entry = head->next;
+
+       pos = list_entry(self->first_visible_entry, struct objdump_line, node);
+
+       list_for_each_entry_from(pos, head, node) {
+               bool current_entry = (self->first_visible_entry_idx + row) == self->index;
+               SLsmg_gotorc(self->top + row, self->left);
+               objdump_line__show(pos, head, self->width,
+                                  he, len, current_entry);
+               if (++row == self->height)
+                       break;
+       }
+
+       SLsmg_set_color(HE_COLORSET_NORMAL);
+       SLsmg_fill_region(self->top + row, self->left,
+                         self->height - row, self->width, ' ');
+
+       return 0;
+}
+
+static int ui_browser__run(struct ui_browser *self, const char *title,
+                          struct newtExitStruct *es)
+{
+       if (self->form) {
+               newtFormDestroy(self->form);
+               newtPopWindow();
+       }
+
+       ui_browser__refresh_dimensions(self);
+       newtCenteredWindow(self->width + 2, self->height, title);
+       self->form = newt_form__new();
+       if (self->form == NULL)
+               return -1;
+
+       self->sb = newtVerticalScrollbar(self->width + 1, 0, self->height,
+                                        HE_COLORSET_NORMAL,
+                                        HE_COLORSET_SELECTED);
+       if (self->sb == NULL)
+               return -1;
+
+       newtFormAddHotKey(self->form, NEWT_KEY_UP);
+       newtFormAddHotKey(self->form, NEWT_KEY_DOWN);
+       newtFormAddHotKey(self->form, NEWT_KEY_PGUP);
+       newtFormAddHotKey(self->form, NEWT_KEY_PGDN);
+       newtFormAddHotKey(self->form, NEWT_KEY_HOME);
+       newtFormAddHotKey(self->form, NEWT_KEY_END);
+
+       if (ui_browser__refresh_entries(self) < 0)
+               return -1;
+       newtFormAddComponent(self->form, self->sb);
+
+       while (1) {
+               unsigned int offset;
+
+               newtFormRun(self->form, es);
+
+               if (es->reason != NEWT_EXIT_HOTKEY)
+                       break;
+               switch (es->u.key) {
+               case NEWT_KEY_DOWN:
+                       if (self->index == self->nr_entries - 1)
+                               break;
+                       ++self->index;
+                       if (self->index == self->first_visible_entry_idx + self->height) {
+                               struct list_head *pos = self->first_visible_entry;
+                               ++self->first_visible_entry_idx;
+                               self->first_visible_entry = pos->next;
+                       }
+                       break;
+               case NEWT_KEY_UP:
+                       if (self->index == 0)
+                               break;
+                       --self->index;
+                       if (self->index < self->first_visible_entry_idx) {
+                               struct list_head *pos = self->first_visible_entry;
+                               --self->first_visible_entry_idx;
+                               self->first_visible_entry = pos->prev;
+                       }
+                       break;
+               case NEWT_KEY_PGDN:
+                       if (self->first_visible_entry_idx + self->height > self->nr_entries - 1)
+                               break;
+
+                       offset = self->height;
+                       if (self->index + offset > self->nr_entries - 1)
+                               offset = self->nr_entries - 1 - self->index;
+                       self->index += offset;
+                       self->first_visible_entry_idx += offset;
+
+                       while (offset--) {
+                               struct list_head *pos = self->first_visible_entry;
+                               self->first_visible_entry = pos->next;
+                       }
+
+                       break;
+               case NEWT_KEY_PGUP:
+                       if (self->first_visible_entry_idx == 0)
+                               break;
+
+                       if (self->first_visible_entry_idx < self->height)
+                               offset = self->first_visible_entry_idx;
+                       else
+                               offset = self->height;
+
+                       self->index -= offset;
+                       self->first_visible_entry_idx -= offset;
+
+                       while (offset--) {
+                               struct list_head *pos = self->first_visible_entry;
+                               self->first_visible_entry = pos->prev;
+                       }
+                       break;
+               case NEWT_KEY_HOME:
+                       ui_browser__reset_index(self);
+                       break;
+               case NEWT_KEY_END: {
+                       struct list_head *head = self->entries;
+                       offset = self->height - 1;
+
+                       if (offset > self->nr_entries)
+                               offset = self->nr_entries;
+
+                       self->index = self->first_visible_entry_idx = self->nr_entries - 1 - offset;
+                       self->first_visible_entry = head->prev;
+                       while (offset-- != 0) {
+                               struct list_head *pos = self->first_visible_entry;
+                               self->first_visible_entry = pos->prev;
+                       }
+               }
+                       break;
+               case NEWT_KEY_ESCAPE:
+               case NEWT_KEY_LEFT:
+               case CTRL('c'):
+               case 'Q':
+               case 'q':
+                       return 0;
+               default:
+                       continue;
+               }
+               if (ui_browser__refresh_entries(self) < 0)
+                       return -1;
+       }
+       return 0;
+}
+
+/*
+ * When debugging newt problems it was useful to be able to "unroll"
+ * the calls to newtCheckBoxTreeAdd{Array,Item}, so that we can generate
+ * a source file with the sequence of calls to these methods, to then
+ * tweak the arrays to get the intended results, so I'm keeping this code
+ * here, may be useful again in the future.
+ */
+#undef NEWT_DEBUG
+
+static void newt_checkbox_tree__add(newtComponent tree, const char *str,
+                                   void *priv, int *indexes)
+{
+#ifdef NEWT_DEBUG
+       /* Print the newtCheckboxTreeAddArray to tinker with its index arrays */
+       int i = 0, len = 40 - strlen(str);
+
+       fprintf(stderr,
+               "\tnewtCheckboxTreeAddItem(tree, %*.*s\"%s\", (void *)%p, 0, ",
+               len, len, " ", str, priv);
+       while (indexes[i] != NEWT_ARG_LAST) {
+               if (indexes[i] != NEWT_ARG_APPEND)
+                       fprintf(stderr, " %d,", indexes[i]);
+               else
+                       fprintf(stderr, " %s,", "NEWT_ARG_APPEND");
+               ++i;
+       }
+       fprintf(stderr, " %s", " NEWT_ARG_LAST);\n");
+       fflush(stderr);
+#endif
+       newtCheckboxTreeAddArray(tree, str, priv, 0, indexes);
+}
+
+static char *callchain_list__sym_name(struct callchain_list *self,
+                                     char *bf, size_t bfsize)
+{
+       if (self->ms.sym)
+               return self->ms.sym->name;
+
+       snprintf(bf, bfsize, "%#Lx", self->ip);
+       return bf;
+}
+
+static void __callchain__append_graph_browser(struct callchain_node *self,
+                                             newtComponent tree, u64 total,
+                                             int *indexes, int depth)
+{
+       struct rb_node *node;
+       u64 new_total, remaining;
+       int idx = 0;
+
+       if (callchain_param.mode == CHAIN_GRAPH_REL)
+               new_total = self->children_hit;
+       else
+               new_total = total;
+
+       remaining = new_total;
+       node = rb_first(&self->rb_root);
+       while (node) {
+               struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
+               struct rb_node *next = rb_next(node);
+               u64 cumul = cumul_hits(child);
+               struct callchain_list *chain;
+               int first = true, printed = 0;
+               int chain_idx = -1;
+               remaining -= cumul;
+
+               indexes[depth] = NEWT_ARG_APPEND;
+               indexes[depth + 1] = NEWT_ARG_LAST;
+
+               list_for_each_entry(chain, &child->val, list) {
+                       char ipstr[BITS_PER_LONG / 4 + 1],
+                            *alloc_str = NULL;
+                       const char *str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
+
+                       if (first) {
+                               double percent = cumul * 100.0 / new_total;
+
+                               first = false;
+                               if (asprintf(&alloc_str, "%2.2f%% %s", percent, str) < 0)
+                                       str = "Not enough memory!";
+                               else
+                                       str = alloc_str;
+                       } else {
+                               indexes[depth] = idx;
+                               indexes[depth + 1] = NEWT_ARG_APPEND;
+                               indexes[depth + 2] = NEWT_ARG_LAST;
+                               ++chain_idx;
+                       }
+                       newt_checkbox_tree__add(tree, str, &chain->ms, indexes);
+                       free(alloc_str);
+                       ++printed;
+               }
+
+               indexes[depth] = idx;
+               if (chain_idx != -1)
+                       indexes[depth + 1] = chain_idx;
+               if (printed != 0)
+                       ++idx;
+               __callchain__append_graph_browser(child, tree, new_total, indexes,
+                                                 depth + (chain_idx != -1 ? 2 : 1));
+               node = next;
+       }
+}
+
+static void callchain__append_graph_browser(struct callchain_node *self,
+                                           newtComponent tree, u64 total,
+                                           int *indexes, int parent_idx)
+{
+       struct callchain_list *chain;
+       int i = 0;
+
+       indexes[1] = NEWT_ARG_APPEND;
+       indexes[2] = NEWT_ARG_LAST;
+
+       list_for_each_entry(chain, &self->val, list) {
+               char ipstr[BITS_PER_LONG / 4 + 1], *str;
+
+               if (chain->ip >= PERF_CONTEXT_MAX)
+                       continue;
+
+               if (!i++ && sort__first_dimension == SORT_SYM)
+                       continue;
+
+               str = callchain_list__sym_name(chain, ipstr, sizeof(ipstr));
+               newt_checkbox_tree__add(tree, str, &chain->ms, indexes);
+       }
+
+       indexes[1] = parent_idx;
+       indexes[2] = NEWT_ARG_APPEND;
+       indexes[3] = NEWT_ARG_LAST;
+       __callchain__append_graph_browser(self, tree, total, indexes, 2);
+}
+
+static void hist_entry__append_callchain_browser(struct hist_entry *self,
+                                                newtComponent tree, u64 total, int parent_idx)
+{
+       struct rb_node *rb_node;
+       int indexes[1024] = { [0] = parent_idx, };
+       int idx = 0;
+       struct callchain_node *chain;
+
+       rb_node = rb_first(&self->sorted_chain);
+       while (rb_node) {
+               chain = rb_entry(rb_node, struct callchain_node, rb_node);
+               switch (callchain_param.mode) {
+               case CHAIN_FLAT:
+                       break;
+               case CHAIN_GRAPH_ABS: /* falldown */
+               case CHAIN_GRAPH_REL:
+                       callchain__append_graph_browser(chain, tree, total, indexes, idx++);
+                       break;
+               case CHAIN_NONE:
+               default:
+                       break;
+               }
+               rb_node = rb_next(rb_node);
+       }
+}
+
+static size_t hist_entry__append_browser(struct hist_entry *self,
+                                        newtComponent tree, u64 total)
+{
+       char s[256];
+       size_t ret;
+
+       if (symbol_conf.exclude_other && !self->parent)
+               return 0;
+
+       ret = hist_entry__snprintf(self, s, sizeof(s), NULL,
+                                  false, 0, false, total);
+       if (symbol_conf.use_callchain) {
+               int indexes[2];
+
+               indexes[0] = NEWT_ARG_APPEND;
+               indexes[1] = NEWT_ARG_LAST;
+               newt_checkbox_tree__add(tree, s, &self->ms, indexes);
+       } else
+               newtListboxAppendEntry(tree, s, &self->ms);
+
+       return ret;
+}
+
+static void hist_entry__annotate_browser(struct hist_entry *self)
+{
+       struct ui_browser browser;
+       struct newtExitStruct es;
+       struct objdump_line *pos, *n;
+       LIST_HEAD(head);
+
+       if (self->ms.sym == NULL)
+               return;
+
+       if (hist_entry__annotate(self, &head) < 0)
+               return;
+
+       ui_helpline__push("Press <- or ESC to exit");
+
+       memset(&browser, 0, sizeof(browser));
+       browser.entries = &head;
+       browser.priv = self;
+       list_for_each_entry(pos, &head, node) {
+               size_t line_len = strlen(pos->line);
+               if (browser.width < line_len)
+                       browser.width = line_len;
+               ++browser.nr_entries;
+       }
+
+       browser.width += 18; /* Percentage */
+       ui_browser__run(&browser, self->ms.sym->name, &es);
+       newtFormDestroy(browser.form);
+       newtPopWindow();
+       list_for_each_entry_safe(pos, n, &head, node) {
+               list_del(&pos->node);
+               objdump_line__free(pos);
+       }
+       ui_helpline__pop();
+}
+
+static const void *newt__symbol_tree_get_current(newtComponent self)
+{
+       if (symbol_conf.use_callchain)
+               return newtCheckboxTreeGetCurrent(self);
+       return newtListboxGetCurrent(self);
+}
+
+static void hist_browser__selection(newtComponent self, void *data)
+{
+       const struct map_symbol **symbol_ptr = data;
+       *symbol_ptr = newt__symbol_tree_get_current(self);
+}
+
+struct hist_browser {
+       newtComponent           form, tree;
+       const struct map_symbol *selection;
+};
+
+static struct hist_browser *hist_browser__new(void)
+{
+       struct hist_browser *self = malloc(sizeof(*self));
+
+       if (self != NULL)
+               self->form = NULL;
+
+       return self;
+}
+
+static void hist_browser__delete(struct hist_browser *self)
+{
+       newtFormDestroy(self->form);
+       newtPopWindow();
+       free(self);
+}
+
+static int hist_browser__populate(struct hist_browser *self, struct hists *hists,
+                                 const char *title)
+{
+       int max_len = 0, idx, cols, rows;
+       struct ui_progress *progress;
+       struct rb_node *nd;
+       u64 curr_hist = 0;
+       char seq[] = ".", unit;
+       char str[256];
+       unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE];
+
+       if (self->form) {
+               newtFormDestroy(self->form);
+               newtPopWindow();
+       }
+
+       nr_events = convert_unit(nr_events, &unit);
+       snprintf(str, sizeof(str), "Events: %lu%c                            ",
+                nr_events, unit);
+       newtDrawRootText(0, 0, str);
+
+       newtGetScreenSize(NULL, &rows);
+
+       if (symbol_conf.use_callchain)
+               self->tree = newtCheckboxTreeMulti(0, 0, rows - 5, seq,
+                                                  NEWT_FLAG_SCROLL);
+       else
+               self->tree = newtListbox(0, 0, rows - 5,
+                                       (NEWT_FLAG_SCROLL |
+                                        NEWT_FLAG_RETURNEXIT));
+
+       newtComponentAddCallback(self->tree, hist_browser__selection,
+                                &self->selection);
+
+       progress = ui_progress__new("Adding entries to the browser...",
+                                   hists->nr_entries);
+       if (progress == NULL)
+               return -1;
+
+       idx = 0;
+       for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
+               struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+               int len;
+
+               if (h->filtered)
+                       continue;
+
+               len = hist_entry__append_browser(h, self->tree, hists->stats.total_period);
+               if (len > max_len)
+                       max_len = len;
+               if (symbol_conf.use_callchain)
+                       hist_entry__append_callchain_browser(h, self->tree,
+                                                            hists->stats.total_period, idx++);
+               ++curr_hist;
+               if (curr_hist % 5)
+                       ui_progress__update(progress, curr_hist);
+       }
+
+       ui_progress__delete(progress);
+
+       newtGetScreenSize(&cols, &rows);
+
+       if (max_len > cols)
+               max_len = cols - 3;
+
+       if (!symbol_conf.use_callchain)
+               newtListboxSetWidth(self->tree, max_len);
+
+       newtCenteredWindow(max_len + (symbol_conf.use_callchain ? 5 : 0),
+                          rows - 5, title);
+       self->form = newt_form__new();
+       if (self->form == NULL)
+               return -1;
+
+       newtFormAddHotKey(self->form, 'A');
+       newtFormAddHotKey(self->form, 'a');
+       newtFormAddHotKey(self->form, 'D');
+       newtFormAddHotKey(self->form, 'd');
+       newtFormAddHotKey(self->form, 'T');
+       newtFormAddHotKey(self->form, 't');
+       newtFormAddHotKey(self->form, '?');
+       newtFormAddHotKey(self->form, 'H');
+       newtFormAddHotKey(self->form, 'h');
+       newtFormAddHotKey(self->form, NEWT_KEY_F1);
+       newtFormAddHotKey(self->form, NEWT_KEY_RIGHT);
+       newtFormAddComponents(self->form, self->tree, NULL);
+       self->selection = newt__symbol_tree_get_current(self->tree);
+
+       return 0;
+}
+
+static struct hist_entry *hist_browser__selected_entry(struct hist_browser *self)
+{
+       int *indexes;
+
+       if (!symbol_conf.use_callchain)
+               goto out;
+
+       indexes = newtCheckboxTreeFindItem(self->tree, (void *)self->selection);
+       if (indexes) {
+               bool is_hist_entry = indexes[1] == NEWT_ARG_LAST;
+               free(indexes);
+               if (is_hist_entry)
+                       goto out;
+       }
+       return NULL;
+out:
+       return container_of(self->selection, struct hist_entry, ms);
+}
+
+static struct thread *hist_browser__selected_thread(struct hist_browser *self)
+{
+       struct hist_entry *he = hist_browser__selected_entry(self);
+       return he ? he->thread : NULL;
+}
+
+static int hist_browser__title(char *bf, size_t size, const char *input_name,
+                              const struct dso *dso, const struct thread *thread)
+{
+       int printed = 0;
+
+       if (thread)
+               printed += snprintf(bf + printed, size - printed,
+                                   "Thread: %s(%d)",
+                                   (thread->comm_set ?  thread->comm : ""),
+                                   thread->pid);
+       if (dso)
+               printed += snprintf(bf + printed, size - printed,
+                                   "%sDSO: %s", thread ? " " : "",
+                                   dso->short_name);
+       return printed ?: snprintf(bf, size, "Report: %s", input_name);
+}
+
+int hists__browse(struct hists *self, const char *helpline, const char *input_name)
+{
+       struct hist_browser *browser = hist_browser__new();
+       struct pstack *fstack = pstack__new(2);
+       const struct thread *thread_filter = NULL;
+       const struct dso *dso_filter = NULL;
+       struct newtExitStruct es;
+       char msg[160];
+       int err = -1;
+
+       if (browser == NULL)
+               return -1;
+
+       fstack = pstack__new(2);
+       if (fstack == NULL)
+               goto out;
+
+       ui_helpline__push(helpline);
+
+       hist_browser__title(msg, sizeof(msg), input_name,
+                           dso_filter, thread_filter);
+       if (hist_browser__populate(browser, self, msg) < 0)
+               goto out_free_stack;
+
+       while (1) {
+               const struct thread *thread;
+               const struct dso *dso;
+               char *options[16];
+               int nr_options = 0, choice = 0, i,
+                   annotate = -2, zoom_dso = -2, zoom_thread = -2;
+
+               newtFormRun(browser->form, &es);
+
+               thread = hist_browser__selected_thread(browser);
+               dso = browser->selection->map ? browser->selection->map->dso : NULL;
+
+               if (es.reason == NEWT_EXIT_HOTKEY) {
+                       if (es.u.key == NEWT_KEY_F1)
+                               goto do_help;
+
+                       switch (toupper(es.u.key)) {
+                       case 'A':
+                               goto do_annotate;
+                       case 'D':
+                               goto zoom_dso;
+                       case 'T':
+                               goto zoom_thread;
+                       case 'H':
+                       case '?':
+do_help:
+                               ui__help_window("->        Zoom into DSO/Threads & Annotate current symbol\n"
+                                               "<-        Zoom out\n"
+                                               "a         Annotate current symbol\n"
+                                               "h/?/F1    Show this window\n"
+                                               "d         Zoom into current DSO\n"
+                                               "t         Zoom into current Thread\n"
+                                               "q/CTRL+C  Exit browser");
+                               continue;
+                       default:;
+                       }
+                       if (toupper(es.u.key) == 'Q' ||
+                           es.u.key == CTRL('c'))
+                               break;
+                       if (es.u.key == NEWT_KEY_ESCAPE) {
+                               if (dialog_yesno("Do you really want to exit?"))
+                                       break;
+                               else
+                                       continue;
+                       }
+
+                       if (es.u.key == NEWT_KEY_LEFT) {
+                               const void *top;
+
+                               if (pstack__empty(fstack))
+                                       continue;
+                               top = pstack__pop(fstack);
+                               if (top == &dso_filter)
+                                       goto zoom_out_dso;
+                               if (top == &thread_filter)
+                                       goto zoom_out_thread;
+                               continue;
+                       }
+               }
+
+               if (browser->selection->sym != NULL &&
+                   asprintf(&options[nr_options], "Annotate %s",
+                            browser->selection->sym->name) > 0)
+                       annotate = nr_options++;
+
+               if (thread != NULL &&
+                   asprintf(&options[nr_options], "Zoom %s %s(%d) thread",
+                            (thread_filter ? "out of" : "into"),
+                            (thread->comm_set ? thread->comm : ""),
+                            thread->pid) > 0)
+                       zoom_thread = nr_options++;
+
+               if (dso != NULL &&
+                   asprintf(&options[nr_options], "Zoom %s %s DSO",
+                            (dso_filter ? "out of" : "into"),
+                            (dso->kernel ? "the Kernel" : dso->short_name)) > 0)
+                       zoom_dso = nr_options++;
+
+               options[nr_options++] = (char *)"Exit";
+
+               choice = popup_menu(nr_options, options);
+
+               for (i = 0; i < nr_options - 1; ++i)
+                       free(options[i]);
+
+               if (choice == nr_options - 1)
+                       break;
+
+               if (choice == -1)
+                       continue;
+
+               if (choice == annotate) {
+                       struct hist_entry *he;
+do_annotate:
+                       if (browser->selection->map->dso->origin == DSO__ORIG_KERNEL) {
+                               ui_helpline__puts("No vmlinux file found, can't "
+                                                "annotate with just a "
+                                                "kallsyms file");
+                               continue;
+                       }
+
+                       he = hist_browser__selected_entry(browser);
+                       if (he == NULL)
+                               continue;
+
+                       hist_entry__annotate_browser(he);
+               } else if (choice == zoom_dso) {
+zoom_dso:
+                       if (dso_filter) {
+                               pstack__remove(fstack, &dso_filter);
+zoom_out_dso:
+                               ui_helpline__pop();
+                               dso_filter = NULL;
+                       } else {
+                               if (dso == NULL)
+                                       continue;
+                               ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s DSO\"",
+                                                  dso->kernel ? "the Kernel" : dso->short_name);
+                               dso_filter = dso;
+                               pstack__push(fstack, &dso_filter);
+                       }
+                       hists__filter_by_dso(self, dso_filter);
+                       hist_browser__title(msg, sizeof(msg), input_name,
+                                           dso_filter, thread_filter);
+                       if (hist_browser__populate(browser, self, msg) < 0)
+                               goto out;
+               } else if (choice == zoom_thread) {
+zoom_thread:
+                       if (thread_filter) {
+                               pstack__remove(fstack, &thread_filter);
+zoom_out_thread:
+                               ui_helpline__pop();
+                               thread_filter = NULL;
+                       } else {
+                               ui_helpline__fpush("To zoom out press <- or -> + \"Zoom out of %s(%d) thread\"",
+                                                  thread->comm_set ? thread->comm : "",
+                                                  thread->pid);
+                               thread_filter = thread;
+                               pstack__push(fstack, &thread_filter);
+                       }
+                       hists__filter_by_thread(self, thread_filter);
+                       hist_browser__title(msg, sizeof(msg), input_name,
+                                           dso_filter, thread_filter);
+                       if (hist_browser__populate(browser, self, msg) < 0)
+                               goto out;
+               }
+       }
+       err = 0;
+out_free_stack:
+       pstack__delete(fstack);
+out:
+       hist_browser__delete(browser);
+       return err;
+}
+
+static struct newtPercentTreeColors {
+       const char *topColorFg, *topColorBg;
+       const char *mediumColorFg, *mediumColorBg;
+       const char *normalColorFg, *normalColorBg;
+       const char *selColorFg, *selColorBg;
+       const char *codeColorFg, *codeColorBg;
+} defaultPercentTreeColors = {
+       "red",       "lightgray",
+       "green",     "lightgray",
+       "black",     "lightgray",
+       "lightgray", "magenta",
+       "blue",      "lightgray",
+};
+
+void setup_browser(void)
+{
+       struct newtPercentTreeColors *c = &defaultPercentTreeColors;
+       if (!isatty(1))
+               return;
+
+       use_browser = true;
+       newtInit();
+       newtCls();
+       ui_helpline__puts(" ");
+       sltt_set_color(HE_COLORSET_TOP, NULL, c->topColorFg, c->topColorBg);
+       sltt_set_color(HE_COLORSET_MEDIUM, NULL, c->mediumColorFg, c->mediumColorBg);
+       sltt_set_color(HE_COLORSET_NORMAL, NULL, c->normalColorFg, c->normalColorBg);
+       sltt_set_color(HE_COLORSET_SELECTED, NULL, c->selColorFg, c->selColorBg);
+       sltt_set_color(HE_COLORSET_CODE, NULL, c->codeColorFg, c->codeColorBg);
+}
+
+void exit_browser(bool wait_for_ok)
+{
+       if (use_browser) {
+               if (wait_for_ok) {
+                       char title[] = "Fatal Error", ok[] = "Ok";
+                       newtWinMessage(title, ok, browser__last_msg);
+               }
+               newtFinished();
+       }
+}
index 05d0c5c..9bf0f40 100644 (file)
@@ -5,6 +5,7 @@
 #include "parse-events.h"
 #include "exec_cmd.h"
 #include "string.h"
+#include "symbol.h"
 #include "cache.h"
 #include "header.h"
 #include "debugfs.h"
@@ -409,7 +410,6 @@ static enum event_result
 parse_single_tracepoint_event(char *sys_name,
                              const char *evt_name,
                              unsigned int evt_length,
-                             char *flags,
                              struct perf_event_attr *attr,
                              const char **strp)
 {
@@ -418,14 +418,6 @@ parse_single_tracepoint_event(char *sys_name,
        u64 id;
        int fd;
 
-       if (flags) {
-               if (!strncmp(flags, "record", strlen(flags))) {
-                       attr->sample_type |= PERF_SAMPLE_RAW;
-                       attr->sample_type |= PERF_SAMPLE_TIME;
-                       attr->sample_type |= PERF_SAMPLE_CPU;
-               }
-       }
-
        snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
                 sys_name, evt_name);
 
@@ -444,6 +436,13 @@ parse_single_tracepoint_event(char *sys_name,
        attr->type = PERF_TYPE_TRACEPOINT;
        *strp = evt_name + evt_length;
 
+       attr->sample_type |= PERF_SAMPLE_RAW;
+       attr->sample_type |= PERF_SAMPLE_TIME;
+       attr->sample_type |= PERF_SAMPLE_CPU;
+
+       attr->sample_period = 1;
+
+
        return EVT_HANDLED;
 }
 
@@ -532,8 +531,7 @@ static enum event_result parse_tracepoint_event(const char **strp,
                                                       flags);
        } else
                return parse_single_tracepoint_event(sys_name, evt_name,
-                                                    evt_length, flags,
-                                                    attr, strp);
+                                                    evt_length, attr, strp);
 }
 
 static enum event_result
@@ -690,19 +688,29 @@ static enum event_result
 parse_event_modifier(const char **strp, struct perf_event_attr *attr)
 {
        const char *str = *strp;
-       int eu = 1, ek = 1, eh = 1;
+       int exclude = 0;
+       int eu = 0, ek = 0, eh = 0, precise = 0;
 
        if (*str++ != ':')
                return 0;
        while (*str) {
-               if (*str == 'u')
+               if (*str == 'u') {
+                       if (!exclude)
+                               exclude = eu = ek = eh = 1;
                        eu = 0;
-               else if (*str == 'k')
+               } else if (*str == 'k') {
+                       if (!exclude)
+                               exclude = eu = ek = eh = 1;
                        ek = 0;
-               else if (*str == 'h')
+               } else if (*str == 'h') {
+                       if (!exclude)
+                               exclude = eu = ek = eh = 1;
                        eh = 0;
-               else
+               } else if (*str == 'p') {
+                       precise++;
+               } else
                        break;
+
                ++str;
        }
        if (str >= *strp + 2) {
@@ -710,6 +718,7 @@ parse_event_modifier(const char **strp, struct perf_event_attr *attr)
                attr->exclude_user   = eu;
                attr->exclude_kernel = ek;
                attr->exclude_hv     = eh;
+               attr->precise_ip     = precise;
                return 1;
        }
        return 0;
@@ -934,7 +943,8 @@ void print_events(void)
 
        printf("\n");
        printf("  %-42s [%s]\n",
-               "rNNN", event_type_descriptors[PERF_TYPE_RAW]);
+               "rNNN (see 'perf list --help' on how to encode it)",
+              event_type_descriptors[PERF_TYPE_RAW]);
        printf("\n");
 
        printf("  %-42s [%s]\n",
index b8c1f64..fc4ab3f 100644 (file)
@@ -13,6 +13,7 @@ struct tracepoint_path {
 };
 
 extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
+extern bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events);
 
 extern int                     nr_counters;
 
index efebd5b..99d02aa 100644 (file)
@@ -49,8 +49,9 @@ static int get_value(struct parse_opt_ctx_t *p,
                                break;
                        /* FALLTHROUGH */
                case OPTION_BOOLEAN:
+               case OPTION_INCR:
                case OPTION_BIT:
-               case OPTION_SET_INT:
+               case OPTION_SET_UINT:
                case OPTION_SET_PTR:
                        return opterror(opt, "takes no value", flags);
                case OPTION_END:
@@ -58,7 +59,9 @@ static int get_value(struct parse_opt_ctx_t *p,
                case OPTION_GROUP:
                case OPTION_STRING:
                case OPTION_INTEGER:
+               case OPTION_UINTEGER:
                case OPTION_LONG:
+               case OPTION_U64:
                default:
                        break;
                }
@@ -73,11 +76,15 @@ static int get_value(struct parse_opt_ctx_t *p,
                return 0;
 
        case OPTION_BOOLEAN:
+               *(bool *)opt->value = unset ? false : true;
+               return 0;
+
+       case OPTION_INCR:
                *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
                return 0;
 
-       case OPTION_SET_INT:
-               *(int *)opt->value = unset ? 0 : opt->defval;
+       case OPTION_SET_UINT:
+               *(unsigned int *)opt->value = unset ? 0 : opt->defval;
                return 0;
 
        case OPTION_SET_PTR:
@@ -120,6 +127,22 @@ static int get_value(struct parse_opt_ctx_t *p,
                        return opterror(opt, "expects a numerical value", flags);
                return 0;
 
+       case OPTION_UINTEGER:
+               if (unset) {
+                       *(unsigned int *)opt->value = 0;
+                       return 0;
+               }
+               if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
+                       *(unsigned int *)opt->value = opt->defval;
+                       return 0;
+               }
+               if (get_arg(p, opt, flags, &arg))
+                       return -1;
+               *(unsigned int *)opt->value = strtol(arg, (char **)&s, 10);
+               if (*s)
+                       return opterror(opt, "expects a numerical value", flags);
+               return 0;
+
        case OPTION_LONG:
                if (unset) {
                        *(long *)opt->value = 0;
@@ -136,6 +159,22 @@ static int get_value(struct parse_opt_ctx_t *p,
                        return opterror(opt, "expects a numerical value", flags);
                return 0;
 
+       case OPTION_U64:
+               if (unset) {
+                       *(u64 *)opt->value = 0;
+                       return 0;
+               }
+               if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
+                       *(u64 *)opt->value = opt->defval;
+                       return 0;
+               }
+               if (get_arg(p, opt, flags, &arg))
+                       return -1;
+               *(u64 *)opt->value = strtoull(arg, (char **)&s, 10);
+               if (*s)
+                       return opterror(opt, "expects a numerical value", flags);
+               return 0;
+
        case OPTION_END:
        case OPTION_ARGUMENT:
        case OPTION_GROUP:
@@ -441,7 +480,10 @@ int usage_with_options_internal(const char * const *usagestr,
                switch (opts->type) {
                case OPTION_ARGUMENT:
                        break;
+               case OPTION_LONG:
+               case OPTION_U64:
                case OPTION_INTEGER:
+               case OPTION_UINTEGER:
                        if (opts->flags & PARSE_OPT_OPTARG)
                                if (opts->long_name)
                                        pos += fprintf(stderr, "[=<n>]");
@@ -473,14 +515,14 @@ int usage_with_options_internal(const char * const *usagestr,
                                        pos += fprintf(stderr, " ...");
                        }
                        break;
-               default: /* OPTION_{BIT,BOOLEAN,SET_INT,SET_PTR} */
+               default: /* OPTION_{BIT,BOOLEAN,SET_UINT,SET_PTR} */
                case OPTION_END:
                case OPTION_GROUP:
                case OPTION_BIT:
                case OPTION_BOOLEAN:
-               case OPTION_SET_INT:
+               case OPTION_INCR:
+               case OPTION_SET_UINT:
                case OPTION_SET_PTR:
-               case OPTION_LONG:
                        break;
                }
 
@@ -500,6 +542,7 @@ int usage_with_options_internal(const char * const *usagestr,
 void usage_with_options(const char * const *usagestr,
                        const struct option *opts)
 {
+       exit_browser(false);
        usage_with_options_internal(usagestr, opts, 0);
        exit(129);
 }
index 948805a..c7d72dc 100644 (file)
@@ -1,6 +1,9 @@
 #ifndef __PERF_PARSE_OPTIONS_H
 #define __PERF_PARSE_OPTIONS_H
 
+#include <linux/kernel.h>
+#include <stdbool.h>
+
 enum parse_opt_type {
        /* special types */
        OPTION_END,
@@ -8,14 +11,17 @@ enum parse_opt_type {
        OPTION_GROUP,
        /* options with no arguments */
        OPTION_BIT,
-       OPTION_BOOLEAN, /* _INCR would have been a better name */
-       OPTION_SET_INT,
+       OPTION_BOOLEAN,
+       OPTION_INCR,
+       OPTION_SET_UINT,
        OPTION_SET_PTR,
        /* options with arguments (usually) */
        OPTION_STRING,
        OPTION_INTEGER,
        OPTION_LONG,
        OPTION_CALLBACK,
+       OPTION_U64,
+       OPTION_UINTEGER,
 };
 
 enum parse_opt_flags {
@@ -73,7 +79,7 @@ typedef int parse_opt_cb(const struct option *, const char *arg, int unset);
  *
  * `defval`::
  *   default value to fill (*->value) with for PARSE_OPT_OPTARG.
- *   OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in
+ *   OPTION_{BIT,SET_UINT,SET_PTR} store the {mask,integer,pointer} to put in
  *   the value when met.
  *   CALLBACKS can use it like they want.
  */
@@ -90,16 +96,21 @@ struct option {
        intptr_t defval;
 };
 
+#define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v )
+
 #define OPT_END()                   { .type = OPTION_END }
 #define OPT_ARGUMENT(l, h)          { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) }
 #define OPT_GROUP(h)                { .type = OPTION_GROUP, .help = (h) }
-#define OPT_BIT(s, l, v, h, b)      { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) }
-#define OPT_BOOLEAN(s, l, v, h)     { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
-#define OPT_SET_INT(s, l, v, h, i)  { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) }
+#define OPT_BIT(s, l, v, h, b)      { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h), .defval = (b) }
+#define OPT_BOOLEAN(s, l, v, h)     { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = check_vtype(v, bool *), .help = (h) }
+#define OPT_INCR(s, l, v, h)        { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }
+#define OPT_SET_UINT(s, l, v, h, i)  { .type = OPTION_SET_UINT, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h), .defval = (i) }
 #define OPT_SET_PTR(s, l, v, h, p)  { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) }
-#define OPT_INTEGER(s, l, v, h)     { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
-#define OPT_LONG(s, l, v, h)        { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
-#define OPT_STRING(s, l, v, a, h)   { .type = OPTION_STRING,  .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }
+#define OPT_INTEGER(s, l, v, h)     { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) }
+#define OPT_UINTEGER(s, l, v, h)    { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) }
+#define OPT_LONG(s, l, v, h)        { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = check_vtype(v, long *), .help = (h) }
+#define OPT_U64(s, l, v, h)         { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = check_vtype(v, u64 *), .help = (h) }
+#define OPT_STRING(s, l, v, a, h)   { .type = OPTION_STRING,  .short_name = (s), .long_name = (l), .value = check_vtype(v, const char **), (a), .help = (h) }
 #define OPT_DATE(s, l, v, h) \
        { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
 #define OPT_CALLBACK(s, l, v, a, h, f) \
index 7c004b6..914c670 100644 (file)
 #include <limits.h>
 
 #undef _GNU_SOURCE
+#include "util.h"
 #include "event.h"
 #include "string.h"
 #include "strlist.h"
 #include "debug.h"
 #include "cache.h"
 #include "color.h"
-#include "parse-events.h"  /* For debugfs_path */
+#include "symbol.h"
+#include "thread.h"
+#include "debugfs.h"
+#include "trace-event.h"       /* For __unused */
 #include "probe-event.h"
+#include "probe-finder.h"
 
 #define MAX_CMDLEN 256
 #define MAX_PROBE_ARGS 128
 #define PERFPROBE_GROUP "probe"
 
-#define semantic_error(msg ...) die("Semantic error :" msg)
+bool probe_event_dry_run;      /* Dry run flag */
+
+#define semantic_error(msg ...) pr_err("Semantic error :" msg)
 
 /* If there is no space to write, returns -E2BIG. */
 static int e_snprintf(char *str, size_t size, const char *format, ...)
@@ -64,7 +71,275 @@ static int e_snprintf(char *str, size_t size, const char *format, ...)
        return ret;
 }
 
-void parse_line_range_desc(const char *arg, struct line_range *lr)
+static char *synthesize_perf_probe_point(struct perf_probe_point *pp);
+static struct machine machine;
+
+/* Initialize symbol maps and path of vmlinux */
+static int init_vmlinux(void)
+{
+       struct dso *kernel;
+       int ret;
+
+       symbol_conf.sort_by_name = true;
+       if (symbol_conf.vmlinux_name == NULL)
+               symbol_conf.try_vmlinux_path = true;
+       else
+               pr_debug("Use vmlinux: %s\n", symbol_conf.vmlinux_name);
+       ret = symbol__init();
+       if (ret < 0) {
+               pr_debug("Failed to init symbol map.\n");
+               goto out;
+       }
+
+       ret = machine__init(&machine, "/", 0);
+       if (ret < 0)
+               goto out;
+
+       kernel = dso__new_kernel(symbol_conf.vmlinux_name);
+       if (kernel == NULL)
+               die("Failed to create kernel dso.");
+
+       ret = __machine__create_kernel_maps(&machine, kernel);
+       if (ret < 0)
+               pr_debug("Failed to create kernel maps.\n");
+
+out:
+       if (ret < 0)
+               pr_warning("Failed to init vmlinux path.\n");
+       return ret;
+}
+
+#ifdef DWARF_SUPPORT
+static int open_vmlinux(void)
+{
+       if (map__load(machine.vmlinux_maps[MAP__FUNCTION], NULL) < 0) {
+               pr_debug("Failed to load kernel map.\n");
+               return -EINVAL;
+       }
+       pr_debug("Try to open %s\n", machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name);
+       return open(machine.vmlinux_maps[MAP__FUNCTION]->dso->long_name, O_RDONLY);
+}
+
+/* Convert trace point to probe point with debuginfo */
+static int convert_to_perf_probe_point(struct kprobe_trace_point *tp,
+                                      struct perf_probe_point *pp)
+{
+       struct symbol *sym;
+       int fd, ret = -ENOENT;
+
+       sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION],
+                                      tp->symbol, NULL);
+       if (sym) {
+               fd = open_vmlinux();
+               if (fd >= 0) {
+                       ret = find_perf_probe_point(fd,
+                                                sym->start + tp->offset, pp);
+                       close(fd);
+               }
+       }
+       if (ret <= 0) {
+               pr_debug("Failed to find corresponding probes from "
+                        "debuginfo. Use kprobe event information.\n");
+               pp->function = strdup(tp->symbol);
+               if (pp->function == NULL)
+                       return -ENOMEM;
+               pp->offset = tp->offset;
+       }
+       pp->retprobe = tp->retprobe;
+
+       return 0;
+}
+
+/* Try to find perf_probe_event with debuginfo */
+static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev,
+                                          struct kprobe_trace_event **tevs,
+                                          int max_tevs)
+{
+       bool need_dwarf = perf_probe_event_need_dwarf(pev);
+       int fd, ntevs;
+
+       fd = open_vmlinux();
+       if (fd < 0) {
+               if (need_dwarf) {
+                       pr_warning("Failed to open debuginfo file.\n");
+                       return fd;
+               }
+               pr_debug("Could not open vmlinux. Try to use symbols.\n");
+               return 0;
+       }
+
+       /* Searching trace events corresponding to probe event */
+       ntevs = find_kprobe_trace_events(fd, pev, tevs, max_tevs);
+       close(fd);
+
+       if (ntevs > 0) {        /* Succeeded to find trace events */
+               pr_debug("find %d kprobe_trace_events.\n", ntevs);
+               return ntevs;
+       }
+
+       if (ntevs == 0) {       /* No error but failed to find probe point. */
+               pr_warning("Probe point '%s' not found.\n",
+                          synthesize_perf_probe_point(&pev->point));
+               return -ENOENT;
+       }
+       /* Error path : ntevs < 0 */
+       pr_debug("An error occurred in debuginfo analysis (%d).\n", ntevs);
+       if (ntevs == -EBADF) {
+               pr_warning("Warning: No dwarf info found in the vmlinux - "
+                       "please rebuild kernel with CONFIG_DEBUG_INFO=y.\n");
+               if (!need_dwarf) {
+                       pr_debug("Trying to use symbols.\nn");
+                       return 0;
+               }
+       }
+       return ntevs;
+}
+
+#define LINEBUF_SIZE 256
+#define NR_ADDITIONAL_LINES 2
+
+static int show_one_line(FILE *fp, int l, bool skip, bool show_num)
+{
+       char buf[LINEBUF_SIZE];
+       const char *color = PERF_COLOR_BLUE;
+
+       if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
+               goto error;
+       if (!skip) {
+               if (show_num)
+                       fprintf(stdout, "%7d  %s", l, buf);
+               else
+                       color_fprintf(stdout, color, "         %s", buf);
+       }
+
+       while (strlen(buf) == LINEBUF_SIZE - 1 &&
+              buf[LINEBUF_SIZE - 2] != '\n') {
+               if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
+                       goto error;
+               if (!skip) {
+                       if (show_num)
+                               fprintf(stdout, "%s", buf);
+                       else
+                               color_fprintf(stdout, color, "%s", buf);
+               }
+       }
+
+       return 0;
+error:
+       if (feof(fp))
+               pr_warning("Source file is shorter than expected.\n");
+       else
+               pr_warning("File read error: %s\n", strerror(errno));
+
+       return -1;
+}
+
+/*
+ * Show line-range always requires debuginfo to find source file and
+ * line number.
+ */
+int show_line_range(struct line_range *lr)
+{
+       int l = 1;
+       struct line_node *ln;
+       FILE *fp;
+       int fd, ret;
+
+       /* Search a line range */
+       ret = init_vmlinux();
+       if (ret < 0)
+               return ret;
+
+       fd = open_vmlinux();
+       if (fd < 0) {
+               pr_warning("Failed to open debuginfo file.\n");
+               return fd;
+       }
+
+       ret = find_line_range(fd, lr);
+       close(fd);
+       if (ret == 0) {
+               pr_warning("Specified source line is not found.\n");
+               return -ENOENT;
+       } else if (ret < 0) {
+               pr_warning("Debuginfo analysis failed. (%d)\n", ret);
+               return ret;
+       }
+
+       setup_pager();
+
+       if (lr->function)
+               fprintf(stdout, "<%s:%d>\n", lr->function,
+                       lr->start - lr->offset);
+       else
+               fprintf(stdout, "<%s:%d>\n", lr->file, lr->start);
+
+       fp = fopen(lr->path, "r");
+       if (fp == NULL) {
+               pr_warning("Failed to open %s: %s\n", lr->path,
+                          strerror(errno));
+               return -errno;
+       }
+       /* Skip to starting line number */
+       while (l < lr->start && ret >= 0)
+               ret = show_one_line(fp, l++, true, false);
+       if (ret < 0)
+               goto end;
+
+       list_for_each_entry(ln, &lr->line_list, list) {
+               while (ln->line > l && ret >= 0)
+                       ret = show_one_line(fp, (l++) - lr->offset,
+                                           false, false);
+               if (ret >= 0)
+                       ret = show_one_line(fp, (l++) - lr->offset,
+                                           false, true);
+               if (ret < 0)
+                       goto end;
+       }
+
+       if (lr->end == INT_MAX)
+               lr->end = l + NR_ADDITIONAL_LINES;
+       while (l <= lr->end && !feof(fp) && ret >= 0)
+               ret = show_one_line(fp, (l++) - lr->offset, false, false);
+end:
+       fclose(fp);
+       return ret;
+}
+
+#else  /* !DWARF_SUPPORT */
+
+static int convert_to_perf_probe_point(struct kprobe_trace_point *tp,
+                                       struct perf_probe_point *pp)
+{
+       pp->function = strdup(tp->symbol);
+       if (pp->function == NULL)
+               return -ENOMEM;
+       pp->offset = tp->offset;
+       pp->retprobe = tp->retprobe;
+
+       return 0;
+}
+
+static int try_to_find_kprobe_trace_events(struct perf_probe_event *pev,
+                               struct kprobe_trace_event **tevs __unused,
+                               int max_tevs __unused)
+{
+       if (perf_probe_event_need_dwarf(pev)) {
+               pr_warning("Debuginfo-analysis is not supported.\n");
+               return -ENOSYS;
+       }
+       return 0;
+}
+
+int show_line_range(struct line_range *lr __unused)
+{
+       pr_warning("Debuginfo-analysis is not supported.\n");
+       return -ENOSYS;
+}
+
+#endif
+
+int parse_line_range_desc(const char *arg, struct line_range *lr)
 {
        const char *ptr;
        char *tmp;
@@ -75,29 +350,45 @@ void parse_line_range_desc(const char *arg, struct line_range *lr)
         */
        ptr = strchr(arg, ':');
        if (ptr) {
-               lr->start = (unsigned int)strtoul(ptr + 1, &tmp, 0);
-               if (*tmp == '+')
-                       lr->end = lr->start + (unsigned int)strtoul(tmp + 1,
-                                                                   &tmp, 0);
-               else if (*tmp == '-')
-                       lr->end = (unsigned int)strtoul(tmp + 1, &tmp, 0);
+               lr->start = (int)strtoul(ptr + 1, &tmp, 0);
+               if (*tmp == '+') {
+                       lr->end = lr->start + (int)strtoul(tmp + 1, &tmp, 0);
+                       lr->end--;      /*
+                                        * Adjust the number of lines here.
+                                        * If the number of lines == 1, the
+                                        * the end of line should be equal to
+                                        * the start of line.
+                                        */
+               } else if (*tmp == '-')
+                       lr->end = (int)strtoul(tmp + 1, &tmp, 0);
                else
-                       lr->end = 0;
-               pr_debug("Line range is %u to %u\n", lr->start, lr->end);
-               if (lr->end && lr->start > lr->end)
+                       lr->end = INT_MAX;
+               pr_debug("Line range is %d to %d\n", lr->start, lr->end);
+               if (lr->start > lr->end) {
                        semantic_error("Start line must be smaller"
-                                      " than end line.");
-               if (*tmp != '\0')
-                       semantic_error("Tailing with invalid character '%d'.",
+                                      " than end line.\n");
+                       return -EINVAL;
+               }
+               if (*tmp != '\0') {
+                       semantic_error("Tailing with invalid character '%d'.\n",
                                       *tmp);
+                       return -EINVAL;
+               }
                tmp = strndup(arg, (ptr - arg));
-       } else
+       } else {
                tmp = strdup(arg);
+               lr->end = INT_MAX;
+       }
+
+       if (tmp == NULL)
+               return -ENOMEM;
 
        if (strchr(tmp, '.'))
                lr->file = tmp;
        else
                lr->function = tmp;
+
+       return 0;
 }
 
 /* Check the name is good for event/group */
@@ -113,8 +404,9 @@ static bool check_event_name(const char *name)
 }
 
 /* Parse probepoint definition. */
-static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
+static int parse_perf_probe_point(char *arg, struct perf_probe_event *pev)
 {
+       struct perf_probe_point *pp = &pev->point;
        char *ptr, *tmp;
        char c, nc = 0;
        /*
@@ -129,13 +421,19 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
        if (ptr && *ptr == '=') {       /* Event name */
                *ptr = '\0';
                tmp = ptr + 1;
-               ptr = strchr(arg, ':');
-               if (ptr)        /* Group name is not supported yet. */
-                       semantic_error("Group name is not supported yet.");
-               if (!check_event_name(arg))
+               if (strchr(arg, ':')) {
+                       semantic_error("Group name is not supported yet.\n");
+                       return -ENOTSUP;
+               }
+               if (!check_event_name(arg)) {
                        semantic_error("%s is bad for event name -it must "
-                                      "follow C symbol-naming rule.", arg);
-               pp->event = strdup(arg);
+                                      "follow C symbol-naming rule.\n", arg);
+                       return -EINVAL;
+               }
+               pev->event = strdup(arg);
+               if (pev->event == NULL)
+                       return -ENOMEM;
+               pev->group = NULL;
                arg = tmp;
        }
 
@@ -145,12 +443,15 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
                *ptr++ = '\0';
        }
 
+       tmp = strdup(arg);
+       if (tmp == NULL)
+               return -ENOMEM;
+
        /* Check arg is function or file and copy it */
-       if (strchr(arg, '.'))   /* File */
-               pp->file = strdup(arg);
+       if (strchr(tmp, '.'))   /* File */
+               pp->file = tmp;
        else                    /* Function */
-               pp->function = strdup(arg);
-       DIE_IF(pp->file == NULL && pp->function == NULL);
+               pp->function = tmp;
 
        /* Parse other options */
        while (ptr) {
@@ -158,6 +459,8 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
                c = nc;
                if (c == ';') { /* Lazy pattern must be the last part */
                        pp->lazy_line = strdup(arg);
+                       if (pp->lazy_line == NULL)
+                               return -ENOMEM;
                        break;
                }
                ptr = strpbrk(arg, ";:+@%");
@@ -168,266 +471,658 @@ static void parse_perf_probe_probepoint(char *arg, struct probe_point *pp)
                switch (c) {
                case ':':       /* Line number */
                        pp->line = strtoul(arg, &tmp, 0);
-                       if (*tmp != '\0')
+                       if (*tmp != '\0') {
                                semantic_error("There is non-digit char"
-                                              " in line number.");
+                                              " in line number.\n");
+                               return -EINVAL;
+                       }
                        break;
                case '+':       /* Byte offset from a symbol */
                        pp->offset = strtoul(arg, &tmp, 0);
-                       if (*tmp != '\0')
+                       if (*tmp != '\0') {
                                semantic_error("There is non-digit character"
-                                               " in offset.");
+                                               " in offset.\n");
+                               return -EINVAL;
+                       }
                        break;
                case '@':       /* File name */
-                       if (pp->file)
-                               semantic_error("SRC@SRC is not allowed.");
+                       if (pp->file) {
+                               semantic_error("SRC@SRC is not allowed.\n");
+                               return -EINVAL;
+                       }
                        pp->file = strdup(arg);
-                       DIE_IF(pp->file == NULL);
+                       if (pp->file == NULL)
+                               return -ENOMEM;
                        break;
                case '%':       /* Probe places */
                        if (strcmp(arg, "return") == 0) {
                                pp->retprobe = 1;
-                       } else  /* Others not supported yet */
-                               semantic_error("%%%s is not supported.", arg);
+                       } else {        /* Others not supported yet */
+                               semantic_error("%%%s is not supported.\n", arg);
+                               return -ENOTSUP;
+                       }
                        break;
-               default:
-                       DIE_IF("Program has a bug.");
+               default:        /* Buggy case */
+                       pr_err("This program has a bug at %s:%d.\n",
+                               __FILE__, __LINE__);
+                       return -ENOTSUP;
                        break;
                }
        }
 
        /* Exclusion check */
-       if (pp->lazy_line && pp->line)
+       if (pp->lazy_line && pp->line) {
                semantic_error("Lazy pattern can't be used with line number.");
+               return -EINVAL;
+       }
 
-       if (pp->lazy_line && pp->offset)
+       if (pp->lazy_line && pp->offset) {
                semantic_error("Lazy pattern can't be used with offset.");
+               return -EINVAL;
+       }
 
-       if (pp->line && pp->offset)
+       if (pp->line && pp->offset) {
                semantic_error("Offset can't be used with line number.");
+               return -EINVAL;
+       }
 
-       if (!pp->line && !pp->lazy_line && pp->file && !pp->function)
+       if (!pp->line && !pp->lazy_line && pp->file && !pp->function) {
                semantic_error("File always requires line number or "
                               "lazy pattern.");
+               return -EINVAL;
+       }
 
-       if (pp->offset && !pp->function)
+       if (pp->offset && !pp->function) {
                semantic_error("Offset requires an entry function.");
+               return -EINVAL;
+       }
 
-       if (pp->retprobe && !pp->function)
+       if (pp->retprobe && !pp->function) {
                semantic_error("Return probe requires an entry function.");
+               return -EINVAL;
+       }
 
-       if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe)
+       if ((pp->offset || pp->line || pp->lazy_line) && pp->retprobe) {
                semantic_error("Offset/Line/Lazy pattern can't be used with "
                               "return probe.");
+               return -EINVAL;
+       }
 
-       pr_debug("symbol:%s file:%s line:%d offset:%d return:%d lazy:%s\n",
+       pr_debug("symbol:%s file:%s line:%d offset:%lu return:%d lazy:%s\n",
                 pp->function, pp->file, pp->line, pp->offset, pp->retprobe,
                 pp->lazy_line);
+       return 0;
 }
 
-/* Parse perf-probe event definition */
-void parse_perf_probe_event(const char *str, struct probe_point *pp,
-                           bool *need_dwarf)
+/* Parse perf-probe event argument */
+static int parse_perf_probe_arg(char *str, struct perf_probe_arg *arg)
 {
-       char **argv;
-       int argc, i;
+       char *tmp;
+       struct perf_probe_arg_field **fieldp;
+
+       pr_debug("parsing arg: %s into ", str);
 
-       *need_dwarf = false;
+       tmp = strchr(str, '=');
+       if (tmp) {
+               arg->name = strndup(str, tmp - str);
+               if (arg->name == NULL)
+                       return -ENOMEM;
+               pr_debug("name:%s ", arg->name);
+               str = tmp + 1;
+       }
 
-       argv = argv_split(str, &argc);
-       if (!argv)
-               die("argv_split failed.");
-       if (argc > MAX_PROBE_ARGS + 1)
-               semantic_error("Too many arguments");
+       tmp = strchr(str, ':');
+       if (tmp) {      /* Type setting */
+               *tmp = '\0';
+               arg->type = strdup(tmp + 1);
+               if (arg->type == NULL)
+                       return -ENOMEM;
+               pr_debug("type:%s ", arg->type);
+       }
 
+       tmp = strpbrk(str, "-.");
+       if (!is_c_varname(str) || !tmp) {
+               /* A variable, register, symbol or special value */
+               arg->var = strdup(str);
+               if (arg->var == NULL)
+                       return -ENOMEM;
+               pr_debug("%s\n", arg->var);
+               return 0;
+       }
+
+       /* Structure fields */
+       arg->var = strndup(str, tmp - str);
+       if (arg->var == NULL)
+               return -ENOMEM;
+       pr_debug("%s, ", arg->var);
+       fieldp = &arg->field;
+
+       do {
+               *fieldp = zalloc(sizeof(struct perf_probe_arg_field));
+               if (*fieldp == NULL)
+                       return -ENOMEM;
+               if (*tmp == '.') {
+                       str = tmp + 1;
+                       (*fieldp)->ref = false;
+               } else if (tmp[1] == '>') {
+                       str = tmp + 2;
+                       (*fieldp)->ref = true;
+               } else {
+                       semantic_error("Argument parse error: %s\n", str);
+                       return -EINVAL;
+               }
+
+               tmp = strpbrk(str, "-.");
+               if (tmp) {
+                       (*fieldp)->name = strndup(str, tmp - str);
+                       if ((*fieldp)->name == NULL)
+                               return -ENOMEM;
+                       pr_debug("%s(%d), ", (*fieldp)->name, (*fieldp)->ref);
+                       fieldp = &(*fieldp)->next;
+               }
+       } while (tmp);
+       (*fieldp)->name = strdup(str);
+       if ((*fieldp)->name == NULL)
+               return -ENOMEM;
+       pr_debug("%s(%d)\n", (*fieldp)->name, (*fieldp)->ref);
+
+       /* If no name is specified, set the last field name */
+       if (!arg->name) {
+               arg->name = strdup((*fieldp)->name);
+               if (arg->name == NULL)
+                       return -ENOMEM;
+       }
+       return 0;
+}
+
+/* Parse perf-probe event command */
+int parse_perf_probe_command(const char *cmd, struct perf_probe_event *pev)
+{
+       char **argv;
+       int argc, i, ret = 0;
+
+       argv = argv_split(cmd, &argc);
+       if (!argv) {
+               pr_debug("Failed to split arguments.\n");
+               return -ENOMEM;
+       }
+       if (argc - 1 > MAX_PROBE_ARGS) {
+               semantic_error("Too many probe arguments (%d).\n", argc - 1);
+               ret = -ERANGE;
+               goto out;
+       }
        /* Parse probe point */
-       parse_perf_probe_probepoint(argv[0], pp);
-       if (pp->file || pp->line || pp->lazy_line)
-               *need_dwarf = true;
+       ret = parse_perf_probe_point(argv[0], pev);
+       if (ret < 0)
+               goto out;
 
        /* Copy arguments and ensure return probe has no C argument */
-       pp->nr_args = argc - 1;
-       pp->args = zalloc(sizeof(char *) * pp->nr_args);
-       for (i = 0; i < pp->nr_args; i++) {
-               pp->args[i] = strdup(argv[i + 1]);
-               if (!pp->args[i])
-                       die("Failed to copy argument.");
-               if (is_c_varname(pp->args[i])) {
-                       if (pp->retprobe)
-                               semantic_error("You can't specify local"
-                                               " variable for kretprobe");
-                       *need_dwarf = true;
+       pev->nargs = argc - 1;
+       pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+       if (pev->args == NULL) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       for (i = 0; i < pev->nargs && ret >= 0; i++) {
+               ret = parse_perf_probe_arg(argv[i + 1], &pev->args[i]);
+               if (ret >= 0 &&
+                   is_c_varname(pev->args[i].var) && pev->point.retprobe) {
+                       semantic_error("You can't specify local variable for"
+                                      " kretprobe.\n");
+                       ret = -EINVAL;
                }
        }
-
+out:
        argv_free(argv);
+
+       return ret;
+}
+
+/* Return true if this perf_probe_event requires debuginfo */
+bool perf_probe_event_need_dwarf(struct perf_probe_event *pev)
+{
+       int i;
+
+       if (pev->point.file || pev->point.line || pev->point.lazy_line)
+               return true;
+
+       for (i = 0; i < pev->nargs; i++)
+               if (is_c_varname(pev->args[i].var))
+                       return true;
+
+       return false;
 }
 
 /* Parse kprobe_events event into struct probe_point */
-void parse_trace_kprobe_event(const char *str, struct probe_point *pp)
+int parse_kprobe_trace_command(const char *cmd, struct kprobe_trace_event *tev)
 {
+       struct kprobe_trace_point *tp = &tev->point;
        char pr;
        char *p;
        int ret, i, argc;
        char **argv;
 
-       pr_debug("Parsing kprobe_events: %s\n", str);
-       argv = argv_split(str, &argc);
-       if (!argv)
-               die("argv_split failed.");
-       if (argc < 2)
-               semantic_error("Too less arguments.");
+       pr_debug("Parsing kprobe_events: %s\n", cmd);
+       argv = argv_split(cmd, &argc);
+       if (!argv) {
+               pr_debug("Failed to split arguments.\n");
+               return -ENOMEM;
+       }
+       if (argc < 2) {
+               semantic_error("Too few probe arguments.\n");
+               ret = -ERANGE;
+               goto out;
+       }
 
        /* Scan event and group name. */
        ret = sscanf(argv[0], "%c:%a[^/ \t]/%a[^ \t]",
-                    &pr, (float *)(void *)&pp->group,
-                    (float *)(void *)&pp->event);
-       if (ret != 3)
-               semantic_error("Failed to parse event name: %s", argv[0]);
-       pr_debug("Group:%s Event:%s probe:%c\n", pp->group, pp->event, pr);
+                    &pr, (float *)(void *)&tev->group,
+                    (float *)(void *)&tev->event);
+       if (ret != 3) {
+               semantic_error("Failed to parse event name: %s\n", argv[0]);
+               ret = -EINVAL;
+               goto out;
+       }
+       pr_debug("Group:%s Event:%s probe:%c\n", tev->group, tev->event, pr);
 
-       pp->retprobe = (pr == 'r');
+       tp->retprobe = (pr == 'r');
 
        /* Scan function name and offset */
-       ret = sscanf(argv[1], "%a[^+]+%d", (float *)(void *)&pp->function,
-                    &pp->offset);
+       ret = sscanf(argv[1], "%a[^+]+%lu", (float *)(void *)&tp->symbol,
+                    &tp->offset);
        if (ret == 1)
-               pp->offset = 0;
-
-       /* kprobe_events doesn't have this information */
-       pp->line = 0;
-       pp->file = NULL;
+               tp->offset = 0;
 
-       pp->nr_args = argc - 2;
-       pp->args = zalloc(sizeof(char *) * pp->nr_args);
-       for (i = 0; i < pp->nr_args; i++) {
+       tev->nargs = argc - 2;
+       tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+       if (tev->args == NULL) {
+               ret = -ENOMEM;
+               goto out;
+       }
+       for (i = 0; i < tev->nargs; i++) {
                p = strchr(argv[i + 2], '=');
                if (p)  /* We don't need which register is assigned. */
-                       *p = '\0';
-               pp->args[i] = strdup(argv[i + 2]);
-               if (!pp->args[i])
-                       die("Failed to copy argument.");
+                       *p++ = '\0';
+               else
+                       p = argv[i + 2];
+               tev->args[i].name = strdup(argv[i + 2]);
+               /* TODO: parse regs and offset */
+               tev->args[i].value = strdup(p);
+               if (tev->args[i].name == NULL || tev->args[i].value == NULL) {
+                       ret = -ENOMEM;
+                       goto out;
+               }
        }
-
+       ret = 0;
+out:
        argv_free(argv);
+       return ret;
 }
 
-/* Synthesize only probe point (not argument) */
-int synthesize_perf_probe_point(struct probe_point *pp)
+/* Compose only probe arg */
+int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf, size_t len)
 {
-       char *buf;
-       char offs[64] = "", line[64] = "";
+       struct perf_probe_arg_field *field = pa->field;
        int ret;
+       char *tmp = buf;
 
-       pp->probes[0] = buf = zalloc(MAX_CMDLEN);
-       pp->found = 1;
-       if (!buf)
-               die("Failed to allocate memory by zalloc.");
+       if (pa->name && pa->var)
+               ret = e_snprintf(tmp, len, "%s=%s", pa->name, pa->var);
+       else
+               ret = e_snprintf(tmp, len, "%s", pa->name ? pa->name : pa->var);
+       if (ret <= 0)
+               goto error;
+       tmp += ret;
+       len -= ret;
+
+       while (field) {
+               ret = e_snprintf(tmp, len, "%s%s", field->ref ? "->" : ".",
+                                field->name);
+               if (ret <= 0)
+                       goto error;
+               tmp += ret;
+               len -= ret;
+               field = field->next;
+       }
+
+       if (pa->type) {
+               ret = e_snprintf(tmp, len, ":%s", pa->type);
+               if (ret <= 0)
+                       goto error;
+               tmp += ret;
+               len -= ret;
+       }
+
+       return tmp - buf;
+error:
+       pr_debug("Failed to synthesize perf probe argument: %s",
+                strerror(-ret));
+       return ret;
+}
+
+/* Compose only probe point (not argument) */
+static char *synthesize_perf_probe_point(struct perf_probe_point *pp)
+{
+       char *buf, *tmp;
+       char offs[32] = "", line[32] = "", file[32] = "";
+       int ret, len;
+
+       buf = zalloc(MAX_CMDLEN);
+       if (buf == NULL) {
+               ret = -ENOMEM;
+               goto error;
+       }
        if (pp->offset) {
-               ret = e_snprintf(offs, 64, "+%d", pp->offset);
+               ret = e_snprintf(offs, 32, "+%lu", pp->offset);
                if (ret <= 0)
                        goto error;
        }
        if (pp->line) {
-               ret = e_snprintf(line, 64, ":%d", pp->line);
+               ret = e_snprintf(line, 32, ":%d", pp->line);
+               if (ret <= 0)
+                       goto error;
+       }
+       if (pp->file) {
+               len = strlen(pp->file) - 31;
+               if (len < 0)
+                       len = 0;
+               tmp = strchr(pp->file + len, '/');
+               if (!tmp)
+                       tmp = pp->file + len;
+               ret = e_snprintf(file, 32, "@%s", tmp + 1);
                if (ret <= 0)
                        goto error;
        }
 
        if (pp->function)
-               ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s", pp->function,
-                                offs, pp->retprobe ? "%return" : "", line);
+               ret = e_snprintf(buf, MAX_CMDLEN, "%s%s%s%s%s", pp->function,
+                                offs, pp->retprobe ? "%return" : "", line,
+                                file);
        else
-               ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", pp->file, line);
-       if (ret <= 0) {
+               ret = e_snprintf(buf, MAX_CMDLEN, "%s%s", file, line);
+       if (ret <= 0)
+               goto error;
+
+       return buf;
 error:
-               free(pp->probes[0]);
-               pp->probes[0] = NULL;
-               pp->found = 0;
-       }
-       return ret;
+       pr_debug("Failed to synthesize perf probe point: %s",
+                strerror(-ret));
+       if (buf)
+               free(buf);
+       return NULL;
 }
 
-int synthesize_perf_probe_event(struct probe_point *pp)
+#if 0
+char *synthesize_perf_probe_command(struct perf_probe_event *pev)
 {
        char *buf;
        int i, len, ret;
 
-       len = synthesize_perf_probe_point(pp);
-       if (len < 0)
-               return 0;
+       buf = synthesize_perf_probe_point(&pev->point);
+       if (!buf)
+               return NULL;
 
-       buf = pp->probes[0];
-       for (i = 0; i < pp->nr_args; i++) {
+       len = strlen(buf);
+       for (i = 0; i < pev->nargs; i++) {
                ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
-                                pp->args[i]);
-               if (ret <= 0)
-                       goto error;
+                                pev->args[i].name);
+               if (ret <= 0) {
+                       free(buf);
+                       return NULL;
+               }
                len += ret;
        }
-       pp->found = 1;
 
-       return pp->found;
-error:
-       free(pp->probes[0]);
-       pp->probes[0] = NULL;
+       return buf;
+}
+#endif
+
+static int __synthesize_kprobe_trace_arg_ref(struct kprobe_trace_arg_ref *ref,
+                                            char **buf, size_t *buflen,
+                                            int depth)
+{
+       int ret;
+       if (ref->next) {
+               depth = __synthesize_kprobe_trace_arg_ref(ref->next, buf,
+                                                        buflen, depth + 1);
+               if (depth < 0)
+                       goto out;
+       }
+
+       ret = e_snprintf(*buf, *buflen, "%+ld(", ref->offset);
+       if (ret < 0)
+               depth = ret;
+       else {
+               *buf += ret;
+               *buflen -= ret;
+       }
+out:
+       return depth;
 
-       return ret;
 }
 
-int synthesize_trace_kprobe_event(struct probe_point *pp)
+static int synthesize_kprobe_trace_arg(struct kprobe_trace_arg *arg,
+                                      char *buf, size_t buflen)
 {
+       int ret, depth = 0;
+       char *tmp = buf;
+
+       /* Argument name or separator */
+       if (arg->name)
+               ret = e_snprintf(buf, buflen, " %s=", arg->name);
+       else
+               ret = e_snprintf(buf, buflen, " ");
+       if (ret < 0)
+               return ret;
+       buf += ret;
+       buflen -= ret;
+
+       /* Dereferencing arguments */
+       if (arg->ref) {
+               depth = __synthesize_kprobe_trace_arg_ref(arg->ref, &buf,
+                                                         &buflen, 1);
+               if (depth < 0)
+                       return depth;
+       }
+
+       /* Print argument value */
+       ret = e_snprintf(buf, buflen, "%s", arg->value);
+       if (ret < 0)
+               return ret;
+       buf += ret;
+       buflen -= ret;
+
+       /* Closing */
+       while (depth--) {
+               ret = e_snprintf(buf, buflen, ")");
+               if (ret < 0)
+                       return ret;
+               buf += ret;
+               buflen -= ret;
+       }
+       /* Print argument type */
+       if (arg->type) {
+               ret = e_snprintf(buf, buflen, ":%s", arg->type);
+               if (ret <= 0)
+                       return ret;
+               buf += ret;
+       }
+
+       return buf - tmp;
+}
+
+char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev)
+{
+       struct kprobe_trace_point *tp = &tev->point;
        char *buf;
        int i, len, ret;
 
-       pp->probes[0] = buf = zalloc(MAX_CMDLEN);
-       if (!buf)
-               die("Failed to allocate memory by zalloc.");
-       ret = e_snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset);
-       if (ret <= 0)
+       buf = zalloc(MAX_CMDLEN);
+       if (buf == NULL)
+               return NULL;
+
+       len = e_snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s+%lu",
+                        tp->retprobe ? 'r' : 'p',
+                        tev->group, tev->event,
+                        tp->symbol, tp->offset);
+       if (len <= 0)
                goto error;
-       len = ret;
 
-       for (i = 0; i < pp->nr_args; i++) {
-               ret = e_snprintf(&buf[len], MAX_CMDLEN - len, " %s",
-                                pp->args[i]);
+       for (i = 0; i < tev->nargs; i++) {
+               ret = synthesize_kprobe_trace_arg(&tev->args[i], buf + len,
+                                                 MAX_CMDLEN - len);
                if (ret <= 0)
                        goto error;
                len += ret;
        }
-       pp->found = 1;
 
-       return pp->found;
+       return buf;
 error:
-       free(pp->probes[0]);
-       pp->probes[0] = NULL;
+       free(buf);
+       return NULL;
+}
+
+int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
+                               struct perf_probe_event *pev)
+{
+       char buf[64] = "";
+       int i, ret;
+
+       /* Convert event/group name */
+       pev->event = strdup(tev->event);
+       pev->group = strdup(tev->group);
+       if (pev->event == NULL || pev->group == NULL)
+               return -ENOMEM;
+
+       /* Convert trace_point to probe_point */
+       ret = convert_to_perf_probe_point(&tev->point, &pev->point);
+       if (ret < 0)
+               return ret;
+
+       /* Convert trace_arg to probe_arg */
+       pev->nargs = tev->nargs;
+       pev->args = zalloc(sizeof(struct perf_probe_arg) * pev->nargs);
+       if (pev->args == NULL)
+               return -ENOMEM;
+       for (i = 0; i < tev->nargs && ret >= 0; i++) {
+               if (tev->args[i].name)
+                       pev->args[i].name = strdup(tev->args[i].name);
+               else {
+                       ret = synthesize_kprobe_trace_arg(&tev->args[i],
+                                                         buf, 64);
+                       pev->args[i].name = strdup(buf);
+               }
+               if (pev->args[i].name == NULL && ret >= 0)
+                       ret = -ENOMEM;
+       }
+
+       if (ret < 0)
+               clear_perf_probe_event(pev);
 
        return ret;
 }
 
-static int open_kprobe_events(int flags, int mode)
+void clear_perf_probe_event(struct perf_probe_event *pev)
+{
+       struct perf_probe_point *pp = &pev->point;
+       struct perf_probe_arg_field *field, *next;
+       int i;
+
+       if (pev->event)
+               free(pev->event);
+       if (pev->group)
+               free(pev->group);
+       if (pp->file)
+               free(pp->file);
+       if (pp->function)
+               free(pp->function);
+       if (pp->lazy_line)
+               free(pp->lazy_line);
+       for (i = 0; i < pev->nargs; i++) {
+               if (pev->args[i].name)
+                       free(pev->args[i].name);
+               if (pev->args[i].var)
+                       free(pev->args[i].var);
+               if (pev->args[i].type)
+                       free(pev->args[i].type);
+               field = pev->args[i].field;
+               while (field) {
+                       next = field->next;
+                       if (field->name)
+                               free(field->name);
+                       free(field);
+                       field = next;
+               }
+       }
+       if (pev->args)
+               free(pev->args);
+       memset(pev, 0, sizeof(*pev));
+}
+
+void clear_kprobe_trace_event(struct kprobe_trace_event *tev)
+{
+       struct kprobe_trace_arg_ref *ref, *next;
+       int i;
+
+       if (tev->event)
+               free(tev->event);
+       if (tev->group)
+               free(tev->group);
+       if (tev->point.symbol)
+               free(tev->point.symbol);
+       for (i = 0; i < tev->nargs; i++) {
+               if (tev->args[i].name)
+                       free(tev->args[i].name);
+               if (tev->args[i].value)
+                       free(tev->args[i].value);
+               if (tev->args[i].type)
+                       free(tev->args[i].type);
+               ref = tev->args[i].ref;
+               while (ref) {
+                       next = ref->next;
+                       free(ref);
+                       ref = next;
+               }
+       }
+       if (tev->args)
+               free(tev->args);
+       memset(tev, 0, sizeof(*tev));
+}
+
+static int open_kprobe_events(bool readwrite)
 {
        char buf[PATH_MAX];
+       const char *__debugfs;
        int ret;
 
-       ret = e_snprintf(buf, PATH_MAX, "%s/../kprobe_events", debugfs_path);
-       if (ret < 0)
-               die("Failed to make kprobe_events path.");
+       __debugfs = debugfs_find_mountpoint();
+       if (__debugfs == NULL) {
+               pr_warning("Debugfs is not mounted.\n");
+               return -ENOENT;
+       }
+
+       ret = e_snprintf(buf, PATH_MAX, "%stracing/kprobe_events", __debugfs);
+       if (ret >= 0) {
+               pr_debug("Opening %s write=%d\n", buf, readwrite);
+               if (readwrite && !probe_event_dry_run)
+                       ret = open(buf, O_RDWR, O_APPEND);
+               else
+                       ret = open(buf, O_RDONLY, 0);
+       }
 
-       ret = open(buf, flags, mode);
        if (ret < 0) {
                if (errno == ENOENT)
-                       die("kprobe_events file does not exist -"
-                           " please rebuild with CONFIG_KPROBE_EVENT.");
+                       pr_warning("kprobe_events file does not exist - please"
+                                " rebuild kernel with CONFIG_KPROBE_EVENT.\n");
                else
-                       die("Could not open kprobe_events file: %s",
-                           strerror(errno));
+                       pr_warning("Failed to open kprobe_events file: %s\n",
+                                  strerror(errno));
        }
        return ret;
 }
 
 /* Get raw string list of current kprobe_events */
-static struct strlist *get_trace_kprobe_event_rawlist(int fd)
+static struct strlist *get_kprobe_trace_command_rawlist(int fd)
 {
        int ret, idx;
        FILE *fp;
@@ -447,271 +1142,486 @@ static struct strlist *get_trace_kprobe_event_rawlist(int fd)
                if (p[idx] == '\n')
                        p[idx] = '\0';
                ret = strlist__add(sl, buf);
-               if (ret < 0)
-                       die("strlist__add failed: %s", strerror(-ret));
+               if (ret < 0) {
+                       pr_debug("strlist__add failed: %s\n", strerror(-ret));
+                       strlist__delete(sl);
+                       return NULL;
+               }
        }
        fclose(fp);
 
        return sl;
 }
 
-/* Free and zero clear probe_point */
-static void clear_probe_point(struct probe_point *pp)
-{
-       int i;
-
-       if (pp->event)
-               free(pp->event);
-       if (pp->group)
-               free(pp->group);
-       if (pp->function)
-               free(pp->function);
-       if (pp->file)
-               free(pp->file);
-       if (pp->lazy_line)
-               free(pp->lazy_line);
-       for (i = 0; i < pp->nr_args; i++)
-               free(pp->args[i]);
-       if (pp->args)
-               free(pp->args);
-       for (i = 0; i < pp->found; i++)
-               free(pp->probes[i]);
-       memset(pp, 0, sizeof(*pp));
-}
-
 /* Show an event */
-static void show_perf_probe_event(const char *event, const char *place,
-                                 struct probe_point *pp)
+static int show_perf_probe_event(struct perf_probe_event *pev)
 {
        int i, ret;
        char buf[128];
+       char *place;
+
+       /* Synthesize only event probe point */
+       place = synthesize_perf_probe_point(&pev->point);
+       if (!place)
+               return -EINVAL;
 
-       ret = e_snprintf(buf, 128, "%s:%s", pp->group, event);
+       ret = e_snprintf(buf, 128, "%s:%s", pev->group, pev->event);
        if (ret < 0)
-               die("Failed to copy event: %s", strerror(-ret));
-       printf("  %-40s (on %s", buf, place);
+               return ret;
+
+       printf("  %-20s (on %s", buf, place);
 
-       if (pp->nr_args > 0) {
+       if (pev->nargs > 0) {
                printf(" with");
-               for (i = 0; i < pp->nr_args; i++)
-                       printf(" %s", pp->args[i]);
+               for (i = 0; i < pev->nargs; i++) {
+                       ret = synthesize_perf_probe_arg(&pev->args[i],
+                                                       buf, 128);
+                       if (ret < 0)
+                               break;
+                       printf(" %s", buf);
+               }
        }
        printf(")\n");
+       free(place);
+       return ret;
 }
 
 /* List up current perf-probe events */
-void show_perf_probe_events(void)
+int show_perf_probe_events(void)
 {
-       int fd;
-       struct probe_point pp;
+       int fd, ret;
+       struct kprobe_trace_event tev;
+       struct perf_probe_event pev;
        struct strlist *rawlist;
        struct str_node *ent;
 
        setup_pager();
-       memset(&pp, 0, sizeof(pp));
+       ret = init_vmlinux();
+       if (ret < 0)
+               return ret;
+
+       memset(&tev, 0, sizeof(tev));
+       memset(&pev, 0, sizeof(pev));
 
-       fd = open_kprobe_events(O_RDONLY, 0);
-       rawlist = get_trace_kprobe_event_rawlist(fd);
+       fd = open_kprobe_events(false);
+       if (fd < 0)
+               return fd;
+
+       rawlist = get_kprobe_trace_command_rawlist(fd);
        close(fd);
+       if (!rawlist)
+               return -ENOENT;
 
        strlist__for_each(ent, rawlist) {
-               parse_trace_kprobe_event(ent->s, &pp);
-               /* Synthesize only event probe point */
-               synthesize_perf_probe_point(&pp);
-               /* Show an event */
-               show_perf_probe_event(pp.event, pp.probes[0], &pp);
-               clear_probe_point(&pp);
+               ret = parse_kprobe_trace_command(ent->s, &tev);
+               if (ret >= 0) {
+                       ret = convert_to_perf_probe_event(&tev, &pev);
+                       if (ret >= 0)
+                               ret = show_perf_probe_event(&pev);
+               }
+               clear_perf_probe_event(&pev);
+               clear_kprobe_trace_event(&tev);
+               if (ret < 0)
+                       break;
        }
-
        strlist__delete(rawlist);
+
+       return ret;
 }
 
 /* Get current perf-probe event names */
-static struct strlist *get_perf_event_names(int fd, bool include_group)
+static struct strlist *get_kprobe_trace_event_names(int fd, bool include_group)
 {
        char buf[128];
        struct strlist *sl, *rawlist;
        struct str_node *ent;
-       struct probe_point pp;
+       struct kprobe_trace_event tev;
+       int ret = 0;
 
-       memset(&pp, 0, sizeof(pp));
-       rawlist = get_trace_kprobe_event_rawlist(fd);
+       memset(&tev, 0, sizeof(tev));
 
+       rawlist = get_kprobe_trace_command_rawlist(fd);
        sl = strlist__new(true, NULL);
        strlist__for_each(ent, rawlist) {
-               parse_trace_kprobe_event(ent->s, &pp);
+               ret = parse_kprobe_trace_command(ent->s, &tev);
+               if (ret < 0)
+                       break;
                if (include_group) {
-                       if (e_snprintf(buf, 128, "%s:%s", pp.group,
-                                      pp.event) < 0)
-                               die("Failed to copy group:event name.");
-                       strlist__add(sl, buf);
+                       ret = e_snprintf(buf, 128, "%s:%s", tev.group,
+                                       tev.event);
+                       if (ret >= 0)
+                               ret = strlist__add(sl, buf);
                } else
-                       strlist__add(sl, pp.event);
-               clear_probe_point(&pp);
+                       ret = strlist__add(sl, tev.event);
+               clear_kprobe_trace_event(&tev);
+               if (ret < 0)
+                       break;
        }
-
        strlist__delete(rawlist);
 
+       if (ret < 0) {
+               strlist__delete(sl);
+               return NULL;
+       }
        return sl;
 }
 
-static void write_trace_kprobe_event(int fd, const char *buf)
+static int write_kprobe_trace_event(int fd, struct kprobe_trace_event *tev)
 {
-       int ret;
+       int ret = 0;
+       char *buf = synthesize_kprobe_trace_command(tev);
+
+       if (!buf) {
+               pr_debug("Failed to synthesize kprobe trace event.\n");
+               return -EINVAL;
+       }
 
        pr_debug("Writing event: %s\n", buf);
-       ret = write(fd, buf, strlen(buf));
-       if (ret <= 0)
-               die("Failed to write event: %s", strerror(errno));
+       if (!probe_event_dry_run) {
+               ret = write(fd, buf, strlen(buf));
+               if (ret <= 0)
+                       pr_warning("Failed to write event: %s\n",
+                                  strerror(errno));
+       }
+       free(buf);
+       return ret;
 }
 
-static void get_new_event_name(char *buf, size_t len, const char *base,
-                              struct strlist *namelist, bool allow_suffix)
+static int get_new_event_name(char *buf, size_t len, const char *base,
+                             struct strlist *namelist, bool allow_suffix)
 {
        int i, ret;
 
        /* Try no suffix */
        ret = e_snprintf(buf, len, "%s", base);
-       if (ret < 0)
-               die("snprintf() failed: %s", strerror(-ret));
+       if (ret < 0) {
+               pr_debug("snprintf() failed: %s\n", strerror(-ret));
+               return ret;
+       }
        if (!strlist__has_entry(namelist, buf))
-               return;
+               return 0;
 
        if (!allow_suffix) {
                pr_warning("Error: event \"%s\" already exists. "
                           "(Use -f to force duplicates.)\n", base);
-               die("Can't add new event.");
+               return -EEXIST;
        }
 
        /* Try to add suffix */
        for (i = 1; i < MAX_EVENT_INDEX; i++) {
                ret = e_snprintf(buf, len, "%s_%d", base, i);
-               if (ret < 0)
-                       die("snprintf() failed: %s", strerror(-ret));
+               if (ret < 0) {
+                       pr_debug("snprintf() failed: %s\n", strerror(-ret));
+                       return ret;
+               }
                if (!strlist__has_entry(namelist, buf))
                        break;
        }
-       if (i == MAX_EVENT_INDEX)
-               die("Too many events are on the same function.");
+       if (i == MAX_EVENT_INDEX) {
+               pr_warning("Too many events are on the same function.\n");
+               ret = -ERANGE;
+       }
+
+       return ret;
 }
 
-void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
-                            bool force_add)
+static int __add_kprobe_trace_events(struct perf_probe_event *pev,
+                                    struct kprobe_trace_event *tevs,
+                                    int ntevs, bool allow_suffix)
 {
-       int i, j, fd;
-       struct probe_point *pp;
-       char buf[MAX_CMDLEN];
-       char event[64];
+       int i, fd, ret;
+       struct kprobe_trace_event *tev = NULL;
+       char buf[64];
+       const char *event, *group;
        struct strlist *namelist;
-       bool allow_suffix;
 
-       fd = open_kprobe_events(O_RDWR, O_APPEND);
+       fd = open_kprobe_events(true);
+       if (fd < 0)
+               return fd;
        /* Get current event names */
-       namelist = get_perf_event_names(fd, false);
-
-       for (j = 0; j < nr_probes; j++) {
-               pp = probes + j;
-               if (!pp->event)
-                       pp->event = strdup(pp->function);
-               if (!pp->group)
-                       pp->group = strdup(PERFPROBE_GROUP);
-               DIE_IF(!pp->event || !pp->group);
-               /* If force_add is true, suffix search is allowed */
-               allow_suffix = force_add;
-               for (i = 0; i < pp->found; i++) {
-                       /* Get an unused new event name */
-                       get_new_event_name(event, 64, pp->event, namelist,
-                                          allow_suffix);
-                       snprintf(buf, MAX_CMDLEN, "%c:%s/%s %s\n",
-                                pp->retprobe ? 'r' : 'p',
-                                pp->group, event,
-                                pp->probes[i]);
-                       write_trace_kprobe_event(fd, buf);
-                       printf("Added new event:\n");
-                       /* Get the first parameter (probe-point) */
-                       sscanf(pp->probes[i], "%s", buf);
-                       show_perf_probe_event(event, buf, pp);
-                       /* Add added event name to namelist */
-                       strlist__add(namelist, event);
-                       /*
-                        * Probes after the first probe which comes from same
-                        * user input are always allowed to add suffix, because
-                        * there might be several addresses corresponding to
-                        * one code line.
-                        */
-                       allow_suffix = true;
+       namelist = get_kprobe_trace_event_names(fd, false);
+       if (!namelist) {
+               pr_debug("Failed to get current event list.\n");
+               return -EIO;
+       }
+
+       ret = 0;
+       printf("Add new event%s\n", (ntevs > 1) ? "s:" : ":");
+       for (i = 0; i < ntevs; i++) {
+               tev = &tevs[i];
+               if (pev->event)
+                       event = pev->event;
+               else
+                       if (pev->point.function)
+                               event = pev->point.function;
+                       else
+                               event = tev->point.symbol;
+               if (pev->group)
+                       group = pev->group;
+               else
+                       group = PERFPROBE_GROUP;
+
+               /* Get an unused new event name */
+               ret = get_new_event_name(buf, 64, event,
+                                        namelist, allow_suffix);
+               if (ret < 0)
+                       break;
+               event = buf;
+
+               tev->event = strdup(event);
+               tev->group = strdup(group);
+               if (tev->event == NULL || tev->group == NULL) {
+                       ret = -ENOMEM;
+                       break;
                }
+               ret = write_kprobe_trace_event(fd, tev);
+               if (ret < 0)
+                       break;
+               /* Add added event name to namelist */
+               strlist__add(namelist, event);
+
+               /* Trick here - save current event/group */
+               event = pev->event;
+               group = pev->group;
+               pev->event = tev->event;
+               pev->group = tev->group;
+               show_perf_probe_event(pev);
+               /* Trick here - restore current event/group */
+               pev->event = (char *)event;
+               pev->group = (char *)group;
+
+               /*
+                * Probes after the first probe which comes from same
+                * user input are always allowed to add suffix, because
+                * there might be several addresses corresponding to
+                * one code line.
+                */
+               allow_suffix = true;
+       }
+
+       if (ret >= 0) {
+               /* Show how to use the event. */
+               printf("\nYou can now use it on all perf tools, such as:\n\n");
+               printf("\tperf record -e %s:%s -aR sleep 1\n\n", tev->group,
+                        tev->event);
        }
-       /* Show how to use the event. */
-       printf("\nYou can now use it on all perf tools, such as:\n\n");
-       printf("\tperf record -e %s:%s -a sleep 1\n\n", PERFPROBE_GROUP, event);
 
        strlist__delete(namelist);
        close(fd);
+       return ret;
+}
+
+static int convert_to_kprobe_trace_events(struct perf_probe_event *pev,
+                                         struct kprobe_trace_event **tevs,
+                                         int max_tevs)
+{
+       struct symbol *sym;
+       int ret = 0, i;
+       struct kprobe_trace_event *tev;
+
+       /* Convert perf_probe_event with debuginfo */
+       ret = try_to_find_kprobe_trace_events(pev, tevs, max_tevs);
+       if (ret != 0)
+               return ret;
+
+       /* Allocate trace event buffer */
+       tev = *tevs = zalloc(sizeof(struct kprobe_trace_event));
+       if (tev == NULL)
+               return -ENOMEM;
+
+       /* Copy parameters */
+       tev->point.symbol = strdup(pev->point.function);
+       if (tev->point.symbol == NULL) {
+               ret = -ENOMEM;
+               goto error;
+       }
+       tev->point.offset = pev->point.offset;
+       tev->nargs = pev->nargs;
+       if (tev->nargs) {
+               tev->args = zalloc(sizeof(struct kprobe_trace_arg)
+                                  * tev->nargs);
+               if (tev->args == NULL) {
+                       ret = -ENOMEM;
+                       goto error;
+               }
+               for (i = 0; i < tev->nargs; i++) {
+                       if (pev->args[i].name) {
+                               tev->args[i].name = strdup(pev->args[i].name);
+                               if (tev->args[i].name == NULL) {
+                                       ret = -ENOMEM;
+                                       goto error;
+                               }
+                       }
+                       tev->args[i].value = strdup(pev->args[i].var);
+                       if (tev->args[i].value == NULL) {
+                               ret = -ENOMEM;
+                               goto error;
+                       }
+                       if (pev->args[i].type) {
+                               tev->args[i].type = strdup(pev->args[i].type);
+                               if (tev->args[i].type == NULL) {
+                                       ret = -ENOMEM;
+                                       goto error;
+                               }
+                       }
+               }
+       }
+
+       /* Currently just checking function name from symbol map */
+       sym = map__find_symbol_by_name(machine.vmlinux_maps[MAP__FUNCTION],
+                                      tev->point.symbol, NULL);
+       if (!sym) {
+               pr_warning("Kernel symbol \'%s\' not found.\n",
+                          tev->point.symbol);
+               ret = -ENOENT;
+               goto error;
+       }
+
+       return 1;
+error:
+       clear_kprobe_trace_event(tev);
+       free(tev);
+       *tevs = NULL;
+       return ret;
+}
+
+struct __event_package {
+       struct perf_probe_event         *pev;
+       struct kprobe_trace_event       *tevs;
+       int                             ntevs;
+};
+
+int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
+                         bool force_add, int max_tevs)
+{
+       int i, j, ret;
+       struct __event_package *pkgs;
+
+       pkgs = zalloc(sizeof(struct __event_package) * npevs);
+       if (pkgs == NULL)
+               return -ENOMEM;
+
+       /* Init vmlinux path */
+       ret = init_vmlinux();
+       if (ret < 0)
+               return ret;
+
+       /* Loop 1: convert all events */
+       for (i = 0; i < npevs; i++) {
+               pkgs[i].pev = &pevs[i];
+               /* Convert with or without debuginfo */
+               ret  = convert_to_kprobe_trace_events(pkgs[i].pev,
+                                                     &pkgs[i].tevs, max_tevs);
+               if (ret < 0)
+                       goto end;
+               pkgs[i].ntevs = ret;
+       }
+
+       /* Loop 2: add all events */
+       for (i = 0; i < npevs && ret >= 0; i++)
+               ret = __add_kprobe_trace_events(pkgs[i].pev, pkgs[i].tevs,
+                                               pkgs[i].ntevs, force_add);
+end:
+       /* Loop 3: cleanup trace events  */
+       for (i = 0; i < npevs; i++)
+               for (j = 0; j < pkgs[i].ntevs; j++)
+                       clear_kprobe_trace_event(&pkgs[i].tevs[j]);
+
+       return ret;
 }
 
-static void __del_trace_kprobe_event(int fd, struct str_node *ent)
+static int __del_trace_kprobe_event(int fd, struct str_node *ent)
 {
        char *p;
        char buf[128];
+       int ret;
 
        /* Convert from perf-probe event to trace-kprobe event */
-       if (e_snprintf(buf, 128, "-:%s", ent->s) < 0)
-               die("Failed to copy event.");
+       ret = e_snprintf(buf, 128, "-:%s", ent->s);
+       if (ret < 0)
+               goto error;
+
        p = strchr(buf + 2, ':');
-       if (!p)
-               die("Internal error: %s should have ':' but not.", ent->s);
+       if (!p) {
+               pr_debug("Internal error: %s should have ':' but not.\n",
+                        ent->s);
+               ret = -ENOTSUP;
+               goto error;
+       }
        *p = '/';
 
-       write_trace_kprobe_event(fd, buf);
+       pr_debug("Writing event: %s\n", buf);
+       ret = write(fd, buf, strlen(buf));
+       if (ret < 0)
+               goto error;
+
        printf("Remove event: %s\n", ent->s);
+       return 0;
+error:
+       pr_warning("Failed to delete event: %s\n", strerror(-ret));
+       return ret;
 }
 
-static void del_trace_kprobe_event(int fd, const char *group,
-                                  const char *event, struct strlist *namelist)
+static int del_trace_kprobe_event(int fd, const char *group,
+                                 const char *event, struct strlist *namelist)
 {
        char buf[128];
        struct str_node *ent, *n;
-       int found = 0;
+       int found = 0, ret = 0;
 
-       if (e_snprintf(buf, 128, "%s:%s", group, event) < 0)
-               die("Failed to copy event.");
+       ret = e_snprintf(buf, 128, "%s:%s", group, event);
+       if (ret < 0) {
+               pr_err("Failed to copy event.");
+               return ret;
+       }
 
        if (strpbrk(buf, "*?")) { /* Glob-exp */
                strlist__for_each_safe(ent, n, namelist)
                        if (strglobmatch(ent->s, buf)) {
                                found++;
-                               __del_trace_kprobe_event(fd, ent);
+                               ret = __del_trace_kprobe_event(fd, ent);
+                               if (ret < 0)
+                                       break;
                                strlist__remove(namelist, ent);
                        }
        } else {
                ent = strlist__find(namelist, buf);
                if (ent) {
                        found++;
-                       __del_trace_kprobe_event(fd, ent);
-                       strlist__remove(namelist, ent);
+                       ret = __del_trace_kprobe_event(fd, ent);
+                       if (ret >= 0)
+                               strlist__remove(namelist, ent);
                }
        }
-       if (found == 0)
-               pr_info("Info: event \"%s\" does not exist, could not remove it.\n", buf);
+       if (found == 0 && ret >= 0)
+               pr_info("Info: Event \"%s\" does not exist.\n", buf);
+
+       return ret;
 }
 
-void del_trace_kprobe_events(struct strlist *dellist)
+int del_perf_probe_events(struct strlist *dellist)
 {
-       int fd;
+       int fd, ret = 0;
        const char *group, *event;
        char *p, *str;
        struct str_node *ent;
        struct strlist *namelist;
 
-       fd = open_kprobe_events(O_RDWR, O_APPEND);
+       fd = open_kprobe_events(true);
+       if (fd < 0)
+               return fd;
+
        /* Get current event names */
-       namelist = get_perf_event_names(fd, true);
+       namelist = get_kprobe_trace_event_names(fd, true);
+       if (namelist == NULL)
+               return -EINVAL;
 
        strlist__for_each(ent, dellist) {
                str = strdup(ent->s);
-               if (!str)
-                       die("Failed to copy event.");
+               if (str == NULL) {
+                       ret = -ENOMEM;
+                       break;
+               }
                pr_debug("Parsing: %s\n", str);
                p = strchr(str, ':');
                if (p) {
@@ -723,80 +1633,14 @@ void del_trace_kprobe_events(struct strlist *dellist)
                        event = str;
                }
                pr_debug("Group: %s, Event: %s\n", group, event);
-               del_trace_kprobe_event(fd, group, event, namelist);
+               ret = del_trace_kprobe_event(fd, group, event, namelist);
                free(str);
+               if (ret < 0)
+                       break;
        }
        strlist__delete(namelist);
        close(fd);
-}
 
-#define LINEBUF_SIZE 256
-#define NR_ADDITIONAL_LINES 2
-
-static void show_one_line(FILE *fp, unsigned int l, bool skip, bool show_num)
-{
-       char buf[LINEBUF_SIZE];
-       const char *color = PERF_COLOR_BLUE;
-
-       if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
-               goto error;
-       if (!skip) {
-               if (show_num)
-                       fprintf(stdout, "%7u  %s", l, buf);
-               else
-                       color_fprintf(stdout, color, "         %s", buf);
-       }
-
-       while (strlen(buf) == LINEBUF_SIZE - 1 &&
-              buf[LINEBUF_SIZE - 2] != '\n') {
-               if (fgets(buf, LINEBUF_SIZE, fp) == NULL)
-                       goto error;
-               if (!skip) {
-                       if (show_num)
-                               fprintf(stdout, "%s", buf);
-                       else
-                               color_fprintf(stdout, color, "%s", buf);
-               }
-       }
-       return;
-error:
-       if (feof(fp))
-               die("Source file is shorter than expected.");
-       else
-               die("File read error: %s", strerror(errno));
+       return ret;
 }
 
-void show_line_range(struct line_range *lr)
-{
-       unsigned int l = 1;
-       struct line_node *ln;
-       FILE *fp;
-
-       setup_pager();
-
-       if (lr->function)
-               fprintf(stdout, "<%s:%d>\n", lr->function,
-                       lr->start - lr->offset);
-       else
-               fprintf(stdout, "<%s:%d>\n", lr->file, lr->start);
-
-       fp = fopen(lr->path, "r");
-       if (fp == NULL)
-               die("Failed to open %s: %s", lr->path, strerror(errno));
-       /* Skip to starting line number */
-       while (l < lr->start)
-               show_one_line(fp, l++, true, false);
-
-       list_for_each_entry(ln, &lr->line_list, list) {
-               while (ln->line > l)
-                       show_one_line(fp, (l++) - lr->offset, false, false);
-               show_one_line(fp, (l++) - lr->offset, false, true);
-       }
-
-       if (lr->end == INT_MAX)
-               lr->end = l + NR_ADDITIONAL_LINES;
-       while (l < lr->end && !feof(fp))
-               show_one_line(fp, (l++) - lr->offset, false, false);
-
-       fclose(fp);
-}
index 711287d..e9db1a2 100644 (file)
 #define _PROBE_EVENT_H
 
 #include <stdbool.h>
-#include "probe-finder.h"
 #include "strlist.h"
 
-extern void parse_line_range_desc(const char *arg, struct line_range *lr);
-extern void parse_perf_probe_event(const char *str, struct probe_point *pp,
-                                  bool *need_dwarf);
-extern int synthesize_perf_probe_point(struct probe_point *pp);
-extern int synthesize_perf_probe_event(struct probe_point *pp);
-extern void parse_trace_kprobe_event(const char *str, struct probe_point *pp);
-extern int synthesize_trace_kprobe_event(struct probe_point *pp);
-extern void add_trace_kprobe_events(struct probe_point *probes, int nr_probes,
-                                   bool force_add);
-extern void del_trace_kprobe_events(struct strlist *dellist);
-extern void show_perf_probe_events(void);
-extern void show_line_range(struct line_range *lr);
+extern bool probe_event_dry_run;
+
+/* kprobe-tracer tracing point */
+struct kprobe_trace_point {
+       char            *symbol;        /* Base symbol */
+       unsigned long   offset;         /* Offset from symbol */
+       bool            retprobe;       /* Return probe flag */
+};
+
+/* kprobe-tracer tracing argument referencing offset */
+struct kprobe_trace_arg_ref {
+       struct kprobe_trace_arg_ref     *next;  /* Next reference */
+       long                            offset; /* Offset value */
+};
+
+/* kprobe-tracer tracing argument */
+struct kprobe_trace_arg {
+       char                            *name;  /* Argument name */
+       char                            *value; /* Base value */
+       char                            *type;  /* Type name */
+       struct kprobe_trace_arg_ref     *ref;   /* Referencing offset */
+};
+
+/* kprobe-tracer tracing event (point + arg) */
+struct kprobe_trace_event {
+       char                            *event; /* Event name */
+       char                            *group; /* Group name */
+       struct kprobe_trace_point       point;  /* Trace point */
+       int                             nargs;  /* Number of args */
+       struct kprobe_trace_arg         *args;  /* Arguments */
+};
+
+/* Perf probe probing point */
+struct perf_probe_point {
+       char            *file;          /* File path */
+       char            *function;      /* Function name */
+       int             line;           /* Line number */
+       bool            retprobe;       /* Return probe flag */
+       char            *lazy_line;     /* Lazy matching pattern */
+       unsigned long   offset;         /* Offset from function entry */
+};
+
+/* Perf probe probing argument field chain */
+struct perf_probe_arg_field {
+       struct perf_probe_arg_field     *next;  /* Next field */
+       char                            *name;  /* Name of the field */
+       bool                            ref;    /* Referencing flag */
+};
+
+/* Perf probe probing argument */
+struct perf_probe_arg {
+       char                            *name;  /* Argument name */
+       char                            *var;   /* Variable name */
+       char                            *type;  /* Type name */
+       struct perf_probe_arg_field     *field; /* Structure fields */
+};
+
+/* Perf probe probing event (point + arg) */
+struct perf_probe_event {
+       char                    *event; /* Event name */
+       char                    *group; /* Group name */
+       struct perf_probe_point point;  /* Probe point */
+       int                     nargs;  /* Number of arguments */
+       struct perf_probe_arg   *args;  /* Arguments */
+};
+
+
+/* Line number container */
+struct line_node {
+       struct list_head        list;
+       int                     line;
+};
+
+/* Line range */
+struct line_range {
+       char                    *file;          /* File name */
+       char                    *function;      /* Function name */
+       int                     start;          /* Start line number */
+       int                     end;            /* End line number */
+       int                     offset;         /* Start line offset */
+       char                    *path;          /* Real path name */
+       struct list_head        line_list;      /* Visible lines */
+};
+
+/* Command string to events */
+extern int parse_perf_probe_command(const char *cmd,
+                                   struct perf_probe_event *pev);
+extern int parse_kprobe_trace_command(const char *cmd,
+                                     struct kprobe_trace_event *tev);
+
+/* Events to command string */
+extern char *synthesize_perf_probe_command(struct perf_probe_event *pev);
+extern char *synthesize_kprobe_trace_command(struct kprobe_trace_event *tev);
+extern int synthesize_perf_probe_arg(struct perf_probe_arg *pa, char *buf,
+                                    size_t len);
+
+/* Check the perf_probe_event needs debuginfo */
+extern bool perf_probe_event_need_dwarf(struct perf_probe_event *pev);
+
+/* Convert from kprobe_trace_event to perf_probe_event */
+extern int convert_to_perf_probe_event(struct kprobe_trace_event *tev,
+                                      struct perf_probe_event *pev);
+
+/* Release event contents */
+extern void clear_perf_probe_event(struct perf_probe_event *pev);
+extern void clear_kprobe_trace_event(struct kprobe_trace_event *tev);
+
+/* Command string to line-range */
+extern int parse_line_range_desc(const char *cmd, struct line_range *lr);
+
+
+extern int add_perf_probe_events(struct perf_probe_event *pevs, int npevs,
+                                bool force_add, int max_probe_points);
+extern int del_perf_probe_events(struct strlist *dellist);
+extern int show_perf_probe_events(void);
+extern int show_line_range(struct line_range *lr);
+
 
 /* Maximum index number of event-name postfix */
 #define MAX_EVENT_INDEX        1024
index c171a24..562b144 100644 (file)
@@ -31,6 +31,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <ctype.h>
+#include <dwarf-regs.h>
 
 #include "string.h"
 #include "event.h"
 #include "util.h"
 #include "probe-finder.h"
 
-
-/*
- * Generic dwarf analysis helpers
- */
-
-#define X86_32_MAX_REGS 8
-const char *x86_32_regs_table[X86_32_MAX_REGS] = {
-       "%ax",
-       "%cx",
-       "%dx",
-       "%bx",
-       "$stack",       /* Stack address instead of %sp */
-       "%bp",
-       "%si",
-       "%di",
-};
-
-#define X86_64_MAX_REGS 16
-const char *x86_64_regs_table[X86_64_MAX_REGS] = {
-       "%ax",
-       "%dx",
-       "%cx",
-       "%bx",
-       "%si",
-       "%di",
-       "%bp",
-       "%sp",
-       "%r8",
-       "%r9",
-       "%r10",
-       "%r11",
-       "%r12",
-       "%r13",
-       "%r14",
-       "%r15",
-};
-
-/* TODO: switching by dwarf address size */
-#ifdef __x86_64__
-#define ARCH_MAX_REGS X86_64_MAX_REGS
-#define arch_regs_table x86_64_regs_table
-#else
-#define ARCH_MAX_REGS X86_32_MAX_REGS
-#define arch_regs_table x86_32_regs_table
-#endif
-
-/* Return architecture dependent register string (for kprobe-tracer) */
-static const char *get_arch_regstr(unsigned int n)
-{
-       return (n <= ARCH_MAX_REGS) ? arch_regs_table[n] : NULL;
-}
+/* Kprobe tracer basic type is up to u64 */
+#define MAX_BASIC_TYPE_BITS    64
 
 /*
  * Compare the tail of two strings.
@@ -108,7 +60,7 @@ static int strtailcmp(const char *s1, const char *s2)
 /* Line number list operations */
 
 /* Add a line to line number list */
-static void line_list__add_line(struct list_head *head, unsigned int line)
+static int line_list__add_line(struct list_head *head, int line)
 {
        struct line_node *ln;
        struct list_head *p;
@@ -119,21 +71,23 @@ static void line_list__add_line(struct list_head *head, unsigned int line)
                        p = &ln->list;
                        goto found;
                } else if (ln->line == line)    /* Already exist */
-                       return ;
+                       return 1;
        }
        /* List is empty, or the smallest entry */
        p = head;
 found:
        pr_debug("line list: add a line %u\n", line);
        ln = zalloc(sizeof(struct line_node));
-       DIE_IF(ln == NULL);
+       if (ln == NULL)
+               return -ENOMEM;
        ln->line = line;
        INIT_LIST_HEAD(&ln->list);
        list_add(&ln->list, p);
+       return 0;
 }
 
 /* Check if the line in line number list */
-static int line_list__has_line(struct list_head *head, unsigned int line)
+static int line_list__has_line(struct list_head *head, int line)
 {
        struct line_node *ln;
 
@@ -184,9 +138,129 @@ static const char *cu_find_realpath(Dwarf_Die *cu_die, const char *fname)
                if (strtailcmp(src, fname) == 0)
                        break;
        }
+       if (i == nfiles)
+               return NULL;
        return src;
 }
 
+/* Compare diename and tname */
+static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
+{
+       const char *name;
+       name = dwarf_diename(dw_die);
+       return name ? strcmp(tname, name) : -1;
+}
+
+/* Get type die, but skip qualifiers and typedef */
+static Dwarf_Die *die_get_real_type(Dwarf_Die *vr_die, Dwarf_Die *die_mem)
+{
+       Dwarf_Attribute attr;
+       int tag;
+
+       do {
+               if (dwarf_attr(vr_die, DW_AT_type, &attr) == NULL ||
+                   dwarf_formref_die(&attr, die_mem) == NULL)
+                       return NULL;
+
+               tag = dwarf_tag(die_mem);
+               vr_die = die_mem;
+       } while (tag == DW_TAG_const_type ||
+                tag == DW_TAG_restrict_type ||
+                tag == DW_TAG_volatile_type ||
+                tag == DW_TAG_shared_type ||
+                tag == DW_TAG_typedef);
+
+       return die_mem;
+}
+
+static bool die_is_signed_type(Dwarf_Die *tp_die)
+{
+       Dwarf_Attribute attr;
+       Dwarf_Word ret;
+
+       if (dwarf_attr(tp_die, DW_AT_encoding, &attr) == NULL ||
+           dwarf_formudata(&attr, &ret) != 0)
+               return false;
+
+       return (ret == DW_ATE_signed_char || ret == DW_ATE_signed ||
+               ret == DW_ATE_signed_fixed);
+}
+
+static int die_get_byte_size(Dwarf_Die *tp_die)
+{
+       Dwarf_Attribute attr;
+       Dwarf_Word ret;
+
+       if (dwarf_attr(tp_die, DW_AT_byte_size, &attr) == NULL ||
+           dwarf_formudata(&attr, &ret) != 0)
+               return 0;
+
+       return (int)ret;
+}
+
+/* Get data_member_location offset */
+static int die_get_data_member_location(Dwarf_Die *mb_die, Dwarf_Word *offs)
+{
+       Dwarf_Attribute attr;
+       Dwarf_Op *expr;
+       size_t nexpr;
+       int ret;
+
+       if (dwarf_attr(mb_die, DW_AT_data_member_location, &attr) == NULL)
+               return -ENOENT;
+
+       if (dwarf_formudata(&attr, offs) != 0) {
+               /* DW_AT_data_member_location should be DW_OP_plus_uconst */
+               ret = dwarf_getlocation(&attr, &expr, &nexpr);
+               if (ret < 0 || nexpr == 0)
+                       return -ENOENT;
+
+               if (expr[0].atom != DW_OP_plus_uconst || nexpr != 1) {
+                       pr_debug("Unable to get offset:Unexpected OP %x (%zd)\n",
+                                expr[0].atom, nexpr);
+                       return -ENOTSUP;
+               }
+               *offs = (Dwarf_Word)expr[0].number;
+       }
+       return 0;
+}
+
+/* Return values for die_find callbacks */
+enum {
+       DIE_FIND_CB_FOUND = 0,          /* End of Search */
+       DIE_FIND_CB_CHILD = 1,          /* Search only children */
+       DIE_FIND_CB_SIBLING = 2,        /* Search only siblings */
+       DIE_FIND_CB_CONTINUE = 3,       /* Search children and siblings */
+};
+
+/* Search a child die */
+static Dwarf_Die *die_find_child(Dwarf_Die *rt_die,
+                                int (*callback)(Dwarf_Die *, void *),
+                                void *data, Dwarf_Die *die_mem)
+{
+       Dwarf_Die child_die;
+       int ret;
+
+       ret = dwarf_child(rt_die, die_mem);
+       if (ret != 0)
+               return NULL;
+
+       do {
+               ret = callback(die_mem, data);
+               if (ret == DIE_FIND_CB_FOUND)
+                       return die_mem;
+
+               if ((ret & DIE_FIND_CB_CHILD) &&
+                   die_find_child(die_mem, callback, data, &child_die)) {
+                       memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
+                       return die_mem;
+               }
+       } while ((ret & DIE_FIND_CB_SIBLING) &&
+                dwarf_siblingof(die_mem, die_mem) == 0);
+
+       return NULL;
+}
+
 struct __addr_die_search_param {
        Dwarf_Addr      addr;
        Dwarf_Die       *die_mem;
@@ -205,8 +279,8 @@ static int __die_search_func_cb(Dwarf_Die *fn_die, void *data)
 }
 
 /* Search a real subprogram including this line, */
-static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
-                                         Dwarf_Die *die_mem)
+static Dwarf_Die *die_find_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
+                                          Dwarf_Die *die_mem)
 {
        struct __addr_die_search_param ad;
        ad.addr = addr;
@@ -218,77 +292,64 @@ static Dwarf_Die *die_get_real_subprogram(Dwarf_Die *cu_die, Dwarf_Addr addr,
                return die_mem;
 }
 
-/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
-static Dwarf_Die *die_get_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
-                                    Dwarf_Die *die_mem)
+/* die_find callback for inline function search */
+static int __die_find_inline_cb(Dwarf_Die *die_mem, void *data)
 {
-       Dwarf_Die child_die;
-       int ret;
+       Dwarf_Addr *addr = data;
 
-       ret = dwarf_child(sp_die, die_mem);
-       if (ret != 0)
-               return NULL;
+       if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
+           dwarf_haspc(die_mem, *addr))
+               return DIE_FIND_CB_FOUND;
 
-       do {
-               if (dwarf_tag(die_mem) == DW_TAG_inlined_subroutine &&
-                   dwarf_haspc(die_mem, addr))
-                       return die_mem;
-
-               if (die_get_inlinefunc(die_mem, addr, &child_die)) {
-                       memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
-                       return die_mem;
-               }
-       } while (dwarf_siblingof(die_mem, die_mem) == 0);
-
-       return NULL;
+       return DIE_FIND_CB_CONTINUE;
 }
 
-/* Compare diename and tname */
-static bool die_compare_name(Dwarf_Die *dw_die, const char *tname)
+/* Similar to dwarf_getfuncs, but returns inlined_subroutine if exists. */
+static Dwarf_Die *die_find_inlinefunc(Dwarf_Die *sp_die, Dwarf_Addr addr,
+                                     Dwarf_Die *die_mem)
 {
-       const char *name;
-       name = dwarf_diename(dw_die);
-       DIE_IF(name == NULL);
-       return strcmp(tname, name);
+       return die_find_child(sp_die, __die_find_inline_cb, &addr, die_mem);
 }
 
-/* Get entry pc(or low pc, 1st entry of ranges)  of the die */
-static Dwarf_Addr die_get_entrypc(Dwarf_Die *dw_die)
+static int __die_find_variable_cb(Dwarf_Die *die_mem, void *data)
 {
-       Dwarf_Addr epc;
-       int ret;
+       const char *name = data;
+       int tag;
 
-       ret = dwarf_entrypc(dw_die, &epc);
-       DIE_IF(ret == -1);
-       return epc;
+       tag = dwarf_tag(die_mem);
+       if ((tag == DW_TAG_formal_parameter ||
+            tag == DW_TAG_variable) &&
+           (die_compare_name(die_mem, name) == 0))
+               return DIE_FIND_CB_FOUND;
+
+       return DIE_FIND_CB_CONTINUE;
 }
 
-/* Get a variable die */
+/* Find a variable called 'name' */
 static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name,
                                    Dwarf_Die *die_mem)
 {
-       Dwarf_Die child_die;
-       int tag;
-       int ret;
+       return die_find_child(sp_die, __die_find_variable_cb, (void *)name,
+                             die_mem);
+}
 
-       ret = dwarf_child(sp_die, die_mem);
-       if (ret != 0)
-               return NULL;
+static int __die_find_member_cb(Dwarf_Die *die_mem, void *data)
+{
+       const char *name = data;
 
-       do {
-               tag = dwarf_tag(die_mem);
-               if ((tag == DW_TAG_formal_parameter ||
-                    tag == DW_TAG_variable) &&
-                   (die_compare_name(die_mem, name) == 0))
-                       return die_mem;
+       if ((dwarf_tag(die_mem) == DW_TAG_member) &&
+           (die_compare_name(die_mem, name) == 0))
+               return DIE_FIND_CB_FOUND;
 
-               if (die_find_variable(die_mem, name, &child_die)) {
-                       memcpy(die_mem, &child_die, sizeof(Dwarf_Die));
-                       return die_mem;
-               }
-       } while (dwarf_siblingof(die_mem, die_mem) == 0);
+       return DIE_FIND_CB_SIBLING;
+}
 
-       return NULL;
+/* Find a member called 'name' */
+static Dwarf_Die *die_find_member(Dwarf_Die *st_die, const char *name,
+                                 Dwarf_Die *die_mem)
+{
+       return die_find_child(st_die, __die_find_member_cb, (void *)name,
+                             die_mem);
 }
 
 /*
@@ -296,19 +357,22 @@ static Dwarf_Die *die_find_variable(Dwarf_Die *sp_die, const char *name,
  */
 
 /* Show a location */
-static void show_location(Dwarf_Op *op, struct probe_finder *pf)
+static int convert_location(Dwarf_Op *op, struct probe_finder *pf)
 {
        unsigned int regn;
        Dwarf_Word offs = 0;
-       int deref = 0, ret;
+       bool ref = false;
        const char *regs;
+       struct kprobe_trace_arg *tvar = pf->tvar;
 
-       /* TODO: support CFA */
        /* If this is based on frame buffer, set the offset */
        if (op->atom == DW_OP_fbreg) {
-               if (pf->fb_ops == NULL)
-                       die("The attribute of frame base is not supported.\n");
-               deref = 1;
+               if (pf->fb_ops == NULL) {
+                       pr_warning("The attribute of frame base is not "
+                                  "supported.\n");
+                       return -ENOTSUP;
+               }
+               ref = true;
                offs = op->number;
                op = &pf->fb_ops[0];
        }
@@ -316,35 +380,164 @@ static void show_location(Dwarf_Op *op, struct probe_finder *pf)
        if (op->atom >= DW_OP_breg0 && op->atom <= DW_OP_breg31) {
                regn = op->atom - DW_OP_breg0;
                offs += op->number;
-               deref = 1;
+               ref = true;
        } else if (op->atom >= DW_OP_reg0 && op->atom <= DW_OP_reg31) {
                regn = op->atom - DW_OP_reg0;
        } else if (op->atom == DW_OP_bregx) {
                regn = op->number;
                offs += op->number2;
-               deref = 1;
+               ref = true;
        } else if (op->atom == DW_OP_regx) {
                regn = op->number;
-       } else
-               die("DW_OP %d is not supported.", op->atom);
+       } else {
+               pr_warning("DW_OP %x is not supported.\n", op->atom);
+               return -ENOTSUP;
+       }
 
        regs = get_arch_regstr(regn);
-       if (!regs)
-               die("%u exceeds max register number.", regn);
+       if (!regs) {
+               pr_warning("Mapping for DWARF register number %u missing on this architecture.", regn);
+               return -ERANGE;
+       }
+
+       tvar->value = strdup(regs);
+       if (tvar->value == NULL)
+               return -ENOMEM;
+
+       if (ref) {
+               tvar->ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
+               if (tvar->ref == NULL)
+                       return -ENOMEM;
+               tvar->ref->offset = (long)offs;
+       }
+       return 0;
+}
+
+static int convert_variable_type(Dwarf_Die *vr_die,
+                                struct kprobe_trace_arg *targ)
+{
+       Dwarf_Die type;
+       char buf[16];
+       int ret;
+
+       if (die_get_real_type(vr_die, &type) == NULL) {
+               pr_warning("Failed to get a type information of %s.\n",
+                          dwarf_diename(vr_die));
+               return -ENOENT;
+       }
+
+       ret = die_get_byte_size(&type) * 8;
+       if (ret) {
+               /* Check the bitwidth */
+               if (ret > MAX_BASIC_TYPE_BITS) {
+                       pr_info("%s exceeds max-bitwidth."
+                               " Cut down to %d bits.\n",
+                               dwarf_diename(&type), MAX_BASIC_TYPE_BITS);
+                       ret = MAX_BASIC_TYPE_BITS;
+               }
+
+               ret = snprintf(buf, 16, "%c%d",
+                              die_is_signed_type(&type) ? 's' : 'u', ret);
+               if (ret < 0 || ret >= 16) {
+                       if (ret >= 16)
+                               ret = -E2BIG;
+                       pr_warning("Failed to convert variable type: %s\n",
+                                  strerror(-ret));
+                       return ret;
+               }
+               targ->type = strdup(buf);
+               if (targ->type == NULL)
+                       return -ENOMEM;
+       }
+       return 0;
+}
+
+static int convert_variable_fields(Dwarf_Die *vr_die, const char *varname,
+                                   struct perf_probe_arg_field *field,
+                                   struct kprobe_trace_arg_ref **ref_ptr,
+                                   Dwarf_Die *die_mem)
+{
+       struct kprobe_trace_arg_ref *ref = *ref_ptr;
+       Dwarf_Die type;
+       Dwarf_Word offs;
+       int ret;
+
+       pr_debug("converting %s in %s\n", field->name, varname);
+       if (die_get_real_type(vr_die, &type) == NULL) {
+               pr_warning("Failed to get the type of %s.\n", varname);
+               return -ENOENT;
+       }
+
+       /* Check the pointer and dereference */
+       if (dwarf_tag(&type) == DW_TAG_pointer_type) {
+               if (!field->ref) {
+                       pr_err("Semantic error: %s must be referred by '->'\n",
+                              field->name);
+                       return -EINVAL;
+               }
+               /* Get the type pointed by this pointer */
+               if (die_get_real_type(&type, &type) == NULL) {
+                       pr_warning("Failed to get the type of %s.\n", varname);
+                       return -ENOENT;
+               }
+               /* Verify it is a data structure  */
+               if (dwarf_tag(&type) != DW_TAG_structure_type) {
+                       pr_warning("%s is not a data structure.\n", varname);
+                       return -EINVAL;
+               }
+
+               ref = zalloc(sizeof(struct kprobe_trace_arg_ref));
+               if (ref == NULL)
+                       return -ENOMEM;
+               if (*ref_ptr)
+                       (*ref_ptr)->next = ref;
+               else
+                       *ref_ptr = ref;
+       } else {
+               /* Verify it is a data structure  */
+               if (dwarf_tag(&type) != DW_TAG_structure_type) {
+                       pr_warning("%s is not a data structure.\n", varname);
+                       return -EINVAL;
+               }
+               if (field->ref) {
+                       pr_err("Semantic error: %s must be referred by '.'\n",
+                              field->name);
+                       return -EINVAL;
+               }
+               if (!ref) {
+                       pr_warning("Structure on a register is not "
+                                  "supported yet.\n");
+                       return -ENOTSUP;
+               }
+       }
+
+       if (die_find_member(&type, field->name, die_mem) == NULL) {
+               pr_warning("%s(tyep:%s) has no member %s.\n", varname,
+                          dwarf_diename(&type), field->name);
+               return -EINVAL;
+       }
 
-       if (deref)
-               ret = snprintf(pf->buf, pf->len, " %s=%+jd(%s)",
-                              pf->var, (intmax_t)offs, regs);
+       /* Get the offset of the field */
+       ret = die_get_data_member_location(die_mem, &offs);
+       if (ret < 0) {
+               pr_warning("Failed to get the offset of %s.\n", field->name);
+               return ret;
+       }
+       ref->offset += (long)offs;
+
+       /* Converting next field */
+       if (field->next)
+               return convert_variable_fields(die_mem, field->name,
+                                       field->next, &ref, die_mem);
        else
-               ret = snprintf(pf->buf, pf->len, " %s=%s", pf->var, regs);
-       DIE_IF(ret < 0);
-       DIE_IF(ret >= pf->len);
+               return 0;
 }
 
 /* Show a variables in kprobe event format */
-static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
+static int convert_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
 {
        Dwarf_Attribute attr;
+       Dwarf_Die die_mem;
        Dwarf_Op *expr;
        size_t nexpr;
        int ret;
@@ -356,142 +549,191 @@ static void show_variable(Dwarf_Die *vr_die, struct probe_finder *pf)
        if (ret <= 0 || nexpr == 0)
                goto error;
 
-       show_location(expr, pf);
+       ret = convert_location(expr, pf);
+       if (ret == 0 && pf->pvar->field) {
+               ret = convert_variable_fields(vr_die, pf->pvar->var,
+                                             pf->pvar->field, &pf->tvar->ref,
+                                             &die_mem);
+               vr_die = &die_mem;
+       }
+       if (ret == 0) {
+               if (pf->pvar->type) {
+                       pf->tvar->type = strdup(pf->pvar->type);
+                       if (pf->tvar->type == NULL)
+                               ret = -ENOMEM;
+               } else
+                       ret = convert_variable_type(vr_die, pf->tvar);
+       }
        /* *expr will be cached in libdw. Don't free it. */
-       return ;
+       return ret;
 error:
        /* TODO: Support const_value */
-       die("Failed to find the location of %s at this address.\n"
-           " Perhaps, it has been optimized out.", pf->var);
+       pr_err("Failed to find the location of %s at this address.\n"
+              " Perhaps, it has been optimized out.\n", pf->pvar->var);
+       return -ENOENT;
 }
 
 /* Find a variable in a subprogram die */
-static void find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
+static int find_variable(Dwarf_Die *sp_die, struct probe_finder *pf)
 {
-       int ret;
        Dwarf_Die vr_die;
+       char buf[32], *ptr;
+       int ret;
 
-       /* TODO: Support struct members and arrays */
-       if (!is_c_varname(pf->var)) {
-               /* Output raw parameters */
-               ret = snprintf(pf->buf, pf->len, " %s", pf->var);
-               DIE_IF(ret < 0);
-               DIE_IF(ret >= pf->len);
-               return ;
+       /* TODO: Support arrays */
+       if (pf->pvar->name)
+               pf->tvar->name = strdup(pf->pvar->name);
+       else {
+               ret = synthesize_perf_probe_arg(pf->pvar, buf, 32);
+               if (ret < 0)
+                       return ret;
+               ptr = strchr(buf, ':'); /* Change type separator to _ */
+               if (ptr)
+                       *ptr = '_';
+               pf->tvar->name = strdup(buf);
+       }
+       if (pf->tvar->name == NULL)
+               return -ENOMEM;
+
+       if (!is_c_varname(pf->pvar->var)) {
+               /* Copy raw parameters */
+               pf->tvar->value = strdup(pf->pvar->var);
+               if (pf->tvar->value == NULL)
+                       return -ENOMEM;
+               else
+                       return 0;
        }
 
-       pr_debug("Searching '%s' variable in context.\n", pf->var);
+       pr_debug("Searching '%s' variable in context.\n",
+                pf->pvar->var);
        /* Search child die for local variables and parameters. */
-       if (!die_find_variable(sp_die, pf->var, &vr_die))
-               die("Failed to find '%s' in this function.", pf->var);
-
-       show_variable(&vr_die, pf);
+       if (!die_find_variable(sp_die, pf->pvar->var, &vr_die)) {
+               pr_warning("Failed to find '%s' in this function.\n",
+                          pf->pvar->var);
+               return -ENOENT;
+       }
+       return convert_variable(&vr_die, pf);
 }
 
 /* Show a probe point to output buffer */
-static void show_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
+static int convert_probe_point(Dwarf_Die *sp_die, struct probe_finder *pf)
 {
-       struct probe_point *pp = pf->pp;
+       struct kprobe_trace_event *tev;
        Dwarf_Addr eaddr;
        Dwarf_Die die_mem;
        const char *name;
-       char tmp[MAX_PROBE_BUFFER];
-       int ret, i, len;
+       int ret, i;
        Dwarf_Attribute fb_attr;
        size_t nops;
 
+       if (pf->ntevs == pf->max_tevs) {
+               pr_warning("Too many( > %d) probe point found.\n",
+                          pf->max_tevs);
+               return -ERANGE;
+       }
+       tev = &pf->tevs[pf->ntevs++];
+
        /* If no real subprogram, find a real one */
        if (!sp_die || dwarf_tag(sp_die) != DW_TAG_subprogram) {
-               sp_die = die_get_real_subprogram(&pf->cu_die,
+               sp_die = die_find_real_subprogram(&pf->cu_die,
                                                 pf->addr, &die_mem);
-               if (!sp_die)
-                       die("Probe point is not found in subprograms.");
+               if (!sp_die) {
+                       pr_warning("Failed to find probe point in any "
+                                  "functions.\n");
+                       return -ENOENT;
+               }
        }
 
-       /* Output name of probe point */
+       /* Copy the name of probe point */
        name = dwarf_diename(sp_die);
        if (name) {
-               dwarf_entrypc(sp_die, &eaddr);
-               ret = snprintf(tmp, MAX_PROBE_BUFFER, "%s+%lu", name,
-                               (unsigned long)(pf->addr - eaddr));
-               /* Copy the function name if possible */
-               if (!pp->function) {
-                       pp->function = strdup(name);
-                       pp->offset = (size_t)(pf->addr - eaddr);
+               if (dwarf_entrypc(sp_die, &eaddr) != 0) {
+                       pr_warning("Failed to get entry pc of %s\n",
+                                  dwarf_diename(sp_die));
+                       return -ENOENT;
                }
-       } else {
+               tev->point.symbol = strdup(name);
+               if (tev->point.symbol == NULL)
+                       return -ENOMEM;
+               tev->point.offset = (unsigned long)(pf->addr - eaddr);
+       } else
                /* This function has no name. */
-               ret = snprintf(tmp, MAX_PROBE_BUFFER, "0x%jx",
-                              (uintmax_t)pf->addr);
-               if (!pp->function) {
-                       /* TODO: Use _stext */
-                       pp->function = strdup("");
-                       pp->offset = (size_t)pf->addr;
-               }
-       }
-       DIE_IF(ret < 0);
-       DIE_IF(ret >= MAX_PROBE_BUFFER);
-       len = ret;
-       pr_debug("Probe point found: %s\n", tmp);
+               tev->point.offset = (unsigned long)pf->addr;
+
+       pr_debug("Probe point found: %s+%lu\n", tev->point.symbol,
+                tev->point.offset);
 
        /* Get the frame base attribute/ops */
        dwarf_attr(sp_die, DW_AT_frame_base, &fb_attr);
        ret = dwarf_getlocation_addr(&fb_attr, pf->addr, &pf->fb_ops, &nops, 1);
-       if (ret <= 0 || nops == 0)
+       if (ret <= 0 || nops == 0) {
                pf->fb_ops = NULL;
+       } else if (nops == 1 && pf->fb_ops[0].atom == DW_OP_call_frame_cfa &&
+                  pf->cfi != NULL) {
+               Dwarf_Frame *frame;
+               if (dwarf_cfi_addrframe(pf->cfi, pf->addr, &frame) != 0 ||
+                   dwarf_frame_cfa(frame, &pf->fb_ops, &nops) != 0) {
+                       pr_warning("Failed to get CFA on 0x%jx\n",
+                                  (uintmax_t)pf->addr);
+                       return -ENOENT;
+               }
+       }
 
        /* Find each argument */
-       /* TODO: use dwarf_cfi_addrframe */
-       for (i = 0; i < pp->nr_args; i++) {
-               pf->var = pp->args[i];
-               pf->buf = &tmp[len];
-               pf->len = MAX_PROBE_BUFFER - len;
-               find_variable(sp_die, pf);
-               len += strlen(pf->buf);
+       tev->nargs = pf->pev->nargs;
+       tev->args = zalloc(sizeof(struct kprobe_trace_arg) * tev->nargs);
+       if (tev->args == NULL)
+               return -ENOMEM;
+       for (i = 0; i < pf->pev->nargs; i++) {
+               pf->pvar = &pf->pev->args[i];
+               pf->tvar = &tev->args[i];
+               ret = find_variable(sp_die, pf);
+               if (ret != 0)
+                       return ret;
        }
 
        /* *pf->fb_ops will be cached in libdw. Don't free it. */
        pf->fb_ops = NULL;
-
-       if (pp->found == MAX_PROBES)
-               die("Too many( > %d) probe point found.\n", MAX_PROBES);
-
-       pp->probes[pp->found] = strdup(tmp);
-       pp->found++;
+       return 0;
 }
 
 /* Find probe point from its line number */
-static void find_probe_point_by_line(struct probe_finder *pf)
+static int find_probe_point_by_line(struct probe_finder *pf)
 {
        Dwarf_Lines *lines;
        Dwarf_Line *line;
        size_t nlines, i;
        Dwarf_Addr addr;
        int lineno;
-       int ret;
+       int ret = 0;
 
-       ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines);
-       DIE_IF(ret != 0);
+       if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) {
+               pr_warning("No source lines found in this CU.\n");
+               return -ENOENT;
+       }
 
-       for (i = 0; i < nlines; i++) {
+       for (i = 0; i < nlines && ret == 0; i++) {
                line = dwarf_onesrcline(lines, i);
-               dwarf_lineno(line, &lineno);
-               if (lineno != pf->lno)
+               if (dwarf_lineno(line, &lineno) != 0 ||
+                   lineno != pf->lno)
                        continue;
 
                /* TODO: Get fileno from line, but how? */
                if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
                        continue;
 
-               ret = dwarf_lineaddr(line, &addr);
-               DIE_IF(ret != 0);
+               if (dwarf_lineaddr(line, &addr) != 0) {
+                       pr_warning("Failed to get the address of the line.\n");
+                       return -ENOENT;
+               }
                pr_debug("Probe line found: line[%d]:%d addr:0x%jx\n",
                         (int)i, lineno, (uintmax_t)addr);
                pf->addr = addr;
 
-               show_probe_point(NULL, pf);
+               ret = convert_probe_point(NULL, pf);
                /* Continuing, because target line might be inlined. */
        }
+       return ret;
 }
 
 /* Find lines which match lazy pattern */
@@ -499,16 +741,27 @@ static int find_lazy_match_lines(struct list_head *head,
                                 const char *fname, const char *pat)
 {
        char *fbuf, *p1, *p2;
-       int fd, line, nlines = 0;
+       int fd, ret, line, nlines = 0;
        struct stat st;
 
        fd = open(fname, O_RDONLY);
-       if (fd < 0)
-               die("failed to open %s", fname);
-       DIE_IF(fstat(fd, &st) < 0);
-       fbuf = malloc(st.st_size + 2);
-       DIE_IF(fbuf == NULL);
-       DIE_IF(read(fd, fbuf, st.st_size) < 0);
+       if (fd < 0) {
+               pr_warning("Failed to open %s: %s\n", fname, strerror(-fd));
+               return fd;
+       }
+
+       ret = fstat(fd, &st);
+       if (ret < 0) {
+               pr_warning("Failed to get the size of %s: %s\n",
+                          fname, strerror(errno));
+               return ret;
+       }
+       fbuf = xmalloc(st.st_size + 2);
+       ret = read(fd, fbuf, st.st_size);
+       if (ret < 0) {
+               pr_warning("Failed to read %s: %s\n", fname, strerror(errno));
+               return ret;
+       }
        close(fd);
        fbuf[st.st_size] = '\n';        /* Dummy line */
        fbuf[st.st_size + 1] = '\0';
@@ -528,7 +781,7 @@ static int find_lazy_match_lines(struct list_head *head,
 }
 
 /* Find probe points from lazy pattern  */
-static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
+static int find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
 {
        Dwarf_Lines *lines;
        Dwarf_Line *line;
@@ -536,37 +789,46 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
        Dwarf_Addr addr;
        Dwarf_Die die_mem;
        int lineno;
-       int ret;
+       int ret = 0;
 
        if (list_empty(&pf->lcache)) {
                /* Matching lazy line pattern */
                ret = find_lazy_match_lines(&pf->lcache, pf->fname,
-                                           pf->pp->lazy_line);
-               if (ret <= 0)
-                       die("No matched lines found in %s.", pf->fname);
+                                           pf->pev->point.lazy_line);
+               if (ret == 0) {
+                       pr_debug("No matched lines found in %s.\n", pf->fname);
+                       return 0;
+               } else if (ret < 0)
+                       return ret;
        }
 
-       ret = dwarf_getsrclines(&pf->cu_die, &lines, &nlines);
-       DIE_IF(ret != 0);
-       for (i = 0; i < nlines; i++) {
+       if (dwarf_getsrclines(&pf->cu_die, &lines, &nlines) != 0) {
+               pr_warning("No source lines found in this CU.\n");
+               return -ENOENT;
+       }
+
+       for (i = 0; i < nlines && ret >= 0; i++) {
                line = dwarf_onesrcline(lines, i);
 
-               dwarf_lineno(line, &lineno);
-               if (!line_list__has_line(&pf->lcache, lineno))
+               if (dwarf_lineno(line, &lineno) != 0 ||
+                   !line_list__has_line(&pf->lcache, lineno))
                        continue;
 
                /* TODO: Get fileno from line, but how? */
                if (strtailcmp(dwarf_linesrc(line, NULL, NULL), pf->fname) != 0)
                        continue;
 
-               ret = dwarf_lineaddr(line, &addr);
-               DIE_IF(ret != 0);
+               if (dwarf_lineaddr(line, &addr) != 0) {
+                       pr_debug("Failed to get the address of line %d.\n",
+                                lineno);
+                       continue;
+               }
                if (sp_die) {
                        /* Address filtering 1: does sp_die include addr? */
                        if (!dwarf_haspc(sp_die, addr))
                                continue;
                        /* Address filtering 2: No child include addr? */
-                       if (die_get_inlinefunc(sp_die, addr, &die_mem))
+                       if (die_find_inlinefunc(sp_die, addr, &die_mem))
                                continue;
                }
 
@@ -574,27 +836,44 @@ static void find_probe_point_lazy(Dwarf_Die *sp_die, struct probe_finder *pf)
                         (int)i, lineno, (unsigned long long)addr);
                pf->addr = addr;
 
-               show_probe_point(sp_die, pf);
+               ret = convert_probe_point(sp_die, pf);
                /* Continuing, because target line might be inlined. */
        }
        /* TODO: deallocate lines, but how? */
+       return ret;
 }
 
+/* Callback parameter with return value */
+struct dwarf_callback_param {
+       void *data;
+       int retval;
+};
+
 static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
 {
-       struct probe_finder *pf = (struct probe_finder *)data;
-       struct probe_point *pp = pf->pp;
+       struct dwarf_callback_param *param = data;
+       struct probe_finder *pf = param->data;
+       struct perf_probe_point *pp = &pf->pev->point;
+       Dwarf_Addr addr;
 
        if (pp->lazy_line)
-               find_probe_point_lazy(in_die, pf);
+               param->retval = find_probe_point_lazy(in_die, pf);
        else {
                /* Get probe address */
-               pf->addr = die_get_entrypc(in_die);
+               if (dwarf_entrypc(in_die, &addr) != 0) {
+                       pr_warning("Failed to get entry pc of %s.\n",
+                                  dwarf_diename(in_die));
+                       param->retval = -ENOENT;
+                       return DWARF_CB_ABORT;
+               }
+               pf->addr = addr;
                pf->addr += pp->offset;
                pr_debug("found inline addr: 0x%jx\n",
                         (uintmax_t)pf->addr);
 
-               show_probe_point(in_die, pf);
+               param->retval = convert_probe_point(in_die, pf);
+               if (param->retval < 0)
+                       return DWARF_CB_ABORT;
        }
 
        return DWARF_CB_OK;
@@ -603,59 +882,88 @@ static int probe_point_inline_cb(Dwarf_Die *in_die, void *data)
 /* Search function from function name */
 static int probe_point_search_cb(Dwarf_Die *sp_die, void *data)
 {
-       struct probe_finder *pf = (struct probe_finder *)data;
-       struct probe_point *pp = pf->pp;
+       struct dwarf_callback_param *param = data;
+       struct probe_finder *pf = param->data;
+       struct perf_probe_point *pp = &pf->pev->point;
 
        /* Check tag and diename */
        if (dwarf_tag(sp_die) != DW_TAG_subprogram ||
            die_compare_name(sp_die, pp->function) != 0)
-               return 0;
+               return DWARF_CB_OK;
 
        pf->fname = dwarf_decl_file(sp_die);
        if (pp->line) { /* Function relative line */
                dwarf_decl_line(sp_die, &pf->lno);
                pf->lno += pp->line;
-               find_probe_point_by_line(pf);
+               param->retval = find_probe_point_by_line(pf);
        } else if (!dwarf_func_inline(sp_die)) {
                /* Real function */
                if (pp->lazy_line)
-                       find_probe_point_lazy(sp_die, pf);
+                       param->retval = find_probe_point_lazy(sp_die, pf);
                else {
-                       pf->addr = die_get_entrypc(sp_die);
+                       if (dwarf_entrypc(sp_die, &pf->addr) != 0) {
+                               pr_warning("Failed to get entry pc of %s.\n",
+                                          dwarf_diename(sp_die));
+                               param->retval = -ENOENT;
+                               return DWARF_CB_ABORT;
+                       }
                        pf->addr += pp->offset;
                        /* TODO: Check the address in this function */
-                       show_probe_point(sp_die, pf);
+                       param->retval = convert_probe_point(sp_die, pf);
                }
-       } else
+       } else {
+               struct dwarf_callback_param _param = {.data = (void *)pf,
+                                                     .retval = 0};
                /* Inlined function: search instances */
-               dwarf_func_inline_instances(sp_die, probe_point_inline_cb, pf);
+               dwarf_func_inline_instances(sp_die, probe_point_inline_cb,
+                                           &_param);
+               param->retval = _param.retval;
+       }
 
-       return 1; /* Exit; no same symbol in this CU. */
+       return DWARF_CB_ABORT; /* Exit; no same symbol in this CU. */
 }
 
-static void find_probe_point_by_func(struct probe_finder *pf)
+static int find_probe_point_by_func(struct probe_finder *pf)
 {
-       dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, pf, 0);
+       struct dwarf_callback_param _param = {.data = (void *)pf,
+                                             .retval = 0};
+       dwarf_getfuncs(&pf->cu_die, probe_point_search_cb, &_param, 0);
+       return _param.retval;
 }
 
-/* Find a probe point */
-int find_probe_point(int fd, struct probe_point *pp)
+/* Find kprobe_trace_events specified by perf_probe_event from debuginfo */
+int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
+                            struct kprobe_trace_event **tevs, int max_tevs)
 {
-       struct probe_finder pf = {.pp = pp};
+       struct probe_finder pf = {.pev = pev, .max_tevs = max_tevs};
+       struct perf_probe_point *pp = &pev->point;
        Dwarf_Off off, noff;
        size_t cuhl;
        Dwarf_Die *diep;
        Dwarf *dbg;
+       int ret = 0;
+
+       pf.tevs = zalloc(sizeof(struct kprobe_trace_event) * max_tevs);
+       if (pf.tevs == NULL)
+               return -ENOMEM;
+       *tevs = pf.tevs;
+       pf.ntevs = 0;
 
        dbg = dwarf_begin(fd, DWARF_C_READ);
-       if (!dbg)
-               return -ENOENT;
+       if (!dbg) {
+               pr_warning("No dwarf info found in the vmlinux - "
+                       "please rebuild with CONFIG_DEBUG_INFO=y.\n");
+               return -EBADF;
+       }
+
+       /* Get the call frame information from this dwarf */
+       pf.cfi = dwarf_getcfi(dbg);
 
-       pp->found = 0;
        off = 0;
        line_list__init(&pf.lcache);
        /* Loop on CUs (Compilation Unit) */
-       while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL)) {
+       while (!dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) &&
+              ret >= 0) {
                /* Get the DIE(Debugging Information Entry) of this CU */
                diep = dwarf_offdie(dbg, off + cuhl, &pf.cu_die);
                if (!diep)
@@ -669,12 +977,12 @@ int find_probe_point(int fd, struct probe_point *pp)
 
                if (!pp->file || pf.fname) {
                        if (pp->function)
-                               find_probe_point_by_func(&pf);
+                               ret = find_probe_point_by_func(&pf);
                        else if (pp->lazy_line)
-                               find_probe_point_lazy(NULL, &pf);
+                               ret = find_probe_point_lazy(NULL, &pf);
                        else {
                                pf.lno = pp->line;
-                               find_probe_point_by_line(&pf);
+                               ret = find_probe_point_by_line(&pf);
                        }
                }
                off = noff;
@@ -682,41 +990,169 @@ int find_probe_point(int fd, struct probe_point *pp)
        line_list__free(&pf.lcache);
        dwarf_end(dbg);
 
-       return pp->found;
+       return (ret < 0) ? ret : pf.ntevs;
+}
+
+/* Reverse search */
+int find_perf_probe_point(int fd, unsigned long addr,
+                         struct perf_probe_point *ppt)
+{
+       Dwarf_Die cudie, spdie, indie;
+       Dwarf *dbg;
+       Dwarf_Line *line;
+       Dwarf_Addr laddr, eaddr;
+       const char *tmp;
+       int lineno, ret = 0;
+       bool found = false;
+
+       dbg = dwarf_begin(fd, DWARF_C_READ);
+       if (!dbg)
+               return -EBADF;
+
+       /* Find cu die */
+       if (!dwarf_addrdie(dbg, (Dwarf_Addr)addr, &cudie)) {
+               ret = -EINVAL;
+               goto end;
+       }
+
+       /* Find a corresponding line */
+       line = dwarf_getsrc_die(&cudie, (Dwarf_Addr)addr);
+       if (line) {
+               if (dwarf_lineaddr(line, &laddr) == 0 &&
+                   (Dwarf_Addr)addr == laddr &&
+                   dwarf_lineno(line, &lineno) == 0) {
+                       tmp = dwarf_linesrc(line, NULL, NULL);
+                       if (tmp) {
+                               ppt->line = lineno;
+                               ppt->file = strdup(tmp);
+                               if (ppt->file == NULL) {
+                                       ret = -ENOMEM;
+                                       goto end;
+                               }
+                               found = true;
+                       }
+               }
+       }
+
+       /* Find a corresponding function */
+       if (die_find_real_subprogram(&cudie, (Dwarf_Addr)addr, &spdie)) {
+               tmp = dwarf_diename(&spdie);
+               if (!tmp || dwarf_entrypc(&spdie, &eaddr) != 0)
+                       goto end;
+
+               if (ppt->line) {
+                       if (die_find_inlinefunc(&spdie, (Dwarf_Addr)addr,
+                                               &indie)) {
+                               /* addr in an inline function */
+                               tmp = dwarf_diename(&indie);
+                               if (!tmp)
+                                       goto end;
+                               ret = dwarf_decl_line(&indie, &lineno);
+                       } else {
+                               if (eaddr == addr) {    /* Function entry */
+                                       lineno = ppt->line;
+                                       ret = 0;
+                               } else
+                                       ret = dwarf_decl_line(&spdie, &lineno);
+                       }
+                       if (ret == 0) {
+                               /* Make a relative line number */
+                               ppt->line -= lineno;
+                               goto found;
+                       }
+               }
+               /* We don't have a line number, let's use offset */
+               ppt->offset = addr - (unsigned long)eaddr;
+found:
+               ppt->function = strdup(tmp);
+               if (ppt->function == NULL) {
+                       ret = -ENOMEM;
+                       goto end;
+               }
+               found = true;
+       }
+
+end:
+       dwarf_end(dbg);
+       if (ret >= 0)
+               ret = found ? 1 : 0;
+       return ret;
+}
+
+/* Add a line and store the src path */
+static int line_range_add_line(const char *src, unsigned int lineno,
+                              struct line_range *lr)
+{
+       /* Copy real path */
+       if (!lr->path) {
+               lr->path = strdup(src);
+               if (lr->path == NULL)
+                       return -ENOMEM;
+       }
+       return line_list__add_line(&lr->line_list, lineno);
+}
+
+/* Search function declaration lines */
+static int line_range_funcdecl_cb(Dwarf_Die *sp_die, void *data)
+{
+       struct dwarf_callback_param *param = data;
+       struct line_finder *lf = param->data;
+       const char *src;
+       int lineno;
+
+       src = dwarf_decl_file(sp_die);
+       if (src && strtailcmp(src, lf->fname) != 0)
+               return DWARF_CB_OK;
+
+       if (dwarf_decl_line(sp_die, &lineno) != 0 ||
+           (lf->lno_s > lineno || lf->lno_e < lineno))
+               return DWARF_CB_OK;
+
+       param->retval = line_range_add_line(src, lineno, lf->lr);
+       if (param->retval < 0)
+               return DWARF_CB_ABORT;
+       return DWARF_CB_OK;
+}
+
+static int find_line_range_func_decl_lines(struct line_finder *lf)
+{
+       struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0};
+       dwarf_getfuncs(&lf->cu_die, line_range_funcdecl_cb, &param, 0);
+       return param.retval;
 }
 
 /* Find line range from its line number */
-static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
+static int find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
 {
        Dwarf_Lines *lines;
        Dwarf_Line *line;
        size_t nlines, i;
        Dwarf_Addr addr;
-       int lineno;
-       int ret;
+       int lineno, ret = 0;
        const char *src;
        Dwarf_Die die_mem;
 
        line_list__init(&lf->lr->line_list);
-       ret = dwarf_getsrclines(&lf->cu_die, &lines, &nlines);
-       DIE_IF(ret != 0);
+       if (dwarf_getsrclines(&lf->cu_die, &lines, &nlines) != 0) {
+               pr_warning("No source lines found in this CU.\n");
+               return -ENOENT;
+       }
 
+       /* Search probable lines on lines list */
        for (i = 0; i < nlines; i++) {
                line = dwarf_onesrcline(lines, i);
-               ret = dwarf_lineno(line, &lineno);
-               DIE_IF(ret != 0);
-               if (lf->lno_s > lineno || lf->lno_e < lineno)
+               if (dwarf_lineno(line, &lineno) != 0 ||
+                   (lf->lno_s > lineno || lf->lno_e < lineno))
                        continue;
 
                if (sp_die) {
                        /* Address filtering 1: does sp_die include addr? */
-                       ret = dwarf_lineaddr(line, &addr);
-                       DIE_IF(ret != 0);
-                       if (!dwarf_haspc(sp_die, addr))
+                       if (dwarf_lineaddr(line, &addr) != 0 ||
+                           !dwarf_haspc(sp_die, addr))
                                continue;
 
                        /* Address filtering 2: No child include addr? */
-                       if (die_get_inlinefunc(sp_die, addr, &die_mem))
+                       if (die_find_inlinefunc(sp_die, addr, &die_mem))
                                continue;
                }
 
@@ -725,30 +1161,49 @@ static void find_line_range_by_line(Dwarf_Die *sp_die, struct line_finder *lf)
                if (strtailcmp(src, lf->fname) != 0)
                        continue;
 
-               /* Copy real path */
-               if (!lf->lr->path)
-                       lf->lr->path = strdup(src);
-               line_list__add_line(&lf->lr->line_list, (unsigned int)lineno);
+               ret = line_range_add_line(src, lineno, lf->lr);
+               if (ret < 0)
+                       return ret;
        }
+
+       /*
+        * Dwarf lines doesn't include function declarations. We have to
+        * check functions list or given function.
+        */
+       if (sp_die) {
+               src = dwarf_decl_file(sp_die);
+               if (src && dwarf_decl_line(sp_die, &lineno) == 0 &&
+                   (lf->lno_s <= lineno && lf->lno_e >= lineno))
+                       ret = line_range_add_line(src, lineno, lf->lr);
+       } else
+               ret = find_line_range_func_decl_lines(lf);
+
        /* Update status */
-       if (!list_empty(&lf->lr->line_list))
-               lf->found = 1;
+       if (ret >= 0)
+               if (!list_empty(&lf->lr->line_list))
+                       ret = lf->found = 1;
+               else
+                       ret = 0;        /* Lines are not found */
        else {
                free(lf->lr->path);
                lf->lr->path = NULL;
        }
+       return ret;
 }
 
 static int line_range_inline_cb(Dwarf_Die *in_die, void *data)
 {
-       find_line_range_by_line(in_die, (struct line_finder *)data);
+       struct dwarf_callback_param *param = data;
+
+       param->retval = find_line_range_by_line(in_die, param->data);
        return DWARF_CB_ABORT;  /* No need to find other instances */
 }
 
 /* Search function from function name */
 static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
 {
-       struct line_finder *lf = (struct line_finder *)data;
+       struct dwarf_callback_param *param = data;
+       struct line_finder *lf = param->data;
        struct line_range *lr = lf->lr;
 
        if (dwarf_tag(sp_die) == DW_TAG_subprogram &&
@@ -757,44 +1212,55 @@ static int line_range_search_cb(Dwarf_Die *sp_die, void *data)
                dwarf_decl_line(sp_die, &lr->offset);
                pr_debug("fname: %s, lineno:%d\n", lf->fname, lr->offset);
                lf->lno_s = lr->offset + lr->start;
-               if (!lr->end)
+               if (lf->lno_s < 0)      /* Overflow */
+                       lf->lno_s = INT_MAX;
+               lf->lno_e = lr->offset + lr->end;
+               if (lf->lno_e < 0)      /* Overflow */
                        lf->lno_e = INT_MAX;
-               else
-                       lf->lno_e = lr->offset + lr->end;
+               pr_debug("New line range: %d to %d\n", lf->lno_s, lf->lno_e);
                lr->start = lf->lno_s;
                lr->end = lf->lno_e;
-               if (dwarf_func_inline(sp_die))
+               if (dwarf_func_inline(sp_die)) {
+                       struct dwarf_callback_param _param;
+                       _param.data = (void *)lf;
+                       _param.retval = 0;
                        dwarf_func_inline_instances(sp_die,
-                                                   line_range_inline_cb, lf);
-               else
-                       find_line_range_by_line(sp_die, lf);
-               return 1;
+                                                   line_range_inline_cb,
+                                                   &_param);
+                       param->retval = _param.retval;
+               } else
+                       param->retval = find_line_range_by_line(sp_die, lf);
+               return DWARF_CB_ABORT;
        }
-       return 0;
+       return DWARF_CB_OK;
 }
 
-static void find_line_range_by_func(struct line_finder *lf)
+static int find_line_range_by_func(struct line_finder *lf)
 {
-       dwarf_getfuncs(&lf->cu_die, line_range_search_cb, lf, 0);
+       struct dwarf_callback_param param = {.data = (void *)lf, .retval = 0};
+       dwarf_getfuncs(&lf->cu_die, line_range_search_cb, &param, 0);
+       return param.retval;
 }
 
 int find_line_range(int fd, struct line_range *lr)
 {
        struct line_finder lf = {.lr = lr, .found = 0};
-       int ret;
+       int ret = 0;
        Dwarf_Off off = 0, noff;
        size_t cuhl;
        Dwarf_Die *diep;
        Dwarf *dbg;
 
        dbg = dwarf_begin(fd, DWARF_C_READ);
-       if (!dbg)
-               return -ENOENT;
+       if (!dbg) {
+               pr_warning("No dwarf info found in the vmlinux - "
+                       "please rebuild with CONFIG_DEBUG_INFO=y.\n");
+               return -EBADF;
+       }
 
        /* Loop on CUs (Compilation Unit) */
-       while (!lf.found) {
-               ret = dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL);
-               if (ret != 0)
+       while (!lf.found && ret >= 0) {
+               if (dwarf_nextcu(dbg, off, &noff, &cuhl, NULL, NULL, NULL) != 0)
                        break;
 
                /* Get the DIE(Debugging Information Entry) of this CU */
@@ -810,20 +1276,18 @@ int find_line_range(int fd, struct line_range *lr)
 
                if (!lr->file || lf.fname) {
                        if (lr->function)
-                               find_line_range_by_func(&lf);
+                               ret = find_line_range_by_func(&lf);
                        else {
                                lf.lno_s = lr->start;
-                               if (!lr->end)
-                                       lf.lno_e = INT_MAX;
-                               else
-                                       lf.lno_e = lr->end;
-                               find_line_range_by_line(NULL, &lf);
+                               lf.lno_e = lr->end;
+                               ret = find_line_range_by_line(NULL, &lf);
                        }
                }
                off = noff;
        }
        pr_debug("path: %lx\n", (unsigned long)lr->path);
        dwarf_end(dbg);
-       return lf.found;
+
+       return (ret < 0) ? ret : lf.found;
 }
 
index 21f7354..66f1980 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <stdbool.h>
 #include "util.h"
+#include "probe-event.h"
 
 #define MAX_PATH_LEN            256
 #define MAX_PROBE_BUFFER       1024
@@ -14,67 +15,39 @@ static inline int is_c_varname(const char *name)
        return isalpha(name[0]) || name[0] == '_';
 }
 
-struct probe_point {
-       char                    *event;                 /* Event name */
-       char                    *group;                 /* Event group */
+#ifdef DWARF_SUPPORT
+/* Find kprobe_trace_events specified by perf_probe_event from debuginfo */
+extern int find_kprobe_trace_events(int fd, struct perf_probe_event *pev,
+                                   struct kprobe_trace_event **tevs,
+                                   int max_tevs);
 
-       /* Inputs */
-       char                    *file;                  /* File name */
-       int                     line;                   /* Line number */
-       char                    *lazy_line;             /* Lazy line pattern */
+/* Find a perf_probe_point from debuginfo */
+extern int find_perf_probe_point(int fd, unsigned long addr,
+                                struct perf_probe_point *ppt);
 
-       char                    *function;              /* Function name */
-       int                     offset;                 /* Offset bytes */
-
-       int                     nr_args;                /* Number of arguments */
-       char                    **args;                 /* Arguments */
-
-       int                     retprobe;               /* Return probe */
-
-       /* Output */
-       int                     found;                  /* Number of found probe points */
-       char                    *probes[MAX_PROBES];    /* Output buffers (will be allocated)*/
-};
-
-/* Line number container */
-struct line_node {
-       struct list_head        list;
-       unsigned int            line;
-};
-
-/* Line range */
-struct line_range {
-       char                    *file;                  /* File name */
-       char                    *function;              /* Function name */
-       unsigned int            start;                  /* Start line number */
-       unsigned int            end;                    /* End line number */
-       int                     offset;                 /* Start line offset */
-       char                    *path;                  /* Real path name */
-       struct list_head        line_list;              /* Visible lines */
-};
-
-#ifndef NO_DWARF_SUPPORT
-extern int find_probe_point(int fd, struct probe_point *pp);
 extern int find_line_range(int fd, struct line_range *lr);
 
 #include <dwarf.h>
 #include <libdw.h>
 
 struct probe_finder {
-       struct probe_point      *pp;            /* Target probe point */
+       struct perf_probe_event *pev;           /* Target probe event */
+       struct kprobe_trace_event *tevs;        /* Result trace events */
+       int                     ntevs;          /* Number of trace events */
+       int                     max_tevs;       /* Max number of trace events */
 
        /* For function searching */
-       Dwarf_Addr              addr;           /* Address */
-       const char              *fname;         /* File name */
        int                     lno;            /* Line number */
+       Dwarf_Addr              addr;           /* Address */
+       const char              *fname;         /* Real file name */
        Dwarf_Die               cu_die;         /* Current CU */
+       struct list_head        lcache;         /* Line cache for lazy match */
 
        /* For variable searching */
+       Dwarf_CFI               *cfi;           /* Call Frame Information */
        Dwarf_Op                *fb_ops;        /* Frame base attribute */
-       const char              *var;           /* Current variable name */
-       char                    *buf;           /* Current output buffer */
-       int                     len;            /* Length of output buffer */
-       struct list_head        lcache;         /* Line cache for lazy match */
+       struct perf_probe_arg   *pvar;          /* Current target variable */
+       struct kprobe_trace_arg *tvar;          /* Current result variable */
 };
 
 struct line_finder {
@@ -87,6 +60,6 @@ struct line_finder {
        int                     found;
 };
 
-#endif /* NO_DWARF_SUPPORT */
+#endif /* DWARF_SUPPORT */
 
 #endif /*_PROBE_FINDER_H */
diff --git a/tools/perf/util/pstack.c b/tools/perf/util/pstack.c
new file mode 100644 (file)
index 0000000..13d36fa
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Simple pointer stack
+ *
+ * (c) 2010 Arnaldo Carvalho de Melo <acme@redhat.com>
+ */
+
+#include "util.h"
+#include "pstack.h"
+#include <linux/kernel.h>
+#include <stdlib.h>
+
+struct pstack {
+       unsigned short  top;
+       unsigned short  max_nr_entries;
+       void            *entries[0];
+};
+
+struct pstack *pstack__new(unsigned short max_nr_entries)
+{
+       struct pstack *self = zalloc((sizeof(*self) +
+                                    max_nr_entries * sizeof(void *)));
+       if (self != NULL)
+               self->max_nr_entries = max_nr_entries;
+       return self;
+}
+
+void pstack__delete(struct pstack *self)
+{
+       free(self);
+}
+
+bool pstack__empty(const struct pstack *self)
+{
+       return self->top == 0;
+}
+
+void pstack__remove(struct pstack *self, void *key)
+{
+       unsigned short i = self->top, last_index = self->top - 1;
+
+       while (i-- != 0) {
+               if (self->entries[i] == key) {
+                       if (i < last_index)
+                               memmove(self->entries + i,
+                                       self->entries + i + 1,
+                                       (last_index - i) * sizeof(void *));
+                       --self->top;
+                       return;
+               }
+       }
+       pr_err("%s: %p not on the pstack!\n", __func__, key);
+}
+
+void pstack__push(struct pstack *self, void *key)
+{
+       if (self->top == self->max_nr_entries) {
+               pr_err("%s: top=%d, overflow!\n", __func__, self->top);
+               return;
+       }
+       self->entries[self->top++] = key;
+}
+
+void *pstack__pop(struct pstack *self)
+{
+       void *ret;
+
+       if (self->top == 0) {
+               pr_err("%s: underflow!\n", __func__);
+               return NULL;
+       }
+
+       ret = self->entries[--self->top];
+       self->entries[self->top] = NULL;
+       return ret;
+}
diff --git a/tools/perf/util/pstack.h b/tools/perf/util/pstack.h
new file mode 100644 (file)
index 0000000..5ad0702
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _PERF_PSTACK_
+#define _PERF_PSTACK_
+
+struct pstack;
+struct pstack *pstack__new(unsigned short max_nr_entries);
+void pstack__delete(struct pstack *self);
+bool pstack__empty(const struct pstack *self);
+void pstack__remove(struct pstack *self, void *key);
+void pstack__push(struct pstack *self, void *key);
+void *pstack__pop(struct pstack *self);
+
+#endif /* _PERF_PSTACK_ */
index 5376378..b059dc5 100644 (file)
@@ -371,7 +371,6 @@ static int perl_start_script(const char *script, int argc, const char **argv)
        run_start_sub();
 
        free(command_line);
-       fprintf(stderr, "perf trace started with Perl script %s\n\n", script);
        return 0;
 error:
        perl_free(my_perl);
@@ -394,8 +393,6 @@ static int perl_stop_script(void)
        perl_destruct(my_perl);
        perl_free(my_perl);
 
-       fprintf(stderr, "\nperf trace Perl script stopped\n");
-
        return 0;
 }
 
index 6a72f14..81f39ca 100644 (file)
@@ -374,8 +374,6 @@ static int python_start_script(const char *script, int argc, const char **argv)
        }
 
        free(command_line);
-       fprintf(stderr, "perf trace started with Python script %s\n\n",
-               script);
 
        return err;
 error:
@@ -407,8 +405,6 @@ out:
        Py_XDECREF(main_module);
        Py_Finalize();
 
-       fprintf(stderr, "\nperf trace Python script stopped\n");
-
        return err;
 }
 
index eed1cb8..25bfca4 100644 (file)
@@ -14,6 +14,16 @@ static int perf_session__open(struct perf_session *self, bool force)
 {
        struct stat input_stat;
 
+       if (!strcmp(self->filename, "-")) {
+               self->fd_pipe = true;
+               self->fd = STDIN_FILENO;
+
+               if (perf_header__read(self, self->fd) < 0)
+                       pr_err("incompatible file format");
+
+               return 0;
+       }
+
        self->fd = open(self->filename, O_RDONLY);
        if (self->fd < 0) {
                pr_err("failed to open file: %s", self->filename);
@@ -38,7 +48,7 @@ static int perf_session__open(struct perf_session *self, bool force)
                goto out_close;
        }
 
-       if (perf_header__read(&self->header, self->fd) < 0) {
+       if (perf_header__read(self, self->fd) < 0) {
                pr_err("incompatible file format");
                goto out_close;
        }
@@ -52,12 +62,21 @@ out_close:
        return -1;
 }
 
-static inline int perf_session__create_kernel_maps(struct perf_session *self)
+void perf_session__update_sample_type(struct perf_session *self)
+{
+       self->sample_type = perf_header__sample_type(&self->header);
+}
+
+int perf_session__create_kernel_maps(struct perf_session *self)
 {
-       return map_groups__create_kernel_maps(&self->kmaps, self->vmlinux_maps);
+       int ret = machine__create_kernel_maps(&self->host_machine);
+
+       if (ret >= 0)
+               ret = machines__create_guest_kernel_maps(&self->machines);
+       return ret;
 }
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force)
+struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe)
 {
        size_t len = filename ? strlen(filename) + 1 : 0;
        struct perf_session *self = zalloc(sizeof(*self) + len);
@@ -70,13 +89,15 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
 
        memcpy(self->filename, filename, len);
        self->threads = RB_ROOT;
-       self->stats_by_id = RB_ROOT;
+       self->hists_tree = RB_ROOT;
        self->last_match = NULL;
        self->mmap_window = 32;
        self->cwd = NULL;
        self->cwdlen = 0;
-       self->unknown_events = 0;
-       map_groups__init(&self->kmaps);
+       self->machines = RB_ROOT;
+       self->repipe = repipe;
+       INIT_LIST_HEAD(&self->ordered_samples.samples_head);
+       machine__init(&self->host_machine, "", HOST_KERNEL_ID);
 
        if (mode == O_RDONLY) {
                if (perf_session__open(self, force) < 0)
@@ -90,7 +111,7 @@ struct perf_session *perf_session__new(const char *filename, int mode, bool forc
                        goto out_delete;
        }
 
-       self->sample_type = perf_header__sample_type(&self->header);
+       perf_session__update_sample_type(self);
 out:
        return self;
 out_free:
@@ -117,22 +138,17 @@ static bool symbol__match_parent_regex(struct symbol *sym)
        return 0;
 }
 
-struct symbol **perf_session__resolve_callchain(struct perf_session *self,
-                                               struct thread *thread,
-                                               struct ip_callchain *chain,
-                                               struct symbol **parent)
+struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
+                                                  struct thread *thread,
+                                                  struct ip_callchain *chain,
+                                                  struct symbol **parent)
 {
        u8 cpumode = PERF_RECORD_MISC_USER;
-       struct symbol **syms = NULL;
        unsigned int i;
+       struct map_symbol *syms = calloc(chain->nr, sizeof(*syms));
 
-       if (symbol_conf.use_callchain) {
-               syms = calloc(chain->nr, sizeof(*syms));
-               if (!syms) {
-                       fprintf(stderr, "Can't allocate memory for symbols\n");
-                       exit(-1);
-               }
-       }
+       if (!syms)
+               return NULL;
 
        for (i = 0; i < chain->nr; i++) {
                u64 ip = chain->ips[i];
@@ -152,15 +168,17 @@ struct symbol **perf_session__resolve_callchain(struct perf_session *self,
                        continue;
                }
 
+               al.filtered = false;
                thread__find_addr_location(thread, self, cpumode,
-                                          MAP__FUNCTION, ip, &al, NULL);
+                               MAP__FUNCTION, thread->pid, ip, &al, NULL);
                if (al.sym != NULL) {
                        if (sort__has_parent && !*parent &&
                            symbol__match_parent_regex(al.sym))
                                *parent = al.sym;
                        if (!symbol_conf.use_callchain)
                                break;
-                       syms[i] = al.sym;
+                       syms[i].map = al.map;
+                       syms[i].sym = al.sym;
                }
        }
 
@@ -174,6 +192,18 @@ static int process_event_stub(event_t *event __used,
        return 0;
 }
 
+static int process_finished_round_stub(event_t *event __used,
+                                      struct perf_session *session __used,
+                                      struct perf_event_ops *ops __used)
+{
+       dump_printf(": unhandled!\n");
+       return 0;
+}
+
+static int process_finished_round(event_t *event,
+                                 struct perf_session *session,
+                                 struct perf_event_ops *ops);
+
 static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
 {
        if (handler->sample == NULL)
@@ -194,29 +224,20 @@ static void perf_event_ops__fill_defaults(struct perf_event_ops *handler)
                handler->throttle = process_event_stub;
        if (handler->unthrottle == NULL)
                handler->unthrottle = process_event_stub;
-}
-
-static const char *event__name[] = {
-       [0]                      = "TOTAL",
-       [PERF_RECORD_MMAP]       = "MMAP",
-       [PERF_RECORD_LOST]       = "LOST",
-       [PERF_RECORD_COMM]       = "COMM",
-       [PERF_RECORD_EXIT]       = "EXIT",
-       [PERF_RECORD_THROTTLE]   = "THROTTLE",
-       [PERF_RECORD_UNTHROTTLE] = "UNTHROTTLE",
-       [PERF_RECORD_FORK]       = "FORK",
-       [PERF_RECORD_READ]       = "READ",
-       [PERF_RECORD_SAMPLE]     = "SAMPLE",
-};
-
-unsigned long event__total[PERF_RECORD_MAX];
-
-void event__print_totals(void)
-{
-       int i;
-       for (i = 0; i < PERF_RECORD_MAX; ++i)
-               pr_info("%10s events: %10ld\n",
-                       event__name[i], event__total[i]);
+       if (handler->attr == NULL)
+               handler->attr = process_event_stub;
+       if (handler->event_type == NULL)
+               handler->event_type = process_event_stub;
+       if (handler->tracing_data == NULL)
+               handler->tracing_data = process_event_stub;
+       if (handler->build_id == NULL)
+               handler->build_id = process_event_stub;
+       if (handler->finished_round == NULL) {
+               if (handler->ordered_samples)
+                       handler->finished_round = process_finished_round;
+               else
+                       handler->finished_round = process_finished_round_stub;
+       }
 }
 
 void mem_bswap_64(void *src, int byte_size)
@@ -270,6 +291,37 @@ static void event__read_swap(event_t *self)
        self->read.id           = bswap_64(self->read.id);
 }
 
+static void event__attr_swap(event_t *self)
+{
+       size_t size;
+
+       self->attr.attr.type            = bswap_32(self->attr.attr.type);
+       self->attr.attr.size            = bswap_32(self->attr.attr.size);
+       self->attr.attr.config          = bswap_64(self->attr.attr.config);
+       self->attr.attr.sample_period   = bswap_64(self->attr.attr.sample_period);
+       self->attr.attr.sample_type     = bswap_64(self->attr.attr.sample_type);
+       self->attr.attr.read_format     = bswap_64(self->attr.attr.read_format);
+       self->attr.attr.wakeup_events   = bswap_32(self->attr.attr.wakeup_events);
+       self->attr.attr.bp_type         = bswap_32(self->attr.attr.bp_type);
+       self->attr.attr.bp_addr         = bswap_64(self->attr.attr.bp_addr);
+       self->attr.attr.bp_len          = bswap_64(self->attr.attr.bp_len);
+
+       size = self->header.size;
+       size -= (void *)&self->attr.id - (void *)self;
+       mem_bswap_64(self->attr.id, size);
+}
+
+static void event__event_type_swap(event_t *self)
+{
+       self->event_type.event_type.event_id =
+               bswap_64(self->event_type.event_type.event_id);
+}
+
+static void event__tracing_data_swap(event_t *self)
+{
+       self->tracing_data.size = bswap_32(self->tracing_data.size);
+}
+
 typedef void (*event__swap_op)(event_t *self);
 
 static event__swap_op event__swap_ops[] = {
@@ -280,9 +332,212 @@ static event__swap_op event__swap_ops[] = {
        [PERF_RECORD_LOST]   = event__all64_swap,
        [PERF_RECORD_READ]   = event__read_swap,
        [PERF_RECORD_SAMPLE] = event__all64_swap,
-       [PERF_RECORD_MAX]    = NULL,
+       [PERF_RECORD_HEADER_ATTR]   = event__attr_swap,
+       [PERF_RECORD_HEADER_EVENT_TYPE]   = event__event_type_swap,
+       [PERF_RECORD_HEADER_TRACING_DATA]   = event__tracing_data_swap,
+       [PERF_RECORD_HEADER_BUILD_ID]   = NULL,
+       [PERF_RECORD_HEADER_MAX]    = NULL,
 };
 
+struct sample_queue {
+       u64                     timestamp;
+       struct sample_event     *event;
+       struct list_head        list;
+};
+
+static void flush_sample_queue(struct perf_session *s,
+                              struct perf_event_ops *ops)
+{
+       struct list_head *head = &s->ordered_samples.samples_head;
+       u64 limit = s->ordered_samples.next_flush;
+       struct sample_queue *tmp, *iter;
+
+       if (!ops->ordered_samples || !limit)
+               return;
+
+       list_for_each_entry_safe(iter, tmp, head, list) {
+               if (iter->timestamp > limit)
+                       return;
+
+               if (iter == s->ordered_samples.last_inserted)
+                       s->ordered_samples.last_inserted = NULL;
+
+               ops->sample((event_t *)iter->event, s);
+
+               s->ordered_samples.last_flush = iter->timestamp;
+               list_del(&iter->list);
+               free(iter->event);
+               free(iter);
+       }
+}
+
+/*
+ * When perf record finishes a pass on every buffers, it records this pseudo
+ * event.
+ * We record the max timestamp t found in the pass n.
+ * Assuming these timestamps are monotonic across cpus, we know that if
+ * a buffer still has events with timestamps below t, they will be all
+ * available and then read in the pass n + 1.
+ * Hence when we start to read the pass n + 2, we can safely flush every
+ * events with timestamps below t.
+ *
+ *    ============ PASS n =================
+ *       CPU 0         |   CPU 1
+ *                     |
+ *    cnt1 timestamps  |   cnt2 timestamps
+ *          1          |         2
+ *          2          |         3
+ *          -          |         4  <--- max recorded
+ *
+ *    ============ PASS n + 1 ==============
+ *       CPU 0         |   CPU 1
+ *                     |
+ *    cnt1 timestamps  |   cnt2 timestamps
+ *          3          |         5
+ *          4          |         6
+ *          5          |         7 <---- max recorded
+ *
+ *      Flush every events below timestamp 4
+ *
+ *    ============ PASS n + 2 ==============
+ *       CPU 0         |   CPU 1
+ *                     |
+ *    cnt1 timestamps  |   cnt2 timestamps
+ *          6          |         8
+ *          7          |         9
+ *          -          |         10
+ *
+ *      Flush every events below timestamp 7
+ *      etc...
+ */
+static int process_finished_round(event_t *event __used,
+                                 struct perf_session *session,
+                                 struct perf_event_ops *ops)
+{
+       flush_sample_queue(session, ops);
+       session->ordered_samples.next_flush = session->ordered_samples.max_timestamp;
+
+       return 0;
+}
+
+static void __queue_sample_end(struct sample_queue *new, struct list_head *head)
+{
+       struct sample_queue *iter;
+
+       list_for_each_entry_reverse(iter, head, list) {
+               if (iter->timestamp < new->timestamp) {
+                       list_add(&new->list, &iter->list);
+                       return;
+               }
+       }
+
+       list_add(&new->list, head);
+}
+
+static void __queue_sample_before(struct sample_queue *new,
+                                 struct sample_queue *iter,
+                                 struct list_head *head)
+{
+       list_for_each_entry_continue_reverse(iter, head, list) {
+               if (iter->timestamp < new->timestamp) {
+                       list_add(&new->list, &iter->list);
+                       return;
+               }
+       }
+
+       list_add(&new->list, head);
+}
+
+static void __queue_sample_after(struct sample_queue *new,
+                                struct sample_queue *iter,
+                                struct list_head *head)
+{
+       list_for_each_entry_continue(iter, head, list) {
+               if (iter->timestamp > new->timestamp) {
+                       list_add_tail(&new->list, &iter->list);
+                       return;
+               }
+       }
+       list_add_tail(&new->list, head);
+}
+
+/* The queue is ordered by time */
+static void __queue_sample_event(struct sample_queue *new,
+                                struct perf_session *s)
+{
+       struct sample_queue *last_inserted = s->ordered_samples.last_inserted;
+       struct list_head *head = &s->ordered_samples.samples_head;
+
+
+       if (!last_inserted) {
+               __queue_sample_end(new, head);
+               return;
+       }
+
+       /*
+        * Most of the time the current event has a timestamp
+        * very close to the last event inserted, unless we just switched
+        * to another event buffer. Having a sorting based on a list and
+        * on the last inserted event that is close to the current one is
+        * probably more efficient than an rbtree based sorting.
+        */
+       if (last_inserted->timestamp >= new->timestamp)
+               __queue_sample_before(new, last_inserted, head);
+       else
+               __queue_sample_after(new, last_inserted, head);
+}
+
+static int queue_sample_event(event_t *event, struct sample_data *data,
+                             struct perf_session *s)
+{
+       u64 timestamp = data->time;
+       struct sample_queue *new;
+
+
+       if (timestamp < s->ordered_samples.last_flush) {
+               printf("Warning: Timestamp below last timeslice flush\n");
+               return -EINVAL;
+       }
+
+       new = malloc(sizeof(*new));
+       if (!new)
+               return -ENOMEM;
+
+       new->timestamp = timestamp;
+
+       new->event = malloc(event->header.size);
+       if (!new->event) {
+               free(new);
+               return -ENOMEM;
+       }
+
+       memcpy(new->event, event, event->header.size);
+
+       __queue_sample_event(new, s);
+       s->ordered_samples.last_inserted = new;
+
+       if (new->timestamp > s->ordered_samples.max_timestamp)
+               s->ordered_samples.max_timestamp = new->timestamp;
+
+       return 0;
+}
+
+static int perf_session__process_sample(event_t *event, struct perf_session *s,
+                                       struct perf_event_ops *ops)
+{
+       struct sample_data data;
+
+       if (!ops->ordered_samples)
+               return ops->sample(event, s);
+
+       bzero(&data, sizeof(struct sample_data));
+       event__parse_sample(event, s->sample_type, &data);
+
+       queue_sample_event(event, &data, s);
+
+       return 0;
+}
+
 static int perf_session__process_event(struct perf_session *self,
                                       event_t *event,
                                       struct perf_event_ops *ops,
@@ -290,12 +545,11 @@ static int perf_session__process_event(struct perf_session *self,
 {
        trace_event(event);
 
-       if (event->header.type < PERF_RECORD_MAX) {
+       if (event->header.type < PERF_RECORD_HEADER_MAX) {
                dump_printf("%#Lx [%#x]: PERF_RECORD_%s",
                            offset + head, event->header.size,
                            event__name[event->header.type]);
-               ++event__total[0];
-               ++event__total[event->header.type];
+               hists__inc_nr_events(&self->hists, event->header.type);
        }
 
        if (self->header.needs_swap && event__swap_ops[event->header.type])
@@ -303,7 +557,7 @@ static int perf_session__process_event(struct perf_session *self,
 
        switch (event->header.type) {
        case PERF_RECORD_SAMPLE:
-               return ops->sample(event, self);
+               return perf_session__process_sample(event, self, ops);
        case PERF_RECORD_MMAP:
                return ops->mmap(event, self);
        case PERF_RECORD_COMM:
@@ -320,8 +574,20 @@ static int perf_session__process_event(struct perf_session *self,
                return ops->throttle(event, self);
        case PERF_RECORD_UNTHROTTLE:
                return ops->unthrottle(event, self);
+       case PERF_RECORD_HEADER_ATTR:
+               return ops->attr(event, self);
+       case PERF_RECORD_HEADER_EVENT_TYPE:
+               return ops->event_type(event, self);
+       case PERF_RECORD_HEADER_TRACING_DATA:
+               /* setup for reading amidst mmap */
+               lseek(self->fd, offset + head, SEEK_SET);
+               return ops->tracing_data(event, self);
+       case PERF_RECORD_HEADER_BUILD_ID:
+               return ops->build_id(event, self);
+       case PERF_RECORD_FINISHED_ROUND:
+               return ops->finished_round(event, self, ops);
        default:
-               self->unknown_events++;
+               ++self->hists.stats.nr_unknown_events;
                return -1;
        }
 }
@@ -333,56 +599,114 @@ void perf_event_header__bswap(struct perf_event_header *self)
        self->size = bswap_16(self->size);
 }
 
-int perf_header__read_build_ids(struct perf_header *self,
-                               int input, u64 offset, u64 size)
+static struct thread *perf_session__register_idle_thread(struct perf_session *self)
 {
-       struct build_id_event bev;
-       char filename[PATH_MAX];
-       u64 limit = offset + size;
-       int err = -1;
-
-       while (offset < limit) {
-               struct dso *dso;
-               ssize_t len;
-               struct list_head *head = &dsos__user;
+       struct thread *thread = perf_session__findnew(self, 0);
 
-               if (read(input, &bev, sizeof(bev)) != sizeof(bev))
-                       goto out;
+       if (thread == NULL || thread__set_comm(thread, "swapper")) {
+               pr_err("problem inserting idle task.\n");
+               thread = NULL;
+       }
 
-               if (self->needs_swap)
-                       perf_event_header__bswap(&bev.header);
+       return thread;
+}
 
-               len = bev.header.size - sizeof(bev);
-               if (read(input, filename, len) != len)
-                       goto out;
+int do_read(int fd, void *buf, size_t size)
+{
+       void *buf_start = buf;
 
-               if (bev.header.misc & PERF_RECORD_MISC_KERNEL)
-                       head = &dsos__kernel;
+       while (size) {
+               int ret = read(fd, buf, size);
 
-               dso = __dsos__findnew(head, filename);
-               if (dso != NULL) {
-                       dso__set_build_id(dso, &bev.build_id);
-                       if (head == &dsos__kernel && filename[0] == '[')
-                               dso->kernel = 1;
-               }
+               if (ret <= 0)
+                       return ret;
 
-               offset += bev.header.size;
+               size -= ret;
+               buf += ret;
        }
-       err = 0;
-out:
-       return err;
+
+       return buf - buf_start;
 }
 
-static struct thread *perf_session__register_idle_thread(struct perf_session *self)
+#define session_done() (*(volatile int *)(&session_done))
+volatile int session_done;
+
+static int __perf_session__process_pipe_events(struct perf_session *self,
+                                              struct perf_event_ops *ops)
 {
-       struct thread *thread = perf_session__findnew(self, 0);
+       event_t event;
+       uint32_t size;
+       int skip = 0;
+       u64 head;
+       int err;
+       void *p;
 
-       if (thread == NULL || thread__set_comm(thread, "swapper")) {
-               pr_err("problem inserting idle task.\n");
-               thread = NULL;
+       perf_event_ops__fill_defaults(ops);
+
+       head = 0;
+more:
+       err = do_read(self->fd, &event, sizeof(struct perf_event_header));
+       if (err <= 0) {
+               if (err == 0)
+                       goto done;
+
+               pr_err("failed to read event header\n");
+               goto out_err;
        }
 
-       return thread;
+       if (self->header.needs_swap)
+               perf_event_header__bswap(&event.header);
+
+       size = event.header.size;
+       if (size == 0)
+               size = 8;
+
+       p = &event;
+       p += sizeof(struct perf_event_header);
+
+       if (size - sizeof(struct perf_event_header)) {
+               err = do_read(self->fd, p,
+                             size - sizeof(struct perf_event_header));
+               if (err <= 0) {
+                       if (err == 0) {
+                               pr_err("unexpected end of event stream\n");
+                               goto done;
+                       }
+
+                       pr_err("failed to read event data\n");
+                       goto out_err;
+               }
+       }
+
+       if (size == 0 ||
+           (skip = perf_session__process_event(self, &event, ops,
+                                               0, head)) < 0) {
+               dump_printf("%#Lx [%#x]: skipping unknown header type: %d\n",
+                           head, event.header.size, event.header.type);
+               /*
+                * assume we lost track of the stream, check alignment, and
+                * increment a single u64 in the hope to catch on again 'soon'.
+                */
+               if (unlikely(head & 7))
+                       head &= ~7ULL;
+
+               size = 8;
+       }
+
+       head += size;
+
+       dump_printf("\n%#Lx [%#x]: event: %d\n",
+                   head, event.header.size, event.header.type);
+
+       if (skip > 0)
+               head += skip;
+
+       if (!session_done())
+               goto more;
+done:
+       err = 0;
+out_err:
+       return err;
 }
 
 int __perf_session__process_events(struct perf_session *self,
@@ -396,6 +720,10 @@ int __perf_session__process_events(struct perf_session *self,
        event_t *event;
        uint32_t size;
        char *buf;
+       struct ui_progress *progress = ui_progress__new("Processing events...",
+                                                       self->size);
+       if (progress == NULL)
+               return -1;
 
        perf_event_ops__fill_defaults(ops);
 
@@ -424,6 +752,7 @@ remap:
 
 more:
        event = (event_t *)(buf + head);
+       ui_progress__update(progress, offset);
 
        if (self->header.needs_swap)
                perf_event_header__bswap(&event->header);
@@ -473,7 +802,11 @@ more:
                goto more;
 done:
        err = 0;
+       /* do the final flush for ordered samples */
+       self->ordered_samples.next_flush = ULLONG_MAX;
+       flush_sample_queue(self, ops);
 out_err:
+       ui_progress__delete(progress);
        return err;
 }
 
@@ -502,9 +835,13 @@ out_getcwd_err:
                self->cwdlen = strlen(self->cwd);
        }
 
-       err = __perf_session__process_events(self, self->header.data_offset,
-                                            self->header.data_size,
-                                            self->size, ops);
+       if (!self->fd_pipe)
+               err = __perf_session__process_events(self,
+                                                    self->header.data_offset,
+                                                    self->header.data_size,
+                                                    self->size, ops);
+       else
+               err = __perf_session__process_pipe_events(self, ops);
 out_err:
        return err;
 }
@@ -519,56 +856,41 @@ bool perf_session__has_traces(struct perf_session *self, const char *msg)
        return true;
 }
 
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
                                             const char *symbol_name,
                                             u64 addr)
 {
        char *bracket;
        enum map_type i;
+       struct ref_reloc_sym *ref;
 
-       self->ref_reloc_sym.name = strdup(symbol_name);
-       if (self->ref_reloc_sym.name == NULL)
+       ref = zalloc(sizeof(struct ref_reloc_sym));
+       if (ref == NULL)
                return -ENOMEM;
 
-       bracket = strchr(self->ref_reloc_sym.name, ']');
+       ref->name = strdup(symbol_name);
+       if (ref->name == NULL) {
+               free(ref);
+               return -ENOMEM;
+       }
+
+       bracket = strchr(ref->name, ']');
        if (bracket)
                *bracket = '\0';
 
-       self->ref_reloc_sym.addr = addr;
+       ref->addr = addr;
 
        for (i = 0; i < MAP__NR_TYPES; ++i) {
-               struct kmap *kmap = map__kmap(self->vmlinux_maps[i]);
-               kmap->ref_reloc_sym = &self->ref_reloc_sym;
+               struct kmap *kmap = map__kmap(maps[i]);
+               kmap->ref_reloc_sym = ref;
        }
 
        return 0;
 }
 
-static u64 map__reloc_map_ip(struct map *map, u64 ip)
-{
-       return ip + (s64)map->pgoff;
-}
-
-static u64 map__reloc_unmap_ip(struct map *map, u64 ip)
-{
-       return ip - (s64)map->pgoff;
-}
-
-void map__reloc_vmlinux(struct map *self)
+size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp)
 {
-       struct kmap *kmap = map__kmap(self);
-       s64 reloc;
-
-       if (!kmap->ref_reloc_sym || !kmap->ref_reloc_sym->unrelocated_addr)
-               return;
-
-       reloc = (kmap->ref_reloc_sym->unrelocated_addr -
-                kmap->ref_reloc_sym->addr);
-
-       if (!reloc)
-               return;
-
-       self->map_ip   = map__reloc_map_ip;
-       self->unmap_ip = map__reloc_unmap_ip;
-       self->pgoff    = reloc;
+       return __dsos__fprintf(&self->host_machine.kernel_dsos, fp) +
+              __dsos__fprintf(&self->host_machine.user_dsos, fp) +
+              machines__fprintf_dsos(&self->machines, fp);
 }
index 5c33417..e7fce48 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __PERF_SESSION_H
 #define __PERF_SESSION_H
 
+#include "hist.h"
 #include "event.h"
 #include "header.h"
 #include "symbol.h"
@@ -8,45 +9,69 @@
 #include <linux/rbtree.h>
 #include "../../../include/linux/perf_event.h"
 
+struct sample_queue;
 struct ip_callchain;
 struct thread;
 
+struct ordered_samples {
+       u64                     last_flush;
+       u64                     next_flush;
+       u64                     max_timestamp;
+       struct list_head        samples_head;
+       struct sample_queue     *last_inserted;
+};
+
 struct perf_session {
        struct perf_header      header;
        unsigned long           size;
        unsigned long           mmap_window;
-       struct map_groups       kmaps;
        struct rb_root          threads;
        struct thread           *last_match;
-       struct map              *vmlinux_maps[MAP__NR_TYPES];
-       struct events_stats     events_stats;
-       struct rb_root          stats_by_id;
-       unsigned long           event_total[PERF_RECORD_MAX];
-       unsigned long           unknown_events;
-       struct rb_root          hists;
+       struct machine          host_machine;
+       struct rb_root          machines;
+       struct rb_root          hists_tree;
+       /*
+        * FIXME: should point to the first entry in hists_tree and
+        *        be a hists instance. Right now its only 'report'
+        *        that is using ->hists_tree while all the rest use
+        *        ->hists.
+        */
+       struct hists            hists;
        u64                     sample_type;
-       struct ref_reloc_sym    ref_reloc_sym;
        int                     fd;
+       bool                    fd_pipe;
+       bool                    repipe;
        int                     cwdlen;
        char                    *cwd;
+       struct ordered_samples  ordered_samples;
        char filename[0];
 };
 
+struct perf_event_ops;
+
 typedef int (*event_op)(event_t *self, struct perf_session *session);
+typedef int (*event_op2)(event_t *self, struct perf_session *session,
+                        struct perf_event_ops *ops);
 
 struct perf_event_ops {
-       event_op sample,
-                mmap,
-                comm,
-                fork,
-                exit,
-                lost,
-                read,
-                throttle,
-                unthrottle;
+       event_op        sample,
+                       mmap,
+                       comm,
+                       fork,
+                       exit,
+                       lost,
+                       read,
+                       throttle,
+                       unthrottle,
+                       attr,
+                       event_type,
+                       tracing_data,
+                       build_id;
+       event_op2       finished_round;
+       bool            ordered_samples;
 };
 
-struct perf_session *perf_session__new(const char *filename, int mode, bool force);
+struct perf_session *perf_session__new(const char *filename, int mode, bool force, bool repipe);
 void perf_session__delete(struct perf_session *self);
 
 void perf_event_header__bswap(struct perf_event_header *self);
@@ -57,33 +82,66 @@ int __perf_session__process_events(struct perf_session *self,
 int perf_session__process_events(struct perf_session *self,
                                 struct perf_event_ops *event_ops);
 
-struct symbol **perf_session__resolve_callchain(struct perf_session *self,
-                                               struct thread *thread,
-                                               struct ip_callchain *chain,
-                                               struct symbol **parent);
+struct map_symbol *perf_session__resolve_callchain(struct perf_session *self,
+                                                  struct thread *thread,
+                                                  struct ip_callchain *chain,
+                                                  struct symbol **parent);
 
 bool perf_session__has_traces(struct perf_session *self, const char *msg);
 
-int perf_header__read_build_ids(struct perf_header *self, int input,
-                               u64 offset, u64 file_size);
-
-int perf_session__set_kallsyms_ref_reloc_sym(struct perf_session *self,
+int perf_session__set_kallsyms_ref_reloc_sym(struct map **maps,
                                             const char *symbol_name,
                                             u64 addr);
 
 void mem_bswap_64(void *src, int byte_size);
 
-static inline int __perf_session__create_kernel_maps(struct perf_session *self,
-                                               struct dso *kernel)
+int perf_session__create_kernel_maps(struct perf_session *self);
+
+int do_read(int fd, void *buf, size_t size);
+void perf_session__update_sample_type(struct perf_session *self);
+
+static inline
+struct machine *perf_session__find_host_machine(struct perf_session *self)
+{
+       return &self->host_machine;
+}
+
+static inline
+struct machine *perf_session__find_machine(struct perf_session *self, pid_t pid)
+{
+       if (pid == HOST_KERNEL_ID)
+               return &self->host_machine;
+       return machines__find(&self->machines, pid);
+}
+
+static inline
+struct machine *perf_session__findnew_machine(struct perf_session *self, pid_t pid)
+{
+       if (pid == HOST_KERNEL_ID)
+               return &self->host_machine;
+       return machines__findnew(&self->machines, pid);
+}
+
+static inline
+void perf_session__process_machines(struct perf_session *self,
+                                   machine__process_t process)
+{
+       process(&self->host_machine, self);
+       return machines__process(&self->machines, process, self);
+}
+
+size_t perf_session__fprintf_dsos(struct perf_session *self, FILE *fp);
+
+static inline
+size_t perf_session__fprintf_dsos_buildid(struct perf_session *self, FILE *fp,
+                                         bool with_hits)
 {
-       return __map_groups__create_kernel_maps(&self->kmaps,
-                                               self->vmlinux_maps, kernel);
+       return machines__fprintf_dsos_buildid(&self->machines, fp, with_hits);
 }
 
-static inline struct map *
-       perf_session__new_module_map(struct perf_session *self,
-                                    u64 start, const char *filename)
+static inline
+size_t perf_session__fprintf_nr_events(struct perf_session *self, FILE *fp)
 {
-       return map_groups__new_module(&self->kmaps, start, filename);
+       return hists__fprintf_nr_events(&self->hists, fp);
 }
 #endif /* __PERF_SESSION_H */
index cb0f327..2316cb5 100644 (file)
@@ -1,10 +1,10 @@
 #include "sort.h"
 
 regex_t                parent_regex;
-char           default_parent_pattern[] = "^sys_|^do_page_fault";
-char           *parent_pattern = default_parent_pattern;
-char           default_sort_order[] = "comm,dso,symbol";
-char           *sort_order = default_sort_order;
+const char     default_parent_pattern[] = "^sys_|^do_page_fault";
+const char     *parent_pattern = default_parent_pattern;
+const char     default_sort_order[] = "comm,dso,symbol";
+const char     *sort_order = default_sort_order;
 int            sort__need_collapse = 0;
 int            sort__has_parent = 0;
 
@@ -18,39 +18,50 @@ char * field_sep;
 
 LIST_HEAD(hist_entry__sort_list);
 
+static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf,
+                                      size_t size, unsigned int width);
+static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf,
+                                    size_t size, unsigned int width);
+static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf,
+                                   size_t size, unsigned int width);
+static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
+                                   size_t size, unsigned int width);
+static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf,
+                                      size_t size, unsigned int width);
+
 struct sort_entry sort_thread = {
-       .header = "Command:  Pid",
-       .cmp    = sort__thread_cmp,
-       .print  = sort__thread_print,
-       .width  = &threads__col_width,
+       .se_header      = "Command:  Pid",
+       .se_cmp         = sort__thread_cmp,
+       .se_snprintf    = hist_entry__thread_snprintf,
+       .se_width       = &threads__col_width,
 };
 
 struct sort_entry sort_comm = {
-       .header         = "Command",
-       .cmp            = sort__comm_cmp,
-       .collapse       = sort__comm_collapse,
-       .print          = sort__comm_print,
-       .width          = &comms__col_width,
+       .se_header      = "Command",
+       .se_cmp         = sort__comm_cmp,
+       .se_collapse    = sort__comm_collapse,
+       .se_snprintf    = hist_entry__comm_snprintf,
+       .se_width       = &comms__col_width,
 };
 
 struct sort_entry sort_dso = {
-       .header = "Shared Object",
-       .cmp    = sort__dso_cmp,
-       .print  = sort__dso_print,
-       .width  = &dsos__col_width,
+       .se_header      = "Shared Object",
+       .se_cmp         = sort__dso_cmp,
+       .se_snprintf    = hist_entry__dso_snprintf,
+       .se_width       = &dsos__col_width,
 };
 
 struct sort_entry sort_sym = {
-       .header = "Symbol",
-       .cmp    = sort__sym_cmp,
-       .print  = sort__sym_print,
+       .se_header      = "Symbol",
+       .se_cmp         = sort__sym_cmp,
+       .se_snprintf    = hist_entry__sym_snprintf,
 };
 
 struct sort_entry sort_parent = {
-       .header = "Parent symbol",
-       .cmp    = sort__parent_cmp,
-       .print  = sort__parent_print,
-       .width  = &parent_symbol__col_width,
+       .se_header      = "Parent symbol",
+       .se_cmp         = sort__parent_cmp,
+       .se_snprintf    = hist_entry__parent_snprintf,
+       .se_width       = &parent_symbol__col_width,
 };
 
 struct sort_dimension {
@@ -85,45 +96,38 @@ sort__thread_cmp(struct hist_entry *left, struct hist_entry *right)
        return right->thread->pid - left->thread->pid;
 }
 
-int repsep_fprintf(FILE *fp, const char *fmt, ...)
+static int repsep_snprintf(char *bf, size_t size, const char *fmt, ...)
 {
        int n;
        va_list ap;
 
        va_start(ap, fmt);
-       if (!field_sep)
-               n = vfprintf(fp, fmt, ap);
-       else {
-               char *bf = NULL;
-               n = vasprintf(&bf, fmt, ap);
-               if (n > 0) {
-                       char *sep = bf;
-
-                       while (1) {
-                               sep = strchr(sep, *field_sep);
-                               if (sep == NULL)
-                                       break;
-                               *sep = '.';
-                       }
+       n = vsnprintf(bf, size, fmt, ap);
+       if (field_sep && n > 0) {
+               char *sep = bf;
+
+               while (1) {
+                       sep = strchr(sep, *field_sep);
+                       if (sep == NULL)
+                               break;
+                       *sep = '.';
                }
-               fputs(bf, fp);
-               free(bf);
        }
        va_end(ap);
        return n;
 }
 
-size_t
-sort__thread_print(FILE *fp, struct hist_entry *self, unsigned int width)
+static int hist_entry__thread_snprintf(struct hist_entry *self, char *bf,
+                                      size_t size, unsigned int width)
 {
-       return repsep_fprintf(fp, "%*s:%5d", width - 6,
+       return repsep_snprintf(bf, size, "%*s:%5d", width,
                              self->thread->comm ?: "", self->thread->pid);
 }
 
-size_t
-sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width)
+static int hist_entry__comm_snprintf(struct hist_entry *self, char *bf,
+                                    size_t size, unsigned int width)
 {
-       return repsep_fprintf(fp, "%*s", width, self->thread->comm);
+       return repsep_snprintf(bf, size, "%*s", width, self->thread->comm);
 }
 
 /* --sort dso */
@@ -131,8 +135,8 @@ sort__comm_print(FILE *fp, struct hist_entry *self, unsigned int width)
 int64_t
 sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
 {
-       struct dso *dso_l = left->map ? left->map->dso : NULL;
-       struct dso *dso_r = right->map ? right->map->dso : NULL;
+       struct dso *dso_l = left->ms.map ? left->ms.map->dso : NULL;
+       struct dso *dso_r = right->ms.map ? right->ms.map->dso : NULL;
        const char *dso_name_l, *dso_name_r;
 
        if (!dso_l || !dso_r)
@@ -149,16 +153,16 @@ sort__dso_cmp(struct hist_entry *left, struct hist_entry *right)
        return strcmp(dso_name_l, dso_name_r);
 }
 
-size_t
-sort__dso_print(FILE *fp, struct hist_entry *self, unsigned int width)
+static int hist_entry__dso_snprintf(struct hist_entry *self, char *bf,
+                                   size_t size, unsigned int width)
 {
-       if (self->map && self->map->dso) {
-               const char *dso_name = !verbose ? self->map->dso->short_name :
-                                                 self->map->dso->long_name;
-               return repsep_fprintf(fp, "%-*s", width, dso_name);
+       if (self->ms.map && self->ms.map->dso) {
+               const char *dso_name = !verbose ? self->ms.map->dso->short_name :
+                                                 self->ms.map->dso->long_name;
+               return repsep_snprintf(bf, size, "%-*s", width, dso_name);
        }
 
-       return repsep_fprintf(fp, "%*llx", width, (u64)self->ip);
+       return repsep_snprintf(bf, size, "%*Lx", width, self->ip);
 }
 
 /* --sort symbol */
@@ -168,31 +172,31 @@ sort__sym_cmp(struct hist_entry *left, struct hist_entry *right)
 {
        u64 ip_l, ip_r;
 
-       if (left->sym == right->sym)
+       if (left->ms.sym == right->ms.sym)
                return 0;
 
-       ip_l = left->sym ? left->sym->start : left->ip;
-       ip_r = right->sym ? right->sym->start : right->ip;
+       ip_l = left->ms.sym ? left->ms.sym->start : left->ip;
+       ip_r = right->ms.sym ? right->ms.sym->start : right->ip;
 
        return (int64_t)(ip_r - ip_l);
 }
 
-
-size_t
-sort__sym_print(FILE *fp, struct hist_entry *self, unsigned int width __used)
+static int hist_entry__sym_snprintf(struct hist_entry *self, char *bf,
+                                   size_t size, unsigned int width __used)
 {
        size_t ret = 0;
 
        if (verbose) {
-               char o = self->map ? dso__symtab_origin(self->map->dso) : '!';
-               ret += repsep_fprintf(fp, "%#018llx %c ", (u64)self->ip, o);
+               char o = self->ms.map ? dso__symtab_origin(self->ms.map->dso) : '!';
+               ret += repsep_snprintf(bf, size, "%#018llx %c ", self->ip, o);
        }
 
-       ret += repsep_fprintf(fp, "[%c] ", self->level);
-       if (self->sym)
-               ret += repsep_fprintf(fp, "%s", self->sym->name);
+       ret += repsep_snprintf(bf + ret, size - ret, "[%c] ", self->level);
+       if (self->ms.sym)
+               ret += repsep_snprintf(bf + ret, size - ret, "%s",
+                                      self->ms.sym->name);
        else
-               ret += repsep_fprintf(fp, "%#016llx", (u64)self->ip);
+               ret += repsep_snprintf(bf + ret, size - ret, "%#016llx", self->ip);
 
        return ret;
 }
@@ -231,10 +235,10 @@ sort__parent_cmp(struct hist_entry *left, struct hist_entry *right)
        return strcmp(sym_l->name, sym_r->name);
 }
 
-size_t
-sort__parent_print(FILE *fp, struct hist_entry *self, unsigned int width)
+static int hist_entry__parent_snprintf(struct hist_entry *self, char *bf,
+                                      size_t size, unsigned int width)
 {
-       return repsep_fprintf(fp, "%-*s", width,
+       return repsep_snprintf(bf, size, "%-*s", width,
                              self->parent ? self->parent->name : "[other]");
 }
 
@@ -251,7 +255,7 @@ int sort_dimension__add(const char *tok)
                if (strncasecmp(tok, sd->name, strlen(tok)))
                        continue;
 
-               if (sd->entry->collapse)
+               if (sd->entry->se_collapse)
                        sort__need_collapse = 1;
 
                if (sd->entry == &sort_parent) {
@@ -260,9 +264,8 @@ int sort_dimension__add(const char *tok)
                                char err[BUFSIZ];
 
                                regerror(ret, &parent_regex, err, sizeof(err));
-                               fprintf(stderr, "Invalid regex: %s\n%s",
-                                       parent_pattern, err);
-                               exit(-1);
+                               pr_err("Invalid regex: %s\n%s", parent_pattern, err);
+                               return -EINVAL;
                        }
                        sort__has_parent = 1;
                }
index 753f9ea..0d61c40 100644 (file)
 #include "sort.h"
 
 extern regex_t parent_regex;
-extern char *sort_order;
-extern char default_parent_pattern[];
-extern char *parent_pattern;
-extern char default_sort_order[];
+extern const char *sort_order;
+extern const char default_parent_pattern[];
+extern const char *parent_pattern;
+extern const char default_sort_order[];
 extern int sort__need_collapse;
 extern int sort__has_parent;
 extern char *field_sep;
@@ -43,19 +43,24 @@ extern enum sort_type sort__first_dimension;
 
 struct hist_entry {
        struct rb_node          rb_node;
-       u64                     count;
+       u64                     period;
+       u64                     period_sys;
+       u64                     period_us;
+       u64                     period_guest_sys;
+       u64                     period_guest_us;
+       struct map_symbol       ms;
        struct thread           *thread;
-       struct map              *map;
-       struct symbol           *sym;
        u64                     ip;
+       u32                     nr_events;
        char                    level;
-       struct symbol     *parent;
-       struct callchain_node   callchain;
+       u8                      filtered;
+       struct symbol           *parent;
        union {
                unsigned long     position;
                struct hist_entry *pair;
                struct rb_root    sorted_chain;
        };
+       struct callchain_node   callchain[0];
 };
 
 enum sort_type {
@@ -73,12 +78,13 @@ enum sort_type {
 struct sort_entry {
        struct list_head list;
 
-       const char *header;
+       const char *se_header;
 
-       int64_t (*cmp)(struct hist_entry *, struct hist_entry *);
-       int64_t (*collapse)(struct hist_entry *, struct hist_entry *);
-       size_t  (*print)(FILE *fp, struct hist_entry *, unsigned int width);
-       unsigned int *width;
+       int64_t (*se_cmp)(struct hist_entry *, struct hist_entry *);
+       int64_t (*se_collapse)(struct hist_entry *, struct hist_entry *);
+       int     (*se_snprintf)(struct hist_entry *self, char *bf, size_t size,
+                              unsigned int width);
+       unsigned int *se_width;
        bool    elide;
 };
 
@@ -87,7 +93,6 @@ extern struct list_head hist_entry__sort_list;
 
 void setup_sorting(const char * const usagestr[], const struct option *opts);
 
-extern int repsep_fprintf(FILE *fp, const char *fmt, ...);
 extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int);
 extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int);
 extern size_t sort__dso_print(FILE *, struct hist_entry *, unsigned int);
index a175949..0409fc7 100644 (file)
@@ -1,48 +1,5 @@
-#include "string.h"
 #include "util.h"
-
-static int hex(char ch)
-{
-       if ((ch >= '0') && (ch <= '9'))
-               return ch - '0';
-       if ((ch >= 'a') && (ch <= 'f'))
-               return ch - 'a' + 10;
-       if ((ch >= 'A') && (ch <= 'F'))
-               return ch - 'A' + 10;
-       return -1;
-}
-
-/*
- * While we find nice hex chars, build a long_val.
- * Return number of chars processed.
- */
-int hex2u64(const char *ptr, u64 *long_val)
-{
-       const char *p = ptr;
-       *long_val = 0;
-
-       while (*p) {
-               const int hex_val = hex(*p);
-
-               if (hex_val < 0)
-                       break;
-
-               *long_val = (*long_val << 4) | hex_val;
-               p++;
-       }
-
-       return p - ptr;
-}
-
-char *strxfrchar(char *s, char from, char to)
-{
-       char *p = s;
-
-       while ((p = strchr(p, from)) != NULL)
-               *p++ = to;
-
-       return s;
-}
+#include "string.h"
 
 #define K 1024LL
 /*
diff --git a/tools/perf/util/string.h b/tools/perf/util/string.h
deleted file mode 100644 (file)
index 542e44d..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __PERF_STRING_H_
-#define __PERF_STRING_H_
-
-#include <stdbool.h>
-#include "types.h"
-
-int hex2u64(const char *ptr, u64 *val);
-char *strxfrchar(char *s, char from, char to);
-s64 perf_atoll(const char *str);
-char **argv_split(const char *str, int *argcp);
-void argv_free(char **argv);
-bool strglobmatch(const char *str, const char *pat);
-bool strlazymatch(const char *str, const char *pat);
-
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-#endif /* __PERF_STRING_H */
index c458c4a..a06131f 100644 (file)
@@ -1,13 +1,19 @@
-#include "util.h"
-#include "../perf.h"
-#include "sort.h"
-#include "string.h"
+#define _GNU_SOURCE
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include "symbol.h"
-#include "thread.h"
+#include "strlist.h"
 
-#include "debug.h"
-
-#include <asm/bug.h>
 #include <libelf.h>
 #include <gelf.h>
 #include <elf.h>
 #define NT_GNU_BUILD_ID 3
 #endif
 
-enum dso_origin {
-       DSO__ORIG_KERNEL = 0,
-       DSO__ORIG_JAVA_JIT,
-       DSO__ORIG_BUILD_ID_CACHE,
-       DSO__ORIG_FEDORA,
-       DSO__ORIG_UBUNTU,
-       DSO__ORIG_BUILDID,
-       DSO__ORIG_DSO,
-       DSO__ORIG_KMODULE,
-       DSO__ORIG_NOT_FOUND,
-};
-
 static void dsos__add(struct list_head *head, struct dso *dso);
 static struct map *map__new2(u64 start, struct dso *dso, enum map_type type);
 static int dso__load_kernel_sym(struct dso *self, struct map *map,
                                symbol_filter_t filter);
+static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
+                       symbol_filter_t filter);
 static int vmlinux_path__nr_entries;
 static char **vmlinux_path;
 
@@ -126,16 +122,17 @@ static void map_groups__fixup_end(struct map_groups *self)
 static struct symbol *symbol__new(u64 start, u64 len, const char *name)
 {
        size_t namelen = strlen(name) + 1;
-       struct symbol *self = zalloc(symbol_conf.priv_size +
-                                    sizeof(*self) + namelen);
+       struct symbol *self = calloc(1, (symbol_conf.priv_size +
+                                        sizeof(*self) + namelen));
        if (self == NULL)
                return NULL;
 
        if (symbol_conf.priv_size)
                self = ((void *)self) + symbol_conf.priv_size;
 
-       self->start = start;
-       self->end   = len ? start + len - 1 : start;
+       self->start   = start;
+       self->end     = len ? start + len - 1 : start;
+       self->namelen = namelen - 1;
 
        pr_debug4("%s: %s %#Lx-%#Lx\n", __func__, name, start, self->end);
 
@@ -178,7 +175,7 @@ static void dso__set_basename(struct dso *self)
 
 struct dso *dso__new(const char *name)
 {
-       struct dso *self = zalloc(sizeof(*self) + strlen(name) + 1);
+       struct dso *self = calloc(1, sizeof(*self) + strlen(name) + 1);
 
        if (self != NULL) {
                int i;
@@ -192,6 +189,8 @@ struct dso *dso__new(const char *name)
                self->loaded = 0;
                self->sorted_by_name = 0;
                self->has_build_id = 0;
+               self->kernel = DSO_TYPE_USER;
+               INIT_LIST_HEAD(&self->node);
        }
 
        return self;
@@ -408,12 +407,9 @@ int kallsyms__parse(const char *filename, void *arg,
                char *symbol_name;
 
                line_len = getline(&line, &n, file);
-               if (line_len < 0)
+               if (line_len < 0 || !line)
                        break;
 
-               if (!line)
-                       goto out_failure;
-
                line[--line_len] = '\0'; /* \n */
 
                len = hex2u64(line, &start);
@@ -465,6 +461,7 @@ static int map__process_kallsym_symbol(void *arg, const char *name,
         * map__split_kallsyms, when we have split the maps per module
         */
        symbols__insert(root, sym);
+
        return 0;
 }
 
@@ -489,6 +486,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
                               symbol_filter_t filter)
 {
        struct map_groups *kmaps = map__kmap(map)->kmaps;
+       struct machine *machine = kmaps->machine;
        struct map *curr_map = map;
        struct symbol *pos;
        int count = 0;
@@ -510,15 +508,33 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
                        *module++ = '\0';
 
                        if (strcmp(curr_map->dso->short_name, module)) {
-                               curr_map = map_groups__find_by_name(kmaps, map->type, module);
+                               if (curr_map != map &&
+                                   self->kernel == DSO_TYPE_GUEST_KERNEL &&
+                                   machine__is_default_guest(machine)) {
+                                       /*
+                                        * We assume all symbols of a module are
+                                        * continuous in * kallsyms, so curr_map
+                                        * points to a module and all its
+                                        * symbols are in its kmap. Mark it as
+                                        * loaded.
+                                        */
+                                       dso__set_loaded(curr_map->dso,
+                                                       curr_map->type);
+                               }
+
+                               curr_map = map_groups__find_by_name(kmaps,
+                                                       map->type, module);
                                if (curr_map == NULL) {
-                                       pr_debug("/proc/{kallsyms,modules} "
+                                       pr_debug("%s/proc/{kallsyms,modules} "
                                                 "inconsistency while looking "
-                                                "for \"%s\" module!\n", module);
-                                       return -1;
+                                                "for \"%s\" module!\n",
+                                                machine->root_dir, module);
+                                       curr_map = map;
+                                       goto discard_symbol;
                                }
 
-                               if (curr_map->dso->loaded)
+                               if (curr_map->dso->loaded &&
+                                   !machine__is_default_guest(machine))
                                        goto discard_symbol;
                        }
                        /*
@@ -531,13 +547,21 @@ static int dso__split_kallsyms(struct dso *self, struct map *map,
                        char dso_name[PATH_MAX];
                        struct dso *dso;
 
-                       snprintf(dso_name, sizeof(dso_name), "[kernel].%d",
-                                kernel_range++);
+                       if (self->kernel == DSO_TYPE_GUEST_KERNEL)
+                               snprintf(dso_name, sizeof(dso_name),
+                                       "[guest.kernel].%d",
+                                       kernel_range++);
+                       else
+                               snprintf(dso_name, sizeof(dso_name),
+                                       "[kernel].%d",
+                                       kernel_range++);
 
                        dso = dso__new(dso_name);
                        if (dso == NULL)
                                return -1;
 
+                       dso->kernel = self->kernel;
+
                        curr_map = map__new2(pos->start, dso, map->type);
                        if (curr_map == NULL) {
                                dso__delete(dso);
@@ -561,6 +585,12 @@ discard_symbol:            rb_erase(&pos->rb_node, root);
                }
        }
 
+       if (curr_map != map &&
+           self->kernel == DSO_TYPE_GUEST_KERNEL &&
+           machine__is_default_guest(kmaps->machine)) {
+               dso__set_loaded(curr_map->dso, curr_map->type);
+       }
+
        return count;
 }
 
@@ -571,7 +601,10 @@ int dso__load_kallsyms(struct dso *self, const char *filename,
                return -1;
 
        symbols__fixup_end(&self->symbols[map->type]);
-       self->origin = DSO__ORIG_KERNEL;
+       if (self->kernel == DSO_TYPE_GUEST_KERNEL)
+               self->origin = DSO__ORIG_GUEST_KERNEL;
+       else
+               self->origin = DSO__ORIG_KERNEL;
 
        return dso__split_kallsyms(self, map, filter);
 }
@@ -870,8 +903,8 @@ out_close:
        if (err == 0)
                return nr;
 out:
-       pr_warning("%s: problems reading %s PLT info.\n",
-                  __func__, self->long_name);
+       pr_debug("%s: problems reading %s PLT info.\n",
+                __func__, self->long_name);
        return 0;
 }
 
@@ -958,7 +991,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
        nr_syms = shdr.sh_size / shdr.sh_entsize;
 
        memset(&sym, 0, sizeof(sym));
-       if (!self->kernel) {
+       if (self->kernel == DSO_TYPE_USER) {
                self->adjust_symbols = (ehdr.e_type == ET_EXEC ||
                                elf_section_by_name(elf, &ehdr, &shdr,
                                                     ".gnu.prelink_undo",
@@ -990,7 +1023,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
 
                section_name = elf_sec__name(&shdr, secstrs);
 
-               if (self->kernel || kmodule) {
+               if (self->kernel != DSO_TYPE_USER || kmodule) {
                        char dso_name[PATH_MAX];
 
                        if (strcmp(section_name,
@@ -1017,6 +1050,7 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
                                curr_dso = dso__new(dso_name);
                                if (curr_dso == NULL)
                                        goto out_elf_end;
+                               curr_dso->kernel = self->kernel;
                                curr_map = map__new2(start, curr_dso,
                                                     map->type);
                                if (curr_map == NULL) {
@@ -1025,9 +1059,9 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name,
                                }
                                curr_map->map_ip = identity__map_ip;
                                curr_map->unmap_ip = identity__map_ip;
-                               curr_dso->origin = DSO__ORIG_KERNEL;
+                               curr_dso->origin = self->origin;
                                map_groups__insert(kmap->kmaps, curr_map);
-                               dsos__add(&dsos__kernel, curr_dso);
+                               dsos__add(&self->node, curr_dso);
                                dso__set_loaded(curr_dso, map->type);
                        } else
                                curr_dso = curr_map->dso;
@@ -1089,7 +1123,7 @@ static bool dso__build_id_equal(const struct dso *self, u8 *build_id)
        return memcmp(self->build_id, build_id, sizeof(self->build_id)) == 0;
 }
 
-static bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
+bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
 {
        bool have_build_id = false;
        struct dso *pos;
@@ -1107,13 +1141,6 @@ static bool __dsos__read_build_ids(struct list_head *head, bool with_hits)
        return have_build_id;
 }
 
-bool dsos__read_build_ids(bool with_hits)
-{
-       bool kbuildids = __dsos__read_build_ids(&dsos__kernel, with_hits),
-            ubuildids = __dsos__read_build_ids(&dsos__user, with_hits);
-       return kbuildids || ubuildids;
-}
-
 /*
  * Align offset to 4 bytes as needed for note name and descriptor data.
  */
@@ -1248,6 +1275,8 @@ char dso__symtab_origin(const struct dso *self)
                [DSO__ORIG_BUILDID] =  'b',
                [DSO__ORIG_DSO] =      'd',
                [DSO__ORIG_KMODULE] =  'K',
+               [DSO__ORIG_GUEST_KERNEL] =  'g',
+               [DSO__ORIG_GUEST_KMODULE] =  'G',
        };
 
        if (self == NULL || self->origin == DSO__ORIG_NOT_FOUND)
@@ -1263,11 +1292,20 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)
        char build_id_hex[BUILD_ID_SIZE * 2 + 1];
        int ret = -1;
        int fd;
+       struct machine *machine;
+       const char *root_dir;
 
        dso__set_loaded(self, map->type);
 
-       if (self->kernel)
+       if (self->kernel == DSO_TYPE_KERNEL)
                return dso__load_kernel_sym(self, map, filter);
+       else if (self->kernel == DSO_TYPE_GUEST_KERNEL)
+               return dso__load_guest_kernel_sym(self, map, filter);
+
+       if (map->groups && map->groups->machine)
+               machine = map->groups->machine;
+       else
+               machine = NULL;
 
        name = malloc(size);
        if (!name)
@@ -1321,6 +1359,13 @@ more:
                case DSO__ORIG_DSO:
                        snprintf(name, size, "%s", self->long_name);
                        break;
+               case DSO__ORIG_GUEST_KMODULE:
+                       if (map->groups && map->groups->machine)
+                               root_dir = map->groups->machine->root_dir;
+                       else
+                               root_dir = "";
+                       snprintf(name, size, "%s%s", root_dir, self->long_name);
+                       break;
 
                default:
                        goto out;
@@ -1374,7 +1419,8 @@ struct map *map_groups__find_by_name(struct map_groups *self,
        return NULL;
 }
 
-static int dso__kernel_module_get_build_id(struct dso *self)
+static int dso__kernel_module_get_build_id(struct dso *self,
+                               const char *root_dir)
 {
        char filename[PATH_MAX];
        /*
@@ -1384,8 +1430,8 @@ static int dso__kernel_module_get_build_id(struct dso *self)
        const char *name = self->short_name + 1;
 
        snprintf(filename, sizeof(filename),
-                "/sys/module/%.*s/notes/.note.gnu.build-id",
-                (int)strlen(name - 1), name);
+                "%s/sys/module/%.*s/notes/.note.gnu.build-id",
+                root_dir, (int)strlen(name) - 1, name);
 
        if (sysfs__read_build_id(filename, self->build_id,
                                 sizeof(self->build_id)) == 0)
@@ -1394,26 +1440,33 @@ static int dso__kernel_module_get_build_id(struct dso *self)
        return 0;
 }
 
-static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirname)
+static int map_groups__set_modules_path_dir(struct map_groups *self,
+                               const char *dir_name)
 {
        struct dirent *dent;
-       DIR *dir = opendir(dirname);
+       DIR *dir = opendir(dir_name);
 
        if (!dir) {
-               pr_debug("%s: cannot open %s dir\n", __func__, dirname);
+               pr_debug("%s: cannot open %s dir\n", __func__, dir_name);
                return -1;
        }
 
        while ((dent = readdir(dir)) != NULL) {
                char path[PATH_MAX];
+               struct stat st;
 
-               if (dent->d_type == DT_DIR) {
+               /*sshfs might return bad dent->d_type, so we have to stat*/
+               sprintf(path, "%s/%s", dir_name, dent->d_name);
+               if (stat(path, &st))
+                       continue;
+
+               if (S_ISDIR(st.st_mode)) {
                        if (!strcmp(dent->d_name, ".") ||
                            !strcmp(dent->d_name, ".."))
                                continue;
 
                        snprintf(path, sizeof(path), "%s/%s",
-                                dirname, dent->d_name);
+                                dir_name, dent->d_name);
                        if (map_groups__set_modules_path_dir(self, path) < 0)
                                goto failure;
                } else {
@@ -1433,13 +1486,13 @@ static int map_groups__set_modules_path_dir(struct map_groups *self, char *dirna
                                continue;
 
                        snprintf(path, sizeof(path), "%s/%s",
-                                dirname, dent->d_name);
+                                dir_name, dent->d_name);
 
                        long_name = strdup(path);
                        if (long_name == NULL)
                                goto failure;
                        dso__set_long_name(map->dso, long_name);
-                       dso__kernel_module_get_build_id(map->dso);
+                       dso__kernel_module_get_build_id(map->dso, "");
                }
        }
 
@@ -1449,18 +1502,47 @@ failure:
        return -1;
 }
 
-static int map_groups__set_modules_path(struct map_groups *self)
+static char *get_kernel_version(const char *root_dir)
 {
-       struct utsname uts;
+       char version[PATH_MAX];
+       FILE *file;
+       char *name, *tmp;
+       const char *prefix = "Linux version ";
+
+       sprintf(version, "%s/proc/version", root_dir);
+       file = fopen(version, "r");
+       if (!file)
+               return NULL;
+
+       version[0] = '\0';
+       tmp = fgets(version, sizeof(version), file);
+       fclose(file);
+
+       name = strstr(version, prefix);
+       if (!name)
+               return NULL;
+       name += strlen(prefix);
+       tmp = strchr(name, ' ');
+       if (tmp)
+               *tmp = '\0';
+
+       return strdup(name);
+}
+
+static int machine__set_modules_path(struct machine *self)
+{
+       char *version;
        char modules_path[PATH_MAX];
 
-       if (uname(&uts) < 0)
+       version = get_kernel_version(self->root_dir);
+       if (!version)
                return -1;
 
-       snprintf(modules_path, sizeof(modules_path), "/lib/modules/%s/kernel",
-                uts.release);
+       snprintf(modules_path, sizeof(modules_path), "%s/lib/modules/%s/kernel",
+                self->root_dir, version);
+       free(version);
 
-       return map_groups__set_modules_path_dir(self, modules_path);
+       return map_groups__set_modules_path_dir(&self->kmaps, modules_path);
 }
 
 /*
@@ -1470,8 +1552,8 @@ static int map_groups__set_modules_path(struct map_groups *self)
  */
 static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
 {
-       struct map *self = zalloc(sizeof(*self) +
-                                 (dso->kernel ? sizeof(struct kmap) : 0));
+       struct map *self = calloc(1, (sizeof(*self) +
+                                     (dso->kernel ? sizeof(struct kmap) : 0)));
        if (self != NULL) {
                /*
                 * ->end will be filled after we load all the symbols
@@ -1482,11 +1564,11 @@ static struct map *map__new2(u64 start, struct dso *dso, enum map_type type)
        return self;
 }
 
-struct map *map_groups__new_module(struct map_groups *self, u64 start,
-                                  const char *filename)
+struct map *machine__new_module(struct machine *self, u64 start,
+                               const char *filename)
 {
        struct map *map;
-       struct dso *dso = __dsos__findnew(&dsos__kernel, filename);
+       struct dso *dso = __dsos__findnew(&self->kernel_dsos, filename);
 
        if (dso == NULL)
                return NULL;
@@ -1495,18 +1577,31 @@ struct map *map_groups__new_module(struct map_groups *self, u64 start,
        if (map == NULL)
                return NULL;
 
-       dso->origin = DSO__ORIG_KMODULE;
-       map_groups__insert(self, map);
+       if (machine__is_host(self))
+               dso->origin = DSO__ORIG_KMODULE;
+       else
+               dso->origin = DSO__ORIG_GUEST_KMODULE;
+       map_groups__insert(&self->kmaps, map);
        return map;
 }
 
-static int map_groups__create_modules(struct map_groups *self)
+static int machine__create_modules(struct machine *self)
 {
        char *line = NULL;
        size_t n;
-       FILE *file = fopen("/proc/modules", "r");
+       FILE *file;
        struct map *map;
+       const char *modules;
+       char path[PATH_MAX];
+
+       if (machine__is_default_guest(self))
+               modules = symbol_conf.default_guest_modules;
+       else {
+               sprintf(path, "%s/proc/modules", self->root_dir);
+               modules = path;
+       }
 
+       file = fopen(modules, "r");
        if (file == NULL)
                return -1;
 
@@ -1538,16 +1633,16 @@ static int map_groups__create_modules(struct map_groups *self)
                *sep = '\0';
 
                snprintf(name, sizeof(name), "[%s]", line);
-               map = map_groups__new_module(self, start, name);
+               map = machine__new_module(self, start, name);
                if (map == NULL)
                        goto out_delete_line;
-               dso__kernel_module_get_build_id(map->dso);
+               dso__kernel_module_get_build_id(map->dso, self->root_dir);
        }
 
        free(line);
        fclose(file);
 
-       return map_groups__set_modules_path(self);
+       return machine__set_modules_path(self);
 
 out_delete_line:
        free(line);
@@ -1714,8 +1809,56 @@ out_fixup:
        return err;
 }
 
-LIST_HEAD(dsos__user);
-LIST_HEAD(dsos__kernel);
+static int dso__load_guest_kernel_sym(struct dso *self, struct map *map,
+                               symbol_filter_t filter)
+{
+       int err;
+       const char *kallsyms_filename = NULL;
+       struct machine *machine;
+       char path[PATH_MAX];
+
+       if (!map->groups) {
+               pr_debug("Guest kernel map hasn't the point to groups\n");
+               return -1;
+       }
+       machine = map->groups->machine;
+
+       if (machine__is_default_guest(machine)) {
+               /*
+                * if the user specified a vmlinux filename, use it and only
+                * it, reporting errors to the user if it cannot be used.
+                * Or use file guest_kallsyms inputted by user on commandline
+                */
+               if (symbol_conf.default_guest_vmlinux_name != NULL) {
+                       err = dso__load_vmlinux(self, map,
+                               symbol_conf.default_guest_vmlinux_name, filter);
+                       goto out_try_fixup;
+               }
+
+               kallsyms_filename = symbol_conf.default_guest_kallsyms;
+               if (!kallsyms_filename)
+                       return -1;
+       } else {
+               sprintf(path, "%s/proc/kallsyms", machine->root_dir);
+               kallsyms_filename = path;
+       }
+
+       err = dso__load_kallsyms(self, kallsyms_filename, map, filter);
+       if (err > 0)
+               pr_debug("Using %s for symbols\n", kallsyms_filename);
+
+out_try_fixup:
+       if (err > 0) {
+               if (kallsyms_filename != NULL) {
+                       machine__mmap_name(machine, path, sizeof(path));
+                       dso__set_long_name(self, strdup(path));
+               }
+               map__fixup_start(map);
+               map__fixup_end(map);
+       }
+
+       return err;
+}
 
 static void dsos__add(struct list_head *head, struct dso *dso)
 {
@@ -1747,21 +1890,32 @@ struct dso *__dsos__findnew(struct list_head *head, const char *name)
        return dso;
 }
 
-static void __dsos__fprintf(struct list_head *head, FILE *fp)
+size_t __dsos__fprintf(struct list_head *head, FILE *fp)
 {
        struct dso *pos;
+       size_t ret = 0;
 
        list_for_each_entry(pos, head, node) {
                int i;
                for (i = 0; i < MAP__NR_TYPES; ++i)
-                       dso__fprintf(pos, i, fp);
+                       ret += dso__fprintf(pos, i, fp);
        }
+
+       return ret;
 }
 
-void dsos__fprintf(FILE *fp)
+size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp)
 {
-       __dsos__fprintf(&dsos__kernel, fp);
-       __dsos__fprintf(&dsos__user, fp);
+       struct rb_node *nd;
+       size_t ret = 0;
+
+       for (nd = rb_first(self); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               ret += __dsos__fprintf(&pos->kernel_dsos, fp);
+               ret += __dsos__fprintf(&pos->user_dsos, fp);
+       }
+
+       return ret;
 }
 
 static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
@@ -1779,10 +1933,17 @@ static size_t __dsos__fprintf_buildid(struct list_head *head, FILE *fp,
        return ret;
 }
 
-size_t dsos__fprintf_buildid(FILE *fp, bool with_hits)
+size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits)
 {
-       return (__dsos__fprintf_buildid(&dsos__kernel, fp, with_hits) +
-               __dsos__fprintf_buildid(&dsos__user, fp, with_hits));
+       struct rb_node *nd;
+       size_t ret = 0;
+
+       for (nd = rb_first(self); nd; nd = rb_next(nd)) {
+               struct machine *pos = rb_entry(nd, struct machine, rb_node);
+               ret += __dsos__fprintf_buildid(&pos->kernel_dsos, fp, with_hits);
+               ret += __dsos__fprintf_buildid(&pos->user_dsos, fp, with_hits);
+       }
+       return ret;
 }
 
 struct dso *dso__new_kernel(const char *name)
@@ -1791,55 +1952,98 @@ struct dso *dso__new_kernel(const char *name)
 
        if (self != NULL) {
                dso__set_short_name(self, "[kernel]");
-               self->kernel     = 1;
+               self->kernel = DSO_TYPE_KERNEL;
        }
 
        return self;
 }
 
-void dso__read_running_kernel_build_id(struct dso *self)
+static struct dso *dso__new_guest_kernel(struct machine *machine,
+                                       const char *name)
 {
-       if (sysfs__read_build_id("/sys/kernel/notes", self->build_id,
+       char bf[PATH_MAX];
+       struct dso *self = dso__new(name ?: machine__mmap_name(machine, bf, sizeof(bf)));
+
+       if (self != NULL) {
+               dso__set_short_name(self, "[guest.kernel]");
+               self->kernel = DSO_TYPE_GUEST_KERNEL;
+       }
+
+       return self;
+}
+
+void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine)
+{
+       char path[PATH_MAX];
+
+       if (machine__is_default_guest(machine))
+               return;
+       sprintf(path, "%s/sys/kernel/notes", machine->root_dir);
+       if (sysfs__read_build_id(path, self->build_id,
                                 sizeof(self->build_id)) == 0)
                self->has_build_id = true;
 }
 
-static struct dso *dsos__create_kernel(const char *vmlinux)
+static struct dso *machine__create_kernel(struct machine *self)
 {
-       struct dso *kernel = dso__new_kernel(vmlinux);
+       const char *vmlinux_name = NULL;
+       struct dso *kernel;
 
-       if (kernel != NULL) {
-               dso__read_running_kernel_build_id(kernel);
-               dsos__add(&dsos__kernel, kernel);
+       if (machine__is_host(self)) {
+               vmlinux_name = symbol_conf.vmlinux_name;
+               kernel = dso__new_kernel(vmlinux_name);
+       } else {
+               if (machine__is_default_guest(self))
+                       vmlinux_name = symbol_conf.default_guest_vmlinux_name;
+               kernel = dso__new_guest_kernel(self, vmlinux_name);
        }
 
+       if (kernel != NULL) {
+               dso__read_running_kernel_build_id(kernel, self);
+               dsos__add(&self->kernel_dsos, kernel);
+       }
        return kernel;
 }
 
-int __map_groups__create_kernel_maps(struct map_groups *self,
-                                    struct map *vmlinux_maps[MAP__NR_TYPES],
-                                    struct dso *kernel)
+int __machine__create_kernel_maps(struct machine *self, struct dso *kernel)
 {
        enum map_type type;
 
        for (type = 0; type < MAP__NR_TYPES; ++type) {
                struct kmap *kmap;
 
-               vmlinux_maps[type] = map__new2(0, kernel, type);
-               if (vmlinux_maps[type] == NULL)
+               self->vmlinux_maps[type] = map__new2(0, kernel, type);
+               if (self->vmlinux_maps[type] == NULL)
                        return -1;
 
-               vmlinux_maps[type]->map_ip =
-                       vmlinux_maps[type]->unmap_ip = identity__map_ip;
+               self->vmlinux_maps[type]->map_ip =
+                       self->vmlinux_maps[type]->unmap_ip = identity__map_ip;
 
-               kmap = map__kmap(vmlinux_maps[type]);
-               kmap->kmaps = self;
-               map_groups__insert(self, vmlinux_maps[type]);
+               kmap = map__kmap(self->vmlinux_maps[type]);
+               kmap->kmaps = &self->kmaps;
+               map_groups__insert(&self->kmaps, self->vmlinux_maps[type]);
        }
 
        return 0;
 }
 
+int machine__create_kernel_maps(struct machine *self)
+{
+       struct dso *kernel = machine__create_kernel(self);
+
+       if (kernel == NULL ||
+           __machine__create_kernel_maps(self, kernel) < 0)
+               return -1;
+
+       if (symbol_conf.use_modules && machine__create_modules(self) < 0)
+               pr_debug("Problems creating module maps, continuing anyway...\n");
+       /*
+        * Now that we have all the maps created, just set the ->end of them:
+        */
+       map_groups__fixup_end(&self->kmaps);
+       return 0;
+}
+
 static void vmlinux_path__exit(void)
 {
        while (--vmlinux_path__nr_entries >= 0) {
@@ -1895,6 +2099,17 @@ out_fail:
        return -1;
 }
 
+size_t vmlinux_path__fprintf(FILE *fp)
+{
+       int i;
+       size_t printed = 0;
+
+       for (i = 0; i < vmlinux_path__nr_entries; ++i)
+               printed += fprintf(fp, "[%d] %s\n", i, vmlinux_path[i]);
+
+       return printed;
+}
+
 static int setup_list(struct strlist **list, const char *list_str,
                      const char *list_name)
 {
@@ -1945,22 +2160,129 @@ out_free_comm_list:
        return -1;
 }
 
-int map_groups__create_kernel_maps(struct map_groups *self,
-                                  struct map *vmlinux_maps[MAP__NR_TYPES])
+int machines__create_kernel_maps(struct rb_root *self, pid_t pid)
 {
-       struct dso *kernel = dsos__create_kernel(symbol_conf.vmlinux_name);
+       struct machine *machine = machines__findnew(self, pid);
 
-       if (kernel == NULL)
+       if (machine == NULL)
                return -1;
 
-       if (__map_groups__create_kernel_maps(self, vmlinux_maps, kernel) < 0)
-               return -1;
+       return machine__create_kernel_maps(machine);
+}
 
-       if (symbol_conf.use_modules && map_groups__create_modules(self) < 0)
-               pr_debug("Problems creating module maps, continuing anyway...\n");
-       /*
-        * Now that we have all the maps created, just set the ->end of them:
-        */
-       map_groups__fixup_end(self);
-       return 0;
+static int hex(char ch)
+{
+       if ((ch >= '0') && (ch <= '9'))
+               return ch - '0';
+       if ((ch >= 'a') && (ch <= 'f'))
+               return ch - 'a' + 10;
+       if ((ch >= 'A') && (ch <= 'F'))
+               return ch - 'A' + 10;
+       return -1;
+}
+
+/*
+ * While we find nice hex chars, build a long_val.
+ * Return number of chars processed.
+ */
+int hex2u64(const char *ptr, u64 *long_val)
+{
+       const char *p = ptr;
+       *long_val = 0;
+
+       while (*p) {
+               const int hex_val = hex(*p);
+
+               if (hex_val < 0)
+                       break;
+
+               *long_val = (*long_val << 4) | hex_val;
+               p++;
+       }
+
+       return p - ptr;
+}
+
+char *strxfrchar(char *s, char from, char to)
+{
+       char *p = s;
+
+       while ((p = strchr(p, from)) != NULL)
+               *p++ = to;
+
+       return s;
+}
+
+int machines__create_guest_kernel_maps(struct rb_root *self)
+{
+       int ret = 0;
+       struct dirent **namelist = NULL;
+       int i, items = 0;
+       char path[PATH_MAX];
+       pid_t pid;
+
+       if (symbol_conf.default_guest_vmlinux_name ||
+           symbol_conf.default_guest_modules ||
+           symbol_conf.default_guest_kallsyms) {
+               machines__create_kernel_maps(self, DEFAULT_GUEST_KERNEL_ID);
+       }
+
+       if (symbol_conf.guestmount) {
+               items = scandir(symbol_conf.guestmount, &namelist, NULL, NULL);
+               if (items <= 0)
+                       return -ENOENT;
+               for (i = 0; i < items; i++) {
+                       if (!isdigit(namelist[i]->d_name[0])) {
+                               /* Filter out . and .. */
+                               continue;
+                       }
+                       pid = atoi(namelist[i]->d_name);
+                       sprintf(path, "%s/%s/proc/kallsyms",
+                               symbol_conf.guestmount,
+                               namelist[i]->d_name);
+                       ret = access(path, R_OK);
+                       if (ret) {
+                               pr_debug("Can't access file %s\n", path);
+                               goto failure;
+                       }
+                       machines__create_kernel_maps(self, pid);
+               }
+failure:
+               free(namelist);
+       }
+
+       return ret;
+}
+
+int machine__load_kallsyms(struct machine *self, const char *filename,
+                          enum map_type type, symbol_filter_t filter)
+{
+       struct map *map = self->vmlinux_maps[type];
+       int ret = dso__load_kallsyms(map->dso, filename, map, filter);
+
+       if (ret > 0) {
+               dso__set_loaded(map->dso, type);
+               /*
+                * Since /proc/kallsyms will have multiple sessions for the
+                * kernel, with modules between them, fixup the end of all
+                * sections.
+                */
+               __map_groups__fixup_end(&self->kmaps, type);
+       }
+
+       return ret;
+}
+
+int machine__load_vmlinux_path(struct machine *self, enum map_type type,
+                              symbol_filter_t filter)
+{
+       struct map *map = self->vmlinux_maps[type];
+       int ret = dso__load_vmlinux_path(map->dso, map, filter);
+
+       if (ret > 0) {
+               dso__set_loaded(map->dso, type);
+               map__reloc_vmlinux(map);
+       }
+
+       return ret;
 }
index f30a374..032469e 100644 (file)
@@ -3,10 +3,11 @@
 
 #include <linux/types.h>
 #include <stdbool.h>
-#include "types.h"
+#include <stdint.h>
+#include "map.h"
 #include <linux/list.h>
 #include <linux/rbtree.h>
-#include "event.h"
+#include <stdio.h>
 
 #define DEBUG_CACHE_DIR ".debug"
 
@@ -29,6 +30,9 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
 #endif
 #endif
 
+int hex2u64(const char *ptr, u64 *val);
+char *strxfrchar(char *s, char from, char to);
+
 /*
  * libelf 0.8.x and earlier do not support ELF_C_READ_MMAP;
  * for newer versions we can use mmap to reduce memory usage:
@@ -44,10 +48,13 @@ static inline char *bfd_demangle(void __used *v, const char __used *c,
 #define DMGL_ANSI        (1 << 1)       /* Include const, volatile, etc */
 #endif
 
+#define BUILD_ID_SIZE 20
+
 struct symbol {
        struct rb_node  rb_node;
        u64             start;
        u64             end;
+       u16             namelen;
        char            name[0];
 };
 
@@ -63,10 +70,15 @@ struct symbol_conf {
                        show_nr_samples,
                        use_callchain,
                        exclude_other,
-                       full_paths;
+                       full_paths,
+                       show_cpu_utilization;
        const char      *vmlinux_name,
                        *field_sep;
-       char            *dso_list_str,
+       const char      *default_guest_vmlinux_name,
+                       *default_guest_kallsyms,
+                       *default_guest_modules;
+       const char      *guestmount;
+       const char      *dso_list_str,
                        *comm_list_str,
                        *sym_list_str,
                        *col_width_list_str;
@@ -88,6 +100,11 @@ struct ref_reloc_sym {
        u64             unrelocated_addr;
 };
 
+struct map_symbol {
+       struct map    *map;
+       struct symbol *sym;
+};
+
 struct addr_location {
        struct thread *thread;
        struct map    *map;
@@ -95,6 +112,13 @@ struct addr_location {
        u64           addr;
        char          level;
        bool          filtered;
+       unsigned int  cpumode;
+};
+
+enum dso_kernel_type {
+       DSO_TYPE_USER = 0,
+       DSO_TYPE_KERNEL,
+       DSO_TYPE_GUEST_KERNEL
 };
 
 struct dso {
@@ -104,8 +128,9 @@ struct dso {
        u8               adjust_symbols:1;
        u8               slen_calculated:1;
        u8               has_build_id:1;
-       u8               kernel:1;
+       enum dso_kernel_type    kernel;
        u8               hit:1;
+       u8               annotate_warned:1;
        unsigned char    origin;
        u8               sorted_by_name;
        u8               loaded;
@@ -131,42 +156,65 @@ static inline void dso__set_loaded(struct dso *self, enum map_type type)
 
 void dso__sort_by_name(struct dso *self, enum map_type type);
 
-extern struct list_head dsos__user, dsos__kernel;
-
 struct dso *__dsos__findnew(struct list_head *head, const char *name);
 
-static inline struct dso *dsos__findnew(const char *name)
-{
-       return __dsos__findnew(&dsos__user, name);
-}
-
 int dso__load(struct dso *self, struct map *map, symbol_filter_t filter);
 int dso__load_vmlinux_path(struct dso *self, struct map *map,
                           symbol_filter_t filter);
 int dso__load_kallsyms(struct dso *self, const char *filename, struct map *map,
                       symbol_filter_t filter);
-void dsos__fprintf(FILE *fp);
-size_t dsos__fprintf_buildid(FILE *fp, bool with_hits);
+int machine__load_kallsyms(struct machine *self, const char *filename,
+                          enum map_type type, symbol_filter_t filter);
+int machine__load_vmlinux_path(struct machine *self, enum map_type type,
+                              symbol_filter_t filter);
+
+size_t __dsos__fprintf(struct list_head *head, FILE *fp);
+
+size_t machines__fprintf_dsos(struct rb_root *self, FILE *fp);
+size_t machines__fprintf_dsos_buildid(struct rb_root *self, FILE *fp, bool with_hits);
 
 size_t dso__fprintf_buildid(struct dso *self, FILE *fp);
 size_t dso__fprintf(struct dso *self, enum map_type type, FILE *fp);
+
+enum dso_origin {
+       DSO__ORIG_KERNEL = 0,
+       DSO__ORIG_GUEST_KERNEL,
+       DSO__ORIG_JAVA_JIT,
+       DSO__ORIG_BUILD_ID_CACHE,
+       DSO__ORIG_FEDORA,
+       DSO__ORIG_UBUNTU,
+       DSO__ORIG_BUILDID,
+       DSO__ORIG_DSO,
+       DSO__ORIG_GUEST_KMODULE,
+       DSO__ORIG_KMODULE,
+       DSO__ORIG_NOT_FOUND,
+};
+
 char dso__symtab_origin(const struct dso *self);
 void dso__set_long_name(struct dso *self, char *name);
 void dso__set_build_id(struct dso *self, void *build_id);
-void dso__read_running_kernel_build_id(struct dso *self);
+void dso__read_running_kernel_build_id(struct dso *self, struct machine *machine);
 struct symbol *dso__find_symbol(struct dso *self, enum map_type type, u64 addr);
 struct symbol *dso__find_symbol_by_name(struct dso *self, enum map_type type,
                                        const char *name);
 
 int filename__read_build_id(const char *filename, void *bf, size_t size);
 int sysfs__read_build_id(const char *filename, void *bf, size_t size);
-bool dsos__read_build_ids(bool with_hits);
+bool __dsos__read_build_ids(struct list_head *head, bool with_hits);
 int build_id__sprintf(const u8 *self, int len, char *bf);
 int kallsyms__parse(const char *filename, void *arg,
                    int (*process_symbol)(void *arg, const char *name,
                                          char type, u64 start));
 
+int __machine__create_kernel_maps(struct machine *self, struct dso *kernel);
+int machine__create_kernel_maps(struct machine *self);
+
+int machines__create_kernel_maps(struct rb_root *self, pid_t pid);
+int machines__create_guest_kernel_maps(struct rb_root *self);
+
 int symbol__init(void);
 bool symbol_type__is_a(char symbol_type, enum map_type map_type);
 
+size_t vmlinux_path__fprintf(FILE *fp);
+
 #endif /* __PERF_SYMBOL */
index fa96831..1f7ecd4 100644 (file)
@@ -7,13 +7,35 @@
 #include "util.h"
 #include "debug.h"
 
-void map_groups__init(struct map_groups *self)
+int find_all_tid(int pid, pid_t ** all_tid)
 {
+       char name[256];
+       int items;
+       struct dirent **namelist = NULL;
+       int ret = 0;
        int i;
-       for (i = 0; i < MAP__NR_TYPES; ++i) {
-               self->maps[i] = RB_ROOT;
-               INIT_LIST_HEAD(&self->removed_maps[i]);
+
+       sprintf(name, "/proc/%d/task", pid);
+       items = scandir(name, &namelist, NULL, NULL);
+       if (items <= 0)
+                return -ENOENT;
+       *all_tid = malloc(sizeof(pid_t) * items);
+       if (!*all_tid) {
+               ret = -ENOMEM;
+               goto failure;
        }
+
+       for (i = 0; i < items; i++)
+               (*all_tid)[i] = atoi(namelist[i]->d_name);
+
+       ret = items;
+
+failure:
+       for (i=0; i<items; i++)
+               free(namelist[i]);
+       free(namelist);
+
+       return ret;
 }
 
 static struct thread *thread__new(pid_t pid)
@@ -31,28 +53,6 @@ static struct thread *thread__new(pid_t pid)
        return self;
 }
 
-static void map_groups__flush(struct map_groups *self)
-{
-       int type;
-
-       for (type = 0; type < MAP__NR_TYPES; type++) {
-               struct rb_root *root = &self->maps[type];
-               struct rb_node *next = rb_first(root);
-
-               while (next) {
-                       struct map *pos = rb_entry(next, struct map, rb_node);
-                       next = rb_next(&pos->rb_node);
-                       rb_erase(&pos->rb_node, root);
-                       /*
-                        * We may have references to this map, for
-                        * instance in some hist_entry instances, so
-                        * just move them to a separate list.
-                        */
-                       list_add_tail(&pos->node, &self->removed_maps[pos->type]);
-               }
-       }
-}
-
 int thread__set_comm(struct thread *self, const char *comm)
 {
        int err;
@@ -79,69 +79,10 @@ int thread__comm_len(struct thread *self)
        return self->comm_len;
 }
 
-size_t __map_groups__fprintf_maps(struct map_groups *self,
-                                 enum map_type type, FILE *fp)
-{
-       size_t printed = fprintf(fp, "%s:\n", map_type__name[type]);
-       struct rb_node *nd;
-
-       for (nd = rb_first(&self->maps[type]); nd; nd = rb_next(nd)) {
-               struct map *pos = rb_entry(nd, struct map, rb_node);
-               printed += fprintf(fp, "Map:");
-               printed += map__fprintf(pos, fp);
-               if (verbose > 2) {
-                       printed += dso__fprintf(pos->dso, type, fp);
-                       printed += fprintf(fp, "--\n");
-               }
-       }
-
-       return printed;
-}
-
-size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp)
-{
-       size_t printed = 0, i;
-       for (i = 0; i < MAP__NR_TYPES; ++i)
-               printed += __map_groups__fprintf_maps(self, i, fp);
-       return printed;
-}
-
-static size_t __map_groups__fprintf_removed_maps(struct map_groups *self,
-                                                enum map_type type, FILE *fp)
-{
-       struct map *pos;
-       size_t printed = 0;
-
-       list_for_each_entry(pos, &self->removed_maps[type], node) {
-               printed += fprintf(fp, "Map:");
-               printed += map__fprintf(pos, fp);
-               if (verbose > 1) {
-                       printed += dso__fprintf(pos->dso, type, fp);
-                       printed += fprintf(fp, "--\n");
-               }
-       }
-       return printed;
-}
-
-static size_t map_groups__fprintf_removed_maps(struct map_groups *self, FILE *fp)
-{
-       size_t printed = 0, i;
-       for (i = 0; i < MAP__NR_TYPES; ++i)
-               printed += __map_groups__fprintf_removed_maps(self, i, fp);
-       return printed;
-}
-
-static size_t map_groups__fprintf(struct map_groups *self, FILE *fp)
-{
-       size_t printed = map_groups__fprintf_maps(self, fp);
-       printed += fprintf(fp, "Removed maps:\n");
-       return printed + map_groups__fprintf_removed_maps(self, fp);
-}
-
 static size_t thread__fprintf(struct thread *self, FILE *fp)
 {
        return fprintf(fp, "Thread %d %s\n", self->pid, self->comm) +
-              map_groups__fprintf(&self->mg, fp);
+              map_groups__fprintf(&self->mg, verbose, fp);
 }
 
 struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
@@ -183,127 +124,12 @@ struct thread *perf_session__findnew(struct perf_session *self, pid_t pid)
        return th;
 }
 
-static int map_groups__fixup_overlappings(struct map_groups *self,
-                                         struct map *map)
-{
-       struct rb_root *root = &self->maps[map->type];
-       struct rb_node *next = rb_first(root);
-
-       while (next) {
-               struct map *pos = rb_entry(next, struct map, rb_node);
-               next = rb_next(&pos->rb_node);
-
-               if (!map__overlap(pos, map))
-                       continue;
-
-               if (verbose >= 2) {
-                       fputs("overlapping maps:\n", stderr);
-                       map__fprintf(map, stderr);
-                       map__fprintf(pos, stderr);
-               }
-
-               rb_erase(&pos->rb_node, root);
-               /*
-                * We may have references to this map, for instance in some
-                * hist_entry instances, so just move them to a separate
-                * list.
-                */
-               list_add_tail(&pos->node, &self->removed_maps[map->type]);
-               /*
-                * Now check if we need to create new maps for areas not
-                * overlapped by the new map:
-                */
-               if (map->start > pos->start) {
-                       struct map *before = map__clone(pos);
-
-                       if (before == NULL)
-                               return -ENOMEM;
-
-                       before->end = map->start - 1;
-                       map_groups__insert(self, before);
-                       if (verbose >= 2)
-                               map__fprintf(before, stderr);
-               }
-
-               if (map->end < pos->end) {
-                       struct map *after = map__clone(pos);
-
-                       if (after == NULL)
-                               return -ENOMEM;
-
-                       after->start = map->end + 1;
-                       map_groups__insert(self, after);
-                       if (verbose >= 2)
-                               map__fprintf(after, stderr);
-               }
-       }
-
-       return 0;
-}
-
-void maps__insert(struct rb_root *maps, struct map *map)
-{
-       struct rb_node **p = &maps->rb_node;
-       struct rb_node *parent = NULL;
-       const u64 ip = map->start;
-       struct map *m;
-
-       while (*p != NULL) {
-               parent = *p;
-               m = rb_entry(parent, struct map, rb_node);
-               if (ip < m->start)
-                       p = &(*p)->rb_left;
-               else
-                       p = &(*p)->rb_right;
-       }
-
-       rb_link_node(&map->rb_node, parent, p);
-       rb_insert_color(&map->rb_node, maps);
-}
-
-struct map *maps__find(struct rb_root *maps, u64 ip)
-{
-       struct rb_node **p = &maps->rb_node;
-       struct rb_node *parent = NULL;
-       struct map *m;
-
-       while (*p != NULL) {
-               parent = *p;
-               m = rb_entry(parent, struct map, rb_node);
-               if (ip < m->start)
-                       p = &(*p)->rb_left;
-               else if (ip > m->end)
-                       p = &(*p)->rb_right;
-               else
-                       return m;
-       }
-
-       return NULL;
-}
-
 void thread__insert_map(struct thread *self, struct map *map)
 {
-       map_groups__fixup_overlappings(&self->mg, map);
+       map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);
        map_groups__insert(&self->mg, map);
 }
 
-/*
- * XXX This should not really _copy_ te maps, but refcount them.
- */
-static int map_groups__clone(struct map_groups *self,
-                            struct map_groups *parent, enum map_type type)
-{
-       struct rb_node *nd;
-       for (nd = rb_first(&parent->maps[type]); nd; nd = rb_next(nd)) {
-               struct map *map = rb_entry(nd, struct map, rb_node);
-               struct map *new = map__clone(map);
-               if (new == NULL)
-                       return -ENOMEM;
-               map_groups__insert(self, new);
-       }
-       return 0;
-}
-
 int thread__fork(struct thread *self, struct thread *parent)
 {
        int i;
@@ -336,15 +162,3 @@ size_t perf_session__fprintf(struct perf_session *self, FILE *fp)
 
        return ret;
 }
-
-struct symbol *map_groups__find_symbol(struct map_groups *self,
-                                      enum map_type type, u64 addr,
-                                      symbol_filter_t filter)
-{
-       struct map *map = map_groups__find(self, type, addr);
-
-       if (map != NULL)
-               return map__find_symbol(map, map->map_ip(map, addr), filter);
-
-       return NULL;
-}
index dcf7030..1dfd9ff 100644 (file)
@@ -5,14 +5,6 @@
 #include <unistd.h>
 #include "symbol.h"
 
-struct map_groups {
-       struct rb_root          maps[MAP__NR_TYPES];
-       struct list_head        removed_maps[MAP__NR_TYPES];
-};
-
-size_t __map_groups__fprintf_maps(struct map_groups *self,
-                                 enum map_type type, FILE *fp);
-
 struct thread {
        struct rb_node          rb_node;
        struct map_groups       mg;
@@ -23,29 +15,16 @@ struct thread {
        int                     comm_len;
 };
 
-void map_groups__init(struct map_groups *self);
+struct perf_session;
+
+int find_all_tid(int pid, pid_t ** all_tid);
 int thread__set_comm(struct thread *self, const char *comm);
 int thread__comm_len(struct thread *self);
 struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
 void thread__insert_map(struct thread *self, struct map *map);
 int thread__fork(struct thread *self, struct thread *parent);
-size_t map_groups__fprintf_maps(struct map_groups *self, FILE *fp);
 size_t perf_session__fprintf(struct perf_session *self, FILE *fp);
 
-void maps__insert(struct rb_root *maps, struct map *map);
-struct map *maps__find(struct rb_root *maps, u64 addr);
-
-static inline void map_groups__insert(struct map_groups *self, struct map *map)
-{
-        maps__insert(&self->maps[map->type], map);
-}
-
-static inline struct map *map_groups__find(struct map_groups *self,
-                                          enum map_type type, u64 addr)
-{
-       return maps__find(&self->maps[type], addr);
-}
-
 static inline struct map *thread__find_map(struct thread *self,
                                           enum map_type type, u64 addr)
 {
@@ -54,34 +33,12 @@ static inline struct map *thread__find_map(struct thread *self,
 
 void thread__find_addr_map(struct thread *self,
                           struct perf_session *session, u8 cpumode,
-                          enum map_type type, u64 addr,
+                          enum map_type type, pid_t pid, u64 addr,
                           struct addr_location *al);
 
 void thread__find_addr_location(struct thread *self,
                                struct perf_session *session, u8 cpumode,
-                               enum map_type type, u64 addr,
+                               enum map_type type, pid_t pid, u64 addr,
                                struct addr_location *al,
                                symbol_filter_t filter);
-struct symbol *map_groups__find_symbol(struct map_groups *self,
-                                      enum map_type type, u64 addr,
-                                      symbol_filter_t filter);
-
-static inline struct symbol *map_groups__find_function(struct map_groups *self,
-                                                      u64 addr,
-                                                      symbol_filter_t filter)
-{
-       return map_groups__find_symbol(self, MAP__FUNCTION, addr, filter);
-}
-
-struct map *map_groups__find_by_name(struct map_groups *self,
-                                    enum map_type type, const char *name);
-
-int __map_groups__create_kernel_maps(struct map_groups *self,
-                                    struct map *vmlinux_maps[MAP__NR_TYPES],
-                                    struct dso *kernel);
-int map_groups__create_kernel_maps(struct map_groups *self,
-                                  struct map *vmlinux_maps[MAP__NR_TYPES]);
-
-struct map *map_groups__new_module(struct map_groups *self, u64 start,
-                                  const char *filename);
 #endif /* __PERF_THREAD_H */
index 5ea8973..b157260 100644 (file)
@@ -154,10 +154,17 @@ static void put_tracing_file(char *file)
        free(file);
 }
 
+static ssize_t calc_data_size;
+
 static ssize_t write_or_die(const void *buf, size_t len)
 {
        int ret;
 
+       if (calc_data_size) {
+               calc_data_size += len;
+               return len;
+       }
+
        ret = write(output_fd, buf, len);
        if (ret < 0)
                die("writing to '%s'", output_file);
@@ -480,6 +487,17 @@ get_tracepoints_path(struct perf_event_attr *pattrs, int nb_events)
        return nr_tracepoints > 0 ? path.next : NULL;
 }
 
+bool have_tracepoints(struct perf_event_attr *pattrs, int nb_events)
+{
+       int i;
+
+       for (i = 0; i < nb_events; i++)
+               if (pattrs[i].type == PERF_TYPE_TRACEPOINT)
+                       return true;
+
+       return false;
+}
+
 int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
 {
        char buf[BUFSIZ];
@@ -526,3 +544,20 @@ int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events)
 
        return 0;
 }
+
+ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs,
+                              int nb_events)
+{
+       ssize_t size;
+       int err = 0;
+
+       calc_data_size = 1;
+       err = read_tracing_data(fd, pattrs, nb_events);
+       size = calc_data_size - 1;
+       calc_data_size = 0;
+
+       if (err < 0)
+               return err;
+
+       return size;
+}
index 613c9cc..73a0222 100644 (file)
@@ -37,10 +37,12 @@ int header_page_ts_offset;
 int header_page_ts_size;
 int header_page_size_offset;
 int header_page_size_size;
+int header_page_overwrite_offset;
+int header_page_overwrite_size;
 int header_page_data_offset;
 int header_page_data_size;
 
-int latency_format;
+bool latency_format;
 
 static char *input_buf;
 static unsigned long long input_buf_ptr;
@@ -628,23 +630,32 @@ static int test_type(enum event_type type, enum event_type expect)
        return 0;
 }
 
-static int test_type_token(enum event_type type, char *token,
-                   enum event_type expect, const char *expect_tok)
+static int __test_type_token(enum event_type type, char *token,
+                            enum event_type expect, const char *expect_tok,
+                            bool warn)
 {
        if (type != expect) {
-               warning("Error: expected type %d but read %d",
-                   expect, type);
+               if (warn)
+                       warning("Error: expected type %d but read %d",
+                               expect, type);
                return -1;
        }
 
        if (strcmp(token, expect_tok) != 0) {
-               warning("Error: expected '%s' but read '%s'",
-                   expect_tok, token);
+               if (warn)
+                       warning("Error: expected '%s' but read '%s'",
+                               expect_tok, token);
                return -1;
        }
        return 0;
 }
 
+static int test_type_token(enum event_type type, char *token,
+                          enum event_type expect, const char *expect_tok)
+{
+       return __test_type_token(type, token, expect, expect_tok, true);
+}
+
 static int __read_expect_type(enum event_type expect, char **tok, int newline_ok)
 {
        enum event_type type;
@@ -661,7 +672,8 @@ static int read_expect_type(enum event_type expect, char **tok)
        return __read_expect_type(expect, tok, 1);
 }
 
-static int __read_expected(enum event_type expect, const char *str, int newline_ok)
+static int __read_expected(enum event_type expect, const char *str,
+                          int newline_ok, bool warn)
 {
        enum event_type type;
        char *token;
@@ -672,7 +684,7 @@ static int __read_expected(enum event_type expect, const char *str, int newline_
        else
                type = read_token_item(&token);
 
-       ret = test_type_token(type, token, expect, str);
+       ret = __test_type_token(type, token, expect, str, warn);
 
        free_token(token);
 
@@ -681,12 +693,12 @@ static int __read_expected(enum event_type expect, const char *str, int newline_
 
 static int read_expected(enum event_type expect, const char *str)
 {
-       return __read_expected(expect, str, 1);
+       return __read_expected(expect, str, 1, true);
 }
 
 static int read_expected_item(enum event_type expect, const char *str)
 {
-       return __read_expected(expect, str, 0);
+       return __read_expected(expect, str, 0, true);
 }
 
 static char *event_read_name(void)
@@ -744,7 +756,7 @@ static int field_is_string(struct format_field *field)
 
 static int field_is_dynamic(struct format_field *field)
 {
-       if (!strcmp(field->type, "__data_loc"))
+       if (!strncmp(field->type, "__data_loc", 10))
                return 1;
 
        return 0;
@@ -3087,88 +3099,6 @@ static void print_args(struct print_arg *args)
        }
 }
 
-static void parse_header_field(const char *field,
-                              int *offset, int *size)
-{
-       char *token;
-       int type;
-
-       if (read_expected(EVENT_ITEM, "field") < 0)
-               return;
-       if (read_expected(EVENT_OP, ":") < 0)
-               return;
-
-       /* type */
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
-               goto fail;
-       free_token(token);
-
-       if (read_expected(EVENT_ITEM, field) < 0)
-               return;
-       if (read_expected(EVENT_OP, ";") < 0)
-               return;
-       if (read_expected(EVENT_ITEM, "offset") < 0)
-               return;
-       if (read_expected(EVENT_OP, ":") < 0)
-               return;
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
-               goto fail;
-       *offset = atoi(token);
-       free_token(token);
-       if (read_expected(EVENT_OP, ";") < 0)
-               return;
-       if (read_expected(EVENT_ITEM, "size") < 0)
-               return;
-       if (read_expected(EVENT_OP, ":") < 0)
-               return;
-       if (read_expect_type(EVENT_ITEM, &token) < 0)
-               goto fail;
-       *size = atoi(token);
-       free_token(token);
-       if (read_expected(EVENT_OP, ";") < 0)
-               return;
-       type = read_token(&token);
-       if (type != EVENT_NEWLINE) {
-               /* newer versions of the kernel have a "signed" type */
-               if (type != EVENT_ITEM)
-                       goto fail;
-
-               if (strcmp(token, "signed") != 0)
-                       goto fail;
-
-               free_token(token);
-
-               if (read_expected(EVENT_OP, ":") < 0)
-                       return;
-
-               if (read_expect_type(EVENT_ITEM, &token))
-                       goto fail;
-
-               free_token(token);
-               if (read_expected(EVENT_OP, ";") < 0)
-                       return;
-
-               if (read_expect_type(EVENT_NEWLINE, &token))
-                       goto fail;
-       }
- fail:
-       free_token(token);
-}
-
-int parse_header_page(char *buf, unsigned long size)
-{
-       init_input_buf(buf, size);
-
-       parse_header_field("timestamp", &header_page_ts_offset,
-                          &header_page_ts_size);
-       parse_header_field("commit", &header_page_size_offset,
-                          &header_page_size_size);
-       parse_header_field("data", &header_page_data_offset,
-                          &header_page_data_size);
-
-       return 0;
-}
-
 int parse_ftrace_file(char *buf, unsigned long size)
 {
        struct format_field *field;
index 7cd1193..cb54cd0 100644 (file)
@@ -50,14 +50,51 @@ static int long_size;
 
 static unsigned long   page_size;
 
+static ssize_t calc_data_size;
+static bool repipe;
+
+/* If it fails, the next read will report it */
+static void skip(int size)
+{
+       lseek(input_fd, size, SEEK_CUR);
+}
+
+static int do_read(int fd, void *buf, int size)
+{
+       int rsize = size;
+
+       while (size) {
+               int ret = read(fd, buf, size);
+
+               if (ret <= 0)
+                       return -1;
+
+               if (repipe) {
+                       int retw = write(STDOUT_FILENO, buf, ret);
+
+                       if (retw <= 0 || retw != ret)
+                               die("repiping input file");
+               }
+
+               size -= ret;
+               buf += ret;
+       }
+
+       return rsize;
+}
+
 static int read_or_die(void *data, int size)
 {
        int r;
 
-       r = read(input_fd, data, size);
-       if (r != size)
+       r = do_read(input_fd, data, size);
+       if (r <= 0)
                die("reading input file (size expected=%d received=%d)",
                    size, r);
+
+       if (calc_data_size)
+               calc_data_size += r;
+
        return r;
 }
 
@@ -82,57 +119,36 @@ static char *read_string(void)
        char buf[BUFSIZ];
        char *str = NULL;
        int size = 0;
-       int i;
        off_t r;
+       char c;
 
        for (;;) {
-               r = read(input_fd, buf, BUFSIZ);
+               r = read(input_fd, &c, 1);
                if (r < 0)
                        die("reading input file");
 
                if (!r)
                        die("no data");
 
-               for (i = 0; i < r; i++) {
-                       if (!buf[i])
-                               break;
-               }
-               if (i < r)
-                       break;
+               if (repipe) {
+                       int retw = write(STDOUT_FILENO, &c, 1);
 
-               if (str) {
-                       size += BUFSIZ;
-                       str = realloc(str, size);
-                       if (!str)
-                               die("malloc of size %d", size);
-                       memcpy(str + (size - BUFSIZ), buf, BUFSIZ);
-               } else {
-                       size = BUFSIZ;
-                       str = malloc_or_die(size);
-                       memcpy(str, buf, size);
+                       if (retw <= 0 || retw != r)
+                               die("repiping input file string");
                }
-       }
 
-       /* trailing \0: */
-       i++;
-
-       /* move the file descriptor to the end of the string */
-       r = lseek(input_fd, -(r - i), SEEK_CUR);
-       if (r == (off_t)-1)
-               die("lseek");
-
-       if (str) {
-               size += i;
-               str = realloc(str, size);
-               if (!str)
-                       die("malloc of size %d", size);
-               memcpy(str + (size - i), buf, i);
-       } else {
-               size = i;
-               str = malloc_or_die(i);
-               memcpy(str, buf, i);
+               buf[size++] = c;
+
+               if (!c)
+                       break;
        }
 
+       if (calc_data_size)
+               calc_data_size += size;
+
+       str = malloc_or_die(size);
+       memcpy(str, buf, size);
+
        return str;
 }
 
@@ -174,7 +190,6 @@ static void read_ftrace_printk(void)
 static void read_header_files(void)
 {
        unsigned long long size;
-       char *header_page;
        char *header_event;
        char buf[BUFSIZ];
 
@@ -184,10 +199,7 @@ static void read_header_files(void)
                die("did not read header page");
 
        size = read8();
-       header_page = malloc_or_die(size);
-       read_or_die(header_page, size);
-       parse_header_page(header_page, size);
-       free(header_page);
+       skip(size);
 
        /*
         * The size field in the page is of type long,
@@ -459,7 +471,7 @@ struct record *trace_read_data(int cpu)
        return data;
 }
 
-void trace_report(int fd)
+ssize_t trace_report(int fd, bool __repipe)
 {
        char buf[BUFSIZ];
        char test[] = { 23, 8, 68 };
@@ -467,6 +479,10 @@ void trace_report(int fd)
        int show_version = 0;
        int show_funcs = 0;
        int show_printk = 0;
+       ssize_t size;
+
+       calc_data_size = 1;
+       repipe = __repipe;
 
        input_fd = fd;
 
@@ -499,14 +515,18 @@ void trace_report(int fd)
        read_proc_kallsyms();
        read_ftrace_printk();
 
+       size = calc_data_size - 1;
+       calc_data_size = 0;
+       repipe = false;
+
        if (show_funcs) {
                print_funcs();
-               return;
+               return size;
        }
        if (show_printk) {
                print_printk();
-               return;
+               return size;
        }
 
-       return;
+       return size;
 }
index c3269b9..406d452 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __PERF_TRACE_EVENTS_H
 #define __PERF_TRACE_EVENTS_H
 
+#include <stdbool.h>
 #include "parse-events.h"
 
 #define __unused __attribute__((unused))
@@ -162,7 +163,7 @@ struct record *trace_read_data(int cpu);
 
 void parse_set_info(int nr_cpus, int long_sz);
 
-void trace_report(int fd);
+ssize_t trace_report(int fd, bool repipe);
 
 void *malloc_or_die(unsigned int size);
 
@@ -241,9 +242,8 @@ extern int header_page_size_size;
 extern int header_page_data_offset;
 extern int header_page_data_size;
 
-extern int latency_format;
+extern bool latency_format;
 
-int parse_header_page(char *buf, unsigned long size);
 int trace_parse_common_type(void *data);
 int trace_parse_common_pid(void *data);
 int parse_common_pc(void *data);
@@ -258,6 +258,8 @@ void *raw_field_ptr(struct event *event, const char *name, void *data);
 unsigned long long eval_flag(const char *flag);
 
 int read_tracing_data(int fd, struct perf_event_attr *pattrs, int nb_events);
+ssize_t read_tracing_data_size(int fd, struct perf_event_attr *pattrs,
+                              int nb_events);
 
 /* taken from kernel/trace/trace.h */
 enum trace_flag_type {
index f9b890f..2142656 100644 (file)
@@ -92,3 +92,25 @@ out_close_from:
 out:
        return err;
 }
+
+unsigned long convert_unit(unsigned long value, char *unit)
+{
+       *unit = ' ';
+
+       if (value > 1000) {
+               value /= 1000;
+               *unit = 'K';
+       }
+
+       if (value > 1000) {
+               value /= 1000;
+               *unit = 'M';
+       }
+
+       if (value > 1000) {
+               value /= 1000;
+               *unit = 'G';
+       }
+
+       return value;
+}
index 0f5b2a6..0795bf3 100644 (file)
 #define _ALL_SOURCE 1
 #define _GNU_SOURCE 1
 #define _BSD_SOURCE 1
+#define HAS_BOOL
 
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/stat.h>
 #include <sys/statfs.h>
 #include <fcntl.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -78,6 +80,7 @@
 #include <pwd.h>
 #include <inttypes.h>
 #include "../../../include/linux/magic.h"
+#include "types.h"
 
 
 #ifndef NO_ICONV
@@ -295,6 +298,13 @@ extern void *xmemdupz(const void *data, size_t len);
 extern char *xstrndup(const char *str, size_t len);
 extern void *xrealloc(void *ptr, size_t size) __attribute__((weak));
 
+static inline void *xzalloc(size_t size)
+{
+       void *buf = xmalloc(size);
+
+       return memset(buf, 0, size);
+}
+
 static inline void *zalloc(size_t size)
 {
        return calloc(1, size);
@@ -309,6 +319,7 @@ static inline int has_extension(const char *filename, const char *ext)
 {
        size_t len = strlen(filename);
        size_t extlen = strlen(ext);
+
        return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
 }
 
@@ -322,6 +333,7 @@ static inline int has_extension(const char *filename, const char *ext)
 #undef isalnum
 #undef tolower
 #undef toupper
+
 extern unsigned char sane_ctype[256];
 #define GIT_SPACE              0x01
 #define GIT_DIGIT              0x02
@@ -406,4 +418,14 @@ void git_qsort(void *base, size_t nmemb, size_t size,
 int mkdir_p(char *path, mode_t mode);
 int copyfile(const char *from, const char *to);
 
+s64 perf_atoll(const char *str);
+char **argv_split(const char *str, int *argcp);
+void argv_free(char **argv);
+bool strglobmatch(const char *str, const char *pat);
+bool strlazymatch(const char *str, const char *pat);
+unsigned long convert_unit(unsigned long value, char *unit);
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
 #endif
index 80fd3ad..11692b9 100644 (file)
@@ -32,12 +32,30 @@ static int kvm_iommu_unmap_memslots(struct kvm *kvm);
 static void kvm_iommu_put_pages(struct kvm *kvm,
                                gfn_t base_gfn, unsigned long npages);
 
+static pfn_t kvm_pin_pages(struct kvm *kvm, struct kvm_memory_slot *slot,
+                          gfn_t gfn, unsigned long size)
+{
+       gfn_t end_gfn;
+       pfn_t pfn;
+
+       pfn     = gfn_to_pfn_memslot(kvm, slot, gfn);
+       end_gfn = gfn + (size >> PAGE_SHIFT);
+       gfn    += 1;
+
+       if (is_error_pfn(pfn))
+               return pfn;
+
+       while (gfn < end_gfn)
+               gfn_to_pfn_memslot(kvm, slot, gfn++);
+
+       return pfn;
+}
+
 int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
 {
-       gfn_t gfn = slot->base_gfn;
-       unsigned long npages = slot->npages;
+       gfn_t gfn, end_gfn;
        pfn_t pfn;
-       int i, r = 0;
+       int r = 0;
        struct iommu_domain *domain = kvm->arch.iommu_domain;
        int flags;
 
@@ -45,31 +63,62 @@ int kvm_iommu_map_pages(struct kvm *kvm, struct kvm_memory_slot *slot)
        if (!domain)
                return 0;
 
+       gfn     = slot->base_gfn;
+       end_gfn = gfn + slot->npages;
+
        flags = IOMMU_READ | IOMMU_WRITE;
        if (kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY)
                flags |= IOMMU_CACHE;
 
-       for (i = 0; i < npages; i++) {
-               /* check if already mapped */
-               if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn)))
+
+       while (gfn < end_gfn) {
+               unsigned long page_size;
+
+               /* Check if already mapped */
+               if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) {
+                       gfn += 1;
+                       continue;
+               }
+
+               /* Get the page size we could use to map */
+               page_size = kvm_host_page_size(kvm, gfn);
+
+               /* Make sure the page_size does not exceed the memslot */
+               while ((gfn + (page_size >> PAGE_SHIFT)) > end_gfn)
+                       page_size >>= 1;
+
+               /* Make sure gfn is aligned to the page size we want to map */
+               while ((gfn << PAGE_SHIFT) & (page_size - 1))
+                       page_size >>= 1;
+
+               /*
+                * Pin all pages we are about to map in memory. This is
+                * important because we unmap and unpin in 4kb steps later.
+                */
+               pfn = kvm_pin_pages(kvm, slot, gfn, page_size);
+               if (is_error_pfn(pfn)) {
+                       gfn += 1;
                        continue;
+               }
 
-               pfn = gfn_to_pfn_memslot(kvm, slot, gfn);
-               r = iommu_map_range(domain,
-                                   gfn_to_gpa(gfn),
-                                   pfn_to_hpa(pfn),
-                                   PAGE_SIZE, flags);
+               /* Map into IO address space */
+               r = iommu_map(domain, gfn_to_gpa(gfn), pfn_to_hpa(pfn),
+                             get_order(page_size), flags);
                if (r) {
                        printk(KERN_ERR "kvm_iommu_map_address:"
                               "iommu failed to map pfn=%lx\n", pfn);
                        goto unmap_pages;
                }
-               gfn++;
+
+               gfn += page_size >> PAGE_SHIFT;
+
+
        }
+
        return 0;
 
 unmap_pages:
-       kvm_iommu_put_pages(kvm, slot->base_gfn, i);
+       kvm_iommu_put_pages(kvm, slot->base_gfn, gfn);
        return r;
 }
 
@@ -189,27 +238,47 @@ out_unmap:
        return r;
 }
 
+static void kvm_unpin_pages(struct kvm *kvm, pfn_t pfn, unsigned long npages)
+{
+       unsigned long i;
+
+       for (i = 0; i < npages; ++i)
+               kvm_release_pfn_clean(pfn + i);
+}
+
 static void kvm_iommu_put_pages(struct kvm *kvm,
                                gfn_t base_gfn, unsigned long npages)
 {
-       gfn_t gfn = base_gfn;
+       struct iommu_domain *domain;
+       gfn_t end_gfn, gfn;
        pfn_t pfn;
-       struct iommu_domain *domain = kvm->arch.iommu_domain;
-       unsigned long i;
        u64 phys;
 
+       domain  = kvm->arch.iommu_domain;
+       end_gfn = base_gfn + npages;
+       gfn     = base_gfn;
+
        /* check if iommu exists and in use */
        if (!domain)
                return;
 
-       for (i = 0; i < npages; i++) {
+       while (gfn < end_gfn) {
+               unsigned long unmap_pages;
+               int order;
+
+               /* Get physical address */
                phys = iommu_iova_to_phys(domain, gfn_to_gpa(gfn));
-               pfn = phys >> PAGE_SHIFT;
-               kvm_release_pfn_clean(pfn);
-               gfn++;
-       }
+               pfn  = phys >> PAGE_SHIFT;
+
+               /* Unmap address from IO address space */
+               order       = iommu_unmap(domain, gfn_to_gpa(gfn), PAGE_SIZE);
+               unmap_pages = 1ULL << order;
 
-       iommu_unmap_range(domain, gfn_to_gpa(base_gfn), PAGE_SIZE * npages);
+               /* Unpin all pages we just unmapped to not leak any memory */
+               kvm_unpin_pages(kvm, pfn, unmap_pages);
+
+               gfn += unmap_pages;
+       }
 }
 
 static int kvm_iommu_unmap_memslots(struct kvm *kvm)